]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
core: Show streams in "core show channel". 59/5059/1
authorJoshua Colp <jcolp@digium.com>
Wed, 22 Feb 2017 14:32:23 +0000 (14:32 +0000)
committerJoshua Colp <jcolp@digium.com>
Wed, 22 Feb 2017 14:32:23 +0000 (14:32 +0000)
The "core show channel" CLI command will now output the streams
present on the channel with their details.

ASTERISK-26811

Change-Id: I9c95b57aa09415005f0677a1949a0feb07e4987a

include/asterisk/stream.h
main/cli.c
main/stream.c

index edb00b9ebe5fa57f139590c69140d8f150f5c602..48ee883224e27af98970767384c7970827e0daa4 100644 (file)
@@ -190,6 +190,17 @@ enum ast_stream_state ast_stream_get_state(const struct ast_stream *stream);
  */
 void ast_stream_set_state(struct ast_stream *stream, enum ast_stream_state state);
 
+/*!
+ * \brief Convert the state of a stream into a string
+ *
+ * \param state The stream state
+ *
+ * \return The state of the stream in string format
+ *
+ * \since 15
+ */
+const char *ast_stream_state2str(enum ast_stream_state state);
+
 /*!
  * \brief Get the position of the stream in the topology
  *
index ccdbb97c3e472ecb06a48f6f56c724e0ae5e1531..06f2d55b2bbf718bee51a3f4341f1fd7e7165b72 100644 (file)
@@ -61,6 +61,7 @@
 #include "asterisk/stasis_channels.h"
 #include "asterisk/stasis_bridges.h"
 #include "asterisk/vector.h"
+#include "asterisk/stream.h"
 
 /*!
  * \brief List of restrictions per user.
@@ -1542,6 +1543,7 @@ static char *handle_showchan(struct ast_cli_entry *e, int cmd, struct ast_cli_ar
        struct ast_bridge *bridge;
        ast_callid callid;
        char callid_buf[32];
+       int stream_num;
 
        switch (cmd) {
        case CLI_INIT:
@@ -1668,6 +1670,7 @@ static char *handle_showchan(struct ast_cli_entry *e, int cmd, struct ast_cli_ar
                S_OR(ast_channel_data(chan), "(Empty)"),
                S_OR(callid_buf, "(None)")
                );
+
        ast_str_append(&output, 0, "      Variables:\n");
 
        AST_LIST_TRAVERSE(ast_channel_varshead(chan), var, entries) {
@@ -1679,6 +1682,22 @@ static char *handle_showchan(struct ast_cli_entry *e, int cmd, struct ast_cli_ar
                ast_str_append(&output, 0, "  CDR Variables:\n%s\n", ast_str_buffer(obuf));
        }
 
+       ast_str_append(&output, 0, " -- Streams --\n");
+       for (stream_num = 0; stream_num < ast_stream_topology_get_count(ast_channel_get_stream_topology(chan)); stream_num++) {
+               struct ast_stream *stream = ast_stream_topology_get_stream(ast_channel_get_stream_topology(chan), stream_num);
+
+               ast_str_append(&output, 0,
+                       "Name: %s\n"
+                       "    Type: %s\n"
+                       "    State: %s\n"
+                       "    Formats: %s\n",
+                       ast_stream_get_name(stream),
+                       ast_codec_media_type2str(ast_stream_get_type(stream)),
+                       ast_stream_state2str(ast_stream_get_state(stream)),
+                       ast_format_cap_get_names(ast_stream_get_formats(stream), &codec_buf)
+                       );
+       }
+
        ast_channel_unlock(chan);
 
        ast_cli(a->fd, "%s", ast_str_buffer(output));
index aacd33f1734629bcdf21fededd9306abbba12465..8bee2fdd0a913b5eb5b7552b3cf906d259f7e719 100644 (file)
@@ -168,6 +168,24 @@ void ast_stream_set_state(struct ast_stream *stream, enum ast_stream_state state
        stream->state = state;
 }
 
+const char *ast_stream_state2str(enum ast_stream_state state)
+{
+       switch (state) {
+       case AST_STREAM_STATE_REMOVED:
+               return "removed";
+       case AST_STREAM_STATE_SENDRECV:
+               return "sendrecv";
+       case AST_STREAM_STATE_SENDONLY:
+               return "sendonly";
+       case AST_STREAM_STATE_RECVONLY:
+               return "recvonly";
+       case AST_STREAM_STATE_INACTIVE:
+               return "inactive";
+       default:
+               return "<unknown>";
+       }
+}
+
 int ast_stream_get_position(const struct ast_stream *stream)
 {
        ast_assert(stream != NULL);