Propagate the correct gapless values in passthrough

Previously the input format values were used,
but it could be incorrect if two format change were
occurring in quick successions.

PiperOrigin-RevId: 310142675
This commit is contained in:
krocard 2020-05-06 14:54:33 +01:00 committed by Oliver Woodman
parent 64b50ba9fc
commit 34327bec5c

View file

@ -411,24 +411,44 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
}
int channelCount = mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
int sampleRate = mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE);
int[] channelMap;
@Nullable int[] channelMap = null;
if (codecNeedsDiscardChannelsWorkaround && channelCount == 6 && inputFormat.channelCount < 6) {
channelMap = new int[inputFormat.channelCount];
for (int i = 0; i < inputFormat.channelCount; i++) {
channelMap[i] = i;
}
} else {
channelMap = null;
}
configureAudioSink(encoding, channelCount, sampleRate, channelMap);
try {
audioSink.configure(
encoding,
channelCount,
sampleRate,
/* specifiedBufferSize= */ 0,
channelMap,
inputFormat.encoderDelay,
inputFormat.encoderPadding);
} catch (AudioSink.ConfigurationException e) {
// TODO(internal: b/145658993) Use outputFormat instead.
throw createRendererException(e, inputFormat);
}
}
@Override
protected void onOutputPassthroughFormatChanged(Format outputFormat) throws ExoPlaybackException {
@C.Encoding
int encoding = getPassthroughEncoding(outputFormat.channelCount, outputFormat.sampleMimeType);
configureAudioSink(
encoding, outputFormat.channelCount, outputFormat.sampleRate, /* channelMap= */ null);
try {
audioSink.configure(
encoding,
outputFormat.channelCount,
outputFormat.sampleRate,
/* specifiedBufferSize= */ 0,
/* outputChannels= */ null,
outputFormat.encoderDelay,
outputFormat.encoderPadding);
} catch (AudioSink.ConfigurationException e) {
throw createRendererException(e, outputFormat);
}
}
/**
@ -766,24 +786,6 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
return mediaFormat;
}
private void configureAudioSink(
int encoding, int channelCount, int sampleRate, @Nullable int[] channelMap)
throws ExoPlaybackException {
try {
audioSink.configure(
encoding,
channelCount,
sampleRate,
/* specifiedBufferSize= */ 0,
channelMap,
inputFormat.encoderDelay,
inputFormat.encoderPadding);
} catch (AudioSink.ConfigurationException e) {
// TODO(internal: b/145658993) Use outputFormat instead.
throw createRendererException(e, inputFormat);
}
}
private void updateCurrentPosition() {
long newCurrentPositionUs = audioSink.getCurrentPositionUs(isEnded());
if (newCurrentPositionUs != AudioSink.CURRENT_POSITION_NOT_SET) {