Asterisk - The Open Source Telephony Project  21.4.1
Data Structures | Macros | Enumerations | Functions
rtp_engine.h File Reference

Pluggable RTP Architecture. More...

#include "asterisk/astobj2.h"
#include "asterisk/frame.h"
#include "asterisk/format_cap.h"
#include "asterisk/netsock2.h"
#include "asterisk/sched.h"
#include "asterisk/res_srtp.h"
#include "asterisk/stasis.h"
#include "asterisk/vector.h"
#include "asterisk/logger_category.h"

Go to the source code of this file.

Data Structures

struct  ast_rtp_codecs
 
struct  ast_rtp_dtls_cfg
 DTLS configuration structure. More...
 
struct  ast_rtp_engine
 
struct  ast_rtp_engine_dtls
 Structure that represents the optional DTLS SRTP support within an RTP engine. More...
 
struct  ast_rtp_engine_ice
 Structure that represents the optional ICE support within an RTP engine. More...
 
struct  ast_rtp_engine_ice_candidate
 Structure for an ICE candidate. More...
 
struct  ast_rtp_glue
 
struct  ast_rtp_instance_stats
 
struct  ast_rtp_payload_type
 
struct  ast_rtp_rtcp_feedback
 An object that represents data received in a feedback report. More...
 
struct  ast_rtp_rtcp_feedback_remb
 A REMB feedback message (see draft-alvestrand-rmcat-remb-03 for details) More...
 
struct  ast_rtp_rtcp_report
 An object that represents data sent during a SR/RR RTCP report. More...
 
struct  ast_rtp_rtcp_report_block
 A report block within a SR/RR report. More...
 

Macros

#define AST_DEBUG_CATEGORY_DTLS   ast_debug_category_dtls_id() /* DTLS debug logging category id */
 
#define AST_DEBUG_CATEGORY_DTLS_PACKET   ast_debug_category_dtls_packet_id() /* DTLS packet debug logging category id */
 
#define AST_DEBUG_CATEGORY_ICE   ast_debug_category_ice_id() /* ICE debug logging category id */
 
#define AST_DEBUG_CATEGORY_RTCP   ast_debug_category_rtcp_id() /* RTCP debug logging category id */
 
#define AST_DEBUG_CATEGORY_RTCP_PACKET   ast_debug_category_rtcp_packet_id() /* RTCP packet debug logging category id */
 
#define AST_DEBUG_CATEGORY_RTP   ast_debug_category_rtp_id() /* RTP debug logging category id */
 
#define AST_DEBUG_CATEGORY_RTP_PACKET   ast_debug_category_rtp_packet_id() /* RTP packet debug logging category id */
 
#define ast_debug_dtls(sublevel, ...)   ast_debug_category(sublevel, AST_DEBUG_CATEGORY_DTLS, __VA_ARGS__)
 Log debug level DTLS information. More...
 
#define ast_debug_dtls_packet_is_allowed   ast_debug_category_is_allowed(AST_LOG_CATEGORY_ENABLED, AST_DEBUG_CATEGORY_DTLS_PACKET)
 
#define ast_debug_ice(sublevel, ...)   ast_debug_category(sublevel, AST_DEBUG_CATEGORY_ICE, __VA_ARGS__)
 Log debug level ICE information. More...
 
#define ast_debug_rtcp(sublevel, ...)   ast_debug_category(sublevel, AST_DEBUG_CATEGORY_RTCP, __VA_ARGS__)
 Log debug level RTCP information. More...
 
#define ast_debug_rtcp_is_allowed   ast_debug_category_is_allowed(AST_LOG_CATEGORY_ENABLED, AST_DEBUG_CATEGORY_RTCP)
 
#define ast_debug_rtcp_packet_is_allowed   ast_debug_category_is_allowed(AST_LOG_CATEGORY_ENABLED, AST_DEBUG_CATEGORY_RTCP_PACKET)
 
#define ast_debug_rtp(sublevel, ...)   ast_debug_category(sublevel, AST_DEBUG_CATEGORY_RTP, __VA_ARGS__)
 Log debug level RTP information. More...
 
#define ast_debug_rtp_is_allowed   ast_debug_category_is_allowed(AST_LOG_CATEGORY_ENABLED, AST_DEBUG_CATEGORY_RTP)
 
#define ast_debug_rtp_packet_is_allowed   ast_debug_category_is_allowed(AST_LOG_CATEGORY_ENABLED, AST_DEBUG_CATEGORY_RTP_PACKET)
 
#define AST_LOG_CATEGORY_DTLS   "dtls"
 
#define AST_LOG_CATEGORY_DTLS_PACKET   "dtls_packet"
 
#define AST_LOG_CATEGORY_ICE   "ice"
 
#define AST_LOG_CATEGORY_RTCP   "rtcp"
 
#define AST_LOG_CATEGORY_RTCP_PACKET   "rtcp_packet"
 
#define AST_LOG_CATEGORY_RTP   "rtp"
 
#define AST_LOG_CATEGORY_RTP_PACKET   "rtp_packet"
 
#define AST_RED_MAX_GENERATION   5
 
#define AST_RTP_CISCO_DTMF   (1 << 2)
 
#define AST_RTP_CN   (1 << 1)
 
#define AST_RTP_CODECS_NULL_INIT   { .codecs_lock = AST_RWLOCK_INIT_VALUE, .payload_mapping_rx = { 0, }, .payload_mapping_tx = { 0, }, .framing = 0, .preferred_format = NULL }
 
#define AST_RTP_DTMF   (1 << 0)
 
#define ast_rtp_engine_register(engine)   ast_rtp_engine_register2(engine, AST_MODULE_SELF)
 
#define ast_rtp_glue_register(glue)   ast_rtp_glue_register2(glue, AST_MODULE_SELF)
 
#define ast_rtp_instance_get_and_cmp_remote_address(instance, address)   ast_rtp_instance_get_and_cmp_requested_target_address((instance), (address))
 Get the address of the remote endpoint that we are sending RTP to, comparing its address to another. More...
 
#define ast_rtp_instance_get_remote_address(instance, address)   ast_rtp_instance_get_incoming_source_address((instance), (address))
 Get the address of the remote endpoint that we are sending RTP to. More...
 
#define ast_rtp_instance_set_remote_address(instance, address)   ast_rtp_instance_set_requested_target_address((instance), (address))
 Set the address of the remote endpoint that we are sending RTP to. More...
 
#define AST_RTP_MAX   AST_RTP_CISCO_DTMF
 
#define AST_RTP_MAX_PT   128
 
#define AST_RTP_PT_FIRST_DYNAMIC   96
 
#define AST_RTP_PT_LAST_REASSIGN   63
 
#define AST_RTP_PT_LAST_STATIC   34
 
#define AST_RTP_RTCP_FMT_FIR   4
 
#define AST_RTP_RTCP_FMT_NACK   1
 
#define AST_RTP_RTCP_FMT_PLI   1
 
#define AST_RTP_RTCP_FMT_REMB   15
 
#define AST_RTP_RTCP_FMT_TRANSPORT_WIDE_CC   15
 
#define AST_RTP_RTCP_PSFB   206
 
#define AST_RTP_RTCP_RR   201
 
#define AST_RTP_RTCP_RTPFB   205
 
#define AST_RTP_RTCP_SR   200
 
#define AST_RTP_STAT_SET(current_stat, combined, placement, value)
 
#define AST_RTP_STAT_STRCPY(current_stat, combined, placement, value)
 
#define AST_RTP_STAT_TERMINATOR(combined)
 
#define DEFAULT_DTMF_SAMPLE_RATE_MS   8000
 
#define MAX_CHANNEL_ID   152
 

Enumerations

enum  ast_rtp_dtls_connection { AST_RTP_DTLS_CONNECTION_NEW, AST_RTP_DTLS_CONNECTION_EXISTING }
 DTLS connection states. More...
 
enum  ast_rtp_dtls_hash { AST_RTP_DTLS_HASH_SHA256, AST_RTP_DTLS_HASH_SHA1 }
 DTLS fingerprint hashes. More...
 
enum  ast_rtp_dtls_setup { AST_RTP_DTLS_SETUP_ACTIVE, AST_RTP_DTLS_SETUP_PASSIVE, AST_RTP_DTLS_SETUP_ACTPASS, AST_RTP_DTLS_SETUP_HOLDCONN }
 DTLS setup types. More...
 
enum  ast_rtp_dtls_verify { AST_RTP_DTLS_VERIFY_NONE = 0, AST_RTP_DTLS_VERIFY_FINGERPRINT = (1 << 0), AST_RTP_DTLS_VERIFY_CERTIFICATE = (1 << 1) }
 DTLS verification settings. More...
 
enum  ast_rtp_dtmf_mode { AST_RTP_DTMF_MODE_NONE = 0, AST_RTP_DTMF_MODE_RFC2833, AST_RTP_DTMF_MODE_INBAND }
 
enum  ast_rtp_extension { AST_RTP_EXTENSION_UNSUPPORTED = 0, AST_RTP_EXTENSION_ABS_SEND_TIME, AST_RTP_EXTENSION_TRANSPORT_WIDE_CC, AST_RTP_EXTENSION_MAX }
 Known RTP extensions. More...
 
enum  ast_rtp_extension_direction {
  AST_RTP_EXTENSION_DIRECTION_NONE, AST_RTP_EXTENSION_DIRECTION_SENDRECV, AST_RTP_EXTENSION_DIRECTION_SENDONLY, AST_RTP_EXTENSION_DIRECTION_RECVONLY,
  AST_RTP_EXTENSION_DIRECTION_INACTIVE
}
 Directions for RTP extensions. More...
 
enum  ast_rtp_glue_result { AST_RTP_GLUE_RESULT_FORBID = 0, AST_RTP_GLUE_RESULT_REMOTE, AST_RTP_GLUE_RESULT_LOCAL }
 
enum  ast_rtp_ice_candidate_type { AST_RTP_ICE_CANDIDATE_TYPE_HOST, AST_RTP_ICE_CANDIDATE_TYPE_SRFLX, AST_RTP_ICE_CANDIDATE_TYPE_RELAYED }
 ICE candidate types. More...
 
enum  ast_rtp_ice_component_type { AST_RTP_ICE_COMPONENT_RTP = 1, AST_RTP_ICE_COMPONENT_RTCP = 2 }
 ICE component types.
 
enum  ast_rtp_ice_role { AST_RTP_ICE_ROLE_CONTROLLED, AST_RTP_ICE_ROLE_CONTROLLING }
 ICE role during negotiation.
 
enum  ast_rtp_instance_rtcp { AST_RTP_INSTANCE_RTCP_DISABLED = 0, AST_RTP_INSTANCE_RTCP_STANDARD, AST_RTP_INSTANCE_RTCP_MUX }
 
enum  ast_rtp_instance_stat {
  AST_RTP_INSTANCE_STAT_ALL = 0, AST_RTP_INSTANCE_STAT_TXCOUNT, AST_RTP_INSTANCE_STAT_RXCOUNT, AST_RTP_INSTANCE_STAT_COMBINED_LOSS,
  AST_RTP_INSTANCE_STAT_TXPLOSS, AST_RTP_INSTANCE_STAT_RXPLOSS, AST_RTP_INSTANCE_STAT_REMOTE_MAXRXPLOSS, AST_RTP_INSTANCE_STAT_REMOTE_MINRXPLOSS,
  AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVRXPLOSS, AST_RTP_INSTANCE_STAT_REMOTE_STDEVRXPLOSS, AST_RTP_INSTANCE_STAT_LOCAL_MAXRXPLOSS, AST_RTP_INSTANCE_STAT_LOCAL_MINRXPLOSS,
  AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVRXPLOSS, AST_RTP_INSTANCE_STAT_LOCAL_STDEVRXPLOSS, AST_RTP_INSTANCE_STAT_COMBINED_JITTER, AST_RTP_INSTANCE_STAT_TXJITTER,
  AST_RTP_INSTANCE_STAT_RXJITTER, AST_RTP_INSTANCE_STAT_REMOTE_MAXJITTER, AST_RTP_INSTANCE_STAT_REMOTE_MINJITTER, AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVJITTER,
  AST_RTP_INSTANCE_STAT_REMOTE_STDEVJITTER, AST_RTP_INSTANCE_STAT_LOCAL_MAXJITTER, AST_RTP_INSTANCE_STAT_LOCAL_MINJITTER, AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVJITTER,
  AST_RTP_INSTANCE_STAT_LOCAL_STDEVJITTER, AST_RTP_INSTANCE_STAT_COMBINED_RTT, AST_RTP_INSTANCE_STAT_RTT, AST_RTP_INSTANCE_STAT_MAX_RTT,
  AST_RTP_INSTANCE_STAT_MIN_RTT, AST_RTP_INSTANCE_STAT_NORMDEVRTT, AST_RTP_INSTANCE_STAT_STDEVRTT, AST_RTP_INSTANCE_STAT_LOCAL_SSRC,
  AST_RTP_INSTANCE_STAT_REMOTE_SSRC, AST_RTP_INSTANCE_STAT_CHANNEL_UNIQUEID, AST_RTP_INSTANCE_STAT_TXOCTETCOUNT, AST_RTP_INSTANCE_STAT_RXOCTETCOUNT,
  AST_RTP_INSTANCE_STAT_COMBINED_MES, AST_RTP_INSTANCE_STAT_TXMES, AST_RTP_INSTANCE_STAT_RXMES, AST_RTP_INSTANCE_STAT_REMOTE_MAXMES,
  AST_RTP_INSTANCE_STAT_REMOTE_MINMES, AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVMES, AST_RTP_INSTANCE_STAT_REMOTE_STDEVMES, AST_RTP_INSTANCE_STAT_LOCAL_MAXMES,
  AST_RTP_INSTANCE_STAT_LOCAL_MINMES, AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVMES, AST_RTP_INSTANCE_STAT_LOCAL_STDEVMES
}
 
enum  ast_rtp_instance_stat_field {
  AST_RTP_INSTANCE_STAT_FIELD_QUALITY = 0, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT,
  AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES
}
 
enum  ast_rtp_options { AST_RTP_OPT_G726_NONSTANDARD = (1 << 0) }
 
enum  ast_rtp_property {
  AST_RTP_PROPERTY_NAT = 0, AST_RTP_PROPERTY_DTMF, AST_RTP_PROPERTY_DTMF_COMPENSATE, AST_RTP_PROPERTY_STUN,
  AST_RTP_PROPERTY_RTCP, AST_RTP_PROPERTY_ASYMMETRIC_CODEC, AST_RTP_PROPERTY_RETRANS_RECV, AST_RTP_PROPERTY_RETRANS_SEND,
  AST_RTP_PROPERTY_REMB, AST_RTP_PROPERTY_MAX
}
 

Functions

uintmax_t ast_debug_category_dtls_id (void)
 
uintmax_t ast_debug_category_dtls_packet_id (void)
 
uintmax_t ast_debug_category_ice_id (void)
 
uintmax_t ast_debug_category_rtcp_id (void)
 
uintmax_t ast_debug_category_rtcp_packet_id (void)
 
uintmax_t ast_debug_category_rtp_id (void)
 
uintmax_t ast_debug_category_rtp_packet_id (void)
 
int ast_rtp_codecs_find_payload_code (struct ast_rtp_codecs *codecs, int payload)
 Search for the tx payload type in the ast_rtp_codecs structure. More...
 
unsigned int ast_rtp_codecs_get_framing (struct ast_rtp_codecs *codecs)
 Get the framing used for a set of codecs. More...
 
struct ast_rtp_payload_typeast_rtp_codecs_get_payload (struct ast_rtp_codecs *codecs, int payload)
 Retrieve rx payload mapped information by payload type. More...
 
struct ast_formatast_rtp_codecs_get_payload_format (struct ast_rtp_codecs *codecs, int payload)
 Retrieve the actual ast_format stored on the codecs structure for a specific tx payload type. More...
 
struct ast_formatast_rtp_codecs_get_preferred_format (struct ast_rtp_codecs *codecs)
 Retrieve rx preferred format. More...
 
enum ast_media_type ast_rtp_codecs_get_stream_type (struct ast_rtp_codecs *codecs)
 Determine the type of RTP stream media from the codecs mapped. More...
 
int ast_rtp_codecs_payload_code (struct ast_rtp_codecs *codecs, int asterisk_format, struct ast_format *format, int code)
 Retrieve a rx mapped payload type based on whether it is an Asterisk format and the code. More...
 
int ast_rtp_codecs_payload_code_sample_rate (struct ast_rtp_codecs *codecs, int asterisk_format, struct ast_format *format, int code, unsigned int sample_rate)
 Retrieve a rx mapped payload type based on whether it is an Asterisk format, the code and the sample rate. More...
 
int ast_rtp_codecs_payload_code_tx (struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code)
 Retrieve a tx mapped payload type based on whether it is an Asterisk format and the code. More...
 
int ast_rtp_codecs_payload_code_tx_sample_rate (struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code, unsigned int sample_rate)
 Retrieve a tx mapped payload type based on whether it is an Asterisk format and the code. More...
 
void ast_rtp_codecs_payload_formats (struct ast_rtp_codecs *codecs, struct ast_format_cap *astformats, int *nonastformats)
 Retrieve all formats that were found. More...
 
int ast_rtp_codecs_payload_replace_format (struct ast_rtp_codecs *codecs, int payload, struct ast_format *format)
 Update the format associated with a tx payload type in a codecs structure. More...
 
int ast_rtp_codecs_payload_set_rx (struct ast_rtp_codecs *codecs, int code, struct ast_format *format)
 Set a payload code for use with a specific Asterisk format. More...
 
int ast_rtp_codecs_payload_set_rx_sample_rate (struct ast_rtp_codecs *codecs, int code, struct ast_format *format, unsigned int sample_rate)
 Set a payload code with sample rate for use with a specific Asterisk format. More...
 
void ast_rtp_codecs_payloads_clear (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance)
 Clear rx and tx payload mapping information from an RTP instance. More...
 
void ast_rtp_codecs_payloads_copy (struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
 Copy payload information from one RTP instance to another. More...
 
void ast_rtp_codecs_payloads_destroy (struct ast_rtp_codecs *codecs)
 Destroy the contents of an RTP codecs structure (but not the structure itself) More...
 
int ast_rtp_codecs_payloads_initialize (struct ast_rtp_codecs *codecs)
 Initialize an RTP codecs structure. More...
 
void ast_rtp_codecs_payloads_set_m_type (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
 Record tx payload type information that was seen in an m= SDP line. More...
 
int ast_rtp_codecs_payloads_set_rtpmap_type (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload, char *mimetype, char *mimesubtype, enum ast_rtp_options options)
 Record tx payload type information that was seen in an a=rtpmap: SDP line. More...
 
int ast_rtp_codecs_payloads_set_rtpmap_type_rate (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int pt, char *mimetype, char *mimesubtype, enum ast_rtp_options options, unsigned int sample_rate)
 Set tx payload type to a known MIME media type for a codec with a specific sample rate. More...
 
void ast_rtp_codecs_payloads_unset (struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
 Remove tx payload type mapped information. More...
 
void ast_rtp_codecs_payloads_xover (struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
 Crossover copy the tx payload mapping of src to the rx payload mapping of dest. More...
 
void ast_rtp_codecs_set_framing (struct ast_rtp_codecs *codecs, unsigned int framing)
 Set the framing used for a set of codecs. More...
 
int ast_rtp_codecs_set_preferred_format (struct ast_rtp_codecs *codecs, struct ast_format *format)
 Set the preferred format. More...
 
struct ast_jsonast_rtp_convert_stats_json (const struct ast_rtp_instance_stats *stats)
 Convert given stat instance into json format. More...
 
void ast_rtp_dtls_cfg_copy (const struct ast_rtp_dtls_cfg *src_cfg, struct ast_rtp_dtls_cfg *dst_cfg)
 Copy contents of a DTLS configuration structure. More...
 
void ast_rtp_dtls_cfg_free (struct ast_rtp_dtls_cfg *dtls_cfg)
 Free contents of a DTLS configuration structure. More...
 
int ast_rtp_dtls_cfg_parse (struct ast_rtp_dtls_cfg *dtls_cfg, const char *name, const char *value)
 Parse DTLS related configuration options. More...
 
int ast_rtp_dtls_cfg_validate (struct ast_rtp_dtls_cfg *dtls_cfg)
 Validates DTLS related configuration options. More...
 
struct ast_rtp_payload_typeast_rtp_engine_alloc_payload_type (void)
 Allocation routine for ast_rtp_payload_type. More...
 
int ast_rtp_engine_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. More...
 
int ast_rtp_engine_register_srtp (struct ast_srtp_res *srtp_res, struct ast_srtp_policy_res *policy_res)
 
int ast_rtp_engine_srtp_is_registered (void)
 
int ast_rtp_engine_unload_format (struct ast_format *format)
 Formats requiring the use of a format attribute interface must have that interface registered in order for the rtp engine to handle it correctly. If an attribute interface is unloaded, this function must be called to notify the rtp_engine.
 
int ast_rtp_engine_unregister (struct ast_rtp_engine *engine)
 Unregister an RTP engine. More...
 
void ast_rtp_engine_unregister_srtp (void)
 
int ast_rtp_get_rate (const struct ast_format *format)
 Retrieve the sample rate of a format according to RTP specifications. More...
 
int ast_rtp_glue_register2 (struct ast_rtp_glue *glue, struct ast_module *module)
 Register RTP glue. More...
 
int ast_rtp_glue_unregister (struct ast_rtp_glue *glue)
 Unregister RTP glue. More...
 
int ast_rtp_instance_activate (struct ast_rtp_instance *instance)
 Indicate to the RTP engine that packets are now expected to be sent/received on the RTP instance. More...
 
int ast_rtp_instance_add_srtp_policy (struct ast_rtp_instance *instance, struct ast_srtp_policy *remote_policy, struct ast_srtp_policy *local_policy, int rtcp)
 Add or replace the SRTP policies for the given RTP instance. More...
 
void ast_rtp_instance_available_formats (struct ast_rtp_instance *instance, struct ast_format_cap *to_endpoint, struct ast_format_cap *to_asterisk, struct ast_format_cap *result)
 Request the formats that can be transcoded. More...
 
int ast_rtp_instance_bundle (struct ast_rtp_instance *child, struct ast_rtp_instance *parent)
 Request that an RTP instance be bundled with another. More...
 
void ast_rtp_instance_change_source (struct ast_rtp_instance *instance)
 Indicate a new source of audio has dropped in and the ssrc should change. More...
 
int ast_rtp_instance_destroy (struct ast_rtp_instance *instance)
 Destroy an RTP instance. More...
 
int ast_rtp_instance_dtmf_begin (struct ast_rtp_instance *instance, char digit)
 Begin sending a DTMF digit. More...
 
int ast_rtp_instance_dtmf_end (struct ast_rtp_instance *instance, char digit)
 Stop sending a DTMF digit. More...
 
int ast_rtp_instance_dtmf_end_with_duration (struct ast_rtp_instance *instance, char digit, unsigned int duration)
 
enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get (struct ast_rtp_instance *instance)
 Get the DTMF mode of an RTP instance. More...
 
int ast_rtp_instance_dtmf_mode_set (struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode)
 Set the DTMF mode that should be used. More...
 
int ast_rtp_instance_early_bridge (struct ast_channel *c0, struct ast_channel *c1)
 Early bridge two channels that use RTP instances. More...
 
void ast_rtp_instance_early_bridge_make_compatible (struct ast_channel *c_dst, struct ast_channel *c_src)
 Make two channels compatible for early bridging. More...
 
void ast_rtp_instance_extmap_clear (struct ast_rtp_instance *instance)
 Clear negotiated RTP extension information. More...
 
size_t ast_rtp_instance_extmap_count (struct ast_rtp_instance *instance)
 Get the number of known unique identifiers. More...
 
int ast_rtp_instance_extmap_enable (struct ast_rtp_instance *instance, int id, enum ast_rtp_extension extension, enum ast_rtp_extension_direction direction)
 Enable support for an RTP extension on an instance. More...
 
enum ast_rtp_extension_direction ast_rtp_instance_extmap_get_direction (struct ast_rtp_instance *instance, int id)
 Retrieve the negotiated direction for an RTP extension id. More...
 
enum ast_rtp_extension ast_rtp_instance_extmap_get_extension (struct ast_rtp_instance *instance, int id)
 Retrieve the extension for an RTP extension id. More...
 
int ast_rtp_instance_extmap_get_id (struct ast_rtp_instance *instance, enum ast_rtp_extension extension)
 Retrieve the id for an RTP extension. More...
 
const char * ast_rtp_instance_extmap_get_uri (struct ast_rtp_instance *instance, int id)
 Retrieve the URI for an RTP extension id. More...
 
int ast_rtp_instance_extmap_negotiate (struct ast_rtp_instance *instance, int id, enum ast_rtp_extension_direction direction, const char *uri, const char *attributes)
 Negotiate received RTP extension information. More...
 
int ast_rtp_instance_fd (struct ast_rtp_instance *instance, int rtcp)
 Get the file descriptor for an RTP session (or RTCP) More...
 
struct ast_rtp_glueast_rtp_instance_get_active_glue (struct ast_rtp_instance *instance)
 Get the RTP glue in use on an RTP instance. More...
 
int ast_rtp_instance_get_and_cmp_local_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the address of the local endpoint that we are sending RTP to, comparing its address to another. More...
 
int ast_rtp_instance_get_and_cmp_requested_target_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the requested target address of the remote endpoint and compare it to the given address. More...
 
struct ast_rtp_instanceast_rtp_instance_get_bridged (struct ast_rtp_instance *instance)
 Get the other RTP instance that an instance is bridged to. More...
 
const char * ast_rtp_instance_get_channel_id (struct ast_rtp_instance *instance)
 Get the unique ID of the channel that owns this RTP instance. More...
 
const char * ast_rtp_instance_get_cname (struct ast_rtp_instance *rtp)
 Retrieve the CNAME used in RTCP SDES items. More...
 
struct ast_rtp_codecsast_rtp_instance_get_codecs (struct ast_rtp_instance *instance)
 Get the codecs structure of an RTP instance. More...
 
void * ast_rtp_instance_get_data (struct ast_rtp_instance *instance)
 Get the data portion of an RTP instance. More...
 
struct ast_rtp_engine_dtlsast_rtp_instance_get_dtls (struct ast_rtp_instance *instance)
 Obtain a pointer to the DTLS support present on an RTP instance. More...
 
struct ast_rtp_engineast_rtp_instance_get_engine (struct ast_rtp_instance *instance)
 Get the RTP engine in use on an RTP instance. More...
 
void * ast_rtp_instance_get_extended_prop (struct ast_rtp_instance *instance, int property)
 Get the value of an RTP instance extended property. More...
 
struct ast_rtp_glueast_rtp_instance_get_glue (const char *type)
 Get the RTP glue that binds a channel to the RTP engine. More...
 
int ast_rtp_instance_get_hold_timeout (struct ast_rtp_instance *instance)
 Get the RTP timeout value for when an RTP instance is on hold. More...
 
struct ast_rtp_engine_iceast_rtp_instance_get_ice (struct ast_rtp_instance *instance)
 Obtain a pointer to the ICE support present on an RTP instance. More...
 
void ast_rtp_instance_get_incoming_source_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the incoming source address of the remote endpoint. More...
 
int ast_rtp_instance_get_keepalive (struct ast_rtp_instance *instance)
 Get the RTP keepalive interval. More...
 
time_t ast_rtp_instance_get_last_rx (const struct ast_rtp_instance *rtp)
 Get the last RTP reception time. More...
 
time_t ast_rtp_instance_get_last_tx (const struct ast_rtp_instance *rtp)
 Get the last RTP transmission time. More...
 
void ast_rtp_instance_get_local_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the local address that we are expecting RTP on. More...
 
int ast_rtp_instance_get_prop (struct ast_rtp_instance *instance, enum ast_rtp_property property)
 Get the value of an RTP instance property. More...
 
char * ast_rtp_instance_get_quality (struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size)
 Retrieve quality statistics about an RTP instance. More...
 
void ast_rtp_instance_get_requested_target_address (struct ast_rtp_instance *instance, struct ast_sockaddr *address)
 Get the requested target address of the remote endpoint. More...
 
struct ast_srtpast_rtp_instance_get_srtp (struct ast_rtp_instance *instance, int rtcp)
 Obtain the SRTP instance associated with an RTP instance. More...
 
unsigned int ast_rtp_instance_get_ssrc (struct ast_rtp_instance *rtp)
 Retrieve the local SSRC value that we will be using. More...
 
int ast_rtp_instance_get_stats (struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
 Retrieve statistics about an RTP instance. More...
 
struct ast_jsonast_rtp_instance_get_stats_all_json (struct ast_rtp_instance *instance)
 Retrieve statistics about an RTP instance in json format. More...
 
int ast_rtp_instance_get_timeout (struct ast_rtp_instance *instance)
 Get the RTP timeout value. More...
 
int ast_rtp_instance_make_compatible (struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_channel *peer)
 Request that the underlying RTP engine make two RTP instances compatible with eachother. More...
 
struct ast_rtp_instanceast_rtp_instance_new (const char *engine_name, struct ast_sched_context *sched, const struct ast_sockaddr *sa, void *data)
 Create a new RTP instance. More...
 
struct ast_frameast_rtp_instance_read (struct ast_rtp_instance *instance, int rtcp)
 Receive a frame over RTP. More...
 
int ast_rtp_instance_sendcng (struct ast_rtp_instance *instance, int level)
 Send a comfort noise packet to the RTP instance. More...
 
void ast_rtp_instance_set_bridged (struct ast_rtp_instance *instance, struct ast_rtp_instance *bridged)
 Set the other RTP instance that an instance is bridged to. More...
 
void ast_rtp_instance_set_channel_id (struct ast_rtp_instance *instance, const char *uniqueid)
 Set the channel that owns this RTP instance. More...
 
void ast_rtp_instance_set_data (struct ast_rtp_instance *instance, void *data)
 Set the data portion of an RTP instance. More...
 
void ast_rtp_instance_set_extended_prop (struct ast_rtp_instance *instance, int property, void *value)
 Set the value of an RTP instance extended property. More...
 
void ast_rtp_instance_set_hold_timeout (struct ast_rtp_instance *instance, int timeout)
 Set the RTP timeout value for when the instance is on hold. More...
 
int ast_rtp_instance_set_incoming_source_address (struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
 Set the incoming source address of the remote endpoint that we are sending RTP to. More...
 
void ast_rtp_instance_set_keepalive (struct ast_rtp_instance *instance, int timeout)
 Set the RTP keepalive interval. More...
 
void ast_rtp_instance_set_last_rx (struct ast_rtp_instance *rtp, time_t time)
 Set the last RTP reception time. More...
 
void ast_rtp_instance_set_last_tx (struct ast_rtp_instance *rtp, time_t time)
 Set the last RTP transmission time. More...
 
int ast_rtp_instance_set_local_address (struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
 Set the address that we are expecting to receive RTP on. More...
 
void ast_rtp_instance_set_prop (struct ast_rtp_instance *instance, enum ast_rtp_property property, int value)
 Set the value of an RTP instance property. More...
 
int ast_rtp_instance_set_qos (struct ast_rtp_instance *instance, int tos, int cos, const char *desc)
 Set QoS parameters on an RTP session. More...
 
int ast_rtp_instance_set_read_format (struct ast_rtp_instance *instance, struct ast_format *format)
 Request that the underlying RTP engine provide audio frames in a specific format. More...
 
void ast_rtp_instance_set_remote_ssrc (struct ast_rtp_instance *rtp, unsigned int ssrc)
 Set the remote SSRC for an RTP instance. More...
 
int ast_rtp_instance_set_requested_target_address (struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
 Set the requested target address of the remote endpoint. More...
 
void ast_rtp_instance_set_stats_vars (struct ast_channel *chan, struct ast_rtp_instance *instance)
 Set standard statistics from an RTP instance on a channel. More...
 
void ast_rtp_instance_set_stream_num (struct ast_rtp_instance *instance, int stream_num)
 Set the stream number for an RTP instance. More...
 
void ast_rtp_instance_set_timeout (struct ast_rtp_instance *instance, int timeout)
 Set the RTP timeout value. More...
 
int ast_rtp_instance_set_write_format (struct ast_rtp_instance *instance, struct ast_format *format)
 Tell underlying RTP engine that audio frames will be provided in a specific format. More...
 
void ast_rtp_instance_stop (struct ast_rtp_instance *instance)
 Stop an RTP instance. More...
 
void ast_rtp_instance_stun_request (struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username)
 Request that the underlying RTP engine send a STUN BIND request. More...
 
void ast_rtp_instance_update_source (struct ast_rtp_instance *instance)
 Indicate that the RTP marker bit should be set on an RTP stream. More...
 
int ast_rtp_instance_write (struct ast_rtp_instance *instance, struct ast_frame *frame)
 Send a frame out over RTP. More...
 
char * ast_rtp_lookup_mime_multiple2 (struct ast_str *buf, struct ast_format_cap *ast_format_capability, int rtp_capability, const int asterisk_format, enum ast_rtp_options options)
 Convert formats into a string and put them into a buffer. More...
 
const char * ast_rtp_lookup_mime_subtype2 (const int asterisk_format, const struct ast_format *format, int code, enum ast_rtp_options options)
 Retrieve mime subtype information on a payload. More...
 
unsigned int ast_rtp_lookup_sample_rate2 (int asterisk_format, const struct ast_format *format, int code)
 Get the sample rate associated with known RTP payload types. More...
 
void ast_rtp_publish_rtcp_message (struct ast_rtp_instance *rtp, struct stasis_message_type *message_type, struct ast_rtp_rtcp_report *report, struct ast_json *blob)
 Publish an RTCP message to Stasis Message Bus API. More...
 
int ast_rtp_red_buffer (struct ast_rtp_instance *instance, struct ast_frame *frame)
 Buffer a frame in an RTP instance for RED. More...
 
int ast_rtp_red_init (struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations)
 Initialize RED support on an RTP instance. More...
 
struct stasis_message_typeast_rtp_rtcp_received_type (void)
 Message type for an RTCP message received from some external source. More...
 
struct ast_rtp_rtcp_reportast_rtp_rtcp_report_alloc (unsigned int report_blocks)
 Allocate an ao2 ref counted instance of ast_rtp_rtcp_report. More...
 
struct stasis_message_typeast_rtp_rtcp_sent_type (void)
 Message type for an RTCP message sent from this Asterisk instance. More...
 
struct stasis_topicast_rtp_topic (void)
 Stasis Message Bus API topic for RTP and RTCP related messages More...
 

Detailed Description

Pluggable RTP Architecture.

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

Definition in file rtp_engine.h.

Macro Definition Documentation

#define ast_debug_dtls (   sublevel,
  ... 
)    ast_debug_category(sublevel, AST_DEBUG_CATEGORY_DTLS, __VA_ARGS__)

Log debug level DTLS information.

Parameters
sublevelDebug output sublevel (>= 0)
...String format and any associated arguments

Definition at line 3051 of file rtp_engine.h.

Referenced by __rtp_recvfrom().

#define ast_debug_ice (   sublevel,
  ... 
)    ast_debug_category(sublevel, AST_DEBUG_CATEGORY_ICE, __VA_ARGS__)

Log debug level ICE information.

Parameters
sublevelDebug output sublevel (>= 0)
...String format and any associated arguments

Definition at line 3063 of file rtp_engine.h.

Referenced by ast_rtp_ice_add_cand(), ast_rtp_ice_add_remote_candidate(), ast_rtp_ice_change_components(), ast_rtp_ice_set_role(), ast_rtp_ice_start(), ast_rtp_ice_stop(), ast_rtp_ice_turn_request(), ice_reset_session(), process_ice_attributes(), and rtp_add_candidates_to_ice().

#define ast_debug_rtcp (   sublevel,
  ... 
)    ast_debug_category(sublevel, AST_DEBUG_CATEGORY_RTCP, __VA_ARGS__)

Log debug level RTCP information.

Parameters
sublevelDebug output sublevel (>= 0)
...String format and any associated arguments

Definition at line 3034 of file rtp_engine.h.

Referenced by ast_rtcp_interpret(), ast_rtp_prop_set(), ast_rtp_read(), ast_rtp_remote_address_set(), ast_rtp_rtcp_handle_nack(), and rtp_raw_write().

#define ast_debug_rtp (   sublevel,
  ... 
)    ast_debug_category(sublevel, AST_DEBUG_CATEGORY_RTP, __VA_ARGS__)

Log debug level RTP information.

Parameters
sublevelDebug output sublevel (>= 0)
...String format and any associated arguments

Definition at line 3017 of file rtp_engine.h.

Referenced by ast_rtp_change_source(), ast_rtp_dtmf_end_with_duration(), ast_rtp_instance_destroy(), ast_rtp_read(), ast_rtp_stop(), ast_rtp_update_source(), ast_rtp_write(), bridge_p2p_rtp_write(), create_rtp(), and rtp_raw_write().

#define AST_RED_MAX_GENERATION   5

Maximum number of generations

Definition at line 98 of file rtp_engine.h.

#define AST_RTP_CISCO_DTMF   (1 << 2)

DTMF (Cisco Proprietary)

Definition at line 298 of file rtp_engine.h.

Referenced by ast_rtp_engine_init().

#define AST_RTP_CN   (1 << 1)

'Comfort Noise' (RFC3389)

Definition at line 296 of file rtp_engine.h.

Referenced by ast_rtp_engine_init(), and ast_rtp_sendcng().

#define AST_RTP_DTMF   (1 << 0)

DTMF (RFC2833)

Definition at line 294 of file rtp_engine.h.

Referenced by ast_rtp_dtmf_begin(), ast_rtp_engine_init(), and create_outgoing_sdp_stream().

#define ast_rtp_instance_get_and_cmp_remote_address (   instance,
  address 
)    ast_rtp_instance_get_and_cmp_requested_target_address((instance), (address))

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

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

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

Since
1.8

Definition at line 1281 of file rtp_engine.h.

Referenced by check_for_rtp_changes().

#define ast_rtp_instance_get_remote_address (   instance,
  address 
)    ast_rtp_instance_get_incoming_source_address((instance), (address))

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

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

Example usage:

1 struct ast_sockaddr address;
2 ast_rtp_instance_get_remote_address(instance, &address);

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

Since
1.8

Definition at line 1245 of file rtp_engine.h.

Referenced by __rtp_recvfrom(), ast_rtcp_write(), ast_rtp_bundle(), ast_rtp_dtmf_begin(), ast_rtp_dtmf_continuation(), ast_rtp_dtmf_end_with_duration(), ast_rtp_prop_set(), ast_rtp_read(), ast_rtp_rtcp_handle_nack(), ast_rtp_sendcng(), ast_rtp_write(), bridge_p2p_rtp_write(), jingle_interpret_ice_udp_transport(), multicast_send_control_packet(), and rtp_raw_write().

#define ast_rtp_instance_set_remote_address (   instance,
  address 
)    ast_rtp_instance_set_requested_target_address((instance), (address))

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

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

Example usage:

1 ast_rtp_instance_set_remote_address(instance, &sin);

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

Since
1.8

Definition at line 1133 of file rtp_engine.h.

Referenced by __rtp_recvfrom(), ast_rtp_bundle(), ast_rtp_read(), ast_rtp_remote_address_set(), ast_rtp_stop(), jingle_interpret_ice_udp_transport(), multicast_rtp_request(), and unicast_rtp_request().

#define AST_RTP_MAX   AST_RTP_CISCO_DTMF

Maximum RTP-specific code

Definition at line 300 of file rtp_engine.h.

Referenced by ast_rtp_lookup_mime_multiple2(), and create_outgoing_sdp_stream().

#define AST_RTP_MAX_PT   128
#define AST_RTP_PT_FIRST_DYNAMIC   96

First dynamic RTP payload type

Definition at line 92 of file rtp_engine.h.

Referenced by handle_show_settings().

#define AST_RTP_PT_LAST_REASSIGN   63

Last reassignable RTP payload type

Definition at line 95 of file rtp_engine.h.

Referenced by handle_show_settings().

#define AST_RTP_PT_LAST_STATIC   34

Last RTP payload type statically assigned, see http://www.iana.org/assignments/rtp-parameters

Definition at line 89 of file rtp_engine.h.

Referenced by ast_rtp_codecs_get_payload(), and ast_rtp_codecs_payloads_set_m_type().

#define AST_RTP_RTCP_FMT_FIR   4

Full INTRA-frame Request (From RFC5104)

Definition at line 337 of file rtp_engine.h.

Referenced by ast_rtcp_interpret().

#define AST_RTP_RTCP_FMT_NACK   1

Generic NACK (From RFC4585 also RFC5104)

Definition at line 333 of file rtp_engine.h.

Referenced by ast_rtcp_interpret().

#define AST_RTP_RTCP_FMT_PLI   1

Picture loss indication (From RFC4585)

Definition at line 335 of file rtp_engine.h.

Referenced by ast_rtcp_interpret().

#define AST_RTP_RTCP_FMT_REMB   15

REMB Information (From draft-alvestrand-rmcat-remb-03)

Definition at line 339 of file rtp_engine.h.

Referenced by ast_rtcp_interpret(), and remb_collector_alloc().

#define AST_RTP_RTCP_FMT_TRANSPORT_WIDE_CC   15

Transport-wide congestion control feedback (From draft-holmer-rmcat-transport-wide-cc-extensions-01)

Definition at line 341 of file rtp_engine.h.

#define AST_RTP_RTCP_PSFB   206

Payload Specific Feed Back (From RFC4585 also RFC5104)

Definition at line 329 of file rtp_engine.h.

Referenced by ast_rtp_write(), and remb_collector_alloc().

#define AST_RTP_RTCP_RR   201

Receiver Report

Definition at line 325 of file rtp_engine.h.

Referenced by lintospeex_feedback().

#define AST_RTP_RTCP_RTPFB   205

Transport Layer Feed Back (From RFC4585 also RFC5104)

Definition at line 327 of file rtp_engine.h.

Referenced by ast_rtcp_interpret().

#define AST_RTP_RTCP_SR   200

Sender Report

Definition at line 323 of file rtp_engine.h.

Referenced by lintospeex_feedback().

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

Definition at line 500 of file rtp_engine.h.

#define MAX_CHANNEL_ID   152

Maximum size of an internal Asterisk channel unique ID.

Note
Must match the AST_MAX_UNIQUEID(AST_MAX_PUBLIC_UNIQUEID) value. We don't use that defined value directly here to avoid a hard dependency on channel.h.DTMF samples per second

Definition at line 107 of file rtp_engine.h.

Enumeration Type Documentation

DTLS connection states.

Enumerator
AST_RTP_DTLS_CONNECTION_NEW 

Endpoint wants to use a new connection

AST_RTP_DTLS_CONNECTION_EXISTING 

Endpoint wishes to use existing connection

Definition at line 572 of file rtp_engine.h.

572  {
573  AST_RTP_DTLS_CONNECTION_NEW, /*!< Endpoint wants to use a new connection */
574  AST_RTP_DTLS_CONNECTION_EXISTING, /*!< Endpoint wishes to use existing connection */
575 };

DTLS fingerprint hashes.

Enumerator
AST_RTP_DTLS_HASH_SHA256 

SHA-256 fingerprint hash

AST_RTP_DTLS_HASH_SHA1 

SHA-1 fingerprint hash

Definition at line 578 of file rtp_engine.h.

578  {
579  AST_RTP_DTLS_HASH_SHA256, /*!< SHA-256 fingerprint hash */
580  AST_RTP_DTLS_HASH_SHA1, /*!< SHA-1 fingerprint hash */
581 };

DTLS setup types.

Enumerator
AST_RTP_DTLS_SETUP_ACTIVE 

Endpoint is willing to inititate connections

AST_RTP_DTLS_SETUP_PASSIVE 

Endpoint is willing to accept connections

AST_RTP_DTLS_SETUP_ACTPASS 

Endpoint is willing to both accept and initiate connections

AST_RTP_DTLS_SETUP_HOLDCONN 

Endpoint does not want the connection to be established right now

Definition at line 564 of file rtp_engine.h.

564  {
565  AST_RTP_DTLS_SETUP_ACTIVE, /*!< Endpoint is willing to inititate connections */
566  AST_RTP_DTLS_SETUP_PASSIVE, /*!< Endpoint is willing to accept connections */
567  AST_RTP_DTLS_SETUP_ACTPASS, /*!< Endpoint is willing to both accept and initiate connections */
568  AST_RTP_DTLS_SETUP_HOLDCONN, /*!< Endpoint does not want the connection to be established right now */
569 };

DTLS verification settings.

Enumerator
AST_RTP_DTLS_VERIFY_NONE 

Don't verify anything

AST_RTP_DTLS_VERIFY_FINGERPRINT 

Verify the fingerprint

AST_RTP_DTLS_VERIFY_CERTIFICATE 

Verify the certificate

Definition at line 584 of file rtp_engine.h.

584  {
585  AST_RTP_DTLS_VERIFY_NONE = 0, /*!< Don't verify anything */
586  AST_RTP_DTLS_VERIFY_FINGERPRINT = (1 << 0), /*!< Verify the fingerprint */
587  AST_RTP_DTLS_VERIFY_CERTIFICATE = (1 << 1), /*!< Verify the certificate */
588 };

RTP DTMF Modes

Enumerator
AST_RTP_DTMF_MODE_NONE 

No DTMF is being carried over the RTP stream

AST_RTP_DTMF_MODE_RFC2833 

DTMF is being carried out of band using RFC2833

AST_RTP_DTMF_MODE_INBAND 

DTMF is being carried inband over the RTP stream

Definition at line 151 of file rtp_engine.h.

151  {
152  /*! No DTMF is being carried over the RTP stream */
154  /*! DTMF is being carried out of band using RFC2833 */
156  /*! DTMF is being carried inband over the RTP stream */
158 };

Known RTP extensions.

Enumerator
AST_RTP_EXTENSION_UNSUPPORTED 

Per the RFC 0 should not be used, so we treat it as an unsupported extension placeholder

AST_RTP_EXTENSION_ABS_SEND_TIME 

abs-send-time from https://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03

AST_RTP_EXTENSION_TRANSPORT_WIDE_CC 

transport-cc from https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01

AST_RTP_EXTENSION_MAX 

The maximum number of known RTP extensions

Definition at line 593 of file rtp_engine.h.

593  {
594  /*! Per the RFC 0 should not be used, so we treat it as an unsupported extension placeholder */
596  /*! abs-send-time from https://tools.ietf.org/html/draft-alvestrand-rmcat-remb-03 */
598  /*! transport-cc from https://tools.ietf.org/html/draft-holmer-rmcat-transport-wide-cc-extensions-01 */
600  /*! The maximum number of known RTP extensions */
602 };

Directions for RTP extensions.

Enumerator
AST_RTP_EXTENSION_DIRECTION_NONE 

The extension is not negotiated and is not flowing

AST_RTP_EXTENSION_DIRECTION_SENDRECV 

Send and receive

AST_RTP_EXTENSION_DIRECTION_SENDONLY 

Send only

AST_RTP_EXTENSION_DIRECTION_RECVONLY 

Receive only

AST_RTP_EXTENSION_DIRECTION_INACTIVE 

Negotiated but not sending or receiving

Definition at line 822 of file rtp_engine.h.

822  {
823  /*! The extension is not negotiated and is not flowing */
825  /*! Send and receive */
827  /*! Send only */
829  /*! Receive only */
831  /*! Negotiated but not sending or receiving */
833 };

Result codes when RTP glue is queried for information

Enumerator
AST_RTP_GLUE_RESULT_FORBID 

No remote or local bridging is permitted

AST_RTP_GLUE_RESULT_REMOTE 

Move RTP stream to be remote between devices directly

AST_RTP_GLUE_RESULT_LOCAL 

Perform RTP engine level bridging if possible

Definition at line 161 of file rtp_engine.h.

161  {
162  /*! No remote or local bridging is permitted */
164  /*! Move RTP stream to be remote between devices directly */
166  /*! Perform RTP engine level bridging if possible */
168 };

ICE candidate types.

Enumerator
AST_RTP_ICE_CANDIDATE_TYPE_HOST 

ICE host candidate. A host candidate represents the actual local transport address in the host.

AST_RTP_ICE_CANDIDATE_TYPE_SRFLX 

ICE server reflexive candidate, which represents the public mapped address of the local address.

AST_RTP_ICE_CANDIDATE_TYPE_RELAYED 

ICE relayed candidate, which represents the address allocated in TURN server.

Definition at line 506 of file rtp_engine.h.

506  {
507  AST_RTP_ICE_CANDIDATE_TYPE_HOST, /*!< ICE host candidate. A host candidate represents the actual local transport address in the host. */
508  AST_RTP_ICE_CANDIDATE_TYPE_SRFLX, /*!< ICE server reflexive candidate, which represents the public mapped address of the local address. */
509  AST_RTP_ICE_CANDIDATE_TYPE_RELAYED, /*!< ICE relayed candidate, which represents the address allocated in TURN server. */
510 };
Enumerator
AST_RTP_INSTANCE_RTCP_DISABLED 

RTCP should not be sent/received

AST_RTP_INSTANCE_RTCP_STANDARD 

RTCP should be sent/received based on standard port rules

AST_RTP_INSTANCE_RTCP_MUX 

RTCP should be sent/received on the same port as RTP

Definition at line 283 of file rtp_engine.h.

283  {
284  /*! RTCP should not be sent/received */
286  /*! RTCP should be sent/received based on standard port rules */
288  /*! RTCP should be sent/received on the same port as RTP */
290 };

Statistics that can be retrieved from an RTP instance

Enumerator
AST_RTP_INSTANCE_STAT_ALL 

Retrieve all statistics

AST_RTP_INSTANCE_STAT_TXCOUNT 

Retrieve number of packets transmitted

AST_RTP_INSTANCE_STAT_RXCOUNT 

Retrieve number of packets received

AST_RTP_INSTANCE_STAT_COMBINED_LOSS 

Retrieve ALL statistics relating to packet loss

AST_RTP_INSTANCE_STAT_TXPLOSS 

Retrieve number of packets lost for transmitting

AST_RTP_INSTANCE_STAT_RXPLOSS 

Retrieve number of packets lost for receiving

AST_RTP_INSTANCE_STAT_REMOTE_MAXRXPLOSS 

Retrieve maximum number of packets lost on remote side

AST_RTP_INSTANCE_STAT_REMOTE_MINRXPLOSS 

Retrieve minimum number of packets lost on remote side

AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVRXPLOSS 

Retrieve average number of packets lost on remote side

AST_RTP_INSTANCE_STAT_REMOTE_STDEVRXPLOSS 

Retrieve standard deviation of packets lost on remote side

AST_RTP_INSTANCE_STAT_LOCAL_MAXRXPLOSS 

Retrieve maximum number of packets lost on local side

AST_RTP_INSTANCE_STAT_LOCAL_MINRXPLOSS 

Retrieve minimum number of packets lost on local side

AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVRXPLOSS 

Retrieve average number of packets lost on local side

AST_RTP_INSTANCE_STAT_LOCAL_STDEVRXPLOSS 

Retrieve standard deviation of packets lost on local side

AST_RTP_INSTANCE_STAT_COMBINED_JITTER 

Retrieve ALL statistics relating to jitter

AST_RTP_INSTANCE_STAT_TXJITTER 

Retrieve jitter on transmitted packets

AST_RTP_INSTANCE_STAT_RXJITTER 

Retrieve jitter on received packets

AST_RTP_INSTANCE_STAT_REMOTE_MAXJITTER 

Retrieve maximum jitter on remote side

AST_RTP_INSTANCE_STAT_REMOTE_MINJITTER 

Retrieve minimum jitter on remote side

AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVJITTER 

Retrieve average jitter on remote side

AST_RTP_INSTANCE_STAT_REMOTE_STDEVJITTER 

Retrieve standard deviation jitter on remote side

AST_RTP_INSTANCE_STAT_LOCAL_MAXJITTER 

Retrieve maximum jitter on local side

AST_RTP_INSTANCE_STAT_LOCAL_MINJITTER 

Retrieve minimum jitter on local side

AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVJITTER 

Retrieve average jitter on local side

AST_RTP_INSTANCE_STAT_LOCAL_STDEVJITTER 

Retrieve standard deviation jitter on local side

AST_RTP_INSTANCE_STAT_COMBINED_RTT 

Retrieve ALL statistics relating to round trip time

AST_RTP_INSTANCE_STAT_RTT 

Retrieve round trip time

AST_RTP_INSTANCE_STAT_MAX_RTT 

Retrieve maximum round trip time

AST_RTP_INSTANCE_STAT_MIN_RTT 

Retrieve minimum round trip time

AST_RTP_INSTANCE_STAT_NORMDEVRTT 

Retrieve average round trip time

AST_RTP_INSTANCE_STAT_STDEVRTT 

Retrieve standard deviation round trip time

AST_RTP_INSTANCE_STAT_LOCAL_SSRC 

Retrieve local SSRC

AST_RTP_INSTANCE_STAT_REMOTE_SSRC 

Retrieve remote SSRC

AST_RTP_INSTANCE_STAT_CHANNEL_UNIQUEID 

Retrieve channel unique ID

AST_RTP_INSTANCE_STAT_TXOCTETCOUNT 

Retrieve number of octets transmitted

AST_RTP_INSTANCE_STAT_RXOCTETCOUNT 

Retrieve number of octets received

AST_RTP_INSTANCE_STAT_COMBINED_MES 

Retrieve ALL statistics relating to Media Experience Score

AST_RTP_INSTANCE_STAT_TXMES 

Retrieve MES on transmitted packets

AST_RTP_INSTANCE_STAT_RXMES 

Retrieve MES on received packets

AST_RTP_INSTANCE_STAT_REMOTE_MAXMES 

Retrieve maximum MES on remote side

AST_RTP_INSTANCE_STAT_REMOTE_MINMES 

Retrieve minimum MES on remote side

AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVMES 

Retrieve average MES on remote side

AST_RTP_INSTANCE_STAT_REMOTE_STDEVMES 

Retrieve standard deviation MES on remote side

AST_RTP_INSTANCE_STAT_LOCAL_MAXMES 

Retrieve maximum MES on local side

AST_RTP_INSTANCE_STAT_LOCAL_MINMES 

Retrieve minimum MES on local side

AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVMES 

Retrieve average MES on local side

AST_RTP_INSTANCE_STAT_LOCAL_STDEVMES 

Retrieve standard deviation MES on local side

Definition at line 185 of file rtp_engine.h.

185  {
186  /*! Retrieve all statistics */
188  /*! Retrieve number of packets transmitted */
190  /*! Retrieve number of packets received */
192  /*! Retrieve ALL statistics relating to packet loss */
194  /*! Retrieve number of packets lost for transmitting */
196  /*! Retrieve number of packets lost for receiving */
198  /*! Retrieve maximum number of packets lost on remote side */
200  /*! Retrieve minimum number of packets lost on remote side */
202  /*! Retrieve average number of packets lost on remote side */
204  /*! Retrieve standard deviation of packets lost on remote side */
206  /*! Retrieve maximum number of packets lost on local side */
208  /*! Retrieve minimum number of packets lost on local side */
210  /*! Retrieve average number of packets lost on local side */
212  /*! Retrieve standard deviation of packets lost on local side */
214  /*! Retrieve ALL statistics relating to jitter */
216  /*! Retrieve jitter on transmitted packets */
218  /*! Retrieve jitter on received packets */
220  /*! Retrieve maximum jitter on remote side */
222  /*! Retrieve minimum jitter on remote side */
224  /*! Retrieve average jitter on remote side */
226  /*! Retrieve standard deviation jitter on remote side */
228  /*! Retrieve maximum jitter on local side */
230  /*! Retrieve minimum jitter on local side */
232  /*! Retrieve average jitter on local side */
234  /*! Retrieve standard deviation jitter on local side */
236  /*! Retrieve ALL statistics relating to round trip time */
238  /*! Retrieve round trip time */
240  /*! Retrieve maximum round trip time */
242  /*! Retrieve minimum round trip time */
244  /*! Retrieve average round trip time */
246  /*! Retrieve standard deviation round trip time */
248  /*! Retrieve local SSRC */
250  /*! Retrieve remote SSRC */
252  /*! Retrieve channel unique ID */
254  /*! Retrieve number of octets transmitted */
256  /*! Retrieve number of octets received */
258 
259  /*! Retrieve ALL statistics relating to Media Experience Score */
261  /*! Retrieve MES on transmitted packets */
263  /*! Retrieve MES on received packets */
265  /*! Retrieve maximum MES on remote side */
267  /*! Retrieve minimum MES on remote side */
269  /*! Retrieve average MES on remote side */
271  /*! Retrieve standard deviation MES on remote side */
273  /*! Retrieve maximum MES on local side */
275  /*! Retrieve minimum MES on local side */
277  /*! Retrieve average MES on local side */
279  /*! Retrieve standard deviation MES on local side */
281 };

Field statistics that can be retrieved from an RTP instance

Enumerator
AST_RTP_INSTANCE_STAT_FIELD_QUALITY 

Retrieve quality information

AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER 

Retrieve quality information about jitter

AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS 

Retrieve quality information about packet loss

AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT 

Retrieve quality information about round trip time

AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES 

Retrieve quality information about Media Experience Score

Definition at line 171 of file rtp_engine.h.

171  {
172  /*! Retrieve quality information */
174  /*! Retrieve quality information about jitter */
176  /*! Retrieve quality information about packet loss */
178  /*! Retrieve quality information about round trip time */
180  /*! Retrieve quality information about Media Experience Score */
182 };

Additional RTP options

Enumerator
AST_RTP_OPT_G726_NONSTANDARD 

Remote side is using non-standard G.726

Definition at line 145 of file rtp_engine.h.

145  {
146  /*! Remote side is using non-standard G.726 */
147  AST_RTP_OPT_G726_NONSTANDARD = (1 << 0),
148 };

RTP Properties that can be set on an RTP instance

Enumerator
AST_RTP_PROPERTY_NAT 

Enable symmetric RTP support

AST_RTP_PROPERTY_DTMF 

RTP instance will be carrying DTMF (using RFC2833)

AST_RTP_PROPERTY_DTMF_COMPENSATE 

Expect unreliable DTMF from remote party

AST_RTP_PROPERTY_STUN 

Enable STUN support

AST_RTP_PROPERTY_RTCP 

Enable RTCP support

AST_RTP_PROPERTY_ASYMMETRIC_CODEC 

Enable Asymmetric RTP Codecs

AST_RTP_PROPERTY_RETRANS_RECV 

Enable packet retransmission for received packets

AST_RTP_PROPERTY_RETRANS_SEND 

Enable packet retransmission for sent packets

AST_RTP_PROPERTY_REMB 

Enable REMB sending and receiving passthrough support

AST_RTP_PROPERTY_MAX 

Maximum number of RTP properties supported.

Note
THIS MUST BE THE LAST ENTRY IN THIS ENUM.

Definition at line 116 of file rtp_engine.h.

116  {
117  /*! Enable symmetric RTP support */
119  /*! RTP instance will be carrying DTMF (using RFC2833) */
121  /*! Expect unreliable DTMF from remote party */
123  /*! Enable STUN support */
125  /*! Enable RTCP support */
127  /*! Enable Asymmetric RTP Codecs */
129  /*! Enable packet retransmission for received packets */
131  /*! Enable packet retransmission for sent packets */
133  /*! Enable REMB sending and receiving passthrough support */
135 
136  /*!
137  * \brief Maximum number of RTP properties supported
138  *
139  * \note THIS MUST BE THE LAST ENTRY IN THIS ENUM.
140  */
142 };
Maximum number of RTP properties supported.
Definition: rtp_engine.h:141

Function Documentation

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:

1 int payload = ast_rtp_codecs_find_payload_code(&codecs, 0);

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

Definition at line 2099 of file rtp_engine.c.

References AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_codecs::codecs_lock, ast_rtp_payload_type::payload, and ast_rtp_codecs::payload_mapping_tx.

Referenced by bridge_p2p_rtp_write().

2100 {
2101  struct ast_rtp_payload_type *type;
2102  int res = -1;
2103 
2104  ast_rwlock_rdlock(&codecs->codecs_lock);
2105  if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
2106  type = AST_VECTOR_GET(&codecs->payload_mapping_tx, payload);
2107  if (type) {
2108  res = payload;
2109  }
2110  }
2111  ast_rwlock_unlock(&codecs->codecs_lock);
2112 
2113  return res;
2114 }
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
struct ast_rtp_codecs::@281 payload_mapping_tx
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
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 1640 of file rtp_engine.c.

References ast_rtp_codecs::codecs_lock, and ast_rtp_codecs::framing.

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

1641 {
1642  unsigned int framing;
1643 
1644  ast_rwlock_rdlock(&codecs->codecs_lock);
1645  framing = codecs->framing;
1646  ast_rwlock_unlock(&codecs->codecs_lock);
1647 
1648  return framing;
1649 }
unsigned int framing
Definition: rtp_engine.h:764
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
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:

1 struct ast_rtp_payload_type *payload_type;
2 payload_type = ast_rtp_codecs_get_payload(&codecs, 0);

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

Definition at line 1533 of file rtp_engine.c.

References ao2_bump, AST_RTP_MAX_PT, AST_RTP_PT_LAST_STATIC, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_codecs::codecs_lock, and ast_rtp_codecs::payload_mapping_rx.

Referenced by bridge_p2p_rtp_write().

1534 {
1535  struct ast_rtp_payload_type *type = NULL;
1536 
1537  if (payload < 0 || payload >= AST_RTP_MAX_PT) {
1538  return NULL;
1539  }
1540 
1541  ast_rwlock_rdlock(&codecs->codecs_lock);
1542  if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_rx)) {
1543  type = AST_VECTOR_GET(&codecs->payload_mapping_rx, payload);
1544  ao2_bump(type);
1545  }
1546  ast_rwlock_unlock(&codecs->codecs_lock);
1547 
1548  if (!type && payload <= AST_RTP_PT_LAST_STATIC) {
1549  ast_rwlock_rdlock(&static_RTP_PT_lock);
1550  type = ao2_bump(static_RTP_PT[payload]);
1551  ast_rwlock_unlock(&static_RTP_PT_lock);
1552  }
1553 
1554  return type;
1555 }
#define AST_RTP_PT_LAST_STATIC
Definition: rtp_engine.h:89
struct ast_rtp_codecs::@280 payload_mapping_rx
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
#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
static struct ast_rtp_payload_type * static_RTP_PT[AST_RTP_MAX_PT]
Mapping between Asterisk codecs and rtp payload types.
Definition: rtp_engine.c:273
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
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 1608 of file rtp_engine.c.

References ao2_bump, AST_RTP_MAX_PT, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_payload_type::asterisk_format, ast_rtp_codecs::codecs_lock, ast_rtp_payload_type::format, and ast_rtp_codecs::payload_mapping_tx.

1609 {
1610  struct ast_rtp_payload_type *type;
1611  struct ast_format *format = NULL;
1612 
1613  if (payload < 0 || payload >= AST_RTP_MAX_PT) {
1614  return NULL;
1615  }
1616 
1617  ast_rwlock_rdlock(&codecs->codecs_lock);
1618  if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1619  type = AST_VECTOR_GET(&codecs->payload_mapping_tx, payload);
1620  if (type && type->asterisk_format) {
1621  format = ao2_bump(type->format);
1622  }
1623  }
1624  ast_rwlock_unlock(&codecs->codecs_lock);
1625 
1626  return format;
1627 }
Definition of a media format.
Definition: format.c:43
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
#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
struct ast_rtp_codecs::@281 payload_mapping_tx
struct ast_format * format
Definition: rtp_engine.h:306
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
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:

1 struct ast_format *payload_format;
2 payload_format = ast_rtp_codecs_get_preferred_format(&codecs);

This looks up the preferred format on the codec

Definition at line 1557 of file rtp_engine.c.

References ao2_bump, ast_rtp_codecs::codecs_lock, and ast_rtp_codecs::preferred_format.

Referenced by ast_rtp_dtmf_begin().

1558 {
1559  struct ast_format *format;
1560  ast_rwlock_rdlock(&codecs->codecs_lock);
1561  format = ao2_bump(codecs->preferred_format);
1562  ast_rwlock_unlock(&codecs->codecs_lock);
1563  return format;
1564 }
Definition of a media format.
Definition: format.c:43
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
struct ast_format * preferred_format
Definition: rtp_engine.h:766
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 1514 of file rtp_engine.c.

References ast_format_get_type(), AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_payload_type::asterisk_format, ast_rtp_codecs::codecs_lock, ast_rtp_payload_type::format, ast_rtp_payload_type::payload, and ast_rtp_codecs::payload_mapping_rx.

Referenced by ast_rtp_read().

1515 {
1516  enum ast_media_type stream_type = AST_MEDIA_TYPE_UNKNOWN;
1517  int payload;
1518  struct ast_rtp_payload_type *type;
1519 
1520  ast_rwlock_rdlock(&codecs->codecs_lock);
1521  for (payload = 0; payload < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++payload) {
1522  type = AST_VECTOR_GET(&codecs->payload_mapping_rx, payload);
1523  if (type && type->asterisk_format) {
1524  stream_type = ast_format_get_type(type->format);
1525  break;
1526  }
1527  }
1528  ast_rwlock_unlock(&codecs->codecs_lock);
1529 
1530  return stream_type;
1531 }
enum ast_media_type ast_format_get_type(const struct ast_format *format)
Get the media type of a format.
Definition: format.c:354
struct ast_rtp_codecs::@280 payload_mapping_rx
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
struct ast_format * format
Definition: rtp_engine.h:306
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
ast_media_type
Types of media.
Definition: codec.h:30
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
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:

1 int payload = ast_rtp_codecs_payload_code(&codecs, 1, ast_format_ulaw, 0);

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

Since
1.8

Definition at line 1977 of file rtp_engine.c.

References ast_rtp_codecs_payload_code_sample_rate().

Referenced by create_outgoing_sdp_stream(), and jingle_add_payloads_to_description().

1978 {
1979  return ast_rtp_codecs_payload_code_sample_rate(codecs, asterisk_format, format, code, 0);
1980 }
int ast_rtp_codecs_payload_code_sample_rate(struct ast_rtp_codecs *codecs, int asterisk_format, struct ast_format *format, int code, unsigned int sample_rate)
Retrieve a rx mapped payload type based on whether it is an Asterisk format, the code and the sample ...
Definition: rtp_engine.c:1982
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:

1 int payload = ast_rtp_codecs_payload_code_sample_rate(&codecs, 0, NULL, AST_RTP_DTMF, 8000);

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

References ast_format_cmp(), AST_FORMAT_CMP_EQUAL, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_payload_type::asterisk_format, ast_rtp_codecs::codecs_lock, ast_rtp_payload_type::format, ast_rtp_payload_type::payload, ast_rtp_codecs::payload_mapping_rx, ast_rtp_payload_type::primary_mapping, ast_rtp_payload_type::rtp_code, and ast_rtp_payload_type::sample_rate.

Referenced by ast_rtp_codecs_payload_code(), and create_outgoing_sdp_stream().

1983 {
1984  struct ast_rtp_payload_type *type;
1985  int idx;
1986  int payload = -1;
1987 
1988  ast_rwlock_rdlock(&static_RTP_PT_lock);
1989  if (!asterisk_format) {
1990  ast_rwlock_rdlock(&codecs->codecs_lock);
1991  for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
1992  type = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
1993  if (!type) {
1994  continue;
1995  }
1996 
1997  if (!type->asterisk_format
1998  && type->primary_mapping
1999  && type->rtp_code == code
2000  && (sample_rate == 0 || type->sample_rate == sample_rate)) {
2001  payload = idx;
2002  break;
2003  }
2004  }
2005  ast_rwlock_unlock(&codecs->codecs_lock);
2006  } else if (format) {
2007  ast_rwlock_rdlock(&codecs->codecs_lock);
2008  for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
2009  type = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
2010  if (!type) {
2011  continue;
2012  }
2013 
2014  if (type->asterisk_format
2015  && type->primary_mapping
2016  && ast_format_cmp(format, type->format) == AST_FORMAT_CMP_EQUAL) {
2017  payload = idx;
2018  break;
2019  }
2020  }
2021  ast_rwlock_unlock(&codecs->codecs_lock);
2022  }
2023 
2024  if (payload < 0) {
2025  payload = rtp_codecs_assign_payload_code_rx(codecs, asterisk_format, format,
2026  code, 0, sample_rate);
2027  }
2028  ast_rwlock_unlock(&static_RTP_PT_lock);
2029 
2030  return payload;
2031 }
struct ast_rtp_codecs::@280 payload_mapping_rx
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
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
struct ast_format * format
Definition: rtp_engine.h:306
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
unsigned int sample_rate
Definition: rtp_engine.h:318
unsigned int primary_mapping
Definition: rtp_engine.h:314
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
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 2094 of file rtp_engine.c.

References ast_rtp_codecs_payload_code_tx_sample_rate().

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

2095 {
2096  return ast_rtp_codecs_payload_code_tx_sample_rate(codecs, asterisk_format, format, code, 0);
2097 }
int ast_rtp_codecs_payload_code_tx_sample_rate(struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code, unsigned int sample_rate)
Retrieve a tx mapped payload type based on whether it is an Asterisk format and the code...
Definition: rtp_engine.c:2043
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 2043 of file rtp_engine.c.

References ast_format_cmp(), AST_FORMAT_CMP_EQUAL, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_payload_type::asterisk_format, ast_rtp_codecs::codecs_lock, ast_rtp_payload_type::format, ast_rtp_payload_type::payload, ast_rtp_codecs::payload_mapping_tx, ast_rtp_payload_type::rtp_code, and ast_rtp_payload_type::sample_rate.

Referenced by ast_rtp_codecs_payload_code_tx(), and ast_rtp_dtmf_begin().

2044 {
2045  struct ast_rtp_payload_type *type;
2046  int idx;
2047  int payload = -1;
2048 
2049  if (!asterisk_format) {
2050  ast_rwlock_rdlock(&codecs->codecs_lock);
2051  for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
2052  type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
2053  if (!type) {
2054  continue;
2055  }
2056 
2057  if (!type->asterisk_format
2058  && type->rtp_code == code
2059  /* Multiple DTMF types share an rtp code but have different sample rates. To ensure we have the right
2060  type we therefore need the sample rate as well as the format and code. Other types have a fixed
2061  sample rate so this is not needed. For those pass in a sample rate of 0 or use ast_rtp_codecs_payload_code_tx. */
2062  && (sample_rate == 0 || type->sample_rate == sample_rate)) {
2063  payload = idx;
2064  break;
2065  }
2066  }
2067  ast_rwlock_unlock(&codecs->codecs_lock);
2068  } else if (format) {
2069  ast_rwlock_rdlock(&codecs->codecs_lock);
2070  for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
2071  type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
2072  if (!type) {
2073  continue;
2074  }
2075 
2076  if (type->asterisk_format
2077  && ast_format_cmp(format, type->format) == AST_FORMAT_CMP_EQUAL) {
2078  payload = idx;
2079  break;
2080  }
2081  }
2082  ast_rwlock_unlock(&codecs->codecs_lock);
2083  }
2084 
2085  if (payload < 0) {
2086  ast_rwlock_rdlock(&static_RTP_PT_lock);
2087  payload = find_static_payload_type(asterisk_format, format, code);
2088  ast_rwlock_unlock(&static_RTP_PT_lock);
2089  }
2090 
2091  return payload;
2092 }
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
struct ast_rtp_codecs::@281 payload_mapping_tx
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
struct ast_format * format
Definition: rtp_engine.h:306
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
unsigned int sample_rate
Definition: rtp_engine.h:318
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
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:

1 struct ast_format_cap *astformats = ast_format_cap_alloc_nolock()
2 int nonastformats;
3 ast_rtp_codecs_payload_formats(&codecs, astformats, &nonastformats);

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

Since
1.8

Definition at line 1651 of file rtp_engine.c.

References ast_format_cap_append, ast_format_cap_remove_by_type(), ast_format_cap_set_framing(), AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_payload_type::asterisk_format, ast_rtp_codecs::codecs_lock, ast_rtp_payload_type::format, ast_rtp_codecs::framing, ast_rtp_codecs::payload_mapping_tx, and ast_rtp_payload_type::rtp_code.

Referenced by jingle_interpret_description().

1652 {
1653  int idx;
1654 
1655  ast_format_cap_remove_by_type(astformats, AST_MEDIA_TYPE_UNKNOWN);
1656  *nonastformats = 0;
1657 
1658  ast_rwlock_rdlock(&codecs->codecs_lock);
1659 
1660  for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
1661  struct ast_rtp_payload_type *type;
1662 
1663  type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
1664  if (!type) {
1665  continue;
1666  }
1667 
1668  if (type->asterisk_format) {
1669  ast_format_cap_append(astformats, type->format, 0);
1670  } else {
1671  *nonastformats |= type->rtp_code;
1672  }
1673  }
1674  if (codecs->framing) {
1675  ast_format_cap_set_framing(astformats, codecs->framing);
1676  }
1677 
1678  ast_rwlock_unlock(&codecs->codecs_lock);
1679 }
unsigned int framing
Definition: rtp_engine.h:764
void ast_format_cap_set_framing(struct ast_format_cap *cap, unsigned int framing)
Set the global framing.
Definition: format_cap.c:136
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
struct ast_rtp_codecs::@281 payload_mapping_tx
#define ast_format_cap_append(cap, format, framing)
Add format capability to capabilities structure.
Definition: format_cap.h:99
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
struct ast_format * format
Definition: rtp_engine.h:306
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
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 1574 of file rtp_engine.c.

References ao2_ref, ast_rtp_engine_alloc_payload_type(), AST_RTP_MAX_PT, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, ast_rtp_payload_type::asterisk_format, ast_rtp_codecs::codecs_lock, ast_rtp_payload_type::format, ast_rtp_payload_type::payload, ast_rtp_codecs::payload_mapping_tx, and ast_rtp_payload_type::primary_mapping.

1575 {
1576  struct ast_rtp_payload_type *type;
1577 
1578  if (payload < 0 || payload >= AST_RTP_MAX_PT || !format) {
1579  return -1;
1580  }
1581 
1583  if (!type) {
1584  return -1;
1585  }
1586  ao2_ref(format, +1);
1587  type->format = format;
1588  type->asterisk_format = 1;
1589  type->payload = payload;
1590  type->primary_mapping = 1;
1591 
1592  ast_rwlock_wrlock(&codecs->codecs_lock);
1593  if (!payload_mapping_tx_is_present(codecs, type)) {
1594  if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1595  ao2_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, payload));
1596  }
1597  if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, type)) {
1598  ao2_ref(type, -1);
1599  }
1600  } else {
1601  ao2_ref(type, -1);
1602  }
1603  ast_rwlock_unlock(&codecs->codecs_lock);
1604 
1605  return 0;
1606 }
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:83
struct ast_rtp_codecs::@281 payload_mapping_tx
struct ast_rtp_payload_type * ast_rtp_engine_alloc_payload_type(void)
Allocation routine for ast_rtp_payload_type.
Definition: rtp_engine.c:325
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
struct ast_format * format
Definition: rtp_engine.h:306
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
#define AST_VECTOR_REPLACE(vec, idx, elem)
Replace an element at a specific position in a vector, growing the vector if needed.
Definition: vector.h:284
unsigned int primary_mapping
Definition: rtp_engine.h:314
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
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 2033 of file rtp_engine.c.

Referenced by create_outgoing_sdp_stream().

2034 {
2035  return rtp_codecs_assign_payload_code_rx(codecs, 1, format, code, 1, 0);
2036 }
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 2038 of file rtp_engine.c.

2039 {
2040  return rtp_codecs_assign_payload_code_rx(codecs, 1, format, code, 0, sample_rate);
2041 }
unsigned int sample_rate
Definition: rtp_engine.h:318
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:

1 struct ast_rtp_codecs codecs;
2 ast_rtp_codecs_payloads_clear(&codecs, NULL);

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

Since
1.8

Definition at line 1018 of file rtp_engine.c.

References ast_rtp_codecs_payloads_destroy(), ast_rtp_codecs_payloads_initialize(), AST_RTP_MAX_PT, ast_rtp_instance::engine, and ast_rtp_engine::payload_set.

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

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

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

Since
1.8

Definition at line 1262 of file rtp_engine.c.

References ao2_replace, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, ast_rtp_codecs::codecs_lock, ast_rtp_codecs::framing, ast_rtp_codecs::payload_mapping_tx, and ast_rtp_codecs::preferred_format.

Referenced by jingle_interpret_description().

1263 {
1264  int idx;
1265  struct ast_rtp_payload_type *type;
1266 
1267  ast_rwlock_wrlock(&dest->codecs_lock);
1268 
1269  /* Deadlock avoidance because of held write lock. */
1270  while (ast_rwlock_tryrdlock(&src->codecs_lock)) {
1271  ast_rwlock_unlock(&dest->codecs_lock);
1272  sched_yield();
1273  ast_rwlock_wrlock(&dest->codecs_lock);
1274  }
1275 
1276  /*
1277  * This represents a completely new mapping of what the remote party is
1278  * expecting for payloads, so we clear out the entire tx payload mapping
1279  * vector and replace it.
1280  */
1281  for (idx = 0; idx < AST_VECTOR_SIZE(&dest->payload_mapping_tx); ++idx) {
1282  type = AST_VECTOR_GET(&dest->payload_mapping_tx, idx);
1283  ao2_t_cleanup(type, "destroying ast_rtp_codec tx mapping");
1284  AST_VECTOR_REPLACE(&dest->payload_mapping_tx, idx, NULL);
1285  }
1286 
1287  rtp_codecs_payloads_copy_rx(src, dest, instance);
1288  rtp_codecs_payloads_copy_tx(src, dest, instance);
1289  dest->framing = src->framing;
1291 
1292  ast_rwlock_unlock(&src->codecs_lock);
1293  ast_rwlock_unlock(&dest->codecs_lock);
1294 }
unsigned int framing
Definition: rtp_engine.h:764
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
struct ast_rtp_codecs::@281 payload_mapping_tx
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
Definition: astobj2.h:501
#define AST_VECTOR_REPLACE(vec, idx, elem)
Replace an element at a specific position in a vector, growing the vector if needed.
Definition: vector.h:284
struct ast_format * preferred_format
Definition: rtp_engine.h:766
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
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:

1 struct ast_rtp_codecs codecs;
2 ast_rtp_codecs_payloads_destroy(&codecs);
Since
11

Definition at line 996 of file rtp_engine.c.

References AST_VECTOR_FREE, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_codecs::codecs_lock, ast_rtp_codecs::payload_mapping_rx, ast_rtp_codecs::payload_mapping_tx, and ast_rtp_codecs::preferred_format.

Referenced by ast_rtp_codecs_payloads_clear(), ast_stream_free(), ast_stream_set_rtp_codecs(), and jingle_interpret_description().

997 {
998  int idx;
999  struct ast_rtp_payload_type *type;
1000 
1001  for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
1002  type = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
1003  ao2_t_cleanup(type, "destroying ast_rtp_codec rx mapping");
1004  }
1006 
1007  for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
1008  type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
1009  ao2_t_cleanup(type, "destroying ast_rtp_codec tx mapping");
1010  }
1012 
1013  ao2_t_cleanup(codecs->preferred_format, "destroying ast_rtp_codec preferred format");
1014 
1015  ast_rwlock_destroy(&codecs->codecs_lock);
1016 }
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
struct ast_rtp_codecs::@280 payload_mapping_rx
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
struct ast_rtp_codecs::@281 payload_mapping_tx
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
struct ast_format * preferred_format
Definition: rtp_engine.h:766
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
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:

1 struct ast_rtp_codecs codecs;
2 ast_rtp_codecs_payloads_initialize(&codecs);
Since
11

Definition at line 980 of file rtp_engine.c.

References AST_RTP_MAX_PT, ast_rwlock_init, AST_VECTOR_FREE, AST_VECTOR_INIT, ast_rtp_codecs::codecs_lock, ast_rtp_codecs::framing, ast_rtp_codecs::payload_mapping_rx, and ast_rtp_codecs::payload_mapping_tx.

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

981 {
982  int res;
983 
984  codecs->framing = 0;
985  ast_rwlock_init(&codecs->codecs_lock);
988  if (res) {
991  }
992 
993  return res;
994 }
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
unsigned int framing
Definition: rtp_engine.h:764
#define ast_rwlock_init(rwlock)
wrapper for rwlock with tracking enabled
Definition: lock.h:224
struct ast_rtp_codecs::@280 payload_mapping_rx
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:83
struct ast_rtp_codecs::@281 payload_mapping_tx
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
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:

1 ast_rtp_codecs_payloads_set_m_type(&codecs, NULL, 0);

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

Since
1.8

Definition at line 1341 of file rtp_engine.c.

References ao2_bump, ao2_ref, ast_debug, AST_RTP_MAX_PT, AST_RTP_PT_LAST_STATIC, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, ast_rtp_payload_type::asterisk_format, ast_rtp_codecs::codecs_lock, ast_rtp_instance::engine, ast_rtp_payload_type::format, ast_rtp_codecs::payload_mapping_tx, ast_rtp_engine::payload_set, and ast_rtp_payload_type::rtp_code.

1342 {
1343  struct ast_rtp_payload_type *new_type;
1344 
1345  if (payload < 0 || payload >= AST_RTP_MAX_PT || payload > AST_RTP_PT_LAST_STATIC) {
1346  return;
1347  }
1348 
1349  ast_rwlock_rdlock(&static_RTP_PT_lock);
1350  new_type = ao2_bump(static_RTP_PT[payload]);
1351  ast_rwlock_unlock(&static_RTP_PT_lock);
1352  if (!new_type) {
1353  ast_debug(1, "Don't have a default tx payload type %d format for m type on %p\n",
1354  payload, codecs);
1355  return;
1356  }
1357 
1358  ast_debug(1, "Setting tx payload type %d based on m type on %p\n",
1359  payload, codecs);
1360 
1361  ast_rwlock_wrlock(&codecs->codecs_lock);
1362 
1363  if (!payload_mapping_tx_is_present(codecs, new_type)) {
1364  if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1365  ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, payload),
1366  "cleaning up replaced tx payload type");
1367  }
1368 
1369  if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, new_type)) {
1370  ao2_ref(new_type, -1);
1371  } else if (instance && instance->engine && instance->engine->payload_set) {
1372  ao2_lock(instance);
1373  instance->engine->payload_set(instance, payload, new_type->asterisk_format, new_type->format, new_type->rtp_code);
1374  ao2_unlock(instance);
1375  }
1376  } else {
1377  ao2_ref(new_type, -1);
1378  }
1379 
1380  ast_rwlock_unlock(&codecs->codecs_lock);
1381 }
void(* payload_set)(struct ast_rtp_instance *instance, int payload, int asterisk_format, struct ast_format *format, int code)
Definition: rtp_engine.h:694
#define AST_RTP_PT_LAST_STATIC
Definition: rtp_engine.h:89
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
#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
struct ast_rtp_codecs::@281 payload_mapping_tx
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ast_debug(level,...)
Log a DEBUG message.
struct ast_format * format
Definition: rtp_engine.h:306
static struct ast_rtp_payload_type * static_RTP_PT[AST_RTP_MAX_PT]
Mapping between Asterisk codecs and rtp payload types.
Definition: rtp_engine.c:273
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
#define AST_VECTOR_REPLACE(vec, idx, elem)
Replace an element at a specific position in a vector, growing the vector if needed.
Definition: vector.h:284
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
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:

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

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

Since
1.8

Definition at line 1469 of file rtp_engine.c.

References ast_rtp_codecs_payloads_set_rtpmap_type_rate().

Referenced by jingle_interpret_description().

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

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

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

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

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

Definition at line 1383 of file rtp_engine.c.

References ao2_ref, 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_OPT_G726_NONSTANDARD, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, ast_rtp_payload_type::asterisk_format, ast_rtp_codecs::codecs_lock, ast_rtp_instance::engine, ast_rtp_payload_type::format, ast_rtp_payload_type::payload, ast_rtp_codecs::payload_mapping_tx, ast_rtp_engine::payload_set, ast_rtp_mime_type::payload_type, ast_rtp_payload_type::primary_mapping, ast_rtp_payload_type::rtp_code, ast_rtp_mime_type::sample_rate, ast_rtp_payload_type::sample_rate, ast_rtp_mime_type::subtype, and ast_rtp_mime_type::type.

Referenced by ast_rtp_codecs_payloads_set_rtpmap_type(), and jingle_interpret_description().

1387 {
1388  unsigned int idx;
1389  int found = 0;
1390 
1391  if (pt < 0 || pt >= AST_RTP_MAX_PT) {
1392  return -1; /* bogus payload type */
1393  }
1394 
1395  ast_rwlock_rdlock(&mime_types_lock);
1396  ast_rwlock_wrlock(&codecs->codecs_lock);
1397 
1398  for (idx = 0; idx < mime_types_len; ++idx) {
1399  const struct ast_rtp_mime_type *t = &ast_rtp_mime_types[idx];
1400  struct ast_rtp_payload_type *new_type;
1401 
1402  if (strcasecmp(mimesubtype, t->subtype)) {
1403  continue;
1404  }
1405 
1406  if (strcasecmp(mimetype, t->type)) {
1407  continue;
1408  }
1409 
1410  /* if both sample rates have been supplied, and they don't match,
1411  * then this not a match; if one has not been supplied, then the
1412  * rates are not compared */
1413  if (sample_rate && t->sample_rate &&
1414  (sample_rate != t->sample_rate)) {
1415  continue;
1416  }
1417 
1418  found = 1;
1419 
1420  new_type = ast_rtp_engine_alloc_payload_type();
1421  if (!new_type) {
1422  continue;
1423  }
1424 
1426  new_type->rtp_code = t->payload_type.rtp_code;
1427  new_type->payload = pt;
1428  new_type->primary_mapping = 1;
1429  new_type->sample_rate = sample_rate;
1432  && (options & AST_RTP_OPT_G726_NONSTANDARD)) {
1433  new_type->format = ast_format_g726_aal2;
1434  } else {
1435  new_type->format = t->payload_type.format;
1436  }
1437 
1438  if (new_type->format) {
1439  /* SDP parsing automatically increases the reference count */
1440  new_type->format = ast_format_parse_sdp_fmtp(new_type->format, "");
1441  }
1442 
1443  if (!payload_mapping_tx_is_present(codecs, new_type)) {
1444  if (pt < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1445  ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, pt),
1446  "cleaning up replaced tx payload type");
1447  }
1448 
1449  if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, pt, new_type)) {
1450  ao2_ref(new_type, -1);
1451  } else if (instance && instance->engine && instance->engine->payload_set) {
1452  ao2_lock(instance);
1453  instance->engine->payload_set(instance, pt, new_type->asterisk_format, new_type->format, new_type->rtp_code);
1454  ao2_unlock(instance);
1455  }
1456  } else {
1457  ao2_ref(new_type, -1);
1458  }
1459 
1460  break;
1461  }
1462 
1463  ast_rwlock_unlock(&codecs->codecs_lock);
1464  ast_rwlock_unlock(&mime_types_lock);
1465 
1466  return (found ? 0 : -2);
1467 }
struct ast_format * ast_format_g726
Built-in cached g726 format.
Definition: format_cache.c:111
char type[16]
The media type.
Definition: rtp_engine.c:254
void(* payload_set)(struct ast_rtp_instance *instance, int payload, int asterisk_format, struct ast_format *format, int code)
Definition: rtp_engine.h:694
char subtype[64]
The format type.
Definition: rtp_engine.c:256
struct ast_format * ast_format_g726_aal2
Built-in cached g726 aal2 format.
Definition: format_cache.c:116
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
unsigned int sample_rate
Expected sample rate of the /c subtype.
Definition: rtp_engine.c:258
struct ast_rtp_payload_type payload_type
A mapping object between the Asterisk codec and this RTP payload.
Definition: rtp_engine.c:252
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:83
struct ast_rtp_codecs::@281 payload_mapping_tx
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
struct ast_rtp_payload_type * ast_rtp_engine_alloc_payload_type(void)
Allocation routine for ast_rtp_payload_type.
Definition: rtp_engine.c:325
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
struct ast_format * format
Definition: rtp_engine.h:306
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
#define AST_VECTOR_REPLACE(vec, idx, elem)
Replace an element at a specific position in a vector, growing the vector if needed.
Definition: vector.h:284
unsigned int sample_rate
Definition: rtp_engine.h:318
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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
unsigned int primary_mapping
Definition: rtp_engine.h:314
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
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:

1 ast_rtp_codecs_payloads_unset(&codecs, NULL, 0);

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

Since
1.8

Definition at line 1474 of file rtp_engine.c.

References ao2_ref, ao2_replace, ast_debug, ast_format_cmp(), AST_FORMAT_CMP_EQUAL, AST_RTP_MAX_PT, AST_VECTOR_GET, AST_VECTOR_REPLACE, AST_VECTOR_SIZE, ast_rtp_codecs::codecs_lock, ast_rtp_instance::engine, ast_rtp_payload_type::format, ast_rtp_codecs::payload_mapping_tx, ast_rtp_engine::payload_set, and ast_rtp_codecs::preferred_format.

1475 {
1476  struct ast_rtp_payload_type *type;
1477 
1478  if (payload < 0 || payload >= AST_RTP_MAX_PT) {
1479  return;
1480  }
1481 
1482  ast_debug(2, "Unsetting payload %d on %p\n", payload, codecs);
1483 
1484  ast_rwlock_wrlock(&codecs->codecs_lock);
1485 
1486  if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1487  type = AST_VECTOR_GET(&codecs->payload_mapping_tx, payload);
1488  /*
1489  * Remove the preferred format if we are unsetting its container.
1490  *
1491  * There can be empty slots in payload_mapping_tx corresponding to
1492  * dynamic payload types that haven't been seen before so we need
1493  * to check for NULL before attempting to use 'type' in the call to
1494  * ast_format_cmp.
1495  */
1496  if (type) {
1498  ao2_replace(codecs->preferred_format, NULL);
1499  }
1500  ao2_ref(type, -1);
1502  }
1503  }
1504 
1505  if (instance && instance->engine && instance->engine->payload_set) {
1506  ao2_lock(instance);
1507  instance->engine->payload_set(instance, payload, 0, NULL, 0);
1508  ao2_unlock(instance);
1509  }
1510 
1511  ast_rwlock_unlock(&codecs->codecs_lock);
1512 }
void(* payload_set)(struct ast_rtp_instance *instance, int payload, int asterisk_format, struct ast_format *format, int code)
Definition: rtp_engine.h:694
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:83
struct ast_rtp_codecs::@281 payload_mapping_tx
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
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ast_debug(level,...)
Log a DEBUG message.
struct ast_format * format
Definition: rtp_engine.h:306
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
Definition: astobj2.h:501
#define AST_VECTOR_REPLACE(vec, idx, elem)
Replace an element at a specific position in a vector, growing the vector if needed.
Definition: vector.h:284
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
struct ast_format * preferred_format
Definition: rtp_engine.h:766
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
void ast_rtp_codecs_payloads_xover ( struct ast_rtp_codecs src,
struct ast_rtp_codecs dest,
struct ast_rtp_instance instance 
)

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

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

Definition at line 1296 of file rtp_engine.c.

References ao2_replace, ast_debug, AST_VECTOR_GET, AST_VECTOR_SIZE, ast_rtp_payload_type::asterisk_format, ast_rtp_codecs::codecs_lock, ast_rtp_instance::engine, ast_rtp_payload_type::format, ast_rtp_codecs::framing, ast_rtp_codecs::payload_mapping_tx, ast_rtp_engine::payload_set, ast_rtp_codecs::preferred_format, ast_rtp_payload_type::primary_mapping, and ast_rtp_payload_type::rtp_code.

Referenced by ast_rtp_instance_early_bridge_make_compatible().

1297 {
1298  int idx;
1299  struct ast_rtp_payload_type *type;
1300 
1301  ast_rwlock_wrlock(&dest->codecs_lock);
1302  if (src != dest) {
1303  /* Deadlock avoidance because of held write lock. */
1304  while (ast_rwlock_tryrdlock(&src->codecs_lock)) {
1305  ast_rwlock_unlock(&dest->codecs_lock);
1306  sched_yield();
1307  ast_rwlock_wrlock(&dest->codecs_lock);
1308  }
1309  }
1310 
1311  /* Crossover copy payload type tx mapping to rx mapping. */
1312  for (idx = 0; idx < AST_VECTOR_SIZE(&src->payload_mapping_tx); ++idx) {
1313  type = AST_VECTOR_GET(&src->payload_mapping_tx, idx);
1314  if (!type) {
1315  continue;
1316  }
1317 
1318  /* All tx mapping elements should have the primary flag set. */
1319  ast_assert(type->primary_mapping);
1320 
1321  ast_debug(2, "Crossover copying tx to rx payload mapping %d (%p) from %p to %p\n",
1322  idx, type, src, dest);
1323  rtp_codecs_payload_replace_rx(dest, idx, type);
1324 
1325  if (instance && instance->engine && instance->engine->payload_set) {
1326  ao2_lock(instance);
1327  instance->engine->payload_set(instance, idx, type->asterisk_format, type->format, type->rtp_code);
1328  ao2_unlock(instance);
1329  }
1330  }
1331 
1332  dest->framing = src->framing;
1334 
1335  if (src != dest) {
1336  ast_rwlock_unlock(&src->codecs_lock);
1337  }
1338  ast_rwlock_unlock(&dest->codecs_lock);
1339 }
void(* payload_set)(struct ast_rtp_instance *instance, int payload, int asterisk_format, struct ast_format *format, int code)
Definition: rtp_engine.h:694
unsigned int framing
Definition: rtp_engine.h:764
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
struct ast_rtp_codecs::@281 payload_mapping_tx
#define ast_debug(level,...)
Log a DEBUG message.
struct ast_format * format
Definition: rtp_engine.h:306
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
Definition: astobj2.h:501
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
struct ast_format * preferred_format
Definition: rtp_engine.h:766
unsigned int primary_mapping
Definition: rtp_engine.h:314
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
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 1629 of file rtp_engine.c.

References ast_rtp_codecs::codecs_lock, and ast_rtp_codecs::framing.

Referenced by jingle_enable_video(), and jingle_new().

1630 {
1631  if (!framing) {
1632  return;
1633  }
1634 
1635  ast_rwlock_wrlock(&codecs->codecs_lock);
1636  codecs->framing = framing;
1637  ast_rwlock_unlock(&codecs->codecs_lock);
1638 }
unsigned int framing
Definition: rtp_engine.h:764
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
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:

1 struct ast_format *preferred_format = ast_format_cap_get_format(joint, 0);
2 ast_rtp_codecs_set_preferred_format(&codecs, preferred_format));

This sets the first joint format as the preferred format.

Definition at line 1566 of file rtp_engine.c.

References ao2_replace, ast_rtp_codecs::codecs_lock, and ast_rtp_codecs::preferred_format.

1567 {
1568  ast_rwlock_wrlock(&codecs->codecs_lock);
1569  ao2_replace(codecs->preferred_format, format);
1570  ast_rwlock_unlock(&codecs->codecs_lock);
1571  return 0;
1572 }
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:758
#define ao2_replace(dst, src)
Replace one object reference with another cleaning up the original.
Definition: astobj2.h:501
struct ast_format * preferred_format
Definition: rtp_engine.h:766
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 4137 of file rtp_engine.c.

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_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, ast_rtp_instance_stats::maxrtt, ast_rtp_instance_stats::minrtt, ast_rtp_instance_stats::normdevrtt, ast_rtp_instance_stats::remote_maxjitter, ast_rtp_instance_stats::remote_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().

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

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.

3262 {
3263  ast_rtp_dtls_cfg_free(dst_cfg); /* Prevent a double-call leaking memory via ast_strdup */
3264 
3265  dst_cfg->enabled = src_cfg->enabled;
3266  dst_cfg->verify = src_cfg->verify;
3267  dst_cfg->rekey = src_cfg->rekey;
3268  dst_cfg->suite = src_cfg->suite;
3269  dst_cfg->hash = src_cfg->hash;
3270  dst_cfg->ephemeral_cert = src_cfg->ephemeral_cert;
3271  dst_cfg->certfile = ast_strdup(src_cfg->certfile);
3272  dst_cfg->pvtfile = ast_strdup(src_cfg->pvtfile);
3273  dst_cfg->cipher = ast_strdup(src_cfg->cipher);
3274  dst_cfg->cafile = ast_strdup(src_cfg->cafile);
3275  dst_cfg->capath = ast_strdup(src_cfg->capath);
3276  dst_cfg->default_setup = src_cfg->default_setup;
3277 }
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
void ast_rtp_dtls_cfg_free(struct ast_rtp_dtls_cfg *dtls_cfg)
Free contents of a DTLS configuration structure.
Definition: rtp_engine.c:3279
enum ast_rtp_dtls_hash hash
Definition: rtp_engine.h:610
unsigned int enabled
Definition: rtp_engine.h:606
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 ephemeral_cert
Definition: rtp_engine.h:617
enum ast_srtp_suite suite
Definition: rtp_engine.h:609
unsigned int rekey
Definition: rtp_engine.h:607
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 3279 of file rtp_engine.c.

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

Referenced by ast_rtp_dtls_cfg_copy().

3280 {
3281  ast_free(dtls_cfg->certfile);
3282  dtls_cfg->certfile = NULL;
3283  ast_free(dtls_cfg->pvtfile);
3284  dtls_cfg->pvtfile = NULL;
3285  ast_free(dtls_cfg->cipher);
3286  dtls_cfg->cipher = NULL;
3287  ast_free(dtls_cfg->cafile);
3288  dtls_cfg->cafile = NULL;
3289  ast_free(dtls_cfg->capath);
3290  dtls_cfg->capath = NULL;
3291 }
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 3168 of file rtp_engine.c.

References ast_file_is_readable(), 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_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, ast_rtp_dtls_cfg::pvtfile, ast_rtp_dtls_cfg::rekey, and ast_rtp_dtls_cfg::verify.

3169 {
3170  if (!strcasecmp(name, "dtlsenable")) {
3171  dtls_cfg->enabled = ast_true(value) ? 1 : 0;
3172  } else if (!strcasecmp(name, "dtlsverify")) {
3173  if (!strcasecmp(value, "yes")) {
3175  } else if (!strcasecmp(value, "fingerprint")) {
3177  } else if (!strcasecmp(value, "certificate")) {
3179  } else if (!strcasecmp(value, "no")) {
3180  dtls_cfg->verify = AST_RTP_DTLS_VERIFY_NONE;
3181  } else {
3182  return -1;
3183  }
3184  } else if (!strcasecmp(name, "dtlsrekey")) {
3185  if (sscanf(value, "%30u", &dtls_cfg->rekey) != 1) {
3186  return -1;
3187  }
3188  } else if (!strcasecmp(name, "dtlsautogeneratecert")) {
3189  dtls_cfg->ephemeral_cert = ast_true(value) ? 1 : 0;
3190  } else if (!strcasecmp(name, "dtlscertfile")) {
3191  if (!ast_strlen_zero(value) && !ast_file_is_readable(value)) {
3192  ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3193  return -1;
3194  }
3195  ast_free(dtls_cfg->certfile);
3196  dtls_cfg->certfile = ast_strdup(value);
3197  } else if (!strcasecmp(name, "dtlsprivatekey")) {
3198  if (!ast_strlen_zero(value) && !ast_file_is_readable(value)) {
3199  ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3200  return -1;
3201  }
3202  ast_free(dtls_cfg->pvtfile);
3203  dtls_cfg->pvtfile = ast_strdup(value);
3204  } else if (!strcasecmp(name, "dtlscipher")) {
3205  ast_free(dtls_cfg->cipher);
3206  dtls_cfg->cipher = ast_strdup(value);
3207  } else if (!strcasecmp(name, "dtlscafile")) {
3208  if (!ast_strlen_zero(value) && !ast_file_is_readable(value)) {
3209  ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3210  return -1;
3211  }
3212  ast_free(dtls_cfg->cafile);
3213  dtls_cfg->cafile = ast_strdup(value);
3214  } else if (!strcasecmp(name, "dtlscapath") || !strcasecmp(name, "dtlscadir")) {
3215  if (!ast_strlen_zero(value) && !ast_file_is_readable(value)) {
3216  ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3217  return -1;
3218  }
3219  ast_free(dtls_cfg->capath);
3220  dtls_cfg->capath = ast_strdup(value);
3221  } else if (!strcasecmp(name, "dtlssetup")) {
3222  if (!strcasecmp(value, "active")) {
3224  } else if (!strcasecmp(value, "passive")) {
3226  } else if (!strcasecmp(value, "actpass")) {
3228  }
3229  } else if (!strcasecmp(name, "dtlsfingerprint")) {
3230  if (!strcasecmp(value, "sha-256")) {
3231  dtls_cfg->hash = AST_RTP_DTLS_HASH_SHA256;
3232  } else if (!strcasecmp(value, "sha-1")) {
3233  dtls_cfg->hash = AST_RTP_DTLS_HASH_SHA1;
3234  }
3235  } else {
3236  return -1;
3237  }
3238 
3239  return 0;
3240 }
int ast_file_is_readable(const char *filename)
Test that a file exists and is readable by the effective user.
Definition: utils.c:3107
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
enum ast_rtp_dtls_hash hash
Definition: rtp_engine.h:610
unsigned int enabled
Definition: rtp_engine.h:606
enum ast_rtp_dtls_setup default_setup
Definition: rtp_engine.h:608
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true". This function checks to see whether a string passed to it is an indication of an "true" value. It checks to see if the string is "yes", "true", "y", "t", "on" or "1".
Definition: utils.c:2199
enum ast_rtp_dtls_verify verify
Definition: rtp_engine.h:611
unsigned int ephemeral_cert
Definition: rtp_engine.h:617
unsigned int rekey
Definition: rtp_engine.h:607
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 3242 of file rtp_engine.c.

References ast_rtp_dtls_cfg::cafile, ast_rtp_dtls_cfg::capath, ast_rtp_dtls_cfg::certfile, ast_rtp_dtls_cfg::ephemeral_cert, and ast_rtp_dtls_cfg::pvtfile.

3243 {
3244  if (dtls_cfg->ephemeral_cert) {
3245  if (!ast_strlen_zero(dtls_cfg->certfile)) {
3246  ast_log(LOG_ERROR, "You cannot request automatically generated certificates"
3247  " (dtls_auto_generate_cert) and also specify a certificate file"
3248  " (dtls_cert_file) at the same time\n");
3249  return -1;
3250  } else if (!ast_strlen_zero(dtls_cfg->pvtfile)
3251  || !ast_strlen_zero(dtls_cfg->cafile)
3252  || !ast_strlen_zero(dtls_cfg->capath)) {
3253  ast_log(LOG_NOTICE, "dtls_pvt_file, dtls_cafile, and dtls_ca_path are"
3254  " ignored when dtls_auto_generate_cert is enabled\n");
3255  }
3256  }
3257 
3258  return 0;
3259 }
unsigned int ephemeral_cert
Definition: rtp_engine.h:617
struct ast_rtp_payload_type* ast_rtp_engine_alloc_payload_type ( void  )

Allocation routine for ast_rtp_payload_type.

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

Definition at line 325 of file rtp_engine.c.

Referenced by ast_rtp_codecs_payload_replace_format(), and ast_rtp_codecs_payloads_set_rtpmap_type_rate().

326 {
327  return rtp_payload_type_alloc(NULL, 0, 0, 0, 0);
328 }
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:

1 ast_rtp_engine_register2(&example_rtp_engine, NULL);

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

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

Definition at line 330 of file rtp_engine.c.

References AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_rtp_engine::destroy, ast_rtp_engine::mod, ast_rtp_engine::name, ast_rtp_engine::new, ast_rtp_engine::read, and ast_rtp_engine::write.

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

1 ast_rtp_engine_unregister(&example_rtp_engine);

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

Since
1.8

Definition at line 364 of file rtp_engine.c.

References AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and ast_rtp_engine::name.

Referenced by rtp_reload().

365 {
366  struct ast_rtp_engine *current_engine = NULL;
367 
369 
370  if ((current_engine = AST_RWLIST_REMOVE(&engines, engine, entry))) {
371  ast_verb(5, "Unregistered RTP engine '%s'\n", engine->name);
372  }
373 
375 
376  return current_engine ? 0 : -1;
377 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
const char * name
Definition: rtp_engine.h:667
Definition: search.h:40
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
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 4224 of file rtp_engine.c.

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

Referenced by ast_rtcp_interpret(), ast_rtp_dtmf_end_with_duration(), and rtp_raw_write().

4225 {
4226  /* For those wondering: due to a fluke in RFC publication, G.722 is advertised
4227  * as having a sample rate of 8kHz, while implementations must know that its
4228  * real rate is 16kHz. Seriously.
4229  */
4230  return (ast_format_cmp(format, ast_format_g722) == AST_FORMAT_CMP_EQUAL) ? 8000 : (int)ast_format_get_sample_rate(format);
4231 }
struct ast_format * ast_format_g722
Built-in cached g722 format.
Definition: format_cache.c:106
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
unsigned int ast_format_get_sample_rate(const struct ast_format *format)
Get the sample rate of a media format.
Definition: format.c:379
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:

1 ast_rtp_glue_register2(&example_rtp_glue, NULL);

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

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

Definition at line 379 of file rtp_engine.c.

References AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, ast_rtp_glue::mod, and ast_rtp_glue::type.

380 {
381  struct ast_rtp_glue *current_glue = NULL;
382 
383  if (ast_strlen_zero(glue->type)) {
384  return -1;
385  }
386 
387  glue->mod = module;
388 
390 
391  AST_RWLIST_TRAVERSE(&glues, current_glue, entry) {
392  if (!strcasecmp(current_glue->type, glue->type)) {
393  ast_log(LOG_WARNING, "RTP glue with the name '%s' has already been registered.\n", glue->type);
395  return -1;
396  }
397  }
398 
399  AST_RWLIST_INSERT_TAIL(&glues, glue, entry);
400 
402 
403  ast_verb(5, "Registered RTP glue '%s'\n", glue->type);
404 
405  return 0;
406 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
const char * type
Definition: rtp_engine.h:775
struct ast_module * mod
Definition: rtp_engine.h:777
Definition: search.h:40
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
int ast_rtp_glue_unregister ( struct ast_rtp_glue glue)

Unregister RTP glue.

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

Example usage:

1 ast_rtp_glue_unregister(&example_rtp_glue);

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

Since
1.8

Definition at line 408 of file rtp_engine.c.

References AST_RWLIST_UNLOCK, AST_RWLIST_WRLOCK, and ast_rtp_glue::type.

Referenced by load_module(), and unload_module().

409 {
410  struct ast_rtp_glue *current_glue = NULL;
411 
413 
414  if ((current_glue = AST_RWLIST_REMOVE(&glues, glue, entry))) {
415  ast_verb(5, "Unregistered RTP glue '%s'\n", glue->type);
416  }
417 
419 
420  return current_glue ? 0 : -1;
421 }
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
const char * type
Definition: rtp_engine.h:775
Definition: search.h:40
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
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:

1 ast_rtp_instance_activate(instance);

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

Since
1.8

Definition at line 2795 of file rtp_engine.c.

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

Referenced by rtp_call().

2796 {
2797  int res;
2798 
2799  if (instance->engine->activate) {
2800  ao2_lock(instance);
2801  res = instance->engine->activate(instance);
2802  ao2_unlock(instance);
2803  } else {
2804  res = 0;
2805  }
2806  return res;
2807 }
int(* activate)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:724
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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 2884 of file rtp_engine.c.

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

2885 {
2886  int res = 0;
2887  struct ast_srtp **srtp;
2888 
2889  if (!res_srtp) {
2890  return -1;
2891  }
2892 
2893  ao2_lock(instance);
2894 
2895  srtp = rtcp ? &instance->rtcp_srtp : &instance->srtp;
2896 
2897  if (!*srtp) {
2898  res = res_srtp->create(srtp, instance, remote_policy);
2899  } else if (remote_policy) {
2900  res = res_srtp->replace(srtp, instance, remote_policy);
2901  }
2902  if (!res) {
2903  res = res_srtp->add_stream(*srtp, local_policy);
2904  }
2905 
2906  ao2_unlock(instance);
2907 
2908  return res;
2909 }
struct ast_srtp * srtp
Definition: rtp_engine.c:214
struct ast_srtp * rtcp_srtp
Definition: rtp_engine.c:216
int(* create)(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy)
Definition: res_srtp.h:36
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:

1 ast_rtp_instance_available_formats(instance, to_capabilities, from_capabilities, result_capabilities);

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

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

2782 {
2783  if (instance->engine->available_formats) {
2784  ao2_lock(instance);
2785  instance->engine->available_formats(instance, to_endpoint, to_asterisk, result);
2786  ao2_unlock(instance);
2787  if (ast_format_cap_count(result)) {
2788  return;
2789  }
2790  }
2791 
2792  ast_translate_available_formats(to_endpoint, to_asterisk, result);
2793 }
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 ast_translate_available_formats(struct ast_format_cap *dest, struct ast_format_cap *src, struct ast_format_cap *result)
Find available formats.
Definition: translate.c:1616
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
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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 3985 of file rtp_engine.c.

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

Referenced by negotiate_incoming_sdp_stream().

3986 {
3987  int res = -1;
3988 
3989  if (parent && (child->engine != parent->engine)) {
3990  return -1;
3991  }
3992 
3993  ao2_lock(child);
3994  if (child->engine->bundle) {
3995  res = child->engine->bundle(child, parent);
3996  }
3997  ao2_unlock(child);
3998 
3999  return res;
4000 }
int(* bundle)(struct ast_rtp_instance *child, struct ast_rtp_instance *parent)
Definition: rtp_engine.h:736
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

1 ast_rtp_instance_change_source(instance);

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

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

Referenced by create_outgoing_sdp_stream(), and jingle_indicate().

2285 {
2286  if (instance->engine->change_source) {
2287  ao2_lock(instance);
2288  instance->engine->change_source(instance);
2289  ao2_unlock(instance);
2290  }
2291 }
void(* change_source)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:686
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

1 ast_rtp_instance_destroy(instance);

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

Since
1.8

Definition at line 458 of file rtp_engine.c.

References ast_debug_rtp, 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 jingle_session_destructor(), multicast_rtp_request(), rtp_hangup(), stream_destroy(), and unicast_rtp_request().

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

1 ast_rtp_instance_dtmf_begin(instance, '1');

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

Since
1.8

Definition at line 2205 of file rtp_engine.c.

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

Referenced by chan_pjsip_digit_begin(), and jingle_digit_begin().

2206 {
2207  int res;
2208 
2209  if (instance->engine->dtmf_begin) {
2210  ao2_lock(instance);
2211  res = instance->engine->dtmf_begin(instance, digit);
2212  ao2_unlock(instance);
2213  } else {
2214  res = -1;
2215  }
2216  return res;
2217 }
int(* dtmf_begin)(struct ast_rtp_instance *instance, char digit)
Definition: rtp_engine.h:679
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

1 ast_rtp_instance_dtmf_end(instance, '1');

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

Since
1.8

Definition at line 2219 of file rtp_engine.c.

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

2220 {
2221  int res;
2222 
2223  if (instance->engine->dtmf_end) {
2224  ao2_lock(instance);
2225  res = instance->engine->dtmf_end(instance, digit);
2226  ao2_unlock(instance);
2227  } else {
2228  res = -1;
2229  }
2230  return res;
2231 }
int(* dtmf_end)(struct ast_rtp_instance *instance, char digit)
Definition: rtp_engine.h:681
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

1 enum ast_rtp_dtmf_mode dtmf_mode = ast_rtp_instance_dtmf_mode_get(instance);

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

Since
1.8

Definition at line 2261 of file rtp_engine.c.

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

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

2262 {
2263  int res;
2264 
2265  if (instance->engine->dtmf_mode_get) {
2266  ao2_lock(instance);
2267  res = instance->engine->dtmf_mode_get(instance);
2268  ao2_unlock(instance);
2269  } else {
2270  res = 0;
2271  }
2272  return res;
2273 }
enum ast_rtp_dtmf_mode(* dtmf_mode_get)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:700
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

1 ast_rtp_instance_dtmf_mode_set(instance, AST_RTP_DTMF_MODE_RFC2833);

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

Since
1.8

Definition at line 2247 of file rtp_engine.c.

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

Referenced by create_rtp(), and pjsip_acf_dtmf_mode_write().

2248 {
2249  int res;
2250 
2251  if (instance->engine->dtmf_mode_set) {
2252  ao2_lock(instance);
2253  res = instance->engine->dtmf_mode_set(instance, dtmf_mode);
2254  ao2_unlock(instance);
2255  } else {
2256  res = -1;
2257  }
2258  return res;
2259 }
int(* dtmf_mode_set)(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode)
Definition: rtp_engine.h:698
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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 2461 of file rtp_engine.c.

References ast_channel_lock_both, ast_debug, ast_format_cap_alloc, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_iscompatible(), AST_RTP_GLUE_RESULT_FORBID, AST_RTP_GLUE_RESULT_REMOTE, ast_rtp_instance_get_glue(), ast_rtp_glue::get_codec, ast_rtp_glue::get_rtp_info, ast_rtp_glue::get_vrtp_info, unref_instance_cond(), and ast_rtp_glue::update_peer.

2462 {
2463  struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
2464  *vinstance0 = NULL, *vinstance1 = NULL,
2465  *tinstance0 = NULL, *tinstance1 = NULL;
2466  struct ast_rtp_glue *glue0, *glue1;
2467  enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
2468  enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
2471 
2472  /* If there is no second channel just immediately bail out, we are of no use in that scenario */
2473  if (!c1 || !cap1 || !cap0) {
2474  ao2_cleanup(cap0);
2475  ao2_cleanup(cap1);
2476  return -1;
2477  }
2478 
2479  /* Lock both channels so we can look for the glue that binds them together */
2480  ast_channel_lock_both(c0, c1);
2481 
2482  /* Grab glue that binds each channel to something using the RTP engine */
2483  if (!(glue0 = ast_rtp_instance_get_glue(ast_channel_tech(c0)->type)) || !(glue1 = ast_rtp_instance_get_glue(ast_channel_tech(c1)->type))) {
2484  ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", glue0 ? ast_channel_name(c1) : ast_channel_name(c0));
2485  goto done;
2486  }
2487 
2488  audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
2489  video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;
2490 
2491  audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
2492  video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;
2493 
2494  /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
2495  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)) {
2496  audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
2497  }
2498  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)) {
2499  audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
2500  }
2501  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) {
2502  glue0->get_codec(c0, cap0);
2503  }
2504  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) {
2505  glue1->get_codec(c1, cap1);
2506  }
2507 
2508  /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
2509  if (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE) {
2510  goto done;
2511  }
2512 
2513  /* Make sure we have matching codecs */
2514  if (!ast_format_cap_iscompatible(cap0, cap1)) {
2515  goto done;
2516  }
2517 
2518  /* Bridge media early */
2519  if (glue0->update_peer(c0, instance1, vinstance1, tinstance1, cap1, 0)) {
2520  ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", ast_channel_name(c0), c1 ? ast_channel_name(c1) : "<unspecified>");
2521  }
2522 
2523 done:
2524  ast_channel_unlock(c0);
2525  ast_channel_unlock(c1);
2526 
2527  ao2_cleanup(cap0);
2528  ao2_cleanup(cap1);
2529 
2530  unref_instance_cond(&instance0);
2531  unref_instance_cond(&instance1);
2532  unref_instance_cond(&vinstance0);
2533  unref_instance_cond(&vinstance1);
2534  unref_instance_cond(&tinstance0);
2535  unref_instance_cond(&tinstance1);
2536 
2537  ast_debug(1, "Setting early bridge SDP of '%s' with that of '%s'\n", ast_channel_name(c0), c1 ? ast_channel_name(c1) : "<unspecified>");
2538 
2539  return 0;
2540 }
static void unref_instance_cond(struct ast_rtp_instance **instance)
Conditionally unref an rtp instance.
Definition: rtp_engine.c:2350
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:809
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:782
struct ast_rtp_glue * ast_rtp_instance_get_glue(const char *type)
Get the RTP glue that binds a channel to the RTP engine.
Definition: rtp_engine.c:2330
#define ast_debug(level,...)
Log a DEBUG message.
ast_rtp_glue_result
Definition: rtp_engine.h:161
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:814
#define ast_format_cap_alloc(flags)
Allocate a new ast_format_cap structure.
Definition: format_cap.h:49
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:628
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition: channel.h:2929
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:794
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
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 2375 of file rtp_engine.c.

References ast_channel_lock_both, ast_debug, ast_format_cap_alloc, AST_FORMAT_CAP_FLAG_DEFAULT, ast_format_cap_iscompatible(), ast_rtp_codecs_payloads_xover(), AST_RTP_GLUE_RESULT_FORBID, AST_RTP_GLUE_RESULT_REMOTE, ast_rtp_instance_get_glue(), ast_rtp_instance::codecs, ast_rtp_glue::get_codec, ast_rtp_glue::get_rtp_info, ast_rtp_glue::get_vrtp_info, unref_instance_cond(), and ast_rtp_glue::update_peer.

Referenced by dial_exec_full(), and do_forward().

2376 {
2377  struct ast_rtp_instance *instance_dst = NULL, *instance_src = NULL,
2378  *vinstance_dst = NULL, *vinstance_src = NULL,
2379  *tinstance_dst = NULL, *tinstance_src = NULL;
2380  struct ast_rtp_glue *glue_dst, *glue_src;
2381  enum ast_rtp_glue_result audio_glue_dst_res = AST_RTP_GLUE_RESULT_FORBID, video_glue_dst_res = AST_RTP_GLUE_RESULT_FORBID;
2382  enum ast_rtp_glue_result audio_glue_src_res = AST_RTP_GLUE_RESULT_FORBID, video_glue_src_res = AST_RTP_GLUE_RESULT_FORBID;
2385 
2386  /* Lock both channels so we can look for the glue that binds them together */
2387  ast_channel_lock_both(c_dst, c_src);
2388 
2389  if (!cap_src || !cap_dst) {
2390  goto done;
2391  }
2392 
2393  /* Grab glue that binds each channel to something using the RTP engine */
2394  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))) {
2395  ast_debug(1, "Can't find native functions for channel '%s'\n", glue_dst ? ast_channel_name(c_src) : ast_channel_name(c_dst));
2396  goto done;
2397  }
2398 
2399  audio_glue_dst_res = glue_dst->get_rtp_info(c_dst, &instance_dst);
2400  video_glue_dst_res = glue_dst->get_vrtp_info ? glue_dst->get_vrtp_info(c_dst, &vinstance_dst) : AST_RTP_GLUE_RESULT_FORBID;
2401 
2402  audio_glue_src_res = glue_src->get_rtp_info(c_src, &instance_src);
2403  video_glue_src_res = glue_src->get_vrtp_info ? glue_src->get_vrtp_info(c_src, &vinstance_src) : AST_RTP_GLUE_RESULT_FORBID;
2404 
2405  /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
2406  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)) {
2407  audio_glue_dst_res = AST_RTP_GLUE_RESULT_FORBID;
2408  }
2409  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)) {
2410  audio_glue_src_res = AST_RTP_GLUE_RESULT_FORBID;
2411  }
2412  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) {
2413  glue_dst->get_codec(c_dst, cap_dst);
2414  }
2415  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) {
2416  glue_src->get_codec(c_src, cap_src);
2417  }
2418 
2419  /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
2420  if (audio_glue_dst_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue_src_res != AST_RTP_GLUE_RESULT_REMOTE) {
2421  goto done;
2422  }
2423 
2424  /* Make sure we have matching codecs */
2425  if (!ast_format_cap_iscompatible(cap_dst, cap_src)) {
2426  goto done;
2427  }
2428 
2429  ast_rtp_codecs_payloads_xover(&instance_src->codecs, &instance_dst->codecs, instance_dst);
2430 
2431  if (vinstance_dst && vinstance_src) {
2432  ast_rtp_codecs_payloads_xover(&vinstance_src->codecs, &vinstance_dst->codecs, vinstance_dst);
2433  }
2434  if (tinstance_dst && tinstance_src) {
2435  ast_rtp_codecs_payloads_xover(&tinstance_src->codecs, &tinstance_dst->codecs, tinstance_dst);
2436  }
2437 
2438  if (glue_dst->update_peer(c_dst, instance_src, vinstance_src, tinstance_src, cap_src, 0)) {
2439  ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n",
2440  ast_channel_name(c_dst), ast_channel_name(c_src));
2441  } else {
2442  ast_debug(1, "Seeded SDP of '%s' with that of '%s'\n",
2443  ast_channel_name(c_dst), ast_channel_name(c_src));
2444  }
2445 
2446 done:
2447  ast_channel_unlock(c_dst);
2448  ast_channel_unlock(c_src);
2449 
2450  ao2_cleanup(cap_dst);
2451  ao2_cleanup(cap_src);
2452 
2453  unref_instance_cond(&instance_dst);
2454  unref_instance_cond(&instance_src);
2455  unref_instance_cond(&vinstance_dst);
2456  unref_instance_cond(&vinstance_src);
2457  unref_instance_cond(&tinstance_dst);
2458  unref_instance_cond(&tinstance_src);
2459 }
static void unref_instance_cond(struct ast_rtp_instance **instance)
Conditionally unref an rtp instance.
Definition: rtp_engine.c:2350
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:809
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:782
struct ast_rtp_glue * ast_rtp_instance_get_glue(const char *type)
Get the RTP glue that binds a channel to the RTP engine.
Definition: rtp_engine.c:2330
#define ast_debug(level,...)
Log a DEBUG message.
ast_rtp_glue_result
Definition: rtp_engine.h:161
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:814
#define ast_format_cap_alloc(flags)
Allocate a new ast_format_cap structure.
Definition: format_cap.h:49
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:628
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition: channel.h:2929
void ast_rtp_codecs_payloads_xover(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
Crossover copy the tx payload mapping of src to the rx payload mapping of dest.
Definition: rtp_engine.c:1296
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:794
struct ast_rtp_codecs codecs
Definition: rtp_engine.c:204
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
void ast_rtp_instance_extmap_clear ( struct ast_rtp_instance instance)

Clear negotiated RTP extension information.

Parameters
instanceThe RTP instance to clear negotiated extension information on

Definition at line 884 of file rtp_engine.c.

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

885 {
886  static const struct rtp_extmap extmap_none = {
889  };
890  int idx;
891 
892  ao2_lock(instance);
893 
894  /* Clear both the known unique ids and the negotiated extensions as we are about to have
895  * new results set on us.
896  */
897  for (idx = 0; idx < AST_VECTOR_SIZE(&instance->extmap_unique_ids); ++idx) {
898  AST_VECTOR_REPLACE(&instance->extmap_unique_ids, idx, extmap_none);
899  }
900 
901  for (idx = 0; idx < AST_VECTOR_SIZE(&instance->extmap_negotiated); ++idx) {
902  AST_VECTOR_REPLACE(&instance->extmap_negotiated, idx, -1);
903  }
904 
905  ao2_unlock(instance);
906 }
struct ast_rtp_instance::@390 extmap_unique_ids
enum ast_rtp_extension extension
Definition: rtp_engine.c:182
struct ast_rtp_instance::@389 extmap_negotiated
#define AST_VECTOR_REPLACE(vec, idx, elem)
Replace an element at a specific position in a vector, growing the vector if needed.
Definition: vector.h:284
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
size_t ast_rtp_instance_extmap_count ( struct ast_rtp_instance instance)

Get the number of known unique identifiers.

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

Definition at line 921 of file rtp_engine.c.

References AST_VECTOR_SIZE, and ast_rtp_instance::extmap_unique_ids.

Referenced by enable_rtp_extension().

922 {
923  size_t count;
924 
925  ao2_lock(instance);
926  count = AST_VECTOR_SIZE(&instance->extmap_unique_ids);
927  ao2_unlock(instance);
928 
929  return count;
930 }
struct ast_rtp_instance::@390 extmap_unique_ids
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
int ast_rtp_instance_extmap_enable ( struct ast_rtp_instance instance,
int  id,
enum ast_rtp_extension  extension,
enum ast_rtp_extension_direction  direction 
)

Enable support for an RTP extension on an instance.

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

Definition at line 754 of file rtp_engine.c.

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

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

Retrieve the negotiated direction for an RTP extension id.

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

Definition at line 952 of file rtp_engine.c.

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

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

Retrieve the extension for an RTP extension id.

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

Definition at line 932 of file rtp_engine.c.

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

Referenced by ast_rtp_instance_extmap_get_uri().

933 {
935 
936  ao2_lock(instance);
937 
938  /* The local unique identifier starts at '1' so the highest unique identifier
939  * can be the actual size of the vector. We compensate (as it is 0 index based)
940  * by dropping it down to 1 to get the correct information.
941  */
942  if (0 < id && id <= AST_VECTOR_SIZE(&instance->extmap_unique_ids)) {
943  struct rtp_extmap *extmap = AST_VECTOR_GET_ADDR(&instance->extmap_unique_ids, id - 1);
944 
945  extension = extmap->extension;
946  }
947  ao2_unlock(instance);
948 
949  return extension;
950 }
ast_rtp_extension
Known RTP extensions.
Definition: rtp_engine.h:593
struct ast_rtp_instance::@390 extmap_unique_ids
#define AST_VECTOR_GET_ADDR(vec, idx)
Get an address of element in a vector.
Definition: vector.h:668
structure to hold extensions
enum ast_rtp_extension extension
Definition: rtp_engine.c:182
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
int ast_rtp_instance_extmap_get_id ( struct ast_rtp_instance instance,
enum ast_rtp_extension  extension 
)

Retrieve the id for an RTP extension.

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

Definition at line 908 of file rtp_engine.c.

References AST_VECTOR_GET, AST_VECTOR_SIZE, and ast_rtp_instance::extmap_negotiated.

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

909 {
910  int id = -1;
911 
912  ao2_lock(instance);
913  if (extension < AST_VECTOR_SIZE(&instance->extmap_negotiated)) {
914  id = AST_VECTOR_GET(&instance->extmap_negotiated, extension);
915  }
916  ao2_unlock(instance);
917 
918  return id;
919 }
structure to hold extensions
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
struct ast_rtp_instance::@389 extmap_negotiated
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
const char* ast_rtp_instance_extmap_get_uri ( struct ast_rtp_instance instance,
int  id 
)

Retrieve the URI for an RTP extension id.

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

Definition at line 968 of file rtp_engine.c.

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

969 {
971 
972  if (extension == AST_RTP_EXTENSION_UNSUPPORTED ||
973  (unsigned int)extension >= ARRAY_LEN(rtp_extension_uris)) {
974  return NULL;
975  }
976 
978 }
enum ast_rtp_extension ast_rtp_instance_extmap_get_extension(struct ast_rtp_instance *instance, int id)
Retrieve the extension for an RTP extension id.
Definition: rtp_engine.c:932
ast_rtp_extension
Known RTP extensions.
Definition: rtp_engine.h:593
structure to hold extensions
enum ast_rtp_extension extension
Definition: rtp_engine.c:182
static const char *const rtp_extension_uris[AST_RTP_EXTENSION_MAX]
URIs for known RTP extensions.
Definition: rtp_engine.c:234
int ast_rtp_instance_extmap_negotiate ( struct ast_rtp_instance instance,
int  id,
enum ast_rtp_extension_direction  direction,
const char *  uri,
const char *  attributes 
)

Negotiate received RTP extension information.

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

Definition at line 840 of file rtp_engine.c.

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

842 {
843  /* 'attributes' is currently unused but exists in the API to ensure it does not need to be altered
844  * in the future in case we need to use it.
845  */
846  int idx;
848 
849  /* Per the RFC the identifier has to be 1 or above */
850  if (id < 1) {
851  return -1;
852  }
853 
854  /* Convert the provided URI to the internal representation */
855  for (idx = 0; idx < ARRAY_LEN(rtp_extension_uris); ++idx) {
856  if (!strcasecmp(rtp_extension_uris[idx], uri)) {
857  extension = idx;
858  break;
859  }
860  }
861 
862  ao2_lock(instance);
863  /* We only accept the extension if it is enabled */
864  if (extension < AST_VECTOR_SIZE(&instance->extmap_enabled) &&
866  struct rtp_extmap extmap = {
867  .extension = extension,
868  .direction = rtp_extmap_negotiate_direction(AST_VECTOR_GET(&instance->extmap_enabled, extension), direction),
869  };
870 
871  /* If the direction negotiation failed then don't accept or use this extension */
873  if (extension != AST_RTP_EXTENSION_UNSUPPORTED) {
874  AST_VECTOR_REPLACE(&instance->extmap_negotiated, extension, id);
875  }
876  AST_VECTOR_REPLACE(&instance->extmap_unique_ids, id - 1, extmap);
877  }
878  }
879  ao2_unlock(instance);
880 
881  return 0;
882 }
struct ast_rtp_instance::@388 extmap_enabled
static enum ast_rtp_extension_direction rtp_extmap_negotiate_direction(enum ast_rtp_extension_direction ours, enum ast_rtp_extension_direction theirs)
Helper function which negotiates two RTP extension directions to get our current direction.
Definition: rtp_engine.c:812
ast_rtp_extension
Known RTP extensions.
Definition: rtp_engine.h:593
struct ast_rtp_instance::@390 extmap_unique_ids
structure to hold extensions
enum ast_rtp_extension_direction direction
Definition: rtp_engine.c:184
enum ast_rtp_extension extension
Definition: rtp_engine.c:182
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
struct ast_rtp_instance::@389 extmap_negotiated
#define AST_VECTOR_REPLACE(vec, idx, elem)
Replace an element at a specific position in a vector, growing the vector if needed.
Definition: vector.h:284
static const char *const rtp_extension_uris[AST_RTP_EXTENSION_MAX]
URIs for known RTP extensions.
Definition: rtp_engine.c:234
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
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:

1 int rtp_fd = ast_rtp_instance_fd(instance, 0);

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

Since
1.8

Definition at line 2316 of file rtp_engine.c.

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

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

2317 {
2318  int res;
2319 
2320  if (instance->engine->fd) {
2321  ao2_lock(instance);
2322  res = instance->engine->fd(instance, rtcp);
2323  ao2_unlock(instance);
2324  } else {
2325  res = -1;
2326  }
2327  return res;
2328 }
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
int(* fd)(struct ast_rtp_instance *instance, int rtcp)
Definition: rtp_engine.h:706
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:

1 struct ast_rtp_glue *glue = ast_rtp_instance_get_active_glue(instance);

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

Since
1.8

Definition at line 2853 of file rtp_engine.c.

References ast_rtp_instance::glue.

2854 {
2855  return instance->glue;
2856 }
struct ast_rtp_glue * glue
Definition: rtp_engine.c:212
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:
1 struct ast_sockaddr address;
2 int ret;
3 ret = ast_rtp_instance_get_and_cmp_local_address(instance, &address);

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

Since
1.8

Definition at line 651 of file rtp_engine.c.

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

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

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

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

Definition at line 673 of file rtp_engine.c.

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

675 {
676  ao2_lock(instance);
677  if (ast_sockaddr_cmp(address, &instance->requested_target_address) != 0) {
678  ast_sockaddr_copy(address, &instance->requested_target_address);
679  ao2_unlock(instance);
680  return 1;
681  }
682  ao2_unlock(instance);
683 
684  return 0;
685 }
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 requested_target_address
Definition: rtp_engine.c:198
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:

1 struct ast_rtp_instance *bridged = ast_rtp_instance_get_bridged(instance0);

This gets the RTP instance that instance0 is bridged to.

Since
1.8

Definition at line 2358 of file rtp_engine.c.

References ast_rtp_instance::bridged.

2359 {
2360  struct ast_rtp_instance *bridged;
2361 
2362  ao2_lock(instance);
2363  bridged = instance->bridged;
2364  ao2_unlock(instance);
2365  return bridged;
2366 }
struct ast_rtp_instance * bridged
Definition: rtp_engine.c:202
const char* ast_rtp_instance_get_channel_id ( struct ast_rtp_instance instance)

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

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

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

Definition at line 570 of file rtp_engine.c.

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(), rtp_check_timeout(), and rtp_raw_write().

571 {
572  return instance->channel_uniqueid;
573 }
char channel_uniqueid[AST_MAX_UNIQUEID]
Definition: rtp_engine.c:218
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 3972 of file rtp_engine.c.

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

Referenced by add_ssrc_to_stream().

3973 {
3974  const char *cname = "";
3975 
3976  ao2_lock(rtp);
3977  if (rtp->engine->cname_get) {
3978  cname = rtp->engine->cname_get(rtp);
3979  }
3980  ao2_unlock(rtp);
3981 
3982  return cname;
3983 }
const char *(* cname_get)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:734
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

1 struct ast_rtp_codecs *codecs = ast_rtp_instance_get_codecs(instance);

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

Since
1.8

Definition at line 749 of file rtp_engine.c.

References ast_rtp_instance::codecs.

Referenced by ast_rtp_dtmf_begin(), ast_rtp_read(), ast_rtp_sendcng(), ast_rtp_write(), bridge_p2p_rtp_write(), create_outgoing_sdp_stream(), jingle_add_payloads_to_description(), jingle_enable_video(), jingle_interpret_description(), jingle_new(), and multicast_rtp_write().

750 {
751  return &instance->codecs;
752 }
struct ast_rtp_codecs codecs
Definition: rtp_engine.c:204
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:

1  struct *blob = ast_rtp_instance_get_data(instance);
2 (

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

Since
1.8

Definition at line 585 of file rtp_engine.c.

References ast_rtp_instance::data.

Referenced by __rtp_recvfrom(), __rtp_sendto(), 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_ice_add_remote_candidate(), ast_rtp_ice_change_components(), ast_rtp_ice_get_local_candidates(), ast_rtp_ice_get_password(), ast_rtp_ice_get_ufrag(), ast_rtp_ice_lite(), ast_rtp_ice_set_authentication(), ast_rtp_ice_set_role(), ast_rtp_ice_start(), ast_rtp_ice_stop(), ast_rtp_ice_turn_request(), 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_stop(), ast_rtp_stun_request(), ast_rtp_update_source(), ast_rtp_write(), bridge_p2p_rtp_write(), ice_reset_session(), multicast_rtp_activate(), multicast_rtp_destroy(), multicast_rtp_write(), red_write(), rtp_raw_write(), rtp_red_buffer(), rtp_red_init(), and rtp_sendto().

586 {
587  return instance->data;
588 }
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 3159 of file rtp_engine.c.

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

Referenced by ast_sdp_get_rtp_profile().

3160 {
3161  if (instance->engine->dtls) {
3162  return &rtp_dtls_wrappers;
3163  }
3164  /* DTLS not available */
3165  return NULL;
3166 }
struct ast_rtp_engine_dtls * dtls
Definition: rtp_engine.h:744
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

1 struct ast_rtp_engine *engine = ast_rtp_instance_get_engine(instance);

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

Since
1.8

Definition at line 2848 of file rtp_engine.c.

References ast_rtp_instance::engine.

2849 {
2850  return instance->engine;
2851 }
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
void* ast_rtp_instance_get_extended_prop ( struct ast_rtp_instance instance,
int  property 
)

Get the value of an RTP instance extended property.

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

Definition at line 712 of file rtp_engine.c.

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

713 {
714  void *prop;
715 
716  if (instance->engine->extended_prop_get) {
717  ao2_lock(instance);
718  prop = instance->engine->extended_prop_get(instance, property);
719  ao2_unlock(instance);
720  } else {
721  prop = NULL;
722  }
723 
724  return prop;
725 }
void *(* extended_prop_get)(struct ast_rtp_instance *instance, int property)
Definition: rtp_engine.h:690
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

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

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

Since
1.8

Definition at line 2330 of file rtp_engine.c.

References AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_rtp_instance::glue, and ast_rtp_glue::type.

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

2331 {
2332  struct ast_rtp_glue *glue = NULL;
2333 
2335 
2336  AST_RWLIST_TRAVERSE(&glues, glue, entry) {
2337  if (!strcasecmp(glue->type, type)) {
2338  break;
2339  }
2340  }
2341 
2343 
2344  return glue;
2345 }
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
const char * type
Definition: rtp_engine.h:775
Definition: search.h:40
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
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:

1 int timeout = ast_rtp_instance_get_hold_timeout(instance);

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

Since
1.8

Definition at line 2838 of file rtp_engine.c.

References ast_rtp_instance::holdtimeout.

2839 {
2840  return instance->holdtimeout;
2841 }
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 3039 of file rtp_engine.c.

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

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

3040 {
3041  if (instance->engine->ice) {
3042  return &rtp_ice_wrappers;
3043  }
3044  /* ICE not available */
3045  return NULL;
3046 }
struct ast_rtp_engine_ice * ice
Definition: rtp_engine.h:742
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
void ast_rtp_instance_get_incoming_source_address ( struct ast_rtp_instance instance,
struct ast_sockaddr address 
)

Get the incoming source address of the remote endpoint.

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

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

Definition at line 687 of file rtp_engine.c.

References ast_sockaddr_copy(), and ast_rtp_instance::incoming_source_address.

689 {
690  ao2_lock(instance);
691  ast_sockaddr_copy(address, &instance->incoming_source_address);
692  ao2_unlock(instance);
693 }
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
struct ast_sockaddr incoming_source_address
Definition: rtp_engine.c:200
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:

1 int interval = ast_rtp_instance_get_keepalive(instance);

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

Since
1.8

Definition at line 2843 of file rtp_engine.c.

References ast_rtp_instance::keepalive.

2844 {
2845  return instance->keepalive;
2846 }
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 3949 of file rtp_engine.c.

References ast_rtp_instance::last_rx.

Referenced by rtp_check_timeout().

3950 {
3951  return rtp->last_rx;
3952 }
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 3939 of file rtp_engine.c.

References ast_rtp_instance::last_tx.

3940 {
3941  return rtp->last_tx;
3942 }
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:

1 struct ast_sockaddr address;
2 ast_rtp_instance_get_local_address(instance, &address);

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

Since
1.8

Definition at line 665 of file rtp_engine.c.

References ast_sockaddr_copy(), and ast_rtp_instance::local_address.

Referenced by ast_rtp_ice_turn_request(), ast_rtp_prop_set(), ast_rtp_remote_address_set(), create_outgoing_sdp_stream(), multicast_send_control_packet(), and unicast_rtp_request().

667 {
668  ao2_lock(instance);
669  ast_sockaddr_copy(address, &instance->local_address);
670  ao2_unlock(instance);
671 }
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
struct ast_sockaddr local_address
Definition: rtp_engine.c:196
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:

1 ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT);

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

Since
1.8

Definition at line 738 of file rtp_engine.c.

References ast_rtp_instance::properties.

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

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

1 char quality[AST_MAX_USER_FIELD];
2 ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, &buf, sizeof(buf));

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

Since
1.8

Definition at line 2588 of file rtp_engine.c.

References ast_rtp_instance_get_stats(), AST_RTP_INSTANCE_STAT_ALL, AST_RTP_INSTANCE_STAT_COMBINED_JITTER, AST_RTP_INSTANCE_STAT_COMBINED_LOSS, AST_RTP_INSTANCE_STAT_COMBINED_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, 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, 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 ast_rtp_instance_set_stats_vars().

2589 {
2590  struct ast_rtp_instance_stats stats = { 0, };
2591  enum ast_rtp_instance_stat stat;
2592 
2593  /* Determine what statistics we will need to retrieve based on field passed in */
2594  if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY) {
2596  } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
2598  } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
2600  } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
2602  } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES) {
2604  } else {
2605  return NULL;
2606  }
2607 
2608  /* Attempt to actually retrieve the statistics we need to generate the quality string */
2609  if (ast_rtp_instance_get_stats(instance, &stats, stat)) {
2610  return NULL;
2611  }
2612 
2613  /* Now actually fill the buffer with the good information */
2614  if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY) {
2615  snprintf(buf, size, "ssrc=%u;themssrc=%u;lp=%u;rxjitter=%f;rxcount=%u;"
2616  "txjitter=%f;txcount=%u;rlp=%u;rtt=%f;rxmes=%f;txmes=%f",
2617  stats.local_ssrc, stats.remote_ssrc, stats.rxploss, stats.rxjitter,
2618  stats.rxcount, stats.txjitter, stats.txcount, stats.txploss, stats.rtt,
2619  stats.rxmes, stats.txmes);
2620  } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
2621  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;",
2623  } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
2624  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;",
2626  } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
2627  snprintf(buf, size, " minrtt=%010.6f; maxrtt=%010.6f; avgrtt=%010.6f; stdevrtt=%010.6f;", stats.minrtt, stats.maxrtt, stats.normdevrtt, stats.stdevrtt);
2628  } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES) {
2629  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;",
2630  stats.local_minmes, stats.local_maxmes,
2631  stats.local_normdevmes, stats.local_stdevmes,
2632  stats.remote_minmes, stats.remote_maxmes,
2633  stats.remote_normdevmes, stats.remote_stdevmes);
2634  }
2635 
2636  return buf;
2637 }
unsigned int txcount
Definition: rtp_engine.h:398
unsigned int rxploss
Definition: rtp_engine.h:424
int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
Retrieve statistics about an RTP instance.
Definition: rtp_engine.c:2570
ast_rtp_instance_stat
Definition: rtp_engine.h:185
unsigned int rxcount
Definition: rtp_engine.h:400
unsigned int local_ssrc
Definition: rtp_engine.h:452
unsigned int txploss
Definition: rtp_engine.h:422
unsigned int remote_ssrc
Definition: rtp_engine.h:454
void ast_rtp_instance_get_requested_target_address ( struct ast_rtp_instance instance,
struct ast_sockaddr address 
)

Get the requested target address of the remote endpoint.

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

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

Definition at line 695 of file rtp_engine.c.

References ast_sockaddr_copy(), and ast_rtp_instance::requested_target_address.

Referenced by ast_rtp_read().

697 {
698  ao2_lock(instance);
699  ast_sockaddr_copy(address, &instance->requested_target_address);
700  ao2_unlock(instance);
701 }
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
struct ast_sockaddr requested_target_address
Definition: rtp_engine.c:198
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 2911 of file rtp_engine.c.

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

2912 {
2913  if (rtcp && instance->rtcp_srtp) {
2914  return instance->rtcp_srtp;
2915  } else {
2916  return instance->srtp;
2917  }
2918 }
struct ast_srtp * srtp
Definition: rtp_engine.c:214
struct ast_srtp * rtcp_srtp
Definition: rtp_engine.c:216
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 3959 of file rtp_engine.c.

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

Referenced by add_ssrc_to_stream(), and create_outgoing_sdp_stream().

3960 {
3961  unsigned int ssrc = 0;
3962 
3963  ao2_lock(rtp);
3964  if (rtp->engine->ssrc_get) {
3965  ssrc = rtp->engine->ssrc_get(rtp);
3966  }
3967  ao2_unlock(rtp);
3968 
3969  return ssrc;
3970 }
unsigned int(* ssrc_get)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:732
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

1 struct ast_rtp_instance_stats stats;
2 ast_rtp_instance_get_stats(instance, &stats, AST_RTP_INSTANCE_STAT_ALL);

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

Since
1.8

Definition at line 2570 of file rtp_engine.c.

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

Referenced by ast_rtp_instance_get_quality(), ast_rtp_instance_get_stats_all_json(), and process_ssrc_attributes().

2571 {
2572  int res;
2573 
2574  if (!instance || !instance->engine || !stats) {
2575  return -1;
2576  }
2577 
2578  if (instance->engine->get_stat) {
2579  ao2_lock(instance);
2580  res = instance->engine->get_stat(instance, stats, stat);
2581  ao2_unlock(instance);
2582  } else {
2583  res = -1;
2584  }
2585  return res;
2586 }
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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
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 4213 of file rtp_engine.c.

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

Referenced by ast_ari_channels_rtpstatistics().

4214 {
4215  struct ast_rtp_instance_stats stats = {0,};
4216 
4217  if(ast_rtp_instance_get_stats(instance, &stats, AST_RTP_INSTANCE_STAT_ALL)) {
4218  return NULL;
4219  }
4220 
4221  return ast_rtp_convert_stats_json(&stats);
4222 }
int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
Retrieve statistics about an RTP instance.
Definition: rtp_engine.c:2570
struct ast_json * ast_rtp_convert_stats_json(const struct ast_rtp_instance_stats *stats)
Convert given stat instance into json format.
Definition: rtp_engine.c:4137
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:

1 int timeout = ast_rtp_instance_get_timeout(instance);

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

Since
1.8

Definition at line 2833 of file rtp_engine.c.

References ast_rtp_instance::timeout.

Referenced by rtp_check_timeout().

2834 {
2835  return instance->timeout;
2836 }
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:

1 ast_rtp_instance_make_compatible(instance, peer);

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

Since
1.8

Definition at line 2737 of file rtp_engine.c.

References ao2_ref, ast_rtp_instance_get_glue(), ast_rtp_instance::engine, ast_rtp_glue::get_rtp_info, ast_rtp_instance::glue, ast_rtp_engine::make_compatible, and ast_rtp_glue::type.

2738 {
2739  struct ast_rtp_glue *glue;
2740  struct ast_rtp_instance *peer_instance = NULL;
2741  int res = -1;
2742 
2743  if (!instance->engine->make_compatible) {
2744  return -1;
2745  }
2746 
2747  ast_channel_lock(peer);
2748 
2749  if (!(glue = ast_rtp_instance_get_glue(ast_channel_tech(peer)->type))) {
2750  ast_channel_unlock(peer);
2751  return -1;
2752  }
2753 
2754  glue->get_rtp_info(peer, &peer_instance);
2755  if (!peer_instance) {
2756  ast_log(LOG_ERROR, "Unable to get_rtp_info for peer type %s\n", glue->type);
2757  ast_channel_unlock(peer);
2758  return -1;
2759  }
2760  if (peer_instance->engine != instance->engine) {
2761  ast_log(LOG_ERROR, "Peer engine mismatch for type %s\n", glue->type);
2762  ast_channel_unlock(peer);
2763  ao2_ref(peer_instance, -1);
2764  return -1;
2765  }
2766 
2767  /*
2768  * XXX Good thing nothing calls this function because we would need
2769  * deadlock avoidance to get the two instance locks.
2770  */
2771  res = instance->engine->make_compatible(chan, instance, peer, peer_instance);
2772 
2773  ast_channel_unlock(peer);
2774 
2775  ao2_ref(peer_instance, -1);
2776  peer_instance = NULL;
2777 
2778  return res;
2779 }
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
const char * type
Definition: rtp_engine.h:775
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:782
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
struct ast_rtp_glue * ast_rtp_instance_get_glue(const char *type)
Get the RTP glue that binds a channel to the RTP engine.
Definition: rtp_engine.c:2330
Structure to describe a channel "technology", ie a channel driver See for examples: ...
Definition: channel.h:628
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

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

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

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

Definition at line 487 of file rtp_engine.c.

References ao2_ref, ast_debug, ast_module_running_ref, ast_module_unref, ast_rtp_codecs_payloads_initialize(), AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK, ast_sockaddr_copy(), AST_VECTOR_INIT, ast_rtp_instance::codecs, ast_rtp_instance::engine, ast_rtp_instance::extmap_enabled, ast_rtp_instance::extmap_negotiated, ast_rtp_instance::extmap_unique_ids, ast_rtp_instance::local_address, ast_rtp_engine::mod, ast_rtp_engine::name, and ast_rtp_engine::new.

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

490 {
491  struct ast_sockaddr address = {{0,}};
492  struct ast_rtp_instance *instance = NULL;
493  struct ast_rtp_engine *engine = NULL;
494  struct ast_module *mod_ref;
495 
497 
498  /* If an engine name was specified try to use it or otherwise use the first one registered */
499  if (!ast_strlen_zero(engine_name)) {
500  AST_RWLIST_TRAVERSE(&engines, engine, entry) {
501  if (!strcmp(engine->name, engine_name)) {
502  break;
503  }
504  }
505  } else {
506  engine = AST_RWLIST_FIRST(&engines);
507  }
508 
509  /* If no engine was actually found bail out now */
510  if (!engine) {
511  ast_log(LOG_ERROR, "No RTP engine was found. Do you have one loaded?\n");
513  return NULL;
514  }
515 
516  /* Bump up the reference count before we return so the module can not be unloaded */
517  mod_ref = ast_module_running_ref(engine->mod);
518 
520 
521  if (!mod_ref) {
522  /* BUGBUG: improve handling of this situation. */
523  return NULL;
524  }
525 
526  /* Allocate a new RTP instance */
527  if (!(instance = ao2_alloc(sizeof(*instance), instance_destructor))) {
528  ast_module_unref(engine->mod);
529  return NULL;
530  }
531  instance->engine = engine;
532  ast_sockaddr_copy(&instance->local_address, sa);
533  ast_sockaddr_copy(&address, sa);
534 
535  if (ast_rtp_codecs_payloads_initialize(&instance->codecs)) {
536  ao2_ref(instance, -1);
537  return NULL;
538  }
539 
540  /* Initialize RTP extension support */
541  if (AST_VECTOR_INIT(&instance->extmap_enabled, 0) ||
542  AST_VECTOR_INIT(&instance->extmap_negotiated, 0) ||
543  AST_VECTOR_INIT(&instance->extmap_unique_ids, 0)) {
544  ao2_ref(instance, -1);
545  return NULL;
546  }
547 
548  ast_debug(1, "Using engine '%s' for RTP instance '%p'\n", engine->name, instance);
549 
550  /*
551  * And pass it off to the engine to setup
552  *
553  * Lock in case the RTP engine has other threads that
554  * need synchronization with the construction.
555  */
556  ao2_lock(instance);
557  if (instance->engine->new(instance, sched, &address, data)) {
558  ast_debug(1, "Engine '%s' failed to setup RTP instance '%p'\n", engine->name, instance);
559  ao2_unlock(instance);
560  ao2_ref(instance, -1);
561  return NULL;
562  }
563  ao2_unlock(instance);
564 
565  ast_debug(1, "RTP instance '%p' is setup and ready to go\n", instance);
566 
567  return instance;
568 }
int ast_rtp_codecs_payloads_initialize(struct ast_rtp_codecs *codecs)
Initialize an RTP codecs structure.
Definition: rtp_engine.c:980
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
struct ast_rtp_instance::@388 extmap_enabled
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
Socket address structure.
Definition: netsock2.h:97
struct ast_rtp_instance::@390 extmap_unique_ids
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
int(* new)(struct ast_rtp_instance *instance, struct ast_sched_context *sched, struct ast_sockaddr *sa, void *data)
Definition: rtp_engine.h:671
#define ast_debug(level,...)
Log a DEBUG message.
struct ast_module * mod
Definition: rtp_engine.h:669
const char * name
Definition: rtp_engine.h:667
struct ast_sockaddr local_address
Definition: rtp_engine.c:196
#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
struct ast_rtp_instance::@389 extmap_negotiated
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
Definition: search.h:40
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
struct ast_rtp_codecs codecs
Definition: rtp_engine.c:204
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:

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

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

Since
1.8

Definition at line 600 of file rtp_engine.c.

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

Referenced by jingle_read(), and rtp_read().

601 {
602  struct ast_frame *frame;
603 
604  ao2_lock(instance);
605  frame = instance->engine->read(instance, rtcp);
606  ao2_unlock(instance);
607  return frame;
608 }
struct ast_frame *(* read)(struct ast_rtp_instance *instance, int rtcp)
Definition: rtp_engine.h:712
Data structure associated with a single frame of data.
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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 2920 of file rtp_engine.c.

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

2921 {
2922  int res;
2923 
2924  if (instance->engine->sendcng) {
2925  ao2_lock(instance);
2926  res = instance->engine->sendcng(instance, level);
2927  ao2_unlock(instance);
2928  } else {
2929  res = -1;
2930  }
2931  return res;
2932 }
int(* sendcng)(struct ast_rtp_instance *instance, int level)
Definition: rtp_engine.h:730
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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 2368 of file rtp_engine.c.

References ast_rtp_instance::bridged.

2369 {
2370  ao2_lock(instance);
2371  instance->bridged = bridged;
2372  ao2_unlock(instance);
2373 }
struct ast_rtp_instance * bridged
Definition: rtp_engine.c:202
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 575 of file rtp_engine.c.

References ast_copy_string(), and ast_rtp_instance::channel_uniqueid.

Referenced by jingle_enable_video(), jingle_set_owner(), multicast_rtp_request(), and unicast_rtp_request().

576 {
577  ast_copy_string(instance->channel_uniqueid, uniqueid, sizeof(instance->channel_uniqueid));
578 }
char channel_uniqueid[AST_MAX_UNIQUEID]
Definition: rtp_engine.c:218
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
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:

1 ast_rtp_instance_set_data(instance, blob);

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

Since
1.8

Definition at line 580 of file rtp_engine.c.

References ast_rtp_instance::data.

Referenced by ast_rtp_new(), and multicast_rtp_new().

581 {
582  instance->data = data;
583 }
union ast_frame::@224 data
void ast_rtp_instance_set_extended_prop ( struct ast_rtp_instance instance,
int  property,
void *  value 
)

Set the value of an RTP instance extended property.

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

Definition at line 703 of file rtp_engine.c.

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

704 {
705  if (instance->engine->extended_prop_set) {
706  ao2_lock(instance);
707  instance->engine->extended_prop_set(instance, property, value);
708  ao2_unlock(instance);
709  }
710 }
int(* extended_prop_set)(struct ast_rtp_instance *instance, int property, void *value)
Definition: rtp_engine.h:688
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

1 ast_rtp_instance_set_hold_timeout(instance, 5000);

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

Since
1.8

Definition at line 2823 of file rtp_engine.c.

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

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

Referenced by ast_rtp_read().

630 {
631  ao2_lock(instance);
632  rtp_instance_set_incoming_source_address_nolock(instance, address);
633  ao2_unlock(instance);
634 
635  return 0;
636 }
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:

1 ast_rtp_instance_set_keepalive(instance, 5000);

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

Since
1.8

Definition at line 2828 of file rtp_engine.c.

References ast_rtp_instance::keepalive.

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

References ast_rtp_instance::last_rx.

Referenced by create_rtp(), and rtp_check_timeout().

3955 {
3956  rtp->last_rx = time;
3957 }
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 3944 of file rtp_engine.c.

References ast_rtp_instance::last_tx.

Referenced by __rtp_sendto().

3945 {
3946  rtp->last_tx = time;
3947 }
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:

1 ast_rtp_instance_set_local_address(instance, &sin);

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

Since
1.8

Definition at line 610 of file rtp_engine.c.

References ast_sockaddr_copy(), and ast_rtp_instance::local_address.

Referenced by ast_rtp_remote_address_set().

612 {
613  ao2_lock(instance);
614  ast_sockaddr_copy(&instance->local_address, address);
615  ao2_unlock(instance);
616  return 0;
617 }
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
struct ast_sockaddr local_address
Definition: rtp_engine.c:196
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:

1 ast_rtp_instance_set_prop(instance, AST_RTP_PROPERTY_NAT, 1);

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

Since
1.8

Definition at line 727 of file rtp_engine.c.

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

Referenced by check_for_rtp_changes(), create_rtp(), enable_rtcp(), jingle_alloc(), jingle_enable_video(), and pjsip_acf_dtmf_mode_write().

728 {
729  ao2_lock(instance);
730  instance->properties[property] = value;
731 
732  if (instance->engine->prop_set) {
733  instance->engine->prop_set(instance, property, value);
734  }
735  ao2_unlock(instance);
736 }
void(* prop_set)(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value)
Definition: rtp_engine.h:692
int properties[AST_RTP_PROPERTY_MAX]
Definition: rtp_engine.c:194
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

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

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

Since
1.8

Definition at line 2293 of file rtp_engine.c.

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

Referenced by create_rtp().

2294 {
2295  int res;
2296 
2297  if (instance->engine->qos) {
2298  ao2_lock(instance);
2299  res = instance->engine->qos(instance, tos, cos, desc);
2300  ao2_unlock(instance);
2301  } else {
2302  res = -1;
2303  }
2304  return res;
2305 }
int(* qos)(struct ast_rtp_instance *instance, int tos, int cos, const char *desc)
Definition: rtp_engine.h:704
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

1 struct ast_format tmp_fmt;
2 ast_rtp_instance_set_read_format(instance, ast_format_ulaw);

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

Since
1.8

Definition at line 2708 of file rtp_engine.c.

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

2709 {
2710  int res;
2711 
2712  if (instance->engine->set_read_format) {
2713  ao2_lock(instance);
2714  res = instance->engine->set_read_format(instance, format);
2715  ao2_unlock(instance);
2716  } else {
2717  res = -1;
2718  }
2719  return res;
2720 }
int(* set_read_format)(struct ast_rtp_instance *instance, struct ast_format *format)
Definition: rtp_engine.h:716
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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 4002 of file rtp_engine.c.

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

Referenced by process_ssrc_attributes().

4003 {
4004  ao2_lock(rtp);
4005  if (rtp->engine->set_remote_ssrc) {
4006  rtp->engine->set_remote_ssrc(rtp, ssrc);
4007  }
4008  ao2_unlock(rtp);
4009 }
void(* set_remote_ssrc)(struct ast_rtp_instance *instance, unsigned int ssrc)
Definition: rtp_engine.h:738
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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 638 of file rtp_engine.c.

References ast_sockaddr_copy(), and ast_rtp_instance::requested_target_address.

640 {
641  ao2_lock(instance);
642 
643  ast_sockaddr_copy(&instance->requested_target_address, address);
644  rtp_instance_set_incoming_source_address_nolock(instance, address);
645 
646  ao2_unlock(instance);
647 
648  return 0;
649 }
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
struct ast_sockaddr requested_target_address
Definition: rtp_engine.c:198
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
Note
Absolutely NO channel locks should be held before calling this function.

Example usage:

1 ast_rtp_instance_set_stats_vars(chan, rtp);

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

References ast_channel_bridge_peer(), ast_channel_lock_both, ast_channel_stage_snapshot(), ast_channel_stage_snapshot_done(), ast_channel_unref, AST_MAX_USER_FIELD, ast_rtp_instance_get_quality(), AST_RTP_INSTANCE_STAT_FIELD_QUALITY, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, ast_channel::bridge, and pbx_builtin_setvar_helper().

Referenced by chan_pjsip_session_end().

2640 {
2641  char quality_buf[AST_MAX_USER_FIELD];
2642  char *quality;
2643  struct ast_channel *bridge;
2644 
2645  bridge = ast_channel_bridge_peer(chan);
2646  if (bridge) {
2647  ast_channel_lock_both(chan, bridge);
2649  } else {
2650  ast_channel_lock(chan);
2651  }
2653 
2655  quality_buf, sizeof(quality_buf));
2656  if (quality) {
2657  pbx_builtin_setvar_helper(chan, "RTPAUDIOQOS", quality);
2658  if (bridge) {
2659  pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSBRIDGED", quality);
2660  }
2661  }
2662 
2663  quality = ast_rtp_instance_get_quality(instance,
2664  AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, quality_buf, sizeof(quality_buf));
2665  if (quality) {
2666  pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSJITTER", quality);
2667  if (bridge) {
2668  pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSJITTERBRIDGED", quality);
2669  }
2670  }
2671 
2672  quality = ast_rtp_instance_get_quality(instance,
2673  AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, quality_buf, sizeof(quality_buf));
2674  if (quality) {
2675  pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSLOSS", quality);
2676  if (bridge) {
2677  pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSLOSSBRIDGED", quality);
2678  }
2679  }
2680 
2681  quality = ast_rtp_instance_get_quality(instance,
2682  AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, quality_buf, sizeof(quality_buf));
2683  if (quality) {
2684  pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSRTT", quality);
2685  if (bridge) {
2686  pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSRTTBRIDGED", quality);
2687  }
2688  }
2689 
2690  quality = ast_rtp_instance_get_quality(instance,
2691  AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES, quality_buf, sizeof(quality_buf));
2692  if (quality) {
2693  pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSMES", quality);
2694  if (bridge) {
2695  pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSMESBRIDGED", quality);
2696  }
2697  }
2698 
2700  ast_channel_unlock(chan);
2701  if (bridge) {
2703  ast_channel_unlock(bridge);
2704  ast_channel_unref(bridge);
2705  }
2706 }
Main Channel structure associated with a channel.
char * ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size)
Retrieve quality statistics about an RTP instance.
Definition: rtp_engine.c:2588
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2958
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.
struct ast_bridge * bridge
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name...
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition: channel.h:2929
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:10564
#define AST_MAX_USER_FIELD
Definition: channel.h:174
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 4011 of file rtp_engine.c.

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

4012 {
4013  ao2_lock(rtp);
4014  if (rtp->engine->set_stream_num) {
4015  rtp->engine->set_stream_num(rtp, stream_num);
4016  }
4017  ao2_unlock(rtp);
4018 }
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:

1 ast_rtp_instance_set_timeout(instance, 5000);

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

Since
1.8

Definition at line 2818 of file rtp_engine.c.

References ast_rtp_instance::timeout.

2819 {
2820  instance->timeout = timeout;
2821 }
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:

1 struct ast_format tmp_fmt;
2 ast_rtp_instance_set_write_format(instance, ast_format_ulaw);

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

Since
1.8

Definition at line 2722 of file rtp_engine.c.

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

2723 {
2724  int res;
2725 
2726  if (instance->engine->set_read_format) {
2727  ao2_lock(instance);
2728  res = instance->engine->set_write_format(instance, format);
2729  ao2_unlock(instance);
2730  } else {
2731  res = -1;
2732  }
2733  return res;
2734 }
int(* set_write_format)(struct ast_rtp_instance *instance, struct ast_format *format)
Definition: rtp_engine.h:718
int(* set_read_format)(struct ast_rtp_instance *instance, struct ast_format *format)
Definition: rtp_engine.h:716
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

1 ast_rtp_instance_stop(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 2307 of file rtp_engine.c.

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

Referenced by jingle_session_destructor(), and stream_stop().

2308 {
2309  if (instance->engine->stop) {
2310  ao2_lock(instance);
2311  instance->engine->stop(instance);
2312  ao2_unlock(instance);
2313  }
2314 }
void(* stop)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:677
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

1 ast_rtp_instance_stun_request(instance, NULL, NULL);

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

Since
1.8

Definition at line 2809 of file rtp_engine.c.

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

Referenced by jingle_interpret_google_transport().

2812 {
2813  if (instance->engine->stun_request) {
2814  instance->engine->stun_request(instance, suggestion, username);
2815  }
2816 }
void(* stun_request)(struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username)
Definition: rtp_engine.h:726
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

1 ast_rtp_instance_update_source(instance);

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

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

Referenced by jingle_indicate().

2276 {
2277  if (instance->engine->update_source) {
2278  ao2_lock(instance);
2279  instance->engine->update_source(instance);
2280  ao2_unlock(instance);
2281  }
2282 }
void(* update_source)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:684
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

1 ast_rtp_instance_write(instance, frame);

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

Since
1.8

Definition at line 590 of file rtp_engine.c.

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

Referenced by chan_pjsip_indicate(), jingle_write(), and rtp_write().

591 {
592  int res;
593 
594  ao2_lock(instance);
595  res = instance->engine->write(instance, frame);
596  ao2_unlock(instance);
597  return res;
598 }
int(* write)(struct ast_rtp_instance *instance, struct ast_frame *frame)
Definition: rtp_engine.h:675
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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:

1 char buf[256] = "";
2 struct ast_format tmp_fmt;
3 struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
4 ast_format_cap_append(cap, ast_format_ulaw, 0);
5 ast_format_cap_append(cap, ast_format_ulaw, 0);
6 char *mime = ast_rtp_lookup_mime_multiple2(&buf, sizeof(buf), cap, 0, 1, 0);
7 ast_format_cap_destroy(cap);

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

Since
1.8

Definition at line 2169 of file rtp_engine.c.

References ao2_ref, ast_format_cap_count(), ast_format_cap_get_format(), ast_rtp_lookup_mime_subtype2(), AST_RTP_MAX, ast_str_append(), and ast_str_buffer().

2170 {
2171  int found = 0;
2172  const char *name;
2173  if (!buf) {
2174  return NULL;
2175  }
2176 
2177 
2178  if (asterisk_format) {
2179  int x;
2180  struct ast_format *tmp_fmt;
2181  for (x = 0; x < ast_format_cap_count(ast_format_capability); x++) {
2182  tmp_fmt = ast_format_cap_get_format(ast_format_capability, x);
2183  name = ast_rtp_lookup_mime_subtype2(asterisk_format, tmp_fmt, 0, options);
2184  ao2_ref(tmp_fmt, -1);
2185  ast_str_append(&buf, 0, "%s|", name);
2186  found = 1;
2187  }
2188  } else {
2189  int x;
2190  ast_str_append(&buf, 0, "0x%x (", (unsigned int) rtp_capability);
2191  for (x = 1; x <= AST_RTP_MAX; x <<= 1) {
2192  if (rtp_capability & x) {
2193  name = ast_rtp_lookup_mime_subtype2(asterisk_format, NULL, x, options);
2194  ast_str_append(&buf, 0, "%s|", name);
2195  found = 1;
2196  }
2197  }
2198  }
2199 
2200  ast_str_append(&buf, 0, "%s", found ? ")" : "nothing)");
2201 
2202  return ast_str_buffer(buf);
2203 }
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
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.
Definition: rtp_engine.c:2116
Definition of a media format.
Definition: format.c:43
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
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
#define AST_RTP_MAX
Definition: rtp_engine.h:300
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
const ast_string_field name
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
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:

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

This looks up the mime subtype for the ULAW format.

Since
1.8

Definition at line 2116 of file rtp_engine.c.

References ast_format_cmp(), AST_FORMAT_CMP_EQUAL, AST_FORMAT_CMP_NOT_EQUAL, ast_format_g726_aal2, AST_RTP_OPT_G726_NONSTANDARD, 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(), and jingle_add_payloads_to_description().

2118 {
2119  int i;
2120  const char *res = "";
2121 
2122  ast_rwlock_rdlock(&mime_types_lock);
2123  for (i = 0; i < mime_types_len; i++) {
2124  if (ast_rtp_mime_types[i].payload_type.asterisk_format && asterisk_format && format &&
2125  (ast_format_cmp(format, ast_rtp_mime_types[i].payload_type.format) != AST_FORMAT_CMP_NOT_EQUAL)) {
2127  (options & AST_RTP_OPT_G726_NONSTANDARD)) {
2128  res = "G726-32";
2129  break;
2130  } else {
2131  res = ast_rtp_mime_types[i].subtype;
2132  break;
2133  }
2134  } else if (!ast_rtp_mime_types[i].payload_type.asterisk_format && !asterisk_format &&
2135  ast_rtp_mime_types[i].payload_type.rtp_code == code) {
2136 
2137  res = ast_rtp_mime_types[i].subtype;
2138  break;
2139  }
2140  }
2141  ast_rwlock_unlock(&mime_types_lock);
2142 
2143  return res;
2144 }
char subtype[64]
The format type.
Definition: rtp_engine.c:256
struct ast_format * ast_format_g726_aal2
Built-in cached g726 aal2 format.
Definition: format_cache.c:116
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
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 2146 of file rtp_engine.c.

References ast_format_cmp(), AST_FORMAT_CMP_NOT_EQUAL, 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(), and jingle_add_payloads_to_description().

2148 {
2149  unsigned int i;
2150  unsigned int res = 0;
2151 
2152  ast_rwlock_rdlock(&mime_types_lock);
2153  for (i = 0; i < mime_types_len; ++i) {
2154  if (ast_rtp_mime_types[i].payload_type.asterisk_format && asterisk_format && format &&
2155  (ast_format_cmp(format, ast_rtp_mime_types[i].payload_type.format) != AST_FORMAT_CMP_NOT_EQUAL)) {
2156  res = ast_rtp_mime_types[i].sample_rate;
2157  break;
2158  } else if (!ast_rtp_mime_types[i].payload_type.asterisk_format && !asterisk_format &&
2159  ast_rtp_mime_types[i].payload_type.rtp_code == code) {
2160  res = ast_rtp_mime_types[i].sample_rate;
2161  break;
2162  }
2163  }
2164  ast_rwlock_unlock(&mime_types_lock);
2165 
2166  return res;
2167 }
unsigned int sample_rate
Expected sample rate of the /c subtype.
Definition: rtp_engine.c:258
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
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 3638 of file rtp_engine.c.

References ao2_ref, ast_channel_snapshot_get_latest(), ast_json_ref(), ast_rtp_topic(), ast_rtp_instance::channel_uniqueid, RAII_VAR, stasis_message_create(), and stasis_publish().

Referenced by ast_rtcp_interpret().

3642 {
3643  RAII_VAR(struct rtcp_message_payload *, payload, NULL, ao2_cleanup);
3644  RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
3645 
3646  if (!message_type) {
3647  return;
3648  }
3649 
3650  payload = ao2_alloc(sizeof(*payload), rtcp_message_payload_dtor);
3651  if (!payload || !report) {
3652  return;
3653  }
3654 
3655  if (!ast_strlen_zero(rtp->channel_uniqueid)) {
3656  payload->snapshot = ast_channel_snapshot_get_latest(rtp->channel_uniqueid);
3657  }
3658  if (blob) {
3659  payload->blob = blob;
3660  ast_json_ref(blob);
3661  }
3662  ao2_ref(report, +1);
3663  payload->report = report;
3664 
3665  message = stasis_message_create(message_type, payload);
3666  if (!message) {
3667  return;
3668  }
3669 
3671 }
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
Definition: rtp_engine.c:3684
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
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:1511
char channel_uniqueid[AST_MAX_UNIQUEID]
Definition: rtp_engine.c:218
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...
#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:941
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 2556 of file rtp_engine.c.

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

2557 {
2558  int res;
2559 
2560  if (instance->engine->red_buffer) {
2561  ao2_lock(instance);
2562  res = instance->engine->red_buffer(instance, frame);
2563  ao2_unlock(instance);
2564  } else {
2565  res = -1;
2566  }
2567  return res;
2568 }
int(* red_buffer)(struct ast_rtp_instance *instance, struct ast_frame *frame)
Definition: rtp_engine.h:710
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
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 2542 of file rtp_engine.c.

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

2543 {
2544  int res;
2545 
2546  if (instance->engine->red_init) {
2547  ao2_lock(instance);
2548  res = instance->engine->red_init(instance, buffer_time, payloads, generations);
2549  ao2_unlock(instance);
2550  } else {
2551  res = -1;
2552  }
2553  return res;
2554 }
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
int(* red_init)(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations)
Definition: rtp_engine.h:708
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 3627 of file rtp_engine.c.

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

3628 {
3629  struct ast_rtp_rtcp_report *rtcp_report;
3630 
3631  /* Size of object is sizeof the report + the number of report_blocks * sizeof pointer */
3632  rtcp_report = ao2_alloc((sizeof(*rtcp_report) + report_blocks * sizeof(struct ast_rtp_rtcp_report_block *)),
3633  rtp_rtcp_report_dtor);
3634 
3635  return rtcp_report;
3636 }
An object that represents data sent during a SR/RR RTCP report.
Definition: rtp_engine.h:361
A report block within a SR/RR report.
Definition: rtp_engine.h:346
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 3684 of file rtp_engine.c.

References rtp_topic.

Referenced by ast_rtp_publish_rtcp_message(), and manager_subscriptions_init().

3685 {
3686  return rtp_topic;
3687 }
static struct stasis_topic * rtp_topic
Stasis Message Bus API topic for RTP related messages
Definition: rtp_engine.c:277