Skip to content

Commit

Permalink
Only update codecInfo when needed
Browse files Browse the repository at this point in the history
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:/google/moe
MOE_MIGRATED_REVID=157847702
  • Loading branch information
ojw28 committed Jun 6, 2017
1 parent c5cf909 commit 35cc0d6
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -314,36 +314,36 @@ protected final void maybeInitCodec() throws ExoPlaybackException {
}
}

MediaCodecInfo codecInfo = null;
try {
codecInfo = getDecoderInfo(mediaCodecSelector, format, drmSessionRequiresSecureDecoder);
if (codecInfo == null && drmSessionRequiresSecureDecoder) {
// The drm session indicates that a secure decoder is required, but the device does not have
// one. Assuming that supportsFormat indicated support for the media being played, we know
// that it does not require a secure output path. Most CDM implementations allow playback to
// proceed with a non-secure decoder in this case, so we try our luck.
codecInfo = getDecoderInfo(mediaCodecSelector, format, false);
if (codecInfo != null) {
Log.w(TAG, "Drm session requires secure decoder for " + mimeType + ", but "
+ "no secure decoder available. Trying to proceed with " + codecInfo.name + ".");
if (codecInfo == null) {
try {
codecInfo = getDecoderInfo(mediaCodecSelector, format, drmSessionRequiresSecureDecoder);
if (codecInfo == null && drmSessionRequiresSecureDecoder) {
// The drm session indicates that a secure decoder is required, but the device does not
// have one. Assuming that supportsFormat indicated support for the media being played, we
// know that it does not require a secure output path. Most CDM implementations allow
// playback to proceed with a non-secure decoder in this case, so we try our luck.
codecInfo = getDecoderInfo(mediaCodecSelector, format, false);
if (codecInfo != null) {
Log.w(TAG, "Drm session requires secure decoder for " + mimeType + ", but "
+ "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) {
throwDecoderInitError(new DecoderInitializationException(format, null,
drmSessionRequiresSecureDecoder,
DecoderInitializationException.NO_SUITABLE_DECODER_ERROR));
if (codecInfo == null) {
throwDecoderInitError(new DecoderInitializationException(format, null,
drmSessionRequiresSecureDecoder,
DecoderInitializationException.NO_SUITABLE_DECODER_ERROR));
}
}

if (!shouldInitCodec(codecInfo)) {
return;
}

this.codecInfo = codecInfo;
String codecName = codecInfo.name;
codecNeedsDiscardToSpsWorkaround = codecNeedsDiscardToSpsWorkaround(codecName, format);
codecNeedsFlushWorkaround = codecNeedsFlushWorkaround(codecName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ MediaCodecInfo getDecoderInfo(String mimeType, boolean requiresSecureDecoder)
/**
* Selects a decoder to instantiate for audio passthrough.
*
* @return A {@link MediaCodecInfo} describing the decoder, or null if no suitable decoder
* exists.
* @return A {@link MediaCodecInfo} describing the decoder, or null if no suitable decoder exists.
* @throws DecoderQueryException Thrown if there was an error querying decoders.
*/
MediaCodecInfo getPassthroughDecoderInfo() throws DecoderQueryException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static void warmDecoderInfoCache(String mimeType, boolean secure) {

/**
* Returns information about a decoder suitable for audio passthrough.
**
*
* @return A {@link MediaCodecInfo} describing the decoder, or null if no suitable decoder
* exists.
*/
Expand Down

0 comments on commit 35cc0d6

Please sign in to comment.