From patchwork Sun Jan 20 11:15: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: 10772343 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 1878E91E for ; Sun, 20 Jan 2019 11:15:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05E3A2A745 for ; Sun, 20 Jan 2019 11:15:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE8F62A761; Sun, 20 Jan 2019 11:15:35 +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 EBF422A745 for ; Sun, 20 Jan 2019 11:15:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730493AbfATLPe (ORCPT ); Sun, 20 Jan 2019 06:15:34 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43694 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728894AbfATLPe (ORCPT ); Sun, 20 Jan 2019 06:15:34 -0500 Received: by mail-wr1-f67.google.com with SMTP id r10so20024212wrs.10 for ; Sun, 20 Jan 2019 03:15:31 -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=ijCwH6DqnatoJm1xHFsdAVtYROaAMTdNO3FcfPqQE4w=; b=DPUzKfcC6aTQJXy/Ks+FSy9jyaK5cc7QUFsppLkPf9TRbUUhMB8u4ihH+RzqF8vBRA qd/ik48zXjKUw2gxG1x/jSw5A1Z0uzQEeZ2IAUBXPxH5iNwTgvrOW9d0Lo30HjoFy+WZ miyoJOO6XZJx/jV35i/7s3zKxg4FgdUOR6dKENqQ69eIYAfOlgduiz3PIcEr9ZVcloVS c1kIKms6S8vzActePS7NUFEWDAEWTb86Z42aptvdXzzVtZepHTBoyTdxJaEUIQEZET84 yWC3gHfJS95PGcoH+oWHC+urDEg4dW9DQq/3W8rh0hC/+pu/j32++h9pF64a5q5zhAQ5 wDGw== 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=ijCwH6DqnatoJm1xHFsdAVtYROaAMTdNO3FcfPqQE4w=; b=lXUwJNExcVSkpRA47vMOvKrND2SFywGGOZ8jVowgburwzhiCZXW/QGdxiKB7+wjA/I XqOZfTvlO+DTaTxlH3sUQG+to0bZnQ+ze1ilVeSoavIaufxvlhaMfNYsGdeTUzCL4Pz0 VfaE6ZsfUrGGU+fdhBcB13oITxkmr06L2/CGpQS1eXUCot6SzwJKX4S/dOFfVxZkbAyA yv3fxdE44YyT4GHxFr16Wucz7T/f/6evaYG1HA5c8niQgkbxKcxK+YhSloNUBR6dEJdA oCKcHCOchJADrVIc7AaDj3f9V5FJfBZMFVGLbXObHpjflJiCZvJ3u4kUBaN0Tppw5s+G VYNw== X-Gm-Message-State: AJcUukcyd9ej+jUcRDc0fSiF7OYKeBIYcxOSF6v1iu3xSH59P3bRoPWD yzb2nOsLt0C4V8wbAcBopqLLLZnhyaY= X-Google-Smtp-Source: ALg8bN49cwChogxmwn6b4ySAzEyHwQwVznDGRo1qP/JODaf4NEIlXiEFjIPO4emH7f2ir5eOJwLNcg== X-Received: by 2002:adf:bb44:: with SMTP id x4mr24736781wrg.24.1547982930470; Sun, 20 Jan 2019 03:15:30 -0800 (PST) Received: from localhost.localdomain ([87.70.46.65]) by smtp.gmail.com with ESMTPSA id n11sm28281796wrw.60.2019.01.20.03.15.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Jan 2019 03:15: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 1/6] v4l2-ctl: Add support for crop and compose selection in streaming Date: Sun, 20 Jan 2019 03:15:15 -0800 Message-Id: <20190120111520.114305-2-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190120111520.114305-1-dafna3@gmail.com> References: <20190120111520.114305-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 Support crop and compose selection. If the driver supports crop/compose then the raw frame is arranged inside a padded buffer. Signed-off-by: Dafna Hirschfeld --- utils/common/codec-fwht.patch | 8 +- utils/common/v4l-stream.c | 14 +-- utils/common/v4l-stream.h | 6 +- utils/qvidcap/capture.cpp | 2 + utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 141 ++++++++++++++++++++++++-- 5 files changed, 150 insertions(+), 21 deletions(-) diff --git a/utils/common/codec-fwht.patch b/utils/common/codec-fwht.patch index 4d41225b..37ac4672 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-11-23 13:43:52.713731559 +0100 -+++ b/utils/common/codec-fwht.h 2018-11-23 13:47:55.484198283 +0100 -@@ -8,8 +8,24 @@ +--- 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 @@ #define CODEC_FWHT_H #include @@ -17,6 +17,8 @@ +#define GENMASK(h, l) \ + (((~0UL) - (1UL << (l)) + 1) & (~0UL >> ((8 * sizeof(long)) - 1 - (h)))) +#define pr_err(arg...) ++#define __round_mask(x, y) ((__typeof__(x))((y)-1)) ++#define round_up(x, y) ((((x)-1) | __round_mask(x, y))+1) + + +typedef __u32 u32; diff --git a/utils/common/v4l-stream.c b/utils/common/v4l-stream.c index 9f842e21..a1cabadb 100644 --- a/utils/common/v4l-stream.c +++ b/utils/common/v4l-stream.c @@ -171,25 +171,28 @@ unsigned rle_compress(__u8 *b, unsigned size, unsigned bpl) return (__u8 *)dst - b; } -struct codec_ctx *fwht_alloc(unsigned pixfmt, unsigned w, unsigned h, +struct codec_ctx *fwht_alloc(unsigned pixfmt, unsigned visible_width, unsigned visible_height, + unsigned coded_width, unsigned coded_height, unsigned field, unsigned colorspace, unsigned xfer_func, unsigned ycbcr_enc, unsigned quantization) { struct codec_ctx *ctx; const struct v4l2_fwht_pixfmt_info *info = v4l2_fwht_find_pixfmt(pixfmt); unsigned int chroma_div; - unsigned int size = w * h; + unsigned int size = coded_width * coded_height; // fwht expects macroblock alignment, check can be dropped once that // restriction is lifted. - if (!info || w % 8 || h % 8) + if (!info || coded_width % 8 || coded_height % 8) return NULL; ctx = malloc(sizeof(*ctx)); if (!ctx) return NULL; - ctx->state.width = w; - ctx->state.height = h; + ctx->state.coded_width = coded_width; + ctx->state.coded_height = coded_height; + ctx->state.visible_width = visible_width; + ctx->state.visible_height = visible_height; ctx->state.info = info; ctx->field = field; ctx->state.colorspace = colorspace; @@ -208,7 +211,6 @@ struct codec_ctx *fwht_alloc(unsigned pixfmt, unsigned w, unsigned h, free(ctx); return NULL; } - ctx->state.ref_frame.width = ctx->state.ref_frame.height = 0; ctx->state.ref_frame.cb = ctx->state.ref_frame.luma + size; ctx->state.ref_frame.cr = ctx->state.ref_frame.cb + size / chroma_div; ctx->state.ref_frame.alpha = ctx->state.ref_frame.cr + size / chroma_div; diff --git a/utils/common/v4l-stream.h b/utils/common/v4l-stream.h index c235150b..fe5dfe90 100644 --- a/utils/common/v4l-stream.h +++ b/utils/common/v4l-stream.h @@ -9,12 +9,13 @@ #define _V4L_STREAM_H_ #include -#include #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ +#include + /* Default port */ #define V4L_STREAM_PORT 8362 @@ -145,7 +146,8 @@ struct codec_ctx { unsigned rle_compress(__u8 *buf, unsigned size, unsigned bytesperline); void rle_decompress(__u8 *buf, unsigned size, unsigned rle_size, unsigned bytesperline); -struct codec_ctx *fwht_alloc(unsigned pixfmt, unsigned w, unsigned h, unsigned field, +struct codec_ctx *fwht_alloc(unsigned pixfmt, unsigned visible_width, unsigned visible_height, + unsigned coded_width, unsigned coded_height, unsigned field, unsigned colorspace, unsigned xfer_func, unsigned ycbcr_enc, unsigned quantization); void fwht_free(struct codec_ctx *ctx); diff --git a/utils/qvidcap/capture.cpp b/utils/qvidcap/capture.cpp index 8c11ac53..e04db6be 100644 --- a/utils/qvidcap/capture.cpp +++ b/utils/qvidcap/capture.cpp @@ -749,6 +749,7 @@ void CaptureWin::setModeSocket(int socket, int port) if (m_ctx) free(m_ctx); m_ctx = fwht_alloc(m_v4l_fmt.g_pixelformat(), m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), + m_v4l_fmt.g_width(), m_v4l_fmt.g_height(), m_v4l_fmt.g_field(), m_v4l_fmt.g_colorspace(), m_v4l_fmt.g_xfer_func(), m_v4l_fmt.g_ycbcr_enc(), m_v4l_fmt.g_quantization()); @@ -1114,6 +1115,7 @@ void CaptureWin::listenForNewConnection() if (m_ctx) free(m_ctx); m_ctx = fwht_alloc(fmt.g_pixelformat(), fmt.g_width(), fmt.g_height(), + fmt.g_width(), fmt.g_height(), fmt.g_field(), fmt.g_colorspace(), fmt.g_xfer_func(), fmt.g_ycbcr_enc(), fmt.g_quantization()); setPixelAspect(pixelaspect); diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 79e015ce..8a98b6bd 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -20,7 +20,6 @@ #include "v4l2-ctl.h" #include "v4l-stream.h" -#include "codec-fwht.h" extern "C" { #include "v4l2-tpg.h" @@ -73,6 +72,13 @@ static unsigned bpl_out[VIDEO_MAX_PLANES]; static bool last_buffer = false; static codec_ctx *ctx; +static unsigned int cropped_width; +static unsigned int cropped_height; +static unsigned int composed_width; +static unsigned int composed_height; +static bool support_cap_compose; +static bool support_out_crop; + #define TS_WINDOW 241 #define FILE_HDR_ID v4l2_fourcc('V', 'h', 'd', 'r') @@ -657,7 +663,60 @@ void streaming_cmd(int ch, char *optarg) } } -static bool fill_buffer_from_file(cv4l_queue &q, cv4l_buffer &b, FILE *fin) +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 = v4l2_fwht_find_pixfmt(fmt.g_pixelformat()); + unsigned coded_height = fmt.g_height(); + unsigned real_width; + unsigned real_height; + unsigned char *plane_p = buf; + unsigned char *row_p; + + if (is_read) { + real_width = cropped_width; + real_height = cropped_height; + } else { + real_width = composed_width; + real_height = composed_height; + } + + sz = 0; + len = real_width * real_height * vic_fmt->sizeimage_mult / vic_fmt->sizeimage_div; + + for (unsigned plane_idx = 0; plane_idx < vic_fmt->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; + + 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); + else + wsz = fwrite(row_p, 1, consume_sz, fpointer); + if (wsz == 0 && i == 0 && plane_idx == 0) + break; + if (wsz != consume_sz) { + fprintf(stderr, "padding: needed %u bytes, got %u\n", consume_sz, wsz); + return; + } + sz += wsz; + row_p += fmt.g_bytesperline() / stride_div; + } + plane_p += (fmt.g_bytesperline() / stride_div) * (coded_height / h_div); + if (sz == 0) + break; + } +} + +static bool fill_buffer_from_file(cv4l_fd &fd, cv4l_queue &q, cv4l_buffer &b, FILE *fin) { static bool first = true; static bool is_fwht = false; @@ -776,7 +835,9 @@ restart: void *buf = q.g_dataptr(b.g_index(), j); unsigned len = q.g_length(j); unsigned sz; + cv4l_fmt fmt; + fd.g_fmt(fmt, q.g_type()); if (from_with_hdr) { len = read_u32(fin); if (len > q.g_length(j)) { @@ -785,7 +846,12 @@ restart: return false; } } - sz = fread(buf, 1, len, fin); + + if (support_out_crop && v4l2_fwht_find_pixfmt(fmt.g_pixelformat())) + read_write_padded_frame(fmt, (unsigned char *)buf, fin, sz, len, true); + else + sz = fread(buf, 1, len, fin); + if (first && sz != len) { fprintf(stderr, "Insufficient data\n"); return false; @@ -908,7 +974,7 @@ static int do_setup_out_buffers(cv4l_fd &fd, cv4l_queue &q, FILE *fin, bool qbuf tpg_fillbuffer(&tpg, stream_out_std, j, (u8 *)q.g_dataptr(i, j)); } } - if (fin && !fill_buffer_from_file(q, buf, fin)) + if (fin && !fill_buffer_from_file(fd, q, buf, fin)) return -2; if (qbuf) { @@ -926,7 +992,7 @@ static int do_setup_out_buffers(cv4l_fd &fd, cv4l_queue &q, FILE *fin, bool qbuf return 0; } -static void write_buffer_to_file(cv4l_queue &q, cv4l_buffer &buf, FILE *fout) +static void write_buffer_to_file(cv4l_fd &fd, cv4l_queue &q, cv4l_buffer &buf, FILE *fout) { #ifndef NO_STREAM_TO unsigned comp_size[VIDEO_MAX_PLANES]; @@ -967,7 +1033,9 @@ static void write_buffer_to_file(cv4l_queue &q, cv4l_buffer &buf, FILE *fout) __u32 used = buf.g_bytesused(); unsigned offset = buf.g_data_offset(); unsigned sz; + cv4l_fmt fmt; + fd.g_fmt(fmt, q.g_type()); if (offset > used) { // Should never happen fprintf(stderr, "offset %d > used %d!\n", @@ -985,6 +1053,9 @@ static void write_buffer_to_file(cv4l_queue &q, cv4l_buffer &buf, FILE *fout) } if (host_fd_to >= 0) sz = fwrite(comp_ptr[j] + offset, 1, used, fout); + else if (support_cap_compose && v4l2_fwht_find_pixfmt(fmt.g_pixelformat())) + read_write_padded_frame(fmt, (u8 *)q.g_dataptr(buf.g_index(), j) + offset, + fout, sz, used, false); else sz = fwrite((u8 *)q.g_dataptr(buf.g_index(), j) + offset, 1, used, fout); @@ -1036,7 +1107,7 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, if (fout && (!stream_skip || ignore_count_skip) && buf.g_bytesused(0) && !(buf.g_flags() & V4L2_BUF_FLAG_ERROR)) - write_buffer_to_file(q, buf, fout); + write_buffer_to_file(fd, q, buf, fout); if (buf.g_flags() & V4L2_BUF_FLAG_KEYFRAME) ch = 'K'; @@ -1135,7 +1206,7 @@ static int do_handle_out(cv4l_fd &fd, cv4l_queue &q, FILE *fin, cv4l_buffer *cap output_field = V4L2_FIELD_TOP; } - if (fin && !fill_buffer_from_file(q, buf, fin)) + if (fin && !fill_buffer_from_file(fd, q, buf, fin)) return -2; if (!fin && stream_out_refresh) { @@ -1333,10 +1404,15 @@ recover: write_u32(fout, cfmt.g_bytesperline(i)); bpl_cap[i] = rle_calc_bpl(cfmt.g_bytesperline(i), cfmt.g_pixelformat()); } - if (!host_lossless) - ctx = fwht_alloc(cfmt.g_pixelformat(), cfmt.g_width(), cfmt.g_height(), + if (!host_lossless) { + unsigned visible_width = support_cap_compose ? composed_width : cfmt.g_width(); + unsigned visible_height = support_cap_compose ? composed_height : cfmt.g_height(); + + ctx = fwht_alloc(cfmt.g_pixelformat(), visible_width, visible_height, + cfmt.g_width(), cfmt.g_height(), cfmt.g_field(), cfmt.g_colorspace(), cfmt.g_xfer_func(), cfmt.g_ycbcr_enc(), cfmt.g_quantization()); + } fflush(fout); } #endif @@ -1560,7 +1636,11 @@ static void streaming_set_out(cv4l_fd &fd) cfmt.s_quantization(read_u32(fin)); cfmt.s_xfer_func(read_u32(fin)); cfmt.s_flags(read_u32(fin)); - ctx = fwht_alloc(cfmt.g_pixelformat(), cfmt.g_width(), cfmt.g_height(), + unsigned visible_width = support_out_crop ? cropped_width : cfmt.g_width(); + unsigned visible_height = support_out_crop ? cropped_height : cfmt.g_height(); + + ctx = fwht_alloc(cfmt.g_pixelformat(), visible_width, visible_height, + cfmt.g_width(), cfmt.g_height(), cfmt.g_field(), cfmt.g_colorspace(), cfmt.g_xfer_func(), cfmt.g_ycbcr_enc(), cfmt.g_quantization()); @@ -2029,6 +2109,44 @@ done: fclose(file[OUT]); } +static int get_cap_compose_rect(cv4l_fd &fd) +{ + v4l2_selection sel; + + memset(&sel, 0, sizeof(sel)); + sel.type = vidcap_buftype; + sel.target = V4L2_SEL_TGT_COMPOSE; + + if (fd.g_selection(sel) == 0) { + support_cap_compose = true; + composed_width = sel.r.width; + composed_height = sel.r.height; + return 0; + } + + support_cap_compose = false; + return 0; +} + +static int get_out_crop_rect(cv4l_fd &fd) +{ + v4l2_selection sel; + + memset(&sel, 0, sizeof(sel)); + sel.type = vidout_buftype; + sel.target = V4L2_SEL_TGT_CROP; + + if (fd.g_selection(sel) == 0) { + support_out_crop = true; + cropped_width = sel.r.width; + cropped_height = sel.r.height; + return 0; + } + + support_out_crop = false; + return 0; +} + void streaming_set(cv4l_fd &fd, cv4l_fd &out_fd) { cv4l_disable_trace dt(fd); @@ -2036,6 +2154,9 @@ void streaming_set(cv4l_fd &fd, cv4l_fd &out_fd) int do_cap = options[OptStreamMmap] + options[OptStreamUser] + options[OptStreamDmaBuf]; int do_out = options[OptStreamOutMmap] + options[OptStreamOutUser] + options[OptStreamOutDmaBuf]; + get_cap_compose_rect(fd); + get_out_crop_rect(fd); + if (out_fd.g_fd() < 0) { out_capabilities = capabilities; out_priv_magic = priv_magic; From patchwork Sun Jan 20 11:15: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: 10772341 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 E83D21390 for ; Sun, 20 Jan 2019 11:15:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D746E2A761 for ; Sun, 20 Jan 2019 11:15:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB3142A768; Sun, 20 Jan 2019 11:15:35 +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 66C3B2A761 for ; Sun, 20 Jan 2019 11:15:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730494AbfATLPe (ORCPT ); Sun, 20 Jan 2019 06:15:34 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:40969 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730485AbfATLPe (ORCPT ); Sun, 20 Jan 2019 06:15:34 -0500 Received: by mail-wr1-f67.google.com with SMTP id x10so20030391wrs.8 for ; Sun, 20 Jan 2019 03:15:32 -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=lhUt4MCSYBcoj9QkV5uD5hupkXsfjcJMHDwhcTO/SYE=; b=WKZYw9Ktz3EnbLHkOXRlZr445VxadwheeeaTvQiIL2m0TCFaBRhZR4dC5YxzAgXwbj Oh1W6+d/Sq0YpPRN1wh19ef27+FlGvBKKySqC0UinRH+DcesaE9+vgbzdhp3jz6dgY47 5hwFPArKbMgcc9xaj0LPrCc0vuHm3kwkrx97BchpS8wCyZgxSUFRyHy3VqR/U6hLqweO c+hip+wyWdXSPmL0gJ4fA1+TYUElxc2j20HYQ4FwrE4C0Lk0FhnXARou5guT2yOfAO4a qQ1GnjbWghS0I8f69bIVjFgUUIfK/OPrFf//OoL9rnJVKxdf3ntCl6NYHWTV89T2eIFu AuVw== 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=lhUt4MCSYBcoj9QkV5uD5hupkXsfjcJMHDwhcTO/SYE=; b=O2xP/uMuFK0Q7rFU0V1SK36MPNS0IrkLjV/IzkiszhFzVDuM9L1TXJGMKlbqXDJoET 5nafp+cT7V13lknTdkR1nk5sWn7v8o9v82SagybdsuWXNHxjfzxtuQKr72YWK6JpgDJo AuDdny+3LIfWxTF18dm4x9zOXTKZzzKf8mAGfkLqy50q7keI/dqaJXU+GIsXplE/MDqq YzQGmcY5tie62xaVZuK9FFp5+Ym1lnAzM3qBMx7khQob+CIikUTPy6usRlLxlbJ9IJ+S uypmLidm/nAI+CPatrnjnfDKDRVFa73AkxqOwV7K3RYhKEEReIrzVQQN7dI9Ct9Y0sSX BfCQ== X-Gm-Message-State: AJcUuke8LlNSt6mIMZMP+pH5tiXBIWKX7ib1ghwqujk69O7OzW8fLKK0 yD82Z8udh0Id+P8qk5K0LZcVMQ1sWmI= X-Google-Smtp-Source: ALg8bN5/zACBm53FgnpkDBqzvAzrdSksZX0J4gkoBUbDjFswBQJKwR6jS8R4VtFI9uPxMj06NwNH3A== X-Received: by 2002:a5d:49cd:: with SMTP id t13mr24185533wrs.144.1547982931795; Sun, 20 Jan 2019 03:15:31 -0800 (PST) Received: from localhost.localdomain ([87.70.46.65]) by smtp.gmail.com with ESMTPSA id n11sm28281796wrw.60.2019.01.20.03.15.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Jan 2019 03:15:31 -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/6] v4l2-ctl: Add function get_codec_type Date: Sun, 20 Jan 2019 03:15:16 -0800 Message-Id: <20190120111520.114305-3-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190120111520.114305-1-dafna3@gmail.com> References: <20190120111520.114305-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 function get_codec_type that returns the type of codec NOT_CODEC/ENCODER/DEOCDER. Move the functions get_cap_compose/crop_rect to the start of the file. Signed-off-by: Dafna Hirschfeld --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 126 ++++++++++++++++++-------- 1 file changed, 88 insertions(+), 38 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 8a98b6bd..3e81fdfc 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -82,6 +82,12 @@ static bool support_out_crop; #define TS_WINDOW 241 #define FILE_HDR_ID v4l2_fourcc('V', 'h', 'd', 'r') +enum codec_type { + NOT_CODEC, + ENCODER, + DECODER +}; + class fps_timestamps { private: unsigned idx; @@ -334,6 +340,88 @@ void streaming_usage(void) V4L_STREAM_PORT); } +static int get_codec_type(cv4l_fd &fd, enum codec_type &codec_type) +{ + struct v4l2_fmtdesc fmt_desc; + int num_cap_fmts = 0; + int num_compressed_cap_fmts = 0; + int num_out_fmts = 0; + int num_compressed_out_fmts = 0; + + codec_type = NOT_CODEC; + if (!fd.has_vid_m2m()) + return 0; + + if (fd.enum_fmt(fmt_desc, true, 0, V4L2_BUF_TYPE_VIDEO_CAPTURE)) + return -1; + + do { + if (fmt_desc.flags & V4L2_FMT_FLAG_COMPRESSED) + num_compressed_cap_fmts++; + num_cap_fmts++; + } while (!fd.enum_fmt(fmt_desc)); + + + if (fd.enum_fmt(fmt_desc, true, 0, V4L2_BUF_TYPE_VIDEO_OUTPUT)) + return -1; + + do { + if (fmt_desc.flags & V4L2_FMT_FLAG_COMPRESSED) + num_compressed_out_fmts++; + num_out_fmts++; + } while (!fd.enum_fmt(fmt_desc)); + + if (num_compressed_out_fmts == 0 && num_compressed_cap_fmts == num_cap_fmts) { + codec_type = ENCODER; + return 0; + } + + if (num_compressed_cap_fmts == 0 && num_compressed_out_fmts == num_out_fmts) { + codec_type = DECODER; + return 0; + } + + return 0; +} + +static int get_cap_compose_rect(cv4l_fd &fd) +{ + v4l2_selection sel; + + memset(&sel, 0, sizeof(sel)); + sel.type = vidcap_buftype; + sel.target = V4L2_SEL_TGT_COMPOSE; + + if (fd.g_selection(sel) == 0) { + support_cap_compose = true; + composed_width = sel.r.width; + composed_height = sel.r.height; + return 0; + } + + support_cap_compose = false; + return 0; +} + +static int get_out_crop_rect(cv4l_fd &fd) +{ + v4l2_selection sel; + + memset(&sel, 0, sizeof(sel)); + sel.type = vidout_buftype; + sel.target = V4L2_SEL_TGT_CROP; + + if (fd.g_selection(sel) == 0) { + support_out_crop = true; + cropped_width = sel.r.width; + cropped_height = sel.r.height; + return 0; + } + + support_out_crop = false; + return 0; +} + static void set_time_stamp(cv4l_buffer &buf) { if ((buf.g_flags() & V4L2_BUF_FLAG_TIMESTAMP_MASK) != V4L2_BUF_FLAG_TIMESTAMP_COPY) @@ -2109,44 +2197,6 @@ done: fclose(file[OUT]); } -static int get_cap_compose_rect(cv4l_fd &fd) -{ - v4l2_selection sel; - - memset(&sel, 0, sizeof(sel)); - sel.type = vidcap_buftype; - sel.target = V4L2_SEL_TGT_COMPOSE; - - if (fd.g_selection(sel) == 0) { - support_cap_compose = true; - composed_width = sel.r.width; - composed_height = sel.r.height; - return 0; - } - - support_cap_compose = false; - return 0; -} - -static int get_out_crop_rect(cv4l_fd &fd) -{ - v4l2_selection sel; - - memset(&sel, 0, sizeof(sel)); - sel.type = vidout_buftype; - sel.target = V4L2_SEL_TGT_CROP; - - if (fd.g_selection(sel) == 0) { - support_out_crop = true; - cropped_width = sel.r.width; - cropped_height = sel.r.height; - return 0; - } - - support_out_crop = false; - return 0; -} - void streaming_set(cv4l_fd &fd, cv4l_fd &out_fd) { cv4l_disable_trace dt(fd); From patchwork Sun Jan 20 11:15:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10772345 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 0850791E for ; Sun, 20 Jan 2019 11:15:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EC9E72A745 for ; Sun, 20 Jan 2019 11:15:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0ED22A763; Sun, 20 Jan 2019 11:15:36 +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 91C3A2A745 for ; Sun, 20 Jan 2019 11:15:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730496AbfATLPf (ORCPT ); Sun, 20 Jan 2019 06:15:35 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:46379 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730490AbfATLPf (ORCPT ); Sun, 20 Jan 2019 06:15:35 -0500 Received: by mail-wr1-f67.google.com with SMTP id l9so20003193wrt.13 for ; Sun, 20 Jan 2019 03:15:34 -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=o1d4iX6rbOMXHfqtnOjgesiwaMW6UYez6BTKR1fazd4=; b=IFgmdMEDXUoEAumLOthHtAwponONbStPXlIvjwaRDkkgkyAx+mHnhVCZErP92bz+K1 0S5g6CY+9NtH7AgDLxD2zSfN5VN/bMskveVMfBvoIyS3popb9Acwfajl5Dc51oad6ZT/ ANzqS+yyYJQLQa8h3PwNoGlFtXWtkl5vASPzIpbGtia1IImc4UTHcHAtMfHcU4G7rowu 3uVDgcn7sPyHRqHHcgB+8yFX5eypDwmgX0atsJSDUASj3XNNv6Ot+aAwCcMR++WuWCgA d6EeapORSwj0nocI9k6TVDr8J8zuQ3FYWtRdDYpI4QAxMRTXbik4n83abmgbuX+AlMUV wGxw== 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=o1d4iX6rbOMXHfqtnOjgesiwaMW6UYez6BTKR1fazd4=; b=fk6gVPZW06ncT4XTjqoU13ILtGZlq9w2TAFH+kGSKwSMIwao5LITlMaRTh/zuMG+tq uAnCa2H+K8xA05ixoockZt7D2F4vWlBJq8cjegv+hAxhZG2180imyzQET8c6r2h989qZ Y9BUDV91k27hteXamV8DNSjbuMPby6wXMacNB4Stq1DJz5LbxbIiWhOikVgVVEWLFuo/ O7Qm3EnyjXChvOuc8ZjnrH9eX9UMTYdV44dXtBtjCmQboXbPnpItqafT/P94DqQtKqXF KTDTvqKrVuC2lt11Cbp+HAWjNKStwFqkOpTMMQyr1rX6Uqm6TXeNl20ksdeb7RCz+Q86 q8vg== X-Gm-Message-State: AJcUukcDyjPU+V9TimjQk4RPN88teOT168AQNxNbyXF2l77YGGZv3LL4 PVP0qOfT45xOQ9GfPuommbFmW+ErtLM= X-Google-Smtp-Source: ALg8bN4Fl+is4uBrd62wyMgbGh8eX6qM1LABmnTrrRr5ff+CPEPRxpCAlpl+z0tTl2suERGfhXvKQw== X-Received: by 2002:adf:8342:: with SMTP id 60mr22329895wrd.212.1547982933105; Sun, 20 Jan 2019 03:15:33 -0800 (PST) Received: from localhost.localdomain ([87.70.46.65]) by smtp.gmail.com with ESMTPSA id n11sm28281796wrw.60.2019.01.20.03.15.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Jan 2019 03:15:32 -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/6] v4l2-ctl: test the excpetion fds first in streaming_set_m2m Date: Sun, 20 Jan 2019 03:15:17 -0800 Message-Id: <20190120111520.114305-4-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190120111520.114305-1-dafna3@gmail.com> References: <20190120111520.114305-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 test the excpetion fds first in the select loop in streaming_set_m2m. This is needed in the next patch in order to dequeue a source change event before its coresponding last buffer. Signed-off-by: Dafna Hirschfeld --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 3e81fdfc..fc204304 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -1953,6 +1953,19 @@ static void streaming_set_m2m(cv4l_fd &fd) goto done; } + if (ex_fds && FD_ISSET(fd.g_fd(), ex_fds)) { + struct v4l2_event ev; + + while (!fd.dqevent(ev)) { + if (ev.type != V4L2_EVENT_EOS) + continue; + wr_fds = NULL; + fprintf(stderr, "EOS"); + fflush(stderr); + break; + } + } + if (rd_fds && FD_ISSET(fd.g_fd(), rd_fds)) { r = do_handle_cap(fd, in, file[CAP], NULL, count[CAP], fps_ts[CAP]); @@ -1990,19 +2003,6 @@ static void streaming_set_m2m(cv4l_fd &fd) } } } - - if (ex_fds && FD_ISSET(fd.g_fd(), ex_fds)) { - struct v4l2_event ev; - - while (!fd.dqevent(ev)) { - if (ev.type != V4L2_EVENT_EOS) - continue; - wr_fds = NULL; - fprintf(stderr, "EOS"); - fflush(stderr); - break; - } - } } fcntl(fd.g_fd(), F_SETFL, fd_flags); From patchwork Sun Jan 20 11:15:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dafna Hirschfeld X-Patchwork-Id: 10772347 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 1399591E for ; Sun, 20 Jan 2019 11:15:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 03B122A745 for ; Sun, 20 Jan 2019 11:15:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC1682A763; Sun, 20 Jan 2019 11:15:38 +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 CC4232A745 for ; Sun, 20 Jan 2019 11:15:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730490AbfATLPh (ORCPT ); Sun, 20 Jan 2019 06:15:37 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35067 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730485AbfATLPg (ORCPT ); Sun, 20 Jan 2019 06:15:36 -0500 Received: by mail-wm1-f67.google.com with SMTP id t200so8309332wmt.0 for ; Sun, 20 Jan 2019 03:15:35 -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=ptJ/fu0UHGNXsc6HRQMlWyiyrSUIjEymX1Wci7NkwwQ=; b=lnB30w3hsrmMpg+eH83nypqmzf5S+Bjgr2/uzLQ3h0XO9P+flPDzig/lvMjs6H5etR 0SVeVw/jEgF++KEMnnv+NxM9mn7iX1aBSpyfpHCmqWeTffomS/fEOyCOdniKgFML8O1i DN8xWopCCCcBC2vAGR3dBr5MNkjC2HJSg+9Bza0R7w3nscD5t8LMydCyjhggxcXi5KW3 yQ18LMgYtvkfRl9xTaP1Hd6ef+mE1kbW36aZA6W+s4j5lRY1rx10FJ9p+aY2ifGmHx8v P4Szp5mJoaAWvKTXHBOox8CAczw9rLHhfwJfI8e/OMj27XB/HRWFsEEp16vEEMGqWPwY Gpfw== 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=ptJ/fu0UHGNXsc6HRQMlWyiyrSUIjEymX1Wci7NkwwQ=; b=a9YrbLwY4alktr6zfDqRA2EsLfN1Nh0XdJCKKhipVnGKcRjX5vtiMxIY5aXz82KkBR ggUaJzYIgwKZjgH625Gb0dTxA4TtNQQaeXb1PWk810JUXHfF8QOFluA3CSX8VuL0WtS7 42e9IR5OnyjXFmO81DPJhknMSssUbzc2o6rIB2vFaUBBZtggfXekHkvoN5lmVQP2Gnh8 lHgeBsSFbVBrwZCb0VEQ8HoElSwAVipPnOp9+O98JJpBbtIJTR2e6dSwaHw0Ap4VpebZ uKRntI8q9Ate9FaAObrP0CXtg/A+aRarPMOcsXMFkj8z0DcE+AdHMPvOv+BVKdd6pRwD q9vg== X-Gm-Message-State: AJcUuke5BU+HOK+/+AuzAf/5M5kyT7Lf9MKefp4xdbNPuM+u9TRgy6RW wPnB9mAheXeSUJtlS1C+UyTv8DJiKWI= X-Google-Smtp-Source: ALg8bN7dCiP6kIcpfj25mOJiM2+MuzbcEx9be2fa9c0WjOSBYim8jLM53HrlF7Zv/WTQDT0uUV9jiw== X-Received: by 2002:a1c:b70a:: with SMTP id h10mr20524495wmf.125.1547982934275; Sun, 20 Jan 2019 03:15:34 -0800 (PST) Received: from localhost.localdomain ([87.70.46.65]) by smtp.gmail.com with ESMTPSA id n11sm28281796wrw.60.2019.01.20.03.15.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Jan 2019 03:15:33 -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/6] v4l2-ctl: Introduce capture_setup Date: Sun, 20 Jan 2019 03:15:18 -0800 Message-Id: <20190120111520.114305-5-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190120111520.114305-1-dafna3@gmail.com> References: <20190120111520.114305-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 function capture_setup that implements the capture setup sequence. Signed-off-by: Dafna Hirschfeld --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 58 +++++++++++++++++++++++---- 1 file changed, 50 insertions(+), 8 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index fc204304..cd20dec7 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -1836,6 +1836,48 @@ enum stream_type { OUT, }; +static int capture_setup(cv4l_fd &fd, cv4l_queue &in) +{ + struct v4l2_fmtdesc fmt_desc; + cv4l_fmt fmt; + + if (fd.streamoff(in.g_type())) { + fprintf(stderr, "%s: fd.streamoff error\n", __func__); + return -1; + } + get_cap_compose_rect(fd); + + /* release any buffer allocated */ + if (in.reqbufs(&fd)) { + fprintf(stderr, "%s: in.reqbufs 0 error\n", __func__); + return -1; + } + + if (fd.enum_fmt(fmt_desc, true, 0, in.g_type())) { + fprintf(stderr, "%s: fd.enum_fmt error\n", __func__); + return -1; + } + + fd.g_fmt(fmt, in.g_type()); + fmt.s_pixelformat(fmt_desc.pixelformat); + fd.s_fmt(fmt, in.g_type()); + + if (in.reqbufs(&fd, reqbufs_count_cap)) { + fprintf(stderr, "%s: in.reqbufs %u error\n", __func__, + reqbufs_count_cap); + return -1; + } + if (in.obtain_bufs(&fd) || in.queue_all(&fd)) { + fprintf(stderr, "%s: in.obtain_bufs error\n", __func__); + return -1; + } + if (fd.streamon(in.g_type())) { + fprintf(stderr, "%s: fd.streamon error\n", __func__); + return -1; + } + return 0; +} + static void streaming_set_m2m(cv4l_fd &fd) { int fd_flags = fcntl(fd.g_fd(), F_GETFL); @@ -1900,21 +1942,21 @@ static void streaming_set_m2m(cv4l_fd &fd) } } - if (in.reqbufs(&fd, reqbufs_count_cap) || - out.reqbufs(&fd, reqbufs_count_out)) + if (out.reqbufs(&fd, reqbufs_count_out)) goto done; - if (in.obtain_bufs(&fd) || - in.queue_all(&fd) || - do_setup_out_buffers(fd, out, file[OUT], true)) + if (do_setup_out_buffers(fd, out, file[OUT], true)) goto done; - fps_ts[CAP].determine_field(fd.g_fd(), in.g_type()); - fps_ts[OUT].determine_field(fd.g_fd(), out.g_type()); + if (fd.streamon(out.g_type())) + goto done; - if (fd.streamon(in.g_type()) || fd.streamon(out.g_type())) + if (capture_setup(fd, in)) goto done; + fps_ts[CAP].determine_field(fd.g_fd(), in.g_type()); + fps_ts[OUT].determine_field(fd.g_fd(), out.g_type()); + while (stream_sleep == 0) sleep(100); From patchwork Sun Jan 20 11:15: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: 10772349 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 D9EA691E for ; Sun, 20 Jan 2019 11:15:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C96AB2A745 for ; Sun, 20 Jan 2019 11:15:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD84D2A763; Sun, 20 Jan 2019 11:15:39 +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 4418B2A745 for ; Sun, 20 Jan 2019 11:15:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730508AbfATLPi (ORCPT ); Sun, 20 Jan 2019 06:15:38 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:37199 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730458AbfATLPi (ORCPT ); Sun, 20 Jan 2019 06:15:38 -0500 Received: by mail-wm1-f66.google.com with SMTP id g67so8242351wmd.2 for ; Sun, 20 Jan 2019 03:15:36 -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=EtonKIt+3G0rODzQaQI97BdBzvKU5a7Lt9SBpSYGRuw=; b=P6HmigClfBnzqVVRja4PEYHcWJ5x17ZhaINZfapm8JFNMCSk8EGw8q0S+rKBfdud+L L0AVpyOa9QaB+L/J+TU96X6vBAasBaa1RPu/Tfp0VPXC3elsWquF6bSCdbxXWPVHeNBC P/jv1Ib7E85zRydYZ4knEWQDtw+3K3TA6bylYjlExiVxsWyT1pI1OtSKnU7OLA5RSroX SmOz4LZwLXMrzxniNdVyXJy7v32J8XFTkphbo+WzkCPXngzCPkuE9PT09/6DEBdVd7Xa suKMCnjyxYZDwgto5zQkdb/k8QgGT069Cwlwqq5BwGJDMpk4AR3H/ObVdHeAGSy73uoX 9MeA== 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=EtonKIt+3G0rODzQaQI97BdBzvKU5a7Lt9SBpSYGRuw=; b=qyoICF1XdrKVIOeftJ06I1hFZJzCTJq6rwc148YOPKA8mp5sBLfNFW2geA/IaOM0PL a2sLLlbeZVCdCEiLzNQn+f7L+pSFgGlaV1wcjLsKVhfr3Y07XZpTYmfDJO2+rCsZLWJT Ec6ilbbIIC9ToYbzqGeDpWq7d2Z+K+UkiQQFADDvrYZYP69EUAk3Ood+hra70f03OhLt Lv+lXmrzjec3ZFLTQeY1Lymd3PUgRHzITgYEKPMF8AJt/yL5Y5l8pt62TV9LJngIQX/+ WKljUBvdF3L1VeArtqMXo/3SXcelCmVYVmXieytyESoVjN9bKqcJKqtWZYw+OFMKTFxN HvqA== X-Gm-Message-State: AJcUuke3ggboWXdBQE9LD5U4GvTlnapsQs2evmOC1iHPAsm6ByHfUYRu B+par/QLTiIu6dcx2ECb7DYVrEeZWmY= X-Google-Smtp-Source: ALg8bN4WVQm0PRyaD8XWf8dkZDSxchj4kSebbhpXBpYrQwnhb8OTia0mOCWtqjUbGWZAcWB2B5AHPw== X-Received: by 2002:a1c:bc82:: with SMTP id m124mr20904936wmf.77.1547982935550; Sun, 20 Jan 2019 03:15:35 -0800 (PST) Received: from localhost.localdomain ([87.70.46.65]) by smtp.gmail.com with ESMTPSA id n11sm28281796wrw.60.2019.01.20.03.15.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Jan 2019 03:15:35 -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 5/6] v4l2-ctl: Add support for source change event for m2m decoder Date: Sun, 20 Jan 2019 03:15:19 -0800 Message-Id: <20190120111520.114305-6-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190120111520.114305-1-dafna3@gmail.com> References: <20190120111520.114305-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 Subscribe to source change event. The capture setup sequence is executed only due to a change event. Signed-off-by: Dafna Hirschfeld --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 90 ++++++++++++++++++++++----- 1 file changed, 76 insertions(+), 14 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index cd20dec7..61dd84db 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -78,6 +78,7 @@ static unsigned int composed_width; static unsigned int composed_height; static bool support_cap_compose; static bool support_out_crop; +static bool in_source_change_event; #define TS_WINDOW 241 #define FILE_HDR_ID v4l2_fourcc('V', 'h', 'd', 'r') @@ -755,8 +756,11 @@ 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 = v4l2_fwht_find_pixfmt(fmt.g_pixelformat()); - unsigned coded_height = fmt.g_height(); + const struct v4l2_fwht_pixfmt_info *vic_fmt; + const static struct v4l2_fwht_pixfmt_info *old_info = + v4l2_fwht_find_pixfmt(fmt.g_pixelformat()); + static cv4l_fmt old_fmt = fmt; + unsigned coded_height; unsigned real_width; unsigned real_height; unsigned char *plane_p = buf; @@ -770,6 +774,21 @@ static void read_write_padded_frame(cv4l_fmt &fmt, unsigned char *buf, real_height = composed_height; } + /* + * if the source change event was dequeued but the stream was not yet + * restarted then the current buffers still fit the old resolution so + * we need to save it + */ + if (in_source_change_event) { + vic_fmt = old_info; + fmt = old_fmt; + } else { + vic_fmt = v4l2_fwht_find_pixfmt(fmt.g_pixelformat()); + old_info = vic_fmt; + old_fmt = fmt; + } + + coded_height = fmt.g_height(); sz = 0; len = real_width * real_height * vic_fmt->sizeimage_mult / vic_fmt->sizeimage_div; @@ -1208,8 +1227,18 @@ static int do_handle_cap(cv4l_fd &fd, cv4l_queue &q, FILE *fout, int *index, host_fd_to >= 0 ? 100 - comp_perc / comp_perc_count : -1); comp_perc_count = comp_perc = 0; } - if (!last_buffer && index == NULL && fd.qbuf(buf)) - return -1; + if (!last_buffer && index == NULL) { + /* + * EINVAL in qbuf can happen if this is the last buffer before + * a dynamic resolution change sequence. In this case the buffer + * has the size that fits the old resolution and might not + * fit to the new one. + */ + if (fd.qbuf(buf) && errno != EINVAL) { + fprintf(stderr, "%s: qbuf error\n", __func__); + return -1; + } + } if (index) *index = buf.g_index(); @@ -1890,6 +1919,7 @@ static void streaming_set_m2m(cv4l_fd &fd) fd_set *rd_fds = &fds[0]; /* for capture */ fd_set *ex_fds = &fds[1]; /* for capture */ fd_set *wr_fds = &fds[2]; /* for output */ + bool cap_streaming = false; if (!fd.has_vid_m2m()) { fprintf(stderr, "unsupported m2m stream type\n"); @@ -1920,6 +1950,11 @@ static void streaming_set_m2m(cv4l_fd &fd) is_encoder = !fmt.g_bytesperline(); } + memset(&sub, 0, sizeof(sub)); + sub.type = V4L2_EVENT_SOURCE_CHANGE; + if (fd.subscribe_event(sub)) + goto done; + if (file_to) { if (!strcmp(file_to, "-")) file[CAP] = stdout; @@ -1941,6 +1976,10 @@ static void streaming_set_m2m(cv4l_fd &fd) return; } } + enum codec_type codec_type; + + if (get_codec_type(fd, codec_type)) + goto done; if (out.reqbufs(&fd, reqbufs_count_out)) goto done; @@ -1951,8 +1990,9 @@ static void streaming_set_m2m(cv4l_fd &fd) if (fd.streamon(out.g_type())) goto done; - if (capture_setup(fd, in)) - goto done; + if (codec_type != DECODER) + if (capture_setup(fd, in)) + goto done; fps_ts[CAP].determine_field(fd.g_fd(), in.g_type()); fps_ts[OUT].determine_field(fd.g_fd(), out.g_type()); @@ -1999,12 +2039,25 @@ static void streaming_set_m2m(cv4l_fd &fd) struct v4l2_event ev; while (!fd.dqevent(ev)) { - if (ev.type != V4L2_EVENT_EOS) - continue; - wr_fds = NULL; - fprintf(stderr, "EOS"); - fflush(stderr); - break; + if (ev.type == V4L2_EVENT_EOS) { + wr_fds = NULL; + fprintf(stderr, "EOS"); + fflush(stderr); + } else if (ev.type == V4L2_EVENT_SOURCE_CHANGE) { + fprintf(stderr, "SOURCE CHANGE\n"); + + /* + * if capture is already streaming, + * wait to the a capture buffer with + * LAST_BUFFER flag + */ + if (cap_streaming) { + in_source_change_event = true; + continue; + } + if (capture_setup(fd, in)) + goto done; + } } } @@ -2018,8 +2071,17 @@ static void streaming_set_m2m(cv4l_fd &fd) break; } } - if (last_buffer) - break; + if (last_buffer) { + if (in_source_change_event) { + in_source_change_event = false; + last_buffer = false; + if (capture_setup(fd, in)) + goto done; + cap_streaming = true; + } else { + break; + } + } } if (wr_fds && FD_ISSET(fd.g_fd(), wr_fds)) { From patchwork Sun Jan 20 11:15: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: 10772351 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 497DE91E for ; Sun, 20 Jan 2019 11:15:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 392742A745 for ; Sun, 20 Jan 2019 11:15:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2DB822A763; Sun, 20 Jan 2019 11:15:41 +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 A11E32A745 for ; Sun, 20 Jan 2019 11:15:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730473AbfATLPk (ORCPT ); Sun, 20 Jan 2019 06:15:40 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:52084 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730485AbfATLPj (ORCPT ); Sun, 20 Jan 2019 06:15:39 -0500 Received: by mail-wm1-f66.google.com with SMTP id b11so8294240wmj.1 for ; Sun, 20 Jan 2019 03:15:37 -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=x4XFwEO8zi394fzsOH/mreWQHo+TLvhMV9apS6XZqTc=; b=VMa6rXNJ1/oWbCg2XxgVkEeMp8x11Biju4iZpBlnI1Q0H/SVY0hzA67WtWOj9Z2ZL6 O0Z36wLbNk4TiaALPaV7Mr6DGulNvqYHQIQ7mWspcqM0K2vZpv8V6gHuJZF4ElU1TW5o FtAOamFpeWkVQZ3KODlhmKUSU7EHBYObuPZ4Gt6e8lRAveZ16GayBXoHv4P2AncO/Jio ML215BtAbOxxJYV+C3yWdyH+p9CdgnLf0+G6hcSV1XAk+NMUScDm8Oku/PHAKZs0PGKY egDjN9V/UduwzMUhR+5wrKJe55ZkSTnJ5itfZFO27yTb2HMYwJ/KNYQOwwrJGJjgc3+q Pg7g== 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=x4XFwEO8zi394fzsOH/mreWQHo+TLvhMV9apS6XZqTc=; b=ORX5T7qCLxGKj7HmEhuuTjx4bSFZbVRyNw7OGpU5S8+xOpbL6j7uhCKLN6sZ+g81BX xn3Ik/RXGYuvHMwD3j1lqACuZ4M4+0E9U8HQSPPHQswxrv4c1SBj1W4JvAjNuYzU263O 4OzW1nUF7xhb+5RZ1M4hDc2chjL/1QuIOxK0fJAI+NLR/nDNdNwF8FRdROTvfeKPoT/G qcgzgJV/7RwPW0/rgxnLaLyzsSMXBnQSzdHLd4RxorHy+2PPA7VAdaThBjH90QZrdb4S TECdQenIbeu6UIzgZ1sajnyYrRoIgx2kErpHy6S6sI+KjusVYkfsRE7OM3ZrfHO9YIkq 1vEg== X-Gm-Message-State: AJcUukfmtg6bNvdg3fyJfcsEX0yufLarr7+Q/EurRJyYc1e49h8YyDkr e1um7UVdwL/Dghk7AjRFXTclJnVEVrk= X-Google-Smtp-Source: ALg8bN73vT4yOC9Hpt0GQqHlco6zkkBNZxEaQNNDnrvsfa664uPAOiLro49cpRw6coVPmKm4672SKA== X-Received: by 2002:a1c:1d8e:: with SMTP id d136mr11688101wmd.98.1547982936881; Sun, 20 Jan 2019 03:15:36 -0800 (PST) Received: from localhost.localdomain ([87.70.46.65]) by smtp.gmail.com with ESMTPSA id n11sm28281796wrw.60.2019.01.20.03.15.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 20 Jan 2019 03:15:36 -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 6/6] v4l2-ctl: Add --stream-pixformat option Date: Sun, 20 Jan 2019 03:15:20 -0800 Message-Id: <20190120111520.114305-7-dafna3@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190120111520.114305-1-dafna3@gmail.com> References: <20190120111520.114305-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 option sets the capture pixelformat in the capture setup sequence. If the format is not supported decoding will stop. If the option is not given then the default is to set the first supported format. Signed-off-by: Dafna Hirschfeld --- utils/v4l2-ctl/v4l2-ctl-streaming.cpp | 29 +++++++++++++++++++- utils/v4l2-ctl/v4l2-ctl.cpp | 39 ++++++++++++++++++--------- utils/v4l2-ctl/v4l2-ctl.h | 2 ++ 3 files changed, 56 insertions(+), 14 deletions(-) diff --git a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp index 61dd84db..7ee472b1 100644 --- a/utils/v4l2-ctl/v4l2-ctl-streaming.cpp +++ b/utils/v4l2-ctl/v4l2-ctl-streaming.cpp @@ -78,6 +78,7 @@ static unsigned int composed_width; static unsigned int composed_height; static bool support_cap_compose; static bool support_out_crop; +static unsigned int cap_pixelformat; static bool in_source_change_event; #define TS_WINDOW 241 @@ -272,6 +273,10 @@ void streaming_usage(void) " --stream-from \n" " stream from this file. The default is to generate a pattern.\n" " If is '-', then the data is read from stdin.\n" + " --stream-pixformat \n" + " set the video pixelformat." + " is either the format index as reported by\n" + " --list-formats-out, or the fourcc value as a string.\n" " --stream-from-hdr stream from this file. Same as --stream-from, but each\n" " frame is prefixed by a header. Use for compressed data.\n" " --stream-from-host \n" @@ -609,8 +614,16 @@ void streaming_cmd(int ch, char *optarg) { unsigned i; int speed; + int r; switch (ch) { + case OptStreamPixformat: + r = parse_pixelfmt(optarg, cap_pixelformat); + if (r) { + streaming_usage(); + exit(1); + } + break; case OptStreamCount: stream_count = strtoul(optarg, 0L, 0); break; @@ -1869,6 +1882,7 @@ static int capture_setup(cv4l_fd &fd, cv4l_queue &in) { struct v4l2_fmtdesc fmt_desc; cv4l_fmt fmt; + unsigned int chosen_pixformat; if (fd.streamoff(in.g_type())) { fprintf(stderr, "%s: fd.streamoff error\n", __func__); @@ -1887,8 +1901,21 @@ static int capture_setup(cv4l_fd &fd, cv4l_queue &in) return -1; } + if (cap_pixelformat) { + do { + if (cap_pixelformat == fmt_desc.pixelformat) + break; + } while (!fd.enum_fmt(fmt_desc)); + + if (cap_pixelformat != fmt_desc.pixelformat) { + fprintf(stderr, "%s: format from user not supported\n", __func__); + return -1; + } + } + + chosen_pixformat = fmt_desc.pixelformat; fd.g_fmt(fmt, in.g_type()); - fmt.s_pixelformat(fmt_desc.pixelformat); + fmt.s_pixelformat(chosen_pixformat); fd.s_fmt(fmt, in.g_type()); if (in.reqbufs(&fd, reqbufs_count_cap)) { diff --git a/utils/v4l2-ctl/v4l2-ctl.cpp b/utils/v4l2-ctl/v4l2-ctl.cpp index 1783979d..2cbf519e 100644 --- a/utils/v4l2-ctl/v4l2-ctl.cpp +++ b/utils/v4l2-ctl/v4l2-ctl.cpp @@ -238,6 +238,7 @@ static struct option long_options[] = { {"list-buffers-sdr", no_argument, 0, OptListBuffersSdr}, {"list-buffers-sdr-out", no_argument, 0, OptListBuffersSdrOut}, {"list-buffers-meta", no_argument, 0, OptListBuffersMeta}, + {"stream-pixformat", required_argument, 0, OptStreamPixformat}, {"stream-count", required_argument, 0, OptStreamCount}, {"stream-skip", required_argument, 0, OptStreamSkip}, {"stream-loop", no_argument, 0, OptStreamLoop}, @@ -722,6 +723,30 @@ __u32 parse_quantization(const char *s) return V4L2_QUANTIZATION_DEFAULT; } +int parse_pixelfmt(char *value, __u32 &pixelformat) +{ + int fmts = 0; + bool be_pixfmt; + + if(!value) + return -EINVAL; + + be_pixfmt = strlen(value) == 7 && !memcmp(value + 4, "-BE", 3); + if (be_pixfmt) + value[4] = 0; + if (strlen(value) == 4) { + pixelformat = + v4l2_fourcc(value[0], value[1], + value[2], value[3]); + if (be_pixfmt) + pixelformat |= 1 << 31; + } else { + pixelformat = strtol(value, 0L, 0); + } + fmts |= FmtPixelFormat; + return 0; +} + int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &pixelformat, __u32 &field, __u32 &colorspace, __u32 &xfer_func, __u32 &ycbcr, __u32 &quantization, __u32 &flags, __u32 *bytesperline) @@ -729,7 +754,6 @@ int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &pixelformat, char *value, *subs; int fmts = 0; unsigned bpl_index = 0; - bool be_pixfmt; field = V4L2_FIELD_ANY; flags = 0; @@ -760,18 +784,7 @@ int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &pixelformat, fmts |= FmtHeight; break; case 2: - be_pixfmt = strlen(value) == 7 && !memcmp(value + 4, "-BE", 3); - if (be_pixfmt) - value[4] = 0; - if (strlen(value) == 4) { - pixelformat = - v4l2_fourcc(value[0], value[1], - value[2], value[3]); - if (be_pixfmt) - pixelformat |= 1 << 31; - } else { - pixelformat = strtol(value, 0L, 0); - } + parse_pixelfmt(value, pixelformat); fmts |= FmtPixelFormat; break; case 3: diff --git a/utils/v4l2-ctl/v4l2-ctl.h b/utils/v4l2-ctl/v4l2-ctl.h index 5a52a0a4..8eee5351 100644 --- a/utils/v4l2-ctl/v4l2-ctl.h +++ b/utils/v4l2-ctl/v4l2-ctl.h @@ -205,6 +205,7 @@ enum Option { OptListBuffersSdr, OptListBuffersSdrOut, OptListBuffersMeta, + OptStreamPixformat, OptStreamCount, OptStreamSkip, OptStreamLoop, @@ -299,6 +300,7 @@ __u32 parse_xfer_func(const char *s); __u32 parse_ycbcr(const char *s); __u32 parse_hsv(const char *s); __u32 parse_quantization(const char *s); +int parse_pixelfmt(char *value, __u32 &pixelformat); int parse_fmt(char *optarg, __u32 &width, __u32 &height, __u32 &pixelformat, __u32 &field, __u32 &colorspace, __u32 &xfer, __u32 &ycbcr, __u32 &quantization, __u32 &flags, __u32 *bytesperline);