audio_decoder.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  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_DECODER_H_
  13. #define _AUDIO_DECODER_H_
  14. #include "osi_api.h"
  15. #include "audio_types.h"
  16. OSI_EXTERN_C_BEGIN
  17. /**
  18. * \brief forward declaration
  19. */
  20. struct auDecoder;
  21. /**
  22. * \brief forward declaration
  23. */
  24. struct auReader;
  25. /**
  26. * \brief audio decoder parameter id and value pair
  27. *
  28. * This will be used to set multiple parameters for audio decoder.
  29. */
  30. typedef struct
  31. {
  32. int id; ///< parameter id
  33. const void *val; ///< parameter value pointer
  34. } auDecoderParamSet_t;
  35. /**
  36. * \brief common decoder parameter id
  37. */
  38. typedef enum
  39. {
  40. /** placeholder for param_id start */
  41. AU_DEC_PARAM_START = AUSTREAM_FORMAT_UNKNOWN << 16,
  42. /** \p auFrame_t, format only, all should support get */
  43. AU_DEC_PARAM_FORMAT,
  44. /** placeholder for param_id end */
  45. AU_DEC_PARAM_END
  46. } auDecoderParamId_t;
  47. /**
  48. * \brief audio decoder operations
  49. */
  50. typedef struct
  51. {
  52. /** delete the audio decoder */
  53. void (*destroy)(struct auDecoder *d);
  54. /** refer to \p auDecoderDecode */
  55. int (*decode)(struct auDecoder *d, auFrame_t *frame);
  56. /** refer to \p auDecoderSeek */
  57. bool (*seek)(struct auDecoder *d, unsigned ms);
  58. /** refer to \p auDecoderSetParam */
  59. bool (*set_param)(struct auDecoder *d, int id, const void *val);
  60. /** refer to \p auDecoderGetParam */
  61. bool (*get_param)(struct auDecoder *d, int id, void *val);
  62. /** refer to \p auDecoderParse */
  63. int (*parse)(struct auDecoder *d, auFrame_t *frame);
  64. } auDecoderOps_t;
  65. /**
  66. * \brief opaque data structure of audio decoder
  67. *
  68. * When implement an audio decoder, the first field should be
  69. * <tt>const auDecoderOps_t *</tt>.
  70. */
  71. typedef struct auDecoder
  72. {
  73. auDecoderOps_t ops; ///< audio decoder operations
  74. } auDecoder_t;
  75. /**
  76. * \brief create audio decoder by stream format
  77. *
  78. * \param r audio reader to be used in audio decoder
  79. * \param format stream format
  80. * \return
  81. * - created audio decoder
  82. * - NULL if invalid parameter, or out of memory
  83. */
  84. auDecoder_t *auDecoderCreate(struct auReader *r, auStreamFormat_t format);
  85. /**
  86. * \brief delete the audio decoder
  87. *
  88. * \param d audio decoder
  89. */
  90. void auDecoderDelete(auDecoder_t *d);
  91. /**
  92. * \brief decode an audio frame
  93. *
  94. * Audio decoder shall read data from \p auReader_t. After decoding, the
  95. * decoded audio frame data will be writen to \p frame. Memory of
  96. * \p frame->samples is owned by audio decoder. Before next call of
  97. * \p auDecoderDecode, the content will be kept.
  98. *
  99. * \param d audio decoder
  100. * \param frame decoded audio frame, can't be NULL
  101. * \return
  102. * - decoded audio frame byte count
  103. * - -1 on error
  104. */
  105. int auDecoderDecode(auDecoder_t *d, auFrame_t *frame);
  106. /**
  107. * \brief seek to specified time
  108. *
  109. * After \p auDecoderSeek, the audio frame of next \p auDecoderDecode
  110. * should be the samples starting from the specified time. If the audio
  111. * stream is frame based, the decoded audio frame may be started from the
  112. * middle of audio stream frame.
  113. *
  114. * It is not an error that \p ms is larger than total time. In that case,
  115. * the decoder should be located to the end of stream.
  116. *
  117. * When seek is not supported, the audio frame of next \p auDecoderDecode
  118. * should start from current position.
  119. *
  120. * \param d audio decoder
  121. * \param ms seek time in milliseconds
  122. * \return
  123. * - true on success
  124. * - false for invalid parameters, or seek is not supported
  125. */
  126. bool auDecoderSeek(auDecoder_t *d, unsigned ms);
  127. /**
  128. * \brief set decoder parameter
  129. *
  130. * Though it is rare to set decoder parameter, this mechanism is provided.
  131. * Refer to \p auEncoderSetParam for the usage model.
  132. *
  133. * All pamameter id should be positive, zero and negative values are
  134. * invalid.
  135. *
  136. * \param d audio decoder
  137. * \param param_id parameter id
  138. * \param val parameter val to be set
  139. * \return
  140. * - true on success
  141. * - false on fail, invalud paramter id or invalid parameter value
  142. */
  143. bool auDecoderSetParam(auDecoder_t *d, int param_id, const void *val);
  144. /**
  145. * \brief set multiple decoder parameter
  146. *
  147. * Set multiple parameters of audio decoder. When \p params is not NULL,
  148. * it should be an array, and the \p id of the last element must be zero
  149. * to indicate the end.
  150. *
  151. * When one parameter set fails, it will return false. However, the
  152. * remaining parameters in the array will be set still.
  153. *
  154. * \param d audio decoder
  155. * \param params array of parameter id and value
  156. * \return
  157. * - true on success
  158. * - false when one set fails
  159. */
  160. bool auDecoderSetMultiParams(auDecoder_t *d, const auDecoderParamSet_t *params);
  161. /**
  162. * \brief get decoder parameter
  163. *
  164. * \param d audio decoder
  165. * \param param_id parameter id
  166. * \param val parameter val to be get
  167. * \return
  168. * - true on success
  169. * - false on fail, invalud paramter id
  170. */
  171. bool auDecoderGetParam(auDecoder_t *d, int param_id, void *val);
  172. /**
  173. * \brief parse audio samplerate and channels
  174. *
  175. * \param d audio decoder
  176. * \param frame decoded audio frame, can't be NULL
  177. * \return
  178. * - = 0 : read no data
  179. * - < 0 : error
  180. * - > 0 : success
  181. */
  182. int auDecoderParse(auDecoder_t *d, auFrame_t *frame);
  183. /**
  184. * \brief opaque data structure of MP3 decoder
  185. */
  186. typedef struct auMp3Decoder auMp3Decoder_t;
  187. /**
  188. * \brief create a MP3 decoder
  189. *
  190. * \param r audio reader to be used in audio decoder
  191. * \return
  192. * - created audio decoder
  193. * - NULL if invalid parameter, or out of memory
  194. */
  195. auMp3Decoder_t *auMp3DecoderCreate(struct auReader *r);
  196. /**
  197. * \brief opaque data structure of WAV decoder
  198. */
  199. typedef struct auWavDecoder auWavDecoder_t;
  200. /**
  201. * \brief create a WAV decoder
  202. *
  203. * \param r audio reader to be used in audio decoder
  204. * \return
  205. * - created audio decoder
  206. * - NULL if invalid parameter, or out of memory
  207. */
  208. auWavDecoder_t *auWavDecoderCreate(struct auReader *r);
  209. /**
  210. * \brief opaque data structure of PCM decoder
  211. */
  212. typedef struct auPcmDecoder auPcmDecoder_t;
  213. /**
  214. * \brief create a PCM decoder
  215. *
  216. * \param r audio reader to be used in audio decoder
  217. * \return
  218. * - created audio decoder
  219. * - NULL if invalid parameter, or out of memory
  220. */
  221. auPcmDecoder_t *auPcmDecoderCreate(struct auReader *r);
  222. /**
  223. * \brief opaque data structure of AMR-NB decoder
  224. */
  225. typedef struct auAmrnbDecoder auAmrnbDecoder_t;
  226. /**
  227. * \brief create a AMR-NB decoder
  228. *
  229. * \param r audio reader to be used in audio decoder
  230. * \return
  231. * - created audio decoder
  232. * - NULL if invalid parameter, or out of memory
  233. */
  234. auAmrnbDecoder_t *auAmrnbDecoderCreate(struct auReader *r);
  235. /**
  236. * \brief opaque data structure of AMR-WB decoder
  237. */
  238. typedef struct auAmrwbDecoder auAmrwbDecoder_t;
  239. /**
  240. * \brief create a AMR-WB decoder
  241. *
  242. * \param r audio reader to be used in audio decoder
  243. * \return
  244. * - created audio decoder
  245. * - NULL if invalid parameter, or out of memory
  246. */
  247. auAmrwbDecoder_t *auAmrwbDecoderCreate(struct auReader *r);
  248. /**
  249. * \brief opaque data structure of SBC decoder
  250. */
  251. typedef struct auSbcDecoder auSbcDecoder_t;
  252. /**
  253. * \brief create a SBC decoder
  254. *
  255. * \param r audio reader to be used in audio decoder
  256. * \return
  257. * - created audio decoder
  258. * - NULL if invalid parameter, or out of memory
  259. */
  260. auSbcDecoder_t *auSbcDecoderCreate(struct auReader *r);
  261. OSI_EXTERN_C_END
  262. #endif