<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/5846">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  Kevin Harwell: Looks good to me, approved
  Jenkins2: Approved for Submit

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">stream: Ignore declined streams for some topology calls.<br><br>* Made ast_format_cap_from_stream_topology() not include any formats from<br>declined streams.<br><br>* Made ast_stream_topology_get_first_stream_by_type() ignore declined<br>streams to return the first active stream of the type.<br><br>* Updated unit tests to check these changes have the expected effect.<br><br>Change-Id: Iabbc6a3e8edf263a25fd3056c3c614407c7897df<br>---<br>M include/asterisk/stream.h<br>M main/stream.c<br>M tests/test_stream.c<br>3 files changed, 90 insertions(+), 16 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/include/asterisk/stream.h b/include/asterisk/stream.h<br>index 14d624f..00169a3 100644<br>--- a/include/asterisk/stream.h<br>+++ b/include/asterisk/stream.h<br>@@ -401,8 +401,11 @@<br>     struct ast_format_cap *cap);<br> <br> /*!<br>- * \brief A helper function that, given a stream topology, creates a format<br>- * capabilities structure containing all formats from all streams.<br>+ * \brief Create a format capabilities structure representing the topology.<br>+ *<br>+ * \details<br>+ * A helper function that, given a stream topology, creates a format<br>+ * capabilities structure containing all formats from all active streams.<br>  *<br>  * \param topology The topology of streams<br>  *<br>@@ -417,7 +420,7 @@<br>      struct ast_stream_topology *topology);<br> <br> /*!<br>- * \brief Gets the first stream of a specific type from the topology<br>+ * \brief Gets the first active stream of a specific type from the topology<br>  *<br>  * \param topology The topology of streams<br>  * \param type The media type<br>diff --git a/main/stream.c b/main/stream.c<br>index b617744..20179f3 100644<br>--- a/main/stream.c<br>+++ b/main/stream.c<br>@@ -437,9 +437,11 @@<br>     }<br> <br>  for (i = 0; i < AST_VECTOR_SIZE(&topology->streams); i++) {<br>-                struct ast_stream *stream = AST_VECTOR_GET(&topology->streams, i);<br>+            struct ast_stream *stream;<br> <br>-                if (!stream->formats) {<br>+           stream = AST_VECTOR_GET(&topology->streams, i);<br>+               if (!stream->formats<br>+                      || stream->state == AST_STREAM_STATE_REMOVED) {<br>                    continue;<br>             }<br> <br>@@ -458,9 +460,11 @@<br>    ast_assert(topology != NULL);<br> <br>      for (i = 0; i < AST_VECTOR_SIZE(&topology->streams); i++) {<br>-                struct ast_stream *stream = AST_VECTOR_GET(&topology->streams, i);<br>+            struct ast_stream *stream;<br> <br>-                if (stream->type == type) {<br>+               stream = AST_VECTOR_GET(&topology->streams, i);<br>+               if (stream->type == type<br>+                  && stream->state != AST_STREAM_STATE_REMOVED) {<br>                    return stream;<br>                }<br>     }<br>diff --git a/tests/test_stream.c b/tests/test_stream.c<br>index cf3d2e3..fdb9885 100644<br>--- a/tests/test_stream.c<br>+++ b/tests/test_stream.c<br>@@ -755,7 +755,12 @@<br> AST_TEST_DEFINE(stream_topology_get_first_stream_by_type)<br> {<br>  RAII_VAR(struct ast_stream_topology *, topology, NULL, ast_stream_topology_free);<br>-    struct ast_stream *first_stream, *second_stream, *third_stream, *fourth_stream;<br>+      struct ast_stream *first_stream;<br>+     struct ast_stream *second_stream;<br>+    struct ast_stream *third_stream;<br>+     struct ast_stream *fourth_stream;<br>+    struct ast_stream *fifth_stream;<br>+     struct ast_stream *sixth_stream;<br> <br>   switch (cmd) {<br>        case TEST_INIT:<br>@@ -780,6 +785,7 @@<br>          ast_test_status_update(test, "Failed to create an audio stream for testing stream topology\n");<br>             return AST_TEST_FAIL;<br>         }<br>+    ast_stream_set_state(first_stream, AST_STREAM_STATE_REMOVED);<br> <br>      if (ast_stream_topology_append_stream(topology, first_stream) == -1) {<br>                ast_test_status_update(test, "Failed to append a perfectly good stream to a topology\n");<br>@@ -799,9 +805,9 @@<br>              return AST_TEST_FAIL;<br>         }<br> <br>- third_stream = ast_stream_alloc("video", AST_MEDIA_TYPE_VIDEO);<br>+    third_stream = ast_stream_alloc("audio3", AST_MEDIA_TYPE_AUDIO);<br>    if (!third_stream) {<br>-         ast_test_status_update(test, "Failed to create a video stream for testing stream topology\n");<br>+             ast_test_status_update(test, "Failed to create a third audio stream for testing stream topology\n");<br>                return AST_TEST_FAIL;<br>         }<br> <br>@@ -811,11 +817,12 @@<br>           return AST_TEST_FAIL;<br>         }<br> <br>- fourth_stream = ast_stream_alloc("video2", AST_MEDIA_TYPE_VIDEO);<br>+  fourth_stream = ast_stream_alloc("video", AST_MEDIA_TYPE_VIDEO);<br>    if (!fourth_stream) {<br>-                ast_test_status_update(test, "Failed to create a second video stream for testing stream topology\n");<br>+              ast_test_status_update(test, "Failed to create a video stream for testing stream topology\n");<br>              return AST_TEST_FAIL;<br>         }<br>+    ast_stream_set_state(fourth_stream, AST_STREAM_STATE_REMOVED);<br> <br>     if (ast_stream_topology_append_stream(topology, fourth_stream) == -1) {<br>               ast_test_status_update(test, "Failed to append a perfectly good stream to a topology\n");<br>@@ -823,12 +830,36 @@<br>            return AST_TEST_FAIL;<br>         }<br> <br>- if (ast_stream_topology_get_first_stream_by_type(topology, AST_MEDIA_TYPE_AUDIO) != first_stream) {<br>+  fifth_stream = ast_stream_alloc("video2", AST_MEDIA_TYPE_VIDEO);<br>+   if (!fifth_stream) {<br>+         ast_test_status_update(test, "Failed to create a second video stream for testing stream topology\n");<br>+              return AST_TEST_FAIL;<br>+        }<br>+<br>+ if (ast_stream_topology_append_stream(topology, fifth_stream) == -1) {<br>+               ast_test_status_update(test, "Failed to append a perfectly good stream to a topology\n");<br>+          ast_stream_free(fifth_stream);<br>+               return AST_TEST_FAIL;<br>+        }<br>+<br>+ sixth_stream = ast_stream_alloc("video3", AST_MEDIA_TYPE_VIDEO);<br>+   if (!sixth_stream) {<br>+         ast_test_status_update(test, "Failed to create a third video stream for testing stream topology\n");<br>+               return AST_TEST_FAIL;<br>+        }<br>+<br>+ if (ast_stream_topology_append_stream(topology, sixth_stream) == -1) {<br>+               ast_test_status_update(test, "Failed to append a perfectly good stream to a topology\n");<br>+          ast_stream_free(sixth_stream);<br>+               return AST_TEST_FAIL;<br>+        }<br>+<br>+ if (ast_stream_topology_get_first_stream_by_type(topology, AST_MEDIA_TYPE_AUDIO) != second_stream) {<br>          ast_test_status_update(test, "Retrieved first audio stream from topology but it is not the correct one\n");<br>                 return AST_TEST_FAIL;<br>         }<br> <br>- if (ast_stream_topology_get_first_stream_by_type(topology, AST_MEDIA_TYPE_VIDEO) != third_stream) {<br>+  if (ast_stream_topology_get_first_stream_by_type(topology, AST_MEDIA_TYPE_VIDEO) != fifth_stream) {<br>           ast_test_status_update(test, "Retrieved first video stream from topology but it is not the correct one\n");<br>                 return AST_TEST_FAIL;<br>         }<br>@@ -1918,6 +1949,8 @@<br>      RAII_VAR(struct ast_format_cap *, caps, NULL, ao2_cleanup);<br>   RAII_VAR(struct ast_format_cap *, stream_caps, NULL, ao2_cleanup);<br>    struct ast_stream_topology *topology;<br>+        struct ast_stream *stream;<br>+   struct ast_format_cap *new_cap;<br> <br>    switch (cmd) {<br>        case TEST_INIT:<br>@@ -1938,12 +1971,12 @@<br>      }<br> <br>  if (ast_format_cap_append(caps, ast_format_ulaw, 0)) {<br>-               ast_test_status_update(test, "Failed to append a ulaw format to capabilities for channel nativeformats\n");<br>+                ast_test_status_update(test, "Failed to append ulaw format to capabilities\n");<br>             return AST_TEST_FAIL;<br>         }<br> <br>  if (ast_format_cap_append(caps, ast_format_h264, 0)) {<br>-               ast_test_status_update(test, "Failed to append an h264 format to capabilities for channel nativeformats\n");<br>+               ast_test_status_update(test, "Failed to append h264 format to capabilities\n");<br>             return AST_TEST_FAIL;<br>         }<br> <br>@@ -1953,6 +1986,40 @@<br>          return AST_TEST_FAIL;<br>         }<br> <br>+ /*<br>+    * Append declined stream with formats that should not be included<br>+    * in combined topology caps.<br>+         */<br>+  stream = ast_stream_alloc("audio", AST_MEDIA_TYPE_AUDIO);<br>+  if (!stream) {<br>+               ast_test_status_update(test, "Failed to create an audio stream for testing stream topology\n");<br>+            ast_stream_topology_free(topology);<br>+          return AST_TEST_FAIL;<br>+        }<br>+    ast_stream_set_state(stream, AST_STREAM_STATE_REMOVED);<br>+      new_cap = ast_format_cap_alloc(AST_FORMAT_CAP_FLAG_DEFAULT);<br>+ if (!new_cap) {<br>+              ast_test_status_update(test, "Could not allocate an empty format capabilities structure\n");<br>+               ast_stream_free(stream);<br>+             ast_stream_topology_free(topology);<br>+          return AST_TEST_FAIL;<br>+        }<br>+    if (ast_format_cap_append(new_cap, ast_format_alaw, 0)) {<br>+            ast_test_status_update(test, "Failed to append alaw format to capabilities\n");<br>+            ao2_cleanup(new_cap);<br>+                ast_stream_free(stream);<br>+             ast_stream_topology_free(topology);<br>+          return AST_TEST_FAIL;<br>+        }<br>+    ast_stream_set_formats(stream, new_cap);<br>+     ao2_cleanup(new_cap);<br>+        if (ast_stream_topology_append_stream(topology, stream) == -1) {<br>+             ast_test_status_update(test, "Failed to append a perfectly good stream to a topology\n");<br>+          ast_stream_free(stream);<br>+             ast_stream_topology_free(topology);<br>+          return AST_TEST_FAIL;<br>+        }<br>+<br>  stream_caps = ast_format_cap_from_stream_topology(topology);<br>  if (!stream_caps) {<br>           ast_test_status_update(test, "Failed to create a format capabilities from a stream topology\n");<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/5846">change 5846</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/5846"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Iabbc6a3e8edf263a25fd3056c3c614407c7897df </div>
<div style="display:none"> Gerrit-Change-Number: 5846 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>