[PATCH] Support of /dev/video read with USB camera devices

From: Hugues Fruchet
Date: Mon Mar 04 2019 - 07:35:59 EST


Currently, read() call from /dev/video entry of an USB camera is
returning invalid argument error.
This is quite common for userspace application to read compressed data such as
JPEG from /dev/video then redirect those data to a multimedia player or any
other compressed format consumer, see [1].

There was a tentative of implementation in the past [2] but it was prior to
switch on vb2 helpers usage inside uvc.
Now that vb2 is in place, we can implement read support using vb2_read()
helper.

Tested with Logitech HD Webcam C525 using v4l2-ctl to configure camera
then GStreamer player to play stream:
$> v4l2-ctl -d /dev/video0 --set-fmt-video=width=640,height=480,pixelformat=MJPG
$> gst-play-1.0 /dev/video0

[1]
http://credentiality2.blogspot.com/2010/04/v4l2-example.html?_sm_au_=ikcQHNZZFn2Rqft5
https://stackoverrun.com/fr/q/4215615
https://stackoverflow.com/questions/36297390/read-function-for-webcam-device-in-v4l2-fails-with-invalid-argument
https://stackoverflow.com/questions/31058571/reading-camera-input-from-dev-video0-in-python-or-c

[2] https://www.mail-archive.com/linux-uvc-devel@xxxxxxxxxxxxxxxx/msg01258.html

Hugues Fruchet (1):
media: uvcvideo: Read support

drivers/media/usb/uvc/uvc_queue.c | 15 ++++++++++++++-
drivers/media/usb/uvc/uvc_v4l2.c | 11 ++++++++---
drivers/media/usb/uvc/uvcvideo.h | 2 ++
3 files changed, 24 insertions(+), 4 deletions(-)

--
2.7.4