[vlc-commits] mmdevice: fix restart when switching from 0 to 1 device

Thomas Guillem git at videolan.org
Wed Apr 18 10:57:36 CEST 2018


vlc/vlc-3.0 | branch: master | Thomas Guillem <thomas at gllm.fr> | Tue Apr 17 19:11:34 2018 +0200| [d2b32fd3ac984d6a4ff89547a647f3101441a55e] | committer: Hugo Beauzée-Luyssen

mmdevice: fix restart when switching from 0 to 1 device

 - aout_RestartRequest() was not called because of a NULL sys->acquired_device,

 - DeviceRestartLocked() was not called from Start() because of the early
   sys->dev check,

 - sys->acquired_device was not reset to NULL (when switching from 1 to 0
   devices).

Reminder: sys->dev and sys->acquired_device are NULL if the aout is opened
without any audio devices plugged.

(cherry picked from commit 088533d6d9da13afcca0db855b2ba862e5f48576)
Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>

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

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

diff --git a/modules/audio_output/mmdevice.c b/modules/audio_output/mmdevice.c
index 844152cf93..fda5d4195c 100644
--- a/modules/audio_output/mmdevice.c
+++ b/modules/audio_output/mmdevice.c
@@ -591,7 +591,7 @@ vlc_MMNotificationClient_OnDefaultDeviceChange(IMMNotificationClient *this,
         return S_OK;
 
     EnterCriticalSection(&sys->lock);
-    if (sys->acquired_device == default_device)
+    if (sys->acquired_device == NULL || sys->acquired_device == default_device)
     {
         msg_Dbg(aout, "default device changed: %ls", wid);
         sys->request_device_restart = true;
@@ -775,8 +775,8 @@ static int DeviceRestartLocked(audio_output_t *aout)
 {
     aout_sys_t *sys = aout->sys;
     assert(sys->requested_device == NULL);
-    assert(sys->acquired_device != NULL);
-    sys->requested_device = sys->acquired_device;
+    sys->requested_device = sys->acquired_device ? sys->acquired_device
+                                                 : default_device;
     return DeviceRequestLocked(aout);
 }
 
@@ -849,7 +849,10 @@ static HRESULT MMSession(audio_output_t *aout, IMMDeviceEnumerator *it)
         hr = IMMDeviceEnumerator_GetDefaultAudioEndpoint(it, eRender,
                                                          eConsole, &sys->dev);
         if (FAILED(hr))
+        {
             msg_Err(aout, "cannot get default device (error 0x%lx)", hr);
+            sys->acquired_device = NULL;
+        }
         else
             sys->acquired_device = default_device;
     }
@@ -1122,9 +1125,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)
@@ -1153,8 +1153,11 @@ static int Start(audio_output_t *aout, audio_sample_format_t *restrict fmt)
     EnterMTA();
     EnterCriticalSection(&sys->lock);
 
-    if (sys->request_device_restart && DeviceRestartLocked(aout) != 0)
+    if ((sys->request_device_restart && DeviceRestartLocked(aout) != 0)
+      || sys->dev == NULL)
     {
+        /* Error if the device restart failed or if a request previously
+         * failed. */
         LeaveCriticalSection(&sys->lock);
         LeaveMTA();
         vlc_object_release(s);



More information about the vlc-commits mailing list