diff options
author | Glenn Kasten <gkasten@google.com> | 2015-03-20 10:58:21 -0700 |
---|---|---|
committer | Glenn Kasten <gkasten@google.com> | 2015-03-23 14:53:01 -0700 |
commit | 3622cdff65f34a99d2f55936a895387ad41510ce (patch) | |
tree | c6af21a8fb7d4252d0ac78e542bb1baa5ae29f17 | |
parent | 4c36d6f48f4eecacc148317f775f65961a4f03d2 (diff) | |
download | frameworks_av-3622cdff65f34a99d2f55936a895387ad41510ce.zip frameworks_av-3622cdff65f34a99d2f55936a895387ad41510ce.tar.gz frameworks_av-3622cdff65f34a99d2f55936a895387ad41510ce.tar.bz2 |
AudioRecord::read() can be non-blocking to match AudioTrack
Change-Id: I23b9466b81ab6037d0bccd5e6f5974b7bd4aeacb
-rw-r--r-- | include/media/AudioRecord.h | 5 | ||||
-rw-r--r-- | media/libmedia/AudioRecord.cpp | 5 |
2 files changed, 7 insertions, 3 deletions
diff --git a/include/media/AudioRecord.h b/include/media/AudioRecord.h index c503f25..63d2e20 100644 --- a/include/media/AudioRecord.h +++ b/include/media/AudioRecord.h @@ -406,8 +406,11 @@ public: * WOULD_BLOCK when obtainBuffer() returns same, or * AudioRecord was stopped during the read * or any other error code returned by IAudioRecord::start() or restoreRecord_l(). + * Default behavior is to only return when all data has been transferred. Set 'blocking' to + * false for the method to return immediately without waiting to try multiple times to read + * the full content of the buffer. */ - ssize_t read(void* buffer, size_t size); + ssize_t read(void* buffer, size_t size, bool blocking = true); /* Return the number of input frames lost in the audio driver since the last call of this * function. Audio driver is expected to reset the value to 0 and restart counting upon diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp index 1a65ee8..2ed9221 100644 --- a/media/libmedia/AudioRecord.cpp +++ b/media/libmedia/AudioRecord.cpp @@ -722,7 +722,7 @@ audio_io_handle_t AudioRecord::getInputPrivate() const // ------------------------------------------------------------------------- -ssize_t AudioRecord::read(void* buffer, size_t userSize) +ssize_t AudioRecord::read(void* buffer, size_t userSize, bool blocking) { if (mTransfer != TRANSFER_SYNC) { return INVALID_OPERATION; @@ -741,7 +741,8 @@ ssize_t AudioRecord::read(void* buffer, size_t userSize) while (userSize >= mFrameSize) { audioBuffer.frameCount = userSize / mFrameSize; - status_t err = obtainBuffer(&audioBuffer, &ClientProxy::kForever); + status_t err = obtainBuffer(&audioBuffer, + blocking ? &ClientProxy::kForever : &ClientProxy::kNonBlocking); if (err < 0) { if (read > 0) { break; |