diff options
author | Andreas Huber <andih@google.com> | 2012-08-30 10:56:14 -0700 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2012-08-30 10:56:14 -0700 |
commit | 082830f92373a1b9e512dbbfb940187ffa1c2c6f (patch) | |
tree | 46124186416264ddfe73a0dfabe4974777ff0405 /media/libstagefright/AudioSource.cpp | |
parent | e05a679401c7baeb0f82ce105eb20ae1ec863cdf (diff) | |
download | frameworks_av-082830f92373a1b9e512dbbfb940187ffa1c2c6f.zip frameworks_av-082830f92373a1b9e512dbbfb940187ffa1c2c6f.tar.gz frameworks_av-082830f92373a1b9e512dbbfb940187ffa1c2c6f.tar.bz2 |
Prepare for transmitting audio through AudioSource.
AudioSource can now be configured to output buffers timestamped based
on looper time (absolute) instead of based on systemTime() relative to
start time.
Change-Id: I8eca42648eb50033ac4aafbe5daac64a98a40690
Diffstat (limited to 'media/libstagefright/AudioSource.cpp')
-rw-r--r-- | media/libstagefright/AudioSource.cpp | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/media/libstagefright/AudioSource.cpp b/media/libstagefright/AudioSource.cpp index ed142a4..3248dbc 100644 --- a/media/libstagefright/AudioSource.cpp +++ b/media/libstagefright/AudioSource.cpp @@ -24,6 +24,7 @@ #include <media/stagefright/MediaDefs.h> #include <media/stagefright/MetaData.h> #include <media/stagefright/foundation/ADebug.h> +#include <media/stagefright/foundation/ALooper.h> #include <cutils/properties.h> #include <stdlib.h> @@ -33,7 +34,7 @@ static void AudioRecordCallbackFunction(int event, void *user, void *info) { AudioSource *source = (AudioSource *) user; switch (event) { case AudioRecord::EVENT_MORE_DATA: { - source->dataCallbackTimestamp(*((AudioRecord::Buffer *) info), systemTime() / 1000); + source->dataCallback(*((AudioRecord::Buffer *) info)); break; } case AudioRecord::EVENT_OVERRUN: { @@ -53,7 +54,8 @@ AudioSource::AudioSource( mSampleRate(sampleRate), mPrevSampleTimeUs(0), mNumFramesReceived(0), - mNumClientOwnedBuffers(0) { + mNumClientOwnedBuffers(0), + mUseLooperTime(false) { ALOGV("sampleRate: %d, channelCount: %d", sampleRate, channelCount); CHECK(channelCount == 1 || channelCount == 2); @@ -100,6 +102,12 @@ status_t AudioSource::initCheck() const { return mInitCheck; } +void AudioSource::setUseLooperTime(bool useLooperTime) { + CHECK(!mStarted); + + mUseLooperTime = useLooperTime; +} + status_t AudioSource::start(MetaData *params) { Mutex::Autolock autoLock(mLock); if (mStarted) { @@ -271,8 +279,10 @@ void AudioSource::signalBufferReturned(MediaBuffer *buffer) { return; } -status_t AudioSource::dataCallbackTimestamp( - const AudioRecord::Buffer& audioBuffer, int64_t timeUs) { +status_t AudioSource::dataCallback(const AudioRecord::Buffer& audioBuffer) { + int64_t timeUs = + mUseLooperTime ? ALooper::GetNowUs() : (systemTime() / 1000ll); + ALOGV("dataCallbackTimestamp: %lld us", timeUs); Mutex::Autolock autoLock(mLock); if (!mStarted) { @@ -290,12 +300,15 @@ status_t AudioSource::dataCallbackTimestamp( if (mNumFramesReceived == 0 && mPrevSampleTimeUs == 0) { mInitialReadTimeUs = timeUs; // Initial delay - if (mStartTimeUs > 0) { + if (mUseLooperTime) { + mStartTimeUs = timeUs; + } else if (mStartTimeUs > 0) { mStartTimeUs = timeUs - mStartTimeUs; } else { // Assume latency is constant. mStartTimeUs += mRecord->latency() * 1000; } + mPrevSampleTimeUs = mStartTimeUs; } |