From 7301b538290cccf1be73582e5c8376c8f6b90961 Mon Sep 17 00:00:00 2001 From: olly Date: Thu, 12 May 2016 08:01:36 -0700 Subject: [PATCH] Add MediaCodecSelector.getPassthroughDecoderInfo. Issue: #1518 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=122157463 --- .../MediaCodecAudioTrackRenderer.java | 8 ++++---- .../android/exoplayer/MediaCodecSelector.java | 20 ++++++------------- .../android/exoplayer/MediaCodecUtil.java | 16 +++++++++++++-- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/library/src/main/java/com/google/android/exoplayer/MediaCodecAudioTrackRenderer.java b/library/src/main/java/com/google/android/exoplayer/MediaCodecAudioTrackRenderer.java index c9e4c4ddb3..055daba5e9 100644 --- a/library/src/main/java/com/google/android/exoplayer/MediaCodecAudioTrackRenderer.java +++ b/library/src/main/java/com/google/android/exoplayer/MediaCodecAudioTrackRenderer.java @@ -170,7 +170,7 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem if (!MimeTypes.isAudio(mimeType)) { return FORMAT_UNSUPPORTED_TYPE; } - if (allowPassthrough(mimeType) && mediaCodecSelector.getPassthroughDecoderName() != null) { + if (allowPassthrough(mimeType) && mediaCodecSelector.getPassthroughDecoderInfo() != null) { return ADAPTIVE_NOT_SEAMLESS | FORMAT_HANDLED; } // TODO[REFACTOR]: If requiresSecureDecryption then we should probably also check that the @@ -194,10 +194,10 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer implem protected DecoderInfo getDecoderInfo(MediaCodecSelector mediaCodecSelector, Format format, boolean requiresSecureDecoder) throws DecoderQueryException { if (allowPassthrough(format.sampleMimeType)) { - String passthroughDecoderName = mediaCodecSelector.getPassthroughDecoderName(); - if (passthroughDecoderName != null) { + DecoderInfo passthroughDecoderInfo = mediaCodecSelector.getPassthroughDecoderInfo(); + if (passthroughDecoderInfo != null) { passthroughEnabled = true; - return new DecoderInfo(passthroughDecoderName); + return passthroughDecoderInfo; } } passthroughEnabled = false; diff --git a/library/src/main/java/com/google/android/exoplayer/MediaCodecSelector.java b/library/src/main/java/com/google/android/exoplayer/MediaCodecSelector.java index e1f073c97e..292a405179 100644 --- a/library/src/main/java/com/google/android/exoplayer/MediaCodecSelector.java +++ b/library/src/main/java/com/google/android/exoplayer/MediaCodecSelector.java @@ -29,11 +29,6 @@ public interface MediaCodecSelector { */ MediaCodecSelector DEFAULT = new MediaCodecSelector() { - /** - * The name for the raw (passthrough) decoder OMX component. - */ - private static final String RAW_DECODER_NAME = "OMX.google.raw.decoder"; - @Override public DecoderInfo getDecoderInfo(String mimeType, boolean requiresSecureDecoder) throws DecoderQueryException { @@ -41,9 +36,8 @@ public interface MediaCodecSelector { } @Override - public String getPassthroughDecoderName() throws DecoderQueryException { - // TODO: Return null if the raw decoder doesn't exist. - return RAW_DECODER_NAME; + public DecoderInfo getPassthroughDecoderInfo() throws DecoderQueryException { + return MediaCodecUtil.getPassthroughDecoderInfo(); } }; @@ -53,20 +47,18 @@ public interface MediaCodecSelector { * * @param mimeType The mime type for which a decoder is required. * @param requiresSecureDecoder Whether a secure decoder is required. - * @return A {@link DecoderInfo} describing the decoder to instantiate, or null if no suitable - * decoder exists. + * @return A {@link DecoderInfo} describing the decoder, or null if no suitable decoder exists. * @throws DecoderQueryException Thrown if there was an error querying decoders. */ DecoderInfo getDecoderInfo(String mimeType, boolean requiresSecureDecoder) throws DecoderQueryException; /** - * Gets the name of a decoder suitable for audio passthrough. + * Selects a decoder to instantiate for audio passthrough. * - * @return The name of a decoder suitable for audio passthrough, or null if no suitable decoder - * exists. + * @return A {@link DecoderInfo} describing the decoder, or null if no suitable decoder exists. * @throws DecoderQueryException Thrown if there was an error querying decoders. */ - String getPassthroughDecoderName() throws DecoderQueryException; + DecoderInfo getPassthroughDecoderInfo() throws DecoderQueryException; } diff --git a/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java b/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java index 913cbda5e1..a2b49ac6e1 100644 --- a/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java +++ b/library/src/main/java/com/google/android/exoplayer/MediaCodecUtil.java @@ -52,6 +52,8 @@ public final class MediaCodecUtil { } private static final String TAG = "MediaCodecUtil"; + private static final DecoderInfo PASSTHROUGH_DECODER_INFO = + new DecoderInfo("OMX.google.raw.decoder", null); private static final HashMap> decoderInfosCache = new HashMap<>(); @@ -79,12 +81,22 @@ public final class MediaCodecUtil { } /** - * Returns information about the decoder that will be used for a given mime type. + * Returns information about a decoder suitable for audio passthrough. + ** + * @return A {@link DecoderInfo} describing the decoder, or null if no suitable decoder exists. + */ + public static DecoderInfo getPassthroughDecoderInfo() { + // TODO: Return null if the raw decoder doesn't exist. + return PASSTHROUGH_DECODER_INFO; + } + + /** + * Returns information about the preferred decoder for a given mime type. * * @param mimeType The mime type. * @param secure Whether the decoder is required to support secure decryption. Always pass false * unless secure decryption really is required. - * @return Information about the decoder that will be used, or null if no decoder exists. + * @return A {@link DecoderInfo} describing the decoder, or null if no suitable decoder exists. */ public static DecoderInfo getDecoderInfo(String mimeType, boolean secure) throws DecoderQueryException {