From patchwork Fri Jul 16 12:57:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 12382087 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7DF52C07E95 for ; Fri, 16 Jul 2021 12:57:25 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4A551613E9 for ; Fri, 16 Jul 2021 12:57:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A551613E9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=le5hpV2AN36TAA3vvfJziKTibgDWv0kXxWZqJTBfcZk=; b=3fr4DAoyrTLGto J7J2eJ71F0k6EdYVXE8CBXuP9qWlor7GLectHPZVYFZYIw/zsuY2VgxMAip72svg27NPT82VqQuMo hapyJnpJA/xZqLPEe+DapaeZOmXUE6xJOnLU0K8swa8HcVolb92kPbSr2WLsnQooyb9F9pR1PxbV8 i0Pv4pPm6e9NOgxU7R3QjHIX34Z1w8ssbVw5GBO2jry9L2FMckQD2WVxpnSlPrNzWRSSqKiA5DcXy eNtj1ZYkYNyYcHpPR/QrCI0CtxtFArTigGAsLUk51eF74XOCJivNSePu51uie2CBEIWvrLJRpGAOJ nyhO+sCWrjDu2/8BPBtg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m4NP7-004POG-Rp; Fri, 16 Jul 2021 12:57:21 +0000 Received: from bhuna.collabora.co.uk ([46.235.227.227]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m4NP1-004PJX-3G for linux-rockchip@lists.infradead.org; Fri, 16 Jul 2021 12:57:18 +0000 Received: from guri.fritz.box (unknown [IPv6:2a02:810a:880:f54:f07d:7270:7174:27c4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: dafna) by bhuna.collabora.co.uk (Postfix) with ESMTPSA id BA5451F44084; Fri, 16 Jul 2021 13:57:11 +0100 (BST) From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, dafna.hirschfeld@collabora.com, helen.koike@collabora.com, ezequiel@collabora.com, hverkuil@xs4all.nl, kernel@collabora.com, dafna3@gmail.com, sakari.ailus@linux.intel.com, linux-rockchip@lists.infradead.org, mchehab@kernel.org, tfiga@chromium.org Subject: [patch v4l-utils 2/2] v4l2-ctl: fix bugs found in streaming_set_cap2out Date: Fri, 16 Jul 2021 14:57:03 +0200 Message-Id: <20210716125703.699-3-dafna.hirschfeld@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210716125703.699-1-dafna.hirschfeld@collabora.com> References: <20210716125703.699-1-dafna.hirschfeld@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210716_055715_277191_536EAAC5 X-CRM114-Status: GOOD ( 15.85 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org When exporting buffers from a capture device to an output device. There are several bugs: 1. The bytesused are set from the exported buffer, the value might be bigger than the length of the output buffer. 2. The file descriptor field 'm.fd' in 'struct v4l2_buffer' is not set. This patch fix those issues. Testing: modprobe vimc modprobe vivid //configure vimc pipeline media-ctl -d platform:vimc -V '"Sensor A":0[fmt:SBGGR8_1X8/640x480]' media-ctl -d platform:vimc -V '"Debayer A":0[fmt:SBGGR8_1X8/640x480]' media-ctl -d platform:vimc -V '"Sensor B":0[fmt:SBGGR8_1X8/640x480]' media-ctl -d platform:vimc -V '"Debayer B":0[fmt:SBGGR8_1X8/640x480]' v4l2-ctl -z platform:vimc -d "RGB/YUV Capture" -v width=1920,height=1440 v4l2-ctl -z platform:vimc -d "Raw Capture 0" -v pixelformat=BA81 v4l2-ctl -z platform:vimc -d "Raw Capture 1" -v pixelformat=BA81 // export buffers from vimc capture device (/dev/video2) to vivid output device (/dev/video4) v4l2-ctl -d2 --stream-mmap --out-device /dev/video4 --stream-out-dmabuf Signed-off-by: Dafna Hirschfeld --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 0f28a537..432f1cc6 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -1499,6 +1499,11 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE *fin, cv4l_buffer *cap if (cap) { buf.s_index(cap->g_index()); + if (fd.querybuf(buf)) { + fprintf(stderr, "%s fd.querybuf failed\n", __func__); + return QUEUE_ERROR; + } + for (unsigned j = 0; j < buf.g_num_planes(); j++) { unsigned data_offset = cap->g_data_offset(j); @@ -1507,8 +1512,17 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE *fin, cv4l_buffer *cap buf.s_bytesused(cap->g_bytesused(j) - data_offset, j); buf.s_data_offset(0, j); } else if (q.g_memory() == V4L2_MEMORY_DMABUF) { - buf.s_bytesused(cap->g_bytesused(j), j); + __u32 bytesused = cap->g_bytesused(j); + /* + * bytesused comes from the exported cap buffer + * but the length of the out buffer might be smaller + * so take the smaller of the two + */ + if(bytesused > buf.g_length(j)) + bytesused = buf.g_length(j); + buf.s_bytesused(bytesused, j); buf.s_data_offset(data_offset, j); + buf.s_fd(q.g_fd(buf.g_index(), j)); } } } else {