| 1 |
|
| /* |
| 2 |
|
| * parse various TV stuff out of DVB TS streams. |
| 3 |
|
| * |
| 4 |
|
| */ |
| 5 |
|
| #include <stdio.h> |
| 6 |
|
| #include <stdlib.h> |
| 7 |
|
| #include <unistd.h> |
| 8 |
|
| #include <string.h> |
| 9 |
|
| #include <ctype.h> |
| 10 |
|
| #include <errno.h> |
| 11 |
|
| #include <iconv.h> |
| 12 |
|
| |
| 13 |
|
| #include "parse-mpeg.h" |
| 14 |
|
| |
| 15 |
|
| // dvb_lib |
| 16 |
|
| #include "dvb_debug.h" |
| 17 |
|
| #include "dvb_lib.h" |
| 18 |
|
| |
| 19 |
|
| // Enable testing of multi-frequency handling |
| 20 |
|
| //#define TEST_MULTIFREQ |
| 21 |
|
| |
| 22 |
|
| #ifdef TEST_MULTIFREQ |
| 23 |
|
| |
| 24 |
|
| //idx = (tsid & 0xf000) >> 12 |
| 25 |
|
| // |
| 26 |
|
| //[4107] 0x100B idx=1 |
| 27 |
|
| //frequency = 578000000 |
| 28 |
|
| // |
| 29 |
|
| //[8199] 0x2007 idx=2 |
| 30 |
|
| //frequency = 850000000 |
| 31 |
|
| // |
| 32 |
|
| //[12290] 0x3002 idx=3 |
| 33 |
|
| //frequency = 713833330 |
| 34 |
|
| // |
| 35 |
|
| //[16384] 0x4000 idx=4 |
| 36 |
|
| //frequency = 721833330 |
| 37 |
|
| // |
| 38 |
|
| //[20480] 0x5000 idx=5 |
| 39 |
|
| //frequency = 690000000 |
| 40 |
|
| // |
| 41 |
|
| //[24576] 0x6000 idx=6 |
| 42 |
|
| //frequency = 538000000 |
| 43 |
|
| // |
| 44 |
|
| |
| 45 |
|
| // [idx][] - 1st entry is number of freqs, rest of entries are freq list |
| 46 |
|
| int other_freqs[8][8] = { |
| 47 |
|
| /* 0 */ {0, 0, 0, 0, 0, 0, 0, 0}, |
| 48 |
|
| /* 1 */ {3, 111111, 578000000, 12222222, 0, 0, 0, 0}, |
| 49 |
|
| /* 2 */ {4, 850000000, 21111111, 22222, 233333, 0, 0, 0}, |
| 50 |
|
| /* 3 */ {2, 311, 713833330, 0, 0, 0, 0, 0}, |
| 51 |
|
| /* 4 */ {3, 4111, 4222, 721833330, 0, 0, 0, 0}, |
| 52 |
|
| /* 5 */ {4, 51111, 52222, 53333, 690000000, 0, 0, 0}, |
| 53 |
|
| /* 6 */ {5, 611111, 622222, 633333, 644444, 538000000, 0, 0}, |
| 54 |
|
| /* 7 */ {0, 0, 0, 0, 0, 0, 0, 0}, |
| 55 |
|
| } ; |
| 56 |
|
| |
| 57 |
|
| #endif |
| 58 |
|
| |
| 59 |
|
| |
| 60 |
|
| /* ----------------------------------------------------------------------- */ |
| 61 |
0 |
| static unsigned int unbcd(unsigned int bcd) |
| 62 |
|
| { |
| 63 |
0 |
| unsigned int factor = 1; |
| 64 |
0 |
| unsigned int ret = 0; |
| 65 |
|
| unsigned int digit; |
| 66 |
|
| |
| 67 |
0 |
▶ | while (bcd) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (bcd) { |
0 |
0 |
0 |
|
| 68 |
0 |
| digit = bcd & 0x0f; |
| 69 |
0 |
| ret += digit * factor; |
| 70 |
0 |
| bcd /= 16; |
| 71 |
0 |
| factor *= 10; |
| 72 |
|
| } |
| 73 |
0 |
| return ret; |
| 74 |
|
| } |
| 75 |
|
| |
| 76 |
|
| /* ----------------------------------------------------------------------- */ |
| 77 |
0 |
| static int iconv_string(char *from, char *to, |
| 78 |
|
| char *src, size_t len, |
| 79 |
|
| char *dst, size_t max) |
| 80 |
|
| { |
| 81 |
0 |
▶ | size_t ilen = (-1 != len) ? len : strlen(src); |
Branch: 1 branch
| Branch | True | False | Total |
| size_t ilen = (-1 != len) ? len : strlen(src); |
0 |
0 |
0 |
|
| 82 |
0 |
| size_t olen = max-1; |
| 83 |
|
| iconv_t ic; |
| 84 |
|
| |
| 85 |
0 |
▶ | if (NULL == from) |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL == from) |
0 |
0 |
0 |
|
| 86 |
0 |
| return 0; |
| 87 |
0 |
| ic = iconv_open(to,from); |
| 88 |
0 |
▶ | if (NULL == ic) |
Branch: 1 branch
| Branch | True | False | Total |
| if (NULL == ic) |
0 |
0 |
0 |
|
| 89 |
0 |
| return 0; |
| 90 |
|
| |
| 91 |
0 |
▶ | while (ilen > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (ilen > 0) { |
0 |
0 |
0 |
|
| 92 |
0 |
▶ | if (-1 == iconv(ic,&src,&ilen,&dst,&olen)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (-1 == iconv(ic,&src,&ilen,&dst,&olen)) { |
0 |
0 |
0 |
|
| 93 |
|
| /* skip + quote broken byte unless we are out of space */ |
| 94 |
0 |
▶ | if (E2BIG == errno) |
Branch: 1 branch
| Branch | True | False | Total |
| if (E2BIG == errno) |
0 |
0 |
0 |
|
| 95 |
0 |
| break; |
| 96 |
0 |
▶ | if (olen < 4) |
Branch: 1 branch
| Branch | True | False | Total |
| if (olen < 4) |
0 |
0 |
0 |
|
| 97 |
0 |
| break; |
| 98 |
0 |
| sprintf(dst,"\\x%02x",(int)(unsigned char)src[0]); |
| 99 |
0 |
| src += 1; |
| 100 |
0 |
| dst += 4; |
| 101 |
0 |
| ilen -= 1; |
| 102 |
0 |
| olen -= 4; |
| 103 |
|
| } |
| 104 |
|
| } |
| 105 |
0 |
| dst[0] = 0; |
| 106 |
0 |
| iconv_close(ic); |
| 107 |
0 |
| return max-1 - olen; |
| 108 |
|
| } |
| 109 |
|
| |
| 110 |
|
| /* ----------------------------------------------------------------------- */ |
| 111 |
0 |
| static int handle_control_8(unsigned char *src, int slen, |
| 112 |
|
| unsigned char *dest, int dlen) |
| 113 |
|
| { |
| 114 |
|
| int s,d; |
| 115 |
|
| |
| 116 |
0 |
▶ | for (s = 0, d = 0; s < slen && d < dlen;) { |
Branch: 2 branches
| Branch | True | False | Total |
| for (s = 0, d = 0; s < slen && d < dlen;) { |
0 |
0 |
0 |
| for (s = 0, d = 0; s < slen && d < dlen;) { |
0 |
0 |
0 |
|
| 117 |
0 |
▶ | if (src[s] >= 0x80 && src[s] <= 0x9f) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (src[s] >= 0x80 && src[s] <= 0x9f) { |
0 |
0 |
0 |
| if (src[s] >= 0x80 && src[s] <= 0x9f) { |
0 |
0 |
0 |
|
| 118 |
0 |
| switch (src[s]) { |
| 119 |
0 |
| case 0x86: /* <em> */ |
| 120 |
|
| case 0x87: /* </em> */ |
| 121 |
0 |
| s++; |
| 122 |
0 |
| break; |
| 123 |
0 |
| case 0x1a: /* ^Z */ |
| 124 |
0 |
| dest[d++] = ' '; |
| 125 |
0 |
| s++; |
| 126 |
0 |
| break; |
| 127 |
0 |
| case 0x8a: /* <br> */ |
| 128 |
0 |
| dest[d++] = '\n'; |
| 129 |
0 |
| s++; |
| 130 |
0 |
| break; |
| 131 |
0 |
| default: |
| 132 |
0 |
| s++; |
| 133 |
|
| } |
| 134 |
|
| } else { |
| 135 |
0 |
| dest[d++] = src[s++]; |
| 136 |
|
| } |
| 137 |
|
| } |
| 138 |
0 |
| return d; |
| 139 |
|
| } |
| 140 |
|
| |
| 141 |
|
| /* ----------------------------------------------------------------------- */ |
| 142 |
0 |
| void mpeg_parse_psi_string(char *src, int slen, char *dest, int dlen) |
| 143 |
|
| { |
| 144 |
|
| char *tmp; |
| 145 |
|
| int tlen ; |
| 146 |
0 |
| unsigned ch = 0; |
| 147 |
0 |
| unsigned first_byte = (unsigned)src[0] ; |
| 148 |
|
| |
| 149 |
|
| //fprintf(stderr, "mpeg_parse_psi_string src len=%d [0x%02x ..], dest len=%d\n", slen, first_byte, dlen) ; |
| 150 |
|
| |
| 151 |
0 |
▶ | if (first_byte < 0x20) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (first_byte < 0x20) { |
0 |
0 |
0 |
|
| 152 |
0 |
| ch = first_byte; |
| 153 |
0 |
| src++; |
| 154 |
0 |
| slen--; |
| 155 |
|
| } |
| 156 |
|
| |
| 157 |
0 |
| memset(dest,0,dlen); |
| 158 |
|
| |
| 159 |
|
| //fprintf(stderr, " + ch = 0x%02x\n", ch) ; |
| 160 |
|
| |
| 161 |
0 |
▶ | if (ch < 0x10) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ch < 0x10) { |
0 |
0 |
0 |
|
| 162 |
|
| //fprintf(stderr, " + handle_control_8()\n") ; |
| 163 |
|
| /* 8bit charset */ |
| 164 |
0 |
| tmp = malloc(slen); |
| 165 |
|
| //fprintf(stderr, " + + malloc() %p\n", tmp) ; |
| 166 |
0 |
| tlen = handle_control_8(src, slen, tmp, slen); |
| 167 |
|
| //fprintf(stderr, " + + calling iconv_string() ...\n") ; |
| 168 |
0 |
| iconv_string(psi_charset[ch], "UTF-8", tmp, tlen, dest, dlen); |
| 169 |
|
| //fprintf(stderr, " + + free() %p\n", tmp) ; |
| 170 |
0 |
| free(tmp); |
| 171 |
|
| } else { |
| 172 |
|
| //fprintf(stderr, " + iconv()\n") ; |
| 173 |
|
| /* 16bit charset */ |
| 174 |
0 |
| iconv_string(psi_charset[ch], "UTF-8", src, slen, dest, dlen); |
| 175 |
|
| } |
| 176 |
|
| //fprintf(stderr, "mpeg_parse_psi_string - DONE\n") ; |
| 177 |
0 |
| } |
| 178 |
|
| |
| 179 |
|
| /* ======================================================================= */ |
| 180 |
|
| /* DESCRIPTORS |
| 181 |
|
| * |
| 182 |
|
| */ |
| 183 |
|
| |
| 184 |
|
| /* ----------------------------------------------------------------------- */ |
| 185 |
0 |
| static void parse_nit_desc_1(unsigned char *desc, int dlen, |
| 186 |
|
| char *dest, int max) |
| 187 |
|
| { |
| 188 |
|
| int i,t,l; |
| 189 |
|
| |
| 190 |
0 |
▶ | if (dvb_debug>1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (dvb_debug>1) |
0 |
0 |
0 |
|
| 191 |
0 |
| fprintf(stderr, |
| 192 |
|
| "parse_nit_desc_1()\n"); |
| 193 |
|
| |
| 194 |
0 |
▶ | for (i = 0; i < dlen; i += desc[i+1] +2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < dlen; i += desc[i+1] +2) { |
0 |
0 |
0 |
|
| 195 |
0 |
| t = desc[i]; |
| 196 |
0 |
| l = desc[i+1]; |
| 197 |
|
| |
| 198 |
0 |
▶ | if (dvb_debug>1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (dvb_debug>1) |
0 |
0 |
0 |
|
| 199 |
0 |
| fprintf_timestamp(stderr, |
| 200 |
|
| "ts [nit1]: t 0x%02x l %d\n", |
| 201 |
|
| t, l); |
| 202 |
|
| |
| 203 |
0 |
▶ | switch (t) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch (t) { |
0 |
0 |
0 |
|
| 204 |
0 |
| case 0x40: |
| 205 |
0 |
| mpeg_parse_psi_string((char*)desc+i+2, l, dest, max); |
| 206 |
0 |
| break; |
| 207 |
|
| } |
| 208 |
|
| } |
| 209 |
0 |
| } |
| 210 |
|
| |
| 211 |
|
| /* ----------------------------------------------------------------------- */ |
| 212 |
0 |
| static void parse_nit_desc_2(unsigned char *desc, int dlen, |
| 213 |
|
| struct psi_stream *stream, int tuned_freq) |
| 214 |
|
| { |
| 215 |
|
| static char *bw[4] = { |
| 216 |
|
| [ 0 ] = "8", |
| 217 |
|
| [ 1 ] = "7", |
| 218 |
|
| [ 2 ] = "6", |
| 219 |
|
| [ 3 ] = "5", |
| 220 |
|
| }; |
| 221 |
|
| static char *co_t[4] = { |
| 222 |
|
| [ 0 ] = "0", /* QPSK */ |
| 223 |
|
| [ 1 ] = "16", |
| 224 |
|
| [ 2 ] = "64", |
| 225 |
|
| }; |
| 226 |
|
| static char *co_c[16] = { |
| 227 |
|
| [ 0 ] = "0", |
| 228 |
|
| [ 1 ] = "16", |
| 229 |
|
| [ 2 ] = "32", |
| 230 |
|
| [ 3 ] = "64", |
| 231 |
|
| [ 4 ] = "128", |
| 232 |
|
| [ 5 ] = "256", |
| 233 |
|
| }; |
| 234 |
|
| static char *hi[4] = { |
| 235 |
|
| [ 0 ] = "0", |
| 236 |
|
| [ 1 ] = "1", |
| 237 |
|
| [ 2 ] = "2", |
| 238 |
|
| [ 3 ] = "4", |
| 239 |
|
| }; |
| 240 |
|
| static char *ra_t[8] = { |
| 241 |
|
| [ 0 ] = "12", |
| 242 |
|
| [ 1 ] = "23", |
| 243 |
|
| [ 2 ] = "34", |
| 244 |
|
| [ 3 ] = "56", |
| 245 |
|
| [ 4 ] = "78", |
| 246 |
|
| }; |
| 247 |
|
| static char *ra_sc[8] = { |
| 248 |
|
| [ 1 ] = "12", |
| 249 |
|
| [ 2 ] = "23", |
| 250 |
|
| [ 3 ] = "34", |
| 251 |
|
| [ 4 ] = "56", |
| 252 |
|
| [ 5 ] = "78", |
| 253 |
|
| }; |
| 254 |
|
| static char *gu[4] = { |
| 255 |
|
| [ 0 ] = "32", |
| 256 |
|
| [ 1 ] = "16", |
| 257 |
|
| [ 2 ] = "8", |
| 258 |
|
| [ 3 ] = "4", |
| 259 |
|
| }; |
| 260 |
|
| static char *tr[3] = { |
| 261 |
|
| [ 0 ] = "2", |
| 262 |
|
| [ 1 ] = "8", |
| 263 |
|
| [ 2 ] = "4", |
| 264 |
|
| }; |
| 265 |
|
| static char *po[4] = { |
| 266 |
|
| [ 0 ] = "H", |
| 267 |
|
| [ 1 ] = "V", |
| 268 |
|
| [ 2 ] = "L", // circular left |
| 269 |
|
| [ 3 ] = "R", // circular right |
| 270 |
|
| }; |
| 271 |
|
| unsigned int freq,rate,fec; |
| 272 |
|
| int i,j, t,l; |
| 273 |
|
| |
| 274 |
0 |
▶ | if (dvb_debug>1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (dvb_debug>1) |
0 |
0 |
0 |
|
| 275 |
0 |
| fprintf(stderr, |
| 276 |
|
| "parse_nit_desc_2()\n"); |
| 277 |
|
| |
| 278 |
0 |
▶ | for (i = 0; i < dlen; i += desc[i+1] +2) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < dlen; i += desc[i+1] +2) |
0 |
0 |
0 |
|
| 279 |
|
| { |
| 280 |
0 |
| t = desc[i]; |
| 281 |
0 |
| l = desc[i+1]; |
| 282 |
|
| |
| 283 |
0 |
▶ | if (dvb_debug>1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (dvb_debug>1) |
0 |
0 |
0 |
|
| 284 |
0 |
| fprintf_timestamp(stderr, |
| 285 |
|
| "ts [nit2]: t 0x%02x l %d\n", |
| 286 |
|
| t, l); |
| 287 |
|
| |
| 288 |
|
| |
| 289 |
0 |
| switch (t) { |
| 290 |
0 |
| case 0x43: /* dvb-s */ |
| 291 |
0 |
| freq = mpeg_getbits(desc+i+2, 0, 32); |
| 292 |
0 |
| rate = mpeg_getbits(desc+i+2, 56, 28); |
| 293 |
0 |
| fec = mpeg_getbits(desc+i+2, 85, 3); |
| 294 |
0 |
| stream->frequency = unbcd(freq) * 10; |
| 295 |
0 |
| stream->symbol_rate = unbcd(rate*16) * 10; |
| 296 |
0 |
| stream->fec_inner = ra_sc[fec]; |
| 297 |
0 |
| stream->polarization = po[ mpeg_getbits(desc+i+2, 49, 2) ]; |
| 298 |
0 |
| break; |
| 299 |
|
| |
| 300 |
0 |
| case 0x44: /* dvb-c */ |
| 301 |
0 |
| freq = mpeg_getbits(desc+i+2, 0, 32); |
| 302 |
0 |
| rate = mpeg_getbits(desc+i+2, 56, 28); |
| 303 |
0 |
| fec = mpeg_getbits(desc+i+2, 85, 3); |
| 304 |
0 |
| stream->frequency = unbcd(freq) * 100; |
| 305 |
0 |
| stream->symbol_rate = unbcd(rate*16) * 10; |
| 306 |
0 |
| stream->fec_inner = ra_sc[fec]; |
| 307 |
0 |
| stream->constellation = co_c[ mpeg_getbits(desc+i+2, 52, 4) ]; |
| 308 |
0 |
| break; |
| 309 |
|
| |
| 310 |
|
| |
| 311 |
0 |
| case 0x5a: /* dvb-t */ |
| 312 |
|
| // terrestrial_delivery_system_descriptor |
| 313 |
|
| |
| 314 |
|
| // centre_frequency 32 bslbf |
| 315 |
|
| // bandwidth 3 bslbf |
| 316 |
|
| // priority 1 bslbf |
| 317 |
|
| // Time_Slicing_indicator 1 bslbf |
| 318 |
|
| // MPE-FEC_indicator 1 bslbf |
| 319 |
|
| // reserved_future_use 2 bslbf |
| 320 |
|
| // constellation 2 bslbf |
| 321 |
|
| // hierarchy_information 3 bslbf |
| 322 |
|
| // code_rate-HP_stream 3 bslbf |
| 323 |
|
| // code_rate-LP_stream 3 bslbf |
| 324 |
|
| // guard_interval 2 bslbf |
| 325 |
|
| // transmission_mode 2 bslbf |
| 326 |
|
| // other_frequency_flag 1 bslbf |
| 327 |
|
| // reserved_future_use 32 bslbf |
| 328 |
|
| |
| 329 |
0 |
| stream->frequency = mpeg_getbits(desc+i+2, 0, 32) * 10; |
| 330 |
0 |
| stream->bandwidth = bw[ mpeg_getbits(desc+i+2, 33, 2) ]; |
| 331 |
0 |
| stream->constellation = co_t[ mpeg_getbits(desc+i+2, 40, 2) ]; |
| 332 |
0 |
| stream->hierarchy = hi[ mpeg_getbits(desc+i+2, 43, 2) ]; |
| 333 |
0 |
| stream->code_rate_hp = ra_t[ mpeg_getbits(desc+i+2, 45, 3) ]; |
| 334 |
0 |
| stream->code_rate_lp = ra_t[ mpeg_getbits(desc+i+2, 48, 3) ]; |
| 335 |
0 |
| stream->guard = gu[ mpeg_getbits(desc+i+2, 51, 2) ]; |
| 336 |
0 |
| stream->transmission = tr[ mpeg_getbits(desc+i+2, 54, 1) ]; |
| 337 |
0 |
| stream->other_freq = mpeg_getbits(desc+i+2, 55, 1); |
| 338 |
|
| |
| 339 |
0 |
▶ | if (dvb_debug>2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (dvb_debug>2) |
0 |
0 |
0 |
|
| 340 |
0 |
| fprintf(stderr, |
| 341 |
|
| "#@f terrestrial_delivery_system_descriptor: TSID %d freq=%d (other=%d) bw=%d (%s MHz) const=%d (%s) hier=%d (%s) rate hi=%d (%s) rate lo=%d (%s) guard=%d (%s) tr=%d (%s) : up=%d tuned=%d\n", |
| 342 |
|
| stream->tsid, |
| 343 |
|
| stream->frequency, |
| 344 |
|
| stream->other_freq, |
| 345 |
0 |
| mpeg_getbits(desc+i+2, 33, 2), |
| 346 |
|
| stream->bandwidth, |
| 347 |
0 |
| mpeg_getbits(desc+i+2, 40, 2), |
| 348 |
|
| stream->constellation, |
| 349 |
0 |
| mpeg_getbits(desc+i+2, 43, 2), |
| 350 |
|
| stream->hierarchy, |
| 351 |
0 |
| mpeg_getbits(desc+i+2, 45, 3), |
| 352 |
|
| stream->code_rate_hp, |
| 353 |
0 |
| mpeg_getbits(desc+i+2, 48, 3), |
| 354 |
|
| stream->code_rate_lp, |
| 355 |
0 |
| mpeg_getbits(desc+i+2, 51, 2), |
| 356 |
|
| stream->guard, |
| 357 |
0 |
| mpeg_getbits(desc+i+2, 54, 1), |
| 358 |
|
| stream->transmission, |
| 359 |
|
| stream->updated, stream->tuned |
| 360 |
|
| ); |
| 361 |
|
| |
| 362 |
|
| // Test where broadcast centre freq is invalid |
| 363 |
|
| #ifdef TEST_INVALID_CENTRE |
| 364 |
|
| |
| 365 |
|
| // mangle the real centre freq |
| 366 |
|
| stream->frequency = stream->tsid ; |
| 367 |
|
| |
| 368 |
|
| #endif |
| 369 |
|
| |
| 370 |
|
| |
| 371 |
|
| #ifdef TEST_MULTIFREQ |
| 372 |
|
| |
| 373 |
|
| // mangle the real centre freq |
| 374 |
|
| stream->frequency = stream->tsid ; |
| 375 |
|
| |
| 376 |
|
| // create freq list from table |
| 377 |
|
| { |
| 378 |
|
| int idx = (stream->tsid & 0xf000) >> 12 ; |
| 379 |
|
| int num_freqs = other_freqs[idx][0] ; |
| 380 |
|
| unsigned int freq_index ; |
| 381 |
|
| |
| 382 |
|
| if (dvb_debug>1) |
| 383 |
|
| fprintf(stderr, |
| 384 |
|
| "frequency_list_descriptor: num freqs=%d\n", |
| 385 |
|
| num_freqs); |
| 386 |
|
| |
| 387 |
|
| |
| 388 |
|
| stream->freq_list_len = num_freqs ; |
| 389 |
|
| stream->freq_list = malloc(num_freqs * sizeof(int)) ; |
| 390 |
|
| memset(stream->freq_list, 0, num_freqs * sizeof(int)) ; |
| 391 |
|
| for (freq_index=0; freq_index < num_freqs; ++freq_index) |
| 392 |
|
| { |
| 393 |
|
| int freq = other_freqs[idx][freq_index+1]; |
| 394 |
|
| |
| 395 |
|
| if (dvb_debug>1) |
| 396 |
|
| fprintf(stderr, |
| 397 |
|
| "frequency_list_descriptor: freq[%d]=%d\n", |
| 398 |
|
| freq_index, freq); |
| 399 |
|
| |
| 400 |
|
| stream->freq_list[freq_index] = freq ; |
| 401 |
|
| } |
| 402 |
|
| |
| 403 |
|
| } |
| 404 |
|
| #endif |
| 405 |
|
| |
| 406 |
0 |
▶ | if (dvb_debug > 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (dvb_debug > 1) |
0 |
0 |
0 |
|
| 407 |
|
| { |
| 408 |
0 |
| fprintf(stderr, |
| 409 |
|
| "terrestrial_delivery_system_descriptor:: Freq=%d\n", |
| 410 |
|
| stream->frequency); |
| 411 |
|
| |
| 412 |
|
| } |
| 413 |
0 |
| break; |
| 414 |
|
| |
| 415 |
0 |
| case 0x62: /* freq list */ |
| 416 |
|
| { |
| 417 |
|
| unsigned int coding_type ; |
| 418 |
|
| int num_freqs ; |
| 419 |
|
| |
| 420 |
|
| // frequency_list_descriptor(){ |
| 421 |
|
| // descriptor_tag 8 uimsbf |
| 422 |
|
| // descriptor_length 8 uimsbf |
| 423 |
|
| // reserved_future_use 6 bslbf |
| 424 |
|
| // coding_type 2 bslbf |
| 425 |
|
| // for (i=0;I<N;i++){ |
| 426 |
|
| // centre_frequency 32 uimsbf |
| 427 |
|
| // } |
| 428 |
|
| // } |
| 429 |
|
| // Table 54: Coding type values |
| 430 |
|
| // Coding_type Delivery system |
| 431 |
|
| // 00 not defined |
| 432 |
|
| // 01 satellite |
| 433 |
|
| // 10 cable |
| 434 |
|
| // 11 terrestrial |
| 435 |
|
| |
| 436 |
0 |
| j = 0; |
| 437 |
0 |
| coding_type = mpeg_getbits(desc+i+2, j+6, 2) ; |
| 438 |
0 |
| j+=8 ; |
| 439 |
|
| |
| 440 |
0 |
| num_freqs = (l - 1) / 4 ; |
| 441 |
|
| |
| 442 |
0 |
▶ | if (dvb_debug>1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (dvb_debug>1) |
0 |
0 |
0 |
|
| 443 |
0 |
| fprintf(stderr, |
| 444 |
|
| "frequency_list_descriptor: num freqs=%d\n", |
| 445 |
|
| num_freqs); |
| 446 |
|
| |
| 447 |
0 |
▶ | if ((coding_type == 3) && (num_freqs > 0)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((coding_type == 3) && (num_freqs > 0)) |
0 |
0 |
0 |
| if ((coding_type == 3) && (num_freqs > 0)) |
0 |
0 |
0 |
|
| 448 |
|
| { |
| 449 |
0 |
| unsigned int freq_index=0 ; |
| 450 |
|
| |
| 451 |
0 |
| stream->freq_list_len = num_freqs ; |
| 452 |
0 |
| stream->freq_list = malloc(num_freqs * sizeof(int)) ; |
| 453 |
0 |
| memset(stream->freq_list, 0, num_freqs * sizeof(int)) ; |
| 454 |
0 |
▶ | while (j < l*8) |
Branch: 1 branch
| Branch | True | False | Total |
| while (j < l*8) |
0 |
0 |
0 |
|
| 455 |
|
| { |
| 456 |
|
| int freq ; |
| 457 |
|
| |
| 458 |
0 |
| freq = mpeg_getbits(desc+i+2, j, 32) * 10 ; |
| 459 |
|
| |
| 460 |
0 |
▶ | if (dvb_debug>1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (dvb_debug>1) |
0 |
0 |
0 |
|
| 461 |
0 |
| fprintf(stderr, |
| 462 |
|
| "frequency_list_descriptor: freq[%d]=%d\n", |
| 463 |
|
| freq_index, freq); |
| 464 |
|
| |
| 465 |
0 |
| stream->freq_list[freq_index++] = freq ; |
| 466 |
|
| |
| 467 |
0 |
| j += 32; |
| 468 |
|
| } |
| 469 |
|
| } |
| 470 |
|
| |
| 471 |
|
| } |
| 472 |
0 |
| break; |
| 473 |
|
| |
| 474 |
|
| #ifndef TEST_MULTIFREQ |
| 475 |
|
| |
| 476 |
0 |
| case 0x83 : /* LCN */ |
| 477 |
|
| |
| 478 |
0 |
| j = 0; |
| 479 |
0 |
▶ | while (j < l*8) |
Branch: 1 branch
| Branch | True | False | Total |
| while (j < l*8) |
0 |
0 |
0 |
|
| 480 |
|
| { |
| 481 |
|
| int sid, visible, lcn ; |
| 482 |
|
| struct prog_info *pinfo; |
| 483 |
|
| |
| 484 |
|
| |
| 485 |
|
| // service_id 16 uimsbf |
| 486 |
|
| // visible_service_flag 1 bslbf |
| 487 |
|
| // reserved 5 bslbf |
| 488 |
|
| // logical_channel_number 10 uimsbf |
| 489 |
0 |
| sid = mpeg_getbits(desc+i+2, j, 16) ; |
| 490 |
0 |
| visible = mpeg_getbits(desc+i+2, j+17, 1) ; |
| 491 |
0 |
| lcn = mpeg_getbits(desc+i+2, j+22, 10) ; |
| 492 |
|
| |
| 493 |
0 |
▶ | if (dvb_debug>1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (dvb_debug>1) |
0 |
0 |
0 |
|
| 494 |
0 |
| fprintf(stderr, |
| 495 |
|
| "#@p LCN: service_id=%d (0x%04x) visible=%d lcn=%d (0x%03x)\n", |
| 496 |
|
| sid, sid, visible, lcn, lcn); |
| 497 |
|
| |
| 498 |
0 |
| pinfo = prog_info_get(stream, sid, 1) ; |
| 499 |
0 |
| pinfo->visible = visible ; |
| 500 |
0 |
| pinfo->lcn = lcn ; |
| 501 |
|
| |
| 502 |
0 |
| j += 32; |
| 503 |
|
| } |
| 504 |
|
| |
| 505 |
0 |
| break ; |
| 506 |
|
| #endif |
| 507 |
|
| |
| 508 |
|
| |
| 509 |
0 |
| case 0x41: /* service list descriptor */ |
| 510 |
|
| |
| 511 |
|
| //service_list_descriptor(){ |
| 512 |
|
| // descriptor_tag 8 uimsbf |
| 513 |
|
| // descriptor_length 8 uimsbf |
| 514 |
|
| // for (i=0;i<N;I++){ |
| 515 |
|
| // service_id 16 uimsbf |
| 516 |
|
| // service_type 8 uimsbf |
| 517 |
|
| // } |
| 518 |
|
| //} |
| 519 |
|
| |
| 520 |
0 |
| j = 0; |
| 521 |
0 |
▶ | while (j < l*8) |
Branch: 1 branch
| Branch | True | False | Total |
| while (j < l*8) |
0 |
0 |
0 |
|
| 522 |
|
| { |
| 523 |
|
| int sid, service_type ; |
| 524 |
|
| struct prog_info *pinfo; |
| 525 |
|
| |
| 526 |
0 |
| sid = mpeg_getbits(desc+i+2, j, 16) ; |
| 527 |
0 |
| service_type = mpeg_getbits(desc+i+2, j+17, 8) ; |
| 528 |
|
| |
| 529 |
0 |
▶ | if (dvb_debug>1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (dvb_debug>1) |
0 |
0 |
0 |
|
| 530 |
0 |
| fprintf(stderr, |
| 531 |
|
| "service_list_descriptor: service_id=%d (0x%04x) service_type=%d (0x%02x)\n", |
| 532 |
|
| sid, sid, service_type, service_type); |
| 533 |
|
| |
| 534 |
0 |
| pinfo = prog_info_get(stream, sid, 1) ; |
| 535 |
0 |
| pinfo->service_type = service_type ; |
| 536 |
|
| |
| 537 |
0 |
| j += 24; |
| 538 |
|
| } |
| 539 |
0 |
| break ; |
| 540 |
|
| |
| 541 |
|
| } |
| 542 |
|
| } |
| 543 |
0 |
| return; |
| 544 |
|
| } |
| 545 |
|
| |
| 546 |
|
| /* ----------------------------------------------------------------------- */ |
| 547 |
0 |
| static void parse_sdt_desc(unsigned char *desc, int dlen, |
| 548 |
|
| struct psi_program *pr, int tuned_freq, int verbose) |
| 549 |
|
| { |
| 550 |
|
| int i,t,l; |
| 551 |
|
| char *name,*net; |
| 552 |
|
| |
| 553 |
0 |
▶ | for (i = 0; i < dlen; i += desc[i+1] +2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < dlen; i += desc[i+1] +2) { |
0 |
0 |
0 |
|
| 554 |
0 |
| t = desc[i]; |
| 555 |
0 |
| l = desc[i+1]; |
| 556 |
|
| |
| 557 |
0 |
▶ | switch (t) { |
Branch: 1 branch
| Branch | True | False | Total |
| switch (t) { |
0 |
0 |
0 |
|
| 558 |
0 |
| case 0x48: |
| 559 |
0 |
| pr->type = desc[i+2]; |
| 560 |
0 |
| pr->updated = 1; |
| 561 |
0 |
| net = (char*)desc + i+3; |
| 562 |
0 |
| name = net + net[0] + 1; |
| 563 |
0 |
| mpeg_parse_psi_string(net+1, net[0], pr->net, sizeof(pr->net)); |
| 564 |
0 |
| mpeg_parse_psi_string(name+1, name[0], pr->name, sizeof(pr->name)); |
| 565 |
|
| |
| 566 |
0 |
▶ | if (verbose) fprintf(stderr," pnr %5d %s\n", pr->pnr, pr->name); |
Branch: 1 branch
| Branch | True | False | Total |
| if (verbose) fprintf(stderr," pnr %5d %s\n", pr->pnr, pr->name); |
0 |
0 |
0 |
|
| 567 |
|
| |
| 568 |
0 |
▶ | if (dvb_debug > 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (dvb_debug > 2) |
0 |
0 |
0 |
|
| 569 |
0 |
| fprintf(stderr,"#@p parse_sdt_desc() : tuned=%d : tsid=%d pnr=%d name=%s [v=%d a=%d]\n", |
| 570 |
|
| tuned_freq, |
| 571 |
0 |
| pr->tsid, pr->pnr, pr->name, pr->v_pid, pr->a_pid); |
| 572 |
0 |
| break; |
| 573 |
|
| } |
| 574 |
|
| } |
| 575 |
0 |
| } |
| 576 |
|
| |
| 577 |
|
| /* ======================================================================= */ |
| 578 |
|
| /* TABLES |
| 579 |
|
| * |
| 580 |
|
| */ |
| 581 |
|
| |
| 582 |
|
| /* ----------------------------------------------------------------------- */ |
| 583 |
0 |
| int mpeg_parse_psi_sdt(struct psi_info *info, unsigned char *data, int verbose, int tuned_freq) |
| 584 |
|
| { |
| 585 |
|
| static const char *running[] = { |
| 586 |
|
| [ 0 ] = "undefined", |
| 587 |
|
| [ 1 ] = "not running", |
| 588 |
|
| [ 2 ] = "starts soon", |
| 589 |
|
| [ 3 ] = "pausing", |
| 590 |
|
| [ 4 ] = "running", |
| 591 |
|
| [ 5 ... 8 ] = "reserved", |
| 592 |
|
| }; |
| 593 |
|
| struct psi_program *pr; |
| 594 |
|
| int tsid,pnr,version,current; |
| 595 |
|
| int j,len,dlen,run,ca; |
| 596 |
|
| |
| 597 |
0 |
| len = mpeg_getbits(data,12,12) + 3 - 4; |
| 598 |
0 |
| tsid = mpeg_getbits(data,24,16); |
| 599 |
0 |
| version = mpeg_getbits(data,42,5); |
| 600 |
0 |
| current = mpeg_getbits(data,47,1); |
| 601 |
0 |
▶ | if (!current) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!current) |
0 |
0 |
0 |
|
| 602 |
0 |
| return len+4; |
| 603 |
0 |
▶ | if (info->tsid == tsid && info->sdt_version == version) |
Branch: 2 branches
| Branch | True | False | Total |
| if (info->tsid == tsid && info->sdt_version == version) |
0 |
0 |
0 |
| if (info->tsid == tsid && info->sdt_version == version) |
0 |
0 |
0 |
|
| 604 |
0 |
| return len+4; |
| 605 |
0 |
| info->sdt_version = version; |
| 606 |
|
| |
| 607 |
0 |
▶ | if (verbose>1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (verbose>1) |
0 |
0 |
0 |
|
| 608 |
0 |
| fprintf_timestamp(stderr, |
| 609 |
|
| "ts [sdt]: tsid %d ver %2d [%d/%d]\n", |
| 610 |
|
| tsid, version, |
| 611 |
|
| mpeg_getbits(data,48, 8), |
| 612 |
|
| mpeg_getbits(data,56, 8)); |
| 613 |
|
| |
| 614 |
0 |
| j = 88; |
| 615 |
0 |
▶ | while (j < len*8) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (j < len*8) { |
0 |
0 |
0 |
|
| 616 |
0 |
| pnr = mpeg_getbits(data,j,16); |
| 617 |
0 |
| run = mpeg_getbits(data,j+24,3); |
| 618 |
0 |
| ca = mpeg_getbits(data,j+27,1); |
| 619 |
0 |
| dlen = mpeg_getbits(data,j+28,12); |
| 620 |
0 |
▶ | if (verbose > 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (verbose > 2) { |
0 |
0 |
0 |
|
| 621 |
0 |
| fprintf(stderr," (freq=%d) pnr %3d ca %d %s #", |
| 622 |
|
| tuned_freq, pnr, ca, running[run]); |
| 623 |
0 |
| mpeg_dump_desc(data+j/8+5,dlen); |
| 624 |
0 |
| fprintf(stderr,"\n"); |
| 625 |
|
| } |
| 626 |
0 |
| pr = psi_program_get(info, tsid, pnr, tuned_freq, 1); |
| 627 |
0 |
| parse_sdt_desc(data+j/8+5,dlen,pr,tuned_freq, verbose); |
| 628 |
0 |
| pr->running = run; |
| 629 |
0 |
| pr->ca = ca; |
| 630 |
0 |
| j += 40 + dlen*8; |
| 631 |
|
| } |
| 632 |
0 |
▶ | if (verbose > 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (verbose > 2) |
0 |
0 |
0 |
|
| 633 |
0 |
| fprintf(stderr,"\n"); |
| 634 |
0 |
| return len+4; |
| 635 |
|
| } |
| 636 |
|
| |
| 637 |
|
| /* ----------------------------------------------------------------------- */ |
| 638 |
|
| // network_information_section(){ |
| 639 |
|
| // table_id 8 uimsbf |
| 640 |
|
| // section_syntax_indicator 1 bslbf |
| 641 |
|
| // reserved_future_use 1 bslbf |
| 642 |
|
| // reserved 2 bslbf |
| 643 |
|
| // section_length 12 uimsbf |
| 644 |
|
| // |
| 645 |
|
| // network_id 16 uimsbf |
| 646 |
|
| // reserved 2 bslbf |
| 647 |
|
| // version_number 5 uimsbf |
| 648 |
|
| // current_next_indicator 1 bslbf |
| 649 |
|
| // section_number 8 uimsbf |
| 650 |
|
| // last_section_number 8 uimsbf |
| 651 |
|
| // |
| 652 |
|
| // reserved_future_use 4 bslbf |
| 653 |
|
| // network_descriptors_length 12 uimsbf |
| 654 |
|
| // for(i=0;i<N;i++){ |
| 655 |
|
| // descriptor() |
| 656 |
|
| // } |
| 657 |
|
| // reserved_future_use 4 bslbf |
| 658 |
|
| // transport_stream_loop_length 12 uimsbf |
| 659 |
|
| // for(i=0;i<N;i++){ |
| 660 |
|
| // transport_stream_id 16 uimsbf |
| 661 |
|
| // original_network_id 16 uimsbf |
| 662 |
|
| // reserved_future_use 4 bslbf |
| 663 |
|
| // transport_descriptors_length 12 uimsbf |
| 664 |
|
| // for(j=0;j<N;j++){ |
| 665 |
|
| // descriptor() |
| 666 |
|
| // } |
| 667 |
|
| // } |
| 668 |
|
| // CRC_32 32 rpchof |
| 669 |
|
| // } |
| 670 |
0 |
| int mpeg_parse_psi_nit(struct psi_info *info, unsigned char *data, int verbose, int tuned_freq) |
| 671 |
|
| { |
| 672 |
|
| struct psi_stream *stream; |
| 673 |
0 |
| char network[PSI_STR_MAX] = ""; |
| 674 |
|
| int id,version,current,len; |
| 675 |
|
| int j,dlen,tsid; |
| 676 |
|
| |
| 677 |
|
| |
| 678 |
0 |
| len = mpeg_getbits(data,12,12) + 3 - 4; |
| 679 |
0 |
| id = mpeg_getbits(data,24,16); /* network_id */ |
| 680 |
0 |
| version = mpeg_getbits(data,42,5); |
| 681 |
0 |
| current = mpeg_getbits(data,47,1); |
| 682 |
|
| |
| 683 |
0 |
▶ | if (!current) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!current) |
0 |
0 |
0 |
|
| 684 |
0 |
| return len+4; |
| 685 |
|
| |
| 686 |
|
| if (0 /* info->id == id */ && info->nit_version == version) |
| 687 |
|
| return len+4; |
| 688 |
0 |
| info->nit_version = version; |
| 689 |
|
| |
| 690 |
0 |
| j = 80; |
| 691 |
0 |
| dlen = mpeg_getbits(data,68,12); |
| 692 |
0 |
| parse_nit_desc_1(data + j/8, dlen, network, sizeof(network)); |
| 693 |
|
| |
| 694 |
0 |
▶ | if (verbose>1) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (verbose>1) { |
0 |
0 |
0 |
|
| 695 |
0 |
| fprintf_timestamp(stderr, |
| 696 |
|
| "ts [nit]: id %3d ver %2d [%d/%d] #", |
| 697 |
|
| id, version, |
| 698 |
|
| mpeg_getbits(data,48, 8), |
| 699 |
|
| mpeg_getbits(data,56, 8)); |
| 700 |
0 |
| mpeg_dump_desc(data + j/8, dlen); |
| 701 |
0 |
| fprintf(stderr,"\n"); |
| 702 |
|
| } |
| 703 |
0 |
| j += 16 + 8*dlen; |
| 704 |
|
| |
| 705 |
0 |
▶ | while (j < len*8) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (j < len*8) { |
0 |
0 |
0 |
|
| 706 |
0 |
| tsid = mpeg_getbits(data,j,16); |
| 707 |
0 |
| dlen = mpeg_getbits(data,j+36,12); |
| 708 |
0 |
| j += 48; |
| 709 |
|
| |
| 710 |
0 |
| stream = psi_stream_get(info, tsid, id, 1); |
| 711 |
|
| |
| 712 |
0 |
| stream->updated = 1; |
| 713 |
|
| if (network) |
| 714 |
0 |
| strcpy(stream->net, network); |
| 715 |
0 |
| parse_nit_desc_2(data + j/8, dlen, stream, tuned_freq); |
| 716 |
0 |
▶ | if (verbose > 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (verbose > 2) { |
0 |
0 |
0 |
|
| 717 |
0 |
| fprintf(stderr," tsid %3d #", tsid); |
| 718 |
0 |
| mpeg_dump_desc(data + j/8, dlen); |
| 719 |
0 |
| fprintf(stderr,"\n"); |
| 720 |
|
| } |
| 721 |
0 |
| j += 8*dlen; |
| 722 |
|
| } |
| 723 |
|
| |
| 724 |
0 |
▶ | if (verbose > 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (verbose > 2) |
0 |
0 |
0 |
|
| 725 |
0 |
| fprintf(stderr,"\n"); |
| 726 |
|
| |
| 727 |
0 |
| return len+4; |
| 728 |
|
| } |