diff --git a/dom/media/MediaManager.cpp b/dom/media/MediaManager.cpp index 4fecf89fdc5b..d4e47f084c0c 100644 --- a/dom/media/MediaManager.cpp +++ b/dom/media/MediaManager.cpp @@ -2176,7 +2176,7 @@ int MediaManager::AddDeviceChangeCallback(DeviceChangeCallback* aCallback) { manager->GetBackend()->SetFakeDeviceChangeEvents(); })); - return DeviceChangeCallback::AddDeviceChangeCallback(aCallback); + return DeviceChangeNotifier::AddDeviceChangeCallback(aCallback); } void MediaManager::OnDeviceChange() { @@ -2186,7 +2186,7 @@ void MediaManager::OnDeviceChange() { if (sHasShutdown) { return; } - self->DeviceChangeCallback::OnDeviceChange(); + self->NotifyDeviceChange(); // On some Windows machine, if we call EnumerateRawDevices immediately // after receiving devicechange event, sometimes we would get outdated @@ -3410,7 +3410,7 @@ void MediaManager::RemoveMediaDevicesCallback(uint64_t aWindowID) { nsPIDOMWindowInner* window = mediadevices->GetOwner(); MOZ_ASSERT(window); if (window && window->WindowID() == aWindowID) { - DeviceChangeCallback::RemoveDeviceChangeCallbackLocked(observer); + RemoveDeviceChangeCallbackLocked(observer); return; } } diff --git a/dom/media/MediaManager.h b/dom/media/MediaManager.h index 2fc5166a3baf..96bb65715497 100644 --- a/dom/media/MediaManager.h +++ b/dom/media/MediaManager.h @@ -132,6 +132,7 @@ typedef MozPromise, nsresult, true> SinkInfoPromise; class MediaManager final : public nsIMediaManagerService, public nsIObserver, + public DeviceChangeNotifier, public DeviceChangeCallback { friend SourceListener; diff --git a/dom/media/systemservices/CamerasChild.cpp b/dom/media/systemservices/CamerasChild.cpp index 605a16a315e3..2eec21375e4a 100644 --- a/dom/media/systemservices/CamerasChild.cpp +++ b/dom/media/systemservices/CamerasChild.cpp @@ -52,7 +52,7 @@ class FakeOnDeviceChangeEventRunnable : public Runnable { CamerasChild* child = CamerasSingleton::Child(); if (child) { - child->OnDeviceChange(); + child->NotifyDeviceChange(); if (mCounter++ < FAKE_ONDEVICECHANGE_EVENT_REPEAT_COUNT) { RefPtr evt = @@ -154,7 +154,7 @@ int CamerasChild::AddDeviceChangeCallback(DeviceChangeCallback* aCallback) { // So here we setup camera engine via EnsureInitialized(aCapEngine) EnsureInitialized(CameraEngine); - return DeviceChangeCallback::AddDeviceChangeCallback(aCallback); + return DeviceChangeNotifier::AddDeviceChangeCallback(aCallback); } mozilla::ipc::IPCResult CamerasChild::RecvReplyFailure(void) { @@ -580,7 +580,7 @@ mozilla::ipc::IPCResult CamerasChild::RecvDeliverFrame( } mozilla::ipc::IPCResult CamerasChild::RecvDeviceChange() { - this->OnDeviceChange(); + this->NotifyDeviceChange(); return IPC_OK(); } diff --git a/dom/media/systemservices/CamerasChild.h b/dom/media/systemservices/CamerasChild.h index 5c6bac19a3b2..39309c3e7b50 100644 --- a/dom/media/systemservices/CamerasChild.h +++ b/dom/media/systemservices/CamerasChild.h @@ -143,7 +143,7 @@ int GetChildAndCall(MEM_FUN&& f, ARGS&&... args) { } } -class CamerasChild final : public PCamerasChild, public DeviceChangeCallback { +class CamerasChild final : public PCamerasChild, public DeviceChangeNotifier { friend class mozilla::ipc::BackgroundChildImpl; template friend class mozilla::camera::LockAndDispatch; diff --git a/dom/media/systemservices/DeviceChangeCallback.h b/dom/media/systemservices/DeviceChangeCallback.h index b249174b5f35..653deb2d88e6 100644 --- a/dom/media/systemservices/DeviceChangeCallback.h +++ b/dom/media/systemservices/DeviceChangeCallback.h @@ -13,7 +13,17 @@ namespace mozilla { class DeviceChangeCallback { public: - virtual void OnDeviceChange() { + virtual ~DeviceChangeCallback() = default; + virtual void OnDeviceChange() = 0; +}; + +class DeviceChangeNotifier { + public: + DeviceChangeNotifier() + : mCallbackMutex("mozilla::DeviceChangeCallback::mCallbackMutex") { + } + + void NotifyDeviceChange() { MutexAutoLock lock(mCallbackMutex); for (DeviceChangeCallback* observer : mDeviceChangeCallbackList) { observer->OnDeviceChange(); @@ -28,12 +38,12 @@ class DeviceChangeCallback { return 0; } - virtual int RemoveDeviceChangeCallback(DeviceChangeCallback* aCallback) { + int RemoveDeviceChangeCallback(DeviceChangeCallback* aCallback) { MutexAutoLock lock(mCallbackMutex); return RemoveDeviceChangeCallbackLocked(aCallback); } - virtual int RemoveDeviceChangeCallbackLocked( + int RemoveDeviceChangeCallbackLocked( DeviceChangeCallback* aCallback) { mCallbackMutex.AssertCurrentThreadOwns(); if (mDeviceChangeCallbackList.IndexOf(aCallback) != @@ -42,11 +52,7 @@ class DeviceChangeCallback { return 0; } - DeviceChangeCallback() - : mCallbackMutex("mozilla::media::DeviceChangeCallback::mCallbackMutex") { - } - - virtual ~DeviceChangeCallback() {} + virtual ~DeviceChangeNotifier() = default; protected: nsTArray mDeviceChangeCallbackList; diff --git a/dom/media/webrtc/MediaEngine.h b/dom/media/webrtc/MediaEngine.h index 7b37a1e40921..e6a3e14ed3c2 100644 --- a/dom/media/webrtc/MediaEngine.h +++ b/dom/media/webrtc/MediaEngine.h @@ -30,7 +30,8 @@ enum MediaSinkEnum { enum { kVideoTrack = 1, kAudioTrack = 2, kTrackCount }; -class MediaEngine : public DeviceChangeCallback { +class MediaEngine : public DeviceChangeNotifier, + public DeviceChangeCallback { public: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(MediaEngine) NS_DECL_OWNINGTHREAD @@ -49,6 +50,8 @@ class MediaEngine : public DeviceChangeCallback { virtual void SetFakeDeviceChangeEvents() {} + void OnDeviceChange() override { NotifyDeviceChange(); } + protected: virtual ~MediaEngine() = default; };