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