mirror of
https://github.com/samsonjs/media.git
synced 2026-04-13 12:35:48 +00:00
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:
parent
64b50ba9fc
commit
34327bec5c
1 changed files with 26 additions and 24 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue