00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 1999 - 2009, Digium, Inc. 00005 * 00006 * Mark Spencer <markster@digium.com> 00007 * Joshua Colp <jcolp@digium.com> 00008 * 00009 * See http://www.asterisk.org for more information about 00010 * the Asterisk project. Please do not directly contact 00011 * any of the maintainers of this project for assistance; 00012 * the project provides a web site, mailing lists and IRC 00013 * channels for your use. 00014 * 00015 * This program is free software, distributed under the terms of 00016 * the GNU General Public License Version 2. See the LICENSE file 00017 * at the top of the source tree. 00018 */ 00019 00020 /*! \file 00021 * \brief Pluggable RTP Architecture 00022 * \author Joshua Colp <jcolp@digium.com> 00023 * \ref AstRTPEngine 00024 */ 00025 00026 /*! 00027 * \page AstRTPEngine Asterisk RTP Engine API 00028 * 00029 * The purpose of this API is to provide a way for multiple RTP stacks to be 00030 * used inside of Asterisk without any module that uses RTP knowing any 00031 * different. To the module each RTP stack behaves the same. 00032 * 00033 * An RTP session is called an instance and is made up of a combination of codec 00034 * information, RTP engine, RTP properties, and address information. An engine 00035 * name may be passed in to explicitly choose an RTP stack to be used but a 00036 * default one will be used if none is provided. An address to use for RTP may 00037 * also be provided but the underlying RTP engine may choose a different address 00038 * depending on it's configuration. 00039 * 00040 * An RTP engine is the layer between the RTP engine core and the RTP stack 00041 * itself. The RTP engine core provides a set of callbacks to do various things 00042 * (such as write audio out) that the RTP engine has to have implemented. 00043 * 00044 * Glue is what binds an RTP instance to a channel. It is used to retrieve RTP 00045 * instance information when performing remote or local bridging and is used to 00046 * have the channel driver tell the remote side to change destination of the RTP 00047 * stream. 00048 * 00049 * Statistics from an RTP instance can be retrieved using the 00050 * ast_rtp_instance_get_stats API call. This essentially asks the RTP engine in 00051 * use to fill in a structure with the requested values. It is not required for 00052 * an RTP engine to support all statistic values. 00053 * 00054 * Properties allow behavior of the RTP engine and RTP engine core to be 00055 * changed. For example, there is a property named AST_RTP_PROPERTY_NAT which is 00056 * used to tell the RTP engine to enable symmetric RTP if it supports it. It is 00057 * not required for an RTP engine to support all properties. 00058 * 00059 * Codec information is stored using a separate data structure which has it's 00060 * own set of API calls to add/remove/retrieve information. They are used by the 00061 * module after an RTP instance is created so that payload information is 00062 * available for the RTP engine. 00063 */ 00064 00065 #ifndef _ASTERISK_RTP_ENGINE_H 00066 #define _ASTERISK_RTP_ENGINE_H 00067 00068 #if defined(__cplusplus) || defined(c_plusplus) 00069 extern "C" { 00070 #endif 00071 00072 #include "asterisk/astobj2.h" 00073 #include "asterisk/frame.h" 00074 #include "asterisk/netsock2.h" 00075 #include "asterisk/sched.h" 00076 #include "asterisk/res_srtp.h" 00077 00078 /* Maximum number of payloads supported */ 00079 #if defined(LOW_MEMORY) 00080 #define AST_RTP_MAX_PT 128 00081 #else 00082 #define AST_RTP_MAX_PT 196 00083 #endif 00084 00085 /* Maximum number of generations */ 00086 #define AST_RED_MAX_GENERATION 5 00087 00088 struct ast_rtp_instance; 00089 struct ast_rtp_glue; 00090 00091 /*! RTP Properties that can be set on an RTP instance */ 00092 enum ast_rtp_property { 00093 /*! Enable symmetric RTP support */ 00094 AST_RTP_PROPERTY_NAT = 0, 00095 /*! RTP instance will be carrying DTMF (using RFC2833) */ 00096 AST_RTP_PROPERTY_DTMF, 00097 /*! Expect unreliable DTMF from remote party */ 00098 AST_RTP_PROPERTY_DTMF_COMPENSATE, 00099 /*! Enable STUN support */ 00100 AST_RTP_PROPERTY_STUN, 00101 /*! Enable RTCP support */ 00102 AST_RTP_PROPERTY_RTCP, 00103 00104 /*! 00105 * \brief Maximum number of RTP properties supported 00106 * 00107 * \note THIS MUST BE THE LAST ENTRY IN THIS ENUM. 00108 */ 00109 AST_RTP_PROPERTY_MAX, 00110 }; 00111 00112 /*! Additional RTP options */ 00113 enum ast_rtp_options { 00114 /*! Remote side is using non-standard G.726 */ 00115 AST_RTP_OPT_G726_NONSTANDARD = (1 << 0), 00116 }; 00117 00118 /*! RTP DTMF Modes */ 00119 enum ast_rtp_dtmf_mode { 00120 /*! No DTMF is being carried over the RTP stream */ 00121 AST_RTP_DTMF_MODE_NONE = 0, 00122 /*! DTMF is being carried out of band using RFC2833 */ 00123 AST_RTP_DTMF_MODE_RFC2833, 00124 /*! DTMF is being carried inband over the RTP stream */ 00125 AST_RTP_DTMF_MODE_INBAND, 00126 }; 00127 00128 /*! Result codes when RTP glue is queried for information */ 00129 enum ast_rtp_glue_result { 00130 /*! No remote or local bridging is permitted */ 00131 AST_RTP_GLUE_RESULT_FORBID = 0, 00132 /*! Move RTP stream to be remote between devices directly */ 00133 AST_RTP_GLUE_RESULT_REMOTE, 00134 /*! Perform RTP engine level bridging if possible */ 00135 AST_RTP_GLUE_RESULT_LOCAL, 00136 }; 00137 00138 /*! Field statistics that can be retrieved from an RTP instance */ 00139 enum ast_rtp_instance_stat_field { 00140 /*! Retrieve quality information */ 00141 AST_RTP_INSTANCE_STAT_FIELD_QUALITY = 0, 00142 /*! Retrieve quality information about jitter */ 00143 AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, 00144 /*! Retrieve quality information about packet loss */ 00145 AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, 00146 /*! Retrieve quality information about round trip time */ 00147 AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, 00148 }; 00149 00150 /*! Statistics that can be retrieved from an RTP instance */ 00151 enum ast_rtp_instance_stat { 00152 /*! Retrieve all statistics */ 00153 AST_RTP_INSTANCE_STAT_ALL = 0, 00154 /*! Retrieve number of packets transmitted */ 00155 AST_RTP_INSTANCE_STAT_TXCOUNT, 00156 /*! Retrieve number of packets received */ 00157 AST_RTP_INSTANCE_STAT_RXCOUNT, 00158 /*! Retrieve ALL statistics relating to packet loss */ 00159 AST_RTP_INSTANCE_STAT_COMBINED_LOSS, 00160 /*! Retrieve number of packets lost for transmitting */ 00161 AST_RTP_INSTANCE_STAT_TXPLOSS, 00162 /*! Retrieve number of packets lost for receiving */ 00163 AST_RTP_INSTANCE_STAT_RXPLOSS, 00164 /*! Retrieve maximum number of packets lost on remote side */ 00165 AST_RTP_INSTANCE_STAT_REMOTE_MAXRXPLOSS, 00166 /*! Retrieve minimum number of packets lost on remote side */ 00167 AST_RTP_INSTANCE_STAT_REMOTE_MINRXPLOSS, 00168 /*! Retrieve average number of packets lost on remote side */ 00169 AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVRXPLOSS, 00170 /*! Retrieve standard deviation of packets lost on remote side */ 00171 AST_RTP_INSTANCE_STAT_REMOTE_STDEVRXPLOSS, 00172 /*! Retrieve maximum number of packets lost on local side */ 00173 AST_RTP_INSTANCE_STAT_LOCAL_MAXRXPLOSS, 00174 /*! Retrieve minimum number of packets lost on local side */ 00175 AST_RTP_INSTANCE_STAT_LOCAL_MINRXPLOSS, 00176 /*! Retrieve average number of packets lost on local side */ 00177 AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVRXPLOSS, 00178 /*! Retrieve standard deviation of packets lost on local side */ 00179 AST_RTP_INSTANCE_STAT_LOCAL_STDEVRXPLOSS, 00180 /*! Retrieve ALL statistics relating to jitter */ 00181 AST_RTP_INSTANCE_STAT_COMBINED_JITTER, 00182 /*! Retrieve jitter on transmitted packets */ 00183 AST_RTP_INSTANCE_STAT_TXJITTER, 00184 /*! Retrieve jitter on received packets */ 00185 AST_RTP_INSTANCE_STAT_RXJITTER, 00186 /*! Retrieve maximum jitter on remote side */ 00187 AST_RTP_INSTANCE_STAT_REMOTE_MAXJITTER, 00188 /*! Retrieve minimum jitter on remote side */ 00189 AST_RTP_INSTANCE_STAT_REMOTE_MINJITTER, 00190 /*! Retrieve average jitter on remote side */ 00191 AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVJITTER, 00192 /*! Retrieve standard deviation jitter on remote side */ 00193 AST_RTP_INSTANCE_STAT_REMOTE_STDEVJITTER, 00194 /*! Retrieve maximum jitter on local side */ 00195 AST_RTP_INSTANCE_STAT_LOCAL_MAXJITTER, 00196 /*! Retrieve minimum jitter on local side */ 00197 AST_RTP_INSTANCE_STAT_LOCAL_MINJITTER, 00198 /*! Retrieve average jitter on local side */ 00199 AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVJITTER, 00200 /*! Retrieve standard deviation jitter on local side */ 00201 AST_RTP_INSTANCE_STAT_LOCAL_STDEVJITTER, 00202 /*! Retrieve ALL statistics relating to round trip time */ 00203 AST_RTP_INSTANCE_STAT_COMBINED_RTT, 00204 /*! Retrieve round trip time */ 00205 AST_RTP_INSTANCE_STAT_RTT, 00206 /*! Retrieve maximum round trip time */ 00207 AST_RTP_INSTANCE_STAT_MAX_RTT, 00208 /*! Retrieve minimum round trip time */ 00209 AST_RTP_INSTANCE_STAT_MIN_RTT, 00210 /*! Retrieve average round trip time */ 00211 AST_RTP_INSTANCE_STAT_NORMDEVRTT, 00212 /*! Retrieve standard deviation round trip time */ 00213 AST_RTP_INSTANCE_STAT_STDEVRTT, 00214 /*! Retrieve local SSRC */ 00215 AST_RTP_INSTANCE_STAT_LOCAL_SSRC, 00216 /*! Retrieve remote SSRC */ 00217 AST_RTP_INSTANCE_STAT_REMOTE_SSRC, 00218 }; 00219 00220 /* Codes for RTP-specific data - not defined by our AST_FORMAT codes */ 00221 /*! DTMF (RFC2833) */ 00222 #define AST_RTP_DTMF (1 << 0) 00223 /*! 'Comfort Noise' (RFC3389) */ 00224 #define AST_RTP_CN (1 << 1) 00225 /*! DTMF (Cisco Proprietary) */ 00226 #define AST_RTP_CISCO_DTMF (1 << 2) 00227 /*! Maximum RTP-specific code */ 00228 #define AST_RTP_MAX AST_RTP_CISCO_DTMF 00229 00230 /*! Structure that represents a payload */ 00231 struct ast_rtp_payload_type { 00232 /*! Is this an Asterisk value */ 00233 int asterisk_format; 00234 /*! If asterisk_format is set, this is the internal 00235 * asterisk format represented by the payload */ 00236 struct ast_format format; 00237 /*! Actual internal RTP specific value of the payload */ 00238 int rtp_code; 00239 /*! Actual payload number */ 00240 int payload; 00241 }; 00242 00243 /*! Structure that represents statistics from an RTP instance */ 00244 struct ast_rtp_instance_stats { 00245 /*! Number of packets transmitted */ 00246 unsigned int txcount; 00247 /*! Number of packets received */ 00248 unsigned int rxcount; 00249 /*! Jitter on transmitted packets */ 00250 double txjitter; 00251 /*! Jitter on received packets */ 00252 double rxjitter; 00253 /*! Maximum jitter on remote side */ 00254 double remote_maxjitter; 00255 /*! Minimum jitter on remote side */ 00256 double remote_minjitter; 00257 /*! Average jitter on remote side */ 00258 double remote_normdevjitter; 00259 /*! Standard deviation jitter on remote side */ 00260 double remote_stdevjitter; 00261 /*! Maximum jitter on local side */ 00262 double local_maxjitter; 00263 /*! Minimum jitter on local side */ 00264 double local_minjitter; 00265 /*! Average jitter on local side */ 00266 double local_normdevjitter; 00267 /*! Standard deviation jitter on local side */ 00268 double local_stdevjitter; 00269 /*! Number of transmitted packets lost */ 00270 unsigned int txploss; 00271 /*! Number of received packets lost */ 00272 unsigned int rxploss; 00273 /*! Maximum number of packets lost on remote side */ 00274 double remote_maxrxploss; 00275 /*! Minimum number of packets lost on remote side */ 00276 double remote_minrxploss; 00277 /*! Average number of packets lost on remote side */ 00278 double remote_normdevrxploss; 00279 /*! Standard deviation packets lost on remote side */ 00280 double remote_stdevrxploss; 00281 /*! Maximum number of packets lost on local side */ 00282 double local_maxrxploss; 00283 /*! Minimum number of packets lost on local side */ 00284 double local_minrxploss; 00285 /*! Average number of packets lost on local side */ 00286 double local_normdevrxploss; 00287 /*! Standard deviation packets lost on local side */ 00288 double local_stdevrxploss; 00289 /*! Total round trip time */ 00290 double rtt; 00291 /*! Maximum round trip time */ 00292 double maxrtt; 00293 /*! Minimum round trip time */ 00294 double minrtt; 00295 /*! Average round trip time */ 00296 double normdevrtt; 00297 /*! Standard deviation round trip time */ 00298 double stdevrtt; 00299 /*! Our SSRC */ 00300 unsigned int local_ssrc; 00301 /*! Their SSRC */ 00302 unsigned int remote_ssrc; 00303 }; 00304 00305 #define AST_RTP_STAT_SET(current_stat, combined, placement, value) \ 00306 if (stat == current_stat || stat == AST_RTP_INSTANCE_STAT_ALL || (combined >= 0 && combined == current_stat)) { \ 00307 placement = value; \ 00308 if (stat == current_stat) { \ 00309 return 0; \ 00310 } \ 00311 } 00312 00313 #define AST_RTP_STAT_TERMINATOR(combined) \ 00314 if (stat == combined) { \ 00315 return 0; \ 00316 } 00317 00318 /*! \brief ICE candidate types */ 00319 enum ast_rtp_ice_candidate_type { 00320 AST_RTP_ICE_CANDIDATE_TYPE_HOST, /*!< ICE host candidate. A host candidate represents the actual local transport address in the host. */ 00321 AST_RTP_ICE_CANDIDATE_TYPE_SRFLX, /*!< ICE server reflexive candidate, which represents the public mapped address of the local address. */ 00322 AST_RTP_ICE_CANDIDATE_TYPE_RELAYED, /*!< ICE relayed candidate, which represents the address allocated in TURN server. */ 00323 }; 00324 00325 /*! \brief ICE component types */ 00326 enum ast_rtp_ice_component_type { 00327 AST_RTP_ICE_COMPONENT_RTP = 1, 00328 AST_RTP_ICE_COMPONENT_RTCP = 2, 00329 }; 00330 00331 /*! \brief Structure for an ICE candidate */ 00332 struct ast_rtp_engine_ice_candidate { 00333 char *foundation; /*!< Foundation identifier */ 00334 enum ast_rtp_ice_component_type id; /*!< Component identifier */ 00335 char *transport; /*!< Transport for the media */ 00336 int priority; /*!< Priority which is used if multiple candidates can be used */ 00337 struct ast_sockaddr address; /*!< Address of the candidate */ 00338 struct ast_sockaddr relay_address; /*!< Relay address for the candidate */ 00339 enum ast_rtp_ice_candidate_type type; /*!< Type of candidate */ 00340 }; 00341 00342 /*! \brief Structure that represents the optional ICE support within an RTP engine */ 00343 struct ast_rtp_engine_ice { 00344 /*! Callback for setting received authentication information */ 00345 void (*set_authentication)(struct ast_rtp_instance *instance, const char *ufrag, const char *password); 00346 /*! Callback for adding a remote candidate */ 00347 void (*add_remote_candidate)(struct ast_rtp_instance *instance, const struct ast_rtp_engine_ice_candidate *candidate); 00348 /*! Callback for starting ICE negotiation */ 00349 void (*start)(struct ast_rtp_instance *instance); 00350 /*! Callback for stopping ICE support */ 00351 void (*stop)(struct ast_rtp_instance *instance); 00352 /*! Callback for getting local username */ 00353 const char *(*get_ufrag)(struct ast_rtp_instance *instance); 00354 /*! Callback for getting local password */ 00355 const char *(*get_password)(struct ast_rtp_instance *instance); 00356 /*! Callback for getting local candidates */ 00357 struct ao2_container *(*get_local_candidates)(struct ast_rtp_instance *instance); 00358 /*! Callback for telling the ICE support that it is talking to an ice-lite implementation */ 00359 void (*ice_lite)(struct ast_rtp_instance *instance); 00360 }; 00361 00362 /*! \brief DTLS setup types */ 00363 enum ast_rtp_dtls_setup { 00364 AST_RTP_DTLS_SETUP_ACTIVE, /*!< Endpoint is willing to inititate connections */ 00365 AST_RTP_DTLS_SETUP_PASSIVE, /*!< Endpoint is willing to accept connections */ 00366 AST_RTP_DTLS_SETUP_ACTPASS, /*!< Endpoint is willing to both accept and initiate connections */ 00367 AST_RTP_DTLS_SETUP_HOLDCONN, /*!< Endpoint does not want the connection to be established right now */ 00368 }; 00369 00370 /*! \brief DTLS connection states */ 00371 enum ast_rtp_dtls_connection { 00372 AST_RTP_DTLS_CONNECTION_NEW, /*!< Endpoint wants to use a new connection */ 00373 AST_RTP_DTLS_CONNECTION_EXISTING, /*!< Endpoint wishes to use existing connection */ 00374 }; 00375 00376 /*! \brief DTLS fingerprint hashes */ 00377 enum ast_rtp_dtls_hash { 00378 AST_RTP_DTLS_HASH_SHA1, /*!< SHA-1 fingerprint hash */ 00379 }; 00380 00381 /*! \brief DTLS configuration structure */ 00382 struct ast_rtp_dtls_cfg { 00383 unsigned int enabled:1; /*!< Whether DTLS support is enabled or not */ 00384 unsigned int verify:1; /*!< Whether to request and verify a client certificate when acting as server */ 00385 unsigned int rekey; /*!< Interval at which to renegotiate and rekey - defaults to 0 (off) */ 00386 enum ast_rtp_dtls_setup default_setup; /*!< Default setup type to use for outgoing */ 00387 enum ast_srtp_suite suite; /*!< Crypto suite in use */ 00388 char *certfile; /*!< Certificate file */ 00389 char *pvtfile; /*!< Private key file */ 00390 char *cipher; /*!< Cipher to use */ 00391 char *cafile; /*!< Certificate authority file */ 00392 char *capath; /*!< Path to certificate authority */ 00393 }; 00394 00395 /*! \brief Structure that represents the optional DTLS SRTP support within an RTP engine */ 00396 struct ast_rtp_engine_dtls { 00397 /*! Set the configuration of the DTLS support on the instance */ 00398 int (*set_configuration)(struct ast_rtp_instance *instance, const struct ast_rtp_dtls_cfg *dtls_cfg); 00399 /*! Get if the DTLS SRTP support is active or not */ 00400 int (*active)(struct ast_rtp_instance *instance); 00401 /*! Stop and terminate DTLS SRTP support */ 00402 void (*stop)(struct ast_rtp_instance *instance); 00403 /*! Reset the connection and start fresh */ 00404 void (*reset)(struct ast_rtp_instance *instance); 00405 /*! Get the current connection state */ 00406 enum ast_rtp_dtls_connection (*get_connection)(struct ast_rtp_instance *instance); 00407 /*! Get the current setup state */ 00408 enum ast_rtp_dtls_setup (*get_setup)(struct ast_rtp_instance *instance); 00409 /*! Set the remote setup state */ 00410 void (*set_setup)(struct ast_rtp_instance *instance, enum ast_rtp_dtls_setup setup); 00411 /*! Set the remote fingerprint */ 00412 void (*set_fingerprint)(struct ast_rtp_instance *instance, enum ast_rtp_dtls_hash hash, const char *fingerprint); 00413 /*! Get the local fingerprint */ 00414 const char *(*get_fingerprint)(struct ast_rtp_instance *instance, enum ast_rtp_dtls_hash hash); 00415 }; 00416 00417 /*! Structure that represents an RTP stack (engine) */ 00418 struct ast_rtp_engine { 00419 /*! Name of the RTP engine, used when explicitly requested */ 00420 const char *name; 00421 /*! Module this RTP engine came from, used for reference counting */ 00422 struct ast_module *mod; 00423 /*! Callback for setting up a new RTP instance */ 00424 int (*new)(struct ast_rtp_instance *instance, struct ast_sched_context *sched, struct ast_sockaddr *sa, void *data); 00425 /*! Callback for destroying an RTP instance */ 00426 int (*destroy)(struct ast_rtp_instance *instance); 00427 /*! Callback for writing out a frame */ 00428 int (*write)(struct ast_rtp_instance *instance, struct ast_frame *frame); 00429 /*! Callback for stopping the RTP instance */ 00430 void (*stop)(struct ast_rtp_instance *instance); 00431 /*! Callback for starting RFC2833 DTMF transmission */ 00432 int (*dtmf_begin)(struct ast_rtp_instance *instance, char digit); 00433 /*! Callback for stopping RFC2833 DTMF transmission */ 00434 int (*dtmf_end)(struct ast_rtp_instance *instance, char digit); 00435 int (*dtmf_end_with_duration)(struct ast_rtp_instance *instance, char digit, unsigned int duration); 00436 /*! Callback to indicate that we should update the marker bit */ 00437 void (*update_source)(struct ast_rtp_instance *instance); 00438 /*! Callback to indicate that we should update the marker bit and ssrc */ 00439 void (*change_source)(struct ast_rtp_instance *instance); 00440 /*! Callback for setting an extended RTP property */ 00441 int (*extended_prop_set)(struct ast_rtp_instance *instance, int property, void *value); 00442 /*! Callback for getting an extended RTP property */ 00443 void *(*extended_prop_get)(struct ast_rtp_instance *instance, int property); 00444 /*! Callback for setting an RTP property */ 00445 void (*prop_set)(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value); 00446 /*! Callback for setting a payload. If asterisk is to be used, asterisk_format will be set, otherwise value in code is used. */ 00447 void (*payload_set)(struct ast_rtp_instance *instance, int payload, int asterisk_format, struct ast_format *format, int code); 00448 /*! Callback for setting packetization preferences */ 00449 void (*packetization_set)(struct ast_rtp_instance *instance, struct ast_codec_pref *pref); 00450 /*! Callback for setting the remote address that RTP is to be sent to */ 00451 void (*remote_address_set)(struct ast_rtp_instance *instance, struct ast_sockaddr *sa); 00452 /*! Callback for setting an alternate remote address */ 00453 void (*alt_remote_address_set)(struct ast_rtp_instance *instance, struct ast_sockaddr *sa); 00454 /*! Callback for changing DTMF mode */ 00455 int (*dtmf_mode_set)(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode); 00456 /*! Callback for getting DTMF mode */ 00457 enum ast_rtp_dtmf_mode (*dtmf_mode_get)(struct ast_rtp_instance *instance); 00458 /*! Callback for retrieving statistics */ 00459 int (*get_stat)(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat); 00460 /*! Callback for setting QoS values */ 00461 int (*qos)(struct ast_rtp_instance *instance, int tos, int cos, const char *desc); 00462 /*! Callback for retrieving a file descriptor to poll on, not always required */ 00463 int (*fd)(struct ast_rtp_instance *instance, int rtcp); 00464 /*! Callback for initializing RED support */ 00465 int (*red_init)(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations); 00466 /*! Callback for buffering a frame using RED */ 00467 int (*red_buffer)(struct ast_rtp_instance *instance, struct ast_frame *frame); 00468 /*! Callback for reading a frame from the RTP engine */ 00469 struct ast_frame *(*read)(struct ast_rtp_instance *instance, int rtcp); 00470 /*! Callback to locally bridge two RTP instances */ 00471 int (*local_bridge)(struct ast_rtp_instance *instance0, struct ast_rtp_instance *instance1); 00472 /*! Callback to set the read format */ 00473 int (*set_read_format)(struct ast_rtp_instance *instance, struct ast_format *format); 00474 /*! Callback to set the write format */ 00475 int (*set_write_format)(struct ast_rtp_instance *instance, struct ast_format *format); 00476 /*! Callback to make two instances compatible */ 00477 int (*make_compatible)(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1); 00478 /*! Callback to see if two instances are compatible with DTMF */ 00479 int (*dtmf_compatible)(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1); 00480 /*! Callback to indicate that packets will now flow */ 00481 int (*activate)(struct ast_rtp_instance *instance); 00482 /*! Callback to request that the RTP engine send a STUN BIND request */ 00483 void (*stun_request)(struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username); 00484 /*! Callback to get the transcodeable formats supported. result returned in ast_format_cap *result */ 00485 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); 00486 /*! Callback to send CNG */ 00487 int (*sendcng)(struct ast_rtp_instance *instance, int level); 00488 /*! Callback to pointer for optional ICE support */ 00489 struct ast_rtp_engine_ice *ice; 00490 /*! Callback to pointer for optional DTLS SRTP support */ 00491 struct ast_rtp_engine_dtls *dtls; 00492 /*! Linked list information */ 00493 AST_RWLIST_ENTRY(ast_rtp_engine) entry; 00494 }; 00495 00496 /*! Structure that represents codec and packetization information */ 00497 struct ast_rtp_codecs { 00498 /*! Payloads present */ 00499 struct ao2_container *payloads; 00500 /*! Codec packetization preferences */ 00501 struct ast_codec_pref pref; 00502 }; 00503 00504 /*! Structure that represents the glue that binds an RTP instance to a channel */ 00505 struct ast_rtp_glue { 00506 /*! Name of the channel driver that this glue is responsible for */ 00507 const char *type; 00508 /*! Module that the RTP glue came from */ 00509 struct ast_module *mod; 00510 /*! 00511 * \brief Callback for retrieving the RTP instance carrying audio 00512 * \note This function increases the reference count on the returned RTP instance. 00513 */ 00514 enum ast_rtp_glue_result (*get_rtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance); 00515 /*! 00516 * \brief Used to prevent two channels from remotely bridging audio rtp if the channel tech has a 00517 * reason for prohibiting it based on qualities that need to be compared from both channels. 00518 * \note This function should only be called with two channels of the same technology 00519 * \note This function may be NULL for a given channel driver. This should be accounted for and if that is the case, function this is not used. 00520 */ 00521 int (*allow_rtp_remote)(struct ast_channel *chan1, struct ast_channel *chan2); 00522 /*! 00523 * \brief Callback for retrieving the RTP instance carrying video 00524 * \note This function increases the reference count on the returned RTP instance. 00525 */ 00526 enum ast_rtp_glue_result (*get_vrtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance); 00527 /*! 00528 * \brief Used to prevent two channels from remotely bridging video rtp if the channel tech has a 00529 * reason for prohibiting it based on qualities that need to be compared from both channels. 00530 * \note This function should only be called with two channels of the same technology 00531 * \note This function may be NULL for a given channel driver. This should be accounted for and if that is the case, this function is not used. 00532 */ 00533 int (*allow_vrtp_remote)(struct ast_channel *chan1, struct ast_channel *chan2); 00534 00535 /*! 00536 * \brief Callback for retrieving the RTP instance carrying text 00537 * \note This function increases the reference count on the returned RTP instance. 00538 */ 00539 enum ast_rtp_glue_result (*get_trtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance); 00540 /*! Callback for updating the destination that the remote side should send RTP to */ 00541 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); 00542 /*! Callback for retrieving codecs that the channel can do. Result returned in result_cap. 00543 * \note The channel chan will be locked during this call. 00544 */ 00545 void (*get_codec)(struct ast_channel *chan, struct ast_format_cap *result_cap); 00546 /*! Linked list information */ 00547 AST_RWLIST_ENTRY(ast_rtp_glue) entry; 00548 }; 00549 00550 #define ast_rtp_engine_register(engine) ast_rtp_engine_register2(engine, ast_module_info->self) 00551 00552 /*! 00553 * \brief Register an RTP engine 00554 * 00555 * \param engine Structure of the RTP engine to register 00556 * \param module Module that the RTP engine is part of 00557 * 00558 * \retval 0 success 00559 * \retval -1 failure 00560 * 00561 * Example usage: 00562 * 00563 * \code 00564 * ast_rtp_engine_register2(&example_rtp_engine, NULL); 00565 * \endcode 00566 * 00567 * This registers the RTP engine declared as example_rtp_engine with the RTP engine core, but does not 00568 * associate a module with it. 00569 * 00570 * \note It is recommended that you use the ast_rtp_engine_register macro so that the module is 00571 * associated with the RTP engine and use counting is performed. 00572 * 00573 * \since 1.8 00574 */ 00575 int ast_rtp_engine_register2(struct ast_rtp_engine *engine, struct ast_module *module); 00576 00577 /*! 00578 * \brief Unregister an RTP engine 00579 * 00580 * \param engine Structure of the RTP engine to unregister 00581 * 00582 * \retval 0 success 00583 * \retval -1 failure 00584 * 00585 * Example usage: 00586 * 00587 * \code 00588 * ast_rtp_engine_unregister(&example_rtp_engine); 00589 * \endcode 00590 * 00591 * This unregisters the RTP engine declared as example_rtp_engine from the RTP engine core. If a module 00592 * reference was provided when it was registered then this will only be called once the RTP engine is no longer in use. 00593 * 00594 * \since 1.8 00595 */ 00596 int ast_rtp_engine_unregister(struct ast_rtp_engine *engine); 00597 00598 int ast_rtp_engine_register_srtp(struct ast_srtp_res *srtp_res, struct ast_srtp_policy_res *policy_res); 00599 00600 void ast_rtp_engine_unregister_srtp(void); 00601 int ast_rtp_engine_srtp_is_registered(void); 00602 00603 #define ast_rtp_glue_register(glue) ast_rtp_glue_register2(glue, ast_module_info->self) 00604 00605 /*! 00606 * \brief Register RTP glue 00607 * 00608 * \param glue The glue to register 00609 * \param module Module that the RTP glue is part of 00610 * 00611 * \retval 0 success 00612 * \retval -1 failure 00613 * 00614 * Example usage: 00615 * 00616 * \code 00617 * ast_rtp_glue_register2(&example_rtp_glue, NULL); 00618 * \endcode 00619 * 00620 * This registers the RTP glue declared as example_rtp_glue with the RTP engine core, but does not 00621 * associate a module with it. 00622 * 00623 * \note It is recommended that you use the ast_rtp_glue_register macro so that the module is 00624 * associated with the RTP glue and use counting is performed. 00625 * 00626 * \since 1.8 00627 */ 00628 int ast_rtp_glue_register2(struct ast_rtp_glue *glue, struct ast_module *module); 00629 00630 /*! 00631 * \brief Unregister RTP glue 00632 * 00633 * \param glue The glue to unregister 00634 * 00635 * \retval 0 success 00636 * \retval -1 failure 00637 * 00638 * Example usage: 00639 * 00640 * \code 00641 * ast_rtp_glue_unregister(&example_rtp_glue); 00642 * \endcode 00643 * 00644 * This unregisters the RTP glue declared as example_rtp_gkue from the RTP engine core. If a module 00645 * reference was provided when it was registered then this will only be called once the RTP engine is no longer in use. 00646 * 00647 * \since 1.8 00648 */ 00649 int ast_rtp_glue_unregister(struct ast_rtp_glue *glue); 00650 00651 /*! 00652 * \brief Create a new RTP instance 00653 * 00654 * \param engine_name Name of the engine to use for the RTP instance 00655 * \param sched Scheduler context that the RTP engine may want to use 00656 * \param sa Address we want to bind to 00657 * \param data Unique data for the engine 00658 * 00659 * \retval non-NULL success 00660 * \retval NULL failure 00661 * 00662 * Example usage: 00663 * 00664 * \code 00665 * struct ast_rtp_instance *instance = NULL; 00666 * instance = ast_rtp_instance_new(NULL, sched, &sin, NULL); 00667 * \endcode 00668 * 00669 * This creates a new RTP instance using the default engine and asks the RTP engine to bind to the address given 00670 * in the address structure. 00671 * 00672 * \note The RTP engine does not have to use the address provided when creating an RTP instance. It may choose to use 00673 * another depending on it's own configuration. 00674 * 00675 * \since 1.8 00676 */ 00677 struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name, 00678 struct ast_sched_context *sched, const struct ast_sockaddr *sa, 00679 void *data); 00680 00681 /*! 00682 * \brief Destroy an RTP instance 00683 * 00684 * \param instance The RTP instance to destroy 00685 * 00686 * \retval 0 success 00687 * \retval -1 failure 00688 * 00689 * Example usage: 00690 * 00691 * \code 00692 * ast_rtp_instance_destroy(instance); 00693 * \endcode 00694 * 00695 * This destroys the RTP instance pointed to by instance. Once this function returns instance no longer points to valid 00696 * memory and may not be used again. 00697 * 00698 * \since 1.8 00699 */ 00700 int ast_rtp_instance_destroy(struct ast_rtp_instance *instance); 00701 00702 /*! 00703 * \brief Set the data portion of an RTP instance 00704 * 00705 * \param instance The RTP instance to manipulate 00706 * \param data Pointer to data 00707 * 00708 * Example usage: 00709 * 00710 * \code 00711 * ast_rtp_instance_set_data(instance, blob); 00712 * \endcode 00713 * 00714 * This sets the data pointer on the RTP instance pointed to by 'instance' to 00715 * blob. 00716 * 00717 * \since 1.8 00718 */ 00719 void ast_rtp_instance_set_data(struct ast_rtp_instance *instance, void *data); 00720 00721 /*! 00722 * \brief Get the data portion of an RTP instance 00723 * 00724 * \param instance The RTP instance we want the data portion from 00725 * 00726 * Example usage: 00727 * 00728 * \code 00729 * struct *blob = ast_rtp_instance_get_data(instance); 00730 ( \endcode 00731 * 00732 * This gets the data pointer on the RTP instance pointed to by 'instance'. 00733 * 00734 * \since 1.8 00735 */ 00736 void *ast_rtp_instance_get_data(struct ast_rtp_instance *instance); 00737 00738 /*! 00739 * \brief Send a frame out over RTP 00740 * 00741 * \param instance The RTP instance to send frame out on 00742 * \param frame the frame to send out 00743 * 00744 * \retval 0 success 00745 * \retval -1 failure 00746 * 00747 * Example usage: 00748 * 00749 * \code 00750 * ast_rtp_instance_write(instance, frame); 00751 * \endcode 00752 * 00753 * This gives the frame pointed to by frame to the RTP engine being used for the instance 00754 * and asks that it be transmitted to the current remote address set on the RTP instance. 00755 * 00756 * \since 1.8 00757 */ 00758 int ast_rtp_instance_write(struct ast_rtp_instance *instance, struct ast_frame *frame); 00759 00760 /*! 00761 * \brief Receive a frame over RTP 00762 * 00763 * \param instance The RTP instance to receive frame on 00764 * \param rtcp Whether to read in RTCP or not 00765 * 00766 * \retval non-NULL success 00767 * \retval NULL failure 00768 * 00769 * Example usage: 00770 * 00771 * \code 00772 * struct ast_frame *frame; 00773 * frame = ast_rtp_instance_read(instance, 0); 00774 * \endcode 00775 * 00776 * This asks the RTP engine to read in RTP from the instance and return it as an Asterisk frame. 00777 * 00778 * \since 1.8 00779 */ 00780 struct ast_frame *ast_rtp_instance_read(struct ast_rtp_instance *instance, int rtcp); 00781 00782 /*! 00783 * \brief Set the address of the remote endpoint that we are sending RTP to 00784 * 00785 * \param instance The RTP instance to change the address on 00786 * \param address Address to set it to 00787 * 00788 * \retval 0 success 00789 * \retval -1 failure 00790 * 00791 * Example usage: 00792 * 00793 * \code 00794 * ast_rtp_instance_set_remote_address(instance, &sin); 00795 * \endcode 00796 * 00797 * This changes the remote address that RTP will be sent to on instance to the address given in the sin 00798 * structure. 00799 * 00800 * \since 1.8 00801 */ 00802 int ast_rtp_instance_set_remote_address(struct ast_rtp_instance *instance, const struct ast_sockaddr *address); 00803 00804 00805 /*! 00806 * \brief Set the address of an an alternate RTP address to receive from 00807 * 00808 * \param instance The RTP instance to change the address on 00809 * \param address Address to set it to 00810 * 00811 * \retval 0 success 00812 * \retval -1 failure 00813 * 00814 * Example usage: 00815 * 00816 * \code 00817 * ast_rtp_instance_set_alt_remote_address(instance, &address); 00818 * \endcode 00819 * 00820 * This changes the alternate remote address that RTP will be sent to on instance to the address given in the sin 00821 * structure. 00822 * 00823 * \since 1.8 00824 */ 00825 int ast_rtp_instance_set_alt_remote_address(struct ast_rtp_instance *instance, const struct ast_sockaddr *address); 00826 00827 /*! 00828 * \brief Set the address that we are expecting to receive RTP on 00829 * 00830 * \param instance The RTP instance to change the address on 00831 * \param address Address to set it to 00832 * 00833 * \retval 0 success 00834 * \retval -1 failure 00835 * 00836 * Example usage: 00837 * 00838 * \code 00839 * ast_rtp_instance_set_local_address(instance, &sin); 00840 * \endcode 00841 * 00842 * This changes the local address that RTP is expected on to the address given in the sin 00843 * structure. 00844 * 00845 * \since 1.8 00846 */ 00847 int ast_rtp_instance_set_local_address(struct ast_rtp_instance *instance, 00848 const struct ast_sockaddr *address); 00849 00850 /*! 00851 * \brief Get the local address that we are expecting RTP on 00852 * 00853 * \param instance The RTP instance to get the address from 00854 * \param address The variable to store the address in 00855 * 00856 * Example usage: 00857 * 00858 * \code 00859 * struct ast_sockaddr address; 00860 * ast_rtp_instance_get_local_address(instance, &address); 00861 * \endcode 00862 * 00863 * This gets the local address that we are expecting RTP on and stores it in the 'address' structure. 00864 * 00865 * \since 1.8 00866 */ 00867 void ast_rtp_instance_get_local_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address); 00868 00869 /*! 00870 * \brief Get the address of the local endpoint that we are sending RTP to, comparing its address to another 00871 * 00872 * \param instance The instance that we want to get the local address for 00873 * \param address An initialized address that may be overwritten if the local address is different 00874 * 00875 * \retval 0 address was not changed 00876 * \retval 1 address was changed 00877 * Example usage: 00878 * 00879 * \code 00880 * struct ast_sockaddr address; 00881 * int ret; 00882 * ret = ast_rtp_instance_get_and_cmp_local_address(instance, &address); 00883 * \endcode 00884 * 00885 * This retrieves the current local address set on the instance pointed to by instance and puts the value 00886 * into the address structure. 00887 * 00888 * \since 1.8 00889 */ 00890 int ast_rtp_instance_get_and_cmp_local_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address); 00891 00892 /*! 00893 * \brief Get the address of the remote endpoint that we are sending RTP to 00894 * 00895 * \param instance The instance that we want to get the remote address for 00896 * \param address A structure to put the address into 00897 * 00898 * Example usage: 00899 * 00900 * \code 00901 * struct ast_sockaddr address; 00902 * ast_rtp_instance_get_remote_address(instance, &address); 00903 * \endcode 00904 * 00905 * This retrieves the current remote address set on the instance pointed to by instance and puts the value 00906 * into the address structure. 00907 * 00908 * \since 1.8 00909 */ 00910 void ast_rtp_instance_get_remote_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address); 00911 00912 /*! 00913 * \brief Get the address of the remote endpoint that we are sending RTP to, comparing its address to another 00914 * 00915 * \param instance The instance that we want to get the remote address for 00916 * \param address An initialized address that may be overwritten if the remote address is different 00917 * 00918 * \retval 0 address was not changed 00919 * \retval 1 address was changed 00920 * Example usage: 00921 * 00922 * \code 00923 * struct ast_sockaddr address; 00924 * int ret; 00925 * ret = ast_rtp_instance_get_and_cmp_remote_address(instance, &address); 00926 * \endcode 00927 * 00928 * This retrieves the current remote address set on the instance pointed to by instance and puts the value 00929 * into the address structure. 00930 * 00931 * \since 1.8 00932 */ 00933 00934 int ast_rtp_instance_get_and_cmp_remote_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address); 00935 00936 /*! 00937 * \brief Set the value of an RTP instance extended property 00938 * 00939 * \param instance The RTP instance to set the extended property on 00940 * \param property The extended property to set 00941 * \param value The value to set the extended property to 00942 * 00943 * \since 1.8 00944 */ 00945 void ast_rtp_instance_set_extended_prop(struct ast_rtp_instance *instance, int property, void *value); 00946 00947 /*! 00948 * \brief Get the value of an RTP instance extended property 00949 * 00950 * \param instance The RTP instance to get the extended property on 00951 * \param property The extended property to get 00952 * 00953 * \since 1.8 00954 */ 00955 void *ast_rtp_instance_get_extended_prop(struct ast_rtp_instance *instance, int property); 00956 00957 /*! 00958 * \brief Set the value of an RTP instance property 00959 * 00960 * \param instance The RTP instance to set the property on 00961 * \param property The property to modify 00962 * \param value The value to set the property to 00963 * 00964 * Example usage: 00965 * 00966 * \code 00967 * ast_rtp_instance_set_prop(instance, AST_RTP_PROPERTY_NAT, 1); 00968 * \endcode 00969 * 00970 * This enables the AST_RTP_PROPERTY_NAT property on the instance pointed to by instance. 00971 * 00972 * \since 1.8 00973 */ 00974 void ast_rtp_instance_set_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value); 00975 00976 /*! 00977 * \brief Get the value of an RTP instance property 00978 * 00979 * \param instance The RTP instance to get the property from 00980 * \param property The property to get 00981 * 00982 * \retval Current value of the property 00983 * 00984 * Example usage: 00985 * 00986 * \code 00987 * ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT); 00988 * \endcode 00989 * 00990 * This returns the current value of the NAT property on the instance pointed to by instance. 00991 * 00992 * \since 1.8 00993 */ 00994 int ast_rtp_instance_get_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property); 00995 00996 /*! 00997 * \brief Get the codecs structure of an RTP instance 00998 * 00999 * \param instance The RTP instance to get the codecs structure from 01000 * 01001 * Example usage: 01002 * 01003 * \code 01004 * struct ast_rtp_codecs *codecs = ast_rtp_instance_get_codecs(instance); 01005 * \endcode 01006 * 01007 * This gets the codecs structure on the RTP instance pointed to by 'instance'. 01008 * 01009 * \since 1.8 01010 */ 01011 struct ast_rtp_codecs *ast_rtp_instance_get_codecs(struct ast_rtp_instance *instance); 01012 01013 /*! 01014 * \brief Initialize an RTP codecs structure 01015 * 01016 * \param codecs The codecs structure to initialize 01017 * 01018 * \retval 0 success 01019 * \retval -1 failure 01020 * 01021 * Example usage: 01022 * 01023 * \code 01024 * struct ast_rtp_codecs codecs; 01025 * ast_rtp_codecs_payloads_initialize(&codecs); 01026 * \endcode 01027 * 01028 * \since 11 01029 */ 01030 int ast_rtp_codecs_payloads_initialize(struct ast_rtp_codecs *codecs); 01031 01032 /*! 01033 * \brief Destroy the contents of an RTP codecs structure (but not the structure itself) 01034 * 01035 * \param codecs The codecs structure to destroy the contents of 01036 * 01037 * Example usage: 01038 * 01039 * \code 01040 * struct ast_rtp_codecs codecs; 01041 * ast_rtp_codecs_payloads_destroy(&codecs); 01042 * \endcode 01043 * 01044 * \since 11 01045 */ 01046 void ast_rtp_codecs_payloads_destroy(struct ast_rtp_codecs *codecs); 01047 01048 /*! 01049 * \brief Clear payload information from an RTP instance 01050 * 01051 * \param codecs The codecs structure that payloads will be cleared from 01052 * \param instance Optionally the instance that the codecs structure belongs to 01053 * 01054 * Example usage: 01055 * 01056 * \code 01057 * struct ast_rtp_codecs codecs; 01058 * ast_rtp_codecs_payloads_clear(&codecs, NULL); 01059 * \endcode 01060 * 01061 * This clears the codecs structure and puts it into a pristine state. 01062 * 01063 * \since 1.8 01064 */ 01065 void ast_rtp_codecs_payloads_clear(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance); 01066 01067 /*! 01068 * \brief Set payload information on an RTP instance to the default 01069 * 01070 * \param codecs The codecs structure to set defaults on 01071 * \param instance Optionally the instance that the codecs structure belongs to 01072 * 01073 * Example usage: 01074 * 01075 * \code 01076 * struct ast_rtp_codecs codecs; 01077 * ast_rtp_codecs_payloads_default(&codecs, NULL); 01078 * \endcode 01079 * 01080 * This sets the default payloads on the codecs structure. 01081 * 01082 * \since 1.8 01083 */ 01084 void ast_rtp_codecs_payloads_default(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance); 01085 01086 /*! 01087 * \brief Copy payload information from one RTP instance to another 01088 * 01089 * \param src The source codecs structure 01090 * \param dest The destination codecs structure that the values from src will be copied to 01091 * \param instance Optionally the instance that the dst codecs structure belongs to 01092 * 01093 * Example usage: 01094 * 01095 * \code 01096 * ast_rtp_codecs_payloads_copy(&codecs0, &codecs1, NULL); 01097 * \endcode 01098 * 01099 * This copies the payloads from the codecs0 structure to the codecs1 structure, overwriting any current values. 01100 * 01101 * \since 1.8 01102 */ 01103 void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance); 01104 01105 /*! 01106 * \brief Record payload information that was seen in an m= SDP line 01107 * 01108 * \param codecs The codecs structure to muck with 01109 * \param instance Optionally the instance that the codecs structure belongs to 01110 * \param payload Numerical payload that was seen in the m= SDP line 01111 * 01112 * Example usage: 01113 * 01114 * \code 01115 * ast_rtp_codecs_payloads_set_m_type(&codecs, NULL, 0); 01116 * \endcode 01117 * 01118 * This records that the numerical payload '0' was seen in the codecs structure. 01119 * 01120 * \since 1.8 01121 */ 01122 void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload); 01123 01124 /*! 01125 * \brief Record payload information that was seen in an a=rtpmap: SDP line 01126 * 01127 * \param codecs The codecs structure to muck with 01128 * \param instance Optionally the instance that the codecs structure belongs to 01129 * \param payload Numerical payload that was seen in the a=rtpmap: SDP line 01130 * \param mimetype The string mime type that was seen 01131 * \param mimesubtype The strin mime sub type that was seen 01132 * \param options Optional options that may change the behavior of this specific payload 01133 * 01134 * \retval 0 success 01135 * \retval -1 failure, invalid payload numbe 01136 * \retval -2 failure, unknown mimetype 01137 * 01138 * Example usage: 01139 * 01140 * \code 01141 * ast_rtp_codecs_payloads_set_rtpmap_type(&codecs, NULL, 0, "audio", "PCMU", 0); 01142 * \endcode 01143 * 01144 * This records that the numerical payload '0' was seen with mime type 'audio' and sub mime type 'PCMU' in the codecs structure. 01145 * 01146 * \since 1.8 01147 */ 01148 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); 01149 01150 /*! 01151 * \brief Set payload type to a known MIME media type for a codec with a specific sample rate 01152 * 01153 * \param codecs RTP structure to modify 01154 * \param instance Optionally the instance that the codecs structure belongs to 01155 * \param pt Payload type entry to modify 01156 * \param mimetype top-level MIME type of media stream (typically "audio", "video", "text", etc.) 01157 * \param mimesubtype MIME subtype of media stream (typically a codec name) 01158 * \param options Zero or more flags from the ast_rtp_options enum 01159 * \param sample_rate The sample rate of the media stream 01160 * 01161 * This function 'fills in' an entry in the list of possible formats for 01162 * a media stream associated with an RTP structure. 01163 * 01164 * \retval 0 on success 01165 * \retval -1 if the payload type is out of range 01166 * \retval -2 if the mimeType/mimeSubtype combination was not found 01167 * 01168 * \since 1.8 01169 */ 01170 int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int pt, 01171 char *mimetype, char *mimesubtype, 01172 enum ast_rtp_options options, 01173 unsigned int sample_rate); 01174 01175 /*! 01176 * \brief Remove payload information 01177 * 01178 * \param codecs The codecs structure to muck with 01179 * \param instance Optionally the instance that the codecs structure belongs to 01180 * \param payload Numerical payload to unset 01181 * 01182 * Example usage: 01183 * 01184 * \code 01185 * ast_rtp_codecs_payloads_unset(&codecs, NULL, 0); 01186 * \endcode 01187 * 01188 * This clears the payload '0' from the codecs structure. It will be as if it was never set. 01189 * 01190 * \since 1.8 01191 */ 01192 void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload); 01193 01194 /*! 01195 * \brief Retrieve payload information by payload 01196 * 01197 * \param codecs Codecs structure to look in 01198 * \param payload Numerical payload to look up 01199 * 01200 * \retval Payload information 01201 * 01202 * Example usage: 01203 * 01204 * \code 01205 * struct ast_rtp_payload_type payload_type; 01206 * payload_type = ast_rtp_codecs_payload_lookup(&codecs, 0); 01207 * \endcode 01208 * 01209 * This looks up the information for payload '0' from the codecs structure. 01210 * 01211 * \since 1.8 01212 */ 01213 struct ast_rtp_payload_type ast_rtp_codecs_payload_lookup(struct ast_rtp_codecs *codecs, int payload); 01214 01215 /*! 01216 * \brief Retrieve the actual ast_format stored on the codecs structure for a specific payload 01217 * 01218 * \param codecs Codecs structure to look in 01219 * \param payload Numerical payload to look up 01220 * 01221 * \retval pointer to format structure on success 01222 * \retval NULL on failure 01223 * 01224 * \since 10.0 01225 */ 01226 struct ast_format *ast_rtp_codecs_get_payload_format(struct ast_rtp_codecs *codecs, int payload); 01227 01228 /*! 01229 * \brief Get the sample rate associated with known RTP payload types 01230 * 01231 * \param asterisk_format True if the value in format is to be used. 01232 * \param An asterisk format 01233 * \param code from AST_RTP list 01234 * 01235 * \return the sample rate if the format was found, zero if it was not found 01236 * 01237 * \since 1.8 01238 */ 01239 unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format, struct ast_format *format, int code); 01240 01241 /*! 01242 * \brief Retrieve all formats that were found 01243 * 01244 * \param codecs Codecs structure to look in 01245 * \param astformats A capabilities structure to put the Asterisk formats in. 01246 * \param nonastformats An integer to put the non-Asterisk formats in 01247 * 01248 * Example usage: 01249 * 01250 * \code 01251 * struct ast_format_cap *astformats = ast_format_cap_alloc_nolock() 01252 * int nonastformats; 01253 * ast_rtp_codecs_payload_formats(&codecs, &astformats, &nonastformats); 01254 * \endcode 01255 * 01256 * This retrieves all the formats known about in the codecs structure and puts the Asterisk ones in the integer 01257 * pointed to by astformats and the non-Asterisk ones in the integer pointed to by nonastformats. 01258 * 01259 * \since 1.8 01260 */ 01261 void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, struct ast_format_cap *astformats, int *nonastformats); 01262 01263 /*! 01264 * \brief Retrieve a payload based on whether it is an Asterisk format and the code 01265 * 01266 * \param codecs Codecs structure to look in 01267 * \param asterisk_format Non-zero if the given Asterisk format is present 01268 * \param format Asterisk format to look for 01269 * \param code The format to look for 01270 * 01271 * \retval Numerical payload 01272 * 01273 * Example usage: 01274 * 01275 * \code 01276 * int payload = ast_rtp_codecs_payload_code(&codecs, 1, ast_format_set(&tmp_fmt, AST_FORMAT_ULAW, 0), 0); 01277 * \endcode 01278 * 01279 * This looks for the numerical payload for ULAW in the codecs structure. 01280 * 01281 * \since 1.8 01282 */ 01283 int ast_rtp_codecs_payload_code(struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code); 01284 /*! 01285 * \brief Search for a payload code in the ast_rtp_codecs structure 01286 * 01287 * \param codecs Codecs structure to look in 01288 * \param code The format to look for 01289 * 01290 * \retval Numerical payload or -1 if unable to find payload in codecs 01291 * 01292 * Example usage: 01293 * 01294 * \code 01295 * int payload = ast_rtp_codecs_payload_code(&codecs, 0); 01296 * \endcode 01297 * 01298 * This looks for the numerical payload for ULAW in the codecs structure. 01299 * 01300 */ 01301 int ast_rtp_codecs_find_payload_code(struct ast_rtp_codecs *codecs, int code); 01302 01303 /*! 01304 * \brief Retrieve mime subtype information on a payload 01305 * 01306 * \param asterisk_format Non-zero to look up using Asterisk format 01307 * \param format Asterisk format to look up 01308 * \param code RTP code to look up 01309 * \param options Additional options that may change the result 01310 * 01311 * \retval Mime subtype success 01312 * \retval NULL failure 01313 * 01314 * Example usage: 01315 * 01316 * \code 01317 * const char *subtype = ast_rtp_lookup_mime_subtype2(1, ast_format_set(&tmp_fmt, AST_FORMAT_ULAW, 0), 0, 0); 01318 * \endcode 01319 * 01320 * This looks up the mime subtype for the ULAW format. 01321 * 01322 * \since 1.8 01323 */ 01324 const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format, struct ast_format *format, int code, enum ast_rtp_options options); 01325 01326 /*! 01327 * \brief Convert formats into a string and put them into a buffer 01328 * 01329 * \param buf Buffer to put the mime output into 01330 * \param ast_format_capability Asterisk Formats we are looking up. 01331 * \param rtp_capability RTP codes that we are looking up 01332 * \param asterisk_format Non-zero if the ast_format_capability structure is to be used, 0 if rtp_capability is to be used 01333 * \param options Additional options that may change the result 01334 * 01335 * \retval non-NULL success 01336 * \retval NULL failure 01337 * 01338 * Example usage: 01339 * 01340 * \code 01341 * char buf[256] = ""; 01342 * struct ast_format tmp_fmt; 01343 * struct ast_format_cap *cap = ast_format_cap_alloc_nolock(); 01344 * ast_format_cap_add(cap, ast_format_set(&tmp_fmt, AST_FORMAT_ULAW, 0)); 01345 * ast_format_cap_add(cap, ast_format_set(&tmp_fmt, AST_FORMAT_GSM, 0)); 01346 * char *mime = ast_rtp_lookup_mime_multiple2(&buf, sizeof(buf), cap, 0, 1, 0); 01347 * ast_format_cap_destroy(cap); 01348 * \endcode 01349 * 01350 * This returns the mime values for ULAW and ALAW in the buffer pointed to by buf. 01351 * 01352 * \since 1.8 01353 */ 01354 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); 01355 01356 /*! 01357 * \brief Set codec packetization preferences 01358 * 01359 * \param codecs Codecs structure to muck with 01360 * \param instance Optionally the instance that the codecs structure belongs to 01361 * \param prefs Codec packetization preferences 01362 * 01363 * Example usage: 01364 * 01365 * \code 01366 * ast_rtp_codecs_packetization_set(&codecs, NULL, &prefs); 01367 * \endcode 01368 * 01369 * This sets the packetization preferences pointed to by prefs on the codecs structure pointed to by codecs. 01370 * 01371 * \since 1.8 01372 */ 01373 void ast_rtp_codecs_packetization_set(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, struct ast_codec_pref *prefs); 01374 01375 /*! 01376 * \brief Begin sending a DTMF digit 01377 * 01378 * \param instance The RTP instance to send the DTMF on 01379 * \param digit What DTMF digit to send 01380 * 01381 * \retval 0 success 01382 * \retval -1 failure 01383 * 01384 * Example usage: 01385 * 01386 * \code 01387 * ast_rtp_instance_dtmf_begin(instance, '1'); 01388 * \endcode 01389 * 01390 * This starts sending the DTMF '1' on the RTP instance pointed to by instance. It will 01391 * continue being sent until it is ended. 01392 * 01393 * \since 1.8 01394 */ 01395 int ast_rtp_instance_dtmf_begin(struct ast_rtp_instance *instance, char digit); 01396 01397 /*! 01398 * \brief Stop sending a DTMF digit 01399 * 01400 * \param instance The RTP instance to stop the DTMF on 01401 * \param digit What DTMF digit to stop 01402 * 01403 * \retval 0 success 01404 * \retval -1 failure 01405 * 01406 * Example usage: 01407 * 01408 * \code 01409 * ast_rtp_instance_dtmf_end(instance, '1'); 01410 * \endcode 01411 * 01412 * This stops sending the DTMF '1' on the RTP instance pointed to by instance. 01413 * 01414 * \since 1.8 01415 */ 01416 int ast_rtp_instance_dtmf_end(struct ast_rtp_instance *instance, char digit); 01417 int ast_rtp_instance_dtmf_end_with_duration(struct ast_rtp_instance *instance, char digit, unsigned int duration); 01418 01419 /*! 01420 * \brief Set the DTMF mode that should be used 01421 * 01422 * \param instance the RTP instance to set DTMF mode on 01423 * \param dtmf_mode The DTMF mode that is in use 01424 * 01425 * \retval 0 success 01426 * \retval -1 failure 01427 * 01428 * Example usage: 01429 * 01430 * \code 01431 * ast_rtp_instance_dtmf_mode_set(instance, AST_RTP_DTMF_MODE_RFC2833); 01432 * \endcode 01433 * 01434 * This sets the RTP instance to use RFC2833 for DTMF transmission and receiving. 01435 * 01436 * \since 1.8 01437 */ 01438 int ast_rtp_instance_dtmf_mode_set(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode); 01439 01440 /*! 01441 * \brief Get the DTMF mode of an RTP instance 01442 * 01443 * \param instance The RTP instance to get the DTMF mode of 01444 * 01445 * \retval DTMF mode 01446 * 01447 * Example usage: 01448 * 01449 * \code 01450 * enum ast_rtp_dtmf_mode dtmf_mode = ast_rtp_instance_dtmf_mode_get(instance); 01451 * \endcode 01452 * 01453 * This gets the DTMF mode set on the RTP instance pointed to by 'instance'. 01454 * 01455 * \since 1.8 01456 */ 01457 enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get(struct ast_rtp_instance *instance); 01458 01459 /*! 01460 * \brief Indicate that the RTP marker bit should be set on an RTP stream 01461 * 01462 * \param instance Instance that the new media source is feeding into 01463 * 01464 * Example usage: 01465 * 01466 * \code 01467 * ast_rtp_instance_update_source(instance); 01468 * \endcode 01469 * 01470 * This indicates that the source of media that is feeding the instance pointed to by 01471 * instance has been updated and that the marker bit should be set. 01472 * 01473 * \since 1.8 01474 */ 01475 void ast_rtp_instance_update_source(struct ast_rtp_instance *instance); 01476 01477 /*! 01478 * \brief Indicate a new source of audio has dropped in and the ssrc should change 01479 * 01480 * \param instance Instance that the new media source is feeding into 01481 * 01482 * Example usage: 01483 * 01484 * \code 01485 * ast_rtp_instance_change_source(instance); 01486 * \endcode 01487 * 01488 * This indicates that the source of media that is feeding the instance pointed to by 01489 * instance has changed and that the marker bit should be set and the SSRC updated. 01490 * 01491 * \since 1.8 01492 */ 01493 void ast_rtp_instance_change_source(struct ast_rtp_instance *instance); 01494 01495 /*! 01496 * \brief Set QoS parameters on an RTP session 01497 * 01498 * \param instance Instance to set the QoS parameters on 01499 * \param tos Terms of service value 01500 * \param cos Class of service value 01501 * \param desc What is setting the QoS values 01502 * 01503 * \retval 0 success 01504 * \retval -1 failure 01505 * 01506 * Example usage: 01507 * 01508 * \code 01509 * ast_rtp_instance_set_qos(instance, 0, 0, "Example"); 01510 * \endcode 01511 * 01512 * This sets the TOS and COS values to 0 on the instance pointed to by instance. 01513 * 01514 * \since 1.8 01515 */ 01516 int ast_rtp_instance_set_qos(struct ast_rtp_instance *instance, int tos, int cos, const char *desc); 01517 01518 /*! 01519 * \brief Stop an RTP instance 01520 * 01521 * \param instance Instance that media is no longer going to at this time 01522 * 01523 * Example usage: 01524 * 01525 * \code 01526 * ast_rtp_instance_stop(instance); 01527 * \endcode 01528 * 01529 * This tells the RTP engine being used for the instance pointed to by instance 01530 * that media is no longer going to it at this time, but may in the future. 01531 * 01532 * \since 1.8 01533 */ 01534 void ast_rtp_instance_stop(struct ast_rtp_instance *instance); 01535 01536 /*! 01537 * \brief Get the file descriptor for an RTP session (or RTCP) 01538 * 01539 * \param instance Instance to get the file descriptor for 01540 * \param rtcp Whether to retrieve the file descriptor for RTCP or not 01541 * 01542 * \retval fd success 01543 * \retval -1 failure 01544 * 01545 * Example usage: 01546 * 01547 * \code 01548 * int rtp_fd = ast_rtp_instance_fd(instance, 0); 01549 * \endcode 01550 * 01551 * This retrieves the file descriptor for the socket carrying media on the instance 01552 * pointed to by instance. 01553 * 01554 * \since 1.8 01555 */ 01556 int ast_rtp_instance_fd(struct ast_rtp_instance *instance, int rtcp); 01557 01558 /*! 01559 * \brief Get the RTP glue that binds a channel to the RTP engine 01560 * 01561 * \param type Name of the glue we want 01562 * 01563 * \retval non-NULL success 01564 * \retval NULL failure 01565 * 01566 * Example usage: 01567 * 01568 * \code 01569 * struct ast_rtp_glue *glue = ast_rtp_instance_get_glue("Example"); 01570 * \endcode 01571 * 01572 * This retrieves the RTP glue that has the name 'Example'. 01573 * 01574 * \since 1.8 01575 */ 01576 struct ast_rtp_glue *ast_rtp_instance_get_glue(const char *type); 01577 01578 /*! 01579 * \brief Bridge two channels that use RTP instances 01580 * 01581 * \param c0 First channel part of the bridge 01582 * \param c1 Second channel part of the bridge 01583 * \param flags Bridging flags 01584 * \param fo If a frame needs to be passed up it is stored here 01585 * \param rc Channel that passed the above frame up 01586 * \param timeoutms How long the channels should be bridged for 01587 * 01588 * \retval Bridge result 01589 * 01590 * \note This should only be used by channel drivers in their technology declaration. 01591 * 01592 * \since 1.8 01593 */ 01594 enum ast_bridge_result ast_rtp_instance_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms); 01595 01596 /*! 01597 * \brief Get the other RTP instance that an instance is bridged to 01598 * 01599 * \param instance The RTP instance that we want 01600 * 01601 * \retval non-NULL success 01602 * \retval NULL failure 01603 * 01604 * Example usage: 01605 * 01606 * \code 01607 * struct ast_rtp_instance *bridged = ast_rtp_instance_get_bridged(instance0); 01608 * \endcode 01609 * 01610 * This gets the RTP instance that instance0 is bridged to. 01611 * 01612 * \since 1.8 01613 */ 01614 struct ast_rtp_instance *ast_rtp_instance_get_bridged(struct ast_rtp_instance *instance); 01615 01616 /*! 01617 * \brief Make two channels compatible for early bridging 01618 * 01619 * \param c_dst Destination channel to copy to 01620 * \param c_src Source channel to copy from 01621 * 01622 * \since 1.8 01623 */ 01624 void ast_rtp_instance_early_bridge_make_compatible(struct ast_channel *c_dst, struct ast_channel *c_src); 01625 01626 /*! 01627 * \brief Early bridge two channels that use RTP instances 01628 * 01629 * \param c0 First channel part of the bridge 01630 * \param c1 Second channel part of the bridge 01631 * 01632 * \retval 0 success 01633 * \retval -1 failure 01634 * 01635 * \note This should only be used by channel drivers in their technology declaration. 01636 * 01637 * \since 1.8 01638 */ 01639 int ast_rtp_instance_early_bridge(struct ast_channel *c0, struct ast_channel *c1); 01640 01641 /*! 01642 * \brief Initialize RED support on an RTP instance 01643 * 01644 * \param instance The instance to initialize RED support on 01645 * \param buffer_time How long to buffer before sending 01646 * \param payloads Payload values 01647 * \param generations Number of generations 01648 * 01649 * \retval 0 success 01650 * \retval -1 failure 01651 * 01652 * \since 1.8 01653 */ 01654 int ast_rtp_red_init(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations); 01655 01656 /*! 01657 * \brief Buffer a frame in an RTP instance for RED 01658 * 01659 * \param instance The instance to buffer the frame on 01660 * \param frame Frame that we want to buffer 01661 * 01662 * \retval 0 success 01663 * \retval -1 failure 01664 * 01665 * \since 1.8 01666 */ 01667 int ast_rtp_red_buffer(struct ast_rtp_instance *instance, struct ast_frame *frame); 01668 01669 /*! 01670 * \brief Retrieve statistics about an RTP instance 01671 * 01672 * \param instance Instance to get statistics on 01673 * \param stats Structure to put results into 01674 * \param stat What statistic(s) to retrieve 01675 * 01676 * \retval 0 success 01677 * \retval -1 failure 01678 * 01679 * Example usage: 01680 * 01681 * \code 01682 * struct ast_rtp_instance_stats stats; 01683 * ast_rtp_instance_get_stats(instance, &stats, AST_RTP_INSTANCE_STAT_ALL); 01684 * \endcode 01685 * 01686 * This retrieves all statistics the underlying RTP engine supports and puts the values into the 01687 * stats structure. 01688 * 01689 * \since 1.8 01690 */ 01691 int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat); 01692 01693 /*! 01694 * \brief Set standard statistics from an RTP instance on a channel 01695 * 01696 * \param chan Channel to set the statistics on 01697 * \param instance The RTP instance that statistics will be retrieved from 01698 * 01699 * Example usage: 01700 * 01701 * \code 01702 * ast_rtp_instance_set_stats_vars(chan, rtp); 01703 * \endcode 01704 * 01705 * This retrieves standard statistics from the RTP instance rtp and sets it on the channel pointed to 01706 * by chan. 01707 * 01708 * \since 1.8 01709 */ 01710 void ast_rtp_instance_set_stats_vars(struct ast_channel *chan, struct ast_rtp_instance *instance); 01711 01712 /*! 01713 * \brief Retrieve quality statistics about an RTP instance 01714 * 01715 * \param instance Instance to get statistics on 01716 * \param field What quality statistic to retrieve 01717 * \param buf What buffer to put the result into 01718 * \param size Size of the above buffer 01719 * 01720 * \retval non-NULL success 01721 * \retval NULL failure 01722 * 01723 * Example usage: 01724 * 01725 * \code 01726 * char quality[AST_MAX_USER_FIELD]; 01727 * ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, &buf, sizeof(buf)); 01728 * \endcode 01729 * 01730 * This retrieves general quality statistics and places a text representation into the buf pointed to by buf. 01731 * 01732 * \since 1.8 01733 */ 01734 char *ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size); 01735 01736 /*! 01737 * \brief Request that the underlying RTP engine provide audio frames in a specific format 01738 * 01739 * \param instance The RTP instance to change read format on 01740 * \param format Format that frames are wanted in 01741 * 01742 * \retval 0 success 01743 * \retval -1 failure 01744 * 01745 * Example usage: 01746 * 01747 * \code 01748 * struct ast_format tmp_fmt; 01749 * ast_rtp_instance_set_read_format(instance, ast_format_set(&tmp_fmt, AST_FORMAT_ULAW, 0)); 01750 * \endcode 01751 * 01752 * This requests that the RTP engine provide audio frames in the ULAW format. 01753 * 01754 * \since 1.8 01755 */ 01756 int ast_rtp_instance_set_read_format(struct ast_rtp_instance *instance, struct ast_format *format); 01757 01758 /*! 01759 * \brief Tell underlying RTP engine that audio frames will be provided in a specific format 01760 * 01761 * \param instance The RTP instance to change write format on 01762 * \param format Format that frames will be provided in 01763 * 01764 * \retval 0 success 01765 * \retval -1 failure 01766 * 01767 * Example usage: 01768 * 01769 * \code 01770 * struct ast_format tmp_fmt; 01771 * ast_rtp_instance_set_write_format(instance, ast_format_set(&tmp_fmt, AST_FORMAT_ULAW, 0)); 01772 * \endcode 01773 * 01774 * This tells the underlying RTP engine that audio frames will be provided to it in ULAW format. 01775 * 01776 * \since 1.8 01777 */ 01778 int ast_rtp_instance_set_write_format(struct ast_rtp_instance *instance, struct ast_format *format); 01779 01780 /*! 01781 * \brief Request that the underlying RTP engine make two RTP instances compatible with eachother 01782 * 01783 * \param chan Our own Asterisk channel 01784 * \param instance The first RTP instance 01785 * \param peer The peer Asterisk channel 01786 * 01787 * \retval 0 success 01788 * \retval -1 failure 01789 * 01790 * Example usage: 01791 * 01792 * \code 01793 * ast_rtp_instance_make_compatible(instance, peer); 01794 * \endcode 01795 * 01796 * This makes the RTP instance for 'peer' compatible with 'instance' and vice versa. 01797 * 01798 * \since 1.8 01799 */ 01800 int ast_rtp_instance_make_compatible(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_channel *peer); 01801 01802 /*! \brief Request the formats that can be transcoded 01803 * 01804 * \param instance The RTP instance 01805 * \param to_endpoint Formats being sent/received towards the endpoint 01806 * \param to_asterisk Formats being sent/received towards Asterisk 01807 * \param result capabilities structure to store and return supported formats in. 01808 * 01809 * Example usage: 01810 * 01811 * \code 01812 * ast_rtp_instance_available_formats(instance, to_capabilities, from_capabilities, result_capabilities); 01813 * \endcode 01814 * 01815 * This sees if it is possible to have ulaw communicated to the endpoint but signed linear received into Asterisk. 01816 * 01817 * \since 1.8 01818 */ 01819 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); 01820 01821 /*! 01822 * \brief Indicate to the RTP engine that packets are now expected to be sent/received on the RTP instance 01823 * 01824 * \param instance The RTP instance 01825 * 01826 * \retval 0 success 01827 * \retval -1 failure 01828 * 01829 * Example usage: 01830 * 01831 * \code 01832 * ast_rtp_instance_activate(instance); 01833 * \endcode 01834 * 01835 * This tells the underlying RTP engine of instance that packets will now flow. 01836 * 01837 * \since 1.8 01838 */ 01839 int ast_rtp_instance_activate(struct ast_rtp_instance *instance); 01840 01841 /*! 01842 * \brief Request that the underlying RTP engine send a STUN BIND request 01843 * 01844 * \param instance The RTP instance 01845 * \param suggestion The suggested destination 01846 * \param username Optionally a username for the request 01847 * 01848 * Example usage: 01849 * 01850 * \code 01851 * ast_rtp_instance_stun_request(instance, NULL, NULL); 01852 * \endcode 01853 * 01854 * This requests that the RTP engine send a STUN BIND request on the session pointed to by 01855 * 'instance'. 01856 * 01857 * \since 1.8 01858 */ 01859 void ast_rtp_instance_stun_request(struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username); 01860 01861 /*! 01862 * \brief Set the RTP timeout value 01863 * 01864 * \param instance The RTP instance 01865 * \param timeout Value to set the timeout to 01866 * 01867 * Example usage: 01868 * 01869 * \code 01870 * ast_rtp_instance_set_timeout(instance, 5000); 01871 * \endcode 01872 * 01873 * This sets the RTP timeout value on 'instance' to be 5000. 01874 * 01875 * \since 1.8 01876 */ 01877 void ast_rtp_instance_set_timeout(struct ast_rtp_instance *instance, int timeout); 01878 01879 /*! 01880 * \brief Set the RTP timeout value for when the instance is on hold 01881 * 01882 * \param instance The RTP instance 01883 * \param timeout Value to set the timeout to 01884 * 01885 * Example usage: 01886 * 01887 * \code 01888 * ast_rtp_instance_set_hold_timeout(instance, 5000); 01889 * \endcode 01890 * 01891 * This sets the RTP hold timeout value on 'instance' to be 5000. 01892 * 01893 * \since 1.8 01894 */ 01895 void ast_rtp_instance_set_hold_timeout(struct ast_rtp_instance *instance, int timeout); 01896 01897 /*! 01898 * \brief Set the RTP keepalive interval 01899 * 01900 * \param instance The RTP instance 01901 * \param period Value to set the keepalive interval to 01902 * 01903 * Example usage: 01904 * 01905 * \code 01906 * ast_rtp_instance_set_keepalive(instance, 5000); 01907 * \endcode 01908 * 01909 * This sets the RTP keepalive interval on 'instance' to be 5000. 01910 * 01911 * \since 1.8 01912 */ 01913 void ast_rtp_instance_set_keepalive(struct ast_rtp_instance *instance, int timeout); 01914 01915 /*! 01916 * \brief Get the RTP timeout value 01917 * 01918 * \param instance The RTP instance 01919 * 01920 * \retval timeout value 01921 * 01922 * Example usage: 01923 * 01924 * \code 01925 * int timeout = ast_rtp_instance_get_timeout(instance); 01926 * \endcode 01927 * 01928 * This gets the RTP timeout value for the RTP instance pointed to by 'instance'. 01929 * 01930 * \since 1.8 01931 */ 01932 int ast_rtp_instance_get_timeout(struct ast_rtp_instance *instance); 01933 01934 /*! 01935 * \brief Get the RTP timeout value for when an RTP instance is on hold 01936 * 01937 * \param instance The RTP instance 01938 * 01939 * \retval timeout value 01940 * 01941 * Example usage: 01942 * 01943 * \code 01944 * int timeout = ast_rtp_instance_get_hold_timeout(instance); 01945 * \endcode 01946 * 01947 * This gets the RTP hold timeout value for the RTP instance pointed to by 'instance'. 01948 * 01949 * \since 1.8 01950 */ 01951 int ast_rtp_instance_get_hold_timeout(struct ast_rtp_instance *instance); 01952 01953 /*! 01954 * \brief Get the RTP keepalive interval 01955 * 01956 * \param instance The RTP instance 01957 * 01958 * \retval period Keepalive interval value 01959 * 01960 * Example usage: 01961 * 01962 * \code 01963 * int interval = ast_rtp_instance_get_keepalive(instance); 01964 * \endcode 01965 * 01966 * This gets the RTP keepalive interval value for the RTP instance pointed to by 'instance'. 01967 * 01968 * \since 1.8 01969 */ 01970 int ast_rtp_instance_get_keepalive(struct ast_rtp_instance *instance); 01971 01972 /*! 01973 * \brief Get the RTP engine in use on an RTP instance 01974 * 01975 * \param instance The RTP instance 01976 * 01977 * \retval pointer to the engine 01978 * 01979 * Example usage: 01980 * 01981 * \code 01982 * struct ast_rtp_engine *engine = ast_rtp_instance_get_engine(instance); 01983 * \endcode 01984 * 01985 * This gets the RTP engine currently in use on the RTP instance pointed to by 'instance'. 01986 * 01987 * \since 1.8 01988 */ 01989 struct ast_rtp_engine *ast_rtp_instance_get_engine(struct ast_rtp_instance *instance); 01990 01991 /*! 01992 * \brief Get the RTP glue in use on an RTP instance 01993 * 01994 * \param instance The RTP instance 01995 * 01996 * \retval pointer to the glue 01997 * 01998 * Example: 01999 * 02000 * \code 02001 * struct ast_rtp_glue *glue = ast_rtp_instance_get_active_glue(instance); 02002 * \endcode 02003 * 02004 * This gets the RTP glue currently in use on the RTP instance pointed to by 'instance'. 02005 * 02006 * \since 1.8 02007 */ 02008 struct ast_rtp_glue *ast_rtp_instance_get_active_glue(struct ast_rtp_instance *instance); 02009 02010 /*! 02011 * \brief Get the channel that is associated with an RTP instance while in a bridge 02012 * 02013 * \param instance The RTP instance 02014 * 02015 * \retval pointer to the channel 02016 * 02017 * Example: 02018 * 02019 * \code 02020 * struct ast_channel *chan = ast_rtp_instance_get_chan(instance); 02021 * \endcode 02022 * 02023 * This gets the channel associated with the RTP instance pointed to by 'instance'. 02024 * 02025 * \note This will only return a channel while in a local or remote bridge. 02026 * 02027 * \since 1.8 02028 */ 02029 struct ast_channel *ast_rtp_instance_get_chan(struct ast_rtp_instance *instance); 02030 02031 /*! 02032 * \brief Send a comfort noise packet to the RTP instance 02033 * 02034 * \param instance The RTP instance 02035 * \param level Magnitude of the noise level 02036 * 02037 * \retval 0 Success 02038 * \retval non-zero Failure 02039 */ 02040 int ast_rtp_instance_sendcng(struct ast_rtp_instance *instance, int level); 02041 02042 /*! 02043 * \brief Add or replace the SRTP policies for the given RTP instance 02044 * 02045 * \param instance the RTP instance 02046 * \param remote_policy the remote endpoint's policy 02047 * \param local_policy our policy for this RTP instance's remote endpoint 02048 * 02049 * \retval 0 Success 02050 * \retval non-zero Failure 02051 */ 02052 int ast_rtp_instance_add_srtp_policy(struct ast_rtp_instance *instance, struct ast_srtp_policy* remote_policy, struct ast_srtp_policy *local_policy); 02053 02054 /*! 02055 * \brief Obtain the SRTP instance associated with an RTP instance 02056 * 02057 * \param instance the RTP instance 02058 * \retval the SRTP instance on success 02059 * \retval NULL if no SRTP instance exists 02060 */ 02061 struct ast_srtp *ast_rtp_instance_get_srtp(struct ast_rtp_instance *instance); 02062 02063 /*! \brief Custom formats declared in codecs.conf at startup must be communicated to the rtp_engine 02064 * so their mime type can payload number can be initialized. */ 02065 int ast_rtp_engine_load_format(const struct ast_format *format); 02066 02067 /*! \brief Formats requiring the use of a format attribute interface must have that 02068 * interface registered in order for the rtp engine to handle it correctly. If an 02069 * attribute interface is unloaded, this function must be called to notify the rtp_engine. */ 02070 int ast_rtp_engine_unload_format(const struct ast_format *format); 02071 02072 /*! 02073 * \brief Obtain a pointer to the ICE support present on an RTP instance 02074 * 02075 * \param instance the RTP instance 02076 * 02077 * \retval ICE support if present 02078 * \retval NULL if no ICE support available 02079 */ 02080 struct ast_rtp_engine_ice *ast_rtp_instance_get_ice(struct ast_rtp_instance *instance); 02081 02082 /*! 02083 * \brief Obtain a pointer to the DTLS support present on an RTP instance 02084 * 02085 * \param instance the RTP instance 02086 * 02087 * \retval DTLS support if present 02088 * \retval NULL if no DTLS support available 02089 */ 02090 struct ast_rtp_engine_dtls *ast_rtp_instance_get_dtls(struct ast_rtp_instance *instance); 02091 02092 /*! 02093 * \brief Parse DTLS related configuration options 02094 * 02095 * \param dtls_cfg a DTLS configuration structure 02096 * \param name name of the configuration option 02097 * \param value value of the configuration option 02098 * 02099 * \retval 0 if handled 02100 * \retval -1 if not handled 02101 */ 02102 int ast_rtp_dtls_cfg_parse(struct ast_rtp_dtls_cfg *dtls_cfg, const char *name, const char *value); 02103 02104 /*! 02105 * \brief Copy contents of a DTLS configuration structure 02106 * 02107 * \param src_cfg source DTLS configuration structure 02108 * \param dst_cfg destination DTLS configuration structure 02109 */ 02110 void ast_rtp_dtls_cfg_copy(const struct ast_rtp_dtls_cfg *src_cfg, struct ast_rtp_dtls_cfg *dst_cfg); 02111 02112 /*! 02113 * \brief Free contents of a DTLS configuration structure 02114 * 02115 * \param dtls_cfg a DTLS configuration structure 02116 */ 02117 void ast_rtp_dtls_cfg_free(struct ast_rtp_dtls_cfg *dtls_cfg); 02118 02119 #if defined(__cplusplus) || defined(c_plusplus) 02120 } 02121 #endif 02122 02123 #endif /* _ASTERISK_RTP_ENGINE_H */