mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +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
|
@Override
|
||||||
protected void onOutputFormatChanged(MediaFormat format) {
|
protected void onOutputFormatChanged(MediaFormat format) {
|
||||||
releaseAudioTrack();
|
|
||||||
this.sampleRate = format.getInteger(MediaFormat.KEY_SAMPLE_RATE);
|
|
||||||
int channelCount = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
|
int channelCount = format.getInteger(MediaFormat.KEY_CHANNEL_COUNT);
|
||||||
int channelConfig;
|
int channelConfig;
|
||||||
switch (channelCount) {
|
switch (channelCount) {
|
||||||
|
|
@ -283,6 +281,16 @@ public class MediaCodecAudioTrackRenderer extends MediaCodecTrackRenderer {
|
||||||
default:
|
default:
|
||||||
throw new IllegalArgumentException("Unsupported channel count: " + channelCount);
|
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.channelConfig = channelConfig;
|
||||||
this.minBufferSize = AudioTrack.getMinBufferSize(sampleRate, channelConfig,
|
this.minBufferSize = AudioTrack.getMinBufferSize(sampleRate, channelConfig,
|
||||||
AudioFormat.ENCODING_PCM_16BIT);
|
AudioFormat.ENCODING_PCM_16BIT);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue