summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorWei Jia <wjia@google.com>2015-04-23 14:06:42 -0700
committerWei Jia <wjia@google.com>2015-04-23 16:08:06 -0700
commit99d1f78c9b16b5668e78c353373e0e7f4592cab9 (patch)
tree8970f2f018cc0829ee78c4ed5461c39c8f9a1775 /media
parent1ac91ed2c67245ea5052182212463d3f0afe8b5a (diff)
downloadframeworks_av-99d1f78c9b16b5668e78c353373e0e7f4592cab9.zip
frameworks_av-99d1f78c9b16b5668e78c353373e0e7f4592cab9.tar.gz
frameworks_av-99d1f78c9b16b5668e78c353373e0e7f4592cab9.tar.bz2
MediaSync: allow users to query play time for pending audio frames.
Bug: 19666434 Change-Id: I5cfd3e1a9b4f56aaa6482facd55a22ed1e7ed3e6
Diffstat (limited to 'media')
-rw-r--r--media/libstagefright/MediaSync.cpp36
1 files changed, 36 insertions, 0 deletions
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) {