UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
lib_common.h File Reference
#include "host.h"
#include <list>
#include <map>
#include <string>
Include dependency graph for lib_common.h:

Go to the source code of this file.

Macros

#define MK_NAME(A)
 
#define MK_NAME_REF(A)
 
#define MK_STATIC(A)
 This macro causes that this module will be statically linked with UltraGrid.
 
#define MK_STATIC_REF(A)
 
#define NULL_IF_BUILD_LIBRARIES(x)
 
#define REGISTER_HIDDEN_MODULE(name, info, lclass, abi)
 
#define REGISTER_MODULE(name, info, lclass, abi)
 Registers module to global modules' registry.
 
#define REGISTER_MODULE_FUNC_FUNCNAME(name, func, lclass, abi, funcname, hidden)
 
#define REGISTER_MODULE_FUNCNAME(name, info, lclass, abi, funcname, hidden)
 
#define REGISTER_MODULE_WITH_FUNC(name, func, lclass, abi)
 

Enumerations

enum  library_class {
  LIBRARY_CLASS_UNDEFINED , LIBRARY_CLASS_CAPTURE_FILTER , LIBRARY_CLASS_AUDIO_CAPTURE , LIBRARY_CLASS_AUDIO_PLAYBACK ,
  LIBRARY_CLASS_VIDEO_CAPTURE , LIBRARY_CLASS_VIDEO_DISPLAY , LIBRARY_CLASS_AUDIO_COMPRESS , LIBRARY_CLASS_VIDEO_DECOMPRESS ,
  LIBRARY_CLASS_VIDEO_COMPRESS , LIBRARY_CLASS_VIDEO_POSTPROCESS , LIBRARY_CLASS_VIDEO_RXTX , LIBRARY_CLASS_AUDIO_FILTER
}
 

Functions

std::map< std::string, const void * > get_libraries_for_class (enum library_class cls, int abi_version, bool include_hidden=true)
 
bool list_all_modules ()
 
void list_modules (enum library_class, int abi_version, bool full)
 
const void * load_library (const char *name, enum library_class, int abi_version)
 
void open_all (const char *pattern, std::list< void * > &libs)
 
void register_library (const char *name, const void *info, enum library_class, int abi_version, int hidden)
 

Detailed Description

Author
Martin Pulec pulec.nosp@m.@ces.nosp@m.net.c.nosp@m.z

Definition in file lib_common.h.

Macro Definition Documentation

◆ MK_NAME

#define MK_NAME ( A)
Value:
A, NULL

Definition at line 58 of file lib_common.h.

◆ MK_NAME_REF

#define MK_NAME_REF ( A)
Value:
&A, NULL

Definition at line 59 of file lib_common.h.

◆ MK_STATIC

#define MK_STATIC ( A)
Value:
A, NULL

This macro causes that this module will be statically linked with UltraGrid.

Definition at line 44 of file lib_common.h.

◆ MK_STATIC_REF

#define MK_STATIC_REF ( A)
Value:
&A, NULL

Definition at line 45 of file lib_common.h.

◆ NULL_IF_BUILD_LIBRARIES

#define NULL_IF_BUILD_LIBRARIES ( x)
Value:
x

Definition at line 61 of file lib_common.h.

◆ REGISTER_HIDDEN_MODULE

#define REGISTER_HIDDEN_MODULE ( name,
info,
lclass,
abi )
Value:
#define UNIQUE_LABEL
Definition host.h:194
#define REGISTER_MODULE_FUNCNAME(name, info, lclass, abi, funcname, hidden)
Definition lib_common.h:112
const char * name
Definition settings.cpp:193

Similar to REGISTER_MODULE but do not show the module under help of correcponding class (usable for technical or deprecated modules).

Definition at line 156 of file lib_common.h.

◆ REGISTER_MODULE

#define REGISTER_MODULE ( name,
info,
lclass,
abi )
Value:

Registers module to global modules' registry.

Parameters
namename of the module to be used to load the module (Note that it has to be without quotation marks!)
infopointer to structure with the (class specific) info about module
lclassmember of library_class
abiABI version of info parameter, usually defined per class in appropriate class header (eg. video_display.h)
Note
Mangling of the constructor function name is because some files may define multiple modules (eg. audio playback SDI) and without that, function would be defined multiple times under the same name.

Definition at line 144 of file lib_common.h.

◆ REGISTER_MODULE_FUNC_FUNCNAME

#define REGISTER_MODULE_FUNC_FUNCNAME ( name,
func,
lclass,
abi,
funcname,
hidden )
Value:
static void funcname(void) __attribute__((constructor));\
\
static void funcname(void)\
{\
const void *info = func();\
if (info) {\
register_library(#name, info, lclass, abi, hidden);\
}\
}\
struct NOT_DEFINED_STRUCT_THAT_SWALLOWS_SEMICOLON
struct __attribute__((packed))
Definition rtp.h:88
HRESULT __stdcall(* func)()
Definition screen_win.c:325

Definition at line 120 of file lib_common.h.

120#define REGISTER_MODULE_FUNC_FUNCNAME(name, func, lclass, abi, funcname, hidden) static void funcname(void) __attribute__((constructor));\
121\
122static void funcname(void)\
123{\
124 const void *info = func();\
125 if (info) {\
126 register_library(#name, info, lclass, abi, hidden);\
127 }\
128}\
129struct NOT_DEFINED_STRUCT_THAT_SWALLOWS_SEMICOLON

◆ REGISTER_MODULE_FUNCNAME

#define REGISTER_MODULE_FUNCNAME ( name,
info,
lclass,
abi,
funcname,
hidden )
Value:
static void funcname(void) __attribute__((constructor));\
\
static void funcname(void)\
{\
register_library(#name, info, lclass, abi, hidden);\
}\
struct NOT_DEFINED_STRUCT_THAT_SWALLOWS_SEMICOLON

Placeholder that installs module via constructor for every macro REGISTER_MODULE/REGISTER_MODULE_HIDDEN call

Parameters
namenon-quoted module name
lclassclass of the module
abiabi version (specific for every class)
funcnameunique function name that will be used to register the module (as a constructor)
hidden0/1 - whether the module should be visible by eg. '-c help' (for technical and deprecated modules), default true

Definition at line 112 of file lib_common.h.

112#define REGISTER_MODULE_FUNCNAME(name, info, lclass, abi, funcname, hidden) static void funcname(void) __attribute__((constructor));\
113\
114static void funcname(void)\
115{\
116 register_library(#name, info, lclass, abi, hidden);\
117}\
118struct NOT_DEFINED_STRUCT_THAT_SWALLOWS_SEMICOLON

◆ REGISTER_MODULE_WITH_FUNC

#define REGISTER_MODULE_WITH_FUNC ( name,
func,
lclass,
abi )
Value:
#define REGISTER_MODULE_FUNC_FUNCNAME(name, func, lclass, abi, funcname, hidden)
Definition lib_common.h:120

same as REGISTER_MODULE, but a function is called to get the info structure on run-time allowing to run arbitrary code to do some setup

Definition at line 150 of file lib_common.h.

Enumeration Type Documentation

◆ library_class

Enumerator
LIBRARY_CLASS_UNDEFINED 
LIBRARY_CLASS_CAPTURE_FILTER 
LIBRARY_CLASS_AUDIO_CAPTURE 
LIBRARY_CLASS_AUDIO_PLAYBACK 
LIBRARY_CLASS_VIDEO_CAPTURE 
LIBRARY_CLASS_VIDEO_DISPLAY 
LIBRARY_CLASS_AUDIO_COMPRESS 
LIBRARY_CLASS_VIDEO_DECOMPRESS 
LIBRARY_CLASS_VIDEO_COMPRESS 
LIBRARY_CLASS_VIDEO_POSTPROCESS 
LIBRARY_CLASS_VIDEO_RXTX 
LIBRARY_CLASS_AUDIO_FILTER 

Definition at line 73 of file lib_common.h.

73 {
86};
@ LIBRARY_CLASS_VIDEO_POSTPROCESS
Definition lib_common.h:83
@ LIBRARY_CLASS_VIDEO_DECOMPRESS
Definition lib_common.h:81
@ 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_VIDEO_RXTX
Definition lib_common.h:84
@ LIBRARY_CLASS_AUDIO_CAPTURE
Definition lib_common.h:76
@ LIBRARY_CLASS_VIDEO_DISPLAY
Definition lib_common.h:79
@ LIBRARY_CLASS_UNDEFINED
Definition lib_common.h:74
@ LIBRARY_CLASS_CAPTURE_FILTER
Definition lib_common.h:75
@ LIBRARY_CLASS_AUDIO_COMPRESS
Definition lib_common.h:80
@ LIBRARY_CLASS_VIDEO_COMPRESS
Definition lib_common.h:82

Function Documentation

◆ get_libraries_for_class()

std::map< std::string, const void * > get_libraries_for_class ( enum library_class cls,
int abi_version,
bool include_hidden = true )

Definition at line 336 of file lib_common.cpp.

337{
338 map<string, const void *> ret;
339 auto& libraries = get_libmap();
340 auto it = libraries.find(cls);
341 if (it != libraries.end()) {
342 for (auto && item : it->second) {
343 if (abi_version == item.second.abi_version) {
344 if (include_hidden || !item.second.hidden) {
345 ret[item.first] = item.second.data;
346 }
347 } else {
348 LOG(LOG_LEVEL_WARNING) << "Module " << item.first << " ABI version mismatch (required " <<
349 abi_version << ", have " << item.second.abi_version << ")\n";
350
351 }
352 }
353 }
354
355 return ret;
356}
#define LOG(level)
Definition debug.h:313
#define LOG_LEVEL_WARNING
less severe errors
Definition debug.h:60
enum library_class cls
Definition host.cpp:749
static auto & get_libmap()
Definition hd-rum.c:27

References cls, get_libmap(), LOG, and LOG_LEVEL_WARNING.

Referenced by audio_codec_init_real(), audio_filter_init(), create_filter(), find_best_decompress(), list_modules(), and print_capabilities().

Here is the call graph for this function:

◆ list_all_modules()

bool list_all_modules ( )
Return values
falseif there occurs some problem opening one or more modules, true otherwise

Definition at line 308 of file lib_common.cpp.

308 {
309 bool ret = true;
310
311 auto& libraries = get_libmap();
312 for (auto cls_it = library_class_info.begin(); cls_it != library_class_info.end();
313 ++cls_it) {
314 cout << cls_it->second.class_name << "\n";
315 auto it = libraries.find(cls_it->first);
316 if (it != libraries.end()) {
317 for (auto && item : it->second) {
318 col() << "\t" << SBOLD(item.first) << "\n";
319 }
320 }
321 cout << "\n";
322 }
323
324 if (!lib_errors.empty()) {
325 ret = false;
326 col() << SBOLD(SRED("Errors:")) << "\n";
327 for (auto && item : lib_errors) {
328 cout << "\t" << SRED(item.first) << "\n\t\t" << item.second << "\n";
329 }
330 cout << "\n";
331 }
332
333 return ret;
334}
#define SRED(x)
Definition color_out.h:85
#define SBOLD(x)
Definition color_out.h:80
const map< enum library_class, library_class_info_t > library_class_info
static map< string, string > lib_errors

References get_libmap(), lib_errors, library_class_info, SBOLD, and SRED.

Referenced by parse_global_opts(), and parse_options_internal().

Here is the call graph for this function:

◆ list_modules()

void list_modules ( enum library_class cls,
int abi_version,
bool full )

Prints list of modules of given class

Parameters
fullinclude hidden modules

Definition at line 298 of file lib_common.cpp.

298 {
299 const auto & class_set = get_libraries_for_class(cls, abi_version, full);
300 for (auto && item : class_set) {
301 col() << "\t" << SBOLD(item.first.c_str()) << "\n";
302 }
303}
map< string, const void * > get_libraries_for_class(enum library_class cls, int abi_version, bool include_hidden)

References cls, get_libraries_for_class(), and SBOLD.

Referenced by audio_capture_print_help(), audio_playback_help(), capture_filter_init(), video_rxtx::list(), list_video_capture_devices(), list_video_display_devices(), show_compress_help(), and show_vo_postprocess_help().

Here is the call graph for this function:

◆ load_library()

const void * load_library ( const char * name,
enum library_class,
int abi_version )

Definition at line 259 of file lib_common.cpp.

260{
261 auto it_cls = get_libmap().find(cls);
262 if (it_cls != get_libmap().end()) {
263 auto it_module = it_cls->second.find(name);
264 if (it_module != it_cls->second.end()) {
265 const auto& mod_pair = it_module->second;
266 if (mod_pair.abi_version == abi_version) {
267 return mod_pair.data;
268 } else {
269 LOG(LOG_LEVEL_WARNING) << "Module " << name << " ABI version mismatch (required " <<
270 abi_version << ", have " << mod_pair.abi_version << ")\n";
271 }
272 }
273 }
274
275 // Library was not found or was not loaded due to unsatisfied
276 // dependencies. If the latter one, display reason why dlopen() failed.
277 if (library_class_info.find(cls) != library_class_info.end()) {
278 string filename = "ultragrid_";
279 if (strlen(library_class_info.at(cls).file_prefix) > 0) {
280 filename += library_class_info.at(cls).file_prefix;
281 filename += "_";
282 }
283
284 filename += name + string(".so");
285
286 if (lib_errors.find(filename) != lib_errors.end()) {
287 LOG(LOG_LEVEL_WARNING) << filename << ": " << lib_errors.find(filename)->second << "\n";
288 }
289 }
290
291 return NULL;
292}

References cls, get_libmap(), lib_errors, library_class_info, LOG, LOG_LEVEL_WARNING, and name.

Referenced by adjust_params(), audio_capture_init(), audio_decoder_init(), audio_playback_init(), video_rxtx::create(), video_rxtx::get_long_name(), init(), ldgm::init(), initialize_video_capture(), initialize_video_display(), tx_init(), and video_decoder_init().

Here is the call graph for this function:

◆ open_all()

void open_all ( const char * pattern,
std::list< void * > & libs )

Definition at line 176 of file lib_common.cpp.

176 {
177#ifdef BUILD_LIBRARIES
178 char path[512];
179 glob_t glob_buf;
180
181 /* binary not from $PATH */
182 if (!running_from_path(uv_argv)) {
183 char *tmp = strdup(uv_argv[0]);
184 char *dir = dirname(tmp);
185 snprintf(path, sizeof(path), "%s/../lib/ultragrid/%s", dir, pattern);
186 free(tmp);
187 } else {
188 snprintf(path, sizeof(path), LIB_DIR "/ultragrid/%s", pattern);
189 }
190
191 glob(path, 0, NULL, &glob_buf);
192
193 for(unsigned int i = 0; i < glob_buf.gl_pathc; ++i) {
194 void *handle = dlopen(glob_buf.gl_pathv[i], RTLD_NOW|RTLD_GLOBAL);
195 if (!handle) {
196 char *error = dlerror();
197 MSG(WARNING, "Library %s opening warning: %s \n",
198 glob_buf.gl_pathv[i], error);
199 char *filename = basename(glob_buf.gl_pathv[i]);
200 if (filename && error) {
201 lib_errors.emplace(filename, error);
202 }
203 continue;
204 }
205 libs.push_back(handle);
206 }
207
208 globfree(&glob_buf);
209#else
210 UNUSED(libs);
212#endif
213}
#define UNUSED(x)
pattern
Definition testcard.c:94
#define MSG(l, fmt,...)
Definition debug.h:96
char ** uv_argv
Definition host.cpp:174

References lib_errors, MSG, UNUSED, and uv_argv.

Referenced by common_preinit().

◆ register_library()

void register_library ( const char * name,
const void * info,
enum library_class,
int abi_version,
int hidden )

Definition at line 250 of file lib_common.cpp.

251{
252 auto& map = get_libmap()[cls];
253 if (map.find(name) != map.end()) {
254 LOG(LOG_LEVEL_ERROR) << "Module \"" << name << "\" (class " << cls << ") multiple initialization!\n";
255 }
256 map[name] = {data, abi_version, static_cast<bool>(hidden)};
257}
#define LOG_LEVEL_ERROR
general errors
Definition debug.h:59

References cls, get_libmap(), LOG, LOG_LEVEL_ERROR, and name.

Here is the call graph for this function: