Browse Source

Remove CRC fields from table definitions (use CRC in struct ts_section_header)

Georgi Chorbadzhiyski 9 years ago
parent
commit
d0cae59808
7 changed files with 15 additions and 77 deletions
  1. 0
    11
      tsdata.h
  2. 3
    12
      tsfuncs_cat.c
  3. 2
    11
      tsfuncs_eit.c
  4. 2
    11
      tsfuncs_nit.c
  5. 3
    11
      tsfuncs_pat.c
  6. 3
    11
      tsfuncs_pmt.c
  7. 2
    10
      tsfuncs_sdt.c

+ 0
- 11
tsdata.h View File

@@ -77,7 +77,6 @@ struct ts_pat {
77 77
 	struct ts_section_header	*section_header;
78 78
 
79 79
 	struct ts_pat_program		**programs;
80
-	uint32_t					CRC;
81 80
 
82 81
 	// The variables bellow are nor part of the physical packet
83 82
 	int							programs_max;	// How much programs are allocated
@@ -99,8 +98,6 @@ struct ts_cat {
99 98
 	int							program_info_size;
100 99
 	uint8_t						*program_info;
101 100
 
102
-	uint32_t					CRC;
103
-
104 101
 	// The variables bellow are nor part of the physical packet
105 102
 	uint8_t						initialized;	// Set to 1 when full table is initialized
106 103
 };
@@ -130,8 +127,6 @@ struct ts_pmt {
130 127
 
131 128
 	struct ts_pmt_stream		**streams;
132 129
 
133
-	uint32_t					CRC;
134
-
135 130
 	// The variables bellow are nor part of the physical packet
136 131
 	int							streams_max;	// How much streams are allocated
137 132
 	int							streams_num;	// How much streams are initialized
@@ -162,8 +157,6 @@ struct ts_sdt {
162 157
 
163 158
 	struct ts_sdt_stream		**streams;
164 159
 
165
-	uint32_t					CRC;
166
-
167 160
 	// The variables bellow are nor part of the physical packet
168 161
 	int							streams_max;	// How much streams are allocated
169 162
 	int							streams_num;	// How much streams are initialized
@@ -196,8 +189,6 @@ struct ts_nit {
196 189
 
197 190
 	struct ts_nit_stream		**streams;
198 191
 
199
-	uint32_t					CRC;
200
-
201 192
 	// The variables bellow are nor part of the physical packet
202 193
 	int							streams_max;	// How much streams are allocated
203 194
 	int							streams_num;	// How much streams are initialized
@@ -229,8 +220,6 @@ struct ts_eit {
229 220
 
230 221
 	struct ts_eit_stream		**streams;
231 222
 
232
-	uint32_t					CRC;
233
-
234 223
 	// The variables bellow are nor part of the physical packet
235 224
 	int							streams_max;	// How much streams are allocated
236 225
 	int							streams_num;	// How much streams are initialized

+ 3
- 12
tsfuncs_cat.c View File

@@ -83,16 +83,8 @@ int ts_cat_parse(struct ts_cat *cat) {
83 83
 	memcpy(cat->program_info, stream_data, cat->program_info_size);
84 84
 	stream_data += cat->program_info_size;
85 85
 
86
-	cat->CRC = (cat->CRC << 8) | stream_data[3];
87
-	cat->CRC = (cat->CRC << 8) | stream_data[2];
88
-	cat->CRC = (cat->CRC << 8) | stream_data[1];
89
-	cat->CRC = (cat->CRC << 8) | stream_data[0];
90
-
91
-	u_int32_t check_crc = ts_crc32_section(cat->section_header);
92
-	if (check_crc != 0) {
93
-		ts_LOGf("!!! Wrong cat CRC! It should be 0 but it is %08x (CRC in data is 0x%08x)\n", check_crc, cat->CRC);
86
+	if (!ts_crc32_section_check(cat->section_header, "CAT"))
94 87
 		return 0;
95
-	}
96 88
 
97 89
 	cat->initialized = 1;
98 90
 	return 1;
@@ -106,7 +98,7 @@ void ts_cat_generate(struct ts_cat *cat, uint8_t **ts_packets, int *num_packets)
106 98
 	memcpy(secdata + curpos, cat->program_info, cat->program_info_size);
107 99
 	curpos += cat->program_info_size;
108 100
 
109
-    cat->CRC = ts_section_data_calculate_crc(secdata, curpos);
101
+	cat->section_header->CRC = ts_section_data_calculate_crc(secdata, curpos);
110 102
     curpos += 4; // CRC
111 103
 
112 104
     ts_section_data_gen_ts_packets(&cat->ts_header, secdata, curpos, cat->section_header->pointer_field, ts_packets, num_packets);
@@ -172,13 +164,12 @@ void ts_cat_dump(struct ts_cat *cat) {
172 164
 		ts_LOGf("  * Descriptor dump:\n");
173 165
 		ts_descriptor_dump(cat->program_info, cat->program_info_size);
174 166
 	}
175
-	ts_LOGf("  * CRC 0x%04x\n", cat->CRC);
176 167
 
177 168
 	ts_cat_check_generator(cat);
178 169
 }
179 170
 
180 171
 int ts_cat_is_same(struct ts_cat *cat1, struct ts_cat *cat2) {
181
-	if (cat1->CRC == cat2->CRC) // Same
172
+	if (cat1->section_header->CRC == cat2->section_header->CRC) // Same
182 173
 		return 1;
183 174
 
184 175
 	// If some version is not current, just claim the structures are the same

+ 2
- 11
tsfuncs_eit.c View File

@@ -136,16 +136,8 @@ int ts_eit_parse(struct ts_eit *eit) {
136 136
 		stream_data += sinfo->descriptor_size;
137 137
 	}
138 138
 
139
-	eit->CRC = (eit->CRC << 8) | stream_data[3];
140
-	eit->CRC = (eit->CRC << 8) | stream_data[2];
141
-	eit->CRC = (eit->CRC << 8) | stream_data[1];
142
-	eit->CRC = (eit->CRC << 8) | stream_data[0];
143
-
144
-	u_int32_t check_crc = ts_crc32_section(eit->section_header);
145
-	if (check_crc != 0) {
146
-		ts_LOGf("!!! Wrong EIT CRC! It should be 0 but it is %08x (CRC in data is 0x%08x)\n", check_crc, eit->CRC);
139
+	if (!ts_crc32_section_check(eit->section_header, "EIT"))
147 140
 		return 0;
148
-	}
149 141
 
150 142
 	eit->initialized = 1;
151 143
 	return 1;
@@ -195,7 +187,7 @@ void ts_eit_generate(struct ts_eit *eit, uint8_t **ts_packets, int *num_packets)
195 187
 			curpos += stream->descriptor_size;
196 188
 		}
197 189
 	}
198
-	eit->CRC = ts_section_data_calculate_crc(secdata, curpos);
190
+	eit->section_header->CRC = ts_section_data_calculate_crc(secdata, curpos);
199 191
 	curpos += 4; // CRC
200 192
 
201 193
 	ts_section_data_gen_ts_packets(&eit->ts_header, secdata, curpos, eit->section_header->pointer_field, ts_packets, num_packets);
@@ -291,7 +283,6 @@ void ts_eit_dump(struct ts_eit *eit) {
291 283
 			ts_descriptor_dump(stream->descriptor_data, stream->descriptor_size);
292 284
 		}
293 285
 	}
294
-	ts_LOGf("  * CRC 0x%04x\n", eit->CRC);
295 286
 
296 287
 	ts_eit_check_generator(eit);
297 288
 }

+ 2
- 11
tsfuncs_nit.c View File

@@ -137,16 +137,8 @@ int ts_nit_parse(struct ts_nit *nit) {
137 137
 		stream_len  -= 6 + sinfo->descriptor_size;
138 138
 	}
139 139
 
140
-	nit->CRC = (nit->CRC << 8) | stream_data[3];
141
-	nit->CRC = (nit->CRC << 8) | stream_data[2];
142
-	nit->CRC = (nit->CRC << 8) | stream_data[1];
143
-	nit->CRC = (nit->CRC << 8) | stream_data[0];
144
-
145
-	u_int32_t check_crc = ts_crc32_section(nit->section_header);
146
-	if (check_crc != 0) {
147
-		ts_LOGf("!!! Wrong NIT CRC! It should be 0 but it is %08x (CRC in data is 0x%08x)\n", check_crc, nit->CRC);
140
+	if (!ts_crc32_section_check(nit->section_header, "NIT"))
148 141
 		return 0;
149
-	}
150 142
 
151 143
 	nit->initialized = 1;
152 144
 	return 1;
@@ -195,7 +187,7 @@ void ts_nit_generate(struct ts_nit *nit, uint8_t **ts_packets, int *num_packets)
195 187
 			curpos += stream->descriptor_size;
196 188
 		}
197 189
 	}
198
-	nit->CRC = ts_section_data_calculate_crc(secdata, curpos);
190
+	nit->section_header->CRC = ts_section_data_calculate_crc(secdata, curpos);
199 191
 	curpos += 4; // CRC
200 192
 
201 193
 	ts_section_data_gen_ts_packets(&nit->ts_header, secdata, curpos, nit->section_header->pointer_field, ts_packets, num_packets);
@@ -261,7 +253,6 @@ void ts_nit_dump(struct ts_nit *nit) {
261 253
 			ts_descriptor_dump(stream->descriptor_data, stream->descriptor_size);
262 254
 		}
263 255
 	}
264
-	ts_LOGf("  * CRC 0x%04x\n", nit->CRC);
265 256
 
266 257
 	ts_nit_check_generator(nit);
267 258
 }

+ 3
- 11
tsfuncs_pat.c View File

@@ -102,16 +102,9 @@ int ts_pat_parse(struct ts_pat *pat) {
102 102
 		section_data += 4;
103 103
 		section_len  -= 4;
104 104
 	}
105
-	pat->CRC = (pat->CRC << 8) | section_data[3];
106
-	pat->CRC = (pat->CRC << 8) | section_data[2];
107
-	pat->CRC = (pat->CRC << 8) | section_data[1];
108
-	pat->CRC = (pat->CRC << 8) | section_data[0];
109 105
 
110
-	u_int32_t check_crc = ts_crc32_section(pat->section_header);
111
-	if (check_crc != 0) {
112
-		ts_LOGf("!!! Wrong PAT CRC! It should be 0 but it is %08x (CRC in data is 0x%08x)\n", check_crc, pat->CRC);
106
+	if (!ts_crc32_section_check(pat->section_header, "PAT"))
113 107
 		return 0;
114
-	}
115 108
 
116 109
 	pat->initialized = 1;
117 110
 	return 1;
@@ -133,7 +126,7 @@ void ts_pat_generate(struct ts_pat *pat, uint8_t **ts_packets, int *num_packets)
133 126
 		secdata[curpos + 3]  = prg->pid &~ 0xff00;
134 127
 		curpos += 4; // Compensate for the above
135 128
 	}
136
-	pat->CRC = ts_section_data_calculate_crc(secdata, curpos);
129
+	pat->section_header->CRC = ts_section_data_calculate_crc(secdata, curpos);
137 130
 	curpos += 4; // CRC
138 131
 
139 132
 	ts_section_data_gen_ts_packets(&pat->ts_header, secdata, curpos, pat->section_header->pointer_field, ts_packets, num_packets);
@@ -208,7 +201,6 @@ void ts_pat_dump(struct ts_pat *pat) {
208 201
 			ts_LOGf("      - NIT PID %04x (%d)\n", prg->pid, prg->pid);
209 202
 		}
210 203
 	}
211
-	ts_LOGf("  * CRC 0x%08x\n", pat->CRC);
212 204
 
213 205
 	ts_pat_check_generator(pat);
214 206
 }
@@ -216,7 +208,7 @@ void ts_pat_dump(struct ts_pat *pat) {
216 208
 int ts_pat_is_same(struct ts_pat *pat1, struct ts_pat *pat2) {
217 209
 	int i;
218 210
 
219
-	if (pat1->CRC == pat2->CRC) // Same
211
+	if (pat1->section_header->CRC == pat2->section_header->CRC) // Same
220 212
 		return 1;
221 213
 
222 214
 	// If some version is not current, just claim the structures are the same

+ 3
- 11
tsfuncs_pmt.c View File

@@ -131,16 +131,9 @@ int ts_pmt_parse(struct ts_pmt *pmt) {
131 131
 		stream_data += 5 + sinfo->ES_info_size;
132 132
 		stream_len  -= 5 + sinfo->ES_info_size;
133 133
 	}
134
-	pmt->CRC = (pmt->CRC << 8) | stream_data[3];
135
-	pmt->CRC = (pmt->CRC << 8) | stream_data[2];
136
-	pmt->CRC = (pmt->CRC << 8) | stream_data[1];
137
-	pmt->CRC = (pmt->CRC << 8) | stream_data[0];
138 134
 
139
-	u_int32_t check_crc = ts_crc32_section(pmt->section_header);
140
-	if (check_crc != 0) {
141
-		ts_LOGf("!!! Wrong PMT CRC! It should be 0 but it is %08x (CRC in data is 0x%08x)\n", check_crc, pmt->CRC);
135
+	if (!ts_crc32_section_check(pmt->section_header, "PMT"))
142 136
 		return 0;
143
-	}
144 137
 
145 138
 	pmt->initialized = 1;
146 139
 	return 1;
@@ -184,7 +177,7 @@ void ts_pmt_generate(struct ts_pmt *pmt, uint8_t **ts_packets, int *num_packets)
184 177
 			curpos += stream->ES_info_size;
185 178
 		}
186 179
 	}
187
-    pmt->CRC = ts_section_data_calculate_crc(secdata, curpos);
180
+    pmt->section_header->CRC = ts_section_data_calculate_crc(secdata, curpos);
188 181
     curpos += 4; // CRC
189 182
 
190 183
     ts_section_data_gen_ts_packets(&pmt->ts_header, secdata, curpos, pmt->section_header->pointer_field, ts_packets, num_packets);
@@ -272,7 +265,6 @@ void ts_pmt_dump(struct ts_pmt *pmt) {
272 265
 			ts_descriptor_dump(stream->ES_info, stream->ES_info_size);
273 266
 		}
274 267
 	}
275
-	ts_LOGf("  * CRC 0x%04x\n", pmt->CRC);
276 268
 
277 269
 	ts_pmt_check_generator(pmt);
278 270
 }
@@ -303,7 +295,7 @@ int parse_pmt(uint8_t *ts_packet, uint16_t pmt_pid, uint16_t *pcr_pid, uint16_t
303 295
 int ts_pmt_is_same(struct ts_pmt *pmt1, struct ts_pmt *pmt2) {
304 296
 	int i;
305 297
 
306
-	if (pmt1->CRC == pmt2->CRC) // Same
298
+	if (pmt1->section_header->CRC == pmt2->section_header->CRC) // Same
307 299
 		return 1;
308 300
 
309 301
 	// If some version is not current, just claim the structures are the same

+ 2
- 10
tsfuncs_sdt.c View File

@@ -122,16 +122,9 @@ int ts_sdt_parse(struct ts_sdt *sdt) {
122 122
 		section_data += 5 + sinfo->descriptor_size;
123 123
 		section_len  -= 5 + sinfo->descriptor_size;
124 124
 	}
125
-	sdt->CRC = (sdt->CRC << 8) | section_data[3];
126
-	sdt->CRC = (sdt->CRC << 8) | section_data[2];
127
-	sdt->CRC = (sdt->CRC << 8) | section_data[1];
128
-	sdt->CRC = (sdt->CRC << 8) | section_data[0];
129 125
 
130
-	u_int32_t check_crc = ts_crc32_section(sdt->section_header);
131
-	if (check_crc != 0) {
132
-		ts_LOGf("!!! Wrong SDT CRC! It should be 0 but it is %08x (CRC in data is 0x%08x)\n", check_crc, sdt->CRC);
126
+	if (!ts_crc32_section_check(sdt->section_header, "SDT"))
133 127
 		return 0;
134
-	}
135 128
 
136 129
 	sdt->initialized = 1;
137 130
 	return 1;
@@ -169,7 +162,7 @@ void ts_sdt_generate(struct ts_sdt *sdt, uint8_t **ts_packets, int *num_packets)
169 162
 			curpos += stream->descriptor_size;
170 163
 		}
171 164
 	}
172
-    sdt->CRC = ts_section_data_calculate_crc(secdata, curpos);
165
+    sdt->section_header->CRC = ts_section_data_calculate_crc(secdata, curpos);
173 166
     curpos += 4; // CRC
174 167
 
175 168
     ts_section_data_gen_ts_packets(&sdt->ts_header, secdata, curpos, sdt->section_header->pointer_field, ts_packets, num_packets);
@@ -229,7 +222,6 @@ void ts_sdt_dump(struct ts_sdt *sdt) {
229 222
 			ts_descriptor_dump(stream->descriptor_data, stream->descriptor_size);
230 223
 		}
231 224
 	}
232
-	ts_LOGf("  * CRC 0x%04x\n", sdt->CRC);
233 225
 
234 226
 	ts_sdt_check_generator(sdt);
235 227
 }

Loading…
Cancel
Save