Skip to content

Commit

Permalink
Fail on empty AudioRecord read()
Browse files Browse the repository at this point in the history
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 <#3812>
  • Loading branch information
rom1v committed Mar 14, 2023
1 parent 2eced46 commit 337d6c2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public void stop() {
@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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void inputThread(MediaCodec mediaCodec, AudioCapture capture) throws IOE
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);
}

Expand Down

0 comments on commit 337d6c2

Please sign in to comment.