Browse Source

Add section_data_len to struct ts_section_header

Georgi Chorbadzhiyski 9 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,6 +55,7 @@ struct ts_section_header {
55 55
 	int			section_pos;					// Up to this pos the section data has come
56 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 59
 	uint8_t		*section_data;					// The whole section data
59 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,13 +40,11 @@ uint32_t ts_crc32(uint8_t *data, int data_size) {
40 40
 }
41 41
 
42 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 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 49
 	if (check_crc != 0) {
52 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,14 +110,14 @@ void ts_section_add_packet(struct ts_section_header *sec, struct ts_header *ts_h
110 110
 		return;
111 111
 
112 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 116
 	memcpy(sec->section_data + sec->section_pos, ts_packet + payload_offset, to_copy);
117 117
 	memcpy(sec->packet_data + (sec->num_packets * TS_PACKET_SIZE), ts_packet, TS_PACKET_SIZE);
118 118
 	sec->section_pos += to_copy;
119 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 121
 	if (sec->initialized) {
122 122
 		// CRC is after sec->data[sec->data_len]
123 123
 		sec->CRC = (sec->CRC << 8) | sec->data[sec->data_len + 3];

+ 3
- 0
tsfuncs_sections.c View File

@@ -49,6 +49,9 @@ uint8_t *ts_section_header_parse(uint8_t *ts_packet, struct ts_header *ts_header
49 49
 		ts_section_header->data     = ts_section_header->section_data + 3; // Skip header
50 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 55
 	return data;
53 56
 }
54 57
 

Loading…
Cancel
Save