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 (implies -v)\n");
46 printf(" --print-dot Print the device topology as a dot graph (implies -v)\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("\tv4l2-mbusfmt = 'fmt:' fcc '/' size ;\n");
63 printf("\tv4l2-crop = 'crop:' '(' left ',' top ')' '/' size ;\n");
64 printf("\tv4l2-interval = '@' numerator '/' denominator ;\n");
66 printf("\tsize = width 'x' height ;\n");
68 printf("where the fields are\n");
69 printf("\tentity-number Entity numeric identifier\n");
70 printf("\tentity-name Entity name (string) \n");
71 printf("\tpad-number Pad numeric identifier\n");
72 printf("\tflags Link flags (0: inactive, 1: active)\n");
73 printf("\tfcc Format FourCC\n");
74 printf("\twidth Image width in pixels\n");
75 printf("\theight Image height in pixels\n");
76 printf("\tnumerator Frame interval numerator\n");
77 printf("\tdenominator Frame interval denominator\n");
80 #define OPT_PRINT_DOT 256
81 #define OPT_GET_FORMAT 257
83 static struct option opts[] = {
84 {"device", 1, 0, 'd'},
85 {"entity", 1, 0, 'e'},
86 {"set-format", 1, 0, 'f'},
87 {"set-v4l2", 1, 0, 'V'},
88 {"get-format", 1, 0, OPT_GET_FORMAT},
89 {"get-v4l2", 1, 0, OPT_GET_FORMAT},
91 {"interactive", 0, 0, 'i'},
93 {"print-dot", 0, 0, OPT_PRINT_DOT},
94 {"print-topology", 0, 0, 'p'},
96 {"verbose", 0, 0, 'v'},
99 int parse_cmdline(int argc, char **argv)
109 while ((opt = getopt_long(argc, argv, "d:e:f:hil:prvV:", opts, NULL)) != -1) {
112 media_opts.devname = optarg;
116 media_opts.entity = optarg;
119 /* 'f' is supported for backward compatibility reasons and will
123 fprintf(stderr, "Warning: the -f option is deprecated "
124 "and has been replaced by -V.\n");
126 media_opts.formats = optarg;
134 media_opts.interactive = 1;
138 media_opts.links = optarg;
142 media_opts.print = 1;
143 media_opts.verbose = 1;
147 media_opts.reset = 1;
151 media_opts.verbose = 1;
155 media_opts.print_dot = 1;
159 media_opts.pad = optarg;
163 printf("Invalid option -%c\n", opt);
164 printf("Run %s -h for help.\n", argv[0]);