From 349679083d1f1053ee79cc933e0e41c48ce05fb9 Mon Sep 17 00:00:00 2001 From: Paul Elder Date: Mon, 21 May 2018 23:45:17 +0800 Subject: uvc-gadget: Dynamically watch/unwatch uvc device fd When the uvc device fd is put on the watch list statically, then there are many "Unable to dequeue buffer: Invalid argument (22)." because the V4L2 API returns write events immediately when the stream is off. To fix this, add the fd to the watch list on streamon, and remove it on streamoff. Signed-off-by: Paul Elder Signed-off-by: Laurent Pinchart --- uvc-gadget.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'uvc-gadget.c') diff --git a/uvc-gadget.c b/uvc-gadget.c index 31dbbf6..7d6c20a 100644 --- a/uvc-gadget.c +++ b/uvc-gadget.c @@ -251,6 +251,7 @@ uvc_video_stream(struct uvc_device *dev, int enable) if (!enable) { printf("Stopping video stream.\n"); + events_unwatch_fd(&dev->events, dev->fd, EVENT_WRITE); ioctl(dev->fd, VIDIOC_STREAMOFF, &type); return 0; } @@ -275,6 +276,8 @@ uvc_video_stream(struct uvc_device *dev, int enable) } ioctl(dev->fd, VIDIOC_STREAMON, &type); + events_watch_fd(&dev->events, dev->fd, EVENT_WRITE, + uvc_video_process, dev); return ret; } @@ -749,8 +752,6 @@ int main(int argc, char *argv[]) uvc_device = dev; signal(SIGINT, sigint_handler); - events_watch_fd(&dev->events, dev->fd, EVENT_WRITE, - uvc_video_process, dev); events_watch_fd(&dev->events, dev->fd, EVENT_EXCEPTION, uvc_events_process, dev); -- cgit v1.2.3