2019-08-07 04:46:08 +03:00
|
|
|
/* 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/. */
|
|
|
|
|
2019-10-30 02:08:05 +03:00
|
|
|
#ifndef DOM_MEDIA_MEDIACONTROL_AUDIOFOCUSMANAGER_H_
|
|
|
|
#define DOM_MEDIA_MEDIACONTROL_AUDIOFOCUSMANAGER_H_
|
2019-08-07 04:46:08 +03:00
|
|
|
|
|
|
|
#include "base/basictypes.h"
|
|
|
|
#include "nsTArray.h"
|
2020-12-24 05:42:56 +03:00
|
|
|
#include "VideoUtils.h"
|
2019-08-07 04:46:08 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
|
2020-05-14 01:08:01 +03:00
|
|
|
class IMediaController;
|
2019-08-07 04:46:08 +03:00
|
|
|
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:
|
2020-05-14 01:08:01 +03:00
|
|
|
void RequestAudioFocus(IMediaController* aController);
|
|
|
|
void RevokeAudioFocus(IMediaController* aController);
|
2019-08-07 04:46:08 +03:00
|
|
|
|
2020-01-16 02:26:29 +03:00
|
|
|
explicit AudioFocusManager() = default;
|
2020-12-24 05:42:56 +03:00
|
|
|
~AudioFocusManager();
|
2019-08-07 04:46:08 +03:00
|
|
|
|
|
|
|
uint32_t GetAudioFocusNums() const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
friend class MediaControlService;
|
2020-12-24 05:42:56 +03:00
|
|
|
// 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);
|
2019-08-07 04:46:08 +03:00
|
|
|
|
2020-05-14 01:08:01 +03:00
|
|
|
nsTArray<RefPtr<IMediaController>> mOwningFocusControllers;
|
2020-12-24 05:42:56 +03:00
|
|
|
RefPtr<SimpleTimer> mTelemetryTimer;
|
2019-08-07 04:46:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2019-10-30 02:08:05 +03:00
|
|
|
#endif // DOM_MEDIA_MEDIACONTROL_AUDIOFOCUSMANAGER_H_
|