Bug 809554: if a device has no uniqueId, use the name r=derf
authorRandell Jesup <rjesup@jesup.org>
Mon, 12 Nov 2012 20:46:52 -0500
changeset 113087 213b5afa306881c08a89c8b7c9dbc7ddf700cfcc
parent 113086 c3b7e68ef6a04d97994c219d9d59c42ad7df0545
child 113088 be70af79cb29a2b0001af246ce7c2ab9bf65e689
push id17937
push userrjesup@wgate.com
push dateTue, 13 Nov 2012 16:21:11 +0000
treeherdermozilla-inbound@213b5afa3068 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersderf
bugs809554
milestone19.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 809554: if a device has no uniqueId, use the name r=derf
content/media/webrtc/MediaEngineWebRTC.cpp
--- a/content/media/webrtc/MediaEngineWebRTC.cpp
+++ b/content/media/webrtc/MediaEngineWebRTC.cpp
@@ -83,37 +83,43 @@ MediaEngineWebRTC::EnumerateVideoDevices
 
     // paranoia
     deviceName[0] = '\0';
     uniqueId[0] = '\0';
     int error = ptrViECapture->GetCaptureDevice(i, deviceName,
                                                 sizeof(deviceName), uniqueId,
                                                 sizeof(uniqueId));
 
-#ifdef DEBUG
     if (error) {
       LOG((" VieCapture:GetCaptureDevice: Failed %d",
            ptrViEBase->LastError() ));
       continue;
     }
+#ifdef DEBUG
     LOG(("  Capture Device Index %d, Name %s", i, deviceName));
 
     webrtc::CaptureCapability cap;
     int numCaps = ptrViECapture->NumberOfCapabilities(uniqueId, kMaxUniqueIdLength);
     LOG(("Number of Capabilities %d", numCaps));
     for (int j = 0; j < numCaps; j++) {
       if (ptrViECapture->GetCaptureCapability(uniqueId, kMaxUniqueIdLength,
                                               j, cap ) != 0 ) {
         break;
       }
       LOG(("type=%d width=%d height=%d maxFPS=%d",
            cap.rawType, cap.width, cap.height, cap.maxFPS ));
     }
 #endif
 
+    if (uniqueId[0] == '\0') {
+      // In case a device doesn't set uniqueId!
+      strncpy(uniqueId, deviceName, sizeof(uniqueId));
+	  uniqueId[sizeof(uniqueId)-1] = '\0'; // strncpy isn't safe
+    }
+
     nsRefPtr<MediaEngineWebRTCVideoSource> vSource;
     NS_ConvertUTF8toUTF16 uuid(uniqueId);
     if (mVideoSources.Get(uuid, getter_AddRefs(vSource))) {
       // We've already seen this device, just append.
       aVSources->AppendElement(vSource.get());
     } else {
       vSource = new MediaEngineWebRTCVideoSource(mVideoEngine, i);
       mVideoSources.Put(uuid, vSource); // Hashtable takes ownership.
@@ -164,17 +170,29 @@ MediaEngineWebRTC::EnumerateAudioDevices
   for (int i = 0; i < nDevices; i++) {
     // We use constants here because GetRecordingDeviceName takes char[128].
     char deviceName[128];
     char uniqueId[128];
     // paranoia; jingle doesn't bother with this
     deviceName[0] = '\0';
     uniqueId[0] = '\0';
 
-    ptrVoEHw->GetRecordingDeviceName(i, deviceName, uniqueId);
+    int error = ptrVoEHw->GetRecordingDeviceName(i, deviceName, uniqueId);
+    if (error) {
+      LOG((" VoEHardware:GetRecordingDeviceName: Failed %d",
+           ptrVoEBase->LastError() ));
+      continue;
+    }
+
+    LOG(("  Capture Device Index %d, Name %s Uuid %s", i, deviceName, uniqueId));
+    if (uniqueId[0] == '\0') {
+      // Mac and Linux don't set uniqueId!
+      MOZ_ASSERT(sizeof(deviceName) == sizeof(uniqueId)); // total paranoia
+      strcpy(uniqueId,deviceName); // safe given assert and initialization/error-check
+    }
 
     nsRefPtr<MediaEngineWebRTCAudioSource> aSource;
     NS_ConvertUTF8toUTF16 uuid(uniqueId);
     if (mAudioSources.Get(uuid, getter_AddRefs(aSource))) {
       // We've already seen this device, just append.
       aASources->AppendElement(aSource.get());
     } else {
       aSource = new MediaEngineWebRTCAudioSource(