Bug 1400758 - part1 : report the error description with InitPromise for Apple's decoders. draft
authorAlastor Wu <alwu@mozilla.com>
Mon, 18 Sep 2017 18:05:21 +0800
changeset 666239 8064839a8a795c1efb07b8c4596836583f0b06ec
parent 664736 dd6b788f149763c4014c27f2fe1a1d13228bda82
child 666240 6ef0cdb830fc4fb8e6979e8a79e945744e53b10a
child 666242 eba38d2d663018b71db3aaf0e552ba5161e6b226
push id80333
push useralwu@mozilla.com
push dateMon, 18 Sep 2017 10:07:06 +0000
bugs1400758
milestone57.0a1
Bug 1400758 - part1 : report the error description with InitPromise for Apple's decoders. MozReview-Commit-ID: 8rifWLm8BPt
dom/media/platforms/apple/AppleATDecoder.cpp
dom/media/platforms/apple/AppleVTDecoder.cpp
dom/media/platforms/apple/AppleVTDecoder.h
--- a/dom/media/platforms/apple/AppleATDecoder.cpp
+++ b/dom/media/platforms/apple/AppleATDecoder.cpp
@@ -1,19 +1,19 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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 "AppleATDecoder.h"
 #include "AppleUtils.h"
 #include "MP4Decoder.h"
 #include "mp4_demuxer/Adts.h"
 #include "MediaInfo.h"
-#include "AppleATDecoder.h"
 #include "mozilla/Logging.h"
 #include "mozilla/SyncRunnable.h"
 #include "mozilla/UniquePtr.h"
 
 #define LOG(...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
 #define FourCC2Str(n) ((char[5]){(char)(n >> 24), (char)(n >> 16), (char)(n >> 8), (char)(n), 0})
 
 namespace mozilla {
@@ -50,18 +50,20 @@ AppleATDecoder::~AppleATDecoder()
   MOZ_COUNT_DTOR(AppleATDecoder);
   MOZ_ASSERT(!mConverter);
 }
 
 RefPtr<MediaDataDecoder::InitPromise>
 AppleATDecoder::Init()
 {
   if (!mFormatID) {
-    NS_ERROR("Non recognised format");
-    return InitPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_FATAL_ERR, __func__);
+    return InitPromise::CreateAndReject(
+      MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
+                  RESULT_DETAIL("Non recognised format")),
+      __func__);
   }
 
   return InitPromise::CreateAndResolve(TrackType::kAudioTrack, __func__);
 }
 
 RefPtr<MediaDataDecoder::DecodePromise>
 AppleATDecoder::Decode(MediaRawData* aSample)
 {
--- a/dom/media/platforms/apple/AppleVTDecoder.cpp
+++ b/dom/media/platforms/apple/AppleVTDecoder.cpp
@@ -1,20 +1,20 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 et cindent: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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 <CoreFoundation/CFString.h>
 
+#include "AppleVTDecoder.h"
 #include "AppleCMLinker.h"
 #include "AppleDecoderModule.h"
 #include "AppleUtils.h"
-#include "AppleVTDecoder.h"
 #include "AppleVTLinker.h"
 #include "MediaData.h"
 #include "mozilla/ArrayUtils.h"
 #include "mp4_demuxer/H264.h"
 #include "nsAutoPtr.h"
 #include "nsThreadUtils.h"
 #include "mozilla/Logging.h"
 #include "VideoUtils.h"
@@ -58,23 +58,23 @@ AppleVTDecoder::AppleVTDecoder(const Vid
 AppleVTDecoder::~AppleVTDecoder()
 {
   MOZ_COUNT_DTOR(AppleVTDecoder);
 }
 
 RefPtr<MediaDataDecoder::InitPromise>
 AppleVTDecoder::Init()
 {
-  nsresult rv = InitializeSession();
+  MediaResult rv = InitializeSession();
 
   if (NS_SUCCEEDED(rv)) {
     return InitPromise::CreateAndResolve(TrackType::kVideoTrack, __func__);
   }
 
-  return InitPromise::CreateAndReject(NS_ERROR_DOM_MEDIA_FATAL_ERR, __func__);
+  return InitPromise::CreateAndReject(rv, __func__);
 }
 
 RefPtr<MediaDataDecoder::DecodePromise>
 AppleVTDecoder::Decode(MediaRawData* aSample)
 {
   LOG("mp4 input sample %p pts %lld duration %lld us%s %zu bytes",
       aSample,
       aSample->mTime.ToMicroseconds(),
@@ -468,32 +468,32 @@ AppleVTDecoder::WaitForAsynchronousFrame
   OSStatus rv = VTDecompressionSessionWaitForAsynchronousFrames(mSession);
   if (rv != noErr) {
     NS_ERROR("AppleVTDecoder: Error waiting for asynchronous frames");
     return NS_ERROR_FAILURE;
   }
   return NS_OK;
 }
 
-nsresult
+MediaResult
 AppleVTDecoder::InitializeSession()
 {
   OSStatus rv;
 
   AutoCFRelease<CFDictionaryRef> extensions = CreateDecoderExtensions();
 
   rv = CMVideoFormatDescriptionCreate(kCFAllocatorDefault,
                                       kCMVideoCodecType_H264,
                                       mPictureWidth,
                                       mPictureHeight,
                                       extensions,
                                       &mFormat);
   if (rv != noErr) {
-    NS_ERROR("Couldn't create format description!");
-    return NS_ERROR_FAILURE;
+    return MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
+                       RESULT_DETAIL("Couldn't create format description!"));
   }
 
   // Contruct video decoder selection spec.
   AutoCFRelease<CFDictionaryRef> spec = CreateDecoderSpecification();
 
   // Contruct output configuration.
   AutoCFRelease<CFDictionaryRef> outputConfiguration =
     CreateOutputConfiguration();
@@ -502,18 +502,18 @@ AppleVTDecoder::InitializeSession()
   rv = VTDecompressionSessionCreate(kCFAllocatorDefault,
                                     mFormat,
                                     spec, // Video decoder selection.
                                     outputConfiguration, // Output video format.
                                     &cb,
                                     &mSession);
 
   if (rv != noErr) {
-    NS_ERROR("Couldn't create decompression session!");
-    return NS_ERROR_FAILURE;
+    return MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
+                       RESULT_DETAIL("Couldn't create decompression session!"));
   }
 
   if (AppleVTLinker::skPropUsingHWAccel) {
     CFBooleanRef isUsingHW = nullptr;
     rv = VTSessionCopyProperty(mSession,
                                AppleVTLinker::skPropUsingHWAccel,
                                kCFAllocatorDefault,
                                &isUsingHW);
--- a/dom/media/platforms/apple/AppleVTDecoder.h
+++ b/dom/media/platforms/apple/AppleVTDecoder.h
@@ -87,17 +87,17 @@ private:
 
   const RefPtr<MediaByteBuffer> mExtraData;
   const uint32_t mPictureWidth;
   const uint32_t mPictureHeight;
   const uint32_t mDisplayWidth;
   const uint32_t mDisplayHeight;
 
   // Method to set up the decompression session.
-  nsresult InitializeSession();
+  MediaResult InitializeSession();
   nsresult WaitForAsynchronousFrames();
   CFDictionaryRef CreateDecoderSpecification();
   CFDictionaryRef CreateDecoderExtensions();
 
   const RefPtr<TaskQueue> mTaskQueue;
   const uint32_t mMaxRefFrames;
   const RefPtr<layers::ImageContainer> mImageContainer;
   const bool mUseSoftwareImages;