am 3238302b: Merge "media: add AudioRecord::getMinFrameCount()." into gingerbread

Merge commit '3238302b1819bb384b79402c0106a2bdfc3f35d0' into gingerbread-plus-aosp

* commit '3238302b1819bb384b79402c0106a2bdfc3f35d0':
  media: add AudioRecord::getMinFrameCount().
This commit is contained in:
Chia-chi Yeh
2010-06-22 17:22:10 -07:00
committed by Android Git Automerger
2 changed files with 51 additions and 25 deletions

View File

@@ -100,6 +100,19 @@ public:
typedef void (*callback_t)(int event, void* user, void *info); typedef void (*callback_t)(int event, void* user, void *info);
/* Returns the minimum frame count required for the successful creation of
* an AudioRecord object.
* Returned status (from utils/Errors.h) can be:
* - NO_ERROR: successful operation
* - NO_INIT: audio server or audio hardware not initialized
* - BAD_VALUE: unsupported configuration
*/
static status_t getMinFrameCount(int* frameCount,
uint32_t sampleRate,
int format,
int channelCount);
/* Constructs an uninitialized AudioRecord. No connection with /* Constructs an uninitialized AudioRecord. No connection with
* AudioFlinger takes place. * AudioFlinger takes place.
*/ */

View File

@@ -41,6 +41,38 @@
#define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false ))
namespace android { 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 // validate framecount
size_t inputBuffSizeInBytes = -1; int minFrameCount = 0;
if (AudioSystem::getInputBufferSize(sampleRate, format, channelCount, &inputBuffSizeInBytes) status_t status = getMinFrameCount(&minFrameCount, sampleRate, format, channelCount);
!= NO_ERROR) { if (status != NO_ERROR) {
LOGE("AudioSystem could not query the input buffer size."); return status;
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);
}
// 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); LOGV("AudioRecord::set() minFrameCount = %d", minFrameCount);
if (frameCount == 0) { if (frameCount == 0) {
@@ -170,9 +184,8 @@ status_t AudioRecord::set(
mSessionId = sessionId; mSessionId = sessionId;
// create the IAudioRecord // create the IAudioRecord
status_t status = openRecord(sampleRate, format, channelCount, status = openRecord(sampleRate, format, channelCount,
frameCount, flags, input); frameCount, flags, input);
if (status != NO_ERROR) { if (status != NO_ERROR) {
return status; return status;
} }