Bug 1247056 - Report audio sink creation error to dec-doc - r?jwwang draft
authorGerald Squelart <gsquelart@mozilla.com>
Wed, 07 Sep 2016 22:11:26 -0700
changeset 840310 323befa921e1
parent 840309 aa1f79aa4492
child 840311 dcaff8ecde3d
push id143460
push usergsquelart@mozilla.com
push dateThu, 08 Sep 2016 07:44:12 +0000
treeherdertry@dcaff8ecde3d [default view] [failures only]
reviewersjwwang
bugs1247056
milestone51.0a1
Bug 1247056 - Report audio sink creation error to dec-doc - r?jwwang MozReview-Commit-ID: 75SHetFVJea
dom/media/MediaDecoderStateMachine.cpp
dom/media/MediaDecoderStateMachine.h
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -34,16 +34,17 @@
 #include "nsITimer.h"
 #include "nsPrintfCString.h"
 #include "nsTArray.h"
 #include "nsDeque.h"
 #include "prenv.h"
 
 #include "AccurateSeekTask.h"
 #include "AudioSegment.h"
+#include "DecoderDoctorDiagnostics.h"
 #include "DOMMediaStream.h"
 #include "ImageContainer.h"
 #include "MediaDecoder.h"
 #include "MediaDecoderReader.h"
 #include "MediaDecoderReaderWrapper.h"
 #include "MediaDecoderStateMachine.h"
 #include "MediaShutdownManager.h"
 #include "MediaPrefs.h"
@@ -2739,25 +2740,45 @@ void MediaDecoderStateMachine::OnMediaSi
   VERBOSE_LOG("[%s]", __func__);
 
   mMediaSinkAudioPromise.Complete();
   mAudioCompleted = true;
   // To notify PlaybackEnded as soon as possible.
   ScheduleStateMachine();
 }
 
-void MediaDecoderStateMachine::OnMediaSinkAudioError()
+void MediaDecoderStateMachine::OnMediaSinkAudioError(nsresult rv)
 {
   MOZ_ASSERT(OnTaskQueue());
   MOZ_ASSERT(mInfo.HasAudio());
   VERBOSE_LOG("[%s]", __func__);
 
   mMediaSinkAudioPromise.Complete();
   mAudioCompleted = true;
 
+  RefPtr<MediaDecoderStateMachine> self(this);
+  nsCOMPtr<nsIRunnable> r = NS_NewRunnableFunction([self, rv] () {
+    MOZ_ASSERT(NS_IsMainThread());
+    MediaDecoderOwner* decoderOwner = self->mDecoderOwner;
+    if (!decoderOwner) {
+      return;
+    }
+    HTMLMediaElement* element = decoderOwner->GetMediaElement();
+    if (!element) {
+      return;
+    }
+    nsIDocument* doc = element->OwnerDoc();
+    if (!doc) {
+      return;
+    }
+    DecoderDoctorDiagnostics diagnostics;
+    diagnostics.StoreImmediateError(doc, "MediaAudioSinkError", rv, __func__);
+  });
+  AbstractThread::MainThread()->Dispatch(r.forget());
+
   // Make the best effort to continue playback when there is video.
   if (HasVideo()) {
     return;
   }
 
   // Otherwise notify media decoder/element about this error for it makes
   // no sense to play an audio-only file without sound output.
   DecodeError();
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -572,17 +572,17 @@ protected:
 
 private:
   // Resolved by the MediaSink to signal that all audio/video outstanding
   // work is complete and identify which part(a/v) of the sink is shutting down.
   void OnMediaSinkAudioComplete();
   void OnMediaSinkVideoComplete();
 
   // Rejected by the MediaSink to signal errors for audio/video.
-  void OnMediaSinkAudioError();
+  void OnMediaSinkAudioError(nsresult rv);
   void OnMediaSinkVideoError();
 
   // Return true if the video decoder's decode speed can not catch up the
   // play time.
   bool NeedToSkipToNextKeyframe();
 
   // This should only ever be accessed from the main thread.
   // It is set in Init() and cleared in BeginShutdown().