mirror of https://github.com/asterisk/asterisk
* 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: Iefbd877af7f5a4d3c74deead1bff8802661b0d48pull/7/head
parent
018e01543d
commit
8470c2bdea
@ -0,0 +1,559 @@
|
|||||||
|
/*
|
||||||
|
* Asterisk -- An open source telephony toolkit.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017, Digium, Inc.
|
||||||
|
*
|
||||||
|
* Mark Michelson <mmichelson@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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* NOTE: It is unlikely that you need to include this file. You probably will only need
|
||||||
|
* this if you are an SDP translator, or if you are an inner part of the SDP API
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SDP_PRIV_H
|
||||||
|
#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
|
||||||
|
*/
|
||||||
|
struct ast_sdp_a_line {
|
||||||
|
/*! Attribute name */
|
||||||
|
char *name;
|
||||||
|
/*! Attribute value. For attributes that have no value, this will be an empty string */
|
||||||
|
char *value;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \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 *address_type;
|
||||||
|
/* Connection address. Can be an IP address or FQDN */
|
||||||
|
char *address;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Structre representing SDP Media Payloads
|
||||||
|
*/
|
||||||
|
struct ast_sdp_payload {
|
||||||
|
/* Media format description */
|
||||||
|
char *fmt;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \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.
|
||||||
|
*/
|
||||||
|
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 payloads */
|
||||||
|
struct ast_sdp_payloads *payloads;
|
||||||
|
/*! Connection information for this media stream */
|
||||||
|
struct ast_sdp_c_line *c_line;
|
||||||
|
/*! The attributes for this media stream */
|
||||||
|
struct ast_sdp_a_lines *a_lines;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \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 */
|
||||||
|
uint64_t session_id;
|
||||||
|
/*! Origin version */
|
||||||
|
uint64_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 */
|
||||||
|
uint64_t start_time;
|
||||||
|
/*! Session end time */
|
||||||
|
uint64_t stop_time;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief An SDP
|
||||||
|
*/
|
||||||
|
struct ast_sdp {
|
||||||
|
/*! SDP Origin line */
|
||||||
|
struct ast_sdp_o_line *o_line;
|
||||||
|
/*! SDP Session name */
|
||||||
|
struct ast_sdp_s_line *s_line;
|
||||||
|
/*! SDP top-level connection information */
|
||||||
|
struct ast_sdp_c_line *c_line;
|
||||||
|
/*! SDP timing information */
|
||||||
|
struct ast_sdp_t_line *t_line;
|
||||||
|
/*! SDP top-level attributes */
|
||||||
|
struct ast_sdp_a_lines *a_lines;
|
||||||
|
/*! SDP media streams */
|
||||||
|
struct ast_sdp_m_lines *m_lines;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Free an SDP Attribute
|
||||||
|
*
|
||||||
|
* \param a_line The attribute to free
|
||||||
|
*
|
||||||
|
* \since 15
|
||||||
|
*/
|
||||||
|
void ast_sdp_a_free(struct ast_sdp_a_line *a_line);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Free an SDP Attribute collection
|
||||||
|
*
|
||||||
|
* \param a_lines The attribute collection to free
|
||||||
|
*
|
||||||
|
* \since 15
|
||||||
|
*/
|
||||||
|
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(const char *name, const 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(const char *family, const 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(const 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(const 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(const char *username, uint64_t session_id,
|
||||||
|
uint64_t session_version, const char *address_type, const 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(const 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(const 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, const struct ast_sdp_options *options,
|
||||||
|
struct ast_rtp_instance *rtp, const 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(const 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(const 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(const 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(const 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(const 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(const 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, const struct ast_sdp_options *options,
|
||||||
|
int rtp_code, int asterisk_format, const 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);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \brief Create an SDP from an existing SDP State local topology
|
||||||
|
*
|
||||||
|
* \param sdp_state SDP State
|
||||||
|
*
|
||||||
|
* \retval non-NULL Success
|
||||||
|
* \retval NULL Failure
|
||||||
|
*
|
||||||
|
* \since 15
|
||||||
|
*/
|
||||||
|
struct ast_sdp *ast_sdp_create_from_state(const struct ast_sdp_state *sdp_state);
|
||||||
|
|
||||||
|
#endif /* _SDP_PRIV_H */
|
@ -1,130 +0,0 @@
|
|||||||
/*
|
|
||||||
* Asterisk -- An open source telephony toolkit.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2017, Digium, Inc.
|
|
||||||
*
|
|
||||||
* Mark Michelson <mmichelson@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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* NOTE: It is unlikely that you need to include this file. You probably will only need
|
|
||||||
* this if you are an SDP translator, or if you are an inner part of the SDP API
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef _SDP_PRIV_H
|
|
||||||
#define _SDP_PRIV_H
|
|
||||||
|
|
||||||
#include "asterisk/vector.h"
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Structure representing an SDP attribute
|
|
||||||
*/
|
|
||||||
struct ast_sdp_a_line {
|
|
||||||
/*! Attribute name */
|
|
||||||
char *name;
|
|
||||||
/*! Attribute value. For attributes that have no value, this will be an empty string */
|
|
||||||
char *value;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Structure representing an SDP connection
|
|
||||||
*/
|
|
||||||
struct ast_sdp_c_line {
|
|
||||||
/* IP family string (e.g. IP4 or IP6) */
|
|
||||||
char *family;
|
|
||||||
/* Connection address. Can be an IP address or FQDN */
|
|
||||||
char *addr;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief A collection of SDP attributes
|
|
||||||
*/
|
|
||||||
AST_VECTOR(ast_sdp_a_line_vector, struct ast_sdp_a_line);
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief An SDP media stream
|
|
||||||
*
|
|
||||||
* This contains both the m line, as well as its
|
|
||||||
* constituent a lines.
|
|
||||||
*/
|
|
||||||
struct ast_sdp_m_line {
|
|
||||||
/*! Media type (e.g. "audio" or "video") */
|
|
||||||
char *type;
|
|
||||||
/*! 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;
|
|
||||||
/*! Connection information for this media stream */
|
|
||||||
struct ast_sdp_c_line c_line;
|
|
||||||
/*! The attributes for this media stream */
|
|
||||||
struct ast_sdp_a_line_vector a_lines;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief SDP time information
|
|
||||||
*/
|
|
||||||
struct ast_sdp_t_line {
|
|
||||||
/*! Session start time */
|
|
||||||
uint32_t start;
|
|
||||||
/*! Session end time */
|
|
||||||
uint32_t end;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief An SDP
|
|
||||||
*/
|
|
||||||
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;
|
|
||||||
/*! SDP Session name */
|
|
||||||
char *s_line;
|
|
||||||
/*! SDP top-level connection information */
|
|
||||||
struct ast_sdp_c_line c_line;
|
|
||||||
/*! SDP timing information */
|
|
||||||
struct ast_sdp_t_line t_line;
|
|
||||||
/*! SDP top-level attributes */
|
|
||||||
struct ast_sdp_a_line_vector a_lines;
|
|
||||||
/*! SDP media streams */
|
|
||||||
AST_VECTOR(, struct ast_sdp_m_line) m_lines;
|
|
||||||
};
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Allocate a new SDP.
|
|
||||||
*
|
|
||||||
* \note This does not perform any initialization.
|
|
||||||
*
|
|
||||||
* \retval NULL FAIL
|
|
||||||
* \retval non-NULL New SDP
|
|
||||||
*/
|
|
||||||
struct ast_sdp *ast_sdp_alloc(void);
|
|
||||||
|
|
||||||
/*!
|
|
||||||
* \brief Free an SDP and all its constituent parts
|
|
||||||
*/
|
|
||||||
void ast_sdp_free(struct ast_sdp *dead);
|
|
||||||
|
|
||||||
#endif /* _SDP_PRIV_H */
|
|
@ -0,0 +1,765 @@
|
|||||||
|
/*
|
||||||
|
* Asterisk -- An open source telephony toolkit.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017, Digium, Inc.
|
||||||
|
*
|
||||||
|
* George Joseph <gjoseph@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.h"
|
||||||
|
#include "asterisk/vector.h"
|
||||||
|
#include "asterisk/utils.h"
|
||||||
|
#include "asterisk/stream.h"
|
||||||
|
#include "sdp_private.h"
|
||||||
|
|
||||||
|
void ast_sdp_a_free(struct ast_sdp_a_line *a_line)
|
||||||
|
{
|
||||||
|
ast_free(a_line);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ast_sdp_a_lines_free(struct ast_sdp_a_lines *a_lines)
|
||||||
|
{
|
||||||
|
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_free(c_line);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ast_sdp_payload_free(struct ast_sdp_payload *payload)
|
||||||
|
{
|
||||||
|
ast_free(payload);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ast_sdp_payloads_free(struct ast_sdp_payloads *payloads)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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_free(o_line);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ast_sdp_s_free(struct ast_sdp_s_line *s_line)
|
||||||
|
{
|
||||||
|
ast_free(s_line);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ast_sdp_t_free(struct ast_sdp_t_line *t_line)
|
||||||
|
{
|
||||||
|
ast_free(t_line);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ast_sdp_free(struct ast_sdp *sdp)
|
||||||
|
{
|
||||||
|
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(const char *name, const 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(const char *address_type, const 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(const 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(const 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(const char *username, uint64_t session_id,
|
||||||
|
uint64_t session_version, const char *address_type, const 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 = ast_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(const struct ast_sdp *sdp)
|
||||||
|
{
|
||||||
|
ast_assert(sdp != NULL);
|
||||||
|
|
||||||
|
return AST_VECTOR_SIZE(sdp->a_lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ast_sdp_a_line *ast_sdp_get_a(const 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(const struct ast_sdp *sdp)
|
||||||
|
{
|
||||||
|
ast_assert(sdp != NULL);
|
||||||
|
|
||||||
|
return AST_VECTOR_SIZE(sdp->m_lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct ast_sdp_m_line *ast_sdp_get_m(const 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(const 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(const 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(const 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(const 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, const 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,
|
||||||
|
const struct ast_sdp_options *options, int rtp_code, int asterisk_format,
|
||||||
|
const struct ast_format *format, int code)
|
||||||
|
{
|
||||||
|
char tmp[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(tmp), "%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, const struct ast_sdp_options *options,
|
||||||
|
int rtp_code, int asterisk_format, const 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(const 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_audio || options->cos_audio)) {
|
||||||
|
ast_rtp_instance_set_qos(rtp, options->tos_audio,
|
||||||
|
options->cos_audio, "SIP RTP Audio");
|
||||||
|
} else if (media_type == AST_MEDIA_TYPE_VIDEO &&
|
||||||
|
(options->tos_video || options->cos_video)) {
|
||||||
|
ast_rtp_instance_set_qos(rtp, options->tos_video,
|
||||||
|
options->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, const struct ast_sdp_options *options,
|
||||||
|
struct ast_rtp_instance *rtp, const 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);
|
||||||
|
ao2_ref(format, -1);
|
||||||
|
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(const struct ast_sdp_state *sdp_state)
|
||||||
|
{
|
||||||
|
const struct ast_sdp_options *options;
|
||||||
|
RAII_VAR(struct ast_sdp *, sdp, NULL, ao2_cleanup);
|
||||||
|
const const struct ast_stream_topology *topology;
|
||||||
|
int stream_count;
|
||||||
|
int stream_num;
|
||||||
|
struct ast_sdp_o_line *o_line = NULL;
|
||||||
|
struct ast_sdp_c_line *c_line = NULL;
|
||||||
|
struct ast_sdp_s_line *s_line = NULL;
|
||||||
|
struct ast_sdp_t_line *t_line = NULL;
|
||||||
|
struct ast_rtp_instance *rtp = NULL;
|
||||||
|
char *address_type;
|
||||||
|
struct timeval tv = ast_tvnow();
|
||||||
|
uint32_t t;
|
||||||
|
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);
|
||||||
|
|
||||||
|
t = tv.tv_sec + 2208988800UL;
|
||||||
|
address_type = (strchr(options->media_address, ':') ? "IP6" : "IP4");
|
||||||
|
|
||||||
|
o_line = ast_sdp_o_alloc(options->sdpowner, t, t, address_type, options->media_address);
|
||||||
|
if (!o_line) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
c_line = ast_sdp_c_alloc(address_type, options->media_address);
|
||||||
|
if (!c_line) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
s_line = ast_sdp_s_alloc(options->sdpsession);
|
||||||
|
if (!s_line) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
sdp = ast_sdp_alloc(o_line, c_line, s_line, NULL);
|
||||||
|
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, AST_STREAM_DATA_RTP_INSTANCE,
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* Asterisk -- An open source telephony toolkit.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2017, Digium, Inc.
|
||||||
|
*
|
||||||
|
* Mark Michelson <mmichelson@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 _MAIN_SDP_PRIVATE_H
|
||||||
|
#define _MAIN_SDP_PRIVATE_H
|
||||||
|
|
||||||
|
#include "asterisk/stringfields.h"
|
||||||
|
#include "asterisk/sdp_options.h"
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
enum ast_sdp_options_ice ice;
|
||||||
|
enum ast_sdp_options_impl impl;
|
||||||
|
enum ast_sdp_options_encryption encryption;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* _MAIN_SDP_PRIVATE_H */
|
@ -1,111 +0,0 @@
|
|||||||
/*
|
|
||||||
* Asterisk -- An open source telephony toolkit.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2017, Digium, Inc.
|
|
||||||
*
|
|
||||||
* Mark Michelson <mmichelson@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);
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in new issue