Commit 35cc0d65 by olly Committed by Oliver Woodman

Only update codecInfo when needed

This avoids calling getDecoderInfo repeatedly in the case
where shouldInitCodec return false (e.g. because we don't
have a surface and cannot instantiate a dummy surface).

Issue: #677

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=157847702
parent c5cf9090
...@@ -314,36 +314,36 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -314,36 +314,36 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
} }
} }
MediaCodecInfo codecInfo = null; if (codecInfo == null) {
try { try {
codecInfo = getDecoderInfo(mediaCodecSelector, format, drmSessionRequiresSecureDecoder); codecInfo = getDecoderInfo(mediaCodecSelector, format, drmSessionRequiresSecureDecoder);
if (codecInfo == null && drmSessionRequiresSecureDecoder) { if (codecInfo == null && drmSessionRequiresSecureDecoder) {
// The drm session indicates that a secure decoder is required, but the device does not have // The drm session indicates that a secure decoder is required, but the device does not
// one. Assuming that supportsFormat indicated support for the media being played, we know // have one. Assuming that supportsFormat indicated support for the media being played, we
// that it does not require a secure output path. Most CDM implementations allow playback to // know that it does not require a secure output path. Most CDM implementations allow
// proceed with a non-secure decoder in this case, so we try our luck. // playback to proceed with a non-secure decoder in this case, so we try our luck.
codecInfo = getDecoderInfo(mediaCodecSelector, format, false); codecInfo = getDecoderInfo(mediaCodecSelector, format, false);
if (codecInfo != null) { if (codecInfo != null) {
Log.w(TAG, "Drm session requires secure decoder for " + mimeType + ", but " Log.w(TAG, "Drm session requires secure decoder for " + mimeType + ", but "
+ "no secure decoder available. Trying to proceed with " + codecInfo.name + "."); + "no secure decoder available. Trying to proceed with " + codecInfo.name + ".");
}
} }
} catch (DecoderQueryException e) {
throwDecoderInitError(new DecoderInitializationException(format, e,
drmSessionRequiresSecureDecoder, DecoderInitializationException.DECODER_QUERY_ERROR));
} }
} catch (DecoderQueryException e) {
throwDecoderInitError(new DecoderInitializationException(format, e,
drmSessionRequiresSecureDecoder, DecoderInitializationException.DECODER_QUERY_ERROR));
}
if (codecInfo == null) { if (codecInfo == null) {
throwDecoderInitError(new DecoderInitializationException(format, null, throwDecoderInitError(new DecoderInitializationException(format, null,
drmSessionRequiresSecureDecoder, drmSessionRequiresSecureDecoder,
DecoderInitializationException.NO_SUITABLE_DECODER_ERROR)); DecoderInitializationException.NO_SUITABLE_DECODER_ERROR));
}
} }
if (!shouldInitCodec(codecInfo)) { if (!shouldInitCodec(codecInfo)) {
return; return;
} }
this.codecInfo = codecInfo;
String codecName = codecInfo.name; String codecName = codecInfo.name;
codecNeedsDiscardToSpsWorkaround = codecNeedsDiscardToSpsWorkaround(codecName, format); codecNeedsDiscardToSpsWorkaround = codecNeedsDiscardToSpsWorkaround(codecName, format);
codecNeedsFlushWorkaround = codecNeedsFlushWorkaround(codecName); codecNeedsFlushWorkaround = codecNeedsFlushWorkaround(codecName);
......
...@@ -55,8 +55,7 @@ public interface MediaCodecSelector { ...@@ -55,8 +55,7 @@ public interface MediaCodecSelector {
/** /**
* Selects a decoder to instantiate for audio passthrough. * Selects a decoder to instantiate for audio passthrough.
* *
* @return A {@link MediaCodecInfo} describing the decoder, or null if no suitable decoder * @return A {@link MediaCodecInfo} describing the decoder, or null if no suitable decoder exists.
* exists.
* @throws DecoderQueryException Thrown if there was an error querying decoders. * @throws DecoderQueryException Thrown if there was an error querying decoders.
*/ */
MediaCodecInfo getPassthroughDecoderInfo() throws DecoderQueryException; MediaCodecInfo getPassthroughDecoderInfo() throws DecoderQueryException;
......
...@@ -99,7 +99,7 @@ public final class MediaCodecUtil { ...@@ -99,7 +99,7 @@ public final class MediaCodecUtil {
/** /**
* Returns information about a decoder suitable for audio passthrough. * Returns information about a decoder suitable for audio passthrough.
** *
* @return A {@link MediaCodecInfo} describing the decoder, or null if no suitable decoder * @return A {@link MediaCodecInfo} describing the decoder, or null if no suitable decoder
* exists. * exists.
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment