bridge_technology.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2009, Digium, Inc.
  5. *
  6. * Joshua Colp <jcolp@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*! \file
  19. * \brief Channel Bridging API
  20. * \author Joshua Colp <jcolp@digium.com>
  21. */
  22. #ifndef _ASTERISK_BRIDGING_TECHNOLOGY_H
  23. #define _ASTERISK_BRIDGING_TECHNOLOGY_H
  24. #if defined(__cplusplus) || defined(c_plusplus)
  25. extern "C" {
  26. #endif
  27. /*!
  28. * \brief Base preference values for choosing a bridge technology.
  29. *
  30. * \note Higher is more preference.
  31. */
  32. enum ast_bridge_preference {
  33. AST_BRIDGE_PREFERENCE_BASE_HOLDING = 50,
  34. AST_BRIDGE_PREFERENCE_BASE_EARLY = 100,
  35. AST_BRIDGE_PREFERENCE_BASE_NATIVE = 90,
  36. AST_BRIDGE_PREFERENCE_BASE_1TO1MIX = 50,
  37. AST_BRIDGE_PREFERENCE_BASE_MULTIMIX = 10,
  38. };
  39. /*!
  40. * \brief Structure specific to bridge technologies capable of
  41. * performing talking optimizations.
  42. */
  43. struct ast_bridge_tech_optimizations {
  44. /*! Minimum average magnitude threshold to determine talking by the DSP. */
  45. unsigned int talking_threshold;
  46. /*! Time in ms of silence necessary to declare talking stopped by the bridge. */
  47. unsigned int silence_threshold;
  48. /*! Whether or not the bridging technology should drop audio
  49. * detected as silence from the mix. */
  50. unsigned int drop_silence:1;
  51. };
  52. /*!
  53. * \brief Structure that is the essence of a bridge technology
  54. */
  55. struct ast_bridge_technology {
  56. /*! Unique name to this bridge technology */
  57. const char *name;
  58. /*! The capabilities that this bridge technology is capable of. This has nothing to do with
  59. * format capabilities. */
  60. uint32_t capabilities;
  61. /*! Preference level that should be used when determining whether to use this bridge technology or not */
  62. enum ast_bridge_preference preference;
  63. /*!
  64. * \brief Create a bridge technology instance for a bridge.
  65. *
  66. * \retval 0 on success
  67. * \retval -1 on failure
  68. *
  69. * \note On entry, bridge may or may not already be locked.
  70. * However, it can be accessed as if it were locked.
  71. */
  72. int (*create)(struct ast_bridge *bridge);
  73. /*!
  74. * \brief Request a bridge technology instance start operations.
  75. *
  76. * \retval 0 on success
  77. * \retval -1 on failure
  78. *
  79. * \note On entry, bridge may or may not already be locked.
  80. * However, it can be accessed as if it were locked.
  81. */
  82. int (*start)(struct ast_bridge *bridge);
  83. /*!
  84. * \brief Request a bridge technology instance stop in preparation for being destroyed.
  85. *
  86. * \note On entry, bridge is already locked.
  87. */
  88. void (*stop)(struct ast_bridge *bridge);
  89. /*!
  90. * \brief Destroy a bridging technology instance for a bridge.
  91. *
  92. * \note On entry, bridge must NOT be locked.
  93. */
  94. void (*destroy)(struct ast_bridge *bridge);
  95. /*!
  96. * \brief Add a channel to a bridging technology instance for a bridge.
  97. *
  98. * \retval 0 on success
  99. * \retval -1 on failure
  100. *
  101. * \note On entry, bridge is already locked.
  102. *
  103. * \note The bridge technology must tolerate a failed to join channel
  104. * until it can be kicked from the bridge.
  105. *
  106. * \note A channel may be in a suspended state already when joining a bridge
  107. * technology. The technology must handle this case.
  108. *
  109. * \note A channel may not be answered when joining a bridge technology.
  110. */
  111. int (*join)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
  112. /*!
  113. * \brief Remove a channel from a bridging technology instance for a bridge.
  114. *
  115. * \note On entry, bridge is already locked.
  116. * \note Do not make assumptions about the number of channels in the bridge when
  117. * this callback is called. When a channel is swapped into a bridge for another
  118. * channel, the leave callback is called after the new channel has been added to
  119. * the bridge.
  120. */
  121. void (*leave)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
  122. /*!
  123. * \brief Suspend a channel on a bridging technology instance for a bridge.
  124. *
  125. * \note On entry, bridge is already locked.
  126. */
  127. void (*suspend)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
  128. /*!
  129. * \brief Unsuspend a channel on a bridging technology instance for a bridge.
  130. *
  131. * \note On entry, bridge is already locked.
  132. */
  133. void (*unsuspend)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
  134. /*!
  135. * \brief Check if a bridge is compatible with the bridging technology.
  136. *
  137. * \retval 0 if not compatible
  138. * \retval non-zero if compatible
  139. *
  140. * \note On entry, bridge may or may not already be locked.
  141. * However, it can be accessed as if it were locked.
  142. */
  143. int (*compatible)(struct ast_bridge *bridge);
  144. /*!
  145. * \brief Write a frame into the bridging technology instance for a bridge.
  146. *
  147. * \note The bridge must be tolerant of bridge_channel being NULL.
  148. *
  149. * \retval 0 Frame accepted into the bridge.
  150. * \retval -1 Frame needs to be deferred.
  151. *
  152. * \note On entry, bridge is already locked.
  153. *
  154. * \note Deferred frames will be automatically queued onto the channel when another
  155. * channel joins the bridge.
  156. */
  157. int (*write)(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, struct ast_frame *frame);
  158. /*!
  159. * \brief Formats that the bridge technology supports
  160. * \note This is no longer used. It remains for ABI compatibility.
  161. */
  162. struct ast_format_cap *format_capabilities;
  163. /*! TRUE if the bridge technology is currently suspended. */
  164. unsigned int suspended:1;
  165. /*! Module this bridge technology belongs to. It is used for reference counting bridges using the technology. */
  166. struct ast_module *mod;
  167. /*! Linked list information */
  168. AST_RWLIST_ENTRY(ast_bridge_technology) entry;
  169. };
  170. /*!
  171. * \brief Register a bridge technology for use
  172. *
  173. * \param technology The bridge technology to register
  174. * \param mod The module that is registering the bridge technology
  175. *
  176. * \retval 0 on success
  177. * \retval -1 on failure
  178. *
  179. * Example usage:
  180. *
  181. * \code
  182. * ast_bridge_technology_register(&simple_bridge_tech);
  183. * \endcode
  184. *
  185. * This registers a bridge technology declared as the structure
  186. * simple_bridge_tech with the bridging core and makes it available for
  187. * use when creating bridges.
  188. */
  189. int __ast_bridge_technology_register(struct ast_bridge_technology *technology, struct ast_module *mod);
  190. /*! \brief See \ref __ast_bridge_technology_register() */
  191. #define ast_bridge_technology_register(technology) __ast_bridge_technology_register(technology, ast_module_info->self)
  192. /*!
  193. * \brief Unregister a bridge technology from use
  194. *
  195. * \param technology The bridge technology to unregister
  196. *
  197. * \retval 0 on success
  198. * \retval -1 on failure
  199. *
  200. * Example usage:
  201. *
  202. * \code
  203. * ast_bridge_technology_unregister(&simple_bridge_tech);
  204. * \endcode
  205. *
  206. * This unregisters a bridge technlogy declared as the structure
  207. * simple_bridge_tech with the bridging core. It will no longer be
  208. * considered when creating a new bridge.
  209. */
  210. int ast_bridge_technology_unregister(struct ast_bridge_technology *technology);
  211. /*!
  212. * \brief Suspend a bridge technology from consideration
  213. *
  214. * \param technology The bridge technology to suspend
  215. *
  216. * Example usage:
  217. *
  218. * \code
  219. * ast_bridge_technology_suspend(&simple_bridge_tech);
  220. * \endcode
  221. *
  222. * This suspends the bridge technology simple_bridge_tech from being considered
  223. * when creating a new bridge. Existing bridges using the bridge technology
  224. * are not affected.
  225. */
  226. void ast_bridge_technology_suspend(struct ast_bridge_technology *technology);
  227. /*!
  228. * \brief Unsuspend a bridge technology
  229. *
  230. * \param technology The bridge technology to unsuspend
  231. *
  232. * Example usage:
  233. *
  234. * \code
  235. * ast_bridge_technology_unsuspend(&simple_bridge_tech);
  236. * \endcode
  237. *
  238. * This makes the bridge technology simple_bridge_tech considered when
  239. * creating a new bridge again.
  240. */
  241. void ast_bridge_technology_unsuspend(struct ast_bridge_technology *technology);
  242. #if defined(__cplusplus) || defined(c_plusplus)
  243. }
  244. #endif
  245. #endif /* _ASTERISK_BRIDGING_TECHNOLOGY_H */