]> git.sesse.net Git - nageru/blob - flags.cpp
Make it possible to override stream mux on the command line.
[nageru] / flags.cpp
1 #include "flags.h"
2
3 #include <getopt.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6
7 Flags global_flags;
8
9 void usage()
10 {
11         fprintf(stderr, "Usage: nageru [OPTION]...\n");
12         fprintf(stderr, "\n");
13         fprintf(stderr, "  -h, --help                      print usage information\n");
14         fprintf(stderr, "  -c, --num-cards                 set number of input cards (default 2)\n");
15         fprintf(stderr, "  -t, --theme=FILE                choose theme (default theme.lua)\n");
16         fprintf(stderr, "  -v, --va-display=SPEC           VA-API device for H.264 encoding\n");
17         fprintf(stderr, "                                    ($DISPLAY spec or /dev/dri/render* path)\n");
18         fprintf(stderr, "      --http-uncompressed-video   send uncompressed NV12 video to HTTP clients\n");
19         fprintf(stderr, "      --http-mux=NAME             mux to use for HTTP streams (default " DEFAULT_STREAM_MUX_NAME ")\n");
20         fprintf(stderr, "      --flat-audio                start with most audio processing turned off\n");
21         fprintf(stderr, "      --no-flush-pbos             do not explicitly signal texture data uploads\n");
22         fprintf(stderr, "                                    (will give display corruption, but makes it\n");
23         fprintf(stderr, "                                    possible to run with apitrace in real time)\n");
24 }
25
26 void parse_flags(int argc, char * const argv[])
27 {
28         static const option long_options[] = {
29                 { "help", no_argument, 0, 'h' },
30                 { "num-cards", required_argument, 0, 'c' },
31                 { "theme", required_argument, 0, 't' },
32                 { "va-display", required_argument, 0, 1000 },
33                 { "http-uncompressed-video", no_argument, 0, 1001 },
34                 { "http-mux", required_argument, 0, 1004 },
35                 { "flat-audio", no_argument, 0, 1002 },
36                 { "no-flush-pbos", no_argument, 0, 1003 },
37                 { 0, 0, 0, 0 }
38         };
39         for ( ;; ) {
40                 int option_index = 0;
41                 int c = getopt_long(argc, argv, "c:t:", long_options, &option_index);
42
43                 if (c == -1) {
44                         break;
45                 }
46                 switch (c) {
47                 case 'c':
48                         global_flags.num_cards = atoi(optarg);
49                         break;
50                 case 't':
51                         global_flags.theme_filename = optarg;
52                         break;
53                 case 1000:
54                         global_flags.va_display = optarg;
55                         break;
56                 case 1001:
57                         global_flags.uncompressed_video_to_http = true;
58                         break;
59                 case 1004:
60                         global_flags.stream_mux_name = optarg;
61                         break;
62                 case 1002:
63                         global_flags.flat_audio = true;
64                         break;
65                 case 1003:
66                         global_flags.flush_pbos = false;
67                         break;
68                 case 'h':
69                         usage();
70                         exit(0);
71                 default:
72                         fprintf(stderr, "Unknown option '%s'\n", argv[option_index]);
73                         fprintf(stderr, "\n");
74                         usage();
75                         exit(1);
76                 }
77         }
78 }