Skip to content

Commit 89fdbe3

Browse files
committed
main: mv holepunch setting to separate function
from adjust_params() to shorten it. Also it is now more clearly separated. + add -DHAVE_LIBJUICE to config.h instead of passing with compiler cmdline params - in the earlier case, reconfiguration with just holepunch state switched may not trigger rebuild (config.h not changed); also consistent with most of other features Also removed HAVE_LIBJUICE guard from the udp_holepunch.h header - no need to add config.h include for udp_holepunch.c.
1 parent 32cfbe7 commit 89fdbe3

3 files changed

Lines changed: 65 additions & 57 deletions

File tree

configure.ac

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ if test "$libjuice_req" != no; then
10841084
then
10851085
libjuice=yes
10861086
add_module holepunch src/utils/udp_holepunch.o "$LIBJUICE_LIB"
1087-
COMMON_FLAGS="$COMMON_FLAGS -DHAVE_LIBJUICE"
1087+
AC_DEFINE([HAVE_LIBJUICE], [1], [Linked with libjuice library])
10881088
fi
10891089
fi
10901090

src/main.cpp

Lines changed: 64 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,6 +1123,67 @@ adjust_ports(struct ug_options *opt, unsigned audio_rxtx_mode)
11231123
}
11241124
}
11251125

1126+
static int
1127+
adjust_params_holepunch(struct ug_options *opt)
1128+
{
1129+
#ifndef HAVE_LIBJUICE
1130+
(void) opt;
1131+
log_msg(LOG_LEVEL_ERROR, "Ultragrid was compiled without holepunch support\n");
1132+
return EXIT_FAILURE;
1133+
#else
1134+
static char punched_host[512];
1135+
Holepunch_config punch_c = {};
1136+
1137+
if(!parse_holepunch_conf(opt->nat_traverse_config, &punch_c)){
1138+
return EXIT_FAILURE;
1139+
}
1140+
1141+
commandline_params["udp-disable-multi-socket"] = string();
1142+
1143+
if (strcmp("none", vidcap_params_get_driver(opt->vidcap_params_head)) == 0
1144+
&& strcmp("none", opt->requested_display) != 0)
1145+
{
1146+
vidcap_params_set_device(opt->vidcap_params_tail, "testcard:2:2:1:UYVY");
1147+
opt->vidcap_params_tail = vidcap_params_allocate_next(opt->vidcap_params_tail);
1148+
}
1149+
1150+
if (strcmp("none", opt->audio.send_cfg) == 0
1151+
&& strcmp("none", opt->audio.recv_cfg) != 0)
1152+
{
1153+
set_audio_capture_format("sample_rate=5");
1154+
opt->audio.send_cfg = "testcard:frames=1";
1155+
}
1156+
1157+
punch_c.video_rx_port = &opt->video.rx_port;
1158+
punch_c.video_tx_port = &opt->video.tx_port;
1159+
punch_c.audio_rx_port = &opt->audio.recv_port;
1160+
punch_c.audio_tx_port = &opt->audio.send_port;
1161+
1162+
punch_c.host_addr = punched_host;
1163+
punch_c.host_addr_len = sizeof(punched_host);
1164+
1165+
auto punch_fcn = reinterpret_cast<bool(*)(Holepunch_config *)>(
1166+
const_cast<void *>(
1167+
load_library("udp_holepunch", LIBRARY_CLASS_UNDEFINED, HOLEPUNCH_ABI_VERSION)));
1168+
1169+
if(!punch_fcn){
1170+
log_msg(LOG_LEVEL_ERROR, "Failed to load holepunching module\n");
1171+
return EXIT_FAILURE;
1172+
}
1173+
1174+
if(!punch_fcn(&punch_c)){
1175+
log_msg(LOG_LEVEL_ERROR, "Hole punching failed.\n");
1176+
return EXIT_FAILURE;
1177+
}
1178+
1179+
log_msg(LOG_LEVEL_INFO, "[holepunch] remote: %s\n rx: %d\n tx: %d\n",
1180+
punched_host, opt->video.rx_port, opt->video.tx_port);
1181+
opt->video.receiver = punched_host;
1182+
opt->audio.host = punched_host;
1183+
return 0;
1184+
#endif //HAVE_LIBJUICE
1185+
}
1186+
11261187
static int adjust_params(struct ug_options *opt) {
11271188
unsigned int audio_rxtx_mode = 0;
11281189
if (opt->is_server) {
@@ -1179,63 +1240,12 @@ static int adjust_params(struct ug_options *opt) {
11791240
}
11801241

11811242
if(opt->nat_traverse_config && strncmp(opt->nat_traverse_config, "holepunch", strlen("holepunch")) == 0){
1182-
#ifndef HAVE_LIBJUICE
1183-
log_msg(LOG_LEVEL_ERROR, "Ultragrid was compiled without holepunch support\n");
1184-
return EXIT_FAILURE;
1185-
#else
1186-
static char punched_host[512];
1187-
Holepunch_config punch_c = {};
1188-
1189-
if(!parse_holepunch_conf(opt->nat_traverse_config, &punch_c)){
1190-
return EXIT_FAILURE;
1243+
int rc = adjust_params_holepunch(opt);
1244+
if (rc != 0) {
1245+
return rc;
11911246
}
1192-
1193-
commandline_params["udp-disable-multi-socket"] = string();
1194-
1195-
if (strcmp("none", vidcap_params_get_driver(opt->vidcap_params_head)) == 0
1196-
&& strcmp("none", opt->requested_display) != 0)
1197-
{
1198-
vidcap_params_set_device(opt->vidcap_params_tail, "testcard:2:2:1:UYVY");
1199-
opt->vidcap_params_tail = vidcap_params_allocate_next(opt->vidcap_params_tail);
1200-
}
1201-
1202-
if (strcmp("none", opt->audio.send_cfg) == 0
1203-
&& strcmp("none", opt->audio.recv_cfg) != 0)
1204-
{
1205-
set_audio_capture_format("sample_rate=5");
1206-
opt->audio.send_cfg = "testcard:frames=1";
1207-
}
1208-
1209-
punch_c.video_rx_port = &opt->video.rx_port;
1210-
punch_c.video_tx_port = &opt->video.tx_port;
1211-
punch_c.audio_rx_port = &opt->audio.recv_port;
1212-
punch_c.audio_tx_port = &opt->audio.send_port;
1213-
1214-
punch_c.host_addr = punched_host;
1215-
punch_c.host_addr_len = sizeof(punched_host);
1216-
1217-
auto punch_fcn = reinterpret_cast<bool(*)(Holepunch_config *)>(
1218-
const_cast<void *>(
1219-
load_library("udp_holepunch", LIBRARY_CLASS_UNDEFINED, HOLEPUNCH_ABI_VERSION)));
1220-
1221-
if(!punch_fcn){
1222-
log_msg(LOG_LEVEL_ERROR, "Failed to load holepunching module\n");
1223-
return EXIT_FAILURE;
1224-
}
1225-
1226-
if(!punch_fcn(&punch_c)){
1227-
log_msg(LOG_LEVEL_ERROR, "Hole punching failed.\n");
1228-
return EXIT_FAILURE;
1229-
}
1230-
1231-
log_msg(LOG_LEVEL_INFO, "[holepunch] remote: %s\n rx: %d\n tx: %d\n",
1232-
punched_host, opt->video.rx_port, opt->video.tx_port);
1233-
opt->video.receiver = punched_host;
1234-
opt->audio.host = punched_host;
1235-
#endif //HAVE_LIBJUICE
12361247
}
12371248

1238-
12391249
if (strcmp("none", opt->audio.recv_cfg) != 0) {
12401250
audio_rxtx_mode |= MODE_RECEIVER;
12411251
}

src/utils/udp_holepunch.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ struct Holepunch_config{
6868
int stun_srv_port;
6969
};
7070

71-
#ifdef HAVE_LIBJUICE
7271
bool punch_udp(struct Holepunch_config *c);
73-
#endif
7472

7573
#ifdef __cplusplus
7674
} //extern "C"

0 commit comments

Comments
 (0)