summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2012-06-12 18:40:25 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2012-06-12 18:40:25 -0700
commit02bd296991e7e8a17939419cf197a6747ea441de (patch)
treedd72a9f8fc044b802a4ae93415b667e41fb385bf /media
parent92a6141ea0bae283c898a8542604f6b47e226fad (diff)
parentb4ea1ab821d652cb080910d4081f5f1318597a90 (diff)
downloadframeworks_av-02bd296991e7e8a17939419cf197a6747ea441de.zip
frameworks_av-02bd296991e7e8a17939419cf197a6747ea441de.tar.gz
frameworks_av-02bd296991e7e8a17939419cf197a6747ea441de.tar.bz2
am b4ea1ab8: Merge "stagefright: fix AudioRecord callback buffer size" into jb-dev
* commit 'b4ea1ab821d652cb080910d4081f5f1318597a90': stagefright: fix AudioRecord callback buffer size
Diffstat (limited to 'media')
-rw-r--r--media/libstagefright/AudioSource.cpp46
1 files changed, 33 insertions, 13 deletions
diff --git a/media/libstagefright/AudioSource.cpp b/media/libstagefright/AudioSource.cpp
index 0f1d841..72d797e 100644
--- a/media/libstagefright/AudioSource.cpp
+++ b/media/libstagefright/AudioSource.cpp
@@ -56,19 +56,39 @@ AudioSource::AudioSource(
ALOGV("sampleRate: %d, channelCount: %d", sampleRate, channelCount);
CHECK(channelCount == 1 || channelCount == 2);
- AudioRecord::record_flags flags = (AudioRecord::record_flags)
- (AudioRecord::RECORD_AGC_ENABLE |
- AudioRecord::RECORD_NS_ENABLE |
- AudioRecord::RECORD_IIR_ENABLE);
- mRecord = new AudioRecord(
- inputSource, sampleRate, AUDIO_FORMAT_PCM_16_BIT,
- audio_channel_in_mask_from_count(channelCount),
- 4 * kMaxBufferSize / sizeof(int16_t), /* Enable ping-pong buffers */
- flags,
- AudioRecordCallbackFunction,
- this);
-
- mInitCheck = mRecord->initCheck();
+
+ int minFrameCount;
+ status_t status = AudioRecord::getMinFrameCount(&minFrameCount,
+ sampleRate,
+ AUDIO_FORMAT_PCM_16_BIT,
+ channelCount);
+ if (status == OK) {
+ // make sure that the AudioRecord callback never returns more than the maximum
+ // buffer size
+ int frameCount = kMaxBufferSize / sizeof(int16_t) / channelCount;
+
+ // make sure that the AudioRecord total buffer size is large enough
+ int bufCount = 2;
+ while ((bufCount * frameCount) < minFrameCount) {
+ bufCount++;
+ }
+
+ AudioRecord::record_flags flags = (AudioRecord::record_flags)
+ (AudioRecord::RECORD_AGC_ENABLE |
+ AudioRecord::RECORD_NS_ENABLE |
+ AudioRecord::RECORD_IIR_ENABLE);
+ mRecord = new AudioRecord(
+ inputSource, sampleRate, AUDIO_FORMAT_PCM_16_BIT,
+ audio_channel_in_mask_from_count(channelCount),
+ bufCount * frameCount,
+ flags,
+ AudioRecordCallbackFunction,
+ this,
+ frameCount);
+ mInitCheck = mRecord->initCheck();
+ } else {
+ mInitCheck = status;
+ }
}
AudioSource::~AudioSource() {