diff options
author | Joshua Colp <jcolp@digium.com> | 2017-02-13 17:00:42 +0000 |
---|---|---|
committer | Joshua Colp <jcolp@digium.com> | 2017-02-13 17:00:42 +0000 |
commit | 6c4657e28ebf9cbe6d952750142d9631ff600657 (patch) | |
tree | 81376038c5727d9527c651cb3a1de6afff915659 /main/stream.c | |
parent | 8b72ec312bd9fc439383a24d3f5c29b638758fd3 (diff) |
stream: Add stream topology unit tests and fix uncovered bugs.
This change adds unit tests for the various API calls relating
to stream topologies. This includes creation, destruction,
inspection, and manipulation.
Through this a few bugs were uncovered in the implementation:
1. Creating a topology using a format capabilities would fail as
the code considered a return value of 0 from the append stream
function to indicate an error which is incorrect.
2. Not all functions which placed a stream into a topology
set the position on the stream itself.
3. Appending a stream would cause a frack if the position
provided was the last one. This occurred because the existing
stream was queried but the index was outside of what the
vector was currently at for size.
ASTERISK-26786
Change-Id: Id5590e87c8a605deea1a89e53169a9c011d66fa0
Diffstat (limited to 'main/stream.c')
-rw-r--r-- | main/stream.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/main/stream.c b/main/stream.c index 0fabfc738..24844c4ab 100644 --- a/main/stream.c +++ b/main/stream.c @@ -239,6 +239,8 @@ int ast_stream_topology_append_stream(struct ast_stream_topology *topology, stru return -1; } + stream->position = AST_VECTOR_SIZE(&topology->streams) - 1; + return AST_VECTOR_SIZE(&topology->streams) - 1; } @@ -268,15 +270,18 @@ int ast_stream_topology_set_stream(struct ast_stream_topology *topology, return -1; } - existing_stream = AST_VECTOR_GET(&topology->streams, position); - ast_stream_destroy(existing_stream); + if (position < AST_VECTOR_SIZE(&topology->streams)) { + existing_stream = AST_VECTOR_GET(&topology->streams, position); + ast_stream_destroy(existing_stream); + } + + stream->position = position; if (position == AST_VECTOR_SIZE(&topology->streams)) { AST_VECTOR_APPEND(&topology->streams, stream); return 0; } - stream->position = position; return AST_VECTOR_REPLACE(&topology->streams, position, stream); } @@ -323,7 +328,7 @@ struct ast_stream_topology *ast_stream_topology_create_from_format_cap( /* We're transferring the initial ref so no bump needed */ stream->formats = new_cap; stream->state = AST_STREAM_STATE_SENDRECV; - if (!ast_stream_topology_append_stream(topology, stream)) { + if (ast_stream_topology_append_stream(topology, stream) == -1) { ast_stream_destroy(stream); ast_stream_topology_destroy(topology); return NULL; |