Mon Mar 12 2012 21:45:06

Asterisk developer's documentation


rtp_engine.c File Reference

Pluggable RTP Architecture. More...

#include "asterisk.h"
#include <math.h>
#include "asterisk/channel.h"
#include "asterisk/frame.h"
#include "asterisk/module.h"
#include "asterisk/rtp_engine.h"
#include "asterisk/manager.h"
#include "asterisk/options.h"
#include "asterisk/astobj2.h"
#include "asterisk/pbx.h"
#include "asterisk/translate.h"
#include "asterisk/netsock2.h"
#include "asterisk/framehook.h"
Include dependency graph for rtp_engine.c:

Go to the source code of this file.

Data Structures

struct  ast_rtp_instance
struct  ast_rtp_mime_type
struct  engines
struct  glues

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.
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.
void ast_rtp_codecs_payload_formats (struct ast_rtp_codecs *codecs, format_t *astformats, int *nonastformats)
 Retrieve all formats that were found.
struct ast_rtp_payload_type ast_rtp_codecs_payload_lookup (struct ast_rtp_codecs *codecs, int payload)
 Retrieve payload information by payload.
void ast_rtp_codecs_payloads_clear (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance)
 Clear payload information from an RTP instance.
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.
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.
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.
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.
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.
void ast_rtp_codecs_payloads_unset (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
 Remove payload information.
int ast_rtp_engine_register2 (struct ast_rtp_engine *engine, struct ast_module *module)
 Register an RTP engine.
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.
void ast_rtp_engine_unregister_srtp (void)
int ast_rtp_glue_register2 (struct ast_rtp_glue *glue, struct ast_module *module)
 Register RTP glue.
int ast_rtp_glue_unregister (struct ast_rtp_glue *glue)
 Unregister RTP glue.
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.
int ast_rtp_instance_add_srtp_policy (struct ast_rtp_instance *instance, struct ast_srtp_policy *policy)
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.
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.
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.
int ast_rtp_instance_destroy (struct ast_rtp_instance *instance)
 Destroy an RTP instance.
int ast_rtp_instance_dtmf_begin (struct ast_rtp_instance *instance, char digit)
 Begin sending a DTMF digit.
int ast_rtp_instance_dtmf_end (struct ast_rtp_instance *instance, char digit)
 Stop sending a DTMF digit.
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.
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.
int ast_rtp_instance_early_bridge (struct ast_channel *c0, struct ast_channel *c1)
 Early bridge two channels that use RTP instances.
void ast_rtp_instance_early_bridge_make_compatible (struct ast_channel *c0, struct ast_channel *c1)
 Make two channels compatible for early bridging.
int ast_rtp_instance_fd (struct ast_rtp_instance *instance, int rtcp)
 Get the file descriptor for an RTP session (or RTCP)
struct ast_rtp_glueast_rtp_instance_get_active_glue (struct ast_rtp_instance *instance)
 Get the RTP glue in use on an RTP instance.
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.
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.
struct ast_rtp_instanceast_rtp_instance_get_bridged (struct ast_rtp_instance *instance)
 Get the other RTP instance that an instance is bridged to.
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.
struct ast_rtp_codecsast_rtp_instance_get_codecs (struct ast_rtp_instance *instance)
 Get the codecs structure of an RTP instance.
void * ast_rtp_instance_get_data (struct ast_rtp_instance *instance)
 Get the data portion of an RTP instance.
struct ast_rtp_engineast_rtp_instance_get_engine (struct ast_rtp_instance *instance)
 Get the RTP engine in use on an RTP instance.
void * ast_rtp_instance_get_extended_prop (struct ast_rtp_instance *instance, int property)
 Get the value of an RTP instance extended property.
struct ast_rtp_glueast_rtp_instance_get_glue (const char *type)
 Get the RTP glue that binds a channel to the RTP engine.
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.
int ast_rtp_instance_get_keepalive (struct ast_rtp_instance *instance)
 Get the RTP keepalive interval.
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.
int ast_rtp_instance_get_prop (struct ast_rtp_instance *instance, enum ast_rtp_property property)
 Get the value of an RTP instance property.
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.
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.
struct ast_srtpast_rtp_instance_get_srtp (struct ast_rtp_instance *instance)
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.
int ast_rtp_instance_get_timeout (struct ast_rtp_instance *instance)
 Get the RTP timeout value.
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.
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.
struct ast_frameast_rtp_instance_read (struct ast_rtp_instance *instance, int rtcp)
 Receive a frame over RTP.
int ast_rtp_instance_sendcng (struct ast_rtp_instance *instance, int level)
 Send a comfort noise packet to the RTP instance.
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.
void ast_rtp_instance_set_data (struct ast_rtp_instance *instance, void *data)
 Set the data portion of an RTP instance.
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.
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.
void ast_rtp_instance_set_keepalive (struct ast_rtp_instance *instance, int interval)
 Set the RTP keepalive interval.
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.
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.
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.
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.
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.
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.
void ast_rtp_instance_set_timeout (struct ast_rtp_instance *instance, int timeout)
 Set the RTP timeout value.
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.
void ast_rtp_instance_stop (struct ast_rtp_instance *instance)
 Stop an RTP instance.
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.
void ast_rtp_instance_update_source (struct ast_rtp_instance *instance)
 Indicate that the RTP marker bit should be set on an RTP stream.
int ast_rtp_instance_write (struct ast_rtp_instance *instance, struct ast_frame *frame)
 Send a frame out over RTP.
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.
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.
unsigned int ast_rtp_lookup_sample_rate2 (int asterisk_format, format_t code)
 Get the sample rate associated with known RTP payload types.
int ast_rtp_red_buffer (struct ast_rtp_instance *instance, struct ast_frame *frame)
 Buffer a frame in an RTP instance for RED.
int ast_rtp_red_init (struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations)
 Initialize RED support on an RTP instance.
static void instance_destructor (void *obj)
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)
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)
static void unref_instance_cond (struct ast_rtp_instance **instance)
 Conditionally unref an rtp instance.

Variables

static struct ast_rtp_mime_type ast_rtp_mime_types []
static struct engines engines
static struct glues glues
struct ast_srtp_resres_srtp = NULL
struct ast_srtp_policy_resres_srtp_policy = NULL
static struct ast_rtp_payload_type static_RTP_PT [AST_RTP_MAX_PT]
 Mapping between Asterisk codecs and rtp payload types.

Detailed Description

Pluggable RTP Architecture.

Author:
Joshua Colp <jcolp@digium.com>

Definition in file rtp_engine.c.


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 722 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().

{
   codecs->pref = *prefs;

   if (instance && instance->engine->packetization_set) {
      instance->engine->packetization_set(instance, &instance->codecs.pref);
   }
}
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 649 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_write(), bridge_p2p_rtp_write(), multicast_rtp_write(), and start_rtp().

{
   int i;

   for (i = 0; i < AST_RTP_MAX_PT; i++) {
      if (codecs->payloads[i].asterisk_format == asterisk_format && codecs->payloads[i].code == code) {
         return i;
      }
   }

   for (i = 0; i < AST_RTP_MAX_PT; i++) {
      if (static_RTP_PT[i].asterisk_format == asterisk_format && static_RTP_PT[i].code == code) {
         return i;
      }
   }

   return -1;
}
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 631 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().

{
   int i;

   *astformats = *nonastformats = 0;

   for (i = 0; i < AST_RTP_MAX_PT; i++) {
      if (codecs->payloads[i].code) {
         ast_debug(1, "Incorporating payload %d on %p\n", i, codecs);
      }
      if (codecs->payloads[i].asterisk_format) {
         *astformats |= codecs->payloads[i].code;
      } else {
         *nonastformats |= codecs->payloads[i].code;
      }
   }
}
struct ast_rtp_payload_type ast_rtp_codecs_payload_lookup ( struct ast_rtp_codecs codecs,
int  payload 
) [read]

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 613 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(), ast_rtp_sendcng(), bridge_p2p_rtp_write(), process_sdp_a_audio(), and setup_rtp_connection().

{
   struct ast_rtp_payload_type result = { .asterisk_format = 0, };

   if (payload < 0 || payload >= AST_RTP_MAX_PT) {
      return result;
   }

   result.asterisk_format = codecs->payloads[payload].asterisk_format;
   result.code = codecs->payloads[payload].code;

   if (!result.code) {
      result = static_RTP_PT[payload];
   }

   return result;
}
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;
 ast_rtp_codecs_payloads_clear(&codecs, NULL);

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

Since:
1.8

Definition at line 483 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().

{
   int i;

   for (i = 0; i < AST_RTP_MAX_PT; i++) {
      codecs->payloads[i].asterisk_format = 0;
      codecs->payloads[i].code = 0;
      if (instance && instance->engine && instance->engine->payload_set) {
         instance->engine->payload_set(instance, i, 0, 0);
      }
   }
}
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 511 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().

{
   int i;

   for (i = 0; i < AST_RTP_MAX_PT; i++) {
      if (src->payloads[i].code) {
         ast_debug(2, "Copying payload %d from %p to %p\n", i, src, dest);
         dest->payloads[i].asterisk_format = src->payloads[i].asterisk_format;
         dest->payloads[i].code = src->payloads[i].code;
         if (instance && instance->engine && instance->engine->payload_set) {
            instance->engine->payload_set(instance, i, dest->payloads[i].asterisk_format, dest->payloads[i].code);
         }
      }
   }
}
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;
 ast_rtp_codecs_payloads_default(&codecs, NULL);

This sets the default payloads on the codecs structure.

Since:
1.8

Definition at line 496 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.

{
   int i;

   for (i = 0; i < AST_RTP_MAX_PT; i++) {
      if (static_RTP_PT[i].code) {
         codecs->payloads[i].asterisk_format = static_RTP_PT[i].asterisk_format;
         codecs->payloads[i].code = static_RTP_PT[i].code;
         if (instance && instance->engine && instance->engine->payload_set) {
            instance->engine->payload_set(instance, i, codecs->payloads[i].asterisk_format, codecs->payloads[i].code);
         }
      }
   }
}
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 527 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().

{
   if (payload < 0 || payload >= AST_RTP_MAX_PT || !static_RTP_PT[payload].code) {
      return;
   }

   codecs->payloads[payload].asterisk_format = static_RTP_PT[payload].asterisk_format;
   codecs->payloads[payload].code = static_RTP_PT[payload].code;

   ast_debug(1, "Setting payload %d based on m type on %p\n", payload, codecs);

   if (instance && instance->engine && instance->engine->payload_set) {
      instance->engine->payload_set(instance, payload, codecs->payloads[payload].asterisk_format, codecs->payloads[payload].code);
   }
}
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 592 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().

{
   return ast_rtp_codecs_payloads_set_rtpmap_type_rate(codecs, instance, payload, mimetype, mimesubtype, options, 0);
}
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 543 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().

{
   unsigned int i;
   int found = 0;

   if (pt < 0 || pt >= AST_RTP_MAX_PT)
      return -1; /* bogus payload type */

   for (i = 0; i < ARRAY_LEN(ast_rtp_mime_types); ++i) {
      const struct ast_rtp_mime_type *t = &ast_rtp_mime_types[i];

      if (strcasecmp(mimesubtype, t->subtype)) {
         continue;
      }

      if (strcasecmp(mimetype, t->type)) {
         continue;
      }

      /* if both sample rates have been supplied, and they don't match,
       * then this not a match; if one has not been supplied, then the
       * rates are not compared */
      if (sample_rate && t->sample_rate &&
          (sample_rate != t->sample_rate)) {
         continue;
      }

      found = 1;
      codecs->payloads[pt] = t->payload_type;

      if ((t->payload_type.code == AST_FORMAT_G726) &&
                              t->payload_type.asterisk_format &&
          (options & AST_RTP_OPT_G726_NONSTANDARD)) {
         codecs->payloads[pt].code = AST_FORMAT_G726_AAL2;
      }

      if (instance && instance->engine && instance->engine->payload_set) {
         instance->engine->payload_set(instance, pt, codecs->payloads[i].asterisk_format, codecs->payloads[i].code);
      }

      break;
   }

   return (found ? 0 : -2);
}
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 597 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().

{
   if (payload < 0 || payload >= AST_RTP_MAX_PT) {
      return;
   }

   ast_debug(2, "Unsetting payload %d on %p\n", payload, codecs);

   codecs->payloads[payload].asterisk_format = 0;
   codecs->payloads[payload].code = 0;

   if (instance && instance->engine && instance->engine->payload_set) {
      instance->engine->payload_set(instance, payload, 0, 0);
   }
}
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 183 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.

{
   struct ast_rtp_engine *current_engine;

   /* Perform a sanity check on the engine structure to make sure it has the basics */
   if (ast_strlen_zero(engine->name) || !engine->new || !engine->destroy || !engine->write || !engine->read) {
      ast_log(LOG_WARNING, "RTP Engine '%s' failed sanity check so it was not registered.\n", !ast_strlen_zero(engine->name) ? engine->name : "Unknown");
      return -1;
   }

   /* Link owner module to the RTP engine for reference counting purposes */
   engine->mod = module;

   AST_RWLIST_WRLOCK(&engines);

   /* Ensure that no two modules with the same name are registered at the same time */
   AST_RWLIST_TRAVERSE(&engines, current_engine, entry) {
      if (!strcmp(current_engine->name, engine->name)) {
         ast_log(LOG_WARNING, "An RTP engine with the name '%s' has already been registered.\n", engine->name);
         AST_RWLIST_UNLOCK(&engines);
         return -1;
      }
   }

   /* The engine survived our critique. Off to the list it goes to be used */
   AST_RWLIST_INSERT_TAIL(&engines, engine, entry);

   AST_RWLIST_UNLOCK(&engines);

   ast_verb(2, "Registered RTP engine '%s'\n", engine->name);

   return 0;
}
int ast_rtp_engine_register_srtp ( struct ast_srtp_res srtp_res,
struct ast_srtp_policy_res policy_res 
)

Definition at line 1758 of file rtp_engine.c.

References policy_res, and srtp_res.

Referenced by res_srtp_init().

{
   if (res_srtp || res_srtp_policy) {
      return -1;
   }
   if (!srtp_res || !policy_res) {
      return -1;
   }

   res_srtp = srtp_res;
   res_srtp_policy = policy_res;

   return 0;
}
int ast_rtp_engine_srtp_is_registered ( void  )

Definition at line 1779 of file rtp_engine.c.

References res_srtp_policy.

Referenced by setup_srtp().

{
   return res_srtp && res_srtp_policy;
}
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 217 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().

{
   struct ast_rtp_engine *current_engine = NULL;

   AST_RWLIST_WRLOCK(&engines);

   if ((current_engine = AST_RWLIST_REMOVE(&engines, engine, entry))) {
      ast_verb(2, "Unregistered RTP engine '%s'\n", engine->name);
   }

   AST_RWLIST_UNLOCK(&engines);

   return current_engine ? 0 : -1;
}
void ast_rtp_engine_unregister_srtp ( void  )

Definition at line 1773 of file rtp_engine.c.

Referenced by unload_module().

{
   res_srtp = NULL;
   res_srtp_policy = NULL;
}
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 232 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.

{
   struct ast_rtp_glue *current_glue = NULL;

   if (ast_strlen_zero(glue->type)) {
      return -1;
   }

   glue->mod = module;

   AST_RWLIST_WRLOCK(&glues);

   AST_RWLIST_TRAVERSE(&glues, current_glue, entry) {
      if (!strcasecmp(current_glue->type, glue->type)) {
         ast_log(LOG_WARNING, "RTP glue with the name '%s' has already been registered.\n", glue->type);
         AST_RWLIST_UNLOCK(&glues);
         return -1;
      }
   }

   AST_RWLIST_INSERT_TAIL(&glues, glue, entry);

   AST_RWLIST_UNLOCK(&glues);

   ast_verb(2, "Registered RTP glue '%s'\n", glue->type);

   return 0;
}
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 261 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().

{
   struct ast_rtp_glue *current_glue = NULL;

   AST_RWLIST_WRLOCK(&glues);

   if ((current_glue = AST_RWLIST_REMOVE(&glues, glue, entry))) {
      ast_verb(2, "Unregistered RTP glue '%s'\n", glue->type);
   }

   AST_RWLIST_UNLOCK(&glues);

   return current_glue ? 0 : -1;
}
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 1699 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().

{
   return instance->engine->activate ? instance->engine->activate(instance) : 0;
}
int ast_rtp_instance_add_srtp_policy ( struct ast_rtp_instance instance,
struct ast_srtp_policy policy 
)

Definition at line 1784 of file rtp_engine.c.

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

{
   if (!res_srtp) {
      return -1;
   }

   if (!instance->srtp) {
      return res_srtp->create(&instance->srtp, instance, policy);
   } else {
      return res_srtp->add_stream(instance->srtp, policy);
   }
}
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 1688 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().

{
   format_t formats;

   if (instance->engine->available_formats && (formats = instance->engine->available_formats(instance, to_endpoint, to_asterisk))) {
      return formats;
   }

   return ast_translate_available_formats(to_endpoint, to_asterisk);
}
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 1250 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_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_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, remote_bridge_loop(), ast_sockaddr::ss, ast_channel::tech, ast_channel::tech_pvt, ast_channel_tech::type, and unref_instance_cond().

{
   struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
         *vinstance0 = NULL, *vinstance1 = NULL,
         *tinstance0 = NULL, *tinstance1 = NULL;
   struct ast_rtp_glue *glue0, *glue1;
   struct ast_sockaddr addr1 = { {0, }, }, addr2 = { {0, }, };
   enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
   enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
   enum ast_bridge_result res = AST_BRIDGE_FAILED;
   enum ast_rtp_dtmf_mode dmode;
   format_t codec0 = 0, codec1 = 0;
   int unlock_chans = 1;

   /* Lock both channels so we can look for the glue that binds them together */
   ast_channel_lock(c0);
   while (ast_channel_trylock(c1)) {
      ast_channel_unlock(c0);
      usleep(1);
      ast_channel_lock(c0);
   }

   /* Ensure neither channel got hungup during lock avoidance */
   if (ast_check_hangup(c0) || ast_check_hangup(c1)) {
      ast_log(LOG_WARNING, "Got hangup while attempting to bridge '%s' and '%s'\n", c0->name, c1->name);
      goto done;
   }

   /* Grab glue that binds each channel to something using the RTP engine */
   if (!(glue0 = ast_rtp_instance_get_glue(c0->tech->type)) || !(glue1 = ast_rtp_instance_get_glue(c1->tech->type))) {
      ast_debug(1, "Can't find native functions for channel '%s'\n", glue0 ? c1->name : c0->name);
      goto done;
   }

   audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
   video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;

   audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
   video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;

   /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
   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)) {
      audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
   }
   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)) {
      audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
   }

   /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
   if (audio_glue0_res == AST_RTP_GLUE_RESULT_FORBID || audio_glue1_res == AST_RTP_GLUE_RESULT_FORBID) {
      res = AST_BRIDGE_FAILED_NOWARN;
      goto done;
   }


   /* If address families differ, force a local bridge */
   ast_rtp_instance_get_remote_address(instance0, &addr1);
   ast_rtp_instance_get_remote_address(instance1, &addr2);

   if (addr1.ss.ss_family != addr2.ss.ss_family ||
      (ast_sockaddr_is_ipv4_mapped(&addr1) != ast_sockaddr_is_ipv4_mapped(&addr2))) {
      audio_glue0_res = AST_RTP_GLUE_RESULT_LOCAL;
      audio_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
   }

   /* If we need to get DTMF see if we can do it outside of the RTP stream itself */
   dmode = ast_rtp_instance_dtmf_mode_get(instance0);
   if ((flags & AST_BRIDGE_DTMF_CHANNEL_0) && dmode) {
      res = AST_BRIDGE_FAILED_NOWARN;
      goto done;
   }
   dmode = ast_rtp_instance_dtmf_mode_get(instance1);
   if ((flags & AST_BRIDGE_DTMF_CHANNEL_1) && dmode) {
      res = AST_BRIDGE_FAILED_NOWARN;
      goto done;
   }

   /* 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 */
   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)))) {
      res = AST_BRIDGE_FAILED_NOWARN;
      goto done;
   }

   /* Make sure that codecs match */
   codec0 = glue0->get_codec ? glue0->get_codec(c0) : 0;
   codec1 = glue1->get_codec ? glue1->get_codec(c1) : 0;
   if (codec0 && codec1 && !(codec0 & codec1)) {
      ast_debug(1, "Channel codec0 = %s is not codec1 = %s, cannot native bridge in RTP.\n", ast_getformatname(codec0), ast_getformatname(codec1));
      res = AST_BRIDGE_FAILED_NOWARN;
      goto done;
   }

   instance0->glue = glue0;
   instance1->glue = glue1;
   instance0->chan = c0;
   instance1->chan = c1;

   /* Depending on the end result for bridging either do a local bridge or remote bridge */
   if (audio_glue0_res == AST_RTP_GLUE_RESULT_LOCAL || audio_glue1_res == AST_RTP_GLUE_RESULT_LOCAL) {
      ast_verb(3, "Locally bridging %s and %s\n", c0->name, c1->name);
      res = local_bridge_loop(c0, c1, instance0, instance1, timeoutms, flags, fo, rc, c0->tech_pvt, c1->tech_pvt);
   } else {
      ast_verb(3, "Remotely bridging %s and %s\n", c0->name, c1->name);
      res = remote_bridge_loop(c0, c1, instance0, instance1, vinstance0, vinstance1,
            tinstance0, tinstance1, glue0, glue1, codec0, codec1, timeoutms, flags,
            fo, rc, c0->tech_pvt, c1->tech_pvt);
   }

   instance0->glue = NULL;
   instance1->glue = NULL;
   instance0->chan = NULL;
   instance1->chan = NULL;

   unlock_chans = 0;

done:
   if (unlock_chans) {
      ast_channel_unlock(c0);
      ast_channel_unlock(c1);
   }

   unref_instance_cond(&instance0);
   unref_instance_cond(&instance1);
   unref_instance_cond(&vinstance0);
   unref_instance_cond(&vinstance1);
   unref_instance_cond(&tinstance0);
   unref_instance_cond(&tinstance1);

   return res;
}
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 762 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().

{
   if (instance->engine->change_source) {
      instance->engine->change_source(instance);
   }
}
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 296 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().

{
   ao2_ref(instance, -1);

   return 0;
}
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 731 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().

{
   return instance->engine->dtmf_begin ? instance->engine->dtmf_begin(instance, digit) : -1;
}
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 736 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().

{
   return instance->engine->dtmf_end ? instance->engine->dtmf_end(instance, digit) : -1;
}
int ast_rtp_instance_dtmf_end_with_duration ( struct ast_rtp_instance instance,
char  digit,
unsigned int  duration 
)

Definition at line 740 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().

{
   return instance->engine->dtmf_end_with_duration ? instance->engine->dtmf_end_with_duration(instance, digit, duration) : -1;
}
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 750 of file rtp_engine.c.

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

Referenced by ast_rtp_instance_bridge().

{
   return instance->engine->dtmf_mode_get ? instance->engine->dtmf_mode_get(instance) : 0;
}
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 745 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().

{
   return (!instance->engine->dtmf_mode_set || instance->engine->dtmf_mode_set(instance, dtmf_mode)) ? -1 : 0;
}
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 1468 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.

{
   struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
         *vinstance0 = NULL, *vinstance1 = NULL,
         *tinstance0 = NULL, *tinstance1 = NULL;
   struct ast_rtp_glue *glue0, *glue1;
   enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
   enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
   format_t codec0 = 0, codec1 = 0;
   int res = 0;

   /* If there is no second channel just immediately bail out, we are of no use in that scenario */
   if (!c1) {
      return -1;
   }

   /* Lock both channels so we can look for the glue that binds them together */
   ast_channel_lock(c0);
   while (ast_channel_trylock(c1)) {
      ast_channel_unlock(c0);
      usleep(1);
      ast_channel_lock(c0);
   }

   /* Grab glue that binds each channel to something using the RTP engine */
   if (!(glue0 = ast_rtp_instance_get_glue(c0->tech->type)) || !(glue1 = ast_rtp_instance_get_glue(c1->tech->type))) {
      ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", glue0 ? c1->name : c0->name);
      goto done;
   }

   audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
   video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;

   audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
   video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;

   /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
   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)) {
      audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
   }
   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)) {
      audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
   }
   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)) {
      codec0 = glue0->get_codec(c0);
   }
   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)) {
      codec1 = glue1->get_codec(c1);
   }

   /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
   if (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE) {
      goto done;
   }

   /* Make sure we have matching codecs */
   if (!(codec0 & codec1)) {
      goto done;
   }

   /* Bridge media early */
   if (glue0->update_peer(c0, instance1, vinstance1, tinstance1, codec1, 0)) {
      ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", c0->name, c1 ? c1->name : "<unspecified>");
   }

   res = 0;

done:
   ast_channel_unlock(c0);
   ast_channel_unlock(c1);

   unref_instance_cond(&instance0);
   unref_instance_cond(&instance1);
   unref_instance_cond(&vinstance0);
   unref_instance_cond(&vinstance1);
   unref_instance_cond(&tinstance0);
   unref_instance_cond(&tinstance1);

   if (!res) {
      ast_debug(1, "Setting early bridge SDP of '%s' with that of '%s'\n", c0->name, c1 ? c1->name : "<unspecified>");
   }

   return res;
}
void ast_rtp_instance_early_bridge_make_compatible ( struct ast_channel c0,
struct ast_channel c1 
)

Make two channels compatible for early bridging.

Parameters:
c0First channel part of the bridge
c1Second channel part of the bridge
Since:
1.8

Definition at line 1386 of file rtp_engine.c.

References ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_debug, 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, ast_channel::name, ast_channel::tech, ast_channel_tech::type, and unref_instance_cond().

Referenced by dial_exec_full(), and do_forward().

{
   struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
      *vinstance0 = NULL, *vinstance1 = NULL,
      *tinstance0 = NULL, *tinstance1 = NULL;
   struct ast_rtp_glue *glue0, *glue1;
   enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
   enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
   format_t codec0 = 0, codec1 = 0;
   int res = 0;

   /* Lock both channels so we can look for the glue that binds them together */
   ast_channel_lock(c0);
   while (ast_channel_trylock(c1)) {
      ast_channel_unlock(c0);
      usleep(1);
      ast_channel_lock(c0);
   }

   /* Grab glue that binds each channel to something using the RTP engine */
   if (!(glue0 = ast_rtp_instance_get_glue(c0->tech->type)) || !(glue1 = ast_rtp_instance_get_glue(c1->tech->type))) {
      ast_debug(1, "Can't find native functions for channel '%s'\n", glue0 ? c1->name : c0->name);
      goto done;
   }

   audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
   video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;

   audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
   video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;

   /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
   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)) {
      audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
   }
   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)) {
      audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
   }
   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) {
      codec0 = glue0->get_codec(c0);
   }
   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) {
      codec1 = glue1->get_codec(c1);
   }

   /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
   if (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE) {
      goto done;
   }

   /* Make sure we have matching codecs */
   if (!(codec0 & codec1)) {
      goto done;
   }

   ast_rtp_codecs_payloads_copy(&instance0->codecs, &instance1->codecs, instance1);

   if (vinstance0 && vinstance1) {
      ast_rtp_codecs_payloads_copy(&vinstance0->codecs, &vinstance1->codecs, vinstance1);
   }
   if (tinstance0 && tinstance1) {
      ast_rtp_codecs_payloads_copy(&tinstance0->codecs, &tinstance1->codecs, tinstance1);
   }

   res = 0;

done:
   ast_channel_unlock(c0);
   ast_channel_unlock(c1);

   unref_instance_cond(&instance0);
   unref_instance_cond(&instance1);
   unref_instance_cond(&vinstance0);
   unref_instance_cond(&vinstance1);
   unref_instance_cond(&tinstance0);
   unref_instance_cond(&tinstance1);

   if (!res) {
      ast_debug(1, "Seeded SDP of '%s' with that of '%s'\n", c0->name, c1 ? c1->name : "<unspecified>");
   }
}
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 781 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(), skinny_new(), start_rtp(), and unistim_new().

{
   return instance->engine->fd ? instance->engine->fd(instance, rtcp) : -1;
}
struct ast_rtp_glue* ast_rtp_instance_get_active_glue ( struct ast_rtp_instance instance) [read]

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 1748 of file rtp_engine.c.

References ast_rtp_instance::glue.

{
   return instance->glue;
}
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 414 of file rtp_engine.c.

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

{
   if (ast_sockaddr_cmp(address, &instance->local_address) != 0) {
      ast_sockaddr_copy(address, &instance->local_address);
      return 1;
   }

   return 0;
}
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 431 of file rtp_engine.c.

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

Referenced by sip_set_rtp_peer().

{
   if (ast_sockaddr_cmp(address, &instance->remote_address) != 0) {
      ast_sockaddr_copy(address, &instance->remote_address);
      return 1;
   }

   return 0;
}
struct ast_rtp_instance* ast_rtp_instance_get_bridged ( struct ast_rtp_instance instance) [read]

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 1381 of file rtp_engine.c.

References ast_rtp_instance::bridged.

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

{
   return instance->bridged;
}
struct ast_channel* ast_rtp_instance_get_chan ( struct ast_rtp_instance instance) [read]

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 1753 of file rtp_engine.c.

References ast_rtp_instance::chan.

{
   return instance->chan;
}
struct ast_rtp_codecs* ast_rtp_instance_get_codecs ( struct ast_rtp_instance instance) [read]

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 478 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().

{
   return &instance->codecs;
}
struct ast_rtp_engine* ast_rtp_instance_get_engine ( struct ast_rtp_instance instance) [read]

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 1743 of file rtp_engine.c.

References ast_rtp_instance::engine.

{
   return instance->engine;
}
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 455 of file rtp_engine.c.

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

{
   if (instance->engine->extended_prop_get) {
      return instance->engine->extended_prop_get(instance, property);
   }

   return NULL;
}
struct ast_rtp_glue* ast_rtp_instance_get_glue ( const char *  type) [read]

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 786 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().

{
   struct ast_rtp_glue *glue = NULL;

   AST_RWLIST_RDLOCK(&glues);

   AST_RWLIST_TRAVERSE(&glues, glue, entry) {
      if (!strcasecmp(glue->type, type)) {
         break;
      }
   }

   AST_RWLIST_UNLOCK(&glues);

   return glue;
}
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 1733 of file rtp_engine.c.

References ast_rtp_instance::holdtimeout.

Referenced by check_rtp_timeout().

{
   return instance->holdtimeout;
}
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 1738 of file rtp_engine.c.

References ast_rtp_instance::keepalive.

Referenced by check_rtp_timeout().

{
   return instance->keepalive;
}
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 425 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(), skinny_set_rtp_peer(), and start_rtp().

{
   ast_sockaddr_copy(address, &instance->local_address);
}
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 473 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().

{
   return instance->properties[property];
}
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 1568 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(), and sip_hangup().

{
   struct ast_rtp_instance_stats stats = { 0, };
   enum ast_rtp_instance_stat stat;

   /* Determine what statistics we will need to retrieve based on field passed in */
   if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY) {
      stat = AST_RTP_INSTANCE_STAT_ALL;
   } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
      stat = AST_RTP_INSTANCE_STAT_COMBINED_JITTER;
   } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
      stat = AST_RTP_INSTANCE_STAT_COMBINED_LOSS;
   } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
      stat = AST_RTP_INSTANCE_STAT_COMBINED_RTT;
   } else {
      return NULL;
   }

   /* Attempt to actually retrieve the statistics we need to generate the quality string */
   if (ast_rtp_instance_get_stats(instance, &stats, stat)) {
      return NULL;
   }

   /* Now actually fill the buffer with the good information */
   if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY) {
      snprintf(buf, size, "ssrc=%i;themssrc=%u;lp=%u;rxjitter=%f;rxcount=%u;txjitter=%f;txcount=%u;rlp=%u;rtt=%f",
          stats.local_ssrc, stats.remote_ssrc, stats.rxploss, stats.txjitter, stats.rxcount, stats.rxjitter, stats.txcount, stats.txploss, stats.rtt);
   } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
      snprintf(buf, size, "minrxjitter=%f;maxrxjitter=%f;avgrxjitter=%f;stdevrxjitter=%f;reported_minjitter=%f;reported_maxjitter=%f;reported_avgjitter=%f;reported_stdevjitter=%f;",
          stats.local_minjitter, stats.local_maxjitter, stats.local_normdevjitter, sqrt(stats.local_stdevjitter), stats.remote_minjitter, stats.remote_maxjitter, stats.remote_normdevjitter, sqrt(stats.remote_stdevjitter));
   } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
      snprintf(buf, size, "minrxlost=%f;maxrxlost=%f;avgrxlost=%f;stdevrxlost=%f;reported_minlost=%f;reported_maxlost=%f;reported_avglost=%f;reported_stdevlost=%f;",
          stats.local_minrxploss, stats.local_maxrxploss, stats.local_normdevrxploss, sqrt(stats.local_stdevrxploss), stats.remote_minrxploss, stats.remote_maxrxploss, stats.remote_normdevrxploss, sqrt(stats.remote_stdevrxploss));
   } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
      snprintf(buf, size, "minrtt=%f;maxrtt=%f;avgrtt=%f;stdevrtt=%f;", stats.minrtt, stats.maxrtt, stats.normdevrtt, stats.stdevrtt);
   }

   return buf;
}
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;
 ast_rtp_instance_get_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 442 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(), multicast_rtp_write(), multicast_send_control_packet(), oh323_set_rtp_peer(), process_cn_rfc3389(), process_dtmf_rfc2833(), process_sdp(), remote_bridge_loop(), skinny_set_rtp_peer(), and transmit_modify_with_sdp().

{
   ast_sockaddr_copy(address, &instance->remote_address);
}
struct ast_srtp* ast_rtp_instance_get_srtp ( struct ast_rtp_instance instance) [read]

Definition at line 1797 of file rtp_engine.c.

References ast_rtp_instance::srtp.

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

{
   return instance->srtp;
}
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 1563 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(), and show_chanstats_cb().

{
   return instance->engine->get_stat ? instance->engine->get_stat(instance, stats, stat) : -1;
}
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 1728 of file rtp_engine.c.

References ast_rtp_instance::timeout.

Referenced by check_rtp_timeout().

{
   return instance->timeout;
}
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 1652 of file rtp_engine.c.

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

Referenced by sip_setoption().

{
   struct ast_rtp_glue *glue;
   struct ast_rtp_instance *peer_instance = NULL;
   int res = -1;

   if (!instance->engine->make_compatible) {
      return -1;
   }

   ast_channel_lock(peer);

   if (!(glue = ast_rtp_instance_get_glue(peer->tech->type))) {
      ast_channel_unlock(peer);
      return -1;
   }

   glue->get_rtp_info(peer, &peer_instance);

   if (!peer_instance || peer_instance->engine != instance->engine) {
      ast_channel_unlock(peer);
      ao2_ref(peer_instance, -1);
      peer_instance = NULL;
      return -1;
   }

   res = instance->engine->make_compatible(chan, instance, peer, peer_instance);

   ast_channel_unlock(peer);

   ao2_ref(peer_instance, -1);
   peer_instance = NULL;

   return res;
}
struct ast_rtp_instance* ast_rtp_instance_new ( const char *  engine_name,
struct sched_context sched,
const struct ast_sockaddr sa,
void *  data 
) [read]

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 303 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().

{
   struct ast_sockaddr address = {{0,}};
   struct ast_rtp_instance *instance = NULL;
   struct ast_rtp_engine *engine = NULL;

   AST_RWLIST_RDLOCK(&engines);

   /* If an engine name was specified try to use it or otherwise use the first one registered */
   if (!ast_strlen_zero(engine_name)) {
      AST_RWLIST_TRAVERSE(&engines, engine, entry) {
         if (!strcmp(engine->name, engine_name)) {
            break;
         }
      }
   } else {
      engine = AST_RWLIST_FIRST(&engines);
   }

   /* If no engine was actually found bail out now */
   if (!engine) {
      ast_log(LOG_ERROR, "No RTP engine was found. Do you have one loaded?\n");
      AST_RWLIST_UNLOCK(&engines);
      return NULL;
   }

   /* Bump up the reference count before we return so the module can not be unloaded */
   ast_module_ref(engine->mod);

   AST_RWLIST_UNLOCK(&engines);

   /* Allocate a new RTP instance */
   if (!(instance = ao2_alloc(sizeof(*instance), instance_destructor))) {
      ast_module_unref(engine->mod);
      return NULL;
   }
   instance->engine = engine;
   ast_sockaddr_copy(&instance->local_address, sa);
   ast_sockaddr_copy(&address, sa);

   ast_debug(1, "Using engine '%s' for RTP instance '%p'\n", engine->name, instance);

   /* And pass it off to the engine to setup */
   if (instance->engine->new(instance, sched, &address, data)) {
      ast_debug(1, "Engine '%s' failed to setup RTP instance '%p'\n", engine->name, instance);
      ao2_ref(instance, -1);
      return NULL;
   }

   ast_debug(1, "RTP instance '%p' is setup and ready to go\n", instance);

   return instance;
}
struct ast_frame* ast_rtp_instance_read ( struct ast_rtp_instance instance,
int  rtcp 
) [read]

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 374 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().

{
   return instance->engine->read(instance, rtcp);
}
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 1802 of file rtp_engine.c.

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

Referenced by check_rtp_timeout().

{
   if (instance->engine->sendcng) {
      return instance->engine->sendcng(instance, level);
   }

   return -1;
}
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 400 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().

{
   ast_sockaddr_copy(&instance->alt_remote_address, address);

   /* oink */

   if (instance->engine->alt_remote_address_set) {
      instance->engine->alt_remote_address_set(instance, &instance->alt_remote_address);
   }

   return 0;
}
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 359 of file rtp_engine.c.

References ast_rtp_instance::data.

Referenced by ast_rtp_new(), and multicast_rtp_new().

{
   instance->data = 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 448 of file rtp_engine.c.

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

{
   if (instance->engine->extended_prop_set) {
      instance->engine->extended_prop_set(instance, property, value);
   }
}
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 1718 of file rtp_engine.c.

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

Referenced by check_rtp_timeout(), and dialog_initialize_rtp().

{
   instance->holdtimeout = timeout;
}
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 1723 of file rtp_engine.c.

References ast_rtp_instance::keepalive.

Referenced by dialog_initialize_rtp().

{
   instance->keepalive = interval;
}
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 379 of file rtp_engine.c.

References ast_sockaddr_copy(), and ast_rtp_instance::local_address.

Referenced by ast_rtp_new().

{
   ast_sockaddr_copy(&instance->local_address, address);
   return 0;
}
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 464 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(), and start_rtp().

{
   instance->properties[property] = value;

   if (instance->engine->prop_set) {
      instance->engine->prop_set(instance, property, value);
   }
}
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 769 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().

{
   return instance->engine->qos ? instance->engine->qos(instance, tos, cos, desc) : -1;
}
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 1642 of file rtp_engine.c.

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

Referenced by sip_new(), and sip_setoption().

{
   return instance->engine->set_read_format ? instance->engine->set_read_format(instance, format) : -1;
}
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 386 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().

{
   ast_sockaddr_copy(&instance->remote_address, address);

   /* moo */

   if (instance->engine->remote_address_set) {
      instance->engine->remote_address_set(instance, &instance->remote_address);
   }

   return 0;
}
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 1608 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().

{
   char quality_buf[AST_MAX_USER_FIELD], *quality;
   struct ast_channel *bridge = ast_bridged_channel(chan);

   if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
      pbx_builtin_setvar_helper(chan, "RTPAUDIOQOS", quality);
      if (bridge) {
         pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSBRIDGED", quality);
      }
   }

   if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, quality_buf, sizeof(quality_buf)))) {
      pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSJITTER", quality);
      if (bridge) {
         pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSJITTERBRIDGED", quality);
      }
   }

   if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, quality_buf, sizeof(quality_buf)))) {
      pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSLOSS", quality);
      if (bridge) {
         pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSLOSSBRIDGED", quality);
      }
   }

   if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, quality_buf, sizeof(quality_buf)))) {
      pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSRTT", quality);
      if (bridge) {
         pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSRTTBRIDGED", quality);
      }
   }
}
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 1713 of file rtp_engine.c.

References ast_rtp_instance::timeout.

Referenced by check_rtp_timeout(), and dialog_initialize_rtp().

{
   instance->timeout = timeout;
}
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 1647 of file rtp_engine.c.

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

Referenced by sip_new(), and sip_setoption().

{
   return instance->engine->set_write_format ? instance->engine->set_write_format(instance, format) : -1;
}
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 774 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().

{
   if (instance->engine->stop) {
      instance->engine->stop(instance);
   }
}
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 1704 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().

{
   if (instance->engine->stun_request) {
      instance->engine->stun_request(instance, suggestion, username);
   }
}
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 755 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().

{
   if (instance->engine->update_source) {
      instance->engine->update_source(instance);
   }
}
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 369 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().

{
   return instance->engine->write(instance, frame);
}
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 698 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().

{
   format_t format;
   int found = 0;

   if (!buf) {
      return NULL;
   }

   ast_str_append(&buf, 0, "0x%llx (", (unsigned long long) capability);

   for (format = 1; format < AST_RTP_MAX; format <<= 1) {
      if (capability & format) {
         const char *name = ast_rtp_lookup_mime_subtype2(asterisk_format, format, options);
         ast_str_append(&buf, 0, "%s|", name);
         found = 1;
      }
   }

   ast_str_append(&buf, 0, "%s", found ? ")" : "nothing)");

   return ast_str_buffer(buf);
}
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 668 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().

{
   int i;

   for (i = 0; i < ARRAY_LEN(ast_rtp_mime_types); i++) {
      if (ast_rtp_mime_types[i].payload_type.code == code && ast_rtp_mime_types[i].payload_type.asterisk_format == asterisk_format) {
         if (asterisk_format && (code == AST_FORMAT_G726_AAL2) && (options & AST_RTP_OPT_G726_NONSTANDARD)) {
            return "G726-32";
         } else {
            return ast_rtp_mime_types[i].subtype;
         }
      }
   }

   return "";
}
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 685 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().

{
   unsigned int i;

   for (i = 0; i < ARRAY_LEN(ast_rtp_mime_types); ++i) {
      if ((ast_rtp_mime_types[i].payload_type.code == code) && (ast_rtp_mime_types[i].payload_type.asterisk_format == asterisk_format)) {
         return ast_rtp_mime_types[i].sample_rate;
      }
   }

   return 0;
}
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 1558 of file rtp_engine.c.

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

Referenced by sip_write().

{
   return instance->engine->red_buffer ? instance->engine->red_buffer(instance, frame) : -1;
}
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 1553 of file rtp_engine.c.

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

Referenced by process_sdp().

{
   return instance->engine->red_init ? instance->engine->red_init(instance, buffer_time, payloads, generations) : -1;
}
static void instance_destructor ( void *  obj) [static]

Definition at line 276 of file rtp_engine.c.

References ast_debug, ast_module_unref(), ast_rtp_instance::data, ast_srtp_res::destroy, ast_rtp_engine::destroy, ast_rtp_instance::engine, ast_rtp_engine::mod, ast_rtp_engine::name, and ast_rtp_instance::srtp.

Referenced by ast_rtp_instance_new().

{
   struct ast_rtp_instance *instance = obj;

   /* Pass us off to the engine to destroy */
   if (instance->data && instance->engine->destroy(instance)) {
      ast_debug(1, "Engine '%s' failed to destroy RTP instance '%p'\n", instance->engine->name, instance);
      return;
   }

   if (instance->srtp) {
      res_srtp->destroy(instance->srtp);
   }

   /* Drop our engine reference */
   ast_module_unref(instance->engine->mod);

   ast_debug(1, "Destroyed RTP instance '%p'\n", instance);
}
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 
) [static]

Definition at line 803 of file rtp_engine.c.

References AST_BRIDGE_COMPLETE, AST_BRIDGE_DTMF_CHANNEL_0, AST_BRIDGE_DTMF_CHANNEL_1, AST_BRIDGE_FAILED, AST_BRIDGE_FAILED_NOWARN, AST_BRIDGE_IGNORE_SIGS, AST_BRIDGE_RETRY, ast_channel_connected_line_macro(), ast_channel_redirecting_macro(), ast_channel_unlock, ast_check_hangup(), AST_CONTROL_CONNECTED_LINE, AST_CONTROL_HOLD, AST_CONTROL_REDIRECTING, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_UNHOLD, AST_CONTROL_UPDATE_RTP_PEER, AST_CONTROL_VIDUPDATE, ast_debug, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_framehook_list_is_empty(), ast_frfree, ast_indicate_data(), ast_poll_channel_add(), ast_poll_channel_del(), ast_read(), ast_waitfor_n(), ast_write(), ast_channel::audiohooks, ast_rtp_instance::bridged, ast_frame::data, ast_frame::datalen, ast_rtp_instance::engine, ast_channel::framehooks, ast_frame::frametype, ast_frame_subclass::integer, ast_rtp_engine::local_bridge, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::name, ast_frame::ptr, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_frame::subclass, and ast_channel::tech_pvt.

Referenced by ast_rtp_instance_bridge().

{
   enum ast_bridge_result res = AST_BRIDGE_FAILED;
   struct ast_channel *who = NULL, *other = NULL, *cs[3] = { NULL, };
   struct ast_frame *fr = NULL;

   /* Start locally bridging both instances */
   if (instance0->engine->local_bridge && instance0->engine->local_bridge(instance0, instance1)) {
      ast_debug(1, "Failed to locally bridge %s to %s, backing out.\n", c0->name, c1->name);
      ast_channel_unlock(c0);
      ast_channel_unlock(c1);
      return AST_BRIDGE_FAILED_NOWARN;
   }
   if (instance1->engine->local_bridge && instance1->engine->local_bridge(instance1, instance0)) {
      ast_debug(1, "Failed to locally bridge %s to %s, backing out.\n", c1->name, c0->name);
      if (instance0->engine->local_bridge) {
         instance0->engine->local_bridge(instance0, NULL);
      }
      ast_channel_unlock(c0);
      ast_channel_unlock(c1);
      return AST_BRIDGE_FAILED_NOWARN;
   }

   ast_channel_unlock(c0);
   ast_channel_unlock(c1);

   instance0->bridged = instance1;
   instance1->bridged = instance0;

   ast_poll_channel_add(c0, c1);

   /* Hop into a loop waiting for a frame from either channel */
   cs[0] = c0;
   cs[1] = c1;
   cs[2] = NULL;
   for (;;) {
      /* If the underlying formats have changed force this bridge to break */
      if ((c0->rawreadformat != c1->rawwriteformat) || (c1->rawreadformat != c0->rawwriteformat)) {
         ast_debug(1, "rtp-engine-local-bridge: Oooh, formats changed, backing out\n");
         res = AST_BRIDGE_FAILED_NOWARN;
         break;
      }
      /* Check if anything changed */
      if ((c0->tech_pvt != pvt0) ||
          (c1->tech_pvt != pvt1) ||
          (c0->masq || c0->masqr || c1->masq || c1->masqr) ||
          (c0->monitor || c0->audiohooks || c1->monitor || c1->audiohooks) ||
          (!ast_framehook_list_is_empty(c0->framehooks) || !ast_framehook_list_is_empty(c1->framehooks))) {
         ast_debug(1, "rtp-engine-local-bridge: Oooh, something is weird, backing out\n");
         /* If a masquerade needs to happen we have to try to read in a frame so that it actually happens. Without this we risk being called again and going into a loop */
         if ((c0->masq || c0->masqr) && (fr = ast_read(c0))) {
            ast_frfree(fr);
         }
         if ((c1->masq || c1->masqr) && (fr = ast_read(c1))) {
            ast_frfree(fr);
         }
         res = AST_BRIDGE_RETRY;
         break;
      }
      /* Wait on a channel to feed us a frame */
      if (!(who = ast_waitfor_n(cs, 2, &timeoutms))) {
         if (!timeoutms) {
            res = AST_BRIDGE_RETRY;
            break;
         }
         ast_debug(2, "rtp-engine-local-bridge: Ooh, empty read...\n");
         if (ast_check_hangup(c0) || ast_check_hangup(c1)) {
            break;
         }
         continue;
      }
      /* Read in frame from channel */
      fr = ast_read(who);
      other = (who == c0) ? c1 : c0;
      /* Depending on the frame we may need to break out of our bridge */
      if (!fr || ((fr->frametype == AST_FRAME_DTMF_BEGIN || fr->frametype == AST_FRAME_DTMF_END) &&
             ((who == c0) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) |
             ((who == c1) && (flags & AST_BRIDGE_DTMF_CHANNEL_1)))) {
         /* Record received frame and who */
         *fo = fr;
         *rc = who;
         ast_debug(1, "rtp-engine-local-bridge: Ooh, got a %s\n", fr ? "digit" : "hangup");
         res = AST_BRIDGE_COMPLETE;
         break;
      } else if ((fr->frametype == AST_FRAME_CONTROL) && !(flags & AST_BRIDGE_IGNORE_SIGS)) {
         if ((fr->subclass.integer == AST_CONTROL_HOLD) ||
             (fr->subclass.integer == AST_CONTROL_UNHOLD) ||
             (fr->subclass.integer == AST_CONTROL_VIDUPDATE) ||
             (fr->subclass.integer == AST_CONTROL_SRCUPDATE) ||
             (fr->subclass.integer == AST_CONTROL_T38_PARAMETERS) ||
             (fr->subclass.integer == AST_CONTROL_UPDATE_RTP_PEER)) {
            /* If we are going on hold, then break callback mode and P2P bridging */
            if (fr->subclass.integer == AST_CONTROL_HOLD) {
               if (instance0->engine->local_bridge) {
                  instance0->engine->local_bridge(instance0, NULL);
               }
               if (instance1->engine->local_bridge) {
                  instance1->engine->local_bridge(instance1, NULL);
               }
               instance0->bridged = NULL;
               instance1->bridged = NULL;
            } else if (fr->subclass.integer == AST_CONTROL_UNHOLD) {
               if (instance0->engine->local_bridge) {
                  instance0->engine->local_bridge(instance0, instance1);
               }
               if (instance1->engine->local_bridge) {
                  instance1->engine->local_bridge(instance1, instance0);
               }
               instance0->bridged = instance1;
               instance1->bridged = instance0;
            }
            /* Since UPDATE_BRIDGE_PEER is only used by the bridging code, don't forward it */
            if (fr->subclass.integer != AST_CONTROL_UPDATE_RTP_PEER) {
               ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
            }
            ast_frfree(fr);
         } else if (fr->subclass.integer == AST_CONTROL_CONNECTED_LINE) {
            if (ast_channel_connected_line_macro(who, other, fr, other == c0, 1)) {
               ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
            }
            ast_frfree(fr);
         } else if (fr->subclass.integer == AST_CONTROL_REDIRECTING) {
            if (ast_channel_redirecting_macro(who, other, fr, other == c0, 1)) {
               ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
            }
            ast_frfree(fr);
         } else {
            *fo = fr;
            *rc = who;
            ast_debug(1, "rtp-engine-local-bridge: Got a FRAME_CONTROL (%d) frame on channel %s\n", fr->subclass.integer, who->name);
            res = AST_BRIDGE_COMPLETE;
            break;
         }
      } else {
         if ((fr->frametype == AST_FRAME_DTMF_BEGIN) ||
             (fr->frametype == AST_FRAME_DTMF_END) ||
             (fr->frametype == AST_FRAME_VOICE) ||
             (fr->frametype == AST_FRAME_VIDEO) ||
             (fr->frametype == AST_FRAME_IMAGE) ||
             (fr->frametype == AST_FRAME_HTML) ||
             (fr->frametype == AST_FRAME_MODEM) ||
             (fr->frametype == AST_FRAME_TEXT)) {
            ast_write(other, fr);
         }

         ast_frfree(fr);
      }
      /* Swap priority */
      cs[2] = cs[0];
      cs[0] = cs[1];
      cs[1] = cs[2];
   }

   /* Stop locally bridging both instances */
   if (instance0->engine->local_bridge) {
      instance0->engine->local_bridge(instance0, NULL);
   }
   if (instance1->engine->local_bridge) {
      instance1->engine->local_bridge(instance1, NULL);
   }

   instance0->bridged = NULL;
   instance1->bridged = NULL;

   ast_poll_channel_del(c0, c1);

   return res;
}
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 
) [static]

Definition at line 972 of file rtp_engine.c.

References AST_BRIDGE_COMPLETE, AST_BRIDGE_DTMF_CHANNEL_0, AST_BRIDGE_DTMF_CHANNEL_1, AST_BRIDGE_FAILED, AST_BRIDGE_IGNORE_SIGS, AST_BRIDGE_RETRY, ast_channel_connected_line_macro(), ast_channel_redirecting_macro(), ast_channel_unlock, ast_check_hangup(), AST_CONTROL_CONNECTED_LINE, AST_CONTROL_HOLD, AST_CONTROL_REDIRECTING, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_UNHOLD, AST_CONTROL_UPDATE_RTP_PEER, AST_CONTROL_VIDUPDATE, ast_debug, AST_FLAG_ZOMBIE, AST_FRAME_CONTROL, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_HTML, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_framehook_list_is_empty(), ast_frfree, ast_getformatname(), ast_indicate_data(), ast_log(), ast_poll_channel_add(), ast_poll_channel_del(), ast_read(), ast_rtp_instance_get_glue(), ast_rtp_instance_get_remote_address(), ast_sockaddr_cmp(), ast_sockaddr_copy(), ast_sockaddr_isnull(), ast_sockaddr_stringify(), ast_test_flag, ast_waitfor_n(), ast_write(), ast_channel::audiohooks, ast_rtp_instance::bridged, ast_frame::data, ast_frame::datalen, ast_channel::framehooks, ast_frame::frametype, ast_rtp_glue::get_codec, ast_frame_subclass::integer, LOG_WARNING, ast_channel::masq, ast_channel::masqr, ast_channel::monitor, ast_channel::name, ast_frame::ptr, ast_frame::subclass, ast_channel::tech, ast_channel::tech_pvt, ast_channel_tech::type, and ast_rtp_glue::update_peer.

Referenced by ast_rtp_instance_bridge().

{
   enum ast_bridge_result res = AST_BRIDGE_FAILED;
   struct ast_channel *who = NULL, *other = NULL, *cs[3] = { NULL, };
   format_t oldcodec0 = codec0, oldcodec1 = codec1;
   struct ast_sockaddr ac1 = {{0,}}, vac1 = {{0,}}, tac1 = {{0,}}, ac0 = {{0,}}, vac0 = {{0,}}, tac0 = {{0,}};
   struct ast_sockaddr t1 = {{0,}}, vt1 = {{0,}}, tt1 = {{0,}}, t0 = {{0,}}, vt0 = {{0,}}, tt0 = {{0,}};
   struct ast_frame *fr = NULL;

   /* Test the first channel */
   if (!(glue0->update_peer(c0, instance1, vinstance1, tinstance1, codec1, 0))) {
      ast_rtp_instance_get_remote_address(instance1, &ac1);
      if (vinstance1) {
         ast_rtp_instance_get_remote_address(vinstance1, &vac1);
      }
      if (tinstance1) {
         ast_rtp_instance_get_remote_address(tinstance1, &tac1);
      }
   } else {
      ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", c0->name, c1->name);
   }

   /* Test the second channel */
   if (!(glue1->update_peer(c1, instance0, vinstance0, tinstance0, codec0, 0))) {
      ast_rtp_instance_get_remote_address(instance0, &ac0);
      if (vinstance0) {
         ast_rtp_instance_get_remote_address(instance0, &vac0);
      }
      if (tinstance0) {
         ast_rtp_instance_get_remote_address(instance0, &tac0);
      }
   } else {
      ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", c1->name, c0->name);
   }

   ast_channel_unlock(c0);
   ast_channel_unlock(c1);

   instance0->bridged = instance1;
   instance1->bridged = instance0;

   ast_poll_channel_add(c0, c1);

   /* Go into a loop handling any stray frames that may come in */
   cs[0] = c0;
   cs[1] = c1;
   cs[2] = NULL;
   for (;;) {
      /* Check if anything changed */
      if ((c0->tech_pvt != pvt0) ||
          (c1->tech_pvt != pvt1) ||
          (c0->masq || c0->masqr || c1->masq || c1->masqr) ||
          (c0->monitor || c0->audiohooks || c1->monitor || c1->audiohooks) ||
          (!ast_framehook_list_is_empty(c0->framehooks) || !ast_framehook_list_is_empty(c1->framehooks))) {
         ast_debug(1, "Oooh, something is weird, backing out\n");
         res = AST_BRIDGE_RETRY;
         break;
      }

      /* Check if they have changed their address */
      ast_rtp_instance_get_remote_address(instance1, &t1);
      if (vinstance1) {
         ast_rtp_instance_get_remote_address(vinstance1, &vt1);
      }
      if (tinstance1) {
         ast_rtp_instance_get_remote_address(tinstance1, &tt1);
      }
      if (glue1->get_codec) {
         codec1 = glue1->get_codec(c1);
      }

      ast_rtp_instance_get_remote_address(instance0, &t0);
      if (vinstance0) {
         ast_rtp_instance_get_remote_address(vinstance0, &vt0);
      }
      if (tinstance0) {
         ast_rtp_instance_get_remote_address(tinstance0, &tt0);
      }
      if (glue0->get_codec) {
         codec0 = glue0->get_codec(c0);
      }

      if ((ast_sockaddr_cmp(&t1, &ac1)) ||
          (vinstance1 && ast_sockaddr_cmp(&vt1, &vac1)) ||
          (tinstance1 && ast_sockaddr_cmp(&tt1, &tac1)) ||
          (codec1 != oldcodec1)) {
         ast_debug(1, "Oooh, '%s' changed end address to %s (format %s)\n",
              c1->name, ast_sockaddr_stringify(&t1),
              ast_getformatname(codec1));
         ast_debug(1, "Oooh, '%s' changed end vaddress to %s (format %s)\n",
              c1->name, ast_sockaddr_stringify(&vt1),
              ast_getformatname(codec1));
         ast_debug(1, "Oooh, '%s' changed end taddress to %s (format %s)\n",
              c1->name, ast_sockaddr_stringify(&tt1),
              ast_getformatname(codec1));
         ast_debug(1, "Oooh, '%s' was %s/(format %s)\n",
              c1->name, ast_sockaddr_stringify(&ac1),
              ast_getformatname(oldcodec1));
         ast_debug(1, "Oooh, '%s' was %s/(format %s)\n",
              c1->name, ast_sockaddr_stringify(&vac1),
              ast_getformatname(oldcodec1));
         ast_debug(1, "Oooh, '%s' was %s/(format %s)\n",
              c1->name, ast_sockaddr_stringify(&tac1),
              ast_getformatname(oldcodec1));
         if (glue0->update_peer(c0,
                      ast_sockaddr_isnull(&t1)  ? NULL : instance1,
                      ast_sockaddr_isnull(&vt1) ? NULL : vinstance1,
                      ast_sockaddr_isnull(&tt1) ? NULL : tinstance1,
                      codec1, 0)) {
            ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c0->name, c1->name);
         }
         ast_sockaddr_copy(&ac1, &t1);
         ast_sockaddr_copy(&vac1, &vt1);
         ast_sockaddr_copy(&tac1, &tt1);
         oldcodec1 = codec1;
      }
      if ((ast_sockaddr_cmp(&t0, &ac0)) ||
          (vinstance0 && ast_sockaddr_cmp(&vt0, &vac0)) ||
          (tinstance0 && ast_sockaddr_cmp(&tt0, &tac0)) ||
          (codec0 != oldcodec0)) {
         ast_debug(1, "Oooh, '%s' changed end address to %s (format %s)\n",
              c0->name, ast_sockaddr_stringify(&t0),
              ast_getformatname(codec0));
         ast_debug(1, "Oooh, '%s' was %s/(format %s)\n",
              c0->name, ast_sockaddr_stringify(&ac0),
              ast_getformatname(oldcodec0));
         if (glue1->update_peer(c1, t0.len ? instance0 : NULL,
                  vt0.len ? vinstance0 : NULL,
                  tt0.len ? tinstance0 : NULL,
                  codec0, 0)) {
            ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", c1->name, c0->name);
         }
         ast_sockaddr_copy(&ac0, &t0);
         ast_sockaddr_copy(&vac0, &vt0);
         ast_sockaddr_copy(&tac0, &tt0);
         oldcodec0 = codec0;
      }

      /* Wait for frame to come in on the channels */
      if (!(who = ast_waitfor_n(cs, 2, &timeoutms))) {
         if (!timeoutms) {
            res = AST_BRIDGE_RETRY;
            break;
         }
         ast_debug(1, "Ooh, empty read...\n");
         if (ast_check_hangup(c0) || ast_check_hangup(c1)) {
            break;
         }
         continue;
      }
      fr = ast_read(who);
      other = (who == c0) ? c1 : c0;
      if (!fr || ((fr->frametype == AST_FRAME_DTMF_BEGIN || fr->frametype == AST_FRAME_DTMF_END) &&
             (((who == c0) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) ||
              ((who == c1) && (flags & AST_BRIDGE_DTMF_CHANNEL_1))))) {
         /* Break out of bridge */
         *fo = fr;
         *rc = who;
         ast_debug(1, "Oooh, got a %s\n", fr ? "digit" : "hangup");
         res = AST_BRIDGE_COMPLETE;
         break;
      } else if ((fr->frametype == AST_FRAME_CONTROL) && !(flags & AST_BRIDGE_IGNORE_SIGS)) {
         if ((fr->subclass.integer == AST_CONTROL_HOLD) ||
             (fr->subclass.integer == AST_CONTROL_UNHOLD) ||
             (fr->subclass.integer == AST_CONTROL_VIDUPDATE) ||
             (fr->subclass.integer == AST_CONTROL_SRCUPDATE) ||
             (fr->subclass.integer == AST_CONTROL_T38_PARAMETERS) ||
            (fr->subclass.integer == AST_CONTROL_UPDATE_RTP_PEER)) {
            if (fr->subclass.integer == AST_CONTROL_HOLD) {
               /* If we someone went on hold we want the other side to reinvite back to us */
               if (who == c0) {
                  glue1->update_peer(c1, NULL, NULL, NULL, 0, 0);
               } else {
                  glue0->update_peer(c0, NULL, NULL, NULL, 0, 0);
               }
            } else if (fr->subclass.integer == AST_CONTROL_UNHOLD ||
               fr->subclass.integer == AST_CONTROL_UPDATE_RTP_PEER) {
               /* If they went off hold they should go back to being direct, or if we have
                * been told to force a peer update, go ahead and do it. */
               if (who == c0) {
                  glue1->update_peer(c1, instance0, vinstance0, tinstance0, codec0, 0);
               } else {
                  glue0->update_peer(c0, instance1, vinstance1, tinstance1, codec1, 0);
               }
            }
            /* Update local address information */
            ast_rtp_instance_get_remote_address(instance0, &t0);
            ast_sockaddr_copy(&ac0, &t0);
            ast_rtp_instance_get_remote_address(instance1, &t1);
            ast_sockaddr_copy(&ac1, &t1);
            /* Update codec information */
            if (glue0->get_codec && c0->tech_pvt) {
               oldcodec0 = codec0 = glue0->get_codec(c0);
            }
            if (glue1->get_codec && c1->tech_pvt) {
               oldcodec1 = codec1 = glue1->get_codec(c1);
            }
            /* Since UPDATE_BRIDGE_PEER is only used by the bridging code, don't forward it */
            if (fr->subclass.integer != AST_CONTROL_UPDATE_RTP_PEER) {
               ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
            }
            ast_frfree(fr);
         } else if (fr->subclass.integer == AST_CONTROL_CONNECTED_LINE) {
            if (ast_channel_connected_line_macro(who, other, fr, other == c0, 1)) {
               ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
            }
            ast_frfree(fr);
         } else if (fr->subclass.integer == AST_CONTROL_REDIRECTING) {
            if (ast_channel_redirecting_macro(who, other, fr, other == c0, 1)) {
               ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
            }
            ast_frfree(fr);
         } else {
            *fo = fr;
            *rc = who;
            ast_debug(1, "Got a FRAME_CONTROL (%d) frame on channel %s\n", fr->subclass.integer, who->name);
            return AST_BRIDGE_COMPLETE;
         }
      } else {
         if ((fr->frametype == AST_FRAME_DTMF_BEGIN) ||
             (fr->frametype == AST_FRAME_DTMF_END) ||
             (fr->frametype == AST_FRAME_VOICE) ||
             (fr->frametype == AST_FRAME_VIDEO) ||
             (fr->frametype == AST_FRAME_IMAGE) ||
             (fr->frametype == AST_FRAME_HTML) ||
             (fr->frametype == AST_FRAME_MODEM) ||
             (fr->frametype == AST_FRAME_TEXT)) {
            ast_write(other, fr);
         }
         ast_frfree(fr);
      }
      /* Swap priority */
      cs[2] = cs[0];
      cs[0] = cs[1];
      cs[1] = cs[2];
   }

   if (ast_test_flag(c0, AST_FLAG_ZOMBIE)) {
      ast_debug(1, "Channel '%s' Zombie cleardown from bridge\n", c0->name);
   } else if (c0->tech_pvt != pvt0) {
      ast_debug(1, "Channel c0->'%s' pvt changed, in bridge with c1->'%s'\n", c0->name, c1->name);
   } else if (glue0 != ast_rtp_instance_get_glue(c0->tech->type)) {
      ast_debug(1, "Channel c0->'%s' technology changed, in bridge with c1->'%s'\n", c0->name, c1->name);
   } else if (glue0->update_peer(c0, NULL, NULL, NULL, 0, 0)) {
      ast_log(LOG_WARNING, "Channel '%s' failed to break RTP bridge\n", c0->name);
   }
   if (ast_test_flag(c1, AST_FLAG_ZOMBIE)) {
      ast_debug(1, "Channel '%s' Zombie cleardown from bridge\n", c1->name);
   } else if (c1->tech_pvt != pvt1) {
      ast_debug(1, "Channel c1->'%s' pvt changed, in bridge with c0->'%s'\n", c1->name, c0->name);
   } else if (glue1 != ast_rtp_instance_get_glue(c1->tech->type)) {
      ast_debug(1, "Channel c1->'%s' technology changed, in bridge with c0->'%s'\n", c1->name, c0->name);
   } else if (glue1->update_peer(c1, NULL, NULL, NULL, 0, 0)) {
      ast_log(LOG_WARNING, "Channel '%s' failed to break RTP bridge\n", c1->name);
   }

   instance0->bridged = NULL;
   instance1->bridged = NULL;

   ast_poll_channel_del(c0, c1);

   return res;
}
static void unref_instance_cond ( struct ast_rtp_instance **  instance) [static]

Conditionally unref an rtp instance.

Definition at line 1242 of file rtp_engine.c.

References ao2_ref.

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

{
   if (*instance) {
      ao2_ref(*instance, -1);
      *instance = NULL;
   }
}

Variable Documentation

struct engines engines [static]
struct glues glues [static]
struct ast_srtp_res* res_srtp = NULL

Definition at line 44 of file rtp_engine.c.

Definition at line 45 of file rtp_engine.c.

Referenced by ast_rtp_engine_srtp_is_registered().

struct ast_rtp_payload_type static_RTP_PT[AST_RTP_MAX_PT] [static]

Mapping between Asterisk codecs and rtp payload types.

Static (i.e., well-known) RTP payload types for our "AST_FORMAT..."s: also, our own choices for dynamic payload types. This is our master table for transmission

See http://www.iana.org/assignments/rtp-parameters for a list of assigned values

Definition at line 142 of file rtp_engine.c.