Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp2551808imb; Mon, 4 Mar 2019 08:00:20 -0800 (PST) X-Google-Smtp-Source: APXvYqzhoHnbPfNq4ipkWyFkzU4lW7uIQ4HZkdebAG2+qr26OuffQcEsrLzIPEyGcTs8HgLVicL/ X-Received: by 2002:a65:6290:: with SMTP id f16mr19068196pgv.106.1551715220496; Mon, 04 Mar 2019 08:00:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551715220; cv=none; d=google.com; s=arc-20160816; b=JM2iN6/eiLTGwt2KydGQ9UCTtinzS4PoYwrLZ5jmOjlfZSW3pyJm4i6ls5a4REaWeO ZFhJM3y/PdRLuxzFbVj2anh4LUsFpqtaFu2a8nk3UYbtlxqlFX9OjzC0/6zVLjTU3Eh6 VziOXUw7sBM7IfkZWm4C8MNP48nc56Mf+TR7t0kMUc8XcIl0lAA6XTbmvQDbwzHC+AUZ DSlJcMSDi6cDANAIIKAOScKl2aNGp33wd0mUNIW+PKKOuOYNU5zkl7F3keXrBYmrhARl MbncVGJEe4hRFghKQOoxbDw8MtfKK9vI2d0Hm197I0hwMQYKjvAzvWkTgh+fwt9i9kVX mVWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=xV2MJPuKDwZKg9LYY4AWed5cwhLt3H4fuvkXcWeFy8o=; b=bM8A3r7taqyqLAVicvVnijiDrLz+xXokxe1a0IesHTjzCvsnIqg+9+d1qnk9hDl1cu Dokt8wPRgWAZ8t/aJcQ/BEcYjYvARtCrDHPRCcOtonEBXXkZbm0c7AWkRPHJ81/1D4OQ pIB5P6/4kAp6bSP7HyPbLunz+URVJLWVEfirpXt6gRu1VGnxryGzklUTxHLq44zCkqk+ /HM2exWj/elzo4d/4H5VSSniZC16VGb2Mcm3J/09lqnlwWepds5qfTNXLe+JTy6OPJVy 4Csl/Yu0yunITzcOP0Cu+TCcNXdh6dCZXYv9Oxkb7fA+YWCH5BFmZHyeu6FOYrzQOR1T Wqjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=gVS0Kspt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 30si5837353plc.153.2019.03.04.08.00.05; Mon, 04 Mar 2019 08:00:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=gVS0Kspt; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727190AbfCDPpH (ORCPT + 99 others); Mon, 4 Mar 2019 10:45:07 -0500 Received: from perceval.ideasonboard.com ([213.167.242.64]:40708 "EHLO perceval.ideasonboard.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726162AbfCDPpG (ORCPT ); Mon, 4 Mar 2019 10:45:06 -0500 Received: from pendragon.ideasonboard.com (81-175-216-236.bb.dnainternet.fi [81.175.216.236]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6049E2F2; Mon, 4 Mar 2019 16:45:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1551714304; bh=JLbrlXXP/742VfouaVpu0f+zVOuWtXTFCRhtYi0WCIs=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=gVS0Kspt3eMiPxsspdB8rrVOjMT61fSdsjYKXPgSE5mrIn7dglaOvxpEfU/Mk8adD 4/TpdQcXZzcqaDs8LaKB4MAuItAoiML4X4S8Hp6hg2ZVTMwHpMAm9fPjWmldq5LkBL imBzgMBqdTn/YshGoaOp5hRqxfUyzjDd9kqjCC8M= Date: Mon, 4 Mar 2019 17:44:58 +0200 From: Laurent Pinchart To: Kieran Bingham Cc: Hugues Fruchet , Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] media: uvcvideo: Read support Message-ID: <20190304154458.GO6325@pendragon.ideasonboard.com> References: <1551702925-7739-1-git-send-email-hugues.fruchet@st.com> <1551702925-7739-2-git-send-email-hugues.fruchet@st.com> <8ec96fe6-96af-c101-ff20-ab59d953ad6a@ideasonboard.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <8ec96fe6-96af-c101-ff20-ab59d953ad6a@ideasonboard.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Mon, Mar 04, 2019 at 03:36:32PM +0000, Kieran Bingham wrote: > On 04/03/2019 12:35, Hugues Fruchet wrote: > > Add support of read() call from userspace by implementing > > uvc_v4l2_read() with vb2_read() helper. > > Just thinking out loud, > > This opens up UVC devices to read raw full frame images through this > interface as well. > > Due to the UVC protocol, there is /already/ a full memcpy to get these > images out of the URB packets, so using a read() interface would be > another full frame copy. > > I can perhaps see the usecase for reading compressed data through this > interface - but full frames don't seem appropriate. (not impossible of > course, just is it reasonable?) > > If this is to be enabled, should it be enabled for compressed formats > only? or would that complicate matters? I've repeatedly refused read() support in uvcvideo for this reason, and also because read() doesn't carry framing information very well. It's just not a good API for capturing video frames from a webcam, and so far I haven't heard a compeling reason why it should be enabled. I thus haven't changed my mind :-) > > Signed-off-by: Hugues Fruchet > > --- > > 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(-) > > > > diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c > > index 682698e..0c8a0a8 100644 > > --- a/drivers/media/usb/uvc/uvc_queue.c > > +++ b/drivers/media/usb/uvc/uvc_queue.c > > @@ -227,7 +227,7 @@ int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type, > > int ret; > > > > queue->queue.type = type; > > - queue->queue.io_modes = VB2_MMAP | VB2_USERPTR; > > + queue->queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; > > queue->queue.drv_priv = queue; > > queue->queue.buf_struct_size = sizeof(struct uvc_buffer); > > queue->queue.mem_ops = &vb2_vmalloc_memops; > > @@ -361,6 +361,19 @@ int uvc_queue_streamoff(struct uvc_video_queue *queue, enum v4l2_buf_type type) > > return ret; > > } > > > > +ssize_t uvc_queue_read(struct uvc_video_queue *queue, struct file *file, > > + char __user *buf, size_t count, loff_t *ppos) > > +{ > > + ssize_t ret; > > + > > + mutex_lock(&queue->mutex); > > + ret = vb2_read(&queue->queue, buf, count, ppos, > > + file->f_flags & O_NONBLOCK); > > + mutex_unlock(&queue->mutex); > > + > > + return ret; > > +} > > + > > int uvc_queue_mmap(struct uvc_video_queue *queue, struct vm_area_struct *vma) > > { > > return vb2_mmap(&queue->queue, vma); > > diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c > > index 84be596..3866832 100644 > > --- a/drivers/media/usb/uvc/uvc_v4l2.c > > +++ b/drivers/media/usb/uvc/uvc_v4l2.c > > @@ -594,7 +594,8 @@ static int uvc_ioctl_querycap(struct file *file, void *fh, > > strscpy(cap->driver, "uvcvideo", sizeof(cap->driver)); > > strscpy(cap->card, vdev->name, sizeof(cap->card)); > > usb_make_path(stream->dev->udev, cap->bus_info, sizeof(cap->bus_info)); > > - cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING > > + cap->capabilities = V4L2_CAP_DEVICE_CAPS | V4L2_CAP_STREAMING | > > + V4L2_CAP_READWRITE > > | chain->caps; > > > > return 0; > > @@ -1434,8 +1435,12 @@ static long uvc_v4l2_compat_ioctl32(struct file *file, > > static ssize_t uvc_v4l2_read(struct file *file, char __user *data, > > size_t count, loff_t *ppos) > > { > > - uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_read: not implemented.\n"); > > - return -EINVAL; > > + struct uvc_fh *handle = file->private_data; > > + struct uvc_streaming *stream = handle->stream; > > + > > + uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_read\n"); > > + > > + return uvc_queue_read(&stream->queue, file, data, count, ppos); > > } > > > > static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma) > > diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h > > index c7c1baa..5d0515c 100644 > > --- a/drivers/media/usb/uvc/uvcvideo.h > > +++ b/drivers/media/usb/uvc/uvcvideo.h > > @@ -766,6 +766,8 @@ struct uvc_buffer *uvc_queue_next_buffer(struct uvc_video_queue *queue, > > struct uvc_buffer *buf); > > struct uvc_buffer *uvc_queue_get_current_buffer(struct uvc_video_queue *queue); > > void uvc_queue_buffer_release(struct uvc_buffer *buf); > > +ssize_t uvc_queue_read(struct uvc_video_queue *queue, struct file *file, > > + char __user *buf, size_t count, loff_t *ppos); > > int uvc_queue_mmap(struct uvc_video_queue *queue, > > struct vm_area_struct *vma); > > __poll_t uvc_queue_poll(struct uvc_video_queue *queue, struct file *file, -- Regards, Laurent Pinchart