diff --git a/dom/media/systemservices/video_engine/browser_capture_impl.h b/dom/media/systemservices/video_engine/browser_capture_impl.h index 7ead2d9cf4e9..aeaae6220252 100644 --- a/dom/media/systemservices/video_engine/browser_capture_impl.h +++ b/dom/media/systemservices/video_engine/browser_capture_impl.h @@ -20,11 +20,11 @@ class BrowserDeviceInfoImpl : public VideoCaptureModule::DeviceInfo { virtual int32_t Refresh() { return 0; } virtual int32_t GetDeviceName(uint32_t deviceNumber, char* deviceNameUTF8, - uint32_t deviceNameLength, + uint32_t deviceNameSize, char* deviceUniqueIdUTF8, - uint32_t deviceUniqueIdUTF8Length, + uint32_t deviceUniqueIdUTF8Size, char* productUniqueIdUTF8 = NULL, - uint32_t productUniqueIdUTF8Length = 0, + uint32_t productUniqueIdUTF8Size = 0, pid_t* pid = 0) { deviceNameUTF8 = const_cast(kDeviceName); deviceUniqueIdUTF8 = const_cast(kUniqueDeviceName); diff --git a/media/webrtc/trunk/webrtc/modules/video_capture/android/video_capture_android.cc b/media/webrtc/trunk/webrtc/modules/video_capture/android/video_capture_android.cc index b1395f953091..2ae77690c7c9 100644 --- a/media/webrtc/trunk/webrtc/modules/video_capture/android/video_capture_android.cc +++ b/media/webrtc/trunk/webrtc/modules/video_capture/android/video_capture_android.cc @@ -146,7 +146,7 @@ VideoCaptureAndroid::VideoCaptureAndroid() int32_t VideoCaptureAndroid::Init(const char* deviceUniqueIdUTF8) { const int nameLength = strlen(deviceUniqueIdUTF8); - if (nameLength >= kVideoCaptureUniqueNameLength) + if (nameLength >= kVideoCaptureUniqueNameSize) return -1; // Store the device name 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 7162f1ece7c5..825fbd56c1e9 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 @@ -215,11 +215,11 @@ uint32_t DeviceInfoLinux::NumberOfDevices() { int32_t DeviceInfoLinux::GetDeviceName(uint32_t deviceNumber, char* deviceNameUTF8, - uint32_t deviceNameLength, + uint32_t deviceNameSize, char* deviceUniqueIdUTF8, - uint32_t deviceUniqueIdUTF8Length, + uint32_t deviceUniqueIdUTF8Size, char* /*productUniqueIdUTF8*/, - uint32_t /*productUniqueIdUTF8Length*/, + uint32_t /*productUniqueIdUTF8Size*/, pid_t* /*pid*/) { RTC_LOG(LS_INFO) << __FUNCTION__; @@ -258,10 +258,10 @@ int32_t DeviceInfoLinux::GetDeviceName(uint32_t deviceNumber, close(fd); char cameraName[64]; - memset(deviceNameUTF8, 0, deviceNameLength); + memset(deviceNameUTF8, 0, deviceNameSize); memcpy(cameraName, cap.card, sizeof(cap.card)); - if (deviceNameLength >= strlen(cameraName)) { + if (deviceNameSize > strlen(cameraName)) { memcpy(deviceNameUTF8, cameraName, strlen(cameraName)); } else { RTC_LOG(LS_INFO) << "buffer passed is too small"; @@ -271,8 +271,8 @@ int32_t DeviceInfoLinux::GetDeviceName(uint32_t deviceNumber, if (cap.bus_info[0] != 0) // may not available in all drivers { // copy device id - if (deviceUniqueIdUTF8Length >= strlen((const char*)cap.bus_info)) { - memset(deviceUniqueIdUTF8, 0, deviceUniqueIdUTF8Length); + if (deviceUniqueIdUTF8Size > strlen((const char*)cap.bus_info)) { + memset(deviceUniqueIdUTF8, 0, deviceUniqueIdUTF8Size); memcpy(deviceUniqueIdUTF8, cap.bus_info, strlen((const char*)cap.bus_info)); } else { @@ -282,8 +282,8 @@ int32_t DeviceInfoLinux::GetDeviceName(uint32_t deviceNumber, } 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) >= - (int) deviceUniqueIdUTF8Length) + deviceUniqueIdUTF8Size, "fake_%u", device_index) >= + (int) deviceUniqueIdUTF8Size) { return -1; } @@ -298,7 +298,7 @@ int32_t DeviceInfoLinux::CreateCapabilityMap(const char* deviceUniqueIdUTF8) { const int32_t deviceUniqueIdUTF8Length = (int32_t)strlen((char*)deviceUniqueIdUTF8); - if (deviceUniqueIdUTF8Length > kVideoCaptureUniqueNameLength) { + if (deviceUniqueIdUTF8Length > kVideoCaptureUniqueNameSize) { RTC_LOG(LS_INFO) << "Device name too long"; return -1; } diff --git a/media/webrtc/trunk/webrtc/modules/video_capture/linux/device_info_linux.h b/media/webrtc/trunk/webrtc/modules/video_capture/linux/device_info_linux.h index 9141673ed2fc..1eb41fa5b213 100644 --- a/media/webrtc/trunk/webrtc/modules/video_capture/linux/device_info_linux.h +++ b/media/webrtc/trunk/webrtc/modules/video_capture/linux/device_info_linux.h @@ -34,11 +34,11 @@ public: virtual int32_t GetDeviceName( uint32_t deviceNumber, char* deviceNameUTF8, - uint32_t deviceNameLength, + uint32_t deviceNameSize, char* deviceUniqueIdUTF8, - uint32_t deviceUniqueIdUTF8Length, + uint32_t deviceUniqueIdUTF8Size, char* productUniqueIdUTF8=0, - uint32_t productUniqueIdUTF8Length=0, + uint32_t productUniqueIdUTF8Size=0, pid_t* pid=0); /* * Fills the membervariable _captureCapabilities with capabilites for the given device name. diff --git a/media/webrtc/trunk/webrtc/modules/video_capture/objc/video_capture.mm b/media/webrtc/trunk/webrtc/modules/video_capture/objc/video_capture.mm index 6dd2fd6e62c6..6df86d01fb08 100644 --- a/media/webrtc/trunk/webrtc/modules/video_capture/objc/video_capture.mm +++ b/media/webrtc/trunk/webrtc/modules/video_capture/objc/video_capture.mm @@ -51,7 +51,7 @@ rtc::scoped_refptr VideoCaptureIos::Create( new rtc::RefCountedObject()); const int32_t name_length = strlen(deviceUniqueIdUTF8); - if (name_length > kVideoCaptureUniqueNameLength) + if (name_length >= kVideoCaptureUniqueNameSize) return nullptr; capture_module->_deviceUniqueId = new char[name_length + 1]; diff --git a/media/webrtc/trunk/webrtc/modules/video_capture/video_capture.h b/media/webrtc/trunk/webrtc/modules/video_capture/video_capture.h index 63a5415f0ae4..11c880baa772 100644 --- a/media/webrtc/trunk/webrtc/modules/video_capture/video_capture.h +++ b/media/webrtc/trunk/webrtc/modules/video_capture/video_capture.h @@ -106,11 +106,11 @@ class VideoCaptureModule: public rtc::RefCountInterface { virtual int32_t GetDeviceName( uint32_t deviceNumber, char* deviceNameUTF8, - uint32_t deviceNameLength, + uint32_t deviceNameSize, char* deviceUniqueIdUTF8, - uint32_t deviceUniqueIdUTF8Length, + uint32_t deviceUniqueIdUTF8Size, char* productUniqueIdUTF8 = 0, - uint32_t productUniqueIdUTF8Length = 0, + uint32_t productUniqueIdUTF8Size = 0, pid_t* pid = 0) = 0; diff --git a/media/webrtc/trunk/webrtc/modules/video_capture/video_capture_defines.h b/media/webrtc/trunk/webrtc/modules/video_capture/video_capture_defines.h index a6d45d4d6e08..172509e3dfd2 100644 --- a/media/webrtc/trunk/webrtc/modules/video_capture/video_capture_defines.h +++ b/media/webrtc/trunk/webrtc/modules/video_capture/video_capture_defines.h @@ -26,9 +26,8 @@ namespace webrtc #define NULL 0 #endif -enum {kVideoCaptureUniqueNameLength =1024}; //Max unique capture device name lenght -enum {kVideoCaptureDeviceNameLength =256}; //Max capture device name lenght -enum {kVideoCaptureProductIdLength =128}; //Max product id length +enum {kVideoCaptureUniqueNameSize =1024}; //Max unique capture device name length +enum {kVideoCaptureProductIdSize =128}; //Max product id length struct VideoCaptureCapability { diff --git a/media/webrtc/trunk/webrtc/modules/video_capture/windows/device_info_ds.cc b/media/webrtc/trunk/webrtc/modules/video_capture/windows/device_info_ds.cc index 61041867479c..e48c438ffd6b 100644 --- a/media/webrtc/trunk/webrtc/modules/video_capture/windows/device_info_ds.cc +++ b/media/webrtc/trunk/webrtc/modules/video_capture/windows/device_info_ds.cc @@ -170,26 +170,26 @@ uint32_t DeviceInfoDS::NumberOfDevices() { int32_t DeviceInfoDS::GetDeviceName(uint32_t deviceNumber, char* deviceNameUTF8, - uint32_t deviceNameLength, + uint32_t deviceNameSize, char* deviceUniqueIdUTF8, - uint32_t deviceUniqueIdUTF8Length, + uint32_t deviceUniqueIdUTF8Size, char* productUniqueIdUTF8, - uint32_t productUniqueIdUTF8Length, + uint32_t productUniqueIdUTF8Size, pid_t *pid) { ReadLockScoped cs(_apiLock); const int32_t result = GetDeviceInfo( - deviceNumber, deviceNameUTF8, deviceNameLength, deviceUniqueIdUTF8, - deviceUniqueIdUTF8Length, productUniqueIdUTF8, productUniqueIdUTF8Length); + deviceNumber, deviceNameUTF8, deviceNameSize, deviceUniqueIdUTF8, + deviceUniqueIdUTF8Size, productUniqueIdUTF8, productUniqueIdUTF8Size); return result > (int32_t)deviceNumber ? 0 : -1; } int32_t DeviceInfoDS::GetDeviceInfo(uint32_t deviceNumber, char* deviceNameUTF8, - uint32_t deviceNameLength, + uint32_t deviceNameSize, char* deviceUniqueIdUTF8, - uint32_t deviceUniqueIdUTF8Length, + uint32_t deviceUniqueIdUTF8Size, char* productUniqueIdUTF8, - uint32_t productUniqueIdUTF8Length) + uint32_t productUniqueIdUTF8Size) { // enumerate all video capture devices @@ -224,20 +224,20 @@ int32_t DeviceInfoDS::GetDeviceInfo(uint32_t deviceNumber, // Found a valid device. if (index == static_cast(deviceNumber)) { int convResult = 0; - if (deviceNameLength > 0) { + if (deviceNameSize > 0) { convResult = WideCharToMultiByte(CP_UTF8, 0, varName.bstrVal, -1, (char*)deviceNameUTF8, - deviceNameLength, NULL, NULL); + deviceNameSize, NULL, NULL); if (convResult == 0) { RTC_LOG(LS_INFO) << "Failed to convert device name to UTF8, " << "error = " << GetLastError(); return -1; } } - if (deviceUniqueIdUTF8Length > 0) { + if (deviceUniqueIdUTF8Size > 0) { hr = pBag->Read(L"DevicePath", &varName, 0); if (FAILED(hr)) { - strncpy_s((char*)deviceUniqueIdUTF8, deviceUniqueIdUTF8Length, + strncpy_s((char*)deviceUniqueIdUTF8, deviceUniqueIdUTF8Size, (char*)deviceNameUTF8, convResult); RTC_LOG(LS_INFO) << "Failed to get " << "deviceUniqueIdUTF8 using " @@ -245,16 +245,16 @@ int32_t DeviceInfoDS::GetDeviceInfo(uint32_t deviceNumber, } else { convResult = WideCharToMultiByte( CP_UTF8, 0, varName.bstrVal, -1, (char*)deviceUniqueIdUTF8, - deviceUniqueIdUTF8Length, NULL, NULL); + deviceUniqueIdUTF8Size, NULL, NULL); if (convResult == 0) { RTC_LOG(LS_INFO) << "Failed to convert device " << "name to UTF8, error = " << GetLastError(); return -1; } - if (productUniqueIdUTF8 && productUniqueIdUTF8Length > 0) { + if (productUniqueIdUTF8 && productUniqueIdUTF8Size > 0) { GetProductId(deviceUniqueIdUTF8, productUniqueIdUTF8, - productUniqueIdUTF8Length); + productUniqueIdUTF8Size); } } } @@ -267,7 +267,7 @@ int32_t DeviceInfoDS::GetDeviceInfo(uint32_t deviceNumber, pM->Release(); } } - if (deviceNameLength) { + if (deviceNameSize) { RTC_LOG(LS_INFO) << __FUNCTION__ << " " << deviceNameUTF8; } return index; @@ -275,10 +275,10 @@ int32_t DeviceInfoDS::GetDeviceInfo(uint32_t deviceNumber, IBaseFilter* DeviceInfoDS::GetDeviceFilter(const char* deviceUniqueIdUTF8, char* productUniqueIdUTF8, - uint32_t productUniqueIdUTF8Length) { + uint32_t productUniqueIdUTF8Size) { const int32_t deviceUniqueIdUTF8Length = (int32_t)strlen( (char*)deviceUniqueIdUTF8); // UTF8 is also NULL terminated - if (deviceUniqueIdUTF8Length > kVideoCaptureUniqueNameLength) { + if (deviceUniqueIdUTF8Length >= kVideoCaptureUniqueNameSize) { RTC_LOG(LS_INFO) << "Device name too long"; return NULL; } @@ -332,10 +332,10 @@ IBaseFilter* DeviceInfoDS::GetDeviceFilter(const char* deviceUniqueIdUTF8, } if (productUniqueIdUTF8 && - productUniqueIdUTF8Length > 0) // Get the device name + productUniqueIdUTF8Size > 0) // Get the device name { GetProductId(deviceUniqueIdUTF8, productUniqueIdUTF8, - productUniqueIdUTF8Length); + productUniqueIdUTF8Size); } } } @@ -370,16 +370,16 @@ int32_t DeviceInfoDS::CreateCapabilityMap(const char* deviceUniqueIdUTF8) const int32_t deviceUniqueIdUTF8Length = (int32_t)strlen((char*)deviceUniqueIdUTF8); - if (deviceUniqueIdUTF8Length > kVideoCaptureUniqueNameLength) { + if (deviceUniqueIdUTF8Length >= kVideoCaptureUniqueNameSize) { RTC_LOG(LS_INFO) << "Device name too long"; return -1; } RTC_LOG(LS_INFO) << "CreateCapabilityMap called for device " << deviceUniqueIdUTF8; - char productId[kVideoCaptureProductIdLength]; + char productId[kVideoCaptureProductIdSize]; IBaseFilter* captureDevice = DeviceInfoDS::GetDeviceFilter( - deviceUniqueIdUTF8, productId, kVideoCaptureProductIdLength); + deviceUniqueIdUTF8, productId, sizeof(productId)); if (!captureDevice) return -1; IPin* outputCapturePin = GetOutputPin(captureDevice, GUID_NULL); @@ -613,11 +613,11 @@ int32_t DeviceInfoDS::CreateCapabilityMap(const char* deviceUniqueIdUTF8) // "\\?\avc#sony&dv-vcr&camcorder&dv#65b2d50301460008#{65e8773d-8f56-11d0-a3b9-00a0c9223196}\global" void DeviceInfoDS::GetProductId(const char* devicePath, char* productUniqueIdUTF8, - uint32_t productUniqueIdUTF8Length) { + uint32_t productUniqueIdUTF8Size) { *productUniqueIdUTF8 = '\0'; char* startPos = strstr((char*)devicePath, "\\\\?\\"); if (!startPos) { - strncpy_s((char*)productUniqueIdUTF8, productUniqueIdUTF8Length, "", 1); + strncpy_s((char*)productUniqueIdUTF8, productUniqueIdUTF8Size, "", 1); RTC_LOG(LS_INFO) << "Failed to get the product Id"; return; } @@ -625,19 +625,19 @@ void DeviceInfoDS::GetProductId(const char* devicePath, char* pos = strchr(startPos, '&'); if (!pos || pos >= (char*)devicePath + strlen((char*)devicePath)) { - strncpy_s((char*)productUniqueIdUTF8, productUniqueIdUTF8Length, "", 1); + strncpy_s((char*)productUniqueIdUTF8, productUniqueIdUTF8Size, "", 1); RTC_LOG(LS_INFO) << "Failed to get the product Id"; return; } // Find the second occurrence. pos = strchr(pos + 1, '&'); uint32_t bytesToCopy = (uint32_t)(pos - startPos); - if (pos && (bytesToCopy <= productUniqueIdUTF8Length) && - bytesToCopy <= kVideoCaptureProductIdLength) { - strncpy_s((char*)productUniqueIdUTF8, productUniqueIdUTF8Length, + if (pos && (bytesToCopy < productUniqueIdUTF8Size) && + bytesToCopy < kVideoCaptureProductIdSize) { + strncpy_s((char*)productUniqueIdUTF8, productUniqueIdUTF8Size, (char*)startPos, bytesToCopy); } else { - strncpy_s((char*)productUniqueIdUTF8, productUniqueIdUTF8Length, "", 1); + strncpy_s((char*)productUniqueIdUTF8, productUniqueIdUTF8Size, "", 1); RTC_LOG(LS_INFO) << "Failed to get the product Id"; } } diff --git a/media/webrtc/trunk/webrtc/modules/video_capture/windows/video_capture_ds.cc b/media/webrtc/trunk/webrtc/modules/video_capture/windows/video_capture_ds.cc index b9d03858ff9c..df46f58606ff 100644 --- a/media/webrtc/trunk/webrtc/modules/video_capture/windows/video_capture_ds.cc +++ b/media/webrtc/trunk/webrtc/modules/video_capture/windows/video_capture_ds.cc @@ -57,7 +57,7 @@ VideoCaptureDS::~VideoCaptureDS() { int32_t VideoCaptureDS::Init(const char* deviceUniqueIdUTF8) { const int32_t nameLength = (int32_t)strlen((char*)deviceUniqueIdUTF8); - if (nameLength > kVideoCaptureUniqueNameLength) + if (nameLength >= kVideoCaptureUniqueNameSize) return -1; // Store the device name