2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2009, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
7 * Joshua Colp <jcolp@digium.com>
9 * See http://www.asterisk.org for more information about
10 * the Asterisk project. Please do not directly contact
11 * any of the maintainers of this project for assistance;
12 * the project provides a web site, mailing lists and IRC
13 * channels for your use.
15 * This program is free software, distributed under the terms of
16 * the GNU General Public License Version 2. See the LICENSE file
17 * at the top of the source tree.
21 * \brief Pluggable RTP Architecture
22 * \author Joshua Colp <jcolp@digium.com>
27 * \page AstRTPEngine Asterisk RTP Engine API
29 * The purpose of this API is to provide a way for multiple RTP stacks to be
30 * used inside of Asterisk without any module that uses RTP knowing any
31 * different. To the module each RTP stack behaves the same.
33 * An RTP session is called an instance and is made up of a combination of codec
34 * information, RTP engine, RTP properties, and address information. An engine
35 * name may be passed in to explicitly choose an RTP stack to be used but a
36 * default one will be used if none is provided. An address to use for RTP may
37 * also be provided but the underlying RTP engine may choose a different address
38 * depending on it's configuration.
40 * An RTP engine is the layer between the RTP engine core and the RTP stack
41 * itself. The RTP engine core provides a set of callbacks to do various things
42 * (such as write audio out) that the RTP engine has to have implemented.
44 * Glue is what binds an RTP instance to a channel. It is used to retrieve RTP
45 * instance information when performing remote or local bridging and is used to
46 * have the channel driver tell the remote side to change destination of the RTP
49 * Statistics from an RTP instance can be retrieved using the
50 * ast_rtp_instance_get_stats API call. This essentially asks the RTP engine in
51 * use to fill in a structure with the requested values. It is not required for
52 * an RTP engine to support all statistic values.
54 * Properties allow behavior of the RTP engine and RTP engine core to be
55 * changed. For example, there is a property named AST_RTP_PROPERTY_NAT which is
56 * used to tell the RTP engine to enable symmetric RTP if it supports it. It is
57 * not required for an RTP engine to support all properties.
59 * Codec information is stored using a separate data structure which has it's
60 * own set of API calls to add/remove/retrieve information. They are used by the
61 * module after an RTP instance is created so that payload information is
62 * available for the RTP engine.
65 #ifndef _ASTERISK_RTP_ENGINE_H
66 #define _ASTERISK_RTP_ENGINE_H
68 #if defined(__cplusplus) || defined(c_plusplus)
72 #include "asterisk/astobj2.h"
74 /* Maximum number of payloads supported */
75 #define AST_RTP_MAX_PT 256
77 /* Maximum number of generations */
78 #define AST_RED_MAX_GENERATION 5
80 struct ast_rtp_instance;
83 /*! RTP Properties that can be set on an RTP instance */
84 enum ast_rtp_property {
85 /*! Enable symmetric RTP support */
86 AST_RTP_PROPERTY_NAT = 0,
87 /*! RTP instance will be carrying DTMF (using RFC2833) */
88 AST_RTP_PROPERTY_DTMF,
89 /*! Expect unreliable DTMF from remote party */
90 AST_RTP_PROPERTY_DTMF_COMPENSATE,
91 /*! Enable STUN support */
92 AST_RTP_PROPERTY_STUN,
93 /*! Enable RTCP support */
94 AST_RTP_PROPERTY_RTCP,
95 /*! Maximum number of RTP properties supported */
99 /*! Additional RTP options */
100 enum ast_rtp_options {
101 /*! Remote side is using non-standard G.726 */
102 AST_RTP_OPT_G726_NONSTANDARD = (1 << 0),
105 /*! RTP DTMF Modes */
106 enum ast_rtp_dtmf_mode {
107 /*! No DTMF is being carried over the RTP stream */
108 AST_RTP_DTMF_MODE_NONE = 0,
109 /*! DTMF is being carried out of band using RFC2833 */
110 AST_RTP_DTMF_MODE_RFC2833,
111 /*! DTMF is being carried inband over the RTP stream */
112 AST_RTP_DTMF_MODE_INBAND,
115 /*! Result codes when RTP glue is queried for information */
116 enum ast_rtp_glue_result {
117 /*! No remote or local bridging is permitted */
118 AST_RTP_GLUE_RESULT_FORBID = 0,
119 /*! Move RTP stream to be remote between devices directly */
120 AST_RTP_GLUE_RESULT_REMOTE,
121 /*! Perform RTP engine level bridging if possible */
122 AST_RTP_GLUE_RESULT_LOCAL,
125 /*! Field statistics that can be retrieved from an RTP instance */
126 enum ast_rtp_instance_stat_field {
127 /*! Retrieve quality information */
128 AST_RTP_INSTANCE_STAT_FIELD_QUALITY = 0,
129 /*! Retrieve quality information about jitter */
130 AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER,
131 /*! Retrieve quality information about packet loss */
132 AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS,
133 /*! Retrieve quality information about round trip time */
134 AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT,
137 /*! Statistics that can be retrieved from an RTP instance */
138 enum ast_rtp_instance_stat {
139 /*! Retrieve all statistics */
140 AST_RTP_INSTANCE_STAT_ALL = 0,
141 /*! Retrieve number of packets transmitted */
142 AST_RTP_INSTANCE_STAT_TXCOUNT,
143 /*! Retrieve number of packets received */
144 AST_RTP_INSTANCE_STAT_RXCOUNT,
145 /*! Retrieve ALL statistics relating to packet loss */
146 AST_RTP_INSTANCE_STAT_COMBINED_LOSS,
147 /*! Retrieve number of packets lost for transmitting */
148 AST_RTP_INSTANCE_STAT_TXPLOSS,
149 /*! Retrieve number of packets lost for receiving */
150 AST_RTP_INSTANCE_STAT_RXPLOSS,
151 /*! Retrieve maximum number of packets lost on remote side */
152 AST_RTP_INSTANCE_STAT_REMOTE_MAXRXPLOSS,
153 /*! Retrieve minimum number of packets lost on remote side */
154 AST_RTP_INSTANCE_STAT_REMOTE_MINRXPLOSS,
155 /*! Retrieve average number of packets lost on remote side */
156 AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVRXPLOSS,
157 /*! Retrieve standard deviation of packets lost on remote side */
158 AST_RTP_INSTANCE_STAT_REMOTE_STDEVRXPLOSS,
159 /*! Retrieve maximum number of packets lost on local side */
160 AST_RTP_INSTANCE_STAT_LOCAL_MAXRXPLOSS,
161 /*! Retrieve minimum number of packets lost on local side */
162 AST_RTP_INSTANCE_STAT_LOCAL_MINRXPLOSS,
163 /*! Retrieve average number of packets lost on local side */
164 AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVRXPLOSS,
165 /*! Retrieve standard deviation of packets lost on local side */
166 AST_RTP_INSTANCE_STAT_LOCAL_STDEVRXPLOSS,
167 /*! Retrieve ALL statistics relating to jitter */
168 AST_RTP_INSTANCE_STAT_COMBINED_JITTER,
169 /*! Retrieve jitter on transmitted packets */
170 AST_RTP_INSTANCE_STAT_TXJITTER,
171 /*! Retrieve jitter on received packets */
172 AST_RTP_INSTANCE_STAT_RXJITTER,
173 /*! Retrieve maximum jitter on remote side */
174 AST_RTP_INSTANCE_STAT_REMOTE_MAXJITTER,
175 /*! Retrieve minimum jitter on remote side */
176 AST_RTP_INSTANCE_STAT_REMOTE_MINJITTER,
177 /*! Retrieve average jitter on remote side */
178 AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVJITTER,
179 /*! Retrieve standard deviation jitter on remote side */
180 AST_RTP_INSTANCE_STAT_REMOTE_STDEVJITTER,
181 /*! Retrieve maximum jitter on local side */
182 AST_RTP_INSTANCE_STAT_LOCAL_MAXJITTER,
183 /*! Retrieve minimum jitter on local side */
184 AST_RTP_INSTANCE_STAT_LOCAL_MINJITTER,
185 /*! Retrieve average jitter on local side */
186 AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVJITTER,
187 /*! Retrieve standard deviation jitter on local side */
188 AST_RTP_INSTANCE_STAT_LOCAL_STDEVJITTER,
189 /*! Retrieve ALL statistics relating to round trip time */
190 AST_RTP_INSTANCE_STAT_COMBINED_RTT,
191 /*! Retrieve round trip time */
192 AST_RTP_INSTANCE_STAT_RTT,
193 /*! Retrieve maximum round trip time */
194 AST_RTP_INSTANCE_STAT_MAX_RTT,
195 /*! Retrieve minimum round trip time */
196 AST_RTP_INSTANCE_STAT_MIN_RTT,
197 /*! Retrieve average round trip time */
198 AST_RTP_INSTANCE_STAT_NORMDEVRTT,
199 /*! Retrieve standard deviation round trip time */
200 AST_RTP_INSTANCE_STAT_STDEVRTT,
201 /*! Retrieve local SSRC */
202 AST_RTP_INSTANCE_STAT_LOCAL_SSRC,
203 /*! Retrieve remote SSRC */
204 AST_RTP_INSTANCE_STAT_REMOTE_SSRC,
207 /* Codes for RTP-specific data - not defined by our AST_FORMAT codes */
208 /*! DTMF (RFC2833) */
209 #define AST_RTP_DTMF (1 << 0)
210 /*! 'Comfort Noise' (RFC3389) */
211 #define AST_RTP_CN (1 << 1)
212 /*! DTMF (Cisco Proprietary) */
213 #define AST_RTP_CISCO_DTMF (1 << 2)
214 /*! Maximum RTP-specific code */
215 #define AST_RTP_MAX AST_RTP_CISCO_DTMF
217 /*! Structure that represents a payload */
218 struct ast_rtp_payload_type {
219 /*! Is this an Asterisk value */
221 /*! Actual internal value of the payload */
225 /*! Structure that represents statistics from an RTP instance */
226 struct ast_rtp_instance_stats {
227 /*! Number of packets transmitted */
228 unsigned int txcount;
229 /*! Number of packets received */
230 unsigned int rxcount;
231 /*! Jitter on transmitted packets */
232 unsigned int txjitter;
233 /*! Jitter on received packets */
234 unsigned int rxjitter;
235 /*! Maximum jitter on remote side */
236 double remote_maxjitter;
237 /*! Minimum jitter on remote side */
238 double remote_minjitter;
239 /*! Average jitter on remote side */
240 double remote_normdevjitter;
241 /*! Standard deviation jitter on remote side */
242 double remote_stdevjitter;
243 /*! Maximum jitter on local side */
244 double local_maxjitter;
245 /*! Minimum jitter on local side */
246 double local_minjitter;
247 /*! Average jitter on local side */
248 double local_normdevjitter;
249 /*! Standard deviation jitter on local side */
250 double local_stdevjitter;
251 /*! Number of transmitted packets lost */
252 unsigned int txploss;
253 /*! Number of received packets lost */
254 unsigned int rxploss;
255 /*! Maximum number of packets lost on remote side */
256 double remote_maxrxploss;
257 /*! Minimum number of packets lost on remote side */
258 double remote_minrxploss;
259 /*! Average number of packets lost on remote side */
260 double remote_normdevrxploss;
261 /*! Standard deviation packets lost on remote side */
262 double remote_stdevrxploss;
263 /*! Maximum number of packets lost on local side */
264 double local_maxrxploss;
265 /*! Minimum number of packets lost on local side */
266 double local_minrxploss;
267 /*! Average number of packets lost on local side */
268 double local_normdevrxploss;
269 /*! Standard deviation packets lost on local side */
270 double local_stdevrxploss;
271 /*! Total round trip time */
273 /*! Maximum round trip time */
275 /*! Minimum round trip time */
277 /*! Average round trip time */
279 /*! Standard deviation round trip time */
282 unsigned int local_ssrc;
284 unsigned int remote_ssrc;
287 #define AST_RTP_STAT_SET(current_stat, combined, placement, value) \
288 if (stat == current_stat || stat == AST_RTP_INSTANCE_STAT_ALL || (combined >= 0 && combined == current_stat)) { \
290 if (stat == current_stat) { \
295 #define AST_RTP_STAT_TERMINATOR(combined) \
296 if (stat == combined) { \
300 /*! Structure that represents an RTP stack (engine) */
301 struct ast_rtp_engine {
302 /*! Name of the RTP engine, used when explicitly requested */
304 /*! Module this RTP engine came from, used for reference counting */
305 struct ast_module *mod;
306 /*! Callback for setting up a new RTP instance */
307 int (*new)(struct ast_rtp_instance *instance, struct sched_context *sched, struct sockaddr_in *sin, void *data);
308 /*! Callback for destroying an RTP instance */
309 int (*destroy)(struct ast_rtp_instance *instance);
310 /*! Callback for writing out a frame */
311 int (*write)(struct ast_rtp_instance *instance, struct ast_frame *frame);
312 /*! Callback for stopping the RTP instance */
313 void (*stop)(struct ast_rtp_instance *instance);
314 /*! Callback for starting RFC2833 DTMF transmission */
315 int (*dtmf_begin)(struct ast_rtp_instance *instance, char digit);
316 /*! Callback for stopping RFC2833 DTMF transmission */
317 int (*dtmf_end)(struct ast_rtp_instance *instance, char digit);
318 /*! Callback to indicate that a new source of media has come in */
319 void (*new_source)(struct ast_rtp_instance *instance);
320 /*! Callback for setting an extended RTP property */
321 int (*extended_prop_set)(struct ast_rtp_instance *instance, int property, void *value);
322 /*! Callback for getting an extended RTP property */
323 void *(*extended_prop_get)(struct ast_rtp_instance *instance, int property);
324 /*! Callback for setting an RTP property */
325 void (*prop_set)(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value);
326 /*! Callback for setting a payload */
327 void (*payload_set)(struct ast_rtp_instance *instance, int payload, int astformat, int format);
328 /*! Callback for setting packetization preferences */
329 void (*packetization_set)(struct ast_rtp_instance *instance, struct ast_codec_pref *pref);
330 /*! Callback for setting the remote address that RTP is to be sent to */
331 void (*remote_address_set)(struct ast_rtp_instance *instance, struct sockaddr_in *sin);
332 /*! Callback for setting an alternate remote address */
333 void (*alt_remote_address_set)(struct ast_rtp_instance *instance, struct sockaddr_in *sin);
334 /*! Callback for changing DTMF mode */
335 int (*dtmf_mode_set)(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode);
336 /*! Callback for retrieving statistics */
337 int (*get_stat)(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat);
338 /*! Callback for setting QoS values */
339 int (*qos)(struct ast_rtp_instance *instance, int tos, int cos, const char *desc);
340 /*! Callback for retrieving a file descriptor to poll on, not always required */
341 int (*fd)(struct ast_rtp_instance *instance, int rtcp);
342 /*! Callback for initializing RED support */
343 int (*red_init)(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations);
344 /*! Callback for buffering a frame using RED */
345 int (*red_buffer)(struct ast_rtp_instance *instance, struct ast_frame *frame);
346 /*! Callback for reading a frame from the RTP engine */
347 struct ast_frame *(*read)(struct ast_rtp_instance *instance, int rtcp);
348 /*! Callback to locally bridge two RTP instances */
349 int (*local_bridge)(struct ast_rtp_instance *instance0, struct ast_rtp_instance *instance1);
350 /*! Callback to set the read format */
351 int (*set_read_format)(struct ast_rtp_instance *instance, int format);
352 /*! Callback to set the write format */
353 int (*set_write_format)(struct ast_rtp_instance *instance, int format);
354 /*! Callback to make two instances compatible */
355 int (*make_compatible)(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1);
356 /*! Callback to see if two instances are compatible with DTMF */
357 int (*dtmf_compatible)(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1);
358 /*! Callback to indicate that packets will now flow */
359 int (*activate)(struct ast_rtp_instance *instance);
360 /*! Callback to request that the RTP engine send a STUN BIND request */
361 void (*stun_request)(struct ast_rtp_instance *instance, struct sockaddr_in *suggestion, const char *username);
362 /*! Callback to get the transcodeable formats supported */
363 int (*available_formats)(struct ast_rtp_instance *instance, int to_endpoint, int to_asterisk);
364 /*! Linked list information */
365 AST_RWLIST_ENTRY(ast_rtp_engine) entry;
368 /*! Structure that represents codec and packetization information */
369 struct ast_rtp_codecs {
370 /*! Codec packetization preferences */
371 struct ast_codec_pref pref;
372 /*! Payloads present */
373 struct ast_rtp_payload_type payloads[AST_RTP_MAX_PT];
376 /*! Structure that represents the glue that binds an RTP instance to a channel */
377 struct ast_rtp_glue {
378 /*! Name of the channel driver that this glue is responsible for */
380 /*! Module that the RTP glue came from */
381 struct ast_module *mod;
383 * \brief Callback for retrieving the RTP instance carrying audio
384 * \note This function increases the reference count on the returned RTP instance.
386 enum ast_rtp_glue_result (*get_rtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance);
388 * \brief Callback for retrieving the RTP instance carrying video
389 * \note This function increases the reference count on the returned RTP instance.
391 enum ast_rtp_glue_result (*get_vrtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance);
393 * \brief Callback for retrieving the RTP instance carrying text
394 * \note This function increases the reference count on the returned RTP instance.
396 enum ast_rtp_glue_result (*get_trtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance);
397 /*! Callback for updating the destination that the remote side should send RTP to */
398 int (*update_peer)(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, int codecs, int nat_active);
399 /*! Callback for retrieving codecs that the channel can do */
400 int (*get_codec)(struct ast_channel *chan);
401 /*! Linked list information */
402 AST_RWLIST_ENTRY(ast_rtp_glue) entry;
405 #define ast_rtp_engine_register(engine) ast_rtp_engine_register2(engine, ast_module_info->self)
408 * \brief Register an RTP engine
410 * \param engine Structure of the RTP engine to register
411 * \param module Module that the RTP engine is part of
419 * ast_rtp_engine_register2(&example_rtp_engine, NULL);
422 * This registers the RTP engine declared as example_rtp_engine with the RTP engine core, but does not
423 * associate a module with it.
425 * \note It is recommended that you use the ast_rtp_engine_register macro so that the module is
426 * associated with the RTP engine and use counting is performed.
430 int ast_rtp_engine_register2(struct ast_rtp_engine *engine, struct ast_module *module);
433 * \brief Unregister an RTP engine
435 * \param engine Structure of the RTP engine to unregister
443 * ast_rtp_engine_unregister(&example_rtp_engine);
446 * This unregisters the RTP engine declared as example_rtp_engine from the RTP engine core. If a module
447 * reference was provided when it was registered then this will only be called once the RTP engine is no longer in use.
451 int ast_rtp_engine_unregister(struct ast_rtp_engine *engine);
453 #define ast_rtp_glue_register(glue) ast_rtp_glue_register2(glue, ast_module_info->self)
456 * \brief Register RTP glue
458 * \param glue The glue to register
459 * \param module Module that the RTP glue is part of
467 * ast_rtp_glue_register2(&example_rtp_glue, NULL);
470 * This registers the RTP glue declared as example_rtp_glue with the RTP engine core, but does not
471 * associate a module with it.
473 * \note It is recommended that you use the ast_rtp_glue_register macro so that the module is
474 * associated with the RTP glue and use counting is performed.
478 int ast_rtp_glue_register2(struct ast_rtp_glue *glue, struct ast_module *module);
481 * \brief Unregister RTP glue
483 * \param glue The glue to unregister
491 * ast_rtp_glue_unregister(&example_rtp_glue);
494 * This unregisters the RTP glue declared as example_rtp_gkue from the RTP engine core. If a module
495 * reference was provided when it was registered then this will only be called once the RTP engine is no longer in use.
499 int ast_rtp_glue_unregister(struct ast_rtp_glue *glue);
502 * \brief Create a new RTP instance
504 * \param engine_name Name of the engine to use for the RTP instance
505 * \param sched Scheduler context that the RTP engine may want to use
506 * \param sin Address we want to bind to
507 * \param data Unique data for the engine
509 * \retval non-NULL success
510 * \retval NULL failure
515 * struct ast_rtp_instance *instance = NULL;
516 * instance = ast_rtp_instance_new(NULL, sched, &sin, NULL);
519 * This creates a new RTP instance using the default engine and asks the RTP engine to bind to the address given
520 * in the sin structure.
522 * \note The RTP engine does not have to use the address provided when creating an RTP instance. It may choose to use
523 * another depending on it's own configuration.
527 struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name, struct sched_context *sched, struct sockaddr_in *sin, void *data);
530 * \brief Destroy an RTP instance
532 * \param instance The RTP instance to destroy
540 * ast_rtp_instance_destroy(instance);
543 * This destroys the RTP instance pointed to by instance. Once this function returns instance no longer points to valid
544 * memory and may not be used again.
548 int ast_rtp_instance_destroy(struct ast_rtp_instance *instance);
551 * \brief Set the data portion of an RTP instance
553 * \param instance The RTP instance to manipulate
554 * \param data Pointer to data
559 * ast_rtp_instance_set_data(instance, blob);
562 * This sets the data pointer on the RTP instance pointed to by 'instance' to
567 void ast_rtp_instance_set_data(struct ast_rtp_instance *instance, void *data);
570 * \brief Get the data portion of an RTP instance
572 * \param instance The RTP instance we want the data portion from
577 * struct *blob = ast_rtp_instance_get_data(instance);
580 * This gets the data pointer on the RTP instance pointed to by 'instance'.
584 void *ast_rtp_instance_get_data(struct ast_rtp_instance *instance);
587 * \brief Send a frame out over RTP
589 * \param instance The RTP instance to send frame out on
597 * ast_rtp_instance_write(instance, frame);
600 * This gives the frame pointed to by frame to the RTP engine being used for the instance
601 * and asks that it be transmitted to the current remote address set on the RTP instance.
605 int ast_rtp_instance_write(struct ast_rtp_instance *instance, struct ast_frame *frame);
608 * \brief Receive a frame over RTP
610 * \param instance The RTP instance to receive frame on
611 * \param rtcp Whether to read in RTCP or not
613 * \retval non-NULL success
614 * \retval NULL failure
619 * struct ast_frame *frame;
620 * frame = ast_rtp_instance_read(instance, 0);
623 * This asks the RTP engine to read in RTP from the instance and return it as an Asterisk frame.
627 struct ast_frame *ast_rtp_instance_read(struct ast_rtp_instance *instance, int rtcp);
630 * \brief Set the address of the remote endpoint that we are sending RTP to
632 * \param instance The RTP instance to change the address on
633 * \param address Address to set it to
641 * ast_rtp_instance_set_remote_address(instance, &sin);
644 * This changes the remote address that RTP will be sent to on instance to the address given in the sin
649 int ast_rtp_instance_set_remote_address(struct ast_rtp_instance *instance, struct sockaddr_in *address);
652 * \brief Set the address of an an alternate RTP address to receive from
654 * \param instance The RTP instance to change the address on
655 * \param address Address to set it to
663 * ast_rtp_instance_set_alt_remote_address(instance, &sin);
666 * This changes the alternate remote address that RTP will be sent to on instance to the address given in the sin
671 int ast_rtp_instance_set_alt_remote_address(struct ast_rtp_instance *instance, struct sockaddr_in *address);
674 * \brief Set the address that we are expecting to receive RTP on
676 * \param instance The RTP instance to change the address on
677 * \param address Address to set it to
685 * ast_rtp_instance_set_local_address(instance, &sin);
688 * This changes the local address that RTP is expected on to the address given in the sin
693 int ast_rtp_instance_set_local_address(struct ast_rtp_instance *instance, struct sockaddr_in *address);
696 * \brief Get the local address that we are expecting RTP on
698 * \param instance The RTP instance to get the address from
699 * \param address The variable to store the address in
707 * struct sockaddr_in sin;
708 * ast_rtp_instance_get_local_address(instance, &sin);
711 * This gets the local address that we are expecting RTP on and stores it in the 'sin' structure.
715 int ast_rtp_instance_get_local_address(struct ast_rtp_instance *instance, struct sockaddr_in *address);
718 * \brief Get the address of the remote endpoint that we are sending RTP to
720 * \param instance The instance that we want to get the remote address for
721 * \param address A structure to put the address into
729 * struct sockaddr_in sin;
730 * ast_rtp_instance_get_remote_address(instance, &sin);
733 * This retrieves the current remote address set on the instance pointed to by instance and puts the value
734 * into the sin structure.
738 int ast_rtp_instance_get_remote_address(struct ast_rtp_instance *instance, struct sockaddr_in *address);
741 * \brief Set the value of an RTP instance extended property
743 * \param instance The RTP instance to set the extended property on
744 * \param property The extended property to set
745 * \param value The value to set the extended property to
749 void ast_rtp_instance_set_extended_prop(struct ast_rtp_instance *instance, int property, void *value);
752 * \brief Get the value of an RTP instance extended property
754 * \param instance The RTP instance to get the extended property on
755 * \param property The extended property to get
759 void *ast_rtp_instance_get_extended_prop(struct ast_rtp_instance *instance, int property);
762 * \brief Set the value of an RTP instance property
764 * \param instance The RTP instance to set the property on
765 * \param property The property to modify
766 * \param value The value to set the property to
771 * ast_rtp_instance_set_prop(instance, AST_RTP_PROPERTY_NAT, 1);
774 * This enables the AST_RTP_PROPERTY_NAT property on the instance pointed to by instance.
778 void ast_rtp_instance_set_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value);
781 * \brief Get the value of an RTP instance property
783 * \param instance The RTP instance to get the property from
784 * \param property The property to get
786 * \retval Current value of the property
791 * ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT);
794 * This returns the current value of the NAT property on the instance pointed to by instance.
798 int ast_rtp_instance_get_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property);
801 * \brief Get the codecs structure of an RTP instance
803 * \param instance The RTP instance to get the codecs structure from
808 * struct ast_rtp_codecs *codecs = ast_rtp_instance_get_codecs(instance);
811 * This gets the codecs structure on the RTP instance pointed to by 'instance'.
815 struct ast_rtp_codecs *ast_rtp_instance_get_codecs(struct ast_rtp_instance *instance);
818 * \brief Clear payload information from an RTP instance
820 * \param codecs The codecs structure that payloads will be cleared from
821 * \param instance Optionally the instance that the codecs structure belongs to
826 * struct ast_rtp_codecs codecs;
827 * ast_rtp_codecs_payloads_clear(&codecs, NULL);
830 * This clears the codecs structure and puts it into a pristine state.
834 void ast_rtp_codecs_payloads_clear(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance);
837 * \brief Set payload information on an RTP instance to the default
839 * \param codecs The codecs structure to set defaults on
840 * \param instance Optionally the instance that the codecs structure belongs to
845 * struct ast_rtp_codecs codecs;
846 * ast_rtp_codecs_payloads_default(&codecs, NULL);
849 * This sets the default payloads on the codecs structure.
853 void ast_rtp_codecs_payloads_default(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance);
856 * \brief Copy payload information from one RTP instance to another
858 * \param src The source codecs structure
859 * \param dst The destination codecs structure that the values from src will be copied to
860 * \param instance Optionally the instance that the dst codecs structure belongs to
865 * ast_rtp_codecs_payloads_copy(&codecs0, &codecs1, NULL);
868 * This copies the payloads from the codecs0 structure to the codecs1 structure, overwriting any current values.
872 void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance);
875 * \brief Record payload information that was seen in an m= SDP line
877 * \param codecs The codecs structure to muck with
878 * \param instance Optionally the instance that the codecs structure belongs to
879 * \param payload Numerical payload that was seen in the m= SDP line
884 * ast_rtp_codecs_payloads_set_m_type(&codecs, NULL, 0);
887 * This records that the numerical payload '0' was seen in the codecs structure.
891 void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload);
894 * \brief Record payload information that was seen in an a=rtpmap: SDP line
896 * \param codecs The codecs structure to muck with
897 * \param instance Optionally the instance that the codecs structure belongs to
898 * \param payload Numerical payload that was seen in the a=rtpmap: SDP line
899 * \param mimetype The string mime type that was seen
900 * \param mimesubtype The strin mime sub type that was seen
901 * \param options Optional options that may change the behavior of this specific payload
909 * ast_rtp_codecs_payloads_set_rtpmap_type(&codecs, NULL, 0, "audio", "PCMU", 0);
912 * This records that the numerical payload '0' was seen with mime type 'audio' and sub mime type 'PCMU' in the codecs structure.
916 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);
919 * \brief Set payload type to a known MIME media type for a codec with a specific sample rate
921 * \param rtp RTP structure to modify
922 * \param instance Optionally the instance that the codecs structure belongs to
923 * \param pt Payload type entry to modify
924 * \param mimetype top-level MIME type of media stream (typically "audio", "video", "text", etc.)
925 * \param mimesubtype MIME subtype of media stream (typically a codec name)
926 * \param options Zero or more flags from the ast_rtp_options enum
927 * \param sample_rate The sample rate of the media stream
929 * This function 'fills in' an entry in the list of possible formats for
930 * a media stream associated with an RTP structure.
932 * \retval 0 on success
933 * \retval -1 if the payload type is out of range
934 * \retval -2 if the mimeType/mimeSubtype combination was not found
938 int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int pt,
939 char *mimetype, char *mimesubtype,
940 enum ast_rtp_options options,
941 unsigned int sample_rate);
944 * \brief Remove payload information
946 * \param codecs The codecs structure to muck with
947 * \param instance Optionally the instance that the codecs structure belongs to
948 * \param payload Numerical payload to unset
953 * ast_rtp_codecs_payloads_unset(&codecs, NULL, 0);
956 * This clears the payload '0' from the codecs structure. It will be as if it was never set.
960 void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload);
963 * \brief Retrieve payload information by payload
965 * \param codecs Codecs structure to look in
966 * \param payload Numerical payload to look up
968 * \retval Payload information
973 * struct ast_rtp_payload_type payload_type;
974 * payload_type = ast_rtp_codecs_payload_lookup(&codecs, 0);
977 * This looks up the information for payload '0' from the codecs structure.
981 struct ast_rtp_payload_type ast_rtp_codecs_payload_lookup(struct ast_rtp_codecs *codecs, int payload);
984 * \brief Get the sample rate associated with known RTP payload types
986 * \param asterisk_format True if the value in the 'code' parameter is an AST_FORMAT value
987 * \param code Format code, either from AST_FORMAT list or from AST_RTP list
989 * \return the sample rate if the format was found, zero if it was not found
993 unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format, int code);
996 * \brief Retrieve all formats that were found
998 * \param codecs Codecs structure to look in
999 * \param astFormats An integer to put the Asterisk formats in
1000 * \param nonastformats An integer to put the non-Asterisk formats in
1005 * int astformats, nonastformats;
1006 * ast_rtp_codecs_payload_Formats(&codecs, &astformats, &nonastformats);
1009 * This retrieves all the formats known about in the codecs structure and puts the Asterisk ones in the integer
1010 * pointed to by astformats and the non-Asterisk ones in the integer pointed to by nonastformats.
1014 void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, int *astformats, int *nonastformats);
1017 * \brief Retrieve a payload based on whether it is an Asterisk format and the code
1019 * \param codecs Codecs structure to look in
1020 * \param asterisk_format Non-zero if the given code is an Asterisk format value
1021 * \param code The format to look for
1023 * \retval Numerical payload
1028 * int payload = ast_rtp_codecs_payload_code(&codecs, 1, AST_FORMAT_ULAW);
1031 * This looks for the numerical payload for ULAW in the codecs structure.
1035 int ast_rtp_codecs_payload_code(struct ast_rtp_codecs *codecs, const int asterisk_format, const int code);
1038 * \brief Retrieve mime subtype information on a payload
1040 * \param asterisk_format Non-zero if the given code is an Asterisk format value
1041 * \param code Format to look up
1042 * \param options Additional options that may change the result
1044 * \retval Mime subtype success
1045 * \retval NULL failure
1050 * const char *subtype = ast_rtp_lookup_mime_subtype2(1, AST_FORMAT_ULAW, 0);
1053 * This looks up the mime subtype for the ULAW format.
1057 const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format, const int code, enum ast_rtp_options options);
1060 * \brief Convert formats into a string and put them into a buffer
1062 * \param buf Buffer to put the mime output into
1063 * \param capability Formats that we are looking up
1064 * \param asterisk_format Non-zero if the given capability are Asterisk format capabilities
1065 * \param options Additional options that may change the result
1067 * \retval non-NULL success
1068 * \retval NULL failure
1073 * char buf[256] = "";
1074 * char *mime = ast_rtp_lookup_mime_multiple2(&buf, sizeof(buf), AST_FORMAT_ULAW | AST_FORMAT_ALAW, 1, 0);
1077 * This returns the mime values for ULAW and ALAW in the buffer pointed to by buf.
1081 char *ast_rtp_lookup_mime_multiple2(struct ast_str *buf, const int capability, const int asterisk_format, enum ast_rtp_options options);
1084 * \brief Set codec packetization preferences
1086 * \param codecs Codecs structure to muck with
1087 * \param instance Optionally the instance that the codecs structure belongs to
1088 * \param prefs Codec packetization preferences
1093 * ast_rtp_codecs_packetization_set(&codecs, NULL, &prefs);
1096 * This sets the packetization preferences pointed to by prefs on the codecs structure pointed to by codecs.
1100 void ast_rtp_codecs_packetization_set(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, struct ast_codec_pref *prefs);
1103 * \brief Begin sending a DTMF digit
1105 * \param instance The RTP instance to send the DTMF on
1106 * \param digit What DTMF digit to send
1109 * \retval -1 failure
1114 * ast_rtp_instance_dtmf_begin(instance, '1');
1117 * This starts sending the DTMF '1' on the RTP instance pointed to by instance. It will
1118 * continue being sent until it is ended.
1122 int ast_rtp_instance_dtmf_begin(struct ast_rtp_instance *instance, char digit);
1125 * \brief Stop sending a DTMF digit
1127 * \param instance The RTP instance to stop the DTMF on
1128 * \param digit What DTMF digit to stop
1131 * \retval -1 failure
1136 * ast_rtp_instance_dtmf_end(instance, '1');
1139 * This stops sending the DTMF '1' on the RTP instance pointed to by instance.
1143 int ast_rtp_instance_dtmf_end(struct ast_rtp_instance *instance, char digit);
1146 * \brief Set the DTMF mode that should be used
1148 * \param instance the RTP instance to set DTMF mode on
1149 * \param dtmf_mode The DTMF mode that is in use
1152 * \retval -1 failure
1157 * ast_rtp_instance_dtmf_mode_set(instance, AST_RTP_DTMF_MODE_RFC2833);
1160 * This sets the RTP instance to use RFC2833 for DTMF transmission and receiving.
1164 int ast_rtp_instance_dtmf_mode_set(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode);
1167 * \brief Get the DTMF mode of an RTP instance
1169 * \param instance The RTP instance to get the DTMF mode of
1176 * enum ast_rtp_dtmf_mode dtmf_mode = ast_rtp_instance_dtmf_mode_get(instance);
1179 * This gets the DTMF mode set on the RTP instance pointed to by 'instance'.
1183 enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get(struct ast_rtp_instance *instance);
1186 * \brief Indicate a new source of audio has dropped in
1188 * \param instance Instance that the new media source is feeding into
1193 * ast_rtp_instance_new_source(instance);
1196 * This indicates that a new source of media is feeding the instance pointed to by
1201 void ast_rtp_instance_new_source(struct ast_rtp_instance *instance);
1204 * \brief Set QoS parameters on an RTP session
1206 * \param instance Instance to set the QoS parameters on
1207 * \param tos Terms of service value
1208 * \param cos Class of service value
1209 * \param desc What is setting the QoS values
1212 * \retval -1 failure
1217 * ast_rtp_instance_set_qos(instance, 0, 0, "Example");
1220 * This sets the TOS and COS values to 0 on the instance pointed to by instance.
1224 int ast_rtp_instance_set_qos(struct ast_rtp_instance *instance, int tos, int cos, const char *desc);
1227 * \brief Stop an RTP instance
1229 * \param instance Instance that media is no longer going to at this time
1234 * ast_rtp_instance_stop(instance);
1237 * This tells the RTP engine being used for the instance pointed to by instance
1238 * that media is no longer going to it at this time, but may in the future.
1242 void ast_rtp_instance_stop(struct ast_rtp_instance *instance);
1245 * \brief Get the file descriptor for an RTP session (or RTCP)
1247 * \param instance Instance to get the file descriptor for
1248 * \param rtcp Whether to retrieve the file descriptor for RTCP or not
1250 * \retval fd success
1251 * \retval -1 failure
1256 * int rtp_fd = ast_rtp_instance_fd(instance, 0);
1259 * This retrieves the file descriptor for the socket carrying media on the instance
1260 * pointed to by instance.
1264 int ast_rtp_instance_fd(struct ast_rtp_instance *instance, int rtcp);
1267 * \brief Get the RTP glue that binds a channel to the RTP engine
1269 * \param type Name of the glue we want
1271 * \retval non-NULL success
1272 * \retval NULL failure
1277 * struct ast_rtp_glue *glue = ast_rtp_instance_get_glue("Example");
1280 * This retrieves the RTP glue that has the name 'Example'.
1284 struct ast_rtp_glue *ast_rtp_instance_get_glue(const char *type);
1287 * \brief Bridge two channels that use RTP instances
1289 * \param c0 First channel part of the bridge
1290 * \param c1 Second channel part of the bridge
1291 * \param flags Bridging flags
1292 * \param fo If a frame needs to be passed up it is stored here
1293 * \param rc Channel that passed the above frame up
1294 * \param timeoutms How long the channels should be bridged for
1296 * \retval Bridge result
1298 * \note This should only be used by channel drivers in their technology declaration.
1302 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);
1305 * \brief Get the other RTP instance that an instance is bridged to
1307 * \param instance The RTP instance that we want
1309 * \retval non-NULL success
1310 * \retval NULL failure
1315 * struct ast_rtp_instance *bridged = ast_rtp_instance_get_bridged(instance0);
1318 * This gets the RTP instance that instance0 is bridged to.
1322 struct ast_rtp_instance *ast_rtp_instance_get_bridged(struct ast_rtp_instance *instance);
1325 * \brief Make two channels compatible for early bridging
1327 * \param c0 First channel part of the bridge
1328 * \param c1 Second channel part of the bridge
1332 void ast_rtp_instance_early_bridge_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
1335 * \brief Early bridge two channels that use RTP instances
1337 * \param c0 First channel part of the bridge
1338 * \param c1 Second channel part of the bridge
1341 * \retval -1 failure
1343 * \note This should only be used by channel drivers in their technology declaration.
1347 int ast_rtp_instance_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
1350 * \brief Initialize RED support on an RTP instance
1352 * \param instance The instance to initialize RED support on
1353 * \param buffer_time How long to buffer before sending
1354 * \param payloads Payload values
1355 * \param generations Number of generations
1358 * \retval -1 failure
1362 int ast_rtp_red_init(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations);
1365 * \brief Buffer a frame in an RTP instance for RED
1367 * \param instance The instance to buffer the frame on
1368 * \param frame Frame that we want to buffer
1371 * \retval -1 failure
1375 int ast_rtp_red_buffer(struct ast_rtp_instance *instance, struct ast_frame *frame);
1378 * \brief Retrieve statistics about an RTP instance
1380 * \param instance Instance to get statistics on
1381 * \param stats Structure to put results into
1382 * \param stat What statistic(s) to retrieve
1385 * \retval -1 failure
1390 * struct ast_rtp_instance_stats stats;
1391 * ast_rtp_instance_get_stats(instance, &stats, AST_RTP_INSTANCE_STAT_ALL);
1394 * This retrieves all statistics the underlying RTP engine supports and puts the values into the
1399 int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat);
1402 * \brief Set standard statistics from an RTP instance on a channel
1404 * \param chan Channel to set the statistics on
1405 * \param instance The RTP instance that statistics will be retrieved from
1410 * ast_rtp_instance_set_stats_vars(chan, rtp);
1413 * This retrieves standard statistics from the RTP instance rtp and sets it on the channel pointed to
1418 void ast_rtp_instance_set_stats_vars(struct ast_channel *chan, struct ast_rtp_instance *instance);
1421 * \brief Retrieve quality statistics about an RTP instance
1423 * \param instance Instance to get statistics on
1424 * \param field What quality statistic to retrieve
1425 * \param buf What buffer to put the result into
1426 * \param size Size of the above buffer
1428 * \retval non-NULL success
1429 * \retval NULL failure
1434 * char quality[AST_MAX_USER_FIELD];
1435 * ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, &buf, sizeof(buf));
1438 * This retrieves general quality statistics and places a text representation into the buf pointed to by buf.
1442 char *ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size);
1445 * \brief Request that the underlying RTP engine provide audio frames in a specific format
1447 * \param instance The RTP instance to change read format on
1448 * \param format Format that frames are wanted in
1451 * \retval -1 failure
1456 * ast_rtp_instance_set_read_format(instance, AST_FORMAT_ULAW);
1459 * This requests that the RTP engine provide audio frames in the ULAW format.
1463 int ast_rtp_instance_set_read_format(struct ast_rtp_instance *instance, int format);
1466 * \brief Tell underlying RTP engine that audio frames will be provided in a specific format
1468 * \param instance The RTP instance to change write format on
1469 * \param format Format that frames will be provided in
1472 * \retval -1 failure
1477 * ast_rtp_instance_set_write_format(instance, AST_FORMAT_ULAW);
1480 * This tells the underlying RTP engine that audio frames will be provided to it in ULAW format.
1484 int ast_rtp_instance_set_write_format(struct ast_rtp_instance *instance, int format);
1487 * \brief Request that the underlying RTP engine make two RTP instances compatible with eachother
1489 * \param chan Our own Asterisk channel
1490 * \param instance The first RTP instance
1491 * \param peer The peer Asterisk channel
1494 * \retval -1 failure
1499 * ast_rtp_instance_make_compatible(instance, peer);
1502 * This makes the RTP instance for 'peer' compatible with 'instance' and vice versa.
1506 int ast_rtp_instance_make_compatible(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_channel *peer);
1508 /*! \brief Request the formats that can be transcoded
1510 * \param instance The RTP instance
1511 * \param to_endpoint Formats being sent/received towards the endpoint
1512 * \param to_asterisk Formats being sent/received towards Asterisk
1514 * \retval supported formats
1519 * ast_rtp_instance_available_formats(instance, AST_FORMAT_ULAW, AST_FORMAT_SLINEAR);
1522 * This sees if it is possible to have ulaw communicated to the endpoint but signed linear received into Asterisk.
1526 int ast_rtp_instance_available_formats(struct ast_rtp_instance *instance, int to_endpoint, int to_asterisk);
1529 * \brief Indicate to the RTP engine that packets are now expected to be sent/received on the RTP instance
1531 * \param instance The RTP instance
1534 * \retval -1 failure
1539 * ast_rtp_instance_activate(instance);
1542 * This tells the underlying RTP engine of instance that packets will now flow.
1546 int ast_rtp_instance_activate(struct ast_rtp_instance *instance);
1549 * \brief Request that the underlying RTP engine send a STUN BIND request
1551 * \param instance The RTP instance
1552 * \param suggestion The suggested destination
1553 * \param username Optionally a username for the request
1558 * ast_rtp_instance_stun_request(instance, NULL, NULL);
1561 * This requests that the RTP engine send a STUN BIND request on the session pointed to by
1566 void ast_rtp_instance_stun_request(struct ast_rtp_instance *instance, struct sockaddr_in *suggestion, const char *username);
1569 * \brief Set the RTP timeout value
1571 * \param instance The RTP instance
1572 * \param timeout Value to set the timeout to
1577 * ast_rtp_instance_set_timeout(instance, 5000);
1580 * This sets the RTP timeout value on 'instance' to be 5000.
1584 void ast_rtp_instance_set_timeout(struct ast_rtp_instance *instance, int timeout);
1587 * \brief Set the RTP timeout value for when the instance is on hold
1589 * \param instance The RTP instance
1590 * \param timeout Value to set the timeout to
1595 * ast_rtp_instance_set_hold_timeout(instance, 5000);
1598 * This sets the RTP hold timeout value on 'instance' to be 5000.
1602 void ast_rtp_instance_set_hold_timeout(struct ast_rtp_instance *instance, int timeout);
1605 * \brief Get the RTP timeout value
1607 * \param instance The RTP instance
1609 * \retval timeout value
1614 * int timeout = ast_rtp_instance_get_timeout(instance);
1617 * This gets the RTP timeout value for the RTP instance pointed to by 'instance'.
1621 int ast_rtp_instance_get_timeout(struct ast_rtp_instance *instance);
1624 * \brief Get the RTP timeout value for when an RTP instance is on hold
1626 * \param instance The RTP instance
1628 * \retval timeout value
1633 * int timeout = ast_rtp_instance_get_hold_timeout(instance);
1636 * This gets the RTP hold timeout value for the RTP instance pointed to by 'instance'.
1640 int ast_rtp_instance_get_hold_timeout(struct ast_rtp_instance *instance);
1643 * \brief Get the RTP engine in use on an RTP instance
1645 * \param instance The RTP instance
1647 * \retval pointer to the engine
1652 * struct ast_rtp_engine *engine = ast_rtp_instance_get_engine(instance);
1655 * This gets the RTP engine currently in use on the RTP instance pointed to by 'instance'.
1659 struct ast_rtp_engine *ast_rtp_instance_get_engine(struct ast_rtp_instance *instance);
1661 #if defined(__cplusplus) || defined(c_plusplus)
1665 #endif /* _ASTERISK_RTP_ENGINE_H */