converter.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. /*
  2. * Copyright (C) 2010-2011 Teluu Inc. (http://www.teluu.com)
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #ifndef __PJMEDIA_CONVERTER_H__
  19. #define __PJMEDIA_CONVERTER_H__
  20. /**
  21. * @file pjmedia/converter.h Format conversion utilities
  22. * @brief Format conversion utilities
  23. */
  24. #include <pjmedia/frame.h>
  25. #include <pjmedia/format.h>
  26. #include <pj/list.h>
  27. #include <pj/pool.h>
  28. /**
  29. * @defgroup PJMEDIA_CONVERTER Format converter
  30. * @ingroup PJMEDIA_FRAME_OP
  31. * @brief Audio and video converter utilities
  32. * @{
  33. */
  34. PJ_BEGIN_DECL
  35. /**
  36. * This describes conversion parameter. It specifies the source and
  37. * destination formats of the conversion.
  38. */
  39. typedef struct pjmedia_conversion_param
  40. {
  41. pjmedia_format src; /**< Source format. */
  42. pjmedia_format dst; /**< Destination format. */
  43. } pjmedia_conversion_param;
  44. /** Forward declaration of factory operation structure */
  45. typedef struct pjmedia_converter_factory_op pjmedia_converter_factory_op;
  46. /**
  47. * Converter priority guides. Converter priority determines which converter
  48. * instance to be used if more than one converters are able to perform the
  49. * requested conversion. Converter implementor can use this value to order
  50. * the preference based on attributes such as quality or performance. Higher
  51. * number indicates higher priority.
  52. */
  53. typedef enum pjmedia_converter_priority_guide
  54. {
  55. /** Lowest priority. */
  56. PJMEDIA_CONVERTER_PRIORITY_LOWEST = 0,
  57. /** Normal priority. */
  58. PJMEDIA_CONVERTER_PRIORITY_NORMAL = 15000,
  59. /** Highest priority. */
  60. PJMEDIA_CONVERTER_PRIORITY_HIGHEST = 32000
  61. } pjmedia_converter_priority_guide;
  62. /**
  63. * Converter factory. The converter factory registers a callback function
  64. * to create converters.
  65. */
  66. typedef struct pjmedia_converter_factory
  67. {
  68. /**
  69. * Standard list members.
  70. */
  71. PJ_DECL_LIST_MEMBER(struct pjmedia_converter_factory);
  72. /**
  73. * Factory name.
  74. */
  75. const char *name;
  76. /**
  77. * Converter priority determines which converter instance to be used if
  78. * more than one converters are able to perform the requested conversion.
  79. * Converter implementor can use this value to order the preference based
  80. * on attributes such as quality or performance. Higher number indicates
  81. * higher priority. The pjmedia_converter_priority_guide enumeration shall
  82. * be used as the base value to set the priority.
  83. */
  84. int priority;
  85. /**
  86. * Pointer to factory operation.
  87. */
  88. pjmedia_converter_factory_op *op;
  89. } pjmedia_converter_factory;
  90. /** Forward declaration for converter operation. */
  91. typedef struct pjmedia_converter_op pjmedia_converter_op;
  92. /**
  93. * This structure describes a converter instance.
  94. */
  95. typedef struct pjmedia_converter
  96. {
  97. /**
  98. * Pointer to converter operation.
  99. */
  100. pjmedia_converter_op *op;
  101. } pjmedia_converter;
  102. /**
  103. * Settings for pjmedia_converter_convert2().
  104. */
  105. typedef void pjmedia_converter_convert_setting;
  106. /**
  107. * Converter factory operation.
  108. */
  109. struct pjmedia_converter_factory_op
  110. {
  111. /**
  112. * This function creates a converter with the specified conversion format,
  113. * if such format is supported.
  114. *
  115. * @param cf The converter factory.
  116. * @param pool Pool to allocate memory from.
  117. * @param prm Conversion parameter.
  118. * @param p_cv Pointer to hold the created converter instance.
  119. *
  120. * @return PJ_SUCCESS if converter has been created successfully.
  121. */
  122. pj_status_t (*create_converter)(pjmedia_converter_factory *cf,
  123. pj_pool_t *pool,
  124. const pjmedia_conversion_param *prm,
  125. pjmedia_converter **p_cv);
  126. /**
  127. * Destroy the factory.
  128. *
  129. * @param cf The converter factory.
  130. */
  131. void (*destroy_factory)(pjmedia_converter_factory *cf);
  132. };
  133. /**
  134. * Converter operation.
  135. */
  136. struct pjmedia_converter_op
  137. {
  138. /**
  139. * Convert the buffer of the source frame and save the result in the
  140. * buffer of the destination frame, according to conversion format that
  141. * was specified when the converter was created.
  142. *
  143. * Note that application should use #pjmedia_converter_convert() instead
  144. * of calling this function directly.
  145. *
  146. * @param cv The converter instance.
  147. * @param src_frame The source frame.
  148. * @param dst_frame The destination frame.
  149. *
  150. * @return PJ_SUCCESS if conversion has been performed
  151. * successfully.
  152. */
  153. pj_status_t (*convert)(pjmedia_converter *cv,
  154. pjmedia_frame *src_frame,
  155. pjmedia_frame *dst_frame);
  156. /**
  157. * Destroy the converter instance.
  158. *
  159. * Note that application should use #pjmedia_converter_destroy() instead
  160. * of calling this function directly.
  161. *
  162. * @param cv The converter.
  163. */
  164. void (*destroy)(pjmedia_converter *cv);
  165. /**
  166. * Convert a region in the buffer of the source frame and put the result
  167. * into a region in the buffer of the destination frame, according to
  168. * conversion format that was specified when the converter was created.
  169. *
  170. * Note that application should use #pjmedia_converter_convert2() instead
  171. * of calling this function directly.
  172. *
  173. * @param cv The converter instance.
  174. * @param src_frame The source frame.
  175. * @param src_frame_size The source frame size.
  176. * @param src_reg_pos The source region position.
  177. * @param dst_frame The destination frame.
  178. * @param dst_frame_size The destination frame size.
  179. * @param dst_reg_pos The destination region position.
  180. * @param param This is unused for now and must be NULL.
  181. *
  182. * @return PJ_SUCCESS if conversion has been performed
  183. * successfully.
  184. */
  185. pj_status_t (*convert2)(pjmedia_converter *cv,
  186. pjmedia_frame *src_frame,
  187. const pjmedia_rect_size *src_frame_size,
  188. const pjmedia_coord *src_pos,
  189. pjmedia_frame *dst_frame,
  190. const pjmedia_rect_size *dst_frame_size,
  191. const pjmedia_coord *dst_pos,
  192. pjmedia_converter_convert_setting
  193. *param);
  194. };
  195. /**
  196. * Opaque data type for conversion manager. Typically, the conversion manager
  197. * is a singleton instance, although application may instantiate more than one
  198. * instances of this if required.
  199. */
  200. typedef struct pjmedia_converter_mgr pjmedia_converter_mgr;
  201. /**
  202. * Create a new conversion manager instance. This will also set the pointer
  203. * to the singleton instance if the value is still NULL.
  204. *
  205. * @param pool Pool to allocate memory from.
  206. * @param mgr Pointer to hold the created instance of the
  207. * conversion manager.
  208. *
  209. * @return PJ_SUCCESS on success or the appropriate error code.
  210. */
  211. PJ_DECL(pj_status_t) pjmedia_converter_mgr_create(pj_pool_t *pool,
  212. pjmedia_converter_mgr **mgr);
  213. /**
  214. * Get the singleton instance of the conversion manager.
  215. *
  216. * @return The instance.
  217. */
  218. PJ_DECL(pjmedia_converter_mgr*) pjmedia_converter_mgr_instance(void);
  219. /**
  220. * Manually assign a specific video manager instance as the singleton
  221. * instance. Normally this is not needed if only one instance is ever
  222. * going to be created, as the library automatically assign the singleton
  223. * instance.
  224. *
  225. * @param mgr The instance to be used as the singleton instance.
  226. * Application may specify NULL to clear the singleton
  227. * singleton instance.
  228. */
  229. PJ_DECL(void) pjmedia_converter_mgr_set_instance(pjmedia_converter_mgr *mgr);
  230. /**
  231. * Destroy a converter manager. If the manager happens to be the singleton
  232. * instance, the singleton instance will be set to NULL.
  233. *
  234. * @param mgr The converter manager. Specify NULL to use
  235. * the singleton instance.
  236. */
  237. PJ_DECL(void) pjmedia_converter_mgr_destroy(pjmedia_converter_mgr *mgr);
  238. /**
  239. * Register a converter factory to the converter manager.
  240. *
  241. * @param mgr The converter manager. Specify NULL to use
  242. * the singleton instance.
  243. * @param f The converter factory to be registered.
  244. *
  245. * @return PJ_SUCCESS on success or the appropriate error code.
  246. */
  247. PJ_DECL(pj_status_t)
  248. pjmedia_converter_mgr_register_factory(pjmedia_converter_mgr *mgr,
  249. pjmedia_converter_factory *f);
  250. /**
  251. * Unregister a previously registered converter factory from the converter
  252. * manager.
  253. *
  254. * @param mgr The converter manager. Specify NULL to use
  255. * the singleton instance.
  256. * @param f The converter factory to be unregistered.
  257. * @param call_destroy If this is set to non-zero, the \a destroy_factory()
  258. * callback of the factory will be called while
  259. * unregistering the factory from the manager.
  260. *
  261. * @return PJ_SUCCESS on success or the appropriate error code.
  262. */
  263. PJ_DECL(pj_status_t)
  264. pjmedia_converter_mgr_unregister_factory(pjmedia_converter_mgr *mgr,
  265. pjmedia_converter_factory *f,
  266. pj_bool_t call_destroy);
  267. /**
  268. * Create a converter instance to perform the specified format conversion
  269. * as specified in \a param.
  270. *
  271. * @param mgr The converter manager. Specify NULL to use
  272. * the singleton instance.
  273. * @param pool Pool to allocate the memory from.
  274. * @param param Conversion parameter.
  275. * @param p_cv Pointer to hold the created converter.
  276. *
  277. * @return PJ_SUCCESS if a converter has been created successfully
  278. * or the appropriate error code.
  279. */
  280. PJ_DECL(pj_status_t) pjmedia_converter_create(pjmedia_converter_mgr *mgr,
  281. pj_pool_t *pool,
  282. pjmedia_conversion_param *param,
  283. pjmedia_converter **p_cv);
  284. /**
  285. * Convert the buffer in the source frame and save the result in the
  286. * buffer of the destination frame, according to conversion format that
  287. * was specified when the converter was created.
  288. *
  289. * @param cv The converter instance.
  290. * @param src_frame The source frame.
  291. * @param dst_frame The destination frame.
  292. *
  293. * @return PJ_SUCCESS if conversion has been performed
  294. * successfully.
  295. */
  296. PJ_DECL(pj_status_t) pjmedia_converter_convert(pjmedia_converter *cv,
  297. pjmedia_frame *src_frame,
  298. pjmedia_frame *dst_frame);
  299. /**
  300. * Convert a region in the buffer of the source frame and put the result
  301. * into a region in the buffer of the destination frame, according to
  302. * conversion format that was specified when the converter was created.
  303. *
  304. * @param cv The converter instance.
  305. * @param src_frame The source frame.
  306. * @param src_frame_size The source frame size.
  307. * @param src_pos The source region position.
  308. * @param dst_frame The destination frame.
  309. * @param dst_frame_size The destination frame size.
  310. * @param dst_pos The destination region position.
  311. * @param param This is unused for now and must be NULL.
  312. *
  313. * @return PJ_SUCCESS if conversion has been performed
  314. * successfully.
  315. */
  316. PJ_DECL(pj_status_t) pjmedia_converter_convert2(
  317. pjmedia_converter *cv,
  318. pjmedia_frame *src_frame,
  319. const pjmedia_rect_size *src_frame_size,
  320. const pjmedia_coord *src_pos,
  321. pjmedia_frame *dst_frame,
  322. const pjmedia_rect_size *dst_frame_size,
  323. const pjmedia_coord *dst_pos,
  324. pjmedia_converter_convert_setting
  325. *param);
  326. /**
  327. * Destroy the converter.
  328. *
  329. * @param cv The converter instance.
  330. */
  331. PJ_DECL(void) pjmedia_converter_destroy(pjmedia_converter *cv);
  332. PJ_END_DECL
  333. /**
  334. * @}
  335. */
  336. #endif /* __PJMEDIA_CONVERTER_H__ */