Don't throw DecoderQueryException from getCodecMaxSize
It's only thrown in an edge case on API level 20 and below. If it is thrown it causes playback failure when playback could succeed, by throwing up through configureCodec. It seems better just to catch the exception and have the codec be configured using the format's own width and height. PiperOrigin-RevId: 251745539
This commit is contained in:
parent
3490bea339
commit
cfa837df5c
@ -455,15 +455,13 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
|
|||||||
* @param crypto For drm protected playbacks, a {@link MediaCrypto} to use for decryption.
|
* @param crypto For drm protected playbacks, a {@link MediaCrypto} to use for decryption.
|
||||||
* @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
|
* @param codecOperatingRate The codec operating rate, or {@link #CODEC_OPERATING_RATE_UNSET} if
|
||||||
* no codec operating rate should be set.
|
* no codec operating rate should be set.
|
||||||
* @throws DecoderQueryException If an error occurs querying {@code codecInfo}.
|
|
||||||
*/
|
*/
|
||||||
protected abstract void configureCodec(
|
protected abstract void configureCodec(
|
||||||
MediaCodecInfo codecInfo,
|
MediaCodecInfo codecInfo,
|
||||||
MediaCodec codec,
|
MediaCodec codec,
|
||||||
Format format,
|
Format format,
|
||||||
MediaCrypto crypto,
|
MediaCrypto crypto,
|
||||||
float codecOperatingRate)
|
float codecOperatingRate);
|
||||||
throws DecoderQueryException;
|
|
||||||
|
|
||||||
protected final void maybeInitCodec() throws ExoPlaybackException {
|
protected final void maybeInitCodec() throws ExoPlaybackException {
|
||||||
if (codec != null || inputFormat == null) {
|
if (codec != null || inputFormat == null) {
|
||||||
|
@ -581,8 +581,7 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
|||||||
MediaCodec codec,
|
MediaCodec codec,
|
||||||
Format format,
|
Format format,
|
||||||
MediaCrypto crypto,
|
MediaCrypto crypto,
|
||||||
float codecOperatingRate)
|
float codecOperatingRate) {
|
||||||
throws DecoderQueryException {
|
|
||||||
codecMaxValues = getCodecMaxValues(codecInfo, format, getStreamFormats());
|
codecMaxValues = getCodecMaxValues(codecInfo, format, getStreamFormats());
|
||||||
MediaFormat mediaFormat =
|
MediaFormat mediaFormat =
|
||||||
getMediaFormat(
|
getMediaFormat(
|
||||||
@ -1210,11 +1209,9 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
|||||||
* @param format The format for which the codec is being configured.
|
* @param format The format for which the codec is being configured.
|
||||||
* @param streamFormats The possible stream formats.
|
* @param streamFormats The possible stream formats.
|
||||||
* @return Suitable {@link CodecMaxValues}.
|
* @return Suitable {@link CodecMaxValues}.
|
||||||
* @throws DecoderQueryException If an error occurs querying {@code codecInfo}.
|
|
||||||
*/
|
*/
|
||||||
protected CodecMaxValues getCodecMaxValues(
|
protected CodecMaxValues getCodecMaxValues(
|
||||||
MediaCodecInfo codecInfo, Format format, Format[] streamFormats)
|
MediaCodecInfo codecInfo, Format format, Format[] streamFormats) {
|
||||||
throws DecoderQueryException {
|
|
||||||
int maxWidth = format.width;
|
int maxWidth = format.width;
|
||||||
int maxHeight = format.height;
|
int maxHeight = format.height;
|
||||||
int maxInputSize = getMaxInputSize(codecInfo, format);
|
int maxInputSize = getMaxInputSize(codecInfo, format);
|
||||||
@ -1264,17 +1261,15 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a maximum video size to use when configuring a codec for {@code format} in a way
|
* Returns a maximum video size to use when configuring a codec for {@code format} in a way that
|
||||||
* that will allow possible adaptation to other compatible formats that are expected to have the
|
* will allow possible adaptation to other compatible formats that are expected to have the same
|
||||||
* same aspect ratio, but whose sizes are unknown.
|
* aspect ratio, but whose sizes are unknown.
|
||||||
*
|
*
|
||||||
* @param codecInfo Information about the {@link MediaCodec} being configured.
|
* @param codecInfo Information about the {@link MediaCodec} being configured.
|
||||||
* @param format The format for which the codec is being configured.
|
* @param format The format for which the codec is being configured.
|
||||||
* @return The maximum video size to use, or null if the size of {@code format} should be used.
|
* @return The maximum video size to use, or null if the size of {@code format} should be used.
|
||||||
* @throws DecoderQueryException If an error occurs querying {@code codecInfo}.
|
|
||||||
*/
|
*/
|
||||||
private static Point getCodecMaxSize(MediaCodecInfo codecInfo, Format format)
|
private static Point getCodecMaxSize(MediaCodecInfo codecInfo, Format format) {
|
||||||
throws DecoderQueryException {
|
|
||||||
boolean isVerticalVideo = format.height > format.width;
|
boolean isVerticalVideo = format.height > format.width;
|
||||||
int formatLongEdgePx = isVerticalVideo ? format.height : format.width;
|
int formatLongEdgePx = isVerticalVideo ? format.height : format.width;
|
||||||
int formatShortEdgePx = isVerticalVideo ? format.width : format.height;
|
int formatShortEdgePx = isVerticalVideo ? format.width : format.height;
|
||||||
@ -1292,12 +1287,18 @@ public class MediaCodecVideoRenderer extends MediaCodecRenderer {
|
|||||||
return alignedSize;
|
return alignedSize;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Conservatively assume the codec requires 16px width and height alignment.
|
try {
|
||||||
longEdgePx = Util.ceilDivide(longEdgePx, 16) * 16;
|
// Conservatively assume the codec requires 16px width and height alignment.
|
||||||
shortEdgePx = Util.ceilDivide(shortEdgePx, 16) * 16;
|
longEdgePx = Util.ceilDivide(longEdgePx, 16) * 16;
|
||||||
if (longEdgePx * shortEdgePx <= MediaCodecUtil.maxH264DecodableFrameSize()) {
|
shortEdgePx = Util.ceilDivide(shortEdgePx, 16) * 16;
|
||||||
return new Point(isVerticalVideo ? shortEdgePx : longEdgePx,
|
if (longEdgePx * shortEdgePx <= MediaCodecUtil.maxH264DecodableFrameSize()) {
|
||||||
isVerticalVideo ? longEdgePx : shortEdgePx);
|
return new Point(
|
||||||
|
isVerticalVideo ? shortEdgePx : longEdgePx,
|
||||||
|
isVerticalVideo ? longEdgePx : shortEdgePx);
|
||||||
|
}
|
||||||
|
} catch (DecoderQueryException e) {
|
||||||
|
// We tried our best. Give up!
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ import com.google.android.exoplayer2.drm.DrmSessionManager;
|
|||||||
import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
|
import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
|
||||||
import com.google.android.exoplayer2.mediacodec.MediaCodecInfo;
|
import com.google.android.exoplayer2.mediacodec.MediaCodecInfo;
|
||||||
import com.google.android.exoplayer2.mediacodec.MediaCodecSelector;
|
import com.google.android.exoplayer2.mediacodec.MediaCodecSelector;
|
||||||
import com.google.android.exoplayer2.mediacodec.MediaCodecUtil.DecoderQueryException;
|
|
||||||
import com.google.android.exoplayer2.video.MediaCodecVideoRenderer;
|
import com.google.android.exoplayer2.video.MediaCodecVideoRenderer;
|
||||||
import com.google.android.exoplayer2.video.VideoRendererEventListener;
|
import com.google.android.exoplayer2.video.VideoRendererEventListener;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -115,8 +114,7 @@ public class DebugRenderersFactory extends DefaultRenderersFactory {
|
|||||||
MediaCodec codec,
|
MediaCodec codec,
|
||||||
Format format,
|
Format format,
|
||||||
MediaCrypto crypto,
|
MediaCrypto crypto,
|
||||||
float operatingRate)
|
float operatingRate) {
|
||||||
throws DecoderQueryException {
|
|
||||||
// If the codec is being initialized whilst the renderer is started, default behavior is to
|
// If the codec is being initialized whilst the renderer is started, default behavior is to
|
||||||
// render the first frame (i.e. the keyframe before the current position), then drop frames up
|
// render the first frame (i.e. the keyframe before the current position), then drop frames up
|
||||||
// to the current playback position. For test runs that place a maximum limit on the number of
|
// to the current playback position. For test runs that place a maximum limit on the number of
|
||||||
|
Loading…
x
Reference in New Issue
Block a user