Bug 1347758 - part4 : add audio channel log. r=Ehsan
☠☠ backed out by e7dbc2e8b2f9 ☠ ☠
authorAlastor Wu <alwu@mozilla.com>
Fri, 24 Mar 2017 12:04:15 +0800
changeset 349365 80232d4c85d546b267972a493cd96fd1be5f4017
parent 349364 1fd084ec34d4e189f5a855cb3a25310bb8815299
child 349366 2abce19f5001f97ff7df214cb2a92b6d81ffa0be
push id31550
push usercbook@mozilla.com
push dateFri, 24 Mar 2017 13:22:27 +0000
treeherdermozilla-central@473e0b201761 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersEhsan
bugs1347758
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1347758 - part4 : add audio channel log. r=Ehsan MozReview-Commit-ID: LNXzRZx2rC2
dom/audiochannel/AudioChannelAgent.cpp
dom/audiochannel/AudioChannelService.cpp
dom/audiochannel/AudioChannelService.h
dom/base/nsGlobalWindow.cpp
dom/html/HTMLMediaElement.cpp
dom/media/webaudio/AudioDestinationNode.cpp
dom/plugins/base/nsNPAPIPluginInstance.cpp
--- a/dom/audiochannel/AudioChannelAgent.cpp
+++ b/dom/audiochannel/AudioChannelAgent.cpp
@@ -215,18 +215,20 @@ AudioChannelAgent::NotifyStartedPlaying(
   service->RegisterAudioChannelAgent(this,
     static_cast<AudioChannelService::AudibleState>(aAudible));
 
   AudioPlaybackConfig config = service->GetMediaConfig(mWindow,
                                                        mAudioChannelType);
 
   MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
          ("AudioChannelAgent, NotifyStartedPlaying, this = %p, "
-          "audible = %d, mute = %d, volume = %f, suspend = %d\n", this,
-          aAudible, config.mMuted, config.mVolume, config.mSuspend));
+          "audible = %s, mute = %s, volume = %f, suspend = %s\n", this,
+          AudibleStateToStr(static_cast<AudioChannelService::AudibleState>(aAudible)),
+          config.mMuted ? "true" : "false", config.mVolume,
+          SuspendTypeToStr(config.mSuspend)));
 
   aConfig->SetConfig(config.mVolume, config.mMuted, config.mSuspend);
   mIsRegToService = true;
   return NS_OK;
 }
 
 NS_IMETHODIMP
 AudioChannelAgent::NotifyStoppedPlaying()
@@ -248,17 +250,19 @@ AudioChannelAgent::NotifyStoppedPlaying(
   return NS_OK;
 }
 
 NS_IMETHODIMP
 AudioChannelAgent::NotifyStartedAudible(uint8_t aAudible, uint32_t aReason)
 {
   MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
          ("AudioChannelAgent, NotifyStartedAudible, this = %p, "
-          "audible = %d, reason = %d\n", this, aAudible, aReason));
+          "audible = %s, reason = %s\n", this,
+          AudibleStateToStr(static_cast<AudioChannelService::AudibleState>(aAudible)),
+          AudibleChangedReasonToStr(static_cast<AudioChannelService::AudibleChangedReasons>(aReason))));
 
   RefPtr<AudioChannelService> service = AudioChannelService::GetOrCreate();
   if (NS_WARN_IF(!service)) {
     return NS_ERROR_FAILURE;
   }
 
   service->AudioAudibleChanged(
     this,
@@ -282,18 +286,19 @@ AudioChannelAgent::WindowVolumeChanged()
 {
   nsCOMPtr<nsIAudioChannelAgentCallback> callback = GetCallback();
   if (!callback) {
     return;
   }
 
   AudioPlaybackConfig config = GetMediaConfig();
   MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
-         ("AudioChannelAgent, WindowVolumeChanged, this = %p, mute = %d, "
-          "volume = %f\n", this, config.mMuted, config.mVolume));
+         ("AudioChannelAgent, WindowVolumeChanged, this = %p, mute = %s, "
+          "volume = %f\n",
+          this, config.mMuted ? "true" : "false", config.mVolume));
 
   callback->WindowVolumeChanged(config.mVolume, config.mMuted);
 }
 
 void
 AudioChannelAgent::WindowSuspendChanged(nsSuspendedTypes aSuspend)
 {
   nsCOMPtr<nsIAudioChannelAgentCallback> callback = GetCallback();
@@ -302,17 +307,17 @@ AudioChannelAgent::WindowSuspendChanged(
   }
 
   if (!IsDisposableSuspend(aSuspend)) {
     aSuspend = GetMediaConfig().mSuspend;
   }
 
   MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
          ("AudioChannelAgent, WindowSuspendChanged, this = %p, "
-          "suspended = %d\n", this, aSuspend));
+          "suspended = %s\n", this, SuspendTypeToStr(aSuspend)));
 
   callback->WindowSuspendChanged(aSuspend);
 }
 
 AudioPlaybackConfig
 AudioChannelAgent::GetMediaConfig()
 {
   RefPtr<AudioChannelService> service = AudioChannelService::GetOrCreate();
--- a/dom/audiochannel/AudioChannelService.cpp
+++ b/dom/audiochannel/AudioChannelService.cpp
@@ -88,18 +88,18 @@ public:
     // TODO : remove b2g related event in bug1299390.
     observerService->NotifyObservers(wrapper,
                                      "media-playback",
                                      mActive
                                        ? u"active"
                                        : u"inactive");
 
     MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
-           ("NotifyChannelActiveRunnable, type = %" PRIu32 ", active = %d\n",
-            static_cast<uint32_t>(mAudioChannel), mActive));
+           ("NotifyChannelActiveRunnable, type = %" PRIu32 ", active = %s\n",
+            static_cast<uint32_t>(mAudioChannel), mActive ? "true" : "false"));
 
     return NS_OK;
   }
 
 private:
   const uint64_t mWindowID;
   const AudioChannel mAudioChannel;
   const bool mActive;
@@ -132,18 +132,18 @@ public:
     nsAutoString state;
     GetActiveState(state);
 
     observerService->NotifyObservers(ToSupports(mWindow),
                                      "audio-playback",
                                      state.get());
 
     MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
-           ("AudioPlaybackRunnable, active = %d, reason = %d\n",
-            mActive, mReason));
+           ("AudioPlaybackRunnable, active = %s, reason = %s\n",
+            mActive ? "true" : "false", AudibleChangedReasonToStr(mReason)));
 
     return NS_OK;
   }
 
 private:
   void GetActiveState(nsAString& astate)
   {
     if (mActive) {
@@ -175,16 +175,82 @@ IsEnableAudioCompetingForAllAgents()
   return true;
 #else
   return sAudioChannelCompetingAllAgents;
 #endif
 }
 
 } // anonymous namespace
 
+namespace mozilla {
+namespace dom {
+
+const char*
+SuspendTypeToStr(const nsSuspendedTypes& aSuspend)
+{
+  MOZ_ASSERT(aSuspend == nsISuspendedTypes::NONE_SUSPENDED ||
+             aSuspend == nsISuspendedTypes::SUSPENDED_PAUSE ||
+             aSuspend == nsISuspendedTypes::SUSPENDED_BLOCK ||
+             aSuspend == nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE ||
+             aSuspend == nsISuspendedTypes::SUSPENDED_STOP_DISPOSABLE);
+
+  switch (aSuspend) {
+    case nsISuspendedTypes::NONE_SUSPENDED:
+      return "none";
+    case nsISuspendedTypes::SUSPENDED_PAUSE:
+      return "pause";
+    case nsISuspendedTypes::SUSPENDED_BLOCK:
+      return "block";
+    case nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE:
+      return "disposable-pause";
+    case nsISuspendedTypes::SUSPENDED_STOP_DISPOSABLE:
+      return "disposable-stop";
+    default:
+      return "unknown";
+  }
+}
+
+const char*
+AudibleStateToStr(const AudioChannelService::AudibleState& aAudible)
+{
+  MOZ_ASSERT(aAudible == AudioChannelService::AudibleState::eNotAudible ||
+             aAudible == AudioChannelService::AudibleState::eMaybeAudible ||
+             aAudible == AudioChannelService::AudibleState::eAudible);
+
+  switch (aAudible) {
+    case AudioChannelService::AudibleState::eNotAudible :
+      return "not-audible";
+    case AudioChannelService::AudibleState::eMaybeAudible :
+      return "maybe-audible";
+    case AudioChannelService::AudibleState::eAudible :
+      return "audible";
+    default:
+      return "unknown";
+  }
+}
+
+const char*
+AudibleChangedReasonToStr(const AudioChannelService::AudibleChangedReasons& aReason)
+{
+  MOZ_ASSERT(aReason == AudioChannelService::AudibleChangedReasons::eVolumeChanged ||
+             aReason == AudioChannelService::AudibleChangedReasons::eDataAudibleChanged ||
+             aReason == AudioChannelService::AudibleChangedReasons::ePauseStateChanged);
+
+  switch (aReason) {
+    case AudioChannelService::AudibleChangedReasons::eVolumeChanged :
+      return "volume";
+    case AudioChannelService::AudibleChangedReasons::eDataAudibleChanged :
+      return "data-audible";
+    case AudioChannelService::AudibleChangedReasons::ePauseStateChanged :
+      return "pause-state";
+    default:
+      return "unknown";
+  }
+}
+
 StaticRefPtr<AudioChannelService> gAudioChannelService;
 
 // Mappings from 'mozaudiochannel' attribute strings to an enumeration.
 static const nsAttrValue::EnumTable kMozAudioChannelAttributeTable[] = {
   { "normal",             (int16_t)AudioChannel::Normal },
   { "content",            (int16_t)AudioChannel::Content },
   { "notification",       (int16_t)AudioChannel::Notification },
   { "alarm",              (int16_t)AudioChannel::Alarm },
@@ -898,17 +964,18 @@ AudioChannelService::SetAudioChannelMute
                                           bool aMuted)
 {
   MOZ_ASSERT(NS_IsMainThread());
   MOZ_ASSERT(aWindow);
   MOZ_ASSERT(aWindow->IsOuterWindow());
 
   MOZ_LOG(GetAudioChannelLog(), LogLevel::Debug,
          ("AudioChannelService, SetAudioChannelMuted, window = %p, type = %" PRIu32 ", "
-          "mute = %d\n", aWindow, static_cast<uint32_t>(aAudioChannel), aMuted));
+          "mute = %s\n", aWindow, static_cast<uint32_t>(aAudioChannel),
+          aMuted ? "true" : "false"));
 
   if (aAudioChannel == AudioChannel::System) {
     // Workaround for bug1183033, system channel type can always playback.
     return;
   }
 
   AudioChannelWindow* winData = GetOrCreateWindowData(aWindow);
   winData->mChannels[(uint32_t)aAudioChannel].mMuted = aMuted;
@@ -1139,18 +1206,18 @@ AudioChannelService::AudioChannelWindow:
   // One exception is if the pref "media.block-autoplay-until-in-foreground"
   // is on and the background page is the non-visited before. Because the media
   // in that page would be blocked until the page is going to foreground.
   mOwningAudioFocus = (!(aAgent->Window()->IsBackground()) ||
                        aAgent->Window()->GetMediaSuspend() == nsISuspendedTypes::SUSPENDED_BLOCK) ;
 
   MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
          ("AudioChannelWindow, RequestAudioFocus, this = %p, "
-          "agent = %p, owning audio focus = %d\n",
-          this, aAgent, mOwningAudioFocus));
+          "agent = %p, owning audio focus = %s\n",
+          this, aAgent, mOwningAudioFocus ? "true" : "false"));
 }
 
 void
 AudioChannelService::AudioChannelWindow::NotifyAudioCompetingChanged(AudioChannelAgent* aAgent)
 {
   // This function may be called after RemoveAgentAndReduceAgentsNum(), so the
   // agent may be not contained in mAgent. In addition, the agent would still
   // be alive because we have kungFuDeathGrip in UnregisterAudioChannelAgent().
@@ -1241,17 +1308,17 @@ AudioChannelService::AudioChannelWindow:
           agent->WindowSuspendChanged(type);
           break;
       }
     }
   }
 
   MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
          ("AudioChannelWindow, AudioFocusChanged, this = %p, "
-          "OwningAudioFocus = %d\n", this, mOwningAudioFocus));
+          "OwningAudioFocus = %s\n", this, mOwningAudioFocus ? "true" : "false"));
 }
 
 bool
 AudioChannelService::AudioChannelWindow::IsContainingPlayingAgent(AudioChannelAgent* aAgent) const
 {
   return (aAgent->WindowID() == mWindowID);
 }
 
@@ -1269,18 +1336,19 @@ AudioChannelService::AudioChannelWindow:
   // TODO : add other competing cases for MediaSession API
   if (presentChannelType == int32_t(AudioChannel::Normal) &&
       aIncomingChannelType == int32_t(AudioChannel::Normal)) {
     competingBehavior = nsISuspendedTypes::SUSPENDED_STOP_DISPOSABLE;
   }
 
   MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
          ("AudioChannelWindow, GetCompetingBehavior, this = %p, "
-          "present type = %d, incoming channel = %d, behavior = %d\n",
-          this, presentChannelType, aIncomingChannelType, competingBehavior));
+          "present type = %d, incoming channel = %d, behavior = %s\n",
+          this, presentChannelType, aIncomingChannelType,
+          SuspendTypeToStr(competingBehavior)));
 
   return competingBehavior;
 }
 
 /* static */ bool
 AudioChannelService::IsAudioChannelMutedByDefault()
 {
   CreateServiceIfNeeded();
@@ -1513,8 +1581,12 @@ AudioChannelService::AudioChannelWindow:
 
         observerService->NotifyObservers(ToSupports(window),
                                          "audio-playback",
                                          u"blockStart");
       })
     );
   }
 }
+
+} // namespace dom
+} // namespace mozilla
+
--- a/dom/audiochannel/AudioChannelService.h
+++ b/dom/audiochannel/AudioChannelService.h
@@ -364,12 +364,16 @@ private:
   bool mAnyChannel;
 
   // This is needed for IPC comunication between
   // AudioChannelServiceChild and this class.
   friend class ContentParent;
   friend class ContentChild;
 };
 
+const char* SuspendTypeToStr(const nsSuspendedTypes& aSuspend);
+const char* AudibleStateToStr(const AudioChannelService::AudibleState& aAudible);
+const char* AudibleChangedReasonToStr(const AudioChannelService::AudibleChangedReasons& aReason);
+
 } // namespace dom
 } // namespace mozilla
 
 #endif
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -4380,16 +4380,20 @@ nsPIDOMWindowOuter::MaybeActiveMediaComp
   }
 
   // If the document is not visible, don't need to resume it.
   nsCOMPtr<nsIDocument> doc = inner->GetExtantDoc();
   if (!doc || doc->Hidden()) {
     return;
   }
 
+  MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
+         ("nsPIDOMWindowOuter, MaybeActiveMediaComponents, "
+          "resume the window from blocked, this = %p\n", this));
+
   SetMediaSuspend(nsISuspendedTypes::NONE_SUSPENDED);
 }
 
 SuspendTypes
 nsPIDOMWindowOuter::GetMediaSuspend() const
 {
   if (IsInnerWindow()) {
     return mOuterWindow->GetMediaSuspend();
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -687,17 +687,18 @@ public:
 
   NS_IMETHODIMP
   WindowVolumeChanged(float aVolume, bool aMuted) override
   {
     MOZ_ASSERT(mAudioChannelAgent);
 
     MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
            ("HTMLMediaElement::AudioChannelAgentCallback, WindowVolumeChanged, "
-            "this = %p, aVolume = %f, aMuted = %d\n", this, aVolume, aMuted));
+            "this = %p, aVolume = %f, aMuted = %s\n",
+            this, aVolume, aMuted ? "true" : "false"));
 
     if (mAudioChannelVolume != aVolume) {
       mAudioChannelVolume = aVolume;
       mOwner->SetVolumeInternal();
     }
 
     const uint32_t muted = mOwner->mMuted;
     if (aMuted && !mOwner->ComputedMuted()) {
@@ -711,17 +712,17 @@ public:
 
   NS_IMETHODIMP
   WindowSuspendChanged(SuspendTypes aSuspend) override
   {
     MOZ_ASSERT(mAudioChannelAgent);
 
     MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
            ("HTMLMediaElement::AudioChannelAgentCallback, WindowSuspendChanged, "
-            "this = %p, aSuspend = %d\n", this, aSuspend));
+            "this = %p, aSuspend = %s\n", this, SuspendTypeToStr(aSuspend)));
 
     switch (aSuspend) {
       case nsISuspendedTypes::NONE_SUSPENDED:
         Resume();
         break;
       case nsISuspendedTypes::SUSPENDED_PAUSE:
       case nsISuspendedTypes::SUSPENDED_PAUSE_DISPOSABLE:
       case nsISuspendedTypes::SUSPENDED_BLOCK:
@@ -878,17 +879,17 @@ private:
     if (mSuspended == aSuspend) {
       return;
     }
 
     MaybeNotifyMediaResumed(aSuspend);
     mSuspended = aSuspend;
     MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
            ("HTMLMediaElement::AudioChannelAgentCallback, SetAudioChannelSuspended, "
-            "this = %p, aSuspend = %d\n", this, aSuspend));
+            "this = %p, aSuspend = %s\n", this, SuspendTypeToStr(aSuspend)));
 
     NotifyAudioPlaybackChanged(
       AudioChannelService::AudibleChangedReasons::ePauseStateChanged);
   }
 
   void
   Resume()
   {
--- a/dom/media/webaudio/AudioDestinationNode.cpp
+++ b/dom/media/webaudio/AudioDestinationNode.cpp
@@ -502,16 +502,21 @@ AudioDestinationNode::StartRendering(Pro
 
 NS_IMETHODIMP
 AudioDestinationNode::WindowVolumeChanged(float aVolume, bool aMuted)
 {
   if (!mStream) {
     return NS_OK;
   }
 
+  MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
+         ("AudioDestinationNode, WindowVolumeChanged, "
+          "this = %p, aVolume = %f, aMuted = %s\n",
+          this, aVolume, aMuted ? "true" : "false"));
+
   float volume = aMuted ? 0.0 : aVolume;
   mStream->SetAudioOutputVolume(&gWebAudioOutputKey, volume);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 AudioDestinationNode::WindowSuspendChanged(nsSuspendedTypes aSuspend)
 {
@@ -519,16 +524,20 @@ AudioDestinationNode::WindowSuspendChang
     return NS_OK;
   }
 
   bool suspended = (aSuspend != nsISuspendedTypes::NONE_SUSPENDED);
   if (mAudioChannelSuspended == suspended) {
     return NS_OK;
   }
 
+  MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
+         ("AudioDestinationNode, WindowSuspendChanged, "
+          "this = %p, aSuspend = %s\n", this, SuspendTypeToStr(aSuspend)));
+
   mAudioChannelSuspended = suspended;
   Context()->DispatchTrustedEvent(!suspended ?
     NS_LITERAL_STRING("mozinterruptend") :
     NS_LITERAL_STRING("mozinterruptbegin"));
 
   DisabledTrackMode disabledMode = suspended ? DisabledTrackMode::SILENCE_BLACK
                                              : DisabledTrackMode::ENABLED;
   mStream->SetTrackEnabled(AudioNodeStream::AUDIO_TRACK, disabledMode);
--- a/dom/plugins/base/nsNPAPIPluginInstance.cpp
+++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp
@@ -1733,16 +1733,21 @@ nsNPAPIPluginInstance::GetOrCreateAudioC
   nsCOMPtr<nsIAudioChannelAgent> agent = mAudioChannelAgent;
   agent.forget(aAgent);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNPAPIPluginInstance::WindowVolumeChanged(float aVolume, bool aMuted)
 {
+  MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
+         ("nsNPAPIPluginInstance, WindowVolumeChanged, "
+          "this = %p, aVolume = %f, aMuted = %s\n",
+          this, aVolume, aMuted ? "true" : "false"));
+
   // We just support mute/unmute
   nsresult rv = SetMuted(aMuted);
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "SetMuted failed");
   if (mMuted != aMuted) {
     mMuted = aMuted;
     if (mAudioChannelAgent) {
       AudioChannelService::AudibleState audible = aMuted ?
         AudioChannelService::AudibleState::eNotAudible :
@@ -1752,16 +1757,20 @@ nsNPAPIPluginInstance::WindowVolumeChang
     }
   }
   return rv;
 }
 
 NS_IMETHODIMP
 nsNPAPIPluginInstance::WindowSuspendChanged(nsSuspendedTypes aSuspend)
 {
+  MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
+         ("nsNPAPIPluginInstance, WindowSuspendChanged, "
+          "this = %p, aSuspend = %s\n", this, SuspendTypeToStr(aSuspend)));
+
   // It doesn't support suspended, so we just do something like mute/unmute.
   WindowVolumeChanged(1.0, /* useless */
                       aSuspend != nsISuspendedTypes::NONE_SUSPENDED);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsNPAPIPluginInstance::WindowAudioCaptureChanged(bool aCapture)