summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Grzeschik <m.grzeschik@pengutronix.de>2021-05-18 20:57:51 +0200
committerMichael Grzeschik <m.grzeschik@pengutronix.de>2022-01-26 14:02:16 +0100
commit361e84e5268035e1813bc6192f168c3af8aa9b84 (patch)
treeede46cfb1f112babee38ba401ec694ffd356db80
parent784c07c0f6cb37951db6c8cec602cbde82732793 (diff)
downloaduvc-gadget-ml.tar.gz
uvc-gadget-ml.tar.xz
uvc, stream: remove DATA/SETUP event handlingml
-rw-r--r--lib/stream.c22
-rw-r--r--lib/uvc.c262
-rw-r--r--lib/uvc.h1
3 files changed, 0 insertions, 285 deletions
diff --git a/lib/stream.c b/lib/stream.c
index 168dc71..4024d5e 100644
--- a/lib/stream.c
+++ b/lib/stream.c
@@ -140,28 +140,6 @@ void uvc_stream_enable(struct uvc_stream *stream, int enable)
uvc_stream_stop(stream);
}
-int uvc_stream_set_format(struct uvc_stream *stream,
- const struct v4l2_pix_format *format)
-{
- struct v4l2_pix_format fmt = *format;
- int ret;
-
- printf("Setting format to 0x%08x %ux%u\n",
- format->pixelformat, format->width, format->height);
-
- ret = uvc_set_format(stream->uvc, &fmt);
- if (ret < 0)
- return ret;
-
- 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 975413a..d3ed317 100644
--- a/lib/uvc.c
+++ b/lib/uvc.c
@@ -30,16 +30,6 @@ struct uvc_device
struct uvc_stream *stream;
struct uvc_function_config *fc;
-
- struct uvc_streaming_control probe;
- struct uvc_streaming_control commit;
-
- int control;
-
- unsigned int fcc;
- unsigned int width;
- unsigned int height;
- unsigned int maxsize;
};
struct uvc_device *uvc_open(const char *devname, struct uvc_stream *stream)
@@ -70,238 +60,10 @@ void uvc_close(struct uvc_device *dev)
free(dev);
}
-/* ---------------------------------------------------------------------------
- * Request processing
- */
-
-static void
-uvc_fill_streaming_control(struct uvc_device *dev,
- struct uvc_streaming_control *ctrl,
- int iformat, int iframe, unsigned int ival)
-{
- const struct uvc_function_config_format *format;
- const struct uvc_function_config_frame *frame;
- unsigned int i;
-
- /*
- * Restrict the iformat, iframe and ival to valid values. Negative
- * values for iformat or iframe will result in the maximum valid value
- * being selected.
- */
- iformat = clamp((unsigned int)iformat, 1U,
- dev->fc->streaming.num_formats);
- format = &dev->fc->streaming.formats[iformat-1];
-
- iframe = clamp((unsigned int)iframe, 1U, format->num_frames);
- frame = &format->frames[iframe-1];
-
- for (i = 0; i < frame->num_intervals; ++i) {
- if (ival <= frame->intervals[i]) {
- ival = frame->intervals[i];
- break;
- }
- }
-
- if (i == frame->num_intervals)
- ival = frame->intervals[frame->num_intervals-1];
-
- memset(ctrl, 0, sizeof *ctrl);
-
- ctrl->bmHint = 1;
- ctrl->bFormatIndex = iformat;
- ctrl->bFrameIndex = iframe ;
- ctrl->dwFrameInterval = ival;
-
- switch (format->fcc) {
- case V4L2_PIX_FMT_YUYV:
- ctrl->dwMaxVideoFrameSize = frame->width * frame->height * 2;
- break;
- case V4L2_PIX_FMT_MJPEG:
- ctrl->dwMaxVideoFrameSize = dev->maxsize;
- break;
- }
-
- ctrl->dwMaxPayloadTransferSize = dev->fc->streaming.ep.wMaxPacketSize;
- ctrl->bmFramingInfo = 3;
- ctrl->bPreferedVersion = 1;
- ctrl->bMaxVersion = 1;
-}
-
-static void
-uvc_events_process_standard(struct uvc_device *dev,
- const struct usb_ctrlrequest *ctrl,
- struct uvc_request_data *resp)
-{
- printf("standard request\n");
- (void)dev;
- (void)ctrl;
- (void)resp;
-}
-
-static void
-uvc_events_process_control(struct uvc_device *dev, uint8_t req, uint8_t cs,
- struct uvc_request_data *resp)
-{
- printf("control request (req %02x cs %02x)\n", req, cs);
- (void)dev;
- (void)resp;
-}
-
-static void
-uvc_events_process_streaming(struct uvc_device *dev, uint8_t req, uint8_t cs,
- struct uvc_request_data *resp)
-{
- struct uvc_streaming_control *ctrl;
-
- printf("streaming request (req %02x cs %02x)\n", req, cs);
-
- if (cs != UVC_VS_PROBE_CONTROL && cs != UVC_VS_COMMIT_CONTROL)
- return;
-
- ctrl = (struct uvc_streaming_control *)&resp->data;
- resp->length = sizeof *ctrl;
-
- switch (req) {
- case UVC_SET_CUR:
- dev->control = cs;
- resp->length = 34;
- break;
-
- case UVC_GET_CUR:
- if (cs == UVC_VS_PROBE_CONTROL)
- memcpy(ctrl, &dev->probe, sizeof *ctrl);
- else
- memcpy(ctrl, &dev->commit, sizeof *ctrl);
- break;
-
- case UVC_GET_MIN:
- case UVC_GET_MAX:
- case UVC_GET_DEF:
- if (req == UVC_GET_MAX)
- uvc_fill_streaming_control(dev, ctrl, -1, -1, UINT_MAX);
- else
- uvc_fill_streaming_control(dev, ctrl, 1, 1, 0);
- break;
-
- case UVC_GET_RES:
- memset(ctrl, 0, sizeof *ctrl);
- break;
-
- case UVC_GET_LEN:
- resp->data[0] = 0x00;
- resp->data[1] = 0x22;
- resp->length = 2;
- break;
-
- case UVC_GET_INFO:
- resp->data[0] = 0x03;
- resp->length = 1;
- break;
- }
-}
-
-static void
-uvc_events_process_class(struct uvc_device *dev,
- const struct usb_ctrlrequest *ctrl,
- struct uvc_request_data *resp)
-{
- unsigned int interface = ctrl->wIndex & 0xff;
-
- if ((ctrl->bRequestType & USB_RECIP_MASK) != USB_RECIP_INTERFACE)
- return;
-
- if (interface == dev->fc->control.intf.bInterfaceNumber)
- uvc_events_process_control(dev, ctrl->bRequest, ctrl->wValue >> 8, resp);
- else if (interface == dev->fc->streaming.intf.bInterfaceNumber)
- uvc_events_process_streaming(dev, ctrl->bRequest, ctrl->wValue >> 8, resp);
-}
-
-static void
-uvc_events_process_setup(struct uvc_device *dev,
- const struct usb_ctrlrequest *ctrl,
- struct uvc_request_data *resp)
-{
- dev->control = 0;
-
- printf("bRequestType %02x bRequest %02x wValue %04x wIndex %04x "
- "wLength %04x\n", ctrl->bRequestType, ctrl->bRequest,
- ctrl->wValue, ctrl->wIndex, ctrl->wLength);
-
- switch (ctrl->bRequestType & USB_TYPE_MASK) {
- case USB_TYPE_STANDARD:
- uvc_events_process_standard(dev, ctrl, resp);
- break;
-
- case USB_TYPE_CLASS:
- uvc_events_process_class(dev, ctrl, resp);
- break;
-
- default:
- break;
- }
-}
-
-static void
-uvc_events_process_data(struct uvc_device *dev,
- const struct uvc_request_data *data)
-{
- const struct uvc_streaming_control *ctrl =
- (const struct uvc_streaming_control *)&data->data;
- struct uvc_streaming_control *target;
-
- switch (dev->control) {
- case UVC_VS_PROBE_CONTROL:
- printf("setting probe control, length = %d\n", data->length);
- target = &dev->probe;
- break;
-
- case UVC_VS_COMMIT_CONTROL:
- printf("setting commit control, length = %d\n", data->length);
- target = &dev->commit;
- break;
-
- default:
- printf("setting unknown control, length = %d\n", data->length);
- return;
- }
-
- uvc_fill_streaming_control(dev, target, ctrl->bFormatIndex,
- ctrl->bFrameIndex, ctrl->dwFrameInterval);
-
- 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;
- unsigned int fps;
-
- format = &dev->fc->streaming.formats[target->bFormatIndex-1];
- frame = &format->frames[target->bFrameIndex-1];
-
- dev->fcc = format->fcc;
- dev->width = frame->width;
- dev->height = frame->height;
-
- 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);
-
- /* 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);
- }
-}
-
static void uvc_events_process(void *d)
{
struct uvc_device *dev = d;
struct v4l2_event v4l2_event;
- const struct uvc_event *uvc_event = (void *)&v4l2_event.u.data;
struct uvc_request_data resp;
int ret;
@@ -316,18 +78,6 @@ static void uvc_events_process(void *d)
resp.length = -EL2HLT;
switch (v4l2_event.type) {
- case UVC_EVENT_CONNECT:
- case UVC_EVENT_DISCONNECT:
- return;
-
- case UVC_EVENT_SETUP:
- uvc_events_process_setup(dev, &uvc_event->req, &resp);
- break;
-
- case UVC_EVENT_DATA:
- uvc_events_process_data(dev, &uvc_event->data);
- return;
-
case UVC_EVENT_STREAMON:
uvc_stream_enable(dev->stream, 1);
return;
@@ -353,15 +103,9 @@ void uvc_events_init(struct uvc_device *dev, struct events *events)
{
struct v4l2_event_subscription sub;
- /* Default to the minimum values. */
- uvc_fill_streaming_control(dev, &dev->probe, 1, 1, 0);
- uvc_fill_streaming_control(dev, &dev->commit, 1, 1, 0);
-
memset(&sub, 0, sizeof sub);
sub.type = UVC_EVENT_SETUP;
ioctl(dev->vdev->fd, VIDIOC_SUBSCRIBE_EVENT, &sub);
- sub.type = UVC_EVENT_DATA;
- ioctl(dev->vdev->fd, VIDIOC_SUBSCRIBE_EVENT, &sub);
sub.type = UVC_EVENT_STREAMON;
ioctl(dev->vdev->fd, VIDIOC_SUBSCRIBE_EVENT, &sub);
sub.type = UVC_EVENT_STREAMOFF;
@@ -374,15 +118,9 @@ void uvc_events_init(struct uvc_device *dev, struct events *events)
void uvc_set_config(struct uvc_device *dev, struct uvc_function_config *fc)
{
/* FIXME: The maximum size should be specified per format and frame. */
- dev->maxsize = 0;
dev->fc = fc;
}
-int uvc_set_format(struct uvc_device *dev, struct v4l2_pix_format *format)
-{
- return v4l2_set_format(dev->vdev, format);
-}
-
struct v4l2_device *uvc_v4l2_device(struct uvc_device *dev)
{
/*
diff --git a/lib/uvc.h b/lib/uvc.h
index f888a84..a03cf14 100644
--- a/lib/uvc.h
+++ b/lib/uvc.h
@@ -20,7 +20,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);
struct v4l2_device *uvc_v4l2_device(struct uvc_device *dev);
#endif /* __UVC_H__ */