mirror of
https://github.com/samsonjs/media.git
synced 2026-04-09 11:55:46 +00:00
Don't release AudioTrack unless we have to.
This commit is contained in:
parent
4a745b1cd8
commit
e0a29c841e
1 changed files with 10 additions and 2 deletions
|
|
@ -266,8 +266,6 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer {
|
|||
|
||||
@Override
|
||||
protected void onOutputFormatChanged(MediaFormat format) {
|
||||
releaseAudioTrack();
|
||||
this.sampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
|
||||
int channelCount = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
|
||||
int channelConfig;
|
||||
switch (channelCount) {
|
||||
|
|
@ -283,6 +281,16 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer {
|
|||
default:
|
||||
throw new IllegalArgumentException("Unsupported channel count: " + channelCount);
|
||||
}
|
||||
|
||||
int sampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
|
||||
if (audioTrack != null && this.sampleRate == sampleRate
|
||||
&& this.channelConfig == channelConfig) {
|
||||
// We already have an existing audio track with the correct sample rate and channel config.
|
||||
return;
|
||||
}
|
||||
|
||||
releaseAudioTrack();
|
||||
this.sampleRate = sampleRate;
|
||||
this.channelConfig = channelConfig;
|
||||
this.minBufferSize = AudioTrack.getMinBufferSize(sampleRate, channelConfig,
|
||||
AudioFormat.ENCODING_PCM_16BIT);
|
||||
|
|
|
|||
Loading…
Reference in a new issue