From patchwork Wed Feb 27 07:07:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10831299 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 EC93A180E for ; Wed, 27 Feb 2019 07:08:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D81762C6F5 for ; Wed, 27 Feb 2019 07:08:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CCB592C6FC; Wed, 27 Feb 2019 07:08: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 74DA22C6F5 for ; Wed, 27 Feb 2019 07:08:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729248AbfB0HIL (ORCPT ); Wed, 27 Feb 2019 02:08:11 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:37306 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726889AbfB0HIL (ORCPT ); Wed, 27 Feb 2019 02:08:11 -0500 Received: by mail-wr1-f67.google.com with SMTP id w6so13366609wrs.4 for ; Tue, 26 Feb 2019 23:08:09 -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=EhlJr7NFBn5NYhw9sXk7y9gLsYE/N76oNdPaPzHoy7z7pd3uKJm2TbhKz0/X9f1x40 k9TnplimYW1ZG07LmBaDtSlxoYbp9e3eXwJvUuKN+3CIaA0mzr8Kp9ZFhkC7/G99Qa/X +JV70BNEYewtuYQNbsNS9+s8vAToaYluwz6qsuIrUET/iP2ANoO0ssMCunngXt0snLAL oRSHGzyN9+1q4JVuV1LZISKip+kBnA/JMZbJyWyvXyfDWR5fs7XZocV7s57hVifinIDB yhvgAlUDDgYWZEmuIDGhRTcbHJSca84ZEPMGysDFDndG8AT9/0n+1dKUxR6rL9mD5/1k ZnQQ== 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=gH87nWK1hE3Dv6PeIywvLlDFG5os0wvofI69Vaw3GLZgVbllfgw6uWrWsA2EB2xpjx FXPxKrPar+nR684dyl26TcjetHQaHbAUMVokUGs0+jkwZC6cX0Qm8yzwLIRO7opeXRTn yqiJv6SEEV/U8OUZo1vj1rGWFnyrOB7qXomyif6JXnPefdqlRArM1sBefKKDk9Ko49FS ez2kA4kyKFdJG7u99lkRKf7kLyH6x7LozphVP5wmcr2o8jc78043IFQ1a2TAbYvGvBtI q+5YOVHRNVlioSVDImEiWTO9Wtg+NuFSSi+2fs7ti8oFbNZgPvykZMarWu46kPqHS+ZV BqZA== X-Gm-Message-State: APjAAAVhOS5x7ZNqRrfYuxGBy7vDDgQenfwP/Qt8j6+Vjm7NYbs0SZu1 nbGFWZ3QtkOU+3BIPk+WBMx9Kthm8Lg= X-Google-Smtp-Source: APXvYqzTR+UGscSOcJ7iJw0T8qr4pZzA11UUs571i7uYU9HIrBXGqE6bb/7f82pBt81980gTxA3avw== X-Received: by 2002:adf:dd12:: with SMTP id a18mr1075156wrm.4.1551251288724; Tue, 26 Feb 2019 23:08:08 -0800 (PST) Received: from ubuntu.home ([77.127.107.32]) by smtp.gmail.com with ESMTPSA id i10sm41984852wrx.54.2019.02.26.23.08.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 23:08: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 1/3] v4l-utils: copy fwht-ctrls.h from kernel dir Date: Tue, 26 Feb 2019 23:07:55 -0800 Message-Id: <20190227070757.25092-2-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190227070757.25092-1-dafna3@gmail.com> References: <20190227070757.25092-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 Feb 27 07:07:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10831301 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 C6877180E for ; Wed, 27 Feb 2019 07:08:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1A9F2C6F5 for ; Wed, 27 Feb 2019 07:08:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9D1F42C6FC; Wed, 27 Feb 2019 07:08:16 +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 CD5D32C6F5 for ; Wed, 27 Feb 2019 07:08:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729514AbfB0HIO (ORCPT ); Wed, 27 Feb 2019 02:08:14 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:52816 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726889AbfB0HIO (ORCPT ); Wed, 27 Feb 2019 02:08:14 -0500 Received: by mail-wm1-f65.google.com with SMTP id m1so4701683wml.2 for ; Tue, 26 Feb 2019 23:08:12 -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=Mq/Yod24JfhKhxr6FkbFBOpWzvVCj70kIlU3Jk+e1uY=; b=cJy5pumUsrioez80HnxK2gu/+1FLTNWY4BQkAbBEyqybLaTcx0wdiUaBPvvW/ZQYFi f1q+J5l2xYoFggYq7fMnCOUGygalrTb3en6VuwXhyKqSz3oy/wMa9ZyoxBIBOtBnB0Rs 33v19MrnZ5XpKvtg2hyOTg7b3PKzhgCE3GUR4HwBixyN50ltnqVF++UIGOM0zmPSaqwV T78L1vGvl8MS2AwZpKHfNm662o/mr/pOusD+88OhlbfqqdQwB1KamZtb3Ip3+82Q9A84 HQ3M0dNNL+ardb378KCEqqTMKVFjC5qsexXZVmH2V2l/oTUN8QDPKQzmpXyRl2NDnMQ2 L2wg== 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=Mq/Yod24JfhKhxr6FkbFBOpWzvVCj70kIlU3Jk+e1uY=; b=JtkXbttZ2/xOFui7OUN5mV3b3WPkVXi7yVtCO8VGWa7tczio2KbJWtPlilia9E8JzZ 7kxV24gVLF1GVdCnipZIiZ+rD7cLwqFfjoA5IbOtrLBz8J5QA77mRwNo3TQX55TTxqn3 tuHudOzSgf8I3kDhj0E8vkEGH2YE9oTtXLJ14xVNYuqyX1TL2wWdKoHEfSdy3+8Fh8D0 UiDRzSWgdOtzZe4WTkXqhKDBNPnLlTUZD5VNBGAUHb/LKxj5Mphn9dMIyY4obfijvSq0 lPj0iG/FQNAaiHuVGtOoRHv3X3fUR+YPDCkbpOs6f3vCG4m2iZlDcgGArX0zLuJT4tsS qthg== X-Gm-Message-State: AHQUAuY5NH0pfGqakavB6DpHOOb+CN8rFnTWycwHSlgdK/7Izxgea9ou UqAd0g9CMpH0ve5OtEMdrQ4vd2yy12Y= X-Google-Smtp-Source: AHgI3IbWw1QhWijK4OqLkK4Mqnq6XMvR4aTtfrRBdKBF2lmOOybTuyrUVLuSDsAPI2wm/Pl9jgyLFA== X-Received: by 2002:a1c:7008:: with SMTP id l8mr1126787wmc.63.1551251290314; Tue, 26 Feb 2019 23:08:10 -0800 (PST) Received: from ubuntu.home ([77.127.107.32]) by smtp.gmail.com with ESMTPSA id i10sm41984852wrx.54.2019.02.26.23.08.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 23:08:09 -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/3] v4l2-ctl: Add functions and variables to support fwht stateless decoder Date: Tue, 26 Feb 2019 23:07:56 -0800 Message-Id: <20190227070757.25092-3-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190227070757.25092-1-dafna3@gmail.com> References: <20190227070757.25092-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 | 129 ++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index adfa6796..dd0eeef6 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,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 +433,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 +768,116 @@ 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); + + 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 void read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf, FILE *fpointer, unsigned &sz, unsigned &len, bool is_read) From patchwork Wed Feb 27 07:07:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10831303 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 3B5D71390 for ; Wed, 27 Feb 2019 07:08:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 26ED72C6F5 for ; Wed, 27 Feb 2019 07:08:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BD6C2C6FC; Wed, 27 Feb 2019 07:08:18 +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 5453D2C6F5 for ; Wed, 27 Feb 2019 07:08:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729345AbfB0HIQ (ORCPT ); Wed, 27 Feb 2019 02:08:16 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:40073 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729249AbfB0HIQ (ORCPT ); Wed, 27 Feb 2019 02:08:16 -0500 Received: by mail-wm1-f67.google.com with SMTP id g20so3742038wmh.5 for ; Tue, 26 Feb 2019 23:08:13 -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=79BFkcFv27OtlF2sUuZDgzTODs8MFobIVq+Gep5lC74=; b=j3wp0JhVjgX0ivZqCrR0WgFrCxjp1DW97/PsOwqaOFMCn8UK0GXLOwZjVCPGMpOcGz ZDUaVt4lStD/9soU0om+2f4PUSBQBogovSTvP3LwPe+4CtCQwYPeb2rMwbfbfYrrzXF6 jlYQourk4hgLmID2POttY8FrLxxZqZIE5yd5Un5AFnBpe5Fuf/NbVp3upsub/502yzLz 4BrI6QafSL4OaOKXTHxTltHvTBISFXa+YjDLxzujUWNqDw0oZqzCp78Uf026qh8pFVfn vpvjoXNjWzuBywwy4ZmqTxv0yML4i6oSbSfuyFpt18q+ZcKyYJGOjmxDrsT0oLHnUcw/ 1K8w== 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=79BFkcFv27OtlF2sUuZDgzTODs8MFobIVq+Gep5lC74=; b=m7ahtHtgO0Tq4xkerhweJ0B68vUE6pQLdehZ5o6SR91NIQknPUUv1ziPLvdA+qSSCH hIR/DzPnoZD9D6rKtrYhUMyZ89FdTu8PObZhoApmLX/NfXTpS/n29ytpn3dS00gtgAX8 y3HMH2MeqI6J8gIJk87RvtVPYx/5J1YyLpk6QSjVqI6kYiexSF9htBufTQvMstX+7V0m hnTDwQQX7F69OA1MTENcGT3osmqUZFpm4uyFlwTPFLZiT0FyEkBBz3WeDX4hw3Kzmtlu jl/5N9vwzPm25thD4GeAyCQLgZkm+601Z+p7rKgL/sQIy37v2PU40KmOqX53HD6g4mFx K1vg== X-Gm-Message-State: AHQUAuZEtXov1N78LarNZ4OlFvibI0NbKHBKc3sMVQwVJ6P3NI1KkzJr P413ABSMcKG9HLGOH0KaOa3h7qKNGG4= X-Google-Smtp-Source: AHgI3IbgNM4/uyscQpAoUnVqVEMCh/9A8BYr8pLCJtQf0bvg592SZUtlevxrfKXO6rvn/lb/0ekiGA== X-Received: by 2002:a1c:1fc8:: with SMTP id f191mr1149520wmf.110.1551251292611; Tue, 26 Feb 2019 23:08:12 -0800 (PST) Received: from ubuntu.home ([77.127.107.32]) by smtp.gmail.com with ESMTPSA id i10sm41984852wrx.54.2019.02.26.23.08.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Feb 2019 23:08:12 -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/3] v4l2-ctl: Add implementation for the stateless fwht decoder. Date: Tue, 26 Feb 2019 23:07:57 -0800 Message-Id: <20190227070757.25092-4-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190227070757.25092-1-dafna3@gmail.com> References: <20190227070757.25092-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 | 234 +++++++++++++++++++++++++- 1 file changed, 231 insertions(+), 3 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index dd0eeef6..e279b0b5 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -1071,8 +1071,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); @@ -1099,6 +1100,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; @@ -1203,6 +1219,33 @@ 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 (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, &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)) @@ -1212,6 +1255,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, + 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; @@ -1450,12 +1503,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) @@ -2244,6 +2333,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 =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[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); @@ -2280,7 +2503,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();