2014-03-09 23:13:36 +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-03-09 23:13:36 +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-03-09 23:13:36 +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-03-09 23:13:36 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MP_AO_WASAPI_H_
|
|
|
|
#define MP_AO_WASAPI_H_
|
|
|
|
|
2016-01-05 03:47:38 +00:00
|
|
|
#include <stdlib.h>
|
2015-03-31 08:56:17 +00:00
|
|
|
#include <stdbool.h>
|
2016-01-05 03:47:38 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <mmdeviceapi.h>
|
2014-03-09 23:13:36 +00:00
|
|
|
#include <audioclient.h>
|
2014-03-11 06:46:22 +00:00
|
|
|
#include <audiopolicy.h>
|
2016-01-05 03:47:38 +00:00
|
|
|
#include <endpointvolume.h>
|
2014-03-09 23:13:36 +00:00
|
|
|
|
2016-01-05 03:47:38 +00:00
|
|
|
#include "common/msg.h"
|
2016-09-07 09:26:25 +00:00
|
|
|
#include "osdep/atomic.h"
|
2016-01-11 13:39:19 +00:00
|
|
|
#include "osdep/windows_utils.h"
|
2016-01-05 03:47:38 +00:00
|
|
|
#include "internal.h"
|
|
|
|
#include "ao.h"
|
2014-05-20 23:04:47 +00:00
|
|
|
|
2014-11-17 11:37:51 +00:00
|
|
|
typedef struct change_notify {
|
2015-12-21 00:43:23 +00:00
|
|
|
IMMNotificationClient client; // this must be first in the structure!
|
2015-12-29 09:13:17 +00:00
|
|
|
IMMDeviceEnumerator *pEnumerator; // object where client is registered
|
2015-12-21 00:43:23 +00:00
|
|
|
LPWSTR monitored; // Monitored device
|
2015-03-31 08:56:17 +00:00
|
|
|
bool is_hotplug;
|
2014-11-13 09:09:47 +00:00
|
|
|
struct ao *ao;
|
2014-11-17 11:37:51 +00:00
|
|
|
} change_notify;
|
|
|
|
|
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
|
|
|
void wasapi_change_uninit(struct ao* ao);
|
|
|
|
|
|
|
|
#define EXIT_ON_ERROR(hres) \
|
|
|
|
do { if (FAILED(hres)) { goto exit_label; } } while(0)
|
|
|
|
#define SAFE_RELEASE(unk, release) \
|
|
|
|
do { if ((unk) != NULL) { release; (unk) = NULL; } } while(0)
|
2014-11-17 11:37:51 +00:00
|
|
|
|
2016-11-30 16:44:59 +00:00
|
|
|
#define mp_format_res_str(hres) \
|
|
|
|
(SUCCEEDED(hres) ? "ok" : ((hres) == AUDCLNT_E_UNSUPPORTED_FORMAT) \
|
|
|
|
? "unsupported" : mp_HRESULT_to_str(hres))
|
|
|
|
|
2015-03-29 00:12:48 +00:00
|
|
|
enum wasapi_thread_state {
|
|
|
|
WASAPI_THREAD_FEED = 0,
|
|
|
|
WASAPI_THREAD_RESUME,
|
|
|
|
WASAPI_THREAD_RESET,
|
|
|
|
WASAPI_THREAD_SHUTDOWN
|
|
|
|
};
|
|
|
|
|
2014-03-09 23:13:36 +00:00
|
|
|
typedef struct wasapi_state {
|
|
|
|
struct mp_log *log;
|
|
|
|
|
2015-12-21 02:19:12 +00:00
|
|
|
// Thread handles
|
|
|
|
HRESULT init_ret; // status of init phase
|
|
|
|
HANDLE hInitDone; // set when init is complete in audio thread
|
|
|
|
HANDLE hAudioThread; // the audio thread itself
|
|
|
|
HANDLE hWake; // thread wakeup event
|
|
|
|
atomic_int thread_state; // enum wasapi_thread_state (what to do on wakeup)
|
2016-02-26 14:58:09 +00:00
|
|
|
struct mp_dispatch_queue *dispatch; // for volume/mute/session display
|
2014-03-09 23:13:36 +00:00
|
|
|
|
2015-12-21 02:19:12 +00:00
|
|
|
// for setting the audio thread priority
|
|
|
|
HANDLE hTask;
|
|
|
|
|
2015-12-26 20:57:16 +00:00
|
|
|
// ID of the device to use
|
|
|
|
LPWSTR deviceID;
|
2015-12-21 02:19:12 +00:00
|
|
|
// WASAPI object handles owned and used by audio thread
|
2014-03-09 23:13:36 +00:00
|
|
|
IMMDevice *pDevice;
|
|
|
|
IAudioClient *pAudioClient;
|
|
|
|
IAudioRenderClient *pRenderClient;
|
2014-11-13 09:09:47 +00:00
|
|
|
|
2015-12-21 02:19:12 +00:00
|
|
|
// WASAPI internal clock information, for estimating delay
|
|
|
|
IAudioClock *pAudioClock;
|
|
|
|
atomic_ullong sample_count; // samples per channel written by GetBuffer
|
|
|
|
UINT64 clock_frequency; // scale for position returned by GetPosition
|
|
|
|
LARGE_INTEGER qpc_frequency; // frequency of Windows' high resolution timer
|
|
|
|
|
2016-02-26 14:58:09 +00:00
|
|
|
// WASAPI control
|
2015-12-21 02:19:12 +00:00
|
|
|
IAudioSessionControl *pSessionControl; // setting the stream title
|
|
|
|
IAudioEndpointVolume *pEndpointVolume; // exclusive mode volume/mute
|
|
|
|
ISimpleAudioVolume *pAudioVolume; // shared mode volume/mute
|
|
|
|
DWORD vol_hw_support; // is hardware volume supported for exclusive-mode?
|
|
|
|
|
|
|
|
// ao options
|
2014-03-09 23:13:36 +00:00
|
|
|
int opt_exclusive;
|
|
|
|
|
2015-12-21 02:19:12 +00:00
|
|
|
// format info
|
2015-03-27 23:48:39 +00:00
|
|
|
WAVEFORMATEXTENSIBLE format;
|
2015-12-21 02:19:12 +00:00
|
|
|
AUDCLNT_SHAREMODE share_mode; // AUDCLNT_SHAREMODE_EXCLUSIVE / SHARED
|
|
|
|
UINT32 bufferFrameCount; // number of frames in buffer
|
2015-03-27 23:48:39 +00:00
|
|
|
|
2014-11-13 09:09:47 +00:00
|
|
|
change_notify change;
|
2014-03-09 23:13:36 +00:00
|
|
|
} wasapi_state;
|
|
|
|
|
2016-01-05 03:47:38 +00:00
|
|
|
char *mp_PKEY_to_str_buf(char *buf, size_t buf_size, const PROPERTYKEY *pkey);
|
|
|
|
#define mp_PKEY_to_str(pkey) mp_PKEY_to_str_buf((char[42]){0}, 42, (pkey))
|
|
|
|
|
|
|
|
void wasapi_list_devs(struct ao *ao, struct ao_device_list *list);
|
2016-01-23 05:35:51 +00:00
|
|
|
bstr wasapi_get_specified_device_string(struct ao *ao);
|
2016-01-28 08:45:38 +00:00
|
|
|
LPWSTR wasapi_find_deviceID(struct ao *ao);
|
2016-01-05 03:47:38 +00:00
|
|
|
|
|
|
|
void wasapi_dispatch(struct ao *ao);
|
|
|
|
HRESULT wasapi_thread_init(struct ao *ao);
|
|
|
|
void wasapi_thread_uninit(struct ao *ao);
|
|
|
|
|
|
|
|
void wasapi_receive_proxies(wasapi_state *state);
|
|
|
|
void wasapi_release_proxies(wasapi_state *state);
|
|
|
|
|
2014-03-11 03:47:33 +00:00
|
|
|
#endif
|