audio_encoder.h 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _AUDIO_ENCODER_H_
  13. #define _AUDIO_ENCODER_H_
  14. #include "osi_api.h"
  15. #include "audio_types.h"
  16. OSI_EXTERN_C_BEGIN
  17. /**
  18. * \brief forward declaration
  19. */
  20. struct auEncoder;
  21. /**
  22. * \brief forward declaration
  23. */
  24. struct auWriter;
  25. /**
  26. * \brief audio encoder parameter id and value pair
  27. *
  28. * This will be used to set multiple parameters for audio encoder.
  29. */
  30. typedef struct
  31. {
  32. int id; ///< parameter id
  33. const void *val; ///< parameter value pointer
  34. } auEncoderParamSet_t;
  35. /**
  36. * \brief audio encoder operations
  37. */
  38. typedef struct
  39. {
  40. /** delete the audio encoder */
  41. void (*destroy)(struct auEncoder *d);
  42. /** refer to \p auEncoderEncode */
  43. int (*encode)(struct auEncoder *d, const auFrame_t *frame);
  44. /** refer to \p auEncoderSetParam */
  45. bool (*set_param)(struct auEncoder *d, int id, const void *val);
  46. /** refer to \p auEncoderGetParam */
  47. bool (*get_param)(struct auEncoder *d, int id, void *val);
  48. } auEncoderOps_t;
  49. /**
  50. * \brief opaque data structure of audio encoder
  51. *
  52. * When implement an audio encoder, the first field should be
  53. * <tt>const auEncoderOps_t *</tt>.
  54. */
  55. typedef struct auEncoder
  56. {
  57. auEncoderOps_t ops; ///< audio encoder operations
  58. } auEncoder_t;
  59. /**
  60. * \brief create audio encoder by stream format
  61. *
  62. * The audio frame information is unknown at creation. The audio frame
  63. * information in the first frame to be encoded will be used.
  64. *
  65. * \param w audio writer to be used in audio encoder
  66. * \param format stream format
  67. * \return
  68. * - created audio encoder
  69. * - NULL if invalid parameter, or out of memory
  70. */
  71. auEncoder_t *auEncoderCreate(struct auWriter *w, auStreamFormat_t format);
  72. /**
  73. * \brief delete the audio encoder
  74. *
  75. * \param d audio encoder
  76. */
  77. void auEncoderDelete(auEncoder_t *d);
  78. /**
  79. * \brief encoder an audio frame
  80. *
  81. * Audio decoder shall write data to \p auWriter_t. Encoder should consume
  82. * all frame data. When audio encoder is frame based, the remaining data
  83. * should be backup by encoder.
  84. *
  85. * \param d audio encoder
  86. * \param frame audio frame to be encoded, can't be NULL
  87. * \return
  88. * - encoded audio stream byte count
  89. * - -1 on error
  90. */
  91. int auEncoderEncode(auEncoder_t *d, const auFrame_t *frame);
  92. /**
  93. * \brief set encoder parameter
  94. *
  95. * Audio encoder may support configurable parameter. This is the unified
  96. * API to set parameter. Each audio encoder will have independent param_id
  97. * definition, and the data type may be different for each parameter.
  98. * For example:
  99. *
  100. * \code{.cpp}
  101. * auEncoder_t *encoder = auEncoderCreare(w, AUSTREAM_FORMAT_AMRNB);
  102. * auAmrnbMode_t mode = AU_AMRNB_MODE_795;
  103. * auEncoderSetParam(encoder, AU_AMBNB_ENC_PARAM_MODE, &mode);
  104. * auEncoderGetParam(encoder, AU_AMBNB_ENC_PARAM_MODE, &mode);
  105. * \endcode
  106. *
  107. * All pamameter id should be positive, zero and negative values are
  108. * invalid.
  109. *
  110. * \param d audio encoder
  111. * \param param_id parameter id
  112. * \param val parameter val to be set
  113. * \return
  114. * - true on success
  115. * - false on fail, invalud paramter id or invalid parameter value
  116. */
  117. bool auEncoderSetParam(auEncoder_t *d, int param_id, const void *val);
  118. /**
  119. * \brief set multiple encoder parameter
  120. *
  121. * Set multiple parameters of audio encoder. When \p params is not NULL,
  122. * it should be an array, and the \p id of the last element must be zero
  123. * to indicate the end.
  124. *
  125. * When one parameter set fails, it will return false. However, the
  126. * remaining parameters in the array will be set still.
  127. *
  128. * \param d audio encoder
  129. * \param params array of parameter id and value
  130. * \return
  131. * - true on success
  132. * - false when one set fails
  133. */
  134. bool auEncoderSetMultiParams(auEncoder_t *d, const auEncoderParamSet_t *params);
  135. /**
  136. * \brief get encoder parameter
  137. *
  138. * \param d audio encoder
  139. * \param param_id parameter id
  140. * \param val parameter val to be get
  141. * \return
  142. * - true on success
  143. * - false on fail, invalud paramter id
  144. */
  145. bool auEncoderGetParam(auEncoder_t *d, int param_id, void *val);
  146. /**
  147. * \brief opaque data structure of WAV encoder
  148. */
  149. typedef struct auWavEncoder auWavEncoder_t;
  150. /**
  151. * \brief create a WAV encoder
  152. *
  153. * \param w audio writer to be used in audio encoder
  154. * \return
  155. * - created audio encoder
  156. * - NULL if invalid parameter, or out of memory
  157. */
  158. auWavEncoder_t *auWavEncoderCreate(struct auWriter *w);
  159. /**
  160. * \brief opaque data structure of PCM encoder
  161. */
  162. typedef struct auPcmEncoder auPcmEncoder_t;
  163. /**
  164. * \brief create a PCM encoder
  165. *
  166. * \param w audio writer to be used in audio encoder
  167. * \return
  168. * - created audio encoder
  169. * - NULL if invalid parameter, or out of memory
  170. */
  171. auPcmEncoder_t *auPcmEncoderCreate(struct auWriter *w);
  172. /**
  173. * \brief opaque data structure of AMR-NB encoder
  174. */
  175. typedef struct auAmrnbEncoder auAmrnbEncoder_t;
  176. /**
  177. * \brief AMR-NB encoder parameter id
  178. */
  179. typedef enum
  180. {
  181. /** placeholder for param_id start */
  182. AU_AMRNB_ENC_PARAM_START = AUSTREAM_FORMAT_AMRNB << 16,
  183. /** \p auAmrnbMode_t, mode */
  184. AU_AMRNB_ENC_PARAM_MODE,
  185. /** placeholder for param_id end */
  186. AU_AMRNB_ENC_PARAM_END
  187. } auAmrnbEncoderParamId_t;
  188. /**
  189. * \brief AMR-NB encoder default mode at create
  190. */
  191. extern const auAmrnbMode_t gAmrnbEncodeDefaultMode;
  192. /**
  193. * \brief create a AMR-NB encoder
  194. *
  195. * \param w audio writer to be used in audio encoder
  196. * \return
  197. * - created audio encoder
  198. * - NULL if invalid parameter, or out of memory
  199. */
  200. auAmrnbEncoder_t *auAmrnbEncoderCreate(struct auWriter *w);
  201. /**
  202. * \brief opaque data structure of AMR-WB encoder
  203. */
  204. typedef struct auAmrwbEncoder auAmrwbEncoder_t;
  205. /**
  206. * \brief AMR-WB encoder parameter id
  207. */
  208. typedef enum
  209. {
  210. /** placeholder for param_id start */
  211. AU_AMRWB_ENC_PARAM_START = AUSTREAM_FORMAT_AMRWB << 16,
  212. /** \p auAmrnbMode_t, mode */
  213. AU_AMRWB_ENC_PARAM_MODE,
  214. /** placeholder for param_id end */
  215. AU_AMRWB_ENC_PARAM_END
  216. } auAmrwbEncoderParamId_t;
  217. /**
  218. * \brief AMR-WB encoder default mode at create
  219. */
  220. extern const auAmrwbMode_t gAmrwbEncodeDefaultMode;
  221. /**
  222. * \brief create a AMR-WB encoder
  223. *
  224. * \param w audio writer to be used in audio encoder
  225. * \return
  226. * - created audio encoder
  227. * - NULL if invalid parameter, or out of memory
  228. */
  229. auAmrwbEncoder_t *auAmrwbEncoderCreate(struct auWriter *w);
  230. OSI_EXTERN_C_END
  231. #endif