Bug 1538508 - P1. Reset mError upon success. r=bryce a=pascalc
authorNarcis Beleuzu <nbeleuzu@mozilla.com>
Sat, 30 Mar 2019 21:05:53 +0200
changeset 525832 a6c41b0eebc2d225fe633bc95554c10d233fcc02
parent 525831 ab24bd3fb3e79b0df21b42780c8b87e3922a1bf3
child 525833 30cb64155f7b9f648a5fff7473909bdf5b7c5de4
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbryce, pascalc
bugs1538508
milestone67.0
Bug 1538508 - P1. Reset mError upon success. r=bryce a=pascalc Reviewers: bryce Reviewed By: bryce Bug #: 1538508 Differential Revision: https://phabricator.services.mozilla.com/D24869
media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.cpp
--- a/media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.cpp
+++ b/media/webrtc/signaling/src/media-conduit/WebrtcMediaDataDecoderCodec.cpp
@@ -2,18 +2,18 @@
  * 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/layers/ImageBridgeChild.h"
 #include "mozilla/media/MediaUtils.h"
-#include "mozilla/layers/ImageBridgeChild.h"
 #include "webrtc/rtc_base/keep_ref_until_done.h"
 
 namespace mozilla {
 
 WebrtcMediaDataDecoder::WebrtcMediaDataDecoder()
     : mThreadPool(GetMediaThreadPool(MediaThreadType::PLATFORM_DECODER)),
       mTaskQueue(new TaskQueue(do_AddRef(mThreadPool),
                                "WebrtcMediaDataDecoder::mTaskQueue")),
@@ -44,27 +44,31 @@ int32_t WebrtcMediaDataDecoder::InitDeco
   mTrackType = TrackInfo::kVideoTrack;
 
   mInfo = VideoInfo(aCodecSettings->width, aCodecSettings->height);
   mInfo.mMimeType = codec;
 
   RefPtr<layers::KnowsCompositor> knowsCompositor =
       layers::ImageBridgeChild::GetSingleton();
 
+  if (mDecoder) {
+    Release();
+  }
+
   mDecoder = mFactory->CreateDecoder(
       {mInfo, mTaskQueue,
        CreateDecoderParams::OptionSet(CreateDecoderParams::Option::LowLatency),
        mTrackType, mImageContainer, knowsCompositor});
 
   if (!mDecoder) {
     return WEBRTC_VIDEO_CODEC_ERROR;
   }
 
   media::Await(do_AddRef(mThreadPool), mDecoder->Init(),
-               [](TrackInfo::TrackType) {},
+               [&](TrackInfo::TrackType) { mError = NS_OK; },
                [&](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,
@@ -102,16 +106,17 @@ int32_t WebrtcMediaDataDecoder::Decode(
   compressedFrame->mTimecode =
       media::TimeUnit::FromMicroseconds(aRenderTimeMs * 1000);
   compressedFrame->mKeyframe =
       aInputImage._frameType == webrtc::FrameType::kVideoFrameKey;
   {
     media::Await(do_AddRef(mThreadPool), mDecoder->Decode(compressedFrame),
                  [&](const MediaDataDecoder::DecodedData& aResults) {
                    mResults = aResults;
+                   mError = NS_OK;
                  },
                  [&](const MediaResult& aError) { mError = aError; });
 
     for (auto& frame : mResults) {
       MOZ_ASSERT(frame->mType == MediaData::Type::VIDEO_DATA);
       RefPtr<VideoData> video = frame->As<VideoData>();
       MOZ_ASSERT(video);
       if (!video->mImage) {
@@ -139,16 +144,17 @@ int32_t WebrtcMediaDataDecoder::Register
 }
 
 int32_t WebrtcMediaDataDecoder::Release() {
   RefPtr<MediaDataDecoder> decoder = mDecoder.forget();
   decoder->Flush()->Then(mTaskQueue, __func__,
                          [decoder]() { decoder->Shutdown(); });
 
   mNeedKeyframe = true;
+  mError = NS_OK;
 
   return WEBRTC_VIDEO_CODEC_OK;
 }
 
 bool WebrtcMediaDataDecoder::OnTaskQueue() const {
   return OwnerThread()->IsCurrentThreadIn();
 }