diff options
author | James Dong <jdong@google.com> | 2010-06-25 09:43:14 -0700 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-06-25 09:43:14 -0700 |
commit | d4b91aac78e565a135f8ef1bfda7e6317debaf35 (patch) | |
tree | 1e5d982ee1114143fb8aa240e189ee8df48d6c7e /media | |
parent | a5522c94a437d9449fba9d8167409f5e357075b6 (diff) | |
parent | d3d4e5069e1af0437c4f5a7b4ba344bda5b937af (diff) | |
download | frameworks_av-d4b91aac78e565a135f8ef1bfda7e6317debaf35.zip frameworks_av-d4b91aac78e565a135f8ef1bfda7e6317debaf35.tar.gz frameworks_av-d4b91aac78e565a135f8ef1bfda7e6317debaf35.tar.bz2 |
Merge "Track maximum amplitude and fix getMaxAmplitude()" into gingerbread
Diffstat (limited to 'media')
-rw-r--r-- | media/libmediaplayerservice/StagefrightRecorder.cpp | 8 | ||||
-rw-r--r-- | media/libmediaplayerservice/StagefrightRecorder.h | 2 | ||||
-rw-r--r-- | media/libstagefright/AudioSource.cpp | 29 |
3 files changed, 38 insertions, 1 deletions
diff --git a/media/libmediaplayerservice/StagefrightRecorder.cpp b/media/libmediaplayerservice/StagefrightRecorder.cpp index d49c4e0..ba04d1b 100644 --- a/media/libmediaplayerservice/StagefrightRecorder.cpp +++ b/media/libmediaplayerservice/StagefrightRecorder.cpp @@ -484,6 +484,7 @@ sp<MediaSource> StagefrightRecorder::createAudioSource() { sp<MediaSource> audioEncoder = OMXCodec::Create(client.interface(), encMeta, true /* createEncoder */, audioSource); + mAudioSourceNode = audioSource; return audioEncoder; } @@ -822,6 +823,7 @@ status_t StagefrightRecorder::reset() { mAudioBitRate = 12200; mInterleaveDurationUs = 0; mIFramesInterval = 1; + mAudioSourceNode = 0; mEncoderProfiles = MediaProfiles::getInstance(); mOutputFd = -1; @@ -831,7 +833,11 @@ status_t StagefrightRecorder::reset() { } status_t StagefrightRecorder::getMaxAmplitude(int *max) { - *max = 0; + if (mAudioSourceNode != 0) { + *max = mAudioSourceNode->getMaxAmplitude(); + } else { + *max = 0; + } return OK; } diff --git a/media/libmediaplayerservice/StagefrightRecorder.h b/media/libmediaplayerservice/StagefrightRecorder.h index 7de96f6..6eedf0c 100644 --- a/media/libmediaplayerservice/StagefrightRecorder.h +++ b/media/libmediaplayerservice/StagefrightRecorder.h @@ -26,6 +26,7 @@ namespace android { class Camera; struct MediaSource; struct MediaWriter; +struct AudioSource; class MediaProfiles; struct StagefrightRecorder : public MediaRecorderBase { @@ -64,6 +65,7 @@ private: sp<ISurface> mPreviewSurface; sp<IMediaPlayerClient> mListener; sp<MediaWriter> mWriter; + sp<AudioSource> mAudioSourceNode; audio_source mAudioSource; video_source mVideoSource; diff --git a/media/libstagefright/AudioSource.cpp b/media/libstagefright/AudioSource.cpp index d203dbf..6031797 100644 --- a/media/libstagefright/AudioSource.cpp +++ b/media/libstagefright/AudioSource.cpp @@ -78,6 +78,8 @@ status_t AudioSource::start(MetaData *params) { mCollectStats = true; } + mTrackMaxAmplitude = false; + mMaxAmplitude = 0; mStartTimeUs = 0; int64_t startTimeUs; if (params && params->findInt64(kKeyTime, &startTimeUs)) { @@ -168,6 +170,10 @@ status_t AudioSource::read( return (status_t)n; } + if (mTrackMaxAmplitude) { + trackMaxAmplitude((int16_t *) buffer->data(), n >> 1); + } + uint32_t sampleRate = mRecord->getSampleRate(); int64_t timestampUs = (1000000LL * numFramesRecorded) / sampleRate + mStartTimeUs; buffer->meta_data()->setInt64(kKeyTime, timestampUs); @@ -181,4 +187,27 @@ status_t AudioSource::read( return OK; } +void AudioSource::trackMaxAmplitude(int16_t *data, int nSamples) { + for (int i = nSamples; i > 0; --i) { + int16_t value = *data++; + if (value < 0) { + value = -value; + } + if (mMaxAmplitude < value) { + mMaxAmplitude = value; + } + } +} + +int16_t AudioSource::getMaxAmplitude() { + // First call activates the tracking. + if (!mTrackMaxAmplitude) { + mTrackMaxAmplitude = true; + } + int16_t value = mMaxAmplitude; + mMaxAmplitude = 0; + LOGV("max amplitude since last call: %d", value); + return value; +} + } // namespace android |