summaryrefslogtreecommitdiffstats
path: root/media/libmedia/AudioRecord.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'media/libmedia/AudioRecord.cpp')
-rw-r--r--media/libmedia/AudioRecord.cpp93
1 files changed, 87 insertions, 6 deletions
diff --git a/media/libmedia/AudioRecord.cpp b/media/libmedia/AudioRecord.cpp
index 2725b5b..087a567 100644
--- a/media/libmedia/AudioRecord.cpp
+++ b/media/libmedia/AudioRecord.cpp
@@ -1,7 +1,7 @@
/*
**
** Copyright 2008, The Android Open Source Project
-** Copyright (c) 2011-2012, The Linux Foundation. All rights reserved.
+** Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
@@ -136,6 +136,7 @@ status_t AudioRecord::set(
ALOGV("set(): sampleRate %d, channelMask %#x, frameCount %d",sampleRate, channelMask, frameCount);
AutoMutex lock(mLock);
+ status_t status;
if (mAudioRecord != 0) {
return INVALID_OPERATION;
@@ -185,12 +186,61 @@ status_t AudioRecord::set(
return BAD_VALUE;
}
+#ifdef QCOM_HARDWARE
+ size_t inputBuffSizeInBytes = -1;
+ if (AudioSystem::getInputBufferSize(sampleRate, format, channelCount, &inputBuffSizeInBytes)
+ != NO_ERROR) {
+ ALOGE("AudioSystem could not query the input buffer size.");
+ return NO_INIT;
+ }
+ ALOGV("AudioRecord::set() inputBuffSizeInBytes = %d", inputBuffSizeInBytes );
+
+ if (inputBuffSizeInBytes == 0) {
+ ALOGE("Recording parameters are not supported: sampleRate %d, channelCount %d, format %d",
+ sampleRate, channelCount, format);
+ return BAD_VALUE;
+ }
+
+ // Change for Codec type
+ int frameSizeInBytes = 0;
+ if(inputSource == AUDIO_SOURCE_VOICE_COMMUNICATION) {
+ if (audio_is_linear_pcm(format)) {
+ frameSizeInBytes = channelCount * (format == AUDIO_FORMAT_PCM_16_BIT ? sizeof(int16_t)
+: sizeof(int8_t));
+ } else {
+ frameSizeInBytes = channelCount *sizeof(int16_t);
+ }
+ } else {
+ if (format ==AUDIO_FORMAT_AMR_NB) {
+ frameSizeInBytes = channelCount * 32; // Full rate framesize
+ } else if (format ==AUDIO_FORMAT_EVRC) {
+ frameSizeInBytes = channelCount * 23; // Full rate framesize
+ } else if (format ==AUDIO_FORMAT_QCELP) {
+ frameSizeInBytes = channelCount * 35; // Full rate framesize
+ } else if (format ==AUDIO_FORMAT_AAC) {
+ frameSizeInBytes = 2048;
+ } else if ((format ==AUDIO_FORMAT_PCM_16_BIT) || (format ==AUDIO_FORMAT_PCM_8_BIT)) {
+ if (audio_is_linear_pcm(format)) {
+ frameSizeInBytes = channelCount * (format == AUDIO_FORMAT_PCM_16_BIT ? sizeof(int16_t) : sizeof(int8_t));
+ } else {
+ frameSizeInBytes = sizeof(int8_t);
+ }
+ } else if(format == AUDIO_FORMAT_AMR_WB) {
+ frameSizeInBytes = channelCount * 61;
+
+ }
+ }
+ // We use 2* size of input buffer for ping pong use of record buffer.
+ int minFrameCount = 2 * inputBuffSizeInBytes / frameSizeInBytes;
+#else
// validate framecount
int minFrameCount = 0;
- status_t status = getMinFrameCount(&minFrameCount, sampleRate, format, channelMask);
+ status = getMinFrameCount(&minFrameCount, sampleRate, format, channelMask);
if (status != NO_ERROR) {
return status;
}
+#endif
+
ALOGV("AudioRecord::set() minFrameCount = %d", minFrameCount);
if (frameCount == 0) {
@@ -203,6 +253,10 @@ status_t AudioRecord::set(
notificationFrames = frameCount/2;
}
+#ifdef QCOM_HARDWARE
+ //update mInputSource before openRecord_l
+ mInputSource = inputSource;
+#endif
// create the IAudioRecord
status = openRecord_l(sampleRate, format, channelMask,
frameCount, input);
@@ -233,7 +287,9 @@ status_t AudioRecord::set(
mMarkerReached = false;
mNewPosition = 0;
mUpdatePeriod = 0;
+#ifndef QCOM_HARDWARE
mInputSource = inputSource;
+#endif
mInput = input;
AudioSystem::acquireAudioSessionId(mSessionId);
@@ -269,11 +325,36 @@ uint32_t AudioRecord::frameCount() const
size_t AudioRecord::frameSize() const
{
- if (audio_is_linear_pcm(mFormat)) {
- return channelCount()*audio_bytes_per_sample(mFormat);
+#ifdef QCOM_HARDWARE
+ if(inputSource() == AUDIO_SOURCE_VOICE_COMMUNICATION) {
+ if (audio_is_linear_pcm(mFormat)) {
+ return channelCount()*audio_bytes_per_sample(mFormat);
+ } else {
+ return channelCount()*sizeof(int16_t);
+ }
} else {
- return sizeof(uint8_t);
+ if (format() ==AUDIO_FORMAT_AMR_NB) {
+ return channelCount() * 32; // Full rate framesize
+ } else if (format() == AUDIO_FORMAT_EVRC) {
+ return channelCount() * 23; // Full rate framesize
+ } else if (format() == AUDIO_FORMAT_QCELP) {
+ return channelCount() * 35; // Full rate framesize
+ } else if (format() == AUDIO_FORMAT_AAC) {
+ // Not actual framsize but for variable frame rate AAC encoding,
+ // buffer size is treated as a frame size
+ return 2048;
+ } else if(format() == AUDIO_FORMAT_AMR_WB) {
+ return channelCount() * 61;
+ }
+#endif
+ if (audio_is_linear_pcm(mFormat)) {
+ return channelCount()*audio_bytes_per_sample(mFormat);
+ } else {
+ return sizeof(uint8_t);
+ }
+#ifdef QCOM_HARDWARE
}
+#endif
}
audio_source_t AudioRecord::inputSource() const
@@ -453,7 +534,7 @@ status_t AudioRecord::openRecord_l(
sampleRate, format,
channelMask,
frameCount,
- IAudioFlinger::TRACK_DEFAULT,
+ (int16_t)inputSource(),
tid,
&mSessionId,
&status);