]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res/res_pjsip_session.c: Check that media type matches in
authorRobert Cripps <rcripps@voxbone.com>
Tue, 22 Dec 2020 10:42:35 +0000 (11:42 +0100)
committerJoshua Colp <jcolp@sangoma.com>
Mon, 18 Jan 2021 17:30:26 +0000 (11:30 -0600)
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

res/res_pjsip_session.c

index ac4b8771e8de2c7f4b87de989a83abc0773f3ad0..d841aca04eb103a297b308e3729a13774725cd2e 100644 (file)
@@ -491,15 +491,16 @@ struct ast_sip_session_media *ast_sip_session_media_state_add(struct ast_sip_ses
        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");
                }
        }
 
@@ -576,6 +577,8 @@ struct ast_sip_session_media *ast_sip_session_media_state_add(struct ast_sip_ses
                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));