/* * Copyright (c) Hisilicon Technologies Co., Ltd. 2012-2019. All rights reserved. * Description: Defines drive sync interface * Author: Hisilicon * Create: 2012-12-22 * History: */ #ifndef __DRV_SYNC_H__ #define __DRV_SYNC_H__ #include "linux/huanglong/securec.h" #include "osal_ext.h" #include "drv_ioctl_sync.h" #ifdef __cplusplus #if __cplusplus extern "C" { #endif #endif #define PTS_JUMP_NUM_MAX 11 #define PTS_JUMP_STEP 1 #define sync_abs(x) abs(x) typedef td_s32 (*sync_manage_fn)(td_handle *sync); typedef enum { SYNC_DBG_INFO_SYS_INIT, SYNC_DBG_INFO_SYS_DEINIT, SYNC_DBG_INFO_LIST_INITIAL, SYNC_DBG_INFO_LIST_SIZE, SYNC_DBG_INFO_LIST_RELEASE, SYNC_DBG_INFO_LIST_VIDADD, SYNC_DBG_INFO_MAX } sync_dbg_info_mode; typedef enum { SYNC_PCR_ADJUST_SCR, SYNC_AUD_ADJUST_SCR, SYNC_SCR_ADJUST_MAX } sync_pcr_adjust_type; typedef struct { td_s32 sum; /* ppm sum */ td_s32 num; /* ppm number */ td_s32 valid; /* ppm valid = ppm sum / ppm num */ } sync_ppm_info; typedef struct { td_u64 stc_last_val; /* last stc value 27M */ td_u32 stc_last; /* last stc value ms */ td_s32 stc_delta_sum; /* stc delta sum value */ td_bool is_stc_adjust_fail; td_bool is_stc_adjust_init; } sync_stc_info; typedef struct { td_bool is_pcr_first_come; /* arrive flag of the first pcr */ td_bool is_pcr_aud_sync_ok; td_bool is_pcr_vid_sync_ok; td_bool is_pcr_adjust_delta_ok; td_u32 pcr_first_sys_time; /* arrive time of the first pcr */ td_u32 pcr_first; /* first pcr value */ td_u32 pcr_last; /* last pcr value ms */ td_u32 pcr_last_valid; td_bool is_pcr_valid; td_u32 pcr_last_sys_time; /* last system time of setting pcr localtime */ td_u32 pcr_last_local_time; /* last pcr localtime */ td_u32 pcr_pause_local_time; /* pcr localtime when pause */ td_u32 pcr_series_cnt; /* pcr successive count */ td_u32 pcr_lead_series_cnt; td_u32 pcr_lag_series_cnt; td_u32 pcr_abnormal_series_cnt; td_u32 pcr_sync_start_sys_time; /* start time of pcr synchronization,set when sync start */ td_bool is_pcr_local_time; /* valid flag of pcr localtime */ td_bool is_pcr_adjust_delta; sync_pcr_adjust_type pcr_adjust_type; /* which way to adjust scr */ td_s32 pcr_delta; /* adjust pcr value */ td_s32 aud_pcr_diff; /* difference value between audio localtime and pcr localtime */ td_s32 vid_pcr_diff; /* difference value between video localtime and pcr localtime */ td_s32 last_vid_pcr_diff; td_s32 last_aud_pcr_diff; td_bool is_pcr_loop_rewind; td_u32 pcr_gradient; /* gradient of pcr and system time(* 100) */ sync_ppm_info ppm_info; /* PPM calculate */ sync_stc_info stc_info; td_s32 pcr_delta_sum; td_s32 pcr_delta_num; td_u64 pcr_last_val; /* last pcr value */ td_bool is_stc_adjust_refer; } sync_pcr_info; typedef struct { td_bool is_not_sync; td_u32 not_sync_start_time; td_u32 sync_pre_vdec_pts; td_u32 sync_pre_adec_pts; td_u32 sync_pre_system_time; td_bool is_not_sync_report; td_bool is_vdec_slow; td_bool is_adec_slow; td_bool is_deq_vdec_frame_err; td_bool is_deq_vdec_frame_report; td_bool is_deq_adec_frame_report; td_bool is_presync_status_checked; td_bool is_abandon_sync_report; td_bool is_pts_normal_loop_report; td_bool disp_pts_check_status; td_u32 disp_pts_check_start_time; td_bool is_disp_pts_err_report; td_bool is_pcr_pts_err_report; td_u32 pcr_pts_check_start_time; td_bool pcr_pts_check_status; } sync_fc_info_status; /* sync region status enum */ typedef enum { SYNC_REGION_STAT_IN_STOP, SYNC_REGION_STAT_IN_START, SYNC_REGION_STAT_IN_NOVEL, SYNC_REGION_STAT_IN_DISCARD, SYNC_REGION_STAT_OUT_DISCARD, SYNC_REGION_STAT_MAX } sync_region_stat_mode; typedef struct { td_u32 aud_src_pts; td_u32 aud_pts; td_u32 aud_local_time; td_u32 aud_buf_time; td_u32 aud_frame_time; td_u32 vid_src_pts; td_u32 vid_pts; td_u32 vid_local_time; td_u32 vid_delay_time; td_u32 vid_frame_time; td_u32 vid_aud_diff; td_u32 disp_time; td_u32 pcr_last; td_u32 pcr_local_time; td_u32 pcr_delta_time; td_u32 vid_pcr_diff; td_u32 aud_pcr_diff; td_u32 system_time; td_u32 idx; sync_proc_mode proc_type; struct list_head list; } sync_dbg_info_status; typedef struct { td_s64 jump_diff[PTS_JUMP_NUM_MAX]; td_u32 front; td_u32 rear; } pts_jump_diff; typedef struct { td_handle handle; sync_attr attr; /* sync attributes set by user */ td_bool is_vid_enable; /* video enable flag, set when start video */ td_bool is_aud_enable; /* audio enable flag, set when start audio */ td_bool is_ddp_mode; /* for DDP test only */ /* AV common information. reset only when both of av are stoped */ sync_status cur_status; /* current status */ sync_buf_status cur_buf_status; /* current buf status */ sync_event_info evt; td_u32 loop_rewind_time; td_bool is_loop_rewind; td_u32 vid_first_dec_pts; td_u32 vid_second_dec_pts; td_u32 presync_start_sys_time; /* start time of presynchronization,set when presync start */ td_u32 presync_end_sys_time; /* end time of presynchronization,set when presync end */ td_bool is_presync_finish; /* finish flag of presynchronization */ td_bool is_first_frame_disp_check_finish; sync_chan_type presync_target; /* presynchronization target */ td_u32 presync_target_time; /* target time of presynchronization */ td_bool is_presync_target_init; /* initialize flag of presynchronization target */ td_bool is_buf_fund_finish; /* finish flag of audio and video data cumulation */ td_u32 buf_fund_end_sys_time; /* end time of audio and video data cumulation */ td_u32 ext_presync_target_time; td_bool is_use_ext_presync_target; sync_pcr_info pcr_sync_info; /* some information while sync reference set IAPI_SYNC_REF_MODE_PCR */ /* video statistics, reset when stop */ td_bool is_vid_first_come; /* arrive flag of the first video frame */ td_u32 vid_first_sys_time; /* arrive time of the first video frame */ td_u32 vid_first_pts; /* PTS of the first video frame */ td_bool is_vid_fist_valid_pts_come; td_u32 vid_first_valid_pts; td_bool is_vid_first_valid_src_pts_come; td_u32 vid_first_valid_src_pts; td_u32 vid_last_pts; /* PTS of the last video frame */ td_u32 vid_disp_pts; td_u32 vid_last_src_pts; td_u32 vid_last_valid_pts; td_bool is_vid_presync_target_init; /* initialize flag of video presync target */ td_u32 vid_presync_target_time; /* video presync target time */ td_bool is_vid_local_time; /* valid flag of video localtime */ td_u32 vid_last_sys_time; /* last system time of setting video localtime */ td_u32 vid_last_local_time; /* last video localtime */ td_u32 vid_start_sys_time; /* start system time of setting video localtime */ td_u32 vid_start_local_time; /* start video localtime */ td_u32 vid_pause_local_time; /* video localtime when pause */ td_u32 vid_pts_series_cnt; /* video pts successive count */ td_bool is_vid_sync_adjust; /* adjust flag */ td_u32 vid_discard_play_cnt; /* video play count when discard */ td_u32 vid_discard_cnt; /* video discard count */ td_u32 vid_repeat_play_cnt; /* video play count when repeat */ td_u32 vid_repeat_cnt; /* video repeat count */ sync_vid_info vid_info; /* video channel information,set by vo and used by sync */ sync_vid_opt vid_opt; /* video adjust mode,set by sync */ td_bool is_vid_first_play; /* played flag of the first video frame */ td_u32 vid_first_play_time; /* time of playing the first video frame */ td_bool is_vid_normal_play; td_s32 vid_aud_diff; /* difference value between video localtime and audio localtime */ td_s32 last_vid_aud_diff; td_bool is_vid_pts_loop_rewind; td_bool is_vid_pts_normal_loop; td_bool one_more_frame; sync_vid_info last_vid_info; /* used in valid pts jump */ td_bool checking_valid_pts_jump; /* is checking pts jump */ td_bool vid_local_time_update_flag; /* vid local time update flag. 0: update by vo, 1:update by sync record local time */ td_bool is_proc_valid_pts_jump; /* whether process valid pts jump and enable by default */ td_u32 vid_speed; /* video playback speed */ /* audio statistics,reset when stop */ td_bool is_aud_first_come; /* arrive flag of the first audio frame */ td_u32 aud_first_sys_time; /* arrive time of the first audio frame */ td_u32 aud_first_pts; /* pts of the first audio frame */ td_bool is_aud_first_valid_come; td_u32 aud_first_valid_pts; td_u32 aud_last_pts; /* pts of the last audio frame */ td_u32 aud_last_src_pts; td_u32 aud_last_valid_pts; td_u32 aud_last_buf_time; /* buftime value when last audio pts arrived */ td_bool is_aud_presync_target_init; /* initialize flag of audio presync target */ td_u32 aud_presync_target_time; /* audio presync target time */ td_bool is_aud_local_time; /* valid flag of audio localtime */ td_u32 aud_last_sys_time; /* last system time of setting audio localtime */ td_u32 aud_last_local_time; /* last audio localtime */ td_u32 aud_start_sys_time; /* last system time of setting audio localtime */ td_u32 aud_start_local_time; /* last audio localtime */ td_u32 aud_pause_local_time; /* audio localtime when pause */ td_u32 aud_pts_series_cnt; /* audio pts successive count */ td_bool is_aud_resync; /* audio resync flag */ td_bool is_aud_rebuf_fund; /* audio recumulate flag */ td_u32 aud_play_cnt; /* audio play count */ td_u32 aud_repeat_cnt; /* audio repeat count */ td_u32 aud_discard_cnt; /* audio discard count */ sync_aud_info aud_info; /* audio channel information,set by adec and used by sync */ sync_aud_opt aud_opt; /* audio adjust mode,set by sync */ sync_aud_info ad_aud_info; /* audio channel information,set by adec and used by sync */ sync_aud_opt ad_aud_opt; /* audio adjust mode,set by sync */ td_bool is_aud_first_play; /* played flag of the first audio frame */ td_u32 aud_first_play_time; /* time of playing the first audio frame */ td_bool is_aud_pts_loop_rewind; td_bool is_aud_pts_normal_loop; td_u32 aud_speed; /* audio playback speed */ td_u32 scr_first_sys_time; /* last scr system time */ td_u32 scr_first_local_time; /* last scr local time */ td_u32 scr_last_sys_time; /* last scr system time */ td_u32 scr_last_local_time; /* last scr local time */ td_u32 scr_pause_local_time; /* scr localtime when pause */ td_s32 aud_scr_diff; /* difference time between audio localtime and scr localtime */ td_s32 vid_scr_diff; /* difference time between vidio localtime and scr localtime */ td_bool is_scr_init; /* scr be inited or not */ td_bool is_print; td_bool is_use_stop_region; /* use stop region or not */ td_bool is_first_sync_state_report; td_bool is_pcr_stc_changed; /* pcr and stc changed or not */ td_bool is_ext_pll_adjust; /* use external pll adjusting method or not */ td_s32 external_ppm; /* External PPM config by user */ td_u64 cur_pcr_val; /* current pcr value */ td_u64 cur_stc_val; /* current stc value */ td_u32 aud_fund_begin_time; td_bool is_ms12; td_bool is_pcr_rewind; td_bool is_vid_rewind; td_bool is_aud_rewind; td_u32 loop_rewind_start_time; td_u32 reset_first_frame_disp_start_time; td_u32 sync_adjust_delay_frm_cnt; td_bool is_sync_finish; /* finish flag of synchronization */ td_u32 sync_finish_continue_cnt; td_u32 sync_novel_continue_cnt; td_u32 aud_loop_rewind_pts; td_u32 aud_loop_rewind_count; td_u32 vid_loop_rewind_pts; td_u32 vid_loop_rewind_count; td_bool is_show_dbg_detail; td_u32 dbg_list_node_idx; td_u32 dbg_list_node_cnt; td_u32 dbg_list_max_len; td_bool is_buf_adjust; td_bool aiao_stc_correct_support; td_bool quick_repeat_support; td_bool scr_support; td_bool stc_support; td_u32 vid_pts_jump_cnt; pts_jump_diff vid_pts_jump; td_u32 aud_pts_jump_cnt; pts_jump_diff aud_pts_jump; #ifdef CONFIG_SOCT_SYNC_DEBUG_SUPPORT struct list_head dbg_info_list_head; #endif sync_fc_info_status fc_info; } sync_context; typedef struct { sync_context *ctx; /* SYNC kernel space pointer */ const void *unique; /* SYNC unique id */ } sync_state_info; typedef struct { sync_state_info info[SYNC_MAX_NUM]; td_u32 cnt; sync_manage_fn add_ins; sync_manage_fn del_ins; } sync_global_state; td_bool sync_handle_verify(td_handle sync); td_s32 sync_start(td_handle sync); td_s32 sync_pause(td_u32 id); td_s32 sync_resume(td_u32 id); td_s32 sync_get_time(td_u32 id, td_u32 *local_time, td_u32 *play_time); td_u32 sync_get_local_time(const sync_context *ctx, sync_chan_type chn); td_u32 sync_get_sys_time(void); void sync_vid_proc(td_handle sync, sync_vid_info *info, sync_vid_opt *opt); void sync_aud_proc(td_handle sync, sync_aud_info *info, sync_aud_opt *opt); void sync_ad_aud_proc(td_handle sync, const sync_aud_info *info, sync_aud_opt *opt); void sync_pcr_proc(td_handle sync, td_u64 pcr, td_u64 stc); td_s32 sync_hpll_conf_flag_set_print(td_bool is_conf); #ifdef __cplusplus #if __cplusplus } #endif #endif #endif