summaryrefslogtreecommitdiffstats
path: root/audio/out/ao_wasapi.h
diff options
context:
space:
mode:
Diffstat (limited to 'audio/out/ao_wasapi.h')
-rw-r--r--[-rwxr-xr-x]audio/out/ao_wasapi.h112
1 files changed, 64 insertions, 48 deletions
diff --git a/audio/out/ao_wasapi.h b/audio/out/ao_wasapi.h
index 2fbd2d5a9c..5ba2aa325c 100755..100644
--- a/audio/out/ao_wasapi.h
+++ b/audio/out/ao_wasapi.h
@@ -20,17 +20,24 @@
#ifndef MP_AO_WASAPI_H_
#define MP_AO_WASAPI_H_
+#include <stdlib.h>
#include <stdbool.h>
+#include <windows.h>
+#include <mmdeviceapi.h>
#include <audioclient.h>
#include <audiopolicy.h>
-#include <mmdeviceapi.h>
-#include <avrt.h>
+#include <endpointvolume.h>
+#include "common/msg.h"
#include "osdep/atomics.h"
+#include "osdep/windows_utils.h"
+#include "internal.h"
+#include "ao.h"
typedef struct change_notify {
- IMMNotificationClient client; /* this must be first in the structure! */
- LPWSTR monitored; /* Monitored device */
+ IMMNotificationClient client; // this must be first in the structure!
+ IMMDeviceEnumerator *pEnumerator; // object where client is registered
+ LPWSTR monitored; // Monitored device
bool is_hotplug;
struct ao *ao;
} change_notify;
@@ -52,64 +59,73 @@ enum wasapi_thread_state {
typedef struct wasapi_state {
struct mp_log *log;
- /* Init phase */
- HRESULT init_ret;
- HANDLE hInitDone;
- int share_mode;
-
- /* volume control */
- DWORD vol_hw_support;
- float audio_volume;
- float previous_volume;
- float initial_volume;
-
- /* WASAPI handles, owned by audio thread */
- IMMDevice *pDevice;
- IAudioClient *pAudioClient;
- IAudioRenderClient *pRenderClient;
- ISimpleAudioVolume *pAudioVolume;
- IAudioEndpointVolume *pEndpointVolume;
- IAudioSessionControl *pSessionControl;
- IMMDeviceEnumerator *pEnumerator;
- /* thread handles */
- HANDLE hAudioThread; /* the thread itself */
- HANDLE hWake; /* thread wakeup event */
- atomic_int thread_state; /* enum wasapi_thread_state */
+ // 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)
- /* for setting the audio thread priority */
- HANDLE hTask; /* AV thread */
+ // for setting the audio thread priority
+ HANDLE hTask;
- /* WASAPI proxy handles, for Single-Threaded Apartment communication.
- One is needed for each audio thread object that's accessed from the main thread. */
- ISimpleAudioVolume *pAudioVolumeProxy;
- IAudioEndpointVolume *pEndpointVolumeProxy;
- IAudioSessionControl *pSessionControlProxy;
+ // ID of the device to use
+ LPWSTR deviceID;
+ // WASAPI object handles owned and used by audio thread
+ IMMDevice *pDevice;
+ IAudioClient *pAudioClient;
+ IAudioRenderClient *pRenderClient;
- /* Streams used to marshal the proxy objects. The thread owning the actual objects
- needs to marshal proxy objects into these streams, and the thread that wants the
- proxies unmarshals them from here. */
- IStream *sAudioVolume;
- IStream *sEndpointVolume;
+ // 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
+
+ // WASAPI control (handles owned by audio thread but used by main thread)
+ 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?
+
+ // Streams used to marshal the proxy objects. The thread owning the actual
+ // objects needs to marshal proxy objects into these streams, and the thread
+ // that wants the proxies unmarshals them from here.
IStream *sSessionControl;
+ IStream *sEndpointVolume;
+ IStream *sAudioVolume;
- /* WASAPI internal clock information, for estimating delay */
- IAudioClock *pAudioClock;
- UINT64 clock_frequency; /* scale for the "samples" returned by the clock */
- atomic_ullong sample_count; /* the amount of samples per channel written to a GetBuffer buffer */
- LARGE_INTEGER qpc_frequency; /* frequency of windows' high resolution timer */
+ // WASAPI proxy handles, for Single-Threaded Apartment communication. One is
+ // needed for each audio thread object that's accessed from the main thread.
+ IAudioSessionControl *pSessionControlProxy;
+ IAudioEndpointVolume *pEndpointVolumeProxy;
+ ISimpleAudioVolume *pAudioVolumeProxy;
- /* ao options */
+ // ao options
int opt_exclusive;
int opt_list;
char *opt_device;
- /* format info */
+ // format info
WAVEFORMATEXTENSIBLE format;
- size_t buffer_block_size; /* Size of each block in bytes */
- UINT32 bufferFrameCount; /* wasapi buffer block size, number of frames, frame size at format.nBlockAlign */
+ AUDCLNT_SHAREMODE share_mode; // AUDCLNT_SHAREMODE_EXCLUSIVE / SHARED
+ UINT32 bufferFrameCount; // number of frames in buffer
change_notify change;
} wasapi_state;
+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);
+LPWSTR find_deviceID(struct ao *ao);
+
+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);
+
#endif