[vlc-commits] mmdevice: fix restart due to preemption in Start()

Rémi Denis-Courmont git at videolan.org
Tue Feb 4 23:06:30 CET 2014


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Tue Feb  4 22:09:13 2014 +0200| [43291e2e7ffd353d171ada04d3d0980cc21e866c] | committer: Rémi Denis-Courmont

mmdevice: fix restart due to preemption in Start()

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

 modules/audio_output/mmdevice.c |   28 +++++++++++++++++-----------
 1 file changed, 17 insertions(+), 11 deletions(-)

diff --git a/modules/audio_output/mmdevice.c b/modules/audio_output/mmdevice.c
index 757481e..81225a1 100644
--- a/modules/audio_output/mmdevice.c
+++ b/modules/audio_output/mmdevice.c
@@ -642,7 +642,7 @@ static int DeviceSelect(audio_output_t *aout, const char *id)
         SleepConditionVariableCS(&sys->ready, &sys->lock, INFINITE);
     LeaveCriticalSection(&sys->lock);
 
-    if (sys->stream != NULL)
+    if (sys->stream != NULL && sys->dev != NULL)
         /* Request restart of stream with the new device */
         aout_RestartRequest(aout, AOUT_RESTART_OUTPUT);
     return (sys->dev != NULL) ? 0 : -1;
@@ -865,9 +865,12 @@ static int aout_stream_Start(void *func, va_list ap)
     aout_stream_start_t start = func;
     aout_stream_t *s = va_arg(ap, aout_stream_t *);
     audio_sample_format_t *fmt = va_arg(ap, audio_sample_format_t *);
+    HRESULT *hr = va_arg(ap, HRESULT *);
 
-    return SUCCEEDED(start(s, fmt, &GUID_VLC_AUD_OUT))
-        ? VLC_SUCCESS : VLC_EGENERIC;
+    *hr = start(s, fmt, &GUID_VLC_AUD_OUT);
+    if (*hr == AUDCLNT_E_DEVICE_INVALIDATED)
+        return VLC_ETIMEOUT;
+    return SUCCEEDED(*hr) ? VLC_SUCCESS : VLC_EGENERIC;
 }
 
 static void aout_stream_Stop(void *func, va_list ap)
@@ -881,13 +884,8 @@ static void aout_stream_Stop(void *func, va_list ap)
 static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
 {
     aout_sys_t *sys = aout->sys;
-
-    assert (sys->stream == NULL);
-#if !VLC_WINSTORE_APP
-    /* Open the default device if required (to deal with restarts) */
-    if (sys->dev == NULL && FAILED(DeviceSelect(aout, NULL)))
+    if (sys->dev == NULL)
         return -1;
-#endif
 
     aout_stream_t *s = vlc_object_create(aout, sizeof (*s));
     if (unlikely(s == NULL))
@@ -901,8 +899,15 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
     s->owner.activate = ActivateDevice;
 
     EnterMTA();
-    sys->module = vlc_module_load(s, "aout stream", NULL, false,
-                                  aout_stream_Start, s, fmt);
+    for (;;)
+    {
+        HRESULT hr;
+
+        sys->module = vlc_module_load(s, "aout stream", NULL, false,
+                                      aout_stream_Start, s, fmt, &hr);
+        if (hr != AUDCLNT_E_DEVICE_INVALIDATED || DeviceSelect(aout, NULL))
+            break;
+    }
     LeaveMTA();
 
     if (sys->module == NULL)
@@ -911,6 +916,7 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
         return -1;
     }
 
+    assert (sys->stream == NULL);
     sys->stream = s;
     return 0;
 }



More information about the vlc-commits mailing list