Bug 971528 - Allow stereo capture in AudioCallbackDriver. r?padenot draft
authorAlex Chronopoulos <achronop@gmail.com>
Fri, 02 Jun 2017 09:11:56 +0300
changeset 588110 a8fb5a1d1243a8920a80350ca176e3c2d7af350e
parent 587839 0e9853e31da9848ab638bdd0df4eb734a5ebc232
child 588111 cafb069d6d2cf15f4d76cc8fd8592ededeb28533
push id61914
push userachronop@gmail.com
push dateFri, 02 Jun 2017 06:39:03 +0000
reviewerspadenot
bugs971528
milestone55.0a1
Bug 971528 - Allow stereo capture in AudioCallbackDriver. r?padenot * * * [mq]: graph-driver-comments MozReview-Commit-ID: JnU3opk8X5K * * * [mq]: tmp MozReview-Commit-ID: 73CtZw4CRG
dom/media/GraphDriver.cpp
dom/media/webrtc/MediaEngineWebRTC.h
--- a/dom/media/GraphDriver.cpp
+++ b/dom/media/GraphDriver.cpp
@@ -657,20 +657,29 @@ AudioCallbackDriver::Init()
   }
 
   // Macbook and MacBook air don't have enough CPU to run very low latency
   // MediaStreamGraphs, cap the minimal latency to 512 frames int this case.
   if (IsMacbookOrMacbookAir()) {
     latency_frames = std::max((uint32_t) 512, latency_frames);
   }
 
+  input = output;
+  input.channels = mInputChannels;
+  input.layout = CUBEB_LAYOUT_UNDEFINED;
 
-  input = output;
-  input.channels = mInputChannels; // change to support optional stereo capture
-  input.layout = CUBEB_LAYOUT_MONO;
+#ifdef MOZ_WEBRTC
+  if (mGraphImpl->mInputWanted) {
+    StaticMutexAutoLock lock(AudioInputCubeb::Mutex());
+    uint32_t maxInputChannels = 0;
+    if (AudioInputCubeb::GetDeviceMaxChannels(mGraphImpl->mInputDeviceID, maxInputChannels) == 0) {
+      input.channels = mInputChannels = maxInputChannels;
+    }
+  }
+#endif
 
   cubeb_stream* stream = nullptr;
   CubebUtils::AudioDeviceID input_id = nullptr, output_id = nullptr;
   // We have to translate the deviceID values to cubeb devid's since those can be
   // freed whenever enumerate is called.
   {
 #ifdef MOZ_WEBRTC
     StaticMutexAutoLock lock(AudioInputCubeb::Mutex());
--- a/dom/media/webrtc/MediaEngineWebRTC.h
+++ b/dom/media/webrtc/MediaEngineWebRTC.h
@@ -203,16 +203,17 @@ public:
     // -1 = system default if any
     if (aIndex == -1) {
       if (mDefaultDevice == -1) {
         aIndex = 0;
       } else {
         aIndex = mDefaultDevice;
       }
     }
+    MOZ_ASSERT(mDeviceIndexes);
     if (aIndex < 0 || aIndex >= (int) mDeviceIndexes->Length()) {
       return -1;
     }
     // Note: if the device is gone, this will be -1
     return (*mDeviceIndexes)[aIndex]; // translate to mDevices index
   }
 
   static StaticMutex& Mutex()
@@ -258,16 +259,30 @@ public:
   int GetRecordingDeviceStatus(bool& aIsAvailable)
   {
     // With cubeb, we only expose devices of type CUBEB_DEVICE_TYPE_INPUT,
     // so unless it was removed, say it's available
     aIsAvailable = true;
     return 0;
   }
 
+  static int GetDeviceMaxChannels(int aDeviceIndex, uint32_t& aChannels)
+  {
+#ifdef MOZ_WIDGET_ANDROID
+    aChannels = 1;
+#else
+    int32_t devindex = DeviceIndex(aDeviceIndex);
+    if (mDevices.count == 0 || devindex < 0) {
+      return 1;
+    }
+    aChannels = mDevices.device[devindex].max_channels;
+#endif
+    return 0;
+  }
+
   void StartRecording(SourceMediaStream *aStream, AudioDataListener *aListener)
   {
 #ifdef MOZ_WIDGET_ANDROID
     // OpenSL ES does not support enumerating devices.
     MOZ_ASSERT(mDevices.count == 0);
 #else
     MOZ_ASSERT(mDevices.count > 0);
 #endif