From patchwork Mon Dec 3 13:51:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Verkuil X-Patchwork-Id: 10709611 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 A35B01731 for ; Mon, 3 Dec 2018 13:51:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9460D2AF57 for ; Mon, 3 Dec 2018 13:51:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 884A22B015; Mon, 3 Dec 2018 13:51:54 +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 240812AF57 for ; Mon, 3 Dec 2018 13:51:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726078AbeLCNw6 (ORCPT ); Mon, 3 Dec 2018 08:52:58 -0500 Received: from lb2-smtp-cloud7.xs4all.net ([194.109.24.28]:37961 "EHLO lb2-smtp-cloud7.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725888AbeLCNw6 (ORCPT ); Mon, 3 Dec 2018 08:52:58 -0500 Received: from tschai.fritz.box ([212.251.195.8]) by smtp-cloud7.xs4all.net with ESMTPA id TodTgVSsf3Hr7TodZgJCu4; Mon, 03 Dec 2018 14:51:50 +0100 From: hverkuil-cisco@xs4all.nl To: linux-media@vger.kernel.org Cc: Alexandre Courbot , maxime.ripard@bootlin.com, paul.kocialkowski@bootlin.com, tfiga@chromium.org, nicolas@ndufresne.ca, sakari.ailus@linux.intel.com, Hans Verkuil Subject: [PATCHv3 5/9] v4l2-mem2mem: add v4l2_m2m_buf_copy_data helper function Date: Mon, 3 Dec 2018 14:51:39 +0100 Message-Id: <20181203135143.45487-6-hverkuil-cisco@xs4all.nl> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181203135143.45487-1-hverkuil-cisco@xs4all.nl> References: <20181203135143.45487-1-hverkuil-cisco@xs4all.nl> MIME-Version: 1.0 X-CMAE-Envelope: MS4wfKvZrTWFyJx5pqld1EVIEexBmLhyizlWuNyDdaPsLhiZjTL3JFPHYa34FOP0nyOy9q50mQp93g4ApLr0HUY86TtfGCyz46iOQWpkWro617FhfcbTGQI4 ApQMev5MqpOqf3mzN+DYAP+xtkhi4LO6QPuj9bqIq2MR94kvaf/lfF9gfUcs03RNcccrQwjjjkKzL4P+RZtp9sdwLciTZwFlQ2I941SwLCjsMxm//Wepnsw0 PycFewz056fZ8pr4y/QBhQJGqLGOat38KYvkpkGV+k0EIK0lmcD6DvCcOtEw9y+iSVRJ8XzQO4mMyE6jhX6+N4ADv/VqcdnVSZB0dGy/tGIE9mCBwqGLWL8Q NWfXecWJSCOqbWPCBLMnGWnylcGoyfeKLaZkzDG1QEaF+FsKA/ehnDCUfckDp6oTUcY4kROesxllcqiQoscbpuUZYjMUdw== 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 Memory-to-memory devices should copy various parts of struct v4l2_buffer from the output buffer to the capture buffer. Add a helper function that does that to simplify the driver code. Signed-off-by: Hans Verkuil Reviewed-by: Paul Kocialkowski Reviewed-by: Alexandre Courbot --- drivers/media/v4l2-core/v4l2-mem2mem.c | 23 +++++++++++++++++++++++ include/media/v4l2-mem2mem.h | 21 +++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/drivers/media/v4l2-core/v4l2-mem2mem.c b/drivers/media/v4l2-core/v4l2-mem2mem.c index 5bbdec55b7d7..a9cb1ac33dc0 100644 --- a/drivers/media/v4l2-core/v4l2-mem2mem.c +++ b/drivers/media/v4l2-core/v4l2-mem2mem.c @@ -975,6 +975,29 @@ void v4l2_m2m_buf_queue(struct v4l2_m2m_ctx *m2m_ctx, } EXPORT_SYMBOL_GPL(v4l2_m2m_buf_queue); +void v4l2_m2m_buf_copy_data(const struct vb2_v4l2_buffer *out_vb, + struct vb2_v4l2_buffer *cap_vb, + bool copy_frame_flags) +{ + u32 mask = V4L2_BUF_FLAG_TIMECODE | V4L2_BUF_FLAG_TAG | + V4L2_BUF_FLAG_TSTAMP_SRC_MASK; + + if (copy_frame_flags) + mask |= V4L2_BUF_FLAG_KEYFRAME | V4L2_BUF_FLAG_PFRAME | + V4L2_BUF_FLAG_BFRAME; + + cap_vb->vb2_buf.timestamp = out_vb->vb2_buf.timestamp; + + if (out_vb->flags & V4L2_BUF_FLAG_TAG) + cap_vb->tag = out_vb->tag; + if (out_vb->flags & V4L2_BUF_FLAG_TIMECODE) + cap_vb->timecode = out_vb->timecode; + cap_vb->field = out_vb->field; + cap_vb->flags &= ~mask; + cap_vb->flags |= out_vb->flags & mask; +} +EXPORT_SYMBOL_GPL(v4l2_m2m_buf_copy_data); + void v4l2_m2m_request_queue(struct media_request *req) { struct media_request_object *obj, *obj_safe; diff --git a/include/media/v4l2-mem2mem.h b/include/media/v4l2-mem2mem.h index 5467264771ec..bb4feb6969d2 100644 --- a/include/media/v4l2-mem2mem.h +++ b/include/media/v4l2-mem2mem.h @@ -622,6 +622,27 @@ v4l2_m2m_dst_buf_remove_by_idx(struct v4l2_m2m_ctx *m2m_ctx, unsigned int idx) return v4l2_m2m_buf_remove_by_idx(&m2m_ctx->cap_q_ctx, idx); } +/** + * v4l2_m2m_buf_copy_data() - copy buffer data from the output buffer to the + * capture buffer + * + * @out_vb: the output buffer that is the source of the data. + * @cap_vb: the capture buffer that will receive the data. + * @copy_frame_flags: copy the KEY/B/PFRAME flags as well. + * + * This helper function copies the timestamp, timecode (if the TIMECODE + * buffer flag was set), tag (if the TAG buffer flag was set), field + * and the TIMECODE, TAG, KEYFRAME, BFRAME, PFRAME and TSTAMP_SRC_MASK + * flags from @out_vb to @cap_vb. + * + * If @copy_frame_flags is false, then the KEYFRAME, BFRAME and PFRAME + * flags are not copied. This is typically needed for encoders that + * set this bits explicitly. + */ +void v4l2_m2m_buf_copy_data(const struct vb2_v4l2_buffer *out_vb, + struct vb2_v4l2_buffer *cap_vb, + bool copy_frame_flags); + /* v4l2 request helper */ void v4l2_m2m_request_queue(struct media_request *req);