[asterisk-commits] stream: Ignore declined streams for some topology calls. (asterisk[master])
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Fri Jun 16 11:51:42 CDT 2017
Jenkins2 has submitted this change and it was merged. ( https://gerrit.asterisk.org/5846 )
Change subject: stream: Ignore declined streams for some topology calls.
......................................................................
stream: Ignore declined streams for some topology calls.
* Made ast_format_cap_from_stream_topology() not include any formats from
declined streams.
* Made ast_stream_topology_get_first_stream_by_type() ignore declined
streams to return the first active stream of the type.
* Updated unit tests to check these changes have the expected effect.
Change-Id: Iabbc6a3e8edf263a25fd3056c3c614407c7897df
---
M include/asterisk/stream.h
M main/stream.c
M tests/test_stream.c
3 files changed, 90 insertions(+), 16 deletions(-)
Approvals:
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Jenkins2: Approved for Submit
diff --git a/include/asterisk/stream.h b/include/asterisk/stream.h
index 14d624f..00169a3 100644
--- a/include/asterisk/stream.h
+++ b/include/asterisk/stream.h
@@ -401,8 +401,11 @@
struct ast_format_cap *cap);
/*!
- * \brief A helper function that, given a stream topology, creates a format
- * capabilities structure containing all formats from all streams.
+ * \brief Create a format capabilities structure representing the topology.
+ *
+ * \details
+ * A helper function that, given a stream topology, creates a format
+ * capabilities structure containing all formats from all active streams.
*
* \param topology The topology of streams
*
@@ -417,7 +420,7 @@
struct ast_stream_topology *topology);
/*!
- * \brief Gets the first stream of a specific type from the topology
+ * \brief Gets the first active stream of a specific type from the topology
*
* \param topology The topology of streams
* \param type The media type
diff --git a/main/stream.c b/main/stream.c
index b617744..20179f3 100644
--- a/main/stream.c
+++ b/main/stream.c
@@ -437,9 +437,11 @@
}
for (i = 0; i < AST_VECTOR_SIZE(&topology->streams); i++) {
- struct ast_stream *stream = AST_VECTOR_GET(&topology->streams, i);
+ struct ast_stream *stream;
- if (!stream->formats) {
+ stream = AST_VECTOR_GET(&topology->streams, i);
+ if (!stream->formats
+ || stream->state == AST_STREAM_STATE_REMOVED) {
continue;
}
@@ -458,9 +460,11 @@
ast_assert(topology != NULL);
for (i = 0; i < AST_VECTOR_SIZE(&topology->streams); i++) {
- struct ast_stream *stream = AST_VECTOR_GET(&topology->streams, i);
+ struct ast_stream *stream;
- if (stream->type == type) {
+ stream = AST_VECTOR_GET(&topology->streams, i);
+ if (stream->type == type
+ && stream->state != AST_STREAM_STATE_REMOVED) {
return stream;
}
}
diff --git a/tests/test_stream.c b/tests/test_stream.c
index cf3d2e3..fdb9885 100644
--- a/tests/test_stream.c
+++ b/tests/test_stream.c
@@ -755,7 +755,12 @@
AST_TEST_DEFINE(stream_topology_get_first_stream_by_type)
{
RAII_VAR(struct ast_stream_topology *, topology, NULL, ast_stream_topology_free);
- struct ast_stream *first_stream, *second_stream, *third_stream, *fourth_stream;
+ struct ast_stream *first_stream;
+ struct ast_stream *second_stream;
+ struct ast_stream *third_stream;
+ struct ast_stream *fourth_stream;
+ struct ast_stream *fifth_stream;
+ struct ast_stream *sixth_stream;
switch (cmd) {
case TEST_INIT:
@@ -780,6 +785,7 @@
ast_test_status_update(test, "Failed to create an audio stream for testing stream topology\n");
return AST_TEST_FAIL;
}
+ ast_stream_set_state(first_stream, AST_STREAM_STATE_REMOVED);
if (ast_stream_topology_append_stream(topology, first_stream) == -1) {
ast_test_status_update(test, "Failed to append a perfectly good stream to a topology\n");
@@ -799,9 +805,9 @@
return AST_TEST_FAIL;
}
- third_stream = ast_stream_alloc("video", AST_MEDIA_TYPE_VIDEO);
+ third_stream = ast_stream_alloc("audio3", AST_MEDIA_TYPE_AUDIO);
if (!third_stream) {
- ast_test_status_update(test, "Failed to create a video stream for testing stream topology\n");
+ ast_test_status_update(test, "Failed to create a third audio stream for testing stream topology\n");
return AST_TEST_FAIL;
}
@@ -811,11 +817,12 @@
return AST_TEST_FAIL;
}
- fourth_stream = ast_stream_alloc("video2", AST_MEDIA_TYPE_VIDEO);
+ fourth_stream = ast_stream_alloc("video", AST_MEDIA_TYPE_VIDEO);
if (!fourth_stream) {
- ast_test_status_update(test, "Failed to create a second video stream for testing stream topology\n");
+ ast_test_status_update(test, "Failed to create a video stream for testing stream topology\n");
return AST_TEST_FAIL;
}
+ ast_stream_set_state(fourth_stream, AST_STREAM_STATE_REMOVED);
if (ast_stream_topology_append_stream(topology, fourth_stream) == -1) {
ast_test_status_update(test, "Failed to append a perfectly good stream to a topology\n");
@@ -823,12 +830,36 @@
return AST_TEST_FAIL;
}
- if (ast_stream_topology_get_first_stream_by_type(topology, AST_MEDIA_TYPE_AUDIO) != first_stream) {
+ fifth_stream = ast_stream_alloc("video2", AST_MEDIA_TYPE_VIDEO);
+ if (!fifth_stream) {
+ ast_test_status_update(test, "Failed to create a second video stream for testing stream topology\n");
+ return AST_TEST_FAIL;
+ }
+
+ if (ast_stream_topology_append_stream(topology, fifth_stream) == -1) {
+ ast_test_status_update(test, "Failed to append a perfectly good stream to a topology\n");
+ ast_stream_free(fifth_stream);
+ return AST_TEST_FAIL;
+ }
+
+ sixth_stream = ast_stream_alloc("video3", AST_MEDIA_TYPE_VIDEO);
+ if (!sixth_stream) {
+ ast_test_status_update(test, "Failed to create a third video stream for testing stream topology\n");
+ return AST_TEST_FAIL;
+ }
+
+ if (ast_stream_topology_append_stream(topology, sixth_stream) == -1) {
+ ast_test_status_update(test, "Failed to append a perfectly good stream to a topology\n");
+ ast_stream_free(sixth_stream);
+ return AST_TEST_FAIL;
+ }
+
+ if (ast_stream_topology_get_first_stream_by_type(topology, AST_MEDIA_TYPE_AUDIO) != second_stream) {
ast_test_status_update(test, "Retrieved first audio stream from topology but it is not the correct one\n");
return AST_TEST_FAIL;
}
- if (ast_stream_topology_get_first_stream_by_type(topology, AST_MEDIA_TYPE_VIDEO) != third_stream) {
+ if (ast_stream_topology_get_first_stream_by_type(topology, AST_MEDIA_TYPE_VIDEO) != fifth_stream) {
ast_test_status_update(test, "Retrieved first video stream from topology but it is not the correct one\n");
return AST_TEST_FAIL;
}
@@ -1918,6 +1949,8 @@
RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);
RAII_VAR(struct ast_format_cap *, stream_caps, NULL, ao2_cleanup);
struct ast_stream_topology *topology;
+ struct ast_stream *stream;
+ struct ast_format_cap *new_cap;
switch (cmd) {
case TEST_INIT:
@@ -1938,12 +1971,12 @@
}
if (ast_format_cap_append(caps, ast_format_ulaw, 0)) {
- ast_test_status_update(test, "Failed to append a ulaw format to capabilities for channel nativeformats\n");
+ ast_test_status_update(test, "Failed to append ulaw format to capabilities\n");
return AST_TEST_FAIL;
}
if (ast_format_cap_append(caps, ast_format_h264, 0)) {
- ast_test_status_update(test, "Failed to append an h264 format to capabilities for channel nativeformats\n");
+ ast_test_status_update(test, "Failed to append h264 format to capabilities\n");
return AST_TEST_FAIL;
}
@@ -1953,6 +1986,40 @@
return AST_TEST_FAIL;
}
+ /*
+ * Append declined stream with formats that should not be included
+ * in combined topology caps.
+ */
+ stream = ast_stream_alloc("audio", AST_MEDIA_TYPE_AUDIO);
+ if (!stream) {
+ ast_test_status_update(test, "Failed to create an audio stream for testing stream topology\n");
+ ast_stream_topology_free(topology);
+ return AST_TEST_FAIL;
+ }
+ ast_stream_set_state(stream, AST_STREAM_STATE_REMOVED);
+ new_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);
+ if (!new_cap) {
+ ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");
+ ast_stream_free(stream);
+ ast_stream_topology_free(topology);
+ return AST_TEST_FAIL;
+ }
+ if (ast_format_cap_append(new_cap, ast_format_alaw, 0)) {
+ ast_test_status_update(test, "Failed to append alaw format to capabilities\n");
+ ao2_cleanup(new_cap);
+ ast_stream_free(stream);
+ ast_stream_topology_free(topology);
+ return AST_TEST_FAIL;
+ }
+ ast_stream_set_formats(stream, new_cap);
+ ao2_cleanup(new_cap);
+ if (ast_stream_topology_append_stream(topology, stream) == -1) {
+ ast_test_status_update(test, "Failed to append a perfectly good stream to a topology\n");
+ ast_stream_free(stream);
+ ast_stream_topology_free(topology);
+ return AST_TEST_FAIL;
+ }
+
stream_caps = ast_format_cap_from_stream_topology(topology);
if (!stream_caps) {
ast_test_status_update(test, "Failed to create a format capabilities from a stream topology\n");
--
To view, visit https://gerrit.asterisk.org/5846
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: Iabbc6a3e8edf263a25fd3056c3c614407c7897df
Gerrit-Change-Number: 5846
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
Gerrit-Reviewer: Jenkins2
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-commits/attachments/20170616/a188eeaa/attachment-0001.html>
More information about the asterisk-commits
mailing list