Fully reset AudioProcessors on releasing AudioTrack

Issue: #2675

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=153445372
This commit is contained in:
andrewlewis 2017-04-18 03:22:42 -07:00 committed by Oliver Woodman
parent 835839456f
commit e87e2318d8
6 changed files with 30 additions and 13 deletions

View File

@ -152,14 +152,19 @@ public final class GvrAudioProcessor implements AudioProcessor {
@Override
public void flush() {
if (gvrAudioSurround != null) {
gvrAudioSurround.flush();
}
inputEnded = false;
}
@Override
public synchronized void release() {
buffer = null;
public synchronized void reset() {
maybeReleaseGvrAudioSurround();
inputEnded = false;
buffer = null;
sampleRateHz = Format.NO_VALUE;
channelCount = Format.NO_VALUE;
}
private void maybeReleaseGvrAudioSurround() {

View File

@ -116,8 +116,8 @@ public interface AudioProcessor {
void flush();
/**
* Releases any resources associated with this instance.
* Resets the processor to its initial state.
*/
void release();
void reset();
}

View File

@ -1187,7 +1187,7 @@ public final class AudioTrack {
reset();
releaseKeepSessionIdAudioTrack();
for (AudioProcessor audioProcessor : availableAudioProcessors) {
audioProcessor.release();
audioProcessor.reset();
}
audioSessionId = C.AUDIO_SESSION_ID_UNSET;
playing = false;

View File

@ -17,6 +17,7 @@ package com.google.android.exoplayer2.audio;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.C.Encoding;
import com.google.android.exoplayer2.Format;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.Arrays;
@ -43,6 +44,8 @@ import java.util.Arrays;
public ChannelMappingAudioProcessor() {
buffer = EMPTY_BUFFER;
outputBuffer = EMPTY_BUFFER;
channelCount = Format.NO_VALUE;
sampleRateHz = Format.NO_VALUE;
}
/**
@ -147,9 +150,13 @@ import java.util.Arrays;
}
@Override
public void release() {
public void reset() {
flush();
buffer = EMPTY_BUFFER;
channelCount = Format.NO_VALUE;
sampleRateHz = Format.NO_VALUE;
outputChannels = null;
active = false;
}
}

View File

@ -168,9 +168,12 @@ import java.nio.ByteOrder;
}
@Override
public void release() {
public void reset() {
flush();
buffer = EMPTY_BUFFER;
sampleRateHz = Format.NO_VALUE;
channelCount = Format.NO_VALUE;
encoding = C.ENCODING_INVALID;
}
}

View File

@ -58,9 +58,8 @@ import java.nio.ShortBuffer;
private float speed;
private float pitch;
private ShortBuffer shortBuffer;
private ByteBuffer buffer;
private ShortBuffer shortBuffer;
private ByteBuffer outputBuffer;
private long inputBytes;
private long outputBytes;
@ -199,13 +198,16 @@ import java.nio.ShortBuffer;
}
@Override
public void release() {
public void reset() {
sonic = null;
channelCount = Format.NO_VALUE;
sampleRateHz = Format.NO_VALUE;
buffer = EMPTY_BUFFER;
shortBuffer = buffer.asShortBuffer();
outputBuffer = EMPTY_BUFFER;
channelCount = Format.NO_VALUE;
sampleRateHz = Format.NO_VALUE;
inputBytes = 0;
outputBytes = 0;
inputEnded = false;
}
}