summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWei Jia <wjia@google.com>2015-04-24 00:25:00 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2015-04-24 00:25:00 +0000
commite2e2cb08acf267b5151e61cda261cdda25afac38 (patch)
treef1289bd0891ca5644b2a8f7694809e1c49966d3c
parent3fa46d8bb636aeba420ebb2f454205d509f1af29 (diff)
parent99d1f78c9b16b5668e78c353373e0e7f4592cab9 (diff)
downloadframeworks_av-e2e2cb08acf267b5151e61cda261cdda25afac38.zip
frameworks_av-e2e2cb08acf267b5151e61cda261cdda25afac38.tar.gz
frameworks_av-e2e2cb08acf267b5151e61cda261cdda25afac38.tar.bz2
Merge "MediaSync: allow users to query play time for pending audio frames."
-rw-r--r--include/media/stagefright/MediaSync.h3
-rw-r--r--media/libstagefright/MediaSync.cpp36
2 files changed, 39 insertions, 0 deletions
diff --git a/include/media/stagefright/MediaSync.h b/include/media/stagefright/MediaSync.h
index 8bb8c7f..8ad74a4 100644
--- a/include/media/stagefright/MediaSync.h
+++ b/include/media/stagefright/MediaSync.h
@@ -113,6 +113,9 @@ public:
// MediaClock::getMediaTime() and MediaClock::getRealTimeFor().
sp<const MediaClock> getMediaClock();
+ // Get the play time for pending audio frames in audio sink.
+ status_t getPlayTimeForPendingAudioFrames(int64_t *outTimeUs);
+
protected:
virtual void onMessageReceived(const sp<AMessage> &msg);
diff --git a/media/libstagefright/MediaSync.cpp b/media/libstagefright/MediaSync.cpp
index 9c37a3d..8030a36 100644
--- a/media/libstagefright/MediaSync.cpp
+++ b/media/libstagefright/MediaSync.cpp
@@ -179,6 +179,42 @@ sp<const MediaClock> MediaSync::getMediaClock() {
return mMediaClock;
}
+status_t MediaSync::getPlayTimeForPendingAudioFrames(int64_t *outTimeUs) {
+ Mutex::Autolock lock(mMutex);
+ // User should check the playback rate if it doesn't want to receive a
+ // huge number for play time.
+ if (mPlaybackRate == 0.0f) {
+ *outTimeUs = INT64_MAX;
+ return OK;
+ }
+
+ uint32_t numFramesPlayed = 0;
+ if (mAudioTrack != NULL) {
+ status_t res = mAudioTrack->getPosition(&numFramesPlayed);
+ if (res != OK) {
+ return res;
+ }
+ }
+
+ int64_t numPendingFrames = mNumFramesWritten - numFramesPlayed;
+ if (numPendingFrames < 0) {
+ numPendingFrames = 0;
+ ALOGW("getPlayTimeForPendingAudioFrames: pending frame count is negative.");
+ }
+ double timeUs = numPendingFrames * 1000000.0
+ / (mNativeSampleRateInHz * (double)mPlaybackRate);
+ if (timeUs > (double)INT64_MAX) {
+ // Overflow.
+ *outTimeUs = INT64_MAX;
+ ALOGW("getPlayTimeForPendingAudioFrames: play time for pending audio frames "
+ "is too high, possibly due to super low playback rate(%f)", mPlaybackRate);
+ } else {
+ *outTimeUs = (int64_t)timeUs;
+ }
+
+ return OK;
+}
+
status_t MediaSync::updateQueuedAudioData(
size_t sizeInBytes, int64_t presentationTimeUs) {
if (sizeInBytes == 0) {