Wed Jan 8 2020 09:50:19

Asterisk developer's documentation


rtp_engine.h File Reference

Pluggable RTP Architecture. More...

#include "asterisk/astobj2.h"
#include "asterisk/frame.h"
#include "asterisk/netsock2.h"
#include "asterisk/sched.h"
#include "asterisk/res_srtp.h"

Go to the source code of this file.

Data Structures

struct  ast_rtp_codecs
 
struct  ast_rtp_engine
 
struct  ast_rtp_glue
 
struct  ast_rtp_instance_stats
 
struct  ast_rtp_payload_type
 

Macros

#define AST_RED_MAX_GENERATION   5
 
#define AST_RTP_CISCO_DTMF   (1 << 2)
 
#define AST_RTP_CN   (1 << 1)
 
#define AST_RTP_DTMF   (1 << 0)
 
#define ast_rtp_engine_register(engine)   ast_rtp_engine_register2(engine, ast_module_info->self)
 
#define ast_rtp_glue_register(glue)   ast_rtp_glue_register2(glue, ast_module_info->self)
 
#define AST_RTP_MAX   AST_RTP_CISCO_DTMF
 
#define AST_RTP_MAX_PT   256
 
#define AST_RTP_STAT_SET(current_stat, combined, placement, value)
 
#define AST_RTP_STAT_TERMINATOR(combined)
 

Enumerations

enum  ast_rtp_dtmf_mode { AST_RTP_DTMF_MODE_NONE = 0, AST_RTP_DTMF_MODE_RFC2833, AST_RTP_DTMF_MODE_INBAND }
 
enum  ast_rtp_glue_result { AST_RTP_GLUE_RESULT_FORBID = 0, AST_RTP_GLUE_RESULT_REMOTE, AST_RTP_GLUE_RESULT_LOCAL }
 
enum  ast_rtp_instance_stat {
  AST_RTP_INSTANCE_STAT_ALL = 0, AST_RTP_INSTANCE_STAT_TXCOUNT, AST_RTP_INSTANCE_STAT_RXCOUNT, AST_RTP_INSTANCE_STAT_COMBINED_LOSS,
  AST_RTP_INSTANCE_STAT_TXPLOSS, AST_RTP_INSTANCE_STAT_RXPLOSS, AST_RTP_INSTANCE_STAT_REMOTE_MAXRXPLOSS, AST_RTP_INSTANCE_STAT_REMOTE_MINRXPLOSS,
  AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVRXPLOSS, AST_RTP_INSTANCE_STAT_REMOTE_STDEVRXPLOSS, AST_RTP_INSTANCE_STAT_LOCAL_MAXRXPLOSS, AST_RTP_INSTANCE_STAT_LOCAL_MINRXPLOSS,
  AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVRXPLOSS, AST_RTP_INSTANCE_STAT_LOCAL_STDEVRXPLOSS, AST_RTP_INSTANCE_STAT_COMBINED_JITTER, AST_RTP_INSTANCE_STAT_TXJITTER,
  AST_RTP_INSTANCE_STAT_RXJITTER, AST_RTP_INSTANCE_STAT_REMOTE_MAXJITTER, AST_RTP_INSTANCE_STAT_REMOTE_MINJITTER, AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVJITTER,
  AST_RTP_INSTANCE_STAT_REMOTE_STDEVJITTER, AST_RTP_INSTANCE_STAT_LOCAL_MAXJITTER, AST_RTP_INSTANCE_STAT_LOCAL_MINJITTER, AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVJITTER,
  AST_RTP_INSTANCE_STAT_LOCAL_STDEVJITTER, AST_RTP_INSTANCE_STAT_COMBINED_RTT, AST_RTP_INSTANCE_STAT_RTT, AST_RTP_INSTANCE_STAT_MAX_RTT,
  AST_RTP_INSTANCE_STAT_MIN_RTT, AST_RTP_INSTANCE_STAT_NORMDEVRTT, AST_RTP_INSTANCE_STAT_STDEVRTT, AST_RTP_INSTANCE_STAT_LOCAL_SSRC,
  AST_RTP_INSTANCE_STAT_REMOTE_SSRC
}
 
enum  ast_rtp_instance_stat_field { AST_RTP_INSTANCE_STAT_FIELD_QUALITY = 0, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT }
 
enum  ast_rtp_options { AST_RTP_OPT_G726_NONSTANDARD = (1 << 0) }
 
enum  ast_rtp_property {
  AST_RTP_PROPERTY_NAT = 0, AST_RTP_PROPERTY_DTMF, AST_RTP_PROPERTY_DTMF_COMPENSATE, AST_RTP_PROPERTY_STUN,
  AST_RTP_PROPERTY_RTCP, AST_RTP_PROPERTY_MAX
}
 

Functions

void ast_rtp_codecs_packetization_set (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, struct ast_codec_pref *prefs)
 Set codec packetization preferences. More...
 
int ast_rtp_codecs_payload_code (struct ast_rtp_codecs *codecs, const int asterisk_format, const format_t code)
 Retrieve a payload based on whether it is an Asterisk format and the code. More...
 
void ast_rtp_codecs_payload_formats (struct ast_rtp_codecs *codecs, format_t *astformats, int *nonastformats)
 Retrieve all formats that were found. More...
 
struct ast_rtp_payload_type ast_rtp_codecs_payload_lookup (struct ast_rtp_codecs *codecs, int payload)
 Retrieve payload information by payload. More...
 
void ast_rtp_codecs_payloads_clear (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance)
 Clear payload information from an RTP instance. More...
 
void ast_rtp_codecs_payloads_copy (struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
 Copy payload information from one RTP instance to another. More...
 
void ast_rtp_codecs_payloads_default (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance)
 Set payload information on an RTP instance to the default. More...
 
void ast_rtp_codecs_payloads_set_m_type (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
 Record payload information that was seen in an m= SDP line. More...
 
int ast_rtp_codecs_payloads_set_rtpmap_type (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload, char *mimetype, char *mimesubtype, enum ast_rtp_options options)
 Record payload information that was seen in an a=rtpmap: SDP line. More...
 
int ast_rtp_codecs_payloads_set_rtpmap_type_rate (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int pt, char *mimetype, char *mimesubtype, enum ast_rtp_options options, unsigned int sample_rate)
 Set payload type to a known MIME media type for a codec with a specific sample rate. More...
 
void ast_rtp_codecs_payloads_unset (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
 Remove payload information. More...
 
int ast_rtp_engine_register2 (struct ast_rtp_engine *engine, struct ast_module *module)
 Register an RTP engine. More...
 
int ast_rtp_engine_register_srtp (struct ast_srtp_res *srtp_res, struct ast_srtp_policy_res *policy_res)
 
int ast_rtp_engine_srtp_is_registered (void)
 
int ast_rtp_engine_unregister (struct ast_rtp_engine *engine)
 Unregister an RTP engine. More...
 
void ast_rtp_engine_unregister_srtp (void)
 
int ast_rtp_glue_register2 (struct ast_rtp_glue *glue, struct ast_module *module)
 Register RTP glue. More...
 
int ast_rtp_glue_unregister (struct ast_rtp_glue *glue)
 Unregister RTP glue. More...
 
int ast_rtp_instance_activate (struct ast_rtp_instance *instance)
 Indicate to the RTP engine that packets are now expected to be sent/received on the RTP instance. More...
 
int ast_rtp_instance_add_srtp_policy (struct ast_rtp_instance *instance, struct ast_srtp_policy *remote_policy, struct ast_srtp_policy *local_policy)
 Add or replace the SRTP policies for the given RTP instance. More...
 
format_t ast_rtp_instance_available_formats (struct ast_rtp_instance *instance, format_t to_endpoint, format_t to_asterisk)
 Request the formats that can be transcoded. More...
 
enum ast_bridge_result ast_rtp_instance_bridge (struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms)
 Bridge two channels that use RTP instances. More...
 
void ast_rtp_instance_change_source (struct ast_rtp_instance *instance)
 Indicate a new source of audio has dropped in and the ssrc should change. More...
 
int ast_rtp_instance_destroy (struct ast_rtp_instance *instance)
 Destroy an RTP instance. More...
 
int ast_rtp_instance_dtmf_begin (struct ast_rtp_instance *instance, char digit)
 Begin sending a DTMF digit. More...
 
int ast_rtp_instance_dtmf_end (struct ast_rtp_instance *instance, char digit)
 Stop sending a DTMF digit. More...
 
int ast_rtp_instance_dtmf_end_with_duration (struct ast_rtp_instance *instance, char digit, unsigned int duration)
 
enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get (struct ast_rtp_instance *instance)
 Get the DTMF mode of an RTP instance. More...
 
int ast_rtp_instance_dtmf_mode_set (struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode)
 Set the DTMF mode that should be used. More...
 
int ast_rtp_instance_early_bridge (struct ast_channel *c0, struct ast_channel *c1)
 Early bridge two channels that use RTP instances. More...
 
void ast_rtp_instance_early_bridge_make_compatible (struct ast_channel *c_dst, struct ast_channel *c_src)
 Make two channels compatible for early bridging. More...
 
int ast_rtp_instance_fd (struct ast_rtp_instance *instance, int rtcp)
 Get the file descriptor for an RTP session (or RTCP) More...
 
struct ast_rtp_glueast_rtp_instance_get_active_glue (struct ast_rtp_instance *instance)
 Get the RTP glue in use on an RTP instance. More...
 
int ast_rtp_instance_get_and_cmp_local_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the address of the local endpoint that we are sending RTP to, comparing its address to another. More...
 
int ast_rtp_instance_get_and_cmp_remote_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the address of the remote endpoint that we are sending RTP to, comparing its address to another. More...
 
struct ast_rtp_instanceast_rtp_instance_get_bridged (struct ast_rtp_instance *instance)
 Get the other RTP instance that an instance is bridged to. More...
 
struct ast_channelast_rtp_instance_get_chan (struct ast_rtp_instance *instance)
 Get the channel that is associated with an RTP instance while in a bridge. More...
 
struct ast_rtp_codecsast_rtp_instance_get_codecs (struct ast_rtp_instance *instance)
 Get the codecs structure of an RTP instance. More...
 
void * ast_rtp_instance_get_data (struct ast_rtp_instance *instance)
 Get the data portion of an RTP instance. More...
 
struct ast_rtp_engineast_rtp_instance_get_engine (struct ast_rtp_instance *instance)
 Get the RTP engine in use on an RTP instance. More...
 
void * ast_rtp_instance_get_extended_prop (struct ast_rtp_instance *instance, int property)
 Get the value of an RTP instance extended property. More...
 
struct ast_rtp_glueast_rtp_instance_get_glue (const char *type)
 Get the RTP glue that binds a channel to the RTP engine. More...
 
int ast_rtp_instance_get_hold_timeout (struct ast_rtp_instance *instance)
 Get the RTP timeout value for when an RTP instance is on hold. More...
 
int ast_rtp_instance_get_keepalive (struct ast_rtp_instance *instance)
 Get the RTP keepalive interval. More...
 
void ast_rtp_instance_get_local_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the local address that we are expecting RTP on. More...
 
int ast_rtp_instance_get_prop (struct ast_rtp_instance *instance, enum ast_rtp_property property)
 Get the value of an RTP instance property. More...
 
char * ast_rtp_instance_get_quality (struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size)
 Retrieve quality statistics about an RTP instance. More...
 
void ast_rtp_instance_get_remote_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the address of the remote endpoint that we are sending RTP to. More...
 
struct ast_srtpast_rtp_instance_get_srtp (struct ast_rtp_instance *instance)
 Obtain the SRTP instance associated with an RTP instance. More...
 
int ast_rtp_instance_get_stats (struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
 Retrieve statistics about an RTP instance. More...
 
int ast_rtp_instance_get_timeout (struct ast_rtp_instance *instance)
 Get the RTP timeout value. More...
 
int ast_rtp_instance_make_compatible (struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_channel *peer)
 Request that the underlying RTP engine make two RTP instances compatible with eachother. More...
 
struct ast_rtp_instanceast_rtp_instance_new (const char *engine_name, struct sched_context *sched, const struct ast_sockaddr *sa, void *data)
 Create a new RTP instance. More...
 
struct ast_frameast_rtp_instance_read (struct ast_rtp_instance *instance, int rtcp)
 Receive a frame over RTP. More...
 
int ast_rtp_instance_sendcng (struct ast_rtp_instance *instance, int level)
 Send a comfort noise packet to the RTP instance. More...
 
int ast_rtp_instance_set_alt_remote_address (struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
 Set the address of an an alternate RTP address to receive from. More...
 
void ast_rtp_instance_set_data (struct ast_rtp_instance *instance, void *data)
 Set the data portion of an RTP instance. More...
 
void ast_rtp_instance_set_extended_prop (struct ast_rtp_instance *instance, int property, void *value)
 Set the value of an RTP instance extended property. More...
 
void ast_rtp_instance_set_hold_timeout (struct ast_rtp_instance *instance, int timeout)
 Set the RTP timeout value for when the instance is on hold. More...
 
void ast_rtp_instance_set_keepalive (struct ast_rtp_instance *instance, int timeout)
 Set the RTP keepalive interval. More...
 
int ast_rtp_instance_set_local_address (struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
 Set the address that we are expecting to receive RTP on. More...
 
void ast_rtp_instance_set_prop (struct ast_rtp_instance *instance, enum ast_rtp_property property, int value)
 Set the value of an RTP instance property. More...
 
int ast_rtp_instance_set_qos (struct ast_rtp_instance *instance, int tos, int cos, const char *desc)
 Set QoS parameters on an RTP session. More...
 
int ast_rtp_instance_set_read_format (struct ast_rtp_instance *instance, format_t format)
 Request that the underlying RTP engine provide audio frames in a specific format. More...
 
int ast_rtp_instance_set_remote_address (struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
 Set the address of the remote endpoint that we are sending RTP to. More...
 
void ast_rtp_instance_set_stats_vars (struct ast_channel *chan, struct ast_rtp_instance *instance)
 Set standard statistics from an RTP instance on a channel. More...
 
void ast_rtp_instance_set_timeout (struct ast_rtp_instance *instance, int timeout)
 Set the RTP timeout value. More...
 
int ast_rtp_instance_set_write_format (struct ast_rtp_instance *instance, format_t format)
 Tell underlying RTP engine that audio frames will be provided in a specific format. More...
 
void ast_rtp_instance_stop (struct ast_rtp_instance *instance)
 Stop an RTP instance. More...
 
void ast_rtp_instance_stun_request (struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username)
 Request that the underlying RTP engine send a STUN BIND request. More...
 
void ast_rtp_instance_update_source (struct ast_rtp_instance *instance)
 Indicate that the RTP marker bit should be set on an RTP stream. More...
 
int ast_rtp_instance_write (struct ast_rtp_instance *instance, struct ast_frame *frame)
 Send a frame out over RTP. More...
 
char * ast_rtp_lookup_mime_multiple2 (struct ast_str *buf, const format_t capability, const int asterisk_format, enum ast_rtp_options options)
 Convert formats into a string and put them into a buffer. More...
 
const char * ast_rtp_lookup_mime_subtype2 (const int asterisk_format, const format_t code, enum ast_rtp_options options)
 Retrieve mime subtype information on a payload. More...
 
unsigned int ast_rtp_lookup_sample_rate2 (int asterisk_format, format_t code)
 Get the sample rate associated with known RTP payload types. More...
 
int ast_rtp_red_buffer (struct ast_rtp_instance *instance, struct ast_frame *frame)
 Buffer a frame in an RTP instance for RED. More...
 
int ast_rtp_red_init (struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations)
 Initialize RED support on an RTP instance. More...
 

Detailed Description

Pluggable RTP Architecture.

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om Asterisk RTP Engine API

Definition in file rtp_engine.h.

Macro Definition Documentation

#define AST_RED_MAX_GENERATION   5

Definition at line 82 of file rtp_engine.h.

Referenced by process_sdp_a_text().

#define AST_RTP_CISCO_DTMF   (1 << 2)

DTMF (Cisco Proprietary)

Definition at line 222 of file rtp_engine.h.

Referenced by ast_rtp_read().

#define AST_RTP_CN   (1 << 1)

'Comfort Noise' (RFC3389)

Definition at line 220 of file rtp_engine.h.

Referenced by ast_rtp_read(), and ast_rtp_sendcng().

#define ast_rtp_engine_register (   engine)    ast_rtp_engine_register2(engine, ast_module_info->self)

Definition at line 423 of file rtp_engine.h.

Referenced by load_module().

#define ast_rtp_glue_register (   glue)    ast_rtp_glue_register2(glue, ast_module_info->self)

Definition at line 476 of file rtp_engine.h.

Referenced by load_module().

#define AST_RTP_MAX   AST_RTP_CISCO_DTMF

Maximum RTP-specific code

Definition at line 224 of file rtp_engine.h.

Referenced by add_sdp(), and ast_rtp_lookup_mime_multiple2().

#define AST_RTP_STAT_SET (   current_stat,
  combined,
  placement,
  value 
)

Definition at line 296 of file rtp_engine.h.

Referenced by ast_rtp_get_stat().

#define AST_RTP_STAT_TERMINATOR (   combined)
Value:
if (stat == combined) { \
return 0; \
}

Definition at line 304 of file rtp_engine.h.

Referenced by ast_rtp_get_stat().

Enumeration Type Documentation

RTP DTMF Modes

Enumerator
AST_RTP_DTMF_MODE_NONE 

No DTMF is being carried over the RTP stream

AST_RTP_DTMF_MODE_RFC2833 

DTMF is being carried out of band using RFC2833

AST_RTP_DTMF_MODE_INBAND 

DTMF is being carried inband over the RTP stream

Definition at line 115 of file rtp_engine.h.

115  {
116  /*! No DTMF is being carried over the RTP stream */
118  /*! DTMF is being carried out of band using RFC2833 */
120  /*! DTMF is being carried inband over the RTP stream */
122 };

Result codes when RTP glue is queried for information

Enumerator
AST_RTP_GLUE_RESULT_FORBID 

No remote or local bridging is permitted

AST_RTP_GLUE_RESULT_REMOTE 

Move RTP stream to be remote between devices directly

AST_RTP_GLUE_RESULT_LOCAL 

Perform RTP engine level bridging if possible

Definition at line 125 of file rtp_engine.h.

125  {
126  /*! No remote or local bridging is permitted */
128  /*! Move RTP stream to be remote between devices directly */
130  /*! Perform RTP engine level bridging if possible */
132 };

Statistics that can be retrieved from an RTP instance

Enumerator
AST_RTP_INSTANCE_STAT_ALL 

Retrieve all statistics

AST_RTP_INSTANCE_STAT_TXCOUNT 

Retrieve number of packets transmitted

AST_RTP_INSTANCE_STAT_RXCOUNT 

Retrieve number of packets received

AST_RTP_INSTANCE_STAT_COMBINED_LOSS 

Retrieve ALL statistics relating to packet loss

AST_RTP_INSTANCE_STAT_TXPLOSS 

Retrieve number of packets lost for transmitting

AST_RTP_INSTANCE_STAT_RXPLOSS 

Retrieve number of packets lost for receiving

AST_RTP_INSTANCE_STAT_REMOTE_MAXRXPLOSS 

Retrieve maximum number of packets lost on remote side

AST_RTP_INSTANCE_STAT_REMOTE_MINRXPLOSS 

Retrieve minimum number of packets lost on remote side

AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVRXPLOSS 

Retrieve average number of packets lost on remote side

AST_RTP_INSTANCE_STAT_REMOTE_STDEVRXPLOSS 

Retrieve standard deviation of packets lost on remote side

AST_RTP_INSTANCE_STAT_LOCAL_MAXRXPLOSS 

Retrieve maximum number of packets lost on local side

AST_RTP_INSTANCE_STAT_LOCAL_MINRXPLOSS 

Retrieve minimum number of packets lost on local side

AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVRXPLOSS 

Retrieve average number of packets lost on local side

AST_RTP_INSTANCE_STAT_LOCAL_STDEVRXPLOSS 

Retrieve standard deviation of packets lost on local side

AST_RTP_INSTANCE_STAT_COMBINED_JITTER 

Retrieve ALL statistics relating to jitter

AST_RTP_INSTANCE_STAT_TXJITTER 

Retrieve jitter on transmitted packets

AST_RTP_INSTANCE_STAT_RXJITTER 

Retrieve jitter on received packets

AST_RTP_INSTANCE_STAT_REMOTE_MAXJITTER 

Retrieve maximum jitter on remote side

AST_RTP_INSTANCE_STAT_REMOTE_MINJITTER 

Retrieve minimum jitter on remote side

AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVJITTER 

Retrieve average jitter on remote side

AST_RTP_INSTANCE_STAT_REMOTE_STDEVJITTER 

Retrieve standard deviation jitter on remote side

AST_RTP_INSTANCE_STAT_LOCAL_MAXJITTER 

Retrieve maximum jitter on local side

AST_RTP_INSTANCE_STAT_LOCAL_MINJITTER 

Retrieve minimum jitter on local side

AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVJITTER 

Retrieve average jitter on local side

AST_RTP_INSTANCE_STAT_LOCAL_STDEVJITTER 

Retrieve standard deviation jitter on local side

AST_RTP_INSTANCE_STAT_COMBINED_RTT 

Retrieve ALL statistics relating to round trip time

AST_RTP_INSTANCE_STAT_RTT 

Retrieve round trip time

AST_RTP_INSTANCE_STAT_MAX_RTT 

Retrieve maximum round trip time

AST_RTP_INSTANCE_STAT_MIN_RTT 

Retrieve minimum round trip time

AST_RTP_INSTANCE_STAT_NORMDEVRTT 

Retrieve average round trip time

AST_RTP_INSTANCE_STAT_STDEVRTT 

Retrieve standard deviation round trip time

AST_RTP_INSTANCE_STAT_LOCAL_SSRC 

Retrieve local SSRC

AST_RTP_INSTANCE_STAT_REMOTE_SSRC 

Retrieve remote SSRC

Definition at line 147 of file rtp_engine.h.

147  {
148  /*! Retrieve all statistics */
150  /*! Retrieve number of packets transmitted */
152  /*! Retrieve number of packets received */
154  /*! Retrieve ALL statistics relating to packet loss */
156  /*! Retrieve number of packets lost for transmitting */
158  /*! Retrieve number of packets lost for receiving */
160  /*! Retrieve maximum number of packets lost on remote side */
162  /*! Retrieve minimum number of packets lost on remote side */
164  /*! Retrieve average number of packets lost on remote side */
166  /*! Retrieve standard deviation of packets lost on remote side */
168  /*! Retrieve maximum number of packets lost on local side */
170  /*! Retrieve minimum number of packets lost on local side */
172  /*! Retrieve average number of packets lost on local side */
174  /*! Retrieve standard deviation of packets lost on local side */
176  /*! Retrieve ALL statistics relating to jitter */
178  /*! Retrieve jitter on transmitted packets */
180  /*! Retrieve jitter on received packets */
182  /*! Retrieve maximum jitter on remote side */
184  /*! Retrieve minimum jitter on remote side */
186  /*! Retrieve average jitter on remote side */
188  /*! Retrieve standard deviation jitter on remote side */
190  /*! Retrieve maximum jitter on local side */
192  /*! Retrieve minimum jitter on local side */
194  /*! Retrieve average jitter on local side */
196  /*! Retrieve standard deviation jitter on local side */
198  /*! Retrieve ALL statistics relating to round trip time */
200  /*! Retrieve round trip time */
202  /*! Retrieve maximum round trip time */
204  /*! Retrieve minimum round trip time */
206  /*! Retrieve average round trip time */
208  /*! Retrieve standard deviation round trip time */
210  /*! Retrieve local SSRC */
212  /*! Retrieve remote SSRC */
214 };

Field statistics that can be retrieved from an RTP instance

Enumerator
AST_RTP_INSTANCE_STAT_FIELD_QUALITY 

Retrieve quality information

AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER 

Retrieve quality information about jitter

AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS 

Retrieve quality information about packet loss

AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT 

Retrieve quality information about round trip time

Definition at line 135 of file rtp_engine.h.

135  {
136  /*! Retrieve quality information */
138  /*! Retrieve quality information about jitter */
140  /*! Retrieve quality information about packet loss */
142  /*! Retrieve quality information about round trip time */
144 };

Additional RTP options

Enumerator
AST_RTP_OPT_G726_NONSTANDARD 

Remote side is using non-standard G.726

Definition at line 109 of file rtp_engine.h.

109  {
110  /*! Remote side is using non-standard G.726 */
111  AST_RTP_OPT_G726_NONSTANDARD = (1 << 0),
112 };

RTP Properties that can be set on an RTP instance

Enumerator
AST_RTP_PROPERTY_NAT 

Enable symmetric RTP support

AST_RTP_PROPERTY_DTMF 

RTP instance will be carrying DTMF (using RFC2833)

AST_RTP_PROPERTY_DTMF_COMPENSATE 

Expect unreliable DTMF from remote party

AST_RTP_PROPERTY_STUN 

Enable STUN support

AST_RTP_PROPERTY_RTCP 

Enable RTCP support

AST_RTP_PROPERTY_MAX 

Maximum number of RTP properties supported.

Note
THIS MUST BE THE LAST ENTRY IN THIS ENUM.

Definition at line 88 of file rtp_engine.h.

88  {
89  /*! Enable symmetric RTP support */
91  /*! RTP instance will be carrying DTMF (using RFC2833) */
93  /*! Expect unreliable DTMF from remote party */
95  /*! Enable STUN support */
97  /*! Enable RTCP support */
99 
100  /*!
101  * \brief Maximum number of RTP properties supported
102  *
103  * \note THIS MUST BE THE LAST ENTRY IN THIS ENUM.
104  */
106 };
Maximum number of RTP properties supported.
Definition: rtp_engine.h:105

Function Documentation

void ast_rtp_codecs_packetization_set ( struct ast_rtp_codecs codecs,
struct ast_rtp_instance instance,
struct ast_codec_pref prefs 
)

Set codec packetization preferences.

Parameters
codecsCodecs structure to muck with
instanceOptionally the instance that the codecs structure belongs to
prefsCodec packetization preferences

Example usage:

This sets the packetization preferences pointed to by prefs on the codecs structure pointed to by codecs.

Since
1.8

Definition at line 727 of file rtp_engine.c.

References ast_rtp_instance::codecs, ast_rtp_instance::engine, ast_rtp_engine::packetization_set, ast_rtp_codecs::pref, and prefs.

Referenced by __oh323_rtp_create(), check_peer_ok(), create_addr_from_peer(), gtalk_new(), jingle_new(), process_sdp_a_audio(), set_peer_capabilities(), start_rtp(), and transmit_response_with_sdp().

728 {
729  codecs->pref = *prefs;
730 
731  if (instance && instance->engine->packetization_set) {
732  instance->engine->packetization_set(instance, &instance->codecs.pref);
733  }
734 }
struct ast_codec_pref pref
Definition: rtp_engine.h:387
void(* packetization_set)(struct ast_rtp_instance *instance, struct ast_codec_pref *pref)
Definition: rtp_engine.h:341
static struct ast_codec_pref prefs
Definition: chan_iax2.c:258
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
struct ast_rtp_codecs codecs
Definition: rtp_engine.c:68
int ast_rtp_codecs_payload_code ( struct ast_rtp_codecs codecs,
const int  asterisk_format,
const format_t  code 
)

Retrieve a payload based on whether it is an Asterisk format and the code.

Parameters
codecsCodecs structure to look in
asterisk_formatNon-zero if the given code is an Asterisk format value
codeThe format to look for
Return values
Numericalpayload

Example usage:

* int payload = ast_rtp_codecs_payload_code(&codecs, 1, AST_FORMAT_ULAW);
*

This looks for the numerical payload for ULAW in the codecs structure.

Since
1.8

Definition at line 654 of file rtp_engine.c.

References AST_RTP_MAX_PT, ast_rtp_payload_type::asterisk_format, ast_rtp_payload_type::code, and ast_rtp_codecs::payloads.

Referenced by add_codec_to_sdp(), add_noncodec_to_sdp(), add_sdp(), add_tcodec_to_sdp(), add_vcodec_to_sdp(), ast_rtp_dtmf_begin(), ast_rtp_sendcng(), ast_rtp_write(), bridge_p2p_rtp_write(), multicast_rtp_write(), and start_rtp().

655 {
656  int i;
657 
658  for (i = 0; i < AST_RTP_MAX_PT; i++) {
659  if (codecs->payloads[i].asterisk_format == asterisk_format && codecs->payloads[i].code == code) {
660  return i;
661  }
662  }
663 
664  for (i = 0; i < AST_RTP_MAX_PT; i++) {
665  if (static_RTP_PT[i].asterisk_format == asterisk_format && static_RTP_PT[i].code == code) {
666  return i;
667  }
668  }
669 
670  return -1;
671 }
static struct ast_rtp_payload_type static_RTP_PT[AST_RTP_MAX_PT]
Mapping between Asterisk codecs and rtp payload types.
Definition: rtp_engine.c:147
struct ast_rtp_payload_type payloads[AST_RTP_MAX_PT]
Definition: rtp_engine.h:389
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:79
void ast_rtp_codecs_payload_formats ( struct ast_rtp_codecs codecs,
format_t astformats,
int *  nonastformats 
)

Retrieve all formats that were found.

Parameters
codecsCodecs structure to look in
astformatsAn integer to put the Asterisk formats in
nonastformatsAn integer to put the non-Asterisk formats in

Example usage:

* int astformats, nonastformats;
* ast_rtp_codecs_payload_Formats(&codecs, &astformats, &nonastformats);
*

This retrieves all the formats known about in the codecs structure and puts the Asterisk ones in the integer pointed to by astformats and the non-Asterisk ones in the integer pointed to by nonastformats.

Since
1.8

Definition at line 636 of file rtp_engine.c.

References ast_debug, AST_RTP_MAX_PT, ast_rtp_payload_type::asterisk_format, ast_rtp_payload_type::code, and ast_rtp_codecs::payloads.

Referenced by gtalk_is_answered(), gtalk_newcall(), and process_sdp().

637 {
638  int i;
639 
640  *astformats = *nonastformats = 0;
641 
642  for (i = 0; i < AST_RTP_MAX_PT; i++) {
643  if (codecs->payloads[i].code) {
644  ast_debug(1, "Incorporating payload %d on %p\n", i, codecs);
645  }
646  if (codecs->payloads[i].asterisk_format) {
647  *astformats |= codecs->payloads[i].code;
648  } else {
649  *nonastformats |= codecs->payloads[i].code;
650  }
651  }
652 }
struct ast_rtp_payload_type payloads[AST_RTP_MAX_PT]
Definition: rtp_engine.h:389
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:79
struct ast_rtp_payload_type ast_rtp_codecs_payload_lookup ( struct ast_rtp_codecs codecs,
int  payload 
)

Retrieve payload information by payload.

Parameters
codecsCodecs structure to look in
payloadNumerical payload to look up
Return values
Payloadinformation

Example usage:

* struct ast_rtp_payload_type payload_type;
* payload_type = ast_rtp_codecs_payload_lookup(&codecs, 0);
*

This looks up the information for payload '0' from the codecs structure.

Since
1.8

Definition at line 618 of file rtp_engine.c.

References AST_RTP_MAX_PT, ast_rtp_payload_type::asterisk_format, and ast_rtp_payload_type::code.

Referenced by ast_rtp_read(), bridge_p2p_rtp_write(), process_sdp_a_audio(), and setup_rtp_connection().

619 {
620  struct ast_rtp_payload_type result = { .asterisk_format = 0, };
621 
622  if (payload < 0 || payload >= AST_RTP_MAX_PT) {
623  return result;
624  }
625 
626  result.asterisk_format = codecs->payloads[payload].asterisk_format;
627  result.code = codecs->payloads[payload].code;
628 
629  if (!result.code) {
630  result = static_RTP_PT[payload];
631  }
632 
633  return result;
634 }
static struct ast_rtp_payload_type static_RTP_PT[AST_RTP_MAX_PT]
Mapping between Asterisk codecs and rtp payload types.
Definition: rtp_engine.c:147
struct ast_rtp_payload_type payloads[AST_RTP_MAX_PT]
Definition: rtp_engine.h:389
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:79
void ast_rtp_codecs_payloads_clear ( struct ast_rtp_codecs codecs,
struct ast_rtp_instance instance 
)

Clear payload information from an RTP instance.

Parameters
codecsThe codecs structure that payloads will be cleared from
instanceOptionally the instance that the codecs structure belongs to

Example usage:

* struct ast_rtp_codecs codecs;
*

This clears the codecs structure and puts it into a pristine state.

Since
1.8

Definition at line 488 of file rtp_engine.c.

References AST_RTP_MAX_PT, ast_rtp_payload_type::asterisk_format, ast_rtp_payload_type::code, ast_rtp_instance::engine, ast_rtp_engine::payload_set, and ast_rtp_codecs::payloads.

Referenced by gtalk_alloc(), and process_sdp().

489 {
490  int i;
491 
492  for (i = 0; i < AST_RTP_MAX_PT; i++) {
493  codecs->payloads[i].asterisk_format = 0;
494  codecs->payloads[i].code = 0;
495  if (instance && instance->engine && instance->engine->payload_set) {
496  instance->engine->payload_set(instance, i, 0, 0);
497  }
498  }
499 }
struct ast_rtp_payload_type payloads[AST_RTP_MAX_PT]
Definition: rtp_engine.h:389
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:79
void(* payload_set)(struct ast_rtp_instance *instance, int payload, int astformat, format_t format)
Definition: rtp_engine.h:339
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
void ast_rtp_codecs_payloads_copy ( struct ast_rtp_codecs src,
struct ast_rtp_codecs dest,
struct ast_rtp_instance instance 
)

Copy payload information from one RTP instance to another.

Parameters
srcThe source codecs structure
destThe destination codecs structure that the values from src will be copied to
instanceOptionally the instance that the dst codecs structure belongs to

Example usage:

* ast_rtp_codecs_payloads_copy(&codecs0, &codecs1, NULL);
*

This copies the payloads from the codecs0 structure to the codecs1 structure, overwriting any current values.

Since
1.8

Definition at line 516 of file rtp_engine.c.

References ast_debug, AST_RTP_MAX_PT, ast_rtp_payload_type::asterisk_format, ast_rtp_payload_type::code, ast_rtp_instance::engine, ast_rtp_engine::payload_set, and ast_rtp_codecs::payloads.

Referenced by ast_rtp_instance_early_bridge_make_compatible(), and process_sdp().

517 {
518  int i;
519 
520  for (i = 0; i < AST_RTP_MAX_PT; i++) {
521  if (src->payloads[i].code) {
522  ast_debug(2, "Copying payload %d from %p to %p\n", i, src, dest);
524  dest->payloads[i].code = src->payloads[i].code;
525  if (instance && instance->engine && instance->engine->payload_set) {
526  instance->engine->payload_set(instance, i, dest->payloads[i].asterisk_format, dest->payloads[i].code);
527  }
528  }
529  }
530 }
struct ast_rtp_payload_type payloads[AST_RTP_MAX_PT]
Definition: rtp_engine.h:389
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:79
void(* payload_set)(struct ast_rtp_instance *instance, int payload, int astformat, format_t format)
Definition: rtp_engine.h:339
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
void ast_rtp_codecs_payloads_default ( struct ast_rtp_codecs codecs,
struct ast_rtp_instance instance 
)

Set payload information on an RTP instance to the default.

Parameters
codecsThe codecs structure to set defaults on
instanceOptionally the instance that the codecs structure belongs to

Example usage:

* struct ast_rtp_codecs codecs;
*

This sets the default payloads on the codecs structure.

Since
1.8

Definition at line 501 of file rtp_engine.c.

References AST_RTP_MAX_PT, ast_rtp_payload_type::asterisk_format, ast_rtp_payload_type::code, ast_rtp_instance::engine, ast_rtp_engine::payload_set, and ast_rtp_codecs::payloads.

502 {
503  int i;
504 
505  for (i = 0; i < AST_RTP_MAX_PT; i++) {
506  if (static_RTP_PT[i].code) {
508  codecs->payloads[i].code = static_RTP_PT[i].code;
509  if (instance && instance->engine && instance->engine->payload_set) {
510  instance->engine->payload_set(instance, i, codecs->payloads[i].asterisk_format, codecs->payloads[i].code);
511  }
512  }
513  }
514 }
static struct ast_rtp_payload_type static_RTP_PT[AST_RTP_MAX_PT]
Mapping between Asterisk codecs and rtp payload types.
Definition: rtp_engine.c:147
struct ast_rtp_payload_type payloads[AST_RTP_MAX_PT]
Definition: rtp_engine.h:389
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:79
void(* payload_set)(struct ast_rtp_instance *instance, int payload, int astformat, format_t format)
Definition: rtp_engine.h:339
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
void ast_rtp_codecs_payloads_set_m_type ( struct ast_rtp_codecs codecs,
struct ast_rtp_instance instance,
int  payload 
)

Record payload information that was seen in an m= SDP line.

Parameters
codecsThe codecs structure to muck with
instanceOptionally the instance that the codecs structure belongs to
payloadNumerical payload that was seen in the m= SDP line

Example usage:

*

This records that the numerical payload '0' was seen in the codecs structure.

Since
1.8

Definition at line 532 of file rtp_engine.c.

References ast_debug, AST_RTP_MAX_PT, ast_rtp_payload_type::asterisk_format, ast_rtp_payload_type::code, ast_rtp_instance::engine, ast_rtp_engine::payload_set, and ast_rtp_codecs::payloads.

Referenced by gtalk_is_answered(), gtalk_newcall(), jingle_newcall(), and process_sdp().

533 {
534  if (payload < 0 || payload >= AST_RTP_MAX_PT || !static_RTP_PT[payload].code) {
535  return;
536  }
537 
538  codecs->payloads[payload].asterisk_format = static_RTP_PT[payload].asterisk_format;
539  codecs->payloads[payload].code = static_RTP_PT[payload].code;
540 
541  ast_debug(1, "Setting payload %d based on m type on %p\n", payload, codecs);
542 
543  if (instance && instance->engine && instance->engine->payload_set) {
544  instance->engine->payload_set(instance, payload, codecs->payloads[payload].asterisk_format, codecs->payloads[payload].code);
545  }
546 }
static struct ast_rtp_payload_type static_RTP_PT[AST_RTP_MAX_PT]
Mapping between Asterisk codecs and rtp payload types.
Definition: rtp_engine.c:147
struct ast_rtp_payload_type payloads[AST_RTP_MAX_PT]
Definition: rtp_engine.h:389
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:79
void(* payload_set)(struct ast_rtp_instance *instance, int payload, int astformat, format_t format)
Definition: rtp_engine.h:339
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
int ast_rtp_codecs_payloads_set_rtpmap_type ( struct ast_rtp_codecs codecs,
struct ast_rtp_instance instance,
int  payload,
char *  mimetype,
char *  mimesubtype,
enum ast_rtp_options  options 
)

Record payload information that was seen in an a=rtpmap: SDP line.

Parameters
codecsThe codecs structure to muck with
instanceOptionally the instance that the codecs structure belongs to
payloadNumerical payload that was seen in the a=rtpmap: SDP line
mimetypeThe string mime type that was seen
mimesubtypeThe strin mime sub type that was seen
optionsOptional options that may change the behavior of this specific payload
Return values
0success
-1failure, invalid payload numbe
-2failure, unknown mimetype

Example usage:

* ast_rtp_codecs_payloads_set_rtpmap_type(&codecs, NULL, 0, "audio", "PCMU", 0);
*

This records that the numerical payload '0' was seen with mime type 'audio' and sub mime type 'PCMU' in the codecs structure.

Since
1.8

Definition at line 597 of file rtp_engine.c.

References ast_rtp_codecs_payloads_set_rtpmap_type_rate().

Referenced by __oh323_rtp_create(), gtalk_is_answered(), gtalk_newcall(), jingle_newcall(), process_sdp(), set_dtmf_payload(), and setup_rtp_connection().

598 {
599  return ast_rtp_codecs_payloads_set_rtpmap_type_rate(codecs, instance, payload, mimetype, mimesubtype, options, 0);
600 }
int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int pt, char *mimetype, char *mimesubtype, enum ast_rtp_options options, unsigned int sample_rate)
Set payload type to a known MIME media type for a codec with a specific sample rate.
Definition: rtp_engine.c:548
int ast_rtp_codecs_payloads_set_rtpmap_type_rate ( struct ast_rtp_codecs codecs,
struct ast_rtp_instance instance,
int  pt,
char *  mimetype,
char *  mimesubtype,
enum ast_rtp_options  options,
unsigned int  sample_rate 
)

Set payload type to a known MIME media type for a codec with a specific sample rate.

Parameters
codecsRTP structure to modify
instanceOptionally the instance that the codecs structure belongs to
ptPayload type entry to modify
mimetypetop-level MIME type of media stream (typically "audio", "video", "text", etc.)
mimesubtypeMIME subtype of media stream (typically a codec name)
optionsZero or more flags from the ast_rtp_options enum
sample_rateThe sample rate of the media stream

This function 'fills in' an entry in the list of possible formats for a media stream associated with an RTP structure.

Return values
0on success
-1if the payload type is out of range
-2if the mimeType/mimeSubtype combination was not found
Since
1.8

Definition at line 548 of file rtp_engine.c.

References ARRAY_LEN, AST_FORMAT_G726, AST_FORMAT_G726_AAL2, AST_RTP_MAX_PT, ast_rtp_mime_types, AST_RTP_OPT_G726_NONSTANDARD, ast_rtp_payload_type::asterisk_format, ast_rtp_payload_type::code, ast_rtp_instance::engine, ast_rtp_engine::payload_set, ast_rtp_mime_type::payload_type, ast_rtp_codecs::payloads, ast_rtp_mime_type::sample_rate, ast_rtp_mime_type::subtype, and ast_rtp_mime_type::type.

Referenced by ast_rtp_codecs_payloads_set_rtpmap_type(), process_sdp_a_audio(), process_sdp_a_text(), and process_sdp_a_video().

552 {
553  unsigned int i;
554  int found = 0;
555 
556  if (pt < 0 || pt >= AST_RTP_MAX_PT)
557  return -1; /* bogus payload type */
558 
559  for (i = 0; i < ARRAY_LEN(ast_rtp_mime_types); ++i) {
560  const struct ast_rtp_mime_type *t = &ast_rtp_mime_types[i];
561 
562  if (strcasecmp(mimesubtype, t->subtype)) {
563  continue;
564  }
565 
566  if (strcasecmp(mimetype, t->type)) {
567  continue;
568  }
569 
570  /* if both sample rates have been supplied, and they don't match,
571  * then this not a match; if one has not been supplied, then the
572  * rates are not compared */
573  if (sample_rate && t->sample_rate &&
574  (sample_rate != t->sample_rate)) {
575  continue;
576  }
577 
578  found = 1;
579  codecs->payloads[pt] = t->payload_type;
580 
581  if ((t->payload_type.code == AST_FORMAT_G726) &&
583  (options & AST_RTP_OPT_G726_NONSTANDARD)) {
584  codecs->payloads[pt].code = AST_FORMAT_G726_AAL2;
585  }
586 
587  if (instance && instance->engine && instance->engine->payload_set) {
588  instance->engine->payload_set(instance, pt, codecs->payloads[i].asterisk_format, codecs->payloads[i].code);
589  }
590 
591  break;
592  }
593 
594  return (found ? 0 : -2);
595 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
struct ast_rtp_payload_type payloads[AST_RTP_MAX_PT]
Definition: rtp_engine.h:389
unsigned int sample_rate
Definition: rtp_engine.c:95
struct ast_rtp_payload_type payload_type
Definition: rtp_engine.c:92
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:79
void(* payload_set)(struct ast_rtp_instance *instance, int payload, int astformat, format_t format)
Definition: rtp_engine.h:339
#define AST_FORMAT_G726
Definition: frame.h:264
#define AST_FORMAT_G726_AAL2
Definition: frame.h:250
static struct ast_rtp_mime_type ast_rtp_mime_types[]
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
void ast_rtp_codecs_payloads_unset ( struct ast_rtp_codecs codecs,
struct ast_rtp_instance instance,
int  payload 
)

Remove payload information.

Parameters
codecsThe codecs structure to muck with
instanceOptionally the instance that the codecs structure belongs to
payloadNumerical payload to unset

Example usage:

* ast_rtp_codecs_payloads_unset(&codecs, NULL, 0);
*

This clears the payload '0' from the codecs structure. It will be as if it was never set.

Since
1.8

Definition at line 602 of file rtp_engine.c.

References ast_debug, AST_RTP_MAX_PT, ast_rtp_payload_type::asterisk_format, ast_rtp_payload_type::code, ast_rtp_instance::engine, ast_rtp_engine::payload_set, and ast_rtp_codecs::payloads.

Referenced by process_sdp_a_audio(), and process_sdp_a_video().

603 {
604  if (payload < 0 || payload >= AST_RTP_MAX_PT) {
605  return;
606  }
607 
608  ast_debug(2, "Unsetting payload %d on %p\n", payload, codecs);
609 
610  codecs->payloads[payload].asterisk_format = 0;
611  codecs->payloads[payload].code = 0;
612 
613  if (instance && instance->engine && instance->engine->payload_set) {
614  instance->engine->payload_set(instance, payload, 0, 0);
615  }
616 }
struct ast_rtp_payload_type payloads[AST_RTP_MAX_PT]
Definition: rtp_engine.h:389
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:79
void(* payload_set)(struct ast_rtp_instance *instance, int payload, int astformat, format_t format)
Definition: rtp_engine.h:339
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
int ast_rtp_engine_register2 ( struct ast_rtp_engine engine,
struct ast_module module 
)

Register an RTP engine.

Parameters
engineStructure of the RTP engine to register
moduleModule that the RTP engine is part of
Return values
0success
-1failure

Example usage:

* ast_rtp_engine_register2(&example_rtp_engine, NULL);
*

This registers the RTP engine declared as example_rtp_engine with the RTP engine core, but does not associate a module with it.

Note
It is recommended that you use the ast_rtp_engine_register macro so that the module is associated with the RTP engine and use counting is performed.
Since
1.8

Definition at line 188 of file rtp_engine.c.

References ast_log(), AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strlen_zero(), ast_verb, ast_rtp_engine::destroy, LOG_WARNING, ast_rtp_engine::mod, ast_rtp_engine::name, ast_rtp_engine::new, ast_rtp_engine::read, and ast_rtp_engine::write.

189 {
190  struct ast_rtp_engine *current_engine;
191 
192  /* Perform a sanity check on the engine structure to make sure it has the basics */
193  if (ast_strlen_zero(engine->name) || !engine->new || !engine->destroy || !engine->write || !engine->read) {
194  ast_log(LOG_WARNING, "RTP Engine '%s' failed sanity check so it was not registered.\n", !ast_strlen_zero(engine->name) ? engine->name : "Unknown");
195  return -1;
196  }
197 
198  /* Link owner module to the RTP engine for reference counting purposes */
199  engine->mod = module;
200 
202 
203  /* Ensure that no two modules with the same name are registered at the same time */
204  AST_RWLIST_TRAVERSE(&engines, current_engine, entry) {
205  if (!strcmp(current_engine->name, engine->name)) {
206  ast_log(LOG_WARNING, "An RTP engine with the name '%s' has already been registered.\n", engine->name);
208  return -1;
209  }
210  }
211 
212  /* The engine survived our critique. Off to the list it goes to be used */
213  AST_RWLIST_INSERT_TAIL(&engines, engine, entry);
214 
216 
217  ast_verb(2, "Registered RTP engine '%s'\n", engine->name);
218 
219  return 0;
220 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:144
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
int(* new)(struct ast_rtp_instance *instance, struct sched_context *sched, struct ast_sockaddr *sa, void *data)
Definition: rtp_engine.h:316
int(* write)(struct ast_rtp_instance *instance, struct ast_frame *frame)
Definition: rtp_engine.h:320
int(* destroy)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:318
#define ast_verb(level,...)
Definition: logger.h:243
struct ast_frame *(* read)(struct ast_rtp_instance *instance, int rtcp)
Definition: rtp_engine.h:361
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
struct ast_module * mod
Definition: rtp_engine.h:314
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
const char * name
Definition: rtp_engine.h:312
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:726
int ast_rtp_engine_register_srtp ( struct ast_srtp_res srtp_res,
struct ast_srtp_policy_res policy_res 
)

Definition at line 1803 of file rtp_engine.c.

References policy_res, and srtp_res.

Referenced by res_srtp_init().

1804 {
1805  if (res_srtp || res_srtp_policy) {
1806  return -1;
1807  }
1808  if (!srtp_res || !policy_res) {
1809  return -1;
1810  }
1811 
1812  res_srtp = srtp_res;
1814 
1815  return 0;
1816 }
struct ast_srtp_policy_res * res_srtp_policy
Definition: rtp_engine.c:49
static struct ast_srtp_res srtp_res
Definition: res_srtp.c:89
static struct ast_srtp_policy_res policy_res
Definition: res_srtp.c:101
struct ast_srtp_res * res_srtp
Definition: rtp_engine.c:48
int ast_rtp_engine_srtp_is_registered ( void  )

Definition at line 1824 of file rtp_engine.c.

References res_srtp_policy.

Referenced by sdp_crypto_activate(), sdp_crypto_process(), sdp_crypto_setup(), set_crypto_policy(), and setup_srtp().

1825 {
1826  return res_srtp && res_srtp_policy;
1827 }
struct ast_srtp_policy_res * res_srtp_policy
Definition: rtp_engine.c:49
struct ast_srtp_res * res_srtp
Definition: rtp_engine.c:48
int ast_rtp_engine_unregister ( struct ast_rtp_engine engine)

Unregister an RTP engine.

Parameters
engineStructure of the RTP engine to unregister
Return values
0success
-1failure

Example usage:

* ast_rtp_engine_unregister(&example_rtp_engine);
*

This unregisters the RTP engine declared as example_rtp_engine from the RTP engine core. If a module reference was provided when it was registered then this will only be called once the RTP engine is no longer in use.

Since
1.8

Definition at line 222 of file rtp_engine.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, and ast_rtp_engine::name.

Referenced by load_module(), and unload_module().

223 {
224  struct ast_rtp_engine *current_engine = NULL;
225 
227 
228  if ((current_engine = AST_RWLIST_REMOVE(&engines, engine, entry))) {
229  ast_verb(2, "Unregistered RTP engine '%s'\n", engine->name);
230  }
231 
233 
234  return current_engine ? 0 : -1;
235 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define ast_verb(level,...)
Definition: logger.h:243
const char * name
Definition: rtp_engine.h:312
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:870
void ast_rtp_engine_unregister_srtp ( void  )

Definition at line 1818 of file rtp_engine.c.

Referenced by res_srtp_shutdown().

1819 {
1820  res_srtp = NULL;
1821  res_srtp_policy = NULL;
1822 }
struct ast_srtp_policy_res * res_srtp_policy
Definition: rtp_engine.c:49
struct ast_srtp_res * res_srtp
Definition: rtp_engine.c:48
int ast_rtp_glue_register2 ( struct ast_rtp_glue glue,
struct ast_module module 
)

Register RTP glue.

Parameters
glueThe glue to register
moduleModule that the RTP glue is part of
Return values
0success
-1failure

Example usage:

* ast_rtp_glue_register2(&example_rtp_glue, NULL);
*

This registers the RTP glue declared as example_rtp_glue with the RTP engine core, but does not associate a module with it.

Note
It is recommended that you use the ast_rtp_glue_register macro so that the module is associated with the RTP glue and use counting is performed.
Since
1.8

Definition at line 237 of file rtp_engine.c.

References ast_log(), AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strlen_zero(), ast_verb, LOG_WARNING, ast_rtp_glue::mod, and ast_rtp_glue::type.

238 {
239  struct ast_rtp_glue *current_glue = NULL;
240 
241  if (ast_strlen_zero(glue->type)) {
242  return -1;
243  }
244 
245  glue->mod = module;
246 
248 
249  AST_RWLIST_TRAVERSE(&glues, current_glue, entry) {
250  if (!strcasecmp(current_glue->type, glue->type)) {
251  ast_log(LOG_WARNING, "RTP glue with the name '%s' has already been registered.\n", glue->type);
253  return -1;
254  }
255  }
256 
257  AST_RWLIST_INSERT_TAIL(&glues, glue, entry);
258 
260 
261  ast_verb(2, "Registered RTP glue '%s'\n", glue->type);
262 
263  return 0;
264 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define LOG_WARNING
Definition: logger.h:144
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define ast_verb(level,...)
Definition: logger.h:243
const char * type
Definition: rtp_engine.h:395
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
struct ast_module * mod
Definition: rtp_engine.h:397
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:726
int ast_rtp_glue_unregister ( struct ast_rtp_glue glue)

Unregister RTP glue.

Parameters
glueThe glue to unregister
Return values
0success
-1failure

Example usage:

* ast_rtp_glue_unregister(&example_rtp_glue);
*

This unregisters the RTP glue declared as example_rtp_gkue from the RTP engine core. If a module reference was provided when it was registered then this will only be called once the RTP engine is no longer in use.

Since
1.8

Definition at line 266 of file rtp_engine.c.

References AST_RWLIST_REMOVE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_verb, and ast_rtp_glue::type.

Referenced by load_module(), and unload_module().

267 {
268  struct ast_rtp_glue *current_glue = NULL;
269 
271 
272  if ((current_glue = AST_RWLIST_REMOVE(&glues, glue, entry))) {
273  ast_verb(2, "Unregistered RTP glue '%s'\n", glue->type);
274  }
275 
277 
278  return current_glue ? 0 : -1;
279 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:51
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
#define ast_verb(level,...)
Definition: logger.h:243
const char * type
Definition: rtp_engine.h:395
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:870
int ast_rtp_instance_activate ( struct ast_rtp_instance instance)

Indicate to the RTP engine that packets are now expected to be sent/received on the RTP instance.

Parameters
instanceThe RTP instance
Return values
0success
-1failure

Example usage:

This tells the underlying RTP engine of instance that packets will now flow.

Since
1.8

Definition at line 1744 of file rtp_engine.c.

References ast_rtp_engine::activate, and ast_rtp_instance::engine.

Referenced by handle_response_invite(), multicast_rtp_call(), and transmit_response_with_sdp().

1745 {
1746  return instance->engine->activate ? instance->engine->activate(instance) : 0;
1747 }
int(* activate)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:373
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
int ast_rtp_instance_add_srtp_policy ( struct ast_rtp_instance instance,
struct ast_srtp_policy remote_policy,
struct ast_srtp_policy local_policy 
)

Add or replace the SRTP policies for the given RTP instance.

Parameters
instancethe RTP instance
remote_policythe remote endpoint's policy
local_policyour policy for this RTP instance's remote endpoint
Return values
0Success
non-zeroFailure

Definition at line 1829 of file rtp_engine.c.

References ast_srtp_res::add_stream, ast_srtp_res::create, ast_srtp_res::replace, and ast_rtp_instance::srtp.

Referenced by sdp_crypto_activate().

1830 {
1831  int res = 0;
1832 
1833  if (!res_srtp) {
1834  return -1;
1835  }
1836 
1837  if (!instance->srtp) {
1838  res = res_srtp->create(&instance->srtp, instance, remote_policy);
1839  } else {
1840  res = res_srtp->replace(&instance->srtp, instance, remote_policy);
1841  }
1842  if (!res) {
1843  res = res_srtp->add_stream(instance->srtp, local_policy);
1844  }
1845 
1846  return res;
1847 }
int(* create)(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy)
Definition: res_srtp.h:34
int(* replace)(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy)
Definition: res_srtp.h:36
int(* add_stream)(struct ast_srtp *srtp, struct ast_srtp_policy *policy)
Definition: res_srtp.h:40
struct ast_srtp * srtp
Definition: rtp_engine.c:80
struct ast_srtp_res * res_srtp
Definition: rtp_engine.c:48
format_t ast_rtp_instance_available_formats ( struct ast_rtp_instance instance,
format_t  to_endpoint,
format_t  to_asterisk 
)

Request the formats that can be transcoded.

Parameters
instanceThe RTP instance
to_endpointFormats being sent/received towards the endpoint
to_asteriskFormats being sent/received towards Asterisk
Return values
supportedformats

Example usage:

This sees if it is possible to have ulaw communicated to the endpoint but signed linear received into Asterisk.

Since
1.8

Definition at line 1733 of file rtp_engine.c.

References ast_translate_available_formats(), ast_rtp_engine::available_formats, ast_rtp_instance::engine, and formats.

Referenced by sip_call().

1734 {
1735  format_t formats;
1736 
1737  if (instance->engine->available_formats && (formats = instance->engine->available_formats(instance, to_endpoint, to_asterisk))) {
1738  return formats;
1739  }
1740 
1741  return ast_translate_available_formats(to_endpoint, to_asterisk);
1742 }
static struct formats formats
format_t ast_translate_available_formats(format_t dest, format_t src)
Mask off unavailable formats from a format bitmask.
Definition: translate.c:1081
int64_t format_t
Definition: frame_defs.h:32
format_t(* available_formats)(struct ast_rtp_instance *instance, format_t to_endpoint, format_t to_asterisk)
Definition: rtp_engine.h:377
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
enum ast_bridge_result ast_rtp_instance_bridge ( struct ast_channel c0,
struct ast_channel c1,
int  flags,
struct ast_frame **  fo,
struct ast_channel **  rc,
int  timeoutms 
)

Bridge two channels that use RTP instances.

Parameters
c0First channel part of the bridge
c1Second channel part of the bridge
flagsBridging flags
foIf a frame needs to be passed up it is stored here
rcChannel that passed the above frame up
timeoutmsHow long the channels should be bridged for
Return values
Bridgeresult
Note
This should only be used by channel drivers in their technology declaration.
Since
1.8

Definition at line 1274 of file rtp_engine.c.

References AST_BRIDGE_DTMF_CHANNEL_0, AST_BRIDGE_DTMF_CHANNEL_1, AST_BRIDGE_FAILED, AST_BRIDGE_FAILED_NOWARN, ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_check_hangup(), ast_codec_pref_getsize(), ast_debug, ast_getformatname(), ast_log(), AST_RTP_GLUE_RESULT_FORBID, AST_RTP_GLUE_RESULT_LOCAL, AST_RTP_GLUE_RESULT_REMOTE, ast_rtp_instance_dtmf_mode_get(), ast_rtp_instance_get_glue(), ast_rtp_instance_get_remote_address(), ast_sockaddr_is_ipv4_mapped(), ast_verb, ast_rtp_instance::chan, ast_rtp_instance::codecs, ast_rtp_engine::dtmf_compatible, ast_rtp_instance::engine, ast_rtp_glue::get_codec, ast_rtp_glue::get_rtp_info, ast_rtp_glue::get_vrtp_info, ast_rtp_instance::glue, ast_rtp_engine::local_bridge, local_bridge_loop(), LOG_WARNING, ast_channel::name, ast_rtp_codecs::pref, ast_channel::rawreadformat, ast_channel::rawwriteformat, remote_bridge_loop(), ast_sockaddr::ss, ast_channel::tech, ast_channel::tech_pvt, ast_channel_tech::type, and unref_instance_cond().

1275 {
1276  struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
1277  *vinstance0 = NULL, *vinstance1 = NULL,
1278  *tinstance0 = NULL, *tinstance1 = NULL;
1279  struct ast_rtp_glue *glue0, *glue1;
1280  struct ast_sockaddr addr1 = { {0, }, }, addr2 = { {0, }, };
1281  enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
1282  enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
1284  enum ast_rtp_dtmf_mode dmode;
1285  format_t codec0 = 0, codec1 = 0;
1286  int unlock_chans = 1;
1287  int read_ptime0, read_ptime1, write_ptime0, write_ptime1;
1288 
1289  /* Lock both channels so we can look for the glue that binds them together */
1290  ast_channel_lock(c0);
1291  while (ast_channel_trylock(c1)) {
1292  ast_channel_unlock(c0);
1293  usleep(1);
1294  ast_channel_lock(c0);
1295  }
1296 
1297  /* Ensure neither channel got hungup during lock avoidance */
1298  if (ast_check_hangup(c0) || ast_check_hangup(c1)) {
1299  ast_log(LOG_WARNING, "Got hangup while attempting to bridge '%s' and '%s'\n", c0->name, c1->name);
1300  goto done;
1301  }
1302 
1303  /* Grab glue that binds each channel to something using the RTP engine */
1304  if (!(glue0 = ast_rtp_instance_get_glue(c0->tech->type)) || !(glue1 = ast_rtp_instance_get_glue(c1->tech->type))) {
1305  ast_debug(1, "Can't find native functions for channel '%s'\n", glue0 ? c1->name : c0->name);
1306  goto done;
1307  }
1308 
1309  audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
1310  video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;
1311 
1312  audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
1313  video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;
1314 
1315  /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
1316  if (video_glue0_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue0_res != AST_RTP_GLUE_RESULT_REMOTE)) {
1317  audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
1318  }
1319  if (video_glue1_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue1_res != AST_RTP_GLUE_RESULT_REMOTE)) {
1320  audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
1321  }
1322 
1323  /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
1324  if (audio_glue0_res == AST_RTP_GLUE_RESULT_FORBID || audio_glue1_res == AST_RTP_GLUE_RESULT_FORBID) {
1326  goto done;
1327  }
1328 
1329 
1330  /* If address families differ, force a local bridge */
1331  ast_rtp_instance_get_remote_address(instance0, &addr1);
1332  ast_rtp_instance_get_remote_address(instance1, &addr2);
1333 
1334  if (addr1.ss.ss_family != addr2.ss.ss_family ||
1336  audio_glue0_res = AST_RTP_GLUE_RESULT_LOCAL;
1337  audio_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
1338  }
1339 
1340  /* If we need to get DTMF see if we can do it outside of the RTP stream itself */
1341  dmode = ast_rtp_instance_dtmf_mode_get(instance0);
1342  if ((flags & AST_BRIDGE_DTMF_CHANNEL_0) && dmode) {
1344  goto done;
1345  }
1346  dmode = ast_rtp_instance_dtmf_mode_get(instance1);
1347  if ((flags & AST_BRIDGE_DTMF_CHANNEL_1) && dmode) {
1349  goto done;
1350  }
1351 
1352  /* If we have gotten to a local bridge make sure that both sides have the same local bridge callback and that they are DTMF compatible */
1353  if ((audio_glue0_res == AST_RTP_GLUE_RESULT_LOCAL || audio_glue1_res == AST_RTP_GLUE_RESULT_LOCAL) && ((instance0->engine->local_bridge != instance1->engine->local_bridge) || (instance0->engine->dtmf_compatible && !instance0->engine->dtmf_compatible(c0, instance0, c1, instance1)))) {
1355  goto done;
1356  }
1357 
1358  /* Make sure that codecs match */
1359  codec0 = glue0->get_codec ? glue0->get_codec(c0) : 0;
1360  codec1 = glue1->get_codec ? glue1->get_codec(c1) : 0;
1361  if (codec0 && codec1 && !(codec0 & codec1)) {
1362  ast_debug(1, "Channel codec0 = %s is not codec1 = %s, cannot native bridge in RTP.\n", ast_getformatname(codec0), ast_getformatname(codec1));
1364  goto done;
1365  }
1366 
1367  read_ptime0 = (ast_codec_pref_getsize(&instance0->codecs.pref, c0->rawreadformat)).cur_ms;
1368  read_ptime1 = (ast_codec_pref_getsize(&instance1->codecs.pref, c1->rawreadformat)).cur_ms;
1369  write_ptime0 = (ast_codec_pref_getsize(&instance0->codecs.pref, c0->rawwriteformat)).cur_ms;
1370  write_ptime1 = (ast_codec_pref_getsize(&instance1->codecs.pref, c1->rawwriteformat)).cur_ms;
1371 
1372  if (read_ptime0 != write_ptime1 || read_ptime1 != write_ptime0) {
1373  ast_debug(1, "Packetization differs between RTP streams (%d != %d or %d != %d). Cannot native bridge in RTP\n",
1374  read_ptime0, write_ptime1, read_ptime1, write_ptime0);
1376  goto done;
1377  }
1378 
1379  instance0->glue = glue0;
1380  instance1->glue = glue1;
1381  instance0->chan = c0;
1382  instance1->chan = c1;
1383 
1384  /* Depending on the end result for bridging either do a local bridge or remote bridge */
1385  if (audio_glue0_res == AST_RTP_GLUE_RESULT_LOCAL || audio_glue1_res == AST_RTP_GLUE_RESULT_LOCAL) {
1386  ast_verb(3, "Locally bridging %s and %s\n", c0->name, c1->name);
1387  res = local_bridge_loop(c0, c1, instance0, instance1, timeoutms, flags, fo, rc, c0->tech_pvt, c1->tech_pvt);
1388  } else {
1389  ast_verb(3, "Remotely bridging %s and %s\n", c0->name, c1->name);
1390  res = remote_bridge_loop(c0, c1, instance0, instance1, vinstance0, vinstance1,
1391  tinstance0, tinstance1, glue0, glue1, codec0, codec1, timeoutms, flags,
1392  fo, rc, c0->tech_pvt, c1->tech_pvt);
1393  }
1394 
1395  instance0->glue = NULL;
1396  instance1->glue = NULL;
1397  instance0->chan = NULL;
1398  instance1->chan = NULL;
1399 
1400  unlock_chans = 0;
1401 
1402 done:
1403  if (unlock_chans) {
1404  ast_channel_unlock(c0);
1405  ast_channel_unlock(c1);
1406  }
1407 
1408  unref_instance_cond(&instance0);
1409  unref_instance_cond(&instance1);
1410  unref_instance_cond(&vinstance0);
1411  unref_instance_cond(&vinstance1);
1412  unref_instance_cond(&tinstance0);
1413  unref_instance_cond(&tinstance1);
1414 
1415  return res;
1416 }
struct ast_codec_pref pref
Definition: rtp_engine.h:387
struct sockaddr_storage ss
Definition: netsock2.h:64
#define ast_channel_lock(chan)
Definition: channel.h:2466
static void unref_instance_cond(struct ast_rtp_instance **instance)
Conditionally unref an rtp instance.
Definition: rtp_engine.c:1266
const char *const type
Definition: channel.h:508
void * tech_pvt
Definition: channel.h:744
#define LOG_WARNING
Definition: logger.h:144
format_t rawwriteformat
Definition: channel.h:856
int(* dtmf_compatible)(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1)
Definition: rtp_engine.h:371
format_t rawreadformat
Definition: channel.h:855
Socket address structure.
Definition: netsock2.h:63
#define ast_verb(level,...)
Definition: logger.h:243
struct ast_format_list ast_codec_pref_getsize(struct ast_codec_pref *pref, format_t format)
Get packet size for codec.
Definition: frame.c:1205
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
enum ast_rtp_glue_result(* get_vrtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance)
Callback for retrieving the RTP instance carrying video.
Definition: rtp_engine.h:407
struct ast_rtp_glue * glue
Definition: rtp_engine.c:76
#define AST_BRIDGE_DTMF_CHANNEL_1
Report DTMF on channel 1.
Definition: channel.h:1934
struct ast_channel * chan
Definition: rtp_engine.c:78
ast_rtp_glue_result
Definition: rtp_engine.h:125
int ast_check_hangup(struct ast_channel *chan)
Check to see if a channel is needing hang up.
Definition: channel.c:806
char * ast_getformatname(format_t format)
Get the name of a format.
Definition: frame.c:578
int(* local_bridge)(struct ast_rtp_instance *instance0, struct ast_rtp_instance *instance1)
Definition: rtp_engine.h:363
int64_t format_t
Definition: frame_defs.h:32
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
void ast_rtp_instance_get_remote_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address)
Get the address of the remote endpoint that we are sending RTP to.
Definition: rtp_engine.c:447
int ast_sockaddr_is_ipv4_mapped(const struct ast_sockaddr *addr)
Determine if this is an IPv4-mapped IPv6 address.
Definition: netsock2.c:406
ast_rtp_dtmf_mode
Definition: rtp_engine.h:115
format_t(* get_codec)(struct ast_channel *chan)
Definition: rtp_engine.h:418
static enum ast_bridge_result remote_bridge_loop(struct ast_channel *c0, struct ast_channel *c1, struct ast_rtp_instance *instance0, struct ast_rtp_instance *instance1, struct ast_rtp_instance *vinstance0, struct ast_rtp_instance *vinstance1, struct ast_rtp_instance *tinstance0, struct ast_rtp_instance *tinstance1, struct ast_rtp_glue *glue0, struct ast_rtp_glue *glue1, format_t codec0, format_t codec1, int timeoutms, int flags, struct ast_frame **fo, struct ast_channel **rc, void *pvt0, void *pvt1)
Definition: rtp_engine.c:981
enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get(struct ast_rtp_instance *instance)
Get the DTMF mode of an RTP instance.
Definition: rtp_engine.c:755
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
static enum ast_bridge_result local_bridge_loop(struct ast_channel *c0, struct ast_channel *c1, struct ast_rtp_instance *instance0, struct ast_rtp_instance *instance1, int timeoutms, int flags, struct ast_frame **fo, struct ast_channel **rc, void *pvt0, void *pvt1)
Definition: rtp_engine.c:808
#define ast_channel_trylock(chan)
Definition: channel.h:2468
struct ast_rtp_glue * ast_rtp_instance_get_glue(const char *type)
Get the RTP glue that binds a channel to the RTP engine.
Definition: rtp_engine.c:791
struct ast_channel_tech * tech
Definition: channel.h:743
#define AST_BRIDGE_DTMF_CHANNEL_0
Report DTMF on channel 0.
Definition: channel.h:1932
struct ast_rtp_codecs codecs
Definition: rtp_engine.c:68
ast_bridge_result
Definition: channel.h:168
enum ast_rtp_glue_result(* get_rtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance)
Callback for retrieving the RTP instance carrying audio.
Definition: rtp_engine.h:402
void ast_rtp_instance_change_source ( struct ast_rtp_instance instance)

Indicate a new source of audio has dropped in and the ssrc should change.

Parameters
instanceInstance that the new media source is feeding into

Example usage:

This indicates that the source of media that is feeding the instance pointed to by instance has changed and that the marker bit should be set and the SSRC updated.

Since
1.8

Definition at line 767 of file rtp_engine.c.

References ast_rtp_engine::change_source, and ast_rtp_instance::engine.

Referenced by mgcp_indicate(), oh323_indicate(), sip_indicate(), and skinny_indicate().

768 {
769  if (instance->engine->change_source) {
770  instance->engine->change_source(instance);
771  }
772 }
void(* change_source)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:331
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
int ast_rtp_instance_destroy ( struct ast_rtp_instance instance)

Destroy an RTP instance.

Parameters
instanceThe RTP instance to destroy
Return values
0success
-1failure

Example usage:

*

This destroys the RTP instance pointed to by instance. Once this function returns instance no longer points to valid memory and may not be used again.

Since
1.8

Definition at line 301 of file rtp_engine.c.

References ao2_ref.

Referenced by __oh323_destroy(), __sip_destroy(), cleanup_connection(), destroy_endpoint(), gtalk_free_pvt(), jingle_free_pvt(), mgcp_hangup(), multicast_rtp_hangup(), multicast_rtp_request(), oh323_alloc(), skinny_hangup(), start_rtp(), unalloc_sub(), and unistim_hangup().

302 {
303  ao2_ref(instance, -1);
304 
305  return 0;
306 }
#define ao2_ref(o, delta)
Definition: astobj2.h:472
int ast_rtp_instance_dtmf_begin ( struct ast_rtp_instance instance,
char  digit 
)

Begin sending a DTMF digit.

Parameters
instanceThe RTP instance to send the DTMF on
digitWhat DTMF digit to send
Return values
0success
-1failure

Example usage:

* ast_rtp_instance_dtmf_begin(instance, '1');
*

This starts sending the DTMF '1' on the RTP instance pointed to by instance. It will continue being sent until it is ended.

Since
1.8

Definition at line 736 of file rtp_engine.c.

References ast_rtp_engine::dtmf_begin, and ast_rtp_instance::engine.

Referenced by gtalk_digit_begin(), mgcp_senddigit_begin(), oh323_digit_begin(), and sip_senddigit_begin().

737 {
738  return instance->engine->dtmf_begin ? instance->engine->dtmf_begin(instance, digit) : -1;
739 }
int(* dtmf_begin)(struct ast_rtp_instance *instance, char digit)
Definition: rtp_engine.h:324
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
int ast_rtp_instance_dtmf_end ( struct ast_rtp_instance instance,
char  digit 
)

Stop sending a DTMF digit.

Parameters
instanceThe RTP instance to stop the DTMF on
digitWhat DTMF digit to stop
Return values
0success
-1failure

Example usage:

* ast_rtp_instance_dtmf_end(instance, '1');
*

This stops sending the DTMF '1' on the RTP instance pointed to by instance.

Since
1.8

Definition at line 741 of file rtp_engine.c.

References ast_rtp_engine::dtmf_end, and ast_rtp_instance::engine.

Referenced by mgcp_senddigit_end(), and oh323_digit_end().

742 {
743  return instance->engine->dtmf_end ? instance->engine->dtmf_end(instance, digit) : -1;
744 }
int(* dtmf_end)(struct ast_rtp_instance *instance, char digit)
Definition: rtp_engine.h:326
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
int ast_rtp_instance_dtmf_end_with_duration ( struct ast_rtp_instance instance,
char  digit,
unsigned int  duration 
)

Definition at line 745 of file rtp_engine.c.

References ast_rtp_engine::dtmf_end_with_duration, and ast_rtp_instance::engine.

Referenced by gtalk_digit_end(), and sip_senddigit_end().

746 {
747  return instance->engine->dtmf_end_with_duration ? instance->engine->dtmf_end_with_duration(instance, digit, duration) : -1;
748 }
int(* dtmf_end_with_duration)(struct ast_rtp_instance *instance, char digit, unsigned int duration)
Definition: rtp_engine.h:327
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get ( struct ast_rtp_instance instance)

Get the DTMF mode of an RTP instance.

Parameters
instanceThe RTP instance to get the DTMF mode of
Return values
DTMFmode

Example usage:

*

This gets the DTMF mode set on the RTP instance pointed to by 'instance'.

Since
1.8

Definition at line 755 of file rtp_engine.c.

References ast_rtp_engine::dtmf_mode_get, and ast_rtp_instance::engine.

Referenced by ast_rtp_instance_bridge().

756 {
757  return instance->engine->dtmf_mode_get ? instance->engine->dtmf_mode_get(instance) : 0;
758 }
enum ast_rtp_dtmf_mode(* dtmf_mode_get)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:349
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
int ast_rtp_instance_dtmf_mode_set ( struct ast_rtp_instance instance,
enum ast_rtp_dtmf_mode  dtmf_mode 
)

Set the DTMF mode that should be used.

Parameters
instancethe RTP instance to set DTMF mode on
dtmf_modeThe DTMF mode that is in use
Return values
0success
-1failure

Example usage:

This sets the RTP instance to use RFC2833 for DTMF transmission and receiving.

Since
1.8

Definition at line 750 of file rtp_engine.c.

References ast_rtp_engine::dtmf_mode_set, and ast_rtp_instance::engine.

Referenced by enable_dsp_detect(), gtalk_alloc(), and sip_new().

751 {
752  return (!instance->engine->dtmf_mode_set || instance->engine->dtmf_mode_set(instance, dtmf_mode)) ? -1 : 0;
753 }
int(* dtmf_mode_set)(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode)
Definition: rtp_engine.h:347
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
int ast_rtp_instance_early_bridge ( struct ast_channel c0,
struct ast_channel c1 
)

Early bridge two channels that use RTP instances.

Parameters
c0First channel part of the bridge
c1Second channel part of the bridge
Return values
0success
-1failure
Note
This should only be used by channel drivers in their technology declaration.
Since
1.8

Definition at line 1509 of file rtp_engine.c.

References ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_debug, ast_log(), AST_RTP_GLUE_RESULT_FORBID, AST_RTP_GLUE_RESULT_REMOTE, ast_rtp_instance_get_glue(), ast_rtp_glue::get_codec, ast_rtp_glue::get_rtp_info, ast_rtp_glue::get_vrtp_info, LOG_WARNING, ast_channel::name, ast_channel::tech, ast_channel_tech::type, unref_instance_cond(), and ast_rtp_glue::update_peer.

1510 {
1511  struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
1512  *vinstance0 = NULL, *vinstance1 = NULL,
1513  *tinstance0 = NULL, *tinstance1 = NULL;
1514  struct ast_rtp_glue *glue0, *glue1;
1515  enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
1516  enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
1517  format_t codec0 = 0, codec1 = 0;
1518  int res = 0;
1519 
1520  /* If there is no second channel just immediately bail out, we are of no use in that scenario */
1521  if (!c1) {
1522  return -1;
1523  }
1524 
1525  /* Lock both channels so we can look for the glue that binds them together */
1526  ast_channel_lock(c0);
1527  while (ast_channel_trylock(c1)) {
1528  ast_channel_unlock(c0);
1529  usleep(1);
1530  ast_channel_lock(c0);
1531  }
1532 
1533  /* Grab glue that binds each channel to something using the RTP engine */
1534  if (!(glue0 = ast_rtp_instance_get_glue(c0->tech->type)) || !(glue1 = ast_rtp_instance_get_glue(c1->tech->type))) {
1535  ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", glue0 ? c1->name : c0->name);
1536  goto done;
1537  }
1538 
1539  audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
1540  video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;
1541 
1542  audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
1543  video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;
1544 
1545  /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
1546  if (video_glue0_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue0_res != AST_RTP_GLUE_RESULT_REMOTE)) {
1547  audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
1548  }
1549  if (video_glue1_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue1_res != AST_RTP_GLUE_RESULT_REMOTE)) {
1550  audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
1551  }
1552  if (audio_glue0_res == AST_RTP_GLUE_RESULT_REMOTE && (video_glue0_res == AST_RTP_GLUE_RESULT_FORBID || video_glue0_res == AST_RTP_GLUE_RESULT_REMOTE) && glue0->get_codec(c0)) {
1553  codec0 = glue0->get_codec(c0);
1554  }
1555  if (audio_glue1_res == AST_RTP_GLUE_RESULT_REMOTE && (video_glue1_res == AST_RTP_GLUE_RESULT_FORBID || video_glue1_res == AST_RTP_GLUE_RESULT_REMOTE) && glue1->get_codec(c1)) {
1556  codec1 = glue1->get_codec(c1);
1557  }
1558 
1559  /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
1560  if (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE) {
1561  goto done;
1562  }
1563 
1564  /* Make sure we have matching codecs */
1565  if (!(codec0 & codec1)) {
1566  goto done;
1567  }
1568 
1569  /* Bridge media early */
1570  if (glue0->update_peer(c0, instance1, vinstance1, tinstance1, codec1, 0)) {
1571  ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", c0->name, c1 ? c1->name : "<unspecified>");
1572  }
1573 
1574  res = 0;
1575 
1576 done:
1577  ast_channel_unlock(c0);
1578  ast_channel_unlock(c1);
1579 
1580  unref_instance_cond(&instance0);
1581  unref_instance_cond(&instance1);
1582  unref_instance_cond(&vinstance0);
1583  unref_instance_cond(&vinstance1);
1584  unref_instance_cond(&tinstance0);
1585  unref_instance_cond(&tinstance1);
1586 
1587  if (!res) {
1588  ast_debug(1, "Setting early bridge SDP of '%s' with that of '%s'\n", c0->name, c1 ? c1->name : "<unspecified>");
1589  }
1590 
1591  return res;
1592 }
#define ast_channel_lock(chan)
Definition: channel.h:2466
static void unref_instance_cond(struct ast_rtp_instance **instance)
Conditionally unref an rtp instance.
Definition: rtp_engine.c:1266
const char *const type
Definition: channel.h:508
#define LOG_WARNING
Definition: logger.h:144
int(* update_peer)(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, format_t codecs, int nat_active)
Definition: rtp_engine.h:414
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
enum ast_rtp_glue_result(* get_vrtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance)
Callback for retrieving the RTP instance carrying video.
Definition: rtp_engine.h:407
ast_rtp_glue_result
Definition: rtp_engine.h:125
int64_t format_t
Definition: frame_defs.h:32
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
format_t(* get_codec)(struct ast_channel *chan)
Definition: rtp_engine.h:418
#define ast_channel_trylock(chan)
Definition: channel.h:2468
struct ast_rtp_glue * ast_rtp_instance_get_glue(const char *type)
Get the RTP glue that binds a channel to the RTP engine.
Definition: rtp_engine.c:791
struct ast_channel_tech * tech
Definition: channel.h:743
enum ast_rtp_glue_result(* get_rtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance)
Callback for retrieving the RTP instance carrying audio.
Definition: rtp_engine.h:402
void ast_rtp_instance_early_bridge_make_compatible ( struct ast_channel c_dst,
struct ast_channel c_src 
)

Make two channels compatible for early bridging.

Parameters
c_dstDestination channel to copy to
c_srcSource channel to copy from
Since
1.8

Definition at line 1423 of file rtp_engine.c.

References ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_debug, ast_log(), ast_rtp_codecs_payloads_copy(), AST_RTP_GLUE_RESULT_FORBID, AST_RTP_GLUE_RESULT_REMOTE, ast_rtp_instance_get_glue(), ast_rtp_instance::codecs, ast_rtp_glue::get_codec, ast_rtp_glue::get_rtp_info, ast_rtp_glue::get_vrtp_info, LOG_WARNING, ast_channel::name, ast_channel::tech, ast_channel_tech::type, unref_instance_cond(), and ast_rtp_glue::update_peer.

Referenced by dial_exec_full(), and do_forward().

1424 {
1425  struct ast_rtp_instance *instance_dst = NULL, *instance_src = NULL,
1426  *vinstance_dst = NULL, *vinstance_src = NULL,
1427  *tinstance_dst = NULL, *tinstance_src = NULL;
1428  struct ast_rtp_glue *glue_dst, *glue_src;
1429  enum ast_rtp_glue_result audio_glue_dst_res = AST_RTP_GLUE_RESULT_FORBID, video_glue_dst_res = AST_RTP_GLUE_RESULT_FORBID;
1430  enum ast_rtp_glue_result audio_glue_src_res = AST_RTP_GLUE_RESULT_FORBID, video_glue_src_res = AST_RTP_GLUE_RESULT_FORBID;
1431  format_t codec_dst = 0, codec_src = 0;
1432  int res = 0;
1433 
1434  /* Lock both channels so we can look for the glue that binds them together */
1435  ast_channel_lock(c_dst);
1436  while (ast_channel_trylock(c_src)) {
1437  ast_channel_unlock(c_dst);
1438  usleep(1);
1439  ast_channel_lock(c_dst);
1440  }
1441 
1442  /* Grab glue that binds each channel to something using the RTP engine */
1443  if (!(glue_dst = ast_rtp_instance_get_glue(c_dst->tech->type)) || !(glue_src = ast_rtp_instance_get_glue(c_src->tech->type))) {
1444  ast_debug(1, "Can't find native functions for channel '%s'\n", glue_dst ? c_src->name : c_dst->name);
1445  goto done;
1446  }
1447 
1448  audio_glue_dst_res = glue_dst->get_rtp_info(c_dst, &instance_dst);
1449  video_glue_dst_res = glue_dst->get_vrtp_info ? glue_dst->get_vrtp_info(c_dst, &vinstance_dst) : AST_RTP_GLUE_RESULT_FORBID;
1450 
1451  audio_glue_src_res = glue_src->get_rtp_info(c_src, &instance_src);
1452  video_glue_src_res = glue_src->get_vrtp_info ? glue_src->get_vrtp_info(c_src, &vinstance_src) : AST_RTP_GLUE_RESULT_FORBID;
1453 
1454  /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
1455  if (video_glue_dst_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue_dst_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue_dst_res != AST_RTP_GLUE_RESULT_REMOTE)) {
1456  audio_glue_dst_res = AST_RTP_GLUE_RESULT_FORBID;
1457  }
1458  if (video_glue_src_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue_src_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue_src_res != AST_RTP_GLUE_RESULT_REMOTE)) {
1459  audio_glue_src_res = AST_RTP_GLUE_RESULT_FORBID;
1460  }
1461  if (audio_glue_dst_res == AST_RTP_GLUE_RESULT_REMOTE && (video_glue_dst_res == AST_RTP_GLUE_RESULT_FORBID || video_glue_dst_res == AST_RTP_GLUE_RESULT_REMOTE) && glue_dst->get_codec) {
1462  codec_dst = glue_dst->get_codec(c_dst);
1463  }
1464  if (audio_glue_src_res == AST_RTP_GLUE_RESULT_REMOTE && (video_glue_src_res == AST_RTP_GLUE_RESULT_FORBID || video_glue_src_res == AST_RTP_GLUE_RESULT_REMOTE) && glue_src->get_codec) {
1465  codec_src = glue_src->get_codec(c_src);
1466  }
1467 
1468  /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
1469  if (audio_glue_dst_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue_src_res != AST_RTP_GLUE_RESULT_REMOTE) {
1470  goto done;
1471  }
1472 
1473  /* Make sure we have matching codecs */
1474  if (!(codec_dst & codec_src)) {
1475  goto done;
1476  }
1477 
1478  ast_rtp_codecs_payloads_copy(&instance_src->codecs, &instance_dst->codecs, instance_dst);
1479 
1480  if (vinstance_dst && vinstance_src) {
1481  ast_rtp_codecs_payloads_copy(&vinstance_src->codecs, &vinstance_dst->codecs, vinstance_dst);
1482  }
1483  if (tinstance_dst && tinstance_src) {
1484  ast_rtp_codecs_payloads_copy(&tinstance_src->codecs, &tinstance_dst->codecs, tinstance_dst);
1485  }
1486 
1487  if (glue_dst->update_peer(c_dst, instance_src, vinstance_src, tinstance_src, codec_src, 0)) {
1488  ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", c_dst->name, c_src ? c_src->name : "<unspecified>");
1489  }
1490 
1491  res = 0;
1492 
1493 done:
1494  ast_channel_unlock(c_dst);
1495  ast_channel_unlock(c_src);
1496 
1497  unref_instance_cond(&instance_dst);
1498  unref_instance_cond(&instance_src);
1499  unref_instance_cond(&vinstance_dst);
1500  unref_instance_cond(&vinstance_src);
1501  unref_instance_cond(&tinstance_dst);
1502  unref_instance_cond(&tinstance_src);
1503 
1504  if (!res) {
1505  ast_debug(1, "Seeded SDP of '%s' with that of '%s'\n", c_dst->name, c_src ? c_src->name : "<unspecified>");
1506  }
1507 }
#define ast_channel_lock(chan)
Definition: channel.h:2466
static void unref_instance_cond(struct ast_rtp_instance **instance)
Conditionally unref an rtp instance.
Definition: rtp_engine.c:1266
const char *const type
Definition: channel.h:508
#define LOG_WARNING
Definition: logger.h:144
int(* update_peer)(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, format_t codecs, int nat_active)
Definition: rtp_engine.h:414
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
enum ast_rtp_glue_result(* get_vrtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance)
Callback for retrieving the RTP instance carrying video.
Definition: rtp_engine.h:407
ast_rtp_glue_result
Definition: rtp_engine.h:125
int64_t format_t
Definition: frame_defs.h:32
const ast_string_field name
Definition: channel.h:787
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
Copy payload information from one RTP instance to another.
Definition: rtp_engine.c:516
format_t(* get_codec)(struct ast_channel *chan)
Definition: rtp_engine.h:418
#define ast_channel_trylock(chan)
Definition: channel.h:2468
struct ast_rtp_glue * ast_rtp_instance_get_glue(const char *type)
Get the RTP glue that binds a channel to the RTP engine.
Definition: rtp_engine.c:791
struct ast_channel_tech * tech
Definition: channel.h:743
struct ast_rtp_codecs codecs
Definition: rtp_engine.c:68
enum ast_rtp_glue_result(* get_rtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance)
Callback for retrieving the RTP instance carrying audio.
Definition: rtp_engine.h:402
int ast_rtp_instance_fd ( struct ast_rtp_instance instance,
int  rtcp 
)

Get the file descriptor for an RTP session (or RTCP)

Parameters
instanceInstance to get the file descriptor for
rtcpWhether to retrieve the file descriptor for RTCP or not
Return values
fdsuccess
-1failure

Example usage:

* int rtp_fd = ast_rtp_instance_fd(instance, 0);
*

This retrieves the file descriptor for the socket carrying media on the instance pointed to by instance.

Since
1.8

Definition at line 786 of file rtp_engine.c.

References ast_rtp_instance::engine, and ast_rtp_engine::fd.

Referenced by __oh323_new(), __oh323_rtp_create(), __oh323_update_info(), gtalk_new(), jingle_new(), mgcp_new(), process_sdp(), sip_new(), sip_set_rtp_peer(), skinny_new(), start_rtp(), and unistim_new().

787 {
788  return instance->engine->fd ? instance->engine->fd(instance, rtcp) : -1;
789 }
int(* fd)(struct ast_rtp_instance *instance, int rtcp)
Definition: rtp_engine.h:355
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
struct ast_rtp_glue* ast_rtp_instance_get_active_glue ( struct ast_rtp_instance instance)

Get the RTP glue in use on an RTP instance.

Parameters
instanceThe RTP instance
Return values
pointerto the glue

Example:

*

This gets the RTP glue currently in use on the RTP instance pointed to by 'instance'.

Since
1.8

Definition at line 1793 of file rtp_engine.c.

References ast_rtp_instance::glue.

1794 {
1795  return instance->glue;
1796 }
struct ast_rtp_glue * glue
Definition: rtp_engine.c:76
int ast_rtp_instance_get_and_cmp_local_address ( struct ast_rtp_instance instance,
struct ast_sockaddr address 
)

Get the address of the local endpoint that we are sending RTP to, comparing its address to another.

Parameters
instanceThe instance that we want to get the local address for
addressAn initialized address that may be overwritten if the local address is different
Return values
0address was not changed
1address was changed Example usage:
* struct ast_sockaddr address;
* int ret;
* ret = ast_rtp_instance_get_and_cmp_local_address(instance, &address);
*

This retrieves the current local address set on the instance pointed to by instance and puts the value into the address structure.

Since
1.8

Definition at line 419 of file rtp_engine.c.

References ast_sockaddr_cmp(), ast_sockaddr_copy(), and ast_rtp_instance::local_address.

421 {
422  if (ast_sockaddr_cmp(address, &instance->local_address) != 0) {
423  ast_sockaddr_copy(address, &instance->local_address);
424  return 1;
425  }
426 
427  return 0;
428 }
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:121
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
Definition: netsock2.c:300
struct ast_sockaddr local_address
Definition: rtp_engine.c:60
int ast_rtp_instance_get_and_cmp_remote_address ( struct ast_rtp_instance instance,
struct ast_sockaddr address 
)

Get the address of the remote endpoint that we are sending RTP to, comparing its address to another.

Parameters
instanceThe instance that we want to get the remote address for
addressAn initialized address that may be overwritten if the remote address is different
Return values
0address was not changed
1address was changed Example usage:
* struct ast_sockaddr address;
* int ret;
* ret = ast_rtp_instance_get_and_cmp_remote_address(instance, &address);
*

This retrieves the current remote address set on the instance pointed to by instance and puts the value into the address structure.

Since
1.8

Definition at line 436 of file rtp_engine.c.

References ast_sockaddr_cmp(), ast_sockaddr_copy(), and ast_rtp_instance::remote_address.

Referenced by sip_set_rtp_peer().

438 {
439  if (ast_sockaddr_cmp(address, &instance->remote_address) != 0) {
440  ast_sockaddr_copy(address, &instance->remote_address);
441  return 1;
442  }
443 
444  return 0;
445 }
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:121
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
Definition: netsock2.c:300
struct ast_sockaddr remote_address
Definition: rtp_engine.c:62
struct ast_rtp_instance* ast_rtp_instance_get_bridged ( struct ast_rtp_instance instance)

Get the other RTP instance that an instance is bridged to.

Parameters
instanceThe RTP instance that we want
Return values
non-NULLsuccess
NULLfailure

Example usage:

This gets the RTP instance that instance0 is bridged to.

Since
1.8

Definition at line 1418 of file rtp_engine.c.

References ast_rtp_instance::bridged.

Referenced by ast_rtp_read(), bridge_p2p_rtp_write(), and dialog_needdestroy().

1419 {
1420  return instance->bridged;
1421 }
struct ast_rtp_instance * bridged
Definition: rtp_engine.c:66
struct ast_channel* ast_rtp_instance_get_chan ( struct ast_rtp_instance instance)

Get the channel that is associated with an RTP instance while in a bridge.

Parameters
instanceThe RTP instance
Return values
pointerto the channel

Example:

* struct ast_channel *chan = ast_rtp_instance_get_chan(instance);
*

This gets the channel associated with the RTP instance pointed to by 'instance'.

Note
This will only return a channel while in a local or remote bridge.
Since
1.8

Definition at line 1798 of file rtp_engine.c.

References ast_rtp_instance::chan.

1799 {
1800  return instance->chan;
1801 }
struct ast_channel * chan
Definition: rtp_engine.c:78
struct ast_rtp_codecs* ast_rtp_instance_get_codecs ( struct ast_rtp_instance instance)

Get the codecs structure of an RTP instance.

Parameters
instanceThe RTP instance to get the codecs structure from

Example usage:

* struct ast_rtp_codecs *codecs = ast_rtp_instance_get_codecs(instance);
*

This gets the codecs structure on the RTP instance pointed to by 'instance'.

Since
1.8

Definition at line 483 of file rtp_engine.c.

References ast_rtp_instance::codecs.

Referenced by __oh323_rtp_create(), add_codec_to_sdp(), add_noncodec_to_sdp(), add_sdp(), add_tcodec_to_sdp(), add_vcodec_to_sdp(), ast_rtp_dtmf_begin(), ast_rtp_read(), ast_rtp_sendcng(), ast_rtp_write(), bridge_p2p_rtp_write(), check_peer_ok(), create_addr_from_peer(), gtalk_alloc(), gtalk_is_answered(), gtalk_new(), gtalk_newcall(), jingle_new(), jingle_newcall(), multicast_rtp_write(), process_sdp(), process_sdp_a_audio(), set_dtmf_payload(), set_peer_capabilities(), setup_rtp_connection(), start_rtp(), and transmit_response_with_sdp().

484 {
485  return &instance->codecs;
486 }
struct ast_rtp_codecs codecs
Definition: rtp_engine.c:68
struct ast_rtp_engine* ast_rtp_instance_get_engine ( struct ast_rtp_instance instance)

Get the RTP engine in use on an RTP instance.

Parameters
instanceThe RTP instance
Return values
pointerto the engine

Example usage:

* struct ast_rtp_engine *engine = ast_rtp_instance_get_engine(instance);
*

This gets the RTP engine currently in use on the RTP instance pointed to by 'instance'.

Since
1.8

Definition at line 1788 of file rtp_engine.c.

References ast_rtp_instance::engine.

1789 {
1790  return instance->engine;
1791 }
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
void* ast_rtp_instance_get_extended_prop ( struct ast_rtp_instance instance,
int  property 
)

Get the value of an RTP instance extended property.

Parameters
instanceThe RTP instance to get the extended property on
propertyThe extended property to get
Since
1.8

Definition at line 460 of file rtp_engine.c.

References ast_rtp_instance::engine, and ast_rtp_engine::extended_prop_get.

461 {
462  if (instance->engine->extended_prop_get) {
463  return instance->engine->extended_prop_get(instance, property);
464  }
465 
466  return NULL;
467 }
void *(* extended_prop_get)(struct ast_rtp_instance *instance, int property)
Definition: rtp_engine.h:335
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
struct ast_rtp_glue* ast_rtp_instance_get_glue ( const char *  type)

Get the RTP glue that binds a channel to the RTP engine.

Parameters
typeName of the glue we want
Return values
non-NULLsuccess
NULLfailure

Example usage:

* struct ast_rtp_glue *glue = ast_rtp_instance_get_glue("Example");
*

This retrieves the RTP glue that has the name 'Example'.

Since
1.8

Definition at line 791 of file rtp_engine.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, and ast_rtp_glue::type.

Referenced by ast_rtp_instance_bridge(), ast_rtp_instance_early_bridge(), ast_rtp_instance_early_bridge_make_compatible(), ast_rtp_instance_make_compatible(), and remote_bridge_loop().

792 {
793  struct ast_rtp_glue *glue = NULL;
794 
796 
797  AST_RWLIST_TRAVERSE(&glues, glue, entry) {
798  if (!strcasecmp(glue->type, type)) {
799  break;
800  }
801  }
802 
804 
805  return glue;
806 }
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
const char * type
Definition: rtp_engine.h:395
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
static const char type[]
Definition: chan_nbs.c:57
int ast_rtp_instance_get_hold_timeout ( struct ast_rtp_instance instance)

Get the RTP timeout value for when an RTP instance is on hold.

Parameters
instanceThe RTP instance
Return values
timeoutvalue

Example usage:

* int timeout = ast_rtp_instance_get_hold_timeout(instance);
*

This gets the RTP hold timeout value for the RTP instance pointed to by 'instance'.

Since
1.8

Definition at line 1778 of file rtp_engine.c.

References ast_rtp_instance::holdtimeout.

Referenced by check_rtp_timeout().

1779 {
1780  return instance->holdtimeout;
1781 }
int ast_rtp_instance_get_keepalive ( struct ast_rtp_instance instance)

Get the RTP keepalive interval.

Parameters
instanceThe RTP instance
Return values
periodKeepalive interval value

Example usage:

* int interval = ast_rtp_instance_get_keepalive(instance);
*

This gets the RTP keepalive interval value for the RTP instance pointed to by 'instance'.

Since
1.8

Definition at line 1783 of file rtp_engine.c.

References ast_rtp_instance::keepalive.

Referenced by check_rtp_timeout().

1784 {
1785  return instance->keepalive;
1786 }
void ast_rtp_instance_get_local_address ( struct ast_rtp_instance instance,
struct ast_sockaddr address 
)

Get the local address that we are expecting RTP on.

Parameters
instanceThe RTP instance to get the address from
addressThe variable to store the address in

Example usage:

* struct ast_sockaddr address;
* ast_rtp_instance_get_local_address(instance, &address);
*

This gets the local address that we are expecting RTP on and stores it in the 'address' structure.

Since
1.8

Definition at line 430 of file rtp_engine.c.

References ast_sockaddr_copy(), and ast_rtp_instance::local_address.

Referenced by add_sdp(), apply_directmedia_ha(), ast_rtp_prop_set(), external_rtp_create(), get_our_media_address(), gtalk_create_candidates(), handle_open_receive_channel_ack_message(), jingle_create_candidates(), multicast_send_control_packet(), oh323_set_rtp_peer(), sip_acf_channel_read(), skinny_set_rtp_peer(), start_rtp(), and unistim_set_rtp_peer().

432 {
433  ast_sockaddr_copy(address, &instance->local_address);
434 }
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:121
struct ast_sockaddr local_address
Definition: rtp_engine.c:60
int ast_rtp_instance_get_prop ( struct ast_rtp_instance instance,
enum ast_rtp_property  property 
)

Get the value of an RTP instance property.

Parameters
instanceThe RTP instance to get the property from
propertyThe property to get
Return values
Currentvalue of the property

Example usage:

This returns the current value of the NAT property on the instance pointed to by instance.

Since
1.8

Definition at line 478 of file rtp_engine.c.

References ast_rtp_instance::properties.

Referenced by ast_rtcp_read(), ast_rtp_dtmf_compatible(), ast_rtp_raw_write(), ast_rtp_read(), bridge_p2p_rtp_write(), process_dtmf_cisco(), and process_dtmf_rfc2833().

479 {
480  return instance->properties[property];
481 }
int properties[AST_RTP_PROPERTY_MAX]
Definition: rtp_engine.c:58
char* ast_rtp_instance_get_quality ( struct ast_rtp_instance instance,
enum ast_rtp_instance_stat_field  field,
char *  buf,
size_t  size 
)

Retrieve quality statistics about an RTP instance.

Parameters
instanceInstance to get statistics on
fieldWhat quality statistic to retrieve
bufWhat buffer to put the result into
sizeSize of the above buffer
Return values
non-NULLsuccess
NULLfailure

Example usage:

This retrieves general quality statistics and places a text representation into the buf pointed to by buf.

Since
1.8

Definition at line 1609 of file rtp_engine.c.

References ast_rtp_instance_get_stats(), AST_RTP_INSTANCE_STAT_ALL, AST_RTP_INSTANCE_STAT_COMBINED_JITTER, AST_RTP_INSTANCE_STAT_COMBINED_LOSS, AST_RTP_INSTANCE_STAT_COMBINED_RTT, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, ast_rtp_instance_stats::local_maxjitter, ast_rtp_instance_stats::local_maxrxploss, ast_rtp_instance_stats::local_minjitter, ast_rtp_instance_stats::local_minrxploss, ast_rtp_instance_stats::local_normdevjitter, ast_rtp_instance_stats::local_normdevrxploss, ast_rtp_instance_stats::local_ssrc, ast_rtp_instance_stats::local_stdevjitter, ast_rtp_instance_stats::local_stdevrxploss, ast_rtp_instance_stats::maxrtt, ast_rtp_instance_stats::minrtt, ast_rtp_instance_stats::normdevrtt, ast_rtp_instance_stats::remote_maxjitter, ast_rtp_instance_stats::remote_maxrxploss, ast_rtp_instance_stats::remote_minjitter, ast_rtp_instance_stats::remote_minrxploss, ast_rtp_instance_stats::remote_normdevjitter, ast_rtp_instance_stats::remote_normdevrxploss, ast_rtp_instance_stats::remote_ssrc, ast_rtp_instance_stats::remote_stdevjitter, ast_rtp_instance_stats::remote_stdevrxploss, ast_rtp_instance_stats::rtt, ast_rtp_instance_stats::rxcount, ast_rtp_instance_stats::rxjitter, ast_rtp_instance_stats::rxploss, ast_rtp_instance_stats::stdevrtt, ast_rtp_instance_stats::txcount, ast_rtp_instance_stats::txjitter, and ast_rtp_instance_stats::txploss.

Referenced by ast_rtp_instance_set_stats_vars(), handle_request_bye(), sip_acf_channel_read(), and sip_hangup().

1610 {
1611  struct ast_rtp_instance_stats stats = { 0, };
1612  enum ast_rtp_instance_stat stat;
1613 
1614  /* Determine what statistics we will need to retrieve based on field passed in */
1615  if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY) {
1617  } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
1619  } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
1621  } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
1623  } else {
1624  return NULL;
1625  }
1626 
1627  /* Attempt to actually retrieve the statistics we need to generate the quality string */
1628  if (ast_rtp_instance_get_stats(instance, &stats, stat)) {
1629  return NULL;
1630  }
1631 
1632  /* Now actually fill the buffer with the good information */
1633  if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY) {
1634  snprintf(buf, size, "ssrc=%u;themssrc=%u;lp=%u;rxjitter=%f;rxcount=%u;txjitter=%f;txcount=%u;rlp=%u;rtt=%f",
1635  stats.local_ssrc, stats.remote_ssrc, stats.rxploss, stats.rxjitter, stats.rxcount, stats.txjitter, stats.txcount, stats.txploss, stats.rtt);
1636  } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
1637  snprintf(buf, size, "minrxjitter=%f;maxrxjitter=%f;avgrxjitter=%f;stdevrxjitter=%f;reported_minjitter=%f;reported_maxjitter=%f;reported_avgjitter=%f;reported_stdevjitter=%f;",
1639  } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
1640  snprintf(buf, size, "minrxlost=%f;maxrxlost=%f;avgrxlost=%f;stdevrxlost=%f;reported_minlost=%f;reported_maxlost=%f;reported_avglost=%f;reported_stdevlost=%f;",
1642  } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
1643  snprintf(buf, size, "minrtt=%f;maxrtt=%f;avgrtt=%f;stdevrtt=%f;", stats.minrtt, stats.maxrtt, stats.normdevrtt, stats.stdevrtt);
1644  }
1645 
1646  return buf;
1647 }
int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
Retrieve statistics about an RTP instance.
Definition: rtp_engine.c:1604
unsigned int txcount
Definition: rtp_engine.h:237
unsigned int rxploss
Definition: rtp_engine.h:263
ast_rtp_instance_stat
Definition: rtp_engine.h:147
unsigned int rxcount
Definition: rtp_engine.h:239
unsigned int local_ssrc
Definition: rtp_engine.h:291
unsigned int txploss
Definition: rtp_engine.h:261
unsigned int remote_ssrc
Definition: rtp_engine.h:293
void ast_rtp_instance_get_remote_address ( struct ast_rtp_instance instance,
struct ast_sockaddr address 
)

Get the address of the remote endpoint that we are sending RTP to.

Parameters
instanceThe instance that we want to get the remote address for
addressA structure to put the address into

Example usage:

* struct ast_sockaddr address;
*

This retrieves the current remote address set on the instance pointed to by instance and puts the value into the address structure.

Since
1.8

Definition at line 447 of file rtp_engine.c.

References ast_sockaddr_copy(), and ast_rtp_instance::remote_address.

Referenced by add_sdp(), apply_directmedia_ha(), ast_rtp_dtmf_begin(), ast_rtp_dtmf_continuation(), ast_rtp_dtmf_end_with_duration(), ast_rtp_instance_bridge(), ast_rtp_raw_write(), ast_rtp_read(), ast_rtp_sendcng(), ast_rtp_write(), bridge_p2p_rtp_write(), create_dtmf_frame(), gtalk_update_stun(), handle_response_invite(), multicast_rtp_write(), multicast_send_control_packet(), oh323_set_rtp_peer(), process_cn_rfc3389(), process_dtmf_rfc2833(), process_sdp(), remote_bridge_loop(), sip_acf_channel_read(), skinny_set_rtp_peer(), transmit_modify_with_sdp(), and unistim_set_rtp_peer().

449 {
450  ast_sockaddr_copy(address, &instance->remote_address);
451 }
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:121
struct ast_sockaddr remote_address
Definition: rtp_engine.c:62
struct ast_srtp* ast_rtp_instance_get_srtp ( struct ast_rtp_instance instance)

Obtain the SRTP instance associated with an RTP instance.

Parameters
instancethe RTP instance
Return values
theSRTP instance on success
NULLif no SRTP instance exists

Definition at line 1849 of file rtp_engine.c.

References ast_rtp_instance::srtp.

Referenced by __rtp_recvfrom(), __rtp_sendto(), and ast_rtp_change_source().

1850 {
1851  return instance->srtp;
1852 }
struct ast_srtp * srtp
Definition: rtp_engine.c:80
int ast_rtp_instance_get_stats ( struct ast_rtp_instance instance,
struct ast_rtp_instance_stats stats,
enum ast_rtp_instance_stat  stat 
)

Retrieve statistics about an RTP instance.

Parameters
instanceInstance to get statistics on
statsStructure to put results into
statWhat statistic(s) to retrieve
Return values
0success
-1failure

Example usage:

This retrieves all statistics the underlying RTP engine supports and puts the values into the stats structure.

Since
1.8

Definition at line 1604 of file rtp_engine.c.

References ast_rtp_instance::engine, and ast_rtp_engine::get_stat.

Referenced by ast_rtp_instance_get_quality(), ast_srtp_unprotect(), sdp_crypto_activate(), show_chanstats_cb(), and sip_acf_channel_read().

1605 {
1606  return instance->engine->get_stat ? instance->engine->get_stat(instance, stats, stat) : -1;
1607 }
int(* get_stat)(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
Definition: rtp_engine.h:351
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
int ast_rtp_instance_get_timeout ( struct ast_rtp_instance instance)

Get the RTP timeout value.

Parameters
instanceThe RTP instance
Return values
timeoutvalue

Example usage:

* int timeout = ast_rtp_instance_get_timeout(instance);
*

This gets the RTP timeout value for the RTP instance pointed to by 'instance'.

Since
1.8

Definition at line 1773 of file rtp_engine.c.

References ast_rtp_instance::timeout.

Referenced by check_rtp_timeout().

1774 {
1775  return instance->timeout;
1776 }
int ast_rtp_instance_make_compatible ( struct ast_channel chan,
struct ast_rtp_instance instance,
struct ast_channel peer 
)

Request that the underlying RTP engine make two RTP instances compatible with eachother.

Parameters
chanOur own Asterisk channel
instanceThe first RTP instance
peerThe peer Asterisk channel
Return values
0success
-1failure

Example usage:

*

This makes the RTP instance for 'peer' compatible with 'instance' and vice versa.

Since
1.8

Definition at line 1693 of file rtp_engine.c.

References ao2_ref, ast_channel_lock, ast_channel_unlock, ast_log(), ast_rtp_instance_get_glue(), ast_rtp_instance::engine, ast_rtp_glue::get_rtp_info, LOG_ERROR, ast_rtp_engine::make_compatible, ast_channel::tech, ast_rtp_glue::type, and ast_channel_tech::type.

Referenced by sip_setoption().

1694 {
1695  struct ast_rtp_glue *glue;
1696  struct ast_rtp_instance *peer_instance = NULL;
1697  int res = -1;
1698 
1699  if (!instance->engine->make_compatible) {
1700  return -1;
1701  }
1702 
1703  ast_channel_lock(peer);
1704 
1705  if (!(glue = ast_rtp_instance_get_glue(peer->tech->type))) {
1706  ast_channel_unlock(peer);
1707  return -1;
1708  }
1709 
1710  glue->get_rtp_info(peer, &peer_instance);
1711  if (!peer_instance) {
1712  ast_log(LOG_ERROR, "Unable to get_rtp_info for peer type %s\n", glue->type);
1713  ast_channel_unlock(peer);
1714  return -1;
1715  }
1716  if (peer_instance->engine != instance->engine) {
1717  ast_log(LOG_ERROR, "Peer engine mismatch for type %s\n", glue->type);
1718  ast_channel_unlock(peer);
1719  ao2_ref(peer_instance, -1);
1720  return -1;
1721  }
1722 
1723  res = instance->engine->make_compatible(chan, instance, peer, peer_instance);
1724 
1725  ast_channel_unlock(peer);
1726 
1727  ao2_ref(peer_instance, -1);
1728  peer_instance = NULL;
1729 
1730  return res;
1731 }
#define ast_channel_lock(chan)
Definition: channel.h:2466
const char *const type
Definition: channel.h:508
int(* make_compatible)(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1)
Definition: rtp_engine.h:369
const char * type
Definition: rtp_engine.h:395
#define ao2_ref(o, delta)
Definition: astobj2.h:472
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ast_channel_unlock(chan)
Definition: channel.h:2467
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
struct ast_rtp_glue * ast_rtp_instance_get_glue(const char *type)
Get the RTP glue that binds a channel to the RTP engine.
Definition: rtp_engine.c:791
struct ast_channel_tech * tech
Definition: channel.h:743
enum ast_rtp_glue_result(* get_rtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance)
Callback for retrieving the RTP instance carrying audio.
Definition: rtp_engine.h:402
struct ast_rtp_instance* ast_rtp_instance_new ( const char *  engine_name,
struct sched_context sched,
const struct ast_sockaddr sa,
void *  data 
)

Create a new RTP instance.

Parameters
engine_nameName of the engine to use for the RTP instance
schedScheduler context that the RTP engine may want to use
saAddress we want to bind to
dataUnique data for the engine
Return values
non-NULLsuccess
NULLfailure

Example usage:

* struct ast_rtp_instance *instance = NULL;
* instance = ast_rtp_instance_new(NULL, sched, &sin, NULL);
*

This creates a new RTP instance using the default engine and asks the RTP engine to bind to the address given in the address structure.

Note
The RTP engine does not have to use the address provided when creating an RTP instance. It may choose to use another depending on it's own configuration.
Since
1.8

Definition at line 308 of file rtp_engine.c.

References ao2_alloc, ao2_ref, ast_debug, ast_log(), ast_module_ref(), ast_module_unref(), AST_RWLIST_FIRST, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_sockaddr_copy(), ast_strlen_zero(), ast_rtp_instance::engine, instance_destructor(), ast_rtp_instance::local_address, LOG_ERROR, ast_rtp_engine::mod, ast_rtp_engine::name, and ast_rtp_engine::new.

Referenced by __oh323_rtp_create(), dialog_initialize_rtp(), gtalk_alloc(), jingle_alloc(), multicast_rtp_request(), and start_rtp().

311 {
312  struct ast_sockaddr address = {{0,}};
313  struct ast_rtp_instance *instance = NULL;
314  struct ast_rtp_engine *engine = NULL;
315 
317 
318  /* If an engine name was specified try to use it or otherwise use the first one registered */
319  if (!ast_strlen_zero(engine_name)) {
320  AST_RWLIST_TRAVERSE(&engines, engine, entry) {
321  if (!strcmp(engine->name, engine_name)) {
322  break;
323  }
324  }
325  } else {
326  engine = AST_RWLIST_FIRST(&engines);
327  }
328 
329  /* If no engine was actually found bail out now */
330  if (!engine) {
331  ast_log(LOG_ERROR, "No RTP engine was found. Do you have one loaded?\n");
333  return NULL;
334  }
335 
336  /* Bump up the reference count before we return so the module can not be unloaded */
337  ast_module_ref(engine->mod);
338 
340 
341  /* Allocate a new RTP instance */
342  if (!(instance = ao2_alloc(sizeof(*instance), instance_destructor))) {
343  ast_module_unref(engine->mod);
344  return NULL;
345  }
346  instance->engine = engine;
347  ast_sockaddr_copy(&instance->local_address, sa);
348  ast_sockaddr_copy(&address, sa);
349 
350  ast_debug(1, "Using engine '%s' for RTP instance '%p'\n", engine->name, instance);
351 
352  /* And pass it off to the engine to setup */
353  if (instance->engine->new(instance, sched, &address, data)) {
354  ast_debug(1, "Engine '%s' failed to setup RTP instance '%p'\n", engine->name, instance);
355  ao2_ref(instance, -1);
356  return NULL;
357  }
358 
359  ast_debug(1, "RTP instance '%p' is setup and ready to go\n", instance);
360 
361  return instance;
362 }
void ast_module_unref(struct ast_module *)
Definition: loader.c:1312
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:121
static void instance_destructor(void *obj)
Definition: rtp_engine.c:281
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:150
int(* new)(struct ast_rtp_instance *instance, struct sched_context *sched, struct ast_sockaddr *sa, void *data)
Definition: rtp_engine.h:316
Socket address structure.
Definition: netsock2.h:63
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:77
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:236
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:493
#define ao2_ref(o, delta)
Definition: astobj2.h:472
struct ast_module * mod
Definition: rtp_engine.h:314
#define LOG_ERROR
Definition: logger.h:155
void ast_log(int level, const char *file, int line, const char *function, const char *fmt,...)
Used for sending a log message This is the standard logger function. Probably the only way you will i...
Definition: logger.c:1207
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:430
const char * name
Definition: rtp_engine.h:312
struct ast_sockaddr local_address
Definition: rtp_engine.c:60
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
#define AST_RWLIST_FIRST
Definition: linkedlists.h:422
struct ast_module * ast_module_ref(struct ast_module *)
Definition: loader.c:1300
struct ast_frame* ast_rtp_instance_read ( struct ast_rtp_instance instance,
int  rtcp 
)

Receive a frame over RTP.

Parameters
instanceThe RTP instance to receive frame on
rtcpWhether to read in RTCP or not
Return values
non-NULLsuccess
NULLfailure

Example usage:

* struct ast_frame *frame;
* frame = ast_rtp_instance_read(instance, 0);
*

This asks the RTP engine to read in RTP from the instance and return it as an Asterisk frame.

Since
1.8

Definition at line 379 of file rtp_engine.c.

References ast_rtp_instance::engine, and ast_rtp_engine::read.

Referenced by gtalk_rtp_read(), jingle_rtp_read(), mgcp_rtp_read(), oh323_read(), oh323_rtp_read(), sip_rtp_read(), skinny_rtp_read(), and unistim_rtp_read().

380 {
381  return instance->engine->read(instance, rtcp);
382 }
struct ast_frame *(* read)(struct ast_rtp_instance *instance, int rtcp)
Definition: rtp_engine.h:361
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
int ast_rtp_instance_sendcng ( struct ast_rtp_instance instance,
int  level 
)

Send a comfort noise packet to the RTP instance.

Parameters
instanceThe RTP instance
levelMagnitude of the noise level
Return values
0Success
non-zeroFailure

Definition at line 1854 of file rtp_engine.c.

References ast_rtp_instance::engine, and ast_rtp_engine::sendcng.

Referenced by check_rtp_timeout().

1855 {
1856  if (instance->engine->sendcng) {
1857  return instance->engine->sendcng(instance, level);
1858  }
1859 
1860  return -1;
1861 }
int(* sendcng)(struct ast_rtp_instance *instance, int level)
Definition: rtp_engine.h:379
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
int ast_rtp_instance_set_alt_remote_address ( struct ast_rtp_instance instance,
const struct ast_sockaddr address 
)

Set the address of an an alternate RTP address to receive from.

Parameters
instanceThe RTP instance to change the address on
addressAddress to set it to
Return values
0success
-1failure

Example usage:

*

This changes the alternate remote address that RTP will be sent to on instance to the address given in the sin structure.

Since
1.8

Definition at line 405 of file rtp_engine.c.

References ast_rtp_instance::alt_remote_address, ast_rtp_engine::alt_remote_address_set, ast_sockaddr_copy(), and ast_rtp_instance::engine.

Referenced by handle_request_invite().

407 {
408  ast_sockaddr_copy(&instance->alt_remote_address, address);
409 
410  /* oink */
411 
412  if (instance->engine->alt_remote_address_set) {
413  instance->engine->alt_remote_address_set(instance, &instance->alt_remote_address);
414  }
415 
416  return 0;
417 }
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:121
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
struct ast_sockaddr alt_remote_address
Definition: rtp_engine.c:64
void(* alt_remote_address_set)(struct ast_rtp_instance *instance, struct ast_sockaddr *sa)
Definition: rtp_engine.h:345
void ast_rtp_instance_set_data ( struct ast_rtp_instance instance,
void *  data 
)

Set the data portion of an RTP instance.

Parameters
instanceThe RTP instance to manipulate
dataPointer to data

Example usage:

* ast_rtp_instance_set_data(instance, blob);
*

This sets the data pointer on the RTP instance pointed to by 'instance' to blob.

Since
1.8

Definition at line 364 of file rtp_engine.c.

References ast_rtp_instance::data.

Referenced by ast_rtp_new(), and multicast_rtp_new().

365 {
366  instance->data = data;
367 }
union ast_frame::@172 data
void ast_rtp_instance_set_extended_prop ( struct ast_rtp_instance instance,
int  property,
void *  value 
)

Set the value of an RTP instance extended property.

Parameters
instanceThe RTP instance to set the extended property on
propertyThe extended property to set
valueThe value to set the extended property to
Since
1.8

Definition at line 453 of file rtp_engine.c.

References ast_rtp_instance::engine, and ast_rtp_engine::extended_prop_set.

454 {
455  if (instance->engine->extended_prop_set) {
456  instance->engine->extended_prop_set(instance, property, value);
457  }
458 }
int(* extended_prop_set)(struct ast_rtp_instance *instance, int property, void *value)
Definition: rtp_engine.h:333
int value
Definition: syslog.c:39
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
void ast_rtp_instance_set_hold_timeout ( struct ast_rtp_instance instance,
int  timeout 
)

Set the RTP timeout value for when the instance is on hold.

Parameters
instanceThe RTP instance
timeoutValue to set the timeout to

Example usage:

*

This sets the RTP hold timeout value on 'instance' to be 5000.

Since
1.8

Definition at line 1763 of file rtp_engine.c.

References ast_rtp_instance::holdtimeout, and ast_rtp_instance::timeout.

Referenced by check_rtp_timeout(), and dialog_initialize_rtp().

1764 {
1765  instance->holdtimeout = timeout;
1766 }
void ast_rtp_instance_set_keepalive ( struct ast_rtp_instance instance,
int  timeout 
)

Set the RTP keepalive interval.

Parameters
instanceThe RTP instance
periodValue to set the keepalive interval to

Example usage:

*

This sets the RTP keepalive interval on 'instance' to be 5000.

Since
1.8

Definition at line 1768 of file rtp_engine.c.

References ast_rtp_instance::keepalive.

Referenced by dialog_initialize_rtp().

1769 {
1770  instance->keepalive = interval;
1771 }
int ast_rtp_instance_set_local_address ( struct ast_rtp_instance instance,
const struct ast_sockaddr address 
)

Set the address that we are expecting to receive RTP on.

Parameters
instanceThe RTP instance to change the address on
addressAddress to set it to
Return values
0success
-1failure

Example usage:

This changes the local address that RTP is expected on to the address given in the sin structure.

Since
1.8

Definition at line 384 of file rtp_engine.c.

References ast_sockaddr_copy(), and ast_rtp_instance::local_address.

Referenced by ast_rtp_new().

386 {
387  ast_sockaddr_copy(&instance->local_address, address);
388  return 0;
389 }
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:121
struct ast_sockaddr local_address
Definition: rtp_engine.c:60
void ast_rtp_instance_set_prop ( struct ast_rtp_instance instance,
enum ast_rtp_property  property,
int  value 
)

Set the value of an RTP instance property.

Parameters
instanceThe RTP instance to set the property on
propertyThe property to modify
valueThe value to set the property to

Example usage:

This enables the AST_RTP_PROPERTY_NAT property on the instance pointed to by instance.

Since
1.8

Definition at line 469 of file rtp_engine.c.

References ast_rtp_instance::engine, ast_rtp_engine::prop_set, ast_rtp_instance::properties, and value.

Referenced by __oh323_rtp_create(), create_addr_from_peer(), dialog_initialize_rtp(), do_setnat(), gtalk_alloc(), handle_request_invite(), oh323_rtp_read(), process_sdp(), sip_dtmfmode(), sip_set_rtp_peer(), and start_rtp().

470 {
471  instance->properties[property] = value;
472 
473  if (instance->engine->prop_set) {
474  instance->engine->prop_set(instance, property, value);
475  }
476 }
int value
Definition: syslog.c:39
void(* prop_set)(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value)
Definition: rtp_engine.h:337
int properties[AST_RTP_PROPERTY_MAX]
Definition: rtp_engine.c:58
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
int ast_rtp_instance_set_qos ( struct ast_rtp_instance instance,
int  tos,
int  cos,
const char *  desc 
)

Set QoS parameters on an RTP session.

Parameters
instanceInstance to set the QoS parameters on
tosTerms of service value
cosClass of service value
descWhat is setting the QoS values
Return values
0success
-1failure

Example usage:

* ast_rtp_instance_set_qos(instance, 0, 0, "Example");
*

This sets the TOS and COS values to 0 on the instance pointed to by instance.

Since
1.8

Definition at line 774 of file rtp_engine.c.

References ast_rtp_instance::engine, and ast_rtp_engine::qos.

Referenced by __oh323_rtp_create(), dialog_initialize_rtp(), and start_rtp().

775 {
776  return instance->engine->qos ? instance->engine->qos(instance, tos, cos, desc) : -1;
777 }
int(* qos)(struct ast_rtp_instance *instance, int tos, int cos, const char *desc)
Definition: rtp_engine.h:353
static unsigned int tos
Definition: chan_h323.c:146
static const char desc[]
Definition: cdr_radius.c:85
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
static unsigned int cos
Definition: chan_h323.c:147
int ast_rtp_instance_set_read_format ( struct ast_rtp_instance instance,
format_t  format 
)

Request that the underlying RTP engine provide audio frames in a specific format.

Parameters
instanceThe RTP instance to change read format on
formatFormat that frames are wanted in
Return values
0success
-1failure

Example usage:

This requests that the RTP engine provide audio frames in the ULAW format.

Since
1.8

Definition at line 1683 of file rtp_engine.c.

References ast_rtp_instance::engine, and ast_rtp_engine::set_read_format.

Referenced by sip_new(), and sip_setoption().

1684 {
1685  return instance->engine->set_read_format ? instance->engine->set_read_format(instance, format) : -1;
1686 }
int(* set_read_format)(struct ast_rtp_instance *instance, format_t format)
Definition: rtp_engine.h:365
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
static snd_pcm_format_t format
Definition: chan_alsa.c:93
int ast_rtp_instance_set_remote_address ( struct ast_rtp_instance instance,
const struct ast_sockaddr address 
)

Set the address of the remote endpoint that we are sending RTP to.

Parameters
instanceThe RTP instance to change the address on
addressAddress to set it to
Return values
0success
-1failure

Example usage:

This changes the remote address that RTP will be sent to on instance to the address given in the sin structure.

Since
1.8

Definition at line 391 of file rtp_engine.c.

References ast_sockaddr_copy(), ast_rtp_instance::engine, ast_rtp_instance::remote_address, and ast_rtp_engine::remote_address_set.

Referenced by ast_rtp_read(), ast_rtp_stop(), handle_open_receive_channel_ack_message(), multicast_rtp_request(), process_sdp(), setup_rtp_connection(), and start_rtp().

393 {
394  ast_sockaddr_copy(&instance->remote_address, address);
395 
396  /* moo */
397 
398  if (instance->engine->remote_address_set) {
399  instance->engine->remote_address_set(instance, &instance->remote_address);
400  }
401 
402  return 0;
403 }
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:121
void(* remote_address_set)(struct ast_rtp_instance *instance, struct ast_sockaddr *sa)
Definition: rtp_engine.h:343
struct ast_sockaddr remote_address
Definition: rtp_engine.c:62
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
void ast_rtp_instance_set_stats_vars ( struct ast_channel chan,
struct ast_rtp_instance instance 
)

Set standard statistics from an RTP instance on a channel.

Parameters
chanChannel to set the statistics on
instanceThe RTP instance that statistics will be retrieved from

Example usage:

This retrieves standard statistics from the RTP instance rtp and sets it on the channel pointed to by chan.

Since
1.8

Definition at line 1649 of file rtp_engine.c.

References ast_bridged_channel(), AST_MAX_USER_FIELD, ast_rtp_instance_get_quality(), AST_RTP_INSTANCE_STAT_FIELD_QUALITY, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, ast_channel::bridge, pbx_builtin_setvar_helper(), and quality.

Referenced by handle_request_bye(), and sip_hangup().

1650 {
1651  char quality_buf[AST_MAX_USER_FIELD], *quality;
1652  struct ast_channel *bridge = ast_bridged_channel(chan);
1653 
1654  if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
1655  pbx_builtin_setvar_helper(chan, "RTPAUDIOQOS", quality);
1656  if (bridge) {
1657  pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSBRIDGED", quality);
1658  }
1659  }
1660 
1661  if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, quality_buf, sizeof(quality_buf)))) {
1662  pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSJITTER", quality);
1663  if (bridge) {
1664  pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSJITTERBRIDGED", quality);
1665  }
1666  }
1667 
1668  if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, quality_buf, sizeof(quality_buf)))) {
1669  pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSLOSS", quality);
1670  if (bridge) {
1671  pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSLOSSBRIDGED", quality);
1672  }
1673  }
1674 
1675  if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, quality_buf, sizeof(quality_buf)))) {
1676  pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSRTT", quality);
1677  if (bridge) {
1678  pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSRTTBRIDGED", quality);
1679  }
1680  }
1681 }
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MAX_USER_FIELD
Definition: cdr.h:72
static int quality
Definition: codec_speex.c:58
char * ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size)
Retrieve quality statistics about an RTP instance.
Definition: rtp_engine.c:1609
struct ast_channel * ast_bridged_channel(struct ast_channel *chan)
Find bridged channel.
Definition: channel.c:7160
struct ast_bridge * bridge
Definition: channel.h:865
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
Definition: pbx.c:10546
void ast_rtp_instance_set_timeout ( struct ast_rtp_instance instance,
int  timeout 
)

Set the RTP timeout value.

Parameters
instanceThe RTP instance
timeoutValue to set the timeout to

Example usage:

* ast_rtp_instance_set_timeout(instance, 5000);
*

This sets the RTP timeout value on 'instance' to be 5000.

Since
1.8

Definition at line 1758 of file rtp_engine.c.

References ast_rtp_instance::timeout.

Referenced by check_rtp_timeout(), and dialog_initialize_rtp().

1759 {
1760  instance->timeout = timeout;
1761 }
int ast_rtp_instance_set_write_format ( struct ast_rtp_instance instance,
format_t  format 
)

Tell underlying RTP engine that audio frames will be provided in a specific format.

Parameters
instanceThe RTP instance to change write format on
formatFormat that frames will be provided in
Return values
0success
-1failure

Example usage:

This tells the underlying RTP engine that audio frames will be provided to it in ULAW format.

Since
1.8

Definition at line 1688 of file rtp_engine.c.

References ast_rtp_instance::engine, and ast_rtp_engine::set_write_format.

Referenced by sip_new(), and sip_setoption().

1689 {
1690  return instance->engine->set_write_format ? instance->engine->set_write_format(instance, format) : -1;
1691 }
int(* set_write_format)(struct ast_rtp_instance *instance, format_t format)
Definition: rtp_engine.h:367
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
static snd_pcm_format_t format
Definition: chan_alsa.c:93
void ast_rtp_instance_stop ( struct ast_rtp_instance instance)

Stop an RTP instance.

Parameters
instanceInstance that media is no longer going to at this time

Example usage:

*

This tells the RTP engine being used for the instance pointed to by instance that media is no longer going to it at this time, but may in the future.

Since
1.8

Definition at line 779 of file rtp_engine.c.

References ast_rtp_instance::engine, and ast_rtp_engine::stop.

Referenced by process_sdp(), setup_rtp_connection(), and stop_media_flows().

780 {
781  if (instance->engine->stop) {
782  instance->engine->stop(instance);
783  }
784 }
void(* stop)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:322
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
void ast_rtp_instance_stun_request ( struct ast_rtp_instance instance,
struct ast_sockaddr suggestion,
const char *  username 
)

Request that the underlying RTP engine send a STUN BIND request.

Parameters
instanceThe RTP instance
suggestionThe suggested destination
usernameOptionally a username for the request

Example usage:

* ast_rtp_instance_stun_request(instance, NULL, NULL);
*

This requests that the RTP engine send a STUN BIND request on the session pointed to by 'instance'.

Since
1.8

Definition at line 1749 of file rtp_engine.c.

References ast_rtp_instance::engine, and ast_rtp_engine::stun_request.

Referenced by gtalk_update_stun(), and jingle_update_stun().

1752 {
1753  if (instance->engine->stun_request) {
1754  instance->engine->stun_request(instance, suggestion, username);
1755  }
1756 }
void(* stun_request)(struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username)
Definition: rtp_engine.h:375
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
void ast_rtp_instance_update_source ( struct ast_rtp_instance instance)

Indicate that the RTP marker bit should be set on an RTP stream.

Parameters
instanceInstance that the new media source is feeding into

Example usage:

This indicates that the source of media that is feeding the instance pointed to by instance has been updated and that the marker bit should be set.

Since
1.8

Definition at line 760 of file rtp_engine.c.

References ast_rtp_instance::engine, and ast_rtp_engine::update_source.

Referenced by mgcp_indicate(), oh323_indicate(), sip_answer(), sip_indicate(), sip_write(), and skinny_indicate().

761 {
762  if (instance->engine->update_source) {
763  instance->engine->update_source(instance);
764  }
765 }
void(* update_source)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:329
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
int ast_rtp_instance_write ( struct ast_rtp_instance instance,
struct ast_frame frame 
)

Send a frame out over RTP.

Parameters
instanceThe RTP instance to send frame out on
framethe frame to send out
Return values
0success
-1failure

Example usage:

* ast_rtp_instance_write(instance, frame);
*

This gives the frame pointed to by frame to the RTP engine being used for the instance and asks that it be transmitted to the current remote address set on the RTP instance.

Since
1.8

Definition at line 374 of file rtp_engine.c.

References ast_rtp_instance::engine, and ast_rtp_engine::write.

Referenced by gtalk_write(), jingle_write(), mgcp_write(), multicast_rtp_write(), oh323_write(), sip_write(), skinny_write(), and unistim_write().

375 {
376  return instance->engine->write(instance, frame);
377 }
int(* write)(struct ast_rtp_instance *instance, struct ast_frame *frame)
Definition: rtp_engine.h:320
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
char* ast_rtp_lookup_mime_multiple2 ( struct ast_str buf,
const format_t  capability,
const int  asterisk_format,
enum ast_rtp_options  options 
)

Convert formats into a string and put them into a buffer.

Parameters
bufBuffer to put the mime output into
capabilityFormats that we are looking up
asterisk_formatNon-zero if the given capability are Asterisk format capabilities
optionsAdditional options that may change the result
Return values
non-NULLsuccess
NULLfailure

Example usage:

* char buf[256] = "";
* char *mime = ast_rtp_lookup_mime_multiple2(&buf, sizeof(buf), AST_FORMAT_ULAW | AST_FORMAT_ALAW, 1, 0);
*

This returns the mime values for ULAW and ALAW in the buffer pointed to by buf.

Since
1.8

Definition at line 703 of file rtp_engine.c.

References ast_rtp_lookup_mime_subtype2(), AST_RTP_MAX, ast_str_append(), ast_str_buffer(), format, and name.

Referenced by process_sdp().

704 {
706  int found = 0;
707 
708  if (!buf) {
709  return NULL;
710  }
711 
712  ast_str_append(&buf, 0, "0x%llx (", (unsigned long long) capability);
713 
714  for (format = 1; format <= AST_RTP_MAX; format <<= 1) {
715  if (capability & format) {
716  const char *name = ast_rtp_lookup_mime_subtype2(asterisk_format, format, options);
717  ast_str_append(&buf, 0, "%s|", name);
718  found = 1;
719  }
720  }
721 
722  ast_str_append(&buf, 0, "%s", found ? ")" : "nothing)");
723 
724  return ast_str_buffer(buf);
725 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:497
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:900
#define AST_RTP_MAX
Definition: rtp_engine.h:224
int64_t format_t
Definition: frame_defs.h:32
static const char name[]
static format_t capability
Definition: chan_mgcp.c:228
const char * ast_rtp_lookup_mime_subtype2(const int asterisk_format, const format_t code, enum ast_rtp_options options)
Retrieve mime subtype information on a payload.
Definition: rtp_engine.c:673
static snd_pcm_format_t format
Definition: chan_alsa.c:93
const char* ast_rtp_lookup_mime_subtype2 ( const int  asterisk_format,
const format_t  code,
enum ast_rtp_options  options 
)

Retrieve mime subtype information on a payload.

Parameters
asterisk_formatNon-zero if the given code is an Asterisk format value
codeFormat to look up
optionsAdditional options that may change the result
Return values
Mimesubtype success
NULLfailure

Example usage:

* const char *subtype = ast_rtp_lookup_mime_subtype2(1, AST_FORMAT_ULAW, 0);
*

This looks up the mime subtype for the ULAW format.

Since
1.8

Definition at line 673 of file rtp_engine.c.

References ARRAY_LEN, AST_FORMAT_G726_AAL2, ast_rtp_mime_types, AST_RTP_OPT_G726_NONSTANDARD, ast_rtp_payload_type::asterisk_format, ast_rtp_mime_type::payload_type, and ast_rtp_mime_type::subtype.

Referenced by add_codec_to_sdp(), add_noncodec_to_sdp(), add_sdp(), add_tcodec_to_sdp(), add_vcodec_to_sdp(), ast_rtp_lookup_mime_multiple2(), transmit_connect(), transmit_connect_with_sdp(), transmit_modify_request(), and transmit_modify_with_sdp().

674 {
675  int i;
676 
677  for (i = 0; i < ARRAY_LEN(ast_rtp_mime_types); i++) {
678  if (ast_rtp_mime_types[i].payload_type.code == code && ast_rtp_mime_types[i].payload_type.asterisk_format == asterisk_format) {
679  if (asterisk_format && (code == AST_FORMAT_G726_AAL2) && (options & AST_RTP_OPT_G726_NONSTANDARD)) {
680  return "G726-32";
681  } else {
682  return ast_rtp_mime_types[i].subtype;
683  }
684  }
685  }
686 
687  return "";
688 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
struct ast_rtp_payload_type payload_type
Definition: rtp_engine.c:92
#define AST_FORMAT_G726_AAL2
Definition: frame.h:250
static struct ast_rtp_mime_type ast_rtp_mime_types[]
unsigned int ast_rtp_lookup_sample_rate2 ( int  asterisk_format,
format_t  code 
)

Get the sample rate associated with known RTP payload types.

Parameters
asterisk_formatTrue if the value in the 'code' parameter is an AST_FORMAT value
codeFormat code, either from AST_FORMAT list or from AST_RTP list
Returns
the sample rate if the format was found, zero if it was not found
Since
1.8

Definition at line 690 of file rtp_engine.c.

References ARRAY_LEN, ast_rtp_mime_types, ast_rtp_payload_type::asterisk_format, ast_rtp_mime_type::payload_type, and ast_rtp_mime_type::sample_rate.

Referenced by add_codec_to_sdp(), add_noncodec_to_sdp(), add_tcodec_to_sdp(), and add_vcodec_to_sdp().

691 {
692  unsigned int i;
693 
694  for (i = 0; i < ARRAY_LEN(ast_rtp_mime_types); ++i) {
695  if ((ast_rtp_mime_types[i].payload_type.code == code) && (ast_rtp_mime_types[i].payload_type.asterisk_format == asterisk_format)) {
697  }
698  }
699 
700  return 0;
701 }
#define ARRAY_LEN(a)
Definition: isdn_lib.c:42
unsigned int sample_rate
Definition: rtp_engine.c:95
struct ast_rtp_payload_type payload_type
Definition: rtp_engine.c:92
static struct ast_rtp_mime_type ast_rtp_mime_types[]
int ast_rtp_red_buffer ( struct ast_rtp_instance instance,
struct ast_frame frame 
)

Buffer a frame in an RTP instance for RED.

Parameters
instanceThe instance to buffer the frame on
frameFrame that we want to buffer
Return values
0success
-1failure
Since
1.8

Definition at line 1599 of file rtp_engine.c.

References ast_rtp_instance::engine, and ast_rtp_engine::red_buffer.

Referenced by sip_write().

1600 {
1601  return instance->engine->red_buffer ? instance->engine->red_buffer(instance, frame) : -1;
1602 }
int(* red_buffer)(struct ast_rtp_instance *instance, struct ast_frame *frame)
Definition: rtp_engine.h:359
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54
int ast_rtp_red_init ( struct ast_rtp_instance instance,
int  buffer_time,
int *  payloads,
int  generations 
)

Initialize RED support on an RTP instance.

Parameters
instanceThe instance to initialize RED support on
buffer_timeHow long to buffer before sending
payloadsPayload values
generationsNumber of generations
Return values
0success
-1failure
Since
1.8

Definition at line 1594 of file rtp_engine.c.

References ast_rtp_instance::engine, and ast_rtp_engine::red_init.

Referenced by process_sdp().

1595 {
1596  return instance->engine->red_init ? instance->engine->red_init(instance, buffer_time, payloads, generations) : -1;
1597 }
int(* red_init)(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations)
Definition: rtp_engine.h:357
struct ast_rtp_engine * engine
Definition: rtp_engine.c:54