Commit a715eaa0 authored by Thomas Guillem's avatar Thomas Guillem

mmdevice: fix opening of invalid device

CD 6f95511a-91a2-45de-bd43-735bf52a2185

And check sys->dev locked since it can be written from the MMSession thread.
parent 9c146272
......@@ -1081,9 +1081,6 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
{
aout_sys_t *sys = aout->sys;
if (sys->dev == NULL)
return -1;
const bool b_spdif = AOUT_FMT_SPDIF(fmt);
const bool b_hdmi = AOUT_FMT_HDMI(fmt);
if (b_spdif || b_hdmi)
......@@ -1111,6 +1108,14 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
EnterMTA();
EnterCriticalSection(&sys->lock);
if (sys->dev == NULL)
{
LeaveCriticalSection(&sys->lock);
LeaveMTA();
return -1;
}
for (;;)
{
char *modlist = var_InheritString(aout, "mmdevice-backend");
......@@ -1146,25 +1151,28 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
break;
}
IPropertyStore *props;
HRESULT hr = IMMDevice_OpenPropertyStore(sys->dev, STGM_READ, &props);
if (SUCCEEDED(hr))
if (sys->module != NULL)
{
PROPVARIANT v;
PropVariantInit(&v);
hr = IPropertyStore_GetValue(props, &PKEY_AudioEndpoint_FormFactor, &v);
IPropertyStore *props;
HRESULT hr = IMMDevice_OpenPropertyStore(sys->dev, STGM_READ, &props);
if (SUCCEEDED(hr))
{
switch (v.uintVal)
PROPVARIANT v;
PropVariantInit(&v);
hr = IPropertyStore_GetValue(props, &PKEY_AudioEndpoint_FormFactor, &v);
if (SUCCEEDED(hr))
{
case Headphones:
case Headset:
aout->current_sink_info.headphones = true;
break;
switch (v.uintVal)
{
case Headphones:
case Headset:
aout->current_sink_info.headphones = true;
break;
}
PropVariantClear(&v);
}
PropVariantClear(&v);
IPropertyStore_Release(props);
}
IPropertyStore_Release(props);
}
LeaveCriticalSection(&sys->lock);
......
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