indications.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2002, Pauline Middelink
  5. * Copyright (C) 2009, Digium, Inc.
  6. *
  7. * See http://www.asterisk.org for more information about
  8. * the Asterisk project. Please do not directly contact
  9. * any of the maintainers of this project for assistance;
  10. * the project provides a web site, mailing lists and IRC
  11. * channels for your use.
  12. *
  13. * This program is free software, distributed under the terms of
  14. * the GNU General Public License Version 2. See the LICENSE file
  15. * at the top of the source tree.
  16. */
  17. /*!
  18. * \file
  19. * \brief Tone Indication Support
  20. *
  21. * \author Pauline Middelink <middelink@polyware.nl>
  22. * \author Russell Bryant <russell@digium.com>
  23. */
  24. #ifndef _ASTERISK_INDICATIONS_H
  25. #define _ASTERISK_INDICATIONS_H
  26. #include "asterisk/astobj2.h"
  27. #include "asterisk/utils.h"
  28. #include "asterisk/data.h"
  29. /*!
  30. * \brief Description of a tone
  31. */
  32. struct ast_tone_zone_sound {
  33. /*! \brief Name of the tone. For example, "busy". */
  34. const char *name;
  35. /*!
  36. * \brief Description of a tone
  37. *
  38. * The format is a comma separated list of tone parts in the following format:
  39. *
  40. * Format: [!][M]freq[<+|*>freq2][/duration]
  41. * - '!' - means that the element is NOT repeated
  42. * - 'M' - interpret the frequencies as midi notes instead of frequencies
  43. * - freq - The first frequency
  44. * - freq2 - The second frequency (optional)
  45. * - '*' - modulate freq by freq2 at a fixed depth of 90%
  46. * - '+' - combine the frequencies
  47. * - duration - the length of the tone part (optional, forever if not specified)
  48. */
  49. const char *data;
  50. /*! \brief Linked list fields for including in the list on an ast_tone_zone */
  51. AST_LIST_ENTRY(ast_tone_zone_sound) entry;
  52. /*! \brief Flags only used internally */
  53. union {
  54. uint32_t __padding;
  55. struct {
  56. unsigned int killme:1;
  57. };
  58. };
  59. };
  60. #define MAX_TONEZONE_COUNTRY 16
  61. /*!
  62. * \brief A set of tones for a given locale
  63. *
  64. * \note If a reference to this tone zone is held, then the country
  65. * is guaranteed not to change. It is safe to read it without
  66. * locking the tone zone. This is not the case for any other
  67. * field.
  68. */
  69. struct ast_tone_zone {
  70. /*! \brief Country code that this set of tones is for */
  71. char country[MAX_TONEZONE_COUNTRY];
  72. /*!
  73. * \brief Text description of the given country.
  74. *
  75. * This is for nothing more than friendly display to a human.
  76. */
  77. char description[40];
  78. /*! \brief Number of ring cadence elements in the ringcadence array */
  79. unsigned int nrringcadence;
  80. /*!
  81. * \brief Array of ring cadence parts
  82. *
  83. * Each element is an amount of time in milliseconds. The first element
  84. * is for time on, and from there it alternates between on and off.
  85. */
  86. int *ringcadence;
  87. /*! \brief A list of tones for this locale */
  88. AST_LIST_HEAD_NOLOCK(, ast_tone_zone_sound) tones;
  89. /*! \brief Flags only used internally */
  90. union {
  91. uint32_t __padding;
  92. struct {
  93. unsigned int killme:1;
  94. };
  95. };
  96. };
  97. /*!
  98. * \brief A description of a part of a tone
  99. *
  100. * The elements in this structure map to the format described for the data
  101. * part of the ast_tone_zone_sound struct.
  102. */
  103. struct ast_tone_zone_part {
  104. unsigned int freq1;
  105. unsigned int freq2;
  106. unsigned int time;
  107. unsigned int modulate:1;
  108. unsigned int midinote:1;
  109. };
  110. /*!
  111. * \brief Parse a tone part
  112. *
  113. * \param s The part of a tone to parse. This should be in the form described for
  114. * the data part of ast_tone_zone_sound. '!' should be removed if present.
  115. * \param tone_data An output parameter that contains the result of the parsing.
  116. *
  117. * \retval 0 success
  118. * \retval -1 failure, and the contents of tone_data are undefined
  119. */
  120. int ast_tone_zone_part_parse(const char *s, struct ast_tone_zone_part *tone_data);
  121. /*!
  122. * \brief locate ast_tone_zone
  123. *
  124. * \param country country to find. If NULL is provided, get the default.
  125. *
  126. * \return a reference to the specified country if found or NULL if not found
  127. */
  128. struct ast_tone_zone *ast_get_indication_zone(const char *country);
  129. /*!
  130. * \brief Locate a tone zone sound
  131. *
  132. * \param zone Zone to look in for a sound, if NULL, the default will be used
  133. * \param indication Sound to look for, such as "busy"
  134. *
  135. * \return a reference to the specified sound if it exists, NULL if not
  136. */
  137. struct ast_tone_zone_sound *ast_get_indication_tone(const struct ast_tone_zone *zone, const char *indication);
  138. /*!
  139. * \brief Start playing a list of tones on a channel
  140. *
  141. * \param chan the channel to play tones on
  142. * \param vol volume
  143. * \param tonelist the list of tones to play, comma separated
  144. * \param interruptible whether or not this tone can be interrupted
  145. *
  146. * \retval 0 success
  147. * \retval non-zero failure
  148. */
  149. int ast_playtones_start(struct ast_channel *chan, int vol, const char *tonelist, int interruptible);
  150. /*!
  151. * \brief Stop playing tones on a channel
  152. *
  153. * \param chan the channel to stop tones on
  154. */
  155. void ast_playtones_stop(struct ast_channel *chan);
  156. /*!
  157. * \brief Get the number of registered tone zones
  158. *
  159. * \return the total number of registered tone zones
  160. */
  161. int ast_tone_zone_count(void);
  162. /*!
  163. * \brief Get an iterator for the available tone zones
  164. *
  165. * \note Use ao2_iterator_next() to iterate the tone zones.
  166. * \note Use ao2_iterator_destroy() to clean up.
  167. *
  168. * \return an initialized iterator
  169. */
  170. struct ao2_iterator ast_tone_zone_iterator_init(void);
  171. /*!
  172. * \brief Lock an ast_tone_zone
  173. */
  174. #define ast_tone_zone_lock(tz) ao2_lock(tz)
  175. /*!
  176. * \brief Unlock an ast_tone_zone
  177. */
  178. #define ast_tone_zone_unlock(tz) ao2_unlock(tz)
  179. /*!
  180. * \brief Trylock an ast_tone_zone
  181. */
  182. #define ast_tone_zone_trylock(tz) ao2_trylock(tz)
  183. /*!
  184. * \brief Release a reference to an ast_tone_zone
  185. *
  186. * \return NULL
  187. */
  188. static inline struct ast_tone_zone *ast_tone_zone_unref(struct ast_tone_zone *tz)
  189. {
  190. ao2_ref(tz, -1);
  191. return NULL;
  192. }
  193. /*!
  194. * \brief Increase the reference count on an ast_tone_zone
  195. *
  196. * \return The tone zone provided as an argument
  197. */
  198. static inline struct ast_tone_zone *ast_tone_zone_ref(struct ast_tone_zone *tz)
  199. {
  200. ao2_ref(tz, +1);
  201. return tz;
  202. }
  203. /*!
  204. * \brief Release a reference to an ast_tone_zone_sound
  205. *
  206. * \return NULL
  207. */
  208. static inline struct ast_tone_zone_sound *ast_tone_zone_sound_unref(struct ast_tone_zone_sound *ts)
  209. {
  210. ao2_ref(ts, -1);
  211. return NULL;
  212. }
  213. /*!
  214. * \brief Increase the reference count on an ast_tone_zone_sound
  215. *
  216. * \return The tone zone sound provided as an argument
  217. */
  218. static inline struct ast_tone_zone_sound *ast_tone_zone_sound_ref(struct ast_tone_zone_sound *ts)
  219. {
  220. ao2_ref(ts, +1);
  221. return ts;
  222. }
  223. /*!
  224. * \brief Add a tone_zone structure to the data tree specified.
  225. *
  226. * \retval <0 on error.
  227. * \retval 0 on success.
  228. */
  229. int ast_tone_zone_data_add_structure(struct ast_data *tree, struct ast_tone_zone *zone);
  230. #endif /* _ASTERISK_INDICATIONS_H */