From patchwork Wed Aug 31 18:02:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guennadi Liakhovetski X-Patchwork-Id: 1117402 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7VI2tN8027627 for ; Wed, 31 Aug 2011 18:02:57 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757003Ab1HaSCw (ORCPT ); Wed, 31 Aug 2011 14:02:52 -0400 Received: from moutng.kundenserver.de ([212.227.17.9]:54004 "EHLO moutng.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756967Ab1HaSCw (ORCPT ); Wed, 31 Aug 2011 14:02:52 -0400 Received: from axis700.grange (dslb-094-221-100-032.pools.arcor-ip.net [94.221.100.32]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0MflMO-1QbdPS0uxg-00NlAy; Wed, 31 Aug 2011 20:02:50 +0200 Received: from 6a.grange (6a.grange [192.168.1.11]) by axis700.grange (Postfix) with ESMTPS id 70BB7189B83; Wed, 31 Aug 2011 20:02:49 +0200 (CEST) Received: from lyakh by 6a.grange with local (Exim 4.72) (envelope-from ) id 1Qyp7h-0007EL-1j; Wed, 31 Aug 2011 20:02:49 +0200 From: Guennadi Liakhovetski To: Linux Media Mailing List Cc: Hans Verkuil , Laurent Pinchart , Pawel Osciak , Sakari Ailus , Mauro Carvalho Chehab , Marek Szyprowski Subject: [PATCH 1/9 v6] V4L: add a new videobuf2 buffer state VB2_BUF_STATE_PREPARED Date: Wed, 31 Aug 2011 20:02:40 +0200 Message-Id: <1314813768-27752-2-git-send-email-g.liakhovetski@gmx.de> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1314813768-27752-1-git-send-email-g.liakhovetski@gmx.de> References: <1314813768-27752-1-git-send-email-g.liakhovetski@gmx.de> X-Provags-ID: V02:K0:/mn2z28lkrDhsUd+YAb9Z+X9VRMG/fKiddqIGeUcKcz YHtfsJyl+v2vVRfvFRmmNB1QWh4HmSKqQlVOqZM+hRgZeSdaHp VenIak1HygqkfZ06WItwsrQTwicOa+S+UaT0oLJ5UOMYaixbeW NVI/bxOFB52RgpI6NM01l33vs7vpkZ6kFmaCB6b4zqpB8iWY2l eyaKdtqTnv7lvobWnalwlHZrzvoc9c+LRAlj7FC1NPvHJjVfdX lxChaBs5ho5wB2zcFX+l5IT21zUyK36KBTLQAUjQiqoT2PXi2A WT488P7mqfCF7zq/c+2j8Cblr70brjm+0Es6M7IUUxa9PokXfm OJV8afzDjYeLZ05zaq0k1Pu2Ld9Zp3aSmgn2bkE0OhkvuoFW54 s3bwF0llsby9A== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 31 Aug 2011 18:02:57 +0000 (UTC) This patch prepares for a better separation of the buffer preparation stage. Signed-off-by: Guennadi Liakhovetski Cc: Hans Verkuil Cc: Laurent Pinchart Cc: Marek Szyprowski Cc: Mauro Carvalho Chehab Cc: Pawel Osciak Cc: Sakari Ailus --- v6: as reported by Pawel: the VB2_BUF_STATE_PREPARED state has to actually be set drivers/media/video/videobuf2-core.c | 61 +++++++++++++++++++++------------ include/media/videobuf2-core.h | 2 + 2 files changed, 41 insertions(+), 22 deletions(-) diff --git a/drivers/media/video/videobuf2-core.c b/drivers/media/video/videobuf2-core.c index 3015e60..4153da2 100644 --- a/drivers/media/video/videobuf2-core.c +++ b/drivers/media/video/videobuf2-core.c @@ -333,6 +333,7 @@ static int __fill_v4l2_buffer(struct vb2_buffer *vb, struct v4l2_buffer *b) b->flags |= V4L2_BUF_FLAG_DONE; break; case VB2_BUF_STATE_DEQUEUED: + case VB2_BUF_STATE_PREPARED: /* nothing */ break; } @@ -817,6 +818,33 @@ static void __enqueue_in_driver(struct vb2_buffer *vb) q->ops->buf_queue(vb); } +static int __buf_prepare(struct vb2_buffer *vb, struct v4l2_buffer *b) +{ + struct vb2_queue *q = vb->vb2_queue; + int ret; + + switch (q->memory) { + case V4L2_MEMORY_MMAP: + ret = __qbuf_mmap(vb, b); + break; + case V4L2_MEMORY_USERPTR: + ret = __qbuf_userptr(vb, b); + break; + default: + WARN(1, "Invalid queue type\n"); + ret = -EINVAL; + } + + if (!ret) + ret = call_qop(q, buf_prepare, vb); + if (ret) + dprintk(1, "qbuf: buffer preparation failed: %d\n", ret); + else + vb->state = VB2_BUF_STATE_PREPARED; + + return ret; +} + /** * vb2_qbuf() - Queue a buffer from userspace * @q: videobuf2 queue @@ -826,8 +854,8 @@ static void __enqueue_in_driver(struct vb2_buffer *vb) * Should be called from vidioc_qbuf ioctl handler of a driver. * This function: * 1) verifies the passed buffer, - * 2) calls buf_prepare callback in the driver (if provided), in which - * driver-specific buffer initialization can be performed, + * 2) if necessary, calls buf_prepare callback in the driver (if provided), in + * which driver-specific buffer initialization can be performed, * 3) if streaming is on, queues the buffer in driver by the means of buf_queue * callback for processing. * @@ -837,7 +865,7 @@ static void __enqueue_in_driver(struct vb2_buffer *vb) int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) { struct vb2_buffer *vb; - int ret = 0; + int ret; if (q->fileio) { dprintk(1, "qbuf: file io in progress\n"); @@ -866,29 +894,18 @@ int vb2_qbuf(struct vb2_queue *q, struct v4l2_buffer *b) return -EINVAL; } - if (vb->state != VB2_BUF_STATE_DEQUEUED) { + switch (vb->state) { + case VB2_BUF_STATE_DEQUEUED: + ret = __buf_prepare(vb, b); + if (ret) + return ret; + case VB2_BUF_STATE_PREPARED: + break; + default: dprintk(1, "qbuf: buffer already in use\n"); return -EINVAL; } - if (q->memory == V4L2_MEMORY_MMAP) - ret = __qbuf_mmap(vb, b); - else if (q->memory == V4L2_MEMORY_USERPTR) - ret = __qbuf_userptr(vb, b); - else { - WARN(1, "Invalid queue type\n"); - return -EINVAL; - } - - if (ret) - return ret; - - ret = call_qop(q, buf_prepare, vb); - if (ret) { - dprintk(1, "qbuf: buffer preparation failed\n"); - return ret; - } - /* * Add to the queued buffers list, a buffer will stay on it until * dequeued in dqbuf. diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index f87472a..65946c5 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -106,6 +106,7 @@ enum vb2_fileio_flags { /** * enum vb2_buffer_state - current video buffer state * @VB2_BUF_STATE_DEQUEUED: buffer under userspace control + * @VB2_BUF_STATE_PREPARED: buffer prepared in videobuf and by the driver * @VB2_BUF_STATE_QUEUED: buffer queued in videobuf, but not in driver * @VB2_BUF_STATE_ACTIVE: buffer queued in driver and possibly used * in a hardware operation @@ -117,6 +118,7 @@ enum vb2_fileio_flags { */ enum vb2_buffer_state { VB2_BUF_STATE_DEQUEUED, + VB2_BUF_STATE_PREPARED, VB2_BUF_STATE_QUEUED, VB2_BUF_STATE_ACTIVE, VB2_BUF_STATE_DONE,