/*************************************************************************** * Copyright (c) 2003-2006, Broadcom Corporation * All Rights Reserved * Confidential Property of Broadcom Corporation * * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. * * $brcm_Workfile: $ * $brcm_Revision: $ * $brcm_Date: $ * * Module Description: * * Revision History: * * $brcm_Log: $ * ***************************************************************************/ #ifndef CHAN_MGR_H__ #define CHAN_MGR_H__ #include "bsettop_stream.h" #include "bsettop_tuner.h" #include "bsettop_smessage.h" #include "bstd.h" #include "ts_psi.h" #include "ts_pat.h" #include "ts_pmt.h" #include "psip_mss.h" #include "psip_descriptor.h" #include "bos.h" #include "ch_map.h" #include "bapp_freq_table.h" #include "psip_vct.h" #include "psip_stt.h" #include "psip_rrt.h" #include "psip_mgt.h" #include "psip_eit.h" #define MAX_CHANNELS 128 #define MAX_CH_NAME_CHARS 32 #define MAX_CH_SHORT_NAME_CHARS 7 /* short name in VCT */ #define MAX_LONG_NAME_CHARS 128 #define MAX_TIME_STR_CHARS 32 #define MAX_RATING_STR_CHARS 32 #define MAX_EIT_NUM 9 /* make it multiple of detailed EPG entry size 9 for each page */ #define EIT_CURRENT 0 #define EIT_NEXT 1 #define MAX_CMD_HIST 128 /* for SCTE 127 VBI */ #ifdef HAS_VBI #include "pmt_desc_scte_127.h" #include "scte_127.h" #endif #define EAS_BUF_LEN (1024 + 188) #define MAX_RRT_DIM 128 #define RRT_BUF_LEN (1024 + 188) #define MAX_CHM_EVENT 32 #define MAX_TITLE_CHARS 96 #define MAX_DESC_CHARS 256 #define MAX_TIME_STR_CHARS 32 #define MAX_CC_SERVICES 6 /* Summary: Internal state. */ typedef enum chm_state_t { eCHM_GET_STT, eCHM_GET_VCT, eCHM_GET_MGT, eCHM_PROCESS_MGT, eCHM_PROG_IDLE }chm_state_t; /* Summary: Command enumeration to control channel manager. */ typedef enum chm_cmd_t { eCHM_CANCEL, eCHM_TUNE, eCHM_INFO, eCHM_STOP, eCHM_CHECK_SIGNAL, eCHM_HUNT, eCHM_GUIDE, eCHM_SAP }chm_cmd_t; /* Command event structure */ typedef struct chm_cmd_event_t { chm_cmd_t cmd_id; /* Command ID */ unsigned char data[32]; }chm_cmd_event_t; /* Summary: Types of tune commands. */ typedef enum chm_tune_type_t { eCHM_UP, eCHM_DOWN, eCHM_CURRENT, eCHM_CH_NUM, eCHM_FREQ, }chm_tune_type_t; /* Summary: Tune command event structure. */ typedef struct chm_tune_event_t { chm_cmd_t cmd_id; /* Command ID */ chm_tune_type_t type; /* Type of tune command */ unsigned int data; /* Frequency in Hz, or channel number depending on type */ }chm_tune_event_t; /* Summary: Command enumeration to control channel manager. */ typedef enum chm_status_t { eCHM_STATUS_HUNT, eCHM_STATUS_CHMAP, eCHM_STATUS_NORMAL, eCHM_STATUS_PAT, eCHM_STATUS_NOPAT, eCHM_STATUS_TUNE_MS, eCHM_STATUS_SI_MS, }chm_status_t; /* Summary: Command enumeration to control channel manager. */ typedef enum chm_evt_type_t { eCHM_EVT_CANCEL, eCHM_EVT_DONE, eCHM_EVT_REDRAW, eCHM_EVT_PROGRESS, eCHM_EVT_SIGNAL, /* Provide CA information, id - signal strength, data: SNR (32 bits), freq hz (32 bits) */ eCHM_EVT_EAS, eCHM_EVT_STATUS, /* Provide status information, id - 0 Hunt Mode, 1 Pending Init Mode, 2 new ch map, 3 PAT, 4 PAT failed */ eCHM_EVT_AV_MUTE, /* change AV Mute, id - 0 Unmute, 1 mute */ eCHM_EVT_SAVE, /* save settings message */ eCHM_EVT_TIME, /* system time message, id - system time - GPS_offset , data: host clock offset (32 bits) */ eCHM_EVT_RRT, /* RRT event */ eCHM_EVT_CAD, /* content advisory descriptor event */ eCHM_EVT_BLOCK, /* block event from XDS packet */ eCHM_EVT_SET_SCREEN, /* captioning service information */ eCHM_EVT_SNR, /* SNR event */ eCHM_EVT_RESET, /* reset message, id - 0 nop, 1 reboot, 2 partial reset, 3 full reset */ eCHM_EVT_MAX, /* Number of eCHM_EVTs */ }chm_evt_type_t; /* event structure for signaling application */ typedef struct chm_event_t { chm_evt_type_t type; unsigned int id; unsigned int ticks; unsigned char data[256]; }chm_event_t; /* Screen event structure */ typedef struct chm_time_event_t { chm_evt_type_t type; unsigned int system_time; unsigned int system_offset; unsigned int utc_offset; }chm_time_event_t; /* Signal structure */ typedef struct chm_signal_event_t { chm_evt_type_t type; unsigned int lock; unsigned int power; unsigned int ticks; unsigned int SNR; unsigned int freq_hz; unsigned int signal_quality; int mode; }chm_signal_event_t; /* Summary: Structure to help associate a stream and video PID */ typedef struct chm_stream_t { bstream_t stream; unsigned int freq_hz; unsigned short pid; }chm_stream_t; /* EIT Info structure */ typedef struct chm_eit_t { unsigned int start_time; unsigned int length; unsigned short event_id; unsigned char prog_title[MAX_TITLE_CHARS + 1]; unsigned char prog_desc[MAX_DESC_CHARS + 1]; PSIP_CSD_service cc_service[MAX_CC_SERVICES]; }chm_eit_t; /* Channel info structure */ typedef struct chm_info_t { unsigned short source_id; unsigned short major; unsigned short minor; unsigned short program_number; unsigned char ch_name[MAX_CH_NAME_CHARS]; unsigned char ext_ch_name[MAX_LONG_NAME_CHARS + 1]; //unsigned char vct_name[MAX_LONG_NAME_CHARS + 1]; chm_eit_t eit_info[MAX_EIT_NUM]; bool got_vct; unsigned char psip_rating_str[MAX_RATING_STR_CHARS]; /* remember psip rating string associated with EIT */ }chm_info_t; typedef enum time_source_t { eTS_NONE, eTS_TSID, eTS_XDS, eTS_FIXED, }time_source_t; /* MGT state constants */ typedef enum chm_mgt_state_t { eMGT_EIT, eMGT_ETT, }chm_mgt_state_t; /* flag indication what type of eit found */ typedef enum chm_eit_found_t { eEIT_NONE = 0x00, eEIT_CURRENT = 0x01, eEIT_NEXT = 0x02, eEIT_BOTH = 0x03, eEIT_CONT = 0x04, /* EIT/ETT beyond current and next */ }chm_eit_found_t; /* rrt event structure */ typedef struct chm_rrt_event_t { chm_evt_type_t type; unsigned int size; unsigned char rrt[RRT_BUF_LEN]; } chm_rrt_event_t; #define MAX_MSG_EVENTS 10 /* Summary: Command enumeration to control channel manager. */ typedef struct chm_mgr_t { chm_cmd_t cmd; /* Current channel manager state */ chm_state_t state; /* state controls data acquisition priority */ b_task_t task; unsigned int *stack; unsigned char *stt_buf; unsigned char *pat_buf; unsigned char *pmt_buf; unsigned char *eas_buf; b_queue_t queue; b_event_t event[MAX_CHM_EVENT]; chm_event_t chm_evt; chm_event_t chm_pat_evt; chm_event_t chm_pending_evt; chm_event_t chm_hunt_evt; chm_event_t chm_eas_evt; chm_event_t status_evt; chm_time_event_t time_evt; chm_event_t chmap_evt; chm_cmd_event_t cancel_cmd; chm_signal_event_t signal_evt; chm_event_t reset_evt; chm_event_t redraw_evt; void *p_app; b_mutex_t mutex; b_mutex_t ch_map_mutex; char tmp_text[MAX_TITLE_CHARS + 1]; smessage_stream_t stt_msg; smessage_stream_t eas_msg; char eas_timer_started; /* EAS timer support */ uint16_t sequence_number; /* sequence number (% 32) */ uint16_t EAS_event_ID; /* EAS event ID */ bool eas_reset; /* flag indicates eas is reset (will accept new eas without checking parameters) */ unsigned int select_idx; unsigned int hunt_cnt; b_queue_t gen_queue; b_event_t gen_event[MAX_MSG_EVENTS]; unsigned int pat_crc; unsigned int pmt_crc; ch_map_t ch_map; btuner_t tuner; smessage_stream_t smsg; btuner_params tuner_params; bapp_freq_table_type_t fe_type; unsigned int *freq_table; unsigned int num_freq; chm_stream_t chm_stream[BSETTOP_MAX_STREAMS]; bstream_mpeg mpeg[BSETTOP_MAX_STREAMS]; chm_stream_t *curr_stream; bband_t band; smessage_stream_params_t msg_params; bool decoding_video; bool decoding_audio; unsigned short network_pid; unsigned int vendor_id; unsigned int hardware_version_id; unsigned int last_freq_hz; unsigned int force_tune; /* force to tune even last frequency is same */ /* Status counts */ unsigned short ccm_cnt; unsigned short amm_cnt; unsigned short acm_even_cnt; unsigned short acm_odd_cnt; unsigned short key_table_cnt; unsigned short cds_cnt; unsigned short mms_cnt; unsigned short sns_cnt; unsigned short dcm_cnt; unsigned short vcm_cnt; unsigned short stt_cnt; unsigned short ops_cnt; unsigned short cfg_cnt; unsigned short eas_cnt; unsigned short em_cnt; unsigned short pat_cnt; unsigned short pmt_cnt; unsigned short refresh_count; unsigned short system_id_errors; /* STT */ PSIP_STT_header stt; unsigned int sys_time; /* UTC seconds minus UTC offset in STT */ unsigned int sys_UTC_offset; /* UTC offset in STT */ unsigned int sys_offset; /* System seconds from gettimeofday when STT came in */ bool got_stt; /* eit */ smessage_stream_t eit_msg; unsigned char *eit_buf; unsigned short eit_cnt; bool got_eit; unsigned int eit_start_time; unsigned int eit_length; unsigned int eit_crc; /* mgt */ smessage_stream_t mgt_msg; unsigned char *mgt_buf; unsigned short mgt_cnt; bool got_mgt; b_timeval mgt_tv; /* Time we finished processing MGT */ chm_mgt_state_t mgt_state; /* state of MGT processing */ unsigned int mgt_crc; /* vct */ smessage_stream_t vct_msg; unsigned char *vct_buf; unsigned short vct_cnt; bool got_vct; unsigned int vct_crc; PSIP_VCT_channel prev_vct; /* in Mexico broacast, some stations even encoding VCT wrong, e.g. duplication of VCT entry */ /* ett */ unsigned char *ett_buf; unsigned short ett_cnt; bool got_ett; /* rrt */ smessage_stream_t rrt_msg; unsigned char *rrt_buf; unsigned short rrt_cnt; bool got_rrt; unsigned int rrt_crc; chm_rrt_event_t rrt_evt; time_source_t local_time_source; /* Identifies method used to obtain local time */ int local_offset; /* local time offset from UTC time to obtain standard time */ char local_dst_obs; /* local DST observance */ unsigned short TSID; /* remember latest TSID */ unsigned int mgt_size; unsigned int mgt_idx; chm_info_t cur_info; chm_info_t *p_info; unsigned int max_info_num; unsigned int rrt_size; unsigned int last_rrt; chm_event_t snr_evt; b_timeval guide_tv; /* time guide was retrieved */ int cur_ch_num; /* current channel number */ int cur_epg_ch_num; /* track current channel number for addtional EPG display */ int epg_update_ch_num; /* the channel number that the EPG screen will start to update */ bool not_check_cancel; /* don't check cancel event */ bool first_pat_pmt; /* flag indicate if we have make a first check of PAT/PMT */ }chm_mgr_t; extern unsigned int g_xds_time_offset; extern bool g_xds_dst; /* Summary: Initialization. */ void chm_init(chm_mgr_t *p_chm, void *p_app); /* Summary: Function to pass a command to the channel manager. Any results and notification is handled by passing events to the app via the msg_queue. */ void chm_cmd(chm_mgr_t *p_chm,chm_cmd_event_t *p_cmd_evt); /* Summary: Get the current UTC time, local offset and dst flag. Returns non-zero when it is not possible to determine local time. */ int chm_get_time_info(chm_mgr_t *p_chm, unsigned int *utc_secs, /* Current UTC time in seconds */ int *local_offset, /* Local time offset from UTC time in seconds */ bool *dst /* Daylight savings flag */ ); /* Summary: process the MMS string and associated tables. Returns non-zero on failure. */ int chm_process_mss(chm_mgr_t *p_chm, /* Channel manager reference */ PSIP_MSS_string p_mms, /* Pointer to MMS */ unsigned char* mms_buf, /* string buffer */ unsigned int mms_len /* string buffer length */ ); /* Summary: Return the hunt mode progress in percent. */ int chm_get_hunt_progress(chm_mgr_t *p_chm); /* get current channel information */ void chm_get_cur_ch_info( chm_mgr_t *p_chm, chm_info_t *p_info, bstream_mpeg *p_mpeg); bool chm_GetScanStatusFinish(void); typedef enum chm_msg_filter_t { eCHM_MSG_FILTER_STT = 0x0001, eCHM_MSG_FILTER_RRT = 0x0002, /* downloadable RRT */ eCHM_MSG_FILTER_MGT = 0x0004, eCHM_MSG_FILTER_EAS = 0x0008 } chm_msg_filter_t; void chm_start_filter_monitoring(chm_mgr_t *p_chm, chm_msg_filter_t which); void chm_stop_filter_monitoring(chm_mgr_t *p_chm, chm_msg_filter_t which); int chm_clear_current(chm_mgr_t *p_chm); bool chm_has_valid_cc_service(chm_mgr_t *p_chm, bool *wide_aspect_ratio); #ifdef CONFIG_NXP_TDA182I4 void NXP_TDA182I4_SetStandby(); #endif #ifdef TUNER_DEBUG int chm_scan_psi_a_freq(chm_mgr_t *p_chm, unsigned int freq); #endif bool chm_check_program_end_time(chm_mgr_t *p_chm); #endif /* CHAN_MGR_H__ */