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 #include "asterisk.h"
00027
00028 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 366408 $")
00029
00030 #include <math.h>
00031
00032 #include "asterisk/channel.h"
00033 #include "asterisk/frame.h"
00034 #include "asterisk/module.h"
00035 #include "asterisk/rtp_engine.h"
00036 #include "asterisk/manager.h"
00037 #include "asterisk/options.h"
00038 #include "asterisk/astobj2.h"
00039 #include "asterisk/pbx.h"
00040 #include "asterisk/translate.h"
00041 #include "asterisk/netsock2.h"
00042 #include "asterisk/_private.h"
00043 #include "asterisk/framehook.h"
00044
00045 struct ast_srtp_res *res_srtp = NULL;
00046 struct ast_srtp_policy_res *res_srtp_policy = NULL;
00047
00048
00049 struct ast_rtp_instance {
00050
00051 struct ast_rtp_engine *engine;
00052
00053 void *data;
00054
00055 int properties[AST_RTP_PROPERTY_MAX];
00056
00057 struct ast_sockaddr local_address;
00058
00059 struct ast_sockaddr remote_address;
00060
00061 struct ast_sockaddr alt_remote_address;
00062
00063 struct ast_rtp_instance *bridged;
00064
00065 struct ast_rtp_codecs codecs;
00066
00067 int timeout;
00068
00069 int holdtimeout;
00070
00071 int keepalive;
00072
00073 struct ast_rtp_glue *glue;
00074
00075 struct ast_channel *chan;
00076
00077 struct ast_srtp *srtp;
00078 };
00079
00080
00081 static AST_RWLIST_HEAD_STATIC(engines, ast_rtp_engine);
00082
00083
00084 static AST_RWLIST_HEAD_STATIC(glues, ast_rtp_glue);
00085
00086
00087
00088 static struct ast_rtp_mime_type {
00089 struct ast_rtp_payload_type payload_type;
00090 char *type;
00091 char *subtype;
00092 unsigned int sample_rate;
00093 } ast_rtp_mime_types[128];
00094 static ast_rwlock_t mime_types_lock;
00095 static int mime_types_len = 0;
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107 static struct ast_rtp_payload_type static_RTP_PT[AST_RTP_MAX_PT];
00108 static ast_rwlock_t static_RTP_PT_lock;
00109
00110 int ast_rtp_engine_register2(struct ast_rtp_engine *engine, struct ast_module *module)
00111 {
00112 struct ast_rtp_engine *current_engine;
00113
00114
00115 if (ast_strlen_zero(engine->name) || !engine->new || !engine->destroy || !engine->write || !engine->read) {
00116 ast_log(LOG_WARNING, "RTP Engine '%s' failed sanity check so it was not registered.\n", !ast_strlen_zero(engine->name) ? engine->name : "Unknown");
00117 return -1;
00118 }
00119
00120
00121 engine->mod = module;
00122
00123 AST_RWLIST_WRLOCK(&engines);
00124
00125
00126 AST_RWLIST_TRAVERSE(&engines, current_engine, entry) {
00127 if (!strcmp(current_engine->name, engine->name)) {
00128 ast_log(LOG_WARNING, "An RTP engine with the name '%s' has already been registered.\n", engine->name);
00129 AST_RWLIST_UNLOCK(&engines);
00130 return -1;
00131 }
00132 }
00133
00134
00135 AST_RWLIST_INSERT_TAIL(&engines, engine, entry);
00136
00137 AST_RWLIST_UNLOCK(&engines);
00138
00139 ast_verb(2, "Registered RTP engine '%s'\n", engine->name);
00140
00141 return 0;
00142 }
00143
00144 int ast_rtp_engine_unregister(struct ast_rtp_engine *engine)
00145 {
00146 struct ast_rtp_engine *current_engine = NULL;
00147
00148 AST_RWLIST_WRLOCK(&engines);
00149
00150 if ((current_engine = AST_RWLIST_REMOVE(&engines, engine, entry))) {
00151 ast_verb(2, "Unregistered RTP engine '%s'\n", engine->name);
00152 }
00153
00154 AST_RWLIST_UNLOCK(&engines);
00155
00156 return current_engine ? 0 : -1;
00157 }
00158
00159 int ast_rtp_glue_register2(struct ast_rtp_glue *glue, struct ast_module *module)
00160 {
00161 struct ast_rtp_glue *current_glue = NULL;
00162
00163 if (ast_strlen_zero(glue->type)) {
00164 return -1;
00165 }
00166
00167 glue->mod = module;
00168
00169 AST_RWLIST_WRLOCK(&glues);
00170
00171 AST_RWLIST_TRAVERSE(&glues, current_glue, entry) {
00172 if (!strcasecmp(current_glue->type, glue->type)) {
00173 ast_log(LOG_WARNING, "RTP glue with the name '%s' has already been registered.\n", glue->type);
00174 AST_RWLIST_UNLOCK(&glues);
00175 return -1;
00176 }
00177 }
00178
00179 AST_RWLIST_INSERT_TAIL(&glues, glue, entry);
00180
00181 AST_RWLIST_UNLOCK(&glues);
00182
00183 ast_verb(2, "Registered RTP glue '%s'\n", glue->type);
00184
00185 return 0;
00186 }
00187
00188 int ast_rtp_glue_unregister(struct ast_rtp_glue *glue)
00189 {
00190 struct ast_rtp_glue *current_glue = NULL;
00191
00192 AST_RWLIST_WRLOCK(&glues);
00193
00194 if ((current_glue = AST_RWLIST_REMOVE(&glues, glue, entry))) {
00195 ast_verb(2, "Unregistered RTP glue '%s'\n", glue->type);
00196 }
00197
00198 AST_RWLIST_UNLOCK(&glues);
00199
00200 return current_glue ? 0 : -1;
00201 }
00202
00203 static void instance_destructor(void *obj)
00204 {
00205 struct ast_rtp_instance *instance = obj;
00206
00207
00208 if (instance->data && instance->engine->destroy(instance)) {
00209 ast_debug(1, "Engine '%s' failed to destroy RTP instance '%p'\n", instance->engine->name, instance);
00210 return;
00211 }
00212
00213 if (instance->srtp) {
00214 res_srtp->destroy(instance->srtp);
00215 }
00216
00217
00218 ast_module_unref(instance->engine->mod);
00219
00220 ast_debug(1, "Destroyed RTP instance '%p'\n", instance);
00221 }
00222
00223 int ast_rtp_instance_destroy(struct ast_rtp_instance *instance)
00224 {
00225 ao2_ref(instance, -1);
00226
00227 return 0;
00228 }
00229
00230 struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name,
00231 struct ast_sched_context *sched, const struct ast_sockaddr *sa,
00232 void *data)
00233 {
00234 struct ast_sockaddr address = {{0,}};
00235 struct ast_rtp_instance *instance = NULL;
00236 struct ast_rtp_engine *engine = NULL;
00237
00238 AST_RWLIST_RDLOCK(&engines);
00239
00240
00241 if (!ast_strlen_zero(engine_name)) {
00242 AST_RWLIST_TRAVERSE(&engines, engine, entry) {
00243 if (!strcmp(engine->name, engine_name)) {
00244 break;
00245 }
00246 }
00247 } else {
00248 engine = AST_RWLIST_FIRST(&engines);
00249 }
00250
00251
00252 if (!engine) {
00253 ast_log(LOG_ERROR, "No RTP engine was found. Do you have one loaded?\n");
00254 AST_RWLIST_UNLOCK(&engines);
00255 return NULL;
00256 }
00257
00258
00259 ast_module_ref(engine->mod);
00260
00261 AST_RWLIST_UNLOCK(&engines);
00262
00263
00264 if (!(instance = ao2_alloc(sizeof(*instance), instance_destructor))) {
00265 ast_module_unref(engine->mod);
00266 return NULL;
00267 }
00268 instance->engine = engine;
00269 ast_sockaddr_copy(&instance->local_address, sa);
00270 ast_sockaddr_copy(&address, sa);
00271
00272 ast_debug(1, "Using engine '%s' for RTP instance '%p'\n", engine->name, instance);
00273
00274
00275 if (instance->engine->new(instance, sched, &address, data)) {
00276 ast_debug(1, "Engine '%s' failed to setup RTP instance '%p'\n", engine->name, instance);
00277 ao2_ref(instance, -1);
00278 return NULL;
00279 }
00280
00281 ast_debug(1, "RTP instance '%p' is setup and ready to go\n", instance);
00282
00283 return instance;
00284 }
00285
00286 void ast_rtp_instance_set_data(struct ast_rtp_instance *instance, void *data)
00287 {
00288 instance->data = data;
00289 }
00290
00291 void *ast_rtp_instance_get_data(struct ast_rtp_instance *instance)
00292 {
00293 return instance->data;
00294 }
00295
00296 int ast_rtp_instance_write(struct ast_rtp_instance *instance, struct ast_frame *frame)
00297 {
00298 return instance->engine->write(instance, frame);
00299 }
00300
00301 struct ast_frame *ast_rtp_instance_read(struct ast_rtp_instance *instance, int rtcp)
00302 {
00303 return instance->engine->read(instance, rtcp);
00304 }
00305
00306 int ast_rtp_instance_set_local_address(struct ast_rtp_instance *instance,
00307 const struct ast_sockaddr *address)
00308 {
00309 ast_sockaddr_copy(&instance->local_address, address);
00310 return 0;
00311 }
00312
00313 int ast_rtp_instance_set_remote_address(struct ast_rtp_instance *instance,
00314 const struct ast_sockaddr *address)
00315 {
00316 ast_sockaddr_copy(&instance->remote_address, address);
00317
00318
00319
00320 if (instance->engine->remote_address_set) {
00321 instance->engine->remote_address_set(instance, &instance->remote_address);
00322 }
00323
00324 return 0;
00325 }
00326
00327 int ast_rtp_instance_set_alt_remote_address(struct ast_rtp_instance *instance,
00328 const struct ast_sockaddr *address)
00329 {
00330 ast_sockaddr_copy(&instance->alt_remote_address, address);
00331
00332
00333
00334 if (instance->engine->alt_remote_address_set) {
00335 instance->engine->alt_remote_address_set(instance, &instance->alt_remote_address);
00336 }
00337
00338 return 0;
00339 }
00340
00341 int ast_rtp_instance_get_and_cmp_local_address(struct ast_rtp_instance *instance,
00342 struct ast_sockaddr *address)
00343 {
00344 if (ast_sockaddr_cmp(address, &instance->local_address) != 0) {
00345 ast_sockaddr_copy(address, &instance->local_address);
00346 return 1;
00347 }
00348
00349 return 0;
00350 }
00351
00352 void ast_rtp_instance_get_local_address(struct ast_rtp_instance *instance,
00353 struct ast_sockaddr *address)
00354 {
00355 ast_sockaddr_copy(address, &instance->local_address);
00356 }
00357
00358 int ast_rtp_instance_get_and_cmp_remote_address(struct ast_rtp_instance *instance,
00359 struct ast_sockaddr *address)
00360 {
00361 if (ast_sockaddr_cmp(address, &instance->remote_address) != 0) {
00362 ast_sockaddr_copy(address, &instance->remote_address);
00363 return 1;
00364 }
00365
00366 return 0;
00367 }
00368
00369 void ast_rtp_instance_get_remote_address(struct ast_rtp_instance *instance,
00370 struct ast_sockaddr *address)
00371 {
00372 ast_sockaddr_copy(address, &instance->remote_address);
00373 }
00374
00375 void ast_rtp_instance_set_extended_prop(struct ast_rtp_instance *instance, int property, void *value)
00376 {
00377 if (instance->engine->extended_prop_set) {
00378 instance->engine->extended_prop_set(instance, property, value);
00379 }
00380 }
00381
00382 void *ast_rtp_instance_get_extended_prop(struct ast_rtp_instance *instance, int property)
00383 {
00384 if (instance->engine->extended_prop_get) {
00385 return instance->engine->extended_prop_get(instance, property);
00386 }
00387
00388 return NULL;
00389 }
00390
00391 void ast_rtp_instance_set_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value)
00392 {
00393 instance->properties[property] = value;
00394
00395 if (instance->engine->prop_set) {
00396 instance->engine->prop_set(instance, property, value);
00397 }
00398 }
00399
00400 int ast_rtp_instance_get_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property)
00401 {
00402 return instance->properties[property];
00403 }
00404
00405 struct ast_rtp_codecs *ast_rtp_instance_get_codecs(struct ast_rtp_instance *instance)
00406 {
00407 return &instance->codecs;
00408 }
00409
00410 void ast_rtp_codecs_payloads_clear(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance)
00411 {
00412 int i;
00413
00414 for (i = 0; i < AST_RTP_MAX_PT; i++) {
00415 codecs->payloads[i].asterisk_format = 0;
00416 codecs->payloads[i].rtp_code = 0;
00417 ast_format_clear(&codecs->payloads[i].format);
00418 if (instance && instance->engine && instance->engine->payload_set) {
00419 instance->engine->payload_set(instance, i, 0, NULL, 0);
00420 }
00421 }
00422 }
00423
00424 void ast_rtp_codecs_payloads_default(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance)
00425 {
00426 int i;
00427
00428 ast_rwlock_rdlock(&static_RTP_PT_lock);
00429 for (i = 0; i < AST_RTP_MAX_PT; i++) {
00430 if (static_RTP_PT[i].rtp_code || static_RTP_PT[i].asterisk_format) {
00431
00432 codecs->payloads[i].asterisk_format = static_RTP_PT[i].asterisk_format;
00433 codecs->payloads[i].rtp_code = static_RTP_PT[i].rtp_code;
00434 ast_format_copy(&codecs->payloads[i].format, &static_RTP_PT[i].format);
00435 if (instance && instance->engine && instance->engine->payload_set) {
00436 instance->engine->payload_set(instance, i, codecs->payloads[i].asterisk_format, &codecs->payloads[i].format, codecs->payloads[i].rtp_code);
00437 }
00438 }
00439 }
00440 ast_rwlock_unlock(&static_RTP_PT_lock);
00441 }
00442
00443 void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
00444 {
00445 int i;
00446
00447 for (i = 0; i < AST_RTP_MAX_PT; i++) {
00448 if (src->payloads[i].rtp_code || src->payloads[i].asterisk_format) {
00449 ast_debug(2, "Copying payload %d from %p to %p\n", i, src, dest);
00450 dest->payloads[i].asterisk_format = src->payloads[i].asterisk_format;
00451 dest->payloads[i].rtp_code = src->payloads[i].rtp_code;
00452 ast_format_copy(&dest->payloads[i].format, &src->payloads[i].format);
00453 if (instance && instance->engine && instance->engine->payload_set) {
00454 instance->engine->payload_set(instance, i, dest->payloads[i].asterisk_format, &dest->payloads[i].format, dest->payloads[i].rtp_code);
00455 }
00456 }
00457 }
00458 }
00459
00460 void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
00461 {
00462
00463 ast_rwlock_rdlock(&static_RTP_PT_lock);
00464 if (payload < 0 || payload >= AST_RTP_MAX_PT || (!static_RTP_PT[payload].rtp_code && !static_RTP_PT[payload].asterisk_format)) {
00465 ast_rwlock_unlock(&static_RTP_PT_lock);
00466 return;
00467 }
00468
00469 codecs->payloads[payload].asterisk_format = static_RTP_PT[payload].asterisk_format;
00470 codecs->payloads[payload].rtp_code = static_RTP_PT[payload].rtp_code;
00471 ast_format_copy(&codecs->payloads[payload].format, &static_RTP_PT[payload].format);
00472
00473 ast_debug(1, "Setting payload %d based on m type on %p\n", payload, codecs);
00474
00475 if (instance && instance->engine && instance->engine->payload_set) {
00476 instance->engine->payload_set(instance, payload, codecs->payloads[payload].asterisk_format, &codecs->payloads[payload].format, codecs->payloads[payload].rtp_code);
00477 }
00478 ast_rwlock_unlock(&static_RTP_PT_lock);
00479 }
00480
00481 int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int pt,
00482 char *mimetype, char *mimesubtype,
00483 enum ast_rtp_options options,
00484 unsigned int sample_rate)
00485 {
00486 unsigned int i;
00487 int found = 0;
00488
00489 if (pt < 0 || pt >= AST_RTP_MAX_PT)
00490 return -1;
00491
00492 ast_rwlock_rdlock(&mime_types_lock);
00493 for (i = 0; i < mime_types_len; ++i) {
00494 const struct ast_rtp_mime_type *t = &ast_rtp_mime_types[i];
00495
00496 if (strcasecmp(mimesubtype, t->subtype)) {
00497 continue;
00498 }
00499
00500 if (strcasecmp(mimetype, t->type)) {
00501 continue;
00502 }
00503
00504
00505
00506
00507 if (sample_rate && t->sample_rate &&
00508 (sample_rate != t->sample_rate)) {
00509 continue;
00510 }
00511
00512 found = 1;
00513 codecs->payloads[pt] = t->payload_type;
00514
00515 if ((t->payload_type.format.id == AST_FORMAT_G726) && t->payload_type.asterisk_format && (options & AST_RTP_OPT_G726_NONSTANDARD)) {
00516 ast_format_set(&codecs->payloads[pt].format, AST_FORMAT_G726_AAL2, 0);
00517 }
00518
00519 if (instance && instance->engine && instance->engine->payload_set) {
00520 instance->engine->payload_set(instance, pt, codecs->payloads[i].asterisk_format, &codecs->payloads[i].format, codecs->payloads[i].rtp_code);
00521 }
00522
00523 break;
00524 }
00525 ast_rwlock_unlock(&mime_types_lock);
00526
00527 return (found ? 0 : -2);
00528 }
00529
00530 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)
00531 {
00532 return ast_rtp_codecs_payloads_set_rtpmap_type_rate(codecs, instance, payload, mimetype, mimesubtype, options, 0);
00533 }
00534
00535 void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
00536 {
00537 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
00538 return;
00539 }
00540
00541 ast_debug(2, "Unsetting payload %d on %p\n", payload, codecs);
00542
00543 codecs->payloads[payload].asterisk_format = 0;
00544 codecs->payloads[payload].rtp_code = 0;
00545 ast_format_clear(&codecs->payloads[payload].format);
00546
00547 if (instance && instance->engine && instance->engine->payload_set) {
00548 instance->engine->payload_set(instance, payload, 0, NULL, 0);
00549 }
00550 }
00551
00552 struct ast_rtp_payload_type ast_rtp_codecs_payload_lookup(struct ast_rtp_codecs *codecs, int payload)
00553 {
00554 struct ast_rtp_payload_type result = { .asterisk_format = 0, };
00555
00556 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
00557 return result;
00558 }
00559
00560 result.asterisk_format = codecs->payloads[payload].asterisk_format;
00561 result.rtp_code = codecs->payloads[payload].rtp_code;
00562 ast_format_copy(&result.format, &codecs->payloads[payload].format);
00563
00564 if (!result.rtp_code && !result.asterisk_format) {
00565 ast_rwlock_rdlock(&static_RTP_PT_lock);
00566 result = static_RTP_PT[payload];
00567 ast_rwlock_unlock(&static_RTP_PT_lock);
00568 }
00569
00570 return result;
00571 }
00572
00573
00574 struct ast_format *ast_rtp_codecs_get_payload_format(struct ast_rtp_codecs *codecs, int payload)
00575 {
00576 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
00577 return NULL;
00578 }
00579 if (!codecs->payloads[payload].asterisk_format) {
00580 return NULL;
00581 }
00582 return &codecs->payloads[payload].format;
00583 }
00584
00585 void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, struct ast_format_cap *astformats, int *nonastformats)
00586 {
00587 int i;
00588
00589 ast_format_cap_remove_all(astformats);
00590 *nonastformats = 0;
00591
00592 for (i = 0; i < AST_RTP_MAX_PT; i++) {
00593 if (codecs->payloads[i].rtp_code || codecs->payloads[i].asterisk_format) {
00594 ast_debug(1, "Incorporating payload %d on %p\n", i, codecs);
00595 }
00596 if (codecs->payloads[i].asterisk_format) {
00597 ast_format_cap_add(astformats, &codecs->payloads[i].format);
00598 } else {
00599 *nonastformats |= codecs->payloads[i].rtp_code;
00600 }
00601 }
00602 }
00603
00604 int ast_rtp_codecs_payload_code(struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code)
00605 {
00606 int i;
00607 int res = -1;
00608 for (i = 0; i < AST_RTP_MAX_PT; i++) {
00609 if (codecs->payloads[i].asterisk_format && asterisk_format && format &&
00610 (ast_format_cmp(format, &codecs->payloads[i].format) != AST_FORMAT_CMP_NOT_EQUAL)) {
00611 return i;
00612 } else if (!codecs->payloads[i].asterisk_format && !asterisk_format &&
00613 (codecs->payloads[i].rtp_code == code)) {
00614 return i;
00615 }
00616 }
00617
00618 ast_rwlock_rdlock(&static_RTP_PT_lock);
00619 for (i = 0; i < AST_RTP_MAX_PT; i++) {
00620 if (static_RTP_PT[i].asterisk_format && asterisk_format && format &&
00621 (ast_format_cmp(format, &static_RTP_PT[i].format) != AST_FORMAT_CMP_NOT_EQUAL)) {
00622 res = i;
00623 break;
00624 } else if (!static_RTP_PT[i].asterisk_format && !asterisk_format &&
00625 (static_RTP_PT[i].rtp_code == code)) {
00626 res = i;
00627 break;
00628 }
00629 }
00630 ast_rwlock_unlock(&static_RTP_PT_lock);
00631
00632 return res;
00633 }
00634
00635 const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format, struct ast_format *format, int code, enum ast_rtp_options options)
00636 {
00637 int i;
00638 const char *res = "";
00639
00640 ast_rwlock_rdlock(&mime_types_lock);
00641 for (i = 0; i < mime_types_len; i++) {
00642 if (ast_rtp_mime_types[i].payload_type.asterisk_format && asterisk_format && format &&
00643 (ast_format_cmp(format, &ast_rtp_mime_types[i].payload_type.format) != AST_FORMAT_CMP_NOT_EQUAL)) {
00644 if ((format->id == AST_FORMAT_G726_AAL2) && (options & AST_RTP_OPT_G726_NONSTANDARD)) {
00645 res = "G726-32";
00646 break;
00647 } else {
00648 res = ast_rtp_mime_types[i].subtype;
00649 break;
00650 }
00651 } else if (!ast_rtp_mime_types[i].payload_type.asterisk_format && !asterisk_format &&
00652 ast_rtp_mime_types[i].payload_type.rtp_code == code) {
00653
00654 res = ast_rtp_mime_types[i].subtype;
00655 break;
00656 }
00657 }
00658 ast_rwlock_unlock(&mime_types_lock);
00659
00660 return res;
00661 }
00662
00663 unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format, struct ast_format *format, int code)
00664 {
00665 unsigned int i;
00666 unsigned int res = 0;
00667
00668 ast_rwlock_rdlock(&mime_types_lock);
00669 for (i = 0; i < mime_types_len; ++i) {
00670 if (ast_rtp_mime_types[i].payload_type.asterisk_format && asterisk_format && format &&
00671 (ast_format_cmp(format, &ast_rtp_mime_types[i].payload_type.format) != AST_FORMAT_CMP_NOT_EQUAL)) {
00672 res = ast_rtp_mime_types[i].sample_rate;
00673 break;
00674 } else if (!ast_rtp_mime_types[i].payload_type.asterisk_format && !asterisk_format &&
00675 ast_rtp_mime_types[i].payload_type.rtp_code == code) {
00676 res = ast_rtp_mime_types[i].sample_rate;
00677 break;
00678 }
00679 }
00680 ast_rwlock_unlock(&mime_types_lock);
00681
00682 return res;
00683 }
00684
00685 char *ast_rtp_lookup_mime_multiple2(struct ast_str *buf, struct ast_format_cap *ast_format_capability, int rtp_capability, const int asterisk_format, enum ast_rtp_options options)
00686 {
00687 int found = 0;
00688 const char *name;
00689 if (!buf) {
00690 return NULL;
00691 }
00692
00693
00694 if (asterisk_format) {
00695 struct ast_format tmp_fmt;
00696 ast_format_cap_iter_start(ast_format_capability);
00697 while (!ast_format_cap_iter_next(ast_format_capability, &tmp_fmt)) {
00698 name = ast_rtp_lookup_mime_subtype2(asterisk_format, &tmp_fmt, 0, options);
00699 ast_str_append(&buf, 0, "%s|", name);
00700 found = 1;
00701 }
00702 ast_format_cap_iter_end(ast_format_capability);
00703
00704 } else {
00705 int x;
00706 ast_str_append(&buf, 0, "0x%x (", (unsigned int) rtp_capability);
00707 for (x = 1; x < AST_RTP_MAX; x <<= 1) {
00708 if (rtp_capability & x) {
00709 name = ast_rtp_lookup_mime_subtype2(asterisk_format, NULL, x, options);
00710 ast_str_append(&buf, 0, "%s|", name);
00711 found = 1;
00712 }
00713 }
00714 }
00715
00716 ast_str_append(&buf, 0, "%s", found ? ")" : "nothing)");
00717
00718 return ast_str_buffer(buf);
00719 }
00720
00721 void ast_rtp_codecs_packetization_set(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, struct ast_codec_pref *prefs)
00722 {
00723 codecs->pref = *prefs;
00724
00725 if (instance && instance->engine->packetization_set) {
00726 instance->engine->packetization_set(instance, &instance->codecs.pref);
00727 }
00728 }
00729
00730 int ast_rtp_instance_dtmf_begin(struct ast_rtp_instance *instance, char digit)
00731 {
00732 return instance->engine->dtmf_begin ? instance->engine->dtmf_begin(instance, digit) : -1;
00733 }
00734
00735 int ast_rtp_instance_dtmf_end(struct ast_rtp_instance *instance, char digit)
00736 {
00737 return instance->engine->dtmf_end ? instance->engine->dtmf_end(instance, digit) : -1;
00738 }
00739 int ast_rtp_instance_dtmf_end_with_duration(struct ast_rtp_instance *instance, char digit, unsigned int duration)
00740 {
00741 return instance->engine->dtmf_end_with_duration ? instance->engine->dtmf_end_with_duration(instance, digit, duration) : -1;
00742 }
00743
00744 int ast_rtp_instance_dtmf_mode_set(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode)
00745 {
00746 return (!instance->engine->dtmf_mode_set || instance->engine->dtmf_mode_set(instance, dtmf_mode)) ? -1 : 0;
00747 }
00748
00749 enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get(struct ast_rtp_instance *instance)
00750 {
00751 return instance->engine->dtmf_mode_get ? instance->engine->dtmf_mode_get(instance) : 0;
00752 }
00753
00754 void ast_rtp_instance_update_source(struct ast_rtp_instance *instance)
00755 {
00756 if (instance->engine->update_source) {
00757 instance->engine->update_source(instance);
00758 }
00759 }
00760
00761 void ast_rtp_instance_change_source(struct ast_rtp_instance *instance)
00762 {
00763 if (instance->engine->change_source) {
00764 instance->engine->change_source(instance);
00765 }
00766 }
00767
00768 int ast_rtp_instance_set_qos(struct ast_rtp_instance *instance, int tos, int cos, const char *desc)
00769 {
00770 return instance->engine->qos ? instance->engine->qos(instance, tos, cos, desc) : -1;
00771 }
00772
00773 void ast_rtp_instance_stop(struct ast_rtp_instance *instance)
00774 {
00775 if (instance->engine->stop) {
00776 instance->engine->stop(instance);
00777 }
00778 }
00779
00780 int ast_rtp_instance_fd(struct ast_rtp_instance *instance, int rtcp)
00781 {
00782 return instance->engine->fd ? instance->engine->fd(instance, rtcp) : -1;
00783 }
00784
00785 struct ast_rtp_glue *ast_rtp_instance_get_glue(const char *type)
00786 {
00787 struct ast_rtp_glue *glue = NULL;
00788
00789 AST_RWLIST_RDLOCK(&glues);
00790
00791 AST_RWLIST_TRAVERSE(&glues, glue, entry) {
00792 if (!strcasecmp(glue->type, type)) {
00793 break;
00794 }
00795 }
00796
00797 AST_RWLIST_UNLOCK(&glues);
00798
00799 return glue;
00800 }
00801
00802 static enum ast_bridge_result local_bridge_loop(struct ast_channel *c0, struct ast_channel *c1, struct ast_rtp_instance *instance0, struct ast_rtp_instance *instance1, int timeoutms, int flags, struct ast_frame **fo, struct ast_channel **rc, void *pvt0, void *pvt1)
00803 {
00804 enum ast_bridge_result res = AST_BRIDGE_FAILED;
00805 struct ast_channel *who = NULL, *other = NULL, *cs[3] = { NULL, };
00806 struct ast_frame *fr = NULL;
00807
00808
00809 if (instance0->engine->local_bridge && instance0->engine->local_bridge(instance0, instance1)) {
00810 ast_debug(1, "Failed to locally bridge %s to %s, backing out.\n", ast_channel_name(c0), ast_channel_name(c1));
00811 ast_channel_unlock(c0);
00812 ast_channel_unlock(c1);
00813 return AST_BRIDGE_FAILED_NOWARN;
00814 }
00815 if (instance1->engine->local_bridge && instance1->engine->local_bridge(instance1, instance0)) {
00816 ast_debug(1, "Failed to locally bridge %s to %s, backing out.\n", ast_channel_name(c1), ast_channel_name(c0));
00817 if (instance0->engine->local_bridge) {
00818 instance0->engine->local_bridge(instance0, NULL);
00819 }
00820 ast_channel_unlock(c0);
00821 ast_channel_unlock(c1);
00822 return AST_BRIDGE_FAILED_NOWARN;
00823 }
00824
00825 ast_channel_unlock(c0);
00826 ast_channel_unlock(c1);
00827
00828 instance0->bridged = instance1;
00829 instance1->bridged = instance0;
00830
00831 ast_poll_channel_add(c0, c1);
00832
00833
00834 cs[0] = c0;
00835 cs[1] = c1;
00836 cs[2] = NULL;
00837 for (;;) {
00838
00839 if ((ast_format_cmp(ast_channel_rawreadformat(c0), ast_channel_rawwriteformat(c1)) == AST_FORMAT_CMP_NOT_EQUAL) ||
00840 (ast_format_cmp(ast_channel_rawreadformat(c1), ast_channel_rawwriteformat(c0)) == AST_FORMAT_CMP_NOT_EQUAL)) {
00841 ast_debug(1, "rtp-engine-local-bridge: Oooh, formats changed, backing out\n");
00842 res = AST_BRIDGE_FAILED_NOWARN;
00843 break;
00844 }
00845
00846 if ((ast_channel_tech_pvt(c0) != pvt0) ||
00847 (ast_channel_tech_pvt(c1) != pvt1) ||
00848 (ast_channel_masq(c0) || ast_channel_masqr(c0) || ast_channel_masq(c1) || ast_channel_masqr(c1)) ||
00849 (ast_channel_monitor(c0) || ast_channel_audiohooks(c0) || ast_channel_monitor(c1) || ast_channel_audiohooks(c1)) ||
00850 (!ast_framehook_list_is_empty(ast_channel_framehooks(c0)) || !ast_framehook_list_is_empty(ast_channel_framehooks(c1)))) {
00851 ast_debug(1, "rtp-engine-local-bridge: Oooh, something is weird, backing out\n");
00852
00853 if ((ast_channel_masq(c0) || ast_channel_masqr(c0)) && (fr = ast_read(c0))) {
00854 ast_frfree(fr);
00855 }
00856 if ((ast_channel_masq(c1) || ast_channel_masqr(c1)) && (fr = ast_read(c1))) {
00857 ast_frfree(fr);
00858 }
00859 res = AST_BRIDGE_RETRY;
00860 break;
00861 }
00862
00863 if (!(who = ast_waitfor_n(cs, 2, &timeoutms))) {
00864 if (!timeoutms) {
00865 res = AST_BRIDGE_RETRY;
00866 break;
00867 }
00868 ast_debug(2, "rtp-engine-local-bridge: Ooh, empty read...\n");
00869 if (ast_check_hangup(c0) || ast_check_hangup(c1)) {
00870 break;
00871 }
00872 continue;
00873 }
00874
00875 fr = ast_read(who);
00876 other = (who == c0) ? c1 : c0;
00877
00878 if (!fr || ((fr->frametype == AST_FRAME_DTMF_BEGIN || fr->frametype == AST_FRAME_DTMF_END) &&
00879 ((who == c0) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) |
00880 ((who == c1) && (flags & AST_BRIDGE_DTMF_CHANNEL_1)))) {
00881
00882 *fo = fr;
00883 *rc = who;
00884 ast_debug(1, "rtp-engine-local-bridge: Ooh, got a %s\n", fr ? "digit" : "hangup");
00885 res = AST_BRIDGE_COMPLETE;
00886 break;
00887 } else if ((fr->frametype == AST_FRAME_CONTROL) && !(flags & AST_BRIDGE_IGNORE_SIGS)) {
00888 if ((fr->subclass.integer == AST_CONTROL_HOLD) ||
00889 (fr->subclass.integer == AST_CONTROL_UNHOLD) ||
00890 (fr->subclass.integer == AST_CONTROL_VIDUPDATE) ||
00891 (fr->subclass.integer == AST_CONTROL_SRCUPDATE) ||
00892 (fr->subclass.integer == AST_CONTROL_T38_PARAMETERS) ||
00893 (fr->subclass.integer == AST_CONTROL_UPDATE_RTP_PEER)) {
00894
00895 if (fr->subclass.integer == AST_CONTROL_HOLD) {
00896 if (instance0->engine->local_bridge) {
00897 instance0->engine->local_bridge(instance0, NULL);
00898 }
00899 if (instance1->engine->local_bridge) {
00900 instance1->engine->local_bridge(instance1, NULL);
00901 }
00902 instance0->bridged = NULL;
00903 instance1->bridged = NULL;
00904 } else if (fr->subclass.integer == AST_CONTROL_UNHOLD) {
00905 if (instance0->engine->local_bridge) {
00906 instance0->engine->local_bridge(instance0, instance1);
00907 }
00908 if (instance1->engine->local_bridge) {
00909 instance1->engine->local_bridge(instance1, instance0);
00910 }
00911 instance0->bridged = instance1;
00912 instance1->bridged = instance0;
00913 }
00914
00915 if (fr->subclass.integer != AST_CONTROL_UPDATE_RTP_PEER) {
00916 ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
00917 }
00918 ast_frfree(fr);
00919 } else if (fr->subclass.integer == AST_CONTROL_CONNECTED_LINE) {
00920 if (ast_channel_connected_line_sub(who, other, fr, 1) &&
00921 ast_channel_connected_line_macro(who, other, fr, other == c0, 1)) {
00922 ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
00923 }
00924 ast_frfree(fr);
00925 } else if (fr->subclass.integer == AST_CONTROL_REDIRECTING) {
00926 if (ast_channel_redirecting_sub(who, other, fr, 1) &&
00927 ast_channel_redirecting_macro(who, other, fr, other == c0, 1)) {
00928 ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
00929 }
00930 ast_frfree(fr);
00931 } else if (fr->subclass.integer == AST_CONTROL_PVT_CAUSE_CODE) {
00932 ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
00933 ast_frfree(fr);
00934 } else {
00935 *fo = fr;
00936 *rc = who;
00937 ast_debug(1, "rtp-engine-local-bridge: Got a FRAME_CONTROL (%d) frame on channel %s\n", fr->subclass.integer, ast_channel_name(who));
00938 res = AST_BRIDGE_COMPLETE;
00939 break;
00940 }
00941 } else {
00942 if ((fr->frametype == AST_FRAME_DTMF_BEGIN) ||
00943 (fr->frametype == AST_FRAME_DTMF_END) ||
00944 (fr->frametype == AST_FRAME_VOICE) ||
00945 (fr->frametype == AST_FRAME_VIDEO) ||
00946 (fr->frametype == AST_FRAME_IMAGE) ||
00947 (fr->frametype == AST_FRAME_HTML) ||
00948 (fr->frametype == AST_FRAME_MODEM) ||
00949 (fr->frametype == AST_FRAME_TEXT)) {
00950 ast_write(other, fr);
00951 }
00952
00953 ast_frfree(fr);
00954 }
00955
00956 cs[2] = cs[0];
00957 cs[0] = cs[1];
00958 cs[1] = cs[2];
00959 }
00960
00961
00962 if (instance0->engine->local_bridge) {
00963 instance0->engine->local_bridge(instance0, NULL);
00964 }
00965 if (instance1->engine->local_bridge) {
00966 instance1->engine->local_bridge(instance1, NULL);
00967 }
00968
00969 instance0->bridged = NULL;
00970 instance1->bridged = NULL;
00971
00972 ast_poll_channel_del(c0, c1);
00973
00974 return res;
00975 }
00976
00977 static enum ast_bridge_result remote_bridge_loop(struct ast_channel *c0,
00978 struct ast_channel *c1,
00979 struct ast_rtp_instance *instance0,
00980 struct ast_rtp_instance *instance1,
00981 struct ast_rtp_instance *vinstance0,
00982 struct ast_rtp_instance *vinstance1,
00983 struct ast_rtp_instance *tinstance0,
00984 struct ast_rtp_instance *tinstance1,
00985 struct ast_rtp_glue *glue0,
00986 struct ast_rtp_glue *glue1,
00987 struct ast_format_cap *cap0,
00988 struct ast_format_cap *cap1,
00989 int timeoutms,
00990 int flags,
00991 struct ast_frame **fo,
00992 struct ast_channel **rc,
00993 void *pvt0,
00994 void *pvt1)
00995 {
00996 enum ast_bridge_result res = AST_BRIDGE_FAILED;
00997 struct ast_channel *who = NULL, *other = NULL, *cs[3] = { NULL, };
00998 struct ast_format_cap *oldcap0 = ast_format_cap_dup(cap0);
00999 struct ast_format_cap *oldcap1 = ast_format_cap_dup(cap1);
01000 struct ast_sockaddr ac1 = {{0,}}, vac1 = {{0,}}, tac1 = {{0,}}, ac0 = {{0,}}, vac0 = {{0,}}, tac0 = {{0,}};
01001 struct ast_sockaddr t1 = {{0,}}, vt1 = {{0,}}, tt1 = {{0,}}, t0 = {{0,}}, vt0 = {{0,}}, tt0 = {{0,}};
01002 struct ast_frame *fr = NULL;
01003
01004 if (!oldcap0 || !oldcap1) {
01005 ast_channel_unlock(c0);
01006 ast_channel_unlock(c1);
01007 goto remote_bridge_cleanup;
01008 }
01009
01010 if (!(glue0->update_peer(c0, instance1, vinstance1, tinstance1, cap1, 0))) {
01011 ast_rtp_instance_get_remote_address(instance1, &ac1);
01012 if (vinstance1) {
01013 ast_rtp_instance_get_remote_address(vinstance1, &vac1);
01014 }
01015 if (tinstance1) {
01016 ast_rtp_instance_get_remote_address(tinstance1, &tac1);
01017 }
01018 } else {
01019 ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", ast_channel_name(c0), ast_channel_name(c1));
01020 }
01021
01022
01023 if (!(glue1->update_peer(c1, instance0, vinstance0, tinstance0, cap0, 0))) {
01024 ast_rtp_instance_get_remote_address(instance0, &ac0);
01025 if (vinstance0) {
01026 ast_rtp_instance_get_remote_address(instance0, &vac0);
01027 }
01028 if (tinstance0) {
01029 ast_rtp_instance_get_remote_address(instance0, &tac0);
01030 }
01031 } else {
01032 ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", ast_channel_name(c1), ast_channel_name(c0));
01033 }
01034
01035 ast_channel_unlock(c0);
01036 ast_channel_unlock(c1);
01037
01038 instance0->bridged = instance1;
01039 instance1->bridged = instance0;
01040
01041 ast_poll_channel_add(c0, c1);
01042
01043
01044 cs[0] = c0;
01045 cs[1] = c1;
01046 cs[2] = NULL;
01047 for (;;) {
01048
01049 if ((ast_channel_tech_pvt(c0) != pvt0) ||
01050 (ast_channel_tech_pvt(c1) != pvt1) ||
01051 (ast_channel_masq(c0) || ast_channel_masqr(c0) || ast_channel_masq(c1) || ast_channel_masqr(c1)) ||
01052 (ast_channel_monitor(c0) || ast_channel_audiohooks(c0) || ast_channel_monitor(c1) || ast_channel_audiohooks(c1)) ||
01053 (!ast_framehook_list_is_empty(ast_channel_framehooks(c0)) || !ast_framehook_list_is_empty(ast_channel_framehooks(c1)))) {
01054 ast_debug(1, "Oooh, something is weird, backing out\n");
01055 res = AST_BRIDGE_RETRY;
01056 break;
01057 }
01058
01059
01060 ast_rtp_instance_get_remote_address(instance1, &t1);
01061 if (vinstance1) {
01062 ast_rtp_instance_get_remote_address(vinstance1, &vt1);
01063 }
01064 if (tinstance1) {
01065 ast_rtp_instance_get_remote_address(tinstance1, &tt1);
01066 }
01067 if (glue1->get_codec) {
01068 ast_format_cap_remove_all(cap1);
01069 glue1->get_codec(c1, cap1);
01070 }
01071
01072 ast_rtp_instance_get_remote_address(instance0, &t0);
01073 if (vinstance0) {
01074 ast_rtp_instance_get_remote_address(vinstance0, &vt0);
01075 }
01076 if (tinstance0) {
01077 ast_rtp_instance_get_remote_address(tinstance0, &tt0);
01078 }
01079 if (glue0->get_codec) {
01080 ast_format_cap_remove_all(cap0);
01081 glue0->get_codec(c0, cap0);
01082 }
01083
01084 if ((ast_sockaddr_cmp(&t1, &ac1)) ||
01085 (vinstance1 && ast_sockaddr_cmp(&vt1, &vac1)) ||
01086 (tinstance1 && ast_sockaddr_cmp(&tt1, &tac1)) ||
01087 (!ast_format_cap_identical(cap1, oldcap1))) {
01088 char tmp_buf[512] = { 0, };
01089 ast_debug(1, "Oooh, '%s' changed end address to %s (format %s)\n",
01090 ast_channel_name(c1), ast_sockaddr_stringify(&t1),
01091 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), cap1));
01092 ast_debug(1, "Oooh, '%s' changed end vaddress to %s (format %s)\n",
01093 ast_channel_name(c1), ast_sockaddr_stringify(&vt1),
01094 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), cap1));
01095 ast_debug(1, "Oooh, '%s' changed end taddress to %s (format %s)\n",
01096 ast_channel_name(c1), ast_sockaddr_stringify(&tt1),
01097 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), cap1));
01098 ast_debug(1, "Oooh, '%s' was %s/(format %s)\n",
01099 ast_channel_name(c1), ast_sockaddr_stringify(&ac1),
01100 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), oldcap1));
01101 ast_debug(1, "Oooh, '%s' was %s/(format %s)\n",
01102 ast_channel_name(c1), ast_sockaddr_stringify(&vac1),
01103 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), oldcap1));
01104 ast_debug(1, "Oooh, '%s' was %s/(format %s)\n",
01105 ast_channel_name(c1), ast_sockaddr_stringify(&tac1),
01106 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), oldcap1));
01107 if (glue0->update_peer(c0,
01108 ast_sockaddr_isnull(&t1) ? NULL : instance1,
01109 ast_sockaddr_isnull(&vt1) ? NULL : vinstance1,
01110 ast_sockaddr_isnull(&tt1) ? NULL : tinstance1,
01111 cap1, 0)) {
01112 ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", ast_channel_name(c0), ast_channel_name(c1));
01113 }
01114 ast_sockaddr_copy(&ac1, &t1);
01115 ast_sockaddr_copy(&vac1, &vt1);
01116 ast_sockaddr_copy(&tac1, &tt1);
01117 ast_format_cap_copy(oldcap1, cap1);
01118 }
01119 if ((ast_sockaddr_cmp(&t0, &ac0)) ||
01120 (vinstance0 && ast_sockaddr_cmp(&vt0, &vac0)) ||
01121 (tinstance0 && ast_sockaddr_cmp(&tt0, &tac0)) ||
01122 (!ast_format_cap_identical(cap0, oldcap0))) {
01123 char tmp_buf[512] = { 0, };
01124 ast_debug(1, "Oooh, '%s' changed end address to %s (format %s)\n",
01125 ast_channel_name(c0), ast_sockaddr_stringify(&t0),
01126 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), cap0));
01127 ast_debug(1, "Oooh, '%s' was %s/(format %s)\n",
01128 ast_channel_name(c0), ast_sockaddr_stringify(&ac0),
01129 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), oldcap0));
01130 if (glue1->update_peer(c1, t0.len ? instance0 : NULL,
01131 vt0.len ? vinstance0 : NULL,
01132 tt0.len ? tinstance0 : NULL,
01133 cap0, 0)) {
01134 ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", ast_channel_name(c1), ast_channel_name(c0));
01135 }
01136 ast_sockaddr_copy(&ac0, &t0);
01137 ast_sockaddr_copy(&vac0, &vt0);
01138 ast_sockaddr_copy(&tac0, &tt0);
01139 ast_format_cap_copy(oldcap0, cap0);
01140 }
01141
01142
01143 if (!(who = ast_waitfor_n(cs, 2, &timeoutms))) {
01144 if (!timeoutms) {
01145 res = AST_BRIDGE_RETRY;
01146 break;
01147 }
01148 ast_debug(1, "Ooh, empty read...\n");
01149 if (ast_check_hangup(c0) || ast_check_hangup(c1)) {
01150 break;
01151 }
01152 continue;
01153 }
01154 fr = ast_read(who);
01155 other = (who == c0) ? c1 : c0;
01156 if (!fr || ((fr->frametype == AST_FRAME_DTMF_BEGIN || fr->frametype == AST_FRAME_DTMF_END) &&
01157 (((who == c0) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) ||
01158 ((who == c1) && (flags & AST_BRIDGE_DTMF_CHANNEL_1))))) {
01159
01160 *fo = fr;
01161 *rc = who;
01162 ast_debug(1, "Oooh, got a %s\n", fr ? "digit" : "hangup");
01163 res = AST_BRIDGE_COMPLETE;
01164 break;
01165 } else if ((fr->frametype == AST_FRAME_CONTROL) && !(flags & AST_BRIDGE_IGNORE_SIGS)) {
01166 if ((fr->subclass.integer == AST_CONTROL_HOLD) ||
01167 (fr->subclass.integer == AST_CONTROL_UNHOLD) ||
01168 (fr->subclass.integer == AST_CONTROL_VIDUPDATE) ||
01169 (fr->subclass.integer == AST_CONTROL_SRCUPDATE) ||
01170 (fr->subclass.integer == AST_CONTROL_T38_PARAMETERS) ||
01171 (fr->subclass.integer == AST_CONTROL_UPDATE_RTP_PEER)) {
01172 if (fr->subclass.integer == AST_CONTROL_HOLD) {
01173
01174 if (who == c0) {
01175 glue1->update_peer(c1, NULL, NULL, NULL, 0, 0);
01176 } else {
01177 glue0->update_peer(c0, NULL, NULL, NULL, 0, 0);
01178 }
01179 } else if (fr->subclass.integer == AST_CONTROL_UNHOLD ||
01180 fr->subclass.integer == AST_CONTROL_UPDATE_RTP_PEER) {
01181
01182
01183 if (who == c0) {
01184 glue1->update_peer(c1, instance0, vinstance0, tinstance0, cap0, 0);
01185 } else {
01186 glue0->update_peer(c0, instance1, vinstance1, tinstance1, cap1, 0);
01187 }
01188 }
01189
01190 ast_rtp_instance_get_remote_address(instance0, &t0);
01191 ast_sockaddr_copy(&ac0, &t0);
01192 ast_rtp_instance_get_remote_address(instance1, &t1);
01193 ast_sockaddr_copy(&ac1, &t1);
01194
01195 if (glue0->get_codec && ast_channel_tech_pvt(c0)) {
01196 ast_format_cap_remove_all(cap0);
01197 ast_format_cap_remove_all(oldcap0);
01198 glue0->get_codec(c0, cap0);
01199 ast_format_cap_append(oldcap0, cap0);
01200
01201 }
01202 if (glue1->get_codec && ast_channel_tech_pvt(c1)) {
01203 ast_format_cap_remove_all(cap1);
01204 ast_format_cap_remove_all(oldcap1);
01205 glue0->get_codec(c1, cap1);
01206 ast_format_cap_append(oldcap1, cap1);
01207 }
01208
01209 if (fr->subclass.integer != AST_CONTROL_UPDATE_RTP_PEER) {
01210 ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
01211 }
01212 ast_frfree(fr);
01213 } else if (fr->subclass.integer == AST_CONTROL_CONNECTED_LINE) {
01214 if (ast_channel_connected_line_sub(who, other, fr, 1) &&
01215 ast_channel_connected_line_macro(who, other, fr, other == c0, 1)) {
01216 ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
01217 }
01218 ast_frfree(fr);
01219 } else if (fr->subclass.integer == AST_CONTROL_REDIRECTING) {
01220 if (ast_channel_redirecting_sub(who, other, fr, 1) &&
01221 ast_channel_redirecting_macro(who, other, fr, other == c0, 1)) {
01222 ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
01223 }
01224 ast_frfree(fr);
01225 } else if (fr->subclass.integer == AST_CONTROL_PVT_CAUSE_CODE) {
01226 ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
01227 ast_frfree(fr);
01228 } else {
01229 *fo = fr;
01230 *rc = who;
01231 ast_debug(1, "Got a FRAME_CONTROL (%d) frame on channel %s\n", fr->subclass.integer, ast_channel_name(who));
01232 res = AST_BRIDGE_COMPLETE;
01233 goto remote_bridge_cleanup;
01234 }
01235 } else {
01236 if ((fr->frametype == AST_FRAME_DTMF_BEGIN) ||
01237 (fr->frametype == AST_FRAME_DTMF_END) ||
01238 (fr->frametype == AST_FRAME_VOICE) ||
01239 (fr->frametype == AST_FRAME_VIDEO) ||
01240 (fr->frametype == AST_FRAME_IMAGE) ||
01241 (fr->frametype == AST_FRAME_HTML) ||
01242 (fr->frametype == AST_FRAME_MODEM) ||
01243 (fr->frametype == AST_FRAME_TEXT)) {
01244 ast_write(other, fr);
01245 }
01246 ast_frfree(fr);
01247 }
01248
01249 cs[2] = cs[0];
01250 cs[0] = cs[1];
01251 cs[1] = cs[2];
01252 }
01253
01254 if (ast_test_flag(ast_channel_flags(c0), AST_FLAG_ZOMBIE)) {
01255 ast_debug(1, "Channel '%s' Zombie cleardown from bridge\n", ast_channel_name(c0));
01256 } else if (ast_channel_tech_pvt(c0) != pvt0) {
01257 ast_debug(1, "Channel c0->'%s' pvt changed, in bridge with c1->'%s'\n", ast_channel_name(c0), ast_channel_name(c1));
01258 } else if (glue0 != ast_rtp_instance_get_glue(ast_channel_tech(c0)->type)) {
01259 ast_debug(1, "Channel c0->'%s' technology changed, in bridge with c1->'%s'\n", ast_channel_name(c0), ast_channel_name(c1));
01260 } else if (glue0->update_peer(c0, NULL, NULL, NULL, 0, 0)) {
01261 ast_log(LOG_WARNING, "Channel '%s' failed to break RTP bridge\n", ast_channel_name(c0));
01262 }
01263 if (ast_test_flag(ast_channel_flags(c1), AST_FLAG_ZOMBIE)) {
01264 ast_debug(1, "Channel '%s' Zombie cleardown from bridge\n", ast_channel_name(c1));
01265 } else if (ast_channel_tech_pvt(c1) != pvt1) {
01266 ast_debug(1, "Channel c1->'%s' pvt changed, in bridge with c0->'%s'\n", ast_channel_name(c1), ast_channel_name(c0));
01267 } else if (glue1 != ast_rtp_instance_get_glue(ast_channel_tech(c1)->type)) {
01268 ast_debug(1, "Channel c1->'%s' technology changed, in bridge with c0->'%s'\n", ast_channel_name(c1), ast_channel_name(c0));
01269 } else if (glue1->update_peer(c1, NULL, NULL, NULL, 0, 0)) {
01270 ast_log(LOG_WARNING, "Channel '%s' failed to break RTP bridge\n", ast_channel_name(c1));
01271 }
01272
01273 instance0->bridged = NULL;
01274 instance1->bridged = NULL;
01275
01276 ast_poll_channel_del(c0, c1);
01277
01278 remote_bridge_cleanup:
01279 ast_format_cap_destroy(oldcap0);
01280 ast_format_cap_destroy(oldcap1);
01281
01282 return res;
01283 }
01284
01285
01286
01287
01288 static void unref_instance_cond(struct ast_rtp_instance **instance)
01289 {
01290 if (*instance) {
01291 ao2_ref(*instance, -1);
01292 *instance = NULL;
01293 }
01294 }
01295
01296 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)
01297 {
01298 struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
01299 *vinstance0 = NULL, *vinstance1 = NULL,
01300 *tinstance0 = NULL, *tinstance1 = NULL;
01301 struct ast_rtp_glue *glue0, *glue1;
01302 struct ast_sockaddr addr1 = { {0, }, }, addr2 = { {0, }, };
01303 enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
01304 enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
01305 enum ast_bridge_result res = AST_BRIDGE_FAILED;
01306 enum ast_rtp_dtmf_mode dmode;
01307 struct ast_format_cap *cap0 = ast_format_cap_alloc_nolock();
01308 struct ast_format_cap *cap1 = ast_format_cap_alloc_nolock();
01309 int unlock_chans = 1;
01310
01311 if (!cap0 || !cap1) {
01312 unlock_chans = 0;
01313 goto done;
01314 }
01315
01316
01317 ast_channel_lock(c0);
01318 while (ast_channel_trylock(c1)) {
01319 ast_channel_unlock(c0);
01320 usleep(1);
01321 ast_channel_lock(c0);
01322 }
01323
01324
01325 if (ast_check_hangup(c0) || ast_check_hangup(c1)) {
01326 ast_log(LOG_WARNING, "Got hangup while attempting to bridge '%s' and '%s'\n", ast_channel_name(c0), ast_channel_name(c1));
01327 goto done;
01328 }
01329
01330
01331 if (!(glue0 = ast_rtp_instance_get_glue(ast_channel_tech(c0)->type)) || !(glue1 = ast_rtp_instance_get_glue(ast_channel_tech(c1)->type))) {
01332 ast_debug(1, "Can't find native functions for channel '%s'\n", glue0 ? ast_channel_name(c1) : ast_channel_name(c0));
01333 goto done;
01334 }
01335
01336 audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
01337 video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;
01338
01339 audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
01340 video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;
01341
01342
01343 if (video_glue0_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue0_res != AST_RTP_GLUE_RESULT_REMOTE)) {
01344 audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
01345 }
01346 if (video_glue1_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue1_res != AST_RTP_GLUE_RESULT_REMOTE)) {
01347 audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
01348 }
01349
01350
01351 if (audio_glue0_res == AST_RTP_GLUE_RESULT_FORBID || audio_glue1_res == AST_RTP_GLUE_RESULT_FORBID) {
01352 res = AST_BRIDGE_FAILED_NOWARN;
01353 goto done;
01354 }
01355
01356
01357
01358 ast_rtp_instance_get_remote_address(instance0, &addr1);
01359 ast_rtp_instance_get_remote_address(instance1, &addr2);
01360
01361 if (addr1.ss.ss_family != addr2.ss.ss_family ||
01362 (ast_sockaddr_is_ipv4_mapped(&addr1) != ast_sockaddr_is_ipv4_mapped(&addr2))) {
01363 audio_glue0_res = AST_RTP_GLUE_RESULT_LOCAL;
01364 audio_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
01365 }
01366
01367
01368 dmode = ast_rtp_instance_dtmf_mode_get(instance0);
01369 if ((flags & AST_BRIDGE_DTMF_CHANNEL_0) && dmode) {
01370 res = AST_BRIDGE_FAILED_NOWARN;
01371 goto done;
01372 }
01373 dmode = ast_rtp_instance_dtmf_mode_get(instance1);
01374 if ((flags & AST_BRIDGE_DTMF_CHANNEL_1) && dmode) {
01375 res = AST_BRIDGE_FAILED_NOWARN;
01376 goto done;
01377 }
01378
01379
01380 if ((audio_glue0_res == AST_RTP_GLUE_RESULT_LOCAL || audio_glue1_res == AST_RTP_GLUE_RESULT_LOCAL) && ((instance0->engine->local_bridge != instance1->engine->local_bridge) || (instance0->engine->dtmf_compatible && !instance0->engine->dtmf_compatible(c0, instance0, c1, instance1)))) {
01381 res = AST_BRIDGE_FAILED_NOWARN;
01382 goto done;
01383 }
01384
01385
01386 if (glue0->get_codec){
01387 glue0->get_codec(c0, cap0);
01388 }
01389 if (glue1->get_codec) {
01390 glue1->get_codec(c1, cap1);
01391 }
01392 if (!ast_format_cap_is_empty(cap0) && !ast_format_cap_is_empty(cap1) && !ast_format_cap_has_joint(cap0, cap1)) {
01393 char tmp0[256] = { 0, };
01394 char tmp1[256] = { 0, };
01395 ast_debug(1, "Channel codec0 = %s is not codec1 = %s, cannot native bridge in RTP.\n",
01396 ast_getformatname_multiple(tmp0, sizeof(tmp0), cap0),
01397 ast_getformatname_multiple(tmp1, sizeof(tmp1), cap1));
01398 res = AST_BRIDGE_FAILED_NOWARN;
01399 goto done;
01400 }
01401
01402 instance0->glue = glue0;
01403 instance1->glue = glue1;
01404 instance0->chan = c0;
01405 instance1->chan = c1;
01406
01407
01408 if (audio_glue0_res == AST_RTP_GLUE_RESULT_LOCAL || audio_glue1_res == AST_RTP_GLUE_RESULT_LOCAL) {
01409 ast_verb(3, "Locally bridging %s and %s\n", ast_channel_name(c0), ast_channel_name(c1));
01410 res = local_bridge_loop(c0, c1, instance0, instance1, timeoutms, flags, fo, rc, ast_channel_tech_pvt(c0), ast_channel_tech_pvt(c1));
01411 } else {
01412 ast_verb(3, "Remotely bridging %s and %s\n", ast_channel_name(c0), ast_channel_name(c1));
01413 res = remote_bridge_loop(c0, c1, instance0, instance1, vinstance0, vinstance1,
01414 tinstance0, tinstance1, glue0, glue1, cap0, cap1, timeoutms, flags,
01415 fo, rc, ast_channel_tech_pvt(c0), ast_channel_tech_pvt(c1));
01416 }
01417
01418 instance0->glue = NULL;
01419 instance1->glue = NULL;
01420 instance0->chan = NULL;
01421 instance1->chan = NULL;
01422
01423 unlock_chans = 0;
01424
01425 done:
01426 if (unlock_chans) {
01427 ast_channel_unlock(c0);
01428 ast_channel_unlock(c1);
01429 }
01430 ast_format_cap_destroy(cap1);
01431 ast_format_cap_destroy(cap0);
01432
01433 unref_instance_cond(&instance0);
01434 unref_instance_cond(&instance1);
01435 unref_instance_cond(&vinstance0);
01436 unref_instance_cond(&vinstance1);
01437 unref_instance_cond(&tinstance0);
01438 unref_instance_cond(&tinstance1);
01439
01440 return res;
01441 }
01442
01443 struct ast_rtp_instance *ast_rtp_instance_get_bridged(struct ast_rtp_instance *instance)
01444 {
01445 return instance->bridged;
01446 }
01447
01448 void ast_rtp_instance_early_bridge_make_compatible(struct ast_channel *c0, struct ast_channel *c1)
01449 {
01450 struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
01451 *vinstance0 = NULL, *vinstance1 = NULL,
01452 *tinstance0 = NULL, *tinstance1 = NULL;
01453 struct ast_rtp_glue *glue0, *glue1;
01454 enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
01455 enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
01456 struct ast_format_cap *cap0 = ast_format_cap_alloc_nolock();
01457 struct ast_format_cap *cap1 = ast_format_cap_alloc_nolock();
01458
01459
01460 ast_channel_lock_both(c0, c1);
01461
01462 if (!cap1 || !cap0) {
01463 goto done;
01464 }
01465
01466
01467 if (!(glue0 = ast_rtp_instance_get_glue(ast_channel_tech(c0)->type)) || !(glue1 = ast_rtp_instance_get_glue(ast_channel_tech(c1)->type))) {
01468 ast_debug(1, "Can't find native functions for channel '%s'\n", glue0 ? ast_channel_name(c1) : ast_channel_name(c0));
01469 goto done;
01470 }
01471
01472 audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
01473 video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;
01474
01475 audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
01476 video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;
01477
01478
01479 if (video_glue0_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue0_res != AST_RTP_GLUE_RESULT_REMOTE)) {
01480 audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
01481 }
01482 if (video_glue1_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue1_res != AST_RTP_GLUE_RESULT_REMOTE)) {
01483 audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
01484 }
01485 if (audio_glue0_res == AST_RTP_GLUE_RESULT_REMOTE && (video_glue0_res == AST_RTP_GLUE_RESULT_FORBID || video_glue0_res == AST_RTP_GLUE_RESULT_REMOTE) && glue0->get_codec) {
01486 glue0->get_codec(c0, cap0);
01487 }
01488 if (audio_glue1_res == AST_RTP_GLUE_RESULT_REMOTE && (video_glue1_res == AST_RTP_GLUE_RESULT_FORBID || video_glue1_res == AST_RTP_GLUE_RESULT_REMOTE) && glue1->get_codec) {
01489 glue1->get_codec(c1, cap1);
01490 }
01491
01492
01493 if (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE) {
01494 goto done;
01495 }
01496
01497
01498 if (!ast_format_cap_has_joint(cap0, cap1)) {
01499 goto done;
01500 }
01501
01502 ast_rtp_codecs_payloads_copy(&instance0->codecs, &instance1->codecs, instance1);
01503
01504 if (vinstance0 && vinstance1) {
01505 ast_rtp_codecs_payloads_copy(&vinstance0->codecs, &vinstance1->codecs, vinstance1);
01506 }
01507 if (tinstance0 && tinstance1) {
01508 ast_rtp_codecs_payloads_copy(&tinstance0->codecs, &tinstance1->codecs, tinstance1);
01509 }
01510
01511 if (glue0->update_peer(c0, instance1, vinstance1, tinstance1, cap1, 0)) {
01512 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n",
01513 ast_channel_name(c0), ast_channel_name(c1));
01514 } else {
01515 ast_debug(1, "Seeded SDP of '%s' with that of '%s'\n",
01516 ast_channel_name(c0), ast_channel_name(c1));
01517 }
01518
01519 done:
01520 ast_channel_unlock(c0);
01521 ast_channel_unlock(c1);
01522
01523 ast_format_cap_destroy(cap0);
01524 ast_format_cap_destroy(cap1);
01525
01526 unref_instance_cond(&instance0);
01527 unref_instance_cond(&instance1);
01528 unref_instance_cond(&vinstance0);
01529 unref_instance_cond(&vinstance1);
01530 unref_instance_cond(&tinstance0);
01531 unref_instance_cond(&tinstance1);
01532 }
01533
01534 int ast_rtp_instance_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
01535 {
01536 struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
01537 *vinstance0 = NULL, *vinstance1 = NULL,
01538 *tinstance0 = NULL, *tinstance1 = NULL;
01539 struct ast_rtp_glue *glue0, *glue1;
01540 enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
01541 enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
01542 struct ast_format_cap *cap0 = ast_format_cap_alloc_nolock();
01543 struct ast_format_cap *cap1 = ast_format_cap_alloc_nolock();
01544 int res = 0;
01545
01546
01547 if (!c1) {
01548 ast_format_cap_destroy(cap0);
01549 ast_format_cap_destroy(cap1);
01550 return -1;
01551 }
01552
01553
01554 ast_channel_lock(c0);
01555 while (ast_channel_trylock(c1)) {
01556 ast_channel_unlock(c0);
01557 usleep(1);
01558 ast_channel_lock(c0);
01559 }
01560
01561 if (!cap1 || !cap0) {
01562 goto done;
01563 }
01564
01565
01566 if (!(glue0 = ast_rtp_instance_get_glue(ast_channel_tech(c0)->type)) || !(glue1 = ast_rtp_instance_get_glue(ast_channel_tech(c1)->type))) {
01567 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", glue0 ? ast_channel_name(c1) : ast_channel_name(c0));
01568 goto done;
01569 }
01570
01571 audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
01572 video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;
01573
01574 audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
01575 video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;
01576
01577
01578 if (video_glue0_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue0_res != AST_RTP_GLUE_RESULT_REMOTE)) {
01579 audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
01580 }
01581 if (video_glue1_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue1_res != AST_RTP_GLUE_RESULT_REMOTE)) {
01582 audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
01583 }
01584 if (audio_glue0_res == AST_RTP_GLUE_RESULT_REMOTE && (video_glue0_res == AST_RTP_GLUE_RESULT_FORBID || video_glue0_res == AST_RTP_GLUE_RESULT_REMOTE) && glue0->get_codec) {
01585 glue0->get_codec(c0, cap0);
01586 }
01587 if (audio_glue1_res == AST_RTP_GLUE_RESULT_REMOTE && (video_glue1_res == AST_RTP_GLUE_RESULT_FORBID || video_glue1_res == AST_RTP_GLUE_RESULT_REMOTE) && glue1->get_codec) {
01588 glue1->get_codec(c1, cap1);
01589 }
01590
01591
01592 if (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE) {
01593 goto done;
01594 }
01595
01596
01597 if (!ast_format_cap_has_joint(cap0, cap1)) {
01598 goto done;
01599 }
01600
01601
01602 if (glue0->update_peer(c0, instance1, vinstance1, tinstance1, cap1, 0)) {
01603 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", ast_channel_name(c0), c1 ? ast_channel_name(c1) : "<unspecified>");
01604 }
01605
01606 res = 0;
01607
01608 done:
01609 ast_channel_unlock(c0);
01610 ast_channel_unlock(c1);
01611
01612 ast_format_cap_destroy(cap0);
01613 ast_format_cap_destroy(cap1);
01614
01615 unref_instance_cond(&instance0);
01616 unref_instance_cond(&instance1);
01617 unref_instance_cond(&vinstance0);
01618 unref_instance_cond(&vinstance1);
01619 unref_instance_cond(&tinstance0);
01620 unref_instance_cond(&tinstance1);
01621
01622 if (!res) {
01623 ast_debug(1, "Setting early bridge SDP of '%s' with that of '%s'\n", ast_channel_name(c0), c1 ? ast_channel_name(c1) : "<unspecified>");
01624 }
01625
01626 return res;
01627 }
01628
01629 int ast_rtp_red_init(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations)
01630 {
01631 return instance->engine->red_init ? instance->engine->red_init(instance, buffer_time, payloads, generations) : -1;
01632 }
01633
01634 int ast_rtp_red_buffer(struct ast_rtp_instance *instance, struct ast_frame *frame)
01635 {
01636 return instance->engine->red_buffer ? instance->engine->red_buffer(instance, frame) : -1;
01637 }
01638
01639 int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
01640 {
01641 return instance->engine->get_stat ? instance->engine->get_stat(instance, stats, stat) : -1;
01642 }
01643
01644 char *ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size)
01645 {
01646 struct ast_rtp_instance_stats stats = { 0, };
01647 enum ast_rtp_instance_stat stat;
01648
01649
01650 if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY) {
01651 stat = AST_RTP_INSTANCE_STAT_ALL;
01652 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
01653 stat = AST_RTP_INSTANCE_STAT_COMBINED_JITTER;
01654 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
01655 stat = AST_RTP_INSTANCE_STAT_COMBINED_LOSS;
01656 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
01657 stat = AST_RTP_INSTANCE_STAT_COMBINED_RTT;
01658 } else {
01659 return NULL;
01660 }
01661
01662
01663 if (ast_rtp_instance_get_stats(instance, &stats, stat)) {
01664 return NULL;
01665 }
01666
01667
01668 if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY) {
01669 snprintf(buf, size, "ssrc=%i;themssrc=%u;lp=%u;rxjitter=%f;rxcount=%u;txjitter=%f;txcount=%u;rlp=%u;rtt=%f",
01670 stats.local_ssrc, stats.remote_ssrc, stats.rxploss, stats.txjitter, stats.rxcount, stats.rxjitter, stats.txcount, stats.txploss, stats.rtt);
01671 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
01672 snprintf(buf, size, "minrxjitter=%f;maxrxjitter=%f;avgrxjitter=%f;stdevrxjitter=%f;reported_minjitter=%f;reported_maxjitter=%f;reported_avgjitter=%f;reported_stdevjitter=%f;",
01673 stats.local_minjitter, stats.local_maxjitter, stats.local_normdevjitter, sqrt(stats.local_stdevjitter), stats.remote_minjitter, stats.remote_maxjitter, stats.remote_normdevjitter, sqrt(stats.remote_stdevjitter));
01674 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
01675 snprintf(buf, size, "minrxlost=%f;maxrxlost=%f;avgrxlost=%f;stdevrxlost=%f;reported_minlost=%f;reported_maxlost=%f;reported_avglost=%f;reported_stdevlost=%f;",
01676 stats.local_minrxploss, stats.local_maxrxploss, stats.local_normdevrxploss, sqrt(stats.local_stdevrxploss), stats.remote_minrxploss, stats.remote_maxrxploss, stats.remote_normdevrxploss, sqrt(stats.remote_stdevrxploss));
01677 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
01678 snprintf(buf, size, "minrtt=%f;maxrtt=%f;avgrtt=%f;stdevrtt=%f;", stats.minrtt, stats.maxrtt, stats.normdevrtt, stats.stdevrtt);
01679 }
01680
01681 return buf;
01682 }
01683
01684 void ast_rtp_instance_set_stats_vars(struct ast_channel *chan, struct ast_rtp_instance *instance)
01685 {
01686 char quality_buf[AST_MAX_USER_FIELD], *quality;
01687 struct ast_channel *bridge = ast_bridged_channel(chan);
01688
01689 if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
01690 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOS", quality);
01691 if (bridge) {
01692 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSBRIDGED", quality);
01693 }
01694 }
01695
01696 if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, quality_buf, sizeof(quality_buf)))) {
01697 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSJITTER", quality);
01698 if (bridge) {
01699 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSJITTERBRIDGED", quality);
01700 }
01701 }
01702
01703 if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, quality_buf, sizeof(quality_buf)))) {
01704 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSLOSS", quality);
01705 if (bridge) {
01706 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSLOSSBRIDGED", quality);
01707 }
01708 }
01709
01710 if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, quality_buf, sizeof(quality_buf)))) {
01711 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSRTT", quality);
01712 if (bridge) {
01713 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSRTTBRIDGED", quality);
01714 }
01715 }
01716 }
01717
01718 int ast_rtp_instance_set_read_format(struct ast_rtp_instance *instance, struct ast_format *format)
01719 {
01720 return instance->engine->set_read_format ? instance->engine->set_read_format(instance, format) : -1;
01721 }
01722
01723 int ast_rtp_instance_set_write_format(struct ast_rtp_instance *instance, struct ast_format *format)
01724 {
01725 return instance->engine->set_write_format ? instance->engine->set_write_format(instance, format) : -1;
01726 }
01727
01728 int ast_rtp_instance_make_compatible(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_channel *peer)
01729 {
01730 struct ast_rtp_glue *glue;
01731 struct ast_rtp_instance *peer_instance = NULL;
01732 int res = -1;
01733
01734 if (!instance->engine->make_compatible) {
01735 return -1;
01736 }
01737
01738 ast_channel_lock(peer);
01739
01740 if (!(glue = ast_rtp_instance_get_glue(ast_channel_tech(peer)->type))) {
01741 ast_channel_unlock(peer);
01742 return -1;
01743 }
01744
01745 glue->get_rtp_info(peer, &peer_instance);
01746
01747 if (!peer_instance || peer_instance->engine != instance->engine) {
01748 ast_channel_unlock(peer);
01749 ao2_ref(peer_instance, -1);
01750 peer_instance = NULL;
01751 return -1;
01752 }
01753
01754 res = instance->engine->make_compatible(chan, instance, peer, peer_instance);
01755
01756 ast_channel_unlock(peer);
01757
01758 ao2_ref(peer_instance, -1);
01759 peer_instance = NULL;
01760
01761 return res;
01762 }
01763
01764 void ast_rtp_instance_available_formats(struct ast_rtp_instance *instance, struct ast_format_cap *to_endpoint, struct ast_format_cap *to_asterisk, struct ast_format_cap *result)
01765 {
01766 if (instance->engine->available_formats) {
01767 instance->engine->available_formats(instance, to_endpoint, to_asterisk, result);
01768 if (!ast_format_cap_is_empty(result)) {
01769 return;
01770 }
01771 }
01772
01773 ast_translate_available_formats(to_endpoint, to_asterisk, result);
01774 }
01775
01776 int ast_rtp_instance_activate(struct ast_rtp_instance *instance)
01777 {
01778 return instance->engine->activate ? instance->engine->activate(instance) : 0;
01779 }
01780
01781 void ast_rtp_instance_stun_request(struct ast_rtp_instance *instance,
01782 struct ast_sockaddr *suggestion,
01783 const char *username)
01784 {
01785 if (instance->engine->stun_request) {
01786 instance->engine->stun_request(instance, suggestion, username);
01787 }
01788 }
01789
01790 void ast_rtp_instance_set_timeout(struct ast_rtp_instance *instance, int timeout)
01791 {
01792 instance->timeout = timeout;
01793 }
01794
01795 void ast_rtp_instance_set_hold_timeout(struct ast_rtp_instance *instance, int timeout)
01796 {
01797 instance->holdtimeout = timeout;
01798 }
01799
01800 void ast_rtp_instance_set_keepalive(struct ast_rtp_instance *instance, int interval)
01801 {
01802 instance->keepalive = interval;
01803 }
01804
01805 int ast_rtp_instance_get_timeout(struct ast_rtp_instance *instance)
01806 {
01807 return instance->timeout;
01808 }
01809
01810 int ast_rtp_instance_get_hold_timeout(struct ast_rtp_instance *instance)
01811 {
01812 return instance->holdtimeout;
01813 }
01814
01815 int ast_rtp_instance_get_keepalive(struct ast_rtp_instance *instance)
01816 {
01817 return instance->keepalive;
01818 }
01819
01820 struct ast_rtp_engine *ast_rtp_instance_get_engine(struct ast_rtp_instance *instance)
01821 {
01822 return instance->engine;
01823 }
01824
01825 struct ast_rtp_glue *ast_rtp_instance_get_active_glue(struct ast_rtp_instance *instance)
01826 {
01827 return instance->glue;
01828 }
01829
01830 struct ast_channel *ast_rtp_instance_get_chan(struct ast_rtp_instance *instance)
01831 {
01832 return instance->chan;
01833 }
01834
01835 int ast_rtp_engine_register_srtp(struct ast_srtp_res *srtp_res, struct ast_srtp_policy_res *policy_res)
01836 {
01837 if (res_srtp || res_srtp_policy) {
01838 return -1;
01839 }
01840 if (!srtp_res || !policy_res) {
01841 return -1;
01842 }
01843
01844 res_srtp = srtp_res;
01845 res_srtp_policy = policy_res;
01846
01847 return 0;
01848 }
01849
01850 void ast_rtp_engine_unregister_srtp(void)
01851 {
01852 res_srtp = NULL;
01853 res_srtp_policy = NULL;
01854 }
01855
01856 int ast_rtp_engine_srtp_is_registered(void)
01857 {
01858 return res_srtp && res_srtp_policy;
01859 }
01860
01861 int ast_rtp_instance_add_srtp_policy(struct ast_rtp_instance *instance, struct ast_srtp_policy *remote_policy, struct ast_srtp_policy *local_policy)
01862 {
01863 int res = 0;
01864
01865 if (!res_srtp) {
01866 return -1;
01867 }
01868
01869 if (!instance->srtp) {
01870 res = res_srtp->create(&instance->srtp, instance, remote_policy);
01871 } else {
01872 res = res_srtp->replace(&instance->srtp, instance, remote_policy);
01873 }
01874 if (!res) {
01875 res = res_srtp->add_stream(instance->srtp, local_policy);
01876 }
01877
01878 return res;
01879 }
01880
01881 struct ast_srtp *ast_rtp_instance_get_srtp(struct ast_rtp_instance *instance)
01882 {
01883 return instance->srtp;
01884 }
01885
01886 int ast_rtp_instance_sendcng(struct ast_rtp_instance *instance, int level)
01887 {
01888 if (instance->engine->sendcng) {
01889 return instance->engine->sendcng(instance, level);
01890 }
01891
01892 return -1;
01893 }
01894
01895 static void set_next_mime_type(const struct ast_format *format, int rtp_code, char *type, char *subtype, unsigned int sample_rate)
01896 {
01897 int x = mime_types_len;
01898 if (ARRAY_LEN(ast_rtp_mime_types) == mime_types_len) {
01899 return;
01900 }
01901
01902 ast_rwlock_wrlock(&mime_types_lock);
01903 if (format) {
01904 ast_rtp_mime_types[x].payload_type.asterisk_format = 1;
01905 ast_format_copy(&ast_rtp_mime_types[x].payload_type.format, format);
01906 } else {
01907 ast_rtp_mime_types[x].payload_type.rtp_code = rtp_code;
01908 }
01909 ast_rtp_mime_types[x].type = type;
01910 ast_rtp_mime_types[x].subtype = subtype;
01911 ast_rtp_mime_types[x].sample_rate = sample_rate;
01912 mime_types_len++;
01913 ast_rwlock_unlock(&mime_types_lock);
01914 }
01915
01916 static void add_static_payload(int map, const struct ast_format *format, int rtp_code)
01917 {
01918 int x;
01919 ast_rwlock_wrlock(&static_RTP_PT_lock);
01920 if (map < 0) {
01921
01922 for (x = 96; x < 127; x++) {
01923 if (!static_RTP_PT[x].asterisk_format && !static_RTP_PT[x].rtp_code) {
01924 map = x;
01925 break;
01926 }
01927 }
01928 }
01929
01930 if (map < 0) {
01931 ast_log(LOG_WARNING, "No Dynamic RTP mapping avaliable for format %s\n" ,ast_getformatname(format));
01932 ast_rwlock_unlock(&static_RTP_PT_lock);
01933 return;
01934 }
01935
01936 if (format) {
01937 static_RTP_PT[map].asterisk_format = 1;
01938 ast_format_copy(&static_RTP_PT[map].format, format);
01939 } else {
01940 static_RTP_PT[map].rtp_code = rtp_code;
01941 }
01942 ast_rwlock_unlock(&static_RTP_PT_lock);
01943 }
01944
01945 int ast_rtp_engine_load_format(const struct ast_format *format)
01946 {
01947 switch (format->id) {
01948 case AST_FORMAT_SILK:
01949 set_next_mime_type(format, 0, "audio", "SILK", ast_format_rate(format));
01950 add_static_payload(-1, format, 0);
01951 break;
01952 case AST_FORMAT_CELT:
01953 set_next_mime_type(format, 0, "audio", "CELT", ast_format_rate(format));
01954 add_static_payload(-1, format, 0);
01955 break;
01956 default:
01957 break;
01958 }
01959
01960 return 0;
01961 }
01962
01963 int ast_rtp_engine_unload_format(const struct ast_format *format)
01964 {
01965 int x;
01966 int y = 0;
01967
01968 ast_rwlock_wrlock(&static_RTP_PT_lock);
01969
01970 for (x = 0; x < AST_RTP_MAX_PT; x++) {
01971 if (ast_format_cmp(&static_RTP_PT[x].format, format) == AST_FORMAT_CMP_EQUAL) {
01972 memset(&static_RTP_PT[x], 0, sizeof(struct ast_rtp_payload_type));
01973 }
01974 }
01975 ast_rwlock_unlock(&static_RTP_PT_lock);
01976
01977
01978 ast_rwlock_wrlock(&mime_types_lock);
01979
01980 for (x = 0; x < mime_types_len; x++) {
01981 if (ast_format_cmp(&ast_rtp_mime_types[x].payload_type.format, format) == AST_FORMAT_CMP_EQUAL) {
01982 continue;
01983 }
01984 ast_rtp_mime_types[y] = ast_rtp_mime_types[x];
01985 y++;
01986 }
01987 mime_types_len = y;
01988 ast_rwlock_unlock(&mime_types_lock);
01989 return 0;
01990 }
01991
01992 int ast_rtp_engine_init()
01993 {
01994 struct ast_format tmpfmt;
01995
01996 ast_rwlock_init(&mime_types_lock);
01997 ast_rwlock_init(&static_RTP_PT_lock);
01998
01999
02000 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G723_1, 0), 0, "audio", "G723", 8000);
02001 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_GSM, 0), 0, "audio", "GSM", 8000);
02002 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0), 0, "audio", "PCMU", 8000);
02003 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0), 0, "audio", "G711U", 8000);
02004 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0), 0, "audio", "PCMA", 8000);
02005 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0), 0, "audio", "G711A", 8000);
02006 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G726, 0), 0, "audio", "G726-32", 8000);
02007 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_ADPCM, 0), 0, "audio", "DVI4", 8000);
02008 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0), 0, "audio", "L16", 8000);
02009 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR16, 0), 0, "audio", "L16", 16000);
02010 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR16, 0), 0, "audio", "L16-256", 16000);
02011 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_LPC10, 0), 0, "audio", "LPC", 8000);
02012 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G729A, 0), 0, "audio", "G729", 8000);
02013 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G729A, 0), 0, "audio", "G729A", 8000);
02014 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G729A, 0), 0, "audio", "G.729", 8000);
02015 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SPEEX, 0), 0, "audio", "speex", 8000);
02016 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SPEEX16, 0), 0, "audio", "speex", 16000);
02017 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SPEEX32, 0), 0, "audio", "speex", 32000);
02018 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_ILBC, 0), 0, "audio", "iLBC", 8000);
02019
02020 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G722, 0), 0, "audio", "G722", 8000);
02021 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G726_AAL2, 0), 0, "audio", "AAL2-G726-32", 8000);
02022 set_next_mime_type(NULL, AST_RTP_DTMF, "audio", "telephone-event", 8000);
02023 set_next_mime_type(NULL, AST_RTP_CISCO_DTMF, "audio", "cisco-telephone-event", 8000);
02024 set_next_mime_type(NULL, AST_RTP_CN, "audio", "CN", 8000);
02025 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_JPEG, 0), 0, "video", "JPEG", 90000);
02026 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_PNG, 0), 0, "video", "PNG", 90000);
02027 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_H261, 0), 0, "video", "H261", 90000);
02028 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_H263, 0), 0, "video", "H263", 90000);
02029 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_H263_PLUS, 0), 0, "video", "h263-1998", 90000);
02030 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_H264, 0), 0, "video", "H264", 90000);
02031 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_MP4_VIDEO, 0), 0, "video", "MP4V-ES", 90000);
02032 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_T140RED, 0), 0, "text", "RED", 1000);
02033 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_T140, 0), 0, "text", "T140", 1000);
02034 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SIREN7, 0), 0, "audio", "G7221", 16000);
02035 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SIREN14, 0), 0, "audio", "G7221", 32000);
02036 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G719, 0), 0, "audio", "G719", 48000);
02037
02038
02039 add_static_payload(0, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0), 0);
02040 #ifdef USE_DEPRECATED_G726
02041 add_static_payload(2, ast_format_set(&tmpfmt, AST_FORMAT_G726, 0), 0);
02042 #endif
02043 add_static_payload(3, ast_format_set(&tmpfmt, AST_FORMAT_GSM, 0), 0);
02044 add_static_payload(4, ast_format_set(&tmpfmt, AST_FORMAT_G723_1, 0), 0);
02045 add_static_payload(5, ast_format_set(&tmpfmt, AST_FORMAT_ADPCM, 0), 0);
02046 add_static_payload(6, ast_format_set(&tmpfmt, AST_FORMAT_ADPCM, 0), 0);
02047 add_static_payload(7, ast_format_set(&tmpfmt, AST_FORMAT_LPC10, 0), 0);
02048 add_static_payload(8, ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0), 0);
02049 add_static_payload(9, ast_format_set(&tmpfmt, AST_FORMAT_G722, 0), 0);
02050 add_static_payload(10, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0), 0);
02051 add_static_payload(11, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0), 0);
02052 add_static_payload(13, NULL, AST_RTP_CN);
02053 add_static_payload(16, ast_format_set(&tmpfmt, AST_FORMAT_ADPCM, 0), 0);
02054 add_static_payload(17, ast_format_set(&tmpfmt, AST_FORMAT_ADPCM, 0), 0);
02055 add_static_payload(18, ast_format_set(&tmpfmt, AST_FORMAT_G729A, 0), 0);
02056 add_static_payload(19, NULL, AST_RTP_CN);
02057 add_static_payload(26, ast_format_set(&tmpfmt, AST_FORMAT_JPEG, 0), 0);
02058 add_static_payload(31, ast_format_set(&tmpfmt, AST_FORMAT_H261, 0), 0);
02059 add_static_payload(34, ast_format_set(&tmpfmt, AST_FORMAT_H263, 0), 0);
02060 add_static_payload(97, ast_format_set(&tmpfmt, AST_FORMAT_ILBC, 0), 0);
02061 add_static_payload(98, ast_format_set(&tmpfmt, AST_FORMAT_H263_PLUS, 0), 0);
02062 add_static_payload(99, ast_format_set(&tmpfmt, AST_FORMAT_H264, 0), 0);
02063 add_static_payload(101, NULL, AST_RTP_DTMF);
02064 add_static_payload(102, ast_format_set(&tmpfmt, AST_FORMAT_SIREN7, 0), 0);
02065 add_static_payload(103, ast_format_set(&tmpfmt, AST_FORMAT_H263_PLUS, 0), 0);
02066 add_static_payload(104, ast_format_set(&tmpfmt, AST_FORMAT_MP4_VIDEO, 0), 0);
02067 add_static_payload(105, ast_format_set(&tmpfmt, AST_FORMAT_T140RED, 0), 0);
02068 add_static_payload(106, ast_format_set(&tmpfmt, AST_FORMAT_T140, 0), 0);
02069 add_static_payload(110, ast_format_set(&tmpfmt, AST_FORMAT_SPEEX, 0), 0);
02070 add_static_payload(111, ast_format_set(&tmpfmt, AST_FORMAT_G726, 0), 0);
02071 add_static_payload(112, ast_format_set(&tmpfmt, AST_FORMAT_G726_AAL2, 0), 0);
02072 add_static_payload(115, ast_format_set(&tmpfmt, AST_FORMAT_SIREN14, 0), 0);
02073 add_static_payload(116, ast_format_set(&tmpfmt, AST_FORMAT_G719, 0), 0);
02074 add_static_payload(117, ast_format_set(&tmpfmt, AST_FORMAT_SPEEX16, 0), 0);
02075 add_static_payload(118, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR16, 0), 0);
02076 add_static_payload(119, ast_format_set(&tmpfmt, AST_FORMAT_SPEEX32, 0), 0);
02077 add_static_payload(121, NULL, AST_RTP_CISCO_DTMF);
02078
02079 return 0;
02080 }