mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-03 11:25:35 +00:00
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
This commit is contained in:
@@ -1432,7 +1432,8 @@ unsigned int ast_rtp_codecs_get_framing(struct ast_rtp_codecs *codecs);
|
||||
*
|
||||
* \since 1.8
|
||||
*/
|
||||
unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format, struct ast_format *format, int code);
|
||||
unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format,
|
||||
const struct ast_format *format, int code);
|
||||
|
||||
/*!
|
||||
* \brief Retrieve all formats that were found
|
||||
@@ -1537,7 +1538,8 @@ int ast_rtp_codecs_find_payload_code(struct ast_rtp_codecs *codecs, int payload)
|
||||
*
|
||||
* \since 1.8
|
||||
*/
|
||||
const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format, struct ast_format *format, int code, enum ast_rtp_options options);
|
||||
const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format,
|
||||
const struct ast_format *format, int code, enum ast_rtp_options options);
|
||||
|
||||
/*!
|
||||
* \brief Convert formats into a string and put them into a buffer
|
||||
|
559
include/asterisk/sdp.h
Normal file
559
include/asterisk/sdp.h
Normal file
@@ -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 */
|
@@ -21,6 +21,48 @@
|
||||
|
||||
struct ast_sdp_options;
|
||||
|
||||
/*!
|
||||
* \brief ICE options
|
||||
*
|
||||
* This is an enum because it will support a TRICKLE-ICE option
|
||||
* in the future.
|
||||
*/
|
||||
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 Implementation of the SDP
|
||||
*
|
||||
* Users of the SDP API set the implementation 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_impl {
|
||||
/*! SDP is represented as a string */
|
||||
AST_SDP_IMPL_STRING,
|
||||
/*! SDP is represented as a pjmedia_sdp_session */
|
||||
AST_SDP_IMPL_PJMEDIA,
|
||||
/*! End of the list */
|
||||
AST_SDP_IMPL_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,
|
||||
};
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Allocate a new SDP options structure.
|
||||
@@ -47,111 +89,343 @@ struct ast_sdp_options *ast_sdp_options_alloc(void);
|
||||
void ast_sdp_options_free(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \brief ICE options
|
||||
* \since 15.0.0
|
||||
* \brief Set SDP Options media_address
|
||||
*
|
||||
* This is an enum because it is predicted that this eventually
|
||||
* support a TRICKLE-ICE option.
|
||||
* \param options SDP Options
|
||||
* \param media_address
|
||||
*/
|
||||
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,
|
||||
};
|
||||
void ast_sdp_options_set_media_address(struct ast_sdp_options *options,
|
||||
const char *media_address);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set ICE options
|
||||
* \brief Get SDP Options media_address
|
||||
*
|
||||
* The default is AST_SDP_ICE_DISABLED
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns media_address
|
||||
*/
|
||||
int ast_sdp_options_set_ice(struct ast_sdp_options *options,
|
||||
enum ast_sdp_options_ice ice_setting);
|
||||
const char *ast_sdp_options_get_media_address(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Retrieve ICE options
|
||||
* \brief Set SDP Options sdpowner
|
||||
*
|
||||
* \param options SDP Options
|
||||
* \param sdpowner
|
||||
*/
|
||||
enum ast_sdp_options_ice ast_sdp_options_get_ice(const struct ast_sdp_options *options);
|
||||
void ast_sdp_options_set_sdpowner(struct ast_sdp_options *options,
|
||||
const char *sdpowner);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Enable or disable telephone events.
|
||||
* \brief Get SDP Options sdpowner
|
||||
*
|
||||
* A non-zero value indicates telephone events are enabled.
|
||||
* A zero value indicates telephone events are disabled.
|
||||
* \param options SDP Options
|
||||
*
|
||||
* The default is 0
|
||||
* \returns sdpowner
|
||||
*/
|
||||
int ast_sdp_options_set_telephone_event(struct ast_sdp_options *options,
|
||||
int telephone_event_enabled);
|
||||
const char *ast_sdp_options_get_sdpowner(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Retrieve telephone event setting.
|
||||
* \brief Set SDP Options sdpsession
|
||||
*
|
||||
* \retval 0 Telephone events are currently disabled.
|
||||
* \retval non-zero Telephone events are currently enabled.
|
||||
* \param options SDP Options
|
||||
* \param sdpsession
|
||||
*/
|
||||
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,
|
||||
};
|
||||
void ast_sdp_options_set_sdpsession(struct ast_sdp_options *options,
|
||||
const char *sdpsession);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set the SDP representation
|
||||
* \brief Get SDP Options sdpsession
|
||||
*
|
||||
* The default is AST_SDP_REPR_STRING
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns sdpsession
|
||||
*/
|
||||
int ast_sdp_options_set_repr(struct ast_sdp_options *options,
|
||||
enum ast_sdp_options_repr repr);
|
||||
const char *ast_sdp_options_get_sdpsession(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Get the SDP representation
|
||||
* \brief Set SDP Options rtp_engine
|
||||
*
|
||||
* \param options SDP Options
|
||||
* \param rtp_engine
|
||||
*/
|
||||
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,
|
||||
};
|
||||
void ast_sdp_options_set_rtp_engine(struct ast_sdp_options *options,
|
||||
const char *rtp_engine);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set the SDP encryption
|
||||
* \brief Get SDP Options rtp_engine
|
||||
*
|
||||
* The default is AST_SDP_ENCRYPTION_DISABLED
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns rtp_engine
|
||||
*/
|
||||
int ast_sdp_options_set_encryption(struct ast_sdp_options *options,
|
||||
const char *ast_sdp_options_get_rtp_engine(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set SDP Options bind_rtp_to_media_address
|
||||
*
|
||||
* \param options SDP Options
|
||||
* \param bind_rtp_to_media_address
|
||||
*/
|
||||
void ast_sdp_options_set_bind_rtp_to_media_address(struct ast_sdp_options *options,
|
||||
unsigned int bind_rtp_to_media_address);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Get SDP Options bind_rtp_to_media_address
|
||||
*
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns bind_rtp_to_media_address
|
||||
*/
|
||||
unsigned int ast_sdp_options_get_bind_rtp_to_media_address(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set SDP Options rtp_symmetric
|
||||
*
|
||||
* \param options SDP Options
|
||||
* \param rtp_symmetric
|
||||
*/
|
||||
void ast_sdp_options_set_rtp_symmetric(struct ast_sdp_options *options,
|
||||
unsigned int rtp_symmetric);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Get SDP Options rtp_symmetric
|
||||
*
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns rtp_symmetric
|
||||
*/
|
||||
unsigned int ast_sdp_options_get_rtp_symmetric(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set SDP Options telephone_event
|
||||
*
|
||||
* \param options SDP Options
|
||||
* \param telephone_event
|
||||
*/
|
||||
void ast_sdp_options_set_telephone_event(struct ast_sdp_options *options,
|
||||
unsigned int telephone_event);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Get SDP Options telephone_event
|
||||
*
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns telephone_event
|
||||
*/
|
||||
unsigned int ast_sdp_options_get_telephone_event(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set SDP Options rtp_ipv6
|
||||
*
|
||||
* \param options SDP Options
|
||||
* \param rtp_ipv6
|
||||
*/
|
||||
void ast_sdp_options_set_rtp_ipv6(struct ast_sdp_options *options,
|
||||
unsigned int rtp_ipv6);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Get SDP Options rtp_ipv6
|
||||
*
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns rtp_ipv6
|
||||
*/
|
||||
unsigned int ast_sdp_options_get_rtp_ipv6(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set SDP Options g726_non_standard
|
||||
*
|
||||
* \param options SDP Options
|
||||
* \param g726_non_standard
|
||||
*/
|
||||
void ast_sdp_options_set_g726_non_standard(struct ast_sdp_options *options,
|
||||
unsigned int g726_non_standard);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Get SDP Options g726_non_standard
|
||||
*
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns g726_non_standard
|
||||
*/
|
||||
unsigned int ast_sdp_options_get_g726_non_standard(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set SDP Options locally_held
|
||||
*
|
||||
* \param options SDP Options
|
||||
* \param locally_held
|
||||
*/
|
||||
void ast_sdp_options_set_locally_held(struct ast_sdp_options *options,
|
||||
unsigned int locally_held);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Get SDP Options locally_held
|
||||
*
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns locally_held
|
||||
*/
|
||||
unsigned int ast_sdp_options_get_locally_held(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set SDP Options tos_audio
|
||||
*
|
||||
* \param options SDP Options
|
||||
* \param tos_audio
|
||||
*/
|
||||
void ast_sdp_options_set_tos_audio(struct ast_sdp_options *options,
|
||||
unsigned int tos_audio);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Get SDP Options tos_audio
|
||||
*
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns tos_audio
|
||||
*/
|
||||
unsigned int ast_sdp_options_get_tos_audio(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set SDP Options cos_audio
|
||||
*
|
||||
* \param options SDP Options
|
||||
* \param cos_audio
|
||||
*/
|
||||
void ast_sdp_options_set_cos_audio(struct ast_sdp_options *options,
|
||||
unsigned int cos_audio);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Get SDP Options cos_audio
|
||||
*
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns cos_audio
|
||||
*/
|
||||
unsigned int ast_sdp_options_get_cos_audio(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set SDP Options tos_video
|
||||
*
|
||||
* \param options SDP Options
|
||||
* \param tos_video
|
||||
*/
|
||||
void ast_sdp_options_set_tos_video(struct ast_sdp_options *options,
|
||||
unsigned int tos_video);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Get SDP Options tos_video
|
||||
*
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns tos_video
|
||||
*/
|
||||
unsigned int ast_sdp_options_get_tos_video(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set SDP Options cos_video
|
||||
*
|
||||
* \param options SDP Options
|
||||
* \param cos_video
|
||||
*/
|
||||
void ast_sdp_options_set_cos_video(struct ast_sdp_options *options,
|
||||
unsigned int cos_video);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Get SDP Options cos_video
|
||||
*
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns cos_video
|
||||
*/
|
||||
unsigned int ast_sdp_options_get_cos_video(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set SDP Options ice
|
||||
*
|
||||
* \param options SDP Options
|
||||
* \param ice
|
||||
*/
|
||||
void ast_sdp_options_set_ice(struct ast_sdp_options *options,
|
||||
enum ast_sdp_options_ice ice);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Get SDP Options ice
|
||||
*
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns ice
|
||||
*/
|
||||
enum ast_sdp_options_ice ast_sdp_options_get_ice(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set SDP Options impl
|
||||
*
|
||||
* \param options SDP Options
|
||||
* \param impl
|
||||
*/
|
||||
void ast_sdp_options_set_impl(struct ast_sdp_options *options,
|
||||
enum ast_sdp_options_impl impl);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Get SDP Options impl
|
||||
*
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns impl
|
||||
*/
|
||||
enum ast_sdp_options_impl ast_sdp_options_get_impl(struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Set SDP Options encryption
|
||||
*
|
||||
* \param options SDP Options
|
||||
* \param encryption
|
||||
*/
|
||||
void ast_sdp_options_set_encryption(struct ast_sdp_options *options,
|
||||
enum ast_sdp_options_encryption encryption);
|
||||
|
||||
/*!
|
||||
* \since 15.0.0
|
||||
* \brief Get the SDP encryption
|
||||
* \brief Get SDP Options encryption
|
||||
*
|
||||
* \param options SDP Options
|
||||
*
|
||||
* \returns encryption
|
||||
*/
|
||||
enum ast_sdp_options_encryption ast_sdp_options_get_encryption(const struct ast_sdp_options *options);
|
||||
enum ast_sdp_options_encryption ast_sdp_options_get_encryption(struct ast_sdp_options *options);
|
||||
|
||||
#endif /* _ASTERISK_SDP_OPTIONS_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 */
|
@@ -19,9 +19,10 @@
|
||||
#ifndef _ASTERISK_SDP_STATE_H
|
||||
#define _ASTERISK_SDP_STATE_H
|
||||
|
||||
#include "asterisk/stream.h"
|
||||
#include "asterisk/sdp_options.h"
|
||||
|
||||
struct ast_sdp_state;
|
||||
struct ast_sdp_options;
|
||||
struct ast_stream_topology;
|
||||
|
||||
/*!
|
||||
* \brief Allocate a new SDP state
|
||||
@@ -31,7 +32,8 @@ struct ast_stream_topology;
|
||||
* Ownership of the SDP options is taken on by the SDP state.
|
||||
* A good strategy is to call this during session creation.
|
||||
*/
|
||||
struct ast_sdp_state *ast_sdp_state_alloc(struct ast_stream_topology *streams, struct ast_sdp_options *options);
|
||||
struct ast_sdp_state *ast_sdp_state_alloc(struct ast_stream_topology *streams,
|
||||
struct ast_sdp_options *options);
|
||||
|
||||
/*!
|
||||
* \brief Free the SDP state.
|
||||
@@ -45,7 +47,8 @@ void ast_sdp_state_free(struct ast_sdp_state *sdp_state);
|
||||
*
|
||||
* Stream numbers correspond to the streams in the topology of the associated channel
|
||||
*/
|
||||
struct ast_rtp_instance *ast_sdp_state_get_rtp_instance(struct ast_sdp_state *sdp_state, int stream_index);
|
||||
struct ast_rtp_instance *ast_sdp_state_get_rtp_instance(const struct ast_sdp_state *sdp_state,
|
||||
int stream_index);
|
||||
|
||||
/*!
|
||||
* \brief Get the joint negotiated streams based on local and remote capabilities.
|
||||
@@ -53,44 +56,96 @@ struct ast_rtp_instance *ast_sdp_state_get_rtp_instance(struct ast_sdp_state *sd
|
||||
* If this is called prior to receiving a remote SDP, then this will just mirror
|
||||
* the local configured endpoint capabilities.
|
||||
*/
|
||||
struct ast_stream_topology *ast_sdp_state_get_joint_topology(struct ast_sdp_state *sdp_state);
|
||||
const struct ast_stream_topology *ast_sdp_state_get_joint_topology(
|
||||
const struct ast_sdp_state *sdp_state);
|
||||
|
||||
/*!
|
||||
* \brief Get the local topology
|
||||
*
|
||||
*/
|
||||
const struct ast_stream_topology *ast_sdp_state_get_local_topology(
|
||||
const struct ast_sdp_state *sdp_state);
|
||||
|
||||
/*!
|
||||
* \brief Get the sdp_state options
|
||||
*
|
||||
*/
|
||||
const struct ast_sdp_options *ast_sdp_state_get_options(
|
||||
const 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
|
||||
* on known streams and options If we have received a remote SDP, this will
|
||||
* be the negotiated SDP based on the joint capabilities. The return type is
|
||||
* a void pointer because the representation of the SDP is going to be determined based
|
||||
* on the SDP options when allocating the SDP state.
|
||||
* \param sdp_state
|
||||
*
|
||||
* This function will allocate RTP instances if RTP instances have not already
|
||||
* been allocated for the streams.
|
||||
* \retval non-NULL Success
|
||||
* \retval NULL Failure
|
||||
*
|
||||
* \note
|
||||
* This function will allocate a new SDP with RTP instances if it has not already
|
||||
* been allocated.
|
||||
*
|
||||
* The return here is const. The use case for this is so that a channel can add the SDP to an outgoing
|
||||
* message. The API user should not attempt to modify the SDP. SDP modification should only be done through
|
||||
* the API.
|
||||
*/
|
||||
const void *ast_sdp_state_get_local(struct ast_sdp_state *sdp_state);
|
||||
const struct ast_sdp *ast_sdp_state_get_local_sdp(struct ast_sdp_state *sdp_state);
|
||||
|
||||
/*!
|
||||
* \brief Set the remote SDP.
|
||||
* \brief Get the local SDP Implementation.
|
||||
*
|
||||
* This can be used for either a remote offer or answer.
|
||||
* This can also be used whenever an UPDATE, re-INVITE, etc. arrives.
|
||||
* The type of the "remote" parameter is dictated by whatever SDP representation
|
||||
* was set in the ast_sdp_options used during ast_sdp_state allocation
|
||||
* \param sdp_state
|
||||
*
|
||||
* This function will NOT allocate RTP instances.
|
||||
* \retval non-NULL Success
|
||||
* \retval NULL Failure
|
||||
*
|
||||
* \note
|
||||
* This function calls ast_sdp_state_get_local_sdp then translates it into
|
||||
* the defined implementation.
|
||||
*
|
||||
* The return here is const. The use case for this is so that a channel can add
|
||||
* the SDP to an outgoing message. The API user should not attempt to modify the SDP.
|
||||
* SDP modification should only be done through the API.
|
||||
*
|
||||
* \since 15
|
||||
*/
|
||||
int ast_sdp_state_set_remote(struct ast_sdp_state *sdp_state, void *remote);
|
||||
const void *ast_sdp_state_get_local_sdp_impl(struct ast_sdp_state *sdp_state);
|
||||
|
||||
/*!
|
||||
* \brief Set the remote SDP
|
||||
*
|
||||
* \param sdp_state
|
||||
* \param sdp
|
||||
*
|
||||
* \since 15
|
||||
*/
|
||||
void ast_sdp_state_set_remote_sdp(struct ast_sdp_state *sdp_state, struct ast_sdp *sdp);
|
||||
|
||||
/*!
|
||||
* \brief Set the remote SDP from an Implementation
|
||||
*
|
||||
* \param sdp_state
|
||||
* \param remote The implementation's representation of an SDP.
|
||||
*
|
||||
* \retval 0 Success
|
||||
* \retval non-0 Failure
|
||||
*
|
||||
* \since 15
|
||||
*/
|
||||
int ast_sdp_state_set_remote_sdp_from_impl(struct ast_sdp_state *sdp_state, void *remote);
|
||||
|
||||
/*!
|
||||
* \brief Reset the SDP state and stream capabilities as if the SDP state had just been allocated.
|
||||
*
|
||||
* \param sdp_state
|
||||
* \param remote The implementation's representation of an SDP.
|
||||
*
|
||||
* \retval 0 Success
|
||||
*
|
||||
* \note
|
||||
* This is most useful for when a channel driver is sending a session refresh message
|
||||
* and needs to re-advertise its initial capabilities instead of the previously-negotiated
|
||||
* joint capabilities.
|
||||
*
|
||||
* \since 15
|
||||
*/
|
||||
int ast_sdp_state_reset(struct ast_sdp_state *sdp_state);
|
||||
|
||||
|
@@ -28,7 +28,7 @@ struct sdp;
|
||||
*/
|
||||
struct ast_sdp_translator_ops {
|
||||
/*! The SDP representation on which this translator operates */
|
||||
enum ast_sdp_options_repr repr;
|
||||
enum ast_sdp_options_impl repr;
|
||||
/*! Allocate new translator private data for a translator */
|
||||
void *(*translator_new)(void);
|
||||
/*! Free translator private data */
|
||||
@@ -36,7 +36,7 @@ struct ast_sdp_translator_ops {
|
||||
/*! Convert the channel-native SDP into an internal Asterisk SDP */
|
||||
struct ast_sdp *(*to_sdp)(void *repr_sdp, void *translator_priv);
|
||||
/*! Convert an internal Asterisk SDP into a channel-native SDP */
|
||||
void *(*from_sdp)(struct ast_sdp *sdp, void *translator_priv);
|
||||
void *(*from_sdp)(const struct ast_sdp *sdp, void *translator_priv);
|
||||
};
|
||||
|
||||
/*!
|
||||
@@ -72,7 +72,7 @@ void ast_sdp_unregister_translator(struct ast_sdp_translator_ops *ops);
|
||||
* \retval NULL FAIL
|
||||
* \retval non-NULL New SDP translator
|
||||
*/
|
||||
struct ast_sdp_translator *ast_sdp_translator_new(enum ast_sdp_options_repr repr);
|
||||
struct ast_sdp_translator *ast_sdp_translator_new(enum ast_sdp_options_impl repr);
|
||||
|
||||
/*!
|
||||
* \brief Free an SDP translator
|
||||
@@ -97,6 +97,7 @@ struct ast_sdp *ast_sdp_translator_to_sdp(struct ast_sdp_translator *translator,
|
||||
* \retval NULL FAIL
|
||||
* \retval non-NULL The translated SDP
|
||||
*/
|
||||
void *ast_sdp_translator_from_sdp(struct ast_sdp_translator *translator, struct ast_sdp *ast_sdp);
|
||||
void *ast_sdp_translator_from_sdp(struct ast_sdp_translator *translator,
|
||||
const struct ast_sdp *ast_sdp);
|
||||
|
||||
#endif /* _ASTERISK_SDP_TRANSLATOR_H */
|
||||
|
@@ -43,6 +43,8 @@ struct ast_format_cap;
|
||||
*/
|
||||
struct ast_stream_topology;
|
||||
|
||||
typedef void (*ast_stream_data_free_fn)(void *);
|
||||
|
||||
/*!
|
||||
* \brief States that a stream may be in
|
||||
*/
|
||||
@@ -69,6 +71,20 @@ enum ast_stream_state {
|
||||
AST_STREAM_STATE_INACTIVE,
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Stream data slots
|
||||
*/
|
||||
enum ast_stream_data_slot {
|
||||
/*!
|
||||
* \brief Data slot for RTP instance
|
||||
*/
|
||||
AST_STREAM_DATA_RTP_INSTANCE = 0,
|
||||
/*!
|
||||
* \brief Controls the size of the data pointer array
|
||||
*/
|
||||
AST_STREAM_DATA_SLOT_MAX
|
||||
};
|
||||
|
||||
/*!
|
||||
* \brief Create a new media stream representation
|
||||
*
|
||||
@@ -103,6 +119,9 @@ void ast_stream_free(struct ast_stream *stream);
|
||||
* \retval non-NULL success
|
||||
* \retval NULL failure
|
||||
*
|
||||
* \note Opaque data pointers set with ast_stream_set_data() are not part
|
||||
* of the deep clone. The pointers are simply copied.
|
||||
*
|
||||
* \since 15
|
||||
*/
|
||||
struct ast_stream *ast_stream_clone(const struct ast_stream *stream);
|
||||
@@ -201,6 +220,34 @@ void ast_stream_set_state(struct ast_stream *stream, enum ast_stream_state state
|
||||
*/
|
||||
const char *ast_stream_state2str(enum ast_stream_state state);
|
||||
|
||||
/*!
|
||||
* \brief Get the opaque stream data
|
||||
*
|
||||
* \param stream The media stream
|
||||
* \param slot The data slot to retrieve
|
||||
*
|
||||
* \retval non-NULL success
|
||||
* \retval NULL failure
|
||||
*
|
||||
* \since 15
|
||||
*/
|
||||
void *ast_stream_get_data(struct ast_stream *stream, enum ast_stream_data_slot slot);
|
||||
|
||||
/*!
|
||||
* \brief Set the opaque stream data
|
||||
*
|
||||
* \param stream The media stream
|
||||
* \param slot The data slot to set
|
||||
* \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, enum ast_stream_data_slot slot,
|
||||
void *data, ast_stream_data_free_fn data_free_fn);
|
||||
|
||||
/*!
|
||||
* \brief Get the position of the stream in the topology
|
||||
*
|
||||
|
@@ -1493,7 +1493,8 @@ int ast_rtp_codecs_find_payload_code(struct ast_rtp_codecs *codecs, int payload)
|
||||
return res;
|
||||
}
|
||||
|
||||
const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format, struct ast_format *format, int code, enum ast_rtp_options options)
|
||||
const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format,
|
||||
const struct ast_format *format, int code, enum ast_rtp_options options)
|
||||
{
|
||||
int i;
|
||||
const char *res = "";
|
||||
@@ -1522,7 +1523,8 @@ const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format, struct ast_f
|
||||
return res;
|
||||
}
|
||||
|
||||
unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format, struct ast_format *format, int code)
|
||||
unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format,
|
||||
const struct ast_format *format, int code)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned int res = 0;
|
||||
|
765
main/sdp.c
Normal file
765
main/sdp.c
Normal file
@@ -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;
|
||||
}
|
||||
|
@@ -21,23 +21,63 @@
|
||||
#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;
|
||||
};
|
||||
#include "sdp_private.h"
|
||||
|
||||
#define DEFAULT_ICE AST_SDP_ICE_DISABLED
|
||||
#define DEFAULT_TELEPHONE_EVENT 0
|
||||
#define DEFAULT_REPR AST_SDP_REPR_STRING
|
||||
#define DEFAULT_IMPL AST_SDP_IMPL_STRING
|
||||
#define DEFAULT_ENCRYPTION AST_SDP_ENCRYPTION_DISABLED
|
||||
|
||||
#define DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(field, assert_on_null) \
|
||||
void ast_sdp_options_set_##field(struct ast_sdp_options *options, const char *value) \
|
||||
{ \
|
||||
ast_assert(options != NULL); \
|
||||
if ((assert_on_null)) ast_assert(!ast_strlen_zero(value)); \
|
||||
if (!strcmp(value, options->field)) return; \
|
||||
ast_string_field_set(options, field, value); \
|
||||
} \
|
||||
const char *ast_sdp_options_get_##field(struct ast_sdp_options *options) \
|
||||
{ \
|
||||
ast_assert(options != NULL); \
|
||||
return options->field; \
|
||||
} \
|
||||
|
||||
#define DEFINE_GETTERS_SETTERS_FOR(type, field) \
|
||||
void ast_sdp_options_set_##field(struct ast_sdp_options *options, type value) \
|
||||
{ \
|
||||
ast_assert(options != NULL); \
|
||||
options->field = value; \
|
||||
} \
|
||||
type ast_sdp_options_get_##field(struct ast_sdp_options *options) \
|
||||
{ \
|
||||
ast_assert(options != NULL); \
|
||||
return options->field; \
|
||||
} \
|
||||
|
||||
DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(media_address, 0);
|
||||
DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(sdpowner, 0);
|
||||
DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(sdpsession, 0);
|
||||
DEFINE_STRINGFIELD_GETTERS_SETTERS_FOR(rtp_engine, 0);
|
||||
|
||||
DEFINE_GETTERS_SETTERS_FOR(unsigned int, bind_rtp_to_media_address);
|
||||
DEFINE_GETTERS_SETTERS_FOR(unsigned int, rtp_symmetric);
|
||||
DEFINE_GETTERS_SETTERS_FOR(unsigned int, telephone_event);
|
||||
DEFINE_GETTERS_SETTERS_FOR(unsigned int, rtp_ipv6);
|
||||
DEFINE_GETTERS_SETTERS_FOR(unsigned int, g726_non_standard);
|
||||
DEFINE_GETTERS_SETTERS_FOR(unsigned int, locally_held);
|
||||
DEFINE_GETTERS_SETTERS_FOR(unsigned int, tos_audio);
|
||||
DEFINE_GETTERS_SETTERS_FOR(unsigned int, cos_audio);
|
||||
DEFINE_GETTERS_SETTERS_FOR(unsigned int, tos_video);
|
||||
DEFINE_GETTERS_SETTERS_FOR(unsigned int, cos_video);
|
||||
DEFINE_GETTERS_SETTERS_FOR(enum ast_sdp_options_ice, ice);
|
||||
DEFINE_GETTERS_SETTERS_FOR(enum ast_sdp_options_impl, impl);
|
||||
DEFINE_GETTERS_SETTERS_FOR(enum ast_sdp_options_encryption, encryption);
|
||||
|
||||
static void set_defaults(struct ast_sdp_options *options)
|
||||
{
|
||||
options->ice = DEFAULT_ICE;
|
||||
options->telephone_event = DEFAULT_TELEPHONE_EVENT;
|
||||
options->repr = DEFAULT_REPR;
|
||||
options->impl = DEFAULT_IMPL;
|
||||
options->encryption = DEFAULT_ENCRYPTION;
|
||||
}
|
||||
|
||||
@@ -49,72 +89,18 @@ struct ast_sdp_options *ast_sdp_options_alloc(void)
|
||||
if (!options) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (ast_string_field_init(options, 256)) {
|
||||
ast_free(options);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
set_defaults(options);
|
||||
return options;
|
||||
}
|
||||
|
||||
void ast_sdp_options_free(struct ast_sdp_options *options)
|
||||
{
|
||||
ast_string_field_free_memory(options);
|
||||
ast_free(options);
|
||||
}
|
||||
|
||||
int ast_sdp_options_set_ice(struct ast_sdp_options *options, enum ast_sdp_options_ice ice_setting)
|
||||
{
|
||||
ast_assert(options != NULL);
|
||||
|
||||
options->ice = ice_setting;
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum ast_sdp_options_ice ast_sdp_options_get_ice(const struct ast_sdp_options *options)
|
||||
{
|
||||
ast_assert(options != NULL);
|
||||
|
||||
return options->ice;
|
||||
}
|
||||
|
||||
int ast_sdp_options_set_telephone_event(struct ast_sdp_options *options, int telephone_event_enabled)
|
||||
{
|
||||
ast_assert(options != NULL);
|
||||
|
||||
options->telephone_event = telephone_event_enabled;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ast_sdp_options_get_telephone_event(const struct ast_sdp_options *options)
|
||||
{
|
||||
ast_assert(options != NULL);
|
||||
|
||||
return options->telephone_event;
|
||||
}
|
||||
|
||||
int ast_sdp_options_set_repr(struct ast_sdp_options *options, enum ast_sdp_options_repr repr)
|
||||
{
|
||||
ast_assert(options != NULL);
|
||||
|
||||
options->repr = repr;
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum ast_sdp_options_repr ast_sdp_options_get_repr(const struct ast_sdp_options *options)
|
||||
{
|
||||
ast_assert(options != NULL);
|
||||
|
||||
return options->repr;
|
||||
}
|
||||
|
||||
int ast_sdp_options_set_encryption(struct ast_sdp_options *options,
|
||||
enum ast_sdp_options_encryption encryption)
|
||||
{
|
||||
ast_assert(options != NULL);
|
||||
|
||||
options->encryption = encryption;
|
||||
return 0;
|
||||
}
|
||||
|
||||
enum ast_sdp_options_encryption ast_sdp_options_get_encryption(const struct ast_sdp_options *options)
|
||||
{
|
||||
ast_assert(options != NULL);
|
||||
|
||||
return options->encryption;
|
||||
}
|
||||
|
55
main/sdp_private.h
Normal file
55
main/sdp_private.h
Normal file
@@ -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 */
|
111
main/sdp_repr.c
111
main/sdp_repr.c
@@ -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);
|
||||
}
|
||||
|
107
main/sdp_state.c
107
main/sdp_state.c
@@ -20,9 +20,10 @@
|
||||
#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 "../include/asterisk/sdp.h"
|
||||
#include "asterisk/stream.h"
|
||||
|
||||
enum ast_sdp_state_machine {
|
||||
@@ -77,13 +78,12 @@ struct ast_sdp_state {
|
||||
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;
|
||||
};
|
||||
|
||||
struct ast_sdp_state *ast_sdp_state_alloc(struct ast_stream_topology *streams, struct ast_sdp_options *options)
|
||||
struct ast_sdp_state *ast_sdp_state_alloc(struct ast_stream_topology *streams,
|
||||
struct ast_sdp_options *options)
|
||||
{
|
||||
struct ast_sdp_state *sdp_state;
|
||||
|
||||
@@ -94,7 +94,7 @@ struct ast_sdp_state *ast_sdp_state_alloc(struct ast_stream_topology *streams, s
|
||||
|
||||
sdp_state->options = options;
|
||||
|
||||
sdp_state->translator = ast_sdp_translator_new(ast_sdp_options_get_repr(sdp_state->options));
|
||||
sdp_state->translator = ast_sdp_translator_new(ast_sdp_options_get_impl(sdp_state->options));
|
||||
if (!sdp_state->translator) {
|
||||
ast_sdp_state_free(sdp_state);
|
||||
return NULL;
|
||||
@@ -126,18 +126,23 @@ void ast_sdp_state_free(struct ast_sdp_state *sdp_state)
|
||||
ast_sdp_translator_free(sdp_state->translator);
|
||||
}
|
||||
|
||||
struct ast_rtp_instance *ast_sdp_state_get_rtp_instance(struct ast_sdp_state *sdp_state, int stream_index)
|
||||
struct ast_rtp_instance *ast_sdp_state_get_rtp_instance(
|
||||
const 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, AST_STREAM_DATA_RTP_INSTANCE);
|
||||
}
|
||||
|
||||
struct ast_stream_topology *ast_sdp_state_get_joint_topology(struct ast_sdp_state *sdp_state)
|
||||
const struct ast_stream_topology *ast_sdp_state_get_joint_topology(
|
||||
const struct ast_sdp_state *sdp_state)
|
||||
{
|
||||
ast_assert(sdp_state != NULL);
|
||||
if (sdp_state->state == SDP_STATE_NEGOTIATED) {
|
||||
@@ -147,6 +152,23 @@ struct ast_stream_topology *ast_sdp_state_get_joint_topology(struct ast_sdp_stat
|
||||
}
|
||||
}
|
||||
|
||||
const struct ast_stream_topology *ast_sdp_state_get_local_topology(
|
||||
const struct ast_sdp_state *sdp_state)
|
||||
{
|
||||
ast_assert(sdp_state != NULL);
|
||||
|
||||
return sdp_state->local_capabilities;
|
||||
}
|
||||
|
||||
const struct ast_sdp_options *ast_sdp_state_get_options(
|
||||
const struct ast_sdp_state *sdp_state)
|
||||
{
|
||||
ast_assert(sdp_state != NULL);
|
||||
|
||||
return sdp_state->options;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int merge_sdps(struct ast_sdp_state *sdp_state)
|
||||
{
|
||||
ast_assert(sdp_state->local_sdp != NULL);
|
||||
@@ -169,37 +191,38 @@ static int merge_sdps(struct ast_sdp_state *sdp_state)
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
const void *ast_sdp_state_get_local(struct ast_sdp_state *sdp_state)
|
||||
const struct ast_sdp *ast_sdp_state_get_local_sdp(struct ast_sdp_state *sdp_state)
|
||||
{
|
||||
struct ast_sdp *sdp;
|
||||
|
||||
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) */
|
||||
if (!sdp_state->local_sdp) {
|
||||
sdp_state->local_sdp = ast_sdp_create_from_state(sdp_state);
|
||||
}
|
||||
|
||||
switch (sdp_state->state) {
|
||||
case SDP_STATE_INITIAL:
|
||||
sdp_state->state = SDP_STATE_OFFERER;
|
||||
/* Fall through */
|
||||
case SDP_STATE_OFFERER:
|
||||
default:
|
||||
sdp = sdp_state->local_sdp;
|
||||
break;
|
||||
case SDP_STATE_ANSWERER:
|
||||
sdp_state->state = SDP_STATE_NEGOTIATED;
|
||||
merge_sdps(sdp_state);
|
||||
/* Fall through */
|
||||
case SDP_STATE_NEGOTIATED:
|
||||
sdp = sdp_state->joint_sdp;
|
||||
break;
|
||||
return sdp_state->local_sdp;
|
||||
}
|
||||
|
||||
const void *ast_sdp_state_get_local_sdp_impl(struct ast_sdp_state *sdp_state)
|
||||
{
|
||||
const struct ast_sdp *sdp = ast_sdp_state_get_local_sdp(sdp_state);
|
||||
|
||||
if (!sdp) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return ast_sdp_translator_from_sdp(sdp_state->translator, sdp);
|
||||
}
|
||||
|
||||
int ast_sdp_state_set_remote(struct ast_sdp_state *sdp_state, void *remote)
|
||||
void ast_sdp_state_set_remote_sdp(struct ast_sdp_state *sdp_state, struct ast_sdp *sdp)
|
||||
{
|
||||
ast_assert(sdp_state != NULL);
|
||||
|
||||
sdp_state->remote_sdp = sdp;
|
||||
}
|
||||
|
||||
int ast_sdp_state_set_remote_sdp_from_impl(struct ast_sdp_state *sdp_state, void *remote)
|
||||
{
|
||||
struct ast_sdp *sdp;
|
||||
|
||||
@@ -210,29 +233,7 @@ int ast_sdp_state_set_remote(struct ast_sdp_state *sdp_state, void *remote)
|
||||
return -1;
|
||||
}
|
||||
|
||||
sdp_state->remote_sdp = remote;
|
||||
/* TODO Convert the remote SDP into a topology and store that in
|
||||
* sdp_state->remote_capabilities
|
||||
*/
|
||||
|
||||
switch (sdp_state->state) {
|
||||
case SDP_STATE_ANSWERER:
|
||||
default:
|
||||
break;
|
||||
case SDP_STATE_INITIAL:
|
||||
sdp_state->state = SDP_STATE_ANSWERER;
|
||||
break;
|
||||
case SDP_STATE_OFFERER:
|
||||
sdp_state->state = SDP_STATE_NEGOTIATED;
|
||||
/* Fall through */
|
||||
case SDP_STATE_NEGOTIATED:
|
||||
/* If state is already negotiated, and we receive a new
|
||||
* remote SDP, we need to re-create the joint SDP and joint
|
||||
* capabilities
|
||||
*/
|
||||
merge_sdps(sdp_state);
|
||||
break;
|
||||
}
|
||||
sdp_state->remote_sdp = sdp;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -24,13 +24,13 @@
|
||||
#include "asterisk/lock.h"
|
||||
|
||||
AST_RWLOCK_DEFINE_STATIC(registered_ops_lock);
|
||||
static struct ast_sdp_translator_ops *registered_ops[AST_SDP_REPR_END];
|
||||
static struct ast_sdp_translator_ops *registered_ops[AST_SDP_IMPL_END];
|
||||
|
||||
int ast_sdp_register_translator(struct ast_sdp_translator_ops *ops)
|
||||
{
|
||||
SCOPED_WRLOCK(lock, ®istered_ops_lock);
|
||||
|
||||
if (ops->repr >= AST_SDP_REPR_END) {
|
||||
if (ops->repr >= AST_SDP_IMPL_END) {
|
||||
ast_log(LOG_ERROR, "SDP translator has unrecognized representation\n");
|
||||
return -1;
|
||||
}
|
||||
@@ -49,14 +49,14 @@ void ast_sdp_unregister_translator(struct ast_sdp_translator_ops *ops)
|
||||
{
|
||||
SCOPED_WRLOCK(lock, ®istered_ops_lock);
|
||||
|
||||
if (ops->repr >= AST_SDP_REPR_END) {
|
||||
if (ops->repr >= AST_SDP_IMPL_END) {
|
||||
return;
|
||||
}
|
||||
|
||||
registered_ops[ops->repr] = NULL;
|
||||
}
|
||||
|
||||
struct ast_sdp_translator *ast_sdp_translator_new(enum ast_sdp_options_repr repr)
|
||||
struct ast_sdp_translator *ast_sdp_translator_new(enum ast_sdp_options_impl repr)
|
||||
{
|
||||
struct ast_sdp_translator *translator;
|
||||
SCOPED_RDLOCK(lock, ®istered_ops_lock);
|
||||
@@ -88,12 +88,14 @@ void ast_sdp_translator_free(struct ast_sdp_translator *translator)
|
||||
ast_free(translator);
|
||||
}
|
||||
|
||||
struct ast_sdp *ast_sdp_translator_to_sdp(struct ast_sdp_translator *translator, void *native_sdp)
|
||||
struct ast_sdp *ast_sdp_translator_to_sdp(struct ast_sdp_translator *translator,
|
||||
void *native_sdp)
|
||||
{
|
||||
return translator->ops->to_sdp(native_sdp, translator->translator_priv);
|
||||
}
|
||||
|
||||
void *ast_sdp_translator_from_sdp(struct ast_sdp_translator *translator, struct ast_sdp *ast_sdp)
|
||||
void *ast_sdp_translator_from_sdp(struct ast_sdp_translator *translator,
|
||||
const struct ast_sdp *ast_sdp)
|
||||
{
|
||||
return translator->ops->from_sdp(ast_sdp, translator->translator_priv);
|
||||
}
|
||||
|
@@ -56,6 +56,16 @@ struct ast_stream {
|
||||
*/
|
||||
enum ast_stream_state state;
|
||||
|
||||
/*!
|
||||
* \brief Opaque stream data
|
||||
*/
|
||||
void *data[AST_STREAM_DATA_SLOT_MAX];
|
||||
|
||||
/*!
|
||||
* \brief What to do with data when the stream is freed
|
||||
*/
|
||||
ast_stream_data_free_fn data_free_fn[AST_STREAM_DATA_SLOT_MAX];
|
||||
|
||||
/*!
|
||||
* \brief Name for the stream within the context of the channel it is on
|
||||
*/
|
||||
@@ -110,10 +120,18 @@ struct ast_stream *ast_stream_clone(const struct ast_stream *stream)
|
||||
|
||||
void ast_stream_free(struct ast_stream *stream)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!stream) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < AST_STREAM_DATA_SLOT_MAX; i++) {
|
||||
if (stream->data_free_fn[i]) {
|
||||
stream->data_free_fn[i](stream->data[i]);
|
||||
}
|
||||
}
|
||||
|
||||
ao2_cleanup(stream->formats);
|
||||
ast_free(stream);
|
||||
}
|
||||
@@ -186,6 +204,24 @@ const char *ast_stream_state2str(enum ast_stream_state state)
|
||||
}
|
||||
}
|
||||
|
||||
void *ast_stream_get_data(struct ast_stream *stream, enum ast_stream_data_slot slot)
|
||||
{
|
||||
ast_assert(stream != NULL);
|
||||
|
||||
return stream->data[slot];
|
||||
}
|
||||
|
||||
void *ast_stream_set_data(struct ast_stream *stream, enum ast_stream_data_slot slot,
|
||||
void *data, ast_stream_data_free_fn data_free_fn)
|
||||
{
|
||||
ast_assert(stream != NULL);
|
||||
|
||||
stream->data[slot] = data;
|
||||
stream->data_free_fn[slot] = data_free_fn;
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
int ast_stream_get_position(const struct ast_stream *stream)
|
||||
{
|
||||
ast_assert(stream != NULL);
|
||||
|
@@ -19,13 +19,14 @@
|
||||
#include "asterisk.h"
|
||||
#include "asterisk/sdp_translator.h"
|
||||
#include "asterisk/sdp_options.h"
|
||||
#include "asterisk/sdp_priv.h"
|
||||
#include "asterisk/vector.h"
|
||||
#include "asterisk/netsock2.h"
|
||||
#include "asterisk/utils.h"
|
||||
#include "asterisk/config.h"
|
||||
#include "asterisk/test.h"
|
||||
#include "asterisk/module.h"
|
||||
|
||||
#include "../include/asterisk/sdp.h"
|
||||
#ifdef HAVE_PJPROJECT
|
||||
#include <pjlib.h>
|
||||
#include <pjmedia.h>
|
||||
@@ -55,93 +56,56 @@ static void pjmedia_free(void *translator_priv)
|
||||
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;
|
||||
|
||||
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);
|
||||
|
||||
AST_VECTOR_INIT(&new_m_line->payloads, pjmedia_m_line->desc.fmt_count);
|
||||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
static void pjmedia_copy_m_lines(struct ast_sdp *new_sdp, struct pjmedia_sdp_session *pjmedia_sdp)
|
||||
static void pjmedia_copy_m_lines(struct ast_sdp *new_sdp,
|
||||
struct pjmedia_sdp_session *pjmedia_sdp)
|
||||
{
|
||||
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,128 +113,149 @@ static struct ast_sdp *pjmedia_to_sdp(void *in, void *translator_priv)
|
||||
{
|
||||
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)
|
||||
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)
|
||||
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,
|
||||
const 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);
|
||||
}
|
||||
}
|
||||
|
||||
static void copy_m_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_media *media, struct ast_sdp_m_line *m_line)
|
||||
static void copy_m_line_pjmedia(pj_pool_t *pool, pjmedia_sdp_media *media,
|
||||
struct ast_sdp_m_line *m_line)
|
||||
{
|
||||
int i;
|
||||
|
||||
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)
|
||||
static void copy_m_lines_pjmedia(pj_pool_t *pool, pjmedia_sdp_session *pjmedia_sdp,
|
||||
const 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;
|
||||
}
|
||||
}
|
||||
|
||||
static void *sdp_to_pjmedia(struct ast_sdp *sdp, void *translator_priv)
|
||||
static void *sdp_to_pjmedia(const struct ast_sdp *sdp, void *translator_priv)
|
||||
{
|
||||
pj_pool_t *pool = translator_priv;
|
||||
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;
|
||||
}
|
||||
|
||||
static struct ast_sdp_translator_ops pjmedia_translator = {
|
||||
.repr = AST_SDP_REPR_PJMEDIA,
|
||||
.repr = AST_SDP_IMPL_PJMEDIA,
|
||||
.translator_new = pjmedia_new,
|
||||
.translator_free = pjmedia_free,
|
||||
.to_sdp = pjmedia_to_sdp,
|
||||
@@ -279,37 +264,38 @@ static struct ast_sdp_translator_ops pjmedia_translator = {
|
||||
|
||||
#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, ...)
|
||||
static int verify_m_line(struct ast_sdp *sdp, int index, char *type, int port,
|
||||
int port_count, char *profile, ...)
|
||||
{
|
||||
struct ast_sdp_m_line *m_line;
|
||||
int res;
|
||||
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,19 +303,20 @@ static int verify_m_line(struct ast_sdp *sdp, int index, char *type, int port, i
|
||||
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;
|
||||
}
|
||||
|
||||
static int verify_a_line(struct ast_sdp *sdp, int m_index, int a_index, char *name, char *value)
|
||||
static int verify_a_line(struct ast_sdp *sdp, int m_index, int a_index, char *name,
|
||||
char *value)
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -340,10 +327,10 @@ AST_TEST_DEFINE(pjmedia_to_sdp_test)
|
||||
pj_pool_t *pool;
|
||||
char *sdp_str =
|
||||
"v=0\r\n"
|
||||
"o=alice 2890844526 2890844526 IN IP4 host.atlanta.example.com\r\n"
|
||||
"o=alice 2890844526 2890844527 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"
|
||||
@@ -371,7 +358,7 @@ AST_TEST_DEFINE(pjmedia_to_sdp_test)
|
||||
|
||||
pool = pj_pool_create(&sdp_caching_pool.factory, "pjmedia to sdp test", 1024, 1024, NULL);
|
||||
|
||||
translator = ast_sdp_translator_new(AST_SDP_REPR_PJMEDIA);
|
||||
translator = ast_sdp_translator_new(AST_SDP_IMPL_PJMEDIA);
|
||||
if (!translator) {
|
||||
ast_test_status_update(test, "Failed to create SDP translator\n");
|
||||
res = AST_TEST_FAIL;
|
||||
@@ -387,24 +374,24 @@ AST_TEST_DEFINE(pjmedia_to_sdp_test)
|
||||
|
||||
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 != 2890844526UL) {
|
||||
ast_test_status_update(test, "Unexpected SDP id '%" PRId64 "lu'\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 != 2890844527UL) {
|
||||
ast_test_status_update(test, "Unexpected SDP version '%" PRId64 "'\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 +400,11 @@ AST_TEST_DEFINE(pjmedia_to_sdp_test)
|
||||
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 +459,7 @@ AST_TEST_DEFINE(sdp_to_pjmedia_test)
|
||||
"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 +474,8 @@ AST_TEST_DEFINE(sdp_to_pjmedia_test)
|
||||
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:
|
||||
@@ -502,7 +491,7 @@ AST_TEST_DEFINE(sdp_to_pjmedia_test)
|
||||
|
||||
pool = pj_pool_create(&sdp_caching_pool.factory, "pjmedia to sdp test", 1024, 1024, NULL);
|
||||
|
||||
translator = ast_sdp_translator_new(AST_SDP_REPR_PJMEDIA);
|
||||
translator = ast_sdp_translator_new(AST_SDP_IMPL_PJMEDIA);
|
||||
if (!translator) {
|
||||
ast_test_status_update(test, "Failed to create SDP translator\n");
|
||||
res = AST_TEST_FAIL;
|
||||
@@ -520,15 +509,13 @@ AST_TEST_DEFINE(sdp_to_pjmedia_test)
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user