Skip to content

Commit 4ced077

Browse files
committed
rtpdec hevc: implement aggregation packets (untested)
1 parent 07715c6 commit 4ced077

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/rtp/rtpdec_h264.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,56 @@ decode_hevc_nal_unit(struct video_frame *frame, int *total_length, int pass,
281281
memcpy(*dst, start_sequence, sizeof(start_sequence));
282282
memcpy(*dst + sizeof(start_sequence), data, data_len);
283283
}
284+
} else if (type == NAL_RTP_HEVC_AP) {
285+
// untested (copy from decode_h264_nal_unit)
286+
int nal_sizes[100];
287+
unsigned nal_count = 0;
288+
data += 2;
289+
data_len -= 2;
290+
291+
while (data_len > 2) {
292+
uint16_t nal_size;
293+
memcpy(&nal_size, data, sizeof(uint16_t));
294+
nal_size = ntohs(nal_size);
295+
296+
data += 2;
297+
data_len -= 2;
298+
299+
log_msg(LOG_LEVEL_DEBUG2,
300+
"HEVC AP subpacket NAL type %d\n",
301+
(int) HEVC_NALU_HDR_GET_TYPE(data));
302+
303+
if (nal_size <= data_len) {
304+
if (pass == 0) {
305+
*total_length += sizeof(start_sequence) + nal_size;
306+
process_hevc_nal(data, frame, data, data_len);
307+
} else {
308+
assert(nal_count < sizeof nal_sizes / sizeof nal_sizes[0] - 1);
309+
nal_sizes[nal_count++] = nal_size;
310+
}
311+
} else {
312+
error_msg("NAL size exceeds length: %u %d\n", nal_size, data_len);
313+
return false;
314+
}
315+
data += nal_size;
316+
data_len -= nal_size;
317+
318+
if (data_len < 0) {
319+
error_msg("Consumed more bytes than we got! (%d)\n", data_len);
320+
return false;
321+
}
322+
323+
}
324+
if (pass > 0) {
325+
for (int i = nal_count - 1; i >= 0; i--) {
326+
int nal_size = nal_sizes[i];
327+
data -= nal_size;
328+
*dst -= nal_size + sizeof(start_sequence);
329+
memcpy(*dst, start_sequence, sizeof(start_sequence));
330+
memcpy(*dst + sizeof(start_sequence), data, nal_size);
331+
data -= 2;
332+
}
333+
}
284334
} else if (type == NAL_RTP_HEVC_FU) {
285335
data += 2;
286336
data_len -= 2;

0 commit comments

Comments
 (0)