| 1 | #ifndef __PARSER_DVB_H__ |
|---|
| 2 | #define __PARSER_DVB_H__ |
|---|
| 3 | |
|---|
| 4 | #include "blst_list.h" |
|---|
| 5 | #include "ch_map.h" |
|---|
| 6 | #include "getbits.h" |
|---|
| 7 | |
|---|
| 8 | /* TODO:: Scheduled event parsing ... */ |
|---|
| 9 | |
|---|
| 10 | /* based on en_300468 */ |
|---|
| 11 | #define DVB_PID_NIT 0x10 |
|---|
| 12 | #define DVB_PID_SDT 0x11 |
|---|
| 13 | #define DVB_PID_EIT 0x12 |
|---|
| 14 | #define DVB_PID_TDT 0x14 |
|---|
| 15 | #define DVB_PID_BAT 0x11 |
|---|
| 16 | |
|---|
| 17 | /* table id definition */ |
|---|
| 18 | #define DVB_TID_NIT_ACT 0x40 |
|---|
| 19 | #define DVB_TID_NIT_OTH 0x41 |
|---|
| 20 | #define DVB_TID_SDT_ACT 0x42 /* service_description_section - actual_transport_stream */ |
|---|
| 21 | #define DVB_TID_SDT_OTH 0x46 /* service_description_section - other_transport_stream */ |
|---|
| 22 | |
|---|
| 23 | #define DVB_TID_EIT_ACT 0x4E |
|---|
| 24 | #define DVB_TID_EIT_OTH 0x4F |
|---|
| 25 | #define DVB_TID_EIT_SCH_ACT 0x50 |
|---|
| 26 | #define DVB_TID_EIT_SCH_OTH 0x60 |
|---|
| 27 | |
|---|
| 28 | #define DVB_TID_TIME_DATE 0x70 |
|---|
| 29 | #define DVB_TID_TIME_OFFSET 0x73 |
|---|
| 30 | #define DVB_TID_BAT 0x4A |
|---|
| 31 | |
|---|
| 32 | #define DVB_TID_SIT 0x7F |
|---|
| 33 | #define DVB_TID_DIT 0x7E |
|---|
| 34 | #define DVB_TID_RST 0x71 |
|---|
| 35 | #define DVB_TID_STUFF 0x72 |
|---|
| 36 | |
|---|
| 37 | #define DVB_SDT_LEN 11 /* except descriptor+crc */ |
|---|
| 38 | #define DVB_SDT_DESCR_LEN 5 |
|---|
| 39 | #define DVB_EIT_LEN 11 |
|---|
| 40 | /* descriptor tag */ |
|---|
| 41 | #define DVB_DESC_TAG_NETWORK_NAME 0x40 |
|---|
| 42 | #define DVB_DESC_TAG |
|---|
| 43 | #define DVB_DESC_TAG_SERVICE |
|---|
| 44 | |
|---|
| 45 | #define MAX_NAME_LEN 30 |
|---|
| 46 | #define MAX_EVENT_NAME 96 // sync with MAX_TITLE_CHARS |
|---|
| 47 | #define MAX_EVENT_TEXT 256 // sync with MAX_DESC_CHARS |
|---|
| 48 | |
|---|
| 49 | #define MAX_SERVICE_LIST 30 |
|---|
| 50 | |
|---|
| 51 | typedef struct sdt_t { |
|---|
| 52 | uint32_t frequency; |
|---|
| 53 | uint16_t stream_id; /* transport stream id */ |
|---|
| 54 | uint16_t service_id; /* 16 bit service id which is program number in PMT */ |
|---|
| 55 | uint8_t eit_schedule_flag:1; /* EIT schedule information is present */ |
|---|
| 56 | uint8_t eit_pf_flag:1; /* EIT present/following service is present */ |
|---|
| 57 | uint8_t running_status:3; /* 0: undefined, 1:not running, 2:start in a few seconds, 3:pausing, 4:running */ |
|---|
| 58 | uint8_t free_ca_mode:1; /* 0: not scrambled, 1: controlled by CA system */ |
|---|
| 59 | uint8_t service_type; /* service type. table 72. */ |
|---|
| 60 | uint8_t provider_name[MAX_NAME_LEN]; |
|---|
| 61 | uint8_t service_name[MAX_NAME_LEN]; |
|---|
| 62 | } sdt_t; |
|---|
| 63 | |
|---|
| 64 | typedef struct nit_t { |
|---|
| 65 | uint16_t stream_id; |
|---|
| 66 | uint8_t type; |
|---|
| 67 | uint32_t frequency; |
|---|
| 68 | uint8_t modulation; |
|---|
| 69 | uint8_t bandwidth; |
|---|
| 70 | uint32_t symbol_rate; |
|---|
| 71 | uint8_t code_rate; |
|---|
| 72 | uint8_t program_cnt; |
|---|
| 73 | uint16_t program_id[MAX_SERVICE_LIST]; |
|---|
| 74 | } nit_t; |
|---|
| 75 | |
|---|
| 76 | typedef struct nit_map_t { |
|---|
| 77 | uint16_t num_nit; |
|---|
| 78 | nit_t nit[MAX_FREQ_MAP]; |
|---|
| 79 | } nit_map_t; |
|---|
| 80 | |
|---|
| 81 | typedef struct dvb_sdt_cb_t |
|---|
| 82 | { |
|---|
| 83 | void (*cb)(sdt_t *sdt, void *data); |
|---|
| 84 | void *data; |
|---|
| 85 | } dvb_sdt_cb_t; |
|---|
| 86 | |
|---|
| 87 | typedef struct dvb_nit_cb_t |
|---|
| 88 | { |
|---|
| 89 | void (*cb)(nit_t *nit, void *data); |
|---|
| 90 | void *data; |
|---|
| 91 | } dvb_nit_cb_t; |
|---|
| 92 | |
|---|
| 93 | typedef struct sdt_map_t { |
|---|
| 94 | uint16_t num_sdt; |
|---|
| 95 | sdt_t sdt[MAX_VCH]; |
|---|
| 96 | } sdt_map_t; |
|---|
| 97 | |
|---|
| 98 | typedef struct eit_t { |
|---|
| 99 | /* following 5 sequence should be matched with chm_eit_t in bapp.h */ |
|---|
| 100 | uint32_t start_time; |
|---|
| 101 | uint32_t duration; |
|---|
| 102 | uint16_t event_id; |
|---|
| 103 | uint8_t event_name[MAX_EVENT_NAME+1]; |
|---|
| 104 | uint8_t event_text[MAX_EVENT_TEXT+1]; |
|---|
| 105 | |
|---|
| 106 | uint8_t running_status:3; |
|---|
| 107 | uint8_t free_ca_mode:1; |
|---|
| 108 | uint8_t rating_code[3]; |
|---|
| 109 | uint8_t rating_age; |
|---|
| 110 | } eit_t; |
|---|
| 111 | |
|---|
| 112 | #define MAX_EIT (MAX_VCH*2) |
|---|
| 113 | typedef struct eit_entry_t { |
|---|
| 114 | BLST_D_ENTRY(eit_entry_t) link; |
|---|
| 115 | |
|---|
| 116 | uint16_t service_id; |
|---|
| 117 | uint16_t stream_id; |
|---|
| 118 | uint8_t version; |
|---|
| 119 | |
|---|
| 120 | uint32_t section_mask[8]; |
|---|
| 121 | |
|---|
| 122 | eit_t eit_present; |
|---|
| 123 | eit_t eit_following; |
|---|
| 124 | } eit_entry_t; |
|---|
| 125 | |
|---|
| 126 | |
|---|
| 127 | typedef struct eit_entry_list { |
|---|
| 128 | BLST_D_HEAD(eitlist, eit_entry_t) list; |
|---|
| 129 | } eit_entry_list; |
|---|
| 130 | |
|---|
| 131 | typedef struct eit_map_t { |
|---|
| 132 | uint16_t num_eit; |
|---|
| 133 | eit_entry_list eit_list; |
|---|
| 134 | } eit_map_t; |
|---|
| 135 | |
|---|
| 136 | #define MAX_SCHED_ENTRY 30 |
|---|
| 137 | typedef struct eit_sched_entry_t { |
|---|
| 138 | BLST_D_ENTRY(eit_sched_entry_t) link; |
|---|
| 139 | uint16_t service_id; |
|---|
| 140 | uint16_t stream_id; |
|---|
| 141 | uint8_t version[16]; |
|---|
| 142 | uint8_t count; |
|---|
| 143 | uint32_t section_mask[16][8]; |
|---|
| 144 | |
|---|
| 145 | eit_t eit_sched[MAX_SCHED_ENTRY]; |
|---|
| 146 | } eit_sched_entry_t; |
|---|
| 147 | |
|---|
| 148 | typedef struct eit_sched_entry_list { |
|---|
| 149 | BLST_D_HEAD(eitschedlist, eit_sched_entry_t) list; |
|---|
| 150 | } eit_sched_entry_list; |
|---|
| 151 | |
|---|
| 152 | typedef struct eit_sched_map_t { |
|---|
| 153 | uint16_t num_eit; |
|---|
| 154 | eit_sched_entry_list eit_list; |
|---|
| 155 | } eit_sched_map_t; |
|---|
| 156 | |
|---|
| 157 | #define MAX_TIMEOFFSET 10 |
|---|
| 158 | typedef struct tot_t { |
|---|
| 159 | uint8_t country[3]; |
|---|
| 160 | uint8_t region_id; |
|---|
| 161 | uint8_t polarity; |
|---|
| 162 | uint16_t offset; |
|---|
| 163 | uint32_t toc; |
|---|
| 164 | uint16_t next_offset; |
|---|
| 165 | } tot_t; |
|---|
| 166 | |
|---|
| 167 | typedef struct tot_map_t { |
|---|
| 168 | uint8_t num_tot; |
|---|
| 169 | tot_t tot[MAX_TIMEOFFSET]; |
|---|
| 170 | } tot_map_t; |
|---|
| 171 | |
|---|
| 172 | #ifdef LINUX |
|---|
| 173 | #define MJD_START 40587 |
|---|
| 174 | #else |
|---|
| 175 | #define MJD_START 44244 |
|---|
| 176 | #endif |
|---|
| 177 | |
|---|
| 178 | #define MJD_TO_TIME(x,y) (((x<<8| y)-MJD_START)*86400) |
|---|
| 179 | #define BCD_TO_SEC(h,m,s) ((3600 * ((10*((h & 0xF0)>>4)) + (h & 0xF))) + \ |
|---|
| 180 | (60 * ((10*((m & 0xF0)>>4)) + (m & 0xF))) + \ |
|---|
| 181 | ((10*((s & 0xF0)>>4)) + (s & 0xF))) |
|---|
| 182 | #define BCD_TO_MIN(h,m) ((60*((10*((h&0xF0)>>4))+(h&0xF))) + \ |
|---|
| 183 | ((10*((m&0xF0)>>4))+(m&0xF))) |
|---|
| 184 | |
|---|
| 185 | uint32_t dvb_find_frequency_for_stream_id(uint16_t stream_id); |
|---|
| 186 | |
|---|
| 187 | void dvb_nit_init(dvb_nit_cb_t *cb); |
|---|
| 188 | void dvb_sdt_init(dvb_sdt_cb_t *cb); |
|---|
| 189 | void dvb_tdt_init(void); |
|---|
| 190 | void dvb_eit_init(void); |
|---|
| 191 | |
|---|
| 192 | bool dvb_sdt_complete(int num_stream); |
|---|
| 193 | bool dvb_nit_complete(void); |
|---|
| 194 | |
|---|
| 195 | int dvb_nit_parse(const uint8_t *nit_buf, size_t *psize); |
|---|
| 196 | int dvb_sdt_parse(const uint8_t *nit_buf, size_t *psize); |
|---|
| 197 | int dvb_eit_parse(const uint8_t *eit_buf, size_t *psize); |
|---|
| 198 | int dvb_tdt_parse(const uint8_t *nit_buf, size_t *psize); |
|---|
| 199 | //void dvb_get_current_event(vch_t vch, int *eit_cnt, eit_t *p_eit_cur, eit_t *p_eit_next); |
|---|
| 200 | void dvb_get_current_event(vch_t vch, int *eit_cnt, eit_t *p_eit); |
|---|
| 201 | uint32_t dvb_get_cur_time(void); |
|---|
| 202 | void dvb_parse_descriptors(uint8_t *buf, uint16_t length, uint8_t table_id, void *entry); |
|---|
| 203 | eit_entry_t *dvb_eit_get_entry(uint16_t stream_id, uint16_t service_id); |
|---|
| 204 | eit_sched_entry_t *dvb_eit_get_sched_entry(uint16_t stream_id, uint16_t service_id); |
|---|
| 205 | #endif |
|---|