From 2483a44374433299866b0c16e35ccea40b5379e5 Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Sat, 9 Jun 2018 02:45:00 +0300 Subject: uvc: Add API to set video format Add a uvc_setformat() function to set the format for the UVC video stream instead of accessing the internals of the uvc_device in stream.c. Signed-off-by: Laurent Pinchart --- uvc.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'uvc.c') diff --git a/uvc.c b/uvc.c index 0a276a4..fc28482 100644 --- a/uvc.c +++ b/uvc.c @@ -260,6 +260,7 @@ uvc_events_process_data(struct uvc_device *dev, if (dev->control == UVC_VS_COMMIT_CONTROL) { const struct uvc_function_config_format *format; const struct uvc_function_config_frame *frame; + struct v4l2_pix_format pixfmt; format = &dev->fc->streaming.formats[target->bFormatIndex-1]; frame = &format->frames[target->bFrameIndex-1]; @@ -268,7 +269,15 @@ uvc_events_process_data(struct uvc_device *dev, dev->width = frame->width; dev->height = frame->height; - uvc_stream_set_format(dev->stream); + memset(&pixfmt, 0, sizeof pixfmt); + pixfmt.width = frame->width; + pixfmt.height = frame->height; + pixfmt.pixelformat = format->fcc; + pixfmt.field = V4L2_FIELD_NONE; + if (format->fcc == V4L2_PIX_FMT_MJPEG) + pixfmt.sizeimage = dev->maxsize * 1.5; + + uvc_stream_set_format(dev->stream, &pixfmt); } } @@ -320,6 +329,10 @@ static void uvc_events_process(void *d) } } +/* --------------------------------------------------------------------------- + * Initialization and setup + */ + void uvc_events_init(struct uvc_device *dev, struct events *events) { struct v4l2_event_subscription sub; @@ -346,3 +359,8 @@ void uvc_set_config(struct uvc_device *dev, struct uvc_function_config *fc) { dev->fc = fc; } + +int uvc_set_format(struct uvc_device *dev, struct v4l2_pix_format *format) +{ + return v4l2_set_format(dev->vdev, format); +} -- cgit v1.2.3