Asterisk - The Open Source Telephony Project GIT-master-f3e88d3
Data Structures | Macros | Functions | Variables
rtp_engine.c File Reference

Pluggable RTP Architecture. More...

#include "asterisk.h"
#include <sched.h>
#include <sys/time.h>
#include <time.h>
#include "asterisk/_private.h"
#include "asterisk/astobj2.h"
#include "asterisk/channel.h"
#include "asterisk/codec.h"
#include "asterisk/format.h"
#include "asterisk/format_cache.h"
#include "asterisk/format_cap.h"
#include "asterisk/json.h"
#include "asterisk/linkedlists.h"
#include "asterisk/lock.h"
#include "asterisk/logger.h"
#include "asterisk/manager.h"
#include "asterisk/module.h"
#include "asterisk/netsock2.h"
#include "asterisk/options.h"
#include "asterisk/pbx.h"
#include "asterisk/res_srtp.h"
#include "asterisk/rtp_engine.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/strings.h"
#include "asterisk/translate.h"
#include "asterisk/utils.h"
#include "asterisk/vector.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
 
struct  rtcp_message_payload
 
struct  rtp_extmap
 

Macros

#define MAX_RTP_MIME_TYPES   128
 
#define SET_AST_JSON_OBJ(target, name, obj)
 Set given json object into target with name. More...
 

Functions

static void add_static_payload (int payload, struct ast_format *format, int rtp_code)
 
uintmax_t ast_debug_category_dtls_id (void)
 
uintmax_t ast_debug_category_dtls_packet_id (void)
 
uintmax_t ast_debug_category_ice_id (void)
 
uintmax_t ast_debug_category_rtcp_id (void)
 
uintmax_t ast_debug_category_rtcp_packet_id (void)
 
uintmax_t ast_debug_category_rtp_id (void)
 
uintmax_t ast_debug_category_rtp_packet_id (void)
 
int ast_rtp_codecs_find_payload_code (struct ast_rtp_codecs *codecs, int payload)
 Search for the tx payload type in the ast_rtp_codecs structure. More...
 
unsigned int ast_rtp_codecs_get_framing (struct ast_rtp_codecs *codecs)
 Get the framing used for a set of codecs. More...
 
struct ast_rtp_payload_typeast_rtp_codecs_get_payload (struct ast_rtp_codecs *codecs, int payload)
 Retrieve rx payload mapped information by payload type. More...
 
struct ast_formatast_rtp_codecs_get_payload_format (struct ast_rtp_codecs *codecs, int payload)
 Retrieve the actual ast_format stored on the codecs structure for a specific tx payload type. More...
 
struct ast_formatast_rtp_codecs_get_preferred_format (struct ast_rtp_codecs *codecs)
 Retrieve rx preferred format. More...
 
enum ast_media_type ast_rtp_codecs_get_stream_type (struct ast_rtp_codecs *codecs)
 Determine the type of RTP stream media from the codecs mapped. More...
 
int ast_rtp_codecs_payload_code (struct ast_rtp_codecs *codecs, int asterisk_format, struct ast_format *format, int code)
 Retrieve a rx mapped payload type based on whether it is an Asterisk format and the code. More...
 
int ast_rtp_codecs_payload_code_sample_rate (struct ast_rtp_codecs *codecs, int asterisk_format, struct ast_format *format, int code, unsigned int sample_rate)
 Retrieve a rx mapped payload type based on whether it is an Asterisk format, the code and the sample rate. More...
 
int ast_rtp_codecs_payload_code_tx (struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code)
 Retrieve a tx mapped payload type based on whether it is an Asterisk format and the code. More...
 
int ast_rtp_codecs_payload_code_tx_sample_rate (struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code, unsigned int sample_rate)
 Retrieve a tx mapped payload type based on whether it is an Asterisk format and the code. More...
 
void ast_rtp_codecs_payload_formats (struct ast_rtp_codecs *codecs, struct ast_format_cap *astformats, int *nonastformats)
 Retrieve all formats that were found. More...
 
int ast_rtp_codecs_payload_replace_format (struct ast_rtp_codecs *codecs, int payload, struct ast_format *format)
 Update the format associated with a tx payload type in a codecs structure. More...
 
int ast_rtp_codecs_payload_set_rx (struct ast_rtp_codecs *codecs, int code, struct ast_format *format)
 Set a payload code for use with a specific Asterisk format. More...
 
int ast_rtp_codecs_payload_set_rx_sample_rate (struct ast_rtp_codecs *codecs, int code, struct ast_format *format, unsigned int sample_rate)
 Set a payload code with sample rate for use with a specific Asterisk format. More...
 
void ast_rtp_codecs_payloads_clear (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance)
 Clear rx and tx payload mapping information from an RTP instance. More...
 
void ast_rtp_codecs_payloads_copy (struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
 Copy payload information from one RTP instance to another. More...
 
void ast_rtp_codecs_payloads_destroy (struct ast_rtp_codecs *codecs)
 Destroy the contents of an RTP codecs structure (but not the structure itself) More...
 
int ast_rtp_codecs_payloads_initialize (struct ast_rtp_codecs *codecs)
 Initialize an RTP codecs structure. More...
 
void ast_rtp_codecs_payloads_set_m_type (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
 Record tx payload type information that was seen in an m= SDP line. More...
 
int ast_rtp_codecs_payloads_set_rtpmap_type (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload, char *mimetype, char *mimesubtype, enum ast_rtp_options options)
 Record tx payload type information that was seen in an a=rtpmap: SDP line. More...
 
int ast_rtp_codecs_payloads_set_rtpmap_type_rate (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int pt, char *mimetype, char *mimesubtype, enum ast_rtp_options options, unsigned int sample_rate)
 Set tx payload type to a known MIME media type for a codec with a specific sample rate. More...
 
void ast_rtp_codecs_payloads_unset (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
 Remove tx payload type mapped information. More...
 
void ast_rtp_codecs_payloads_xover (struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
 Crossover copy the tx payload mapping of src to the rx payload mapping of dest. More...
 
void ast_rtp_codecs_set_framing (struct ast_rtp_codecs *codecs, unsigned int framing)
 Set the framing used for a set of codecs. More...
 
int ast_rtp_codecs_set_preferred_format (struct ast_rtp_codecs *codecs, struct ast_format *format)
 Set the preferred format. More...
 
struct ast_jsonast_rtp_convert_stats_json (const struct ast_rtp_instance_stats *stats)
 Convert given stat instance into json format. More...
 
void ast_rtp_dtls_cfg_copy (const struct ast_rtp_dtls_cfg *src_cfg, struct ast_rtp_dtls_cfg *dst_cfg)
 Copy contents of a DTLS configuration structure. More...
 
void ast_rtp_dtls_cfg_free (struct ast_rtp_dtls_cfg *dtls_cfg)
 Free contents of a DTLS configuration structure. More...
 
int ast_rtp_dtls_cfg_parse (struct ast_rtp_dtls_cfg *dtls_cfg, const char *name, const char *value)
 Parse DTLS related configuration options. More...
 
int ast_rtp_dtls_cfg_validate (struct ast_rtp_dtls_cfg *dtls_cfg)
 Validates DTLS related configuration options. More...
 
struct ast_rtp_payload_typeast_rtp_engine_alloc_payload_type (void)
 Allocation routine for ast_rtp_payload_type. More...
 
int ast_rtp_engine_init (void)
 initializes the rtp engine arrays More...
 
int ast_rtp_engine_load_format (struct ast_format *format)
 Custom formats declared in codecs.conf at startup must be communicated to the rtp_engine so their mime type can payload number can be initialized. More...
 
int ast_rtp_engine_register2 (struct ast_rtp_engine *engine, struct ast_module *module)
 Register an RTP engine. More...
 
int ast_rtp_engine_register_srtp (struct ast_srtp_res *srtp_res, struct ast_srtp_policy_res *policy_res)
 
int ast_rtp_engine_srtp_is_registered (void)
 
int ast_rtp_engine_unload_format (struct ast_format *format)
 Formats requiring the use of a format attribute interface must have that interface registered in order for the rtp engine to handle it correctly. If an attribute interface is unloaded, this function must be called to notify the rtp_engine. More...
 
int ast_rtp_engine_unregister (struct ast_rtp_engine *engine)
 Unregister an RTP engine. More...
 
void ast_rtp_engine_unregister_srtp (void)
 
int ast_rtp_get_rate (const struct ast_format *format)
 Retrieve the sample rate of a format according to RTP specifications. More...
 
int ast_rtp_glue_register2 (struct ast_rtp_glue *glue, struct ast_module *module)
 Register RTP glue. More...
 
int ast_rtp_glue_unregister (struct ast_rtp_glue *glue)
 Unregister RTP glue. More...
 
int ast_rtp_instance_activate (struct ast_rtp_instance *instance)
 Indicate to the RTP engine that packets are now expected to be sent/received on the RTP instance. More...
 
int ast_rtp_instance_add_srtp_policy (struct ast_rtp_instance *instance, struct ast_srtp_policy *remote_policy, struct ast_srtp_policy *local_policy, int rtcp)
 Add or replace the SRTP policies for the given RTP instance. More...
 
void ast_rtp_instance_available_formats (struct ast_rtp_instance *instance, struct ast_format_cap *to_endpoint, struct ast_format_cap *to_asterisk, struct ast_format_cap *result)
 Request the formats that can be transcoded. More...
 
int ast_rtp_instance_bundle (struct ast_rtp_instance *child, struct ast_rtp_instance *parent)
 Request that an RTP instance be bundled with another. More...
 
void ast_rtp_instance_change_source (struct ast_rtp_instance *instance)
 Indicate a new source of audio has dropped in and the ssrc should change. More...
 
int ast_rtp_instance_destroy (struct ast_rtp_instance *instance)
 Destroy an RTP instance. More...
 
int ast_rtp_instance_dtmf_begin (struct ast_rtp_instance *instance, char digit)
 Begin sending a DTMF digit. More...
 
int ast_rtp_instance_dtmf_end (struct ast_rtp_instance *instance, char digit)
 Stop sending a DTMF digit. More...
 
int ast_rtp_instance_dtmf_end_with_duration (struct ast_rtp_instance *instance, char digit, unsigned int duration)
 
enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get (struct ast_rtp_instance *instance)
 Get the DTMF mode of an RTP instance. More...
 
int ast_rtp_instance_dtmf_mode_set (struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode)
 Set the DTMF mode that should be used. More...
 
int ast_rtp_instance_early_bridge (struct ast_channel *c0, struct ast_channel *c1)
 Early bridge two channels that use RTP instances. More...
 
void ast_rtp_instance_early_bridge_make_compatible (struct ast_channel *c_dst, struct ast_channel *c_src)
 Make two channels compatible for early bridging. More...
 
void ast_rtp_instance_extmap_clear (struct ast_rtp_instance *instance)
 Clear negotiated RTP extension information. More...
 
size_t ast_rtp_instance_extmap_count (struct ast_rtp_instance *instance)
 Get the number of known unique identifiers. More...
 
int ast_rtp_instance_extmap_enable (struct ast_rtp_instance *instance, int id, enum ast_rtp_extension extension, enum ast_rtp_extension_direction direction)
 Enable support for an RTP extension on an instance. More...
 
enum ast_rtp_extension_direction ast_rtp_instance_extmap_get_direction (struct ast_rtp_instance *instance, int id)
 Retrieve the negotiated direction for an RTP extension id. More...
 
enum ast_rtp_extension ast_rtp_instance_extmap_get_extension (struct ast_rtp_instance *instance, int id)
 Retrieve the extension for an RTP extension id. More...
 
int ast_rtp_instance_extmap_get_id (struct ast_rtp_instance *instance, enum ast_rtp_extension extension)
 Retrieve the id for an RTP extension. More...
 
const char * ast_rtp_instance_extmap_get_uri (struct ast_rtp_instance *instance, int id)
 Retrieve the URI for an RTP extension id. More...
 
int ast_rtp_instance_extmap_negotiate (struct ast_rtp_instance *instance, int id, enum ast_rtp_extension_direction direction, const char *uri, const char *attributes)
 Negotiate received RTP extension information. More...
 
int ast_rtp_instance_fd (struct ast_rtp_instance *instance, int rtcp)
 Get the file descriptor for an RTP session (or RTCP) More...
 
struct ast_rtp_glueast_rtp_instance_get_active_glue (struct ast_rtp_instance *instance)
 Get the RTP glue in use on an RTP instance. More...
 
int ast_rtp_instance_get_and_cmp_local_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the address of the local endpoint that we are sending RTP to, comparing its address to another. More...
 
int ast_rtp_instance_get_and_cmp_requested_target_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the requested target address of the remote endpoint and compare it to the given address. More...
 
struct ast_rtp_instanceast_rtp_instance_get_bridged (struct ast_rtp_instance *instance)
 Get the other RTP instance that an instance is bridged to. More...
 
const char * ast_rtp_instance_get_channel_id (struct ast_rtp_instance *instance)
 Get the unique ID of the channel that owns this RTP instance. More...
 
const char * ast_rtp_instance_get_cname (struct ast_rtp_instance *rtp)
 Retrieve the CNAME used in RTCP SDES items. More...
 
struct ast_rtp_codecsast_rtp_instance_get_codecs (struct ast_rtp_instance *instance)
 Get the codecs structure of an RTP instance. More...
 
void * ast_rtp_instance_get_data (struct ast_rtp_instance *instance)
 Get the data portion of an RTP instance. More...
 
struct ast_rtp_engine_dtlsast_rtp_instance_get_dtls (struct ast_rtp_instance *instance)
 Obtain a pointer to the DTLS support present on an RTP instance. More...
 
struct ast_rtp_engineast_rtp_instance_get_engine (struct ast_rtp_instance *instance)
 Get the RTP engine in use on an RTP instance. More...
 
void * ast_rtp_instance_get_extended_prop (struct ast_rtp_instance *instance, int property)
 Get the value of an RTP instance extended property. More...
 
struct ast_rtp_glueast_rtp_instance_get_glue (const char *type)
 Get the RTP glue that binds a channel to the RTP engine. More...
 
int ast_rtp_instance_get_hold_timeout (struct ast_rtp_instance *instance)
 Get the RTP timeout value for when an RTP instance is on hold. More...
 
struct ast_rtp_engine_iceast_rtp_instance_get_ice (struct ast_rtp_instance *instance)
 Obtain a pointer to the ICE support present on an RTP instance. More...
 
void ast_rtp_instance_get_incoming_source_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the incoming source address of the remote endpoint. More...
 
int ast_rtp_instance_get_keepalive (struct ast_rtp_instance *instance)
 Get the RTP keepalive interval. More...
 
time_t ast_rtp_instance_get_last_rx (const struct ast_rtp_instance *rtp)
 Get the last RTP reception time. More...
 
time_t ast_rtp_instance_get_last_tx (const struct ast_rtp_instance *rtp)
 Get the last RTP transmission time. More...
 
void ast_rtp_instance_get_local_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the local address that we are expecting RTP on. More...
 
int ast_rtp_instance_get_prop (struct ast_rtp_instance *instance, enum ast_rtp_property property)
 Get the value of an RTP instance property. More...
 
char * ast_rtp_instance_get_quality (struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size)
 Retrieve quality statistics about an RTP instance. More...
 
void ast_rtp_instance_get_requested_target_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the requested target address of the remote endpoint. More...
 
struct ast_srtpast_rtp_instance_get_srtp (struct ast_rtp_instance *instance, int rtcp)
 Obtain the SRTP instance associated with an RTP instance. More...
 
unsigned int ast_rtp_instance_get_ssrc (struct ast_rtp_instance *rtp)
 Retrieve the local SSRC value that we will be using. More...
 
int ast_rtp_instance_get_stats (struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
 Retrieve statistics about an RTP instance. More...
 
struct ast_jsonast_rtp_instance_get_stats_all_json (struct ast_rtp_instance *instance)
 Retrieve statistics about an RTP instance in json format. More...
 
int ast_rtp_instance_get_timeout (struct ast_rtp_instance *instance)
 Get the RTP timeout value. More...
 
int ast_rtp_instance_make_compatible (struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_channel *peer)
 Request that the underlying RTP engine make two RTP instances compatible with eachother. More...
 
struct ast_rtp_instanceast_rtp_instance_new (const char *engine_name, struct ast_sched_context *sched, const struct ast_sockaddr *sa, void *data)
 Create a new RTP instance. More...
 
struct ast_frameast_rtp_instance_read (struct ast_rtp_instance *instance, int rtcp)
 Receive a frame over RTP. More...
 
int ast_rtp_instance_sendcng (struct ast_rtp_instance *instance, int level)
 Send a comfort noise packet to the RTP instance. More...
 
void ast_rtp_instance_set_bridged (struct ast_rtp_instance *instance, struct ast_rtp_instance *bridged)
 Set the other RTP instance that an instance is bridged to. More...
 
void ast_rtp_instance_set_channel_id (struct ast_rtp_instance *instance, const char *uniqueid)
 Set the channel that owns this RTP instance. More...
 
void ast_rtp_instance_set_data (struct ast_rtp_instance *instance, void *data)
 Set the data portion of an RTP instance. More...
 
void ast_rtp_instance_set_extended_prop (struct ast_rtp_instance *instance, int property, void *value)
 Set the value of an RTP instance extended property. More...
 
void ast_rtp_instance_set_hold_timeout (struct ast_rtp_instance *instance, int timeout)
 Set the RTP timeout value for when the instance is on hold. More...
 
int ast_rtp_instance_set_incoming_source_address (struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
 Set the incoming source address of the remote endpoint that we are sending RTP to. More...
 
void ast_rtp_instance_set_keepalive (struct ast_rtp_instance *instance, int interval)
 Set the RTP keepalive interval. More...
 
void ast_rtp_instance_set_last_rx (struct ast_rtp_instance *rtp, time_t time)
 Set the last RTP reception time. More...
 
void ast_rtp_instance_set_last_tx (struct ast_rtp_instance *rtp, time_t time)
 Set the last RTP transmission time. More...
 
int ast_rtp_instance_set_local_address (struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
 Set the address that we are expecting to receive RTP on. More...
 
void ast_rtp_instance_set_prop (struct ast_rtp_instance *instance, enum ast_rtp_property property, int value)
 Set the value of an RTP instance property. More...
 
int ast_rtp_instance_set_qos (struct ast_rtp_instance *instance, int tos, int cos, const char *desc)
 Set QoS parameters on an RTP session. More...
 
int ast_rtp_instance_set_read_format (struct ast_rtp_instance *instance, struct ast_format *format)
 Request that the underlying RTP engine provide audio frames in a specific format. More...
 
void ast_rtp_instance_set_remote_ssrc (struct ast_rtp_instance *rtp, unsigned int ssrc)
 Set the remote SSRC for an RTP instance. More...
 
int ast_rtp_instance_set_requested_target_address (struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
 Set the requested target address of the remote endpoint. More...
 
void ast_rtp_instance_set_stats_vars (struct ast_channel *chan, struct ast_rtp_instance *instance)
 Set standard statistics from an RTP instance on a channel. More...
 
void ast_rtp_instance_set_stream_num (struct ast_rtp_instance *rtp, int stream_num)
 Set the stream number for an RTP instance. More...
 
void ast_rtp_instance_set_timeout (struct ast_rtp_instance *instance, int timeout)
 Set the RTP timeout value. More...
 
int ast_rtp_instance_set_write_format (struct ast_rtp_instance *instance, struct ast_format *format)
 Tell underlying RTP engine that audio frames will be provided in a specific format. More...
 
void ast_rtp_instance_stop (struct ast_rtp_instance *instance)
 Stop an RTP instance. More...
 
void ast_rtp_instance_stun_request (struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username)
 Request that the underlying RTP engine send a STUN BIND request. More...
 
void ast_rtp_instance_update_source (struct ast_rtp_instance *instance)
 Indicate that the RTP marker bit should be set on an RTP stream. More...
 
int ast_rtp_instance_write (struct ast_rtp_instance *instance, struct ast_frame *frame)
 Send a frame out over RTP. More...
 
char * ast_rtp_lookup_mime_multiple2 (struct ast_str *buf, struct ast_format_cap *ast_format_capability, int rtp_capability, const int asterisk_format, enum ast_rtp_options options)
 Convert formats into a string and put them into a buffer. More...
 
const char * ast_rtp_lookup_mime_subtype2 (const int asterisk_format, const struct ast_format *format, int code, enum ast_rtp_options options)
 Retrieve mime subtype information on a payload. More...
 
unsigned int ast_rtp_lookup_sample_rate2 (int asterisk_format, const struct ast_format *format, int code)
 Get the sample rate associated with known RTP payload types. More...
 
void ast_rtp_publish_rtcp_message (struct ast_rtp_instance *rtp, struct stasis_message_type *message_type, struct ast_rtp_rtcp_report *report, struct ast_json *blob)
 Publish an RTCP message to Stasis Message Bus API. More...
 
int ast_rtp_red_buffer (struct ast_rtp_instance *instance, struct ast_frame *frame)
 Buffer a frame in an RTP instance for RED. More...
 
int ast_rtp_red_init (struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations)
 Initialize RED support on an RTP instance. More...
 
struct ast_rtp_rtcp_reportast_rtp_rtcp_report_alloc (unsigned int report_blocks)
 Allocate an ao2 ref counted instance of ast_rtp_rtcp_report. More...
 
struct stasis_topicast_rtp_topic (void)
 Stasis Message Bus API topic for RTP and RTCP related messages More...
 
static int find_static_payload_type (int asterisk_format, const struct ast_format *format, int code)
 
static int find_unused_payload (const struct ast_rtp_codecs *codecs)
 
static int find_unused_payload_in_range (const struct ast_rtp_codecs *codecs, int start, int end, struct ast_rtp_payload_type *ignore[])
 
static void instance_destructor (void *obj)
 
static void payload_mapping_rx_clear_primary (struct ast_rtp_codecs *codecs, struct ast_rtp_payload_type *to_match)
 
static int payload_mapping_tx_is_present (const struct ast_rtp_codecs *codecs, const struct ast_rtp_payload_type *to_match)
 
static void rtcp_message_payload_dtor (void *obj)
 
static struct ast_manager_event_blobrtcp_report_to_ami (struct stasis_message *msg)
 
static struct ast_jsonrtcp_report_to_json (struct stasis_message *msg, const struct stasis_message_sanitizer *sanitize)
 
static int rtp_codecs_assign_payload_code_rx (struct ast_rtp_codecs *codecs, int asterisk_format, struct ast_format *format, int code, int explicit, unsigned int sample_rate)
 
static int rtp_codecs_find_non_primary_dynamic_rx (struct ast_rtp_codecs *codecs)
 
static void rtp_codecs_payload_replace_rx (struct ast_rtp_codecs *codecs, int payload, struct ast_rtp_payload_type *new_type)
 
static void rtp_codecs_payload_set_rx (struct ast_rtp_codecs *codecs, int payload, struct ast_rtp_payload_type *new_type, int replace)
 
static void rtp_codecs_payloads_copy_rx (struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
 
static void rtp_codecs_payloads_copy_tx (struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
 
static int rtp_dtls_wrap_active (struct ast_rtp_instance *instance)
 
static enum ast_rtp_dtls_connection rtp_dtls_wrap_get_connection (struct ast_rtp_instance *instance)
 
static const char * rtp_dtls_wrap_get_fingerprint (struct ast_rtp_instance *instance)
 
static enum ast_rtp_dtls_hash rtp_dtls_wrap_get_fingerprint_hash (struct ast_rtp_instance *instance)
 
static enum ast_rtp_dtls_setup rtp_dtls_wrap_get_setup (struct ast_rtp_instance *instance)
 
static void rtp_dtls_wrap_reset (struct ast_rtp_instance *instance)
 
static int rtp_dtls_wrap_set_configuration (struct ast_rtp_instance *instance, const struct ast_rtp_dtls_cfg *dtls_cfg)
 
static void rtp_dtls_wrap_set_fingerprint (struct ast_rtp_instance *instance, enum ast_rtp_dtls_hash hash, const char *fingerprint)
 
static void rtp_dtls_wrap_set_setup (struct ast_rtp_instance *instance, enum ast_rtp_dtls_setup setup)
 
static void rtp_dtls_wrap_stop (struct ast_rtp_instance *instance)
 
static void rtp_engine_atexit (void)
 
static void rtp_engine_mime_type_cleanup (int i)
 
static void rtp_engine_shutdown (void)
 
static enum ast_rtp_extension_direction rtp_extmap_negotiate_direction (enum ast_rtp_extension_direction ours, enum ast_rtp_extension_direction theirs)
 Helper function which negotiates two RTP extension directions to get our current direction. More...
 
static void rtp_ice_wrap_add_remote_candidate (struct ast_rtp_instance *instance, const struct ast_rtp_engine_ice_candidate *candidate)
 
static void rtp_ice_wrap_change_components (struct ast_rtp_instance *instance, int num_components)
 
static struct ao2_containerrtp_ice_wrap_get_local_candidates (struct ast_rtp_instance *instance)
 
static const char * rtp_ice_wrap_get_password (struct ast_rtp_instance *instance)
 
static const char * rtp_ice_wrap_get_ufrag (struct ast_rtp_instance *instance)
 
static void rtp_ice_wrap_ice_lite (struct ast_rtp_instance *instance)
 
static void rtp_ice_wrap_set_authentication (struct ast_rtp_instance *instance, const char *ufrag, const char *password)
 
static void rtp_ice_wrap_set_role (struct ast_rtp_instance *instance, enum ast_rtp_ice_role role)
 
static void rtp_ice_wrap_start (struct ast_rtp_instance *instance)
 
static void rtp_ice_wrap_stop (struct ast_rtp_instance *instance)
 
static void rtp_ice_wrap_turn_request (struct ast_rtp_instance *instance, enum ast_rtp_ice_component_type component, enum ast_transport transport, const char *server, unsigned int port, const char *username, const char *password)
 
static void rtp_instance_set_incoming_source_address_nolock (struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
 
static struct ast_rtp_payload_typertp_payload_type_alloc (struct ast_format *format, int payload, int rtp_code, int primary_mapping, unsigned int sample_rate)
 
static void rtp_payload_type_dtor (void *obj)
 
static void rtp_rtcp_report_dtor (void *obj)
 
static void set_next_mime_type (struct ast_format *format, int rtp_code, const char *type, const char *subtype, unsigned int sample_rate)
 
static void unref_instance_cond (struct ast_rtp_instance **instance)
 Conditionally unref an rtp instance. More...
 
 STASIS_MESSAGE_TYPE_DEFN (ast_rtp_rtcp_received_type,.to_ami=rtcp_report_to_ami,.to_json=rtcp_report_to_json,)
 
 STASIS_MESSAGE_TYPE_DEFN (ast_rtp_rtcp_sent_type,.to_ami=rtcp_report_to_ami,.to_json=rtcp_report_to_json,)
 Define RTCP/RTP message types. More...
 

Variables

static struct ast_rtp_mime_type ast_rtp_mime_types [128]
 
static uintmax_t debug_category_dtls_id
 
static uintmax_t debug_category_dtls_packet_id
 
static uintmax_t debug_category_ice_id
 
static uintmax_t debug_category_rtcp_id
 
static uintmax_t debug_category_rtcp_packet_id
 
static uintmax_t debug_category_rtp_id
 
static uintmax_t debug_category_rtp_packet_id
 
static struct engines engines = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
static struct glues glues = { .first = NULL, .last = NULL, .lock = { PTHREAD_RWLOCK_INITIALIZER , NULL, {1, 0} } , }
 
static int mime_types_len = 0
 
static ast_rwlock_t mime_types_lock
 
struct ast_srtp_resres_srtp = NULL
 
struct ast_srtp_policy_resres_srtp_policy = NULL
 
static struct ast_rtp_engine_dtls rtp_dtls_wrappers
 
static const char *const rtp_extension_uris [AST_RTP_EXTENSION_MAX]
 URIs for known RTP extensions. More...
 
static struct ast_rtp_engine_ice rtp_ice_wrappers
 
static struct stasis_topicrtp_topic
 Stasis Message Bus API topic for RTP related messages More...
 
static struct ast_rtp_payload_typestatic_RTP_PT [AST_RTP_MAX_PT]
 Mapping between Asterisk codecs and rtp payload types. More...
 
static ast_rwlock_t static_RTP_PT_lock
 

Detailed Description

Pluggable RTP Architecture.

Author
Joshua Colp jcolp.nosp@m.@dig.nosp@m.ium.c.nosp@m.om

Definition in file rtp_engine.c.

Macro Definition Documentation

◆ MAX_RTP_MIME_TYPES

#define MAX_RTP_MIME_TYPES   128

Definition at line 246 of file rtp_engine.c.

◆ SET_AST_JSON_OBJ

#define SET_AST_JSON_OBJ (   target,
  name,
  obj 
)

Set given json object into target with name.

Parameters
targetTarget json.
namekey of given object.
objJson value will be set.

Definition at line 287 of file rtp_engine.c.

Function Documentation

◆ add_static_payload()

static void add_static_payload ( int  payload,
struct ast_format format,
int  rtp_code 
)
static

Definition at line 3322 of file rtp_engine.c.

3323{
3324 struct ast_rtp_payload_type *type;
3325
3326 /*
3327 * ARRAY_LEN's result is cast to an int so 'map' is not autocast to a size_t,
3328 * which if negative would cause an assertion.
3329 */
3331
3332 if (ast_option_rtpusedynamic && payload < 0) {
3333 /*
3334 * We're going to build dynamic payloads dynamically. An RTP code is
3335 * required otherwise one will be dynamically allocated per instance.
3336 */
3337 return;
3338 }
3339
3340 /*
3341 * Either the given payload is truly a static type, or Asterisk is
3342 * globally storing the dynamic payloads in the static_RTP_PT object.
3343 */
3345
3346 if (payload < 0) {
3347 /*
3348 * This is a dynamic payload that will be stored globally,
3349 * so find the next available empty slot.
3350 */
3352 if (payload < 0) {
3353 ast_log(LOG_WARNING, "No dynamic RTP payload type values available "
3354 "for %s - %d!\n", format ? ast_format_get_name(format) : "", rtp_code);
3356 return;
3357 }
3358 }
3359
3361 if (type) {
3364 }
3366}
#define ast_log
Definition: astobj2.c:42
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
static const char type[]
Definition: chan_ooh323.c:109
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
int ast_option_rtpusedynamic
Definition: options.c:88
#define LOG_WARNING
#define ast_rwlock_wrlock(a)
Definition: lock.h:236
#define ast_rwlock_unlock(a)
Definition: lock.h:234
#define NULL
Definition: resample.c:96
static struct ast_rtp_payload_type * static_RTP_PT[AST_RTP_MAX_PT]
Mapping between Asterisk codecs and rtp payload types.
Definition: rtp_engine.c:273
static ast_rwlock_t static_RTP_PT_lock
Definition: rtp_engine.c:274
static struct ast_rtp_payload_type * rtp_payload_type_alloc(struct ast_format *format, int payload, int rtp_code, int primary_mapping, unsigned int sample_rate)
Definition: rtp_engine.c:305
static int find_unused_payload(const struct ast_rtp_codecs *codecs)
Definition: rtp_engine.c:1763
struct ast_format * format
Definition: rtp_engine.h:303
#define ast_assert(a)
Definition: utils.h:739
#define ARRAY_LEN(a)
Definition: utils.h:666

References ao2_cleanup, ARRAY_LEN, ast_assert, ast_format_get_name(), ast_log, ast_option_rtpusedynamic, ast_rwlock_unlock, ast_rwlock_wrlock, find_unused_payload(), ast_rtp_payload_type::format, LOG_WARNING, NULL, ast_rtp_payload_type::payload, ast_rtp_payload_type::rtp_code, rtp_payload_type_alloc(), static_RTP_PT, static_RTP_PT_lock, and type.

Referenced by ast_rtp_engine_init(), and ast_rtp_engine_load_format().

◆ ast_debug_category_dtls_id()

uintmax_t ast_debug_category_dtls_id ( void  )

Definition at line 3710 of file rtp_engine.c.

3711{
3713}
static uintmax_t debug_category_dtls_id
Definition: rtp_engine.c:3708

References debug_category_dtls_id.

◆ ast_debug_category_dtls_packet_id()

uintmax_t ast_debug_category_dtls_packet_id ( void  )

Definition at line 3717 of file rtp_engine.c.

3718{
3720}
static uintmax_t debug_category_dtls_packet_id
Definition: rtp_engine.c:3715

References debug_category_dtls_packet_id.

◆ ast_debug_category_ice_id()

uintmax_t ast_debug_category_ice_id ( void  )

Definition at line 3724 of file rtp_engine.c.

3725{
3726 return debug_category_ice_id;
3727}
static uintmax_t debug_category_ice_id
Definition: rtp_engine.c:3722

References debug_category_ice_id.

◆ ast_debug_category_rtcp_id()

uintmax_t ast_debug_category_rtcp_id ( void  )

Definition at line 3696 of file rtp_engine.c.

3697{
3699}
static uintmax_t debug_category_rtcp_id
Definition: rtp_engine.c:3694

References debug_category_rtcp_id.

◆ ast_debug_category_rtcp_packet_id()

uintmax_t ast_debug_category_rtcp_packet_id ( void  )

Definition at line 3703 of file rtp_engine.c.

3704{
3706}
static uintmax_t debug_category_rtcp_packet_id
Definition: rtp_engine.c:3701

References debug_category_rtcp_packet_id.

◆ ast_debug_category_rtp_id()

uintmax_t ast_debug_category_rtp_id ( void  )

Definition at line 3682 of file rtp_engine.c.

3683{
3684 return debug_category_rtp_id;
3685}
static uintmax_t debug_category_rtp_id
Definition: rtp_engine.c:3680

References debug_category_rtp_id.

◆ ast_debug_category_rtp_packet_id()

uintmax_t ast_debug_category_rtp_packet_id ( void  )

Definition at line 3689 of file rtp_engine.c.

3690{
3692}
static uintmax_t debug_category_rtp_packet_id
Definition: rtp_engine.c:3687

References debug_category_rtp_packet_id.

◆ ast_rtp_codecs_find_payload_code()

int ast_rtp_codecs_find_payload_code ( struct ast_rtp_codecs codecs,
int  payload 
)

Search for the tx payload type in the ast_rtp_codecs structure.

Parameters
codecsCodecs structure to look in
payloadThe payload type format to look for
Returns
Numerical payload type or -1 if unable to find payload in codecs

Example usage:

static struct ao2_container * codecs
Registered codecs.
Definition: codec.c:48
int ast_rtp_codecs_find_payload_code(struct ast_rtp_codecs *codecs, int payload)
Search for the tx payload type in the ast_rtp_codecs structure.
Definition: rtp_engine.c:2090

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

Definition at line 2090 of file rtp_engine.c.

2091{
2092 struct ast_rtp_payload_type *type;
2093 int res = -1;
2094
2095 ast_rwlock_rdlock(&codecs->codecs_lock);
2096 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
2097 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, payload);
2098 if (type) {
2099 res = payload;
2100 }
2101 }
2102 ast_rwlock_unlock(&codecs->codecs_lock);
2103
2104 return res;
2105}
#define ast_rwlock_rdlock(a)
Definition: lock.h:235
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680

References ast_rwlock_rdlock, ast_rwlock_unlock, AST_VECTOR_GET, AST_VECTOR_SIZE, codecs, ast_rtp_payload_type::payload, and type.

Referenced by bridge_p2p_rtp_write().

◆ ast_rtp_codecs_get_framing()

unsigned int ast_rtp_codecs_get_framing ( struct ast_rtp_codecs codecs)

Get the framing used for a set of codecs.

Parameters
codecsCodecs structure to get the framing from
Returns
The framing to be used for the media stream associated with these codecs
Since
13.0.0

Definition at line 1631 of file rtp_engine.c.

1632{
1633 unsigned int framing;
1634
1635 ast_rwlock_rdlock(&codecs->codecs_lock);
1636 framing = codecs->framing;
1637 ast_rwlock_unlock(&codecs->codecs_lock);
1638
1639 return framing;
1640}

References ast_rwlock_rdlock, ast_rwlock_unlock, and codecs.

Referenced by ast_rtp_write(), create_outgoing_sdp_stream(), multicast_rtp_write(), and native_rtp_bridge_compatible_check().

◆ ast_rtp_codecs_get_payload()

struct ast_rtp_payload_type * ast_rtp_codecs_get_payload ( struct ast_rtp_codecs codecs,
int  payload 
)

Retrieve rx payload mapped information by payload type.

Parameters
codecsCodecs structure to look in
payloadNumerical payload to look up
Returns
Payload information.
Return values
NULLif payload does not exist.
Note
The payload returned by this function has its reference count increased. Callers are responsible for decrementing the reference count.

Example usage:

struct ast_rtp_payload_type *payload_type;
payload_type = ast_rtp_codecs_get_payload(&codecs, 0);
struct ast_rtp_payload_type * ast_rtp_codecs_get_payload(struct ast_rtp_codecs *codecs, int payload)
Retrieve rx payload mapped information by payload type.
Definition: rtp_engine.c:1524

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

Definition at line 1524 of file rtp_engine.c.

1525{
1526 struct ast_rtp_payload_type *type = NULL;
1527
1528 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
1529 return NULL;
1530 }
1531
1532 ast_rwlock_rdlock(&codecs->codecs_lock);
1533 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_rx)) {
1534 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, payload);
1535 ao2_bump(type);
1536 }
1537 ast_rwlock_unlock(&codecs->codecs_lock);
1538
1539 if (!type && payload <= AST_RTP_PT_LAST_STATIC) {
1543 }
1544
1545 return type;
1546}
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:83
#define AST_RTP_PT_LAST_STATIC
Definition: rtp_engine.h:89

References ao2_bump, AST_RTP_MAX_PT, AST_RTP_PT_LAST_STATIC, ast_rwlock_rdlock, ast_rwlock_unlock, AST_VECTOR_GET, AST_VECTOR_SIZE, codecs, NULL, ast_rtp_payload_type::payload, static_RTP_PT, static_RTP_PT_lock, and type.

Referenced by ast_rtp_interpret(), and bridge_p2p_rtp_write().

◆ ast_rtp_codecs_get_payload_format()

struct ast_format * ast_rtp_codecs_get_payload_format ( struct ast_rtp_codecs codecs,
int  payload 
)

Retrieve the actual ast_format stored on the codecs structure for a specific tx payload type.

Parameters
codecsCodecs structure to look in
payloadNumerical payload type to look up
Returns
pointer to format structure on success
Return values
NULLon failure
Note
The format returned by this function has its reference count increased. Callers are responsible for decrementing the reference count.
Since
10.0

Definition at line 1599 of file rtp_engine.c.

1600{
1601 struct ast_rtp_payload_type *type;
1602 struct ast_format *format = NULL;
1603
1604 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
1605 return NULL;
1606 }
1607
1608 ast_rwlock_rdlock(&codecs->codecs_lock);
1609 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1610 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, payload);
1611 if (type && type->asterisk_format) {
1612 format = ao2_bump(type->format);
1613 }
1614 }
1615 ast_rwlock_unlock(&codecs->codecs_lock);
1616
1617 return format;
1618}
Definition of a media format.
Definition: format.c:43

References ao2_bump, AST_RTP_MAX_PT, ast_rwlock_rdlock, ast_rwlock_unlock, AST_VECTOR_GET, AST_VECTOR_SIZE, codecs, NULL, and type.

Referenced by get_codecs().

◆ ast_rtp_codecs_get_preferred_format()

struct ast_format * ast_rtp_codecs_get_preferred_format ( struct ast_rtp_codecs codecs)

Retrieve rx preferred format.

Parameters
codecsCodecs structure to look in
Returns
format information.
Return values
NULLif format does not exist.
Note
The format returned by this function has its reference count increased. Callers are responsible for decrementing the reference count.

Example usage:

struct ast_format *payload_format;
struct ast_format * ast_rtp_codecs_get_preferred_format(struct ast_rtp_codecs *codecs)
Retrieve rx preferred format.
Definition: rtp_engine.c:1548

This looks up the preferred format on the codec

Definition at line 1548 of file rtp_engine.c.

1549{
1550 struct ast_format *format;
1551 ast_rwlock_rdlock(&codecs->codecs_lock);
1552 format = ao2_bump(codecs->preferred_format);
1553 ast_rwlock_unlock(&codecs->codecs_lock);
1554 return format;
1555}

References ao2_bump, ast_rwlock_rdlock, ast_rwlock_unlock, and codecs.

Referenced by ast_rtp_dtmf_begin().

◆ ast_rtp_codecs_get_stream_type()

enum ast_media_type ast_rtp_codecs_get_stream_type ( struct ast_rtp_codecs codecs)

Determine the type of RTP stream media from the codecs mapped.

Since
13.19.0
Parameters
codecsCodecs structure to look in
Returns
Media type or AST_MEDIA_TYPE_UNKNOWN if no codecs mapped.

Definition at line 1505 of file rtp_engine.c.

1506{
1507 enum ast_media_type stream_type = AST_MEDIA_TYPE_UNKNOWN;
1508 int payload;
1509 struct ast_rtp_payload_type *type;
1510
1511 ast_rwlock_rdlock(&codecs->codecs_lock);
1512 for (payload = 0; payload < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++payload) {
1513 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, payload);
1514 if (type && type->asterisk_format) {
1515 stream_type = ast_format_get_type(type->format);
1516 break;
1517 }
1518 }
1519 ast_rwlock_unlock(&codecs->codecs_lock);
1520
1521 return stream_type;
1522}
ast_media_type
Types of media.
Definition: codec.h:30
@ AST_MEDIA_TYPE_UNKNOWN
Definition: codec.h:31
enum ast_media_type ast_format_get_type(const struct ast_format *format)
Get the media type of a format.
Definition: format.c:354

References ast_format_get_type(), AST_MEDIA_TYPE_UNKNOWN, ast_rwlock_rdlock, ast_rwlock_unlock, AST_VECTOR_GET, AST_VECTOR_SIZE, codecs, ast_rtp_payload_type::payload, and type.

Referenced by ast_rtp_read().

◆ ast_rtp_codecs_payload_code()

int ast_rtp_codecs_payload_code ( struct ast_rtp_codecs codecs,
int  asterisk_format,
struct ast_format format,
int  code 
)

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

Parameters
codecsCodecs structure to look in
asterisk_formatNon-zero if the given Asterisk format is present
formatAsterisk format to look for
codeThe format to look for

Find the currently assigned rx mapped payload type based on whether it is an Asterisk format or non-format code. If one is currently not assigned then create a rx payload type mapping.

Returns
Numerical payload type
Return values
-1if could not assign.

Example usage:

struct ast_format * ast_format_ulaw
Built-in cached ulaw format.
Definition: format_cache.c:86
int ast_rtp_codecs_payload_code(struct ast_rtp_codecs *codecs, int asterisk_format, struct ast_format *format, int code)
Retrieve a rx mapped payload type based on whether it is an Asterisk format and the code.
Definition: rtp_engine.c:1968

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

Since
1.8

Definition at line 1968 of file rtp_engine.c.

1969{
1970 return ast_rtp_codecs_payload_code_sample_rate(codecs, asterisk_format, format, code, 0);
1971}
int ast_rtp_codecs_payload_code_sample_rate(struct ast_rtp_codecs *codecs, int asterisk_format, struct ast_format *format, int code, unsigned int sample_rate)
Retrieve a rx mapped payload type based on whether it is an Asterisk format, the code and the sample ...
Definition: rtp_engine.c:1973

References ast_rtp_codecs_payload_code_sample_rate(), ast_rtp_payload_type::asterisk_format, codecs, and ast_rtp_payload_type::format.

Referenced by apply_cap_to_bundled(), create_outgoing_sdp_stream(), and jingle_add_payloads_to_description().

◆ ast_rtp_codecs_payload_code_sample_rate()

int ast_rtp_codecs_payload_code_sample_rate ( struct ast_rtp_codecs codecs,
int  asterisk_format,
struct ast_format format,
int  code,
unsigned int  sample_rate 
)

Retrieve a rx mapped payload type based on whether it is an Asterisk format, the code and the sample rate.

Parameters
codecsCodecs structure to look in
asterisk_formatNon-zero if the given Asterisk format is present
formatAsterisk format to look for
codeThe format to look for
sample_rateNon-zero if we want to also match on sample rate.

Find the currently assigned rx mapped payload type based on whether it is an Asterisk format or non-format code. If one is currently not assigned then create a rx payload type mapping.

Returns
Numerical payload type
Return values
-1if could not assign.

Example usage:

#define AST_RTP_DTMF
Definition: rtp_engine.h:291
int ast_rtp_codecs_payload_code_sample_rate(struct ast_rtp_codecs *codecs, int asterisk_format, struct ast_format *format, int code, unsigned int sample_rate)
Retrieve a rx mapped payload type based on whether it is an Asterisk format, the code and the sample ...
Definition: rtp_engine.c:1973

This looks for the numerical payload for a DTMF type with a sample rate of 8kHz in the codecs structure.

Since
22.0.0

Definition at line 1973 of file rtp_engine.c.

1974{
1975 struct ast_rtp_payload_type *type;
1976 int idx;
1977 int payload = -1;
1978
1980 if (!asterisk_format) {
1981 ast_rwlock_rdlock(&codecs->codecs_lock);
1982 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
1983 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
1984 if (!type) {
1985 continue;
1986 }
1987
1988 if (!type->asterisk_format
1989 && type->primary_mapping
1990 && type->rtp_code == code
1991 && (sample_rate == 0 || type->sample_rate == sample_rate)) {
1992 payload = idx;
1993 break;
1994 }
1995 }
1996 ast_rwlock_unlock(&codecs->codecs_lock);
1997 } else if (format) {
1998 ast_rwlock_rdlock(&codecs->codecs_lock);
1999 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
2000 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
2001 if (!type) {
2002 continue;
2003 }
2004
2005 if (type->asterisk_format
2006 && type->primary_mapping
2008 payload = idx;
2009 break;
2010 }
2011 }
2012 ast_rwlock_unlock(&codecs->codecs_lock);
2013 }
2014
2015 if (payload < 0) {
2017 code, 0, sample_rate);
2018 }
2020
2021 return payload;
2022}
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
@ AST_FORMAT_CMP_EQUAL
Definition: format.h:36
static int rtp_codecs_assign_payload_code_rx(struct ast_rtp_codecs *codecs, int asterisk_format, struct ast_format *format, int code, int explicit, unsigned int sample_rate)
Definition: rtp_engine.c:1877
unsigned int sample_rate
Definition: rtp_engine.h:315

References ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_rwlock_rdlock, ast_rwlock_unlock, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_payload_type::asterisk_format, codecs, ast_rtp_payload_type::format, ast_rtp_payload_type::payload, rtp_codecs_assign_payload_code_rx(), ast_rtp_payload_type::sample_rate, static_RTP_PT_lock, and type.

Referenced by ast_rtp_codecs_payload_code(), and create_outgoing_sdp_stream().

◆ ast_rtp_codecs_payload_code_tx()

int ast_rtp_codecs_payload_code_tx ( struct ast_rtp_codecs codecs,
int  asterisk_format,
const struct ast_format format,
int  code 
)

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

Since
14.0.0
Parameters
codecsCodecs structure to look in
asterisk_formatNon-zero if the given Asterisk format is present
formatAsterisk format to look for
codeThe format to look for
Returns
Numerical payload type
Return values
-1if not found.

Definition at line 2085 of file rtp_engine.c.

2086{
2087 return ast_rtp_codecs_payload_code_tx_sample_rate(codecs, asterisk_format, format, code, 0);
2088}
int ast_rtp_codecs_payload_code_tx_sample_rate(struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code, unsigned int sample_rate)
Retrieve a tx mapped payload type based on whether it is an Asterisk format and the code.
Definition: rtp_engine.c:2034

References ast_rtp_codecs_payload_code_tx_sample_rate(), ast_rtp_payload_type::asterisk_format, codecs, and ast_rtp_payload_type::format.

Referenced by ast_rtp_sendcng(), ast_rtp_write(), bridge_p2p_rtp_write(), multicast_rtp_write(), and send_start_rtp().

◆ ast_rtp_codecs_payload_code_tx_sample_rate()

int ast_rtp_codecs_payload_code_tx_sample_rate ( struct ast_rtp_codecs codecs,
int  asterisk_format,
const struct ast_format format,
int  code,
unsigned int  sample_rate 
)

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

Since
22.0.0
Parameters
codecsCodecs structure to look in
asterisk_formatNon-zero if the given Asterisk format is present
formatAsterisk format to look for
codeThe format to look for
sample_rateThe sample rate to look for, zero if we don't care
Returns
Numerical payload type
Return values
-1if not found.

Definition at line 2034 of file rtp_engine.c.

2035{
2036 struct ast_rtp_payload_type *type;
2037 int idx;
2038 int payload = -1;
2039
2040 if (!asterisk_format) {
2041 ast_rwlock_rdlock(&codecs->codecs_lock);
2042 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
2043 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
2044 if (!type) {
2045 continue;
2046 }
2047
2048 if (!type->asterisk_format
2049 && type->rtp_code == code
2050 /* Multiple DTMF types share an rtp code but have different sample rates. To ensure we have the right
2051 type we therefore need the sample rate as well as the format and code. Other types have a fixed
2052 sample rate so this is not needed. For those pass in a sample rate of 0 or use ast_rtp_codecs_payload_code_tx. */
2053 && (sample_rate == 0 || type->sample_rate == sample_rate)) {
2054 payload = idx;
2055 break;
2056 }
2057 }
2058 ast_rwlock_unlock(&codecs->codecs_lock);
2059 } else if (format) {
2060 ast_rwlock_rdlock(&codecs->codecs_lock);
2061 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
2062 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
2063 if (!type) {
2064 continue;
2065 }
2066
2067 if (type->asterisk_format
2069 payload = idx;
2070 break;
2071 }
2072 }
2073 ast_rwlock_unlock(&codecs->codecs_lock);
2074 }
2075
2076 if (payload < 0) {
2080 }
2081
2082 return payload;
2083}
static int find_static_payload_type(int asterisk_format, const struct ast_format *format, int code)
Definition: rtp_engine.c:1686

References ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_rwlock_rdlock, ast_rwlock_unlock, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_payload_type::asterisk_format, codecs, find_static_payload_type(), ast_rtp_payload_type::format, ast_rtp_payload_type::payload, ast_rtp_payload_type::sample_rate, static_RTP_PT_lock, and type.

Referenced by ast_rtp_codecs_payload_code_tx(), and ast_rtp_dtmf_begin().

◆ ast_rtp_codecs_payload_formats()

void ast_rtp_codecs_payload_formats ( struct ast_rtp_codecs codecs,
struct ast_format_cap astformats,
int *  nonastformats 
)

Retrieve all formats that were found.

Parameters
codecsCodecs structure to look in
astformatsA capabilities structure to put the Asterisk formats in.
nonastformatsAn integer to put the non-Asterisk formats in

Example usage:

struct ast_format_cap *astformats = ast_format_cap_alloc_nolock()
int nonastformats;
ast_rtp_codecs_payload_formats(&codecs, astformats, &nonastformats);
void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, struct ast_format_cap *astformats, int *nonastformats)
Retrieve all formats that were found.
Definition: rtp_engine.c:1642
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54

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

1643{
1644 int idx;
1645
1647 *nonastformats = 0;
1648
1649 ast_rwlock_rdlock(&codecs->codecs_lock);
1650
1651 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
1652 struct ast_rtp_payload_type *type;
1653
1654 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
1655 if (!type) {
1656 continue;
1657 }
1658
1659 if (type->asterisk_format) {
1660 ast_format_cap_append(astformats, type->format, 0);
1661 } else {
1662 *nonastformats |= type->rtp_code;
1663 }
1664 }
1665 if (codecs->framing) {
1666 ast_format_cap_set_framing(astformats, codecs->framing);
1667 }
1668
1669 ast_rwlock_unlock(&codecs->codecs_lock);
1670}
void ast_format_cap_remove_by_type(struct ast_format_cap *cap, enum ast_media_type type)
Remove all formats matching a specific format type.
Definition: format_cap.c:523
#define ast_format_cap_append(cap, format, framing)
Add format capability to capabilities structure.
Definition: format_cap.h:99
void ast_format_cap_set_framing(struct ast_format_cap *cap, unsigned int framing)
Set the global framing.
Definition: format_cap.c:136

References ast_format_cap_append, ast_format_cap_remove_by_type(), ast_format_cap_set_framing(), AST_MEDIA_TYPE_UNKNOWN, ast_rwlock_rdlock, ast_rwlock_unlock, AST_VECTOR_GET, AST_VECTOR_SIZE, codecs, and type.

Referenced by jingle_interpret_description().

◆ ast_rtp_codecs_payload_replace_format()

int ast_rtp_codecs_payload_replace_format ( struct ast_rtp_codecs codecs,
int  payload,
struct ast_format format 
)

Update the format associated with a tx payload type in a codecs structure.

Parameters
codecsCodecs structure to operate on
payloadNumerical payload type to look up
formatThe format to replace the existing one
Return values
0success
-1failure
Since
13

Definition at line 1565 of file rtp_engine.c.

1566{
1567 struct ast_rtp_payload_type *type;
1568
1569 if (payload < 0 || payload >= AST_RTP_MAX_PT || !format) {
1570 return -1;
1571 }
1572
1574 if (!type) {
1575 return -1;
1576 }
1577 ao2_ref(format, +1);
1578 type->format = format;
1579 type->asterisk_format = 1;
1580 type->payload = payload;
1581 type->primary_mapping = 1;
1582
1583 ast_rwlock_wrlock(&codecs->codecs_lock);
1585 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1586 ao2_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, payload));
1587 }
1588 if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, type)) {
1589 ao2_ref(type, -1);
1590 }
1591 } else {
1592 ao2_ref(type, -1);
1593 }
1594 ast_rwlock_unlock(&codecs->codecs_lock);
1595
1596 return 0;
1597}
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
struct ast_rtp_payload_type * ast_rtp_engine_alloc_payload_type(void)
Allocation routine for ast_rtp_payload_type.
Definition: rtp_engine.c:325
static int payload_mapping_tx_is_present(const struct ast_rtp_codecs *codecs, const struct ast_rtp_payload_type *to_match)
Definition: rtp_engine.c:1181
#define AST_VECTOR_REPLACE(vec, idx, elem)
Replace an element at a specific position in a vector, growing the vector if needed.
Definition: vector.h:284

References ao2_cleanup, ao2_ref, ast_rtp_engine_alloc_payload_type(), AST_RTP_MAX_PT, ast_rwlock_unlock, ast_rwlock_wrlock, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, codecs, ast_rtp_payload_type::format, ast_rtp_payload_type::payload, payload_mapping_tx_is_present(), and type.

Referenced by get_codecs().

◆ ast_rtp_codecs_payload_set_rx()

int ast_rtp_codecs_payload_set_rx ( struct ast_rtp_codecs codecs,
int  code,
struct ast_format format 
)

Set a payload code for use with a specific Asterisk format.

Parameters
codecsCodecs structure to manipulate
codeThe payload code
formatAsterisk format
Return values
0Payload was set to the given format
-1Payload was in use or could not be set
Since
15.0.0

Definition at line 2024 of file rtp_engine.c.

2025{
2026 return rtp_codecs_assign_payload_code_rx(codecs, 1, format, code, 1, 0);
2027}

References codecs, ast_rtp_payload_type::format, and rtp_codecs_assign_payload_code_rx().

Referenced by apply_cap_to_bundled(), and create_outgoing_sdp_stream().

◆ ast_rtp_codecs_payload_set_rx_sample_rate()

int ast_rtp_codecs_payload_set_rx_sample_rate ( struct ast_rtp_codecs codecs,
int  code,
struct ast_format format,
unsigned int  sample_rate 
)

Set a payload code with sample rate for use with a specific Asterisk format.

Parameters
codecsCodecs structure to manipulate
codeThe payload code
formatAsterisk format
sample_rateSample rate of the format, 0 to use the format's default
Return values
0Payload was set to the given format
-1Payload was in use or could not be set
Since
22.0.0

Definition at line 2029 of file rtp_engine.c.

2030{
2031 return rtp_codecs_assign_payload_code_rx(codecs, 1, format, code, 0, sample_rate);
2032}

References codecs, ast_rtp_payload_type::format, rtp_codecs_assign_payload_code_rx(), and ast_rtp_payload_type::sample_rate.

◆ ast_rtp_codecs_payloads_clear()

void ast_rtp_codecs_payloads_clear ( struct ast_rtp_codecs codecs,
struct ast_rtp_instance instance 
)

Clear rx and tx payload mapping 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:

void ast_rtp_codecs_payloads_clear(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance)
Clear rx and tx payload mapping information from an RTP instance.
Definition: rtp_engine.c:1018

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

Since
1.8

Definition at line 1018 of file rtp_engine.c.

1019{
1022
1023 if (instance && instance->engine && instance->engine->payload_set) {
1024 int i;
1025
1026 ao2_lock(instance);
1027 for (i = 0; i < AST_RTP_MAX_PT; i++) {
1028 instance->engine->payload_set(instance, i, 0, NULL, 0);
1029 }
1030 ao2_unlock(instance);
1031 }
1032}
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717
void ast_rtp_codecs_payloads_destroy(struct ast_rtp_codecs *codecs)
Destroy the contents of an RTP codecs structure (but not the structure itself)
Definition: rtp_engine.c:996
int ast_rtp_codecs_payloads_initialize(struct ast_rtp_codecs *codecs)
Initialize an RTP codecs structure.
Definition: rtp_engine.c:980
void(* payload_set)(struct ast_rtp_instance *instance, int payload, int asterisk_format, struct ast_format *format, int code)
Definition: rtp_engine.h:691
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190

References ao2_lock, ao2_unlock, ast_rtp_codecs_payloads_destroy(), ast_rtp_codecs_payloads_initialize(), AST_RTP_MAX_PT, codecs, ast_rtp_instance::engine, NULL, and ast_rtp_engine::payload_set.

◆ ast_rtp_codecs_payloads_copy()

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);
void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
Copy payload information from one RTP instance to another.
Definition: rtp_engine.c:1262

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

Since
1.8

Definition at line 1262 of file rtp_engine.c.

1263{
1264 int idx;
1265 struct ast_rtp_payload_type *type;
1266
1268
1269 /* Deadlock avoidance because of held write lock. */
1270 while (ast_rwlock_tryrdlock(&src->codecs_lock)) {
1272 sched_yield();
1274 }
1275
1276 /*
1277 * This represents a completely new mapping of what the remote party is
1278 * expecting for payloads, so we clear out the entire tx payload mapping
1279 * vector and replace it.
1280 */
1281 for (idx = 0; idx < AST_VECTOR_SIZE(&dest->payload_mapping_tx); ++idx) {
1282 type = AST_VECTOR_GET(&dest->payload_mapping_tx, idx);
1283 ao2_t_cleanup(type, "destroying ast_rtp_codec tx mapping");
1285 }
1286
1287 rtp_codecs_payloads_copy_rx(src, dest, instance);
1288 rtp_codecs_payloads_copy_tx(src, dest, instance);
1289 dest->framing = src->framing;
1291
1294}
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
Definition: astobj2.h:501
#define ao2_t_cleanup(obj, tag)
Definition: astobj2.h:1935
#define ast_rwlock_tryrdlock(a)
Definition: lock.h:237
static void rtp_codecs_payloads_copy_tx(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
Definition: rtp_engine.c:1231
static void rtp_codecs_payloads_copy_rx(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
Definition: rtp_engine.c:1145
struct ast_rtp_codecs::@277 payload_mapping_tx
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:755
struct ast_format * preferred_format
Definition: rtp_engine.h:763
unsigned int framing
Definition: rtp_engine.h:761

References ao2_replace, ao2_t_cleanup, ast_rwlock_tryrdlock, ast_rwlock_unlock, ast_rwlock_wrlock, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, ast_rtp_codecs::codecs_lock, ast_rtp_codecs::framing, NULL, ast_rtp_codecs::payload_mapping_tx, ast_rtp_codecs::preferred_format, rtp_codecs_payloads_copy_rx(), rtp_codecs_payloads_copy_tx(), and type.

Referenced by jingle_interpret_description(), set_caps(), and set_incoming_call_offer_cap().

◆ ast_rtp_codecs_payloads_destroy()

void ast_rtp_codecs_payloads_destroy ( struct ast_rtp_codecs codecs)

Destroy the contents of an RTP codecs structure (but not the structure itself)

Parameters
codecsThe codecs structure to destroy the contents of

Example usage:

void ast_rtp_codecs_payloads_destroy(struct ast_rtp_codecs *codecs)
Destroy the contents of an RTP codecs structure (but not the structure itself)
Definition: rtp_engine.c:996
Since
11

Definition at line 996 of file rtp_engine.c.

997{
998 int idx;
1000
1001 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
1002 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
1003 ao2_t_cleanup(type, "destroying ast_rtp_codec rx mapping");
1004 }
1005 AST_VECTOR_FREE(&codecs->payload_mapping_rx);
1006
1007 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
1008 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
1009 ao2_t_cleanup(type, "destroying ast_rtp_codec tx mapping");
1010 }
1011 AST_VECTOR_FREE(&codecs->payload_mapping_tx);
1012
1013 ao2_t_cleanup(codecs->preferred_format, "destroying ast_rtp_codec preferred format");
1014
1015 ast_rwlock_destroy(&codecs->codecs_lock);
1016}
#define ast_rwlock_destroy(rwlock)
Definition: lock.h:233
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174

References ao2_t_cleanup, ast_rwlock_destroy, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_SIZE, codecs, and type.

Referenced by ast_rtp_codecs_payloads_clear(), ast_stream_free(), ast_stream_set_rtp_codecs(), instance_destructor(), jingle_interpret_description(), set_caps(), and set_incoming_call_offer_cap().

◆ ast_rtp_codecs_payloads_initialize()

int ast_rtp_codecs_payloads_initialize ( struct ast_rtp_codecs codecs)

Initialize an RTP codecs structure.

Parameters
codecsThe codecs structure to initialize
Return values
0success
-1failure

Example usage:

int ast_rtp_codecs_payloads_initialize(struct ast_rtp_codecs *codecs)
Initialize an RTP codecs structure.
Definition: rtp_engine.c:980
Since
11

Definition at line 980 of file rtp_engine.c.

981{
982 int res;
983
984 codecs->framing = 0;
985 ast_rwlock_init(&codecs->codecs_lock);
986 res = AST_VECTOR_INIT(&codecs->payload_mapping_rx, AST_RTP_MAX_PT);
987 res |= AST_VECTOR_INIT(&codecs->payload_mapping_tx, AST_RTP_MAX_PT);
988 if (res) {
989 AST_VECTOR_FREE(&codecs->payload_mapping_rx);
990 AST_VECTOR_FREE(&codecs->payload_mapping_tx);
991 }
992
993 return res;
994}
#define ast_rwlock_init(rwlock)
wrapper for rwlock with tracking enabled
Definition: lock.h:224
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113

References AST_RTP_MAX_PT, ast_rwlock_init, AST_VECTOR_FREE, AST_VECTOR_INIT, and codecs.

Referenced by ast_rtp_codecs_payloads_clear(), ast_rtp_instance_new(), get_codecs(), and jingle_interpret_description().

◆ ast_rtp_codecs_payloads_set_m_type()

void ast_rtp_codecs_payloads_set_m_type ( struct ast_rtp_codecs codecs,
struct ast_rtp_instance instance,
int  payload 
)

Record tx payload type 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:

void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
Record tx payload type information that was seen in an m= SDP line.
Definition: rtp_engine.c:1341

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

Since
1.8

Definition at line 1341 of file rtp_engine.c.

1342{
1344
1345 if (payload < 0 || payload >= AST_RTP_MAX_PT || payload > AST_RTP_PT_LAST_STATIC) {
1346 return;
1347 }
1348
1352 if (!new_type) {
1353 ast_debug(1, "Don't have a default tx payload type %d format for m type on %p\n",
1354 payload, codecs);
1355 return;
1356 }
1357
1358 ast_debug(1, "Setting tx payload type %d based on m type on %p\n",
1359 payload, codecs);
1360
1361 ast_rwlock_wrlock(&codecs->codecs_lock);
1362
1364 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1365 ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, payload),
1366 "cleaning up replaced tx payload type");
1367 }
1368
1369 if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, new_type)) {
1370 ao2_ref(new_type, -1);
1371 } else if (instance && instance->engine && instance->engine->payload_set) {
1372 ao2_lock(instance);
1373 instance->engine->payload_set(instance, payload, new_type->asterisk_format, new_type->format, new_type->rtp_code);
1374 ao2_unlock(instance);
1375 }
1376 } else {
1377 ao2_ref(new_type, -1);
1378 }
1379
1380 ast_rwlock_unlock(&codecs->codecs_lock);
1381}
#define ast_debug(level,...)
Log a DEBUG message.

References ao2_bump, ao2_lock, ao2_ref, ao2_t_cleanup, ao2_unlock, ast_debug, AST_RTP_MAX_PT, AST_RTP_PT_LAST_STATIC, ast_rwlock_rdlock, ast_rwlock_unlock, ast_rwlock_wrlock, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, codecs, ast_rtp_instance::engine, 10aedae86a32_add_outgoing_enum_va::new_type, ast_rtp_payload_type::payload, payload_mapping_tx_is_present(), ast_rtp_engine::payload_set, static_RTP_PT, and static_RTP_PT_lock.

Referenced by get_codecs().

◆ ast_rtp_codecs_payloads_set_rtpmap_type()

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 tx payload type 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 string 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:

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 tx payload type information that was seen in an a=rtpmap: SDP line.
Definition: rtp_engine.c:1469

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

1470{
1471 return ast_rtp_codecs_payloads_set_rtpmap_type_rate(codecs, instance, payload, mimetype, mimesubtype, options, 0);
1472}
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 tx payload type to a known MIME media type for a codec with a specific sample rate.
Definition: rtp_engine.c:1383
static struct test_options options

References ast_rtp_codecs_payloads_set_rtpmap_type_rate(), codecs, options, and ast_rtp_payload_type::payload.

Referenced by configure_local_rtp(), jingle_interpret_description(), ooh323_set_write_format(), and setup_rtp_connection().

◆ ast_rtp_codecs_payloads_set_rtpmap_type_rate()

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

1387{
1388 unsigned int idx;
1389 int found = 0;
1390
1391 if (pt < 0 || pt >= AST_RTP_MAX_PT) {
1392 return -1; /* bogus payload type */
1393 }
1394
1396 ast_rwlock_wrlock(&codecs->codecs_lock);
1397
1398 for (idx = 0; idx < mime_types_len; ++idx) {
1399 const struct ast_rtp_mime_type *t = &ast_rtp_mime_types[idx];
1401
1402 if (strcasecmp(mimesubtype, t->subtype)) {
1403 continue;
1404 }
1405
1406 if (strcasecmp(mimetype, t->type)) {
1407 continue;
1408 }
1409
1410 /* if both sample rates have been supplied, and they don't match,
1411 * then this not a match; if one has not been supplied, then the
1412 * rates are not compared */
1413 if (sample_rate && t->sample_rate &&
1414 (sample_rate != t->sample_rate)) {
1415 continue;
1416 }
1417
1418 found = 1;
1419
1421 if (!new_type) {
1422 continue;
1423 }
1424
1425 new_type->asterisk_format = t->payload_type.asterisk_format;
1426 new_type->rtp_code = t->payload_type.rtp_code;
1427 new_type->payload = pt;
1428 new_type->primary_mapping = 1;
1429 new_type->sample_rate = sample_rate;
1434 } else {
1435 new_type->format = t->payload_type.format;
1436 }
1437
1438 if (new_type->format) {
1439 /* SDP parsing automatically increases the reference count */
1440 new_type->format = ast_format_parse_sdp_fmtp(new_type->format, "");
1441 }
1442
1444 if (pt < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1445 ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, pt),
1446 "cleaning up replaced tx payload type");
1447 }
1448
1449 if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, pt, new_type)) {
1450 ao2_ref(new_type, -1);
1451 } else if (instance && instance->engine && instance->engine->payload_set) {
1452 ao2_lock(instance);
1453 instance->engine->payload_set(instance, pt, new_type->asterisk_format, new_type->format, new_type->rtp_code);
1454 ao2_unlock(instance);
1455 }
1456 } else {
1457 ao2_ref(new_type, -1);
1458 }
1459
1460 break;
1461 }
1462
1463 ast_rwlock_unlock(&codecs->codecs_lock);
1465
1466 return (found ? 0 : -2);
1467}
struct ast_format * ast_format_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
This function is used to have a media format aware module parse and interpret SDP attribute informati...
Definition: format.c:286
struct ast_format * ast_format_g726
Built-in cached g726 format.
Definition: format_cache.c:111
struct ast_format * ast_format_g726_aal2
Built-in cached g726 aal2 format.
Definition: format_cache.c:116
static struct ast_rtp_mime_type ast_rtp_mime_types[128]
static int mime_types_len
Definition: rtp_engine.c:261
static ast_rwlock_t mime_types_lock
Definition: rtp_engine.c:260
@ AST_RTP_OPT_G726_NONSTANDARD
Definition: rtp_engine.h:144
unsigned int sample_rate
Expected sample rate of the /c subtype.
Definition: rtp_engine.c:258
char subtype[64]
The format type.
Definition: rtp_engine.c:256
char type[16]
The media type.
Definition: rtp_engine.c:254
struct ast_rtp_payload_type payload_type
A mapping object between the Asterisk codec and this RTP payload.
Definition: rtp_engine.c:252

References ao2_lock, ao2_ref, ao2_t_cleanup, ao2_unlock, ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format_g726, ast_format_g726_aal2, ast_format_parse_sdp_fmtp(), ast_rtp_engine_alloc_payload_type(), AST_RTP_MAX_PT, ast_rtp_mime_types, AST_RTP_OPT_G726_NONSTANDARD, ast_rwlock_rdlock, ast_rwlock_unlock, ast_rwlock_wrlock, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, ast_rtp_payload_type::asterisk_format, codecs, ast_rtp_instance::engine, ast_rtp_payload_type::format, mime_types_len, mime_types_lock, 10aedae86a32_add_outgoing_enum_va::new_type, options, payload_mapping_tx_is_present(), ast_rtp_engine::payload_set, ast_rtp_mime_type::payload_type, ast_rtp_payload_type::rtp_code, ast_rtp_payload_type::sample_rate, 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(), get_codecs(), and jingle_interpret_description().

◆ ast_rtp_codecs_payloads_unset()

void ast_rtp_codecs_payloads_unset ( struct ast_rtp_codecs codecs,
struct ast_rtp_instance instance,
int  payload 
)

Remove tx payload type mapped information.

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

Example usage:

void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
Remove tx payload type mapped information.
Definition: rtp_engine.c:1474

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

Since
1.8

Definition at line 1474 of file rtp_engine.c.

1475{
1476 struct ast_rtp_payload_type *type;
1477
1478 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
1479 return;
1480 }
1481
1482 ast_debug(2, "Unsetting payload %d on %p\n", payload, codecs);
1483
1484 ast_rwlock_wrlock(&codecs->codecs_lock);
1485
1486 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1487 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, payload);
1488 /* remove the preferred format if we are unsetting its container. */
1489 if (ast_format_cmp(type->format, codecs->preferred_format) == AST_FORMAT_CMP_EQUAL) {
1490 ao2_replace(codecs->preferred_format, NULL);
1491 }
1493 AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, NULL);
1494 }
1495
1496 if (instance && instance->engine && instance->engine->payload_set) {
1497 ao2_lock(instance);
1498 instance->engine->payload_set(instance, payload, 0, NULL, 0);
1499 ao2_unlock(instance);
1500 }
1501
1502 ast_rwlock_unlock(&codecs->codecs_lock);
1503}

References ao2_cleanup, ao2_lock, ao2_replace, ao2_unlock, ast_debug, ast_format_cmp(), AST_FORMAT_CMP_EQUAL, AST_RTP_MAX_PT, ast_rwlock_unlock, ast_rwlock_wrlock, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, codecs, ast_rtp_instance::engine, NULL, ast_rtp_payload_type::payload, ast_rtp_engine::payload_set, and type.

◆ ast_rtp_codecs_payloads_xover()

void ast_rtp_codecs_payloads_xover ( struct ast_rtp_codecs src,
struct ast_rtp_codecs dest,
struct ast_rtp_instance instance 
)

Crossover copy the tx payload mapping of src to the rx payload mapping of dest.

Since
14.0.0
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

Definition at line 1296 of file rtp_engine.c.

1297{
1298 int idx;
1299 struct ast_rtp_payload_type *type;
1300
1302 if (src != dest) {
1303 /* Deadlock avoidance because of held write lock. */
1304 while (ast_rwlock_tryrdlock(&src->codecs_lock)) {
1306 sched_yield();
1308 }
1309 }
1310
1311 /* Crossover copy payload type tx mapping to rx mapping. */
1312 for (idx = 0; idx < AST_VECTOR_SIZE(&src->payload_mapping_tx); ++idx) {
1314 if (!type) {
1315 continue;
1316 }
1317
1318 /* All tx mapping elements should have the primary flag set. */
1319 ast_assert(type->primary_mapping);
1320
1321 ast_debug(2, "Crossover copying tx to rx payload mapping %d (%p) from %p to %p\n",
1322 idx, type, src, dest);
1324
1325 if (instance && instance->engine && instance->engine->payload_set) {
1326 ao2_lock(instance);
1327 instance->engine->payload_set(instance, idx, type->asterisk_format, type->format, type->rtp_code);
1328 ao2_unlock(instance);
1329 }
1330 }
1331
1332 dest->framing = src->framing;
1334
1335 if (src != dest) {
1337 }
1339}
static void rtp_codecs_payload_replace_rx(struct ast_rtp_codecs *codecs, int payload, struct ast_rtp_payload_type *new_type)
Definition: rtp_engine.c:1128

References ao2_lock, ao2_replace, ao2_unlock, ast_assert, ast_debug, ast_rwlock_tryrdlock, ast_rwlock_unlock, ast_rwlock_wrlock, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_codecs::codecs_lock, ast_rtp_instance::engine, ast_rtp_codecs::framing, ast_rtp_codecs::payload_mapping_tx, ast_rtp_engine::payload_set, ast_rtp_codecs::preferred_format, rtp_codecs_payload_replace_rx(), and type.

Referenced by ast_rtp_instance_early_bridge_make_compatible(), set_caps(), and set_incoming_call_offer_cap().

◆ ast_rtp_codecs_set_framing()

void ast_rtp_codecs_set_framing ( struct ast_rtp_codecs codecs,
unsigned int  framing 
)

Set the framing used for a set of codecs.

Parameters
codecsCodecs structure to set framing on
framingThe framing value to set on the codecs
Since
13.0.0

Definition at line 1620 of file rtp_engine.c.

1621{
1622 if (!framing) {
1623 return;
1624 }
1625
1626 ast_rwlock_wrlock(&codecs->codecs_lock);
1627 codecs->framing = framing;
1628 ast_rwlock_unlock(&codecs->codecs_lock);
1629}

References ast_rwlock_unlock, ast_rwlock_wrlock, and codecs.

Referenced by configure_local_rtp(), get_codecs(), jingle_enable_video(), and jingle_new().

◆ ast_rtp_codecs_set_preferred_format()

int ast_rtp_codecs_set_preferred_format ( struct ast_rtp_codecs codecs,
struct ast_format format 
)

Set the preferred format.

Parameters
codecsCodecs structure to set the preferred format in
formatPreferred format to set.
Returns
0
Note
The format passed this function has its reference count increased. If an existing format is set, that format is replaced.

Example usage:

struct ast_format *preferred_format = ast_format_cap_get_format(joint, 0);
struct ast_format * ast_format_cap_get_format(const struct ast_format_cap *cap, int position)
Get the format at a specific index.
Definition: format_cap.c:400
int ast_rtp_codecs_set_preferred_format(struct ast_rtp_codecs *codecs, struct ast_format *format)
Set the preferred format.
Definition: rtp_engine.c:1557

This sets the first joint format as the preferred format.

Definition at line 1557 of file rtp_engine.c.

1558{
1559 ast_rwlock_wrlock(&codecs->codecs_lock);
1560 ao2_replace(codecs->preferred_format, format);
1561 ast_rwlock_unlock(&codecs->codecs_lock);
1562 return 0;
1563}

References ao2_replace, ast_rwlock_unlock, ast_rwlock_wrlock, and codecs.

Referenced by set_caps().

◆ ast_rtp_convert_stats_json()

struct ast_json * ast_rtp_convert_stats_json ( const struct ast_rtp_instance_stats stats)

Convert given stat instance into json format.

Parameters
stats
Returns
A json format stat

Definition at line 4128 of file rtp_engine.c.

4129{
4130 struct ast_json *j_res;
4131 int ret;
4132
4133 j_res = ast_json_object_create();
4134 if (!j_res) {
4135 return NULL;
4136 }
4137
4138 /* set mandatory items */
4139 ret = ast_json_object_set(j_res, "txcount", ast_json_integer_create(stats->txcount));
4140 ret |= ast_json_object_set(j_res, "rxcount", ast_json_integer_create(stats->rxcount));
4141
4142 ret |= ast_json_object_set(j_res, "txploss", ast_json_integer_create(stats->txploss));
4143 ret |= ast_json_object_set(j_res, "rxploss", ast_json_integer_create(stats->rxploss));
4144
4145 ret |= ast_json_object_set(j_res, "local_ssrc", ast_json_integer_create(stats->local_ssrc));
4146 ret |= ast_json_object_set(j_res, "remote_ssrc", ast_json_integer_create(stats->remote_ssrc));
4147
4148 ret |= ast_json_object_set(j_res, "txoctetcount", ast_json_integer_create(stats->txoctetcount));
4149 ret |= ast_json_object_set(j_res, "rxoctetcount", ast_json_integer_create(stats->rxoctetcount));
4150
4151 ret |= ast_json_object_set(j_res, "channel_uniqueid", ast_json_string_create(stats->channel_uniqueid));
4152 if (ret) {
4153 ast_log(LOG_WARNING, "Could not create rtp statistics info. channel: %s\n", stats->channel_uniqueid);
4154 ast_json_unref(j_res);
4155 return NULL;
4156 }
4157
4158 /* set other items */
4159 SET_AST_JSON_OBJ(j_res, "txjitter", ast_json_real_create(stats->txjitter));
4160 SET_AST_JSON_OBJ(j_res, "rxjitter", ast_json_real_create(stats->rxjitter));
4161
4162 SET_AST_JSON_OBJ(j_res, "remote_maxjitter", ast_json_real_create(stats->remote_maxjitter));
4163 SET_AST_JSON_OBJ(j_res, "remote_minjitter", ast_json_real_create(stats->remote_minjitter));
4164 SET_AST_JSON_OBJ(j_res, "remote_normdevjitter", ast_json_real_create(stats->remote_normdevjitter));
4165 SET_AST_JSON_OBJ(j_res, "remote_stdevjitter", ast_json_real_create(stats->remote_stdevjitter));
4166
4167 SET_AST_JSON_OBJ(j_res, "local_maxjitter", ast_json_real_create(stats->local_maxjitter));
4168 SET_AST_JSON_OBJ(j_res, "local_minjitter", ast_json_real_create(stats->local_minjitter));
4169 SET_AST_JSON_OBJ(j_res, "local_normdevjitter", ast_json_real_create(stats->local_normdevjitter));
4170 SET_AST_JSON_OBJ(j_res, "local_stdevjitter", ast_json_real_create(stats->local_stdevjitter));
4171
4172 SET_AST_JSON_OBJ(j_res, "remote_maxrxploss", ast_json_real_create(stats->remote_maxrxploss));
4173 SET_AST_JSON_OBJ(j_res, "remote_minrxploss", ast_json_real_create(stats->remote_minrxploss));
4174 SET_AST_JSON_OBJ(j_res, "remote_normdevrxploss", ast_json_real_create(stats->remote_normdevrxploss));
4175 SET_AST_JSON_OBJ(j_res, "remote_stdevrxploss", ast_json_real_create(stats->remote_stdevrxploss));
4176
4177 SET_AST_JSON_OBJ(j_res, "local_maxrxploss", ast_json_real_create(stats->local_maxrxploss));
4178 SET_AST_JSON_OBJ(j_res, "local_minrxploss", ast_json_real_create(stats->local_minrxploss));
4179 SET_AST_JSON_OBJ(j_res, "local_normdevrxploss", ast_json_real_create(stats->local_normdevrxploss));
4180 SET_AST_JSON_OBJ(j_res, "local_stdevrxploss", ast_json_real_create(stats->local_stdevrxploss));
4181
4182 SET_AST_JSON_OBJ(j_res, "rtt", ast_json_real_create(stats->rtt));
4183 SET_AST_JSON_OBJ(j_res, "maxrtt", ast_json_real_create(stats->maxrtt));
4184 SET_AST_JSON_OBJ(j_res, "minrtt", ast_json_real_create(stats->minrtt));
4185 SET_AST_JSON_OBJ(j_res, "normdevrtt", ast_json_real_create(stats->normdevrtt));
4186 SET_AST_JSON_OBJ(j_res, "stdevrtt", ast_json_real_create(stats->stdevrtt));
4187
4188 SET_AST_JSON_OBJ(j_res, "txmes", ast_json_integer_create(stats->txmes));
4189 SET_AST_JSON_OBJ(j_res, "rxmes", ast_json_integer_create(stats->rxmes));
4190
4191 SET_AST_JSON_OBJ(j_res, "remote_maxmes", ast_json_real_create(stats->remote_maxmes));
4192 SET_AST_JSON_OBJ(j_res, "remote_minmes", ast_json_real_create(stats->remote_minmes));
4193 SET_AST_JSON_OBJ(j_res, "remote_normdevmes", ast_json_real_create(stats->remote_normdevmes));
4194 SET_AST_JSON_OBJ(j_res, "remote_stdevmes", ast_json_real_create(stats->remote_stdevmes));
4195
4196 SET_AST_JSON_OBJ(j_res, "local_maxmes", ast_json_real_create(stats->local_maxmes));
4197 SET_AST_JSON_OBJ(j_res, "local_minmes", ast_json_real_create(stats->local_minmes));
4198 SET_AST_JSON_OBJ(j_res, "local_normdevmes", ast_json_real_create(stats->local_normdevmes));
4199 SET_AST_JSON_OBJ(j_res, "local_stdevmes", ast_json_real_create(stats->local_stdevmes));
4200
4201 return j_res;
4202}
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:278
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
Definition: json.c:399
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
Definition: json.c:327
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition: json.c:414
struct ast_json * ast_json_real_create(double value)
Create a JSON real number.
Definition: json.c:342
#define SET_AST_JSON_OBJ(target, name, obj)
Set given json object into target with name.
Definition: rtp_engine.c:287
Abstract JSON element (object, array, string, int, ...).
unsigned int remote_ssrc
Definition: rtp_engine.h:451
unsigned int rxcount
Definition: rtp_engine.h:397
unsigned int local_ssrc
Definition: rtp_engine.h:449
unsigned int rxoctetcount
Definition: rtp_engine.h:457
unsigned int rxploss
Definition: rtp_engine.h:421
unsigned int txcount
Definition: rtp_engine.h:395
unsigned int txploss
Definition: rtp_engine.h:419
unsigned int txoctetcount
Definition: rtp_engine.h:455
char channel_uniqueid[MAX_CHANNEL_ID]
Definition: rtp_engine.h:453

References ast_json_integer_create(), ast_json_object_create(), ast_json_object_set(), ast_json_real_create(), ast_json_string_create(), ast_json_unref(), ast_log, ast_rtp_instance_stats::channel_uniqueid, ast_rtp_instance_stats::local_maxjitter, ast_rtp_instance_stats::local_maxmes, ast_rtp_instance_stats::local_maxrxploss, ast_rtp_instance_stats::local_minjitter, ast_rtp_instance_stats::local_minmes, ast_rtp_instance_stats::local_minrxploss, ast_rtp_instance_stats::local_normdevjitter, ast_rtp_instance_stats::local_normdevmes, ast_rtp_instance_stats::local_normdevrxploss, ast_rtp_instance_stats::local_ssrc, ast_rtp_instance_stats::local_stdevjitter, ast_rtp_instance_stats::local_stdevmes, ast_rtp_instance_stats::local_stdevrxploss, LOG_WARNING, ast_rtp_instance_stats::maxrtt, ast_rtp_instance_stats::minrtt, ast_rtp_instance_stats::normdevrtt, NULL, ast_rtp_instance_stats::remote_maxjitter, ast_rtp_instance_stats::remote_maxmes, ast_rtp_instance_stats::remote_maxrxploss, ast_rtp_instance_stats::remote_minjitter, ast_rtp_instance_stats::remote_minmes, ast_rtp_instance_stats::remote_minrxploss, ast_rtp_instance_stats::remote_normdevjitter, ast_rtp_instance_stats::remote_normdevmes, ast_rtp_instance_stats::remote_normdevrxploss, ast_rtp_instance_stats::remote_ssrc, ast_rtp_instance_stats::remote_stdevjitter, ast_rtp_instance_stats::remote_stdevmes, 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::rxmes, ast_rtp_instance_stats::rxoctetcount, ast_rtp_instance_stats::rxploss, SET_AST_JSON_OBJ, ast_rtp_instance_stats::stdevrtt, ast_rtp_instance_stats::txcount, ast_rtp_instance_stats::txjitter, ast_rtp_instance_stats::txmes, ast_rtp_instance_stats::txoctetcount, and ast_rtp_instance_stats::txploss.

Referenced by ast_rtp_instance_get_stats_all_json().

◆ ast_rtp_dtls_cfg_copy()

void ast_rtp_dtls_cfg_copy ( const struct ast_rtp_dtls_cfg src_cfg,
struct ast_rtp_dtls_cfg dst_cfg 
)

Copy contents of a DTLS configuration structure.

Parameters
src_cfgsource DTLS configuration structure
dst_cfgdestination DTLS configuration structure

Definition at line 3252 of file rtp_engine.c.

3253{
3254 ast_rtp_dtls_cfg_free(dst_cfg); /* Prevent a double-call leaking memory via ast_strdup */
3255
3256 dst_cfg->enabled = src_cfg->enabled;
3257 dst_cfg->verify = src_cfg->verify;
3258 dst_cfg->rekey = src_cfg->rekey;
3259 dst_cfg->suite = src_cfg->suite;
3260 dst_cfg->hash = src_cfg->hash;
3261 dst_cfg->ephemeral_cert = src_cfg->ephemeral_cert;
3262 dst_cfg->certfile = ast_strdup(src_cfg->certfile);
3263 dst_cfg->pvtfile = ast_strdup(src_cfg->pvtfile);
3264 dst_cfg->cipher = ast_strdup(src_cfg->cipher);
3265 dst_cfg->cafile = ast_strdup(src_cfg->cafile);
3266 dst_cfg->capath = ast_strdup(src_cfg->capath);
3267 dst_cfg->default_setup = src_cfg->default_setup;
3268}
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
void ast_rtp_dtls_cfg_free(struct ast_rtp_dtls_cfg *dtls_cfg)
Free contents of a DTLS configuration structure.
Definition: rtp_engine.c:3270
enum ast_rtp_dtls_setup default_setup
Definition: rtp_engine.h:605
enum ast_rtp_dtls_verify verify
Definition: rtp_engine.h:608
unsigned int rekey
Definition: rtp_engine.h:604
enum ast_rtp_dtls_hash hash
Definition: rtp_engine.h:607
unsigned int enabled
Definition: rtp_engine.h:603
unsigned int ephemeral_cert
Definition: rtp_engine.h:614
enum ast_srtp_suite suite
Definition: rtp_engine.h:606

References ast_rtp_dtls_cfg_free(), ast_strdup, ast_rtp_dtls_cfg::cafile, ast_rtp_dtls_cfg::capath, ast_rtp_dtls_cfg::certfile, ast_rtp_dtls_cfg::cipher, ast_rtp_dtls_cfg::default_setup, ast_rtp_dtls_cfg::enabled, ast_rtp_dtls_cfg::ephemeral_cert, ast_rtp_dtls_cfg::hash, ast_rtp_dtls_cfg::pvtfile, ast_rtp_dtls_cfg::rekey, ast_rtp_dtls_cfg::suite, and ast_rtp_dtls_cfg::verify.

◆ ast_rtp_dtls_cfg_free()

void ast_rtp_dtls_cfg_free ( struct ast_rtp_dtls_cfg dtls_cfg)

Free contents of a DTLS configuration structure.

Parameters
dtls_cfga DTLS configuration structure

Definition at line 3270 of file rtp_engine.c.

3271{
3272 ast_free(dtls_cfg->certfile);
3273 dtls_cfg->certfile = NULL;
3274 ast_free(dtls_cfg->pvtfile);
3275 dtls_cfg->pvtfile = NULL;
3276 ast_free(dtls_cfg->cipher);
3277 dtls_cfg->cipher = NULL;
3278 ast_free(dtls_cfg->cafile);
3279 dtls_cfg->cafile = NULL;
3280 ast_free(dtls_cfg->capath);
3281 dtls_cfg->capath = NULL;
3282}
#define ast_free(a)
Definition: astmm.h:180

References ast_free, ast_rtp_dtls_cfg::cafile, ast_rtp_dtls_cfg::capath, ast_rtp_dtls_cfg::certfile, ast_rtp_dtls_cfg::cipher, NULL, and ast_rtp_dtls_cfg::pvtfile.

Referenced by ast_rtp_dtls_cfg_copy(), and media_configuration_destroy().

◆ ast_rtp_dtls_cfg_parse()

int ast_rtp_dtls_cfg_parse ( struct ast_rtp_dtls_cfg dtls_cfg,
const char *  name,
const char *  value 
)

Parse DTLS related configuration options.

Parameters
dtls_cfga DTLS configuration structure
namename of the configuration option
valuevalue of the configuration option
Return values
0if handled
-1if not handled

Definition at line 3159 of file rtp_engine.c.

3160{
3161 if (!strcasecmp(name, "dtlsenable")) {
3162 dtls_cfg->enabled = ast_true(value) ? 1 : 0;
3163 } else if (!strcasecmp(name, "dtlsverify")) {
3164 if (!strcasecmp(value, "yes")) {
3166 } else if (!strcasecmp(value, "fingerprint")) {
3168 } else if (!strcasecmp(value, "certificate")) {
3170 } else if (!strcasecmp(value, "no")) {
3171 dtls_cfg->verify = AST_RTP_DTLS_VERIFY_NONE;
3172 } else {
3173 return -1;
3174 }
3175 } else if (!strcasecmp(name, "dtlsrekey")) {
3176 if (sscanf(value, "%30u", &dtls_cfg->rekey) != 1) {
3177 return -1;
3178 }
3179 } else if (!strcasecmp(name, "dtlsautogeneratecert")) {
3180 dtls_cfg->ephemeral_cert = ast_true(value) ? 1 : 0;
3181 } else if (!strcasecmp(name, "dtlscertfile")) {
3183 ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3184 return -1;
3185 }
3186 ast_free(dtls_cfg->certfile);
3187 dtls_cfg->certfile = ast_strdup(value);
3188 } else if (!strcasecmp(name, "dtlsprivatekey")) {
3190 ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3191 return -1;
3192 }
3193 ast_free(dtls_cfg->pvtfile);
3194 dtls_cfg->pvtfile = ast_strdup(value);
3195 } else if (!strcasecmp(name, "dtlscipher")) {
3196 ast_free(dtls_cfg->cipher);
3197 dtls_cfg->cipher = ast_strdup(value);
3198 } else if (!strcasecmp(name, "dtlscafile")) {
3200 ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3201 return -1;
3202 }
3203 ast_free(dtls_cfg->cafile);
3204 dtls_cfg->cafile = ast_strdup(value);
3205 } else if (!strcasecmp(name, "dtlscapath") || !strcasecmp(name, "dtlscadir")) {
3207 ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3208 return -1;
3209 }
3210 ast_free(dtls_cfg->capath);
3211 dtls_cfg->capath = ast_strdup(value);
3212 } else if (!strcasecmp(name, "dtlssetup")) {
3213 if (!strcasecmp(value, "active")) {
3215 } else if (!strcasecmp(value, "passive")) {
3217 } else if (!strcasecmp(value, "actpass")) {
3219 }
3220 } else if (!strcasecmp(name, "dtlsfingerprint")) {
3221 if (!strcasecmp(value, "sha-256")) {
3222 dtls_cfg->hash = AST_RTP_DTLS_HASH_SHA256;
3223 } else if (!strcasecmp(value, "sha-1")) {
3224 dtls_cfg->hash = AST_RTP_DTLS_HASH_SHA1;
3225 }
3226 } else {
3227 return -1;
3228 }
3229
3230 return 0;
3231}
static const char name[]
Definition: format_mp3.c:68
#define LOG_ERROR
@ AST_RTP_DTLS_SETUP_PASSIVE
Definition: rtp_engine.h:563
@ AST_RTP_DTLS_SETUP_ACTPASS
Definition: rtp_engine.h:564
@ AST_RTP_DTLS_SETUP_ACTIVE
Definition: rtp_engine.h:562
@ AST_RTP_DTLS_HASH_SHA1
Definition: rtp_engine.h:577
@ AST_RTP_DTLS_HASH_SHA256
Definition: rtp_engine.h:576
@ AST_RTP_DTLS_VERIFY_NONE
Definition: rtp_engine.h:582
@ AST_RTP_DTLS_VERIFY_FINGERPRINT
Definition: rtp_engine.h:583
@ AST_RTP_DTLS_VERIFY_CERTIFICATE
Definition: rtp_engine.h:584
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: utils.c:2199
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
int value
Definition: syslog.c:37
int ast_file_is_readable(const char *filename)
Test that a file exists and is readable by the effective user.
Definition: utils.c:3107

References ast_file_is_readable(), ast_free, ast_log, AST_RTP_DTLS_HASH_SHA1, AST_RTP_DTLS_HASH_SHA256, AST_RTP_DTLS_SETUP_ACTIVE, AST_RTP_DTLS_SETUP_ACTPASS, AST_RTP_DTLS_SETUP_PASSIVE, AST_RTP_DTLS_VERIFY_CERTIFICATE, AST_RTP_DTLS_VERIFY_FINGERPRINT, AST_RTP_DTLS_VERIFY_NONE, ast_strdup, ast_strlen_zero(), ast_true(), ast_rtp_dtls_cfg::cafile, ast_rtp_dtls_cfg::capath, ast_rtp_dtls_cfg::certfile, ast_rtp_dtls_cfg::cipher, ast_rtp_dtls_cfg::default_setup, ast_rtp_dtls_cfg::enabled, ast_rtp_dtls_cfg::ephemeral_cert, ast_rtp_dtls_cfg::hash, LOG_ERROR, name, ast_rtp_dtls_cfg::pvtfile, ast_rtp_dtls_cfg::rekey, value, and ast_rtp_dtls_cfg::verify.

Referenced by dtls_handler(), and media_encryption_handler().

◆ ast_rtp_dtls_cfg_validate()

int ast_rtp_dtls_cfg_validate ( struct ast_rtp_dtls_cfg dtls_cfg)

Validates DTLS related configuration options.

Parameters
dtls_cfga DTLS configuration structure
Return values
0if valid
-1if invalid

Definition at line 3233 of file rtp_engine.c.

3234{
3235 if (dtls_cfg->ephemeral_cert) {
3236 if (!ast_strlen_zero(dtls_cfg->certfile)) {
3237 ast_log(LOG_ERROR, "You cannot request automatically generated certificates"
3238 " (dtls_auto_generate_cert) and also specify a certificate file"
3239 " (dtls_cert_file) at the same time\n");
3240 return -1;
3241 } else if (!ast_strlen_zero(dtls_cfg->pvtfile)
3242 || !ast_strlen_zero(dtls_cfg->cafile)
3243 || !ast_strlen_zero(dtls_cfg->capath)) {
3244 ast_log(LOG_NOTICE, "dtls_pvt_file, dtls_cafile, and dtls_ca_path are"
3245 " ignored when dtls_auto_generate_cert is enabled\n");
3246 }
3247 }
3248
3249 return 0;
3250}
#define LOG_NOTICE

References ast_log, ast_strlen_zero(), ast_rtp_dtls_cfg::cafile, ast_rtp_dtls_cfg::capath, ast_rtp_dtls_cfg::certfile, ast_rtp_dtls_cfg::ephemeral_cert, LOG_ERROR, LOG_NOTICE, and ast_rtp_dtls_cfg::pvtfile.

Referenced by sip_endpoint_apply_handler().

◆ ast_rtp_engine_alloc_payload_type()

struct ast_rtp_payload_type * ast_rtp_engine_alloc_payload_type ( void  )

Allocation routine for ast_rtp_payload_type.

Return values
NULLon error
Returns
An ao2 ref counted ast_rtp_payload_type on success.
Note
The ast_rtp_payload_type returned by this function is an ao2 ref counted object.

Definition at line 325 of file rtp_engine.c.

326{
327 return rtp_payload_type_alloc(NULL, 0, 0, 0, 0);
328}

References NULL, and rtp_payload_type_alloc().

Referenced by ast_rtp_codecs_payload_replace_format(), ast_rtp_codecs_payloads_set_rtpmap_type_rate(), and payload_mapping_rx_clear_primary().

◆ ast_rtp_engine_init()

int ast_rtp_engine_init ( void  )

initializes the rtp engine arrays

Definition at line 3779 of file rtp_engine.c.

3780{
3783
3784 rtp_topic = stasis_topic_create("rtp:all");
3785 if (!rtp_topic) {
3786 return -1;
3787 }
3791
3792 /* Define all the RTP mime types available */
3793 set_next_mime_type(ast_format_g723, 0, "audio", "G723", 8000);
3794 set_next_mime_type(ast_format_gsm, 0, "audio", "GSM", 8000);
3795 set_next_mime_type(ast_format_ulaw, 0, "audio", "PCMU", 8000);
3796 set_next_mime_type(ast_format_ulaw, 0, "audio", "G711U", 8000);
3797 set_next_mime_type(ast_format_alaw, 0, "audio", "PCMA", 8000);
3798 set_next_mime_type(ast_format_alaw, 0, "audio", "G711A", 8000);
3799 set_next_mime_type(ast_format_g726, 0, "audio", "G726-32", 8000);
3800 set_next_mime_type(ast_format_adpcm, 0, "audio", "DVI4", 8000);
3801 set_next_mime_type(ast_format_slin, 0, "audio", "L16", 8000);
3802 set_next_mime_type(ast_format_slin16, 0, "audio", "L16", 16000);
3803 set_next_mime_type(ast_format_slin16, 0, "audio", "L16-256", 16000);
3804 set_next_mime_type(ast_format_slin12, 0, "audio", "L16", 12000);
3805 set_next_mime_type(ast_format_slin24, 0, "audio", "L16", 24000);
3806 set_next_mime_type(ast_format_slin32, 0, "audio", "L16", 32000);
3807 set_next_mime_type(ast_format_slin44, 0, "audio", "L16", 44100);
3808 set_next_mime_type(ast_format_slin48, 0, "audio", "L16", 48000);
3809 set_next_mime_type(ast_format_slin96, 0, "audio", "L16", 96000);
3810 set_next_mime_type(ast_format_slin192, 0, "audio", "L16", 192000);
3811 set_next_mime_type(ast_format_lpc10, 0, "audio", "LPC", 8000);
3812 set_next_mime_type(ast_format_g729, 0, "audio", "G729", 8000);
3813 set_next_mime_type(ast_format_g729, 0, "audio", "G729A", 8000);
3814 set_next_mime_type(ast_format_g729, 0, "audio", "G.729", 8000);
3815 set_next_mime_type(ast_format_speex, 0, "audio", "speex", 8000);
3816 set_next_mime_type(ast_format_speex16, 0, "audio", "speex", 16000);
3817 set_next_mime_type(ast_format_speex32, 0, "audio", "speex", 32000);
3818 set_next_mime_type(ast_format_ilbc, 0, "audio", "iLBC", 8000);
3819 /* this is the sample rate listed in the RTP profile for the G.722 codec, *NOT* the actual sample rate of the media stream */
3820 set_next_mime_type(ast_format_g722, 0, "audio", "G722", 8000);
3821 set_next_mime_type(ast_format_g726_aal2, 0, "audio", "AAL2-G726-32", 8000);
3822 /* we need all possible dtmf/bitrate combinations or ast_rtp_codecs_payloads_set_rtpmap_type_rate will not examine it */
3823 set_next_mime_type(NULL, AST_RTP_DTMF, "audio", "telephone-event", 8000);
3824 set_next_mime_type(NULL, AST_RTP_DTMF, "audio", "telephone-event", 16000);
3825 set_next_mime_type(NULL, AST_RTP_DTMF, "audio", "telephone-event", 24000);
3826 set_next_mime_type(NULL, AST_RTP_DTMF, "audio", "telephone-event", 32000);
3827 set_next_mime_type(NULL, AST_RTP_DTMF, "audio", "telephone-event", 48000);
3828 set_next_mime_type(NULL, AST_RTP_CISCO_DTMF, "audio", "cisco-telephone-event", 8000);
3829 set_next_mime_type(NULL, AST_RTP_CN, "audio", "CN", 8000);
3830 set_next_mime_type(ast_format_jpeg, 0, "video", "JPEG", 90000);
3831 set_next_mime_type(ast_format_png, 0, "video", "PNG", 90000);
3832 set_next_mime_type(ast_format_h261, 0, "video", "H261", 90000);
3833 set_next_mime_type(ast_format_h263, 0, "video", "H263", 90000);
3834 set_next_mime_type(ast_format_h263p, 0, "video", "h263-1998", 90000);
3835 set_next_mime_type(ast_format_h264, 0, "video", "H264", 90000);
3836 set_next_mime_type(ast_format_h265, 0, "video", "H265", 90000);
3837 set_next_mime_type(ast_format_mp4, 0, "video", "MP4V-ES", 90000);
3838 set_next_mime_type(ast_format_t140_red, 0, "text", "RED", 1000);
3839 set_next_mime_type(ast_format_t140, 0, "text", "T140", 1000);
3840 set_next_mime_type(ast_format_siren7, 0, "audio", "G7221", 16000);
3841 set_next_mime_type(ast_format_siren14, 0, "audio", "G7221", 32000);
3842 set_next_mime_type(ast_format_g719, 0, "audio", "G719", 48000);
3843 /* Opus, VP8, and VP9 */
3844 set_next_mime_type(ast_format_opus, 0, "audio", "opus", 48000);
3845 set_next_mime_type(ast_format_vp8, 0, "video", "VP8", 90000);
3846 set_next_mime_type(ast_format_vp9, 0, "video", "VP9", 90000);
3847
3848 /* Define the static rtp payload mappings */
3850 #ifdef USE_DEPRECATED_G726
3851 add_static_payload(2, ast_format_g726, 0);/* Technically this is G.721, but if Cisco can do it, so can we... */
3852 #endif
3855 add_static_payload(5, ast_format_adpcm, 0);/* 8 kHz */
3856 add_static_payload(6, ast_format_adpcm, 0); /* 16 kHz */
3860 add_static_payload(10, ast_format_slin, 0); /* 2 channels */
3861 add_static_payload(11, ast_format_slin, 0); /* 1 channel */
3863 add_static_payload(16, ast_format_adpcm, 0); /* 11.025 kHz */
3864 add_static_payload(17, ast_format_adpcm, 0); /* 22.050 kHz */
3866 add_static_payload(19, NULL, AST_RTP_CN); /* Also used for CN */
3870
3871 /*
3872 * Dynamic payload types - Even when dynamically assigning them we'll fall
3873 * back to using the statically declared values as the default number.
3874 */
3877
3884 add_static_payload(105, ast_format_t140_red, 0); /* Real time text chat (with redundancy encoding) */
3885 add_static_payload(106, ast_format_t140, 0); /* Real time text chat */
3889
3893
3897 add_static_payload(118, ast_format_slin16, 0); /* 16 Khz signed linear */
3899
3900 add_static_payload(121, NULL, AST_RTP_CISCO_DTMF); /* Must be type 121 */
3907 /* payload types above 127 are not valid */
3908
3916
3917 /*
3918 * Normnally a core module should call ast_register_cleanup,
3919 * which doesn't run if any module fails to unload. This
3920 * prevents resources being pulled out from under a running
3921 * module and possibly causing a segfault. In this case however,
3922 * the only thing we're cleaning up are the registrations of the
3923 * debug categories.
3924 */
3926
3927 return 0;
3928}
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
Definition: clicompat.c:13
struct ast_format * ast_format_speex16
Built-in cached speex at 16kHz format.
Definition: format_cache.c:136
struct ast_format * ast_format_h264
Built-in cached h264 format.
Definition: format_cache.c:176
struct ast_format * ast_format_slin44
Built-in cached signed linear 44kHz format.
Definition: format_cache.c:66
struct ast_format * ast_format_adpcm
Built-in cached adpcm format.
Definition: format_cache.c:101
struct ast_format * ast_format_slin24
Built-in cached signed linear 24kHz format.
Definition: format_cache.c:56
struct ast_format * ast_format_opus
Built-in cached opus format.
Definition: format_cache.c:221
struct ast_format * ast_format_h265
Built-in cached h265 format.
Definition: format_cache.c:181
struct ast_format * ast_format_gsm
Built-in cached gsm format.
Definition: format_cache.c:96
struct ast_format * ast_format_slin32
Built-in cached signed linear 32kHz format.
Definition: format_cache.c:61
struct ast_format * ast_format_siren14
Built-in cached siren14 format.
Definition: format_cache.c:211
struct ast_format * ast_format_speex
Built-in cached speex format.
Definition: format_cache.c:131
struct ast_format * ast_format_h263
Built-in cached h263 format.
Definition: format_cache.c:166
struct ast_format * ast_format_mp4
Built-in cached mp4 format.
Definition: format_cache.c:186
struct ast_format * ast_format_slin192
Built-in cached signed linear 192kHz format.
Definition: format_cache.c:81
struct ast_format * ast_format_ilbc
Built-in cached ilbc format.
Definition: format_cache.c:121
struct ast_format * ast_format_lpc10
Built-in cached ilbc format.
Definition: format_cache.c:126
struct ast_format * ast_format_slin16
Built-in cached signed linear 16kHz format.
Definition: format_cache.c:51
struct ast_format * ast_format_slin96
Built-in cached signed linear 96kHz format.
Definition: format_cache.c:76
struct ast_format * ast_format_slin48
Built-in cached signed linear 48kHz format.
Definition: format_cache.c:71
struct ast_format * ast_format_g723
Built-in cached g723.1 format.
Definition: format_cache.c:146
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
struct ast_format * ast_format_siren7
Built-in cached siren7 format.
Definition: format_cache.c:216
struct ast_format * ast_format_alaw
Built-in cached alaw format.
Definition: format_cache.c:91
struct ast_format * ast_format_speex32
Built-in cached speex at 32kHz format.
Definition: format_cache.c:141
struct ast_format * ast_format_h261
Built-in cached h261 format.
Definition: format_cache.c:161
struct ast_format * ast_format_vp9
Built-in cached vp9 format.
Definition: format_cache.c:196
struct ast_format * ast_format_t140_red
Built-in cached t140 red format.
Definition: format_cache.c:236
struct ast_format * ast_format_slin12
Built-in cached signed linear 12kHz format.
Definition: format_cache.c:46
struct ast_format * ast_format_h263p
Built-in cached h263 plus format.
Definition: format_cache.c:171
struct ast_format * ast_format_png
Built-in cached png format.
Definition: format_cache.c:206
struct ast_format * ast_format_g722
Built-in cached g722 format.
Definition: format_cache.c:106
struct ast_format * ast_format_t140
Built-in cached t140 format.
Definition: format_cache.c:231
struct ast_format * ast_format_g729
Built-in cached g729 format.
Definition: format_cache.c:151
struct ast_format * ast_format_jpeg
Built-in cached jpeg format.
Definition: format_cache.c:201
struct ast_format * ast_format_vp8
Built-in cached vp8 format.
Definition: format_cache.c:191
struct ast_format * ast_format_g719
Built-in cached g719 format.
Definition: format_cache.c:156
struct stasis_message_type * ast_rtp_rtcp_sent_type(void)
Message type for an RTCP message sent from this Asterisk instance.
struct stasis_message_type * ast_rtp_rtcp_received_type(void)
Message type for an RTCP message received from some external source.
uintmax_t ast_debug_category_register(const char *name)
Register a debug level logger category.
static struct stasis_topic * rtp_topic
Stasis Message Bus API topic for RTP related messages
Definition: rtp_engine.c:277
static void rtp_engine_shutdown(void)
Definition: rtp_engine.c:3734
static void add_static_payload(int payload, struct ast_format *format, int rtp_code)
Definition: rtp_engine.c:3322
static void rtp_engine_atexit(void)
Definition: rtp_engine.c:3765
static void set_next_mime_type(struct ast_format *format, int rtp_code, const char *type, const char *subtype, unsigned int sample_rate)
Definition: rtp_engine.c:3294
#define AST_LOG_CATEGORY_ICE
Definition: rtp_engine.h:2990
#define AST_LOG_CATEGORY_RTCP_PACKET
Definition: rtp_engine.h:2984
#define AST_LOG_CATEGORY_DTLS
Definition: rtp_engine.h:2986
#define AST_LOG_CATEGORY_RTCP
Definition: rtp_engine.h:2982
#define AST_LOG_CATEGORY_RTP
Definition: rtp_engine.h:2978
#define AST_LOG_CATEGORY_RTP_PACKET
Definition: rtp_engine.h:2980
#define AST_LOG_CATEGORY_DTLS_PACKET
Definition: rtp_engine.h:2988
#define AST_RTP_CN
Definition: rtp_engine.h:293
#define AST_RTP_CISCO_DTMF
Definition: rtp_engine.h:295
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Definition: stasis.c:617
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition: stasis.h:1493

References add_static_payload(), ast_debug_category_register(), ast_format_adpcm, ast_format_alaw, ast_format_g719, ast_format_g722, ast_format_g723, ast_format_g726, ast_format_g726_aal2, ast_format_g729, ast_format_gsm, ast_format_h261, ast_format_h263, ast_format_h263p, ast_format_h264, ast_format_h265, ast_format_ilbc, ast_format_jpeg, ast_format_lpc10, ast_format_mp4, ast_format_opus, ast_format_png, ast_format_siren14, ast_format_siren7, ast_format_slin, ast_format_slin12, ast_format_slin16, ast_format_slin192, ast_format_slin24, ast_format_slin32, ast_format_slin44, ast_format_slin48, ast_format_slin96, ast_format_speex, ast_format_speex16, ast_format_speex32, ast_format_t140, ast_format_t140_red, ast_format_ulaw, ast_format_vp8, ast_format_vp9, AST_LOG_CATEGORY_DTLS, AST_LOG_CATEGORY_DTLS_PACKET, AST_LOG_CATEGORY_ICE, AST_LOG_CATEGORY_RTCP, AST_LOG_CATEGORY_RTCP_PACKET, AST_LOG_CATEGORY_RTP, AST_LOG_CATEGORY_RTP_PACKET, ast_register_atexit(), ast_register_cleanup(), AST_RTP_CISCO_DTMF, AST_RTP_CN, AST_RTP_DTMF, ast_rtp_rtcp_received_type(), ast_rtp_rtcp_sent_type(), ast_rwlock_init, debug_category_dtls_id, debug_category_dtls_packet_id, debug_category_ice_id, debug_category_rtcp_id, debug_category_rtcp_packet_id, debug_category_rtp_id, debug_category_rtp_packet_id, mime_types_lock, NULL, rtp_engine_atexit(), rtp_engine_shutdown(), rtp_topic, set_next_mime_type(), STASIS_MESSAGE_TYPE_INIT, stasis_topic_create(), and static_RTP_PT_lock.

Referenced by asterisk_daemon().

◆ ast_rtp_engine_load_format()

int ast_rtp_engine_load_format ( struct ast_format format)

Custom formats declared in codecs.conf at startup must be communicated to the rtp_engine so their mime type can payload number can be initialized.

Definition at line 3368 of file rtp_engine.c.

3369{
3370 char *codec_name = ast_strdupa(ast_format_get_codec_name(format));
3371
3372 codec_name = ast_str_to_upper(codec_name);
3373
3374 set_next_mime_type(format,
3375 0,
3377 codec_name,
3379 add_static_payload(-1, format, 0);
3380
3381 return 0;
3382}
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
const char * ast_codec_media_type2str(enum ast_media_type type)
Conversion function to take a media type and turn it into a string.
Definition: codec.c:348
unsigned int ast_format_get_sample_rate(const struct ast_format *format)
Get the sample rate of a media format.
Definition: format.c:379
const char * ast_format_get_codec_name(const struct ast_format *format)
Get the codec name associated with a format.
Definition: format.c:339
static force_inline char * ast_str_to_upper(char *str)
Convert a string to all upper-case.
Definition: strings.h:1342

References add_static_payload(), ast_codec_media_type2str(), ast_format_get_codec_name(), ast_format_get_sample_rate(), ast_format_get_type(), ast_str_to_upper(), ast_strdupa, ast_rtp_payload_type::format, and set_next_mime_type().

Referenced by load_module().

◆ ast_rtp_engine_register2()

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);
int ast_rtp_engine_register2(struct ast_rtp_engine *engine, struct ast_module *module)
Register an RTP engine.
Definition: rtp_engine.c:330

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

331{
332 struct ast_rtp_engine *current_engine;
333
334 /* Perform a sanity check on the engine structure to make sure it has the basics */
335 if (ast_strlen_zero(engine->name) || !engine->new || !engine->destroy || !engine->write || !engine->read) {
336 ast_log(LOG_WARNING, "RTP Engine '%s' failed sanity check so it was not registered.\n", !ast_strlen_zero(engine->name) ? engine->name : "Unknown");
337 return -1;
338 }
339
340 /* Link owner module to the RTP engine for reference counting purposes */
341 engine->mod = module;
342
344
345 /* Ensure that no two modules with the same name are registered at the same time */
346 AST_RWLIST_TRAVERSE(&engines, current_engine, entry) {
347 if (!strcmp(current_engine->name, engine->name)) {
348 ast_log(LOG_WARNING, "An RTP engine with the name '%s' has already been registered.\n", engine->name);
350 return -1;
351 }
352 }
353
354 /* The engine survived our critique. Off to the list it goes to be used */
356
358
359 ast_verb(5, "Registered RTP engine '%s'\n", engine->name);
360
361 return 0;
362}
#define ast_verb(level,...)
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:741
int(* write)(struct ast_rtp_instance *instance, struct ast_frame *frame)
Definition: rtp_engine.h:672
int(* destroy)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:670
struct ast_module * mod
Definition: rtp_engine.h:666
int(* new)(struct ast_rtp_instance *instance, struct ast_sched_context *sched, struct ast_sockaddr *sa, void *data)
Definition: rtp_engine.h:668
const char * name
Definition: rtp_engine.h:664
struct ast_frame *(* read)(struct ast_rtp_instance *instance, int rtcp)
Definition: rtp_engine.h:709
Definition: search.h:40

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.

◆ ast_rtp_engine_register_srtp()

int ast_rtp_engine_register_srtp ( struct ast_srtp_res srtp_res,
struct ast_srtp_policy_res policy_res 
)

Definition at line 2849 of file rtp_engine.c.

2850{
2851 if (res_srtp || res_srtp_policy) {
2852 return -1;
2853 }
2854 if (!srtp_res || !policy_res) {
2855 return -1;
2856 }
2857
2860
2861 return 0;
2862}
static struct ast_srtp_res srtp_res
Definition: res_srtp.c:103
static struct ast_srtp_policy_res policy_res
Definition: res_srtp.c:115
struct ast_srtp_res * res_srtp
Definition: rtp_engine.c:176
struct ast_srtp_policy_res * res_srtp_policy
Definition: rtp_engine.c:177

References policy_res, res_srtp, res_srtp_policy, and srtp_res.

Referenced by res_srtp_init().

◆ ast_rtp_engine_srtp_is_registered()

int ast_rtp_engine_srtp_is_registered ( void  )

Definition at line 2870 of file rtp_engine.c.

2871{
2872 return res_srtp && res_srtp_policy;
2873}

References res_srtp, and res_srtp_policy.

Referenced by ast_sdp_srtp_alloc().

◆ ast_rtp_engine_unload_format()

int ast_rtp_engine_unload_format ( struct ast_format format)

Formats requiring the use of a format attribute interface must have that interface registered in order for the rtp engine to handle it correctly. If an attribute interface is unloaded, this function must be called to notify the rtp_engine.

Definition at line 3384 of file rtp_engine.c.

3385{
3386 int x;
3387 int y = 0;
3388
3390 /* remove everything pertaining to this format id from the lists */
3391 for (x = 0; x < AST_RTP_MAX_PT; x++) {
3392 if (static_RTP_PT[x]
3393 && ast_format_cmp(static_RTP_PT[x]->format, format) == AST_FORMAT_CMP_EQUAL) {
3394 ao2_ref(static_RTP_PT[x], -1);
3395 static_RTP_PT[x] = NULL;
3396 }
3397 }
3399
3401 /* rebuild the list skipping the items matching this id */
3402 for (x = 0; x < mime_types_len; x++) {
3403 if (ast_format_cmp(ast_rtp_mime_types[x].payload_type.format, format) == AST_FORMAT_CMP_EQUAL) {
3405 continue;
3406 }
3407 if (x != y) {
3409 }
3410 y++;
3411 }
3412 mime_types_len = y;
3414 return 0;
3415}
static void rtp_engine_mime_type_cleanup(int i)
Definition: rtp_engine.c:3288

References ao2_ref, ast_format_cmp(), AST_FORMAT_CMP_EQUAL, AST_RTP_MAX_PT, ast_rtp_mime_types, ast_rwlock_unlock, ast_rwlock_wrlock, ast_rtp_payload_type::format, mime_types_len, mime_types_lock, NULL, rtp_engine_mime_type_cleanup(), static_RTP_PT, and static_RTP_PT_lock.

Referenced by unload_module().

◆ ast_rtp_engine_unregister()

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);
int ast_rtp_engine_unregister(struct ast_rtp_engine *engine)
Unregister an RTP engine.
Definition: rtp_engine.c:364

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

365{
366 struct ast_rtp_engine *current_engine = NULL;
367
369
370 if ((current_engine = AST_RWLIST_REMOVE(&engines, engine, entry))) {
371 ast_verb(5, "Unregistered RTP engine '%s'\n", engine->name);
372 }
373
375
376 return current_engine ? 0 : -1;
377}
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:885

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

Referenced by load_module(), and unload_module().

◆ ast_rtp_engine_unregister_srtp()

void ast_rtp_engine_unregister_srtp ( void  )

Definition at line 2864 of file rtp_engine.c.

2865{
2866 res_srtp = NULL;
2868}

References NULL, res_srtp, and res_srtp_policy.

Referenced by res_srtp_shutdown().

◆ ast_rtp_get_rate()

int ast_rtp_get_rate ( const struct ast_format format)

Retrieve the sample rate of a format according to RTP specifications.

Since
16.7.0
17.1.0
Parameters
formatThe media format
Returns
The sample rate

Definition at line 4215 of file rtp_engine.c.

4216{
4217 /* For those wondering: due to a fluke in RFC publication, G.722 is advertised
4218 * as having a sample rate of 8kHz, while implementations must know that its
4219 * real rate is 16kHz. Seriously.
4220 */
4221 return (ast_format_cmp(format, ast_format_g722) == AST_FORMAT_CMP_EQUAL) ? 8000 : (int)ast_format_get_sample_rate(format);
4222}

References ast_format_cmp(), AST_FORMAT_CMP_EQUAL, ast_format_g722, and ast_format_get_sample_rate().

Referenced by ast_rtcp_calculate_sr_rr_statistics(), ast_rtcp_interpret(), ast_rtp_dtmf_end_with_duration(), ast_rtp_interpret(), calc_rxstamp_and_jitter(), jitterbuffer_frame_get_ntp_timestamp(), process_dtmf_cisco(), process_dtmf_rfc2833(), rtp_raw_write(), and update_jitter_stats().

◆ ast_rtp_glue_register2()

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);
int ast_rtp_glue_register2(struct ast_rtp_glue *glue, struct ast_module *module)
Register RTP glue.
Definition: rtp_engine.c:379

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

380{
381 struct ast_rtp_glue *current_glue = NULL;
382
383 if (ast_strlen_zero(glue->type)) {
384 return -1;
385 }
386
387 glue->mod = module;
388
390
391 AST_RWLIST_TRAVERSE(&glues, current_glue, entry) {
392 if (!strcasecmp(current_glue->type, glue->type)) {
393 ast_log(LOG_WARNING, "RTP glue with the name '%s' has already been registered.\n", glue->type);
395 return -1;
396 }
397 }
398
400
402
403 ast_verb(5, "Registered RTP glue '%s'\n", glue->type);
404
405 return 0;
406}
const char * type
Definition: rtp_engine.h:772
struct ast_module * mod
Definition: rtp_engine.h:774

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, NULL, and ast_rtp_glue::type.

◆ ast_rtp_glue_unregister()

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);
int ast_rtp_glue_unregister(struct ast_rtp_glue *glue)
Unregister RTP glue.
Definition: rtp_engine.c:408

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

409{
410 struct ast_rtp_glue *current_glue = NULL;
411
413
414 if ((current_glue = AST_RWLIST_REMOVE(&glues, glue, entry))) {
415 ast_verb(5, "Unregistered RTP glue '%s'\n", glue->type);
416 }
417
419
420 return current_glue ? 0 : -1;
421}

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

Referenced by load_module(), and unload_module().

◆ ast_rtp_instance_activate()

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:

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.
Definition: rtp_engine.c:2786

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

Since
1.8

Definition at line 2786 of file rtp_engine.c.

2787{
2788 int res;
2789
2790 if (instance->engine->activate) {
2791 ao2_lock(instance);
2792 res = instance->engine->activate(instance);
2793 ao2_unlock(instance);
2794 } else {
2795 res = 0;
2796 }
2797 return res;
2798}
int(* activate)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:721

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

Referenced by apply_negotiated_sdp_stream(), rtp_call(), and test_init_rtp_instances().

◆ ast_rtp_instance_add_srtp_policy()

int ast_rtp_instance_add_srtp_policy ( struct ast_rtp_instance instance,
struct ast_srtp_policy remote_policy,
struct ast_srtp_policy local_policy,
int  rtcp 
)

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

Parameters
instancethe RTP instance
remote_policythe remote endpoint's policy
local_policyour policy for this RTP instance's remote endpoint
rtcp1 for dedicated RTCP policies
Return values
0Success
non-zeroFailure
Note
If no remote policy is provided any existing SRTP policies are left and the new local policy is added

Definition at line 2875 of file rtp_engine.c.

2876{
2877 int res = 0;
2878 struct ast_srtp **srtp;
2879
2880 if (!res_srtp) {
2881 return -1;
2882 }
2883
2884 ao2_lock(instance);
2885
2886 srtp = rtcp ? &instance->rtcp_srtp : &instance->srtp;
2887
2888 if (!*srtp) {
2889 res = res_srtp->create(srtp, instance, remote_policy);
2890 } else if (remote_policy) {
2891 res = res_srtp->replace(srtp, instance, remote_policy);
2892 }
2893 if (!res) {
2894 res = res_srtp->add_stream(*srtp, local_policy);
2895 }
2896
2897 ao2_unlock(instance);
2898
2899 return res;
2900}
struct ast_srtp * rtcp_srtp
Definition: rtp_engine.c:216
struct ast_srtp * srtp
Definition: rtp_engine.c:214
int(* replace)(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy)
Definition: res_srtp.h:38
int(* add_stream)(struct ast_srtp *srtp, struct ast_srtp_policy *policy)
Definition: res_srtp.h:42
int(* create)(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy)
Definition: res_srtp.h:36

References ast_srtp_res::add_stream, ao2_lock, ao2_unlock, ast_srtp_res::create, ast_srtp_res::replace, res_srtp, ast_rtp_instance::rtcp_srtp, and ast_rtp_instance::srtp.

Referenced by crypto_activate().

◆ ast_rtp_instance_available_formats()

void ast_rtp_instance_available_formats ( struct ast_rtp_instance instance,
struct ast_format_cap to_endpoint,
struct ast_format_cap to_asterisk,
struct ast_format_cap result 
)

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
resultcapabilities structure to store and return supported formats in.

Example usage:

ast_rtp_instance_available_formats(instance, to_capabilities, from_capabilities, result_capabilities);
void ast_rtp_instance_available_formats(struct ast_rtp_instance *instance, struct ast_format_cap *to_endpoint, struct ast_format_cap *to_asterisk, struct ast_format_cap *result)
Request the formats that can be transcoded.
Definition: rtp_engine.c:2772

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

2773{
2774 if (instance->engine->available_formats) {
2775 ao2_lock(instance);
2776 instance->engine->available_formats(instance, to_endpoint, to_asterisk, result);
2777 ao2_unlock(instance);
2779 return;
2780 }
2781 }
2782
2783 ast_translate_available_formats(to_endpoint, to_asterisk, result);
2784}
static PGresult * result
Definition: cel_pgsql.c:84
size_t ast_format_cap_count(const struct ast_format_cap *cap)
Get the number of formats present within the capabilities structure.
Definition: format_cap.c:395
void(* available_formats)(struct ast_rtp_instance *instance, struct ast_format_cap *to_endpoint, struct ast_format_cap *to_asterisk, struct ast_format_cap *result)
Definition: rtp_engine.h:725
void ast_translate_available_formats(struct ast_format_cap *dest, struct ast_format_cap *src, struct ast_format_cap *result)
Find available formats.
Definition: translate.c:1616

References ao2_lock, ao2_unlock, ast_format_cap_count(), ast_translate_available_formats(), ast_rtp_engine::available_formats, ast_rtp_instance::engine, and result.

◆ ast_rtp_instance_bundle()

int ast_rtp_instance_bundle ( struct ast_rtp_instance child,
struct ast_rtp_instance parent 
)

Request that an RTP instance be bundled with another.

Since
15.0.0
Parameters
childThe child RTP instance
parentThe parent RTP instance the child should be bundled with
Return values
0success
-1failure

Definition at line 3976 of file rtp_engine.c.

3977{
3978 int res = -1;
3979
3980 if (parent && (child->engine != parent->engine)) {
3981 return -1;
3982 }
3983
3984 ao2_lock(child);
3985 if (child->engine->bundle) {
3986 res = child->engine->bundle(child, parent);
3987 }
3988 ao2_unlock(child);
3989
3990 return res;
3991}
int(* bundle)(struct ast_rtp_instance *child, struct ast_rtp_instance *parent)
Definition: rtp_engine.h:733

References ao2_lock, ao2_unlock, ast_rtp_engine::bundle, and ast_rtp_instance::engine.

Referenced by apply_negotiated_sdp_stream(), and negotiate_incoming_sdp_stream().

◆ ast_rtp_instance_change_source()

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:

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.
Definition: rtp_engine.c:2275

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

2276{
2277 if (instance->engine->change_source) {
2278 ao2_lock(instance);
2279 instance->engine->change_source(instance);
2280 ao2_unlock(instance);
2281 }
2282}
void(* change_source)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:683

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

Referenced by create_outgoing_sdp_stream(), jingle_indicate(), ooh323_indicate(), and unistim_indicate().

◆ ast_rtp_instance_destroy()

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:

int ast_rtp_instance_destroy(struct ast_rtp_instance *instance)
Destroy an RTP instance.
Definition: rtp_engine.c:458

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

459{
460 if (!instance) {
461 return 0;
462 }
464 char buffer[4][512];
465 ast_debug_rtp(1, "%s:\n"
466 " RTT: %s\n"
467 " Loss: %s\n"
468 " Jitter: %s\n"
469 " MES: %s\n",
470 instance->channel_uniqueid,
472 buffer[0], sizeof(buffer[0])),
474 buffer[1], sizeof(buffer[1])),
476 buffer[2], sizeof(buffer[2])),
478 buffer[3], sizeof(buffer[3]))
479 );
480 }
481
482 ao2_cleanup(instance);
483
484 return 0;
485}
char * ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size)
Retrieve quality statistics about an RTP instance.
Definition: rtp_engine.c:2579
@ AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS
Definition: rtp_engine.h:174
@ AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT
Definition: rtp_engine.h:176
@ AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER
Definition: rtp_engine.h:172
@ AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES
Definition: rtp_engine.h:178
#define ast_debug_rtp(sublevel,...)
Log debug level RTP information.
Definition: rtp_engine.h:3014
#define ast_debug_rtp_is_allowed
Definition: rtp_engine.h:3018
char channel_uniqueid[AST_MAX_UNIQUEID]
Definition: rtp_engine.c:218

References ao2_cleanup, ast_debug_rtp, ast_debug_rtp_is_allowed, ast_rtp_instance_get_quality(), AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, and ast_rtp_instance::channel_uniqueid.

Referenced by AST_TEST_DEFINE(), jingle_session_destructor(), multicast_rtp_request(), ooh323_destroy(), rtp_hangup(), stream_destroy(), unicast_rtp_request(), and unistim_hangup_clean().

◆ ast_rtp_instance_dtmf_begin()

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:

int ast_rtp_instance_dtmf_begin(struct ast_rtp_instance *instance, char digit)
Begin sending a DTMF digit.
Definition: rtp_engine.c:2196

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

2197{
2198 int res;
2199
2200 if (instance->engine->dtmf_begin) {
2201 ao2_lock(instance);
2202 res = instance->engine->dtmf_begin(instance, digit);
2203 ao2_unlock(instance);
2204 } else {
2205 res = -1;
2206 }
2207 return res;
2208}
char digit
int(* dtmf_begin)(struct ast_rtp_instance *instance, char digit)
Definition: rtp_engine.h:676

References ao2_lock, ao2_unlock, digit, ast_rtp_engine::dtmf_begin, and ast_rtp_instance::engine.

Referenced by chan_pjsip_digit_begin(), jingle_digit_begin(), and ooh323_digit_begin().

◆ ast_rtp_instance_dtmf_end()

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:

int ast_rtp_instance_dtmf_end(struct ast_rtp_instance *instance, char digit)
Stop sending a DTMF digit.
Definition: rtp_engine.c:2210

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

Since
1.8

Definition at line 2210 of file rtp_engine.c.

2211{
2212 int res;
2213
2214 if (instance->engine->dtmf_end) {
2215 ao2_lock(instance);
2216 res = instance->engine->dtmf_end(instance, digit);
2217 ao2_unlock(instance);
2218 } else {
2219 res = -1;
2220 }
2221 return res;
2222}
int(* dtmf_end)(struct ast_rtp_instance *instance, char digit)
Definition: rtp_engine.h:678

References ao2_lock, ao2_unlock, digit, ast_rtp_engine::dtmf_end, and ast_rtp_instance::engine.

Referenced by ooh323_digit_end().

◆ ast_rtp_instance_dtmf_end_with_duration()

int ast_rtp_instance_dtmf_end_with_duration ( struct ast_rtp_instance instance,
char  digit,
unsigned int  duration 
)

Definition at line 2224 of file rtp_engine.c.

2225{
2226 int res;
2227
2228 if (instance->engine->dtmf_end_with_duration) {
2229 ao2_lock(instance);
2230 res = instance->engine->dtmf_end_with_duration(instance, digit, duration);
2231 ao2_unlock(instance);
2232 } else {
2233 res = -1;
2234 }
2235 return res;
2236}
int(* dtmf_end_with_duration)(struct ast_rtp_instance *instance, char digit, unsigned int duration)
Definition: rtp_engine.h:679

References ao2_lock, ao2_unlock, digit, ast_rtp_engine::dtmf_end_with_duration, and ast_rtp_instance::engine.

Referenced by chan_pjsip_digit_end(), and jingle_digit_end().

◆ ast_rtp_instance_dtmf_mode_get()

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
Returns
DTMF mode

Example usage:

enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get(struct ast_rtp_instance *instance)
Get the DTMF mode of an RTP instance.
Definition: rtp_engine.c:2252
ast_rtp_dtmf_mode
Definition: rtp_engine.h:148

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

Since
1.8

Definition at line 2252 of file rtp_engine.c.

2253{
2254 int res;
2255
2256 if (instance->engine->dtmf_mode_get) {
2257 ao2_lock(instance);
2258 res = instance->engine->dtmf_mode_get(instance);
2259 ao2_unlock(instance);
2260 } else {
2261 res = 0;
2262 }
2263 return res;
2264}
enum ast_rtp_dtmf_mode(* dtmf_mode_get)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:697

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

Referenced by chan_pjsip_digit_begin(), chan_pjsip_digit_end(), native_rtp_bridge_compatible_check(), pjsip_acf_dtmf_mode_write(), and set_caps().

◆ ast_rtp_instance_dtmf_mode_set()

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:

@ AST_RTP_DTMF_MODE_RFC2833
Definition: rtp_engine.h:152
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.
Definition: rtp_engine.c:2238

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

Since
1.8

Definition at line 2238 of file rtp_engine.c.

2239{
2240 int res;
2241
2242 if (instance->engine->dtmf_mode_set) {
2243 ao2_lock(instance);
2244 res = instance->engine->dtmf_mode_set(instance, dtmf_mode);
2245 ao2_unlock(instance);
2246 } else {
2247 res = -1;
2248 }
2249 return res;
2250}
int(* dtmf_mode_set)(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode)
Definition: rtp_engine.h:695

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

Referenced by create_rtp(), get_codecs(), and pjsip_acf_dtmf_mode_write().

◆ ast_rtp_instance_early_bridge()

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

2453{
2454 struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
2455 *vinstance0 = NULL, *vinstance1 = NULL,
2456 *tinstance0 = NULL, *tinstance1 = NULL;
2457 struct ast_rtp_glue *glue0, *glue1;
2458 enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
2459 enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
2462
2463 /* If there is no second channel just immediately bail out, we are of no use in that scenario */
2464 if (!c1 || !cap1 || !cap0) {
2465 ao2_cleanup(cap0);
2466 ao2_cleanup(cap1);
2467 return -1;
2468 }
2469
2470 /* Lock both channels so we can look for the glue that binds them together */
2471 ast_channel_lock_both(c0, c1);
2472
2473 /* Grab glue that binds each channel to something using the RTP engine */
2475 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", glue0 ? ast_channel_name(c1) : ast_channel_name(c0));
2476 goto done;
2477 }
2478
2479 audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
2480 video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;
2481
2482 audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
2483 video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;
2484
2485 /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
2486 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)) {
2487 audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
2488 }
2489 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)) {
2490 audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
2491 }
2492 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) {
2493 glue0->get_codec(c0, cap0);
2494 }
2495 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) {
2496 glue1->get_codec(c1, cap1);
2497 }
2498
2499 /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
2500 if (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE) {
2501 goto done;
2502 }
2503
2504 /* Make sure we have matching codecs */
2505 if (!ast_format_cap_iscompatible(cap0, cap1)) {
2506 goto done;
2507 }
2508
2509 /* Bridge media early */
2510 if (glue0->update_peer(c0, instance1, vinstance1, tinstance1, cap1, 0)) {
2511 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", ast_channel_name(c0), c1 ? ast_channel_name(c1) : "<unspecified>");
2512 }
2513
2514done:
2517
2518 ao2_cleanup(cap0);
2519 ao2_cleanup(cap1);
2520
2521 unref_instance_cond(&instance0);
2522 unref_instance_cond(&instance1);
2523 unref_instance_cond(&vinstance0);
2524 unref_instance_cond(&vinstance1);
2525 unref_instance_cond(&tinstance0);
2526 unref_instance_cond(&tinstance1);
2527
2528 ast_debug(1, "Setting early bridge SDP of '%s' with that of '%s'\n", ast_channel_name(c0), c1 ? ast_channel_name(c1) : "<unspecified>");
2529
2530 return 0;
2531}
const char * ast_channel_name(const struct ast_channel *chan)
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition: channel.h:2929
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
#define ast_channel_unlock(chan)
Definition: channel.h:2923
@ AST_FORMAT_CAP_FLAG_DEFAULT
Definition: format_cap.h:38
int ast_format_cap_iscompatible(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2)
Determine if any joint capabilities exist between two capabilities structures.
Definition: format_cap.c:653
#define ast_format_cap_alloc(flags)
Allocate a new ast_format_cap structure.
Definition: format_cap.h:49
static void unref_instance_cond(struct ast_rtp_instance **instance)
Conditionally unref an rtp instance.
Definition: rtp_engine.c:2341
struct ast_rtp_glue * ast_rtp_instance_get_glue(const char *type)
Get the RTP glue that binds a channel to the RTP engine.
Definition: rtp_engine.c:2321
ast_rtp_glue_result
Definition: rtp_engine.h:158
@ AST_RTP_GLUE_RESULT_REMOTE
Definition: rtp_engine.h:162
@ AST_RTP_GLUE_RESULT_FORBID
Definition: rtp_engine.h:160
enum ast_rtp_glue_result(* get_rtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance)
Callback for retrieving the RTP instance carrying audio.
Definition: rtp_engine.h:779
void(* get_codec)(struct ast_channel *chan, struct ast_format_cap *result_cap)
Callback for retrieving codecs that the channel can do. Result returned in result_cap.
Definition: rtp_engine.h:811
int(* update_peer)(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, const struct ast_format_cap *cap, int nat_active)
Definition: rtp_engine.h:806
enum ast_rtp_glue_result(* get_vrtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance)
Callback for retrieving the RTP instance carrying video.
Definition: rtp_engine.h:791
int done
Definition: test_amihooks.c:48

References ao2_cleanup, ast_channel_lock_both, ast_channel_name(), ast_channel_tech(), ast_channel_unlock, ast_debug, ast_format_cap_alloc, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_iscompatible(), ast_log, AST_RTP_GLUE_RESULT_FORBID, AST_RTP_GLUE_RESULT_REMOTE, ast_rtp_instance_get_glue(), done, ast_rtp_glue::get_codec, ast_rtp_glue::get_rtp_info, ast_rtp_glue::get_vrtp_info, LOG_WARNING, NULL, type, unref_instance_cond(), and ast_rtp_glue::update_peer.

◆ ast_rtp_instance_early_bridge_make_compatible()

void ast_rtp_instance_early_bridge_make_compatible ( struct ast_channel c_dst,
struct ast_channel c_src 
)

Make two channels compatible for early bridging.

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

Definition at line 2366 of file rtp_engine.c.

2367{
2368 struct ast_rtp_instance *instance_dst = NULL, *instance_src = NULL,
2369 *vinstance_dst = NULL, *vinstance_src = NULL,
2370 *tinstance_dst = NULL, *tinstance_src = NULL;
2371 struct ast_rtp_glue *glue_dst, *glue_src;
2372 enum ast_rtp_glue_result audio_glue_dst_res = AST_RTP_GLUE_RESULT_FORBID, video_glue_dst_res = AST_RTP_GLUE_RESULT_FORBID;
2373 enum ast_rtp_glue_result audio_glue_src_res = AST_RTP_GLUE_RESULT_FORBID, video_glue_src_res = AST_RTP_GLUE_RESULT_FORBID;
2376
2377 /* Lock both channels so we can look for the glue that binds them together */
2378 ast_channel_lock_both(c_dst, c_src);
2379
2380 if (!cap_src || !cap_dst) {
2381 goto done;
2382 }
2383
2384 /* Grab glue that binds each channel to something using the RTP engine */
2385 if (!(glue_dst = ast_rtp_instance_get_glue(ast_channel_tech(c_dst)->type)) || !(glue_src = ast_rtp_instance_get_glue(ast_channel_tech(c_src)->type))) {
2386 ast_debug(1, "Can't find native functions for channel '%s'\n", glue_dst ? ast_channel_name(c_src) : ast_channel_name(c_dst));
2387 goto done;
2388 }
2389
2390 audio_glue_dst_res = glue_dst->get_rtp_info(c_dst, &instance_dst);
2391 video_glue_dst_res = glue_dst->get_vrtp_info ? glue_dst->get_vrtp_info(c_dst, &vinstance_dst) : AST_RTP_GLUE_RESULT_FORBID;
2392
2393 audio_glue_src_res = glue_src->get_rtp_info(c_src, &instance_src);
2394 video_glue_src_res = glue_src->get_vrtp_info ? glue_src->get_vrtp_info(c_src, &vinstance_src) : AST_RTP_GLUE_RESULT_FORBID;
2395
2396 /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
2397 if (video_glue_dst_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue_dst_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue_dst_res != AST_RTP_GLUE_RESULT_REMOTE)) {
2398 audio_glue_dst_res = AST_RTP_GLUE_RESULT_FORBID;
2399 }
2400 if (video_glue_src_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue_src_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue_src_res != AST_RTP_GLUE_RESULT_REMOTE)) {
2401 audio_glue_src_res = AST_RTP_GLUE_RESULT_FORBID;
2402 }
2403 if (audio_glue_dst_res == AST_RTP_GLUE_RESULT_REMOTE && (video_glue_dst_res == AST_RTP_GLUE_RESULT_FORBID || video_glue_dst_res == AST_RTP_GLUE_RESULT_REMOTE) && glue_dst->get_codec) {
2404 glue_dst->get_codec(c_dst, cap_dst);
2405 }
2406 if (audio_glue_src_res == AST_RTP_GLUE_RESULT_REMOTE && (video_glue_src_res == AST_RTP_GLUE_RESULT_FORBID || video_glue_src_res == AST_RTP_GLUE_RESULT_REMOTE) && glue_src->get_codec) {
2407 glue_src->get_codec(c_src, cap_src);
2408 }
2409
2410 /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
2411 if (audio_glue_dst_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue_src_res != AST_RTP_GLUE_RESULT_REMOTE) {
2412 goto done;
2413 }
2414
2415 /* Make sure we have matching codecs */
2416 if (!ast_format_cap_iscompatible(cap_dst, cap_src)) {
2417 goto done;
2418 }
2419
2420 ast_rtp_codecs_payloads_xover(&instance_src->codecs, &instance_dst->codecs, instance_dst);
2421
2422 if (vinstance_dst && vinstance_src) {
2423 ast_rtp_codecs_payloads_xover(&vinstance_src->codecs, &vinstance_dst->codecs, vinstance_dst);
2424 }
2425 if (tinstance_dst && tinstance_src) {
2426 ast_rtp_codecs_payloads_xover(&tinstance_src->codecs, &tinstance_dst->codecs, tinstance_dst);
2427 }
2428
2429 if (glue_dst->update_peer(c_dst, instance_src, vinstance_src, tinstance_src, cap_src, 0)) {
2430 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n",
2431 ast_channel_name(c_dst), ast_channel_name(c_src));
2432 } else {
2433 ast_debug(1, "Seeded SDP of '%s' with that of '%s'\n",
2434 ast_channel_name(c_dst), ast_channel_name(c_src));
2435 }
2436
2437done:
2438 ast_channel_unlock(c_dst);
2439 ast_channel_unlock(c_src);
2440
2441 ao2_cleanup(cap_dst);
2442 ao2_cleanup(cap_src);
2443
2444 unref_instance_cond(&instance_dst);
2445 unref_instance_cond(&instance_src);
2446 unref_instance_cond(&vinstance_dst);
2447 unref_instance_cond(&vinstance_src);
2448 unref_instance_cond(&tinstance_dst);
2449 unref_instance_cond(&tinstance_src);
2450}
void ast_rtp_codecs_payloads_xover(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
Crossover copy the tx payload mapping of src to the rx payload mapping of dest.
Definition: rtp_engine.c:1296
struct ast_rtp_codecs codecs
Definition: rtp_engine.c:204

References ao2_cleanup, ast_channel_lock_both, ast_channel_name(), ast_channel_tech(), ast_channel_unlock, ast_debug, ast_format_cap_alloc, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_iscompatible(), ast_log, ast_rtp_codecs_payloads_xover(), AST_RTP_GLUE_RESULT_FORBID, AST_RTP_GLUE_RESULT_REMOTE, ast_rtp_instance_get_glue(), ast_rtp_instance::codecs, done, ast_rtp_glue::get_codec, ast_rtp_glue::get_rtp_info, ast_rtp_glue::get_vrtp_info, LOG_WARNING, NULL, type, unref_instance_cond(), and ast_rtp_glue::update_peer.

Referenced by dial_exec_full(), and do_forward().

◆ ast_rtp_instance_extmap_clear()

void ast_rtp_instance_extmap_clear ( struct ast_rtp_instance instance)

Clear negotiated RTP extension information.

Parameters
instanceThe RTP instance to clear negotiated extension information on

Definition at line 884 of file rtp_engine.c.

885{
886 static const struct rtp_extmap extmap_none = {
889 };
890 int idx;
891
892 ao2_lock(instance);
893
894 /* Clear both the known unique ids and the negotiated extensions as we are about to have
895 * new results set on us.
896 */
897 for (idx = 0; idx < AST_VECTOR_SIZE(&instance->extmap_unique_ids); ++idx) {
898 AST_VECTOR_REPLACE(&instance->extmap_unique_ids, idx, extmap_none);
899 }
900
901 for (idx = 0; idx < AST_VECTOR_SIZE(&instance->extmap_negotiated); ++idx) {
902 AST_VECTOR_REPLACE(&instance->extmap_negotiated, idx, -1);
903 }
904
905 ao2_unlock(instance);
906}
@ AST_RTP_EXTENSION_UNSUPPORTED
Definition: rtp_engine.h:592
@ AST_RTP_EXTENSION_DIRECTION_NONE
Definition: rtp_engine.h:821
struct ast_rtp_instance::@383 extmap_negotiated
struct ast_rtp_instance::@384 extmap_unique_ids
enum ast_rtp_extension extension
Definition: rtp_engine.c:182

References ao2_lock, ao2_unlock, AST_RTP_EXTENSION_DIRECTION_NONE, AST_RTP_EXTENSION_UNSUPPORTED, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, rtp_extmap::extension, ast_rtp_instance::extmap_negotiated, and ast_rtp_instance::extmap_unique_ids.

Referenced by process_extmap_attributes().

◆ ast_rtp_instance_extmap_count()

size_t ast_rtp_instance_extmap_count ( struct ast_rtp_instance instance)

Get the number of known unique identifiers.

Parameters
instanceThe RTP instance to retrieve the count from
Returns
the number of known unique identifiers
Since
15.5.0

Definition at line 921 of file rtp_engine.c.

922{
923 size_t count;
924
925 ao2_lock(instance);
926 count = AST_VECTOR_SIZE(&instance->extmap_unique_ids);
927 ao2_unlock(instance);
928
929 return count;
930}

References ao2_lock, ao2_unlock, AST_VECTOR_SIZE, and ast_rtp_instance::extmap_unique_ids.

Referenced by add_extmap_to_stream(), and enable_rtp_extension().

◆ ast_rtp_instance_extmap_enable()

int ast_rtp_instance_extmap_enable ( struct ast_rtp_instance instance,
int  id,
enum ast_rtp_extension  extension,
enum ast_rtp_extension_direction  direction 
)

Enable support for an RTP extension on an instance.

Parameters
instanceThe RTP instance to enable the extension on
idThe unique local identifier to use for this extension (-1 to have one auto selected)
extensionThe RTP extension
directionThe initial direction that the RTP extension should be used in
Return values
0success
-1failure
Since
15.5.0

Definition at line 754 of file rtp_engine.c.

756{
757 struct rtp_extmap extmap = {
759 .direction = direction,
760 };
761
762 ao2_lock(instance);
763
764 if (!instance->engine->extension_enable || !instance->engine->extension_enable(instance, extension)) {
765 ao2_unlock(instance);
766 return 0;
767 }
768
769 /* We store enabled extensions separately so we can easily do negotiation */
771 ao2_unlock(instance);
772 return -1;
773 }
774
775 if (id <= 0) {
776 /* We find a free unique identifier for this extension by just appending it to the
777 * vector of unique ids. The size of the vector will become its unique identifier.
778 * As well when we are asking for information on the extensions it will be returned,
779 * allowing it to be added to the SDP offer.
780 */
781 if (AST_VECTOR_APPEND(&instance->extmap_unique_ids, extmap)) {
783 ao2_unlock(instance);
784 return -1;
785 }
786 id = AST_VECTOR_SIZE(&instance->extmap_unique_ids);
787 } else {
788 /* Otherwise we put it precisely where they want it */
789 if (AST_VECTOR_REPLACE(&instance->extmap_unique_ids, id - 1, extmap)) {
791 ao2_unlock(instance);
792 return -1;
793 }
794 }
795
796 /* Now that we have an id add the extension to here */
797 if (AST_VECTOR_REPLACE(&instance->extmap_negotiated, extension, id)) {
801 AST_VECTOR_REPLACE(&instance->extmap_unique_ids, id - 1, extmap);
802 ao2_unlock(instance);
803 return -1;
804 }
805
806 ao2_unlock(instance);
807
808 return 0;
809}
direction
int(* extension_enable)(struct ast_rtp_instance *instance, enum ast_rtp_extension extension)
Definition: rtp_engine.h:747
struct ast_rtp_instance::@382 extmap_enabled
structure to hold extensions
enum ast_rtp_extension_direction direction
Definition: rtp_engine.c:184
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256

References ao2_lock, ao2_unlock, AST_RTP_EXTENSION_DIRECTION_NONE, AST_RTP_EXTENSION_UNSUPPORTED, AST_VECTOR_APPEND, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, rtp_extmap::direction, ast_rtp_instance::engine, rtp_extmap::extension, ast_rtp_engine::extension_enable, ast_rtp_instance::extmap_enabled, ast_rtp_instance::extmap_negotiated, and ast_rtp_instance::extmap_unique_ids.

Referenced by enable_rtp_extension().

◆ ast_rtp_instance_extmap_get_direction()

enum ast_rtp_extension_direction ast_rtp_instance_extmap_get_direction ( struct ast_rtp_instance instance,
int  id 
)

Retrieve the negotiated direction for an RTP extension id.

Parameters
instanceThe RTP instance to retrieve the direction from
idThe negotiated RTP extension id
Returns
direction the direction that has been negotiated
Since
15.5.0

Definition at line 952 of file rtp_engine.c.

953{
955
956 ao2_lock(instance);
957
958 if (0 < id && id <= AST_VECTOR_SIZE(&instance->extmap_unique_ids)) {
959 struct rtp_extmap *extmap = AST_VECTOR_GET_ADDR(&instance->extmap_unique_ids, id - 1);
960
961 direction = extmap->direction;
962 }
963 ao2_unlock(instance);
964
965 return direction;
966}
ast_rtp_extension_direction
Directions for RTP extensions.
Definition: rtp_engine.h:819
#define AST_VECTOR_GET_ADDR(vec, idx)
Get an address of element in a vector.
Definition: vector.h:668

References ao2_lock, ao2_unlock, AST_RTP_EXTENSION_DIRECTION_NONE, AST_VECTOR_GET_ADDR, AST_VECTOR_SIZE, rtp_extmap::direction, and ast_rtp_instance::extmap_unique_ids.

Referenced by add_extmap_to_stream().

◆ ast_rtp_instance_extmap_get_extension()

enum ast_rtp_extension ast_rtp_instance_extmap_get_extension ( struct ast_rtp_instance instance,
int  id 
)

Retrieve the extension for an RTP extension id.

Parameters
instanceThe RTP instance to retrieve the extension from
idThe negotiated RTP extension id
Returns
extension the extension that maps to the id
Since
15.5.0
Note
This will return AST_RTP_EXTENSION_UNSUPPORTED if an extension was proposed for this unique identifier but it is not supported or if the unique identifier is unused.

Definition at line 932 of file rtp_engine.c.

933{
935
936 ao2_lock(instance);
937
938 /* The local unique identifier starts at '1' so the highest unique identifier
939 * can be the actual size of the vector. We compensate (as it is 0 index based)
940 * by dropping it down to 1 to get the correct information.
941 */
942 if (0 < id && id <= AST_VECTOR_SIZE(&instance->extmap_unique_ids)) {
943 struct rtp_extmap *extmap = AST_VECTOR_GET_ADDR(&instance->extmap_unique_ids, id - 1);
944
945 extension = extmap->extension;
946 }
947 ao2_unlock(instance);
948
949 return extension;
950}
ast_rtp_extension
Known RTP extensions.
Definition: rtp_engine.h:590

References ao2_lock, ao2_unlock, AST_RTP_EXTENSION_UNSUPPORTED, AST_VECTOR_GET_ADDR, AST_VECTOR_SIZE, rtp_extmap::extension, and ast_rtp_instance::extmap_unique_ids.

Referenced by add_extmap_to_stream(), and ast_rtp_instance_extmap_get_uri().

◆ ast_rtp_instance_extmap_get_id()

int ast_rtp_instance_extmap_get_id ( struct ast_rtp_instance instance,
enum ast_rtp_extension  extension 
)

Retrieve the id for an RTP extension.

Parameters
instanceThe RTP instance to retrieve the id from
extensionThe RTP extension
Return values
-1not negotiated
idif negotiated
Since
15.5.0

Definition at line 908 of file rtp_engine.c.

909{
910 int id = -1;
911
912 ao2_lock(instance);
913 if (extension < AST_VECTOR_SIZE(&instance->extmap_negotiated)) {
915 }
916 ao2_unlock(instance);
917
918 return id;
919}
enum queue_result id
Definition: app_queue.c:1638

References ao2_lock, ao2_unlock, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_instance::extmap_negotiated, and id.

Referenced by ast_rtp_rtcp_handle_nack(), enable_rtp_extension(), rtp_instance_parse_extmap_extensions(), and rtp_raw_write().

◆ ast_rtp_instance_extmap_get_uri()

const char * ast_rtp_instance_extmap_get_uri ( struct ast_rtp_instance instance,
int  id 
)

Retrieve the URI for an RTP extension id.

Parameters
instanceThe RTP instance to retrieve the direction from
idThe negotiated RTP extension id
Returns
The URI for the RTP extension
Since
15.5.0

Definition at line 968 of file rtp_engine.c.

969{
971
973 (unsigned int)extension >= ARRAY_LEN(rtp_extension_uris)) {
974 return NULL;
975 }
976
978}
enum ast_rtp_extension ast_rtp_instance_extmap_get_extension(struct ast_rtp_instance *instance, int id)
Retrieve the extension for an RTP extension id.
Definition: rtp_engine.c:932
static const char *const rtp_extension_uris[AST_RTP_EXTENSION_MAX]
URIs for known RTP extensions.
Definition: rtp_engine.c:234

References ARRAY_LEN, AST_RTP_EXTENSION_UNSUPPORTED, ast_rtp_instance_extmap_get_extension(), rtp_extmap::extension, NULL, and rtp_extension_uris.

Referenced by add_extmap_to_stream().

◆ ast_rtp_instance_extmap_negotiate()

int ast_rtp_instance_extmap_negotiate ( struct ast_rtp_instance instance,
int  id,
enum ast_rtp_extension_direction  direction,
const char *  uri,
const char *  attributes 
)

Negotiate received RTP extension information.

Parameters
instanceThe RTP instance to set the extension on
idThe local identifier for the extension
directionThe direction that the extension should be used in
uriThe unique URI for the extension
attributesAttributes specific to this extension (if NULL or empty then no attributes)
Return values
0success
-1failure
Since
15.5.0

Definition at line 840 of file rtp_engine.c.

842{
843 /* 'attributes' is currently unused but exists in the API to ensure it does not need to be altered
844 * in the future in case we need to use it.
845 */
846 int idx;
848
849 /* Per the RFC the identifier has to be 1 or above */
850 if (id < 1) {
851 return -1;
852 }
853
854 /* Convert the provided URI to the internal representation */
855 for (idx = 0; idx < ARRAY_LEN(rtp_extension_uris); ++idx) {
856 if (!strcasecmp(rtp_extension_uris[idx], uri)) {
857 extension = idx;
858 break;
859 }
860 }
861
862 ao2_lock(instance);
863 /* We only accept the extension if it is enabled */
864 if (extension < AST_VECTOR_SIZE(&instance->extmap_enabled) &&
866 struct rtp_extmap extmap = {
869 };
870
871 /* If the direction negotiation failed then don't accept or use this extension */
875 }
876 AST_VECTOR_REPLACE(&instance->extmap_unique_ids, id - 1, extmap);
877 }
878 }
879 ao2_unlock(instance);
880
881 return 0;
882}
static enum ast_rtp_extension_direction rtp_extmap_negotiate_direction(enum ast_rtp_extension_direction ours, enum ast_rtp_extension_direction theirs)
Helper function which negotiates two RTP extension directions to get our current direction.
Definition: rtp_engine.c:812

References ao2_lock, ao2_unlock, ARRAY_LEN, AST_RTP_EXTENSION_DIRECTION_NONE, AST_RTP_EXTENSION_UNSUPPORTED, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, rtp_extmap::direction, rtp_extmap::extension, ast_rtp_instance::extmap_enabled, ast_rtp_instance::extmap_negotiated, ast_rtp_instance::extmap_unique_ids, rtp_extension_uris, and rtp_extmap_negotiate_direction().

Referenced by process_extmap_attributes().

◆ ast_rtp_instance_fd()

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);
int ast_rtp_instance_fd(struct ast_rtp_instance *instance, int rtcp)
Get the file descriptor for an RTP session (or RTCP)
Definition: rtp_engine.c:2307

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

Since
1.8

Definition at line 2307 of file rtp_engine.c.

2308{
2309 int res;
2310
2311 if (instance->engine->fd) {
2312 ao2_lock(instance);
2313 res = instance->engine->fd(instance, rtcp);
2314 ao2_unlock(instance);
2315 } else {
2316 res = -1;
2317 }
2318 return res;
2319}
int(* fd)(struct ast_rtp_instance *instance, int rtcp)
Definition: rtp_engine.h:703

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

Referenced by apply_negotiated_sdp_stream(), check_for_rtp_changes(), configure_local_rtp(), jingle_enable_video(), jingle_new(), rtp_find_rtcp_fd_position(), start_rtp(), unicast_rtp_request(), and unistim_new().

◆ ast_rtp_instance_get_active_glue()

struct ast_rtp_glue * ast_rtp_instance_get_active_glue ( struct ast_rtp_instance instance)

Get the RTP glue in use on an RTP instance.

Parameters
instanceThe RTP instance
Returns
pointer to the glue

Example:

struct ast_rtp_glue * ast_rtp_instance_get_active_glue(struct ast_rtp_instance *instance)
Get the RTP glue in use on an RTP instance.
Definition: rtp_engine.c:2844

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

Since
1.8

Definition at line 2844 of file rtp_engine.c.

2845{
2846 return instance->glue;
2847}
struct ast_rtp_glue * glue
Definition: rtp_engine.c:212

References ast_rtp_instance::glue.

◆ ast_rtp_instance_get_and_cmp_local_address()

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:
int ret;
char * address
Definition: f2c.h:59
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.
Definition: rtp_engine.c:651
Socket address structure.
Definition: netsock2.h:97

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

653{
654 ao2_lock(instance);
655 if (ast_sockaddr_cmp(address, &instance->local_address) != 0) {
657 ao2_unlock(instance);
658 return 1;
659 }
660 ao2_unlock(instance);
661
662 return 0;
663}
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:167
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
Definition: netsock2.c:388
struct ast_sockaddr local_address
Definition: rtp_engine.c:196

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

◆ ast_rtp_instance_get_and_cmp_requested_target_address()

int ast_rtp_instance_get_and_cmp_requested_target_address ( struct ast_rtp_instance instance,
struct ast_sockaddr address 
)

Get the requested target address of the remote endpoint and compare it to the given address.

Parameters
instanceThe instance that we want to get the remote address for
addressAn initialized address that may be overwritten addresses differ
Return values
0address was not changed
1address was changed

Definition at line 673 of file rtp_engine.c.

675{
676 ao2_lock(instance);
677 if (ast_sockaddr_cmp(address, &instance->requested_target_address) != 0) {
679 ao2_unlock(instance);
680 return 1;
681 }
682 ao2_unlock(instance);
683
684 return 0;
685}
struct ast_sockaddr requested_target_address
Definition: rtp_engine.c:198

References ao2_lock, ao2_unlock, ast_sockaddr_cmp(), ast_sockaddr_copy(), and ast_rtp_instance::requested_target_address.

◆ ast_rtp_instance_get_bridged()

struct ast_rtp_instance * ast_rtp_instance_get_bridged ( struct ast_rtp_instance instance)

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

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

Example usage:

struct ast_rtp_instance * ast_rtp_instance_get_bridged(struct ast_rtp_instance *instance)
Get the other RTP instance that an instance is bridged to.
Definition: rtp_engine.c:2349
struct ast_rtp_instance * bridged
Definition: rtp_engine.c:202

This gets the RTP instance that instance0 is bridged to.

Since
1.8

Definition at line 2349 of file rtp_engine.c.

2350{
2351 struct ast_rtp_instance *bridged;
2352
2353 ao2_lock(instance);
2354 bridged = instance->bridged;
2355 ao2_unlock(instance);
2356 return bridged;
2357}

References ao2_lock, ao2_unlock, and ast_rtp_instance::bridged.

Referenced by ast_rtp_interpret().

◆ ast_rtp_instance_get_channel_id()

const char * ast_rtp_instance_get_channel_id ( struct ast_rtp_instance instance)

Get the unique ID of the channel that owns this RTP instance.

Note that this should remain valid for the lifetime of the RTP instance.

Parameters
instanceThe RTP instance
Returns
The unique ID of the channel
Return values
Emptystring if no channel owns this RTP instance
Since
12

Definition at line 570 of file rtp_engine.c.

571{
572 return instance->channel_uniqueid;
573}

References ast_rtp_instance::channel_uniqueid.

Referenced by __rtp_recvfrom(), ast_rtcp_interpret(), ast_rtp_get_stat(), ast_rtp_prop_set(), ast_rtp_stop(), ast_rtp_write(), calc_rxstamp_and_jitter(), rtp_check_timeout(), rtp_raw_write(), rtp_transport_wide_cc_feedback_produce(), update_local_mes_stats(), and update_reported_mes_stats().

◆ ast_rtp_instance_get_cname()

const char * ast_rtp_instance_get_cname ( struct ast_rtp_instance rtp)

Retrieve the CNAME used in RTCP SDES items.

This is a pointer directly into the RTP struct, not a copy.

Parameters
rtpThe RTP instance
Returns
the CNAME

Definition at line 3963 of file rtp_engine.c.

3964{
3965 const char *cname = "";
3966
3967 ao2_lock(rtp);
3968 if (rtp->engine->cname_get) {
3969 cname = rtp->engine->cname_get(rtp);
3970 }
3971 ao2_unlock(rtp);
3972
3973 return cname;
3974}
const char *(* cname_get)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:731

References ao2_lock, ao2_unlock, ast_rtp_engine::cname_get, and ast_rtp_instance::engine.

Referenced by add_ssrc_to_stream().

◆ ast_rtp_instance_get_codecs()

struct ast_rtp_codecs * ast_rtp_instance_get_codecs ( struct ast_rtp_instance instance)

Get the codecs structure of an RTP instance.

Parameters
instanceThe RTP instance to get the codecs structure from

Example usage:

struct ast_rtp_codecs * ast_rtp_instance_get_codecs(struct ast_rtp_instance *instance)
Get the codecs structure of an RTP instance.
Definition: rtp_engine.c:749

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

Since
1.8

Definition at line 749 of file rtp_engine.c.

750{
751 return &instance->codecs;
752}

References ast_rtp_instance::codecs.

Referenced by apply_cap_to_bundled(), ast_rtp_dtmf_begin(), ast_rtp_interpret(), ast_rtp_read(), ast_rtp_sendcng(), ast_rtp_write(), bridge_p2p_rtp_write(), configure_local_rtp(), create_outgoing_sdp_stream(), jingle_add_payloads_to_description(), jingle_enable_video(), jingle_interpret_description(), jingle_new(), multicast_rtp_write(), native_rtp_bridge_compatible_check(), ooh323_set_write_format(), send_start_rtp(), set_caps(), set_incoming_call_offer_cap(), and setup_rtp_connection().

◆ ast_rtp_instance_get_data()

void * ast_rtp_instance_get_data ( struct ast_rtp_instance instance)

Get the data portion of an RTP instance.

Parameters
instanceThe RTP instance we want the data portion from

Example usage:

struct *blob = ast_rtp_instance_get_data(instance);
(
void * ast_rtp_instance_get_data(struct ast_rtp_instance *instance)
Get the data portion of an RTP instance.
Definition: rtp_engine.c:585

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

Since
1.8

Definition at line 585 of file rtp_engine.c.

586{
587 return instance->data;
588}

References ast_rtp_instance::data.

Referenced by __rtp_recvfrom(), __rtp_sendto(), ast_rtcp_calculate_sr_rr_statistics(), ast_rtcp_generate_nack(), ast_rtcp_generate_report(), ast_rtcp_generate_sdes(), ast_rtcp_interpret(), ast_rtcp_read(), ast_rtcp_write(), ast_rtp_bundle(), ast_rtp_change_source(), ast_rtp_destroy(), ast_rtp_dtmf_begin(), ast_rtp_dtmf_continuation(), ast_rtp_dtmf_end_with_duration(), ast_rtp_dtmf_mode_get(), ast_rtp_dtmf_mode_set(), ast_rtp_fd(), ast_rtp_get_cname(), ast_rtp_get_ssrc(), ast_rtp_get_stat(), ast_rtp_interpret(), ast_rtp_local_bridge(), ast_rtp_prop_set(), ast_rtp_qos_set(), ast_rtp_read(), ast_rtp_remote_address_set(), ast_rtp_rtcp_handle_nack(), ast_rtp_sendcng(), ast_rtp_set_remote_ssrc(), ast_rtp_set_stream_num(), ast_rtp_stop(), ast_rtp_stun_request(), ast_rtp_update_source(), ast_rtp_write(), bridge_p2p_rtp_write(), create_dtmf_frame(), multicast_rtp_activate(), multicast_rtp_destroy(), multicast_rtp_write(), process_cn_rfc3389(), process_dtmf_cisco(), process_dtmf_rfc2833(), red_write(), rtp_instance_parse_transport_wide_cc(), rtp_raw_write(), rtp_red_buffer(), rtp_red_init(), rtp_sendto(), and rtp_transport_wide_cc_feedback_produce().

◆ ast_rtp_instance_get_dtls()

struct ast_rtp_engine_dtls * ast_rtp_instance_get_dtls ( struct ast_rtp_instance instance)

Obtain a pointer to the DTLS support present on an RTP instance.

Parameters
instancethe RTP instance
Returns
DTLS support if present
Return values
NULLif no DTLS support available

Definition at line 3150 of file rtp_engine.c.

3151{
3152 if (instance->engine->dtls) {
3153 return &rtp_dtls_wrappers;
3154 }
3155 /* DTLS not available */
3156 return NULL;
3157}
static struct ast_rtp_engine_dtls rtp_dtls_wrappers
Definition: rtp_engine.c:3137
struct ast_rtp_engine_dtls * dtls
Definition: rtp_engine.h:741

References ast_rtp_engine::dtls, ast_rtp_instance::engine, NULL, and rtp_dtls_wrappers.

Referenced by add_crypto_to_stream(), add_fingerprints_if_present(), apply_dtls_attrib(), ast_sdp_get_rtp_profile(), and setup_dtls_srtp().

◆ ast_rtp_instance_get_engine()

struct ast_rtp_engine * ast_rtp_instance_get_engine ( struct ast_rtp_instance instance)

Get the RTP engine in use on an RTP instance.

Parameters
instanceThe RTP instance
Returns
pointer to the engine

Example usage:

struct ast_rtp_engine *engine = ast_rtp_instance_get_engine(instance);
struct ast_rtp_engine * ast_rtp_instance_get_engine(struct ast_rtp_instance *instance)
Get the RTP engine in use on an RTP instance.
Definition: rtp_engine.c:2839

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

Since
1.8

Definition at line 2839 of file rtp_engine.c.

2840{
2841 return instance->engine;
2842}

References ast_rtp_instance::engine.

Referenced by native_rtp_bridge_compatible_check(), native_rtp_bridge_start(), and native_rtp_bridge_stop().

◆ ast_rtp_instance_get_extended_prop()

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

713{
714 void *prop;
715
716 if (instance->engine->extended_prop_get) {
717 ao2_lock(instance);
718 prop = instance->engine->extended_prop_get(instance, property);
719 ao2_unlock(instance);
720 } else {
721 prop = NULL;
722 }
723
724 return prop;
725}
void *(* extended_prop_get)(struct ast_rtp_instance *instance, int property)
Definition: rtp_engine.h:687

References ao2_lock, ao2_unlock, ast_rtp_instance::engine, ast_rtp_engine::extended_prop_get, and NULL.

◆ ast_rtp_instance_get_glue()

struct ast_rtp_glue * ast_rtp_instance_get_glue ( const char *  type)

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

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

Example usage:

struct ast_rtp_glue *glue = ast_rtp_instance_get_glue("Example");
struct ast_rtp_glue * ast_rtp_instance_get_glue(const char *type)
Get the RTP glue that binds a channel to the RTP engine.
Definition: rtp_engine.c:2321

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

Since
1.8

Definition at line 2321 of file rtp_engine.c.

2322{
2323 struct ast_rtp_glue *glue = NULL;
2324
2326
2328 if (!strcasecmp(glue->type, type)) {
2329 break;
2330 }
2331 }
2332
2334
2335 return glue;
2336}
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78

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

Referenced by ast_ari_channels_rtpstatistics(), ast_rtp_instance_early_bridge(), ast_rtp_instance_early_bridge_make_compatible(), ast_rtp_instance_make_compatible(), and rtp_glue_data_get().

◆ ast_rtp_instance_get_hold_timeout()

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
Returns
timeout value

Example usage:

int timeout = ast_rtp_instance_get_hold_timeout(instance);
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.
Definition: rtp_engine.c:2829

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

Since
1.8

Definition at line 2829 of file rtp_engine.c.

2830{
2831 return instance->holdtimeout;
2832}

References ast_rtp_instance::holdtimeout.

◆ ast_rtp_instance_get_ice()

struct ast_rtp_engine_ice * ast_rtp_instance_get_ice ( struct ast_rtp_instance instance)

Obtain a pointer to the ICE support present on an RTP instance.

Parameters
instancethe RTP instance
Returns
ICE support if present
Return values
NULLif no ICE support available

Definition at line 3030 of file rtp_engine.c.

3031{
3032 if (instance->engine->ice) {
3033 return &rtp_ice_wrappers;
3034 }
3035 /* ICE not available */
3036 return NULL;
3037}
static struct ast_rtp_engine_ice rtp_ice_wrappers
Definition: rtp_engine.c:3016
struct ast_rtp_engine_ice * ice
Definition: rtp_engine.h:739

References ast_rtp_instance::engine, ast_rtp_engine::ice, NULL, and rtp_ice_wrappers.

Referenced by add_ice_to_stream(), check_ice_support(), create_rtp(), jingle_add_google_candidates_to_transport(), jingle_add_ice_udp_candidates_to_transport(), jingle_enable_video(), jingle_interpret_google_transport(), jingle_interpret_ice_udp_transport(), jingle_new(), jingle_outgoing_hook(), jingle_request(), process_ice_attributes(), process_ice_auth_attrb(), and set_ice_components().

◆ ast_rtp_instance_get_incoming_source_address()

void ast_rtp_instance_get_incoming_source_address ( struct ast_rtp_instance instance,
struct ast_sockaddr address 
)

Get the incoming source address of the remote endpoint.

This returns the remote address the engine is sending RTP to. Usually this will be the same as the requested target address, however in the case where the engine "learns" the address (for instance, symmetric RTP enabled) this will then contain the learned address.

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

Definition at line 687 of file rtp_engine.c.

689{
690 ao2_lock(instance);
692 ao2_unlock(instance);
693}
struct ast_sockaddr incoming_source_address
Definition: rtp_engine.c:200

References ao2_lock, ao2_unlock, ast_sockaddr_copy(), and ast_rtp_instance::incoming_source_address.

◆ ast_rtp_instance_get_keepalive()

int ast_rtp_instance_get_keepalive ( struct ast_rtp_instance instance)

Get the RTP keepalive interval.

Parameters
instanceThe RTP instance
Returns
period Keepalive interval value

Example usage:

int interval = ast_rtp_instance_get_keepalive(instance);
int ast_rtp_instance_get_keepalive(struct ast_rtp_instance *instance)
Get the RTP keepalive interval.
Definition: rtp_engine.c:2834

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

Since
1.8

Definition at line 2834 of file rtp_engine.c.

2835{
2836 return instance->keepalive;
2837}

References ast_rtp_instance::keepalive.

Referenced by send_keepalive().

◆ ast_rtp_instance_get_last_rx()

time_t ast_rtp_instance_get_last_rx ( const struct ast_rtp_instance rtp)

Get the last RTP reception time.

Parameters
rtpThe instance from which to get the last reception time
Returns
The last RTP reception time

Definition at line 3940 of file rtp_engine.c.

3941{
3942 return rtp->last_rx;
3943}

References ast_rtp_instance::last_rx.

Referenced by rtp_check_timeout().

◆ ast_rtp_instance_get_last_tx()

time_t ast_rtp_instance_get_last_tx ( const struct ast_rtp_instance rtp)

Get the last RTP transmission time.

Parameters
rtpThe instance from which to get the last transmission time
Returns
The last RTP transmission time

Definition at line 3930 of file rtp_engine.c.

3931{
3932 return rtp->last_tx;
3933}

References ast_rtp_instance::last_tx.

Referenced by send_keepalive().

◆ ast_rtp_instance_get_local_address()

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:

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.
Definition: rtp_engine.c:665

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

Since
1.8

Definition at line 665 of file rtp_engine.c.

667{
668 ao2_lock(instance);
670 ao2_unlock(instance);
671}

References ao2_lock, ao2_unlock, ast_sockaddr_copy(), and ast_rtp_instance::local_address.

Referenced by ast_rtp_prop_set(), ast_rtp_remote_address_set(), channel_read_rtp(), configure_local_rtp(), create_outgoing_sdp_stream(), multicast_send_control_packet(), send_start_rtp(), test_init_rtp_instances(), unicast_rtp_request(), and unistim_set_rtp_peer().

◆ ast_rtp_instance_get_prop()

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
Returns
Current value of the property

Example usage:

int ast_rtp_instance_get_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property)
Get the value of an RTP instance property.
Definition: rtp_engine.c:738
@ AST_RTP_PROPERTY_NAT
Definition: rtp_engine.h:115

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

Since
1.8

Definition at line 738 of file rtp_engine.c.

739{
740 int prop;
741
742 ao2_lock(instance);
743 prop = instance->properties[property];
744 ao2_unlock(instance);
745
746 return prop;
747}
int properties[AST_RTP_PROPERTY_MAX]
Definition: rtp_engine.c:194

References ao2_lock, ao2_unlock, and ast_rtp_instance::properties.

Referenced by ast_rtcp_interpret(), ast_rtp_dtmf_compatible(), ast_rtp_read(), bridge_p2p_rtp_write(), process_dtmf_cisco(), process_dtmf_rfc2833(), rtp_raw_write(), and rtp_write_rtcp_psfb().

◆ ast_rtp_instance_get_quality()

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:

#define AST_MAX_USER_FIELD
Definition: channel.h:174
static int quality
Definition: codec_speex.c:62
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
@ AST_RTP_INSTANCE_STAT_FIELD_QUALITY
Definition: rtp_engine.h:170
char * ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size)
Retrieve quality statistics about an RTP instance.
Definition: rtp_engine.c:2579

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

Since
1.8

Definition at line 2579 of file rtp_engine.c.

2580{
2581 struct ast_rtp_instance_stats stats = { 0, };
2582 enum ast_rtp_instance_stat stat;
2583
2584 /* Determine what statistics we will need to retrieve based on field passed in */
2587 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
2589 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
2591 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
2593 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES) {
2595 } else {
2596 return NULL;
2597 }
2598
2599 /* Attempt to actually retrieve the statistics we need to generate the quality string */
2600 if (ast_rtp_instance_get_stats(instance, &stats, stat)) {
2601 return NULL;
2602 }
2603
2604 /* Now actually fill the buffer with the good information */
2606 snprintf(buf, size, "ssrc=%u;themssrc=%u;lp=%u;rxjitter=%f;rxcount=%u;"
2607 "txjitter=%f;txcount=%u;rlp=%u;rtt=%f;rxmes=%f;txmes=%f",
2608 stats.local_ssrc, stats.remote_ssrc, stats.rxploss, stats.rxjitter,
2609 stats.rxcount, stats.txjitter, stats.txcount, stats.txploss, stats.rtt,
2610 stats.rxmes, stats.txmes);
2611 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
2612 snprintf(buf, size, "minrxjitter=%010.6f;maxrxjitter=%010.6f;avgrxjitter=%010.6f;stdevrxjitter=%010.6f;mintxjitter=%010.6f;maxtxjitter=%010.6f;avgtxjitter=%010.6f;stdevtxjitter=%010.6f;",
2614 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
2615 snprintf(buf, size, " minrxlost=%010.6f; maxrxlost=%010.6f; avgrxlost=%010.6f; stdevrxlost=%010.6f; mintxlost=%010.6f; maxtxlost=%010.6f; avgtxlost=%010.6f; stdevtxlost=%010.6f;",
2617 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
2618 snprintf(buf, size, " minrtt=%010.6f; maxrtt=%010.6f; avgrtt=%010.6f; stdevrtt=%010.6f;", stats.minrtt, stats.maxrtt, stats.normdevrtt, stats.stdevrtt);
2619 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES) {
2620 snprintf(buf, size, " minrxmes=%010.6f; maxrxmes=%010.6f; avgrxmes=%010.6f; stdevrxmes=%010.6f; mintxmes=%010.6f; maxtxmes=%010.6f; avgtxmes=%010.6f; stdevtxmes=%010.6f;",
2621 stats.local_minmes, stats.local_maxmes,
2622 stats.local_normdevmes, stats.local_stdevmes,
2623 stats.remote_minmes, stats.remote_maxmes,
2624 stats.remote_normdevmes, stats.remote_stdevmes);
2625 }
2626
2627 return buf;
2628}
int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
Retrieve statistics about an RTP instance.
Definition: rtp_engine.c:2561
ast_rtp_instance_stat
Definition: rtp_engine.h:182
@ AST_RTP_INSTANCE_STAT_COMBINED_MES
Definition: rtp_engine.h:257
@ AST_RTP_INSTANCE_STAT_COMBINED_JITTER
Definition: rtp_engine.h:212
@ AST_RTP_INSTANCE_STAT_COMBINED_LOSS
Definition: rtp_engine.h:190
@ AST_RTP_INSTANCE_STAT_COMBINED_RTT
Definition: rtp_engine.h:234
@ AST_RTP_INSTANCE_STAT_ALL
Definition: rtp_engine.h:184

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_MES, 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_MES, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, buf, ast_rtp_instance_stats::local_maxjitter, ast_rtp_instance_stats::local_maxmes, ast_rtp_instance_stats::local_maxrxploss, ast_rtp_instance_stats::local_minjitter, ast_rtp_instance_stats::local_minmes, ast_rtp_instance_stats::local_minrxploss, ast_rtp_instance_stats::local_normdevjitter, ast_rtp_instance_stats::local_normdevmes, ast_rtp_instance_stats::local_normdevrxploss, ast_rtp_instance_stats::local_ssrc, ast_rtp_instance_stats::local_stdevjitter, ast_rtp_instance_stats::local_stdevmes, ast_rtp_instance_stats::local_stdevrxploss, ast_rtp_instance_stats::maxrtt, ast_rtp_instance_stats::minrtt, ast_rtp_instance_stats::normdevrtt, NULL, ast_rtp_instance_stats::remote_maxjitter, ast_rtp_instance_stats::remote_maxmes, ast_rtp_instance_stats::remote_maxrxploss, ast_rtp_instance_stats::remote_minjitter, ast_rtp_instance_stats::remote_minmes, ast_rtp_instance_stats::remote_minrxploss, ast_rtp_instance_stats::remote_normdevjitter, ast_rtp_instance_stats::remote_normdevmes, ast_rtp_instance_stats::remote_normdevrxploss, ast_rtp_instance_stats::remote_ssrc, ast_rtp_instance_stats::remote_stdevjitter, ast_rtp_instance_stats::remote_stdevmes, 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::rxmes, ast_rtp_instance_stats::rxploss, ast_rtp_instance_stats::stdevrtt, ast_rtp_instance_stats::txcount, ast_rtp_instance_stats::txjitter, ast_rtp_instance_stats::txmes, and ast_rtp_instance_stats::txploss.

Referenced by ast_rtp_instance_destroy(), ast_rtp_instance_set_stats_vars(), and channel_read_rtcp().

◆ ast_rtp_instance_get_requested_target_address()

void ast_rtp_instance_get_requested_target_address ( struct ast_rtp_instance instance,
struct ast_sockaddr address 
)

Get the requested target address of the remote endpoint.

This returns the explicitly set address of a remote endpoint. Meaning this won't change unless specifically told to change. In most cases this should be the same as the incoming source address, except in cases where the engine "learns" the address in which case this and the incoming source address might differ.

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

Definition at line 695 of file rtp_engine.c.

697{
698 ao2_lock(instance);
700 ao2_unlock(instance);
701}