| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2003-2006, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: $ |
|---|
| 11 | * $brcm_Revision: $ |
|---|
| 12 | * $brcm_Date: $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | ***************************************************************************/ |
|---|
| 21 | #ifndef CHAN_MGR_H__ |
|---|
| 22 | #define CHAN_MGR_H__ |
|---|
| 23 | |
|---|
| 24 | #include "bsettop_stream.h" |
|---|
| 25 | #include "bsettop_smessage.h" |
|---|
| 26 | #include "bstd.h" |
|---|
| 27 | #include "ts_psi.h" |
|---|
| 28 | #include "ts_pat.h" |
|---|
| 29 | #include "ts_pmt.h" |
|---|
| 30 | #include "psip_mss.h" |
|---|
| 31 | #include "psip_descriptor.h" |
|---|
| 32 | #include "bapp_types.h" |
|---|
| 33 | #include "bapp_tune.h" |
|---|
| 34 | #include "ch_map.h" |
|---|
| 35 | #include "si.h" |
|---|
| 36 | #include "si_nit.h" |
|---|
| 37 | #include "si_ntt.h" |
|---|
| 38 | #include "si_stt.h" |
|---|
| 39 | #include "si_svct.h" |
|---|
| 40 | #include "dsmcc.h" |
|---|
| 41 | #include "bapp_av.h" |
|---|
| 42 | |
|---|
| 43 | /* for SCTE 127 VBI */ |
|---|
| 44 | #ifdef HAS_VBI |
|---|
| 45 | #include "pmt_desc_scte_127.h" |
|---|
| 46 | #include "scte_127.h" |
|---|
| 47 | #endif |
|---|
| 48 | |
|---|
| 49 | #define MAX_CHM_EVENT 16 |
|---|
| 50 | #define MAX_TITLE_CHARS 96 |
|---|
| 51 | #define MAX_DESC_CHARS 256 |
|---|
| 52 | #define MAX_TIME_STR_CHARS 32 |
|---|
| 53 | #define MAX_CC_SERVICES 6 |
|---|
| 54 | |
|---|
| 55 | /* |
|---|
| 56 | Summary: |
|---|
| 57 | Internal state. |
|---|
| 58 | */ |
|---|
| 59 | typedef enum chm_state_t |
|---|
| 60 | { |
|---|
| 61 | eCHM_PROG_INIT, |
|---|
| 62 | eCHM_PROG_SCTE65, |
|---|
| 63 | eCHM_PROG_UPDATING, |
|---|
| 64 | eCHM_PROG_CAT, |
|---|
| 65 | eCHM_PROG_IDLE |
|---|
| 66 | }chm_state_t; |
|---|
| 67 | |
|---|
| 68 | /* |
|---|
| 69 | Summary: |
|---|
| 70 | Command enumeration to control channel manager. |
|---|
| 71 | */ |
|---|
| 72 | typedef enum chm_cmd_t |
|---|
| 73 | { |
|---|
| 74 | eCHM_CANCEL, |
|---|
| 75 | eCHM_TUNE, |
|---|
| 76 | eCHM_INFO, |
|---|
| 77 | eCHM_STOP, |
|---|
| 78 | eCHM_CHECK_SIGNAL, |
|---|
| 79 | eCHM_HUNT, |
|---|
| 80 | eCHM_HUNTING, |
|---|
| 81 | eCHM_PENDING_INIT, |
|---|
| 82 | eCHM_DOWNLOAD, |
|---|
| 83 | eCHM_SAP |
|---|
| 84 | }chm_cmd_t; |
|---|
| 85 | /* Command event structure */ |
|---|
| 86 | typedef struct chm_cmd_event_t |
|---|
| 87 | { |
|---|
| 88 | chm_cmd_t cmd_id; /* Command ID */ |
|---|
| 89 | unsigned char data[32]; |
|---|
| 90 | }chm_cmd_event_t; |
|---|
| 91 | /* |
|---|
| 92 | Summary: |
|---|
| 93 | Types of tune commands. |
|---|
| 94 | */ |
|---|
| 95 | typedef enum chm_tune_type_t |
|---|
| 96 | { |
|---|
| 97 | eCHM_UP, |
|---|
| 98 | eCHM_DOWN, |
|---|
| 99 | eCHM_CURRENT, |
|---|
| 100 | eCHM_CH_NUM, |
|---|
| 101 | eCHM_FREQ |
|---|
| 102 | }chm_tune_type_t; |
|---|
| 103 | |
|---|
| 104 | /* |
|---|
| 105 | Summary: |
|---|
| 106 | Tune command event structure. |
|---|
| 107 | */ |
|---|
| 108 | typedef struct chm_tune_event_t |
|---|
| 109 | { |
|---|
| 110 | chm_cmd_t cmd_id; /* Command ID */ |
|---|
| 111 | chm_tune_type_t type; /* Type of tune command */ |
|---|
| 112 | unsigned int data; /* Frequency in Hz, or channel number depending on type */ |
|---|
| 113 | }chm_tune_event_t; |
|---|
| 114 | |
|---|
| 115 | /* |
|---|
| 116 | Summary: |
|---|
| 117 | Command enumeration to control channel manager. |
|---|
| 118 | */ |
|---|
| 119 | typedef enum chm_status_t |
|---|
| 120 | { |
|---|
| 121 | eCHM_STATUS_HUNT, |
|---|
| 122 | eCHM_STATUS_PENDING_INIT, |
|---|
| 123 | eCHM_STATUS_CHMAP, |
|---|
| 124 | eCHM_STATUS_NORMAL, |
|---|
| 125 | eCHM_STATUS_PAT, |
|---|
| 126 | eCHM_STATUS_NOPAT, |
|---|
| 127 | eCHM_STATUS_TUNE_MS, |
|---|
| 128 | eCHM_STATUS_SI_MS |
|---|
| 129 | }chm_status_t; |
|---|
| 130 | /* |
|---|
| 131 | Summary: |
|---|
| 132 | Command enumeration to control channel manager. |
|---|
| 133 | */ |
|---|
| 134 | typedef enum chm_evt_type_t |
|---|
| 135 | { |
|---|
| 136 | eCHM_EVT_CANCEL, |
|---|
| 137 | eCHM_EVT_DONE, |
|---|
| 138 | eCHM_EVT_REDRAW, |
|---|
| 139 | eCHM_EVT_PROGRESS, |
|---|
| 140 | eCHM_EVT_SIGNAL, /* Provide CA information, id - signal strength, data: SNR (32 bits), freq hz (32 bits) */ |
|---|
| 141 | eCHM_EVT_DOWNLOAD, |
|---|
| 142 | eCHM_EVT_EAS, |
|---|
| 143 | eCHM_EVT_CA, /* Provide CA information, id - CA_System_ID, data: emm PID (16 bits) , freq_khz (32 bits)*/ |
|---|
| 144 | eCHM_EVT_NETWORK, /* Provide Network PID, id - Network PID */ |
|---|
| 145 | eCHM_EVT_STATUS, /* Provide status information, id - 0 Hunt Mode, 1 Pending Init Mode, 2 new ch map, 3 PAT, 4 PAT failed */ |
|---|
| 146 | eCHM_EVT_AV_MUTE, /* change AV Mute, id - 0 Unmute, 1 mute */ |
|---|
| 147 | eCHM_EVT_ACTIVATION, /* activation message, id - 0 Deactivate, 1 Activate */ |
|---|
| 148 | eCHM_EVT_CONFIGURATION, /* config message, id - location code, data: timeout in hours (16 bits), VCT_ID (16 bits) */ |
|---|
| 149 | eCHM_EVT_VCT_ID, /* config message, id - VCT_ID */ |
|---|
| 150 | eCHM_EVT_LOCATION, /* location message, id - location code */ |
|---|
| 151 | eCHM_EVT_TIMEZONE, /* timezone message, id - UTC offset, data: entry UTC (32 bits), exit UTC (32 bits), delta (8 bits) */ |
|---|
| 152 | eCHM_EVT_PHONENUMBER, /* phone number message, data: 8 bit ASCII phone number (8 bytes)*/ |
|---|
| 153 | eCHM_EVT_RESET, /* reset message, id - 0 nop, 1 reboot, 2 partial reset, 3 full reset */ |
|---|
| 154 | eCHM_EVT_SAVE, /* save settings message */ |
|---|
| 155 | eCHM_EVT_TIME /* system time message, id - system time - GPS_offset , data: host clock offset (32 bits) */ |
|---|
| 156 | }chm_evt_type_t; |
|---|
| 157 | |
|---|
| 158 | /* event structure for signaling application */ |
|---|
| 159 | typedef struct chm_event_t |
|---|
| 160 | { |
|---|
| 161 | chm_evt_type_t type; |
|---|
| 162 | unsigned int id; |
|---|
| 163 | unsigned int ticks; |
|---|
| 164 | unsigned char data[256]; |
|---|
| 165 | }chm_event_t; |
|---|
| 166 | |
|---|
| 167 | /* Screen event structure */ |
|---|
| 168 | typedef struct chm_time_event_t |
|---|
| 169 | { |
|---|
| 170 | chm_evt_type_t type; |
|---|
| 171 | unsigned int system_time; |
|---|
| 172 | unsigned int system_offset; |
|---|
| 173 | unsigned int utc_offset; |
|---|
| 174 | }chm_time_event_t; |
|---|
| 175 | |
|---|
| 176 | /* Signal structure */ |
|---|
| 177 | typedef struct chm_signal_event_t |
|---|
| 178 | { |
|---|
| 179 | chm_evt_type_t type; |
|---|
| 180 | unsigned int lock; |
|---|
| 181 | unsigned int power; |
|---|
| 182 | unsigned int ticks; |
|---|
| 183 | unsigned int SNR; |
|---|
| 184 | unsigned int freq_hz; |
|---|
| 185 | int mode; |
|---|
| 186 | }chm_signal_event_t; |
|---|
| 187 | |
|---|
| 188 | /* CA structure */ |
|---|
| 189 | typedef struct chm_ca_event_t |
|---|
| 190 | { |
|---|
| 191 | chm_evt_type_t type; |
|---|
| 192 | unsigned int CA_System_ID; |
|---|
| 193 | unsigned int ticks; |
|---|
| 194 | unsigned int freq_khz; |
|---|
| 195 | unsigned short EMM_PID; |
|---|
| 196 | unsigned short EMM_Provider_ID; |
|---|
| 197 | unsigned char SCP_operating_mode; |
|---|
| 198 | }chm_ca_event_t; |
|---|
| 199 | |
|---|
| 200 | /* configuration structure */ |
|---|
| 201 | typedef struct chm_config_event_t |
|---|
| 202 | { |
|---|
| 203 | chm_evt_type_t type; |
|---|
| 204 | unsigned int location; |
|---|
| 205 | unsigned int ticks; |
|---|
| 206 | unsigned short timeout; |
|---|
| 207 | unsigned short VCT_ID; |
|---|
| 208 | unsigned short timeout_policy; |
|---|
| 209 | unsigned short max_location_errors; |
|---|
| 210 | }chm_config_event_t; |
|---|
| 211 | |
|---|
| 212 | /* timezone structure */ |
|---|
| 213 | typedef struct chm_tz_event_t |
|---|
| 214 | { |
|---|
| 215 | chm_evt_type_t type; |
|---|
| 216 | unsigned int utc_offset; |
|---|
| 217 | unsigned int ticks; |
|---|
| 218 | unsigned int dst_entry; |
|---|
| 219 | unsigned int dst_exit; |
|---|
| 220 | unsigned char dst_delta; |
|---|
| 221 | }chm_tz_event_t; |
|---|
| 222 | |
|---|
| 223 | /* |
|---|
| 224 | Summary: |
|---|
| 225 | Structure to help associate a stream and video PID |
|---|
| 226 | */ |
|---|
| 227 | typedef struct chm_stream_t |
|---|
| 228 | { |
|---|
| 229 | bstream_t stream; |
|---|
| 230 | unsigned int freq_hz; |
|---|
| 231 | unsigned short pid; |
|---|
| 232 | }chm_stream_t; |
|---|
| 233 | |
|---|
| 234 | #define MAX_MSG_EVENTS 10 |
|---|
| 235 | /* |
|---|
| 236 | Summary: |
|---|
| 237 | Command enumeration to control channel manager. |
|---|
| 238 | */ |
|---|
| 239 | typedef struct chm_mgr_t |
|---|
| 240 | { |
|---|
| 241 | chm_cmd_t cmd; /* Current channel manager state */ |
|---|
| 242 | chm_state_t state; /* state controls data acquisition priority */ |
|---|
| 243 | bapp_task_t task; |
|---|
| 244 | unsigned int *stack; |
|---|
| 245 | |
|---|
| 246 | unsigned char *nit_buf; |
|---|
| 247 | unsigned char *ntt_buf; |
|---|
| 248 | unsigned char *svct_buf; |
|---|
| 249 | unsigned char *stt_buf; |
|---|
| 250 | unsigned char *pat_buf; |
|---|
| 251 | unsigned char *pmt_buf; |
|---|
| 252 | unsigned char *eas_buf; |
|---|
| 253 | unsigned char *cvt_buf; |
|---|
| 254 | unsigned char *cat_buf; |
|---|
| 255 | unsigned char *emm_buf; |
|---|
| 256 | |
|---|
| 257 | bapp_task_queue_t queue; |
|---|
| 258 | bapp_task_event_t event[MAX_CHM_EVENT]; |
|---|
| 259 | chm_event_t chm_evt; |
|---|
| 260 | chm_event_t chm_pat_evt; |
|---|
| 261 | chm_event_t chm_network_evt; |
|---|
| 262 | chm_event_t chm_pending_evt; |
|---|
| 263 | chm_event_t chm_hunt_evt; |
|---|
| 264 | chm_event_t chm_eas_evt; |
|---|
| 265 | chm_event_t status_evt; |
|---|
| 266 | chm_event_t download_evt; |
|---|
| 267 | chm_time_event_t time_evt; |
|---|
| 268 | chm_event_t chmap_evt; |
|---|
| 269 | chm_cmd_event_t cancel_cmd; |
|---|
| 270 | chm_signal_event_t signal_evt; |
|---|
| 271 | chm_tz_event_t tz_evt; |
|---|
| 272 | chm_config_event_t config_evt; |
|---|
| 273 | chm_event_t vct_id_evt; |
|---|
| 274 | chm_event_t reset_evt; |
|---|
| 275 | chm_event_t phone_evt; |
|---|
| 276 | chm_event_t activate_evt; |
|---|
| 277 | chm_event_t location_evt; |
|---|
| 278 | chm_ca_event_t ca_evt; |
|---|
| 279 | void *p_app; |
|---|
| 280 | |
|---|
| 281 | bapp_task_mutex_t mutex; |
|---|
| 282 | bapp_task_mutex_t ch_map_mutex; |
|---|
| 283 | |
|---|
| 284 | char tmp_text[MAX_TITLE_CHARS + 1]; |
|---|
| 285 | |
|---|
| 286 | smessage_stream_t stt_msg; |
|---|
| 287 | smessage_stream_t eas_msg; |
|---|
| 288 | smessage_stream_t cvt_msg; |
|---|
| 289 | |
|---|
| 290 | smessage_stream_t nit_msg; |
|---|
| 291 | smessage_stream_t ntt_msg; |
|---|
| 292 | smessage_stream_t svct_msg; |
|---|
| 293 | smessage_stream_t emm_msg; |
|---|
| 294 | smessage_stream_t cat_msg; |
|---|
| 295 | |
|---|
| 296 | char eas_timer_started; /* EAS timer support */ |
|---|
| 297 | uint16_t sequence_number; /* sequence number (% 32) */ |
|---|
| 298 | uint16_t EAS_event_ID; /* EAS event ID */ |
|---|
| 299 | |
|---|
| 300 | #ifdef HAS_VBI |
|---|
| 301 | smessage_stream_t scte127_msg; |
|---|
| 302 | pscte_127_handle pscte_127; |
|---|
| 303 | unsigned char *scte127_buf; |
|---|
| 304 | int scte127_buf_size; |
|---|
| 305 | #endif |
|---|
| 306 | |
|---|
| 307 | unsigned int select_idx; |
|---|
| 308 | unsigned int hunt_cnt; |
|---|
| 309 | |
|---|
| 310 | bapp_task_queue_t gen_queue; |
|---|
| 311 | bapp_task_event_t gen_event[MAX_MSG_EVENTS]; |
|---|
| 312 | vch_t vch; |
|---|
| 313 | st_t st; |
|---|
| 314 | freq_t freq; |
|---|
| 315 | unsigned int pat_crc; |
|---|
| 316 | unsigned int pmt_crc; |
|---|
| 317 | |
|---|
| 318 | bool cvt_valid; |
|---|
| 319 | struct cvt_info_t cvt; |
|---|
| 320 | |
|---|
| 321 | SI_SVCT_VCM_Callback_t vcm_cb; |
|---|
| 322 | SI_NTT_SNS_Callback_t sns_cb; |
|---|
| 323 | SI_CDS_Callback_t cds_cb; |
|---|
| 324 | SI_MMS_Callback_t mms_cb; |
|---|
| 325 | bool vcm_changed; |
|---|
| 326 | bool sns_changed; |
|---|
| 327 | bool cds_changed; |
|---|
| 328 | bool mms_changed; |
|---|
| 329 | bool mms_flag; |
|---|
| 330 | ch_map_t ch_map; |
|---|
| 331 | |
|---|
| 332 | bapp_tune_t tune; |
|---|
| 333 | bapp_freq_table_type_t fe_type; |
|---|
| 334 | unsigned int *freq_table; |
|---|
| 335 | unsigned int num_freq; |
|---|
| 336 | bapp_av_t av; |
|---|
| 337 | |
|---|
| 338 | smessage_stream_t smsg; |
|---|
| 339 | chm_stream_t chm_stream[BSETTOP_MAX_STREAMS]; |
|---|
| 340 | bstream_mpeg mpeg[BSETTOP_MAX_STREAMS]; |
|---|
| 341 | chm_stream_t *curr_stream; |
|---|
| 342 | bband_t band; |
|---|
| 343 | smessage_stream_params_t msg_params; |
|---|
| 344 | bool decoding_video; |
|---|
| 345 | bool decoding_audio; |
|---|
| 346 | |
|---|
| 347 | unsigned short network_pid; |
|---|
| 348 | unsigned int vendor_id; |
|---|
| 349 | unsigned int hardware_version_id; |
|---|
| 350 | unsigned int last_freq_hz; |
|---|
| 351 | |
|---|
| 352 | unsigned int force_tune; /* force to tune even last frequency is same */ |
|---|
| 353 | |
|---|
| 354 | /* Status counts */ |
|---|
| 355 | unsigned short ccm_cnt; |
|---|
| 356 | unsigned short amm_cnt; |
|---|
| 357 | unsigned short acm_even_cnt; |
|---|
| 358 | unsigned short acm_odd_cnt; |
|---|
| 359 | unsigned short key_table_cnt; |
|---|
| 360 | unsigned short eas_filter_cnt; |
|---|
| 361 | unsigned short cds_cnt; |
|---|
| 362 | unsigned short mms_cnt; |
|---|
| 363 | unsigned short sns_cnt; |
|---|
| 364 | unsigned short dcm_cnt; |
|---|
| 365 | unsigned short vcm_cnt; |
|---|
| 366 | unsigned short stt_cnt; |
|---|
| 367 | unsigned short emm_cnt; |
|---|
| 368 | unsigned short ops_cnt; |
|---|
| 369 | unsigned short cfg_cnt; |
|---|
| 370 | unsigned short eas_cnt; |
|---|
| 371 | unsigned short em_cnt; |
|---|
| 372 | unsigned short cat_cnt; |
|---|
| 373 | unsigned short pat_cnt; |
|---|
| 374 | unsigned short pmt_cnt; |
|---|
| 375 | unsigned short cvt_cnt; |
|---|
| 376 | unsigned short refresh_count; |
|---|
| 377 | unsigned short emm_count; |
|---|
| 378 | unsigned short system_id_errors; |
|---|
| 379 | |
|---|
| 380 | }chm_mgr_t; |
|---|
| 381 | |
|---|
| 382 | extern unsigned int g_xds_time_offset; |
|---|
| 383 | extern bool g_xds_dst; |
|---|
| 384 | |
|---|
| 385 | /* |
|---|
| 386 | Summary: |
|---|
| 387 | Initialization. |
|---|
| 388 | */ |
|---|
| 389 | void chm_init(chm_mgr_t *p_chm, void *p_app); |
|---|
| 390 | |
|---|
| 391 | /* |
|---|
| 392 | Summary: |
|---|
| 393 | Function to pass a command to the channel manager. |
|---|
| 394 | Any results and notification is handled by passing events to the app via |
|---|
| 395 | the msg_queue. |
|---|
| 396 | |
|---|
| 397 | */ |
|---|
| 398 | void chm_cmd(chm_mgr_t *p_chm,chm_cmd_event_t *p_cmd_evt); |
|---|
| 399 | |
|---|
| 400 | |
|---|
| 401 | /* |
|---|
| 402 | Summary: |
|---|
| 403 | Get the current UTC time, local offset and dst flag. |
|---|
| 404 | Returns non-zero when it is not possible to determine local time. |
|---|
| 405 | |
|---|
| 406 | */ |
|---|
| 407 | int chm_get_time_info(chm_mgr_t *p_chm, |
|---|
| 408 | unsigned int *utc_secs, /* Current UTC time in seconds */ |
|---|
| 409 | int *local_offset, /* Local time offset from UTC time in seconds */ |
|---|
| 410 | bool *dst /* Daylight savings flag */ |
|---|
| 411 | ); |
|---|
| 412 | |
|---|
| 413 | /* |
|---|
| 414 | Summary: |
|---|
| 415 | process the MMS string and associated tables. |
|---|
| 416 | Returns non-zero on failure. |
|---|
| 417 | */ |
|---|
| 418 | int chm_process_mss(chm_mgr_t *p_chm, /* Channel manager reference */ |
|---|
| 419 | PSIP_MSS_string p_mms, /* Pointer to MMS */ |
|---|
| 420 | unsigned char* mms_buf, /* string buffer */ |
|---|
| 421 | unsigned int mms_len /* string buffer length */ |
|---|
| 422 | ); |
|---|
| 423 | |
|---|
| 424 | |
|---|
| 425 | /* |
|---|
| 426 | Summary: |
|---|
| 427 | Return the hunt mode progress in percent. |
|---|
| 428 | */ |
|---|
| 429 | int chm_get_hunt_progress(chm_mgr_t *p_chm); |
|---|
| 430 | |
|---|
| 431 | |
|---|
| 432 | #endif /* CHAN_MGR_H__ */ |
|---|
| 433 | |
|---|