Bug 1397141 - part6 : use MediaResult to replace nsresult r=jya
☠☠ backed out by d347d7618b0f ☠ ☠
authorAlastor Wu <alwu@mozilla.com>
Wed, 13 Sep 2017 15:06:07 +0800
changeset 663803 c78c096d0be97477324fe5b0e94b61094ec5d5d0
parent 663802 6dade48b33261cea22bfde63833ae25a1517bca2
child 663804 eab2e401c60fccb6e5904f101775bc298c7135ce
push id79536
push userbmo:rchien@mozilla.com
push dateWed, 13 Sep 2017 12:07:56 +0000
reviewersjya
bugs1397141
milestone57.0a1
Bug 1397141 - part6 : use MediaResult to replace nsresult r=jya Return MediaResult instead of using nsresult, because it can contain more detailed error information. We could also return this error with our rejected decode promise. MozReview-Commit-ID: HrI3QKlSJC
dom/media/platforms/wrappers/H264Converter.cpp
dom/media/platforms/wrappers/H264Converter.h
--- a/dom/media/platforms/wrappers/H264Converter.cpp
+++ b/dom/media/platforms/wrappers/H264Converter.cpp
@@ -28,17 +28,17 @@ H264Converter::H264Converter(PlatformDec
   , mTaskQueue(aParams.mTaskQueue)
   , mDecoder(nullptr)
   , mGMPCrashHelper(aParams.mCrashHelper)
   , mLastError(NS_OK)
   , mType(aParams.mType)
   , mOnWaitingForKeyEvent(aParams.mOnWaitingForKeyEvent)
   , mDecoderOptions(aParams.mOptions)
 {
-  CreateDecoder(mOriginalConfig, aParams.mDiagnostics);
+  mLastError = CreateDecoder(mOriginalConfig, aParams.mDiagnostics);
   if (mDecoder) {
     MOZ_ASSERT(mp4_demuxer::H264::HasSPS(mOriginalConfig.mExtraData));
     // The video metadata contains out of band SPS/PPS (AVC1) store it.
     mOriginalExtraData = mOriginalConfig.mExtraData;
   }
 }
 
 H264Converter::~H264Converter()
@@ -76,17 +76,17 @@ H264Converter::Decode(MediaRawData* aSam
 
   if (!mp4_demuxer::AnnexB::IsAVCC(aSample)) {
     return DecodePromise::CreateAndReject(
       MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
                   RESULT_DETAIL("Invalid H264 content")),
       __func__);
   }
 
-  nsresult rv;
+  MediaResult rv(NS_OK);
   if (!mDecoder) {
     // It is not possible to create an AVCC H264 decoder without SPS.
     // As such, creation will fail if the extra_data just extracted doesn't
     // contain a SPS.
     rv = CreateDecoderAndInit(aSample);
     if (rv == NS_ERROR_NOT_INITIALIZED) {
       // We are missing the required SPS to create the decoder.
       // Ignore for the time being, the MediaRawData will be dropped.
@@ -107,20 +107,17 @@ H264Converter::Decode(MediaRawData* aSam
 
   if (rv == NS_ERROR_DOM_MEDIA_INITIALIZING_DECODER) {
     // The decoder is pending initialization.
     RefPtr<DecodePromise> p = mDecodePromise.Ensure(__func__);
     return p;
   }
 
   if (NS_FAILED(rv)) {
-    return DecodePromise::CreateAndReject(
-      MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
-                  RESULT_DETAIL("Unable to create H264 decoder")),
-      __func__);
+    return DecodePromise::CreateAndReject(rv, __func__);
   }
 
   if (mNeedKeyframe && !aSample->mKeyframe) {
     return DecodePromise::CreateAndResolve(DecodedData(), __func__);
   }
 
   if (!*mNeedAVCC &&
       !mp4_demuxer::AnnexB::ConvertSampleToAnnexB(aSample, mNeedKeyframe)) {
@@ -238,43 +235,41 @@ H264Converter::SetSeekThreshold(const me
 {
   if (mDecoder) {
     mDecoder->SetSeekThreshold(aTime);
   } else {
     MediaDataDecoder::SetSeekThreshold(aTime);
   }
 }
 
-nsresult
+MediaResult
 H264Converter::CreateDecoder(const VideoInfo& aConfig,
                              DecoderDoctorDiagnostics* aDiagnostics)
 {
   if (!mp4_demuxer::H264::HasSPS(aConfig.mExtraData)) {
     // nothing found yet, will try again later
     return NS_ERROR_NOT_INITIALIZED;
   }
   UpdateConfigFromExtraData(aConfig.mExtraData);
 
   mp4_demuxer::SPSData spsdata;
   if (mp4_demuxer::H264::DecodeSPSFromExtraData(aConfig.mExtraData, spsdata)) {
     // Do some format check here.
     // WMF H.264 Video Decoder and Apple ATDecoder do not support YUV444 format.
     if (spsdata.profile_idc == 244 /* Hi444PP */ ||
         spsdata.chroma_format_idc == PDMFactory::kYUV444) {
-      mLastError = MediaResult(NS_ERROR_FAILURE,
-                               RESULT_DETAIL("Not support for YUV444 format."));
       if (aDiagnostics) {
         aDiagnostics->SetVideoNotSupported();
       }
-      return NS_ERROR_FAILURE;
+      return MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
+                         RESULT_DETAIL("No support for YUV444 format."));
     }
   } else {
-    mLastError = MediaResult(NS_ERROR_FAILURE,
-                             RESULT_DETAIL("Invalid SPS NAL."));
-    return NS_ERROR_FAILURE;
+    return MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
+                       RESULT_DETAIL("Invalid SPS NAL."));
   }
 
   mDecoder = mPDM->CreateVideoDecoder({
     aConfig,
     mTaskQueue,
     aDiagnostics,
     mImageContainer,
     mKnowsCompositor,
@@ -282,43 +277,42 @@ H264Converter::CreateDecoder(const Video
     mType,
     mOnWaitingForKeyEvent,
     mDecoderOptions,
     &mLastError
   });
 
   if (!mDecoder) {
     MOZ_ASSERT(NS_FAILED(mLastError));
-    mLastError = MediaResult(mLastError.Code(),
-                             RESULT_DETAIL("Unable to create H264 decoder, reason = %s.",
-                                           mLastError.Description().get()));
-    return NS_ERROR_FAILURE;
+    return MediaResult(mLastError.Code(),
+                       RESULT_DETAIL("Unable to create H264 decoder, reason = %s.",
+                                     mLastError.Description().get()));
   }
 
   mNeedKeyframe = true;
 
   return NS_OK;
 }
 
-nsresult
+MediaResult
 H264Converter::CreateDecoderAndInit(MediaRawData* aSample)
 {
   RefPtr<MediaByteBuffer> extra_data =
     mp4_demuxer::H264::ExtractExtraData(aSample);
   bool inbandExtradata = mp4_demuxer::H264::HasSPS(extra_data);
   if (!inbandExtradata &&
       !mp4_demuxer::H264::HasSPS(mCurrentConfig.mExtraData)) {
     return NS_ERROR_NOT_INITIALIZED;
   }
 
   if (inbandExtradata) {
     UpdateConfigFromExtraData(extra_data);
   }
 
-  nsresult rv =
+  MediaResult rv =
     CreateDecoder(mCurrentConfig, /* DecoderDoctorDiagnostics* */ nullptr);
 
   if (NS_SUCCEEDED(rv)) {
     RefPtr<H264Converter> self = this;
     RefPtr<MediaRawData> sample = aSample;
     mDecoder->Init()
       ->Then(
         AbstractThread::GetCurrent()->AsTaskQueue(),
@@ -395,17 +389,17 @@ H264Converter::DecodeFirstSample(MediaRa
            },
            [self, this](const MediaResult& aError) {
              mDecodePromiseRequest.Complete();
              mDecodePromise.Reject(aError, __func__);
            })
     ->Track(mDecodePromiseRequest);
 }
 
-nsresult
+MediaResult
 H264Converter::CheckForSPSChange(MediaRawData* aSample)
 {
   RefPtr<MediaByteBuffer> extra_data =
     mp4_demuxer::H264::ExtractExtraData(aSample);
   if (!mp4_demuxer::H264::HasSPS(extra_data)) {
     MOZ_ASSERT(mCanRecycleDecoder.isSome());
     if (!*mCanRecycleDecoder) {
       // If the decoder can't be recycled, the out of band extradata will never
@@ -507,17 +501,17 @@ void H264Converter::FlushThenShutdownDec
                         mShutdownPromise = nullptr;
 
                         if (!mFlushPromise.IsEmpty()) {
                           // A Flush is pending, abort the current operation.
                           mFlushPromise.Resolve(true, __func__);
                           return;
                         }
 
-                        nsresult rv = CreateDecoderAndInit(sample);
+                        MediaResult rv = CreateDecoderAndInit(sample);
                         if (rv == NS_ERROR_DOM_MEDIA_INITIALIZING_DECODER) {
                           // All good so far, will continue later.
                           return;
                         }
                         MOZ_ASSERT(NS_FAILED(rv));
                         mDecodePromise.Reject(rv, __func__);
                         return;
                       },
--- a/dom/media/platforms/wrappers/H264Converter.h
+++ b/dom/media/platforms/wrappers/H264Converter.h
@@ -60,20 +60,20 @@ public:
     return ConversionRequired::kNeedAVCC;
   }
   MediaResult GetLastError() const { return mLastError; }
 
 private:
   // Will create the required MediaDataDecoder if need AVCC and we have a SPS NAL.
   // Returns NS_ERROR_FAILURE if error is permanent and can't be recovered and
   // will set mError accordingly.
-  nsresult CreateDecoder(const VideoInfo& aConfig,
+  MediaResult CreateDecoder(const VideoInfo& aConfig,
                          DecoderDoctorDiagnostics* aDiagnostics);
-  nsresult CreateDecoderAndInit(MediaRawData* aSample);
-  nsresult CheckForSPSChange(MediaRawData* aSample);
+  MediaResult CreateDecoderAndInit(MediaRawData* aSample);
+  MediaResult CheckForSPSChange(MediaRawData* aSample);
   void UpdateConfigFromExtraData(MediaByteBuffer* aExtraData);
 
   bool CanRecycleDecoder() const;
 
   void DecodeFirstSample(MediaRawData* aSample);
   void DrainThenFlushDecoder(MediaRawData* aPendingSample);
   void FlushThenShutdownDecoder(MediaRawData* aPendingSample);
   RefPtr<ShutdownPromise> ShutdownDecoder();