codec_config.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /*
  2. * Copyright (c) 2019 Actions Semiconductor Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. /**
  7. * @file codec config interface
  8. */
  9. #include <media_service.h>
  10. #include <string.h>
  11. #include <section_overlay.h>
  12. typedef struct
  13. {
  14. uint8_t format;
  15. uint8_t codec_type;
  16. bool hw_acceleration;
  17. uint32_t overlay_id;
  18. void *ops;
  19. const char *dsp_dec_lib;
  20. const char *dsp_effect_lib;
  21. } codec_config_info_t;
  22. const codec_config_info_t codec_config[] =
  23. {
  24. #ifdef CONFIG_ACTIONS_DECODER
  25. #ifdef CONFIG_DECODER_AAC
  26. {
  27. .format = AAC_TYPE,
  28. .codec_type = CODEC_DEC,
  29. .overlay_id = OVERLAY_ID_LIBADAAC,
  30. #ifdef CONFIG_DECODER_AAC_HW_ACCELERATION
  31. .hw_acceleration = true,
  32. .ops = NULL,
  33. .dsp_dec_lib = "adMUSIC.dsp",
  34. .dsp_effect_lib = NULL,
  35. #else
  36. .hw_acceleration = false,
  37. .ops = as_decoder_ops_aac,
  38. #endif
  39. },
  40. #endif
  41. #ifdef CONFIG_DECODER_M4A
  42. {
  43. .format = M4A_TYPE,
  44. .codec_type = CODEC_DEC,
  45. .overlay_id = OVERLAY_ID_LIBADAAC,
  46. #ifdef CONFIG_DECODER_M4A_HW_ACCELERATION
  47. .hw_acceleration = true,
  48. .ops = NULL,
  49. .dsp_dec_lib = "adMUSIC.dsp",
  50. .dsp_effect_lib = NULL,
  51. #else
  52. .hw_acceleration = false,
  53. .ops = as_decoder_ops_aac,
  54. #endif
  55. },
  56. #endif
  57. #ifdef CONFIG_DECODER_ACT
  58. {
  59. .format = ACT_TYPE,
  60. .codec_type = CODEC_DEC,
  61. .overlay_id = 0, //OVERLAY_ID_LIBADACT,
  62. #ifdef CONFIG_DECODER_ACT_HW_ACCELERATION
  63. .hw_acceleration = true,
  64. .ops = NULL,
  65. .dsp_dec_lib = "adMUSIC.dsp",
  66. .dsp_effect_lib = NULL,
  67. #else
  68. .hw_acceleration = false,
  69. .ops = as_decoder_ops_act,
  70. #endif
  71. },
  72. #endif
  73. #ifdef CONFIG_DECODER_APE
  74. {
  75. .format = APE_TYPE,
  76. .codec_type = CODEC_DEC,
  77. .overlay_id = OVERLAY_ID_LIBADAPE,
  78. #ifdef CONFIG_DECODER_APE_HW_ACCELERATION
  79. .hw_acceleration = true,
  80. .ops = NULL,
  81. .dsp_dec_lib = "adMUSIC.dsp",
  82. .dsp_effect_lib = NULL,
  83. #else
  84. .hw_acceleration = false,
  85. .ops = as_decoder_ops_ape,
  86. #endif
  87. },
  88. #endif
  89. #ifdef CONFIG_DECODER_CVSD
  90. {
  91. .format = CVSD_TYPE,
  92. .codec_type = CODEC_DEC,
  93. .overlay_id = 0,//OVERLAY_ID_LIBADCVS,
  94. #ifdef CONFIG_DECODER_CVSD_HW_ACCELERATION
  95. .hw_acceleration = true,
  96. .ops = NULL,
  97. .dsp_dec_lib = "adMUSIC.dsp",
  98. //.dsp_effect_lib = "PREPRO.dsp",
  99. .dsp_effect_lib = NULL,
  100. #else
  101. .hw_acceleration = false,
  102. //.ops = as_decoder_ops_cvsd,
  103. #endif
  104. },
  105. #endif
  106. #ifdef CONFIG_DECODER_FLAC
  107. {
  108. .format = FLA_TYPE,
  109. .codec_type = CODEC_DEC,
  110. .overlay_id = OVERLAY_ID_LIBADFLA,
  111. #ifdef CONFIG_DECODER_FLAC_HW_ACCELERATION
  112. .hw_acceleration = true,
  113. .ops = NULL,
  114. .dsp_dec_lib = "adMUSIC.dsp",
  115. .dsp_effect_lib = NULL,
  116. #else
  117. .hw_acceleration = false,
  118. .ops = as_decoder_ops_flac,
  119. #endif
  120. },
  121. #endif
  122. #ifdef CONFIG_DECODER_MP3
  123. {
  124. .format = MP3_TYPE,
  125. .codec_type = CODEC_DEC,
  126. .overlay_id = OVERLAY_ID_LIBADMP3,
  127. #ifdef CONFIG_DECODER_MP3_HW_ACCELERATION
  128. .hw_acceleration = true,
  129. .ops = NULL,
  130. .dsp_dec_lib = "adMUSIC.dsp",
  131. .dsp_effect_lib = NULL,
  132. #else
  133. .hw_acceleration = false,
  134. .ops = as_decoder_ops_mp3,
  135. #endif
  136. },
  137. #endif
  138. #ifdef CONFIG_DECODER_WAV
  139. {
  140. .format = WAV_TYPE,
  141. .codec_type = CODEC_DEC,
  142. .overlay_id = OVERLAY_ID_LIBADWAV,
  143. #ifdef CONFIG_DECODER_WAV_HW_ACCELERATION
  144. .hw_acceleration = true,
  145. .ops = NULL,
  146. .dsp_dec_lib = "adMUSIC.dsp",
  147. .dsp_effect_lib = NULL,
  148. #else
  149. .hw_acceleration = false,
  150. .ops = as_decoder_ops_wav,
  151. #endif
  152. },
  153. #endif
  154. #ifdef CONFIG_DECODER_WMA
  155. {
  156. .format = WMA_TYPE,
  157. .codec_type = CODEC_DEC,
  158. .overlay_id = OVERLAY_ID_LIBADWMA,
  159. #ifdef CONFIG_DECODER_WMA_HW_ACCELERATION
  160. .hw_acceleration = true,
  161. .ops = NULL,
  162. .dsp_dec_lib = "adMUSIC.dsp",
  163. .dsp_effect_lib = NULL,
  164. #else
  165. .hw_acceleration = false,
  166. .ops = as_decoder_ops_wma,
  167. #endif
  168. },
  169. #endif
  170. #ifdef CONFIG_DECODER_PCM
  171. {
  172. .format = PCM_TYPE,
  173. .codec_type = CODEC_DEC,
  174. .hw_acceleration = true,
  175. .overlay_id = 0,
  176. .ops = NULL,
  177. .dsp_dec_lib = "adMUSIC.dsp",
  178. .dsp_effect_lib = NULL,
  179. },
  180. #endif
  181. #ifdef CONFIG_DECODER_SBC
  182. {
  183. .format = SBC_TYPE,
  184. .codec_type = CODEC_DEC,
  185. .overlay_id = 0, //OVERLAY_ID_LIBADSBC,
  186. #ifdef CONFIG_DECODER_SBC_HW_ACCELERATION
  187. .hw_acceleration = true,
  188. .ops = NULL,
  189. .dsp_dec_lib = "adMUSIC.dsp",
  190. .dsp_effect_lib = NULL,
  191. #else
  192. .hw_acceleration = false,
  193. //.ops = as_decoder_ops_sbc,
  194. #endif
  195. },
  196. #endif
  197. #ifdef CONFIG_DECODER_MSBC
  198. {
  199. .format = MSBC_TYPE,
  200. .codec_type = CODEC_DEC,
  201. .overlay_id = 0, //OVERLAY_ID_LIBADSBC,
  202. #ifdef CONFIG_DECODER_MSBC_HW_ACCELERATION
  203. .hw_acceleration = true,
  204. .ops = NULL,
  205. .dsp_dec_lib = "adMUSIC.dsp",
  206. //.dsp_effect_lib = "PREPRO.dsp",
  207. .dsp_effect_lib = NULL,
  208. #else
  209. .hw_acceleration = false,
  210. //.ops = as_decoder_ops_sbc,
  211. #endif
  212. },
  213. #endif
  214. #ifdef CONFIG_DECODER_NAV
  215. {
  216. .format = NAV_TYPE,
  217. .codec_type = CODEC_DEC,
  218. .overlay_id = 0,
  219. #ifdef CONFIG_DECODER_NAV_HW_ACCELERATION
  220. .hw_acceleration = true,
  221. .ops = NULL,
  222. .dsp_dec_lib = "audioble.dsp",
  223. .dsp_effect_lib = NULL,
  224. #else
  225. .hw_acceleration = false,
  226. //.ops = as_encoder_ops_nav,
  227. #endif
  228. },
  229. #endif
  230. #endif
  231. #ifdef CONFIG_ACTIONS_ENCODER
  232. #ifdef CONFIG_ENCODER_CVSD
  233. {
  234. .format = CVSD_TYPE,
  235. .codec_type = CODEC_ENC,
  236. .overlay_id = 0,//OVERLAY_ID_LIBAECVS,
  237. #ifdef CONFIG_ENCODER_CVSD_HW_ACCELERATION
  238. .hw_acceleration = true,
  239. .ops = NULL,
  240. .dsp_dec_lib = "adMUSIC.dsp",
  241. .dsp_effect_lib = "PREPRO.dsp",
  242. #else
  243. .hw_acceleration = false,
  244. //.ops = as_encoder_ops_cvsd,
  245. #endif
  246. },
  247. #endif
  248. #ifdef CONFIG_ENCODER_MP3
  249. {
  250. .format = MP3_TYPE,
  251. .codec_type = CODEC_ENC,
  252. .overlay_id = OVERLAY_ID_LIBAEMP3,
  253. #ifdef CONFIG_ENCODER_MP3_HW_ACCELERATION
  254. .hw_acceleration = true,
  255. .ops = NULL,
  256. .dsp_dec_lib = "adMUSIC.dsp",
  257. .dsp_effect_lib = NULL,
  258. #else
  259. .hw_acceleration = false,
  260. .ops = as_encoder_ops_mp2,
  261. #endif
  262. },
  263. #endif
  264. #ifdef CONFIG_ENCODER_OPUS
  265. {
  266. .format = OPUS_TYPE,
  267. .codec_type = CODEC_ENC,
  268. .overlay_id = OVERLAY_ID_LIBAEOPU,
  269. #ifdef CONFIG_ENCODER_OPUS_HW_ACCELERATION
  270. .hw_acceleration = true,
  271. .ops = NULL,
  272. .dsp_dec_lib = "aeOPUS.dsp",
  273. .dsp_effect_lib = NULL,
  274. #else
  275. .hw_acceleration = false,
  276. .ops = as_encoder_ops_opus,
  277. #endif
  278. },
  279. #endif
  280. #ifdef CONFIG_ENCODER_WAV
  281. {
  282. .format = WAV_TYPE,
  283. .codec_type = CODEC_ENC,
  284. .overlay_id = 0,//OVERLAY_ID_LIBAEWAV,
  285. #ifdef CONFIG_ENCODER_WAV_HW_ACCELERATION
  286. .hw_acceleration = true,
  287. .ops = NULL,
  288. .dsp_dec_lib = "adMUSIC.dsp",
  289. .dsp_effect_lib = NULL,
  290. #else
  291. .hw_acceleration = false,
  292. .ops = as_encoder_ops_wav,
  293. #endif
  294. },
  295. #endif
  296. #ifdef CONFIG_ENCODER_PCM
  297. {
  298. .format = PCM_TYPE,
  299. .codec_type = CODEC_ENC,
  300. .hw_acceleration = true,
  301. .overlay_id = 0,
  302. .ops = NULL,
  303. .dsp_dec_lib = "adMUSIC.dsp",
  304. .dsp_effect_lib = NULL,
  305. },
  306. #endif
  307. #ifdef CONFIG_ENCODER_SBC
  308. {
  309. .format = SBC_TYPE,
  310. .codec_type = CODEC_ENC,
  311. .overlay_id = 0,
  312. #ifdef CONFIG_ENCODER_SBC_HW_ACCELERATION
  313. .hw_acceleration = true,
  314. .ops = NULL,
  315. .dsp_dec_lib = "adMUSIC.dsp",
  316. .dsp_effect_lib = NULL,
  317. #else
  318. .hw_acceleration = false,
  319. //.ops = as_encoder_ops_sbc,
  320. #endif
  321. },
  322. #endif
  323. #ifdef CONFIG_ENCODER_MSBC
  324. {
  325. .format = MSBC_TYPE,
  326. .codec_type = CODEC_ENC,
  327. .overlay_id = 0,
  328. #ifdef CONFIG_ENCODER_MSBC_HW_ACCELERATION
  329. .hw_acceleration = true,
  330. .ops = NULL,
  331. .dsp_dec_lib = "adMUSIC.dsp",
  332. .dsp_effect_lib = "PREPRO.dsp",
  333. #else
  334. .hw_acceleration = false,
  335. //.ops = as_encoder_ops_sbc,
  336. #endif
  337. },
  338. #endif
  339. #ifdef CONFIG_ENCODER_NAV
  340. {
  341. .format = NAV_TYPE,
  342. .codec_type = CODEC_ENC,
  343. .overlay_id = 0,
  344. #ifdef CONFIG_ENCODER_NAV_HW_ACCELERATION
  345. .hw_acceleration = true,
  346. .ops = NULL,
  347. .dsp_dec_lib = "audioble.dsp",
  348. .dsp_effect_lib = NULL,
  349. #else
  350. .hw_acceleration = false,
  351. //.ops = as_encoder_ops_nav,
  352. #endif
  353. },
  354. #endif
  355. #endif
  356. };
  357. int codec_get_overlay_id(enum media_type format, enum codec_type type)
  358. {
  359. int i;
  360. for (i = 0; i < ARRAY_SIZE(codec_config); i++) {
  361. if (format == codec_config[i].format
  362. && type == codec_config[i].codec_type) {
  363. return codec_config[i].overlay_id;
  364. }
  365. }
  366. return -1;
  367. }
  368. void *codec_get_ops(enum media_type format, enum codec_type type)
  369. {
  370. int i;
  371. for (i = 0; i < ARRAY_SIZE(codec_config); i++) {
  372. if (format == codec_config[i].format
  373. && type == codec_config[i].codec_type) {
  374. return codec_config[i].ops;
  375. }
  376. }
  377. return NULL;
  378. }
  379. bool codec_support_hw_acceleration(enum media_type format, enum codec_type type)
  380. {
  381. int i;
  382. for (i = 0; i < ARRAY_SIZE(codec_config); i++) {
  383. if (format == codec_config[i].format
  384. && type == codec_config[i].codec_type) {
  385. return codec_config[i].hw_acceleration;
  386. }
  387. }
  388. return false;
  389. }
  390. const char *codec_get_hw_acceleration_dec_lib(enum media_type format, enum codec_type type)
  391. {
  392. int i;
  393. for (i = 0; i < ARRAY_SIZE(codec_config); i++) {
  394. if (format == codec_config[i].format
  395. && type == codec_config[i].codec_type) {
  396. return codec_config[i].dsp_dec_lib;
  397. }
  398. }
  399. return NULL;
  400. }
  401. const char *codec_get_hw_acceleration_effect_lib(enum media_type format, enum codec_type type)
  402. {
  403. int i;
  404. for (i = 0; i < ARRAY_SIZE(codec_config); i++) {
  405. if (format == codec_config[i].format
  406. && type == codec_config[i].codec_type) {
  407. return codec_config[i].dsp_effect_lib;
  408. }
  409. }
  410. return NULL;
  411. }