From 213748300cd611ca4e88776632d15f358d47ce89 Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Thu, 16 Jun 2022 14:30:57 +0200 Subject: [PATCH] main.cpp: use dynamic ports for UDP loopback Use dynammic ports if using both send and receive and sending over loopback. --- src/main.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index cf348f2ea..0d44a30a9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1262,6 +1262,17 @@ static int adjust_params(struct ug_options *opt) { opt->video_rxtx_mode |= MODE_SENDER; } + // use dyn ports if sending only to ourselves + const unsigned mode_both = MODE_RECEIVER | MODE_SENDER; + if (is_host_loopback(opt->requested_receiver) && ((opt->video_rxtx_mode & mode_both) == mode_both) + && (opt->video_rx_port == -1 && opt->video_tx_port == -1)) { + opt->video_rx_port = opt->video_tx_port = 0; + } + if (is_host_loopback(opt->requested_receiver) && ((audio_rxtx_mode & mode_both) == mode_both) + && (opt->audio.recv_port == -1 && opt->audio.recv_port == -1)) { + opt->audio.recv_port = opt->audio.send_port = 0; + } + if (opt->video_rx_port == -1) { if ((opt->video_rxtx_mode & MODE_RECEIVER) == 0U) { // do not occupy recv port if we are not receiving (note that this disables communication with