[Asterisk-code-review] pjsip: Extend 'asymmetric rtp codec' option to include us ch... (asterisk[master])

Joshua Colp asteriskteam at digium.com
Wed Jun 7 04:17:04 CDT 2017


Joshua Colp has uploaded a new change for review. ( https://gerrit.asterisk.org/5767 )

Change subject: pjsip: Extend 'asymmetric_rtp_codec' option to include us changing.
......................................................................

pjsip: Extend 'asymmetric_rtp_codec' option to include us changing.

PJSIP support in Asterisk differs from chan_sip in that it
allows media to be sent as-is without transcoding provided
the codecs were negotiated in the SDP. This is allowed
according to the RFC. Support for this differs quite a lot
though and some endpoints do not handle it well.

This change extends the 'asymmetric_rtp_codec' option to
also cover this case. When set to no (the default) the code
behaves as chan_sip does - the best codec is selected and
we will only ever send that, unless we change what we are
sending if the remote side changes. When set to yes we
will send media as-is without transcoding if the codec
has been negotiated in the SDP.

ASTERISK-26996

Change-Id: Ib1647f6902a0843e8c435946f831c2159e8d1d51
---
M channels/chan_pjsip.c
M res/res_pjsip_sdp_rtp.c
2 files changed, 30 insertions(+), 1 deletion(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/67/5767/1

diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 5bf339e..19fb20b 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -735,11 +735,24 @@
 
 	if (!session->endpoint->asymmetric_rtp_codec &&
 		ast_format_cmp(ast_channel_rawwriteformat(ast), f->subclass.format) == AST_FORMAT_CMP_NOT_EQUAL) {
-		/* For maximum compatibility we ensure that the write format matches that of the received media */
+		struct ast_format_cap *caps;
+
+		/* For maximum compatibility we ensure that the formats match that of the received media */
 		ast_debug(1, "Oooh, got a frame with format of %s on channel '%s' when we're sending '%s', switching to match\n",
 			ast_format_get_name(f->subclass.format), ast_channel_name(ast),
 			ast_format_get_name(ast_channel_rawwriteformat(ast)));
+
+		caps = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+		if (caps) {
+			ast_format_cap_append_from_cap(caps, ast_channel_nativeformats(ast), AST_MEDIA_TYPE_UNKNOWN);
+			ast_format_cap_remove_by_type(caps, AST_MEDIA_TYPE_AUDIO);
+			ast_format_cap_append(caps, f->subclass.format, 0);
+			ast_channel_nativeformats_set(ast, caps);
+			ao2_ref(caps, -1);
+		}
+
 		ast_set_write_format_path(ast, ast_channel_writeformat(ast), f->subclass.format);
+		ast_set_read_format_path(ast, ast_channel_readformat(ast), f->subclass.format);
 
 		if (ast_channel_is_bridged(ast)) {
 			ast_channel_set_unbridged_nolock(ast, 1);
diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c
index 97e365c..c5a673a 100644
--- a/res/res_pjsip_sdp_rtp.c
+++ b/res/res_pjsip_sdp_rtp.c
@@ -410,13 +410,29 @@
 		ast_format_cap_append_from_cap(caps, ast_channel_nativeformats(session->channel),
 			AST_MEDIA_TYPE_UNKNOWN);
 		ast_format_cap_remove_by_type(caps, media_type);
+
 		if (session->endpoint->preferred_codec_only){
 			struct ast_format *preferred_fmt = ast_format_cap_get_format(joint, 0);
 			ast_format_cap_append(caps, preferred_fmt, 0);
 			ao2_ref(preferred_fmt, -1);
+		} else if (!session->endpoint->asymmetric_rtp_codec) {
+			struct ast_format *best;
+			/*
+			 * If we don't allow the sending codec to be changed on our side
+			 * then get the best codec from the joint capabilities of the media
+			 * type and use only that. This ensures the core won't start sending
+			 * out a format that we aren't currently sending.
+			 */
+
+			best = ast_format_cap_get_best_by_type(joint, media_type);
+			if (best) {
+				ast_format_cap_append(caps, best, ast_format_cap_get_framing(joint));
+				ao2_ref(best, -1);
+			}
 		} else {
 			ast_format_cap_append_from_cap(caps, joint, media_type);
 		}
+
 		/*
 		 * Apply the new formats to the channel, potentially changing
 		 * raw read/write formats and translation path while doing so.

-- 
To view, visit https://gerrit.asterisk.org/5767
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib1647f6902a0843e8c435946f831c2159e8d1d51
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Joshua Colp <jcolp at digium.com>



More information about the asterisk-code-review mailing list