This change will allow us to set proper frame rate for the camera on Linux. Earlier we were setting based on the resolution irrespective of input frame rate.
Review URL: https://webrtc-codereview.appspot.com/692006
git-svn-id: http://webrtc.googlecode.com/svn/trunk@2545 4adac7df-926f-26a2-2b94-8c16560cd09d
diff --git a/src/modules/video_capture/main/source/Linux/video_capture_linux.cc b/src/modules/video_capture/main/source/Linux/video_capture_linux.cc
index 2c690e9..d3033b6 100644
--- a/src/modules/video_capture/main/source/Linux/video_capture_linux.cc
+++ b/src/modules/video_capture/main/source/Linux/video_capture_linux.cc
@@ -122,7 +122,7 @@
}
WebRtc_Word32 VideoCaptureModuleV4L2::StartCapture(
- const VideoCaptureCapability& capability)
+ const VideoCaptureCapability& capability)
{
if (_captureStarted)
{
@@ -212,11 +212,43 @@
_currentWidth = video_fmt.fmt.pix.width;
_currentHeight = video_fmt.fmt.pix.height;
_captureDelay = 120;
- // No way of knowing frame rate, make a guess.
- if(_currentWidth >= 800 && _captureVideoType != kVideoMJPEG)
- _currentFrameRate = 15;
- else
- _currentFrameRate = 30;
+
+ // Trying to set frame rate, before check driver capability.
+ bool driver_framerate_support = true;
+ struct v4l2_streamparm streamparms;
+ memset(&streamparms, 0, sizeof(streamparms));
+ streamparms.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ if (ioctl(_deviceFd, VIDIOC_G_PARM, &streamparms) < 0) {
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id,
+ "error in VIDIOC_G_PARM errno = %d", errno);
+ driver_framerate_support = false;
+ // continue
+ } else {
+ // check the capability flag is set to V4L2_CAP_TIMEPERFRAME.
+ if (streamparms.parm.capture.capability == V4L2_CAP_TIMEPERFRAME) {
+ // driver supports the feature. Set required framerate.
+ memset(&streamparms, 0, sizeof(streamparms));
+ streamparms.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+ streamparms.parm.capture.timeperframe.numerator = 1;
+ streamparms.parm.capture.timeperframe.denominator = capability.maxFPS;
+ if (ioctl(_deviceFd, VIDIOC_S_PARM, &streamparms) < 0) {
+ WEBRTC_TRACE(webrtc::kTraceError, webrtc::kTraceVideoCapture, _id,
+ "Failed to set the framerate. errno=%d", errno);
+ driver_framerate_support = false;
+ } else {
+ _currentFrameRate = capability.maxFPS;
+ }
+ }
+ }
+ // If driver doesn't support framerate control, need to hardcode.
+ // Hardcoding the value based on the frame size.
+ if (!driver_framerate_support) {
+ if(_currentWidth >= 800 && _captureVideoType != kVideoMJPEG) {
+ _currentFrameRate = 15;
+ } else {
+ _currentFrameRate = 30;
+ }
+ }
if (!AllocateVideoBuffers())
{