blob: 021e6f875e1874c8076c098277dca79831f95ed6
1 | /** |
2 | * \file adec-external-ctrl.c |
3 | * \brief Audio Dec Lib Functions |
4 | * \version 1.0.0 |
5 | * \date 2011-03-08 |
6 | */ |
7 | /* Copyright (C) 2007-2011, Amlogic Inc. |
8 | * All right reserved |
9 | * |
10 | */ |
11 | |
12 | #include <stdio.h> |
13 | #include <stdlib.h> |
14 | #include <string.h> |
15 | #include <fcntl.h> |
16 | |
17 | #include <math.h> |
18 | #include <unistd.h> |
19 | |
20 | #include <audio-dec.h> |
21 | #include <amthreadpool.h> |
22 | |
23 | |
24 | |
25 | int audio_decode_basic_init(void) |
26 | { |
27 | #ifndef ALSA_OUT |
28 | android_basic_init(); |
29 | #endif |
30 | amthreadpool_system_init(); |
31 | |
32 | return 0; |
33 | } |
34 | |
35 | /** |
36 | * \brief init audio dec |
37 | * \param handle pointer to player private data |
38 | * \return 0 on success otherwise -1 if an error occurred |
39 | */ |
40 | int audio_decode_init(void **handle, arm_audio_info *a_ainfo) |
41 | { |
42 | int ret; |
43 | aml_audio_dec_t *audec; |
44 | |
45 | if (*handle) { |
46 | adec_print("Existing an audio dec instance!Need not to create it !"); |
47 | return -1; |
48 | } |
49 | |
50 | audec = (aml_audio_dec_t *)malloc(sizeof(aml_audio_dec_t)); |
51 | if (audec == NULL) { |
52 | adec_print("malloc failed! not enough memory !"); |
53 | return -1; |
54 | } |
55 | //set param for arm audio decoder |
56 | memset(audec, 0, sizeof(aml_audio_dec_t)); |
57 | audec->channels = a_ainfo->channels; |
58 | audec->samplerate = a_ainfo->sample_rate; |
59 | audec->format = a_ainfo->format; |
60 | audec->adsp_ops.dsp_file_fd = a_ainfo->handle; |
61 | audec->adsp_ops.amstream_fd = a_ainfo->handle; |
62 | audec->extradata_size = a_ainfo->extradata_size; |
63 | audec->SessionID = a_ainfo->SessionID; |
64 | audec->dspdec_not_supported = a_ainfo->dspdec_not_supported; |
65 | audec->droppcm_flag = 0; |
66 | audec->bitrate = a_ainfo->bitrate; |
67 | audec->block_align = a_ainfo->block_align; |
68 | audec->codec_id = a_ainfo->codec_id; |
69 | audec->auto_mute = a_ainfo->automute; |
70 | audec->has_video=a_ainfo->has_video; |
71 | if (a_ainfo->droppcm_flag) { |
72 | audec->droppcm_flag = a_ainfo->droppcm_flag; |
73 | a_ainfo->droppcm_flag = 0; |
74 | } |
75 | if (a_ainfo->extradata_size > 0 && a_ainfo->extradata_size <= AUDIO_EXTRA_DATA_SIZE) { |
76 | memcpy((char*)audec->extradata, (char*)a_ainfo->extradata, a_ainfo->extradata_size); |
77 | } |
78 | audec->adsp_ops.audec = audec; |
79 | // adec_print("audio_decode_init pcodec = %d, pcodec->ctxCodec = %d!\n", pcodec, pcodec->ctxCodec); |
80 | ret = audiodec_init(audec); |
81 | if (ret) { |
82 | adec_print("adec init failed!"); |
83 | return -1; |
84 | } |
85 | |
86 | *handle = (void *)audec; |
87 | |
88 | return 0; |
89 | } |
90 | |
91 | /** |
92 | * \brief start audio dec |
93 | * \param handle pointer to player private data |
94 | * \return 0 on success otherwise -1 if an error occurred |
95 | */ |
96 | int audio_decode_start(void *handle) |
97 | { |
98 | int ret; |
99 | adec_cmd_t *cmd; |
100 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
101 | |
102 | if (!handle) { |
103 | adec_print("audio handle is NULL !\n"); |
104 | return -1; |
105 | } |
106 | |
107 | cmd = adec_message_alloc(); |
108 | if (cmd) { |
109 | cmd->ctrl_cmd = CMD_START; |
110 | ret = adec_send_message(audec, cmd); |
111 | } else { |
112 | adec_print("message alloc failed, no memory!"); |
113 | ret = -1; |
114 | } |
115 | |
116 | return ret; |
117 | } |
118 | |
119 | /** |
120 | * \brief pause audio dec |
121 | * \param handle pointer to player private data |
122 | * \return 0 on success otherwise -1 if an error occurred |
123 | */ |
124 | int audio_decode_pause(void *handle) |
125 | { |
126 | int ret; |
127 | adec_cmd_t *cmd; |
128 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
129 | |
130 | if (!handle) { |
131 | adec_print("audio handle is NULL !\n"); |
132 | return -1; |
133 | } |
134 | |
135 | cmd = adec_message_alloc(); |
136 | if (cmd) { |
137 | cmd->ctrl_cmd = CMD_PAUSE; |
138 | ret = adec_send_message(audec, cmd); |
139 | } else { |
140 | adec_print("message alloc failed, no memory!"); |
141 | ret = -1; |
142 | } |
143 | |
144 | return ret; |
145 | } |
146 | |
147 | /** |
148 | * \brief resume audio dec |
149 | * \param handle pointer to player private data |
150 | * \return 0 on success otherwise -1 if an error occurred |
151 | */ |
152 | int audio_decode_resume(void *handle) |
153 | { |
154 | int ret; |
155 | adec_cmd_t *cmd; |
156 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
157 | |
158 | if (!handle) { |
159 | adec_print("audio handle is NULL !\n"); |
160 | return -1; |
161 | } |
162 | |
163 | cmd = adec_message_alloc(); |
164 | if (cmd) { |
165 | cmd->ctrl_cmd = CMD_RESUME; |
166 | ret = adec_send_message(audec, cmd); |
167 | } else { |
168 | adec_print("message alloc failed, no memory!"); |
169 | ret = -1; |
170 | } |
171 | |
172 | return ret; |
173 | } |
174 | |
175 | /** |
176 | * \brief stop audio dec |
177 | * \param handle pointer to player private data |
178 | * \return 0 on success otherwise -1 if an error occurred |
179 | */ |
180 | int audio_decode_stop(void *handle) |
181 | { |
182 | int ret; |
183 | adec_cmd_t *cmd; |
184 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
185 | |
186 | if (!handle) { |
187 | adec_print("audio handle is NULL !\n"); |
188 | return -1; |
189 | } |
190 | |
191 | audec->need_stop = 1; |
192 | |
193 | cmd = adec_message_alloc(); |
194 | if (cmd) { |
195 | cmd->ctrl_cmd = CMD_STOP; |
196 | ret = adec_send_message(audec, cmd); |
197 | amthreadpool_pool_thread_cancel(audec->thread_pid); |
198 | } else { |
199 | adec_print("message alloc failed, no memory!"); |
200 | ret = -1; |
201 | } |
202 | |
203 | return ret; |
204 | } |
205 | |
206 | /** |
207 | * \brief release audio dec |
208 | * \param handle pointer to player private data |
209 | * \return 0 on success otherwise -1 if an error occurred |
210 | */ |
211 | int audio_decode_release(void **handle) |
212 | { |
213 | int ret; |
214 | adec_cmd_t *cmd; |
215 | aml_audio_dec_t *audec = (aml_audio_dec_t *) * handle; |
216 | |
217 | if (!handle) { |
218 | adec_print("audio handle is NULL !\n"); |
219 | return -1; |
220 | } |
221 | |
222 | cmd = adec_message_alloc(); |
223 | if (cmd) { |
224 | cmd->ctrl_cmd = CMD_RELEASE; |
225 | ret = adec_send_message(audec, cmd); |
226 | } else { |
227 | adec_print("message alloc failed, no memory!"); |
228 | ret = -1; |
229 | } |
230 | |
231 | ret = amthreadpool_pthread_join(audec->thread_pid, NULL); |
232 | |
233 | free(*handle); |
234 | *handle = NULL; |
235 | |
236 | return ret; |
237 | |
238 | } |
239 | |
240 | /** |
241 | * \brief set auto-mute state in audio decode |
242 | * \param handle pointer to player private data |
243 | * \param stat 1 = enable automute, 0 = disable automute |
244 | * \return 0 on success otherwise -1 if an error occurred |
245 | */ |
246 | int audio_decode_automute(void *handle, int stat) |
247 | { |
248 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
249 | |
250 | if (!handle) { |
251 | adec_print("audio handle is NULL !\n"); |
252 | return -1; |
253 | } |
254 | adec_print("[%s:%d]set automute %d!\n", __FUNCTION__, __LINE__, stat); |
255 | //audec->auto_mute = 1; |
256 | audec->auto_mute = stat; |
257 | return 0; |
258 | } |
259 | |
260 | /** |
261 | * \brief mute audio output |
262 | * \param handle pointer to player private data |
263 | * \param en 1 = mute output, 0 = unmute output |
264 | * \return 0 on success otherwise -1 if an error occurred |
265 | */ |
266 | int audio_decode_set_mute(void *handle, int en) |
267 | { |
268 | int ret; |
269 | adec_cmd_t *cmd; |
270 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
271 | |
272 | if (!handle) { |
273 | adec_print("audio handle is NULL !\n"); |
274 | return -1; |
275 | } |
276 | |
277 | cmd = adec_message_alloc(); |
278 | if (cmd) { |
279 | cmd->ctrl_cmd = CMD_MUTE; |
280 | cmd->value.en = en; |
281 | cmd->has_arg = 1; |
282 | ret = adec_send_message(audec, cmd); |
283 | } else { |
284 | adec_print("message alloc failed, no memory!"); |
285 | ret = -1; |
286 | } |
287 | |
288 | return ret; |
289 | } |
290 | |
291 | /** |
292 | * \brief set audio volume |
293 | * \param handle pointer to player private data |
294 | * \param vol volume value |
295 | * \return 0 on success otherwise -1 if an error occurred |
296 | */ |
297 | int audio_decode_set_volume(void *handle, float vol) |
298 | { |
299 | int ret; |
300 | adec_cmd_t *cmd; |
301 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
302 | |
303 | if (!handle) { |
304 | adec_print("audio handle is NULL !\n"); |
305 | return -1; |
306 | } |
307 | |
308 | cmd = adec_message_alloc(); |
309 | if (cmd) { |
310 | cmd->ctrl_cmd = CMD_SET_VOL; |
311 | cmd->value.volume = vol; |
312 | audec->volume = vol; |
313 | cmd->has_arg = 1; |
314 | ret = adec_send_message(audec, cmd); |
315 | } else { |
316 | adec_print("message alloc failed, no memory!"); |
317 | ret = -1; |
318 | } |
319 | |
320 | return ret; |
321 | } |
322 | |
323 | /** |
324 | * \brief set audio pre-gain |
325 | * \param handle pointer to player private data |
326 | * \param gain pre-gain value |
327 | * \return 0 on success otherwise -1 if an error occurred |
328 | */ |
329 | int audio_decode_set_pre_gain(void *handle, float gain) |
330 | { |
331 | int ret = 0; |
332 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
333 | if (!handle) { |
334 | adec_print("audio handle is NULL !\n"); |
335 | ret = -1; |
336 | } else { |
337 | audec->pre_gain_enable = 1; |
338 | //audec->pre_gain = powf(10.0f, gain/20); |
339 | adec_print("[%s] set pre-gain[%f] \n", __FUNCTION__, audec->pre_gain); |
340 | } |
341 | return ret; |
342 | } |
343 | |
344 | /** |
345 | * \brief set audio decode pre-mute |
346 | * \param handle pointer to player private data |
347 | * \param mute pre-mute value |
348 | * \return 0 on success otherwise -1 if an error occurred |
349 | */ |
350 | int audio_decode_set_pre_mute(void *handle, uint mute) |
351 | { |
352 | int ret = 0; |
353 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
354 | if (!handle) { |
355 | adec_print("audio handle is NULL !\n"); |
356 | ret = -1; |
357 | } else { |
358 | audec->pre_mute = mute; |
359 | adec_print("[%s] set pre-mute[%d] \n", __FUNCTION__, audec->pre_mute); |
360 | } |
361 | return ret; |
362 | } |
363 | |
364 | /** |
365 | * \brief set audio volume |
366 | * \param handle pointer to player private data |
367 | * \param vol volume value |
368 | * \return 0 on success otherwise -1 if an error occurred |
369 | */ |
370 | int audio_decode_set_lrvolume(void *handle, float lvol, float rvol) |
371 | { |
372 | int ret; |
373 | adec_cmd_t *cmd; |
374 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
375 | |
376 | if (!handle) { |
377 | adec_print("audio handle is NULL !\n"); |
378 | return -1; |
379 | } |
380 | |
381 | cmd = adec_message_alloc(); |
382 | if (cmd) { |
383 | cmd->ctrl_cmd = CMD_SET_LRVOL; |
384 | cmd->value.volume = lvol; |
385 | audec->volume = lvol; |
386 | cmd->has_arg = 1; |
387 | cmd->value_ext.volume = rvol; |
388 | audec->volume_ext = rvol; |
389 | ret = adec_send_message(audec, cmd); |
390 | } else { |
391 | adec_print("message alloc failed, no memory!"); |
392 | ret = -1; |
393 | } |
394 | |
395 | return ret; |
396 | } |
397 | |
398 | /** |
399 | * \brief set audio volume |
400 | * \param handle pointer to player private data |
401 | * \param vol volume value |
402 | * \return 0 on success otherwise -1 if an error occurred |
403 | */ |
404 | int audio_decode_get_volume(void *handle, float *vol) |
405 | { |
406 | int ret = 0; |
407 | adec_cmd_t *cmd; |
408 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
409 | |
410 | if (!handle) { |
411 | adec_print("audio handle is NULL !\n"); |
412 | return -1; |
413 | } |
414 | |
415 | *vol = audec->volume; |
416 | |
417 | return ret; |
418 | } |
419 | |
420 | /** |
421 | * \brief get audio pre-gain |
422 | * \param handle pointer to player private data |
423 | * \param gain pre-gain value |
424 | * \return 0 on success otherwise -1 if an error occurred |
425 | */ |
426 | int audio_decode_get_pre_gain(void *handle, float *gain) |
427 | { |
428 | int ret = 0; |
429 | adec_cmd_t *cmd; |
430 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
431 | |
432 | if (!handle) { |
433 | adec_print("audio handle is NULL !\n"); |
434 | return -1; |
435 | } |
436 | |
437 | //*gain = 20*log10f((float)audec->pre_gain); |
438 | |
439 | return ret; |
440 | } |
441 | |
442 | /** |
443 | * \brief get audio decode pre-mute |
444 | * \param handle pointer to player private data |
445 | * \param mute pre-mute value |
446 | * \return 0 on success otherwise -1 if an error occurred |
447 | */ |
448 | int audio_decode_get_pre_mute(void *handle, uint *mute) |
449 | { |
450 | int ret = 0; |
451 | adec_cmd_t *cmd; |
452 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
453 | |
454 | if (!handle) { |
455 | adec_print("audio handle is NULL !\n"); |
456 | return -1; |
457 | } |
458 | |
459 | *mute = audec->pre_mute; |
460 | |
461 | return ret; |
462 | } |
463 | |
464 | /** |
465 | * \brief set audio volume |
466 | * \param handle pointer to player private data |
467 | * \param lvol: left volume value,rvol:right volume value |
468 | * \return 0 on success otherwise -1 if an error occurred |
469 | */ |
470 | int audio_decode_get_lrvolume(void *handle, float *lvol, float* rvol) |
471 | { |
472 | int ret = 0; |
473 | adec_cmd_t *cmd; |
474 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
475 | |
476 | if (!handle) { |
477 | adec_print("audio handle is NULL !\n"); |
478 | return -1; |
479 | } |
480 | |
481 | *lvol = audec->volume; |
482 | *rvol = audec->volume_ext; |
483 | |
484 | return ret; |
485 | } |
486 | |
487 | /** |
488 | * \brief swap audio left and right channels |
489 | * \param handle pointer to player private data |
490 | * \return 0 on success otherwise -1 if an error occurred |
491 | */ |
492 | int audio_channels_swap(void *handle) |
493 | { |
494 | int ret; |
495 | adec_cmd_t *cmd; |
496 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
497 | |
498 | if (!handle) { |
499 | adec_print("audio handle is NULL !\n"); |
500 | return -1; |
501 | } |
502 | |
503 | cmd = adec_message_alloc(); |
504 | if (cmd) { |
505 | audec->soundtrack = HW_CHANNELS_SWAP; |
506 | cmd->ctrl_cmd = CMD_CHANL_SWAP; |
507 | ret = adec_send_message(audec, cmd); |
508 | } else { |
509 | adec_print("message alloc failed, no memory!"); |
510 | ret = -1; |
511 | } |
512 | |
513 | return ret; |
514 | } |
515 | |
516 | /** |
517 | * \brief output left channel |
518 | * \param handle pointer to player private data |
519 | * \return 0 on success otherwise -1 if an error occurred |
520 | */ |
521 | int audio_channel_left_mono(void *handle) |
522 | { |
523 | int ret; |
524 | adec_cmd_t *cmd; |
525 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
526 | |
527 | if (!handle) { |
528 | adec_print("audio handle is NULL !\n"); |
529 | return -1; |
530 | } |
531 | |
532 | cmd = adec_message_alloc(); |
533 | if (cmd) { |
534 | audec->soundtrack = HW_LEFT_CHANNEL_MONO; |
535 | cmd->ctrl_cmd = CMD_LEFT_MONO; |
536 | ret = adec_send_message(audec, cmd); |
537 | } else { |
538 | adec_print("message alloc failed, no memory!"); |
539 | ret = -1; |
540 | } |
541 | |
542 | return ret; |
543 | } |
544 | |
545 | /** |
546 | * \brief output right channel |
547 | * \param handle pointer to player private data |
548 | * \return 0 on success otherwise -1 if an error occurred |
549 | */ |
550 | int audio_channel_right_mono(void *handle) |
551 | { |
552 | int ret; |
553 | adec_cmd_t *cmd; |
554 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
555 | |
556 | if (!handle) { |
557 | adec_print("audio handle is NULL !\n"); |
558 | return -1; |
559 | } |
560 | |
561 | cmd = adec_message_alloc(); |
562 | if (cmd) { |
563 | audec->soundtrack = HW_RIGHT_CHANNEL_MONO; |
564 | cmd->ctrl_cmd = CMD_RIGHT_MONO; |
565 | ret = adec_send_message(audec, cmd); |
566 | } else { |
567 | adec_print("message alloc failed, no memory!"); |
568 | ret = -1; |
569 | } |
570 | |
571 | return ret; |
572 | } |
573 | |
574 | /** |
575 | * \brief output left and right channels |
576 | * \param handle pointer to player private data |
577 | * \return 0 on success otherwise -1 if an error occurred |
578 | */ |
579 | int audio_channel_stereo(void *handle) |
580 | { |
581 | int ret; |
582 | adec_cmd_t *cmd; |
583 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
584 | |
585 | if (!handle) { |
586 | adec_print("audio handle is NULL !\n"); |
587 | return -1; |
588 | } |
589 | |
590 | cmd = adec_message_alloc(); |
591 | if (cmd) { |
592 | audec->soundtrack = HW_STEREO_MODE; |
593 | cmd->ctrl_cmd = CMD_STEREO; |
594 | ret = adec_send_message(audec, cmd); |
595 | } else { |
596 | adec_print("message alloc failed, no memory!"); |
597 | ret = -1; |
598 | } |
599 | |
600 | return ret; |
601 | } |
602 | |
603 | int audio_channel_lrmix_flag_set(void *handle, int enable) |
604 | { |
605 | int ret = 0; |
606 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
607 | if (!handle) { |
608 | adec_print("audio handle is NULL !\n"); |
609 | ret = -1; |
610 | } else { |
611 | audec->mix_lr_channel_enable = enable; |
612 | adec_print("[%s] set audec->mix_lr_channel_enable/%d \n", __FUNCTION__, audec->mix_lr_channel_enable); |
613 | } |
614 | return ret; |
615 | } |
616 | |
617 | int audio_decpara_get(void *handle, int *pfs, int *pch ,int *lfepresent) |
618 | { |
619 | int ret = 0; |
620 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
621 | if (!handle) { |
622 | adec_print("audio handle is NULL !\n"); |
623 | ret = -1; |
624 | } else if (pfs != NULL && pch != NULL && lfepresent != NULL) { |
625 | if (audec->adec_ops != NULL) { //armdecoder case |
626 | *pch = audec->adec_ops->NchOriginal; |
627 | *lfepresent = audec->adec_ops->lfepresent; |
628 | } else { //DSP case |
629 | *pch = audec->channels; |
630 | } |
631 | *pfs = audec->samplerate; |
632 | } |
633 | return ret; |
634 | } |
635 | /** |
636 | * \brief check output mute or not |
637 | * \param handle pointer to player private data |
638 | * \return 1 = output is mute, 0 = output not mute |
639 | */ |
640 | int audio_output_muted(void *handle) |
641 | { |
642 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
643 | |
644 | if (!handle) { |
645 | adec_print("audio handle is NULL !\n"); |
646 | return -1; |
647 | } |
648 | |
649 | return audec->muted; |
650 | } |
651 | |
652 | /** |
653 | * \brief check audiodec ready or not |
654 | * \param handle pointer to player private data |
655 | * \return 1 = audiodec is ready, 0 = audiodec not ready |
656 | */ |
657 | int audio_dec_ready(void *handle) |
658 | { |
659 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
660 | |
661 | if (!handle) { |
662 | adec_print("audio handle is NULL !\n"); |
663 | return -1; |
664 | } |
665 | |
666 | if (audec->state > INITTED) { |
667 | return 1; |
668 | } else { |
669 | return 0; |
670 | } |
671 | } |
672 | |
673 | /** |
674 | * \brief get audio dsp decoded frame number |
675 | * \param handle pointer to player private data |
676 | * \return n = audiodec frame number, -1 = error |
677 | */ |
678 | int audio_get_decoded_nb_frames(void *handle) |
679 | { |
680 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
681 | |
682 | if (!handle) { |
683 | adec_print("audio handle is NULL !\n"); |
684 | return -1; |
685 | } |
686 | |
687 | audec->decoded_nb_frames = audiodsp_get_decoded_nb_frames(&audec->adsp_ops); |
688 | //adec_print("audio_get_decoded_nb_frames: %d!", audec->decoded_nb_frames); |
689 | if (audec->decoded_nb_frames >= 0) { |
690 | return audec->decoded_nb_frames; |
691 | } else { |
692 | return -2; |
693 | } |
694 | } |
695 | |
696 | /** |
697 | * \brief set av sync threshold in ms. |
698 | * \param handle pointer to player private data |
699 | * \param threshold av sync time threshold in ms |
700 | */ |
701 | int audio_set_av_sync_threshold(void *handle, int threshold) |
702 | { |
703 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
704 | |
705 | if (!handle) { |
706 | adec_print("audio handle is NULL !\n"); |
707 | return -1; |
708 | } |
709 | |
710 | if ((threshold > 500) || (threshold < 60)) { |
711 | adec_print("threshold %d id too small or too large.\n", threshold); |
712 | } |
713 | |
714 | audec->avsync_threshold = threshold * 90; |
715 | return 0; |
716 | } |
717 | int audio_get_soundtrack(void *handle, int* strack) |
718 | { |
719 | int ret = 0; |
720 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
721 | |
722 | if (!handle) { |
723 | adec_print("audio handle is NULL !\n"); |
724 | return -1; |
725 | } |
726 | |
727 | *strack = audec->soundtrack; |
728 | |
729 | return ret; |
730 | } |
731 | |
732 | int audio_get_pcm_level(void* handle) |
733 | { |
734 | aml_audio_dec_t* audec = (aml_audio_dec_t*)handle; |
735 | if (!handle) { |
736 | adec_print("audio handle is NULL !\n"); |
737 | return -1; |
738 | } |
739 | |
740 | return audiodsp_get_pcm_level(&audec->adsp_ops); |
741 | |
742 | } |
743 | |
744 | int audio_set_skip_bytes(void* handle, unsigned int bytes) |
745 | { |
746 | aml_audio_dec_t* audec = (aml_audio_dec_t*) handle; |
747 | if (!handle) { |
748 | adec_print("audio handle is NULL !!\n"); |
749 | return -1; |
750 | } |
751 | |
752 | return audiodsp_set_skip_bytes(&audec->adsp_ops, bytes); |
753 | } |
754 | |
755 | int audio_get_pts(void* handle) |
756 | { |
757 | aml_audio_dec_t* audec = (aml_audio_dec_t*)handle; |
758 | if (!handle) { |
759 | adec_print("audio handle is NULL !\n"); |
760 | return -1; |
761 | } |
762 | return audiodsp_get_pts(&audec->adsp_ops); |
763 | } |
764 | /* |
765 | @get the audio decoder enabled status ,special for dts/dolby audio , |
766 | @note that :this should be called after audio_decode_start, |
767 | @because the status was got from decoder. |
768 | @default set a invalid value -1.so if got value -1,it means have not got the decoder status.try again. |
769 | @return 0:disable ; 1:enable ; |
770 | |
771 | */ |
772 | int audio_decoder_get_enable_status(void* handle) |
773 | { |
774 | aml_audio_dec_t* audec = (aml_audio_dec_t*)handle; |
775 | if (!handle) { |
776 | adec_print("audio handle is NULL !\n"); |
777 | return -1; |
778 | } |
779 | return audec->audio_decoder_enabled; |
780 | } |
781 | |
782 | /** |
783 | * \brief get audio decoder cached latency |
784 | * \param handle pointer to player private data |
785 | * \return n = audio decoder cached latency ms, -1 = error |
786 | */ |
787 | int audio_get_decoded_pcm_delay(void *handle) |
788 | { |
789 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
790 | if (!audec) { |
791 | adec_print("audec null\n"); |
792 | return -1; |
793 | } |
794 | buffer_stream_t *g_bst = audec->g_bst; |
795 | if (!handle) { |
796 | adec_print("audio handle is NULL !\n"); |
797 | return -1; |
798 | } |
799 | if (!g_bst) { |
800 | return 0; |
801 | } else if (audec->samplerate && audec->channels) { |
802 | return g_bst->buf_level * 1000 / (audec->samplerate * audec->channels * 2); |
803 | } else { |
804 | return 0; |
805 | } |
806 | } |
807 | /** |
808 | * \brief check if the audio format supported by audio decoder |
809 | * \param handle pointer to player private data |
810 | * \return 0 = diable,1 = enable, -1 = error |
811 | */ |
812 | int audio_get_format_supported(int format) |
813 | { |
814 | int enable = 1; |
815 | if (format == ACODEC_FMT_DRA) { |
816 | if (access("/system/lib/libdra.so",F_OK)) { |
817 | enable = 0; |
818 | } |
819 | } |
820 | else if (format < ACODEC_FMT_MPEG || format > ACODEC_FMT_WMAVOI) { |
821 | adec_print("unsupported format %d\n",format); |
822 | enable = 0; |
823 | } |
824 | return enable; |
825 | } |
826 | int audio_decoder_set_trackrate(void* handle, void *rate) |
827 | { |
828 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
829 | audio_out_operations_t *aout_ops = NULL; |
830 | if (!audec) { |
831 | adec_print("audio handle is NULL !\n"); |
832 | return -1; |
833 | } |
834 | aout_ops = &audec->aout_ops; |
835 | if (aout_ops->set_track_rate) |
836 | return aout_ops->set_track_rate(audec,rate); |
837 | return 0; |
838 | } |
839 | |
840 | /** |
841 | * \brief set audio associate decode en/dis-able |
842 | * \param handle pointer to player private data |
843 | * \return 0 =success, -1 = error |
844 | */ |
845 | int audio_set_associate_enable(void* handle, unsigned int enable) |
846 | { |
847 | int ret = 0; |
848 | //enable it after dual-decoder code merged to android N |
849 | #if 0 |
850 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
851 | if (!handle) { |
852 | adec_print("audio handle is NULL !\n"); |
853 | ret = -1; |
854 | } else { |
855 | audec->associate_audio_enable = enable; |
856 | adec_print("[%s]-[associate_audio_enable:%d]\n", __FUNCTION__, audec->associate_audio_enable); |
857 | } |
858 | #endif |
859 | return ret; |
860 | } |
861 | |
862 | /** |
863 | * \brief send the audio-associate data to destination buffer |
864 | * \param handle pointer to player private data |
865 | * \param buf pointer of the destination buffer address |
866 | * \param size which means that the length of request size |
867 | * \return [0, size], the length that have writen to destination buffer. |
868 | * \return -1, handle or other error |
869 | */ |
870 | int audio_send_associate_data(void* handle, uint8_t *buf, size_t size) |
871 | { |
872 | #if 0 |
873 | int ret = 0; |
874 | aml_audio_dec_t *audec = (aml_audio_dec_t *)handle; |
875 | if (!handle) { |
876 | adec_print("audio handle is NULL !\n"); |
877 | ret = -1; |
878 | } else { |
879 | if ((audec->associate_dec_supported) && (audec->g_assoc_bst)) { |
880 | if (audec->associate_audio_enable == 1) { |
881 | ret = write_es_buffer(buf, audec->g_assoc_bst, size); |
882 | } |
883 | else { |
884 | adec_print("[%s]-[associate_audio_enable:%d]\n", __FUNCTION__, audec->associate_audio_enable); |
885 | ret = reset_buffer(audec->g_assoc_bst); |
886 | } |
887 | } |
888 | else { |
889 | adec_print("[%s]-[associate_dec_supported:%d]-[g_assoc_bst:%p]\n", |
890 | __FUNCTION__, audec->associate_dec_supported, audec->g_assoc_bst); |
891 | ret = -1; |
892 | } |
893 | } |
894 | |
895 | return ret; |
896 | #else |
897 | return size; |
898 | #endif |
899 | } |
900 |