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>
This commit is contained in:
Romain Vimont 2023-03-14 19:26:37 +01:00
parent 2eced46a37
commit 337d6c2fd3
2 changed files with 2 additions and 2 deletions

View File

@ -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;
}

View File

@ -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);
}