[vlc-commits] mmdevice: deal with invalidated device in Start()

Rémi Denis-Courmont git at videolan.org
Thu Dec 6 10:16:31 CET 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Dec  6 11:16:14 2012 +0200| [7697d8b299e94bc8370b05da056a450bf96e3535] | committer: Rémi Denis-Courmont

mmdevice: deal with invalidated device in Start()

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7697d8b299e94bc8370b05da056a450bf96e3535
---

 modules/audio_output/mmdevice.c |   14 ++++++++++++--
 modules/audio_output/mmdevice.h |   10 ++++------
 modules/audio_output/wasapi.c   |   20 ++++----------------
 3 files changed, 20 insertions(+), 24 deletions(-)

diff --git a/modules/audio_output/mmdevice.c b/modules/audio_output/mmdevice.c
index 8a321a0..258e99b 100644
--- a/modules/audio_output/mmdevice.c
+++ b/modules/audio_output/mmdevice.c
@@ -597,16 +597,25 @@ static void CloseDevice(audio_output_t *aout)
 static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
 {
     aout_sys_t *sys = aout->sys;
+    HRESULT hr;
 
     assert (sys->stream == NULL);
     if (sys->dev == NULL)
         return -1;
 
+    aout_stream_t *s = vlc_object_create(aout, sizeof (*s));
+    if (unlikely(s == NULL))
+        return -1;
+
     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();
 
-    return (sys->stream != NULL) ? 0 : -1;
+    return vlc_FromHR(aout, hr);
 }
 
 static void Stop(audio_output_t *aout)
@@ -619,6 +628,7 @@ static void Stop(audio_output_t *aout)
     aout_stream_Stop(sys->stream);
     LeaveMTA();
 
+    vlc_object_release(sys->stream);
     sys->stream = NULL;
 }
 
diff --git a/modules/audio_output/mmdevice.h b/modules/audio_output/mmdevice.h
index 2736514..0ba36f1 100644
--- a/modules/audio_output/mmdevice.h
+++ b/modules/audio_output/mmdevice.h
@@ -39,15 +39,13 @@ struct aout_stream
 
 /**
  * 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 dev audio output device
+ * \param dev MMDevice API output device
  * \param sid audio output session GUID [IN]
  */
-aout_stream_t *aout_stream_Start(vlc_object_t *parent,
-                                 audio_sample_format_t *fmt,
-                                 IMMDevice *dev, const GUID *sid);
-#define aout_stream_Start(o,f,d,s) aout_stream_Start(VLC_OBJECT(o),f,d,s)
+HRESULT aout_stream_Start(aout_stream_t *s, audio_sample_format_t *fmt,
+                          IMMDevice *dev, const GUID *sid);
 
 /**
  * Destroys an audio output stream.
diff --git a/modules/audio_output/wasapi.c b/modules/audio_output/wasapi.c
index 5cdeea1..14672be 100644
--- a/modules/audio_output/wasapi.c
+++ b/modules/audio_output/wasapi.c
@@ -403,26 +403,14 @@ static void Stop(aout_stream_t *s)
     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,
+                          IMMDevice *dev, 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, dev, sid);
 }
 
 void aout_stream_Stop(aout_stream_t *s)
 {
     Stop(s);
-    vlc_object_release(s);
 }



More information about the vlc-commits mailing list