From patchwork Mon Feb 4 10:11:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10795369 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DAE717FB for ; Mon, 4 Feb 2019 10:11:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F17A32AB30 for ; Mon, 4 Feb 2019 10:11:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E40BF2AB47; Mon, 4 Feb 2019 10:11:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8D1892AB3E for ; Mon, 4 Feb 2019 10:11:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728552AbfBDKLj (ORCPT ); Mon, 4 Feb 2019 05:11:39 -0500 Received: from lb2-smtp-cloud8.xs4all.net ([194.109.24.25]:42662 "EHLO lb2-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727958AbfBDKLi (ORCPT ); Mon, 4 Feb 2019 05:11:38 -0500 Received: from test-nl.fritz.box ([80.101.105.217]) by smtp-cloud8.xs4all.net with ESMTPA id qbDyg7eyqNR5yqbE0giMRI; Mon, 04 Feb 2019 11:11:36 +0100 From: hverkuil-cisco@xs4all.nl To: linux-media@vger.kernel.org Cc: Nicolas Dufresne , Tomasz Figa , Alexandre Courbot , Paul Kocialkowski , Hans Verkuil Subject: [PATCHv2 1/3] vb2: replace bool by bitfield in vb2_buffer Date: Mon, 4 Feb 2019 11:11:32 +0100 Message-Id: <20190204101134.56283-2-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204101134.56283-1-hverkuil-cisco@xs4all.nl> References: <20190204101134.56283-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfC1OsLAdqq3aBt0icglNKZhLnBKRD635orEa9uWyBL4AHKqi+8rwESeYlpema3gVNcboYst5RNf1xVZpax0YkIoBeEWd+3y9CN0OmGk0JX90vgZAhK7X 3TwD3xRDqHJuYKOCqgJe6M1fUuYXwu9VE4p2TxSYDCXSP/f17ES5NkPYPpJ0hnfxdn4DJ8RDl1r6ZkNC0fGaNzeXrB9vb9tb4GQGk+/f0rjpYv+YHpW/+9PD 7ZQ8MBQEm99zysKtO+T1mHvlSvKDVFpUEuwOAY884HotwYlE9peeLWhb7XmLTmSm0wqwgrfE18iLlHOC/lFD0pCtgsuj9wQqC8QzTjgfnO7DFszVb1VDCp7v m90YEl+t71mStNRYlLkb02U9sEjVMA== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Hans Verkuil The bool type is not recommended for use in structs, so replace these by bitfields. Signed-off-by: Hans Verkuil Reviewed-by: Paul Kocialkowski --- drivers/media/common/videobuf2/videobuf2-core.c | 12 ++++++------ include/media/videobuf2-core.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index e07b6bdb6982..35cf36686e20 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -934,7 +934,7 @@ void vb2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state) /* sync buffers */ for (plane = 0; plane < vb->num_planes; ++plane) call_void_memop(vb, finish, vb->planes[plane].mem_priv); - vb->synced = false; + vb->synced = 0; } spin_lock_irqsave(&q->done_lock, flags); @@ -1313,8 +1313,8 @@ static int __buf_prepare(struct vb2_buffer *vb) for (plane = 0; plane < vb->num_planes; ++plane) call_void_memop(vb, prepare, vb->planes[plane].mem_priv); - vb->synced = true; - vb->prepared = true; + vb->synced = 1; + vb->prepared = 1; vb->state = orig_state; return 0; @@ -1803,7 +1803,7 @@ int vb2_core_dqbuf(struct vb2_queue *q, unsigned int *pindex, void *pb, } call_void_vb_qop(vb, buf_finish, vb); - vb->prepared = false; + vb->prepared = 0; if (pindex) *pindex = vb->index; @@ -1927,12 +1927,12 @@ static void __vb2_queue_cancel(struct vb2_queue *q) for (plane = 0; plane < vb->num_planes; ++plane) call_void_memop(vb, finish, vb->planes[plane].mem_priv); - vb->synced = false; + vb->synced = 0; } if (vb->prepared) { call_void_vb_qop(vb, buf_finish, vb); - vb->prepared = false; + vb->prepared = 0; } __vb2_dqbuf(vb); diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 4849b865b908..2757d1902609 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -269,8 +269,8 @@ struct vb2_buffer { * vb2_plane: per-plane information; do not change */ enum vb2_buffer_state state; - bool synced; - bool prepared; + unsigned int synced:1; + unsigned int prepared:1; struct vb2_plane planes[VB2_MAX_PLANES]; struct list_head queued_entry; From patchwork Mon Feb 4 10:11:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10795371 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF82E6C2 for ; Mon, 4 Feb 2019 10:11:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9CBC22AB30 for ; Mon, 4 Feb 2019 10:11:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 914902AB47; Mon, 4 Feb 2019 10:11:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 281912AB30 for ; Mon, 4 Feb 2019 10:11:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728503AbfBDKLj (ORCPT ); Mon, 4 Feb 2019 05:11:39 -0500 Received: from lb2-smtp-cloud8.xs4all.net ([194.109.24.25]:48593 "EHLO lb2-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728438AbfBDKLi (ORCPT ); Mon, 4 Feb 2019 05:11:38 -0500 Received: from test-nl.fritz.box ([80.101.105.217]) by smtp-cloud8.xs4all.net with ESMTPA id qbDyg7eyqNR5yqbE0giMRP; Mon, 04 Feb 2019 11:11:36 +0100 From: hverkuil-cisco@xs4all.nl To: linux-media@vger.kernel.org Cc: Nicolas Dufresne , Tomasz Figa , Alexandre Courbot , Paul Kocialkowski , Hans Verkuil Subject: [PATCHv2 2/3] vb2: keep track of timestamp status Date: Mon, 4 Feb 2019 11:11:33 +0100 Message-Id: <20190204101134.56283-3-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204101134.56283-1-hverkuil-cisco@xs4all.nl> References: <20190204101134.56283-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfC1OsLAdqq3aBt0icglNKZhLnBKRD635orEa9uWyBL4AHKqi+8rwESeYlpema3gVNcboYst5RNf1xVZpax0YkIoBeEWd+3y9CN0OmGk0JX90vgZAhK7X 3TwD3xRDqHJuYKOCqgJe6M1fUuYXwu9VE4p2TxSYDCXSP/f17ES5NkPYPpJ0hnfxdn4DJ8RDl1r6ZkNC0fGaNzeXrB9vb9tb4GQGk+/f0rjpYv+YHpW/+9PD 7ZQ8MBQEm99zysKtO+T1mHvlSvKDVFpUEuwOAY884HotwYlE9peeLWhb7XmLTmSm0wqwgrfE18iLlHOC/lFD0pCtgsuj9wQqC8QzTjgfnO7DFszVb1VDCp7v m90YEl+t71mStNRYlLkb02U9sEjVMA== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Hans Verkuil If a stream is stopped, or if a USERPTR/DMABUF buffer is queued backed by a different user address or dmabuf fd, then the timestamp should be skipped by vb2_find_timestamp since the memory it refers to is no longer valid. So keep track of a 'copied_timestamp' state: it is set when the timestamp is copied from an output to a capture buffer, and is cleared when it is no longer valid. Signed-off-by: Hans Verkuil Reviewed-by: Paul Kocialkowski --- drivers/media/common/videobuf2/videobuf2-core.c | 3 +++ drivers/media/common/videobuf2/videobuf2-v4l2.c | 3 ++- drivers/media/v4l2-core/v4l2-mem2mem.c | 1 + include/media/videobuf2-core.h | 3 +++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/media/common/videobuf2/videobuf2-core.c b/drivers/media/common/videobuf2/videobuf2-core.c index 35cf36686e20..dc29bd01d6c5 100644 --- a/drivers/media/common/videobuf2/videobuf2-core.c +++ b/drivers/media/common/videobuf2/videobuf2-core.c @@ -1041,6 +1041,7 @@ static int __prepare_userptr(struct vb2_buffer *vb) if (vb->planes[plane].mem_priv) { if (!reacquired) { reacquired = true; + vb->copied_timestamp = 0; call_void_vb_qop(vb, buf_cleanup, vb); } call_void_memop(vb, put_userptr, vb->planes[plane].mem_priv); @@ -1165,6 +1166,7 @@ static int __prepare_dmabuf(struct vb2_buffer *vb) if (!reacquired) { reacquired = true; + vb->copied_timestamp = 0; call_void_vb_qop(vb, buf_cleanup, vb); } @@ -1943,6 +1945,7 @@ static void __vb2_queue_cancel(struct vb2_queue *q) if (vb->request) media_request_put(vb->request); vb->request = NULL; + vb->copied_timestamp = 0; } } diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 3aeaea3af42a..55277370c313 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -604,7 +604,8 @@ int vb2_find_timestamp(const struct vb2_queue *q, u64 timestamp, unsigned int i; for (i = start_idx; i < q->num_buffers; i++) - if (q->bufs[i]->timestamp == timestamp) + if (q->bufs[i]->copied_timestamp && + q->bufs[i]->timestamp == timestamp) return i; return -1; } diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c index 631f4e2aa942..64b19ee1c847 100644 --- a/drivers/media/v4l2-core/v4l2-mem2mem.c +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c @@ -992,6 +992,7 @@ void v4l2_m2m_buf_copy_data(const struct vb2_v4l2_buffer *out_vb, cap_vb->field = out_vb->field; cap_vb->flags &= ~mask; cap_vb->flags |= out_vb->flags & mask; + cap_vb->vb2_buf.copied_timestamp = 1; } EXPORT_SYMBOL_GPL(v4l2_m2m_buf_copy_data); diff --git a/include/media/videobuf2-core.h b/include/media/videobuf2-core.h index 2757d1902609..62488d901747 100644 --- a/include/media/videobuf2-core.h +++ b/include/media/videobuf2-core.h @@ -262,6 +262,8 @@ struct vb2_buffer { * prepared: this buffer has been prepared, i.e. the * buf_prepare op was called. It is cleared again * after the 'buf_finish' op is called. + * copied_timestamp: the timestamp of this capture buffer was copied + * from an output buffer. * queued_entry: entry on the queued buffers list, which holds * all buffers queued from userspace * done_entry: entry on the list that stores all buffers ready @@ -271,6 +273,7 @@ struct vb2_buffer { enum vb2_buffer_state state; unsigned int synced:1; unsigned int prepared:1; + unsigned int copied_timestamp:1; struct vb2_plane planes[VB2_MAX_PLANES]; struct list_head queued_entry; From patchwork Mon Feb 4 10:11:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10795367 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E5681390 for ; Mon, 4 Feb 2019 10:11:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C0F32AB30 for ; Mon, 4 Feb 2019 10:11:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 709002AB47; Mon, 4 Feb 2019 10:11:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 064A42AB30 for ; Mon, 4 Feb 2019 10:11:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728502AbfBDKLj (ORCPT ); Mon, 4 Feb 2019 05:11:39 -0500 Received: from lb3-smtp-cloud8.xs4all.net ([194.109.24.29]:36030 "EHLO lb3-smtp-cloud8.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728449AbfBDKLi (ORCPT ); Mon, 4 Feb 2019 05:11:38 -0500 Received: from test-nl.fritz.box ([80.101.105.217]) by smtp-cloud8.xs4all.net with ESMTPA id qbDyg7eyqNR5yqbE0giMRX; Mon, 04 Feb 2019 11:11:36 +0100 From: hverkuil-cisco@xs4all.nl To: linux-media@vger.kernel.org Cc: Nicolas Dufresne , Tomasz Figa , Alexandre Courbot , Paul Kocialkowski , Hans Verkuil Subject: [PATCHv2 3/3] vb2: add 'match' arg to vb2_find_buffer() Date: Mon, 4 Feb 2019 11:11:34 +0100 Message-Id: <20190204101134.56283-4-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190204101134.56283-1-hverkuil-cisco@xs4all.nl> References: <20190204101134.56283-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfC1OsLAdqq3aBt0icglNKZhLnBKRD635orEa9uWyBL4AHKqi+8rwESeYlpema3gVNcboYst5RNf1xVZpax0YkIoBeEWd+3y9CN0OmGk0JX90vgZAhK7X 3TwD3xRDqHJuYKOCqgJe6M1fUuYXwu9VE4p2TxSYDCXSP/f17ES5NkPYPpJ0hnfxdn4DJ8RDl1r6ZkNC0fGaNzeXrB9vb9tb4GQGk+/f0rjpYv+YHpW/+9PD 7ZQ8MBQEm99zysKtO+T1mHvlSvKDVFpUEuwOAY884HotwYlE9peeLWhb7XmLTmSm0wqwgrfE18iLlHOC/lFD0pCtgsuj9wQqC8QzTjgfnO7DFszVb1VDCp7v m90YEl+t71mStNRYlLkb02U9sEjVMA== Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Hans Verkuil When finding a buffer vb2_find_buffer() should also check if the properties of the found buffer (i.e. number of planes and plane sizes) match the properties of the 'match' buffer. Update the cedrus driver accordingly. Signed-off-by: Hans Verkuil --- drivers/media/common/videobuf2/videobuf2-v4l2.c | 15 ++++++++++++--- drivers/staging/media/sunxi/cedrus/cedrus_mpeg2.c | 8 ++++---- include/media/videobuf2-v4l2.h | 3 ++- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/drivers/media/common/videobuf2/videobuf2-v4l2.c b/drivers/media/common/videobuf2/videobuf2-v4l2.c index 55277370c313..0207493c8877 100644 --- a/drivers/media/common/videobuf2/videobuf2-v4l2.c +++ b/drivers/media/common/videobuf2/videobuf2-v4l2.c @@ -599,14 +599,23 @@ static const struct vb2_buf_ops v4l2_buf_ops = { }; int vb2_find_timestamp(const struct vb2_queue *q, u64 timestamp, - unsigned int start_idx) + const struct vb2_buffer *match, unsigned int start_idx) { unsigned int i; for (i = start_idx; i < q->num_buffers; i++) if (q->bufs[i]->copied_timestamp && - q->bufs[i]->timestamp == timestamp) - return i; + q->bufs[i]->timestamp == timestamp && + q->bufs[i]->num_planes == match->num_planes) { + unsigned int p; + + for (p = 0; p < match->num_planes; p++) + if (q->bufs[i]->planes[p].length < + match->planes[p].length) + break; + if (p == match->num_planes) + return i; + } return -1; } EXPORT_SYMBOL_GPL(vb2_find_timestamp); diff --git a/drivers/staging/media/sunxi/cedrus/cedrus_mpeg2.c b/drivers/staging/media/sunxi/cedrus/cedrus_mpeg2.c index cb45fda9aaeb..16bc82f1cb2c 100644 --- a/drivers/staging/media/sunxi/cedrus/cedrus_mpeg2.c +++ b/drivers/staging/media/sunxi/cedrus/cedrus_mpeg2.c @@ -159,8 +159,8 @@ static void cedrus_mpeg2_setup(struct cedrus_ctx *ctx, struct cedrus_run *run) cedrus_write(dev, VE_DEC_MPEG_PICBOUNDSIZE, reg); /* Forward and backward prediction reference buffers. */ - forward_idx = vb2_find_timestamp(cap_q, - slice_params->forward_ref_ts, 0); + forward_idx = vb2_find_timestamp(cap_q, slice_params->forward_ref_ts, + &run->dst->vb2_buf, 0); fwd_luma_addr = cedrus_dst_buf_addr(ctx, forward_idx, 0); fwd_chroma_addr = cedrus_dst_buf_addr(ctx, forward_idx, 1); @@ -168,8 +168,8 @@ static void cedrus_mpeg2_setup(struct cedrus_ctx *ctx, struct cedrus_run *run) cedrus_write(dev, VE_DEC_MPEG_FWD_REF_LUMA_ADDR, fwd_luma_addr); cedrus_write(dev, VE_DEC_MPEG_FWD_REF_CHROMA_ADDR, fwd_chroma_addr); - backward_idx = vb2_find_timestamp(cap_q, - slice_params->backward_ref_ts, 0); + backward_idx = vb2_find_timestamp(cap_q, slice_params->backward_ref_ts, + &run->dst->vb2_buf, 0); bwd_luma_addr = cedrus_dst_buf_addr(ctx, backward_idx, 0); bwd_chroma_addr = cedrus_dst_buf_addr(ctx, backward_idx, 1); diff --git a/include/media/videobuf2-v4l2.h b/include/media/videobuf2-v4l2.h index 8a10889dc2fd..b123d12424ba 100644 --- a/include/media/videobuf2-v4l2.h +++ b/include/media/videobuf2-v4l2.h @@ -60,6 +60,7 @@ struct vb2_v4l2_buffer { * * @q: pointer to &struct vb2_queue with videobuf2 queue. * @timestamp: the timestamp to find. + * @match: the properties of the buffer to find must match this buffer. * @start_idx: the start index (usually 0) in the buffer array to start * searching from. Note that there may be multiple buffers * with the same timestamp value, so you can restart the search @@ -69,7 +70,7 @@ struct vb2_v4l2_buffer { * -1 if no buffer with @timestamp was found. */ int vb2_find_timestamp(const struct vb2_queue *q, u64 timestamp, - unsigned int start_idx); + const struct vb2_buffer *match, unsigned int start_idx); int vb2_querybuf(struct vb2_queue *q, struct v4l2_buffer *b);