<p>George Joseph has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14727">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">scope_trace: Add/update utilities<br><br>* Added a AST_STREAM_STATE_END sentinel<br>* Add ast_stream_to_str()<br>* Add ast_stream_state_to_str()<br>* Add ast_stream_get_format_count()<br>* Add ast_stream_topology_to_str()<br>* Add ast_stream_topology_get_active_count()<br>* Add ast_format_cap_append_names()<br><br>Change-Id: I132eb5971ea41509c660f64e9113cda8c9013b0b<br>---<br>M include/asterisk/format_cap.h<br>M include/asterisk/stream.h<br>M main/format_cap.c<br>M main/stream.c<br>4 files changed, 195 insertions(+), 2 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/27/14727/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/format_cap.h b/include/asterisk/format_cap.h</span><br><span>index 37021eb..e9796bb 100644</span><br><span>--- a/include/asterisk/format_cap.h</span><br><span>+++ b/include/asterisk/format_cap.h</span><br><span>@@ -310,6 +310,17 @@</span><br><span> */</span><br><span> const char *ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Append the names of codecs of a set of formats to an ast_str buffer</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 18</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param cap The capabilities structure containing the formats</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param buf A \c ast_str buffer to append the names of the formats to</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return The contents of the buffer in \c buf</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+const char *ast_format_cap_append_names(const struct ast_format_cap *cap, struct ast_str **buf);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #ifndef AST_FORMAT_CAP_NAMES_LEN</span><br><span> /*! Buffer size for callers of ast_format_cap_get_names to allocate. */</span><br><span> #define AST_FORMAT_CAP_NAMES_LEN 384</span><br><span>diff --git a/include/asterisk/stream.h b/include/asterisk/stream.h</span><br><span>index 381ef36..3578100 100644</span><br><span>--- a/include/asterisk/stream.h</span><br><span>+++ b/include/asterisk/stream.h</span><br><span>@@ -75,9 +75,29 @@</span><br><span> * \brief Set when the stream is not sending OR receiving media</span><br><span> */</span><br><span> AST_STREAM_STATE_INACTIVE,</span><br><span style="color: hsl(120, 100%, 40%);">+ /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Sentinel</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+ AST_STREAM_STATE_END</span><br><span> };</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Stream state enum to string map</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+extern const char *ast_stream_state_map[AST_STREAM_STATE_END];</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Safely get the name of a stream state</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 18</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param stream_state One of enum ast_stream_state</span><br><span style="color: hsl(120, 100%, 40%);">+ * \returns A constant string with the name of the state or an empty string</span><br><span style="color: hsl(120, 100%, 40%);">+ * if an invalid value was passed in.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+#define ast_stream_state_to_str(stream_state) _stream_maps_to_str(ast_stream_state_map, stream_state)</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Create a new media stream representation</span><br><span> *</span><br><span> * \param name A name for the stream</span><br><span>@@ -153,6 +173,42 @@</span><br><span> void ast_stream_set_type(struct ast_stream *stream, enum ast_media_type type);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Get a string representing the stream for debugging/display purposes</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 18</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param stream A stream</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param buf A pointer to an ast_str* used for the output.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval "" (empty string) if either buf or *buf are NULL</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval "(null stream)" if *stream was NULL</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval <stream_representation> otherwise</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \warning No attempt should ever be made to free the returned</span><br><span style="color: hsl(120, 100%, 40%);">+ * char * and it should be dup'd if needed after the ast_str is freed.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \details</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Return format:</span><br><span style="color: hsl(120, 100%, 40%);">+ * <name>:<media_type>:<stream_state> (formats)</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Sample return:</span><br><span style="color: hsl(120, 100%, 40%);">+ * "audio:audio:sendrecv (ulaw,g722)"</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+const char *ast_stream_to_str(const struct ast_stream *stream, struct ast_str **buf);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Get the count of the current negotiated formats of a stream</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param stream The media stream</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return The count of negotiated formats</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 18</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_stream_get_format_count(const struct ast_stream *stream);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Get the current negotiated formats of a stream</span><br><span> *</span><br><span> * \param stream The media stream</span><br><span>@@ -523,4 +579,35 @@</span><br><span> */</span><br><span> void ast_stream_set_group(struct ast_stream *stream, int group);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Get the number of active (non-REMOVED) streams in a topology</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param topology The topology of streams</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return the number of active streams</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_stream_topology_get_active_count(const struct ast_stream_topology *topology);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Get a string representing the topology for debugging/display purposes</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param topology A stream topology</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param buf A pointer to an ast_str* used for the output.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval "" (empty string) if either buf or *buf are NULL</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval "(null topology)" if *topology was NULL</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval <topology_representation> otherwise</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \warning No attempt should ever be made to free the returned</span><br><span style="color: hsl(120, 100%, 40%);">+ * char * and it should be dup'd if needed after the ast_str is freed.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Return format:</span><br><span style="color: hsl(120, 100%, 40%);">+ * <stream> ...</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Sample return:</span><br><span style="color: hsl(120, 100%, 40%);">+ * "<audio:audio:sendrecv (ulaw,g722)> <video:video:sendonly (h264)>"</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+const char *ast_stream_topology_to_str(const struct ast_stream_topology *topology, struct ast_str **buf);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #endif /* _AST_STREAM_H */</span><br><span>diff --git a/main/format_cap.c b/main/format_cap.c</span><br><span>index ca60557..a97fd6d 100644</span><br><span>--- a/main/format_cap.c</span><br><span>+++ b/main/format_cap.c</span><br><span>@@ -699,11 +699,19 @@</span><br><span> return internal_format_cap_identical(cap2, cap1);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-const char *ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf)</span><br><span style="color: hsl(120, 100%, 40%);">+static const char *__ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf, int append)</span><br><span> {</span><br><span> int i;</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- ast_str_set(buf, 0, "(");</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!buf || !*buf) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return "";</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (append) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(buf, 0, "(");</span><br><span style="color: hsl(120, 100%, 40%);">+ } else {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_set(buf, 0, "(");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span> </span><br><span> if (!cap || !AST_VECTOR_SIZE(&cap->preference_order)) {</span><br><span> ast_str_append(buf, 0, "nothing)");</span><br><span>@@ -725,6 +733,16 @@</span><br><span> return ast_str_buffer(*buf);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+const char *ast_format_cap_get_names(const struct ast_format_cap *cap, struct ast_str **buf)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return __ast_format_cap_get_names(cap, buf, 0);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+const char *ast_format_cap_append_names(const struct ast_format_cap *cap, struct ast_str **buf)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ return __ast_format_cap_get_names(cap, buf, 1);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> int ast_format_cap_empty(const struct ast_format_cap *cap)</span><br><span> {</span><br><span> int count = ast_format_cap_count(cap);</span><br><span>diff --git a/main/stream.c b/main/stream.c</span><br><span>index 21dcede..9c764d0 100644</span><br><span>--- a/main/stream.c</span><br><span>+++ b/main/stream.c</span><br><span>@@ -93,6 +93,14 @@</span><br><span> AST_VECTOR(, struct ast_stream *) streams;</span><br><span> };</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+const char *ast_stream_state_map[] = {</span><br><span style="color: hsl(120, 100%, 40%);">+ [AST_STREAM_STATE_REMOVED] = "removed",</span><br><span style="color: hsl(120, 100%, 40%);">+ [AST_STREAM_STATE_SENDRECV] = "sendrecv",</span><br><span style="color: hsl(120, 100%, 40%);">+ [AST_STREAM_STATE_SENDONLY] = "sendonly",</span><br><span style="color: hsl(120, 100%, 40%);">+ [AST_STREAM_STATE_RECVONLY] = "recvonly",</span><br><span style="color: hsl(120, 100%, 40%);">+ [AST_STREAM_STATE_INACTIVE] = "inactive",</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> struct ast_stream *ast_stream_alloc(const char *name, enum ast_media_type type)</span><br><span> {</span><br><span> struct ast_stream *stream;</span><br><span>@@ -196,6 +204,33 @@</span><br><span> return stream->formats;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+const char *ast_stream_to_str(const struct ast_stream *stream, struct ast_str **buf)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!buf || !*buf) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return "";</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!stream) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(buf, 0, "(null stream)");</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_str_buffer(*buf);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(buf, 0, "%s:%s:%s ",</span><br><span style="color: hsl(120, 100%, 40%);">+ S_OR(stream->name, "noname"),</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_codec_media_type2str(stream->type),</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_stream_state_map[stream->state]);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_format_cap_append_names(stream->formats, buf);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_str_buffer(*buf);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_stream_get_format_count(const struct ast_stream *stream)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_assert(stream != NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return stream->formats ? ast_format_cap_count(stream->formats) : 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> void ast_stream_set_formats(struct ast_stream *stream, struct ast_format_cap *caps)</span><br><span> {</span><br><span> ast_assert(stream != NULL);</span><br><span>@@ -495,6 +530,22 @@</span><br><span> return AST_VECTOR_SIZE(&topology->streams);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int ast_stream_topology_get_active_count(const struct ast_stream_topology *topology)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int i;</span><br><span style="color: hsl(120, 100%, 40%);">+ int count = 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_assert(topology != NULL);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < AST_VECTOR_SIZE(&topology->streams); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_stream *stream = AST_VECTOR_GET(&topology->streams, i);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (stream->state != AST_STREAM_STATE_REMOVED) {</span><br><span style="color: hsl(120, 100%, 40%);">+ count++;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return count;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> struct ast_stream *ast_stream_topology_get_stream(</span><br><span> const struct ast_stream_topology *topology, unsigned int stream_num)</span><br><span> {</span><br><span>@@ -631,6 +682,32 @@</span><br><span> return caps;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+const char *ast_stream_topology_to_str(const struct ast_stream_topology *topology,</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_str **buf)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ int i;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!buf ||!*buf) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return "";</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!topology) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(buf, 0, "(null topology)");</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_str_buffer(*buf);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ for (i = 0; i < AST_VECTOR_SIZE(&topology->streams); i++) {</span><br><span style="color: hsl(120, 100%, 40%);">+ struct ast_stream *stream;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ stream = AST_VECTOR_GET(&topology->streams, i);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(buf, 0, " <");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_stream_to_str(stream, buf);</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_str_append(buf, 0, ">");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return ast_str_buffer(*buf);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> struct ast_stream *ast_stream_topology_get_first_stream_by_type(</span><br><span> const struct ast_stream_topology *topology,</span><br><span> enum ast_media_type type)</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14727">change 14727</a>. To unsubscribe, or for help writing mail filters, 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/c/asterisk/+/14727"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 16 </div>
<div style="display:none"> Gerrit-Change-Id: I132eb5971ea41509c660f64e9113cda8c9013b0b </div>
<div style="display:none"> Gerrit-Change-Number: 14727 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>