Asterisk - The Open Source Telephony Project GIT-master-7e7a603
rtp_engine.c
Go to the documentation of this file.
1/*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 1999 - 2008, Digium, Inc.
5 *
6 * Joshua Colp <jcolp@digium.com>
7 *
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.
13 *
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.
17 */
18
19/*! \file
20 *
21 * \brief Pluggable RTP Architecture
22 *
23 * \author Joshua Colp <jcolp@digium.com>
24 */
25
26/*** MODULEINFO
27 <support_level>core</support_level>
28***/
29
30/*** DOCUMENTATION
31 <managerEvent language="en_US" name="RTCPSent">
32 <managerEventInstance class="EVENT_FLAG_REPORTING">
33 <synopsis>Raised when an RTCP packet is sent.</synopsis>
34 <syntax>
35 <channel_snapshot/>
36 <parameter name="SSRC">
37 <para>The SSRC identifier for our stream</para>
38 </parameter>
39 <parameter name="PT">
40 <para>The type of packet for this RTCP report.</para>
41 <enumlist>
42 <enum name="200(SR)"/>
43 <enum name="201(RR)"/>
44 </enumlist>
45 </parameter>
46 <parameter name="To">
47 <para>The address the report is sent to.</para>
48 </parameter>
49 <parameter name="ReportCount">
50 <para>The number of reports that were sent.</para>
51 <para>The report count determines the number of ReportX headers in
52 the message. The X for each set of report headers will range from 0 to
53 <literal>ReportCount - 1</literal>.</para>
54 </parameter>
55 <parameter name="SentNTP" required="false">
56 <para>The time the sender generated the report. Only valid when
57 PT is <literal>200(SR)</literal>.</para>
58 </parameter>
59 <parameter name="SentRTP" required="false">
60 <para>The sender's last RTP timestamp. Only valid when PT is
61 <literal>200(SR)</literal>.</para>
62 </parameter>
63 <parameter name="SentPackets" required="false">
64 <para>The number of packets the sender has sent. Only valid when PT
65 is <literal>200(SR)</literal>.</para>
66 </parameter>
67 <parameter name="SentOctets" required="false">
68 <para>The number of bytes the sender has sent. Only valid when PT is
69 <literal>200(SR)</literal>.</para>
70 </parameter>
71 <parameter name="ReportXSourceSSRC">
72 <para>The SSRC for the source of this report block.</para>
73 </parameter>
74 <parameter name="ReportXFractionLost">
75 <para>The fraction of RTP data packets from <literal>ReportXSourceSSRC</literal>
76 lost since the previous SR or RR report was sent.</para>
77 </parameter>
78 <parameter name="ReportXCumulativeLost">
79 <para>The total number of RTP data packets from <literal>ReportXSourceSSRC</literal>
80 lost since the beginning of reception.</para>
81 </parameter>
82 <parameter name="ReportXHighestSequence">
83 <para>The highest sequence number received in an RTP data packet from
84 <literal>ReportXSourceSSRC</literal>.</para>
85 </parameter>
86 <parameter name="ReportXSequenceNumberCycles">
87 <para>The number of sequence number cycles seen for the RTP data
88 received from <literal>ReportXSourceSSRC</literal>.</para>
89 </parameter>
90 <parameter name="ReportXIAJitter">
91 <para>An estimate of the statistical variance of the RTP data packet
92 interarrival time, measured in timestamp units.</para>
93 </parameter>
94 <parameter name="ReportXLSR">
95 <para>The last SR timestamp received from <literal>ReportXSourceSSRC</literal>.
96 If no SR has been received from <literal>ReportXSourceSSRC</literal>,
97 then 0.</para>
98 </parameter>
99 <parameter name="ReportXDLSR">
100 <para>The delay, expressed in units of 1/65536 seconds, between
101 receiving the last SR packet from <literal>ReportXSourceSSRC</literal>
102 and sending this report.</para>
103 </parameter>
104 </syntax>
105 <see-also>
106 <ref type="managerEvent">RTCPReceived</ref>
107 </see-also>
108 </managerEventInstance>
109 </managerEvent>
110 <managerEvent language="en_US" name="RTCPReceived">
111 <managerEventInstance class="EVENT_FLAG_REPORTING">
112 <synopsis>Raised when an RTCP packet is received.</synopsis>
113 <syntax>
114 <channel_snapshot/>
115 <parameter name="SSRC">
116 <para>The SSRC identifier for the remote system</para>
117 </parameter>
118 <xi:include xpointer="xpointer(/docs/managerEvent[@name='RTCPSent']/managerEventInstance/syntax/parameter[@name='PT'])" />
119 <parameter name="From">
120 <para>The address the report was received from.</para>
121 </parameter>
122 <parameter name="RTT">
123 <para>Calculated Round-Trip Time in seconds</para>
124 </parameter>
125 <parameter name="ReportCount">
126 <para>The number of reports that were received.</para>
127 <para>The report count determines the number of ReportX headers in
128 the message. The X for each set of report headers will range from 0 to
129 <literal>ReportCount - 1</literal>.</para>
130 </parameter>
131 <xi:include xpointer="xpointer(/docs/managerEvent[@name='RTCPSent']/managerEventInstance/syntax/parameter[@name='SentNTP'])" />
132 <xi:include xpointer="xpointer(/docs/managerEvent[@name='RTCPSent']/managerEventInstance/syntax/parameter[@name='SentRTP'])" />
133 <xi:include xpointer="xpointer(/docs/managerEvent[@name='RTCPSent']/managerEventInstance/syntax/parameter[@name='SentPackets'])" />
134 <xi:include xpointer="xpointer(/docs/managerEvent[@name='RTCPSent']/managerEventInstance/syntax/parameter[@name='SentOctets'])" />
135 <xi:include xpointer="xpointer(/docs/managerEvent[@name='RTCPSent']/managerEventInstance/syntax/parameter[contains(@name, 'ReportX')])" />
136 </syntax>
137 <see-also>
138 <ref type="managerEvent">RTCPSent</ref>
139 </see-also>
140 </managerEventInstance>
141 </managerEvent>
142 ***/
143
144#include "asterisk.h"
145
146#include <sched.h> /* for sched_yield */
147#include <sys/time.h> /* for timeval */
148#include <time.h> /* for time_t */
149
150#include "asterisk/_private.h" /* for ast_rtp_engine_init prototype */
151#include "asterisk/astobj2.h" /* for ao2_cleanup, ao2_ref, etc */
152#include "asterisk/channel.h" /* for ast_channel_name, etc */
153#include "asterisk/codec.h" /* for ast_codec_media_type2str, etc */
154#include "asterisk/format.h" /* for ast_format_cmp, etc */
155#include "asterisk/format_cache.h" /* for ast_format_adpcm, etc */
156#include "asterisk/format_cap.h" /* for ast_format_cap_alloc, etc */
157#include "asterisk/json.h" /* for ast_json_ref, etc */
158#include "asterisk/linkedlists.h" /* for ast_rtp_engine::<anonymous>, etc */
159#include "asterisk/lock.h" /* for ast_rwlock_unlock, etc */
160#include "asterisk/logger.h" /* for ast_log, ast_debug, etc */
161#include "asterisk/manager.h"
162#include "asterisk/module.h" /* for ast_module_unref, etc */
163#include "asterisk/netsock2.h" /* for ast_sockaddr_copy, etc */
164#include "asterisk/options.h" /* for ast_option_rtpptdynamic */
165#include "asterisk/pbx.h" /* for pbx_builtin_setvar_helper */
166#include "asterisk/res_srtp.h" /* for ast_srtp_res */
167#include "asterisk/rtp_engine.h" /* for ast_rtp_codecs, etc */
168#include "asterisk/stasis.h" /* for stasis_message_data, etc */
169#include "asterisk/stasis_channels.h" /* for ast_channel_stage_snapshot, etc */
170#include "asterisk/strings.h" /* for ast_str_append, etc */
171#include "asterisk/time.h" /* for ast_tvdiff_ms, ast_tvnow */
172#include "asterisk/translate.h" /* for ast_translate_available_formats */
173#include "asterisk/utils.h" /* for ast_free, ast_strdup, etc */
174#include "asterisk/vector.h" /* for AST_VECTOR_GET, etc */
175
178
179/*! Structure that contains extmap negotiation information */
181 /*! The RTP extension */
183 /*! The current negotiated direction */
185};
186
187/*! Structure that represents an RTP session (instance) */
189 /*! Engine that is handling this RTP instance */
191 /*! Data unique to the RTP engine */
192 void *data;
193 /*! RTP properties that have been set and their value */
195 /*! Address that we are expecting RTP to come in to */
197 /*! The original source address */
199 /*! Address that we are sending RTP to */
201 /*! Instance that we are bridged to if doing remote or local bridging */
203 /*! Payload and packetization information */
205 /*! RTP timeout time (negative or zero means disabled, negative value means temporarily disabled) */
207 /*! RTP timeout when on hold (negative or zero means disabled, negative value means temporarily disabled). */
209 /*! RTP keepalive interval */
211 /*! Glue currently in use */
213 /*! SRTP info associated with the instance */
214 struct ast_srtp *srtp;
215 /*! SRTP info dedicated for RTCP associated with the instance */
217 /*! Channel unique ID */
219 /*! Time of last packet sent */
220 time_t last_tx;
221 /*! Time of last packet received */
222 time_t last_rx;
223 /*! Enabled RTP extensions */
225 /*! Negotiated RTP extensions (using index based on extension) */
227 /*! Negotiated RTP extensions (using index based on unique id) */
229};
230
231/*!
232 * \brief URIs for known RTP extensions
233 */
234static const char * const rtp_extension_uris[AST_RTP_EXTENSION_MAX] = {
236 [AST_RTP_EXTENSION_ABS_SEND_TIME] = "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time",
237 [AST_RTP_EXTENSION_TRANSPORT_WIDE_CC] = "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01",
238};
239
240/*! List of RTP engines that are currently registered */
242
243/*! List of RTP glues */
245
246#define MAX_RTP_MIME_TYPES 128
247
248/*! The following array defines the MIME Media type (and subtype) for each
249 of our codecs, or RTP-specific data type. */
250static struct ast_rtp_mime_type {
251 /*! \brief A mapping object between the Asterisk codec and this RTP payload */
253 /*! \brief The media type */
254 char type[16];
255 /*! \brief The format type */
256 char subtype[64];
257 /*! \brief Expected sample rate of the /c subtype */
258 unsigned int sample_rate;
259} ast_rtp_mime_types[128]; /* This will Likely not need to grow any time soon. */
261static int mime_types_len = 0;
262
263/*!
264 * \brief Mapping between Asterisk codecs and rtp payload types
265 *
266 * Static (i.e., well-known) RTP payload types for our "AST_FORMAT..."s:
267 * also, our own choices for dynamic payload types. This is our master
268 * table for transmission
269 *
270 * See http://www.iana.org/assignments/rtp-parameters for a list of
271 * assigned values
272 */
275
276/*! \brief \ref stasis topic for RTP related messages */
277static struct stasis_topic *rtp_topic;
278
279
280/*!
281 * \brief Set given json object into target with name
282 *
283 * \param target Target json.
284 * \param name key of given object.
285 * \param obj Json value will be set.
286 */
287#define SET_AST_JSON_OBJ(target, name, obj) ({ \
288 struct ast_json *j_tmp = obj; \
289 if (j_tmp) { \
290 ast_json_object_set(target, name, j_tmp); \
291 } \
292})
293
294/*!
295 * \internal
296 * \brief Destructor for \c ast_rtp_payload_type
297 */
298static void rtp_payload_type_dtor(void *obj)
299{
300 struct ast_rtp_payload_type *payload = obj;
301
302 ao2_cleanup(payload->format);
303}
304
306 int payload, int rtp_code, int primary_mapping)
307{
310
311 if (!type) {
312 return NULL;
313 }
314
315 type->format = ao2_bump(format);
316 type->asterisk_format = type->format != NULL;
317 type->payload = payload;
318 type->rtp_code = rtp_code;
319 type->primary_mapping = primary_mapping;
320
321 return type;
322}
323
325{
326 return rtp_payload_type_alloc(NULL, 0, 0, 0);
327}
328
329int ast_rtp_engine_register2(struct ast_rtp_engine *engine, struct ast_module *module)
330{
331 struct ast_rtp_engine *current_engine;
332
333 /* Perform a sanity check on the engine structure to make sure it has the basics */
334 if (ast_strlen_zero(engine->name) || !engine->new || !engine->destroy || !engine->write || !engine->read) {
335 ast_log(LOG_WARNING, "RTP Engine '%s' failed sanity check so it was not registered.\n", !ast_strlen_zero(engine->name) ? engine->name : "Unknown");
336 return -1;
337 }
338
339 /* Link owner module to the RTP engine for reference counting purposes */
340 engine->mod = module;
341
343
344 /* Ensure that no two modules with the same name are registered at the same time */
345 AST_RWLIST_TRAVERSE(&engines, current_engine, entry) {
346 if (!strcmp(current_engine->name, engine->name)) {
347 ast_log(LOG_WARNING, "An RTP engine with the name '%s' has already been registered.\n", engine->name);
349 return -1;
350 }
351 }
352
353 /* The engine survived our critique. Off to the list it goes to be used */
355
357
358 ast_verb(5, "Registered RTP engine '%s'\n", engine->name);
359
360 return 0;
361}
362
364{
365 struct ast_rtp_engine *current_engine = NULL;
366
368
369 if ((current_engine = AST_RWLIST_REMOVE(&engines, engine, entry))) {
370 ast_verb(5, "Unregistered RTP engine '%s'\n", engine->name);
371 }
372
374
375 return current_engine ? 0 : -1;
376}
377
378int ast_rtp_glue_register2(struct ast_rtp_glue *glue, struct ast_module *module)
379{
380 struct ast_rtp_glue *current_glue = NULL;
381
382 if (ast_strlen_zero(glue->type)) {
383 return -1;
384 }
385
386 glue->mod = module;
387
389
390 AST_RWLIST_TRAVERSE(&glues, current_glue, entry) {
391 if (!strcasecmp(current_glue->type, glue->type)) {
392 ast_log(LOG_WARNING, "RTP glue with the name '%s' has already been registered.\n", glue->type);
394 return -1;
395 }
396 }
397
399
401
402 ast_verb(5, "Registered RTP glue '%s'\n", glue->type);
403
404 return 0;
405}
406
408{
409 struct ast_rtp_glue *current_glue = NULL;
410
412
413 if ((current_glue = AST_RWLIST_REMOVE(&glues, glue, entry))) {
414 ast_verb(5, "Unregistered RTP glue '%s'\n", glue->type);
415 }
416
418
419 return current_glue ? 0 : -1;
420}
421
422static void instance_destructor(void *obj)
423{
424 struct ast_rtp_instance *instance = obj;
425
426 /* Pass us off to the engine to destroy */
427 if (instance->data) {
428 /*
429 * Lock in case the RTP engine has other threads that
430 * need synchronization with the destruction.
431 */
432 ao2_lock(instance);
433 instance->engine->destroy(instance);
434 ao2_unlock(instance);
435 }
436
437 if (instance->srtp) {
438 res_srtp->destroy(instance->srtp);
439 }
440
441 if (instance->rtcp_srtp) {
442 res_srtp->destroy(instance->rtcp_srtp);
443 }
444
446
450
451 /* Drop our engine reference */
452 ast_module_unref(instance->engine->mod);
453
454 ast_debug(1, "Destroyed RTP instance '%p'\n", instance);
455}
456
458{
459 if (!instance) {
460 return 0;
461 }
463 char buffer[4][512];
464 ast_debug_rtp(1, "%s:\n"
465 " RTT: %s\n"
466 " Loss: %s\n"
467 " Jitter: %s\n"
468 " MES: %s\n",
469 instance->channel_uniqueid,
471 buffer[0], sizeof(buffer[0])),
473 buffer[1], sizeof(buffer[1])),
475 buffer[2], sizeof(buffer[2])),
477 buffer[3], sizeof(buffer[3]))
478 );
479 }
480
481 ao2_cleanup(instance);
482
483 return 0;
484}
485
486struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name,
487 struct ast_sched_context *sched, const struct ast_sockaddr *sa,
488 void *data)
489{
490 struct ast_sockaddr address = {{0,}};
491 struct ast_rtp_instance *instance = NULL;
492 struct ast_rtp_engine *engine = NULL;
493 struct ast_module *mod_ref;
494
496
497 /* If an engine name was specified try to use it or otherwise use the first one registered */
498 if (!ast_strlen_zero(engine_name)) {
500 if (!strcmp(engine->name, engine_name)) {
501 break;
502 }
503 }
504 } else {
505 engine = AST_RWLIST_FIRST(&engines);
506 }
507
508 /* If no engine was actually found bail out now */
509 if (!engine) {
510 ast_log(LOG_ERROR, "No RTP engine was found. Do you have one loaded?\n");
512 return NULL;
513 }
514
515 /* Bump up the reference count before we return so the module can not be unloaded */
516 mod_ref = ast_module_running_ref(engine->mod);
517
519
520 if (!mod_ref) {
521 /* BUGBUG: improve handling of this situation. */
522 return NULL;
523 }
524
525 /* Allocate a new RTP instance */
526 if (!(instance = ao2_alloc(sizeof(*instance), instance_destructor))) {
527 ast_module_unref(engine->mod);
528 return NULL;
529 }
530 instance->engine = engine;
531 ast_sockaddr_copy(&instance->local_address, sa);
533
535 ao2_ref(instance, -1);
536 return NULL;
537 }
538
539 /* Initialize RTP extension support */
540 if (AST_VECTOR_INIT(&instance->extmap_enabled, 0) ||
541 AST_VECTOR_INIT(&instance->extmap_negotiated, 0) ||
542 AST_VECTOR_INIT(&instance->extmap_unique_ids, 0)) {
543 ao2_ref(instance, -1);
544 return NULL;
545 }
546
547 ast_debug(1, "Using engine '%s' for RTP instance '%p'\n", engine->name, instance);
548
549 /*
550 * And pass it off to the engine to setup
551 *
552 * Lock in case the RTP engine has other threads that
553 * need synchronization with the construction.
554 */
555 ao2_lock(instance);
556 if (instance->engine->new(instance, sched, &address, data)) {
557 ast_debug(1, "Engine '%s' failed to setup RTP instance '%p'\n", engine->name, instance);
558 ao2_unlock(instance);
559 ao2_ref(instance, -1);
560 return NULL;
561 }
562 ao2_unlock(instance);
563
564 ast_debug(1, "RTP instance '%p' is setup and ready to go\n", instance);
565
566 return instance;
567}
568
570{
571 return instance->channel_uniqueid;
572}
573
574void ast_rtp_instance_set_channel_id(struct ast_rtp_instance *instance, const char *uniqueid)
575{
576 ast_copy_string(instance->channel_uniqueid, uniqueid, sizeof(instance->channel_uniqueid));
577}
578
579void ast_rtp_instance_set_data(struct ast_rtp_instance *instance, void *data)
580{
581 instance->data = data;
582}
583
585{
586 return instance->data;
587}
588
589int ast_rtp_instance_write(struct ast_rtp_instance *instance, struct ast_frame *frame)
590{
591 int res;
592
593 ao2_lock(instance);
594 res = instance->engine->write(instance, frame);
595 ao2_unlock(instance);
596 return res;
597}
598
599struct ast_frame *ast_rtp_instance_read(struct ast_rtp_instance *instance, int rtcp)
600{
601 struct ast_frame *frame;
602
603 ao2_lock(instance);
604 frame = instance->engine->read(instance, rtcp);
605 ao2_unlock(instance);
606 return frame;
607}
608
610 const struct ast_sockaddr *address)
611{
612 ao2_lock(instance);
614 ao2_unlock(instance);
615 return 0;
616}
617
619 const struct ast_sockaddr *address)
620{
622 if (instance->engine->remote_address_set) {
623 instance->engine->remote_address_set(instance, &instance->incoming_source_address);
624 }
625}
626
628 const struct ast_sockaddr *address)
629{
630 ao2_lock(instance);
632 ao2_unlock(instance);
633
634 return 0;
635}
636
638 const struct ast_sockaddr *address)
639{
640 ao2_lock(instance);
641
644
645 ao2_unlock(instance);
646
647 return 0;
648}
649
651 struct ast_sockaddr *address)
652{
653 ao2_lock(instance);
654 if (ast_sockaddr_cmp(address, &instance->local_address) != 0) {
656 ao2_unlock(instance);
657 return 1;
658 }
659 ao2_unlock(instance);
660
661 return 0;
662}
663
665 struct ast_sockaddr *address)
666{
667 ao2_lock(instance);
669 ao2_unlock(instance);
670}
671
673 struct ast_sockaddr *address)
674{
675 ao2_lock(instance);
676 if (ast_sockaddr_cmp(address, &instance->requested_target_address) != 0) {
678 ao2_unlock(instance);
679 return 1;
680 }
681 ao2_unlock(instance);
682
683 return 0;
684}
685
687 struct ast_sockaddr *address)
688{
689 ao2_lock(instance);
691 ao2_unlock(instance);
692}
693
695 struct ast_sockaddr *address)
696{
697 ao2_lock(instance);
699 ao2_unlock(instance);
700}
701
702void ast_rtp_instance_set_extended_prop(struct ast_rtp_instance *instance, int property, void *value)
703{
704 if (instance->engine->extended_prop_set) {
705 ao2_lock(instance);
706 instance->engine->extended_prop_set(instance, property, value);
707 ao2_unlock(instance);
708 }
709}
710
711void *ast_rtp_instance_get_extended_prop(struct ast_rtp_instance *instance, int property)
712{
713 void *prop;
714
715 if (instance->engine->extended_prop_get) {
716 ao2_lock(instance);
717 prop = instance->engine->extended_prop_get(instance, property);
718 ao2_unlock(instance);
719 } else {
720 prop = NULL;
721 }
722
723 return prop;
724}
725
726void ast_rtp_instance_set_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value)
727{
728 ao2_lock(instance);
729 instance->properties[property] = value;
730
731 if (instance->engine->prop_set) {
732 instance->engine->prop_set(instance, property, value);
733 }
734 ao2_unlock(instance);
735}
736
738{
739 int prop;
740
741 ao2_lock(instance);
742 prop = instance->properties[property];
743 ao2_unlock(instance);
744
745 return prop;
746}
747
749{
750 return &instance->codecs;
751}
752
755{
756 struct rtp_extmap extmap = {
758 .direction = direction,
759 };
760
761 ao2_lock(instance);
762
763 if (!instance->engine->extension_enable || !instance->engine->extension_enable(instance, extension)) {
764 ao2_unlock(instance);
765 return 0;
766 }
767
768 /* We store enabled extensions separately so we can easily do negotiation */
770 ao2_unlock(instance);
771 return -1;
772 }
773
774 if (id <= 0) {
775 /* We find a free unique identifier for this extension by just appending it to the
776 * vector of unique ids. The size of the vector will become its unique identifier.
777 * As well when we are asking for information on the extensions it will be returned,
778 * allowing it to be added to the SDP offer.
779 */
780 if (AST_VECTOR_APPEND(&instance->extmap_unique_ids, extmap)) {
782 ao2_unlock(instance);
783 return -1;
784 }
785 id = AST_VECTOR_SIZE(&instance->extmap_unique_ids);
786 } else {
787 /* Otherwise we put it precisely where they want it */
788 if (AST_VECTOR_REPLACE(&instance->extmap_unique_ids, id - 1, extmap)) {
790 ao2_unlock(instance);
791 return -1;
792 }
793 }
794
795 /* Now that we have an id add the extension to here */
796 if (AST_VECTOR_REPLACE(&instance->extmap_negotiated, extension, id)) {
800 AST_VECTOR_REPLACE(&instance->extmap_unique_ids, id - 1, extmap);
801 ao2_unlock(instance);
802 return -1;
803 }
804
805 ao2_unlock(instance);
806
807 return 0;
808}
809
810/*! \brief Helper function which negotiates two RTP extension directions to get our current direction */
812 enum ast_rtp_extension_direction theirs)
813{
815 /* This should not occur but if it does tolerate either side not having this extension
816 * in use.
817 */
819 } else if (theirs == AST_RTP_EXTENSION_DIRECTION_INACTIVE) {
820 /* Inactive is always inactive on our side */
822 } else if (theirs == AST_RTP_EXTENSION_DIRECTION_SENDRECV) {
823 return ours;
824 } else if (theirs == AST_RTP_EXTENSION_DIRECTION_SENDONLY) {
825 /* If they are send only then we become recvonly if we are configured as sendrecv or recvonly */
828 }
829 } else if (theirs == AST_RTP_EXTENSION_DIRECTION_RECVONLY) {
830 /* If they are recv only then we become sendonly if we are configured as sendrecv or sendonly */
833 }
834 }
835
837}
838
840 const char *uri, const char *attributes)
841{
842 /* 'attributes' is currently unused but exists in the API to ensure it does not need to be altered
843 * in the future in case we need to use it.
844 */
845 int idx;
847
848 /* Per the RFC the identifier has to be 1 or above */
849 if (id < 1) {
850 return -1;
851 }
852
853 /* Convert the provided URI to the internal representation */
854 for (idx = 0; idx < ARRAY_LEN(rtp_extension_uris); ++idx) {
855 if (!strcasecmp(rtp_extension_uris[idx], uri)) {
856 extension = idx;
857 break;
858 }
859 }
860
861 ao2_lock(instance);
862 /* We only accept the extension if it is enabled */
863 if (extension < AST_VECTOR_SIZE(&instance->extmap_enabled) &&
865 struct rtp_extmap extmap = {
868 };
869
870 /* If the direction negotiation failed then don't accept or use this extension */
874 }
875 AST_VECTOR_REPLACE(&instance->extmap_unique_ids, id - 1, extmap);
876 }
877 }
878 ao2_unlock(instance);
879
880 return 0;
881}
882
884{
885 static const struct rtp_extmap extmap_none = {
888 };
889 int idx;
890
891 ao2_lock(instance);
892
893 /* Clear both the known unique ids and the negotiated extensions as we are about to have
894 * new results set on us.
895 */
896 for (idx = 0; idx < AST_VECTOR_SIZE(&instance->extmap_unique_ids); ++idx) {
897 AST_VECTOR_REPLACE(&instance->extmap_unique_ids, idx, extmap_none);
898 }
899
900 for (idx = 0; idx < AST_VECTOR_SIZE(&instance->extmap_negotiated); ++idx) {
901 AST_VECTOR_REPLACE(&instance->extmap_negotiated, idx, -1);
902 }
903
904 ao2_unlock(instance);
905}
906
908{
909 int id = -1;
910
911 ao2_lock(instance);
912 if (extension < AST_VECTOR_SIZE(&instance->extmap_negotiated)) {
914 }
915 ao2_unlock(instance);
916
917 return id;
918}
919
921{
922 size_t count;
923
924 ao2_lock(instance);
925 count = AST_VECTOR_SIZE(&instance->extmap_unique_ids);
926 ao2_unlock(instance);
927
928 return count;
929}
930
932{
934
935 ao2_lock(instance);
936
937 /* The local unique identifier starts at '1' so the highest unique identifier
938 * can be the actual size of the vector. We compensate (as it is 0 index based)
939 * by dropping it down to 1 to get the correct information.
940 */
941 if (0 < id && id <= AST_VECTOR_SIZE(&instance->extmap_unique_ids)) {
942 struct rtp_extmap *extmap = AST_VECTOR_GET_ADDR(&instance->extmap_unique_ids, id - 1);
943
944 extension = extmap->extension;
945 }
946 ao2_unlock(instance);
947
948 return extension;
949}
950
952{
954
955 ao2_lock(instance);
956
957 if (0 < id && id <= AST_VECTOR_SIZE(&instance->extmap_unique_ids)) {
958 struct rtp_extmap *extmap = AST_VECTOR_GET_ADDR(&instance->extmap_unique_ids, id - 1);
959
960 direction = extmap->direction;
961 }
962 ao2_unlock(instance);
963
964 return direction;
965}
966
967const char *ast_rtp_instance_extmap_get_uri(struct ast_rtp_instance *instance, int id)
968{
970
972 (unsigned int)extension >= ARRAY_LEN(rtp_extension_uris)) {
973 return NULL;
974 }
975
977}
978
980{
981 int res;
982
983 codecs->framing = 0;
984 ast_rwlock_init(&codecs->codecs_lock);
985 res = AST_VECTOR_INIT(&codecs->payload_mapping_rx, AST_RTP_MAX_PT);
986 res |= AST_VECTOR_INIT(&codecs->payload_mapping_tx, AST_RTP_MAX_PT);
987 if (res) {
988 AST_VECTOR_FREE(&codecs->payload_mapping_rx);
989 AST_VECTOR_FREE(&codecs->payload_mapping_tx);
990 }
991
992 return res;
993}
994
996{
997 int idx;
999
1000 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
1001 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
1002 ao2_t_cleanup(type, "destroying ast_rtp_codec rx mapping");
1003 }
1004 AST_VECTOR_FREE(&codecs->payload_mapping_rx);
1005
1006 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
1007 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
1008 ao2_t_cleanup(type, "destroying ast_rtp_codec tx mapping");
1009 }
1010 AST_VECTOR_FREE(&codecs->payload_mapping_tx);
1011
1012 ast_rwlock_destroy(&codecs->codecs_lock);
1013}
1014
1016{
1019
1020 if (instance && instance->engine && instance->engine->payload_set) {
1021 int i;
1022
1023 ao2_lock(instance);
1024 for (i = 0; i < AST_RTP_MAX_PT; i++) {
1025 instance->engine->payload_set(instance, i, 0, NULL, 0);
1026 }
1027 ao2_unlock(instance);
1028 }
1029}
1030
1031/*!
1032 * \internal
1033 * \brief Clear the rx primary mapping flag on all other matching mappings.
1034 * \since 14.0.0
1035 *
1036 * \param codecs Codecs that need rx clearing.
1037 * \param to_match Payload type object to compare against.
1038 *
1039 * \note It is assumed that codecs is write locked before calling.
1040 */
1042{
1043 int idx;
1046 struct timeval now;
1047
1048 if (!to_match->primary_mapping) {
1049 return;
1050 }
1051
1052 now = ast_tvnow();
1053 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
1054 current = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
1055
1056 if (!current || current == to_match || !current->primary_mapping) {
1057 continue;
1058 }
1059 if (current->asterisk_format && to_match->asterisk_format) {
1060 if (ast_format_cmp(current->format, to_match->format) == AST_FORMAT_CMP_NOT_EQUAL) {
1061 continue;
1062 }
1063 } else if (!current->asterisk_format && !to_match->asterisk_format) {
1064 if (current->rtp_code != to_match->rtp_code) {
1065 continue;
1066 }
1067 } else {
1068 continue;
1069 }
1070
1071 /* Replace current with non-primary marked version */
1073 if (!new_type) {
1074 continue;
1075 }
1076 *new_type = *current;
1077 new_type->primary_mapping = 0;
1078 new_type->when_retired = now;
1079 ao2_bump(new_type->format);
1080 AST_VECTOR_REPLACE(&codecs->payload_mapping_rx, idx, new_type);
1081 ao2_ref(current, -1);
1082 }
1083}
1084
1085/*!
1086 * \internal
1087 * \brief Put the new_type into the rx payload type mapping.
1088 * \since 14.0.0
1089 *
1090 * \param codecs Codecs structure to put new_type into
1091 * \param payload type position to replace.
1092 * \param new_type RTP payload mapping object to store.
1093 *
1094 * \note It is assumed that codecs is write locked before calling.
1095 */
1097{
1098 ao2_ref(new_type, +1);
1099 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_rx)) {
1100 ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_rx, payload),
1101 "cleaning up rx mapping vector element about to be replaced");
1102 }
1103 if (AST_VECTOR_REPLACE(&codecs->payload_mapping_rx, payload, new_type)) {
1104 ao2_ref(new_type, -1);
1105 return;
1106 }
1107
1109}
1110
1111/*!
1112 * \internal
1113 * \brief Copy the rx payload type mapping to the destination.
1114 * \since 14.0.0
1115 *
1116 * \param src The source codecs structure
1117 * \param dest The destination codecs structure that the values from src will be copied to
1118 * \param instance Optionally the instance that the dst codecs structure belongs to
1119 *
1120 * \note It is assumed that src is at least read locked before calling.
1121 * \note It is assumed that dest is write locked before calling.
1122 */
1123static void rtp_codecs_payloads_copy_rx(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
1124{
1125 int idx;
1126 struct ast_rtp_payload_type *type;
1127
1128 for (idx = 0; idx < AST_VECTOR_SIZE(&src->payload_mapping_rx); ++idx) {
1130 if (!type) {
1131 continue;
1132 }
1133
1134 ast_debug(2, "Copying rx payload mapping %d (%p) from %p to %p\n",
1135 idx, type, src, dest);
1137
1138 if (instance && instance->engine && instance->engine->payload_set) {
1139 ao2_lock(instance);
1140 instance->engine->payload_set(instance, idx, type->asterisk_format, type->format, type->rtp_code);
1141 ao2_unlock(instance);
1142 }
1143 }
1144}
1145
1146/*!
1147 * \internal
1148 * \brief Determine if a type of payload is already present in mappings.
1149 * \since 14.0.0
1150 *
1151 * \param codecs Codecs to be checked for mappings.
1152 * \param to_match Payload type object to compare against.
1153 *
1154 * \note It is assumed that codecs is write locked before calling.
1155 *
1156 * \retval 0 not found
1157 * \retval 1 found
1158 */
1159static int payload_mapping_tx_is_present(const struct ast_rtp_codecs *codecs, const struct ast_rtp_payload_type *to_match)
1160{
1161 int idx;
1163
1164 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
1165 current = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
1166
1167 if (!current) {
1168 continue;
1169 }
1170 if (current == to_match) {
1171 /* The exact object is already in the mapping. */
1172 return 1;
1173 }
1174 if (current->asterisk_format && to_match->asterisk_format) {
1176 continue;
1177 } else if (current->payload == to_match->payload) {
1178 return 0;
1179 }
1180 } else if (!current->asterisk_format && !to_match->asterisk_format) {
1181 if (current->rtp_code != to_match->rtp_code) {
1182 continue;
1183 }
1184 } else {
1185 continue;
1186 }
1187
1188 return 1;
1189 }
1190
1191 return 0;
1192}
1193
1194/*!
1195 * \internal
1196 * \brief Copy the tx payload type mapping to the destination.
1197 * \since 14.0.0
1198 *
1199 * \param src The source codecs structure
1200 * \param dest The destination codecs structure that the values from src will be copied to
1201 * \param instance Optionally the instance that the dst codecs structure belongs to
1202 *
1203 * \note It is assumed that src is at least read locked before calling.
1204 * \note It is assumed that dest is write locked before calling.
1205 */
1206static void rtp_codecs_payloads_copy_tx(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
1207{
1208 int idx;
1209 struct ast_rtp_payload_type *type;
1210
1211 for (idx = 0; idx < AST_VECTOR_SIZE(&src->payload_mapping_tx); ++idx) {
1213 if (!type) {
1214 continue;
1215 }
1216
1217 ast_debug(2, "Copying tx payload mapping %d (%p) from %p to %p\n",
1218 idx, type, src, dest);
1219 ao2_ref(type, +1);
1220 if (idx < AST_VECTOR_SIZE(&dest->payload_mapping_tx)) {
1222 "cleaning up tx mapping vector element about to be replaced");
1223 }
1224 if (AST_VECTOR_REPLACE(&dest->payload_mapping_tx, idx, type)) {
1225 ao2_ref(type, -1);
1226 continue;
1227 }
1228
1229 if (instance && instance->engine && instance->engine->payload_set) {
1230 ao2_lock(instance);
1231 instance->engine->payload_set(instance, idx, type->asterisk_format, type->format, type->rtp_code);
1232 ao2_unlock(instance);
1233 }
1234 }
1235}
1236
1237void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
1238{
1239 int idx;
1240 struct ast_rtp_payload_type *type;
1241
1243
1244 /* Deadlock avoidance because of held write lock. */
1245 while (ast_rwlock_tryrdlock(&src->codecs_lock)) {
1247 sched_yield();
1249 }
1250
1251 /*
1252 * This represents a completely new mapping of what the remote party is
1253 * expecting for payloads, so we clear out the entire tx payload mapping
1254 * vector and replace it.
1255 */
1256 for (idx = 0; idx < AST_VECTOR_SIZE(&dest->payload_mapping_tx); ++idx) {
1257 type = AST_VECTOR_GET(&dest->payload_mapping_tx, idx);
1258 ao2_t_cleanup(type, "destroying ast_rtp_codec tx mapping");
1260 }
1261
1262 rtp_codecs_payloads_copy_rx(src, dest, instance);
1263 rtp_codecs_payloads_copy_tx(src, dest, instance);
1264 dest->framing = src->framing;
1265
1268}
1269
1270void ast_rtp_codecs_payloads_xover(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
1271{
1272 int idx;
1273 struct ast_rtp_payload_type *type;
1274
1276 if (src != dest) {
1277 /* Deadlock avoidance because of held write lock. */
1278 while (ast_rwlock_tryrdlock(&src->codecs_lock)) {
1280 sched_yield();
1282 }
1283 }
1284
1285 /* Crossover copy payload type tx mapping to rx mapping. */
1286 for (idx = 0; idx < AST_VECTOR_SIZE(&src->payload_mapping_tx); ++idx) {
1288 if (!type) {
1289 continue;
1290 }
1291
1292 /* All tx mapping elements should have the primary flag set. */
1293 ast_assert(type->primary_mapping);
1294
1295 ast_debug(2, "Crossover copying tx to rx payload mapping %d (%p) from %p to %p\n",
1296 idx, type, src, dest);
1298
1299 if (instance && instance->engine && instance->engine->payload_set) {
1300 ao2_lock(instance);
1301 instance->engine->payload_set(instance, idx, type->asterisk_format, type->format, type->rtp_code);
1302 ao2_unlock(instance);
1303 }
1304 }
1305
1306 dest->framing = src->framing;
1307
1308 if (src != dest) {
1310 }
1312}
1313
1315{
1317
1318 if (payload < 0 || payload >= AST_RTP_MAX_PT || payload > AST_RTP_PT_LAST_STATIC) {
1319 return;
1320 }
1321
1325 if (!new_type) {
1326 ast_debug(1, "Don't have a default tx payload type %d format for m type on %p\n",
1327 payload, codecs);
1328 return;
1329 }
1330
1331 ast_debug(1, "Setting tx payload type %d based on m type on %p\n",
1332 payload, codecs);
1333
1334 ast_rwlock_wrlock(&codecs->codecs_lock);
1335
1337 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1338 ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, payload),
1339 "cleaning up replaced tx payload type");
1340 }
1341
1342 if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, new_type)) {
1343 ao2_ref(new_type, -1);
1344 } else if (instance && instance->engine && instance->engine->payload_set) {
1345 ao2_lock(instance);
1346 instance->engine->payload_set(instance, payload, new_type->asterisk_format, new_type->format, new_type->rtp_code);
1347 ao2_unlock(instance);
1348 }
1349 } else {
1350 ao2_ref(new_type, -1);
1351 }
1352
1353 ast_rwlock_unlock(&codecs->codecs_lock);
1354}
1355
1357 char *mimetype, char *mimesubtype,
1359 unsigned int sample_rate)
1360{
1361 unsigned int idx;
1362 int found = 0;
1363
1364 if (pt < 0 || pt >= AST_RTP_MAX_PT) {
1365 return -1; /* bogus payload type */
1366 }
1367
1369 ast_rwlock_wrlock(&codecs->codecs_lock);
1370
1371 for (idx = 0; idx < mime_types_len; ++idx) {
1372 const struct ast_rtp_mime_type *t = &ast_rtp_mime_types[idx];
1374
1375 if (strcasecmp(mimesubtype, t->subtype)) {
1376 continue;
1377 }
1378
1379 if (strcasecmp(mimetype, t->type)) {
1380 continue;
1381 }
1382
1383 /* if both sample rates have been supplied, and they don't match,
1384 * then this not a match; if one has not been supplied, then the
1385 * rates are not compared */
1386 if (sample_rate && t->sample_rate &&
1387 (sample_rate != t->sample_rate)) {
1388 continue;
1389 }
1390
1391 found = 1;
1392
1394 if (!new_type) {
1395 continue;
1396 }
1397
1398 new_type->asterisk_format = t->payload_type.asterisk_format;
1399 new_type->rtp_code = t->payload_type.rtp_code;
1400 new_type->payload = pt;
1401 new_type->primary_mapping = 1;
1406 } else {
1407 new_type->format = t->payload_type.format;
1408 }
1409
1410 if (new_type->format) {
1411 /* SDP parsing automatically increases the reference count */
1412 new_type->format = ast_format_parse_sdp_fmtp(new_type->format, "");
1413 }
1414
1416 if (pt < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1417 ao2_t_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, pt),
1418 "cleaning up replaced tx payload type");
1419 }
1420
1421 if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, pt, new_type)) {
1422 ao2_ref(new_type, -1);
1423 } else if (instance && instance->engine && instance->engine->payload_set) {
1424 ao2_lock(instance);
1425 instance->engine->payload_set(instance, pt, new_type->asterisk_format, new_type->format, new_type->rtp_code);
1426 ao2_unlock(instance);
1427 }
1428 } else {
1429 ao2_ref(new_type, -1);
1430 }
1431
1432 break;
1433 }
1434
1435 ast_rwlock_unlock(&codecs->codecs_lock);
1437
1438 return (found ? 0 : -2);
1439}
1440
1441int 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)
1442{
1443 return ast_rtp_codecs_payloads_set_rtpmap_type_rate(codecs, instance, payload, mimetype, mimesubtype, options, 0);
1444}
1445
1447{
1448 struct ast_rtp_payload_type *type;
1449
1450 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
1451 return;
1452 }
1453
1454 ast_debug(2, "Unsetting payload %d on %p\n", payload, codecs);
1455
1456 ast_rwlock_wrlock(&codecs->codecs_lock);
1457
1458 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1459 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, payload);
1461 AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, NULL);
1462 }
1463
1464 if (instance && instance->engine && instance->engine->payload_set) {
1465 ao2_lock(instance);
1466 instance->engine->payload_set(instance, payload, 0, NULL, 0);
1467 ao2_unlock(instance);
1468 }
1469
1470 ast_rwlock_unlock(&codecs->codecs_lock);
1471}
1472
1474{
1475 enum ast_media_type stream_type = AST_MEDIA_TYPE_UNKNOWN;
1476 int payload;
1477 struct ast_rtp_payload_type *type;
1478
1479 ast_rwlock_rdlock(&codecs->codecs_lock);
1480 for (payload = 0; payload < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++payload) {
1481 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, payload);
1482 if (type && type->asterisk_format) {
1483 stream_type = ast_format_get_type(type->format);
1484 break;
1485 }
1486 }
1487 ast_rwlock_unlock(&codecs->codecs_lock);
1488
1489 return stream_type;
1490}
1491
1493{
1494 struct ast_rtp_payload_type *type = NULL;
1495
1496 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
1497 return NULL;
1498 }
1499
1500 ast_rwlock_rdlock(&codecs->codecs_lock);
1501 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_rx)) {
1502 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, payload);
1503 ao2_bump(type);
1504 }
1505 ast_rwlock_unlock(&codecs->codecs_lock);
1506
1507 if (!type && payload <= AST_RTP_PT_LAST_STATIC) {
1511 }
1512
1513 return type;
1514}
1515
1517{
1518 struct ast_rtp_payload_type *type;
1519
1520 if (payload < 0 || payload >= AST_RTP_MAX_PT || !format) {
1521 return -1;
1522 }
1523
1525 if (!type) {
1526 return -1;
1527 }
1528 ao2_ref(format, +1);
1529 type->format = format;
1530 type->asterisk_format = 1;
1531 type->payload = payload;
1532 type->primary_mapping = 1;
1533
1534 ast_rwlock_wrlock(&codecs->codecs_lock);
1536 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1537 ao2_cleanup(AST_VECTOR_GET(&codecs->payload_mapping_tx, payload));
1538 }
1539 if (AST_VECTOR_REPLACE(&codecs->payload_mapping_tx, payload, type)) {
1540 ao2_ref(type, -1);
1541 }
1542 } else {
1543 ao2_ref(type, -1);
1544 }
1545 ast_rwlock_unlock(&codecs->codecs_lock);
1546
1547 return 0;
1548}
1549
1551{
1552 struct ast_rtp_payload_type *type;
1553 struct ast_format *format = NULL;
1554
1555 if (payload < 0 || payload >= AST_RTP_MAX_PT) {
1556 return NULL;
1557 }
1558
1559 ast_rwlock_rdlock(&codecs->codecs_lock);
1560 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1561 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, payload);
1562 if (type && type->asterisk_format) {
1563 format = ao2_bump(type->format);
1564 }
1565 }
1566 ast_rwlock_unlock(&codecs->codecs_lock);
1567
1568 return format;
1569}
1570
1571void ast_rtp_codecs_set_framing(struct ast_rtp_codecs *codecs, unsigned int framing)
1572{
1573 if (!framing) {
1574 return;
1575 }
1576
1577 ast_rwlock_wrlock(&codecs->codecs_lock);
1578 codecs->framing = framing;
1579 ast_rwlock_unlock(&codecs->codecs_lock);
1580}
1581
1583{
1584 unsigned int framing;
1585
1586 ast_rwlock_rdlock(&codecs->codecs_lock);
1587 framing = codecs->framing;
1588 ast_rwlock_unlock(&codecs->codecs_lock);
1589
1590 return framing;
1591}
1592
1593void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, struct ast_format_cap *astformats, int *nonastformats)
1594{
1595 int idx;
1596
1598 *nonastformats = 0;
1599
1600 ast_rwlock_rdlock(&codecs->codecs_lock);
1601
1602 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
1603 struct ast_rtp_payload_type *type;
1604
1605 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
1606 if (!type) {
1607 continue;
1608 }
1609
1610 if (type->asterisk_format) {
1611 ast_format_cap_append(astformats, type->format, 0);
1612 } else {
1613 *nonastformats |= type->rtp_code;
1614 }
1615 }
1616 if (codecs->framing) {
1617 ast_format_cap_set_framing(astformats, codecs->framing);
1618 }
1619
1620 ast_rwlock_unlock(&codecs->codecs_lock);
1621}
1622
1623/*!
1624 * \internal
1625 * \brief Find the static payload type mapping for the format.
1626 * \since 14.0.0
1627 *
1628 * \param asterisk_format Non-zero if the given Asterisk format is present
1629 * \param format Asterisk format to look for
1630 * \param code The non-Asterisk format code to look for
1631 *
1632 * \note It is assumed that static_RTP_PT_lock is at least read locked before calling.
1633 *
1634 * \return Numerical payload type
1635 * \retval -1 if not found.
1636 */
1637static int find_static_payload_type(int asterisk_format, const struct ast_format *format, int code)
1638{
1639 int idx;
1640 int payload = -1;
1641
1642 if (!asterisk_format) {
1643 for (idx = 0; idx < AST_RTP_MAX_PT; ++idx) {
1644 if (static_RTP_PT[idx]
1646 && static_RTP_PT[idx]->rtp_code == code) {
1647 payload = idx;
1648 break;
1649 }
1650 }
1651 } else if (format) {
1652 for (idx = 0; idx < AST_RTP_MAX_PT; ++idx) {
1653 if (static_RTP_PT[idx]
1657 payload = idx;
1658 break;
1659 }
1660 }
1661 }
1662
1663 return payload;
1664}
1665
1666/*!
1667 * \internal
1668 * \brief Find the first unused payload type in a given range
1669 *
1670 * \param codecs The codec structure to look in
1671 * \param start Starting index
1672 * \param end Ending index
1673 * \param ignore Skip these payloads types
1674 *
1675 * \note The static_RTP_PT_lock object must be locked before calling
1676 *
1677 * \return Numerical payload type
1678 * \retval -1 if not found.
1679 */
1681 int start, int end, struct ast_rtp_payload_type *ignore[])
1682{
1683 int x;
1684
1685 for (x = start; x < end; ++x) {
1686 struct ast_rtp_payload_type *type;
1687
1688 if (ignore[x]) {
1689 continue;
1690 } else if (!codecs || x >= AST_VECTOR_SIZE(&codecs->payload_mapping_rx)) {
1691 return x;
1692 }
1693
1694 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, x);
1695 if (!type) {
1696 return x;
1697 }
1698 }
1699 return -1;
1700}
1701
1702/*!
1703 * \internal
1704 * \brief Find an unused payload type
1705 *
1706 * \param codecs Codecs structure to look in
1707 *
1708 * \note Both static_RTP_PT_lock and codecs (if given) must be at least
1709 * read locked before calling.
1710 *
1711 * \return Numerical payload type
1712 * \retval -1 if not found.
1713 */
1715{
1716 int res;
1717
1718 /* find next available dynamic payload slot */
1721 if (res != -1) {
1722 return res;
1723 }
1724
1726 /*
1727 * We're using default values for some dynamic types. So if an unused
1728 * slot was not found try again, but this time ignore the default
1729 * values declared for dynamic types (except for 101 and 121) .
1730 */
1731 static struct ast_rtp_payload_type *ignore[AST_RTP_MAX_PT] = {0};
1732
1733 ignore[101] = static_RTP_PT[101];
1734 ignore[121] = static_RTP_PT[121];
1735
1738 if (res != -1) {
1739 return res;
1740 }
1741 }
1742
1743 /* http://www.iana.org/assignments/rtp-parameters
1744 * RFC 3551, Section 3: "[...] applications which need to define more
1745 * than 32 dynamic payload types MAY bind codes below 96, in which case
1746 * it is RECOMMENDED that unassigned payload type numbers be used
1747 * first". Updated by RFC 5761, Section 4: "[...] values in the range
1748 * 64-95 MUST NOT be used [to avoid conflicts with RTCP]". Summaries:
1749 * https://tools.ietf.org/html/draft-roach-mmusic-unified-plan#section-3.2.1.2
1750 * https://tools.ietf.org/html/draft-wu-avtcore-dynamic-pt-usage#section-3
1751 */
1755 if (res != -1) {
1756 return res;
1757 }
1758
1759 /* Yet, reusing mappings below AST_RTP_PT_LAST_STATIC (35) is not supported
1760 * in Asterisk because when Compact Headers are activated, no rtpmap is
1761 * send for those below 35. If you want to use 35 and below
1762 * A) do not use Compact Headers,
1763 * B) remove that code in res_pjsip, or
1764 * C) add a flag that this RTP Payload Type got reassigned dynamically
1765 * and requires a rtpmap even with Compact Headers enabled.
1766 */
1770 if (res != -1) {
1771 return res;
1772 }
1773
1776 20, static_RTP_PT);
1777}
1778
1779/*!
1780 * \internal
1781 * \brief Find the oldest non-primary dynamic rx payload type.
1782 * \since 14.0.0
1783 *
1784 * \param codecs Codecs structure to look in
1785 *
1786 * \note It is assumed that codecs is at least read locked before calling.
1787 *
1788 * \return Numerical payload type
1789 * \retval -1 if not found.
1790 */
1792{
1793 struct ast_rtp_payload_type *type;
1794 struct timeval oldest;
1795 int idx;
1796 int payload = -1;
1797
1799 for (; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
1800 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
1801 if (type
1802 && !type->primary_mapping
1803 && (payload == -1
1804 || ast_tvdiff_ms(type->when_retired, oldest) < 0)) {
1805 oldest = type->when_retired;
1806 payload = idx;
1807 }
1808 }
1809 return payload;
1810}
1811
1812/*!
1813 * \internal
1814 * \brief Assign a payload type for the rx mapping.
1815 * \since 14.0.0
1816 *
1817 * \param codecs Codecs structure to look in
1818 * \param asterisk_format Non-zero if the given Asterisk format is present
1819 * \param format Asterisk format to look for
1820 * \param code The format to look for
1821 * \param explicit Require the provided code to be explicitly used
1822 *
1823 * \note It is assumed that static_RTP_PT_lock is at least read locked before calling.
1824 *
1825 * \return Numerical payload type
1826 * \retval -1 if could not assign.
1827 */
1828static int rtp_codecs_assign_payload_code_rx(struct ast_rtp_codecs *codecs, int asterisk_format, struct ast_format *format, int code, int explicit)
1829{
1830 int payload = code;
1832
1833 if (!explicit) {
1835
1837 return payload;
1838 }
1839 }
1840
1842 if (!new_type) {
1843 return -1;
1844 }
1845
1846 ast_rwlock_wrlock(&codecs->codecs_lock);
1848 || AST_VECTOR_SIZE(&codecs->payload_mapping_rx) <= payload
1849 || !AST_VECTOR_GET(&codecs->payload_mapping_rx, payload))) {
1850 /*
1851 * The payload type is a static assignment
1852 * or our default dynamic position is available.
1853 */
1855 } else if (!explicit && (-1 < (payload = find_unused_payload(codecs))
1857 /*
1858 * We found the first available empty dynamic position
1859 * or we found a mapping that should no longer be
1860 * actively used.
1861 */
1862 new_type->payload = payload;
1864 } else if (explicit) {
1865 /*
1866 * They explicitly requested this payload number be used but it couldn't be
1867 */
1868 payload = -1;
1869 } else {
1870 /*
1871 * There are no empty or non-primary dynamic positions
1872 * left. Sadness.
1873 *
1874 * I don't think this is really possible.
1875 */
1876 ast_log(LOG_WARNING, "No dynamic RTP payload type values available "
1877 "for %s - %d!\n", format ? ast_format_get_name(format) : "", code);
1878 }
1879 ast_rwlock_unlock(&codecs->codecs_lock);
1880
1881 ao2_ref(new_type, -1);
1882
1883 return payload;
1884}
1885
1887{
1888 struct ast_rtp_payload_type *type;
1889 int idx;
1890 int payload = -1;
1891
1893 if (!asterisk_format) {
1894 ast_rwlock_rdlock(&codecs->codecs_lock);
1895 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
1896 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
1897 if (!type) {
1898 continue;
1899 }
1900
1901 if (!type->asterisk_format
1902 && type->primary_mapping
1903 && type->rtp_code == code) {
1904 payload = idx;
1905 break;
1906 }
1907 }
1908 ast_rwlock_unlock(&codecs->codecs_lock);
1909 } else if (format) {
1910 ast_rwlock_rdlock(&codecs->codecs_lock);
1911 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_rx); ++idx) {
1912 type = AST_VECTOR_GET(&codecs->payload_mapping_rx, idx);
1913 if (!type) {
1914 continue;
1915 }
1916
1917 if (type->asterisk_format
1918 && type->primary_mapping
1920 payload = idx;
1921 break;
1922 }
1923 }
1924 ast_rwlock_unlock(&codecs->codecs_lock);
1925 }
1926
1927 if (payload < 0) {
1929 code, 0);
1930 }
1932
1933 return payload;
1934}
1935
1937{
1938 return rtp_codecs_assign_payload_code_rx(codecs, 1, format, code, 1);
1939}
1940
1942{
1943 struct ast_rtp_payload_type *type;
1944 int idx;
1945 int payload = -1;
1946
1947 if (!asterisk_format) {
1948 ast_rwlock_rdlock(&codecs->codecs_lock);
1949 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
1950 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
1951 if (!type) {
1952 continue;
1953 }
1954
1955 if (!type->asterisk_format
1956 && type->rtp_code == code) {
1957 payload = idx;
1958 break;
1959 }
1960 }
1961 ast_rwlock_unlock(&codecs->codecs_lock);
1962 } else if (format) {
1963 ast_rwlock_rdlock(&codecs->codecs_lock);
1964 for (idx = 0; idx < AST_VECTOR_SIZE(&codecs->payload_mapping_tx); ++idx) {
1965 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, idx);
1966 if (!type) {
1967 continue;
1968 }
1969
1970 if (type->asterisk_format
1972 payload = idx;
1973 break;
1974 }
1975 }
1976 ast_rwlock_unlock(&codecs->codecs_lock);
1977 }
1978
1979 if (payload < 0) {
1983 }
1984
1985 return payload;
1986}
1987
1989{
1990 struct ast_rtp_payload_type *type;
1991 int res = -1;
1992
1993 ast_rwlock_rdlock(&codecs->codecs_lock);
1994 if (payload < AST_VECTOR_SIZE(&codecs->payload_mapping_tx)) {
1995 type = AST_VECTOR_GET(&codecs->payload_mapping_tx, payload);
1996 if (type) {
1997 res = payload;
1998 }
1999 }
2000 ast_rwlock_unlock(&codecs->codecs_lock);
2001
2002 return res;
2003}
2004
2006 const struct ast_format *format, int code, enum ast_rtp_options options)
2007{
2008 int i;
2009 const char *res = "";
2010
2012 for (i = 0; i < mime_types_len; i++) {
2013 if (ast_rtp_mime_types[i].payload_type.asterisk_format && asterisk_format && format &&
2014 (ast_format_cmp(format, ast_rtp_mime_types[i].payload_type.format) != AST_FORMAT_CMP_NOT_EQUAL)) {
2017 res = "G726-32";
2018 break;
2019 } else {
2020 res = ast_rtp_mime_types[i].subtype;
2021 break;
2022 }
2023 } else if (!ast_rtp_mime_types[i].payload_type.asterisk_format && !asterisk_format &&
2025
2026 res = ast_rtp_mime_types[i].subtype;
2027 break;
2028 }
2029 }
2031
2032 return res;
2033}
2034
2036 const struct ast_format *format, int code)
2037{
2038 unsigned int i;
2039 unsigned int res = 0;
2040
2042 for (i = 0; i < mime_types_len; ++i) {
2043 if (ast_rtp_mime_types[i].payload_type.asterisk_format && asterisk_format && format &&
2044 (ast_format_cmp(format, ast_rtp_mime_types[i].payload_type.format) != AST_FORMAT_CMP_NOT_EQUAL)) {
2046 break;
2047 } else if (!ast_rtp_mime_types[i].payload_type.asterisk_format && !asterisk_format &&
2050 break;
2051 }
2052 }
2054
2055 return res;
2056}
2057
2058char *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)
2059{
2060 int found = 0;
2061 const char *name;
2062 if (!buf) {
2063 return NULL;
2064 }
2065
2066
2067 if (asterisk_format) {
2068 int x;
2069 struct ast_format *tmp_fmt;
2070 for (x = 0; x < ast_format_cap_count(ast_format_capability); x++) {
2071 tmp_fmt = ast_format_cap_get_format(ast_format_capability, x);
2072 name = ast_rtp_lookup_mime_subtype2(asterisk_format, tmp_fmt, 0, options);
2073 ao2_ref(tmp_fmt, -1);
2074 ast_str_append(&buf, 0, "%s|", name);
2075 found = 1;
2076 }
2077 } else {
2078 int x;
2079 ast_str_append(&buf, 0, "0x%x (", (unsigned int) rtp_capability);
2080 for (x = 1; x <= AST_RTP_MAX; x <<= 1) {
2081 if (rtp_capability & x) {
2082 name = ast_rtp_lookup_mime_subtype2(asterisk_format, NULL, x, options);
2083 ast_str_append(&buf, 0, "%s|", name);
2084 found = 1;
2085 }
2086 }
2087 }
2088
2089 ast_str_append(&buf, 0, "%s", found ? ")" : "nothing)");
2090
2091 return ast_str_buffer(buf);
2092}
2093
2095{
2096 int res;
2097
2098 if (instance->engine->dtmf_begin) {
2099 ao2_lock(instance);
2100 res = instance->engine->dtmf_begin(instance, digit);
2101 ao2_unlock(instance);
2102 } else {
2103 res = -1;
2104 }
2105 return res;
2106}
2107
2109{
2110 int res;
2111
2112 if (instance->engine->dtmf_end) {
2113 ao2_lock(instance);
2114 res = instance->engine->dtmf_end(instance, digit);
2115 ao2_unlock(instance);
2116 } else {
2117 res = -1;
2118 }
2119 return res;
2120}
2121
2122int ast_rtp_instance_dtmf_end_with_duration(struct ast_rtp_instance *instance, char digit, unsigned int duration)
2123{
2124 int res;
2125
2126 if (instance->engine->dtmf_end_with_duration) {
2127 ao2_lock(instance);
2128 res = instance->engine->dtmf_end_with_duration(instance, digit, duration);
2129 ao2_unlock(instance);
2130 } else {
2131 res = -1;
2132 }
2133 return res;
2134}
2135
2137{
2138 int res;
2139
2140 if (instance->engine->dtmf_mode_set) {
2141 ao2_lock(instance);
2142 res = instance->engine->dtmf_mode_set(instance, dtmf_mode);
2143 ao2_unlock(instance);
2144 } else {
2145 res = -1;
2146 }
2147 return res;
2148}
2149
2151{
2152 int res;
2153
2154 if (instance->engine->dtmf_mode_get) {
2155 ao2_lock(instance);
2156 res = instance->engine->dtmf_mode_get(instance);
2157 ao2_unlock(instance);
2158 } else {
2159 res = 0;
2160 }
2161 return res;
2162}
2163
2165{
2166 if (instance->engine->update_source) {
2167 ao2_lock(instance);
2168 instance->engine->update_source(instance);
2169 ao2_unlock(instance);
2170 }
2171}
2172
2174{
2175 if (instance->engine->change_source) {
2176 ao2_lock(instance);
2177 instance->engine->change_source(instance);
2178 ao2_unlock(instance);
2179 }
2180}
2181
2182int ast_rtp_instance_set_qos(struct ast_rtp_instance *instance, int tos, int cos, const char *desc)
2183{
2184 int res;
2185
2186 if (instance->engine->qos) {
2187 ao2_lock(instance);
2188 res = instance->engine->qos(instance, tos, cos, desc);
2189 ao2_unlock(instance);
2190 } else {
2191 res = -1;
2192 }
2193 return res;
2194}
2195
2197{
2198 if (instance->engine->stop) {
2199 ao2_lock(instance);
2200 instance->engine->stop(instance);
2201 ao2_unlock(instance);
2202 }
2203}
2204
2205int ast_rtp_instance_fd(struct ast_rtp_instance *instance, int rtcp)
2206{
2207 int res;
2208
2209 if (instance->engine->fd) {
2210 ao2_lock(instance);
2211 res = instance->engine->fd(instance, rtcp);
2212 ao2_unlock(instance);
2213 } else {
2214 res = -1;
2215 }
2216 return res;
2217}
2218
2220{
2221 struct ast_rtp_glue *glue = NULL;
2222
2224
2226 if (!strcasecmp(glue->type, type)) {
2227 break;
2228 }
2229 }
2230
2232
2233 return glue;
2234}
2235
2236/*!
2237 * \brief Conditionally unref an rtp instance
2238 */
2239static void unref_instance_cond(struct ast_rtp_instance **instance)
2240{
2241 if (*instance) {
2242 ao2_ref(*instance, -1);
2243 *instance = NULL;
2244 }
2245}
2246
2248{
2249 struct ast_rtp_instance *bridged;
2250
2251 ao2_lock(instance);
2252 bridged = instance->bridged;
2253 ao2_unlock(instance);
2254 return bridged;
2255}
2256
2258{
2259 ao2_lock(instance);
2260 instance->bridged = bridged;
2261 ao2_unlock(instance);
2262}
2263
2265{
2266 struct ast_rtp_instance *instance_dst = NULL, *instance_src = NULL,
2267 *vinstance_dst = NULL, *vinstance_src = NULL,
2268 *tinstance_dst = NULL, *tinstance_src = NULL;
2269 struct ast_rtp_glue *glue_dst, *glue_src;
2270 enum ast_rtp_glue_result audio_glue_dst_res = AST_RTP_GLUE_RESULT_FORBID, video_glue_dst_res = AST_RTP_GLUE_RESULT_FORBID;
2271 enum ast_rtp_glue_result audio_glue_src_res = AST_RTP_GLUE_RESULT_FORBID, video_glue_src_res = AST_RTP_GLUE_RESULT_FORBID;
2274
2275 /* Lock both channels so we can look for the glue that binds them together */
2276 ast_channel_lock_both(c_dst, c_src);
2277
2278 if (!cap_src || !cap_dst) {
2279 goto done;
2280 }
2281
2282 /* Grab glue that binds each channel to something using the RTP engine */
2283 if (!(glue_dst = ast_rtp_instance_get_glue(ast_channel_tech(c_dst)->type)) || !(glue_src = ast_rtp_instance_get_glue(ast_channel_tech(c_src)->type))) {
2284 ast_debug(1, "Can't find native functions for channel '%s'\n", glue_dst ? ast_channel_name(c_src) : ast_channel_name(c_dst));
2285 goto done;
2286 }
2287
2288 audio_glue_dst_res = glue_dst->get_rtp_info(c_dst, &instance_dst);
2289 video_glue_dst_res = glue_dst->get_vrtp_info ? glue_dst->get_vrtp_info(c_dst, &vinstance_dst) : AST_RTP_GLUE_RESULT_FORBID;
2290
2291 audio_glue_src_res = glue_src->get_rtp_info(c_src, &instance_src);
2292 video_glue_src_res = glue_src->get_vrtp_info ? glue_src->get_vrtp_info(c_src, &vinstance_src) : AST_RTP_GLUE_RESULT_FORBID;
2293
2294 /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
2295 if (video_glue_dst_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue_dst_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue_dst_res != AST_RTP_GLUE_RESULT_REMOTE)) {
2296 audio_glue_dst_res = AST_RTP_GLUE_RESULT_FORBID;
2297 }
2298 if (video_glue_src_res != AST_RTP_GLUE_RESULT_FORBID && (audio_glue_src_res != AST_RTP_GLUE_RESULT_REMOTE || video_glue_src_res != AST_RTP_GLUE_RESULT_REMOTE)) {
2299 audio_glue_src_res = AST_RTP_GLUE_RESULT_FORBID;
2300 }
2301 if (audio_glue_dst_res == AST_RTP_GLUE_RESULT_REMOTE && (video_glue_dst_res == AST_RTP_GLUE_RESULT_FORBID || video_glue_dst_res == AST_RTP_GLUE_RESULT_REMOTE) && glue_dst->get_codec) {
2302 glue_dst->get_codec(c_dst, cap_dst);
2303 }
2304 if (audio_glue_src_res == AST_RTP_GLUE_RESULT_REMOTE && (video_glue_src_res == AST_RTP_GLUE_RESULT_FORBID || video_glue_src_res == AST_RTP_GLUE_RESULT_REMOTE) && glue_src->get_codec) {
2305 glue_src->get_codec(c_src, cap_src);
2306 }
2307
2308 /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
2309 if (audio_glue_dst_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue_src_res != AST_RTP_GLUE_RESULT_REMOTE) {
2310 goto done;
2311 }
2312
2313 /* Make sure we have matching codecs */
2314 if (!ast_format_cap_iscompatible(cap_dst, cap_src)) {
2315 goto done;
2316 }
2317
2318 ast_rtp_codecs_payloads_xover(&instance_src->codecs, &instance_dst->codecs, instance_dst);
2319
2320 if (vinstance_dst && vinstance_src) {
2321 ast_rtp_codecs_payloads_xover(&vinstance_src->codecs, &vinstance_dst->codecs, vinstance_dst);
2322 }
2323 if (tinstance_dst && tinstance_src) {
2324 ast_rtp_codecs_payloads_xover(&tinstance_src->codecs, &tinstance_dst->codecs, tinstance_dst);
2325 }
2326
2327 if (glue_dst->update_peer(c_dst, instance_src, vinstance_src, tinstance_src, cap_src, 0)) {
2328 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n",
2329 ast_channel_name(c_dst), ast_channel_name(c_src));
2330 } else {
2331 ast_debug(1, "Seeded SDP of '%s' with that of '%s'\n",
2332 ast_channel_name(c_dst), ast_channel_name(c_src));
2333 }
2334
2335done:
2336 ast_channel_unlock(c_dst);
2337 ast_channel_unlock(c_src);
2338
2339 ao2_cleanup(cap_dst);
2340 ao2_cleanup(cap_src);
2341
2342 unref_instance_cond(&instance_dst);
2343 unref_instance_cond(&instance_src);
2344 unref_instance_cond(&vinstance_dst);
2345 unref_instance_cond(&vinstance_src);
2346 unref_instance_cond(&tinstance_dst);
2347 unref_instance_cond(&tinstance_src);
2348}
2349
2351{
2352 struct ast_rtp_instance *instance0 = NULL, *instance1 = NULL,
2353 *vinstance0 = NULL, *vinstance1 = NULL,
2354 *tinstance0 = NULL, *tinstance1 = NULL;
2355 struct ast_rtp_glue *glue0, *glue1;
2356 enum ast_rtp_glue_result audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID, video_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
2357 enum ast_rtp_glue_result audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID, video_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
2360
2361 /* If there is no second channel just immediately bail out, we are of no use in that scenario */
2362 if (!c1 || !cap1 || !cap0) {
2363 ao2_cleanup(cap0);
2364 ao2_cleanup(cap1);
2365 return -1;
2366 }
2367
2368 /* Lock both channels so we can look for the glue that binds them together */
2369 ast_channel_lock_both(c0, c1);
2370
2371 /* Grab glue that binds each channel to something using the RTP engine */
2373 ast_log(LOG_WARNING, "Can't find native functions for channel '%s'\n", glue0 ? ast_channel_name(c1) : ast_channel_name(c0));
2374 goto done;
2375 }
2376
2377 audio_glue0_res = glue0->get_rtp_info(c0, &instance0);
2378 video_glue0_res = glue0->get_vrtp_info ? glue0->get_vrtp_info(c0, &vinstance0) : AST_RTP_GLUE_RESULT_FORBID;
2379
2380 audio_glue1_res = glue1->get_rtp_info(c1, &instance1);
2381 video_glue1_res = glue1->get_vrtp_info ? glue1->get_vrtp_info(c1, &vinstance1) : AST_RTP_GLUE_RESULT_FORBID;
2382
2383 /* If we are carrying video, and both sides are not going to remotely bridge... fail the native bridge */
2384 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)) {
2385 audio_glue0_res = AST_RTP_GLUE_RESULT_FORBID;
2386 }
2387 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)) {
2388 audio_glue1_res = AST_RTP_GLUE_RESULT_FORBID;
2389 }
2390 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) {
2391 glue0->get_codec(c0, cap0);
2392 }
2393 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) {
2394 glue1->get_codec(c1, cap1);
2395 }
2396
2397 /* If any sort of bridge is forbidden just completely bail out and go back to generic bridging */
2398 if (audio_glue0_res != AST_RTP_GLUE_RESULT_REMOTE || audio_glue1_res != AST_RTP_GLUE_RESULT_REMOTE) {
2399 goto done;
2400 }
2401
2402 /* Make sure we have matching codecs */
2403 if (!ast_format_cap_iscompatible(cap0, cap1)) {
2404 goto done;
2405 }
2406
2407 /* Bridge media early */
2408 if (glue0->update_peer(c0, instance1, vinstance1, tinstance1, cap1, 0)) {
2409 ast_log(LOG_WARNING, "Channel '%s' failed to setup early bridge to '%s'\n", ast_channel_name(c0), c1 ? ast_channel_name(c1) : "<unspecified>");
2410 }
2411
2412done:
2415
2416 ao2_cleanup(cap0);
2417 ao2_cleanup(cap1);
2418
2419 unref_instance_cond(&instance0);
2420 unref_instance_cond(&instance1);
2421 unref_instance_cond(&vinstance0);
2422 unref_instance_cond(&vinstance1);
2423 unref_instance_cond(&tinstance0);
2424 unref_instance_cond(&tinstance1);
2425
2426 ast_debug(1, "Setting early bridge SDP of '%s' with that of '%s'\n", ast_channel_name(c0), c1 ? ast_channel_name(c1) : "<unspecified>");
2427
2428 return 0;
2429}
2430
2431int ast_rtp_red_init(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations)
2432{
2433 int res;
2434
2435 if (instance->engine->red_init) {
2436 ao2_lock(instance);
2437 res = instance->engine->red_init(instance, buffer_time, payloads, generations);
2438 ao2_unlock(instance);
2439 } else {
2440 res = -1;
2441 }
2442 return res;
2443}
2444
2445int ast_rtp_red_buffer(struct ast_rtp_instance *instance, struct ast_frame *frame)
2446{
2447 int res;
2448
2449 if (instance->engine->red_buffer) {
2450 ao2_lock(instance);
2451 res = instance->engine->red_buffer(instance, frame);
2452 ao2_unlock(instance);
2453 } else {
2454 res = -1;
2455 }
2456 return res;
2457}
2458
2460{
2461 int res;
2462
2463 if (!instance || !instance->engine || !stats) {
2464 return -1;
2465 }
2466
2467 if (instance->engine->get_stat) {
2468 ao2_lock(instance);
2469 res = instance->engine->get_stat(instance, stats, stat);
2470 ao2_unlock(instance);
2471 } else {
2472 res = -1;
2473 }
2474 return res;
2475}
2476
2477char *ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size)
2478{
2479 struct ast_rtp_instance_stats stats = { 0, };
2480 enum ast_rtp_instance_stat stat;
2481
2482 /* Determine what statistics we will need to retrieve based on field passed in */
2485 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
2487 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
2489 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
2491 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES) {
2493 } else {
2494 return NULL;
2495 }
2496
2497 /* Attempt to actually retrieve the statistics we need to generate the quality string */
2498 if (ast_rtp_instance_get_stats(instance, &stats, stat)) {
2499 return NULL;
2500 }
2501
2502 /* Now actually fill the buffer with the good information */
2504 snprintf(buf, size, "ssrc=%u;themssrc=%u;lp=%u;rxjitter=%f;rxcount=%u;"
2505 "txjitter=%f;txcount=%u;rlp=%u;rtt=%f;rxmes=%f;txmes=%f",
2506 stats.local_ssrc, stats.remote_ssrc, stats.rxploss, stats.rxjitter,
2507 stats.rxcount, stats.txjitter, stats.txcount, stats.txploss, stats.rtt,
2508 stats.rxmes, stats.txmes);
2509 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER) {
2510 snprintf(buf, size, "minrxjitter=%010.6f;maxrxjitter=%010.6f;avgrxjitter=%010.6f;stdevrxjitter=%010.6f;mintxjitter=%010.6f;maxtxjitter=%010.6f;avgtxjitter=%010.6f;stdevtxjitter=%010.6f;",
2512 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS) {
2513 snprintf(buf, size, " minrxlost=%010.6f; maxrxlost=%010.6f; avgrxlost=%010.6f; stdevrxlost=%010.6f; mintxlost=%010.6f; maxtxlost=%010.6f; avgtxlost=%010.6f; stdevtxlost=%010.6f;",
2515 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT) {
2516 snprintf(buf, size, " minrtt=%010.6f; maxrtt=%010.6f; avgrtt=%010.6f; stdevrtt=%010.6f;", stats.minrtt, stats.maxrtt, stats.normdevrtt, stats.stdevrtt);
2517 } else if (field == AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES) {
2518 snprintf(buf, size, " minrxmes=%010.6f; maxrxmes=%010.6f; avgrxmes=%010.6f; stdevrxmes=%010.6f; mintxmes=%010.6f; maxtxmes=%010.6f; avgtxmes=%010.6f; stdevtxmes=%010.6f;",
2519 stats.local_minmes, stats.local_maxmes,
2520 stats.local_normdevmes, stats.local_stdevmes,
2521 stats.remote_minmes, stats.remote_maxmes,
2522 stats.remote_normdevmes, stats.remote_stdevmes);
2523 }
2524
2525 return buf;
2526}
2527
2529{
2530 char quality_buf[AST_MAX_USER_FIELD];
2531 char *quality;
2532 struct ast_channel *bridge;
2533
2535 if (bridge) {
2538 } else {
2539 ast_channel_lock(chan);
2540 }
2542
2544 quality_buf, sizeof(quality_buf));
2545 if (quality) {
2546 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOS", quality);
2547 if (bridge) {
2548 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSBRIDGED", quality);
2549 }
2550 }
2551
2553 AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, quality_buf, sizeof(quality_buf));
2554 if (quality) {
2555 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSJITTER", quality);
2556 if (bridge) {
2557 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSJITTERBRIDGED", quality);
2558 }
2559 }
2560
2562 AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, quality_buf, sizeof(quality_buf));
2563 if (quality) {
2564 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSLOSS", quality);
2565 if (bridge) {
2566 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSLOSSBRIDGED", quality);
2567 }
2568 }
2569
2571 AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, quality_buf, sizeof(quality_buf));
2572 if (quality) {
2573 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSRTT", quality);
2574 if (bridge) {
2575 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSRTTBRIDGED", quality);
2576 }
2577 }
2578
2580 AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES, quality_buf, sizeof(quality_buf));
2581 if (quality) {
2582 pbx_builtin_setvar_helper(chan, "RTPAUDIOQOSMES", quality);
2583 if (bridge) {
2584 pbx_builtin_setvar_helper(bridge, "RTPAUDIOQOSMESBRIDGED", quality);
2585 }
2586 }
2587
2589 ast_channel_unlock(chan);
2590 if (bridge) {
2594 }
2595}
2596
2598{
2599 int res;
2600
2601 if (instance->engine->set_read_format) {
2602 ao2_lock(instance);
2603 res = instance->engine->set_read_format(instance, format);
2604 ao2_unlock(instance);
2605 } else {
2606 res = -1;
2607 }
2608 return res;
2609}
2610
2612{
2613 int res;
2614
2615 if (instance->engine->set_read_format) {
2616 ao2_lock(instance);
2617 res = instance->engine->set_write_format(instance, format);
2618 ao2_unlock(instance);
2619 } else {
2620 res = -1;
2621 }
2622 return res;
2623}
2624
2625/* XXX Nothing calls this */
2626int ast_rtp_instance_make_compatible(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_channel *peer)
2627{
2628 struct ast_rtp_glue *glue;
2629 struct ast_rtp_instance *peer_instance = NULL;
2630 int res = -1;
2631
2632 if (!instance->engine->make_compatible) {
2633 return -1;
2634 }
2635
2636 ast_channel_lock(peer);
2637
2639 ast_channel_unlock(peer);
2640 return -1;
2641 }
2642
2643 glue->get_rtp_info(peer, &peer_instance);
2644 if (!peer_instance) {
2645 ast_log(LOG_ERROR, "Unable to get_rtp_info for peer type %s\n", glue->type);
2646 ast_channel_unlock(peer);
2647 return -1;
2648 }
2649 if (peer_instance->engine != instance->engine) {
2650 ast_log(LOG_ERROR, "Peer engine mismatch for type %s\n", glue->type);
2651 ast_channel_unlock(peer);
2652 ao2_ref(peer_instance, -1);
2653 return -1;
2654 }
2655
2656 /*
2657 * XXX Good thing nothing calls this function because we would need
2658 * deadlock avoidance to get the two instance locks.
2659 */
2660 res = instance->engine->make_compatible(chan, instance, peer, peer_instance);
2661
2662 ast_channel_unlock(peer);
2663
2664 ao2_ref(peer_instance, -1);
2665 peer_instance = NULL;
2666
2667 return res;
2668}
2669
2670void 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)
2671{
2672 if (instance->engine->available_formats) {
2673 ao2_lock(instance);
2674 instance->engine->available_formats(instance, to_endpoint, to_asterisk, result);
2675 ao2_unlock(instance);
2677 return;
2678 }
2679 }
2680
2681 ast_translate_available_formats(to_endpoint, to_asterisk, result);
2682}
2683
2685{
2686 int res;
2687
2688 if (instance->engine->activate) {
2689 ao2_lock(instance);
2690 res = instance->engine->activate(instance);
2691 ao2_unlock(instance);
2692 } else {
2693 res = 0;
2694 }
2695 return res;
2696}
2697
2699 struct ast_sockaddr *suggestion,
2700 const char *username)
2701{
2702 if (instance->engine->stun_request) {
2703 instance->engine->stun_request(instance, suggestion, username);
2704 }
2705}
2706
2708{
2709 instance->timeout = timeout;
2710}
2711
2713{
2714 instance->holdtimeout = timeout;
2715}
2716
2717void ast_rtp_instance_set_keepalive(struct ast_rtp_instance *instance, int interval)
2718{
2719 instance->keepalive = interval;
2720}
2721
2723{
2724 return instance->timeout;
2725}
2726
2728{
2729 return instance->holdtimeout;
2730}
2731
2733{
2734 return instance->keepalive;
2735}
2736
2738{
2739 return instance->engine;
2740}
2741
2743{
2744 return instance->glue;
2745}
2746
2748{
2749 if (res_srtp || res_srtp_policy) {
2750 return -1;
2751 }
2752 if (!srtp_res || !policy_res) {
2753 return -1;
2754 }
2755
2758
2759 return 0;
2760}
2761
2763{
2764 res_srtp = NULL;
2766}
2767
2769{
2770 return res_srtp && res_srtp_policy;
2771}
2772
2773int ast_rtp_instance_add_srtp_policy(struct ast_rtp_instance *instance, struct ast_srtp_policy *remote_policy, struct ast_srtp_policy *local_policy, int rtcp)
2774{
2775 int res = 0;
2776 struct ast_srtp **srtp;
2777
2778 if (!res_srtp) {
2779 return -1;
2780 }
2781
2782 ao2_lock(instance);
2783
2784 srtp = rtcp ? &instance->rtcp_srtp : &instance->srtp;
2785
2786 if (!*srtp) {
2787 res = res_srtp->create(srtp, instance, remote_policy);
2788 } else if (remote_policy) {
2789 res = res_srtp->replace(srtp, instance, remote_policy);
2790 }
2791 if (!res) {
2792 res = res_srtp->add_stream(*srtp, local_policy);
2793 }
2794
2795 ao2_unlock(instance);
2796
2797 return res;
2798}
2799
2800struct ast_srtp *ast_rtp_instance_get_srtp(struct ast_rtp_instance *instance, int rtcp)
2801{
2802 if (rtcp && instance->rtcp_srtp) {
2803 return instance->rtcp_srtp;
2804 } else {
2805 return instance->srtp;
2806 }
2807}
2808
2809int ast_rtp_instance_sendcng(struct ast_rtp_instance *instance, int level)
2810{
2811 int res;
2812
2813 if (instance->engine->sendcng) {
2814 ao2_lock(instance);
2815 res = instance->engine->sendcng(instance, level);
2816 ao2_unlock(instance);
2817 } else {
2818 res = -1;
2819 }
2820 return res;
2821}
2822
2823static void rtp_ice_wrap_set_authentication(struct ast_rtp_instance *instance, const char *ufrag, const char *password)
2824{
2825 ao2_lock(instance);
2826 instance->engine->ice->set_authentication(instance, ufrag, password);
2827 ao2_unlock(instance);
2828}
2829
2830static void rtp_ice_wrap_add_remote_candidate(struct ast_rtp_instance *instance, const struct ast_rtp_engine_ice_candidate *candidate)
2831{
2832 ao2_lock(instance);
2833 instance->engine->ice->add_remote_candidate(instance, candidate);
2834 ao2_unlock(instance);
2835}
2836
2837static void rtp_ice_wrap_start(struct ast_rtp_instance *instance)
2838{
2839 ao2_lock(instance);
2840 instance->engine->ice->start(instance);
2841 ao2_unlock(instance);
2842}
2843
2844static void rtp_ice_wrap_stop(struct ast_rtp_instance *instance)
2845{
2846 ao2_lock(instance);
2847 instance->engine->ice->stop(instance);
2848 ao2_unlock(instance);
2849}
2850
2851static const char *rtp_ice_wrap_get_ufrag(struct ast_rtp_instance *instance)
2852{
2853 const char *ufrag;
2854
2855 ao2_lock(instance);
2856 ufrag = instance->engine->ice->get_ufrag(instance);
2857 ao2_unlock(instance);
2858 return ufrag;
2859}
2860
2861static const char *rtp_ice_wrap_get_password(struct ast_rtp_instance *instance)
2862{
2863 const char *password;
2864
2865 ao2_lock(instance);
2866 password = instance->engine->ice->get_password(instance);
2867 ao2_unlock(instance);
2868 return password;
2869}
2870
2872{
2873 struct ao2_container *local_candidates;
2874
2875 ao2_lock(instance);
2876 local_candidates = instance->engine->ice->get_local_candidates(instance);
2877 ao2_unlock(instance);
2878 return local_candidates;
2879}
2880
2881static void rtp_ice_wrap_ice_lite(struct ast_rtp_instance *instance)
2882{
2883 ao2_lock(instance);
2884 instance->engine->ice->ice_lite(instance);
2885 ao2_unlock(instance);
2886}
2887
2888static void rtp_ice_wrap_set_role(struct ast_rtp_instance *instance,
2889 enum ast_rtp_ice_role role)
2890{
2891 ao2_lock(instance);
2892 instance->engine->ice->set_role(instance, role);
2893 ao2_unlock(instance);
2894}
2895
2896static void rtp_ice_wrap_turn_request(struct ast_rtp_instance *instance,
2897 enum ast_rtp_ice_component_type component, enum ast_transport transport,
2898 const char *server, unsigned int port, const char *username, const char *password)
2899{
2900 ao2_lock(instance);
2901 instance->engine->ice->turn_request(instance, component, transport, server, port,
2902 username, password);
2903 ao2_unlock(instance);
2904}
2905
2907 int num_components)
2908{
2909 ao2_lock(instance);
2910 instance->engine->ice->change_components(instance, num_components);
2911 ao2_unlock(instance);
2912}
2913
2916 .add_remote_candidate = rtp_ice_wrap_add_remote_candidate,
2917 .start = rtp_ice_wrap_start,
2918 .stop = rtp_ice_wrap_stop,
2919 .get_ufrag = rtp_ice_wrap_get_ufrag,
2920 .get_password = rtp_ice_wrap_get_password,
2921 .get_local_candidates = rtp_ice_wrap_get_local_candidates,
2922 .ice_lite = rtp_ice_wrap_ice_lite,
2923 .set_role = rtp_ice_wrap_set_role,
2924 .turn_request = rtp_ice_wrap_turn_request,
2925 .change_components = rtp_ice_wrap_change_components,
2926};
2927
2929{
2930 if (instance->engine->ice) {
2931 return &rtp_ice_wrappers;
2932 }
2933 /* ICE not available */
2934 return NULL;
2935}
2936
2937#ifdef TEST_FRAMEWORK
2938struct ast_rtp_engine_test *ast_rtp_instance_get_test(struct ast_rtp_instance *instance)
2939{
2940 return instance->engine->test;
2941}
2942#endif
2943
2945 const struct ast_rtp_dtls_cfg *dtls_cfg)
2946{
2947 int set_configuration;
2948
2949 ao2_lock(instance);
2950 set_configuration = instance->engine->dtls->set_configuration(instance, dtls_cfg);
2951 ao2_unlock(instance);
2952 return set_configuration;
2953}
2954
2955static int rtp_dtls_wrap_active(struct ast_rtp_instance *instance)
2956{
2957 int active;
2958
2959 ao2_lock(instance);
2960 active = instance->engine->dtls->active(instance);
2961 ao2_unlock(instance);
2962 return active;
2963}
2964
2965static void rtp_dtls_wrap_stop(struct ast_rtp_instance *instance)
2966{
2967 ao2_lock(instance);
2968 instance->engine->dtls->stop(instance);
2969 ao2_unlock(instance);
2970}
2971
2972static void rtp_dtls_wrap_reset(struct ast_rtp_instance *instance)
2973{
2974 ao2_lock(instance);
2975 instance->engine->dtls->reset(instance);
2976 ao2_unlock(instance);
2977}
2978
2980{
2981 enum ast_rtp_dtls_connection get_connection;
2982
2983 ao2_lock(instance);
2984 get_connection = instance->engine->dtls->get_connection(instance);
2985 ao2_unlock(instance);
2986 return get_connection;
2987}
2988
2990{
2991 enum ast_rtp_dtls_setup get_setup;
2992
2993 ao2_lock(instance);
2994 get_setup = instance->engine->dtls->get_setup(instance);
2995 ao2_unlock(instance);
2996 return get_setup;
2997}
2998
2999static void rtp_dtls_wrap_set_setup(struct ast_rtp_instance *instance,
3000 enum ast_rtp_dtls_setup setup)
3001{
3002 ao2_lock(instance);
3003 instance->engine->dtls->set_setup(instance, setup);
3004 ao2_unlock(instance);
3005}
3006
3008 enum ast_rtp_dtls_hash hash, const char *fingerprint)
3009{
3010 ao2_lock(instance);
3011 instance->engine->dtls->set_fingerprint(instance, hash, fingerprint);
3012 ao2_unlock(instance);
3013}
3014
3016{
3017 enum ast_rtp_dtls_hash get_fingerprint_hash;
3018
3019 ao2_lock(instance);
3020 get_fingerprint_hash = instance->engine->dtls->get_fingerprint_hash(instance);
3021 ao2_unlock(instance);
3022 return get_fingerprint_hash;
3023}
3024
3025static const char *rtp_dtls_wrap_get_fingerprint(struct ast_rtp_instance *instance)
3026{
3027 const char *get_fingerprint;
3028
3029 ao2_lock(instance);
3030 get_fingerprint = instance->engine->dtls->get_fingerprint(instance);
3031 ao2_unlock(instance);
3032 return get_fingerprint;
3033}
3034
3037 .active = rtp_dtls_wrap_active,
3038 .stop = rtp_dtls_wrap_stop,
3039 .reset = rtp_dtls_wrap_reset,
3040 .get_connection = rtp_dtls_wrap_get_connection,
3041 .get_setup = rtp_dtls_wrap_get_setup,
3042 .set_setup = rtp_dtls_wrap_set_setup,
3043 .set_fingerprint = rtp_dtls_wrap_set_fingerprint,
3044 .get_fingerprint_hash = rtp_dtls_wrap_get_fingerprint_hash,
3045 .get_fingerprint = rtp_dtls_wrap_get_fingerprint,
3046};
3047
3049{
3050 if (instance->engine->dtls) {
3051 return &rtp_dtls_wrappers;
3052 }
3053 /* DTLS not available */
3054 return NULL;
3055}
3056
3057int ast_rtp_dtls_cfg_parse(struct ast_rtp_dtls_cfg *dtls_cfg, const char *name, const char *value)
3058{
3059 if (!strcasecmp(name, "dtlsenable")) {
3060 dtls_cfg->enabled = ast_true(value) ? 1 : 0;
3061 } else if (!strcasecmp(name, "dtlsverify")) {
3062 if (!strcasecmp(value, "yes")) {
3064 } else if (!strcasecmp(value, "fingerprint")) {
3066 } else if (!strcasecmp(value, "certificate")) {
3068 } else if (!strcasecmp(value, "no")) {
3069 dtls_cfg->verify = AST_RTP_DTLS_VERIFY_NONE;
3070 } else {
3071 return -1;
3072 }
3073 } else if (!strcasecmp(name, "dtlsrekey")) {
3074 if (sscanf(value, "%30u", &dtls_cfg->rekey) != 1) {
3075 return -1;
3076 }
3077 } else if (!strcasecmp(name, "dtlsautogeneratecert")) {
3078 dtls_cfg->ephemeral_cert = ast_true(value) ? 1 : 0;
3079 } else if (!strcasecmp(name, "dtlscertfile")) {
3081 ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3082 return -1;
3083 }
3084 ast_free(dtls_cfg->certfile);
3085 dtls_cfg->certfile = ast_strdup(value);
3086 } else if (!strcasecmp(name, "dtlsprivatekey")) {
3088 ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3089 return -1;
3090 }
3091 ast_free(dtls_cfg->pvtfile);
3092 dtls_cfg->pvtfile = ast_strdup(value);
3093 } else if (!strcasecmp(name, "dtlscipher")) {
3094 ast_free(dtls_cfg->cipher);
3095 dtls_cfg->cipher = ast_strdup(value);
3096 } else if (!strcasecmp(name, "dtlscafile")) {
3098 ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3099 return -1;
3100 }
3101 ast_free(dtls_cfg->cafile);
3102 dtls_cfg->cafile = ast_strdup(value);
3103 } else if (!strcasecmp(name, "dtlscapath") || !strcasecmp(name, "dtlscadir")) {
3105 ast_log(LOG_ERROR, "%s file %s does not exist or is not readable\n", name, value);
3106 return -1;
3107 }
3108 ast_free(dtls_cfg->capath);
3109 dtls_cfg->capath = ast_strdup(value);
3110 } else if (!strcasecmp(name, "dtlssetup")) {
3111 if (!strcasecmp(value, "active")) {
3113 } else if (!strcasecmp(value, "passive")) {
3115 } else if (!strcasecmp(value, "actpass")) {
3117 }
3118 } else if (!strcasecmp(name, "dtlsfingerprint")) {
3119 if (!strcasecmp(value, "sha-256")) {
3120 dtls_cfg->hash = AST_RTP_DTLS_HASH_SHA256;
3121 } else if (!strcasecmp(value, "sha-1")) {
3122 dtls_cfg->hash = AST_RTP_DTLS_HASH_SHA1;
3123 }
3124 } else {
3125 return -1;
3126 }
3127
3128 return 0;
3129}
3130
3132{
3133 if (dtls_cfg->ephemeral_cert) {
3134 if (!ast_strlen_zero(dtls_cfg->certfile)) {
3135 ast_log(LOG_ERROR, "You cannot request automatically generated certificates"
3136 " (dtls_auto_generate_cert) and also specify a certificate file"
3137 " (dtls_cert_file) at the same time\n");
3138 return -1;
3139 } else if (!ast_strlen_zero(dtls_cfg->pvtfile)
3140 || !ast_strlen_zero(dtls_cfg->cafile)
3141 || !ast_strlen_zero(dtls_cfg->capath)) {
3142 ast_log(LOG_NOTICE, "dtls_pvt_file, dtls_cafile, and dtls_ca_path are"
3143 " ignored when dtls_auto_generate_cert is enabled\n");
3144 }
3145 }
3146
3147 return 0;
3148}
3149
3150void ast_rtp_dtls_cfg_copy(const struct ast_rtp_dtls_cfg *src_cfg, struct ast_rtp_dtls_cfg *dst_cfg)
3151{
3152 ast_rtp_dtls_cfg_free(dst_cfg); /* Prevent a double-call leaking memory via ast_strdup */
3153
3154 dst_cfg->enabled = src_cfg->enabled;
3155 dst_cfg->verify = src_cfg->verify;
3156 dst_cfg->rekey = src_cfg->rekey;
3157 dst_cfg->suite = src_cfg->suite;
3158 dst_cfg->hash = src_cfg->hash;
3159 dst_cfg->ephemeral_cert = src_cfg->ephemeral_cert;
3160 dst_cfg->certfile = ast_strdup(src_cfg->certfile);
3161 dst_cfg->pvtfile = ast_strdup(src_cfg->pvtfile);
3162 dst_cfg->cipher = ast_strdup(src_cfg->cipher);
3163 dst_cfg->cafile = ast_strdup(src_cfg->cafile);
3164 dst_cfg->capath = ast_strdup(src_cfg->capath);
3165 dst_cfg->default_setup = src_cfg->default_setup;
3166}
3167
3169{
3170 ast_free(dtls_cfg->certfile);
3171 dtls_cfg->certfile = NULL;
3172 ast_free(dtls_cfg->pvtfile);
3173 dtls_cfg->pvtfile = NULL;
3174 ast_free(dtls_cfg->cipher);
3175 dtls_cfg->cipher = NULL;
3176 ast_free(dtls_cfg->cafile);
3177 dtls_cfg->cafile = NULL;
3178 ast_free(dtls_cfg->capath);
3179 dtls_cfg->capath = NULL;
3180}
3181
3182/*! \internal
3183 * \brief Small helper routine that cleans up entry i in
3184 * \c ast_rtp_mime_types.
3185 */
3187{
3188 ao2_cleanup(ast_rtp_mime_types[i].payload_type.format);
3189 memset(&ast_rtp_mime_types[i], 0, sizeof(struct ast_rtp_mime_type));
3190}
3191
3192static void set_next_mime_type(struct ast_format *format, int rtp_code, const char *type, const char *subtype, unsigned int sample_rate)
3193{
3194 int x;
3195
3197
3198 x = mime_types_len;
3199 if (ARRAY_LEN(ast_rtp_mime_types) <= x) {
3201 return;
3202 }
3203
3204 /* Make sure any previous value in ast_rtp_mime_types is cleaned up */
3205 memset(&ast_rtp_mime_types[x], 0, sizeof(struct ast_rtp_mime_type));
3206 if (format) {
3209 } else {
3211 }
3213 ast_copy_string(ast_rtp_mime_types[x].subtype, subtype, sizeof(ast_rtp_mime_types[x].subtype));
3214 ast_rtp_mime_types[x].sample_rate = sample_rate;
3216
3218}
3219
3220static void add_static_payload(int payload, struct ast_format *format, int rtp_code)
3221{
3222 struct ast_rtp_payload_type *type;
3223
3224 /*
3225 * ARRAY_LEN's result is cast to an int so 'map' is not autocast to a size_t,
3226 * which if negative would cause an assertion.
3227 */
3229
3230 if (ast_option_rtpusedynamic && payload < 0) {
3231 /*
3232 * We're going to build dynamic payloads dynamically. An RTP code is
3233 * required otherwise one will be dynamically allocated per instance.
3234 */
3235 return;
3236 }
3237
3238 /*
3239 * Either the given payload is truly a static type, or Asterisk is
3240 * globally storing the dynamic payloads in the static_RTP_PT object.
3241 */
3243
3244 if (payload < 0) {
3245 /*
3246 * This is a dynamic payload that will be stored globally,
3247 * so find the next available empty slot.
3248 */
3250 if (payload < 0) {
3251 ast_log(LOG_WARNING, "No dynamic RTP payload type values available "
3252 "for %s - %d!\n", format ? ast_format_get_name(format) : "", rtp_code);
3254 return;
3255 }
3256 }
3257
3259 if (type) {
3262 }
3264}
3265
3267{
3268 char *codec_name = ast_strdupa(ast_format_get_codec_name(format));
3269
3270 codec_name = ast_str_to_upper(codec_name);
3271
3273 0,
3275 codec_name,
3277 add_static_payload(-1, format, 0);
3278
3279 return 0;
3280}
3281
3283{
3284 int x;
3285 int y = 0;
3286
3288 /* remove everything pertaining to this format id from the lists */
3289 for (x = 0; x < AST_RTP_MAX_PT; x++) {
3290 if (static_RTP_PT[x]
3292 ao2_ref(static_RTP_PT[x], -1);
3293 static_RTP_PT[x] = NULL;
3294 }
3295 }
3297
3299 /* rebuild the list skipping the items matching this id */
3300 for (x = 0; x < mime_types_len; x++) {
3301 if (ast_format_cmp(ast_rtp_mime_types[x].payload_type.format, format) == AST_FORMAT_CMP_EQUAL) {
3303 continue;
3304 }
3305 if (x != y) {
3307 }
3308 y++;
3309 }
3310 mime_types_len = y;
3312 return 0;
3313}
3314
3315/*!
3316 * \internal
3317 * \brief \ref stasis message payload for RTCP messages
3318 */
3320 struct ast_channel_snapshot *snapshot; /*< The channel snapshot, if available */
3321 struct ast_rtp_rtcp_report *report; /*< The RTCP report */
3322 struct ast_json *blob; /*< Extra JSON data to publish */
3323};
3324
3325static void rtcp_message_payload_dtor(void *obj)
3326{
3327 struct rtcp_message_payload *payload = obj;
3328
3329 ao2_cleanup(payload->report);
3330 ao2_cleanup(payload->snapshot);
3331 ast_json_unref(payload->blob);
3332}
3333
3335{
3336 struct rtcp_message_payload *payload = stasis_message_data(msg);
3337 RAII_VAR(struct ast_str *, channel_string, NULL, ast_free);
3338 RAII_VAR(struct ast_str *, packet_string, ast_str_create(512), ast_free);
3339 unsigned int ssrc = payload->report->ssrc;
3340 unsigned int type = payload->report->type;
3341 unsigned int report_count = payload->report->reception_report_count;
3342 int i;
3343
3344 if (!packet_string) {
3345 return NULL;
3346 }
3347
3348 if (payload->snapshot) {
3349 channel_string = ast_manager_build_channel_state_string(payload->snapshot);
3350 if (!channel_string) {
3351 return NULL;
3352 }
3353 }
3354
3355 if (payload->blob) {
3356 /* Optional data */
3357 struct ast_json *to = ast_json_object_get(payload->blob, "to");
3358 struct ast_json *from = ast_json_object_get(payload->blob, "from");
3359 struct ast_json *rtt = ast_json_object_get(payload->blob, "rtt");
3360 struct ast_json *mes = ast_json_object_get(payload->blob, "mes");
3361 if (to) {
3362 ast_str_append(&packet_string, 0, "To: %s\r\n", ast_json_string_get(to));
3363 }
3364 if (from) {
3365 ast_str_append(&packet_string, 0, "From: %s\r\n", ast_json_string_get(from));
3366 }
3367 if (rtt) {
3368 ast_str_append(&packet_string, 0, "RTT: %4.4f\r\n", ast_json_real_get(rtt));
3369 }
3370 if (mes) {
3371 ast_str_append(&packet_string, 0, "MES: %4.1f\r\n", ast_json_real_get(mes));
3372 }
3373 }
3374
3375 ast_str_append(&packet_string, 0, "SSRC: 0x%.8x\r\n", ssrc);
3376 ast_str_append(&packet_string, 0, "PT: %u(%s)\r\n", type, type== AST_RTP_RTCP_SR ? "SR" : "RR");
3377 ast_str_append(&packet_string, 0, "ReportCount: %u\r\n", report_count);
3378 if (type == AST_RTP_RTCP_SR) {
3379 ast_str_append(&packet_string, 0, "SentNTP: %lu.%06lu\r\n",
3380 (unsigned long)payload->report->sender_information.ntp_timestamp.tv_sec,
3381 (unsigned long)payload->report->sender_information.ntp_timestamp.tv_usec);
3382 ast_str_append(&packet_string, 0, "SentRTP: %u\r\n",
3384 ast_str_append(&packet_string, 0, "SentPackets: %u\r\n",
3386 ast_str_append(&packet_string, 0, "SentOctets: %u\r\n",
3388 }
3389
3390 for (i = 0; i < report_count; i++) {
3391 RAII_VAR(struct ast_str *, report_string, NULL, ast_free);
3392
3393 if (!payload->report->report_block[i]) {
3394 break;
3395 }
3396
3397 report_string = ast_str_create(256);
3398 if (!report_string) {
3399 return NULL;
3400 }
3401
3402 ast_str_append(&report_string, 0, "Report%dSourceSSRC: 0x%.8x\r\n",
3403 i, payload->report->report_block[i]->source_ssrc);
3404 ast_str_append(&report_string, 0, "Report%dFractionLost: %d\r\n",
3405 i, payload->report->report_block[i]->lost_count.fraction);
3406 ast_str_append(&report_string, 0, "Report%dCumulativeLost: %u\r\n",
3407 i, payload->report->report_block[i]->lost_count.packets);
3408 ast_str_append(&report_string, 0, "Report%dHighestSequence: %u\r\n",
3409 i, payload->report->report_block[i]->highest_seq_no & 0xffff);
3410 ast_str_append(&report_string, 0, "Report%dSequenceNumberCycles: %u\r\n",
3411 i, payload->report->report_block[i]->highest_seq_no >> 16);
3412 ast_str_append(&report_string, 0, "Report%dIAJitter: %u\r\n",
3413 i, payload->report->report_block[i]->ia_jitter);
3414 ast_str_append(&report_string, 0, "Report%dLSR: %u\r\n",
3415 i, payload->report->report_block[i]->lsr);
3416 ast_str_append(&report_string, 0, "Report%dDLSR: %4.4f\r\n",
3417 i, ((double)payload->report->report_block[i]->dlsr) / 65536);
3418 ast_str_append(&packet_string, 0, "%s", ast_str_buffer(report_string));
3419 }
3420
3422 stasis_message_type(msg) == ast_rtp_rtcp_received_type() ? "RTCPReceived" : "RTCPSent",
3423 "%s%s",
3424 AS_OR(channel_string, ""),
3425 ast_str_buffer(packet_string));
3426}
3427
3429 const struct stasis_message_sanitizer *sanitize)
3430{
3431 struct rtcp_message_payload *payload = stasis_message_data(msg);
3432 struct ast_json *json_rtcp_report = NULL;
3433 struct ast_json *json_rtcp_report_blocks;
3434 struct ast_json *json_rtcp_sender_info = NULL;
3435 struct ast_json *json_channel = NULL;
3436 int i;
3437
3438 json_rtcp_report_blocks = ast_json_array_create();
3439 if (!json_rtcp_report_blocks) {
3440 return NULL;
3441 }
3442
3443 for (i = 0; i < payload->report->reception_report_count && payload->report->report_block[i]; i++) {
3444 struct ast_json *json_report_block;
3445 char str_lsr[32];
3446
3447 snprintf(str_lsr, sizeof(str_lsr), "%u", payload->report->report_block[i]->lsr);
3448 json_report_block = ast_json_pack("{s: I, s: I, s: I, s: I, s: I, s: s, s: I}",
3449 "source_ssrc", (ast_json_int_t)payload->report->report_block[i]->source_ssrc,
3450 "fraction_lost", (ast_json_int_t)payload->report->report_block[i]->lost_count.fraction,
3451 "packets_lost", (ast_json_int_t)payload->report->report_block[i]->lost_count.packets,
3452 "highest_seq_no", (ast_json_int_t)payload->report->report_block[i]->highest_seq_no,
3453 "ia_jitter", (ast_json_int_t)payload->report->report_block[i]->ia_jitter,
3454 "lsr", str_lsr,
3455 "dlsr", (ast_json_int_t)payload->report->report_block[i]->dlsr);
3456 if (!json_report_block
3457 || ast_json_array_append(json_rtcp_report_blocks, json_report_block)) {
3458 ast_json_unref(json_rtcp_report_blocks);
3459 return NULL;
3460 }
3461 }
3462
3463 if (payload->report->type == AST_RTP_RTCP_SR) {
3464 char sec[32];
3465 char usec[32];
3466
3467 snprintf(sec, sizeof(sec), "%lu", (unsigned long)payload->report->sender_information.ntp_timestamp.tv_sec);
3468 snprintf(usec, sizeof(usec), "%lu", (unsigned long)payload->report->sender_information.ntp_timestamp.tv_usec);
3469 json_rtcp_sender_info = ast_json_pack("{s: s, s: s, s: I, s: I, s: I}",
3470 "ntp_timestamp_sec", sec,
3471 "ntp_timestamp_usec", usec,
3472 "rtp_timestamp", (ast_json_int_t)payload->report->sender_information.rtp_timestamp,
3475 if (!json_rtcp_sender_info) {
3476 ast_json_unref(json_rtcp_report_blocks);
3477 return NULL;
3478 }
3479 }
3480
3481 json_rtcp_report = ast_json_pack("{s: I, s: I, s: i, s: o, s: o}",
3482 "ssrc", (ast_json_int_t)payload->report->ssrc,
3483 "type", (ast_json_int_t)payload->report->type,
3484 "report_count", payload->report->reception_report_count,
3485 "sender_information", json_rtcp_sender_info ?: ast_json_null(),
3486 "report_blocks", json_rtcp_report_blocks);
3487 if (!json_rtcp_report) {
3488 return NULL;
3489 }
3490
3491 if (payload->snapshot) {
3492 json_channel = ast_channel_snapshot_to_json(payload->snapshot, sanitize);
3493 if (!json_channel) {
3494 ast_json_unref(json_rtcp_report);
3495 return NULL;
3496 }
3497 }
3498
3499 return ast_json_pack("{s: s, s: o?, s: o, s: O?}",
3500 "type", stasis_message_type(msg) == ast_rtp_rtcp_received_type() ? "RTCPReceived" : "RTCPSent",
3501 "channel", json_channel,
3502 "rtcp_report", json_rtcp_report,
3503 "blob", payload->blob);
3504}
3505
3506static void rtp_rtcp_report_dtor(void *obj)
3507{
3508 int i;
3509 struct ast_rtp_rtcp_report *rtcp_report = obj;
3510
3511 for (i = 0; i < rtcp_report->reception_report_count; i++) {
3512 ast_free(rtcp_report->report_block[i]);
3513 }
3514}
3515
3516struct ast_rtp_rtcp_report *ast_rtp_rtcp_report_alloc(unsigned int report_blocks)
3517{
3518 struct ast_rtp_rtcp_report *rtcp_report;
3519
3520 /* Size of object is sizeof the report + the number of report_blocks * sizeof pointer */
3521 rtcp_report = ao2_alloc((sizeof(*rtcp_report) + report_blocks * sizeof(struct ast_rtp_rtcp_report_block *)),
3523
3524 return rtcp_report;
3525}
3526
3528 struct stasis_message_type *message_type,
3529 struct ast_rtp_rtcp_report *report,
3530 struct ast_json *blob)
3531{
3532 RAII_VAR(struct rtcp_message_payload *, payload, NULL, ao2_cleanup);
3534
3535 if (!message_type) {
3536 return;
3537 }
3538
3539 payload = ao2_alloc(sizeof(*payload), rtcp_message_payload_dtor);
3540 if (!payload || !report) {
3541 return;
3542 }
3543
3544 if (!ast_strlen_zero(rtp->channel_uniqueid)) {
3545 payload->snapshot = ast_channel_snapshot_get_latest(rtp->channel_uniqueid);
3546 }
3547 if (blob) {
3548 payload->blob = blob;
3549 ast_json_ref(blob);
3550 }
3551 ao2_ref(report, +1);
3552 payload->report = report;
3553
3554 message = stasis_message_create(message_type, payload);
3555 if (!message) {
3556 return;
3557 }
3558
3560}
3561
3562/*!
3563 * @{ \brief Define RTCP/RTP message types.
3564 */
3567 .to_json = rtcp_report_to_json,);
3570 .to_json = rtcp_report_to_json,);
3571/*! @} */
3572
3574{
3575 return rtp_topic;
3576}
3577
3578static uintmax_t debug_category_rtp_id;
3579
3581{
3582 return debug_category_rtp_id;
3583}
3584
3586
3588{
3590}
3591
3592static uintmax_t debug_category_rtcp_id;
3593
3595{
3597}
3598
3600
3602{
3604}
3605
3606static uintmax_t debug_category_dtls_id;
3607
3609{
3611}
3612
3614
3616{
3618}
3619
3620static uintmax_t debug_category_ice_id;
3621
3623{
3624 return debug_category_ice_id;
3625}
3626
3627/*!
3628 * \internal
3629 * \brief Shutdown the RTP engine
3630 * This function will not get called if any module fails to unload.
3631 */
3632static void rtp_engine_shutdown(void)
3633{
3634 int x;
3635
3637 rtp_topic = NULL;
3640
3642 for (x = 0; x < AST_RTP_MAX_PT; x++) {
3644 static_RTP_PT[x] = NULL;
3645 }
3647
3649 for (x = 0; x < mime_types_len; x++) {
3650 if (ast_rtp_mime_types[x].payload_type.format) {
3652 }
3653 }
3654 mime_types_len = 0;
3656}
3657
3658/*!
3659 * \internal
3660 * \brief Unregister the debug categories
3661 * This function will always get called even if any module fails to unload.
3662 */
3663static void rtp_engine_atexit(void)
3664{
3666
3669
3672
3675}
3676
3678{
3681
3682 rtp_topic = stasis_topic_create("rtp:all");
3683 if (!rtp_topic) {
3684 return -1;
3685 }
3689
3690 /* Define all the RTP mime types available */
3691 set_next_mime_type(ast_format_g723, 0, "audio", "G723", 8000);
3692 set_next_mime_type(ast_format_gsm, 0, "audio", "GSM", 8000);
3693 set_next_mime_type(ast_format_ulaw, 0, "audio", "PCMU", 8000);
3694 set_next_mime_type(ast_format_ulaw, 0, "audio", "G711U", 8000);
3695 set_next_mime_type(ast_format_alaw, 0, "audio", "PCMA", 8000);
3696 set_next_mime_type(ast_format_alaw, 0, "audio", "G711A", 8000);
3697 set_next_mime_type(ast_format_g726, 0, "audio", "G726-32", 8000);
3698 set_next_mime_type(ast_format_adpcm, 0, "audio", "DVI4", 8000);
3699 set_next_mime_type(ast_format_slin, 0, "audio", "L16", 8000);
3700 set_next_mime_type(ast_format_slin16, 0, "audio", "L16", 16000);
3701 set_next_mime_type(ast_format_slin16, 0, "audio", "L16-256", 16000);
3702 set_next_mime_type(ast_format_slin12, 0, "audio", "L16", 12000);
3703 set_next_mime_type(ast_format_slin24, 0, "audio", "L16", 24000);
3704 set_next_mime_type(ast_format_slin32, 0, "audio", "L16", 32000);
3705 set_next_mime_type(ast_format_slin44, 0, "audio", "L16", 44100);
3706 set_next_mime_type(ast_format_slin48, 0, "audio", "L16", 48000);
3707 set_next_mime_type(ast_format_slin96, 0, "audio", "L16", 96000);
3708 set_next_mime_type(ast_format_slin192, 0, "audio", "L16", 192000);
3709 set_next_mime_type(ast_format_lpc10, 0, "audio", "LPC", 8000);
3710 set_next_mime_type(ast_format_g729, 0, "audio", "G729", 8000);
3711 set_next_mime_type(ast_format_g729, 0, "audio", "G729A", 8000);
3712 set_next_mime_type(ast_format_g729, 0, "audio", "G.729", 8000);
3713 set_next_mime_type(ast_format_speex, 0, "audio", "speex", 8000);
3714 set_next_mime_type(ast_format_speex16, 0, "audio", "speex", 16000);
3715 set_next_mime_type(ast_format_speex32, 0, "audio", "speex", 32000);
3716 set_next_mime_type(ast_format_ilbc, 0, "audio", "iLBC", 8000);
3717 /* this is the sample rate listed in the RTP profile for the G.722 codec, *NOT* the actual sample rate of the media stream */
3718 set_next_mime_type(ast_format_g722, 0, "audio", "G722", 8000);
3719 set_next_mime_type(ast_format_g726_aal2, 0, "audio", "AAL2-G726-32", 8000);
3720 set_next_mime_type(NULL, AST_RTP_DTMF, "audio", "telephone-event", 8000);
3721 set_next_mime_type(NULL, AST_RTP_CISCO_DTMF, "audio", "cisco-telephone-event", 8000);
3722 set_next_mime_type(NULL, AST_RTP_CN, "audio", "CN", 8000);
3723 set_next_mime_type(ast_format_jpeg, 0, "video", "JPEG", 90000);
3724 set_next_mime_type(ast_format_png, 0, "video", "PNG", 90000);
3725 set_next_mime_type(ast_format_h261, 0, "video", "H261", 90000);
3726 set_next_mime_type(ast_format_h263, 0, "video", "H263", 90000);
3727 set_next_mime_type(ast_format_h263p, 0, "video", "h263-1998", 90000);
3728 set_next_mime_type(ast_format_h264, 0, "video", "H264", 90000);
3729 set_next_mime_type(ast_format_h265, 0, "video", "H265", 90000);
3730 set_next_mime_type(ast_format_mp4, 0, "video", "MP4V-ES", 90000);
3731 set_next_mime_type(ast_format_t140_red, 0, "text", "RED", 1000);
3732 set_next_mime_type(ast_format_t140, 0, "text", "T140", 1000);
3733 set_next_mime_type(ast_format_siren7, 0, "audio", "G7221", 16000);
3734 set_next_mime_type(ast_format_siren14, 0, "audio", "G7221", 32000);
3735 set_next_mime_type(ast_format_g719, 0, "audio", "G719", 48000);
3736 /* Opus, VP8, and VP9 */
3737 set_next_mime_type(ast_format_opus, 0, "audio", "opus", 48000);
3738 set_next_mime_type(ast_format_vp8, 0, "video", "VP8", 90000);
3739 set_next_mime_type(ast_format_vp9, 0, "video", "VP9", 90000);
3740
3741 /* Define the static rtp payload mappings */
3743 #ifdef USE_DEPRECATED_G726
3744 add_static_payload(2, ast_format_g726, 0);/* Technically this is G.721, but if Cisco can do it, so can we... */
3745 #endif
3748 add_static_payload(5, ast_format_adpcm, 0);/* 8 kHz */
3749 add_static_payload(6, ast_format_adpcm, 0); /* 16 kHz */
3753 add_static_payload(10, ast_format_slin, 0); /* 2 channels */
3754 add_static_payload(11, ast_format_slin, 0); /* 1 channel */
3756 add_static_payload(16, ast_format_adpcm, 0); /* 11.025 kHz */
3757 add_static_payload(17, ast_format_adpcm, 0); /* 22.050 kHz */
3759 add_static_payload(19, NULL, AST_RTP_CN); /* Also used for CN */
3763
3764 /*
3765 * Dynamic payload types - Even when dynamically assigning them we'll fall
3766 * back to using the statically declared values as the default number.
3767 */
3770
3777 add_static_payload(105, ast_format_t140_red, 0); /* Real time text chat (with redundancy encoding) */
3778 add_static_payload(106, ast_format_t140, 0); /* Real time text chat */
3782
3786
3790 add_static_payload(118, ast_format_slin16, 0); /* 16 Khz signed linear */
3792
3793 add_static_payload(121, NULL, AST_RTP_CISCO_DTMF); /* Must be type 121 */
3800 /* payload types above 127 are not valid */
3801
3809
3810 /*
3811 * Normnally a core module should call ast_register_cleanup,
3812 * which doesn't run if any module fails to unload. This
3813 * prevents resources being pulled out from under a running
3814 * module and possibly causing a segfault. In this case however,
3815 * the only thing we're cleaning up are the registrations of the
3816 * debug categories.
3817 */
3819
3820 return 0;
3821}
3822
3824{
3825 return rtp->last_tx;
3826}
3827
3829{
3830 rtp->last_tx = time;
3831}
3832
3834{
3835 return rtp->last_rx;
3836}
3837
3839{
3840 rtp->last_rx = time;
3841}
3842
3844{
3845 unsigned int ssrc = 0;
3846
3847 ao2_lock(rtp);
3848 if (rtp->engine->ssrc_get) {
3849 ssrc = rtp->engine->ssrc_get(rtp);
3850 }
3851 ao2_unlock(rtp);
3852
3853 return ssrc;
3854}
3855
3857{
3858 const char *cname = "";
3859
3860 ao2_lock(rtp);
3861 if (rtp->engine->cname_get) {
3862 cname = rtp->engine->cname_get(rtp);
3863 }
3864 ao2_unlock(rtp);
3865
3866 return cname;
3867}
3868
3870{
3871 int res = -1;
3872
3873 if (parent && (child->engine != parent->engine)) {
3874 return -1;
3875 }
3876
3877 ao2_lock(child);
3878 if (child->engine->bundle) {
3879 res = child->engine->bundle(child, parent);
3880 }
3881 ao2_unlock(child);
3882
3883 return res;
3884}
3885
3886void ast_rtp_instance_set_remote_ssrc(struct ast_rtp_instance *rtp, unsigned int ssrc)
3887{
3888 ao2_lock(rtp);
3889 if (rtp->engine->set_remote_ssrc) {
3890 rtp->engine->set_remote_ssrc(rtp, ssrc);
3891 }
3892 ao2_unlock(rtp);
3893}
3894
3895void ast_rtp_instance_set_stream_num(struct ast_rtp_instance *rtp, int stream_num)
3896{
3897 ao2_lock(rtp);
3898 if (rtp->engine->set_stream_num) {
3899 rtp->engine->set_stream_num(rtp, stream_num);
3900 }
3901 ao2_unlock(rtp);
3902}
3903
3904#ifdef TEST_FRAMEWORK
3905size_t ast_rtp_instance_get_recv_buffer_max(struct ast_rtp_instance *instance)
3906{
3907 size_t res;
3908 struct ast_rtp_engine_test *test = ast_rtp_instance_get_test(instance);
3909
3910 if (!test) {
3911 ast_log(LOG_ERROR, "There is no test engine set up!\n");
3912 return 0;
3913 }
3914
3915 ao2_lock(instance);
3916 res = test->recv_buffer_max(instance);
3917 ao2_unlock(instance);
3918
3919 return res;
3920}
3921
3922size_t ast_rtp_instance_get_recv_buffer_count(struct ast_rtp_instance *instance)
3923{
3924 size_t res;
3925 struct ast_rtp_engine_test *test = ast_rtp_instance_get_test(instance);
3926
3927 if (!test) {
3928 ast_log(LOG_ERROR, "There is no test engine set up!\n");
3929 return 0;
3930 }
3931
3932 ao2_lock(instance);
3933 res = test->recv_buffer_count(instance);
3934 ao2_unlock(instance);
3935
3936 return res;
3937}
3938
3939size_t ast_rtp_instance_get_send_buffer_count(struct ast_rtp_instance *instance)
3940{
3941 size_t res;
3942 struct ast_rtp_engine_test *test = ast_rtp_instance_get_test(instance);
3943
3944 if (!test) {
3945 ast_log(LOG_ERROR, "There is no test engine set up!\n");
3946 return 0;
3947 }
3948
3949 ao2_lock(instance);
3950 res = test->send_buffer_count(instance);
3951 ao2_unlock(instance);
3952
3953 return res;
3954}
3955
3956void ast_rtp_instance_set_schedid(struct ast_rtp_instance *instance, int id)
3957{
3958 struct ast_rtp_engine_test *test = ast_rtp_instance_get_test(instance);
3959
3960 if (!test) {
3961 ast_log(LOG_ERROR, "There is no test engine set up!\n");
3962 return;
3963 }
3964
3965 ao2_lock(instance);
3966 test->set_schedid(instance, id);
3967 ao2_unlock(instance);
3968}
3969
3970void ast_rtp_instance_drop_packets(struct ast_rtp_instance *instance, int num)
3971{
3972 struct ast_rtp_engine_test *test = ast_rtp_instance_get_test(instance);
3973
3974 if (!test) {
3975 ast_log(LOG_ERROR, "There is no test engine set up!\n");
3976 return;
3977 }
3978
3979 test->packets_to_drop = num;
3980}
3981
3982void ast_rtp_instance_queue_report(struct ast_rtp_instance *instance)
3983{
3984 struct ast_rtp_engine_test *test = ast_rtp_instance_get_test(instance);
3985
3986 if (!test) {
3987 ast_log(LOG_ERROR, "There is no test engine set up!\n");
3988 return;
3989 }
3990
3991 test->send_report = 1;
3992}
3993
3994int ast_rtp_instance_get_sdes_received(struct ast_rtp_instance *instance)
3995{
3996 struct ast_rtp_engine_test *test = ast_rtp_instance_get_test(instance);
3997
3998 if (!test) {
3999 ast_log(LOG_ERROR, "There is no test engine set up!\n");
4000 return 0;
4001 }
4002
4003 return test->sdes_received;
4004}
4005
4006void ast_rtp_instance_reset_test_engine(struct ast_rtp_instance *instance)
4007{
4008 struct ast_rtp_engine_test *test = ast_rtp_instance_get_test(instance);
4009
4010 if (!test) {
4011 ast_log(LOG_ERROR, "There is no test engine set up!\n");
4012 return;
4013 }
4014
4015 test->packets_to_drop = 0;
4016 test->send_report = 0;
4017 test->sdes_received = 0;
4018}
4019#endif
4020
4022{
4023 struct ast_json *j_res;
4024 int ret;
4025
4026 j_res = ast_json_object_create();
4027 if (!j_res) {
4028 return NULL;
4029 }
4030
4031 /* set mandatory items */
4032 ret = ast_json_object_set(j_res, "txcount", ast_json_integer_create(stats->txcount));
4033 ret |= ast_json_object_set(j_res, "rxcount", ast_json_integer_create(stats->rxcount));
4034
4035 ret |= ast_json_object_set(j_res, "txploss", ast_json_integer_create(stats->txploss));
4036 ret |= ast_json_object_set(j_res, "rxploss", ast_json_integer_create(stats->rxploss));
4037
4038 ret |= ast_json_object_set(j_res, "local_ssrc", ast_json_integer_create(stats->local_ssrc));
4039 ret |= ast_json_object_set(j_res, "remote_ssrc", ast_json_integer_create(stats->remote_ssrc));
4040
4041 ret |= ast_json_object_set(j_res, "txoctetcount", ast_json_integer_create(stats->txoctetcount));
4042 ret |= ast_json_object_set(j_res, "rxoctetcount", ast_json_integer_create(stats->rxoctetcount));
4043
4044 ret |= ast_json_object_set(j_res, "channel_uniqueid", ast_json_string_create(stats->channel_uniqueid));
4045 if (ret) {
4046 ast_log(LOG_WARNING, "Could not create rtp statistics info. channel: %s\n", stats->channel_uniqueid);
4047 ast_json_unref(j_res);
4048 return NULL;
4049 }
4050
4051 /* set other items */
4052 SET_AST_JSON_OBJ(j_res, "txjitter", ast_json_real_create(stats->txjitter));
4053 SET_AST_JSON_OBJ(j_res, "rxjitter", ast_json_real_create(stats->rxjitter));
4054
4055 SET_AST_JSON_OBJ(j_res, "remote_maxjitter", ast_json_real_create(stats->remote_maxjitter));
4056 SET_AST_JSON_OBJ(j_res, "remote_minjitter", ast_json_real_create(stats->remote_minjitter));
4057 SET_AST_JSON_OBJ(j_res, "remote_normdevjitter", ast_json_real_create(stats->remote_normdevjitter));
4058 SET_AST_JSON_OBJ(j_res, "remote_stdevjitter", ast_json_real_create(stats->remote_stdevjitter));
4059
4060 SET_AST_JSON_OBJ(j_res, "local_maxjitter", ast_json_real_create(stats->local_maxjitter));
4061 SET_AST_JSON_OBJ(j_res, "local_minjitter", ast_json_real_create(stats->local_minjitter));
4062 SET_AST_JSON_OBJ(j_res, "local_normdevjitter", ast_json_real_create(stats->local_normdevjitter));
4063 SET_AST_JSON_OBJ(j_res, "local_stdevjitter", ast_json_real_create(stats->local_stdevjitter));
4064
4065 SET_AST_JSON_OBJ(j_res, "remote_maxrxploss", ast_json_real_create(stats->remote_maxrxploss));
4066 SET_AST_JSON_OBJ(j_res, "remote_minrxploss", ast_json_real_create(stats->remote_minrxploss));
4067 SET_AST_JSON_OBJ(j_res, "remote_normdevrxploss", ast_json_real_create(stats->remote_normdevrxploss));
4068 SET_AST_JSON_OBJ(j_res, "remote_stdevrxploss", ast_json_real_create(stats->remote_stdevrxploss));
4069
4070 SET_AST_JSON_OBJ(j_res, "local_maxrxploss", ast_json_real_create(stats->local_maxrxploss));
4071 SET_AST_JSON_OBJ(j_res, "local_minrxploss", ast_json_real_create(stats->local_minrxploss));
4072 SET_AST_JSON_OBJ(j_res, "local_normdevrxploss", ast_json_real_create(stats->local_normdevrxploss));
4073 SET_AST_JSON_OBJ(j_res, "local_stdevrxploss", ast_json_real_create(stats->local_stdevrxploss));
4074
4075 SET_AST_JSON_OBJ(j_res, "rtt", ast_json_real_create(stats->rtt));
4076 SET_AST_JSON_OBJ(j_res, "maxrtt", ast_json_real_create(stats->maxrtt));
4077 SET_AST_JSON_OBJ(j_res, "minrtt", ast_json_real_create(stats->minrtt));
4078 SET_AST_JSON_OBJ(j_res, "normdevrtt", ast_json_real_create(stats->normdevrtt));
4079 SET_AST_JSON_OBJ(j_res, "stdevrtt", ast_json_real_create(stats->stdevrtt));
4080
4081 SET_AST_JSON_OBJ(j_res, "txmes", ast_json_integer_create(stats->txmes));
4082 SET_AST_JSON_OBJ(j_res, "rxmes", ast_json_integer_create(stats->rxmes));
4083
4084 SET_AST_JSON_OBJ(j_res, "remote_maxmes", ast_json_real_create(stats->remote_maxmes));
4085 SET_AST_JSON_OBJ(j_res, "remote_minmes", ast_json_real_create(stats->remote_minmes));
4086 SET_AST_JSON_OBJ(j_res, "remote_normdevmes", ast_json_real_create(stats->remote_normdevmes));
4087 SET_AST_JSON_OBJ(j_res, "remote_stdevmes", ast_json_real_create(stats->remote_stdevmes));
4088
4089 SET_AST_JSON_OBJ(j_res, "local_maxmes", ast_json_real_create(stats->local_maxmes));
4090 SET_AST_JSON_OBJ(j_res, "local_minmes", ast_json_real_create(stats->local_minmes));
4091 SET_AST_JSON_OBJ(j_res, "local_normdevmes", ast_json_real_create(stats->local_normdevmes));
4092 SET_AST_JSON_OBJ(j_res, "local_stdevmes", ast_json_real_create(stats->local_stdevmes));
4093
4094 return j_res;
4095}
4096
4098{
4099 struct ast_rtp_instance_stats stats = {0,};
4100
4102 return NULL;
4103 }
4104
4105 return ast_rtp_convert_stats_json(&stats);
4106}
4107
4108int ast_rtp_get_rate(const struct ast_format *format)
4109{
4110 /* For those wondering: due to a fluke in RFC publication, G.722 is advertised
4111 * as having a sample rate of 8kHz, while implementations must know that its
4112 * real rate is 16kHz. Seriously.
4113 */
4114 return (ast_format_cmp(format, ast_format_g722) == AST_FORMAT_CMP_EQUAL) ? 8000 : (int)ast_format_get_sample_rate(format);
4115}
Prototypes for public functions only of internal interest,.
char digit
enum queue_result id
Definition: app_queue.c:1638
Asterisk main include file. File version handling, generic pbx functions.
int ast_register_cleanup(void(*func)(void))
Register a function to be executed before Asterisk gracefully exits.
Definition: clicompat.c:19
int ast_register_atexit(void(*func)(void))
Register a function to be executed before Asterisk exits.
Definition: clicompat.c:13
#define ast_free(a)
Definition: astmm.h:180
#define ast_strdup(str)
A wrapper for strdup()
Definition: astmm.h:241
#define ast_strdupa(s)
duplicate a string in memory from the stack
Definition: astmm.h:298
#define ast_log
Definition: astobj2.c:42
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717
#define ao2_ref(o, delta)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:459
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:404
#define ao2_t_cleanup(obj, tag)
Definition: astobj2.h:1935
#define ao2_bump(obj)
Bump refcount on an AO2 object by one, returning the object.
Definition: astobj2.h:480
#define ao2_alloc(data_size, destructor_fn)
Definition: astobj2.h:409
static const char desc[]
Definition: cdr_radius.c:84
static PGresult * result
Definition: cel_pgsql.c:84
unsigned int tos
Definition: chan_iax2.c:355
unsigned int cos
Definition: chan_iax2.c:356
static const char type[]
Definition: chan_ooh323.c:109
General Asterisk PBX channel definitions.
const char * ast_channel_name(const struct ast_channel *chan)
struct ast_channel * ast_channel_bridge_peer(struct ast_channel *chan)
Get the channel's bridge peer only if the bridge is two-party.
Definition: channel.c:10564
#define ast_channel_lock(chan)
Definition: channel.h:2922
#define ast_channel_lock_both(chan1, chan2)
Lock two channels.
Definition: channel.h:2929
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2958
#define AST_MAX_UNIQUEID
Definition: channel.h:168
const struct ast_channel_tech * ast_channel_tech(const struct ast_channel *chan)
#define AST_MAX_USER_FIELD
Definition: channel.h:174
#define ast_channel_unlock(chan)
Definition: channel.h:2923
static struct ao2_container * codecs
Registered codecs.
Definition: codec.c:48
Codec API.
ast_media_type
Types of media.
Definition: codec.h:30
@ AST_MEDIA_TYPE_UNKNOWN
Definition: codec.h:31
const char * ast_codec_media_type2str(enum ast_media_type type)
Conversion function to take a media type and turn it into a string.
Definition: codec.c:348
static int quality
Definition: codec_speex.c:62
char * end
Definition: eagi_proxy.c:73
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
char * address
Definition: f2c.h:59
Media Format API.
enum ast_media_type ast_format_get_type(const struct ast_format *format)
Get the media type of a format.
Definition: format.c:354
unsigned int ast_format_get_codec_id(const struct ast_format *format)
Get the codec identifier associated with a format.
Definition: format.c:329
unsigned int ast_format_get_sample_rate(const struct ast_format *format)
Get the sample rate of a media format.
Definition: format.c:379
enum ast_format_cmp_res ast_format_cmp(const struct ast_format *format1, const struct ast_format *format2)
Compare two formats.
Definition: format.c:201
@ AST_FORMAT_CMP_EQUAL
Definition: format.h:36
@ AST_FORMAT_CMP_NOT_EQUAL
Definition: format.h:38
const char * ast_format_get_name(const struct ast_format *format)
Get the name associated with a format.
Definition: format.c:334
const char * ast_format_get_codec_name(const struct ast_format *format)
Get the codec name associated with a format.
Definition: format.c:339
struct ast_format * ast_format_parse_sdp_fmtp(const struct ast_format *format, const char *attributes)
This function is used to have a media format aware module parse and interpret SDP attribute informati...
Definition: format.c:286
Media Format Cache API.
struct ast_format * ast_format_speex16
Built-in cached speex at 16kHz format.
Definition: format_cache.c:136
struct ast_format * ast_format_h264
Built-in cached h264 format.
Definition: format_cache.c:176
struct ast_format * ast_format_slin44
Built-in cached signed linear 44kHz format.
Definition: format_cache.c:66
struct ast_format * ast_format_adpcm
Built-in cached adpcm format.
Definition: format_cache.c:101
struct ast_format * ast_format_slin24
Built-in cached signed linear 24kHz format.
Definition: format_cache.c:56
struct ast_format * ast_format_opus
Built-in cached opus format.
Definition: format_cache.c:221
struct ast_format * ast_format_h265
Built-in cached h265 format.
Definition: format_cache.c:181
struct ast_format * ast_format_gsm
Built-in cached gsm format.
Definition: format_cache.c:96
struct ast_format * ast_format_slin32
Built-in cached signed linear 32kHz format.
Definition: format_cache.c:61
struct ast_format * ast_format_siren14
Built-in cached siren14 format.
Definition: format_cache.c:211
struct ast_format * ast_format_speex
Built-in cached speex format.
Definition: format_cache.c:131
struct ast_format * ast_format_h263
Built-in cached h263 format.
Definition: format_cache.c:166
struct ast_format * ast_format_mp4
Built-in cached mp4 format.
Definition: format_cache.c:186
struct ast_format * ast_format_slin192
Built-in cached signed linear 192kHz format.
Definition: format_cache.c:81
struct ast_format * ast_format_ilbc
Built-in cached ilbc format.
Definition: format_cache.c:121
struct ast_format * ast_format_g726
Built-in cached g726 format.
Definition: format_cache.c:111
struct ast_format * ast_format_ulaw
Built-in cached ulaw format.
Definition: format_cache.c:86
struct ast_format * ast_format_lpc10
Built-in cached ilbc format.
Definition: format_cache.c:126
struct ast_format * ast_format_slin16
Built-in cached signed linear 16kHz format.
Definition: format_cache.c:51
struct ast_format * ast_format_slin96
Built-in cached signed linear 96kHz format.
Definition: format_cache.c:76
struct ast_format * ast_format_slin48
Built-in cached signed linear 48kHz format.
Definition: format_cache.c:71
struct ast_format * ast_format_g723
Built-in cached g723.1 format.
Definition: format_cache.c:146
struct ast_format * ast_format_slin
Built-in cached signed linear 8kHz format.
Definition: format_cache.c:41
struct ast_format * ast_format_siren7
Built-in cached siren7 format.
Definition: format_cache.c:216
struct ast_format * ast_format_alaw
Built-in cached alaw format.
Definition: format_cache.c:91
struct ast_format * ast_format_speex32
Built-in cached speex at 32kHz format.
Definition: format_cache.c:141
struct ast_format * ast_format_h261
Built-in cached h261 format.
Definition: format_cache.c:161
struct ast_format * ast_format_vp9
Built-in cached vp9 format.
Definition: format_cache.c:196
struct ast_format * ast_format_t140_red
Built-in cached t140 red format.
Definition: format_cache.c:236
struct ast_format * ast_format_slin12
Built-in cached signed linear 12kHz format.
Definition: format_cache.c:46
struct ast_format * ast_format_h263p
Built-in cached h263 plus format.
Definition: format_cache.c:171
struct ast_format * ast_format_png
Built-in cached png format.
Definition: format_cache.c:206
struct ast_format * ast_format_g722
Built-in cached g722 format.
Definition: format_cache.c:106
struct ast_format * ast_format_g726_aal2
Built-in cached g726 aal2 format.
Definition: format_cache.c:116
struct ast_format * ast_format_t140
Built-in cached t140 format.
Definition: format_cache.c:231
struct ast_format * ast_format_g729
Built-in cached g729 format.
Definition: format_cache.c:151
struct ast_format * ast_format_jpeg
Built-in cached jpeg format.
Definition: format_cache.c:201
struct ast_format * ast_format_vp8
Built-in cached vp8 format.
Definition: format_cache.c:191
struct ast_format * ast_format_g719
Built-in cached g719 format.
Definition: format_cache.c:156
Format Capabilities API.
struct ast_format * ast_format_cap_get_format(const struct ast_format_cap *cap, int position)
Get the format at a specific index.
Definition: format_cap.c:400
void ast_format_cap_remove_by_type(struct ast_format_cap *cap, enum ast_media_type type)
Remove all formats matching a specific format type.
Definition: format_cap.c:523
@ AST_FORMAT_CAP_FLAG_DEFAULT
Definition: format_cap.h:38
int ast_format_cap_iscompatible(const struct ast_format_cap *cap1, const struct ast_format_cap *cap2)
Determine if any joint capabilities exist between two capabilities structures.
Definition: format_cap.c:653
#define ast_format_cap_append(cap, format, framing)
Add format capability to capabilities structure.
Definition: format_cap.h:99
void ast_format_cap_set_framing(struct ast_format_cap *cap, unsigned int framing)
Set the global framing.
Definition: format_cap.c:136
#define ast_format_cap_alloc(flags)
Allocate a new ast_format_cap structure.
Definition: format_cap.h:49
size_t ast_format_cap_count(const struct ast_format_cap *cap)
Get the number of formats present within the capabilities structure.
Definition: format_cap.c:395
static const char name[]
Definition: format_mp3.c:68
direction
struct stasis_message_type * ast_rtp_rtcp_sent_type(void)
Message type for an RTCP message sent from this Asterisk instance.
struct ast_channel_snapshot * ast_channel_snapshot_get_latest(const char *uniqueid)
Obtain the latest ast_channel_snapshot from the Stasis Message Bus API cache. This is an ao2 object,...
void ast_channel_stage_snapshot_done(struct ast_channel *chan)
Clear flag to indicate channel snapshot is being staged, and publish snapshot.
struct stasis_message_type * ast_rtp_rtcp_received_type(void)
Message type for an RTCP message received from some external source.
void ast_channel_stage_snapshot(struct ast_channel *chan)
Set flag to indicate channel snapshot is being staged.
int ast_option_rtpusedynamic
Definition: options.c:88
unsigned int ast_option_rtpptdynamic
Definition: options.c:89
Support for logging to various files, console and syslog Configuration in file logger....
#define ast_debug(level,...)
Log a DEBUG message.
#define LOG_ERROR
#define ast_verb(level,...)
#define LOG_NOTICE
#define LOG_WARNING
Asterisk JSON abstraction layer.
struct ast_json * ast_json_string_create(const char *value)
Construct a JSON string from value.
Definition: json.c:278
struct ast_json * ast_json_null(void)
Get the JSON null value.
Definition: json.c:248
void ast_json_unref(struct ast_json *value)
Decrease refcount on value. If refcount reaches zero, value is freed.
Definition: json.c:73
int ast_json_array_append(struct ast_json *array, struct ast_json *value)
Append to an array.
Definition: json.c:378
struct ast_json * ast_json_object_create(void)
Create a new JSON object.
Definition: json.c:399
struct ast_json * ast_json_pack(char const *format,...)
Helper for creating complex JSON values.
Definition: json.c:612
struct ast_json * ast_json_integer_create(intmax_t value)
Create a JSON integer.
Definition: json.c:327
struct ast_json * ast_json_array_create(void)
Create a empty JSON array.
Definition: json.c:362
struct ast_json * ast_json_ref(struct ast_json *value)
Increase refcount on value.
Definition: json.c:67
int ast_json_object_set(struct ast_json *object, const char *key, struct ast_json *value)
Set a field in a JSON object.
Definition: json.c:414
const char * ast_json_string_get(const struct ast_json *string)
Get the value of a JSON string.
Definition: json.c:283
struct ast_json * ast_json_object_get(struct ast_json *object, const char *key)
Get a field from a JSON object.
Definition: json.c:407
struct ast_json * ast_json_real_create(double value)
Create a JSON real number.
Definition: json.c:342
AST_JSON_INT_T ast_json_int_t
Primarily used to cast when packing to an "I" type.
Definition: json.h:87
double ast_json_real_get(const struct ast_json *real)
Get the value from a JSON real number.
Definition: json.c:347
A set of macros to manage forward-linked lists.
#define AST_RWLIST_RDLOCK(head)
Read locks a list.
Definition: linkedlists.h:78
#define AST_RWLIST_WRLOCK(head)
Write locks a list.
Definition: linkedlists.h:52
#define AST_RWLIST_UNLOCK(head)
Attempts to unlock a read/write based list.
Definition: linkedlists.h:151
#define AST_RWLIST_HEAD_STATIC(name, type)
Defines a structure to be used to hold a read/write list of specified type, statically initialized.
Definition: linkedlists.h:333
#define AST_RWLIST_REMOVE
Definition: linkedlists.h:885
#define AST_RWLIST_FIRST
Definition: linkedlists.h:423
#define AST_RWLIST_TRAVERSE
Definition: linkedlists.h:494
#define AST_RWLIST_INSERT_TAIL
Definition: linkedlists.h:741
Asterisk locking-related definitions:
#define ast_rwlock_wrlock(a)
Definition: lock.h:236
#define ast_rwlock_rdlock(a)
Definition: lock.h:235
#define ast_rwlock_init(rwlock)
wrapper for rwlock with tracking enabled
Definition: lock.h:224
#define ast_rwlock_destroy(rwlock)
Definition: lock.h:233
#define ast_rwlock_unlock(a)
Definition: lock.h:234
#define ast_rwlock_tryrdlock(a)
Definition: lock.h:237
uintmax_t ast_debug_category_register(const char *name)
Register a debug level logger category.
int ast_debug_category_unregister(const char *name)
Un-register a debug level logger category.
size_t current
Definition: main/cli.c:113
The AMI - Asterisk Manager Interface - is a TCP protocol created to manage Asterisk with third-party ...
#define EVENT_FLAG_REPORTING
Definition: manager.h:84
struct ast_str * ast_manager_build_channel_state_string(const struct ast_channel_snapshot *snapshot)
Generate the AMI message body from a channel snapshot.
struct ast_manager_event_blob * ast_manager_event_blob_create(int event_flags, const char *manager_event, const char *extra_fields_fmt,...)
Construct a ast_manager_event_blob.
Definition: manager.c:10548
Asterisk module definitions.
#define ast_module_unref(mod)
Release a reference to the module.
Definition: module.h:469
#define ast_module_running_ref(mod)
Hold a reference to the module if it is running.
Definition: module.h:455
def ignore(key=None, val=None, section=None, pjsip=None, nmapped=None, type='endpoint')
Definition: sip_to_pjsip.py:48
Network socket handling.
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:167
ast_transport
Definition: netsock2.h:59
int ast_sockaddr_cmp(const struct ast_sockaddr *a, const struct ast_sockaddr *b)
Compares two ast_sockaddr structures.
Definition: netsock2.c:388
Options provided by main asterisk program.
Core PBX routines and definitions.
int pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
Add a variable to the channel variable stack, removing the most recently set value for the same name.
static void to_ami(struct ast_sip_subscription *sub, struct ast_str **buf)
static struct ast_srtp_res srtp_res
Definition: res_srtp.c:103
static struct ast_srtp_policy_res policy_res
Definition: res_srtp.c:115
SRTP resource.
#define NULL
Definition: resample.c:96
uintmax_t ast_debug_category_rtcp_packet_id(void)
Definition: rtp_engine.c:3601
void ast_rtp_instance_set_stats_vars(struct ast_channel *chan, struct ast_rtp_instance *instance)
Set standard statistics from an RTP instance on a channel.
Definition: rtp_engine.c:2528
unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format, const struct ast_format *format, int code)
Get the sample rate associated with known RTP payload types.
Definition: rtp_engine.c:2035
struct stasis_topic * ast_rtp_topic(void)
Stasis Message Bus API topic for RTP and RTCP related messages
Definition: rtp_engine.c:3573
struct ast_format * ast_rtp_codecs_get_payload_format(struct ast_rtp_codecs *codecs, int payload)
Retrieve the actual ast_format stored on the codecs structure for a specific tx payload type.
Definition: rtp_engine.c:1550
void ast_rtp_instance_get_incoming_source_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address)
Get the incoming source address of the remote endpoint.
Definition: rtp_engine.c:686
void ast_rtp_codecs_payloads_destroy(struct ast_rtp_codecs *codecs)
Destroy the contents of an RTP codecs structure (but not the structure itself)
Definition: rtp_engine.c:995
int ast_rtp_instance_destroy(struct ast_rtp_instance *instance)
Destroy an RTP instance.
Definition: rtp_engine.c:457
static enum ast_rtp_dtls_connection rtp_dtls_wrap_get_connection(struct ast_rtp_instance *instance)
Definition: rtp_engine.c:2979
enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get(struct ast_rtp_instance *instance)
Get the DTMF mode of an RTP instance.
Definition: rtp_engine.c:2150
int ast_rtp_codecs_payload_set_rx(struct ast_rtp_codecs *codecs, int code, struct ast_format *format)
Set a payload code for use with a specific Asterisk format.
Definition: rtp_engine.c:1936
struct ast_srtp_res * res_srtp
Definition: rtp_engine.c:176
struct ast_json * ast_rtp_convert_stats_json(const struct ast_rtp_instance_stats *stats)
Convert given stat instance into json format.
Definition: rtp_engine.c:4021
uintmax_t ast_debug_category_rtp_packet_id(void)
Definition: rtp_engine.c:3587
static void rtp_ice_wrap_turn_request(struct ast_rtp_instance *instance, enum ast_rtp_ice_component_type component, enum ast_transport transport, const char *server, unsigned int port, const char *username, const char *password)
Definition: rtp_engine.c:2896
static void rtp_payload_type_dtor(void *obj)
Definition: rtp_engine.c:298
struct ast_rtp_glue * ast_rtp_instance_get_active_glue(struct ast_rtp_instance *instance)
Get the RTP glue in use on an RTP instance.
Definition: rtp_engine.c:2742
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)
Convert formats into a string and put them into a buffer.
Definition: rtp_engine.c:2058
static struct ast_rtp_payload_type * rtp_payload_type_alloc(struct ast_format *format, int payload, int rtp_code, int primary_mapping)
Definition: rtp_engine.c:305
struct ast_rtp_rtcp_report * ast_rtp_rtcp_report_alloc(unsigned int report_blocks)
Allocate an ao2 ref counted instance of ast_rtp_rtcp_report.
Definition: rtp_engine.c:3516
int ast_rtp_instance_get_and_cmp_local_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address)
Get the address of the local endpoint that we are sending RTP to, comparing its address to another.
Definition: rtp_engine.c:650
void ast_rtp_instance_early_bridge_make_compatible(struct ast_channel *c_dst, struct ast_channel *c_src)
Make two channels compatible for early bridging.
Definition: rtp_engine.c:2264
static struct ast_rtp_engine_ice rtp_ice_wrappers
Definition: rtp_engine.c:2914
struct ast_rtp_instance * ast_rtp_instance_new(const char *engine_name, struct ast_sched_context *sched, const struct ast_sockaddr *sa, void *data)
Create a new RTP instance.
Definition: rtp_engine.c:486
struct ast_rtp_payload_type * ast_rtp_codecs_get_payload(struct ast_rtp_codecs *codecs, int payload)
Retrieve rx payload mapped information by payload type.
Definition: rtp_engine.c:1492
void ast_rtp_instance_set_last_rx(struct ast_rtp_instance *rtp, time_t time)
Set the last RTP reception time.
Definition: rtp_engine.c:3838
int ast_rtp_instance_get_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property)
Get the value of an RTP instance property.
Definition: rtp_engine.c:737
static uintmax_t debug_category_dtls_packet_id
Definition: rtp_engine.c:3613
static const char * rtp_dtls_wrap_get_fingerprint(struct ast_rtp_instance *instance)
Definition: rtp_engine.c:3025
int ast_rtp_engine_register_srtp(struct ast_srtp_res *srtp_res, struct ast_srtp_policy_res *policy_res)
Definition: rtp_engine.c:2747
int ast_rtp_instance_set_requested_target_address(struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
Set the requested target address of the remote endpoint.
Definition: rtp_engine.c:637
uintmax_t ast_debug_category_ice_id(void)
Definition: rtp_engine.c:3622
static void rtp_ice_wrap_stop(struct ast_rtp_instance *instance)
Definition: rtp_engine.c:2844
int ast_rtp_engine_srtp_is_registered(void)
Definition: rtp_engine.c:2768
static void rtp_ice_wrap_add_remote_candidate(struct ast_rtp_instance *instance, const struct ast_rtp_engine_ice_candidate *candidate)
Definition: rtp_engine.c:2830
static struct ast_rtp_payload_type * static_RTP_PT[AST_RTP_MAX_PT]
Mapping between Asterisk codecs and rtp payload types.
Definition: rtp_engine.c:273
static const char * rtp_ice_wrap_get_ufrag(struct ast_rtp_instance *instance)
Definition: rtp_engine.c:2851
int ast_rtp_instance_dtmf_mode_set(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode)
Set the DTMF mode that should be used.
Definition: rtp_engine.c:2136
void ast_rtp_instance_stop(struct ast_rtp_instance *instance)
Stop an RTP instance.
Definition: rtp_engine.c:2196
void ast_rtp_dtls_cfg_free(struct ast_rtp_dtls_cfg *dtls_cfg)
Free contents of a DTLS configuration structure.
Definition: rtp_engine.c:3168
static void rtcp_message_payload_dtor(void *obj)
Definition: rtp_engine.c:3325
int ast_rtp_instance_get_and_cmp_requested_target_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address)
Get the requested target address of the remote endpoint and compare it to the given address.
Definition: rtp_engine.c:672
static struct ast_rtp_mime_type ast_rtp_mime_types[128]
static void rtp_ice_wrap_ice_lite(struct ast_rtp_instance *instance)
Definition: rtp_engine.c:2881
static void rtp_ice_wrap_set_role(struct ast_rtp_instance *instance, enum ast_rtp_ice_role role)
Definition: rtp_engine.c:2888
void ast_rtp_engine_unregister_srtp(void)
Definition: rtp_engine.c:2762
static const char * rtp_ice_wrap_get_password(struct ast_rtp_instance *instance)
Definition: rtp_engine.c:2861
static void rtp_ice_wrap_start(struct ast_rtp_instance *instance)
Definition: rtp_engine.c:2837
uintmax_t ast_debug_category_rtp_id(void)
Definition: rtp_engine.c:3580
static uintmax_t debug_category_rtcp_id
Definition: rtp_engine.c:3592
void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
Copy payload information from one RTP instance to another.
Definition: rtp_engine.c:1237
void ast_rtp_publish_rtcp_message(struct ast_rtp_instance *rtp, struct stasis_message_type *message_type, struct ast_rtp_rtcp_report *report, struct ast_json *blob)
Publish an RTCP message to Stasis Message Bus API.
Definition: rtp_engine.c:3527
struct ast_srtp * ast_rtp_instance_get_srtp(struct ast_rtp_instance *instance, int rtcp)
Obtain the SRTP instance associated with an RTP instance.
Definition: rtp_engine.c:2800
static struct stasis_topic * rtp_topic
Stasis Message Bus API topic for RTP related messages
Definition: rtp_engine.c:277
void ast_rtp_instance_set_keepalive(struct ast_rtp_instance *instance, int interval)
Set the RTP keepalive interval.
Definition: rtp_engine.c:2717
struct ast_rtp_instance * ast_rtp_instance_get_bridged(struct ast_rtp_instance *instance)
Get the other RTP instance that an instance is bridged to.
Definition: rtp_engine.c:2247
size_t ast_rtp_instance_extmap_count(struct ast_rtp_instance *instance)
Get the number of known unique identifiers.
Definition: rtp_engine.c:920
static enum ast_rtp_extension_direction rtp_extmap_negotiate_direction(enum ast_rtp_extension_direction ours, enum ast_rtp_extension_direction theirs)
Helper function which negotiates two RTP extension directions to get our current direction.
Definition: rtp_engine.c:811
int ast_rtp_instance_extmap_enable(struct ast_rtp_instance *instance, int id, enum ast_rtp_extension extension, enum ast_rtp_extension_direction direction)
Enable support for an RTP extension on an instance.
Definition: rtp_engine.c:753
static void rtp_engine_shutdown(void)
Definition: rtp_engine.c:3632
#define SET_AST_JSON_OBJ(target, name, obj)
Set given json object into target with name.
Definition: rtp_engine.c:287
int ast_rtp_instance_early_bridge(struct ast_channel *c0, struct ast_channel *c1)
Early bridge two channels that use RTP instances.
Definition: rtp_engine.c:2350
void * ast_rtp_instance_get_data(struct ast_rtp_instance *instance)
Get the data portion of an RTP instance.
Definition: rtp_engine.c:584
struct ast_srtp_policy_res * res_srtp_policy
Definition: rtp_engine.c:177
enum ast_media_type ast_rtp_codecs_get_stream_type(struct ast_rtp_codecs *codecs)
Determine the type of RTP stream media from the codecs mapped.
Definition: rtp_engine.c:1473
char * ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size)
Retrieve quality statistics about an RTP instance.
Definition: rtp_engine.c:2477
int ast_rtp_instance_get_keepalive(struct ast_rtp_instance *instance)
Get the RTP keepalive interval.
Definition: rtp_engine.c:2732
struct ast_rtp_engine * ast_rtp_instance_get_engine(struct ast_rtp_instance *instance)
Get the RTP engine in use on an RTP instance.
Definition: rtp_engine.c:2737
static enum ast_rtp_dtls_setup rtp_dtls_wrap_get_setup(struct ast_rtp_instance *instance)
Definition: rtp_engine.c:2989
static void rtp_ice_wrap_change_components(struct ast_rtp_instance *instance, int num_components)
Definition: rtp_engine.c:2906
static void rtp_dtls_wrap_set_fingerprint(struct ast_rtp_instance *instance, enum ast_rtp_dtls_hash hash, const char *fingerprint)
Definition: rtp_engine.c:3007
const char * ast_rtp_instance_get_cname(struct ast_rtp_instance *rtp)
Retrieve the CNAME used in RTCP SDES items.
Definition: rtp_engine.c:3856
void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, struct ast_format_cap *astformats, int *nonastformats)
Retrieve all formats that were found.
Definition: rtp_engine.c:1593
int ast_rtp_instance_get_timeout(struct ast_rtp_instance *instance)
Get the RTP timeout value.
Definition: rtp_engine.c:2722
int ast_rtp_instance_dtmf_begin(struct ast_rtp_instance *instance, char digit)
Begin sending a DTMF digit.
Definition: rtp_engine.c:2094
struct ast_rtp_engine_dtls * ast_rtp_instance_get_dtls(struct ast_rtp_instance *instance)
Obtain a pointer to the DTLS support present on an RTP instance.
Definition: rtp_engine.c:3048
static void rtp_dtls_wrap_stop(struct ast_rtp_instance *instance)
Definition: rtp_engine.c:2965
static int rtp_codecs_assign_payload_code_rx(struct ast_rtp_codecs *codecs, int asterisk_format, struct ast_format *format, int code, int explicit)
Definition: rtp_engine.c:1828
void ast_rtp_instance_set_last_tx(struct ast_rtp_instance *rtp, time_t time)
Set the last RTP transmission time.
Definition: rtp_engine.c:3828
static void add_static_payload(int payload, struct ast_format *format, int rtp_code)
Definition: rtp_engine.c:3220
static ast_rwlock_t static_RTP_PT_lock
Definition: rtp_engine.c:274
static void rtp_ice_wrap_set_authentication(struct ast_rtp_instance *instance, const char *ufrag, const char *password)
Definition: rtp_engine.c:2823
struct ast_frame * ast_rtp_instance_read(struct ast_rtp_instance *instance, int rtcp)
Receive a frame over RTP.
Definition: rtp_engine.c:599
static int rtp_dtls_wrap_active(struct ast_rtp_instance *instance)
Definition: rtp_engine.c:2955
void ast_rtp_instance_set_data(struct ast_rtp_instance *instance, void *data)
Set the data portion of an RTP instance.
Definition: rtp_engine.c:579
int ast_rtp_instance_set_write_format(struct ast_rtp_instance *instance, struct ast_format *format)
Tell underlying RTP engine that audio frames will be provided in a specific format.
Definition: rtp_engine.c:2611
int ast_rtp_instance_bundle(struct ast_rtp_instance *child, struct ast_rtp_instance *parent)
Request that an RTP instance be bundled with another.
Definition: rtp_engine.c:3869
void ast_rtp_instance_stun_request(struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username)
Request that the underlying RTP engine send a STUN BIND request.
Definition: rtp_engine.c:2698
static void rtp_dtls_wrap_set_setup(struct ast_rtp_instance *instance, enum ast_rtp_dtls_setup setup)
Definition: rtp_engine.c:2999
void ast_rtp_codecs_set_framing(struct ast_rtp_codecs *codecs, unsigned int framing)
Set the framing used for a set of codecs.
Definition: rtp_engine.c:1571
static void rtp_dtls_wrap_reset(struct ast_rtp_instance *instance)
Definition: rtp_engine.c:2972
static uintmax_t debug_category_rtcp_packet_id
Definition: rtp_engine.c:3599
time_t ast_rtp_instance_get_last_tx(const struct ast_rtp_instance *rtp)
Get the last RTP transmission time.
Definition: rtp_engine.c:3823
void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
Record tx payload type information that was seen in an m= SDP line.
Definition: rtp_engine.c:1314
static void rtp_codecs_payloads_copy_tx(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
Definition: rtp_engine.c:1206
static int rtp_codecs_find_non_primary_dynamic_rx(struct ast_rtp_codecs *codecs)
Definition: rtp_engine.c:1791
int ast_rtp_red_init(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations)
Initialize RED support on an RTP instance.
Definition: rtp_engine.c:2431
struct ast_json * ast_rtp_instance_get_stats_all_json(struct ast_rtp_instance *instance)
Retrieve statistics about an RTP instance in json format.
Definition: rtp_engine.c:4097
void ast_rtp_instance_set_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value)
Set the value of an RTP instance property.
Definition: rtp_engine.c:726
static uintmax_t debug_category_ice_id
Definition: rtp_engine.c:3620
void ast_rtp_instance_set_hold_timeout(struct ast_rtp_instance *instance, int timeout)
Set the RTP timeout value for when the instance is on hold.
Definition: rtp_engine.c:2712
static void rtp_codecs_payloads_copy_rx(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
Definition: rtp_engine.c:1123
int ast_rtp_codecs_find_payload_code(struct ast_rtp_codecs *codecs, int payload)
Search for the tx payload type in the ast_rtp_codecs structure.
Definition: rtp_engine.c:1988
int ast_rtp_instance_make_compatible(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_channel *peer)
Request that the underlying RTP engine make two RTP instances compatible with eachother.
Definition: rtp_engine.c:2626
void ast_rtp_instance_set_extended_prop(struct ast_rtp_instance *instance, int property, void *value)
Set the value of an RTP instance extended property.
Definition: rtp_engine.c:702
static int mime_types_len
Definition: rtp_engine.c:261
void ast_rtp_instance_get_local_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address)
Get the local address that we are expecting RTP on.
Definition: rtp_engine.c:664
int ast_rtp_instance_dtmf_end_with_duration(struct ast_rtp_instance *instance, char digit, unsigned int duration)
Definition: rtp_engine.c:2122
int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
Retrieve statistics about an RTP instance.
Definition: rtp_engine.c:2459
int ast_rtp_instance_set_local_address(struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
Set the address that we are expecting to receive RTP on.
Definition: rtp_engine.c:609
int ast_rtp_get_rate(const struct ast_format *format)
Retrieve the sample rate of a format according to RTP specifications.
Definition: rtp_engine.c:4108
int ast_rtp_codecs_payload_code_tx(struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code)
Retrieve a tx mapped payload type based on whether it is an Asterisk format and the code.
Definition: rtp_engine.c:1941
enum ast_rtp_extension ast_rtp_instance_extmap_get_extension(struct ast_rtp_instance *instance, int id)
Retrieve the extension for an RTP extension id.
Definition: rtp_engine.c:931
int ast_rtp_instance_write(struct ast_rtp_instance *instance, struct ast_frame *frame)
Send a frame out over RTP.
Definition: rtp_engine.c:589
int ast_rtp_engine_init(void)
initializes the rtp engine arrays
Definition: rtp_engine.c:3677
int ast_rtp_glue_register2(struct ast_rtp_glue *glue, struct ast_module *module)
Register RTP glue.
Definition: rtp_engine.c:378
static struct ast_rtp_engine_dtls rtp_dtls_wrappers
Definition: rtp_engine.c:3035
uintmax_t ast_debug_category_dtls_packet_id(void)
Definition: rtp_engine.c:3615
static void rtp_engine_atexit(void)
Definition: rtp_engine.c:3663
static void rtp_rtcp_report_dtor(void *obj)
Definition: rtp_engine.c:3506
static uintmax_t debug_category_rtp_id
Definition: rtp_engine.c:3578
void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload)
Remove tx payload type mapped information.
Definition: rtp_engine.c:1446
int ast_rtp_instance_sendcng(struct ast_rtp_instance *instance, int level)
Send a comfort noise packet to the RTP instance.
Definition: rtp_engine.c:2809
static struct ao2_container * rtp_ice_wrap_get_local_candidates(struct ast_rtp_instance *instance)
Definition: rtp_engine.c:2871
static void rtp_engine_mime_type_cleanup(int i)
Definition: rtp_engine.c:3186
void ast_rtp_codecs_payloads_clear(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance)
Clear rx and tx payload mapping information from an RTP instance.
Definition: rtp_engine.c:1015
void ast_rtp_instance_set_remote_ssrc(struct ast_rtp_instance *rtp, unsigned int ssrc)
Set the remote SSRC for an RTP instance.
Definition: rtp_engine.c:3886
struct ast_rtp_engine_ice * ast_rtp_instance_get_ice(struct ast_rtp_instance *instance)
Obtain a pointer to the ICE support present on an RTP instance.
Definition: rtp_engine.c:2928
int ast_rtp_instance_get_hold_timeout(struct ast_rtp_instance *instance)
Get the RTP timeout value for when an RTP instance is on hold.
Definition: rtp_engine.c:2727
int ast_rtp_codecs_payloads_initialize(struct ast_rtp_codecs *codecs)
Initialize an RTP codecs structure.
Definition: rtp_engine.c:979
static uintmax_t debug_category_rtp_packet_id
Definition: rtp_engine.c:3585
int ast_rtp_dtls_cfg_parse(struct ast_rtp_dtls_cfg *dtls_cfg, const char *name, const char *value)
Parse DTLS related configuration options.
Definition: rtp_engine.c:3057
void * ast_rtp_instance_get_extended_prop(struct ast_rtp_instance *instance, int property)
Get the value of an RTP instance extended property.
Definition: rtp_engine.c:711
static uintmax_t debug_category_dtls_id
Definition: rtp_engine.c:3606
int ast_rtp_engine_unload_format(struct ast_format *format)
Formats requiring the use of a format attribute interface must have that interface registered in orde...
Definition: rtp_engine.c:3282
static void payload_mapping_rx_clear_primary(struct ast_rtp_codecs *codecs, struct ast_rtp_payload_type *to_match)
Definition: rtp_engine.c:1041
static int find_unused_payload_in_range(const struct ast_rtp_codecs *codecs, int start, int end, struct ast_rtp_payload_type *ignore[])
Definition: rtp_engine.c:1680
static void set_next_mime_type(struct ast_format *format, int rtp_code, const char *type, const char *subtype, unsigned int sample_rate)
Definition: rtp_engine.c:3192
int ast_rtp_instance_activate(struct ast_rtp_instance *instance)
Indicate to the RTP engine that packets are now expected to be sent/received on the RTP instance.
Definition: rtp_engine.c:2684
const char * ast_rtp_lookup_mime_subtype2(const int asterisk_format, const struct ast_format *format, int code, enum ast_rtp_options options)
Retrieve mime subtype information on a payload.
Definition: rtp_engine.c:2005
static void unref_instance_cond(struct ast_rtp_instance **instance)
Conditionally unref an rtp instance.
Definition: rtp_engine.c:2239
void ast_rtp_instance_get_requested_target_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address)
Get the requested target address of the remote endpoint.
Definition: rtp_engine.c:694
time_t ast_rtp_instance_get_last_rx(const struct ast_rtp_instance *rtp)
Get the last RTP reception time.
Definition: rtp_engine.c:3833
static struct ast_json * rtcp_report_to_json(struct stasis_message *msg, const struct stasis_message_sanitizer *sanitize)
Definition: rtp_engine.c:3428
int ast_rtp_engine_register2(struct ast_rtp_engine *engine, struct ast_module *module)
Register an RTP engine.
Definition: rtp_engine.c:329
static void rtp_codecs_payload_replace_rx(struct ast_rtp_codecs *codecs, int payload, struct ast_rtp_payload_type *new_type)
Definition: rtp_engine.c:1096
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)
Record tx payload type information that was seen in an a=rtpmap: SDP line.
Definition: rtp_engine.c:1441
int ast_rtp_instance_set_qos(struct ast_rtp_instance *instance, int tos, int cos, const char *desc)
Set QoS parameters on an RTP session.
Definition: rtp_engine.c:2182
static enum ast_rtp_dtls_hash rtp_dtls_wrap_get_fingerprint_hash(struct ast_rtp_instance *instance)
Definition: rtp_engine.c:3015
void ast_rtp_instance_set_channel_id(struct ast_rtp_instance *instance, const char *uniqueid)
Set the channel that owns this RTP instance.
Definition: rtp_engine.c:574
void ast_rtp_dtls_cfg_copy(const struct ast_rtp_dtls_cfg *src_cfg, struct ast_rtp_dtls_cfg *dst_cfg)
Copy contents of a DTLS configuration structure.
Definition: rtp_engine.c:3150
int ast_rtp_instance_set_incoming_source_address(struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
Set the incoming source address of the remote endpoint that we are sending RTP to.
Definition: rtp_engine.c:627
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)
Request the formats that can be transcoded.
Definition: rtp_engine.c:2670
int ast_rtp_codecs_payload_replace_format(struct ast_rtp_codecs *codecs, int payload, struct ast_format *format)
Update the format associated with a tx payload type in a codecs structure.
Definition: rtp_engine.c:1516
static int find_static_payload_type(int asterisk_format, const struct ast_format *format, int code)
Definition: rtp_engine.c:1637
uintmax_t ast_debug_category_rtcp_id(void)
Definition: rtp_engine.c:3594
struct ast_rtp_glue * ast_rtp_instance_get_glue(const char *type)
Get the RTP glue that binds a channel to the RTP engine.
Definition: rtp_engine.c:2219
const char * ast_rtp_instance_extmap_get_uri(struct ast_rtp_instance *instance, int id)
Retrieve the URI for an RTP extension id.
Definition: rtp_engine.c:967
int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int pt, char *mimetype, char *mimesubtype, enum ast_rtp_options options, unsigned int sample_rate)
Set tx payload type to a known MIME media type for a codec with a specific sample rate.
Definition: rtp_engine.c:1356
int ast_rtp_instance_dtmf_end(struct ast_rtp_instance *instance, char digit)
Stop sending a DTMF digit.
Definition: rtp_engine.c:2108
int ast_rtp_instance_extmap_get_id(struct ast_rtp_instance *instance, enum ast_rtp_extension extension)
Retrieve the id for an RTP extension.
Definition: rtp_engine.c:907
int ast_rtp_dtls_cfg_validate(struct ast_rtp_dtls_cfg *dtls_cfg)
Validates DTLS related configuration options.
Definition: rtp_engine.c:3131
static struct ast_manager_event_blob * rtcp_report_to_ami(struct stasis_message *msg)
Definition: rtp_engine.c:3334
void ast_rtp_instance_set_stream_num(struct ast_rtp_instance *rtp, int stream_num)
Set the stream number for an RTP instance.
Definition: rtp_engine.c:3895
static const char *const rtp_extension_uris[AST_RTP_EXTENSION_MAX]
URIs for known RTP extensions.
Definition: rtp_engine.c:234
void ast_rtp_instance_change_source(struct ast_rtp_instance *instance)
Indicate a new source of audio has dropped in and the ssrc should change.
Definition: rtp_engine.c:2173
int ast_rtp_engine_unregister(struct ast_rtp_engine *engine)
Unregister an RTP engine.
Definition: rtp_engine.c:363
uintmax_t ast_debug_category_dtls_id(void)
Definition: rtp_engine.c:3608
int ast_rtp_instance_extmap_negotiate(struct ast_rtp_instance *instance, int id, enum ast_rtp_extension_direction direction, const char *uri, const char *attributes)
Negotiate received RTP extension information.
Definition: rtp_engine.c:839
static int find_unused_payload(const struct ast_rtp_codecs *codecs)
Definition: rtp_engine.c:1714
static int rtp_dtls_wrap_set_configuration(struct ast_rtp_instance *instance, const struct ast_rtp_dtls_cfg *dtls_cfg)
Definition: rtp_engine.c:2944
int ast_rtp_engine_load_format(struct ast_format *format)
Custom formats declared in codecs.conf at startup must be communicated to the rtp_engine so their mim...
Definition: rtp_engine.c:3266
void ast_rtp_instance_extmap_clear(struct ast_rtp_instance *instance)
Clear negotiated RTP extension information.
Definition: rtp_engine.c:883
STASIS_MESSAGE_TYPE_DEFN(ast_rtp_rtcp_sent_type,.to_ami=rtcp_report_to_ami,.to_json=rtcp_report_to_json,)
Define RTCP/RTP message types.
struct ast_rtp_payload_type * ast_rtp_engine_alloc_payload_type(void)
Allocation routine for ast_rtp_payload_type.
Definition: rtp_engine.c:324
struct ast_rtp_codecs * ast_rtp_instance_get_codecs(struct ast_rtp_instance *instance)
Get the codecs structure of an RTP instance.
Definition: rtp_engine.c:748
int ast_rtp_instance_set_read_format(struct ast_rtp_instance *instance, struct ast_format *format)
Request that the underlying RTP engine provide audio frames in a specific format.
Definition: rtp_engine.c:2597
static void rtp_instance_set_incoming_source_address_nolock(struct ast_rtp_instance *instance, const struct ast_sockaddr *address)
Definition: rtp_engine.c:618
const char * ast_rtp_instance_get_channel_id(struct ast_rtp_instance *instance)
Get the unique ID of the channel that owns this RTP instance.
Definition: rtp_engine.c:569
int ast_rtp_instance_fd(struct ast_rtp_instance *instance, int rtcp)
Get the file descriptor for an RTP session (or RTCP)
Definition: rtp_engine.c:2205
void ast_rtp_instance_update_source(struct ast_rtp_instance *instance)
Indicate that the RTP marker bit should be set on an RTP stream.
Definition: rtp_engine.c:2164
unsigned int ast_rtp_codecs_get_framing(struct ast_rtp_codecs *codecs)
Get the framing used for a set of codecs.
Definition: rtp_engine.c:1582
unsigned int ast_rtp_instance_get_ssrc(struct ast_rtp_instance *rtp)
Retrieve the local SSRC value that we will be using.
Definition: rtp_engine.c:3843
int ast_rtp_red_buffer(struct ast_rtp_instance *instance, struct ast_frame *frame)
Buffer a frame in an RTP instance for RED.
Definition: rtp_engine.c:2445
static void instance_destructor(void *obj)
Definition: rtp_engine.c:422
int ast_rtp_instance_add_srtp_policy(struct ast_rtp_instance *instance, struct ast_srtp_policy *remote_policy, struct ast_srtp_policy *local_policy, int rtcp)
Add or replace the SRTP policies for the given RTP instance.
Definition: rtp_engine.c:2773
int ast_rtp_codecs_payload_code(struct ast_rtp_codecs *codecs, int asterisk_format, struct ast_format *format, int code)
Retrieve a rx mapped payload type based on whether it is an Asterisk format and the code.
Definition: rtp_engine.c:1886
static int payload_mapping_tx_is_present(const struct ast_rtp_codecs *codecs, const struct ast_rtp_payload_type *to_match)
Definition: rtp_engine.c:1159
enum ast_rtp_extension_direction ast_rtp_instance_extmap_get_direction(struct ast_rtp_instance *instance, int id)
Retrieve the negotiated direction for an RTP extension id.
Definition: rtp_engine.c:951
void ast_rtp_codecs_payloads_xover(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance)
Crossover copy the tx payload mapping of src to the rx payload mapping of dest.
Definition: rtp_engine.c:1270
void ast_rtp_instance_set_bridged(struct ast_rtp_instance *instance, struct ast_rtp_instance *bridged)
Set the other RTP instance that an instance is bridged to.
Definition: rtp_engine.c:2257
void ast_rtp_instance_set_timeout(struct ast_rtp_instance *instance, int timeout)
Set the RTP timeout value.
Definition: rtp_engine.c:2707
int ast_rtp_glue_unregister(struct ast_rtp_glue *glue)
Unregister RTP glue.
Definition: rtp_engine.c:407
static ast_rwlock_t mime_types_lock
Definition: rtp_engine.c:260
Pluggable RTP Architecture.
ast_rtp_dtls_setup
DTLS setup types.
Definition: rtp_engine.h:559
@ AST_RTP_DTLS_SETUP_PASSIVE
Definition: rtp_engine.h:561
@ AST_RTP_DTLS_SETUP_ACTPASS
Definition: rtp_engine.h:562
@ AST_RTP_DTLS_SETUP_ACTIVE
Definition: rtp_engine.h:560
ast_rtp_ice_role
ICE role during negotiation.
Definition: rtp_engine.h:514
#define AST_RTP_PT_LAST_REASSIGN
Definition: rtp_engine.h:95
ast_rtp_ice_component_type
ICE component types.
Definition: rtp_engine.h:508
ast_rtp_dtls_hash
DTLS fingerprint hashes.
Definition: rtp_engine.h:573
@ AST_RTP_DTLS_HASH_SHA1
Definition: rtp_engine.h:575
@ AST_RTP_DTLS_HASH_SHA256
Definition: rtp_engine.h:574
ast_rtp_dtmf_mode
Definition: rtp_engine.h:148
#define AST_LOG_CATEGORY_ICE
Definition: rtp_engine.h:2882
#define AST_RTP_DTMF
Definition: rtp_engine.h:291
#define AST_RTP_RTCP_SR
Definition: rtp_engine.h:318
ast_rtp_instance_stat_field
Definition: rtp_engine.h:168
@ AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS
Definition: rtp_engine.h:174
@ AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT
Definition: rtp_engine.h:176
@ AST_RTP_INSTANCE_STAT_FIELD_QUALITY
Definition: rtp_engine.h:170
@ AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER
Definition: rtp_engine.h:172
@ AST_RTP_INSTANCE_STAT_FIELD_QUALITY_MES
Definition: rtp_engine.h:178
@ AST_RTP_DTLS_VERIFY_NONE
Definition: rtp_engine.h:580
@ AST_RTP_DTLS_VERIFY_FINGERPRINT
Definition: rtp_engine.h:581
@ AST_RTP_DTLS_VERIFY_CERTIFICATE
Definition: rtp_engine.h:582
ast_rtp_glue_result
Definition: rtp_engine.h:158
@ AST_RTP_GLUE_RESULT_REMOTE
Definition: rtp_engine.h:162
@ AST_RTP_GLUE_RESULT_FORBID
Definition: rtp_engine.h:160
#define AST_LOG_CATEGORY_RTCP_PACKET
Definition: rtp_engine.h:2876
ast_rtp_instance_stat
Definition: rtp_engine.h:182
@ AST_RTP_INSTANCE_STAT_COMBINED_MES
Definition: rtp_engine.h:257
@ AST_RTP_INSTANCE_STAT_COMBINED_JITTER
Definition: rtp_engine.h:212
@ AST_RTP_INSTANCE_STAT_COMBINED_LOSS
Definition: rtp_engine.h:190
@ AST_RTP_INSTANCE_STAT_COMBINED_RTT
Definition: rtp_engine.h:234
@ AST_RTP_INSTANCE_STAT_ALL
Definition: rtp_engine.h:184
#define AST_LOG_CATEGORY_DTLS
Definition: rtp_engine.h:2878
#define AST_RTP_MAX_PT
Definition: rtp_engine.h:83
#define AST_LOG_CATEGORY_RTCP
Definition: rtp_engine.h:2874
#define ast_debug_rtp(sublevel,...)
Log debug level RTP information.
Definition: rtp_engine.h:2906
#define AST_LOG_CATEGORY_RTP
Definition: rtp_engine.h:2870
#define ast_debug_rtp_is_allowed
Definition: rtp_engine.h:2910
ast_rtp_extension
Known RTP extensions.
Definition: rtp_engine.h:588
@ AST_RTP_EXTENSION_MAX
Definition: rtp_engine.h:596
@ AST_RTP_EXTENSION_TRANSPORT_WIDE_CC
Definition: rtp_engine.h:594
@ AST_RTP_EXTENSION_ABS_SEND_TIME
Definition: rtp_engine.h:592
@ AST_RTP_EXTENSION_UNSUPPORTED
Definition: rtp_engine.h:590
#define AST_RTP_PT_FIRST_DYNAMIC
Definition: rtp_engine.h:92
ast_rtp_options
Definition: rtp_engine.h:142
@ AST_RTP_OPT_G726_NONSTANDARD
Definition: rtp_engine.h:144
ast_rtp_dtls_connection
DTLS connection states.
Definition: rtp_engine.h:567
ast_rtp_property
Definition: rtp_engine.h:113
@ AST_RTP_PROPERTY_MAX
Maximum number of RTP properties supported.
Definition: rtp_engine.h:138
#define AST_LOG_CATEGORY_RTP_PACKET
Definition: rtp_engine.h:2872
#define AST_RTP_PT_LAST_STATIC
Definition: rtp_engine.h:89
ast_rtp_extension_direction
Directions for RTP extensions.
Definition: rtp_engine.h:815
@ AST_RTP_EXTENSION_DIRECTION_SENDRECV
Definition: rtp_engine.h:819
@ AST_RTP_EXTENSION_DIRECTION_NONE
Definition: rtp_engine.h:817
@ AST_RTP_EXTENSION_DIRECTION_INACTIVE
Definition: rtp_engine.h:825
@ AST_RTP_EXTENSION_DIRECTION_RECVONLY
Definition: rtp_engine.h:823
@ AST_RTP_EXTENSION_DIRECTION_SENDONLY
Definition: rtp_engine.h:821
#define AST_LOG_CATEGORY_DTLS_PACKET
Definition: rtp_engine.h:2880
#define AST_RTP_CN
Definition: rtp_engine.h:293
#define AST_RTP_MAX
Definition: rtp_engine.h:297
#define AST_RTP_CISCO_DTMF
Definition: rtp_engine.h:295
Scheduler Routines (derived from cheops)
Stasis Message Bus API. See Stasis Message Bus API for detailed documentation.
struct stasis_message_type * stasis_message_type(const struct stasis_message *msg)
Get the message type for a stasis_message.
#define STASIS_MESSAGE_TYPE_CLEANUP(name)
Boiler-plate messaging macro for cleaning up message types.
Definition: stasis.h:1515
struct stasis_topic * stasis_topic_create(const char *name)
Create a new topic.
Definition: stasis.c:617
#define STASIS_MESSAGE_TYPE_INIT(name)
Boiler-plate messaging macro for initializing message types.
Definition: stasis.h:1493
void * stasis_message_data(const struct stasis_message *msg)
Get the data contained in a message.
struct stasis_message * stasis_message_create(struct stasis_message_type *type, void *data)
Create a new message.
void stasis_publish(struct stasis_topic *topic, struct stasis_message *message)
Publish a message to a topic's subscribers.
Definition: stasis.c:1511
struct ast_json * ast_channel_snapshot_to_json(const struct ast_channel_snapshot *snapshot, const struct stasis_message_sanitizer *sanitize)
Build a JSON object from a ast_channel_snapshot.
String manipulation functions.
int ast_str_append(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Append to a thread local dynamic string.
Definition: strings.h:1139
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:761
int attribute_pure ast_true(const char *val)
Make sure something is true. Determine if a string containing a boolean value is "true"....
Definition: utils.c:2199
static force_inline char * ast_str_to_upper(char *str)
Convert a string to all upper-case.
Definition: strings.h:1342
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:659
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:425
#define AS_OR(a, b)
Definition: strings.h:49
Generic container type.
Structure representing a snapshot of channel state.
Main Channel structure associated with a channel.
struct ast_bridge * bridge
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
Definition of a media format.
Definition: format.c:43
Data structure associated with a single frame of data.
Abstract JSON element (object, array, string, int, ...).
Struct containing info for an AMI event to send out.
Definition: manager.h:502
struct ast_rtp_codecs::@277 payload_mapping_tx
ast_rwlock_t codecs_lock
Definition: rtp_engine.h:753
struct ast_rtp_codecs::@276 payload_mapping_rx
unsigned int framing
Definition: rtp_engine.h:759
DTLS configuration structure.
Definition: rtp_engine.h:600
enum ast_rtp_dtls_setup default_setup
Definition: rtp_engine.h:603
enum ast_rtp_dtls_verify verify
Definition: rtp_engine.h:606
unsigned int rekey
Definition: rtp_engine.h:602
enum ast_rtp_dtls_hash hash
Definition: rtp_engine.h:605
unsigned int enabled
Definition: rtp_engine.h:601
unsigned int ephemeral_cert
Definition: rtp_engine.h:612
enum ast_srtp_suite suite
Definition: rtp_engine.h:604
Structure that represents the optional DTLS SRTP support within an RTP engine.
Definition: rtp_engine.h:616
int(* set_configuration)(struct ast_rtp_instance *instance, const struct ast_rtp_dtls_cfg *dtls_cfg)
Definition: rtp_engine.h:618
int(* active)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:620
enum ast_rtp_dtls_setup(* get_setup)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:628
void(* stop)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:622
enum ast_rtp_dtls_hash(* get_fingerprint_hash)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:634
const char *(* get_fingerprint)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:636
void(* reset)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:624
void(* set_fingerprint)(struct ast_rtp_instance *instance, enum ast_rtp_dtls_hash hash, const char *fingerprint)
Definition: rtp_engine.h:632
enum ast_rtp_dtls_connection(* get_connection)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:626
void(* set_setup)(struct ast_rtp_instance *instance, enum ast_rtp_dtls_setup setup)
Definition: rtp_engine.h:630
Structure for an ICE candidate.
Definition: rtp_engine.h:520
Structure that represents the optional ICE support within an RTP engine.
Definition: rtp_engine.h:531
void(* ice_lite)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:547
void(* stop)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:539
void(* change_components)(struct ast_rtp_instance *instance, int num_components)
Definition: rtp_engine.h:555
void(* set_authentication)(struct ast_rtp_instance *instance, const char *ufrag, const char *password)
Definition: rtp_engine.h:533
void(* start)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:537
const char *(* get_ufrag)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:541
void(* turn_request)(struct ast_rtp_instance *instance, enum ast_rtp_ice_component_type component, enum ast_transport transport, const char *server, unsigned int port, const char *username, const char *password)
Definition: rtp_engine.h:551
void(* add_remote_candidate)(struct ast_rtp_instance *instance, const struct ast_rtp_engine_ice_candidate *candidate)
Definition: rtp_engine.h:535
const char *(* get_password)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:543
void(* set_role)(struct ast_rtp_instance *instance, enum ast_rtp_ice_role role)
Definition: rtp_engine.h:549
struct ao2_container *(* get_local_candidates)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:545
int(* get_stat)(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat)
Definition: rtp_engine.h:697
int(* write)(struct ast_rtp_instance *instance, struct ast_frame *frame)
Definition: rtp_engine.h:670
int(* qos)(struct ast_rtp_instance *instance, int tos, int cos, const char *desc)
Definition: rtp_engine.h:699
void(* stop)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:672
enum ast_rtp_dtmf_mode(* dtmf_mode_get)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:695
int(* activate)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:719
void(* change_source)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:681
int(* dtmf_end)(struct ast_rtp_instance *instance, char digit)
Definition: rtp_engine.h:676
void(* payload_set)(struct ast_rtp_instance *instance, int payload, int asterisk_format, struct ast_format *format, int code)
Definition: rtp_engine.h:689
int(* destroy)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:668
int(* fd)(struct ast_rtp_instance *instance, int rtcp)
Definition: rtp_engine.h:701
int(* dtmf_mode_set)(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode)
Definition: rtp_engine.h:693
void(* set_remote_ssrc)(struct ast_rtp_instance *instance, unsigned int ssrc)
Definition: rtp_engine.h:733
void *(* extended_prop_get)(struct ast_rtp_instance *instance, int property)
Definition: rtp_engine.h:685
int(* make_compatible)(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1)
Definition: rtp_engine.h:715
struct ast_module * mod
Definition: rtp_engine.h:664
int(* red_buffer)(struct ast_rtp_instance *instance, struct ast_frame *frame)
Definition: rtp_engine.h:705
int(* set_read_format)(struct ast_rtp_instance *instance, struct ast_format *format)
Definition: rtp_engine.h:711
int(* new)(struct ast_rtp_instance *instance, struct ast_sched_context *sched, struct ast_sockaddr *sa, void *data)
Definition: rtp_engine.h:666
int(* red_init)(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations)
Definition: rtp_engine.h:703
void(* prop_set)(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value)
Definition: rtp_engine.h:687
const char * name
Definition: rtp_engine.h:662
int(* dtmf_end_with_duration)(struct ast_rtp_instance *instance, char digit, unsigned int duration)
Definition: rtp_engine.h:677
int(* set_write_format)(struct ast_rtp_instance *instance, struct ast_format *format)
Definition: rtp_engine.h:713
void(* remote_address_set)(struct ast_rtp_instance *instance, struct ast_sockaddr *sa)
Definition: rtp_engine.h:691
void(* available_formats)(struct ast_rtp_instance *instance, struct ast_format_cap *to_endpoint, struct ast_format_cap *to_asterisk, struct ast_format_cap *result)
Definition: rtp_engine.h:723
int(* sendcng)(struct ast_rtp_instance *instance, int level)
Definition: rtp_engine.h:725
void(* update_source)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:679
void(* stun_request)(struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username)
Definition: rtp_engine.h:721
int(* dtmf_begin)(struct ast_rtp_instance *instance, char digit)
Definition: rtp_engine.h:674
const char *(* cname_get)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:729
struct ast_rtp_engine_ice * ice
Definition: rtp_engine.h:737
unsigned int(* ssrc_get)(struct ast_rtp_instance *instance)
Definition: rtp_engine.h:727
struct ast_rtp_engine_dtls * dtls
Definition: rtp_engine.h:739
void(* set_stream_num)(struct ast_rtp_instance *instance, int stream_num)
Definition: rtp_engine.h:735
struct ast_frame *(* read)(struct ast_rtp_instance *instance, int rtcp)
Definition: rtp_engine.h:707
int(* bundle)(struct ast_rtp_instance *child, struct ast_rtp_instance *parent)
Definition: rtp_engine.h:731
int(* extension_enable)(struct ast_rtp_instance *instance, enum ast_rtp_extension extension)
Definition: rtp_engine.h:745
int(* extended_prop_set)(struct ast_rtp_instance *instance, int property, void *value)
Definition: rtp_engine.h:683
enum ast_rtp_glue_result(* get_rtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance)
Callback for retrieving the RTP instance carrying audio.
Definition: rtp_engine.h:775
void(* get_codec)(struct ast_channel *chan, struct ast_format_cap *result_cap)
Callback for retrieving codecs that the channel can do. Result returned in result_cap.
Definition: rtp_engine.h:807
int(* update_peer)(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, const struct ast_format_cap *cap, int nat_active)
Definition: rtp_engine.h:802
const char * type
Definition: rtp_engine.h:768
struct ast_module * mod
Definition: rtp_engine.h:770
enum ast_rtp_glue_result(* get_vrtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance)
Callback for retrieving the RTP instance carrying video.
Definition: rtp_engine.h:787
unsigned int remote_ssrc
Definition: rtp_engine.h:449
unsigned int rxcount
Definition: rtp_engine.h:395
unsigned int local_ssrc
Definition: rtp_engine.h:447
unsigned int rxoctetcount
Definition: rtp_engine.h:455
unsigned int rxploss
Definition: rtp_engine.h:419
unsigned int txcount
Definition: rtp_engine.h:393
unsigned int txploss
Definition: rtp_engine.h:417
unsigned int txoctetcount
Definition: rtp_engine.h:453
char channel_uniqueid[MAX_CHANNEL_ID]
Definition: rtp_engine.h:451
struct ast_rtp_codecs codecs
Definition: rtp_engine.c:204
struct ast_srtp * rtcp_srtp
Definition: rtp_engine.c:216
struct ast_rtp_instance::@382 extmap_enabled
int properties[AST_RTP_PROPERTY_MAX]
Definition: rtp_engine.c:194
struct ast_sockaddr incoming_source_address
Definition: rtp_engine.c:200
struct ast_rtp_glue * glue
Definition: rtp_engine.c:212
struct ast_rtp_instance::@383 extmap_negotiated
struct ast_sockaddr requested_target_address
Definition: rtp_engine.c:198
struct ast_sockaddr local_address
Definition: rtp_engine.c:196
struct ast_rtp_instance::@384 extmap_unique_ids
struct ast_rtp_instance * bridged
Definition: rtp_engine.c:202
struct ast_rtp_engine * engine
Definition: rtp_engine.c:190
char channel_uniqueid[AST_MAX_UNIQUEID]
Definition: rtp_engine.c:218
struct ast_srtp * srtp
Definition: rtp_engine.c:214
unsigned int sample_rate
Expected sample rate of the /c subtype.
Definition: rtp_engine.c:258
char subtype[64]
The format type.
Definition: rtp_engine.c:256
char type[16]
The media type.
Definition: rtp_engine.c:254
struct ast_rtp_payload_type payload_type
A mapping object between the Asterisk codec and this RTP payload.
Definition: rtp_engine.c:252
unsigned int primary_mapping
Definition: rtp_engine.h:311
struct ast_format * format
Definition: rtp_engine.h:303
A report block within a SR/RR report.
Definition: rtp_engine.h:341
unsigned int highest_seq_no
Definition: rtp_engine.h:347
struct ast_rtp_rtcp_report_block::@272 lost_count
unsigned short fraction
Definition: rtp_engine.h:344
unsigned int source_ssrc
Definition: rtp_engine.h:342
An object that represents data sent during a SR/RR RTCP report.
Definition: rtp_engine.h:356
struct ast_rtp_rtcp_report::@273 sender_information
unsigned int type
Definition: rtp_engine.h:359
unsigned short reception_report_count
Definition: rtp_engine.h:357
unsigned int rtp_timestamp
Definition: rtp_engine.h:362
struct ast_rtp_rtcp_report_block * report_block[0]
Definition: rtp_engine.h:369
struct timeval ntp_timestamp
Definition: rtp_engine.h:361
unsigned int octet_count
Definition: rtp_engine.h:364
unsigned int ssrc
Definition: rtp_engine.h:358
unsigned int packet_count
Definition: rtp_engine.h:363
Structure for rwlock and tracking information.
Definition: lock.h:157
Socket address structure.
Definition: netsock2.h:97
void(* destroy)(struct ast_srtp *srtp)
Definition: res_srtp.h:40
int(* replace)(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy)
Definition: res_srtp.h:38
int(* add_stream)(struct ast_srtp *srtp, struct ast_srtp_policy *policy)
Definition: res_srtp.h:42
int(* create)(struct ast_srtp **srtp, struct ast_rtp_instance *rtp, struct ast_srtp_policy *policy)
Definition: res_srtp.h:36
Support for dynamic strings.
Definition: strings.h:623
Definition: search.h:40
structure to hold extensions
struct ast_rtp_rtcp_report * report
Definition: rtp_engine.c:3321
struct ast_channel_snapshot * snapshot
Definition: rtp_engine.c:3320
struct ast_json * blob
Definition: rtp_engine.c:3322
enum ast_rtp_extension extension
Definition: rtp_engine.c:182
enum ast_rtp_extension_direction direction
Definition: rtp_engine.c:184
Definition: sched.c:76
Structure containing callbacks for Stasis message sanitization.
Definition: stasis.h:200
int value
Definition: syslog.c:37
int done
Definition: test_amihooks.c:48
static struct test_options options
Time-related functions and macros.
int64_t ast_tvdiff_ms(struct timeval end, struct timeval start)
Computes the difference (in milliseconds) between two struct timeval instances.
Definition: time.h:107
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:159
Support for translation of data formats. translate.c.
void ast_translate_available_formats(struct ast_format_cap *dest, struct ast_format_cap *src, struct ast_format_cap *result)
Find available formats.
Definition: translate.c:1616
Utility functions.
#define RAII_VAR(vartype, varname, initval, dtor)
Declare a variable that will call a destructor function when it goes out of scope.
Definition: utils.h:941
#define ast_assert(a)
Definition: utils.h:739
int ast_file_is_readable(const char *filename)
Test that a file exists and is readable by the effective user.
Definition: utils.c:3107
#define ARRAY_LEN(a)
Definition: utils.h:666
#define MAX(a, b)
Definition: utils.h:233
Vector container support.
#define AST_VECTOR_REPLACE(vec, idx, elem)
Replace an element at a specific position in a vector, growing the vector if needed.
Definition: vector.h:284
#define AST_VECTOR_SIZE(vec)
Get the number of elements in a vector.
Definition: vector.h:609
#define AST_VECTOR_FREE(vec)
Deallocates this vector.
Definition: vector.h:174
#define AST_VECTOR_INIT(vec, size)
Initialize a vector.
Definition: vector.h:113
#define AST_VECTOR_APPEND(vec, elem)
Append an element to a vector, growing the vector if needed.
Definition: vector.h:256
#define AST_VECTOR(name, type)
Define a vector structure.
Definition: vector.h:44
#define AST_VECTOR_GET(vec, idx)
Get an element from a vector.
Definition: vector.h:680
#define AST_VECTOR_GET_ADDR(vec, idx)
Get an address of element in a vector.
Definition: vector.h:668