core_unreal.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013 Digium, Inc.
  5. *
  6. * Richard Mudgett <rmudgett@digium.com>
  7. *
  8. * See http://www.asterisk.org for more information about
  9. * the Asterisk project. Please do not directly contact
  10. * any of the maintainers of this project for assistance;
  11. * the project provides a web site, mailing lists and IRC
  12. * channels for your use.
  13. *
  14. * This program is free software, distributed under the terms of
  15. * the GNU General Public License Version 2. See the LICENSE file
  16. * at the top of the source tree.
  17. */
  18. /*!
  19. * \file
  20. * \brief Unreal channel derivative framework.
  21. *
  22. * \author Richard Mudgett <rmudgett@digium.com>
  23. *
  24. * See Also:
  25. * \arg \ref AstCREDITS
  26. */
  27. #ifndef _ASTERISK_CORE_UNREAL_H
  28. #define _ASTERISK_CORE_UNREAL_H
  29. #include "asterisk/astobj2.h"
  30. #include "asterisk/channel.h"
  31. #include "asterisk/bridge.h"
  32. #include "asterisk/abstract_jb.h"
  33. #if defined(__cplusplus) || defined(c_plusplus)
  34. extern "C" {
  35. #endif
  36. /* Forward declare some struct names */
  37. struct ast_format_cap;
  38. struct ast_callid;
  39. /* ------------------------------------------------------------------- */
  40. struct ast_unreal_pvt;
  41. enum ast_unreal_channel_indicator {
  42. AST_UNREAL_OWNER,
  43. AST_UNREAL_CHAN,
  44. };
  45. /*!
  46. * \brief Callbacks that can be provided by concrete implementations of the unreal
  47. * channel driver that will be called when events occur in the unreal layer
  48. */
  49. struct ast_unreal_pvt_callbacks {
  50. /*!
  51. * \brief Called when an optimization attempt has started
  52. * \note p is locked when this callback is called
  53. * \param p The \ref ast_unreal_pvt object
  54. * \param source The channel that is optimizing into an unreal_pvt channel's bridge.
  55. * If NULL, the optimization is being accomplished via a bridge merge.
  56. * \param dest Indicator of which channel's bridge in the unreal_pvt will survive the
  57. * optimization
  58. * \param id Unique identifier for this optimization operation.
  59. */
  60. void (* const optimization_started)(struct ast_unreal_pvt *p, struct ast_channel *source,
  61. enum ast_unreal_channel_indicator dest, unsigned int id);
  62. /*!
  63. * \brief Called when an optimization attempt completed successfully
  64. * \note p is locked when this callback is called
  65. * \param p The \ref ast_unreal_pvt object
  66. * \param success Non-zero if the optimization succeeded, zero if the optimization
  67. * met with fatal and permanent error
  68. * \param id Unique identifier for this optimization. Same as the one from the optimization_started
  69. * call
  70. */
  71. void (* const optimization_finished)(struct ast_unreal_pvt *p, int success, unsigned int id);
  72. };
  73. /*!
  74. * \brief The base pvt structure for local channel derivatives.
  75. *
  76. * The unreal pvt has two ast_chan objects - the "owner" and the "next channel", the outbound channel
  77. *
  78. * ast_chan owner -> ast_unreal_pvt -> ast_chan chan
  79. */
  80. struct ast_unreal_pvt {
  81. struct ast_unreal_pvt_callbacks *callbacks; /*!< Event callbacks */
  82. struct ast_channel *owner; /*!< Master Channel - ;1 side */
  83. struct ast_channel *chan; /*!< Outbound channel - ;2 side */
  84. struct ast_format_cap *reqcap; /*!< Requested format capabilities */
  85. struct ast_jb_conf jb_conf; /*!< jitterbuffer configuration */
  86. unsigned int flags; /*!< Private option flags */
  87. /*! Base name of the unreal channels. exten@context or other name. */
  88. char name[AST_MAX_EXTENSION + AST_MAX_CONTEXT + 2];
  89. };
  90. #define AST_UNREAL_IS_OUTBOUND(a, b) ((a) == (b)->chan ? 1 : 0)
  91. #define AST_UNREAL_CARETAKER_THREAD (1 << 0) /*!< The ;2 side launched a PBX, was pushed into a bridge, or was masqueraded into an application. */
  92. #define AST_UNREAL_NO_OPTIMIZATION (1 << 1) /*!< Do not optimize out the unreal channels */
  93. #define AST_UNREAL_MOH_INTERCEPT (1 << 2) /*!< Intercept and act on hold/unhold control frames */
  94. #define AST_UNREAL_OPTIMIZE_BEGUN (1 << 3) /*!< Indicates that an optimization attempt has been started */
  95. /*!
  96. * \brief Send an unreal pvt in with no locks held and get all locks
  97. *
  98. * \note NO locks should be held prior to calling this function
  99. * \note The pvt must have a ref held before calling this function
  100. * \note if outchan or outowner is set != NULL after calling this function
  101. * those channels are locked and reffed.
  102. * \note Batman.
  103. */
  104. void ast_unreal_lock_all(struct ast_unreal_pvt *p, struct ast_channel **outchan, struct ast_channel **outowner);
  105. /*!
  106. * \brief Hangup one end (maybe both ends) of an unreal channel derivative.
  107. * \since 12.0.0
  108. *
  109. * \param p Private channel struct (reffed)
  110. * \param ast Channel being hung up. (locked)
  111. *
  112. * \note Common hangup code for unreal channels. Derived
  113. * channels will need to deal with any additional resources.
  114. *
  115. * \retval 0 on success.
  116. * \retval -1 on error.
  117. */
  118. int ast_unreal_hangup(struct ast_unreal_pvt *p, struct ast_channel *ast);
  119. /*! Unreal channel framework struct ast_channel_tech.send_digit_begin callback */
  120. int ast_unreal_digit_begin(struct ast_channel *ast, char digit);
  121. /*! Unreal channel framework struct ast_channel_tech.send_digit_end callback */
  122. int ast_unreal_digit_end(struct ast_channel *ast, char digit, unsigned int duration);
  123. /*! Unreal channel framework struct ast_channel_tech.answer callback */
  124. int ast_unreal_answer(struct ast_channel *ast);
  125. /*! Unreal channel framework struct ast_channel_tech.read and struct ast_channel_tech.exception callback */
  126. struct ast_frame *ast_unreal_read(struct ast_channel *ast);
  127. /*! Unreal channel framework struct ast_channel_tech.write callback */
  128. int ast_unreal_write(struct ast_channel *ast, struct ast_frame *f);
  129. /*! Unreal channel framework struct ast_channel_tech.indicate callback */
  130. int ast_unreal_indicate(struct ast_channel *ast, int condition, const void *data, size_t datalen);
  131. /*! Unreal channel framework struct ast_channel_tech.fixup callback */
  132. int ast_unreal_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
  133. /*! Unreal channel framework struct ast_channel_tech.send_html callback */
  134. int ast_unreal_sendhtml(struct ast_channel *ast, int subclass, const char *data, int datalen);
  135. /*! Unreal channel framework struct ast_channel_tech.send_text callback */
  136. int ast_unreal_sendtext(struct ast_channel *ast, const char *text);
  137. /*! Unreal channel framework struct ast_channel_tech.queryoption callback */
  138. int ast_unreal_queryoption(struct ast_channel *ast, int option, void *data, int *datalen);
  139. /*! Unreal channel framework struct ast_channel_tech.setoption callback */
  140. int ast_unreal_setoption(struct ast_channel *chan, int option, void *data, int datalen);
  141. /*!
  142. * \brief struct ast_unreal_pvt destructor.
  143. * \since 12.0.0
  144. *
  145. * \param vdoomed Object to destroy.
  146. *
  147. * \return Nothing
  148. */
  149. void ast_unreal_destructor(void *vdoomed);
  150. /*!
  151. * \brief Allocate the base unreal struct for a derivative.
  152. * \since 12.0.0
  153. *
  154. * \param size Size of the unreal struct to allocate.
  155. * \param destructor Destructor callback.
  156. * \param cap Format capabilities to give the unreal private struct.
  157. *
  158. * \retval pvt on success.
  159. * \retval NULL on error.
  160. */
  161. struct ast_unreal_pvt *ast_unreal_alloc(size_t size, ao2_destructor_fn destructor, struct ast_format_cap *cap);
  162. /*!
  163. * \brief Create the semi1 and semi2 unreal channels.
  164. * \since 12.0.0
  165. *
  166. * \param p Unreal channel private struct.
  167. * \param tech Channel technology to use.
  168. * \param semi1_state State to start the semi1(owner) channel in.
  169. * \param semi2_state State to start the semi2(outgoing chan) channel in.
  170. * \param exten Exten to start the chennels in. (NULL if s)
  171. * \param context Context to start the channels in. (NULL if default)
  172. * \param requestor Channel requesting creation. (NULL if none)
  173. * \param callid Thread callid to use.
  174. *
  175. * \retval semi1_channel on success.
  176. * \retval NULL on error.
  177. */
  178. struct ast_channel *ast_unreal_new_channels(struct ast_unreal_pvt *p,
  179. const struct ast_channel_tech *tech, int semi1_state, int semi2_state,
  180. const char *exten, const char *context, const struct ast_assigned_ids *assignedids,
  181. const struct ast_channel *requestor, struct ast_callid *callid);
  182. /*!
  183. * \brief Setup unreal owner and chan channels before initiating call.
  184. * \since 12.0.0
  185. *
  186. * \param semi1 Owner channel of unreal channel pair.
  187. * \param semi2 Outgoing channel of unreal channel pair.
  188. *
  189. * \note On entry, the semi1 and semi2 channels are already locked.
  190. *
  191. * \return Nothing
  192. */
  193. void ast_unreal_call_setup(struct ast_channel *semi1, struct ast_channel *semi2);
  194. /*!
  195. * \brief Push the semi2 unreal channel into a bridge from either member of the unreal pair
  196. * \since 12.0.0
  197. *
  198. * \param ast A member of the unreal channel being pushed
  199. * \param bridge Which bridge we want to push the channel to
  200. * \param flags Feature flags to be set on the bridge channel.
  201. *
  202. * \retval 0 if the channel is successfully imparted onto the bridge
  203. * \retval -1 on failure
  204. *
  205. * \note This is equivalent to ast_call() on unreal based channel drivers that are designed to use it instead.
  206. */
  207. int ast_unreal_channel_push_to_bridge(struct ast_channel *ast, struct ast_bridge *bridge, unsigned int flags);
  208. /* ------------------------------------------------------------------- */
  209. #if defined(__cplusplus) || defined(c_plusplus)
  210. }
  211. #endif
  212. #endif /* _ASTERISK_CORE_UNREAL_H */