Fail on empty AudioRecord read()

If read() returns 0, then there is no data. According to the
documentation, it happens if the buffer is not a direct buffer:
<https://developer.android.com/reference/android/media/AudioRecord#read(java.nio.ByteBuffer,%20int)>

Refs #3812 <https://github.com/Genymobile/scrcpy/issues/3812>
split_workarounds
Romain Vimont 1 year ago
parent 2eced46a37
commit 337d6c2fd3

@ -111,7 +111,7 @@ public final class AudioCapture {
@TargetApi(Build.VERSION_CODES.N)
public int read(ByteBuffer directBuffer, int size, MediaCodec.BufferInfo outBufferInfo) {
int r = recorder.read(directBuffer, size);
if (r < 0) {
if (r <= 0) {
return r;
}

@ -92,7 +92,7 @@ public final class AudioEncoder implements AsyncProcessor {
InputTask task = inputTasks.take();
ByteBuffer buffer = mediaCodec.getInputBuffer(task.index);
int r = capture.read(buffer, READ_SIZE, bufferInfo);
if (r < 0) {
if (r <= 0) {
throw new IOException("Could not read audio: " + r);
}

Loading…
Cancel
Save