summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Elder <paul.elder@ideasonboard.com>2018-08-28 02:17:15 -0400
committerPaul Elder <paul.elder@ideasonboard.com>2019-02-06 01:49:31 -0500
commitbde4deb8803026ec69e11cd380d77bf5d33ee623 (patch)
tree779af4610ffc29499b7d4b672c7a5e75c4cadeb2
parent28c16c6dc72f4c41307f1a317860791c595cdcd6 (diff)
stream, uvc: add uvc_stream_set_frame_rate
We would like to be able to set the frame rate of the video source of a stream. This patch adds such a function to set the source's frame rate from the stream. The frame rate is set right after the format is set. Signed-off-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
-rw-r--r--include/uvcgadget/stream.h13
-rw-r--r--lib/stream.c6
-rw-r--r--lib/uvc.c5
3 files changed, 24 insertions, 0 deletions
diff --git a/include/uvcgadget/stream.h b/include/uvcgadget/stream.h
index 9ab068f..bc83cfa 100644
--- a/include/uvcgadget/stream.h
+++ b/include/uvcgadget/stream.h
@@ -91,6 +91,19 @@ int uvc_stream_set_format(struct uvc_stream *stream,
const struct v4l2_pix_format *format);
/*
+ * uvc_stream_set_frame_rate - Set the frame rate for the stream
+ * @stream: the UVC stream
+ * @fps: the frame rate in frames per second
+ *
+ * This function is called from the UVC protocol handler to configure the frame
+ * rate for the video source of the @stream. It must not be called directly by
+ * applications.
+ *
+ * Returns 0 on success, or a negative error code on failure.
+ */
+int uvc_stream_set_frame_rate(struct uvc_stream *stream, unsigned int fps);
+
+/*
* uvc_stream_enable - Turn on/off video streaming for the UVC stream
* @stream: the UVC stream
* @enable: 0 to stop the stream, 1 to start it
diff --git a/lib/stream.c b/lib/stream.c
index 19f0d78..168dc71 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -156,6 +156,12 @@ int uvc_stream_set_format(struct uvc_stream *stream,
return video_source_set_format(stream->src, &fmt);
}
+int uvc_stream_set_frame_rate(struct uvc_stream *stream, unsigned int fps)
+{
+ printf("=== Setting frame rate to %u fps\n", fps);
+ return video_source_set_frame_rate(stream->src, fps);
+}
+
/* ---------------------------------------------------------------------------
* Stream handling
*/
diff --git a/lib/uvc.c b/lib/uvc.c
index 695db5b..ab03f0e 100644
--- a/lib/uvc.c
+++ b/lib/uvc.c
@@ -269,6 +269,7 @@ uvc_events_process_data(struct uvc_device *dev,
const struct uvc_function_config_format *format;
const struct uvc_function_config_frame *frame;
struct v4l2_pix_format pixfmt;
+ unsigned int fps;
format = &dev->fc->streaming.formats[target->bFormatIndex-1];
frame = &format->frames[target->bFrameIndex-1];
@@ -286,6 +287,10 @@ uvc_events_process_data(struct uvc_device *dev,
pixfmt.sizeimage = dev->maxsize * 1.5;
uvc_stream_set_format(dev->stream, &pixfmt);
+
+ /* fps is guaranteed to be non-zero and thus valid. */
+ fps = 1.0 / (target->dwFrameInterval / 10000000.0);
+ uvc_stream_set_frame_rate(dev->stream, fps);
}
}