[Asterisk-code-review] stream: Add stream topology to channel (asterisk[master])

George Joseph asteriskteam at digium.com
Mon Feb 13 11:55:21 CST 2017


George Joseph has uploaded a new change for review. ( https://gerrit.asterisk.org/4939 )

Change subject: stream:  Add stream topology to channel
......................................................................

stream:  Add stream topology to channel

Adds topology set and get to channel.

ASTERISK-26790

Change-Id: Ic379ea82a9486fc79dbd8c4d95c29fa3b46424f4
---
M include/asterisk/channel.h
M include/asterisk/stream.h
M main/channel_internal_api.c
M main/stream.c
4 files changed, 84 insertions(+), 3 deletions(-)


  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/39/4939/1

diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index e5f792f..36390aa 100644
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -884,6 +884,10 @@
 	 * world
 	 */
 	AST_CHAN_TP_INTERNAL = (1 << 2),
+	/*!
+	 * \brief Channels with this particular technology support multiple simultaneous streams
+	 */
+	AST_CHAN_TP_MULTISTREAM = (1 << 3),
 };
 
 /*! \brief ast_channel flags */
@@ -4734,4 +4738,17 @@
  */
 int ast_channel_get_intercept_mode(void);
 
+/*!
+ * \brief Retrieve the topology of streams on a channel
+ *
+ * \param chan The channel to get the stream topology of
+ *
+ * \pre chan is locked
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ */
+struct ast_stream_topology *ast_channel_get_stream_topology(
+	const struct ast_channel *chan);
+
 #endif /* _ASTERISK_CHANNEL_H */
diff --git a/include/asterisk/stream.h b/include/asterisk/stream.h
index cffe6ea..018ebc7 100644
--- a/include/asterisk/stream.h
+++ b/include/asterisk/stream.h
@@ -134,7 +134,6 @@
  * \brief Change the media type of a stream
  *
  * \param stream The media stream
- * \param type The new media type
  *
  * \since 15
  */
@@ -144,6 +143,7 @@
  * \brief Get the current negotiated formats of a stream
  *
  * \param stream The media stream
+ * \param type The new media type
  *
  * \retval non-NULL success
  * \retval NULL failure
@@ -316,4 +316,19 @@
 struct ast_stream_topology *ast_stream_topology_create_from_format_cap(
 	struct ast_format_cap *cap);
 
+/*!
+ * \brief Gets the first stream of a specific type from the topology
+ *
+ * \param topology The topology of streams
+ * \param type The media type
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ *
+ * \since 15
+ */
+struct ast_stream *ast_stream_topology_get_first_stream_by_type(
+	const struct ast_stream_topology *topology,
+	enum ast_media_type type);
+
 #endif /* _AST_STREAM_H */
diff --git a/main/channel_internal_api.c b/main/channel_internal_api.c
index a0cbe86..2875c3e 100644
--- a/main/channel_internal_api.c
+++ b/main/channel_internal_api.c
@@ -46,6 +46,7 @@
 #include "asterisk/stasis_channels.h"
 #include "asterisk/stasis_endpoints.h"
 #include "asterisk/stringfields.h"
+#include "asterisk/stream.h"
 #include "asterisk/test.h"
 
 /*!
@@ -221,6 +222,8 @@
 	struct stasis_cp_single *topics;		/*!< Topic for all channel's events */
 	struct stasis_forward *endpoint_forward;	/*!< Subscription for event forwarding to endpoint's topic */
 	struct stasis_forward *endpoint_cache_forward; /*!< Subscription for cache updates to endpoint's topic */
+	struct ast_stream_topology *stream_topology; /*!< Stream topology */
+	struct ast_stream *default_streams[AST_MEDIA_TYPE_END]; /*!< Default streams indexed by media type */
 };
 
 /*! \brief The monotonically increasing integer counter for channel uniqueids */
@@ -825,10 +828,29 @@
 {
 	return chan->nativeformats;
 }
-void ast_channel_nativeformats_set(struct ast_channel *chan, struct ast_format_cap *value)
+
+static void channel_set_default_streams(struct ast_channel *chan)
 {
-	ao2_replace(chan->nativeformats, value);
+	enum ast_media_type type;
+
+	for(type = AST_MEDIA_TYPE_UNKNOWN; type < AST_MEDIA_TYPE_END; type++) {
+		chan->default_streams[type] =
+			ast_stream_topology_get_first_stream_by_type(chan->stream_topology, type);
+	}
 }
+
+void ast_channel_nativeformats_set(struct ast_channel *chan,
+	struct ast_format_cap *value)
+{
+	ast_assert(chan != NULL);
+	ao2_replace(chan->nativeformats, value);
+	if (chan->tech->properties & AST_CHAN_TP_MULTISTREAM) {
+		ast_stream_topology_destroy(chan->stream_topology);
+		chan->stream_topology = ast_stream_topology_create_from_format_cap(value);
+		channel_set_default_streams(chan);
+	}
+}
+
 struct ast_framehook_list *ast_channel_framehooks(const struct ast_channel *chan)
 {
 	return chan->framehooks;
@@ -1729,3 +1751,11 @@
 
 	return *error_code;
 }
+
+struct ast_stream_topology *ast_channel_get_stream_topology(
+	const struct ast_channel *chan)
+{
+	ast_assert(chan != NULL);
+
+	return chan->stream_topology;
+}
diff --git a/main/stream.c b/main/stream.c
index 0fabfc7..9bb6771 100644
--- a/main/stream.c
+++ b/main/stream.c
@@ -332,3 +332,22 @@
 
 	return topology;
 }
+
+struct ast_stream *ast_stream_topology_get_first_stream_by_type(
+	const struct ast_stream_topology *topology,
+	enum ast_media_type type)
+{
+	int i;
+
+	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->type == type) {
+			return stream;
+		}
+	}
+
+	return NULL;
+}

-- 
To view, visit https://gerrit.asterisk.org/4939
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic379ea82a9486fc79dbd8c4d95c29fa3b46424f4
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: George Joseph <gjoseph at digium.com>



More information about the asterisk-code-review mailing list