summaryrefslogtreecommitdiff
path: root/include
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 /include
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 'include')
-rw-r--r--include/asterisk/bridge.h3
-rw-r--r--include/asterisk/bridge_channel.h27
-rw-r--r--include/asterisk/bridge_technology.h19
-rw-r--r--include/asterisk/channel.h13
-rw-r--r--include/asterisk/channel_internal.h2
-rw-r--r--include/asterisk/stream.h23
6 files changed, 86 insertions, 1 deletions
diff --git a/include/asterisk/bridge.h b/include/asterisk/bridge.h
index ffe08da13..a9b01a6bb 100644
--- a/include/asterisk/bridge.h
+++ b/include/asterisk/bridge.h
@@ -323,6 +323,9 @@ struct ast_bridge {
/*! Immutable bridge UUID. */
AST_STRING_FIELD(uniqueid);
);
+
+ /*! Type mapping used for media routing */
+ struct ast_vector_int media_types;
};
/*! \brief Bridge base class virtual method table. */
diff --git a/include/asterisk/bridge_channel.h b/include/asterisk/bridge_channel.h
index a7971df27..dd72f3275 100644
--- a/include/asterisk/bridge_channel.h
+++ b/include/asterisk/bridge_channel.h
@@ -183,6 +183,12 @@ struct ast_bridge_channel {
unsigned int padding:30;
};
};
+ struct {
+ /*! An index mapping of where a channel's media needs to be routed */
+ struct ast_vector_int to_bridge;
+ /*! An index mapping of where a bridge's media needs to be routed */
+ struct ast_vector_int to_channel;
+ } stream_map;
};
/*!
@@ -704,6 +710,27 @@ void ast_bridge_channel_feature_digit_add(struct ast_bridge_channel *bridge_chan
*/
void ast_bridge_channel_feature_digit(struct ast_bridge_channel *bridge_channel, int digit);
+/*!
+ * \brief Maps a channel's stream topology to and from the bridge
+ * \since 15.0.0
+ *
+ * When a channel joins a bridge or its associated stream topology is updated, each stream
+ * in the topology needs to be mapped according to its media type to the bridge. Calling
+ * this method creates a mapping of each stream on the channel indexed to the bridge's
+ * supported media types and vice versa (i.e. bridge's media types indexed to channel
+ * streams).
+ *
+ * The first channel to join the bridge creates the initial order for the bridge's media
+ * types (e.g. a one to one mapping is made). Subsequently added channels are mapped to
+ * that order adding more media types if/when the newly added channel has more streams
+ * and/or media types specified by the bridge.
+ *
+ * \param bridge_channel Channel to map
+ *
+ * \return Nothing
+ */
+void ast_bridge_channel_stream_map(struct ast_bridge_channel *bridge_channel);
+
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
diff --git a/include/asterisk/bridge_technology.h b/include/asterisk/bridge_technology.h
index 843d93ccf..09b0fc0e8 100644
--- a/include/asterisk/bridge_technology.h
+++ b/include/asterisk/bridge_technology.h
@@ -158,6 +158,25 @@ struct ast_bridge_technology {
* \note On entry, bridge is already locked.
*/
int (*write)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame);
+ /*!
+ * \brief Callback for when a request has been made to change a stream topology on a channel
+ *
+ * This is called when a bridge receives a request to change the topology on the channel. A bridge
+ * technology should define a handler for this callback if it needs to update internals or intercept
+ * the request and not pass it on to other channels. This can be done by returning a nonzero value.
+ *
+ * \retval 0 Frame accepted by the bridge.
+ * \retval -1 Frame rejected.
+ */
+ int (*stream_topology_request_change)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
+ /*!
+ * \brief Callback for when a stream topology changes on the channel
+ *
+ * This is called when a bridge receives an indication that a topology has been changed on a channel
+ * and the new topology has been mapped to the bridge. A bridge technology should define a handler for
+ * this callback if it needs to update internals due to a channel's topology changing.
+ */
+ void (*stream_topology_changed)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
/*! TRUE if the bridge technology is currently suspended. */
unsigned int suspended:1;
/*! Module this bridge technology belongs to. It is used for reference counting bridges using the technology. */
diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index 128cd3056..889d3ff07 100644
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -4904,6 +4904,7 @@ int ast_channel_is_multistream(struct ast_channel *chan);
*
* \param chan The channel to change
* \param topology The new stream topology
+ * \param change_source The source that initiated the change
*
* \pre chan is locked
*
@@ -4918,7 +4919,8 @@ int ast_channel_is_multistream(struct ast_channel *chan);
* \note This interface is provided for applications and resources to request that the topology change.
* It is not for use by the channel driver itself.
*/
-int ast_channel_request_stream_topology_change(struct ast_channel *chan, struct ast_stream_topology *topology);
+int ast_channel_request_stream_topology_change(struct ast_channel *chan,
+ struct ast_stream_topology *topology, void *change_source);
/*!
* \brief Provide notice to a channel that the stream topology has changed
@@ -4936,4 +4938,13 @@ int ast_channel_request_stream_topology_change(struct ast_channel *chan, struct
*/
int ast_channel_stream_topology_changed(struct ast_channel *chan, struct ast_stream_topology *topology);
+/*!
+ * \brief Retrieve the source that initiated the last stream topology change
+ *
+ * \param chan The channel
+ *
+ * \retval The channel's stream topology change source
+ */
+void *ast_channel_get_stream_topology_change_source(struct ast_channel *chan);
+
#endif /* _ASTERISK_CHANNEL_H */
diff --git a/include/asterisk/channel_internal.h b/include/asterisk/channel_internal.h
index 3de2b14aa..dd791a416 100644
--- a/include/asterisk/channel_internal.h
+++ b/include/asterisk/channel_internal.h
@@ -29,5 +29,7 @@ void ast_channel_internal_errno_set(enum ast_channel_error error);
enum ast_channel_error ast_channel_internal_errno(void);
void ast_channel_internal_set_stream_topology(struct ast_channel *chan,
struct ast_stream_topology *topology);
+void ast_channel_internal_set_stream_topology_change_source(
+ struct ast_channel *chan, void *change_source);
void ast_channel_internal_swap_stream_topology(struct ast_channel *chan1,
struct ast_channel *chan2);
diff --git a/include/asterisk/stream.h b/include/asterisk/stream.h
index 1e07407a9..1bb34b72a 100644
--- a/include/asterisk/stream.h
+++ b/include/asterisk/stream.h
@@ -27,6 +27,7 @@
#define _AST_STREAM_H_
#include "asterisk/codec.h"
+#include "asterisk/vector.h"
/*!
* \brief Forward declaration for a stream, as it is opaque
@@ -43,6 +44,11 @@ struct ast_format_cap;
*/
struct ast_stream_topology;
+/*!
+ * \brief A mapping of two topologies.
+ */
+struct ast_stream_topology_map;
+
typedef void (*ast_stream_data_free_fn)(void *);
/*!
@@ -405,4 +411,21 @@ struct ast_stream *ast_stream_topology_get_first_stream_by_type(
const struct ast_stream_topology *topology,
enum ast_media_type type);
+/*!
+ * \brief Map a given topology's streams to the given types.
+ *
+ * \note The given vectors in which mapping values are placed are reset by
+ * this function. This means if those vectors already contain mapping
+ * values they will be lost.
+ *
+ * \param topology The topology to map
+ * \param types The media types to be mapped
+ * \param v0 Index mapping of topology to types
+ * \param v1 Index mapping of types to topology
+ *
+ * \since 15
+ */
+void ast_stream_topology_map(const struct ast_stream_topology *topology,
+ struct ast_vector_int *types, struct ast_vector_int *v0, struct ast_vector_int *v1);
+
#endif /* _AST_STREAM_H */