Merge onOutputCodecBypassFormatChanged and onOutputFormatChanged

PiperOrigin-RevId: 319230328
This commit is contained in:
krocard 2020-07-01 16:33:16 +01:00 committed by Oliver Woodman
parent 69187523b1
commit 541568386b
2 changed files with 20 additions and 40 deletions

View file

@ -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.

View file

@ -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).
*
* <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.
*
@ -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;
}