Bug 1242874 - part1 : create suspened types draft
authorAlastor Wu <alwu@mozilla.com>
Tue, 03 May 2016 09:50:24 +0800
changeset 362705 4f516e86fd244aed7c3f8e9fee78e3202065523a
parent 358327 77cead2cd20300623eea2416bc9bce4d5021df09
child 362706 fd5c0a34a0d2e4c35a78abe5d2df0fc6ec7adb8d
push id17024
push useralwu@mozilla.com
push dateTue, 03 May 2016 01:54:01 +0000
bugs1242874
milestone49.0a1
Bug 1242874 - part1 : create suspened types MozReview-Commit-ID: FUAPZAdPVse
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/nsNPAPIPluginInstance.cpp
dom/telephony/Telephony.cpp
--- a/dom/audiochannel/nsIAudioChannelAgent.idl
+++ b/dom/audiochannel/nsIAudioChannelAgent.idl
@@ -1,24 +1,78 @@
 /* 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 "nsISupports.idl"
 
 interface mozIDOMWindow;
 
+typedef uint32_t nsSuspendedTypes;
+
+[scriptable, builtinclass, uuid(2822a840-f009-11e5-a837-0800200c9a66)]
+interface nsISuspendedTypes : nsISupports
+{
+  /**
+   * The suspended enum is used in three different situations,
+   * - platform audio focus (Fennec/B2G)
+   * - remote media control (Fennec)
+   * - block auto-play video in non-active page
+   *
+   * Note: the "remote side" must control the AudioChannelAgent using
+   * nsIAudioChannelAgentCallback.windowSuspendChanged() callback instead using
+   * play/pause methods or any button in the webpage.
+   *
+   * - SUSPENDED_PAUSE :
+   * It's used when transiently losing audio focus, the media can't be resumed
+   * until we gain the audio focus again. It would change the internal state of
+   * MediaElement when it's being suspended/resumed, and it would trigger the
+   * related JS event. eg. "play" and "pause" event.
+   *
+   * - SUSPENDED_BLOCK
+   * It's used to prevent auto-playing media in inactive page in order to
+   * reduce the power consumption, and the media can't be resumed until the
+   * page becomes active again. It would change the internal state of
+   * MediaElement when it's being blocked/resumed, so it won't trigger the
+   * related JS event. eg. "play" and "pause" event.
+   *
+   * - SUSPENDED_PAUSE_DISPOSABLE
+   * It's used for remote media-control to pause the playing media and when we
+   * lose audio focus permanently. It's disposable suspended, so the media can
+   * be resumed arbitrary after that. Same as SUSPENDED_PAUSE, it would change
+   * the internal state of MediaElement when it's being suspended.
+   *
+   * - SUSPENDED_STOP_DISPOSABLE
+   * It's used for remote media-control to stop the playing media. The remote
+   * control would disappear after stopping the media, so we would disconnect
+   * the audio channel agent. It's disposable suspended, so the media can be
+   * resumed arbitrary after that. Same as SUSPENDED_PAUSE, it would change
+   * the internal state of MediaElement when it's being suspended.
+   */
+
+  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;
+};
+
 [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);
 
+   /**
+   * Notified when the window needs to be suspended or resumed.
+   */
+  void windowSuspendChanged(in uint32_t aSuspend);
+
   /**
    * Notified when the capture state is changed.
    */
   void windowAudioCaptureChanged(in bool aCapture);
 };
 
 /**
  * This interface provides an agent for gecko components to participate
--- a/dom/fmradio/FMRadio.cpp
+++ b/dom/fmradio/FMRadio.cpp
@@ -464,16 +464,23 @@ NS_IMETHODIMP
 FMRadio::WindowVolumeChanged(float aVolume, bool aMuted)
 {
   IFMRadioService::Singleton()->EnableAudio(!aMuted);
   // TODO: what about the volume?
   return NS_OK;
 }
 
 NS_IMETHODIMP
+FMRadio::WindowSuspendChanged(nsSuspendedTypes aSuspend)
+{
+  // TODO : implementation.
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 FMRadio::WindowAudioCaptureChanged(bool aCapture)
 {
   return NS_OK;
 }
 
 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(FMRadio)
   NS_INTERFACE_MAP_ENTRY(nsISupportsWeakReference)
   NS_INTERFACE_MAP_ENTRY(nsIAudioChannelAgentCallback)
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -5129,16 +5129,23 @@ NS_IMETHODIMP HTMLMediaElement::WindowVo
 
   if (UseAudioChannelAPI()) {
     mPaused.SetCanPlay(!aMuted);
   }
 
   return NS_OK;
 }
 
+NS_IMETHODIMP
+HTMLMediaElement::WindowSuspendChanged(nsSuspendedTypes aSuspend)
+{
+  // TODO : implementation.
+  return NS_OK;
+}
+
 #ifdef MOZ_EME
 MediaKeys*
 HTMLMediaElement::GetMediaKeys() const
 {
   return mMediaKeys;
 }
 
 bool
--- a/dom/media/webaudio/AudioDestinationNode.cpp
+++ b/dom/media/webaudio/AudioDestinationNode.cpp
@@ -525,16 +525,23 @@ AudioDestinationNode::WindowVolumeChange
     }
   }
 
   SetCanPlay(aVolume, aMuted);
   return NS_OK;
 }
 
 NS_IMETHODIMP
+AudioDestinationNode::WindowSuspendChanged(nsSuspendedTypes aSuspend)
+{
+  // TODO : implementation.
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 AudioDestinationNode::WindowAudioCaptureChanged(bool aCapture)
 {
   MOZ_ASSERT(mAudioChannelAgent);
 
   if (!mStream || Context()->IsOffline()) {
     return NS_OK;
   }
 
--- a/dom/media/webspeech/synth/nsSpeechTask.cpp
+++ b/dom/media/webspeech/synth/nsSpeechTask.cpp
@@ -729,16 +729,23 @@ nsSpeechTask::DestroyAudioChannelAgent()
 NS_IMETHODIMP
 nsSpeechTask::WindowVolumeChanged(float aVolume, bool aMuted)
 {
   SetAudioOutputVolume(aMuted ? 0.0 : mVolume * aVolume);
   return NS_OK;
 }
 
 NS_IMETHODIMP
+nsSpeechTask::WindowSuspendChanged(nsSuspendedTypes aSuspend)
+{
+  // TODO : implementation.
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsSpeechTask::WindowAudioCaptureChanged(bool aCapture)
 {
   // This is not supported yet.
   return NS_OK;
 }
 
 void
 nsSpeechTask::SetAudioOutputVolume(float aVolume)
--- a/dom/plugins/base/nsNPAPIPluginInstance.cpp
+++ b/dom/plugins/base/nsNPAPIPluginInstance.cpp
@@ -1844,16 +1844,23 @@ nsNPAPIPluginInstance::WindowVolumeChang
 {
   // We just support mute/unmute
   nsresult rv = SetMuted(aMuted);
   NS_WARN_IF(NS_FAILED(rv));
   return rv;
 }
 
 NS_IMETHODIMP
+nsNPAPIPluginInstance::WindowSuspendChanged(nsSuspendedTypes aSuspend)
+{
+  // TODO : implementation.
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 nsNPAPIPluginInstance::WindowAudioCaptureChanged(bool aCapture)
 {
   return NS_OK;
 }
 
 nsresult
 nsNPAPIPluginInstance::SetMuted(bool aIsMuted)
 {
--- a/dom/telephony/Telephony.cpp
+++ b/dom/telephony/Telephony.cpp
@@ -714,16 +714,23 @@ Telephony::WindowVolumeChanged(float aVo
       mHaveDispatchedInterruptBeginEvent = mMuted;
     }
   }
 
   return NS_OK;
 }
 
 NS_IMETHODIMP
+Telephony::WindowSuspendChanged(nsSuspendedTypes aSuspend)
+{
+  // Not support yet.
+  return NS_OK;
+}
+
+NS_IMETHODIMP
 Telephony::WindowAudioCaptureChanged(bool aCapture)
 {
   // Do nothing, it's useless for the telephony object.
   return NS_OK;
 }
 
 // nsITelephonyListener