Fix SonicAudioProcessor
end of stream behavior
The `AudioProcessor` interface requires that no more input is queued after queueing end of stream, but `DefaultAudioSink` did queue more input and the implementation of `SonicAudioProcessor` actually relied on this to drain output at the end of the stream. Fix this behavior by getting `Sonic` output in `getOutput` and having `DefaultAudioSink` only queue input to processors that are not draining. Also add TODOs to clean up audio processor implementations where the code handles interaction that doesn't conform to the interface. PiperOrigin-RevId: 345406478
This commit is contained in:
parent
35173a016b
commit
2516e94eb9
@ -135,6 +135,7 @@ public class GvrAudioProcessor implements AudioProcessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void queueEndOfStream() {
|
public void queueEndOfStream() {
|
||||||
|
// TODO(internal b/174554082): assert gvrAudioSurround is non-null here and in getOutput.
|
||||||
if (gvrAudioSurround != null) {
|
if (gvrAudioSurround != null) {
|
||||||
gvrAudioSurround.triggerProcessing();
|
gvrAudioSurround.triggerProcessing();
|
||||||
}
|
}
|
||||||
|
@ -869,7 +869,9 @@ public final class DefaultAudioSink implements AudioSink {
|
|||||||
writeBuffer(input, avSyncPresentationTimeUs);
|
writeBuffer(input, avSyncPresentationTimeUs);
|
||||||
} else {
|
} else {
|
||||||
AudioProcessor audioProcessor = activeAudioProcessors[index];
|
AudioProcessor audioProcessor = activeAudioProcessors[index];
|
||||||
audioProcessor.queueInput(input);
|
if (index > drainingAudioProcessorIndex) {
|
||||||
|
audioProcessor.queueInput(input);
|
||||||
|
}
|
||||||
ByteBuffer output = audioProcessor.getOutput();
|
ByteBuffer output = audioProcessor.getOutput();
|
||||||
outputBuffers[index] = output;
|
outputBuffers[index] = output;
|
||||||
if (output.hasRemaining()) {
|
if (output.hasRemaining()) {
|
||||||
|
@ -165,32 +165,20 @@ public final class SonicAudioProcessor implements AudioProcessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void queueInput(ByteBuffer inputBuffer) {
|
public void queueInput(ByteBuffer inputBuffer) {
|
||||||
|
if (!inputBuffer.hasRemaining()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
Sonic sonic = checkNotNull(this.sonic);
|
Sonic sonic = checkNotNull(this.sonic);
|
||||||
if (inputBuffer.hasRemaining()) {
|
ShortBuffer shortBuffer = inputBuffer.asShortBuffer();
|
||||||
ShortBuffer shortBuffer = inputBuffer.asShortBuffer();
|
int inputSize = inputBuffer.remaining();
|
||||||
int inputSize = inputBuffer.remaining();
|
inputBytes += inputSize;
|
||||||
inputBytes += inputSize;
|
sonic.queueInput(shortBuffer);
|
||||||
sonic.queueInput(shortBuffer);
|
inputBuffer.position(inputBuffer.position() + inputSize);
|
||||||
inputBuffer.position(inputBuffer.position() + inputSize);
|
|
||||||
}
|
|
||||||
int outputSize = sonic.getOutputSize();
|
|
||||||
if (outputSize > 0) {
|
|
||||||
if (buffer.capacity() < outputSize) {
|
|
||||||
buffer = ByteBuffer.allocateDirect(outputSize).order(ByteOrder.nativeOrder());
|
|
||||||
shortBuffer = buffer.asShortBuffer();
|
|
||||||
} else {
|
|
||||||
buffer.clear();
|
|
||||||
shortBuffer.clear();
|
|
||||||
}
|
|
||||||
sonic.getOutput(shortBuffer);
|
|
||||||
outputBytes += outputSize;
|
|
||||||
buffer.limit(outputSize);
|
|
||||||
outputBuffer = buffer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void queueEndOfStream() {
|
public void queueEndOfStream() {
|
||||||
|
// TODO(internal b/174554082): assert sonic is non-null here and in getOutput.
|
||||||
if (sonic != null) {
|
if (sonic != null) {
|
||||||
sonic.queueEndOfStream();
|
sonic.queueEndOfStream();
|
||||||
}
|
}
|
||||||
@ -199,6 +187,23 @@ public final class SonicAudioProcessor implements AudioProcessor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuffer getOutput() {
|
public ByteBuffer getOutput() {
|
||||||
|
@Nullable Sonic sonic = this.sonic;
|
||||||
|
if (sonic != null) {
|
||||||
|
int outputSize = sonic.getOutputSize();
|
||||||
|
if (outputSize > 0) {
|
||||||
|
if (buffer.capacity() < outputSize) {
|
||||||
|
buffer = ByteBuffer.allocateDirect(outputSize).order(ByteOrder.nativeOrder());
|
||||||
|
shortBuffer = buffer.asShortBuffer();
|
||||||
|
} else {
|
||||||
|
buffer.clear();
|
||||||
|
shortBuffer.clear();
|
||||||
|
}
|
||||||
|
sonic.getOutput(shortBuffer);
|
||||||
|
outputBytes += outputSize;
|
||||||
|
buffer.limit(outputSize);
|
||||||
|
outputBuffer = buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
ByteBuffer outputBuffer = this.outputBuffer;
|
ByteBuffer outputBuffer = this.outputBuffer;
|
||||||
this.outputBuffer = EMPTY_BUFFER;
|
this.outputBuffer = EMPTY_BUFFER;
|
||||||
return outputBuffer;
|
return outputBuffer;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user