blob: 872ba4ef7362d2951e6d70d7acf2ceaf73401adb
1 | /** |
2 | * @file codec_ctrl.c |
3 | * @brief Codec control lib functions |
4 | * @author Zhou Zhi <zhi.zhou@amlogic.com> |
5 | * @version 1.0.0 |
6 | * @date 2011-02-24 |
7 | */ |
8 | /* Copyright (C) 2007-2011, Amlogic Inc. |
9 | * All right reserved |
10 | * |
11 | */ |
12 | #include <stdio.h> |
13 | #include <stdio.h> |
14 | #include <string.h> |
15 | #include <sys/types.h> |
16 | #include <sys/stat.h> |
17 | #include <sys/poll.h> |
18 | #include <errno.h> |
19 | #include <sys/ioctl.h> |
20 | #include <fcntl.h> |
21 | #include <codec_error.h> |
22 | #include <codec_type.h> |
23 | #include <codec.h> |
24 | #include <audio_priv.h> |
25 | #include "codec_h_ctrl.h" |
26 | #include <adec-external-ctrl.h> |
27 | #include <Amvideoutils.h> |
28 | #include "codec_msg.h" |
29 | #include "../audio_ctl/audio_ctrl.h" |
30 | #include "amconfigutils.h" |
31 | |
32 | #define SUBTITLE_EVENT |
33 | #define TS_PACKET_SIZE 188 |
34 | #define DEMUX_PLAYER_SOURCE 1 |
35 | |
36 | /* --------------------------------------------------------------------------*/ |
37 | /** |
38 | * @brief codec_set_eos set eos flag |
39 | * |
40 | * @param[in] pcodec Pointer of codec parameter structure |
41 | * @param[in] source set 1 for eos flag |
42 | * |
43 | * @return 0 for success, or fail type if < 0 |
44 | */ |
45 | |
46 | int codec_set_eos(codec_para_t *pcodec, int is_eos) { |
47 | int r = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_EOS, is_eos); |
48 | //if (r < 0) { |
49 | // return system_error_to_codec_error(r); |
50 | //} |
51 | CODEC_PRINT("codec_set_eos is_eos =%d\n", is_eos); |
52 | return 0; |
53 | } |
54 | |
55 | /* --------------------------------------------------------------------------*/ |
56 | /** |
57 | * @brief codec_set_demux_source set ts demux source |
58 | * |
59 | * @param[in] pcodec Pointer of codec parameter structure |
60 | * @param[in] source set 1 for player |
61 | * |
62 | * @return 0 for success, or fail type if < 0 |
63 | */ |
64 | /* --------------------------------------------------------------------------*/ |
65 | static int codec_set_demux_source(codec_para_t *pcodec, int source) |
66 | { |
67 | int ret = 0; |
68 | |
69 | ret = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_DEMUX, (unsigned long)source); |
70 | if (ret < 0) { |
71 | return ret; |
72 | } |
73 | return ret; |
74 | } |
75 | |
76 | /* --------------------------------------------------------------------------*/ |
77 | /** |
78 | * @brief codec_change_buf_size Change buffer size of codec device |
79 | * |
80 | * @param[in] pcodec Pointer of codec parameter structure |
81 | * |
82 | * @return Success of fail error type |
83 | */ |
84 | /* --------------------------------------------------------------------------*/ |
85 | static int codec_change_buf_size(codec_para_t *pcodec) |
86 | { |
87 | int r; |
88 | if (pcodec->abuf_size > 0) { |
89 | r = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_AB_SIZE, pcodec->abuf_size); |
90 | if (r < 0) { |
91 | return system_error_to_codec_error(r); |
92 | } |
93 | } |
94 | if (pcodec->vbuf_size > 0) { |
95 | r = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_VB_SIZE, pcodec->vbuf_size); |
96 | if (r < 0) { |
97 | return system_error_to_codec_error(r); |
98 | } |
99 | } |
100 | return CODEC_ERROR_NONE; |
101 | } |
102 | /* --------------------------------------------------------------------------*/ |
103 | /** |
104 | * @brief set_video_format Set video format to codec device |
105 | * |
106 | * @param[in] pcodec Pointer of codec parameter structure |
107 | * |
108 | * @return 0 for success, or error type |
109 | */ |
110 | /* --------------------------------------------------------------------------*/ |
111 | static int set_video_format(codec_para_t *pcodec) |
112 | { |
113 | int format = pcodec->video_type; |
114 | int r; |
115 | |
116 | if (format < 0 || format > VFORMAT_MAX) { |
117 | return -CODEC_ERROR_VIDEO_TYPE_UNKNOW; |
118 | } |
119 | |
120 | r = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_VFORMAT, format); |
121 | if (pcodec->video_pid >= 0) { |
122 | r = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_VID, pcodec->video_pid); |
123 | if (r < 0) { |
124 | return system_error_to_codec_error(r); |
125 | } |
126 | } |
127 | if (r < 0) { |
128 | return system_error_to_codec_error(r); |
129 | } |
130 | return 0; |
131 | } |
132 | |
133 | /* --------------------------------------------------------------------------*/ |
134 | /** |
135 | * @brief set_video_codec_info Set video information(width, height...) to codec device |
136 | * |
137 | * @param[in] pcodec Pointer of codec parameter structure |
138 | * |
139 | * @return 0 for success, or error type |
140 | */ |
141 | /* --------------------------------------------------------------------------*/ |
142 | static int set_video_codec_info(codec_para_t *pcodec) |
143 | { |
144 | dec_sysinfo_t am_sysinfo = pcodec->am_sysinfo; |
145 | int r; |
146 | r = codec_h_control(pcodec->handle, AMSTREAM_IOC_SYSINFO, (unsigned long)&am_sysinfo); |
147 | if (r < 0) { |
148 | return system_error_to_codec_error(r); |
149 | } |
150 | return 0; |
151 | } |
152 | /* --------------------------------------------------------------------------*/ |
153 | /** |
154 | * @brief set_audio_format Set audio format to codec device |
155 | * |
156 | * @param[in] pcodec Pointer of codec parameter structure |
157 | * |
158 | * @return 0 for success, or error type |
159 | */ |
160 | /* --------------------------------------------------------------------------*/ |
161 | static int set_audio_format(codec_para_t *pcodec) |
162 | { |
163 | int format = pcodec->audio_type; |
164 | int r; |
165 | int codec_r; |
166 | |
167 | if (format < 0 || format > AFORMAT_MAX) { |
168 | return -CODEC_ERROR_AUDIO_TYPE_UNKNOW; |
169 | } |
170 | |
171 | r = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_AFORMAT, format); |
172 | if (r < 0) { |
173 | codec_r = system_error_to_codec_error(r); |
174 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
175 | return codec_r; |
176 | } |
177 | if (pcodec->audio_pid >= 0) { |
178 | r = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_AID, pcodec->audio_pid); |
179 | if (r < 0) { |
180 | codec_r = system_error_to_codec_error(r); |
181 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
182 | return codec_r; |
183 | } |
184 | } |
185 | if (pcodec->audio_samplerate > 0) { |
186 | r = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_SAMPLERATE, pcodec->audio_samplerate); |
187 | if (r < 0) { |
188 | codec_r = system_error_to_codec_error(r); |
189 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
190 | return codec_r; |
191 | } |
192 | } |
193 | if (pcodec->audio_channels > 0) { |
194 | r = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_ACHANNEL, pcodec->audio_channels); |
195 | if (r < 0) { |
196 | codec_r = system_error_to_codec_error(r); |
197 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
198 | return codec_r; |
199 | } |
200 | } |
201 | return 0; |
202 | } |
203 | |
204 | /* --------------------------------------------------------------------------*/ |
205 | /** |
206 | * @brief set_audio_info Set audio information to codec device |
207 | * |
208 | * @param[in] pcodec Pointer of codec parameter structure |
209 | * |
210 | * @return 0 for success, or error type |
211 | */ |
212 | /* --------------------------------------------------------------------------*/ |
213 | static int set_audio_info(codec_para_t *pcodec) |
214 | { |
215 | int r; |
216 | int codec_r; |
217 | audio_info_t *audio_info = &pcodec->audio_info; |
218 | CODEC_PRINT("set_audio_info\n"); |
219 | r = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET_PTR, AMSTREAM_SET_PTR_AUDIO_INFO, (unsigned long)audio_info); |
220 | if (r < 0) { |
221 | codec_r = system_error_to_codec_error(r); |
222 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
223 | return codec_r; |
224 | } |
225 | return 0; |
226 | } |
227 | |
228 | /* --------------------------------------------------------------------------*/ |
229 | /** |
230 | * @brief set_sub_format Set subtitle format to codec device |
231 | * |
232 | * @param[in] pcodec Pointer of codec parameter structure |
233 | * |
234 | * @return 0 for success, or error type |
235 | */ |
236 | /* --------------------------------------------------------------------------*/ |
237 | static int set_sub_format(codec_para_t *pcodec) |
238 | { |
239 | int r; |
240 | |
241 | if (pcodec->sub_pid >= 0) { |
242 | r = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_SID, pcodec->sub_pid); |
243 | if (r < 0) { |
244 | return system_error_to_codec_error(r); |
245 | } |
246 | |
247 | r = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_SUB_TYPE, pcodec->sub_type); |
248 | if (r < 0) { |
249 | return system_error_to_codec_error(r); |
250 | } |
251 | } |
252 | |
253 | return 0; |
254 | } |
255 | |
256 | /* --------------------------------------------------------------------------*/ |
257 | /** |
258 | * @brief set_ts_skip_byte Set the number of ts skip bytes, especially for m2ts file |
259 | * |
260 | * @param[in] pcodec Pointer of codec parameter structure |
261 | * |
262 | * @return 0 for success, or error type |
263 | */ |
264 | /* --------------------------------------------------------------------------*/ |
265 | static int set_ts_skip_byte(codec_para_t *pcodec) |
266 | { |
267 | int r, skip_byte; |
268 | |
269 | skip_byte = pcodec->packet_size - TS_PACKET_SIZE; |
270 | |
271 | if (skip_byte < 0) { |
272 | skip_byte = 0; |
273 | } |
274 | |
275 | r = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_TS_SKIPBYTE, skip_byte); |
276 | if (r < 0) { |
277 | return system_error_to_codec_error(r); |
278 | } |
279 | |
280 | return 0; |
281 | } |
282 | /* --------------------------------------------------------------------------*/ |
283 | /** |
284 | * @brief codec_check_new_cmd Check new cmd for ioctl |
285 | * |
286 | */ |
287 | /* --------------------------------------------------------------------------*/ |
288 | static inline void codec_check_new_cmd(CODEC_HANDLE handle) |
289 | { |
290 | if (!codec_h_is_support_new_cmd()) { |
291 | int r; |
292 | int version = 0; |
293 | r = codec_h_control(handle, AMSTREAM_IOC_GET_VERSION, (unsigned long)&version); |
294 | if ((r == 0) && (version >= 0x20000)) { |
295 | CODEC_PRINT("codec_init amstream version : %d.%d\n", (version & 0xffff0000) >> 16, version & 0xffff); |
296 | codec_h_set_support_new_cmd(1); |
297 | } else { |
298 | CODEC_PRINT("codec_init amstream use old cmd\n"); |
299 | codec_h_set_support_new_cmd(0); |
300 | } |
301 | |
302 | } |
303 | } |
304 | |
305 | /* --------------------------------------------------------------------------*/ |
306 | /** |
307 | * @brief codec_video_es_init Initialize the codec device for es video |
308 | * |
309 | * @param[in] pcodec Pointer of codec parameter structure |
310 | * |
311 | * @return Success or fail error type |
312 | */ |
313 | /* --------------------------------------------------------------------------*/ |
314 | static inline int codec_video_es_init(codec_para_t *pcodec) |
315 | { |
316 | CODEC_HANDLE handle; |
317 | int r; |
318 | int codec_r; |
319 | int flags = O_WRONLY; |
320 | if (!pcodec->has_video) { |
321 | return CODEC_ERROR_NONE; |
322 | } |
323 | |
324 | flags |= pcodec->noblock ? O_NONBLOCK : 0; |
325 | |
326 | if (pcodec->video_type == VFORMAT_HEVC || pcodec->video_type == VFORMAT_VP9) { |
327 | if (pcodec->dv_enable && pcodec->video_type == VFORMAT_HEVC) |
328 | handle = codec_h_open(CODEC_VIDEO_DVHEVC_DEVICE, flags); |
329 | else |
330 | handle = codec_h_open(CODEC_VIDEO_HEVC_DEVICE, flags); |
331 | } else { |
332 | if (pcodec->video_type == VFORMAT_H264 && pcodec->dv_enable) |
333 | handle = codec_h_open(CODEC_VIDEO_DVAVC_DEVICE, flags); |
334 | else |
335 | handle = codec_h_open(CODEC_VIDEO_ES_DEVICE, flags); |
336 | } |
337 | if (handle < 0) { |
338 | codec_r = system_error_to_codec_error(handle); |
339 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
340 | return CODEC_OPEN_HANDLE_FAILED; |
341 | } |
342 | pcodec->handle = handle; |
343 | |
344 | codec_check_new_cmd(handle); |
345 | |
346 | r = set_video_format(pcodec); |
347 | if (r < 0) { |
348 | codec_h_close(handle); |
349 | codec_r = system_error_to_codec_error(r); |
350 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
351 | return codec_r; |
352 | } |
353 | r = set_video_codec_info(pcodec); |
354 | if (r < 0) { |
355 | codec_h_close(handle); |
356 | codec_r = system_error_to_codec_error(r); |
357 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
358 | return codec_r; |
359 | } |
360 | r = codec_set_drmmode(pcodec, pcodec->drmmode); |
361 | if (r < 0) { |
362 | codec_h_close(handle); |
363 | codec_r = system_error_to_codec_error(r); |
364 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
365 | return codec_r; |
366 | } |
367 | return CODEC_ERROR_NONE; |
368 | } |
369 | |
370 | |
371 | /* --------------------------------------------------------------------------*/ |
372 | /** |
373 | * @brief codec_audio_es_init Initialize the codec device for es audio |
374 | * |
375 | * @param[in] pcodec Pointer of codec parameter structure |
376 | * |
377 | * @return Success or fail error type |
378 | */ |
379 | /* --------------------------------------------------------------------------*/ |
380 | static inline int codec_audio_es_init(codec_para_t *pcodec) |
381 | { |
382 | CODEC_HANDLE handle; |
383 | int r; |
384 | int flags = O_WRONLY; |
385 | int codec_r; |
386 | if (!pcodec->has_audio) { |
387 | return CODEC_ERROR_NONE; |
388 | } |
389 | |
390 | flags |= pcodec->noblock ? O_NONBLOCK : 0; |
391 | handle = codec_h_open(CODEC_AUDIO_ES_DEVICE, flags); |
392 | if (handle < 0) { |
393 | codec_r = system_error_to_codec_error(handle); |
394 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
395 | return CODEC_OPEN_HANDLE_FAILED; |
396 | } |
397 | pcodec->handle = handle; |
398 | |
399 | codec_check_new_cmd(handle); |
400 | |
401 | r = set_audio_format(pcodec); |
402 | if (r < 0) { |
403 | codec_h_close(handle); |
404 | codec_r = system_error_to_codec_error(r); |
405 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
406 | return codec_r; |
407 | } |
408 | |
409 | /*if ((pcodec->audio_type == AFORMAT_ADPCM) || (pcodec->audio_type == AFORMAT_WMAPRO) || (pcodec->audio_type == AFORMAT_WMA) || (pcodec->audio_type == AFORMAT_PCM_S16BE) |
410 | || (pcodec->audio_type == AFORMAT_PCM_S16LE) || (pcodec->audio_type == AFORMAT_PCM_U8)||(pcodec->audio_type == AFORMAT_AMR)) {*/ |
411 | if (IS_AUIDO_NEED_EXT_INFO(pcodec->audio_type)) { |
412 | r = set_audio_info(pcodec); |
413 | if (r < 0) { |
414 | codec_h_close(handle); |
415 | codec_r = system_error_to_codec_error(r); |
416 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
417 | return codec_r; |
418 | } |
419 | } |
420 | |
421 | return CODEC_ERROR_NONE; |
422 | } |
423 | |
424 | /* --------------------------------------------------------------------------*/ |
425 | /** |
426 | * @brief codec_sub_es_init Initialize the codec device for es subtitle |
427 | * |
428 | * @param[in] pcodec Pointer of codec parameter structure |
429 | * |
430 | * @return Success or fail error type |
431 | */ |
432 | /* --------------------------------------------------------------------------*/ |
433 | static inline int codec_sub_es_init(codec_para_t *pcodec) |
434 | { |
435 | #ifdef SUBTITLE_EVENT |
436 | int r, codec_r; |
437 | |
438 | if (pcodec->has_sub) { |
439 | r = codec_init_sub(pcodec); |
440 | if (r < 0) { |
441 | codec_r = system_error_to_codec_error(r); |
442 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
443 | return CODEC_OPEN_HANDLE_FAILED; |
444 | } |
445 | pcodec->handle = pcodec->sub_handle; |
446 | |
447 | pcodec->sub_pid = 0xffff; // for es, sub id is identified for es parser |
448 | r = set_sub_format(pcodec); |
449 | if (r < 0) { |
450 | codec_r = system_error_to_codec_error(r); |
451 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
452 | return codec_r; |
453 | } |
454 | |
455 | } |
456 | |
457 | #endif |
458 | |
459 | return CODEC_ERROR_NONE; |
460 | } |
461 | |
462 | /* --------------------------------------------------------------------------*/ |
463 | /** |
464 | * @brief codec_ps_init Initialize the codec device for PS |
465 | * |
466 | * @param[in] pcodec Pointer of codec parameter structure |
467 | * |
468 | * @return Success or fail error type |
469 | */ |
470 | /* --------------------------------------------------------------------------*/ |
471 | static inline int codec_ps_init(codec_para_t *pcodec) |
472 | { |
473 | CODEC_HANDLE handle; |
474 | int r; |
475 | int flags = O_WRONLY; |
476 | int codec_r; |
477 | if (!((pcodec->has_video && IS_VALID_PID(pcodec->video_pid)) || |
478 | (pcodec->has_audio && IS_VALID_PID(pcodec->audio_pid)))) { |
479 | return -CODEC_ERROR_PARAMETER; |
480 | } |
481 | |
482 | flags |= pcodec->noblock ? O_NONBLOCK : 0; |
483 | handle = codec_h_open(CODEC_PS_DEVICE, flags); |
484 | if (handle < 0) { |
485 | codec_r = system_error_to_codec_error(handle); |
486 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
487 | return CODEC_OPEN_HANDLE_FAILED; |
488 | } |
489 | pcodec->handle = handle; |
490 | |
491 | codec_check_new_cmd(handle); |
492 | |
493 | if (pcodec->has_video) { |
494 | r = set_video_format(pcodec); |
495 | if (r < 0) { |
496 | goto error1; |
497 | } |
498 | if ((pcodec->video_type == VFORMAT_H264) |
499 | || (pcodec->video_type == VFORMAT_VC1) |
500 | || (pcodec->video_type == VFORMAT_MPEG12)) { |
501 | r = set_video_codec_info(pcodec); |
502 | if (r < 0) { |
503 | /*codec_h_close(handle); |
504 | codec_r = system_error_to_codec_error(r); |
505 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
506 | return codec_r; */ |
507 | goto error1; |
508 | } |
509 | } |
510 | } |
511 | if (pcodec->has_audio) { |
512 | r = set_audio_format(pcodec); |
513 | if (r < 0) { |
514 | goto error1; |
515 | } |
516 | |
517 | /*if ((pcodec->audio_type == AFORMAT_ADPCM) || (pcodec->audio_type == AFORMAT_WMA) || (pcodec->audio_type == AFORMAT_WMAPRO) || (pcodec->audio_type == AFORMAT_PCM_S16BE) |
518 | || (pcodec->audio_type == AFORMAT_PCM_S16LE) || (pcodec->audio_type == AFORMAT_PCM_U8) |
519 | || (pcodec->audio_type == AFORMAT_PCM_BLURAY)||(pcodec->audio_type == AFORMAT_AMR)) {*/ |
520 | if (IS_AUIDO_NEED_EXT_INFO(pcodec->audio_type)) { |
521 | r = set_audio_info(pcodec); |
522 | if (r < 0) { |
523 | goto error1; |
524 | } |
525 | } |
526 | } |
527 | #ifdef SUBTITLE_EVENT |
528 | if (pcodec->has_sub) { |
529 | r = set_sub_format(pcodec); |
530 | if (r < 0) { |
531 | goto error1; |
532 | } |
533 | |
534 | r = codec_init_sub(pcodec); |
535 | if (r < 0) { |
536 | goto error1; |
537 | } |
538 | } |
539 | #endif |
540 | |
541 | return CODEC_ERROR_NONE; |
542 | error1: |
543 | codec_h_close(handle); |
544 | codec_r = system_error_to_codec_error(r); |
545 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
546 | return codec_r; |
547 | |
548 | } |
549 | |
550 | |
551 | /* --------------------------------------------------------------------------*/ |
552 | /** |
553 | * @brief codec_ts_init Initialize the codec device for TS |
554 | * |
555 | * @param[in] pcodec Pointer of codec parameter structure |
556 | * |
557 | * @return Success or fail error type |
558 | */ |
559 | /* --------------------------------------------------------------------------*/ |
560 | static inline int codec_ts_init(codec_para_t *pcodec) |
561 | { |
562 | CODEC_HANDLE handle; |
563 | int r; |
564 | int flags = O_WRONLY; |
565 | int codec_r; |
566 | if (!((pcodec->has_video && IS_VALID_PID(pcodec->video_pid)) || |
567 | (pcodec->has_audio && IS_VALID_PID(pcodec->audio_pid)))) { |
568 | return -CODEC_ERROR_PARAMETER; |
569 | } |
570 | |
571 | flags |= pcodec->noblock ? O_NONBLOCK : 0; |
572 | handle = codec_h_open(CODEC_TS_DEVICE, flags); |
573 | if (handle < 0) { |
574 | codec_r = system_error_to_codec_error(handle); |
575 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
576 | return CODEC_OPEN_HANDLE_FAILED; |
577 | } |
578 | pcodec->handle = handle; |
579 | |
580 | codec_check_new_cmd(handle); |
581 | |
582 | codec_set_demux_source(pcodec, DEMUX_PLAYER_SOURCE); |
583 | if (pcodec->has_video) { |
584 | r = set_video_format(pcodec); |
585 | if (r < 0) { |
586 | goto error1; |
587 | } |
588 | if ((pcodec->video_type == VFORMAT_H264) || (pcodec->video_type == VFORMAT_MPEG4) || (pcodec->video_type == VFORMAT_VC1) || (pcodec->video_type == VFORMAT_AVS) || (pcodec->video_type == VFORMAT_MPEG12)) { |
589 | r = set_video_codec_info(pcodec); |
590 | if (r < 0) { |
591 | codec_h_close(handle); |
592 | codec_r = system_error_to_codec_error(r); |
593 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
594 | return codec_r; |
595 | } |
596 | } |
597 | } |
598 | if (pcodec->has_audio) { |
599 | r = set_audio_format(pcodec); |
600 | if (r < 0) { |
601 | goto error1; |
602 | } |
603 | |
604 | /*if ((pcodec->audio_type == AFORMAT_ADPCM) || (pcodec->audio_type == AFORMAT_WMA) || (pcodec->audio_type == AFORMAT_WMAPRO) || (pcodec->audio_type == AFORMAT_PCM_S16BE) |
605 | || (pcodec->audio_type == AFORMAT_PCM_S16LE) || (pcodec->audio_type == AFORMAT_PCM_U8) |
606 | || (pcodec->audio_type == AFORMAT_PCM_BLURAY)||(pcodec->audio_type == AFORMAT_AMR))*/ |
607 | if (pcodec->audio_info.valid) { |
608 | r = set_audio_info(pcodec); |
609 | if (r < 0) { |
610 | goto error1; |
611 | } |
612 | } |
613 | } |
614 | |
615 | r = set_ts_skip_byte(pcodec); |
616 | if (r < 0) { |
617 | goto error1; |
618 | } |
619 | |
620 | #ifdef SUBTITLE_EVENT |
621 | if (pcodec->has_sub) { |
622 | r = set_sub_format(pcodec); |
623 | if (r < 0) { |
624 | goto error1; |
625 | } |
626 | |
627 | r = codec_init_sub(pcodec); |
628 | if (r < 0) { |
629 | goto error1; |
630 | } |
631 | } |
632 | #endif |
633 | return CODEC_ERROR_NONE; |
634 | error1: |
635 | codec_h_close(handle); |
636 | codec_r = system_error_to_codec_error(r); |
637 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
638 | return codec_r; |
639 | |
640 | } |
641 | |
642 | /* --------------------------------------------------------------------------*/ |
643 | /** |
644 | * @brief codec_rm_init Initialize the codec device for RM |
645 | * |
646 | * @param[in] pcodec Pointer of codec parameter structure |
647 | * |
648 | * @return Success or fail error type |
649 | */ |
650 | /* --------------------------------------------------------------------------*/ |
651 | static inline int codec_rm_init(codec_para_t *pcodec) |
652 | { |
653 | CODEC_HANDLE handle; |
654 | int r; |
655 | int flags = O_WRONLY; |
656 | int codec_r; |
657 | if (!((pcodec->has_video && IS_VALID_PID(pcodec->video_pid)) || |
658 | (pcodec->has_audio && IS_VALID_PID(pcodec->audio_pid)))) { |
659 | CODEC_PRINT("codec_rm_init failed! video=%d vpid=%d audio=%d apid=%d\n", pcodec->has_video, pcodec->video_pid, pcodec->has_audio, pcodec->audio_pid); |
660 | return -CODEC_ERROR_PARAMETER; |
661 | } |
662 | flags |= pcodec->noblock ? O_NONBLOCK : 0; |
663 | handle = codec_h_open(CODEC_RM_DEVICE, flags); |
664 | if (handle < 0) { |
665 | codec_r = system_error_to_codec_error(handle); |
666 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
667 | return CODEC_OPEN_HANDLE_FAILED; |
668 | } |
669 | |
670 | pcodec->handle = handle; |
671 | |
672 | codec_check_new_cmd(handle); |
673 | |
674 | if (pcodec->has_video) { |
675 | r = set_video_format(pcodec); |
676 | if (r < 0) { |
677 | goto error1; |
678 | } |
679 | |
680 | r = set_video_codec_info(pcodec); |
681 | if (r < 0) { |
682 | goto error1; |
683 | } |
684 | } |
685 | if (pcodec->has_audio) { |
686 | r = set_audio_format(pcodec); |
687 | if (r < 0) { |
688 | goto error1; |
689 | } |
690 | r = set_audio_info(pcodec); |
691 | if (r < 0) { |
692 | goto error1; |
693 | } |
694 | } |
695 | return CODEC_ERROR_NONE; |
696 | |
697 | error1: |
698 | codec_h_close(handle); |
699 | codec_r = system_error_to_codec_error(r); |
700 | print_error_msg(codec_r, errno, __FUNCTION__, __LINE__); |
701 | return codec_r; |
702 | } |
703 | |
704 | /* --------------------------------------------------------------------------*/ |
705 | /** |
706 | * @brief codec_init Initialize the codec device based on stream type |
707 | * |
708 | * @param[in] pcodec Pointer of codec parameter structure |
709 | * |
710 | * @return Success or fail error type |
711 | */ |
712 | /* --------------------------------------------------------------------------*/ |
713 | int codec_init(codec_para_t *pcodec) |
714 | { |
715 | int ret; |
716 | //if(pcodec->has_audio) |
717 | // audio_stop(); |
718 | pcodec->handle = -1; |
719 | pcodec->cntl_handle = -1; |
720 | pcodec->sub_handle = -1; |
721 | pcodec->audio_utils_handle = -1; |
722 | if (pcodec->audio_type == AFORMAT_MPEG1 || pcodec->audio_type == AFORMAT_MPEG2) { |
723 | pcodec->audio_type = AFORMAT_MPEG; |
724 | } |
725 | switch (pcodec->stream_type) { |
726 | case STREAM_TYPE_ES_VIDEO: |
727 | ret = codec_video_es_init(pcodec); |
728 | break; |
729 | case STREAM_TYPE_ES_AUDIO: |
730 | ret = codec_audio_es_init(pcodec); |
731 | break; |
732 | case STREAM_TYPE_ES_SUB: |
733 | ret = codec_sub_es_init(pcodec); |
734 | break; |
735 | case STREAM_TYPE_PS: |
736 | ret = codec_ps_init(pcodec); |
737 | break; |
738 | case STREAM_TYPE_TS: |
739 | ret = codec_ts_init(pcodec); |
740 | break; |
741 | case STREAM_TYPE_RM: |
742 | ret = codec_rm_init(pcodec); |
743 | break; |
744 | case STREAM_TYPE_UNKNOW: |
745 | default: |
746 | return -CODEC_ERROR_STREAM_TYPE_UNKNOW; |
747 | } |
748 | if (ret != 0) { |
749 | return ret; |
750 | } |
751 | |
752 | ret = codec_init_cntl(pcodec); |
753 | if (ret != CODEC_ERROR_NONE) { |
754 | return ret; |
755 | } |
756 | ret = codec_change_buf_size(pcodec); |
757 | if (ret != 0) { |
758 | return -CODEC_ERROR_SET_BUFSIZE_FAILED; |
759 | } |
760 | |
761 | ret = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_PORT_INIT, 0); |
762 | if (ret != 0) { |
763 | |
764 | return -CODEC_ERROR_INIT_FAILED; |
765 | } |
766 | if (pcodec->has_audio) { |
767 | arm_audio_info a_ainfo; |
768 | memset(&a_ainfo, 0, sizeof(arm_audio_info)); |
769 | a_ainfo.channels = pcodec->audio_channels; |
770 | a_ainfo.sample_rate = pcodec->audio_samplerate; |
771 | a_ainfo.format = pcodec->audio_type; |
772 | a_ainfo.handle = pcodec->handle; |
773 | a_ainfo.SessionID = pcodec->SessionID; |
774 | a_ainfo.dspdec_not_supported = pcodec->dspdec_not_supported; |
775 | a_ainfo.droppcm_flag = 0; |
776 | a_ainfo.bitrate = pcodec->audio_info.bitrate; |
777 | a_ainfo.block_align = pcodec->audio_info.block_align; |
778 | a_ainfo.codec_id = pcodec->audio_info.codec_id; |
779 | a_ainfo.automute = pcodec->automute_flag; |
780 | a_ainfo.has_video = pcodec->has_video; |
781 | if (IS_AUIDO_NEED_EXT_INFO(pcodec->audio_type)) { |
782 | if (pcodec->audio_type != AFORMAT_WMA && pcodec->audio_type != AFORMAT_WMAPRO && pcodec->audio_type != AFORMAT_WMAVOI) { |
783 | a_ainfo.extradata_size = pcodec->audio_info.extradata_size; |
784 | if (a_ainfo.extradata_size > 0 && a_ainfo.extradata_size <= AUDIO_EXTRA_DATA_SIZE) { |
785 | memcpy((char*)a_ainfo.extradata, pcodec->audio_info.extradata, a_ainfo.extradata_size); |
786 | } else { |
787 | a_ainfo.extradata_size = 0; |
788 | } |
789 | } else { |
790 | Asf_audio_info_t asfinfo = {0}; |
791 | asfinfo.bitrate = pcodec->audio_info.bitrate; |
792 | asfinfo.block_align = pcodec->audio_info.block_align; |
793 | asfinfo.channels = pcodec->audio_info.channels; |
794 | asfinfo.codec_id = pcodec->audio_info.codec_id; |
795 | asfinfo.sample_rate = pcodec->audio_info.sample_rate; |
796 | asfinfo.valid = pcodec->audio_info.valid; |
797 | if (pcodec->audio_info.extradata_size <= 512) { |
798 | memcpy(asfinfo.extradata, pcodec->audio_info.extradata, pcodec->audio_info.extradata_size); |
799 | asfinfo.extradata_size = pcodec->audio_info.extradata_size; |
800 | } |
801 | memcpy((char*)a_ainfo.extradata, &asfinfo, sizeof(Asf_audio_info_t)); |
802 | a_ainfo.extradata_size = sizeof(Asf_audio_info_t); |
803 | } |
804 | } |
805 | //DEBUG_TMP audio_start(&pcodec->adec_priv, &a_ainfo); |
806 | if (pcodec->avsync_threshold > 0) { |
807 | //DEBUG_TMP audio_set_avsync_threshold(pcodec->adec_priv, pcodec->avsync_threshold); |
808 | } |
809 | } |
810 | |
811 | return ret; |
812 | } |
813 | |
814 | void codec_audio_basic_init(void) |
815 | { |
816 | //DEBUG_TMP audio_basic_init(); |
817 | } |
818 | |
819 | /* --------------------------------------------------------------------------*/ |
820 | /** |
821 | * @brief codec_write Write data to codec device |
822 | * |
823 | * @param[in] pcodec Pointer of codec parameter structure |
824 | * @param[in] buffer Buffer for data to be written |
825 | * @param[in] len Length of the data to be written |
826 | * |
827 | * @return Length of the written data, or fail if < 0 |
828 | */ |
829 | /* --------------------------------------------------------------------------*/ |
830 | int codec_write(codec_para_t *pcodec, void *buffer, int len) |
831 | { |
832 | return codec_h_write(pcodec->handle, buffer, len); |
833 | } |
834 | |
835 | /* --------------------------------------------------------------------------*/ |
836 | /** |
837 | * @brief codec_read Read data from codec device |
838 | * |
839 | * @param[in] pcodec Pointer of codec parameter structure |
840 | * @param[out] buffer Buffer for data read from codec device |
841 | * @param[in] len Length of the data to be read |
842 | * |
843 | * @return Length of the read data, or fail if < 0 |
844 | */ |
845 | /* --------------------------------------------------------------------------*/ |
846 | int codec_read(codec_para_t *pcodec, void *buffer, int len) |
847 | { |
848 | return codec_h_read(pcodec->handle, buffer, len); |
849 | } |
850 | |
851 | /* --------------------------------------------------------------------------*/ |
852 | /** |
853 | * @brief codec_close Close codec device |
854 | * |
855 | * @param[in] pcodec Pointer of codec parameter structure |
856 | * |
857 | * @return 0 for success, or fail type if < 0 |
858 | */ |
859 | /* --------------------------------------------------------------------------*/ |
860 | int codec_close(codec_para_t *pcodec) |
861 | { |
862 | int res = 0; |
863 | if (pcodec->has_audio) { |
864 | //DEBUG_TMP audio_stop(&pcodec->adec_priv); |
865 | CODEC_PRINT("[%s]audio stop OK!\n", __FUNCTION__); |
866 | } |
867 | #ifdef SUBTITLE_EVENT |
868 | if (pcodec->has_sub && pcodec->sub_handle >= 0) { |
869 | res |= codec_close_sub_fd(pcodec->sub_handle); |
870 | } |
871 | #endif |
872 | |
873 | res |= codec_close_cntl(pcodec); |
874 | res |= codec_h_close(pcodec->handle); |
875 | return res; |
876 | } |
877 | |
878 | /* --------------------------------------------------------------------------*/ |
879 | /** |
880 | * @brief codec_close_audio Close audio decoder |
881 | * |
882 | * @param[in] pcodec Pointer of codec parameter structure |
883 | */ |
884 | /* --------------------------------------------------------------------------*/ |
885 | void codec_close_audio(codec_para_t *pcodec) |
886 | { |
887 | if (pcodec) { |
888 | pcodec->has_audio = 0; |
889 | //DEBUG_TMP audio_stop(&pcodec->adec_priv); |
890 | } |
891 | return; |
892 | } |
893 | |
894 | /* --------------------------------------------------------------------------*/ |
895 | /** |
896 | * @brief codec_close_audio Close audio decoder |
897 | * |
898 | * @param[in] pcodec Pointer of codec parameter structure |
899 | */ |
900 | /* --------------------------------------------------------------------------*/ |
901 | void codec_close_audio_async(codec_para_t *pcodec) |
902 | { |
903 | if (pcodec) { |
904 | //DEBUG_TMP audio_stop_async(&pcodec->adec_priv); |
905 | } |
906 | return; |
907 | } |
908 | |
909 | /* --------------------------------------------------------------------------*/ |
910 | /** |
911 | * @brief codec_resume_audio Resume audio decoder to work (etc, after pause) |
912 | * |
913 | * @param[in] pcodec Pointer of codec parameter structure |
914 | * @param[in] orig Original audio status (has audio or not) |
915 | */ |
916 | /* --------------------------------------------------------------------------*/ |
917 | void codec_resume_audio(codec_para_t *pcodec, unsigned int orig) |
918 | { |
919 | pcodec->has_audio = orig; |
920 | if (pcodec->has_audio) { |
921 | arm_audio_info a_ainfo; |
922 | memset(&a_ainfo, 0, sizeof(arm_audio_info)); |
923 | a_ainfo.channels = pcodec->audio_channels; |
924 | a_ainfo.sample_rate = pcodec->audio_samplerate; |
925 | a_ainfo.format = pcodec->audio_type; |
926 | a_ainfo.handle = pcodec->handle; |
927 | a_ainfo.dspdec_not_supported = pcodec->dspdec_not_supported; |
928 | a_ainfo.bitrate = pcodec->audio_info.bitrate; |
929 | a_ainfo.block_align = pcodec->audio_info.block_align; |
930 | a_ainfo.codec_id = pcodec->audio_info.codec_id; |
931 | a_ainfo.automute = pcodec->automute_flag; |
932 | a_ainfo.has_video = pcodec->has_video; |
933 | if (pcodec->switch_audio_flag) { |
934 | a_ainfo.droppcm_flag = pcodec->switch_audio_flag; |
935 | if (pcodec->stream_type == STREAM_TYPE_TS || pcodec->stream_type == STREAM_TYPE_PS) { |
936 | a_ainfo.droppcm_flag = 0; |
937 | } |
938 | pcodec->switch_audio_flag = 0; |
939 | } |
940 | if (IS_AUIDO_NEED_EXT_INFO(pcodec->audio_type)) { |
941 | if (pcodec->audio_type != AFORMAT_WMA && pcodec->audio_type != AFORMAT_WMAPRO && pcodec->audio_type != AFORMAT_WMAVOI) { |
942 | a_ainfo.extradata_size = pcodec->audio_info.extradata_size; |
943 | if (a_ainfo.extradata_size > 0 && a_ainfo.extradata_size <= AUDIO_EXTRA_DATA_SIZE) { |
944 | memcpy((char*)a_ainfo.extradata, pcodec->audio_info.extradata, a_ainfo.extradata_size); |
945 | } else { |
946 | a_ainfo.extradata_size = 0; |
947 | } |
948 | } else { |
949 | Asf_audio_info_t asfinfo = {0}; |
950 | asfinfo.bitrate = pcodec->audio_info.bitrate; |
951 | asfinfo.block_align = pcodec->audio_info.block_align; |
952 | asfinfo.channels = pcodec->audio_info.channels; |
953 | asfinfo.codec_id = pcodec->audio_info.codec_id; |
954 | asfinfo.sample_rate = pcodec->audio_info.sample_rate; |
955 | asfinfo.valid = pcodec->audio_info.valid; |
956 | if (pcodec->audio_info.extradata_size <= 512) { |
957 | memcpy(asfinfo.extradata, pcodec->audio_info.extradata, pcodec->audio_info.extradata_size); |
958 | asfinfo.extradata_size = pcodec->audio_info.extradata_size; |
959 | } |
960 | memcpy((char*)a_ainfo.extradata, &asfinfo, sizeof(Asf_audio_info_t)); |
961 | a_ainfo.extradata_size = sizeof(Asf_audio_info_t); |
962 | } |
963 | } |
964 | //DEBUG_TMP audio_start(&pcodec->adec_priv, &a_ainfo); |
965 | } |
966 | return; |
967 | } |
968 | |
969 | /* --------------------------------------------------------------------------*/ |
970 | /** |
971 | * @brief codec_checkin_pts Checkin pts to codec device |
972 | * |
973 | * @param[in] pcodec Pointer of codec parameter structure |
974 | * @param[in] pts Pts to be checked in |
975 | * |
976 | * @return 0 for success, or fail type |
977 | */ |
978 | /* --------------------------------------------------------------------------*/ |
979 | int codec_checkin_pts(codec_para_t *pcodec, unsigned long pts) |
980 | { |
981 | //CODEC_PRINT("[%s:%d]pts=%x(%d)\n",__FUNCTION__,__LINE__,pts,pts/90000); |
982 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_TSTAMP, pts); |
983 | } |
984 | |
985 | /* --------------------------------------------------------------------------*/ |
986 | /** |
987 | * @brief codec_get_vbuf_state Get the state of video buffer by codec device |
988 | * |
989 | * @param[in] p Pointer of codec parameter structure |
990 | * @param[out] buf Pointer of buffer status structure to get video buffer state |
991 | * |
992 | * @return Success or fail type |
993 | */ |
994 | /* --------------------------------------------------------------------------*/ |
995 | int codec_get_vbuf_state(codec_para_t *p, struct buf_status *buf) |
996 | { |
997 | int r; |
998 | if (codec_h_is_support_new_cmd()) { |
999 | struct buf_status status; |
1000 | r = codec_h_ioctl(p->handle, AMSTREAM_IOC_GET_EX, AMSTREAM_GET_EX_VB_STATUS, (unsigned long)&status); |
1001 | memcpy(buf, &status, sizeof(*buf)); |
1002 | } else { |
1003 | struct am_io_param am_io; |
1004 | r = codec_h_control(p->handle, AMSTREAM_IOC_VB_STATUS, (unsigned long)&am_io); |
1005 | memcpy(buf, &am_io.status, sizeof(*buf)); |
1006 | } |
1007 | return system_error_to_codec_error(r); |
1008 | } |
1009 | /* --------------------------------------------------------------------------*/ |
1010 | /** |
1011 | * @brief codec_get_abuf_state Get the state of audio buffer by codec device |
1012 | * |
1013 | * @param[in] p Pointer of codec parameter structure |
1014 | * @param[out] buf Pointer of buffer status structure to get audio buffer state |
1015 | * |
1016 | * @return Success or fail type |
1017 | */ |
1018 | /* --------------------------------------------------------------------------*/ |
1019 | int codec_get_abuf_state(codec_para_t *p, struct buf_status *buf) |
1020 | { |
1021 | int r; |
1022 | if (codec_h_is_support_new_cmd()) { |
1023 | struct buf_status status; |
1024 | r = codec_h_ioctl(p->handle, AMSTREAM_IOC_GET_EX, AMSTREAM_GET_EX_AB_STATUS, (unsigned long)&status); |
1025 | memcpy(buf, &status, sizeof(*buf)); |
1026 | } else { |
1027 | struct am_io_param am_io; |
1028 | r = codec_h_control(p->handle, AMSTREAM_IOC_AB_STATUS, (unsigned long)&am_io); |
1029 | memcpy(buf, &am_io.status, sizeof(*buf)); |
1030 | } |
1031 | return system_error_to_codec_error(r); |
1032 | } |
1033 | |
1034 | /* --------------------------------------------------------------------------*/ |
1035 | /** |
1036 | * @brief codec_get_vdec_state Get the state of video decoder by codec device |
1037 | * |
1038 | * @param[in] p Pointer of codec parameter structure |
1039 | * @param[out] vdec Pointer of video decoder status structure |
1040 | * |
1041 | * @return Success or fail type |
1042 | */ |
1043 | /* --------------------------------------------------------------------------*/ |
1044 | int codec_get_vdec_state(codec_para_t *p, struct vdec_status *vdec) |
1045 | { |
1046 | int r; |
1047 | if (codec_h_is_support_new_cmd()) { |
1048 | struct vdec_status vstatus; |
1049 | r = codec_h_ioctl(p->handle, AMSTREAM_IOC_GET_EX, AMSTREAM_GET_EX_VDECSTAT, (unsigned long)&vstatus); |
1050 | memcpy(vdec, &vstatus, sizeof(*vdec)); |
1051 | } else { |
1052 | struct am_io_param am_io; |
1053 | r = codec_h_control(p->handle, AMSTREAM_IOC_VDECSTAT, (unsigned long)&am_io); |
1054 | memcpy(vdec, &am_io.vstatus, sizeof(*vdec)); |
1055 | } |
1056 | if (r < 0) { |
1057 | CODEC_PRINT("[codec_get_vdec_state]error[%d]: %s\n", r, codec_error_msg(system_error_to_codec_error(r))); |
1058 | } |
1059 | return system_error_to_codec_error(r); |
1060 | } |
1061 | |
1062 | /* --------------------------------------------------------------------------*/ |
1063 | /** |
1064 | * @brief codec_get_adec_state Get the state of audio decoder by codec device |
1065 | * |
1066 | * @param[in] p Pointer of codec parameter structure |
1067 | * @param[out] adec Pointer of audio decoder status structure |
1068 | * |
1069 | * @return Success or fail type |
1070 | */ |
1071 | /* --------------------------------------------------------------------------*/ |
1072 | int codec_get_adec_state(codec_para_t *p, struct adec_status *adec) |
1073 | { |
1074 | //DEBUG_TMP if (get_audio_decoder() == AUDIO_ARM_DECODER) { |
1075 | //DEBUG_TMP return get_decoder_status(p->adec_priv, adec); |
1076 | //DEBUG_TMP } |
1077 | int r; |
1078 | if (codec_h_is_support_new_cmd()) { |
1079 | struct adec_status astatus; |
1080 | r = codec_h_ioctl(p->handle, AMSTREAM_IOC_GET_EX, AMSTREAM_GET_EX_ADECSTAT, (unsigned long)&astatus); |
1081 | if (r == 0) { |
1082 | memcpy(adec, &astatus, sizeof(*adec)); |
1083 | } |
1084 | } else { |
1085 | struct am_io_param am_io; |
1086 | r = codec_h_control(p->handle, AMSTREAM_IOC_ADECSTAT, (unsigned long)&am_io); |
1087 | if (r == 0) { |
1088 | memcpy(adec, &am_io.astatus, sizeof(*adec)); |
1089 | } |
1090 | |
1091 | } |
1092 | return system_error_to_codec_error(r); |
1093 | } |
1094 | |
1095 | /* --------------------------------------------------------------------------*/ |
1096 | /** |
1097 | * @brief video_pause Pause video playing by codec device |
1098 | * |
1099 | * @param[in] p Pointer of codec parameter structure |
1100 | * |
1101 | * @return 0 for success, or fail type if < 0 |
1102 | */ |
1103 | /* --------------------------------------------------------------------------*/ |
1104 | static int video_pause(codec_para_t *p) |
1105 | { |
1106 | CODEC_PRINT("video_pause!\n"); |
1107 | return codec_h_control(p->cntl_handle, AMSTREAM_IOC_VPAUSE, 1); |
1108 | } |
1109 | |
1110 | /* --------------------------------------------------------------------------*/ |
1111 | /** |
1112 | * @brief video_resume Resume video playing by codec device |
1113 | * |
1114 | * @param[in] p Pointer of codec parameter structure |
1115 | * |
1116 | * @return 0 for success, or fail type if < 0 |
1117 | */ |
1118 | /* --------------------------------------------------------------------------*/ |
1119 | static int video_resume(codec_para_t *p) |
1120 | { |
1121 | CODEC_PRINT("video_resume!\n"); |
1122 | return codec_h_control(p->cntl_handle, AMSTREAM_IOC_VPAUSE, 0); |
1123 | } |
1124 | |
1125 | /* --------------------------------------------------------------------------*/ |
1126 | /** |
1127 | * @brief codec_pause Pause all playing(A/V) by codec device |
1128 | * |
1129 | * @param[in] p Pointer of codec parameter structure |
1130 | * |
1131 | * @return Success or fail error type |
1132 | */ |
1133 | /* --------------------------------------------------------------------------*/ |
1134 | int codec_pause(codec_para_t *p) |
1135 | { |
1136 | int ret = CODEC_ERROR_NONE; |
1137 | if (p) { |
1138 | CODEC_PRINT("[codec_pause]p->has_audio=%d\n", p->has_audio); |
1139 | if (p->has_audio) { |
1140 | //DEBUG_TMP audio_pause(p->adec_priv); |
1141 | } |
1142 | if (p->has_video) { |
1143 | ret = video_pause(p); |
1144 | } |
1145 | } else { |
1146 | ret = CODEC_ERROR_PARAMETER; |
1147 | } |
1148 | return ret; |
1149 | } |
1150 | /* --------------------------------------------------------------------------*/ |
1151 | /** |
1152 | * @brief codec_resume Resume playing(A/V) by codec device |
1153 | * |
1154 | * @param[in] p Pointer of codec parameter structure |
1155 | * |
1156 | * @return Success or fail error type |
1157 | */ |
1158 | /* --------------------------------------------------------------------------*/ |
1159 | int codec_resume(codec_para_t *p) |
1160 | { |
1161 | int ret = CODEC_ERROR_NONE; |
1162 | if (p) { |
1163 | CODEC_PRINT("[codec_resume]p->has_audio=%d\n", p->has_audio); |
1164 | if (p->has_audio) { |
1165 | //DEBUG_TMP audio_resume(p->adec_priv); |
1166 | } |
1167 | if (p->has_video) { |
1168 | ret = video_resume(p); |
1169 | } |
1170 | } else { |
1171 | ret = CODEC_ERROR_PARAMETER; |
1172 | } |
1173 | return ret; |
1174 | } |
1175 | |
1176 | /* --------------------------------------------------------------------------*/ |
1177 | /** |
1178 | * @brief codec_reset Reset codec device |
1179 | * |
1180 | * @param[in] p Pointer of codec parameter structure |
1181 | * |
1182 | * @return Success or fail error type |
1183 | */ |
1184 | /* --------------------------------------------------------------------------*/ |
1185 | int codec_reset(codec_para_t *p) |
1186 | { |
1187 | int ret; |
1188 | ret = codec_close(p); |
1189 | if (ret != 0) { |
1190 | return ret; |
1191 | } |
1192 | ret = codec_init(p); |
1193 | CODEC_PRINT("[%s:%d]ret=%x\n", __FUNCTION__, __LINE__, ret); |
1194 | return system_error_to_codec_error(ret); |
1195 | } |
1196 | |
1197 | /* --------------------------------------------------------------------------*/ |
1198 | /** |
1199 | * @brief codec_init_sub Initialize subtile codec device |
1200 | * |
1201 | * @param[in] pcodec Pointer of codec parameter structure |
1202 | * |
1203 | * @return Success or fail error type |
1204 | */ |
1205 | /* --------------------------------------------------------------------------*/ |
1206 | int codec_init_sub(codec_para_t *pcodec) |
1207 | { |
1208 | CODEC_HANDLE sub_handle; |
1209 | int flags = O_WRONLY; |
1210 | flags |= pcodec->noblock ? O_NONBLOCK : 0; |
1211 | sub_handle = codec_h_open(CODEC_SUB_DEVICE, flags); |
1212 | if (sub_handle < 0) { |
1213 | CODEC_PRINT("get %s failed\n", CODEC_SUB_DEVICE); |
1214 | return system_error_to_codec_error(sub_handle); |
1215 | } |
1216 | |
1217 | pcodec->sub_handle = sub_handle; |
1218 | return CODEC_ERROR_NONE; |
1219 | } |
1220 | |
1221 | /* --------------------------------------------------------------------------*/ |
1222 | /** |
1223 | * @brief codec_open_sub_read Open read_subtitle device which is special for read subtile data |
1224 | * |
1225 | * @return Device handler, or error type if < 0 |
1226 | */ |
1227 | /* --------------------------------------------------------------------------*/ |
1228 | int codec_open_sub_read(void) |
1229 | { |
1230 | CODEC_HANDLE sub_handle; |
1231 | |
1232 | sub_handle = codec_h_open_rd(CODEC_SUB_READ_DEVICE); |
1233 | if (sub_handle < 0) { |
1234 | CODEC_PRINT("get %s failed\n", CODEC_SUB_READ_DEVICE); |
1235 | return system_error_to_codec_error(sub_handle); |
1236 | } |
1237 | |
1238 | return sub_handle; |
1239 | } |
1240 | |
1241 | /* --------------------------------------------------------------------------*/ |
1242 | /** |
1243 | * @brief codec_close_sub Close subtile device |
1244 | * |
1245 | * @param[in] pcodec Pointer of codec parameter structure |
1246 | * |
1247 | * @return Success or fail error type |
1248 | */ |
1249 | /* --------------------------------------------------------------------------*/ |
1250 | int codec_close_sub(codec_para_t *pcodec) |
1251 | { |
1252 | int res = CODEC_ERROR_NONE; |
1253 | |
1254 | if (pcodec) { |
1255 | if (pcodec->sub_handle) { |
1256 | res = codec_h_close(pcodec->sub_handle); |
1257 | } |
1258 | } |
1259 | return res; |
1260 | } |
1261 | |
1262 | /* --------------------------------------------------------------------------*/ |
1263 | /** |
1264 | * @brief codec_close_sub_fd Close subtile device by fd |
1265 | * |
1266 | * @param[in] sub_fd subtile device fd |
1267 | * |
1268 | * @return 0 for success, or fail type if < 0 |
1269 | */ |
1270 | /* --------------------------------------------------------------------------*/ |
1271 | int codec_close_sub_fd(CODEC_HANDLE sub_fd) |
1272 | { |
1273 | int res = CODEC_ERROR_NONE; |
1274 | |
1275 | if (sub_fd) { |
1276 | res = codec_h_close(sub_fd); |
1277 | } |
1278 | return res; |
1279 | } |
1280 | |
1281 | /* --------------------------------------------------------------------------*/ |
1282 | /** |
1283 | * @brief codec_poll_sub Polling subtile device if subtitle data is ready |
1284 | * |
1285 | * @param[in] pcodec Pointer of codec parameter structure |
1286 | * |
1287 | * @return Polling result |
1288 | */ |
1289 | /* --------------------------------------------------------------------------*/ |
1290 | int codec_poll_sub(codec_para_t *pcodec) |
1291 | { |
1292 | struct pollfd sub_poll_fd[1]; |
1293 | |
1294 | if (pcodec->sub_handle == 0) { |
1295 | return 0; |
1296 | } |
1297 | |
1298 | sub_poll_fd[0].fd = pcodec->sub_handle; |
1299 | sub_poll_fd[0].events = POLLOUT; |
1300 | |
1301 | return poll(sub_poll_fd, 1, 10); |
1302 | } |
1303 | |
1304 | /* --------------------------------------------------------------------------*/ |
1305 | /** |
1306 | * @brief codec_poll_sub_fd Polling subtile device if subtitle data is ready by fd |
1307 | * |
1308 | * @param[in] sub_fd Subtitle device fd |
1309 | * @param[in] timeout Timeout for polling |
1310 | * |
1311 | * @return Polling result |
1312 | */ |
1313 | /* --------------------------------------------------------------------------*/ |
1314 | int codec_poll_sub_fd(CODEC_HANDLE sub_fd, int timeout) |
1315 | { |
1316 | struct pollfd sub_poll_fd[1]; |
1317 | |
1318 | if (sub_fd <= 0) { |
1319 | return 0; |
1320 | } |
1321 | |
1322 | sub_poll_fd[0].fd = sub_fd; |
1323 | sub_poll_fd[0].events = POLLOUT; |
1324 | |
1325 | return poll(sub_poll_fd, 1, timeout); |
1326 | } |
1327 | |
1328 | /* --------------------------------------------------------------------------*/ |
1329 | /** |
1330 | * @brief codec_get_sub_size Get the size of subtitle data which is ready |
1331 | * |
1332 | * @param[in] pcodec Pointer of codec parameter structure |
1333 | * |
1334 | * @return Subtile ready data size, or fail error type if < 0 |
1335 | */ |
1336 | /* --------------------------------------------------------------------------*/ |
1337 | int codec_get_sub_size(codec_para_t *pcodec) |
1338 | { |
1339 | int sub_size, r; |
1340 | |
1341 | if (pcodec->sub_handle == 0) { |
1342 | CODEC_PRINT("no control handler\n"); |
1343 | return 0; |
1344 | } |
1345 | |
1346 | r = codec_h_ioctl(pcodec->sub_handle, AMSTREAM_IOC_GET, AMSTREAM_GET_SUB_LENGTH, (unsigned long)&sub_size); |
1347 | if (r < 0) { |
1348 | return system_error_to_codec_error(r); |
1349 | } else { |
1350 | return sub_size; |
1351 | } |
1352 | } |
1353 | |
1354 | /* --------------------------------------------------------------------------*/ |
1355 | /** |
1356 | * @brief codec_get_sub_size_fd Get the size of subtitle data which is ready by fd |
1357 | * |
1358 | * @param[in] sub_fd Subtitle device fd |
1359 | * |
1360 | * @return Subtile ready data size, or fail error type if < 0 |
1361 | */ |
1362 | /* --------------------------------------------------------------------------*/ |
1363 | int codec_get_sub_size_fd(CODEC_HANDLE sub_fd) |
1364 | { |
1365 | int sub_size, r; |
1366 | |
1367 | if (sub_fd <= 0) { |
1368 | CODEC_PRINT("no sub handler\n"); |
1369 | return 0; |
1370 | } |
1371 | |
1372 | r = codec_h_ioctl(sub_fd, AMSTREAM_IOC_GET, AMSTREAM_GET_SUB_LENGTH, (unsigned long)&sub_size); |
1373 | if (r < 0) { |
1374 | return system_error_to_codec_error(r); |
1375 | } else { |
1376 | return sub_size; |
1377 | } |
1378 | } |
1379 | |
1380 | /* --------------------------------------------------------------------------*/ |
1381 | /** |
1382 | * @brief codec_read_sub_data Read subtitle data from codec device |
1383 | * |
1384 | * @param[in] pcodec Pointer of codec parameter structure |
1385 | * @param[out] buf Buffer for data read from subtitle codec device |
1386 | * @param[in] length Data length to be read from subtitle codec device |
1387 | * |
1388 | * @return 0 for success, or fail type if < 0 |
1389 | */ |
1390 | /* --------------------------------------------------------------------------*/ |
1391 | int codec_read_sub_data(codec_para_t *pcodec, char *buf, unsigned int length) |
1392 | { |
1393 | int data_size = length, r, read_done = 0; |
1394 | |
1395 | if (pcodec->sub_handle == 0) { |
1396 | CODEC_PRINT("no control handler\n"); |
1397 | return 0; |
1398 | } |
1399 | |
1400 | while (data_size) { |
1401 | r = codec_h_read(pcodec->sub_handle, buf + read_done, data_size); |
1402 | if (r < 0) { |
1403 | return system_error_to_codec_error(r); |
1404 | } else { |
1405 | data_size -= r; |
1406 | read_done += r; |
1407 | } |
1408 | } |
1409 | |
1410 | return 0; |
1411 | } |
1412 | |
1413 | /* --------------------------------------------------------------------------*/ |
1414 | /** |
1415 | * @brief codec_read_sub_data_fd Read subtitle data from codec device by fd |
1416 | * |
1417 | * @param[in] sub_fd Subtitle device fd |
1418 | * @param[out] buf Buffer for data read from subtitle codec device |
1419 | * @param[in] length Data length to be read from subtile codec device |
1420 | * |
1421 | * @return 0 for success, or fail type if < 0 |
1422 | */ |
1423 | /* --------------------------------------------------------------------------*/ |
1424 | int codec_read_sub_data_fd(CODEC_HANDLE sub_fd, char *buf, unsigned int length) |
1425 | { |
1426 | int data_size = length, r, read_done = 0; |
1427 | |
1428 | if (sub_fd <= 0) { |
1429 | CODEC_PRINT("no sub handler\n"); |
1430 | return 0; |
1431 | } |
1432 | |
1433 | while (data_size) { |
1434 | r = codec_h_read(sub_fd, buf + read_done, data_size); |
1435 | if (r < 0) { |
1436 | return system_error_to_codec_error(r); |
1437 | } else { |
1438 | data_size -= r; |
1439 | read_done += r; |
1440 | } |
1441 | } |
1442 | |
1443 | return 0; |
1444 | } |
1445 | |
1446 | /* --------------------------------------------------------------------------*/ |
1447 | /** |
1448 | * @brief codec_write_sub_data Write subtile data to subtitle device |
1449 | * |
1450 | * @param[in] pcodec Pointer of codec parameter structure |
1451 | * @param[in] buf Buffer for data to be written |
1452 | * @param[in] length Length of the dat to be written |
1453 | * |
1454 | * @return Write length, or fail type if < 0 |
1455 | */ |
1456 | /* --------------------------------------------------------------------------*/ |
1457 | int codec_write_sub_data(codec_para_t *pcodec, char *buf, unsigned int length) |
1458 | { |
1459 | if (pcodec->sub_handle == 0) { |
1460 | CODEC_PRINT("no control handler\n"); |
1461 | return 0; |
1462 | } |
1463 | |
1464 | return codec_h_write(pcodec->sub_handle, buf, length); |
1465 | } |
1466 | |
1467 | /* --------------------------------------------------------------------------*/ |
1468 | /** |
1469 | * @brief codec_init_cntl Initialize the video control device |
1470 | * |
1471 | * @param[in] pcodec Pointer of codec parameter structure |
1472 | * |
1473 | * @return Success or fail error type |
1474 | */ |
1475 | /* --------------------------------------------------------------------------*/ |
1476 | int codec_init_cntl(codec_para_t *pcodec) |
1477 | { |
1478 | CODEC_HANDLE cntl; |
1479 | |
1480 | |
1481 | cntl = codec_h_open(CODEC_CNTL_DEVICE, O_RDWR); |
1482 | if (cntl < 0) { |
1483 | CODEC_PRINT("get %s failed\n", CODEC_CNTL_DEVICE); |
1484 | return system_error_to_codec_error(cntl); |
1485 | } |
1486 | |
1487 | pcodec->cntl_handle = cntl; |
1488 | |
1489 | return CODEC_ERROR_NONE; |
1490 | } |
1491 | |
1492 | /* --------------------------------------------------------------------------*/ |
1493 | /** |
1494 | * @brief codec_close_cntl Close video control device |
1495 | * |
1496 | * @param[in] pcodec Pointer of codec parameter structure |
1497 | * |
1498 | * @return Success or fail error type |
1499 | */ |
1500 | /* --------------------------------------------------------------------------*/ |
1501 | int codec_close_cntl(codec_para_t *pcodec) |
1502 | { |
1503 | int res = CODEC_ERROR_NONE; |
1504 | |
1505 | if (pcodec) { |
1506 | if (pcodec->cntl_handle) { |
1507 | res = codec_h_close(pcodec->cntl_handle); |
1508 | } |
1509 | } |
1510 | return res; |
1511 | } |
1512 | |
1513 | /* --------------------------------------------------------------------------*/ |
1514 | /** |
1515 | * @brief codec_poll_cntl Polling video control device |
1516 | * |
1517 | * @param[in] pcodec Pointer of codec parameter structure |
1518 | * |
1519 | * @return Polling results |
1520 | */ |
1521 | /* --------------------------------------------------------------------------*/ |
1522 | int codec_poll_cntl(codec_para_t *pcodec) |
1523 | { |
1524 | struct pollfd codec_poll_fd[1]; |
1525 | |
1526 | if (pcodec->cntl_handle == 0) { |
1527 | return 0; |
1528 | } |
1529 | |
1530 | codec_poll_fd[0].fd = pcodec->cntl_handle; |
1531 | codec_poll_fd[0].events = POLLOUT; |
1532 | |
1533 | return poll(codec_poll_fd, 1, 10); |
1534 | } |
1535 | |
1536 | /* --------------------------------------------------------------------------*/ |
1537 | /** |
1538 | * @brief codec_get_cntl_state Get the status of video control device, especially for trickmode |
1539 | * |
1540 | * @param[in] pcodec Pointer of codec parameter structure |
1541 | * |
1542 | * @return Video control device status or fail error type |
1543 | */ |
1544 | /* --------------------------------------------------------------------------*/ |
1545 | int codec_get_cntl_state(codec_para_t *pcodec) |
1546 | { |
1547 | int cntl_state, r; |
1548 | |
1549 | if (pcodec->cntl_handle == 0) { |
1550 | CODEC_PRINT("no control handler\n"); |
1551 | return 0; |
1552 | } |
1553 | |
1554 | r = codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_TRICK_STAT, (unsigned long)&cntl_state); |
1555 | if (r < 0) { |
1556 | return system_error_to_codec_error(r); |
1557 | } else { |
1558 | return cntl_state; |
1559 | } |
1560 | } |
1561 | |
1562 | /* --------------------------------------------------------------------------*/ |
1563 | /** |
1564 | * @brief codec_set_cntl_mode Set the mode to video control device, especially for trickmode |
1565 | * |
1566 | * @param[in] pcodec Pointer of codec parameter structure |
1567 | * @param[in] mode Trick mode to be set |
1568 | * |
1569 | * @return 0 for success, or fail type if < 0 |
1570 | */ |
1571 | /* --------------------------------------------------------------------------*/ |
1572 | int codec_set_cntl_mode(codec_para_t *pcodec, unsigned int mode) |
1573 | { |
1574 | return codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_TRICKMODE, (unsigned long)mode); |
1575 | } |
1576 | |
1577 | int codec_set_mode(codec_para_t *pcodec, unsigned int mode) |
1578 | { |
1579 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_TRICKMODE, (unsigned long)mode); |
1580 | } |
1581 | /* --------------------------------------------------------------------------*/ |
1582 | /** |
1583 | * @brief codec_set_cntl_avthresh Set the AV sync threshold which defines the max time difference between A/V |
1584 | * |
1585 | * @param[in] pcodec Pointer of codec parameter structure |
1586 | * @param[in] avthresh Threshold to be set |
1587 | * |
1588 | * @return 0 for success, or fail type if < 0 |
1589 | */ |
1590 | /* --------------------------------------------------------------------------*/ |
1591 | int codec_set_cntl_avthresh(codec_para_t *pcodec, unsigned int avthresh) |
1592 | { |
1593 | return codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_AVTHRESH, (unsigned long)avthresh); |
1594 | } |
1595 | |
1596 | /* --------------------------------------------------------------------------*/ |
1597 | /** |
1598 | * @brief codec_set_cntl_syncthresh Set sync threshold control which defines the starting system time (hold video or not) |
1599 | * when playing |
1600 | * |
1601 | * @param[in] pcodec Pointer of codec parameter structure |
1602 | * @param[in] syncthresh Sync threshold control |
1603 | * |
1604 | * @return 0 for success, or fail type if < 0 |
1605 | */ |
1606 | /* --------------------------------------------------------------------------*/ |
1607 | int codec_set_cntl_syncthresh(codec_para_t *pcodec, unsigned int syncthresh) |
1608 | { |
1609 | return codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_SYNCTHRESH, (unsigned long)syncthresh); |
1610 | } |
1611 | |
1612 | /* --------------------------------------------------------------------------*/ |
1613 | /** |
1614 | * @brief codec_reset_audio Reset audio decoder, especially for audio switch |
1615 | * |
1616 | * @param[in] pcodec Pointer of codec parameter structure |
1617 | * |
1618 | * @return 0 for success, or fail type if < 0 |
1619 | */ |
1620 | /* --------------------------------------------------------------------------*/ |
1621 | int codec_reset_audio(codec_para_t *pcodec) |
1622 | { |
1623 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_AUDIO_RESET, 0); |
1624 | } |
1625 | |
1626 | /* --------------------------------------------------------------------------*/ |
1627 | /** |
1628 | * @brief codec_reset_subtile Reset subtitle device, especially for subtitle swith |
1629 | * |
1630 | * @param[in] pcodec Pointer of codec parameter structure |
1631 | * |
1632 | * @return 0 for success, or fail type if < 0 |
1633 | */ |
1634 | /* --------------------------------------------------------------------------*/ |
1635 | int codec_reset_subtile(codec_para_t *pcodec) |
1636 | { |
1637 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SUB_RESET, 0); |
1638 | } |
1639 | |
1640 | /* --------------------------------------------------------------------------*/ |
1641 | /** |
1642 | * @brief codec_set_audio_id Set audio pid by codec device |
1643 | * |
1644 | * @param[in] pcodec Pointer of codec parameter structure |
1645 | * |
1646 | * @return 0 for success, or fail type if < 0 |
1647 | */ |
1648 | /* --------------------------------------------------------------------------*/ |
1649 | int codec_set_audio_pid(codec_para_t *pcodec) |
1650 | { |
1651 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_AID, pcodec->audio_pid); |
1652 | } |
1653 | |
1654 | /* --------------------------------------------------------------------------*/ |
1655 | /** |
1656 | * @brief codec_set_sub_id Set subtitle pid by codec device |
1657 | * |
1658 | * @param[in] pcodec Pointer of codec parameter structure |
1659 | * |
1660 | * @return 0 for success, or fail type if < 0 |
1661 | */ |
1662 | /* --------------------------------------------------------------------------*/ |
1663 | int codec_set_sub_id(codec_para_t *pcodec) |
1664 | { |
1665 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_SID, pcodec->sub_pid); |
1666 | } |
1667 | |
1668 | /* --------------------------------------------------------------------------*/ |
1669 | /** |
1670 | * @brief codec_set_sub_type Set subtitle type by codec device |
1671 | * |
1672 | * @param[in] pcodec Pointer of codec parameter structure |
1673 | * |
1674 | * @return 0 for success, or fail type if < 0 |
1675 | */ |
1676 | /* --------------------------------------------------------------------------*/ |
1677 | int codec_set_sub_type(codec_para_t *pcodec) |
1678 | { |
1679 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_SUB_TYPE, pcodec->sub_type); |
1680 | } |
1681 | |
1682 | /* --------------------------------------------------------------------------*/ |
1683 | /** |
1684 | * @brief codec_audio_reinit Re-initialize audio codec |
1685 | * |
1686 | * @param[in] pcodec Pointer of codec parameter structure |
1687 | * |
1688 | * @return 0 for success, or fail type if < 0 |
1689 | */ |
1690 | /* --------------------------------------------------------------------------*/ |
1691 | int codec_audio_reinit(codec_para_t *pcodec) |
1692 | { |
1693 | int ret; |
1694 | ret = set_audio_format(pcodec); |
1695 | if (!ret && pcodec->audio_info.valid) { |
1696 | ret = set_audio_info(pcodec); |
1697 | } |
1698 | return ret; |
1699 | } |
1700 | |
1701 | /* --------------------------------------------------------------------------*/ |
1702 | /** |
1703 | * @brief codec_set_dec_reset Set decoder reset flag when reset |
1704 | * |
1705 | * @param[in] pcodec Pointer of codec parameter structure |
1706 | * |
1707 | * @return 0 for success, or fail type if < 0 |
1708 | */ |
1709 | /* --------------------------------------------------------------------------*/ |
1710 | int codec_set_dec_reset(codec_para_t *pcodec) |
1711 | { |
1712 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_DEC_RESET, 0); |
1713 | } |
1714 | |
1715 | /* --------------------------------------------------------------------------*/ |
1716 | /** |
1717 | * @brief codec_audio_isready check audio finish init ok |
1718 | * |
1719 | * @param[in] pcodec Pointer of codec parameter structure |
1720 | * |
1721 | * @return 1 for ready, or not ready if = 0 |
1722 | */ |
1723 | /* --------------------------------------------------------------------------*/ |
1724 | int codec_audio_isready(codec_para_t *p) |
1725 | { |
1726 | int audio_isready = 1; |
1727 | if (!p) { |
1728 | CODEC_PRINT("[%s]ERROR invalid pointer!\n", __FUNCTION__); |
1729 | return -1; |
1730 | } |
1731 | if (p->has_audio) { |
1732 | //DEBUG_TMP audio_isready = audio_dec_ready(p->adec_priv); |
1733 | } |
1734 | |
1735 | return audio_isready; |
1736 | } |
1737 | |
1738 | /* --------------------------------------------------------------------------*/ |
1739 | /** |
1740 | * @brief codec_audio_get_nb_frames get audiodsp decoded frame number |
1741 | * |
1742 | * @param[in] pcodec Pointer of codec parameter structure |
1743 | * |
1744 | * @return n decoded frames number, or return 0 |
1745 | */ |
1746 | /* --------------------------------------------------------------------------*/ |
1747 | int codec_audio_get_nb_frames(codec_para_t *p) |
1748 | { |
1749 | int audio_nb_frames = -1; |
1750 | if (!p) { |
1751 | CODEC_PRINT("[%s]ERROR invalid pointer!\n", __FUNCTION__); |
1752 | return -1; |
1753 | } |
1754 | |
1755 | if (p->has_audio) { |
1756 | //DEBUG_TMP audio_nb_frames = audio_get_decoded_nb_frames(p->adec_priv); |
1757 | } |
1758 | //CODEC_PRINT("[%s]get audio decoded frame number[%d]!\n", __FUNCTION__, audio_nb_frames); |
1759 | return audio_nb_frames; |
1760 | } |
1761 | |
1762 | /* --------------------------------------------------------------------------*/ |
1763 | /** |
1764 | * @brief codec_get_apts get audio pts |
1765 | * |
1766 | * @param[in] pcodec Pointer of codec parameter structure |
1767 | * |
1768 | * @return audio pts, or -1 if it failed |
1769 | */ |
1770 | /* --------------------------------------------------------------------------*/ |
1771 | int codec_get_apts(codec_para_t *pcodec) |
1772 | { |
1773 | unsigned int apts; |
1774 | int ret; |
1775 | |
1776 | if (!pcodec) { |
1777 | CODEC_PRINT("[%s]ERROR invalid pointer!\n", __FUNCTION__); |
1778 | return -1; |
1779 | } |
1780 | |
1781 | ret = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_GET, AMSTREAM_GET_APTS, (unsigned long)&apts); |
1782 | if (ret < 0) { |
1783 | CODEC_PRINT("[%s]ioctl failed %d\n", __FUNCTION__, ret); |
1784 | return -1; |
1785 | } |
1786 | |
1787 | return apts; |
1788 | } |
1789 | |
1790 | /* --------------------------------------------------------------------------*/ |
1791 | /** |
1792 | * @brief codec_get_vpts get video pts |
1793 | * |
1794 | * @param[in] pcodec Pointer of codec parameter structure |
1795 | * |
1796 | * @return video pts, or -1 if it failed |
1797 | */ |
1798 | /* --------------------------------------------------------------------------*/ |
1799 | int codec_get_vpts(codec_para_t *pcodec) |
1800 | { |
1801 | unsigned int vpts; |
1802 | int ret; |
1803 | |
1804 | if (!pcodec) { |
1805 | CODEC_PRINT("[%s]ERROR invalid pointer!\n", __FUNCTION__); |
1806 | return -1; |
1807 | } |
1808 | |
1809 | ret = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_GET, AMSTREAM_GET_VPTS, (unsigned long)&vpts); |
1810 | if (ret < 0) { |
1811 | CODEC_PRINT("[%s]ioctl failed %d\n", __FUNCTION__, ret); |
1812 | return -1; |
1813 | } |
1814 | |
1815 | return vpts; |
1816 | } |
1817 | |
1818 | /* --------------------------------------------------------------------------*/ |
1819 | /** |
1820 | * @brief codec_get_pcrscr get system pcrscr |
1821 | * |
1822 | * @param[in] pcodec Pointer of codec parameter structure |
1823 | * |
1824 | * @return system pcrscr, or -1 it failed |
1825 | */ |
1826 | /* --------------------------------------------------------------------------*/ |
1827 | int codec_get_pcrscr(codec_para_t *pcodec) |
1828 | { |
1829 | unsigned int pcrscr; |
1830 | int ret; |
1831 | |
1832 | if (!pcodec) { |
1833 | CODEC_PRINT("[%s]ERROR invalid pointer!\n", __FUNCTION__); |
1834 | return -1; |
1835 | } |
1836 | |
1837 | ret = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_GET, AMSTREAM_GET_PCRSCR, (unsigned long)&pcrscr); |
1838 | if (ret < 0) { |
1839 | CODEC_PRINT("[%s]ioctl failed %d\n", __FUNCTION__, ret); |
1840 | return -1; |
1841 | } |
1842 | |
1843 | return pcrscr; |
1844 | } |
1845 | |
1846 | /* --------------------------------------------------------------------------*/ |
1847 | /** |
1848 | * @brief codec_set_pcrscr set system pcrscr |
1849 | * |
1850 | * @param[in] pcodec Pointer of codec parameter structure |
1851 | * @param[in] val system pcrscr value |
1852 | * |
1853 | * @return 0 is success , or -1 failed. |
1854 | */ |
1855 | /* --------------------------------------------------------------------------*/ |
1856 | int codec_set_pcrscr(codec_para_t *pcodec, int val) |
1857 | { |
1858 | unsigned int pcrscr; |
1859 | int ret; |
1860 | |
1861 | if (!pcodec) { |
1862 | CODEC_PRINT("[%s]ERROR invalid pointer!\n", __FUNCTION__); |
1863 | return -1; |
1864 | } |
1865 | |
1866 | ret = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_PCRSCR, val); |
1867 | if (ret < 0) { |
1868 | CODEC_PRINT("[%s]ioctl failed %d\n", __FUNCTION__, ret); |
1869 | return -1; |
1870 | } |
1871 | |
1872 | return 0; |
1873 | } |
1874 | |
1875 | /* --------------------------------------------------------------------------*/ |
1876 | /** |
1877 | * @brief codec_set_syncenable enable or disable av sync |
1878 | * |
1879 | * @param[in] pcodec Pointer of codec parameter structure |
1880 | * @param[in] enable Enable or disable to be set |
1881 | * |
1882 | * @return 0 for success, or fail type if < 0 |
1883 | */ |
1884 | /* --------------------------------------------------------------------------*/ |
1885 | int codec_set_syncenable(codec_para_t *pcodec, int enable) |
1886 | { |
1887 | return codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_SYNCENABLE, (unsigned long)enable); |
1888 | } |
1889 | |
1890 | /* --------------------------------------------------------------------------*/ |
1891 | /** |
1892 | * @brief codec_set_sync_audio_discont set sync discontinue state |
1893 | * |
1894 | * @param[in] pcodec Pointer of codec parameter structure |
1895 | * @param[in] discontinue Discontinue state to be set |
1896 | * |
1897 | * @return 0 for success, or fail type if < 0 |
1898 | */ |
1899 | /* --------------------------------------------------------------------------*/ |
1900 | int codec_set_sync_audio_discont(codec_para_t *pcodec, int discontinue) |
1901 | { |
1902 | return codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_SET_SYNC_ADISCON, (unsigned long)discontinue); |
1903 | } |
1904 | |
1905 | /* --------------------------------------------------------------------------*/ |
1906 | /** |
1907 | * @brief codec_set_sync_video_discont set sync discontinue state |
1908 | * |
1909 | * @param[in] pcodec Pointer of codec parameter structure |
1910 | * @param[in] discontinue Discontinue state to be set |
1911 | * |
1912 | * @return 0 for success, or fail type if < 0 |
1913 | */ |
1914 | /* --------------------------------------------------------------------------*/ |
1915 | int codec_set_sync_video_discont(codec_para_t *pcodec, int discontinue) |
1916 | { |
1917 | return codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_SET_SYNC_VDISCON, (unsigned long)discontinue); |
1918 | } |
1919 | |
1920 | /* --------------------------------------------------------------------------*/ |
1921 | /** |
1922 | * @brief codec_get_sync_audio_discont get audio sync discontinue state |
1923 | * |
1924 | * @param[in] pcodec Pointer of codec parameter structure |
1925 | * |
1926 | * @return discontiue state, or fail if < 0 |
1927 | */ |
1928 | /* --------------------------------------------------------------------------*/ |
1929 | int codec_get_sync_audio_discont(codec_para_t *pcodec) |
1930 | { |
1931 | int discontinue = 0; |
1932 | int ret; |
1933 | |
1934 | ret = codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_GET_SYNC_ADISCON, (unsigned long)&discontinue); |
1935 | if (ret < 0) { |
1936 | return ret; |
1937 | } |
1938 | return discontinue; |
1939 | } |
1940 | |
1941 | /* --------------------------------------------------------------------------*/ |
1942 | /** |
1943 | * @brief codec_get_sync_video_discont get video sync discontinue state |
1944 | * |
1945 | * @param[in] pcodec Pointer of codec parameter structure |
1946 | * |
1947 | * @return discontiue state, or fail if < 0 |
1948 | */ |
1949 | /* --------------------------------------------------------------------------*/ |
1950 | int codec_get_sync_video_discont(codec_para_t *pcodec) |
1951 | { |
1952 | int discontinue = 0; |
1953 | int ret; |
1954 | |
1955 | ret = codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_GET_SYNC_VDISCON, (unsigned long)&discontinue); |
1956 | if (ret < 0) { |
1957 | return ret; |
1958 | } |
1959 | return discontinue; |
1960 | } |
1961 | |
1962 | /* --------------------------------------------------------------------------*/ |
1963 | /** |
1964 | * @brief codec_get_sync_audio_discont_diff get audio sync discontinue state |
1965 | * |
1966 | * @param[in] pcodec Pointer of codec parameter structure |
1967 | * |
1968 | * @return discontiue diff, or fail if < 0 |
1969 | */ |
1970 | /* --------------------------------------------------------------------------*/ |
1971 | unsigned long codec_get_sync_audio_discont_diff(codec_para_t *pcodec) |
1972 | { |
1973 | unsigned long discontinue_diff = 0; |
1974 | int ret; |
1975 | |
1976 | ret = codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_GET_SYNC_ADISCON_DIFF, (unsigned long)&discontinue_diff); |
1977 | if (ret < 0) { |
1978 | return ret; |
1979 | } |
1980 | return discontinue_diff; |
1981 | } |
1982 | |
1983 | /* --------------------------------------------------------------------------*/ |
1984 | /** |
1985 | * @brief codec_get_sync_video_discont_diff get audio sync discontinue state |
1986 | * |
1987 | * @param[in] pcodec Pointer of codec parameter structure |
1988 | * |
1989 | * @return discontiue diff, or fail if < 0 |
1990 | */ |
1991 | /* --------------------------------------------------------------------------*/ |
1992 | unsigned long codec_get_sync_video_discont_diff(codec_para_t *pcodec) |
1993 | { |
1994 | unsigned long discontinue_diff = 0; |
1995 | int ret; |
1996 | |
1997 | ret = codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_GET_SYNC_VDISCON_DIFF, (unsigned long)&discontinue_diff); |
1998 | if (ret < 0) { |
1999 | return ret; |
2000 | } |
2001 | return discontinue_diff; |
2002 | } |
2003 | |
2004 | /* --------------------------------------------------------------------------*/ |
2005 | /** |
2006 | * @brief codec_set_sync_audio_discont_diff set sync discontinue diff |
2007 | * |
2008 | * @param[in] pcodec Pointer of codec parameter structure |
2009 | * @param[in] discontinue_diff Discontinue diff to be set |
2010 | * |
2011 | * @return 0 for success, or fail type if < 0 |
2012 | */ |
2013 | /* --------------------------------------------------------------------------*/ |
2014 | int codec_set_sync_audio_discont_diff(codec_para_t *pcodec, unsigned long discontinue_diff) |
2015 | { |
2016 | return codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_SET_SYNC_ADISCON_DIFF, discontinue_diff); |
2017 | } |
2018 | |
2019 | /* --------------------------------------------------------------------------*/ |
2020 | /** |
2021 | * @brief codec_set_sync_video_discont_diff set sync discontinue diff |
2022 | * |
2023 | * @param[in] pcodec Pointer of codec parameter structure |
2024 | * @param[in] discontinue_diff Discontinue diff to be set |
2025 | * |
2026 | * @return 0 for success, or fail type if < 0 |
2027 | */ |
2028 | /* --------------------------------------------------------------------------*/ |
2029 | int codec_set_sync_video_discont_diff(codec_para_t *pcodec, unsigned long discontinue_diff) |
2030 | { |
2031 | return codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_SET_SYNC_VDISCON_DIFF, discontinue_diff); |
2032 | } |
2033 | |
2034 | /* --------------------------------------------------------------------------*/ |
2035 | /** |
2036 | * @brief codec_get_sub_num get the number of subtitle |
2037 | * |
2038 | * @param[in] pcodec Pointer of codec parameter structure |
2039 | * |
2040 | * @return the number of subtitle, or fail if < 0 |
2041 | */ |
2042 | /* --------------------------------------------------------------------------*/ |
2043 | int codec_get_sub_num(codec_para_t *pcodec) |
2044 | { |
2045 | int sub_num = 0; |
2046 | int ret; |
2047 | |
2048 | ret = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_GET, AMSTREAM_GET_SUB_NUM, (unsigned long)&sub_num); |
2049 | if (ret < 0) { |
2050 | return ret; |
2051 | } |
2052 | return sub_num; |
2053 | } |
2054 | |
2055 | /* --------------------------------------------------------------------------*/ |
2056 | /** |
2057 | * @brief codec_get_sub_info get subtitle information |
2058 | * |
2059 | * @param[in] pcodec Pointer of codec parameter structure |
2060 | * @param[out] sub_info Pointer of subtitle_info_t to save the subtitle information |
2061 | * |
2062 | * @return 0 for success, or fail type if < 0 |
2063 | */ |
2064 | /* --------------------------------------------------------------------------*/ |
2065 | int codec_get_sub_info(codec_para_t *pcodec, subtitle_info_t *sub_info) |
2066 | { |
2067 | int ret = 0; |
2068 | int i; |
2069 | if (!sub_info) { |
2070 | CODEC_PRINT("[codec_get_sub_info] error, NULL pointer!\n"); |
2071 | ret = CODEC_ERROR_INVAL; |
2072 | return ret; |
2073 | } |
2074 | ret = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_GET_PTR, AMSTREAM_GET_PTR_SUB_INFO, (unsigned long)sub_info); |
2075 | if (ret < 0) { |
2076 | return ret; |
2077 | } |
2078 | return ret; |
2079 | } |
2080 | |
2081 | /******************************************************************************** |
2082 | * |
2083 | *the interface for av sync threshold setting |
2084 | * |
2085 | *********************************************************************************/ |
2086 | int codec_set_av_threshold(codec_para_t *pcodec, int threshold) |
2087 | { |
2088 | int ret = 0; |
2089 | if (pcodec->has_audio) { |
2090 | //DEBUG_TMP audio_set_av_sync_threshold(pcodec->adec_priv, threshold); |
2091 | } else { |
2092 | CODEC_PRINT("[codec_set_av_threshold] error, no audio!\n"); |
2093 | ret = -1; |
2094 | } |
2095 | |
2096 | return ret; |
2097 | } |
2098 | |
2099 | /* --------------------------------------------------------------------------*/ |
2100 | /** |
2101 | * @brief codec_get_freerun_mode Get the mode of video freerun |
2102 | * |
2103 | * @param[in] pcodec Pointer of codec parameter structure |
2104 | * |
2105 | * @return Video free run mode or fail error type |
2106 | */ |
2107 | /* --------------------------------------------------------------------------*/ |
2108 | int codec_get_freerun_mode(codec_para_t *pcodec) |
2109 | { |
2110 | int freerun_mode, r; |
2111 | |
2112 | if (pcodec->cntl_handle == 0) { |
2113 | CODEC_PRINT("no control handler\n"); |
2114 | return 0; |
2115 | } |
2116 | |
2117 | r = codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_GET_FREERUN_MODE, (unsigned long)&freerun_mode); |
2118 | if (r < 0) { |
2119 | return system_error_to_codec_error(r); |
2120 | } else { |
2121 | return freerun_mode; |
2122 | } |
2123 | } |
2124 | |
2125 | /* --------------------------------------------------------------------------*/ |
2126 | /** |
2127 | * @brief codec_set_freerun_mode Set the mode to video freerun |
2128 | * |
2129 | * @param[in] pcodec Pointer of codec parameter structure |
2130 | * @param[in] mode Freerun mode to be set |
2131 | * |
2132 | * @return 0 for success, or fail type if < 0 |
2133 | */ |
2134 | /* --------------------------------------------------------------------------*/ |
2135 | int codec_set_freerun_mode(codec_para_t *pcodec, unsigned int mode) |
2136 | { |
2137 | return codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_SET_FREERUN_MODE, (unsigned long)mode); |
2138 | } |
2139 | |
2140 | /* --------------------------------------------------------------------------*/ |
2141 | /** |
2142 | * @brief codec_init_audio_utils Initialize the audio utils device |
2143 | * |
2144 | * @param[in] pcodec Pointer of codec parameter structure |
2145 | * |
2146 | * @return Success or fail error type |
2147 | */ |
2148 | /* --------------------------------------------------------------------------*/ |
2149 | int codec_init_audio_utils(codec_para_t *pcodec) |
2150 | { |
2151 | CODEC_HANDLE audio_utils; |
2152 | |
2153 | audio_utils = codec_h_open(CODEC_AUDIO_UTILS_DEVICE, O_RDONLY); |
2154 | if (audio_utils < 0) { |
2155 | CODEC_PRINT("get %s failed\n", CODEC_AUDIO_UTILS_DEVICE); |
2156 | return system_error_to_codec_error(audio_utils); |
2157 | } |
2158 | |
2159 | pcodec->audio_utils_handle = audio_utils; |
2160 | |
2161 | return CODEC_ERROR_NONE; |
2162 | } |
2163 | |
2164 | /* --------------------------------------------------------------------------*/ |
2165 | /** |
2166 | * @brief codec_release_audio_utils Release the audio utils device |
2167 | * |
2168 | * @param[in] pcodec Pointer of codec parameter structure |
2169 | * |
2170 | * @return Success or fail error type |
2171 | */ |
2172 | /* --------------------------------------------------------------------------*/ |
2173 | int codec_release_audio_utils(codec_para_t *pcodec) |
2174 | { |
2175 | if (pcodec) { |
2176 | if (pcodec->audio_utils_handle >= 0) { |
2177 | codec_h_close(pcodec->audio_utils_handle); |
2178 | } |
2179 | } |
2180 | |
2181 | pcodec->audio_utils_handle = -1; |
2182 | |
2183 | return CODEC_ERROR_NONE; |
2184 | } |
2185 | |
2186 | /* --------------------------------------------------------------------------*/ |
2187 | /** |
2188 | * @brief codec_set_audio_resample_ena Set audio resample |
2189 | * |
2190 | * @param[in] pcodec Pointer of codec parameter structure |
2191 | * |
2192 | * @return Success or fail error type |
2193 | */ |
2194 | /* --------------------------------------------------------------------------*/ |
2195 | int codec_set_audio_resample_ena(codec_para_t *pcodec, unsigned long mode) |
2196 | { |
2197 | return codec_h_control(pcodec->audio_utils_handle, AMAUDIO_IOC_SET_RESAMPLE_ENA, mode); |
2198 | } |
2199 | |
2200 | /* --------------------------------------------------------------------------*/ |
2201 | /** |
2202 | * @brief codec_set_audio_resample_ena Set audio resample enable |
2203 | * |
2204 | * @param[in] pcodec Pointer of codec parameter structure |
2205 | * |
2206 | * @return Success or fail error type |
2207 | */ |
2208 | /* --------------------------------------------------------------------------*/ |
2209 | int codec_get_audio_resample_ena(codec_para_t *pcodec) |
2210 | { |
2211 | unsigned long audio_resample_ena; |
2212 | int ret; |
2213 | ret = codec_h_control(pcodec->audio_utils_handle, AMAUDIO_IOC_GET_RESAMPLE_ENA, (unsigned long)&audio_resample_ena); |
2214 | if (ret < 0) { |
2215 | return system_error_to_codec_error(ret); |
2216 | } else { |
2217 | return audio_resample_ena; |
2218 | } |
2219 | } |
2220 | |
2221 | /* --------------------------------------------------------------------------*/ |
2222 | /** |
2223 | * @brief codec_set_audio_resample_type Set audio resample type |
2224 | * |
2225 | * @param[in] pcodec Pointer of codec parameter structure |
2226 | * |
2227 | * @return Success or fail error type |
2228 | */ |
2229 | /* --------------------------------------------------------------------------*/ |
2230 | int codec_set_audio_resample_type(codec_para_t *pcodec, unsigned long type) |
2231 | { |
2232 | return codec_h_control(pcodec->audio_utils_handle, AMAUDIO_IOC_SET_RESAMPLE_TYPE, type); |
2233 | } |
2234 | |
2235 | /* --------------------------------------------------------------------------*/ |
2236 | /** |
2237 | * @brief codec_set_video_delay_limited_ms Set video buffer max delayed,if> settings,write may wait& again, |
2238 | * |
2239 | * @param[in] pcodec Pointer of codec parameter structure |
2240 | * |
2241 | * @return 0 for success, or fail type if < 0 |
2242 | */ |
2243 | /* --------------------------------------------------------------------------*/ |
2244 | int codec_set_video_delay_limited_ms(codec_para_t *pcodec, int delay_ms) |
2245 | { |
2246 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_VIDEO_DELAY_LIMIT_MS, delay_ms); |
2247 | } |
2248 | /* --------------------------------------------------------------------------*/ |
2249 | /** |
2250 | * @brief codec_get_video_delay_limited_ms Set video buffer max delayed,if> settings,write may wait& again, |
2251 | * |
2252 | * @param[in] pcodec Pointer of codec parameter structure |
2253 | * |
2254 | * @return 0 for success, or fail type if < 0 |
2255 | */ |
2256 | /* --------------------------------------------------------------------------*/ |
2257 | int codec_get_video_delay_limited_ms(codec_para_t *pcodec, int *delay_ms) |
2258 | { |
2259 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_GET, AMSTREAM_GET_VIDEO_DELAY_LIMIT_MS, (unsigned long)delay_ms); |
2260 | } |
2261 | |
2262 | |
2263 | /* --------------------------------------------------------------------------*/ |
2264 | /** |
2265 | * @brief codec_set_video_delay_limited_ms Set video buffer max delayed,if> settings,write may wait& again, |
2266 | * |
2267 | * @param[in] pcodec Pointer of codec parameter structure |
2268 | * |
2269 | * @return 0 for success, or fail type if < 0 |
2270 | */ |
2271 | /* --------------------------------------------------------------------------*/ |
2272 | int codec_set_audio_delay_limited_ms(codec_para_t *pcodec, int delay_ms) |
2273 | { |
2274 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_AUDIO_DELAY_LIMIT_MS, delay_ms); |
2275 | } |
2276 | |
2277 | /* --------------------------------------------------------------------------*/ |
2278 | /** |
2279 | * @brief codec_get_audio_delay_limited_ms get video buffer max delayed,if> settings,write may wait& again, |
2280 | * |
2281 | * @param[in] pcodec Pointer of codec parameter structure |
2282 | * |
2283 | * @return 0 for success, or fail type if < 0 |
2284 | */ |
2285 | /* --------------------------------------------------------------------------*/ |
2286 | int codec_get_audio_delay_limited_ms(codec_para_t *pcodec, int *delay_ms) |
2287 | { |
2288 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_GET, AMSTREAM_GET_AUDIO_DELAY_LIMIT_MS, (unsigned long)delay_ms); |
2289 | } |
2290 | |
2291 | /* --------------------------------------------------------------------------*/ |
2292 | /** |
2293 | * @brief codec_get_audio_cur_delay_ms get current audio delay ms |
2294 | * |
2295 | * @param[in] pcodec Pointer of codec parameter structure |
2296 | * |
2297 | * @return 0 for success, or fail type if < 0 |
2298 | */ |
2299 | /* --------------------------------------------------------------------------*/ |
2300 | int codec_get_audio_cur_delay_ms(codec_para_t *pcodec, int *delay_ms) |
2301 | { |
2302 | int abuf_delay = 0; |
2303 | int adec_delay = 0; |
2304 | int ret = 0; |
2305 | ret = codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_GET, AMSTREAM_GET_AUDIO_CUR_DELAY_MS, (unsigned long)&abuf_delay); |
2306 | if (ret < 0) { |
2307 | CODEC_PRINT("[%s]ioctl failed %d\n", __FUNCTION__, ret); |
2308 | return -1; |
2309 | } |
2310 | if (pcodec->has_audio) { |
2311 | //DEBUG_TMP adec_delay = audio_get_decoded_pcm_delay(pcodec->adec_priv); |
2312 | if (adec_delay < 0) { |
2313 | adec_delay = 0; |
2314 | } |
2315 | } |
2316 | *delay_ms = abuf_delay + adec_delay; |
2317 | return ret; |
2318 | } |
2319 | |
2320 | |
2321 | |
2322 | /* --------------------------------------------------------------------------*/ |
2323 | /** |
2324 | * @brief codec_get_video_cur_delay_ms get video current delay ms |
2325 | * |
2326 | * @param[in] pcodec Pointer of codec parameter structure |
2327 | * |
2328 | * @return 0 for success, or fail type if < 0 |
2329 | */ |
2330 | /* --------------------------------------------------------------------------*/ |
2331 | int codec_get_video_cur_delay_ms(codec_para_t *pcodec, int *delay_ms) |
2332 | { |
2333 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_GET, AMSTREAM_GET_VIDEO_CUR_DELAY_MS, (unsigned long)delay_ms); |
2334 | } |
2335 | |
2336 | /* --------------------------------------------------------------------------*/ |
2337 | /** |
2338 | * @brief codec_get_audio_cur_delay_ms get vido latest bitrate. |
2339 | * |
2340 | * @param[in] pcodec Pointer of codec parameter structure |
2341 | * |
2342 | * @return 0 for success, or fail type if < 0 |
2343 | */ |
2344 | /* --------------------------------------------------------------------------*/ |
2345 | int codec_get_video_cur_bitrate(codec_para_t *pcodec, int *bitrate) |
2346 | { |
2347 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_GET, AMSTREAM_GET_VIDEO_AVG_BITRATE_BPS, (unsigned long)bitrate); |
2348 | } |
2349 | |
2350 | |
2351 | /* --------------------------------------------------------------------------*/ |
2352 | /** |
2353 | * @brief codec_get_audio_cur_bitrate get audio latest bitrate. |
2354 | * |
2355 | * @param[in] pcodec Pointer of codec parameter structure |
2356 | * |
2357 | * @return 0 for success, or fail type if < 0 |
2358 | */ |
2359 | /* --------------------------------------------------------------------------*/ |
2360 | int codec_get_audio_cur_bitrate(codec_para_t *pcodec, int *bitrate) |
2361 | { |
2362 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_GET, AMSTREAM_GET_AUDIO_AVG_BITRATE_BPS, (unsigned long)bitrate); |
2363 | } |
2364 | /* --------------------------------------------------------------------------*/ |
2365 | /** |
2366 | * @brief codec_get_video_checkin_bitrate get vido latest bitrate. |
2367 | * |
2368 | * @param[in] pcodec Pointer of codec parameter structure |
2369 | * |
2370 | * @return 0 for success, or fail type if < 0 |
2371 | */ |
2372 | /* --------------------------------------------------------------------------*/ |
2373 | int codec_get_video_checkin_bitrate(codec_para_t *pcodec, int *bitrate) |
2374 | { |
2375 | return codec_h_control(pcodec->handle, AMSTREAM_IOC_GET_VIDEO_CHECKIN_BITRATE_BPS, (unsigned long)bitrate); |
2376 | } |
2377 | /* --------------------------------------------------------------------------*/ |
2378 | /** |
2379 | * @brief codec_get_audio_checkin_bitrate get audio latest bitrate. |
2380 | * |
2381 | * @param[in] pcodec Pointer of codec parameter structure |
2382 | * |
2383 | * @return 0 for success, or fail type if < 0 |
2384 | */ |
2385 | /* --------------------------------------------------------------------------*/ |
2386 | int codec_get_audio_checkin_bitrate(codec_para_t *pcodec, int *bitrate) |
2387 | { |
2388 | return codec_h_control(pcodec->handle, AMSTREAM_IOC_GET_AUDIO_CHECKIN_BITRATE_BPS, (unsigned long)bitrate); |
2389 | } |
2390 | |
2391 | /* --------------------------------------------------------------------------*/ |
2392 | /** |
2393 | * @brief codec_set_vsync_upint Set the mode to video freerun |
2394 | * |
2395 | * @param[in] pcodec Pointer of codec parameter structure |
2396 | * @param[in] mode vsync upint mode to be set |
2397 | * |
2398 | * @return 0 for success, or fail type if < 0 |
2399 | */ |
2400 | /* --------------------------------------------------------------------------*/ |
2401 | int codec_set_vsync_upint(codec_para_t *pcodec, unsigned int mode) |
2402 | { |
2403 | return codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_SET_VSYNC_UPINT, (unsigned long)mode); |
2404 | } |
2405 | int codec_set_drmmode(codec_para_t *pcodec, unsigned int setval) |
2406 | { |
2407 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_SET, AMSTREAM_SET_DRMMODE, setval); |
2408 | } |
2409 | |
2410 | /** |
2411 | * |
2412 | * |
2413 | */ |
2414 | int codec_get_last_checkout_apts(codec_para_t* pcodec, unsigned long *apts) |
2415 | { |
2416 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_GET, AMSTREAM_GET_LAST_CHECKOUT_APTS, (unsigned long)apts); |
2417 | } |
2418 | |
2419 | int codec_get_last_checkin_apts(codec_para_t* pcodec, unsigned long* apts) |
2420 | { |
2421 | return codec_h_ioctl(pcodec->handle, AMSTREAM_IOC_GET, AMSTREAM_GET_LAST_CHECKIN_APTS, (unsigned long)apts); |
2422 | } |
2423 | |
2424 | /** |
2425 | *@brief codec_get_pcm_level get the PCM data in buffer between DSP and output |
2426 | * |
2427 | * @param[in] pcodec Pointer of codec parameter structre |
2428 | * @param[in] level Address to store "level" |
2429 | * @return 0 for success, or fail type if<0 |
2430 | */ |
2431 | |
2432 | int codec_get_pcm_level(codec_para_t* pcodec, unsigned int* level) |
2433 | { |
2434 | return 0;//DEBUG_TMP audio_get_pcm_level(pcodec->adec_priv); |
2435 | } |
2436 | |
2437 | int codec_set_skip_bytes(codec_para_t* pcodec, unsigned int bytes) |
2438 | { |
2439 | return 0;//DEBUG_TMP audio_set_skip_bytes(pcodec->adec_priv, bytes); |
2440 | } |
2441 | |
2442 | int codec_get_dsp_apts(codec_para_t* pcodec, unsigned int * apts) |
2443 | { |
2444 | return 0;//DEBUG_TMP audio_get_pts(pcodec->adec_priv); |
2445 | } |
2446 | |
2447 | /* --------------------------------------------------------------------------*/ |
2448 | /** |
2449 | * @brief codec_get_cntl_vpts Get the vpts in trickmode |
2450 | * |
2451 | * @param[in] pcodec Pointer of codec parameter structure |
2452 | * |
2453 | * @return Video pts or fail error type |
2454 | */ |
2455 | /* --------------------------------------------------------------------------*/ |
2456 | int codec_get_cntl_vpts(codec_para_t *pcodec) |
2457 | { |
2458 | int cntl_vpts, r; |
2459 | |
2460 | if (pcodec->cntl_handle == 0) { |
2461 | CODEC_PRINT("no control handler\n"); |
2462 | return 0; |
2463 | } |
2464 | |
2465 | r = codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_GET_TRICK_VPTS, (unsigned long)&cntl_vpts); |
2466 | if (r < 0) { |
2467 | return system_error_to_codec_error(r); |
2468 | } else { |
2469 | return cntl_vpts; |
2470 | } |
2471 | } |
2472 | |
2473 | /* --------------------------------------------------------------------------*/ |
2474 | /** |
2475 | * @brief codec_disalbe_slowsync Set the slowsync disable or enable |
2476 | * |
2477 | * @param[in] pcodec Pointer of codec parameter structure |
2478 | * @param[in] disalbe_slowsync disable slowsync or not |
2479 | * |
2480 | * @return 0 or fail error type |
2481 | */ |
2482 | /* --------------------------------------------------------------------------*/ |
2483 | int codec_disalbe_slowsync(codec_para_t *pcodec, int disable_slowsync) |
2484 | { |
2485 | int cntl_vpts, r; |
2486 | |
2487 | if (pcodec->cntl_handle == 0) { |
2488 | CODEC_PRINT("no control handler\n"); |
2489 | return 0; |
2490 | } |
2491 | |
2492 | r = codec_h_control(pcodec->cntl_handle, AMSTREAM_IOC_DISABLE_SLOW_SYNC, (unsigned long)disable_slowsync); |
2493 | if (r < 0) { |
2494 | return system_error_to_codec_error(r); |
2495 | } else { |
2496 | return 0; |
2497 | } |
2498 | } |
2499 | |
2500 | /* --------------------------------------------------------------------------*/ |
2501 | /** |
2502 | * @brief add video position setting for xbmc APK |
2503 | * |
2504 | * @param[in] osd position value |
2505 | * @param[in] rotation angle |
2506 | * |
2507 | * @return 0 success or fail error type |
2508 | */ |
2509 | /* --------------------------------------------------------------------------*/ |
2510 | int codec_utils_set_video_position(int x, int y, int w, int h, int rotation) |
2511 | { |
2512 | amvideo_utils_set_virtual_position(x, y, w, h, rotation); |
2513 | return 0; |
2514 | |
2515 | } |
2516 | |
2517 |