Sat Mar 26 11:08:13 2011

Asterisk developer's documentation


rtp_engine.h

Go to the documentation of this file.
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 #define AST_RTP_MAX_PT 256
00080 
00081 /* Maximum number of generations */
00082 #define AST_RED_MAX_GENERATION 5
00083 
00084 struct ast_rtp_instance;
00085 struct ast_rtp_glue;
00086 
00087 /*! RTP Properties that can be set on an RTP instance */
00088 enum ast_rtp_property {
00089    /*! Enable symmetric RTP support */
00090    AST_RTP_PROPERTY_NAT = 0,
00091    /*! RTP instance will be carrying DTMF (using RFC2833) */
00092    AST_RTP_PROPERTY_DTMF,
00093    /*! Expect unreliable DTMF from remote party */
00094    AST_RTP_PROPERTY_DTMF_COMPENSATE,
00095    /*! Enable STUN support */
00096    AST_RTP_PROPERTY_STUN,
00097    /*! Enable RTCP support */
00098    AST_RTP_PROPERTY_RTCP,
00099 
00100    /*!
00101     * \brief Maximum number of RTP properties supported
00102     *
00103     * \note THIS MUST BE THE LAST ENTRY IN THIS ENUM.
00104     */
00105    AST_RTP_PROPERTY_MAX,
00106 };
00107 
00108 /*! Additional RTP options */
00109 enum ast_rtp_options {
00110    /*! Remote side is using non-standard G.726 */
00111    AST_RTP_OPT_G726_NONSTANDARD = (1 << 0),
00112 };
00113 
00114 /*! RTP DTMF Modes */
00115 enum ast_rtp_dtmf_mode {
00116    /*! No DTMF is being carried over the RTP stream */
00117    AST_RTP_DTMF_MODE_NONE = 0,
00118    /*! DTMF is being carried out of band using RFC2833 */
00119    AST_RTP_DTMF_MODE_RFC2833,
00120    /*! DTMF is being carried inband over the RTP stream */
00121    AST_RTP_DTMF_MODE_INBAND,
00122 };
00123 
00124 /*! Result codes when RTP glue is queried for information */
00125 enum ast_rtp_glue_result {
00126    /*! No remote or local bridging is permitted */
00127    AST_RTP_GLUE_RESULT_FORBID = 0,
00128    /*! Move RTP stream to be remote between devices directly */
00129    AST_RTP_GLUE_RESULT_REMOTE,
00130    /*! Perform RTP engine level bridging if possible */
00131    AST_RTP_GLUE_RESULT_LOCAL,
00132 };
00133 
00134 /*! Field statistics that can be retrieved from an RTP instance */
00135 enum ast_rtp_instance_stat_field {
00136    /*! Retrieve quality information */
00137    AST_RTP_INSTANCE_STAT_FIELD_QUALITY = 0,
00138    /*! Retrieve quality information about jitter */
00139    AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER,
00140    /*! Retrieve quality information about packet loss */
00141    AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS,
00142    /*! Retrieve quality information about round trip time */
00143    AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT,
00144 };
00145 
00146 /*! Statistics that can be retrieved from an RTP instance */
00147 enum ast_rtp_instance_stat {
00148    /*! Retrieve all statistics */
00149    AST_RTP_INSTANCE_STAT_ALL = 0,
00150    /*! Retrieve number of packets transmitted */
00151    AST_RTP_INSTANCE_STAT_TXCOUNT,
00152    /*! Retrieve number of packets received */
00153    AST_RTP_INSTANCE_STAT_RXCOUNT,
00154    /*! Retrieve ALL statistics relating to packet loss */
00155    AST_RTP_INSTANCE_STAT_COMBINED_LOSS,
00156    /*! Retrieve number of packets lost for transmitting */
00157    AST_RTP_INSTANCE_STAT_TXPLOSS,
00158    /*! Retrieve number of packets lost for receiving */
00159    AST_RTP_INSTANCE_STAT_RXPLOSS,
00160    /*! Retrieve maximum number of packets lost on remote side */
00161    AST_RTP_INSTANCE_STAT_REMOTE_MAXRXPLOSS,
00162    /*! Retrieve minimum number of packets lost on remote side */
00163    AST_RTP_INSTANCE_STAT_REMOTE_MINRXPLOSS,
00164    /*! Retrieve average number of packets lost on remote side */
00165    AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVRXPLOSS,
00166    /*! Retrieve standard deviation of packets lost on remote side */
00167    AST_RTP_INSTANCE_STAT_REMOTE_STDEVRXPLOSS,
00168    /*! Retrieve maximum number of packets lost on local side */
00169    AST_RTP_INSTANCE_STAT_LOCAL_MAXRXPLOSS,
00170    /*! Retrieve minimum number of packets lost on local side */
00171    AST_RTP_INSTANCE_STAT_LOCAL_MINRXPLOSS,
00172    /*! Retrieve average number of packets lost on local side */
00173    AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVRXPLOSS,
00174    /*! Retrieve standard deviation of packets lost on local side */
00175    AST_RTP_INSTANCE_STAT_LOCAL_STDEVRXPLOSS,
00176    /*! Retrieve ALL statistics relating to jitter */
00177    AST_RTP_INSTANCE_STAT_COMBINED_JITTER,
00178    /*! Retrieve jitter on transmitted packets */
00179    AST_RTP_INSTANCE_STAT_TXJITTER,
00180    /*! Retrieve jitter on received packets */
00181    AST_RTP_INSTANCE_STAT_RXJITTER,
00182    /*! Retrieve maximum jitter on remote side */
00183    AST_RTP_INSTANCE_STAT_REMOTE_MAXJITTER,
00184    /*! Retrieve minimum jitter on remote side */
00185    AST_RTP_INSTANCE_STAT_REMOTE_MINJITTER,
00186    /*! Retrieve average jitter on remote side */
00187    AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVJITTER,
00188    /*! Retrieve standard deviation jitter on remote side */
00189    AST_RTP_INSTANCE_STAT_REMOTE_STDEVJITTER,
00190    /*! Retrieve maximum jitter on local side */
00191    AST_RTP_INSTANCE_STAT_LOCAL_MAXJITTER,
00192    /*! Retrieve minimum jitter on local side */
00193    AST_RTP_INSTANCE_STAT_LOCAL_MINJITTER,
00194    /*! Retrieve average jitter on local side */
00195    AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVJITTER,
00196    /*! Retrieve standard deviation jitter on local side */
00197    AST_RTP_INSTANCE_STAT_LOCAL_STDEVJITTER,
00198    /*! Retrieve ALL statistics relating to round trip time */
00199    AST_RTP_INSTANCE_STAT_COMBINED_RTT,
00200    /*! Retrieve round trip time */
00201    AST_RTP_INSTANCE_STAT_RTT,
00202    /*! Retrieve maximum round trip time */
00203    AST_RTP_INSTANCE_STAT_MAX_RTT,
00204    /*! Retrieve minimum round trip time */
00205    AST_RTP_INSTANCE_STAT_MIN_RTT,
00206    /*! Retrieve average round trip time */
00207    AST_RTP_INSTANCE_STAT_NORMDEVRTT,
00208    /*! Retrieve standard deviation round trip time */
00209    AST_RTP_INSTANCE_STAT_STDEVRTT,
00210    /*! Retrieve local SSRC */
00211    AST_RTP_INSTANCE_STAT_LOCAL_SSRC,
00212    /*! Retrieve remote SSRC */
00213    AST_RTP_INSTANCE_STAT_REMOTE_SSRC,
00214 };
00215 
00216 /* Codes for RTP-specific data - not defined by our AST_FORMAT codes */
00217 /*! DTMF (RFC2833) */
00218 #define AST_RTP_DTMF                    (1 << 0)
00219 /*! 'Comfort Noise' (RFC3389) */
00220 #define AST_RTP_CN                      (1 << 1)
00221 /*! DTMF (Cisco Proprietary) */
00222 #define AST_RTP_CISCO_DTMF              (1 << 2)
00223 /*! Maximum RTP-specific code */
00224 #define AST_RTP_MAX                     AST_RTP_CISCO_DTMF
00225 
00226 /*! Structure that represents a payload */
00227 struct ast_rtp_payload_type {
00228    /*! Is this an Asterisk value */
00229    int asterisk_format;
00230    /*! Actual internal value of the payload */
00231    format_t code;
00232 };
00233 
00234 /*! Structure that represents statistics from an RTP instance */
00235 struct ast_rtp_instance_stats {
00236    /*! Number of packets transmitted */
00237    unsigned int txcount;
00238    /*! Number of packets received */
00239    unsigned int rxcount;
00240    /*! Jitter on transmitted packets */
00241    double txjitter;
00242    /*! Jitter on received packets */
00243    double rxjitter;
00244    /*! Maximum jitter on remote side */
00245    double remote_maxjitter;
00246    /*! Minimum jitter on remote side */
00247    double remote_minjitter;
00248    /*! Average jitter on remote side */
00249    double remote_normdevjitter;
00250    /*! Standard deviation jitter on remote side */
00251    double remote_stdevjitter;
00252    /*! Maximum jitter on local side */
00253    double local_maxjitter;
00254    /*! Minimum jitter on local side */
00255    double local_minjitter;
00256    /*! Average jitter on local side */
00257    double local_normdevjitter;
00258    /*! Standard deviation jitter on local side */
00259    double local_stdevjitter;
00260    /*! Number of transmitted packets lost */
00261    unsigned int txploss;
00262    /*! Number of received packets lost */
00263    unsigned int rxploss;
00264    /*! Maximum number of packets lost on remote side */
00265    double remote_maxrxploss;
00266    /*! Minimum number of packets lost on remote side */
00267    double remote_minrxploss;
00268    /*! Average number of packets lost on remote side */
00269    double remote_normdevrxploss;
00270    /*! Standard deviation packets lost on remote side */
00271    double remote_stdevrxploss;
00272    /*! Maximum number of packets lost on local side */
00273    double local_maxrxploss;
00274    /*! Minimum number of packets lost on local side */
00275    double local_minrxploss;
00276    /*! Average number of packets lost on local side */
00277    double local_normdevrxploss;
00278    /*! Standard deviation packets lost on local side */
00279    double local_stdevrxploss;
00280    /*! Total round trip time */
00281    double rtt;
00282    /*! Maximum round trip time */
00283    double maxrtt;
00284    /*! Minimum round trip time */
00285    double minrtt;
00286    /*! Average round trip time */
00287    double normdevrtt;
00288    /*! Standard deviation round trip time */
00289    double stdevrtt;
00290    /*! Our SSRC */
00291    unsigned int local_ssrc;
00292    /*! Their SSRC */
00293    unsigned int remote_ssrc;
00294 };
00295 
00296 #define AST_RTP_STAT_SET(current_stat, combined, placement, value) \
00297 if (stat == current_stat || stat == AST_RTP_INSTANCE_STAT_ALL || (combined >= 0 && combined == current_stat)) { \
00298 placement = value; \
00299 if (stat == current_stat) { \
00300 return 0; \
00301 } \
00302 }
00303 
00304 #define AST_RTP_STAT_TERMINATOR(combined) \
00305 if (stat == combined) { \
00306 return 0; \
00307 }
00308 
00309 /*! Structure that represents an RTP stack (engine) */
00310 struct ast_rtp_engine {
00311    /*! Name of the RTP engine, used when explicitly requested */
00312    const char *name;
00313    /*! Module this RTP engine came from, used for reference counting */
00314    struct ast_module *mod;
00315    /*! Callback for setting up a new RTP instance */
00316    int (*new)(struct ast_rtp_instance *instance, struct sched_context *sched, struct ast_sockaddr *sa, void *data);
00317    /*! Callback for destroying an RTP instance */
00318    int (*destroy)(struct ast_rtp_instance *instance);
00319    /*! Callback for writing out a frame */
00320    int (*write)(struct ast_rtp_instance *instance, struct ast_frame *frame);
00321    /*! Callback for stopping the RTP instance */
00322    void (*stop)(struct ast_rtp_instance *instance);
00323    /*! Callback for starting RFC2833 DTMF transmission */
00324    int (*dtmf_begin)(struct ast_rtp_instance *instance, char digit);
00325    /*! Callback for stopping RFC2833 DTMF transmission */
00326    int (*dtmf_end)(struct ast_rtp_instance *instance, char digit);
00327    int (*dtmf_end_with_duration)(struct ast_rtp_instance *instance, char digit, unsigned int duration);
00328    /*! Callback to indicate that we should update the marker bit */
00329    void (*update_source)(struct ast_rtp_instance *instance);
00330    /*! Callback to indicate that we should update the marker bit and ssrc */
00331    void (*change_source)(struct ast_rtp_instance *instance);
00332    /*! Callback for setting an extended RTP property */
00333    int (*extended_prop_set)(struct ast_rtp_instance *instance, int property, void *value);
00334    /*! Callback for getting an extended RTP property */
00335    void *(*extended_prop_get)(struct ast_rtp_instance *instance, int property);
00336    /*! Callback for setting an RTP property */
00337    void (*prop_set)(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value);
00338    /*! Callback for setting a payload */
00339    void (*payload_set)(struct ast_rtp_instance *instance, int payload, int astformat, format_t format);
00340    /*! Callback for setting packetization preferences */
00341    void (*packetization_set)(struct ast_rtp_instance *instance, struct ast_codec_pref *pref);
00342    /*! Callback for setting the remote address that RTP is to be sent to */
00343    void (*remote_address_set)(struct ast_rtp_instance *instance, struct ast_sockaddr *sa);
00344    /*! Callback for setting an alternate remote address */
00345    void (*alt_remote_address_set)(struct ast_rtp_instance *instance, struct ast_sockaddr *sa);
00346    /*! Callback for changing DTMF mode */
00347    int (*dtmf_mode_set)(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode);
00348    /*! Callback for retrieving statistics */
00349    int (*get_stat)(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat);
00350    /*! Callback for setting QoS values */
00351    int (*qos)(struct ast_rtp_instance *instance, int tos, int cos, const char *desc);
00352    /*! Callback for retrieving a file descriptor to poll on, not always required */
00353    int (*fd)(struct ast_rtp_instance *instance, int rtcp);
00354    /*! Callback for initializing RED support */
00355    int (*red_init)(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations);
00356    /*! Callback for buffering a frame using RED */
00357    int (*red_buffer)(struct ast_rtp_instance *instance, struct ast_frame *frame);
00358    /*! Callback for reading a frame from the RTP engine */
00359    struct ast_frame *(*read)(struct ast_rtp_instance *instance, int rtcp);
00360    /*! Callback to locally bridge two RTP instances */
00361    int (*local_bridge)(struct ast_rtp_instance *instance0, struct ast_rtp_instance *instance1);
00362    /*! Callback to set the read format */
00363    int (*set_read_format)(struct ast_rtp_instance *instance, format_t format);
00364    /*! Callback to set the write format */
00365    int (*set_write_format)(struct ast_rtp_instance *instance, format_t format);
00366    /*! Callback to make two instances compatible */
00367    int (*make_compatible)(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1);
00368    /*! Callback to see if two instances are compatible with DTMF */
00369    int (*dtmf_compatible)(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1);
00370    /*! Callback to indicate that packets will now flow */
00371    int (*activate)(struct ast_rtp_instance *instance);
00372    /*! Callback to request that the RTP engine send a STUN BIND request */
00373    void (*stun_request)(struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username);
00374    /*! Callback to get the transcodeable formats supported */
00375    int (*available_formats)(struct ast_rtp_instance *instance, format_t to_endpoint, format_t to_asterisk);
00376    /*! Linked list information */
00377    AST_RWLIST_ENTRY(ast_rtp_engine) entry;
00378 };
00379 
00380 /*! Structure that represents codec and packetization information */
00381 struct ast_rtp_codecs {
00382    /*! Codec packetization preferences */
00383    struct ast_codec_pref pref;
00384    /*! Payloads present */
00385    struct ast_rtp_payload_type payloads[AST_RTP_MAX_PT];
00386 };
00387 
00388 /*! Structure that represents the glue that binds an RTP instance to a channel */
00389 struct ast_rtp_glue {
00390    /*! Name of the channel driver that this glue is responsible for */
00391    const char *type;
00392    /*! Module that the RTP glue came from */
00393    struct ast_module *mod;
00394    /*!
00395     * \brief Callback for retrieving the RTP instance carrying audio
00396     * \note This function increases the reference count on the returned RTP instance.
00397     */
00398    enum ast_rtp_glue_result (*get_rtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance);
00399    /*!
00400     * \brief Callback for retrieving the RTP instance carrying video
00401     * \note This function increases the reference count on the returned RTP instance.
00402     */
00403    enum ast_rtp_glue_result (*get_vrtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance);
00404    /*!
00405     * \brief Callback for retrieving the RTP instance carrying text
00406     * \note This function increases the reference count on the returned RTP instance.
00407     */
00408    enum ast_rtp_glue_result (*get_trtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance);
00409    /*! Callback for updating the destination that the remote side should send RTP to */
00410    int (*update_peer)(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, format_t codecs, int nat_active);
00411    /*! Callback for retrieving codecs that the channel can do */
00412    format_t (*get_codec)(struct ast_channel *chan);
00413    /*! Linked list information */
00414    AST_RWLIST_ENTRY(ast_rtp_glue) entry;
00415 };
00416 
00417 #define ast_rtp_engine_register(engine) ast_rtp_engine_register2(engine, ast_module_info->self)
00418 
00419 /*!
00420  * \brief Register an RTP engine
00421  *
00422  * \param engine Structure of the RTP engine to register
00423  * \param module Module that the RTP engine is part of
00424  *
00425  * \retval 0 success
00426  * \retval -1 failure
00427  *
00428  * Example usage:
00429  *
00430  * \code
00431  * ast_rtp_engine_register2(&example_rtp_engine, NULL);
00432  * \endcode
00433  *
00434  * This registers the RTP engine declared as example_rtp_engine with the RTP engine core, but does not
00435  * associate a module with it.
00436  *
00437  * \note It is recommended that you use the ast_rtp_engine_register macro so that the module is
00438  *       associated with the RTP engine and use counting is performed.
00439  *
00440  * \since 1.8
00441  */
00442 int ast_rtp_engine_register2(struct ast_rtp_engine *engine, struct ast_module *module);
00443 
00444 /*!
00445  * \brief Unregister an RTP engine
00446  *
00447  * \param engine Structure of the RTP engine to unregister
00448  *
00449  * \retval 0 success
00450  * \retval -1 failure
00451  *
00452  * Example usage:
00453  *
00454  * \code
00455  * ast_rtp_engine_unregister(&example_rtp_engine);
00456  * \endcode
00457  *
00458  * This unregisters the RTP engine declared as example_rtp_engine from the RTP engine core. If a module
00459  * reference was provided when it was registered then this will only be called once the RTP engine is no longer in use.
00460  *
00461  * \since 1.8
00462  */
00463 int ast_rtp_engine_unregister(struct ast_rtp_engine *engine);
00464 
00465 int ast_rtp_engine_register_srtp(struct ast_srtp_res *srtp_res, struct ast_srtp_policy_res *policy_res);
00466 
00467 void ast_rtp_engine_unregister_srtp(void);
00468 int ast_rtp_engine_srtp_is_registered(void);
00469 
00470 #define ast_rtp_glue_register(glue) ast_rtp_glue_register2(glue, ast_module_info->self)
00471 
00472 /*!
00473  * \brief Register RTP glue
00474  *
00475  * \param glue The glue to register
00476  * \param module Module that the RTP glue is part of
00477  *
00478  * \retval 0 success
00479  * \retval -1 failure
00480  *
00481  * Example usage:
00482  *
00483  * \code
00484  * ast_rtp_glue_register2(&example_rtp_glue, NULL);
00485  * \endcode
00486  *
00487  * This registers the RTP glue declared as example_rtp_glue with the RTP engine core, but does not
00488  * associate a module with it.
00489  *
00490  * \note It is recommended that you use the ast_rtp_glue_register macro so that the module is
00491  *       associated with the RTP glue and use counting is performed.
00492  *
00493  * \since 1.8
00494  */
00495 int ast_rtp_glue_register2(struct ast_rtp_glue *glue, struct ast_module *module);
00496 
00497 /*!
00498  * \brief Unregister RTP glue
00499  *
00500  * \param glue The glue to unregister
00501  *
00502  * \retval 0 success
00503  * \retval -1 failure
00504  *
00505  * Example usage:
00506  *
00507  * \code
00508  * ast_rtp_glue_unregister(&example_rtp_glue);
00509  * \endcode
00510  *
00511  * This unregisters the RTP glue declared as example_rtp_gkue from the RTP engine core. If a module
00512  * reference was provided when it was registered then this will only be called once the RTP engine is no longer in use.
00513  *
00514  * \since 1.8
00515  */
00516 int ast_rtp_glue_unregister(struct ast_rtp_glue *glue);
00517 
00518 /*!
00519  * \brief Create a new RTP instance
00520  *
00521  * \param engine_name Name of the engine to use for the RTP instance
00522  * \param sched Scheduler context that the RTP engine may want to use
00523  * \param sa Address we want to bind to
00524  * \param data Unique data for the engine
00525  *
00526  * \retval non-NULL success
00527  * \retval NULL failure
00528  *
00529  * Example usage:
00530  *
00531  * \code
00532  * struct ast_rtp_instance *instance = NULL;
00533  * instance = ast_rtp_instance_new(NULL, sched, &sin, NULL);
00534  * \endcode
00535  *
00536  * This creates a new RTP instance using the default engine and asks the RTP engine to bind to the address given
00537  * in the address structure.
00538  *
00539  * \note The RTP engine does not have to use the address provided when creating an RTP instance. It may choose to use
00540  *       another depending on it's own configuration.
00541  *
00542  * \since 1.8
00543  */
00544 struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name,
00545                 struct sched_context *sched, const struct ast_sockaddr *sa,
00546                 void *data);
00547 
00548 /*!
00549  * \brief Destroy an RTP instance
00550  *
00551  * \param instance The RTP instance to destroy
00552  *
00553  * \retval 0 success
00554  * \retval -1 failure
00555  *
00556  * Example usage:
00557  *
00558  * \code
00559  * ast_rtp_instance_destroy(instance);
00560  * \endcode
00561  *
00562  * This destroys the RTP instance pointed to by instance. Once this function returns instance no longer points to valid
00563  * memory and may not be used again.
00564  *
00565  * \since 1.8
00566  */
00567 int ast_rtp_instance_destroy(struct ast_rtp_instance *instance);
00568 
00569 /*!
00570  * \brief Set the data portion of an RTP instance
00571  *
00572  * \param instance The RTP instance to manipulate
00573  * \param data Pointer to data
00574  *
00575  * Example usage:
00576  *
00577  * \code
00578  * ast_rtp_instance_set_data(instance, blob);
00579  * \endcode
00580  *
00581  * This sets the data pointer on the RTP instance pointed to by 'instance' to
00582  * blob.
00583  *
00584  * \since 1.8
00585  */
00586 void ast_rtp_instance_set_data(struct ast_rtp_instance *instance, void *data);
00587 
00588 /*!
00589  * \brief Get the data portion of an RTP instance
00590  *
00591  * \param instance The RTP instance we want the data portion from
00592  *
00593  * Example usage:
00594  *
00595  * \code
00596  * struct *blob = ast_rtp_instance_get_data(instance);
00597  ( \endcode
00598  *
00599  * This gets the data pointer on the RTP instance pointed to by 'instance'.
00600  *
00601  * \since 1.8
00602  */
00603 void *ast_rtp_instance_get_data(struct ast_rtp_instance *instance);
00604 
00605 /*!
00606  * \brief Send a frame out over RTP
00607  *
00608  * \param instance The RTP instance to send frame out on
00609  * \param frame the frame to send out
00610  *
00611  * \retval 0 success
00612  * \retval -1 failure
00613  *
00614  * Example usage:
00615  *
00616  * \code
00617  * ast_rtp_instance_write(instance, frame);
00618  * \endcode
00619  *
00620  * This gives the frame pointed to by frame to the RTP engine being used for the instance
00621  * and asks that it be transmitted to the current remote address set on the RTP instance.
00622  *
00623  * \since 1.8
00624  */
00625 int ast_rtp_instance_write(struct ast_rtp_instance *instance, struct ast_frame *frame);
00626 
00627 /*!
00628  * \brief Receive a frame over RTP
00629  *
00630  * \param instance The RTP instance to receive frame on
00631  * \param rtcp Whether to read in RTCP or not
00632  *
00633  * \retval non-NULL success
00634  * \retval NULL failure
00635  *
00636  * Example usage:
00637  *
00638  * \code
00639  * struct ast_frame *frame;
00640  * frame = ast_rtp_instance_read(instance, 0);
00641  * \endcode
00642  *
00643  * This asks the RTP engine to read in RTP from the instance and return it as an Asterisk frame.
00644  *
00645  * \since 1.8
00646  */
00647 struct ast_frame *ast_rtp_instance_read(struct ast_rtp_instance *instance, int rtcp);
00648 
00649 /*!
00650  * \brief Set the address of the remote endpoint that we are sending RTP to
00651  *
00652  * \param instance The RTP instance to change the address on
00653  * \param address Address to set it to
00654  *
00655  * \retval 0 success
00656  * \retval -1 failure
00657  *
00658  * Example usage:
00659  *
00660  * \code
00661  * ast_rtp_instance_set_remote_address(instance, &sin);
00662  * \endcode
00663  *
00664  * This changes the remote address that RTP will be sent to on instance to the address given in the sin
00665  * structure.
00666  *
00667  * \since 1.8
00668  */
00669 int ast_rtp_instance_set_remote_address(struct ast_rtp_instance *instance, const struct ast_sockaddr *address);
00670 
00671 
00672 /*!
00673  * \brief Set the address of an an alternate RTP address to receive from
00674  *
00675  * \param instance The RTP instance to change the address on
00676  * \param address Address to set it to
00677  *
00678  * \retval 0 success
00679  * \retval -1 failure
00680  *
00681  * Example usage:
00682  *
00683  * \code
00684  * ast_rtp_instance_set_alt_remote_address(instance, &address);
00685  * \endcode
00686  *
00687  * This changes the alternate remote address that RTP will be sent to on instance to the address given in the sin
00688  * structure.
00689  *
00690  * \since 1.8
00691  */
00692 int ast_rtp_instance_set_alt_remote_address(struct ast_rtp_instance *instance, const struct ast_sockaddr *address);
00693 
00694 /*!
00695  * \brief Set the address that we are expecting to receive RTP on
00696  *
00697  * \param instance The RTP instance to change the address on
00698  * \param address Address to set it to
00699  *
00700  * \retval 0 success
00701  * \retval -1 failure
00702  *
00703  * Example usage:
00704  *
00705  * \code
00706  * ast_rtp_instance_set_local_address(instance, &sin);
00707  * \endcode
00708  *
00709  * This changes the local address that RTP is expected on to the address given in the sin
00710  * structure.
00711  *
00712  * \since 1.8
00713  */
00714 int ast_rtp_instance_set_local_address(struct ast_rtp_instance *instance,
00715                 const struct ast_sockaddr *address);
00716 
00717 /*!
00718  * \brief Get the local address that we are expecting RTP on
00719  *
00720  * \param instance The RTP instance to get the address from
00721  * \param address The variable to store the address in
00722  *
00723  * \retval 0 success
00724  * \retval -1 failure
00725  *
00726  * Example usage:
00727  *
00728  * \code
00729  * struct ast_sockaddr address;
00730  * ast_rtp_instance_get_local_address(instance, &address);
00731  * \endcode
00732  *
00733  * This gets the local address that we are expecting RTP on and stores it in the 'address' structure.
00734  *
00735  * \since 1.8
00736  */
00737 int ast_rtp_instance_get_local_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address);
00738 
00739 /*!
00740  * \brief Get the address of the remote endpoint that we are sending RTP to
00741  *
00742  * \param instance The instance that we want to get the remote address for
00743  * \param address A structure to put the address into
00744  *
00745  * \retval 0 success
00746  * \retval -1 failure
00747  *
00748  * Example usage:
00749  *
00750  * \code
00751  * struct ast_sockaddr address;
00752  * ast_rtp_instance_get_remote_address(instance, &address);
00753  * \endcode
00754  *
00755  * This retrieves the current remote address set on the instance pointed to by instance and puts the value
00756  * into the address structure.
00757  *
00758  * \since 1.8
00759  */
00760 int ast_rtp_instance_get_remote_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address);
00761 
00762 /*!
00763  * \brief Set the value of an RTP instance extended property
00764  *
00765  * \param instance The RTP instance to set the extended property on
00766  * \param property The extended property to set
00767  * \param value The value to set the extended property to
00768  *
00769  * \since 1.8
00770  */
00771 void ast_rtp_instance_set_extended_prop(struct ast_rtp_instance *instance, int property, void *value);
00772 
00773 /*!
00774  * \brief Get the value of an RTP instance extended property
00775  *
00776  * \param instance The RTP instance to get the extended property on
00777  * \param property The extended property to get
00778  *
00779  * \since 1.8
00780  */
00781 void *ast_rtp_instance_get_extended_prop(struct ast_rtp_instance *instance, int property);
00782 
00783 /*!
00784  * \brief Set the value of an RTP instance property
00785  *
00786  * \param instance The RTP instance to set the property on
00787  * \param property The property to modify
00788  * \param value The value to set the property to
00789  *
00790  * Example usage:
00791  *
00792  * \code
00793  * ast_rtp_instance_set_prop(instance, AST_RTP_PROPERTY_NAT, 1);
00794  * \endcode
00795  *
00796  * This enables the AST_RTP_PROPERTY_NAT property on the instance pointed to by instance.
00797  *
00798  * \since 1.8
00799  */
00800 void ast_rtp_instance_set_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value);
00801 
00802 /*!
00803  * \brief Get the value of an RTP instance property
00804  *
00805  * \param instance The RTP instance to get the property from
00806  * \param property The property to get
00807  *
00808  * \retval Current value of the property
00809  *
00810  * Example usage:
00811  *
00812  * \code
00813  * ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT);
00814  * \endcode
00815  *
00816  * This returns the current value of the NAT property on the instance pointed to by instance.
00817  *
00818  * \since 1.8
00819  */
00820 int ast_rtp_instance_get_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property);
00821 
00822 /*!
00823  * \brief Get the codecs structure of an RTP instance
00824  *
00825  * \param instance The RTP instance to get the codecs structure from
00826  *
00827  * Example usage:
00828  *
00829  * \code
00830  * struct ast_rtp_codecs *codecs = ast_rtp_instance_get_codecs(instance);
00831  * \endcode
00832  *
00833  * This gets the codecs structure on the RTP instance pointed to by 'instance'.
00834  *
00835  * \since 1.8
00836  */
00837 struct ast_rtp_codecs *ast_rtp_instance_get_codecs(struct ast_rtp_instance *instance);
00838 
00839 /*!
00840  * \brief Clear payload information from an RTP instance
00841  *
00842  * \param codecs The codecs structure that payloads will be cleared from
00843  * \param instance Optionally the instance that the codecs structure belongs to
00844  *
00845  * Example usage:
00846  *
00847  * \code
00848  * struct ast_rtp_codecs codecs;
00849  * ast_rtp_codecs_payloads_clear(&codecs, NULL);
00850  * \endcode
00851  *
00852  * This clears the codecs structure and puts it into a pristine state.
00853  *
00854  * \since 1.8
00855  */
00856 void ast_rtp_codecs_payloads_clear(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance);
00857 
00858 /*!
00859  * \brief Set payload information on an RTP instance to the default
00860  *
00861  * \param codecs The codecs structure to set defaults on
00862  * \param instance Optionally the instance that the codecs structure belongs to
00863  *
00864  * Example usage:
00865  *
00866  * \code
00867  * struct ast_rtp_codecs codecs;
00868  * ast_rtp_codecs_payloads_default(&codecs, NULL);
00869  * \endcode
00870  *
00871  * This sets the default payloads on the codecs structure.
00872  *
00873  * \since 1.8
00874  */
00875 void ast_rtp_codecs_payloads_default(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance);
00876 
00877 /*!
00878  * \brief Copy payload information from one RTP instance to another
00879  *
00880  * \param src The source codecs structure
00881  * \param dest The destination codecs structure that the values from src will be copied to
00882  * \param instance Optionally the instance that the dst codecs structure belongs to
00883  *
00884  * Example usage:
00885  *
00886  * \code
00887  * ast_rtp_codecs_payloads_copy(&codecs0, &codecs1, NULL);
00888  * \endcode
00889  *
00890  * This copies the payloads from the codecs0 structure to the codecs1 structure, overwriting any current values.
00891  *
00892  * \since 1.8
00893  */
00894 void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance);
00895 
00896 /*!
00897  * \brief Record payload information that was seen in an m= SDP line
00898  *
00899  * \param codecs The codecs structure to muck with
00900  * \param instance Optionally the instance that the codecs structure belongs to
00901  * \param payload Numerical payload that was seen in the m= SDP line
00902  *
00903  * Example usage:
00904  *
00905  * \code
00906  * ast_rtp_codecs_payloads_set_m_type(&codecs, NULL, 0);
00907  * \endcode
00908  *
00909  * This records that the numerical payload '0' was seen in the codecs structure.
00910  *
00911  * \since 1.8
00912  */
00913 void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload);
00914 
00915 /*!
00916  * \brief Record payload information that was seen in an a=rtpmap: SDP line
00917  *
00918  * \param codecs The codecs structure to muck with
00919  * \param instance Optionally the instance that the codecs structure belongs to
00920  * \param payload Numerical payload that was seen in the a=rtpmap: SDP line
00921  * \param mimetype The string mime type that was seen
00922  * \param mimesubtype The strin mime sub type that was seen
00923  * \param options Optional options that may change the behavior of this specific payload
00924  *
00925  * \retval 0 success
00926  * \retval -1 failure
00927  *
00928  * Example usage:
00929  *
00930  * \code
00931  * ast_rtp_codecs_payloads_set_rtpmap_type(&codecs, NULL, 0, "audio", "PCMU", 0);
00932  * \endcode
00933  *
00934  * This records that the numerical payload '0' was seen with mime type 'audio' and sub mime type 'PCMU' in the codecs structure.
00935  *
00936  * \since 1.8
00937  */
00938 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);
00939 
00940 /*!
00941  * \brief Set payload type to a known MIME media type for a codec with a specific sample rate
00942  *
00943  * \param codecs RTP structure to modify
00944  * \param instance Optionally the instance that the codecs structure belongs to
00945  * \param pt Payload type entry to modify
00946  * \param mimetype top-level MIME type of media stream (typically "audio", "video", "text", etc.)
00947  * \param mimesubtype MIME subtype of media stream (typically a codec name)
00948  * \param options Zero or more flags from the ast_rtp_options enum
00949  * \param sample_rate The sample rate of the media stream
00950  *
00951  * This function 'fills in' an entry in the list of possible formats for
00952  * a media stream associated with an RTP structure.
00953  *
00954  * \retval 0 on success
00955  * \retval -1 if the payload type is out of range
00956  * \retval -2 if the mimeType/mimeSubtype combination was not found
00957  *
00958  * \since 1.8
00959  */
00960 int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int pt,
00961               char *mimetype, char *mimesubtype,
00962               enum ast_rtp_options options,
00963               unsigned int sample_rate);
00964 
00965 /*!
00966  * \brief Remove payload information
00967  *
00968  * \param codecs The codecs structure to muck with
00969  * \param instance Optionally the instance that the codecs structure belongs to
00970  * \param payload Numerical payload to unset
00971  *
00972  * Example usage:
00973  *
00974  * \code
00975  * ast_rtp_codecs_payloads_unset(&codecs, NULL, 0);
00976  * \endcode
00977  *
00978  * This clears the payload '0' from the codecs structure. It will be as if it was never set.
00979  *
00980  * \since 1.8
00981  */
00982 void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload);
00983 
00984 /*!
00985  * \brief Retrieve payload information by payload
00986  *
00987  * \param codecs Codecs structure to look in
00988  * \param payload Numerical payload to look up
00989  *
00990  * \retval Payload information
00991  *
00992  * Example usage:
00993  *
00994  * \code
00995  * struct ast_rtp_payload_type payload_type;
00996  * payload_type = ast_rtp_codecs_payload_lookup(&codecs, 0);
00997  * \endcode
00998  *
00999  * This looks up the information for payload '0' from the codecs structure.
01000  *
01001  * \since 1.8
01002  */
01003 struct ast_rtp_payload_type ast_rtp_codecs_payload_lookup(struct ast_rtp_codecs *codecs, int payload);
01004 
01005 /*!
01006  * \brief Get the sample rate associated with known RTP payload types
01007  *
01008  * \param asterisk_format True if the value in the 'code' parameter is an AST_FORMAT value
01009  * \param code Format code, either from AST_FORMAT list or from AST_RTP list
01010  *
01011  * \return the sample rate if the format was found, zero if it was not found
01012  *
01013  * \since 1.8
01014  */
01015 unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format, format_t code);
01016 
01017 /*!
01018  * \brief Retrieve all formats that were found
01019  *
01020  * \param codecs Codecs structure to look in
01021  * \param astformats An integer to put the Asterisk formats in
01022  * \param nonastformats An integer to put the non-Asterisk formats in
01023  *
01024  * Example usage:
01025  *
01026  * \code
01027  * int astformats, nonastformats;
01028  * ast_rtp_codecs_payload_Formats(&codecs, &astformats, &nonastformats);
01029  * \endcode
01030  *
01031  * This retrieves all the formats known about in the codecs structure and puts the Asterisk ones in the integer
01032  * pointed to by astformats and the non-Asterisk ones in the integer pointed to by nonastformats.
01033  *
01034  * \since 1.8
01035  */
01036 void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, format_t *astformats, int *nonastformats);
01037 
01038 /*!
01039  * \brief Retrieve a payload based on whether it is an Asterisk format and the code
01040  *
01041  * \param codecs Codecs structure to look in
01042  * \param asterisk_format Non-zero if the given code is an Asterisk format value
01043  * \param code The format to look for
01044  *
01045  * \retval Numerical payload
01046  *
01047  * Example usage:
01048  *
01049  * \code
01050  * int payload = ast_rtp_codecs_payload_code(&codecs, 1, AST_FORMAT_ULAW);
01051  * \endcode
01052  *
01053  * This looks for the numerical payload for ULAW in the codecs structure.
01054  *
01055  * \since 1.8
01056  */
01057 int ast_rtp_codecs_payload_code(struct ast_rtp_codecs *codecs, const int asterisk_format, const format_t code);
01058 
01059 /*!
01060  * \brief Retrieve mime subtype information on a payload
01061  *
01062  * \param asterisk_format Non-zero if the given code is an Asterisk format value
01063  * \param code Format to look up
01064  * \param options Additional options that may change the result
01065  *
01066  * \retval Mime subtype success
01067  * \retval NULL failure
01068  *
01069  * Example usage:
01070  *
01071  * \code
01072  * const char *subtype = ast_rtp_lookup_mime_subtype2(1, AST_FORMAT_ULAW, 0);
01073  * \endcode
01074  *
01075  * This looks up the mime subtype for the ULAW format.
01076  *
01077  * \since 1.8
01078  */
01079 const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format, const format_t code, enum ast_rtp_options options);
01080 
01081 /*!
01082  * \brief Convert formats into a string and put them into a buffer
01083  *
01084  * \param buf Buffer to put the mime output into
01085  * \param capability Formats that we are looking up
01086  * \param asterisk_format Non-zero if the given capability are Asterisk format capabilities
01087  * \param options Additional options that may change the result
01088  *
01089  * \retval non-NULL success
01090  * \retval NULL failure
01091  *
01092  * Example usage:
01093  *
01094  * \code
01095  * char buf[256] = "";
01096  * char *mime = ast_rtp_lookup_mime_multiple2(&buf, sizeof(buf), AST_FORMAT_ULAW | AST_FORMAT_ALAW, 1, 0);
01097  * \endcode
01098  *
01099  * This returns the mime values for ULAW and ALAW in the buffer pointed to by buf.
01100  *
01101  * \since 1.8
01102  */
01103 char *ast_rtp_lookup_mime_multiple2(struct ast_str *buf, const format_t capability, const int asterisk_format, enum ast_rtp_options options);
01104 
01105 /*!
01106  * \brief Set codec packetization preferences
01107  *
01108  * \param codecs Codecs structure to muck with
01109  * \param instance Optionally the instance that the codecs structure belongs to
01110  * \param prefs Codec packetization preferences
01111  *
01112  * Example usage:
01113  *
01114  * \code
01115  * ast_rtp_codecs_packetization_set(&codecs, NULL, &prefs);
01116  * \endcode
01117  *
01118  * This sets the packetization preferences pointed to by prefs on the codecs structure pointed to by codecs.
01119  *
01120  * \since 1.8
01121  */
01122 void ast_rtp_codecs_packetization_set(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, struct ast_codec_pref *prefs);
01123 
01124 /*!
01125  * \brief Begin sending a DTMF digit
01126  *
01127  * \param instance The RTP instance to send the DTMF on
01128  * \param digit What DTMF digit to send
01129  *
01130  * \retval 0 success
01131  * \retval -1 failure
01132  *
01133  * Example usage:
01134  *
01135  * \code
01136  * ast_rtp_instance_dtmf_begin(instance, '1');
01137  * \endcode
01138  *
01139  * This starts sending the DTMF '1' on the RTP instance pointed to by instance. It will
01140  * continue being sent until it is ended.
01141  *
01142  * \since 1.8
01143  */
01144 int ast_rtp_instance_dtmf_begin(struct ast_rtp_instance *instance, char digit);
01145 
01146 /*!
01147  * \brief Stop sending a DTMF digit
01148  *
01149  * \param instance The RTP instance to stop the DTMF on
01150  * \param digit What DTMF digit to stop
01151  *
01152  * \retval 0 success
01153  * \retval -1 failure
01154  *
01155  * Example usage:
01156  *
01157  * \code
01158  * ast_rtp_instance_dtmf_end(instance, '1');
01159  * \endcode
01160  *
01161  * This stops sending the DTMF '1' on the RTP instance pointed to by instance.
01162  *
01163  * \since 1.8
01164  */
01165 int ast_rtp_instance_dtmf_end(struct ast_rtp_instance *instance, char digit);
01166 int ast_rtp_instance_dtmf_end_with_duration(struct ast_rtp_instance *instance, char digit, unsigned int duration);
01167 
01168 /*!
01169  * \brief Set the DTMF mode that should be used
01170  *
01171  * \param instance the RTP instance to set DTMF mode on
01172  * \param dtmf_mode The DTMF mode that is in use
01173  *
01174  * \retval 0 success
01175  * \retval -1 failure
01176  *
01177  * Example usage:
01178  *
01179  * \code
01180  * ast_rtp_instance_dtmf_mode_set(instance, AST_RTP_DTMF_MODE_RFC2833);
01181  * \endcode
01182  *
01183  * This sets the RTP instance to use RFC2833 for DTMF transmission and receiving.
01184  *
01185  * \since 1.8
01186  */
01187 int ast_rtp_instance_dtmf_mode_set(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode);
01188 
01189 /*!
01190  * \brief Get the DTMF mode of an RTP instance
01191  *
01192  * \param instance The RTP instance to get the DTMF mode of
01193  *
01194  * \retval DTMF mode
01195  *
01196  * Example usage:
01197  *
01198  * \code
01199  * enum ast_rtp_dtmf_mode dtmf_mode = ast_rtp_instance_dtmf_mode_get(instance);
01200  * \endcode
01201  *
01202  * This gets the DTMF mode set on the RTP instance pointed to by 'instance'.
01203  *
01204  * \since 1.8
01205  */
01206 enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get(struct ast_rtp_instance *instance);
01207 
01208 /*!
01209  * \brief Indicate that the RTP marker bit should be set on an RTP stream
01210  *
01211  * \param instance Instance that the new media source is feeding into
01212  *
01213  * Example usage:
01214  *
01215  * \code
01216  * ast_rtp_instance_update_source(instance);
01217  * \endcode
01218  *
01219  * This indicates that the source of media that is feeding the instance pointed to by
01220  * instance has been updated and that the marker bit should be set.
01221  *
01222  * \since 1.8
01223  */
01224 void ast_rtp_instance_update_source(struct ast_rtp_instance *instance);
01225 
01226 /*!
01227  * \brief Indicate a new source of audio has dropped in and the ssrc should change
01228  *
01229  * \param instance Instance that the new media source is feeding into
01230  *
01231  * Example usage:
01232  *
01233  * \code
01234  * ast_rtp_instance_change_source(instance);
01235  * \endcode
01236  *
01237  * This indicates that the source of media that is feeding the instance pointed to by
01238  * instance has changed and that the marker bit should be set and the SSRC updated.
01239  *
01240  * \since 1.8
01241  */
01242 void ast_rtp_instance_change_source(struct ast_rtp_instance *instance);
01243 
01244 /*!
01245  * \brief Set QoS parameters on an RTP session
01246  *
01247  * \param instance Instance to set the QoS parameters on
01248  * \param tos Terms of service value
01249  * \param cos Class of service value
01250  * \param desc What is setting the QoS values
01251  *
01252  * \retval 0 success
01253  * \retval -1 failure
01254  *
01255  * Example usage:
01256  *
01257  * \code
01258  * ast_rtp_instance_set_qos(instance, 0, 0, "Example");
01259  * \endcode
01260  *
01261  * This sets the TOS and COS values to 0 on the instance pointed to by instance.
01262  *
01263  * \since 1.8
01264  */
01265 int ast_rtp_instance_set_qos(struct ast_rtp_instance *instance, int tos, int cos, const char *desc);
01266 
01267 /*!
01268  * \brief Stop an RTP instance
01269  *
01270  * \param instance Instance that media is no longer going to at this time
01271  *
01272  * Example usage:
01273  *
01274  * \code
01275  * ast_rtp_instance_stop(instance);
01276  * \endcode
01277  *
01278  * This tells the RTP engine being used for the instance pointed to by instance
01279  * that media is no longer going to it at this time, but may in the future.
01280  *
01281  * \since 1.8
01282  */
01283 void ast_rtp_instance_stop(struct ast_rtp_instance *instance);
01284 
01285 /*!
01286  * \brief Get the file descriptor for an RTP session (or RTCP)
01287  *
01288  * \param instance Instance to get the file descriptor for
01289  * \param rtcp Whether to retrieve the file descriptor for RTCP or not
01290  *
01291  * \retval fd success
01292  * \retval -1 failure
01293  *
01294  * Example usage:
01295  *
01296  * \code
01297  * int rtp_fd = ast_rtp_instance_fd(instance, 0);
01298  * \endcode
01299  *
01300  * This retrieves the file descriptor for the socket carrying media on the instance
01301  * pointed to by instance.
01302  *
01303  * \since 1.8
01304  */
01305 int ast_rtp_instance_fd(struct ast_rtp_instance *instance, int rtcp);
01306 
01307 /*!
01308  * \brief Get the RTP glue that binds a channel to the RTP engine
01309  *
01310  * \param type Name of the glue we want
01311  *
01312  * \retval non-NULL success
01313  * \retval NULL failure
01314  *
01315  * Example usage:
01316  *
01317  * \code
01318  * struct ast_rtp_glue *glue = ast_rtp_instance_get_glue("Example");
01319  * \endcode
01320  *
01321  * This retrieves the RTP glue that has the name 'Example'.
01322  *
01323  * \since 1.8
01324  */
01325 struct ast_rtp_glue *ast_rtp_instance_get_glue(const char *type);
01326 
01327 /*!
01328  * \brief Bridge two channels that use RTP instances
01329  *
01330  * \param c0 First channel part of the bridge
01331  * \param c1 Second channel part of the bridge
01332  * \param flags Bridging flags
01333  * \param fo If a frame needs to be passed up it is stored here
01334  * \param rc Channel that passed the above frame up
01335  * \param timeoutms How long the channels should be bridged for
01336  *
01337  * \retval Bridge result
01338  *
01339  * \note This should only be used by channel drivers in their technology declaration.
01340  *
01341  * \since 1.8
01342  */
01343 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);
01344 
01345 /*!
01346  * \brief Get the other RTP instance that an instance is bridged to
01347  *
01348  * \param instance The RTP instance that we want
01349  *
01350  * \retval non-NULL success
01351  * \retval NULL failure
01352  *
01353  * Example usage:
01354  *
01355  * \code
01356  * struct ast_rtp_instance *bridged = ast_rtp_instance_get_bridged(instance0);
01357  * \endcode
01358  *
01359  * This gets the RTP instance that instance0 is bridged to.
01360  *
01361  * \since 1.8
01362  */
01363 struct ast_rtp_instance *ast_rtp_instance_get_bridged(struct ast_rtp_instance *instance);
01364 
01365 /*!
01366  * \brief Make two channels compatible for early bridging
01367  *
01368  * \param c0 First channel part of the bridge
01369  * \param c1 Second channel part of the bridge
01370  *
01371  * \since 1.8
01372  */
01373 void ast_rtp_instance_early_bridge_make_compatible(struct ast_channel *c0, struct ast_channel *c1);
01374 
01375 /*!
01376  * \brief Early bridge two channels that use RTP instances
01377  *
01378  * \param c0 First channel part of the bridge
01379  * \param c1 Second channel part of the bridge
01380  *
01381  * \retval 0 success
01382  * \retval -1 failure
01383  *
01384  * \note This should only be used by channel drivers in their technology declaration.
01385  *
01386  * \since 1.8
01387  */
01388 int ast_rtp_instance_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
01389 
01390 /*!
01391  * \brief Initialize RED support on an RTP instance
01392  *
01393  * \param instance The instance to initialize RED support on
01394  * \param buffer_time How long to buffer before sending
01395  * \param payloads Payload values
01396  * \param generations Number of generations
01397  *
01398  * \retval 0 success
01399  * \retval -1 failure
01400  *
01401  * \since 1.8
01402  */
01403 int ast_rtp_red_init(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations);
01404 
01405 /*!
01406  * \brief Buffer a frame in an RTP instance for RED
01407  *
01408  * \param instance The instance to buffer the frame on
01409  * \param frame Frame that we want to buffer
01410  *
01411  * \retval 0 success
01412  * \retval -1 failure
01413  *
01414  * \since 1.8
01415  */
01416 int ast_rtp_red_buffer(struct ast_rtp_instance *instance, struct ast_frame *frame);
01417 
01418 /*!
01419  * \brief Retrieve statistics about an RTP instance
01420  *
01421  * \param instance Instance to get statistics on
01422  * \param stats Structure to put results into
01423  * \param stat What statistic(s) to retrieve
01424  *
01425  * \retval 0 success
01426  * \retval -1 failure
01427  *
01428  * Example usage:
01429  *
01430  * \code
01431  * struct ast_rtp_instance_stats stats;
01432  * ast_rtp_instance_get_stats(instance, &stats, AST_RTP_INSTANCE_STAT_ALL);
01433  * \endcode
01434  *
01435  * This retrieves all statistics the underlying RTP engine supports and puts the values into the
01436  * stats structure.
01437  *
01438  * \since 1.8
01439  */
01440 int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat);
01441 
01442 /*!
01443  * \brief Set standard statistics from an RTP instance on a channel
01444  *
01445  * \param chan Channel to set the statistics on
01446  * \param instance The RTP instance that statistics will be retrieved from
01447  *
01448  * Example usage:
01449  *
01450  * \code
01451  * ast_rtp_instance_set_stats_vars(chan, rtp);
01452  * \endcode
01453  *
01454  * This retrieves standard statistics from the RTP instance rtp and sets it on the channel pointed to
01455  * by chan.
01456  *
01457  * \since 1.8
01458  */
01459 void ast_rtp_instance_set_stats_vars(struct ast_channel *chan, struct ast_rtp_instance *instance);
01460 
01461 /*!
01462  * \brief Retrieve quality statistics about an RTP instance
01463  *
01464  * \param instance Instance to get statistics on
01465  * \param field What quality statistic to retrieve
01466  * \param buf What buffer to put the result into
01467  * \param size Size of the above buffer
01468  *
01469  * \retval non-NULL success
01470  * \retval NULL failure
01471  *
01472  * Example usage:
01473  *
01474  * \code
01475  * char quality[AST_MAX_USER_FIELD];
01476  * ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, &buf, sizeof(buf));
01477  * \endcode
01478  *
01479  * This retrieves general quality statistics and places a text representation into the buf pointed to by buf.
01480  *
01481  * \since 1.8
01482  */
01483 char *ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size);
01484 
01485 /*!
01486  * \brief Request that the underlying RTP engine provide audio frames in a specific format
01487  *
01488  * \param instance The RTP instance to change read format on
01489  * \param format Format that frames are wanted in
01490  *
01491  * \retval 0 success
01492  * \retval -1 failure
01493  *
01494  * Example usage:
01495  *
01496  * \code
01497  * ast_rtp_instance_set_read_format(instance, AST_FORMAT_ULAW);
01498  * \endcode
01499  *
01500  * This requests that the RTP engine provide audio frames in the ULAW format.
01501  *
01502  * \since 1.8
01503  */
01504 int ast_rtp_instance_set_read_format(struct ast_rtp_instance *instance, format_t format);
01505 
01506 /*!
01507  * \brief Tell underlying RTP engine that audio frames will be provided in a specific format
01508  *
01509  * \param instance The RTP instance to change write format on
01510  * \param format Format that frames will be provided in
01511  *
01512  * \retval 0 success
01513  * \retval -1 failure
01514  *
01515  * Example usage:
01516  *
01517  * \code
01518  * ast_rtp_instance_set_write_format(instance, AST_FORMAT_ULAW);
01519  * \endcode
01520  *
01521  * This tells the underlying RTP engine that audio frames will be provided to it in ULAW format.
01522  *
01523  * \since 1.8
01524  */
01525 int ast_rtp_instance_set_write_format(struct ast_rtp_instance *instance, format_t format);
01526 
01527 /*!
01528  * \brief Request that the underlying RTP engine make two RTP instances compatible with eachother
01529  *
01530  * \param chan Our own Asterisk channel
01531  * \param instance The first RTP instance
01532  * \param peer The peer Asterisk channel
01533  *
01534  * \retval 0 success
01535  * \retval -1 failure
01536  *
01537  * Example usage:
01538  *
01539  * \code
01540  * ast_rtp_instance_make_compatible(instance, peer);
01541  * \endcode
01542  *
01543  * This makes the RTP instance for 'peer' compatible with 'instance' and vice versa.
01544  *
01545  * \since 1.8
01546  */
01547 int ast_rtp_instance_make_compatible(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_channel *peer);
01548 
01549 /*! \brief Request the formats that can be transcoded
01550  *
01551  * \param instance The RTP instance
01552  * \param to_endpoint Formats being sent/received towards the endpoint
01553  * \param to_asterisk Formats being sent/received towards Asterisk
01554  *
01555  * \retval supported formats
01556  *
01557  * Example usage:
01558  *
01559  * \code
01560  * ast_rtp_instance_available_formats(instance, AST_FORMAT_ULAW, AST_FORMAT_SLINEAR);
01561  * \endcode
01562  *
01563  * This sees if it is possible to have ulaw communicated to the endpoint but signed linear received into Asterisk.
01564  *
01565  * \since 1.8
01566  */
01567 format_t ast_rtp_instance_available_formats(struct ast_rtp_instance *instance, format_t to_endpoint, format_t to_asterisk);
01568 
01569 /*!
01570  * \brief Indicate to the RTP engine that packets are now expected to be sent/received on the RTP instance
01571  *
01572  * \param instance The RTP instance
01573  *
01574  * \retval 0 success
01575  * \retval -1 failure
01576  *
01577  * Example usage:
01578  *
01579  * \code
01580  * ast_rtp_instance_activate(instance);
01581  * \endcode
01582  *
01583  * This tells the underlying RTP engine of instance that packets will now flow.
01584  *
01585  * \since 1.8
01586  */
01587 int ast_rtp_instance_activate(struct ast_rtp_instance *instance);
01588 
01589 /*!
01590  * \brief Request that the underlying RTP engine send a STUN BIND request
01591  *
01592  * \param instance The RTP instance
01593  * \param suggestion The suggested destination
01594  * \param username Optionally a username for the request
01595  *
01596  * Example usage:
01597  *
01598  * \code
01599  * ast_rtp_instance_stun_request(instance, NULL, NULL);
01600  * \endcode
01601  *
01602  * This requests that the RTP engine send a STUN BIND request on the session pointed to by
01603  * 'instance'.
01604  *
01605  * \since 1.8
01606  */
01607 void ast_rtp_instance_stun_request(struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username);
01608 
01609 /*!
01610  * \brief Set the RTP timeout value
01611  *
01612  * \param instance The RTP instance
01613  * \param timeout Value to set the timeout to
01614  *
01615  * Example usage:
01616  *
01617  * \code
01618  * ast_rtp_instance_set_timeout(instance, 5000);
01619  * \endcode
01620  *
01621  * This sets the RTP timeout value on 'instance' to be 5000.
01622  *
01623  * \since 1.8
01624  */
01625 void ast_rtp_instance_set_timeout(struct ast_rtp_instance *instance, int timeout);
01626 
01627 /*!
01628  * \brief Set the RTP timeout value for when the instance is on hold
01629  *
01630  * \param instance The RTP instance
01631  * \param timeout Value to set the timeout to
01632  *
01633  * Example usage:
01634  *
01635  * \code
01636  * ast_rtp_instance_set_hold_timeout(instance, 5000);
01637  * \endcode
01638  *
01639  * This sets the RTP hold timeout value on 'instance' to be 5000.
01640  *
01641  * \since 1.8
01642  */
01643 void ast_rtp_instance_set_hold_timeout(struct ast_rtp_instance *instance, int timeout);
01644 
01645 /*!
01646  * \brief Get the RTP timeout value
01647  *
01648  * \param instance The RTP instance
01649  *
01650  * \retval timeout value
01651  *
01652  * Example usage:
01653  *
01654  * \code
01655  * int timeout = ast_rtp_instance_get_timeout(instance);
01656  * \endcode
01657  *
01658  * This gets the RTP timeout value for the RTP instance pointed to by 'instance'.
01659  *
01660  * \since 1.8
01661  */
01662 int ast_rtp_instance_get_timeout(struct ast_rtp_instance *instance);
01663 
01664 /*!
01665  * \brief Get the RTP timeout value for when an RTP instance is on hold
01666  *
01667  * \param instance The RTP instance
01668  *
01669  * \retval timeout value
01670  *
01671  * Example usage:
01672  *
01673  * \code
01674  * int timeout = ast_rtp_instance_get_hold_timeout(instance);
01675  * \endcode
01676  *
01677  * This gets the RTP hold timeout value for the RTP instance pointed to by 'instance'.
01678  *
01679  * \since 1.8
01680  */
01681 int ast_rtp_instance_get_hold_timeout(struct ast_rtp_instance *instance);
01682 
01683 /*!
01684  * \brief Get the RTP engine in use on an RTP instance
01685  *
01686  * \param instance The RTP instance
01687  *
01688  * \retval pointer to the engine
01689  *
01690  * Example usage:
01691  *
01692  * \code
01693  * struct ast_rtp_engine *engine = ast_rtp_instance_get_engine(instance);
01694  * \endcode
01695  *
01696  * This gets the RTP engine currently in use on the RTP instance pointed to by 'instance'.
01697  *
01698  * \since 1.8
01699  */
01700 struct ast_rtp_engine *ast_rtp_instance_get_engine(struct ast_rtp_instance *instance);
01701 
01702 /*!
01703  * \brief Get the RTP glue in use on an RTP instance
01704  *
01705  * \param instance The RTP instance
01706  *
01707  * \retval pointer to the glue
01708  *
01709  * Example:
01710  *
01711  * \code
01712  * struct ast_rtp_glue *glue = ast_rtp_instance_get_active_glue(instance);
01713  * \endcode
01714  *
01715  * This gets the RTP glue currently in use on the RTP instance pointed to by 'instance'.
01716  *
01717  * \since 1.8
01718  */
01719 struct ast_rtp_glue *ast_rtp_instance_get_active_glue(struct ast_rtp_instance *instance);
01720 
01721 /*!
01722  * \brief Get the channel that is associated with an RTP instance while in a bridge
01723  *
01724  * \param instance The RTP instance
01725  *
01726  * \retval pointer to the channel
01727  *
01728  * Example:
01729  *
01730  * \code
01731  * struct ast_channel *chan = ast_rtp_instance_get_chan(instance);
01732  * \endcode
01733  *
01734  * This gets the channel associated with the RTP instance pointed to by 'instance'.
01735  *
01736  * \note This will only return a channel while in a local or remote bridge.
01737  *
01738  * \since 1.8
01739  */
01740 struct ast_channel *ast_rtp_instance_get_chan(struct ast_rtp_instance *instance);
01741 
01742 int ast_rtp_instance_add_srtp_policy(struct ast_rtp_instance *instance, struct ast_srtp_policy *policy);
01743 struct ast_srtp *ast_rtp_instance_get_srtp(struct ast_rtp_instance *instance);
01744 
01745 #if defined(__cplusplus) || defined(c_plusplus)
01746 }
01747 #endif
01748 
01749 #endif /* _ASTERISK_RTP_ENGINE_H */

Generated on Sat Mar 26 11:08:14 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.9