00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
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
00042
00043 #define AST_RTP_DTMF (1 << 0)
00044
00045 #define AST_RTP_CN (1 << 1)
00046
00047 #define AST_RTP_CISCO_DTMF (1 << 2)
00048
00049 #define AST_RTP_MAX AST_RTP_CISCO_DTMF
00050
00051 #define MAX_RTP_PT 256
00052
00053 enum ast_rtp_options {
00054 AST_RTP_OPT_G726_NONSTANDARD = (1 << 0),
00055 };
00056
00057 enum ast_rtp_get_result {
00058
00059 AST_RTP_GET_FAILED = 0,
00060
00061 AST_RTP_TRY_PARTIAL,
00062
00063 AST_RTP_TRY_NATIVE,
00064 };
00065
00066 struct ast_rtp;
00067
00068 struct ast_rtp_protocol {
00069
00070 enum ast_rtp_get_result (* const get_rtp_info)(struct ast_channel *chan, struct ast_rtp **rtp);
00071
00072 enum ast_rtp_get_result (* const get_vrtp_info)(struct ast_channel *chan, struct ast_rtp **rtp);
00073
00074 int (* const set_rtp_peer)(struct ast_channel *chan, struct ast_rtp *peer, struct ast_rtp *vpeer, int codecs, int nat_active);
00075 int (* const get_codec)(struct ast_channel *chan);
00076 const char * const type;
00077 AST_LIST_ENTRY(ast_rtp_protocol) list;
00078 };
00079
00080 struct ast_rtp_quality {
00081 unsigned int local_ssrc;
00082 unsigned int local_lostpackets;
00083 double local_jitter;
00084 unsigned int local_count;
00085 unsigned int remote_ssrc;
00086 unsigned int remote_lostpackets;
00087 double remote_jitter;
00088 unsigned int remote_count;
00089 double rtt;
00090 };
00091
00092
00093 #define FLAG_3389_WARNING (1 << 0)
00094
00095 typedef int (*ast_rtp_callback)(struct ast_rtp *rtp, struct ast_frame *f, void *data);
00096
00097
00098
00099
00100
00101 size_t ast_rtp_alloc_size(void);
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode);
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 struct ast_rtp *ast_rtp_new_with_bindaddr(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode, struct in_addr in);
00127
00128 void ast_rtp_set_peer(struct ast_rtp *rtp, struct sockaddr_in *them);
00129
00130
00131 int ast_rtp_get_peer(struct ast_rtp *rtp, struct sockaddr_in *them);
00132
00133 void ast_rtp_get_us(struct ast_rtp *rtp, struct sockaddr_in *us);
00134
00135 struct ast_rtp *ast_rtp_get_bridged(struct ast_rtp *rtp);
00136
00137 void ast_rtp_destroy(struct ast_rtp *rtp);
00138
00139 void ast_rtp_reset(struct ast_rtp *rtp);
00140
00141 void ast_rtp_stun_request(struct ast_rtp *rtp, struct sockaddr_in *suggestion, const char *username);
00142
00143 void ast_rtp_set_callback(struct ast_rtp *rtp, ast_rtp_callback callback);
00144
00145 void ast_rtp_set_data(struct ast_rtp *rtp, void *data);
00146
00147 int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *f);
00148
00149 struct ast_frame *ast_rtp_read(struct ast_rtp *rtp);
00150
00151 struct ast_frame *ast_rtcp_read(struct ast_rtp *rtp);
00152
00153 int ast_rtp_fd(struct ast_rtp *rtp);
00154
00155 int ast_rtcp_fd(struct ast_rtp *rtp);
00156
00157 int ast_rtp_senddigit_begin(struct ast_rtp *rtp, char digit);
00158
00159 int ast_rtp_senddigit_end(struct ast_rtp *rtp, char digit);
00160
00161 int ast_rtp_sendcng(struct ast_rtp *rtp, int level);
00162
00163 int ast_rtp_settos(struct ast_rtp *rtp, int tos);
00164
00165
00166 void ast_rtp_pt_clear(struct ast_rtp* rtp);
00167
00168 void ast_rtp_pt_default(struct ast_rtp* rtp);
00169
00170
00171 void ast_rtp_pt_copy(struct ast_rtp *dest, struct ast_rtp *src);
00172
00173
00174 void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt);
00175
00176
00177 void ast_rtp_unset_m_type(struct ast_rtp* rtp, int pt);
00178
00179
00180 int ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
00181 char *mimeType, char *mimeSubtype,
00182 enum ast_rtp_options options);
00183
00184
00185 struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt);
00186 int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code);
00187
00188 void ast_rtp_get_current_formats(struct ast_rtp* rtp,
00189 int* astFormats, int* nonAstFormats);
00190
00191
00192 const char *ast_rtp_lookup_mime_subtype(int isAstFormat, int code,
00193 enum ast_rtp_options options);
00194
00195
00196 char *ast_rtp_lookup_mime_multiple(char *buf, size_t size, const int capability,
00197 const int isAstFormat, enum ast_rtp_options options);
00198
00199 void ast_rtp_setnat(struct ast_rtp *rtp, int nat);
00200
00201 int ast_rtp_getnat(struct ast_rtp *rtp);
00202
00203
00204 void ast_rtp_setdtmf(struct ast_rtp *rtp, int dtmf);
00205
00206
00207 void ast_rtp_setdtmfcompensate(struct ast_rtp *rtp, int compensate);
00208
00209
00210 void ast_rtp_setstun(struct ast_rtp *rtp, int stun_enable);
00211
00212 int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
00213
00214 int ast_rtp_proto_register(struct ast_rtp_protocol *proto);
00215
00216 void ast_rtp_proto_unregister(struct ast_rtp_protocol *proto);
00217
00218 int ast_rtp_make_compatible(struct ast_channel *dest, struct ast_channel *src, int media);
00219
00220
00221
00222 int ast_rtp_early_bridge(struct ast_channel *dest, struct ast_channel *src);
00223
00224 void ast_rtp_stop(struct ast_rtp *rtp);
00225
00226
00227 char *ast_rtp_get_quality(struct ast_rtp *rtp, struct ast_rtp_quality *qual);
00228
00229
00230 int ast_rtcp_send_h261fur(void *data);
00231
00232 void ast_rtp_new_init(struct ast_rtp *rtp);
00233
00234 void ast_rtp_init(void);
00235
00236 int ast_rtp_reload(void);
00237
00238 int ast_rtp_codec_setpref(struct ast_rtp *rtp, struct ast_codec_pref *prefs);
00239
00240 struct ast_codec_pref *ast_rtp_codec_getpref(struct ast_rtp *rtp);
00241
00242 int ast_rtp_codec_getformat(int pt);
00243
00244
00245 void ast_rtp_set_rtptimeout(struct ast_rtp *rtp, int timeout);
00246
00247 void ast_rtp_set_rtpholdtimeout(struct ast_rtp *rtp, int timeout);
00248
00249 void ast_rtp_set_rtpkeepalive(struct ast_rtp *rtp, int period);
00250
00251 int ast_rtp_get_rtpkeepalive(struct ast_rtp *rtp);
00252
00253 int ast_rtp_get_rtpholdtimeout(struct ast_rtp *rtp);
00254
00255 int ast_rtp_get_rtptimeout(struct ast_rtp *rtp);
00256
00257 void ast_rtp_set_rtptimers_onhold(struct ast_rtp *rtp);
00258
00259 #if defined(__cplusplus) || defined(c_plusplus)
00260 }
00261 #endif
00262
00263 #endif