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 f8e1b991f2..b2bd454440 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 @@ -387,11 +387,11 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media @Override protected void configureOutput(Format outputFormat) throws ExoPlaybackException { Format audioSinkInputFormat; - if (codecPassthroughFormat != null) { - @C.Encoding int passthroughEncoding = getPassthroughEncoding(codecPassthroughFormat); - // TODO(b/112299307): Passthrough can have become unavailable since usePassthrough was called. - Assertions.checkState(passthroughEncoding != C.ENCODING_INVALID); - audioSinkInputFormat = outputFormat.buildUpon().setEncoding(passthroughEncoding).build(); + @Nullable int[] channelMap = null; + if (codecPassthroughFormat != null) { // Raw codec passthrough + audioSinkInputFormat = getFormatWithEncodingForPassthrough(codecPassthroughFormat); + } else if (getCodec() == null) { // Codec bypass passthrough + audioSinkInputFormat = getFormatWithEncodingForPassthrough(outputFormat); } else { MediaFormat mediaFormat = getCodec().getOutputFormat(); @C.Encoding int encoding; @@ -407,14 +407,13 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media .setChannelCount(mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT)) .setSampleRate(mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE)) .build(); - } - @Nullable int[] channelMap = null; - if (codecNeedsDiscardChannelsWorkaround - && audioSinkInputFormat.channelCount == 6 - && outputFormat.channelCount < 6) { - channelMap = new int[outputFormat.channelCount]; - for (int i = 0; i < outputFormat.channelCount; i++) { - channelMap[i] = i; + if (codecNeedsDiscardChannelsWorkaround + && audioSinkInputFormat.channelCount == 6 + && outputFormat.channelCount < 6) { + channelMap = new int[outputFormat.channelCount]; + for (int i = 0; i < outputFormat.channelCount; i++) { + channelMap[i] = i; + } } } try { @@ -424,19 +423,6 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media } } - @Override - protected void onOutputBypassFormatChanged(Format outputFormat) throws ExoPlaybackException { - @C.Encoding int passthroughEncoding = getPassthroughEncoding(outputFormat); - // TODO(b/112299307): Passthrough can have become unavailable since usePassthrough was called. - Assertions.checkState(passthroughEncoding != C.ENCODING_INVALID); - Format format = outputFormat.buildUpon().setEncoding(passthroughEncoding).build(); - try { - audioSink.configure(format, /* specifiedBufferSize= */ 0, /* outputChannels= */ null); - } catch (AudioSink.ConfigurationException e) { - throw createRendererException(e, outputFormat); - } - } - /** * Returns the {@link C.Encoding} constant to use for passthrough of the given format, or {@link * C#ENCODING_INVALID} if passthrough is not possible. @@ -799,6 +785,13 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media } } + private Format getFormatWithEncodingForPassthrough(Format outputFormat) { + @C.Encoding int passthroughEncoding = getPassthroughEncoding(outputFormat); + // TODO(b/112299307): Passthrough can have become unavailable since usePassthrough was called. + Assertions.checkState(passthroughEncoding != C.ENCODING_INVALID); + return outputFormat.buildUpon().setEncoding(passthroughEncoding).build(); + } + /** * Returns whether the device's decoders are known to not support setting the codec operating * rate. diff --git a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java index d50b9b31de..12aacaed51 100644 --- a/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java +++ b/library/core/src/main/java/com/google/android/exoplayer2/mediacodec/MediaCodecRenderer.java @@ -1513,19 +1513,6 @@ public abstract class MediaCodecRenderer extends BaseRenderer { // Do nothing. } - /** - * Called when the output {@link Format} changes in bypass mode (no codec used). - * - *
The default implementation is a no-op. - * - * @param outputFormat The new output {@link MediaFormat}. - * @throws ExoPlaybackException Thrown if an error occurs handling the new output media format. - */ - // TODO(b/154849417): merge with {@link #onOutputFormatChanged(Format)}. - protected void onOutputBypassFormatChanged(Format outputFormat) throws ExoPlaybackException { - // Do nothing. - } - /** * Handles supplemental data associated with an input buffer. * @@ -2132,7 +2119,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer { if (!batchBuffer.isEmpty() && waitingForFirstSampleInFormat) { // This is the first buffer in a new format, the output format must be updated. outputFormat = Assertions.checkNotNull(inputFormat); - onOutputBypassFormatChanged(outputFormat); + onOutputFormatChanged(outputFormat); waitingForFirstSampleInFormat = false; }