Skip to content

Commit 07715c6

Browse files
committed
rtpdec_hevc: implement FU packets
1 parent e96314c commit 07715c6

File tree

2 files changed

+59
-3
lines changed

2 files changed

+59
-3
lines changed

src/rtp/rtpdec_h264.c

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ decode_hevc_nal_unit(struct video_frame *frame, int *total_length, int pass,
268268
unsigned char **dst, uint8_t *data, int data_len)
269269
{
270270
uint8_t nal[2] = { data[0], data[1] };
271+
int fu_length = 0;
271272
enum hevc_nal_type type = pass == 0
272273
? process_hevc_nal(nal, frame, data, data_len)
273274
: HEVC_NALU_HDR_GET_TYPE(&nal);
@@ -280,10 +281,61 @@ decode_hevc_nal_unit(struct video_frame *frame, int *total_length, int pass,
280281
memcpy(*dst, start_sequence, sizeof(start_sequence));
281282
memcpy(*dst + sizeof(start_sequence), data, data_len);
282283
}
283-
return true;
284+
} else if (type == NAL_RTP_HEVC_FU) {
285+
data += 2;
286+
data_len -= 2;
287+
288+
if (data_len > 1) {
289+
uint8_t fu_header = *data;
290+
uint8_t start_bit = fu_header >> 7;
291+
uint8_t end_bit = (fu_header & 0x40) >> 6;
292+
enum hevc_nal_type nal_type = fu_header & 0x3f;
293+
uint8_t reconstructed_nal[2];
294+
295+
// Reconstruct this packet's true nal; only the data follows.
296+
/* The original nal forbidden bit, layer ID and TID are stored
297+
* packet's nal. */
298+
reconstructed_nal[0] = nal[0] & 0x81; // keep 1st and last bit
299+
reconstructed_nal[0] |= nal_type << 1;
300+
reconstructed_nal[1] = nal[1];
301+
302+
// skip the fu_header
303+
data++;
304+
data_len--;
305+
// + skip DONL if present
306+
307+
if (pass == 0) {
308+
if (end_bit) {
309+
fu_length = data_len;
310+
} else {
311+
fu_length += data_len;
312+
}
313+
if (start_bit) {
314+
*total_length += sizeof(start_sequence) + sizeof(reconstructed_nal) + data_len;
315+
process_hevc_nal(reconstructed_nal, frame, data, fu_length);
316+
} else {
317+
*total_length += data_len;
318+
}
319+
} else {
320+
if (start_bit) {
321+
*dst -= sizeof(start_sequence) + sizeof(reconstructed_nal) + data_len;
322+
memcpy(*dst, start_sequence, sizeof(start_sequence));
323+
memcpy(*dst + sizeof(start_sequence), &reconstructed_nal, sizeof(reconstructed_nal));
324+
memcpy(*dst + sizeof(start_sequence) + sizeof(reconstructed_nal), data, data_len);
325+
} else {
326+
*dst -= data_len;
327+
memcpy(*dst, data, data_len);
328+
}
329+
}
330+
} else {
331+
error_msg("Too short data for FU HEVC RTP packet\n");
332+
return false;
333+
}
334+
} else {
335+
MSG(ERROR, "%s type not implemented!\n", get_hevc_nalu_name(type));
336+
return false;
284337
}
285-
MSG(ERROR, "%s type not implemented!\n", get_hevc_nalu_name(type));
286-
return false;
338+
return true;
287339
}
288340

289341
static void

src/video_capture/rtsp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,6 +1272,10 @@ get_nals(FILE *sdp_file, codec_t codec, char *nals, int *width, int *height) {
12721272
} else {
12731273
sprop = sprop_val;
12741274
}
1275+
if (strcmp(sprop_name, "sprop-max-don-diff") == 0) {
1276+
bug_msg(LOG_LEVEL_ERROR, "sprop-max-don-diff not implemented. ");
1277+
continue;
1278+
}
12751279
if (strcmp(sprop_name, "sprop-parameter-sets") != 0 && // H.264
12761280
strcmp(sprop_name, "sprop-vps") != 0 && // HEVC
12771281
strcmp(sprop_name, "sprop-sps") != 0 &&

0 commit comments

Comments
 (0)