mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-01 00:32:11 +00:00
Bug 1689516 - Remove AudioNotification{Sender, Receiver}. r=chunmin
Differential Revision: https://phabricator.services.mozilla.com/D103430
This commit is contained in:
parent
ffa59b72d4
commit
3a6e3014e5
@ -225,7 +225,6 @@
|
||||
# include <process.h>
|
||||
# define getpid _getpid
|
||||
# include "mozilla/WinDllServices.h"
|
||||
# include "mozilla/audio/AudioNotificationReceiver.h"
|
||||
# include "mozilla/widget/AudioSession.h"
|
||||
# include "mozilla/widget/WinContentSystemParameters.h"
|
||||
#endif
|
||||
@ -1556,13 +1555,6 @@ mozilla::ipc::IPCResult ContentChild::RecvReinitRendering(
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult ContentChild::RecvAudioDefaultDeviceChange() {
|
||||
#ifdef XP_WIN
|
||||
audio::AudioNotificationReceiver::NotifyDefaultDeviceChanged();
|
||||
#endif
|
||||
return IPC_OK();
|
||||
}
|
||||
|
||||
mozilla::ipc::IPCResult ContentChild::RecvReinitRenderingForDeviceReset() {
|
||||
gfxPlatform::GetPlatform()->CompositorUpdated();
|
||||
|
||||
|
@ -189,8 +189,6 @@ class ContentChild final : public PContentChild,
|
||||
Endpoint<PRemoteDecoderManagerChild>&& aVideoManager,
|
||||
nsTArray<uint32_t>&& namespaces);
|
||||
|
||||
mozilla::ipc::IPCResult RecvAudioDefaultDeviceChange();
|
||||
|
||||
mozilla::ipc::IPCResult RecvReinitRenderingForDeviceReset();
|
||||
|
||||
mozilla::ipc::IPCResult RecvSetProcessSandbox(
|
||||
|
@ -298,7 +298,6 @@
|
||||
#endif
|
||||
|
||||
#ifdef XP_WIN
|
||||
# include "mozilla/audio/AudioNotificationSender.h"
|
||||
# include "mozilla/widget/AudioSession.h"
|
||||
# include "mozilla/widget/WinContentSystemParameters.h"
|
||||
# include "mozilla/WinDllServices.h"
|
||||
@ -2769,9 +2768,6 @@ ContentParent::ContentParent(const nsACString& aRemoteType, int32_t aJSPluginID)
|
||||
mMessageManager = nsFrameMessageManager::NewProcessMessageManager(true);
|
||||
|
||||
#if defined(XP_WIN)
|
||||
if (XRE_IsParentProcess()) {
|
||||
audio::AudioNotificationSender::Init();
|
||||
}
|
||||
// Request Windows message deferral behavior on our side of the PContent
|
||||
// channel. Generally only applies to the situation where we get caught in
|
||||
// a deadlock with the plugin process when sending CPOWs.
|
||||
|
@ -516,8 +516,6 @@ child:
|
||||
Endpoint<PRemoteDecoderManagerChild> video,
|
||||
uint32_t[] namespaces);
|
||||
|
||||
async AudioDefaultDeviceChange();
|
||||
|
||||
async NetworkLinkTypeChange(uint32_t type);
|
||||
|
||||
// Re-create the rendering stack for a device reset.
|
||||
|
@ -1,88 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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/. */
|
||||
|
||||
#include "AudioNotificationReceiver.h"
|
||||
#include "mozilla/Logging.h" // for LazyLogModule
|
||||
#include "mozilla/StaticMutex.h" // for StaticMutex
|
||||
#include "mozilla/StaticPtr.h" // for StaticAutoPtr
|
||||
#include "nsAppRunner.h" // for XRE_IsContentProcess
|
||||
#include "nsTArray.h" // for nsTArray
|
||||
|
||||
static mozilla::LazyLogModule sLogger("AudioNotificationReceiver");
|
||||
|
||||
#undef ANR_LOG
|
||||
#define ANR_LOG(...) MOZ_LOG(sLogger, mozilla::LogLevel::Debug, (__VA_ARGS__))
|
||||
#undef ANR_LOGW
|
||||
#define ANR_LOGW(...) \
|
||||
MOZ_LOG(sLogger, mozilla::LogLevel::Warning, (__VA_ARGS__))
|
||||
|
||||
namespace mozilla {
|
||||
namespace audio {
|
||||
|
||||
/*
|
||||
* A list containing all clients subscribering the device-changed notifications.
|
||||
*/
|
||||
static StaticAutoPtr<nsTArray<DeviceChangeListener*>> sSubscribers;
|
||||
static StaticMutex sMutex;
|
||||
|
||||
/*
|
||||
* AudioNotificationReceiver Implementation
|
||||
*/
|
||||
/* static */
|
||||
void AudioNotificationReceiver::Register(
|
||||
DeviceChangeListener* aDeviceChangeListener) {
|
||||
MOZ_ASSERT(XRE_IsContentProcess());
|
||||
|
||||
StaticMutexAutoLock lock(sMutex);
|
||||
if (!sSubscribers) {
|
||||
sSubscribers = new nsTArray<DeviceChangeListener*>();
|
||||
}
|
||||
sSubscribers->AppendElement(aDeviceChangeListener);
|
||||
|
||||
ANR_LOG("The DeviceChangeListener: %p is registered successfully.",
|
||||
aDeviceChangeListener);
|
||||
}
|
||||
|
||||
/* static */
|
||||
void AudioNotificationReceiver::Unregister(
|
||||
DeviceChangeListener* aDeviceChangeListener) {
|
||||
MOZ_ASSERT(XRE_IsContentProcess());
|
||||
|
||||
StaticMutexAutoLock lock(sMutex);
|
||||
MOZ_ASSERT(!sSubscribers->IsEmpty(), "No subscriber.");
|
||||
|
||||
sSubscribers->RemoveElement(aDeviceChangeListener);
|
||||
if (sSubscribers->IsEmpty()) {
|
||||
// Clear the static pointer here to prevent memory leak.
|
||||
sSubscribers = nullptr;
|
||||
}
|
||||
|
||||
ANR_LOG("The DeviceChangeListener: %p is unregistered successfully.",
|
||||
aDeviceChangeListener);
|
||||
}
|
||||
|
||||
/* static */
|
||||
void AudioNotificationReceiver::NotifyDefaultDeviceChanged() {
|
||||
MOZ_ASSERT(XRE_IsContentProcess());
|
||||
|
||||
StaticMutexAutoLock lock(sMutex);
|
||||
|
||||
// Do nothing when there is no DeviceChangeListener.
|
||||
if (!sSubscribers) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (DeviceChangeListener* stream : *sSubscribers) {
|
||||
ANR_LOG(
|
||||
"Notify the DeviceChangeListener: %p "
|
||||
"that the default device has been changed.",
|
||||
stream);
|
||||
stream->ResetDefaultDevice();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace audio
|
||||
} // namespace mozilla
|
@ -1,97 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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 MOZILLA_AUDIONOTIFICATIONRECEIVER_H_
|
||||
#define MOZILLA_AUDIONOTIFICATIONRECEIVER_H_
|
||||
|
||||
// clang-format off
|
||||
/*
|
||||
* Architecture to send/receive default device-changed notification:
|
||||
*
|
||||
* Chrome Process ContentProcess 1
|
||||
* ------------------ ------------------
|
||||
*
|
||||
* AudioNotification DeviceChangeListener 1 DeviceChangeListener N
|
||||
* | ^ | ^ ^
|
||||
* (4)| |(2) |(3) |(8) .
|
||||
* v | v | v
|
||||
* AudioNotificationSender AudioNotificationReceiver
|
||||
* ^ | ^ ^
|
||||
* . (5)| |(1) |(7)
|
||||
* . v | |
|
||||
* . (P)ContentParent 1 (P)ContentChild 1
|
||||
* . | ^
|
||||
* . (6)| |
|
||||
* . | |
|
||||
* . | |
|
||||
* . +------------------------------------+
|
||||
* . PContent IPC
|
||||
* .
|
||||
* . Content Process M
|
||||
* . ------------------
|
||||
* . .
|
||||
* v .
|
||||
* (P)ContentParent M < . . . . . . . . . > (P)ContentChild M
|
||||
* PContent IPC
|
||||
*
|
||||
* Steps
|
||||
* --------
|
||||
* 1) Initailize the AudioNotificationSender when ContentParent is created.
|
||||
* 2) Create an AudioNotification to get the device-changed signal
|
||||
* from the system.
|
||||
* 3) Register the DeviceChangeListener to AudioNotificationReceiver when it's
|
||||
* created. 4) When the default device is changed, AudioNotification get the
|
||||
* signal and 5) Pass this message by AudioNotificationSender. 6) The
|
||||
* AudioNotificationSender sends the device-changed notification via the
|
||||
* PContent. 7) The ContentChild will call AudioNotificationReceiver to 8)
|
||||
* Notify all the registered audio streams to reconfigure the output devices.
|
||||
*
|
||||
* Notes
|
||||
* --------
|
||||
* a) There is only one AudioNotificationSender and AudioNotification
|
||||
* in a chrome process.
|
||||
* b) There is only one AudioNotificationReceiver and might be many
|
||||
* DeviceChangeListeners in a content process.
|
||||
* c) There might be many ContentParent in a chrome process.
|
||||
* d) There is only one ContentChild in a content process.
|
||||
* e) All the DeviceChangeListeners are registered in the
|
||||
* AudioNotificationReceiver. f) All the ContentParents are registered in the
|
||||
* AudioNotificationSender.
|
||||
*/
|
||||
// clang-format on
|
||||
|
||||
namespace mozilla {
|
||||
namespace audio {
|
||||
|
||||
// The base class that provides a ResetDefaultDevice interface that
|
||||
// will be called in AudioNotificationReceiver::NotifyDefaultDeviceChanged
|
||||
// when it receives device-changed notification from the chrome process.
|
||||
class DeviceChangeListener {
|
||||
protected:
|
||||
virtual ~DeviceChangeListener(){};
|
||||
|
||||
public:
|
||||
// The subclass shoule provide its own implementation switching the
|
||||
// audio stream to the new default output device.
|
||||
virtual void ResetDefaultDevice() = 0;
|
||||
};
|
||||
|
||||
class AudioNotificationReceiver final {
|
||||
public:
|
||||
// Add the DeviceChangeListener into the subscribers list.
|
||||
static void Register(DeviceChangeListener* aDeviceChangeListener);
|
||||
|
||||
// Remove the DeviceChangeListener from the subscribers list.
|
||||
static void Unregister(DeviceChangeListener* aDeviceChangeListener);
|
||||
|
||||
// Notify all the streams that the default device has been changed.
|
||||
static void NotifyDefaultDeviceChanged();
|
||||
}; // AudioNotificationReceiver
|
||||
|
||||
} // namespace audio
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // MOZILLA_AUDIONOTIFICATIONRECEIVER_H_
|
@ -1,211 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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/. */
|
||||
|
||||
#include "AudioNotificationSender.h"
|
||||
#include "mozilla/ClearOnShutdown.h" // for ClearOnShutdown
|
||||
#include "mozilla/dom/ContentParent.h" // for ContentParent
|
||||
#include "mozilla/Logging.h" // for LazyLogModule
|
||||
#include "mozilla/RefPtr.h" // for RefPtr
|
||||
#include "mozilla/StaticPtr.h" // for StaticAutoPtr
|
||||
#include "nsAppRunner.h" // for XRE_IsParentProcess
|
||||
#include "nsTArray.h" // for nsTArray
|
||||
#include <mmdeviceapi.h> // for IMMNotificationClient interface
|
||||
|
||||
static mozilla::LazyLogModule sLogger("AudioNotificationSender");
|
||||
|
||||
#undef ANS_LOG
|
||||
#define ANS_LOG(...) MOZ_LOG(sLogger, mozilla::LogLevel::Debug, (__VA_ARGS__))
|
||||
#undef ANS_LOGW
|
||||
#define ANS_LOGW(...) \
|
||||
MOZ_LOG(sLogger, mozilla::LogLevel::Warning, (__VA_ARGS__))
|
||||
|
||||
namespace mozilla {
|
||||
namespace audio {
|
||||
|
||||
/*
|
||||
* A runnable task to notify the audio device-changed event.
|
||||
*/
|
||||
class AudioDeviceChangedRunnable final : public Runnable {
|
||||
public:
|
||||
explicit AudioDeviceChangedRunnable()
|
||||
: Runnable("AudioDeviceChangedRunnable") {}
|
||||
|
||||
NS_IMETHOD Run() override {
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
nsTArray<dom::ContentParent*> parents;
|
||||
dom::ContentParent::GetAll(parents);
|
||||
for (dom::ContentParent* p : parents) {
|
||||
Unused << p->SendAudioDefaultDeviceChange();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
}; // class AudioDeviceChangedRunnable
|
||||
|
||||
/*
|
||||
* An observer for receiving audio device events from Windows.
|
||||
*/
|
||||
typedef void (*DefaultDeviceChangedCallback)();
|
||||
class AudioNotification final : public IMMNotificationClient {
|
||||
public:
|
||||
explicit AudioNotification(DefaultDeviceChangedCallback aCallback)
|
||||
: mCallback(aCallback), mRefCt(0), mIsRegistered(false) {
|
||||
MOZ_COUNT_CTOR(AudioNotification);
|
||||
MOZ_ASSERT(mCallback);
|
||||
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
|
||||
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
|
||||
HRESULT hr = CoCreateInstance(CLSID_MMDeviceEnumerator, nullptr,
|
||||
CLSCTX_INPROC_SERVER, IID_IMMDeviceEnumerator,
|
||||
getter_AddRefs(mDeviceEnumerator));
|
||||
|
||||
if (FAILED(hr)) {
|
||||
ANS_LOGW("Cannot create an IMMDeviceEnumerator instance.");
|
||||
return;
|
||||
}
|
||||
|
||||
hr = mDeviceEnumerator->RegisterEndpointNotificationCallback(this);
|
||||
if (FAILED(hr)) {
|
||||
ANS_LOGW("Cannot register notification callback.");
|
||||
return;
|
||||
}
|
||||
|
||||
ANS_LOG("Register notification callback successfully.");
|
||||
mIsRegistered = true;
|
||||
}
|
||||
|
||||
~AudioNotification() {
|
||||
MOZ_COUNT_DTOR(AudioNotification);
|
||||
// Assert mIsRegistered is true when we have mDeviceEnumerator.
|
||||
// Don't care mIsRegistered if there is no mDeviceEnumerator.
|
||||
MOZ_ASSERT(!mDeviceEnumerator || mIsRegistered);
|
||||
if (!mDeviceEnumerator) {
|
||||
ANS_LOG("No device enumerator in use.");
|
||||
return;
|
||||
}
|
||||
|
||||
HRESULT hr =
|
||||
mDeviceEnumerator->UnregisterEndpointNotificationCallback(this);
|
||||
if (FAILED(hr)) {
|
||||
// We can't really do anything here, so we just add a log for debugging.
|
||||
ANS_LOGW("Unregister notification failed.");
|
||||
} else {
|
||||
ANS_LOG("Unregister notification callback successfully.");
|
||||
}
|
||||
|
||||
mIsRegistered = false;
|
||||
}
|
||||
|
||||
// True whenever the notification server is set to report events to this
|
||||
// object.
|
||||
bool IsRegistered() const { return mIsRegistered; }
|
||||
|
||||
// IMMNotificationClient Implementation
|
||||
HRESULT STDMETHODCALLTYPE OnDefaultDeviceChanged(EDataFlow aFlow, ERole aRole,
|
||||
LPCWSTR aDeviceId) override {
|
||||
ANS_LOG("Default device has changed: flow %d, role: %d\n", aFlow, aRole);
|
||||
mCallback();
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// The remaining methods are not implemented. they simply log when called
|
||||
// (if log is enabled), for debugging.
|
||||
HRESULT STDMETHODCALLTYPE OnDeviceAdded(LPCWSTR aDeviceId) override {
|
||||
ANS_LOG("Audio device added.");
|
||||
return S_OK;
|
||||
};
|
||||
|
||||
HRESULT STDMETHODCALLTYPE OnDeviceRemoved(LPCWSTR aDeviceId) override {
|
||||
ANS_LOG("Audio device removed.");
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE OnDeviceStateChanged(LPCWSTR aDeviceId,
|
||||
DWORD aNewState) override {
|
||||
ANS_LOG("Audio device state changed.");
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE
|
||||
OnPropertyValueChanged(LPCWSTR aDeviceId, const PROPERTYKEY aKey) override {
|
||||
ANS_LOG("Audio device property value changed.");
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
// IUnknown Implementation
|
||||
ULONG STDMETHODCALLTYPE AddRef() override {
|
||||
return InterlockedIncrement(&mRefCt);
|
||||
}
|
||||
|
||||
ULONG STDMETHODCALLTYPE Release() override {
|
||||
ULONG ulRef = InterlockedDecrement(&mRefCt);
|
||||
if (0 == ulRef) {
|
||||
delete this;
|
||||
}
|
||||
return ulRef;
|
||||
}
|
||||
|
||||
HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid,
|
||||
VOID** ppvInterface) override {
|
||||
if (__uuidof(IUnknown) == riid) {
|
||||
AddRef();
|
||||
*ppvInterface = static_cast<IUnknown*>(this);
|
||||
} else if (__uuidof(IMMNotificationClient) == riid) {
|
||||
AddRef();
|
||||
*ppvInterface = static_cast<IMMNotificationClient*>(this);
|
||||
} else {
|
||||
*ppvInterface = NULL;
|
||||
return E_NOINTERFACE;
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
private:
|
||||
RefPtr<IMMDeviceEnumerator> mDeviceEnumerator;
|
||||
DefaultDeviceChangedCallback mCallback;
|
||||
LONG mRefCt;
|
||||
bool mIsRegistered;
|
||||
}; // class AudioNotification
|
||||
|
||||
/*
|
||||
* A singleton observer for audio device changed events.
|
||||
*/
|
||||
static StaticAutoPtr<AudioNotification> sAudioNotification;
|
||||
|
||||
/*
|
||||
* AudioNotificationSender Implementation
|
||||
*/
|
||||
/* static */
|
||||
nsresult AudioNotificationSender::Init() {
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
|
||||
if (!sAudioNotification) {
|
||||
sAudioNotification = new AudioNotification(NotifyDefaultDeviceChanged);
|
||||
ClearOnShutdown(&sAudioNotification);
|
||||
|
||||
if (!sAudioNotification->IsRegistered()) {
|
||||
ANS_LOGW("The notification sender cannot be initialized.");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
ANS_LOG("The notification sender is initailized successfully.");
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* static */
|
||||
void AudioNotificationSender::NotifyDefaultDeviceChanged() {
|
||||
// This is running on the callback thread (from OnDefaultDeviceChanged).
|
||||
MOZ_ASSERT(XRE_IsParentProcess());
|
||||
ANS_LOG("Notify the default device-changed event.");
|
||||
|
||||
RefPtr<AudioDeviceChangedRunnable> runnable =
|
||||
new AudioDeviceChangedRunnable();
|
||||
NS_DispatchToMainThread(runnable);
|
||||
}
|
||||
|
||||
} // namespace audio
|
||||
} // namespace mozilla
|
@ -1,30 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* 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 MOZILLA_AUDIONOTIFICATIONSENDER_H_
|
||||
#define MOZILLA_AUDIONOTIFICATIONSENDER_H_
|
||||
|
||||
#include "nsError.h" // for nsresult
|
||||
|
||||
namespace mozilla {
|
||||
namespace audio {
|
||||
|
||||
// Please see the architecture figure in AudioNotificationReceiver.h.
|
||||
class AudioNotificationSender final {
|
||||
public:
|
||||
// Register the AudioNotification to get the device-changed event.
|
||||
static nsresult Init();
|
||||
|
||||
private:
|
||||
// Send the device-changed notification from the chrome processes
|
||||
// to the content processes.
|
||||
static void NotifyDefaultDeviceChanged();
|
||||
}; // AudioNotificationSender
|
||||
|
||||
} // namespace audio
|
||||
} // namespace mozilla
|
||||
|
||||
#endif // MOZILLA_AUDIONOTIFICATIONSENDER_H_
|
@ -142,11 +142,6 @@ AudioStream::AudioStream(DataSource& aSource)
|
||||
mPrefillQuirk(false),
|
||||
mAudioThreadId(0),
|
||||
mSandboxed(CubebUtils::SandboxEnabled()) {
|
||||
#if defined(XP_WIN)
|
||||
if (XRE_IsContentProcess()) {
|
||||
audio::AudioNotificationReceiver::Register(this);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
AudioStream::~AudioStream() {
|
||||
@ -156,11 +151,6 @@ AudioStream::~AudioStream() {
|
||||
if (mTimeStretcher) {
|
||||
soundtouch::destroySoundTouchObj(mTimeStretcher);
|
||||
}
|
||||
#if defined(XP_WIN)
|
||||
if (XRE_IsContentProcess()) {
|
||||
audio::AudioNotificationReceiver::Unregister(this);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t AudioStream::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
|
||||
@ -448,22 +438,6 @@ void AudioStream::Shutdown() {
|
||||
mEndedPromise.ResolveIfExists(true, __func__);
|
||||
}
|
||||
|
||||
#if defined(XP_WIN)
|
||||
void AudioStream::ResetDefaultDevice() {
|
||||
TRACE();
|
||||
MonitorAutoLock mon(mMonitor);
|
||||
if (mState != STARTED && mState != STOPPED) {
|
||||
return;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(mCubebStream);
|
||||
auto r = InvokeCubeb(cubeb_stream_reset_default_device);
|
||||
if (!(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED)) {
|
||||
mState = ERRORED;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
int64_t AudioStream::GetPosition() {
|
||||
TRACE();
|
||||
MonitorAutoLock mon(mMonitor);
|
||||
|
@ -21,10 +21,6 @@
|
||||
# include "nsThreadUtils.h"
|
||||
# include "WavDumper.h"
|
||||
|
||||
# if defined(XP_WIN)
|
||||
# include "mozilla/audio/AudioNotificationReceiver.h"
|
||||
# endif
|
||||
|
||||
namespace soundtouch {
|
||||
class MOZ_EXPORT SoundTouch;
|
||||
}
|
||||
@ -174,9 +170,6 @@ class AudioBufferWriter : private AudioBufferCursor {
|
||||
// GetPosition, GetPositionInFrames, SetVolume, and Get{Rate,Channels},
|
||||
// SetMicrophoneActive is thread-safe without external synchronization.
|
||||
class AudioStream final
|
||||
# if defined(XP_WIN)
|
||||
: public audio::DeviceChangeListener
|
||||
# endif
|
||||
{
|
||||
virtual ~AudioStream();
|
||||
|
||||
@ -239,11 +232,6 @@ class AudioStream final
|
||||
// Resume audio playback.
|
||||
void Resume();
|
||||
|
||||
# if defined(XP_WIN)
|
||||
// Reset stream to the default device.
|
||||
void ResetDefaultDevice() override;
|
||||
# endif
|
||||
|
||||
// Return the position in microseconds of the audio frame being played by
|
||||
// the audio hardware, compensated for playback rate change. Thread-safe.
|
||||
int64_t GetPosition();
|
||||
|
@ -56,9 +56,6 @@
|
||||
// Hidden pref used by tests to force failure to obtain cubeb context
|
||||
#define PREF_CUBEB_FORCE_NULL_CONTEXT "media.cubeb.force_null_context"
|
||||
#define PREF_CUBEB_OUTPUT_VOICE_ROUTING "media.cubeb.output_voice_routing"
|
||||
// Hidden pref to disable BMO 1427011 experiment; can be removed once proven.
|
||||
#define PREF_CUBEB_DISABLE_DEVICE_SWITCHING \
|
||||
"media.cubeb.disable_device_switching"
|
||||
#define PREF_CUBEB_SANDBOX "media.cubeb.sandbox"
|
||||
#define PREF_AUDIOIPC_POOL_SIZE "media.audioipc.pool_size"
|
||||
#define PREF_AUDIOIPC_STACK_SIZE "media.audioipc.stack_size"
|
||||
@ -106,7 +103,6 @@ bool sCubebPlaybackLatencyPrefSet = false;
|
||||
bool sCubebMTGLatencyPrefSet = false;
|
||||
bool sAudioStreamInitEverSucceeded = false;
|
||||
bool sCubebForceNullContext = false;
|
||||
bool sCubebDisableDeviceSwitching = true;
|
||||
bool sRouteOutputAsVoice = false;
|
||||
#ifdef MOZ_CUBEB_REMOTING
|
||||
bool sCubebSandbox = false;
|
||||
@ -258,12 +254,6 @@ void PrefChanged(const char* aPref, void* aClosure) {
|
||||
MOZ_LOG(gCubebLog, LogLevel::Verbose,
|
||||
("%s: %s", PREF_CUBEB_FORCE_NULL_CONTEXT,
|
||||
sCubebForceNullContext ? "true" : "false"));
|
||||
} else if (strcmp(aPref, PREF_CUBEB_DISABLE_DEVICE_SWITCHING) == 0) {
|
||||
StaticMutexAutoLock lock(sMutex);
|
||||
sCubebDisableDeviceSwitching = Preferences::GetBool(aPref, true);
|
||||
MOZ_LOG(gCubebLog, LogLevel::Verbose,
|
||||
("%s: %s", PREF_CUBEB_DISABLE_DEVICE_SWITCHING,
|
||||
sCubebDisableDeviceSwitching ? "true" : "false"));
|
||||
}
|
||||
#ifdef MOZ_CUBEB_REMOTING
|
||||
else if (strcmp(aPref, PREF_CUBEB_SANDBOX) == 0) {
|
||||
@ -700,12 +690,6 @@ char* GetForcedOutputDevice() {
|
||||
cubeb_stream_prefs GetDefaultStreamPrefs(cubeb_device_type aType) {
|
||||
cubeb_stream_prefs prefs = CUBEB_STREAM_PREF_NONE;
|
||||
#ifdef XP_WIN
|
||||
// Investigation for bug 1427011 - if we're in E10S mode, rely on the
|
||||
// AudioNotification IPC to detect device changes.
|
||||
if (sCubebDisableDeviceSwitching &&
|
||||
(XRE_IsE10sParentProcess() || XRE_IsContentProcess())) {
|
||||
prefs |= CUBEB_STREAM_PREF_DISABLE_DEVICE_SWITCHING;
|
||||
}
|
||||
if (StaticPrefs::media_cubeb_wasapi_raw() & static_cast<uint32_t>(aType)) {
|
||||
prefs |= CUBEB_STREAM_PREF_RAW;
|
||||
}
|
||||
|
@ -516,11 +516,6 @@ AudioCallbackDriver::AudioCallbackDriver(
|
||||
mInitShutdownThread->SetIdleThreadTimeout(
|
||||
PR_MillisecondsToInterval(kIdleThreadTimeoutMs));
|
||||
|
||||
#if defined(XP_WIN)
|
||||
if (XRE_IsContentProcess()) {
|
||||
audio::AudioNotificationReceiver::Register(this);
|
||||
}
|
||||
#endif
|
||||
if (aAudioInputType == AudioInputType::Voice) {
|
||||
LOG(LogLevel::Debug, ("VOICE."));
|
||||
mInputDevicePreference = CUBEB_DEVICE_PREF_VOICE;
|
||||
@ -533,11 +528,6 @@ AudioCallbackDriver::AudioCallbackDriver(
|
||||
}
|
||||
|
||||
AudioCallbackDriver::~AudioCallbackDriver() {
|
||||
#if defined(XP_WIN)
|
||||
if (XRE_IsContentProcess()) {
|
||||
audio::AudioNotificationReceiver::Unregister(this);
|
||||
}
|
||||
#endif
|
||||
if (mInputDevicePreference == CUBEB_DEVICE_PREF_VOICE) {
|
||||
CubebUtils::SetInCommunication(false);
|
||||
}
|
||||
@ -806,15 +796,6 @@ void AudioCallbackDriver::Shutdown() {
|
||||
releaseEvent->Dispatch(NS_DISPATCH_SYNC);
|
||||
}
|
||||
|
||||
#if defined(XP_WIN)
|
||||
void AudioCallbackDriver::ResetDefaultDevice() {
|
||||
TRACE();
|
||||
if (cubeb_stream_reset_default_device(mAudioStream) != CUBEB_OK) {
|
||||
NS_WARNING("Could not reset cubeb stream to default output device.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* static */
|
||||
long AudioCallbackDriver::DataCallback_s(cubeb_stream* aStream, void* aUser,
|
||||
const void* aInputBuffer,
|
||||
|
@ -21,10 +21,6 @@
|
||||
|
||||
#include <thread>
|
||||
|
||||
#if defined(XP_WIN)
|
||||
# include "mozilla/audio/AudioNotificationReceiver.h"
|
||||
#endif
|
||||
|
||||
struct cubeb_stream;
|
||||
|
||||
template <>
|
||||
@ -562,10 +558,6 @@ enum class AudioInputType { Unknown, Voice };
|
||||
*/
|
||||
class AudioCallbackDriver : public GraphDriver,
|
||||
public MixerCallbackReceiver
|
||||
#if defined(XP_WIN)
|
||||
,
|
||||
public audio::DeviceChangeListener
|
||||
#endif
|
||||
{
|
||||
using IterationResult = GraphInterface::IterationResult;
|
||||
enum class FallbackDriverState;
|
||||
@ -584,9 +576,6 @@ class AudioCallbackDriver : public GraphDriver,
|
||||
|
||||
void Start() override;
|
||||
MOZ_CAN_RUN_SCRIPT void Shutdown() override;
|
||||
#if defined(XP_WIN)
|
||||
void ResetDefaultDevice() override;
|
||||
#endif
|
||||
|
||||
/* Static wrapper function cubeb calls back. */
|
||||
static long DataCallback_s(cubeb_stream* aStream, void* aUser,
|
||||
|
@ -305,13 +305,7 @@ else:
|
||||
UNIFIED_SOURCES += ["UnderrunHandlerNoop.cpp"]
|
||||
|
||||
if CONFIG["OS_TARGET"] == "WINNT":
|
||||
EXPORTS.mozilla.audio += [
|
||||
"AudioNotificationReceiver.h",
|
||||
"AudioNotificationSender.h",
|
||||
]
|
||||
SOURCES += [
|
||||
"AudioNotificationReceiver.cpp",
|
||||
"AudioNotificationSender.cpp",
|
||||
"ThreadPoolCOMListener.cpp",
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user