Bug 1404997 - P19. Use new Await method with WebrtcMediaDataDecoder. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Fri, 08 Dec 2017 17:30:28 +0100
changeset 448420 f9b7dc9f7e08bca6862b1706660b042ec1ccbe4b
parent 448419 737f227413b71fa1df005fbbaf1b3372547dcae7
child 448421 c27eaf506c73c88f90d5b1966046b4e173d00825
push id8527
push userCallek@gmail.com
push dateThu, 11 Jan 2018 21:05:50 +0000
treeherdermozilla-beta@95342d212a7a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgerald
bugs1404997
milestone59.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 1404997 - P19. Use new Await method with WebrtcMediaDataDecoder. r=gerald MozReview-Commit-ID: nRQL312aDE
media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.cpp
media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.h
--- a/media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.cpp
+++ b/media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.cpp
@@ -2,29 +2,29 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebrtcMediaDataDecoderCodec.h"
 #include "ImageContainer.h"
 #include "Layers.h"
 #include "PDMFactory.h"
 #include "VideoUtils.h"
+#include "mozilla/media/MediaUtils.h"
 #include "mozilla/layers/ImageBridgeChild.h"
 #include "webrtc/base/keep_ref_until_done.h"
 
 namespace mozilla {
 
 WebrtcMediaDataDecoder::WebrtcMediaDataDecoder()
   : mTaskQueue(
       new TaskQueue(GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER),
                     "WebrtcMediaDataDecoder::mTaskQueue"))
   , mImageContainer(layers::LayerManager::CreateImageContainer(
       layers::ImageContainer::ASYNCHRONOUS))
   , mFactory(new PDMFactory())
-  , mMonitor("WebrtcMediaDataDecoder")
 {
 }
 
 WebrtcMediaDataDecoder::~WebrtcMediaDataDecoder()
 {
   mTaskQueue->BeginShutdown();
   mTaskQueue->AwaitShutdownAndIdle();
 }
@@ -63,35 +63,19 @@ WebrtcMediaDataDecoder::InitDecode(const
       mTrackType,
       mImageContainer,
       knowsCompositor });
 
   if (!mDecoder) {
     return WEBRTC_VIDEO_CODEC_ERROR;
   }
 
-  MonitorAutoLock lock(mMonitor);
-  bool done = false;
-  mDecoder->Init()->Then(mTaskQueue,
-                         __func__,
-                         [&](TrackInfo::TrackType) {
-                           MonitorAutoLock lock(mMonitor);
-                           done = true;
-                           mMonitor.Notify();
-                         },
-                         [&](const MediaResult& aError) {
-                           MonitorAutoLock lock(mMonitor);
-                           done = true;
-                           mError = aError;
-                           mMonitor.Notify();
-                         });
-
-  while (!done) {
-    mMonitor.Wait();
-  }
+  media::Await(mDecoder->Init(),
+               [](TrackInfo::TrackType) {},
+               [&](const MediaResult& aError) { mError = aError; });
 
   return NS_SUCCEEDED(mError) ? WEBRTC_VIDEO_CODEC_OK : WEBRTC_VIDEO_CODEC_ERROR;
 }
 
 int32_t
 WebrtcMediaDataDecoder::Decode(
   const webrtc::EncodedImage& aInputImage,
   bool aMissingFrames,
@@ -127,37 +111,21 @@ WebrtcMediaDataDecoder::Decode(
 
   compressedFrame->mTime =
     media::TimeUnit::FromMicroseconds(aInputImage._timeStamp);
   compressedFrame->mTimecode =
     media::TimeUnit::FromMicroseconds(aRenderTimeMs * 1000);
   compressedFrame->mKeyframe =
     aInputImage._frameType == webrtc::FrameType::kVideoFrameKey;
   {
-    MonitorAutoLock lock(mMonitor);
-    bool done = false;
-    mDecoder->Decode(compressedFrame)->Then(
-      mTaskQueue,
-      __func__,
-      [&](const MediaDataDecoder::DecodedData& aResults) {
-        MonitorAutoLock lock(mMonitor);
-        mResults = aResults;
-        done = true;
-        mMonitor.Notify();
-      },
-      [&](const MediaResult& aError) {
-        MonitorAutoLock lock(mMonitor);
-        mError = aError;
-        done = true;
-        mMonitor.Notify();
-      });
-
-    while (!done) {
-      mMonitor.Wait();
-    }
+    media::Await(mDecoder->Decode(compressedFrame),
+                 [&](const MediaDataDecoder::DecodedData& aResults) {
+                   mResults = aResults;
+                 },
+                 [&](const MediaResult& aError) { mError = aError; });
 
     for (auto& frame : mResults) {
       MOZ_ASSERT(frame->mType == MediaData::VIDEO_DATA);
       RefPtr<VideoData> video = frame->As<VideoData>();
       MOZ_ASSERT(video);
       if (!video->mImage) {
         // Nothing to display.
         continue;
@@ -183,35 +151,22 @@ WebrtcMediaDataDecoder::RegisterDecodeCo
 {
   mCallback = aCallback;
   return WEBRTC_VIDEO_CODEC_OK;
 }
 
 int32_t
 WebrtcMediaDataDecoder::Release()
 {
-  MonitorAutoLock lock(mMonitor);
-  bool done = false;
-  mDecoder->Flush()
-    ->Then(mTaskQueue,
-           __func__,
-           [this]() { return mDecoder->Shutdown(); },
-           [this](const MediaResult& aError) { return mDecoder->Shutdown(); })
-    ->Then(mTaskQueue,
-           __func__,
-           [&]() {
-             MonitorAutoLock lock(mMonitor);
-             done = true;
-             mMonitor.Notify();
-           },
-           []() { MOZ_ASSERT_UNREACHABLE("Shutdown promise always resolved"); });
-
-  while (!done) {
-    mMonitor.Wait();
-  }
+  RefPtr<ShutdownPromise> p =
+    mDecoder->Flush()->Then(mTaskQueue,
+                            __func__,
+                            [this]() { return mDecoder->Shutdown(); },
+                            [this]() { return mDecoder->Shutdown(); });
+  media::Await(p);
 
   mDecoder = nullptr;
   mNeedKeyframe = true;
 
   return WEBRTC_VIDEO_CODEC_OK;
 }
 
 bool
--- a/media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.h
+++ b/media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.h
@@ -67,17 +67,15 @@ private:
   const RefPtr<PDMFactory> mFactory;
   RefPtr<MediaDataDecoder> mDecoder;
   webrtc::DecodedImageCallback* mCallback = nullptr;
   VideoInfo mInfo;
   TrackInfo::TrackType mTrackType;
   bool mNeedKeyframe = true;
   MozPromiseRequestHolder<MediaDataDecoder::DecodePromise> mDecodeRequest;
 
-  Monitor mMonitor;
-  // Members below are accessed via mMonitor
   MediaResult mError = NS_OK;
   MediaDataDecoder::DecodedData mResults;
 };
 
 } // namespace mozilla
 
 #endif // WebrtcMediaDataDecoderCodec_h__