[asterisk-commits] Add initial SDP state code. (asterisk[master])

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 22 10:56:02 CST 2017


Joshua Colp has submitted this change and it was merged. ( https://gerrit.asterisk.org/4961 )

Change subject: Add initial SDP state code.
......................................................................


Add initial SDP state code.

This establishes the basic allocation/destruction of an SDP state
object, plus some of the simpler getter methods involved. Subsequent
tasks will deal with adding a state machine, creating SDPs from
capabilities and options, and merging SDPs into a joint SDP.

Change-Id: Ie3757ce186f04b65e9d1883f5aace53f24e53709
---
A include/asterisk/sdp_state.h
A main/sdp_state.c
2 files changed, 165 insertions(+), 0 deletions(-)

Approvals:
  Kevin Harwell: Looks good to me, approved
  Anonymous Coward #1000019: Verified
  Joshua Colp: Looks good to me, but someone else must approve



diff --git a/include/asterisk/sdp_state.h b/include/asterisk/sdp_state.h
new file mode 100644
index 0000000..b5e4417
--- /dev/null
+++ b/include/asterisk/sdp_state.h
@@ -0,0 +1,58 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2017, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#ifndef _ASTERISK_SDP_STATE_H
+#define _ASTERISK_SDP_STATE_H
+
+struct ast_sdp_state;
+struct ast_sdp_options;
+struct ast_stream_topology;
+
+/*!
+ * \brief Allocate a new SDP state
+ *
+ * SDP state keeps tabs on everything SDP-related for a media session.
+ * Most SDP operations will require the state to be provided.
+ * Ownership of the SDP options is taken on by the SDP state.
+ * A good strategy is to call this during session creation.
+ */
+struct ast_sdp_state *ast_sdp_state_alloc(struct ast_stream_topology *streams, struct ast_sdp_options *options);
+
+/*!
+ * \brief Free the SDP state.
+ *
+ * A good strategy is to call this during session destruction
+ */
+void ast_sdp_state_free(struct ast_sdp_state *sdp_state);
+
+/*!
+ * \brief Get the associated RTP instance for a particular stream on the SDP state.
+ *
+ * Stream numbers correspond to the streams in the topology of the associated channel
+ */
+struct ast_rtp_instance *ast_sdp_state_get_rtp_instance(struct ast_sdp_state *sdp_state, int stream_index);
+
+/*!
+ * \brief Get the joint negotiated streams based on local and remote capabilities.
+ *
+ * If this is called prior to receiving a remote SDP, then this will just mirror
+ * the local configured endpoint capabilities.
+ */
+struct ast_stream_topology *ast_sdp_state_get_joint_topology(struct ast_sdp_state *sdp_state);
+
+#endif /* _ASTERISK_SDP_STATE_H */
diff --git a/main/sdp_state.c b/main/sdp_state.c
new file mode 100644
index 0000000..04de6e3
--- /dev/null
+++ b/main/sdp_state.c
@@ -0,0 +1,107 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2017, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#include "asterisk.h"
+#include "asterisk/sdp_state.h"
+#include "asterisk/sdp_options.h"
+#include "asterisk/sdp_translator.h"
+#include "asterisk/sdp_priv.h"
+#include "asterisk/vector.h"
+#include "asterisk/utils.h"
+#include "asterisk/stream.h"
+
+struct ast_sdp_state {
+	/*! Local capabilities, learned through configuration */
+	struct ast_stream_topology *local_capabilities;
+	/*! Remote capabilities, learned through remote SDP */
+	struct ast_stream_topology *remote_capabilities;
+	/*! Joint capabilities. The combined local and remote capabilities. */
+	struct ast_stream_topology *joint_capabilities;
+	/*! Local SDP. Generated via the options and local capabilities. */
+	struct ast_sdp *local_sdp;
+	/*! Remote SDP. Received directly from a peer. */
+	struct ast_sdp *remote_sdp;
+	/*! Joint SDP. The merged local and remote SDPs. */
+	struct ast_sdp *joint_sdp;
+	/*! SDP options. Configured options beyond media capabilities. */
+	struct ast_sdp_options *options;
+	/*! Translator that puts SDPs into the expected representation */
+	struct ast_sdp_translator *translator;
+	/*! RTP instance for each media stream */
+	AST_VECTOR(, struct ast_rtp_instance *) rtp;
+};
+
+struct ast_sdp_state *ast_sdp_state_alloc(struct ast_stream_topology *streams, struct ast_sdp_options *options)
+{
+	struct ast_sdp_state *sdp_state;
+
+	sdp_state = ast_calloc(1, sizeof(*sdp_state));
+	if (!sdp_state) {
+		return NULL;
+	}
+
+	sdp_state->options = options;
+
+	sdp_state->translator = ast_sdp_translator_new(ast_sdp_options_get_repr(sdp_state->options));
+	if (!sdp_state->translator) {
+		ast_sdp_state_free(sdp_state);
+		return NULL;
+	}
+
+	sdp_state->local_capabilities = ast_stream_topology_clone(streams);
+	if (!sdp_state->local_capabilities) {
+		ast_sdp_state_free(sdp_state);
+		return NULL;
+	}
+
+	return sdp_state;
+}
+
+void ast_sdp_state_free(struct ast_sdp_state *sdp_state)
+{
+	if (!sdp_state) {
+		return;
+	}
+
+	ast_stream_topology_free(sdp_state->local_capabilities);
+	ast_stream_topology_free(sdp_state->remote_capabilities);
+	ast_stream_topology_free(sdp_state->joint_capabilities);
+	ast_sdp_free(sdp_state->local_sdp);
+	ast_sdp_free(sdp_state->remote_sdp);
+	ast_sdp_free(sdp_state->joint_sdp);
+	ast_sdp_options_free(sdp_state->options);
+	ast_sdp_translator_free(sdp_state->translator);
+}
+
+struct ast_rtp_instance *ast_sdp_state_get_rtp_instance(struct ast_sdp_state *sdp_state, int stream_index)
+{
+	if (stream_index >= AST_VECTOR_SIZE(&sdp_state->rtp)) {
+		return NULL;
+	}
+
+	return AST_VECTOR_GET(&sdp_state->rtp, stream_index);
+}
+
+struct ast_stream_topology *ast_sdp_state_get_joint_topology(struct ast_sdp_state *sdp_state)
+{
+	if (sdp_state->joint_capabilities) {
+		return sdp_state->joint_capabilities;
+	} else {
+		return sdp_state->local_capabilities;
+	}
+}

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

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie3757ce186f04b65e9d1883f5aace53f24e53709
Gerrit-PatchSet: 5
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Mark Michelson <mmichelson at digium.com>
Gerrit-Reviewer: Anonymous Coward #1000019
Gerrit-Reviewer: George Joseph <gjoseph at digium.com>
Gerrit-Reviewer: Joshua Colp <jcolp at digium.com>
Gerrit-Reviewer: Kevin Harwell <kharwell at digium.com>



More information about the asterisk-commits mailing list