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

mmdevice: deal with invalidated device in Start()

parent c242a515
...@@ -597,16 +597,25 @@ static void CloseDevice(audio_output_t *aout) ...@@ -597,16 +597,25 @@ static void CloseDevice(audio_output_t *aout)
static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt) static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
{ {
aout_sys_t *sys = aout->sys; aout_sys_t *sys = aout->sys;
HRESULT hr;
assert (sys->stream == NULL); assert (sys->stream == NULL);
if (sys->dev == NULL) if (sys->dev == NULL)
return -1; return -1;
aout_stream_t *s = vlc_object_create(aout, sizeof (*s));
if (unlikely(s == NULL))
return -1;
EnterMTA(); EnterMTA();
sys->stream = aout_stream_Start(aout, fmt, sys->dev, &GUID_VLC_AUD_OUT); hr = aout_stream_Start(s, fmt, sys->dev, &GUID_VLC_AUD_OUT);
if (SUCCEEDED(hr))
sys->stream = s;
else
vlc_object_release(s);
LeaveMTA(); LeaveMTA();
return (sys->stream != NULL) ? 0 : -1; return vlc_FromHR(aout, hr);
} }
static void Stop(audio_output_t *aout) static void Stop(audio_output_t *aout)
...@@ -619,6 +628,7 @@ static void Stop(audio_output_t *aout) ...@@ -619,6 +628,7 @@ static void Stop(audio_output_t *aout)
aout_stream_Stop(sys->stream); aout_stream_Stop(sys->stream);
LeaveMTA(); LeaveMTA();
vlc_object_release(sys->stream);
sys->stream = NULL; sys->stream = NULL;
} }
......
...@@ -39,15 +39,13 @@ struct aout_stream ...@@ -39,15 +39,13 @@ struct aout_stream
/** /**
* Creates an audio output stream on a given Windows multimedia device. * Creates an audio output stream on a given Windows multimedia device.
* \param parent parent VLC object * \param s audio output stream object to be initialized
* \param fmt audio output sample format [IN/OUT] * \param fmt audio output sample format [IN/OUT]
* \param dev audio output device * \param dev MMDevice API output device
* \param sid audio output session GUID [IN] * \param sid audio output session GUID [IN]
*/ */
aout_stream_t *aout_stream_Start(vlc_object_t *parent, HRESULT aout_stream_Start(aout_stream_t *s, audio_sample_format_t *fmt,
audio_sample_format_t *fmt, IMMDevice *dev, const GUID *sid);
IMMDevice *dev, const GUID *sid);
#define aout_stream_Start(o,f,d,s) aout_stream_Start(VLC_OBJECT(o),f,d,s)
/** /**
* Destroys an audio output stream. * Destroys an audio output stream.
......
...@@ -403,26 +403,14 @@ static void Stop(aout_stream_t *s) ...@@ -403,26 +403,14 @@ static void Stop(aout_stream_t *s)
IAudioClient_Release(sys->client); IAudioClient_Release(sys->client);
} }
#undef aout_stream_Start HRESULT aout_stream_Start(aout_stream_t *s,
aout_stream_t *aout_stream_Start(vlc_object_t *parent, audio_sample_format_t *restrict fmt,
audio_sample_format_t *restrict fmt, IMMDevice *dev, const GUID *sid)
IMMDevice *dev, const GUID *sid)
{ {
aout_stream_t *s = vlc_object_create(parent, sizeof (*s)); return Start(s, fmt, dev, sid);
if (unlikely(s == NULL))
return NULL;
HRESULT hr = Start(s, fmt, dev, sid);
if (FAILED(hr))
{
vlc_object_release(s);
s = NULL;
}
return s;
} }
void aout_stream_Stop(aout_stream_t *s) void aout_stream_Stop(aout_stream_t *s)
{ {
Stop(s); Stop(s);
vlc_object_release(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