uvc-gadget: Dynamically watch/unwatch uvc device fd
authorPaul Elder <paul.elder@ideasonboard.com>
Mon, 21 May 2018 15:45:17 +0000 (23:45 +0800)
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>
Mon, 21 May 2018 18:27:39 +0000 (21:27 +0300)
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 <paul.elder@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
uvc-gadget.c

index 31dbbf6..7d6c20a 100644 (file)
@@ -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);