UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
host.h
Go to the documentation of this file.
1
14/*
15 * Copyright (c) 2005-2024, CESNET
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, is permitted provided that the following conditions
19 * are met:
20 *
21 * 1. Redistributions of source code must retain the above copyright
22 * notice, this list of conditions and the following disclaimer.
23 *
24 * 2. Redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution.
27 *
28 * 3. All advertising materials mentioning features or use of this software
29 * must display the following acknowledgement:
30 *
31 * This product includes software developed by CESNET z.s.p.o.
32 *
33 * 4. Neither the name of the CESNET nor the names of its contributors may be
34 * used to endorse or promote products derived from this software without
35 * specific prior written permission.
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS
38 * "AS IS" AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
39 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
40 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
41 * EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
42 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
43 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
44 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
46 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
47 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
48 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49 *
50 */
51#ifndef __host_h
52#define __host_h
53
54#ifndef __cplusplus
55#include <stdbool.h>
56#endif
57
58#include "tv.h"
59#include "utils/macros.h" // for STR_LEN
60
61#define EXIT_FAIL_USAGE 2
62#define EXIT_FAIL_UI 3
63#define EXIT_FAIL_DISPLAY 4
64#define EXIT_FAIL_CAPTURE 5
65#define EXIT_FAIL_DECODER 6
66#define EXIT_FAIL_TRANSMIT 7
67#define EXIT_FAIL_COMPRESS 8
68#define EXIT_FAIL_CONTROL_SOCK 9
69#define EXIT_FAIL_NETWORK 10
70#define EXIT_FAIL_AUDIO 11
73#define INIT_NOERR ((void*)1) // NOLINT (cppcoreguidelines-pro-type-cstyle-cast)
74
75#ifdef __cplusplus
76extern "C" {
77#endif
78
79struct module;
80struct video_frame;
81struct vidcap_params;
82
83extern int uv_argc;
84extern char **uv_argv;
85
86void handle_error(int status);
87void exit_uv(int status);
88
89#define DEFAULT_AUDIO_CAPTURE_CHANNELS 1
90extern unsigned int audio_capture_channels;
92extern unsigned int audio_capture_bps; // user-specified bps, if zero, module should choose
93 // best bps by itself
94extern unsigned int audio_capture_sample_rate; // user-specified sample rate, if zero, module should
95 // choose best value by itself (usually 48000)
96
97#define MAX_CUDA_DEVICES 4
98extern unsigned int cuda_devices[];
99extern unsigned int cuda_devices_count;
100extern bool cuda_devices_explicit;
101
102#define MODE_SENDER (1U<<0U)
103#define MODE_RECEIVER (1U<<1U)
104
105typedef void (*mainloop_t)(void *);
107extern mainloop_t mainloop;
108extern void *mainloop_udata;
109
110extern int glfw_init_count;
111extern char pixfmt_conv_pref[]; // defined in video_codec.c
112extern char *sage_network_device;
113
114// Both of following varables are non-negative. It indicates amount of milliseconds that
115// audio or video should be delayed. This shall be used for AV sync control. For
116// getting/setting you can use get_av_delay()/set_av_delay(). All is in milliseconds.
117extern volatile int audio_offset;
118extern volatile int video_offset;
119int get_audio_delay(void);
120void set_audio_delay(int val);
121
122#define RATE_UNLIMITED 0
123#define RATE_AUTO (-1)
124#define RATE_DYNAMIC (-2)
125#define RATE_MIN RATE_DYNAMIC
126#define RATE_DEFAULT (-3)
127#define RATE_FLAG_FIXED_RATE (1ll<<62ll)
128
129struct init_data;
130struct init_data *common_preinit(int argc, char *argv[]);
132
133// root module management
134void init_root_module(struct module *root_mod);
135void register_should_exit_callback(struct module *mod, void (*callback)(void *), void *udata);
137 void (*callback)(void *), void *udata);
138void exit_uv(int status);
139int get_exit_status(struct module *root_mod);
140
141void print_capabilities(const char *cfg);
142
143const char *get_version_details(void);
144void print_version(void);
145void print_configuration(void);
146
147const char *get_commandline_param(const char *key);
148void set_commandline_param(const char *key, const char *val);
149
150bool tok_in_argv(char **argv, const char *tok);
151int set_audio_capture_format(const char *optarg);
152int set_pixfmt_conv_policy(const char *optarg);
153bool parse_params(const char *optarg, bool preinit);
154bool parse_bitrate(char *optarg, long long int *bitrate);
155void print_pixel_formats(void);
156void print_video_codecs(void);
157void register_param(const char *param, const char *doc);
158
159bool register_mainloop(mainloop_t, void *);
160
162
163void crash_signal_handler(int sig);
164void hang_signal_handler(int sig);
165
166#ifdef __cplusplus
167}
168#endif
169
171 struct module *parent;
174 int mtu;
175 int ttl;
179#define COMMON_OPTS_INIT \
180 /* .parent = */ 0, \
181 /* .encryption = */ "", /* .mcast_if = */ "", /* .mtu = */ 1500, \
182 /* .ttl = */ -1, /* .force_ip_version = */ 0, /* .exporter = */ 0, \
183 /* .start_time = */ get_time_in_ns(),
184};
185
186#ifdef __cplusplus
187#include <string>
188#include <unordered_map>
189extern std::unordered_map<std::string, std::string> commandline_params;
190#endif
191
192#define MERGE_(a,b) a##b
193#define LABEL_(a) MERGE_(unique_name_, a)
194#define UNIQUE_LABEL LABEL_(__COUNTER__)
195
203#define ADD_TO_PARAM(param, doc) ADD_TO_PARAM_SALT(UNIQUE_LABEL, param, doc)
204#define ADD_TO_PARAM_SALT(salt, param, doc) static void MERGE_(add_to_param_doc_, salt)(void) __attribute__((constructor));\
205\
206static void MERGE_(add_to_param_doc_, salt)(void) \
207{\
208 register_param(param, doc);\
209}\
210struct NOT_DEFINED_STRUCT_THAT_SWALLOWS_SEMICOLON
211
212#endif
int void * val
const char * doc
Definition host.cpp:923
void handle_error(int status)
Definition host.cpp:1184
bool running_in_debugger()
Definition host.cpp:1190
void common_cleanup(struct init_data *init_data)
Definition host.cpp:203
void crash_signal_handler(int sig)
Definition host.cpp:1253
void init_root_module(struct module *root_mod)
Definition host.cpp:610
unsigned int cuda_devices_count
Definition host.cpp:168
void exit_uv(int status)
Definition host.cpp:625
void * mainloop_udata
Definition host.cpp:187
char * sage_network_device
void print_capabilities(const char *cfg)
Definition host.cpp:801
void register_should_exit_callback(struct module *mod, void(*callback)(void *), void *udata)
Definition host.cpp:1144
volatile int audio_offset
added audio delay in ms (non-negative), can be used to tune AV sync
Definition host.cpp:178
int glfw_init_count
0->1 - call glfwInit, 1->0 call glfwTerminate; glfw{Init,Terminate} should be called from main thr,...
Definition host.cpp:182
void(* mainloop_t)(void *)
Definition host.h:105
bool cuda_devices_explicit
–cuda-device/-D specified expilcitly
Definition host.cpp:169
unsigned int audio_capture_bps
Definition host.cpp:164
const char * get_commandline_param(const char *key)
Definition host.cpp:894
int get_exit_status(struct module *root_mod)
Definition host.cpp:633
int set_pixfmt_conv_policy(const char *optarg)
Definition host.cpp:327
void unregister_should_exit_callback(struct module *mod, void(*callback)(void *), void *udata)
Definition host.cpp:1158
std::unordered_map< std::string, std::string > commandline_params
Definition host.cpp:184
void register_param(const char *param, const char *doc)
Definition host.cpp:930
bool tok_in_argv(char **argv, const char *tok)
Definition host.cpp:417
bool register_mainloop(mainloop_t, void *)
Definition host.cpp:1132
bool parse_params(const char *optarg, bool preinit)
Definition host.cpp:976
unsigned int audio_capture_sample_rate
Definition host.cpp:165
void hang_signal_handler(int sig)
Definition host.cpp:1276
void set_audio_delay(int val)
Definition host.cpp:914
char pixfmt_conv_pref[]
bitdepth, subsampling, color space
Definition video_codec.c:80
void print_configuration(void)
Definition host.cpp:882
const char * get_version_details(void)
Definition host.cpp:856
bool parse_bitrate(char *optarg, long long int *bitrate)
Definition host.cpp:1012
char ** uv_argv
Definition host.cpp:174
unsigned int cuda_devices[]
Definition host.cpp:167
volatile int video_offset
added video delay in ms (non-negative), can be used to tune AV sync
Definition host.cpp:179
void print_version(void)
Definition host.cpp:868
struct init_data * common_preinit(int argc, char *argv[])
Definition host.cpp:435
int uv_argc
Definition host.cpp:173
mainloop_t mainloop
mainloop to be run if display mainloop isn't run
Definition host.cpp:186
int get_audio_delay(void)
Definition host.cpp:909
void set_commandline_param(const char *key, const char *val)
Definition host.cpp:904
void print_video_codecs(void)
Definition host.cpp:1115
int set_audio_capture_format(const char *optarg)
Definition host.cpp:313
void print_pixel_formats(void)
Definition host.cpp:1103
unsigned int audio_capture_channels
Definition host.cpp:163
@ STR_LEN
"standard" string length placeholder
Definition macros.h:134
const char * param
Definition settings.cpp:195
Option::Callback::fcn_type callback
Definition settings.cpp:251
char encryption[STR_LEN]
Definition host.h:172
int mtu
Definition host.h:174
int ttl
Definition host.h:175
char mcast_if[STR_LEN]
Definition host.h:173
struct module * parent
Definition host.h:171
struct exporter * exporter
Definition host.h:177
time_ns_t start_time
Definition host.h:178
int force_ip_version
Definition host.h:176
Struct video_frame represents a video frame and contains video description.
Definition types.h:305
long long time_ns_t
Definition tv.h:81
const char * key
Definition cineform.cpp:125