From 3a8cc9aa16846cd5a4b1ed7a30f84044e0b91b6a Mon Sep 17 00:00:00 2001 From: Randell Jesup Date: Sun, 12 May 2013 05:12:57 -0400 Subject: [PATCH] Bug 861280: use fake_N for uniqueId for video devices with no capability value we can use r=derf --- .../video_capture/linux/device_info_linux.cc | 77 +++++++++++-------- .../linux/video_capture_linux.cc | 7 ++ 2 files changed, 51 insertions(+), 33 deletions(-) diff --git a/media/webrtc/trunk/webrtc/modules/video_capture/linux/device_info_linux.cc b/media/webrtc/trunk/webrtc/modules/video_capture/linux/device_info_linux.cc index 239a29267c1..9300dc2859c 100644 --- a/media/webrtc/trunk/webrtc/modules/video_capture/linux/device_info_linux.cc +++ b/media/webrtc/trunk/webrtc/modules/video_capture/linux/device_info_linux.cc @@ -94,9 +94,10 @@ WebRtc_Word32 DeviceInfoLinux::GetDeviceName( char device[20]; int fd = -1; bool found = false; - for (int n = 0; n < 64; n++) + int device_index; + for (device_index = 0; device_index < 64; device_index++) { - sprintf(device, "/dev/video%d", n); + sprintf(device, "/dev/video%d", device_index); if ((fd = open(device, O_RDONLY)) != -1) { if (count == deviceNumber) { @@ -155,6 +156,15 @@ WebRtc_Word32 DeviceInfoLinux::GetDeviceName( "buffer passed is too small"); return -1; } + } else { + // if there's no bus info to use for uniqueId, invent one - and it has to be repeatable + if (snprintf(deviceUniqueIdUTF8, deviceUniqueIdUTF8Length, "fake_%u", device_index) >= + deviceUniqueIdUTF8Length) + { + WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, + "buffer passed is too small"); + return -1; + } } return 0; @@ -166,6 +176,7 @@ WebRtc_Word32 DeviceInfoLinux::CreateCapabilityMap( int fd; char device[32]; bool found = false; + int device_index; const WebRtc_Word32 deviceUniqueIdUTF8Length = (WebRtc_Word32) strlen((char*) deviceUniqueIdUTF8); @@ -177,41 +188,41 @@ WebRtc_Word32 DeviceInfoLinux::CreateCapabilityMap( WEBRTC_TRACE(webrtc::kTraceInfo, webrtc::kTraceVideoCapture, _id, "CreateCapabilityMap called for device %s", deviceUniqueIdUTF8); - /* detect /dev/video [0-63] entries */ - for (int n = 0; n < 64; ++n) + if (sscanf(deviceUniqueIdUTF8,"fake_%d",&device_index) == 1) { - sprintf(device, "/dev/video%d", n); + sprintf(device, "/dev/video%d", device_index); fd = open(device, O_RDONLY); - if (fd == -1) - continue; - - // query device capabilities - struct v4l2_capability cap; - if (ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0) - { - if (cap.bus_info[0] != 0) - { - if (strncmp((const char*) cap.bus_info, - (const char*) deviceUniqueIdUTF8, - strlen((const char*) deviceUniqueIdUTF8)) == 0) //match with device id - { - found = true; - break; // fd matches with device unique id supplied - } - } - else //match for device name - { - if (IsDeviceNameMatches((const char*) cap.card, - (const char*) deviceUniqueIdUTF8)) - { - found = true; - break; - } - } + if (fd != -1) { + found = true; } - close(fd); // close since this is not the matching device - } + } else { + /* detect /dev/video [0-63] entries */ + for (int n = 0; n < 64; ++n) + { + sprintf(device, "/dev/video%d", n); + fd = open(device, O_RDONLY); + if (fd == -1) + continue; + // query device capabilities + struct v4l2_capability cap; + if (ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0) + { + if (cap.bus_info[0] != 0) + { + if (strncmp((const char*) cap.bus_info, + (const char*) deviceUniqueIdUTF8, + strlen((const char*) deviceUniqueIdUTF8)) == 0) //match with device id + { + found = true; + break; // fd matches with device unique id supplied + } + } + // else can't be a match as the test for fake_* above would have matched it + } + close(fd); // close since this is not the matching device + } + } if (!found) { WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id, "no matching device found"); diff --git a/media/webrtc/trunk/webrtc/modules/video_capture/linux/video_capture_linux.cc b/media/webrtc/trunk/webrtc/modules/video_capture/linux/video_capture_linux.cc index 12df1b3dd05..61837003cea 100644 --- a/media/webrtc/trunk/webrtc/modules/video_capture/linux/video_capture_linux.cc +++ b/media/webrtc/trunk/webrtc/modules/video_capture/linux/video_capture_linux.cc @@ -70,6 +70,13 @@ WebRtc_Word32 VideoCaptureModuleV4L2::Init(const char* deviceUniqueIdUTF8) memcpy(_deviceUniqueId, deviceUniqueIdUTF8, len + 1); } + int device_index; + if (sscanf(deviceUniqueIdUTF8,"fake_%d", &device_index) == 1) + { + _deviceId = device_index; + return 0; + } + int fd; char device[32]; bool found = false;