summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/AudioSource.cpp
diff options
context:
space:
mode:
authorJames Dong <jdong@google.com>2010-06-19 09:04:18 -0700
committerJames Dong <jdong@google.com>2010-06-21 17:34:01 -0700
commitf60cafe0e6aad8f9ce54660fa88b651ae4e749e6 (patch)
treeeabfca8c6c979a1000f49efca5c33ab9039245ba /media/libstagefright/AudioSource.cpp
parente6de2667d6bf4bb7b926da6784cc7eb886b93e83 (diff)
downloadframeworks_av-f60cafe0e6aad8f9ce54660fa88b651ae4e749e6.zip
frameworks_av-f60cafe0e6aad8f9ce54660fa88b651ae4e749e6.tar.gz
frameworks_av-f60cafe0e6aad8f9ce54660fa88b651ae4e749e6.tar.bz2
Audio/video sync during recording (second part)
Change-Id: Iba0b35f57fdeac7ee1da16899406bf4b957a2c8c
Diffstat (limited to 'media/libstagefright/AudioSource.cpp')
-rw-r--r--media/libstagefright/AudioSource.cpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/media/libstagefright/AudioSource.cpp b/media/libstagefright/AudioSource.cpp
index d6020a6..d203dbf 100644
--- a/media/libstagefright/AudioSource.cpp
+++ b/media/libstagefright/AudioSource.cpp
@@ -77,6 +77,12 @@ status_t AudioSource::start(MetaData *params) {
&& (!strcmp(value, "1") || !strcasecmp(value, "true"))) {
mCollectStats = true;
}
+
+ mStartTimeUs = 0;
+ int64_t startTimeUs;
+ if (params && params->findInt64(kKeyTime, &startTimeUs)) {
+ mStartTimeUs = startTimeUs;
+ }
status_t err = mRecord->start();
if (err == OK) {
@@ -132,21 +138,22 @@ status_t AudioSource::read(
uint32_t numFramesRecorded;
mRecord->getPosition(&numFramesRecorded);
int64_t latency = mRecord->latency() * 1000;
- uint32_t sampleRate = mRecord->getSampleRate();
- int64_t timestampUs = (1000000LL * numFramesRecorded) / sampleRate - latency;
- LOGV("latency: %lld, sample rate: %d, timestamp: %lld",
- latency, sampleRate, timestampUs);
- buffer->meta_data()->setInt64(kKeyTime, timestampUs);
+ int64_t readTime = systemTime() / 1000;
+ if (numFramesRecorded == 0) {
+ // Initial delay
+ if (mStartTimeUs > 0) {
+ mStartTimeUs = readTime - mStartTimeUs;
+ } else {
+ mStartTimeUs += latency;
+ }
+ }
ssize_t n = 0;
if (mCollectStats) {
- struct timeval tv_start, tv_end;
- gettimeofday(&tv_start, NULL);
n = mRecord->read(buffer->data(), buffer->size());
- gettimeofday(&tv_end, NULL);
- mTotalReadTimeUs += ((1000000LL * (tv_end.tv_sec - tv_start.tv_sec))
- + (tv_end.tv_usec - tv_start.tv_usec));
+ int64_t endTime = systemTime() / 1000;
+ mTotalReadTimeUs += (endTime - readTime);
if (n >= 0) {
mTotalReadBytes += n;
}
@@ -161,6 +168,12 @@ status_t AudioSource::read(
return (status_t)n;
}
+ uint32_t sampleRate = mRecord->getSampleRate();
+ int64_t timestampUs = (1000000LL * numFramesRecorded) / sampleRate + mStartTimeUs;
+ buffer->meta_data()->setInt64(kKeyTime, timestampUs);
+ LOGV("initial delay: %lld, sample rate: %d, timestamp: %lld",
+ mStartTimeUs, sampleRate, timestampUs);
+
buffer->set_range(0, n);
*out = buffer;