2 * Media controller test application
4 * Copyright (C) 2010-2011 Ideas on board SPRL
6 * Contact: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published
10 * by the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
29 #define MEDIA_DEVNAME_DEFAULT "/dev/media0"
31 struct media_options media_opts = {
32 .devname = MEDIA_DEVNAME_DEFAULT,
35 static void usage(const char *argv0, int verbose)
37 printf("%s [options] device\n", argv0);
38 printf("-d, --device dev Media device name (default: %s)\n", MEDIA_DEVNAME_DEFAULT);
39 printf("-e, --entity name Print the device name associated with the given entity\n");
40 printf("-V, --set-v4l2 v4l2 Comma-separated list of formats to setup\n");
41 printf(" --get-v4l2 pad Print the active format on a given pad\n");
42 printf("-h, --help Show verbose help and exit\n");
43 printf("-i, --interactive Modify links interactively\n");
44 printf("-l, --links Comma-separated list of links descriptors to setup\n");
45 printf("-p, --print-topology Print the device topology\n");
46 printf(" --print-dot Print the device topology as a dot graph\n");
47 printf("-r, --reset Reset all links to inactive\n");
48 printf("-v, --verbose Be verbose\n");
54 printf("Links and formats are defined as\n");
55 printf("\tlink = pad '->' pad '[' flags ']' ;\n");
56 printf("\tpad = entity ':' pad-number ;\n");
57 printf("\tentity = entity-number | ( '\"' entity-name '\"' ) ;\n");
59 printf("\tv4l2 = pad '[' v4l2-properties ']' ;\n");
60 printf("\tv4l2-properties = v4l2-property { ',' v4l2-property } ;\n");
61 printf("\tv4l2-property = v4l2-mbusfmt | v4l2-crop | v4l2-interval\n");
62 printf("\t | v4l2-compose | v4l2-interval ;\n");
63 printf("\tv4l2-mbusfmt = 'fmt:' fcc '/' size ;\n");
64 printf("\tv4l2-crop = 'crop:' rectangle ;\n");
65 printf("\tv4l2-compose = 'compose:' rectangle ;\n");
66 printf("\tv4l2-interval = '@' numerator '/' denominator ;\n");
68 printf("\trectangle = '(' left ',' top, ')' '/' size ;\n");
69 printf("\tsize = width 'x' height ;\n");
71 printf("where the fields are\n");
72 printf("\tentity-number Entity numeric identifier\n");
73 printf("\tentity-name Entity name (string) \n");
74 printf("\tpad-number Pad numeric identifier\n");
75 printf("\tflags Link flags (0: inactive, 1: active)\n");
76 printf("\tfcc Format FourCC\n");
77 printf("\twidth Image width in pixels\n");
78 printf("\theight Image height in pixels\n");
79 printf("\tnumerator Frame interval numerator\n");
80 printf("\tdenominator Frame interval denominator\n");
83 #define OPT_PRINT_DOT 256
84 #define OPT_GET_FORMAT 257
86 static struct option opts[] = {
87 {"device", 1, 0, 'd'},
88 {"entity", 1, 0, 'e'},
89 {"set-format", 1, 0, 'f'},
90 {"set-v4l2", 1, 0, 'V'},
91 {"get-format", 1, 0, OPT_GET_FORMAT},
92 {"get-v4l2", 1, 0, OPT_GET_FORMAT},
94 {"interactive", 0, 0, 'i'},
96 {"print-dot", 0, 0, OPT_PRINT_DOT},
97 {"print-topology", 0, 0, 'p'},
99 {"verbose", 0, 0, 'v'},
102 int parse_cmdline(int argc, char **argv)
112 while ((opt = getopt_long(argc, argv, "d:e:f:hil:prvV:", opts, NULL)) != -1) {
115 media_opts.devname = optarg;
119 media_opts.entity = optarg;
122 /* 'f' is supported for backward compatibility reasons and will
126 fprintf(stderr, "Warning: the -f option is deprecated "
127 "and has been replaced by -V.\n");
129 media_opts.formats = optarg;
137 media_opts.interactive = 1;
141 media_opts.links = optarg;
145 media_opts.print = 1;
149 media_opts.reset = 1;
153 media_opts.verbose = 1;
157 media_opts.print_dot = 1;
161 media_opts.pad = optarg;
165 printf("Invalid option -%c\n", opt);
166 printf("Run %s -h for help.\n", argv[0]);