Bug 1481957 - Make input device enumeration for Android similar to other platforms when cubeb is disabled. r=padenot
authorAlex Chronopoulos <achronop@gmail.com>
Mon, 13 Aug 2018 08:25:38 +0000
changeset 486288 6c752dc707f5bc5557bc558d8737c143c658727c
parent 486287 3a54c28335c447bac5ce3b1dbad39ff7a724f8d1
child 486289 7b6834fceadea39c08a4a5dd819f418e53cb2b2e
push id9719
push userffxbld-merge
push dateFri, 24 Aug 2018 17:49:46 +0000
treeherdermozilla-beta@719ec98fba77 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1481957
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1481957 - Make input device enumeration for Android similar to other platforms when cubeb is disabled. r=padenot In the case that cubeb is disabled we do not need to offer the dummy device on android because will leave gUM request thinking that everything is good, which will create other side effects. Also the special handling for android increases the complexity. Differential Revision: https://phabricator.services.mozilla.com/D3026
dom/media/gtest/TestAudioDeviceEnumerator.cpp
dom/media/tests/mochitest/test_getUserMedia_cubebDisabled.html
dom/media/webrtc/MediaEngineWebRTC.cpp
--- a/dom/media/gtest/TestAudioDeviceEnumerator.cpp
+++ b/dom/media/gtest/TestAudioDeviceEnumerator.cpp
@@ -567,8 +567,18 @@ TEST(CubebDeviceEnumerator, EnumerateAnd
   nsTArray<RefPtr<AudioDeviceInfo>> inputDevices;
   enumerator.EnumerateAudioInputDevices(inputDevices);
   EXPECT_EQ(inputDevices.Length(), 1u) <<  "Android always exposes a single input device.";
   EXPECT_EQ(inputDevices[0]->MaxChannels(), 1u) << "With a single channel.";
   EXPECT_EQ(inputDevices[0]->DeviceID(), nullptr) << "It's always the default device.";
   EXPECT_TRUE(inputDevices[0]->Preferred()) << "it's always the prefered device.";
 }
 #endif
+
+TEST(CubebDeviceEnumerator, ForceNullCubebContext)
+{
+  mozilla::CubebUtils::ForceSetCubebContext(nullptr);
+  CubebDeviceEnumerator enumerator;
+  nsTArray<RefPtr<AudioDeviceInfo>> inputDevices;
+  enumerator.EnumerateAudioInputDevices(inputDevices);
+  EXPECT_EQ(inputDevices.Length(), 0u) << "Enumeration must fail device list must be empty.";
+}
+
--- a/dom/media/tests/mochitest/test_getUserMedia_cubebDisabled.html
+++ b/dom/media/tests/mochitest/test_getUserMedia_cubebDisabled.html
@@ -15,44 +15,26 @@
    * during a gUM call.
    */
   runTest(async function () {
     info("Get user media with cubeb disabled starting");
     // Push prefs to ensure no cubeb context and no fake streams.
     await pushPrefs(["media.cubeb.force_null_context", true],
                     ["media.navigator.streams.fake", false]);
 
-    // Android has its own codepath which means it works even when cubeb is
-    // disabled. For examples see MediaEngineWebRTC::GetNumOfRecordingDevices and
-    // MediaEngineWebRTC::GetRecordingDeviceName.
-    let isAndroid = navigator.appVersion.includes("Android");
-    // We're on android we expect to get an audio stream, create an elem for it
-    let testAudio = createMediaElement('audio', 'testAudio');
-
     // Request audio only, to avoid cams
     let constraints = {audio: true, video: false};
     let stream;
     try {
       stream = await getUserMedia(constraints);
     } catch (e) {
-      if (isAndroid) {
-        ok(false, `getUserMedia expected to succeed on android, even with null cubeb context, but got ${e}`);
-        return;
-      }
-      // !isAndroid
       // We've got no audio backend, so we expect gUM to fail.
       ok(e.name == "NotFoundError", "Expected NotFoundError due to no audio tracks!");
       return;
     }
-    if (isAndroid) {
-      ok(stream, "getUserMedia expected to return a stream on Android even when cubeb context null!");
-      let playback = new LocalMediaStreamPlayback(testAudio, stream);
-      return playback.playMedia(false);
-    }
-    // !isAndroid
     // If we're not on android we should not have gotten a stream without a cubeb context!
     ok(false, "getUserMedia not expected to succeed when cubeb is disabled, but it did!");
   });
 
 
 </script>
 </pre>
 </body>
--- a/dom/media/webrtc/MediaEngineWebRTC.cpp
+++ b/dom/media/webrtc/MediaEngineWebRTC.cpp
@@ -386,55 +386,53 @@ CubebDeviceEnumerator::~CubebDeviceEnume
   }
 }
 
 void
 CubebDeviceEnumerator::EnumerateAudioInputDevices(nsTArray<RefPtr<AudioDeviceInfo>>& aOutDevices)
 {
   aOutDevices.Clear();
 
-#ifdef ANDROID
-  // Bug 1473346: enumerating devices is not supported on Android in cubeb,
-  // simply state that there is a single mic, that it is the default, and has a
-  // single channel. All the other values are made up and are not to be used.
-  RefPtr<AudioDeviceInfo> info = new AudioDeviceInfo(nullptr,
-                                                     NS_ConvertUTF8toUTF16(""),
-                                                     NS_ConvertUTF8toUTF16(""),
-                                                     NS_ConvertUTF8toUTF16(""),
-                                                     CUBEB_DEVICE_TYPE_INPUT,
-                                                     CUBEB_DEVICE_STATE_ENABLED,
-                                                     CUBEB_DEVICE_PREF_ALL,
-                                                     CUBEB_DEVICE_FMT_ALL,
-                                                     CUBEB_DEVICE_FMT_S16NE,
-                                                     1,
-                                                     44100,
-                                                     44100,
-                                                     41000,
-                                                     410,
-                                                     128);
-  if (mDevices.IsEmpty()) {
-    mDevices.AppendElement(info);
-  }
-  aOutDevices.AppendElements(mDevices);
-#else
   cubeb* context = GetCubebContext();
-
   if (!context) {
     return;
   }
 
   MutexAutoLock lock(mMutex);
 
+#ifdef ANDROID
+  if (mDevices.IsEmpty()) {
+    // Bug 1473346: enumerating devices is not supported on Android in cubeb,
+    // simply state that there is a single mic, that it is the default, and has a
+    // single channel. All the other values are made up and are not to be used.
+    RefPtr<AudioDeviceInfo> info = new AudioDeviceInfo(nullptr,
+                                                       NS_ConvertUTF8toUTF16(""),
+                                                       NS_ConvertUTF8toUTF16(""),
+                                                       NS_ConvertUTF8toUTF16(""),
+                                                       CUBEB_DEVICE_TYPE_INPUT,
+                                                       CUBEB_DEVICE_STATE_ENABLED,
+                                                       CUBEB_DEVICE_PREF_ALL,
+                                                       CUBEB_DEVICE_FMT_ALL,
+                                                       CUBEB_DEVICE_FMT_S16NE,
+                                                       1,
+                                                       44100,
+                                                       44100,
+                                                       41000,
+                                                       410,
+                                                       128);
+    mDevices.AppendElement(info);
+  }
+#else
   if (mDevices.IsEmpty() || mManualInvalidation) {
     mDevices.Clear();
     CubebUtils::GetDeviceCollection(mDevices, CubebUtils::Input);
   }
+#endif
 
   aOutDevices.AppendElements(mDevices);
-#endif
 }
 
 already_AddRefed<AudioDeviceInfo>
 CubebDeviceEnumerator::DeviceInfoFromID(CubebUtils::AudioDeviceID aID)
 {
   MutexAutoLock lock(mMutex);
 
   for (uint32_t i  = 0; i < mDevices.Length(); i++) {