[Asterisk-code-review] res/res_pjsip_session.c: Check that media type matches in function as... (asterisk[16])

Friendly Automation asteriskteam at digium.com
Mon Jan 18 11:15:06 CST 2021


Friendly Automation has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/15230 )

Change subject: res/res_pjsip_session.c: Check that media type matches in function ast_sip_session_media_state_add.
......................................................................

res/res_pjsip_session.c: Check that media type matches in
function ast_sip_session_media_state_add.

Check ast_media_type matches when a ast_sip_session_media is found
otherwise when transitioning from say image to audio, the wrong
session is returned in the first if statement.

ASTERISK-29220 #close

Change-Id: I6f6efa9b821ebe8881bb4c8c957f8802ddcb4b5d
---
M res/res_pjsip_session.c
1 file changed, 6 insertions(+), 3 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved
  Friendly Automation: Approved for Submit



diff --git a/res/res_pjsip_session.c b/res/res_pjsip_session.c
index 960b72d..1d26309 100644
--- a/res/res_pjsip_session.c
+++ b/res/res_pjsip_session.c
@@ -490,15 +490,16 @@
 	struct ast_sip_session_media_state *media_state, enum ast_media_type type, int position)
 {
 	struct ast_sip_session_media *session_media = NULL;
+	struct ast_sip_session_media *current_session_media = NULL;
 	SCOPE_ENTER(1, "%s Adding position %d\n", ast_sip_session_get_name(session), position);
 
 	/* It is possible for this media state to already contain a session for the stream. If this
 	 * is the case we simply return it.
 	 */
 	if (position < AST_VECTOR_SIZE(&media_state->sessions)) {
-		session_media = AST_VECTOR_GET(&media_state->sessions, position);
-		if (session_media) {
-			SCOPE_EXIT_RTN_VALUE(session_media, "Using existing media_session\n");
+		current_session_media = AST_VECTOR_GET(&media_state->sessions, position);
+		if (current_session_media && current_session_media->type == type) {
+			SCOPE_EXIT_RTN_VALUE(current_session_media, "Using existing media_session\n");
 		}
 	}
 
@@ -575,6 +576,8 @@
 		SCOPE_EXIT_RTN_VALUE(NULL, "Couldn't replace media_session\n");
 	}
 
+	ao2_cleanup(current_session_media);
+
 	/* If this stream will be active in some way and it is the first of this type then consider this the default media session to match */
 	if (!media_state->default_session[type] && ast_stream_get_state(ast_stream_topology_get_stream(media_state->topology, position)) != AST_STREAM_STATE_REMOVED) {
 		ast_trace(1, "Setting media session as default for %s\n", ast_codec_media_type2str(session_media->type));

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/15230
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: I6f6efa9b821ebe8881bb4c8c957f8802ddcb4b5d
Gerrit-Change-Number: 15230
Gerrit-PatchSet: 6
Gerrit-Owner: Robert Cripps <rcripps at voxbone.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Sean Bright <sean.bright at gmail.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20210118/bf5930ce/attachment.html>


More information about the asterisk-code-review mailing list