dsp_runinfo.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480
  1. /*
  2. * Copyright (c) 2020 Actions Technology Co., Ltd
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. */
  6. #include <zephyr.h>
  7. #include <stdint.h>
  8. #include "dsp_inner.h"
  9. static struct dsp_ringbuf *buf_dsp2cpu(uint32_t dsp_buf)
  10. {
  11. return (struct dsp_ringbuf *)dsp_data_to_mcu_address(dsp_buf);
  12. }
  13. static void print_ringbuf_info(const char *str, uint32_t buf, int type)
  14. {
  15. struct dsp_ringbuf *dsp_buf = buf_dsp2cpu(buf);
  16. if (type == 0) {
  17. printk("\t\t%s=%p (length=%u/%u ptr=%u)\n",
  18. str, dsp_buf,
  19. dsp_ringbuf_length(dsp_buf),
  20. dsp_ringbuf_size(dsp_buf),
  21. (u32_t)acts_ringbuf_base(&dsp_buf->buf));
  22. } else {
  23. printk("\t\t%s=%p (space=%u/%u ptr=%u)\n",
  24. str, dsp_buf,
  25. dsp_ringbuf_space(dsp_buf),
  26. dsp_ringbuf_size(dsp_buf),
  27. (u32_t)acts_ringbuf_base(&dsp_buf->buf));
  28. }
  29. }
  30. static void dump_media_session(void *info)
  31. {
  32. #if 0
  33. struct media_dspssn_info *media_info = info;
  34. struct media_dspssn_params *params = &media_info->params;
  35. printk("\nsession media (id=%u):\n", DSP_SESSION_MEDIA);
  36. printk("\taec_en=%d\n", params->aec_en);
  37. printk("\taec_delay=%d samples\n", params->aec_delay);
  38. if (media_info->aec_refbuf)
  39. printk("\taec_refbuf=%p (length=%u/%u)\n",
  40. buf_dsp2cpu(media_info->aec_refbuf),
  41. dsp_ringbuf_length(buf_dsp2cpu(media_info->aec_refbuf)),
  42. dsp_ringbuf_size(buf_dsp2cpu(media_info->aec_refbuf)));
  43. #endif
  44. }
  45. void dsp_session_dump_info(struct dsp_session *session, void *info)
  46. {
  47. switch (session->id) {
  48. case DSP_SESSION_MEDIA:
  49. dump_media_session(info);
  50. break;
  51. default:
  52. break;
  53. }
  54. }
  55. #if 0
  56. static void dump_test_function(void *info, bool dump_debug)
  57. {
  58. struct test_dspfunc_info *test_info = info;
  59. struct test_dspfunc_params *params = &test_info->params;
  60. struct test_dspfunc_runtime *runtime = &test_info->runtime;
  61. printk("\nfunction (id=%u):\n", DSP_FUNCTION_TEST);
  62. printk("\tparameters:\n");
  63. printk("\t\t(%p)inbuf.length=%u/%u\n", buf_dsp2cpu(params->inbuf),
  64. dsp_ringbuf_length(buf_dsp2cpu(params->inbuf)),
  65. dsp_ringbuf_size(buf_dsp2cpu(params->inbuf)));
  66. printk("\t\t(%p)outbuf.space=%u/%u\n", buf_dsp2cpu(params->outbuf),
  67. dsp_ringbuf_space(buf_dsp2cpu(params->outbuf)),
  68. dsp_ringbuf_size(buf_dsp2cpu(params->outbuf)));
  69. printk("\truntime:\n");
  70. printk("\t\tsample_count=%u\n", runtime->sample_count);
  71. }
  72. #endif
  73. static void dump_decoder_function(void *info, bool dump_debug)
  74. {
  75. struct decoder_dspfunc_info *decoder_info = info;
  76. struct decoder_dspfunc_params *params = &decoder_info->params;
  77. struct decoder_dspfunc_runtime *runtime = &decoder_info->runtime;
  78. struct decoder_dspfunc_debug *debug = &decoder_info->debug;
  79. printk("\nfunction decoder (id=%u):\n", DSP_FUNCTION_DECODER);
  80. printk("\tparameters:\n");
  81. printk("\t\tformat=%u\n", params->format);
  82. printk("\t\tsample_rate(in)=%u\n", params->resample_param.input_sr);
  83. printk("\t\tsample_rate(out)=%u\n", params->resample_param.output_sr);
  84. print_ringbuf_info("inbuf", params->inbuf, 0);
  85. print_ringbuf_info("outbuf", params->outbuf, 1);
  86. printk("\truntime:\n");
  87. printk("\t\tframe_size=%u\n", runtime->frame_size);
  88. printk("\t\tchannels=%u\n", runtime->channels);
  89. printk("\t\tsample_count=%u\n", runtime->sample_count);
  90. printk("\t\tdatalost_count=%u\n", runtime->datalost_count);
  91. printk("\t\traw_count=%u\n", runtime->raw_count);
  92. if (!dump_debug)
  93. return;
  94. printk("\tdebug:\n");
  95. if (debug->stream) {
  96. print_ringbuf_info("stream", debug->stream, 1);
  97. }
  98. if (debug->pcmbuf) {
  99. print_ringbuf_info("pcmbuf", debug->stream, 1);
  100. }
  101. }
  102. static void dump_encoder_function(void *info, bool dump_debug)
  103. {
  104. struct encoder_dspfunc_info *encoder_info = info;
  105. struct encoder_dspfunc_params *params = &encoder_info->params;
  106. struct encoder_dspfunc_runtime *runtime = &encoder_info->runtime;
  107. struct encoder_dspfunc_debug *debug = &encoder_info->debug;
  108. printk("\nfunction encoder (id=%u):\n", DSP_FUNCTION_ENCODER);
  109. printk("\tparameters:\n");
  110. printk("\t\tformat=%u\n", params->format);
  111. printk("\t\tsample_rate=%u\n", params->sample_rate);
  112. printk("\t\tbit_rate=%u\n", params->bit_rate);
  113. printk("\t\tcomplexityt=%u\n", params->complexity);
  114. printk("\t\tchannels=%u\n", params->channels);
  115. printk("\t\tframe_size=%u\n", params->frame_size);
  116. print_ringbuf_info("inbuf", params->inbuf, 0);
  117. print_ringbuf_info("outbuf", params->outbuf, 1);
  118. printk("\truntime:\n");
  119. printk("\t\tframe_size=%u\n", runtime->frame_size);
  120. printk("\t\tchannels=%u\n", runtime->channels);
  121. printk("\t\tcompression_ratio=%u\n", runtime->compression_ratio);
  122. printk("\t\tsample_count=%u\n", runtime->sample_count);
  123. if (!dump_debug)
  124. return;
  125. printk("\tdebug:\n");
  126. if (debug->pcmbuf) {
  127. print_ringbuf_info("pcmbuf", debug->pcmbuf, 1);
  128. }
  129. if (debug->stream) {
  130. print_ringbuf_info("stream", debug->stream, 1);
  131. }
  132. }
  133. static void dump_player_function(void *info, bool dump_debug)
  134. {
  135. struct player_dspfunc_info *player_info = info;
  136. struct decoder_dspfunc_info *decoder_info =
  137. (void *)dsp_data_to_mcu_address(POINTER_TO_UINT(player_info->decoder_info));
  138. struct player_dspfunc_debug *debug = &player_info->debug;
  139. printk("\nfunction player (id=%u):\n", DSP_FUNCTION_PLAYER);
  140. printk("\tparameters:\n");
  141. printk("\t\tdae.pbuf=%p\n", (void *)dsp_data_to_mcu_address(player_info->dae.pbuf));
  142. printk("\t\tdae.pbufsz=%u\n", player_info->dae.pbufsz);
  143. #if 0
  144. if (player_info->aec.enable) {
  145. printk("\t\taec.delay=%d\n", player_info->aec.delay);
  146. printk("\t\taec.refbuf=%p (space=%u/%u)\n",
  147. buf_dsp2cpu(player_info->aec.channel[0].refbuf),
  148. dsp_ringbuf_space(buf_dsp2cpu(player_info->aec.channel[0].refbuf)),
  149. dsp_ringbuf_size(buf_dsp2cpu(player_info->aec.channel[0].refbuf)));
  150. }
  151. #endif
  152. print_ringbuf_info("dacbuf", player_info->output.outbuf, 1);
  153. if (!dump_debug) {
  154. dump_decoder_function(decoder_info, false);
  155. return;
  156. }
  157. printk("\tdebug:\n");
  158. if (debug->decode_stream) {
  159. print_ringbuf_info("decode_stream", debug->decode_stream, 1);
  160. }
  161. if (debug->decode_data) {
  162. print_ringbuf_info("decode_data", debug->decode_data, 1);
  163. }
  164. if (debug->plc_data) {
  165. print_ringbuf_info("plc_data", debug->plc_data, 1);
  166. }
  167. dump_decoder_function(decoder_info, false);
  168. }
  169. static void dump_asr_function(void *info, bool dump_debug)
  170. {
  171. struct asr_dspfunc_info *asr_info = info;
  172. struct asr_dspfunc_params *params = &asr_info->params;
  173. struct asr_dspfunc_runtime *runtime = &asr_info->runtime;
  174. struct asr_dspfunc_debug *debug = &asr_info->debug;
  175. printk("\nfunction asr (id=%u):\n", DSP_FUNCTION_ASR);
  176. printk("\tparameters:\n");
  177. printk("\t\tsample_rate=%u\n", params->sample_rate);
  178. printk("\t\tinbuf=%p (length=%u/%u)\n",
  179. buf_dsp2cpu(params->inbuf),
  180. dsp_ringbuf_length(buf_dsp2cpu(params->inbuf)),
  181. dsp_ringbuf_size(buf_dsp2cpu(params->inbuf)));
  182. if (params->outbuf) {
  183. printk("\t\toutbuf=%p (space=%u/%u)\n",
  184. buf_dsp2cpu(params->outbuf),
  185. dsp_ringbuf_space(buf_dsp2cpu(params->outbuf)),
  186. dsp_ringbuf_size(buf_dsp2cpu(params->outbuf)));
  187. } else {
  188. printk("\t\toutbuf=null\n");
  189. }
  190. printk("\truntime:\n");
  191. printk("\t\tframe_size=%u\n", runtime->frame_size);
  192. printk("\t\tsample_count=%u\n", runtime->sample_count);
  193. printk("\t\tasr_id=%d\n", runtime->asr_id);
  194. printk("\t\tasr_count=%u\n", runtime->asr_count);
  195. if (!dump_debug)
  196. return;
  197. printk("\tdebug:\n");
  198. if (debug->pcmbuf) {
  199. printk("\t\tpcmbuf=%p (space=%u/%u)\n",
  200. buf_dsp2cpu(debug->pcmbuf),
  201. dsp_ringbuf_space(buf_dsp2cpu(debug->pcmbuf)),
  202. dsp_ringbuf_size(buf_dsp2cpu(debug->pcmbuf)));
  203. }
  204. if (debug->resbuf) {
  205. printk("\t\tstream=%p (space=%u/%u)\n",
  206. buf_dsp2cpu(debug->resbuf),
  207. dsp_ringbuf_space(buf_dsp2cpu(debug->resbuf)),
  208. dsp_ringbuf_size(buf_dsp2cpu(debug->resbuf)));
  209. }
  210. }
  211. static void dump_recorder_function(void *info, bool dump_debug)
  212. {
  213. struct recorder_dspfunc_info *recorder_info = info;
  214. struct recorder_dspfunc_params *params = &recorder_info->param;
  215. struct recorder_dspfunc_debug *debug = &recorder_info->debug;
  216. struct asr_dspfunc_info *asr_info =
  217. (void *)dsp_data_to_mcu_address(recorder_info->asr_info);
  218. struct encoder_dspfunc_info *encoder_info =
  219. (void *)dsp_data_to_mcu_address((u32_t)recorder_info->encoder_info);
  220. printk("\nfunction recorder (id=%u):\n", DSP_FUNCTION_RECORDER);
  221. printk("\tparameters: %p params %p\n",recorder_info,params);
  222. printk("\t\tmode=%d\n", params->mode);
  223. if (params->evtbuf) {
  224. printk("\t\tevtbuf=%p (length=%u/%u)\n",
  225. buf_dsp2cpu(params->evtbuf),
  226. dsp_ringbuf_length(buf_dsp2cpu(params->evtbuf)),
  227. dsp_ringbuf_size(buf_dsp2cpu(params->evtbuf)));
  228. }
  229. printk("\t\tdae\n");
  230. printk("\t\t - pbuf=%p\n", (void *)buf_dsp2cpu(recorder_info->dae.pbuf));
  231. printk("\t\t - pbufsz=%u\n", recorder_info->dae.pbufsz);
  232. if (recorder_info->aec_ref.channel[0].refbuf) {
  233. printk("\t\taec.delay=%d\n", recorder_info->aec_ref.delay);
  234. printk("\t\taec.refbuf=%p (space=%u/%u)\n",
  235. buf_dsp2cpu(recorder_info->aec_ref.channel[0].refbuf),
  236. dsp_ringbuf_space(buf_dsp2cpu(recorder_info->aec_ref.channel[0].refbuf)),
  237. dsp_ringbuf_size(buf_dsp2cpu(recorder_info->aec_ref.channel[0].refbuf)));
  238. }
  239. printk("\t\tvad\n");
  240. printk("\t\t - enabled=%u\n", recorder_info->vad.enabled);
  241. if (recorder_info->vad.enabled) {
  242. printk("\t\t - sample_rate=%u\n", recorder_info->vad.sample_rate);
  243. printk("\t\t - channels=%u\n", recorder_info->vad.channels);
  244. printk("\t\t - amplitude=%u\n", recorder_info->vad.amplitude);
  245. printk("\t\t - energy=%u\n", recorder_info->vad.energy);
  246. printk("\t\t - decibel=%u\n", recorder_info->vad.decibel);
  247. printk("\t\t - period=%u\n", recorder_info->vad.period);
  248. printk("\t\t - uptime=%u\n", recorder_info->vad.uptime);
  249. printk("\t\t - downtime=%u\n", recorder_info->vad.downtime);
  250. printk("\t\t - slowadapt=%u\n", recorder_info->vad.slowadapt);
  251. printk("\t\t - fastadapt=%u\n", recorder_info->vad.fastadapt);
  252. printk("\t\t - agc=%u\n", recorder_info->vad.agc);
  253. printk("\t\t - ns=%u\n", recorder_info->vad.ns);
  254. printk("\t\t - outputzero=%u\n", recorder_info->vad.outputzero);
  255. }
  256. printk("\t\tadcbuf=%p (length=%u/%u)\n",
  257. buf_dsp2cpu(recorder_info->adcbuf),
  258. dsp_ringbuf_space(buf_dsp2cpu(recorder_info->adcbuf)),
  259. dsp_ringbuf_size(buf_dsp2cpu(recorder_info->adcbuf)));
  260. if (!dump_debug) {
  261. dump_encoder_function(encoder_info, false);
  262. return;
  263. }
  264. printk("\tdebug:\n");
  265. if (debug->mic1_data) {
  266. printk("\t\tmic1_data=%p (space=%u/%u)\n",
  267. buf_dsp2cpu(debug->mic1_data),
  268. dsp_ringbuf_space(buf_dsp2cpu(debug->mic1_data)),
  269. dsp_ringbuf_size(buf_dsp2cpu(debug->mic1_data)));
  270. }
  271. if (debug->mic2_data) {
  272. printk("\t\tmic2_data=%p (space=%u/%u)\n",
  273. buf_dsp2cpu(debug->mic2_data),
  274. dsp_ringbuf_space(buf_dsp2cpu(debug->mic2_data)),
  275. dsp_ringbuf_size(buf_dsp2cpu(debug->mic2_data)));
  276. }
  277. if (debug->ref_data) {
  278. printk("\t\tref_data=%p (space=%u/%u)\n",
  279. buf_dsp2cpu(debug->ref_data),
  280. dsp_ringbuf_space(buf_dsp2cpu(debug->ref_data)),
  281. dsp_ringbuf_size(buf_dsp2cpu(debug->ref_data)));
  282. }
  283. if (debug->aec1_data) {
  284. printk("\t\taec1_data=%p (space=%u/%u)\n",
  285. buf_dsp2cpu(debug->aec1_data),
  286. dsp_ringbuf_space(buf_dsp2cpu(debug->aec1_data)),
  287. dsp_ringbuf_size(buf_dsp2cpu(debug->aec1_data)));
  288. }
  289. if (debug->aec2_data) {
  290. printk("\t\taec2_data=%p (space=%u/%u)\n",
  291. buf_dsp2cpu(debug->aec2_data),
  292. dsp_ringbuf_space(buf_dsp2cpu(debug->aec2_data)),
  293. dsp_ringbuf_size(buf_dsp2cpu(debug->aec2_data)));
  294. }
  295. if (debug->encode_data) {
  296. printk("\t\tencode_data=%p (space=%u/%u)\n",
  297. buf_dsp2cpu(debug->encode_data),
  298. dsp_ringbuf_space(buf_dsp2cpu(debug->encode_data)),
  299. dsp_ringbuf_size(buf_dsp2cpu(debug->encode_data)));
  300. }
  301. if (debug->encode_stream) {
  302. printk("\t\tencode_stream=%p (space=%u/%u)\n",
  303. buf_dsp2cpu(debug->encode_stream),
  304. dsp_ringbuf_space(buf_dsp2cpu(debug->encode_stream)),
  305. dsp_ringbuf_size(buf_dsp2cpu(debug->encode_stream)));
  306. }
  307. if (params->mode == RECORDER_DSPMODE_ENCODE)
  308. dump_encoder_function(encoder_info, false);
  309. else
  310. dump_asr_function(asr_info, false);
  311. }
  312. void dsp_session_dump_function(struct dsp_session *session, unsigned int func)
  313. {
  314. struct dsp_request_function request = { .id = func, };
  315. dsp_request_userinfo(session->dev, DSP_REQUEST_FUNCTION_INFO, &request);
  316. if (request.info == NULL)
  317. return;
  318. switch (func) {
  319. #if 0
  320. case DSP_FUNCTION_TEST:
  321. dump_test_function(request.info, true);
  322. break;
  323. #endif
  324. case DSP_FUNCTION_ENCODER:
  325. dump_encoder_function(request.info, true);
  326. break;
  327. case DSP_FUNCTION_DECODER:
  328. dump_decoder_function(request.info, true);
  329. break;
  330. case DSP_FUNCTION_PLAYER:
  331. dump_player_function(request.info, true);
  332. break;
  333. case DSP_FUNCTION_RECORDER:
  334. dump_recorder_function(request.info, true);
  335. break;
  336. default:
  337. break;
  338. }
  339. }
  340. unsigned int dsp_session_get_samples_count(struct dsp_session *session, unsigned int func)
  341. {
  342. union {
  343. struct test_dspfunc_info *test;
  344. struct encoder_dspfunc_info *encoder;
  345. struct decoder_dspfunc_info *decoder;
  346. } func_info;
  347. if (func == DSP_FUNCTION_PLAYER)
  348. func = DSP_FUNCTION_DECODER;
  349. else if (func == DSP_FUNCTION_RECORDER)
  350. func = DSP_FUNCTION_ENCODER;
  351. struct dsp_request_function request = { .id = func, };
  352. dsp_request_userinfo(session->dev, DSP_REQUEST_FUNCTION_INFO, &request);
  353. if (request.info == NULL)
  354. return 0;
  355. switch (func) {
  356. #if 0
  357. case DSP_FUNCTION_TEST:
  358. func_info.test = request.info;
  359. return func_info.test->runtime.sample_count;
  360. #endif
  361. case DSP_FUNCTION_ENCODER:
  362. func_info.encoder = request.info;
  363. return func_info.encoder->runtime.sample_count;
  364. case DSP_FUNCTION_DECODER:
  365. func_info.decoder = request.info;
  366. return func_info.decoder->runtime.sample_count;
  367. default:
  368. return 0;
  369. }
  370. }
  371. unsigned int dsp_session_get_datalost_count(struct dsp_session *session, unsigned int func)
  372. {
  373. struct dsp_request_function request = { .id = DSP_FUNCTION_DECODER, };
  374. if (func != DSP_FUNCTION_PLAYER && func != DSP_FUNCTION_DECODER)
  375. return 0;
  376. dsp_request_userinfo(session->dev, DSP_REQUEST_FUNCTION_INFO, &request);
  377. if (request.info) {
  378. struct decoder_dspfunc_info *decoder = request.info;
  379. return decoder->runtime.datalost_count;
  380. }
  381. return 0;
  382. }
  383. unsigned int dsp_session_get_raw_count(struct dsp_session *session, unsigned int func)
  384. {
  385. struct dsp_request_function request = { .id = DSP_FUNCTION_DECODER, };
  386. if (func != DSP_FUNCTION_PLAYER && func != DSP_FUNCTION_DECODER)
  387. return 0;
  388. dsp_request_userinfo(session->dev, DSP_REQUEST_FUNCTION_INFO, &request);
  389. if (request.info) {
  390. struct decoder_dspfunc_info *decoder = request.info;
  391. return decoder->runtime.raw_count;
  392. }
  393. return 0;
  394. }
  395. int dsp_session_get_recoder_param(struct dsp_session *session, int param_type, void *param)
  396. {
  397. struct dsp_request_session session_request;
  398. struct dsp_request_function request = { .id = DSP_FUNCTION_RECORDER, };
  399. dsp_request_userinfo(session->dev, DSP_REQUEST_SESSION_INFO, &session_request);
  400. if (!(session_request.func_enabled & DSP_FUNC_BIT(DSP_FUNCTION_RECORDER))) {
  401. return -EINVAL;
  402. }
  403. dsp_request_userinfo(session->dev, DSP_REQUEST_FUNCTION_INFO, &request);
  404. if (request.info) {
  405. struct recorder_dspfunc_info *encoder = request.info;
  406. if (param_type == DSP_CONFIG_AEC) {
  407. memcpy(param, &encoder->aec, sizeof(struct aec_dspfunc_params));
  408. return 0;
  409. }
  410. }
  411. return -EINVAL;
  412. }