]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
stream.c: Added 2 more debugging utils and added pos to stream string
authorGeorge Joseph <gjoseph@digium.com>
Thu, 20 Aug 2020 13:32:03 +0000 (07:32 -0600)
committerFriendly Automation <jenkins2@gerrit.asterisk.org>
Mon, 24 Aug 2020 12:46:39 +0000 (07:46 -0500)
 * Added ast_stream_to_stra and ast_stream_topology_to_stra() macros
   which are shortcuts for
      ast_str_tmp(256, ast_stream_to_str(stream, &STR_TMP))

 * Added the stream position to the string representation of the
   stream.

 * Fixed some formatting in ast_stream_to_str().

Change-Id: Idaf4cb0affa46d4dce58a73a111f35435331cc4b

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

index 35781001951af11164cf1e1a660529fb9fc22aad..1c8e8756eac47bbae89d1c3415c5be59b1acdd7e 100644 (file)
@@ -197,6 +197,19 @@ void ast_stream_set_type(struct ast_stream *stream, enum ast_media_type type);
  */
 const char *ast_stream_to_str(const struct ast_stream *stream, struct ast_str **buf);
 
+/*!
+ * \brief Get a stack allocated string representing the stream for debugging/display purposes
+ *
+ * \param stream A stream
+ *
+ * \returns a stack allocated pointer to a string representing the stream.
+ *
+ * \warning No attempt should ever be made to free the returned
+ * char* as it is allocated from the stack.
+ *
+ */
+#define ast_stream_to_stra(__stream) ast_str_tmp(128, ast_stream_to_str(__stream, &STR_TMP))
+
 /*!
  * \brief Get the count of the current negotiated formats of a stream
  *
@@ -610,4 +623,17 @@ int ast_stream_topology_get_active_count(const struct ast_stream_topology *topol
  */
 const char *ast_stream_topology_to_str(const struct ast_stream_topology *topology, struct ast_str **buf);
 
+/*!
+ * \brief Get a stack allocated string representing the topology for debugging/display purposes
+ *
+ * \param topology A topology
+ *
+ * \returns a stack allocated pointer to a string representing the topology.
+ *
+ * \warning No attempt should ever be made to free the returned
+ * char* as it is allocated from the stack.
+ *
+ */
+#define ast_stream_topology_to_stra(__topology) ast_str_tmp(256, ast_stream_topology_to_str(__topology, &STR_TMP))
+
 #endif /* _AST_STREAM_H */
index 9c764d0e6870cc58e4a9fad291ea9b966ecdc2c1..5141ca39df6c635812a0acda79bbc4a1d9641f3e 100644 (file)
@@ -206,22 +206,23 @@ const struct ast_format_cap *ast_stream_get_formats(const struct ast_stream *str
 
 const char *ast_stream_to_str(const struct ast_stream *stream, struct ast_str **buf)
 {
-       if (!buf || !*buf) {
-               return "";
-       }
+       if (!buf || !*buf) {
+               return "";
+       }
 
-       if (!stream) {
-               ast_str_append(buf, 0, "(null stream)");
-               return ast_str_buffer(*buf);
-       }
+       if (!stream) {
+               ast_str_append(buf, 0, "(null stream)");
+               return ast_str_buffer(*buf);
+       }
 
-       ast_str_append(buf, 0, "%s:%s:%s ",
-               S_OR(stream->name, "noname"),
-               ast_codec_media_type2str(stream->type),
-               ast_stream_state_map[stream->state]);
-       ast_format_cap_append_names(stream->formats, buf);
+       ast_str_append(buf, 0, "%d:%s:%s:%s ",
+               stream->position,
+               S_OR(stream->name, "noname"),
+               ast_codec_media_type2str(stream->type),
+               ast_stream_state_map[stream->state]);
+       ast_format_cap_append_names(stream->formats, buf);
 
-       return ast_str_buffer(*buf);
+       return ast_str_buffer(*buf);
 }
 
 int ast_stream_get_format_count(const struct ast_stream *stream)