Fixing Coverity issues

Note: This doesn't address Google Code style guidelines issues.
Review URL: https://webrtc-codereview.appspot.com/391011

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1707 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
mallinath@webrtc.org
2012-02-16 18:18:21 +00:00
parent 3ab6dda5cb
commit 12984f0d02
6 changed files with 61 additions and 74 deletions

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source * that can be found in the LICENSE file in the root of the source
@@ -61,7 +61,7 @@ class VideoCaptureModule: public RefCountedModule {
// Returns the deviceCapabilityNumber on success. // Returns the deviceCapabilityNumber on success.
virtual WebRtc_Word32 GetBestMatchedCapability( virtual WebRtc_Word32 GetBestMatchedCapability(
const WebRtc_UWord8*deviceUniqueIdUTF8, const WebRtc_UWord8*deviceUniqueIdUTF8,
const VideoCaptureCapability requested, const VideoCaptureCapability& requested,
VideoCaptureCapability& resulting) = 0; VideoCaptureCapability& resulting) = 0;
// Display OS /capture device specific settings dialog // Display OS /capture device specific settings dialog

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source * that can be found in the LICENSE file in the root of the source
@@ -10,7 +10,6 @@
#include "device_info_linux.h" #include "device_info_linux.h"
#include <sys/stat.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
@@ -68,15 +67,11 @@ WebRtc_UWord32 DeviceInfoLinux::NumberOfDevices()
/* detect /dev/video [0-63]VideoCaptureModule entries */ /* detect /dev/video [0-63]VideoCaptureModule entries */
for (int n = 0; n < 64; n++) for (int n = 0; n < 64; n++)
{ {
struct stat s;
sprintf(device, "/dev/video%d", n); sprintf(device, "/dev/video%d", n);
if (stat(device, &s) == 0) //check validity of path if ((fd = open(device, O_RDONLY)) != -1)
{ {
if ((fd = open(device, O_RDONLY)) != -1) close(fd);
{ count++;
close(fd);
count++;
}
} }
} }
@@ -101,20 +96,16 @@ WebRtc_Word32 DeviceInfoLinux::GetDeviceName(
bool found = false; bool found = false;
for (int n = 0; n < 64; n++) for (int n = 0; n < 64; n++)
{ {
struct stat s;
sprintf(device, "/dev/video%d", n); sprintf(device, "/dev/video%d", n);
if (stat(device, &s) == 0) // Check validity of path if ((fd = open(device, O_RDONLY)) != -1)
{ {
if ((fd = open(device, O_RDONLY)) != -1) if (count == deviceNumber) {
{ // Found the device
if (count == deviceNumber) { found = true;
// Found the device break;
found = true; } else {
break; close(fd);
} else { count++;
close(fd);
count++;
}
} }
} }
} }
@@ -187,41 +178,38 @@ WebRtc_Word32 DeviceInfoLinux::CreateCapabilityMap(
"CreateCapabilityMap called for device %s", deviceUniqueIdUTF8); "CreateCapabilityMap called for device %s", deviceUniqueIdUTF8);
/* detect /dev/video [0-63] entries */ /* detect /dev/video [0-63] entries */
for (int n = 0; n < 64; n++) for (int n = 0; n < 64; ++n)
{ {
struct stat s;
sprintf(device, "/dev/video%d", n); sprintf(device, "/dev/video%d", n);
if (stat(device, &s) == 0) //check validity of path fd = open(device, O_RDONLY);
if (fd == -1)
continue;
// query device capabilities
struct v4l2_capability cap;
if (ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
{ {
if ((fd = open(device, O_RDONLY)) > 0) if (cap.bus_info[0] != 0)
{ {
// query device capabilities if (strncmp((const char*) cap.bus_info,
struct v4l2_capability cap; (const char*) deviceUniqueIdUTF8,
if (ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0) strlen((const char*) deviceUniqueIdUTF8)) == 0) //match with device id
{ {
if (cap.bus_info[0] != 0) found = true;
{ break; // fd matches with device unique id supplied
if (strncmp((const char*) cap.bus_info, }
(const char*) deviceUniqueIdUTF8, }
strlen((const char*) deviceUniqueIdUTF8)) == 0) //match with device id else //match for device name
{ {
found = true; if (IsDeviceNameMatches((const char*) cap.card,
break; // fd matches with device unique id supplied (const char*) deviceUniqueIdUTF8))
} {
} found = true;
else //match for device name break;
{
if (IsDeviceNameMatches((const char*) cap.card,
(const char*) deviceUniqueIdUTF8))
{
found = true;
break;
}
}
} }
close(fd); // close since this is not the matching device
} }
} }
close(fd); // close since this is not the matching device
} }
if (!found) if (!found)

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source * that can be found in the LICENSE file in the root of the source
@@ -50,7 +50,8 @@ VideoCaptureModuleV4L2::VideoCaptureModuleV4L2(const WebRtc_Word32 id)
: VideoCaptureImpl(id), _captureThread(NULL), : VideoCaptureImpl(id), _captureThread(NULL),
_captureCritSect(CriticalSectionWrapper::CreateCriticalSection()), _captureCritSect(CriticalSectionWrapper::CreateCriticalSection()),
_deviceId(-1), _currentWidth(-1), _currentHeight(-1), _deviceId(-1), _currentWidth(-1), _currentHeight(-1),
_currentFrameRate(-1), _captureStarted(false), _captureVideoType(kVideoI420) _currentFrameRate(-1), _captureStarted(false),
_captureVideoType(kVideoI420), pool(NULL)
{ {
} }
@@ -71,30 +72,26 @@ WebRtc_Word32 VideoCaptureModuleV4L2::Init(const WebRtc_UWord8* deviceUniqueIdUT
int n; int n;
for (n = 0; n < 64; n++) for (n = 0; n < 64; n++)
{ {
struct stat s;
sprintf(device, "/dev/video%d", n); sprintf(device, "/dev/video%d", n);
if (stat(device, &s) == 0) //check validity of path if ((fd = open(device, O_RDONLY)) != -1)
{ {
if ((fd = open(device, O_RDONLY)) > 0) // query device capabilities
struct v4l2_capability cap;
if (ioctl(fd, VIDIOC_QUERYCAP, &cap) == 0)
{ {
// query device capabilities if (cap.bus_info[0] != 0)
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
{ {
if (strncmp((const char*) cap.bus_info, close(fd);
(const char*) deviceUniqueIdUTF8, found = true;
strlen((const char*) deviceUniqueIdUTF8)) == 0) //match with device id break; // fd matches with device unique id supplied
{
close(fd);
found = true;
break; // fd matches with device unique id supplied
}
} }
} }
close(fd); // close since this is not the matching device
} }
close(fd); // close since this is not the matching device
} }
} }
if (!found) if (!found)

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source * that can be found in the LICENSE file in the root of the source
@@ -149,7 +149,7 @@ WebRtc_Word32 DeviceInfoImpl::GetCapability(const WebRtc_UWord8* deviceUniqueIdU
WebRtc_Word32 DeviceInfoImpl::GetBestMatchedCapability( WebRtc_Word32 DeviceInfoImpl::GetBestMatchedCapability(
const WebRtc_UWord8*deviceUniqueIdUTF8, const WebRtc_UWord8*deviceUniqueIdUTF8,
const VideoCaptureCapability requested, const VideoCaptureCapability& requested,
VideoCaptureCapability& resulting) VideoCaptureCapability& resulting)
{ {

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source * that can be found in the LICENSE file in the root of the source
@@ -32,7 +32,7 @@ public:
VideoCaptureCapability& capability); VideoCaptureCapability& capability);
virtual WebRtc_Word32 GetBestMatchedCapability(const WebRtc_UWord8*deviceUniqueIdUTF8, virtual WebRtc_Word32 GetBestMatchedCapability(const WebRtc_UWord8*deviceUniqueIdUTF8,
const VideoCaptureCapability requested, const VideoCaptureCapability& requested,
VideoCaptureCapability& resulting); VideoCaptureCapability& resulting);
virtual WebRtc_Word32 GetOrientation(const WebRtc_UWord8* deviceUniqueIdUTF8, virtual WebRtc_Word32 GetOrientation(const WebRtc_UWord8* deviceUniqueIdUTF8,
VideoCaptureRotation& orientation); VideoCaptureRotation& orientation);

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source * that can be found in the LICENSE file in the root of the source
@@ -136,7 +136,9 @@ VideoCaptureImpl::VideoCaptureImpl(const WebRtc_Word32 id)
_lastProcessTime(TickTime::Now()), _lastProcessTime(TickTime::Now()),
_lastFrameRateCallbackTime(TickTime::Now()), _frameRateCallBack(false), _lastFrameRateCallbackTime(TickTime::Now()), _frameRateCallBack(false),
_noPictureAlarmCallBack(false), _captureAlarm(Cleared), _setCaptureDelay(0), _noPictureAlarmCallBack(false), _captureAlarm(Cleared), _setCaptureDelay(0),
_dataCallBack(NULL), _captureCallBack(NULL), _startImageFrameIntervall(0), _dataCallBack(NULL), _captureCallBack(NULL),
_startImage(), _startImageFrameIntervall(0),
_lastSentStartImageTime(TickTime::Now()),
_lastProcessFrameCount(TickTime::Now()), _rotateFrame(kRotateNone), _lastProcessFrameCount(TickTime::Now()), _rotateFrame(kRotateNone),
last_capture_time_(TickTime::MillisecondTimestamp()) last_capture_time_(TickTime::MillisecondTimestamp())