From 72ab033473f34a8f017962bcdf2eba08a703480a Mon Sep 17 00:00:00 2001 From: Martin Pulec Date: Fri, 11 Aug 2023 09:29:16 +0200 Subject: [PATCH] rtpdec_h264: added function to get NALU name --- configure.ac | 2 +- src/rtp/rtpdec_h264.c | 20 ++++++++++++++++++++ src/rtp/rtpdec_h264.h | 18 +++++++++++------- src/video_decompress/libavcodec.c | 9 +++------ 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/configure.ac b/configure.ac index 98c06c516..e7a711577 100644 --- a/configure.ac +++ b/configure.ac @@ -1692,7 +1692,7 @@ then LIBAVCODEC_AUDIO_CODEC_OBJ="$LIBAVCODEC_COMMON src/audio/codec/libavcodec.o" LIBAVCODEC_COMPRESS_OBJ="$LIBAVCODEC_COMMON $LIBAVCODEC_VIDEO $HW_ACC_OBJ src/video_compress/libavcodec.o" - LIBAVCODEC_DECOMPRESS_OBJ="$LIBAVCODEC_COMMON $LIBAVCODEC_VIDEO $HW_ACC_OBJ src/video_decompress/libavcodec.o" + LIBAVCODEC_DECOMPRESS_OBJ="$LIBAVCODEC_COMMON $LIBAVCODEC_VIDEO $HW_ACC_OBJ src/video_decompress/libavcodec.o src/rtp/rtpdec_h264.o src/utils/h264_stream.o" if test $system = MacOSX; then LIBAVCODEC_DECOMPRESS_OBJ="$LIBAVCODEC_DECOMPRESS_OBJ src/hwaccel_videotoolbox.o" fi diff --git a/src/rtp/rtpdec_h264.c b/src/rtp/rtpdec_h264.c index 456075e85..6a0f85c13 100644 --- a/src/rtp/rtpdec_h264.c +++ b/src/rtp/rtpdec_h264.c @@ -344,4 +344,24 @@ int width_height_from_SDP(int *widthOut, int *heightOut , unsigned char *data, i return 0; } +const char * +get_nalu_name(int type) +{ + _Thread_local static char buf[32]; + + switch (type) { + case NAL_IDR: + return "H264 IDR"; + case NAL_SEI: + return "H264 SEI"; + case NAL_SPS: + return "H264 SPS"; + case NAL_HEVC_VPS: + return "HEVC VPS"; + default: + snprintf(buf, sizeof buf, "(NALU %d)", type); + return buf; + } +} + // vi: set et sw=4 : diff --git a/src/rtp/rtpdec_h264.h b/src/rtp/rtpdec_h264.h index f0297969b..e66faacca 100644 --- a/src/rtp/rtpdec_h264.h +++ b/src/rtp/rtpdec_h264.h @@ -48,13 +48,16 @@ extern "C" { #endif -#define NAL_MIN 1 -#define NAL_IDR 5 -#define NAL_SEI 6 -#define NAL_SPS 7 -#define NAL_MAX 23 - -#define NAL_HEVC_VPS 32 +enum { + // H.264 + NAL_MIN = 1, + NAL_IDR = 5, + NAL_SEI = 6, + NAL_SPS = 7, + NAL_MAX = 23, + // HEVC + NAL_HEVC_VPS = 32, +}; struct video_frame; @@ -71,6 +74,7 @@ struct coded_data; int decode_frame_h264(struct coded_data *cdata, void *decode_data); int width_height_from_SDP(int *widthOut, int *heightOut , unsigned char *data, int data_len); +const char *get_nalu_name(int type); #ifdef __cplusplus } diff --git a/src/video_decompress/libavcodec.c b/src/video_decompress/libavcodec.c index 1195e7435..27497a3bd 100644 --- a/src/video_decompress/libavcodec.c +++ b/src/video_decompress/libavcodec.c @@ -817,20 +817,17 @@ static _Bool check_first_sps_vps(struct state_libavcodec_decompress *s, unsigned nalu_type = first_nal[0] >> 1; } - s->sps_vps_found = 1; switch (nalu_type) { case NAL_SPS: - log_msg(LOG_LEVEL_VERBOSE, - MOD_NAME "Received H.264 SPS NALU, decoding begins.\n"); - return 1; case NAL_HEVC_VPS: + s->sps_vps_found = 1; log_msg(LOG_LEVEL_VERBOSE, - MOD_NAME "Received HEVC VPS NALU, decoding begins.\n"); + MOD_NAME "Received %s NALU, decoding begins.\n", + get_nalu_name(nalu_type)); return 1; default: log_msg(LOG_LEVEL_WARNING, MOD_NAME "Waiting for first SPS/VPS NALU...\n"); - s->sps_vps_found = 0; return 0; } }