Browse Source

Fix off-by-one in section gathering.

When 1 byte of the section was in the next TS packet, section
gathering misses it.
Georgi Chorbadzhiyski 13 years ago
parent
commit
7d13c10049
1 changed files with 3 additions and 2 deletions
  1. 3
    2
      secdata.c

+ 3
- 2
secdata.c View File

@@ -143,7 +143,7 @@ void ts_section_add_packet(struct ts_section_header *sec, struct ts_header *ts_h
143 143
 		payload_offset += sec->pointer_field + 1; // Pointer field
144 144
 	}
145 145
 
146
-	int to_copy = TS_PACKET_SIZE - payload_offset;
146
+	int to_copy = min(TS_PACKET_SIZE - payload_offset, sec->section_data_len - sec->section_pos);
147 147
 	if (to_copy <= 0)
148 148
 		return;
149 149
 
@@ -155,7 +155,8 @@ void ts_section_add_packet(struct ts_section_header *sec, struct ts_header *ts_h
155 155
 	memcpy(sec->packet_data + (sec->num_packets * TS_PACKET_SIZE), ts_packet, TS_PACKET_SIZE);
156 156
 	sec->section_pos += to_copy;
157 157
 	sec->num_packets++;
158
-	sec->initialized = (sec->section_pos+1) >= sec->section_data_len;
158
+	sec->initialized = (sec->section_pos+1) > sec->section_data_len;
159
+
159 160
 	if (sec->initialized) {
160 161
 		// CRC is after sec->data[sec->data_len]
161 162
 		sec->CRC = (sec->CRC << 8) | sec->data[sec->data_len + 3];

Loading…
Cancel
Save