Bug 1340718 - Retry getting the default device when audio devices are present and the first call failed. r?kinetik draft
authorPaul Adenot <paul@paul.cx>
Tue, 21 Feb 2017 17:05:59 +0100
changeset 487465 a9a06495d49c34513b75fd687c317a3b633f6c23
parent 487464 2d23434260fcf8db23f4d35718b0c8a11194fd59
child 546463 a27c5c415e88a14b3b716e1b391be614acd23600
push id46228
push userpaul@paul.cx
push dateTue, 21 Feb 2017 16:19:44 +0000
reviewerskinetik
bugs1340718
milestone45.7.1
Bug 1340718 - Retry getting the default device when audio devices are present and the first call failed. r?kinetik MozReview-Commit-ID: IBtM77Dzsx6
media/libcubeb/retry-device-unavailable.patch
media/libcubeb/src/cubeb_wasapi.cpp
media/libcubeb/update.sh
new file mode 100644
--- /dev/null
+++ b/media/libcubeb/retry-device-unavailable.patch
@@ -0,0 +1,33 @@
+diff --git a/media/libcubeb/src/cubeb_wasapi.cpp b/media/libcubeb/src/cubeb_wasapi.cpp
+--- a/media/libcubeb/src/cubeb_wasapi.cpp
++++ b/media/libcubeb/src/cubeb_wasapi.cpp
+@@ -695,22 +695,23 @@ HRESULT get_default_endpoint(IMMDevice *
+   if (FAILED(hr)) {
+     LOG("Could not get device enumerator: %x\n", hr);
+     return hr;
+   }
+   /* eMultimedia is okay for now ("Music, movies, narration, [...]").
+      We will need to change this when we distinguish streams by use-case, other
+      possible values being eConsole ("Games, system notification sounds [...]")
+      and eCommunication ("Voice communication"). */
+-  hr = enumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, device);
+-  if (FAILED(hr)) {
+-    LOG("Could not get default audio endpoint: %x\n", hr);
+-    SafeRelease(enumerator);
+-    return hr;
+-  }
++  do {
++    hr = enumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, device);
++    if (FAILED(hr)) {
++      LOG("Could not get default audio endpoint: %x\n", hr);
++      Sleep(100);
++    }
++  } while (FAILED(hr) && hr != E_NOTFOUND);
+ 
+   SafeRelease(enumerator);
+ 
+   return ERROR_SUCCESS;
+ }
+ 
+ double
+ current_stream_delay(cubeb_stream * stm)
--- a/media/libcubeb/src/cubeb_wasapi.cpp
+++ b/media/libcubeb/src/cubeb_wasapi.cpp
@@ -695,22 +695,23 @@ HRESULT get_default_endpoint(IMMDevice *
   if (FAILED(hr)) {
     LOG("Could not get device enumerator: %x\n", hr);
     return hr;
   }
   /* eMultimedia is okay for now ("Music, movies, narration, [...]").
      We will need to change this when we distinguish streams by use-case, other
      possible values being eConsole ("Games, system notification sounds [...]")
      and eCommunication ("Voice communication"). */
-  hr = enumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, device);
-  if (FAILED(hr)) {
-    LOG("Could not get default audio endpoint: %x\n", hr);
-    SafeRelease(enumerator);
-    return hr;
-  }
+  do {
+    hr = enumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, device);
+    if (FAILED(hr)) {
+      LOG("Could not get default audio endpoint: %x\n", hr);
+      Sleep(100);
+    }
+  } while (FAILED(hr) && hr != E_NOTFOUND);
 
   SafeRelease(enumerator);
 
   return ERROR_SUCCESS;
 }
 
 double
 current_stream_delay(cubeb_stream * stm)
--- a/media/libcubeb/update.sh
+++ b/media/libcubeb/update.sh
@@ -38,8 +38,10 @@ if [ -n "$rev" ]; then
     echo "WARNING: updating from a dirty git repository."
   fi
   sed -i.bak -e "/The git commit ID used was/ s/[0-9a-f]\{40\}\(-dirty\)\{0,1\}\./$version./" README_MOZILLA
   rm README_MOZILLA.bak
 else
   echo "Remember to update README_MOZILLA with the version details."
 fi
 
+echo "Applying a patch on top of $version."
+patch -p1 < ./retry-device-unavailable.patch