56#define MOD_NAME "[switcher] "
65 TBOLD(
"switcher")
" capture allow switching between given "
66 "video devices optionally with audio "
67 "(see below or wiki for usage).\n\n"
68 "Switching can be done by using keys 1-N or "
69 "via a control socket.\n\n";
75 "<dev2> [-t ...]")
"\n\n");
79 "<devN>")
" - a configuration of device to be switched\n");
81 "select=<N>")
" - specifies initially selected device idx\n");
83 "excl_init")
" - devices will be initialized after switching to "
84 "and\n\t\tdeinitialized after switching to another\n");
86 "fallback")
" - in case that capture doesn't return a frame (in "
87 "time),\n\t\tcapture from next available "
91 "positional")
" options should precede its respective device.\n");
93 " uv -t switcher -s embedded -F flip -t testcard -s "
94 "analog -t decklink")
"\n");
95 color_printf(
"flip & embedded aplies to testcard, analog to decklink.\n");
98 "also: <" TUNDERLINE(
"https://github.com/CESNET/UltraGrid/wiki/"
99 "Video-Switcher#audio")
">\n\n");
119 *available_cards = NULL;
126 snprintf(
m->text,
sizeof m->text,
"map %d capture.data %d#switch to video input %d", i + 1, i, i + 1);
139 char *save_ptr = NULL;
141 while ((
item = strtok_r(cfg,
":", &save_ptr))) {
142 if (strcmp(
item,
"help") == 0) {
146 if (strcmp(
item,
"excl_init") == 0) {
148 }
else if (strcmp(
item,
"fallback") == 0) {
150 }
else if (strncasecmp(
item,
"select=", strlen(
"select=")) ==
152 char *val_s =
item + strlen(
"select=");
155 long val = strtol(val_s, &endptr, 0);
156 if (errno != 0 || *val_s ==
'\0' || *endptr !=
'\0' ||
157 val < 0 || (uintmax_t)
val > UINT_MAX) {
159 MOD_NAME "Wrong value: %s\n", val_s);
164 MSG(ERROR,
"Unknown initialization option: %s\n",
item);
171 MSG(ERROR,
"Options \"excl_init\" and \"fallback\" are "
172 "mutualy incompatible!\n");
186 MSG(ERROR,
"Unable to allocate switcher capture state\n");
191 if (cfg_c && strcmp(cfg_c,
"") != 0) {
192 char *cfg = strdup(cfg_c);
214 MSG(ERROR,
"Error: device #%d not available!\n",
222 for (
unsigned int i = 0; i < s->
devices_cnt; ++i) {
233 "Unable to initialize device %d (%s:%s).\n",
266 for (
unsigned int i = 0U; i < s->
devices_cnt; ++i) {
290 long val = strtol(msg_univ->
text, &endptr, 0);
291 if (errno != 0 ||
val < 0 || (uintmax_t)
val > UINT_MAX || msg_univ->
text[0] ==
'\0' || *endptr !=
'\0') {
296 unsigned int new_selected_device =
val;
299 if (new_selected_device < s->devices_cnt){
301 "Switched from device %d to device %d (%s).\n",
309 &s->
devices[new_selected_device]);
316 log_msg(
LOG_LEVEL_ERROR,
"[switcher] Cannot switch to device %u. Device out of bounds (total devices %u).\n",
338 "Frame timed out, using fallback device #%d\n",
struct video_frame * frame
struct audio_frame ** audio
int void(** deleter)(void *))
This file contains definition of some common audio types.
struct audio_frame audio_frame
struct used to comunicate with audio capture/playback device
int color_printf(const char *format,...)
static void new_message(struct module *m)
void log_msg(int level, const char *format,...)
#define LOG_LEVEL_INFO
normal reporting
#define LOG_LEVEL_ERROR
general errors
void module_init_default(struct module *module_data)
void module_register(struct module *module_data, struct module *parent)
void module_done(struct module *module_data)
struct module * get_root_module(struct module *node)
#define VIDCAP_INIT_NOERR
state not initialized, other action performed (typically help)
#define VIDCAP_INIT_OK
initialization successful
struct video_frame * vidcap_grab(struct vidcap *state, struct audio_frame **audio)
Grabs video frame. This function may block for a short period if waiting for incoming frame....
int initialize_video_capture(struct module *parent, struct vidcap_params *param, struct vidcap **state)
Initializes video capture.
void vidcap_done(struct vidcap *state)
Destroys vidap state.
#define VIDEO_CAPTURE_ABI_VERSION
#define VIDCAP_INIT_FAIL
error ocured
static struct @19 params[100]
@ LIBRARY_CLASS_VIDEO_CAPTURE
#define REGISTER_MODULE(name, info, lclass, abi)
Registers module to global modules' registry.
void free_message(struct message *msg, struct response *r)
struct response * new_response(int status, const char *text)
struct response * send_message_sync(struct module *root, const char *const_path, struct message *msg, int timeout_ms, int flags)
Sends message without waiting for response.
int response_get_status(struct response *r)
struct message * check_message(struct module *mod)
void free_response(struct response *r)
#define SEND_MESSAGE_FLAG_QUIET
do not print error messages on console (recv not found/queue full)
#define SEND_MESSAGE_FLAG_NO_STORE
if receiver doesn't exist, doesn't store it and retur 404 instead
#define RESPONSE_BAD_REQUEST
struct used to comunicate with audio capture/playback device
unsigned int selected_device
struct vidcap_params * params
char(* device_names)[128]
This struct represents video capture state.
Struct video_frame represents a video frame and contains video description.
static void vidcap_switcher_probe(struct device_info **available_cards, int *count, void(**deleter)(void *))
static const struct video_capture_info vidcap_switcher_info
static int parse_fmt(struct vidcap_switcher_state *s, char *cfg)
static struct video_frame * vidcap_switcher_grab(void *state, struct audio_frame **audio)
static void vidcap_switcher_done(void *state)
static void show_help(void)
static void vidcap_switcher_register_keyboard_ctl(struct vidcap_switcher_state *s)
static int vidcap_switcher_init(struct vidcap_params *params, void **state)
char * wrap_paragraph(char *text)
This is an umbrella header for video functions.
struct module * vidcap_params_get_parent(const struct vidcap_params *params)
struct vidcap_params * vidcap_params_get_next(const struct vidcap_params *curr)
const char * vidcap_params_get_driver(const struct vidcap_params *params)
void vidcap_params_set_flags(struct vidcap_params *params, unsigned int flags)
const char * vidcap_params_get_fmt(const struct vidcap_params *params)
unsigned int vidcap_params_get_flags(const struct vidcap_params *params)
struct vidcap_params * vidcap_params_get_nth(struct vidcap_params *curr, int index)