summaryrefslogtreecommitdiffstats
path: root/media/libstagefright
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2012-08-30 10:56:14 -0700
committerAndreas Huber <andih@google.com>2012-08-30 10:56:14 -0700
commit082830f92373a1b9e512dbbfb940187ffa1c2c6f (patch)
tree46124186416264ddfe73a0dfabe4974777ff0405 /media/libstagefright
parente05a679401c7baeb0f82ce105eb20ae1ec863cdf (diff)
downloadframeworks_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')
-rw-r--r--media/libstagefright/AudioSource.cpp23
-rw-r--r--media/libstagefright/wifi-display/source/PlaybackSession.cpp27
2 files changed, 45 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;
}
diff --git a/media/libstagefright/wifi-display/source/PlaybackSession.cpp b/media/libstagefright/wifi-display/source/PlaybackSession.cpp
index 53d27c1..c99a11e 100644
--- a/media/libstagefright/wifi-display/source/PlaybackSession.cpp
+++ b/media/libstagefright/wifi-display/source/PlaybackSession.cpp
@@ -32,6 +32,7 @@
#include <media/stagefright/foundation/ADebug.h>
#include <media/stagefright/foundation/AMessage.h>
#include <media/stagefright/foundation/hexdump.h>
+#include <media/stagefright/AudioSource.h>
#include <media/stagefright/DataSource.h>
#include <media/stagefright/MediaDefs.h>
#include <media/stagefright/MediaErrors.h>
@@ -649,6 +650,32 @@ status_t WifiDisplaySource::PlaybackSession::setupPacketizer() {
mTracks.add(index, new Track(converter));
#endif
+#if 0
+ sp<AudioSource> audioSource = new AudioSource(
+ AUDIO_SOURCE_MIC,
+ 48000 /* sampleRate */,
+ 2 /* channelCount */); // XXX AUDIO_CHANNEL_IN_STEREO?
+
+ CHECK_EQ((status_t)OK, audioSource->initCheck());
+
+ audioSource->setUseLooperTime(true);
+
+ index = mSerializer->addSource(audioSource);
+ CHECK_GE(index, 0);
+
+ sp<AMessage> audioFormat;
+ err = convertMetaDataToMessage(audioSource->getFormat(), &audioFormat);
+ CHECK_EQ(err, (status_t)OK);
+
+ sp<AMessage> audioNotify = new AMessage(kWhatConverterNotify, id());
+ audioNotify->setSize("trackIndex", index);
+
+ converter = new Converter(audioNotify, mCodecLooper, audioFormat);
+ looper()->registerHandler(converter);
+
+ mTracks.add(index, new Track(converter));
+#endif
+
return OK;
}