moved some common transmission opts to struct

This commit is contained in:
Martin Pulec
2024-08-05 15:56:00 +02:00
parent b785c3d845
commit 1ab725d575
20 changed files with 149 additions and 146 deletions

View File

@@ -114,7 +114,7 @@ struct audio_network_parameters {
int send_port = 0;
struct pdb *participants = 0;
int force_ip_version = 0;
char *mcast_if = nullptr;
const char *mcast_if;
int ttl = -1;
};
@@ -172,7 +172,7 @@ struct state_audio {
struct exporter *exporter = nullptr;
int resample_to = 0;
char *requested_encryption = nullptr;
struct common_opts opts;
int audio_tx_mode = 0;
@@ -274,12 +274,8 @@ sdp_change_address_callback(void *udata, const char *address)
* @retval >0 success but no state was created (eg. help printed)
*/
int audio_init(struct state_audio **ret, struct module *parent,
struct audio_options *opt,
const char *encryption,
int force_ip_version, const char *mcast_iface,
long long int bitrate, volatile int *audio_delay,
time_ns_t start_time,
int mtu, int ttl, struct exporter *exporter)
const struct audio_options *opt,
const struct common_opts *common)
{
char *tmp, *unused = NULL;
char *addr;
@@ -300,7 +296,7 @@ int audio_init(struct state_audio **ret, struct module *parent,
return 1;
}
struct state_audio *s = new state_audio(parent, start_time);
struct state_audio *s = new state_audio(parent, common->start_time);
s->audio_channel_map = opt->channel_map;
s->audio_scale = opt->scale;
@@ -308,7 +304,7 @@ int audio_init(struct state_audio **ret, struct module *parent,
s->audio_sender_thread_started = s->audio_receiver_thread_started = false;
s->resample_to = parse_audio_codec_params(opt->codec_cfg).sample_rate;
s->exporter = exporter;
s->exporter = common->exporter;
if (opt->echo_cancellation) {
#ifdef HAVE_SPEEXDSP
@@ -336,13 +332,11 @@ int audio_init(struct state_audio **ret, struct module *parent,
}
}
if(encryption) {
s->requested_encryption = strdup(encryption);
}
s->opts = *common;
assert(opt->host != nullptr);
tmp = strdup(opt->host);
s->audio_participants = pdb_init(audio_delay);
s->audio_participants = pdb_init(&audio_offset);
addr = strtok_r(tmp, ",", &unused);
assert(addr != nullptr);
@@ -350,10 +344,10 @@ int audio_init(struct state_audio **ret, struct module *parent,
s->audio_network_parameters.recv_port = opt->recv_port;
s->audio_network_parameters.send_port = opt->send_port;
s->audio_network_parameters.participants = s->audio_participants;
s->audio_network_parameters.force_ip_version = force_ip_version;
s->audio_network_parameters.mcast_if = mcast_iface
? strdup(mcast_iface) : NULL;
s->audio_network_parameters.ttl = ttl;
s->audio_network_parameters.force_ip_version = common->force_ip_version;
s->audio_network_parameters.mcast_if =
strlen(s->opts.mcast_if) > 0 ? s->opts.mcast_if : nullptr;
s->audio_network_parameters.ttl = s->opts.ttl;
free(tmp);
if (strcmp(opt->send_cfg, "none") != 0) {
@@ -371,7 +365,9 @@ int audio_init(struct state_audio **ret, struct module *parent,
retval = ret;
goto error;
}
s->tx_session = tx_init(s->audio_sender_module.get(), mtu, TX_MEDIA_AUDIO, opt->fec_cfg, encryption, bitrate);
s->tx_session = tx_init(
s->audio_sender_module.get(), common->mtu, TX_MEDIA_AUDIO,
opt->fec_cfg, common->encryption, 0 /* unused */);
if(!s->tx_session) {
fprintf(stderr, "Unable to initialize audio transmit.\n");
goto error;
@@ -554,10 +550,8 @@ void audio_done(struct state_audio *s)
if(s->audio_participants) {
pdb_destroy(&s->audio_participants);
}
free(s->requested_encryption);
free(s->audio_network_parameters.addr);
free(s->audio_network_parameters.mcast_if);
audio_codec_done(s->audio_encoder);
@@ -681,7 +675,11 @@ static struct audio_decoder *audio_decoder_state_create(struct state_audio *s) {
auto *dec_state = (struct audio_decoder *) calloc(1, sizeof(struct audio_decoder));
assert(dec_state != NULL);
dec_state->enabled = true;
dec_state->pbuf_data.decoder = (struct state_audio_decoder *) audio_decoder_init(s->audio_channel_map, s->audio_scale, s->requested_encryption, (audio_playback_ctl_t) audio_playback_ctl, s->audio_playback_device, s->audio_receiver_module.get());
dec_state->pbuf_data.decoder =
(struct state_audio_decoder *) audio_decoder_init(
s->audio_channel_map, s->audio_scale, s->opts.encryption,
(audio_playback_ctl_t) audio_playback_ctl,
s->audio_playback_device, s->audio_receiver_module.get());
if (!dec_state->pbuf_data.decoder) {
free(dec_state);
return NULL;

View File

@@ -56,6 +56,7 @@
#define PORT_AUDIO 5006
#include "audio/types.h"
#include "host.h" // common_opt
#include "module.h"
#include "tv.h"
@@ -81,12 +82,8 @@ struct audio_options {
};
int audio_init(struct state_audio **state, struct module *parent,
struct audio_options *opt,
const char *encryption,
int force_ip_version, const char *mcast_iface,
long long int bitrate, volatile int *audio_delay,
time_ns_t start_time,
int mtu, int ttl, struct exporter *exporter);
const struct audio_options *opt,
const struct common_opts *common);
#endif
#ifdef __cplusplus

View File

@@ -57,6 +57,7 @@
#include "video.h"
#include "video_display.h"
#include "video_display/pipe.hpp"
#include "video_rxtx.hpp" // for param_u, video_rxtx
#include "video_rxtx/ultragrid_rtp.hpp"
#include "utils/profile_timer.hpp"
@@ -94,6 +95,8 @@ struct state_transcoder_decompress : public frame_recv_delegate {
void worker();
struct capture_filter *capture_filter_state;
struct common_opts common = { COMMON_OPTS_INIT };
};
void state_transcoder_decompress::frame_arrived(struct video_frame *f, struct audio_frame *a)
@@ -179,6 +182,8 @@ void *hd_rum_decompress_init(struct module *parent, struct hd_rum_output_conf co
s = new state_transcoder_decompress();
s->recompress = recompress;
s->common.force_ip_version = force_ip_version;
s->common.start_time = get_time_in_ns();
char cfg[128] = "";
int ret;
@@ -209,17 +214,13 @@ void *hd_rum_decompress_init(struct module *parent, struct hd_rum_output_conf co
params["rxtx_mode"].i = MODE_RECEIVER;
//RTP
params["mtu"].i = 9000; // doesn't matter anyway...
// should be localhost and RX TX ports the same (here dynamic) in order to work like a pipe
params["receiver"].str = "localhost";
params["rx_port"].i = 0;
params["tx_port"].i = 0;
params["force_ip_version"].b = force_ip_version;
params["mcast_if"].str = NULL;
params["common"].ptr = &s->common;
params["fec"].str = "none";
params["encryption"].str = NULL;
params["bitrate"].ll = 0;
params["start_time"].ll = get_time_in_ns();
params["video_delay"].vptr = 0;
// UltraGrid RTP

View File

@@ -76,7 +76,8 @@ struct recompress_output_port {
recompress_output_port() = default;
recompress_output_port(struct module *parent,
std::string host, unsigned short rx_port,
unsigned short tx_port, int mtu, const char *fec, long long bitrate);
unsigned short tx_port, const struct common_opts *common,
const char *fec, long long bitrate);
std::unique_ptr<ultragrid_rtp_video_rxtx> video_rxtx;
std::string host;
@@ -107,34 +108,27 @@ struct state_recompress {
recompress_output_port::recompress_output_port(struct module *parent,
std::string host, unsigned short rx_port,
unsigned short tx_port, int mtu, const char *fec, long long bitrate) :
unsigned short tx_port, const struct common_opts *common,
const char *fec, long long bitrate) :
host(std::move(host)),
tx_port(tx_port),
frames(0),
active(true)
{
int force_ip_version = 0;
std::map<std::string, param_u> params;
// common
params["parent"].ptr = parent;
params["exporter"].ptr = NULL;
params["compression"].str = "none";
params["rxtx_mode"].i = MODE_SENDER;
//RTP
params["mtu"].i = mtu;
params["common"].cptr = common;
params["receiver"].str = this->host.c_str();
params["rx_port"].i = rx_port;
params["tx_port"].i = tx_port;
params["force_ip_version"].i = force_ip_version;
params["mcast_if"].str = NULL;
params["fec"].str = fec;
params["encryption"].str = NULL;
params["bitrate"].ll = bitrate;
params["start_time"].ll = get_time_in_ns();
params["video_delay"].vptr = 0;
// UltraGrid RTP
params["decoder_mode"].l = VIDEO_NORMAL;
@@ -211,13 +205,14 @@ static int move_port_to_worker(struct state_recompress *s, const char *compress,
int recompress_add_port(struct state_recompress *s, struct module *parent_rep,
const char *host, const char *compress, unsigned short rx_port,
unsigned short tx_port, int mtu, const char *fec, long long bitrate)
unsigned short tx_port, const struct common_opts *common,
const char *fec, long long bitrate)
{
recompress_output_port port;
try{
port = recompress_output_port(parent_rep, host, rx_port, tx_port,
mtu, fec, bitrate);
common, fec, bitrate);
} catch(...) {
return -1;
}

View File

@@ -46,6 +46,7 @@
extern "C" {
#endif
struct common_opts;
struct module;
struct video_frame;
@@ -59,7 +60,8 @@ uint32_t recompress_get_port_ssrc(struct state_recompress *s, int idx);
int recompress_add_port(struct state_recompress *s, struct module *parent_rep,
const char *host, const char *compress, unsigned short rx_port,
unsigned short tx_port, int mtu, const char *fec, long long bitrate);
unsigned short tx_port, const struct common_opts *common,
const char *fec, long long bitrate);
void recompress_remove_port(struct state_recompress *s, int index);

View File

@@ -323,12 +323,14 @@ static VOID CALLBACK wsa_deleter(DWORD /* dwErrorCode */,
#endif
static int create_output_port(struct hd_rum_translator_state *s,
const char *addr, int rx_port, int tx_port, int bufsize, int force_ip_version,
const char *compression, int mtu, const char *fec, int bitrate, bool use_server_sock = false)
const char *addr, int rx_port, int tx_port, int bufsize,
struct common_opts *common, const char *compression, const char *fec,
int bitrate, bool use_server_sock = false)
{
struct replica *rep;
try {
rep = new replica(addr, rx_port, tx_port, bufsize, &s->mod, force_ip_version);
rep = new replica(addr, rx_port, tx_port, bufsize, &s->mod,
common->force_ip_version);
if(use_server_sock){
rep->sock = s->server_socket;
}
@@ -343,7 +345,7 @@ static int create_output_port(struct hd_rum_translator_state *s,
rep->type = compression ? replica::type_t::RECOMPRESS : replica::type_t::USE_SOCK;
int idx = recompress_add_port(s->recompress, &rep->mod,
addr, compression ? compression : "none",
0, tx_port, mtu, fec, bitrate);
0, tx_port, common, fec, bitrate);
if (idx < 0) {
fprintf(stderr, "Initializing output port '%s' compression failed!\n", addr);
@@ -438,9 +440,10 @@ static void *writer(void *arg)
}
char *compress = strtok_r(NULL, " ", &save_ptr);
struct common_opts opts = { COMMON_OPTS_INIT };
int idx = create_output_port(s,
host, 0, tx_port, s->bufsize, false,
compress, 1500, nullptr, RATE_UNLIMITED, s->server_socket != nullptr);
host, 0, tx_port, s->bufsize, &opts,
compress, nullptr, RATE_UNLIMITED, s->server_socket != nullptr);
if(idx < 0) {
free_message((struct message *) msg, new_response(RESPONSE_INT_SERV_ERR, "Cannot create output port."));
@@ -584,11 +587,10 @@ struct host_opts {
char *addr;
int rx_port;
int tx_port;
int mtu;
const char *compression;
char *fec;
long long int bitrate;
int force_ip_version;
struct common_opts common_opts = { COMMON_OPTS_INIT };
};
struct cmdline_parameters {
@@ -758,7 +760,6 @@ parse_fmt(int argc, char **argv,
while (optind < argc) {
parsed->hosts.resize(parsed->host_count + 1);
parsed->hosts[parsed->host_count].bitrate = RATE_UNLIMITED;
parsed->hosts[parsed->host_count].mtu = 1500;
const char *const optstring = "+46P:c:f:l:m:";
int ch = 0;
@@ -776,7 +777,8 @@ parse_fmt(int argc, char **argv,
}
break;
case 'm':
parsed->hosts[parsed->host_count].mtu = stoi(optarg);
parsed->hosts[parsed->host_count].common_opts.mtu =
stoi(optarg);
break;
case 'c':
parsed->hosts[parsed->host_count].compression = optarg;
@@ -792,10 +794,12 @@ parse_fmt(int argc, char **argv,
}
break;
case '4':
parsed->hosts[parsed->host_count].force_ip_version = 4;
parsed->hosts[parsed->host_count]
.common_opts.force_ip_version = 4;
break;
case '6':
parsed->hosts[parsed->host_count].force_ip_version = 6;
parsed->hosts[parsed->host_count]
.common_opts.force_ip_version = 6;
break;
default:
MSG(FATAL, "Error: invalid host option.\nn");
@@ -1107,8 +1111,8 @@ int main(int argc, char **argv)
}
int idx = create_output_port(&state,
h.addr, rx_port, tx_port, state.bufsize, h.force_ip_version,
h.compression, h.mtu, h.compression ? h.fec : nullptr, h.bitrate);
h.addr, rx_port, tx_port, state.bufsize, &h.common_opts,
h.compression, h.compression ? h.fec : nullptr, h.bitrate);
if(idx < 0) {
EXIT(EXIT_FAILURE);
}

View File

@@ -55,6 +55,9 @@
#include <stdbool.h>
#endif
#include "tv.h"
#include "utils/macros.h" // for STR_LEN
#define EXIT_FAIL_USAGE 2
#define EXIT_FAIL_UI 3
#define EXIT_FAIL_DISPLAY 4
@@ -166,6 +169,20 @@ void hang_signal_handler(int sig);
}
#endif
struct common_opts {
char encryption[STR_LEN];
char mcast_if[STR_LEN];
int mtu;
int ttl;
int force_ip_version;
struct exporter *exporter;
time_ns_t start_time;
#define COMMON_OPTS_INIT \
.encryption = "", .mcast_if = "", .mtu = 1500, .ttl = -1, \
.force_ip_version = 0, .exporter = NULL, \
.start_time = get_time_in_ns(),
};
#ifdef __cplusplus
#include <string>
#include <unordered_map>

View File

@@ -498,6 +498,7 @@ struct ug_options {
audio.recv_port = -1;
audio.send_port = -1;
audio.codec_cfg = "PCM";
common.mtu = 0;
}
~ug_options() {
while (vidcap_params_head != nullptr) {
@@ -506,6 +507,8 @@ struct ug_options {
vidcap_params_head = next;
}
}
struct common_opts common = { COMMON_OPTS_INIT };
struct audio_options audio;
std::string audio_filter_cfg;
// NULL terminated array of capture devices
@@ -515,7 +518,6 @@ struct ug_options {
const char *display_cfg = "";
const char *requested_video_fec = "none";
int port_base = PORT_BASE;
int requested_ttl = -1;
int video_rx_port = -1, video_tx_port = -1;
bool should_export = false;
@@ -527,17 +529,11 @@ struct ug_options {
enum video_mode decoder_mode = VIDEO_NORMAL;
const char *requested_compression = nullptr;
int force_ip_version = 0;
const char *requested_mcast_if = NULL;
unsigned requested_mtu = 0;
const char *postprocess = NULL;
const char *requested_display = "none";
const char *requested_receiver = nullptr;
const char *requested_encryption = NULL;
long long int bitrate = RATE_DEFAULT;
long long int bitrate = RATE_DEFAULT; // video
bool is_client = false;
bool is_server = false;
@@ -767,9 +763,13 @@ parse_options_internal(int argc, char *argv[], struct ug_options *opt)
opt->vidcap_params_tail = vidcap_params_allocate_next(opt->vidcap_params_tail);
break;
case 'm':
opt->requested_mtu = atoi(optarg);
if (opt->requested_mtu < 576 && optarg[strlen(optarg) - 1] != '!') {
log_msg(LOG_LEVEL_WARNING, "MTU %1$u seems to be too low, use \"%1$u!\" to force.\n", opt->requested_mtu);
opt->common.mtu = atoi(optarg);
if (opt->common.mtu < 576 &&
optarg[strlen(optarg) - 1] != '!') {
log_msg(LOG_LEVEL_WARNING,
"MTU %1$u seems to be too low, use "
"\"%1$u!\" to force.\n",
opt->common.mtu);
return -EXIT_FAIL_USAGE;
}
break;
@@ -852,7 +852,7 @@ parse_options_internal(int argc, char *argv[], struct ug_options *opt)
break;
case '4':
case '6':
opt->force_ip_version = ch - '0';
opt->common.force_ip_version = ch - '0';
break;
case 'U':
opt->audio.channel_map = optarg;
@@ -892,7 +892,7 @@ parse_options_internal(int argc, char *argv[], struct ug_options *opt)
}
break;
case OPT_MCAST_IF:
opt->requested_mcast_if = optarg;
snprintf_ch(opt->common.mcast_if, "%s", optarg);
break;
case OPT_AUDIO_HOST:
opt->audio.host = optarg;
@@ -924,7 +924,7 @@ parse_options_internal(int argc, char *argv[], struct ug_options *opt)
vidcap_params_set_capture_filter(opt->vidcap_params_tail, optarg);
break;
case 'e':
opt->requested_encryption = optarg;
snprintf_ch(opt->common.encryption, "%s", optarg);
break;
case OPT_CONTROL_PORT:
if (!parse_control_port(optarg, opt)) {
@@ -972,7 +972,7 @@ parse_options_internal(int argc, char *argv[], struct ug_options *opt)
opt->is_server = true;
break;
case 'T':
opt->requested_ttl = stoi(optarg);
opt->common.ttl = stoi(optarg);
break;
case '?':
default:
@@ -1066,7 +1066,7 @@ static int adjust_params(struct ug_options *opt) {
if (!is_ipv6_supported()) {
LOG(LOG_LEVEL_WARNING) << "IPv6 support missing, setting IPv4-only mode.\n";
opt->force_ip_version = 4;
opt->common.force_ip_version = 4;
}
// default values for different RXTX protocols
@@ -1221,10 +1221,11 @@ static int adjust_params(struct ug_options *opt) {
if (is_host_loopback(opt->requested_receiver)
&& (opt->video_rx_port == opt->video_tx_port || opt->video_tx_port == 0)
&& (opt->audio.recv_port == opt->audio.send_port || opt->audio.send_port == 0)) {
opt->requested_mtu = opt->requested_mtu == 0 ? min(RTP_MAX_MTU, 65535) : opt->requested_mtu;
opt->common.mtu = opt->common.mtu == 0 ? min(RTP_MAX_MTU, 65535)
: opt->common.mtu;
opt->bitrate = opt->bitrate == RATE_DEFAULT ? RATE_UNLIMITED : opt->bitrate;
} else {
opt->requested_mtu = opt->requested_mtu == 0 ? 1500 : opt->requested_mtu;
opt->common.mtu = opt->common.mtu == 0 ? 1500 : opt->common.mtu;
opt->bitrate = opt->bitrate == RATE_DEFAULT ? RATE_DYNAMIC : opt->bitrate;
}
@@ -1258,7 +1259,6 @@ int main(int argc, char *argv[])
capture_thread_started = false;
unsigned display_flags = 0;
struct control_state *control = NULL;
struct exporter *exporter = NULL;
int ret;
time_ns_t start_time = get_time_in_ns();
@@ -1302,7 +1302,7 @@ int main(int argc, char *argv[])
col() << TBOLD("Capture device : ") << vidcap_params_get_driver(opt.vidcap_params_head) << "\n";
col() << TBOLD("Audio capture : ") << opt.audio.send_cfg << "\n";
col() << TBOLD("Audio playback : ") << opt.audio.recv_cfg << "\n";
col() << TBOLD("MTU : ") << opt.requested_mtu << " B\n";
col() << TBOLD("MTU : ") << opt.common.mtu << " B\n";
col() << TBOLD("Video compression: ") << opt.requested_compression << "\n";
col() << TBOLD("Audio codec : ")
<< get_name_to_audio_codec(ac_params.codec) << "\n";
@@ -1312,13 +1312,14 @@ int main(int argc, char *argv[])
col() << "\n";
}
exporter = export_init(&uv.root_module, opt.export_opts, opt.should_export);
if (!exporter) {
opt.common.exporter = export_init(&uv.root_module, opt.export_opts, opt.should_export);
if (!opt.common.exporter) {
log_msg(LOG_LEVEL_ERROR, "Export initialization failed.\n");
EXIT(EXIT_FAILURE);
}
if (control_init(opt.control_port, opt.connection_type, &control, &uv.root_module, opt.force_ip_version) != 0) {
if (control_init(opt.control_port, opt.connection_type, &control,
&uv.root_module, opt.common.force_ip_version) != 0) {
LOG(LOG_LEVEL_FATAL) << "Error: Unable to initialize remote control!\n";
EXIT(EXIT_FAIL_CONTROL_SOCK);
}
@@ -1332,11 +1333,7 @@ int main(int argc, char *argv[])
}
}
ret = audio_init (&uv.audio, &uv.root_module, &opt.audio,
opt.requested_encryption,
opt.force_ip_version, opt.requested_mcast_if,
opt.bitrate, &audio_offset, start_time,
opt.requested_mtu, opt.requested_ttl, exporter);
ret = audio_init(&uv.audio, &uv.root_module, &opt.audio, &opt.common);
if (ret != 0) {
exit_uv(ret < 0 ? EXIT_FAIL_AUDIO : 0);
goto cleanup;
@@ -1394,7 +1391,6 @@ int main(int argc, char *argv[])
// common
params["parent"].ptr = &uv.root_module;
params["exporter"].ptr = exporter;
params["compression"].str = opt.requested_compression;
params["rxtx_mode"].i = opt.video_rxtx_mode;
@@ -1405,19 +1401,13 @@ int main(int argc, char *argv[])
params["display_device"].ptr = (opt.video_rxtx_mode & MODE_RECEIVER) != 0U ? uv.display_device : nullptr;
//RTP
params["mtu"].i = opt.requested_mtu;
params["ttl"].i = opt.requested_ttl;
params["common"].cptr = &opt.common;
params["receiver"].str = opt.requested_receiver;
params["rx_port"].i = opt.video_rx_port;
params["tx_port"].i = opt.video_tx_port;
params["force_ip_version"].i = opt.force_ip_version;
params["mcast_if"].str = opt.requested_mcast_if;
params["mtu"].i = opt.requested_mtu;
params["fec"].str = opt.requested_video_fec;
params["encryption"].str = opt.requested_encryption;
params["bitrate"].ll = opt.bitrate;
params["start_time"].ll = start_time;
params["video_delay"].vptr = (volatile void *) &video_offset;
// UltraGrid RTP
params["decoder_mode"].l = (long) opt.decoder_mode;
@@ -1546,7 +1536,7 @@ cleanup:
if (uv.state_video_rxtx)
uv.state_video_rxtx->join();
export_destroy(exporter);
export_destroy(opt.common.exporter);
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);

View File

@@ -273,7 +273,7 @@ void *audio_decoder_init(char *audio_channel_map, const char *audio_scale, const
s->control = (struct control_state *) get_module(get_root_module(parent), "control");
if (encryption) {
if (strlen(encryption) > 0) {
s->dec_funcs = static_cast<const struct openssl_decrypt_info *>(load_library("openssl_decrypt",
LIBRARY_CLASS_UNDEFINED, OPENSSL_DECRYPT_ABI_VERSION));
if (!s->dec_funcs) {

View File

@@ -750,7 +750,7 @@ struct state_video_decoder *video_decoder_init(struct module *parent,
s = new state_video_decoder(parent);
if (encryption) {
if (strlen(encryption) > 0) {
s->dec_funcs = static_cast<const struct openssl_decrypt_info *>(load_library("openssl_decrypt",
LIBRARY_CLASS_UNDEFINED, OPENSSL_DECRYPT_ABI_VERSION));
if (!s->dec_funcs) {

View File

@@ -234,7 +234,7 @@ struct tx *tx_init(struct module *parent, unsigned mtu, enum tx_media_type media
return NULL;
}
}
if (encryption) {
if (strlen(encryption) > 0) {
tx->enc_funcs = static_cast<const struct openssl_encrypt_info *>(load_library("openssl_encrypt",
LIBRARY_CLASS_UNDEFINED, OPENSSL_ENCRYPT_ABI_VERSION));
if (!tx->enc_funcs) {

View File

@@ -87,6 +87,8 @@ struct ug_input_state : public frame_recv_delegate {
std::chrono::steady_clock::time_point t0;
int frames;
struct common_opts common = { COMMON_OPTS_INIT };
};
void ug_input_state::frame_arrived(struct video_frame *f, struct audio_frame *a)
@@ -163,7 +165,6 @@ static int vidcap_ug_input_init(struct vidcap_params *cap_params, void **state)
int ret = initialize_video_display(vidcap_params_get_parent(cap_params), "pipe", cfg, 0, NULL, &s->display);
assert(ret == 0 && "Unable to initialize proxy display");
time_ns_t start_time = get_time_in_ns();
map<string, param_u> params;
// common
@@ -173,18 +174,13 @@ static int vidcap_ug_input_init(struct vidcap_params *cap_params, void **state)
params["rxtx_mode"].i = MODE_RECEIVER;
//RTP
params["mtu"].i = 9000; // doesn't matter anyway...
params["common"].ptr = &s->common;
// should be localhost and RX TX ports the same (here dynamic) in order to work like a pipe
params["receiver"].str = "localhost";
params["rx_port"].i = port;
params["tx_port"].i = 0;
params["force_ip_version"].i = 0;
params["mcast_if"].str = NULL;
params["fec"].str = "none";
params["encryption"].str = NULL;
params["bitrate"].ll = 0;
params["start_time"].ll = start_time;
params["video_delay"].vptr = 0;
// UltraGrid RTP
params["decoder_mode"].l = VIDEO_NORMAL;
@@ -208,8 +204,7 @@ static int vidcap_ug_input_init(struct vidcap_params *cap_params, void **state)
.echo_cancellation = false,
.codec_cfg = "PCM"
};
if (audio_init(&s->audio, vidcap_params_get_parent(cap_params), &opt, nullptr, 0, nullptr, RATE_UNLIMITED,
nullptr, start_time, 1500, -1, nullptr) != 0) {
if (audio_init(&s->audio, vidcap_params_get_parent(cap_params), &opt, &s->common) != 0) {
delete s;
return VIDCAP_INIT_FAIL;
}

View File

@@ -68,8 +68,8 @@ using std::string;
video_rxtx::video_rxtx(map<string, param_u> const &params): m_port_id("default"),
m_rxtx_mode(params.at("rxtx_mode").i),
m_parent(static_cast<struct module *>(params.at("parent").ptr)),
m_frames_sent(0ull), m_compression(nullptr),
m_exporter(static_cast<struct exporter *>(params.at("exporter").ptr)),
m_frames_sent(0ull),
m_common(*static_cast<struct common_opts const *>(params.at("common").cptr)),
m_thread_id(), m_poisoned(false), m_joined(true) {
module_init_default(&m_sender_mod);
@@ -190,7 +190,7 @@ void *video_rxtx::sender_loop() {
break;
}
export_video(m_exporter, tx_frame.get());
export_video(m_common.exporter, tx_frame.get());
send_frame(std::move(tx_frame));
m_frames_sent += 1;

View File

@@ -38,11 +38,11 @@
#ifndef VIDEO_RXTX_H_
#define VIDEO_RXTX_H_
#include <chrono>
#include <map>
#include <memory>
#include <string>
#include "host.h"
#include "module.h"
#define VIDEO_RXTX_ABI_VERSION 3
@@ -55,6 +55,10 @@ struct video_frame;
class video_rxtx;
/**
* @todo
* get rid of this altogether and pass 2 structs (common + video_rxtx opts)
*/
union param_u {
void *ptr;
const void *cptr;
@@ -99,6 +103,8 @@ protected:
int m_rxtx_mode;
struct module *m_parent;
unsigned long long int m_frames_sent;
struct common_opts m_common;
private:
void start();
virtual void send_frame(std::shared_ptr<video_frame>) noexcept = 0;
@@ -109,9 +115,8 @@ private:
return NULL;
}
struct compress_state *m_compression;
struct compress_state *m_compression = nullptr;
pthread_mutex_t m_lock;
struct exporter *m_exporter;
pthread_t m_thread_id;
bool m_poisoned, m_joined;

View File

@@ -106,7 +106,7 @@ h264_rtp_video_rxtx::send_frame(shared_ptr<video_frame> tx_frame) noexcept
if ((m_rxtx_mode & MODE_RECEIVER) == 0) { // send RTCP (receiver thread would otherwise do this
time_ns_t curr_time = get_time_in_ns();
uint32_t ts = (curr_time - m_start_time) / 100'000 * 9; // at 90000 Hz
uint32_t ts = (curr_time - m_common.start_time) / 100'000 * 9; // at 90000 Hz
rtp_update(m_network_device, curr_time);
rtp_send_ctrl(m_network_device, ts, nullptr, curr_time);

View File

@@ -151,7 +151,7 @@ ihdtv_video_rxtx::ihdtv_video_rxtx(map<string, param_u> const &params) :
(&m_rx_connection, (argc == 0) ? NULL : argv[0],
(argc ==
0) ? NULL : ((argc == 1) ? argv[0] : argv[1]),
3000, 3001, params.at("mtu").i) != 0) {
3000, 3001, m_common.mtu) != 0) {
throw string("Error initializing receiver session");
}
}
@@ -164,7 +164,7 @@ ihdtv_video_rxtx::ihdtv_video_rxtx(map<string, param_u> const &params) :
if (ihdtv_init_tx_session
(&m_tx_connection, argv[0],
(argc == 2) ? argv[1] : argv[0],
params.at("mtu").i) != 0) {
m_common.mtu) != 0) {
throw string("Error initializing sender session");
}
}

View File

@@ -81,8 +81,9 @@ rtp_video_rxtx::process_sender_message(struct msg_sender *msg)
m_requested_receiver = msg->receiver;
m_network_device = initialize_network(
m_requested_receiver.c_str(), m_recv_port_number,
m_send_port_number, m_participants, m_force_ip_version,
m_requested_mcast_if, m_requested_ttl);
m_send_port_number, m_participants,
m_common.force_ip_version,
m_common.mcast_if, m_common.ttl);
if (m_network_device == nullptr) {
m_network_device = old_device;
m_requested_receiver = std::move(old_receiver);
@@ -105,8 +106,9 @@ rtp_video_rxtx::process_sender_message(struct msg_sender *msg)
}
m_network_device = initialize_network(
m_requested_receiver.c_str(), m_recv_port_number,
m_send_port_number, m_participants, m_force_ip_version,
m_requested_mcast_if, m_requested_ttl);
m_send_port_number, m_participants,
m_common.force_ip_version,
m_common.mcast_if, m_common.ttl);
if (m_network_device == nullptr) {
m_network_device = old_device;
@@ -161,8 +163,9 @@ rtp_video_rxtx::process_sender_message(struct msg_sender *msg)
auto *old_device = m_network_device;
m_network_device = initialize_network(
m_requested_receiver.c_str(), m_recv_port_number,
m_send_port_number, m_participants, m_force_ip_version,
m_requested_mcast_if, m_requested_ttl);
m_send_port_number, m_participants,
m_common.force_ip_version,
m_common.mcast_if, m_common.ttl);
if (m_network_device == nullptr) {
m_network_device = old_device;
MSG(ERROR, "Unable to change SSRC!\n");
@@ -189,29 +192,26 @@ rtp_video_rxtx::process_sender_message(struct msg_sender *msg)
}
rtp_video_rxtx::rtp_video_rxtx(map<string, param_u> const &params) :
video_rxtx(params), m_fec_state(NULL), m_start_time(params.at("start_time").ll), m_video_desc{}
video_rxtx(params), m_fec_state(NULL), m_video_desc{}
{
m_participants = pdb_init((volatile int *) params.at("video_delay").vptr);
m_participants = pdb_init(&video_offset);
m_requested_receiver = params.at("receiver").str;
m_recv_port_number = params.at("rx_port").i;
m_send_port_number = params.at("tx_port").i;
m_force_ip_version = params.at("force_ip_version").i;
m_requested_mcast_if = params.at("mcast_if").str;
m_requested_ttl = params.find("ttl") != params.end() ? params.at("ttl").i : -1;
m_network_device = initialize_network(
m_requested_receiver.c_str(), m_recv_port_number,
m_send_port_number, m_participants, m_force_ip_version,
m_requested_mcast_if, m_requested_ttl);
m_send_port_number, m_participants, m_common.force_ip_version,
m_common.mcast_if, m_common.ttl);
if (m_network_device == nullptr) {
throw ug_runtime_error("Unable to open network",
EXIT_FAIL_NETWORK);
}
if ((m_tx = tx_init(&m_sender_mod,
params.at("mtu").i, TX_MEDIA_VIDEO,
if ((m_tx = tx_init(&m_sender_mod, m_common.mtu,
TX_MEDIA_VIDEO,
params.at("fec").str,
params.at("encryption").str,
m_common.encryption,
params.at("bitrate").ll)) == NULL) {
throw ug_runtime_error("Unable to initialize transmitter", EXIT_FAIL_TRANSMIT);
}
@@ -276,6 +276,9 @@ struct rtp *rtp_video_rxtx::initialize_network(const char *addr, int recv_port,
const bool multithreaded = false;
#endif
if (strlen(mcast_if) == 0) {
mcast_if = nullptr;
}
struct rtp *device =
rtp_init_if(addr, mcast_if, recv_port, send_port, ttl, rtcp_bw,
FALSE, rtp_recv_callback, (uint8_t *) participants,

View File

@@ -75,11 +75,7 @@ protected:
std::string m_requested_receiver;
int m_recv_port_number;
int m_send_port_number;
int m_force_ip_version;
const char *m_requested_mcast_if;
int m_requested_ttl;
fec *m_fec_state;
time_ns_t m_start_time;
video_desc m_video_desc;
private:
struct response *process_sender_message(struct msg_sender *msg) override;

View File

@@ -85,7 +85,6 @@ ultragrid_rtp_video_rxtx::ultragrid_rtp_video_rxtx(const map<string, param_u> &p
{
m_decoder_mode = (enum video_mode) params.at("decoder_mode").l;
m_display_device = (struct display *) params.at("display_device").ptr;
m_requested_encryption = (const char *) params.at("encryption").ptr;
m_async_sending = false;
if (get_commandline_param("decoder-use-codec") != nullptr && "help"s == get_commandline_param("decoder-use-codec")) {
@@ -155,7 +154,7 @@ void ultragrid_rtp_video_rxtx::send_frame_async(shared_ptr<video_frame> tx_frame
if ((m_rxtx_mode & MODE_RECEIVER) == 0) { // otherwise receiver thread does the stuff...
time_ns_t curr_time = get_time_in_ns();
uint32_t ts = (curr_time - m_start_time) / 100'000 * 9; // at 90000 Hz
uint32_t ts = (curr_time - m_common.start_time) / 100'000 * 9; // at 90000 Hz
rtp_update(m_network_device, curr_time);
rtp_send_ctrl(m_network_device, ts, nullptr, curr_time);
@@ -189,8 +188,10 @@ void ultragrid_rtp_video_rxtx::receiver_process_messages()
m_recv_port_number = msg->new_rx_port;
m_network_device = initialize_network(m_requested_receiver.c_str(),
m_recv_port_number,
m_send_port_number, m_participants, m_force_ip_version,
m_requested_mcast_if, m_requested_ttl);
m_send_port_number, m_participants,
m_common.force_ip_version,
m_common.mcast_if,
m_common.ttl);
if (m_network_device == nullptr) {
log_msg(LOG_LEVEL_ERROR, "[control] Failed to change RX port to %d\n", msg->new_rx_port);
r = new_response(RESPONSE_INT_SERV_ERR, "Changing RX port failed!");
@@ -258,7 +259,7 @@ struct vcodec_state *ultragrid_rtp_video_rxtx::new_video_decoder(struct display
if(state) {
state->decoder = video_decoder_init(&m_receiver_mod, m_decoder_mode,
d, m_requested_encryption);
d, m_common.encryption);
if(!state->decoder) {
fprintf(stderr, "Error initializing decoder (incorrect '-M' or '-p' option?).\n");
@@ -297,7 +298,7 @@ void *ultragrid_rtp_video_rxtx::receiver_loop()
struct timeval timeout;
/* Housekeeping and RTCP... */
time_ns_t curr_time = get_time_in_ns();
uint32_t ts = (m_start_time - curr_time) / 100'000 * 9; // at 90000 Hz
uint32_t ts = (m_common.start_time - curr_time) / 100'000 * 9; // at 90000 Hz
rtp_update(m_network_device, curr_time);
rtp_send_ctrl(m_network_device, ts, nullptr, curr_time);

View File

@@ -77,7 +77,6 @@ private:
///< and used simultaneously from
///< multiple decoders, here are
///< saved forked states
const char *m_requested_encryption;
/**
* This variables serve as a notification when asynchronous sending exits