Browse Source

Add section_data_len to struct ts_section_header

Georgi Chorbadzhiyski 13 years ago
parent
commit
927f87c027
4 changed files with 8 additions and 6 deletions
  1. 1
    0
      tsdata.h
  2. 2
    4
      tsfuncs_crc.c
  3. 2
    2
      tsfuncs_section_data.c
  4. 3
    0
      tsfuncs_sections.c

+ 1
- 0
tsdata.h View File

55
 	int			section_pos;					// Up to this pos the section data has come
55
 	int			section_pos;					// Up to this pos the section data has come
56
 	int			initialized;					// Set to 1 when whole sectino is initialized
56
 	int			initialized;					// Set to 1 when whole sectino is initialized
57
 
57
 
58
+	int			section_data_len;				// Full section length (3 + section_length)
58
 	uint8_t		*section_data;					// The whole section data
59
 	uint8_t		*section_data;					// The whole section data
59
 	uint8_t		*packet_data;					// TS packet(s) that were used to transfer the table.
60
 	uint8_t		*packet_data;					// TS packet(s) that were used to transfer the table.
60
 
61
 

+ 2
- 4
tsfuncs_crc.c View File

40
 }
40
 }
41
 
41
 
42
 u_int32_t ts_crc32_section(struct ts_section_header *section_header) {
42
 u_int32_t ts_crc32_section(struct ts_section_header *section_header) {
43
-	// +3 to include the first 3 bytes before section_length field
44
-	return ts_crc32(section_header->section_data, section_header->section_length + 3);
43
+	return ts_crc32(section_header->section_data, section_header->section_data_len);
45
 }
44
 }
46
 
45
 
47
 int ts_crc32_section_check(struct ts_section_header *section_header, char *table) {
46
 int ts_crc32_section_check(struct ts_section_header *section_header, char *table) {
48
-	// +3 to include the first 3 bytes before section_length field
49
-	uint32_t check_crc = ts_crc32(section_header->section_data, section_header->section_length + 3);
47
+	uint32_t check_crc = ts_crc32(section_header->section_data, section_header->section_data_len);
50
 
48
 
51
 	if (check_crc != 0) {
49
 	if (check_crc != 0) {
52
 		ts_LOGf("!!! Wrong %s table CRC! It should be 0 but it is 0x%08x (CRC in data is 0x%08x)\n",
50
 		ts_LOGf("!!! Wrong %s table CRC! It should be 0 but it is 0x%08x (CRC in data is 0x%08x)\n",

+ 2
- 2
tsfuncs_section_data.c View File

110
 		return;
110
 		return;
111
 
111
 
112
 	if (sec->section_pos + to_copy >= 4092) {
112
 	if (sec->section_pos + to_copy >= 4092) {
113
-		to_copy = (sec->section_length + 3) - sec->section_pos;
113
+		to_copy = sec->section_data_len - sec->section_pos;
114
 	}
114
 	}
115
 
115
 
116
 	memcpy(sec->section_data + sec->section_pos, ts_packet + payload_offset, to_copy);
116
 	memcpy(sec->section_data + sec->section_pos, ts_packet + payload_offset, to_copy);
117
 	memcpy(sec->packet_data + (sec->num_packets * TS_PACKET_SIZE), ts_packet, TS_PACKET_SIZE);
117
 	memcpy(sec->packet_data + (sec->num_packets * TS_PACKET_SIZE), ts_packet, TS_PACKET_SIZE);
118
 	sec->section_pos += to_copy;
118
 	sec->section_pos += to_copy;
119
 	sec->num_packets++;
119
 	sec->num_packets++;
120
-	sec->initialized = (sec->section_pos+1) >= sec->section_length + 3;
120
+	sec->initialized = (sec->section_pos+1) >= sec->section_data_len;
121
 	if (sec->initialized) {
121
 	if (sec->initialized) {
122
 		// CRC is after sec->data[sec->data_len]
122
 		// CRC is after sec->data[sec->data_len]
123
 		sec->CRC = (sec->CRC << 8) | sec->data[sec->data_len + 3];
123
 		sec->CRC = (sec->CRC << 8) | sec->data[sec->data_len + 3];

+ 3
- 0
tsfuncs_sections.c View File

49
 		ts_section_header->data     = ts_section_header->section_data + 3; // Skip header
49
 		ts_section_header->data     = ts_section_header->section_data + 3; // Skip header
50
 		ts_section_header->data_len = ts_section_header->section_length;
50
 		ts_section_header->data_len = ts_section_header->section_length;
51
 	}
51
 	}
52
+
53
+	ts_section_header->section_data_len = ts_section_header->section_length + 3;	// 3 for section header
54
+
52
 	return data;
55
 	return data;
53
 }
56
 }
54
 
57
 

Loading…
Cancel
Save