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:
parent
2eced46a37
commit
337d6c2fd3
2 changed files with 2 additions and 2 deletions
|
@ -111,7 +111,7 @@ public final class AudioCapture {
|
||||||
@TargetApi(Build.VERSION_CODES.N)
|
@TargetApi(Build.VERSION_CODES.N)
|
||||||
public int read(ByteBuffer directBuffer, int size, MediaCodec.BufferInfo outBufferInfo) {
|
public int read(ByteBuffer directBuffer, int size, MediaCodec.BufferInfo outBufferInfo) {
|
||||||
int r = recorder.read(directBuffer, size);
|
int r = recorder.read(directBuffer, size);
|
||||||
if (r < 0) {
|
if (r <= 0) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -92,7 +92,7 @@ public final class AudioEncoder implements AsyncProcessor {
|
||||||
InputTask task = inputTasks.take();
|
InputTask task = inputTasks.take();
|
||||||
ByteBuffer buffer = mediaCodec.getInputBuffer(task.index);
|
ByteBuffer buffer = mediaCodec.getInputBuffer(task.index);
|
||||||
int r = capture.read(buffer, READ_SIZE, bufferInfo);
|
int r = capture.read(buffer, READ_SIZE, bufferInfo);
|
||||||
if (r < 0) {
|
if (r <= 0) {
|
||||||
throw new IOException("Could not read audio: " + r);
|
throw new IOException("Could not read audio: " + r);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue