Browse Source

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

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

+ 3
- 12
tsfuncs_cat.c View File

83
 	memcpy(cat->program_info, stream_data, cat->program_info_size);
83
 	memcpy(cat->program_info, stream_data, cat->program_info_size);
84
 	stream_data += cat->program_info_size;
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
 		return 0;
87
 		return 0;
95
-	}
96
 
88
 
97
 	cat->initialized = 1;
89
 	cat->initialized = 1;
98
 	return 1;
90
 	return 1;
106
 	memcpy(secdata + curpos, cat->program_info, cat->program_info_size);
98
 	memcpy(secdata + curpos, cat->program_info, cat->program_info_size);
107
 	curpos += cat->program_info_size;
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
     curpos += 4; // CRC
102
     curpos += 4; // CRC
111
 
103
 
112
     ts_section_data_gen_ts_packets(&cat->ts_header, secdata, curpos, cat->section_header->pointer_field, ts_packets, num_packets);
104
     ts_section_data_gen_ts_packets(&cat->ts_header, secdata, curpos, cat->section_header->pointer_field, ts_packets, num_packets);
172
 		ts_LOGf("  * Descriptor dump:\n");
164
 		ts_LOGf("  * Descriptor dump:\n");
173
 		ts_descriptor_dump(cat->program_info, cat->program_info_size);
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
 	ts_cat_check_generator(cat);
168
 	ts_cat_check_generator(cat);
178
 }
169
 }
179
 
170
 
180
 int ts_cat_is_same(struct ts_cat *cat1, struct ts_cat *cat2) {
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
 		return 1;
173
 		return 1;
183
 
174
 
184
 	// If some version is not current, just claim the structures are the same
175
 	// If some version is not current, just claim the structures are the same

+ 2
- 11
tsfuncs_eit.c View File

136
 		stream_data += sinfo->descriptor_size;
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
 		return 0;
140
 		return 0;
148
-	}
149
 
141
 
150
 	eit->initialized = 1;
142
 	eit->initialized = 1;
151
 	return 1;
143
 	return 1;
195
 			curpos += stream->descriptor_size;
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
 	curpos += 4; // CRC
191
 	curpos += 4; // CRC
200
 
192
 
201
 	ts_section_data_gen_ts_packets(&eit->ts_header, secdata, curpos, eit->section_header->pointer_field, ts_packets, num_packets);
193
 	ts_section_data_gen_ts_packets(&eit->ts_header, secdata, curpos, eit->section_header->pointer_field, ts_packets, num_packets);
291
 			ts_descriptor_dump(stream->descriptor_data, stream->descriptor_size);
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
 	ts_eit_check_generator(eit);
287
 	ts_eit_check_generator(eit);
297
 }
288
 }

+ 2
- 11
tsfuncs_nit.c View File

137
 		stream_len  -= 6 + sinfo->descriptor_size;
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
 		return 0;
141
 		return 0;
149
-	}
150
 
142
 
151
 	nit->initialized = 1;
143
 	nit->initialized = 1;
152
 	return 1;
144
 	return 1;
195
 			curpos += stream->descriptor_size;
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
 	curpos += 4; // CRC
191
 	curpos += 4; // CRC
200
 
192
 
201
 	ts_section_data_gen_ts_packets(&nit->ts_header, secdata, curpos, nit->section_header->pointer_field, ts_packets, num_packets);
193
 	ts_section_data_gen_ts_packets(&nit->ts_header, secdata, curpos, nit->section_header->pointer_field, ts_packets, num_packets);
261
 			ts_descriptor_dump(stream->descriptor_data, stream->descriptor_size);
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
 	ts_nit_check_generator(nit);
257
 	ts_nit_check_generator(nit);
267
 }
258
 }

+ 3
- 11
tsfuncs_pat.c View File

102
 		section_data += 4;
102
 		section_data += 4;
103
 		section_len  -= 4;
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
 		return 0;
107
 		return 0;
114
-	}
115
 
108
 
116
 	pat->initialized = 1;
109
 	pat->initialized = 1;
117
 	return 1;
110
 	return 1;
133
 		secdata[curpos + 3]  = prg->pid &~ 0xff00;
126
 		secdata[curpos + 3]  = prg->pid &~ 0xff00;
134
 		curpos += 4; // Compensate for the above
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
 	curpos += 4; // CRC
130
 	curpos += 4; // CRC
138
 
131
 
139
 	ts_section_data_gen_ts_packets(&pat->ts_header, secdata, curpos, pat->section_header->pointer_field, ts_packets, num_packets);
132
 	ts_section_data_gen_ts_packets(&pat->ts_header, secdata, curpos, pat->section_header->pointer_field, ts_packets, num_packets);
208
 			ts_LOGf("      - NIT PID %04x (%d)\n", prg->pid, prg->pid);
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
 	ts_pat_check_generator(pat);
205
 	ts_pat_check_generator(pat);
214
 }
206
 }
216
 int ts_pat_is_same(struct ts_pat *pat1, struct ts_pat *pat2) {
208
 int ts_pat_is_same(struct ts_pat *pat1, struct ts_pat *pat2) {
217
 	int i;
209
 	int i;
218
 
210
 
219
-	if (pat1->CRC == pat2->CRC) // Same
211
+	if (pat1->section_header->CRC == pat2->section_header->CRC) // Same
220
 		return 1;
212
 		return 1;
221
 
213
 
222
 	// If some version is not current, just claim the structures are the same
214
 	// If some version is not current, just claim the structures are the same

+ 3
- 11
tsfuncs_pmt.c View File

131
 		stream_data += 5 + sinfo->ES_info_size;
131
 		stream_data += 5 + sinfo->ES_info_size;
132
 		stream_len  -= 5 + sinfo->ES_info_size;
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
 		return 0;
136
 		return 0;
143
-	}
144
 
137
 
145
 	pmt->initialized = 1;
138
 	pmt->initialized = 1;
146
 	return 1;
139
 	return 1;
184
 			curpos += stream->ES_info_size;
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
     curpos += 4; // CRC
181
     curpos += 4; // CRC
189
 
182
 
190
     ts_section_data_gen_ts_packets(&pmt->ts_header, secdata, curpos, pmt->section_header->pointer_field, ts_packets, num_packets);
183
     ts_section_data_gen_ts_packets(&pmt->ts_header, secdata, curpos, pmt->section_header->pointer_field, ts_packets, num_packets);
272
 			ts_descriptor_dump(stream->ES_info, stream->ES_info_size);
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
 	ts_pmt_check_generator(pmt);
269
 	ts_pmt_check_generator(pmt);
278
 }
270
 }
303
 int ts_pmt_is_same(struct ts_pmt *pmt1, struct ts_pmt *pmt2) {
295
 int ts_pmt_is_same(struct ts_pmt *pmt1, struct ts_pmt *pmt2) {
304
 	int i;
296
 	int i;
305
 
297
 
306
-	if (pmt1->CRC == pmt2->CRC) // Same
298
+	if (pmt1->section_header->CRC == pmt2->section_header->CRC) // Same
307
 		return 1;
299
 		return 1;
308
 
300
 
309
 	// If some version is not current, just claim the structures are the same
301
 	// If some version is not current, just claim the structures are the same

+ 2
- 10
tsfuncs_sdt.c View File

122
 		section_data += 5 + sinfo->descriptor_size;
122
 		section_data += 5 + sinfo->descriptor_size;
123
 		section_len  -= 5 + sinfo->descriptor_size;
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
 		return 0;
127
 		return 0;
134
-	}
135
 
128
 
136
 	sdt->initialized = 1;
129
 	sdt->initialized = 1;
137
 	return 1;
130
 	return 1;
169
 			curpos += stream->descriptor_size;
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
     curpos += 4; // CRC
166
     curpos += 4; // CRC
174
 
167
 
175
     ts_section_data_gen_ts_packets(&sdt->ts_header, secdata, curpos, sdt->section_header->pointer_field, ts_packets, num_packets);
168
     ts_section_data_gen_ts_packets(&sdt->ts_header, secdata, curpos, sdt->section_header->pointer_field, ts_packets, num_packets);
229
 			ts_descriptor_dump(stream->descriptor_data, stream->descriptor_size);
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
 	ts_sdt_check_generator(sdt);
226
 	ts_sdt_check_generator(sdt);
235
 }
227
 }

Loading…
Cancel
Save