Merge "bridge_softmix.c: Don't match dead streams."
[asterisk/asterisk.git] / bridges / bridge_softmix.c
index c8dd8ea..83b1a83 100644 (file)
@@ -668,6 +668,7 @@ static int softmix_bridge_join(struct ast_bridge *bridge, struct ast_bridge_chan
                                ast_log(LOG_ERROR, "Bridge %s: Failed to join channel %s. "
                                                "Could not allocate enough memory.\n", bridge->uniqueid,
                                                ast_channel_name(bridge_channel->chan));
+                               ast_free(sc);
                                return -1;
                        }
                }
@@ -693,10 +694,11 @@ static int softmix_bridge_join(struct ast_bridge *bridge, struct ast_bridge_chan
        return 0;
 }
 
-static void remove_destination_streams(struct ast_stream_topology *topology,
+static int remove_destination_streams(struct ast_stream_topology *topology,
        const char *channel_name)
 {
        int i;
+       int stream_removed = 0;
 
        for (i = 0; i < ast_stream_topology_get_count(topology); ++i) {
                struct ast_stream *stream;
@@ -705,8 +707,10 @@ static void remove_destination_streams(struct ast_stream_topology *topology,
 
                if (is_video_dest(stream, channel_name, NULL)) {
                        ast_stream_set_state(stream, AST_STREAM_STATE_REMOVED);
+                       stream_removed = 1;
                }
        }
+       return stream_removed;
 }
 
 static int sfu_topologies_on_leave(struct ast_bridge_channel *leaver, struct ast_bridge_channels_list *participants)
@@ -716,13 +720,16 @@ static int sfu_topologies_on_leave(struct ast_bridge_channel *leaver, struct ast
 
        AST_LIST_TRAVERSE(participants, participant, entry) {
                sc = participant->tech_pvt;
-               remove_destination_streams(sc->topology, ast_channel_name(leaver->chan));
+               if (!remove_destination_streams(sc->topology, ast_channel_name(leaver->chan))) {
+                       continue;
+               }
                ast_channel_request_stream_topology_change(participant->chan, sc->topology, NULL);
        }
 
        sc = leaver->tech_pvt;
-       remove_destination_streams(sc->topology, "");
-       ast_channel_request_stream_topology_change(leaver->chan, sc->topology, NULL);
+       if (remove_destination_streams(sc->topology, "")) {
+               ast_channel_request_stream_topology_change(leaver->chan, sc->topology, NULL);
+       }
 
        return 0;
 }
@@ -1302,6 +1309,8 @@ static int softmix_mixing_array_grow(struct softmix_mixing_array *mixing_array,
                ast_log(LOG_NOTICE, "Failed to re-allocate softmix mixing structure.\n");
                return -1;
        }
+       mixing_array->buffers = tmp;
+
        if (binaural_active) {
                struct convolve_channel_pair **tmp2;
                if (!(tmp2 = ast_realloc(mixing_array->chan_pairs,
@@ -1311,7 +1320,6 @@ static int softmix_mixing_array_grow(struct softmix_mixing_array *mixing_array,
                }
                mixing_array->chan_pairs = tmp2;
        }
-       mixing_array->buffers = tmp;
        return 0;
 }