UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
host.cpp File Reference
#include "host.h"
#include <execinfo.h>
#include <fcntl.h>
#include <algorithm>
#include <array>
#include <cassert>
#include <cerrno>
#include <cmath>
#include <csignal>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <getopt.h>
#include <iterator>
#include <map>
#include <mutex>
#include <string_view>
#include <sys/types.h>
#include <tuple>
#include <unistd.h>
#include <vector>
#include "audio/audio_capture.h"
#include "audio/audio_filter.h"
#include "audio/audio_playback.h"
#include "audio/codec.h"
#include "audio/types.h"
#include "audio/utils.h"
#include "capture_filter.h"
#include "compat/platform_pipe.h"
#include "compat/strings.h"
#include "config_unix.h"
#include "cuda_wrapper.h"
#include "debug.h"
#include "keyboard_control.h"
#include "lib_common.h"
#include "module.h"
#include "types.h"
#include "utils/color_out.h"
#include "utils/fs.h"
#include "utils/misc.h"
#include "utils/random.h"
#include "utils/string.h"
#include "utils/string_view_utils.hpp"
#include "utils/text.h"
#include "utils/thread.h"
#include "utils/windows.h"
#include "video_capture.h"
#include "video_codec.h"
#include "video_compress.h"
#include "video_display.h"
#include <iomanip>
#include <iostream>
#include <list>
#include <fstream>
#include <string>
#include <thread>
#include <utility>

Go to the source code of this file.

Classes

struct  init_data
 
struct  state_root
 

Macros

#define MOD_NAME   "[host] "
 

Typedefs

using module_info_map = std::map<std::string, const void *>
 

Functions

 ADD_TO_PARAM ("allow-unknown-params", "* allow-unknown-params\n" " Do not exit on unknown parameter.\n")
 
 ADD_TO_PARAM ("audio-buffer-len", "* audio-buffer-len=<ms>\n" " Sets length of software audio playback buffer (in ms, ALSA/Coreaudio/Portaudio/WASAPI)\n")
 
 ADD_TO_PARAM ("audio-cap-frames", "* audio-cap-frames=<f>\n" " Sets number of audio frames captured at once (CoreAudio)\n")
 
 ADD_TO_PARAM ("audio-disable-adaptive-buffer", "* audio-disable-adaptive-buffer\n" " Disables audio adaptive playback buffer (CoreAudio/JACK)\n")
 
 ADD_TO_PARAM ("color", "* color=CT\n" " [experimental] Color space to use, C - colorimetry: 0 - undefined, 1 - BT.709, 2 - BT.2020/2100, 3 - P3; T - transfer fn: 0 - undefined, 1 - 709, 2 - HLG; 3 - PQ (signalized to GLFW on mac, NDI receiver)\n")
 
 ADD_TO_PARAM ("errors-fatal", "* errors-fatal\n" " Treats some errors as fatal and exit even though " PACKAGE_NAME " could continue otherwise.\n" " This allows less severe errors to be catched (which should not occur under normal circumstances).\n" " An environment variable ULTRAGRID_ERRORS_FATAL with the same effect can also be used.\n")
 
 ADD_TO_PARAM ("low-latency-audio", "* low-latency-audio[=ultra]\n" " Try to reduce audio latency at the expense of worse reliability\n" " Add ultra for even more aggressive setting.\n")
 
 ADD_TO_PARAM ("stderr-buf", "* stderr-buf={no|line|full}\n" " Buffering for stderr\n")
 
 ADD_TO_PARAM ("stdout-buf", "* stdout-buf={no|line|full}\n" " Buffering for stdout\n")
 
 ADD_TO_PARAM ("window-title", "* window-title=<title>\n" " Use alternative window title (SDL/GL only)\n")
 
void common_cleanup (struct init_data *init)
 
struct init_data * common_preinit (int argc, char *argv[])
 
void crash_signal_handler (int sig)
 
static void echeck_unexpected_exit (void)
 
void exit_uv (int status)
 
int get_audio_delay (void)
 
const char * get_commandline_param (const char *key)
 
int get_exit_status (struct module *root_mod)
 
const char * get_version_details ()
 
void handle_error (int status)
 
void hang_signal_handler (int sig)
 
void init_root_module (struct module *root_mod)
 
static void load_libgcc ()
 
bool parse_bitrate (char *optarg, long long int *bitrate)
 
static bool parse_opts_set_logging (int argc, char *argv[])
 
bool parse_params (const char *optarg, bool preinit)
 
static void print_backtrace ()
 
void print_capabilities (const char *cfg)
 
void print_configuration ()
 
static void print_device (std::string purpose, std::string const &mod, const device_info &device)
 
static void print_modules (std::map< enum library_class, module_info_map > &class_mod_map)
 
static void print_param_doc (void)
 
void print_pixel_formats (void)
 
void print_version ()
 
void print_video_codecs (void)
 
static void probe_all (std::map< enum library_class, module_info_map > &class_mod_map)
 
static void probe_compress (std::string const &name, const void *mod) noexcept
 
template<typename T >
static void probe_device (std::string_view cap_str, std::string const &name, const void *mod)
 
bool register_mainloop (mainloop_t m, void *u)
 
void register_param (const char *param, const char *doc)
 
void register_should_exit_callback (struct module *mod, void(*callback)(void *), void *udata)
 
bool running_in_debugger ()
 
int set_audio_capture_format (const char *optarg)
 
void set_audio_delay (int audio_delay)
 
void set_commandline_param (const char *key, const char *val)
 
static bool set_output_buffering ()
 
int set_pixfmt_conv_policy (const char *optarg)
 
bool tok_in_argv (char **argv, const char *tok)
 
void unregister_should_exit_callback (struct module *mod, void(*callback)(void *), void *udata)
 
static bool validate_param (const char *param)
 

Variables

unsigned int audio_capture_bps = 0
 
unsigned int audio_capture_channels = 0
 
unsigned int audio_capture_sample_rate = 0
 
volatile int audio_offset
 added audio delay in ms (non-negative), can be used to tune AV sync
 
std::unordered_map< std::string, std::string > commandline_params
 
unsigned int cuda_devices [MAX_CUDA_DEVICES] = { 0 }
 
unsigned int cuda_devices_count = 1
 
bool cuda_devices_explicit = false
 –cuda-device/-D specified expilcitly
 
char * export_dir = NULL
 
int glfw_init_count
 0->1 - call glfwInit, 1->0 call glfwTerminate; glfw{Init,Terminate} should be called from main thr, thus no need to synchronize
 
mainloop_t mainloop
 mainloop to be run if display mainloop isn't run
 
void * mainloop_udata
 
struct { 
 
   int   abi_ver 
 
   std::string_view   cap_str 
 
   enum library_class   cls 
 
   std::string_view   desc 
 
   void(*   probe_print )(std::string name, const void *) 
 
} mod_classes [] 
 
struct { 
 
   const char *   doc 
 
   const char *   param 
 
} params [100] 
 
uint32_t RTT = 0
 
static state_root *volatile state_root_static
 used by exit_uv() called from signal handler
 
static bool unexpected_exit_called = true
 
int uv_argc
 
char ** uv_argv
 
volatile int video_offset
 added video delay in ms (non-negative), can be used to tune AV sync
 

Detailed Description

Author
Martin Piatka piatk.nosp@m.a@ce.nosp@m.snet..nosp@m.cz
Martin Pulec marti.nosp@m.n.pu.nosp@m.lec@c.nosp@m.esne.nosp@m.t.cz

This file contains common external definitions.

Definition in file host.cpp.

Macro Definition Documentation

◆ MOD_NAME

#define MOD_NAME   "[host] "

Definition at line 142 of file host.cpp.

Typedef Documentation

◆ module_info_map

using module_info_map = std::map<std::string, const void *>

Definition at line 638 of file host.cpp.

Function Documentation

◆ ADD_TO_PARAM() [1/10]

ADD_TO_PARAM ( "allow-unknown-params" ,
"* allow-unknown-params\n" " Do not exit on unknown parameter.\n"  )

◆ ADD_TO_PARAM() [2/10]

ADD_TO_PARAM ( "audio-buffer-len" )

◆ ADD_TO_PARAM() [3/10]

ADD_TO_PARAM ( "audio-cap-frames" )

◆ ADD_TO_PARAM() [4/10]

ADD_TO_PARAM ( "audio-disable-adaptive-buffer" ,
"* audio-disable-adaptive-buffer\n" " Disables audio adaptive playback buffer (CoreAudio/JACK)\n"  )

◆ ADD_TO_PARAM() [5/10]

ADD_TO_PARAM ( "color" ,
"* color = CT\n" "  [experimental] Color space to use,
C - colorimetry:0 - undefined,
1 - BT. 709,
2 - BT.2020/ 2100,
3 - P3;T - transfer fn:0 - undefined,
1 - 709,
2 - HLG;3 - PQ(signalized to GLFW on mac, NDI receiver)\n"  )

◆ ADD_TO_PARAM() [6/10]

ADD_TO_PARAM ( "errors-fatal" ,
"* errors-fatal\n" " Treats some errors as fatal and exit even though " PACKAGE_NAME " could continue otherwise.\n" " This allows less severe errors to be catched (which should not occur under normal circumstances).\n" " An environment variable ULTRAGRID_ERRORS_FATAL with the same effect can also be used.\n"  )

◆ ADD_TO_PARAM() [7/10]

ADD_TO_PARAM ( "low-latency-audio" ,
"* low-latency-audio\n" " Try to reduce audio latency at the expense of worse reliability\n" " Add ultra for even more aggressive setting.\n" [=ultra] )

◆ ADD_TO_PARAM() [8/10]

ADD_TO_PARAM ( "stderr-buf" )

◆ ADD_TO_PARAM() [9/10]

ADD_TO_PARAM ( "stdout-buf" )

◆ ADD_TO_PARAM() [10/10]

ADD_TO_PARAM ( "window-title" )

◆ common_cleanup()

void common_cleanup ( struct init_data * init)

Definition at line 203 of file host.cpp.

204{
205 if (init) {
206#if defined BUILD_LIBRARIES
207 for (auto a : init->opened_libs) {
208 dlclose(a);
209 }
210#endif
211 com_uninitialize(&init->com_initialized);
212 }
213 delete init;
214
215#ifdef __linux__
216 muntrace();
217#endif
218
219#ifdef _WIN32
220 WSACleanup();
221#endif
222
223#if defined CUDA_DEVICE_RESET
224 // to allow "cuda-memcheck --leak-check full"
226#endif
227
229}
static af_result_code init(struct module *parent, const char *cfg, void **state)
void cuda_wrapper_device_reset(void)
static bool unexpected_exit_called
Definition host.cpp:202
void com_uninitialize(bool *com_initialized)
Definition windows.c:94

References com_uninitialize(), cuda_wrapper_device_reset(), init(), and unexpected_exit_called.

Referenced by main(), and main().

Here is the call graph for this function:

◆ common_preinit()

struct init_data * common_preinit ( int argc,
char * argv[] )

Definition at line 435 of file host.cpp.

436{
437 uv_argc = argc;
438 uv_argv = argv;
439
440 if (!parse_opts_set_logging(argc, argv)) {
441 return nullptr;
442 }
443
444 if (!set_output_buffering()) {
445 LOG(LOG_LEVEL_WARNING) << "Cannot set console output buffering!\n";
446 return nullptr;
447 }
448 std::clog.rdbuf(std::cout.rdbuf()); // use stdout for logs by default
450
451#ifdef HAVE_X
452 void *handle = dlopen(X11_LIB_NAME, RTLD_NOW);
453
454 if (handle) {
455 Status (*XInitThreadsProc)();
456 XInitThreadsProc = (Status (*)()) dlsym(handle, "XInitThreads");
457 if (XInitThreadsProc) {
458 Status s = XInitThreadsProc();
459 if (s != True) {
460 log_msg(LOG_LEVEL_WARNING, "XInitThreads failed.\n");
461 }
462 } else {
463 log_msg(LOG_LEVEL_WARNING, "Unable to load symbol XInitThreads: %s\n", dlerror());
464 }
465
466 typedef int (*XSetErrorHandler_t(int (*handler)(Display *, XErrorEvent *)))();
467 XSetErrorHandler_t *XSetErrorHandlerProc;
468 XSetErrorHandlerProc = (XSetErrorHandler_t *) dlsym(handle, "XSetErrorHandler");
469 if (XSetErrorHandlerProc) {
470 XSetErrorHandlerProc(x11_error_handler);
471 } else {
472 log_msg(LOG_LEVEL_WARNING, "Unable to load symbol XSetErrorHandler: %s\n", dlerror());
473 }
474
475 dlclose(handle);
476 } else {
477 log_msg(LOG_LEVEL_WARNING, "Unable open " X11_LIB_NAME " library: %s\n", dlerror());
478 }
479#endif
480
481 struct init_data init{};
482#ifdef _WIN32
483 WSADATA wsaData;
484 int err = WSAStartup(MAKEWORD(2, 2), &wsaData);
485 if(err != 0) {
486 fprintf(stderr, "WSAStartup failed with error %d.", err);
487 return nullptr;
488 }
489 if(LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2) {
490 fprintf(stderr, "Counld not found usable version of Winsock.\n");
491 WSACleanup();
492 return nullptr;
493 }
494
495 SetConsoleOutputCP(CP_UTF8); // see also https://stackoverflow.com/questions/1660492/utf-8-output-on-windows-console
496
497 // Initialize COM on main thread - otherwise Portaudio would initialize it as COINIT_APARTMENTTHREADED but MULTITHREADED
498 // is perhaps better variant (Portaudio would accept that).
499 const bool init_com = !tok_in_argv(argv, "screen:unregister_elevated");
500 if (init_com) {
501 com_initialize(&init.com_initialized, nullptr);
502 }
503
504 // warn in W10 "legacy" terminal emulators
505 if (getenv("TERM") == nullptr &&
506 _isatty(fileno(stdout)) &&
507 get_windows_build() < BUILD_WINDOWS_11_OR_LATER &&
508 (win_has_ancestor_process("powershell.exe") ||
509 win_has_ancestor_process("cmd.exe")) &&
510 !win_has_ancestor_process("WindowsTerminal.exe")) {
511 MSG(WARNING, "Running inside PS/cmd terminal is not recommended "
512 "because scrolling the output freezes the process, "
513 "consider using Windows Terminal instead!\n");
514 Sleep(1000);
515 }
516#endif
517
518 if (strstr(argv[0], "run_tests") == nullptr) {
519 open_all("ultragrid_*.so", init.opened_libs); // load modules
520 }
521
522 ug_rand_init();
523
524#ifdef __linux__
525 mtrace();
526#endif
527
528 load_libgcc();
529
530#ifdef HAVE_FEC_INIT
531 fec_init();
532#endif
533
535
536 return new init_data{ std::move(init) };
537}
bool color_output_init()
sets internal variable color_stdout and retunrs its contents
void log_msg(int level, const char *format,...)
Definition debug.cpp:130
#define MSG(l, fmt,...)
Definition debug.h:96
#define LOG(level)
Definition debug.h:313
#define LOG_LEVEL_WARNING
less severe errors
Definition debug.h:60
static bool parse_opts_set_logging(int argc, char *argv[])
Definition host.cpp:357
static void echeck_unexpected_exit(void)
Definition host.cpp:428
bool tok_in_argv(char **argv, const char *tok)
Definition host.cpp:417
static void load_libgcc()
Definition host.cpp:300
static bool set_output_buffering()
Definition host.cpp:237
char ** uv_argv
Definition host.cpp:174
int uv_argc
Definition host.cpp:173
void open_all(const char *pattern, list< void * > &libs)
void ug_rand_init(void)
Definition random.c:64
bool com_initialize(bool *com_initialized, const char *err_prefix)
Definition windows.c:65
@ BUILD_WINDOWS_11_OR_LATER
Definition windows.h:46

References BUILD_WINDOWS_11_OR_LATER, color_output_init(), com_initialize(), echeck_unexpected_exit(), init(), load_libgcc(), LOG, LOG_LEVEL_WARNING, log_msg(), MSG, open_all(), parse_opts_set_logging(), set_output_buffering(), tok_in_argv(), ug_rand_init(), uv_argc, and uv_argv.

Referenced by main(), and main().

Here is the call graph for this function:

◆ crash_signal_handler()

void crash_signal_handler ( int sig)

Definition at line 1253 of file host.cpp.

1254{
1256
1257 char buf[1024];
1258 char *ptr = buf;
1259 char *ptr_end = buf + sizeof buf;
1260 strappend(&ptr, ptr_end, "\n" PACKAGE_NAME " has crashed");
1261
1262 append_sig_desc(&ptr, ptr_end, sig);
1263
1264 strappend(&ptr, ptr_end, ".\n\nPlease send a bug report to address " PACKAGE_BUGREPORT ".\n");
1265 strappend(&ptr, ptr_end, "You may find some tips how to report bugs in file doc/REPORTING_BUGS.md distributed with " PACKAGE_NAME "\n");
1266 strappend(&ptr, ptr_end, "(or available online at https://github.com/CESNET/UltraGrid/blob/master/doc/REPORTING-BUGS.md).\n");
1267
1268 write_all(STDERR_FILENO, ptr - buf, buf);
1269
1271
1272 signal(sig, SIG_DFL);
1273 raise(sig);
1274}
static ssize_t write_all(fd_t fd, const void *buf, size_t count)
static void print_backtrace()
Definition host.cpp:1205
void restore_old_tio(void)
static void strappend(char **dst, size_t *dst_alloc_len, const char *src)
Definition sdp.c:366
void append_sig_desc(char **ptr, const char *ptr_end, int signum)

References append_sig_desc(), print_backtrace(), restore_old_tio(), strappend(), and write_all().

Referenced by main(), and main().

Here is the call graph for this function:

◆ echeck_unexpected_exit()

static void echeck_unexpected_exit ( void )
static

Definition at line 428 of file host.cpp.

428 {
430 return;
431 }
432 fprintf(stderr, "exit() called unexpectedly! Maybe by some library?\n");
433}

References unexpected_exit_called.

Referenced by common_preinit().

◆ exit_uv()

void exit_uv ( int status)

Exit function that sets return value and brodcasts registered modules should_exit.

Should be called after init_root_module() is called.

Definition at line 625 of file host.cpp.

625 {
626 if (!state_root_static) {
627 log_msg(LOG_LEVEL_WARNING, "%s called witout state registered.\n", __func__);
628 }
631}
static state_root *volatile state_root_static
used by exit_uv() called from signal handler
Definition host.cpp:602
void broadcast_should_exit(bool quit_watcher=false)
Definition host.cpp:579
volatile int exit_status
Definition host.cpp:587

References state_root::broadcast_should_exit(), state_root::exit_status, LOG_LEVEL_WARNING, log_msg(), and state_root_static.

Referenced by audio_cap_alsa_read(), audio_decoder_reconfigure(), audio_play_alsa_write_frame(), audio_receiver_thread(), audio_sender_process_message(), audio_sender_thread(), audio_start(), configure_with(), display_dummy_putf(), display_gl_process_key(), display_panogl_run(), display_reconfigure_audio(), display_sage_run(), display_sdl2_process_key(), display_sdl2_run(), display_sdl_run(), display_xrgl_run(), export_video(), fec_thread(), get_usable_decoders(), glfw_close_callback(), handle_error(), handle_events(), handle_keyboard_event(), initialize(), keep_alive_thread(), main(), ultragrid_rtp_video_rxtx::new_video_decoder(), process_msg(), rtp_video_rxtx::process_sender_message(), ultragrid_rtp_video_rxtx::receiver_loop(), reconfigure(), reconfigure_slave_rendering(), restartAcquisition(), h264_sdp_video_rxtx::send_frame(), signal_handler(), signal_handler(), slave_worker(), tx_send_jpeg(), validate_hwacc_param(), vidcap_file_process_messages(), vidcap_import_grab(), vidcap_screen_x11_grab(), and worker().

Here is the call graph for this function:

◆ get_audio_delay()

int get_audio_delay ( void )

Definition at line 909 of file host.cpp.

910{
911 return audio_offset > 0 ? audio_offset : -video_offset;
912}
volatile int audio_offset
added audio delay in ms (non-negative), can be used to tune AV sync
Definition host.cpp:178
volatile int video_offset
added video delay in ms (non-negative), can be used to tune AV sync
Definition host.cpp:179

References audio_offset, and video_offset.

Referenced by keyboard_control::impl::info(), and keyboard_control::impl::run().

◆ get_commandline_param()

const char * get_commandline_param ( const char * key)

Definition at line 894 of file host.cpp.

895{
896 auto it = commandline_params.find(key);
897 if (it != commandline_params.end()) {
898 return it->second.c_str();
899 } else {
900 return NULL;
901 }
902}
std::unordered_map< std::string, std::string > commandline_params
Definition host.cpp:184
const char * key
Definition cineform.cpp:125

References commandline_params, and key.

Referenced by am_participant::am_participant(), audio_frame2_resampler::audio_frame2_resampler(), ultragrid_rtp_video_rxtx::ultragrid_rtp_video_rxtx(), audio_cap_ca_init(), audio_decoder_init(), audio_decoder_reconfigure(), audio_play_alsa_init(), audio_play_alsa_reconfigure(), audio_play_ca_init(), audio_play_ca_reconfigure(), audio_play_jack_reconfigure(), audio_play_portaudio_reconfigure(), audio_play_wasapi_reconfigure(), audio_receiver_thread(), check_packet_size(), configure_with(), control_init(), control_thread(), decklink_help(), display_decklink_putf(), display_decklink_reconfigure(), display_gl_init_opengl(), display_gl_set_window_hints(), display_sdl2_reconfigure_real(), display_sdl_reconfigure_real(), echo_cancellation_init(), get_format_callback(), get_sine_signal(), get_usable_decoders(), gl_substitute_compile_link(), handle_error(), vidcap_state_aja::Init(), ldgm::init(), init_common(), init_decoder(), init_encoder(), is_output_color(), j2k_decompress_init(), libavcodec_decompress_get_property(), libavcodec_decompress_reconfigure(), libavcodec_init(), ndi_disp_format_video_metadata(), parse_params(), postprocess_frame(), reconfigure_echo(), vidcap_decklink_state::set_codec(), set_codec_context_params(), set_device_buffer(), set_mac_color_space(), set_output_buffering(), set_postprocess_convert(), show_help(), keyboard_control::impl::start(), udp_init_if(), ug_set_av_logging(), validate_hwacc_param(), vdp_interop_supported(), and video_decoder_register_display().

◆ get_exit_status()

int get_exit_status ( struct module * root_mod)

Definition at line 633 of file host.cpp.

633 {
634 assert(root_mod->cls == MODULE_CLASS_ROOT);
635 return static_cast<state_root *>(root_mod->priv_data)->exit_status;
636}
@ MODULE_CLASS_ROOT
Definition module.h:83
enum module_class cls
Definition module.h:115
void * priv_data
Definition module.h:126

References module::cls, MODULE_CLASS_ROOT, and module::priv_data.

Referenced by main().

◆ get_version_details()

const char * get_version_details ( void )

Definition at line 856 of file host.cpp.

857{
858 return
859#ifdef GIT_BRANCH
860 GIT_BRANCH " "
861#endif
862#ifdef GIT_REV
863 "rev " GIT_REV " "
864#endif
865 "built " __DATE__ " " __TIME__;
866}

Referenced by keyboard_control::impl::info(), and print_version().

◆ handle_error()

void handle_error ( int status)

Soft version of exit_uv() checks errors-fatal command-line parameters and if set, exit UltraGrid. Otherwise error is ignored.

Caller code normally continues after this function so the error must not have been fatal and UltraGrid must remain in a consistent state.

Definition at line 1184 of file host.cpp.

1184 {
1185 if (get_commandline_param("errors-fatal") || getenv("ULTRAGRID_ERRORS_FATAL")) {
1186 exit_uv(status);
1187 }
1188}
void exit_uv(int status)
Definition host.cpp:625
const char * get_commandline_param(const char *key)
Definition host.cpp:894

References exit_uv(), and get_commandline_param().

Referenced by decode_video_frame(), display_gl_init_opengl(), init_decoder(), and set_sock_opts_and_bind().

Here is the call graph for this function:

◆ hang_signal_handler()

void hang_signal_handler ( int sig)

Definition at line 1276 of file host.cpp.

1277{
1278 UNUSED(sig);
1279#ifndef _WIN32
1280 assert(sig == SIGALRM);
1281 char msg[] = "Hang detected - you may continue waiting or kill UltraGrid. Please report if UltraGrid doesn't exit after reasonable amount of time.\n";
1282 write_all(STDERR_FILENO, sizeof msg - 1, msg);
1283 signal(SIGALRM, SIG_DFL);
1284#endif // ! defined _WIN32
1285}
#define UNUSED(x)

References UNUSED, and write_all().

Referenced by main(), and main().

Here is the call graph for this function:

◆ init_root_module()

void init_root_module ( struct module * root_mod)

Initializes root module

This the root module is also responsible for regiestering and broadcasting should_exit events (see register_should_exit_callback) called by exit_uv().

Definition at line 610 of file host.cpp.

610 {
611 module_init_default(root_mod);
612 root_mod->cls = MODULE_CLASS_ROOT;
613 root_mod->new_message = nullptr; // note that the root mod messages
614 // processes also the reflector
615 root_mod->deleter = state_root::deleter;
617 root_mod->priv_data = state_root_static;
618}
void module_init_default(struct module *module_data)
Definition module.c:48
notify_t new_message
if set, notifies module that new message is in queue, receiver lock is hold during the call
Definition module.h:119
module_deleter_t deleter
Definition module.h:118
static void deleter(struct module *m)
Definition host.cpp:557

References module::cls, module::deleter, state_root::deleter(), MODULE_CLASS_ROOT, module_init_default(), module::new_message, module::priv_data, and state_root_static.

Referenced by hd_rum_translator_state::hd_rum_translator_state(), and state_uv::state_uv().

Here is the call graph for this function:

◆ load_libgcc()

static void load_libgcc ( )
static

dummy load of libgcc for backtrace() to be signal safe within crash_signal_handler() (see backtrace(3))

Definition at line 300 of file host.cpp.

301{
302#ifndef _WIN32
303 array<void *, 1> addresses{};
304 backtrace(addresses.data(), addresses.size());
305#endif
306}

Referenced by common_preinit().

◆ parse_bitrate()

bool parse_bitrate ( char * optarg,
long long int * bitrate )

Definition at line 1012 of file host.cpp.

1013{
1014 unordered_map<string, long long int> bitrate_spec_map = {
1015 {"auto", RATE_AUTO },
1016 { "dynamic", RATE_DYNAMIC },
1017 { "unlimited", RATE_UNLIMITED},
1018 };
1019
1020 if (auto it = bitrate_spec_map.find(optarg);
1021 it != bitrate_spec_map.end()) {
1022 *bitrate = it->second;
1023 return true;
1024 }
1025 if (strcmp(optarg, "help") == 0) {
1026 constexpr char const *NUMERIC_PATTERN = "{1-9}{0-9}*[kMG][!][E]";
1027 col()
1028 << "Usage:\n"
1029 << "\tuv " << TERM_BOLD "-l [auto | dynamic | unlimited | "
1030 << NUMERIC_PATTERN << "]\n" TERM_RESET
1031 << "where\n"
1032 "\t"
1033 << TBOLD("auto")
1034 << " - spread packets across frame time\n"
1035 "\t"
1036 << TBOLD("dynamic")
1037 << " - similar to \"auto\" but more relaxed - occasional "
1038 "huge frame can spread 1.5x frame time (default)\n"
1039 "\t"
1040 << TBOLD("unlimited")
1041 << " - send packets at a wire speed (in bursts)\n"
1042 "\t"
1043 << SBOLD(NUMERIC_PATTERN)
1044 << " - send packets at most at specified bitrate\n\n"
1045 << TBOLD("Notes: ")
1046 << "Use an exclamation mark to indicate intentionally very "
1047 "low bitrate. 'E' to use the value as a fixed bitrate, "
1048 "not cap /i. e. even the frames that may be sent at "
1049 "lower bitrate are sent at the nominal bitrate)\n"
1050 << "\n";
1051 return true;
1052 }
1053 bool force = false;
1054 bool fixed = false;
1055 for (int i = 0; i < 2; ++i) {
1056 if (optarg[strlen(optarg) - 1] == '!' ||
1057 optarg[strlen(optarg) - 1] == 'E') {
1058 if (optarg[strlen(optarg) - 1] == '!') {
1059 force = true;
1060 optarg[strlen(optarg) - 1] = '\0';
1061 }
1062 if (optarg[strlen(optarg) - 1] == 'E') {
1063 fixed = true;
1064 optarg[strlen(optarg) - 1] = '\0';
1065 }
1066 }
1067 }
1068 *bitrate = unit_evaluate(optarg, nullptr);
1069 if (*bitrate <= 0) {
1070 log_msg(LOG_LEVEL_ERROR, "Invalid bitrate %s!\n", optarg);
1071 return false;
1072 }
1073 constexpr long long mb5 =
1074 5ll * 1000 *
1075 1000; // it'll take 6.4 sec to send 4 MB frame at 5 Mbps
1076 constexpr long long gb100 =
1077 100ll * 1000 * 1000 *
1078 1000; // traffic shaping to eg. 40 Gbps may make sense
1079 if ((*bitrate < mb5 || *bitrate > gb100) && !force) {
1081 "Bitrate %lld bps seems to be too %s, use \"-l %s!\" "
1082 "to force if this is not a mistake.\n",
1083 *bitrate, *bitrate < mb5 ? "low" : "high", optarg);
1084 return false;
1085 }
1086 if (fixed) {
1087 *bitrate |= RATE_FLAG_FIXED_RATE;
1088 }
1089 return true;
1090}
#define TERM_BOLD
Definition color_out.h:48
#define TERM_RESET
Definition color_out.h:47
#define SBOLD(x)
Definition color_out.h:80
#define TBOLD(x)
Definition color_out.h:70
#define LOG_LEVEL_ERROR
general errors
Definition debug.h:59
#define RATE_AUTO
spread packets evenly across frame time (currently 3/4)
Definition host.h:123
#define RATE_FLAG_FIXED_RATE
use the bitrate as fixed, not capped
Definition host.h:127
#define RATE_UNLIMITED
Definition host.h:122
#define RATE_DYNAMIC
same as RATE_AUTO but occasional excess frame allowed
Definition host.h:124
long long unit_evaluate(const char *str, const char **endptr)
Definition misc.cpp:81

References LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, log_msg(), RATE_AUTO, RATE_DYNAMIC, RATE_FLAG_FIXED_RATE, RATE_UNLIMITED, SBOLD, TBOLD, TERM_BOLD, TERM_RESET, and unit_evaluate().

Referenced by parse_fmt(), and parse_options_internal().

Here is the call graph for this function:

◆ parse_opts_set_logging()

static bool parse_opts_set_logging ( int argc,
char * argv[] )
static

Sets things that must be set before anything else (logging and params)

(params because "std{out,err}-buf" param used by set_output_buffering())

Definition at line 357 of file host.cpp.

358{
359 char *log_opt = nullptr;
360 static struct option getopt_options[] = {
361 {"param", required_argument, nullptr, 'O'},
362 {"verbose", optional_argument, nullptr, 'V'},
363 { nullptr, 0, nullptr, 0 }
364 };
365 const char *const optstring = "+O:V";
366 int saved_opterr = opterr;
367 opterr = 0; // options are further handled in main.cpp. skip unknown
368
369 int logging_lvl = 0;
370 bool logger_skip_repeats = true;
371
372 log_timestamp_mode logger_show_timestamps = LOG_TIMESTAMP_AUTO;
373
374 while (optind < argc) {
375 const int ch =
376 getopt_long(argc, argv, optstring, getopt_options, nullptr);
377 switch (ch) {
378 case 'V':
379 if (optarg != nullptr) {
380 log_opt = optarg;
381 } else {
382 logging_lvl += 1;
383 }
384 break;
385 case 'O':
386 if (!parse_params(optarg, true)) {
387 return false;
388 }
389 break;
390 case -1: // skip a non-option (or an argument to an option that
391 // is not recognized by this getopt)
392 optind += 1;
393 break;
394 case '?': // other option that will be handled in main
395 break;
396 default:
397 abort(); // shouldn't reach here
398 }
399 }
400 optind = 0;
401 opterr = saved_opterr;
402 if (logging_lvl == 0) {
403 logging_lvl = getenv("ULTRAGRID_VERBOSE") != nullptr && strlen(getenv("ULTRAGRID_VERBOSE")) > 0 ? LOG_LEVEL_VERBOSE : log_level;
404 } else {
405 logging_lvl += LOG_LEVEL_INFO;
406 }
407 if (log_opt != nullptr && !parse_log_cfg(log_opt, &logging_lvl, &logger_skip_repeats, &logger_show_timestamps)) {
408 return false;
409 }
410 log_level = logging_lvl;
411 get_log_output().set_skip_repeats(logger_skip_repeats);
412 get_log_output().set_timestamp_mode(logger_show_timestamps);
413 return true;
414}
void set_skip_repeats(bool val)
Definition debug.h:155
void set_timestamp_mode(log_timestamp_mode val)
Definition debug.h:158
bool parse_log_cfg(const char *conf_str, int *log_lvl, bool *logger_skip_repeats, log_timestamp_mode *show_timestamps)
Definition debug.cpp:227
#define LOG_LEVEL_INFO
normal reporting
Definition debug.h:62
#define LOG_LEVEL_VERBOSE
Definition debug.h:63
Log_output & get_log_output()
Definition debug.h:266
log_timestamp_mode
Definition debug.h:72
@ LOG_TIMESTAMP_AUTO
Definition debug.h:75
bool parse_params(const char *optarg, bool preinit)
Definition host.cpp:976
volatile int log_level
Definition debug.cpp:65

References get_log_output(), log_level, LOG_LEVEL_INFO, LOG_LEVEL_VERBOSE, LOG_TIMESTAMP_AUTO, parse_log_cfg(), parse_params(), Log_output::set_skip_repeats(), and Log_output::set_timestamp_mode().

Referenced by common_preinit().

Here is the call graph for this function:

◆ parse_params()

bool parse_params ( const char * optarg,
bool preinit )

Parses command-line parameters given as "--param <key>=<val>[...".

Parameters
optargcommand-line arguments given to "--param", must not be NULL
preinittrue - only parse/set known parameters (notably output buffer setting), ignore help false - set also remaining parameters including full check and "help" output
Note
This function will be usually called twice - first with preinit=true and then with false. It is because the bufffering parameter need to be set early (prior to any output). On the other hand not all params can be set immediately – modules are not yet registered, so it is called once more the preinit is done.

Definition at line 976 of file host.cpp.

977{
978 if (!preinit && strcmp(optarg, "help") == 0) {
979 puts("Use of params below is experimental and should be used with a caution and a knowledge of consequences and affected functionality!\n");
980 puts("Params can be one or more (separated by comma) of following:");
982 return false;
983 }
984 char *tmp = strdupa(optarg);
985 char *item = nullptr;
986 char *save_ptr = nullptr;
987 while ((item = strtok_r(tmp, ",", &save_ptr)) != nullptr) {
988 tmp = nullptr;
989 char *key_cstr = item;
990 const char *val_cstr = "";
991 if (char *delim = strchr(item, '=')) {
992 val_cstr = delim + 1;
993 *delim = '\0';
994 }
995 if (!validate_param(key_cstr)) {
996 if (preinit) {
997 continue;
998 }
999 LOG(LOG_LEVEL_ERROR) << "Unknown parameter: " << key_cstr << "\n";
1000 LOG(LOG_LEVEL_INFO) << "Type '" << uv_argv[0] << " --param help' for list.\n";
1001 if (get_commandline_param("allow-unknown-params") ==
1002 nullptr) {
1003 return false;
1004 }
1005 }
1006 commandline_params[key_cstr] = val_cstr;
1007 }
1008 return true;
1009}
static bool validate_param(const char *param)
Definition host.cpp:949
static void print_param_doc(void)
Definition host.cpp:1092
#define strdupa(s)
Definition strings.h:77
Definition hd-rum.c:27

References commandline_params, get_commandline_param(), LOG, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, print_param_doc(), strdupa, uv_argv, and validate_param().

Referenced by parse_global_opts(), parse_options_internal(), and parse_opts_set_logging().

Here is the call graph for this function:

◆ print_backtrace()

static void print_backtrace ( )
static

Definition at line 1205 of file host.cpp.

1206{
1207#ifdef _WIN32
1208 print_stacktrace_win();
1209#else
1210 // print to a temporary file to avoid interleaving from multiple
1211 // threads
1212#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 27)
1213 int fd = memfd_create("ultragrid_backtrace", MFD_CLOEXEC);
1214#else
1215 char path[MAX_PATH_SIZE];
1216#ifdef __APPLE__
1217 const unsigned long tid = pthread_mach_thread_np(pthread_self());
1218#else
1219 const unsigned long tid = syscall(__NR_gettid);
1220#endif
1221 snprintf(path, sizeof path, "%s/ug-%lu", get_temp_dir(), tid);
1222 int fd = open(path, O_CLOEXEC | O_CREAT | O_RDWR, S_IRUSR | S_IWUSR);
1223 unlink(path);
1224#endif
1225 if (fd == -1) {
1226 fd = STDERR_FILENO;
1227 }
1228 char backtrace_msg[] = "Backtrace:\n";
1229 write_all(fd, sizeof backtrace_msg, backtrace_msg);
1230 array<void *, 256> addresses{};
1231 const int num_symbols = backtrace(addresses.data(), addresses.size());
1232 backtrace_symbols_fd(addresses.data(), num_symbols, fd);
1233 if (fd == STDERR_FILENO) {
1234 return;
1235 }
1236
1237 lseek(fd, 0, SEEK_SET);
1238 char buf[STR_LEN];
1239 ssize_t rbytes = 0;
1240 while ((rbytes = read(fd, buf, sizeof buf)) > 0) {
1241 ssize_t written = 0;
1242 ssize_t wbytes = 0;
1243 while (written < rbytes &&
1244 (wbytes = write(STDERR_FILENO, buf + written,
1245 rbytes - written)) > 0) {
1246 written += wbytes;
1247 }
1248 }
1249 close(fd);
1250#endif // defined _WIN32
1251}
#define MAX_PATH_SIZE
Definition fs.h:48
@ STR_LEN
"standard" string length placeholder
Definition macros.h:134
static const char * get_temp_dir(void)

References get_temp_dir(), MAX_PATH_SIZE, STR_LEN, and write_all().

Referenced by crash_signal_handler().

Here is the call graph for this function:

◆ print_capabilities()

void print_capabilities ( const char * cfg)

Definition at line 801 of file host.cpp.

802{
803 std::string_view conf(cfg);
804
805 std::cout << "[capability][start] version 4" << endl;
806
807 std::map<enum library_class, module_info_map> class_mod_map;
808 for(const auto& mod_class: mod_classes){
809 class_mod_map.emplace(mod_class.cls,
810 get_libraries_for_class(mod_class.cls, mod_class.abi_ver));
811 }
813 for(const auto& codec : codecs){
814 class_mod_map[LIBRARY_CLASS_AUDIO_COMPRESS].emplace(get<0>(codec).name, nullptr);
815 }
816
817 if(conf == "noprobe"){
818 print_modules(class_mod_map);
819 } else if(conf.empty()){
820 print_modules(class_mod_map);
821 probe_all(class_mod_map);
822 } else {
823 auto class_sv = tokenize(conf, ':');
824 auto mod_sv = tokenize(conf, ':');
825
827 void (*probe_print)(std::string name, const void *) = nullptr;
828 for(const auto& i : mod_classes){
829 if(i.cap_str == class_sv){
830 cls = i.cls;
831 probe_print = i.probe_print;
832 }
833 }
834
836 log_msg(LOG_LEVEL_FATAL, "Unknown library class\n");
837 return;
838 }
839
840 auto& modmap = class_mod_map[cls];
841
842 auto modinfo = modmap.find(std::string(mod_sv));
843 if(modinfo == modmap.end()){
844 log_msg(LOG_LEVEL_FATAL, "Module not found\n");
845 return;
846 }
847
848 if(probe_print)
849 probe_print(std::string(mod_sv), modinfo->second);
850
851 }
852
853 cout << "[capability][end]" << endl;
854}
vector< tuple< audio_codec_info_t, bool, string > > get_audio_codec_list()
Definition codec.cpp:109
#define LOG_LEVEL_FATAL
errors that prevent UG run
Definition debug.h:58
static void print_modules(std::map< enum library_class, module_info_map > &class_mod_map)
Definition host.cpp:791
enum library_class cls
Definition host.cpp:749
static const struct @18 mod_classes[]
void(* probe_print)(std::string name, const void *)
Definition host.cpp:751
static void probe_all(std::map< enum library_class, module_info_map > &class_mod_map)
Definition host.cpp:780
map< string, const void * > get_libraries_for_class(enum library_class cls, int abi_version, bool include_hidden)
library_class
Definition lib_common.h:73
@ LIBRARY_CLASS_UNDEFINED
Definition lib_common.h:74
@ LIBRARY_CLASS_AUDIO_COMPRESS
Definition lib_common.h:80
const char * name
Definition settings.cpp:193
std::string_view tokenize(std::string_view &str, char delim, char quot)
Tokenizer for string_view.
static struct @76 codecs[]

References cls, codecs, get_audio_codec_list(), get_libraries_for_class(), LIBRARY_CLASS_AUDIO_COMPRESS, LIBRARY_CLASS_UNDEFINED, LOG_LEVEL_FATAL, log_msg(), mod_classes, name, print_modules(), probe_all(), probe_print, and tokenize().

Referenced by main(), and parse_global_opts().

Here is the call graph for this function:

◆ print_configuration()

void print_configuration ( void )

Definition at line 882 of file host.cpp.

883{
884 const char *config_flags = CONFIG_FLAGS;
885 if (strlen(config_flags) == 0) {
886 config_flags = "(none)";
887 }
888 printf("configuration flags: %s", config_flags);
889 printf("\n\n");
890 printf(PACKAGE_NAME " was compiled with following features:\n");
891 printf(AUTOCONF_RESULT);
892}

Referenced by parse_options_internal().

◆ print_device()

static void print_device ( std::string purpose,
std::string const & mod,
const device_info & device )
static

Definition at line 640 of file host.cpp.

640 {
641 cout << "[capability][device] {"
642 "\"purpose\":" << std::quoted(purpose) << ", "
643 "\"module\":" << std::quoted(mod) << ", "
644 "\"device\":" << std::quoted(device.dev) << ", "
645 "\"name\":" << std::quoted(device.name) << ", "
646 "\"extra\": {" << device.extra << "}, "
647 "\"repeatable\":\"" << device.repeatable << "\", "
648 "\"modes\": [";
649
650 for(unsigned int j = 0; j < std::size(device.modes); j++) {
651 if (device.modes[j].id[0] == '\0') { // last item
652 break;
653 }
654 if (j > 0) {
655 printf(", ");
656 }
657 std::cout << "{\"name\":" << std::quoted(device.modes[j].name) << ", "
658 "\"opts\":" << device.modes[j].id << "}";
659 }
660 std::cout << "]";
661
662 std::cout << ", \"options\": [";
663 for(unsigned int j = 0; j < std::size(device.options); j++) {
664 if (device.options[j].key[0] == '\0') { // last item
665 break;
666 }
667 if (j > 0) {
668 printf(", ");
669 }
670 cout << "{"
671 "\"display_name\":" << std::quoted(device.options[j].display_name) << ", "
672 "\"display_desc\":" << std::quoted(device.options[j].display_desc) << ", "
673 "\"key\":" << std::quoted(device.options[j].key) << ", "
674 "\"opt_str\":" << std::quoted(device.options[j].opt_str) << ", "
675 "\"is_boolean\":\"" << (device.options[j].is_boolean ? "t" : "f") << "\"}";
676 }
677 std::cout << "]";
678
679 std::cout << "}\n";
680}
char name[1024]
human readable name of the mode
Definition types.h:395
char id[1024]
< optional zero-terminated array of available modes
Definition types.h:392
bool repeatable
Definition types.h:386
char extra[1024]
Definition types.h:389
char name[1024]
human readable name of the device
Definition types.h:385
struct device_option options[64]
Definition types.h:398
struct device_info::mode modes[512]
char dev[1024]
Definition types.h:383
char display_name[512]
Definition types.h:369
char key[512]
Definition types.h:376
char display_desc[512]
Definition types.h:370
char opt_str[512]
Definition types.h:377
bool is_boolean
Definition types.h:379

References device_info::dev, device_option::display_desc, device_option::display_name, device_info::extra, device_info::mode::id, device_option::is_boolean, device_option::key, device_info::modes, device_info::mode::name, device_info::name, device_option::opt_str, device_info::options, and device_info::repeatable.

Referenced by probe_device().

◆ print_modules()

static void print_modules ( std::map< enum library_class, module_info_map > & class_mod_map)
static

Definition at line 791 of file host.cpp.

792{
793 for(const auto& mod_class : mod_classes){
794 std::cout << "[cap] " << mod_class.desc << ":\n";
795 for(const auto& mod : class_mod_map[mod_class.cls]){
796 cout << "[cap][" << mod_class.cap_str <<"] " << mod.first << "\n";
797 }
798 }
799}

References mod_classes.

Referenced by print_capabilities().

◆ print_param_doc()

void print_param_doc ( void )
static

Definition at line 1092 of file host.cpp.

1093{
1094 for (unsigned int i = 0; i < sizeof params / sizeof params[0]; ++i) {
1095 if (params[i].doc != NULL) {
1096 puts(params[i].doc);
1097 } else {
1098 break;
1099 }
1100 }
1101}
const char * doc
Definition host.cpp:923

References doc.

Referenced by parse_params().

◆ print_pixel_formats()

void print_pixel_formats ( void )

Definition at line 1103 of file host.cpp.

1103 {
1104 cout << "codec RGB/YCbCr depth description\n";
1105 for (codec_t c = VIDEO_CODEC_FIRST; c != VIDEO_CODEC_COUNT; c = static_cast<codec_t>(static_cast<int>(c) + 1)) {
1106 if (is_codec_opaque(c)) {
1107 continue;
1108 }
1109
1110 char tag = codec_is_a_rgb(c) ? 'R' : 'Y';
1111 col() << " " << left << setw(12) << SBOLD(get_codec_name(c)) << setw(0) << " " << tag << " " << setw(2) << get_bits_per_component(c) << setw(0) << " " << get_codec_name_long(c) << "\n";
1112 }
1113}
const char * get_codec_name(codec_t codec)
codec_t
Definition types.h:65
@ VIDEO_CODEC_FIRST
Definition types.h:68
@ VIDEO_CODEC_COUNT
count of known video codecs (including VIDEO_CODEC_NONE)
Definition types.h:108
bool is_codec_opaque(codec_t codec)
bool codec_is_a_rgb(codec_t codec)
Returns TRUE if specified pixelformat is some form of RGB (not YUV).
const char * get_codec_name_long(codec_t codec)
int get_bits_per_component(codec_t codec)

References codec_is_a_rgb(), get_bits_per_component(), get_codec_name(), get_codec_name_long(), is_codec_opaque(), SBOLD, VIDEO_CODEC_COUNT, and VIDEO_CODEC_FIRST.

Referenced by parse_options_internal().

Here is the call graph for this function:

◆ print_version()

void print_version ( void )

Definition at line 868 of file host.cpp.

869{
870 bool is_release = true;
871#ifdef GIT_BRANCH
872 if (strstr(GIT_BRANCH, "release") == nullptr &&
873 strstr(GIT_BRANCH, "tags/v") == nullptr) {
874 is_release = false;
875 }
876#endif
877 col() << SBOLD(S256_FG(T_PEACH_FUZZ, PACKAGE_STRING <<
878 (is_release ? "" : "+"))) <<
879 " (" << get_version_details() << ")\n";
880}
#define T_PEACH_FUZZ
Definition color_out.h:65
#define S256_FG(col, x)
Definition color_out.h:68
const char * get_version_details()
Definition host.cpp:856

References get_version_details(), S256_FG, SBOLD, and T_PEACH_FUZZ.

Referenced by main(), and main().

Here is the call graph for this function:

◆ print_video_codecs()

void print_video_codecs ( void )

Definition at line 1115 of file host.cpp.

1115 {
1116 for (codec_t c = VIDEO_CODEC_FIRST; c != VIDEO_CODEC_COUNT; c = static_cast<codec_t>(static_cast<int>(c) + 1)) {
1117 if (!is_codec_opaque(c)) {
1118 continue;
1119 }
1120
1121 char tag = is_codec_interframe(c) ? 'I' : '.';
1122 col() << " " << left << setw(12) << SBOLD(get_codec_name(c)) << setw(0) << " " << tag << " " << " " << get_codec_name_long(c) << "\n";
1123 }
1124 cout << "\nLegend:\n" << " I - interframe codec\n";
1125}
bool is_codec_interframe(codec_t codec)

References get_codec_name(), get_codec_name_long(), is_codec_interframe(), is_codec_opaque(), SBOLD, VIDEO_CODEC_COUNT, and VIDEO_CODEC_FIRST.

Referenced by parse_options_internal().

Here is the call graph for this function:

◆ probe_all()

static void probe_all ( std::map< enum library_class, module_info_map > & class_mod_map)
static

Definition at line 780 of file host.cpp.

781{
782 for(const auto& mod_class : mod_classes){
783 for(const auto& mod : class_mod_map[mod_class.cls]){
784 if(!mod_class.probe_print)
785 continue;
786 mod_class.probe_print(mod.first, mod.second);
787 }
788 }
789}

References mod_classes.

Referenced by print_capabilities().

◆ probe_compress()

static void probe_compress ( std::string const & name,
const void * mod )
staticnoexcept

Definition at line 695 of file host.cpp.

695 {
696 auto vci = static_cast<const struct video_compress_info *>(mod);
697
698 if(vci->get_module_info){
699 auto module_info = vci->get_module_info();
700 cout << "[capability][video_compress] {"
701 "\"name\":" << std::quoted(name) << ", "
702 "\"options\": [";
703
704 int i = 0;
705 for(const auto& opt : module_info.opts){
706 if(i++ > 0)
707 cout << ", ";
708
709 cout << "{"
710 "\"display_name\":" << std::quoted(opt.display_name) << ", "
711 "\"display_desc\":" << std::quoted(opt.display_desc) << ", "
712 "\"placeholder_text\":" << std::quoted(opt.placeholder_text) << ", "
713 "\"key\":" << std::quoted(opt.key) << ", "
714 "\"opt_str\":" << std::quoted(opt.opt_str) << ", "
715 "\"is_boolean\":\"" << (opt.is_boolean ? "t" : "f") << "\"}";
716 }
717
718 cout << "], "
719 "\"codecs\": [";
720
721 int j = 0;
722 for(const auto& c : module_info.codecs){
723 if(j++ > 0)
724 cout << ", ";
725
726 cout << "{\"name\":" << std::quoted(c.name) << ", "
727 "\"priority\": " << c.priority << ", "
728 "\"encoders\":[";
729
730 int z = 0;
731 for(const auto& e : c.encoders){
732 if(z++ > 0)
733 cout << ", ";
734
735 cout << "{\"name\":" << std::quoted(e.name) << ", "
736 "\"opt_str\":" << std::quoted(e.opt_str) << "}";
737 }
738 cout << "]}";
739 }
740
741 cout << "]}" << std::endl;
742
743 }
744}

References name.

◆ probe_device()

template<typename T >
static void probe_device ( std::string_view cap_str,
std::string const & name,
const void * mod )
static

Definition at line 683 of file host.cpp.

683 {
684 auto vdi = static_cast<T>(mod);
685 int count = 0;
686 struct device_info *devices = nullptr;
687 void (*deleter)(void *) = nullptr;
688 vdi->probe(&devices, &count, &deleter);
689 for (int i = 0; i < count; ++i) {
690 print_device(std::string(cap_str), name, devices[i]);
691 }
692 deleter ? deleter(devices) : free(devices);
693}
int void(** deleter)(void *))
int count
Definition hd-rum.c:44
static void print_device(std::string purpose, std::string const &mod, const device_info &device)
Definition host.cpp:640
std::string_view cap_str
Definition host.cpp:748

References cap_str, count, deleter, name, and print_device().

Here is the call graph for this function:

◆ register_mainloop()

bool register_mainloop ( mainloop_t m,
void * u )

Registers mainloop that will be run if display-owned mainloop isn't run. Currently this is only used by Syphon, that either connects to display event loop and if there isn't any, it runs its own.

Definition at line 1132 of file host.cpp.

1133{
1134 if (mainloop) {
1135 return false;
1136 }
1137
1138 mainloop = m;
1139 mainloop_udata = u;
1140
1141 return true;
1142}
void * mainloop_udata
Definition host.cpp:187
mainloop_t mainloop
mainloop to be run if display mainloop isn't run
Definition host.cpp:186

References mainloop, and mainloop_udata.

Referenced by vidcap_syphon_init().

◆ register_param()

void register_param ( const char * param,
const char * doc )

Registers param to param database ("--param"). If param given multiple times, only first value is stored.

Definition at line 930 of file host.cpp.

931{
932 assert(param != NULL && doc != NULL);
933 for (unsigned int i = 0; i < sizeof params / sizeof params[0]; ++i) {
934 if (params[i].param == NULL) {
935 params[i].param = param;
936 params[i].doc = doc;
937 return;
938 }
939 if (strcmp(params[i].param, param) == 0) {
940 if (strcmp(params[i].doc, doc) != 0) {
941 log_msg(LOG_LEVEL_WARNING, "Param \"%s\" as it is already registered but with different documentation.\n", param);
942 }
943 return;
944 }
945 }
946 log_msg(LOG_LEVEL_WARNING, "Cannot register param \"%s\", maxmimum number of parameters reached.\n", param);
947}
const char * param
Definition host.cpp:922

References doc, LOG_LEVEL_WARNING, log_msg(), and param.

Here is the call graph for this function:

◆ register_should_exit_callback()

void register_should_exit_callback ( struct module * mod,
void(* callback )(void *),
void * udata )

Definition at line 1144 of file host.cpp.

1145{
1146 auto *s = (state_root *) get_root_module(mod)->priv_data;
1147 unique_lock<mutex> lk(s->lock);
1148 s->should_exit_callbacks.emplace_back(callback, udata);
1149}
struct module * get_root_module(struct module *node)
Definition module.c:203
Option::Callback::fcn_type callback
Definition settings.cpp:251

Referenced by state_uv::state_uv(), audio_cap_jack_init(), audio_init(), main(), video_rxtx::start(), vidcap_dshow_init(), vidcap_file_init(), and vidcap_syphon_init().

◆ running_in_debugger()

bool running_in_debugger ( )

Definition at line 1190 of file host.cpp.

1190 {
1191#ifdef __linux__
1192 ifstream ppid_f("/proc/" + to_string(getppid()) + "/comm", ifstream::in);
1193 if (ppid_f.is_open()) {
1194 string comm;
1195 ppid_f >> comm;
1196 if (comm == "gdb") {
1197 return true;
1198 }
1199 }
1200#endif
1201 return false;
1202}

Referenced by set_output_buffering(), and keyboard_control::impl::start().

◆ set_audio_capture_format()

int set_audio_capture_format ( const char * optarg)
Return values
-1invalid usage
0success
1help was printed

Definition at line 313 of file host.cpp.

314{
315 struct audio_desc desc = {};
316 if (int ret = parse_audio_format(optarg, &desc)) {
317 return ret;
318 }
319
323
324 return 0;
325}
unsigned int audio_capture_bps
Definition host.cpp:164
unsigned int audio_capture_sample_rate
Definition host.cpp:165
std::string_view desc
Definition host.cpp:747
unsigned int audio_capture_channels
Definition host.cpp:163
#define IF_NOT_NULL_ELSE(val, default_val)
Definition macros.h:51
int parse_audio_format(const char *str, struct audio_desc *ret)
Definition utils.cpp:655

References audio_capture_bps, audio_capture_channels, audio_capture_sample_rate, desc, IF_NOT_NULL_ELSE, and parse_audio_format().

Referenced by adjust_params(), and parse_options_internal().

Here is the call graph for this function:

◆ set_audio_delay()

void set_audio_delay ( int audio_delay)

Definition at line 914 of file host.cpp.

915{
916 log_msg(LOG_LEVEL_NOTICE, "Setting A/V delay: %d\n", audio_delay);
917 audio_offset = max(audio_delay, 0);
918 video_offset = audio_delay < 0 ? abs(audio_delay) : 0;
919}
static __device__ vec2 abs(const vec2 &v)
Definition cuda_dxt.cu:118
#define LOG_LEVEL_NOTICE
information that may be interesting
Definition debug.h:61
#define max(a, b)
Definition rtp.c:98

References abs(), audio_offset, LOG_LEVEL_NOTICE, log_msg(), max, and video_offset.

Referenced by parse_options_internal(), process_msg(), and keyboard_control::impl::run().

Here is the call graph for this function:

◆ set_commandline_param()

void set_commandline_param ( const char * key,
const char * val )

Definition at line 904 of file host.cpp.

905{
907}
int void * val

References commandline_params, key, and val.

Referenced by display_caca_init(), and init_common().

◆ set_output_buffering()

static bool set_output_buffering ( )
static

Definition at line 237 of file host.cpp.

237 {
238 const unordered_map<const char *, pair<FILE *, int>> outs = { // pair<output, default mode>
239#ifdef _WIN32
240 { "stdout-buf", pair{stdout, _IONBF} },
241#else
242 { "stdout-buf", pair{stdout, _IOLBF} },
243#endif
244 { "stderr-buf", pair{stderr, _IONBF} }
245 };
246 for (const auto& outp : outs) {
247 int mode = outp.second.second; // default
248
250 mode = _IONBF;
251 log_msg(LOG_LEVEL_WARNING, "Running inside debugger - disabling output buffering.\n");
252 }
253
254 if (get_commandline_param(outp.first)) {
255 const unordered_map<string, int> buf_map {
256 { "no", _IONBF }, { "line", _IOLBF }, { "full", _IOFBF }
257 };
258
259 if (string("help") == get_commandline_param(outp.first)) {
260 printf("Available values for buffering are \"no\", \"line\" and \"full\"\n");
261 return false;
262 }
263 auto it = buf_map.find(get_commandline_param(outp.first));
264 if (it == buf_map.end()) {
265 log_msg(LOG_LEVEL_ERROR, "Wrong buffer type: %s\n", get_commandline_param(outp.first));
266 return false;
267 }
268 mode = it->second;
269 }
270 if (setvbuf(outp.second.first, NULL, mode, BUFSIZ) != 0) {
271 log_msg(LOG_LEVEL_WARNING, "setvbuf: %s\n", ug_strerror(errno));
272 }
273 }
274 return true;
275}
bool running_in_debugger()
Definition host.cpp:1190
const char * ug_strerror(int errnum)
Definition misc.cpp:203
enum openssl_mode mode

References get_commandline_param(), LOG_LEVEL_ERROR, LOG_LEVEL_WARNING, log_msg(), mode, running_in_debugger(), and ug_strerror().

Referenced by common_preinit().

Here is the call graph for this function:

◆ set_pixfmt_conv_policy()

int set_pixfmt_conv_policy ( const char * optarg)

Definition at line 327 of file host.cpp.

327 {
328 if (strcmp(optarg, "help") == 0) {
329 char desc[] =
330 TBOLD("--conv-policy") " specifies the order in which various pixfmt properties are to be evaluated "
331 "if some pixel format needs conversion to another suitable pixel format.";
332 color_printf("%s\n\n", wrap_paragraph(desc));
333 color_printf("\t" TBOLD("c") " - color space\n");
334 color_printf("\t" TBOLD("d") " - bit depth\n");
335 color_printf("\t" TBOLD("s") " - subsampling\n");
336 color_printf("\nDefault: \"" TBOLD("dsc") "\" - first is respected bit-depth, then subsampling and finally color space\n\n"
337 "Permute the above letters to change the default order, eg. \"" TBOLD("cds") "\" to attempt to keep colorspace.\n");
338 return 1;
339 }
340 if (strlen(optarg) != strlen(pixfmt_conv_pref)) {
341 log_msg(LOG_LEVEL_ERROR, "Wrong pixfmt conversion policy length (exactly 3 letters need to be used)!\n");
342 return -1;
343 }
344 if (strchr(optarg, 'd') == NULL || strchr(optarg, 's') == NULL || strchr(optarg, 'c') == NULL) {
345 log_msg(LOG_LEVEL_ERROR, "Wrong pixfmt conversion policy - use exactly the set 'dsc'!\n");
346 return -1;
347 }
348 memcpy(pixfmt_conv_pref, optarg, strlen(pixfmt_conv_pref));
349 return 0;
350}
int color_printf(const char *format,...)
char pixfmt_conv_pref[]
bitdepth, subsampling, color space
Definition video_codec.c:80
char * wrap_paragraph(char *text)
Definition text.c:204

References color_printf(), desc, LOG_LEVEL_ERROR, log_msg(), pixfmt_conv_pref, TBOLD, and wrap_paragraph().

Referenced by parse_options_internal().

Here is the call graph for this function:

◆ tok_in_argv()

bool tok_in_argv ( char ** argv,
const char * tok )

Definition at line 417 of file host.cpp.

418{
419 while (*argv != nullptr) {
420 if (strstr(*argv, tok) != nullptr) {
421 return true;
422 }
423 argv++;
424 }
425 return false;
426}

Referenced by common_preinit(), and main().

◆ unregister_should_exit_callback()

void unregister_should_exit_callback ( struct module * mod,
void(* callback )(void *),
void * udata )

Unregisters should_exit callback registered with register_should_exit_callback

The callback must have been registered (and not unregistered), otherwise abort is (currently) called.

Definition at line 1158 of file host.cpp.

1160{
1161 auto *s = (state_root *) get_root_module(mod)->priv_data;
1162 unique_lock<mutex> lk(s->lock);
1163 for (auto it = s->should_exit_callbacks.begin();
1164 it != s->should_exit_callbacks.end(); ++it) {
1165 if (get<0>(*it) == callback && get<1>(*it) == udata) {
1166 s->should_exit_callbacks.erase(it);
1167 return;
1168 }
1169 }
1170 abort();
1171}

Referenced by audio_cap_jack_done(), audio_done(), video_rxtx::join(), main(), vidcap_dshow_done(), vidcap_file_done(), and vidcap_syphon_done().

◆ validate_param()

bool validate_param ( const char * param)
static

Definition at line 949 of file host.cpp.

950{
951 for (unsigned int i = 0; i < sizeof params / sizeof params[0]; ++i) {
952 if (params[i].param == NULL) {
953 return false;
954 }
955 if (strcmp(params[i].param, param) == 0) {
956 return true;
957 }
958 }
959 return false;
960}

References param.

Referenced by parse_params().

Variable Documentation

◆ abi_ver

int abi_ver

Definition at line 750 of file host.cpp.

◆ audio_capture_bps

◆ audio_capture_channels

◆ audio_capture_sample_rate

◆ audio_offset

volatile int audio_offset

added audio delay in ms (non-negative), can be used to tune AV sync

Definition at line 178 of file host.cpp.

Referenced by audio_init(), get_audio_delay(), and set_audio_delay().

◆ cap_str

std::string_view cap_str

Definition at line 748 of file host.cpp.

Referenced by probe_device(), and try_open_v4l2_device().

◆ cls

◆ commandline_params

◆ cuda_devices

◆ cuda_devices_count

◆ cuda_devices_explicit

bool cuda_devices_explicit = false

–cuda-device/-D specified expilcitly

Definition at line 169 of file host.cpp.

Referenced by cuda_conv_enabled(), cuda_conv_enabled(), and parse_cuda_device().

◆ desc

std::string_view desc

Definition at line 747 of file host.cpp.

Referenced by set_audio_capture_format(), and set_pixfmt_conv_policy().

◆ doc

◆ export_dir

char* export_dir = NULL

Definition at line 176 of file host.cpp.

◆ glfw_init_count

int glfw_init_count

0->1 - call glfwInit, 1->0 call glfwTerminate; glfw{Init,Terminate} should be called from main thr, thus no need to synchronize

Definition at line 182 of file host.cpp.

Referenced by state_gl::~state_gl(), display_gl_init_opengl(), and gl_print_monitors().

◆ mainloop

mainloop_t mainloop

mainloop to be run if display mainloop isn't run

Definition at line 186 of file host.cpp.

Referenced by display_run_mainloop(), and register_mainloop().

◆ mainloop_udata

void* mainloop_udata

Definition at line 187 of file host.cpp.

Referenced by display_run_mainloop(), and register_mainloop().

◆ [struct]

const struct { ... } mod_classes[]
Initial value:
= {
{"Compressions", "compress",
[](std::string name, const void *m) { probe_compress(name, m); }},
{"Capture filters", "capture_filter",
nullptr},
{"Capturers", "capture",
[](std::string name, const void *m){ probe_device<const video_capture_info *>("capture", name, m); }},
{"Displays", "display",
[](std::string name, const void *m){ probe_device<const video_display_info *>("video_disp", name, m); }},
{"Audio capturers", "audio_cap",
[](std::string name, const void *m){ probe_device<const audio_capture_info *>("audio_cap", name, m); }},
{"Audio filters", "audio_filter",
nullptr},
{"Audio compress", "audio_compress",
nullptr},
{"Audio playback", "audio_play",
[](std::string name, const void *m){ probe_device<const audio_playback_info *>("audio_play", name, m); }},
}
#define AUDIO_CAPTURE_ABI_VERSION
#define AUDIO_FILTER_ABI_VERSION
#define AUDIO_PLAYBACK_ABI_VERSION
#define CAPTURE_FILTER_ABI_VERSION
#define AUDIO_COMPRESS_ABI_VERSION
Definition codec.h:43
#define VIDEO_DISPLAY_ABI_VERSION
#define VIDEO_CAPTURE_ABI_VERSION
#define VIDEO_COMPRESS_ABI_VERSION
static void probe_device(std::string_view cap_str, std::string const &name, const void *mod)
Definition host.cpp:683
static void probe_compress(std::string const &name, const void *mod) noexcept
Definition host.cpp:695
@ LIBRARY_CLASS_AUDIO_FILTER
Definition lib_common.h:85
@ LIBRARY_CLASS_VIDEO_CAPTURE
Definition lib_common.h:78
@ LIBRARY_CLASS_AUDIO_PLAYBACK
Definition lib_common.h:77
@ LIBRARY_CLASS_AUDIO_CAPTURE
Definition lib_common.h:76
@ LIBRARY_CLASS_VIDEO_DISPLAY
Definition lib_common.h:79
@ LIBRARY_CLASS_CAPTURE_FILTER
Definition lib_common.h:75
@ LIBRARY_CLASS_VIDEO_COMPRESS
Definition lib_common.h:82

Referenced by print_capabilities(), print_modules(), and probe_all().

◆ param

const char* param

Definition at line 922 of file host.cpp.

Referenced by register_param(), and validate_param().

◆ [struct]

◆ probe_print

void(* probe_print) (std::string name, const void *) ( std::string name,
const void *  )

Definition at line 751 of file host.cpp.

Referenced by print_capabilities().

◆ RTT

uint32_t RTT = 0

Definition at line 171 of file host.cpp.

Referenced by process_rr().

◆ state_root_static

state_root* volatile state_root_static
static

used by exit_uv() called from signal handler

Definition at line 602 of file host.cpp.

Referenced by exit_uv(), and init_root_module().

◆ unexpected_exit_called

bool unexpected_exit_called = true
static

Definition at line 202 of file host.cpp.

Referenced by common_cleanup(), and echeck_unexpected_exit().

◆ uv_argc

int uv_argc

Definition at line 173 of file host.cpp.

Referenced by ihdtv_video_rxtx::ihdtv_video_rxtx(), common_preinit(), and run_child_process().

◆ uv_argv

◆ video_offset

volatile int video_offset

added video delay in ms (non-negative), can be used to tune AV sync

Definition at line 179 of file host.cpp.

Referenced by rtp_video_rxtx::rtp_video_rxtx(), get_audio_delay(), and set_audio_delay().