Commit 54156838 by krocard Committed by Oliver Woodman

Merge `onOutputCodecBypassFormatChanged` and `onOutputFormatChanged`

PiperOrigin-RevId: 319230328
parent 69187523
...@@ -387,11 +387,11 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -387,11 +387,11 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
@Override @Override
protected void configureOutput(Format outputFormat) throws ExoPlaybackException { protected void configureOutput(Format outputFormat) throws ExoPlaybackException {
Format audioSinkInputFormat; Format audioSinkInputFormat;
if (codecPassthroughFormat != null) { @Nullable int[] channelMap = null;
@C.Encoding int passthroughEncoding = getPassthroughEncoding(codecPassthroughFormat); if (codecPassthroughFormat != null) { // Raw codec passthrough
// TODO(b/112299307): Passthrough can have become unavailable since usePassthrough was called. audioSinkInputFormat = getFormatWithEncodingForPassthrough(codecPassthroughFormat);
Assertions.checkState(passthroughEncoding != C.ENCODING_INVALID); } else if (getCodec() == null) { // Codec bypass passthrough
audioSinkInputFormat = outputFormat.buildUpon().setEncoding(passthroughEncoding).build(); audioSinkInputFormat = getFormatWithEncodingForPassthrough(outputFormat);
} else { } else {
MediaFormat mediaFormat = getCodec().getOutputFormat(); MediaFormat mediaFormat = getCodec().getOutputFormat();
@C.Encoding int encoding; @C.Encoding int encoding;
...@@ -407,8 +407,6 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -407,8 +407,6 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
.setChannelCount(mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT)) .setChannelCount(mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT))
.setSampleRate(mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE)) .setSampleRate(mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE))
.build(); .build();
}
@Nullable int[] channelMap = null;
if (codecNeedsDiscardChannelsWorkaround if (codecNeedsDiscardChannelsWorkaround
&& audioSinkInputFormat.channelCount == 6 && audioSinkInputFormat.channelCount == 6
&& outputFormat.channelCount < 6) { && outputFormat.channelCount < 6) {
...@@ -417,21 +415,9 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -417,21 +415,9 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
channelMap[i] = i; channelMap[i] = i;
} }
} }
try {
audioSink.configure(audioSinkInputFormat, /* specifiedBufferSize= */ 0, channelMap);
} catch (AudioSink.ConfigurationException e) {
throw createRendererException(e, outputFormat);
} }
}
@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 { try {
audioSink.configure(format, /* specifiedBufferSize= */ 0, /* outputChannels= */ null); audioSink.configure(audioSinkInputFormat, /* specifiedBufferSize= */ 0, channelMap);
} catch (AudioSink.ConfigurationException e) { } catch (AudioSink.ConfigurationException e) {
throw createRendererException(e, outputFormat); throw createRendererException(e, outputFormat);
} }
...@@ -799,6 +785,13 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -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 * Returns whether the device's decoders are known to not support setting the codec operating
* rate. * rate.
......
...@@ -1514,19 +1514,6 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -1514,19 +1514,6 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
} }
/** /**
* Called when the output {@link Format} changes in bypass mode (no codec used).
*
* <p>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. * Handles supplemental data associated with an input buffer.
* *
* <p>The default implementation is a no-op. * <p>The default implementation is a no-op.
...@@ -2132,7 +2119,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer { ...@@ -2132,7 +2119,7 @@ public abstract class MediaCodecRenderer extends BaseRenderer {
if (!batchBuffer.isEmpty() && waitingForFirstSampleInFormat) { if (!batchBuffer.isEmpty() && waitingForFirstSampleInFormat) {
// This is the first buffer in a new format, the output format must be updated. // This is the first buffer in a new format, the output format must be updated.
outputFormat = Assertions.checkNotNull(inputFormat); outputFormat = Assertions.checkNotNull(inputFormat);
onOutputBypassFormatChanged(outputFormat); onOutputFormatChanged(outputFormat);
waitingForFirstSampleInFormat = false; waitingForFirstSampleInFormat = false;
} }
......
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