]> git.sesse.net Git - cubemap/blob - config.h
Simplify setting the non-blocking flag when creating HTTP sockets.
[cubemap] / config.h
1 #ifndef _CONFIG_H
2 #define _CONFIG_H
3
4 // Various routines that deal with parsing the configuration file.
5
6 #include <arpa/inet.h>
7 #include <netinet/in.h>
8 #include <stddef.h>
9 #include <string>
10 #include <vector>
11
12 struct StreamConfig {
13         std::string url;  // As seen by the client.
14         std::string hls_url;  // As seen by the client. Can be empty.
15         std::string src;  // Can be empty.
16         size_t backlog_size;
17         size_t prebuffering_bytes;
18         uint32_t pacing_rate;  // In bytes per second. Default is ~0U (no limit).
19         enum Encoding { STREAM_ENCODING_RAW = 0, STREAM_ENCODING_METACUBE };
20         Encoding encoding;
21         Encoding src_encoding;
22         std::string allow_origin;
23
24         // These only matter if hls_url is nonempty.
25         int hls_frag_duration = 6;  // Apple recommendation (“HLS Authoring Specification for Apple Devices”, point 7.5).
26         size_t hls_backlog_margin = 0;
27 };
28
29 struct UDPStreamConfig {
30         sockaddr_in6 dst;
31         std::string src;  // Can be empty.
32         uint32_t pacing_rate;  // In bytes per second. Default is ~0U (no limit).
33         int ttl;  // Default is -1 (use operating system default).
34         int multicast_iface_index;  // Default is -1 (use operating system default).
35 };
36
37 struct Gen204Config {
38         std::string url;  // As seen by the client.
39         std::string allow_origin;  // Can be empty.
40 };
41
42 struct AcceptorConfig {
43         sockaddr_in6 addr;
44
45         std::string certificate_chain, private_key;  // In PEM format.
46 };
47
48 struct LogConfig {
49         enum { LOG_TYPE_FILE, LOG_TYPE_CONSOLE, LOG_TYPE_SYSLOG } type;
50         std::string filename;
51 };
52
53 struct Config {
54         bool daemonize;
55         int num_servers;
56         std::vector<StreamConfig> streams;
57         std::vector<UDPStreamConfig> udpstreams;
58         std::vector<Gen204Config> pings;
59         std::vector<AcceptorConfig> acceptors;
60         std::vector<LogConfig> log_destinations;
61
62         std::string stats_file;  // Empty means no stats file.
63         int stats_interval;
64
65         std::string input_stats_file;  // Empty means no input stats file.
66         int input_stats_interval;
67
68         std::string access_log_file;  // Empty means no accses_log file.
69 };
70
71 // Parse and validate configuration. Returns false on error.
72 // <config> is taken to be empty (uninitialized) on entry.
73 bool parse_config(const std::string &filename, Config *config);
74
75 #endif  // !defined(_CONFIG_H)