1 |
#include <stdio.h> |
---|
2 |
#include <stdlib.h> |
---|
3 |
#include <string.h> |
---|
4 |
|
---|
5 |
#include "eit.h" |
---|
6 |
|
---|
7 |
char *subtitle_cnv_str[] = { |
---|
8 |
NULL |
---|
9 |
}; |
---|
10 |
static void timecmp(int *,int *,int *, |
---|
11 |
int, int, int); |
---|
12 |
|
---|
13 |
int parseEIThead(unsigned char *data, EIThead *h) { |
---|
14 |
int boff = 0; |
---|
15 |
|
---|
16 |
memset(h, 0, sizeof(EIThead)); |
---|
17 |
|
---|
18 |
h->table_id = getBit(data, &boff, 8); |
---|
19 |
h->section_syntax_indicator = getBit(data, &boff, 1); |
---|
20 |
h->reserved_future_use = getBit(data, &boff, 1); |
---|
21 |
h->reserved1 = getBit(data, &boff, 2); |
---|
22 |
h->section_length =getBit(data, &boff,12); |
---|
23 |
h->service_id = getBit(data, &boff, 16); |
---|
24 |
h->reserved2 = getBit(data, &boff, 2); |
---|
25 |
h->version_number = getBit(data, &boff, 5); |
---|
26 |
h->current_next_indicator = getBit(data, &boff, 1); |
---|
27 |
h->section_number = getBit(data, &boff, 8); |
---|
28 |
h->last_section_number = getBit(data, &boff, 8); |
---|
29 |
h->transport_stream_id = getBit(data, &boff, 16); |
---|
30 |
h->original_network_id = getBit(data, &boff, 16); |
---|
31 |
h->segment_last_section_number = getBit(data, &boff, 8); |
---|
32 |
h->last_table_id = getBit(data, &boff, 8); |
---|
33 |
|
---|
34 |
return 14; |
---|
35 |
} |
---|
36 |
|
---|
37 |
int parseEITbody(unsigned char *data, EITbody *b) |
---|
38 |
{ |
---|
39 |
int boff = 0; |
---|
40 |
int tnum; |
---|
41 |
char buf[4]; |
---|
42 |
|
---|
43 |
memset(b, 0, sizeof(EITbody)); |
---|
44 |
|
---|
45 |
b->event_id = getBit(data, &boff, 16); |
---|
46 |
|
---|
47 |
memcpy(b->start_time, data + boff / 8, 5); |
---|
48 |
|
---|
49 |
boff += 40; |
---|
50 |
memcpy(b->duration, data + boff / 8, 3); |
---|
51 |
|
---|
52 |
boff += 24; |
---|
53 |
b->running_status = getBit(data, &boff, 3); |
---|
54 |
b->free_CA_mode = getBit(data, &boff, 1); |
---|
55 |
b->descriptors_loop_length = getBit(data, &boff, 12); |
---|
56 |
|
---|
57 |
|
---|
58 |
tnum = (b->start_time[0] & 0xFF) << 8 | (b->start_time[1] & 0xFF); |
---|
59 |
|
---|
60 |
b->yy = (tnum - 15078.2) / 365.25; |
---|
61 |
b->mm = ((tnum - 14956.1) - (int)(b->yy * 365.25)) / 30.6001; |
---|
62 |
b->dd = (tnum - 14956) - (int)(b->yy * 365.25) - (int)(b->mm * 30.6001); |
---|
63 |
|
---|
64 |
if(b->dd == 0) { |
---|
65 |
printf("aa"); |
---|
66 |
} |
---|
67 |
|
---|
68 |
if(b->mm == 14 || b->mm == 15) { |
---|
69 |
b->yy += 1; |
---|
70 |
b->mm = b->mm - 1 - (1 * 12); |
---|
71 |
} else { |
---|
72 |
b->mm = b->mm - 1; |
---|
73 |
} |
---|
74 |
|
---|
75 |
b->yy += 1900; |
---|
76 |
|
---|
77 |
memset(buf, '\0', sizeof(buf)); |
---|
78 |
sprintf(buf, "%x", b->start_time[2]); |
---|
79 |
b->hh = atoi(buf); |
---|
80 |
memset(buf, '\0', sizeof(buf)); |
---|
81 |
sprintf(buf, "%x", b->start_time[3]); |
---|
82 |
b->hm = atoi(buf); |
---|
83 |
memset(buf, '\0', sizeof(buf)); |
---|
84 |
sprintf(buf, "%x", b->start_time[4]); |
---|
85 |
b->ss = atoi(buf); |
---|
86 |
|
---|
87 |
if((b->duration[0] == 0xFF) && (b->duration[1] == 0xFF) && (b->duration[2] == 0xFF)){ |
---|
88 |
b->dhh = b->dhm = b->dss = 0; |
---|
89 |
}else{ |
---|
90 |
memset(buf, '\0', sizeof(buf)); |
---|
91 |
sprintf(buf, "%x", b->duration[0]); |
---|
92 |
b->dhh = atoi(buf); |
---|
93 |
memset(buf, '\0', sizeof(buf)); |
---|
94 |
sprintf(buf, "%x", b->duration[1]); |
---|
95 |
b->dhm = atoi(buf); |
---|
96 |
memset(buf, '\0', sizeof(buf)); |
---|
97 |
sprintf(buf, "%x", b->duration[2]); |
---|
98 |
b->dss = atoi(buf); |
---|
99 |
} |
---|
100 |
return 12; |
---|
101 |
} |
---|
102 |
|
---|
103 |
int parseSEVTdesc(unsigned char *data, SEVTdesc *desc) { |
---|
104 |
int boff = 0; |
---|
105 |
|
---|
106 |
memset(desc, 0, sizeof(SEVTdesc)); |
---|
107 |
|
---|
108 |
desc->descriptor_tag = getBit(data, &boff, 8); |
---|
109 |
if((desc->descriptor_tag & 0xFF) != 0x4D) { |
---|
110 |
return -1; |
---|
111 |
} |
---|
112 |
desc->descriptor_length = getBit(data, &boff, 8); |
---|
113 |
memcpy(desc->ISO_639_language_code, data + boff / 8, 3); |
---|
114 |
|
---|
115 |
boff += 24; |
---|
116 |
desc->event_name_length = getBit(data, &boff, 8); |
---|
117 |
getStr(desc->event_name, data, &boff, desc->event_name_length); |
---|
118 |
desc->text_length = getBit(data, &boff, 8); |
---|
119 |
getStr(desc->text, data, &boff, desc->text_length); |
---|
120 |
|
---|
121 |
return desc->descriptor_length + 2; |
---|
122 |
} |
---|
123 |
|
---|
124 |
int parseContentDesc(unsigned char *data, ContentDesc *desc) { |
---|
125 |
int boff = 0; |
---|
126 |
|
---|
127 |
memset(desc, 0, sizeof(ContentDesc)); |
---|
128 |
|
---|
129 |
desc->descriptor_tag = getBit(data, &boff, 8); |
---|
130 |
if((desc->descriptor_tag & 0xFF) != 0x54) { |
---|
131 |
return -1; |
---|
132 |
} |
---|
133 |
desc->descriptor_length = getBit(data, &boff, 8); |
---|
134 |
memcpy(desc->content, data+(boff/8), desc->descriptor_length); |
---|
135 |
|
---|
136 |
return desc->descriptor_length + 2; |
---|
137 |
} |
---|
138 |
|
---|
139 |
int parseSeriesDesc(unsigned char *data, SeriesDesc *desc) { |
---|
140 |
int boff = 0; |
---|
141 |
|
---|
142 |
memset(desc, 0, sizeof(SeriesDesc)); |
---|
143 |
|
---|
144 |
desc->descriptor_tag = getBit(data, &boff, 8); |
---|
145 |
if((desc->descriptor_tag & 0xFF) != 0xD5) { |
---|
146 |
return -1; |
---|
147 |
} |
---|
148 |
desc->descriptor_length = getBit(data, &boff, 8); |
---|
149 |
desc->series_id = getBit(data, &boff, 16); |
---|
150 |
desc->repeat_label = getBit(data, &boff, 4); |
---|
151 |
desc->program_pattern = getBit(data, &boff, 3); |
---|
152 |
desc->expire_date_valid_flag = getBit(data, &boff, 1); |
---|
153 |
|
---|
154 |
desc->expire_date = getBit(data, &boff, 16); |
---|
155 |
|
---|
156 |
|
---|
157 |
|
---|
158 |
desc->episode_number = getBit(data, &boff, 12); |
---|
159 |
desc->last_episode_number = getBit(data, &boff, 12); |
---|
160 |
|
---|
161 |
getStr(desc->series_name_char, data, &boff, desc->descriptor_length - 8); |
---|
162 |
return desc->descriptor_length + 2; |
---|
163 |
} |
---|
164 |
|
---|
165 |
int parseEEVTDhead(unsigned char *data, EEVTDhead *desc) { |
---|
166 |
int boff = 0; |
---|
167 |
|
---|
168 |
memset(desc, 0, sizeof(EEVTDhead)); |
---|
169 |
|
---|
170 |
desc->descriptor_tag = getBit(data, &boff, 8); |
---|
171 |
if((desc->descriptor_tag & 0xFF) != 0x4E) { |
---|
172 |
return -1; |
---|
173 |
} |
---|
174 |
desc->descriptor_length = getBit(data, &boff, 8); |
---|
175 |
desc->descriptor_number = getBit(data, &boff, 4); |
---|
176 |
desc->last_descriptor_number = getBit(data, &boff, 4); |
---|
177 |
memcpy(desc->ISO_639_language_code, data + boff / 8, 3); |
---|
178 |
|
---|
179 |
boff += 24; |
---|
180 |
|
---|
181 |
desc->length_of_items = getBit(data, &boff, 8); |
---|
182 |
|
---|
183 |
return 7; |
---|
184 |
} |
---|
185 |
|
---|
186 |
int parseEEVTDitem(unsigned char *data, EEVTDitem *desc) { |
---|
187 |
int boff = 0; |
---|
188 |
|
---|
189 |
memset(desc, 0, sizeof(EEVTDitem)); |
---|
190 |
|
---|
191 |
desc->item_description_length = getBit(data, &boff, 8); |
---|
192 |
getStr(desc->item_description, data, &boff, desc->item_description_length); |
---|
193 |
|
---|
194 |
desc->item_length = getBit(data, &boff, 8); |
---|
195 |
memcpy(desc->item, data + (boff / 8), desc->item_length); |
---|
196 |
|
---|
197 |
|
---|
198 |
return desc->item_description_length + desc->item_length + 2; |
---|
199 |
} |
---|
200 |
|
---|
201 |
int parseEEVTDtail(unsigned char *data, EEVTDtail *desc) { |
---|
202 |
int boff = 0; |
---|
203 |
|
---|
204 |
memset(desc, 0, sizeof(EEVTDtail)); |
---|
205 |
|
---|
206 |
desc->text_length = getBit(data, &boff, 8); |
---|
207 |
getStr(desc->text, data, &boff, desc->text_length); |
---|
208 |
|
---|
209 |
return desc->text_length + 1; |
---|
210 |
} |
---|
211 |
|
---|
212 |
int checkEEVTDitem(EEVTDitem *save, EEVTDitem *new, int descriptor_number) { |
---|
213 |
|
---|
214 |
EEVTDitem swap; |
---|
215 |
int boff = 0; |
---|
216 |
|
---|
217 |
if(new == NULL) { |
---|
218 |
if(save->item_length != 0) { |
---|
219 |
swap = *save; |
---|
220 |
getStr(save->item, (unsigned char*)swap.item, &boff, swap.item_length); |
---|
221 |
return 1; |
---|
222 |
} else { |
---|
223 |
return 0; |
---|
224 |
} |
---|
225 |
} |
---|
226 |
|
---|
227 |
if(new->item_description_length == 0) { |
---|
228 |
|
---|
229 |
memcpy(save->item + save->item_length, new->item, new->item_length); |
---|
230 |
save->item_length += new->item_length; |
---|
231 |
return 0; |
---|
232 |
} else { |
---|
233 |
|
---|
234 |
if(save->item_length != 0) { |
---|
235 |
|
---|
236 |
swap = *save; |
---|
237 |
getStr(save->item, (unsigned char*)swap.item, &boff, swap.item_length); |
---|
238 |
swap = *new; |
---|
239 |
*new = *save; |
---|
240 |
*save = swap; |
---|
241 |
save->descriptor_number = descriptor_number; |
---|
242 |
} else { |
---|
243 |
*save = *new; |
---|
244 |
save->descriptor_number = descriptor_number; |
---|
245 |
return 0; |
---|
246 |
} |
---|
247 |
} |
---|
248 |
|
---|
249 |
return 1; |
---|
250 |
} |
---|
251 |
EIT_CONTROL *searcheit(EIT_CONTROL *top, int servid, int eventid) |
---|
252 |
{ |
---|
253 |
EIT_CONTROL *cur ; |
---|
254 |
cur = top ; |
---|
255 |
|
---|
256 |
while(cur != NULL){ |
---|
257 |
if((cur->event_id == eventid) && (cur->servid == servid)){ |
---|
258 |
return cur ; |
---|
259 |
} |
---|
260 |
|
---|
261 |
cur = cur->next ; |
---|
262 |
} |
---|
263 |
return NULL ; |
---|
264 |
} |
---|
265 |
char *strstr_eucjp(const char *str, const char *search) |
---|
266 |
{ |
---|
267 |
char *pos ; |
---|
268 |
pos = (char *)str ; |
---|
269 |
|
---|
270 |
while (*pos != '\0') { |
---|
271 |
if (*pos == *search) { |
---|
272 |
if (strncmp(pos, search, strlen(search)) == 0) { |
---|
273 |
return pos ; |
---|
274 |
} |
---|
275 |
} |
---|
276 |
if ((unsigned char)*pos == 0x8Fu) { |
---|
277 |
pos += 3 ; |
---|
278 |
} else if ((unsigned char)*pos >= 0x80u) { |
---|
279 |
pos += 2 ; |
---|
280 |
} else { |
---|
281 |
pos += 1 ; |
---|
282 |
} |
---|
283 |
} |
---|
284 |
|
---|
285 |
return NULL ; |
---|
286 |
} |
---|
287 |
void conv_title_subtitle(EIT_CONTROL *eitptr) |
---|
288 |
{ |
---|
289 |
int lp = 0 ; |
---|
290 |
|
---|
291 |
char *ptr ; |
---|
292 |
char *ptr2 ; |
---|
293 |
char *newsubtitle ; |
---|
294 |
|
---|
295 |
for(lp = 0 ; subtitle_cnv_str[lp] != NULL ; lp++){ |
---|
296 |
ptr = strstr(eitptr->title, subtitle_cnv_str[lp]); |
---|
297 |
if(ptr == NULL){ |
---|
298 |
continue ; |
---|
299 |
} |
---|
300 |
|
---|
301 |
continue ; |
---|
302 |
} |
---|
303 |
ptr2 = ptr ; |
---|
304 |
for( ; (unsigned char)*ptr2 == 0x20u ; ptr2++ ); |
---|
305 |
for( ; (unsigned char)*ptr2 == 0xA1u && (unsigned char)*(ptr2+1) == 0xA1u ; ptr2 += 2); |
---|
306 |
for( ; (unsigned char)*ptr2 == 0x20u ; ptr2++ ); |
---|
307 |
newsubtitle = calloc(1, ((strlen(ptr2) + 2) + (strlen(eitptr->subtitle) + 1))); |
---|
308 |
memcpy(newsubtitle, ptr2, strlen(ptr2)); |
---|
309 |
|
---|
310 |
strcat(newsubtitle, "��); |
---|
311 |
|
---|
312 |
|
---|
313 |
|
---|
314 |
|
---|
315 |
|
---|
316 |
|
---|
317 |
|
---|
318 |
|
---|
319 |
|
---|
320 |
|
---|
321 |
|
---|
322 |
|
---|
323 |
|
---|
324 |
|
---|
325 |
|
---|
326 |
|
---|
327 |
|
---|
328 |
|
---|
329 |
|
---|
330 |
|
---|
331 |
|
---|
332 |
|
---|
333 |
|
---|
334 |
|
---|
335 |
|
---|
336 |
|
---|
337 |
|
---|
338 |
|
---|
339 |
|
---|
340 |
|
---|
341 |
|
---|
342 |
|
---|
343 |
|
---|
344 |
|
---|
345 |
|
---|
346 |
|
---|
347 |
|
---|
348 |
|
---|
349 |
|
---|
350 |
|
---|
351 |
|
---|
352 |
|
---|
353 |
|
---|
354 |
|
---|
355 |
|
---|
356 |
|
---|
357 |
|
---|
358 |
|
---|
359 |
|
---|
360 |
|
---|
361 |
|
---|
362 |
|
---|
363 |
|
---|
364 |
|
---|
365 |
|
---|
366 |
|
---|
367 |
|
---|
368 |
|
---|
369 |
|
---|
370 |
|
---|
371 |
|
---|
372 |
|
---|
373 |
|
---|
374 |
|
---|
375 |
|
---|
376 |
|
---|
377 |
|
---|
378 |
|
---|
379 |
|
---|
380 |
|
---|
381 |
|
---|
382 |
|
---|
383 |
|
---|
384 |
|
---|
385 |
|
---|
386 |
|
---|
387 |
|
---|
388 |
|
---|
389 |
|
---|
390 |
|
---|
391 |
|
---|
392 |
|
---|
393 |
|
---|
394 |
|
---|
395 |
|
---|
396 |
|
---|
397 |
|
---|
398 |
|
---|
399 |
|
---|
400 |
|
---|
401 |
|
---|
402 |
|
---|
403 |
|
---|
404 |
|
---|
405 |
|
---|
406 |
|
---|
407 |
|
---|
408 |
|
---|
409 |
evtid:%d\n", eitb.event_id); */ |
---|
410 |
|
---|
411 |
|
---|
412 |
|
---|
413 |
|
---|
414 |
|
---|
415 |
|
---|
416 |
|
---|
417 |
|
---|
418 |
|
---|
419 |
|
---|
420 |
|
---|
421 |
aa"); |
---|
422 |
|
---|
423 |
|
---|
424 |
|
---|
425 |
|
---|
426 |
|
---|
427 |
|
---|
428 |
|
---|
429 |
|
---|
430 |
|
---|
431 |
|
---|
432 |
|
---|
433 |
|
---|
434 |
|
---|
435 |
|
---|
436 |
|
---|
437 |
|
---|
438 |
|
---|
439 |
|
---|
440 |
|
---|
441 |
|
---|
442 |
|
---|
443 |
|
---|
444 |
|
---|
445 |
|
---|
446 |
|
---|
447 |
|
---|
448 |
|
---|
449 |
|
---|
450 |
|
---|
451 |
|
---|
452 |
|
---|
453 |
|
---|
454 |
|
---|
455 |
|
---|
456 |
|
---|
457 |
|
---|
458 |
|
---|
459 |
|
---|
460 |
|
---|
461 |
|
---|
462 |
|
---|
463 |
|
---|
464 |
aa"); |
---|
465 |
|
---|
466 |
|
---|
467 |
|
---|
468 |
|
---|
469 |
|
---|
470 |
|
---|
471 |
|
---|
472 |
|
---|
473 |
|
---|
474 |
|
---|
475 |
|
---|
476 |
|
---|
477 |
|
---|
478 |
|
---|
479 |
|
---|
480 |
|
---|
481 |
|
---|
482 |
|
---|
483 |
|
---|
484 |
|
---|
485 |
|
---|
486 |
EEVT,%d,%d,%d,%s,%s\n", |
---|
487 |
|
---|
488 |
|
---|
489 |
|
---|
490 |
|
---|
491 |
|
---|
492 |
|
---|
493 |
|
---|
494 |
|
---|
495 |
|
---|
496 |
|
---|
497 |
|
---|
498 |
|
---|
499 |
|
---|
500 |
EEVTt,%d,%d,%d,%s\n", |
---|
501 |
|
---|
502 |
|
---|
503 |
|
---|
504 |
|
---|
505 |
|
---|
506 |
|
---|
507 |
|
---|
508 |
|
---|
509 |
|
---|
510 |
|
---|
511 |
|
---|
512 |
|
---|
513 |
|
---|
514 |
|
---|
515 |
|
---|
516 |
|
---|
517 |
|
---|
518 |
|
---|
519 |
Content,%d,%d", |
---|
520 |
|
---|
521 |
|
---|
522 |
|
---|
523 |
|
---|
524 |
|
---|
525 |
|
---|
526 |
,%02x%02x", (unsigned char)contentDesc.content[i], (unsigned char)contentDesc.content[i+1]); |
---|
527 |
|
---|
528 |
|
---|
529 |
|
---|
530 |
|
---|
531 |
|
---|
532 |
|
---|
533 |
|
---|
534 |
%s:", cur->title); |
---|
535 |
,%02x%02x", (unsigned char)contentDesc.content[0], (unsigned char)contentDesc.content[1]); |
---|
536 |
,%02x%02x\n", (unsigned char)contentDesc.content[2], (unsigned char)contentDesc.content[3]); |
---|
537 |
|
---|
538 |
|
---|
539 |
|
---|
540 |
|
---|
541 |
|
---|
542 |
\n"); |
---|
543 |
|
---|
544 |
|
---|
545 |
|
---|
546 |
|
---|
547 |
|
---|
548 |
|
---|
549 |
|
---|
550 |
|
---|
551 |
Series,%d,%d,series=%d,repeat=%01x,pattern=%d,expire_valid=%d,expire=%04x,epinum=%d,lastepinum=%d,%s\n", |
---|
552 |
|
---|
553 |
|
---|
554 |
|
---|
555 |
|
---|
556 |
|
---|
557 |
|
---|
558 |
|
---|
559 |
|
---|
560 |
|
---|
561 |
|
---|
562 |
|
---|
563 |
|
---|
564 |
|
---|
565 |
|
---|
566 |
|
---|
567 |
|
---|
568 |
|
---|
569 |
|
---|
570 |
|
---|
571 |
|
---|
572 |
|
---|
573 |
|
---|
574 |
|
---|
575 |
|
---|
576 |
|
---|
577 |
EEVT,%d,%d,%d,%s,%s\n", |
---|
578 |
|
---|
579 |
|
---|
580 |
|
---|
581 |
|
---|
582 |
|
---|
583 |
|
---|
584 |
|
---|
585 |
|
---|
586 |
|
---|
587 |
|
---|
588 |
|
---|
589 |
|
---|
590 |
|
---|
591 |
|
---|
592 |
|
---|
593 |
|
---|
594 |
|
---|
595 |
|
---|
596 |
|
---|
597 |
|
---|
598 |
|
---|
599 |
|
---|
600 |
|
---|
601 |
|
---|
602 |
|
---|
603 |
|
---|
604 |
|
---|
605 |
|
---|
606 |
|
---|
607 |
|
---|
608 |
|
---|
609 |
|
---|