@@ -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
289341static void
0 commit comments