amplayerMy Project
|
player_ctrl.c
Go to the documentation of this file.
00001 00009 /* Copyright (c) 2007-2011, Amlogic Inc. 00010 * All right reserved 00011 * 00012 */ 00013 00014 #include <pthread.h> 00015 #include <player.h> 00016 #include <player_set_sys.h> 00017 00018 #include "player_ts.h" 00019 #include "player_es.h" 00020 #include "player_rm.h" 00021 #include "player_ps.h" 00022 #include "player_video.h" 00023 #include "player_audio.h" 00024 00025 #include "player_update.h" 00026 #include "thread_mgt.h" 00027 #include "player_ffmpeg_ctrl.h" 00028 #include "player_cache_mgt.h" 00029 #include "player_priv.h" 00030 #include <amthreadpool.h> 00031 00032 #ifndef FBIOPUT_OSD_SRCCOLORKEY 00033 #define FBIOPUT_OSD_SRCCOLORKEY 0x46fb 00034 #endif 00035 00036 #ifndef FBIOPUT_OSD_SRCKEY_ENABLE 00037 #define FBIOPUT_OSD_SRCKEY_ENABLE 0x46fa 00038 #endif 00039 00040 extern void print_version_info(); 00041 00042 /* --------------------------------------------------------------------------*/ 00059 /* --------------------------------------------------------------------------*/ 00060 00061 int player_init(void) 00062 { 00063 print_version_info(); 00064 update_loglevel_setting(); 00065 /*register all formats and codecs*/ 00066 ffmpeg_init(); 00067 00068 player_id_pool_init(); 00069 00070 codec_audio_basic_init(); 00071 00072 /*register all support decoder */ 00073 ts_register_stream_decoder(); 00074 es_register_stream_decoder(); 00075 ps_register_stream_decoder(); 00076 rm_register_stream_decoder(); 00077 audio_register_stream_decoder(); 00078 video_register_stream_decoder(); 00079 return PLAYER_SUCCESS; 00080 } 00081 00082 /* --------------------------------------------------------------------------*/ 00097 /* --------------------------------------------------------------------------*/ 00098 int player_start(play_control_t *ctrl_p, unsigned long priv) 00099 { 00100 int ret; 00101 int pid = -1; 00102 play_para_t *p_para; 00103 //char stb_source[32]; 00104 00105 update_loglevel_setting(); 00106 update_dump_dir_path(); 00107 print_version_info(); 00108 log_print("[player_start:enter]p=%p black=%d\n", ctrl_p, get_black_policy()); 00109 00110 if (ctrl_p == NULL) { 00111 return PLAYER_EMPTY_P; 00112 } 00113 00114 /*keep last frame displaying --default*/ 00115 set_black_policy(0); 00116 /* if not set keep last frame, or change file playback, clear display last frame */ 00117 if (!ctrl_p->displast_frame) { 00118 set_black_policy(1); 00119 } else if (!check_file_same(ctrl_p->file_name)) { 00120 set_black_policy(1); 00121 } 00122 00123 pid = player_request_pid(); 00124 if (pid < 0) { 00125 return PLAYER_NOT_VALID_PID; 00126 } 00127 00128 p_para = MALLOC(sizeof(play_para_t)); 00129 if (p_para == NULL) { 00130 return PLAYER_NOMEM; 00131 } 00132 00133 MEMSET(p_para, 0, sizeof(play_para_t)); 00134 00135 /* init time_point to a invalid value */ 00136 p_para->playctrl_info.time_point = -1; 00137 00138 player_init_pid_data(pid, p_para); 00139 00140 message_pool_init(p_para); 00141 00142 p_para->start_param = ctrl_p; 00143 p_para->player_id = pid; 00144 p_para->extern_priv = priv; 00145 log_debug1("[player_start]player_para=%p,start_param=%p pid=%d\n", p_para, p_para->start_param, pid); 00146 00147 ret = player_thread_create(p_para) ; 00148 if (ret != PLAYER_SUCCESS) { 00149 FREE(p_para); 00150 player_release_pid(pid); 00151 return PLAYER_CAN_NOT_CREAT_THREADS; 00152 } 00153 log_print("[player_start:exit]pid = %d \n", pid); 00154 00155 return pid; 00156 } 00157 00158 /* --------------------------------------------------------------------------*/ 00172 /* --------------------------------------------------------------------------*/ 00173 int player_start_play(int pid) 00174 { 00175 player_cmd_t *cmd; 00176 int r = PLAYER_SUCCESS; 00177 play_para_t *player_para; 00178 00179 log_print("[player_start_play:enter]pid=%d\n", pid); 00180 00181 player_para = player_open_pid_data(pid); 00182 if (player_para == NULL) { 00183 return PLAYER_NOT_VALID_PID; 00184 } 00185 00186 cmd = message_alloc(); 00187 if (cmd) { 00188 cmd->ctrl_cmd = CMD_START; 00189 r = send_message(player_para, cmd); 00190 } else { 00191 r = PLAYER_NOMEM; 00192 } 00193 00194 player_close_pid_data(pid); 00195 log_print("[player_start_play:exit]pid = %d\n", pid); 00196 00197 return r; 00198 } 00199 00200 /* --------------------------------------------------------------------------*/ 00215 /* --------------------------------------------------------------------------*/ 00216 int player_stop(int pid) 00217 { 00218 player_cmd_t *cmd; 00219 int r = PLAYER_SUCCESS; 00220 play_para_t *player_para; 00221 player_status sta; 00222 00223 log_print("[player_stop:enter]pid=%d\n", pid); 00224 00225 player_para = player_open_pid_data(pid); 00226 if (player_para == NULL) { 00227 return PLAYER_NOT_VALID_PID; 00228 } 00229 00230 sta = get_player_state(player_para); 00231 log_print("[player_stop]player_status=%x\n", sta); 00232 if (PLAYER_THREAD_IS_STOPPED(sta)) { 00233 player_close_pid_data(pid); 00234 log_print("[player_stop]pid=%d thread is already stopped\n", pid); 00235 return PLAYER_SUCCESS; 00236 } 00237 /*if (player_para->pFormatCtx) { 00238 av_ioctrl(player_para->pFormatCtx, AVIOCTL_STOP, 0, 0); 00239 }*/ 00240 clear_all_message(player_para);/*clear old message to make sure fast exit.*/ 00241 cmd = message_alloc(); 00242 if (cmd) { 00243 cmd->ctrl_cmd = CMD_STOP; 00244 ffmpeg_interrupt(player_para->thread_mgt.pthread_id); 00245 r = send_message(player_para, cmd); 00246 r = player_thread_wait_exit(player_para); 00247 log_print("[player_stop:%d]wait player_theadpid[%d] r = %d\n", __LINE__, player_para->player_id, r); 00248 clear_all_message(player_para); 00249 ffmpeg_uninterrupt(player_para->thread_mgt.pthread_id); 00250 } else { 00251 r = PLAYER_NOMEM; 00252 } 00253 00254 player_close_pid_data(pid); 00255 log_print("[player_stop:exit]pid=%d\n", pid); 00256 tcppool_refresh_link_and_check(); 00257 log_print("[tcppool_refresh_link_and_check]pid=%d\n", pid); 00258 return r; 00259 } 00260 00261 /* --------------------------------------------------------------------------*/ 00276 /* --------------------------------------------------------------------------*/ 00277 int player_stop_async(int pid) 00278 { 00279 player_cmd_t *cmd; 00280 int r = PLAYER_SUCCESS; 00281 play_para_t *player_para; 00282 player_status sta; 00283 00284 player_para = player_open_pid_data(pid); 00285 00286 if (player_para == NULL) { 00287 return PLAYER_NOT_VALID_PID; 00288 } 00289 00290 sta = get_player_state(player_para); 00291 log_print("[player_stop]player_status=%x\n", sta); 00292 if (PLAYER_THREAD_IS_STOPPED(sta)) { 00293 player_close_pid_data(pid); 00294 log_print("[player_stop]pid=%d thread is already stopped\n", pid); 00295 return PLAYER_SUCCESS; 00296 } 00297 clear_all_message(player_para);/*clear old message to make sure fast exit.*/ 00298 cmd = message_alloc(); 00299 if (cmd) { 00300 cmd->ctrl_cmd = CMD_STOP; 00301 ffmpeg_interrupt(player_para->thread_mgt.pthread_id); 00302 r = send_message(player_para, cmd); 00303 } else { 00304 r = PLAYER_NOMEM; 00305 } 00306 00307 player_close_pid_data(pid); 00308 00309 return r; 00310 } 00311 00312 00313 00314 00315 /* --------------------------------------------------------------------------*/ 00329 /* --------------------------------------------------------------------------*/ 00330 int player_exit(int pid) 00331 { 00332 int ret = PLAYER_SUCCESS; 00333 play_para_t *para; 00334 00335 log_print("[player_exit:enter]pid=%d\n", pid); 00336 00337 para = player_open_pid_data(pid); 00338 if (para != NULL) { 00339 log_print("[player_exit]player_state=0x%x\n", get_player_state(para)); 00340 if (get_player_state(para) != PLAYER_EXIT) { 00341 player_stop(pid); 00342 } 00343 00344 ret = player_thread_wait_exit(para); 00345 log_print("[player_exit]player thread already exit: %d\n", ret); 00346 ffmpeg_uninterrupt(para->thread_mgt.pthread_id); 00347 FREE(para); 00348 para = NULL; 00349 } 00350 player_close_pid_data(pid); 00351 player_release_pid(pid); 00352 log_print("[player_exit:exit]pid=%d\n", pid); 00353 00354 return ret; 00355 } 00356 00357 /* --------------------------------------------------------------------------*/ 00371 /* --------------------------------------------------------------------------*/ 00372 int player_pause(int pid) 00373 { 00374 player_cmd_t cmd; 00375 int ret = PLAYER_SUCCESS; 00376 00377 log_print("[player_pause:enter]pid=%d\n", pid); 00378 00379 MEMSET(&cmd, 0, sizeof(player_cmd_t)); 00380 00381 cmd.ctrl_cmd = CMD_PAUSE; 00382 00383 ret = player_send_message(pid, &cmd); 00384 log_print("[player_pause:exit]pid=%d ret=%d\n", pid, ret); 00385 00386 return ret; 00387 } 00388 00389 /* --------------------------------------------------------------------------*/ 00403 /* --------------------------------------------------------------------------*/ 00404 int player_resume(int pid) 00405 { 00406 player_cmd_t cmd; 00407 int ret; 00408 00409 log_print("[player_resume:enter]pid=%d\n", pid); 00410 00411 MEMSET(&cmd, 0, sizeof(player_cmd_t)); 00412 00413 cmd.ctrl_cmd = CMD_RESUME; 00414 00415 ret = player_send_message(pid, &cmd); 00416 log_print("[player_resume:exit]pid=%d ret=%d\n", pid, ret); 00417 00418 return ret; 00419 } 00420 00421 /* --------------------------------------------------------------------------*/ 00435 /* --------------------------------------------------------------------------*/ 00436 int player_loop(int pid) 00437 { 00438 player_cmd_t cmd; 00439 int ret; 00440 00441 log_print("[player_loop:enter]pid=%d\n", pid); 00442 00443 MEMSET(&cmd, 0, sizeof(player_cmd_t)); 00444 00445 cmd.set_mode = CMD_LOOP; 00446 00447 ret = player_send_message(pid, &cmd); 00448 log_print("[player_loop:exit]pid=%d ret=%d\n", pid, ret); 00449 00450 return ret; 00451 } 00452 00453 /* --------------------------------------------------------------------------*/ 00467 /* --------------------------------------------------------------------------*/ 00468 00469 int player_noloop(int pid) 00470 { 00471 player_cmd_t cmd; 00472 int ret; 00473 00474 log_print("[player_loop:enter]pid=%d\n", pid); 00475 00476 MEMSET(&cmd, 0, sizeof(player_cmd_t)); 00477 00478 cmd.set_mode = CMD_NOLOOP; 00479 00480 ret = player_send_message(pid, &cmd); 00481 log_print("[player_loop:exit]pid=%d ret=%d\n", pid, ret); 00482 00483 return ret; 00484 } 00485 00486 /* --------------------------------------------------------------------------*/ 00501 /* --------------------------------------------------------------------------*/ 00502 int player_timesearch(int pid, float s_time) 00503 { 00504 player_cmd_t cmd; 00505 int ret; 00506 log_print("[player_timesearch:enter]pid=%d s_time=%f\n", pid, s_time); 00507 00508 MEMSET(&cmd, 0, sizeof(player_cmd_t)); 00509 00510 cmd.ctrl_cmd = CMD_SEARCH; 00511 cmd.f_param = s_time; 00512 00513 ret = player_send_message(pid, &cmd); 00514 log_print("[player_timesearch:exit]pid=%d ret=%d\n", pid, ret); 00515 00516 return ret; 00517 } 00518 00519 /* --------------------------------------------------------------------------*/ 00534 /* --------------------------------------------------------------------------*/ 00535 int player_forward(int pid, int speed) 00536 { 00537 player_cmd_t cmd; 00538 int ret; 00539 00540 log_print("[player_forward:enter]pid=%d speed=%d\n", pid, speed); 00541 00542 MEMSET(&cmd, 0, sizeof(player_cmd_t)); 00543 00544 cmd.ctrl_cmd = CMD_FF; 00545 cmd.param = speed; 00546 00547 ret = player_send_message(pid, &cmd); 00548 log_print("[player_forward:exit]pid=%d ret=%d\n", pid, ret); 00549 00550 return ret; 00551 } 00552 00553 /* --------------------------------------------------------------------------*/ 00568 /* --------------------------------------------------------------------------*/ 00569 int player_backward(int pid, int speed) 00570 { 00571 player_cmd_t cmd; 00572 int ret; 00573 00574 log_print("[player_backward:enter]pid=%d speed=%d\n", pid, speed); 00575 00576 MEMSET(&cmd, 0, sizeof(player_cmd_t)); 00577 00578 cmd.ctrl_cmd = CMD_FB; 00579 cmd.param = speed; 00580 00581 ret = player_send_message(pid, &cmd); 00582 log_print("[player_backward]cmd=%x param=%d ret=%d\n", cmd.ctrl_cmd, cmd.param, ret); 00583 00584 return ret; 00585 } 00586 00587 /* --------------------------------------------------------------------------*/ 00603 /* --------------------------------------------------------------------------*/ 00604 int player_aid(int pid, int audio_id) 00605 { 00606 player_cmd_t cmd; 00607 int ret; 00608 00609 log_print("[player_aid:enter]pid=%d aid=%d\n", pid, audio_id); 00610 00611 MEMSET(&cmd, 0, sizeof(player_cmd_t)); 00612 00613 cmd.ctrl_cmd = CMD_SWITCH_AID; 00614 cmd.param = audio_id; 00615 00616 ret = player_send_message(pid, &cmd); 00617 log_print("[player_aid:exit]pid=%d ret=%d\n", pid, ret); 00618 00619 return ret; 00620 00621 } 00622 00623 /* --------------------------------------------------------------------------*/ 00639 /* --------------------------------------------------------------------------*/ 00640 int player_sid(int pid, int sub_id) 00641 { 00642 player_cmd_t cmd; 00643 int ret; 00644 00645 log_print("[player_sid:enter]pid=%d sub_id=%d\n", pid, sub_id); 00646 00647 MEMSET(&cmd, 0, sizeof(player_cmd_t)); 00648 00649 cmd.ctrl_cmd = CMD_SWITCH_SID; 00650 cmd.param = sub_id; 00651 00652 ret = player_send_message(pid, &cmd); 00653 log_print("[player_sid:exit]pid=%d sub_id=%d\n", pid, sub_id); 00654 00655 return ret; 00656 00657 } 00658 00659 /* --------------------------------------------------------------------------*/ 00674 /* --------------------------------------------------------------------------*/ 00675 int player_enable_autobuffer(int pid, int enable) 00676 { 00677 player_cmd_t cmd; 00678 int ret; 00679 00680 log_print("[%s:enter]pid=%d enable=%d\n", __FUNCTION__, pid, enable); 00681 00682 MEMSET(&cmd, 0, sizeof(player_cmd_t)); 00683 00684 cmd.set_mode = CMD_EN_AUTOBUF; 00685 cmd.param = enable; 00686 00687 ret = player_send_message(pid, &cmd); 00688 log_print("[%s:exit]pid=%d enable=%d\n", __FUNCTION__, pid, enable); 00689 00690 return ret; 00691 00692 } 00693 00694 /* --------------------------------------------------------------------------*/ 00712 /* --------------------------------------------------------------------------*/ 00713 int player_set_autobuffer_level(int pid, float min, float middle, float max) 00714 { 00715 player_cmd_t cmd; 00716 int ret; 00717 00718 log_print("[%s:enter]pid=%d min=%.3f middle=%.3f max=%.3f\n", __FUNCTION__, pid, min, middle, max); 00719 00720 if (min < middle && middle < max && max < 1) { 00721 MEMSET(&cmd, 0, sizeof(player_cmd_t)); 00722 00723 cmd.set_mode = CMD_SET_AUTOBUF_LEV; 00724 cmd.f_param = min; 00725 cmd.f_param1 = middle; 00726 cmd.f_param2 = max; 00727 00728 ret = player_send_message(pid, &cmd); 00729 } else { 00730 ret = -1; 00731 log_error("[%s]invalid param, please check!\n", __FUNCTION__); 00732 } 00733 log_print("[%s:exit]pid=%d min=%.3f middle=%.3f max=%.3f\n", __FUNCTION__, pid, min, middle, max); 00734 00735 return ret; 00736 00737 } 00738 00739 00740 /* --------------------------------------------------------------------------*/ 00755 /* --------------------------------------------------------------------------*/ 00756 int player_send_message(int pid, player_cmd_t *cmd) 00757 { 00758 player_cmd_t *mycmd; 00759 int r = -1; 00760 play_para_t *player_para; 00761 char buf[512]; 00762 00763 player_para = player_open_pid_data(pid); 00764 if (player_para == NULL) { 00765 return PLAYER_NOT_VALID_PID; 00766 } 00767 00768 if (player_get_state(pid) == PLAYER_EXIT) { 00769 player_close_pid_data(pid); 00770 return PLAYER_SUCCESS; 00771 } 00772 00773 mycmd = message_alloc(); 00774 if (mycmd) { 00775 memcpy(mycmd, cmd, sizeof(*cmd)); 00776 r = send_message_by_pid(pid, mycmd); 00777 if (cmd2str(cmd, buf) != -1) { 00778 log_print("[%s]cmd = %s\n", __FUNCTION__, buf); 00779 } 00780 } else { 00781 r = PLAYER_NOMEM; 00782 } 00783 player_close_pid_data(pid); 00784 return r; 00785 } 00786 00787 /* --------------------------------------------------------------------------*/ 00803 /* --------------------------------------------------------------------------*/ 00804 int player_register_update_callback(callback_t *cb, update_state_fun_t up_fn, int interval_s) 00805 { 00806 int ret; 00807 if (!cb) { 00808 log_error("[player_register_update_callback]empty callback pointer!\n"); 00809 return PLAYER_EMPTY_P; 00810 } 00811 00812 ret = register_update_callback(cb, up_fn, interval_s); 00813 00814 return ret; 00815 } 00816 00817 /* --------------------------------------------------------------------------*/ 00830 /* --------------------------------------------------------------------------*/ 00831 player_status player_get_state(int pid) 00832 { 00833 player_status status; 00834 play_para_t *player_para; 00835 00836 player_para = player_open_pid_data(pid); 00837 if (player_para == NULL) { 00838 return PLAYER_NOT_VALID_PID; 00839 } 00840 00841 status = get_player_state(player_para); 00842 player_close_pid_data(pid); 00843 00844 return status; 00845 } 00846 00847 /* --------------------------------------------------------------------------*/ 00860 /* --------------------------------------------------------------------------*/ 00861 unsigned int player_get_extern_priv(int pid) 00862 { 00863 unsigned long externed; 00864 play_para_t *player_para; 00865 00866 player_para = player_open_pid_data(pid); 00867 if (player_para == NULL) { 00868 return PLAYER_NOT_VALID_PID; /*this data is 0 for default!*/ 00869 } 00870 00871 externed = player_para->extern_priv; 00872 player_close_pid_data(pid); 00873 00874 return externed; 00875 } 00876 00877 00878 /* --------------------------------------------------------------------------*/ 00892 /* --------------------------------------------------------------------------*/ 00893 int player_get_play_info(int pid, player_info_t *info) 00894 { 00895 play_para_t *player_para; 00896 00897 player_para = player_open_pid_data(pid); 00898 if (player_para == NULL) { 00899 return PLAYER_NOT_VALID_PID; /*this data is 0 for default!*/ 00900 } 00901 00902 MEMSET(info, 0, sizeof(player_info_t)); 00903 MEMCPY(info, &player_para->state, sizeof(player_info_t)); 00904 player_close_pid_data(pid); 00905 00906 return PLAYER_SUCCESS; 00907 } 00908 /* --------------------------------------------------------------------------*/ 00920 /* --------------------------------------------------------------------------*/ 00921 int64_t player_get_lpbufbuffedsize(int pid) 00922 { 00923 int64_t buffedsize = -1; 00924 play_para_t *player_para; 00925 00926 player_para = player_open_pid_data(pid); 00927 if (player_para == NULL) { 00928 return PLAYER_NOT_VALID_PID; 00929 } 00930 00931 buffedsize = getlpbuffer_buffedsize(player_para); 00932 player_close_pid_data(pid); 00933 00934 return buffedsize; 00935 } 00936 /* --------------------------------------------------------------------------*/ 00948 /* --------------------------------------------------------------------------*/ 00949 int64_t player_get_streambufbuffedsize(int pid) 00950 { 00951 int64_t buffedsize = -1; 00952 play_para_t *player_para; 00953 00954 player_para = player_open_pid_data(pid); 00955 if (player_para == NULL) { 00956 return PLAYER_NOT_VALID_PID; 00957 } 00958 00959 buffedsize = getstreambuffer_buffedsize(player_para); 00960 player_close_pid_data(pid); 00961 00962 return buffedsize; 00963 } 00964 00965 /* --------------------------------------------------------------------------*/ 00979 /* --------------------------------------------------------------------------*/ 00980 int player_get_media_info(int pid, media_info_t *minfo) 00981 { 00982 play_para_t *player_para; 00983 player_status sta; 00984 00985 while (player_get_state(pid) < PLAYER_INITOK) { 00986 sta = player_get_state(pid); 00987 if (sta == NULL){ 00988 log_error("player_get_media_info failed pid [%d]\n",pid); 00989 return PLAYER_FAILED; 00990 } 00991 if (sta >= PLAYER_ERROR && sta <= PLAYER_EXIT) { 00992 player_close_pid_data(pid); 00993 log_error("player_get_media_info status err [0x%x]\n",sta); 00994 return PLAYER_INVALID_CMD; 00995 } 00996 if ((player_get_state(pid)) == PLAYER_ERROR || 00997 player_get_state(pid) == PLAYER_STOPED || 00998 player_get_state(pid) == PLAYER_PLAYEND || 00999 player_get_state(pid) == PLAYER_EXIT) { 01000 log_error("player_get_media_info failed status [0x%x]\n",sta); 01001 return PLAYER_FAILED; 01002 } 01003 usleep(1000 * 10); 01004 } 01005 01006 player_para = player_open_pid_data(pid); 01007 if (player_para == NULL) { 01008 return PLAYER_NOT_VALID_PID; /*this data is 0 for default!*/ 01009 } 01010 01011 MEMSET(minfo, 0, sizeof(media_info_t)); 01012 MEMCPY(minfo, &player_para->media_info, sizeof(media_info_t)); 01013 01014 log_print("[player_get_media_info]video_num=%d vidx=%d\n", minfo->stream_info.total_video_num, minfo->stream_info.cur_video_index); 01015 player_close_pid_data(pid); 01016 01017 return PLAYER_SUCCESS; 01018 } 01019 01020 /* --------------------------------------------------------------------------*/ 01033 /* --------------------------------------------------------------------------*/ 01034 int player_video_overlay_en(unsigned enable) 01035 { 01036 int fd = open("/dev/graphics/fb0", O_RDWR); 01037 if (fd >= 0) { 01038 unsigned myKeyColor = 0; 01039 unsigned myKeyColor_en = enable; 01040 01041 if (myKeyColor_en) { 01042 myKeyColor = 0xff;/*set another value to solved the bug in kernel..remove later*/ 01043 ioctl(fd, FBIOPUT_OSD_SRCCOLORKEY, &myKeyColor); 01044 myKeyColor = 0; 01045 ioctl(fd, FBIOPUT_OSD_SRCCOLORKEY, &myKeyColor); 01046 ioctl(fd, FBIOPUT_OSD_SRCKEY_ENABLE, &myKeyColor_en); 01047 } else { 01048 ioctl(fd, FBIOPUT_OSD_SRCKEY_ENABLE, &myKeyColor_en); 01049 } 01050 close(fd); 01051 return PLAYER_SUCCESS; 01052 } 01053 return PLAYER_FAILED; 01054 } 01055 01056 /* --------------------------------------------------------------------------*/ 01070 /* --------------------------------------------------------------------------*/ 01071 01072 int audio_set_mute(int pid, int mute_on) 01073 { 01074 01075 int ret = PLAYER_FAILED; 01076 play_para_t *player_para; 01077 codec_para_t *p; 01078 01079 player_para = player_open_pid_data(pid); 01080 if (player_para != NULL) { 01081 player_para->playctrl_info.audio_mute = mute_on & 0x1; 01082 log_print("[audio_set_mute:%d]muteon=%d audio_mute=%d\n", __LINE__, mute_on, player_para->playctrl_info.audio_mute); 01083 01084 p = get_audio_codec(player_para); 01085 if (p != NULL) { 01086 ret = codec_set_mute(p, mute_on); 01087 } 01088 player_close_pid_data(pid); 01089 } else { 01090 ret = codec_set_mute(NULL, mute_on); 01091 } 01092 01093 return ret; 01094 } 01095 01096 /* --------------------------------------------------------------------------*/ 01111 /* --------------------------------------------------------------------------*/ 01112 int audio_get_volume_range(int pid, float *min, float *max) 01113 { 01114 return codec_get_volume_range(NULL, min, max); 01115 } 01116 01117 /* --------------------------------------------------------------------------*/ 01131 /* --------------------------------------------------------------------------*/ 01132 int audio_set_volume(int pid, float val) 01133 { 01134 return codec_set_volume(NULL, val); 01135 } 01136 01137 /* --------------------------------------------------------------------------*/ 01149 /* --------------------------------------------------------------------------*/ 01150 int audio_get_volume(int pid, float *vol) 01151 { 01152 int r; 01153 01154 r = codec_get_volume(NULL, vol); 01155 log_print("[audio_get_volume:%d]r=%d\n", __LINE__, r); 01156 01157 return r;//codec_get_volume(NULL); 01158 } 01159 01160 /* --------------------------------------------------------------------------*/ 01175 /* --------------------------------------------------------------------------*/ 01176 int audio_set_lrvolume(int pid, float lvol, float rvol) 01177 { 01178 play_para_t *player_para; 01179 log_print("[audio_set_lrvolume:enter]pid=%d\n", pid); 01180 player_para = player_open_pid_data(pid); 01181 if(player_para == NULL){ 01182 log_print("player ID is NULL!\n"); 01183 return -1; 01184 } 01185 if(player_para->acodec == NULL){ 01186 log_print("codec is not ready!\n"); 01187 return -1; 01188 } 01189 return codec_set_lrvolume(player_para->acodec, lvol, rvol); 01190 } 01191 01192 /* --------------------------------------------------------------------------*/ 01204 /* --------------------------------------------------------------------------*/ 01205 int audio_get_lrvolume(int pid, float *lvol, float* rvol) 01206 { 01207 int r; 01208 01209 r = codec_get_lrvolume(NULL, lvol, rvol); 01210 log_print("[audio_get_volume:%d]r=%d\n", __LINE__, r); 01211 01212 return r;//codec_get_volume(NULL); 01213 } 01214 01215 01216 01217 /* --------------------------------------------------------------------------*/ 01231 /* --------------------------------------------------------------------------*/ 01232 int audio_set_volume_balance(int pid, int balance) 01233 { 01234 return codec_set_volume_balance(NULL, balance); 01235 } 01236 01237 /* --------------------------------------------------------------------------*/ 01250 /* --------------------------------------------------------------------------*/ 01251 int audio_swap_left_right(int pid) 01252 { 01253 return codec_swap_left_right(NULL); 01254 } 01255 01256 /* --------------------------------------------------------------------------*/ 01268 /* --------------------------------------------------------------------------*/ 01269 01270 int audio_left_mono(int pid) 01271 { 01272 int ret = -1; 01273 play_para_t *player_para; 01274 codec_para_t *p; 01275 01276 player_para = player_open_pid_data(pid); 01277 if (player_para == NULL) { 01278 return 0; /*this data is 0 for default!*/ 01279 } 01280 01281 p = get_audio_codec(player_para); 01282 if (p != NULL) { 01283 ret = codec_left_mono(p); 01284 } 01285 player_close_pid_data(pid); 01286 01287 return ret; 01288 } 01289 01290 /* --------------------------------------------------------------------------*/ 01302 /* --------------------------------------------------------------------------*/ 01303 int audio_right_mono(int pid) 01304 { 01305 int ret = -1; 01306 play_para_t *player_para; 01307 codec_para_t *p; 01308 01309 player_para = player_open_pid_data(pid); 01310 if (player_para == NULL) { 01311 return 0; /*this data is 0 for default!*/ 01312 } 01313 01314 p = get_audio_codec(player_para); 01315 if (p != NULL) { 01316 ret = codec_right_mono(p); 01317 } 01318 player_close_pid_data(pid); 01319 01320 return ret; 01321 } 01322 01323 /* --------------------------------------------------------------------------*/ 01335 /* --------------------------------------------------------------------------*/ 01336 int audio_stereo(int pid) 01337 { 01338 int ret = -1; 01339 play_para_t *player_para; 01340 codec_para_t *p; 01341 01342 player_para = player_open_pid_data(pid); 01343 if (player_para == NULL) { 01344 return 0; /*this data is 0 for default!*/ 01345 } 01346 01347 p = get_audio_codec(player_para); 01348 if (p != NULL) { 01349 ret = codec_stereo(p); 01350 } 01351 player_close_pid_data(pid); 01352 01353 return ret; 01354 } 01355 01356 /* --------------------------------------------------------------------------*/ 01367 /* --------------------------------------------------------------------------*/ 01368 int audio_lr_mix_set(int pid,int enable) 01369 { 01370 int ret = -1; 01371 play_para_t *player_para; 01372 codec_para_t *p; 01373 player_para = player_open_pid_data(pid); 01374 if (player_para == NULL) { 01375 log_print("[%s %d] player_para==NULL,set fail audio_lr_mix!!",__FUNCTION__,__LINE__); 01376 return -1; /*this data is 0 for default!*/ 01377 } 01378 p = get_audio_codec(player_para); 01379 if (p != NULL) { 01380 ret = codec_lr_mix_set(p,enable); 01381 }else{ 01382 log_print("[%s %d] p==NULL,set fail audio_lr_mix!!",__FUNCTION__,__LINE__); 01383 } 01384 player_close_pid_data(pid); 01385 return ret; 01386 } 01387 01388 int audio_cur_pcmpara_Applied_get(int pid,int *pfs,int *pch) 01389 { 01390 int ret = -1; 01391 play_para_t *player_para; 01392 codec_para_t *p; 01393 player_para = player_open_pid_data(pid); 01394 if (player_para == NULL) { 01395 log_print("[%s %d] player_para==NULL,set fail audio_FsNch_get!!",__FUNCTION__,__LINE__); 01396 return -1; /*this data is 0 for default!*/ 01397 } 01398 p = get_audio_codec(player_para); 01399 if (p != NULL) { 01400 ret = codec_pcmpara_Applied_get(p,pfs,pch); 01401 }else{ 01402 log_print("[%s %d] p==NULL,set fail audio_FsNch_get!!",__FUNCTION__,__LINE__); 01403 } 01404 player_close_pid_data(pid); 01405 return ret; 01406 } 01407 01408 01409 /* --------------------------------------------------------------------------*/ 01423 /* --------------------------------------------------------------------------*/ 01424 int audio_set_spectrum_switch(int pid, int isStart, int interval) 01425 { 01426 int ret = -1; 01427 play_para_t *player_para; 01428 codec_para_t *p; 01429 01430 player_para = player_open_pid_data(pid); 01431 if (player_para == NULL) { 01432 return 0; /*this data is 0 for default!*/ 01433 } 01434 01435 p = get_audio_codec(player_para); 01436 if (p != NULL) { 01437 ret = codec_audio_spectrum_switch(p, isStart, interval); 01438 } 01439 player_close_pid_data(pid); 01440 01441 return ret; 01442 } 01443 01444 /* --------------------------------------------------------------------------*/ 01454 /* --------------------------------------------------------------------------*/ 01455 int player_progress_exit(void) 01456 { 01457 codec_close_audio(NULL); 01458 01459 return 0; 01460 } 01461 01462 /* --------------------------------------------------------------------------*/ 01475 /* --------------------------------------------------------------------------*/ 01476 01477 int player_list_allpid(pid_info_t *pid) 01478 { 01479 char buf[MAX_PLAYER_THREADS]; 01480 int pnum = 0; 01481 int i; 01482 01483 pnum = player_list_pid(buf, MAX_PLAYER_THREADS); 01484 pid->num = pnum; 01485 01486 for (i = 0; i < pnum; i++) { 01487 pid->pid[i] = buf[i]; 01488 } 01489 01490 return 0; 01491 } 01492 01493 /* --------------------------------------------------------------------------*/ 01508 /* --------------------------------------------------------------------------*/ 01509 01510 01511 int player_cache_system_init(int enable, const char*dir, int max_size, int block_size) 01512 { 01513 return cache_system_init(enable, dir, max_size, block_size); 01514 } 01515 01516 /* --------------------------------------------------------------------------*/ 01528 /* --------------------------------------------------------------------------*/ 01529 char *player_status2str(player_status status) 01530 { 01531 switch (status) { 01532 case PLAYER_INITING: 01533 return "BEGIN_INIT"; 01534 01535 case PLAYER_TYPE_REDY: 01536 return "TYPE_READY"; 01537 01538 case PLAYER_INITOK: 01539 return "INIT_OK"; 01540 01541 case PLAYER_RUNNING: 01542 return "PLAYING"; 01543 01544 case PLAYER_BUFFERING: 01545 return "BUFFERING"; 01546 01547 case PLAYER_BUFFER_OK: 01548 return "BUFFEROK"; 01549 01550 case PLAYER_PAUSE: 01551 return "PAUSE"; 01552 01553 case PLAYER_SEARCHING: 01554 return "SEARCH_FFFB"; 01555 01556 case PLAYER_SEARCHOK: 01557 return "SEARCH_OK"; 01558 01559 case PLAYER_START: 01560 return "START_PLAY"; 01561 01562 case PLAYER_FF_END: 01563 return "FF_END"; 01564 01565 case PLAYER_FB_END: 01566 return "FB_END"; 01567 01568 case PLAYER_ERROR: 01569 return "ERROR"; 01570 01571 case PLAYER_PLAYEND: 01572 return "PLAY_END"; 01573 01574 case PLAYER_STOPED: 01575 return "STOPED"; 01576 01577 case PLAYER_EXIT: 01578 return "EXIT"; 01579 01580 case PLAYER_PLAY_NEXT: 01581 return "PLAY_NEXT"; 01582 01583 case PLAYER_FOUND_SUB: 01584 return "NEW_SUB"; 01585 01586 case PLAYER_DIVX_AUTHORERR: 01587 return "DIVX_AUTHORERR"; 01588 case PLAYER_DIVX_RENTAL_VIEW: 01589 return "DIVX_RENTAL"; 01590 case PLAYER_DIVX_RENTAL_EXPIRED: 01591 return "DIVX_EXPIRED"; 01592 default: 01593 return "UNKNOW_STATE"; 01594 } 01595 } 01596 01597 static char* player_vformat2str(vformat_t value) 01598 { 01599 switch(value) { 01600 case VFORMAT_MPEG12: 01601 return "VFORMAT_MPEG12"; 01602 01603 case VFORMAT_MPEG4: 01604 return "VFORMAT_MPEG4"; 01605 01606 case VFORMAT_H264: 01607 return "VFORMAT_H264"; 01608 01609 case VFORMAT_HEVC: 01610 return "VFORMAT_HEVC"; 01611 01612 case VFORMAT_MJPEG: 01613 return "VFORMAT_MJPEG"; 01614 01615 case VFORMAT_REAL: 01616 return "VFORMAT_REAL"; 01617 01618 case VFORMAT_JPEG: 01619 return "VFORMAT_JPEG"; 01620 01621 case VFORMAT_VC1: 01622 return "VFORMAT_VC1"; 01623 01624 case VFORMAT_AVS: 01625 return "VFORMAT_AVS"; 01626 01627 case VFORMAT_SW: 01628 return "VFORMAT_SW"; 01629 01630 case VFORMAT_H264MVC: 01631 return "VFORMAT_H264MVC"; 01632 01633 case VFORMAT_H264_4K2K: 01634 return "VFORMAT_H264_4K2K"; 01635 01636 default: 01637 return "NOT_SUPPORT VFORMAT"; 01638 } 01639 return NULL; 01640 } 01641 01642 static char* player_aformat2str(aformat_t value) 01643 { 01644 switch(value) { 01645 case AFORMAT_MPEG: 01646 return "AFORMAT_MPEG"; 01647 01648 case AFORMAT_PCM_S16LE: 01649 return "AFORMAT_PCM_S16LE"; 01650 01651 case AFORMAT_AAC: 01652 return "AFORMAT_AAC"; 01653 01654 case AFORMAT_AC3: 01655 return "AFORMAT_AC3"; 01656 01657 case AFORMAT_ALAW: 01658 return "AFORMAT_ALAW"; 01659 01660 case AFORMAT_MULAW: 01661 return "AFORMAT_MULAW"; 01662 01663 case AFORMAT_DTS: 01664 return "AFORMAT_DTS"; 01665 01666 case AFORMAT_PCM_S16BE: 01667 return "AFORMAT_PCM_S16BE"; 01668 01669 case AFORMAT_FLAC: 01670 return "AFORMAT_FLAC"; 01671 01672 case AFORMAT_COOK: 01673 return "AFORMAT_COOK"; 01674 01675 case AFORMAT_PCM_U8: 01676 return "AFORMAT_PCM_U8"; 01677 01678 case AFORMAT_ADPCM: 01679 return "AFORMAT_ADPCM"; 01680 01681 case AFORMAT_AMR: 01682 return "AFORMAT_AMR"; 01683 01684 case AFORMAT_RAAC: 01685 return "AFORMAT_RAAC"; 01686 01687 case AFORMAT_WMA: 01688 return "AFORMAT_WMA"; 01689 01690 case AFORMAT_WMAPRO: 01691 return "AFORMAT_WMAPRO"; 01692 01693 case AFORMAT_PCM_BLURAY: 01694 return "AFORMAT_PCM_BLURAY"; 01695 01696 case AFORMAT_ALAC: 01697 return "AFORMAT_ALAC"; 01698 01699 case AFORMAT_VORBIS: 01700 return "AFORMAT_VORBIS"; 01701 01702 case AFORMAT_AAC_LATM: 01703 return "AFORMAT_AAC_LATM"; 01704 01705 case AFORMAT_APE: 01706 return "AFORMAT_APE"; 01707 01708 case AFORMAT_EAC3: 01709 return "AFORMAT_EAC3"; 01710 case AFORMAT_TRUEHD: 01711 return "AFORMAT_TRUEHD"; 01712 default: 01713 return "NOT_SUPPORT AFORMAT"; 01714 } 01715 return NULL; 01716 } 01717 /* --------------------------------------------------------------------------*/ 01733 /* --------------------------------------------------------------------------*/ 01734 char *player_value2str(char *key, int value) 01735 { 01736 if(strcasecmp(key, "status") == 0) 01737 return player_status2str((player_status)value); 01738 else if(strcasecmp(key, "vformat") == 0) 01739 return player_vformat2str((vformat_t)value); 01740 else if(strcasecmp(key, "aformat") == 0) 01741 return player_aformat2str((aformat_t)value); 01742 else 01743 return ("INVALID KEYWORDS"); 01744 } 01745 01746 int audio_get_decoder_enable(int pid) 01747 { 01748 01749 int ret = -1; 01750 play_para_t *player_para; 01751 codec_para_t *p; 01752 01753 player_para = player_open_pid_data(pid); 01754 if (player_para == NULL) { 01755 return -1; /*this data is 0 for default!*/ 01756 } 01757 p = get_audio_codec(player_para); 01758 if (p != NULL) { 01759 ret = codec_get_decoder_enable(p); 01760 } 01761 player_close_pid_data(pid); 01762 01763 return ret; 01764 }
Generated on Tue Dec 2 2014 21:55:13 for amplayerMy Project by
![doxygen](doxygen.png)