diff --git a/include/osmocom/mgcp/Makefile.am b/include/osmocom/mgcp/Makefile.am index 15ff01a53..2ab1d0df0 100644 --- a/include/osmocom/mgcp/Makefile.am +++ b/include/osmocom/mgcp/Makefile.am @@ -1,6 +1,7 @@ noinst_HEADERS = \ vty.h \ mgcp_msg.h \ + mgcp_codec.h \ mgcp_conn.h \ mgcp_stat.h \ mgcp_endp.h \ @@ -13,4 +14,5 @@ noinst_HEADERS = \ mgcp_network.h \ mgcp_protocol.h \ mgcp_iuup.h \ + mgcp_rtp_end.h \ $(NULL) diff --git a/include/osmocom/mgcp/mgcp_codec.h b/include/osmocom/mgcp/mgcp_codec.h index cfc8ecf06..1df805587 100644 --- a/include/osmocom/mgcp/mgcp_codec.h +++ b/include/osmocom/mgcp/mgcp_codec.h @@ -1,5 +1,9 @@ #pragma once +#include +#include +#include + #define DEFAULT_RTP_AUDIO_FRAME_DUR_NUM 20 #define DEFAULT_RTP_AUDIO_FRAME_DUR_DEN 1000 #define DEFAULT_RTP_AUDIO_PACKET_DURATION_MS 20 @@ -8,6 +12,20 @@ #define PTYPE_UNDEFINED (-1) +struct mgcp_rtp_codec { + uint32_t rate; + int channels; + uint32_t frame_duration_num; + uint32_t frame_duration_den; + + int payload_type; + char audio_name[64]; + char subtype_name[64]; + + bool param_present; + struct mgcp_codec_param param; +}; + struct mgcp_conn_rtp; void mgcp_codec_summary(struct mgcp_conn_rtp *conn); diff --git a/include/osmocom/mgcp/mgcp_conn.h b/include/osmocom/mgcp/mgcp_conn.h index 26cdffc3c..4325d46d3 100644 --- a/include/osmocom/mgcp/mgcp_conn.h +++ b/include/osmocom/mgcp/mgcp_conn.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #define LOGPCONN(conn, cat, level, fmt, args...) \ diff --git a/include/osmocom/mgcp/mgcp_network.h b/include/osmocom/mgcp/mgcp_network.h index db3dce7e5..fe35e785a 100644 --- a/include/osmocom/mgcp/mgcp_network.h +++ b/include/osmocom/mgcp/mgcp_network.h @@ -74,66 +74,6 @@ struct mgcp_rtp_state { uint32_t alt_rtp_tx_ssrc; }; -struct mgcp_rtp_codec { - uint32_t rate; - int channels; - uint32_t frame_duration_num; - uint32_t frame_duration_den; - - int payload_type; - char audio_name[64]; - char subtype_name[64]; - - bool param_present; - struct mgcp_codec_param param; -}; - -/* 'mgcp_rtp_end': basically a wrapper around the RTP+RTCP ports */ -struct mgcp_rtp_end { - /* remote IP address of the RTP socket */ - struct osmo_sockaddr addr; - - /* in network byte order */ - uint16_t rtcp_port; - - /* currently selected audio codec */ - struct mgcp_rtp_codec *codec; - - /* array with assigned audio codecs to choose from (SDP) */ - struct mgcp_rtp_codec codecs[MGCP_MAX_CODECS]; - - /* number of assigned audio codecs (SDP) */ - unsigned int codecs_assigned; - - /* per endpoint data */ - int frames_per_packet; - uint32_t packet_duration_ms; - int maximum_packet_time; /* -1: not set */ - /* are we transmitting packets (true) or dropping (false) outbound packets */ - bool output_enabled; - /* FIXME: This parameter can be set + printed, but is nowhere used! */ - int force_output_ptime; - - /* RTP patching */ - int force_constant_ssrc; /* -1: always, 0: don't, 1: once */ - /* should we perform align_rtp_timestamp_offset() (1) or not (0) */ - int force_aligned_timing; - bool rfc5993_hr_convert; - - /* Each end has a separate socket for RTP and RTCP */ - struct osmo_io_fd *rtp; - struct osmo_io_fd *rtcp; - - /* local UDP port number of the RTP socket; RTCP is +1 */ - int local_port; - /* where the endpoint RTP connection binds to, set during CRCX and - * possibly updated during MDCX */ - char local_addr[INET6_ADDRSTRLEN]; -}; - -bool mgcp_rtp_end_remote_addr_available(const struct mgcp_rtp_end *rtp_end); -void mgcp_rtp_end_free_port(struct mgcp_rtp_end *end); - struct mgcp_rtp_tap { /* is this tap active (1) or not (0) */ int enabled; diff --git a/include/osmocom/mgcp/mgcp_rtp_end.h b/include/osmocom/mgcp/mgcp_rtp_end.h new file mode 100644 index 000000000..9c3bb4d0f --- /dev/null +++ b/include/osmocom/mgcp/mgcp_rtp_end.h @@ -0,0 +1,56 @@ +#pragma once + +#include +#include + +#include +#include + +#include +#include + +/* 'mgcp_rtp_end': basically a wrapper around the RTP+RTCP ports */ +struct mgcp_rtp_end { + /* remote IP address of the RTP socket */ + struct osmo_sockaddr addr; + + /* in network byte order */ + uint16_t rtcp_port; + + /* currently selected audio codec */ + struct mgcp_rtp_codec *codec; + + /* array with assigned audio codecs to choose from (SDP) */ + struct mgcp_rtp_codec codecs[MGCP_MAX_CODECS]; + + /* number of assigned audio codecs (SDP) */ + unsigned int codecs_assigned; + + /* per endpoint data */ + int frames_per_packet; + uint32_t packet_duration_ms; + int maximum_packet_time; /* -1: not set */ + /* are we transmitting packets (true) or dropping (false) outbound packets */ + bool output_enabled; + /* FIXME: This parameter can be set + printed, but is nowhere used! */ + int force_output_ptime; + + /* RTP patching */ + int force_constant_ssrc; /* -1: always, 0: don't, 1: once */ + /* should we perform align_rtp_timestamp_offset() (1) or not (0) */ + int force_aligned_timing; + bool rfc5993_hr_convert; + + /* Each end has a separate socket for RTP and RTCP */ + struct osmo_io_fd *rtp; + struct osmo_io_fd *rtcp; + + /* local UDP port number of the RTP socket; RTCP is +1 */ + int local_port; + /* where the endpoint RTP connection binds to, set during CRCX and + * possibly updated during MDCX */ + char local_addr[INET6_ADDRSTRLEN]; +}; + +bool mgcp_rtp_end_remote_addr_available(const struct mgcp_rtp_end *rtp_end); +void mgcp_rtp_end_free_port(struct mgcp_rtp_end *end); diff --git a/src/libosmo-mgcp/Makefile.am b/src/libosmo-mgcp/Makefile.am index fa9a8eb90..c5e4bf4f7 100644 --- a/src/libosmo-mgcp/Makefile.am +++ b/src/libosmo-mgcp/Makefile.am @@ -40,6 +40,7 @@ libosmo_mgcp_a_SOURCES = \ mgcp_endp.c \ mgcp_trunk.c \ mgcp_ratectr.c \ + mgcp_rtp_end.c \ mgcp_e1.c \ mgcp_iuup.c \ $(NULL) diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c index 9a993a7e3..27cca098e 100644 --- a/src/libosmo-mgcp/mgcp_network.c +++ b/src/libosmo-mgcp/mgcp_network.c @@ -1719,28 +1719,3 @@ int mgcp_bind_net_rtp_port(struct mgcp_endpoint *endp, int rtp_port, return bind_rtp(endp->trunk->cfg, conn->end.local_addr, end, endp); } - -/*********************** - * mgcp_rtp_end - **********************/ - -bool mgcp_rtp_end_remote_addr_available(const struct mgcp_rtp_end *rtp_end) -{ - return (osmo_sockaddr_port(&rtp_end->addr.u.sa) != 0) && - (osmo_sockaddr_is_any(&rtp_end->addr) == 0); -} - -/*! free allocated RTP and RTCP ports. - * \param[in] end RTP end */ -void mgcp_rtp_end_free_port(struct mgcp_rtp_end *end) -{ - if (end->rtp) { - osmo_iofd_free(end->rtp); - end->rtp = NULL; - } - - if (end->rtcp) { - osmo_iofd_free(end->rtcp); - end->rtcp = NULL; - } -} diff --git a/src/libosmo-mgcp/mgcp_rtp_end.c b/src/libosmo-mgcp/mgcp_rtp_end.c new file mode 100644 index 000000000..ddc153307 --- /dev/null +++ b/src/libosmo-mgcp/mgcp_rtp_end.c @@ -0,0 +1,56 @@ +/* 'mgcp_rtp_end': basically a wrapper around the RTP+RTCP ports */ +/* + * (C) 2009-2012 by Holger Hans Peter Freyther + * (C) 2009-2012 by On-Waves + * (C) 2013-2024 by sysmocom - s.f.m.c. GmbH + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +#include +#include +#include +#include + +#include +#include +#include +#include + +/*********************** + * mgcp_rtp_end + **********************/ + +bool mgcp_rtp_end_remote_addr_available(const struct mgcp_rtp_end *rtp_end) +{ + return (osmo_sockaddr_port(&rtp_end->addr.u.sa) != 0) && + (osmo_sockaddr_is_any(&rtp_end->addr) == 0); +} + +/*! free allocated RTP and RTCP ports. + * \param[in] end RTP end */ +void mgcp_rtp_end_free_port(struct mgcp_rtp_end *end) +{ + if (end->rtp) { + osmo_iofd_free(end->rtp); + end->rtp = NULL; + } + + if (end->rtcp) { + osmo_iofd_free(end->rtcp); + end->rtcp = NULL; + } +}