![]() |
Home page |
Mailing list |
Docs
Asterisk developer's documentation :: Codename Pineapple
rtp.h
Go to the documentation of this file.
00001 /* 00002 * Asterisk -- An open source telephony toolkit. 00003 * 00004 * Copyright (C) 1999 - 2006, Digium, Inc. 00005 * 00006 * Mark Spencer <markster@digium.com> 00007 * 00008 * See http://www.asterisk.org for more information about 00009 * the Asterisk project. Please do not directly contact 00010 * any of the maintainers of this project for assistance; 00011 * the project provides a web site, mailing lists and IRC 00012 * channels for your use. 00013 * 00014 * This program is free software, distributed under the terms of 00015 * the GNU General Public License Version 2. See the LICENSE file 00016 * at the top of the source tree. 00017 */ 00018 00019 /*! 00020 * \file rtp.h 00021 * \brief Supports RTP and RTCP with Symmetric RTP support for NAT traversal. 00022 * 00023 * RTP is defined in RFC 3550. 00024 */ 00025 00026 #ifndef _ASTERISK_RTP_H 00027 #define _ASTERISK_RTP_H 00028 00029 #include <netinet/in.h> 00030 00031 #include "asterisk/frame.h" 00032 #include "asterisk/io.h" 00033 #include "asterisk/sched.h" 00034 #include "asterisk/channel.h" 00035 #include "asterisk/linkedlists.h" 00036 00037 #if defined(__cplusplus) || defined(c_plusplus) 00038 extern "C" { 00039 #endif 00040 00041 /* Codes for RTP-specific data - not defined by our AST_FORMAT codes */ 00042 /*! DTMF (RFC2833) */ 00043 #define AST_RTP_DTMF (1 << 0) 00044 /*! 'Comfort Noise' (RFC3389) */ 00045 #define AST_RTP_CN (1 << 1) 00046 /*! DTMF (Cisco Proprietary) */ 00047 #define AST_RTP_CISCO_DTMF (1 << 2) 00048 /*! Maximum RTP-specific code */ 00049 #define AST_RTP_MAX AST_RTP_CISCO_DTMF 00050 00051 /*! Maxmum number of payload defintions for a RTP session */ 00052 #define MAX_RTP_PT 256 00053 00054 #define FLAG_3389_WARNING (1 << 0) 00055 00056 enum ast_rtp_options { 00057 AST_RTP_OPT_G726_NONSTANDARD = (1 << 0), 00058 }; 00059 00060 enum ast_rtp_get_result { 00061 /*! Failed to find the RTP structure */ 00062 AST_RTP_GET_FAILED = 0, 00063 /*! RTP structure exists but true native bridge can not occur so try partial */ 00064 AST_RTP_TRY_PARTIAL, 00065 /*! RTP structure exists and native bridge can occur */ 00066 AST_RTP_TRY_NATIVE, 00067 }; 00068 00069 struct ast_rtp; 00070 00071 /*! \brief This is the structure that binds a channel (SIP/Jingle/H.323) to the RTP subsystem 00072 */ 00073 struct ast_rtp_protocol { 00074 /*! Get RTP struct, or NULL if unwilling to transfer */ 00075 enum ast_rtp_get_result (* const get_rtp_info)(struct ast_channel *chan, struct ast_rtp **rtp); 00076 /*! Get RTP struct, or NULL if unwilling to transfer */ 00077 enum ast_rtp_get_result (* const get_vrtp_info)(struct ast_channel *chan, struct ast_rtp **rtp); 00078 /*! Set RTP peer */ 00079 int (* const set_rtp_peer)(struct ast_channel *chan, struct ast_rtp *peer, struct ast_rtp *vpeer, int codecs, int nat_active); 00080 int (* const get_codec)(struct ast_channel *chan); 00081 const char * const type; 00082 AST_LIST_ENTRY(ast_rtp_protocol) list; 00083 }; 00084 00085 00086 /*! RTP callback structure */ 00087 typedef int (*ast_rtp_callback)(struct ast_rtp *rtp, struct ast_frame *f, void *data); 00088 00089 /*! 00090 * \brief Get the amount of space required to hold an RTP session 00091 * \return number of bytes required 00092 */ 00093 size_t ast_rtp_alloc_size(void); 00094 00095 /*! 00096 * \brief Initializate a RTP session. 00097 * 00098 * \param sched 00099 * \param io 00100 * \param rtcpenable 00101 * \param callbackmode 00102 * \returns A representation (structure) of an RTP session. 00103 */ 00104 struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode); 00105 00106 /*! 00107 * \brief Initializate a RTP session using an in_addr structure. 00108 * 00109 * This fuction gets called by ast_rtp_new(). 00110 * 00111 * \param sched 00112 * \param io 00113 * \param rtcpenable 00114 * \param callbackmode 00115 * \param in 00116 * \returns A representation (structure) of an RTP session. 00117 */ 00118 struct ast_rtp *ast_rtp_new_with_bindaddr(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode, struct in_addr in); 00119 00120 void ast_rtp_set_peer(struct ast_rtp *rtp, struct sockaddr_in *them); 00121 00122 /* Copies from rtp to them and returns 1 if there was a change or 0 if it was already the same */ 00123 int ast_rtp_get_peer(struct ast_rtp *rtp, struct sockaddr_in *them); 00124 00125 void ast_rtp_get_us(struct ast_rtp *rtp, struct sockaddr_in *us); 00126 00127 struct ast_rtp *ast_rtp_get_bridged(struct ast_rtp *rtp); 00128 00129 /*! Destroy RTP session */ 00130 void ast_rtp_destroy(struct ast_rtp *rtp); 00131 00132 void ast_rtp_reset(struct ast_rtp *rtp); 00133 00134 /*! Stop RTP session, do not destroy structure */ 00135 void ast_rtp_stop(struct ast_rtp *rtp); 00136 00137 void ast_rtp_set_callback(struct ast_rtp *rtp, ast_rtp_callback callback); 00138 00139 void ast_rtp_set_data(struct ast_rtp *rtp, void *data); 00140 00141 int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *f); 00142 00143 struct ast_frame *ast_rtp_read(struct ast_rtp *rtp); 00144 00145 struct ast_frame *ast_rtcp_read(struct ast_rtp *rtp); 00146 00147 int ast_rtp_fd(struct ast_rtp *rtp); 00148 00149 int ast_rtcp_fd(struct ast_rtp *rtp); 00150 00151 int ast_rtp_senddigit_begin(struct ast_rtp *rtp, char digit); 00152 00153 int ast_rtp_senddigit_end(struct ast_rtp *rtp, char digit); 00154 00155 int ast_rtp_sendcng(struct ast_rtp *rtp, int level); 00156 00157 int ast_rtp_settos(struct ast_rtp *rtp, int tos); 00158 00159 /*! \brief Setting RTP payload types from lines in a SDP description: */ 00160 void ast_rtp_pt_clear(struct ast_rtp* rtp); 00161 /*! \brief Set payload types to defaults */ 00162 void ast_rtp_pt_default(struct ast_rtp* rtp); 00163 00164 /*! \brief Copy payload types between RTP structures */ 00165 void ast_rtp_pt_copy(struct ast_rtp *dest, struct ast_rtp *src); 00166 00167 void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt); 00168 void ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt, 00169 char *mimeType, char *mimeSubtype, 00170 enum ast_rtp_options options); 00171 00172 /*! \brief Mapping between RTP payload format codes and Asterisk codes: */ 00173 struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt); 00174 int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code); 00175 00176 void ast_rtp_get_current_formats(struct ast_rtp* rtp, 00177 int* astFormats, int* nonAstFormats); 00178 00179 /*! \brief Mapping an Asterisk code into a MIME subtype (string): */ 00180 const char *ast_rtp_lookup_mime_subtype(int isAstFormat, int code, 00181 enum ast_rtp_options options); 00182 00183 /*! \brief Build a string of MIME subtype names from a capability list */ 00184 char *ast_rtp_lookup_mime_multiple(char *buf, size_t size, const int capability, 00185 const int isAstFormat, enum ast_rtp_options options); 00186 00187 void ast_rtp_setnat(struct ast_rtp *rtp, int nat); 00188 00189 int ast_rtp_getnat(struct ast_rtp *rtp); 00190 00191 /*! \brief Indicate whether this RTP session is carrying DTMF or not */ 00192 void ast_rtp_setdtmf(struct ast_rtp *rtp, int dtmf); 00193 00194 /*! \brief Compensate for devices that send RFC2833 packets all at once */ 00195 void ast_rtp_setdtmfcompensate(struct ast_rtp *rtp, int compensate); 00196 00197 /*! \brief Enable STUN capability */ 00198 void ast_rtp_setstun(struct ast_rtp *rtp, int stun_enable); 00199 00200 /*! \brief Send STUN request (??) */ 00201 void ast_rtp_stun_request(struct ast_rtp *rtp, struct sockaddr_in *suggestion, const char *username); 00202 00203 /*! \brief The RTP bridge. 00204 \arg \ref AstRTPbridge 00205 */ 00206 int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms); 00207 00208 /*! \brief Register an RTP channel client */ 00209 int ast_rtp_proto_register(struct ast_rtp_protocol *proto); 00210 00211 /*! \brief Unregister an RTP channel client */ 00212 void ast_rtp_proto_unregister(struct ast_rtp_protocol *proto); 00213 00214 int ast_rtp_make_compatible(struct ast_channel *dest, struct ast_channel *src, int media); 00215 00216 /*! \brief If possible, create an early bridge directly between the devices without 00217 having to send a re-invite later */ 00218 int ast_rtp_early_bridge(struct ast_channel *c0, struct ast_channel *c1); 00219 00220 00221 00222 /*! \brief Send an H.261 fast update request. Some devices need this rather than the XML message in SIP */ 00223 int ast_rtcp_send_h261fur(void *data); 00224 00225 char *ast_rtp_get_quality(struct ast_rtp *rtp); /*! \brief Return RTCP quality string */ 00226 void ast_rtp_init(void); /*! Initialize RTP subsystem */ 00227 int ast_rtp_reload(void); /*! reload rtp configuration */ 00228 void ast_rtp_new_init(struct ast_rtp *rtp); 00229 00230 /*! Set codec preference */ 00231 int ast_rtp_codec_setpref(struct ast_rtp *rtp, struct ast_codec_pref *prefs); 00232 00233 /*! Get codec preference */ 00234 struct ast_codec_pref *ast_rtp_codec_getpref(struct ast_rtp *rtp); 00235 00236 /*! get format from predefined dynamic payload format */ 00237 int ast_rtp_codec_getformat(int pt); 00238 00239 /*! \brief Set rtp timeout */ 00240 void ast_rtp_set_rtptimeout(struct ast_rtp *rtp, int timeout); 00241 /*! \brief Set rtp hold timeout */ 00242 void ast_rtp_set_rtpholdtimeout(struct ast_rtp *rtp, int timeout); 00243 /*! \brief set RTP keepalive interval */ 00244 void ast_rtp_set_rtpkeepalive(struct ast_rtp *rtp, int period); 00245 /*! \brief Get RTP keepalive interval */ 00246 int ast_rtp_get_rtpkeepalive(struct ast_rtp *rtp); 00247 /*! \brief Get rtp hold timeout */ 00248 int ast_rtp_get_rtpholdtimeout(struct ast_rtp *rtp); 00249 /*! \brief Get rtp timeout */ 00250 int ast_rtp_get_rtptimeout(struct ast_rtp *rtp); 00251 /* \brief Put RTP timeout timers on hold during another transaction, like T.38 */ 00252 void ast_rtp_set_rtptimers_onhold(struct ast_rtp *rtp); 00253 00254 #if defined(__cplusplus) || defined(c_plusplus) 00255 } 00256 #endif 00257 00258 #endif /* _ASTERISK_RTP_H */