summaryrefslogtreecommitdiffstats
path: root/dom/media/mediacontrol/AudioFocusManager.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/media/mediacontrol/AudioFocusManager.h
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/mediacontrol/AudioFocusManager.h')
-rw-r--r--dom/media/mediacontrol/AudioFocusManager.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/dom/media/mediacontrol/AudioFocusManager.h b/dom/media/mediacontrol/AudioFocusManager.h
new file mode 100644
index 0000000000..b6047444bb
--- /dev/null
+++ b/dom/media/mediacontrol/AudioFocusManager.h
@@ -0,0 +1,54 @@
+/* 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/. */
+
+#ifndef DOM_MEDIA_MEDIACONTROL_AUDIOFOCUSMANAGER_H_
+#define DOM_MEDIA_MEDIACONTROL_AUDIOFOCUSMANAGER_H_
+
+#include "base/basictypes.h"
+#include "nsTArray.h"
+#include "VideoUtils.h"
+
+namespace mozilla::dom {
+
+class IMediaController;
+class MediaControlService;
+
+/**
+ * AudioFocusManager is used to assign the audio focus to different requester
+ * and decide which requester can own audio focus when audio competing happens.
+ * When the audio competing happens, the last request would be a winner who can
+ * still own the audio focus, and all the other requesters would lose the audio
+ * focus. Now MediaController is the onlt requester, it would request the audio
+ * focus when it becomes audible and revoke the audio focus when the controller
+ * is no longer active.
+ */
+class AudioFocusManager {
+ public:
+ void RequestAudioFocus(IMediaController* aController);
+ void RevokeAudioFocus(IMediaController* aController);
+
+ explicit AudioFocusManager() = default;
+ ~AudioFocusManager();
+
+ uint32_t GetAudioFocusNums() const;
+
+ private:
+ friend class MediaControlService;
+ // Return true if we manage audio focus by clearing other controllers owning
+ // audio focus before assigning audio focus to the new controller.
+ bool ClearFocusControllersIfNeeded();
+
+ void CreateTimerForUpdatingTelemetry();
+ // This would check if user has managed audio focus by themselves and update
+ // the result to telemetry. This method should only be called from timer.
+ void UpdateTelemetryDataFromTimer(uint32_t aPrevFocusNum,
+ uint64_t aPrevActiveControllerNum);
+
+ nsTArray<RefPtr<IMediaController>> mOwningFocusControllers;
+ RefPtr<SimpleTimer> mTelemetryTimer;
+};
+
+} // namespace mozilla::dom
+
+#endif // DOM_MEDIA_MEDIACONTROL_AUDIOFOCUSMANAGER_H_