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,14 +407,13 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -407,14 +407,13 @@ 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();
} if (codecNeedsDiscardChannelsWorkaround
@Nullable int[] channelMap = null; && audioSinkInputFormat.channelCount == 6
if (codecNeedsDiscardChannelsWorkaround && outputFormat.channelCount < 6) {
&& audioSinkInputFormat.channelCount == 6 channelMap = new int[outputFormat.channelCount];
&& outputFormat.channelCount < 6) { for (int i = 0; i < outputFormat.channelCount; i++) {
channelMap = new int[outputFormat.channelCount]; channelMap[i] = i;
for (int i = 0; i < outputFormat.channelCount; i++) { }
channelMap[i] = i;
} }
} }
try { try {
...@@ -424,19 +423,6 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media ...@@ -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 * Returns the {@link C.Encoding} constant to use for passthrough of the given format, or {@link
* C#ENCODING_INVALID} if passthrough is not possible. * C#ENCODING_INVALID} if passthrough is not possible.
...@@ -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