From patchwork Mon Feb 11 20:49:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10806789 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 92D8D13B5 for ; Mon, 11 Feb 2019 20:49:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 825D42A97C for ; Mon, 11 Feb 2019 20:49:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 769832AA26; Mon, 11 Feb 2019 20:49:30 +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 923C22A98B for ; Mon, 11 Feb 2019 20:49:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726852AbfBKUt2 (ORCPT ); Mon, 11 Feb 2019 15:49:28 -0500 Received: from mail-wm1-f50.google.com ([209.85.128.50]:50381 "EHLO mail-wm1-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726080AbfBKUt2 (ORCPT ); Mon, 11 Feb 2019 15:49:28 -0500 Received: by mail-wm1-f50.google.com with SMTP id x7so671086wmj.0 for ; Mon, 11 Feb 2019 12:49:26 -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=GBbQ/vkk1SAuZy9P+bDsHlaMw6sm4ht6Ti5xqOT37qs=; b=tBLuTxGbYADSs+PTGEPxb9u75gpAiGR0/dMchmnn03Y0niKEv/dGqYxtU2d81FYAcr yaEdkx76LPpwlGl/Bvxr8L9NgnJvyg4JXPBoaSh5buobO9/9QHGRnqD9K5xK8l967jii aN4EwPNQOnquV8yPfb3Dy9FOM1M4SMSwOA1c19jKEI2hFKC4B+fj/yGluB1mxcA9aHz9 QQukSh0yJK3iWg1Y2TZh3PlSqiJ3Y33Pu1LpChd5fVQA7Q6kTVKyBUyGEKIpHwyUSm2u bc6VcuvV3QDjCtSfROyGV3NEueKbHnkBb9724GVG36R1mJhSJDTBXSHvYLnK7R5qLoOW ZTNQ== 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=GBbQ/vkk1SAuZy9P+bDsHlaMw6sm4ht6Ti5xqOT37qs=; b=QgljG9ls2P2qRkNbNoQ9FAuChe1fqwNpD6XG3E3sKIKZ2vMmDqc903fTm0SFK21Byl j7qm++Y9ObBzVwYmyQpEJ/SIWx8cVoIql2/tbHCk3XlXyCXds0AhvZvMDeRbsTdOWtR8 eGyr5HFODczfCrAWzW1DXWnUyCBFNLg8+bLx11zVb4F5DNYcaUHGjMnrFLFb2HAQu4R/ hVvzHzGxfySRlA0/6+5i1hWBoaJKMFOqXgj4yfHzAnysjZfdQs/3I/W8I1zXKYlBolGx 9jurILJGPeQQxjGaLIQzPTnsEB/3L8l8H4HB1Mp6tGLfBbNEpznOUkdyRRz1N8N4q0Yy 5tnA== X-Gm-Message-State: AHQUAuZU7pOMwXbc3x4NmVu1bTtnWUyWHJ7vlgyWqU72KI0AlXN3KHtB 7TOac617Vc32ZDyNvG4xyav+nZFinYE= X-Google-Smtp-Source: AHgI3IZIQ0XZdJvDO+ojCeOAZlUMR+AT92ciMdAhBb7DmmLTRg2++Lymwzsy8zseyRtAotAbiWhvbQ== X-Received: by 2002:a7b:cc86:: with SMTP id p6mr117488wma.32.1549918165515; Mon, 11 Feb 2019 12:49:25 -0800 (PST) Received: from localhost.localdomain ([87.70.76.19]) by smtp.gmail.com with ESMTPSA id y139sm625778wmd.22.2019.02.11.12.49.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Feb 2019 12:49:24 -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 1/4] v4l2-ctl: move stateful m2m decode code to a separate function Date: Mon, 11 Feb 2019 12:49:13 -0800 Message-Id: <20190211204916.77001-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 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 766872b5..40ddc1c3 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -1933,16 +1933,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 */ @@ -1953,19 +1949,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)); @@ -1986,34 +1969,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)) - goto done; + if (do_setup_out_buffers(fd, out, fout, true)) + 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()); @@ -2049,15 +2016,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; @@ -2069,7 +2036,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; @@ -2120,7 +2087,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; @@ -2138,7 +2105,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 Mon Feb 11 20:49:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10806791 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 6F4E013A4 for ; Mon, 11 Feb 2019 20:49:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 60EE52A97C for ; Mon, 11 Feb 2019 20:49:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 550B52A98B; Mon, 11 Feb 2019 20:49:31 +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 1BF2B2A98D for ; Mon, 11 Feb 2019 20:49:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726864AbfBKUt3 (ORCPT ); Mon, 11 Feb 2019 15:49:29 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:37496 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726199AbfBKUt3 (ORCPT ); Mon, 11 Feb 2019 15:49:29 -0500 Received: by mail-wr1-f67.google.com with SMTP id c8so300748wrs.4 for ; Mon, 11 Feb 2019 12:49:27 -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=e4ooo9EgFAjEx7ZohL2HVkCQ0w2S6mPaaL1rAfR4vzFUjh88Ay76lE9DRWRpgya4HM 2AxVNTyOUfbxkK+ObkylARxOx1DatrRipcc125CR1QYoBPgO1QrO72iYplwp1O5vhwEF tGDQrbNY4lSUmLj9UoWlWTzA3rCz0WNBoWWKnNfto6OifjDF6E0MEaHTe7VHO5X8CkTG vi3ZENZTWYIf5tJNmb83i+liJXpwr+MHHeEWkkchOoYYim5C3ppy8oHjK7sHdIq0RsMM +Y/KRPA6LjkAacncxgR8OvpK9nFrS0EadqloGu0M6zDFmRq7W/jdu5f6r0XNhObKrzAn d82Q== 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=lAP1O2pyzM79ywF8iE7MtcDNqY7b0Ct5HsQDjJkn+KkmCVu8HNJAZ5yHVHfe7U0mfF 9YxkEgWIcqrrUm4FCoCriiMFeokjhYaPVwPFArcdYDGvBOXU2Sw7w0HAMycBIC6ngE/Q Js2zbBhLgWK1OFpxB8WoM1ZF7OyphQhDmct5pg0VQQm39LGvaZ982I9Y3Qsu1DwkBQY9 jv9QFeFNMoUfuEartkm0STqyA4o9fO76FPpvd6ks7v85gqCX8EP4FlM98U1+D/fHcuwu R1Tlo5HLAuePDZ9uOgEkawdVEVEbDvIaVI0mqEzpQXPcR5NstdKZtRVS2IFnlwZkROSm UqYg== X-Gm-Message-State: AHQUAuYxSGxGIFvmIiBeXUieSwF1gG+oIkWOarUIVyUdMW5InqvelyU9 ZCJp26oGVSi+cMhXv37ip60UMWkOc9w= X-Google-Smtp-Source: AHgI3IZXtninCJFcfah+RLjlLo4x54CelKJ8S7Q8kkBN20P/puxgveh419WeHGq9pv+FfgiGlLZmdg== X-Received: by 2002:a05:6000:1185:: with SMTP id g5mr62678wrx.299.1549918166909; Mon, 11 Feb 2019 12:49:26 -0800 (PST) Received: from localhost.localdomain ([87.70.76.19]) by smtp.gmail.com with ESMTPSA id y139sm625778wmd.22.2019.02.11.12.49.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Feb 2019 12:49:26 -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 2/4] (c)v4l-helpers.h: Add support for the request api Date: Mon, 11 Feb 2019 12:49:14 -0800 Message-Id: <20190211204916.77001-2-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190211204916.77001-1-dafna3@gmail.com> References: <20190211204916.77001-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 Mon Feb 11 20:49:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10806793 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 7799A13A4 for ; Mon, 11 Feb 2019 20:49:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 674862A97C for ; Mon, 11 Feb 2019 20:49:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5BA812A98D; Mon, 11 Feb 2019 20:49:32 +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 8E84C2A97C for ; Mon, 11 Feb 2019 20:49:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726866AbfBKUta (ORCPT ); Mon, 11 Feb 2019 15:49:30 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:43267 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726860AbfBKUta (ORCPT ); Mon, 11 Feb 2019 15:49:30 -0500 Received: by mail-wr1-f68.google.com with SMTP id r2so262600wrv.10 for ; Mon, 11 Feb 2019 12:49:29 -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=EHvvK3ARkJz9UTKh+0nTMN66N1/gSjr3pEoc7HzRvOs=; b=AvDRm/VsMsN24RsxMGUzhTgowI2JmCqm2JtLtA/xLoL8xrhp/icg11X0wf7yHH55rI nSbB+jMU9mhJGjapKAUTv/UpD9o/l3lzfS57KfuX66HdiC/O6jXtVXWIeaIs4ZBHn9x/ V6qb9jRxXftIPa9lZ8QUYO7OjaU7jek0+ulwPYtAcsyv0NGVwmzzFFMOI23HflzdIHso W6uqplCwo9V8AFOWvSRiXhOBxbKFl/6ur+ozRAr1wxRzMXTEfYQdNQy/oMc8QNOO6jER HwfKiHWf8mPz9wq5eJS8E//Z+mNsavObXjwiG6ZPeJcTh1S5TL5lECZUXb6dIGBHb2NQ jg5Q== 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=EHvvK3ARkJz9UTKh+0nTMN66N1/gSjr3pEoc7HzRvOs=; b=KuNtGMyU5Ofkd3Kdp7KAW2jzLq/N/BAIHx3loj9Ilz6ArVm326dd41B9h+CEIdxmt4 qOagaKXtpdIq/BzHpB+C4xqDN/EhCbx+oGjFAYhBFXUfIqwRK8Yfi7SWkaLcjRxUeg4/ 0aNwvGrFPNbwNAXlvOWry7qn0oh7Jjf/rwx17vh5fNSU72bO/jjLuTm/dP4ZnnBTXbzd CIUxPZz25AWnijQbgj1Axfu2/jEom+Fi7OUMg1vX3o0MBLM+TbE0YmGAUrpWZtSwwIcG Ue0dZaC8O1+BbjDbjWB9n3yOOiYhsbSKmPJaO9cDU7iffk0tccp5DWOits+ExqRHXUXR evCA== X-Gm-Message-State: AHQUAuYd+duAv9fByZtknSMIJ/64E9XWD7eTrzOliOa/gQ/iLoKibO7K 6bxU1FmUdJbDq8rdTf9zaNKOkaO9Qa0= X-Google-Smtp-Source: AHgI3IYdkdVOZZVwP7Wj9GqEeEgIfz1zEtSwN9lbwYGiBL7PYC2TJPFR//qBkiYylq16Zyj3UzQkGA== X-Received: by 2002:adf:9e0c:: with SMTP id u12mr103171wre.216.1549918168319; Mon, 11 Feb 2019 12:49:28 -0800 (PST) Received: from localhost.localdomain ([87.70.76.19]) by smtp.gmail.com with ESMTPSA id y139sm625778wmd.22.2019.02.11.12.49.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Feb 2019 12:49:27 -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 3/4] v4l2-ctl: Add functions and variables to support fwht stateless decoder Date: Mon, 11 Feb 2019 12:49:15 -0800 Message-Id: <20190211204916.77001-3-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190211204916.77001-1-dafna3@gmail.com> References: <20190211204916.77001-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 | 103 ++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 40ddc1c3..701e42ef 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -80,6 +80,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 +430,12 @@ static int get_out_crop_rect(cv4l_fd &fd) return 0; } +static __u64 get_ns_time_stamp(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 +765,93 @@ 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) +{ + len = sizeof(struct fwht_cframe_hdr); + sz = fread(buf, 1, sizeof(struct fwht_cframe_hdr), fpointer); + if (sz < sizeof(struct fwht_cframe_hdr)) + return; + + struct fwht_cframe_hdr *h = (struct fwht_cframe_hdr *)buf; + len += ntohl(h->size); + sz += fread(buf + sz, 1, ntohl(h->size), fpointer); +} + +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; + + memset(&fwht_params, 0, sizeof(fwht_params)); + fwht_params.backward_ref_ts = last_bf_ts; + fwht_params.width = ntohl(hdr->width); + fwht_params.height = ntohl(hdr->height); + + 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; + + memset(&fwht_params, 0, sizeof(fwht_params)); + fwht_params.backward_ref_ts = last_bf_ts; + fwht_params.width = ntohl(hdr->width); + fwht_params.height = ntohl(hdr->height); + + 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(&fwht_params, 0, sizeof(fwht_params)); + memset(&control, 0, sizeof(control)); + memset(&controls, 0, sizeof(controls)); + + fwht_params.backward_ref_ts = last_bf_ts; + fwht_params.width = ntohl(hdr->width); + fwht_params.height = ntohl(hdr->height); + + 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 Mon Feb 11 20:49:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10806795 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 A317313B5 for ; Mon, 11 Feb 2019 20:49:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90CF32A97C for ; Mon, 11 Feb 2019 20:49:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 851562A98D; Mon, 11 Feb 2019 20:49:40 +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 BCB502A97C for ; Mon, 11 Feb 2019 20:49:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727080AbfBKUti (ORCPT ); Mon, 11 Feb 2019 15:49:38 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:40323 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726883AbfBKUtd (ORCPT ); Mon, 11 Feb 2019 15:49:33 -0500 Received: by mail-wm1-f66.google.com with SMTP id q21so637780wmc.5 for ; Mon, 11 Feb 2019 12:49:30 -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=gPTd7nsb7mJAv5VF8QjEFNH5QZwxoivfetfKdc81SZ4=; b=YVRARo20wjqKkcRGeO+Fv/61jSHLNG07wvlOFkvor6oc9Ef2q/tJPkU0P5h22zW0Va tLSO6aD1hgKR4Ccaox3BYetjD+gfZKDwqYWZMVdLIMzIK4cV1uGqOtde8kWpbnJjU8Lt Kgkyr+JeTsGV+7FKMtuRhzXIMxX2MmMggQoiwX1xsgtIpLBlbBEye8B/A35BFnNUHEC+ uB8jpdqqFHbrFUhNoKpnE5Ozocd9Gk4uQKxSP6MKGiwO7hp9E7kFLQ/bSZjJM2/Hobve eHm3/jLBPo8nyDsKRPB6WEPFcihjZpMXicjAaWac/J4Cd2iYUTnjGhUcR/yJJC/khriW X4Wg== 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=gPTd7nsb7mJAv5VF8QjEFNH5QZwxoivfetfKdc81SZ4=; b=WHCxPnei94+GT4U6yDNeaEtIMzL5G5z9jHhwLxr/4s3xDKdPMJeYmpj99fVhXwccpX Pqnt3maMxwSF8K8/UQRJ8cQtsVoM6EiJqBd56CdyzDVYZrAulTJSbILXUmOSjC6lOVZV rwefdE7b0+kHWQQ18EhLvWvBeH0+DTk3pPeTiUA8E+vd5q/dX4EyQPX+NInJ6b18izOH ONHUeQLZAlv4aXzvSEFzV0FkS37lLsnIEt7Bjb5R0N7ylb7kSeLJ5I5Mexw8lEBI0iDs VgDIEoLe6RLyhnr3eWlOH8PxyU6JMjbGdHftWdNtsl4EsiGOV0tuc40L1ObuP4RbOHks Y9yA== X-Gm-Message-State: AHQUAuZdAFvtrL/42yeQosikZWf4jsj/B9EistUchne/28I/dTKTvMRy vTNGqZGLMfFGu1uTG5DodVNvUp4XexM= X-Google-Smtp-Source: AHgI3Ib+JQtWVnGtHf5Wc4DkHjj8+O3tMF2qyLZcdENKwPK+0dvFu+Z4mWOCb14L+u5JubbqzrRPTw== X-Received: by 2002:a1c:be0f:: with SMTP id o15mr118643wmf.34.1549918169688; Mon, 11 Feb 2019 12:49:29 -0800 (PST) Received: from localhost.localdomain ([87.70.76.19]) by smtp.gmail.com with ESMTPSA id y139sm625778wmd.22.2019.02.11.12.49.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Feb 2019 12:49:29 -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 4/4] v4l2-ctl: Add implementation for the stateless fwht decoder. Date: Mon, 11 Feb 2019 12:49:16 -0800 Message-Id: <20190211204916.77001-4-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190211204916.77001-1-dafna3@gmail.com> References: <20190211204916.77001-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 | 224 +++++++++++++++++++++++++- 1 file changed, 221 insertions(+), 3 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 701e42ef..84ffc105 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -20,11 +20,17 @@ #include "v4l2-ctl.h" #include "v4l-stream.h" +#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; @@ -1037,8 +1043,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); @@ -1169,6 +1176,30 @@ 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 (q.g_capabilities() & V4L2_BUF_CAP_SUPPORTS_REQUESTS) { + int media_fd = mi_get_media_fd(fd.g_fd()); + struct fwht_cframe_hdr *hdr = + (struct fwht_cframe_hdr *)q.g_dataptr(buf.g_index(), 0); + + 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)) @@ -1178,6 +1209,19 @@ 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) { + struct fwht_cframe_hdr *hdr = + (struct fwht_cframe_hdr *)q.g_dataptr(buf.g_index(), 0); + + set_fwht_req_by_idx(i, hdr, q.g_req_fd(i), + last_fwht_bf_ts, get_ns_time_stamp(buf)); + last_fwht_bf_ts = get_ns_time_stamp(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; @@ -1415,6 +1459,22 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE *fin, cv4l_buffer *cap tpg_fillbuffer(&tpg, stream_out_std, j, (u8 *)q.g_dataptr(buf.g_index(), j)); } + 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; + } + struct fwht_cframe_hdr *hdr = + (struct fwht_cframe_hdr *)q.g_dataptr(buf.g_index(), 0); + + 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); @@ -1422,6 +1482,25 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE *fin, cv4l_buffer *cap fprintf(stderr, "%s: failed: %s\n", "VIDIOC_QBUF", strerror(errno)); return -1; } + if (q.g_capabilities() & V4L2_BUF_CAP_SUPPORTS_REQUESTS) { + struct fwht_cframe_hdr *hdr = + (struct fwht_cframe_hdr *)q.g_dataptr(buf.g_index(), 0); + + if (!set_fwht_req_by_fd(hdr, buf.g_request_fd(), last_fwht_bf_ts, + get_ns_time_stamp(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_time_stamp(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) @@ -2210,6 +2289,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)) { + 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_time_stamp(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_time_stamp(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); @@ -2246,7 +2459,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();