Bug 1247056 - Handle PulseAudio init error in DecDoc - r=jwwang draft
authorGerald Squelart <gsquelart@mozilla.com>
Sun, 18 Sep 2016 19:41:36 -0700
changeset 417923 b557992bb78c
parent 417922 269f30b363e6
child 417924 2c8bfb9e7ce6
push id30524
push usergsquelart@mozilla.com
push dateTue, 27 Sep 2016 09:30:55 +0000
reviewersjwwang
bugs1247056
milestone52.0a1
Bug 1247056 - Handle PulseAudio init error in DecDoc - r=jwwang MozReview-Commit-ID: 8qa0MO35mRD
dom/locales/en-US/chrome/dom/dom.properties
dom/media/DecoderDoctorDiagnostics.cpp
dom/media/DecoderDoctorDiagnostics.h
modules/libpref/init/all.js
--- a/dom/locales/en-US/chrome/dom/dom.properties
+++ b/dom/locales/en-US/chrome/dom/dom.properties
@@ -129,16 +129,17 @@ MediaWMFNeeded=To play video formats %S,
 # LOCALIZATION NOTE: %S is a comma-separated list of codecs (e.g. 'video/mp4, video/webm')
 MediaUnsupportedBeforeWindowsVista=Video formats %S unsupported by Microsoft before Windows Vista
 # LOCALIZATION NOTE: %S is a comma-separated list of codecs (e.g. 'video/mp4, video/webm')
 MediaPlatformDecoderNotFound=The video on this page can’t be played. Your system may not have the required video codecs for: %S
 # LOCALIZATION NOTE: %S is a comma-separated list of codecs (e.g. 'video/mp4, video/webm')
 MediaCannotPlayNoDecoders=Cannot play media. No decoders for requested formats: %S
 # LOCALIZATION NOTE: %S is a comma-separated list of codecs (e.g. 'video/mp4, video/webm')
 MediaNoDecoders=No decoders for some of the requested formats: %S
+MediaCannotInitializePulseAudio=Unable to use PulseAudio
 # LOCALIZATION NOTE: Do not translate "MediaRecorder".
 MediaRecorderMultiTracksNotSupported=MediaRecorder does not support recording multiple tracks of the same type at this time.
 # LOCALIZATION NOTE: %S is the ID of the MediaStreamTrack passed to MediaStream.addTrack(). Do not translate "MediaStreamTrack" and "AudioChannel".
 MediaStreamAddTrackDifferentAudioChannel=MediaStreamTrack %S could not be added since it belongs to a different AudioChannel.
 # LOCALIZATION NOTE: Do not translate "MediaStream", "stop()" and "MediaStreamTrack"
 MediaStreamStopDeprecatedWarning=MediaStream.stop() is deprecated and will soon be removed. Use MediaStreamTrack.stop() instead.
 # LOCALIZATION NOTE: Do not translate "DOMException", "code" and "name"
 DOMExceptionCodeWarning=Use of DOMException’s code attribute is deprecated. Use name instead.
--- a/dom/media/DecoderDoctorDiagnostics.cpp
+++ b/dom/media/DecoderDoctorDiagnostics.cpp
@@ -259,26 +259,30 @@ static const NotificationAndReportString
   { dom::DecoderDoctorNotificationType::Platform_decoder_not_found,
     "MediaPlatformDecoderNotFound" };
 static const NotificationAndReportStringId sMediaCannotPlayNoDecoders =
   { dom::DecoderDoctorNotificationType::Cannot_play,
     "MediaCannotPlayNoDecoders" };
 static const NotificationAndReportStringId sMediaNoDecoders =
   { dom::DecoderDoctorNotificationType::Can_play_but_some_missing_decoders,
     "MediaNoDecoders" };
+static const NotificationAndReportStringId sCannotInitializePulseAudio =
+  { dom::DecoderDoctorNotificationType::Cannot_initialize_pulseaudio,
+    "MediaCannotInitializePulseAudio" };
 
 static const NotificationAndReportStringId*
 sAllNotificationsAndReportStringIds[] =
 {
   &sMediaWidevineNoWMFNoSilverlight,
   &sMediaWMFNeeded,
   &sMediaUnsupportedBeforeWindowsVista,
   &sMediaPlatformDecoderNotFound,
   &sMediaCannotPlayNoDecoders,
-  &sMediaNoDecoders
+  &sMediaNoDecoders,
+  &sCannotInitializePulseAudio
 };
 
 static void
 DispatchNotification(nsISupports* aSubject,
                      const NotificationAndReportStringId& aNotification,
                      bool aIsSolved,
                      const nsAString& aFormats)
 {
@@ -752,24 +756,42 @@ DecoderDoctorDiagnostics::StoreEvent(nsI
   mEvent = aEvent;
 
   if (NS_WARN_IF(!aDocument)) {
     DD_WARN("DecoderDoctorDiagnostics[%p]::StoreEvent(nsIDocument* aDocument=nullptr, aEvent=%s, call site '%s')",
             this, GetDescription().get(), aCallSite);
     return;
   }
 
-  // TODO: Handle event here.
+  // Don't keep events for later processing, just handle them now.
+#ifdef MOZ_PULSEAUDIO
+  switch (aEvent.mDomain) {
+    case DecoderDoctorEvent::eAudioSinkStartup:
+      if (aEvent.mResult == NS_ERROR_DOM_MEDIA_CUBEB_INITIALIZATION_ERR) {
+        DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::AddDiagnostics() - unable to initialize PulseAudio",
+                this, aDocument);
+        ReportAnalysis(aDocument, sCannotInitializePulseAudio,
+                       false, NS_LITERAL_STRING("*"));
+      } else if (aEvent.mResult == NS_OK) {
+        DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::AddDiagnostics() - now able to initialize PulseAudio",
+                this, aDocument);
+        ReportAnalysis(aDocument, sCannotInitializePulseAudio,
+                       true, NS_LITERAL_STRING("*"));
+      }
+      break;
+  }
+#endif // MOZ_PULSEAUDIO
 }
 
 static const char*
 EventDomainString(DecoderDoctorEvent::Domain aDomain)
 {
   switch (aDomain) {
-    // TODO
+    case DecoderDoctorEvent::eAudioSinkStartup:
+      return "audio-sink-startup";
   }
   return "?";
 }
 
 nsCString
 DecoderDoctorDiagnostics::GetDescription() const
 {
   nsCString s;
--- a/dom/media/DecoderDoctorDiagnostics.h
+++ b/dom/media/DecoderDoctorDiagnostics.h
@@ -10,17 +10,17 @@
 #include "nsString.h"
 
 class nsIDocument;
 
 namespace mozilla {
 
 struct DecoderDoctorEvent {
   enum Domain {
-    // TODO
+    eAudioSinkStartup,
   } mDomain;
   nsresult mResult;
 };
 
 // DecoderDoctorDiagnostics class, used to gather data from PDMs/DecoderTraits,
 // and then notify the user about issues preventing (or worsening) playback.
 //
 // The expected usage is:
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -386,17 +386,17 @@ pref("media.apple.mp4.enabled", true);
 // media.gmp.storage.version.observed, and if the versions don't match,
 // we clear storage and set media.gmp.storage.version.observed=expected.
 // This provides a mechanism to clear GMP storage when non-compatible
 // changes are made.
 pref("media.gmp.storage.version.expected", 1);
 
 // Filter what triggers user notifications.
 // See DecoderDoctorDocumentWatcher::ReportAnalysis for details.
-pref("media.decoder-doctor.notifications-allowed", "MediaWMFNeeded,MediaWidevineNoWMFNoSilverlight");
+pref("media.decoder-doctor.notifications-allowed", "MediaWMFNeeded,MediaWidevineNoWMFNoSilverlight,MediaCannotInitializePulseAudio");
 // Whether we report partial failures.
 pref("media.decoder-doctor.verbose", false);
 // Whether DD should consider WMF-disabled a WMF failure, useful for testing.
 pref("media.decoder-doctor.wmf-disabled-is-failure", false);
 
 // Whether to suspend decoding of videos in background tabs.
 #ifdef NIGHTLY_BUILD
 pref("media.suspend-bkgnd-video.enabled", true);