Bug 1598543 - Cleanup upstream constants to also use size instead of length. r=dminor

Depends on D58144

Differential Revision: https://phabricator.services.mozilla.com/D58157

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jan-Ivar Bruaroey 2020-01-21 21:59:35 +00:00
Родитель db29649dbd
Коммит f79191282b
9 изменённых файлов: 54 добавлений и 55 удалений

Просмотреть файл

@ -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<char*>(kDeviceName);
deviceUniqueIdUTF8 = const_cast<char*>(kUniqueDeviceName);

Просмотреть файл

@ -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

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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.

Просмотреть файл

@ -51,7 +51,7 @@ rtc::scoped_refptr<VideoCaptureModule> VideoCaptureIos::Create(
new rtc::RefCountedObject<VideoCaptureIos>());
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];

Просмотреть файл

@ -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;

Просмотреть файл

@ -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
{

Просмотреть файл

@ -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<int>(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";
}
}

Просмотреть файл

@ -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