OSDN Git Service

Bug 5385386 missing HEADATNEWPOS
authorGlenn Kasten <gkasten@google.com>
Thu, 29 Sep 2011 21:34:13 +0000 (14:34 -0700)
committerGlenn Kasten <gkasten@google.com>
Thu, 29 Sep 2011 21:41:00 +0000 (14:41 -0700)
Workaround for mediaserver bug where it does not send MEDIA_SEEK_COMPLETE
to the MediaPlayerNotifier after a discontinuity is processed.

Instead, we simulate a seek complete event in this case.
A short delay is applied to compensate for shared memory latency.

A longer-term fix will be to have mediaserver send the event.

Change-Id: Id0d01b842a145fa5762d44f03144741152f7b03f

wilhelm/src/android/android_GenericMediaPlayer.cpp
wilhelm/src/android/android_GenericPlayer.cpp
wilhelm/src/android/android_GenericPlayer.h
wilhelm/src/android/android_StreamPlayer.cpp

index 8cca0d8..8158cf6 100644 (file)
@@ -295,8 +295,9 @@ void GenericMediaPlayer::onSeek(const sp<AMessage> &msg) {
         // invalid command, drop it
         return;
     }
-    if ((mStateFlags & kFlagSeeking) && (timeMsec == mSeekTimeMsec)) {
-        // already seeking to the same time, cancel this command
+    if ((mStateFlags & kFlagSeeking) && (timeMsec == mSeekTimeMsec) &&
+            (timeMsec != ANDROID_UNKNOWN_TIME)) {
+        // already seeking to the same non-unknown time, cancel this command
         return;
     } else if (mStateFlags & kFlagPreparedUnsuccessfully) {
         // discard seeks after unsuccessful prepare
@@ -307,7 +308,12 @@ void GenericMediaPlayer::onSeek(const sp<AMessage> &msg) {
         if (msg->findInt64(WHATPARAM_SEEK_SEEKTIME_MS, &timeMsec) && (mPlayer != 0)) {
             mStateFlags |= kFlagSeeking;
             mSeekTimeMsec = (int32_t)timeMsec;
-            if (OK != mPlayer->seekTo(timeMsec)) {
+            // seek to unknown time is used by StreamPlayer after discontinuity
+            if (timeMsec == ANDROID_UNKNOWN_TIME) {
+                // FIXME simulate a MEDIA_SEEK_COMPLETE event in 250 ms;
+                // this is a terrible hack to make up for mediaserver not sending one
+                (new AMessage(kWhatSeekComplete, id()))->post(250000);
+            } else if (OK != mPlayer->seekTo(timeMsec)) {
                 mStateFlags &= ~kFlagSeeking;
                 mSeekTimeMsec = ANDROID_UNKNOWN_TIME;
             }
index 676be8d..5e91365 100644 (file)
@@ -166,7 +166,7 @@ void GenericPlayer::stop() {
 
 void GenericPlayer::seek(int64_t timeMsec) {
     SL_LOGV("GenericPlayer::seek %lld", timeMsec);
-    if (timeMsec < 0) {
+    if (timeMsec < 0 && timeMsec != ANDROID_UNKNOWN_TIME) {
         SL_LOGE("GenericPlayer::seek error, can't seek to negative time %lldms", timeMsec);
         return;
     }
index 5a7fc22..8f47673 100644 (file)
@@ -68,6 +68,7 @@ public:
     virtual void play();
     virtual void pause();
     virtual void stop();
+    // timeMsec must be >= 0 or == ANDROID_UNKNOWN_TIME (used by StreamPlayer after discontinuity)
     virtual void seek(int64_t timeMsec);
     virtual void loop(bool loop);
     virtual void setBufferingUpdateThreshold(int16_t thresholdPercent);
index 7fad498..9307a98 100644 (file)
@@ -139,6 +139,11 @@ void StreamSourceAppProxy::pullFromBuffQueue() {
                 msg->setInt32(IStreamListener::kKeyFormatChange, (int32_t) 1);
                 receivedCmd_l(IStreamListener::DISCONTINUITY, msg /*msg*/);
             }
+            if (oldFront->mItems.mTsCmdData.mTsCmdCode & (ANDROID_MP2TSEVENT_DISCONTINUITY |
+                    ANDROID_MP2TSEVENT_DISCON_NEWPTS | ANDROID_MP2TSEVENT_FORMAT_CHANGE)) {
+                // FIXME see note at onSeek
+                mPlayer->seek(ANDROID_UNKNOWN_TIME);
+            }
             oldFront->mItems.mTsCmdData.mTsCmdCode = ANDROID_MP2TSEVENT_NONE;
         }