Bug 1468241 - P2. Ensure RemoteVideoDecoder::mSeekTarget is only accessed on task queue. r=padenot
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 21 Jun 2018 13:34:41 +0000
changeset 477471 686fc84d4ffbe8d1bef16767fdd8c867479258a0
parent 477470 3d039520dd5abfc686a47ec447624ee4f3072156
child 477472 7110e2638671135ef6149864614f35355494c6f3
push id9385
push userdluca@mozilla.com
push dateFri, 22 Jun 2018 15:47:18 +0000
treeherdermozilla-beta@82a9a1027e2b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1468241
milestone62.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1468241 - P2. Ensure RemoteVideoDecoder::mSeekTarget is only accessed on task queue. r=padenot Amend comments to clarify how some members are accessed. MozReview-Commit-ID: FeEIRap3zvn Depends on D1726 Differential Revision: https://phabricator.services.mozilla.com/D1727
dom/media/platforms/android/RemoteDataDecoder.cpp
--- a/dom/media/platforms/android/RemoteDataDecoder.cpp
+++ b/dom/media/platforms/android/RemoteDataDecoder.cpp
@@ -208,19 +208,25 @@ public:
     }
     mIsCodecSupportAdaptivePlayback =
       mJavaDecoder->IsAdaptivePlaybackSupported();
     return InitPromise::CreateAndResolve(TrackInfo::kVideoTrack, __func__);
   }
 
   RefPtr<MediaDataDecoder::FlushPromise> Flush() override
   {
-    mInputInfos.Clear();
-    mSeekTarget.reset();
-    return RemoteDataDecoder::Flush();
+    RefPtr<RemoteVideoDecoder> self = this;
+    return RemoteDataDecoder::Flush()->Then(
+      mTaskQueue,
+      __func__,
+      [self](const FlushPromise::ResolveOrRejectValue& aValue) {
+        self->mInputInfos.Clear();
+        self->mSeekTarget.reset();
+        return FlushPromise::CreateAndResolveOrReject(aValue, __func__);
+      });
   }
 
   RefPtr<MediaDataDecoder::DecodePromise> Decode(MediaRawData* aSample) override
   {
     const VideoInfo* config = aSample->mTrackInfo
                               ? aSample->mTrackInfo->GetAsVideoInfo()
                               : &mConfig;
     MOZ_ASSERT(config);
@@ -233,17 +239,23 @@ public:
 
   bool SupportDecoderRecycling() const override
   {
     return mIsCodecSupportAdaptivePlayback;
   }
 
   void SetSeekThreshold(const TimeUnit& aTime) override
   {
-    mSeekTarget = Some(aTime);
+    RefPtr<RemoteVideoDecoder> self = this;
+    nsCOMPtr<nsIRunnable> runnable = NS_NewRunnableFunction(
+      "RemoteVideoDecoder::SetSeekThreshold",
+      [self, aTime]() { self->mSeekTarget = Some(aTime); });
+    nsresult rv = mTaskQueue->Dispatch(runnable.forget());
+    MOZ_DIAGNOSTIC_ASSERT(NS_SUCCEEDED(rv));
+    Unused << rv;
   }
 
   bool IsUsefulData(const RefPtr<MediaData>& aSample) override
   {
     AssertOnTaskQueue();
     if (!mSeekTarget) {
       return true;
     }
@@ -253,18 +265,22 @@ public:
     }
     return false;
   }
 
 private:
   const VideoInfo mConfig;
   GeckoSurface::GlobalRef mSurface;
   AndroidSurfaceTextureHandle mSurfaceHandle;
+  // Only accessed on reader's task queue.
+  bool mIsCodecSupportAdaptivePlayback = false;
+  // Accessed on mTaskQueue, reader's TaskQueue and Java callback tread.
+  // SimpleMap however is thread-safe, so it's okay to do so.
   SimpleMap<InputInfo> mInputInfos;
-  bool mIsCodecSupportAdaptivePlayback = false;
+  // Only accessed on the TaskQueue.
   Maybe<TimeUnit> mSeekTarget;
 };
 
 class RemoteAudioDecoder : public RemoteDataDecoder
 {
 public:
   RemoteAudioDecoder(const AudioInfo& aConfig,
                      MediaFormat::Param aFormat,