Backed out changeset df13b449ffcc (bug 1242874)
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Thu, 28 Apr 2016 13:59:02 +0200
changeset 750120 4a2138ef59b1e474c85a72dee793a65b0961243b
parent 750119 a9866d374ab8d8ae917b4671ffa513afdffd638c
child 750121 977dedde75b1f7cecdaddc44cba167aa2b09c354
push id121898
push useramarchesini@mozilla.com
push dateThu, 28 Apr 2016 15:12:15 +0000
treeherdertry@b58f6b4ed90b [default view] [failures only]
bugs1242874
milestone49.0a1
backs outdf13b449ffcc10111ca8984ff86946efee5988a7
Backed out changeset df13b449ffcc (bug 1242874)
dom/audiochannel/AudioChannelAgent.cpp
dom/audiochannel/nsIAudioChannelAgent.idl
dom/fmradio/FMRadio.cpp
dom/html/HTMLMediaElement.cpp
dom/media/webaudio/AudioDestinationNode.cpp
dom/media/webspeech/synth/nsSpeechTask.cpp
dom/plugins/base/nsNPAPIPlugin.cpp
dom/telephony/Telephony.cpp
--- a/dom/audiochannel/AudioChannelAgent.cpp
+++ b/dom/audiochannel/AudioChannelAgent.cpp
@@ -196,21 +196,27 @@ AudioChannelAgent::InitInternal(nsPIDOMW
   MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
          ("AudioChannelAgent, InitInternal, this = %p, type = %d, "
           "owner = %p, hasCallback = %d\n", this, mAudioChannelType,
           mWindow.get(), (!!mCallback || !!mWeakCallback)));
 
   return NS_OK;
 }
 
-NS_IMETHODIMP
-AudioChannelAgent::NotifyStartedPlaying(AudioPlaybackConfig* aConfig)
+NS_IMETHODIMP AudioChannelAgent::NotifyStartedPlaying(float *aVolume,
+                                                      bool* aMuted)
 {
-  if (NS_WARN_IF(!aConfig)) {
-    return NS_ERROR_FAILURE;
+  MOZ_ASSERT(aVolume);
+  MOZ_ASSERT(aMuted);
+
+  // Window-less AudioChannelAgents are muted by default.
+  if (!mWindow) {
+    *aVolume = 0;
+    *aMuted = true;
+    return NS_OK;
   }
 
   RefPtr<AudioChannelService> service = AudioChannelService::GetOrCreate();
   if (mAudioChannelType == AUDIO_AGENT_CHANNEL_ERROR ||
       service == nullptr || mIsRegToService) {
     return NS_ERROR_FAILURE;
   }
 
@@ -220,23 +226,24 @@ AudioChannelAgent::NotifyStartedPlaying(
   AudioPlaybackConfig config = service->GetMediaConfig(mWindow,
                                                        mAudioChannelType);
 
   MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
          ("AudioChannelAgent, NotifyStartedPlaying, this = %p, "
           "mute = %d, volume = %f, suspend = %d\n", this,
           config.mMuted, config.mVolume, config.mSuspend));
 
-  aConfig->SetConfig(config.mVolume, config.mMuted, config.mSuspend);
+  *aVolume = config.mVolume;
+  *aMuted = config.mMuted;
+
   mIsRegToService = true;
   return NS_OK;
 }
 
-NS_IMETHODIMP
-AudioChannelAgent::NotifyStoppedPlaying()
+NS_IMETHODIMP AudioChannelAgent::NotifyStoppedPlaying()
 {
   if (mAudioChannelType == AUDIO_AGENT_CHANNEL_ERROR ||
       !mIsRegToService) {
     return NS_ERROR_FAILURE;
   }
 
   MOZ_LOG(AudioChannelService::GetAudioChannelLog(), LogLevel::Debug,
          ("AudioChannelAgent, NotifyStoppedPlaying, this = %p\n", this));
--- a/dom/audiochannel/nsIAudioChannelAgent.idl
+++ b/dom/audiochannel/nsIAudioChannelAgent.idl
@@ -50,26 +50,16 @@ interface nsISuspendedTypes : nsISupport
 
   const uint32_t NONE_SUSPENDED             = 0;
   const uint32_t SUSPENDED_PAUSE            = 1;
   const uint32_t SUSPENDED_BLOCK            = 2;
   const uint32_t SUSPENDED_PAUSE_DISPOSABLE = 3;
   const uint32_t SUSPENDED_STOP_DISPOSABLE  = 4;
 };
 
-%{C++
-namespace mozilla {
-namespace dom {
-// It's defined in dom/audiochannel/AudioChannelService.h.
-class AudioPlaybackConfig;
-}
-}
-%}
-[ptr] native AudioPlaybackConfig(mozilla::dom::AudioPlaybackConfig);
-
 [uuid(15c05894-408e-4798-b527-a8c32d9c5f8c)]
 interface nsIAudioChannelAgentCallback : nsISupports
 {
   /**
    * Notified when the window volume/mute is changed
    */
   void windowVolumeChanged(in float aVolume, in bool aMuted);
 
@@ -157,20 +147,25 @@ interface nsIAudioChannelAgent : nsISupp
   void initWithWeakCallback(in mozIDOMWindow window, in long channelType,
                             in nsIAudioChannelAgentCallback callback);
 
   /**
    * Notify the agent that we want to start playing.
    * Note: Gecko component SHOULD call this function first then start to
    *          play audio stream only when return value is true.
    *
-   * @param config
-   *    It contains the playback related states (volume/mute/suspend)
+   * @return
+   *    normal state: the agent has registered with audio channel service and
+   *          the component should start playback.
+   *    muted state: the agent has registered with audio channel service but
+   *          the component should not start playback.
+   *    faded state: the agent has registered with audio channel service the
+   *          component should start playback as well as reducing the volume.
    */
-  void notifyStartedPlaying(in AudioPlaybackConfig config);
+  void notifyStartedPlaying(out float volume, out bool muted);
 
   /**
    * Notify the agent we no longer want to play.
    *
    * Note : even if notifyStartedPlaying() returned false, the agent would
    * still be registered with the audio channel service and receive callbacks
    * for status changes. So notifyStoppedPlaying must still eventually be
    * called to unregister the agent with the channel service.
--- a/dom/fmradio/FMRadio.cpp
+++ b/dom/fmradio/FMRadio.cpp
@@ -447,24 +447,20 @@ FMRadio::DisableRDS()
   return r.forget();
 }
 
 void
 FMRadio::EnableAudioChannelAgent()
 {
   NS_ENSURE_TRUE_VOID(mAudioChannelAgent);
 
-  AudioPlaybackConfig config;
-  nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return;
-  }
-
-  WindowVolumeChanged(config.mVolume, config.mMuted);
-  WindowSuspendChanged(config.mSuspend);
+  float volume = 0.0;
+  bool muted = true;
+  mAudioChannelAgent->NotifyStartedPlaying(&volume, &muted);
+  WindowVolumeChanged(volume, muted);
 
   mAudioChannelAgentEnabled = true;
 }
 
 NS_IMETHODIMP
 FMRadio::WindowVolumeChanged(float aVolume, bool aMuted)
 {
   // TODO : Not support to change volume now, so we just close it.
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -5056,24 +5056,20 @@ void
 HTMLMediaElement::NotifyAudioChannelAgent(bool aPlaying)
 {
   // This is needed to pass nsContentUtils::IsCallerChrome().
   // AudioChannel API should not called from content but it can happen that
   // this method has some content JS in its stack.
   AutoNoJSAPI nojsapi;
 
   if (aPlaying) {
-    AudioPlaybackConfig config;
-    nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return;
-    }
-
-    WindowVolumeChanged(config.mVolume, config.mMuted);
-    WindowSuspendChanged(config.mSuspend);
+    float volume = 0.0;
+    bool muted = true;
+    mAudioChannelAgent->NotifyStartedPlaying(&volume, &muted);
+    WindowVolumeChanged(volume, muted);
   } else {
     mAudioChannelAgent->NotifyStoppedPlaying();
     mAudioChannelAgent = nullptr;
   }
 }
 
 NS_IMETHODIMP
 HTMLMediaElement::WindowVolumeChanged(float aVolume, bool aMuted)
--- a/dom/media/webaudio/AudioDestinationNode.cpp
+++ b/dom/media/webaudio/AudioDestinationNode.cpp
@@ -729,20 +729,20 @@ AudioDestinationNode::InputMuted(bool aM
     CreateAudioChannelAgent();
   }
 
   if (aMuted) {
     mAudioChannelAgent->NotifyStoppedPlaying();
     return;
   }
 
-  AudioPlaybackConfig config;
-  nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config);
+  float volume = 0.0;
+  bool muted = true;
+  nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&volume, &muted);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 
-  WindowVolumeChanged(config.mVolume, config.mMuted);
-  WindowSuspendChanged(config.mSuspend);
+  WindowVolumeChanged(volume, muted);
 }
 
 } // namespace dom
 } // namespace mozilla
--- a/dom/media/webspeech/synth/nsSpeechTask.cpp
+++ b/dom/media/webspeech/synth/nsSpeechTask.cpp
@@ -707,25 +707,19 @@ nsSpeechTask::CreateAudioChannelAgent()
   if (mAudioChannelAgent) {
     mAudioChannelAgent->NotifyStoppedPlaying();
   }
 
   mAudioChannelAgent = new AudioChannelAgent();
   mAudioChannelAgent->InitWithWeakCallback(mUtterance->GetOwner(),
                                            static_cast<int32_t>(AudioChannelService::GetDefaultAudioChannel()),
                                            this);
-
-  AudioPlaybackConfig config;
-  nsresult rv = mAudioChannelAgent->NotifyStartedPlaying(&config);
-  if (NS_WARN_IF(NS_FAILED(rv))) {
-    return;
-  }
-
-  WindowVolumeChanged(config.mVolume, config.mMuted);
-  WindowSuspendChanged(config.mSuspend);
+  float volume = 0.0f;
+  bool muted = true;
+  mAudioChannelAgent->NotifyStartedPlaying(&volume, &muted);
 }
 
 void
 nsSpeechTask::DestroyAudioChannelAgent()
 {
   if (mAudioChannelAgent) {
     mAudioChannelAgent->NotifyStoppedPlaying();
     mAudioChannelAgent = nullptr;
@@ -737,21 +731,19 @@ nsSpeechTask::WindowVolumeChanged(float 
 {
   SetAudioOutputVolume(aMuted ? 0.0 : mVolume * aVolume);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSpeechTask::WindowSuspendChanged(nsSuspendedTypes aSuspend)
 {
-  if (aSuspend == nsISuspendedTypes::NONE_SUSPENDED &&
-      mUtterance->mPaused) {
+  if (aSuspend == nsISuspendedTypes::NONE_SUSPENDED) {
     Resume();
-  } else if (aSuspend != nsISuspendedTypes::NONE_SUSPENDED &&
-             !mUtterance->mPaused) {
+  } else {
     Pause();
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsSpeechTask::WindowAudioCaptureChanged(bool aCapture)
 {
--- a/dom/plugins/base/nsNPAPIPlugin.cpp
+++ b/dom/plugins/base/nsNPAPIPlugin.cpp
@@ -102,17 +102,16 @@ using mozilla::plugins::PluginModuleCont
 #include "android_npapi.h"
 #include "ANPBase.h"
 #include "AndroidBridge.h"
 #undef LOG
 #define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "GeckoPlugins" , ## args)
 #endif
 
 #include "nsIAudioChannelAgent.h"
-#include "AudioChannelService.h"
 
 using namespace mozilla;
 using namespace mozilla::plugins::parent;
 
 // We should make this const...
 static NPNetscapeFuncs sBrowserFuncs = {
   sizeof(sBrowserFuncs),
   (NP_VERSION_MAJOR << 8) + NP_VERSION_MINOR,
@@ -2285,29 +2284,24 @@ NPError
       MOZ_ASSERT(agent);
 
       if (isMuted) {
         rv = agent->NotifyStoppedPlaying();
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return NPERR_NO_ERROR;
         }
       } else {
-
-        dom::AudioPlaybackConfig config;
-        rv = agent->NotifyStartedPlaying(&config);
+        float volume = 0.0;
+        bool muted = true;
+        rv = agent->NotifyStartedPlaying(&volume, &muted);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return NPERR_NO_ERROR;
         }
 
-        rv = inst->WindowVolumeChanged(config.mVolume, config.mMuted);
-        if (NS_WARN_IF(NS_FAILED(rv))) {
-          return NPERR_NO_ERROR;
-        }
-
-        rv = inst->WindowSuspendChanged(config.mSuspend);
+        rv = inst->WindowVolumeChanged(volume, muted);
         if (NS_WARN_IF(NS_FAILED(rv))) {
           return NPERR_NO_ERROR;
         }
       }
 
       return NPERR_NO_ERROR;
     }
 
--- a/dom/telephony/Telephony.cpp
+++ b/dom/telephony/Telephony.cpp
@@ -556,37 +556,35 @@ Telephony::HandleAudioAgentState()
     mIsAudioStartPlaying = false;
     rv = mAudioAgent->NotifyStoppedPlaying();
     mAudioAgent = nullptr;
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   } else if (!activeCall.IsNull() && !mIsAudioStartPlaying) {
     mIsAudioStartPlaying = true;
-    AudioPlaybackConfig config;
-    rv = mAudioAgent->NotifyStartedPlaying(&config);
+    float volume;
+    bool muted;
+    rv = mAudioAgent->NotifyStartedPlaying(&volume, &muted);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
 
     // In B2G, the system app manages audio playback policy. If there is a new
     // sound want to be playback, it must wait for the permission from the
     // system app. It means that the sound would be muted first, and then be
     // unmuted. For telephony, the behaviors are hold() first, then resume().
     // However, the telephony service can't handle all these requests within a
     // short period. The telephony service would reject our resume request,
     // because the modem have not changed the call state yet. It causes that
     // the telephony can't be resumed. Therefore, we don't mute the telephony
     // at the beginning.
-    rv = WindowVolumeChanged(1.0, false);
-    if (NS_WARN_IF(NS_FAILED(rv))) {
-      return rv;
-    }
-
-    rv = WindowSuspendChanged(config.mSuspend);
+    volume = 1.0;
+    muted = false;
+    rv = WindowVolumeChanged(volume, muted);
     if (NS_WARN_IF(NS_FAILED(rv))) {
       return rv;
     }
   }
   return NS_OK;
 }
 
 bool