From patchwork Wed Mar 6 21:17:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10841791 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 7A05B1669 for ; Wed, 6 Mar 2019 21:18:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 671782DF07 for ; Wed, 6 Mar 2019 21:18:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5B73A2E183; Wed, 6 Mar 2019 21:18:04 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 100D42DF07 for ; Wed, 6 Mar 2019 21:18:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726127AbfCFVSD (ORCPT ); Wed, 6 Mar 2019 16:18:03 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:34178 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725793AbfCFVSD (ORCPT ); Wed, 6 Mar 2019 16:18:03 -0500 Received: by mail-wm1-f65.google.com with SMTP id o10so5312580wmc.1 for ; Wed, 06 Mar 2019 13:18:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=QlpOK6oJV8oeAwbvelcizyRnTulOUmA1Vc7OVMdeGbw=; b=kjzKhUb5ArxHajVcLgPkvtV85ISXItpsuZI97q94i+NS4TMHQKSyg2Z+0B8V7hhlH9 br5icVmjkg/tRFDG0t0Xc2ZD4pST4jcpVQrRLpP8lC1C8S1gw+I2SRlhLJm3BOEQeFIz /ROvLRoP1Hm0R4W04QbcRcC68jUBjyFtqmUyEune0YUfRdQimCDQK7vWvbo4TP2ZQzUY EzNYm+eKpNUEGi5Cr9Cg5XcQL1Y+FoML3yV6glY4xYlqed/Fnsoyb0kIt6fFyUU9F7c0 vSmbbgBCsZzn/pyzRHoac5b14ToReOxdA2SV5+swTJV9Jqm3D3gE/rq0ttSNDkB+7egz S41Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=QlpOK6oJV8oeAwbvelcizyRnTulOUmA1Vc7OVMdeGbw=; b=PxmLH7EET0gWl4qUnvOenJ6j1RrprvVgbIOoK/M+jyT4J+4DaMhwdVmvpFE63zw9ZQ feGcaFDYcJ9Wd4rOMv1Zk3guLgSwrRLo/ZaMRt1NjVjxUAkWFrq58Q3/S6g86vMxvQd4 hFpA1NtgYNs+4DSpiXbPKgv8t2M52q+Z1C8EkYEhGmIB8fNT2NSOPuMgiudINsOSTe4y hz8ddToP2g7/tzYNF3mC8OuNqSnyDRxhaDenBC2gOBMFMGZQo8U7y/nJm2gx9exCAoEO GOzLtZ76/F4m8zO1z88gkbp/5tCo0jXXMemooHBPbPAr63tx6fSbHGHyx7vuYu/mg0FK 0aMQ== X-Gm-Message-State: APjAAAVRdOw1jlV8YDCNDVSDGhY9mwohn5tbCuIAKCNb2s2Zr/mh6+Lr likzMx/GFT+chqRP6itwA7UPORa56/k= X-Google-Smtp-Source: APXvYqykJnkx87TNkSRpWM8n2GOtqRF7lKVCThMYNqo9HdkVhH9ZyXzz1y0331sz1ozPJ4bV7LuzCQ== X-Received: by 2002:a1c:b40b:: with SMTP id d11mr3848796wmf.80.1551907080604; Wed, 06 Mar 2019 13:18:00 -0800 (PST) Received: from ubuntu.home ([77.124.117.239]) by smtp.gmail.com with ESMTPSA id c2sm5252495wrt.93.2019.03.06.13.17.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 13:18:00 -0800 (PST) From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: hverkuil@xs4all.nl, helen.koike@collabora.com, Dafna Hirschfeld Subject: [v4l-utils PATCH v5 1/6] v4l2-ctl: in streaming_set_m2m, close file pointers upon error Date: Wed, 6 Mar 2019 13:17:47 -0800 Message-Id: <20190306211752.15531-1-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 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 In streaming_set_m2m, make sure to close all file pointers and file descriptors before returning. Signed-off-by: Dafna Hirschfeld --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 0eda8449..ee84abbe 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -2141,18 +2141,19 @@ static void streaming_set_m2m(cv4l_fd &fd, cv4l_fd &exp_fd) if (options[OptStreamDmaBuf]) { if (exp_q.reqbufs(&exp_fd, reqbufs_count_cap)) - return; + goto done; exp_fd_p = &exp_fd; } if (options[OptStreamOutDmaBuf]) { if (exp_q.reqbufs(&exp_fd, reqbufs_count_out)) - return; + goto done; if (out.export_bufs(&exp_fd, exp_fd.g_type())) - return; + goto done; } stateful_m2m(fd, in, out, file[CAP], file[OUT], exp_fd_p); +done: if (options[OptStreamDmaBuf] || options[OptStreamOutDmaBuf]) exp_q.close_exported_fds(); From patchwork Wed Mar 6 21:17:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10841793 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 C95A61669 for ; Wed, 6 Mar 2019 21:18:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AD0302E167 for ; Wed, 6 Mar 2019 21:18:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A095A2DF07; Wed, 6 Mar 2019 21:18:05 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 184C52DF07 for ; Wed, 6 Mar 2019 21:18:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726195AbfCFVSE (ORCPT ); Wed, 6 Mar 2019 16:18:04 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:34181 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725793AbfCFVSE (ORCPT ); Wed, 6 Mar 2019 16:18:04 -0500 Received: by mail-wm1-f66.google.com with SMTP id o10so5312614wmc.1 for ; Wed, 06 Mar 2019 13:18:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=fYNZwgQ6sI3JOZRshOTInAinKACUoWtKfmbXGzDGtLs=; b=QuvZoIAcoQ/Hgaqa5GGMDSHa1yKKtY3WX6+SsLQK/tjZATk1aPb06e222t0xG2yYzH YjkBPrExYsDVqleoFhpxpBzh46k2gMpoc6UfDuyB59Hfwc2neOVQrO6xWyT0+pbzdwts LyWhzAy9sVl1x7jUwswlOrXlmFPXAGM3rVwMgvvfyCKhcR2e/74IkDVaqx25Ec+a2tBx 0tnbqkyyOimV+qgfL0NdnaVcCMz23eVA1NNiwVjNwoqUqCAfvirNa2HdmuynQMngjKcs sAD4L5bLTCgbAwT/E9FSsKWs+U2ncE4IDbqH4Uo1DwGavxwuRFOiXqc/6+IfZxP3lRCq rmsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=fYNZwgQ6sI3JOZRshOTInAinKACUoWtKfmbXGzDGtLs=; b=bUu5tbksL8a3SO90HLBr7oDHkF/clQfTZTedEPq+lZF9OxBeQnt/cUdNdic63+dvzT cwLS4WVj+2W9Tnoa3qla6H3Jay2dLmCIKijOz72IoEqIwtK7e1wUKtjNrlUF6CiA1IGa Y9PWTzKAuEgUbvl/krnVVTFUJOoW5U0y2J4N6bzcbhYOgOM32zQH0krbOfljvEmYL+zx /4VsVYD2NLmtVIqvEazZpH0dlfSsI0GF3k8gP8XA4HNtDMb9RWWESHHIH/1pps9r28aX 4e/YlMjFwyDN/EdY2k1AZ/cs9mlE98/hvDg8nAyEluHwGekD2iIa7pyk8mAxGMiWNhag M9Qw== X-Gm-Message-State: APjAAAX86WeAG0RKKaa4NmXDUfYL4HRyFIQXspIf2qzQzDOCh5QoUHO+ 0B0SOS1YEBUtMnGnRr2jOTIUZBVPLzg= X-Google-Smtp-Source: APXvYqy+vHVgnh4Y3w0rEAsaFj3rlm44p+ZbQt+l6Y72U2Y4j8X530MBgtvBk7euuxamcebbbvEzpg== X-Received: by 2002:a1c:eb17:: with SMTP id j23mr3488573wmh.86.1551907082280; Wed, 06 Mar 2019 13:18:02 -0800 (PST) Received: from ubuntu.home ([77.124.117.239]) by smtp.gmail.com with ESMTPSA id c2sm5252495wrt.93.2019.03.06.13.18.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 13:18:01 -0800 (PST) From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: hverkuil@xs4all.nl, helen.koike@collabora.com, Dafna Hirschfeld Subject: [v4l-utils PATCH v5 2/6] v4l2-ctl: check that the size read/write fit the buffer size Date: Wed, 6 Mar 2019 13:17:48 -0800 Message-Id: <20190306211752.15531-2-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190306211752.15531-1-dafna3@gmail.com> References: <20190306211752.15531-1-dafna3@gmail.com> 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 'read_write_padded_frame' should check that the expected size to read/write is not larger than the size of the buffer. Signed-off-by: Dafna Hirschfeld --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 41 ++++++++++++++++----------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index ee84abbe..465ba50c 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -749,9 +749,10 @@ void streaming_cmd(int ch, char *optarg) } } -static void read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf, +static bool read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf, FILE *fpointer, unsigned &sz, - unsigned &len, bool is_read) + unsigned &expected_len, unsigned buf_len, + bool is_read) { const struct v4l2_fwht_pixfmt_info *info = v4l2_fwht_find_pixfmt(fmt.g_pixelformat()); @@ -771,8 +772,9 @@ static void read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf, } sz = 0; - len = real_width * real_height * info->sizeimage_mult / info->sizeimage_div; - + expected_len = real_width * real_height * info->sizeimage_mult / info->sizeimage_div; + if (expected_len > buf_len) + return false; for (unsigned plane_idx = 0; plane_idx < info->planes_num; plane_idx++) { bool is_chroma_plane = plane_idx == 1 || plane_idx == 2; unsigned h_div = is_chroma_plane ? info->height_div : 1; @@ -800,7 +802,7 @@ static void read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf, break; if (wsz != consume_sz) { fprintf(stderr, "padding: needed %u bytes, got %u\n", consume_sz, wsz); - return; + return true; } sz += wsz; row_p += stride; @@ -809,6 +811,7 @@ static void read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf, if (sz == 0) break; } + return true; } static bool fill_buffer_from_file(cv4l_fd &fd, cv4l_queue &q, cv4l_buffer &b, @@ -929,26 +932,30 @@ restart: for (unsigned j = 0; j < q.g_num_planes(); j++) { void *buf = q.g_dataptr(b.g_index(), j); - unsigned len = q.g_length(j); + unsigned buf_len = q.g_length(j); + unsigned expected_len = q.g_length(j); unsigned sz; cv4l_fmt fmt; fd.g_fmt(fmt, q.g_type()); if (from_with_hdr) { - len = read_u32(fin); - if (len > q.g_length(j)) { + expected_len = read_u32(fin); + if (expected_len > q.g_length(j)) { fprintf(stderr, "plane size is too large (%u > %u)\n", - len, q.g_length(j)); + expected_len, q.g_length(j)); return false; } } - if (support_out_crop && v4l2_fwht_find_pixfmt(fmt.g_pixelformat())) - read_write_padded_frame(fmt, (unsigned char *)buf, fin, sz, len, true); - else - sz = fread(buf, 1, len, fin); + if (support_out_crop && v4l2_fwht_find_pixfmt(fmt.g_pixelformat())) { + if (!read_write_padded_frame(fmt, (unsigned char *)buf, + fin, sz, expected_len, buf_len, true)) + return false; + } else { + sz = fread(buf, 1, expected_len, fin); + } - if (first && sz != len) { + if (first && sz != expected_len) { fprintf(stderr, "Insufficient data\n"); return false; } @@ -958,12 +965,12 @@ restart: goto restart; } b.s_bytesused(sz, j); - if (sz == len) + if (sz == expected_len) continue; if (sz == 0) return false; if (sz) - fprintf(stderr, "%u != %u\n", sz, len); + fprintf(stderr, "%u != %u\n", sz, expected_len); continue; } first = false; @@ -1151,7 +1158,7 @@ static void write_buffer_to_file(cv4l_fd &fd, cv4l_queue &q, cv4l_buffer &buf, sz = fwrite(comp_ptr[j] + offset, 1, used, fout); else if (support_cap_compose && v4l2_fwht_find_pixfmt(fmt.g_pixelformat())) read_write_padded_frame(fmt, (u8 *)q.g_dataptr(buf.g_index(), j) + offset, - fout, sz, used, false); + fout, sz, used, used, false); else sz = fwrite((u8 *)q.g_dataptr(buf.g_index(), j) + offset, 1, used, fout); From patchwork Wed Mar 6 21:17:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10841795 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 99CFE922 for ; Wed, 6 Mar 2019 21:18:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8788D2DF07 for ; Wed, 6 Mar 2019 21:18:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C18C2E183; Wed, 6 Mar 2019 21:18:07 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 1593F2DF07 for ; Wed, 6 Mar 2019 21:18:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726264AbfCFVSG (ORCPT ); Wed, 6 Mar 2019 16:18:06 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:38003 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725793AbfCFVSG (ORCPT ); Wed, 6 Mar 2019 16:18:06 -0500 Received: by mail-wr1-f67.google.com with SMTP id g12so15045978wrm.5 for ; Wed, 06 Mar 2019 13:18:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4g1J+UKxUiGZS2eq+l2j4sB8EZ28KfhN+TrdzntsQAs=; b=JuQ/xYgSLRE4LC2Eq/F/TlsN525dpIuvU8JD3ebobwVTxnSPKEq2XlcMZw267UfBU+ fdcpPnRGmTFEgjR8vtBbCEFc+3OVEEymeDFUGnlNnTppxHa4kdHMAsCLfEYNVKnHImqk xCOijyM0PF535NH/woObDHFEvVJNbX8cwqDDlALZ/8huBDWpCkxXgobJsNpvue6sHeYF ZWJ9cpuChipofnWnorDKduwjvMgYsE5iP0cxrt75Mxwm1ITrOo/ib0SLOEWkjyBkql5L hoA/4bEQKHVBktBSdoAnwL1SO8y2di1nCaX+yRKLId3Gkylf7bD6GvRO+INNlJoFsE82 VzlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4g1J+UKxUiGZS2eq+l2j4sB8EZ28KfhN+TrdzntsQAs=; b=V1N7oIkLgI/47LI3x5mX7xNfb7EINg2fEpPK+uRXZCb5sXVRVwMZaSlbO5E4jLkOXV i93GXwSu/Y2dF18f/SDfQzuyQV4msdivApj5Se7/eqOZe0kH22aQGoi6/cXkf8GLZOpe dQAxd9sPuOZoDH/S2cLH46Vnf/x8XA7ndLeLm/jUAvGTp+bYsUkEQSB+MzesjOeH5cFE rKhUZZGCci1a0wKlH6fYEWKnzlpaczC1bleHLTCHuANA3SWiYxqlpWCg4aUxn01Sa/xZ 9uV562vdfGzKev7BMdeF5C5adebR2oSIXTFtxykt+D475sdx6iSaS2Bnrn/HOqMhn8Vg mVVQ== X-Gm-Message-State: APjAAAWiwVE2AIV8MZQeL4VAYHBE04DrBwVczImOyFrPKU/X83kmhtjI 0YWNbxtqYb4HQA3V+ZdUeEclTWmYr/I= X-Google-Smtp-Source: APXvYqzNgRwSmlNmlhhq6felQa57mDvz0nMJrrrr8jA4S37TME3Tz+5MgQneOK+gHCFEB6/gTN58BA== X-Received: by 2002:adf:fecd:: with SMTP id q13mr4377305wrs.3.1551907083757; Wed, 06 Mar 2019 13:18:03 -0800 (PST) Received: from ubuntu.home ([77.124.117.239]) by smtp.gmail.com with ESMTPSA id c2sm5252495wrt.93.2019.03.06.13.18.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 13:18:03 -0800 (PST) From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: hverkuil@xs4all.nl, helen.koike@collabora.com, Dafna Hirschfeld Subject: [v4l-utils PATCH v5 3/6] v4l2-ctl: set the in/out fmt variables in streaming_set_m2m Date: Wed, 6 Mar 2019 13:17:49 -0800 Message-Id: <20190306211752.15531-3-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190306211752.15531-1-dafna3@gmail.com> References: <20190306211752.15531-1-dafna3@gmail.com> 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 set the in/out fmt variables in streaming_set_m2m This is needed later to check for stateless fwht pixel format. Signed-off-by: Dafna Hirschfeld --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 465ba50c..9bb58a0b 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -1949,7 +1949,8 @@ static int capture_setup(cv4l_fd &fd, cv4l_queue &in, cv4l_fd *exp_fd) } static void stateful_m2m(cv4l_fd &fd, cv4l_queue &in, cv4l_queue &out, - FILE *fin, FILE *fout, cv4l_fd *exp_fd_p) + FILE *fin, FILE *fout, cv4l_fmt &fmt_in, + cv4l_fmt &fmt_out, cv4l_fd *exp_fd_p) { int fd_flags = fcntl(fd.g_fd(), F_GETFL); fps_timestamps fps_ts[2]; @@ -1959,10 +1960,6 @@ static void stateful_m2m(cv4l_fd &fd, cv4l_queue &in, cv4l_queue &out, fd_set *ex_fds = &fds[1]; /* for capture */ fd_set *wr_fds = &fds[2]; /* for output */ bool cap_streaming = false; - cv4l_fmt fmt[2]; - - fd.g_fmt(fmt[OUT], out.g_type()); - fd.g_fmt(fmt[CAP], in.g_type()); struct v4l2_event_subscription sub; @@ -2040,7 +2037,7 @@ static void stateful_m2m(cv4l_fd &fd, cv4l_queue &in, cv4l_queue &out, if (rd_fds && FD_ISSET(fd.g_fd(), rd_fds)) { r = do_handle_cap(fd, in, fin, NULL, - count[CAP], fps_ts[CAP], fmt[CAP]); + count[CAP], fps_ts[CAP], fmt_in); if (r < 0) { rd_fds = NULL; if (!have_eos) { @@ -2052,7 +2049,7 @@ static void stateful_m2m(cv4l_fd &fd, cv4l_queue &in, cv4l_queue &out, if (wr_fds && FD_ISSET(fd.g_fd(), wr_fds)) { r = do_handle_out(fd, out, fout, NULL, - count[OUT], fps_ts[OUT], fmt[OUT]); + count[OUT], fps_ts[OUT], fmt_out); if (r < 0) { wr_fds = NULL; @@ -2103,8 +2100,8 @@ static void stateful_m2m(cv4l_fd &fd, cv4l_queue &in, cv4l_queue &out, last_buffer = false; if (capture_setup(fd, in, exp_fd_p)) return; - fd.g_fmt(fmt[OUT], out.g_type()); - fd.g_fmt(fmt[CAP], in.g_type()); + fd.g_fmt(fmt_out, out.g_type()); + fd.g_fmt(fmt_in, in.g_type()); cap_streaming = true; } else { break; @@ -2129,6 +2126,10 @@ static void streaming_set_m2m(cv4l_fd &fd, cv4l_fd &exp_fd) cv4l_queue exp_q(exp_fd.g_type(), V4L2_MEMORY_MMAP); cv4l_fd *exp_fd_p = NULL; FILE *file[2] = {NULL, NULL}; + cv4l_fmt fmt[2]; + + fd.g_fmt(fmt[OUT], out.g_type()); + fd.g_fmt(fmt[CAP], in.g_type()); if (!fd.has_vid_m2m()) { fprintf(stderr, "unsupported m2m stream type\n"); From patchwork Wed Mar 6 21:17:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10841797 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 4E645922 for ; Wed, 6 Mar 2019 21:18:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C1762DF07 for ; Wed, 6 Mar 2019 21:18:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 306542E183; Wed, 6 Mar 2019 21:18:09 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 A95222DF07 for ; Wed, 6 Mar 2019 21:18:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726270AbfCFVSI (ORCPT ); Wed, 6 Mar 2019 16:18:08 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:46394 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726200AbfCFVSH (ORCPT ); Wed, 6 Mar 2019 16:18:07 -0500 Received: by mail-wr1-f66.google.com with SMTP id i16so15023741wrs.13 for ; Wed, 06 Mar 2019 13:18:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=NJuDvYOzvxWLj4xiAF59Sw+NAvCcwJCWwv5LqJCSCFI=; b=LV7KXQiYbKJUqHzmlquFeujVFarqT/j0ox6Sluh/KNQBNZkfa1Z+vdkk2WNkx92RNx Tg+/2qo4k9K0JIKvkViIXu+up2hTHK8kw2HvVMASkP4LqOoW9NAqgWfXvrbCf+X+7AfD /7oJhcWtUBohe3mXiMGIH3+g6xvTKhI3oLFQdaC4Zed3KV6ULipf6c0tjCg45KLPhhVE ptPBp+8yR1D6905jXWf5iMQL1DM/HIStQbxXTRGxwfmC5LAGNAYXJzTRfzfpwvTNmtQc 27NWTtyYmL2t+bsRFgO7NZnQmqFg8hGWFUR4B3CMW/rOKFSPMfEjERmnoamNQdgUEWlP 138A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=NJuDvYOzvxWLj4xiAF59Sw+NAvCcwJCWwv5LqJCSCFI=; b=CjLRrAK62efwjvmlKs4h0F5vfmtUTqHnRE61XXTV08UQt4neaiwErBH/nXRmeFc1LU ayOiwX38+XwXIZ9BtqClauqBtPBfA8W/OFnnEooCpFzBAxVPRrpe2zwcl8iQkSlyfhHT vYPufHrbFIyJFu3RqukzDs7necckBNj4G1sTrSXZNyfejoEYSVkbackk7fO+JEnkXDGp 6M1i8++ZiLngJ5kZsrc4hhp/4w9AzFqyijvO1qLMcfPXH/1IAovPv2FpRMx2pwXcsjfs k5hIi+n08IfWC02a70XWRb649warnV6Ww9jFSYdP8XpHMo9xafXNh0IdeYv+4DDph4kU tzhg== X-Gm-Message-State: APjAAAWrgYVcf2klqqV9lp4JEsb8lmdBsBMwMMqp6gKbPSbh5OZ3J2yF yR20std9AGcxt87CM+00A9H7wJnSDuw= X-Google-Smtp-Source: APXvYqxv3iMwUITZTbvJEimtD30KQyeeFweblitIBAr32r9mbasojYa12+C8P42YC3ZIFoFVwvdkxQ== X-Received: by 2002:a5d:4585:: with SMTP id p5mr4750831wrq.178.1551907085261; Wed, 06 Mar 2019 13:18:05 -0800 (PST) Received: from ubuntu.home ([77.124.117.239]) by smtp.gmail.com with ESMTPSA id c2sm5252495wrt.93.2019.03.06.13.18.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 13:18:04 -0800 (PST) From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: hverkuil@xs4all.nl, helen.koike@collabora.com, Dafna Hirschfeld Subject: [v4l-utils PATCH v5 4/6] v4l-utils: copy fwht-ctrls.h from kernel dir Date: Wed, 6 Mar 2019 13:17:50 -0800 Message-Id: <20190306211752.15531-4-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190306211752.15531-1-dafna3@gmail.com> References: <20190306211752.15531-1-dafna3@gmail.com> 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 copy fwht-ctrls.h from the kernel dir when running 'sync' and add typedef for u64 in codec-fwht.h Signed-off-by: Dafna Hirschfeld --- Makefile.am | 1 + utils/common/codec-fwht.patch | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Makefile.am b/Makefile.am index b0b8a098..8abe4f94 100644 --- a/Makefile.am +++ b/Makefile.am @@ -52,6 +52,7 @@ sync-with-kernel: cp -a $(KERNEL_DIR)/drivers/media/common/v4l2-tpg/v4l2-tpg-core.c $(top_srcdir)/utils/common cp -a $(KERNEL_DIR)/drivers/media/common/v4l2-tpg/v4l2-tpg-colors.c $(top_srcdir)/utils/common cp -a $(KERNEL_DIR)/include/media/tpg/v4l2-tpg* $(top_srcdir)/utils/common + cp -a $(KERNEL_DIR)/include/media/fwht-ctrls.h $(top_srcdir)/utils/common patch -d $(top_srcdir) --no-backup-if-mismatch -p0 <$(top_srcdir)/utils/common/v4l2-tpg.patch cp -a $(KERNEL_DIR)/drivers/media/platform/vicodec/codec-fwht.[ch] $(top_srcdir)/utils/common/ cp -a $(KERNEL_DIR)/drivers/media/platform/vicodec/codec-v4l2-fwht.[ch] $(top_srcdir)/utils/common/ diff --git a/utils/common/codec-fwht.patch b/utils/common/codec-fwht.patch index 37ac4672..ad27b37a 100644 --- a/utils/common/codec-fwht.patch +++ b/utils/common/codec-fwht.patch @@ -1,6 +1,6 @@ ---- a/utils/common/codec-fwht.h.old 2018-12-29 11:23:58.128328613 -0800 -+++ b/utils/common/codec-fwht.h 2018-12-29 11:24:16.099127560 -0800 -@@ -8,8 +8,26 @@ +--- a/utils/common/codec-fwht.h.old 2019-02-23 09:38:59.454065366 -0800 ++++ b/utils/common/codec-fwht.h 2019-02-23 09:40:44.007803414 -0800 +@@ -8,8 +8,27 @@ #define CODEC_FWHT_H #include @@ -21,6 +21,7 @@ +#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) + + ++typedef __u64 u64; +typedef __u32 u32; +typedef __u16 u16; +typedef __s16 s16; From patchwork Wed Mar 6 21:17:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10841799 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 3A5911669 for ; Wed, 6 Mar 2019 21:18:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 279542DF07 for ; Wed, 6 Mar 2019 21:18:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C2C42E183; Wed, 6 Mar 2019 21:18:11 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 46CF12DF07 for ; Wed, 6 Mar 2019 21:18:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726318AbfCFVSJ (ORCPT ); Wed, 6 Mar 2019 16:18:09 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:54447 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726200AbfCFVSJ (ORCPT ); Wed, 6 Mar 2019 16:18:09 -0500 Received: by mail-wm1-f65.google.com with SMTP id f3so7353074wmj.4 for ; Wed, 06 Mar 2019 13:18:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=eALtZQdWGW89J+GEjbIcRbfvVT6vwiS7X6VZEZ/dLUw=; b=D+gxwLbiPcG7oA49snTEQGsrZUn2IGK5/a5Y9IZyE1tr3yQvwTqOeUcSVT17yEjMn3 DR831GwphBwfb/ueu5bQg4bIL3Yy8jDUhc8JO99QkNWf7g/e22YAzH8ZJAcMVusMfy16 dIOn43uly6bOXIgJeYmr4i0+6m2Me65LWIBmZOg0xtob3VgqK7p4O0XAs9sJVBkagvvO d2F9hQsttg1/6rN40XM8DLFpQ+7pu/tQRFIJB+YYqnk4Y0Uh0Z0qTZrhL1Xg7fOqIMCT TG2QIIHPlRPZf1cRrcduNGyj+VIO6RwiaznQc6CaR7/AtDSHbb+dK4+95JLQcK5BhywM rEhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=eALtZQdWGW89J+GEjbIcRbfvVT6vwiS7X6VZEZ/dLUw=; b=qBQvzfbM/AnXfV3zbt5D7/Xbgaxpc3zgehx4h3U7RXk52TV6WXDpQ/ijbbspprqY3K O2uGks0KtJCXWlzL5cl6ao7XIG/C2xYe/DP9KclZuLTUhGCgJDRgu4wXjjp9LObrUFUz gtnoW5WMXUd+xIxDrHVq/FHaIcHVzzO+eUSLV5dsvwFv8pgnt/wguUTqAHp4NeDbGbVc Pu6rp485bAfiKnVvRTPKEZMF98DCH9aEAAph5V+E1yzBQ5G49r/2dyVshDq5efdQq3UN 2owTpouget08P5RP8GrMxxP3M6pIx0Oc9O4JEW+e2eQDcc2IsbrjOoWpTal0HpCe6SnM xXhA== X-Gm-Message-State: APjAAAUJrQn7UcCuo0P83165rkLYwPltkgEZH15a6kFaiqWkGX0DQhBR p7sPQOJ6L0/q9y/Pe+PlC1ODrxGPRzU= X-Google-Smtp-Source: APXvYqxzoKrfs9+8cQ5NWBgykz9pMyrtnR14HjrisGWCqttxeYG5oNc4hZXo8HzuG01mni0TgwyxCw== X-Received: by 2002:a1c:6505:: with SMTP id z5mr3834581wmb.7.1551907087132; Wed, 06 Mar 2019 13:18:07 -0800 (PST) Received: from ubuntu.home ([77.124.117.239]) by smtp.gmail.com with ESMTPSA id c2sm5252495wrt.93.2019.03.06.13.18.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 13:18:06 -0800 (PST) From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: hverkuil@xs4all.nl, helen.koike@collabora.com, Dafna Hirschfeld Subject: [v4l-utils PATCH v5 5/6] v4l2-ctl: Add functions and variables to support fwht stateless decoder Date: Wed, 6 Mar 2019 13:17:51 -0800 Message-Id: <20190306211752.15531-5-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190306211752.15531-1-dafna3@gmail.com> References: <20190306211752.15531-1-dafna3@gmail.com> 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 Add the variable 'last_fwht_bf_ts' and the array 'fwht_reqs' to allow the fwht stateless decoder to maintain the requests. Signed-off-by: Dafna Hirschfeld --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 138 ++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 9bb58a0b..4bb2d301 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -17,9 +17,12 @@ #include #include #include +#include #include "v4l2-ctl.h" #include "v4l-stream.h" +#include +#include extern "C" { #include "v4l2-tpg.h" @@ -80,6 +83,17 @@ static bool support_cap_compose; static bool support_out_crop; static bool in_source_change_event; +static __u64 last_fwht_bf_ts; +static fwht_cframe_hdr last_fwht_hdr; + +struct request_fwht { + int fd; + __u64 ts; + struct v4l2_ctrl_fwht_params params; +}; + +static request_fwht fwht_reqs[VIDEO_MAX_FRAME]; + #define TS_WINDOW 241 #define FILE_HDR_ID v4l2_fourcc('V', 'h', 'd', 'r') @@ -420,6 +434,12 @@ static int get_out_crop_rect(cv4l_fd &fd) return 0; } +static __u64 get_ns_timestamp(cv4l_buffer &buf) +{ + const struct timeval tv = buf.g_timestamp(); + return v4l2_timeval_to_ns(&tv); +} + static void set_time_stamp(cv4l_buffer &buf) { if ((buf.g_flags() & V4L2_BUF_FLAG_TIMESTAMP_MASK) != V4L2_BUF_FLAG_TIMESTAMP_COPY) @@ -749,6 +769,124 @@ void streaming_cmd(int ch, char *optarg) } } +/* + * Assume that the fwht stream is valid and that each + * frame starts right after the previous one. + */ +static bool read_fwht_frame(cv4l_fmt &fmt, unsigned char *buf, + FILE *fpointer, unsigned &sz, + unsigned &expected_len, unsigned buf_len) +{ + expected_len = sizeof(struct fwht_cframe_hdr); + if (expected_len > buf_len) + return false; + sz = fread(&last_fwht_hdr, 1, sizeof(struct fwht_cframe_hdr), fpointer); + if (sz < sizeof(struct fwht_cframe_hdr)) + return true; + + expected_len = ntohl(last_fwht_hdr.size); + if (expected_len > buf_len) + return false; + sz = fread(buf, 1, ntohl(last_fwht_hdr.size), fpointer); + return true; +} + +static void set_fwht_stateless_params(struct v4l2_ctrl_fwht_params &fwht_params, + const struct fwht_cframe_hdr *hdr, + __u64 last_bf_ts) +{ + fwht_params.backward_ref_ts = last_bf_ts; + fwht_params.version = ntohl(hdr->version); + fwht_params.width = ntohl(hdr->width); + fwht_params.height = ntohl(hdr->height); + fwht_params.flags = ntohl(hdr->flags); + fwht_params.colorspace = ntohl(hdr->colorspace); + fwht_params.xfer_func = ntohl(hdr->xfer_func); + fwht_params.ycbcr_enc = ntohl(hdr->ycbcr_enc); + fwht_params.quantization = ntohl(hdr->quantization); + + /* + * if last_bf_ts is 0 it indicates that either this is the + * first frame, or that last frame returned with an error so + * it is better not to reference it so the error won't propagate + */ + if (!last_bf_ts) + fwht_params.flags |= FWHT_FL_I_FRAME; +} + +static int alloc_fwht_req(int media_fd, unsigned index) +{ + int rc = 0; + + rc = ioctl(media_fd, MEDIA_IOC_REQUEST_ALLOC, &fwht_reqs[index]); + if (rc < 0) { + fprintf(stderr, "Unable to allocate media request: %s\n", + strerror(errno)); + return rc; + } + + return 0; +} + +static void set_fwht_req_by_idx(unsigned idx, struct fwht_cframe_hdr *hdr, + __u64 last_bf_ts, __u64 ts) +{ + struct v4l2_ctrl_fwht_params fwht_params; + + set_fwht_stateless_params(fwht_params, hdr, last_bf_ts); + + fwht_reqs[idx].ts = ts; + fwht_reqs[idx].params = fwht_params; +} + +static int get_fwht_req_by_ts(__u64 ts) +{ + for (int idx = 0; idx < VIDEO_MAX_FRAME; idx++) { + if (fwht_reqs[idx].ts == ts) + return idx; + } + return -1; +} + +static bool set_fwht_req_by_fd(struct fwht_cframe_hdr *hdr, + int req_fd, __u64 last_bf_ts, __u64 ts) +{ + struct v4l2_ctrl_fwht_params fwht_params; + + set_fwht_stateless_params(fwht_params, hdr, last_bf_ts); + + for (int idx = 0; idx < VIDEO_MAX_FRAME; idx++) { + if (fwht_reqs[idx].fd == req_fd) { + fwht_reqs[idx].ts = ts; + fwht_reqs[idx].params = fwht_params; + return true; + } + } + return false; +} + +static int set_fwht_ext_ctrl(cv4l_fd &fd, struct fwht_cframe_hdr *hdr, + __u64 last_bf_ts, int req_fd) +{ + v4l2_ext_controls controls; + struct v4l2_ext_control control; + struct v4l2_ctrl_fwht_params fwht_params; + + memset(&control, 0, sizeof(control)); + memset(&controls, 0, sizeof(controls)); + + set_fwht_stateless_params(fwht_params, hdr, last_bf_ts); + + control.id = V4L2_CID_MPEG_VIDEO_FWHT_PARAMS; + control.ptr = &fwht_params; + control.size = sizeof(fwht_params); + controls.which = V4L2_CTRL_WHICH_REQUEST_VAL; + controls.request_fd = req_fd; + controls.controls = &control; + controls.count = 1; + return fd.s_ext_ctrls(controls); +} + static bool read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf, FILE *fpointer, unsigned &sz, unsigned &expected_len, unsigned buf_len, From patchwork Wed Mar 6 21:17:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10841801 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 E42ED1669 for ; Wed, 6 Mar 2019 21:18:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D17CD2DF07 for ; Wed, 6 Mar 2019 21:18:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5D962E183; Wed, 6 Mar 2019 21:18:12 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,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 0D8962DF07 for ; Wed, 6 Mar 2019 21:18:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726351AbfCFVSL (ORCPT ); Wed, 6 Mar 2019 16:18:11 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55859 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726200AbfCFVSL (ORCPT ); Wed, 6 Mar 2019 16:18:11 -0500 Received: by mail-wm1-f67.google.com with SMTP id q187so7354685wme.5 for ; Wed, 06 Mar 2019 13:18:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=lOU282FEQucw25HOiA+H9k2htNwyhXrwhYPJi2Za5Fg=; b=lke5UHoLn9xhSxZKmw2W5oz84ehrAjJQQ8HeYNx+3IQ0I1kezHO/stF46riwtRWy06 P0MedP7zkf5jHRL32vVmPKODlFqXo6m0UkcHbFldYrr3obyAUCq+lUxloSV72Vp7rPk2 pTNFJDLiRv+gmIu7tTkz0BNS1d6DRO89DVEeBeL7ULQ+YaVgch0XePVe5zxMDKQDi8eq /Btj6zs4/UCU2FpltyW2W5pcvSN4TuZVl+NF3nStX+Jf1CbuTVob5DZ/1Vyg4vsXvg0l 6MwIlV7ewmEfbMFsFh0SucVQs7wc1x0P1xE1Pw7kiljCC9DbE546ACuEixEkr1uR/TAU jUYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=lOU282FEQucw25HOiA+H9k2htNwyhXrwhYPJi2Za5Fg=; b=MKwKhx19lZC30oh+wMk5mH6dMWzjHCatijWJIeyBCI4L+cNH7SWRwQwSyzmG/i+1uQ unC+Ipk2EDTIR8bPXqZ/lcCvLy8h7+Q284gBOgyU/Or+mKlpQkYMP50PB5gnuCMyC+pk mB1EqPFgFMbDPG8y50XXCEHlX+IP0U9XtN8Jyb9V8EK0Gg1lU+/W7Ldhu6DANp14P7sz 3dUBUeMRasUT6cudFHJy8Wn42UyJ+6wX6CHQgiA1iPJJ0xjOBedU+94lMlO72bsWDnJZ /+aYJNGlJX7A9zBGNXBTN6fAxLZ2y/6TkPK7IAGrNH357VB3/Wx8TgfvRkDyeF862QWA k3wA== X-Gm-Message-State: APjAAAX79NW2fZj/KVOquKWNA8GPjRgc4flBoULmeZJF0oc5ta8Ss7wH /qZZ6LQNfaipbq1DkHgZ7beFVjAa1ho= X-Google-Smtp-Source: APXvYqy5jK5MFda6Y8B+P9lplLc8oVb/AwFh7Zg6iYacmoLBYszzReNX1sP7zilWsT4WuNfgQDGVUQ== X-Received: by 2002:a7b:c92b:: with SMTP id h11mr3606440wml.33.1551907089002; Wed, 06 Mar 2019 13:18:09 -0800 (PST) Received: from ubuntu.home ([77.124.117.239]) by smtp.gmail.com with ESMTPSA id c2sm5252495wrt.93.2019.03.06.13.18.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 06 Mar 2019 13:18:08 -0800 (PST) From: Dafna Hirschfeld To: linux-media@vger.kernel.org Cc: hverkuil@xs4all.nl, helen.koike@collabora.com, Dafna Hirschfeld Subject: [v4l-utils PATCH v5 6/6] v4l2-ctl: Add implementation for the stateless fwht decoder. Date: Wed, 6 Mar 2019 13:17:52 -0800 Message-Id: <20190306211752.15531-6-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190306211752.15531-1-dafna3@gmail.com> References: <20190306211752.15531-1-dafna3@gmail.com> 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 Add code to support the stateless decoder and the function 'stateless_m2m' that implements it. Signed-off-by: Dafna Hirschfeld --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 218 +++++++++++++++++++++++++- 1 file changed, 210 insertions(+), 8 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 4bb2d301..2911e74f 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -1074,6 +1074,7 @@ restart: unsigned expected_len = q.g_length(j); unsigned sz; cv4l_fmt fmt; + bool res = true; fd.g_fmt(fmt, q.g_type()); if (from_with_hdr) { @@ -1085,16 +1086,22 @@ restart: } } - if (support_out_crop && v4l2_fwht_find_pixfmt(fmt.g_pixelformat())) { - if (!read_write_padded_frame(fmt, (unsigned char *)buf, - fin, sz, expected_len, buf_len, true)) - return false; - } else { + if (fmt.g_pixelformat() == V4L2_PIX_FMT_FWHT_STATELESS) + res = read_fwht_frame(fmt, (unsigned char *)buf, fin, + sz, expected_len, buf_len); + else if (support_out_crop && v4l2_fwht_find_pixfmt(fmt.g_pixelformat())) + res = read_write_padded_frame(fmt, (unsigned char *)buf, + fin, sz, expected_len, buf_len, true); + else sz = fread(buf, 1, expected_len, fin); - } + if (!res) { + fprintf(stderr, "amount intended to be read/written is larger than the buffer size\n"); + return false; + } if (first && sz != expected_len) { - fprintf(stderr, "Insufficient data\n"); + fprintf(stderr, "%s: size read (%u) is different than needed (%u) in the first frame\n", + __func__, sz, expected_len); return false; } if (j == 0 && sz == 0 && stream_loop) { @@ -1219,6 +1226,26 @@ static int do_setup_out_buffers(cv4l_fd &fd, cv4l_queue &q, FILE *fin, bool qbuf if (fin && !fill_buffer_from_file(fd, q, buf, fmt, fin)) return -2; + if (fmt.g_pixelformat() == V4L2_PIX_FMT_FWHT_STATELESS) { + int media_fd = mi_get_media_fd(fd.g_fd()); + + if (media_fd < 0) { + fprintf(stderr, "%s: mi_get_media_fd failed\n", __func__); + return media_fd; + } + + if (alloc_fwht_req(media_fd, i)) + return -1; + buf.s_request_fd(fwht_reqs[i].fd); + buf.or_flags(V4L2_BUF_FLAG_REQUEST_FD); + + if (set_fwht_ext_ctrl(fd, &last_fwht_hdr, last_fwht_bf_ts, + buf.g_request_fd())) { + fprintf(stderr, "%s: set_fwht_ext_ctrls failed on %dth buf: %s\n", + __func__, i, strerror(errno)); + return -1; + } + } if (qbuf) { set_time_stamp(buf); if (fd.qbuf(buf)) @@ -1228,6 +1255,16 @@ static int do_setup_out_buffers(cv4l_fd &fd, cv4l_queue &q, FILE *fin, bool qbuf fprintf(stderr, ">"); fflush(stderr); } + if (fmt.g_pixelformat() == V4L2_PIX_FMT_FWHT_STATELESS) { + set_fwht_req_by_idx(i, &last_fwht_hdr, + last_fwht_bf_ts, get_ns_timestamp(buf)); + last_fwht_bf_ts = get_ns_timestamp(buf); + if (ioctl(buf.g_request_fd(), MEDIA_REQUEST_IOC_QUEUE) < 0) { + fprintf(stderr, "Unable to queue media request: %s\n", + strerror(errno)); + return -1; + } + } } if (qbuf) output_field = field; @@ -1466,12 +1503,43 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE *fin, cv4l_buffer *cap (u8 *)q.g_dataptr(buf.g_index(), j)); } + if (fmt.g_pixelformat() == V4L2_PIX_FMT_FWHT_STATELESS) { + if (ioctl(buf.g_request_fd(), MEDIA_REQUEST_IOC_REINIT, NULL)) { + fprintf(stderr, "Unable to reinit media request: %s\n", + strerror(errno)); + return -1; + } + + if (set_fwht_ext_ctrl(fd, &last_fwht_hdr, last_fwht_bf_ts, + buf.g_request_fd())) { + fprintf(stderr, "%s: set_fwht_ext_ctrls failed: %s\n", + __func__, strerror(errno)); + return -1; + } + } + set_time_stamp(buf); if (fd.qbuf(buf)) { fprintf(stderr, "%s: failed: %s\n", "VIDIOC_QBUF", strerror(errno)); return -1; } + if (fmt.g_pixelformat() == V4L2_PIX_FMT_FWHT_STATELESS) { + if (!set_fwht_req_by_fd(&last_fwht_hdr, buf.g_request_fd(), last_fwht_bf_ts, + get_ns_timestamp(buf))) { + fprintf(stderr, "%s: request for fd %d does not exist\n", + __func__, buf.g_request_fd()); + return -1; + } + + last_fwht_bf_ts = get_ns_timestamp(buf); + if (ioctl(buf.g_request_fd(), MEDIA_REQUEST_IOC_QUEUE) < 0) { + fprintf(stderr, "Unable to queue media request: %s\n", + strerror(errno)); + return -1; + } + } + tpg_update_mv_count(&tpg, V4L2_FIELD_HAS_T_OR_B(output_field)); if (!verbose) @@ -2257,6 +2325,137 @@ static void stateful_m2m(cv4l_fd &fd, cv4l_queue &in, cv4l_queue &out, tpg_free(&tpg); } +static void stateless_m2m(cv4l_fd &fd, cv4l_queue &in, cv4l_queue &out, + FILE *fin, FILE *fout, cv4l_fmt &fmt_in, + cv4l_fmt &fmt_out, cv4l_fd *exp_fd_p) +{ + fps_timestamps fps_ts[2]; + unsigned count[2] = { 0, 0 }; + int fd_flags = fcntl(fd.g_fd(), F_GETFL); + + if (out.reqbufs(&fd, reqbufs_count_out)) { + fprintf(stderr, "%s: out.reqbufs failed\n", __func__); + return; + } + + if (in.reqbufs(&fd, reqbufs_count_cap)) { + fprintf(stderr, "%s: in.reqbufs failed\n", __func__); + return; + } + + if (exp_fd_p && in.export_bufs(exp_fd_p, exp_fd_p->g_type())) + return; + + if (in.obtain_bufs(&fd)) { + fprintf(stderr, "%s: in.obtain_bufs error\n", __func__); + return; + } + + if (do_setup_out_buffers(fd, out, fout, true) == -1) { + fprintf(stderr, "%s: do_setup_out_buffers failed\n", __func__); + return; + } + + if (in.queue_all(&fd)) { + fprintf(stderr, "%s: in.queue_all failed\n", __func__); + return; + } + + if (fd.streamon(out.g_type())) { + fprintf(stderr, "%s: streamon for out failed\n", __func__); + return; + } + + if (fd.streamon(in.g_type())) { + fprintf(stderr, "%s: streamon for in failed\n", __func__); + return; + } + int index = 0; + bool queue_lst_buf = false; + cv4l_buffer last_in_buf; + + fcntl(fd.g_fd(), F_SETFL, fd_flags | O_NONBLOCK); + + while (true) { + fd_set except_fds; + int req_fd =fwht_reqs[index].fd; + struct timeval tv = { 2, 0 }; + + FD_ZERO(&except_fds); + FD_SET(req_fd, &except_fds); + + int rc = select(req_fd + 1, NULL, NULL, &except_fds, &tv); + + if (rc == 0) { + fprintf(stderr, "Timeout when waiting for media request\n"); + return; + } else if (rc < 0) { + fprintf(stderr, "Unable to select media request: %s\n", + strerror(errno)); + return; + } + /* + * it is safe to queue back last cap buffer only after + * the following request is done so that the buffer + * is not needed anymore as a reference frame + */ + if (queue_lst_buf) { + if (fd.qbuf(last_in_buf) < 0) { + fprintf(stderr, "%s: qbuf failed\n", __func__); + return; + } + } + int buf_idx = -1; + /* + * fin is not sent to do_handle_cap since the capture buf is + * written to the file in current function + */ + rc = do_handle_cap(fd, in, NULL, &buf_idx, count[CAP], + fps_ts[CAP], fmt_in); + if (rc) { + fprintf(stderr, "%s: do_handle_cap err\n", __func__); + return; + } + /* + * in case of an error in the frame, set last ts to 0 as a mean + * to recover so that next request will not use a + * reference buffer. Otherwise the error flag will be set to + * all the future capture buffers. + */ + if (buf_idx == -1) { + fprintf(stderr, "%s: frame returned with error\n", __func__); + last_fwht_bf_ts = 0; + } else { + cv4l_buffer cap_buf(in, index); + if (fd.querybuf(cap_buf)) + return; + last_in_buf = cap_buf; + queue_lst_buf = true; + if (fin && cap_buf.g_bytesused(0) && + !(cap_buf.g_flags() & V4L2_BUF_FLAG_ERROR)) { + int idx = get_fwht_req_by_ts(get_ns_timestamp(cap_buf)); + + if (idx < 0) { + fprintf(stderr, "%s: could not find request from buffer\n", __func__); + fprintf(stderr, "%s: ts = %llu\n", __func__, get_ns_timestamp(cap_buf)); + return; + } + composed_width = fwht_reqs[idx].params.width; + composed_height = fwht_reqs[idx].params.height; + write_buffer_to_file(fd, in, cap_buf, + fmt_in, fin); + } + } + rc = do_handle_out(fd, out, fout, NULL, count[OUT], + fps_ts[OUT], fmt_out); + if (rc) { + fprintf(stderr, "%s: output stream ended\n", __func__); + close(req_fd); + } + index = (index + 1) % out.g_buffers(); + } +} + static void streaming_set_m2m(cv4l_fd &fd, cv4l_fd &exp_fd) { cv4l_queue in(fd.g_type(), memory); @@ -2297,7 +2496,10 @@ static void streaming_set_m2m(cv4l_fd &fd, cv4l_fd &exp_fd) if (out.export_bufs(&exp_fd, exp_fd.g_type())) goto done; } - stateful_m2m(fd, in, out, file[CAP], file[OUT], exp_fd_p); + if (fmt[OUT].g_pixelformat() == V4L2_PIX_FMT_FWHT_STATELESS) + stateless_m2m(fd, in, out, file[CAP], file[OUT], fmt[CAP], fmt[OUT], exp_fd_p); + else + stateful_m2m(fd, in, out, file[CAP], file[OUT], fmt[CAP], fmt[OUT], exp_fd_p); done: if (options[OptStreamDmaBuf] || options[OptStreamOutDmaBuf])