diff --git a/src/libosmo-mgcp/mgcp_codec.c b/src/libosmo-mgcp/mgcp_codec.c index 7f1a6d126..5d7f840fe 100644 --- a/src/libosmo-mgcp/mgcp_codec.c +++ b/src/libosmo-mgcp/mgcp_codec.c @@ -348,6 +348,25 @@ int mgcp_codec_decide(struct mgcp_conn_rtp *conn) return -EINVAL; } +/* 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": + * + * octet-align: Permissible values are 0 and 1. If 1, octet-aligned + * operation SHALL be used. If 0 or if not present, + * bandwidth-efficient operation is employed. + * + * https://tools.ietf.org/html/rfc4867 + */ +static bool amr_is_octet_aligned(const struct mgcp_rtp_codec *codec) +{ + if (!codec->param_present) + return false; + if (!codec->param.amr_octet_aligned_present) + return false; + return codec->param.amr_octet_aligned; +} + /* Compare two codecs, all parameters must match up, except for the payload type * number. */ static bool codecs_same(struct mgcp_rtp_codec *codec_a, struct mgcp_rtp_codec *codec_b) @@ -364,6 +383,10 @@ static bool codecs_same(struct mgcp_rtp_codec *codec_a, struct mgcp_rtp_codec *c return false; if (strcmp(codec_a->subtype_name, codec_b->subtype_name)) return false; + if (!strcmp(codec_a->subtype_name, "AMR")) { + if (amr_is_octet_aligned(codec_a) != amr_is_octet_aligned(codec_b)) + return false; + } return true; } diff --git a/tests/mgcp/mgcp_test.c b/tests/mgcp/mgcp_test.c index 460ea9b2f..5ebe475ec 100644 --- a/tests/mgcp/mgcp_test.c +++ b/tests/mgcp/mgcp_test.c @@ -1716,7 +1716,6 @@ static const struct mgcp_codec_param amr_param_octet_aligned_true = { .amr_octet_aligned = true, }; -#if 0 static const struct mgcp_codec_param amr_param_octet_aligned_false = { .amr_octet_aligned_present = true, .amr_octet_aligned = false, @@ -1725,7 +1724,6 @@ static const struct mgcp_codec_param amr_param_octet_aligned_false = { static const struct mgcp_codec_param amr_param_octet_aligned_unset = { .amr_octet_aligned_present = false, }; -#endif struct testcase_mgcp_codec_pt_translate_codec { int payload_type; @@ -1850,6 +1848,58 @@ static const struct testcase_mgcp_codec_pt_translate test_mgcp_codec_pt_translat { .end = true }, }, }, + { + .descr = "test AMR with differing octet-aligned settings", + .codecs = { + { + { 111, "AMR/8000", &amr_param_octet_aligned_true, }, + { 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 = {111, 121}, }, + { .payload_type_map = {112, 122} }, + { .end = true }, + }, + }, + { + .descr = "test AMR with missing octet-aligned settings (defaults to 0)", + .codecs = { + { + { 111, "AMR/8000", &amr_param_octet_aligned_true, }, + { 112, "AMR/8000", &amr_param_octet_aligned_false, }, + }, + { + { 122, "AMR/8000", &amr_param_octet_aligned_unset, }, + }, + }, + .expect = { + { .payload_type_map = {111, -EINVAL}, }, + { .payload_type_map = {112, 122} }, + { .end = true }, + }, + }, + { + .descr = "test AMR with NULL param (defaults to 0)", + .codecs = { + { + { 111, "AMR/8000", &amr_param_octet_aligned_true, }, + { 112, "AMR/8000", &amr_param_octet_aligned_false, }, + }, + { + { 122, "AMR/8000", NULL, }, + }, + }, + .expect = { + { .payload_type_map = {111, -EINVAL}, }, + { .payload_type_map = {112, 122} }, + { .end = true }, + }, + }, }; static void test_mgcp_codec_pt_translate(void) diff --git a/tests/mgcp/mgcp_test.ok b/tests/mgcp/mgcp_test.ok index 708e0c371..14d5d7373 100644 --- a/tests/mgcp/mgcp_test.ok +++ b/tests/mgcp/mgcp_test.ok @@ -1286,6 +1286,35 @@ Testing mgcp_codec_pt_translate() - mgcp_codec_pt_translate(conn0, conn1, 112) -> -22 - mgcp_codec_pt_translate(conn0, conn1, 0) -> -22 - mgcp_codec_pt_translate(conn0, conn1, 111) -> -22 +#5: test AMR with differing octet-aligned settings + - add codecs on conn0: + 0: 111 AMR/8000 octet-aligned=1 -> rc=0 + 1: 112 AMR/8000 octet-aligned=0 -> rc=0 + - add codecs on conn1: + 0: 122 AMR/8000 octet-aligned=0 -> rc=0 + 1: 121 AMR/8000 octet-aligned=1 -> rc=0 + - mgcp_codec_pt_translate(conn0, conn1, 111) -> 121 + - mgcp_codec_pt_translate(conn1, conn0, 121) -> 111 + - mgcp_codec_pt_translate(conn0, conn1, 112) -> 122 + - mgcp_codec_pt_translate(conn1, conn0, 122) -> 112 +#6: test AMR with missing octet-aligned settings (defaults to 0) + - add codecs on conn0: + 0: 111 AMR/8000 octet-aligned=1 -> rc=0 + 1: 112 AMR/8000 octet-aligned=0 -> rc=0 + - add codecs on conn1: + 0: 122 AMR/8000 octet-aligned=unset -> rc=0 + - mgcp_codec_pt_translate(conn0, conn1, 111) -> -22 + - mgcp_codec_pt_translate(conn0, conn1, 112) -> 122 + - mgcp_codec_pt_translate(conn1, conn0, 122) -> 112 +#7: test AMR with NULL param (defaults to 0) + - add codecs on conn0: + 0: 111 AMR/8000 octet-aligned=1 -> rc=0 + 1: 112 AMR/8000 octet-aligned=0 -> rc=0 + - add codecs on conn1: + 0: 122 AMR/8000 -> rc=0 + - mgcp_codec_pt_translate(conn0, conn1, 111) -> -22 + - mgcp_codec_pt_translate(conn0, conn1, 112) -> 122 + - mgcp_codec_pt_translate(conn1, conn0, 122) -> 112 Testing test_conn_id_matching needle='23AB' found '000023AB'