2014-11-17 11:37:51 +00:00
|
|
|
/*
|
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
|
|
|
* Original author: Jonathan Yong <10walls@gmail.com>
|
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2014-11-17 11:37:51 +00:00
|
|
|
*
|
|
|
|
* mpv is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2014-11-17 11:37:51 +00:00
|
|
|
*
|
Relicense some non-MPlayer source files to LGPL 2.1 or later
This covers source files which were added in mplayer2 and mpv times
only, and where all code is covered by LGPL relicensing agreements.
There are probably more files to which this applies, but I'm being
conservative here.
A file named ao_sdl.c exists in MPlayer too, but the mpv one is a
complete rewrite, and was added some time after the original ao_sdl.c
was removed. The same applies to vo_sdl.c, for which the SDL2 API is
radically different in addition (MPlayer supports SDL 1.2 only).
common.c contains only code written by me. But common.h is a strange
case: although it originally was named mp_common.h and exists in MPlayer
too, by now it contains only definitions written by uau and me. The
exceptions are the CONTROL_ defines - thus not changing the license of
common.h yet.
codec_tags.c contained once large tables generated from MPlayer's
codecs.conf, but all of these tables were removed.
From demux_playlist.c I'm removing a code fragment from someone who was
not asked; this probably could be done later (see commit 15dccc37).
misc.c is a bit complicated to reason about (it was split off mplayer.c
and thus contains random functions out of this file), but actually all
functions have been added post-MPlayer. Except get_relative_time(),
which was written by uau, but looks similar to 3 different versions of
something similar in each of the Unix/win32/OSX timer source files. I'm
not sure what that means in regards to copyright, so I've just moved it
into another still-GPL source file for now.
screenshot.c once had some minor parts of MPlayer's vf_screenshot.c, but
they're all gone.
2016-01-19 17:36:06 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2014-11-17 11:37:51 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <wchar.h>
|
|
|
|
|
|
|
|
#include "ao_wasapi.h"
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE sIMMNotificationClient_QueryInterface(
|
|
|
|
IMMNotificationClient* This, REFIID riid, void **ppvObject)
|
|
|
|
{
|
2015-12-21 00:43:23 +00:00
|
|
|
// Compatible with IMMNotificationClient and IUnknown
|
2015-01-02 22:26:08 +00:00
|
|
|
if (IsEqualGUID(&IID_IMMNotificationClient, riid) ||
|
2015-03-26 12:52:34 +00:00
|
|
|
IsEqualGUID(&IID_IUnknown, riid))
|
|
|
|
{
|
2014-11-17 11:37:51 +00:00
|
|
|
*ppvObject = (void *)This;
|
|
|
|
return S_OK;
|
|
|
|
} else {
|
|
|
|
*ppvObject = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-21 00:43:23 +00:00
|
|
|
// these are required, but not actually used
|
2014-11-17 11:37:51 +00:00
|
|
|
static ULONG STDMETHODCALLTYPE sIMMNotificationClient_AddRef(
|
|
|
|
IMMNotificationClient *This)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-12-21 00:43:23 +00:00
|
|
|
// MSDN says it should free itself, but we're static
|
2014-11-17 11:37:51 +00:00
|
|
|
static ULONG STDMETHODCALLTYPE sIMMNotificationClient_Release(
|
|
|
|
IMMNotificationClient *This)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE sIMMNotificationClient_OnDeviceStateChanged(
|
|
|
|
IMMNotificationClient *This,
|
|
|
|
LPCWSTR pwstrDeviceId,
|
|
|
|
DWORD dwNewState)
|
|
|
|
{
|
|
|
|
change_notify *change = (change_notify *)This;
|
2014-11-13 09:09:47 +00:00
|
|
|
struct ao *ao = change->ao;
|
2014-11-17 11:37:51 +00:00
|
|
|
|
2015-03-31 08:56:17 +00:00
|
|
|
if (change->is_hotplug) {
|
2015-12-21 00:43:23 +00:00
|
|
|
MP_VERBOSE(ao,
|
|
|
|
"OnDeviceStateChanged triggered: sending hotplug event\n");
|
2015-03-31 08:56:17 +00:00
|
|
|
ao_hotplug_event(ao);
|
2015-08-01 18:51:52 +00:00
|
|
|
} else if (pwstrDeviceId && !wcscmp(pwstrDeviceId, change->monitored)) {
|
2014-11-17 11:37:51 +00:00
|
|
|
switch (dwNewState) {
|
|
|
|
case DEVICE_STATE_DISABLED:
|
|
|
|
case DEVICE_STATE_NOTPRESENT:
|
|
|
|
case DEVICE_STATE_UNPLUGGED:
|
2017-04-20 05:38:03 +00:00
|
|
|
MP_VERBOSE(ao, "OnDeviceStateChanged triggered on device %ls: "
|
2015-03-31 08:56:17 +00:00
|
|
|
"requesting ao reload\n", pwstrDeviceId);
|
2014-11-13 09:09:47 +00:00
|
|
|
ao_request_reload(ao);
|
2015-03-31 08:56:17 +00:00
|
|
|
break;
|
2014-11-17 11:37:51 +00:00
|
|
|
case DEVICE_STATE_ACTIVE:
|
2015-03-31 08:56:17 +00:00
|
|
|
break;
|
2014-11-17 11:37:51 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-31 08:56:17 +00:00
|
|
|
|
2014-11-17 11:37:51 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE sIMMNotificationClient_OnDeviceAdded(
|
|
|
|
IMMNotificationClient *This,
|
|
|
|
LPCWSTR pwstrDeviceId)
|
|
|
|
{
|
|
|
|
change_notify *change = (change_notify *)This;
|
2014-11-13 09:09:47 +00:00
|
|
|
struct ao *ao = change->ao;
|
2014-11-17 11:37:51 +00:00
|
|
|
|
2015-03-31 08:56:17 +00:00
|
|
|
if (change->is_hotplug) {
|
|
|
|
MP_VERBOSE(ao, "OnDeviceAdded triggered: sending hotplug event\n");
|
|
|
|
ao_hotplug_event(ao);
|
|
|
|
}
|
|
|
|
|
2014-11-17 11:37:51 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-06-25 18:07:38 +00:00
|
|
|
// maybe MPV can go over to the preferred device once it is plugged in?
|
2014-11-17 11:37:51 +00:00
|
|
|
static HRESULT STDMETHODCALLTYPE sIMMNotificationClient_OnDeviceRemoved(
|
|
|
|
IMMNotificationClient *This,
|
|
|
|
LPCWSTR pwstrDeviceId)
|
|
|
|
{
|
|
|
|
change_notify *change = (change_notify *)This;
|
2014-11-13 09:09:47 +00:00
|
|
|
struct ao *ao = change->ao;
|
2014-11-17 11:37:51 +00:00
|
|
|
|
2015-03-31 08:56:17 +00:00
|
|
|
if (change->is_hotplug) {
|
|
|
|
MP_VERBOSE(ao, "OnDeviceRemoved triggered: sending hotplug event\n");
|
|
|
|
ao_hotplug_event(ao);
|
2015-08-01 18:51:52 +00:00
|
|
|
} else if (pwstrDeviceId && !wcscmp(pwstrDeviceId, change->monitored)) {
|
2017-04-20 05:38:03 +00:00
|
|
|
MP_VERBOSE(ao, "OnDeviceRemoved triggered for device %ls: "
|
2015-03-31 08:56:17 +00:00
|
|
|
"requesting ao reload\n", pwstrDeviceId);
|
2014-11-13 09:09:47 +00:00
|
|
|
ao_request_reload(ao);
|
2014-11-17 11:37:51 +00:00
|
|
|
}
|
2015-03-31 08:56:17 +00:00
|
|
|
|
2014-11-17 11:37:51 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE sIMMNotificationClient_OnDefaultDeviceChanged(
|
|
|
|
IMMNotificationClient *This,
|
|
|
|
EDataFlow flow,
|
|
|
|
ERole role,
|
|
|
|
LPCWSTR pwstrDeviceId)
|
|
|
|
{
|
|
|
|
change_notify *change = (change_notify *)This;
|
2014-11-13 09:09:47 +00:00
|
|
|
struct ao *ao = change->ao;
|
|
|
|
|
2015-12-21 00:43:23 +00:00
|
|
|
// don't care about "eCapture" or non-"eMultimedia" roles
|
2015-01-02 22:26:08 +00:00
|
|
|
if (flow == eCapture || role != eMultimedia) return S_OK;
|
2014-11-17 11:37:51 +00:00
|
|
|
|
2015-03-31 08:56:17 +00:00
|
|
|
if (change->is_hotplug) {
|
2015-12-21 00:43:23 +00:00
|
|
|
MP_VERBOSE(ao,
|
|
|
|
"OnDefaultDeviceChanged triggered: sending hotplug event\n");
|
2015-03-31 08:56:17 +00:00
|
|
|
ao_hotplug_event(ao);
|
|
|
|
} else {
|
2015-12-21 00:43:23 +00:00
|
|
|
// stay on the device the user specified
|
2016-01-23 05:35:51 +00:00
|
|
|
bstr device = wasapi_get_specified_device_string(ao);
|
|
|
|
if (device.len) {
|
2015-03-31 08:56:17 +00:00
|
|
|
MP_VERBOSE(ao, "OnDefaultDeviceChanged triggered: "
|
2016-01-23 05:35:51 +00:00
|
|
|
"staying on specified device %.*s\n", BSTR_P(device));
|
2015-03-31 08:56:17 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
2014-11-13 09:09:47 +00:00
|
|
|
|
2015-12-21 00:43:23 +00:00
|
|
|
// don't reload if already on the new default
|
2015-08-01 18:51:52 +00:00
|
|
|
if (pwstrDeviceId && !wcscmp(pwstrDeviceId, change->monitored)) {
|
2015-03-31 08:56:17 +00:00
|
|
|
MP_VERBOSE(ao, "OnDefaultDeviceChanged triggered: "
|
|
|
|
"already using default device, no reload required\n");
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-12-21 00:43:23 +00:00
|
|
|
// if we got here, we need to reload
|
|
|
|
MP_VERBOSE(ao,
|
|
|
|
"OnDefaultDeviceChanged triggered: requesting ao reload\n");
|
2015-03-31 08:56:17 +00:00
|
|
|
ao_request_reload(ao);
|
2014-11-13 09:09:47 +00:00
|
|
|
}
|
|
|
|
|
2014-11-17 11:37:51 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE sIMMNotificationClient_OnPropertyValueChanged(
|
|
|
|
IMMNotificationClient *This,
|
|
|
|
LPCWSTR pwstrDeviceId,
|
|
|
|
const PROPERTYKEY key)
|
|
|
|
{
|
|
|
|
change_notify *change = (change_notify *)This;
|
2014-11-13 09:09:47 +00:00
|
|
|
struct ao *ao = change->ao;
|
|
|
|
|
2015-03-31 08:56:17 +00:00
|
|
|
if (!change->is_hotplug && pwstrDeviceId &&
|
2015-08-01 18:51:52 +00:00
|
|
|
!wcscmp(pwstrDeviceId, change->monitored))
|
2015-03-31 08:56:17 +00:00
|
|
|
{
|
2017-04-20 05:38:03 +00:00
|
|
|
MP_VERBOSE(ao, "OnPropertyValueChanged triggered on device %ls\n",
|
2015-03-31 08:56:17 +00:00
|
|
|
pwstrDeviceId);
|
2015-01-02 22:26:08 +00:00
|
|
|
if (IsEqualPropertyKey(PKEY_AudioEngine_DeviceFormat, key)) {
|
2014-11-13 09:09:47 +00:00
|
|
|
MP_VERBOSE(change->ao,
|
2015-03-31 08:56:17 +00:00
|
|
|
"Changed property: PKEY_AudioEngine_DeviceFormat "
|
|
|
|
"- requesting ao reload\n");
|
2014-11-13 09:09:47 +00:00
|
|
|
ao_request_reload(change->ao);
|
|
|
|
} else {
|
2015-03-31 08:56:17 +00:00
|
|
|
MP_VERBOSE(ao, "Changed property: %s\n", mp_PKEY_to_str(&key));
|
2014-11-13 09:09:47 +00:00
|
|
|
}
|
2014-11-17 11:37:51 +00:00
|
|
|
}
|
2015-03-31 08:56:17 +00:00
|
|
|
|
2014-11-17 11:37:51 +00:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2015-12-29 09:13:50 +00:00
|
|
|
static CONST_VTBL IMMNotificationClientVtbl sIMMNotificationClientVtbl = {
|
2014-11-17 11:37:51 +00:00
|
|
|
.QueryInterface = sIMMNotificationClient_QueryInterface,
|
|
|
|
.AddRef = sIMMNotificationClient_AddRef,
|
|
|
|
.Release = sIMMNotificationClient_Release,
|
|
|
|
.OnDeviceStateChanged = sIMMNotificationClient_OnDeviceStateChanged,
|
|
|
|
.OnDeviceAdded = sIMMNotificationClient_OnDeviceAdded,
|
|
|
|
.OnDeviceRemoved = sIMMNotificationClient_OnDeviceRemoved,
|
|
|
|
.OnDefaultDeviceChanged = sIMMNotificationClient_OnDefaultDeviceChanged,
|
|
|
|
.OnPropertyValueChanged = sIMMNotificationClient_OnPropertyValueChanged,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2015-03-31 08:56:17 +00:00
|
|
|
HRESULT wasapi_change_init(struct ao *ao, bool is_hotplug)
|
2014-11-13 09:09:47 +00:00
|
|
|
{
|
2015-03-31 21:12:24 +00:00
|
|
|
struct wasapi_state *state = ao->priv;
|
2014-11-13 09:09:47 +00:00
|
|
|
struct change_notify *change = &state->change;
|
2015-12-29 09:13:17 +00:00
|
|
|
HRESULT hr = CoCreateInstance(&CLSID_MMDeviceEnumerator, NULL, CLSCTX_ALL,
|
|
|
|
&IID_IMMDeviceEnumerator,
|
|
|
|
(void **)&change->pEnumerator);
|
|
|
|
EXIT_ON_ERROR(hr);
|
|
|
|
|
2015-12-21 00:43:23 +00:00
|
|
|
// so the callbacks can access the ao
|
2015-03-31 08:56:17 +00:00
|
|
|
change->ao = ao;
|
|
|
|
|
2015-12-21 00:43:23 +00:00
|
|
|
// whether or not this is the hotplug instance
|
2015-03-31 08:56:17 +00:00
|
|
|
change->is_hotplug = is_hotplug;
|
|
|
|
|
|
|
|
if (is_hotplug) {
|
|
|
|
MP_DBG(ao, "Monitoring for hotplug events\n");
|
|
|
|
} else {
|
2015-12-21 00:43:23 +00:00
|
|
|
// Get the device string to compare with the pwstrDeviceId
|
2015-12-29 11:13:52 +00:00
|
|
|
change->monitored = state->deviceID;
|
2017-04-20 05:38:03 +00:00
|
|
|
MP_VERBOSE(ao, "Monitoring changes in device %ls\n", change->monitored);
|
2015-03-31 08:56:17 +00:00
|
|
|
}
|
|
|
|
|
2017-04-20 05:33:13 +00:00
|
|
|
// COM voodoo to emulate c++ class
|
|
|
|
change->client.lpVtbl = &sIMMNotificationClientVtbl;
|
|
|
|
|
|
|
|
// register the change notification client
|
|
|
|
hr = IMMDeviceEnumerator_RegisterEndpointNotificationCallback(
|
|
|
|
change->pEnumerator, (IMMNotificationClient *)change);
|
|
|
|
EXIT_ON_ERROR(hr);
|
|
|
|
|
2014-11-13 09:09:47 +00:00
|
|
|
return hr;
|
|
|
|
exit_label:
|
|
|
|
MP_ERR(state, "Error setting up device change monitoring: %s\n",
|
2015-04-01 09:20:12 +00:00
|
|
|
mp_HRESULT_to_str(hr));
|
2014-11-13 09:09:47 +00:00
|
|
|
wasapi_change_uninit(ao);
|
|
|
|
return hr;
|
2014-11-17 11:37:51 +00:00
|
|
|
}
|
|
|
|
|
2014-11-13 09:09:47 +00:00
|
|
|
void wasapi_change_uninit(struct ao *ao)
|
2014-11-17 11:37:51 +00:00
|
|
|
{
|
2015-03-31 21:12:24 +00:00
|
|
|
struct wasapi_state *state = ao->priv;
|
2014-11-13 09:09:47 +00:00
|
|
|
struct change_notify *change = &state->change;
|
|
|
|
|
2015-12-29 09:13:17 +00:00
|
|
|
if (change->pEnumerator && change->client.lpVtbl) {
|
2014-11-13 09:09:47 +00:00
|
|
|
IMMDeviceEnumerator_UnregisterEndpointNotificationCallback(
|
2015-12-29 09:13:17 +00:00
|
|
|
change->pEnumerator, (IMMNotificationClient *)change);
|
2015-03-26 12:52:34 +00:00
|
|
|
}
|
2014-11-13 09:09:47 +00:00
|
|
|
|
2017-01-29 12:59:24 +00:00
|
|
|
SAFE_RELEASE(change->pEnumerator);
|
2014-11-17 11:37:51 +00:00
|
|
|
}
|