OSDN Git Service

stop using trunk directory in rectool
[rec10/rec10-git.git] / epgdump / bit.c
1 // -*- tab-width:4 -*-
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 #include "bit.h"
8
9 // 2-STD-B10v4_6.pdf p89 (101/399)
10 int parseBIThead(unsigned char *data, BIThead *head) {
11         int boff = 0;
12
13         memset(head, 0, sizeof(BIThead));
14
15         head->table_id = getBit(data, &boff, 8);
16         head->section_syntax_indicator = getBit(data, &boff, 1);
17         head->reserved_future_use1 = getBit(data, &boff, 1);
18         head->reserved1 = getBit(data, &boff, 2);
19         head->section_length = getBit(data, &boff, 12);
20         head->original_network_id = getBit(data, &boff, 16);
21         head->reserved2 = getBit(data, &boff, 2);
22         head->version_number = getBit(data, &boff, 5);
23         head->current_next_indicator = getBit(data, &boff, 1);
24         head->section_number = getBit(data, &boff, 8);
25         head->last_section_number = getBit(data, &boff, 8);
26         head->reserved_future_use2 = getBit(data, &boff, 3);
27         head->broadcast_view_propriety = getBit(data, &boff, 1);
28         head->first_descriptors_length = getBit(data, &boff, 12);
29         return 10 + head->first_descriptors_length;
30 }
31
32 // 4-TR-B14v4_3-2p3.pdf p4-254 (276/543)
33 int parseBITloop(unsigned char *data, BITloop *loop) {
34         int boff = 0;
35
36         memset(loop, 0, sizeof(BITloop));
37
38         loop->broadcaster_id = getBit(data, &boff, 8);
39         loop->reserved_future_use = getBit(data, &boff, 4);
40         loop->broadcaster_descriptors_length = getBit(data, &boff, 12);
41
42         return 3;
43 }
44
45 // SI伝送パラメータ記述子
46 int parseBITdesc(unsigned char *data, BITdesc *desc) {
47         int boff = 0;
48
49         memset(desc, 0, sizeof(BITdesc));
50
51         desc->descriptor_tag = getBit(data, &boff, 8);
52         desc->descriptor_length = getBit(data, &boff, 8);
53         desc->parameter_version = getBit(data, &boff, 8);
54         desc->update_time = getBit(data, &boff,16);
55
56         return 5;
57 }
58
59 int parseBITtable(unsigned char *data, BITtable *table) {
60         int boff = 0;
61
62         memset(table, 0, sizeof(BITtable));
63
64         table->table_id = getBit(data, &boff, 8);
65         table->table_description_length = getBit(data, &boff, 8);
66         table->table_cycle = getBit(data, &boff, 16);
67
68         return table->table_description_length + 2;
69 }
70
71 void dumpBIT(unsigned char *ptr)
72 {
73         BIThead   bith;
74         BITloop   bitl;
75         BITdesc   bitd;
76         BITtable  bitt;
77
78         int len = 0;
79         int loop_len = 0;
80         int desc_len = 0;
81         int table_len = 0;
82
83         /* BIT */
84         len = parseBIThead(ptr, &bith);
85         ptr += len;
86         loop_len = bith.section_length - (len - 3 + 4); // 3は共通ヘッダ長 4はCRC
87
88         while(loop_len > 0) {
89                 len = parseBITloop(ptr, &bitl);
90                 ptr += len;
91                 loop_len -= len;
92
93                 desc_len = bitl.broadcaster_descriptors_length;
94                 loop_len -= desc_len;
95
96                 while(desc_len > 0) {
97                         len = parseBITdesc(ptr, &bitd);
98                         ptr += len;
99                         desc_len -= len;
100
101                         table_len = bitd.descriptor_length - 3;
102                         desc_len -= table_len;
103
104                         if ( bitd.descriptor_tag != 0xD7 ) {
105                                 ptr += table_len;
106                                 continue;
107                         }
108
109                         while(table_len > 0) {
110                                 len = parseBITtable(ptr, &bitt);
111                                 ptr += len;
112                                 table_len -= len;
113
114                                 /*
115                                         0x4E (M-EIT,L-EIT)
116                                         0x50(各局伝送パラメータ運用部分の H-EIT[schedule basic])
117                                         0x58 (各局伝送パラメータ運用部分の H-EIT[schedule extended])
118                                         0xC3(SDTT)
119                                         0xC8(CDT)
120                                 */
121
122                                 if (0) printf("BIT=(%d)%d:%d:%d:%d|0x%x:%d:%d=BCD(%d)\n",
123                                         bitl.broadcaster_id, bitd.descriptor_tag, bitd.descriptor_length, 
124                                         bitd.parameter_version, bitd.update_time, 
125                                         bitt.table_id, bitt.table_description_length, 
126                                         bitt.table_cycle, BCD(bitt.table_cycle));
127                         }
128                 }
129         }
130
131         return;
132 }
133