mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 20:05:49 +00:00
Bug 861280: use fake_N for uniqueId for video devices with no capability value we can use r=derf
This commit is contained in:
parent
86b86d8e0b
commit
317500f434
@ -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");
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user