diff options
author | Kevin Harwell <kharwell@digium.com> | 2017-04-25 11:49:16 -0500 |
---|---|---|
committer | Kevin Harwell <kharwell@digium.com> | 2017-05-03 16:36:22 -0500 |
commit | 7b0e3b92fd49e5fbe406ef74336e164eb3f31b6e (patch) | |
tree | be14294023edfbb6698f4c8e8b25d529756e5aee /main/stream.c | |
parent | bdec0852b96a9475a013f88949ad162511fd8404 (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 'main/stream.c')
-rw-r--r-- | main/stream.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/main/stream.c b/main/stream.c index 39b6b1b13..0f2393359 100644 --- a/main/stream.c +++ b/main/stream.c @@ -434,3 +434,48 @@ struct ast_stream *ast_stream_topology_get_first_stream_by_type( return NULL; } + +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) +{ + int i; + int nths[AST_MEDIA_TYPE_END] = {0}; + int size = ast_stream_topology_get_count(topology); + + /* + * Clear out any old mappings and initialize the new ones + */ + AST_VECTOR_FREE(v0); + AST_VECTOR_FREE(v1); + + /* + * Both vectors are sized to the topology. The media types vector is always + * guaranteed to be the size of the given topology or greater. + */ + AST_VECTOR_INIT(v0, size); + AST_VECTOR_INIT(v1, size); + + for (i = 0; i < size; ++i) { + struct ast_stream *stream = ast_stream_topology_get_stream(topology, i); + enum ast_media_type type = ast_stream_get_type(stream); + int index = AST_VECTOR_GET_INDEX_NTH(types, ++nths[type], + type, AST_VECTOR_ELEM_DEFAULT_CMP); + + if (index == -1) { + /* + * If a given type is not found for an index level then update the + * media types vector with that type. This keeps the media types + * vector always at the max topology size. + */ + AST_VECTOR_APPEND(types, type); + index = AST_VECTOR_SIZE(types) - 1; + } + + /* + * The mapping is reflexive in the sense that if it maps in one direction + * then the reverse direction maps back to the other's index. + */ + AST_VECTOR_REPLACE(v0, i, index); + AST_VECTOR_REPLACE(v1, index, i); + } +} |