Commit f8c07e70 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

wasapi: remove direct dependency on desktop-only IMMDevice

parent 4a1c30a0
......@@ -618,6 +618,18 @@ static void CloseDevice(audio_output_t *aout)
sys->dev = NULL;
}
/**
* Callback for aout_stream_t to create a stream on the device.
* This can instantiate an IAudioClient or IDirectSound(8) object.
*/
static HRESULT ActivateDevice(void *opaque, REFIID iid, PROPVARIANT *actparms,
void **restrict pv)
{
IMMDevice *dev = opaque;
return IMMDevice_Activate(dev, iid, CLSCTX_ALL, actparms, pv);
}
static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
{
aout_sys_t *sys = aout->sys;
......@@ -631,8 +643,11 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
if (unlikely(s == NULL))
return -1;
s->owner.device = sys->dev;
s->owner.activate = ActivateDevice;
EnterMTA();
hr = aout_stream_Start(s, fmt, sys->dev, &GUID_VLC_AUD_OUT);
hr = aout_stream_Start(s, fmt, &GUID_VLC_AUD_OUT);
if (SUCCEEDED(hr))
sys->stream = s;
else
......
......@@ -35,17 +35,22 @@ struct aout_stream
HRESULT (*play)(aout_stream_t *, block_t *);
HRESULT (*pause)(aout_stream_t *, bool);
HRESULT (*flush)(aout_stream_t *);
struct
{
void *device;
HRESULT (*activate)(void *device, REFIID, PROPVARIANT *, void **);
} owner;
};
/**
* Creates an audio output stream on a given Windows multimedia device.
* \param s audio output stream object to be initialized
* \param fmt audio output sample format [IN/OUT]
* \param dev MMDevice API output device
* \param sid audio output session GUID [IN]
*/
HRESULT aout_stream_Start(aout_stream_t *s, audio_sample_format_t *fmt,
IMMDevice *dev, const GUID *sid);
const GUID *sid);
/**
* Destroys an audio output stream.
......@@ -71,4 +76,11 @@ static inline HRESULT aout_stream_Flush(aout_stream_t *s)
{
return (s->flush)(s);
}
static inline
HRESULT aout_stream_Activate(aout_stream_t *s, REFIID iid,
PROPVARIANT *actparms, void **pv)
{
return s->owner.activate(s->owner.device, iid, actparms, pv);
}
#endif
......@@ -29,7 +29,6 @@
#include <stdlib.h>
#include <assert.h>
#include <audioclient.h>
#include <mmdeviceapi.h>
#include <vlc_common.h>
#include <vlc_aout.h>
......@@ -312,7 +311,7 @@ static unsigned vlc_CheckWaveOrder (const WAVEFORMATEX *restrict wf,
}
static HRESULT Start(aout_stream_t *s, audio_sample_format_t *restrict fmt,
IMMDevice *dev, const GUID *sid)
const GUID *sid)
{
aout_stream_sys_t *sys = malloc(sizeof (*sys));
if (unlikely(sys == NULL))
......@@ -320,9 +319,7 @@ static HRESULT Start(aout_stream_t *s, audio_sample_format_t *restrict fmt,
sys->client = NULL;
void *pv;
HRESULT hr;
hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_ALL, NULL, &pv);
HRESULT hr = aout_stream_Activate(s, &IID_IAudioClient, NULL, &pv);
if (FAILED(hr))
{
msg_Err(s, "cannot activate client (error 0x%lx)", hr);
......@@ -404,10 +401,9 @@ static void Stop(aout_stream_t *s)
}
HRESULT aout_stream_Start(aout_stream_t *s,
audio_sample_format_t *restrict fmt,
IMMDevice *dev, const GUID *sid)
audio_sample_format_t *restrict fmt, const GUID *sid)
{
return Start(s, fmt, dev, sid);
return Start(s, fmt, sid);
}
void aout_stream_Stop(aout_stream_t *s)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment