Bug 1397141 - part4 : change mLastError type to MediaResult draft
authorAlastor Wu <alwu@mozilla.com>
Wed, 13 Sep 2017 15:05:52 +0800
changeset 663589 790eaab523546fde48c90cf5821035cd0928d18f
parent 663588 eeb2767b126c0662614dfccd9ee2a0a071a11751
child 663590 7bf37f3218ebb8c4bce85c05715c2fdee800369b
child 663631 98769a940568db0a14a25e698cac761d618587cb
push id79482
push useralwu@mozilla.com
push dateWed, 13 Sep 2017 07:06:40 +0000
bugs1397141
milestone57.0a1
Bug 1397141 - part4 : change mLastError type to MediaResult Change mLastError type to MediaResult and send it as parameter to PDM::CreateVideoDecoder in order to get detailed error description. MozReview-Commit-ID: 4sIRXTHsrzr
dom/media/platforms/PDMFactory.cpp
dom/media/platforms/wrappers/H264Converter.cpp
dom/media/platforms/wrappers/H264Converter.h
--- a/dom/media/platforms/PDMFactory.cpp
+++ b/dom/media/platforms/PDMFactory.cpp
@@ -286,23 +286,26 @@ PDMFactory::CreateDecoderWithPDM(Platfor
     *result = MediaResult(
       NS_ERROR_DOM_MEDIA_FATAL_ERR,
       RESULT_DETAIL("Decoder configuration error, expected audio or video."));
     return nullptr;
   }
 
   if (MP4Decoder::IsH264(config.mMimeType) && !aParams.mUseNullDecoder) {
     RefPtr<H264Converter> h = new H264Converter(aPDM, aParams);
-    const nsresult rv = h->GetLastError();
-    if (NS_SUCCEEDED(rv) || rv == NS_ERROR_NOT_INITIALIZED) {
+    const MediaResult result = h->GetLastError();
+    if (NS_SUCCEEDED(result) || result == NS_ERROR_NOT_INITIALIZED) {
       // The H264Converter either successfully created the wrapped decoder,
       // or there wasn't enough AVCC data to do so. Otherwise, there was some
       // problem, for example WMF DLLs were missing.
       m = h.forget();
     }
+    if (NS_FAILED(result) && aParams.mError) {
+      *aParams.mError = result;
+    }
   } else {
     m = aPDM->CreateVideoDecoder(aParams);
   }
 
   return m.forget();
 }
 
 bool
--- a/dom/media/platforms/wrappers/H264Converter.cpp
+++ b/dom/media/platforms/wrappers/H264Converter.cpp
@@ -254,42 +254,47 @@ H264Converter::CreateDecoder(const Video
   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 = NS_ERROR_FAILURE;
+      mLastError = MediaResult(NS_ERROR_FAILURE,
+                               RESULT_DETAIL("Not support for YUV444 format."));
       if (aDiagnostics) {
         aDiagnostics->SetVideoNotSupported();
       }
       return NS_ERROR_FAILURE;
     }
   } else {
-    // SPS was invalid.
-    mLastError = NS_ERROR_FAILURE;
+    mLastError = MediaResult(NS_ERROR_FAILURE,
+                             RESULT_DETAIL("Invalid SPS NAL."));
     return NS_ERROR_FAILURE;
   }
 
   mDecoder = mPDM->CreateVideoDecoder({
     aConfig,
     mTaskQueue,
     aDiagnostics,
     mImageContainer,
     mKnowsCompositor,
     mGMPCrashHelper,
     mType,
     mOnWaitingForKeyEvent,
-    mDecoderOptions
+    mDecoderOptions,
+    &mLastError
   });
 
   if (!mDecoder) {
-    mLastError = NS_ERROR_FAILURE;
+    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;
   }
 
   mNeedKeyframe = true;
 
   return NS_OK;
 }
 
--- a/dom/media/platforms/wrappers/H264Converter.h
+++ b/dom/media/platforms/wrappers/H264Converter.h
@@ -54,17 +54,17 @@ public:
   ConversionRequired NeedsConversion() const override
   {
     if (mDecoder) {
       return mDecoder->NeedsConversion();
     }
     // Default so no conversion is performed.
     return ConversionRequired::kNeedAVCC;
   }
-  nsresult GetLastError() const { return mLastError; }
+  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,
                          DecoderDoctorDiagnostics* aDiagnostics);
   nsresult CreateDecoderAndInit(MediaRawData* aSample);
@@ -94,17 +94,17 @@ private:
   MediaDataDecoder::DecodedData mPendingFrames;
   MozPromiseRequestHolder<DecodePromise> mDrainRequest;
   MozPromiseRequestHolder<ShutdownPromise> mShutdownRequest;
   RefPtr<ShutdownPromise> mShutdownPromise;
   MozPromiseHolder<FlushPromise> mFlushPromise;
 
   RefPtr<GMPCrashHelper> mGMPCrashHelper;
   Maybe<bool> mNeedAVCC;
-  nsresult mLastError;
+  MediaResult mLastError;
   bool mNeedKeyframe = true;
   const TrackInfo::TrackType mType;
   MediaEventProducer<TrackInfo::TrackType>* const mOnWaitingForKeyEvent;
   const CreateDecoderParams::OptionSet mDecoderOptions;
   Maybe<bool> mCanRecycleDecoder;
 };
 
 } // namespace mozilla