Bug 1126465 - Factor out calls to Request{Audio,Video}Data into a helper method. r=mattwoodrow, a=sledru
authorBobby Holley <bobbyholley@gmail.com>
Thu, 29 Jan 2015 22:11:11 -0800
changeset 243647 e76764c0e076
parent 243646 5daace5690d6
child 243648 cc2a8374de88
push id4421
push userryanvm@gmail.com
push date2015-02-02 19:52 +0000
treeherdermozilla-beta@08a02585bc60 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow, sledru
bugs1126465
milestone36.0
Bug 1126465 - Factor out calls to Request{Audio,Video}Data into a helper method. r=mattwoodrow, a=sledru
dom/media/mediasource/MediaSourceReader.cpp
dom/media/mediasource/MediaSourceReader.h
--- a/dom/media/mediasource/MediaSourceReader.cpp
+++ b/dom/media/mediasource/MediaSourceReader.cpp
@@ -135,31 +135,35 @@ MediaSourceReader::RequestAudioData()
       break;
     case READER_ERROR:
       if (mLastAudioTime) {
         CheckForWaitOrEndOfStream(MediaData::AUDIO_DATA, mLastAudioTime);
         break;
       }
       // Fallback to using current reader
     default:
-      RequestAudioDataComplete(0);
+      DoAudioRequest();
       break;
   }
   return p;
 }
 
 void
 MediaSourceReader::RequestAudioDataComplete(int64_t aTime)
 {
   if (IsSeeking()) {
     MSE_DEBUG("MediaSourceReader(%p)::RequestAudioDataComplete called mid-seek. Rejecting.", this);
     MOZ_RELEASE_ASSERT(mAudioPromise.IsEmpty()); // Already rejected in ::Seek().
     return;
   }
+  DoAudioRequest();
+}
 
+void MediaSourceReader::DoAudioRequest()
+{
   mAudioRequest.Begin(mAudioReader->RequestAudioData()
                       ->RefableThen(GetTaskQueue(), __func__, this,
                                     &MediaSourceReader::OnAudioDecoded,
                                     &MediaSourceReader::OnAudioNotDecoded));
 }
 
 void
 MediaSourceReader::RequestAudioDataFailed(nsresult aResult)
@@ -282,34 +286,37 @@ MediaSourceReader::RequestVideoData(bool
       break;
     case READER_ERROR:
       if (mLastVideoTime) {
         CheckForWaitOrEndOfStream(MediaData::VIDEO_DATA, mLastVideoTime);
         break;
       }
       // Fallback to using current reader.
     default:
-      mVideoRequest.Begin(mVideoReader->RequestVideoData(mDropVideoBeforeThreshold, mTimeThreshold)
-                          ->RefableThen(GetTaskQueue(), __func__, this,
-                                        &MediaSourceReader::OnVideoDecoded,
-                                        &MediaSourceReader::OnVideoNotDecoded));
+      DoVideoRequest();
       break;
   }
 
   return p;
 }
 
 void
 MediaSourceReader::RequestVideoDataComplete(int64_t aTime)
 {
   if (IsSeeking()) {
     MSE_DEBUG("MediaSourceReader(%p)::RequestVideoDataComplete called mid-seek. Rejecting.", this);
     MOZ_ASSERT(mVideoPromise.IsEmpty()); // Already rejected in ::Seek().
     return;
   }
+  DoVideoRequest();
+}
+
+void
+MediaSourceReader::DoVideoRequest()
+{
   mVideoRequest.Begin(mVideoReader->RequestVideoData(mDropVideoBeforeThreshold, mTimeThreshold)
                       ->RefableThen(GetTaskQueue(), __func__, this,
                                     &MediaSourceReader::OnVideoDecoded,
                                     &MediaSourceReader::OnVideoNotDecoded));
 }
 
 void
 MediaSourceReader::RequestVideoDataFailed(nsresult aResult)
@@ -324,20 +331,17 @@ MediaSourceReader::OnVideoDecoded(VideoD
   mVideoRequest.Complete();
 
   MSE_DEBUGV("MediaSourceReader(%p)::OnVideoDecoded [mTime=%lld mDuration=%lld mDiscontinuity=%d]",
              this, aSample->mTime, aSample->mDuration, aSample->mDiscontinuity);
   if (mDropVideoBeforeThreshold) {
     if (aSample->mTime < mTimeThreshold) {
       MSE_DEBUG("MediaSourceReader(%p)::OnVideoDecoded mTime=%lld < mTimeThreshold=%lld",
                 this, aSample->mTime, mTimeThreshold);
-      mVideoRequest.Begin(mVideoReader->RequestVideoData(mDropVideoBeforeThreshold, mTimeThreshold)
-                          ->RefableThen(GetTaskQueue(), __func__, this,
-                                        &MediaSourceReader::OnVideoDecoded,
-                                        &MediaSourceReader::OnVideoNotDecoded));
+      DoVideoRequest();
       return;
     }
     mDropVideoBeforeThreshold = false;
     mTimeThreshold = 0;
   }
 
   mLastVideoTime = aSample->mTime + aSample->mDuration;
 
--- a/dom/media/mediasource/MediaSourceReader.h
+++ b/dom/media/mediasource/MediaSourceReader.h
@@ -155,16 +155,19 @@ private:
     READER_ERROR = -1,
     READER_EXISTING = 0,
     READER_NEW = 1,
   };
 
   SwitchReaderResult SwitchAudioReader(int64_t aTarget);
   SwitchReaderResult SwitchVideoReader(int64_t aTarget);
 
+  void DoAudioRequest();
+  void DoVideoRequest();
+
   void RequestAudioDataComplete(int64_t aTime);
   void RequestAudioDataFailed(nsresult aResult);
   void RequestVideoDataComplete(int64_t aTime);
   void RequestVideoDataFailed(nsresult aResult);
   // Will reject the MediaPromise with END_OF_STREAM if mediasource has ended
   // or with WAIT_FOR_DATA otherwise.
   void CheckForWaitOrEndOfStream(MediaData::Type aType, int64_t aTime /* microseconds */);