From 9153ed8e60a908457bf629ed3d3b9753b604482f Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Wed, 18 May 2016 12:59:15 +0200 Subject: [PATCH] Control socket: extended port setting Allow to configure also src port for the sender and ports for audio. --- src/audio/audio.cpp | 5 ++- src/control_socket.cpp | 86 ++++++++++++++++++++++++++++-------------- src/messaging.h | 5 ++- src/video_rxtx/rtp.cpp | 9 +++-- 4 files changed, 72 insertions(+), 33 deletions(-) diff --git a/src/audio/audio.cpp b/src/audio/audio.cpp index fc8b33853..4a7fcd9c2 100644 --- a/src/audio/audio.cpp +++ b/src/audio/audio.cpp @@ -760,7 +760,10 @@ static struct response *audio_sender_process_message(struct state_audio *s, stru auto old_device = s->audio_network_device; auto old_port = s->audio_network_parameters.send_port; - s->audio_network_parameters.send_port = msg->port; + s->audio_network_parameters.send_port = msg->tx_port; + if (msg->rx_port) { + s->audio_network_parameters.recv_port = msg->rx_port; + } s->audio_network_device = initialize_audio_network(&s->audio_network_parameters); if (!s->audio_network_device) { diff --git a/src/control_socket.cpp b/src/control_socket.cpp index 932c5ff81..f0f06237f 100644 --- a/src/control_socket.cpp +++ b/src/control_socket.cpp @@ -1,14 +1,10 @@ +/** + * @file control_socket.cpp + * @author Martin Pulec + */ /* - * FILE: control_socket.c - * AUTHORS: Martin Benes - * Lukas Hejtmanek - * Petr Holub - * Milos Liska - * Jiri Matela - * Dalibor Matura <255899@mail.muni.cz> - * Ian Wesley-Smith - * - * Copyright (c) 2005-2010 CESNET z.s.p.o. + * Copyright (c) 2013-2016 CESNET, z. s. p. o. + * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, is permitted provided that the following conditions @@ -21,12 +17,7 @@ * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * - * This product includes software developed by CESNET z.s.p.o. - * - * 4. Neither the name of the CESNET nor the names of its contributors may be + * 3. Neither the name of CESNET nor the names of its contributors may be * used to endorse or promote products derived from this software without * specific prior written permission. * @@ -42,8 +33,8 @@ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * */ + #ifdef HAVE_CONFIG_H #include "config.h" #include "config_unix.h" @@ -333,18 +324,53 @@ static int process_msg(struct control_state *s, fd_t client_fd, char *message, s resp = new_response(RESPONSE_BAD_REQUEST, NULL); } } + } else if (prefix_matches(message, "sender-port ")) { + struct msg_sender *msg = (struct msg_sender *) + new_message(sizeof(struct msg_sender)); + struct msg_sender *msg_audio = (struct msg_sender *) + new_message(sizeof(struct msg_sender)); + char *port_str = suffix(message, "sender-port "); + + msg->type = SENDER_MSG_CHANGE_PORT; + msg_audio->type = SENDER_MSG_CHANGE_PORT; + + msg->tx_port = atoi(port_str); + if (strchr(port_str, ':')) { + char *save_ptr, *item; + item = strtok_r(port_str, ":", &save_ptr); + msg->rx_port = atoi(item); + + item = strtok_r(NULL, ":", &save_ptr); + if (item && strchr(item, ':')) { + msg_audio->tx_port = atoi(item); + item = strtok_r(NULL, ":", &save_ptr); + msg_audio->rx_port = atoi(item); + } + } + + if (msg_audio->tx_port == 0) { + msg_audio->tx_port = msg->tx_port + 2; + } + + enum module_class path_sender[] = { MODULE_CLASS_SENDER, MODULE_CLASS_NONE }; + enum module_class path_sender_audio[] = { MODULE_CLASS_AUDIO, MODULE_CLASS_SENDER, MODULE_CLASS_NONE }; + memcpy(path_audio, path, sizeof(path_audio)); + append_message_path(path, sizeof(path), path_sender); + append_message_path(path_audio, sizeof(path_audio), path_sender_audio); + + resp = + send_message(s->root_module, path, (struct message *) msg); + struct response *resp_audio = + send_message(s->root_module, path_audio, (struct message *) msg_audio); + free_response(resp_audio); } else if(prefix_matches(message, "receiver ") || prefix_matches(message, "play") || - prefix_matches(message, "pause") || prefix_matches(message, "sender-port ") || - prefix_matches(message, "reset-ssrc")) { + prefix_matches(message, "pause") || prefix_matches(message, "reset-ssrc")) { struct msg_sender *msg = (struct msg_sender *) new_message(sizeof(struct msg_sender)); if(prefix_matches(message, "receiver ")) { strncpy(msg->receiver, suffix(message, "receiver "), sizeof(msg->receiver) - 1); msg->type = SENDER_MSG_CHANGE_RECEIVER; - } else if(prefix_matches(message, "sender-port ")) { - msg->port = atoi(suffix(message, "sender-port ")); - msg->type = SENDER_MSG_CHANGE_PORT; } else if(prefix_matches(message, "play")) { msg->type = SENDER_MSG_PLAY; } else if(prefix_matches(message, "pause")) { @@ -357,9 +383,6 @@ static int process_msg(struct control_state *s, fd_t client_fd, char *message, s struct msg_sender *msg_audio = (struct msg_sender *) malloc(sizeof(struct msg_sender)); memcpy(msg_audio, msg, sizeof(struct msg_sender)); - if (msg_audio->type == SENDER_MSG_CHANGE_PORT) { - msg_audio->port = atoi(suffix(message, "sender-port ")) + 2; - } enum module_class path_sender[] = { MODULE_CLASS_SENDER, MODULE_CLASS_NONE }; enum module_class path_sender_audio[] = { MODULE_CLASS_AUDIO, MODULE_CLASS_SENDER, MODULE_CLASS_NONE }; @@ -380,9 +403,16 @@ static int process_msg(struct control_state *s, fd_t client_fd, char *message, s (struct msg_receiver *) new_message(sizeof(struct msg_receiver)); msg->type = RECEIVER_MSG_CHANGE_RX_PORT; - msg->new_rx_port = atoi(suffix(message, "receiver-port ")); - memcpy(msg_audio, msg, sizeof(struct msg_receiver)); - msg_audio->new_rx_port = atoi(suffix(message, "receiver-port ")) + 2; + msg_audio->type = RECEIVER_MSG_CHANGE_RX_PORT; + + char *port_str = suffix(message, "receiver-port "); + + msg->new_rx_port = atoi(port_str); + if (strchr(port_str, ':')) { + msg_audio->new_rx_port = atoi(strchr(port_str, ':') + 1); + } else { + msg_audio->new_rx_port = msg_audio->new_rx_port + 2; + } enum module_class path_receiver[] = { MODULE_CLASS_RECEIVER, MODULE_CLASS_NONE }; enum module_class path_audio_receiver[] = { MODULE_CLASS_AUDIO, MODULE_CLASS_RECEIVER, MODULE_CLASS_NONE }; diff --git a/src/messaging.h b/src/messaging.h index 9dd1b4714..05964c213 100644 --- a/src/messaging.h +++ b/src/messaging.h @@ -55,7 +55,10 @@ struct msg_sender { struct message m; enum msg_sender_type type; union { - int port; + struct { + int rx_port; + int tx_port; + }; char receiver[128]; char fec_cfg[1024]; }; diff --git a/src/video_rxtx/rtp.cpp b/src/video_rxtx/rtp.cpp index b2c518002..1d6a49f52 100644 --- a/src/video_rxtx/rtp.cpp +++ b/src/video_rxtx/rtp.cpp @@ -108,7 +108,10 @@ struct response *rtp_video_rxtx::process_sender_message(struct msg_sender *msg) auto old_devices = m_network_devices; auto old_port = m_send_port_number; - m_send_port_number = msg->port; + m_send_port_number = msg->tx_port; + if (msg->rx_port) { + m_recv_port_number = msg->rx_port; + } m_network_devices = initialize_network(m_requested_receiver.c_str(), m_recv_port_number, m_send_port_number, m_participants, m_ipv6, m_requested_mcast_if); @@ -117,11 +120,11 @@ struct response *rtp_video_rxtx::process_sender_message(struct msg_sender *msg) m_network_devices = old_devices; m_send_port_number = old_port; log_msg(LOG_LEVEL_ERROR, "[control] Failed to Change TX port to %d.\n", - msg->port); + msg->tx_port); return new_response(RESPONSE_INT_SERV_ERR, "Changing TX port failed!"); } else { log_msg(LOG_LEVEL_NOTICE, "[control] Changed TX port to %d.\n", - msg->port); + msg->tx_port); destroy_rtp_devices(old_devices); } }