mirror of
https://github.com/samsonjs/media.git
synced 2026-04-13 12:35:48 +00:00
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
This commit is contained in:
parent
945471452f
commit
351b54e97f
2 changed files with 35 additions and 10 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue