as_audio_codec.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. /*
  2. * Copyright (c) 2017 Actions Semi Co., Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. * Author: jpl<jianpingliao@actions-semi.com>
  16. *
  17. * Change log:
  18. * 2019/12/16: Created by jpl.
  19. */
  20. #ifndef __AS_AUDIO_CODEC_H__
  21. #define __AS_AUDIO_CODEC_H__
  22. #include <stdint.h>
  23. #include "al_storage_io.h"
  24. #include "lib_a1_ape_p.h"
  25. #include "lib_a1_fla_p.h"
  26. #include "lib_a1_wav_e.h"
  27. #include "lib_a1_wav_p.h"
  28. #include "lib_a1_w13_p.h"
  29. /**
  30. * @defgroup arithmetic_codec_apis arithmetic codec APIs
  31. * @ingroup mem_managers
  32. * @{
  33. */
  34. /*!
  35. * \brief
  36. * maximum audio output channels
  37. */
  38. #define MAX_CHANNEL_OUT 2
  39. /*!
  40. * \brief
  41. * audio (decoder) pcm output structure
  42. */
  43. typedef struct
  44. {
  45. /*! [OUTPUT] address of pcm buffer of each channel */
  46. void *pcm[MAX_CHANNEL_OUT];
  47. /*! [OUTPUT] number of pcm channels */
  48. int channels;
  49. /*! [OUTPUT] number of pcm samples of each channel */
  50. int samples;
  51. /*! [OUTPUT] number of pcm sample bits, 16/24/32 */
  52. int sample_bits;
  53. /*! [OUTPUT] number of pcm sample fraction bits */
  54. int frac_bits;
  55. } asout_pcm_t;
  56. /*!
  57. * \brief
  58. * maximum audio input channels
  59. */
  60. #define MAX_CHANNEL_IN 4
  61. /*!
  62. * \brief
  63. * audio (encoder) pcm input structure
  64. */
  65. typedef struct
  66. {
  67. /*! [INPUT] address of pcm buffer of each channel */
  68. void *pcm[MAX_CHANNEL_IN];
  69. /*! [INPUT] number of pcm channels */
  70. int channels;
  71. /*! [INPUT] number of pcm samples of each channel */
  72. int samples;
  73. /*! [INPUT] number of pcm sample bits, 16/24/32 */
  74. int sample_bits;
  75. /*! [INPUT] number of pcm sample fraction bits */
  76. int frac_bits;
  77. } asin_pcm_t;
  78. #if 0 /* see ext/actions/include/media/media_type.h */
  79. typedef enum
  80. {
  81. UNSUPPORT_TYPE = 0,
  82. MP3_TYPE,
  83. WMA_TYPE,
  84. WAV_TYPE, // 3
  85. FLAC_TYPE,
  86. APE_TYPE,
  87. AAC_TYPE, // 6
  88. OGG_TYPE,
  89. ACT_TYPE,
  90. AMR_TYPE, // 9
  91. SBC_TYPE,
  92. MSBC_TYPE,
  93. OPUS_TYPE, // 12
  94. AAX_TYPE,
  95. AA_TYPE,
  96. CVSD_TYPE, // 15
  97. SPEEX_TYPE,
  98. // raw pcm format
  99. PCM_TYPE, // 17
  100. } as_type_t;
  101. #endif
  102. /*******************************************************************************
  103. * actions decoder
  104. ******************************************************************************/
  105. /*!
  106. * \brief
  107. * music information by audio decoder
  108. */
  109. typedef struct
  110. {
  111. /*! [OUTPUT]: music format, see enum as_type_t */
  112. int as_type;
  113. /*! [OUTPUT]: total time in ms */
  114. int total_time;
  115. /*! [OUTPUT]: average bitrate in kbps */
  116. int avg_bitrate;
  117. /*! [OUTPUT]: sample rate in kHz */
  118. int sample_rate;
  119. /*! [OUTPUT]: sample rate in Hz */
  120. int sample_rate_hz;
  121. /*! [OUTPUT]: number of channels */
  122. int channels;
  123. /*! [OUTPUT]: sample bits */
  124. int bps;
  125. /*! [OUTPUT]: number of samples per block */
  126. int block_size;
  127. /*! [OUTPUT]: number of samples per frame, mp3 frame/wma packet/ogg page */
  128. int frame_size;
  129. /*! [OUTPUT]: sub format */
  130. int sub_format;
  131. /*! [OUTPUT]: file length in bytes */
  132. unsigned int file_len;
  133. /*! [OUTPUT]: file header lenght inbytes */
  134. unsigned int file_hdr_len;
  135. /*! address of data buffer used internally in library */
  136. void *data_buf_addr;
  137. /*! length of data buffer used internally in library */
  138. int data_buf_len;
  139. /*! [INPUT]: drm flag, indicate file is encrypted or not. 1-encrypted, 0-not encrypted,
  140. * may used in AA, AAX format.
  141. */
  142. int drm_flag;
  143. /*! [INPUT]: address of drm secret key buffer, required when drm_flag=1 */
  144. void *key_buf;
  145. /*! [INPUT]: storage io handle, see struct storage_io_s */
  146. void *storage_io;
  147. /*! [INPUT]: decoder specific buffer */
  148. void *buf;
  149. /*! [INPUT]: decode mode
  150. * 1) if used as tts, set to 0x0abcd, no matter what format
  151. * 2) for aac format, 0 stands for locall file decoding, while 1 is BT stream decoding.
  152. */
  153. int decode_mode;
  154. /*! [INPUT] global memory block address array */
  155. void *global_buf_addr[3];
  156. /*! [INPUT] global memory block length array */
  157. int global_buf_len[3];
  158. /*! [INPUT] share memory block address array */
  159. void *share_buf_addr[3];
  160. /*! [INPUT] share memory block length array */
  161. int share_buf_len[3];
  162. /*! [INPUT]: expected pcm sample bits of decode output (16/24/32). 16 by default */
  163. int set_pcm_out_bits;
  164. /*[INPUT]: 0: accurate seek, but slower; 1: quick seek, but bigger deviation */
  165. int seek_mode;
  166. /*! [INPUT]: extended parameter, whichi is decoder specific */
  167. void *param;
  168. } as_dec_t;
  169. typedef struct
  170. {
  171. /* [OUTPUT] global memory block length array, 3 blocks at maximum */
  172. int global_buf_len[3];
  173. /* [OUTPUT] share memory block length array, 3 blocks at maximum */
  174. int share_buf_len[3];
  175. /* [INPUT] extended parameters
  176. * for encoder: passed address of structure as_enc_t.
  177. */
  178. void* param;
  179. } as_mem_info_t;
  180. /*!
  181. * \brief
  182. * music break point information by audio decoder
  183. * For WAV/MP3/WMA, bp_time_offset and bp_file_offset should be consistent.
  184. */
  185. typedef struct
  186. {
  187. /*! break point time in ms. when used in seeking, it stands for the target time */
  188. int bp_time_offset;
  189. /*! break point file positon in bytes */
  190. unsigned int bp_file_offset;
  191. /*! auxiliary information for resuming break point */
  192. int bp_info_ext;
  193. } as_bp_info_t;
  194. /*!
  195. * \brief
  196. * decoding frame information by audio decoder
  197. */
  198. typedef struct
  199. {
  200. /* start address of current frame data */
  201. void *addr;
  202. /* length of current frame data */
  203. int len;
  204. /* bit width of data unit */
  205. int sample_size;
  206. /* status of current frame, like data lost status when decoding BT stream */
  207. int status;
  208. } as_dec_frame_info_t;
  209. /*!
  210. * \brief
  211. * decoding information by audio decoder
  212. */
  213. typedef struct
  214. {
  215. /*! [OUTPUT]: decoder status. 0: normal, otherwise error */
  216. int status;
  217. /*! [OUTPUT]: current decoding time in ms */
  218. int cur_time;
  219. /*! [OUTPUT]: current decoding bitrate in kbps */
  220. int cur_bitrate;
  221. /*! [OUTPUT]: current energy */
  222. int cur_energy;
  223. /*! [OUTPUT]: address of decoding output pcm structure. set by caller, filled by decoder */
  224. asout_pcm_t *aout;
  225. /*! [OUTPUT]: current decoding file positon in bytes */
  226. unsigned int cur_file_offset;
  227. /*! [OUTPUT]: length of decoding consumed data in bytes */
  228. int bytes_used;
  229. /*! [OUTPUT]: break point infomation corresponding to current decoding time */
  230. as_bp_info_t as_bp_info;
  231. /*! [OUTPUT]: reserved */
  232. void *param;
  233. } as_decode_info_t;
  234. /** as decoder cmd */
  235. typedef enum
  236. {
  237. /** decoder open */
  238. AD_CMD_OPEN = 0,
  239. /** decoder close */
  240. AD_CMD_CLOSE,
  241. /** get media info */
  242. AD_CMD_MEDIA_INFO,
  243. /** reset chunk */
  244. AD_CMD_CHUNK_RESET,
  245. /** decode frame */
  246. AD_CMD_FRAME_DECODE,
  247. /** chunk seek */
  248. AD_CMD_CHUNK_SEEK,
  249. /*set output channel, such as sbc*/
  250. AD_CMD_CHANNEL_SET,
  251. /** get memory require size(bytes) */
  252. AD_CMD_MEM_REQUIRE,
  253. /** parser frame */
  254. AD_CMD_FRAME_PARSE,
  255. /** get codec verison */
  256. AD_CMD_GET_VERSION,
  257. /** get codec err info */
  258. AD_CMD_GET_ERROR_INFO,
  259. /*drm init*/
  260. AD_CMD_DRM_INIT,
  261. } asdec_ex_ops_cmd_t;
  262. /** audio decoder return state */
  263. typedef enum
  264. {
  265. /** unexpected state */
  266. AD_RET_UNEXPECTED = -3,
  267. /** outof memory state */
  268. AD_RET_OUTOFMEMORY,
  269. /** unsupported state */
  270. AD_RET_UNSUPPORTED,
  271. /** ok state */
  272. AD_RET_OK,
  273. /** data underflow state */
  274. AD_RET_DATAUNDERFLOW,
  275. } asdec_ret_t;
  276. /** audio decoder ops prototype */
  277. typedef int (*as_decoder_ops_t)(void *hnd, asdec_ex_ops_cmd_t cmd, unsigned int args);
  278. /**
  279. * @brief check real audio format
  280. *
  281. * This routine provides checking audio format
  282. *
  283. * @param storage_io pointer of storage io
  284. * @extension buffer (require 8 bytes) to store format extension, all lower case, like mp3, wav, flac, etc.
  285. *
  286. * @return 0 if succeed, others failed
  287. */
  288. int as_decoder_format_check(void *storage_io, char extension[8]);
  289. /**
  290. * @brief aac decoder operation
  291. *
  292. * This routine provides aac decoder operation
  293. *
  294. * @param hnd handle of aac decoder
  295. * @param cmd operation cmd, type of asdec_ex_ops_cmd_t
  296. * @param args args of decoder parama addr
  297. *
  298. * @return type of asdec_ret_t
  299. */
  300. int as_decoder_ops_aac(void *hnd, asdec_ex_ops_cmd_t cmd, unsigned int args);
  301. /**
  302. * @brief act decoder operation
  303. *
  304. * This routine provides act decoder operation
  305. *
  306. * @param hnd handle of act decoder
  307. * @param cmd operation cmd, type of asdec_ex_ops_cmd_t
  308. * @param args args of decoder parama addr
  309. *
  310. * @return type of asdec_ret_t
  311. */
  312. int as_decoder_ops_act(void *hnd, asdec_ex_ops_cmd_t cmd, unsigned int args);
  313. /**
  314. * @brief ape decoder operation
  315. *
  316. * This routine provides ape decoder operation
  317. *
  318. * @param hnd handle of ape decoder
  319. * @param cmd operation cmd, type of asdec_ex_ops_cmd_t
  320. * @param args args of decoder parama addr
  321. *
  322. * @return type of asdec_ret_t
  323. */
  324. int as_decoder_ops_ape(void *hnd, asdec_ex_ops_cmd_t cmd, unsigned int args);
  325. /**
  326. * @brief cvsd decoder operation
  327. *
  328. * This routine provides cvsd decoder operation
  329. *
  330. * @param hnd handle of cvsd decoder
  331. * @param cmd operation cmd, type of asdec_ex_ops_cmd_t
  332. * @param args args of decoder parama addr
  333. *
  334. * @return type of asdec_ret_t
  335. */
  336. int as_decoder_ops_cvsd(void *hnd, asdec_ex_ops_cmd_t cmd, unsigned int args);
  337. /**
  338. * @brief flac decoder operation
  339. *
  340. * This routine provides flac decoder operation
  341. *
  342. * @param hnd handle of flac decoder
  343. * @param cmd operation cmd, type of asdec_ex_ops_cmd_t
  344. * @param args args of decoder parama addr
  345. *
  346. * @return type of asdec_ret_t
  347. */
  348. int as_decoder_ops_flac(void *hnd, asdec_ex_ops_cmd_t cmd, unsigned int args);
  349. /**
  350. * @brief mp3 decoder operation
  351. *
  352. * This routine provides mp3 decoder operation
  353. *
  354. * @param hnd handle of mp3 decoder
  355. * @param cmd operation cmd, type of asdec_ex_ops_cmd_t
  356. * @param args args of decoder parama addr
  357. *
  358. * @return type of asdec_ret_t
  359. */
  360. int as_decoder_ops_mp3(void *hnd, asdec_ex_ops_cmd_t cmd, unsigned int args);
  361. /**
  362. * @brief pcm decoder operation
  363. *
  364. * This routine provides pcm decoder operation
  365. *
  366. * @param hnd handle of pcm decoder
  367. * @param cmd operation cmd, type of asdec_ex_ops_cmd_t
  368. * @param args args of decoder parama addr
  369. *
  370. * @return type of asdec_ret_t
  371. */
  372. int as_decoder_ops_pcm(void *hnd, asdec_ex_ops_cmd_t cmd, unsigned int args);
  373. /**
  374. * @brief sbc decoder operation
  375. *
  376. * This routine provides sbc decoder operation
  377. *
  378. * @param hnd handle of sbc decoder
  379. * @param cmd operation cmd, type of asdec_ex_ops_cmd_t
  380. * @param args args of decoder parama addr
  381. *
  382. * @return type of asdec_ret_t
  383. */
  384. int as_decoder_ops_sbc(void *hnd, asdec_ex_ops_cmd_t cmd, unsigned int args);
  385. /**
  386. * @brief wav decoder operation
  387. *
  388. * This routine provides wav decoder operation
  389. *
  390. * @param hnd handle of wav decoder
  391. * @param cmd operation cmd, type of asdec_ex_ops_cmd_t
  392. * @param args args of decoder parama addr
  393. *
  394. * @return type of asdec_ret_t
  395. */
  396. int as_decoder_ops_wav(void *hnd, asdec_ex_ops_cmd_t cmd, unsigned int args);
  397. /**
  398. * @brief wma decoder operation
  399. *
  400. * This routine provides wma decoder operation
  401. *
  402. * @param hnd handle of wma decoder
  403. * @param cmd operation cmd, type of asdec_ex_ops_cmd_t
  404. * @param args args of decoder parama addr
  405. *
  406. * @return type of asdec_ret_t
  407. */
  408. int as_decoder_ops_wma(void *hnd, asdec_ex_ops_cmd_t cmd, unsigned int args);
  409. /*******************************************************************************
  410. * actions encoder
  411. ******************************************************************************/
  412. /*!
  413. * \brief
  414. * encoding configuration provided to audio encoder
  415. */
  416. typedef struct
  417. {
  418. /*! [INPUT]: sample rate in Hz */
  419. int sample_rate;
  420. /*! [INPUT]: input pcm channels */
  421. int channels;
  422. /*! [INPUT]: output encoding channels. the same as channels by default */
  423. int channels_out;
  424. /*! [INPUT]: target bitrate */
  425. int bitrate;
  426. /*! [INPUT]: encoding sub format
  427. * For wav: 0-LPCM, 1-ADPCM
  428. * For sbc: 0-sbc, 1-msbc
  429. */
  430. int audio_format;
  431. /*! [INPUT]: chunk time interval in ms per encoding frame. if set 0, no limit */
  432. int chunk_time;
  433. /*! [OUTPUT]: input pcm buffer length of each channel per frame in bytes */
  434. int block_size;
  435. /*! [OUTPUT]: output encoded data length per frame in bytes */
  436. int block_enc_size_max;
  437. /*! [INPUT] global memory block address array */
  438. void *global_buf_addr[3];
  439. /*! [INPUT] global memory block length array */
  440. int global_buf_len[3];
  441. /*! [INPUT] share memory block address array */
  442. void *share_buf_addr[3];
  443. /*! [INPUT] share memory block length array */
  444. int share_buf_len[3];
  445. /* [INPUT]: input pcm sample bits. 16/24/32, 16 by default */
  446. int sample_bits;
  447. /*! [INPUT]: encoder specific parameters */
  448. void *param;
  449. } as_enc_t;
  450. /*!
  451. * \brief
  452. * encoding information by audio encoder
  453. */
  454. typedef struct
  455. {
  456. /*! [OUTPUT]: encoding status. 0-normal, otherwise error */
  457. int status;
  458. /*! [OUTPUT]: current encoding time in ms*/
  459. int cur_time;
  460. /*! [INPUT]: current encoding energy */
  461. int cur_energy;
  462. /*! [INPUT]: slient flag */
  463. int silence_flag;
  464. /*! [INPUT]: address of input pcm structure */
  465. asin_pcm_t *ain;
  466. /*! [INPUT]: address of output encoded data. set by caller, filled by encoder */
  467. void *aout;
  468. /*! [OUTPUT]: length of output encoded data in bytes */
  469. int bytes_used;
  470. /* [OUTPUT]: length of remain non-encoded data in bytes */
  471. int bytes_remain;
  472. /*![OUTPUT]: reserved */
  473. void *param;
  474. } as_encode_info_t;
  475. typedef struct
  476. {
  477. /*![OUTPUT]: address of header buffer */
  478. void *hdr_buf;
  479. /*![OUTPUT]: length of header buffer */
  480. int hdr_len;
  481. } as_enc_fhdr_t;
  482. /*
  483. * opus encoder specific parameter
  484. */
  485. typedef struct {
  486. /*! [INPUT]: application mode: 2048 (VOIP), 2049 (AUDIO), 2051 (RESTRICTED_LOWDELAY)*/
  487. int application;
  488. /*! [INPUT]: comlexity, range 0~10 */
  489. int complexity;
  490. /*! [INPUT]: vbr flag. 1: variable bitrate; 0: constant bitrate*/
  491. int vbr;
  492. } as_enc_opus_param_t;
  493. /** audio encorder cmd */
  494. typedef enum
  495. {
  496. /** open encoder library */
  497. AE_CMD_OPEN = 0,
  498. /** close encoder library */
  499. AE_CMD_CLOSE,
  500. /** decoder frame */
  501. AE_CMD_FRAME_ENCODE,
  502. /** get memory require size(bytes) */
  503. AE_CMD_MEM_REQUIRE,
  504. /**get codec verison**/
  505. AE_CMD_GET_VERSION,
  506. /**get encoded file header**/
  507. AE_CMD_GET_FHDR,
  508. } asenc_ex_ops_cmd_t;
  509. /** audio decoder state */
  510. typedef enum
  511. {
  512. /** unkown expected */
  513. AE_RET_UNEXPECTED = -7,
  514. /** load library failed */
  515. AE_RET_LIBLOAD_ERROR,
  516. /** load error library */
  517. AE_RET_LIB_ERROR,
  518. /** encoder error */
  519. AE_RET_ENCODER_ERROR,
  520. /** sample rate error */
  521. AE_RET_FS_ERROR,
  522. /** out of memory*/
  523. AE_RET_OUTOFMEMORY,
  524. /** format not support*/
  525. AE_RET_UNSUPPORTED,
  526. /** success */
  527. AE_RET_OK,
  528. /** data over flow*/
  529. AE_RET_DATAOVERFLOW,
  530. /** out of data */
  531. AE_RET_OUTOFDATA,
  532. } asenc_ret_t;
  533. /** audio encoder ops prototype */
  534. typedef int (*as_encoder_ops_t)(void *hnd, asenc_ex_ops_cmd_t cmd, unsigned int args);
  535. /**
  536. * @brief cvsd encoder operation
  537. *
  538. * This routine provides cvsd encoder operation
  539. *
  540. * @param hnd handle of cvsd encoder
  541. * @param cmd operation cmd, type of asenc_ex_ops_cmd_t
  542. * @param args args of encoder parama addr
  543. *
  544. * @return type of asenc_ret_t
  545. */
  546. int as_encoder_ops_cvsd(void *hnd, asenc_ex_ops_cmd_t cmd, unsigned int args);
  547. /**
  548. * @brief mp3 encoder operation
  549. *
  550. * This routine provides mp3 encoder operation
  551. *
  552. * @param hnd handle of mp3 encoder
  553. * @param cmd operation cmd, type of asenc_ex_ops_cmd_t
  554. * @param args args of encoder parama addr
  555. *
  556. * @return type of asenc_ret_t
  557. */
  558. int as_encoder_ops_mp2(void *hnd, asenc_ex_ops_cmd_t cmd, unsigned int args);
  559. /**
  560. * @brief opus encoder operation
  561. *
  562. * This routine provides opus encoder operation
  563. *
  564. * @param hnd handle of opus encoder
  565. * @param cmd operation cmd, type of asenc_ex_ops_cmd_t
  566. * @param args args of encoder parama addr
  567. *
  568. * @return type of asenc_ret_t
  569. */
  570. int as_encoder_ops_opus(void *hnd, asenc_ex_ops_cmd_t cmd, unsigned int args);
  571. /**
  572. * @brief pcm encoder operation
  573. *
  574. * This routine provides pcm encoder operation
  575. *
  576. * @param hnd handle of pcm encoder
  577. * @param cmd operation cmd, type of asenc_ex_ops_cmd_t
  578. * @param args args of encoder parama addr
  579. *
  580. * @return type of asenc_ret_t
  581. */
  582. int as_encoder_ops_pcm(void *hnd, asenc_ex_ops_cmd_t cmd, unsigned int args);
  583. /**
  584. * @brief sbc encoder operation
  585. *
  586. * This routine provides sbc encoder operation
  587. *
  588. * @param hnd handle of sbc encoder
  589. * @param cmd operation cmd, type of asenc_ex_ops_cmd_t
  590. * @param args args of encoder parama addr
  591. *
  592. * @return type of asenc_ret_t
  593. */
  594. int as_encoder_ops_sbc(void *hnd, asenc_ex_ops_cmd_t cmd, unsigned int args);
  595. /**
  596. * @brief wav encoder operation
  597. *
  598. * This routine provides wav encoder operation
  599. *
  600. * @param hnd handle of wav encoder
  601. * @param cmd operation cmd, type of asenc_ex_ops_cmd_t
  602. * @param args args of encoder parama addr
  603. *
  604. * @return type of asenc_ret_t
  605. */
  606. int as_encoder_ops_wav(void *hnd, asenc_ex_ops_cmd_t cmd, unsigned int args);
  607. /*******************************************************************************
  608. * actions parser
  609. ******************************************************************************/
  610. /*!
  611. * \brief
  612. * audio parser ops error code
  613. */
  614. typedef enum
  615. {
  616. /*! unexpected error */
  617. AP_RET_UNEXPECTED = -3,
  618. /*! not enough memory */
  619. AP_RET_OUTOFMEMORY,
  620. /*! unsupported format */
  621. AP_RET_UNSUPPORTED,
  622. /*! no error */
  623. AP_RET_OK = 0,
  624. /*! end of file */
  625. AP_RET_ENDFILE
  626. } asparse_ret_t;
  627. /** audio parser cmd */
  628. typedef enum
  629. {
  630. AP_CMD_OPEN = 0,
  631. AP_CMD_CLOSE,
  632. AP_CMD_PARSER_HEADER,
  633. AP_CMD_GET_CHUNK,
  634. AP_CMD_SEEK,
  635. AP_CMD_EX_OPS,
  636. AP_CMD_FORCE_ENDFILE,
  637. } asparse_ex_ops_cmd_t;
  638. /*!
  639. * \brief
  640. * parser cmd AP_CMD_OPEN argument
  641. */
  642. typedef struct
  643. {
  644. /* provided to access the raw stream */
  645. storage_io_t *storage_io;
  646. /* TYPE: struct acts_ringbuf, which store request/feedback from codec */
  647. void *evtbuf;
  648. } asparse_param_t;
  649. /*!
  650. * \brief
  651. * music information by audio parser, and argument of cmd AP_CMD_PARSER_HEADER
  652. */
  653. typedef struct
  654. {
  655. /*! [OUTPUT]: format extension, upper case, like "COOK" */
  656. char extension[8];
  657. /*! [OUTPUT]: maximum chunk size in bytes */
  658. int max_chunksize;
  659. /*! [OUTPUT]: total time in milliseconds */
  660. int total_time;
  661. /*! [OUTPUT]: average bitrate in kbps */
  662. int avg_bitrate;
  663. /*! [OUTPUT]: sample rate in Hz */
  664. int sample_rate;
  665. /*! [OUTPUT]: channels */
  666. int channels;
  667. /*! [OUTPUT]: parser specific information */
  668. void *buf;
  669. int buf_len;
  670. /*![OUTPUT] file head length*/
  671. int hdr_len;
  672. /*![OUTPUT] bit width*/
  673. int sample_bits;
  674. } asparse_info_t;
  675. /*!
  676. * \brief
  677. * parser cmd AP_CMD_GET_CHUNK argument
  678. */
  679. typedef struct
  680. {
  681. /* chunk buffer */
  682. uint8_t *outbuf;
  683. uint16_t chunk_bytes;
  684. int16_t chunk_rest;
  685. /* chunk seek information */
  686. int32_t chunk_start_time;
  687. int32_t chunk_start_offset;
  688. } asparse_bs_info_t;
  689. /*!
  690. * \brief
  691. * parser cmd AP_CMD_SEEK argument
  692. */
  693. typedef struct
  694. {
  695. /* decide the seek possiton */
  696. int32_t time_offset;
  697. int32_t origin;
  698. /* store the feedback of parser lib according to the seek position */
  699. int32_t chunk_start_time;
  700. /* used to accelerate the seeking speed
  701. * >= 0, valid file offset, can be used to speed up seeking
  702. * <0, invalid file offset
  703. */
  704. int32_t file_offset_for_time_offset; /* measured in bytes */
  705. } asparse_seek_info_t;
  706. #define AP_SEEK_SET 0
  707. #define AP_SEEK_CUR 1
  708. #define AP_SEEK_END 2
  709. #define AP_TELL_CUR 0
  710. #define AP_TELL_END 1
  711. /** audio parser ops prototype */
  712. typedef int (*as_parser_ops_t)(void *hnd, asparse_ex_ops_cmd_t cmd, unsigned int args);
  713. /**
  714. * @brief ape parser operation
  715. *
  716. * This routine provides ape parser operation
  717. *
  718. * @param hnd handle of ape parser
  719. * @param cmd operation cmd, type of asparse_ex_ops_cmd_t
  720. * @param args args of parser parama addr
  721. *
  722. * @return type of asparse_ret_t
  723. */
  724. int as_parser_ops_ape(void *hnd, asparse_ex_ops_cmd_t cmd, unsigned int args);
  725. /**
  726. * @brief flac parser operation
  727. *
  728. * This routine provides flac parser operation
  729. *
  730. * @param hnd handle of flac parser
  731. * @param cmd operation cmd, type of asparse_ex_ops_cmd_t
  732. * @param args args of parser parama addr
  733. *
  734. * @return type of asparse_ret_t
  735. */
  736. int as_parser_ops_flac(void *hnd, asparse_ex_ops_cmd_t cmd, unsigned int args);
  737. /**
  738. * @brief mp3 parser operation
  739. *
  740. * This routine provides mp3 parser operation
  741. *
  742. * @param hnd handle of mp3 parser
  743. * @param cmd operation cmd, type of asparse_ex_ops_cmd_t
  744. * @param args args of parser parama addr
  745. *
  746. * @return type of asparse_ret_t
  747. */
  748. int as_parser_ops_mp3(void *hnd, asparse_ex_ops_cmd_t cmd, unsigned int args);
  749. /**
  750. * @brief wav parser operation
  751. *
  752. * This routine provides wav parser operation
  753. *
  754. * @param hnd handle of wav parser
  755. * @param cmd operation cmd, type of asparse_ex_ops_cmd_t
  756. * @param args args of parser parama addr
  757. *
  758. * @return type of asparse_ret_t
  759. */
  760. int as_parser_ops_wav(void *hnd, asparse_ex_ops_cmd_t cmd, unsigned int args);
  761. /**
  762. * @brief wma parser operation
  763. *
  764. * This routine provides wma parser operation
  765. *
  766. * @param hnd handle of wma parser
  767. * @param cmd operation cmd, type of asparse_ex_ops_cmd_t
  768. * @param args args of parser parama addr
  769. *
  770. * @return type of asparse_ret_t
  771. */
  772. int as_parser_ops_wma(void *hnd, asparse_ex_ops_cmd_t cmd, unsigned int args);
  773. /**
  774. * @brief aac parser operation
  775. *
  776. * This routine provides aac parser operation
  777. *
  778. * @param hnd handle of aac parser
  779. * @param cmd operation cmd, type of asparse_ex_ops_cmd_t
  780. * @param args args of parser parama addr
  781. *
  782. * @return type of asparse_ret_t
  783. */
  784. int as_parser_ops_a13(void *hnd, asparse_ex_ops_cmd_t cmd, unsigned int args);
  785. #endif /* __AS_AUDIO_CODEC_H__ */