summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorChia-chi Yeh <chiachi@android.com>2010-06-22 17:20:44 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2010-06-22 17:20:44 -0700
commit3238302b1819bb384b79402c0106a2bdfc3f35d0 (patch)
treee7df1b81e1117b7083fa6561a052aa6de144d3c6 /media
parentd1559d6b2db1d7e1718a15dc43a82450de2934db (diff)
parent97d61f751899d3d68f53fb14d0025766bf1be3f7 (diff)
downloadframeworks_base-3238302b1819bb384b79402c0106a2bdfc3f35d0.zip
frameworks_base-3238302b1819bb384b79402c0106a2bdfc3f35d0.tar.gz
frameworks_base-3238302b1819bb384b79402c0106a2bdfc3f35d0.tar.bz2
Merge "media: add AudioRecord::getMinFrameCount()." into gingerbread
Diffstat (limited to 'media')
-rw-r--r--media/libmedia/AudioRecord.cpp63
1 files changed, 38 insertions, 25 deletions
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index a2436ab..a6c515c 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -41,6 +41,38 @@
#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
namespace android {
+// ---------------------------------------------------------------------------
+
+// static
+status_t AudioRecord::getMinFrameCount(
+ int* frameCount,
+ uint32_t sampleRate,
+ int format,
+ int channelCount)
+{
+ size_t size = 0;
+ if (AudioSystem::getInputBufferSize(sampleRate, format, channelCount, &size)
+ != NO_ERROR) {
+ LOGE("AudioSystem could not query the input buffer size.");
+ return NO_INIT;
+ }
+
+ if (size == 0) {
+ LOGE("Unsupported configuration: sampleRate %d, format %d, channelCount %d",
+ sampleRate, format, channelCount);
+ return BAD_VALUE;
+ }
+
+ // We double the size of input buffer for ping pong use of record buffer.
+ size <<= 1;
+
+ if (AudioSystem::isLinearPCM(format)) {
+ size /= channelCount * (format == AudioSystem::PCM_16_BIT ? 2 : 1);
+ }
+
+ *frameCount = size;
+ return NO_ERROR;
+}
// ---------------------------------------------------------------------------
@@ -132,29 +164,11 @@ status_t AudioRecord::set(
}
// validate framecount
- size_t inputBuffSizeInBytes = -1;
- if (AudioSystem::getInputBufferSize(sampleRate, format, channelCount, &inputBuffSizeInBytes)
- != NO_ERROR) {
- LOGE("AudioSystem could not query the input buffer size.");
- return NO_INIT;
- }
-
- if (inputBuffSizeInBytes == 0) {
- LOGE("Recording parameters are not supported: sampleRate %d, channelCount %d, format %d",
- sampleRate, channelCount, format);
- return BAD_VALUE;
- }
-
- int frameSizeInBytes = channelCount * (format == AudioSystem::PCM_16_BIT ? 2 : 1);
- if (AudioSystem::isLinearPCM(format)) {
- frameSizeInBytes = channelCount * (format == AudioSystem::PCM_16_BIT ? sizeof(int16_t) : sizeof(int8_t));
- } else {
- frameSizeInBytes = sizeof(int8_t);
+ int minFrameCount = 0;
+ status_t status = getMinFrameCount(&minFrameCount, sampleRate, format, channelCount);
+ if (status != NO_ERROR) {
+ return status;
}
-
-
- // We use 2* size of input buffer for ping pong use of record buffer.
- int minFrameCount = 2 * inputBuffSizeInBytes / frameSizeInBytes;
LOGV("AudioRecord::set() minFrameCount = %d", minFrameCount);
if (frameCount == 0) {
@@ -170,9 +184,8 @@ status_t AudioRecord::set(
mSessionId = sessionId;
// create the IAudioRecord
- status_t status = openRecord(sampleRate, format, channelCount,
- frameCount, flags, input);
-
+ status = openRecord(sampleRate, format, channelCount,
+ frameCount, flags, input);
if (status != NO_ERROR) {
return status;
}