nsIAudioChannelAgent.idl 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  3. * You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. #include "nsISupports.idl"
  5. interface mozIDOMWindow;
  6. typedef uint32_t nsSuspendedTypes;
  7. [scriptable, builtinclass, uuid(2822a840-f009-11e5-a837-0800200c9a66)]
  8. interface nsISuspendedTypes : nsISupports
  9. {
  10. /**
  11. * The suspended enum is used in three different situations,
  12. * - platform audio focus (Fennec/B2G)
  13. * - remote media control (Fennec)
  14. * - block auto-play video in non-active page
  15. *
  16. * Note: the "remote side" must control the AudioChannelAgent using
  17. * nsIAudioChannelAgentCallback.windowSuspendChanged() callback instead using
  18. * play/pause methods or any button in the webpage.
  19. *
  20. * - SUSPENDED_PAUSE :
  21. * It's used when transiently losing audio focus, the media can't be resumed
  22. * until we gain the audio focus again. It would change the internal state of
  23. * MediaElement when it's being suspended/resumed, and it would trigger the
  24. * related JS event. eg. "play" and "pause" event.
  25. *
  26. * - SUSPENDED_BLOCK
  27. * It's used to prevent auto-playing media in inactive page in order to
  28. * reduce the power consumption, and the media can't be resumed until the
  29. * page becomes active again. It would change the internal state of
  30. * MediaElement when it's being blocked/resumed, so it won't trigger the
  31. * related JS event. eg. "play" and "pause" event.
  32. *
  33. * - SUSPENDED_PAUSE_DISPOSABLE
  34. * It's used for remote media-control to pause the playing media and when we
  35. * lose audio focus permanently. It's disposable suspended, so the media can
  36. * be resumed arbitrary after that. Same as SUSPENDED_PAUSE, it would change
  37. * the internal state of MediaElement when it's being suspended.
  38. *
  39. * - SUSPENDED_STOP_DISPOSABLE
  40. * It's used for remote media-control to stop the playing media. The remote
  41. * control would disappear after stopping the media, so we would disconnect
  42. * the audio channel agent. It's disposable suspended, so the media can be
  43. * resumed arbitrary after that. Same as SUSPENDED_PAUSE, it would change
  44. * the internal state of MediaElement when it's being suspended.
  45. */
  46. const uint32_t NONE_SUSPENDED = 0;
  47. const uint32_t SUSPENDED_PAUSE = 1;
  48. const uint32_t SUSPENDED_BLOCK = 2;
  49. const uint32_t SUSPENDED_PAUSE_DISPOSABLE = 3;
  50. const uint32_t SUSPENDED_STOP_DISPOSABLE = 4;
  51. };
  52. %{C++
  53. namespace mozilla {
  54. namespace dom {
  55. // It's defined in dom/audiochannel/AudioChannelService.h.
  56. class AudioPlaybackConfig;
  57. }
  58. }
  59. %}
  60. [ptr] native AudioPlaybackConfig(mozilla::dom::AudioPlaybackConfig);
  61. [uuid(15c05894-408e-4798-b527-a8c32d9c5f8c)]
  62. interface nsIAudioChannelAgentCallback : nsISupports
  63. {
  64. /**
  65. * Notified when the window volume/mute is changed
  66. */
  67. void windowVolumeChanged(in float aVolume, in bool aMuted);
  68. /**
  69. * Notified when the window needs to be suspended or resumed.
  70. */
  71. void windowSuspendChanged(in uint32_t aSuspend);
  72. /**
  73. * Notified when the capture state is changed.
  74. */
  75. void windowAudioCaptureChanged(in bool aCapture);
  76. };
  77. /**
  78. * This interface provides an agent for gecko components to participate
  79. * in the audio channel service. Gecko components are responsible for
  80. * 1. Indicating what channel type they are using (via the init() member
  81. * function).
  82. * 2. Notifying the agent when they start/stop using this channel.
  83. * 3. Notifying the agent when they are audible.
  84. *
  85. * The agent will invoke a callback to notify Gecko components of
  86. * 1. Changes to the playable status of this channel.
  87. */
  88. [uuid(ab7e21c0-970c-11e5-a837-0800200c9a66)]
  89. interface nsIAudioChannelAgent : nsISupports
  90. {
  91. const long AUDIO_AGENT_CHANNEL_NORMAL = 0;
  92. const long AUDIO_AGENT_CHANNEL_CONTENT = 1;
  93. const long AUDIO_AGENT_CHANNEL_NOTIFICATION = 2;
  94. const long AUDIO_AGENT_CHANNEL_ALARM = 3;
  95. const long AUDIO_AGENT_CHANNEL_TELEPHONY = 4;
  96. const long AUDIO_AGENT_CHANNEL_RINGER = 5;
  97. const long AUDIO_AGENT_CHANNEL_PUBLICNOTIFICATION = 6;
  98. const long AUDIO_AGENT_CHANNEL_SYSTEM = 7;
  99. const long AUDIO_AGENT_CHANNEL_ERROR = 1000;
  100. const long AUDIO_AGENT_STATE_NORMAL = 0;
  101. const long AUDIO_AGENT_STATE_MUTED = 1;
  102. const long AUDIO_AGENT_STATE_FADED = 2;
  103. /**
  104. * Before init() is called, this returns AUDIO_AGENT_CHANNEL_ERROR.
  105. */
  106. readonly attribute long audioChannelType;
  107. %{C++
  108. inline int32_t AudioChannelType() {
  109. int32_t channel;
  110. return NS_SUCCEEDED(GetAudioChannelType(&channel)) ? channel : AUDIO_AGENT_CHANNEL_ERROR;
  111. }
  112. %}
  113. /**
  114. * Initialize the agent with a channel type.
  115. * Note: This function should only be called once.
  116. *
  117. * @param window
  118. * The window
  119. * @param channelType
  120. * Audio Channel Type listed as above
  121. * @param callback
  122. * 1. Once the playable status changes, agent uses this callback function
  123. * to notify Gecko component.
  124. * 2. The callback is allowed to be null. Ex: telephony doesn't need to
  125. * listen change of the playable status.
  126. * 3. The AudioChannelAgent keeps a strong reference to the callback
  127. * object.
  128. */
  129. void init(in mozIDOMWindow window, in long channelType,
  130. in nsIAudioChannelAgentCallback callback);
  131. /**
  132. * This method is just like init(), except the audio channel agent keeps a
  133. * weak reference to the callback object.
  134. *
  135. * In order for this to work, |callback| must implement
  136. * nsISupportsWeakReference.
  137. */
  138. void initWithWeakCallback(in mozIDOMWindow window, in long channelType,
  139. in nsIAudioChannelAgentCallback callback);
  140. /**
  141. * Notify the agent that we want to start playing.
  142. * Note: Gecko component SHOULD call this function first then start to
  143. * play audio stream only when return value is true.
  144. *
  145. * @param config
  146. * It contains the playback related states (volume/mute/suspend)
  147. */
  148. void notifyStartedPlaying(in AudioPlaybackConfig config, in uint8_t audible);
  149. /**
  150. * Notify the agent we no longer want to play.
  151. *
  152. * Note : even if notifyStartedPlaying() returned false, the agent would
  153. * still be registered with the audio channel service and receive callbacks
  154. * for status changes. So notifyStoppedPlaying must still eventually be
  155. * called to unregister the agent with the channel service.
  156. */
  157. void notifyStoppedPlaying();
  158. /**
  159. * Notify agent that we already start producing audible data.
  160. *
  161. * Note : sometime audio might become silent during playing, this method is used to
  162. * notify the actually audible state to other services which want to know
  163. * about that, ex. tab sound indicator.
  164. */
  165. void notifyStartedAudible(in uint8_t audible, in uint32_t reason);
  166. };