[Asterisk-code-review] res_pjsip_sdp_rtp: Preserve order of RTP codecs (asterisk[18])
Joshua Colp
asteriskteam at digium.com
Wed Jan 5 07:14:55 CST 2022
Joshua Colp has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/17519 )
Change subject: res_pjsip_sdp_rtp: Preserve order of RTP codecs
......................................................................
res_pjsip_sdp_rtp: Preserve order of RTP codecs
The ast_rtp_codecs_payloads functions do not preserve the order in which
the payloads were specified on an incoming SDP media line. This leads to
a problem with the codec negotiation functionality, as the format
capabilities of the stream are extracted from the ast_rtp_codecs. This
commit moves the ast_rtp_codec to ast_format conversion to the place
where the order is still known.
ASTERISK-28863
ASTERISK-29320
Change-Id: I3aabcfed3f379c36654f59c1872c313d0cb57e25
---
M res/res_pjsip_sdp_rtp.c
1 file changed, 15 insertions(+), 8 deletions(-)
Approvals:
Joshua Colp: Looks good to me, approved; Approved for Submit
George Joseph: Looks good to me, approved; Verified
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index ae200a7..10db010 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -313,7 +313,7 @@
}
static void get_codecs(struct ast_sip_session *session, const struct pjmedia_sdp_media *stream, struct ast_rtp_codecs *codecs,
- struct ast_sip_session_media *session_media)
+ struct ast_sip_session_media *session_media, struct ast_format_cap *astformats)
{
pjmedia_sdp_attr *attr;
pjmedia_sdp_rtpmap *rtpmap;
@@ -329,6 +329,8 @@
ast_rtp_codecs_payloads_initialize(codecs);
+ ast_format_cap_remove_by_type(astformats, AST_MEDIA_TYPE_UNKNOWN);
+
/* Iterate through provided formats */
for (i = 0; i < stream->desc.fmt_count; ++i) {
/* The payload is kept as a string for things like t38 but for video it is always numerical */
@@ -372,11 +374,19 @@
ast_rtp_codecs_payload_replace_format(codecs, num, format_parsed);
ao2_ref(format_parsed, -1);
}
-
ao2_ref(format, -1);
}
}
}
+
+ /* Parsing done, now fill the ast_format_cap struct in the correct order */
+ for (i = 0; i < stream->desc.fmt_count; ++i) {
+ if ((format = ast_rtp_codecs_get_payload_format(codecs, pj_strtoul(&stream->desc.fmt[i])))) {
+ ast_format_cap_append(astformats, format, 0);
+ ao2_ref(format, -1);
+ }
+ }
+
if (!tel_event && (session->dtmf == AST_SIP_DTMF_AUTO)) {
ast_rtp_instance_dtmf_mode_set(session_media->rtp, AST_RTP_DTMF_MODE_INBAND);
ast_rtp_instance_set_prop(session_media->rtp, AST_RTP_PROPERTY_DTMF, 0);
@@ -398,6 +408,7 @@
unsigned long framing = pj_strtoul(pj_strltrim(&attr->value));
if (framing && session->endpoint->media.rtp.use_ptime) {
ast_rtp_codecs_set_framing(codecs, framing);
+ ast_format_cap_set_framing(astformats, framing);
}
}
@@ -442,7 +453,6 @@
struct ast_format_cap *incoming_call_offer_cap;
struct ast_format_cap *remote;
struct ast_rtp_codecs codecs = AST_RTP_CODECS_NULL_INIT;
- int fmts = 0;
SCOPE_ENTER(1, "%s\n", ast_sip_session_get_name(session));
@@ -454,8 +464,7 @@
}
/* Get the peer's capabilities*/
- get_codecs(session, stream, &codecs, session_media);
- ast_rtp_codecs_payload_formats(&codecs, remote, &fmts);
+ get_codecs(session, stream, &codecs, session_media, remote);
incoming_call_offer_cap = ast_sip_session_create_joint_call_cap(
session, session_media->type, remote);
@@ -493,7 +502,6 @@
RAII_VAR(struct ast_format_cap *, joint, NULL, ao2_cleanup);
enum ast_media_type media_type = session_media->type;
struct ast_rtp_codecs codecs = AST_RTP_CODECS_NULL_INIT;
- int fmts = 0;
int direct_media_enabled = !ast_sockaddr_isnull(&session_media->direct_media_addr) &&
ast_format_cap_count(session->direct_media_cap);
int dsp_features = 0;
@@ -516,8 +524,7 @@
}
/* get the capabilities on the peer */
- get_codecs(session, stream, &codecs, session_media);
- ast_rtp_codecs_payload_formats(&codecs, peer, &fmts);
+ get_codecs(session, stream, &codecs, session_media, peer);
/* get the joint capabilities between peer and endpoint */
ast_format_cap_get_compatible(caps, peer, joint);
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/17519
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 18
Gerrit-Change-Id: I3aabcfed3f379c36654f59c1872c313d0cb57e25
Gerrit-Change-Number: 17519
Gerrit-PatchSet: 6
Gerrit-Owner: Florentin Mayer <f.mayer at commend.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220105/27a73e40/attachment-0001.html>
More information about the asterisk-code-review
mailing list