]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
bridge_channel: Don't queue unmapped frames.
authorJoshua C. Colp <jcolp@sangoma.com>
Fri, 5 Jun 2020 09:45:18 +0000 (06:45 -0300)
committerJoshua Colp <jcolp@sangoma.com>
Mon, 8 Jun 2020 15:49:49 +0000 (10:49 -0500)
If a frame is written to a channel in a bridge we
would normally queue this frame up and the channel
thread would then act upon it. If this frame had no
stream mapping on the channel it would then be
discarded.

This change adds a check before the queueing occurs
to determine if a mapping exists. If it does not
exist then the frame is not even queued at all. This
stops a frame duplication from happening and from
the channel thread having to wake up and deal with
it.

Change-Id: I17189b9b1dec45fc7e4490e8081d444a25a00bda

main/bridge_channel.c

index 8566187cc1dbc6a9269097ac39ab912856f8046b..251dea7e356e71765f0a6e451110af6bf249fc28 100644 (file)
@@ -1043,6 +1043,23 @@ int ast_bridge_channel_queue_frame(struct ast_bridge_channel *bridge_channel, st
                return 0;
        }
 
+       if ((fr->frametype == AST_FRAME_VOICE || fr->frametype == AST_FRAME_VIDEO ||
+               fr->frametype == AST_FRAME_TEXT || fr->frametype == AST_FRAME_IMAGE ||
+               fr->frametype == AST_FRAME_RTCP) && fr->stream_num > -1) {
+               int num = -1;
+
+               ast_bridge_channel_lock(bridge_channel);
+               if (fr->stream_num < (int)AST_VECTOR_SIZE(&bridge_channel->stream_map.to_channel)) {
+                       num = AST_VECTOR_GET(&bridge_channel->stream_map.to_channel, fr->stream_num);
+               }
+               ast_bridge_channel_unlock(bridge_channel);
+
+               if (num == -1) {
+                       /* We don't have a mapped stream so just discard this frame. */
+                       return 0;
+               }
+       }
+
        dup = ast_frdup(fr);
        if (!dup) {
                return -1;