6363/// type was 1-23 representing H.264 NAL type
6464#define H264_NAL 32
6565
66- #define MOD_NAME "[rtpdec_h264 ] "
66+ #define MOD_NAME "[rtpdec_h2645 ] "
6767
6868static const uint8_t start_sequence [] = { 0 , 0 , 0 , 1 };
6969
@@ -415,14 +415,18 @@ get_sps_pps_frame(const struct video_desc *desc,
415415 return frame ;
416416}
417417
418- int decode_frame_h264 (struct coded_data * cdata , void * decode_data ) {
418+ int decode_frame_h2645 (struct coded_data * cdata , void * decode_data ) {
419419 struct coded_data * orig = cdata ;
420420
421421 int total_length = 0 ;
422422
423423 struct decode_data_rtsp * data = decode_data ;
424424 struct video_frame * frame = data -> frame ;
425425 frame -> frame_type = BFRAME ;
426+ assert (frame -> color_spec == H264 || frame -> color_spec == H265 );
427+ bool (* const decode_nal_unit )(struct video_frame * , int * , int ,
428+ unsigned char * * , uint8_t * , int ) =
429+ frame -> color_spec == H264 ? decode_h264_nal_unit : decode_hevc_nal_unit ;
426430
427431 for (int pass = 0 ; pass < 2 ; pass ++ ) {
428432 unsigned char * dst = NULL ;
@@ -442,49 +446,7 @@ int decode_frame_h264(struct coded_data *cdata, void *decode_data) {
442446 while (cdata != NULL ) {
443447 rtp_packet * pckt = cdata -> data ;
444448
445- if (!decode_h264_nal_unit (frame , & total_length , pass , & dst , (uint8_t * ) pckt -> data , pckt -> data_len )) {
446- return false;
447- }
448-
449- cdata = cdata -> nxt ;
450- }
451- }
452-
453- if (frame -> frame_type == INTRA ) {
454- write_sps_pps (frame , data );
455- }
456-
457- return true;
458- }
459-
460- int decode_frame_hevc (struct coded_data * cdata , void * decode_data ) {
461- struct coded_data * orig = cdata ;
462-
463- int total_length = 0 ;
464-
465- struct decode_data_rtsp * data = decode_data ;
466- struct video_frame * frame = data -> frame ;
467- frame -> frame_type = BFRAME ;
468-
469- for (int pass = 0 ; pass < 2 ; pass ++ ) {
470- unsigned char * dst = NULL ;
471-
472- if (pass > 0 ) {
473- cdata = orig ;
474- if (frame -> frame_type == INTRA ){
475- total_length += data -> offset_len ;
476- }
477- frame -> tiles [0 ].data_len = total_length ;
478- assert (frame -> tiles [0 ].data == NULL );
479- frame -> tiles [0 ].data = malloc (total_length );
480- frame -> callbacks .data_deleter = vf_data_deleter ;
481- dst = (unsigned char * ) frame -> tiles [0 ].data + total_length ;
482- }
483-
484- while (cdata != NULL ) {
485- rtp_packet * pckt = cdata -> data ;
486-
487- if (!decode_hevc_nal_unit (frame , & total_length , pass , & dst , (uint8_t * ) pckt -> data , pckt -> data_len )) {
449+ if (!decode_nal_unit (frame , & total_length , pass , & dst , (uint8_t * ) pckt -> data , pckt -> data_len )) {
488450 return false;
489451 }
490452
0 commit comments