|
@@ -10,6 +10,17 @@
|
10
|
10
|
#define have_left(X) \
|
11
|
11
|
do { if (data + (X) > data_end) return NULL; } while(0)
|
12
|
12
|
|
|
13
|
+void ts_section_header_set_private_vars(struct ts_section_header *ts_section_header) {
|
|
14
|
+ if (ts_section_header->section_syntax_indicator) {
|
|
15
|
+ ts_section_header->data = ts_section_header->section_data + 3 + 5; // Skip header and extended header
|
|
16
|
+ ts_section_header->data_len = ts_section_header->section_length - 9; // 5 for extended header, 4 for crc at the end
|
|
17
|
+ } else {
|
|
18
|
+ ts_section_header->data = ts_section_header->section_data + 3; // Skip header
|
|
19
|
+ ts_section_header->data_len = ts_section_header->section_length;
|
|
20
|
+ }
|
|
21
|
+ ts_section_header->section_data_len = ts_section_header->section_length + 3; // 3 for section header
|
|
22
|
+}
|
|
23
|
+
|
13
|
24
|
uint8_t *ts_section_header_parse(uint8_t *ts_packet, struct ts_header *ts_header, struct ts_section_header *ts_section_header) {
|
14
|
25
|
uint8_t *data = ts_packet + ts_header->payload_offset;
|
15
|
26
|
uint8_t *data_end = ts_packet + TS_PACKET_SIZE;
|
|
@@ -34,9 +45,6 @@ uint8_t *ts_section_header_parse(uint8_t *ts_packet, struct ts_header *ts_header
|
34
|
45
|
return NULL;
|
35
|
46
|
|
36
|
47
|
if (ts_section_header->section_syntax_indicator) {
|
37
|
|
- ts_section_header->data = ts_section_header->section_data + 3 + 5; // Skip header and extended header
|
38
|
|
- ts_section_header->data_len = ts_section_header->section_length - 9; // 5 for extended header, 4 for crc at the end
|
39
|
|
-
|
40
|
48
|
have_left(5);
|
41
|
49
|
ts_section_header->ts_id_number = (data[0] << 8) | data[1]; // xxxxxxx xxxxxxx
|
42
|
50
|
ts_section_header->reserved2 = data[2] >> 6; // xx111111
|
|
@@ -45,12 +53,9 @@ uint8_t *ts_section_header_parse(uint8_t *ts_packet, struct ts_header *ts_header
|
45
|
53
|
ts_section_header->section_number = data[3];
|
46
|
54
|
ts_section_header->last_section_number = data[4];
|
47
|
55
|
data += 5;
|
48
|
|
- } else {
|
49
|
|
- ts_section_header->data = ts_section_header->section_data + 3; // Skip header
|
50
|
|
- ts_section_header->data_len = ts_section_header->section_length;
|
51
|
56
|
}
|
52
|
57
|
|
53
|
|
- ts_section_header->section_data_len = ts_section_header->section_length + 3; // 3 for section header
|
|
58
|
+ ts_section_header_set_private_vars(ts_section_header);
|
54
|
59
|
|
55
|
60
|
return data;
|
56
|
61
|
}
|