format_cache.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2014, 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. /*!
  19. * \file
  20. * \brief Media Format Cache API
  21. *
  22. * \author Joshua Colp <jcolp@digium.com>
  23. */
  24. #ifndef _AST_FORMAT_CACHE_H_
  25. #define _AST_FORMAT_CACHE_H_
  26. struct ast_format;
  27. /*!
  28. * \brief Built-in cached signed linear 8kHz format.
  29. */
  30. extern struct ast_format *ast_format_slin;
  31. /*!
  32. * \brief Built-in cached signed linear 12kHz format.
  33. */
  34. extern struct ast_format *ast_format_slin12;
  35. /*!
  36. * \brief Built-in cached signed linear 16kHz format.
  37. */
  38. extern struct ast_format *ast_format_slin16;
  39. /*!
  40. * \brief Built-in cached signed linear 24kHz format.
  41. */
  42. extern struct ast_format *ast_format_slin24;
  43. /*!
  44. * \brief Built-in cached signed linear 32kHz format.
  45. */
  46. extern struct ast_format *ast_format_slin32;
  47. /*!
  48. * \brief Built-in cached signed linear 44kHz format.
  49. */
  50. extern struct ast_format *ast_format_slin44;
  51. /*!
  52. * \brief Built-in cached signed linear 48kHz format.
  53. */
  54. extern struct ast_format *ast_format_slin48;
  55. /*!
  56. * \brief Built-in cached signed linear 96kHz format.
  57. */
  58. extern struct ast_format *ast_format_slin96;
  59. /*!
  60. * \brief Built-in cached signed linear 192kHz format.
  61. */
  62. extern struct ast_format *ast_format_slin192;
  63. /*!
  64. * \brief Built-in cached ulaw format.
  65. */
  66. extern struct ast_format *ast_format_ulaw;
  67. /*!
  68. * \brief Built-in cached alaw format.
  69. */
  70. extern struct ast_format *ast_format_alaw;
  71. /*!
  72. * \brief Built-in cached testlaw format.
  73. */
  74. extern struct ast_format *ast_format_testlaw;
  75. /*!
  76. * \brief Built-in cached gsm format.
  77. */
  78. extern struct ast_format *ast_format_gsm;
  79. /*!
  80. * \brief Built-in cached adpcm format.
  81. */
  82. extern struct ast_format *ast_format_adpcm;
  83. /*!
  84. * \brief Built-in cached g722 format.
  85. */
  86. extern struct ast_format *ast_format_g722;
  87. /*!
  88. * \brief Built-in cached g726 format.
  89. */
  90. extern struct ast_format *ast_format_g726;
  91. /*!
  92. * \brief Built-in cached g726 aal2 format.
  93. */
  94. extern struct ast_format *ast_format_g726_aal2;
  95. /*!
  96. * \brief Built-in cached ilbc format.
  97. */
  98. extern struct ast_format *ast_format_ilbc;
  99. /*!
  100. * \brief Built-in cached ilbc format.
  101. */
  102. extern struct ast_format *ast_format_lpc10;
  103. /*!
  104. * \brief Built-in cached speex format.
  105. */
  106. extern struct ast_format *ast_format_speex;
  107. /*!
  108. * \brief Built-in cached speex at 16kHz format.
  109. */
  110. extern struct ast_format *ast_format_speex16;
  111. /*!
  112. * \brief Built-in cached speex at 32kHz format.
  113. */
  114. extern struct ast_format *ast_format_speex32;
  115. /*!
  116. * \brief Built-in cached g723.1 format.
  117. */
  118. extern struct ast_format *ast_format_g723;
  119. /*!
  120. * \brief Built-in cached g729 format.
  121. */
  122. extern struct ast_format *ast_format_g729;
  123. /*!
  124. * \brief Built-in cached g719 format.
  125. */
  126. extern struct ast_format *ast_format_g719;
  127. /*!
  128. * \brief Built-in cached h261 format.
  129. */
  130. extern struct ast_format *ast_format_h261;
  131. /*!
  132. * \brief Built-in cached h263 format.
  133. */
  134. extern struct ast_format *ast_format_h263;
  135. /*!
  136. * \brief Built-in cached h263 plus format.
  137. */
  138. extern struct ast_format *ast_format_h263p;
  139. /*!
  140. * \brief Built-in cached h264 format.
  141. */
  142. extern struct ast_format *ast_format_h264;
  143. /*!
  144. * \brief Built-in cached mp4 format.
  145. */
  146. extern struct ast_format *ast_format_mp4;
  147. /*!
  148. * \brief Built-in cached vp8 format.
  149. */
  150. extern struct ast_format *ast_format_vp8;
  151. /*!
  152. * \brief Built-in cached vp9 format.
  153. */
  154. extern struct ast_format *ast_format_vp9;
  155. /*!
  156. * \brief Built-in cached jpeg format.
  157. */
  158. extern struct ast_format *ast_format_jpeg;
  159. /*!
  160. * \brief Built-in cached png format.
  161. */
  162. extern struct ast_format *ast_format_png;
  163. /*!
  164. * \brief Built-in cached siren14 format.
  165. */
  166. extern struct ast_format *ast_format_siren14;
  167. /*!
  168. * \brief Built-in cached siren7 format.
  169. */
  170. extern struct ast_format *ast_format_siren7;
  171. /*!
  172. * \brief Built-in cached opus format.
  173. */
  174. extern struct ast_format *ast_format_opus;
  175. /*!
  176. * \brief Built-in cached t140 format.
  177. */
  178. extern struct ast_format *ast_format_t140;
  179. /*!
  180. * \brief Built-in cached t140 red format.
  181. */
  182. extern struct ast_format *ast_format_t140_red;
  183. /*!
  184. * \brief Built-in "null" format.
  185. */
  186. extern struct ast_format *ast_format_none;
  187. /*!
  188. * \brief Built-in SILK format.
  189. */
  190. extern struct ast_format *ast_format_silk8;
  191. extern struct ast_format *ast_format_silk12;
  192. extern struct ast_format *ast_format_silk16;
  193. extern struct ast_format *ast_format_silk24;
  194. /*!
  195. * \brief Initialize format cache support within the core.
  196. *
  197. * \retval 0 success
  198. * \retval -1 failure
  199. */
  200. int ast_format_cache_init(void);
  201. /*!
  202. * \brief Set a named format cache entry.
  203. *
  204. * \param format A pointer to the format to cache
  205. *
  206. * \retval 0 success
  207. * \retval -1 failure
  208. */
  209. int ast_format_cache_set(struct ast_format *format);
  210. /*!
  211. * \brief Retrieve a named format from the cache.
  212. *
  213. * \param name Name of the cached format
  214. *
  215. * \retval non-NULL if found
  216. * \retval NULL if not found
  217. *
  218. * \note The returned format has its reference count incremented. It must be
  219. * dropped using ao2_ref or ao2_cleanup.
  220. */
  221. struct ast_format *__ast_format_cache_get(const char *name);
  222. struct ast_format *__ast_format_cache_get_debug(const char *name, const char *tag, const char *file, int line, const char *func);
  223. #ifdef REF_DEBUG
  224. #define ast_format_cache_get(name) \
  225. __ast_format_cache_get_debug((name), "", __FILE__, __LINE__, __PRETTY_FUNCTION__)
  226. #define ast_t_format_cache_get(name, tag) \
  227. __ast_format_cache_get_debug((name), (tag), __FILE__, __LINE__, __PRETTY_FUNCTION__)
  228. #else
  229. #define ast_format_cache_get(name) \
  230. __ast_format_cache_get((name))
  231. #define ast_t_format_cache_get(name, tag) \
  232. __ast_format_cache_get((name))
  233. #endif
  234. /*!
  235. * \brief Retrieve the best signed linear format given a sample rate.
  236. *
  237. * \param rate The sample rate
  238. *
  239. * \details
  240. * This is a convenience function that returns one of the global
  241. * ast_format_slinxxx formats.
  242. *
  243. * \return pointer to the signed linear format
  244. *
  245. * \note The returned format has NOT had its reference count incremented.
  246. */
  247. struct ast_format *ast_format_cache_get_slin_by_rate(unsigned int rate);
  248. /*!
  249. * \brief Determines if a format is one of the cached slin formats
  250. *
  251. * \param format The format to check
  252. *
  253. * \retval 0 if the format is not an SLIN format
  254. * \retval 1 if the format is an SLIN format
  255. */
  256. int ast_format_cache_is_slinear(struct ast_format *format);
  257. #endif /* _AST_FORMAT_CACHE_H */