#include <stdlib.h>
#include <assert.h>
#include <audioclient.h>
-#include <mmdeviceapi.h>
#include <vlc_common.h>
#include <vlc_aout.h>
return (d.quot * 10000000) + ((d.rem * 10000000) / freq.QuadPart);
}
-static void Enter(void)
-{
- HRESULT hr = CoInitializeEx(NULL, COINIT_MULTITHREADED);
- if (unlikely(FAILED(hr)))
- abort();
-}
-
-static void Leave(void)
-{
- CoUninitialize();
-}
-
typedef struct aout_stream_sys
{
IAudioClient *client;
uint8_t chans_table[AOUT_CHAN_MAX];
uint8_t chans_to_reorder;
- uint8_t bits; /**< Bits per sample */
+ vlc_fourcc_t format; /**< Sample format */
unsigned rate; /**< Sample rate */
unsigned bytes_per_frame;
UINT32 written; /**< Frames written to the buffer */
if (sys->chans_to_reorder)
aout_ChannelReorder(block->p_buffer, block->i_buffer,
- sys->chans_to_reorder, sys->chans_table, sys->bits);
+ sys->chans_to_reorder, sys->chans_table, sys->format);
hr = IAudioClient_GetService(sys->client, &IID_IAudioRenderClient, &pv);
if (FAILED(hr))
wf->SubFormat = KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
break;
- case VLC_CODEC_S8:
case VLC_CODEC_U8:
audio->i_format = VLC_CODEC_S16N;
case VLC_CODEC_S16N:
}
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))
sys->client = NULL;
void *pv;
- HRESULT hr;
-
- Enter();
- hr = IMMDevice_Activate(dev, &IID_IAudioClient, CLSCTX_ALL, NULL, &pv);
- Leave();
+ HRESULT hr = aout_stream_Activate(s, &IID_IAudioClient, NULL, &pv);
if (FAILED(hr))
{
msg_Err(s, "cannot activate client (error 0x%lx)", hr);
sys->chans_to_reorder = vlc_CheckWaveOrder((hr == S_OK) ? &wf.Format : pwf,
sys->chans_table);
- sys->bits = fmt->i_bitspersample;
+ sys->format = fmt->i_format;
hr = IAudioClient_Initialize(sys->client, AUDCLNT_SHAREMODE_SHARED, 0,
AOUT_MAX_PREPARE_TIME * 10, 0,
IAudioClient_Release(sys->client);
}
-#undef aout_stream_Start
-aout_stream_t *aout_stream_Start(vlc_object_t *parent,
- audio_sample_format_t *restrict fmt,
- IMMDevice *dev, const GUID *sid)
+HRESULT aout_stream_Start(aout_stream_t *s,
+ audio_sample_format_t *restrict fmt, const GUID *sid)
{
- aout_stream_t *s = vlc_object_create(parent, sizeof (*s));
- if (unlikely(s == NULL))
- return NULL;
-
- HRESULT hr = Start(s, fmt, dev, sid);
- if (FAILED(hr))
- {
- vlc_object_release(s);
- s = NULL;
- }
- return s;
+ return Start(s, fmt, sid);
}
void aout_stream_Stop(aout_stream_t *s)
{
Stop(s);
- vlc_object_release(s);
}