lists.osmocom.org
Sign In Sign Up
Manage this list Sign In Sign Up

Keyboard Shortcuts

Thread View

  • j: Next unread message
  • k: Previous unread message
  • j a: Jump to all threads
  • j l: Jump to MailingList overview

gerrit-log

Thread Start a new thread
Download
Threads by month
  • ----- 2026 -----
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2025 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2024 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2023 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
  • ----- 2022 -----
  • December
  • November
  • October
  • September
  • August
  • July
  • June
  • May
  • April
  • March
  • February
  • January
gerrit-log@lists.osmocom.org

January 2025

  • 1 participants
  • 1491 discussions
[M] Change in osmo-mgw[master]: mgw: Simplify and redo code around ssrc patch feature
by pespin 14 Jan '25

14 Jan '25
pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-mgw/+/39221?usp=email ) Change subject: mgw: Simplify and redo code around ssrc patch feature ...................................................................... mgw: Simplify and redo code around ssrc patch feature The previous logic to configure SSRC patching was over complex and confusing, with even some broken logic like "patch only once", which is not really needed. Hence, simplify the internal logic to either patch SSRC always or don't do it, based on VTY configuration. The "force SSRC" feature was added in db2d431697609d473de433b7028f81ce499a02c0 and further changed in e2292f3aa1e9ae1faf5521a9cb108775f1ac0540, due to the need for nanoBTS to always keep the same SSRC on received packets. However, it makes no sense that is actually needed only once: if remote end changed several times, then we should keep patching in that case. This change allows getting rid of confusing applying of settings at a later time through mgcp_rtp_end_config(), which is no longer needed and can be dropped, simplifying steps during CRCX/MDCX/DLCX. Change-Id: Ib7216a775f4ad126e62b9e99aff381fd45015819 --- M include/osmocom/mgcp/mgcp_protocol.h M include/osmocom/mgcp/mgcp_rtp_end.h M include/osmocom/mgcp/mgcp_trunk.h M src/libosmo-mgcp/mgcp_network.c M src/libosmo-mgcp/mgcp_protocol.c M src/libosmo-mgcp/mgcp_rtp_end.c M src/libosmo-mgcp/mgcp_vty.c M tests/mgcp/mgcp_test.c 8 files changed, 15 insertions(+), 40 deletions(-) Approvals: pespin: Looks good to me, approved Jenkins Builder: Verified laforge: Looks good to me, but someone else must approve daniel: Looks good to me, but someone else must approve diff --git a/include/osmocom/mgcp/mgcp_protocol.h b/include/osmocom/mgcp/mgcp_protocol.h index ddb226b..77f17d5 100644 --- a/include/osmocom/mgcp/mgcp_protocol.h +++ b/include/osmocom/mgcp/mgcp_protocol.h @@ -26,8 +26,6 @@ struct mgcp_rtp_end; struct mgcp_endpoint; -void mgcp_rtp_end_config(struct mgcp_endpoint *endp, int expect_ssrc_change, - struct mgcp_rtp_end *rtp); uint32_t mgcp_rtp_packet_duration(const struct mgcp_endpoint *endp, const struct mgcp_rtp_end *rtp); diff --git a/include/osmocom/mgcp/mgcp_rtp_end.h b/include/osmocom/mgcp/mgcp_rtp_end.h index 02554cb..df06569 100644 --- a/include/osmocom/mgcp/mgcp_rtp_end.h +++ b/include/osmocom/mgcp/mgcp_rtp_end.h @@ -30,7 +30,7 @@ int force_output_ptime; /* RTP patching */ - int force_constant_ssrc; /* -1: always, 0: don't, 1: once */ + bool force_constant_ssrc; /* should we perform align_rtp_timestamp_offset() (1) or not (0) */ int force_aligned_timing; bool rfc5993_hr_convert; diff --git a/include/osmocom/mgcp/mgcp_trunk.h b/include/osmocom/mgcp/mgcp_trunk.h index 1679239..68d37dd 100644 --- a/include/osmocom/mgcp/mgcp_trunk.h +++ b/include/osmocom/mgcp/mgcp_trunk.h @@ -34,7 +34,7 @@ int keepalive_interval; /* RTP patching */ - int force_constant_ssrc; /* 0: don't, 1: once */ + bool force_constant_ssrc; int force_aligned_timing; bool rfc5993_hr_convert; diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c index 476e3b1..894ca2a 100644 --- a/src/libosmo-mgcp/mgcp_network.c +++ b/src/libosmo-mgcp/mgcp_network.c @@ -542,16 +542,16 @@ if (!state->initialized) { state->initialized = 1; + state->packet_duration = mgcp_rtp_packet_duration(endp, rtp_end); state->in_stream.last_seq = seq - 1; - state->in_stream.ssrc = state->patch.orig_ssrc = ssrc; + state->in_stream.ssrc = ssrc; state->in_stream.last_tsdelta = 0; - state->packet_duration = - mgcp_rtp_packet_duration(endp, rtp_end); state->out_stream.last_seq = seq - 1; - state->out_stream.ssrc = state->patch.orig_ssrc = ssrc; state->out_stream.last_tsdelta = 0; state->out_stream.last_timestamp = timestamp; state->out_stream.ssrc = ssrc - 1; /* force output SSRC change */ + state->patch.orig_ssrc = ssrc; + state->patch.patch_ssrc = rtp_end->force_constant_ssrc; LOGPENDP(endp, DRTP, LOGL_INFO, "initializing stream, SSRC: %u timestamp: %u " "pkt-duration: %d, from %s:%d\n", @@ -578,7 +578,7 @@ osmo_sockaddr_port(&addr->u.sa)); state->in_stream.ssrc = ssrc; - if (rtp_end->force_constant_ssrc) { + if (state->patch.patch_ssrc) { int16_t delta_seq; /* Always increment seqno by 1 */ @@ -594,10 +594,7 @@ adjust_rtp_timestamp_offset(endp, state, rtp_end, addr, delta_seq, timestamp, marker_bit); - state->patch.patch_ssrc = true; ssrc = state->patch.orig_ssrc; - if (rtp_end->force_constant_ssrc != -1) - rtp_end->force_constant_ssrc -= 1; LOGPENDP(endp, DRTP, LOGL_NOTICE, "SSRC patching enabled, SSRC: %u " diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c index 97eb43d..bbd38da 100644 --- a/src/libosmo-mgcp/mgcp_protocol.c +++ b/src/libosmo-mgcp/mgcp_protocol.c @@ -722,22 +722,6 @@ return 0; } -void mgcp_rtp_end_config(struct mgcp_endpoint *endp, int expect_ssrc_change, - struct mgcp_rtp_end *rtp) -{ - struct mgcp_trunk *trunk = endp->trunk; - - bool patch_ssrc = expect_ssrc_change && trunk->force_constant_ssrc; - - rtp->force_constant_ssrc = patch_ssrc ? 1 : 0; - - LOGPENDP(endp, DLMGCP, LOGL_DEBUG, - "Configuring RTP endpoint: local port %d%s%s\n", - osmo_sockaddr_port(&rtp->addr.u.sa), - rtp->force_aligned_timing ? ", force constant timing" : "", - rtp->force_constant_ssrc ? ", force constant ssrc" : ""); -} - uint32_t mgcp_rtp_packet_duration(const struct mgcp_endpoint *endp, const struct mgcp_rtp_end *rtp) { @@ -1087,8 +1071,6 @@ rc = mgcp_conn_iuup_init(conn_rtp); } - mgcp_rtp_end_config(endp, 0, &conn_rtp->end); - /* Find a local address for conn based on policy and initial SDP remote information, then find a free port for it */ if (mgcp_get_local_addr(conn_rtp->end.local_addr, conn_rtp) < 0) { @@ -1340,8 +1322,6 @@ goto error3; } - mgcp_rtp_end_config(endp, 1, &conn_rtp->end); - /* modify */ LOGPCONN(conn, DLMGCP, LOGL_DEBUG, "MDCX: modified conn:%s\n", mgcp_conn_dump(conn)); diff --git a/src/libosmo-mgcp/mgcp_rtp_end.c b/src/libosmo-mgcp/mgcp_rtp_end.c index 819a922..34614fe 100644 --- a/src/libosmo-mgcp/mgcp_rtp_end.c +++ b/src/libosmo-mgcp/mgcp_rtp_end.c @@ -55,6 +55,7 @@ end->maximum_packet_time = -1; end->force_aligned_timing = trunk->force_aligned_timing; + end->force_constant_ssrc = trunk->force_constant_ssrc; end->rfc5993_hr_convert = trunk->rfc5993_hr_convert; if (cfg->force_ptime) { diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c index e90ceaa..1d9079c 100644 --- a/src/libosmo-mgcp/mgcp_vty.c +++ b/src/libosmo-mgcp/mgcp_vty.c @@ -857,7 +857,7 @@ { struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID); OSMO_ASSERT(trunk); - trunk->force_constant_ssrc = 1; + trunk->force_constant_ssrc = true; return CMD_SUCCESS; } @@ -868,7 +868,7 @@ { struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID); OSMO_ASSERT(trunk); - trunk->force_constant_ssrc = 0; + trunk->force_constant_ssrc = false; return CMD_SUCCESS; } @@ -923,7 +923,7 @@ { struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID); OSMO_ASSERT(trunk); - trunk->force_constant_ssrc = 0; + trunk->force_constant_ssrc = false; trunk->force_aligned_timing = 0; trunk->rfc5993_hr_convert = false; return CMD_SUCCESS; @@ -1197,7 +1197,7 @@ "rtp-patch ssrc", RTP_PATCH_STR "Force a fixed SSRC\n") { struct mgcp_trunk *trunk = vty->index; - trunk->force_constant_ssrc = 1; + trunk->force_constant_ssrc = true; return CMD_SUCCESS; } @@ -1207,7 +1207,7 @@ "no rtp-patch ssrc", NO_STR RTP_PATCH_STR "Force a fixed SSRC\n") { struct mgcp_trunk *trunk = vty->index; - trunk->force_constant_ssrc = 0; + trunk->force_constant_ssrc = false; return CMD_SUCCESS; } @@ -1257,7 +1257,7 @@ "no rtp-patch", NO_STR RTP_PATCH_STR) { struct mgcp_trunk *trunk = vty->index; - trunk->force_constant_ssrc = 0; + trunk->force_constant_ssrc = false; trunk->force_aligned_timing = 0; trunk->rfc5993_hr_convert = false; return CMD_SUCCESS; @@ -1361,7 +1361,7 @@ if (conn->type == MGCP_CONN_TYPE_RTP) { /* Handle it like a MDCX, switch on SSRC patching if enabled */ struct mgcp_conn_rtp *conn_rtp = mgcp_conn_get_conn_rtp(conn); - mgcp_rtp_end_config(endp, 1, &conn_rtp->end); + conn_rtp->state.patch.patch_ssrc = true; } else { /* FIXME: Introduce support for other connection (E1) * types when implementation is available */ diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c index 9aa7326..1c1a41e 100644 --- a/tests/mgcp/mgcp_test.c +++ b/tests/mgcp/mgcp_test.c @@ -1479,7 +1479,6 @@ OSMO_ASSERT(info->len >= 0); msg->l3h = msgb_put(msg, info->len); memcpy((char*)msgb_l3(msg), info->data, info->len); - mgcp_rtp_end_config(&endp, 1, rtp); mgcp_patch_and_count(&endp, &state, rtp, &addr, msg); -- To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/39221?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-Change-Id: Ib7216a775f4ad126e62b9e99aff381fd45015819 Gerrit-Change-Number: 39221 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
1 0
0 0
[S] Change in osmo-mgw[master]: mgw: Introduce mgcp_rtp_end_init()
by pespin 14 Jan '25

14 Jan '25
pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-mgw/+/39214?usp=email ) Change subject: mgw: Introduce mgcp_rtp_end_init() ...................................................................... mgw: Introduce mgcp_rtp_end_init() Change-Id: I29f57dfde60e3134f1db422dc63e7c58d3db7d54 --- M include/osmocom/mgcp/mgcp_rtp_end.h M src/libosmo-mgcp/mgcp_conn.c M src/libosmo-mgcp/mgcp_rtp_end.c 3 files changed, 18 insertions(+), 12 deletions(-) Approvals: laforge: Looks good to me, but someone else must approve Jenkins Builder: Verified daniel: Looks good to me, approved diff --git a/include/osmocom/mgcp/mgcp_rtp_end.h b/include/osmocom/mgcp/mgcp_rtp_end.h index 9c3bb4d..2ab300a 100644 --- a/include/osmocom/mgcp/mgcp_rtp_end.h +++ b/include/osmocom/mgcp/mgcp_rtp_end.h @@ -52,5 +52,6 @@ char local_addr[INET6_ADDRSTRLEN]; }; +void mgcp_rtp_end_init(struct mgcp_rtp_end *end); 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/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c index e7ff30b..8682e4b 100644 --- a/src/libosmo-mgcp/mgcp_conn.c +++ b/src/libosmo-mgcp/mgcp_conn.c @@ -88,7 +88,6 @@ /* Initialize rtp connection struct with default values */ static int mgcp_rtp_conn_init(struct mgcp_conn_rtp *conn_rtp, struct mgcp_conn *conn) { - struct mgcp_rtp_end *end = &conn_rtp->end; /* FIXME: Each new rate counter group requires an unique index. At the * moment we generate this index using this counter, but perhaps there * is a more concious way to assign the indexes. */ @@ -106,17 +105,6 @@ /* backpointer to the generic part of the connection */ conn->u.rtp.conn = conn; - end->rtp = NULL; - end->rtcp = NULL; - memset(&end->addr, 0, sizeof(end->addr)); - end->rtcp_port = 0; - - /* Set default values */ - end->frames_per_packet = 0; /* unknown */ - end->packet_duration_ms = DEFAULT_RTP_AUDIO_PACKET_DURATION_MS; - end->output_enabled = false; - end->maximum_packet_time = -1; - conn_rtp->ctrg = rate_ctr_group_alloc(conn, &rate_ctr_group_desc, rate_ctr_index++); if (!conn_rtp->ctrg) return -1; @@ -124,6 +112,8 @@ conn_rtp->state.in_stream.err_ts_ctr = rate_ctr_group_get_ctr(conn_rtp->ctrg, IN_STREAM_ERR_TSTMP_CTR); conn_rtp->state.out_stream.err_ts_ctr = rate_ctr_group_get_ctr(conn_rtp->ctrg, OUT_STREAM_ERR_TSTMP_CTR); + mgcp_rtp_end_init(&conn_rtp->end); + /* Make sure codec table is reset */ mgcp_codec_reset_all(conn_rtp); diff --git a/src/libosmo-mgcp/mgcp_rtp_end.c b/src/libosmo-mgcp/mgcp_rtp_end.c index ddc1533..422c199 100644 --- a/src/libosmo-mgcp/mgcp_rtp_end.c +++ b/src/libosmo-mgcp/mgcp_rtp_end.c @@ -29,11 +29,26 @@ #include <osmocom/core/socket.h> #include <osmocom/core/osmo_io.h> #include <osmocom/mgcp/mgcp_rtp_end.h> +#include <osmocom/mgcp/mgcp_codec.h> /*********************** * mgcp_rtp_end **********************/ +void mgcp_rtp_end_init(struct mgcp_rtp_end *end) +{ + end->rtp = NULL; + end->rtcp = NULL; + memset(&end->addr, 0, sizeof(end->addr)); + end->rtcp_port = 0; + + /* Set default values */ + end->frames_per_packet = 0; /* unknown */ + end->packet_duration_ms = DEFAULT_RTP_AUDIO_PACKET_DURATION_MS; + end->output_enabled = false; + end->maximum_packet_time = -1; +} + bool mgcp_rtp_end_remote_addr_available(const struct mgcp_rtp_end *rtp_end) { return (osmo_sockaddr_port(&rtp_end->addr.u.sa) != 0) && -- To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/39214?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-Change-Id: I29f57dfde60e3134f1db422dc63e7c58d3db7d54 Gerrit-Change-Number: 39214 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
1 0
0 0
[M] Change in osmo-mgw[master]: mgw: Split mgcp_rtp_end to its own file
by pespin 14 Jan '25

14 Jan '25
pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-mgw/+/39213?usp=email ) Change subject: mgw: Split mgcp_rtp_end to its own file ...................................................................... mgw: Split mgcp_rtp_end to its own file Preparation path to add an init function and start untangling related code. While at it, move definition of struct mgcp_rtp_codec to the mgcp_codec.h where it belongs. Change-Id: Id1b6cab57e44ad4859bde8212d0ac9f7146d7198 --- M include/osmocom/mgcp/Makefile.am M include/osmocom/mgcp/mgcp_codec.h M include/osmocom/mgcp/mgcp_conn.h M include/osmocom/mgcp/mgcp_network.h A include/osmocom/mgcp/mgcp_rtp_end.h M src/libosmo-mgcp/Makefile.am M src/libosmo-mgcp/mgcp_network.c A src/libosmo-mgcp/mgcp_rtp_end.c 8 files changed, 134 insertions(+), 85 deletions(-) Approvals: daniel: Looks good to me, approved laforge: Looks good to me, but someone else must approve Jenkins Builder: Verified diff --git a/include/osmocom/mgcp/Makefile.am b/include/osmocom/mgcp/Makefile.am index 15ff01a..2ab1d0d 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 @@ 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 cfc8ecf..1df8055 100644 --- a/include/osmocom/mgcp/mgcp_codec.h +++ b/include/osmocom/mgcp/mgcp_codec.h @@ -1,5 +1,9 @@ #pragma once +#include <stdint.h> +#include <stdbool.h> +#include <osmocom/mgcp/mgcp_common.h> + #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 26cdffc..4325d46 100644 --- a/include/osmocom/mgcp/mgcp_conn.h +++ b/include/osmocom/mgcp/mgcp_conn.h @@ -31,6 +31,7 @@ #include <osmocom/core/rate_ctr.h> #include <osmocom/core/utils.h> #include <osmocom/gsm/iuup.h> +#include <osmocom/mgcp/mgcp_rtp_end.h> #include <inttypes.h> #define LOGPCONN(conn, cat, level, fmt, args...) \ diff --git a/include/osmocom/mgcp/mgcp_network.h b/include/osmocom/mgcp/mgcp_network.h index db3dce7..fe35e78 100644 --- a/include/osmocom/mgcp/mgcp_network.h +++ b/include/osmocom/mgcp/mgcp_network.h @@ -74,66 +74,6 @@ 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 0000000..9c3bb4d --- /dev/null +++ b/include/osmocom/mgcp/mgcp_rtp_end.h @@ -0,0 +1,56 @@ +#pragma once + +#include <inttypes.h> +#include <stdbool.h> + +#include <osmocom/core/socket.h> +#include <osmocom/core/osmo_io.h> + +#include <osmocom/mgcp/mgcp.h> +#include <osmocom/mgcp/mgcp_codec.h> + +/* '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 fa9a8eb..c5e4bf4 100644 --- a/src/libosmo-mgcp/Makefile.am +++ b/src/libosmo-mgcp/Makefile.am @@ -40,6 +40,7 @@ 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 9a993a7..27cca09 100644 --- a/src/libosmo-mgcp/mgcp_network.c +++ b/src/libosmo-mgcp/mgcp_network.c @@ -1719,28 +1719,3 @@ 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 0000000..ddc1533 --- /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 <zecke(a)selfish.org> + * (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 <http://www.gnu.org/licenses/>. + * + */ + +#include <string.h> +#include <stdlib.h> +#include <stdbool.h> +#include <unistd.h> + +#include <osmocom/core/select.h> +#include <osmocom/core/socket.h> +#include <osmocom/core/osmo_io.h> +#include <osmocom/mgcp/mgcp_rtp_end.h> + +/*********************** + * 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; + } +} -- To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/39213?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-Change-Id: Id1b6cab57e44ad4859bde8212d0ac9f7146d7198 Gerrit-Change-Number: 39213 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: neels <nhofmeyr(a)sysmocom.de> Gerrit-Reviewer: osmith <osmith(a)sysmocom.de> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
1 0
0 0
[L] Change in osmo-mgw[master]: mgw: Introduce struct mgcp_codecset struct
by pespin 14 Jan '25

14 Jan '25
pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-mgw/+/39215?usp=email ) Change subject: mgw: Introduce struct mgcp_codecset struct ...................................................................... mgw: Introduce struct mgcp_codecset struct We do tons of operations on 3 fields (array of codecs, len of array, selected code) which can be isolated. Right now, we are using APIs which somehow require structs 2-3 levels of encapsulation above the ones really required, which makes all code totally entangled, difficult to understand and prone to errors when changing stuff in deeply nested structs. A prove of this is how this patch affects a lot of lines in lots of places. Change-Id: Id7db7ab01d56b7fa2415123b604375e48c82ab25 --- M include/osmocom/mgcp/mgcp_codec.h M include/osmocom/mgcp/mgcp_rtp_end.h M src/libosmo-mgcp/mgcp_codec.c M src/libosmo-mgcp/mgcp_conn.c M src/libosmo-mgcp/mgcp_e1.c M src/libosmo-mgcp/mgcp_iuup.c M src/libosmo-mgcp/mgcp_network.c M src/libosmo-mgcp/mgcp_osmux.c M src/libosmo-mgcp/mgcp_protocol.c M src/libosmo-mgcp/mgcp_sdp.c M src/libosmo-mgcp/mgcp_vty.c M tests/mgcp/mgcp_test.c 12 files changed, 171 insertions(+), 169 deletions(-) Approvals: Jenkins Builder: Verified daniel: Looks good to me, approved laforge: Looks good to me, but someone else must approve diff --git a/include/osmocom/mgcp/mgcp_codec.h b/include/osmocom/mgcp/mgcp_codec.h index 1df8055..0d99fdf 100644 --- a/include/osmocom/mgcp/mgcp_codec.h +++ b/include/osmocom/mgcp/mgcp_codec.h @@ -26,14 +26,23 @@ struct mgcp_codec_param param; }; -struct mgcp_conn_rtp; - -void mgcp_codec_summary(struct mgcp_conn_rtp *conn); -void mgcp_codec_reset_all(struct mgcp_conn_rtp *conn); -int mgcp_codec_add(struct mgcp_conn_rtp *conn, int payload_type, const char *audio_name, const struct mgcp_codec_param *param); -int mgcp_codec_decide(struct mgcp_conn_rtp *conn_src, struct mgcp_conn_rtp *conn_dst); -const struct mgcp_rtp_codec *mgcp_codec_pt_find_by_subtype_name(struct mgcp_conn_rtp *conn, - const char *subtype_name, unsigned int match_nr); bool mgcp_codec_amr_align_mode_is_indicated(const struct mgcp_rtp_codec *codec); bool mgcp_codec_amr_is_octet_aligned(const struct mgcp_rtp_codec *codec); -struct mgcp_rtp_codec *mgcp_codec_from_pt(struct mgcp_conn_rtp *conn, int payload_type); + +struct mgcp_rtp_codecset { + /* 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; +}; + +void mgcp_codecset_reset(struct mgcp_rtp_codecset *cset); +void mgcp_codecset_summary(struct mgcp_rtp_codecset *cset, const char *prefix_str); +int mgcp_codecset_add_codec(struct mgcp_rtp_codecset *cset, int payload_type, + const char *audio_name, const struct mgcp_codec_param *param); +int mgcp_codecset_decide(struct mgcp_rtp_codecset *cset_src, struct mgcp_rtp_codecset *cset_dst); +const struct mgcp_rtp_codec *mgcp_codecset_pt_find_by_subtype_name(const struct mgcp_rtp_codecset *cset, + const char *subtype_name, unsigned int match_nr); +struct mgcp_rtp_codec *mgcp_codecset_find_codec_from_pt(struct mgcp_rtp_codecset *cset, int payload_type); diff --git a/include/osmocom/mgcp/mgcp_rtp_end.h b/include/osmocom/mgcp/mgcp_rtp_end.h index 2ab300a..69208e5 100644 --- a/include/osmocom/mgcp/mgcp_rtp_end.h +++ b/include/osmocom/mgcp/mgcp_rtp_end.h @@ -17,14 +17,7 @@ /* 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; + struct mgcp_rtp_codecset cset; /* per endpoint data */ int frames_per_packet; diff --git a/src/libosmo-mgcp/mgcp_codec.c b/src/libosmo-mgcp/mgcp_codec.c index 2f1df7b..0a57667 100644 --- a/src/libosmo-mgcp/mgcp_codec.c +++ b/src/libosmo-mgcp/mgcp_codec.c @@ -28,7 +28,7 @@ /* Helper function to dump codec information of a specified codec to a printable * string, used by dump_codec_summary() */ -static char *dump_codec(struct mgcp_rtp_codec *codec) +static char *mgcp_codec_dump(struct mgcp_rtp_codec *codec) { static char str[256]; char *pt_str; @@ -49,31 +49,25 @@ } /*! Dump a summary of all negotiated codecs to debug log - * \param[in] conn related rtp-connection. */ -void mgcp_codec_summary(struct mgcp_conn_rtp *conn) + * \param[in] cset related codecset. + * \param[in] prefix_str Prefix string to print during logging. + * */ +void mgcp_codecset_summary(struct mgcp_rtp_codecset *cset, const char *prefix_str) { - struct mgcp_rtp_end *rtp; unsigned int i; - struct mgcp_rtp_codec *codec; - struct mgcp_endpoint *endp; - rtp = &conn->end; - endp = conn->conn->endp; - - if (rtp->codecs_assigned == 0) { - LOGPENDP(endp, DLMGCP, LOGL_ERROR, "conn:%s no codecs available\n", - mgcp_conn_dump(conn->conn)); + if (cset->codecs_assigned == 0) { + LOGP(DLMGCP, LOGL_ERROR, "%s no codecs available\n", prefix_str); return; } /* Store parsed codec information */ - for (i = 0; i < rtp->codecs_assigned; i++) { - codec = &rtp->codecs[i]; + for (i = 0; i < cset->codecs_assigned; i++) { + struct mgcp_rtp_codec *codec = &cset->codecs[i]; - LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "conn:%s codecs[%u]:%s", - mgcp_conn_dump(conn->conn), i, dump_codec(codec)); + LOGP(DLMGCP, LOGL_DEBUG, "%s codecs[%u]:%s", prefix_str, i, mgcp_codec_dump(codec)); - if (codec == rtp->codec) + if (codec == cset->codec) LOGPC(DLMGCP, LOGL_DEBUG, " [selected]"); LOGPC(DLMGCP, LOGL_DEBUG, "\n"); @@ -81,7 +75,7 @@ } /* Initalize or reset codec information with default data. */ -static void codec_init(struct mgcp_rtp_codec *codec) +static void mgcp_codec_init(struct mgcp_rtp_codec *codec) { *codec = (struct mgcp_rtp_codec){ .payload_type = -1, @@ -94,20 +88,20 @@ }; } -static void codec_free(struct mgcp_rtp_codec *codec) +static void mgcp_codec_free(struct mgcp_rtp_codec *codec) { *codec = (struct mgcp_rtp_codec){}; } /*! Initalize or reset codec information with default data. * \param[out] conn related rtp-connection. */ -void mgcp_codec_reset_all(struct mgcp_conn_rtp *conn) +void mgcp_codecset_reset(struct mgcp_rtp_codecset *cset) { int i; - for (i = 0; i < conn->end.codecs_assigned; i++) - codec_free(&conn->end.codecs[i]); - conn->end.codecs_assigned = 0; - conn->end.codec = NULL; + for (i = 0; i < cset->codecs_assigned; i++) + mgcp_codec_free(&cset->codecs[i]); + cset->codecs_assigned = 0; + cset->codec = NULL; } /*! Add codec configuration depending on payload type and/or codec name. This @@ -118,23 +112,23 @@ * \param[in] audio_name audio codec name, in uppercase (e.g. "GSM/8000/1"). * \param[in] param optional codec parameters (set to NULL when unused). * \returns 0 on success, -EINVAL on failure. */ -int mgcp_codec_add(struct mgcp_conn_rtp *conn, int payload_type, const char *audio_name, const struct mgcp_codec_param *param) +int mgcp_codecset_add_codec(struct mgcp_rtp_codecset *cset, int payload_type, const char *audio_name, const struct mgcp_codec_param *param) { int rate; int channels; struct mgcp_rtp_codec *codec; - unsigned int pt_offset = conn->end.codecs_assigned; + unsigned int pt_offset = cset->codecs_assigned; /* The amount of codecs we can store is limited, make sure we do not * overrun this limit. */ - if (conn->end.codecs_assigned >= MGCP_MAX_CODECS) + if (cset->codecs_assigned >= MGCP_MAX_CODECS) return -EINVAL; /* First unused entry */ - codec = &conn->end.codecs[conn->end.codecs_assigned]; + codec = &cset->codecs[cset->codecs_assigned]; /* Initalize the codec struct with some default data to begin with */ - codec_init(codec); + mgcp_codec_init(codec); if (payload_type != PTYPE_UNDEFINED) { /* Make sure we do not get any reserved or undefined type numbers */ @@ -268,11 +262,11 @@ } else codec->param_present = false; - conn->end.codecs_assigned++; + cset->codecs_assigned++; return 0; error: /* Make sure we leave a clean codec entry on error. */ - codec_free(codec); + mgcp_codec_free(codec); return -EINVAL; } @@ -296,7 +290,7 @@ } /* Compare two codecs, all parameters must match up */ -static bool codecs_same(struct mgcp_rtp_codec *codec_a, struct mgcp_rtp_codec *codec_b) +static bool codecs_same(const struct mgcp_rtp_codec *codec_a, const struct mgcp_rtp_codec *codec_b) { /* All codec properties must match up, except the payload type number. Even though standardisd payload numbers * exist for certain situations, the call agent may still assign them freely. Hence we must not insist on equal @@ -325,7 +319,7 @@ } /* Compare two codecs, all parameters must match up, except parameters related to payload formatting (not checked). */ -static bool codecs_convertible(struct mgcp_rtp_codec *codec_a, struct mgcp_rtp_codec *codec_b) +static bool codecs_convertible(const struct mgcp_rtp_codec *codec_a, const struct mgcp_rtp_codec *codec_b) { /* OsmoMGW currently has no ability to transcode from one codec to another. However OsmoMGW is still able to * translate between different payload formats as long as the encoded voice data itself does not change. @@ -354,21 +348,18 @@ return true; } -struct mgcp_rtp_codec *mgcp_codec_find_same(struct mgcp_conn_rtp *conn, struct mgcp_rtp_codec *codec) +struct mgcp_rtp_codec *mgcp_codecset_find_same(struct mgcp_rtp_codecset *cset, const struct mgcp_rtp_codec *codec) { - struct mgcp_rtp_end *rtp_end; unsigned int i; unsigned int codecs_assigned; - rtp_end = &conn->end; - /* Use the codec information from the source and try to find the equivalent of it on the destination side. In * the first run we will look for an exact match. */ - codecs_assigned = rtp_end->codecs_assigned; + codecs_assigned = cset->codecs_assigned; OSMO_ASSERT(codecs_assigned <= MGCP_MAX_CODECS); for (i = 0; i < codecs_assigned; i++) { - if (codecs_same(codec, &rtp_end->codecs[i])) { - return &rtp_end->codecs[i]; + if (codecs_same(codec, &cset->codecs[i])) { + return &cset->codecs[i]; break; } } @@ -377,28 +368,26 @@ } /* For a given codec, find a convertible codec in the given connection. */ -static struct mgcp_rtp_codec *codec_find_convertible(struct mgcp_conn_rtp *conn, struct mgcp_rtp_codec *codec) +static struct mgcp_rtp_codec *codecset_find_convertible(struct mgcp_rtp_codecset *cset, const struct mgcp_rtp_codec *codec) { - struct mgcp_rtp_end *rtp_end; unsigned int i; unsigned int codecs_assigned; struct mgcp_rtp_codec *codec_convertible = NULL; - rtp_end = &conn->end; /* Use the codec information from the source and try to find the equivalent of it on the destination side. In * the first run we will look for an exact match. */ - codec_convertible = mgcp_codec_find_same(conn, codec); + codec_convertible = mgcp_codecset_find_same(cset, codec); if (codec_convertible) return codec_convertible; /* In case we weren't able to find an exact match, we will try to find a match that is the same codec, but the * payload format may be different. This alternative will require a frame format conversion (i.e. AMR bwe->oe) */ - codecs_assigned = rtp_end->codecs_assigned; + codecs_assigned = cset->codecs_assigned; OSMO_ASSERT(codecs_assigned <= MGCP_MAX_CODECS); for (i = 0; i < codecs_assigned; i++) { - if (codecs_convertible(codec, &rtp_end->codecs[i])) { - codec_convertible = &rtp_end->codecs[i]; + if (codecs_convertible(codec, &cset->codecs[i])) { + codec_convertible = &cset->codecs[i]; break; } } @@ -408,20 +397,20 @@ /*! Decide for one suitable codec on both of the given connections. In case a destination connection is not available, * a tentative decision is made. - * \param[inout] conn_src related rtp-connection. - * \param[inout] conn_dst related destination rtp-connection (NULL if not present). + * \param[in] cset_src related codec set. + * \param[inout] cset_dst related destination codec set (NULL if not present). * \returns 0 on success, -EINVAL on failure. */ -int mgcp_codec_decide(struct mgcp_conn_rtp *conn_src, struct mgcp_conn_rtp *conn_dst) +int mgcp_codecset_decide(struct mgcp_rtp_codecset *cset_src, struct mgcp_rtp_codecset *cset_dst) { unsigned int i; /* In case no destination connection is available (yet), or in case the destination connection exists but has * no codecs assigned, we are forced to make a simple tentative decision: * We just use the first codec of the source connection (conn_src) */ - OSMO_ASSERT(conn_src->end.codecs_assigned <= MGCP_MAX_CODECS); - if (!conn_dst || conn_dst->end.codecs_assigned == 0) { - if (conn_src->end.codecs_assigned >= 1) { - conn_src->end.codec = &conn_src->end.codecs[0]; + OSMO_ASSERT(cset_src->codecs_assigned <= MGCP_MAX_CODECS); + if (!cset_dst || cset_dst->codecs_assigned == 0) { + if (cset_src->codecs_assigned >= 1) { + cset_src->codec = &cset_src->codecs[0]; return 0; } else return -EINVAL; @@ -430,38 +419,38 @@ /* Compare all codecs of the source connection (conn_src) to the codecs of the destination connection (conn_dst). In case * of a match set this codec on both connections. This would be an ideal selection since no codec conversion would be * required. */ - for (i = 0; i < conn_src->end.codecs_assigned; i++) { - struct mgcp_rtp_codec *codec_conn_src = &conn_src->end.codecs[i]; - struct mgcp_rtp_codec *codec_conn_dst = mgcp_codec_find_same(conn_dst, codec_conn_src); - if (codec_conn_dst) { + for (i = 0; i < cset_src->codecs_assigned; i++) { + struct mgcp_rtp_codec *codec_cset_src = &cset_src->codecs[i]; + struct mgcp_rtp_codec *codec_cset_dst = mgcp_codecset_find_same(cset_dst, codec_cset_src); + if (codec_cset_dst) { /* We found the a codec that is exactly the same (same codec, same payload format etc.) on both * sides. We now set this codec on both connections. */ - conn_dst->end.codec = codec_conn_dst; - conn_src->end.codec = codec_conn_src; + cset_dst->codec = codec_cset_dst; + cset_src->codec = codec_cset_src; return 0; } } /* In case we could not find a codec that is exactly the same, let's at least try to find a codec that we are able * to convert. */ - for (i = 0; i < conn_src->end.codecs_assigned; i++) { - struct mgcp_rtp_codec *codec_conn_src = &conn_src->end.codecs[i]; - struct mgcp_rtp_codec *codec_conn_dst = codec_find_convertible(conn_dst, codec_conn_src); - if (codec_conn_dst) { + for (i = 0; i < cset_src->codecs_assigned; i++) { + struct mgcp_rtp_codec *codec_cset_src = &cset_src->codecs[i]; + struct mgcp_rtp_codec *codec_cset_dst = codecset_find_convertible(cset_dst, codec_cset_src); + if (codec_cset_dst) { /* We found the a codec that we can convert to. Set each side to its codec. */ - conn_dst->end.codec = codec_conn_dst; - conn_src->end.codec = codec_conn_src; + cset_dst->codec = codec_cset_dst; + cset_src->codec = codec_cset_src; return 0; } } - if (conn_dst->end.codecs_assigned) - conn_dst->end.codec = &conn_dst->end.codecs[0]; + if (cset_dst->codecs_assigned) + cset_dst->codec = &cset_dst->codecs[0]; else return -EINVAL; - if (conn_src->end.codecs_assigned) - conn_src->end.codec = &conn_src->end.codecs[0]; + if (cset_src->codecs_assigned) + cset_src->codec = &cset_src->codecs[0]; else return -EINVAL; @@ -488,38 +477,36 @@ * \param match_nr Index for the match found, first being match_nr == 0. Iterate all matches by calling multiple times * with incrementing match_nr. * \return codec definition for that conn matching the subtype_name, or NULL if no such match_nr is found. */ -const struct mgcp_rtp_codec *mgcp_codec_pt_find_by_subtype_name(struct mgcp_conn_rtp *conn, +const struct mgcp_rtp_codec *mgcp_codecset_pt_find_by_subtype_name(const struct mgcp_rtp_codecset *cset, const char *subtype_name, unsigned int match_nr) { int i; - for (i = 0; i < conn->end.codecs_assigned; i++) { - if (!strcmp(conn->end.codecs[i].subtype_name, subtype_name)) { + for (i = 0; i < cset->codecs_assigned; i++) { + if (!strcmp(cset->codecs[i].subtype_name, subtype_name)) { if (match_nr) { match_nr--; continue; } - return &conn->end.codecs[i]; + return &cset->codecs[i]; } } return NULL; } /*! Lookup a codec that is assigned to a connection by its payload type number. - * \param[in] conn related rtp-connection. + * \param[in] cset related codec set. * \param[in] payload_type number of the codec to look up. * \returns pointer to codec struct on success, NULL on failure. */ -struct mgcp_rtp_codec *mgcp_codec_from_pt(struct mgcp_conn_rtp *conn, int payload_type) +struct mgcp_rtp_codec *mgcp_codecset_find_codec_from_pt(struct mgcp_rtp_codecset *cset, int payload_type) { - struct mgcp_rtp_end *rtp_end = &conn->end; - unsigned int codecs_assigned = rtp_end->codecs_assigned; struct mgcp_rtp_codec *codec = NULL; size_t i; - OSMO_ASSERT(codecs_assigned <= MGCP_MAX_CODECS); + OSMO_ASSERT(cset->codecs_assigned <= MGCP_MAX_CODECS); - for (i = 0; i < codecs_assigned; i++) { - if (payload_type == rtp_end->codecs[i].payload_type) { - codec = &rtp_end->codecs[i]; + for (i = 0; i < cset->codecs_assigned; i++) { + if (payload_type == cset->codecs[i].payload_type) { + codec = &cset->codecs[i]; break; } } diff --git a/src/libosmo-mgcp/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c index 8682e4b..68b6b39 100644 --- a/src/libosmo-mgcp/mgcp_conn.c +++ b/src/libosmo-mgcp/mgcp_conn.c @@ -115,7 +115,7 @@ mgcp_rtp_end_init(&conn_rtp->end); /* Make sure codec table is reset */ - mgcp_codec_reset_all(conn_rtp); + mgcp_codecset_reset(&conn_rtp->end.cset); return 0; } @@ -129,7 +129,7 @@ mgcp_conn_iuup_cleanup(conn_rtp); mgcp_rtp_end_free_port(&conn_rtp->end); rate_ctr_group_free(conn_rtp->ctrg); - mgcp_codec_reset_all(conn_rtp); + mgcp_codecset_reset(&conn_rtp->end.cset); } void mgcp_conn_watchdog_cb(void *data) diff --git a/src/libosmo-mgcp/mgcp_e1.c b/src/libosmo-mgcp/mgcp_e1.c index 428d652..8a64157 100644 --- a/src/libosmo-mgcp/mgcp_e1.c +++ b/src/libosmo-mgcp/mgcp_e1.c @@ -660,7 +660,7 @@ conn = mgcp_endp_get_conn_oldest(endp); OSMO_ASSERT(conn); conn_rtp = mgcp_conn_get_conn_rtp(conn); - codec = conn_rtp->end.codec; + codec = conn_rtp->end.cset.codec; OSMO_ASSERT(codec); /* Update codec information */ diff --git a/src/libosmo-mgcp/mgcp_iuup.c b/src/libosmo-mgcp/mgcp_iuup.c index a284070..468ea06 100644 --- a/src/libosmo-mgcp/mgcp_iuup.c +++ b/src/libosmo-mgcp/mgcp_iuup.c @@ -264,6 +264,7 @@ uint8_t *amr_data; struct rtp_hdr *rtp_hdr; struct amr_hdr *amr_hdr; + struct mgcp_rtp_codec *dst_codec; int rc; ft = osmo_amr_bytes_to_ft(msgb_l3len(msg)); @@ -275,7 +276,8 @@ } msgb_pull_to_l3(msg); - if (mgcp_codec_amr_is_octet_aligned(conn_rtp_dst->end.codec)) { + dst_codec = conn_rtp_dst->end.cset.codec; + if (mgcp_codec_amr_is_octet_aligned(dst_codec)) { LOGP(DLMGCP, LOGL_DEBUG, "Convert IuUP -> AMR OA: ft %d, len %d\n", ft, msgb_length(msg)); amr_hdr = (struct amr_hdr *) msgb_push(msg, sizeof(struct amr_hdr)); amr_hdr->cmr = 15; /* no change */ @@ -303,7 +305,7 @@ .extension = 0, .padding = 0, .version = 0, - .payload_type = conn_rtp_dst->end.codec->payload_type, + .payload_type = dst_codec->payload_type, .marker = 0, .sequence = frame_nr, .timestamp = 0, @@ -502,7 +504,7 @@ * ignored by the receiver, but still it's useful for debug purposes * to set it. Moreover, it seems ip.access nano3g produces much worse * audio output on the air side if timestamp is not set properly. */ - hdr->timestamp = osmo_htonl(mgcp_get_current_ts(rtp_end->codec->rate)); + hdr->timestamp = osmo_htonl(mgcp_get_current_ts(rtp_end->cset.codec->rate)); hdr->sequence = osmo_htons(rtp_state->alt_rtp_tx_sequence); hdr->ssrc = rtp_state->alt_rtp_tx_ssrc; rtp_state->alt_rtp_tx_sequence++; @@ -550,7 +552,7 @@ .extension = 0, .padding = 0, .version = 2, - .payload_type = conn_rtp_dst->end.codec->payload_type, + .payload_type = conn_rtp_dst->end.cset.codec->payload_type, .marker = 0, .sequence = 0, .timestamp = 0, @@ -645,6 +647,7 @@ struct rtp_hdr *rtph; int rc = -1; int iuup_length = 0; + struct mgcp_rtp_codec *src_codec; int8_t rfci; /* Tx RNL-DATA.req */ @@ -657,13 +660,14 @@ /* TODO: CMR handling & multiple frames handling */ - if (strcmp(conn_src_rtp->end.codec->subtype_name, "AMR") != 0) { + src_codec = conn_src_rtp->end.cset.codec; + if (strcmp(src_codec->subtype_name, "AMR") != 0) { LOG_CONN_RTP(conn_src_rtp, LOGL_ERROR, "Bridge RTP=>IuUP: Bridging src codec %s to IuUP AMR not supported\n", - conn_src_rtp->end.codec->subtype_name); + src_codec->subtype_name); goto free_ret; } - if (mgcp_codec_amr_is_octet_aligned(conn_src_rtp->end.codec)) { + if (mgcp_codec_amr_is_octet_aligned(src_codec)) { struct amr_hdr *amr_hdr = (struct amr_hdr *) msgb_data(msg); if (msgb_length(msg) < (sizeof(*amr_hdr))) { LOG_CONN_RTP(conn_src_rtp, LOGL_NOTICE, diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c index 27cca09..476e3b1 100644 --- a/src/libosmo-mgcp/mgcp_network.c +++ b/src/libosmo-mgcp/mgcp_network.c @@ -332,7 +332,7 @@ osmo_sockaddr_ntop(&addr->u.sa, ipbuf), osmo_sockaddr_port(&addr->u.sa)); } else { - tsdelta = rtp_end->codec->rate * 20 / 1000; + tsdelta = rtp_end->cset.codec->rate * 20 / 1000; LOGPENDP(endp, DRTP, LOGL_NOTICE, "Fixed packet duration and last timestamp delta " "are not available, " @@ -496,11 +496,11 @@ } rtp_hdr = (struct rtp_hdr *)msgb_data(msg); - if (!conn_dst->end.codec) { + if (!conn_dst->end.cset.codec) { LOG_CONN_RTP(conn_dst, LOGL_NOTICE, "no codec set on destination connection!\n"); return -EINVAL; } - rtp_hdr->payload_type = (uint8_t) conn_dst->end.codec->payload_type; + rtp_hdr->payload_type = (uint8_t) conn_dst->end.cset.codec->payload_type; return 0; } @@ -523,7 +523,8 @@ uint32_t timestamp, ssrc; bool marker_bit; struct rtp_hdr *rtp_hdr; - int payload = rtp_end->codec->payload_type; + struct mgcp_rtp_codec *codec = rtp_end->cset.codec; + int payload = codec->payload_type; unsigned int len = msgb_length(msg); if (len < sizeof(*rtp_hdr)) @@ -532,7 +533,7 @@ rtp_hdr = (struct rtp_hdr *)msgb_data(msg); seq = ntohs(rtp_hdr->sequence); timestamp = ntohl(rtp_hdr->timestamp); - arrival_time = mgcp_get_current_ts(rtp_end->codec->rate); + arrival_time = mgcp_get_current_ts(codec->rate); ssrc = ntohl(rtp_hdr->ssrc); marker_bit = !!rtp_hdr->marker; transit = arrival_time - timestamp; @@ -560,7 +561,7 @@ osmo_sockaddr_port(&addr->u.sa)); if (state->packet_duration == 0) { state->packet_duration = - rtp_end->codec->rate * 20 / 1000; + codec->rate * 20 / 1000; LOGPENDP(endp, DRTP, LOGL_NOTICE, "fixed packet duration is not available, " "using fixed 20ms instead: %d from %s:%d\n", @@ -816,8 +817,8 @@ return; hdr->version = 2; - hdr->payload_type = rtp_end->codec->payload_type; - hdr->timestamp = osmo_htonl(mgcp_get_current_ts(rtp_end->codec->rate)); + hdr->payload_type = rtp_end->cset.codec->payload_type; + hdr->timestamp = osmo_htonl(mgcp_get_current_ts(rtp_end->cset.codec->rate)); hdr->sequence = osmo_htons(state->alt_rtp_tx_sequence); hdr->ssrc = state->alt_rtp_tx_ssrc; } @@ -1183,6 +1184,8 @@ osmo_sockaddr_port(&rtp_end->addr.u.sa), ntohs(rtp_end->rtcp_port) ); } else if (is_rtp) { + struct mgcp_rtp_codec *src_codec; + struct mgcp_rtp_codec *dst_codec; /* Make sure we have a valid RTP header, in cases where no RTP * header is present, we will generate one. */ gen_rtp_header(msg, rtp_end, rtp_state); @@ -1198,19 +1201,21 @@ if (addr) mgcp_patch_and_count(endp, rtp_state, rtp_end, addr, msg); + src_codec = conn_src->end.cset.codec; + dst_codec = conn_dst->end.cset.codec; if (mgcp_conn_rtp_is_iuup(conn_dst) || mgcp_conn_rtp_is_iuup(conn_src)) { /* the iuup code will correctly transform to the correct AMR mode */ - } else if (mgcp_codec_amr_align_mode_is_indicated(conn_dst->end.codec)) { - rc = amr_oa_bwe_convert(endp, msg, conn_dst->end.codec->param.amr_octet_aligned); + } else if (mgcp_codec_amr_align_mode_is_indicated(dst_codec)) { + rc = amr_oa_bwe_convert(endp, msg, dst_codec->param.amr_octet_aligned); if (rc < 0) { LOGPENDP(endp, DRTP, LOGL_ERROR, "Error in AMR octet-aligned <-> bandwidth-efficient mode conversion (target=%s)\n", - conn_dst->end.codec->param.amr_octet_aligned ? "octet-aligned" : "bandwidth-efficient"); + dst_codec->param.amr_octet_aligned ? "octet-aligned" : "bandwidth-efficient"); msgb_free(msg); return rc; } } else if (rtp_end->rfc5993_hr_convert && - strcmp(conn_src->end.codec->subtype_name, "GSM-HR-08") == 0) { + strcmp(src_codec->subtype_name, "GSM-HR-08") == 0) { rc = rfc5993_hr_convert(endp, msg); if (rc < 0) { LOGPENDP(endp, DRTP, LOGL_ERROR, "Error while converting to GSM-HR-08\n"); @@ -1434,7 +1439,7 @@ } /* Forward to E1 */ - return mgcp_e1_send_rtp(conn->endp, conn_src->end.codec, msg); + return mgcp_e1_send_rtp(conn->endp, conn_src->end.cset.codec, msg); } /*! cleanup an endpoint when a connection on an RTP bridge endpoint is removed. @@ -1556,18 +1561,18 @@ /* Handle AMR frame format conversion (octet-aligned vs. bandwith-efficient) */ if (mc->proto == MGCP_PROTO_RTP - && conn_src->end.codec - && mgcp_codec_amr_align_mode_is_indicated(conn_src->end.codec)) { + && conn_src->end.cset.codec + && mgcp_codec_amr_align_mode_is_indicated(conn_src->end.cset.codec)) { /* Make sure that the incoming AMR frame format matches the frame format that the call agent has * communicated via SDP when the connection was created/modfied. */ int oa = amr_oa_check((char*)msgb_data(msg), msgb_length(msg)); if (oa < 0) goto out_free; - if (((bool)oa) != conn_src->end.codec->param.amr_octet_aligned) { + if (((bool)oa) != conn_src->end.cset.codec->param.amr_octet_aligned) { LOG_CONN_RTP(conn_src, LOGL_NOTICE, "rx_rtp(%u bytes): Expected RTP AMR octet-aligned=%u but got octet-aligned=%u." " check the config of your call-agent!\n", - msgb_length(msg), conn_src->end.codec->param.amr_octet_aligned, oa); + msgb_length(msg), conn_src->end.cset.codec->param.amr_octet_aligned, oa); goto out_free; } } diff --git a/src/libosmo-mgcp/mgcp_osmux.c b/src/libosmo-mgcp/mgcp_osmux.c index 0c285dd..31f128a 100644 --- a/src/libosmo-mgcp/mgcp_osmux.c +++ b/src/libosmo-mgcp/mgcp_osmux.c @@ -651,7 +651,7 @@ osmux_xfrm_output_set_rtp_ssrc(conn->osmux.out, (conn->osmux.remote_cid * rtp_ssrc_winlen) + (random() % rtp_ssrc_winlen)); - osmux_xfrm_output_set_rtp_pl_type(conn->osmux.out, conn->end.codec->payload_type); + osmux_xfrm_output_set_rtp_pl_type(conn->osmux.out, conn->end.cset.codec->payload_type); osmux_xfrm_output_set_tx_cb(conn->osmux.out, scheduled_from_osmux_tx_rtp_cb, conn); diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c index eef9d5f..45f2c4f 100644 --- a/src/libosmo-mgcp/mgcp_protocol.c +++ b/src/libosmo-mgcp/mgcp_protocol.c @@ -744,19 +744,20 @@ const struct mgcp_rtp_end *rtp) { int f = 0; + struct mgcp_rtp_codec *codec = rtp->cset.codec; /* Get the number of frames per channel and packet */ if (rtp->frames_per_packet) f = rtp->frames_per_packet; - else if (rtp->packet_duration_ms && rtp->codec->frame_duration_num) { - int den = 1000 * rtp->codec->frame_duration_num; - f = (rtp->packet_duration_ms * rtp->codec->frame_duration_den + + else if (rtp->packet_duration_ms && codec->frame_duration_num) { + int den = 1000 * codec->frame_duration_num; + f = (rtp->packet_duration_ms * codec->frame_duration_den + den / 2) / den; } - return rtp->codec->rate * f * rtp->codec->frame_duration_num / - rtp->codec->frame_duration_den; + return codec->rate * f * codec->frame_duration_num / + codec->frame_duration_den; } /*! Initializes osmux socket if not yet initialized. Parses Osmux CID from MGCP line. @@ -784,6 +785,7 @@ struct mgcp_endpoint *endp = rq->endp; struct mgcp_conn *conn_dst; struct mgcp_conn_rtp *conn_dst_rtp; + struct mgcp_rtp_codecset *cset = &conn->end.cset; int rc; char *cmd; @@ -797,7 +799,7 @@ if (have_sdp) { /* If we have SDP, we ignore the local connection options and * use only the SDP information. */ - mgcp_codec_reset_all(conn); + mgcp_codecset_reset(cset); rc = mgcp_parse_sdp_data(endp, conn, rq->pdata); if (rc != 0) { LOGPCONN(conn->conn, DLMGCP, LOGL_ERROR, @@ -809,19 +811,19 @@ } else if (endp->local_options.codec) { /* When no SDP is available, we use the codec information from * the local connection options (if present) */ - mgcp_codec_reset_all(conn); - rc = mgcp_codec_add(conn, PTYPE_UNDEFINED, endp->local_options.codec, NULL); + mgcp_codecset_reset(cset); + rc = mgcp_codecset_add_codec(cset, PTYPE_UNDEFINED, endp->local_options.codec, NULL); if (rc != 0) goto error; } /* Make sure we always set a sane default codec */ - if (conn->end.codecs_assigned == 0) { + if (cset->codecs_assigned == 0) { /* When SDP and/or LCO did not supply any codec information, * than it makes sense to pick a sane default: (payload-type 0, * PCMU), see also: OS#2658 */ - mgcp_codec_reset_all(conn); - rc = mgcp_codec_add(conn, 0, NULL, NULL); + mgcp_codecset_reset(cset); + rc = mgcp_codecset_add_codec(cset, 0, NULL, NULL); if (rc != 0) goto error; } @@ -834,7 +836,7 @@ conn_dst_rtp = NULL; /* Make codec decision */ - if (mgcp_codec_decide(conn, conn_dst_rtp) != 0) + if (mgcp_codecset_decide(&conn->end.cset, conn_dst_rtp ? &conn_dst_rtp->end.cset : NULL) != 0) goto error; return 0; @@ -1074,7 +1076,7 @@ /* Handle codec information and decide for a suitable codec */ rc = handle_codec_info(conn_rtp, rq, have_sdp, true); - mgcp_codec_summary(conn_rtp); + mgcp_codecset_summary(&conn_rtp->end.cset, mgcp_conn_dump(conn)); if (rc) { error_code = rc; rate_ctr_inc(rate_ctr_group_get_ctr(rate_ctrs, MGCP_CRCX_FAIL_CODEC_NEGOTIATION)); @@ -1082,7 +1084,8 @@ } /* Upgrade the conn type RTP_DEFAULT->RTP_IUUP if needed based on requested codec: */ /* TODO: "codec" probably needs to be moved from endp to conn */ - if (conn_rtp->type == MGCP_RTP_DEFAULT && strcmp(conn_rtp->end.codec->subtype_name, "VND.3GPP.IUFP") == 0) { + if (conn_rtp->type == MGCP_RTP_DEFAULT && + strcmp(conn_rtp->end.cset.codec->subtype_name, "VND.3GPP.IUFP") == 0) { rc = mgcp_conn_iuup_init(conn_rtp); } @@ -1285,14 +1288,15 @@ /* Handle codec information and decide for a suitable codec */ rc = handle_codec_info(conn_rtp, rq, have_sdp, false); - mgcp_codec_summary(conn_rtp); + mgcp_codecset_summary(&conn_rtp->end.cset, mgcp_conn_dump(conn)); if (rc) { error_code = rc; goto error3; } /* Upgrade the conn type RTP_DEFAULT->RTP_IUUP if needed based on requested codec: */ /* TODO: "codec" probably needs to be moved from endp to conn */ - if (conn_rtp->type == MGCP_RTP_DEFAULT && strcmp(conn_rtp->end.codec->subtype_name, "VND.3GPP.IUFP") == 0) + if (conn_rtp->type == MGCP_RTP_DEFAULT && + strcmp(conn_rtp->end.cset.codec->subtype_name, "VND.3GPP.IUFP") == 0) rc = mgcp_conn_iuup_init(conn_rtp); if (mgcp_conn_rtp_is_osmux(conn_rtp)) { diff --git a/src/libosmo-mgcp/mgcp_sdp.c b/src/libosmo-mgcp/mgcp_sdp.c index 77825f6..4d13388 100644 --- a/src/libosmo-mgcp/mgcp_sdp.c +++ b/src/libosmo-mgcp/mgcp_sdp.c @@ -422,7 +422,7 @@ /* Store parsed codec information */ for (i = 0; i < codecs_used; i++) { codec_param = param_by_pt(codecs[i].payload_type, fmtp_params, fmtp_used); - rc = mgcp_codec_add(conn, codecs[i].payload_type, codecs[i].map_line, codec_param); + rc = mgcp_codecset_add_codec(&conn->end.cset, codecs[i].payload_type, codecs[i].map_line, codec_param); if (rc < 0) LOGPENDP(endp, DLMGCP, LOGL_NOTICE, "failed to add codec\n"); } @@ -437,8 +437,8 @@ LOGPC(DLMGCP, LOGL_NOTICE, "none"); for (i = 0; i < codecs_used; i++) { LOGPC(DLMGCP, LOGL_NOTICE, "%d=%s", - rtp->codecs[i].payload_type, - strlen(rtp->codecs[i].subtype_name) ? rtp->codecs[i].subtype_name : "unknown"); + rtp->cset.codecs[i].payload_type, + strlen(rtp->cset.codecs[i].subtype_name) ? rtp->cset.codecs[i].subtype_name : "unknown"); LOGPC(DLMGCP, LOGL_NOTICE, " "); } LOGPC(DLMGCP, LOGL_NOTICE, "\n"); @@ -542,7 +542,7 @@ OSMO_ASSERT(sdp); OSMO_ASSERT(addr); - codec = conn->end.codec; + codec = conn->end.cset.codec; audio_name = codec->audio_name; payload_type = codec->payload_type; diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c index 8e0360f..e90ceaa 100644 --- a/src/libosmo-mgcp/mgcp_vty.c +++ b/src/libosmo-mgcp/mgcp_vty.c @@ -165,7 +165,7 @@ { struct mgcp_rtp_state *state = &conn->state; struct mgcp_rtp_end *end = &conn->end; - struct mgcp_rtp_codec *codec = end->codec; + struct mgcp_rtp_codec *codec = end->cset.codec; struct rate_ctr *tx_packets, *tx_bytes; struct rate_ctr *rx_packets, *rx_bytes; struct rate_ctr *dropped_packets; diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c index c257d6a..9aa7326 100644 --- a/tests/mgcp/mgcp_test.c +++ b/tests/mgcp/mgcp_test.c @@ -1023,14 +1023,14 @@ fprintf(stderr, "endpoint:%s: " "payload type %d (expected %d)\n", last_endpoint, - conn->end.codec->payload_type, t->ptype); + conn->end.cset.codec->payload_type, t->ptype); if (t->ptype != PTYPE_IGNORE) - OSMO_ASSERT(conn->end.codec->payload_type == + OSMO_ASSERT(conn->end.cset.codec->payload_type == t->ptype); /* Reset them again for next test */ - conn->end.codec->payload_type = PTYPE_NONE; + conn->end.cset.codec->payload_type = PTYPE_NONE; } } @@ -1466,8 +1466,8 @@ rtp = &conn->end; - OSMO_ASSERT(mgcp_codec_add(conn, PTYPE_UNDEFINED, "AMR/8000/1", NULL) == 0); - rtp->codec = &rtp->codecs[0]; + OSMO_ASSERT(mgcp_codecset_add_codec(&conn->end.cset, PTYPE_UNDEFINED, "AMR/8000/1", NULL) == 0); + rtp->cset.codec = &rtp->cset.codecs[0]; for (i = 0; i < ARRAY_SIZE(test_rtp_packets1); ++i) { struct rtp_packet_info *info = test_rtp_packets1 + i; @@ -1550,7 +1550,7 @@ OSMO_ASSERT(endp); conn = mgcp_endp_get_conn_rtp(endp, conn_id); OSMO_ASSERT(conn); - OSMO_ASSERT(conn->end.codec->payload_type == 18); + OSMO_ASSERT(conn->end.cset.codec->payload_type == 18); /* Allocate 2@mgw with three codecs, last one ignored */ last_endpoint[0] = '\0'; @@ -1566,7 +1566,7 @@ OSMO_ASSERT(endp); conn = mgcp_endp_get_conn_rtp(endp, conn_id); OSMO_ASSERT(conn); - OSMO_ASSERT(conn->end.codec->payload_type == 18); + OSMO_ASSERT(conn->end.cset.codec->payload_type == 18); /* Allocate 3@mgw with no codecs, check for PT == 0 */ /* Note: It usually makes no sense to leave the payload type list @@ -1587,7 +1587,7 @@ OSMO_ASSERT(endp); conn = mgcp_endp_get_conn_rtp(endp, conn_id); OSMO_ASSERT(conn); - OSMO_ASSERT(conn->end.codec->payload_type == 0); + OSMO_ASSERT(conn->end.cset.codec->payload_type == 0); /* Allocate 4@mgw with a single codec */ last_endpoint[0] = '\0'; @@ -1603,7 +1603,7 @@ OSMO_ASSERT(endp); conn = mgcp_endp_get_conn_rtp(endp, conn_id); OSMO_ASSERT(conn); - OSMO_ASSERT(conn->end.codec->payload_type == 18); + OSMO_ASSERT(conn->end.cset.codec->payload_type == 18); /* Allocate 5@mgw and let osmo-mgw pick a codec from the list */ last_endpoint[0] = '\0'; @@ -1619,7 +1619,7 @@ OSMO_ASSERT(endp); conn = mgcp_endp_get_conn_rtp(endp, conn_id); OSMO_ASSERT(conn); - OSMO_ASSERT(conn->end.codec->payload_type == 0); + OSMO_ASSERT(conn->end.cset.codec->payload_type == 0); inp = create_msg(MDCX_NAT_DUMMY, conn_id); last_endpoint[0] = '\0'; @@ -1631,7 +1631,7 @@ OSMO_ASSERT(endp); conn = mgcp_endp_get_conn_rtp(endp, conn_id); OSMO_ASSERT(conn); - OSMO_ASSERT(conn->end.codec->payload_type == 3); + OSMO_ASSERT(conn->end.cset.codec->payload_type == 3); OSMO_ASSERT(osmo_sockaddr_port(&conn->end.addr.u.sa) == 16434); memset(&addr, 0, sizeof(addr)); inet_aton("8.8.8.8", &addr); @@ -1662,7 +1662,7 @@ OSMO_ASSERT(endp); conn = mgcp_endp_get_conn_rtp(endp, conn_id); OSMO_ASSERT(conn); - OSMO_ASSERT(conn->end.codec->payload_type == 0); + OSMO_ASSERT(conn->end.cset.codec->payload_type == 0); mgcp_endpoints_release(trunk); talloc_free(cfg); @@ -2195,7 +2195,7 @@ int payload_type_conn_dst; printf(" - mgcp_codec_decide(&conn[%u], &conn[%u]):\n", index_conn_src, index_conn_dst); - if (mgcp_codec_decide(&conn[index_conn_src], &conn[index_conn_dst]) != 0) { + if (mgcp_codecset_decide(&conn[index_conn_src].end.cset, &conn[index_conn_dst].end.cset) != 0) { if (expect->payload_type_map[index_conn_src] == -EINVAL && expect->payload_type_map[index_conn_dst] == -EINVAL) printf(" codec decision failed (expected)!\n"); @@ -2205,19 +2205,19 @@ } } else { printf(" Codec decision result:\n"); - if (conn[index_conn_src].end.codec) { - payload_type_conn_src = conn[index_conn_src].end.codec->payload_type; + if (conn[index_conn_src].end.cset.codec) { + payload_type_conn_src = conn[index_conn_src].end.cset.codec->payload_type; printf(" conn[%u]: codec:%s, pt:%d\n", - index_conn_src, conn[index_conn_src].end.codec->subtype_name, payload_type_conn_src); + index_conn_src, conn[index_conn_src].end.cset.codec->subtype_name, payload_type_conn_src); } else { payload_type_conn_src = -EINVAL; printf(" conn[%u]: codec:none, pt:none\n", index_conn_src); } - if (conn[index_conn_dst].end.codec) { - payload_type_conn_dst = conn[index_conn_dst].end.codec->payload_type; + if (conn[index_conn_dst].end.cset.codec) { + payload_type_conn_dst = conn[index_conn_dst].end.cset.codec->payload_type; printf(" conn[%u]: codec:%s, pt:%d\n", - index_conn_dst, conn[index_conn_dst].end.codec->subtype_name, + index_conn_dst, conn[index_conn_dst].end.cset.codec->subtype_name, payload_type_conn_dst); } else { payload_type_conn_dst = -EINVAL; @@ -2265,8 +2265,8 @@ if (!codec->audio_name) break; - rc = mgcp_codec_add(&conn[conn_i], codec->payload_type, codec->audio_name, - codec->param); + rc = mgcp_codecset_add_codec(&conn[conn_i].end.cset, codec->payload_type, + codec->audio_name, codec->param); printf(" %2d: %3d %s%s -> rc=%d\n", c, codec->payload_type, codec->audio_name, codec->param ? -- To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/39215?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-Change-Id: Id7db7ab01d56b7fa2415123b604375e48c82ab25 Gerrit-Change-Number: 39215 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
1 0
0 0
[S] Change in osmo-mgw[master]: mgw: Cleanup rtp_endp fields in its own function
by pespin 14 Jan '25

14 Jan '25
pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-mgw/+/39216?usp=email ) Change subject: mgw: Cleanup rtp_endp fields in its own function ...................................................................... mgw: Cleanup rtp_endp fields in its own function Change-Id: I0b2ccb94129dc7aed6fe13bb20f9910a53d8a41e --- M include/osmocom/mgcp/mgcp_rtp_end.h M src/libosmo-mgcp/mgcp_conn.c M src/libosmo-mgcp/mgcp_rtp_end.c 3 files changed, 11 insertions(+), 6 deletions(-) Approvals: laforge: Looks good to me, but someone else must approve daniel: Looks good to me, approved Jenkins Builder: Verified diff --git a/include/osmocom/mgcp/mgcp_rtp_end.h b/include/osmocom/mgcp/mgcp_rtp_end.h index 69208e5..c08f00d 100644 --- a/include/osmocom/mgcp/mgcp_rtp_end.h +++ b/include/osmocom/mgcp/mgcp_rtp_end.h @@ -46,5 +46,6 @@ }; void mgcp_rtp_end_init(struct mgcp_rtp_end *end); +void mgcp_rtp_end_cleanup(struct mgcp_rtp_end *end); 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/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c index 68b6b39..088d3e3 100644 --- a/src/libosmo-mgcp/mgcp_conn.c +++ b/src/libosmo-mgcp/mgcp_conn.c @@ -113,10 +113,6 @@ conn_rtp->state.out_stream.err_ts_ctr = rate_ctr_group_get_ctr(conn_rtp->ctrg, OUT_STREAM_ERR_TSTMP_CTR); mgcp_rtp_end_init(&conn_rtp->end); - - /* Make sure codec table is reset */ - mgcp_codecset_reset(&conn_rtp->end.cset); - return 0; } @@ -127,9 +123,8 @@ conn_osmux_disable(conn_rtp); if (mgcp_conn_rtp_is_iuup(conn_rtp)) mgcp_conn_iuup_cleanup(conn_rtp); - mgcp_rtp_end_free_port(&conn_rtp->end); + mgcp_rtp_end_cleanup(&conn_rtp->end); rate_ctr_group_free(conn_rtp->ctrg); - mgcp_codecset_reset(&conn_rtp->end.cset); } void mgcp_conn_watchdog_cb(void *data) diff --git a/src/libosmo-mgcp/mgcp_rtp_end.c b/src/libosmo-mgcp/mgcp_rtp_end.c index 422c199..e48eaeb 100644 --- a/src/libosmo-mgcp/mgcp_rtp_end.c +++ b/src/libosmo-mgcp/mgcp_rtp_end.c @@ -47,6 +47,15 @@ end->packet_duration_ms = DEFAULT_RTP_AUDIO_PACKET_DURATION_MS; end->output_enabled = false; end->maximum_packet_time = -1; + + /* Make sure codec table is reset */ + mgcp_codecset_reset(&end->cset); +} + +void mgcp_rtp_end_cleanup(struct mgcp_rtp_end *end) +{ + mgcp_rtp_end_free_port(end); + mgcp_codecset_reset(&end->cset); } bool mgcp_rtp_end_remote_addr_available(const struct mgcp_rtp_end *rtp_end) -- To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/39216?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-Change-Id: I0b2ccb94129dc7aed6fe13bb20f9910a53d8a41e Gerrit-Change-Number: 39216 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
1 0
0 0
[S] Change in osmo-mgw[master]: mgw: Move force_ptime logic outside of main CRCX func handler
by pespin 14 Jan '25

14 Jan '25
pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-mgw/+/39217?usp=email ) Change subject: mgw: Move force_ptime logic outside of main CRCX func handler ...................................................................... mgw: Move force_ptime logic outside of main CRCX func handler Apply the forced value automatically during init, and then only override it based on received input from MGCP when it has not been forced by VTY config. Change-Id: I02a92a090887caa8e05917a44c8b2351fa7b9b50 --- M include/osmocom/mgcp/mgcp_rtp_end.h M src/libosmo-mgcp/mgcp_conn.c M src/libosmo-mgcp/mgcp_protocol.c M src/libosmo-mgcp/mgcp_rtp_end.c M src/libosmo-mgcp/mgcp_sdp.c 5 files changed, 28 insertions(+), 11 deletions(-) Approvals: daniel: Looks good to me, approved Jenkins Builder: Verified laforge: Looks good to me, but someone else must approve diff --git a/include/osmocom/mgcp/mgcp_rtp_end.h b/include/osmocom/mgcp/mgcp_rtp_end.h index c08f00d..02554cb 100644 --- a/include/osmocom/mgcp/mgcp_rtp_end.h +++ b/include/osmocom/mgcp/mgcp_rtp_end.h @@ -11,6 +11,7 @@ /* 'mgcp_rtp_end': basically a wrapper around the RTP+RTCP ports */ struct mgcp_rtp_end { + struct mgcp_conn_rtp *conn_rtp; /* backpointer */ /* remote IP address of the RTP socket */ struct osmo_sockaddr addr; @@ -45,7 +46,8 @@ char local_addr[INET6_ADDRSTRLEN]; }; -void mgcp_rtp_end_init(struct mgcp_rtp_end *end); +void mgcp_rtp_end_init(struct mgcp_rtp_end *end, struct mgcp_conn_rtp *conn_rtp); void mgcp_rtp_end_cleanup(struct mgcp_rtp_end *end); +void mgcp_rtp_end_set_packet_duration_ms(struct mgcp_rtp_end *end, uint32_t packet_duration_ms); 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/mgcp_conn.c b/src/libosmo-mgcp/mgcp_conn.c index 088d3e3..48a9f19 100644 --- a/src/libosmo-mgcp/mgcp_conn.c +++ b/src/libosmo-mgcp/mgcp_conn.c @@ -112,7 +112,7 @@ conn_rtp->state.in_stream.err_ts_ctr = rate_ctr_group_get_ctr(conn_rtp->ctrg, IN_STREAM_ERR_TSTMP_CTR); conn_rtp->state.out_stream.err_ts_ctr = rate_ctr_group_get_ctr(conn_rtp->ctrg, OUT_STREAM_ERR_TSTMP_CTR); - mgcp_rtp_end_init(&conn_rtp->end); + mgcp_rtp_end_init(&conn_rtp->end, conn_rtp); return 0; } diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c index 45f2c4f..48bb28b 100644 --- a/src/libosmo-mgcp/mgcp_protocol.c +++ b/src/libosmo-mgcp/mgcp_protocol.c @@ -1089,11 +1089,6 @@ rc = mgcp_conn_iuup_init(conn_rtp); } - if (pdata->cfg->force_ptime) { - conn_rtp->end.packet_duration_ms = pdata->cfg->force_ptime; - conn_rtp->end.force_output_ptime = 1; - } - mgcp_rtp_end_config(endp, 0, &conn_rtp->end); /* Find a local address for conn based on policy and initial SDP remote diff --git a/src/libosmo-mgcp/mgcp_rtp_end.c b/src/libosmo-mgcp/mgcp_rtp_end.c index e48eaeb..c9dbc54 100644 --- a/src/libosmo-mgcp/mgcp_rtp_end.c +++ b/src/libosmo-mgcp/mgcp_rtp_end.c @@ -30,13 +30,19 @@ #include <osmocom/core/osmo_io.h> #include <osmocom/mgcp/mgcp_rtp_end.h> #include <osmocom/mgcp/mgcp_codec.h> +#include <osmocom/mgcp/mgcp_conn.h> +#include <osmocom/mgcp/mgcp_endp.h> +#include <osmocom/mgcp/mgcp_trunk.h> /*********************** * mgcp_rtp_end **********************/ -void mgcp_rtp_end_init(struct mgcp_rtp_end *end) +void mgcp_rtp_end_init(struct mgcp_rtp_end *end, struct mgcp_conn_rtp *conn_rtp) { + struct mgcp_config *cfg = conn_rtp->conn->endp->trunk->cfg; + + end->conn_rtp = conn_rtp; end->rtp = NULL; end->rtcp = NULL; memset(&end->addr, 0, sizeof(end->addr)); @@ -44,10 +50,17 @@ /* Set default values */ end->frames_per_packet = 0; /* unknown */ - end->packet_duration_ms = DEFAULT_RTP_AUDIO_PACKET_DURATION_MS; end->output_enabled = false; end->maximum_packet_time = -1; + + if (cfg->force_ptime) { + end->packet_duration_ms = cfg->force_ptime; + end->force_output_ptime = 1; + } else { + end->packet_duration_ms = DEFAULT_RTP_AUDIO_PACKET_DURATION_MS; + } + /* Make sure codec table is reset */ mgcp_codecset_reset(&end->cset); } @@ -58,6 +71,13 @@ mgcp_codecset_reset(&end->cset); } +void mgcp_rtp_end_set_packet_duration_ms(struct mgcp_rtp_end *end, uint32_t packet_duration_ms) +{ + if (end->force_output_ptime) + return; + end->packet_duration_ms = packet_duration_ms; +} + bool mgcp_rtp_end_remote_addr_available(const struct mgcp_rtp_end *rtp_end) { return (osmo_sockaddr_port(&rtp_end->addr.u.sa) != 0) && diff --git a/src/libosmo-mgcp/mgcp_sdp.c b/src/libosmo-mgcp/mgcp_sdp.c index 4d13388..ffd0f18 100644 --- a/src/libosmo-mgcp/mgcp_sdp.c +++ b/src/libosmo-mgcp/mgcp_sdp.c @@ -361,9 +361,9 @@ if (sscanf(line, "a=ptime:%d-%d", &ptime, &ptime2) >= 1) { if (ptime2 > 0 && ptime2 != ptime) - rtp->packet_duration_ms = 0; + mgcp_rtp_end_set_packet_duration_ms(rtp, 0); else - rtp->packet_duration_ms = ptime; + mgcp_rtp_end_set_packet_duration_ms(rtp, ptime); break; } -- To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/39217?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-Change-Id: I02a92a090887caa8e05917a44c8b2351fa7b9b50 Gerrit-Change-Number: 39217 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
1 0
0 0
[XS] Change in osmo-mgw[master]: mgw: Move several params setting to mgcp_rtp_end_init()
by pespin 14 Jan '25

14 Jan '25
pespin has submitted this change. ( https://gerrit.osmocom.org/c/osmo-mgw/+/39220?usp=email ) Change subject: mgw: Move several params setting to mgcp_rtp_end_init() ...................................................................... mgw: Move several params setting to mgcp_rtp_end_init() There's no need to set those 2 params later on, simply set them during init() to simplify code. Change-Id: I38e2cfbe03c1e2de48e48f30a04af746bc2368a4 --- M src/libosmo-mgcp/mgcp_protocol.c M src/libosmo-mgcp/mgcp_rtp_end.c 2 files changed, 4 insertions(+), 3 deletions(-) Approvals: laforge: Looks good to me, but someone else must approve daniel: Looks good to me, approved Jenkins Builder: Verified diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c index 48bb28b..97eb43d 100644 --- a/src/libosmo-mgcp/mgcp_protocol.c +++ b/src/libosmo-mgcp/mgcp_protocol.c @@ -729,9 +729,7 @@ bool patch_ssrc = expect_ssrc_change && trunk->force_constant_ssrc; - rtp->force_aligned_timing = trunk->force_aligned_timing; rtp->force_constant_ssrc = patch_ssrc ? 1 : 0; - rtp->rfc5993_hr_convert = trunk->rfc5993_hr_convert; LOGPENDP(endp, DLMGCP, LOGL_DEBUG, "Configuring RTP endpoint: local port %d%s%s\n", diff --git a/src/libosmo-mgcp/mgcp_rtp_end.c b/src/libosmo-mgcp/mgcp_rtp_end.c index c9dbc54..819a922 100644 --- a/src/libosmo-mgcp/mgcp_rtp_end.c +++ b/src/libosmo-mgcp/mgcp_rtp_end.c @@ -40,7 +40,8 @@ void mgcp_rtp_end_init(struct mgcp_rtp_end *end, struct mgcp_conn_rtp *conn_rtp) { - struct mgcp_config *cfg = conn_rtp->conn->endp->trunk->cfg; + struct mgcp_trunk *trunk = conn_rtp->conn->endp->trunk; + struct mgcp_config *cfg = trunk->cfg; end->conn_rtp = conn_rtp; end->rtp = NULL; @@ -53,6 +54,8 @@ end->output_enabled = false; end->maximum_packet_time = -1; + end->force_aligned_timing = trunk->force_aligned_timing; + end->rfc5993_hr_convert = trunk->rfc5993_hr_convert; if (cfg->force_ptime) { end->packet_duration_ms = cfg->force_ptime; -- To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/39220?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-Change-Id: I38e2cfbe03c1e2de48e48f30a04af746bc2368a4 Gerrit-Change-Number: 39220 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de>
1 0
0 0
[M] Change in osmo-mgw[master]: mgw: Clean up code allocating conn_rtp rtp/rtcp sockets
by daniel 14 Jan '25

14 Jan '25
Attention is currently required from: pespin. daniel has posted comments on this change by pespin. ( https://gerrit.osmocom.org/c/osmo-mgw/+/39222?usp=email ) Change subject: mgw: Clean up code allocating conn_rtp rtp/rtcp sockets ...................................................................... Patch Set 2: (1 comment) File src/libosmo-mgcp/mgcp_network.c: https://gerrit.osmocom.org/c/osmo-mgw/+/39222/comment/b9d5e478_5e024c2b?usp… : PS1, Line 1632: conn Sorry, I forgot to submit this earlier... Rename conn_rtp as well (and _conn->conn) Then +2 from my side -- To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/39222?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-Change-Id: I50a251b66e85ceeeccb30dcd1813863d7c754961 Gerrit-Change-Number: 39222 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-CC: daniel <dwillmann(a)sysmocom.de> Gerrit-Attention: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Tue, 14 Jan 2025 15:38:43 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: No
1 0
0 0
[M] Change in osmo-mgw[master]: mgw: Simplify and redo code around ssrc patch feature
by pespin 14 Jan '25

14 Jan '25
pespin has posted comments on this change by pespin. ( https://gerrit.osmocom.org/c/osmo-mgw/+/39221?usp=email ) Change subject: mgw: Simplify and redo code around ssrc patch feature ...................................................................... Patch Set 2: Code-Review+2 -- To view, visit https://gerrit.osmocom.org/c/osmo-mgw/+/39221?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: comment Gerrit-Project: osmo-mgw Gerrit-Branch: master Gerrit-Change-Id: Ib7216a775f4ad126e62b9e99aff381fd45015819 Gerrit-Change-Number: 39221 Gerrit-PatchSet: 2 Gerrit-Owner: pespin <pespin(a)sysmocom.de> Gerrit-Reviewer: Jenkins Builder Gerrit-Reviewer: daniel <dwillmann(a)sysmocom.de> Gerrit-Reviewer: laforge <laforge(a)osmocom.org> Gerrit-Reviewer: pespin <pespin(a)sysmocom.de> Gerrit-Comment-Date: Tue, 14 Jan 2025 15:38:24 +0000 Gerrit-HasComments: No Gerrit-Has-Labels: Yes
1 0
0 0
[M] Change in libosmo-netif[master]: stream: Introduce osmo_stream_{cli,srv}_set_segmentation_cb2
by pespin 14 Jan '25

14 Jan '25
pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmo-netif/+/39316?usp=email ) Change subject: stream: Introduce osmo_stream_{cli,srv}_set_segmentation_cb2 ...................................................................... stream: Introduce osmo_stream_{cli,srv}_set_segmentation_cb2 Change-Id: I6e8dd6ece13397074075f05a1a0a8dbdd80d8848 --- M TODO-RELEASE M include/osmocom/netif/stream.h M src/stream_cli.c M src/stream_srv.c 4 files changed, 105 insertions(+), 23 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/16/39316/1 diff --git a/TODO-RELEASE b/TODO-RELEASE index 5092ee7..e66b421 100644 --- a/TODO-RELEASE +++ b/TODO-RELEASE @@ -9,4 +9,5 @@ #library what description / commit summary line libosmo-netif add API osmo_stream_cli_set_{ip_dscp,priority}(), osmo_stream_srv_link_set_{ip_dscp,priority}() libosmo-netif add API osmo-stream_cli_set_tx_queue_max_length(), osmo_stream_srv_link_set_tx_queue_max_length() -libosmo-netif add API struct osmo_ipa_ka_fsm_inst \ No newline at end of file +libosmo-netif add API struct osmo_ipa_ka_fsm_inst +libosmo-netif add API osmo_stream_{cli,srv}_set_segmentation_cb2() diff --git a/include/osmocom/netif/stream.h b/include/osmocom/netif/stream.h index a132a27..2866ea3 100644 --- a/include/osmocom/netif/stream.h +++ b/include/osmocom/netif/stream.h @@ -114,6 +114,7 @@ typedef int (*osmo_stream_srv_read_cb2_t)(struct osmo_stream_srv *conn, int res, struct msgb *msg); typedef int (*osmo_stream_srv_segmentation_cb_t)(struct msgb *msg); +typedef int (*osmo_stream_srv_segmentation_cb2_t)(struct osmo_stream_srv *conn, struct msgb *msg); struct osmo_stream_srv *osmo_stream_srv_create(void *ctx, struct osmo_stream_srv_link *link, int fd, osmo_stream_srv_read_cb_t read_cb, @@ -135,7 +136,8 @@ void osmo_stream_srv_set_flush_and_destroy(struct osmo_stream_srv *conn); void osmo_stream_srv_set_data(struct osmo_stream_srv *conn, void *data); -void osmo_stream_srv_set_segmentation_cb(struct osmo_stream_srv *conn, osmo_stream_srv_segmentation_cb_t segmentation_cb); +void osmo_stream_srv_set_segmentation_cb(struct osmo_stream_srv *conn, osmo_stream_srv_segmentation_cb_t segmentation_cb) OSMO_DEPRECATED("Use osmo_stream_srv_set_segmentation_cb2() instead"); +void osmo_stream_srv_set_segmentation_cb2(struct osmo_stream_srv *conn, osmo_stream_srv_segmentation_cb2_t segmentation_cb2); void osmo_stream_srv_send(struct osmo_stream_srv *conn, struct msgb *msg); int osmo_stream_srv_recv(struct osmo_stream_srv *conn, struct msgb *msg); @@ -191,6 +193,7 @@ typedef int (*osmo_stream_cli_read_cb2_t)(struct osmo_stream_cli *cli, int res, struct msgb *msg); typedef int (*osmo_stream_cli_segmentation_cb_t)(struct msgb *msg); +typedef int (*osmo_stream_cli_segmentation_cb2_t)(struct osmo_stream_cli *cli, struct msgb *msg); void osmo_stream_cli_set_name(struct osmo_stream_cli *cli, const char *name); const char *osmo_stream_cli_get_name(const struct osmo_stream_cli *cli); @@ -218,7 +221,8 @@ void osmo_stream_cli_set_disconnect_cb(struct osmo_stream_cli *cli, osmo_stream_cli_disconnect_cb_t disconnect_cb); void osmo_stream_cli_set_read_cb(struct osmo_stream_cli *cli, osmo_stream_cli_read_cb_t read_cb); void osmo_stream_cli_set_read_cb2(struct osmo_stream_cli *cli, osmo_stream_cli_read_cb2_t read_cb); -void osmo_stream_cli_set_segmentation_cb(struct osmo_stream_cli *cli, osmo_stream_cli_segmentation_cb_t segmentation_cb); +void osmo_stream_cli_set_segmentation_cb(struct osmo_stream_cli *cli, osmo_stream_cli_segmentation_cb_t segmentation_cb) OSMO_DEPRECATED("Use osmo_stream_cli_set_segmentation_cb2() instead"); +void osmo_stream_cli_set_segmentation_cb2(struct osmo_stream_cli *cli, osmo_stream_cli_segmentation_cb2_t segmentation_cb2); void osmo_stream_cli_reconnect(struct osmo_stream_cli *cli); bool osmo_stream_cli_is_connected(struct osmo_stream_cli *cli); diff --git a/src/stream_cli.c b/src/stream_cli.c index 48a8858..586b1b0 100644 --- a/src/stream_cli.c +++ b/src/stream_cli.c @@ -117,6 +117,7 @@ osmo_stream_cli_read_cb_t read_cb; osmo_stream_cli_read_cb2_t iofd_read_cb; osmo_stream_cli_segmentation_cb_t segmentation_cb; + osmo_stream_cli_segmentation_cb2_t segmentation_cb2; void *data; int flags; int reconnect_timeout; @@ -511,7 +512,6 @@ cli->state = STREAM_CLI_STATE_CLOSED; osmo_timer_setup(&cli->timer, cli_timer_cb, cli); cli->reconnect_timeout = 5; /* default is 5 seconds. */ - cli->segmentation_cb = NULL; INIT_LLIST_HEAD(&cli->tx_queue); cli->tx_queue_max_length = 1024; /* Default tx queue size, msgbs. */ @@ -598,8 +598,6 @@ static const struct osmo_io_ops osmo_stream_cli_ioops = { .read_cb = stream_cli_iofd_read_cb, .write_cb = stream_cli_iofd_write_cb, - - .segmentation_cb = NULL, }; #ifdef HAVE_LIBSCTP @@ -659,8 +657,6 @@ static const struct osmo_io_ops osmo_stream_cli_ioops_sctp = { .recvmsg_cb = stream_cli_iofd_recvmsg_cb, .sendmsg_cb = stream_cli_iofd_write_cb, - - .segmentation_cb = NULL, }; #endif @@ -795,28 +791,58 @@ cli->flags |= OSMO_STREAM_CLI_F_RECONF; } +/* Callback from iofd, forward to stream_cli user: */ +static int stream_cli_iofd_segmentation_cb2(struct osmo_io_fd *iofd, struct msgb *msg) +{ + struct osmo_stream_cli *cli = osmo_iofd_get_data(iofd); + if (cli->segmentation_cb2) + return cli->segmentation_cb2(cli, msg); + if (cli->segmentation_cb) + return cli->segmentation_cb(msg); + OSMO_ASSERT(0); + return 0; +} + /* Configure client side segmentation for the iofd */ -static void configure_cli_segmentation_cb(struct osmo_stream_cli *cli, - osmo_stream_cli_segmentation_cb_t segmentation_cb) +static void configure_cli_segmentation_cb(struct osmo_stream_cli *cli) { /* Copy default settings */ struct osmo_io_ops client_ops; osmo_iofd_get_ioops(cli->iofd, &client_ops); /* Set segmentation cb for this client */ - client_ops.segmentation_cb = segmentation_cb; + if (cli->segmentation_cb || cli->segmentation_cb2) + client_ops.segmentation_cb2 = stream_cli_iofd_segmentation_cb2; + else + client_ops.segmentation_cb2 = NULL; osmo_iofd_set_ioops(cli->iofd, &client_ops); } /*! Set the segmentation callback for the client. * \param[in,out] cli Stream Client to modify * \param[in] segmentation_cb Target segmentation callback + * + * DEPRECATED: Use osmo_cli_set_segmentation_cb2() instead. */ void osmo_stream_cli_set_segmentation_cb(struct osmo_stream_cli *cli, osmo_stream_cli_segmentation_cb_t segmentation_cb) { cli->segmentation_cb = segmentation_cb; + cli->segmentation_cb2 = NULL; if (cli->iofd) /* Otherwise, this will be done in osmo_stream_cli_open() */ - configure_cli_segmentation_cb(cli, segmentation_cb); + configure_cli_segmentation_cb(cli); +} + +/*! Set the segmentation callback for the client. + * \param[in,out] cli Stream Client to modify + * \param[in] segmentation_cb2 Target segmentation callback + */ +void osmo_stream_cli_set_segmentation_cb2(struct osmo_stream_cli *cli, + osmo_stream_cli_segmentation_cb2_t segmentation_cb2) +{ + cli->segmentation_cb = NULL; + cli->segmentation_cb2 = segmentation_cb2; + if (cli->iofd) /* Otherwise, this will be done in osmo_stream_cli_open() */ + configure_cli_segmentation_cb(cli); } /*! Set the socket type for the stream server link. @@ -1257,7 +1283,7 @@ osmo_iofd_set_txqueue_max_length(cli->iofd, cli->tx_queue_max_length); osmo_iofd_notify_connected(cli->iofd); - configure_cli_segmentation_cb(cli, cli->segmentation_cb); + configure_cli_segmentation_cb(cli); if (osmo_iofd_register(cli->iofd, fd) < 0) goto error_close_socket; diff --git a/src/stream_srv.c b/src/stream_srv.c index c74f7b0..c2b187a 100644 --- a/src/stream_srv.c +++ b/src/stream_srv.c @@ -664,6 +664,8 @@ osmo_stream_srv_closed_cb_t closed_cb; osmo_stream_srv_read_cb_t read_cb; osmo_stream_srv_read_cb2_t iofd_read_cb; + osmo_stream_srv_segmentation_cb_t segmentation_cb; + osmo_stream_srv_segmentation_cb2_t segmentation_cb2; void *data; int flags; }; @@ -1040,7 +1042,37 @@ conn->data = data; } +/* Callback from iofd, forward to stream_srv user: */ +static int stream_srv_iofd_segmentation_cb2(struct osmo_io_fd *iofd, struct msgb *msg) +{ + struct osmo_stream_srv *conn = osmo_iofd_get_data(iofd); + if (conn->segmentation_cb2) + return conn->segmentation_cb2(conn, msg); + if (conn->segmentation_cb) + return conn->segmentation_cb(msg); + OSMO_ASSERT(0); + return 0; +} + +/* Configure server side segmentation for the iofd */ +static void configure_srv_segmentation_cb(struct osmo_stream_srv *conn) +{ + /* Copy default settings */ + struct osmo_io_ops client_ops; + osmo_iofd_get_ioops(conn->iofd, &client_ops); + /* Set segmentation cb for this client */ + if (conn->segmentation_cb || conn->segmentation_cb2) + client_ops.segmentation_cb2 = stream_srv_iofd_segmentation_cb2; + else + client_ops.segmentation_cb2 = NULL; + osmo_iofd_set_ioops(conn->iofd, &client_ops); +} + /*! Set the segmentation callback for target osmo_stream_srv structure. + * \param[in,out] conn Target Stream Server to modify + * \param[in] segmentation_cb Segmentation callback to be set + * + * DEPRECATED: Use osmo_stream_srv_set_segmentation_cb2() instead. * * A segmentation call-back can optionally be used when a packet based protocol (like TCP) is used within a * STREAM style socket that does not preserve message boundaries within the stream. If a segmentation @@ -1048,22 +1080,41 @@ * complete single messages, and not arbitrary segments of the stream. * * This function only works with osmo_stream_srv in osmo_io mode, created by osmo_stream_srv_create2()! - * The connection has to have been established prior to calling this function. - * - * \param[in,out] conn Target Stream Server to modify - * \param[in] segmentation_cb Segmentation callback to be set */ + * The connection has to have been established prior to calling this function. + * + */ void osmo_stream_srv_set_segmentation_cb(struct osmo_stream_srv *conn, osmo_stream_srv_segmentation_cb_t segmentation_cb) { /* Note that the following implies that iofd != NULL, since * osmo_stream_srv_create2() creates the iofd member, too */ OSMO_ASSERT(conn->mode == OSMO_STREAM_MODE_OSMO_IO); - /* Copy default settings */ - struct osmo_io_ops conn_ops; - osmo_iofd_get_ioops(conn->iofd, &conn_ops); - /* Set segmentation cb for this connection */ - conn_ops.segmentation_cb = segmentation_cb; - osmo_iofd_set_ioops(conn->iofd, &conn_ops); + conn->segmentation_cb = segmentation_cb; + conn->segmentation_cb2 = NULL; + configure_srv_segmentation_cb(conn); +} + +/*! Set the segmentation callback for target osmo_stream_srv structure. + * \param[in,out] conn Target Stream Server to modify + * \param[in] segmentation_cb2 Segmentation callback to be set + * + * A segmentation call-back can optionally be used when a packet based protocol (like TCP) is used within a + * STREAM style socket that does not preserve message boundaries within the stream. If a segmentation + * call-back is given, the osmo_stream_srv library code will makes sure that the read_cb called only for + * complete single messages, and not arbitrary segments of the stream. + * + * This function only works with osmo_stream_srv in osmo_io mode, created by osmo_stream_srv_create2()! + * The connection has to have been established prior to calling this function. + */ +void osmo_stream_srv_set_segmentation_cb2(struct osmo_stream_srv *conn, + osmo_stream_srv_segmentation_cb2_t segmentation_cb2) +{ + /* Note that the following implies that iofd != NULL, since + * osmo_stream_srv_create2() creates the iofd member, too */ + OSMO_ASSERT(conn->mode == OSMO_STREAM_MODE_OSMO_IO); + conn->segmentation_cb = NULL; + conn->segmentation_cb2 = segmentation_cb2; + configure_srv_segmentation_cb(conn); } /*! Retrieve application private data of the stream server -- To view, visit https://gerrit.osmocom.org/c/libosmo-netif/+/39316?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: libosmo-netif Gerrit-Branch: master Gerrit-Change-Id: I6e8dd6ece13397074075f05a1a0a8dbdd80d8848 Gerrit-Change-Number: 39316 Gerrit-PatchSet: 1 Gerrit-Owner: pespin <pespin(a)sysmocom.de>
1 0
0 0
  • ← Newer
  • 1
  • ...
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • ...
  • 150
  • Older →

HyperKitty Powered by HyperKitty version 1.3.12.