2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2008, Digium, Inc.
6 * Joshua Colp <jcolp@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief Pluggable RTP Architecture
23 * \author Joshua Colp <jcolp@digium.com>
27 <support_level>core</support_level>
32 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
36 #include "asterisk/channel.h"
37 #include "asterisk/frame.h"
38 #include "asterisk/module.h"
39 #include "asterisk/rtp_engine.h"
40 #include "asterisk/manager.h"
41 #include "asterisk/options.h"
42 #include "asterisk/astobj2.h"
43 #include "asterisk/pbx.h"
44 #include "asterisk/translate.h"
45 #include "asterisk/netsock2.h"
46 #include "asterisk/_private.h"
47 #include "asterisk/framehook.h"
49 struct ast_srtp_res *res_srtp = NULL;
50 struct ast_srtp_policy_res *res_srtp_policy = NULL;
52 /*! Structure that represents an RTP session (instance) */
53 struct ast_rtp_instance {
54 /*! Engine that is handling this RTP instance */
55 struct ast_rtp_engine *engine;
56 /*! Data unique to the RTP engine */
58 /*! RTP properties that have been set and their value */
59 int properties[AST_RTP_PROPERTY_MAX];
60 /*! Address that we are expecting RTP to come in to */
61 struct ast_sockaddr local_address;
62 /*! Address that we are sending RTP to */
63 struct ast_sockaddr remote_address;
64 /*! Alternate address that we are receiving RTP from */
65 struct ast_sockaddr alt_remote_address;
66 /*! Instance that we are bridged to if doing remote or local bridging */
67 struct ast_rtp_instance *bridged;
68 /*! Payload and packetization information */
69 struct ast_rtp_codecs codecs;
70 /*! RTP timeout time (negative or zero means disabled, negative value means temporarily disabled) */
72 /*! RTP timeout when on hold (negative or zero means disabled, negative value means temporarily disabled). */
74 /*! RTP keepalive interval */
76 /*! Glue currently in use */
77 struct ast_rtp_glue *glue;
78 /*! Channel associated with the instance */
79 struct ast_channel *chan;
80 /*! SRTP info associated with the instance */
81 struct ast_srtp *srtp;
84 /*! List of RTP engines that are currently registered */
85 static AST_RWLIST_HEAD_STATIC(engines, ast_rtp_engine);
87 /*! List of RTP glues */
88 static AST_RWLIST_HEAD_STATIC(glues, ast_rtp_glue);
90 /*! The following array defines the MIME Media type (and subtype) for each
91 of our codecs, or RTP-specific data type. */
92 static struct ast_rtp_mime_type {
93 struct ast_rtp_payload_type payload_type;
96 unsigned int sample_rate;
97 } ast_rtp_mime_types[128]; /* This will Likely not need to grow any time soon. */
98 static ast_rwlock_t mime_types_lock;
99 static int mime_types_len = 0;
102 * \brief Mapping between Asterisk codecs and rtp payload types
104 * Static (i.e., well-known) RTP payload types for our "AST_FORMAT..."s:
105 * also, our own choices for dynamic payload types. This is our master
106 * table for transmission
108 * See http://www.iana.org/assignments/rtp-parameters for a list of
111 static struct ast_rtp_payload_type static_RTP_PT[AST_RTP_MAX_PT];
112 static ast_rwlock_t static_RTP_PT_lock;
114 int ast_rtp_engine_register2(struct ast_rtp_engine *engine, struct ast_module *module)
116 struct ast_rtp_engine *current_engine;
118 /* Perform a sanity check on the engine structure to make sure it has the basics */
119 if (ast_strlen_zero(engine->name) || !engine->new || !engine->destroy || !engine->write || !engine->read) {
120 ast_log(LOG_WARNING, "RTP Engine '%s' failed sanity check so it was not registered.\n", !ast_strlen_zero(engine->name) ? engine->name : "Unknown");
124 /* Link owner module to the RTP engine for reference counting purposes */
125 engine->mod = module;
127 AST_RWLIST_WRLOCK(&engines);
129 /* Ensure that no two modules with the same name are registered at the same time */
130 AST_RWLIST_TRAVERSE(&engines, current_engine, entry) {
131 if (!strcmp(current_engine->name, engine->name)) {
132 ast_log(LOG_WARNING, "An RTP engine with the name '%s' has already been registered.\n", engine->name);
133 AST_RWLIST_UNLOCK(&engines);
138 /* The engine survived our critique. Off to the list it goes to be used */
139 AST_RWLIST_INSERT_TAIL(&engines, engine, entry);
141 AST_RWLIST_UNLOCK(&engines);
143 ast_verb(2, "Registered RTP engine '%s'\n", engine->name);
148 int ast_rtp_engine_unregister(struct ast_rtp_engine *engine)
150 struct ast_rtp_engine *current_engine = NULL;
152 AST_RWLIST_WRLOCK(&engines);
154 if ((current_engine = AST_RWLIST_REMOVE(&engines, engine, entry))) {
155 ast_verb(2, "Unregistered RTP engine '%s'\n", engine->name);
158 AST_RWLIST_UNLOCK(&engines);
160 return current_engine ? 0 : -1;
163 int ast_rtp_glue_register2(struct ast_rtp_glue *glue, struct ast_module *module)
165 struct ast_rtp_glue *current_glue = NULL;
167 if (ast_strlen_zero(glue->type)) {
173 AST_RWLIST_WRLOCK(&glues);
175 AST_RWLIST_TRAVERSE(&glues, current_glue, entry) {
176 if (!strcasecmp(current_glue->type, glue->type)) {
177 ast_log(LOG_WARNING, "RTP glue with the name '%s' has already been registered.\n", glue->type);
178 AST_RWLIST_UNLOCK(&glues);
183 AST_RWLIST_INSERT_TAIL(&glues, glue, entry);
185 AST_RWLIST_UNLOCK(&glues);
187 ast_verb(2, "Registered RTP glue '%s'\n", glue->type);
192 int ast_rtp_glue_unregister(struct ast_rtp_glue *glue)
194 struct ast_rtp_glue *current_glue = NULL;
196 AST_RWLIST_WRLOCK(&glues);
198 if ((current_glue = AST_RWLIST_REMOVE(&glues, glue, entry))) {
199 ast_verb(2, "Unregistered RTP glue '%s'\n", glue->type);
202 AST_RWLIST_UNLOCK(&glues);
204 return current_glue ? 0 : -1;
207 static void instance_destructor(void *obj)
209 struct ast_rtp_instance *instance = obj;
211 /* Pass us off to the engine to destroy */
212 if (instance->data && instance->engine->destroy(instance)) {
213 ast_debug(1, "Engine '%s' failed to destroy RTP instance '%p'\n", instance->engine->name, instance);
217 if (instance->srtp) {
218 res_srtp->destroy(instance->srtp);
221 ast_rtp_codecs_payloads_destroy(&instance->codecs);
223 /* Drop our engine reference */
224 ast_module_unref(instance->engine->mod);
226 ast_debug(1, "Destroyed RTP instance '%p'\n", instance);
229 int ast_rtp_instance_destroy(struct ast_rtp_instance *instance)
231 ao2_ref(instance, -1);
236 struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name,
237 struct ast_sched_context *sched, const struct ast_sockaddr *sa,
240 struct ast_sockaddr address = {{0,}};
241 struct ast_rtp_instance *instance = NULL;
242 struct ast_rtp_engine *engine = NULL;
244 AST_RWLIST_RDLOCK(&engines);
246 /* If an engine name was specified try to use it or otherwise use the first one registered */
247 if (!ast_strlen_zero(engine_name)) {
248 AST_RWLIST_TRAVERSE(&engines, engine, entry) {
249 if (!strcmp(engine->name, engine_name)) {
254 engine = AST_RWLIST_FIRST(&engines);
257 /* If no engine was actually found bail out now */
259 ast_log(LOG_ERROR, "No RTP engine was found. Do you have one loaded?\n");
260 AST_RWLIST_UNLOCK(&engines);
264 /* Bump up the reference count before we return so the module can not be unloaded */
265 ast_module_ref(engine->mod);
267 AST_RWLIST_UNLOCK(&engines);
269 /* Allocate a new RTP instance */
270 if (!(instance = ao2_alloc(sizeof(*instance), instance_destructor))) {
271 ast_module_unref(engine->mod);
274 instance->engine = engine;
275 ast_sockaddr_copy(&instance->local_address, sa);
276 ast_sockaddr_copy(&address, sa);
278 if (ast_rtp_codecs_payloads_initialize(&instance->codecs)) {
279 ao2_ref(instance, -1);
283 ast_debug(1, "Using engine '%s' for RTP instance '%p'\n", engine->name, instance);
285 /* And pass it off to the engine to setup */
286 if (instance->engine->new(instance, sched, &address, data)) {
287 ast_debug(1, "Engine '%s' failed to setup RTP instance '%p'\n", engine->name, instance);
288 ao2_ref(instance, -1);
292 ast_debug(1, "RTP instance '%p' is setup and ready to go\n", instance);
297 void ast_rtp_instance_set_data(struct ast_rtp_instance *instance, void *data)
299 instance->data = data;
302 void *ast_rtp_instance_get_data(struct ast_rtp_instance *instance)
304 return instance->data;
307 int ast_rtp_instance_write(struct ast_rtp_instance *instance, struct ast_frame *frame)
309 return instance->engine->write(instance, frame);
312 struct ast_frame *ast_rtp_instance_read(struct ast_rtp_instance *instance, int rtcp)
314 return instance->engine->read(instance, rtcp);
317 int ast_rtp_instance_set_local_address(struct ast_rtp_instance *instance,
318 const struct ast_sockaddr *address)
320 ast_sockaddr_copy(&instance->local_address, address);
324 int ast_rtp_instance_set_remote_address(struct ast_rtp_instance *instance,
325 const struct ast_sockaddr *address)
327 ast_sockaddr_copy(&instance->remote_address, address);
331 if (instance->engine->remote_address_set) {
332 instance->engine->remote_address_set(instance, &instance->remote_address);
338 int ast_rtp_instance_set_alt_remote_address(struct ast_rtp_instance *instance,
339 const struct ast_sockaddr *address)
341 ast_sockaddr_copy(&instance->alt_remote_address, address);
345 if (instance->engine->alt_remote_address_set) {
346 instance->engine->alt_remote_address_set(instance, &instance->alt_remote_address);
352 int ast_rtp_instance_get_and_cmp_local_address(struct ast_rtp_instance *instance,
353 struct ast_sockaddr *address)
355 if (ast_sockaddr_cmp(address, &instance->local_address) != 0) {
356 ast_sockaddr_copy(address, &instance->local_address);
363 void ast_rtp_instance_get_local_address(struct ast_rtp_instance *instance,
364 struct ast_sockaddr *address)
366 ast_sockaddr_copy(address, &instance->local_address);
369 int ast_rtp_instance_get_and_cmp_remote_address(struct ast_rtp_instance *instance,
370 struct ast_sockaddr *address)
372 if (ast_sockaddr_cmp(address, &instance->remote_address) != 0) {
373 ast_sockaddr_copy(address, &instance->remote_address);
380 void ast_rtp_instance_get_remote_address(struct ast_rtp_instance *instance,
381 struct ast_sockaddr *address)
383 ast_sockaddr_copy(address, &instance->remote_address);
386 void ast_rtp_instance_set_extended_prop(struct ast_rtp_instance *instance, int property, void *value)
388 if (instance->engine->extended_prop_set) {
389 instance->engine->extended_prop_set(instance, property, value);
393 void *ast_rtp_instance_get_extended_prop(struct ast_rtp_instance *instance, int property)
395 if (instance->engine->extended_prop_get) {
396 return instance->engine->extended_prop_get(instance, property);
402 void ast_rtp_instance_set_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value)
404 instance->properties[property] = value;
406 if (instance->engine->prop_set) {
407 instance->engine->prop_set(instance, property, value);
411 int ast_rtp_instance_get_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property)
413 return instance->properties[property];
416 struct ast_rtp_codecs *ast_rtp_instance_get_codecs(struct ast_rtp_instance *instance)
418 return &instance->codecs;
421 static int rtp_payload_type_hash(const void *obj, const int flags)
423 const struct ast_rtp_payload_type *type = obj;
424 const int *payload = obj;
426 return (flags & OBJ_KEY) ? *payload : type->payload;
429 static int rtp_payload_type_cmp(void *obj, void *arg, int flags)
431 struct ast_rtp_payload_type *type1 = obj, *type2 = arg;
432 const int *payload = arg;
434 return (type1->payload == (OBJ_KEY ? *payload : type2->payload)) ? CMP_MATCH | CMP_STOP : 0;
437 int ast_rtp_codecs_payloads_initialize(struct ast_rtp_codecs *codecs)
439 if (!(codecs->payloads = ao2_container_alloc(AST_RTP_MAX_PT, rtp_payload_type_hash, rtp_payload_type_cmp))) {
446 void ast_rtp_codecs_payloads_destroy(struct ast_rtp_codecs *codecs)
448 ao2_cleanup(codecs->payloads);
451 void ast_rtp_codecs_payloads_clear(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance)
453 ast_rtp_codecs_payloads_destroy(codecs);
455 if (instance && instance->engine && instance->engine->payload_set) {
457 for (i = 0; i < AST_RTP_MAX_PT; i++) {
458 instance->engine->payload_set(instance, i, 0, NULL, 0);
462 ast_rtp_codecs_payloads_initialize(codecs);
465 void ast_rtp_codecs_payloads_default(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance)
469 ast_rwlock_rdlock(&static_RTP_PT_lock);
470 for (i = 0; i < AST_RTP_MAX_PT; i++) {
471 if (static_RTP_PT[i].rtp_code || static_RTP_PT[i].asterisk_format) {
472 struct ast_rtp_payload_type *type;
474 if (!(type = ao2_alloc(sizeof(*type), NULL))) {
475 /* Unfortunately if this occurs the payloads container will not contain all possible default payloads
476 * but we err on the side of doing what we can in the hopes that the extreme memory conditions which
477 * caused this to occur will go away.
483 type->asterisk_format = static_RTP_PT[i].asterisk_format;
484 type->rtp_code = static_RTP_PT[i].rtp_code;
485 ast_format_copy(&type->format, &static_RTP_PT[i].format);
487 ao2_link_flags(codecs->payloads, type, OBJ_NOLOCK);
489 if (instance && instance->engine && instance->engine->payload_set) {
490 instance->engine->payload_set(instance, i, type->asterisk_format, &type->format, type->rtp_code);
496 ast_rwlock_unlock(&static_RTP_PT_lock);
499 void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
502 struct ast_rtp_payload_type *type;
504 for (i = 0; i < AST_RTP_MAX_PT; i++) {
505 struct ast_rtp_payload_type *new_type;
507 if (!(type = ao2_find(src->payloads, &i, OBJ_KEY | OBJ_NOLOCK))) {
511 if (!(new_type = ao2_alloc(sizeof(*new_type), NULL))) {
515 ast_debug(2, "Copying payload %d from %p to %p\n", i, src, dest);
517 new_type->payload = i;
520 ao2_link_flags(dest->payloads, new_type, OBJ_NOLOCK);
522 ao2_ref(new_type, -1);
524 if (instance && instance->engine && instance->engine->payload_set) {
525 instance->engine->payload_set(instance, i, type->asterisk_format, &type->format, type->rtp_code);
532 void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
534 struct ast_rtp_payload_type *type;
536 ast_rwlock_rdlock(&static_RTP_PT_lock);
538 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
539 ast_rwlock_unlock(&static_RTP_PT_lock);
543 if (!(type = ao2_find(codecs->payloads, &payload, OBJ_KEY | OBJ_NOLOCK))) {
544 if (!(type = ao2_alloc(sizeof(*type), NULL))) {
545 ast_rwlock_unlock(&static_RTP_PT_lock);
548 type->payload = payload;
549 ao2_link_flags(codecs->payloads, type, OBJ_NOLOCK);
552 type->asterisk_format = static_RTP_PT[payload].asterisk_format;
553 type->rtp_code = static_RTP_PT[payload].rtp_code;
554 type->payload = payload;
555 ast_format_copy(&type->format, &static_RTP_PT[payload].format);
557 ast_debug(1, "Setting payload %d based on m type on %p\n", payload, codecs);
559 if (instance && instance->engine && instance->engine->payload_set) {
560 instance->engine->payload_set(instance, payload, type->asterisk_format, &type->format, type->rtp_code);
565 ast_rwlock_unlock(&static_RTP_PT_lock);
568 int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int pt,
569 char *mimetype, char *mimesubtype,
570 enum ast_rtp_options options,
571 unsigned int sample_rate)
576 if (pt < 0 || pt >= AST_RTP_MAX_PT)
577 return -1; /* bogus payload type */
579 ast_rwlock_rdlock(&mime_types_lock);
580 for (i = 0; i < mime_types_len; ++i) {
581 const struct ast_rtp_mime_type *t = &ast_rtp_mime_types[i];
582 struct ast_rtp_payload_type *type;
584 if (strcasecmp(mimesubtype, t->subtype)) {
588 if (strcasecmp(mimetype, t->type)) {
592 /* if both sample rates have been supplied, and they don't match,
593 * then this not a match; if one has not been supplied, then the
594 * rates are not compared */
595 if (sample_rate && t->sample_rate &&
596 (sample_rate != t->sample_rate)) {
602 if (!(type = ao2_find(codecs->payloads, &pt, OBJ_KEY | OBJ_NOLOCK))) {
603 if (!(type = ao2_alloc(sizeof(*type), NULL))) {
607 ao2_link_flags(codecs->payloads, type, OBJ_NOLOCK);
610 *type = t->payload_type;
613 if ((t->payload_type.format.id == AST_FORMAT_G726) && t->payload_type.asterisk_format && (options & AST_RTP_OPT_G726_NONSTANDARD)) {
614 ast_format_set(&type->format, AST_FORMAT_G726_AAL2, 0);
617 if (instance && instance->engine && instance->engine->payload_set) {
618 instance->engine->payload_set(instance, pt, type->asterisk_format, &type->format, type->rtp_code);
625 ast_rwlock_unlock(&mime_types_lock);
627 return (found ? 0 : -2);
630 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)
632 return ast_rtp_codecs_payloads_set_rtpmap_type_rate(codecs, instance, payload, mimetype, mimesubtype, options, 0);
635 void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
637 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
641 ast_debug(2, "Unsetting payload %d on %p\n", payload, codecs);
643 ao2_find(codecs->payloads, &payload, OBJ_KEY | OBJ_NOLOCK | OBJ_NODATA | OBJ_UNLINK);
645 if (instance && instance->engine && instance->engine->payload_set) {
646 instance->engine->payload_set(instance, payload, 0, NULL, 0);
650 struct ast_rtp_payload_type ast_rtp_codecs_payload_lookup(struct ast_rtp_codecs *codecs, int payload)
652 struct ast_rtp_payload_type result = { .asterisk_format = 0, }, *type;
654 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
658 if ((type = ao2_find(codecs->payloads, &payload, OBJ_KEY | OBJ_NOLOCK))) {
663 if (!result.rtp_code && !result.asterisk_format) {
664 ast_rwlock_rdlock(&static_RTP_PT_lock);
665 result = static_RTP_PT[payload];
666 ast_rwlock_unlock(&static_RTP_PT_lock);
673 struct ast_format *ast_rtp_codecs_get_payload_format(struct ast_rtp_codecs *codecs, int payload)
675 struct ast_rtp_payload_type *type;
676 struct ast_format *format;
678 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
682 if (!(type = ao2_find(codecs->payloads, &payload, OBJ_KEY | OBJ_NOLOCK))) {
686 format = type->asterisk_format ? &type->format : NULL;
693 static int rtp_payload_type_add_ast(void *obj, void *arg, int flags)
695 struct ast_rtp_payload_type *type = obj;
696 struct ast_format_cap *astformats = arg;
698 if (type->asterisk_format) {
699 ast_format_cap_add(astformats, &type->format);
705 static int rtp_payload_type_add_nonast(void *obj, void *arg, int flags)
707 struct ast_rtp_payload_type *type = obj;
708 int *nonastformats = arg;
710 if (!type->asterisk_format) {
711 *nonastformats |= type->rtp_code;
717 void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, struct ast_format_cap *astformats, int *nonastformats)
719 ast_format_cap_remove_all(astformats);
722 ao2_callback(codecs->payloads, OBJ_NODATA | OBJ_MULTIPLE | OBJ_NOLOCK, rtp_payload_type_add_ast, astformats);
723 ao2_callback(codecs->payloads, OBJ_NODATA | OBJ_MULTIPLE | OBJ_NOLOCK, rtp_payload_type_add_nonast, nonastformats);
726 static int rtp_payload_type_find_format(void *obj, void *arg, int flags)
728 struct ast_rtp_payload_type *type = obj;
729 struct ast_format *format = arg;
731 return (type->asterisk_format && (ast_format_cmp(&type->format, format) != AST_FORMAT_CMP_NOT_EQUAL)) ? CMP_MATCH | CMP_STOP : 0;
734 int ast_rtp_codecs_payload_code(struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code)
736 struct ast_rtp_payload_type *type;
739 if (asterisk_format && format && (type = ao2_callback(codecs->payloads, OBJ_NOLOCK, rtp_payload_type_find_format, (void*)format))) {
743 } else if (!asterisk_format && (type = ao2_find(codecs->payloads, &code, OBJ_NOLOCK | OBJ_KEY))) {
749 ast_rwlock_rdlock(&static_RTP_PT_lock);
750 for (i = 0; i < AST_RTP_MAX_PT; i++) {
751 if (static_RTP_PT[i].asterisk_format && asterisk_format && format &&
752 (ast_format_cmp(format, &static_RTP_PT[i].format) != AST_FORMAT_CMP_NOT_EQUAL)) {
755 } else if (!static_RTP_PT[i].asterisk_format && !asterisk_format &&
756 (static_RTP_PT[i].rtp_code == code)) {
761 ast_rwlock_unlock(&static_RTP_PT_lock);
765 int ast_rtp_codecs_find_payload_code(struct ast_rtp_codecs *codecs, int code)
767 struct ast_rtp_payload_type *type;
770 /* Search the payload type in the codecs passed */
771 if ((type = ao2_find(codecs->payloads, &code, OBJ_NOLOCK | OBJ_KEY)))
780 const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format, struct ast_format *format, int code, enum ast_rtp_options options)
783 const char *res = "";
785 ast_rwlock_rdlock(&mime_types_lock);
786 for (i = 0; i < mime_types_len; i++) {
787 if (ast_rtp_mime_types[i].payload_type.asterisk_format && asterisk_format && format &&
788 (ast_format_cmp(format, &ast_rtp_mime_types[i].payload_type.format) != AST_FORMAT_CMP_NOT_EQUAL)) {
789 if ((format->id == AST_FORMAT_G726_AAL2) && (options & AST_RTP_OPT_G726_NONSTANDARD)) {
793 res = ast_rtp_mime_types[i].subtype;
796 } else if (!ast_rtp_mime_types[i].payload_type.asterisk_format && !asterisk_format &&
797 ast_rtp_mime_types[i].payload_type.rtp_code == code) {
799 res = ast_rtp_mime_types[i].subtype;
803 ast_rwlock_unlock(&mime_types_lock);
808 unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format, struct ast_format *format, int code)
811 unsigned int res = 0;
813 ast_rwlock_rdlock(&mime_types_lock);
814 for (i = 0; i < mime_types_len; ++i) {
815 if (ast_rtp_mime_types[i].payload_type.asterisk_format && asterisk_format && format &&
816 (ast_format_cmp(format, &ast_rtp_mime_types[i].payload_type.format) != AST_FORMAT_CMP_NOT_EQUAL)) {
817 res = ast_rtp_mime_types[i].sample_rate;
819 } else if (!ast_rtp_mime_types[i].payload_type.asterisk_format && !asterisk_format &&
820 ast_rtp_mime_types[i].payload_type.rtp_code == code) {
821 res = ast_rtp_mime_types[i].sample_rate;
825 ast_rwlock_unlock(&mime_types_lock);
830 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)
839 if (asterisk_format) {
840 struct ast_format tmp_fmt;
841 ast_format_cap_iter_start(ast_format_capability);
842 while (!ast_format_cap_iter_next(ast_format_capability, &tmp_fmt)) {
843 name = ast_rtp_lookup_mime_subtype2(asterisk_format, &tmp_fmt, 0, options);
844 ast_str_append(&buf, 0, "%s|", name);
847 ast_format_cap_iter_end(ast_format_capability);
851 ast_str_append(&buf, 0, "0x%x (", (unsigned int) rtp_capability);
852 for (x = 1; x <= AST_RTP_MAX; x <<= 1) {
853 if (rtp_capability & x) {
854 name = ast_rtp_lookup_mime_subtype2(asterisk_format, NULL, x, options);
855 ast_str_append(&buf, 0, "%s|", name);
861 ast_str_append(&buf, 0, "%s", found ? ")" : "nothing)");
863 return ast_str_buffer(buf);
866 void ast_rtp_codecs_packetization_set(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, struct ast_codec_pref *prefs)
868 codecs->pref = *prefs;
870 if (instance && instance->engine->packetization_set) {
871 instance->engine->packetization_set(instance, &instance->codecs.pref);
875 int ast_rtp_instance_dtmf_begin(struct ast_rtp_instance *instance, char digit)
877 return instance->engine->dtmf_begin ? instance->engine->dtmf_begin(instance, digit) : -1;
880 int ast_rtp_instance_dtmf_end(struct ast_rtp_instance *instance, char digit)
882 return instance->engine->dtmf_end ? instance->engine->dtmf_end(instance, digit) : -1;
884 int ast_rtp_instance_dtmf_end_with_duration(struct ast_rtp_instance *instance, char digit, unsigned int duration)
886 return instance->engine->dtmf_end_with_duration ? instance->engine->dtmf_end_with_duration(instance, digit, duration) : -1;
889 int ast_rtp_instance_dtmf_mode_set(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode)
891 return (!instance->engine->dtmf_mode_set || instance->engine->dtmf_mode_set(instance, dtmf_mode)) ? -1 : 0;
894 enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get(struct ast_rtp_instance *instance)
896 return instance->engine->dtmf_mode_get ? instance->engine->dtmf_mode_get(instance) : 0;
899 void ast_rtp_instance_update_source(struct ast_rtp_instance *instance)
901 if (instance->engine->update_source) {
902 instance->engine->update_source(instance);
906 void ast_rtp_instance_change_source(struct ast_rtp_instance *instance)
908 if (instance->engine->change_source) {
909 instance->engine->change_source(instance);
913 int ast_rtp_instance_set_qos(struct ast_rtp_instance *instance, int tos, int cos, const char *desc)
915 return instance->engine->qos ? instance->engine->qos(instance, tos, cos, desc) : -1;
918 void ast_rtp_instance_stop(struct ast_rtp_instance *instance)
920 if (instance->engine->stop) {
921 instance->engine->stop(instance);
925 int ast_rtp_instance_fd(struct ast_rtp_instance *instance, int rtcp)
927 return instance->engine->fd ? instance->engine->fd(instance, rtcp) : -1;
930 struct ast_rtp_glue *ast_rtp_instance_get_glue(const char *type)
932 struct ast_rtp_glue *glue = NULL;
934 AST_RWLIST_RDLOCK(&glues);
936 AST_RWLIST_TRAVERSE(&glues, glue, entry) {
937 if (!strcasecmp(glue->type, type)) {
942 AST_RWLIST_UNLOCK(&glues);
947 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)
949 enum ast_bridge_result res = AST_BRIDGE_FAILED;
950 struct ast_channel *who = NULL, *other = NULL, *cs[3] = { NULL, };
951 struct ast_frame *fr = NULL;
952 struct timeval start;
954 /* Start locally bridging both instances */
955 if (instance0->engine->local_bridge && instance0->engine->local_bridge(instance0, instance1)) {
956 ast_debug(1, "Failed to locally bridge %s to %s, backing out.\n", ast_channel_name(c0), ast_channel_name(c1));
957 ast_channel_unlock(c0);
958 ast_channel_unlock(c1);
959 return AST_BRIDGE_FAILED_NOWARN;
961 if (instance1->engine->local_bridge && instance1->engine->local_bridge(instance1, instance0)) {
962 ast_debug(1, "Failed to locally bridge %s to %s, backing out.\n", ast_channel_name(c1), ast_channel_name(c0));
963 if (instance0->engine->local_bridge) {
964 instance0->engine->local_bridge(instance0, NULL);
966 ast_channel_unlock(c0);
967 ast_channel_unlock(c1);
968 return AST_BRIDGE_FAILED_NOWARN;
971 ast_channel_unlock(c0);
972 ast_channel_unlock(c1);
974 instance0->bridged = instance1;
975 instance1->bridged = instance0;
977 ast_poll_channel_add(c0, c1);
979 /* Hop into a loop waiting for a frame from either channel */
986 /* If the underlying formats have changed force this bridge to break */
987 if ((ast_format_cmp(ast_channel_rawreadformat(c0), ast_channel_rawwriteformat(c1)) == AST_FORMAT_CMP_NOT_EQUAL) ||
988 (ast_format_cmp(ast_channel_rawreadformat(c1), ast_channel_rawwriteformat(c0)) == AST_FORMAT_CMP_NOT_EQUAL)) {
989 ast_debug(1, "rtp-engine-local-bridge: Oooh, formats changed, backing out\n");
990 res = AST_BRIDGE_FAILED_NOWARN;
993 /* Check if anything changed */
994 if ((ast_channel_tech_pvt(c0) != pvt0) ||
995 (ast_channel_tech_pvt(c1) != pvt1) ||
996 (ast_channel_masq(c0) || ast_channel_masqr(c0) || ast_channel_masq(c1) || ast_channel_masqr(c1)) ||
997 (ast_channel_monitor(c0) || ast_channel_audiohooks(c0) || ast_channel_monitor(c1) || ast_channel_audiohooks(c1)) ||
998 (!ast_framehook_list_is_empty(ast_channel_framehooks(c0)) || !ast_framehook_list_is_empty(ast_channel_framehooks(c1)))) {
999 ast_debug(1, "rtp-engine-local-bridge: Oooh, something is weird, backing out\n");
1000 /* If a masquerade needs to happen we have to try to read in a frame so that it actually happens. Without this we risk being called again and going into a loop */
1001 if ((ast_channel_masq(c0) || ast_channel_masqr(c0)) && (fr = ast_read(c0))) {
1004 if ((ast_channel_masq(c1) || ast_channel_masqr(c1)) && (fr = ast_read(c1))) {
1007 res = AST_BRIDGE_RETRY;
1010 /* Wait on a channel to feed us a frame */
1011 ms = ast_remaining_ms(start, timeoutms);
1012 if (!(who = ast_waitfor_n(cs, 2, &ms))) {
1014 res = AST_BRIDGE_RETRY;
1017 ast_debug(2, "rtp-engine-local-bridge: Ooh, empty read...\n");
1018 if (ast_check_hangup(c0) || ast_check_hangup(c1)) {
1023 /* Read in frame from channel */
1025 other = (who == c0) ? c1 : c0;
1026 /* Depending on the frame we may need to break out of our bridge */
1027 if (!fr || ((fr->frametype == AST_FRAME_DTMF_BEGIN || fr->frametype == AST_FRAME_DTMF_END) &&
1028 ((who == c0) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) |
1029 ((who == c1) && (flags & AST_BRIDGE_DTMF_CHANNEL_1)))) {
1030 /* Record received frame and who */
1033 ast_debug(1, "rtp-engine-local-bridge: Ooh, got a %s\n", fr ? "digit" : "hangup");
1034 res = AST_BRIDGE_COMPLETE;
1036 } else if ((fr->frametype == AST_FRAME_CONTROL) && !(flags & AST_BRIDGE_IGNORE_SIGS)) {
1037 if ((fr->subclass.integer == AST_CONTROL_HOLD) ||
1038 (fr->subclass.integer == AST_CONTROL_UNHOLD) ||
1039 (fr->subclass.integer == AST_CONTROL_VIDUPDATE) ||
1040 (fr->subclass.integer == AST_CONTROL_SRCUPDATE) ||
1041 (fr->subclass.integer == AST_CONTROL_T38_PARAMETERS) ||
1042 (fr->subclass.integer == AST_CONTROL_UPDATE_RTP_PEER)) {
1043 /* If we are going on hold, then break callback mode and P2P bridging */
1044 if (fr->subclass.integer == AST_CONTROL_HOLD) {
1045 if (instance0->engine->local_bridge) {
1046 instance0->engine->local_bridge(instance0, NULL);
1048 if (instance1->engine->local_bridge) {
1049 instance1->engine->local_bridge(instance1, NULL);
1051 instance0->bridged = NULL;
1052 instance1->bridged = NULL;
1053 } else if (fr->subclass.integer == AST_CONTROL_UNHOLD) {
1054 if (instance0->engine->local_bridge) {
1055 instance0->engine->local_bridge(instance0, instance1);
1057 if (instance1->engine->local_bridge) {
1058 instance1->engine->local_bridge(instance1, instance0);
1060 instance0->bridged = instance1;
1061 instance1->bridged = instance0;
1063 /* Since UPDATE_BRIDGE_PEER is only used by the bridging code, don't forward it */
1064 if (fr->subclass.integer != AST_CONTROL_UPDATE_RTP_PEER) {
1065 ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
1068 } else if (fr->subclass.integer == AST_CONTROL_CONNECTED_LINE) {
1069 if (ast_channel_connected_line_sub(who, other, fr, 1) &&
1070 ast_channel_connected_line_macro(who, other, fr, other == c0, 1)) {
1071 ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
1074 } else if (fr->subclass.integer == AST_CONTROL_REDIRECTING) {
1075 if (ast_channel_redirecting_sub(who, other, fr, 1) &&
1076 ast_channel_redirecting_macro(who, other, fr, other == c0, 1)) {
1077 ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
1080 } else if (fr->subclass.integer == AST_CONTROL_PVT_CAUSE_CODE) {
1081 ast_channel_hangupcause_hash_set(other, fr->data.ptr, fr->datalen);
1086 ast_debug(1, "rtp-engine-local-bridge: Got a FRAME_CONTROL (%d) frame on channel %s\n", fr->subclass.integer, ast_channel_name(who));
1087 res = AST_BRIDGE_COMPLETE;
1091 if ((fr->frametype == AST_FRAME_DTMF_BEGIN) ||
1092 (fr->frametype == AST_FRAME_DTMF_END) ||
1093 (fr->frametype == AST_FRAME_VOICE) ||
1094 (fr->frametype == AST_FRAME_VIDEO) ||
1095 (fr->frametype == AST_FRAME_IMAGE) ||
1096 (fr->frametype == AST_FRAME_HTML) ||
1097 (fr->frametype == AST_FRAME_MODEM) ||
1098 (fr->frametype == AST_FRAME_TEXT)) {
1099 ast_write(other, fr);
1110 /* Stop locally bridging both instances */
1111 if (instance0->engine->local_bridge) {
1112 instance0->engine->local_bridge(instance0, NULL);
1114 if (instance1->engine->local_bridge) {
1115 instance1->engine->local_bridge(instance1, NULL);
1118 instance0->bridged = NULL;
1119 instance1->bridged = NULL;
1121 ast_poll_channel_del(c0, c1);
1126 static enum ast_bridge_result remote_bridge_loop(struct ast_channel *c0,
1127 struct ast_channel *c1,
1128 struct ast_rtp_instance *instance0,
1129 struct ast_rtp_instance *instance1,
1130 struct ast_rtp_instance *vinstance0,
1131 struct ast_rtp_instance *vinstance1,
1132 struct ast_rtp_instance *tinstance0,
1133 struct ast_rtp_instance *tinstance1,
1134 struct ast_rtp_glue *glue0,
1135 struct ast_rtp_glue *glue1,
1136 struct ast_format_cap *cap0,
1137 struct ast_format_cap *cap1,
1140 struct ast_frame **fo,
1141 struct ast_channel **rc,
1145 enum ast_bridge_result res = AST_BRIDGE_FAILED;
1146 struct ast_channel *who = NULL, *other = NULL, *cs[3] = { NULL, };
1147 struct ast_format_cap *oldcap0 = ast_format_cap_dup(cap0);
1148 struct ast_format_cap *oldcap1 = ast_format_cap_dup(cap1);
1149 struct ast_sockaddr ac1 = {{0,}}, vac1 = {{0,}}, tac1 = {{0,}}, ac0 = {{0,}}, vac0 = {{0,}}, tac0 = {{0,}};
1150 struct ast_sockaddr t1 = {{0,}}, vt1 = {{0,}}, tt1 = {{0,}}, t0 = {{0,}}, vt0 = {{0,}}, tt0 = {{0,}};
1151 struct ast_frame *fr = NULL;
1152 struct timeval start;
1154 if (!oldcap0 || !oldcap1) {
1155 ast_channel_unlock(c0);
1156 ast_channel_unlock(c1);
1157 goto remote_bridge_cleanup;
1159 /* Test the first channel */
1160 if (!(glue0->update_peer(c0, instance1, vinstance1, tinstance1, cap1, 0))) {
1161 ast_rtp_instance_get_remote_address(instance1, &ac1);
1163 ast_rtp_instance_get_remote_address(vinstance1, &vac1);
1166 ast_rtp_instance_get_remote_address(tinstance1, &tac1);
1169 ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", ast_channel_name(c0), ast_channel_name(c1));
1172 /* Test the second channel */
1173 if (!(glue1->update_peer(c1, instance0, vinstance0, tinstance0, cap0, 0))) {
1174 ast_rtp_instance_get_remote_address(instance0, &ac0);
1176 ast_rtp_instance_get_remote_address(instance0, &vac0);
1179 ast_rtp_instance_get_remote_address(instance0, &tac0);
1182 ast_log(LOG_WARNING, "Channel '%s' failed to talk to '%s'\n", ast_channel_name(c1), ast_channel_name(c0));
1185 ast_channel_unlock(c0);
1186 ast_channel_unlock(c1);
1188 instance0->bridged = instance1;
1189 instance1->bridged = instance0;
1191 ast_poll_channel_add(c0, c1);
1193 /* Go into a loop handling any stray frames that may come in */
1197 start = ast_tvnow();
1200 /* Check if anything changed */
1201 if ((ast_channel_tech_pvt(c0) != pvt0) ||
1202 (ast_channel_tech_pvt(c1) != pvt1) ||
1203 (ast_channel_masq(c0) || ast_channel_masqr(c0) || ast_channel_masq(c1) || ast_channel_masqr(c1)) ||
1204 (ast_channel_monitor(c0) || ast_channel_audiohooks(c0) || ast_channel_monitor(c1) || ast_channel_audiohooks(c1)) ||
1205 (!ast_framehook_list_is_empty(ast_channel_framehooks(c0)) || !ast_framehook_list_is_empty(ast_channel_framehooks(c1)))) {
1206 ast_debug(1, "Oooh, something is weird, backing out\n");
1207 res = AST_BRIDGE_RETRY;
1211 /* Check if they have changed their address */
1212 ast_rtp_instance_get_remote_address(instance1, &t1);
1214 ast_rtp_instance_get_remote_address(vinstance1, &vt1);
1217 ast_rtp_instance_get_remote_address(tinstance1, &tt1);
1219 if (glue1->get_codec) {
1220 ast_format_cap_remove_all(cap1);
1221 glue1->get_codec(c1, cap1);
1224 ast_rtp_instance_get_remote_address(instance0, &t0);
1226 ast_rtp_instance_get_remote_address(vinstance0, &vt0);
1229 ast_rtp_instance_get_remote_address(tinstance0, &tt0);
1231 if (glue0->get_codec) {
1232 ast_format_cap_remove_all(cap0);
1233 glue0->get_codec(c0, cap0);
1236 if ((ast_sockaddr_cmp(&t1, &ac1)) ||
1237 (vinstance1 && ast_sockaddr_cmp(&vt1, &vac1)) ||
1238 (tinstance1 && ast_sockaddr_cmp(&tt1, &tac1)) ||
1239 (!ast_format_cap_identical(cap1, oldcap1))) {
1240 char tmp_buf[512] = { 0, };
1241 ast_debug(1, "Oooh, '%s' changed end address to %s (format %s)\n",
1242 ast_channel_name(c1), ast_sockaddr_stringify(&t1),
1243 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), cap1));
1244 ast_debug(1, "Oooh, '%s' changed end vaddress to %s (format %s)\n",
1245 ast_channel_name(c1), ast_sockaddr_stringify(&vt1),
1246 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), cap1));
1247 ast_debug(1, "Oooh, '%s' changed end taddress to %s (format %s)\n",
1248 ast_channel_name(c1), ast_sockaddr_stringify(&tt1),
1249 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), cap1));
1250 ast_debug(1, "Oooh, '%s' was %s/(format %s)\n",
1251 ast_channel_name(c1), ast_sockaddr_stringify(&ac1),
1252 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), oldcap1));
1253 ast_debug(1, "Oooh, '%s' was %s/(format %s)\n",
1254 ast_channel_name(c1), ast_sockaddr_stringify(&vac1),
1255 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), oldcap1));
1256 ast_debug(1, "Oooh, '%s' was %s/(format %s)\n",
1257 ast_channel_name(c1), ast_sockaddr_stringify(&tac1),
1258 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), oldcap1));
1259 if (glue0->update_peer(c0,
1260 ast_sockaddr_isnull(&t1) ? NULL : instance1,
1261 ast_sockaddr_isnull(&vt1) ? NULL : vinstance1,
1262 ast_sockaddr_isnull(&tt1) ? NULL : tinstance1,
1264 ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", ast_channel_name(c0), ast_channel_name(c1));
1266 ast_sockaddr_copy(&ac1, &t1);
1267 ast_sockaddr_copy(&vac1, &vt1);
1268 ast_sockaddr_copy(&tac1, &tt1);
1269 ast_format_cap_copy(oldcap1, cap1);
1271 if ((ast_sockaddr_cmp(&t0, &ac0)) ||
1272 (vinstance0 && ast_sockaddr_cmp(&vt0, &vac0)) ||
1273 (tinstance0 && ast_sockaddr_cmp(&tt0, &tac0)) ||
1274 (!ast_format_cap_identical(cap0, oldcap0))) {
1275 char tmp_buf[512] = { 0, };
1276 ast_debug(1, "Oooh, '%s' changed end address to %s (format %s)\n",
1277 ast_channel_name(c0), ast_sockaddr_stringify(&t0),
1278 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), cap0));
1279 ast_debug(1, "Oooh, '%s' was %s/(format %s)\n",
1280 ast_channel_name(c0), ast_sockaddr_stringify(&ac0),
1281 ast_getformatname_multiple(tmp_buf, sizeof(tmp_buf), oldcap0));
1282 if (glue1->update_peer(c1, t0.len ? instance0 : NULL,
1283 vt0.len ? vinstance0 : NULL,
1284 tt0.len ? tinstance0 : NULL,
1286 ast_log(LOG_WARNING, "Channel '%s' failed to update to '%s'\n", ast_channel_name(c1), ast_channel_name(c0));
1288 ast_sockaddr_copy(&ac0, &t0);
1289 ast_sockaddr_copy(&vac0, &vt0);
1290 ast_sockaddr_copy(&tac0, &tt0);
1291 ast_format_cap_copy(oldcap0, cap0);
1294 ms = ast_remaining_ms(start, timeoutms);
1295 /* Wait for frame to come in on the channels */
1296 if (!(who = ast_waitfor_n(cs, 2, &ms))) {
1298 res = AST_BRIDGE_RETRY;
1301 ast_debug(1, "Ooh, empty read...\n");
1302 if (ast_check_hangup(c0) || ast_check_hangup(c1)) {
1308 other = (who == c0) ? c1 : c0;
1309 if (!fr || ((fr->frametype == AST_FRAME_DTMF_BEGIN || fr->frametype == AST_FRAME_DTMF_END) &&
1310 (((who == c0) && (flags & AST_BRIDGE_DTMF_CHANNEL_0)) ||
1311 ((who == c1) && (flags & AST_BRIDGE_DTMF_CHANNEL_1))))) {
1312 /* Break out of bridge */
1315 ast_debug(1, "Oooh, got a %s\n", fr ? "digit" : "hangup");
1316 res = AST_BRIDGE_COMPLETE;
1318 } else if ((fr->frametype == AST_FRAME_CONTROL) && !(flags & AST_BRIDGE_IGNORE_SIGS)) {
1319 if ((fr->subclass.integer == AST_CONTROL_HOLD) ||
1320 (fr->subclass.integer == AST_CONTROL_UNHOLD) ||
1321 (fr->subclass.integer == AST_CONTROL_VIDUPDATE) ||
1322 (fr->subclass.integer == AST_CONTROL_SRCUPDATE) ||
1323 (fr->subclass.integer == AST_CONTROL_T38_PARAMETERS) ||
1324 (fr->subclass.integer == AST_CONTROL_UPDATE_RTP_PEER)) {
1325 if (fr->subclass.integer == AST_CONTROL_HOLD) {
1326 /* If we someone went on hold we want the other side to reinvite back to us */
1328 glue1->update_peer(c1, NULL, NULL, NULL, 0, 0);
1330 glue0->update_peer(c0, NULL, NULL, NULL, 0, 0);
1332 } else if (fr->subclass.integer == AST_CONTROL_UNHOLD ||
1333 fr->subclass.integer == AST_CONTROL_UPDATE_RTP_PEER) {
1334 /* If they went off hold they should go back to being direct, or if we have
1335 * been told to force a peer update, go ahead and do it. */
1337 glue1->update_peer(c1, instance0, vinstance0, tinstance0, cap0, 0);
1339 glue0->update_peer(c0, instance1, vinstance1, tinstance1, cap1, 0);
1342 /* Update local address information */
1343 ast_rtp_instance_get_remote_address(instance0, &t0);
1344 ast_sockaddr_copy(&ac0, &t0);
1345 ast_rtp_instance_get_remote_address(instance1, &t1);
1346 ast_sockaddr_copy(&ac1, &t1);
1347 /* Update codec information */
1348 if (glue0->get_codec && ast_channel_tech_pvt(c0)) {
1349 ast_format_cap_remove_all(cap0);
1350 ast_format_cap_remove_all(oldcap0);
1351 glue0->get_codec(c0, cap0);
1352 ast_format_cap_append(oldcap0, cap0);
1355 if (glue1->get_codec && ast_channel_tech_pvt(c1)) {
1356 ast_format_cap_remove_all(cap1);
1357 ast_format_cap_remove_all(oldcap1);
1358 glue1->get_codec(c1, cap1);
1359 ast_format_cap_append(oldcap1, cap1);
1361 /* Since UPDATE_BRIDGE_PEER is only used by the bridging code, don't forward it */
1362 if (fr->subclass.integer != AST_CONTROL_UPDATE_RTP_PEER) {
1363 ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
1366 } else if (fr->subclass.integer == AST_CONTROL_CONNECTED_LINE) {
1367 if (ast_channel_connected_line_sub(who, other, fr, 1) &&
1368 ast_channel_connected_line_macro(who, other, fr, other == c0, 1)) {
1369 ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
1372 } else if (fr->subclass.integer == AST_CONTROL_REDIRECTING) {
1373 if (ast_channel_redirecting_sub(who, other, fr, 1) &&
1374 ast_channel_redirecting_macro(who, other, fr, other == c0, 1)) {
1375 ast_indicate_data(other, fr->subclass.integer, fr->data.ptr, fr->datalen);
1378 } else if (fr->subclass.integer == AST_CONTROL_PVT_CAUSE_CODE) {
1379 ast_channel_hangupcause_hash_set(other, fr->data.ptr, fr->datalen);
1384 ast_debug(1, "Got a FRAME_CONTROL (%d) frame on channel %s\n", fr->subclass.integer, ast_channel_name(who));
1385 res = AST_BRIDGE_COMPLETE;
1386 goto remote_bridge_cleanup;
1389 if ((fr->frametype == AST_FRAME_DTMF_BEGIN) ||
1390 (fr->frametype == AST_FRAME_DTMF_END) ||
1391 (fr->frametype == AST_FRAME_VOICE) ||
1392 (fr->frametype == AST_FRAME_VIDEO) ||
1393 (fr->frametype == AST_FRAME_IMAGE) ||
1394 (fr->frametype == AST_FRAME_HTML) ||
1395 (fr->frametype == AST_FRAME_MODEM) ||
1396 (fr->frametype == AST_FRAME_TEXT)) {
1397 ast_write(other, fr);
1407 if (ast_test_flag(ast_channel_flags(c0), AST_FLAG_ZOMBIE)) {
1408 ast_debug(1, "Channel '%s' Zombie cleardown from bridge\n", ast_channel_name(c0));
1409 } else if (ast_channel_tech_pvt(c0) != pvt0) {
1410 ast_debug(1, "Channel c0->'%s' pvt changed, in bridge with c1->'%s'\n", ast_channel_name(c0), ast_channel_name(c1));
1411 } else if (glue0 != ast_rtp_instance_get_glue(ast_channel_tech(c0)->type)) {
1412 ast_debug(1, "Channel c0->'%s' technology changed, in bridge with c1->'%s'\n", ast_channel_name(c0), ast_channel_name(c1));
1413 } else if (glue0->update_peer(c0, NULL, NULL, NULL, 0, 0)) {
1414 ast_log(LOG_WARNING, "Channel '%s' failed to break RTP bridge\n", ast_channel_name(c0));
1416 if (ast_test_flag(ast_channel_flags(c1), AST_FLAG_ZOMBIE)) {
1417 ast_debug(1, "Channel '%s' Zombie cleardown from bridge\n", ast_channel_name(c1));
1418 } else if (ast_channel_tech_pvt(c1) != pvt1) {
1419 ast_debug(1, "Channel c1->'%s' pvt changed, in bridge with c0->'%s'\n", ast_channel_name(c1), ast_channel_name(c0));
1420 } else if (glue1 != ast_rtp_instance_get_glue(ast_channel_tech(c1)->type)) {
1421 ast_debug(1, "Channel c1->'%s' technology changed, in bridge with c0->'%s'\n", ast_channel_name(c1), ast_channel_name(c0));
1422 } else if (glue1->update_peer(c1, NULL, NULL, NULL, 0, 0)) {
1423 ast_log(LOG_WARNING, "Channel '%s' failed to break RTP bridge\n", ast_channel_name(c1));
1426 instance0->bridged = NULL;
1427 instance1->bridged = NULL;
1429 ast_poll_channel_del(c0, c1);
1431 remote_bridge_cleanup:
1432 ast_format_cap_destroy(oldcap0);
1433 ast_format_cap_destroy(oldcap1);
1439 * \brief Conditionally unref an rtp instance
1441 static void unref_instance_cond(struct ast_rtp_instance **instance)
1444 ao2_ref(*instance, -1);
1449 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)
1451 struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
1452 *vinstance0 = NULL, *vinstance1 = NULL,
1453 *tinstance0 = NULL, *tinstance1 = NULL;
1454 struct ast_rtp_glue *glue0, *glue1;
1455 struct ast_sockaddr addr1 = { {0, }, }, addr2 = { {0, }, };
1456 enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
1457 enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
1458 enum ast_bridge_result res = AST_BRIDGE_FAILED;
1459 enum ast_rtp_dtmf_mode dmode;
1460 struct ast_format_cap *cap0 = ast_format_cap_alloc_nolock();
1461 struct ast_format_cap *cap1 = ast_format_cap_alloc_nolock();
1462 int unlock_chans = 1;
1464 if (!cap0 || !cap1) {
1469 /* Lock both channels so we can look for the glue that binds them together */
1470 ast_channel_lock_both(c0, c1);
1472 /* Ensure neither channel got hungup during lock avoidance */
1473 if (ast_check_hangup(c0) || ast_check_hangup(c1)) {
1474 ast_log(LOG_WARNING, "Got hangup while attempting to bridge '%s' and '%s'\n", ast_channel_name(c0), ast_channel_name(c1));
1478 /* Grab glue that binds each channel to something using the RTP engine */
1479 if (!(glue0 = ast_rtp_instance_get_glue(ast_channel_tech(c0)->type)) || !(glue1 = ast_rtp_instance_get_glue(ast_channel_tech(c1)->type))) {
1480 ast_debug(1, "Can't find native functions for channel '%s'\n", glue0 ? ast_channel_name(c1) : ast_channel_name(c0));
1484 audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
1485 video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;
1487 audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
1488 video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;
1490 /* Apply any limitations on direct media bridging that may be present */
1491 if (audio_glue0_res == audio_glue1_res && audio_glue1_res == AST_RTP_GLUE_RESULT_REMOTE) {
1492 if (glue0->allow_rtp_remote && !(glue0->allow_rtp_remote(c0, instance1))) {
1493 /* If the allow_rtp_remote indicates that remote isn't allowed, revert to local bridge */
1494 audio_glue0_res = audio_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
1495 } else if (glue1->allow_rtp_remote && !(glue1->allow_rtp_remote(c1, instance0))) {
1496 audio_glue0_res = audio_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
1499 if (video_glue0_res == video_glue1_res && video_glue1_res == AST_RTP_GLUE_RESULT_REMOTE) {
1500 if (glue0->allow_vrtp_remote && !(glue0->allow_vrtp_remote(c0, instance1))) {
1501 /* if the allow_vrtp_remote indicates that remote isn't allowed, revert to local bridge */
1502 video_glue0_res = video_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
1503 } else if (glue1->allow_vrtp_remote && !(glue1->allow_vrtp_remote(c1, instance0))) {
1504 video_glue0_res = video_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
1508 /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
1509 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)) {
1510 audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
1512 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)) {
1513 audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
1516 /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
1517 if (audio_glue0_res == AST_RTP_GLUE_RESULT_FORBID || audio_glue1_res == AST_RTP_GLUE_RESULT_FORBID) {
1518 res = AST_BRIDGE_FAILED_NOWARN;
1523 /* If address families differ, force a local bridge */
1524 ast_rtp_instance_get_remote_address(instance0, &addr1);
1525 ast_rtp_instance_get_remote_address(instance1, &addr2);
1527 if (addr1.ss.ss_family != addr2.ss.ss_family ||
1528 (ast_sockaddr_is_ipv4_mapped(&addr1) != ast_sockaddr_is_ipv4_mapped(&addr2))) {
1529 audio_glue0_res = AST_RTP_GLUE_RESULT_LOCAL;
1530 audio_glue1_res = AST_RTP_GLUE_RESULT_LOCAL;
1533 /* If we need to get DTMF see if we can do it outside of the RTP stream itself */
1534 dmode = ast_rtp_instance_dtmf_mode_get(instance0);
1535 if ((flags & AST_BRIDGE_DTMF_CHANNEL_0) && dmode) {
1536 res = AST_BRIDGE_FAILED_NOWARN;
1539 dmode = ast_rtp_instance_dtmf_mode_get(instance1);
1540 if ((flags & AST_BRIDGE_DTMF_CHANNEL_1) && dmode) {
1541 res = AST_BRIDGE_FAILED_NOWARN;
1545 /* If we have gotten to a local bridge make sure that both sides have the same local bridge callback and that they are DTMF compatible */
1546 if ((audio_glue0_res == AST_RTP_GLUE_RESULT_LOCAL || audio_glue1_res == AST_RTP_GLUE_RESULT_LOCAL)
1547 && (instance0->engine->local_bridge != instance1->engine->local_bridge
1548 || (instance0->engine->dtmf_compatible && !instance0->engine->dtmf_compatible(c0, instance0, c1, instance1)))) {
1549 res = AST_BRIDGE_FAILED_NOWARN;
1553 /* Make sure that codecs match */
1554 if (glue0->get_codec){
1555 glue0->get_codec(c0, cap0);
1557 if (glue1->get_codec) {
1558 glue1->get_codec(c1, cap1);
1560 if (!ast_format_cap_is_empty(cap0) && !ast_format_cap_is_empty(cap1) && !ast_format_cap_has_joint(cap0, cap1)) {
1561 char tmp0[256] = { 0, };
1562 char tmp1[256] = { 0, };
1563 ast_debug(1, "Channel codec0 = %s is not codec1 = %s, cannot native bridge in RTP.\n",
1564 ast_getformatname_multiple(tmp0, sizeof(tmp0), cap0),
1565 ast_getformatname_multiple(tmp1, sizeof(tmp1), cap1));
1566 res = AST_BRIDGE_FAILED_NOWARN;
1570 instance0->glue = glue0;
1571 instance1->glue = glue1;
1572 instance0->chan = c0;
1573 instance1->chan = c1;
1575 /* Depending on the end result for bridging either do a local bridge or remote bridge */
1576 if (audio_glue0_res == AST_RTP_GLUE_RESULT_LOCAL || audio_glue1_res == AST_RTP_GLUE_RESULT_LOCAL) {
1577 ast_verb(3, "Locally bridging %s and %s\n", ast_channel_name(c0), ast_channel_name(c1));
1578 res = local_bridge_loop(c0, c1, instance0, instance1, timeoutms, flags, fo, rc, ast_channel_tech_pvt(c0), ast_channel_tech_pvt(c1));
1580 ast_verb(3, "Remotely bridging %s and %s\n", ast_channel_name(c0), ast_channel_name(c1));
1581 res = remote_bridge_loop(c0, c1, instance0, instance1, vinstance0, vinstance1,
1582 tinstance0, tinstance1, glue0, glue1, cap0, cap1, timeoutms, flags,
1583 fo, rc, ast_channel_tech_pvt(c0), ast_channel_tech_pvt(c1));
1586 instance0->glue = NULL;
1587 instance1->glue = NULL;
1588 instance0->chan = NULL;
1589 instance1->chan = NULL;
1595 ast_channel_unlock(c0);
1596 ast_channel_unlock(c1);
1598 ast_format_cap_destroy(cap1);
1599 ast_format_cap_destroy(cap0);
1601 unref_instance_cond(&instance0);
1602 unref_instance_cond(&instance1);
1603 unref_instance_cond(&vinstance0);
1604 unref_instance_cond(&vinstance1);
1605 unref_instance_cond(&tinstance0);
1606 unref_instance_cond(&tinstance1);
1611 struct ast_rtp_instance *ast_rtp_instance_get_bridged(struct ast_rtp_instance *instance)
1613 return instance->bridged;
1616 void ast_rtp_instance_early_bridge_make_compatible(struct ast_channel *c0, struct ast_channel *c1)
1618 struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
1619 *vinstance0 = NULL, *vinstance1 = NULL,
1620 *tinstance0 = NULL, *tinstance1 = NULL;
1621 struct ast_rtp_glue *glue0, *glue1;
1622 enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
1623 enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
1624 struct ast_format_cap *cap0 = ast_format_cap_alloc_nolock();
1625 struct ast_format_cap *cap1 = ast_format_cap_alloc_nolock();
1627 /* Lock both channels so we can look for the glue that binds them together */
1628 ast_channel_lock_both(c0, c1);
1630 if (!cap1 || !cap0) {
1634 /* Grab glue that binds each channel to something using the RTP engine */
1635 if (!(glue0 = ast_rtp_instance_get_glue(ast_channel_tech(c0)->type)) || !(glue1 = ast_rtp_instance_get_glue(ast_channel_tech(c1)->type))) {
1636 ast_debug(1, "Can't find native functions for channel '%s'\n", glue0 ? ast_channel_name(c1) : ast_channel_name(c0));
1640 audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
1641 video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;
1643 audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
1644 video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;
1646 /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
1647 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)) {
1648 audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
1650 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)) {
1651 audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
1653 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) {
1654 glue0->get_codec(c0, cap0);
1656 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) {
1657 glue1->get_codec(c1, cap1);
1660 /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
1661 if (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE) {
1665 /* Make sure we have matching codecs */
1666 if (!ast_format_cap_has_joint(cap0, cap1)) {
1670 ast_rtp_codecs_payloads_copy(&instance0->codecs, &instance1->codecs, instance1);
1672 if (vinstance0 && vinstance1) {
1673 ast_rtp_codecs_payloads_copy(&vinstance0->codecs, &vinstance1->codecs, vinstance1);
1675 if (tinstance0 && tinstance1) {
1676 ast_rtp_codecs_payloads_copy(&tinstance0->codecs, &tinstance1->codecs, tinstance1);
1679 if (glue0->update_peer(c0, instance1, vinstance1, tinstance1, cap1, 0)) {
1680 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n",
1681 ast_channel_name(c0), ast_channel_name(c1));
1683 ast_debug(1, "Seeded SDP of '%s' with that of '%s'\n",
1684 ast_channel_name(c0), ast_channel_name(c1));
1688 ast_channel_unlock(c0);
1689 ast_channel_unlock(c1);
1691 ast_format_cap_destroy(cap0);
1692 ast_format_cap_destroy(cap1);
1694 unref_instance_cond(&instance0);
1695 unref_instance_cond(&instance1);
1696 unref_instance_cond(&vinstance0);
1697 unref_instance_cond(&vinstance1);
1698 unref_instance_cond(&tinstance0);
1699 unref_instance_cond(&tinstance1);
1702 int ast_rtp_instance_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
1704 struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
1705 *vinstance0 = NULL, *vinstance1 = NULL,
1706 *tinstance0 = NULL, *tinstance1 = NULL;
1707 struct ast_rtp_glue *glue0, *glue1;
1708 enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
1709 enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
1710 struct ast_format_cap *cap0 = ast_format_cap_alloc_nolock();
1711 struct ast_format_cap *cap1 = ast_format_cap_alloc_nolock();
1713 /* If there is no second channel just immediately bail out, we are of no use in that scenario */
1714 if (!c1 || !cap1 || !cap0) {
1715 ast_format_cap_destroy(cap0);
1716 ast_format_cap_destroy(cap1);
1720 /* Lock both channels so we can look for the glue that binds them together */
1721 ast_channel_lock_both(c0, c1);
1723 /* Grab glue that binds each channel to something using the RTP engine */
1724 if (!(glue0 = ast_rtp_instance_get_glue(ast_channel_tech(c0)->type)) || !(glue1 = ast_rtp_instance_get_glue(ast_channel_tech(c1)->type))) {
1725 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", glue0 ? ast_channel_name(c1) : ast_channel_name(c0));
1729 audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
1730 video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;
1732 audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
1733 video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;
1735 /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
1736 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)) {
1737 audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
1739 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)) {
1740 audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
1742 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) {
1743 glue0->get_codec(c0, cap0);
1745 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) {
1746 glue1->get_codec(c1, cap1);
1749 /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
1750 if (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE) {
1754 /* Make sure we have matching codecs */
1755 if (!ast_format_cap_has_joint(cap0, cap1)) {
1759 /* Bridge media early */
1760 if (glue0->update_peer(c0, instance1, vinstance1, tinstance1, cap1, 0)) {
1761 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", ast_channel_name(c0), c1 ? ast_channel_name(c1) : "<unspecified>");
1765 ast_channel_unlock(c0);
1766 ast_channel_unlock(c1);
1768 ast_format_cap_destroy(cap0);
1769 ast_format_cap_destroy(cap1);
1771 unref_instance_cond(&instance0);
1772 unref_instance_cond(&instance1);
1773 unref_instance_cond(&vinstance0);
1774 unref_instance_cond(&vinstance1);
1775 unref_instance_cond(&tinstance0);
1776 unref_instance_cond(&tinstance1);
1778 ast_debug(1, "Setting early bridge SDP of '%s' with that of '%s'\n", ast_channel_name(c0), c1 ? ast_channel_name(c1) : "<unspecified>");
1783 int ast_rtp_red_init(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations)
1785 return instance->engine->red_init ? instance->engine->red_init(instance, buffer_time, payloads, generations) : -1;
1788 int ast_rtp_red_buffer(struct ast_rtp_instance *instance, struct ast_frame *frame)
1790 return instance->engine->red_buffer ? instance->engine->red_buffer(instance, frame) : -1;
1793 int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
1795 return instance->engine->get_stat ? instance->engine->get_stat(instance, stats, stat) : -1;
1798 char *ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size)
1800 struct ast_rtp_instance_stats stats = { 0, };
1801 enum ast_rtp_instance_stat stat;
1803 /* Determine what statistics we will need to retrieve based on field passed in */
1804 if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY) {
1805 stat = AST_RTP_INSTANCE_STAT_ALL;
1806 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
1807 stat = AST_RTP_INSTANCE_STAT_COMBINED_JITTER;
1808 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
1809 stat = AST_RTP_INSTANCE_STAT_COMBINED_LOSS;
1810 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
1811 stat = AST_RTP_INSTANCE_STAT_COMBINED_RTT;
1816 /* Attempt to actually retrieve the statistics we need to generate the quality string */
1817 if (ast_rtp_instance_get_stats(instance, &stats, stat)) {
1821 /* Now actually fill the buffer with the good information */
1822 if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY) {
1823 snprintf(buf, size, "ssrc=%i;themssrc=%u;lp=%u;rxjitter=%f;rxcount=%u;txjitter=%f;txcount=%u;rlp=%u;rtt=%f",
1824 stats.local_ssrc, stats.remote_ssrc, stats.rxploss, stats.txjitter, stats.rxcount, stats.rxjitter, stats.txcount, stats.txploss, stats.rtt);
1825 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
1826 snprintf(buf, size, "minrxjitter=%f;maxrxjitter=%f;avgrxjitter=%f;stdevrxjitter=%f;reported_minjitter=%f;reported_maxjitter=%f;reported_avgjitter=%f;reported_stdevjitter=%f;",
1827 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));
1828 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
1829 snprintf(buf, size, "minrxlost=%f;maxrxlost=%f;avgrxlost=%f;stdevrxlost=%f;reported_minlost=%f;reported_maxlost=%f;reported_avglost=%f;reported_stdevlost=%f;",
1830 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));
1831 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
1832 snprintf(buf, size, "minrtt=%f;maxrtt=%f;avgrtt=%f;stdevrtt=%f;", stats.minrtt, stats.maxrtt, stats.normdevrtt, stats.stdevrtt);
1838 void ast_rtp_instance_set_stats_vars(struct ast_channel *chan, struct ast_rtp_instance *instance)
1840 char quality_buf[AST_MAX_USER_FIELD], *quality;
1841 struct ast_channel *bridge = ast_bridged_channel(chan);
1843 if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) {
1844 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOS", quality);
1846 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSBRIDGED", quality);
1850 if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, quality_buf, sizeof(quality_buf)))) {
1851 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSJITTER", quality);
1853 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSJITTERBRIDGED", quality);
1857 if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, quality_buf, sizeof(quality_buf)))) {
1858 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSLOSS", quality);
1860 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSLOSSBRIDGED", quality);
1864 if ((quality = ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, quality_buf, sizeof(quality_buf)))) {
1865 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSRTT", quality);
1867 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSRTTBRIDGED", quality);
1872 int ast_rtp_instance_set_read_format(struct ast_rtp_instance *instance, struct ast_format *format)
1874 return instance->engine->set_read_format ? instance->engine->set_read_format(instance, format) : -1;
1877 int ast_rtp_instance_set_write_format(struct ast_rtp_instance *instance, struct ast_format *format)
1879 return instance->engine->set_write_format ? instance->engine->set_write_format(instance, format) : -1;
1882 int ast_rtp_instance_make_compatible(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_channel *peer)
1884 struct ast_rtp_glue *glue;
1885 struct ast_rtp_instance *peer_instance = NULL;
1888 if (!instance->engine->make_compatible) {
1892 ast_channel_lock(peer);
1894 if (!(glue = ast_rtp_instance_get_glue(ast_channel_tech(peer)->type))) {
1895 ast_channel_unlock(peer);
1899 glue->get_rtp_info(peer, &peer_instance);
1901 if (!peer_instance || peer_instance->engine != instance->engine) {
1902 ast_channel_unlock(peer);
1903 ao2_ref(peer_instance, -1);
1904 peer_instance = NULL;
1908 res = instance->engine->make_compatible(chan, instance, peer, peer_instance);
1910 ast_channel_unlock(peer);
1912 ao2_ref(peer_instance, -1);
1913 peer_instance = NULL;
1918 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)
1920 if (instance->engine->available_formats) {
1921 instance->engine->available_formats(instance, to_endpoint, to_asterisk, result);
1922 if (!ast_format_cap_is_empty(result)) {
1927 ast_translate_available_formats(to_endpoint, to_asterisk, result);
1930 int ast_rtp_instance_activate(struct ast_rtp_instance *instance)
1932 return instance->engine->activate ? instance->engine->activate(instance) : 0;
1935 void ast_rtp_instance_stun_request(struct ast_rtp_instance *instance,
1936 struct ast_sockaddr *suggestion,
1937 const char *username)
1939 if (instance->engine->stun_request) {
1940 instance->engine->stun_request(instance, suggestion, username);
1944 void ast_rtp_instance_set_timeout(struct ast_rtp_instance *instance, int timeout)
1946 instance->timeout = timeout;
1949 void ast_rtp_instance_set_hold_timeout(struct ast_rtp_instance *instance, int timeout)
1951 instance->holdtimeout = timeout;
1954 void ast_rtp_instance_set_keepalive(struct ast_rtp_instance *instance, int interval)
1956 instance->keepalive = interval;
1959 int ast_rtp_instance_get_timeout(struct ast_rtp_instance *instance)
1961 return instance->timeout;
1964 int ast_rtp_instance_get_hold_timeout(struct ast_rtp_instance *instance)
1966 return instance->holdtimeout;
1969 int ast_rtp_instance_get_keepalive(struct ast_rtp_instance *instance)
1971 return instance->keepalive;
1974 struct ast_rtp_engine *ast_rtp_instance_get_engine(struct ast_rtp_instance *instance)
1976 return instance->engine;
1979 struct ast_rtp_glue *ast_rtp_instance_get_active_glue(struct ast_rtp_instance *instance)
1981 return instance->glue;
1984 struct ast_channel *ast_rtp_instance_get_chan(struct ast_rtp_instance *instance)
1986 return instance->chan;
1989 int ast_rtp_engine_register_srtp(struct ast_srtp_res *srtp_res, struct ast_srtp_policy_res *policy_res)
1991 if (res_srtp || res_srtp_policy) {
1994 if (!srtp_res || !policy_res) {
1998 res_srtp = srtp_res;
1999 res_srtp_policy = policy_res;
2004 void ast_rtp_engine_unregister_srtp(void)
2007 res_srtp_policy = NULL;
2010 int ast_rtp_engine_srtp_is_registered(void)
2012 return res_srtp && res_srtp_policy;
2015 int ast_rtp_instance_add_srtp_policy(struct ast_rtp_instance *instance, struct ast_srtp_policy *remote_policy, struct ast_srtp_policy *local_policy)
2023 if (!instance->srtp) {
2024 res = res_srtp->create(&instance->srtp, instance, remote_policy);
2026 res = res_srtp->replace(&instance->srtp, instance, remote_policy);
2029 res = res_srtp->add_stream(instance->srtp, local_policy);
2035 struct ast_srtp *ast_rtp_instance_get_srtp(struct ast_rtp_instance *instance)
2037 return instance->srtp;
2040 int ast_rtp_instance_sendcng(struct ast_rtp_instance *instance, int level)
2042 if (instance->engine->sendcng) {
2043 return instance->engine->sendcng(instance, level);
2049 struct ast_rtp_engine_ice *ast_rtp_instance_get_ice(struct ast_rtp_instance *instance)
2051 return instance->engine->ice;
2054 struct ast_rtp_engine_dtls *ast_rtp_instance_get_dtls(struct ast_rtp_instance *instance)
2056 return instance->engine->dtls;
2059 int ast_rtp_dtls_cfg_parse(struct ast_rtp_dtls_cfg *dtls_cfg, const char *name, const char *value)
2061 if (!strcasecmp(name, "dtlsenable")) {
2062 dtls_cfg->enabled = ast_true(value) ? 1 : 0;
2063 } else if (!strcasecmp(name, "dtlsverify")) {
2064 dtls_cfg->verify = ast_true(value) ? 1 : 0;
2065 } else if (!strcasecmp(name, "dtlsrekey")) {
2066 if (sscanf(value, "%30u", &dtls_cfg->rekey) != 1) {
2069 } else if (!strcasecmp(name, "dtlscertfile")) {
2070 ast_free(dtls_cfg->certfile);
2071 dtls_cfg->certfile = ast_strdup(value);
2072 } else if (!strcasecmp(name, "dtlsprivatekey")) {
2073 ast_free(dtls_cfg->pvtfile);
2074 dtls_cfg->pvtfile = ast_strdup(value);
2075 } else if (!strcasecmp(name, "dtlscipher")) {
2076 ast_free(dtls_cfg->cipher);
2077 dtls_cfg->cipher = ast_strdup(value);
2078 } else if (!strcasecmp(name, "dtlscafile")) {
2079 ast_free(dtls_cfg->cafile);
2080 dtls_cfg->cafile = ast_strdup(value);
2081 } else if (!strcasecmp(name, "dtlscapath") || !strcasecmp(name, "dtlscadir")) {
2082 ast_free(dtls_cfg->capath);
2083 dtls_cfg->capath = ast_strdup(value);
2084 } else if (!strcasecmp(name, "dtlssetup")) {
2085 if (!strcasecmp(value, "active")) {
2086 dtls_cfg->default_setup = AST_RTP_DTLS_SETUP_ACTIVE;
2087 } else if (!strcasecmp(value, "passive")) {
2088 dtls_cfg->default_setup = AST_RTP_DTLS_SETUP_PASSIVE;
2089 } else if (!strcasecmp(value, "actpass")) {
2090 dtls_cfg->default_setup = AST_RTP_DTLS_SETUP_ACTPASS;
2099 void ast_rtp_dtls_cfg_copy(const struct ast_rtp_dtls_cfg *src_cfg, struct ast_rtp_dtls_cfg *dst_cfg)
2101 dst_cfg->enabled = src_cfg->enabled;
2102 dst_cfg->verify = src_cfg->verify;
2103 dst_cfg->rekey = src_cfg->rekey;
2104 dst_cfg->suite = src_cfg->suite;
2105 dst_cfg->certfile = ast_strdup(src_cfg->certfile);
2106 dst_cfg->pvtfile = ast_strdup(src_cfg->pvtfile);
2107 dst_cfg->cipher = ast_strdup(src_cfg->cipher);
2108 dst_cfg->cafile = ast_strdup(src_cfg->cafile);
2109 dst_cfg->capath = ast_strdup(src_cfg->capath);
2110 dst_cfg->default_setup = src_cfg->default_setup;
2113 void ast_rtp_dtls_cfg_free(struct ast_rtp_dtls_cfg *dtls_cfg)
2115 ast_free(dtls_cfg->certfile);
2116 ast_free(dtls_cfg->pvtfile);
2117 ast_free(dtls_cfg->cipher);
2118 ast_free(dtls_cfg->cafile);
2119 ast_free(dtls_cfg->capath);
2122 static void set_next_mime_type(const struct ast_format *format, int rtp_code, char *type, char *subtype, unsigned int sample_rate)
2124 int x = mime_types_len;
2125 if (ARRAY_LEN(ast_rtp_mime_types) == mime_types_len) {
2129 ast_rwlock_wrlock(&mime_types_lock);
2131 ast_rtp_mime_types[x].payload_type.asterisk_format = 1;
2132 ast_format_copy(&ast_rtp_mime_types[x].payload_type.format, format);
2134 ast_rtp_mime_types[x].payload_type.rtp_code = rtp_code;
2136 ast_rtp_mime_types[x].type = type;
2137 ast_rtp_mime_types[x].subtype = subtype;
2138 ast_rtp_mime_types[x].sample_rate = sample_rate;
2140 ast_rwlock_unlock(&mime_types_lock);
2143 static void add_static_payload(int map, const struct ast_format *format, int rtp_code)
2146 ast_rwlock_wrlock(&static_RTP_PT_lock);
2148 /* find next available dynamic payload slot */
2149 for (x = 96; x < 127; x++) {
2150 if (!static_RTP_PT[x].asterisk_format && !static_RTP_PT[x].rtp_code) {
2158 ast_log(LOG_WARNING, "No Dynamic RTP mapping avaliable for format %s\n" ,ast_getformatname(format));
2159 ast_rwlock_unlock(&static_RTP_PT_lock);
2164 static_RTP_PT[map].asterisk_format = 1;
2165 ast_format_copy(&static_RTP_PT[map].format, format);
2167 static_RTP_PT[map].rtp_code = rtp_code;
2169 ast_rwlock_unlock(&static_RTP_PT_lock);
2172 int ast_rtp_engine_load_format(const struct ast_format *format)
2174 switch (format->id) {
2175 case AST_FORMAT_SILK:
2176 set_next_mime_type(format, 0, "audio", "SILK", ast_format_rate(format));
2177 add_static_payload(-1, format, 0);
2179 case AST_FORMAT_CELT:
2180 set_next_mime_type(format, 0, "audio", "CELT", ast_format_rate(format));
2181 add_static_payload(-1, format, 0);
2190 int ast_rtp_engine_unload_format(const struct ast_format *format)
2195 ast_rwlock_wrlock(&static_RTP_PT_lock);
2196 /* remove everything pertaining to this format id from the lists */
2197 for (x = 0; x < AST_RTP_MAX_PT; x++) {
2198 if (ast_format_cmp(&static_RTP_PT[x].format, format) == AST_FORMAT_CMP_EQUAL) {
2199 memset(&static_RTP_PT[x], 0, sizeof(struct ast_rtp_payload_type));
2202 ast_rwlock_unlock(&static_RTP_PT_lock);
2205 ast_rwlock_wrlock(&mime_types_lock);
2206 /* rebuild the list skipping the items matching this id */
2207 for (x = 0; x < mime_types_len; x++) {
2208 if (ast_format_cmp(&ast_rtp_mime_types[x].payload_type.format, format) == AST_FORMAT_CMP_EQUAL) {
2211 ast_rtp_mime_types[y] = ast_rtp_mime_types[x];
2215 ast_rwlock_unlock(&mime_types_lock);
2219 int ast_rtp_engine_init()
2221 struct ast_format tmpfmt;
2223 ast_rwlock_init(&mime_types_lock);
2224 ast_rwlock_init(&static_RTP_PT_lock);
2226 /* Define all the RTP mime types available */
2227 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G723_1, 0), 0, "audio", "G723", 8000);
2228 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_GSM, 0), 0, "audio", "GSM", 8000);
2229 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0), 0, "audio", "PCMU", 8000);
2230 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0), 0, "audio", "G711U", 8000);
2231 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0), 0, "audio", "PCMA", 8000);
2232 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0), 0, "audio", "G711A", 8000);
2233 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G726, 0), 0, "audio", "G726-32", 8000);
2234 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_ADPCM, 0), 0, "audio", "DVI4", 8000);
2235 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0), 0, "audio", "L16", 8000);
2236 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR16, 0), 0, "audio", "L16", 16000);
2237 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR16, 0), 0, "audio", "L16-256", 16000);
2238 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_LPC10, 0), 0, "audio", "LPC", 8000);
2239 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G729A, 0), 0, "audio", "G729", 8000);
2240 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G729A, 0), 0, "audio", "G729A", 8000);
2241 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G729A, 0), 0, "audio", "G.729", 8000);
2242 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SPEEX, 0), 0, "audio", "speex", 8000);
2243 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SPEEX16, 0), 0, "audio", "speex", 16000);
2244 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SPEEX32, 0), 0, "audio", "speex", 32000);
2245 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_ILBC, 0), 0, "audio", "iLBC", 8000);
2246 /* this is the sample rate listed in the RTP profile for the G.722 codec, *NOT* the actual sample rate of the media stream */
2247 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G722, 0), 0, "audio", "G722", 8000);
2248 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G726_AAL2, 0), 0, "audio", "AAL2-G726-32", 8000);
2249 set_next_mime_type(NULL, AST_RTP_DTMF, "audio", "telephone-event", 8000);
2250 set_next_mime_type(NULL, AST_RTP_CISCO_DTMF, "audio", "cisco-telephone-event", 8000);
2251 set_next_mime_type(NULL, AST_RTP_CN, "audio", "CN", 8000);
2252 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_JPEG, 0), 0, "video", "JPEG", 90000);
2253 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_PNG, 0), 0, "video", "PNG", 90000);
2254 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_H261, 0), 0, "video", "H261", 90000);
2255 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_H263, 0), 0, "video", "H263", 90000);
2256 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_H263_PLUS, 0), 0, "video", "h263-1998", 90000);
2257 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_H264, 0), 0, "video", "H264", 90000);
2258 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_MP4_VIDEO, 0), 0, "video", "MP4V-ES", 90000);
2259 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_T140RED, 0), 0, "text", "RED", 1000);
2260 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_T140, 0), 0, "text", "T140", 1000);
2261 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SIREN7, 0), 0, "audio", "G7221", 16000);
2262 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_SIREN14, 0), 0, "audio", "G7221", 32000);
2263 set_next_mime_type(ast_format_set(&tmpfmt, AST_FORMAT_G719, 0), 0, "audio", "G719", 48000);
2265 /* Define the static rtp payload mappings */
2266 add_static_payload(0, ast_format_set(&tmpfmt, AST_FORMAT_ULAW, 0), 0);
2267 #ifdef USE_DEPRECATED_G726
2268 add_static_payload(2, ast_format_set(&tmpfmt, AST_FORMAT_G726, 0), 0);/* Technically this is G.721, but if Cisco can do it, so can we... */
2270 add_static_payload(3, ast_format_set(&tmpfmt, AST_FORMAT_GSM, 0), 0);
2271 add_static_payload(4, ast_format_set(&tmpfmt, AST_FORMAT_G723_1, 0), 0);
2272 add_static_payload(5, ast_format_set(&tmpfmt, AST_FORMAT_ADPCM, 0), 0);/* 8 kHz */
2273 add_static_payload(6, ast_format_set(&tmpfmt, AST_FORMAT_ADPCM, 0), 0); /* 16 kHz */
2274 add_static_payload(7, ast_format_set(&tmpfmt, AST_FORMAT_LPC10, 0), 0);
2275 add_static_payload(8, ast_format_set(&tmpfmt, AST_FORMAT_ALAW, 0), 0);
2276 add_static_payload(9, ast_format_set(&tmpfmt, AST_FORMAT_G722, 0), 0);
2277 add_static_payload(10, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0), 0); /* 2 channels */
2278 add_static_payload(11, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR, 0), 0); /* 1 channel */
2279 add_static_payload(13, NULL, AST_RTP_CN);
2280 add_static_payload(16, ast_format_set(&tmpfmt, AST_FORMAT_ADPCM, 0), 0); /* 11.025 kHz */
2281 add_static_payload(17, ast_format_set(&tmpfmt, AST_FORMAT_ADPCM, 0), 0); /* 22.050 kHz */
2282 add_static_payload(18, ast_format_set(&tmpfmt, AST_FORMAT_G729A, 0), 0);
2283 add_static_payload(19, NULL, AST_RTP_CN); /* Also used for CN */
2284 add_static_payload(26, ast_format_set(&tmpfmt, AST_FORMAT_JPEG, 0), 0);
2285 add_static_payload(31, ast_format_set(&tmpfmt, AST_FORMAT_H261, 0), 0);
2286 add_static_payload(34, ast_format_set(&tmpfmt, AST_FORMAT_H263, 0), 0);
2287 add_static_payload(97, ast_format_set(&tmpfmt, AST_FORMAT_ILBC, 0), 0);
2288 add_static_payload(98, ast_format_set(&tmpfmt, AST_FORMAT_H263_PLUS, 0), 0);
2289 add_static_payload(99, ast_format_set(&tmpfmt, AST_FORMAT_H264, 0), 0);
2290 add_static_payload(101, NULL, AST_RTP_DTMF);
2291 add_static_payload(102, ast_format_set(&tmpfmt, AST_FORMAT_SIREN7, 0), 0);
2292 add_static_payload(103, ast_format_set(&tmpfmt, AST_FORMAT_H263_PLUS, 0), 0);
2293 add_static_payload(104, ast_format_set(&tmpfmt, AST_FORMAT_MP4_VIDEO, 0), 0);
2294 add_static_payload(105, ast_format_set(&tmpfmt, AST_FORMAT_T140RED, 0), 0); /* Real time text chat (with redundancy encoding) */
2295 add_static_payload(106, ast_format_set(&tmpfmt, AST_FORMAT_T140, 0), 0); /* Real time text chat */
2296 add_static_payload(110, ast_format_set(&tmpfmt, AST_FORMAT_SPEEX, 0), 0);
2297 add_static_payload(111, ast_format_set(&tmpfmt, AST_FORMAT_G726, 0), 0);
2298 add_static_payload(112, ast_format_set(&tmpfmt, AST_FORMAT_G726_AAL2, 0), 0);
2299 add_static_payload(115, ast_format_set(&tmpfmt, AST_FORMAT_SIREN14, 0), 0);
2300 add_static_payload(116, ast_format_set(&tmpfmt, AST_FORMAT_G719, 0), 0);
2301 add_static_payload(117, ast_format_set(&tmpfmt, AST_FORMAT_SPEEX16, 0), 0);
2302 add_static_payload(118, ast_format_set(&tmpfmt, AST_FORMAT_SLINEAR16, 0), 0); /* 16 Khz signed linear */
2303 add_static_payload(119, ast_format_set(&tmpfmt, AST_FORMAT_SPEEX32, 0), 0);
2304 add_static_payload(121, NULL, AST_RTP_CISCO_DTMF); /* Must be type 121 */