dexter has uploaded this change for review. (
https://gerrit.osmocom.org/c/osmo-mgw/+/32218 )
Change subject: mgcp_codec: fix codec decision
......................................................................
mgcp_codec: fix codec decision
Unfortunately OsmoMGW was never really tested with multiple different
codecs on either side of the connection. While OsmoMSC and OsmoBSC only
assign exactly one codec on each side this has never been a problem,
however it might become a problem when a call againt assigns multiple
codecs on one side. This has been observed in a setup where OsmoMGW had
one leg towards an external call agent. Also due to recent upgrades to
the TTCN3 tests we are now able to simulate different codecs on both
sides to pinpoint issues.
Testing has shown that OsmoMGW has difficulties with multiple codecs.
The reason for this is that the function that makes the codec decision
was not fully finished. So let's finish the codec decision function and
let's also use that decision when patching the payload type of outgoing
RTP packets.
Related: OS#5461
Change-Id: I6c3291f825488e5d8ce136aeb18450156794aeb5
---
M include/osmocom/mgcp/mgcp_codec.h
M include/osmocom/mgcp/mgcp_trunk.h
M src/libosmo-mgcp/mgcp_codec.c
M src/libosmo-mgcp/mgcp_network.c
M src/libosmo-mgcp/mgcp_protocol.c
M src/libosmo-mgcp/mgcp_vty.c
M tests/mgcp/mgcp_test.c
M tests/mgcp/mgcp_test.ok
8 files changed, 277 insertions(+), 237 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/osmo-mgw refs/changes/18/32218/1
diff --git a/include/osmocom/mgcp/mgcp_codec.h b/include/osmocom/mgcp/mgcp_codec.h
index 1f29b08..eae2918 100644
--- a/include/osmocom/mgcp/mgcp_codec.h
+++ b/include/osmocom/mgcp/mgcp_codec.h
@@ -13,8 +13,7 @@
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);
-struct mgcp_rtp_codec *mgcp_codec_find_convertible(struct mgcp_conn_rtp *conn, struct
mgcp_rtp_codec *codec);
+int mgcp_codec_decide(struct mgcp_conn_rtp *conn, struct mgcp_conn_rtp *conn_opposite);
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);
diff --git a/include/osmocom/mgcp/mgcp_trunk.h b/include/osmocom/mgcp/mgcp_trunk.h
index 33c3d5b..e608161 100644
--- a/include/osmocom/mgcp/mgcp_trunk.h
+++ b/include/osmocom/mgcp/mgcp_trunk.h
@@ -31,8 +31,6 @@
int audio_send_ptime;
int audio_send_name;
- int no_audio_transcoding;
-
int omit_rtcp;
int keepalive_interval;
diff --git a/src/libosmo-mgcp/mgcp_codec.c b/src/libosmo-mgcp/mgcp_codec.c
index 003c4c4..e83bb0d 100644
--- a/src/libosmo-mgcp/mgcp_codec.c
+++ b/src/libosmo-mgcp/mgcp_codec.c
@@ -276,87 +276,6 @@
return -EINVAL;
}
-/* Check if the given codec is applicable on the specified endpoint
- * Helper function for mgcp_codec_decide() */
-static bool is_codec_compatible(const struct mgcp_endpoint *endp, const struct
mgcp_rtp_codec *codec)
-{
- /* A codec name must be set, if not, this might mean that the codec
- * (payload type) that was assigned is unknown to us so we must stop
- * here. */
- if (!strlen(codec->subtype_name))
- return false;
-
- /* FIXME: implement meaningful checks to make sure that the given codec
- * is compatible with the given endpoint */
-
- return true;
-}
-
-/*! Decide for one suitable codec
- * \param[in] conn related rtp-connection.
- * \returns 0 on success, -EINVAL on failure. */
-int mgcp_codec_decide(struct mgcp_conn_rtp *conn)
-{
- struct mgcp_rtp_end *rtp;
- unsigned int i;
- struct mgcp_endpoint *endp;
- bool codec_assigned = false;
-
- endp = conn->conn->endp;
- rtp = &conn->end;
-
- /* This function works on the results the SDP/LCO parser has extracted
- * from the MGCP message. The goal is to select a suitable codec for
- * the given connection. When transcoding is available, the first codec
- * from the codec list is taken without further checking. When
- * transcoding is not available, then the choice must be made more
- * carefully. Each codec in the list is checked until one is found that
- * is rated compatible. The rating is done by the helper function
- * is_codec_compatible(), which does the actual checking. */
- for (i = 0; i < rtp->codecs_assigned; i++) {
- /* When no transcoding is available, avoid codecs that would
- * require transcoding. */
- if (endp->trunk->no_audio_transcoding && !is_codec_compatible(endp,
&rtp->codecs[i])) {
- LOGP(DLMGCP, LOGL_NOTICE, "transcoding not available, skipping codec:
%d/%s\n",
- rtp->codecs[i].payload_type, rtp->codecs[i].subtype_name);
- continue;
- }
-
- rtp->codec = &rtp->codecs[i];
- codec_assigned = true;
- break;
- }
-
- /* FIXME: To the reviewes: This is problematic. I do not get why we
- * need to reset the packet_duration_ms depending on the codec
- * selection. I thought it were all 20ms? Is this to address some
- * cornercase. (This piece of code was in the code path before,
- * together with the note: "TODO/XXX: Store this per codec and derive
- * it on use" */
- if (codec_assigned) {
- if (rtp->maximum_packet_time >= 0
- && rtp->maximum_packet_time * rtp->codec->frame_duration_den >
- rtp->codec->frame_duration_num * 1500)
- rtp->packet_duration_ms = 0;
-
- return 0;
- }
-
- return -EINVAL;
-}
-
-/* Check if the codec has a specific AMR mode (octet-aligned or bandwith-efficient) set.
*/
-bool mgcp_codec_amr_align_mode_is_indicated(const struct mgcp_rtp_codec *codec)
-{
- if (codec->param_present == false)
- return false;
- if (!codec->param.amr_octet_aligned_present)
- return false;
- if (strcmp(codec->subtype_name, "AMR") != 0)
- return false;
- return true;
-}
-
/* Return true if octet-aligned is set in the given codec. Default to octet-aligned=0,
i.e. bandwidth-efficient mode.
* See RFC4867 "RTP Payload Format for AMR and AMR-WB" sections "8.1. AMR
Media Type Registration" and "8.2. AMR-WB
* Media Type Registration":
@@ -425,11 +344,31 @@
return true;
}
-/*! For a given codec, find a convertible codec in the given connection.
- * \param[in] conn connection to search for a convertible codec
- * \param[in] codec for which a convertible codec shall be found.
- * \returns codec on success, -NULL on failure. */
-struct mgcp_rtp_codec *mgcp_codec_find_convertible(struct mgcp_conn_rtp *conn, struct
mgcp_rtp_codec *codec)
+struct mgcp_rtp_codec *mgcp_codec_find_same(struct mgcp_conn_rtp *conn, struct
mgcp_rtp_codec *codec)
+{
+ struct mgcp_rtp_end *rtp_end;
+ unsigned int i;
+ unsigned int codecs_assigned;
+ struct mgcp_rtp_codec *found_same_codec = 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. */
+ codecs_assigned = rtp_end->codecs_assigned;
+ OSMO_ASSERT(codecs_assigned <= MGCP_MAX_CODECS);
+ for (i = 0; i < codecs_assigned; i++) {
+ if (codecs_same(codec, &rtp_end->codecs[i])) {
+ found_same_codec = &rtp_end->codecs[i];
+ break;
+ }
+ }
+
+ return found_same_codec;
+}
+
+/* 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)
{
struct mgcp_rtp_end *rtp_end;
unsigned int i;
@@ -440,17 +379,12 @@
/* 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;
- OSMO_ASSERT(codecs_assigned <= MGCP_MAX_CODECS);
- for (i = 0; i < codecs_assigned; i++) {
- if (codecs_same(codec, &rtp_end->codecs[i])) {
- codec_convertible = &rtp_end->codecs[i];
- break;
- }
- }
+ codec_convertible = mgcp_codec_find_same(conn, codec);
/* 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;
+ OSMO_ASSERT(codecs_assigned <= MGCP_MAX_CODECS)
if (!codec_convertible) {
for (i = 0; i < codecs_assigned; i++) {
if (codecs_convertible(codec, &rtp_end->codecs[i])) {
@@ -463,6 +397,81 @@
return codec_convertible;
}
+/*! Decide for one suitable codec on both of the given connections. In case an opposite
connection is not available
+ * a tentative decision is made.
+ * \param[inout] conn related rtp-connection.
+ * \param[inout] conn related opposite rtp-connection (NULL if not present).
+ * \returns 0 on success, -EINVAL on failure. */
+int mgcp_codec_decide(struct mgcp_conn_rtp *conn, struct mgcp_conn_rtp *conn_opposite)
+{
+ unsigned int i;
+ struct mgcp_rtp_codec *found_same_codec_opposite = NULL;
+
+ /* In case no opposite connection is available (yet), we are forced to make a simple
tentative decision:
+ * We just use the first codec of the connection (conn) */
+ OSMO_ASSERT(conn->end.codecs_assigned <= MGCP_MAX_CODECS);
+ if (!conn_opposite) {
+ if (conn->end.codecs_assigned >= 1) {
+ conn->end.codec = &conn->end.codecs[0];
+ return 0;
+ } else
+ return -EINVAL;
+ }
+
+ /* In case the opposite connection is available but has no codecs assigned we are forced
to make the same
+ * tentative decision as above */
+ if (conn_opposite->end.codecs_assigned == 0) {
+ if (conn->end.codecs_assigned >= 1) {
+ conn->end.codec = &conn->end.codecs[0];
+ return 0;
+ } else
+ return -EINVAL;
+ }
+
+ /* Compare all codecs of the connection (conn) to the codecs of the opposite connection.
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->end.codecs_assigned; i++) {
+ found_same_codec_opposite = mgcp_codec_find_same(conn_opposite,
&conn->end.codecs[i]);
+ if (found_same_codec_opposite) {
+ /* We found the a codec that is exactly the same (same codec, same payload format
etc.) on both
+ * sides. We now set the codec on both connections */
+ conn_opposite->end.codec = found_same_codec_opposite;
+ conn->end.codec = mgcp_codec_find_same(conn, found_same_codec_opposite);
+ OSMO_ASSERT(conn->end.codec);
+ return 0;
+ }
+ }
+
+ /* In case we could not find a codec that is exactly the same, lets at least try to find
one that we are able
+ * to convert. */
+ for (i = 0; i < conn->end.codecs_assigned; i++) {
+ found_same_codec_opposite = codec_find_convertible(conn_opposite,
&conn->end.codecs[i]);
+ if (found_same_codec_opposite) {
+ /* We found the a codec that is exactly the same (same codec, same payload format
etc.) on both
+ * sides. We now set the codec on both connections */
+ conn_opposite->end.codec = found_same_codec_opposite;
+ conn->end.codec = codec_find_convertible(conn, found_same_codec_opposite);
+ OSMO_ASSERT(conn->end.codec);
+ return 0;
+ }
+ }
+
+ return -EINVAL;
+}
+
+/* Check if the codec has a specific AMR mode (octet-aligned or bandwith-efficient) set.
*/
+bool mgcp_codec_amr_align_mode_is_indicated(const struct mgcp_rtp_codec *codec)
+{
+ if (codec->param_present == false)
+ return false;
+ if (!codec->param.amr_octet_aligned_present)
+ return false;
+ if (strcmp(codec->subtype_name, "AMR") != 0)
+ return false;
+ return true;
+}
+
/* Find the payload type number configured for a specific codec by SDP.
* For example, IuUP gets assigned a payload type number, and the endpoint needs to
translate that to the number
* assigned to "AMR" on the other conn (by a=rtpmap:N).
diff --git a/src/libosmo-mgcp/mgcp_network.c b/src/libosmo-mgcp/mgcp_network.c
index ce08dd4..51561d2 100644
--- a/src/libosmo-mgcp/mgcp_network.c
+++ b/src/libosmo-mgcp/mgcp_network.c
@@ -511,9 +511,8 @@
if (!codec_src)
return -EINVAL;
- /* Lookup a suitable codec in the destination connection. (The codec must be of the same
type or at least
- * convertible) */
- codec_dst = mgcp_codec_find_convertible(conn_dst, codec_src);
+ /* Lookup a suitable codec in the destination connection. */
+ codec_dst = conn_dst->end.codec;
if (!codec_dst)
return -EINVAL;
diff --git a/src/libosmo-mgcp/mgcp_protocol.c b/src/libosmo-mgcp/mgcp_protocol.c
index b697a94..c57c9dc 100644
--- a/src/libosmo-mgcp/mgcp_protocol.c
+++ b/src/libosmo-mgcp/mgcp_protocol.c
@@ -761,6 +761,9 @@
struct mgcp_request_data *rq, int have_sdp, bool crcx)
{
struct mgcp_endpoint *endp = rq->endp;
+ struct mgcp_conn *conn_opposite;
+ struct mgcp_conn_rtp *conn_rtp_opposite;
+
int rc;
char *cmd;
@@ -802,8 +805,15 @@
goto error;
}
+ /* Try to find an opposite RTP connection that we can include in the codec decision. */
+ conn_opposite = mgcp_find_dst_conn(conn->conn);
+ if (conn_opposite && conn_opposite->type == MGCP_CONN_TYPE_RTP)
+ conn_rtp_opposite = &conn_opposite->u.rtp;
+ else
+ conn_rtp_opposite = NULL;
+
/* Make codec decision */
- if (mgcp_codec_decide(conn) != 0)
+ if (mgcp_codec_decide(conn, conn_rtp_opposite) != 0)
goto error;
return 0;
diff --git a/src/libosmo-mgcp/mgcp_vty.c b/src/libosmo-mgcp/mgcp_vty.c
index e404fb5..9405007 100644
--- a/src/libosmo-mgcp/mgcp_vty.c
+++ b/src/libosmo-mgcp/mgcp_vty.c
@@ -120,8 +120,6 @@
trunk->audio_send_name ? "" : "no ", VTY_NEWLINE);
vty_out(vty, " number endpoints %u%s",
trunk->v.vty_number_endpoints, VTY_NEWLINE);
- vty_out(vty, " %sallow-transcoding%s",
- trunk->no_audio_transcoding ? "no " : "", VTY_NEWLINE);
if (strlen(g_cfg->call_agent_addr))
vty_out(vty, " call-agent ip %s%s", g_cfg->call_agent_addr,
VTY_NEWLINE);
@@ -700,25 +698,17 @@
return CMD_SUCCESS;
}
-DEFUN_USRATTR(cfg_mgcp_allow_transcoding,
- cfg_mgcp_allow_transcoding_cmd,
- X(MGW_CMD_ATTR_NEWCONN),
- "allow-transcoding", "Allow transcoding\n")
+DEFUN_DEPRECATED(cfg_mgcp_allow_transcoding,
+ cfg_mgcp_allow_transcoding_cmd,
+ "allow-transcoding", "Allow transcoding\n")
{
- struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL,
MGCP_VIRT_TRUNK_ID);
- OSMO_ASSERT(trunk);
- trunk->no_audio_transcoding = 0;
return CMD_SUCCESS;
}
-DEFUN_USRATTR(cfg_mgcp_no_allow_transcoding,
- cfg_mgcp_no_allow_transcoding_cmd,
- X(MGW_CMD_ATTR_NEWCONN),
- "no allow-transcoding", NO_STR "Allow transcoding\n")
+DEFUN_DEPRECATED(cfg_mgcp_no_allow_transcoding,
+ cfg_mgcp_no_allow_transcoding_cmd,
+ "no allow-transcoding", NO_STR "Allow transcoding\n")
{
- struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL,
MGCP_VIRT_TRUNK_ID);
- OSMO_ASSERT(trunk);
- trunk->no_audio_transcoding = 1;
return CMD_SUCCESS;
}
@@ -1069,8 +1059,6 @@
if (trunk->audio_fmtp_extra)
vty_out(vty, " sdp audio fmtp-extra %s%s",
trunk->audio_fmtp_extra, VTY_NEWLINE);
- vty_out(vty, " %sallow-transcoding%s",
- trunk->no_audio_transcoding ? "no " : "", VTY_NEWLINE);
}
return CMD_SUCCESS;
@@ -1319,23 +1307,17 @@
return CMD_SUCCESS;
}
-DEFUN_USRATTR(cfg_trunk_allow_transcoding,
- cfg_trunk_allow_transcoding_cmd,
- X(MGW_CMD_ATTR_NEWCONN),
- "allow-transcoding", "Allow transcoding\n")
+DEFUN_DEPRECATED(cfg_trunk_allow_transcoding,
+ cfg_trunk_allow_transcoding_cmd,
+ "allow-transcoding", "Allow transcoding\n")
{
- struct mgcp_trunk *trunk = vty->index;
- trunk->no_audio_transcoding = 0;
return CMD_SUCCESS;
}
-DEFUN_USRATTR(cfg_trunk_no_allow_transcoding,
- cfg_trunk_no_allow_transcoding_cmd,
- X(MGW_CMD_ATTR_NEWCONN),
- "no allow-transcoding", NO_STR "Allow transcoding\n")
+DEFUN_DEPRECATED(cfg_trunk_no_allow_transcoding,
+ cfg_trunk_no_allow_transcoding_cmd,
+ "no allow-transcoding", NO_STR "Allow transcoding\n")
{
- struct mgcp_trunk *trunk = vty->index;
- trunk->no_audio_transcoding = 1;
return CMD_SUCCESS;
}
diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c
index bc2dae0..ea6e2e5 100644
--- a/tests/mgcp/mgcp_test.c
+++ b/tests/mgcp/mgcp_test.c
@@ -1467,7 +1467,6 @@
/* Allocate 5@mgw and let osmo-mgw pick a codec from the list */
last_endpoint[0] = '\0';
inp = create_msg(CRCX_MULT_GSM_EXACT, NULL);
- trunk->no_audio_transcoding = 1;
resp = mgcp_handle_message(cfg, inp);
OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id,
sizeof(conn_id)) == 0);
@@ -1511,7 +1510,6 @@
last_endpoint[0] = '\0';
inp = create_msg(CRCX_MULT_GSM_EXACT, NULL);
- trunk->no_audio_transcoding = 0;
resp = mgcp_handle_message(cfg, inp);
OSMO_ASSERT(get_conn_id_from_response(resp->data, conn_id,
sizeof(conn_id)) == 0);
@@ -1769,26 +1767,25 @@
.amr_octet_aligned_present = false,
};
-struct testcase_mgcp_codec_find_convertible_codec {
+struct testcase_mgcp_codec_decide_codec {
int payload_type;
const char *audio_name;
const struct mgcp_codec_param *param;
int expect_rc;
};
-struct testcase_mgcp_codec_find_convertible_expect {
- bool end;
+struct testcase_mgcp_codec_decide_expect {
int payload_type_map[2];
};
-struct testcase_mgcp_codec_find_convertible {
+struct testcase_mgcp_codec_decide {
const char *descr;
/* two conns on an endpoint, each with N configured codecs */
- struct testcase_mgcp_codec_find_convertible_codec codecs[2][10];
- struct testcase_mgcp_codec_find_convertible_expect expect[32];
+ struct testcase_mgcp_codec_decide_codec codecs[2][10];
+ struct testcase_mgcp_codec_decide_expect expect[2];
};
-static const struct testcase_mgcp_codec_find_convertible
test_mgcp_codec_find_convertible_cases[] = {
+static const struct testcase_mgcp_codec_decide test_mgcp_codec_find_convertible_cases[] =
{
{
.descr = "same order, but differing payload type numbers",
.codecs = {
@@ -1805,12 +1802,10 @@
},
.expect = {
{ .payload_type_map = {112, 96}, },
- { .payload_type_map = {0, 0}, },
- { .payload_type_map = {111, 97} },
- { .payload_type_map = {123, -EINVAL} },
- { .end = true },
+ { .payload_type_map = {112, 96}, },
},
},
+
{
.descr = "different order and different payload type numbers",
.codecs = {
@@ -1826,11 +1821,8 @@
},
},
.expect = {
- { .payload_type_map = {112, 96}, },
{ .payload_type_map = {0, 0}, },
- { .payload_type_map = {111, 97} },
- { .payload_type_map = {123, -EINVAL} },
- { .end = true },
+ { .payload_type_map = {111, 97}, },
},
},
{
@@ -1848,11 +1840,8 @@
},
},
.expect = {
- { .payload_type_map = {96, 97}, },
- { .payload_type_map = {97, 96}, },
{ .payload_type_map = {0, 0}, },
- { .payload_type_map = {123, -EINVAL} },
- { .end = true },
+ { .payload_type_map = {96, 97}, },
},
},
{
@@ -1868,10 +1857,8 @@
},
},
.expect = {
- { .payload_type_map = {112, -EINVAL}, },
- { .payload_type_map = {0, -EINVAL}, },
- { .payload_type_map = {111, -EINVAL} },
- { .end = true },
+ { .payload_type_map = {-EINVAL, -EINVAL}, },
+ { .payload_type_map = {-EINVAL, 96}, },
},
},
{
@@ -1888,13 +1875,11 @@
},
.expect = {
{ .payload_type_map = {112, -EINVAL}, },
- { .payload_type_map = {0, -EINVAL}, },
- { .payload_type_map = {111, -EINVAL} },
- { .end = true },
+ { .payload_type_map = {-EINVAL, -EINVAL}, },
},
},
{
- .descr = "test AMR with differing octet-aligned settings",
+ .descr = "test AMR with differing octet-aligned settings (both <->
both)",
.codecs = {
{
{ 111, "AMR/8000", &amr_param_octet_aligned_true, },
@@ -1908,8 +1893,38 @@
.expect = {
{ .payload_type_map = {111, 121}, },
{ .payload_type_map = {112, 122} },
- { .payload_type_map = {123, -EINVAL} },
- { .end = true },
+ },
+ },
+ {
+ .descr = "test AMR with differing octet-aligned settings (oa <->
both)",
+ .codecs = {
+ {
+ { 111, "AMR/8000", &amr_param_octet_aligned_true, },
+ },
+ {
+ { 122, "AMR/8000", &amr_param_octet_aligned_false, },
+ { 121, "AMR/8000", &amr_param_octet_aligned_true, },
+ },
+ },
+ .expect = {
+ { .payload_type_map = {111, 121}, },
+ { .payload_type_map = {111, 121}, },
+ },
+ },
+ {
+ .descr = "test AMR with differing octet-aligned settings (bwe <->
both)",
+ .codecs = {
+ {
+ { 112, "AMR/8000", &amr_param_octet_aligned_false, },
+ },
+ {
+ { 122, "AMR/8000", &amr_param_octet_aligned_false, },
+ { 121, "AMR/8000", &amr_param_octet_aligned_true, },
+ },
+ },
+ .expect = {
+ { .payload_type_map = {112, 122}, },
+ { .payload_type_map = {112, 122}, },
},
},
{
@@ -1924,8 +1939,7 @@
},
.expect = {
{ .payload_type_map = {111, 122}, },
- { .payload_type_map = {55, -EINVAL}, },
- { .end = true },
+ { .payload_type_map = {111, 122}, },
},
},
{
@@ -1940,8 +1954,7 @@
},
.expect = {
{ .payload_type_map = {111, 122}, },
- { .payload_type_map = {55, -EINVAL}, },
- { .end = true },
+ { .payload_type_map = {111, 122}, },
},
},
{
@@ -1957,10 +1970,10 @@
.expect = {
/* Note: Both 111, anbd 112 will translate to 122. The translation from 112 */
{ .payload_type_map = {112, 122} },
- { .payload_type_map = {55, -EINVAL}, },
- { .end = true },
+ { .payload_type_map = {112, 122}, },
},
},
+
{
.descr = "test AMR with NULL param (bwe <-> null)",
.codecs = {
@@ -1974,8 +1987,7 @@
.expect = {
/* Note: Both 111, anbd 112 will translate to 122. The translation from 112 */
{ .payload_type_map = {112, 122} },
- { .payload_type_map = {55, -EINVAL}, },
- { .end = true },
+ { .payload_type_map = {112, 122}, },
},
},
{
@@ -1993,11 +2005,8 @@
},
},
.expect = {
- { .payload_type_map = {112, 96}, },
{ .payload_type_map = {0, 0}, },
- { .payload_type_map = {111, 97} },
- { .payload_type_map = {123, -EINVAL} },
- { .end = true },
+ { .payload_type_map = {111, 97}, },
},
},
{
@@ -2015,11 +2024,8 @@
},
},
.expect = {
- { .payload_type_map = {112, 96}, },
{ .payload_type_map = {0, 0}, },
- { .payload_type_map = {111, 97} },
- { .payload_type_map = {123, -EINVAL} },
- { .end = true },
+ { .payload_type_map = {111, 97}, },
},
},
{
@@ -2037,70 +2043,97 @@
},
.expect = {
{ .payload_type_map = {111, 121}, },
- { .payload_type_map = {112, -EINVAL} },
- { .payload_type_map = {113, -EINVAL} },
- { .end = true },
+ { .payload_type_map = {111, 121} },
},
},
};
-static int pt_translate(struct mgcp_conn_rtp *conn, unsigned int index_src, unsigned int
index_dst, int payload_type)
+static bool codec_decision(struct mgcp_conn_rtp *conn, unsigned int index_conn, unsigned
int index_conn_opposite,
+ const struct testcase_mgcp_codec_decide_expect *expect)
{
- struct mgcp_rtp_codec *codec_src = NULL;
- struct mgcp_rtp_codec *codec_dst = NULL;
- struct mgcp_conn_rtp *conn_src = &conn[index_src];
- struct mgcp_conn_rtp *conn_dst = &conn[index_dst];
+ bool ok = true;
+ int payload_type_conn;
+ int payload_type_conn_opposite;
- /* Find the codec information that is used on the source side */
- codec_src = mgcp_codec_from_pt(conn_src, payload_type);
- if (!codec_src) {
- printf(" - mgcp_codec_from_pt(conn%u, %d) -> NO RESULT\n", index_src,
payload_type);
- return -EINVAL;
- }
- printf(" - mgcp_codec_from_pt(conn%u, %d) -> %s\n", index_src,
payload_type, codec_src->subtype_name);
+ printf(" - mgcp_codec_decide(&conn[%u], &conn[%u]):\n", index_conn,
index_conn_opposite);
+ if (mgcp_codec_decide(&conn[index_conn], &conn[index_conn_opposite]) != 0) {
+ if (expect->payload_type_map[index_conn] == -EINVAL
+ && expect->payload_type_map[index_conn_opposite] == -EINVAL)
+ printf(" codec decision failed (expected)!\n");
+ else {
+ printf(" ERROR: codec decision failed!\n");
+ ok = false;
+ }
+ } else {
+ printf(" Codec decision result:\n");
+ if (conn[index_conn].end.codec) {
+ payload_type_conn = conn[index_conn].end.codec->payload_type;
+ printf(" conn[%u]: codec:%s, pt:%d\n",
+ index_conn, conn[index_conn].end.codec->subtype_name, payload_type_conn);
+ } else {
+ payload_type_conn = -EINVAL;
+ printf(" conn[%u]: codec:none, pt:none\n", index_conn);
+ }
- codec_dst = mgcp_codec_find_convertible(conn_dst, codec_src);
- if (!codec_dst) {
- printf(" - mgcp_codec_find_convertible(conn%u, %s) -> NO RESULT\n",
index_dst, codec_src->subtype_name);
- return -EINVAL;
+ if (conn[index_conn_opposite].end.codec) {
+ payload_type_conn_opposite = conn[index_conn_opposite].end.codec->payload_type;
+ printf(" conn[%u]: codec:%s, pt:%d\n",
+ index_conn_opposite, conn[index_conn_opposite].end.codec->subtype_name,
+ payload_type_conn_opposite);
+ } else {
+ payload_type_conn_opposite = -EINVAL;
+ printf(" conn[%u]: codec:none, pt:none\n", index_conn_opposite);
+ }
+
+ if (payload_type_conn != expect->payload_type_map[index_conn]) {
+ printf(" ERROR: conn[%u] unexpected codec decision, expected pt=%d, got
pt=%d\n",
+ index_conn, expect->payload_type_map[index_conn], payload_type_conn);
+ ok = false;
+ }
+
+ if (payload_type_conn_opposite != expect->payload_type_map[index_conn_opposite]) {
+ printf(" ERROR: conn[%u] unexpected codec decision, expected pt=%d, got
pt=%d\n",
+ index_conn_opposite, expect->payload_type_map[index_conn_opposite],
+ payload_type_conn_opposite);
+ ok = false;
+ }
}
- printf(" - mgcp_codec_find_convertible(conn%u, %s) -> %s -> %u\n",
- index_dst, codec_src->subtype_name, codec_dst->subtype_name,
codec_dst->payload_type);
- return codec_dst->payload_type;
+
+ return ok;
}
-static void test_mgcp_codec_find_convertible(void)
+static void test_mgcp_codec_decide(void)
{
int i;
bool ok = true;
printf("\nTesting mgcp_codec_find_convertible()\n");
for (i = 0; i < ARRAY_SIZE(test_mgcp_codec_find_convertible_cases); i++) {
- const struct testcase_mgcp_codec_find_convertible *t =
&test_mgcp_codec_find_convertible_cases[i];
- struct mgcp_conn_rtp conn[2] = {};
+ const struct testcase_mgcp_codec_decide *t =
&test_mgcp_codec_find_convertible_cases[i];
+ struct mgcp_conn_rtp conn[2] = { };
int rc;
int conn_i;
int c;
printf("#%d: %s\n", i, t->descr);
+ /* Build testvector (add codecs to conn, set properties etc... */
for (conn_i = 0; conn_i < 2; conn_i++) {
printf(" - add codecs on conn%d:\n", conn_i);
for (c = 0; c < ARRAY_SIZE(t->codecs[conn_i]); c++) {
- const struct testcase_mgcp_codec_find_convertible_codec *codec =
&t->codecs[conn_i][c];
+ const struct testcase_mgcp_codec_decide_codec *codec = &t->codecs[conn_i][c];
if (!codec->audio_name)
break;
- rc = mgcp_codec_add(&conn[conn_i], codec->payload_type, codec->audio_name,
codec->param);
+ rc = mgcp_codec_add(&conn[conn_i], 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 ?
- (codec->param->amr_octet_aligned_present?
- (codec->param->amr_octet_aligned ?
- " octet-aligned=1" : " octet-aligned=0")
- : " octet-aligned=unset")
- : "",
- rc);
+ (codec->param->amr_octet_aligned_present ?
+ (codec->param->amr_octet_aligned ? " octet-aligned=1" : "
octet-aligned=0")
+ : " octet-aligned=unset")
+ : "", rc);
if (rc != codec->expect_rc) {
printf(" ERROR: expected rc=%d\n", codec->expect_rc);
ok = false;
@@ -2110,32 +2143,17 @@
printf(" (none)\n");
}
- for (c = 0; c < ARRAY_SIZE(t->expect); c++) {
- const struct testcase_mgcp_codec_find_convertible_expect *expect =
&t->expect[c];
- int result;
+ /* Run codec decision and check expectation */
+ if (!codec_decision(conn, 0, 1, &t->expect[0]))
+ ok = false;
- if (expect->end)
- break;
+ if (!codec_decision(conn, 1, 0, &t->expect[1]))
+ ok = false;
- result = pt_translate(conn, 0, 1, expect->payload_type_map[0]);
- if (result != expect->payload_type_map[1]) {
- printf(" ERROR: expected -> %d\n", expect->payload_type_map[1]);
- ok = false;
- }
-
- /* If the expected result is an error, don't do reverse map test */
- if (expect->payload_type_map[1] < 0)
- continue;
-
- result = pt_translate(conn, 1, 0, expect->payload_type_map[1]);
- if (result != expect->payload_type_map[0]) {
- printf(" ERROR: expected -> %d\n", expect->payload_type_map[0]);
- ok = false;
- }
- }
-
- for (conn_i = 0; conn_i < 2; conn_i++)
- mgcp_codec_reset_all(&conn[conn_i]);
+ if (ok)
+ printf(" ===> SUCCESS: codec decision as expected!\n");
+ else
+ printf(" ===> FAIL: unexpected codec decision!\n");
}
OSMO_ASSERT(ok);
@@ -2295,7 +2313,7 @@
test_osmux_cid();
test_get_lco_identifier();
test_check_local_cx_options(ctx);
- test_mgcp_codec_find_convertible();
+ test_mgcp_codec_decide();
test_conn_id_matching();
test_e1_trunk_nr_from_epname();
test_mgcp_is_rtp_dummy_payload();
diff --git a/tests/mgcp/mgcp_test.ok b/tests/mgcp/mgcp_test.ok
index 4ea9a34..08df5d4 100644
--- a/tests/mgcp/mgcp_test.ok
+++ b/tests/mgcp/mgcp_test.ok
Binary files differ
--
To view, visit
https://gerrit.osmocom.org/c/osmo-mgw/+/32218
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: osmo-mgw
Gerrit-Branch: master
Gerrit-Change-Id: I6c3291f825488e5d8ce136aeb18450156794aeb5
Gerrit-Change-Number: 32218
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier(a)sysmocom.de>
Gerrit-MessageType: newchange