From patchwork Sat Apr 12 13:23:57 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sakari Ailus X-Patchwork-Id: 3973061 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 59719BFF02 for ; Sat, 12 Apr 2014 13:24:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 82D2620274 for ; Sat, 12 Apr 2014 13:24:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A6B4D202A7 for ; Sat, 12 Apr 2014 13:24:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755125AbaDLNYt (ORCPT ); Sat, 12 Apr 2014 09:24:49 -0400 Received: from nblzone-211-213.nblnetworks.fi ([83.145.211.213]:50694 "EHLO hillosipuli.retiisi.org.uk" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754308AbaDLNYR (ORCPT ); Sat, 12 Apr 2014 09:24:17 -0400 Received: from masiina.localdomain (masiina.retiisi.org.uk [IPv6:2001:1bc8:102:7fc9::c0:2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by hillosipuli.retiisi.org.uk (Postfix) with ESMTPS id F32D8600A6; Sat, 12 Apr 2014 16:24:13 +0300 (EEST) Received: from masiina.localdomain (localhost [127.0.0.1]) by masiina.localdomain (8.14.4/8.14.4/Debian-4) with ESMTP id s3CDOFJB008426; Sat, 12 Apr 2014 16:24:15 +0300 Received: (from sakke@localhost) by masiina.localdomain (8.14.4/8.14.4/Submit) id s3CDOEN6008425; Sat, 12 Apr 2014 16:24:14 +0300 From: Sakari Ailus To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com Subject: [yavta PATCH v3 05/11] Provide -B option for setting the buffer type Date: Sat, 12 Apr 2014 16:23:57 +0300 Message-Id: <1397309043-8322-6-git-send-email-sakari.ailus@iki.fi> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1397309043-8322-1-git-send-email-sakari.ailus@iki.fi> References: <1397309043-8322-1-git-send-email-sakari.ailus@iki.fi> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-7.3 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Instead of guessing the buffer type, allow setting it explicitly. Signed-off-by: Sakari Ailus --- yavta.c | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/yavta.c b/yavta.c index 01f61d2..78ebf21 100644 --- a/yavta.c +++ b/yavta.c @@ -99,15 +99,34 @@ static bool video_is_output(struct device *dev) static struct { enum v4l2_buf_type type; + bool supported; const char *name; + const char *string; } buf_types[] = { - { V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, "Video capture mplanes", }, - { V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, "Video output", }, - { V4L2_BUF_TYPE_VIDEO_CAPTURE, "Video capture" }, - { V4L2_BUF_TYPE_VIDEO_OUTPUT, "Video output mplanes" }, - { V4L2_BUF_TYPE_VIDEO_OVERLAY, "Video overlay" }, + { V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE, 1, "Video capture mplanes", "capture-mplane", }, + { V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE, 1, "Video output", "output-mplane", }, + { V4L2_BUF_TYPE_VIDEO_CAPTURE, 1, "Video capture", "capture", }, + { V4L2_BUF_TYPE_VIDEO_OUTPUT, 1, "Video output mplanes", "output", }, + { V4L2_BUF_TYPE_VIDEO_OVERLAY, 0, "Video overlay", "overlay" }, }; +static int v4l2_buf_type_from_string(const char *str) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(buf_types); i++) { + if (!buf_types[i].supported) + continue; + + if (strcmp(buf_types[i].string, str)) + continue; + + return buf_types[i].type; + } + + return -1; +} + static const char *v4l2_buf_type_name(enum v4l2_buf_type type) { unsigned int i; @@ -1500,6 +1519,8 @@ static void usage(const char *argv0) { printf("Usage: %s [options] device\n", argv0); printf("Supported options:\n"); + printf("-B, --buffer-type Buffer type (\"capture\", \"output\",\n"); + printf(" \"capture-mplane\" or \"output-mplane\")\n"); printf("-c, --capture[=nframes] Capture frames\n"); printf("-C, --check-overrun Verify dequeued frames for buffer overrun\n"); printf("-d, --delay Delay (in ms) before requeuing buffers\n"); @@ -1541,6 +1562,7 @@ static void usage(const char *argv0) #define OPT_STRIDE 263 static struct option opts[] = { + {"buffer-type", 1, 0, 'B'}, {"capture", 2, 0, 'c'}, {"check-overrun", 0, 0, 'C'}, {"delay", 1, 0, 'd'}, @@ -1618,9 +1640,17 @@ int main(int argc, char *argv[]) video_init(&dev); opterr = 0; - while ((c = getopt_long(argc, argv, "c::Cd:f:F::hi:Iln:pq:r:R::s:t:uw:", opts, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "B:c::Cd:f:F::hi:Iln:pq:r:R::s:t:uw:", opts, NULL)) != -1) { switch (c) { + case 'B': + ret = v4l2_buf_type_from_string(optarg); + if (ret == -1) { + printf("Bad buffer type \"%s\"\n", optarg); + return 1; + } + video_set_buf_type(&dev, ret); + break; case 'c': do_capture = 1; if (optarg) @@ -1783,7 +1813,7 @@ int main(int argc, char *argv[]) if (ret < 0) return 1; - if (!video_is_buf_type_valid(&dev)) + if (!video_has_valid_buf_type(&dev)) video_set_buf_type(&dev, ret); dev.memtype = memtype;