Bug 1313497 - Use InvokeAsync with Storages in MediaSourceDemuxer - r?jya draft
authorGerald Squelart <gsquelart@mozilla.com>
Sun, 13 Nov 2016 12:03:26 +1100
changeset 440567 fdc0461bd1ec801f33306ed7e67ce7c521067fbb
parent 440186 33bf75c3d054dfb4a687cdfd2dab9924e4ec6460
child 440568 58d72a3b0bca183ec39fe343341d138102b6f557
push id36267
push usergsquelart@mozilla.com
push dateThu, 17 Nov 2016 20:57:00 +0000
reviewersjya
bugs1313497
milestone53.0a1
Bug 1313497 - Use InvokeAsync with Storages in MediaSourceDemuxer - r?jya We now take a copy of the TimeUnit object, and can then pass it by rref to internal methods. MozReview-Commit-ID: J0Idw85NMcu
dom/media/mediasource/MediaSourceDemuxer.cpp
dom/media/mediasource/MediaSourceDemuxer.h
--- a/dom/media/mediasource/MediaSourceDemuxer.cpp
+++ b/dom/media/mediasource/MediaSourceDemuxer.cpp
@@ -302,18 +302,19 @@ MediaSourceTrackDemuxer::GetInfo() const
 {
   return mParent->GetTrackInfo(mType)->Clone();
 }
 
 RefPtr<MediaSourceTrackDemuxer::SeekPromise>
 MediaSourceTrackDemuxer::Seek(media::TimeUnit aTime)
 {
   MOZ_ASSERT(mParent, "Called after BreackCycle()");
-  return InvokeAsync(mParent->GetTaskQueue(), this, __func__,
-                     &MediaSourceTrackDemuxer::DoSeek, aTime);
+  return InvokeAsync<media::TimeUnit&&>(
+           mParent->GetTaskQueue(), this, __func__,
+           &MediaSourceTrackDemuxer::DoSeek, aTime);
 }
 
 RefPtr<MediaSourceTrackDemuxer::SamplesPromise>
 MediaSourceTrackDemuxer::GetSamples(int32_t aNumSamples)
 {
   MOZ_ASSERT(mParent, "Called after BreackCycle()");
   return InvokeAsync(mParent->GetTaskQueue(), this, __func__,
                      &MediaSourceTrackDemuxer::DoGetSamples, aNumSamples);
@@ -345,19 +346,20 @@ MediaSourceTrackDemuxer::GetNextRandomAc
   MonitorAutoLock mon(mMonitor);
   *aTime = mNextRandomAccessPoint;
   return NS_OK;
 }
 
 RefPtr<MediaSourceTrackDemuxer::SkipAccessPointPromise>
 MediaSourceTrackDemuxer::SkipToNextRandomAccessPoint(media::TimeUnit aTimeThreshold)
 {
-  return InvokeAsync(mParent->GetTaskQueue(), this, __func__,
-                     &MediaSourceTrackDemuxer::DoSkipToNextRandomAccessPoint,
-                     aTimeThreshold);
+  return InvokeAsync<media::TimeUnit&&>(
+           mParent->GetTaskQueue(), this, __func__,
+           &MediaSourceTrackDemuxer::DoSkipToNextRandomAccessPoint,
+           aTimeThreshold);
 }
 
 media::TimeIntervals
 MediaSourceTrackDemuxer::GetBuffered()
 {
   return mManager->Buffered();
 }
 
@@ -369,17 +371,17 @@ MediaSourceTrackDemuxer::BreakCycles()
     NS_NewRunnableFunction([self]() {
       self->mParent = nullptr;
       self->mManager = nullptr;
     } );
   mParent->GetTaskQueue()->Dispatch(task.forget());
 }
 
 RefPtr<MediaSourceTrackDemuxer::SeekPromise>
-MediaSourceTrackDemuxer::DoSeek(media::TimeUnit aTime)
+MediaSourceTrackDemuxer::DoSeek(const media::TimeUnit& aTime)
 {
   TimeIntervals buffered = mManager->Buffered(mType);
   // Fuzz factor represents a +/- threshold. So when seeking it allows the gap
   // to be twice as big as the fuzz value. We only want to allow EOS_FUZZ gap.
   buffered.SetFuzz(MediaSourceDemuxer::EOS_FUZZ / 2);
   TimeUnit seekTime = std::max(aTime - mPreRoll, TimeUnit::FromMicroseconds(0));
 
   if (mManager->IsEnded() && seekTime >= buffered.GetEnd()) {
@@ -464,17 +466,17 @@ MediaSourceTrackDemuxer::DoGetSamples(in
     MonitorAutoLock mon(mMonitor);
     mNextRandomAccessPoint =
       mManager->GetNextRandomAccessPoint(mType, MediaSourceDemuxer::EOS_FUZZ);
   }
   return SamplesPromise::CreateAndResolve(samples, __func__);
 }
 
 RefPtr<MediaSourceTrackDemuxer::SkipAccessPointPromise>
-MediaSourceTrackDemuxer::DoSkipToNextRandomAccessPoint(media::TimeUnit aTimeThreadshold)
+MediaSourceTrackDemuxer::DoSkipToNextRandomAccessPoint(const media::TimeUnit& aTimeThreadshold)
 {
   uint32_t parsed = 0;
   // Ensure that the data we are about to skip to is still available.
   TimeIntervals buffered = mManager->Buffered(mType);
   buffered.SetFuzz(MediaSourceDemuxer::EOS_FUZZ / 2);
   if (buffered.ContainsWithStrictEnd(aTimeThreadshold)) {
     bool found;
     parsed = mManager->SkipToNextRandomAccessPoint(mType,
--- a/dom/media/mediasource/MediaSourceDemuxer.h
+++ b/dom/media/mediasource/MediaSourceDemuxer.h
@@ -111,19 +111,19 @@ public:
   void BreakCycles() override;
 
   bool GetSamplesMayBlock() const override
   {
     return false;
   }
 
 private:
-  RefPtr<SeekPromise> DoSeek(media::TimeUnit aTime);
+  RefPtr<SeekPromise> DoSeek(const media::TimeUnit& aTime);
   RefPtr<SamplesPromise> DoGetSamples(int32_t aNumSamples);
-  RefPtr<SkipAccessPointPromise> DoSkipToNextRandomAccessPoint(media::TimeUnit aTimeThreadshold);
+  RefPtr<SkipAccessPointPromise> DoSkipToNextRandomAccessPoint(const media::TimeUnit& aTimeThreadshold);
   already_AddRefed<MediaRawData> GetSample(MediaResult& aError);
   // Return the timestamp of the next keyframe after mLastSampleIndex.
   media::TimeUnit GetNextRandomAccessPoint();
 
   RefPtr<MediaSourceDemuxer> mParent;
   RefPtr<TrackBuffersManager> mManager;
   TrackInfo::TrackType mType;
   // Monitor protecting members below accessed from multiple threads.