Loading include/media/stagefright/AudioSource.h +7 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,9 @@ struct AudioSource : public MediaSource { virtual status_t stop(); virtual sp<MetaData> getFormat(); // Returns the maximum amplitude since last call. int16_t getMaxAmplitude(); virtual status_t read( MediaBuffer **buffer, const ReadOptions *options = NULL); Loading @@ -53,13 +56,17 @@ private: bool mStarted; bool mCollectStats; bool mTrackMaxAmplitude; int64_t mTotalReadTimeUs; int64_t mTotalReadBytes; int64_t mTotalReads; int64_t mStartTimeUs; int16_t mMaxAmplitude; MediaBufferGroup *mGroup; void trackMaxAmplitude(int16_t *data, int nSamples); AudioSource(const AudioSource &); AudioSource &operator=(const AudioSource &); }; Loading media/libmediaplayerservice/StagefrightRecorder.cpp +7 −1 Original line number Diff line number Diff line Loading @@ -484,6 +484,7 @@ sp<MediaSource> StagefrightRecorder::createAudioSource() { sp<MediaSource> audioEncoder = OMXCodec::Create(client.interface(), encMeta, true /* createEncoder */, audioSource); mAudioSourceNode = audioSource; return audioEncoder; } Loading Loading @@ -822,6 +823,7 @@ status_t StagefrightRecorder::reset() { mAudioBitRate = 12200; mInterleaveDurationUs = 0; mIFramesInterval = 1; mAudioSourceNode = 0; mEncoderProfiles = MediaProfiles::getInstance(); mOutputFd = -1; Loading @@ -831,7 +833,11 @@ status_t StagefrightRecorder::reset() { } status_t StagefrightRecorder::getMaxAmplitude(int *max) { if (mAudioSourceNode != 0) { *max = mAudioSourceNode->getMaxAmplitude(); } else { *max = 0; } return OK; } Loading media/libmediaplayerservice/StagefrightRecorder.h +2 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ namespace android { class Camera; struct MediaSource; struct MediaWriter; struct AudioSource; class MediaProfiles; struct StagefrightRecorder : public MediaRecorderBase { Loading Loading @@ -64,6 +65,7 @@ private: sp<ISurface> mPreviewSurface; sp<IMediaPlayerClient> mListener; sp<MediaWriter> mWriter; sp<AudioSource> mAudioSourceNode; audio_source mAudioSource; video_source mVideoSource; Loading media/libstagefright/AudioSource.cpp +29 −0 Original line number Diff line number Diff line Loading @@ -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)) { Loading Loading @@ -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); Loading @@ -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 Loading
include/media/stagefright/AudioSource.h +7 −0 Original line number Diff line number Diff line Loading @@ -39,6 +39,9 @@ struct AudioSource : public MediaSource { virtual status_t stop(); virtual sp<MetaData> getFormat(); // Returns the maximum amplitude since last call. int16_t getMaxAmplitude(); virtual status_t read( MediaBuffer **buffer, const ReadOptions *options = NULL); Loading @@ -53,13 +56,17 @@ private: bool mStarted; bool mCollectStats; bool mTrackMaxAmplitude; int64_t mTotalReadTimeUs; int64_t mTotalReadBytes; int64_t mTotalReads; int64_t mStartTimeUs; int16_t mMaxAmplitude; MediaBufferGroup *mGroup; void trackMaxAmplitude(int16_t *data, int nSamples); AudioSource(const AudioSource &); AudioSource &operator=(const AudioSource &); }; Loading
media/libmediaplayerservice/StagefrightRecorder.cpp +7 −1 Original line number Diff line number Diff line Loading @@ -484,6 +484,7 @@ sp<MediaSource> StagefrightRecorder::createAudioSource() { sp<MediaSource> audioEncoder = OMXCodec::Create(client.interface(), encMeta, true /* createEncoder */, audioSource); mAudioSourceNode = audioSource; return audioEncoder; } Loading Loading @@ -822,6 +823,7 @@ status_t StagefrightRecorder::reset() { mAudioBitRate = 12200; mInterleaveDurationUs = 0; mIFramesInterval = 1; mAudioSourceNode = 0; mEncoderProfiles = MediaProfiles::getInstance(); mOutputFd = -1; Loading @@ -831,7 +833,11 @@ status_t StagefrightRecorder::reset() { } status_t StagefrightRecorder::getMaxAmplitude(int *max) { if (mAudioSourceNode != 0) { *max = mAudioSourceNode->getMaxAmplitude(); } else { *max = 0; } return OK; } Loading
media/libmediaplayerservice/StagefrightRecorder.h +2 −0 Original line number Diff line number Diff line Loading @@ -26,6 +26,7 @@ namespace android { class Camera; struct MediaSource; struct MediaWriter; struct AudioSource; class MediaProfiles; struct StagefrightRecorder : public MediaRecorderBase { Loading Loading @@ -64,6 +65,7 @@ private: sp<ISurface> mPreviewSurface; sp<IMediaPlayerClient> mListener; sp<MediaWriter> mWriter; sp<AudioSource> mAudioSourceNode; audio_source mAudioSource; video_source mVideoSource; Loading
media/libstagefright/AudioSource.cpp +29 −0 Original line number Diff line number Diff line Loading @@ -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)) { Loading Loading @@ -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); Loading @@ -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