summaryrefslogtreecommitdiff
path: root/bridges
diff options
context:
space:
mode:
authorKevin Harwell <kharwell@digium.com>2017-04-25 11:49:16 -0500
committerKevin Harwell <kharwell@digium.com>2017-05-03 16:36:22 -0500
commit7b0e3b92fd49e5fbe406ef74336e164eb3f31b6e (patch)
treebe14294023edfbb6698f4c8e8b25d529756e5aee /bridges
parentbdec0852b96a9475a013f88949ad162511fd8404 (diff)
bridge_simple: Added support for streams
This patch is the first cut at adding stream support to the bridging framework. Changes were made to the framework that allows mapping of stream topologies to a bridge's supported media types. The first channel to enter a bridge initially defines the media types for a bridge (i.e. a one to one mapping is created between the bridge and the first channel). Subsequently added channels merge their media types into the bridge's adding to it when necessary. This allows channels with different sized topologies to map correctly to each other according to media type. The bridge drops any frame that does not have a matching index into a given write stream. For now though, bridge_simple will align its two channels according to size or first to join. Once both channels join the bridge the one with the most streams will indicate to the other channel to update its streams to be the same as that of the other. If both channels have the same number of streams then the first channel to join is chosen as the stream base. A topology change source was also added to a channel when a stream toplogy change request is made. This allows subsystems to know whether or not they initiated a change request. Thus avoiding potential recursive situations. ASTERISK-26966 #close Change-Id: I1eb5987921dd80c3cdcf52accc136393ca2d4163
Diffstat (limited to 'bridges')
-rw-r--r--bridges/bridge_simple.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/bridges/bridge_simple.c b/bridges/bridge_simple.c
index 35544f84f..47f41cbb3 100644
--- a/bridges/bridge_simple.c
+++ b/bridges/bridge_simple.c
@@ -42,6 +42,10 @@
#include "asterisk/bridge.h"
#include "asterisk/bridge_technology.h"
#include "asterisk/frame.h"
+#include "asterisk/stream.h"
+
+static void simple_bridge_stream_topology_changed(struct ast_bridge *bridge,
+ struct ast_bridge_channel *bridge_channel);
static int simple_bridge_join(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel)
{
@@ -56,7 +60,13 @@ static int simple_bridge_join(struct ast_bridge *bridge, struct ast_bridge_chann
return 0;
}
- return ast_channel_make_compatible(c0, c1);
+ if (ast_channel_make_compatible(c0, c1)) {
+ return -1;
+ }
+
+ /* Align stream topologies */
+ simple_bridge_stream_topology_changed(bridge, NULL);
+ return 0;
}
static int simple_bridge_write(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame)
@@ -70,8 +80,34 @@ static struct ast_bridge_technology simple_bridge = {
.preference = AST_BRIDGE_PREFERENCE_BASE_1TO1MIX,
.join = simple_bridge_join,
.write = simple_bridge_write,
+ .stream_topology_changed = simple_bridge_stream_topology_changed,
};
+static void simple_bridge_stream_topology_changed(struct ast_bridge *bridge,
+ struct ast_bridge_channel *bridge_channel)
+{
+ struct ast_channel *c0 = AST_LIST_FIRST(&bridge->channels)->chan;
+ struct ast_channel *c1 = AST_LIST_LAST(&bridge->channels)->chan;
+ struct ast_stream_topology *t0 = ast_channel_get_stream_topology(c0);
+ struct ast_stream_topology *t1 = ast_channel_get_stream_topology(c1);
+
+ /*
+ * The bridge_channel should only be NULL after both channels join
+ * the bridge and their topologies are being aligned.
+ */
+ if (bridge_channel && ast_channel_get_stream_topology_change_source(
+ bridge_channel->chan) == &simple_bridge) {
+ return;
+ }
+
+ /* Align topologies according to size or first channel to join */
+ if (ast_stream_topology_get_count(t0) < ast_stream_topology_get_count(t1)) {
+ ast_channel_request_stream_topology_change(c0, t1, &simple_bridge);
+ } else {
+ ast_channel_request_stream_topology_change(c1, t0, &simple_bridge);
+ }
+}
+
static int unload_module(void)
{
ast_bridge_technology_unregister(&simple_bridge);