📄 player.c
字号:
#include "pcdeb.h"#endif#if (0 != IPOD_AP) //[LL]new#include "ACP.h" //[LL]new#include "iAP.h" //[LL]new#endif /*IPOD_AP*/ //[LL]new#include "controller.h"#include "debug.h"#include "plyext.h"#include "plr_conf.h"#include "xfile.h"#include "cddevice.h"#include "usb.h" //[LL]#include "player.h"#if (0 != HAVE_SDC)#include "sdc.h"#endif /* HAVE_SDC */#if (0 != HAVE_UPDATE)#include "utility.h"#endif#if (0 != HAVE_HOST_UPDATE) || (0 != HAVE_HOST_UPDATE_NEW)#include "framebuffer.h"#endif#include "hostif_low.h"#include "hostif_high.h"#include "tmr1reg.h" //for RndNextSeed init val#include "filesys.h"#if (1 == HAVE_WMDRM)#include "WMDRM_Receiver.h"#endif#if (0 != IPOD_AP) #include "ipodvirt.h"#endif//debugging messages to term//#define PLAYER_DEBUG//define for case, that audio is understood as directory#define AUDIO_AS_DIRECTORY #define PAUSE_AT_RANGE_MARGIN_FIX#define STOP_ON_ERROR#define ERROR (RETVAL) 0x0F//global player modes vars uint8 power_mode;uint8 loader_mode;uint8 loader_mode_attribute;uint8 loader_transition_state;uint8 player_mode;uint8 player_transition_state;#if (0 != HAVE_POSITION) || (0 != HAVE_UPDATE)uint32 update_status;#endif /* HAVE_UPDATE *///playlist functionality#include "playlist.h" #include "utf8.h" extern uint16 playlist_partial_dim; extern int16 song_num;extern uint8 filesys_sectbuf[];uint16 x_pls_index, n_mp3;uint8 *filesys_sectbuf_ptr;int8 pls_read_time=-1, pls_step=0;uint16 delta=0;uint16 is_wide;#if (IPOD_AP != 0)//ipod functionality - moved from iap.hextern t_iap_msg IPod_Message;extern t_iap_msg *pIPod_Message;extern uint8* pIPodMessageData;#endif/********************************//* Local variables declarations *//********************************/#if (0 != IPOD_AP) //[LL]new//iap handlert_iap_handler hIap = NULL;#endif /*IPOD_AP*/ //[LL]new//loader vars#if (HAVE_CD_MECHA == 1)static uint8 process_state;static t_loader_cmd_event loader_cmd_event;static t_loader_status_event loader_status;static uint8 loader_retries;#endifstatic t_bool hw_eject_requested;static t_bool unplayable_disc;//player state machines varst_player_mount_fsm_params player_mount_params;t_player_player_play_fsm_params player_play_fsm_params; t_player_pause_fsm_params player_pause_fsm_params;t_player_parse_playlist_fsm_params player_parse_playlist_fsm_params; t_player_read_file_fsm_params player_read_file_fsm_params;//player state machinest_fsm player_play_fsm;t_fsm player_pause_fsm;t_fsm player_stop_fsm;t_fsm player_mount_fsm;t_fsm player_parse_playlist_fsm;t_fsm player_read_file_fsm;#if (0 != IPOD_AP) //[LL]newt_fsm player_ipod_active_fsm; //[LL]newt_fsm ipod_library_init_fsm;#endif /*IPOD_AP*/ //[LL]new//song nr. varst_XItem player_song = 0; //actually played song t_XItem player_prepared_song = 0; //song requested to be prebuffered//continue song index - arrives with cmdContinue, not selected by song_selection_algorithmt_XItem player_continue_song = 0;//song index coming with playback commadt_XItem player_requested_song = 0;t_player_song_time player_requested_song_start_time = 0;// resume song information - will be stored inside NVRAM at cmd power off// to differ audio/data used AUDIO_TRACKS_OFFSETt_player_resume_info player_resume_info[DEV_SLOTS];t_bool player_current_resume_info_available;//global player paramst_player_params player_params = {0,DEV_CD_ID,DT_NO_DISC,RANGE_DEVICE,REPEAT_ON,SHUFFLE_OFF,0,0,0,0,0,b_FALSE,b_FALSE,b_TRUE, b_FALSE, b_FALSE}; //additional params for song selectiont_bool shuffle_random_navigation = b_FALSE;t_direction player_direction = FORWARD;t_range_margin player_at_range_margin = INSIDE_RANGE;t_dir_num_style player_dir_numbering = PATH_TABLE; //by defaultt_player_time_info player_q_subcode; //time event to hostt_bool player_report_time_to_host = b_FALSE;t_bool player_EOP = b_FALSE;t_bool player_EOS = b_FALSE;uint8 player_debug_to_hostif[2];//func prototypesvoid process_preevents(void);void transition_handler(void);void process_postevents(void);int get_playlist_config(void);uint32 rndNextSeed = 1; //JS, need to be changed to take first value from timer (otherwise it generates same seq of indexes//scan paramst_player_scan_params player_scan = {0, FORWARD, 0, 0};//pause modet_bool player_pause = b_FALSE;//seek paramst_player_seek player_seek = {b_FALSE, FORWARD, 4, SEEK_PLAY_TIME_MIN * 588 * 10 , 0, 0}; //588 = 44100/75 equals to 1 frame of data on CD //configuration paramsMEDIA_INFO_SETTING_UNION player_MediaInforSetting; AUDIO_FORMAT_CFG_UNION player_audio_format_cfg; //uint32 debug_flag = 0; //JS debugging/* only for debugging */#ifdef PLAYER_DEBUG OSAL_EVENT_ID_t event_table[OSAL_MAX_EVENT]; #endif// OS20 stuffvoid PlayerTask(void *unused);/* NOTES: ----- hostif to player - first is called process_cmd (similar to controller_cmd - check conditions, if necessary set command) in Player - process_new_command in preevents processing changes internal mode and transition status is used to signal to hostif, that new message in msgfifo is prepared*/void PlayerTask(void *unused){#ifdef PLAYER_DEBUG OSAL_EVENT_ID_t i; for (i=0;i<OSAL_MAX_EVENT;i++) event_table[i] = i;#endif XAR_InsertSafeIndex(&player_song); while(1) { OSAL_wait_thread(OSAL_THREAD_PlayerTask); event_disable_scheduling(); event_in_shedule(PLAYER_CMD_EVENT);#if ((0!=IPOD_PASSTHROUGH) && (0 != IPOD_AP)) event_in_shedule(PLAYER_DOWNSTREAM_CMD_EVENT); event_in_shedule(PLAYER_UPSTREAM_CMD_EVENT);#endif /* ((0!=IPOD_PASSTHROUGH) && (0 != IPOD_AP)) */ event_in_shedule(HW_EJECT_EVENT); event_in_shedule(LOADER_STATUS_EVENT); event_in_shedule(CONTROLLER_STATUS_EVENT); event_in_shedule(CONTROLLER_PRE_EOS_STATUS_EVENT); event_in_shedule(CONTROLLER_EOS_STATUS_EVENT);#if (0 != HAVE_USB) event_in_shedule(CONTROLLER_USB_STATUS_EVENT);#if (0 != IPOD_AP) event_in_shedule(USB_UPSTREAM_STATUS_EVENT); //[LL]new event_in_shedule(USB_DOWNSTREAM_STATUS_EVENT); //[LL]new event_in_shedule(ACP_STATUS_EVENT); //[LL]new#endif /* IPOD_AP */ //[LL]new#endif /* HAVE_USB */ event_in_shedule(CONTROLLER_TIME_STATUS_EVENT);#if (0 != HAVE_SDC) event_in_shedule(CONTROLLER_SDC_STATUS_EVENT);#endif /* HAVE_SDC */ event_enable_scheduling(); process_preevents(); transition_handler(); process_postevents(); event_disable_scheduling(); event_in_clear(PLAYER_CMD_EVENT);#if ((0!=IPOD_PASSTHROUGH) && (0 != IPOD_AP)) event_in_clear(PLAYER_DOWNSTREAM_CMD_EVENT); event_in_clear(PLAYER_UPSTREAM_CMD_EVENT);#endif /* ((0!=IPOD_PASSTHROUGH) && (0 != IPOD_AP)) */ event_in_clear(HW_EJECT_EVENT); event_in_clear(LOADER_STATUS_EVENT); event_in_clear(CONTROLLER_STATUS_EVENT); event_in_clear(CONTROLLER_PRE_EOS_STATUS_EVENT); event_in_clear(CONTROLLER_EOS_STATUS_EVENT);#if (0 != HAVE_USB) event_in_clear(CONTROLLER_USB_STATUS_EVENT);#if (0 != IPOD_AP) //[LL]new event_in_clear(USB_UPSTREAM_STATUS_EVENT); //[LL]new event_in_clear(USB_DOWNSTREAM_STATUS_EVENT); //[LL]new event_in_clear(ACP_STATUS_EVENT); //[LL]new#endif /* IPOD_AP */ #endif /* HAVE_USB */ event_in_clear(CONTROLLER_TIME_STATUS_EVENT);#if (0 != HAVE_SDC) event_in_clear(CONTROLLER_SDC_STATUS_EVENT);#endif /* HAVE_SDC */ event_cmd_shedule(); event_enable_scheduling(); } } #if 0 // unused/******************************************************************************//* Function: IsIndexInPlaylist *//* *//*! \brief * \param * \return * \remark *//******************************************************************************/t_bool IsIndexInPlaylist (t_XItem index, t_player_playlist * playlist){ #if 0 uint16 count; //finds if player_song is contained inside playlist array for (count = 0; count < playlist->array_items; count++) { if (index == playlist->array[count]) { return b_TRUE; } } return b_FALSE;//new implementation - check only current playlist position with current songif (index == playlist->array[playlist->array_index]) return b_TRUE;else return b_FALSE;#endif return b_TRUE;}#endif/******************************************************************************//* Function: rand *//* *//*! \brief Generates random number in range 0 - maxLimit * \param uint16 maxLimit * \return uint16 * \remark *//******************************************************************************/uint32 Random(uint32 *NextSeed, uint16 maxLimit){uint32 a; /* JS fix 10.10.2007 increase probability for hitting result = maxLimit, more random nr. using timer */#if 1 maxLimit +=1; *NextSeed += (TIM1_CNTR + OSAL_time_get()) & 0xFFFF;#endif *NextSeed = *NextSeed * 1103515245 + 12345; a = maxLimit * (1+(*NextSeed - (*NextSeed/maxLimit) * maxLimit))/(maxLimit+1); if(a>maxLimit+1) a=maxLimit; return a;}/******************************************************************************//* Function: player_select_playlist *//* *//*! \brief selects proper playlist depending on direction or playlist_nr param playlist_nr has higher priority before direcion * \param t_direction direction, uint16 playlist_nr * \return t_bool b_TRUE if params set correctly * \remark *//******************************************************************************/t_bool player_playlist_select(t_direction direction, uint16 playlist_nr){ uint32 saved_playlist_nr = player_playlist.fileNr; uint32 playlist_count = CountFilesForDevice(player_params.device, b_FALSE, SEARCH_PLAYLISTS); if (!playlist_nr) { //select by direction switch (direction) { case BACKWARD: if (player_playlist.fileNr > 1) { player_playlist.fileNr--; break; } else if (player_params.repeat == REPEAT_ON) { player_playlist.fileNr = playlist_count; break; } else return b_FALSE; case FORWARD: default: if (player_playlist.fileNr < playlist_count) { player_playlist.fileNr++; break; } else if (player_params.repeat == REPEAT_ON) { player_playlist.fileNr = 1; break; } else return b_FALSE; } } //select playlist nr. by param else { if (playlist_nr <= CountFilesForDevice(player_params.device, b_FALSE, SEARCH_PLAYLISTS)) player_playlist.fileNr = playlist_nr;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -