bridge_channel.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013 Digium, Inc.
  5. *
  6. * Joshua Colp <jcolp@digium.com>
  7. * Richard Mudgett <rmudgett@digium.com>
  8. * Matt Jordan <mjordan@digium.com>
  9. *
  10. * See http://www.asterisk.org for more information about
  11. * the Asterisk project. Please do not directly contact
  12. * any of the maintainers of this project for assistance;
  13. * the project provides a web site, mailing lists and IRC
  14. * channels for your use.
  15. *
  16. * This program is free software, distributed under the terms of
  17. * the GNU General Public License Version 2. See the LICENSE file
  18. * at the top of the source tree.
  19. */
  20. /*!
  21. * \file
  22. * \page AstBridgeChannel Bridging Channel API
  23. *
  24. * An API that act on a channel in a bridge. Note that while the
  25. * \ref ast_bridge_channel is owned by a channel, it should only be used
  26. * by members of the bridging system. The only places where this API should
  27. * be used is:
  28. * \arg \ref AstBridging API itself
  29. * \arg Bridge mixing technologies
  30. * \arg Bridge sub-classes
  31. *
  32. * In general, anywhere else it is unsafe to use this API. Care should be
  33. * taken when using this API to ensure that the locking order remains
  34. * correct. The locking order must be:
  35. * \arg The \ref \c ast_bridge
  36. * \arg The \ref \c ast_bridge_channel
  37. * \arg The \ref \c ast_channel
  38. *
  39. * \author Joshua Colp <jcolp@digium.com>
  40. * \author Richard Mudgett <rmudgett@digium.com>
  41. * \author Matt Jordan <mjordan@digium.com>
  42. *
  43. * See Also:
  44. * \arg \ref AstBridging
  45. * \arg \ref AstCREDITS
  46. */
  47. #ifndef _ASTERISK_BRIDGING_CHANNEL_H
  48. #define _ASTERISK_BRIDGING_CHANNEL_H
  49. #if defined(__cplusplus) || defined(c_plusplus)
  50. extern "C" {
  51. #endif
  52. #include "asterisk/bridge_features.h"
  53. #include "asterisk/bridge_technology.h"
  54. /*! \brief State information about a bridged channel */
  55. enum bridge_channel_state {
  56. /*! Waiting for a signal (Channel in the bridge) */
  57. BRIDGE_CHANNEL_STATE_WAIT = 0,
  58. /*! Bridged channel was forced out and should be hung up (Bridge may dissolve.) */
  59. BRIDGE_CHANNEL_STATE_END,
  60. /*! Bridged channel was forced out. Don't dissolve the bridge regardless */
  61. BRIDGE_CHANNEL_STATE_END_NO_DISSOLVE,
  62. };
  63. enum bridge_channel_thread_state {
  64. /*! Bridge channel thread is idle/waiting. */
  65. BRIDGE_CHANNEL_THREAD_IDLE,
  66. /*! Bridge channel thread is writing a normal/simple frame. */
  67. BRIDGE_CHANNEL_THREAD_SIMPLE,
  68. /*! Bridge channel thread is processing a frame. */
  69. BRIDGE_CHANNEL_THREAD_FRAME,
  70. };
  71. struct ast_bridge;
  72. struct ast_bridge_tech_optimizations;
  73. /*!
  74. * \brief Structure that contains information regarding a channel in a bridge
  75. */
  76. struct ast_bridge_channel {
  77. /* XXX ASTERISK-21271 cond is only here because of external party suspend/unsuspend support. */
  78. /*! Condition, used if we want to wake up a thread waiting on the bridged channel */
  79. ast_cond_t cond;
  80. /*! Current bridged channel state */
  81. enum bridge_channel_state state;
  82. /*! Asterisk channel participating in the bridge */
  83. struct ast_channel *chan;
  84. /*! Asterisk channel we are swapping with (if swapping) */
  85. struct ast_channel *swap;
  86. /*!
  87. * \brief Bridge this channel is participating in
  88. *
  89. * \note The bridge pointer cannot change while the bridge or
  90. * bridge_channel is locked.
  91. */
  92. struct ast_bridge *bridge;
  93. /*!
  94. * \brief Bridge class private channel data.
  95. *
  96. * \note This information is added when the channel is pushed
  97. * into the bridge and removed when it is pulled from the
  98. * bridge.
  99. */
  100. void *bridge_pvt;
  101. /*!
  102. * \brief Private information unique to the bridge technology.
  103. *
  104. * \note This information is added when the channel joins the
  105. * bridge's technology and removed when it leaves the bridge's
  106. * technology.
  107. */
  108. void *tech_pvt;
  109. /*! Thread handling the bridged channel (Needed by ast_bridge_depart) */
  110. pthread_t thread;
  111. /* v-- These flags change while the bridge is locked or before the channel is in the bridge. */
  112. /*! TRUE if the channel is in a bridge. */
  113. unsigned int in_bridge:1;
  114. /*! TRUE if the channel just joined the bridge. */
  115. unsigned int just_joined:1;
  116. /*! TRUE if the channel is suspended from the bridge. */
  117. unsigned int suspended:1;
  118. /*! TRUE if the COLP update on initial join is inhibited. */
  119. unsigned int inhibit_colp:1;
  120. /*! TRUE if the channel must wait for an ast_bridge_depart to reclaim the channel. */
  121. unsigned int depart_wait:1;
  122. /* ^-- These flags change while the bridge is locked or before the channel is in the bridge. */
  123. /*! Features structure for features that are specific to this channel */
  124. struct ast_bridge_features *features;
  125. /*! Technology optimization parameters used by bridging technologies capable of
  126. * optimizing based upon talk detection. */
  127. struct ast_bridge_tech_optimizations tech_args;
  128. /*! Copy of read format used by chan before join */
  129. struct ast_format *read_format;
  130. /*! Copy of write format used by chan before join */
  131. struct ast_format *write_format;
  132. /*! Call ID associated with bridge channel */
  133. struct ast_callid *callid;
  134. /*! A clone of the roles living on chan when the bridge channel joins the bridge. This may require some opacification */
  135. struct bridge_roles_datastore *bridge_roles;
  136. /*! Linked list information */
  137. AST_LIST_ENTRY(ast_bridge_channel) entry;
  138. /*! Queue of outgoing frames to the channel. */
  139. AST_LIST_HEAD_NOLOCK(, ast_frame) wr_queue;
  140. /*! Queue of deferred frames, queued onto channel when other party joins. */
  141. AST_LIST_HEAD_NOLOCK(, ast_frame) deferred_queue;
  142. /*! Pipe to alert thread when frames are put into the wr_queue. */
  143. int alert_pipe[2];
  144. /*!
  145. * \brief The bridge channel thread activity.
  146. *
  147. * \details Used by local channel optimization to determine if
  148. * the thread is in an acceptable state to optimize.
  149. *
  150. * \note Needs to be atomically settable.
  151. */
  152. enum bridge_channel_thread_state activity;
  153. /*! Owed events to the bridge. */
  154. struct {
  155. /*! Time started sending the current digit. (Invalid if owed.dtmf_digit is zero.) */
  156. struct timeval dtmf_tv;
  157. /*! Digit currently sending into the bridge. (zero if not sending) */
  158. char dtmf_digit;
  159. } owed;
  160. /*! DTMF hook sequence state */
  161. struct {
  162. /*! Time at which the DTMF hooks should stop waiting for more digits to come. */
  163. struct timeval interdigit_timeout;
  164. /*! Collected DTMF digits for DTMF hooks. */
  165. char collected[MAXIMUM_DTMF_FEATURE_STRING];
  166. } dtmf_hook_state;
  167. /*! Non-zero if a T.38 session terminate is owed to the bridge. */
  168. char owed_t38_terminate;
  169. };
  170. /*!
  171. * \brief Try locking the bridge_channel.
  172. *
  173. * \param bridge_channel What to try locking
  174. *
  175. * \retval 0 on success.
  176. * \retval non-zero on error.
  177. */
  178. #define ast_bridge_channel_trylock(bridge_channel) _ast_bridge_channel_trylock(bridge_channel, __FILE__, __PRETTY_FUNCTION__, __LINE__, #bridge_channel)
  179. static inline int _ast_bridge_channel_trylock(struct ast_bridge_channel *bridge_channel, const char *file, const char *function, int line, const char *var)
  180. {
  181. return __ao2_trylock(bridge_channel, AO2_LOCK_REQ_MUTEX, file, function, line, var);
  182. }
  183. /*!
  184. * \brief Lock the bridge_channel.
  185. *
  186. * \param bridge_channel What to lock
  187. *
  188. * \return Nothing
  189. */
  190. #define ast_bridge_channel_lock(bridge_channel) _ast_bridge_channel_lock(bridge_channel, __FILE__, __PRETTY_FUNCTION__, __LINE__, #bridge_channel)
  191. static inline void _ast_bridge_channel_lock(struct ast_bridge_channel *bridge_channel, const char *file, const char *function, int line, const char *var)
  192. {
  193. __ao2_lock(bridge_channel, AO2_LOCK_REQ_MUTEX, file, function, line, var);
  194. }
  195. /*!
  196. * \brief Unlock the bridge_channel.
  197. *
  198. * \param bridge_channel What to unlock
  199. *
  200. * \return Nothing
  201. */
  202. #define ast_bridge_channel_unlock(bridge_channel) _ast_bridge_channel_unlock(bridge_channel, __FILE__, __PRETTY_FUNCTION__, __LINE__, #bridge_channel)
  203. static inline void _ast_bridge_channel_unlock(struct ast_bridge_channel *bridge_channel, const char *file, const char *function, int line, const char *var)
  204. {
  205. __ao2_unlock(bridge_channel, file, function, line, var);
  206. }
  207. /*!
  208. * \brief Lock the bridge associated with the bridge channel.
  209. * \since 12.0.0
  210. *
  211. * \param bridge_channel Channel that wants to lock the bridge.
  212. *
  213. * \details
  214. * This is an upstream lock operation. The defined locking
  215. * order is bridge then bridge_channel.
  216. *
  217. * \note On entry, neither the bridge nor bridge_channel is locked.
  218. *
  219. * \note The bridge_channel->bridge pointer changes because of a
  220. * bridge-merge/channel-move operation between bridges.
  221. *
  222. * \return Nothing
  223. */
  224. void ast_bridge_channel_lock_bridge(struct ast_bridge_channel *bridge_channel);
  225. /*!
  226. * \brief Lets the bridging indicate when a bridge channel has stopped or started talking.
  227. *
  228. * \note All DSP functionality on the bridge has been pushed down to the lowest possible
  229. * layer, which in this case is the specific bridging technology being used. Since it
  230. * is necessary for the knowledge of which channels are talking to make its way up to the
  231. * application, this function has been created to allow the bridging technology to communicate
  232. * that information with the bridging core.
  233. *
  234. * \param bridge_channel The bridge channel that has either started or stopped talking.
  235. * \param started_talking set to 1 when this indicates the channel has started talking set to 0
  236. * when this indicates the channel has stopped talking.
  237. *
  238. * \retval 0 on success.
  239. * \retval -1 on error.
  240. */
  241. int ast_bridge_channel_notify_talking(struct ast_bridge_channel *bridge_channel, int started_talking);
  242. /*!
  243. * \brief Set bridge channel state to leave bridge (if not leaving already).
  244. *
  245. * \param bridge_channel Channel to change the state on
  246. * \param new_state The new state to place the channel into
  247. * \param cause Cause of channel leaving bridge.
  248. * If cause <= 0 then use cause on channel if cause still <= 0 use AST_CAUSE_NORMAL_CLEARING.
  249. *
  250. * Example usage:
  251. *
  252. * \code
  253. * ast_bridge_channel_leave_bridge(bridge_channel, BRIDGE_CHANNEL_STATE_END, AST_CAUSE_NORMAL_CLEARING);
  254. * \endcode
  255. *
  256. * This places the channel pointed to by bridge_channel into the
  257. * state BRIDGE_CHANNEL_STATE_END if it was
  258. * BRIDGE_CHANNEL_STATE_WAIT before.
  259. */
  260. void ast_bridge_channel_leave_bridge(struct ast_bridge_channel *bridge_channel, enum bridge_channel_state new_state, int cause);
  261. /*!
  262. * \brief Set bridge channel state to leave bridge (if not leaving already).
  263. *
  264. * \param bridge_channel Channel to change the state on
  265. * \param new_state The new state to place the channel into
  266. * \param cause Cause of channel leaving bridge.
  267. * If cause <= 0 then use cause on channel if cause still <= 0 use AST_CAUSE_NORMAL_CLEARING.
  268. *
  269. * Example usage:
  270. *
  271. * \code
  272. * ast_bridge_channel_leave_bridge(bridge_channel, BRIDGE_CHANNEL_STATE_END, AST_CAUSE_NORMAL_CLEARING);
  273. * \endcode
  274. *
  275. * This places the channel pointed to by bridge_channel into the
  276. * state BRIDGE_CHANNEL_STATE_END if it was
  277. * BRIDGE_CHANNEL_STATE_WAIT before.
  278. */
  279. void ast_bridge_channel_leave_bridge_nolock(struct ast_bridge_channel *bridge_channel, enum bridge_channel_state new_state, int cause);
  280. /*!
  281. * \brief Get the peer bridge channel of a two party bridge.
  282. * \since 12.0.0
  283. *
  284. * \param bridge_channel What to get the peer of.
  285. *
  286. * \note On entry, bridge_channel->bridge is already locked.
  287. *
  288. * \note This is an internal bridge function.
  289. *
  290. * \retval peer on success.
  291. * \retval NULL no peer channel.
  292. */
  293. struct ast_bridge_channel *ast_bridge_channel_peer(struct ast_bridge_channel *bridge_channel);
  294. /*!
  295. * \brief Restore the formats of a bridge channel's channel to how they were before bridge_channel_internal_join
  296. * \since 12.0.0
  297. *
  298. * \param bridge_channel Channel to restore
  299. */
  300. void ast_bridge_channel_restore_formats(struct ast_bridge_channel *bridge_channel);
  301. /*!
  302. * \brief Adjust the bridge_channel's bridge merge inhibit request count.
  303. * \since 12.0.0
  304. *
  305. * \param bridge_channel What to operate on.
  306. * \param request Inhibit request increment.
  307. * (Positive to add requests. Negative to remove requests.)
  308. *
  309. * \note This API call is meant for internal bridging operations.
  310. *
  311. * \retval bridge adjusted merge inhibit with reference count.
  312. */
  313. struct ast_bridge *ast_bridge_channel_merge_inhibit(struct ast_bridge_channel *bridge_channel, int request);
  314. /*!
  315. * \internal
  316. * \brief Update the linkedids for all channels in a bridge
  317. * \since 12.0.0
  318. *
  319. * \param bridge_channel The channel joining the bridge
  320. * \param swap The channel being swapped out of the bridge. May be NULL.
  321. *
  322. * \note The bridge must be locked prior to calling this function.
  323. * \note This should be called during a \ref bridge_channel_internal_push
  324. * operation, typically by a sub-class of a bridge.
  325. */
  326. void ast_bridge_channel_update_linkedids(struct ast_bridge_channel *bridge_channel, struct ast_bridge_channel *swap);
  327. /*!
  328. * \internal
  329. * \brief Update the accountcodes for channels joining/leaving a bridge
  330. * \since 12.0.0
  331. *
  332. * This function updates the accountcode and peeraccount on channels in two-party
  333. * bridges. In multi-party bridges, peeraccount is not set - it doesn't make much sense -
  334. * however accountcode propagation will still occur if the channel joining has an
  335. * accountcode.
  336. *
  337. * \param joining The channel joining the bridge. May be NULL.
  338. * \param leaving The channel leaving or being swapped out of the bridge. May be NULL.
  339. *
  340. * \note The joining and leaving parameters cannot both be NULL.
  341. *
  342. * \note The bridge must be locked prior to calling this function.
  343. * \note This should be called during a \ref bridge_channel_internal_push
  344. * or \ref bridge_channel_internal_pull operation, typically by a
  345. * sub-class of a bridge.
  346. */
  347. void ast_bridge_channel_update_accountcodes(struct ast_bridge_channel *joining, struct ast_bridge_channel *leaving);
  348. /*!
  349. * \brief Write a frame to the specified bridge_channel.
  350. * \since 12.0.0
  351. *
  352. * \param bridge_channel Channel to queue the frame.
  353. * \param fr Frame to write.
  354. *
  355. * \retval 0 on success.
  356. * \retval -1 on error.
  357. */
  358. int ast_bridge_channel_queue_frame(struct ast_bridge_channel *bridge_channel, struct ast_frame *fr);
  359. /*!
  360. * \brief Queue a control frame onto the bridge channel with data.
  361. * \since 12.0.0
  362. *
  363. * \param bridge_channel Which channel to queue the frame onto.
  364. * \param control Type of control frame.
  365. * \param data Frame payload data to pass.
  366. * \param datalen Frame payload data length to pass.
  367. *
  368. * \retval 0 on success.
  369. * \retval -1 on error.
  370. */
  371. int ast_bridge_channel_queue_control_data(struct ast_bridge_channel *bridge_channel, enum ast_control_frame_type control, const void *data, size_t datalen);
  372. /*!
  373. * \brief Write a control frame into the bridge with data.
  374. * \since 12.0.0
  375. *
  376. * \param bridge_channel Which channel is putting the frame into the bridge.
  377. * \param control Type of control frame.
  378. * \param data Frame payload data to pass.
  379. * \param datalen Frame payload data length to pass.
  380. *
  381. * \retval 0 on success.
  382. * \retval -1 on error.
  383. */
  384. int ast_bridge_channel_write_control_data(struct ast_bridge_channel *bridge_channel, enum ast_control_frame_type control, const void *data, size_t datalen);
  385. /*!
  386. * \brief Write a hold frame into the bridge.
  387. * \since 12.0.0
  388. *
  389. * \param bridge_channel Which channel is putting the hold into the bridge.
  390. * \param moh_class The suggested music class for the other end to use.
  391. *
  392. * \retval 0 on success.
  393. * \retval -1 on error.
  394. */
  395. int ast_bridge_channel_write_hold(struct ast_bridge_channel *bridge_channel, const char *moh_class);
  396. /*!
  397. * \brief Write an unhold frame into the bridge.
  398. * \since 12.0.0
  399. *
  400. * \param bridge_channel Which channel is putting the hold into the bridge.
  401. *
  402. * \retval 0 on success.
  403. * \retval -1 on error.
  404. */
  405. int ast_bridge_channel_write_unhold(struct ast_bridge_channel *bridge_channel);
  406. /*!
  407. * \brief Run an application on the bridge channel.
  408. * \since 12.0.0
  409. *
  410. * \param bridge_channel Which channel to run the application on.
  411. * \param app_name Dialplan application name.
  412. * \param app_args Arguments for the application. (NULL tolerant)
  413. * \param moh_class MOH class to request bridge peers to hear while application is running.
  414. * NULL if no MOH.
  415. * Empty if default MOH class.
  416. *
  417. * \note This is intended to be called by bridge hooks.
  418. *
  419. * \return Nothing
  420. */
  421. void ast_bridge_channel_run_app(struct ast_bridge_channel *bridge_channel, const char *app_name, const char *app_args, const char *moh_class);
  422. /*!
  423. * \brief Write a bridge action run application frame into the bridge.
  424. * \since 12.0.0
  425. *
  426. * \param bridge_channel Which channel is putting the frame into the bridge
  427. * \param app_name Dialplan application name.
  428. * \param app_args Arguments for the application. (NULL or empty for no arguments)
  429. * \param moh_class MOH class to request bridge peers to hear while application is running.
  430. * NULL if no MOH.
  431. * Empty if default MOH class.
  432. *
  433. * \note This is intended to be called by bridge hooks.
  434. *
  435. * \retval 0 on success.
  436. * \retval -1 on error.
  437. */
  438. int ast_bridge_channel_write_app(struct ast_bridge_channel *bridge_channel, const char *app_name, const char *app_args, const char *moh_class);
  439. /*!
  440. * \brief Queue a bridge action run application frame onto the bridge channel.
  441. * \since 12.0.0
  442. *
  443. * \param bridge_channel Which channel to put the frame onto
  444. * \param app_name Dialplan application name.
  445. * \param app_args Arguments for the application. (NULL or empty for no arguments)
  446. * \param moh_class MOH class to request bridge peers to hear while application is running.
  447. * NULL if no MOH.
  448. * Empty if default MOH class.
  449. *
  450. * \note This is intended to be called by bridge hooks.
  451. *
  452. * \retval 0 on success.
  453. * \retval -1 on error.
  454. */
  455. int ast_bridge_channel_queue_app(struct ast_bridge_channel *bridge_channel, const char *app_name, const char *app_args, const char *moh_class);
  456. /*!
  457. * \brief Custom interpretation of the playfile name.
  458. *
  459. * \param bridge_channel Which channel to play the file on
  460. * \param playfile Sound filename to play.
  461. *
  462. * \return Nothing
  463. */
  464. typedef void (*ast_bridge_custom_play_fn)(struct ast_bridge_channel *bridge_channel, const char *playfile);
  465. /*!
  466. * \brief Play a file on the bridge channel.
  467. * \since 12.0.0
  468. *
  469. * \param bridge_channel Which channel to play the file on
  470. * \param custom_play Call this function to play the playfile. (NULL if normal sound file to play)
  471. * \param playfile Sound filename to play.
  472. * \param moh_class MOH class to request bridge peers to hear while file is played.
  473. * NULL if no MOH.
  474. * Empty if default MOH class.
  475. *
  476. * \note This is intended to be called by bridge hooks.
  477. *
  478. * \return Nothing
  479. */
  480. void ast_bridge_channel_playfile(struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class);
  481. /*!
  482. * \brief Write a bridge action play file frame into the bridge.
  483. * \since 12.0.0
  484. *
  485. * \param bridge_channel Which channel is putting the frame into the bridge
  486. * \param custom_play Call this function to play the playfile. (NULL if normal sound file to play)
  487. * \param playfile Sound filename to play.
  488. * \param moh_class MOH class to request bridge peers to hear while file is played.
  489. * NULL if no MOH.
  490. * Empty if default MOH class.
  491. *
  492. * \note This is intended to be called by bridge hooks.
  493. *
  494. * \retval 0 on success.
  495. * \retval -1 on error.
  496. */
  497. int ast_bridge_channel_write_playfile(struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class);
  498. /*!
  499. * \brief Queue a bridge action play file frame onto the bridge channel.
  500. * \since 12.0.0
  501. *
  502. * \param bridge_channel Which channel to put the frame onto.
  503. * \param custom_play Call this function to play the playfile. (NULL if normal sound file to play)
  504. * \param playfile Sound filename to play.
  505. * \param moh_class MOH class to request bridge peers to hear while file is played.
  506. * NULL if no MOH.
  507. * Empty if default MOH class.
  508. *
  509. * \note This is intended to be called by bridge hooks.
  510. *
  511. * \retval 0 on success.
  512. * \retval -1 on error.
  513. */
  514. int ast_bridge_channel_queue_playfile(struct ast_bridge_channel *bridge_channel, ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class);
  515. /*!
  516. * \brief Synchronously queue a bridge action play file frame onto the bridge channel.
  517. * \since 12.2.0
  518. *
  519. * \param bridge_channel Which channel to put the frame onto.
  520. * \param custom_play Call this function to play the playfile. (NULL if normal sound file to play)
  521. * \param playfile Sound filename to play.
  522. * \param moh_class MOH class to request bridge peers to hear while file is played.
  523. * NULL if no MOH.
  524. * Empty if default MOH class.
  525. *
  526. * This function will block until the queued frame has been destroyed. This will happen
  527. * either if an error occurs or if the queued playback finishes.
  528. *
  529. * \note No locks may be held when calling this function.
  530. *
  531. * \retval 0 The playback was successfully queued.
  532. * \retval -1 The playback could not be queued.
  533. */
  534. int ast_bridge_channel_queue_playfile_sync(struct ast_bridge_channel *bridge_channel,
  535. ast_bridge_custom_play_fn custom_play, const char *playfile, const char *moh_class);
  536. /*!
  537. * \brief Custom callback run on a bridge channel.
  538. *
  539. * \param bridge_channel Which channel to operate on.
  540. * \param payload Data to pass to the callback. (NULL if none).
  541. * \param payload_size Size of the payload if payload is non-NULL. A number otherwise.
  542. *
  543. * \note The payload MUST NOT have any resources that need to be freed.
  544. *
  545. * \return Nothing
  546. */
  547. typedef void (*ast_bridge_custom_callback_fn)(struct ast_bridge_channel *bridge_channel, const void *payload, size_t payload_size);
  548. enum ast_bridge_channel_custom_callback_option {
  549. /*! The callback temporarily affects media. (Like a custom playfile.) */
  550. AST_BRIDGE_CHANNEL_CB_OPTION_MEDIA = (1 << 0),
  551. };
  552. /*!
  553. * \brief Write a bridge action custom callback frame into the bridge.
  554. * \since 12.0.0
  555. *
  556. * \param bridge_channel Which channel is putting the frame into the bridge
  557. * \param flags Custom callback option flags.
  558. * \param callback Custom callback run on a bridge channel.
  559. * \param payload Data to pass to the callback. (NULL if none).
  560. * \param payload_size Size of the payload if payload is non-NULL. A number otherwise.
  561. *
  562. * \note The payload MUST NOT have any resources that need to be freed.
  563. *
  564. * \note This is intended to be called by bridge hooks.
  565. *
  566. * \retval 0 on success.
  567. * \retval -1 on error.
  568. */
  569. int ast_bridge_channel_write_callback(struct ast_bridge_channel *bridge_channel,
  570. enum ast_bridge_channel_custom_callback_option flags,
  571. ast_bridge_custom_callback_fn callback, const void *payload, size_t payload_size);
  572. /*!
  573. * \brief Queue a bridge action custom callback frame onto the bridge channel.
  574. * \since 12.0.0
  575. *
  576. * \param bridge_channel Which channel to put the frame onto.
  577. * \param flags Custom callback option flags.
  578. * \param callback Custom callback run on a bridge channel.
  579. * \param payload Data to pass to the callback. (NULL if none).
  580. * \param payload_size Size of the payload if payload is non-NULL. A number otherwise.
  581. *
  582. * \note The payload MUST NOT have any resources that need to be freed.
  583. *
  584. * \note This is intended to be called by bridge hooks.
  585. *
  586. * \retval 0 on success.
  587. * \retval -1 on error.
  588. */
  589. int ast_bridge_channel_queue_callback(struct ast_bridge_channel *bridge_channel,
  590. enum ast_bridge_channel_custom_callback_option flags,
  591. ast_bridge_custom_callback_fn callback, const void *payload, size_t payload_size);
  592. /*!
  593. * \brief Have a bridge channel park a channel in the bridge
  594. * \since 12.0.0
  595. *
  596. * \param bridge_channel Bridge channel performing the parking
  597. * \param parkee_uuid Unique id of the channel we want to park
  598. * \param parker_uuid Unique id of the channel parking the call
  599. * \param app_data string indicating data used for park application (NULL allowed)
  600. *
  601. * \note This is intended to be called by bridge hooks.
  602. *
  603. * \retval 0 on success.
  604. * \retval -1 on error.
  605. */
  606. int ast_bridge_channel_write_park(struct ast_bridge_channel *bridge_channel, const char *parkee_uuid,
  607. const char *parker_uuid, const char *app_data);
  608. /*!
  609. * \brief Kick the channel out of the bridge.
  610. * \since 12.0.0
  611. *
  612. * \param bridge_channel Which channel is being kicked or hungup.
  613. * \param cause Cause of channel being kicked.
  614. * If cause <= 0 then use cause on channel if cause still <= 0 use AST_CAUSE_NORMAL_CLEARING.
  615. *
  616. * \note This is intended to be called by bridge hooks and the
  617. * bridge channel thread.
  618. *
  619. * \return Nothing
  620. */
  621. void ast_bridge_channel_kick(struct ast_bridge_channel *bridge_channel, int cause);
  622. /*!
  623. * \brief Add a DTMF digit to the collected digits.
  624. * \since 13.3.0
  625. *
  626. * \param bridge_channel Channel that received a DTMF digit.
  627. * \param digit DTMF digit to add to collected digits
  628. *
  629. * \note Neither the bridge nor the bridge_channel locks should be held
  630. * when entering this function.
  631. *
  632. * \note This is can only be called from within DTMF bridge hooks.
  633. */
  634. void ast_bridge_channel_feature_digit_add(struct ast_bridge_channel *bridge_channel, int digit);
  635. /*!
  636. * \brief Add a DTMF digit to the collected digits to match against DTMF features.
  637. * \since 12.8.0
  638. *
  639. * \param bridge_channel Channel that received a DTMF digit.
  640. * \param digit DTMF digit to add to collected digits or 0 for timeout event.
  641. * \param clear_digits clear the digits array prior to calling hooks
  642. *
  643. * \note Neither the bridge nor the bridge_channel locks should be held
  644. * when entering this function.
  645. *
  646. * \note This is intended to be called by bridge hooks and the
  647. * bridge channel thread.
  648. *
  649. * \note This is intended to be called by non-DTMF bridge hooks and the bridge
  650. * channel thread. Calling from a DTMF bridge hook can potentially cause
  651. * unbounded recursion.
  652. *
  653. * \return Nothing
  654. */
  655. void ast_bridge_channel_feature_digit(struct ast_bridge_channel *bridge_channel, int digit);
  656. #if defined(__cplusplus) || defined(c_plusplus)
  657. }
  658. #endif
  659. #endif /* _ASTERISK_BRIDGING_CHANNEL_H */