[Asterisk-code-review] RFC sdp: Initial SDP creation (asterisk[master])
George Joseph
asteriskteam at digium.com
Fri Mar 3 16:28:23 CST 2017
George Joseph has uploaded a new change for review. ( https://gerrit.asterisk.org/5119 )
Change subject: RFC sdp: Initial SDP creation
......................................................................
RFC sdp: Initial SDP creation
* Added additional fields to ast_sdp_options.
* Re-organized ast_sdp.
* Updated field names to correspond to RFC4566 terminology.
* Created allocs/frees for SDP children.
* Created getters/setters for SDP children where appropriate.
* Added ast_sdp_create_from_state.
* Refactored res_sdp_translator_pjmedia for changes.
Change-Id: Iefbd877af7f5a4d3c74deead1bff8802661b0d48
---
M include/asterisk/sdp_options.h
M include/asterisk/sdp_priv.h
M include/asterisk/sdp_state.h
M include/asterisk/stream.h
A main/sdp.c
M main/sdp_options.c
D main/sdp_repr.c
M main/sdp_state.c
M main/stream.c
M res/res_sdp_translator_pjmedia.c
10 files changed, 1,508 insertions(+), 343 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/19/5119/1
diff --git a/include/asterisk/sdp_options.h b/include/asterisk/sdp_options.h
index a5c2d08..47fa7ba 100644
--- a/include/asterisk/sdp_options.h
+++ b/include/asterisk/sdp_options.h
@@ -19,7 +19,79 @@
#ifndef _ASTERISK_SDP_OPTIONS_H
#define _ASTERISK_SDP_OPTIONS_H
-struct ast_sdp_options;
+#include "asterisk/stringfields.h"
+
+/*!
+ * \brief ICE options
+ *
+ * This is an enum because it is predicted that this eventually
+ * support a TRICKLE-ICE option.
+ */
+enum ast_sdp_options_ice {
+ /*! ICE is not enabled on this session */
+ AST_SDP_ICE_DISABLED,
+ /*! Standard ICE is enabled on this session */
+ AST_SDP_ICE_ENABLED_STANDARD,
+};
+
+/*!
+ * \brief Representation of the SDP
+ *
+ * Users of the SDP API set the representation based on what they
+ * natively handle. This indicates the type of SDP that the API expects
+ * when being given an SDP, and it indicates the type of SDP that the API
+ * returns when asked for one.
+ */
+enum ast_sdp_options_repr {
+ /*! SDP is represented as a string */
+ AST_SDP_REPR_STRING,
+ /*! SDP is represented as a pjmedia_sdp_session */
+ AST_SDP_REPR_PJMEDIA,
+ /*! End of the list */
+ AST_SDP_REPR_END,
+};
+
+/*!
+ * \brief SDP encryption options
+ */
+enum ast_sdp_options_encryption {
+ /*! No encryption */
+ AST_SDP_ENCRYPTION_DISABLED,
+ /*! SRTP SDES encryption */
+ AST_SDP_ENCRYPTION_SRTP_SDES,
+ /*! DTLS encryption */
+ AST_SDP_ENCRYPTION_DTLS,
+};
+
+struct ast_sdp_options {
+ AST_DECLARE_STRING_FIELDS(
+ /*! Optional media address to use in SDP */
+ AST_STRING_FIELD(media_address);
+ /*! SDP origin username */
+ AST_STRING_FIELD(sdpowner);
+ /*! SDP session name */
+ AST_STRING_FIELD(sdpsession);
+ /*! RTP Engine Name */
+ AST_STRING_FIELD(rtp_engine);
+ );
+ struct {
+ unsigned int bind_rtp_to_media_address : 1;
+ unsigned int rtp_symmetric : 1;
+ unsigned int telephone_event : 1;
+ unsigned int rtp_ipv6 : 1;
+ unsigned int g726_non_standard : 1;
+ unsigned int locally_held : 1;
+ };
+ struct {
+ unsigned int tos_audio;
+ unsigned int cos_audio;
+ unsigned int tos_video;
+ unsigned int cos_video;
+ } tos;
+ enum ast_sdp_options_ice ice;
+ enum ast_sdp_options_repr repr;
+ enum ast_sdp_options_encryption encryption;
+};
/*!
* \since 15.0.0
@@ -45,19 +117,6 @@
* \param options The options to free
*/
void ast_sdp_options_free(struct ast_sdp_options *options);
-
-/*!
- * \brief ICE options
- *
- * This is an enum because it is predicted that this eventually
- * support a TRICKLE-ICE option.
- */
-enum ast_sdp_options_ice {
- /*! ICE is not enabled on this session */
- AST_SDP_ICE_DISABLED,
- /*! Standard ICE is enabled on this session */
- AST_SDP_ICE_ENABLED_STANDARD,
-};
/*!
* \since 15.0.0
@@ -96,23 +155,6 @@
int ast_sdp_options_get_telephone_event(const struct ast_sdp_options *options);
/*!
- * \brief Representation of the SDP
- *
- * Users of the SDP API set the representation based on what they
- * natively handle. This indicates the type of SDP that the API expects
- * when being given an SDP, and it indicates the type of SDP that the API
- * returns when asked for one.
- */
-enum ast_sdp_options_repr {
- /*! SDP is represented as a string */
- AST_SDP_REPR_STRING,
- /*! SDP is represented as a pjmedia_sdp_session */
- AST_SDP_REPR_PJMEDIA,
- /*! End of the list */
- AST_SDP_REPR_END,
-};
-
-/*!
* \since 15.0.0
* \brief Set the SDP representation
*
@@ -126,18 +168,6 @@
* \brief Get the SDP representation
*/
enum ast_sdp_options_repr ast_sdp_options_get_repr(const struct ast_sdp_options *options);
-
-/*!
- * \brief SDP encryption options
- */
-enum ast_sdp_options_encryption {
- /*! No encryption */
- AST_SDP_ENCRYPTION_DISABLED,
- /*! SRTP SDES encryption */
- AST_SDP_ENCRYPTION_SRTP_SDES,
- /*! DTLS encryption */
- AST_SDP_ENCRYPTION_DTLS,
-};
/*!
* \since 15.0.0
diff --git a/include/asterisk/sdp_priv.h b/include/asterisk/sdp_priv.h
index 000d111..555fc26 100644
--- a/include/asterisk/sdp_priv.h
+++ b/include/asterisk/sdp_priv.h
@@ -24,9 +24,12 @@
#define _SDP_PRIV_H
#include "asterisk/vector.h"
+#include "asterisk/format.h"
+#include "asterisk/sdp_state.h"
+#include "asterisk/stream.h"
/*!
- * \brief Structure representing an SDP attribute
+ * \brief Structure representing an SDP Attribute
*/
struct ast_sdp_a_line {
/*! Attribute name */
@@ -36,22 +39,35 @@
};
/*!
- * \brief Structure representing an SDP connection
+ * \brief A collection of SDP Attributes
+ */
+AST_VECTOR(ast_sdp_a_lines, struct ast_sdp_a_line *);
+
+/*!
+ * \brief Structure representing an SDP Connection
*/
struct ast_sdp_c_line {
/* IP family string (e.g. IP4 or IP6) */
- char *family;
+ char *address_type;
/* Connection address. Can be an IP address or FQDN */
- char *addr;
+ char *address;
};
/*!
- * \brief A collection of SDP attributes
+ * \brief Structre representing SDP Media Payloads
*/
-AST_VECTOR(ast_sdp_a_line_vector, struct ast_sdp_a_line);
+struct ast_sdp_payload {
+ /* Media format description */
+ char *fmt;
+};
/*!
- * \brief An SDP media stream
+ * \brief A collection of SDP Media Payloads
+ */
+AST_VECTOR(ast_sdp_payloads, struct ast_sdp_payload *);
+
+/*!
+ * \brief Structure representing an SDP Media Stream
*
* This contains both the m line, as well as its
* constituent a lines.
@@ -59,28 +75,57 @@
struct ast_sdp_m_line {
/*! Media type (e.g. "audio" or "video") */
char *type;
+ /*! RTP profile string (e.g. "RTP/AVP") */
+ char *proto;
/*! Port number in m line */
uint16_t port;
/*! Number of ports specified in m line */
uint16_t port_count;
- /*! RTP profile string (e.g. "RTP/AVP") */
- char *profile;
/*! RTP payloads */
- AST_VECTOR(, char *) payloads;
+ struct ast_sdp_payloads *payloads;
/*! Connection information for this media stream */
- struct ast_sdp_c_line c_line;
+ struct ast_sdp_c_line *c_line;
/*! The attributes for this media stream */
- struct ast_sdp_a_line_vector a_lines;
+ struct ast_sdp_a_lines *a_lines;
};
/*!
- * \brief SDP time information
+ * \brief A collection of SDP Media Streams
+ */
+AST_VECTOR(ast_sdp_m_lines, struct ast_sdp_m_line *);
+
+/*!
+ * \brief Structure representing an SDP Origin
+ */
+struct ast_sdp_o_line {
+ /*! Origin user name */
+ char *username;
+ /*! Origin id */
+ uint32_t session_id;
+ /*! Origin version */
+ uint32_t session_version;
+ /*! Origin IP address type (e.g. "IP4" or "IP6") */
+ char *address_type;
+ /*! Origin address. Can be an IP address or FQDN */
+ char *address;
+};
+
+/*!
+ * \brief Structure representing an SDP Session Name
+ */
+struct ast_sdp_s_line {
+ /* Session Name */
+ char *session_name;
+};
+
+/*!
+ * \brief Structure representing SDP Timing
*/
struct ast_sdp_t_line {
/*! Session start time */
- uint32_t start;
+ uint64_t start_time;
/*! Session end time */
- uint32_t end;
+ uint64_t stop_time;
};
/*!
@@ -88,43 +133,418 @@
*/
struct ast_sdp {
/*! SDP Origin line */
- struct {
- /*! Origin user name */
- char *user;
- /*! Origin id */
- uint32_t id;
- /*! Origin version */
- uint32_t version;
- /*! Origin IP address family (e.g. "IP4" or "IP6") */
- char *family;
- /*! Origin address. Can be an IP address or FQDN */
- char *addr;
- } o_line;
+ struct ast_sdp_o_line *o_line;
/*! SDP Session name */
- char *s_line;
+ struct ast_sdp_s_line *s_line;
/*! SDP top-level connection information */
- struct ast_sdp_c_line c_line;
+ struct ast_sdp_c_line *c_line;
/*! SDP timing information */
- struct ast_sdp_t_line t_line;
+ struct ast_sdp_t_line *t_line;
/*! SDP top-level attributes */
- struct ast_sdp_a_line_vector a_lines;
+ struct ast_sdp_a_lines *a_lines;
/*! SDP media streams */
- AST_VECTOR(, struct ast_sdp_m_line) m_lines;
+ struct ast_sdp_m_lines *m_lines;
};
/*!
- * \brief Allocate a new SDP.
+ * \brief Free an SDP Attribute
*
- * \note This does not perform any initialization.
+ * \param a_line The attribute to free
*
- * \retval NULL FAIL
- * \retval non-NULL New SDP
+ * \since 15
*/
-struct ast_sdp *ast_sdp_alloc(void);
+void ast_sdp_a_free(struct ast_sdp_a_line *a_line);
/*!
- * \brief Free an SDP and all its constituent parts
+ * \brief Free an SDP Attribute collection
+ *
+ * \param a_lines The attribute collection to free
+ *
+ * \since 15
*/
-void ast_sdp_free(struct ast_sdp *dead);
+void ast_sdp_a_lines_free(struct ast_sdp_a_lines *a_lines);
+
+/*!
+ * \brief Free SDP Connection Data
+ *
+ * \param c_line The connection data to free
+ *
+ * \since 15
+ */
+void ast_sdp_c_free(struct ast_sdp_c_line *c_line);
+
+/*!
+ * \brief Free an SDP Media Description Payload
+ *
+ * \param payload The payload to free
+ *
+ * \since 15
+ */
+void ast_sdp_payload_free(struct ast_sdp_payload *payload);
+
+/*!
+ * \brief Free an SDP Media Description Payload collection
+ *
+ * \param payloads collection to free
+ *
+ * \since 15
+ */
+void ast_sdp_payloads_free(struct ast_sdp_payloads *payloads);
+
+/*!
+ * \brief Free an SDP Media Description
+ * Frees the media description and all resources it contains
+ *
+ * \param m_line The media description to free
+ *
+ * \since 15
+ */
+void ast_sdp_m_free(struct ast_sdp_m_line *m_line);
+
+/*!
+ * \brief Free an SDP Media Description collection
+ *
+ * \param m_lines The collection description to free
+ *
+ * \since 15
+ */
+void ast_sdp_m_lines_free(struct ast_sdp_m_lines *m_lines);
+
+/*!
+ * \brief Free an SDP Origin
+ *
+ * \param o_line The origin description to free
+ *
+ * \since 15
+ */
+void ast_sdp_o_free(struct ast_sdp_o_line *o_line);
+
+/*!
+ * \brief Free an SDP Session
+ *
+ * \param s_line The session to free
+ *
+ * \since 15
+ */
+void ast_sdp_s_free(struct ast_sdp_s_line *s_line);
+
+/*!
+ * \brief Free SDP Timing
+ *
+ * \param t_line The timing description to free
+ *
+ * \since 15
+ */
+void ast_sdp_t_free(struct ast_sdp_t_line *t_line);
+
+/*!
+ * \brief Free an SDP
+ * Frees the sdp and all resources it contains
+ *
+ * \param sdp The sdp to free
+ *
+ * \since 15
+ */
+void ast_sdp_free(struct ast_sdp *sdp);
+
+/*!
+ * \brief Allocate an SDP Attribute
+ *
+ * \param name Attribute Name
+ * \param value Attribute Name
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_a_line *ast_sdp_a_alloc(char *name, char *value);
+
+/*!
+ * \brief Allocate an SDP Connection
+ *
+ * \param family Family ("IN", etc)
+ * \param addr Address
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_c_line *ast_sdp_c_alloc(char *family, char *addr);
+
+/*!
+ * \brief Allocate an SDP Media Description Payload
+ *
+ * \param fmt The media format description
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_payload *ast_sdp_payload_alloc(char *fmt);
+
+/*!
+ * \brief Allocate an SDP Media Description
+ *
+ * \param type ("audio", "video", etc)
+ * \param port Starting port
+ * \param port_count Port pairs to allocate
+ * \param proto ("RTP/AVP", "RTP/SAVP", "udp")
+ * \param c_line Connection to add. May be NULL
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_m_line *ast_sdp_m_alloc(const char *type, uint16_t port, uint16_t port_count,
+ const char *proto, struct ast_sdp_c_line *c_line);
+
+/*!
+ * \brief Allocate an SDP Session
+ *
+ * \param session_name The session name
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_s_line *ast_sdp_s_alloc(char *session_name);
+
+/*!
+ * \brief Allocate SDP Timing
+ *
+ * \param start_time (Seconds since 1900)
+ * \param end_time (Seconds since 1900)
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_t_line *ast_sdp_t_alloc(uint64_t start_time, uint64_t stop_time);
+
+/*!
+ * \brief Allocate an SDP Origin
+ *
+ * \param username User name
+ * \param sesison_id Session ID
+ * \param sesison_version Session Version
+ * \param address_type Address type ("IN4", "IN6", etc)
+ * \param address Unicast address
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_o_line *ast_sdp_o_alloc(char *username, uint64_t session_id,
+ uint32_t session_version, char *address_type, char *address);
+
+/*!
+ * \brief Add an SDP Attribute to an SDP
+ *
+ * \param sdp SDP
+ * \param a_line Attribute
+ *
+ * \retval 0 Success
+ * \retval non-0 Failure
+ *
+ * \since 15
+ */
+int ast_sdp_add_a(struct ast_sdp *sdp, struct ast_sdp_a_line *a_line);
+
+/*!
+ * \brief Get the count of Attributes on an SDP
+ *
+ * \param sdp SDP
+ *
+ * \returns Number of Attributes
+ *
+ * \since 15
+ */
+int ast_sdp_get_a_count(struct ast_sdp *sdp);
+
+/*!
+ * \brief Get an Attribute from an SDP
+ *
+ * \param sdp SDP
+ * \param index Attribute index
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_a_line *ast_sdp_get_a(struct ast_sdp *sdp, int index);
+
+/*!
+ * \brief Add a Media Description to an SDP
+ *
+ * \param sdp SDP
+ * \param m_line Media Description
+ *
+ * \retval 0 Success
+ * \retval non-0 Failure
+ *
+ * \since 15
+ */
+int ast_sdp_add_m(struct ast_sdp *sdp, struct ast_sdp_m_line *m_line);
+
+/*!
+ * \brief Add a Media Description to an SDP
+ *
+ * \param sdp SDP
+ * \param options SDP Options
+ * \param rtp ast_rtp_instance
+ * \param stream stream
+ *
+ * \retval 0 Success
+ * \retval non-0 Failure
+ *
+ * \since 15
+ */
+int ast_sdp_add_m_from_stream(struct ast_sdp *sdp, struct ast_sdp_options *options,
+ struct ast_rtp_instance *rtp, struct ast_stream *stream);
+
+/*!
+ * \brief Get the count of Media Descriptions on an SDP
+ *
+ * \param sdp SDP
+ *
+ * \returns The number of Media Descriptions
+ *
+ * \since 15
+ */
+int ast_sdp_get_m_count(struct ast_sdp *sdp);
+
+/*!
+ * \brief Get a Media Descriptions from an SDP
+ *
+ * \param sdp SDP
+ * \param index Media Description index
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_m_line *ast_sdp_get_m(struct ast_sdp *sdp, int index);
+
+/*!
+ * \brief Add an SDP Attribute to a Media Description
+ *
+ * \param m_line Media Description
+ * \param a_line Attribute
+ *
+ * \retval 0 Success
+ * \retval non-0 Failure
+ *
+ * \since 15
+ */
+int ast_sdp_m_add_a(struct ast_sdp_m_line *m_line, struct ast_sdp_a_line *a_line);
+
+/*!
+ * \brief Get the count of Attributes on a Media Description
+ *
+ * \param m_line Media Description
+ *
+ * \returns Number of Attributes
+ *
+ * \since 15
+ */
+int ast_sdp_m_get_a_count(struct ast_sdp_m_line *m_line);
+
+/*!
+ * \brief Get an Attribute from a Media Description
+ *
+ * \param m_line Media Description
+ * \param index Attribute index
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_a_line *ast_sdp_m_get_a(struct ast_sdp_m_line *m_line, int index);
+
+/*!
+ * \brief Add a Payload to a Media Description
+ *
+ * \param m_line Media Description
+ * \param payload Payload
+ *
+ * \retval 0 Success
+ * \retval non-0 Failure
+ *
+ * \since 15
+ */
+int ast_sdp_m_add_payload(struct ast_sdp_m_line *m_line, struct ast_sdp_payload *payload);
+
+/*!
+ * \brief Get the count of Payloads on a Media Description
+ *
+ * \param m_line Media Description
+ *
+ * \returns Number of Attributes
+ *
+ * \since 15
+ */
+int ast_sdp_m_get_payload_count(struct ast_sdp_m_line *m_line);
+
+/*!
+ * \brief Get a Payload from a Media Description
+ *
+ * \param m_line Media Description
+ * \param index Payload index
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp_payload *ast_sdp_m_get_payload(struct ast_sdp_m_line *m_line, int index);
+
+/*!
+ * \brief Add a Format to a Media Description
+ *
+ * \param m_line Media Description
+ * \param options SDP Options
+ * \param rtp_code rtp_code from ast_rtp_codecs_payload_code
+ * \param asterisk_format True if the value in format is to be used.
+ * \param format Format
+ * \param code from AST_RTP list
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+int ast_sdp_m_add_format(struct ast_sdp_m_line *m_line, struct ast_sdp_options *options,
+ int rtp_code, int asterisk_format, struct ast_format *format, int code);
+
+/*!
+ * \brief Create an SDP
+ *
+ * \param o_line Origin
+ * \param c_line Connection
+ * \param s_line Session
+ * \param t_line Timing
+ *
+ * \retval non-NULL Success
+ * \retval NULL Failure
+ *
+ * \since 15
+ */
+struct ast_sdp *ast_sdp_alloc(struct ast_sdp_o_line *o_line,
+ struct ast_sdp_c_line *c_line, struct ast_sdp_s_line *s_line,
+ struct ast_sdp_t_line *t_line);
+
+
+struct ast_sdp *ast_sdp_create_from_state(struct ast_sdp_state *sdp_state);
+
#endif /* _SDP_PRIV_H */
diff --git a/include/asterisk/sdp_state.h b/include/asterisk/sdp_state.h
index 14d3e7c..0eaee34 100644
--- a/include/asterisk/sdp_state.h
+++ b/include/asterisk/sdp_state.h
@@ -56,6 +56,18 @@
struct ast_stream_topology *ast_sdp_state_get_joint_topology(struct ast_sdp_state *sdp_state);
/*!
+ * \brief Get the local topology
+ *
+ */
+struct ast_stream_topology *ast_sdp_state_get_local_topology(struct ast_sdp_state *sdp_state);
+
+/*!
+ * \brief Get the sdp_state options
+ *
+ */
+struct ast_sdp_options *ast_sdp_state_get_options(struct ast_sdp_state *sdp_state);
+
+/*!
* \brief Get the local SDP.
*
* If we have not received a remote SDP yet, this will be an SDP offer based
diff --git a/include/asterisk/stream.h b/include/asterisk/stream.h
index 48ee883..1d3d184 100644
--- a/include/asterisk/stream.h
+++ b/include/asterisk/stream.h
@@ -43,6 +43,8 @@
*/
struct ast_stream_topology;
+typedef void (*ast_stream_data_free_fn)(void *);
+
/*!
* \brief States that a stream may be in
*/
@@ -202,6 +204,32 @@
const char *ast_stream_state2str(enum ast_stream_state state);
/*!
+ * \brief Get the opaque stream data
+ *
+ * \param stream The media stream
+ *
+ * \retval non-NULL success
+ * \retval NULL failure
+ *
+ * \since 15
+ */
+void *ast_stream_get_data(struct ast_stream *stream);
+
+/*!
+ * \brief Set the opaque stream data
+ *
+ * \param stream The media stream
+ * \param data Opaque data
+ * \param data_free_fn Callback to free data when stream is freed. May be NULL for no action.
+ *
+ * \return data
+ *
+ * \since 15
+ */
+void *ast_stream_set_data(struct ast_stream *stream, void *data,
+ ast_stream_data_free_fn data_free_fn);
+
+/*!
* \brief Get the position of the stream in the topology
*
* \param stream The media stream
diff --git a/main/sdp.c b/main/sdp.c
new file mode 100644
index 0000000..22154f5
--- /dev/null
+++ b/main/sdp.c
@@ -0,0 +1,771 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2017, Digium, Inc.
+ *
+ * George Joseph <gjoseph 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/utils.h"
+#include "asterisk/netsock2.h"
+#include "asterisk/codec.h"
+#include "asterisk/format.h"
+#include "asterisk/format_cap.h"
+#include "asterisk/rtp_engine.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"
+
+void ast_sdp_a_free(struct ast_sdp_a_line *a_line)
+{
+ ast_debug(5, "free\n");
+ ast_free(a_line);
+}
+
+void ast_sdp_a_lines_free(struct ast_sdp_a_lines *a_lines)
+{
+ ast_debug(5, "free\n");
+ if (!a_lines) {
+ return;
+ }
+
+ AST_VECTOR_CALLBACK_VOID(a_lines, ast_sdp_a_free);
+ AST_VECTOR_FREE(a_lines);
+ ast_free(a_lines);
+}
+
+void ast_sdp_c_free(struct ast_sdp_c_line *c_line)
+{
+ ast_debug(5, "free\n");
+ ast_free(c_line);
+}
+
+void ast_sdp_payload_free(struct ast_sdp_payload *payload)
+{
+ ast_debug(5, "free\n");
+ return;
+}
+
+void ast_sdp_payloads_free(struct ast_sdp_payloads *payloads)
+{
+ ast_debug(5, "free\n");
+ if (!payloads) {
+ return;
+ }
+
+ AST_VECTOR_CALLBACK_VOID(payloads, ast_sdp_payload_free);
+ AST_VECTOR_FREE(payloads);
+ ast_free(payloads);
+}
+
+void ast_sdp_m_free(struct ast_sdp_m_line *m_line)
+{
+ ast_debug(5, "free\n");
+ if (!m_line) {
+ return;
+ }
+
+ ast_sdp_a_lines_free(m_line->a_lines);
+ ast_sdp_payloads_free(m_line->payloads);
+ ast_sdp_c_free(m_line->c_line);
+ ast_free(m_line);
+}
+
+void ast_sdp_m_lines_free(struct ast_sdp_m_lines *m_lines)
+{
+ ast_debug(5, "free\n");
+ if (!m_lines) {
+ return;
+ }
+
+ AST_VECTOR_CALLBACK_VOID(m_lines, ast_sdp_m_free);
+ AST_VECTOR_FREE(m_lines);
+ ast_free(m_lines);
+}
+
+void ast_sdp_o_free(struct ast_sdp_o_line *o_line)
+{
+ ast_debug(5, "free\n");
+ ast_free(o_line);
+}
+
+void ast_sdp_s_free(struct ast_sdp_s_line *s_line)
+{
+ ast_debug(5, "free\n");
+ ast_free(s_line);
+}
+
+void ast_sdp_t_free(struct ast_sdp_t_line *t_line)
+{
+ ast_debug(5, "free\n");
+ ast_free(t_line);
+}
+
+void ast_sdp_free(struct ast_sdp *sdp)
+{
+ ast_debug(5, "free\n");
+ if (!sdp) {
+ return;
+ }
+
+ ast_sdp_o_free(sdp->o_line);
+ ast_sdp_s_free(sdp->s_line);
+ ast_sdp_c_free(sdp->c_line);
+ ast_sdp_t_free(sdp->t_line);
+ ast_sdp_a_lines_free(sdp->a_lines);
+ ast_sdp_m_lines_free(sdp->m_lines);
+ ast_free(sdp);
+}
+
+#define COPY_STR_AND_ADVANCE(p, dest, source) \
+({ \
+ dest = p; \
+ strcpy(dest, source); \
+ p += (strlen(source) + 1); \
+})
+
+struct ast_sdp_a_line *ast_sdp_a_alloc(char *name, char *value)
+{
+ struct ast_sdp_a_line *a_line;
+ size_t len;
+ char *p;
+
+ ast_assert(!ast_strlen_zero(name));
+
+ if (ast_strlen_zero(value)) {
+ value = "";
+ }
+
+ len = sizeof(*a_line) + strlen(name) + strlen(value) + 2;
+ a_line = ast_calloc(1, len);
+ if (!a_line) {
+ return NULL;
+ }
+
+ p = ((char *)a_line) + sizeof(*a_line);
+
+ COPY_STR_AND_ADVANCE(p, a_line->name, name);
+ COPY_STR_AND_ADVANCE(p, a_line->value, value);
+
+ return a_line;
+}
+
+struct ast_sdp_c_line *ast_sdp_c_alloc(char *address_type, char *address)
+{
+ struct ast_sdp_c_line *c_line;
+ size_t len;
+ char *p;
+
+ ast_assert(!ast_strlen_zero(address_type) && !ast_strlen_zero(address));
+
+ len = sizeof(*c_line) + strlen(address_type) + strlen(address) + 2;
+ c_line = ast_calloc(1, len);
+ if (!c_line) {
+ return NULL;
+ }
+
+ p = ((char *)c_line) + sizeof(*c_line);
+
+ COPY_STR_AND_ADVANCE(p, c_line->address_type, address_type);
+ COPY_STR_AND_ADVANCE(p, c_line->address, address);
+
+ return c_line;
+}
+
+struct ast_sdp_payload *ast_sdp_payload_alloc(char *fmt)
+{
+ struct ast_sdp_payload *payload;
+ size_t len;
+
+ ast_assert(!ast_strlen_zero(fmt));
+
+ len = sizeof(*payload) + strlen(fmt) + 1;
+ payload = ast_calloc(1, len);
+ if (!payload) {
+ return NULL;
+ }
+
+ payload->fmt = ((char *)payload) + sizeof(*payload);
+ strcpy(payload->fmt, fmt); /* Safe */
+
+ return payload;
+}
+
+struct ast_sdp_m_line *ast_sdp_m_alloc(const char *type, uint16_t port, uint16_t port_count,
+ const char *proto, struct ast_sdp_c_line *c_line)
+{
+ struct ast_sdp_m_line *m_line;
+ size_t len;
+ char *p;
+
+ ast_assert(!ast_strlen_zero(type) && !ast_strlen_zero(proto));
+
+ len = sizeof(*m_line) + strlen(type) + strlen(proto) + 2;
+ m_line = ast_calloc(1, len);
+ if (!m_line) {
+ return NULL;
+ }
+
+ m_line->a_lines = ast_calloc(1, sizeof(*m_line->a_lines));
+ if (!m_line->a_lines) {
+ ast_sdp_m_free(m_line);
+ return NULL;
+ }
+ if (AST_VECTOR_INIT(m_line->a_lines, 20)) {
+ ast_sdp_m_free(m_line);
+ return NULL;
+ }
+
+ m_line->payloads = ast_calloc(1, sizeof(*m_line->payloads));
+ if (!m_line->payloads) {
+ ast_sdp_m_free(m_line);
+ return NULL;
+ }
+ if (AST_VECTOR_INIT(m_line->payloads, 20)) {
+ ast_sdp_m_free(m_line);
+ return NULL;
+ }
+
+ p = ((char *)m_line) + sizeof(*m_line);
+
+ COPY_STR_AND_ADVANCE(p, m_line->type, type);
+ COPY_STR_AND_ADVANCE(p, m_line->proto, proto);
+ m_line->port = port;
+ m_line->port_count = port_count;
+ m_line->c_line = c_line;
+
+ return m_line;
+}
+
+struct ast_sdp_s_line *ast_sdp_s_alloc(char *session_name)
+{
+ struct ast_sdp_s_line *s_line;
+ size_t len;
+
+ if (ast_strlen_zero(session_name)) {
+ session_name = " ";
+ }
+
+ len = sizeof(*s_line) + strlen(session_name) + 1;
+ s_line = ast_calloc(1, len);
+ if (!s_line) {
+ return NULL;
+ }
+
+ s_line->session_name = ((char *)s_line) + sizeof(*s_line);
+ strcpy(s_line->session_name, session_name); /* Safe */
+
+ return s_line;
+}
+
+struct ast_sdp_t_line *ast_sdp_t_alloc(uint64_t start_time, uint64_t stop_time)
+{
+ struct ast_sdp_t_line *t_line;
+
+ t_line = ast_calloc(1, sizeof(*t_line));
+ if (!t_line) {
+ return NULL;
+ }
+
+ t_line->start_time = start_time;
+ t_line->stop_time = stop_time;
+
+ return t_line;
+}
+
+struct ast_sdp_o_line *ast_sdp_o_alloc(char *username, uint64_t session_id, uint32_t session_version,
+ char *address_type, char *address)
+{
+ struct ast_sdp_o_line *o_line;
+ size_t len;
+ char *p;
+
+ ast_assert(!ast_strlen_zero(username) && !ast_strlen_zero(address_type)
+ && !ast_strlen_zero(address));
+
+ len = sizeof(*o_line) + strlen(username) + strlen(address_type) + strlen(address) + 3;
+ o_line = ast_calloc(1, len);
+ if (!o_line) {
+ return NULL;
+ }
+
+ o_line->session_id = session_id;
+ o_line->session_version = session_version;
+
+ p = ((char *)o_line) + sizeof(*o_line);
+
+ COPY_STR_AND_ADVANCE(p, o_line->username, username);
+ COPY_STR_AND_ADVANCE(p, o_line->address_type, address_type);
+ COPY_STR_AND_ADVANCE(p, o_line->address, address);
+
+ return o_line;
+}
+
+struct ast_sdp *ast_sdp_alloc(struct ast_sdp_o_line *o_line,
+ struct ast_sdp_c_line *c_line, struct ast_sdp_s_line *s_line,
+ struct ast_sdp_t_line *t_line)
+{
+ struct ast_sdp *new_sdp;
+
+ new_sdp = calloc(1, sizeof *new_sdp);
+ if (!new_sdp) {
+ return NULL;
+ }
+
+ new_sdp->a_lines = ast_calloc(1, sizeof(*new_sdp->a_lines));
+ if (!new_sdp->a_lines) {
+ ast_sdp_free(new_sdp);
+ return NULL;
+ }
+ if (AST_VECTOR_INIT(new_sdp->a_lines, 20)) {
+ ast_sdp_free(new_sdp);
+ return NULL;
+ }
+
+ new_sdp->m_lines = ast_calloc(1, sizeof(*new_sdp->m_lines));
+ if (!new_sdp->m_lines) {
+ ast_sdp_free(new_sdp);
+ return NULL;
+ }
+ if (AST_VECTOR_INIT(new_sdp->m_lines, 20)) {
+ ast_sdp_free(new_sdp);
+ return NULL;
+ }
+
+ new_sdp->o_line = o_line;
+ new_sdp->c_line = c_line;
+ new_sdp->s_line = s_line;
+ new_sdp->t_line = t_line;
+
+ return new_sdp;
+}
+
+int ast_sdp_add_a(struct ast_sdp *sdp, struct ast_sdp_a_line *a_line)
+{
+ ast_assert(sdp && a_line);
+
+ return AST_VECTOR_APPEND(sdp->a_lines, a_line);
+}
+
+int ast_sdp_get_a_count(struct ast_sdp *sdp)
+{
+ ast_assert(sdp != NULL);
+
+ return AST_VECTOR_SIZE(sdp->a_lines);
+}
+
+struct ast_sdp_a_line *ast_sdp_get_a(struct ast_sdp *sdp, int index)
+{
+ ast_assert(sdp != NULL);
+
+ return AST_VECTOR_GET(sdp->a_lines, index);
+}
+
+int ast_sdp_add_m(struct ast_sdp *sdp, struct ast_sdp_m_line *m_line)
+{
+ ast_assert(sdp && m_line);
+
+ return AST_VECTOR_APPEND(sdp->m_lines, m_line);
+}
+
+int ast_sdp_get_m_count(struct ast_sdp *sdp)
+{
+ ast_assert(sdp != NULL);
+
+ return AST_VECTOR_SIZE(sdp->m_lines);
+}
+
+struct ast_sdp_m_line *ast_sdp_get_m(struct ast_sdp *sdp, int index)
+{
+ ast_assert(sdp != NULL);
+
+ return AST_VECTOR_GET(sdp->m_lines, index);
+}
+
+int ast_sdp_m_add_a(struct ast_sdp_m_line *m_line, struct ast_sdp_a_line *a_line)
+{
+ ast_assert(m_line && a_line);
+
+ return AST_VECTOR_APPEND(m_line->a_lines, a_line);
+}
+
+int ast_sdp_m_get_a_count(struct ast_sdp_m_line *m_line)
+{
+ ast_assert(m_line != NULL);
+
+ return AST_VECTOR_SIZE(m_line->a_lines);
+}
+
+struct ast_sdp_a_line *ast_sdp_m_get_a(struct ast_sdp_m_line *m_line, int index)
+{
+ ast_assert(m_line != NULL);
+
+ return AST_VECTOR_GET(m_line->a_lines, index);
+}
+
+int ast_sdp_m_add_payload(struct ast_sdp_m_line *m_line, struct ast_sdp_payload *payload)
+{
+ ast_assert(m_line && payload);
+
+ return AST_VECTOR_APPEND(m_line->payloads, payload);
+}
+
+int ast_sdp_m_get_payload_count(struct ast_sdp_m_line *m_line)
+{
+ ast_assert(m_line != NULL);
+
+ return AST_VECTOR_SIZE(m_line->payloads);
+}
+
+struct ast_sdp_payload *ast_sdp_m_get_payload(struct ast_sdp_m_line *m_line, int index)
+{
+ ast_assert(m_line != NULL);
+
+ return AST_VECTOR_GET(m_line->payloads, index);
+}
+
+static int sdp_m_add_fmtp(struct ast_sdp_m_line *m_line, struct ast_format *format, int rtp_code)
+{
+ struct ast_str *fmtp0 = ast_str_alloca(256);
+ char *tmp;
+
+ ast_format_generate_sdp_fmtp(format, rtp_code, &fmtp0);
+ if (ast_str_strlen(fmtp0) == 0) {
+ return -1;
+ }
+
+ tmp = ast_str_buffer(fmtp0) + ast_str_strlen(fmtp0) - 1;
+ /* remove any carriage return line feeds */
+ while (*tmp == '\r' || *tmp == '\n') --tmp;
+ *++tmp = '\0';
+
+ /* ast...generate gives us everything, just need value */
+ tmp = strchr(ast_str_buffer(fmtp0), ':');
+ if (tmp && tmp[1] != '\0') {
+ tmp++;
+ } else {
+ tmp = ast_str_buffer(fmtp0);
+ }
+
+ ast_sdp_m_add_a(m_line, ast_sdp_a_alloc("fmtp", tmp));
+
+ return 0;
+}
+
+static int sdp_m_add_rtpmap(struct ast_sdp_m_line *m_line, struct ast_sdp_options *options,
+ int rtp_code, int asterisk_format, struct ast_format *format, int code)
+{
+ char tmp[64];
+ char rtmap[64];
+ const char *enc_name;
+ struct ast_sdp_payload *payload;
+ struct ast_sdp_a_line *a_line;
+
+ snprintf(tmp, sizeof(tmp), "%d", rtp_code);
+ payload = ast_sdp_payload_alloc(tmp);
+ if (!payload || ast_sdp_m_add_payload(m_line, payload)) {
+ ast_sdp_payload_free(payload);
+ return -1;
+ }
+
+ enc_name = ast_rtp_lookup_mime_subtype2(asterisk_format, format, code,
+ options->g726_non_standard ? AST_RTP_OPT_G726_NONSTANDARD : 0);
+
+ snprintf(tmp, sizeof(rtmap), "%d %s/%d%s%s", rtp_code, enc_name,
+ ast_rtp_lookup_sample_rate2(asterisk_format, format, code),
+ strcmp(enc_name, "opus") ? "" : "/", strcmp(enc_name, "opus") ? "" : "2");
+
+ a_line = ast_sdp_a_alloc("rtpmap", tmp);
+ if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
+ ast_sdp_a_free(a_line);
+ return -1;
+ }
+
+ return 0;
+}
+
+int ast_sdp_m_add_format(struct ast_sdp_m_line *m_line, struct ast_sdp_options *options,
+ int rtp_code, int asterisk_format, struct ast_format *format, int code)
+{
+ sdp_m_add_rtpmap(m_line, options, rtp_code, asterisk_format, format, code);
+ sdp_m_add_fmtp(m_line, format, rtp_code);
+
+ return 0;
+}
+
+/* TODO
+ * This isn't set anywhere yet.
+ */
+/*! \brief Scheduler for RTCP purposes */
+static struct ast_sched_context *sched;
+
+/*! \brief Internal function which creates an RTP instance */
+static struct ast_rtp_instance *create_rtp(struct ast_sdp_options *options,
+ enum ast_media_type media_type)
+{
+ struct ast_rtp_instance *rtp;
+ struct ast_rtp_engine_ice *ice;
+ struct ast_sockaddr temp_media_address;
+ static struct ast_sockaddr address_rtp;
+ struct ast_sockaddr *media_address = &address_rtp;
+
+ if (options->bind_rtp_to_media_address && !ast_strlen_zero(options->media_address)) {
+ ast_sockaddr_parse(&temp_media_address, options->media_address, 0);
+ media_address = &temp_media_address;
+ } else {
+ if (ast_check_ipv6()) {
+ ast_sockaddr_parse(&address_rtp, "::", 0);
+ } else {
+ ast_sockaddr_parse(&address_rtp, "0.0.0.0", 0);
+ }
+ }
+
+ if (!(rtp = ast_rtp_instance_new(options->rtp_engine, sched, media_address, NULL))) {
+ ast_log(LOG_ERROR, "Unable to create RTP instance using RTP engine '%s'\n",
+ options->rtp_engine);
+ return NULL;
+ }
+
+ ast_rtp_instance_set_prop(rtp, AST_RTP_PROPERTY_RTCP, 1);
+ ast_rtp_instance_set_prop(rtp, AST_RTP_PROPERTY_NAT, options->rtp_symmetric);
+
+ if (options->ice == AST_SDP_ICE_DISABLED && (ice = ast_rtp_instance_get_ice(rtp))) {
+ ice->stop(rtp);
+ }
+
+ if (options->telephone_event) {
+ ast_rtp_instance_dtmf_mode_set(rtp, AST_RTP_DTMF_MODE_RFC2833);
+ ast_rtp_instance_set_prop(rtp, AST_RTP_PROPERTY_DTMF, 1);
+ }
+
+ if (media_type == AST_MEDIA_TYPE_AUDIO &&
+ (options->tos.tos_audio || options->tos.cos_audio)) {
+ ast_rtp_instance_set_qos(rtp, options->tos.tos_audio,
+ options->tos.cos_audio, "SIP RTP Audio");
+ } else if (media_type == AST_MEDIA_TYPE_VIDEO &&
+ (options->tos.tos_video || options->tos.cos_video)) {
+ ast_rtp_instance_set_qos(rtp, options->tos.tos_video,
+ options->tos.cos_video, "SIP RTP Video");
+ }
+
+ ast_rtp_instance_set_last_rx(rtp, time(NULL));
+
+ return rtp;
+}
+
+
+int ast_sdp_add_m_from_stream(struct ast_sdp *sdp, struct ast_sdp_options *options,
+ struct ast_rtp_instance *rtp, struct ast_stream *stream)
+{
+ struct ast_sdp_m_line *m_line;
+ struct ast_format_cap *caps;
+ int i;
+ int rtp_code;
+ int min_packet_size = 0;
+ int max_packet_size = 0;
+ enum ast_media_type media_type;
+ char tmp[64];
+ struct ast_sockaddr address_rtp;
+ struct ast_sdp_a_line *a_line;
+
+
+ ast_assert(sdp && options && rtp && stream);
+
+ media_type = ast_stream_get_type(stream);
+ ast_rtp_instance_get_local_address(rtp, &address_rtp);
+
+ m_line = ast_sdp_m_alloc(
+ ast_codec_media_type2str(ast_stream_get_type(stream)),
+ ast_sockaddr_port(&address_rtp), 1,
+ options->encryption != AST_SDP_ENCRYPTION_DISABLED ? "RTP/SAVP" : "RTP/AVP",
+ NULL);
+ if (!m_line) {
+ return -1;
+ }
+
+ caps = ast_stream_get_formats(stream);
+
+ for (i = 0; i < ast_format_cap_count(caps); i++) {
+ struct ast_format *format = ast_format_cap_get_format(caps, i);
+
+ if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(rtp), 1, format, 0)) == -1) {
+ ast_log(LOG_WARNING,"Unable to get rtp codec payload code for %s\n", ast_format_get_name(format));
+ ao2_ref(format, -1);
+ continue;
+ }
+
+ if (ast_sdp_m_add_format(m_line, options, rtp_code, 0, format, 0)) {
+ ast_sdp_m_free(m_line);
+ return -1;
+ }
+
+ if (ast_format_get_maximum_ms(format) &&
+ ((ast_format_get_maximum_ms(format) < max_packet_size) || !max_packet_size)) {
+ max_packet_size = ast_format_get_maximum_ms(format);
+ }
+
+ ao2_ref(format, -1);
+ }
+
+ if (media_type != AST_MEDIA_TYPE_VIDEO) {
+ for (i = 1LL; i <= AST_RTP_MAX; i <<= 1) {
+ if (!(options->telephone_event & i)) {
+ continue;
+ }
+
+ rtp_code = ast_rtp_codecs_payload_code(
+ ast_rtp_instance_get_codecs(rtp), 0, NULL, i);
+
+ if (rtp_code == -1) {
+ continue;
+ }
+
+ if (sdp_m_add_rtpmap(m_line, options, rtp_code, 0, NULL, i)) {
+ continue;
+ }
+
+ if (i == AST_RTP_DTMF) {
+ snprintf(tmp, sizeof(tmp), "%d 0-16", rtp_code);
+ a_line = ast_sdp_a_alloc("fmtp", tmp);
+ if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
+ ast_sdp_a_free(a_line);
+ ast_sdp_m_free(m_line);
+ return -1;
+ }
+ }
+ }
+ }
+
+ if (ast_sdp_m_get_a_count(m_line) == 0) {
+ return 0;
+ }
+
+ /* If ptime is set add it as an attribute */
+ min_packet_size = ast_rtp_codecs_get_framing(ast_rtp_instance_get_codecs(rtp));
+ if (!min_packet_size) {
+ min_packet_size = ast_format_cap_get_framing(caps);
+ }
+ if (min_packet_size) {
+ snprintf(tmp, sizeof(tmp), "%d", min_packet_size);
+
+ a_line = ast_sdp_a_alloc("ptime", tmp);
+ if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
+ ast_sdp_a_free(a_line);
+ ast_sdp_m_free(m_line);
+ return -1;
+ }
+ }
+
+ if (max_packet_size) {
+ snprintf(tmp, sizeof(tmp), "%d", max_packet_size);
+ a_line = ast_sdp_a_alloc("maxptime", tmp);
+ if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
+ ast_sdp_a_free(a_line);
+ ast_sdp_m_free(m_line);
+ return -1;
+ }
+ }
+
+ a_line = ast_sdp_a_alloc(options->locally_held ? "sendonly" : "sendrecv", "");
+ if (!a_line || ast_sdp_m_add_a(m_line, a_line)) {
+ ast_sdp_a_free(a_line);
+ ast_sdp_m_free(m_line);
+ return -1;
+ }
+
+ if (ast_sdp_add_m(sdp, m_line)) {
+ ast_sdp_m_free(m_line);
+ return -1;
+ }
+
+ return 0;
+}
+
+struct ast_sdp *ast_sdp_create_from_state(struct ast_sdp_state *sdp_state)
+{
+ struct ast_sdp_options *options;
+ RAII_VAR(struct ast_sdp *, sdp, NULL, ao2_cleanup);
+ struct ast_stream_topology *topology;
+ int stream_count;
+ int stream_num;
+ struct ast_sdp_o_line *o_line;
+ struct ast_sdp_c_line *c_line;
+ struct ast_sdp_s_line *s_line;
+ struct ast_sdp_t_line *t_line;
+ struct ast_rtp_instance *rtp;
+
+ ast_assert(!!sdp_state);
+
+ options = ast_sdp_state_get_options(sdp_state);
+ topology = ast_sdp_state_get_local_topology(sdp_state);
+ stream_count = ast_stream_topology_get_count(topology);
+
+ /* TODO
+ * Fill in...
+ */
+ o_line = ast_sdp_o_alloc("user", 99999, 0, "IN4", "127.0.0.1");
+ if (!o_line) {
+ goto error;
+ }
+ c_line = ast_sdp_c_alloc("IN4", "127.0.0.1");
+ if (!o_line) {
+ goto error;
+ }
+
+ s_line = ast_sdp_s_alloc("session name");
+ if (!o_line) {
+ goto error;
+ }
+ t_line = ast_sdp_t_alloc(999, 9999);
+
+ sdp = ast_sdp_alloc(o_line, c_line, s_line, t_line);
+ if (!sdp) {
+ goto error;
+ }
+
+ for (stream_num = 0; stream_num < stream_count; stream_num++) {
+ struct ast_stream *stream = ast_stream_topology_get_stream(topology, stream_num);
+
+ rtp = create_rtp(options, ast_stream_get_type(stream));
+ if (!rtp) {
+ goto error;
+ }
+
+ ast_stream_set_data(stream, rtp, (ast_stream_data_free_fn)&ast_rtp_instance_destroy);
+
+ if (ast_sdp_add_m_from_stream(sdp, options, rtp, stream)) {
+ goto error;
+ }
+ }
+
+ return sdp;
+
+error:
+ ao2_cleanup(rtp);
+ if (sdp) {
+ ast_sdp_free(sdp);
+ } else {
+ ast_sdp_t_free(t_line);
+ ast_sdp_s_free(s_line);
+ ast_sdp_c_free(c_line);
+ ast_sdp_o_free(o_line);
+ }
+
+ return NULL;
+}
+
diff --git a/main/sdp_options.c b/main/sdp_options.c
index e18dfa5..a343d8d 100644
--- a/main/sdp_options.c
+++ b/main/sdp_options.c
@@ -21,13 +21,6 @@
#include "asterisk/utils.h"
#include "asterisk/sdp_options.h"
-struct ast_sdp_options {
- enum ast_sdp_options_ice ice;
- int telephone_event;
- enum ast_sdp_options_repr repr;
- enum ast_sdp_options_encryption encryption;
-};
-
#define DEFAULT_ICE AST_SDP_ICE_DISABLED
#define DEFAULT_TELEPHONE_EVENT 0
#define DEFAULT_REPR AST_SDP_REPR_STRING
diff --git a/main/sdp_repr.c b/main/sdp_repr.c
deleted file mode 100644
index 6df243b..0000000
--- a/main/sdp_repr.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * 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_priv.h"
-#include "asterisk/utils.h"
-
-struct ast_sdp *ast_sdp_alloc(void)
-{
- struct ast_sdp *new_sdp;
-
- new_sdp = ast_calloc(1, sizeof *new_sdp);
- return new_sdp;
-}
-
-static void free_o_line(struct ast_sdp *dead)
-{
- ast_free(dead->o_line.user);
- ast_free(dead->o_line.family);
- ast_free(dead->o_line.addr);
-}
-
-static void free_s_line(struct ast_sdp *dead)
-{
- ast_free(dead->s_line);
-}
-
-static void free_c_line(struct ast_sdp_c_line *c_line)
-{
- ast_free(c_line->family);
- ast_free(c_line->addr);
-}
-
-static void free_t_line(struct ast_sdp_t_line *t_line)
-{
- return;
-}
-
-static void free_a_line(struct ast_sdp_a_line *a_line)
-{
- ast_free(a_line->name);
- ast_free(a_line->value);
-}
-
-static void free_a_lines(struct ast_sdp_a_line_vector *a_lines)
-{
- int i;
-
- for (i = 0; i < AST_VECTOR_SIZE(a_lines); ++i) {
- free_a_line(AST_VECTOR_GET_ADDR(a_lines, i));
- }
- AST_VECTOR_FREE(a_lines);
-}
-
-static void free_m_line(struct ast_sdp_m_line *m_line)
-{
- int i;
-
- ast_free(m_line->type);
- ast_free(m_line->profile);
- free_c_line(&m_line->c_line);
-
- for (i = 0; i < AST_VECTOR_SIZE(&m_line->payloads); ++i) {
- ast_free(AST_VECTOR_GET(&m_line->payloads, i));
- }
- AST_VECTOR_FREE(&m_line->payloads);
-
- free_a_lines(&m_line->a_lines);
-}
-
-static void free_m_lines(struct ast_sdp *dead)
-{
- int i;
-
- for (i = 0; i < AST_VECTOR_SIZE(&dead->m_lines); ++i) {
- free_m_line(AST_VECTOR_GET_ADDR(&dead->m_lines, i));
- }
-
- AST_VECTOR_FREE(&dead->m_lines);
-}
-
-void ast_sdp_free(struct ast_sdp *dead)
-{
- if (!dead) {
- return;
- }
-
- free_o_line(dead);
- free_s_line(dead);
- free_c_line(&dead->c_line);
- free_t_line(&dead->t_line);
- free_a_lines(&dead->a_lines);
- free_m_lines(dead);
- ast_free(dead);
-}
-
diff --git a/main/sdp_state.c b/main/sdp_state.c
index b478e71..cc9c51d 100644
--- a/main/sdp_state.c
+++ b/main/sdp_state.c
@@ -77,8 +77,6 @@
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;
/*! The current state machine state that we are in */
enum ast_sdp_state_machine state;
};
@@ -128,13 +126,16 @@
struct ast_rtp_instance *ast_sdp_state_get_rtp_instance(struct ast_sdp_state *sdp_state, int stream_index)
{
+ struct ast_stream *stream;
+
ast_assert(sdp_state != NULL);
- if (stream_index >= AST_VECTOR_SIZE(&sdp_state->rtp)) {
+ stream = ast_stream_topology_get_stream(sdp_state->local_capabilities, stream_index);
+ if (!stream) {
return NULL;
}
- return AST_VECTOR_GET(&sdp_state->rtp, stream_index);
+ return (struct ast_rtp_instance *)ast_stream_get_data(stream);
}
struct ast_stream_topology *ast_sdp_state_get_joint_topology(struct ast_sdp_state *sdp_state)
@@ -146,6 +147,21 @@
return sdp_state->local_capabilities;
}
}
+
+struct ast_stream_topology *ast_sdp_state_get_local_topology(struct ast_sdp_state *sdp_state)
+{
+ ast_assert(sdp_state != NULL);
+
+ return sdp_state->local_capabilities;
+}
+
+struct ast_sdp_options *ast_sdp_state_get_options(struct ast_sdp_state *sdp_state)
+{
+ ast_assert(sdp_state != NULL);
+
+ return sdp_state->options;
+}
+
static int merge_sdps(struct ast_sdp_state *sdp_state)
{
@@ -172,15 +188,14 @@
const void *ast_sdp_state_get_local(struct ast_sdp_state *sdp_state)
{
- struct ast_sdp *sdp;
+ struct ast_sdp *sdp = NULL;
ast_assert(sdp_state != NULL);
- /*TODO Create RTP instances based on local topology and SDP options (if not already created) */
- /*TODO Create local SDP based on local topology, SDP options, and RTP ports (if not already created) */
-
switch (sdp_state->state) {
case SDP_STATE_INITIAL:
+ sdp = ast_sdp_create_from_state(sdp_state);
+ sdp_state->local_sdp = sdp;
sdp_state->state = SDP_STATE_OFFERER;
/* Fall through */
case SDP_STATE_OFFERER:
diff --git a/main/stream.c b/main/stream.c
index 8bee2fd..33a71c9 100644
--- a/main/stream.c
+++ b/main/stream.c
@@ -57,6 +57,16 @@
enum ast_stream_state state;
/*!
+ * \brief Opaque stream data
+ */
+ void *data;
+
+ /*!
+ * \brief What to do with data when the stream is freed
+ */
+ ast_stream_data_free_fn data_free_fn;
+
+ /*!
* \brief Name for the stream within the context of the channel it is on
*/
char name[0];
@@ -112,6 +122,10 @@
{
if (!stream) {
return;
+ }
+
+ if (stream->data_free_fn) {
+ stream->data_free_fn(stream->data);
}
ao2_cleanup(stream->formats);
@@ -186,6 +200,25 @@
}
}
+void *ast_stream_get_data(struct ast_stream *stream)
+{
+ ast_assert(stream != NULL);
+
+ return stream->data;
+}
+
+void *ast_stream_set_data(struct ast_stream *stream, void *data,
+ ast_stream_data_free_fn data_free_fn)
+{
+ ast_assert(stream != NULL);
+
+ stream->data = data;
+ stream->data_free_fn = data_free_fn;
+
+ return data;
+}
+
+
int ast_stream_get_position(const struct ast_stream *stream)
{
ast_assert(stream != NULL);
diff --git a/res/res_sdp_translator_pjmedia.c b/res/res_sdp_translator_pjmedia.c
index 141b976..7086f9a 100644
--- a/res/res_sdp_translator_pjmedia.c
+++ b/res/res_sdp_translator_pjmedia.c
@@ -55,79 +55,45 @@
pj_pool_release(pool);
}
-static void copy_pj_str(char *dest, const pj_str_t *src, size_t size)
-{
- memcpy(dest, pj_strbuf(src), size);
- dest[size] = '\0';
-}
+#define dupa_pj_str(pjstr) \
+({ \
+ char *dest = ast_alloca(pjstr.slen + 1); \
+ memcpy(dest, pjstr.ptr, pjstr.slen); \
+ dest[pjstr.slen] = '\0'; \
+ dest; \
+})
-static void dup_pj_str(char **dest, const pj_str_t *src)
-{
- *dest = ast_malloc(pj_strlen(src) + 1);
- copy_pj_str(*dest, src, pj_strlen(src));
-}
-
-static void pjmedia_copy_o_line(struct ast_sdp *new_sdp, struct pjmedia_sdp_session * pjmedia_sdp)
-{
- dup_pj_str(&new_sdp->o_line.user, &pjmedia_sdp->origin.user);
- new_sdp->o_line.id = pjmedia_sdp->origin.id;
- new_sdp->o_line.version = pjmedia_sdp->origin.version;
- dup_pj_str(&new_sdp->o_line.family, &pjmedia_sdp->origin.addr_type);
- dup_pj_str(&new_sdp->o_line.addr, &pjmedia_sdp->origin.addr);
-}
-
-static void pjmedia_copy_s_line(struct ast_sdp *new_sdp, struct pjmedia_sdp_session *pjmedia_sdp)
-{
- dup_pj_str(&new_sdp->s_line, &pjmedia_sdp->name);
-}
-
-static void pjmedia_copy_t_line(struct ast_sdp_t_line *new_t_line, struct pjmedia_sdp_session *pjmedia_sdp)
-{
- new_t_line->start = pjmedia_sdp->time.start;
- new_t_line->end = pjmedia_sdp->time.stop;
-}
-
-static void pjmedia_copy_c_line(struct ast_sdp_c_line *new_c_line, struct pjmedia_sdp_conn *conn)
-{
- /* It's perfectly reasonable for a c line not to be present, especially within a media description */
- if (!conn) {
- return;
- }
-
- dup_pj_str(&new_c_line->family, &conn->addr_type);
- dup_pj_str(&new_c_line->addr, &conn->addr);
-}
-
-static void pjmedia_copy_m_line(struct ast_sdp_m_line *new_m_line, struct pjmedia_sdp_media *pjmedia_m_line)
+static struct ast_sdp_m_line *pjmedia_copy_m_line(struct pjmedia_sdp_media *pjmedia_m_line)
{
int i;
- dup_pj_str(&new_m_line->type, &pjmedia_m_line->desc.media);
- new_m_line->port = pjmedia_m_line->desc.port;
- new_m_line->port_count = pjmedia_m_line->desc.port_count;
- dup_pj_str(&new_m_line->profile, &pjmedia_m_line->desc.transport);
- pjmedia_copy_c_line(&new_m_line->c_line, pjmedia_m_line->conn);
+ struct ast_sdp_c_line *c_line = pjmedia_m_line->conn ?
+ ast_sdp_c_alloc(dupa_pj_str(pjmedia_m_line->conn->addr_type),
+ dupa_pj_str(pjmedia_m_line->conn->addr)) : NULL;
- AST_VECTOR_INIT(&new_m_line->payloads, pjmedia_m_line->desc.fmt_count);
+ struct ast_sdp_m_line *m_line = ast_sdp_m_alloc(dupa_pj_str(pjmedia_m_line->desc.media),
+ pjmedia_m_line->desc.port, pjmedia_m_line->desc.port_count,
+ dupa_pj_str(pjmedia_m_line->desc.transport), c_line);
+
for (i = 0; i < pjmedia_m_line->desc.fmt_count; ++i) {
- ++new_m_line->payloads.current;
- dup_pj_str(AST_VECTOR_GET_ADDR(&new_m_line->payloads, i), &pjmedia_m_line->desc.fmt[i]);
+ ast_sdp_m_add_payload(m_line, ast_sdp_payload_alloc(dupa_pj_str(pjmedia_m_line->desc.fmt[i])));
}
+
+ for (i = 0; i < pjmedia_m_line->attr_count; ++i) {
+ ast_sdp_m_add_a(m_line, ast_sdp_a_alloc(dupa_pj_str(pjmedia_m_line->attr[i]->name),
+ dupa_pj_str(pjmedia_m_line->attr[i]->value)));
+ }
+
+ return m_line;
}
-static void pjmedia_copy_a_lines(struct ast_sdp_a_line_vector *new_a_lines, pjmedia_sdp_attr **attr, unsigned int attr_count)
+static void pjmedia_copy_a_lines(struct ast_sdp *new_sdp, pjmedia_sdp_session *pjmedia_sdp)
{
int i;
- AST_VECTOR_INIT(new_a_lines, attr_count);
-
- for (i = 0; i < attr_count; ++i) {
- struct ast_sdp_a_line *a_line;
-
- ++new_a_lines->current;
- a_line = AST_VECTOR_GET_ADDR(new_a_lines, i);
- dup_pj_str(&a_line->name, &attr[i]->name);
- dup_pj_str(&a_line->value, &attr[i]->value);
+ for (i = 0; i < pjmedia_sdp->attr_count; ++i) {
+ ast_sdp_add_a(new_sdp, ast_sdp_a_alloc(dupa_pj_str(pjmedia_sdp->attr[i]->name),
+ dupa_pj_str(pjmedia_sdp->attr[i]->value)));
}
}
@@ -135,13 +101,8 @@
{
int i;
- AST_VECTOR_INIT(&new_sdp->m_lines, pjmedia_sdp->media_count);
-
for (i = 0; i < pjmedia_sdp->media_count; ++i) {
- ++new_sdp->m_lines.current;
-
- pjmedia_copy_m_line(AST_VECTOR_GET_ADDR(&new_sdp->m_lines, i), pjmedia_sdp->media[i]);
- pjmedia_copy_a_lines(&AST_VECTOR_GET_ADDR(&new_sdp->m_lines, i)->a_lines, pjmedia_sdp->media[i]->attr, pjmedia_sdp->media[i]->attr_count);
+ ast_sdp_add_m(new_sdp, pjmedia_copy_m_line(pjmedia_sdp->media[i]));
}
}
@@ -149,74 +110,87 @@
{
struct pjmedia_sdp_session *pjmedia_sdp = in;
- struct ast_sdp *new_sdp = ast_sdp_alloc();
+ struct ast_sdp_o_line *o_line = ast_sdp_o_alloc(dupa_pj_str(pjmedia_sdp->origin.user),
+ pjmedia_sdp->origin.id, pjmedia_sdp->origin.version, dupa_pj_str(pjmedia_sdp->origin.addr_type),
+ dupa_pj_str(pjmedia_sdp->origin.addr));
- pjmedia_copy_o_line(new_sdp, pjmedia_sdp);
- pjmedia_copy_s_line(new_sdp, pjmedia_sdp);
- pjmedia_copy_t_line(&new_sdp->t_line, pjmedia_sdp);
- pjmedia_copy_c_line(&new_sdp->c_line, pjmedia_sdp->conn);
- pjmedia_copy_a_lines(&new_sdp->a_lines, pjmedia_sdp->attr, pjmedia_sdp->attr_count);
+ struct ast_sdp_c_line *c_line = pjmedia_sdp->conn ?
+ ast_sdp_c_alloc(dupa_pj_str(pjmedia_sdp->conn->addr_type), dupa_pj_str(pjmedia_sdp->conn->addr)) : NULL;
+
+ struct ast_sdp_s_line *s_line = ast_sdp_s_alloc(dupa_pj_str(pjmedia_sdp->name));
+
+ struct ast_sdp_t_line *t_line = ast_sdp_t_alloc(pjmedia_sdp->time.start, pjmedia_sdp->time.stop);
+
+ struct ast_sdp *new_sdp = ast_sdp_alloc(o_line, c_line, s_line, t_line);
+
+ pjmedia_copy_a_lines(new_sdp, pjmedia_sdp);
pjmedia_copy_m_lines(new_sdp, pjmedia_sdp);
return new_sdp;
}
-static void copy_o_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp, struct ast_sdp *sdp)
+static void copy_o_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp,
+ struct ast_sdp_o_line *o_line)
{
- pjmedia_sdp->origin.id = sdp->o_line.id;
- pjmedia_sdp->origin.version = sdp->o_line.version;
- pj_strdup2(pool, &pjmedia_sdp->origin.user, sdp->o_line.user);
- pj_strdup2(pool, &pjmedia_sdp->origin.addr_type, sdp->o_line.family);
- pj_strdup2(pool, &pjmedia_sdp->origin.addr, sdp->o_line.addr);
+ pjmedia_sdp->origin.id = o_line->session_id;
+ pjmedia_sdp->origin.version = o_line->session_version;
+ pj_strdup2(pool, &pjmedia_sdp->origin.user, o_line->username);
+ pj_strdup2(pool, &pjmedia_sdp->origin.addr_type, o_line->address_type);
+ pj_strdup2(pool, &pjmedia_sdp->origin.addr, o_line->address);
pj_strdup2(pool, &pjmedia_sdp->origin.net_type, "IN");
}
-static void copy_s_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp, struct ast_sdp *sdp)
+static void copy_s_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp,
+ struct ast_sdp_s_line *s_line)
{
- pj_strdup2(pool, &pjmedia_sdp->name, sdp->s_line);
+ pj_strdup2(pool, &pjmedia_sdp->name, s_line->session_name);
}
static void copy_t_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp, struct ast_sdp_t_line *t_line)
{
- pjmedia_sdp->time.start = t_line->start;
- pjmedia_sdp->time.stop = t_line->end;
+ pjmedia_sdp->time.start = t_line->start_time;
+ pjmedia_sdp->time.stop = t_line->stop_time;
}
static void copy_c_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_conn **conn, struct ast_sdp_c_line *c_line)
{
pjmedia_sdp_conn *local_conn;
local_conn = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_conn);
- pj_strdup2(pool, &local_conn->addr_type, c_line->family);
- pj_strdup2(pool, &local_conn->addr, c_line->addr);
+ pj_strdup2(pool, &local_conn->addr_type, c_line->address_type);
+ pj_strdup2(pool, &local_conn->addr, c_line->address);
pj_strdup2(pool, &local_conn->net_type, "IN");
*conn = local_conn;
}
-static void copy_a_lines_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp, struct ast_sdp_a_line_vector *a_lines)
+static void copy_a_lines_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp, struct ast_sdp *sdp)
{
int i;
- for (i = 0; i < AST_VECTOR_SIZE(a_lines); ++i) {
+ for (i = 0; i < ast_sdp_get_a_count(sdp); ++i) {
pjmedia_sdp_attr *attr;
pj_str_t value;
+ struct ast_sdp_a_line *a_line;
- pj_strdup2(pool, &value, AST_VECTOR_GET(a_lines, i).value);
- attr = pjmedia_sdp_attr_create(pool, AST_VECTOR_GET(a_lines, i).name, &value);
+ a_line = ast_sdp_get_a(sdp, i);
+ pj_strdup2(pool, &value, a_line->value);
+ attr = pjmedia_sdp_attr_create(pool, a_line->name, &value);
pjmedia_sdp_session_add_attr(pjmedia_sdp, attr);
}
}
-static void copy_a_lines_pjmedia_media(pj_pool_t *pool, pjmedia_sdp_media *media, struct ast_sdp_a_line_vector *a_lines)
+static void copy_a_lines_pjmedia_media(pj_pool_t *pool, pjmedia_sdp_media *media, struct ast_sdp_m_line *m_line)
{
int i;
- for (i = 0; i < AST_VECTOR_SIZE(a_lines); ++i) {
+ for (i = 0; i < ast_sdp_m_get_a_count(m_line); ++i) {
pjmedia_sdp_attr *attr;
pj_str_t value;
+ struct ast_sdp_a_line *a_line;
- pj_strdup2(pool, &value, AST_VECTOR_GET(a_lines, i).value);
- attr = pjmedia_sdp_attr_create(pool, AST_VECTOR_GET(a_lines, i).name, &value);
+ a_line = ast_sdp_m_get_a(m_line, i);
+ pj_strdup2(pool, &value, a_line->value);
+ attr = pjmedia_sdp_attr_create(pool, a_line->name, &value);
pjmedia_sdp_media_add_attr(media, attr);
}
}
@@ -227,28 +201,28 @@
media->desc.port = m_line->port;
media->desc.port_count = m_line->port_count;
- pj_strdup2(pool, &media->desc.transport, m_line->profile);
+ pj_strdup2(pool, &media->desc.transport, m_line->proto);
pj_strdup2(pool, &media->desc.media, m_line->type);
- for (i = 0; i < AST_VECTOR_SIZE(&m_line->payloads); ++i) {
- pj_strdup2(pool, &media->desc.fmt[i], AST_VECTOR_GET(&m_line->payloads, i));
+ for (i = 0; i < ast_sdp_m_get_payload_count(m_line); ++i) {
+ pj_strdup2(pool, &media->desc.fmt[i], ast_sdp_m_get_payload(m_line, i)->fmt);
++media->desc.fmt_count;
}
- if (m_line->c_line.addr) {
- copy_c_line_pjmedia(pool, &media->conn, &m_line->c_line);
+ if (m_line->c_line && m_line->c_line->address) {
+ copy_c_line_pjmedia(pool, &media->conn, m_line->c_line);
}
- copy_a_lines_pjmedia_media(pool, media, &m_line->a_lines);
+ copy_a_lines_pjmedia_media(pool, media, m_line);
}
static void copy_m_lines_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp, struct ast_sdp *sdp)
{
int i;
- for (i = 0; i < AST_VECTOR_SIZE(&sdp->m_lines); ++i) {
+ for (i = 0; i < ast_sdp_get_m_count(sdp); ++i) {
pjmedia_sdp_media *media;
media = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_media);
- copy_m_line_pjmedia(pool, media, AST_VECTOR_GET_ADDR(&sdp->m_lines, i));
+ copy_m_line_pjmedia(pool, media, ast_sdp_get_m(sdp, i));
pjmedia_sdp->media[pjmedia_sdp->media_count] = media;
++pjmedia_sdp->media_count;
}
@@ -260,11 +234,11 @@
pjmedia_sdp_session *pjmedia_sdp;
pjmedia_sdp = PJ_POOL_ZALLOC_T(pool, pjmedia_sdp_session);
- copy_o_line_pjmedia(pool, pjmedia_sdp, sdp);
- copy_s_line_pjmedia(pool, pjmedia_sdp, sdp);
- copy_t_line_pjmedia(pool, pjmedia_sdp, &sdp->t_line);
- copy_c_line_pjmedia(pool, &pjmedia_sdp->conn, &sdp->c_line);
- copy_a_lines_pjmedia(pool, pjmedia_sdp, &sdp->a_lines);
+ copy_o_line_pjmedia(pool, pjmedia_sdp, sdp->o_line);
+ copy_s_line_pjmedia(pool, pjmedia_sdp, sdp->s_line);
+ copy_t_line_pjmedia(pool, pjmedia_sdp, sdp->t_line);
+ copy_c_line_pjmedia(pool, &pjmedia_sdp->conn, sdp->c_line);
+ copy_a_lines_pjmedia(pool, pjmedia_sdp, sdp);
copy_m_lines_pjmedia(pool, pjmedia_sdp, sdp);
return pjmedia_sdp;
}
@@ -279,19 +253,19 @@
#ifdef TEST_FRAMEWORK
-static int verify_s_line(char *s_line, char *expected)
+static int verify_s_line(struct ast_sdp_s_line *s_line, char *expected)
{
- return strcmp(s_line, expected) == 0;
+ return strcmp(s_line->session_name, expected) == 0;
}
static int verify_c_line(struct ast_sdp_c_line *c_line, char *family, char *addr)
{
- return strcmp(c_line->family, family) == 0 && strcmp(c_line->addr, addr) == 0;
+ return strcmp(c_line->address_type, family) == 0 && strcmp(c_line->address, addr) == 0;
}
static int verify_t_line(struct ast_sdp_t_line *t_line, uint32_t start, uint32_t end)
{
- return t_line->start == start && t_line->end == end;
+ return t_line->start_time == start && t_line->stop_time == end;
}
static int verify_m_line(struct ast_sdp *sdp, int index, char *type, int port, int port_count, char *profile, ...)
@@ -301,15 +275,15 @@
va_list ap;
int i;
- m_line = AST_VECTOR_GET_ADDR(&sdp->m_lines, index);
+ m_line = ast_sdp_get_m(sdp, index);
res = strcmp(m_line->type, type) == 0;
res |= m_line->port == port;
res |= m_line->port_count == port_count;
- res |= strcmp(m_line->profile, profile) == 0;
+ res |= strcmp(m_line->proto, profile) == 0;
va_start(ap, profile);
- for (i = 0; i < AST_VECTOR_SIZE(&m_line->payloads); ++i) {
+ for (i = 0; i < ast_sdp_m_get_payload_count(m_line); ++i) {
char *payload;
payload = va_arg(ap, char *);
@@ -317,7 +291,7 @@
res = -1;
break;
}
- res |= strcmp(AST_VECTOR_GET(&m_line->payloads, i), payload) == 0;
+ res |= strcmp(ast_sdp_m_get_payload(m_line, i)->fmt, payload) == 0;
}
va_end(ap);
return res;
@@ -328,8 +302,8 @@
struct ast_sdp_m_line *m_line;
struct ast_sdp_a_line *a_line;
- m_line = AST_VECTOR_GET_ADDR(&sdp->m_lines, m_index);
- a_line = AST_VECTOR_GET_ADDR(&m_line->a_lines, a_index);
+ m_line = ast_sdp_get_m(sdp, m_index);
+ a_line = ast_sdp_m_get_a(m_line, a_index);
return strcmp(a_line->name, name) == 0 && strcmp(a_line->value, value) == 0;
}
@@ -343,7 +317,7 @@
"o=alice 2890844526 2890844526 IN IP4 host.atlanta.example.com\r\n"
"s= \r\n"
"c=IN IP4 host.atlanta.example.com\r\n"
- "t=0 0\r\n"
+ "t=123 456\r\n"
"m=audio 49170 RTP/AVP 0 8 97\r\n"
"a=rtpmap:0 PCMU/8000\r\n"
"a=rtpmap:8 PCMA/8000\r\n"
@@ -387,24 +361,24 @@
sdp = ast_sdp_translator_to_sdp(translator, pjmedia_sdp);
- if (strcmp(sdp->o_line.user, "alice")) {
- ast_test_status_update(test, "Unexpected SDP user '%s'\n", sdp->o_line.user);
+ if (strcmp(sdp->o_line->username, "alice")) {
+ ast_test_status_update(test, "Unexpected SDP user '%s'\n", sdp->o_line->username);
res = AST_TEST_FAIL;
goto cleanup;
- } else if (sdp->o_line.id != 2890844526u) {
- ast_test_status_update(test, "Unexpected SDP id '%u'\n", sdp->o_line.id);
+ } else if (sdp->o_line->session_id != 2890844526u) {
+ ast_test_status_update(test, "Unexpected SDP id '%u'\n", sdp->o_line->session_id);
res = AST_TEST_FAIL;
goto cleanup;
- } else if (sdp->o_line.version != 2890844526u) {
- ast_test_status_update(test, "Unexpected SDP version '%u'\n", sdp->o_line.version);
+ } else if (sdp->o_line->session_version != 2890844526u) {
+ ast_test_status_update(test, "Unexpected SDP version '%u'\n", sdp->o_line->session_version);
res = AST_TEST_FAIL;
goto cleanup;
- } else if (strcmp(sdp->o_line.family, "IP4")) {
- ast_test_status_update(test, "Unexpected address family '%s'\n", sdp->o_line.family);
+ } else if (strcmp(sdp->o_line->address_type, "IP4")) {
+ ast_test_status_update(test, "Unexpected address family '%s'\n", sdp->o_line->address_type);
res = AST_TEST_FAIL;
goto cleanup;
- } else if (strcmp(sdp->o_line.addr, "host.atlanta.example.com")) {
- ast_test_status_update(test, "Unexpected address '%s'\n", sdp->o_line.addr);
+ } else if (strcmp(sdp->o_line->address, "host.atlanta.example.com")) {
+ ast_test_status_update(test, "Unexpected address '%s'\n", sdp->o_line->address);
res = AST_TEST_FAIL;
goto cleanup;
}
@@ -413,11 +387,11 @@
ast_test_status_update(test, "Bad s line\n");
res = AST_TEST_FAIL;
goto cleanup;
- } else if (!verify_c_line(&sdp->c_line, "IP4", "host.atlanta.example.com")) {
+ } else if (!verify_c_line(sdp->c_line, "IP4", "host.atlanta.example.com")) {
ast_test_status_update(test, "Bad c line\n");
res = AST_TEST_FAIL;
goto cleanup;
- } else if (!verify_t_line(&sdp->t_line, 0, 0)) {
+ } else if (!verify_t_line(sdp->t_line, 123, 456)) {
ast_test_status_update(test, "Bad t line\n");
res = AST_TEST_FAIL;
goto cleanup;
@@ -472,7 +446,7 @@
"o=alice 2890844526 2890844526 IN IP4 host.atlanta.example.com\r\n"
"s= \r\n"
"c=IN IP4 host.atlanta.example.com\r\n"
- "t=0 0\r\n"
+ "t=123 456\r\n"
"m=audio 49170 RTP/AVP 0 8 97\r\n"
"a=rtpmap:0 PCMU/8000\r\n"
"a=rtpmap:8 PCMA/8000\r\n"
@@ -487,6 +461,8 @@
struct ast_sdp *sdp = NULL;
pj_status_t status;
enum ast_test_result_state res = AST_TEST_PASS;
+ char buf[2048];
+ char errbuf[256];
switch (cmd) {
case TEST_INIT:
@@ -520,15 +496,13 @@
pjmedia_sdp_dup = ast_sdp_translator_from_sdp(translator, sdp);
if ((status = pjmedia_sdp_session_cmp(pjmedia_sdp_orig, pjmedia_sdp_dup, 0)) != PJ_SUCCESS) {
- char buf[2048];
- char errbuf[256];
ast_test_status_update(test, "SDPs aren't equal\n");
pjmedia_sdp_print(pjmedia_sdp_orig, buf, sizeof(buf));
- ast_log(LOG_NOTICE, "Original SDP is %s\n", buf);
+ ast_test_status_update(test, "Original SDP is %s\n", buf);
pjmedia_sdp_print(pjmedia_sdp_dup, buf, sizeof(buf));
- ast_log(LOG_NOTICE, "New SDP is %s\n", buf);
+ ast_test_status_update(test, "New SDP is %s\n", buf);
pjmedia_strerror(status, errbuf, sizeof(errbuf));
- ast_log(LOG_NOTICE, "PJMEDIA says %d: '%s'\n", status, errbuf);
+ ast_test_status_update(test, "PJMEDIA says %d: '%s'\n", status, errbuf);
res = AST_TEST_FAIL;
goto cleanup;
}
--
To view, visit https://gerrit.asterisk.org/5119
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iefbd877af7f5a4d3c74deead1bff8802661b0d48
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