Commit 351b54e9 by olly Committed by kim-vde

Pass correct Format to AudioSink.configure

Building on the Format that was provided on the input side of the
decoder creates a format that's a mixture of the formats on the
input and output sides of the decoder. This change instead builds
a PCM format from scratch.

PiperOrigin-RevId: 320405656
parent 94547145
......@@ -398,16 +398,18 @@ public class MediaCodecAudioRenderer extends MediaCodecRenderer implements Media
audioSinkInputFormat = getFormatWithEncodingForPassthrough(outputFormat);
} else {
MediaFormat mediaFormat = getCodec().getOutputFormat();
@C.Encoding int encoding;
@C.PcmEncoding int pcmEncoding;
if (mediaFormat.containsKey(VIVO_BITS_PER_SAMPLE_KEY)) {
encoding = Util.getPcmEncoding(mediaFormat.getInteger(VIVO_BITS_PER_SAMPLE_KEY));
pcmEncoding = Util.getPcmEncoding(mediaFormat.getInteger(VIVO_BITS_PER_SAMPLE_KEY));
} else {
encoding = getPcmEncoding(outputFormat);
pcmEncoding = getPcmEncoding(outputFormat);
}
audioSinkInputFormat =
outputFormat
.buildUpon()
.setEncoding(encoding)
new Format.Builder()
.setSampleMimeType(MimeTypes.AUDIO_RAW)
.setEncoding(pcmEncoding)
.setEncoderDelay(outputFormat.encoderDelay)
.setEncoderPadding(outputFormat.encoderPadding)
.setChannelCount(mediaFormat.getInteger(MediaFormat.KEY_CHANNEL_COUNT))
.setSampleRate(mediaFormat.getInteger(MediaFormat.KEY_SAMPLE_RATE))
.build();
......
......@@ -147,10 +147,16 @@ public class MediaCodecAudioRendererTest {
} while (!mediaCodecAudioRenderer.isEnded());
verify(audioSink)
.configure(AUDIO_AAC, /* specifiedBufferSize= */ 0, /* outputChannels= */ null);
.configure(
getAudioSinkFormat(AUDIO_AAC),
/* specifiedBufferSize= */ 0,
/* outputChannels= */ null);
verify(audioSink)
.configure(changedFormat, /* specifiedBufferSize= */ 0, /* outputChannels= */ null);
.configure(
getAudioSinkFormat(changedFormat),
/* specifiedBufferSize= */ 0,
/* outputChannels= */ null);
}
@Test
......@@ -195,10 +201,16 @@ public class MediaCodecAudioRendererTest {
} while (!mediaCodecAudioRenderer.isEnded());
verify(audioSink)
.configure(AUDIO_AAC, /* specifiedBufferSize= */ 0, /* outputChannels= */ null);
.configure(
getAudioSinkFormat(AUDIO_AAC),
/* specifiedBufferSize= */ 0,
/* outputChannels= */ null);
verify(audioSink)
.configure(changedFormat, /* specifiedBufferSize= */ 0, /* outputChannels= */ null);
.configure(
getAudioSinkFormat(changedFormat),
/* specifiedBufferSize= */ 0,
/* outputChannels= */ null);
}
@Test
......@@ -261,4 +273,15 @@ public class MediaCodecAudioRendererTest {
// render.
exceptionThrowingRenderer.render(/* positionUs= */ 750, SystemClock.elapsedRealtime() * 1000);
}
private static Format getAudioSinkFormat(Format inputFormat) {
return new Format.Builder()
.setSampleMimeType(MimeTypes.AUDIO_RAW)
.setEncoding(C.ENCODING_PCM_16BIT)
.setChannelCount(inputFormat.channelCount)
.setSampleRate(inputFormat.sampleRate)
.setEncoderDelay(inputFormat.encoderDelay)
.setEncoderPadding(inputFormat.encoderPadding)
.build();
}
}
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