summaryrefslogtreecommitdiffstats
path: root/media/libmedia/AudioRecord.cpp
diff options
context:
space:
mode:
authorGlenn Kasten <gkasten@google.com>2014-02-24 13:42:58 -0800
committerGlenn Kasten <gkasten@google.com>2014-02-25 07:46:35 -0800
commitb42f318d9733f88c7eb9bedfd33b086b8ea5dff5 (patch)
tree5a38a8e40dd8c3ad572a418b2eb7fa08866e0a36 /media/libmedia/AudioRecord.cpp
parentdc6ac201032d0f6ad0c8149ae2f009ec38693025 (diff)
downloadframeworks_av-b42f318d9733f88c7eb9bedfd33b086b8ea5dff5.zip
frameworks_av-b42f318d9733f88c7eb9bedfd33b086b8ea5dff5.tar.gz
frameworks_av-b42f318d9733f88c7eb9bedfd33b086b8ea5dff5.tar.bz2
Simplify and cleanup error handling in AudioRecord::getMinFrameCount
Change-Id: I8721ecedfb429c4e233453d1e768ddf69ecabbe4
Diffstat (limited to 'media/libmedia/AudioRecord.cpp')
-rw-r--r--media/libmedia/AudioRecord.cpp27
1 files changed, 10 insertions, 17 deletions
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index 700718d..10aafed 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -41,30 +41,22 @@ status_t AudioRecord::getMinFrameCount(
return BAD_VALUE;
}
- // default to 0 in case of error
- *frameCount = 0;
-
- size_t size = 0;
+ size_t size;
status_t status = AudioSystem::getInputBufferSize(sampleRate, format, channelMask, &size);
if (status != NO_ERROR) {
- ALOGE("AudioSystem could not query the input buffer size; status %d", status);
- return NO_INIT;
+ ALOGE("AudioSystem could not query the input buffer size for sampleRate %u, format %#x, "
+ "channelMask %#x; status %d", sampleRate, format, channelMask, status);
+ return status;
}
- if (size == 0) {
+ // We double the size of input buffer for ping pong use of record buffer.
+ // Assumes audio_is_linear_pcm(format)
+ if ((*frameCount = (size * 2) / (popcount(channelMask) * audio_bytes_per_sample(format))) == 0) {
ALOGE("Unsupported configuration: sampleRate %u, format %#x, channelMask %#x",
sampleRate, format, channelMask);
return BAD_VALUE;
}
- // We double the size of input buffer for ping pong use of record buffer.
- size <<= 1;
-
- // Assumes audio_is_linear_pcm(format)
- uint32_t channelCount = popcount(channelMask);
- size /= channelCount * audio_bytes_per_sample(format);
-
- *frameCount = size;
return NO_ERROR;
}
@@ -213,11 +205,12 @@ status_t AudioRecord::set(
mFrameSize = channelCount * audio_bytes_per_sample(format);
// validate framecount
- size_t minFrameCount = 0;
+ size_t minFrameCount;
status_t status = AudioRecord::getMinFrameCount(&minFrameCount,
sampleRate, format, channelMask);
if (status != NO_ERROR) {
- ALOGE("getMinFrameCount() failed; status %d", status);
+ ALOGE("getMinFrameCount() failed for sampleRate %u, format %#x, channelMask %#x; status %d",
+ sampleRate, format, channelMask, status);
return status;
}
ALOGV("AudioRecord::set() minFrameCount = %d", minFrameCount);