2011-06-24 18:20:03 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-21 15:12:37 +04: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/. */
|
2011-06-24 18:20:03 +04:00
|
|
|
|
|
|
|
#include <windows.h>
|
|
|
|
#include <audiopolicy.h>
|
2011-07-13 19:58:33 +04:00
|
|
|
#include <mmdeviceapi.h>
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2016-04-19 23:51:25 +03:00
|
|
|
#include "mozilla/RefPtr.h"
|
2011-06-24 18:20:03 +04:00
|
|
|
#include "nsIStringBundle.h"
|
|
|
|
#include "nsIUUIDGenerator.h"
|
|
|
|
#include "nsIXULAppInfo.h"
|
|
|
|
|
|
|
|
//#include "AudioSession.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsServiceManagerUtils.h"
|
|
|
|
#include "nsString.h"
|
2011-12-29 20:59:29 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2011-07-13 19:58:33 +04:00
|
|
|
#include "nsXULAppAPI.h"
|
2012-06-14 22:28:06 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2018-01-11 01:57:19 +03:00
|
|
|
#include "mozilla/Mutex.h"
|
2018-05-05 01:57:26 +03:00
|
|
|
#include "mozilla/WindowsVersion.h"
|
2011-06-24 18:20:03 +04:00
|
|
|
|
|
|
|
#include <objbase.h>
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace widget {
|
|
|
|
|
2016-07-22 11:56:13 +03:00
|
|
|
/*
|
2011-06-24 18:20:03 +04:00
|
|
|
* To take advantage of what Vista+ have to offer with respect to audio,
|
|
|
|
* we need to maintain an audio session. This class wraps IAudioSessionControl
|
|
|
|
* and implements IAudioSessionEvents (for callbacks from Windows)
|
|
|
|
*/
|
2015-03-21 19:28:04 +03:00
|
|
|
class AudioSession final : public IAudioSessionEvents {
|
2011-06-24 18:20:03 +04:00
|
|
|
private:
|
|
|
|
AudioSession();
|
|
|
|
~AudioSession();
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-06-24 18:20:03 +04:00
|
|
|
public:
|
|
|
|
static AudioSession* GetSingleton();
|
|
|
|
|
|
|
|
// COM IUnknown
|
|
|
|
STDMETHODIMP_(ULONG) AddRef();
|
|
|
|
STDMETHODIMP QueryInterface(REFIID, void**);
|
|
|
|
STDMETHODIMP_(ULONG) Release();
|
|
|
|
|
|
|
|
// IAudioSessionEvents
|
|
|
|
STDMETHODIMP OnChannelVolumeChanged(DWORD aChannelCount,
|
|
|
|
float aChannelVolumeArray[],
|
|
|
|
DWORD aChangedChannel, LPCGUID aContext);
|
|
|
|
STDMETHODIMP OnDisplayNameChanged(LPCWSTR aDisplayName, LPCGUID aContext);
|
|
|
|
STDMETHODIMP OnGroupingParamChanged(LPCGUID aGroupingParam, LPCGUID aContext);
|
|
|
|
STDMETHODIMP OnIconPathChanged(LPCWSTR aIconPath, LPCGUID aContext);
|
|
|
|
STDMETHODIMP OnSessionDisconnected(AudioSessionDisconnectReason aReason);
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-12-29 20:59:29 +04:00
|
|
|
private:
|
|
|
|
nsresult OnSessionDisconnectedInternal();
|
2018-01-11 01:57:19 +03:00
|
|
|
nsresult CommitAudioSessionData();
|
|
|
|
|
2011-12-29 20:59:29 +04:00
|
|
|
public:
|
2011-06-24 18:20:03 +04:00
|
|
|
STDMETHODIMP OnSimpleVolumeChanged(float aVolume, BOOL aMute,
|
|
|
|
LPCGUID aContext);
|
|
|
|
STDMETHODIMP OnStateChanged(AudioSessionState aState);
|
|
|
|
|
|
|
|
nsresult Start();
|
|
|
|
nsresult Stop();
|
2011-06-24 18:20:03 +04:00
|
|
|
void StopInternal();
|
|
|
|
|
|
|
|
nsresult GetSessionData(nsID& aID, nsString& aSessionName,
|
|
|
|
nsString& aIconPath);
|
|
|
|
|
|
|
|
nsresult SetSessionData(const nsID& aID, const nsString& aSessionName,
|
|
|
|
const nsString& aIconPath);
|
|
|
|
|
|
|
|
enum SessionState {
|
|
|
|
UNINITIALIZED, // Has not been initialized yet
|
|
|
|
STARTED, // Started
|
|
|
|
CLONED, // SetSessionInfoCalled, Start not called
|
2016-03-13 16:25:23 +03:00
|
|
|
FAILED, // The audio session failed to start
|
2012-02-17 18:17:27 +04:00
|
|
|
STOPPED, // Stop called
|
|
|
|
AUDIO_SESSION_DISCONNECTED // Audio session disconnected
|
2011-06-24 18:20:03 +04:00
|
|
|
};
|
2018-11-30 13:46:48 +03:00
|
|
|
|
2011-06-24 18:20:03 +04:00
|
|
|
protected:
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IAudioSessionControl> mAudioSessionControl;
|
2011-06-24 18:20:03 +04:00
|
|
|
nsString mDisplayName;
|
|
|
|
nsString mIconPath;
|
|
|
|
nsID mSessionGroupingParameter;
|
2011-06-24 18:20:03 +04:00
|
|
|
SessionState mState;
|
2018-01-11 01:57:19 +03:00
|
|
|
// Guards the IAudioSessionControl
|
|
|
|
mozilla::Mutex mMutex;
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2013-07-19 06:24:15 +04:00
|
|
|
ThreadSafeAutoRefCnt mRefCnt;
|
2011-06-24 18:20:03 +04:00
|
|
|
NS_DECL_OWNINGTHREAD
|
|
|
|
|
|
|
|
static AudioSession* sService;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult StartAudioSession() { return AudioSession::GetSingleton()->Start(); }
|
|
|
|
|
|
|
|
nsresult StopAudioSession() { return AudioSession::GetSingleton()->Stop(); }
|
|
|
|
|
2011-06-24 18:20:03 +04:00
|
|
|
nsresult GetAudioSessionData(nsID& aID, nsString& aSessionName,
|
|
|
|
nsString& aIconPath) {
|
|
|
|
return AudioSession::GetSingleton()->GetSessionData(aID, aSessionName,
|
|
|
|
aIconPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult RecvAudioSessionData(const nsID& aID, const nsString& aSessionName,
|
|
|
|
const nsString& aIconPath) {
|
|
|
|
return AudioSession::GetSingleton()->SetSessionData(aID, aSessionName,
|
|
|
|
aIconPath);
|
|
|
|
}
|
|
|
|
|
2013-10-08 22:48:02 +04:00
|
|
|
AudioSession* AudioSession::sService = nullptr;
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2018-01-11 01:57:19 +03:00
|
|
|
AudioSession::AudioSession() : mMutex("AudioSessionControl") {
|
2011-06-24 18:20:03 +04:00
|
|
|
mState = UNINITIALIZED;
|
2011-06-24 18:20:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
AudioSession::~AudioSession() {}
|
|
|
|
|
|
|
|
AudioSession* AudioSession::GetSingleton() {
|
|
|
|
if (!(AudioSession::sService)) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<AudioSession> service = new AudioSession();
|
2011-06-24 18:20:03 +04:00
|
|
|
service.forget(&AudioSession::sService);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't refcount AudioSession on the Gecko side, we hold one single ref
|
|
|
|
// as long as the appshell is running.
|
|
|
|
return AudioSession::sService;
|
|
|
|
}
|
|
|
|
|
|
|
|
// It appears Windows will use us on a background thread ...
|
2013-07-19 06:24:15 +04:00
|
|
|
NS_IMPL_ADDREF(AudioSession)
|
|
|
|
NS_IMPL_RELEASE(AudioSession)
|
2011-06-24 18:20:03 +04:00
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
AudioSession::QueryInterface(REFIID iid, void** ppv) {
|
|
|
|
const IID IID_IAudioSessionEvents = __uuidof(IAudioSessionEvents);
|
|
|
|
if ((IID_IUnknown == iid) || (IID_IAudioSessionEvents == iid)) {
|
|
|
|
*ppv = static_cast<IAudioSessionEvents*>(this);
|
|
|
|
AddRef();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Once we are started Windows will hold a reference to us through our
|
|
|
|
// IAudioSessionEvents interface that will keep us alive until the appshell
|
|
|
|
// calls Stop.
|
|
|
|
nsresult AudioSession::Start() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mState == UNINITIALIZED || mState == CLONED ||
|
|
|
|
mState == AUDIO_SESSION_DISCONNECTED,
|
|
|
|
"State invariants violated");
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2011-06-24 18:20:03 +04:00
|
|
|
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
|
|
|
|
const IID IID_IMMDeviceEnumerator = __uuidof(IMMDeviceEnumerator);
|
|
|
|
const IID IID_IAudioSessionManager = __uuidof(IAudioSessionManager);
|
|
|
|
|
|
|
|
HRESULT hr;
|
|
|
|
|
2016-03-13 16:25:23 +03:00
|
|
|
// There's a matching CoUninit in Stop() for this tied to a state of
|
|
|
|
// UNINITIALIZED.
|
|
|
|
hr = CoInitialize(nullptr);
|
|
|
|
MOZ_ASSERT(SUCCEEDED(hr),
|
|
|
|
"CoInitialize failure in audio session control, unexpected");
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2011-06-24 18:20:03 +04:00
|
|
|
if (mState == UNINITIALIZED) {
|
|
|
|
mState = FAILED;
|
|
|
|
|
2016-03-13 16:25:23 +03:00
|
|
|
// Content processes should be CLONED
|
|
|
|
if (XRE_IsContentProcess()) {
|
2011-06-24 18:20:03 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2016-03-13 16:25:23 +03:00
|
|
|
}
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2015-07-04 04:29:00 +03:00
|
|
|
MOZ_ASSERT(XRE_IsParentProcess(),
|
2015-02-10 01:34:50 +03:00
|
|
|
"Should only get here in a chrome process!");
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2016-07-22 11:56:13 +03:00
|
|
|
nsCOMPtr<nsIStringBundleService> bundleService =
|
2011-06-24 18:20:03 +04:00
|
|
|
do_GetService(NS_STRINGBUNDLE_CONTRACTID);
|
|
|
|
NS_ENSURE_TRUE(bundleService, NS_ERROR_FAILURE);
|
|
|
|
nsCOMPtr<nsIStringBundle> bundle;
|
|
|
|
bundleService->CreateBundle("chrome://branding/locale/brand.properties",
|
|
|
|
getter_AddRefs(bundle));
|
|
|
|
NS_ENSURE_TRUE(bundle, NS_ERROR_FAILURE);
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2017-08-04 07:40:52 +03:00
|
|
|
bundle->GetStringFromName("brandFullName", mDisplayName);
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2013-12-03 19:12:57 +04:00
|
|
|
wchar_t* buffer;
|
2011-06-24 18:20:03 +04:00
|
|
|
mIconPath.GetMutableData(&buffer, MAX_PATH);
|
2013-10-08 22:48:02 +04:00
|
|
|
::GetModuleFileNameW(nullptr, buffer, MAX_PATH);
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2011-06-24 18:20:03 +04:00
|
|
|
nsCOMPtr<nsIUUIDGenerator> uuidgen =
|
|
|
|
do_GetService("@mozilla.org/uuid-generator;1");
|
2012-08-10 04:54:35 +04:00
|
|
|
NS_ENSURE_TRUE(uuidgen, NS_ERROR_FAILURE);
|
2011-06-24 18:20:03 +04:00
|
|
|
uuidgen->GenerateUUIDInPlace(&mSessionGroupingParameter);
|
|
|
|
}
|
|
|
|
|
|
|
|
mState = FAILED;
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mDisplayName.IsEmpty() || !mIconPath.IsEmpty(),
|
|
|
|
"Should never happen ...");
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IMMDeviceEnumerator> enumerator;
|
2011-06-24 18:20:03 +04:00
|
|
|
hr = ::CoCreateInstance(CLSID_MMDeviceEnumerator, nullptr, CLSCTX_ALL,
|
|
|
|
IID_IMMDeviceEnumerator, getter_AddRefs(enumerator));
|
|
|
|
if (FAILED(hr)) return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IMMDevice> device;
|
2011-06-24 18:20:03 +04:00
|
|
|
hr = enumerator->GetDefaultAudioEndpoint(
|
|
|
|
EDataFlow::eRender, ERole::eMultimedia, getter_AddRefs(device));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
if (hr == E_NOTFOUND) return NS_ERROR_NOT_AVAILABLE;
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<IAudioSessionManager> manager;
|
2011-06-24 18:20:03 +04:00
|
|
|
hr = device->Activate(IID_IAudioSessionManager, CLSCTX_ALL, nullptr,
|
|
|
|
getter_AddRefs(manager));
|
2016-03-13 16:25:23 +03:00
|
|
|
if (FAILED(hr)) {
|
2011-06-24 18:20:03 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2016-03-13 16:25:23 +03:00
|
|
|
}
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2018-01-11 01:57:19 +03:00
|
|
|
MutexAutoLock lock(mMutex);
|
2016-03-13 16:25:23 +03:00
|
|
|
hr = manager->GetAudioSessionControl(&GUID_NULL, 0,
|
2011-06-24 18:20:03 +04:00
|
|
|
getter_AddRefs(mAudioSessionControl));
|
2016-03-13 16:25:23 +03:00
|
|
|
|
|
|
|
if (FAILED(hr)) {
|
2011-06-24 18:20:03 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
2016-03-13 16:25:23 +03:00
|
|
|
}
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2017-09-29 00:28:39 +03:00
|
|
|
// Increments refcount of 'this'.
|
2011-06-24 18:20:03 +04:00
|
|
|
hr = mAudioSessionControl->RegisterAudioSessionNotification(this);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
StopInternal();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2018-01-11 01:57:19 +03:00
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
|
|
|
NewRunnableMethod("AudioSession::CommitAudioSessionData", this,
|
|
|
|
&AudioSession::CommitAudioSessionData);
|
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
|
2011-06-24 18:20:03 +04:00
|
|
|
mState = STARTED;
|
|
|
|
|
2011-06-24 18:20:03 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-05-05 01:57:26 +03:00
|
|
|
void SpawnASCReleaseThread(RefPtr<IAudioSessionControl>&& aASC) {
|
|
|
|
// Fake moving to the other thread by circumventing the ref count.
|
|
|
|
// (RefPtrs don't play well with C++11 lambdas and we don't want to use
|
|
|
|
// XPCOM here.)
|
|
|
|
IAudioSessionControl* rawPtr = nullptr;
|
|
|
|
aASC.forget(&rawPtr);
|
|
|
|
MOZ_ASSERT(rawPtr);
|
|
|
|
PRThread* thread = PR_CreateThread(
|
|
|
|
PR_USER_THREAD,
|
|
|
|
[](void* aRawPtr) {
|
2019-06-07 00:07:29 +03:00
|
|
|
NS_SetCurrentThreadName("AudioASCReleaser");
|
2018-05-05 01:57:26 +03:00
|
|
|
static_cast<IAudioSessionControl*>(aRawPtr)->Release();
|
|
|
|
},
|
|
|
|
rawPtr, PR_PRIORITY_NORMAL, PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
|
|
|
|
if (!thread) {
|
|
|
|
// We can't make a thread so just destroy the IAudioSessionControl here.
|
|
|
|
rawPtr->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-24 18:20:03 +04:00
|
|
|
void AudioSession::StopInternal() {
|
2018-01-11 01:57:19 +03:00
|
|
|
mMutex.AssertCurrentThreadOwns();
|
|
|
|
|
2016-04-28 00:31:37 +03:00
|
|
|
if (mAudioSessionControl && (mState == STARTED || mState == STOPPED)) {
|
2017-09-29 00:28:39 +03:00
|
|
|
// Decrement refcount of 'this'
|
2011-06-24 18:20:03 +04:00
|
|
|
mAudioSessionControl->UnregisterAudioSessionNotification(this);
|
|
|
|
}
|
2018-05-05 01:57:26 +03:00
|
|
|
|
|
|
|
// Win7 is the only Windows version supported before Win8.
|
|
|
|
if (mAudioSessionControl && !IsWin8OrLater()) {
|
|
|
|
// bug 1419488: Avoid hanging due to Win7 race condition when destroying
|
|
|
|
// AudioSessionControl. We do that by Moving the AudioSessionControl
|
|
|
|
// to a worker thread (that we never 'join') for destruction.
|
2018-05-30 22:15:35 +03:00
|
|
|
SpawnASCReleaseThread(std::move(mAudioSessionControl));
|
2018-05-05 01:57:26 +03:00
|
|
|
} else {
|
|
|
|
mAudioSessionControl = nullptr;
|
|
|
|
}
|
2011-06-24 18:20:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult AudioSession::Stop() {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mState == STARTED || mState == UNINITIALIZED || // XXXremove this
|
|
|
|
mState == FAILED,
|
|
|
|
"State invariants violated");
|
2016-03-13 16:25:23 +03:00
|
|
|
SessionState state = mState;
|
2011-06-24 18:20:03 +04:00
|
|
|
mState = STOPPED;
|
|
|
|
|
2016-03-13 16:25:23 +03:00
|
|
|
{
|
|
|
|
RefPtr<AudioSession> kungFuDeathGrip;
|
|
|
|
kungFuDeathGrip.swap(sService);
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2018-01-11 01:57:19 +03:00
|
|
|
MutexAutoLock lock(mMutex);
|
2011-06-24 18:20:03 +04:00
|
|
|
StopInternal();
|
2016-03-13 16:25:23 +03:00
|
|
|
}
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2016-03-13 16:25:23 +03:00
|
|
|
if (state != UNINITIALIZED) {
|
|
|
|
::CoUninitialize();
|
|
|
|
}
|
2011-06-24 18:20:03 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-24 18:20:03 +04:00
|
|
|
void CopynsID(nsID& lhs, const nsID& rhs) {
|
|
|
|
lhs.m0 = rhs.m0;
|
|
|
|
lhs.m1 = rhs.m1;
|
|
|
|
lhs.m2 = rhs.m2;
|
|
|
|
for (int i = 0; i < 8; i++) {
|
|
|
|
lhs.m3[i] = rhs.m3[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult AudioSession::GetSessionData(nsID& aID, nsString& aSessionName,
|
|
|
|
nsString& aIconPath) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mState == FAILED || mState == STARTED || mState == CLONED,
|
|
|
|
"State invariants violated");
|
2011-06-24 18:20:03 +04:00
|
|
|
|
|
|
|
CopynsID(aID, mSessionGroupingParameter);
|
|
|
|
aSessionName = mDisplayName;
|
|
|
|
aIconPath = mIconPath;
|
|
|
|
|
|
|
|
if (mState == FAILED) return NS_ERROR_FAILURE;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult AudioSession::SetSessionData(const nsID& aID,
|
|
|
|
const nsString& aSessionName,
|
|
|
|
const nsString& aIconPath) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mState == UNINITIALIZED, "State invariants violated");
|
2015-07-04 04:29:00 +03:00
|
|
|
MOZ_ASSERT(!XRE_IsParentProcess(),
|
2015-02-10 01:34:50 +03:00
|
|
|
"Should never get here in a chrome process!");
|
2011-06-24 18:20:03 +04:00
|
|
|
mState = CLONED;
|
|
|
|
|
|
|
|
CopynsID(mSessionGroupingParameter, aID);
|
|
|
|
mDisplayName = aSessionName;
|
|
|
|
mIconPath = aIconPath;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2018-01-11 01:57:19 +03:00
|
|
|
nsresult AudioSession::CommitAudioSessionData() {
|
|
|
|
MutexAutoLock lock(mMutex);
|
|
|
|
|
|
|
|
if (!mAudioSessionControl) {
|
|
|
|
// Stop() was called before we had a chance to do this.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr = mAudioSessionControl->SetGroupingParam(
|
|
|
|
(LPGUID)&mSessionGroupingParameter, nullptr);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
StopInternal();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mAudioSessionControl->SetDisplayName(mDisplayName.get(), nullptr);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
StopInternal();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mAudioSessionControl->SetIconPath(mIconPath.get(), nullptr);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
StopInternal();
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-06-24 18:20:03 +04:00
|
|
|
STDMETHODIMP
|
|
|
|
AudioSession::OnChannelVolumeChanged(DWORD aChannelCount,
|
|
|
|
float aChannelVolumeArray[],
|
|
|
|
DWORD aChangedChannel, LPCGUID aContext) {
|
|
|
|
return S_OK; // NOOP
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
AudioSession::OnDisplayNameChanged(LPCWSTR aDisplayName, LPCGUID aContext) {
|
|
|
|
return S_OK; // NOOP
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
AudioSession::OnGroupingParamChanged(LPCGUID aGroupingParam, LPCGUID aContext) {
|
|
|
|
return S_OK; // NOOP
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
AudioSession::OnIconPathChanged(LPCWSTR aIconPath, LPCGUID aContext) {
|
|
|
|
return S_OK; // NOOP
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
AudioSession::OnSessionDisconnected(AudioSessionDisconnectReason aReason) {
|
2011-12-29 20:59:29 +04:00
|
|
|
// Run our code asynchronously. Per MSDN we can't do anything interesting
|
|
|
|
// in this callback.
|
|
|
|
nsCOMPtr<nsIRunnable> runnable =
|
2017-06-12 22:34:10 +03:00
|
|
|
NewRunnableMethod("widget::AudioSession::OnSessionDisconnectedInternal",
|
|
|
|
this, &AudioSession::OnSessionDisconnectedInternal);
|
2011-12-29 20:59:29 +04:00
|
|
|
NS_DispatchToMainThread(runnable);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult AudioSession::OnSessionDisconnectedInternal() {
|
2018-03-22 05:37:44 +03:00
|
|
|
// When successful, UnregisterAudioSessionNotification will decrement the
|
|
|
|
// refcount of 'this'. Start will re-increment it. In the interim,
|
|
|
|
// we'll need to reference ourselves.
|
|
|
|
RefPtr<AudioSession> kungFuDeathGrip(this);
|
|
|
|
|
2018-01-11 01:57:19 +03:00
|
|
|
{
|
|
|
|
// We need to release the mutex before we call Start().
|
|
|
|
MutexAutoLock lock(mMutex);
|
2011-06-24 18:20:03 +04:00
|
|
|
|
2018-01-11 01:57:19 +03:00
|
|
|
if (!mAudioSessionControl) return NS_OK;
|
|
|
|
|
|
|
|
mAudioSessionControl->UnregisterAudioSessionNotification(this);
|
|
|
|
mAudioSessionControl = nullptr;
|
|
|
|
}
|
2011-12-29 20:59:29 +04:00
|
|
|
|
2012-02-17 18:17:27 +04:00
|
|
|
mState = AUDIO_SESSION_DISCONNECTED;
|
|
|
|
CoUninitialize();
|
2011-12-29 20:59:29 +04:00
|
|
|
Start(); // If it fails there's not much we can do.
|
|
|
|
return NS_OK;
|
2011-06-24 18:20:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
AudioSession::OnSimpleVolumeChanged(float aVolume, BOOL aMute,
|
|
|
|
LPCGUID aContext) {
|
|
|
|
return S_OK; // NOOP
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP
|
|
|
|
AudioSession::OnStateChanged(AudioSessionState aState) {
|
|
|
|
return S_OK; // NOOP
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace widget
|
|
|
|
} // namespace mozilla
|