]> git.sesse.net Git - nageru/blob - flags.cpp
Make it possible for file and HTTP streams to use different audio codecs.
[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, "      --http-audio-codec=NAME     audio codec to use for HTTP streams\n");
21         fprintf(stderr, "                                  (default is to use the same as for the recording)\n");
22         fprintf(stderr, "      --http-audio-bitrate=KBITS  audio codec bit rate to use for HTTP streams\n");
23         fprintf(stderr, "                                  (default is %d, ignored unless --http-audio-codec is set)\n",
24                 DEFAULT_AUDIO_OUTPUT_BIT_RATE / 1000);
25         fprintf(stderr, "      --http-coarse-timebase      use less timebase for HTTP (recommended for muxers\n");
26         fprintf(stderr, "                                  that handle large pts poorly, like e.g. MP4)\n");
27         fprintf(stderr, "      --flat-audio                start with most audio processing turned off\n");
28         fprintf(stderr, "      --no-flush-pbos             do not explicitly signal texture data uploads\n");
29         fprintf(stderr, "                                    (will give display corruption, but makes it\n");
30         fprintf(stderr, "                                    possible to run with apitrace in real time)\n");
31 }
32
33 void parse_flags(int argc, char * const argv[])
34 {
35         static const option long_options[] = {
36                 { "help", no_argument, 0, 'h' },
37                 { "num-cards", required_argument, 0, 'c' },
38                 { "theme", required_argument, 0, 't' },
39                 { "va-display", required_argument, 0, 1000 },
40                 { "http-uncompressed-video", no_argument, 0, 1001 },
41                 { "http-mux", required_argument, 0, 1004 },
42                 { "http-coarse-timebase", no_argument, 0, 1005 },
43                 { "http-audio-codec", required_argument, 0, 1006 },
44                 { "http-audio-bitrate", required_argument, 0, 1007 },
45                 { "flat-audio", no_argument, 0, 1002 },
46                 { "no-flush-pbos", no_argument, 0, 1003 },
47                 { 0, 0, 0, 0 }
48         };
49         for ( ;; ) {
50                 int option_index = 0;
51                 int c = getopt_long(argc, argv, "c:t:", long_options, &option_index);
52
53                 if (c == -1) {
54                         break;
55                 }
56                 switch (c) {
57                 case 'c':
58                         global_flags.num_cards = atoi(optarg);
59                         break;
60                 case 't':
61                         global_flags.theme_filename = optarg;
62                         break;
63                 case 1000:
64                         global_flags.va_display = optarg;
65                         break;
66                 case 1001:
67                         global_flags.uncompressed_video_to_http = true;
68                         break;
69                 case 1004:
70                         global_flags.stream_mux_name = optarg;
71                         break;
72                 case 1005:
73                         global_flags.stream_coarse_timebase = true;
74                         break;
75                 case 1006:
76                         global_flags.stream_audio_codec_name = optarg;
77                         break;
78                 case 1007:
79                         global_flags.stream_audio_codec_bitrate = atoi(optarg) * 1000;
80                         break;
81                 case 1002:
82                         global_flags.flat_audio = true;
83                         break;
84                 case 1003:
85                         global_flags.flush_pbos = false;
86                         break;
87                 case 'h':
88                         usage();
89                         exit(0);
90                 default:
91                         fprintf(stderr, "Unknown option '%s'\n", argv[option_index]);
92                         fprintf(stderr, "\n");
93                         usage();
94                         exit(1);
95                 }
96         }
97 }