Bug 1133955 - Record the last seek time to decide the direction to seek. r=sotaro
authorBlake Wu <bwu@mozilla.com>
Tue, 24 Feb 2015 11:19:54 +0800
changeset 249262 7cea68e38d3f737364164a82e9a64b7b15917209
parent 249261 f1170bf063bd31cdffab3fa443cdf1387befd22a
child 249263 b273c0746faf92c6c21c6a3df295feeead4434c0
push id7860
push userjlund@mozilla.com
push dateMon, 30 Mar 2015 18:46:02 +0000
treeherdermozilla-aurora@8ac636cd51f3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssotaro
bugs1133955
milestone39.0a1
Bug 1133955 - Record the last seek time to decide the direction to seek. r=sotaro
dom/media/omx/OmxDecoder.cpp
dom/media/omx/OmxDecoder.h
--- a/dom/media/omx/OmxDecoder.cpp
+++ b/dom/media/omx/OmxDecoder.cpp
@@ -60,17 +60,17 @@ OmxDecoder::OmxDecoder(MediaResource *aR
   mVideoHeight(0),
   mVideoColorFormat(0),
   mVideoStride(0),
   mVideoSliceHeight(0),
   mVideoRotation(0),
   mAudioChannels(-1),
   mAudioSampleRate(-1),
   mDurationUs(-1),
-  mVideoLastFrameTime(-1),
+  mLastSeekTime(-1),
   mVideoBuffer(nullptr),
   mAudioBuffer(nullptr),
   mIsVideoSeeking(false),
   mAudioMetadataRead(false),
   mAudioPaused(false),
   mVideoPaused(false)
 {
   mLooper = new ALooper;
@@ -381,16 +381,20 @@ void OmxDecoder::ReleaseMediaResources()
 
   if (mAudioSource.get()) {
     mAudioSource->stop();
     mAudioSource.clear();
   }
 
   mNativeWindowClient.clear();
   mNativeWindow.clear();
+
+  // Reset this variable to make the first seek go to the previous keyframe
+  // when resuming
+  mLastSeekTime = -1;
 }
 
 bool OmxDecoder::SetVideoFormat() {
   const char *componentName;
 
   if (!mVideoSource->getFormat()->findInt32(kKeyWidth, &mVideoWidth) ||
       !mVideoSource->getFormat()->findInt32(kKeyHeight, &mVideoHeight) ||
       !mVideoSource->getFormat()->findCString(kKeyDecoderComponent, &componentName) ||
@@ -559,22 +563,23 @@ bool OmxDecoder::ReadVideo(VideoFrame *a
       Mutex::Autolock autoLock(mSeekLock);
       ReleaseAllPendingVideoBuffersLocked();
       mIsVideoSeeking = true;
     }
     MediaSource::ReadOptions options;
     MediaSource::ReadOptions::SeekMode seekMode;
     // If the last timestamp of decoded frame is smaller than seekTime,
     // seek to next key frame. Otherwise seek to the previos one.
-    if (mVideoLastFrameTime > aTimeUs || mVideoLastFrameTime == -1) {
+    OD_LOG("SeekTime: %lld, mLastSeekTime:%lld", aTimeUs, mLastSeekTime);
+    if (mLastSeekTime == -1 || mLastSeekTime > aTimeUs) {
       seekMode = MediaSource::ReadOptions::SEEK_PREVIOUS_SYNC;
     } else {
       seekMode = MediaSource::ReadOptions::SEEK_NEXT_SYNC;
     }
-
+    mLastSeekTime = aTimeUs;
     bool findNextBuffer = true;
     while (findNextBuffer) {
       options.setSeekTo(aTimeUs, seekMode);
       findNextBuffer = false;
       if (mIsVideoSeeking) {
         err = mVideoSource->read(&mVideoBuffer, &options);
         Mutex::Autolock autoLock(mSeekLock);
         mIsVideoSeeking = false;
@@ -670,17 +675,16 @@ bool OmxDecoder::ReadVideo(VideoFrame *a
       if (!ToVideoFrame(aFrame, timeUs, data, length, keyFrame)) {
         return false;
       }
     }
     // Check if this frame is valid or not. If not, skip it.
     if ((aKeyframeSkip && timeUs < aTimeUs) || length == 0) {
       aFrame->mShouldSkip = true;
     }
-    mVideoLastFrameTime = timeUs;
   }
   else if (err == INFO_FORMAT_CHANGED) {
     // If the format changed, update our cached info.
     if (!SetVideoFormat()) {
       return false;
     } else {
       return ReadVideo(aFrame, aTimeUs, aKeyframeSkip, aDoSeek);
     }
--- a/dom/media/omx/OmxDecoder.h
+++ b/dom/media/omx/OmxDecoder.h
@@ -55,17 +55,17 @@ class OmxDecoder : public OMXCodecProxy:
   int32_t mVideoHeight;
   int32_t mVideoColorFormat;
   int32_t mVideoStride;
   int32_t mVideoSliceHeight;
   int32_t mVideoRotation;
   int32_t mAudioChannels;
   int32_t mAudioSampleRate;
   int64_t mDurationUs;
-  int64_t mVideoLastFrameTime;
+  int64_t mLastSeekTime;
 
   VideoFrame mVideoFrame;
   AudioFrame mAudioFrame;
   MP3FrameParser mMP3FrameParser;
   bool mIsMp3;
 
   // Lifetime of these should be handled by OMXCodec, as long as we release
   //   them after use: see ReleaseVideoBuffer(), ReleaseAudioBuffer()