From patchwork Sun Feb 24 08:41:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10827753 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 F2BB51823 for ; Sun, 24 Feb 2019 08:41:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E3DEC2B815 for ; Sun, 24 Feb 2019 08:41:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D75E42B81E; Sun, 24 Feb 2019 08:41:47 +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 71FEB2B815 for ; Sun, 24 Feb 2019 08:41:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726835AbfBXIlq (ORCPT ); Sun, 24 Feb 2019 03:41:46 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37643 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725956AbfBXIlq (ORCPT ); Sun, 24 Feb 2019 03:41:46 -0500 Received: by mail-wm1-f68.google.com with SMTP id x10so5363402wmg.2 for ; Sun, 24 Feb 2019 00:41:44 -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=zSlL0LY/PtW7ZCs79BGc4JKS0Zbo+XdKqZAibVWK/oQ=; b=aCOrKsE82/deehKxFLP12f0Q//6oAywwdwo+WuPlfuMH/vLHyw9e9hcmK28TZXruda gweyVODIvGqBDZZi7NCpw5Z5JYTgnVJq7euy5O3vax82aaSqNNL8fO0omLdR5Pors909 gaB4x2Ndh5j3gtX3x+Uk+c6d9ipxk1nUaBCd0Hjme0j3mq0+zu8rNu/v/XRgHkIaD+yN I+pFKJUR03dLJiSaSjoYnwS8aQuFbQ93ATKO88f+TXlGtWRKsE5OYRA7GoscLPoIXAl2 /nf9opQUKZQvJyvzTPli4LbVv9LA/FxyvwoEtPqv1Xbg9ps23j0SyD4c5HguqHZ1qza9 97Wg== 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=zSlL0LY/PtW7ZCs79BGc4JKS0Zbo+XdKqZAibVWK/oQ=; b=KFhML50JCaTm+Nmno8N3Aveg90Uu02TVqe2GkLk2MLLIRM1R8MYC9cgzNd+vXMmvV6 t4OovRh3Ht/DpaGsbRBQyknNppOt86n0TGQ+9Pewm1rd90SRsDa5KmLZB/kTakhnvBhf a3sRFTnkic/fw5eSlU5tQqu9K/1VF9mQIBxxIAvqYKcczaWHdGU84MRTt0/odYY7b3ps ZfYlZ+/+UL2+yju0tJXkskuKAu0IsPsnorVCrf831X4PwHtiMio4UqXTgSsAFN7/8Ibl C4VT/y2RcqzVgI3k7S5xR5ynOVimR7ASxzS7b+9F9zJ3BGw2g9WMc0DZCQ1hW23XLEoI 5vDw== X-Gm-Message-State: AHQUAuYF3E9lF9Bw8L77JA1/dQ07VNwS/XragURaOe1xoEgR0lvxFn56 104vCEyhT8m8MKo17SbIhwjhA93Kg4I= X-Google-Smtp-Source: AHgI3IYcLPW/ObtfbuZ7ZjQniDvZwoTp8xSHyFtNmUvRLfvja/FDcVh8+kmjJ5p6bjfBxm0fO4ioaA== X-Received: by 2002:a1c:458:: with SMTP id 85mr6760592wme.97.1550997703979; Sun, 24 Feb 2019 00:41:43 -0800 (PST) Received: from ubuntu.home ([77.127.107.32]) by smtp.gmail.com with ESMTPSA id x24sm6837465wmi.5.2019.02.24.00.41.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Feb 2019 00:41:43 -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 v3 1/8] v4l2-ctl: rename variable 'vic_fmt' to 'info' Date: Sun, 24 Feb 2019 00:41:19 -0800 Message-Id: <20190224084126.19412-2-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190224084126.19412-1-dafna3@gmail.com> References: <20190224084126.19412-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 This is a better name for 'v4l2_fwht_pixfmt_info' type and it is not confused with 'cv4l_fmt' type. Signed-off-by: Dafna Hirschfeld --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 766872b5..352b946d 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -753,7 +753,7 @@ static void read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf, FILE *fpointer, unsigned &sz, unsigned &len, bool is_read) { - const struct v4l2_fwht_pixfmt_info *vic_fmt = + const struct v4l2_fwht_pixfmt_info *info = v4l2_fwht_find_pixfmt(fmt.g_pixelformat()); unsigned coded_height = fmt.g_height(); unsigned real_width; @@ -770,14 +770,14 @@ static void read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf, } sz = 0; - len = real_width * real_height * vic_fmt->sizeimage_mult / vic_fmt->sizeimage_div; + len = real_width * real_height * info->sizeimage_mult / info->sizeimage_div; - for (unsigned plane_idx = 0; plane_idx < vic_fmt->planes_num; plane_idx++) { + 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 ? vic_fmt->height_div : 1; - unsigned w_div = is_chroma_plane ? vic_fmt->width_div : 1; - unsigned step = is_chroma_plane ? vic_fmt->chroma_step : vic_fmt->luma_alpha_step; - unsigned stride_div = (vic_fmt->planes_num == 3 && plane_idx > 0) ? 2 : 1; + unsigned h_div = is_chroma_plane ? info->height_div : 1; + unsigned w_div = is_chroma_plane ? info->width_div : 1; + unsigned step = is_chroma_plane ? info->chroma_step : info->luma_alpha_step; + unsigned stride_div = (info->planes_num == 3 && plane_idx > 0) ? 2 : 1; row_p = plane_p; for (unsigned i = 0; i < real_height / h_div; i++) { From patchwork Sun Feb 24 08:41:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10827755 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 ADFD06C2 for ; Sun, 24 Feb 2019 08:41:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9DB912B815 for ; Sun, 24 Feb 2019 08:41:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9217E2B81E; Sun, 24 Feb 2019 08:41:48 +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 3D8AB2B815 for ; Sun, 24 Feb 2019 08:41:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726865AbfBXIlr (ORCPT ); Sun, 24 Feb 2019 03:41:47 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:39594 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725771AbfBXIlr (ORCPT ); Sun, 24 Feb 2019 03:41:47 -0500 Received: by mail-wr1-f68.google.com with SMTP id l5so6638052wrw.6 for ; Sun, 24 Feb 2019 00:41:46 -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=dABEz0fJdhaPuLioYTDa9ju/kgubMdcKZ7LfKuQKK1M=; b=C9GePseimwzh/trIGz4A8cSMxxbDfxMQG/VReePMqAwDWSNLG2B7C3ERavS6sGhuc3 +FNE/q0kDsy4VyGkRwy3pRgNFLxKkbYtmznN4EyrK6h8uAoZ0xowGaqBn1NuSl9E/fES tyliN8kjYRIQbYSJR8iGY+gU4RZKpT3vtCUcoeZzgDh56Dpy7w9B0rRie+31tlIeF0VI AmkAenzdEtlMSbHv/NbTc50b2HB3Cuk5KYaa0hw+AwnZJszm5y+jz0BZ2NXFs9XO2T6x v/J8J81Rrk/U8AeAIkw++uC+sevERcPJ8ZfPgVBQQaO8Qn/QzxEOgLcQSUhssilJ0pbd ogrw== 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=dABEz0fJdhaPuLioYTDa9ju/kgubMdcKZ7LfKuQKK1M=; b=jmJFt+wHwIER7aoCFzxoUAA2NfcwnhvkEEjFccANw2C0XPdF4B24ZwVbgSSb2glfUq 7VAe8MI5LwoWMq2rxcFpCy6+e6iE9aQMBC1CtvG65rhgnyFJNeGDWlgpe2z52Q4JlZJ5 qX/FyewYUvcMPw4lTxqmb3IBKEOQDpk41bfpaz0CTzvXYahToWWQdunazR4ZBM1tCyTF 6cKK4knFAgqhH4S83Te9S2iUSQKFjLH7NYJP5qbnBxoauhCIBC2aPW56FnVfwb4UVHgT syh1bkFctDOqMHrBY/fgl5Uh/CVos8ijsJTXXgFYB4ETKzdjKpFB1QFlOuoktPWh0Sgx kdTw== X-Gm-Message-State: AHQUAuYoyXpAj6Lh6GBGSMs/AKrigo19rLAru1dl9YpBeSrU7H6ODLM3 l9n8w9wxYDvPC8VvVwjkKCve6lONMGQ= X-Google-Smtp-Source: AHgI3Ibkz8e+w+yU0dc0SGaUpUkqtQG7JRiNduCi7U/qKXvnlEWQ2pT/ucn7ONBfl+SuZoAAGJSZ4Q== X-Received: by 2002:adf:f3d0:: with SMTP id g16mr8579380wrp.29.1550997705319; Sun, 24 Feb 2019 00:41:45 -0800 (PST) Received: from ubuntu.home ([77.127.107.32]) by smtp.gmail.com with ESMTPSA id x24sm6837465wmi.5.2019.02.24.00.41.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Feb 2019 00:41:44 -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 v3 2/8] v4l2-ctl: bugfix: correctly read/write V4L2_PIX_FMT_NV24 padded buffer Date: Sun, 24 Feb 2019 00:41:20 -0800 Message-Id: <20190224084126.19412-3-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190224084126.19412-1-dafna3@gmail.com> References: <20190224084126.19412-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 For V4L2_PIX_FMT_NV24/42 types the chroma stride is twice the luma stride. Add support for it in 'read_write_padded_frame' Signed-off-by: Dafna Hirschfeld --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 352b946d..6f4317bf 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -760,6 +760,7 @@ static void read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf, unsigned real_height; unsigned char *plane_p = buf; unsigned char *row_p; + unsigned stride = fmt.g_bytesperline(); if (is_read) { real_width = cropped_width; @@ -776,13 +777,20 @@ static void read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf, bool is_chroma_plane = plane_idx == 1 || plane_idx == 2; unsigned h_div = is_chroma_plane ? info->height_div : 1; unsigned w_div = is_chroma_plane ? info->width_div : 1; - unsigned step = is_chroma_plane ? info->chroma_step : info->luma_alpha_step; - unsigned stride_div = (info->planes_num == 3 && plane_idx > 0) ? 2 : 1; + unsigned step = is_chroma_plane ? info->chroma_step : + info->luma_alpha_step; + unsigned int consume_sz = step * real_width / w_div; + + if (info->planes_num == 3 && plane_idx == 1) + stride /= 2; + + if (plane_idx == 1 && + (info->id == V4L2_PIX_FMT_NV24 || info->id == V4L2_PIX_FMT_NV42)) + stride *= 2; row_p = plane_p; for (unsigned i = 0; i < real_height / h_div; i++) { unsigned int wsz = 0; - unsigned int consume_sz = step * real_width / w_div; if (is_read) wsz = fread(row_p, 1, consume_sz, fpointer); @@ -795,9 +803,9 @@ static void read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf, return; } sz += wsz; - row_p += fmt.g_bytesperline() / stride_div; + row_p += stride; } - plane_p += (fmt.g_bytesperline() / stride_div) * (coded_height / h_div); + plane_p += stride * (coded_height / h_div); if (sz == 0) break; } From patchwork Sun Feb 24 08:41:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10827757 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 46C686C2 for ; Sun, 24 Feb 2019 08:41:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 376ED2B815 for ; Sun, 24 Feb 2019 08:41:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BEEC2B81E; Sun, 24 Feb 2019 08:41:50 +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 C9F3C2B815 for ; Sun, 24 Feb 2019 08:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727991AbfBXIlt (ORCPT ); Sun, 24 Feb 2019 03:41:49 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:42120 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727852AbfBXIls (ORCPT ); Sun, 24 Feb 2019 03:41:48 -0500 Received: by mail-wr1-f66.google.com with SMTP id r5so6619742wrg.9 for ; Sun, 24 Feb 2019 00:41:47 -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=cfjeHo1iFRc8mnM48I4Vxv7KgBP6gIHg/llP/xNtlhY=; b=HgamxFEopJwRq/A7AAU2OSpato/E13ls40XEr7yduf8J63/h370yaic83vhdZWxOod lJ/GAeNn3JQpwjMVptDnzDsI4Y802wOsHc/mgX8VSP5Js3f0mkyxa/GA8BdBVmzzjV4S LUUJZ4MiVDcsN4CWKJhruJ01A1FG++Vea591GhqWrJHwYtH0rR2zAM6ewMyMhz7gZfRM rX9Si3if0B6XGQfbAL+xUNf6Q4VhfQoWC0LmS5X6miEtuhCLTMqzpmDOS1p2acbHwOpl wfNbozolsMAP4Vvv1FFu1SBfYf+9zhAQZJSZP+eaULh/eauj3HO4YrAKsmtiai7h8WGw crCw== 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=cfjeHo1iFRc8mnM48I4Vxv7KgBP6gIHg/llP/xNtlhY=; b=AVafTKS2iC3qXMoAzGTsoMyXyf2D2NlyclQUK/kfZuRGJP7FgCpyplpkwNMVvtldvu IriFdKTvFGs89kFeADomgy186ZzVP5fdFsmXEg81sZUu6LOcIujL2hrj7bB862O00daI Wjm4AYNrFr2R9j/09ycjSWH82M3vnInlu9VONJQQs2L3tztFl3a3DR20AiQTA2ZbaivU hTUQe6QIdVUtkPidt1ouQOQ8kZufFYs2WiAnpMpESR/TJpA1aQjnivTPzW8y63UL8LCP rch54FUeUXhynnAsxeAIrtG4z/cmHSoc+6Cdw6JmduTojMT4KEdG6Mfen4gqgkccnstZ IUXA== X-Gm-Message-State: AHQUAuaDnmU/KQhtdrDKvIsLlTEwzs5W73n7c8hxvosVmcsEkVT+Nhe8 eLoy7ghUIVjeeId1efGOqTtJYqGJI3A= X-Google-Smtp-Source: AHgI3IbdY1ZG8XzepZWJOxlUBzHcVh2RgUvwh2f52A3UC463sAy23KTHmkhMUM5+XPE92lWWhBdxvw== X-Received: by 2002:a5d:4a8a:: with SMTP id o10mr8678666wrq.189.1550997706742; Sun, 24 Feb 2019 00:41:46 -0800 (PST) Received: from ubuntu.home ([77.127.107.32]) by smtp.gmail.com with ESMTPSA id x24sm6837465wmi.5.2019.02.24.00.41.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Feb 2019 00:41:46 -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 v3 3/8] v4l2-ctl: test if do_setup_out_buffers returns -1 instead of non zero Date: Sun, 24 Feb 2019 00:41:21 -0800 Message-Id: <20190224084126.19412-4-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190224084126.19412-1-dafna3@gmail.com> References: <20190224084126.19412-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 If 'do_setup_out_buffers' returns -2 it means that it finished queuing all output stream buffers and the program should not terminate in that case. Signed-off-by: Dafna Hirschfeld --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 6f4317bf..d023aa12 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -1823,7 +1823,7 @@ static void streaming_set_out(cv4l_fd &fd, cv4l_fd &exp_fd) if (q.obtain_bufs(&fd)) goto done; - if (do_setup_out_buffers(fd, q, fin, true)) + if (do_setup_out_buffers(fd, q, fin, true) == -1) goto done; fps_ts.determine_field(fd.g_fd(), type); @@ -2013,7 +2013,7 @@ static void streaming_set_m2m(cv4l_fd &fd, cv4l_fd &exp_fd) goto done; } - if (do_setup_out_buffers(fd, out, file[OUT], true)) + if (do_setup_out_buffers(fd, out, file[OUT], true) == -1) goto done; if (fd.streamon(out.g_type())) @@ -2250,7 +2250,7 @@ static void streaming_set_cap2out(cv4l_fd &fd, cv4l_fd &out_fd) if (in.obtain_bufs(&fd) || in.queue_all(&fd) || - do_setup_out_buffers(out_fd, out, file[OUT], false)) + do_setup_out_buffers(out_fd, out, file[OUT], false) == -1) goto done; fps_ts[CAP].determine_field(fd.g_fd(), in.g_type()); From patchwork Sun Feb 24 08:41:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10827759 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 F1EBB922 for ; Sun, 24 Feb 2019 08:41:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E10812B815 for ; Sun, 24 Feb 2019 08:41:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D59F62B81E; Sun, 24 Feb 2019 08:41:51 +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 50E8A2B815 for ; Sun, 24 Feb 2019 08:41:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728044AbfBXIlu (ORCPT ); Sun, 24 Feb 2019 03:41:50 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:39997 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728004AbfBXIlu (ORCPT ); Sun, 24 Feb 2019 03:41:50 -0500 Received: by mail-wr1-f65.google.com with SMTP id q1so6634386wrp.7 for ; Sun, 24 Feb 2019 00:41:49 -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=ns4WGCSLgi1S+SEMpf3XoTWMZrlpDZ1rKCBURPTfYvk=; b=XEs7qeISuDq1tJgmXFzqtUT/MD7aH6rfA9a/DZJ+xzKVoizJAb2Kh00X+KNIg9oYgJ +h4JdHK7cgyG2IFLKai9J3cgHjlqHN2bbbF/Iz87syasDpcO6kp8IUJ3SF/8MK5HGe9r PxrTuInJFNQszyak4U28L6nfk1keDaty4JWqne1o4SVjTa+JyVuZbJFjEJItyNI8vDiF qNIXa1/zgV/uDmRbw+KGozFwUK8bhRF+YY+lVS40OqVcwnAWoXX/hD4ck2Kl79ovP97K Bs0agsz8qydo2vPqWLS0Ew8SATEGB5gw73JnxgRqA6jbE3GnWSyH0GG9XDK0DVYxE6dt nUwQ== 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=ns4WGCSLgi1S+SEMpf3XoTWMZrlpDZ1rKCBURPTfYvk=; b=LD5+3W6AlWj01UBKxteQjF4aWw4VjbY1sKAbcqXLLmInQmFXHIC8/1uEZRp+LjvXvJ Jv5qBpqHYLLsVyyNopcs8ePOjHCCLuNlVwp4YC5S+V4BGU075ZZFIi20oV2s+x1r+R0I EhmgaA9RNEMms9WshO3jSIZqrWAkDYpA+5xyXzxwq95SUZug/QYvf5bcuElRYS+ZjsPG AjS/ohKUSFzL/Z8q3jCQit/WXHmEMi0giiaD8yzDhJyiKSQ0jNfIayni7zIIROxf06Mn AA8T6II2pO/bmhmhGMujszFv0zkOlUvJomIaNen7L2XDAS1Bso0SUVjcsSkoKpBDfrUC yLwQ== X-Gm-Message-State: AHQUAubL1qEj1FeIvrZG7uYBye+oCuZAPkaQQsAft4tNfXVsEugTS5cT bG3h5Umy9LfmeYnMh0zEMYg62tkaZe8= X-Google-Smtp-Source: AHgI3IbgJ6PbrswsSMzL6g+bktei5xLgripAPREmtHDATb6iGAJrmHd24EHx81d2FBCzPTAEDRauBA== X-Received: by 2002:adf:9d85:: with SMTP id p5mr8598679wre.215.1550997708086; Sun, 24 Feb 2019 00:41:48 -0800 (PST) Received: from ubuntu.home ([77.127.107.32]) by smtp.gmail.com with ESMTPSA id x24sm6837465wmi.5.2019.02.24.00.41.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Feb 2019 00:41:47 -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 v3 4/8] v4l2-ctl: move stateful m2m decode code to a separate function Date: Sun, 24 Feb 2019 00:41:22 -0800 Message-Id: <20190224084126.19412-5-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190224084126.19412-1-dafna3@gmail.com> References: <20190224084126.19412-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 function stateful_m2m that implements the stateful codec api. This is a preparation for having both stateful and stateless implementations Signed-off-by: Dafna Hirschfeld --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 95 ++++++++++++++------------- 1 file changed, 50 insertions(+), 45 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index d023aa12..adfa6796 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -1941,16 +1941,12 @@ static int capture_setup(cv4l_fd &fd, cv4l_queue &in, cv4l_fd *exp_fd) return 0; } -static void streaming_set_m2m(cv4l_fd &fd, 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) { int fd_flags = fcntl(fd.g_fd(), F_GETFL); - cv4l_queue in(fd.g_type(), memory); - cv4l_queue out(v4l_type_invert(fd.g_type()), out_memory); - cv4l_queue exp_q(exp_fd.g_type(), V4L2_MEMORY_MMAP); - cv4l_fd *exp_fd_p = NULL; fps_timestamps fps_ts[2]; unsigned count[2] = { 0, 0 }; - FILE *file[2] = {NULL, NULL}; fd_set fds[3]; fd_set *rd_fds = &fds[0]; /* for capture */ fd_set *ex_fds = &fds[1]; /* for capture */ @@ -1961,19 +1957,6 @@ static void streaming_set_m2m(cv4l_fd &fd, cv4l_fd &exp_fd) 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"); - return; - } - if (options[OptStreamDmaBuf] && options[OptStreamOutDmaBuf]) { - fprintf(stderr, "--stream-dmabuf and --stream-out-dmabuf not supported for m2m devices\n"); - return; - } - if ((options[OptStreamDmaBuf] || options[OptStreamOutDmaBuf]) && exp_fd.g_fd() < 0) { - fprintf(stderr, "--stream-dmabuf or --stream-out-dmabuf can only work in combination with --export-device\n"); - return; - } - struct v4l2_event_subscription sub; memset(&sub, 0, sizeof(sub)); @@ -1994,34 +1977,18 @@ static void streaming_set_m2m(cv4l_fd &fd, cv4l_fd &exp_fd) sub.type = V4L2_EVENT_SOURCE_CHANGE; bool have_source_change = !fd.subscribe_event(sub); - file[CAP] = open_output_file(fd); - file[OUT] = open_input_file(fd, out.g_type()); - if (out.reqbufs(&fd, reqbufs_count_out)) - goto done; - - if (options[OptStreamDmaBuf]) { - if (exp_q.reqbufs(&exp_fd, reqbufs_count_cap)) - goto done; - exp_fd_p = &exp_fd; - } - - if (options[OptStreamOutDmaBuf]) { - if (exp_q.reqbufs(&exp_fd, reqbufs_count_out)) - goto done; - if (out.export_bufs(&exp_fd, exp_fd.g_type())) - goto done; - } + return; - if (do_setup_out_buffers(fd, out, file[OUT], true) == -1) - goto done; + if (do_setup_out_buffers(fd, out, fout, true) == -1) + return; if (fd.streamon(out.g_type())) - goto done; + return; if (codec_type != DECODER || !have_source_change) if (capture_setup(fd, in, exp_fd_p)) - goto done; + return; fps_ts[CAP].determine_field(fd.g_fd(), in.g_type()); fps_ts[OUT].determine_field(fd.g_fd(), out.g_type()); @@ -2057,15 +2024,15 @@ static void streaming_set_m2m(cv4l_fd &fd, cv4l_fd &exp_fd) continue; fprintf(stderr, "select error: %s\n", strerror(errno)); - goto done; + return; } if (r == 0) { fprintf(stderr, "select timeout\n"); - goto done; + return; } if (rd_fds && FD_ISSET(fd.g_fd(), rd_fds)) { - r = do_handle_cap(fd, in, file[CAP], NULL, + r = do_handle_cap(fd, in, fin, NULL, count[CAP], fps_ts[CAP], fmt[CAP]); if (r < 0) { rd_fds = NULL; @@ -2077,7 +2044,7 @@ static void streaming_set_m2m(cv4l_fd &fd, cv4l_fd &exp_fd) } if (wr_fds && FD_ISSET(fd.g_fd(), wr_fds)) { - r = do_handle_out(fd, out, file[OUT], NULL, + r = do_handle_out(fd, out, fout, NULL, count[OUT], fps_ts[OUT], fmt[OUT]); if (r < 0) { wr_fds = NULL; @@ -2128,7 +2095,7 @@ static void streaming_set_m2m(cv4l_fd &fd, cv4l_fd &exp_fd) in_source_change_event = false; last_buffer = false; if (capture_setup(fd, in, exp_fd_p)) - goto done; + return; fd.g_fmt(fmt[OUT], out.g_type()); fd.g_fmt(fmt[CAP], in.g_type()); cap_streaming = true; @@ -2146,7 +2113,45 @@ static void streaming_set_m2m(cv4l_fd &fd, cv4l_fd &exp_fd) in.free(&fd); out.free(&fd); tpg_free(&tpg); +} + +static void streaming_set_m2m(cv4l_fd &fd, cv4l_fd &exp_fd) +{ + cv4l_queue in(fd.g_type(), memory); + cv4l_queue out(v4l_type_invert(fd.g_type()), out_memory); + cv4l_queue exp_q(exp_fd.g_type(), V4L2_MEMORY_MMAP); + cv4l_fd *exp_fd_p = NULL; + FILE *file[2] = {NULL, NULL}; + + if (!fd.has_vid_m2m()) { + fprintf(stderr, "unsupported m2m stream type\n"); + return; + } + if (options[OptStreamDmaBuf] && options[OptStreamOutDmaBuf]) { + fprintf(stderr, "--stream-dmabuf and --stream-out-dmabuf not supported for m2m devices\n"); + return; + } + if ((options[OptStreamDmaBuf] || options[OptStreamOutDmaBuf]) && exp_fd.g_fd() < 0) { + fprintf(stderr, "--stream-dmabuf or --stream-out-dmabuf can only work in combination with --export-device\n"); + return; + } + file[CAP] = open_output_file(fd); + file[OUT] = open_input_file(fd, out.g_type()); + + if (options[OptStreamDmaBuf]) { + if (exp_q.reqbufs(&exp_fd, reqbufs_count_cap)) + return; + exp_fd_p = &exp_fd; + } + + if (options[OptStreamOutDmaBuf]) { + if (exp_q.reqbufs(&exp_fd, reqbufs_count_out)) + return; + if (out.export_bufs(&exp_fd, exp_fd.g_type())) + return; + } + 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 Sun Feb 24 08:41:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10827761 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 4B6AA922 for ; Sun, 24 Feb 2019 08:41:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B96F2B815 for ; Sun, 24 Feb 2019 08:41:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 300CB2B81E; Sun, 24 Feb 2019 08:41:53 +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 C6CEC2B815 for ; Sun, 24 Feb 2019 08:41:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728121AbfBXIlw (ORCPT ); Sun, 24 Feb 2019 03:41:52 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:32993 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727852AbfBXIlv (ORCPT ); Sun, 24 Feb 2019 03:41:51 -0500 Received: by mail-wr1-f66.google.com with SMTP id i12so6666498wrw.0 for ; Sun, 24 Feb 2019 00:41:50 -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=2Kz4T0TAMia1m8zxthVlaxPb1YjonSLkcRZLcMO9ol4=; b=KKZoKSyj6SmSby+07MvtXXNwppFj1n6hQdObGavxCBCK44Wu40O+P6DwVMHFUZie4y fW08vsJrlOUwRhnOzV3EWq4m/qNbUgsVlhxVsoh5j2XW/mo8McAeAD/PfLS2IwBPSw7g pRmTgT9i79JQ0YiG9LlQ7gmMLHU2yUQ+8qp9cIC2hAUPa68fz8v9x1f9abWSNrbAbbWa Fy1Fu46qnnIBlRgoeT2ooWYAI/SA8lbCdnHwXUlyPy/be1f1APJat9Q6KT4MBWubuvsO MtPW8IVcXJtEK4AnLI1JyLz+MhcUHBbRDYOgwKIwfuNgT88m/YXXfnNh+kbvQTwvQXLY hxmg== 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=2Kz4T0TAMia1m8zxthVlaxPb1YjonSLkcRZLcMO9ol4=; b=tujBNHeASlI4AYAqDW435nlNqr8gY2rRsLxaRS72r7ZFrH+9hCfI3+E987l7jIu5sA dzwZjNHEvhOp8SYWfbLwaBTJgHiwJ4kS38F8L05LXdx4n55pMw06m/32bg0V23BF9f8N efn9WcwclPskt8xtge8Yu+a/SENkj/P58Ip+d1iGL7Z8j4XRLgt4H6KF1AGWdIWtSgO9 tYycnx8KZZfCrwe80d0m6bLCRKg9vvU4lcgzwZJGaO53QHTSiyiarybaX5FdIPAV61WB ozguv8A2qJAHh2fPlZD8M4Nkv5S1kpkdmzbIvDXUEn1TD0ITGvz8lN7T8RGX/2f3UR1b dzvg== X-Gm-Message-State: AHQUAua0g+wvGuy8ohepSF9pnVlYlNpZzjyB/FNp+HXRNw+6sJYdNtGG M3dKN6tyWxHOc1ve95r+BZm3g3MIjH8= X-Google-Smtp-Source: AHgI3IYzP9zL3VHA3nqF1vltQceamy8YlhKze4P3Jsk7bPY5ZPSOBDyNYSa6Fw3TGCJ3IYYjMuftZw== X-Received: by 2002:a05:6000:1142:: with SMTP id d2mr8477794wrx.43.1550997709462; Sun, 24 Feb 2019 00:41:49 -0800 (PST) Received: from ubuntu.home ([77.127.107.32]) by smtp.gmail.com with ESMTPSA id x24sm6837465wmi.5.2019.02.24.00.41.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Feb 2019 00:41:48 -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 v3 5/8] (c)v4l-helpers.h: Add support for the request api Date: Sun, 24 Feb 2019 00:41:23 -0800 Message-Id: <20190224084126.19412-6-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190224084126.19412-1-dafna3@gmail.com> References: <20190224084126.19412-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 an array of request file descriptors to v4l_queue and add methods to allocate and get them. Signed-off-by: Dafna Hirschfeld --- utils/common/cv4l-helpers.h | 5 +++++ utils/common/v4l-helpers.h | 22 ++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/utils/common/cv4l-helpers.h b/utils/common/cv4l-helpers.h index 1cd2b6b2..551d4673 100644 --- a/utils/common/cv4l-helpers.h +++ b/utils/common/cv4l-helpers.h @@ -745,6 +745,7 @@ public: unsigned g_capabilities() const { return v4l_queue_g_capabilities(this); } unsigned g_length(unsigned plane) const { return v4l_queue_g_length(this, plane); } unsigned g_mem_offset(unsigned index, unsigned plane) const { return v4l_queue_g_mem_offset(this, index, plane); } + unsigned g_req_fd(unsigned index) const { return v4l_queue_g_req_fd(this, index); } void *g_mmapping(unsigned index, unsigned plane) const { return v4l_queue_g_mmapping(this, index, plane); } void s_mmapping(unsigned index, unsigned plane, void *m) { v4l_queue_s_mmapping(this, index, plane, m); } void *g_userptr(unsigned index, unsigned plane) const { return v4l_queue_g_userptr(this, index, plane); } @@ -797,6 +798,10 @@ public: { return v4l_queue_export_bufs(fd->g_v4l_fd(), this, exp_type); } + int alloc_req(int media_fd, unsigned index) + { + return v4l_queue_alloc_req(this, media_fd, index); + } void close_exported_fds() { v4l_queue_close_exported_fds(this); diff --git a/utils/common/v4l-helpers.h b/utils/common/v4l-helpers.h index 59d8566a..daa49a1f 100644 --- a/utils/common/v4l-helpers.h +++ b/utils/common/v4l-helpers.h @@ -10,6 +10,7 @@ #define _V4L_HELPERS_H_ #include +#include #include #include #include @@ -1414,6 +1415,7 @@ struct v4l_queue { void *mmappings[VIDEO_MAX_FRAME][VIDEO_MAX_PLANES]; unsigned long userptrs[VIDEO_MAX_FRAME][VIDEO_MAX_PLANES]; int fds[VIDEO_MAX_FRAME][VIDEO_MAX_PLANES]; + int req_fds[VIDEO_MAX_FRAME]; }; static inline void v4l_queue_init(struct v4l_queue *q, @@ -1445,6 +1447,11 @@ static inline __u32 v4l_queue_g_mem_offset(const struct v4l_queue *q, unsigned i return q->mem_offsets[index][plane]; } +static inline unsigned v4l_queue_g_req_fd(const struct v4l_queue *q, unsigned index) +{ + return q->req_fds[index]; +} + static inline void v4l_queue_s_mmapping(struct v4l_queue *q, unsigned index, unsigned plane, void *m) { q->mmappings[index][plane] = m; @@ -1701,6 +1708,21 @@ static inline int v4l_queue_export_bufs(struct v4l_fd *f, struct v4l_queue *q, return 0; } +static inline int v4l_queue_alloc_req(struct v4l_queue *q, int media_fd, unsigned index) +{ + int rc = 0; + + rc = ioctl(media_fd, MEDIA_IOC_REQUEST_ALLOC, &q->req_fds[index]); + if (rc < 0) { + fprintf(stderr, "Unable to allocate media request: %s\n", + strerror(errno)); + return rc; + } + + return 0; +} + + static inline void v4l_queue_close_exported_fds(struct v4l_queue *q) { unsigned b, p; From patchwork Sun Feb 24 08:41:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10827763 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 704ED6C2 for ; Sun, 24 Feb 2019 08:41:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5FF4D2B815 for ; Sun, 24 Feb 2019 08:41:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 528F52B81E; Sun, 24 Feb 2019 08:41: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=-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 F1AF42B815 for ; Sun, 24 Feb 2019 08:41:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728141AbfBXIlx (ORCPT ); Sun, 24 Feb 2019 03:41:53 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39158 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728004AbfBXIlx (ORCPT ); Sun, 24 Feb 2019 03:41:53 -0500 Received: by mail-wm1-f66.google.com with SMTP id z84so5382953wmg.4 for ; Sun, 24 Feb 2019 00:41:51 -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=pVa8n2JkrJDhd3mKrTEqaDYfUFQ4mLR8mJrsRnmeqNmIhA/FXmGDw9x4pLXDMTWuAq vKvkkwLqMkaS2V3wA4e4cwVBWcJQAX16y32GxD+bNrkPH2NTET2XaOIjoFFS+hA1U2eu rd3RbnHLMTSP6SMApSXU9HVvgwOsmKIjtG6KKXFTIkWN8IO6/PzePfAqYh+upA3Ifn6V M5ChFuegGAqmwbCYA4YiDVcZhWWyh+t0Nf6aNSfgAGciUtPywNm0GIscmEDmrDjCaSwm uIedAUz+3OVlgiJ33FrTx2Xf5F43dVXm+OGDDKDdVi/ngWHxZJIcw03TrtxUerziFCuI 4l0g== 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=ACabNd/T1g26f0W8FpS7FGdw5QHEL1+W948+RZqjEuweXiPH/c4Qnog4+726xs+dcK zIr4IV7NdgnLKfb7KaR5tuW0VY5otTAu08heezxH+qLtXuG2KfQBS/brVUzJP8qKW4m/ 1BDaCnbLVPJxggazK0FWYSKgbFrcAEBKV4iVjMN3g0wk0MN4Z4vnBUFHtIMKNzbQsWZy OxICjtX3ViopwO/8kcnLUWnvLa6tgcN68Fmy6dIOzX/H/1UEWUXZ42GsatRSsJCdOK4q NrkABQvcu5K3tfMhxP1fLr4ohmcFgKJDuuw0MtVXjCcSrOcjA6uT+JXK/3bnEdr5PKpn mNkQ== X-Gm-Message-State: AHQUAubM4siQcU6/yGczJu+3E1YQXuXykpVLZe0PsDaUpyzDmBpmpVxs QqlhUJC3J+oo1VD2buByJWBL3uOSxqg= X-Google-Smtp-Source: AHgI3IbVBFjddJCulfAjZx80+UH5H9R/mKyZisqhJyI/cA5YBDmtO3Xy33yryU2bI5KormhkpFwUfA== X-Received: by 2002:a1c:6a18:: with SMTP id f24mr2257721wmc.115.1550997710791; Sun, 24 Feb 2019 00:41:50 -0800 (PST) Received: from ubuntu.home ([77.127.107.32]) by smtp.gmail.com with ESMTPSA id x24sm6837465wmi.5.2019.02.24.00.41.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Feb 2019 00:41:50 -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 v3 6/8] v4l-utils: copy fwht-ctrls.h from kernel dir Date: Sun, 24 Feb 2019 00:41:24 -0800 Message-Id: <20190224084126.19412-7-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190224084126.19412-1-dafna3@gmail.com> References: <20190224084126.19412-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 Sun Feb 24 08:41:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10827767 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 54A57922 for ; Sun, 24 Feb 2019 08:42:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 451A62B815 for ; Sun, 24 Feb 2019 08:42:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 39AA22B81E; Sun, 24 Feb 2019 08:42:00 +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 DD3B22B815 for ; Sun, 24 Feb 2019 08:41:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728143AbfBXIlz (ORCPT ); Sun, 24 Feb 2019 03:41:55 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36294 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727852AbfBXIlz (ORCPT ); Sun, 24 Feb 2019 03:41:55 -0500 Received: by mail-wr1-f66.google.com with SMTP id o17so6658587wrw.3 for ; Sun, 24 Feb 2019 00:41:53 -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=3WBY80YWjmrk2S5u9d0O5Idg6JypkTmldeUtaZbtG8Y=; b=S3r6RuDfUw4qAW3LyKq1izmS83T0fFHMAOnXbgmKt6c1hB4voYB0dQA/MYd6kMfxY1 haRt5zz2hiA3yTP9mXw6EWEPhiMZELwTkFd17xbiUWsjwg6XjHJNrIcCykdd6CsVKMph u+uGpR6StvLkp4IpJvljtEIUsVjwM5mWJJIHANxkTuHMFVkusLUbI86YH3CXdenobpN2 0clTbQChKG/o9Dj0JO4K2/8XjsSBkMAg1/loUtrksLaKc1GeD5P8thZg0PDyQjHYzEqv vPHBWuDNeUg3q/9rQVDvfzKR7YPqU/gCuD0lJHbUMpb5HJG+dS4x29+PtPa1aPPPVYEO 3n/g== 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=3WBY80YWjmrk2S5u9d0O5Idg6JypkTmldeUtaZbtG8Y=; b=JP/rkkTkshHBmyKDefldEa6x/je5r88lH1SeniKpzy0B4k23kP0OfXaAVHo2hLQusT Ct5AXhr6CaoMMGStPhfWxMChROOzdohfU1gRM4pWvZiELY9CN/xffgQI8V9UNOnfSRn8 94E5kwCaHXXfIxfi1bu6lCHTwj6qM6GYunb7Oh4Q/k4AGzbt2TnbAxU4xObxjyT64ldA wLGxagazDxAqx5T9Xoxs9+Li6aZWyPAj1VQfGRJtK8DIxwoUCAWjGoO+gwUw8D7qGKXi nA35AjdrjGlfFyDLNkd7q+F2geDpF5ziOAlPy+AEQINJjRKI+KdNqIlSPHVW77xReIIo N0HA== X-Gm-Message-State: AHQUAuYvaJfNZZtv1q5NepHq2EKvS1iGEBru6Isl7FOI54LImftjua0U UBby+9JLjS3RM4pppfxqU/O6RJ8LTng= X-Google-Smtp-Source: AHgI3IaW/F0dSFRg9j+fdutetVhlVFEJsg5cS2TsdYMXi+gR3Br7HUmMQ2c4bCIrscAaNXY84Ag+uw== X-Received: by 2002:adf:e5c5:: with SMTP id a5mr8586304wrn.13.1550997712128; Sun, 24 Feb 2019 00:41:52 -0800 (PST) Received: from ubuntu.home ([77.127.107.32]) by smtp.gmail.com with ESMTPSA id x24sm6837465wmi.5.2019.02.24.00.41.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Feb 2019 00:41:51 -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 v3 7/8] v4l2-ctl: Add functions and variables to support fwht stateless decoder Date: Sun, 24 Feb 2019 00:41:25 -0800 Message-Id: <20190224084126.19412-8-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190224084126.19412-1-dafna3@gmail.com> References: <20190224084126.19412-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 | 121 ++++++++++++++++++++++++++ 1 file changed, 121 insertions(+) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index adfa6796..82a93d4b 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -20,11 +20,18 @@ #include "v4l2-ctl.h" #include "v4l-stream.h" +#include +#include extern "C" { #include "v4l2-tpg.h" } +#define VICODEC_CID_CUSTOM_BASE (V4L2_CID_MPEG_BASE | 0xf000) +#define VICODEC_CID_I_FRAME_QP (VICODEC_CID_CUSTOM_BASE + 0) +#define VICODEC_CID_P_FRAME_QP (VICODEC_CID_CUSTOM_BASE + 1) +#define VICODEC_CID_STATELESS_FWHT (VICODEC_CID_CUSTOM_BASE + 2) + static unsigned stream_count; static unsigned stream_skip; static __u32 memory = V4L2_MEMORY_MMAP; @@ -80,6 +87,16 @@ static bool support_cap_compose; static bool support_out_crop; static bool in_source_change_event; +static __u64 last_fwht_bf_ts; + +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 +437,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 +772,104 @@ 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 void read_fwht_frame(cv4l_fmt &fmt, unsigned char *buf, + FILE *fpointer, unsigned &sz, + unsigned &len) +{ + struct fwht_cframe_hdr *h = (struct fwht_cframe_hdr *)buf; + + len = sizeof(struct fwht_cframe_hdr); + sz = fread(buf, 1, sizeof(struct fwht_cframe_hdr), fpointer); + if (sz < sizeof(struct fwht_cframe_hdr)) + return; + + len += ntohl(h->size); + sz += fread(buf + sz, 1, ntohl(h->size), fpointer); +} + +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); + fwht_params.comp_frame_size = ntohl(hdr->size); + + if (!last_bf_ts) + fwht_params.flags |= FWHT_FL_I_FRAME; +} + +static void set_fwht_req_by_idx(unsigned idx, 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); + + fwht_reqs[idx].fd = req_fd; + 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 = VICODEC_CID_STATELESS_FWHT; + 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 void read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf, FILE *fpointer, unsigned &sz, unsigned &len, bool is_read) From patchwork Sun Feb 24 08:41:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10827765 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 966366C2 for ; Sun, 24 Feb 2019 08:41:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 861242B817 for ; Sun, 24 Feb 2019 08:41:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7A6C62B824; Sun, 24 Feb 2019 08:41:57 +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 B214A2B817 for ; Sun, 24 Feb 2019 08:41:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728149AbfBXIl4 (ORCPT ); Sun, 24 Feb 2019 03:41:56 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44047 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726459AbfBXIlz (ORCPT ); Sun, 24 Feb 2019 03:41:55 -0500 Received: by mail-wr1-f67.google.com with SMTP id w2so6612555wrt.11 for ; Sun, 24 Feb 2019 00:41:54 -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=Ga5/g3343M9bUseYVhoKeXA13d/ynfyPrcFECoXQMd0=; b=V3GVFFh5pcgKwV1XdokPId9rmkGbTpSY03+NcGGeWeIBz3/eseytIqKIs47HoF7t2I OUkjA4bEbyqsHZbDCicDDib4n/TR/WfByOmd4PPYKTM1Xdr4oHllMRb/MNORFKoANyTt 5MRkwWdgW0Q0aIBEitG+zh/z3WwbUskeEYMTRWuElwSChvBG3Bn91mMeowSlJFMscpMx M0OVhI97HZxuTySPCsafubXRtP33PEtO9llgHi3RaHwtqxjWHC3Ga7LbUewX0gnpQJAg ZR39/DXUKX4n4kK1VSrPodm3DqXKWSsOJ061ifJOic+PhSnGf+J2+k6daDpzAK+kISga MJPQ== 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=Ga5/g3343M9bUseYVhoKeXA13d/ynfyPrcFECoXQMd0=; b=eUgJw8P7yi7Kjq1ov8HZZAgIglQr5W8GqDySII4lo1TnflvQvaekmMidFyreRP2IE7 mrpnMTjVSguhNWkkaHm6SMIyfvhQlMcfKGg3ZhAmD5VvP1RigRjJAfv4u1cW/wwRwhaf zpkBropKiy1fFivWVq2WZU+fJ4j444sGl6Npd8VzzJBv3WGlcbhNQz1oD9kvHhZaJh/x C7w+9ORSNBGEH82NLzmQh3sAu6CAduQHgQ1KsKD1eEByU5g+dzxQOc+lVAl8NDVcUtAV jF2ka9p4NayRmHKK/SC+SNA24XTmP5FJtNEm2fl0bch7ZWZsNvVejdKf8HqgEo1kqYNl RguA== X-Gm-Message-State: AHQUAuaQKBpeVo7SvMnMS9DkJUQqgSm7Xfa3clBAkPHxLQtg3JsunLLv 2EQ0DM+7RrVghk7jjPA2SLlPoMe+9aQ= X-Google-Smtp-Source: AHgI3IYTzP6fasaVN9hKi1i1ZopWLZZvrC7ldItj/9jmjFr/40X2LOJ4L3GbgFwmeWumbG00PkuHKg== X-Received: by 2002:a5d:5111:: with SMTP id s17mr8516065wrt.183.1550997713598; Sun, 24 Feb 2019 00:41:53 -0800 (PST) Received: from ubuntu.home ([77.127.107.32]) by smtp.gmail.com with ESMTPSA id x24sm6837465wmi.5.2019.02.24.00.41.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 24 Feb 2019 00:41:53 -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 v3 8/8] v4l2-ctl: Add implementation for the stateless fwht decoder. Date: Sun, 24 Feb 2019 00:41:26 -0800 Message-Id: <20190224084126.19412-9-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190224084126.19412-1-dafna3@gmail.com> References: <20190224084126.19412-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 | 236 +++++++++++++++++++++++++- 1 file changed, 233 insertions(+), 3 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 82a93d4b..db6734e9 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -1063,8 +1063,9 @@ restart: return false; } } - - if (support_out_crop && v4l2_fwht_find_pixfmt(fmt.g_pixelformat())) + if (q.g_capabilities() & V4L2_BUF_CAP_SUPPORTS_REQUESTS) + read_fwht_frame(fmt, (unsigned char *)buf, fin, sz, len); + else 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); @@ -1091,6 +1092,21 @@ restart: return true; } +static bool split_fwht_frame(u8 *frame, struct fwht_cframe_hdr *hdr, unsigned max_len) +{ + unsigned int len; + bool ret = true; + + memcpy(hdr, frame, sizeof(struct fwht_cframe_hdr)); + len = ntohl(hdr->size); + if (len > max_len) { + len = max_len; + ret = false; + } + memmove(frame, frame + sizeof(struct fwht_cframe_hdr), len); + return ret; +} + static int do_setup_out_buffers(cv4l_fd &fd, cv4l_queue &q, FILE *fin, bool qbuf) { tpg_pixel_aspect aspect = TPG_PIXEL_ASPECT_SQUARE; @@ -1195,6 +1211,35 @@ 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; + struct fwht_cframe_hdr hdr; + + if (q.g_capabilities() & V4L2_BUF_CAP_SUPPORTS_REQUESTS) { + int media_fd = mi_get_media_fd(fd.g_fd()); + + if (!split_fwht_frame((u8 *)q.g_dataptr(buf.g_index(), 0), + &hdr, buf.g_length(0))) + fprintf(stderr, "%s: warning: size field in fwht header is larger than buf size\n", + __func__); + + if (media_fd < 0) { + fprintf(stderr, "%s: mi_get_media_fd failed\n", __func__); + return media_fd; + } + + if (q.alloc_req(media_fd, i)) { + fprintf(stderr, "%s: q.alloc_req failed\n", __func__); + return -1; + } + buf.s_request_fd(q.g_req_fd(i)); + buf.or_flags(V4L2_BUF_FLAG_REQUEST_FD); + + if (set_fwht_ext_ctrl(fd, &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)) @@ -1204,6 +1249,16 @@ static int do_setup_out_buffers(cv4l_fd &fd, cv4l_queue &q, FILE *fin, bool qbuf fprintf(stderr, ">"); fflush(stderr); } + if (q.g_capabilities() & V4L2_BUF_CAP_SUPPORTS_REQUESTS) { + set_fwht_req_by_idx(i, &hdr, q.g_req_fd(i), + last_fwht_bf_ts, get_ns_timestamp(buf)); + last_fwht_bf_ts = get_ns_timestamp(buf); + if (ioctl(q.g_req_fd(i), MEDIA_REQUEST_IOC_QUEUE) < 0) { + fprintf(stderr, "Unable to queue media request: %s\n", + strerror(errno)); + return -1; + } + } } if (qbuf) output_field = field; @@ -1442,12 +1497,48 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE *fin, cv4l_buffer *cap (u8 *)q.g_dataptr(buf.g_index(), j)); } + struct fwht_cframe_hdr hdr; + + if (q.g_capabilities() & V4L2_BUF_CAP_SUPPORTS_REQUESTS) { + 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 (!split_fwht_frame((u8 *)q.g_dataptr(buf.g_index(), 0), &hdr, buf.g_length(0))) + fprintf(stderr, "%s: warning: size field in fwht header is larger than buf size\n", + __func__); + + if (set_fwht_ext_ctrl(fd, &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 (q.g_capabilities() & V4L2_BUF_CAP_SUPPORTS_REQUESTS) { + if (!set_fwht_req_by_fd(&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) @@ -2236,6 +2327,140 @@ 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_fd *exp_fd_p) +{ + fps_timestamps fps_ts[2]; + unsigned count[2] = { 0, 0 }; + cv4l_fmt fmt[2]; + int fd_flags = fcntl(fd.g_fd(), F_GETFL); + + fd.g_fmt(fmt[OUT], out.g_type()); + fd.g_fmt(fmt[CAP], in.g_type()); + + 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 = out.g_req_fd(index); + 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[CAP]); + 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[CAP], 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); @@ -2272,7 +2497,12 @@ static void streaming_set_m2m(cv4l_fd &fd, cv4l_fd &exp_fd) if (out.export_bufs(&exp_fd, exp_fd.g_type())) return; } - stateful_m2m(fd, in, out, file[CAP], file[OUT], exp_fd_p); + if (out.reqbufs(&fd, 0)) + goto done; + if (out.g_capabilities() & V4L2_BUF_CAP_SUPPORTS_REQUESTS) + stateless_m2m(fd, in, out, file[CAP], file[OUT], exp_fd_p); + else + stateful_m2m(fd, in, out, file[CAP], file[OUT], exp_fd_p); done: if (options[OptStreamDmaBuf] || options[OptStreamOutDmaBuf]) exp_q.close_exported_fds();