Bug 1397141 - part4 : change mLastError type to MediaResult r=jya
☠☠ backed out by c59fd8f64b53 ☠ ☠
authorAlastor Wu <alwu@mozilla.com>
Wed, 13 Sep 2017 15:05:52 +0800
changeset 663801 9140f22570ea5bd5f1231e8842c827f73dcefa8e
parent 663800 57ab4c51c72bfd1f0ff88d2c9a113938b5012447
child 663802 6dade48b33261cea22bfde63833ae25a1517bca2
push id79536
push userbmo:rchien@mozilla.com
push dateWed, 13 Sep 2017 12:07:56 +0000
reviewersjya
bugs1397141
milestone57.0a1
Bug 1397141 - part4 : change mLastError type to MediaResult r=jya 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