summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart@ideasonboard.com>2018-06-09 02:45:00 +0300
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2018-06-09 02:55:47 +0300
commit2483a44374433299866b0c16e35ccea40b5379e5 (patch)
tree4e0db44dcd69a39e93f8f7f5be8255b307a88b18
parent3e5b2d028c743f8e6f22aae74471a2f1be25d120 (diff)
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 <laurent.pinchart@ideasonboard.com>
-rw-r--r--stream.c21
-rw-r--r--stream.h5
-rw-r--r--uvc.c20
-rw-r--r--uvc.h1
4 files changed, 30 insertions, 17 deletions
diff --git a/stream.c b/stream.c
index ba9a924..d7d061a 100644
--- a/stream.c
+++ b/stream.c
@@ -167,29 +167,20 @@ void uvc_stream_enable(struct uvc_stream *stream, int enable)
}
}
-int uvc_stream_set_format(struct uvc_stream *stream)
+int uvc_stream_set_format(struct uvc_stream *stream,
+ const struct v4l2_pix_format *format)
{
- struct v4l2_device *cap = stream->cap;
- struct uvc_device *dev = stream->uvc;
- struct v4l2_pix_format fmt;
+ struct v4l2_pix_format fmt = *format;
int ret;
printf("Setting format to 0x%08x %ux%u\n",
- dev->fcc, dev->width, dev->height);
-
- memset(&fmt, 0, sizeof fmt);
- fmt.width = dev->width;
- fmt.height = dev->height;
- fmt.pixelformat = dev->fcc;
- fmt.field = V4L2_FIELD_NONE;
- if (dev->fcc == V4L2_PIX_FMT_MJPEG)
- fmt.sizeimage = dev->maxsize * 1.5;
+ format->pixelformat, format->width, format->height);
- ret = v4l2_set_format(dev->vdev, &fmt);
+ ret = uvc_set_format(stream->uvc, &fmt);
if (ret < 0)
return ret;
- return v4l2_set_format(cap, &fmt);
+ return v4l2_set_format(stream->cap, &fmt);
}
/* ---------------------------------------------------------------------------
diff --git a/stream.h b/stream.h
index c9694e7..6eb6731 100644
--- a/stream.h
+++ b/stream.h
@@ -23,6 +23,7 @@
struct events;
struct uvc_function_config;
struct uvc_stream;
+struct v4l2_pix_format;
/*
* uvc_stream_new - Create a new UVC stream
@@ -87,13 +88,15 @@ void uvc_stream_delete(struct uvc_stream *stream);
/*
* uvc_stream_set_format - Set the active video format for the stream
* @stream: the UVC stream
+ * @format: the video stream format
*
* This function is called from the UVC protocol handler to configure the video
* format for 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_format(struct uvc_stream *stream);
+int uvc_stream_set_format(struct uvc_stream *stream,
+ const struct v4l2_pix_format *format);
/*
* uvc_stream_enable - Turn on/off video streaming for the UVC stream
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);
+}
diff --git a/uvc.h b/uvc.h
index c1138bf..f73ff70 100644
--- a/uvc.h
+++ b/uvc.h
@@ -49,5 +49,6 @@ struct uvc_device *uvc_open(const char *devname, struct uvc_stream *stream);
void uvc_close(struct uvc_device *dev);
void uvc_events_init(struct uvc_device *dev, struct events *events);
void uvc_set_config(struct uvc_device *dev, struct uvc_function_config *fc);
+int uvc_set_format(struct uvc_device *dev, struct v4l2_pix_format *format);
#endif /* __UVC_H__ */