Bug 1593131 - part1 : use media event to notity media controller amount changed. r=chunmin
authoralwu <alwu@mozilla.com>
Fri, 08 Nov 2019 22:09:23 +0000
changeset 502050 d168bfd2524c7c7c5110b7dcbca2f3671779c9ea
parent 502049 7a519aeac6438c53c2eec583b75a25f12dbf695c
child 502051 222533f6446ed6f8f544c6e25e10cf344557f62c
push id36805
push useraiakab@mozilla.com
push dateFri, 15 Nov 2019 09:53:19 +0000
treeherdermozilla-central@1e1617c67238 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschunmin
bugs1593131
milestone72.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 1593131 - part1 : use media event to notity media controller amount changed. r=chunmin As we have a need to know if there is any existing controller needs to be controlled in order to achieve dynamically creation and destruction of media keys event source. (that will be implemented in patch2) Therefore, using the media event to send the current media controller amount when the total media controller amount changed in the media service. Differential Revision: https://phabricator.services.mozilla.com/D51763
dom/media/mediacontrol/MediaControlService.cpp
dom/media/mediacontrol/MediaControlService.h
--- a/dom/media/mediacontrol/MediaControlService.cpp
+++ b/dom/media/mediacontrol/MediaControlService.cpp
@@ -106,28 +106,30 @@ void MediaControlService::AddMediaContro
   MOZ_DIAGNOSTIC_ASSERT(aController);
   const uint64_t cId = aController->Id();
   MOZ_DIAGNOSTIC_ASSERT(!mControllers.GetValue(cId),
                         "Controller has been added already!");
   mControllers.Put(cId, aController);
   mControllerHistory.AppendElement(cId);
   LOG("Add media controller %" PRId64 ", currentNum=%" PRId64, cId,
       GetControllersNum());
+  mMediaControllerAmountChangedEvent.Notify(GetControllersNum());
 }
 
 void MediaControlService::RemoveMediaController(
     const RefPtr<MediaController>& aController) {
   MOZ_DIAGNOSTIC_ASSERT(aController);
   const uint64_t cId = aController->Id();
   MOZ_DIAGNOSTIC_ASSERT(mControllers.GetValue(cId),
                         "Controller does not exist!");
   mControllers.Remove(cId);
   mControllerHistory.RemoveElement(cId);
   LOG("Remove media controller %" PRId64 ", currentNum=%" PRId64, cId,
       GetControllersNum());
+  mMediaControllerAmountChangedEvent.Notify(GetControllersNum());
 }
 
 void MediaControlService::PlayAllControllers() const {
   for (auto iter = mControllers.ConstIter(); !iter.Done(); iter.Next()) {
     const RefPtr<MediaController>& controller = iter.Data();
     controller->Play();
   }
 }
--- a/dom/media/mediacontrol/MediaControlService.h
+++ b/dom/media/mediacontrol/MediaControlService.h
@@ -5,16 +5,17 @@
 #ifndef DOM_MEDIA_MEDIACONTROL_MEDIACONTROLSERVICE_H_
 #define DOM_MEDIA_MEDIACONTROL_MEDIACONTROLSERVICE_H_
 
 #include "mozilla/AlreadyAddRefed.h"
 
 #include "AudioFocusManager.h"
 #include "MediaController.h"
 #include "MediaControlKeysManager.h"
+#include "MediaEventSource.h"
 #include "nsDataHashtable.h"
 #include "nsIObserver.h"
 #include "nsTArray.h"
 
 namespace mozilla {
 namespace dom {
 
 /**
@@ -43,30 +44,37 @@ class MediaControlService final : public
   }
 
   void AddMediaController(const RefPtr<MediaController>& aController);
   void RemoveMediaController(const RefPtr<MediaController>& aController);
   uint64_t GetControllersNum() const;
 
   already_AddRefed<MediaController> GetLastAddedController();
 
+  // This event is used to generate a media event indicating media controller
+  // amount changed.
+  MediaEventSource<uint64_t>& MediaControllerAmountChangedEvent() {
+    return mMediaControllerAmountChangedEvent;
+  }
+
  private:
   MediaControlService();
   ~MediaControlService();
 
   void Shutdown();
 
   void PlayAllControllers() const;
   void PauseAllControllers() const;
   void StopAllControllers() const;
   void ShutdownAllControllers() const;
 
   nsDataHashtable<nsUint64HashKey, RefPtr<MediaController>> mControllers;
   nsTArray<uint64_t> mControllerHistory;
   AudioFocusManager mAudioFocusManager;
   MediaControlKeysManager mMediaControlKeysManager;
   RefPtr<MediaControlKeysEventListener> mMediaKeysHandlder;
+  MediaEventProducer<uint64_t> mMediaControllerAmountChangedEvent;
 };
 
 }  // namespace dom
 }  // namespace mozilla
 
 #endif