From 5926e20105ac0fd4d1529f605b4e86526e411ed5 Mon Sep 17 00:00:00 2001 From: andrewlewis Date: Mon, 23 Apr 2018 04:48:28 -0700 Subject: [PATCH] Use the codec MIME type for configuration This may differ from the format MIME type for audio/eac3-joc. Issue: #4165 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=193906521 --- RELEASENOTES.md | 2 ++ .../audio/MediaCodecAudioRenderer.java | 15 ++++++------- .../exoplayer2/mediacodec/MediaCodecInfo.java | 21 ++++++++++--------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index a4febb07b65..747cdcd14cd 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -49,6 +49,8 @@ * Fix an issue where playback of TrueHD streams would get stuck after seeking due to not finding a syncframe ((#3845)[https://github.com/google/ExoPlayer/issues/3845]). + * Fix an issue with eac3-joc playback where a codec would fail to configure + ((#4165)[https://github.com/google/ExoPlayer/issues/4165]). * Handle non-empty end-of-stream buffers, to fix gapless playback of streams with encoder padding when the decoder returns a non-empty final buffer. * Allow trimming more than one sample when applying an elst audio edit via diff --git a/library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java index c73081e2ab2..c0a88c52d58 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/audio/MediaCodecAudioRenderer.java @@ -259,15 +259,14 @@ protected void configureCodec(MediaCodecInfo codecInfo, MediaCodec codec, Format MediaCrypto crypto) { codecMaxInputSize = getCodecMaxInputSize(format, getStreamFormats()); codecNeedsDiscardChannelsWorkaround = codecNeedsDiscardChannelsWorkaround(codecInfo.name); - MediaFormat mediaFormat = getMediaFormat(format, codecMaxInputSize); + String codecMimeType = codecInfo.mimeType == null ? MimeTypes.AUDIO_RAW : codecInfo.mimeType; + MediaFormat mediaFormat = getMediaFormat(format, codecMimeType, codecMaxInputSize); + codec.configure(mediaFormat, /* surface= */ null, crypto, /* flags= */ 0); if (passthroughEnabled) { - // Override the MIME type used to configure the codec if we are using a passthrough decoder. + // Store the input MIME type if we're using the passthrough codec. passthroughMediaFormat = mediaFormat; - passthroughMediaFormat.setString(MediaFormat.KEY_MIME, MimeTypes.AUDIO_RAW); - codec.configure(passthroughMediaFormat, null, crypto, 0); passthroughMediaFormat.setString(MediaFormat.KEY_MIME, format.sampleMimeType); } else { - codec.configure(mediaFormat, null, crypto, 0); passthroughMediaFormat = null; } } @@ -535,13 +534,15 @@ protected int getCodecMaxInputSize(Format format, Format[] streamFormats) { * for decoding the given {@link Format} for playback. * * @param format The format of the media. + * @param codecMimeType The MIME type handled by the codec. + * @param codecMaxInputSize The maximum input size supported by the codec. * @return The framework media format. */ @SuppressLint("InlinedApi") - protected MediaFormat getMediaFormat(Format format, int codecMaxInputSize) { + protected MediaFormat getMediaFormat(Format format, String codecMimeType, int codecMaxInputSize) { MediaFormat mediaFormat = new MediaFormat(); // Set format parameters that should always be set. - mediaFormat.setString(MediaFormat.KEY_MIME, format.sampleMimeType); + mediaFormat.setString(MediaFormat.KEY_MIME, codecMimeType); mediaFormat.setInteger(MediaFormat.KEY_CHANNEL_COUNT, format.channelCount); mediaFormat.setInteger(MediaFormat.KEY_SAMPLE_RATE, format.sampleRate); MediaFormatUtil.setCsdBuffers(mediaFormat, format.initializationData); diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java index cd33051bd23..852c34ba5e0 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecInfo.java @@ -52,6 +52,15 @@ public final class MediaCodecInfo { */ public final String name; + /** The MIME type handled by the codec, or {@code null} if this is a passthrough codec. */ + public final @Nullable String mimeType; + + /** + * The capabilities of the decoder, like the profiles/levels it supports, or {@code null} if this + * is a passthrough codec. + */ + public final @Nullable CodecCapabilities capabilities; + /** * Whether the decoder supports seamless resolution switches. * @@ -76,14 +85,6 @@ public final class MediaCodecInfo { */ public final boolean secure; - /** - * The capabilities of the decoder, like the profiles/levels it supports, or {@code null} if this - * is a passthrough codec. - */ - public final @Nullable CodecCapabilities capabilities; - - private final String mimeType; - /** * Creates an instance representing an audio passthrough decoder. * @@ -134,13 +135,13 @@ public static MediaCodecInfo newInstance( private MediaCodecInfo( String name, - String mimeType, + @Nullable String mimeType, @Nullable CodecCapabilities capabilities, boolean forceDisableAdaptive, boolean forceSecure) { this.name = Assertions.checkNotNull(name); - this.capabilities = capabilities; this.mimeType = mimeType; + this.capabilities = capabilities; adaptive = !forceDisableAdaptive && capabilities != null && isAdaptive(capabilities); tunneling = capabilities != null && isTunneling(capabilities); secure = forceSecure || (capabilities != null && isSecure(capabilities));