Asterisk - The Open Source Telephony Project GIT-master-7988d11
Loading...
Searching...
No Matches
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.
 
#define SET_STATS_VAR_HELPER(var_prefix, field)
 

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.
 
unsigned int ast_rtp_codecs_get_framing (struct ast_rtp_codecs *codecs)
 Get the framing used for a set of codecs.
 
struct ast_rtp_payload_typeast_rtp_codecs_get_payload (struct ast_rtp_codecs *codecs, int payload)
 Retrieve rx payload mapped information by payload type.
 
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.
 
int ast_rtp_codecs_get_preferred_dtmf_format_pt (struct ast_rtp_codecs *codecs)
 Retrieve rx preferred dtmf format payload type.
 
int ast_rtp_codecs_get_preferred_dtmf_format_rate (struct ast_rtp_codecs *codecs)
 Retrieve rx preferred dtmf format sample rate.
 
struct ast_formatast_rtp_codecs_get_preferred_format (struct ast_rtp_codecs *codecs)
 Retrieve rx preferred format.
 
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.
 
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.
 
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.
 
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.
 
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.
 
void ast_rtp_codecs_payload_formats (struct ast_rtp_codecs *codecs, struct ast_format_cap *astformats, int *nonastformats)
 Retrieve all formats that were found.
 
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.
 
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.
 
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.
 
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.
 
void ast_rtp_codecs_payloads_copy (struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
 Copy payload information from one RTP instance to another.
 
void ast_rtp_codecs_payloads_destroy (struct ast_rtp_codecs *codecs)
 Destroy the contents of an RTP codecs structure (but not the structure itself)
 
int ast_rtp_codecs_payloads_initialize (struct ast_rtp_codecs *codecs)
 Initialize an RTP codecs structure.
 
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.
 
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.
 
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.
 
void ast_rtp_codecs_payloads_unset (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
 Remove tx payload type mapped information.
 
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.
 
void ast_rtp_codecs_set_framing (struct ast_rtp_codecs *codecs, unsigned int framing)
 Set the framing used for a set of codecs.
 
int ast_rtp_codecs_set_preferred_dtmf_format (struct ast_rtp_codecs *codecs, int pt, int rate)
 Set the preferred dtmf format pt and sample rate.
 
int ast_rtp_codecs_set_preferred_format (struct ast_rtp_codecs *codecs, struct ast_format *format)
 Set the preferred format.
 
struct ast_jsonast_rtp_convert_stats_json (const struct ast_rtp_instance_stats *stats)
 Convert given stat instance into json format.
 
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.
 
void ast_rtp_dtls_cfg_free (struct ast_rtp_dtls_cfg *dtls_cfg)
 Free contents of a DTLS configuration structure.
 
int ast_rtp_dtls_cfg_parse (struct ast_rtp_dtls_cfg *dtls_cfg, const char *name, const char *value)
 Parse DTLS related configuration options.
 
int ast_rtp_dtls_cfg_validate (struct ast_rtp_dtls_cfg *dtls_cfg)
 Validates DTLS related configuration options.
 
struct ast_rtp_payload_typeast_rtp_engine_alloc_payload_type (void)
 Allocation routine for ast_rtp_payload_type.
 
int ast_rtp_engine_init (void)
 initializes the rtp engine arrays
 
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.
 
int ast_rtp_engine_register2 (struct ast_rtp_engine *engine, struct ast_module *module)
 Register an RTP engine.
 
int ast_rtp_engine_register_srtp (struct ast_srtp_res *srtp_res, struct ast_srtp_policy_res *policy_res)
 
int ast_rtp_engine_srtp_is_registered (void)
 
int ast_rtp_engine_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.
 
int ast_rtp_engine_unregister (struct ast_rtp_engine *engine)
 Unregister an RTP engine.
 
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.
 
int ast_rtp_glue_register2 (struct ast_rtp_glue *glue, struct ast_module *module)
 Register RTP glue.
 
int ast_rtp_glue_unregister (struct ast_rtp_glue *glue)
 Unregister RTP glue.
 
int ast_rtp_instance_activate (struct ast_rtp_instance *instance)
 Indicate to the RTP engine that packets are now expected to be sent/received on the RTP instance.
 
int ast_rtp_instance_add_srtp_policy (struct ast_rtp_instance *instance, struct ast_srtp_policy *remote_policy, struct ast_srtp_policy *local_policy, int rtcp)
 Add or replace the SRTP policies for the given RTP instance.
 
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.
 
int ast_rtp_instance_bundle (struct ast_rtp_instance *child, struct ast_rtp_instance *parent)
 Request that an RTP instance be bundled with another.
 
void ast_rtp_instance_change_source (struct ast_rtp_instance *instance)
 Indicate a new source of audio has dropped in and the ssrc should change.
 
int ast_rtp_instance_destroy (struct ast_rtp_instance *instance)
 Destroy an RTP instance.
 
int ast_rtp_instance_dtmf_begin (struct ast_rtp_instance *instance, char digit)
 Begin sending a DTMF digit.
 
int ast_rtp_instance_dtmf_end (struct ast_rtp_instance *instance, char digit)
 Stop sending a DTMF digit.
 
int ast_rtp_instance_dtmf_end_with_duration (struct ast_rtp_instance *instance, char digit, unsigned int duration)
 
enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get (struct ast_rtp_instance *instance)
 Get the DTMF mode of an RTP instance.
 
int ast_rtp_instance_dtmf_mode_set (struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode)
 Set the DTMF mode that should be used.
 
int ast_rtp_instance_early_bridge (struct ast_channel *c0, struct ast_channel *c1)
 Early bridge two channels that use RTP instances.
 
void ast_rtp_instance_early_bridge_make_compatible (struct ast_channel *c_dst, struct ast_channel *c_src)
 Make two channels compatible for early bridging.
 
void ast_rtp_instance_extmap_clear (struct ast_rtp_instance *instance)
 Clear negotiated RTP extension information.
 
size_t ast_rtp_instance_extmap_count (struct ast_rtp_instance *instance)
 Get the number of known unique identifiers.
 
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.
 
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.
 
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.
 
int ast_rtp_instance_extmap_get_id (struct ast_rtp_instance *instance, enum ast_rtp_extension extension)
 Retrieve the id for an RTP extension.
 
const char * ast_rtp_instance_extmap_get_uri (struct ast_rtp_instance *instance, int id)
 Retrieve the URI for an RTP extension id.
 
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.
 
int ast_rtp_instance_fd (struct ast_rtp_instance *instance, int rtcp)
 Get the file descriptor for an RTP session (or RTCP)
 
struct ast_rtp_glueast_rtp_instance_get_active_glue (struct ast_rtp_instance *instance)
 Get the RTP glue in use on an RTP instance.
 
int ast_rtp_instance_get_and_cmp_local_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the address of the local endpoint that we are sending RTP to, comparing its address to another.
 
int ast_rtp_instance_get_and_cmp_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.
 
struct ast_rtp_instanceast_rtp_instance_get_bridged (struct ast_rtp_instance *instance)
 Get the other RTP instance that an instance is bridged to.
 
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.
 
const char * ast_rtp_instance_get_cname (struct ast_rtp_instance *rtp)
 Retrieve the CNAME used in RTCP SDES items.
 
struct ast_rtp_codecsast_rtp_instance_get_codecs (struct ast_rtp_instance *instance)
 Get the codecs structure of an RTP instance.
 
void * ast_rtp_instance_get_data (struct ast_rtp_instance *instance)
 Get the data portion of an RTP instance.
 
struct ast_rtp_engine_dtlsast_rtp_instance_get_dtls (struct ast_rtp_instance *instance)
 Obtain a pointer to the DTLS support present on an RTP instance.
 
struct ast_rtp_engineast_rtp_instance_get_engine (struct ast_rtp_instance *instance)
 Get the RTP engine in use on an RTP instance.
 
void * ast_rtp_instance_get_extended_prop (struct ast_rtp_instance *instance, int property)
 Get the value of an RTP instance extended property.
 
struct ast_rtp_glueast_rtp_instance_get_glue (const char *type)
 Get the RTP glue that binds a channel to the RTP engine.
 
int ast_rtp_instance_get_hold_timeout (struct ast_rtp_instance *instance)
 Get the RTP timeout value for when an RTP instance is on hold.
 
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.
 
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.
 
int ast_rtp_instance_get_keepalive (struct ast_rtp_instance *instance)
 Get the RTP keepalive interval.
 
time_t ast_rtp_instance_get_last_rx (const struct ast_rtp_instance *rtp)
 Get the last RTP reception time.
 
time_t ast_rtp_instance_get_last_tx (const struct ast_rtp_instance *rtp)
 Get the last RTP transmission time.
 
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.
 
unsigned int ast_rtp_instance_get_port_end (struct ast_rtp_instance *instance)
 Get the per-instance RTP port range end.
 
unsigned int ast_rtp_instance_get_port_start (struct ast_rtp_instance *instance)
 Get the per-instance RTP port range start.
 
int ast_rtp_instance_get_prop (struct ast_rtp_instance *instance, enum ast_rtp_property property)
 Get the value of an RTP instance property.
 
char * ast_rtp_instance_get_quality (struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size)
 Retrieve quality statistics about an RTP instance.
 
void ast_rtp_instance_get_requested_target_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the requested target address of the remote endpoint.
 
struct ast_srtpast_rtp_instance_get_srtp (struct ast_rtp_instance *instance, int rtcp)
 Obtain the SRTP instance associated with an RTP instance.
 
unsigned int ast_rtp_instance_get_ssrc (struct ast_rtp_instance *rtp)
 Retrieve the local SSRC value that we will be using.
 
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.
 
struct ast_jsonast_rtp_instance_get_stats_all_json (struct ast_rtp_instance *instance)
 Retrieve statistics about an RTP instance in json format.
 
int ast_rtp_instance_get_timeout (struct ast_rtp_instance *instance)
 Get the RTP timeout value.
 
int ast_rtp_instance_make_compatible (struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_channel *peer)
 Request that the underlying RTP engine make two RTP instances compatible with eachother.
 
struct ast_rtp_instanceast_rtp_instance_new (const char *engine_name, struct ast_sched_context *sched, const struct ast_sockaddr *sa, void *data)
 Create a new RTP instance.
 
struct ast_rtp_instanceast_rtp_instance_new_with_options (const char *engine_name, struct ast_sched_context *sched, const struct ast_sockaddr *sa, void *data, const struct ast_rtp_instance_options *options)
 Create a new RTP instance with additional options.
 
struct ast_frameast_rtp_instance_read (struct ast_rtp_instance *instance, int rtcp)
 Receive a frame over RTP.
 
int ast_rtp_instance_sendcng (struct ast_rtp_instance *instance, int level)
 Send a comfort noise packet to the RTP instance.
 
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.
 
void ast_rtp_instance_set_channel_id (struct ast_rtp_instance *instance, const char *uniqueid)
 Set the channel that owns this RTP instance.
 
void ast_rtp_instance_set_data (struct ast_rtp_instance *instance, void *data)
 Set the data portion of an RTP instance.
 
void ast_rtp_instance_set_extended_prop (struct ast_rtp_instance *instance, int property, void *value)
 Set the value of an RTP instance extended property.
 
void ast_rtp_instance_set_hold_timeout (struct ast_rtp_instance *instance, int timeout)
 Set the RTP timeout value for when the instance is on hold.
 
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.
 
void ast_rtp_instance_set_keepalive (struct ast_rtp_instance *instance, int interval)
 Set the RTP keepalive interval.
 
void ast_rtp_instance_set_last_rx (struct ast_rtp_instance *rtp, time_t time)
 Set the last RTP reception time.
 
void ast_rtp_instance_set_last_tx (struct ast_rtp_instance *rtp, time_t time)
 Set the last RTP transmission time.
 
int ast_rtp_instance_set_local_address (struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
 Set the address that we are expecting to receive RTP on.
 
void ast_rtp_instance_set_prop (struct ast_rtp_instance *instance, enum ast_rtp_property property, int value)
 Set the value of an RTP instance property.
 
int ast_rtp_instance_set_qos (struct ast_rtp_instance *instance, int tos, int cos, const char *desc)
 Set QoS parameters on an RTP session.
 
int ast_rtp_instance_set_read_format (struct ast_rtp_instance *instance, struct ast_format *format)
 Request that the underlying RTP engine provide audio frames in a specific format.
 
void ast_rtp_instance_set_remote_ssrc (struct ast_rtp_instance *rtp, unsigned int ssrc)
 Set the remote SSRC for an RTP instance.
 
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.
 
void ast_rtp_instance_set_stats_vars (struct ast_channel *chan, struct ast_rtp_instance *instance)
 Set standard statistics from an RTP instance on a channel.
 
void ast_rtp_instance_set_stream_num (struct ast_rtp_instance *rtp, int stream_num)
 Set the stream number for an RTP instance.
 
void ast_rtp_instance_set_timeout (struct ast_rtp_instance *instance, int timeout)
 Set the RTP timeout value.
 
int ast_rtp_instance_set_write_format (struct ast_rtp_instance *instance, struct ast_format *format)
 Tell underlying RTP engine that audio frames will be provided in a specific format.
 
void ast_rtp_instance_stop (struct ast_rtp_instance *instance)
 Stop an RTP instance.
 
void ast_rtp_instance_stun_request (struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username)
 Request that the underlying RTP engine send a STUN BIND request.
 
void ast_rtp_instance_update_source (struct ast_rtp_instance *instance)
 Indicate that the RTP marker bit should be set on an RTP stream.
 
int ast_rtp_instance_write (struct ast_rtp_instance *instance, struct ast_frame *frame)
 Send a frame out over RTP.
 
char * ast_rtp_lookup_mime_multiple2 (struct ast_str *buf, 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.
 
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.
 
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.
 
int ast_rtp_payload_mapping_tx_is_present (struct ast_rtp_codecs *codecs, const struct ast_rtp_payload_type *to_match)
 Determine if a type of payload is already present in mappings.
 
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.
 
int ast_rtp_red_buffer (struct ast_rtp_instance *instance, struct ast_frame *frame)
 Buffer a frame in an RTP instance for RED.
 
int ast_rtp_red_init (struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations)
 Initialize RED support on an RTP instance.
 
struct ast_rtp_rtcp_reportast_rtp_rtcp_report_alloc (unsigned int report_blocks)
 Allocate an ao2 ref counted instance of ast_rtp_rtcp_report.
 
struct stasis_topicast_rtp_topic (void)
 Stasis Message Bus API topic for RTP and RTCP related messages
 
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.
 
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.
 
 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.
 

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 = AST_RWLIST_HEAD_INIT_VALUE
 
static struct glues glues = AST_RWLIST_HEAD_INIT_VALUE
 
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.
 
static struct ast_rtp_engine_ice rtp_ice_wrappers
 
static struct stasis_topicrtp_topic
 Stasis Message Bus API topic for RTP related messages
 
static struct ast_rtp_payload_typestatic_RTP_PT [AST_RTP_MAX_PT]
 Mapping between Asterisk codecs and rtp payload types.
 
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 256 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 297 of file rtp_engine.c.

297 { \
298 struct ast_json *j_tmp = obj; \
299 if (j_tmp) { \
300 ast_json_object_set(target, name, j_tmp); \
301 } \
302})
static const char name[]
Definition format_mp3.c:68
Abstract JSON element (object, array, string, int, ...).

◆ SET_STATS_VAR_HELPER

#define SET_STATS_VAR_HELPER (   var_prefix,
  field 
)

Definition at line 2730 of file rtp_engine.c.

2731 { \
2732 value = ast_rtp_instance_get_quality(instance, field, quality_buf, sizeof(quality_buf)); \
2733 if (value) { \
2734 if (!chanvars || ast_strlen_zero(ast_var_find(chanvars, var_prefix))) { \
2735 pbx_builtin_setvar_helper(chan, var_prefix, value); \
2736 chanchanges++; \
2737 } \
2738 if (bridge) { \
2739 if (!bridgevars || ast_strlen_zero(ast_var_find(bridgevars, var_prefix "BRIDGED"))) { \
2740 pbx_builtin_setvar_helper(bridge, var_prefix "BRIDGED", value); \
2741 bridgechanges++; \
2742 } \
2743 } \
2744 } \
2745})
char * ast_var_find(const struct varshead *head, const char *name)
Definition chanvars.c:85
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.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition strings.h:65
int value
Definition syslog.c:37

Function Documentation

◆ add_static_payload()

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

Definition at line 3438 of file rtp_engine.c.

3439{
3440 struct ast_rtp_payload_type *type;
3441
3442 /*
3443 * ARRAY_LEN's result is cast to an int so 'map' is not autocast to a size_t,
3444 * which if negative would cause an assertion.
3445 */
3447
3448 if (ast_option_rtpusedynamic && payload < 0) {
3449 /*
3450 * We're going to build dynamic payloads dynamically. An RTP code is
3451 * required otherwise one will be dynamically allocated per instance.
3452 */
3453 return;
3454 }
3455
3456 /*
3457 * Either the given payload is truly a static type, or Asterisk is
3458 * globally storing the dynamic payloads in the static_RTP_PT object.
3459 */
3461
3462 if (payload < 0) {
3463 /*
3464 * This is a dynamic payload that will be stored globally,
3465 * so find the next available empty slot.
3466 */
3468 if (payload < 0) {
3469 ast_log(LOG_WARNING, "No dynamic RTP payload type values available "
3470 "for %s - %d!\n", format ? ast_format_get_name(format) : "", rtp_code);
3472 return;
3473 }
3474 }
3475
3477 if (type) {
3480 }
3482}
#define ast_log
Definition astobj2.c:42
#define ao2_cleanup(obj)
Definition astobj2.h:1934
static const char type[]
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:89
#define LOG_WARNING
#define ast_rwlock_wrlock(a)
Definition lock.h:243
#define ast_rwlock_unlock(a)
Definition lock.h:241
#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:283
static ast_rwlock_t static_RTP_PT_lock
Definition rtp_engine.c:284
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:315
static int find_unused_payload(const struct ast_rtp_codecs *codecs)
struct ast_format * format
Definition rtp_engine.h:306
#define ast_assert(a)
Definition utils.h:779
#define ARRAY_LEN(a)
Definition utils.h:706

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

3827{
3829}
static uintmax_t debug_category_dtls_id

References debug_category_dtls_id.

◆ ast_debug_category_dtls_packet_id()

uintmax_t ast_debug_category_dtls_packet_id ( void  )

Definition at line 3833 of file rtp_engine.c.

3834{
3836}
static uintmax_t debug_category_dtls_packet_id

References debug_category_dtls_packet_id.

◆ ast_debug_category_ice_id()

uintmax_t ast_debug_category_ice_id ( void  )

Definition at line 3840 of file rtp_engine.c.

3841{
3842 return debug_category_ice_id;
3843}
static uintmax_t debug_category_ice_id

References debug_category_ice_id.

◆ ast_debug_category_rtcp_id()

uintmax_t ast_debug_category_rtcp_id ( void  )

Definition at line 3812 of file rtp_engine.c.

3813{
3815}
static uintmax_t debug_category_rtcp_id

References debug_category_rtcp_id.

◆ ast_debug_category_rtcp_packet_id()

uintmax_t ast_debug_category_rtcp_packet_id ( void  )

Definition at line 3819 of file rtp_engine.c.

3820{
3822}
static uintmax_t debug_category_rtcp_packet_id

References debug_category_rtcp_packet_id.

◆ ast_debug_category_rtp_id()

uintmax_t ast_debug_category_rtp_id ( void  )

Definition at line 3798 of file rtp_engine.c.

3799{
3800 return debug_category_rtp_id;
3801}
static uintmax_t debug_category_rtp_id

References debug_category_rtp_id.

◆ ast_debug_category_rtp_packet_id()

uintmax_t ast_debug_category_rtp_packet_id ( void  )

Definition at line 3805 of file rtp_engine.c.

3806{
3808}
static uintmax_t debug_category_rtp_packet_id

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.

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

Definition at line 2190 of file rtp_engine.c.

2191{
2192 struct ast_rtp_payload_type *type;
2193 int res = -1;
2194
2195 ast_rwlock_rdlock(&codecs->codecs_lock);
2196 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
2197 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, payload);
2198 if (type) {
2199 res = payload;
2200 }
2201 }
2202 ast_rwlock_unlock(&codecs->codecs_lock);
2203
2204 return res;
2205}
#define ast_rwlock_rdlock(a)
Definition lock.h:242
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition vector.h:620
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition vector.h:691

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

1712{
1713 unsigned int framing;
1714
1715 ast_rwlock_rdlock(&codecs->codecs_lock);
1716 framing = codecs->framing;
1717 ast_rwlock_unlock(&codecs->codecs_lock);
1718
1719 return framing;
1720}

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.

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

Definition at line 1577 of file rtp_engine.c.

1578{
1579 struct ast_rtp_payload_type *type = NULL;
1580
1581 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
1582 return NULL;
1583 }
1584
1585 ast_rwlock_rdlock(&codecs->codecs_lock);
1586 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_rx)) {
1587 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, payload);
1588 ao2_bump(type);
1589 }
1590 ast_rwlock_unlock(&codecs->codecs_lock);
1591
1592 if (!type && payload <= AST_RTP_PT_LAST_STATIC) {
1596 }
1597
1598 return type;
1599}
#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_dtmf_begin(), 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 1679 of file rtp_engine.c.

1680{
1681 struct ast_rtp_payload_type *type;
1682 struct ast_format *format = NULL;
1683
1684 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
1685 return NULL;
1686 }
1687
1688 ast_rwlock_rdlock(&codecs->codecs_lock);
1689 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1690 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, payload);
1691 if (type && type->asterisk_format) {
1692 format = ao2_bump(type->format);
1693 }
1694 }
1695 ast_rwlock_unlock(&codecs->codecs_lock);
1696
1697 return format;
1698}
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_dtmf_format_pt()

int ast_rtp_codecs_get_preferred_dtmf_format_pt ( struct ast_rtp_codecs codecs)

Retrieve rx preferred dtmf format payload type.

Parameters
codecsCodecs structure to look in
Returns
Payload type of preferred dtmf format.
Return values
-1if not set.

Example usage:

int payload;
int ast_rtp_codecs_get_preferred_dtmf_format_pt(struct ast_rtp_codecs *codecs)
Retrieve rx preferred dtmf format payload type.

This looks up the preferred dtmf format pt on the codec

Definition at line 1618 of file rtp_engine.c.

1619{
1620 int pt = -1;
1621 ast_rwlock_rdlock(&codecs->codecs_lock);
1622 pt = codecs->preferred_dtmf_pt;
1623 ast_rwlock_unlock(&codecs->codecs_lock);
1624 return pt;
1625}

References ast_rwlock_rdlock, ast_rwlock_unlock, and codecs.

Referenced by ast_rtp_dtmf_begin().

◆ ast_rtp_codecs_get_preferred_dtmf_format_rate()

int ast_rtp_codecs_get_preferred_dtmf_format_rate ( struct ast_rtp_codecs codecs)

Retrieve rx preferred dtmf format sample rate.

Parameters
codecsCodecs structure to look in
Returns
Sample rate of preferred dtmf format.
Return values
-1if not set.

Example usage:

int sample_rate;
int ast_rtp_codecs_get_preferred_dtmf_format_rate(struct ast_rtp_codecs *codecs)
Retrieve rx preferred dtmf format sample rate.

This looks up the preferred dtmf format sample rate on the codec

Definition at line 1627 of file rtp_engine.c.

1628{
1629 int rate = -1;
1630 ast_rwlock_rdlock(&codecs->codecs_lock);
1631 rate = codecs->preferred_dtmf_rate;
1632 ast_rwlock_unlock(&codecs->codecs_lock);
1633 return rate;
1634}

References ast_rwlock_rdlock, ast_rwlock_unlock, and codecs.

Referenced by ast_rtp_dtmf_begin().

◆ 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.

This looks up the preferred format on the codec

Definition at line 1601 of file rtp_engine.c.

1602{
1603 struct ast_format *format;
1604 ast_rwlock_rdlock(&codecs->codecs_lock);
1605 format = ao2_bump(codecs->preferred_format);
1606 ast_rwlock_unlock(&codecs->codecs_lock);
1607 return format;
1608}

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

1559{
1560 enum ast_media_type stream_type = AST_MEDIA_TYPE_UNKNOWN;
1561 int payload;
1562 struct ast_rtp_payload_type *type;
1563
1564 ast_rwlock_rdlock(&codecs->codecs_lock);
1565 for (payload = 0; payload < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++payload) {
1566 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, payload);
1567 if (type && type->asterisk_format) {
1568 stream_type = ast_format_get_type(type->format);
1569 break;
1570 }
1571 }
1572 ast_rwlock_unlock(&codecs->codecs_lock);
1573
1574 return stream_type;
1575}
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.
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.

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

Since
1.8

Definition at line 2048 of file rtp_engine.c.

2049{
2050 return ast_rtp_codecs_payload_code_sample_rate(codecs, asterisk_format, format, code, 0);
2051}
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 ...

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:294
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 ...

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

2054{
2055 struct ast_rtp_payload_type *type;
2056 int idx;
2057 int payload = -1;
2058
2060 if (!asterisk_format) {
2061 ast_rwlock_rdlock(&codecs->codecs_lock);
2062 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
2063 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
2064 if (!type) {
2065 continue;
2066 }
2067
2068 if (!type->asterisk_format
2069 && type->primary_mapping
2070 && type->rtp_code == code
2071 && (sample_rate == 0 || type->sample_rate == sample_rate)) {
2072 payload = idx;
2073 break;
2074 }
2075 }
2076 ast_rwlock_unlock(&codecs->codecs_lock);
2077 } else if (format) {
2078 ast_rwlock_rdlock(&codecs->codecs_lock);
2079 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
2080 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
2081 if (!type) {
2082 continue;
2083 }
2084
2085 if (type->asterisk_format
2086 && type->primary_mapping
2088 payload = idx;
2089 break;
2090 }
2091 }
2092 ast_rwlock_unlock(&codecs->codecs_lock);
2093 }
2094
2095 if (payload < 0) {
2097 code, 0, sample_rate);
2098 }
2100
2101 return payload;
2102}
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)
unsigned int sample_rate
Definition rtp_engine.h:318

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

2186{
2187 return ast_rtp_codecs_payload_code_tx_sample_rate(codecs, asterisk_format, format, code, 0);
2188}
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.

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_dtmf_begin(), ast_rtp_sendcng(), ast_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 2114 of file rtp_engine.c.

2115{
2116 struct ast_rtp_payload_type *type;
2117 int idx;
2118 int payload = -1;
2119
2120 if (!asterisk_format) {
2121 ast_rwlock_rdlock(&codecs->codecs_lock);
2122 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
2123 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
2124 if (!type) {
2125 continue;
2126 }
2127
2128 if (!type->asterisk_format
2129 && type->rtp_code == code
2130 /* Multiple DTMF types share an rtp code but have different sample rates. To ensure we have the right
2131 type we therefore need the sample rate as well as the format and code. Other types have a fixed
2132 sample rate so this is not needed. For those pass in a sample rate of 0 or use ast_rtp_codecs_payload_code_tx. */
2133 && (sample_rate == 0 || type->sample_rate == sample_rate)) {
2134 payload = idx;
2135 break;
2136 }
2137 }
2138 ast_rwlock_unlock(&codecs->codecs_lock);
2139 } else if (format) {
2140 ast_rwlock_rdlock(&codecs->codecs_lock);
2141 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
2142 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
2143 if (!type) {
2144 continue;
2145 }
2146
2147 if (type->asterisk_format
2149 payload = idx;
2150 break;
2151 }
2152 }
2153 ast_rwlock_unlock(&codecs->codecs_lock);
2154 }
2155
2156 if (payload < 0) {
2160
2161 /*
2162 * Comfort noise is NOT used as an SDP negotiated format within Asterisk;
2163 * instead, it is used when it is not negotiated. This special case allows
2164 * its payload to be returned when not negotiated, allowing keep alive to
2165 * function as expected.
2166 */
2167 if (payload == 13 && code == AST_RTP_CN) {
2168 return payload;
2169 }
2170
2171 ast_rwlock_rdlock(&codecs->codecs_lock);
2172 if (payload >= 0 && payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)){
2173 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, payload);
2174 if (!type || (sample_rate != 0 && type->sample_rate != sample_rate)) {
2175 /* Don't use the type if we can't find it or it doesn't match the supplied sample_rate */
2176 payload = -1;
2177 }
2178 }
2179 ast_rwlock_unlock(&codecs->codecs_lock);
2180 }
2181
2182 return payload;
2183}
static int find_static_payload_type(int asterisk_format, const struct ast_format *format, int code)
#define AST_RTP_CN
Definition rtp_engine.h:296

References ast_format_cmp(), AST_FORMAT_CMP_EQUAL, AST_RTP_CN, 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(), ast_rtp_dtmf_begin(), and bridge_p2p_rtp_write().

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

1723{
1724 int idx;
1725
1727 *nonastformats = 0;
1728
1729 ast_rwlock_rdlock(&codecs->codecs_lock);
1730
1731 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
1732 struct ast_rtp_payload_type *type;
1733
1734 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
1735 if (!type) {
1736 continue;
1737 }
1738
1739 if (type->asterisk_format) {
1740 ast_format_cap_append(astformats, type->format, 0);
1741 } else {
1742 *nonastformats |= type->rtp_code;
1743 }
1744 }
1745 if (codecs->framing) {
1746 ast_format_cap_set_framing(astformats, codecs->framing);
1747 }
1748
1749 ast_rwlock_unlock(&codecs->codecs_lock);
1750}
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 1645 of file rtp_engine.c.

1646{
1647 struct ast_rtp_payload_type *type;
1648
1649 if (payload < 0 || payload >= AST_RTP_MAX_PT || !format) {
1650 return -1;
1651 }
1652
1654 if (!type) {
1655 return -1;
1656 }
1657 ao2_ref(format, +1);
1658 type->format = format;
1659 type->asterisk_format = 1;
1660 type->payload = payload;
1661 type->primary_mapping = 1;
1662
1663 ast_rwlock_wrlock(&codecs->codecs_lock);
1665 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1666 ao2_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, payload));
1667 }
1668 if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, type)) {
1669 ao2_ref(type, -1);
1670 }
1671 } else {
1672 ao2_ref(type, -1);
1673 }
1674 ast_rwlock_unlock(&codecs->codecs_lock);
1675
1676 return 0;
1677}
#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:335
static int payload_mapping_tx_is_present(const struct ast_rtp_codecs *codecs, const struct ast_rtp_payload_type *to_match)
#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:295

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

2105{
2106 return rtp_codecs_assign_payload_code_rx(codecs, 1, format, code, 1, 0);
2107}

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

2110{
2111 return rtp_codecs_assign_payload_code_rx(codecs, 1, format, code, 0, sample_rate);
2112}

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.

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

Since
1.8

Definition at line 1048 of file rtp_engine.c.

1049{
1052
1053 if (instance && instance->engine && instance->engine->payload_set) {
1054 int i;
1055
1056 ao2_lock(instance);
1057 for (i = 0; i < AST_RTP_MAX_PT; i++) {
1058 instance->engine->payload_set(instance, i, 0, NULL, 0);
1059 }
1060 ao2_unlock(instance);
1061 }
1062}
#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)
int ast_rtp_codecs_payloads_initialize(struct ast_rtp_codecs *codecs)
Initialize an RTP codecs structure.
void(* payload_set)(struct ast_rtp_instance *instance, int payload, int asterisk_format, struct ast_format *format, int code)
Definition rtp_engine.h:694
struct ast_rtp_engine * engine
Definition rtp_engine.c:196

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.

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

Since
1.8

Definition at line 1302 of file rtp_engine.c.

1303{
1304 int idx;
1305 struct ast_rtp_payload_type *type;
1306
1308
1309 /* Deadlock avoidance because of held write lock. */
1310 while (ast_rwlock_tryrdlock(&src->codecs_lock)) {
1312 sched_yield();
1314 }
1315
1316 /*
1317 * This represents a completely new mapping of what the remote party is
1318 * expecting for payloads, so we clear out the entire tx payload mapping
1319 * vector and replace it.
1320 */
1321 for (idx = 0; idx < AST_VECTOR_SIZE(&dest->payload_mapping_tx); ++idx) {
1322 type = AST_VECTOR_GET(&dest->payload_mapping_tx, idx);
1323 ao2_t_cleanup(type, "destroying ast_rtp_codec tx mapping");
1325 }
1326
1327 rtp_codecs_payloads_copy_rx(src, dest, instance);
1328 rtp_codecs_payloads_copy_tx(src, dest, instance);
1329 dest->framing = src->framing;
1333
1336}
#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:244
static void rtp_codecs_payloads_copy_tx(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
static void rtp_codecs_payloads_copy_rx(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
ast_rwlock_t codecs_lock
Definition rtp_engine.h:758
int preferred_dtmf_rate
Definition rtp_engine.h:768
struct ast_rtp_codecs::@293 payload_mapping_tx
struct ast_format * preferred_format
Definition rtp_engine.h:766
unsigned int framing
Definition rtp_engine.h:764

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_dtmf_pt, ast_rtp_codecs::preferred_dtmf_rate, 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)
Since
11

Definition at line 1025 of file rtp_engine.c.

1026{
1027 int idx;
1028 struct ast_rtp_payload_type *type;
1029
1030 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
1031 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
1032 ao2_t_cleanup(type, "destroying ast_rtp_codec rx mapping");
1033 }
1034 AST_VECTOR_FREE(&codecs->payload_mapping_rx);
1035
1036 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
1037 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
1038 ao2_t_cleanup(type, "destroying ast_rtp_codec tx mapping");
1039 }
1040 AST_VECTOR_FREE(&codecs->payload_mapping_tx);
1041
1042 ao2_t_cleanup(codecs->preferred_format, "destroying ast_rtp_codec preferred format");
1043 codecs->preferred_format = NULL;
1044
1045 ast_rwlock_destroy(&codecs->codecs_lock);
1046}
#define ast_rwlock_destroy(rwlock)
Definition lock.h:240
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition vector.h:185

References ao2_t_cleanup, ast_rwlock_destroy, AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_SIZE, codecs, NULL, 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.
Since
11

Definition at line 1009 of file rtp_engine.c.

1010{
1011 int res;
1012
1013 codecs->framing = 0;
1014 ast_rwlock_init(&codecs->codecs_lock);
1015 res = AST_VECTOR_INIT(&codecs->payload_mapping_rx, AST_RTP_MAX_PT);
1016 res |= AST_VECTOR_INIT(&codecs->payload_mapping_tx, AST_RTP_MAX_PT);
1017 if (res) {
1018 AST_VECTOR_FREE(&codecs->payload_mapping_rx);
1019 AST_VECTOR_FREE(&codecs->payload_mapping_tx);
1020 }
1021
1022 return res;
1023}
#define ast_rwlock_init(rwlock)
wrapper for rwlock with tracking enabled
Definition lock.h:231
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition vector.h:124

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_with_options(), 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.

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

Since
1.8

Definition at line 1385 of file rtp_engine.c.

1386{
1388
1389 if (payload < 0 || payload >= AST_RTP_MAX_PT || payload > AST_RTP_PT_LAST_STATIC) {
1390 return;
1391 }
1392
1396 if (!new_type) {
1397 ast_debug(1, "Don't have a default tx payload type %d format for m type on %p\n",
1398 payload, codecs);
1399 return;
1400 }
1401
1402 ast_debug(1, "Setting tx payload type %d based on m type on %p\n",
1403 payload, codecs);
1404
1405 ast_rwlock_wrlock(&codecs->codecs_lock);
1406
1407 if (!payload_mapping_tx_is_present(codecs, new_type)) {
1408 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1409 ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, payload),
1410 "cleaning up replaced tx payload type");
1411 }
1412
1413 if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, new_type)) {
1414 ao2_ref(new_type, -1);
1415 } else if (instance && instance->engine && instance->engine->payload_set) {
1416 ao2_lock(instance);
1417 instance->engine->payload_set(instance, payload, new_type->asterisk_format, new_type->format, new_type->rtp_code);
1418 ao2_unlock(instance);
1419 }
1420 } else {
1421 ao2_ref(new_type, -1);
1422 }
1423
1424 ast_rwlock_unlock(&codecs->codecs_lock);
1425}
#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, 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.

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

1514{
1515 return ast_rtp_codecs_payloads_set_rtpmap_type_rate(codecs, instance, payload, mimetype, mimesubtype, options, 0);
1516}
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.
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 1427 of file rtp_engine.c.

1431{
1432 unsigned int idx;
1433 int found = 0;
1434
1435 if (pt < 0 || pt >= AST_RTP_MAX_PT) {
1436 return -1; /* bogus payload type */
1437 }
1438
1440 ast_rwlock_wrlock(&codecs->codecs_lock);
1441
1442 for (idx = 0; idx < mime_types_len; ++idx) {
1443 const struct ast_rtp_mime_type *t = &ast_rtp_mime_types[idx];
1445
1446 if (strcasecmp(mimesubtype, t->subtype)) {
1447 continue;
1448 }
1449
1450 if (strcasecmp(mimetype, t->type)) {
1451 continue;
1452 }
1453
1454 /* if both sample rates have been supplied, and they don't match,
1455 * then this not a match; if one has not been supplied, then the
1456 * rates are not compared */
1457 if (sample_rate && t->sample_rate &&
1458 (sample_rate != t->sample_rate)) {
1459 continue;
1460 }
1461
1462 found = 1;
1463
1465 if (!new_type) {
1466 continue;
1467 }
1468
1469 new_type->asterisk_format = t->payload_type.asterisk_format;
1470 new_type->rtp_code = t->payload_type.rtp_code;
1471 new_type->payload = pt;
1472 new_type->primary_mapping = 1;
1473 new_type->sample_rate = sample_rate;
1478 } else {
1479 new_type->format = t->payload_type.format;
1480 }
1481
1482 if (new_type->format) {
1483 /* SDP parsing automatically increases the reference count */
1484 new_type->format = ast_format_parse_sdp_fmtp(new_type->format, "");
1485 }
1486
1487 if (!payload_mapping_tx_is_present(codecs, new_type)) {
1488 if (pt < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1489 ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, pt),
1490 "cleaning up replaced tx payload type");
1491 }
1492
1493 if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, pt, new_type)) {
1494 ao2_ref(new_type, -1);
1495 } else if (instance && instance->engine && instance->engine->payload_set) {
1496 ao2_lock(instance);
1497 instance->engine->payload_set(instance, pt, new_type->asterisk_format, new_type->format, new_type->rtp_code);
1498 ao2_unlock(instance);
1499 }
1500 } else {
1501 ao2_ref(new_type, -1);
1502 }
1503
1504 break;
1505 }
1506
1507 ast_rwlock_unlock(&codecs->codecs_lock);
1509
1510 return (found ? 0 : -2);
1511}
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.
struct ast_format * ast_format_g726_aal2
Built-in cached g726 aal2 format.
static struct ast_rtp_mime_type ast_rtp_mime_types[128]
static int mime_types_len
Definition rtp_engine.c:271
static ast_rwlock_t mime_types_lock
Definition rtp_engine.c:270
@ AST_RTP_OPT_G726_NONSTANDARD
Definition rtp_engine.h:147
unsigned int sample_rate
Expected sample rate of the /c subtype.
Definition rtp_engine.c:268
char subtype[64]
The format type.
Definition rtp_engine.c:266
char type[16]
The media type.
Definition rtp_engine.c:264
struct ast_rtp_payload_type payload_type
A mapping object between the Asterisk codec and this RTP payload.
Definition rtp_engine.c:262

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, 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.

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

Since
1.8

Definition at line 1518 of file rtp_engine.c.

1519{
1520 struct ast_rtp_payload_type *type;
1521
1522 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
1523 return;
1524 }
1525
1526 ast_debug(2, "Unsetting payload %d on %p\n", payload, codecs);
1527
1528 ast_rwlock_wrlock(&codecs->codecs_lock);
1529
1530 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1531 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, payload);
1532 /*
1533 * Remove the preferred format if we are unsetting its container.
1534 *
1535 * There can be empty slots in payload_mapping_tx corresponding to
1536 * dynamic payload types that haven't been seen before so we need
1537 * to check for NULL before attempting to use 'type' in the call to
1538 * ast_format_cmp.
1539 */
1540 if (type) {
1541 if (ast_format_cmp(type->format, codecs->preferred_format) == AST_FORMAT_CMP_EQUAL) {
1542 ao2_replace(codecs->preferred_format, NULL);
1543 }
1544 ao2_ref(type, -1);
1545 AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, NULL);
1546 }
1547 }
1548
1549 if (instance && instance->engine && instance->engine->payload_set) {
1550 ao2_lock(instance);
1551 instance->engine->payload_set(instance, payload, 0, NULL, 0);
1552 ao2_unlock(instance);
1553 }
1554
1555 ast_rwlock_unlock(&codecs->codecs_lock);
1556}

References ao2_lock, ao2_ref, 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 1338 of file rtp_engine.c.

1339{
1340 int idx;
1341 struct ast_rtp_payload_type *type;
1342
1344 if (src != dest) {
1345 /* Deadlock avoidance because of held write lock. */
1346 while (ast_rwlock_tryrdlock(&src->codecs_lock)) {
1348 sched_yield();
1350 }
1351 }
1352
1353 /* Crossover copy payload type tx mapping to rx mapping. */
1354 for (idx = 0; idx < AST_VECTOR_SIZE(&src->payload_mapping_tx); ++idx) {
1356 if (!type) {
1357 continue;
1358 }
1359
1360 /* All tx mapping elements should have the primary flag set. */
1361 ast_assert(type->primary_mapping);
1362
1363 ast_debug(2, "Crossover copying tx to rx payload mapping %d (%p) from %p to %p\n",
1364 idx, type, src, dest);
1366
1367 if (instance && instance->engine && instance->engine->payload_set) {
1368 ao2_lock(instance);
1369 instance->engine->payload_set(instance, idx, type->asterisk_format, type->format, type->rtp_code);
1370 ao2_unlock(instance);
1371 }
1372 }
1373
1374 dest->framing = src->framing;
1378
1379 if (src != dest) {
1381 }
1383}
static void rtp_codecs_payload_replace_rx(struct ast_rtp_codecs *codecs, int payload, struct ast_rtp_payload_type *new_type)

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_dtmf_pt, ast_rtp_codecs::preferred_dtmf_rate, 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 1700 of file rtp_engine.c.

1701{
1702 if (!framing) {
1703 return;
1704 }
1705
1706 ast_rwlock_wrlock(&codecs->codecs_lock);
1707 codecs->framing = framing;
1708 ast_rwlock_unlock(&codecs->codecs_lock);
1709}

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_dtmf_format()

int ast_rtp_codecs_set_preferred_dtmf_format ( struct ast_rtp_codecs codecs,
int  pt,
int  rate 
)

Set the preferred dtmf format pt and sample rate.

Parameters
codecsCodecs structure to set the preferred format in
ptPreferred dtmf payload type to set.
ratePreferred dtmf payload rate 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:

int dtmf_code = atoi(dtmf_pt);
int dtmf_rate = clock_rate;
int ast_rtp_codecs_set_preferred_dtmf_format(struct ast_rtp_codecs *codecs, int pt, int rate)
Set the preferred dtmf format pt and sample rate.

This sets the preferred dtmf_code and dtmf_rate on the codec.

Definition at line 1636 of file rtp_engine.c.

1637{
1638 ast_rwlock_wrlock(&codecs->codecs_lock);
1639 codecs->preferred_dtmf_pt = pt;
1640 codecs->preferred_dtmf_rate = rate;
1641 ast_rwlock_unlock(&codecs->codecs_lock);
1642 return 0;
1643}

References ast_rwlock_unlock, ast_rwlock_wrlock, and codecs.

Referenced by get_codecs().

◆ 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.

This sets the first joint format as the preferred format.

Definition at line 1610 of file rtp_engine.c.

1611{
1612 ast_rwlock_wrlock(&codecs->codecs_lock);
1613 ao2_replace(codecs->preferred_format, format);
1614 ast_rwlock_unlock(&codecs->codecs_lock);
1615 return 0;
1616}

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

4245{
4246 struct ast_json *j_res;
4247 int ret;
4248
4249 j_res = ast_json_object_create();
4250 if (!j_res) {
4251 return NULL;
4252 }
4253
4254 /* set mandatory items */
4255 ret = ast_json_object_set(j_res, "txcount", ast_json_integer_create(stats->txcount));
4256 ret |= ast_json_object_set(j_res, "rxcount", ast_json_integer_create(stats->rxcount));
4257
4258 ret |= ast_json_object_set(j_res, "txploss", ast_json_integer_create(stats->txploss));
4259 ret |= ast_json_object_set(j_res, "rxploss", ast_json_integer_create(stats->rxploss));
4260
4261 ret |= ast_json_object_set(j_res, "local_ssrc", ast_json_integer_create(stats->local_ssrc));
4262 ret |= ast_json_object_set(j_res, "remote_ssrc", ast_json_integer_create(stats->remote_ssrc));
4263
4264 ret |= ast_json_object_set(j_res, "txoctetcount", ast_json_integer_create(stats->txoctetcount));
4265 ret |= ast_json_object_set(j_res, "rxoctetcount", ast_json_integer_create(stats->rxoctetcount));
4266
4267 ret |= ast_json_object_set(j_res, "channel_uniqueid", ast_json_string_create(stats->channel_uniqueid));
4268 if (ret) {
4269 ast_log(LOG_WARNING, "Could not create rtp statistics info. channel: %s\n", stats->channel_uniqueid);
4270 ast_json_unref(j_res);
4271 return NULL;
4272 }
4273
4274 /* set other items */
4275 SET_AST_JSON_OBJ(j_res, "txjitter", ast_json_real_create(stats->txjitter));
4276 SET_AST_JSON_OBJ(j_res, "rxjitter", ast_json_real_create(stats->rxjitter));
4277
4278 SET_AST_JSON_OBJ(j_res, "remote_maxjitter", ast_json_real_create(stats->remote_maxjitter));
4279 SET_AST_JSON_OBJ(j_res, "remote_minjitter", ast_json_real_create(stats->remote_minjitter));
4280 SET_AST_JSON_OBJ(j_res, "remote_normdevjitter", ast_json_real_create(stats->remote_normdevjitter));
4281 SET_AST_JSON_OBJ(j_res, "remote_stdevjitter", ast_json_real_create(stats->remote_stdevjitter));
4282
4283 SET_AST_JSON_OBJ(j_res, "local_maxjitter", ast_json_real_create(stats->local_maxjitter));
4284 SET_AST_JSON_OBJ(j_res, "local_minjitter", ast_json_real_create(stats->local_minjitter));
4285 SET_AST_JSON_OBJ(j_res, "local_normdevjitter", ast_json_real_create(stats->local_normdevjitter));
4286 SET_AST_JSON_OBJ(j_res, "local_stdevjitter", ast_json_real_create(stats->local_stdevjitter));
4287
4288 SET_AST_JSON_OBJ(j_res, "remote_maxrxploss", ast_json_real_create(stats->remote_maxrxploss));
4289 SET_AST_JSON_OBJ(j_res, "remote_minrxploss", ast_json_real_create(stats->remote_minrxploss));
4290 SET_AST_JSON_OBJ(j_res, "remote_normdevrxploss", ast_json_real_create(stats->remote_normdevrxploss));
4291 SET_AST_JSON_OBJ(j_res, "remote_stdevrxploss", ast_json_real_create(stats->remote_stdevrxploss));
4292
4293 SET_AST_JSON_OBJ(j_res, "local_maxrxploss", ast_json_real_create(stats->local_maxrxploss));
4294 SET_AST_JSON_OBJ(j_res, "local_minrxploss", ast_json_real_create(stats->local_minrxploss));
4295 SET_AST_JSON_OBJ(j_res, "local_normdevrxploss", ast_json_real_create(stats->local_normdevrxploss));
4296 SET_AST_JSON_OBJ(j_res, "local_stdevrxploss", ast_json_real_create(stats->local_stdevrxploss));
4297
4298 SET_AST_JSON_OBJ(j_res, "rtt", ast_json_real_create(stats->rtt));
4299 SET_AST_JSON_OBJ(j_res, "maxrtt", ast_json_real_create(stats->maxrtt));
4300 SET_AST_JSON_OBJ(j_res, "minrtt", ast_json_real_create(stats->minrtt));
4301 SET_AST_JSON_OBJ(j_res, "normdevrtt", ast_json_real_create(stats->normdevrtt));
4302 SET_AST_JSON_OBJ(j_res, "stdevrtt", ast_json_real_create(stats->stdevrtt));
4303
4304 SET_AST_JSON_OBJ(j_res, "txmes", ast_json_integer_create(stats->txmes));
4305 SET_AST_JSON_OBJ(j_res, "rxmes", ast_json_integer_create(stats->rxmes));
4306
4307 SET_AST_JSON_OBJ(j_res, "remote_maxmes", ast_json_real_create(stats->remote_maxmes));
4308 SET_AST_JSON_OBJ(j_res, "remote_minmes", ast_json_real_create(stats->remote_minmes));
4309 SET_AST_JSON_OBJ(j_res, "remote_normdevmes", ast_json_real_create(stats->remote_normdevmes));
4310 SET_AST_JSON_OBJ(j_res, "remote_stdevmes", ast_json_real_create(stats->remote_stdevmes));
4311
4312 SET_AST_JSON_OBJ(j_res, "local_maxmes", ast_json_real_create(stats->local_maxmes));
4313 SET_AST_JSON_OBJ(j_res, "local_minmes", ast_json_real_create(stats->local_minmes));
4314 SET_AST_JSON_OBJ(j_res, "local_normdevmes", ast_json_real_create(stats->local_normdevmes));
4315 SET_AST_JSON_OBJ(j_res, "local_stdevmes", ast_json_real_create(stats->local_stdevmes));
4316
4317 return j_res;
4318}
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:297
unsigned int remote_ssrc
Definition rtp_engine.h:454
unsigned int local_ssrc
Definition rtp_engine.h:452
unsigned int rxoctetcount
Definition rtp_engine.h:460
unsigned int txoctetcount
Definition rtp_engine.h:458
char channel_uniqueid[MAX_CHANNEL_ID]
Definition rtp_engine.h:456

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

3369{
3370 ast_rtp_dtls_cfg_free(dst_cfg); /* Prevent a double-call leaking memory via ast_strdup */
3371
3372 dst_cfg->enabled = src_cfg->enabled;
3373 dst_cfg->verify = src_cfg->verify;
3374 dst_cfg->rekey = src_cfg->rekey;
3375 dst_cfg->suite = src_cfg->suite;
3376 dst_cfg->hash = src_cfg->hash;
3377 dst_cfg->ephemeral_cert = src_cfg->ephemeral_cert;
3378 dst_cfg->certfile = ast_strdup(src_cfg->certfile);
3379 dst_cfg->pvtfile = ast_strdup(src_cfg->pvtfile);
3380 dst_cfg->cipher = ast_strdup(src_cfg->cipher);
3381 dst_cfg->cafile = ast_strdup(src_cfg->cafile);
3382 dst_cfg->capath = ast_strdup(src_cfg->capath);
3383 dst_cfg->default_setup = src_cfg->default_setup;
3384}
#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.
enum ast_rtp_dtls_setup default_setup
Definition rtp_engine.h:608
enum ast_rtp_dtls_verify verify
Definition rtp_engine.h:611
unsigned int rekey
Definition rtp_engine.h:607
enum ast_rtp_dtls_hash hash
Definition rtp_engine.h:610
unsigned int enabled
Definition rtp_engine.h:606
unsigned int ephemeral_cert
Definition rtp_engine.h:617
enum ast_srtp_suite suite
Definition rtp_engine.h:609

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

3387{
3388 ast_free(dtls_cfg->certfile);
3389 dtls_cfg->certfile = NULL;
3390 ast_free(dtls_cfg->pvtfile);
3391 dtls_cfg->pvtfile = NULL;
3392 ast_free(dtls_cfg->cipher);
3393 dtls_cfg->cipher = NULL;
3394 ast_free(dtls_cfg->cafile);
3395 dtls_cfg->cafile = NULL;
3396 ast_free(dtls_cfg->capath);
3397 dtls_cfg->capath = NULL;
3398}
#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 3275 of file rtp_engine.c.

3276{
3277 if (!strcasecmp(name, "dtlsenable")) {
3278 dtls_cfg->enabled = ast_true(value) ? 1 : 0;
3279 } else if (!strcasecmp(name, "dtlsverify")) {
3280 if (!strcasecmp(value, "yes")) {
3282 } else if (!strcasecmp(value, "fingerprint")) {
3284 } else if (!strcasecmp(value, "certificate")) {
3286 } else if (!strcasecmp(value, "no")) {
3287 dtls_cfg->verify = AST_RTP_DTLS_VERIFY_NONE;
3288 } else {
3289 return -1;
3290 }
3291 } else if (!strcasecmp(name, "dtlsrekey")) {
3292 if (sscanf(value, "%30u", &dtls_cfg->rekey) != 1) {
3293 return -1;
3294 }
3295 } else if (!strcasecmp(name, "dtlsautogeneratecert")) {
3296 dtls_cfg->ephemeral_cert = ast_true(value) ? 1 : 0;
3297 } else if (!strcasecmp(name, "dtlscertfile")) {
3299 ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3300 return -1;
3301 }
3302 ast_free(dtls_cfg->certfile);
3303 dtls_cfg->certfile = ast_strdup(value);
3304 } else if (!strcasecmp(name, "dtlsprivatekey")) {
3306 ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3307 return -1;
3308 }
3309 ast_free(dtls_cfg->pvtfile);
3310 dtls_cfg->pvtfile = ast_strdup(value);
3311 } else if (!strcasecmp(name, "dtlscipher")) {
3312 ast_free(dtls_cfg->cipher);
3313 dtls_cfg->cipher = ast_strdup(value);
3314 } else if (!strcasecmp(name, "dtlscafile")) {
3316 ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3317 return -1;
3318 }
3319 ast_free(dtls_cfg->cafile);
3320 dtls_cfg->cafile = ast_strdup(value);
3321 } else if (!strcasecmp(name, "dtlscapath") || !strcasecmp(name, "dtlscadir")) {
3323 ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3324 return -1;
3325 }
3326 ast_free(dtls_cfg->capath);
3327 dtls_cfg->capath = ast_strdup(value);
3328 } else if (!strcasecmp(name, "dtlssetup")) {
3329 if (!strcasecmp(value, "active")) {
3331 } else if (!strcasecmp(value, "passive")) {
3333 } else if (!strcasecmp(value, "actpass")) {
3335 }
3336 } else if (!strcasecmp(name, "dtlsfingerprint")) {
3337 if (!strcasecmp(value, "sha-256")) {
3338 dtls_cfg->hash = AST_RTP_DTLS_HASH_SHA256;
3339 } else if (!strcasecmp(value, "sha-1")) {
3340 dtls_cfg->hash = AST_RTP_DTLS_HASH_SHA1;
3341 }
3342 } else {
3343 return -1;
3344 }
3345
3346 return 0;
3347}
#define LOG_ERROR
@ AST_RTP_DTLS_SETUP_PASSIVE
Definition rtp_engine.h:566
@ AST_RTP_DTLS_SETUP_ACTPASS
Definition rtp_engine.h:567
@ AST_RTP_DTLS_SETUP_ACTIVE
Definition rtp_engine.h:565
@ AST_RTP_DTLS_HASH_SHA1
Definition rtp_engine.h:580
@ AST_RTP_DTLS_HASH_SHA256
Definition rtp_engine.h:579
@ AST_RTP_DTLS_VERIFY_NONE
Definition rtp_engine.h:585
@ AST_RTP_DTLS_VERIFY_FINGERPRINT
Definition rtp_engine.h:586
@ AST_RTP_DTLS_VERIFY_CERTIFICATE
Definition rtp_engine.h:587
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:2233
int ast_file_is_readable(const char *filename)
Test that a file exists and is readable by the effective user.
Definition utils.c:3141

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

3350{
3351 if (dtls_cfg->ephemeral_cert) {
3352 if (!ast_strlen_zero(dtls_cfg->certfile)) {
3353 ast_log(LOG_ERROR, "You cannot request automatically generated certificates"
3354 " (dtls_auto_generate_cert) and also specify a certificate file"
3355 " (dtls_cert_file) at the same time\n");
3356 return -1;
3357 } else if (!ast_strlen_zero(dtls_cfg->pvtfile)
3358 || !ast_strlen_zero(dtls_cfg->cafile)
3359 || !ast_strlen_zero(dtls_cfg->capath)) {
3360 ast_log(LOG_NOTICE, "dtls_pvt_file, dtls_cafile, and dtls_ca_path are"
3361 " ignored when dtls_auto_generate_cert is enabled\n");
3362 }
3363 }
3364
3365 return 0;
3366}
#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 335 of file rtp_engine.c.

336{
337 return rtp_payload_type_alloc(NULL, 0, 0, 0, 0);
338}

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

3896{
3899
3900 rtp_topic = stasis_topic_create("rtp:all");
3901 if (!rtp_topic) {
3902 return -1;
3903 }
3907
3908 /* Define all the RTP mime types available */
3909 set_next_mime_type(ast_format_g723, 0, "audio", "G723", 8000);
3910 set_next_mime_type(ast_format_gsm, 0, "audio", "GSM", 8000);
3911 set_next_mime_type(ast_format_ulaw, 0, "audio", "PCMU", 8000);
3912 set_next_mime_type(ast_format_ulaw, 0, "audio", "G711U", 8000);
3913 set_next_mime_type(ast_format_alaw, 0, "audio", "PCMA", 8000);
3914 set_next_mime_type(ast_format_alaw, 0, "audio", "G711A", 8000);
3915 set_next_mime_type(ast_format_g726, 0, "audio", "G726-32", 8000);
3916 set_next_mime_type(ast_format_adpcm, 0, "audio", "DVI4", 8000);
3917 set_next_mime_type(ast_format_slin, 0, "audio", "L16", 8000);
3918 set_next_mime_type(ast_format_slin16, 0, "audio", "L16", 16000);
3919 set_next_mime_type(ast_format_slin16, 0, "audio", "L16-256", 16000);
3920 set_next_mime_type(ast_format_slin12, 0, "audio", "L16", 12000);
3921 set_next_mime_type(ast_format_slin24, 0, "audio", "L16", 24000);
3922 set_next_mime_type(ast_format_slin32, 0, "audio", "L16", 32000);
3923 set_next_mime_type(ast_format_slin44, 0, "audio", "L16", 44100);
3924 set_next_mime_type(ast_format_slin48, 0, "audio", "L16", 48000);
3925 set_next_mime_type(ast_format_slin96, 0, "audio", "L16", 96000);
3926 set_next_mime_type(ast_format_slin192, 0, "audio", "L16", 192000);
3927 set_next_mime_type(ast_format_lpc10, 0, "audio", "LPC", 8000);
3928 set_next_mime_type(ast_format_g729, 0, "audio", "G729", 8000);
3929 set_next_mime_type(ast_format_g729, 0, "audio", "G729A", 8000);
3930 set_next_mime_type(ast_format_g729, 0, "audio", "G.729", 8000);
3931 set_next_mime_type(ast_format_speex, 0, "audio", "speex", 8000);
3932 set_next_mime_type(ast_format_speex16, 0, "audio", "speex", 16000);
3933 set_next_mime_type(ast_format_speex32, 0, "audio", "speex", 32000);
3934 set_next_mime_type(ast_format_ilbc, 0, "audio", "iLBC", 8000);
3935 /* this is the sample rate listed in the RTP profile for the G.722 codec, *NOT* the actual sample rate of the media stream */
3936 set_next_mime_type(ast_format_g722, 0, "audio", "G722", 8000);
3937 set_next_mime_type(ast_format_g726_aal2, 0, "audio", "AAL2-G726-32", 8000);
3938 /* we need all possible dtmf/bitrate combinations or ast_rtp_codecs_payloads_set_rtpmap_type_rate will not examine it */
3939 set_next_mime_type(NULL, AST_RTP_DTMF, "audio", "telephone-event", 8000);
3940 set_next_mime_type(NULL, AST_RTP_DTMF, "audio", "telephone-event", 16000);
3941 set_next_mime_type(NULL, AST_RTP_DTMF, "audio", "telephone-event", 24000);
3942 set_next_mime_type(NULL, AST_RTP_DTMF, "audio", "telephone-event", 32000);
3943 set_next_mime_type(NULL, AST_RTP_DTMF, "audio", "telephone-event", 48000);
3944 set_next_mime_type(NULL, AST_RTP_CISCO_DTMF, "audio", "cisco-telephone-event", 8000);
3945 set_next_mime_type(NULL, AST_RTP_CN, "audio", "CN", 8000);
3946 set_next_mime_type(ast_format_jpeg, 0, "video", "JPEG", 90000);
3947 set_next_mime_type(ast_format_png, 0, "video", "PNG", 90000);
3948 set_next_mime_type(ast_format_h261, 0, "video", "H261", 90000);
3949 set_next_mime_type(ast_format_h263, 0, "video", "H263", 90000);
3950 set_next_mime_type(ast_format_h263p, 0, "video", "h263-1998", 90000);
3951 set_next_mime_type(ast_format_h264, 0, "video", "H264", 90000);
3952 set_next_mime_type(ast_format_h265, 0, "video", "H265", 90000);
3953 set_next_mime_type(ast_format_mp4, 0, "video", "MP4V-ES", 90000);
3954 set_next_mime_type(ast_format_t140_red, 0, "text", "RED", 1000);
3955 set_next_mime_type(ast_format_t140, 0, "text", "T140", 1000);
3956 set_next_mime_type(ast_format_siren7, 0, "audio", "G7221", 16000);
3957 set_next_mime_type(ast_format_siren14, 0, "audio", "G7221", 32000);
3958 set_next_mime_type(ast_format_g719, 0, "audio", "G719", 48000);
3959 /* Opus, VP8, and VP9 */
3960 set_next_mime_type(ast_format_opus, 0, "audio", "opus", 48000);
3961 set_next_mime_type(ast_format_vp8, 0, "video", "VP8", 90000);
3962 set_next_mime_type(ast_format_vp9, 0, "video", "VP9", 90000);
3963
3964 /* Define the static rtp payload mappings */
3966 #ifdef USE_DEPRECATED_G726
3967 add_static_payload(2, ast_format_g726, 0);/* Technically this is G.721, but if Cisco can do it, so can we... */
3968 #endif
3971 add_static_payload(5, ast_format_adpcm, 0);/* 8 kHz */
3972 add_static_payload(6, ast_format_adpcm, 0); /* 16 kHz */
3976 add_static_payload(10, ast_format_slin, 0); /* 2 channels */
3977 add_static_payload(11, ast_format_slin, 0); /* 1 channel */
3979 add_static_payload(16, ast_format_adpcm, 0); /* 11.025 kHz */
3980 add_static_payload(17, ast_format_adpcm, 0); /* 22.050 kHz */
3982 add_static_payload(19, NULL, AST_RTP_CN); /* Also used for CN */
3986
3987 /*
3988 * Dynamic payload types - Even when dynamically assigning them we'll fall
3989 * back to using the statically declared values as the default number.
3990 */
3993
4000 add_static_payload(105, ast_format_t140_red, 0); /* Real time text chat (with redundancy encoding) */
4001 add_static_payload(106, ast_format_t140, 0); /* Real time text chat */
4005
4009
4013 add_static_payload(118, ast_format_slin16, 0); /* 16 Khz signed linear */
4015
4016 add_static_payload(121, NULL, AST_RTP_CISCO_DTMF); /* Must be type 121 */
4023 /* payload types above 127 are not valid */
4024
4032
4033 /*
4034 * Normnally a core module should call ast_register_cleanup,
4035 * which doesn't run if any module fails to unload. This
4036 * prevents resources being pulled out from under a running
4037 * module and possibly causing a segfault. In this case however,
4038 * the only thing we're cleaning up are the registrations of the
4039 * debug categories.
4040 */
4042
4043 return 0;
4044}
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.
struct ast_format * ast_format_h264
Built-in cached h264 format.
struct ast_format * ast_format_slin44
Built-in cached signed linear 44kHz format.
struct ast_format * ast_format_adpcm
Built-in cached adpcm format.
struct ast_format * ast_format_slin24
Built-in cached signed linear 24kHz format.
struct ast_format * ast_format_opus
Built-in cached opus format.
struct ast_format * ast_format_h265
Built-in cached h265 format.
struct ast_format * ast_format_gsm
Built-in cached gsm format.
struct ast_format * ast_format_slin32
Built-in cached signed linear 32kHz format.
struct ast_format * ast_format_siren14
Built-in cached siren14 format.
struct ast_format * ast_format_speex
Built-in cached speex format.
struct ast_format * ast_format_h263
Built-in cached h263 format.
struct ast_format * ast_format_mp4
Built-in cached mp4 format.
struct ast_format * ast_format_slin192
Built-in cached signed linear 192kHz format.
struct ast_format * ast_format_ilbc
Built-in cached ilbc format.
struct ast_format * ast_format_lpc10
Built-in cached ilbc format.
struct ast_format * ast_format_slin16
Built-in cached signed linear 16kHz format.
struct ast_format * ast_format_slin96
Built-in cached signed linear 96kHz format.
struct ast_format * ast_format_slin48
Built-in cached signed linear 48kHz format.
struct ast_format * ast_format_g723
Built-in cached g723.1 format.
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
struct ast_format * ast_format_siren7
Built-in cached siren7 format.
struct ast_format * ast_format_alaw
Built-in cached alaw format.
struct ast_format * ast_format_speex32
Built-in cached speex at 32kHz format.
struct ast_format * ast_format_h261
Built-in cached h261 format.
struct ast_format * ast_format_vp9
Built-in cached vp9 format.
struct ast_format * ast_format_t140_red
Built-in cached t140 red format.
struct ast_format * ast_format_slin12
Built-in cached signed linear 12kHz format.
struct ast_format * ast_format_h263p
Built-in cached h263 plus format.
struct ast_format * ast_format_png
Built-in cached png format.
struct ast_format * ast_format_g722
Built-in cached g722 format.
struct ast_format * ast_format_t140
Built-in cached t140 format.
struct ast_format * ast_format_g729
Built-in cached g729 format.
struct ast_format * ast_format_jpeg
Built-in cached jpeg format.
struct ast_format * ast_format_vp8
Built-in cached vp8 format.
struct ast_format * ast_format_g719
Built-in cached g719 format.
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:287
static void rtp_engine_shutdown(void)
static void add_static_payload(int payload, struct ast_format *format, int rtp_code)
static void rtp_engine_atexit(void)
static void set_next_mime_type(struct ast_format *format, int rtp_code, const char *type, const char *subtype, unsigned int sample_rate)
#define AST_LOG_CATEGORY_ICE
#define AST_LOG_CATEGORY_RTCP_PACKET
#define AST_LOG_CATEGORY_DTLS
#define AST_LOG_CATEGORY_RTCP
#define AST_LOG_CATEGORY_RTP
#define AST_LOG_CATEGORY_RTP_PACKET
#define AST_LOG_CATEGORY_DTLS_PACKET
#define AST_RTP_CISCO_DTMF
Definition rtp_engine.h:298
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Definition stasis.c:684
#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 3484 of file rtp_engine.c.

3485{
3486 char *codec_name = ast_strdupa(ast_format_get_codec_name(format));
3487
3488 codec_name = ast_str_to_upper(codec_name);
3489
3490 set_next_mime_type(format,
3491 0,
3493 codec_name,
3495 add_static_payload(-1, format, 0);
3496
3497 return 0;
3498}
#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:340

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

341{
342 struct ast_rtp_engine *current_engine;
343
344 /* Perform a sanity check on the engine structure to make sure it has the basics */
345 if (ast_strlen_zero(engine->name) || !engine->new || !engine->destroy || !engine->write || !engine->read) {
346 ast_log(LOG_WARNING, "RTP Engine '%s' failed sanity check so it was not registered.\n", !ast_strlen_zero(engine->name) ? engine->name : "Unknown");
347 return -1;
348 }
349
350 /* Link owner module to the RTP engine for reference counting purposes */
351 engine->mod = module;
352
354
355 /* Ensure that no two modules with the same name are registered at the same time */
356 AST_RWLIST_TRAVERSE(&engines, current_engine, entry) {
357 if (!strcmp(current_engine->name, engine->name)) {
358 ast_log(LOG_WARNING, "An RTP engine with the name '%s' has already been registered.\n", engine->name);
360 return -1;
361 }
362 }
363
364 /* The engine survived our critique. Off to the list it goes to be used */
366
368
369 ast_verb(5, "Registered RTP engine '%s'\n", engine->name);
370
371 return 0;
372}
#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.
#define AST_RWLIST_TRAVERSE
#define AST_RWLIST_INSERT_TAIL
int(* write)(struct ast_rtp_instance *instance, struct ast_frame *frame)
Definition rtp_engine.h:675
struct ast_rtp_engine::@291 entry
int(* destroy)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:673
struct ast_module * mod
Definition rtp_engine.h:669
int(* new)(struct ast_rtp_instance *instance, struct ast_sched_context *sched, struct ast_sockaddr *sa, void *data)
Definition rtp_engine.h:671
const char * name
Definition rtp_engine.h:667
struct ast_frame *(* read)(struct ast_rtp_instance *instance, int rtcp)
Definition rtp_engine.h:712

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, ast_rtp_engine::entry, 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 2965 of file rtp_engine.c.

2966{
2967 if (res_srtp || res_srtp_policy) {
2968 return -1;
2969 }
2970 if (!srtp_res || !policy_res) {
2971 return -1;
2972 }
2973
2976
2977 return 0;
2978}
static struct ast_srtp_res srtp_res
Definition res_srtp.c:129
static struct ast_srtp_policy_res policy_res
Definition res_srtp.c:141
struct ast_srtp_res * res_srtp
Definition rtp_engine.c:182
struct ast_srtp_policy_res * res_srtp_policy
Definition rtp_engine.c:183

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

2987{
2988 return res_srtp && res_srtp_policy;
2989}

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

3501{
3502 int x;
3503 int y = 0;
3504
3506 /* remove everything pertaining to this format id from the lists */
3507 for (x = 0; x < AST_RTP_MAX_PT; x++) {
3508 if (static_RTP_PT[x]
3509 && ast_format_cmp(static_RTP_PT[x]->format, format) == AST_FORMAT_CMP_EQUAL) {
3510 ao2_ref(static_RTP_PT[x], -1);
3511 static_RTP_PT[x] = NULL;
3512 }
3513 }
3515
3517 /* rebuild the list skipping the items matching this id */
3518 for (x = 0; x < mime_types_len; x++) {
3519 if (ast_format_cmp(ast_rtp_mime_types[x].payload_type.format, format) == AST_FORMAT_CMP_EQUAL) {
3521 continue;
3522 }
3523 if (x != y) {
3525 }
3526 y++;
3527 }
3528 mime_types_len = y;
3530 return 0;
3531}
static void rtp_engine_mime_type_cleanup(int i)

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:374

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

375{
376 struct ast_rtp_engine *current_engine = NULL;
377
379
380 if ((current_engine = AST_RWLIST_REMOVE(&engines, engine, entry))) {
381 ast_verb(5, "Unregistered RTP engine '%s'\n", engine->name);
382 }
383
385
386 return current_engine ? 0 : -1;
387}
#define AST_RWLIST_REMOVE

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

Referenced by load_module(), unload_module(), and unload_module().

◆ ast_rtp_engine_unregister_srtp()

void ast_rtp_engine_unregister_srtp ( void  )

Definition at line 2980 of file rtp_engine.c.

2981{
2982 res_srtp = NULL;
2984}

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

4332{
4333 /* For those wondering: due to a fluke in RFC publication, G.722 is advertised
4334 * as having a sample rate of 8kHz, while implementations must know that its
4335 * real rate is 16kHz. Seriously.
4336 */
4337 return (ast_format_cmp(format, ast_format_g722) == AST_FORMAT_CMP_EQUAL) ? 8000 : (int)ast_format_get_sample_rate(format);
4338}

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_begin(), 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:389

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

390{
391 struct ast_rtp_glue *current_glue = NULL;
392
393 if (ast_strlen_zero(glue->type)) {
394 return -1;
395 }
396
397 glue->mod = module;
398
400
401 AST_RWLIST_TRAVERSE(&glues, current_glue, entry) {
402 if (!strcasecmp(current_glue->type, glue->type)) {
403 ast_log(LOG_WARNING, "RTP glue with the name '%s' has already been registered.\n", glue->type);
405 return -1;
406 }
407 }
408
410
412
413 ast_verb(5, "Registered RTP glue '%s'\n", glue->type);
414
415 return 0;
416}
struct ast_rtp_glue::@294 entry
const char * type
Definition rtp_engine.h:780
struct ast_module * mod
Definition rtp_engine.h:782

References ast_log, AST_RWLIST_INSERT_TAIL, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_strlen_zero(), ast_verb, ast_rtp_glue::entry, 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:418

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

419{
420 struct ast_rtp_glue *current_glue = NULL;
421
423
424 if ((current_glue = AST_RWLIST_REMOVE(&glues, glue, entry))) {
425 ast_verb(5, "Unregistered RTP glue '%s'\n", glue->type);
426 }
427
429
430 return current_glue ? 0 : -1;
431}

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

Referenced by load_module(), load_module(), unload_module(), unload_module(), unload_module(), unload_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.

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

Since
1.8

Definition at line 2892 of file rtp_engine.c.

2893{
2894 int res;
2895
2896 if (instance->engine->activate) {
2897 ao2_lock(instance);
2898 res = instance->engine->activate(instance);
2899 ao2_unlock(instance);
2900 } else {
2901 res = 0;
2902 }
2903 return res;
2904}
int(* activate)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:724

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

2992{
2993 int res = 0;
2994 struct ast_srtp **srtp;
2995
2996 if (!res_srtp) {
2997 return -1;
2998 }
2999
3000 ao2_lock(instance);
3001
3002 srtp = rtcp ? &instance->rtcp_srtp : &instance->srtp;
3003
3004 if (!*srtp) {
3005 res = res_srtp->create(srtp, instance, remote_policy);
3006 } else if (remote_policy) {
3007 res = res_srtp->replace(srtp, instance, remote_policy);
3008 }
3009 if (!res) {
3010 res = res_srtp->add_stream(*srtp, local_policy);
3011 }
3012
3013 ao2_unlock(instance);
3014
3015 return res;
3016}
struct ast_srtp * rtcp_srtp
Definition rtp_engine.c:222
struct ast_srtp * srtp
Definition rtp_engine.c:220
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.

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

2879{
2880 if (instance->engine->available_formats) {
2881 ao2_lock(instance);
2882 instance->engine->available_formats(instance, to_endpoint, to_asterisk, result);
2883 ao2_unlock(instance);
2885 return;
2886 }
2887 }
2888
2889 ast_translate_available_formats(to_endpoint, to_asterisk, result);
2890}
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:728
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:1890

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

4093{
4094 int res = -1;
4095
4096 if (parent && (child->engine != parent->engine)) {
4097 return -1;
4098 }
4099
4100 ao2_lock(child);
4101 if (child->engine->bundle) {
4102 res = child->engine->bundle(child, parent);
4103 }
4104 ao2_unlock(child);
4105
4106 return res;
4107}
int(* bundle)(struct ast_rtp_instance *child, struct ast_rtp_instance *parent)
Definition rtp_engine.h:736

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.

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

2376{
2377 if (instance->engine->change_source) {
2378 ao2_lock(instance);
2379 instance->engine->change_source(instance);
2380 ao2_unlock(instance);
2381 }
2382}
void(* change_source)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:686

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

Referenced by chan_pjsip_indicate(), 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:468

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

469{
470 if (!instance) {
471 return 0;
472 }
474 char buffer[4][512];
475 ast_debug_rtp(1, "%s:\n"
476 " RTT: %s\n"
477 " Loss: %s\n"
478 " Jitter: %s\n"
479 " MES: %s\n",
480 instance->channel_uniqueid,
482 buffer[0], sizeof(buffer[0])),
484 buffer[1], sizeof(buffer[1])),
486 buffer[2], sizeof(buffer[2])),
488 buffer[3], sizeof(buffer[3]))
489 );
490 }
491
492 ao2_cleanup(instance);
493
494 return 0;
495}
@ AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS
Definition rtp_engine.h:177
@ AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT
Definition rtp_engine.h:179
@ AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER
Definition rtp_engine.h:175
@ AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES
Definition rtp_engine.h:181
#define ast_debug_rtp(sublevel,...)
Log debug level RTP information.
#define ast_debug_rtp_is_allowed
char channel_uniqueid[AST_MAX_UNIQUEID]
Definition rtp_engine.c:224

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(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), 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.

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

2297{
2298 int res;
2299
2300 if (instance->engine->dtmf_begin) {
2301 ao2_lock(instance);
2302 res = instance->engine->dtmf_begin(instance, digit);
2303 ao2_unlock(instance);
2304 } else {
2305 res = -1;
2306 }
2307 return res;
2308}
char digit
int(* dtmf_begin)(struct ast_rtp_instance *instance, char digit)
Definition rtp_engine.h:679

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.

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

Since
1.8

Definition at line 2310 of file rtp_engine.c.

2311{
2312 int res;
2313
2314 if (instance->engine->dtmf_end) {
2315 ao2_lock(instance);
2316 res = instance->engine->dtmf_end(instance, digit);
2317 ao2_unlock(instance);
2318 } else {
2319 res = -1;
2320 }
2321 return res;
2322}
int(* dtmf_end)(struct ast_rtp_instance *instance, char digit)
Definition rtp_engine.h:681

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

2325{
2326 int res;
2327
2328 if (instance->engine->dtmf_end_with_duration) {
2329 ao2_lock(instance);
2330 res = instance->engine->dtmf_end_with_duration(instance, digit, duration);
2331 ao2_unlock(instance);
2332 } else {
2333 res = -1;
2334 }
2335 return res;
2336}
int(* dtmf_end_with_duration)(struct ast_rtp_instance *instance, char digit, unsigned int duration)
Definition rtp_engine.h:682

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.
ast_rtp_dtmf_mode
Definition rtp_engine.h:151

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

Since
1.8

Definition at line 2352 of file rtp_engine.c.

2353{
2354 int res;
2355
2356 if (instance->engine->dtmf_mode_get) {
2357 ao2_lock(instance);
2358 res = instance->engine->dtmf_mode_get(instance);
2359 ao2_unlock(instance);
2360 } else {
2361 res = 0;
2362 }
2363 return res;
2364}
enum ast_rtp_dtmf_mode(* dtmf_mode_get)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:700

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:155
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.

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

Since
1.8

Definition at line 2338 of file rtp_engine.c.

2339{
2340 int res;
2341
2342 if (instance->engine->dtmf_mode_set) {
2343 ao2_lock(instance);
2344 res = instance->engine->dtmf_mode_set(instance, dtmf_mode);
2345 ao2_unlock(instance);
2346 } else {
2347 res = -1;
2348 }
2349 return res;
2350}
int(* dtmf_mode_set)(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode)
Definition rtp_engine.h:698

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

2553{
2554 struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
2555 *vinstance0 = NULL, *vinstance1 = NULL,
2556 *tinstance0 = NULL, *tinstance1 = NULL;
2557 struct ast_rtp_glue *glue0, *glue1;
2558 enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
2559 enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
2562
2563 /* If there is no second channel just immediately bail out, we are of no use in that scenario */
2564 if (!c1 || !cap1 || !cap0) {
2565 ao2_cleanup(cap0);
2566 ao2_cleanup(cap1);
2567 return -1;
2568 }
2569
2570 /* Lock both channels so we can look for the glue that binds them together */
2571 ast_channel_lock_both(c0, c1);
2572
2573 /* Grab glue that binds each channel to something using the RTP engine */
2575 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", glue0 ? ast_channel_name(c1) : ast_channel_name(c0));
2576 goto done;
2577 }
2578
2579 audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
2580 video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;
2581
2582 audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
2583 video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;
2584
2585 /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
2586 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)) {
2587 audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
2588 }
2589 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)) {
2590 audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
2591 }
2592 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) {
2593 glue0->get_codec(c0, cap0);
2594 }
2595 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) {
2596 glue1->get_codec(c1, cap1);
2597 }
2598
2599 /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
2600 if (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE) {
2601 goto done;
2602 }
2603
2604 /* Make sure we have matching codecs */
2605 if (!ast_format_cap_iscompatible(cap0, cap1)) {
2606 goto done;
2607 }
2608
2609 /* Bridge media early */
2610 if (glue0->update_peer(c0, instance1, vinstance1, tinstance1, cap1, 0)) {
2611 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", ast_channel_name(c0), c1 ? ast_channel_name(c1) : "<unspecified>");
2612 }
2613
2614done:
2617
2618 ao2_cleanup(cap0);
2619 ao2_cleanup(cap1);
2620
2621 unref_instance_cond(&instance0);
2622 unref_instance_cond(&instance1);
2623 unref_instance_cond(&vinstance0);
2624 unref_instance_cond(&vinstance1);
2625 unref_instance_cond(&tinstance0);
2626 unref_instance_cond(&tinstance1);
2627
2628 ast_debug(1, "Setting early bridge SDP of '%s' with that of '%s'\n", ast_channel_name(c0), c1 ? ast_channel_name(c1) : "<unspecified>");
2629
2630 return 0;
2631}
const char * ast_channel_name(const struct ast_channel *chan)
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition channel.h:2996
#define ast_channel_unlock(chan)
Definition channel.h:2990
@ 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.
struct ast_rtp_glue * ast_rtp_instance_get_glue(const char *type)
Get the RTP glue that binds a channel to the RTP engine.
ast_rtp_glue_result
Definition rtp_engine.h:161
@ AST_RTP_GLUE_RESULT_REMOTE
Definition rtp_engine.h:165
@ AST_RTP_GLUE_RESULT_FORBID
Definition rtp_engine.h:163
Structure to describe a channel "technology", ie a channel driver See for examples:
Definition channel.h:648
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:787
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:819
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:814
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:799
int done

References ao2_cleanup, ast_channel_lock_both, ast_channel_name(), 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 2466 of file rtp_engine.c.

2467{
2468 struct ast_rtp_instance *instance_dst = NULL, *instance_src = NULL,
2469 *vinstance_dst = NULL, *vinstance_src = NULL,
2470 *tinstance_dst = NULL, *tinstance_src = NULL;
2471 struct ast_rtp_glue *glue_dst, *glue_src;
2472 enum ast_rtp_glue_result audio_glue_dst_res = AST_RTP_GLUE_RESULT_FORBID, video_glue_dst_res = AST_RTP_GLUE_RESULT_FORBID;
2473 enum ast_rtp_glue_result audio_glue_src_res = AST_RTP_GLUE_RESULT_FORBID, video_glue_src_res = AST_RTP_GLUE_RESULT_FORBID;
2476
2477 /* Lock both channels so we can look for the glue that binds them together */
2478 ast_channel_lock_both(c_dst, c_src);
2479
2480 if (!cap_src || !cap_dst) {
2481 goto done;
2482 }
2483
2484 /* Grab glue that binds each channel to something using the RTP engine */
2485 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))) {
2486 ast_debug(1, "Can't find native functions for channel '%s'\n", glue_dst ? ast_channel_name(c_src) : ast_channel_name(c_dst));
2487 goto done;
2488 }
2489
2490 audio_glue_dst_res = glue_dst->get_rtp_info(c_dst, &instance_dst);
2491 video_glue_dst_res = glue_dst->get_vrtp_info ? glue_dst->get_vrtp_info(c_dst, &vinstance_dst) : AST_RTP_GLUE_RESULT_FORBID;
2492
2493 audio_glue_src_res = glue_src->get_rtp_info(c_src, &instance_src);
2494 video_glue_src_res = glue_src->get_vrtp_info ? glue_src->get_vrtp_info(c_src, &vinstance_src) : AST_RTP_GLUE_RESULT_FORBID;
2495
2496 /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
2497 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)) {
2498 audio_glue_dst_res = AST_RTP_GLUE_RESULT_FORBID;
2499 }
2500 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)) {
2501 audio_glue_src_res = AST_RTP_GLUE_RESULT_FORBID;
2502 }
2503 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) {
2504 glue_dst->get_codec(c_dst, cap_dst);
2505 }
2506 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) {
2507 glue_src->get_codec(c_src, cap_src);
2508 }
2509
2510 /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
2511 if (audio_glue_dst_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue_src_res != AST_RTP_GLUE_RESULT_REMOTE) {
2512 goto done;
2513 }
2514
2515 /* Make sure we have matching codecs */
2516 if (!ast_format_cap_iscompatible(cap_dst, cap_src)) {
2517 goto done;
2518 }
2519
2520 ast_rtp_codecs_payloads_xover(&instance_src->codecs, &instance_dst->codecs, instance_dst);
2521
2522 if (vinstance_dst && vinstance_src) {
2523 ast_rtp_codecs_payloads_xover(&vinstance_src->codecs, &vinstance_dst->codecs, vinstance_dst);
2524 }
2525 if (tinstance_dst && tinstance_src) {
2526 ast_rtp_codecs_payloads_xover(&tinstance_src->codecs, &tinstance_dst->codecs, tinstance_dst);
2527 }
2528
2529 if (glue_dst->update_peer(c_dst, instance_src, vinstance_src, tinstance_src, cap_src, 0)) {
2530 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n",
2531 ast_channel_name(c_dst), ast_channel_name(c_src));
2532 } else {
2533 ast_debug(1, "Seeded SDP of '%s' with that of '%s'\n",
2534 ast_channel_name(c_dst), ast_channel_name(c_src));
2535 }
2536
2537done:
2538 ast_channel_unlock(c_dst);
2539 ast_channel_unlock(c_src);
2540
2541 ao2_cleanup(cap_dst);
2542 ao2_cleanup(cap_src);
2543
2544 unref_instance_cond(&instance_dst);
2545 unref_instance_cond(&instance_src);
2546 unref_instance_cond(&vinstance_dst);
2547 unref_instance_cond(&vinstance_src);
2548 unref_instance_cond(&tinstance_dst);
2549 unref_instance_cond(&tinstance_src);
2550}
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.
struct ast_rtp_codecs codecs
Definition rtp_engine.c:210

References ao2_cleanup, ast_channel_lock_both, ast_channel_name(), 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 913 of file rtp_engine.c.

914{
915 static const struct rtp_extmap extmap_none = {
918 };
919 int idx;
920
921 ao2_lock(instance);
922
923 /* Clear both the known unique ids and the negotiated extensions as we are about to have
924 * new results set on us.
925 */
926 for (idx = 0; idx < AST_VECTOR_SIZE(&instance->extmap_unique_ids); ++idx) {
927 AST_VECTOR_REPLACE(&instance->extmap_unique_ids, idx, extmap_none);
928 }
929
930 for (idx = 0; idx < AST_VECTOR_SIZE(&instance->extmap_negotiated); ++idx) {
931 AST_VECTOR_REPLACE(&instance->extmap_negotiated, idx, -1);
932 }
933
934 ao2_unlock(instance);
935}
@ AST_RTP_EXTENSION_UNSUPPORTED
Definition rtp_engine.h:595
@ AST_RTP_EXTENSION_DIRECTION_NONE
Definition rtp_engine.h:829
struct ast_rtp_instance::@413 extmap_negotiated
struct ast_rtp_instance::@414 extmap_unique_ids
enum ast_rtp_extension extension
Definition rtp_engine.c:188

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

951{
952 size_t count;
953
954 ao2_lock(instance);
955 count = AST_VECTOR_SIZE(&instance->extmap_unique_ids);
956 ao2_unlock(instance);
957
958 return count;
959}

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

785{
786 struct rtp_extmap extmap = {
788 .direction = direction,
789 };
790
791 ao2_lock(instance);
792
793 if (!instance->engine->extension_enable || !instance->engine->extension_enable(instance, extension)) {
794 ao2_unlock(instance);
795 return 0;
796 }
797
798 /* We store enabled extensions separately so we can easily do negotiation */
800 ao2_unlock(instance);
801 return -1;
802 }
803
804 if (id <= 0) {
805 /* We find a free unique identifier for this extension by just appending it to the
806 * vector of unique ids. The size of the vector will become its unique identifier.
807 * As well when we are asking for information on the extensions it will be returned,
808 * allowing it to be added to the SDP offer.
809 */
810 if (AST_VECTOR_APPEND(&instance->extmap_unique_ids, extmap)) {
812 ao2_unlock(instance);
813 return -1;
814 }
815 id = AST_VECTOR_SIZE(&instance->extmap_unique_ids);
816 } else {
817 /* Otherwise we put it precisely where they want it */
818 if (AST_VECTOR_REPLACE(&instance->extmap_unique_ids, id - 1, extmap)) {
820 ao2_unlock(instance);
821 return -1;
822 }
823 }
824
825 /* Now that we have an id add the extension to here */
826 if (AST_VECTOR_REPLACE(&instance->extmap_negotiated, extension, id)) {
830 AST_VECTOR_REPLACE(&instance->extmap_unique_ids, id - 1, extmap);
831 ao2_unlock(instance);
832 return -1;
833 }
834
835 ao2_unlock(instance);
836
837 return 0;
838}
direction
int(* extension_enable)(struct ast_rtp_instance *instance, enum ast_rtp_extension extension)
Definition rtp_engine.h:750
struct ast_rtp_instance::@412 extmap_enabled
structure to hold extensions
enum ast_rtp_extension_direction direction
Definition rtp_engine.c:190
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition vector.h:267

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

982{
984
985 ao2_lock(instance);
986
987 if (0 < id && id <= AST_VECTOR_SIZE(&instance->extmap_unique_ids)) {
988 struct rtp_extmap *extmap = AST_VECTOR_GET_ADDR(&instance->extmap_unique_ids, id - 1);
989
990 direction = extmap->direction;
991 }
992 ao2_unlock(instance);
993
994 return direction;
995}
ast_rtp_extension_direction
Directions for RTP extensions.
Definition rtp_engine.h:827
#define AST_VECTOR_GET_ADDR(vec, idx)
Get an address of element in a vector.
Definition vector.h:679

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

962{
964
965 ao2_lock(instance);
966
967 /* The local unique identifier starts at '1' so the highest unique identifier
968 * can be the actual size of the vector. We compensate (as it is 0 index based)
969 * by dropping it down to 1 to get the correct information.
970 */
971 if (0 < id && id <= AST_VECTOR_SIZE(&instance->extmap_unique_ids)) {
972 struct rtp_extmap *extmap = AST_VECTOR_GET_ADDR(&instance->extmap_unique_ids, id - 1);
973
974 extension = extmap->extension;
975 }
976 ao2_unlock(instance);
977
978 return extension;
979}
ast_rtp_extension
Known RTP extensions.
Definition rtp_engine.h:593

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

938{
939 int id = -1;
940
941 ao2_lock(instance);
942 if (extension < AST_VECTOR_SIZE(&instance->extmap_negotiated)) {
944 }
945 ao2_unlock(instance);
946
947 return id;
948}
enum queue_result id
Definition app_queue.c:1790

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

998{
1000
1002 (unsigned int)extension >= ARRAY_LEN(rtp_extension_uris)) {
1003 return NULL;
1004 }
1005
1007}
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:961
static const char *const rtp_extension_uris[AST_RTP_EXTENSION_MAX]
URIs for known RTP extensions.
Definition rtp_engine.c:244

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

871{
872 /* 'attributes' is currently unused but exists in the API to ensure it does not need to be altered
873 * in the future in case we need to use it.
874 */
875 int idx;
877
878 /* Per the RFC the identifier has to be 1 or above */
879 if (id < 1) {
880 return -1;
881 }
882
883 /* Convert the provided URI to the internal representation */
884 for (idx = 0; idx < ARRAY_LEN(rtp_extension_uris); ++idx) {
885 if (!strcasecmp(rtp_extension_uris[idx], uri)) {
886 extension = idx;
887 break;
888 }
889 }
890
891 ao2_lock(instance);
892 /* We only accept the extension if it is enabled */
893 if (extension < AST_VECTOR_SIZE(&instance->extmap_enabled) &&
895 struct rtp_extmap extmap = {
898 };
899
900 /* If the direction negotiation failed then don't accept or use this extension */
904 }
905 AST_VECTOR_REPLACE(&instance->extmap_unique_ids, id - 1, extmap);
906 }
907 }
908 ao2_unlock(instance);
909
910 return 0;
911}
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:841

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)

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

Since
1.8

Definition at line 2407 of file rtp_engine.c.

2408{
2409 int res;
2410
2411 if (instance->engine->fd) {
2412 ao2_lock(instance);
2413 res = instance->engine->fd(instance, rtcp);
2414 ao2_unlock(instance);
2415 } else {
2416 res = -1;
2417 }
2418 return res;
2419}
int(* fd)(struct ast_rtp_instance *instance, int rtcp)
Definition rtp_engine.h:706

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.

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

Since
1.8

Definition at line 2960 of file rtp_engine.c.

2961{
2962 return instance->glue;
2963}
struct ast_rtp_glue * glue
Definition rtp_engine.c:218

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

682{
683 ao2_lock(instance);
684 if (ast_sockaddr_cmp(address, &instance->local_address) != 0) {
686 ao2_unlock(instance);
687 return 1;
688 }
689 ao2_unlock(instance);
690
691 return 0;
692}
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:202

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

704{
705 ao2_lock(instance);
706 if (ast_sockaddr_cmp(address, &instance->requested_target_address) != 0) {
708 ao2_unlock(instance);
709 return 1;
710 }
711 ao2_unlock(instance);
712
713 return 0;
714}
struct ast_sockaddr requested_target_address
Definition rtp_engine.c:204

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.
struct ast_rtp_instance * bridged
Definition rtp_engine.c:208

This gets the RTP instance that instance0 is bridged to.

Since
1.8

Definition at line 2449 of file rtp_engine.c.

2450{
2451 struct ast_rtp_instance *bridged;
2452
2453 ao2_lock(instance);
2454 bridged = instance->bridged;
2455 ao2_unlock(instance);
2456 return bridged;
2457}

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

600{
601 return instance->channel_uniqueid;
602}

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

4080{
4081 const char *cname = "";
4082
4083 ao2_lock(rtp);
4084 if (rtp->engine->cname_get) {
4085 cname = rtp->engine->cname_get(rtp);
4086 }
4087 ao2_unlock(rtp);
4088
4089 return cname;
4090}
const char *(* cname_get)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:734

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:778

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

Since
1.8

Definition at line 778 of file rtp_engine.c.

779{
780 return &instance->codecs;
781}

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:614

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

Since
1.8

Definition at line 614 of file rtp_engine.c.

615{
616 return instance->data;
617}

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

3267{
3268 if (instance->engine->dtls) {
3269 return &rtp_dtls_wrappers;
3270 }
3271 /* DTLS not available */
3272 return NULL;
3273}
static struct ast_rtp_engine_dtls rtp_dtls_wrappers
struct ast_rtp_engine_dtls * dtls
Definition rtp_engine.h:744

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.

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

Since
1.8

Definition at line 2955 of file rtp_engine.c.

2956{
2957 return instance->engine;
2958}

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

742{
743 void *prop;
744
745 if (instance->engine->extended_prop_get) {
746 ao2_lock(instance);
747 prop = instance->engine->extended_prop_get(instance, property);
748 ao2_unlock(instance);
749 } else {
750 prop = NULL;
751 }
752
753 return prop;
754}
void *(* extended_prop_get)(struct ast_rtp_instance *instance, int property)
Definition rtp_engine.h:690

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.

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

Since
1.8

Definition at line 2421 of file rtp_engine.c.

2422{
2423 struct ast_rtp_glue *glue = NULL;
2424
2426
2428 if (!strcasecmp(glue->type, type)) {
2429 break;
2430 }
2431 }
2432
2434
2435 return glue;
2436}
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition linkedlists.h:78

References AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_rtp_glue::entry, 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(), ast_softhangup(), 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.

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

Since
1.8

Definition at line 2935 of file rtp_engine.c.

2936{
2937 return instance->holdtimeout;
2938}

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

3147{
3148 if (instance->engine->ice) {
3149 return &rtp_ice_wrappers;
3150 }
3151 /* ICE not available */
3152 return NULL;
3153}
static struct ast_rtp_engine_ice rtp_ice_wrappers
struct ast_rtp_engine_ice * ice
Definition rtp_engine.h:742

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

718{
719 ao2_lock(instance);
721 ao2_unlock(instance);
722}
struct ast_sockaddr incoming_source_address
Definition rtp_engine.c:206

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.

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

Since
1.8

Definition at line 2940 of file rtp_engine.c.

2941{
2942 return instance->keepalive;
2943}

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

4057{
4058 return rtp->last_rx;
4059}

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

4047{
4048 return rtp->last_tx;
4049}

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:694

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

Since
1.8

Definition at line 694 of file rtp_engine.c.

696{
697 ao2_lock(instance);
699 ao2_unlock(instance);
700}

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_port_end()

unsigned int ast_rtp_instance_get_port_end ( struct ast_rtp_instance instance)

Get the per-instance RTP port range end.

Parameters
instanceThe RTP instance
Returns
port end value (0 means use global setting)
Since
20.20.0
22.10.0
23.4.0

Definition at line 2950 of file rtp_engine.c.

2951{
2952 return instance->rtp_port_end;
2953}
unsigned int rtp_port_end
Definition rtp_engine.c:238

References ast_rtp_instance::rtp_port_end.

Referenced by rtp_allocate_transport().

◆ ast_rtp_instance_get_port_start()

unsigned int ast_rtp_instance_get_port_start ( struct ast_rtp_instance instance)

Get the per-instance RTP port range start.

Parameters
instanceThe RTP instance
Returns
port start value (0 means use global setting)
Since
20.20.0
22.10.0
23.4.0

Definition at line 2945 of file rtp_engine.c.

2946{
2947 return instance->rtp_port_start;
2948}
unsigned int rtp_port_start
Definition rtp_engine.c:236

References ast_rtp_instance::rtp_port_start.

Referenced by rtp_allocate_transport().

◆ 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:767
@ AST_RTP_PROPERTY_NAT
Definition rtp_engine.h:118

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

Since
1.8

Definition at line 767 of file rtp_engine.c.

768{
769 int prop;
770
771 ao2_lock(instance);
772 prop = instance->properties[property];
773 ao2_unlock(instance);
774
775 return prop;
776}
int properties[AST_RTP_PROPERTY_MAX]
Definition rtp_engine.c:200

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:176
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:173
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.

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

Since
1.8

Definition at line 2679 of file rtp_engine.c.

2680{
2681 struct ast_rtp_instance_stats stats = { 0, };
2682 enum ast_rtp_instance_stat stat;
2683
2684 /* Determine what statistics we will need to retrieve based on field passed in */
2687 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
2689 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
2691 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
2693 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES) {
2695 } else {
2696 return NULL;
2697 }
2698
2699 /* Attempt to actually retrieve the statistics we need to generate the quality string */
2700 if (ast_rtp_instance_get_stats(instance, &stats, stat)) {
2701 return NULL;
2702 }
2703
2704 /* Now actually fill the buffer with the good information */
2706 snprintf(buf, size, "ssrc=%u;themssrc=%u;lp=%u;rxjitter=%f;rxcount=%u;"
2707 "txjitter=%f;txcount=%u;rlp=%u;rtt=%f;rxmes=%f;txmes=%f",
2708 stats.local_ssrc, stats.remote_ssrc, stats.rxploss, stats.rxjitter,
2709 stats.rxcount, stats.txjitter, stats.txcount, stats.txploss, stats.rtt,
2710 stats.rxmes, stats.txmes);
2711 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
2712 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;",
2714 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
2715 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;",
2717 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
2718 snprintf(buf, size, " minrtt=%010.6f; maxrtt=%010.6f; avgrtt=%010.6f; stdevrtt=%010.6f;", stats.minrtt, stats.maxrtt, stats.normdevrtt, stats.stdevrtt);
2719 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES) {
2720 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;",
2721 stats.local_minmes, stats.local_maxmes,
2722 stats.local_normdevmes, stats.local_stdevmes,
2723 stats.remote_minmes, stats.remote_maxmes,
2724 stats.remote_normdevmes, stats.remote_stdevmes);
2725 }
2726
2727 return buf;
2728}
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.
ast_rtp_instance_stat
Definition rtp_engine.h:185
@ AST_RTP_INSTANCE_STAT_COMBINED_MES
Definition rtp_engine.h:260
@ AST_RTP_INSTANCE_STAT_COMBINED_JITTER
Definition rtp_engine.h:215
@ AST_RTP_INSTANCE_STAT_COMBINED_LOSS
Definition rtp_engine.h:193
@ AST_RTP_INSTANCE_STAT_COMBINED_RTT
Definition rtp_engine.h:237
@ AST_RTP_INSTANCE_STAT_ALL
Definition rtp_engine.h:187

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(), 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 724 of file rtp_engine.c.

726{
727 ao2_lock(instance);
729 ao2_unlock(instance);
730}

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

Referenced by ast_rtp_read().

◆ ast_rtp_instance_get_srtp()

struct ast_srtp * ast_rtp_instance_get_srtp ( struct ast_rtp_instance instance,
int  rtcp 
)

Obtain the SRTP instance associated with an RTP instance.

Parameters
instancethe RTP instance
rtcp1 to request instance for RTCP
Returns
the SRTP instance on success
Return values
NULLif no SRTP instance exists

Definition at line 3018 of file rtp_engine.c.

3019{
3020 if (rtcp && instance->rtcp_srtp) {
3021 return instance->rtcp_srtp;
3022 } else {
3023 return instance->srtp;
3024 }
3025}

References ast_rtp_instance::rtcp_srtp, and ast_rtp_instance::srtp.

Referenced by __rtp_sendto(), ast_rtcp_read(), ast_rtp_change_source(), and ast_rtp_read().

◆ ast_rtp_instance_get_ssrc()

unsigned int ast_rtp_instance_get_ssrc ( struct ast_rtp_instance rtp)

Retrieve the local SSRC value that we will be using.

Parameters
rtpThe RTP instance
Returns
The SSRC value

Definition at line 4066 of file rtp_engine.c.

4067{
4068 unsigned int ssrc = 0;
4069
4070 ao2_lock(rtp);
4071 if (rtp->engine->ssrc_get) {
4072 ssrc = rtp->engine->ssrc_get(rtp);
4073 }
4074 ao2_unlock(rtp);
4075
4076 return ssrc;
4077}
unsigned int(* ssrc_get)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:732

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

Referenced by add_ssrc_to_stream(), ast_srtp_unprotect(), and create_outgoing_sdp_stream().

◆ ast_rtp_instance_get_stats()

int ast_rtp_instance_get_stats ( struct ast_rtp_instance instance,
struct ast_rtp_instance_stats stats,
enum ast_rtp_instance_stat  stat 
)

Retrieve statistics about an RTP instance.

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

Example usage:

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.

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

Since
1.8

Definition at line 2661 of file rtp_engine.c.

2662{
2663 int res;
2664
2665 if (!instance || !instance->engine || !stats) {
2666 return -1;
2667 }
2668
2669 if (instance->engine->get_stat) {
2670 ao2_lock(instance);
2671 res = instance->engine->get_stat(instance, stats, stat);
2672 ao2_unlock(instance);
2673 } else {
2674 res = -1;
2675 }
2676 return res;
2677}
int(* get_stat)(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
Definition rtp_engine.h:702

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

Referenced by ast_rtp_instance_get_quality(), ast_rtp_instance_get_stats_all_json(), ast_sip_session_media_stats_save(), ast_srtp_unprotect(), AST_TEST_DEFINE(), channel_read_rtcp(), cli_channelstats_print_body(), crypto_activate(), and process_ssrc_attributes().

◆ ast_rtp_instance_get_stats_all_json()

struct ast_json * ast_rtp_instance_get_stats_all_json ( struct ast_rtp_instance instance)

Retrieve statistics about an RTP instance in json format.

Parameters
instance
Returns
json object of stats

Definition at line 4320 of file rtp_engine.c.

4321{
4322 struct ast_rtp_instance_stats stats = {0,};
4323
4325 return NULL;
4326 }
4327
4328 return ast_rtp_convert_stats_json(&stats);
4329}
struct ast_json * ast_rtp_convert_stats_json(const struct ast_rtp_instance_stats *stats)
Convert given stat instance into json format.

References ast_rtp_convert_stats_json(), ast_rtp_instance_get_stats(), AST_RTP_INSTANCE_STAT_ALL, and NULL.

Referenced by ast_ari_channels_rtpstatistics().

◆ ast_rtp_instance_get_timeout()

int ast_rtp_instance_get_timeout ( struct ast_rtp_instance instance)

Get the RTP timeout value.

Parameters
instanceThe RTP instance
Returns
timeout value

Example usage:

int timeout = ast_rtp_instance_get_timeout(instance);
int ast_rtp_instance_get_timeout(struct ast_rtp_instance *instance)
Get the RTP timeout value.

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

Since
1.8

Definition at line 2930 of file rtp_engine.c.

2931{
2932 return instance->timeout;
2933}

References ast_rtp_instance::timeout.

Referenced by apply_negotiated_sdp_stream(), and rtp_check_timeout().

◆ ast_rtp_instance_make_compatible()

int ast_rtp_instance_make_compatible ( struct ast_channel chan,
struct ast_rtp_instance instance,
struct ast_channel peer 
)

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

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

Example usage:

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.

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

Since
1.8

Definition at line 2834 of file rtp_engine.c.

2835{
2836 struct ast_rtp_glue *glue;
2837 struct ast_rtp_instance *peer_instance = NULL;
2838 int res = -1;
2839
2840 if (!instance->engine->make_compatible) {
2841 return -1;
2842 }
2843
2844 ast_channel_lock(peer);
2845
2847 ast_channel_unlock(peer);
2848 return -1;
2849 }
2850
2851 glue->get_rtp_info(peer, &peer_instance);
2852 if (!peer_instance) {
2853 ast_log(LOG_ERROR, "Unable to get_rtp_info for peer type %s\n", glue->type);
2854 ast_channel_unlock(peer);
2855 return -1;
2856 }
2857 if (peer_instance->engine != instance->engine) {
2858 ast_log(LOG_ERROR, "Peer engine mismatch for type %s\n", glue->type);
2859 ast_channel_unlock(peer);
2860 ao2_ref(peer_instance, -1);
2861 return -1;
2862 }
2863
2864 /*
2865 * XXX Good thing nothing calls this function because we would need
2866 * deadlock avoidance to get the two instance locks.
2867 */
2868 res = instance->engine->make_compatible(chan, instance, peer, peer_instance);
2869
2870 ast_channel_unlock(peer);
2871
2872 ao2_ref(peer_instance, -1);
2873 peer_instance = NULL;
2874
2875 return res;
2876}
#define ast_channel_lock(chan)
Definition channel.h:2989
int(* make_compatible)(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1)
Definition rtp_engine.h:720

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

◆ ast_rtp_instance_new()

struct ast_rtp_instance * ast_rtp_instance_new ( const char *  engine_name,
struct ast_sched_context sched,
const struct ast_sockaddr sa,
void *  data 
)

Create a new RTP instance.

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

Example usage:

struct ast_rtp_instance *instance = NULL;
instance = ast_rtp_instance_new(NULL, sched, &sin, NULL);
struct ast_rtp_instance * ast_rtp_instance_new(const char *engine_name, struct ast_sched_context *sched, const struct ast_sockaddr *sa, void *data)
Create a new RTP instance.
Definition rtp_engine.c:497
Definition sched.c:76

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

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

Definition at line 497 of file rtp_engine.c.

500{
502 engine_name, sched, sa, data, NULL);
503}
struct ast_rtp_instance * ast_rtp_instance_new_with_options(const char *engine_name, struct ast_sched_context *sched, const struct ast_sockaddr *sa, void *data, const struct ast_rtp_instance_options *options)
Create a new RTP instance with additional options.
Definition rtp_engine.c:505

References ast_rtp_instance_new_with_options(), ast_rtp_instance::data, and NULL.

Referenced by configure_local_rtp(), create_rtp(), jingle_alloc(), jingle_enable_video(), multicast_rtp_request(), start_rtp(), test_init_rtp_instances(), and unicast_rtp_request().

◆ ast_rtp_instance_new_with_options()

struct ast_rtp_instance * ast_rtp_instance_new_with_options ( const char *  engine_name,
struct ast_sched_context sched,
const struct ast_sockaddr sa,
void *  data,
const struct ast_rtp_instance_options options 
)

Create a new RTP instance with additional options.

Parameters
engine_nameName of the engine to use for the RTP instance
schedScheduler context that the RTP engine may want to use
saAddress we want to bind to
dataUnique data for the engine
optionsPointer to options struct, or NULL to use defaults
Return values
non-NULLsuccess
NULLfailure

Example usage:

struct ast_rtp_instance_options options = { .port_start = 15000, .port_end = 15010 };
struct ast_rtp_instance *instance = NULL;
struct ast_rtp_instance * ast_rtp_instance_new_with_options(const char *engine_name, struct ast_sched_context *sched, const struct ast_sockaddr *sa, void *data, const struct ast_rtp_instance_options *options)
Create a new RTP instance with additional options.
Definition rtp_engine.c:505
Options for creating a new RTP instance.
Definition rtp_engine.h:994

This creates a new RTP instance using the specified options. When a per-instance port range is provided the global rtp.conf range is ignored. If options is NULL or port values are both 0 the global range is used.

Note
The per-instance port range overrides the global rtp.conf settings for this specific RTP instance only. It does not need to be a subset of the global range.
Since
20.20.0
22.10.0
23.4.0

Definition at line 505 of file rtp_engine.c.

508{
509 struct ast_sockaddr address = {{0,}};
510 struct ast_rtp_instance *instance = NULL;
511 struct ast_rtp_engine *engine = NULL;
512 struct ast_module *mod_ref;
513 unsigned int port_start = options ? options->port_start : 0;
514 unsigned int port_end = options ? options->port_end : 0;
515
517
518 /* If an engine name was specified try to use it or otherwise use the first one registered */
519 if (!ast_strlen_zero(engine_name)) {
521 if (!strcmp(engine->name, engine_name)) {
522 break;
523 }
524 }
525 } else {
526 engine = AST_RWLIST_FIRST(&engines);
527 }
528
529 /* If no engine was actually found bail out now */
530 if (!engine) {
531 ast_log(LOG_ERROR, "No RTP engine was found. Do you have one loaded?\n");
533 return NULL;
534 }
535
536 /* Bump up the reference count before we return so the module can not be unloaded */
537 mod_ref = ast_module_running_ref(engine->mod);
538
540
541 if (!mod_ref) {
542 /* BUGBUG: improve handling of this situation. */
543 return NULL;
544 }
545
546 /* Allocate a new RTP instance */
547 if (!(instance = ao2_alloc(sizeof(*instance), instance_destructor))) {
548 ast_module_unref(engine->mod);
549 return NULL;
550 }
551 instance->engine = engine;
552 ast_sockaddr_copy(&instance->local_address, sa);
554
555 /* Set the per-instance port range before the engine allocates the transport */
556 instance->rtp_port_start = port_start;
557 instance->rtp_port_end = port_end;
558
560 ao2_ref(instance, -1);
561 return NULL;
562 }
563
564 /* Initialize RTP extension support */
565 if (AST_VECTOR_INIT(&instance->extmap_enabled, 0) ||
566 AST_VECTOR_INIT(&instance->extmap_negotiated, 0) ||
567 AST_VECTOR_INIT(&instance->extmap_unique_ids, 0)) {
568 ao2_ref(instance, -1);
569 return NULL;
570 }
571
572 if (port_start && port_end) {
573 ast_debug(1, "Using engine '%s' for RTP instance '%p' with port range %d-%d\n",
574 engine->name, instance, port_start, port_end);
575 } else {
576 ast_debug(1, "Using engine '%s' for RTP instance '%p'\n", engine->name, instance);
577 }
578
579 /*
580 * And pass it off to the engine to setup
581 *
582 * Lock in case the RTP engine has other threads that
583 * need synchronization with the construction.
584 */
585 ao2_lock(instance);
586 if (instance->engine->new(instance, sched, &address, data)) {
587 ast_debug(1, "Engine '%s' failed to setup RTP instance '%p'\n", engine->name, instance);
588 ao2_unlock(instance);
589 ao2_ref(instance, -1);
590 return NULL;
591 }
592 ao2_unlock(instance);
593
594 ast_debug(1, "RTP instance '%p' is setup and ready to go\n", instance);
595
596 return instance;
597}
#define ao2_alloc(data_size, destructor_fn)
Definition astobj2.h:409
#define AST_RWLIST_FIRST
#define ast_module_unref(mod)
Release a reference to the module.
Definition module.h:483
#define ast_module_running_ref(mod)
Hold a reference to the module if it is running.
Definition module.h:469
static void instance_destructor(void *obj)
Definition rtp_engine.c:433
struct ast_module::@387 entry

References ao2_alloc, ao2_lock, ao2_ref, ao2_unlock, ast_debug, ast_log, ast_module_running_ref, ast_module_unref, ast_rtp_codecs_payloads_initialize(), AST_RWLIST_FIRST, AST_RWLIST_RDLOCK, AST_RWLIST_TRAVERSE, AST_RWLIST_UNLOCK, ast_sockaddr_copy(), ast_strlen_zero(), AST_VECTOR_INIT, ast_rtp_instance::codecs, ast_rtp_instance::engine, ast_module::entry, ast_rtp_instance::extmap_enabled, ast_rtp_instance::extmap_negotiated, ast_rtp_instance::extmap_unique_ids, instance_destructor(), ast_rtp_instance::local_address, LOG_ERROR, ast_rtp_engine::mod, ast_rtp_engine::name, ast_rtp_engine::new, NULL, options, ast_rtp_instance::rtp_port_end, and ast_rtp_instance::rtp_port_start.

Referenced by ast_rtp_instance_new(), and create_rtp().

◆ ast_rtp_instance_read()

struct ast_frame * ast_rtp_instance_read ( struct ast_rtp_instance instance,
int  rtcp 
)

Receive a frame over RTP.

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

Example usage:

struct ast_frame *frame;
frame = ast_rtp_instance_read(instance, 0);
struct ast_frame * ast_rtp_instance_read(struct ast_rtp_instance *instance, int rtcp)
Receive a frame over RTP.
Definition rtp_engine.c:629
Data structure associated with a single frame of data.

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

Since
1.8

Definition at line 629 of file rtp_engine.c.

630{
631 struct ast_frame *frame;
632
633 ao2_lock(instance);
634 frame = instance->engine->read(instance, rtcp);
635 ao2_unlock(instance);
636 return frame;
637}

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

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), AST_TEST_DEFINE(), jingle_read(), media_session_rtcp_read_callback(), media_session_rtp_read_callback(), ooh323_rtp_read(), rtp_read(), test_read_frames(), test_write_and_read_interleaved_frames(), and unistim_rtp_read().

◆ ast_rtp_instance_sendcng()

int ast_rtp_instance_sendcng ( struct ast_rtp_instance instance,
int  level 
)

Send a comfort noise packet to the RTP instance.

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

Definition at line 3027 of file rtp_engine.c.

3028{
3029 int res;
3030
3031 if (instance->engine->sendcng) {
3032 ao2_lock(instance);
3033 res = instance->engine->sendcng(instance, level);
3034 ao2_unlock(instance);
3035 } else {
3036 res = -1;
3037 }
3038 return res;
3039}
int(* sendcng)(struct ast_rtp_instance *instance, int level)
Definition rtp_engine.h:730

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

Referenced by do_monitor(), and send_keepalive().

◆ ast_rtp_instance_set_bridged()

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.

Parameters
instanceThe RTP instance that we want to set the bridged value on
bridgedThe RTP instance they are bridged to
Since
12

Definition at line 2459 of file rtp_engine.c.

2460{
2461 ao2_lock(instance);
2462 instance->bridged = bridged;
2463 ao2_unlock(instance);
2464}

References ao2_lock, ao2_unlock, and ast_rtp_instance::bridged.

Referenced by native_rtp_bridge_start(), and native_rtp_bridge_stop().

◆ ast_rtp_instance_set_channel_id()

void ast_rtp_instance_set_channel_id ( struct ast_rtp_instance instance,
const char *  uniqueid 
)

Set the channel that owns this RTP instance.

Parameters
instanceThe RTP instance
uniqueidThe uniqueid of the channel
Since
12

Definition at line 604 of file rtp_engine.c.

605{
606 ast_copy_string(instance->channel_uniqueid, uniqueid, sizeof(instance->channel_uniqueid));
607}
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition strings.h:425

References ast_copy_string(), and ast_rtp_instance::channel_uniqueid.

Referenced by apply_negotiated_sdp_stream(), jingle_enable_video(), jingle_set_owner(), multicast_rtp_request(), set_channel_on_rtp_instance(), start_rtp(), test_init_rtp_instances(), unicast_rtp_request(), and unistim_set_owner().

◆ ast_rtp_instance_set_data()

void ast_rtp_instance_set_data ( struct ast_rtp_instance instance,
void *  data 
)

Set the data portion of an RTP instance.

Parameters
instanceThe RTP instance to manipulate
dataPointer to data

Example usage:

ast_rtp_instance_set_data(instance, blob);
void ast_rtp_instance_set_data(struct ast_rtp_instance *instance, void *data)
Set the data portion of an RTP instance.
Definition rtp_engine.c:609

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

Since
1.8

Definition at line 609 of file rtp_engine.c.

610{
611 instance->data = data;
612}

References ast_rtp_instance::data.

Referenced by ast_rtp_new(), and multicast_rtp_new().

◆ ast_rtp_instance_set_extended_prop()

void ast_rtp_instance_set_extended_prop ( struct ast_rtp_instance instance,
int  property,
void *  value 
)

Set the value of an RTP instance extended property.

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

Definition at line 732 of file rtp_engine.c.

733{
734 if (instance->engine->extended_prop_set) {
735 ao2_lock(instance);
736 instance->engine->extended_prop_set(instance, property, value);
737 ao2_unlock(instance);
738 }
739}
int(* extended_prop_set)(struct ast_rtp_instance *instance, int property, void *value)
Definition rtp_engine.h:688

References ao2_lock, ao2_unlock, ast_rtp_instance::engine, ast_rtp_engine::extended_prop_set, and value.

◆ ast_rtp_instance_set_hold_timeout()

void ast_rtp_instance_set_hold_timeout ( struct ast_rtp_instance instance,
int  timeout 
)

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

Parameters
instanceThe RTP instance
timeoutValue to set the timeout to

Example usage:

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.

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

Since
1.8

Definition at line 2920 of file rtp_engine.c.

2921{
2922 instance->holdtimeout = timeout;
2923}

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

◆ ast_rtp_instance_set_incoming_source_address()

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.

This sets the incoming source 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 RTP instance to change the address on
addressAddress to set it to
Return values
0success
-1failure

Definition at line 657 of file rtp_engine.c.

659{
660 ao2_lock(instance);
662 ao2_unlock(instance);
663
664 return 0;
665}
static void rtp_instance_set_incoming_source_address_nolock(struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
Definition rtp_engine.c:648

References ao2_lock, ao2_unlock, and rtp_instance_set_incoming_source_address_nolock().

Referenced by ast_rtp_read().

◆ ast_rtp_instance_set_keepalive()

void ast_rtp_instance_set_keepalive ( struct ast_rtp_instance instance,
int  timeout 
)

Set the RTP keepalive interval.

Parameters
instanceThe RTP instance
timeoutValue to set the keepalive interval to

Example usage:

void ast_rtp_instance_set_keepalive(struct ast_rtp_instance *instance, int timeout)
Set the RTP keepalive interval.

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

Since
1.8

Definition at line 2925 of file rtp_engine.c.

2926{
2927 instance->keepalive = interval;
2928}

References ast_rtp_instance::keepalive.

Referenced by apply_negotiated_sdp_stream().

◆ ast_rtp_instance_set_last_rx()

void ast_rtp_instance_set_last_rx ( struct ast_rtp_instance rtp,
time_t  time 
)

Set the last RTP reception time.

Parameters
rtpThe instance on which to set the last reception time
timeThe last reception time

Definition at line 4061 of file rtp_engine.c.

4062{
4063 rtp->last_rx = time;
4064}

References ast_rtp_instance::last_rx.

Referenced by create_rtp(), media_session_rtcp_read_callback(), media_session_rtp_read_callback(), and rtp_check_timeout().

◆ ast_rtp_instance_set_last_tx()

void ast_rtp_instance_set_last_tx ( struct ast_rtp_instance rtp,
time_t  time 
)

Set the last RTP transmission time.

Parameters
rtpThe instance on which to set the last transmission time
timeThe last transmission time

Definition at line 4051 of file rtp_engine.c.

4052{
4053 rtp->last_tx = time;
4054}

References ast_rtp_instance::last_tx.

Referenced by __rtp_sendto().

◆ ast_rtp_instance_set_local_address()

int ast_rtp_instance_set_local_address ( struct ast_rtp_instance instance,
const struct ast_sockaddr address 
)

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

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

Example usage:

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

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

Since
1.8

Definition at line 639 of file rtp_engine.c.

641{
642 ao2_lock(instance);
644 ao2_unlock(instance);
645 return 0;
646}

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

Referenced by ast_rtp_remote_address_set(), and rtp_allocate_transport().

◆ ast_rtp_instance_set_prop()

void ast_rtp_instance_set_prop ( struct ast_rtp_instance instance,
enum ast_rtp_property  property,
int  value 
)

Set the value of an RTP instance property.

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

Example usage:

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

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

Since
1.8

Definition at line 756 of file rtp_engine.c.

757{
758 ao2_lock(instance);
759 instance->properties[property] = value;
760
761 if (instance->engine->prop_set) {
762 instance->engine->prop_set(instance, property, value);
763 }
764 ao2_unlock(instance);
765}
void(* prop_set)(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value)
Definition rtp_engine.h:692

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

Referenced by check_for_rtp_changes(), configure_local_rtp(), create_rtp(), enable_rtcp(), get_codecs(), jingle_alloc(), jingle_enable_video(), pjsip_acf_dtmf_mode_write(), start_rtp(), and test_init_rtp_instances().

◆ ast_rtp_instance_set_qos()

int ast_rtp_instance_set_qos ( struct ast_rtp_instance instance,
int  tos,
int  cos,
const char *  desc 
)

Set QoS parameters on an RTP session.

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

Example usage:

ast_rtp_instance_set_qos(instance, 0, 0, "Example");
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.

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

Since
1.8

Definition at line 2384 of file rtp_engine.c.

2385{
2386 int res;
2387
2388 if (instance->engine->qos) {
2389 ao2_lock(instance);
2390 res = instance->engine->qos(instance, tos, cos, desc);
2391 ao2_unlock(instance);
2392 } else {
2393 res = -1;
2394 }
2395 return res;
2396}
static const char desc[]
Definition cdr_radius.c:84
unsigned int tos
Definition chan_iax2.c:392
unsigned int cos
Definition chan_iax2.c:393
int(* qos)(struct ast_rtp_instance *instance, int tos, int cos, const char *desc)
Definition rtp_engine.h:704

References ao2_lock, ao2_unlock, cos, desc, ast_rtp_instance::engine, ast_rtp_engine::qos, and tos.

Referenced by configure_local_rtp(), create_rtp(), and start_rtp().

◆ ast_rtp_instance_set_read_format()

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.

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

Example usage:

struct ast_format tmp_fmt;
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.

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

Since
1.8

Definition at line 2805 of file rtp_engine.c.

2806{
2807 int res;
2808
2809 if (instance->engine->set_read_format) {
2810 ao2_lock(instance);
2811 res = instance->engine->set_read_format(instance, format);
2812 ao2_unlock(instance);
2813 } else {
2814 res = -1;
2815 }
2816 return res;
2817}
int(* set_read_format)(struct ast_rtp_instance *instance, struct ast_format *format)
Definition rtp_engine.h:716

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

◆ ast_rtp_instance_set_remote_ssrc()

void ast_rtp_instance_set_remote_ssrc ( struct ast_rtp_instance rtp,
unsigned int  ssrc 
)

Set the remote SSRC for an RTP instance.

Since
15.0.0
Parameters
rtpThe RTP instance
ssrcThe remote SSRC

Definition at line 4109 of file rtp_engine.c.

4110{
4111 ao2_lock(rtp);
4112 if (rtp->engine->set_remote_ssrc) {
4113 rtp->engine->set_remote_ssrc(rtp, ssrc);
4114 }
4115 ao2_unlock(rtp);
4116}
void(* set_remote_ssrc)(struct ast_rtp_instance *instance, unsigned int ssrc)
Definition rtp_engine.h:738

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

Referenced by process_ssrc_attributes().

◆ ast_rtp_instance_set_requested_target_address()

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.

This should always be the address of the remote endpoint. Consequently, this can differ from the address the engine is sending RTP to. However, usually they will be the same except in some circumstances (for instance when the engine "learns" the address if symmetric RTP is enabled).

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

Definition at line 667 of file rtp_engine.c.

669{
670 ao2_lock(instance);
671
674
675 ao2_unlock(instance);
676
677 return 0;
678}

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

◆ ast_rtp_instance_set_stats_vars()

void ast_rtp_instance_set_stats_vars ( struct ast_channel chan,
struct ast_rtp_instance instance 
)

Set standard statistics from an RTP instance on a channel.

Parameters
chanChannel to set the statistics on
instanceThe RTP instance that statistics will be retrieved from
Warning
Absolutely NO channel locks should be held before calling this function. If this channel is in a bridge, ast_rtp_instance_set_stats_vars() will attempt to lock the bridge peer as well as this channel. This can cause a lock inversion if we already have this channel locked and another thread tries to set bridge variables on the peer because it will have locked the peer first, then this channel. For this reason, we must NOT have the channel locked when we call ast_rtp_instance_set_stats_vars().

Example usage:

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.

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

Since
1.8

Definition at line 2758 of file rtp_engine.c.

2759{
2760 char quality_buf[AST_MAX_USER_FIELD];
2761 char *value;
2762 struct ast_channel *bridge;
2763 struct varshead *chanvars = ast_channel_varshead(chan);
2764 struct varshead *bridgevars = NULL;
2765 int chanchanges = 0;
2766 int bridgechanges = 0;
2767
2768 bridge = ast_channel_bridge_peer(chan);
2769 if (bridge) {
2770 bridgevars = ast_channel_varshead(bridge);
2771 ast_channel_lock_both(chan, bridge);
2773 } else {
2774 ast_channel_lock(chan);
2775 }
2777
2779
2781
2783
2785
2787
2788 if (chanchanges) {
2790 } else {
2792 }
2793 ast_channel_unlock(chan);
2794 if (bridge) {
2795 if (bridgechanges) {
2797 } else {
2799 }
2800 ast_channel_unlock(bridge);
2801 ast_channel_unref(bridge);
2802 }
2803}
struct varshead * ast_channel_varshead(struct ast_channel *chan)
struct ast_channel * ast_channel_bridge_peer(struct ast_channel *chan)
Get the channel's bridge peer only if the bridge is two-party.
Definition channel.c:10674
struct ast_flags * ast_channel_flags(struct ast_channel *chan)
#define ast_channel_unref(c)
Decrease channel reference count.
Definition channel.h:3025
@ AST_FLAG_SNAPSHOT_STAGE
Definition channel.h:1070
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
#define SET_STATS_VAR_HELPER(var_prefix, field)
Main Channel structure associated with a channel.
struct ast_bridge * bridge
#define ast_clear_flag(p, flag)
Definition utils.h:78

References ast_channel_bridge_peer(), ast_channel_flags(), ast_channel_lock, ast_channel_lock_both, ast_channel_stage_snapshot(), ast_channel_stage_snapshot_done(), ast_channel_unlock, ast_channel_unref, ast_channel_varshead(), ast_clear_flag, AST_FLAG_SNAPSHOT_STAGE, AST_MAX_USER_FIELD, 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, ast_channel::bridge, NULL, SET_STATS_VAR_HELPER, and value.

Referenced by ast_softhangup(), chan_pjsip_session_end(), and hangup().

◆ ast_rtp_instance_set_stream_num()

void ast_rtp_instance_set_stream_num ( struct ast_rtp_instance instance,
int  stream_num 
)

Set the stream number for an RTP instance.

Since
15.0.0
Parameters
instanceThe RTP instance
stream_numThe stream identifier number

Definition at line 4118 of file rtp_engine.c.

4119{
4120 ao2_lock(rtp);
4121 if (rtp->engine->set_stream_num) {
4122 rtp->engine->set_stream_num(rtp, stream_num);
4123 }
4124 ao2_unlock(rtp);
4125}
void(* set_stream_num)(struct ast_rtp_instance *instance, int stream_num)
Definition rtp_engine.h:740

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

Referenced by apply_negotiated_sdp_stream().

◆ ast_rtp_instance_set_timeout()

void ast_rtp_instance_set_timeout ( struct ast_rtp_instance instance,
int  timeout 
)

Set the RTP timeout value.

Parameters
instanceThe RTP instance
timeoutValue to set the timeout to

Example usage:

void ast_rtp_instance_set_timeout(struct ast_rtp_instance *instance, int timeout)
Set the RTP timeout value.

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

Since
1.8

Definition at line 2915 of file rtp_engine.c.

2916{
2917 instance->timeout = timeout;
2918}

References ast_rtp_instance::timeout.

Referenced by apply_negotiated_sdp_stream(), and configure_local_rtp().

◆ ast_rtp_instance_set_write_format()

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.

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

Example usage:

struct ast_format tmp_fmt;
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.

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

Since
1.8

Definition at line 2819 of file rtp_engine.c.

2820{
2821 int res;
2822
2823 if (instance->engine->set_read_format) {
2824 ao2_lock(instance);
2825 res = instance->engine->set_write_format(instance, format);
2826 ao2_unlock(instance);
2827 } else {
2828 res = -1;
2829 }
2830 return res;
2831}
int(* set_write_format)(struct ast_rtp_instance *instance, struct ast_format *format)
Definition rtp_engine.h:718

References ao2_lock, ao2_unlock, ast_rtp_instance::engine, ast_rtp_engine::set_read_format, and ast_rtp_engine::set_write_format.

◆ ast_rtp_instance_stop()

void ast_rtp_instance_stop ( struct ast_rtp_instance instance)

Stop an RTP instance.

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

Example usage:

void ast_rtp_instance_stop(struct ast_rtp_instance *instance)
Stop an RTP instance.

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

Since
1.8

Definition at line 2398 of file rtp_engine.c.

2399{
2400 if (instance->engine->stop) {
2401 ao2_lock(instance);
2402 instance->engine->stop(instance);
2403 ao2_unlock(instance);
2404 }
2405}
void(* stop)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:677

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

Referenced by apply_negotiated_sdp_stream(), close_rtp_connection(), jingle_session_destructor(), ooh323_destroy(), stream_stop(), and unistim_hangup_clean().

◆ ast_rtp_instance_stun_request()

void ast_rtp_instance_stun_request ( struct ast_rtp_instance instance,
struct ast_sockaddr suggestion,
const char *  username 
)

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

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

Example usage:

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.

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

Since
1.8

Definition at line 2906 of file rtp_engine.c.

2909{
2910 if (instance->engine->stun_request) {
2911 instance->engine->stun_request(instance, suggestion, username);
2912 }
2913}
void(* stun_request)(struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username)
Definition rtp_engine.h:726

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

Referenced by jingle_interpret_google_transport().

◆ ast_rtp_instance_update_source()

void ast_rtp_instance_update_source ( struct ast_rtp_instance instance)

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

Parameters
instanceInstance that the new media source is feeding into

Example usage:

void ast_rtp_instance_update_source(struct ast_rtp_instance *instance)
Indicate that the RTP marker bit should be set on an RTP stream.

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

Since
1.8

Definition at line 2366 of file rtp_engine.c.

2367{
2368 if (instance->engine->update_source) {
2369 ao2_lock(instance);
2370 instance->engine->update_source(instance);
2371 ao2_unlock(instance);
2372 }
2373}
void(* update_source)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:684

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

Referenced by jingle_indicate(), and ooh323_indicate().

◆ ast_rtp_instance_write()

int ast_rtp_instance_write ( struct ast_rtp_instance instance,
struct ast_frame frame 
)

Send a frame out over RTP.

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

Example usage:

ast_rtp_instance_write(instance, frame);
int ast_rtp_instance_write(struct ast_rtp_instance *instance, struct ast_frame *frame)
Send a frame out over RTP.
Definition rtp_engine.c:619

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

Since
1.8

Definition at line 619 of file rtp_engine.c.

620{
621 int res;
622
623 ao2_lock(instance);
624 res = instance->engine->write(instance, frame);
625 ao2_unlock(instance);
626 return res;
627}

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

Referenced by AST_TEST_DEFINE(), AST_TEST_DEFINE(), chan_pjsip_indicate(), jingle_write(), media_session_rtp_write_callback(), ooh323_write(), rtp_write(), test_write_and_read_interleaved_frames(), test_write_frames(), and unistim_write().

◆ ast_rtp_lookup_mime_multiple2()

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.

Parameters
bufBuffer to put the mime output into
ast_format_capabilityAsterisk Formats we are looking up.
rtp_capabilityRTP codes that we are looking up
asterisk_formatNon-zero if the ast_format_capability structure is to be used, 0 if rtp_capability is to be used
optionsAdditional options that may change the result
Return values
non-NULLsuccess
NULLfailure

Example usage:

char buf[256] = "";
struct ast_format tmp_fmt;
struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
char *mime = ast_rtp_lookup_mime_multiple2(&buf, sizeof(buf), cap, 0, 1, 0);
ast_format_cap_destroy(cap);
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.

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

Since
1.8

Definition at line 2260 of file rtp_engine.c.

2261{
2262 int found = 0;
2263 const char *name;
2264 if (!buf) {
2265 return NULL;
2266 }
2267
2268
2269 if (asterisk_format) {
2270 int x;
2271 struct ast_format *tmp_fmt;
2272 for (x = 0; x < ast_format_cap_count(ast_format_capability); x++) {
2273 tmp_fmt = ast_format_cap_get_format(ast_format_capability, x);
2274 name = ast_rtp_lookup_mime_subtype2(asterisk_format, tmp_fmt, 0, options);
2275 ao2_ref(tmp_fmt, -1);
2276 ast_str_append(&buf, 0, "%s|", name);
2277 found = 1;
2278 }
2279 } else {
2280 int x;
2281 ast_str_append(&buf, 0, "0x%x (", (unsigned int) rtp_capability);
2282 for (x = 1; x <= AST_RTP_MAX; x <<= 1) {
2283 if (rtp_capability & x) {
2284 name = ast_rtp_lookup_mime_subtype2(asterisk_format, NULL, x, options);
2285 ast_str_append(&buf, 0, "%s|", name);
2286 found = 1;
2287 }
2288 }
2289 }
2290
2291 ast_str_append(&buf, 0, "%s", found ? ")" : "nothing)");
2292
2293 return ast_str_buffer(buf);
2294}
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.
#define AST_RTP_MAX
Definition rtp_engine.h:300
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition strings.h:1139
char *attribute_pure ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition strings.h:761

References ao2_ref, ast_format_cap_count(), ast_format_cap_get_format(), ast_rtp_lookup_mime_subtype2(), AST_RTP_MAX, ast_str_append(), ast_str_buffer(), ast_rtp_payload_type::asterisk_format, buf, name, NULL, and options.

◆ ast_rtp_lookup_mime_subtype2()

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.

Parameters
asterisk_formatNon-zero to look up using Asterisk format
formatAsterisk format to look up
codeRTP code to look up
optionsAdditional options that may change the result
Returns
Mime subtype success
Return values
NULLfailure

Example usage:

const char *subtype = ast_rtp_lookup_mime_subtype2(1, ast_format_ulaw, 0, 0);
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.

This looks up the mime subtype for the ULAW format.

Since
1.8

Definition at line 2207 of file rtp_engine.c.

2209{
2210 int i;
2211 const char *res = "";
2212
2214 for (i = 0; i < mime_types_len; i++) {
2215 if (ast_rtp_mime_types[i].payload_type.asterisk_format && asterisk_format && format &&
2216 (ast_format_cmp(format, ast_rtp_mime_types[i].payload_type.format) != AST_FORMAT_CMP_NOT_EQUAL)) {
2219 res = "G726-32";
2220 break;
2221 } else {
2222 res = ast_rtp_mime_types[i].subtype;
2223 break;
2224 }
2225 } else if (!ast_rtp_mime_types[i].payload_type.asterisk_format && !asterisk_format &&
2227
2228 res = ast_rtp_mime_types[i].subtype;
2229 break;
2230 }
2231 }
2233
2234 return res;
2235}
@ AST_FORMAT_CMP_NOT_EQUAL
Definition format.h:38

References ast_format_cmp(), AST_FORMAT_CMP_EQUAL, AST_FORMAT_CMP_NOT_EQUAL, ast_format_g726_aal2, ast_rtp_mime_types, AST_RTP_OPT_G726_NONSTANDARD, ast_rwlock_rdlock, ast_rwlock_unlock, ast_rtp_payload_type::asterisk_format, ast_rtp_payload_type::format, mime_types_len, mime_types_lock, options, ast_rtp_mime_type::payload_type, ast_rtp_payload_type::rtp_code, and ast_rtp_mime_type::subtype.

Referenced by ast_rtp_lookup_mime_multiple2(), generate_rtpmap_attr(), generate_rtpmap_attr2(), and jingle_add_payloads_to_description().

◆ ast_rtp_lookup_sample_rate2()

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.

Parameters
asterisk_formatTrue if the value in format is to be used.
formatAn asterisk format
codefrom AST_RTP list
Returns
the sample rate if the format was found, zero if it was not found
Since
1.8

Definition at line 2237 of file rtp_engine.c.

2239{
2240 unsigned int i;
2241 unsigned int res = 0;
2242
2244 for (i = 0; i < mime_types_len; ++i) {
2245 if (ast_rtp_mime_types[i].payload_type.asterisk_format && asterisk_format && format &&
2246 (ast_format_cmp(format, ast_rtp_mime_types[i].payload_type.format) != AST_FORMAT_CMP_NOT_EQUAL)) {
2248 break;
2249 } else if (!ast_rtp_mime_types[i].payload_type.asterisk_format && !asterisk_format &&
2252 break;
2253 }
2254 }
2256
2257 return res;
2258}

References ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, ast_rtp_mime_types, ast_rwlock_rdlock, ast_rwlock_unlock, ast_rtp_payload_type::asterisk_format, ast_rtp_payload_type::format, mime_types_len, mime_types_lock, ast_rtp_mime_type::payload_type, ast_rtp_payload_type::rtp_code, and ast_rtp_mime_type::sample_rate.

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

◆ ast_rtp_payload_mapping_tx_is_present()

int ast_rtp_payload_mapping_tx_is_present ( struct ast_rtp_codecs codecs,
const struct ast_rtp_payload_type to_match 
)

Determine if a type of payload is already present in mappings.

Since
18
Parameters
codecsCodecs to be checked for mappings.
to_matchPayload type object to compare against.
Note
It is assumed that codecs is not locked before calling.
Return values
0not found
1found

Definition at line 1249 of file rtp_engine.c.

1249 {
1250 int ret = 0;
1251 if (codecs && to_match) {
1252 ast_rwlock_rdlock(&codecs->codecs_lock);
1253 ret = payload_mapping_tx_is_present(codecs, to_match);
1254 ast_rwlock_unlock(&codecs->codecs_lock);
1255 }
1256 return ret;
1257}

References ast_rwlock_rdlock, ast_rwlock_unlock, codecs, and payload_mapping_tx_is_present().

Referenced by ast_rtp_dtmf_begin().

◆ ast_rtp_publish_rtcp_message()

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.

Since
12
Parameters
rtpThe rtp instance object
message_typeThe RTP message type to publish
reportThe RTCP report object to publish. This should be an ao2 ref counted object. This routine will increase the reference count of the object.
blobAdditional JSON objects to publish along with the RTCP information

Definition at line 3745 of file rtp_engine.c.

3749{
3750 RAII_VAR(struct rtcp_message_payload *, payload, NULL, ao2_cleanup);
3752
3753 if (!message_type) {
3754 return;
3755 }
3756
3757 payload = ao2_alloc(sizeof(*payload), rtcp_message_payload_dtor);
3758 if (!payload || !report) {
3759 return;
3760 }
3761
3762 if (!ast_strlen_zero(rtp->channel_uniqueid)) {
3763 payload->snapshot = ast_channel_snapshot_get_latest(rtp->channel_uniqueid);
3764 }
3765 if (blob) {
3766 payload->blob = blob;
3767 ast_json_ref(blob);
3768 }
3769 ao2_ref(report, +1);
3770 payload->report = report;
3771
3772 message = stasis_message_create(message_type, payload);
3773 if (!message) {
3774 return;
3775 }
3776
3778}
struct ast_channel_snapshot * ast_channel_snapshot_get_latest(const char *uniqueid)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object,...
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition json.c:67
struct stasis_topic * ast_rtp_topic(void)
Stasis Message Bus API topic for RTP and RTCP related messages
static void rtcp_message_payload_dtor(void *obj)
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
Definition stasis.c:1578
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition utils.h:981

References ao2_alloc, ao2_cleanup, ao2_ref, ast_channel_snapshot_get_latest(), ast_json_ref(), ast_rtp_topic(), ast_strlen_zero(), ast_rtp_instance::channel_uniqueid, NULL, RAII_VAR, rtcp_message_payload_dtor(), stasis_message_create(), and stasis_publish().

Referenced by ast_rtcp_calculate_sr_rr_statistics(), and ast_rtcp_interpret().

◆ ast_rtp_red_buffer()

int ast_rtp_red_buffer ( struct ast_rtp_instance instance,
struct ast_frame frame 
)

Buffer a frame in an RTP instance for RED.

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

Definition at line 2647 of file rtp_engine.c.

2648{
2649 int res;
2650
2651 if (instance->engine->red_buffer) {
2652 ao2_lock(instance);
2653 res = instance->engine->red_buffer(instance, frame);
2654 ao2_unlock(instance);
2655 } else {
2656 res = -1;
2657 }
2658 return res;
2659}
int(* red_buffer)(struct ast_rtp_instance *instance, struct ast_frame *frame)
Definition rtp_engine.h:710

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

◆ ast_rtp_red_init()

int ast_rtp_red_init ( struct ast_rtp_instance instance,
int  buffer_time,
int *  payloads,
int  generations 
)

Initialize RED support on an RTP instance.

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

Definition at line 2633 of file rtp_engine.c.

2634{
2635 int res;
2636
2637 if (instance->engine->red_init) {
2638 ao2_lock(instance);
2639 res = instance->engine->red_init(instance, buffer_time, payloads, generations);
2640 ao2_unlock(instance);
2641 } else {
2642 res = -1;
2643 }
2644 return res;
2645}
int(* red_init)(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations)
Definition rtp_engine.h:708

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

◆ ast_rtp_rtcp_report_alloc()

struct ast_rtp_rtcp_report * ast_rtp_rtcp_report_alloc ( unsigned int  report_blocks)

Allocate an ao2 ref counted instance of ast_rtp_rtcp_report.

Parameters
report_blocksThe number of report blocks to allocate
Returns
An ao2 ref counted ast_rtp_rtcp_report object on success
Return values
NULLon error

Definition at line 3734 of file rtp_engine.c.

3735{
3736 struct ast_rtp_rtcp_report *rtcp_report;
3737
3738 /* Size of object is sizeof the report + the number of report_blocks * sizeof pointer */
3739 rtcp_report = ao2_alloc((sizeof(*rtcp_report) + report_blocks * sizeof(struct ast_rtp_rtcp_report_block *)),
3741
3742 return rtcp_report;
3743}
static void rtp_rtcp_report_dtor(void *obj)
A report block within a SR/RR report.
Definition rtp_engine.h:346
An object that represents data sent during a SR/RR RTCP report.
Definition rtp_engine.h:361

References ao2_alloc, and rtp_rtcp_report_dtor().

Referenced by ast_rtcp_interpret(), ast_rtcp_write(), ast_rtp_read(), rtp_write_rtcp_fir(), and rtp_write_rtcp_psfb().

◆ ast_rtp_topic()

struct stasis_topic * ast_rtp_topic ( void  )

Stasis Message Bus API topic for RTP and RTCP related messages

Since
12
Returns
A Stasis Message Bus API topic

Definition at line 3791 of file rtp_engine.c.

3792{
3793 return rtp_topic;
3794}

References rtp_topic.

Referenced by ast_rtp_publish_rtcp_message(), load_module(), and manager_subscriptions_init().

◆ find_static_payload_type()

static int find_static_payload_type ( int  asterisk_format,
const struct ast_format format,
int  code 
)
static

Definition at line 1766 of file rtp_engine.c.

1767{
1768 int idx;
1769 int payload = -1;
1770
1771 if (!asterisk_format) {
1772 for (idx = 0; idx < AST_RTP_MAX_PT; ++idx) {
1773 if (static_RTP_PT[idx]
1774 && !static_RTP_PT[idx]->asterisk_format
1775 && static_RTP_PT[idx]->rtp_code == code) {
1776 payload = idx;
1777 break;
1778 }
1779 }
1780 } else if (format) {
1781 for (idx = 0; idx < AST_RTP_MAX_PT; ++idx) {
1782 if (static_RTP_PT[idx]
1783 && static_RTP_PT[idx]->asterisk_format
1784 && ast_format_cmp(format, static_RTP_PT[idx]->format)
1786 payload = idx;
1787 break;
1788 }
1789 }
1790 }
1791
1792 return payload;
1793}

References ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, AST_RTP_MAX_PT, ast_rtp_payload_type::asterisk_format, ast_rtp_payload_type::format, ast_rtp_payload_type::payload, ast_rtp_payload_type::rtp_code, and static_RTP_PT.

Referenced by ast_rtp_codecs_payload_code_tx_sample_rate(), and rtp_codecs_assign_payload_code_rx().

◆ find_unused_payload()

static int find_unused_payload ( const struct ast_rtp_codecs codecs)
static

Definition at line 1843 of file rtp_engine.c.

1844{
1845 int res;
1846
1847 /* find next available dynamic payload slot */
1850 if (res != -1) {
1851 return res;
1852 }
1853
1855 /*
1856 * We're using default values for some dynamic types. So if an unused
1857 * slot was not found try again, but this time ignore the default
1858 * values declared for dynamic types (except for 101 and 121) .
1859 */
1860 static struct ast_rtp_payload_type *ignore[AST_RTP_MAX_PT] = {0};
1861
1862 ignore[101] = static_RTP_PT[101];
1863 ignore[121] = static_RTP_PT[121];
1864
1867 if (res != -1) {
1868 return res;
1869 }
1870 }
1871
1872 /* http://www.iana.org/assignments/rtp-parameters
1873 * RFC 3551, Section 3: "[...] applications which need to define more
1874 * than 32 dynamic payload types MAY bind codes below 96, in which case
1875 * it is RECOMMENDED that unassigned payload type numbers be used
1876 * first". Updated by RFC 5761, Section 4: "[...] values in the range
1877 * 64-95 MUST NOT be used [to avoid conflicts with RTCP]". Summaries:
1878 * https://tools.ietf.org/html/draft-roach-mmusic-unified-plan#section-3.2.1.2
1879 * https://tools.ietf.org/html/draft-wu-avtcore-dynamic-pt-usage#section-3
1880 */
1884 if (res != -1) {
1885 return res;
1886 }
1887
1888 /* Yet, reusing mappings below AST_RTP_PT_LAST_STATIC (35) is not supported
1889 * in Asterisk because when Compact Headers are activated, no rtpmap is
1890 * send for those below 35. If you want to use 35 and below
1891 * A) do not use Compact Headers,
1892 * B) remove that code in res_pjsip, or
1893 * C) add a flag that this RTP Payload Type got reassigned dynamically
1894 * and requires a rtpmap even with Compact Headers enabled.
1895 */
1899 if (res != -1) {
1900 return res;
1901 }
1902
1905 20, static_RTP_PT);
1906}
unsigned int ast_option_rtpptdynamic
Definition options.c:90
ignore(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
static int find_unused_payload_in_range(const struct ast_rtp_codecs *codecs, int start, int end, struct ast_rtp_payload_type *ignore[])
#define AST_RTP_PT_LAST_REASSIGN
Definition rtp_engine.h:95
#define AST_RTP_PT_FIRST_DYNAMIC
Definition rtp_engine.h:92
#define MAX(a, b)
Definition utils.h:254

References ast_option_rtpptdynamic, ast_option_rtpusedynamic, AST_RTP_MAX_PT, AST_RTP_PT_FIRST_DYNAMIC, AST_RTP_PT_LAST_REASSIGN, AST_RTP_PT_LAST_STATIC, codecs, find_unused_payload_in_range(), MAX, and static_RTP_PT.

Referenced by add_static_payload(), and rtp_codecs_assign_payload_code_rx().

◆ find_unused_payload_in_range()

static int find_unused_payload_in_range ( const struct ast_rtp_codecs codecs,
int  start,
int  end,
struct ast_rtp_payload_type ignore[] 
)
static

Definition at line 1809 of file rtp_engine.c.

1811{
1812 int x;
1813
1814 for (x = start; x < end; ++x) {
1815 struct ast_rtp_payload_type *type;
1816
1817 if (ignore[x]) {
1818 continue;
1819 } else if (!codecs || x >= AST_VECTOR_SIZE(&codecs->payload_mapping_rx)) {
1820 return x;
1821 }
1822
1823 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, x);
1824 if (!type) {
1825 return x;
1826 }
1827 }
1828 return -1;
1829}
char * end
Definition eagi_proxy.c:73

References AST_VECTOR_GET, AST_VECTOR_SIZE, codecs, end, and type.

Referenced by find_unused_payload(), and rtp_codecs_assign_payload_code_rx().

◆ instance_destructor()

static void instance_destructor ( void *  obj)
static

Definition at line 433 of file rtp_engine.c.

434{
435 struct ast_rtp_instance *instance = obj;
436
437 /* Pass us off to the engine to destroy */
438 if (instance->data) {
439 /*
440 * Lock in case the RTP engine has other threads that
441 * need synchronization with the destruction.
442 */
443 ao2_lock(instance);
444 instance->engine->destroy(instance);
445 ao2_unlock(instance);
446 }
447
448 if (instance->srtp) {
449 res_srtp->destroy(instance->srtp);
450 }
451
452 if (instance->rtcp_srtp) {
453 res_srtp->destroy(instance->rtcp_srtp);
454 }
455
457
461
462 /* Drop our engine reference */
463 ast_module_unref(instance->engine->mod);
464
465 ast_debug(1, "Destroyed RTP instance '%p'\n", instance);
466}
void(* destroy)(struct ast_srtp *srtp)
Definition res_srtp.h:40

References ao2_lock, ao2_unlock, ast_debug, ast_module_unref, ast_rtp_codecs_payloads_destroy(), AST_VECTOR_FREE, ast_rtp_instance::codecs, ast_rtp_instance::data, ast_rtp_engine::destroy, ast_srtp_res::destroy, ast_rtp_instance::engine, ast_rtp_instance::extmap_enabled, ast_rtp_instance::extmap_negotiated, ast_rtp_instance::extmap_unique_ids, ast_rtp_engine::mod, res_srtp, ast_rtp_instance::rtcp_srtp, and ast_rtp_instance::srtp.

Referenced by ast_rtp_instance_new_with_options().

◆ payload_mapping_rx_clear_primary()

static void payload_mapping_rx_clear_primary ( struct ast_rtp_codecs codecs,
struct ast_rtp_payload_type to_match 
)
static

Definition at line 1074 of file rtp_engine.c.

1075{
1076 int idx;
1079 struct timeval now;
1080
1081 if (!to_match->primary_mapping) {
1082 return;
1083 }
1084
1085 now = ast_tvnow();
1086 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
1087 current = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
1088
1089 if (!current || current == to_match || !current->primary_mapping) {
1090 continue;
1091 }
1092 if (current->asterisk_format && to_match->asterisk_format) {
1093 if (ast_format_cmp(current->format, to_match->format) == AST_FORMAT_CMP_NOT_EQUAL) {
1094 continue;
1095 }
1096 } else if (!current->asterisk_format && !to_match->asterisk_format) {
1097 if (current->rtp_code != to_match->rtp_code) {
1098 continue;
1099 }
1100 } else {
1101 continue;
1102 }
1103
1104 /* Replace current with non-primary marked version */
1106 if (!new_type) {
1107 continue;
1108 }
1109 *new_type = *current;
1110 new_type->primary_mapping = 0;
1111 new_type->when_retired = now;
1112 ao2_bump(new_type->format);
1113 AST_VECTOR_REPLACE(&codecs->payload_mapping_rx, idx, new_type);
1114 ao2_ref(current, -1);
1115 }
1116}
size_t current
unsigned int primary_mapping
Definition rtp_engine.h:314
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition time.h:159

References ao2_bump, ao2_ref, ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, ast_rtp_engine_alloc_payload_type(), ast_tvnow(), AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, ast_rtp_payload_type::asterisk_format, codecs, current, ast_rtp_payload_type::format, ast_rtp_payload_type::primary_mapping, and ast_rtp_payload_type::rtp_code.

Referenced by rtp_codecs_payload_set_rx().

◆ payload_mapping_tx_is_present()

static int payload_mapping_tx_is_present ( const struct ast_rtp_codecs codecs,
const struct ast_rtp_payload_type to_match 
)
static

Definition at line 1211 of file rtp_engine.c.

1212{
1213 int idx;
1215
1216 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
1217 current = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
1218
1219 if (!current) {
1220 continue;
1221 }
1222 if (current == to_match) {
1223 /* The exact object is already in the mapping. */
1224 return 1;
1225 }
1226 if (current->asterisk_format && to_match->asterisk_format) {
1228 continue;
1229 } else if (current->payload == to_match->payload) {
1230 return 0;
1231 }
1232 } else if (!current->asterisk_format && !to_match->asterisk_format) {
1233 if (current->rtp_code != to_match->rtp_code) {
1234 continue;
1235 } else if (to_match->rtp_code == AST_RTP_DTMF && current->sample_rate != to_match->sample_rate) {
1236 /* it is possible for multiple DTMF types to exist with different sample rates */
1237 continue;
1238 }
1239 } else {
1240 continue;
1241 }
1242
1243 return 1;
1244 }
1245
1246 return 0;
1247}
unsigned int ast_format_get_codec_id(const struct ast_format *format)
Get the codec identifier associated with a format.
Definition format.c:329

References ast_format_get_codec_id(), AST_RTP_DTMF, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_payload_type::asterisk_format, codecs, current, ast_rtp_payload_type::format, ast_rtp_payload_type::payload, ast_rtp_payload_type::rtp_code, and ast_rtp_payload_type::sample_rate.

Referenced by ast_rtp_codecs_payload_replace_format(), ast_rtp_codecs_payloads_set_m_type(), ast_rtp_codecs_payloads_set_rtpmap_type_rate(), and ast_rtp_payload_mapping_tx_is_present().

◆ rtcp_message_payload_dtor()

static void rtcp_message_payload_dtor ( void *  obj)
static

Definition at line 3543 of file rtp_engine.c.

3544{
3545 struct rtcp_message_payload *payload = obj;
3546
3547 ao2_cleanup(payload->report);
3548 ao2_cleanup(payload->snapshot);
3549 ast_json_unref(payload->blob);
3550}
struct ast_rtp_rtcp_report * report
struct ast_channel_snapshot * snapshot
struct ast_json * blob

References ao2_cleanup, ast_json_unref(), rtcp_message_payload::blob, rtcp_message_payload::report, and rtcp_message_payload::snapshot.

Referenced by ast_rtp_publish_rtcp_message().

◆ rtcp_report_to_ami()

static struct ast_manager_event_blob * rtcp_report_to_ami ( struct stasis_message msg)
static

Definition at line 3552 of file rtp_engine.c.

3553{
3554 struct rtcp_message_payload *payload = stasis_message_data(msg);
3555 RAII_VAR(struct ast_str *, channel_string, NULL, ast_free);
3556 RAII_VAR(struct ast_str *, packet_string, ast_str_create(512), ast_free);
3557 unsigned int ssrc = payload->report->ssrc;
3558 unsigned int type = payload->report->type;
3559 unsigned int report_count = payload->report->reception_report_count;
3560 int i;
3561
3562 if (!packet_string) {
3563 return NULL;
3564 }
3565
3566 if (payload->snapshot) {
3567 channel_string = ast_manager_build_channel_state_string(payload->snapshot);
3568 if (!channel_string) {
3569 return NULL;
3570 }
3571 }
3572
3573 if (payload->blob) {
3574 /* Optional data */
3575 struct ast_json *to = ast_json_object_get(payload->blob, "to");
3576 struct ast_json *from = ast_json_object_get(payload->blob, "from");
3577 struct ast_json *rtt = ast_json_object_get(payload->blob, "rtt");
3578 struct ast_json *mes = ast_json_object_get(payload->blob, "mes");
3579 if (to) {
3580 ast_str_append(&packet_string, 0, "To: %s\r\n", ast_json_string_get(to));
3581 }
3582 if (from) {
3583 ast_str_append(&packet_string, 0, "From: %s\r\n", ast_json_string_get(from));
3584 }
3585 if (rtt) {
3586 ast_str_append(&packet_string, 0, "RTT: %4.4f\r\n", ast_json_real_get(rtt));
3587 }
3588 if (mes) {
3589 ast_str_append(&packet_string, 0, "MES: %4.1f\r\n", ast_json_real_get(mes));
3590 }
3591 }
3592
3593 ast_str_append(&packet_string, 0, "SSRC: 0x%.8x\r\n", ssrc);
3594 ast_str_append(&packet_string, 0, "PT: %u(%s)\r\n", type, type== AST_RTP_RTCP_SR ? "SR" : "RR");
3595 ast_str_append(&packet_string, 0, "ReportCount: %u\r\n", report_count);
3596 if (type == AST_RTP_RTCP_SR) {
3597 ast_str_append(&packet_string, 0, "SentNTP: %lu.%06lu\r\n",
3598 (unsigned long)payload->report->sender_information.ntp_timestamp.tv_sec,
3599 (unsigned long)payload->report->sender_information.ntp_timestamp.tv_usec);
3600 ast_str_append(&packet_string, 0, "SentRTP: %u\r\n",
3602 ast_str_append(&packet_string, 0, "SentPackets: %u\r\n",
3604 ast_str_append(&packet_string, 0, "SentOctets: %u\r\n",
3606 }
3607
3608 for (i = 0; i < report_count; i++) {
3609 RAII_VAR(struct ast_str *, report_string, NULL, ast_free);
3610
3611 if (!payload->report->report_block[i]) {
3612 break;
3613 }
3614
3615 report_string = ast_str_create(256);
3616 if (!report_string) {
3617 return NULL;
3618 }
3619
3620 ast_str_append(&report_string, 0, "Report%dSourceSSRC: 0x%.8x\r\n",
3621 i, payload->report->report_block[i]->source_ssrc);
3622 ast_str_append(&report_string, 0, "Report%dFractionLost: %d\r\n",
3623 i, payload->report->report_block[i]->lost_count.fraction);
3624 ast_str_append(&report_string, 0, "Report%dCumulativeLost: %u\r\n",
3625 i, payload->report->report_block[i]->lost_count.packets);
3626 ast_str_append(&report_string, 0, "Report%dHighestSequence: %u\r\n",
3627 i, payload->report->report_block[i]->highest_seq_no & 0xffff);
3628 ast_str_append(&report_string, 0, "Report%dSequenceNumberCycles: %u\r\n",
3629 i, payload->report->report_block[i]->highest_seq_no >> 16);
3630 ast_str_append(&report_string, 0, "Report%dIAJitter: %u\r\n",
3631 i, payload->report->report_block[i]->ia_jitter);
3632 ast_str_append(&report_string, 0, "Report%dLSR: %u\r\n",
3633 i, payload->report->report_block[i]->lsr);
3634 ast_str_append(&report_string, 0, "Report%dDLSR: %4.4f\r\n",
3635 i, ((double)payload->report->report_block[i]->dlsr) / 65536);
3636 ast_str_append(&packet_string, 0, "%s", ast_str_buffer(report_string));
3637 }
3638
3640 stasis_message_type(msg) == ast_rtp_rtcp_received_type() ? "RTCPReceived" : "RTCPSent",
3641 "%s%s",
3642 AS_OR(channel_string, ""),
3643 ast_str_buffer(packet_string));
3644}
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition json.c:283
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition json.c:407
double ast_json_real_get(const struct ast_json *real)
Get the value from a JSON real number.
Definition json.c:347
#define EVENT_FLAG_REPORTING
Definition manager.h:84
struct ast_str * ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
Generate the AMI message body from a channel snapshot.
struct ast_manager_event_blob * ast_manager_event_blob_create(int event_flags, const char *manager_event, const char *extra_fields_fmt,...)
Construct a ast_manager_event_blob.
Definition manager.c:10198
#define AST_RTP_RTCP_SR
Definition rtp_engine.h:323
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition strings.h:659
#define AS_OR(a, b)
Definition strings.h:49
unsigned int highest_seq_no
Definition rtp_engine.h:352
unsigned short fraction
Definition rtp_engine.h:349
struct ast_rtp_rtcp_report_block::@287 lost_count
struct ast_rtp_rtcp_report::@288 sender_information
unsigned int type
Definition rtp_engine.h:364
unsigned short reception_report_count
Definition rtp_engine.h:362
unsigned int rtp_timestamp
Definition rtp_engine.h:367
struct ast_rtp_rtcp_report_block * report_block[0]
Definition rtp_engine.h:374
struct timeval ntp_timestamp
Definition rtp_engine.h:366
unsigned int octet_count
Definition rtp_engine.h:369
unsigned int ssrc
Definition rtp_engine.h:363
unsigned int packet_count
Definition rtp_engine.h:368
Support for dynamic strings.
Definition strings.h:623

References AS_OR, ast_free, ast_json_object_get(), ast_json_real_get(), ast_json_string_get(), ast_manager_build_channel_state_string(), ast_manager_event_blob_create(), ast_rtp_rtcp_received_type(), AST_RTP_RTCP_SR, ast_str_append(), ast_str_buffer(), ast_str_create, rtcp_message_payload::blob, ast_rtp_rtcp_report_block::dlsr, EVENT_FLAG_REPORTING, ast_rtp_rtcp_report_block::fraction, ast_rtp_rtcp_report_block::highest_seq_no, ast_rtp_rtcp_report_block::ia_jitter, ast_rtp_rtcp_report_block::lost_count, ast_rtp_rtcp_report_block::lsr, ast_rtp_rtcp_report::ntp_timestamp, NULL, ast_rtp_rtcp_report::octet_count, ast_rtp_rtcp_report::packet_count, ast_rtp_rtcp_report_block::packets, RAII_VAR, ast_rtp_rtcp_report::reception_report_count, rtcp_message_payload::report, ast_rtp_rtcp_report::report_block, ast_rtp_rtcp_report::rtp_timestamp, ast_rtp_rtcp_report::sender_information, rtcp_message_payload::snapshot, ast_rtp_rtcp_report_block::source_ssrc, ast_rtp_rtcp_report::ssrc, stasis_message_data(), type, and ast_rtp_rtcp_report::type.

◆ rtcp_report_to_json()

static struct ast_json * rtcp_report_to_json ( struct stasis_message msg,
const struct stasis_message_sanitizer sanitize 
)
static

Definition at line 3646 of file rtp_engine.c.

3648{
3649 struct rtcp_message_payload *payload = stasis_message_data(msg);
3650 struct ast_json *json_rtcp_report = NULL;
3651 struct ast_json *json_rtcp_report_blocks;
3652 struct ast_json *json_rtcp_sender_info = NULL;
3653 struct ast_json *json_channel = NULL;
3654 int i;
3655
3656 json_rtcp_report_blocks = ast_json_array_create();
3657 if (!json_rtcp_report_blocks) {
3658 return NULL;
3659 }
3660
3661 for (i = 0; i < payload->report->reception_report_count && payload->report->report_block[i]; i++) {
3662 struct ast_json *json_report_block;
3663 char str_lsr[32];
3664
3665 snprintf(str_lsr, sizeof(str_lsr), "%u", payload->report->report_block[i]->lsr);
3666 json_report_block = ast_json_pack("{s: I, s: I, s: I, s: I, s: I, s: s, s: I}",
3667 "source_ssrc", (ast_json_int_t)payload->report->report_block[i]->source_ssrc,
3668 "fraction_lost", (ast_json_int_t)payload->report->report_block[i]->lost_count.fraction,
3669 "packets_lost", (ast_json_int_t)payload->report->report_block[i]->lost_count.packets,
3670 "highest_seq_no", (ast_json_int_t)payload->report->report_block[i]->highest_seq_no,
3671 "ia_jitter", (ast_json_int_t)payload->report->report_block[i]->ia_jitter,
3672 "lsr", str_lsr,
3673 "dlsr", (ast_json_int_t)payload->report->report_block[i]->dlsr);
3674 if (!json_report_block
3675 || ast_json_array_append(json_rtcp_report_blocks, json_report_block)) {
3676 ast_json_unref(json_rtcp_report_blocks);
3677 return NULL;
3678 }
3679 }
3680
3681 if (payload->report->type == AST_RTP_RTCP_SR) {
3682 char sec[32];
3683 char usec[32];
3684
3685 snprintf(sec, sizeof(sec), "%lu", (unsigned long)payload->report->sender_information.ntp_timestamp.tv_sec);
3686 snprintf(usec, sizeof(usec), "%lu", (unsigned long)payload->report->sender_information.ntp_timestamp.tv_usec);
3687 json_rtcp_sender_info = ast_json_pack("{s: s, s: s, s: I, s: I, s: I}",
3688 "ntp_timestamp_sec", sec,
3689 "ntp_timestamp_usec", usec,
3690 "rtp_timestamp", (ast_json_int_t)payload->report->sender_information.rtp_timestamp,
3693 if (!json_rtcp_sender_info) {
3694 ast_json_unref(json_rtcp_report_blocks);
3695 return NULL;
3696 }
3697 }
3698
3699 json_rtcp_report = ast_json_pack("{s: I, s: I, s: i, s: o, s: o}",
3700 "ssrc", (ast_json_int_t)payload->report->ssrc,
3701 "type", (ast_json_int_t)payload->report->type,
3702 "report_count", payload->report->reception_report_count,
3703 "sender_information", json_rtcp_sender_info ?: ast_json_null(),
3704 "report_blocks", json_rtcp_report_blocks);
3705 if (!json_rtcp_report) {
3706 return NULL;
3707 }
3708
3709 if (payload->snapshot) {
3710 json_channel = ast_channel_snapshot_to_json(payload->snapshot, sanitize);
3711 if (!json_channel) {
3712 ast_json_unref(json_rtcp_report);
3713 return NULL;
3714 }
3715 }
3716
3717 return ast_json_pack("{s: s, s: o?, s: o, s: O?}",
3718 "type", stasis_message_type(msg) == ast_rtp_rtcp_received_type() ? "RTCPReceived" : "RTCPSent",
3719 "channel", json_channel,
3720 "rtcp_report", json_rtcp_report,
3721 "blob", payload->blob);
3722}
struct ast_json * ast_json_null(void)
Get the JSON null value.
Definition json.c:248
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition json.c:378
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition json.c:612
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition json.c:362
AST_JSON_INT_T ast_json_int_t
Primarily used to cast when packing to an "I" type.
Definition json.h:87
struct ast_json * ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_channel_snapshot.

References ast_channel_snapshot_to_json(), ast_json_array_append(), ast_json_array_create(), ast_json_null(), ast_json_pack(), ast_json_unref(), ast_rtp_rtcp_received_type(), AST_RTP_RTCP_SR, rtcp_message_payload::blob, ast_rtp_rtcp_report_block::dlsr, ast_rtp_rtcp_report_block::fraction, ast_rtp_rtcp_report_block::highest_seq_no, ast_rtp_rtcp_report_block::ia_jitter, ast_rtp_rtcp_report_block::lost_count, ast_rtp_rtcp_report_block::lsr, ast_rtp_rtcp_report::ntp_timestamp, NULL, ast_rtp_rtcp_report::octet_count, ast_rtp_rtcp_report::packet_count, ast_rtp_rtcp_report_block::packets, ast_rtp_rtcp_report::reception_report_count, rtcp_message_payload::report, ast_rtp_rtcp_report::report_block, ast_rtp_rtcp_report::rtp_timestamp, ast_rtp_rtcp_report::sender_information, rtcp_message_payload::snapshot, ast_rtp_rtcp_report_block::source_ssrc, ast_rtp_rtcp_report::ssrc, stasis_message_data(), and ast_rtp_rtcp_report::type.

◆ rtp_codecs_assign_payload_code_rx()

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

Definition at line 1957 of file rtp_engine.c.

1958{
1959 int payload = code, i;
1961 static struct ast_rtp_payload_type *ignore[AST_RTP_MAX_PT] = {0};
1962
1963 if (!explicit) {
1965
1967 return payload;
1968 }
1969 }
1970
1972 if (!new_type) {
1973 return -1;
1974 }
1975
1976 ast_rwlock_wrlock(&codecs->codecs_lock);
1977
1978 /* Go through the existing mapping to create an ignore list. */
1979 for (i = 0; i < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); i++) {
1980 if (AST_VECTOR_GET(&codecs->payload_mapping_rx, i)) {
1981 ignore[i] = static_RTP_PT[i];
1982 }
1983 }
1984
1985
1987 || AST_VECTOR_SIZE(&codecs->payload_mapping_rx) <= payload
1988 || !AST_VECTOR_GET(&codecs->payload_mapping_rx, payload))) {
1989
1990 /*
1991 * The payload type is a static assignment
1992 * or our default dynamic position is available.
1993 */
1995 } else if (payload > -1 && !explicit
1996 /* We can either call this with the full list or the current rx list. The former
1997 * (static_RTP_PT) results in payload types skipping statically 'used' slots so you
1998 * get 101, 113...
1999 * With the latter (the built ignore list) you get what's expected 101, 102, 103 under
2000 * most circumstances, but this results in static types being replaced. Probably fine
2001 * because we preclude the current list.
2002 */
2004 /*
2005 * Our dynamic position is currently in use.
2006 * Try for the numerically next free one before trying
2007 * across the full range. This keeps the payload id's
2008 * in the best numerical order we can through the free
2009 * types.
2010 */
2011 new_type->payload = payload;
2012 /*
2013 * In this case, consider this the primary mapping for
2014 * the payload type so don't clear it. Set not replace.
2015 */
2017 } else if (!explicit && (-1 < (payload = find_unused_payload(codecs))
2019 /*
2020 * We found the first available empty dynamic position
2021 * or we found a mapping that should no longer be
2022 * actively used.
2023 */
2024 new_type->payload = payload;
2026 } else if (explicit) {
2027 /*
2028 * They explicitly requested this payload number be used but it couldn't be
2029 */
2030 payload = -1;
2031 } else {
2032 /*
2033 * There are no empty or non-primary dynamic positions
2034 * left. Sadness.
2035 *
2036 * I don't think this is really possible.
2037 */
2038 ast_log(LOG_WARNING, "No dynamic RTP payload type values available "
2039 "for %s - %d!\n", format ? ast_format_get_name(format) : "", code);
2040 }
2041 ast_rwlock_unlock(&codecs->codecs_lock);
2042
2043 ao2_ref(new_type, -1);
2044
2045 return payload;
2046}
static int rtp_codecs_find_non_primary_dynamic_rx(struct ast_rtp_codecs *codecs)
static void rtp_codecs_payload_set_rx(struct ast_rtp_codecs *codecs, int payload, struct ast_rtp_payload_type *new_type, int replace)

References ao2_ref, ast_format_get_name(), ast_log, ast_option_rtpusedynamic, AST_RTP_MAX_PT, AST_RTP_PT_FIRST_DYNAMIC, ast_rwlock_unlock, ast_rwlock_wrlock, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_payload_type::asterisk_format, codecs, find_static_payload_type(), find_unused_payload(), find_unused_payload_in_range(), ast_rtp_payload_type::format, LOG_WARNING, ast_rtp_payload_type::payload, rtp_codecs_find_non_primary_dynamic_rx(), rtp_codecs_payload_replace_rx(), rtp_codecs_payload_set_rx(), rtp_payload_type_alloc(), ast_rtp_payload_type::sample_rate, and static_RTP_PT.

Referenced by ast_rtp_codecs_payload_code_sample_rate(), ast_rtp_codecs_payload_set_rx(), and ast_rtp_codecs_payload_set_rx_sample_rate().

◆ rtp_codecs_find_non_primary_dynamic_rx()

static int rtp_codecs_find_non_primary_dynamic_rx ( struct ast_rtp_codecs codecs)
static

Definition at line 1920 of file rtp_engine.c.

1921{
1922 struct ast_rtp_payload_type *type;
1923 struct timeval oldest;
1924 int idx;
1925 int payload = -1;
1926
1928 for (; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
1929 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
1930 if (type
1931 && !type->primary_mapping
1932 && (payload == -1
1933 || ast_tvdiff_ms(type->when_retired, oldest) < 0)) {
1934 oldest = type->when_retired;
1935 payload = idx;
1936 }
1937 }
1938 return payload;
1939}
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition time.h:107

References AST_RTP_PT_FIRST_DYNAMIC, ast_tvdiff_ms(), AST_VECTOR_GET, AST_VECTOR_SIZE, codecs, and type.

Referenced by rtp_codecs_assign_payload_code_rx().

◆ rtp_codecs_payload_replace_rx()

static void rtp_codecs_payload_replace_rx ( struct ast_rtp_codecs codecs,
int  payload,
struct ast_rtp_payload_type new_type 
)
static

Definition at line 1158 of file rtp_engine.c.

1158 {
1159 rtp_codecs_payload_set_rx(codecs, payload, new_type, 1);
1160}

References codecs, and rtp_codecs_payload_set_rx().

Referenced by ast_rtp_codecs_payloads_xover(), rtp_codecs_assign_payload_code_rx(), and rtp_codecs_payloads_copy_rx().

◆ rtp_codecs_payload_set_rx()

static void rtp_codecs_payload_set_rx ( struct ast_rtp_codecs codecs,
int  payload,
struct ast_rtp_payload_type new_type,
int  replace 
)
static

Definition at line 1130 of file rtp_engine.c.

1131{
1132 ao2_ref(new_type, +1);
1133 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_rx)) {
1134 ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_rx, payload),
1135 "cleaning up rx mapping vector element about to be replaced");
1136 }
1137 if (AST_VECTOR_REPLACE(&codecs->payload_mapping_rx, payload, new_type)) {
1138 ao2_ref(new_type, -1);
1139 return;
1140 }
1141
1142 if (replace) {
1144 }
1145}
static int replace(struct ast_channel *chan, const char *cmd, char *data, struct ast_str **buf, ssize_t len)
static void payload_mapping_rx_clear_primary(struct ast_rtp_codecs *codecs, struct ast_rtp_payload_type *to_match)

References ao2_ref, ao2_t_cleanup, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, codecs, payload_mapping_rx_clear_primary(), and replace().

Referenced by rtp_codecs_assign_payload_code_rx(), and rtp_codecs_payload_replace_rx().

◆ rtp_codecs_payloads_copy_rx()

static void rtp_codecs_payloads_copy_rx ( struct ast_rtp_codecs src,
struct ast_rtp_codecs dest,
struct ast_rtp_instance instance 
)
static

Definition at line 1175 of file rtp_engine.c.

1176{
1177 int idx;
1178 struct ast_rtp_payload_type *type;
1179
1180 for (idx = 0; idx < AST_VECTOR_SIZE(&src->payload_mapping_rx); ++idx) {
1182 if (!type) {
1183 continue;
1184 }
1185
1186 ast_debug(2, "Copying rx payload mapping %d (%p) from %p to %p\n",
1187 idx, type, src, dest);
1189
1190 if (instance && instance->engine && instance->engine->payload_set) {
1191 ao2_lock(instance);
1192 instance->engine->payload_set(instance, idx, type->asterisk_format, type->format, type->rtp_code);
1193 ao2_unlock(instance);
1194 }
1195 }
1196}
struct ast_rtp_codecs::@292 payload_mapping_rx

References ao2_lock, ao2_unlock, ast_debug, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_instance::engine, ast_rtp_codecs::payload_mapping_rx, ast_rtp_engine::payload_set, rtp_codecs_payload_replace_rx(), and type.

Referenced by ast_rtp_codecs_payloads_copy().

◆ rtp_codecs_payloads_copy_tx()

static void rtp_codecs_payloads_copy_tx ( struct ast_rtp_codecs src,
struct ast_rtp_codecs dest,
struct ast_rtp_instance instance 
)
static

Definition at line 1271 of file rtp_engine.c.

1272{
1273 int idx;
1274 struct ast_rtp_payload_type *type;
1275
1276 for (idx = 0; idx < AST_VECTOR_SIZE(&src->payload_mapping_tx); ++idx) {
1278 if (!type) {
1279 continue;
1280 }
1281
1282 ast_debug(2, "Copying tx payload mapping %d (%p) from %p to %p\n",
1283 idx, type, src, dest);
1284 ao2_ref(type, +1);
1285 if (idx < AST_VECTOR_SIZE(&dest->payload_mapping_tx)) {
1287 "cleaning up tx mapping vector element about to be replaced");
1288 }
1289 if (AST_VECTOR_REPLACE(&dest->payload_mapping_tx, idx, type)) {
1290 ao2_ref(type, -1);
1291 continue;
1292 }
1293
1294 if (instance && instance->engine && instance->engine->payload_set) {
1295 ao2_lock(instance);
1296 instance->engine->payload_set(instance, idx, type->asterisk_format, type->format, type->rtp_code);
1297 ao2_unlock(instance);
1298 }
1299 }
1300}

References ao2_lock, ao2_ref, ao2_t_cleanup, ao2_unlock, ast_debug, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, ast_rtp_instance::engine, ast_rtp_codecs::payload_mapping_tx, ast_rtp_engine::payload_set, and type.

Referenced by ast_rtp_codecs_payloads_copy().

◆ rtp_dtls_wrap_active()

static int rtp_dtls_wrap_active ( struct ast_rtp_instance instance)
static

Definition at line 3173 of file rtp_engine.c.

3174{
3175 int active;
3176
3177 ao2_lock(instance);
3178 active = instance->engine->dtls->active(instance);
3179 ao2_unlock(instance);
3180 return active;
3181}
int(* active)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:625

References ast_rtp_engine_dtls::active, ao2_lock, ao2_unlock, ast_rtp_engine::dtls, and ast_rtp_instance::engine.

◆ rtp_dtls_wrap_get_connection()

static enum ast_rtp_dtls_connection rtp_dtls_wrap_get_connection ( struct ast_rtp_instance instance)
static

Definition at line 3197 of file rtp_engine.c.

3198{
3199 enum ast_rtp_dtls_connection get_connection;
3200
3201 ao2_lock(instance);
3202 get_connection = instance->engine->dtls->get_connection(instance);
3203 ao2_unlock(instance);
3204 return get_connection;
3205}
ast_rtp_dtls_connection
DTLS connection states.
Definition rtp_engine.h:572
enum ast_rtp_dtls_connection(* get_connection)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:631

References ao2_lock, ao2_unlock, ast_rtp_engine::dtls, ast_rtp_instance::engine, and ast_rtp_engine_dtls::get_connection.

◆ rtp_dtls_wrap_get_fingerprint()

static const char * rtp_dtls_wrap_get_fingerprint ( struct ast_rtp_instance instance)
static

Definition at line 3243 of file rtp_engine.c.

3244{
3245 const char *get_fingerprint;
3246
3247 ao2_lock(instance);
3248 get_fingerprint = instance->engine->dtls->get_fingerprint(instance);
3249 ao2_unlock(instance);
3250 return get_fingerprint;
3251}
const char *(* get_fingerprint)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:641

References ao2_lock, ao2_unlock, ast_rtp_engine::dtls, ast_rtp_instance::engine, and ast_rtp_engine_dtls::get_fingerprint.

◆ rtp_dtls_wrap_get_fingerprint_hash()

static enum ast_rtp_dtls_hash rtp_dtls_wrap_get_fingerprint_hash ( struct ast_rtp_instance instance)
static

Definition at line 3233 of file rtp_engine.c.

3234{
3235 enum ast_rtp_dtls_hash get_fingerprint_hash;
3236
3237 ao2_lock(instance);
3238 get_fingerprint_hash = instance->engine->dtls->get_fingerprint_hash(instance);
3239 ao2_unlock(instance);
3240 return get_fingerprint_hash;
3241}
ast_rtp_dtls_hash
DTLS fingerprint hashes.
Definition rtp_engine.h:578
enum ast_rtp_dtls_hash(* get_fingerprint_hash)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:639

References ao2_lock, ao2_unlock, ast_rtp_engine::dtls, ast_rtp_instance::engine, and ast_rtp_engine_dtls::get_fingerprint_hash.

◆ rtp_dtls_wrap_get_setup()

static enum ast_rtp_dtls_setup rtp_dtls_wrap_get_setup ( struct ast_rtp_instance instance)
static

Definition at line 3207 of file rtp_engine.c.

3208{
3209 enum ast_rtp_dtls_setup get_setup;
3210
3211 ao2_lock(instance);
3212 get_setup = instance->engine->dtls->get_setup(instance);
3213 ao2_unlock(instance);
3214 return get_setup;
3215}
ast_rtp_dtls_setup
DTLS setup types.
Definition rtp_engine.h:564
enum ast_rtp_dtls_setup(* get_setup)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:633

References ao2_lock, ao2_unlock, ast_rtp_engine::dtls, ast_rtp_instance::engine, and ast_rtp_engine_dtls::get_setup.

◆ rtp_dtls_wrap_reset()

static void rtp_dtls_wrap_reset ( struct ast_rtp_instance instance)
static

Definition at line 3190 of file rtp_engine.c.

3191{
3192 ao2_lock(instance);
3193 instance->engine->dtls->reset(instance);
3194 ao2_unlock(instance);
3195}
void(* reset)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:629

References ao2_lock, ao2_unlock, ast_rtp_engine::dtls, ast_rtp_instance::engine, and ast_rtp_engine_dtls::reset.

◆ rtp_dtls_wrap_set_configuration()

static int rtp_dtls_wrap_set_configuration ( struct ast_rtp_instance instance,
const struct ast_rtp_dtls_cfg dtls_cfg 
)
static

Definition at line 3162 of file rtp_engine.c.

3164{
3165 int set_configuration;
3166
3167 ao2_lock(instance);
3168 set_configuration = instance->engine->dtls->set_configuration(instance, dtls_cfg);
3169 ao2_unlock(instance);
3170 return set_configuration;
3171}
int(* set_configuration)(struct ast_rtp_instance *instance, const struct ast_rtp_dtls_cfg *dtls_cfg)
Definition rtp_engine.h:623

References ao2_lock, ao2_unlock, ast_rtp_engine::dtls, ast_rtp_instance::engine, and ast_rtp_engine_dtls::set_configuration.

◆ rtp_dtls_wrap_set_fingerprint()

static void rtp_dtls_wrap_set_fingerprint ( struct ast_rtp_instance instance,
enum ast_rtp_dtls_hash  hash,
const char *  fingerprint 
)
static

Definition at line 3225 of file rtp_engine.c.

3227{
3228 ao2_lock(instance);
3229 instance->engine->dtls->set_fingerprint(instance, hash, fingerprint);
3230 ao2_unlock(instance);
3231}
void(* set_fingerprint)(struct ast_rtp_instance *instance, enum ast_rtp_dtls_hash hash, const char *fingerprint)
Definition rtp_engine.h:637

References ao2_lock, ao2_unlock, ast_rtp_engine::dtls, ast_rtp_instance::engine, and ast_rtp_engine_dtls::set_fingerprint.

◆ rtp_dtls_wrap_set_setup()

static void rtp_dtls_wrap_set_setup ( struct ast_rtp_instance instance,
enum ast_rtp_dtls_setup  setup 
)
static

Definition at line 3217 of file rtp_engine.c.

3219{
3220 ao2_lock(instance);
3221 instance->engine->dtls->set_setup(instance, setup);
3222 ao2_unlock(instance);
3223}
void(* set_setup)(struct ast_rtp_instance *instance, enum ast_rtp_dtls_setup setup)
Definition rtp_engine.h:635

References ao2_lock, ao2_unlock, ast_rtp_engine::dtls, ast_rtp_instance::engine, and ast_rtp_engine_dtls::set_setup.

◆ rtp_dtls_wrap_stop()

static void rtp_dtls_wrap_stop ( struct ast_rtp_instance instance)
static

Definition at line 3183 of file rtp_engine.c.

3184{
3185 ao2_lock(instance);
3186 instance->engine->dtls->stop(instance);
3187 ao2_unlock(instance);
3188}
void(* stop)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:627

References ao2_lock, ao2_unlock, ast_rtp_engine::dtls, ast_rtp_instance::engine, and ast_rtp_engine_dtls::stop.

◆ rtp_engine_atexit()

static void rtp_engine_atexit ( void  )
static

◆ rtp_engine_mime_type_cleanup()

static void rtp_engine_mime_type_cleanup ( int  i)
static

Definition at line 3404 of file rtp_engine.c.

3405{
3406 ao2_cleanup(ast_rtp_mime_types[i].payload_type.format);
3407 memset(&ast_rtp_mime_types[i], 0, sizeof(struct ast_rtp_mime_type));
3408}

References ao2_cleanup, and ast_rtp_mime_types.

Referenced by ast_rtp_engine_unload_format(), and rtp_engine_shutdown().

◆ rtp_engine_shutdown()

static void rtp_engine_shutdown ( void  )
static

◆ rtp_extmap_negotiate_direction()

static enum ast_rtp_extension_direction rtp_extmap_negotiate_direction ( enum ast_rtp_extension_direction  ours,
enum ast_rtp_extension_direction  theirs 
)
static

Helper function which negotiates two RTP extension directions to get our current direction.

Definition at line 841 of file rtp_engine.c.

843{
845 /* This should not occur but if it does tolerate either side not having this extension
846 * in use.
847 */
849 } else if (theirs == AST_RTP_EXTENSION_DIRECTION_INACTIVE) {
850 /* Inactive is always inactive on our side */
852 } else if (theirs == AST_RTP_EXTENSION_DIRECTION_SENDRECV) {
853 return ours;
854 } else if (theirs == AST_RTP_EXTENSION_DIRECTION_SENDONLY) {
855 /* If they are send only then we become recvonly if we are configured as sendrecv or recvonly */
858 }
859 } else if (theirs == AST_RTP_EXTENSION_DIRECTION_RECVONLY) {
860 /* If they are recv only then we become sendonly if we are configured as sendrecv or sendonly */
863 }
864 }
865
867}
@ AST_RTP_EXTENSION_DIRECTION_SENDRECV
Definition rtp_engine.h:831
@ AST_RTP_EXTENSION_DIRECTION_INACTIVE
Definition rtp_engine.h:837
@ AST_RTP_EXTENSION_DIRECTION_RECVONLY
Definition rtp_engine.h:835
@ AST_RTP_EXTENSION_DIRECTION_SENDONLY
Definition rtp_engine.h:833

References AST_RTP_EXTENSION_DIRECTION_INACTIVE, AST_RTP_EXTENSION_DIRECTION_NONE, AST_RTP_EXTENSION_DIRECTION_RECVONLY, AST_RTP_EXTENSION_DIRECTION_SENDONLY, and AST_RTP_EXTENSION_DIRECTION_SENDRECV.

Referenced by ast_rtp_instance_extmap_negotiate().

◆ rtp_ice_wrap_add_remote_candidate()

static void rtp_ice_wrap_add_remote_candidate ( struct ast_rtp_instance instance,
const struct ast_rtp_engine_ice_candidate candidate 
)
static

Definition at line 3048 of file rtp_engine.c.

3049{
3050 ao2_lock(instance);
3051 instance->engine->ice->add_remote_candidate(instance, candidate);
3052 ao2_unlock(instance);
3053}
void(* add_remote_candidate)(struct ast_rtp_instance *instance, const struct ast_rtp_engine_ice_candidate *candidate)
Definition rtp_engine.h:540

References ast_rtp_engine_ice::add_remote_candidate, ao2_lock, ao2_unlock, ast_rtp_instance::engine, and ast_rtp_engine::ice.

◆ rtp_ice_wrap_change_components()

static void rtp_ice_wrap_change_components ( struct ast_rtp_instance instance,
int  num_components 
)
static

Definition at line 3124 of file rtp_engine.c.

3126{
3127 ao2_lock(instance);
3128 instance->engine->ice->change_components(instance, num_components);
3129 ao2_unlock(instance);
3130}
void(* change_components)(struct ast_rtp_instance *instance, int num_components)
Definition rtp_engine.h:560

References ao2_lock, ao2_unlock, ast_rtp_engine_ice::change_components, ast_rtp_instance::engine, and ast_rtp_engine::ice.

◆ rtp_ice_wrap_get_local_candidates()

static struct ao2_container * rtp_ice_wrap_get_local_candidates ( struct ast_rtp_instance instance)
static

Definition at line 3089 of file rtp_engine.c.

3090{
3091 struct ao2_container *local_candidates;
3092
3093 ao2_lock(instance);
3094 local_candidates = instance->engine->ice->get_local_candidates(instance);
3095 ao2_unlock(instance);
3096 return local_candidates;
3097}
Generic container type.
struct ao2_container *(* get_local_candidates)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:550

References ao2_lock, ao2_unlock, ast_rtp_instance::engine, ast_rtp_engine_ice::get_local_candidates, and ast_rtp_engine::ice.

◆ rtp_ice_wrap_get_password()

static const char * rtp_ice_wrap_get_password ( struct ast_rtp_instance instance)
static

Definition at line 3079 of file rtp_engine.c.

3080{
3081 const char *password;
3082
3083 ao2_lock(instance);
3084 password = instance->engine->ice->get_password(instance);
3085 ao2_unlock(instance);
3086 return password;
3087}
const char *(* get_password)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:548

References ao2_lock, ao2_unlock, ast_rtp_instance::engine, ast_rtp_engine_ice::get_password, and ast_rtp_engine::ice.

◆ rtp_ice_wrap_get_ufrag()

static const char * rtp_ice_wrap_get_ufrag ( struct ast_rtp_instance instance)
static

Definition at line 3069 of file rtp_engine.c.

3070{
3071 const char *ufrag;
3072
3073 ao2_lock(instance);
3074 ufrag = instance->engine->ice->get_ufrag(instance);
3075 ao2_unlock(instance);
3076 return ufrag;
3077}
const char *(* get_ufrag)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:546

References ao2_lock, ao2_unlock, ast_rtp_instance::engine, ast_rtp_engine_ice::get_ufrag, and ast_rtp_engine::ice.

◆ rtp_ice_wrap_ice_lite()

static void rtp_ice_wrap_ice_lite ( struct ast_rtp_instance instance)
static

Definition at line 3099 of file rtp_engine.c.

3100{
3101 ao2_lock(instance);
3102 instance->engine->ice->ice_lite(instance);
3103 ao2_unlock(instance);
3104}
void(* ice_lite)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:552

References ao2_lock, ao2_unlock, ast_rtp_instance::engine, ast_rtp_engine::ice, and ast_rtp_engine_ice::ice_lite.

◆ rtp_ice_wrap_set_authentication()

static void rtp_ice_wrap_set_authentication ( struct ast_rtp_instance instance,
const char *  ufrag,
const char *  password 
)
static

Definition at line 3041 of file rtp_engine.c.

3042{
3043 ao2_lock(instance);
3044 instance->engine->ice->set_authentication(instance, ufrag, password);
3045 ao2_unlock(instance);
3046}
void(* set_authentication)(struct ast_rtp_instance *instance, const char *ufrag, const char *password)
Definition rtp_engine.h:538

References ao2_lock, ao2_unlock, ast_rtp_instance::engine, ast_rtp_engine::ice, and ast_rtp_engine_ice::set_authentication.

◆ rtp_ice_wrap_set_role()

static void rtp_ice_wrap_set_role ( struct ast_rtp_instance instance,
enum ast_rtp_ice_role  role 
)
static

Definition at line 3106 of file rtp_engine.c.

3108{
3109 ao2_lock(instance);
3110 instance->engine->ice->set_role(instance, role);
3111 ao2_unlock(instance);
3112}
void(* set_role)(struct ast_rtp_instance *instance, enum ast_rtp_ice_role role)
Definition rtp_engine.h:554

References ao2_lock, ao2_unlock, ast_rtp_instance::engine, ast_rtp_engine::ice, and ast_rtp_engine_ice::set_role.

◆ rtp_ice_wrap_start()

static void rtp_ice_wrap_start ( struct ast_rtp_instance instance)
static

Definition at line 3055 of file rtp_engine.c.

3056{
3057 ao2_lock(instance);
3058 instance->engine->ice->start(instance);
3059 ao2_unlock(instance);
3060}
void(* start)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:542

References ao2_lock, ao2_unlock, ast_rtp_instance::engine, ast_rtp_engine::ice, and ast_rtp_engine_ice::start.

◆ rtp_ice_wrap_stop()

static void rtp_ice_wrap_stop ( struct ast_rtp_instance instance)
static

Definition at line 3062 of file rtp_engine.c.

3063{
3064 ao2_lock(instance);
3065 instance->engine->ice->stop(instance);
3066 ao2_unlock(instance);
3067}
void(* stop)(struct ast_rtp_instance *instance)
Definition rtp_engine.h:544

References ao2_lock, ao2_unlock, ast_rtp_instance::engine, ast_rtp_engine::ice, and ast_rtp_engine_ice::stop.

◆ rtp_ice_wrap_turn_request()

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

Definition at line 3114 of file rtp_engine.c.

3117{
3118 ao2_lock(instance);
3119 instance->engine->ice->turn_request(instance, component, transport, server, port,
3120 username, password);
3121 ao2_unlock(instance);
3122}
void(* 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)
Definition rtp_engine.h:556

References ao2_lock, ao2_unlock, ast_rtp_instance::engine, ast_rtp_engine::ice, and ast_rtp_engine_ice::turn_request.

◆ rtp_instance_set_incoming_source_address_nolock()

static void rtp_instance_set_incoming_source_address_nolock ( struct ast_rtp_instance instance,
const struct ast_sockaddr address 
)
static

Definition at line 648 of file rtp_engine.c.

650{
652 if (instance->engine->remote_address_set) {
653 instance->engine->remote_address_set(instance, &instance->incoming_source_address);
654 }
655}
void(* remote_address_set)(struct ast_rtp_instance *instance, struct ast_sockaddr *sa)
Definition rtp_engine.h:696

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

Referenced by ast_rtp_instance_set_incoming_source_address(), and ast_rtp_instance_set_requested_target_address().

◆ rtp_payload_type_alloc()

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 
)
static

Definition at line 315 of file rtp_engine.c.

317{
320
321 if (!type) {
322 return NULL;
323 }
324
325 type->format = ao2_bump(format);
326 type->asterisk_format = type->format != NULL;
327 type->payload = payload;
328 type->rtp_code = rtp_code;
329 type->primary_mapping = primary_mapping;
330 type->sample_rate = sample_rate;
331
332 return type;
333}
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition astobj2.h:367
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition astobj2.h:404
static void rtp_payload_type_dtor(void *obj)
Definition rtp_engine.c:308

References AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_bump, ast_rtp_payload_type::format, NULL, ast_rtp_payload_type::payload, ast_rtp_payload_type::primary_mapping, ast_rtp_payload_type::rtp_code, rtp_payload_type_dtor(), ast_rtp_payload_type::sample_rate, and type.

Referenced by add_static_payload(), ast_rtp_engine_alloc_payload_type(), and rtp_codecs_assign_payload_code_rx().

◆ rtp_payload_type_dtor()

static void rtp_payload_type_dtor ( void *  obj)
static

Definition at line 308 of file rtp_engine.c.

309{
310 struct ast_rtp_payload_type *payload = obj;
311
312 ao2_cleanup(payload->format);
313}

References ao2_cleanup, and ast_rtp_payload_type::payload.

Referenced by rtp_payload_type_alloc().

◆ rtp_rtcp_report_dtor()

static void rtp_rtcp_report_dtor ( void *  obj)
static

Definition at line 3724 of file rtp_engine.c.

3725{
3726 int i;
3727 struct ast_rtp_rtcp_report *rtcp_report = obj;
3728
3729 for (i = 0; i < rtcp_report->reception_report_count; i++) {
3730 ast_free(rtcp_report->report_block[i]);
3731 }
3732}

References ast_free, ast_rtp_rtcp_report::reception_report_count, and ast_rtp_rtcp_report::report_block.

Referenced by ast_rtp_rtcp_report_alloc().

◆ set_next_mime_type()

static void set_next_mime_type ( struct ast_format format,
int  rtp_code,
const char *  type,
const char *  subtype,
unsigned int  sample_rate 
)
static

Definition at line 3410 of file rtp_engine.c.

3411{
3412 int x;
3413
3415
3416 x = mime_types_len;
3417 if (ARRAY_LEN(ast_rtp_mime_types) <= x) {
3419 return;
3420 }
3421
3422 /* Make sure any previous value in ast_rtp_mime_types is cleaned up */
3423 memset(&ast_rtp_mime_types[x], 0, sizeof(struct ast_rtp_mime_type));
3424 if (format) {
3427 } else {
3429 }
3431 ast_copy_string(ast_rtp_mime_types[x].subtype, subtype, sizeof(ast_rtp_mime_types[x].subtype));
3432 ast_rtp_mime_types[x].sample_rate = sample_rate;
3434
3436}

References ao2_bump, ARRAY_LEN, ast_copy_string(), ast_rtp_mime_types, ast_rwlock_unlock, ast_rwlock_wrlock, ast_rtp_payload_type::asterisk_format, ast_rtp_payload_type::format, mime_types_len, mime_types_lock, ast_rtp_mime_type::payload_type, ast_rtp_payload_type::rtp_code, ast_rtp_mime_type::sample_rate, and type.

Referenced by ast_rtp_engine_init(), and ast_rtp_engine_load_format().

◆ STASIS_MESSAGE_TYPE_DEFN() [1/2]

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() [2/2]

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.

◆ unref_instance_cond()

static void unref_instance_cond ( struct ast_rtp_instance **  instance)
static

Conditionally unref an rtp instance.

Definition at line 2441 of file rtp_engine.c.

2442{
2443 if (*instance) {
2444 ao2_ref(*instance, -1);
2445 *instance = NULL;
2446 }
2447}

References ao2_ref, and NULL.

Referenced by ast_rtp_instance_early_bridge(), and ast_rtp_instance_early_bridge_make_compatible().

Variable Documentation

◆ ast_rtp_mime_types

struct ast_rtp_mime_type ast_rtp_mime_types[128]
static

◆ debug_category_dtls_id

uintmax_t debug_category_dtls_id
static

Definition at line 3824 of file rtp_engine.c.

Referenced by ast_debug_category_dtls_id(), and ast_rtp_engine_init().

◆ debug_category_dtls_packet_id

uintmax_t debug_category_dtls_packet_id
static

Definition at line 3831 of file rtp_engine.c.

Referenced by ast_debug_category_dtls_packet_id(), and ast_rtp_engine_init().

◆ debug_category_ice_id

uintmax_t debug_category_ice_id
static

Definition at line 3838 of file rtp_engine.c.

Referenced by ast_debug_category_ice_id(), and ast_rtp_engine_init().

◆ debug_category_rtcp_id

uintmax_t debug_category_rtcp_id
static

Definition at line 3810 of file rtp_engine.c.

Referenced by ast_debug_category_rtcp_id(), and ast_rtp_engine_init().

◆ debug_category_rtcp_packet_id

uintmax_t debug_category_rtcp_packet_id
static

Definition at line 3817 of file rtp_engine.c.

Referenced by ast_debug_category_rtcp_packet_id(), and ast_rtp_engine_init().

◆ debug_category_rtp_id

uintmax_t debug_category_rtp_id
static

Definition at line 3796 of file rtp_engine.c.

Referenced by ast_debug_category_rtp_id(), and ast_rtp_engine_init().

◆ debug_category_rtp_packet_id

uintmax_t debug_category_rtp_packet_id
static

Definition at line 3803 of file rtp_engine.c.

Referenced by ast_debug_category_rtp_packet_id(), and ast_rtp_engine_init().

◆ engines

◆ glues

◆ mime_types_len

int mime_types_len = 0
static

◆ mime_types_lock

ast_rwlock_t mime_types_lock
static

◆ res_srtp

struct ast_srtp_res* res_srtp = NULL

◆ res_srtp_policy

struct ast_srtp_policy_res* res_srtp_policy = NULL

◆ rtp_dtls_wrappers

struct ast_rtp_engine_dtls rtp_dtls_wrappers
static

Definition at line 3253 of file rtp_engine.c.

3253 {
3254 .set_configuration = rtp_dtls_wrap_set_configuration,
3255 .active = rtp_dtls_wrap_active,
3256 .stop = rtp_dtls_wrap_stop,
3257 .reset = rtp_dtls_wrap_reset,
3258 .get_connection = rtp_dtls_wrap_get_connection,
3259 .get_setup = rtp_dtls_wrap_get_setup,
3260 .set_setup = rtp_dtls_wrap_set_setup,
3261 .set_fingerprint = rtp_dtls_wrap_set_fingerprint,
3262 .get_fingerprint_hash = rtp_dtls_wrap_get_fingerprint_hash,
3263 .get_fingerprint = rtp_dtls_wrap_get_fingerprint,
3264};
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_setup rtp_dtls_wrap_get_setup(struct ast_rtp_instance *instance)
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_stop(struct ast_rtp_instance *instance)
static int rtp_dtls_wrap_active(struct ast_rtp_instance *instance)
static void rtp_dtls_wrap_set_setup(struct ast_rtp_instance *instance, enum ast_rtp_dtls_setup setup)
static void rtp_dtls_wrap_reset(struct ast_rtp_instance *instance)
static enum ast_rtp_dtls_hash rtp_dtls_wrap_get_fingerprint_hash(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)

Referenced by ast_rtp_instance_get_dtls().

◆ rtp_extension_uris

const char* const rtp_extension_uris[AST_RTP_EXTENSION_MAX]
static
Initial value:
= {
[AST_RTP_EXTENSION_ABS_SEND_TIME] = "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time",
[AST_RTP_EXTENSION_TRANSPORT_WIDE_CC] = "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01",
}
@ AST_RTP_EXTENSION_TRANSPORT_WIDE_CC
Definition rtp_engine.h:599
@ AST_RTP_EXTENSION_ABS_SEND_TIME
Definition rtp_engine.h:597

URIs for known RTP extensions.

Definition at line 244 of file rtp_engine.c.

244 {
246 [AST_RTP_EXTENSION_ABS_SEND_TIME] = "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time",
247 [AST_RTP_EXTENSION_TRANSPORT_WIDE_CC] = "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01",
248};

Referenced by ast_rtp_instance_extmap_get_uri(), and ast_rtp_instance_extmap_negotiate().

◆ rtp_ice_wrappers

struct ast_rtp_engine_ice rtp_ice_wrappers
static

Definition at line 3132 of file rtp_engine.c.

3132 {
3133 .set_authentication = rtp_ice_wrap_set_authentication,
3134 .add_remote_candidate = rtp_ice_wrap_add_remote_candidate,
3135 .start = rtp_ice_wrap_start,
3136 .stop = rtp_ice_wrap_stop,
3137 .get_ufrag = rtp_ice_wrap_get_ufrag,
3138 .get_password = rtp_ice_wrap_get_password,
3139 .get_local_candidates = rtp_ice_wrap_get_local_candidates,
3140 .ice_lite = rtp_ice_wrap_ice_lite,
3141 .set_role = rtp_ice_wrap_set_role,
3142 .turn_request = rtp_ice_wrap_turn_request,
3143 .change_components = rtp_ice_wrap_change_components,
3144};
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_ice_wrap_stop(struct ast_rtp_instance *instance)
static void rtp_ice_wrap_add_remote_candidate(struct ast_rtp_instance *instance, const struct ast_rtp_engine_ice_candidate *candidate)
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_role(struct ast_rtp_instance *instance, enum ast_rtp_ice_role role)
static const char * rtp_ice_wrap_get_password(struct ast_rtp_instance *instance)
static void rtp_ice_wrap_start(struct ast_rtp_instance *instance)
static void rtp_ice_wrap_change_components(struct ast_rtp_instance *instance, int num_components)
static void rtp_ice_wrap_set_authentication(struct ast_rtp_instance *instance, const char *ufrag, const char *password)
static struct ao2_container * rtp_ice_wrap_get_local_candidates(struct ast_rtp_instance *instance)

Referenced by ast_rtp_instance_get_ice().

◆ rtp_topic

struct stasis_topic* rtp_topic
static

Stasis Message Bus API topic for RTP related messages

Definition at line 287 of file rtp_engine.c.

Referenced by ast_rtp_engine_init(), ast_rtp_topic(), and rtp_engine_shutdown().

◆ static_RTP_PT

struct ast_rtp_payload_type* static_RTP_PT[AST_RTP_MAX_PT]
static

Mapping between Asterisk codecs and rtp payload types.

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

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

Definition at line 283 of file rtp_engine.c.

Referenced by add_static_payload(), ast_rtp_codecs_get_payload(), ast_rtp_codecs_payloads_set_m_type(), ast_rtp_engine_unload_format(), find_static_payload_type(), find_unused_payload(), rtp_codecs_assign_payload_code_rx(), and rtp_engine_shutdown().

◆ static_RTP_PT_lock

ast_rwlock_t static_RTP_PT_lock
static