rtp_engine.h 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2009, Digium, Inc.
  5. *
  6. * Mark Spencer <markster@digium.com>
  7. * Joshua Colp <jcolp@digium.com>
  8. *
  9. * See http://www.asterisk.org for more information about
  10. * the Asterisk project. Please do not directly contact
  11. * any of the maintainers of this project for assistance;
  12. * the project provides a web site, mailing lists and IRC
  13. * channels for your use.
  14. *
  15. * This program is free software, distributed under the terms of
  16. * the GNU General Public License Version 2. See the LICENSE file
  17. * at the top of the source tree.
  18. */
  19. /*! \file
  20. * \brief Pluggable RTP Architecture
  21. * \author Joshua Colp <jcolp@digium.com>
  22. * \ref AstRTPEngine
  23. */
  24. /*!
  25. * \page AstRTPEngine Asterisk RTP Engine API
  26. *
  27. * The purpose of this API is to provide a way for multiple RTP stacks to be
  28. * used inside of Asterisk without any module that uses RTP knowing any
  29. * different. To the module each RTP stack behaves the same.
  30. *
  31. * An RTP session is called an instance and is made up of a combination of codec
  32. * information, RTP engine, RTP properties, and address information. An engine
  33. * name may be passed in to explicitly choose an RTP stack to be used but a
  34. * default one will be used if none is provided. An address to use for RTP may
  35. * also be provided but the underlying RTP engine may choose a different address
  36. * depending on it's configuration.
  37. *
  38. * An RTP engine is the layer between the RTP engine core and the RTP stack
  39. * itself. The RTP engine core provides a set of callbacks to do various things
  40. * (such as write audio out) that the RTP engine has to have implemented.
  41. *
  42. * Glue is what binds an RTP instance to a channel. It is used to retrieve RTP
  43. * instance information when performing remote or local bridging and is used to
  44. * have the channel driver tell the remote side to change destination of the RTP
  45. * stream.
  46. *
  47. * Statistics from an RTP instance can be retrieved using the
  48. * ast_rtp_instance_get_stats API call. This essentially asks the RTP engine in
  49. * use to fill in a structure with the requested values. It is not required for
  50. * an RTP engine to support all statistic values.
  51. *
  52. * Properties allow behavior of the RTP engine and RTP engine core to be
  53. * changed. For example, there is a property named AST_RTP_PROPERTY_NAT which is
  54. * used to tell the RTP engine to enable symmetric RTP if it supports it. It is
  55. * not required for an RTP engine to support all properties.
  56. *
  57. * Codec information is stored using a separate data structure which has it's
  58. * own set of API calls to add/remove/retrieve information. They are used by the
  59. * module after an RTP instance is created so that payload information is
  60. * available for the RTP engine.
  61. */
  62. #ifndef _ASTERISK_RTP_ENGINE_H
  63. #define _ASTERISK_RTP_ENGINE_H
  64. #if defined(__cplusplus) || defined(c_plusplus)
  65. extern "C" {
  66. #endif
  67. #include "asterisk/astobj2.h"
  68. #include "asterisk/frame.h"
  69. #include "asterisk/format_cap.h"
  70. #include "asterisk/netsock2.h"
  71. #include "asterisk/sched.h"
  72. #include "asterisk/res_srtp.h"
  73. #include "asterisk/stasis.h"
  74. #include "asterisk/vector.h"
  75. /*! Maximum number of payload types RTP can support. */
  76. #define AST_RTP_MAX_PT 128
  77. /*! First dynamic RTP payload type */
  78. #define AST_RTP_PT_FIRST_DYNAMIC 96
  79. /*! Last reassignable RTP payload type */
  80. #define AST_RTP_PT_LAST_REASSIGN 63
  81. /*! Maximum number of generations */
  82. #define AST_RED_MAX_GENERATION 5
  83. /*!
  84. * Maximum size of an internal Asterisk channel unique ID.
  85. *
  86. * \note Must match the AST_MAX_UNIQUEID(AST_MAX_PUBLIC_UNIQUEID) value.
  87. * We don't use that defined value directly here to avoid a hard
  88. * dependency on channel.h.
  89. */
  90. #define MAX_CHANNEL_ID 152
  91. struct ast_rtp_instance;
  92. struct ast_rtp_glue;
  93. /*! RTP Properties that can be set on an RTP instance */
  94. enum ast_rtp_property {
  95. /*! Enable symmetric RTP support */
  96. AST_RTP_PROPERTY_NAT = 0,
  97. /*! RTP instance will be carrying DTMF (using RFC2833) */
  98. AST_RTP_PROPERTY_DTMF,
  99. /*! Expect unreliable DTMF from remote party */
  100. AST_RTP_PROPERTY_DTMF_COMPENSATE,
  101. /*! Enable STUN support */
  102. AST_RTP_PROPERTY_STUN,
  103. /*! Enable RTCP support */
  104. AST_RTP_PROPERTY_RTCP,
  105. /*! Enable Asymmetric RTP Codecs */
  106. AST_RTP_PROPERTY_ASYMMETRIC_CODEC,
  107. /*!
  108. * \brief Maximum number of RTP properties supported
  109. *
  110. * \note THIS MUST BE THE LAST ENTRY IN THIS ENUM.
  111. */
  112. AST_RTP_PROPERTY_MAX,
  113. };
  114. /*! Additional RTP options */
  115. enum ast_rtp_options {
  116. /*! Remote side is using non-standard G.726 */
  117. AST_RTP_OPT_G726_NONSTANDARD = (1 << 0),
  118. };
  119. /*! RTP DTMF Modes */
  120. enum ast_rtp_dtmf_mode {
  121. /*! No DTMF is being carried over the RTP stream */
  122. AST_RTP_DTMF_MODE_NONE = 0,
  123. /*! DTMF is being carried out of band using RFC2833 */
  124. AST_RTP_DTMF_MODE_RFC2833,
  125. /*! DTMF is being carried inband over the RTP stream */
  126. AST_RTP_DTMF_MODE_INBAND,
  127. };
  128. /*! Result codes when RTP glue is queried for information */
  129. enum ast_rtp_glue_result {
  130. /*! No remote or local bridging is permitted */
  131. AST_RTP_GLUE_RESULT_FORBID = 0,
  132. /*! Move RTP stream to be remote between devices directly */
  133. AST_RTP_GLUE_RESULT_REMOTE,
  134. /*! Perform RTP engine level bridging if possible */
  135. AST_RTP_GLUE_RESULT_LOCAL,
  136. };
  137. /*! Field statistics that can be retrieved from an RTP instance */
  138. enum ast_rtp_instance_stat_field {
  139. /*! Retrieve quality information */
  140. AST_RTP_INSTANCE_STAT_FIELD_QUALITY = 0,
  141. /*! Retrieve quality information about jitter */
  142. AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER,
  143. /*! Retrieve quality information about packet loss */
  144. AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS,
  145. /*! Retrieve quality information about round trip time */
  146. AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT,
  147. };
  148. /*! Statistics that can be retrieved from an RTP instance */
  149. enum ast_rtp_instance_stat {
  150. /*! Retrieve all statistics */
  151. AST_RTP_INSTANCE_STAT_ALL = 0,
  152. /*! Retrieve number of packets transmitted */
  153. AST_RTP_INSTANCE_STAT_TXCOUNT,
  154. /*! Retrieve number of packets received */
  155. AST_RTP_INSTANCE_STAT_RXCOUNT,
  156. /*! Retrieve ALL statistics relating to packet loss */
  157. AST_RTP_INSTANCE_STAT_COMBINED_LOSS,
  158. /*! Retrieve number of packets lost for transmitting */
  159. AST_RTP_INSTANCE_STAT_TXPLOSS,
  160. /*! Retrieve number of packets lost for receiving */
  161. AST_RTP_INSTANCE_STAT_RXPLOSS,
  162. /*! Retrieve maximum number of packets lost on remote side */
  163. AST_RTP_INSTANCE_STAT_REMOTE_MAXRXPLOSS,
  164. /*! Retrieve minimum number of packets lost on remote side */
  165. AST_RTP_INSTANCE_STAT_REMOTE_MINRXPLOSS,
  166. /*! Retrieve average number of packets lost on remote side */
  167. AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVRXPLOSS,
  168. /*! Retrieve standard deviation of packets lost on remote side */
  169. AST_RTP_INSTANCE_STAT_REMOTE_STDEVRXPLOSS,
  170. /*! Retrieve maximum number of packets lost on local side */
  171. AST_RTP_INSTANCE_STAT_LOCAL_MAXRXPLOSS,
  172. /*! Retrieve minimum number of packets lost on local side */
  173. AST_RTP_INSTANCE_STAT_LOCAL_MINRXPLOSS,
  174. /*! Retrieve average number of packets lost on local side */
  175. AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVRXPLOSS,
  176. /*! Retrieve standard deviation of packets lost on local side */
  177. AST_RTP_INSTANCE_STAT_LOCAL_STDEVRXPLOSS,
  178. /*! Retrieve ALL statistics relating to jitter */
  179. AST_RTP_INSTANCE_STAT_COMBINED_JITTER,
  180. /*! Retrieve jitter on transmitted packets */
  181. AST_RTP_INSTANCE_STAT_TXJITTER,
  182. /*! Retrieve jitter on received packets */
  183. AST_RTP_INSTANCE_STAT_RXJITTER,
  184. /*! Retrieve maximum jitter on remote side */
  185. AST_RTP_INSTANCE_STAT_REMOTE_MAXJITTER,
  186. /*! Retrieve minimum jitter on remote side */
  187. AST_RTP_INSTANCE_STAT_REMOTE_MINJITTER,
  188. /*! Retrieve average jitter on remote side */
  189. AST_RTP_INSTANCE_STAT_REMOTE_NORMDEVJITTER,
  190. /*! Retrieve standard deviation jitter on remote side */
  191. AST_RTP_INSTANCE_STAT_REMOTE_STDEVJITTER,
  192. /*! Retrieve maximum jitter on local side */
  193. AST_RTP_INSTANCE_STAT_LOCAL_MAXJITTER,
  194. /*! Retrieve minimum jitter on local side */
  195. AST_RTP_INSTANCE_STAT_LOCAL_MINJITTER,
  196. /*! Retrieve average jitter on local side */
  197. AST_RTP_INSTANCE_STAT_LOCAL_NORMDEVJITTER,
  198. /*! Retrieve standard deviation jitter on local side */
  199. AST_RTP_INSTANCE_STAT_LOCAL_STDEVJITTER,
  200. /*! Retrieve ALL statistics relating to round trip time */
  201. AST_RTP_INSTANCE_STAT_COMBINED_RTT,
  202. /*! Retrieve round trip time */
  203. AST_RTP_INSTANCE_STAT_RTT,
  204. /*! Retrieve maximum round trip time */
  205. AST_RTP_INSTANCE_STAT_MAX_RTT,
  206. /*! Retrieve minimum round trip time */
  207. AST_RTP_INSTANCE_STAT_MIN_RTT,
  208. /*! Retrieve average round trip time */
  209. AST_RTP_INSTANCE_STAT_NORMDEVRTT,
  210. /*! Retrieve standard deviation round trip time */
  211. AST_RTP_INSTANCE_STAT_STDEVRTT,
  212. /*! Retrieve local SSRC */
  213. AST_RTP_INSTANCE_STAT_LOCAL_SSRC,
  214. /*! Retrieve remote SSRC */
  215. AST_RTP_INSTANCE_STAT_REMOTE_SSRC,
  216. /*! Retrieve channel unique ID */
  217. AST_RTP_INSTANCE_STAT_CHANNEL_UNIQUEID,
  218. /*! Retrieve number of octets transmitted */
  219. AST_RTP_INSTANCE_STAT_TXOCTETCOUNT,
  220. /*! Retrieve number of octets received */
  221. AST_RTP_INSTANCE_STAT_RXOCTETCOUNT,
  222. };
  223. enum ast_rtp_instance_rtcp {
  224. /*! RTCP should not be sent/received */
  225. AST_RTP_INSTANCE_RTCP_DISABLED = 0,
  226. /*! RTCP should be sent/received based on standard port rules */
  227. AST_RTP_INSTANCE_RTCP_STANDARD,
  228. /*! RTCP should be sent/received on the same port as RTP */
  229. AST_RTP_INSTANCE_RTCP_MUX,
  230. };
  231. /* Codes for RTP-specific data - not defined by our AST_FORMAT codes */
  232. /*! DTMF (RFC2833) */
  233. #define AST_RTP_DTMF (1 << 0)
  234. /*! 'Comfort Noise' (RFC3389) */
  235. #define AST_RTP_CN (1 << 1)
  236. /*! DTMF (Cisco Proprietary) */
  237. #define AST_RTP_CISCO_DTMF (1 << 2)
  238. /*! Maximum RTP-specific code */
  239. #define AST_RTP_MAX AST_RTP_CISCO_DTMF
  240. /*! Structure that represents a payload */
  241. struct ast_rtp_payload_type {
  242. /*! Is this an Asterisk value */
  243. int asterisk_format;
  244. /*! If asterisk_format is set, this is the internal
  245. * asterisk format represented by the payload */
  246. struct ast_format *format;
  247. /*! Actual internal RTP specific value of the payload */
  248. int rtp_code;
  249. /*! Actual payload number */
  250. int payload;
  251. };
  252. /* Common RTCP report types */
  253. /*! Sender Report */
  254. #define AST_RTP_RTCP_SR 200
  255. /*! Receiver Report */
  256. #define AST_RTP_RTCP_RR 201
  257. /*!
  258. * \since 12
  259. * \brief A report block within a SR/RR report */
  260. struct ast_rtp_rtcp_report_block {
  261. unsigned int source_ssrc; /*< The SSRC of the source for this report block */
  262. struct {
  263. unsigned short fraction; /*< The fraction of packets lost since last SR/RR */
  264. unsigned int packets; /*< The cumulative packets since the beginning */
  265. } lost_count; /*< Statistics regarding missed packets */
  266. unsigned int highest_seq_no; /*< Extended highest sequence number received */
  267. unsigned int ia_jitter; /*< Calculated interarrival jitter */
  268. unsigned int lsr; /*< The time the last SR report was received */
  269. unsigned int dlsr; /*< Delay in sending this report */
  270. };
  271. /*!
  272. * \since 12
  273. * \brief An object that represents data sent during a SR/RR RTCP report */
  274. struct ast_rtp_rtcp_report {
  275. unsigned short reception_report_count; /*< The number of report blocks */
  276. unsigned int ssrc; /*< Our SSRC */
  277. unsigned int type; /*< The type of report. 200=SR; 201=RR */
  278. struct {
  279. struct timeval ntp_timestamp; /*< Our NTP timestamp */
  280. unsigned int rtp_timestamp; /*< Our last RTP timestamp */
  281. unsigned int packet_count; /*< Number of packets sent */
  282. unsigned int octet_count; /*< Number of bytes sent */
  283. } sender_information; /*< Sender information for SR */
  284. /*! A dynamic array of report blocks. The number of elements is given by
  285. * \c reception_report_count.
  286. */
  287. struct ast_rtp_rtcp_report_block *report_block[0];
  288. };
  289. /*! Structure that represents statistics from an RTP instance */
  290. struct ast_rtp_instance_stats {
  291. /*! Number of packets transmitted */
  292. unsigned int txcount;
  293. /*! Number of packets received */
  294. unsigned int rxcount;
  295. /*! Jitter on transmitted packets */
  296. double txjitter;
  297. /*! Jitter on received packets */
  298. double rxjitter;
  299. /*! Maximum jitter on remote side */
  300. double remote_maxjitter;
  301. /*! Minimum jitter on remote side */
  302. double remote_minjitter;
  303. /*! Average jitter on remote side */
  304. double remote_normdevjitter;
  305. /*! Standard deviation jitter on remote side */
  306. double remote_stdevjitter;
  307. /*! Maximum jitter on local side */
  308. double local_maxjitter;
  309. /*! Minimum jitter on local side */
  310. double local_minjitter;
  311. /*! Average jitter on local side */
  312. double local_normdevjitter;
  313. /*! Standard deviation jitter on local side */
  314. double local_stdevjitter;
  315. /*! Number of transmitted packets lost */
  316. unsigned int txploss;
  317. /*! Number of received packets lost */
  318. unsigned int rxploss;
  319. /*! Maximum number of packets lost on remote side */
  320. double remote_maxrxploss;
  321. /*! Minimum number of packets lost on remote side */
  322. double remote_minrxploss;
  323. /*! Average number of packets lost on remote side */
  324. double remote_normdevrxploss;
  325. /*! Standard deviation packets lost on remote side */
  326. double remote_stdevrxploss;
  327. /*! Maximum number of packets lost on local side */
  328. double local_maxrxploss;
  329. /*! Minimum number of packets lost on local side */
  330. double local_minrxploss;
  331. /*! Average number of packets lost on local side */
  332. double local_normdevrxploss;
  333. /*! Standard deviation packets lost on local side */
  334. double local_stdevrxploss;
  335. /*! Total round trip time */
  336. double rtt;
  337. /*! Maximum round trip time */
  338. double maxrtt;
  339. /*! Minimum round trip time */
  340. double minrtt;
  341. /*! Average round trip time */
  342. double normdevrtt;
  343. /*! Standard deviation round trip time */
  344. double stdevrtt;
  345. /*! Our SSRC */
  346. unsigned int local_ssrc;
  347. /*! Their SSRC */
  348. unsigned int remote_ssrc;
  349. /*! The Asterisk channel's unique ID that owns this instance */
  350. char channel_uniqueid[MAX_CHANNEL_ID];
  351. /*! Number of octets transmitted */
  352. unsigned int txoctetcount;
  353. /*! Number of octets received */
  354. unsigned int rxoctetcount;
  355. };
  356. #define AST_RTP_STAT_SET(current_stat, combined, placement, value) \
  357. if (stat == current_stat || stat == AST_RTP_INSTANCE_STAT_ALL || (combined >= 0 && combined == stat)) { \
  358. placement = value; \
  359. if (stat == current_stat) { \
  360. return 0; \
  361. } \
  362. }
  363. #define AST_RTP_STAT_STRCPY(current_stat, combined, placement, value) \
  364. if (stat == current_stat || stat == AST_RTP_INSTANCE_STAT_ALL || (combined >= 0 && combined == stat)) { \
  365. ast_copy_string(placement, value, sizeof(placement)); \
  366. if (stat == current_stat) { \
  367. return 0; \
  368. } \
  369. }
  370. #define AST_RTP_STAT_TERMINATOR(combined) \
  371. if (stat == combined) { \
  372. return 0; \
  373. }
  374. /*! \brief ICE candidate types */
  375. enum ast_rtp_ice_candidate_type {
  376. AST_RTP_ICE_CANDIDATE_TYPE_HOST, /*!< ICE host candidate. A host candidate represents the actual local transport address in the host. */
  377. AST_RTP_ICE_CANDIDATE_TYPE_SRFLX, /*!< ICE server reflexive candidate, which represents the public mapped address of the local address. */
  378. AST_RTP_ICE_CANDIDATE_TYPE_RELAYED, /*!< ICE relayed candidate, which represents the address allocated in TURN server. */
  379. };
  380. /*! \brief ICE component types */
  381. enum ast_rtp_ice_component_type {
  382. AST_RTP_ICE_COMPONENT_RTP = 1,
  383. AST_RTP_ICE_COMPONENT_RTCP = 2,
  384. };
  385. /*! \brief ICE role during negotiation */
  386. enum ast_rtp_ice_role {
  387. AST_RTP_ICE_ROLE_CONTROLLED,
  388. AST_RTP_ICE_ROLE_CONTROLLING,
  389. };
  390. /*! \brief Structure for an ICE candidate */
  391. struct ast_rtp_engine_ice_candidate {
  392. char *foundation; /*!< Foundation identifier */
  393. enum ast_rtp_ice_component_type id; /*!< Component identifier */
  394. char *transport; /*!< Transport for the media */
  395. int priority; /*!< Priority which is used if multiple candidates can be used */
  396. struct ast_sockaddr address; /*!< Address of the candidate */
  397. struct ast_sockaddr relay_address; /*!< Relay address for the candidate */
  398. enum ast_rtp_ice_candidate_type type; /*!< Type of candidate */
  399. };
  400. /*! \brief Structure that represents the optional ICE support within an RTP engine */
  401. struct ast_rtp_engine_ice {
  402. /*! Callback for setting received authentication information */
  403. void (*set_authentication)(struct ast_rtp_instance *instance, const char *ufrag, const char *password);
  404. /*! Callback for adding a remote candidate */
  405. void (*add_remote_candidate)(struct ast_rtp_instance *instance, const struct ast_rtp_engine_ice_candidate *candidate);
  406. /*! Callback for starting ICE negotiation */
  407. void (*start)(struct ast_rtp_instance *instance);
  408. /*! Callback for stopping ICE support */
  409. void (*stop)(struct ast_rtp_instance *instance);
  410. /*! Callback for getting local username */
  411. const char *(*get_ufrag)(struct ast_rtp_instance *instance);
  412. /*! Callback for getting local password */
  413. const char *(*get_password)(struct ast_rtp_instance *instance);
  414. /*! Callback for getting local candidates */
  415. struct ao2_container *(*get_local_candidates)(struct ast_rtp_instance *instance);
  416. /*! Callback for telling the ICE support that it is talking to an ice-lite implementation */
  417. void (*ice_lite)(struct ast_rtp_instance *instance);
  418. /*! Callback for changing our role in negotiation */
  419. void (*set_role)(struct ast_rtp_instance *instance, enum ast_rtp_ice_role role);
  420. /*! Callback for requesting a TURN session */
  421. void (*turn_request)(struct ast_rtp_instance *instance, enum ast_rtp_ice_component_type component,
  422. enum ast_transport transport, const char *server, unsigned int port,
  423. const char *username, const char *password);
  424. /*! Callback to alter the number of ICE components on a session */
  425. void (*change_components)(struct ast_rtp_instance *instance, int num_components);
  426. };
  427. /*! \brief DTLS setup types */
  428. enum ast_rtp_dtls_setup {
  429. AST_RTP_DTLS_SETUP_ACTIVE, /*!< Endpoint is willing to inititate connections */
  430. AST_RTP_DTLS_SETUP_PASSIVE, /*!< Endpoint is willing to accept connections */
  431. AST_RTP_DTLS_SETUP_ACTPASS, /*!< Endpoint is willing to both accept and initiate connections */
  432. AST_RTP_DTLS_SETUP_HOLDCONN, /*!< Endpoint does not want the connection to be established right now */
  433. };
  434. /*! \brief DTLS connection states */
  435. enum ast_rtp_dtls_connection {
  436. AST_RTP_DTLS_CONNECTION_NEW, /*!< Endpoint wants to use a new connection */
  437. AST_RTP_DTLS_CONNECTION_EXISTING, /*!< Endpoint wishes to use existing connection */
  438. };
  439. /*! \brief DTLS fingerprint hashes */
  440. enum ast_rtp_dtls_hash {
  441. AST_RTP_DTLS_HASH_SHA256, /*!< SHA-256 fingerprint hash */
  442. AST_RTP_DTLS_HASH_SHA1, /*!< SHA-1 fingerprint hash */
  443. };
  444. /*! \brief DTLS verification settings */
  445. enum ast_rtp_dtls_verify {
  446. AST_RTP_DTLS_VERIFY_NONE = 0, /*!< Don't verify anything */
  447. AST_RTP_DTLS_VERIFY_FINGERPRINT = (1 << 0), /*!< Verify the fingerprint */
  448. AST_RTP_DTLS_VERIFY_CERTIFICATE = (1 << 1), /*!< Verify the certificate */
  449. };
  450. /*! \brief DTLS configuration structure */
  451. struct ast_rtp_dtls_cfg {
  452. unsigned int enabled:1; /*!< Whether DTLS support is enabled or not */
  453. unsigned int rekey; /*!< Interval at which to renegotiate and rekey - defaults to 0 (off) */
  454. enum ast_rtp_dtls_setup default_setup; /*!< Default setup type to use for outgoing */
  455. enum ast_srtp_suite suite; /*!< Crypto suite in use */
  456. enum ast_rtp_dtls_hash hash; /*!< Hash to use for fingerprint */
  457. enum ast_rtp_dtls_verify verify; /*!< What should be verified */
  458. char *certfile; /*!< Certificate file */
  459. char *pvtfile; /*!< Private key file */
  460. char *cipher; /*!< Cipher to use */
  461. char *cafile; /*!< Certificate authority file */
  462. char *capath; /*!< Path to certificate authority */
  463. };
  464. /*! \brief Structure that represents the optional DTLS SRTP support within an RTP engine */
  465. struct ast_rtp_engine_dtls {
  466. /*! Set the configuration of the DTLS support on the instance */
  467. int (*set_configuration)(struct ast_rtp_instance *instance, const struct ast_rtp_dtls_cfg *dtls_cfg);
  468. /*! Get if the DTLS SRTP support is active or not */
  469. int (*active)(struct ast_rtp_instance *instance);
  470. /*! Stop and terminate DTLS SRTP support */
  471. void (*stop)(struct ast_rtp_instance *instance);
  472. /*! Reset the connection and start fresh */
  473. void (*reset)(struct ast_rtp_instance *instance);
  474. /*! Get the current connection state */
  475. enum ast_rtp_dtls_connection (*get_connection)(struct ast_rtp_instance *instance);
  476. /*! Get the current setup state */
  477. enum ast_rtp_dtls_setup (*get_setup)(struct ast_rtp_instance *instance);
  478. /*! Set the remote setup state */
  479. void (*set_setup)(struct ast_rtp_instance *instance, enum ast_rtp_dtls_setup setup);
  480. /*! Set the remote fingerprint */
  481. void (*set_fingerprint)(struct ast_rtp_instance *instance, enum ast_rtp_dtls_hash hash, const char *fingerprint);
  482. /*! Get the local fingerprint hash type */
  483. enum ast_rtp_dtls_hash (*get_fingerprint_hash)(struct ast_rtp_instance *instance);
  484. /*! Get the local fingerprint */
  485. const char *(*get_fingerprint)(struct ast_rtp_instance *instance);
  486. };
  487. /*! Structure that represents an RTP stack (engine) */
  488. struct ast_rtp_engine {
  489. /*! Name of the RTP engine, used when explicitly requested */
  490. const char *name;
  491. /*! Module this RTP engine came from, used for reference counting */
  492. struct ast_module *mod;
  493. /*! Callback for setting up a new RTP instance */
  494. int (*new)(struct ast_rtp_instance *instance, struct ast_sched_context *sched, struct ast_sockaddr *sa, void *data);
  495. /*! Callback for destroying an RTP instance */
  496. int (*destroy)(struct ast_rtp_instance *instance);
  497. /*! Callback for writing out a frame */
  498. int (*write)(struct ast_rtp_instance *instance, struct ast_frame *frame);
  499. /*! Callback for stopping the RTP instance */
  500. void (*stop)(struct ast_rtp_instance *instance);
  501. /*! Callback for starting RFC2833 DTMF transmission */
  502. int (*dtmf_begin)(struct ast_rtp_instance *instance, char digit);
  503. /*! Callback for stopping RFC2833 DTMF transmission */
  504. int (*dtmf_end)(struct ast_rtp_instance *instance, char digit);
  505. int (*dtmf_end_with_duration)(struct ast_rtp_instance *instance, char digit, unsigned int duration);
  506. /*! Callback to indicate that we should update the marker bit */
  507. void (*update_source)(struct ast_rtp_instance *instance);
  508. /*! Callback to indicate that we should update the marker bit and ssrc */
  509. void (*change_source)(struct ast_rtp_instance *instance);
  510. /*! Callback for setting an extended RTP property */
  511. int (*extended_prop_set)(struct ast_rtp_instance *instance, int property, void *value);
  512. /*! Callback for getting an extended RTP property */
  513. void *(*extended_prop_get)(struct ast_rtp_instance *instance, int property);
  514. /*! Callback for setting an RTP property */
  515. void (*prop_set)(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value);
  516. /*! Callback for setting a payload. If asterisk is to be used, asterisk_format will be set, otherwise value in code is used. */
  517. void (*payload_set)(struct ast_rtp_instance *instance, int payload, int asterisk_format, struct ast_format *format, int code);
  518. /*! Callback for setting the remote address that RTP is to be sent to */
  519. void (*remote_address_set)(struct ast_rtp_instance *instance, struct ast_sockaddr *sa);
  520. /*! Callback for changing DTMF mode */
  521. int (*dtmf_mode_set)(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode);
  522. /*! Callback for getting DTMF mode */
  523. enum ast_rtp_dtmf_mode (*dtmf_mode_get)(struct ast_rtp_instance *instance);
  524. /*! Callback for retrieving statistics */
  525. int (*get_stat)(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat);
  526. /*! Callback for setting QoS values */
  527. int (*qos)(struct ast_rtp_instance *instance, int tos, int cos, const char *desc);
  528. /*! Callback for retrieving a file descriptor to poll on, not always required */
  529. int (*fd)(struct ast_rtp_instance *instance, int rtcp);
  530. /*! Callback for initializing RED support */
  531. int (*red_init)(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations);
  532. /*! Callback for buffering a frame using RED */
  533. int (*red_buffer)(struct ast_rtp_instance *instance, struct ast_frame *frame);
  534. /*! Callback for reading a frame from the RTP engine */
  535. struct ast_frame *(*read)(struct ast_rtp_instance *instance, int rtcp);
  536. /*! Callback to locally bridge two RTP instances */
  537. int (*local_bridge)(struct ast_rtp_instance *instance0, struct ast_rtp_instance *instance1);
  538. /*! Callback to set the read format */
  539. int (*set_read_format)(struct ast_rtp_instance *instance, struct ast_format *format);
  540. /*! Callback to set the write format */
  541. int (*set_write_format)(struct ast_rtp_instance *instance, struct ast_format *format);
  542. /*! Callback to make two instances compatible */
  543. int (*make_compatible)(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1);
  544. /*! Callback to see if two instances are compatible with DTMF */
  545. int (*dtmf_compatible)(struct ast_channel *chan0, struct ast_rtp_instance *instance0, struct ast_channel *chan1, struct ast_rtp_instance *instance1);
  546. /*! Callback to indicate that packets will now flow */
  547. int (*activate)(struct ast_rtp_instance *instance);
  548. /*! Callback to request that the RTP engine send a STUN BIND request */
  549. void (*stun_request)(struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username);
  550. /*! Callback to get the transcodeable formats supported. result returned in ast_format_cap *result */
  551. 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);
  552. /*! Callback to send CNG */
  553. int (*sendcng)(struct ast_rtp_instance *instance, int level);
  554. /*! Callback to pointer for optional ICE support */
  555. struct ast_rtp_engine_ice *ice;
  556. /*! Callback to pointer for optional DTLS SRTP support */
  557. struct ast_rtp_engine_dtls *dtls;
  558. /*! Linked list information */
  559. AST_RWLIST_ENTRY(ast_rtp_engine) entry;
  560. };
  561. /*! Structure that represents codec and packetization information */
  562. struct ast_rtp_codecs {
  563. /*! Payloads present */
  564. AST_VECTOR(, struct ast_rtp_payload_type *) payloads;
  565. /*! The framing for this media session */
  566. unsigned int framing;
  567. /*! RW lock that protects elements in this structure */
  568. ast_rwlock_t codecs_lock;
  569. };
  570. #define AST_RTP_CODECS_NULL_INIT \
  571. { .payloads = { 0, }, .framing = 0, .codecs_lock = AST_RWLOCK_INIT_VALUE, }
  572. /*! Structure that represents the glue that binds an RTP instance to a channel */
  573. struct ast_rtp_glue {
  574. /*! Name of the channel driver that this glue is responsible for */
  575. const char *type;
  576. /*! Module that the RTP glue came from */
  577. struct ast_module *mod;
  578. /*!
  579. * \brief Callback for retrieving the RTP instance carrying audio
  580. * \note This function increases the reference count on the returned RTP instance.
  581. */
  582. enum ast_rtp_glue_result (*get_rtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance);
  583. /*!
  584. * \brief Used to prevent two channels from remotely bridging audio rtp if the channel tech has a
  585. * reason for prohibiting it based on qualities that need to be compared from both channels.
  586. * \note This function may be NULL for a given channel driver. This should be accounted for and if that is the case, this function is not used.
  587. */
  588. int (*allow_rtp_remote)(struct ast_channel *chan1, struct ast_rtp_instance *instance);
  589. /*!
  590. * \brief Callback for retrieving the RTP instance carrying video
  591. * \note This function increases the reference count on the returned RTP instance.
  592. * \note This function may be NULL for a given channel driver. This should be accounted for and if that is the case, this function is not used.
  593. */
  594. enum ast_rtp_glue_result (*get_vrtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance);
  595. /*!
  596. * \brief Used to prevent two channels from remotely bridging video rtp if the channel tech has a
  597. * reason for prohibiting it based on qualities that need to be compared from both channels.
  598. * \note This function may be NULL for a given channel driver. This should be accounted for and if that is the case, this function is not used.
  599. */
  600. int (*allow_vrtp_remote)(struct ast_channel *chan1, struct ast_rtp_instance *instance);
  601. /*!
  602. * \brief Callback for retrieving the RTP instance carrying text
  603. * \note This function increases the reference count on the returned RTP instance.
  604. * \note This function may be NULL for a given channel driver. This should be accounted for and if that is the case, this function is not used.
  605. */
  606. enum ast_rtp_glue_result (*get_trtp_info)(struct ast_channel *chan, struct ast_rtp_instance **instance);
  607. /*! Callback for updating the destination that the remote side should send RTP to */
  608. 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);
  609. /*!
  610. * \brief Callback for retrieving codecs that the channel can do. Result returned in result_cap.
  611. * \note This function may be NULL for a given channel driver. This should be accounted for and if that is the case, this function is not used.
  612. */
  613. void (*get_codec)(struct ast_channel *chan, struct ast_format_cap *result_cap);
  614. /*! Linked list information */
  615. AST_RWLIST_ENTRY(ast_rtp_glue) entry;
  616. };
  617. /*!
  618. * \brief Allocation routine for \ref ast_rtp_payload_type
  619. *
  620. * \retval NULL on error
  621. * \retval An ao2 ref counted \c ast_rtp_payload_type on success.
  622. *
  623. * \note The \c ast_rtp_payload_type returned by this function is an
  624. * ao2 ref counted object.
  625. *
  626. */
  627. struct ast_rtp_payload_type *ast_rtp_engine_alloc_payload_type(void);
  628. #define ast_rtp_engine_register(engine) ast_rtp_engine_register2(engine, ast_module_info->self)
  629. /*!
  630. * \brief Register an RTP engine
  631. *
  632. * \param engine Structure of the RTP engine to register
  633. * \param module Module that the RTP engine is part of
  634. *
  635. * \retval 0 success
  636. * \retval -1 failure
  637. *
  638. * Example usage:
  639. *
  640. * \code
  641. * ast_rtp_engine_register2(&example_rtp_engine, NULL);
  642. * \endcode
  643. *
  644. * This registers the RTP engine declared as example_rtp_engine with the RTP engine core, but does not
  645. * associate a module with it.
  646. *
  647. * \note It is recommended that you use the ast_rtp_engine_register macro so that the module is
  648. * associated with the RTP engine and use counting is performed.
  649. *
  650. * \since 1.8
  651. */
  652. int ast_rtp_engine_register2(struct ast_rtp_engine *engine, struct ast_module *module);
  653. /*!
  654. * \brief Unregister an RTP engine
  655. *
  656. * \param engine Structure of the RTP engine to unregister
  657. *
  658. * \retval 0 success
  659. * \retval -1 failure
  660. *
  661. * Example usage:
  662. *
  663. * \code
  664. * ast_rtp_engine_unregister(&example_rtp_engine);
  665. * \endcode
  666. *
  667. * This unregisters the RTP engine declared as example_rtp_engine from the RTP engine core. If a module
  668. * reference was provided when it was registered then this will only be called once the RTP engine is no longer in use.
  669. *
  670. * \since 1.8
  671. */
  672. int ast_rtp_engine_unregister(struct ast_rtp_engine *engine);
  673. int ast_rtp_engine_register_srtp(struct ast_srtp_res *srtp_res, struct ast_srtp_policy_res *policy_res);
  674. void ast_rtp_engine_unregister_srtp(void);
  675. int ast_rtp_engine_srtp_is_registered(void);
  676. #define ast_rtp_glue_register(glue) ast_rtp_glue_register2(glue, ast_module_info->self)
  677. /*!
  678. * \brief Register RTP glue
  679. *
  680. * \param glue The glue to register
  681. * \param module Module that the RTP glue is part of
  682. *
  683. * \retval 0 success
  684. * \retval -1 failure
  685. *
  686. * Example usage:
  687. *
  688. * \code
  689. * ast_rtp_glue_register2(&example_rtp_glue, NULL);
  690. * \endcode
  691. *
  692. * This registers the RTP glue declared as example_rtp_glue with the RTP engine core, but does not
  693. * associate a module with it.
  694. *
  695. * \note It is recommended that you use the ast_rtp_glue_register macro so that the module is
  696. * associated with the RTP glue and use counting is performed.
  697. *
  698. * \since 1.8
  699. */
  700. int ast_rtp_glue_register2(struct ast_rtp_glue *glue, struct ast_module *module);
  701. /*!
  702. * \brief Unregister RTP glue
  703. *
  704. * \param glue The glue to unregister
  705. *
  706. * \retval 0 success
  707. * \retval -1 failure
  708. *
  709. * Example usage:
  710. *
  711. * \code
  712. * ast_rtp_glue_unregister(&example_rtp_glue);
  713. * \endcode
  714. *
  715. * This unregisters the RTP glue declared as example_rtp_gkue from the RTP engine core. If a module
  716. * reference was provided when it was registered then this will only be called once the RTP engine is no longer in use.
  717. *
  718. * \since 1.8
  719. */
  720. int ast_rtp_glue_unregister(struct ast_rtp_glue *glue);
  721. /*!
  722. * \brief Create a new RTP instance
  723. *
  724. * \param engine_name Name of the engine to use for the RTP instance
  725. * \param sched Scheduler context that the RTP engine may want to use
  726. * \param sa Address we want to bind to
  727. * \param data Unique data for the engine
  728. *
  729. * \retval non-NULL success
  730. * \retval NULL failure
  731. *
  732. * Example usage:
  733. *
  734. * \code
  735. * struct ast_rtp_instance *instance = NULL;
  736. * instance = ast_rtp_instance_new(NULL, sched, &sin, NULL);
  737. * \endcode
  738. *
  739. * This creates a new RTP instance using the default engine and asks the RTP engine to bind to the address given
  740. * in the address structure.
  741. *
  742. * \note The RTP engine does not have to use the address provided when creating an RTP instance. It may choose to use
  743. * another depending on it's own configuration.
  744. *
  745. * \since 1.8
  746. */
  747. struct ast_rtp_instance *ast_rtp_instance_new(const char *engine_name,
  748. struct ast_sched_context *sched, const struct ast_sockaddr *sa,
  749. void *data);
  750. /*!
  751. * \brief Destroy an RTP instance
  752. *
  753. * \param instance The RTP instance to destroy
  754. *
  755. * \retval 0 success
  756. * \retval -1 failure
  757. *
  758. * Example usage:
  759. *
  760. * \code
  761. * ast_rtp_instance_destroy(instance);
  762. * \endcode
  763. *
  764. * This destroys the RTP instance pointed to by instance. Once this function returns instance no longer points to valid
  765. * memory and may not be used again.
  766. *
  767. * \since 1.8
  768. */
  769. int ast_rtp_instance_destroy(struct ast_rtp_instance *instance);
  770. /*!
  771. * \brief Set the data portion of an RTP instance
  772. *
  773. * \param instance The RTP instance to manipulate
  774. * \param data Pointer to data
  775. *
  776. * Example usage:
  777. *
  778. * \code
  779. * ast_rtp_instance_set_data(instance, blob);
  780. * \endcode
  781. *
  782. * This sets the data pointer on the RTP instance pointed to by 'instance' to
  783. * blob.
  784. *
  785. * \since 1.8
  786. */
  787. void ast_rtp_instance_set_data(struct ast_rtp_instance *instance, void *data);
  788. /*!
  789. * \brief Get the data portion of an RTP instance
  790. *
  791. * \param instance The RTP instance we want the data portion from
  792. *
  793. * Example usage:
  794. *
  795. * \code
  796. * struct *blob = ast_rtp_instance_get_data(instance);
  797. ( \endcode
  798. *
  799. * This gets the data pointer on the RTP instance pointed to by 'instance'.
  800. *
  801. * \since 1.8
  802. */
  803. void *ast_rtp_instance_get_data(struct ast_rtp_instance *instance);
  804. /*!
  805. * \brief Send a frame out over RTP
  806. *
  807. * \param instance The RTP instance to send frame out on
  808. * \param frame the frame to send out
  809. *
  810. * \retval 0 success
  811. * \retval -1 failure
  812. *
  813. * Example usage:
  814. *
  815. * \code
  816. * ast_rtp_instance_write(instance, frame);
  817. * \endcode
  818. *
  819. * This gives the frame pointed to by frame to the RTP engine being used for the instance
  820. * and asks that it be transmitted to the current remote address set on the RTP instance.
  821. *
  822. * \since 1.8
  823. */
  824. int ast_rtp_instance_write(struct ast_rtp_instance *instance, struct ast_frame *frame);
  825. /*!
  826. * \brief Receive a frame over RTP
  827. *
  828. * \param instance The RTP instance to receive frame on
  829. * \param rtcp Whether to read in RTCP or not
  830. *
  831. * \retval non-NULL success
  832. * \retval NULL failure
  833. *
  834. * Example usage:
  835. *
  836. * \code
  837. * struct ast_frame *frame;
  838. * frame = ast_rtp_instance_read(instance, 0);
  839. * \endcode
  840. *
  841. * This asks the RTP engine to read in RTP from the instance and return it as an Asterisk frame.
  842. *
  843. * \since 1.8
  844. */
  845. struct ast_frame *ast_rtp_instance_read(struct ast_rtp_instance *instance, int rtcp);
  846. /*!
  847. * \brief Set the incoming source address of the remote endpoint that we are sending RTP to
  848. *
  849. * This sets the incoming source address the engine is sending RTP to. Usually this
  850. * will be the same as the requested target address, however in the case where
  851. * the engine "learns" the address (for instance, symmetric RTP enabled) this
  852. * will then contain the learned address.
  853. *
  854. * \param instance The RTP instance to change the address on
  855. * \param address Address to set it to
  856. *
  857. * \retval 0 success
  858. * \retval -1 failure
  859. */
  860. int ast_rtp_instance_set_incoming_source_address(struct ast_rtp_instance *instance,
  861. const struct ast_sockaddr *address);
  862. /*!
  863. * \brief Set the requested target address of the remote endpoint
  864. *
  865. * This should always be the address of the remote endpoint. Consequently, this can differ
  866. * from the address the engine is sending RTP to. However, usually they will be the same
  867. * except in some circumstances (for instance when the engine "learns" the address if
  868. * symmetric RTP is enabled).
  869. *
  870. * \param instance The RTP instance to change the address on
  871. * \param address Address to set it to
  872. *
  873. * \retval 0 success
  874. * \retval -1 failure
  875. */
  876. int ast_rtp_instance_set_requested_target_address(struct ast_rtp_instance *instance,
  877. const struct ast_sockaddr *address);
  878. /*!
  879. * \brief Set the address of the remote endpoint that we are sending RTP to
  880. *
  881. * \param instance The RTP instance to change the address on
  882. * \param address Address to set it to
  883. *
  884. * \retval 0 success
  885. * \retval -1 failure
  886. *
  887. * Example usage:
  888. *
  889. * \code
  890. * ast_rtp_instance_set_remote_address(instance, &sin);
  891. * \endcode
  892. *
  893. * This changes the remote address that RTP will be sent to on instance to the address given in the sin
  894. * structure.
  895. *
  896. * \since 1.8
  897. */
  898. #define ast_rtp_instance_set_remote_address(instance, address) \
  899. ast_rtp_instance_set_requested_target_address((instance), (address))
  900. /*!
  901. * \brief Set the address that we are expecting to receive RTP on
  902. *
  903. * \param instance The RTP instance to change the address on
  904. * \param address Address to set it to
  905. *
  906. * \retval 0 success
  907. * \retval -1 failure
  908. *
  909. * Example usage:
  910. *
  911. * \code
  912. * ast_rtp_instance_set_local_address(instance, &sin);
  913. * \endcode
  914. *
  915. * This changes the local address that RTP is expected on to the address given in the sin
  916. * structure.
  917. *
  918. * \since 1.8
  919. */
  920. int ast_rtp_instance_set_local_address(struct ast_rtp_instance *instance,
  921. const struct ast_sockaddr *address);
  922. /*!
  923. * \brief Get the local address that we are expecting RTP on
  924. *
  925. * \param instance The RTP instance to get the address from
  926. * \param address The variable to store the address in
  927. *
  928. * Example usage:
  929. *
  930. * \code
  931. * struct ast_sockaddr address;
  932. * ast_rtp_instance_get_local_address(instance, &address);
  933. * \endcode
  934. *
  935. * This gets the local address that we are expecting RTP on and stores it in the 'address' structure.
  936. *
  937. * \since 1.8
  938. */
  939. void ast_rtp_instance_get_local_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address);
  940. /*!
  941. * \brief Get the address of the local endpoint that we are sending RTP to, comparing its address to another
  942. *
  943. * \param instance The instance that we want to get the local address for
  944. * \param address An initialized address that may be overwritten if the local address is different
  945. *
  946. * \retval 0 address was not changed
  947. * \retval 1 address was changed
  948. * Example usage:
  949. *
  950. * \code
  951. * struct ast_sockaddr address;
  952. * int ret;
  953. * ret = ast_rtp_instance_get_and_cmp_local_address(instance, &address);
  954. * \endcode
  955. *
  956. * This retrieves the current local address set on the instance pointed to by instance and puts the value
  957. * into the address structure.
  958. *
  959. * \since 1.8
  960. */
  961. int ast_rtp_instance_get_and_cmp_local_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address);
  962. /*!
  963. * \brief Get the incoming source address of the remote endpoint
  964. *
  965. * This returns the remote address the engine is sending RTP to. Usually this
  966. * will be the same as the requested target address, however in the case where
  967. * the engine "learns" the address (for instance, symmetric RTP enabled) this
  968. * will then contain the learned address.
  969. *
  970. * \param instance The instance that we want to get the incoming source address for
  971. * \param address A structure to put the address into
  972. */
  973. void ast_rtp_instance_get_incoming_source_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address);
  974. /*!
  975. * \brief Get the requested target address of the remote endpoint
  976. *
  977. * This returns the explicitly set address of a remote endpoint. Meaning this won't change unless
  978. * specifically told to change. In most cases this should be the same as the incoming source
  979. * address, except in cases where the engine "learns" the address in which case this and the
  980. * incoming source address might differ.
  981. *
  982. * \param instance The instance that we want to get the requested target address for
  983. * \param address A structure to put the address into
  984. */
  985. void ast_rtp_instance_get_requested_target_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address);
  986. /*!
  987. * \brief Get the address of the remote endpoint that we are sending RTP to
  988. *
  989. * \param instance The instance that we want to get the remote address for
  990. * \param address A structure to put the address into
  991. *
  992. * Example usage:
  993. *
  994. * \code
  995. * struct ast_sockaddr address;
  996. * ast_rtp_instance_get_remote_address(instance, &address);
  997. * \endcode
  998. *
  999. * This retrieves the current remote address set on the instance pointed to by instance and puts the value
  1000. * into the address structure.
  1001. *
  1002. * \since 1.8
  1003. */
  1004. #define ast_rtp_instance_get_remote_address(instance, address) \
  1005. ast_rtp_instance_get_incoming_source_address((instance), (address))
  1006. /*!
  1007. * \brief Get the requested target address of the remote endpoint and
  1008. * compare it to the given address
  1009. *
  1010. * \param instance The instance that we want to get the remote address for
  1011. * \param address An initialized address that may be overwritten addresses differ
  1012. *
  1013. * \retval 0 address was not changed
  1014. * \retval 1 address was changed
  1015. */
  1016. int ast_rtp_instance_get_and_cmp_requested_target_address(struct ast_rtp_instance *instance, struct ast_sockaddr *address);
  1017. /*!
  1018. * \brief Get the address of the remote endpoint that we are sending RTP to, comparing its address to another
  1019. *
  1020. * \param instance The instance that we want to get the remote address for
  1021. * \param address An initialized address that may be overwritten if the remote address is different
  1022. *
  1023. * \retval 0 address was not changed
  1024. * \retval 1 address was changed
  1025. * Example usage:
  1026. *
  1027. * \code
  1028. * struct ast_sockaddr address;
  1029. * int ret;
  1030. * ret = ast_rtp_instance_get_and_cmp_remote_address(instance, &address);
  1031. * \endcode
  1032. *
  1033. * This retrieves the current remote address set on the instance pointed to by instance and puts the value
  1034. * into the address structure.
  1035. *
  1036. * \since 1.8
  1037. */
  1038. #define ast_rtp_instance_get_and_cmp_remote_address(instance, address) \
  1039. ast_rtp_instance_get_and_cmp_requested_target_address((instance), (address))
  1040. /*!
  1041. * \brief Set the value of an RTP instance extended property
  1042. *
  1043. * \param instance The RTP instance to set the extended property on
  1044. * \param property The extended property to set
  1045. * \param value The value to set the extended property to
  1046. *
  1047. * \since 1.8
  1048. */
  1049. void ast_rtp_instance_set_extended_prop(struct ast_rtp_instance *instance, int property, void *value);
  1050. /*!
  1051. * \brief Get the value of an RTP instance extended property
  1052. *
  1053. * \param instance The RTP instance to get the extended property on
  1054. * \param property The extended property to get
  1055. *
  1056. * \since 1.8
  1057. */
  1058. void *ast_rtp_instance_get_extended_prop(struct ast_rtp_instance *instance, int property);
  1059. /*!
  1060. * \brief Set the value of an RTP instance property
  1061. *
  1062. * \param instance The RTP instance to set the property on
  1063. * \param property The property to modify
  1064. * \param value The value to set the property to
  1065. *
  1066. * Example usage:
  1067. *
  1068. * \code
  1069. * ast_rtp_instance_set_prop(instance, AST_RTP_PROPERTY_NAT, 1);
  1070. * \endcode
  1071. *
  1072. * This enables the AST_RTP_PROPERTY_NAT property on the instance pointed to by instance.
  1073. *
  1074. * \since 1.8
  1075. */
  1076. void ast_rtp_instance_set_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property, int value);
  1077. /*!
  1078. * \brief Get the value of an RTP instance property
  1079. *
  1080. * \param instance The RTP instance to get the property from
  1081. * \param property The property to get
  1082. *
  1083. * \retval Current value of the property
  1084. *
  1085. * Example usage:
  1086. *
  1087. * \code
  1088. * ast_rtp_instance_get_prop(instance, AST_RTP_PROPERTY_NAT);
  1089. * \endcode
  1090. *
  1091. * This returns the current value of the NAT property on the instance pointed to by instance.
  1092. *
  1093. * \since 1.8
  1094. */
  1095. int ast_rtp_instance_get_prop(struct ast_rtp_instance *instance, enum ast_rtp_property property);
  1096. /*!
  1097. * \brief Get the codecs structure of an RTP instance
  1098. *
  1099. * \param instance The RTP instance to get the codecs structure from
  1100. *
  1101. * Example usage:
  1102. *
  1103. * \code
  1104. * struct ast_rtp_codecs *codecs = ast_rtp_instance_get_codecs(instance);
  1105. * \endcode
  1106. *
  1107. * This gets the codecs structure on the RTP instance pointed to by 'instance'.
  1108. *
  1109. * \since 1.8
  1110. */
  1111. struct ast_rtp_codecs *ast_rtp_instance_get_codecs(struct ast_rtp_instance *instance);
  1112. /*!
  1113. * \brief Initialize an RTP codecs structure
  1114. *
  1115. * \param codecs The codecs structure to initialize
  1116. *
  1117. * \retval 0 success
  1118. * \retval -1 failure
  1119. *
  1120. * Example usage:
  1121. *
  1122. * \code
  1123. * struct ast_rtp_codecs codecs;
  1124. * ast_rtp_codecs_payloads_initialize(&codecs);
  1125. * \endcode
  1126. *
  1127. * \since 11
  1128. */
  1129. int ast_rtp_codecs_payloads_initialize(struct ast_rtp_codecs *codecs);
  1130. /*!
  1131. * \brief Destroy the contents of an RTP codecs structure (but not the structure itself)
  1132. *
  1133. * \param codecs The codecs structure to destroy the contents of
  1134. *
  1135. * Example usage:
  1136. *
  1137. * \code
  1138. * struct ast_rtp_codecs codecs;
  1139. * ast_rtp_codecs_payloads_destroy(&codecs);
  1140. * \endcode
  1141. *
  1142. * \since 11
  1143. */
  1144. void ast_rtp_codecs_payloads_destroy(struct ast_rtp_codecs *codecs);
  1145. /*!
  1146. * \brief Clear payload information from an RTP instance
  1147. *
  1148. * \param codecs The codecs structure that payloads will be cleared from
  1149. * \param instance Optionally the instance that the codecs structure belongs to
  1150. *
  1151. * Example usage:
  1152. *
  1153. * \code
  1154. * struct ast_rtp_codecs codecs;
  1155. * ast_rtp_codecs_payloads_clear(&codecs, NULL);
  1156. * \endcode
  1157. *
  1158. * This clears the codecs structure and puts it into a pristine state.
  1159. *
  1160. * \since 1.8
  1161. */
  1162. void ast_rtp_codecs_payloads_clear(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance);
  1163. /*!
  1164. * \brief Copy payload information from one RTP instance to another
  1165. *
  1166. * \param src The source codecs structure
  1167. * \param dest The destination codecs structure that the values from src will be copied to
  1168. * \param instance Optionally the instance that the dst codecs structure belongs to
  1169. *
  1170. * Example usage:
  1171. *
  1172. * \code
  1173. * ast_rtp_codecs_payloads_copy(&codecs0, &codecs1, NULL);
  1174. * \endcode
  1175. *
  1176. * This copies the payloads from the codecs0 structure to the codecs1 structure, overwriting any current values.
  1177. *
  1178. * \since 1.8
  1179. */
  1180. void ast_rtp_codecs_payloads_copy(struct ast_rtp_codecs *src, struct ast_rtp_codecs *dest, struct ast_rtp_instance *instance);
  1181. /*!
  1182. * \brief Record payload information that was seen in an m= SDP line
  1183. *
  1184. * \param codecs The codecs structure to muck with
  1185. * \param instance Optionally the instance that the codecs structure belongs to
  1186. * \param payload Numerical payload that was seen in the m= SDP line
  1187. *
  1188. * Example usage:
  1189. *
  1190. * \code
  1191. * ast_rtp_codecs_payloads_set_m_type(&codecs, NULL, 0);
  1192. * \endcode
  1193. *
  1194. * This records that the numerical payload '0' was seen in the codecs structure.
  1195. *
  1196. * \since 1.8
  1197. */
  1198. void ast_rtp_codecs_payloads_set_m_type(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload);
  1199. /*!
  1200. * \brief Record payload information that was seen in an a=rtpmap: SDP line
  1201. *
  1202. * \param codecs The codecs structure to muck with
  1203. * \param instance Optionally the instance that the codecs structure belongs to
  1204. * \param payload Numerical payload that was seen in the a=rtpmap: SDP line
  1205. * \param mimetype The string mime type that was seen
  1206. * \param mimesubtype The strin mime sub type that was seen
  1207. * \param options Optional options that may change the behavior of this specific payload
  1208. *
  1209. * \retval 0 success
  1210. * \retval -1 failure, invalid payload numbe
  1211. * \retval -2 failure, unknown mimetype
  1212. *
  1213. * Example usage:
  1214. *
  1215. * \code
  1216. * ast_rtp_codecs_payloads_set_rtpmap_type(&codecs, NULL, 0, "audio", "PCMU", 0);
  1217. * \endcode
  1218. *
  1219. * This records that the numerical payload '0' was seen with mime type 'audio' and sub mime type 'PCMU' in the codecs structure.
  1220. *
  1221. * \since 1.8
  1222. */
  1223. 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);
  1224. /*!
  1225. * \brief Set payload type to a known MIME media type for a codec with a specific sample rate
  1226. *
  1227. * \param codecs RTP structure to modify
  1228. * \param instance Optionally the instance that the codecs structure belongs to
  1229. * \param pt Payload type entry to modify
  1230. * \param mimetype top-level MIME type of media stream (typically "audio", "video", "text", etc.)
  1231. * \param mimesubtype MIME subtype of media stream (typically a codec name)
  1232. * \param options Zero or more flags from the ast_rtp_options enum
  1233. * \param sample_rate The sample rate of the media stream
  1234. *
  1235. * This function 'fills in' an entry in the list of possible formats for
  1236. * a media stream associated with an RTP structure.
  1237. *
  1238. * \retval 0 on success
  1239. * \retval -1 if the payload type is out of range
  1240. * \retval -2 if the mimeType/mimeSubtype combination was not found
  1241. *
  1242. * \since 1.8
  1243. */
  1244. int ast_rtp_codecs_payloads_set_rtpmap_type_rate(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int pt,
  1245. char *mimetype, char *mimesubtype,
  1246. enum ast_rtp_options options,
  1247. unsigned int sample_rate);
  1248. /*!
  1249. * \brief Remove payload information
  1250. *
  1251. * \param codecs The codecs structure to muck with
  1252. * \param instance Optionally the instance that the codecs structure belongs to
  1253. * \param payload Numerical payload to unset
  1254. *
  1255. * Example usage:
  1256. *
  1257. * \code
  1258. * ast_rtp_codecs_payloads_unset(&codecs, NULL, 0);
  1259. * \endcode
  1260. *
  1261. * This clears the payload '0' from the codecs structure. It will be as if it was never set.
  1262. *
  1263. * \since 1.8
  1264. */
  1265. void ast_rtp_codecs_payloads_unset(struct ast_rtp_codecs *codecs, struct ast_rtp_instance *instance, int payload);
  1266. /*!
  1267. * \brief Determine the type of RTP stream media from the codecs mapped.
  1268. * \since 13.19.0
  1269. *
  1270. * \param codecs Codecs structure to look in
  1271. *
  1272. * \return Media type or AST_MEDIA_TYPE_UNKNOWN if no codecs mapped.
  1273. */
  1274. enum ast_media_type ast_rtp_codecs_get_stream_type(struct ast_rtp_codecs *codecs);
  1275. /*!
  1276. * \brief Retrieve payload information by payload
  1277. *
  1278. * \param codecs Codecs structure to look in
  1279. * \param payload Numerical payload to look up
  1280. *
  1281. * \retval Payload information.
  1282. * \retval NULL if payload does not exist.
  1283. *
  1284. * \note The payload returned by this function has its reference count increased.
  1285. * Callers are responsible for decrementing the reference count.
  1286. *
  1287. * Example usage:
  1288. *
  1289. * \code
  1290. * struct ast_rtp_payload_type *payload_type;
  1291. * payload_type = ast_rtp_codecs_get_payload(&codecs, 0);
  1292. * \endcode
  1293. *
  1294. * This looks up the information for payload '0' from the codecs structure.
  1295. */
  1296. struct ast_rtp_payload_type *ast_rtp_codecs_get_payload(struct ast_rtp_codecs *codecs, int payload);
  1297. /*!
  1298. * \brief Update the format associated with a payload in a codecs structure
  1299. *
  1300. * \param codecs Codecs structure to operate on
  1301. * \param payload Numerical payload to look up
  1302. * \param format The format to replace the existing one
  1303. *
  1304. * \retval 0 success
  1305. * \retval -1 failure
  1306. *
  1307. * \since 13
  1308. */
  1309. int ast_rtp_codecs_payload_replace_format(struct ast_rtp_codecs *codecs, int payload, struct ast_format *format);
  1310. /*!
  1311. * \brief Retrieve the actual ast_format stored on the codecs structure for a specific payload
  1312. *
  1313. * \param codecs Codecs structure to look in
  1314. * \param payload Numerical payload to look up
  1315. *
  1316. * \retval pointer to format structure on success
  1317. * \retval NULL on failure
  1318. *
  1319. * \note The format returned by this function has its reference count increased.
  1320. * Callers are responsible for decrementing the reference count.
  1321. *
  1322. * \since 10.0
  1323. */
  1324. struct ast_format *ast_rtp_codecs_get_payload_format(struct ast_rtp_codecs *codecs, int payload);
  1325. /*!
  1326. * \brief Set the framing used for a set of codecs
  1327. *
  1328. * \param codecs Codecs structure to set framing on
  1329. * \param framing The framing value to set on the codecs
  1330. *
  1331. * \since 13.0.0
  1332. */
  1333. void ast_rtp_codecs_set_framing(struct ast_rtp_codecs *codecs, unsigned int framing);
  1334. /*!
  1335. * \brief Get the framing used for a set of codecs
  1336. *
  1337. * \param codecs Codecs structure to get the framing from
  1338. *
  1339. * \retval The framing to be used for the media stream associated with these codecs
  1340. *
  1341. * \since 13.0.0
  1342. */
  1343. unsigned int ast_rtp_codecs_get_framing(struct ast_rtp_codecs *codecs);
  1344. /*!
  1345. * \brief Get the sample rate associated with known RTP payload types
  1346. *
  1347. * \param asterisk_format True if the value in format is to be used.
  1348. * \param format An asterisk format
  1349. * \param code from AST_RTP list
  1350. *
  1351. * \return the sample rate if the format was found, zero if it was not found
  1352. *
  1353. * \since 1.8
  1354. */
  1355. unsigned int ast_rtp_lookup_sample_rate2(int asterisk_format, struct ast_format *format, int code);
  1356. /*!
  1357. * \brief Retrieve all formats that were found
  1358. *
  1359. * \param codecs Codecs structure to look in
  1360. * \param astformats A capabilities structure to put the Asterisk formats in.
  1361. * \param nonastformats An integer to put the non-Asterisk formats in
  1362. *
  1363. * Example usage:
  1364. *
  1365. * \code
  1366. * struct ast_format_cap *astformats = ast_format_cap_alloc_nolock()
  1367. * int nonastformats;
  1368. * ast_rtp_codecs_payload_formats(&codecs, astformats, &nonastformats);
  1369. * \endcode
  1370. *
  1371. * This retrieves all the formats known about in the codecs structure and puts the Asterisk ones in the integer
  1372. * pointed to by astformats and the non-Asterisk ones in the integer pointed to by nonastformats.
  1373. *
  1374. * \since 1.8
  1375. */
  1376. void ast_rtp_codecs_payload_formats(struct ast_rtp_codecs *codecs, struct ast_format_cap *astformats, int *nonastformats);
  1377. /*!
  1378. * \brief Retrieve a payload based on whether it is an Asterisk format and the code
  1379. *
  1380. * \param codecs Codecs structure to look in
  1381. * \param asterisk_format Non-zero if the given Asterisk format is present
  1382. * \param format Asterisk format to look for
  1383. * \param code The format to look for
  1384. *
  1385. * \retval Numerical payload
  1386. *
  1387. * Example usage:
  1388. *
  1389. * \code
  1390. * int payload = ast_rtp_codecs_payload_code(&codecs, 1, ast_format_set(&tmp_fmt, AST_FORMAT_ULAW, 0), 0);
  1391. * \endcode
  1392. *
  1393. * This looks for the numerical payload for ULAW in the codecs structure.
  1394. *
  1395. * \since 1.8
  1396. */
  1397. int ast_rtp_codecs_payload_code(struct ast_rtp_codecs *codecs, int asterisk_format, const struct ast_format *format, int code);
  1398. /*!
  1399. * \brief Search for a payload code in the ast_rtp_codecs structure
  1400. *
  1401. * \param codecs Codecs structure to look in
  1402. * \param code The format to look for
  1403. *
  1404. * \retval Numerical payload or -1 if unable to find payload in codecs
  1405. *
  1406. * Example usage:
  1407. *
  1408. * \code
  1409. * int payload = ast_rtp_codecs_find_payload_code(&codecs, 0);
  1410. * \endcode
  1411. *
  1412. * This looks for the numerical payload for ULAW in the codecs structure.
  1413. *
  1414. */
  1415. int ast_rtp_codecs_find_payload_code(struct ast_rtp_codecs *codecs, int code);
  1416. /*!
  1417. * \brief Retrieve mime subtype information on a payload
  1418. *
  1419. * \param asterisk_format Non-zero to look up using Asterisk format
  1420. * \param format Asterisk format to look up
  1421. * \param code RTP code to look up
  1422. * \param options Additional options that may change the result
  1423. *
  1424. * \retval Mime subtype success
  1425. * \retval NULL failure
  1426. *
  1427. * Example usage:
  1428. *
  1429. * \code
  1430. * const char *subtype = ast_rtp_lookup_mime_subtype2(1, ast_format_set(&tmp_fmt, AST_FORMAT_ULAW, 0), 0, 0);
  1431. * \endcode
  1432. *
  1433. * This looks up the mime subtype for the ULAW format.
  1434. *
  1435. * \since 1.8
  1436. */
  1437. const char *ast_rtp_lookup_mime_subtype2(const int asterisk_format, struct ast_format *format, int code, enum ast_rtp_options options);
  1438. /*!
  1439. * \brief Convert formats into a string and put them into a buffer
  1440. *
  1441. * \param buf Buffer to put the mime output into
  1442. * \param ast_format_capability Asterisk Formats we are looking up.
  1443. * \param rtp_capability RTP codes that we are looking up
  1444. * \param asterisk_format Non-zero if the ast_format_capability structure is to be used, 0 if rtp_capability is to be used
  1445. * \param options Additional options that may change the result
  1446. *
  1447. * \retval non-NULL success
  1448. * \retval NULL failure
  1449. *
  1450. * Example usage:
  1451. *
  1452. * \code
  1453. * char buf[256] = "";
  1454. * struct ast_format tmp_fmt;
  1455. * struct ast_format_cap *cap = ast_format_cap_alloc_nolock();
  1456. * ast_format_cap_append(cap, ast_format_set(&tmp_fmt, AST_FORMAT_ULAW, 0));
  1457. * ast_format_cap_append(cap, ast_format_set(&tmp_fmt, AST_FORMAT_GSM, 0));
  1458. * char *mime = ast_rtp_lookup_mime_multiple2(&buf, sizeof(buf), cap, 0, 1, 0);
  1459. * ast_format_cap_destroy(cap);
  1460. * \endcode
  1461. *
  1462. * This returns the mime values for ULAW and ALAW in the buffer pointed to by buf.
  1463. *
  1464. * \since 1.8
  1465. */
  1466. 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);
  1467. /*!
  1468. * \brief Begin sending a DTMF digit
  1469. *
  1470. * \param instance The RTP instance to send the DTMF on
  1471. * \param digit What DTMF digit to send
  1472. *
  1473. * \retval 0 success
  1474. * \retval -1 failure
  1475. *
  1476. * Example usage:
  1477. *
  1478. * \code
  1479. * ast_rtp_instance_dtmf_begin(instance, '1');
  1480. * \endcode
  1481. *
  1482. * This starts sending the DTMF '1' on the RTP instance pointed to by instance. It will
  1483. * continue being sent until it is ended.
  1484. *
  1485. * \since 1.8
  1486. */
  1487. int ast_rtp_instance_dtmf_begin(struct ast_rtp_instance *instance, char digit);
  1488. /*!
  1489. * \brief Stop sending a DTMF digit
  1490. *
  1491. * \param instance The RTP instance to stop the DTMF on
  1492. * \param digit What DTMF digit to stop
  1493. *
  1494. * \retval 0 success
  1495. * \retval -1 failure
  1496. *
  1497. * Example usage:
  1498. *
  1499. * \code
  1500. * ast_rtp_instance_dtmf_end(instance, '1');
  1501. * \endcode
  1502. *
  1503. * This stops sending the DTMF '1' on the RTP instance pointed to by instance.
  1504. *
  1505. * \since 1.8
  1506. */
  1507. int ast_rtp_instance_dtmf_end(struct ast_rtp_instance *instance, char digit);
  1508. int ast_rtp_instance_dtmf_end_with_duration(struct ast_rtp_instance *instance, char digit, unsigned int duration);
  1509. /*!
  1510. * \brief Set the DTMF mode that should be used
  1511. *
  1512. * \param instance the RTP instance to set DTMF mode on
  1513. * \param dtmf_mode The DTMF mode that is in use
  1514. *
  1515. * \retval 0 success
  1516. * \retval -1 failure
  1517. *
  1518. * Example usage:
  1519. *
  1520. * \code
  1521. * ast_rtp_instance_dtmf_mode_set(instance, AST_RTP_DTMF_MODE_RFC2833);
  1522. * \endcode
  1523. *
  1524. * This sets the RTP instance to use RFC2833 for DTMF transmission and receiving.
  1525. *
  1526. * \since 1.8
  1527. */
  1528. int ast_rtp_instance_dtmf_mode_set(struct ast_rtp_instance *instance, enum ast_rtp_dtmf_mode dtmf_mode);
  1529. /*!
  1530. * \brief Get the DTMF mode of an RTP instance
  1531. *
  1532. * \param instance The RTP instance to get the DTMF mode of
  1533. *
  1534. * \retval DTMF mode
  1535. *
  1536. * Example usage:
  1537. *
  1538. * \code
  1539. * enum ast_rtp_dtmf_mode dtmf_mode = ast_rtp_instance_dtmf_mode_get(instance);
  1540. * \endcode
  1541. *
  1542. * This gets the DTMF mode set on the RTP instance pointed to by 'instance'.
  1543. *
  1544. * \since 1.8
  1545. */
  1546. enum ast_rtp_dtmf_mode ast_rtp_instance_dtmf_mode_get(struct ast_rtp_instance *instance);
  1547. /*!
  1548. * \brief Indicate that the RTP marker bit should be set on an RTP stream
  1549. *
  1550. * \param instance Instance that the new media source is feeding into
  1551. *
  1552. * Example usage:
  1553. *
  1554. * \code
  1555. * ast_rtp_instance_update_source(instance);
  1556. * \endcode
  1557. *
  1558. * This indicates that the source of media that is feeding the instance pointed to by
  1559. * instance has been updated and that the marker bit should be set.
  1560. *
  1561. * \since 1.8
  1562. */
  1563. void ast_rtp_instance_update_source(struct ast_rtp_instance *instance);
  1564. /*!
  1565. * \brief Indicate a new source of audio has dropped in and the ssrc should change
  1566. *
  1567. * \param instance Instance that the new media source is feeding into
  1568. *
  1569. * Example usage:
  1570. *
  1571. * \code
  1572. * ast_rtp_instance_change_source(instance);
  1573. * \endcode
  1574. *
  1575. * This indicates that the source of media that is feeding the instance pointed to by
  1576. * instance has changed and that the marker bit should be set and the SSRC updated.
  1577. *
  1578. * \since 1.8
  1579. */
  1580. void ast_rtp_instance_change_source(struct ast_rtp_instance *instance);
  1581. /*!
  1582. * \brief Set QoS parameters on an RTP session
  1583. *
  1584. * \param instance Instance to set the QoS parameters on
  1585. * \param tos Terms of service value
  1586. * \param cos Class of service value
  1587. * \param desc What is setting the QoS values
  1588. *
  1589. * \retval 0 success
  1590. * \retval -1 failure
  1591. *
  1592. * Example usage:
  1593. *
  1594. * \code
  1595. * ast_rtp_instance_set_qos(instance, 0, 0, "Example");
  1596. * \endcode
  1597. *
  1598. * This sets the TOS and COS values to 0 on the instance pointed to by instance.
  1599. *
  1600. * \since 1.8
  1601. */
  1602. int ast_rtp_instance_set_qos(struct ast_rtp_instance *instance, int tos, int cos, const char *desc);
  1603. /*!
  1604. * \brief Stop an RTP instance
  1605. *
  1606. * \param instance Instance that media is no longer going to at this time
  1607. *
  1608. * Example usage:
  1609. *
  1610. * \code
  1611. * ast_rtp_instance_stop(instance);
  1612. * \endcode
  1613. *
  1614. * This tells the RTP engine being used for the instance pointed to by instance
  1615. * that media is no longer going to it at this time, but may in the future.
  1616. *
  1617. * \since 1.8
  1618. */
  1619. void ast_rtp_instance_stop(struct ast_rtp_instance *instance);
  1620. /*!
  1621. * \brief Get the file descriptor for an RTP session (or RTCP)
  1622. *
  1623. * \param instance Instance to get the file descriptor for
  1624. * \param rtcp Whether to retrieve the file descriptor for RTCP or not
  1625. *
  1626. * \retval fd success
  1627. * \retval -1 failure
  1628. *
  1629. * Example usage:
  1630. *
  1631. * \code
  1632. * int rtp_fd = ast_rtp_instance_fd(instance, 0);
  1633. * \endcode
  1634. *
  1635. * This retrieves the file descriptor for the socket carrying media on the instance
  1636. * pointed to by instance.
  1637. *
  1638. * \since 1.8
  1639. */
  1640. int ast_rtp_instance_fd(struct ast_rtp_instance *instance, int rtcp);
  1641. /*!
  1642. * \brief Get the RTP glue that binds a channel to the RTP engine
  1643. *
  1644. * \param type Name of the glue we want
  1645. *
  1646. * \retval non-NULL success
  1647. * \retval NULL failure
  1648. *
  1649. * Example usage:
  1650. *
  1651. * \code
  1652. * struct ast_rtp_glue *glue = ast_rtp_instance_get_glue("Example");
  1653. * \endcode
  1654. *
  1655. * This retrieves the RTP glue that has the name 'Example'.
  1656. *
  1657. * \since 1.8
  1658. */
  1659. struct ast_rtp_glue *ast_rtp_instance_get_glue(const char *type);
  1660. /*!
  1661. * \brief Get the unique ID of the channel that owns this RTP instance
  1662. *
  1663. * Note that this should remain valid for the lifetime of the RTP instance.
  1664. *
  1665. * \param instance The RTP instance
  1666. *
  1667. * \retval The unique ID of the channel
  1668. * \retval Empty string if no channel owns this RTP instance
  1669. *
  1670. * \since 12
  1671. */
  1672. const char *ast_rtp_instance_get_channel_id(struct ast_rtp_instance *instance);
  1673. /*!
  1674. * \brief Set the channel that owns this RTP instance
  1675. *
  1676. * \param instance The RTP instance
  1677. * \param uniqueid The uniqueid of the channel
  1678. *
  1679. * \since 12
  1680. */
  1681. void ast_rtp_instance_set_channel_id(struct ast_rtp_instance *instance, const char *uniqueid);
  1682. /*!
  1683. * \brief Get the other RTP instance that an instance is bridged to
  1684. *
  1685. * \param instance The RTP instance that we want
  1686. *
  1687. * \retval non-NULL success
  1688. * \retval NULL failure
  1689. *
  1690. * Example usage:
  1691. *
  1692. * \code
  1693. * struct ast_rtp_instance *bridged = ast_rtp_instance_get_bridged(instance0);
  1694. * \endcode
  1695. *
  1696. * This gets the RTP instance that instance0 is bridged to.
  1697. *
  1698. * \since 1.8
  1699. */
  1700. struct ast_rtp_instance *ast_rtp_instance_get_bridged(struct ast_rtp_instance *instance);
  1701. /*!
  1702. * \brief Set the other RTP instance that an instance is bridged to
  1703. *
  1704. * \param instance The RTP instance that we want to set the bridged value on
  1705. * \param bridged The RTP instance they are bridged to
  1706. *
  1707. * \since 12
  1708. */
  1709. void ast_rtp_instance_set_bridged(struct ast_rtp_instance *instance, struct ast_rtp_instance *bridged);
  1710. /*!
  1711. * \brief Make two channels compatible for early bridging
  1712. *
  1713. * \param c_dst Destination channel to copy to
  1714. * \param c_src Source channel to copy from
  1715. *
  1716. * \since 1.8
  1717. */
  1718. void ast_rtp_instance_early_bridge_make_compatible(struct ast_channel *c_dst, struct ast_channel *c_src);
  1719. /*!
  1720. * \brief Early bridge two channels that use RTP instances
  1721. *
  1722. * \param c0 First channel part of the bridge
  1723. * \param c1 Second channel part of the bridge
  1724. *
  1725. * \retval 0 success
  1726. * \retval -1 failure
  1727. *
  1728. * \note This should only be used by channel drivers in their technology declaration.
  1729. *
  1730. * \since 1.8
  1731. */
  1732. int ast_rtp_instance_early_bridge(struct ast_channel *c0, struct ast_channel *c1);
  1733. /*!
  1734. * \brief Initialize RED support on an RTP instance
  1735. *
  1736. * \param instance The instance to initialize RED support on
  1737. * \param buffer_time How long to buffer before sending
  1738. * \param payloads Payload values
  1739. * \param generations Number of generations
  1740. *
  1741. * \retval 0 success
  1742. * \retval -1 failure
  1743. *
  1744. * \since 1.8
  1745. */
  1746. int ast_rtp_red_init(struct ast_rtp_instance *instance, int buffer_time, int *payloads, int generations);
  1747. /*!
  1748. * \brief Buffer a frame in an RTP instance for RED
  1749. *
  1750. * \param instance The instance to buffer the frame on
  1751. * \param frame Frame that we want to buffer
  1752. *
  1753. * \retval 0 success
  1754. * \retval -1 failure
  1755. *
  1756. * \since 1.8
  1757. */
  1758. int ast_rtp_red_buffer(struct ast_rtp_instance *instance, struct ast_frame *frame);
  1759. /*!
  1760. * \brief Retrieve statistics about an RTP instance
  1761. *
  1762. * \param instance Instance to get statistics on
  1763. * \param stats Structure to put results into
  1764. * \param stat What statistic(s) to retrieve
  1765. *
  1766. * \retval 0 success
  1767. * \retval -1 failure
  1768. *
  1769. * Example usage:
  1770. *
  1771. * \code
  1772. * struct ast_rtp_instance_stats stats;
  1773. * ast_rtp_instance_get_stats(instance, &stats, AST_RTP_INSTANCE_STAT_ALL);
  1774. * \endcode
  1775. *
  1776. * This retrieves all statistics the underlying RTP engine supports and puts the values into the
  1777. * stats structure.
  1778. *
  1779. * \since 1.8
  1780. */
  1781. int ast_rtp_instance_get_stats(struct ast_rtp_instance *instance, struct ast_rtp_instance_stats *stats, enum ast_rtp_instance_stat stat);
  1782. /*!
  1783. * \brief Set standard statistics from an RTP instance on a channel
  1784. *
  1785. * \param chan Channel to set the statistics on
  1786. * \param instance The RTP instance that statistics will be retrieved from
  1787. *
  1788. * \note Absolutely _NO_ channel locks should be held before calling this function.
  1789. *
  1790. * Example usage:
  1791. *
  1792. * \code
  1793. * ast_rtp_instance_set_stats_vars(chan, rtp);
  1794. * \endcode
  1795. *
  1796. * This retrieves standard statistics from the RTP instance rtp and sets it on the channel pointed to
  1797. * by chan.
  1798. *
  1799. * \since 1.8
  1800. */
  1801. void ast_rtp_instance_set_stats_vars(struct ast_channel *chan, struct ast_rtp_instance *instance);
  1802. /*!
  1803. * \brief Retrieve quality statistics about an RTP instance
  1804. *
  1805. * \param instance Instance to get statistics on
  1806. * \param field What quality statistic to retrieve
  1807. * \param buf What buffer to put the result into
  1808. * \param size Size of the above buffer
  1809. *
  1810. * \retval non-NULL success
  1811. * \retval NULL failure
  1812. *
  1813. * Example usage:
  1814. *
  1815. * \code
  1816. * char quality[AST_MAX_USER_FIELD];
  1817. * ast_rtp_instance_get_quality(instance, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, &buf, sizeof(buf));
  1818. * \endcode
  1819. *
  1820. * This retrieves general quality statistics and places a text representation into the buf pointed to by buf.
  1821. *
  1822. * \since 1.8
  1823. */
  1824. char *ast_rtp_instance_get_quality(struct ast_rtp_instance *instance, enum ast_rtp_instance_stat_field field, char *buf, size_t size);
  1825. /*!
  1826. * \brief Request that the underlying RTP engine provide audio frames in a specific format
  1827. *
  1828. * \param instance The RTP instance to change read format on
  1829. * \param format Format that frames are wanted in
  1830. *
  1831. * \retval 0 success
  1832. * \retval -1 failure
  1833. *
  1834. * Example usage:
  1835. *
  1836. * \code
  1837. * struct ast_format tmp_fmt;
  1838. * ast_rtp_instance_set_read_format(instance, ast_format_set(&tmp_fmt, AST_FORMAT_ULAW, 0));
  1839. * \endcode
  1840. *
  1841. * This requests that the RTP engine provide audio frames in the ULAW format.
  1842. *
  1843. * \since 1.8
  1844. */
  1845. int ast_rtp_instance_set_read_format(struct ast_rtp_instance *instance, struct ast_format *format);
  1846. /*!
  1847. * \brief Tell underlying RTP engine that audio frames will be provided in a specific format
  1848. *
  1849. * \param instance The RTP instance to change write format on
  1850. * \param format Format that frames will be provided in
  1851. *
  1852. * \retval 0 success
  1853. * \retval -1 failure
  1854. *
  1855. * Example usage:
  1856. *
  1857. * \code
  1858. * struct ast_format tmp_fmt;
  1859. * ast_rtp_instance_set_write_format(instance, ast_format_set(&tmp_fmt, AST_FORMAT_ULAW, 0));
  1860. * \endcode
  1861. *
  1862. * This tells the underlying RTP engine that audio frames will be provided to it in ULAW format.
  1863. *
  1864. * \since 1.8
  1865. */
  1866. int ast_rtp_instance_set_write_format(struct ast_rtp_instance *instance, struct ast_format *format);
  1867. /*!
  1868. * \brief Request that the underlying RTP engine make two RTP instances compatible with eachother
  1869. *
  1870. * \param chan Our own Asterisk channel
  1871. * \param instance The first RTP instance
  1872. * \param peer The peer Asterisk channel
  1873. *
  1874. * \retval 0 success
  1875. * \retval -1 failure
  1876. *
  1877. * Example usage:
  1878. *
  1879. * \code
  1880. * ast_rtp_instance_make_compatible(instance, peer);
  1881. * \endcode
  1882. *
  1883. * This makes the RTP instance for 'peer' compatible with 'instance' and vice versa.
  1884. *
  1885. * \since 1.8
  1886. */
  1887. int ast_rtp_instance_make_compatible(struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_channel *peer);
  1888. /*! \brief Request the formats that can be transcoded
  1889. *
  1890. * \param instance The RTP instance
  1891. * \param to_endpoint Formats being sent/received towards the endpoint
  1892. * \param to_asterisk Formats being sent/received towards Asterisk
  1893. * \param result capabilities structure to store and return supported formats in.
  1894. *
  1895. * Example usage:
  1896. *
  1897. * \code
  1898. * ast_rtp_instance_available_formats(instance, to_capabilities, from_capabilities, result_capabilities);
  1899. * \endcode
  1900. *
  1901. * This sees if it is possible to have ulaw communicated to the endpoint but signed linear received into Asterisk.
  1902. *
  1903. * \since 1.8
  1904. */
  1905. 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);
  1906. /*!
  1907. * \brief Indicate to the RTP engine that packets are now expected to be sent/received on the RTP instance
  1908. *
  1909. * \param instance The RTP instance
  1910. *
  1911. * \retval 0 success
  1912. * \retval -1 failure
  1913. *
  1914. * Example usage:
  1915. *
  1916. * \code
  1917. * ast_rtp_instance_activate(instance);
  1918. * \endcode
  1919. *
  1920. * This tells the underlying RTP engine of instance that packets will now flow.
  1921. *
  1922. * \since 1.8
  1923. */
  1924. int ast_rtp_instance_activate(struct ast_rtp_instance *instance);
  1925. /*!
  1926. * \brief Request that the underlying RTP engine send a STUN BIND request
  1927. *
  1928. * \param instance The RTP instance
  1929. * \param suggestion The suggested destination
  1930. * \param username Optionally a username for the request
  1931. *
  1932. * Example usage:
  1933. *
  1934. * \code
  1935. * ast_rtp_instance_stun_request(instance, NULL, NULL);
  1936. * \endcode
  1937. *
  1938. * This requests that the RTP engine send a STUN BIND request on the session pointed to by
  1939. * 'instance'.
  1940. *
  1941. * \since 1.8
  1942. */
  1943. void ast_rtp_instance_stun_request(struct ast_rtp_instance *instance, struct ast_sockaddr *suggestion, const char *username);
  1944. /*!
  1945. * \brief Set the RTP timeout value
  1946. *
  1947. * \param instance The RTP instance
  1948. * \param timeout Value to set the timeout to
  1949. *
  1950. * Example usage:
  1951. *
  1952. * \code
  1953. * ast_rtp_instance_set_timeout(instance, 5000);
  1954. * \endcode
  1955. *
  1956. * This sets the RTP timeout value on 'instance' to be 5000.
  1957. *
  1958. * \since 1.8
  1959. */
  1960. void ast_rtp_instance_set_timeout(struct ast_rtp_instance *instance, int timeout);
  1961. /*!
  1962. * \brief Set the RTP timeout value for when the instance is on hold
  1963. *
  1964. * \param instance The RTP instance
  1965. * \param timeout Value to set the timeout to
  1966. *
  1967. * Example usage:
  1968. *
  1969. * \code
  1970. * ast_rtp_instance_set_hold_timeout(instance, 5000);
  1971. * \endcode
  1972. *
  1973. * This sets the RTP hold timeout value on 'instance' to be 5000.
  1974. *
  1975. * \since 1.8
  1976. */
  1977. void ast_rtp_instance_set_hold_timeout(struct ast_rtp_instance *instance, int timeout);
  1978. /*!
  1979. * \brief Set the RTP keepalive interval
  1980. *
  1981. * \param instance The RTP instance
  1982. * \param timeout Value to set the keepalive interval to
  1983. *
  1984. * Example usage:
  1985. *
  1986. * \code
  1987. * ast_rtp_instance_set_keepalive(instance, 5000);
  1988. * \endcode
  1989. *
  1990. * This sets the RTP keepalive interval on 'instance' to be 5000.
  1991. *
  1992. * \since 1.8
  1993. */
  1994. void ast_rtp_instance_set_keepalive(struct ast_rtp_instance *instance, int timeout);
  1995. /*!
  1996. * \brief Get the RTP timeout value
  1997. *
  1998. * \param instance The RTP instance
  1999. *
  2000. * \retval timeout value
  2001. *
  2002. * Example usage:
  2003. *
  2004. * \code
  2005. * int timeout = ast_rtp_instance_get_timeout(instance);
  2006. * \endcode
  2007. *
  2008. * This gets the RTP timeout value for the RTP instance pointed to by 'instance'.
  2009. *
  2010. * \since 1.8
  2011. */
  2012. int ast_rtp_instance_get_timeout(struct ast_rtp_instance *instance);
  2013. /*!
  2014. * \brief Get the RTP timeout value for when an RTP instance is on hold
  2015. *
  2016. * \param instance The RTP instance
  2017. *
  2018. * \retval timeout value
  2019. *
  2020. * Example usage:
  2021. *
  2022. * \code
  2023. * int timeout = ast_rtp_instance_get_hold_timeout(instance);
  2024. * \endcode
  2025. *
  2026. * This gets the RTP hold timeout value for the RTP instance pointed to by 'instance'.
  2027. *
  2028. * \since 1.8
  2029. */
  2030. int ast_rtp_instance_get_hold_timeout(struct ast_rtp_instance *instance);
  2031. /*!
  2032. * \brief Get the RTP keepalive interval
  2033. *
  2034. * \param instance The RTP instance
  2035. *
  2036. * \retval period Keepalive interval value
  2037. *
  2038. * Example usage:
  2039. *
  2040. * \code
  2041. * int interval = ast_rtp_instance_get_keepalive(instance);
  2042. * \endcode
  2043. *
  2044. * This gets the RTP keepalive interval value for the RTP instance pointed to by 'instance'.
  2045. *
  2046. * \since 1.8
  2047. */
  2048. int ast_rtp_instance_get_keepalive(struct ast_rtp_instance *instance);
  2049. /*!
  2050. * \brief Get the RTP engine in use on an RTP instance
  2051. *
  2052. * \param instance The RTP instance
  2053. *
  2054. * \retval pointer to the engine
  2055. *
  2056. * Example usage:
  2057. *
  2058. * \code
  2059. * struct ast_rtp_engine *engine = ast_rtp_instance_get_engine(instance);
  2060. * \endcode
  2061. *
  2062. * This gets the RTP engine currently in use on the RTP instance pointed to by 'instance'.
  2063. *
  2064. * \since 1.8
  2065. */
  2066. struct ast_rtp_engine *ast_rtp_instance_get_engine(struct ast_rtp_instance *instance);
  2067. /*!
  2068. * \brief Get the RTP glue in use on an RTP instance
  2069. *
  2070. * \param instance The RTP instance
  2071. *
  2072. * \retval pointer to the glue
  2073. *
  2074. * Example:
  2075. *
  2076. * \code
  2077. * struct ast_rtp_glue *glue = ast_rtp_instance_get_active_glue(instance);
  2078. * \endcode
  2079. *
  2080. * This gets the RTP glue currently in use on the RTP instance pointed to by 'instance'.
  2081. *
  2082. * \since 1.8
  2083. */
  2084. struct ast_rtp_glue *ast_rtp_instance_get_active_glue(struct ast_rtp_instance *instance);
  2085. /*!
  2086. * \brief Send a comfort noise packet to the RTP instance
  2087. *
  2088. * \param instance The RTP instance
  2089. * \param level Magnitude of the noise level
  2090. *
  2091. * \retval 0 Success
  2092. * \retval non-zero Failure
  2093. */
  2094. int ast_rtp_instance_sendcng(struct ast_rtp_instance *instance, int level);
  2095. /*!
  2096. * \brief Add or replace the SRTP policies for the given RTP instance
  2097. *
  2098. * \param instance the RTP instance
  2099. * \param remote_policy the remote endpoint's policy
  2100. * \param local_policy our policy for this RTP instance's remote endpoint
  2101. * \param rtcp 1 for dedicated RTCP policies
  2102. *
  2103. * \retval 0 Success
  2104. * \retval non-zero Failure
  2105. */
  2106. 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);
  2107. /*!
  2108. * \brief Obtain the SRTP instance associated with an RTP instance
  2109. *
  2110. * \param instance the RTP instance
  2111. * \param rtcp 1 to request instance for RTCP
  2112. * \retval the SRTP instance on success
  2113. * \retval NULL if no SRTP instance exists
  2114. */
  2115. struct ast_srtp *ast_rtp_instance_get_srtp(struct ast_rtp_instance *instance, int rtcp);
  2116. /*! \brief Custom formats declared in codecs.conf at startup must be communicated to the rtp_engine
  2117. * so their mime type can payload number can be initialized. */
  2118. int ast_rtp_engine_load_format(struct ast_format *format);
  2119. /*! \brief Formats requiring the use of a format attribute interface must have that
  2120. * interface registered in order for the rtp engine to handle it correctly. If an
  2121. * attribute interface is unloaded, this function must be called to notify the rtp_engine. */
  2122. int ast_rtp_engine_unload_format(struct ast_format *format);
  2123. /*!
  2124. * \brief Obtain a pointer to the ICE support present on an RTP instance
  2125. *
  2126. * \param instance the RTP instance
  2127. *
  2128. * \retval ICE support if present
  2129. * \retval NULL if no ICE support available
  2130. */
  2131. struct ast_rtp_engine_ice *ast_rtp_instance_get_ice(struct ast_rtp_instance *instance);
  2132. /*!
  2133. * \brief Obtain a pointer to the DTLS support present on an RTP instance
  2134. *
  2135. * \param instance the RTP instance
  2136. *
  2137. * \retval DTLS support if present
  2138. * \retval NULL if no DTLS support available
  2139. */
  2140. struct ast_rtp_engine_dtls *ast_rtp_instance_get_dtls(struct ast_rtp_instance *instance);
  2141. /*!
  2142. * \brief Parse DTLS related configuration options
  2143. *
  2144. * \param dtls_cfg a DTLS configuration structure
  2145. * \param name name of the configuration option
  2146. * \param value value of the configuration option
  2147. *
  2148. * \retval 0 if handled
  2149. * \retval -1 if not handled
  2150. */
  2151. int ast_rtp_dtls_cfg_parse(struct ast_rtp_dtls_cfg *dtls_cfg, const char *name, const char *value);
  2152. /*!
  2153. * \brief Copy contents of a DTLS configuration structure
  2154. *
  2155. * \param src_cfg source DTLS configuration structure
  2156. * \param dst_cfg destination DTLS configuration structure
  2157. */
  2158. void ast_rtp_dtls_cfg_copy(const struct ast_rtp_dtls_cfg *src_cfg, struct ast_rtp_dtls_cfg *dst_cfg);
  2159. /*!
  2160. * \brief Free contents of a DTLS configuration structure
  2161. *
  2162. * \param dtls_cfg a DTLS configuration structure
  2163. */
  2164. void ast_rtp_dtls_cfg_free(struct ast_rtp_dtls_cfg *dtls_cfg);
  2165. struct ast_json;
  2166. /*!
  2167. * \brief Allocate an ao2 ref counted instance of \ref ast_rtp_rtcp_report
  2168. *
  2169. * \param report_blocks The number of report blocks to allocate
  2170. * \retval An ao2 ref counted \ref ast_rtp_rtcp_report object on success
  2171. * \retval NULL on error
  2172. */
  2173. struct ast_rtp_rtcp_report *ast_rtp_rtcp_report_alloc(unsigned int report_blocks);
  2174. /*!
  2175. * \since 12
  2176. * \brief Publish an RTCP message to \ref stasis
  2177. *
  2178. * \param rtp The rtp instance object
  2179. * \param message_type The RTP message type to publish
  2180. * \param report The RTCP report object to publish. This should be an ao2 ref counted
  2181. * object. This routine will increase the reference count of the object.
  2182. * \param blob Additional JSON objects to publish along with the RTCP information
  2183. */
  2184. void ast_rtp_publish_rtcp_message(struct ast_rtp_instance *rtp,
  2185. struct stasis_message_type *message_type,
  2186. struct ast_rtp_rtcp_report *report,
  2187. struct ast_json *blob);
  2188. /*!
  2189. * \brief Get the last RTP transmission time
  2190. *
  2191. * \param rtp The instance from which to get the last transmission time
  2192. * \return The last RTP transmission time
  2193. */
  2194. time_t ast_rtp_instance_get_last_tx(const struct ast_rtp_instance *rtp);
  2195. /*!
  2196. * \brief Set the last RTP transmission time
  2197. *
  2198. * \param rtp The instance on which to set the last transmission time
  2199. * \param time The last transmission time
  2200. */
  2201. void ast_rtp_instance_set_last_tx(struct ast_rtp_instance *rtp, time_t time);
  2202. /*
  2203. * \brief Get the last RTP reception time
  2204. *
  2205. * \param rtp The instance from which to get the last reception time
  2206. * \return The last RTP reception time
  2207. */
  2208. time_t ast_rtp_instance_get_last_rx(const struct ast_rtp_instance *rtp);
  2209. /*!
  2210. * \brief Set the last RTP reception time
  2211. *
  2212. * \param rtp The instance on which to set the last reception time
  2213. * \param time The last reception time
  2214. */
  2215. void ast_rtp_instance_set_last_rx(struct ast_rtp_instance *rtp, time_t time);
  2216. /*! \addtogroup StasisTopicsAndMessages
  2217. * @{
  2218. */
  2219. /*!
  2220. * \since 12
  2221. * \brief Message type for an RTCP message sent from this Asterisk instance
  2222. *
  2223. * \retval A stasis message type
  2224. */
  2225. struct stasis_message_type *ast_rtp_rtcp_sent_type(void);
  2226. /*!
  2227. * \since 12
  2228. * \brief Message type for an RTCP message received from some external source
  2229. *
  2230. * \retval A stasis message type
  2231. */
  2232. struct stasis_message_type *ast_rtp_rtcp_received_type(void);
  2233. /*!
  2234. * \since 12
  2235. * \brief \ref stasis topic for RTP and RTCP related messages
  2236. *
  2237. * \retval A \ref stasis topic
  2238. */
  2239. struct stasis_topic *ast_rtp_topic(void);
  2240. /* }@ */
  2241. #if defined(__cplusplus) || defined(c_plusplus)
  2242. }
  2243. #endif
  2244. #endif /* _ASTERISK_RTP_ENGINE_H */