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 "asterisk/network.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
00052 #define MAX_RTP_PT 256
00053
00054
00055 #define RED_MAX_GENERATION 5
00056
00057 #define FLAG_3389_WARNING (1 << 0)
00058
00059 enum ast_rtp_options {
00060 AST_RTP_OPT_G726_NONSTANDARD = (1 << 0),
00061 };
00062
00063 enum ast_rtp_get_result {
00064
00065 AST_RTP_GET_FAILED = 0,
00066
00067 AST_RTP_TRY_PARTIAL,
00068
00069 AST_RTP_TRY_NATIVE,
00070 };
00071
00072
00073 enum ast_rtp_qos_vars {
00074 AST_RTP_TXCOUNT,
00075 AST_RTP_RXCOUNT,
00076 AST_RTP_TXJITTER,
00077 AST_RTP_RXJITTER,
00078 AST_RTP_RXPLOSS,
00079 AST_RTP_TXPLOSS,
00080 AST_RTP_RTT
00081 };
00082
00083 struct ast_rtp;
00084
00085 struct rtp_red;
00086
00087
00088
00089 struct ast_rtp_protocol {
00090
00091 enum ast_rtp_get_result (* const get_rtp_info)(struct ast_channel *chan, struct ast_rtp **rtp);
00092
00093 enum ast_rtp_get_result (* const get_vrtp_info)(struct ast_channel *chan, struct ast_rtp **rtp);
00094
00095 enum ast_rtp_get_result (* const get_trtp_info)(struct ast_channel *chan, struct ast_rtp **rtp);
00096
00097 int (* const set_rtp_peer)(struct ast_channel *chan, struct ast_rtp *peer, struct ast_rtp *vpeer, struct ast_rtp *tpeer, int codecs, int nat_active);
00098 int (* const get_codec)(struct ast_channel *chan);
00099 const char * const type;
00100 AST_LIST_ENTRY(ast_rtp_protocol) list;
00101 };
00102
00103 enum ast_rtp_quality_type {
00104 RTPQOS_SUMMARY = 0,
00105 RTPQOS_JITTER,
00106 RTPQOS_LOSS,
00107 RTPQOS_RTT
00108 };
00109
00110
00111 struct ast_rtp_quality {
00112 unsigned int local_ssrc;
00113 unsigned int local_lostpackets;
00114 double local_jitter;
00115 unsigned int local_count;
00116 unsigned int remote_ssrc;
00117 unsigned int remote_lostpackets;
00118 double remote_jitter;
00119 unsigned int remote_count;
00120 double rtt;
00121 };
00122
00123
00124 typedef int (*ast_rtp_callback)(struct ast_rtp *rtp, struct ast_frame *f, void *data);
00125
00126
00127
00128
00129
00130 size_t ast_rtp_alloc_size(void);
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141 struct ast_rtp *ast_rtp_new(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode);
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 struct ast_rtp *ast_rtp_new_with_bindaddr(struct sched_context *sched, struct io_context *io, int rtcpenable, int callbackmode, struct in_addr in);
00156
00157 void ast_rtp_set_peer(struct ast_rtp *rtp, struct sockaddr_in *them);
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174 void ast_rtp_set_alt_peer(struct ast_rtp *rtp, struct sockaddr_in *alt);
00175
00176
00177 int ast_rtp_get_peer(struct ast_rtp *rtp, struct sockaddr_in *them);
00178
00179 void ast_rtp_get_us(struct ast_rtp *rtp, struct sockaddr_in *us);
00180
00181 struct ast_rtp *ast_rtp_get_bridged(struct ast_rtp *rtp);
00182
00183
00184 void ast_rtp_destroy(struct ast_rtp *rtp);
00185
00186 void ast_rtp_reset(struct ast_rtp *rtp);
00187
00188
00189 void ast_rtp_stop(struct ast_rtp *rtp);
00190
00191 void ast_rtp_set_callback(struct ast_rtp *rtp, ast_rtp_callback callback);
00192
00193 void ast_rtp_set_data(struct ast_rtp *rtp, void *data);
00194
00195 int ast_rtp_write(struct ast_rtp *rtp, struct ast_frame *f);
00196
00197 struct ast_frame *ast_rtp_read(struct ast_rtp *rtp);
00198
00199 struct ast_frame *ast_rtcp_read(struct ast_rtp *rtp);
00200
00201 int ast_rtp_fd(struct ast_rtp *rtp);
00202
00203 int ast_rtcp_fd(struct ast_rtp *rtp);
00204
00205 int ast_rtp_senddigit_begin(struct ast_rtp *rtp, char digit);
00206
00207 int ast_rtp_senddigit_end(struct ast_rtp *rtp, char digit);
00208
00209 int ast_rtp_sendcng(struct ast_rtp *rtp, int level);
00210
00211 int ast_rtp_setqos(struct ast_rtp *rtp, int tos, int cos, char *desc);
00212
00213
00214 void ast_rtp_new_source(struct ast_rtp *rtp);
00215
00216
00217 void ast_rtp_change_source(struct ast_rtp *rtp);
00218
00219
00220 void ast_rtp_pt_clear(struct ast_rtp* rtp);
00221
00222 void ast_rtp_pt_default(struct ast_rtp* rtp);
00223
00224
00225 void ast_rtp_pt_copy(struct ast_rtp *dest, struct ast_rtp *src);
00226
00227
00228 void ast_rtp_set_m_type(struct ast_rtp* rtp, int pt);
00229
00230
00231 void ast_rtp_unset_m_type(struct ast_rtp* rtp, int pt);
00232
00233
00234 int ast_rtp_set_rtpmap_type(struct ast_rtp* rtp, int pt,
00235 char *mimeType, char *mimeSubtype,
00236 enum ast_rtp_options options);
00237
00238
00239 struct rtpPayloadType ast_rtp_lookup_pt(struct ast_rtp* rtp, int pt);
00240 int ast_rtp_lookup_code(struct ast_rtp* rtp, int isAstFormat, int code);
00241
00242 void ast_rtp_get_current_formats(struct ast_rtp* rtp,
00243 int* astFormats, int* nonAstFormats);
00244
00245
00246 const char *ast_rtp_lookup_mime_subtype(int isAstFormat, int code,
00247 enum ast_rtp_options options);
00248
00249
00250 char *ast_rtp_lookup_mime_multiple(char *buf, size_t size, const int capability,
00251 const int isAstFormat, enum ast_rtp_options options);
00252
00253 void ast_rtp_setnat(struct ast_rtp *rtp, int nat);
00254
00255 int ast_rtp_getnat(struct ast_rtp *rtp);
00256
00257
00258 void ast_rtp_setdtmf(struct ast_rtp *rtp, int dtmf);
00259
00260
00261 void ast_rtp_setdtmfcompensate(struct ast_rtp *rtp, int compensate);
00262
00263
00264 void ast_rtp_setstun(struct ast_rtp *rtp, int stun_enable);
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276 int ast_stun_request(int s, struct sockaddr_in *dst,
00277 const char *username, struct sockaddr_in *answer);
00278
00279
00280
00281
00282 void ast_rtp_stun_request(struct ast_rtp *rtp, struct sockaddr_in *suggestion, const char *username);
00283
00284
00285
00286
00287 int ast_rtp_bridge(struct ast_channel *c0, struct ast_channel *c1, int flags, struct ast_frame **fo, struct ast_channel **rc, int timeoutms);
00288
00289
00290 int ast_rtp_proto_register(struct ast_rtp_protocol *proto);
00291
00292
00293 void ast_rtp_proto_unregister(struct ast_rtp_protocol *proto);
00294
00295 int ast_rtp_make_compatible(struct ast_channel *dest, struct ast_channel *src, int media);
00296
00297
00298
00299 int ast_rtp_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
00300
00301
00302
00303
00304 int ast_rtp_get_qos(struct ast_rtp *rtp, const char *qos, char *buf, unsigned int buflen);
00305
00306
00307
00308
00309 unsigned int ast_rtp_get_qosvalue(struct ast_rtp *rtp, enum ast_rtp_qos_vars value);
00310
00311
00312
00313
00314 void ast_rtp_set_vars(struct ast_channel *chan, struct ast_rtp *rtp);
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337 char *ast_rtp_get_quality(struct ast_rtp *rtp, struct ast_rtp_quality *qual, enum ast_rtp_quality_type qtype);
00338
00339 int ast_rtcp_send_h261fur(void *data);
00340
00341 void ast_rtp_init(void);
00342 int ast_rtp_reload(void);
00343 void ast_rtp_new_init(struct ast_rtp *rtp);
00344
00345
00346 void ast_rtp_codec_setpref(struct ast_rtp *rtp, struct ast_codec_pref *prefs);
00347
00348
00349 struct ast_codec_pref *ast_rtp_codec_getpref(struct ast_rtp *rtp);
00350
00351
00352 int ast_rtp_codec_getformat(int pt);
00353
00354
00355 void ast_rtp_set_rtptimeout(struct ast_rtp *rtp, int timeout);
00356
00357 void ast_rtp_set_rtpholdtimeout(struct ast_rtp *rtp, int timeout);
00358
00359 void ast_rtp_set_rtpkeepalive(struct ast_rtp *rtp, int period);
00360
00361 int ast_rtp_get_rtpkeepalive(struct ast_rtp *rtp);
00362
00363 int ast_rtp_get_rtpholdtimeout(struct ast_rtp *rtp);
00364
00365 int ast_rtp_get_rtptimeout(struct ast_rtp *rtp);
00366
00367 void ast_rtp_set_rtptimers_onhold(struct ast_rtp *rtp);
00368
00369
00370
00371
00372
00373
00374
00375
00376 int rtp_red_init(struct ast_rtp *rtp, int ti, int *pt, int num_gen);
00377
00378
00379 void red_buffer_t140(struct ast_rtp *rtp, struct ast_frame *f);
00380
00381
00382
00383 #if defined(__cplusplus) || defined(c_plusplus)
00384 }
00385 #endif
00386
00387 #endif