[Asterisk-code-review] stream.c: Added 2 more debugging utils and added pos to stream string (asterisk[certified/16.8])

George Joseph asteriskteam at digium.com
Thu Sep 3 06:51:01 CDT 2020


George Joseph has submitted this change. ( https://gerrit.asterisk.org/c/asterisk/+/14739 )

Change subject: stream.c:  Added 2 more debugging utils and added pos to stream string
......................................................................

stream.c:  Added 2 more debugging utils and added pos to stream string

 * 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
---
M include/asterisk/stream.h
M main/stream.c
2 files changed, 51 insertions(+), 23 deletions(-)

Approvals:
  Joshua Colp: Looks good to me, but someone else must approve
  George Joseph: Looks good to me, approved; Approved for Submit



diff --git a/include/asterisk/stream.h b/include/asterisk/stream.h
index a91124b..caffef4 100644
--- a/include/asterisk/stream.h
+++ b/include/asterisk/stream.h
@@ -198,6 +198,19 @@
 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
  *
  * \param stream The media stream
@@ -610,4 +623,17 @@
  */
 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 */
diff --git a/main/stream.c b/main/stream.c
index 091eb1c..b02e09b 100644
--- a/main/stream.c
+++ b/main/stream.c
@@ -196,22 +196,23 @@
 
 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)
@@ -522,18 +523,18 @@
 
 int ast_stream_topology_get_active_count(const struct ast_stream_topology *topology)
 {
-       int i;
-       int count = 0;
-       ast_assert(topology != NULL);
+	int i;
+	int count = 0;
+	ast_assert(topology != NULL);
 
-       for (i = 0; i < AST_VECTOR_SIZE(&topology->streams); i++) {
-               struct ast_stream *stream = AST_VECTOR_GET(&topology->streams, i);
-               if (stream->state != AST_STREAM_STATE_REMOVED) {
-                       count++;
-               }
-       }
+	for (i = 0; i < AST_VECTOR_SIZE(&topology->streams); i++) {
+		struct ast_stream *stream = AST_VECTOR_GET(&topology->streams, i);
+		if (stream->state != AST_STREAM_STATE_REMOVED) {
+			count++;
+		}
+	}
 
-       return count;
+	return count;
 }
 
 struct ast_stream *ast_stream_topology_get_stream(
@@ -630,6 +631,7 @@
 			ast_stream_topology_free(topology);
 			return NULL;
 		}
+
 		/* We're transferring the initial ref so no bump needed */
 		stream->formats = new_cap;
 		stream->state = AST_STREAM_STATE_SENDRECV;

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14739
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: certified/16.8
Gerrit-Change-Id: Idaf4cb0affa46d4dce58a73a111f35435331cc4b
Gerrit-Change-Number: 14739
Gerrit-PatchSet: 5
Gerrit-Owner: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Benjamin Keith Ford <bford at digium.com>
Gerrit-Reviewer: Friendly Automation
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at sangoma.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200903/d68e4f7a/attachment-0001.html>


More information about the asterisk-code-review mailing list