60#define MOD_NAME "[ug_input] "
72using std::chrono::duration;
73using std::chrono::duration_cast;
74using std::chrono::steady_clock;
78 queue<pair<struct video_frame *, struct audio_frame *>>
frame_queue;
88 std::chrono::steady_clock::time_point
t0;
96 lock_guard<mutex> lk(
lock);
100 MSG(WARNING,
"Dropping frame!\n");
111 TRED(
"-t ug_input")
"[:<port>[:codec=<c>]] [-s embedded]")
"\n");
121 char *saveptr =
nullptr;
122 while ((tok = strtok_r(
fmt,
":", &saveptr)) !=
nullptr) {
124 const char *
val = strchr(tok,
'=') + 1;
125 if (isdigit(tok[0])) {
130 MSG(ERROR,
"Invalid codec: %s\n",
val);
134 MSG(ERROR,
"Invalid option: %s\n", tok);
143 uint16_t port = 5004;
151 const bool parse_ret =
parse_fmt(fmt_cpy, &port, &decode_to);
160 snprintf(cfg,
sizeof cfg,
"%p", s);
162 snprintf(cfg + strlen(cfg),
sizeof cfg - strlen(cfg),
166 assert(ret == 0 &&
"Unable to initialize proxy display");
168 map<string, param_u>
params;
172 params[
"exporter"].ptr = NULL;
173 params[
"compression"].str =
"none";
177 params[
"common"].ptr = &s->common;
179 params[
"receiver"].str =
"localhost";
180 params[
"rx_port"].i = port;
182 params[
"fec"].str =
"none";
187 params[
"display_device"].ptr = s->display;
190 assert (s->video_rxtx);
195 .recv_port = port + 2,
197 .recv_cfg =
"embedded",
199 .proto =
"ultragrid_rtp",
204 .echo_cancellation =
false,
207 if (
audio_init(&s->audio, &opt, &s->common) != 0) {
223 s->t0 = steady_clock::now();
237 s->receiver_thread.join();
243 s->video_rxtx->join();
245 while (!s->frame_queue.empty()) {
246 auto item = s->frame_queue.front();
247 s->frame_queue.pop();
260 lock_guard<mutex> lk(s->lock);
261 if (s->frame_queue.empty()) {
264 auto item = s->frame_queue.front();
267 s->frame_queue.pop();
271 auto curr_time = steady_clock::now();
272 double seconds = duration_cast<duration<double>>(curr_time - s->t0).
count();
273 if (seconds >= 5.0) {
274 float fps = s->frames / seconds;
276 s->frames, seconds,
fps);
289 *available_cards =
nullptr;
struct video_frame * frame
struct audio_frame ** audio
int void(** deleter)(void *))
void vf_free(struct video_frame *buf)
Frees video_frame structure.
const char * get_codec_name(codec_t codec)
codec_t get_codec_from_name(const char *name)
This file contains definition of some common audio types.
#define AUDIO_FRAME_DISPOSE(frame)
void audio_register_aux_data(struct state_audio *s, struct additional_audio_data data)
void audio_join(struct state_audio *s)
void audio_done(struct state_audio *s)
int audio_init(struct state_audio **ret, const struct audio_options *opt, const struct common_opts *common)
void audio_start(struct state_audio *s)
int color_printf(const char *format,...)
void log_msg(int level, const char *format,...)
#define LOG_LEVEL_INFO
normal reporting
bool display_reconfigure_audio(struct display *d, int quant_samples, int channels, int sample_rate)
void display_put_audio_frame(struct display *d, const struct audio_frame *frame)
Puts audio data.
bool display_put_frame(struct display *d, struct video_frame *frame, long long timeout_ns)
Puts filled video frame. After calling this function, video frame cannot be used.
bool display_ctl_property(struct display *d, int property, void *val, size_t *len)
Gets property from video display.
void display_run_new_thread(struct display *d)
void display_done(struct display *d)
This function performs cleanup after done.
void display_join(struct display *d)
int initialize_video_display(struct module *parent, const char *requested_display, const char *fmt, unsigned int flags, const char *postprocess, struct display **out)
Initializes video display.
#define VIDCAP_INIT_NOERR
state not initialized, other action performed (typically help)
#define VIDCAP_INIT_OK
initialization successful
#define VIDCAP_NO_GENERIC_FPS_INDICATOR
#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.
#define IS_KEY_PREFIX(tok, key)
expands to true value if <k> from tok in format <k>=<v> is prefix of key
struct used to comunicate with audio capture/playback device
This struct represents initialized video display state.
void(* dispose)(struct video_frame *)
Struct video_frame represents a video frame and contains video description.
struct video_frame_callbacks callbacks
static video_rxtx * create(std::string const &name, std::map< std::string, param_u > const &)
static void * receiver_thread(void *arg)
@ VIDEO_NORMAL
normal video (one tile)
@ VIDEO_CODEC_NONE
dummy color spec
This is an umbrella header for video functions.
struct module * vidcap_params_get_parent(const struct vidcap_params *params)
const char * vidcap_params_get_fmt(const struct vidcap_params *params)
unsigned int vidcap_params_get_flags(const struct vidcap_params *params)
#define VIDCAP_FLAG_AUDIO_ANY
#define VIDEO_FRAME_DISPOSE(frame)