rtpdec_h264: fixed incorrect address-of taken

Using operator & makes it actually the type uint8_t (*)[2], althoug the
pointer value remained the same. The cast then pruned the type - added
checks before the cast if the value given is really ptr to a char type.

Dropped the HEVC hint - now little-endian uint16_t ptr cannot be passed
by mistake.
This commit is contained in:
Martin Pulec
2025-03-28 12:55:15 +01:00
parent 4ef3f49297
commit 2a1deceab8
2 changed files with 32 additions and 16 deletions

View File

@@ -271,7 +271,7 @@ decode_hevc_nal_unit(struct video_frame *frame, int *total_length, int pass,
int fu_length = 0;
enum hevc_nal_type type = pass == 0
? process_hevc_nal(nal, frame, data, data_len)
: HEVC_NALU_HDR_GET_TYPE(&nal);
: HEVC_NALU_HDR_GET_TYPE(nal);
if (type <= NAL_HEVC_MAX) {
if (pass == 0) {

View File

@@ -90,21 +90,6 @@ struct coded_data;
struct decode_data_rtsp;
struct video_desc;
#define H264_NALU_HDR_GET_TYPE(nal) (*(const uint8_t *) (nal) & 0x1F)
#define H264_NALU_HDR_GET_NRI(nal) ((*(const uint8_t *) (nal) & 0x60) >> 5)
/// @param nal pointer to **big-endian** NAL header
#define HEVC_NALU_HDR_GET_TYPE(nal) (*(const uint8_t *) (nal) >> 1)
#define HEVC_NALU_HDR_GET_LAYER_ID(nal) \
((((const uint8_t *) (nal))[0] & 0x1) << 5 | \
((const uint8_t *) (nal))[1] >> 3)
#define HEVC_NALU_HDR_GET_TID(nal) \
(((const uint8_t *) (nal))[1] & 0x7)
#define NALU_HDR_GET_TYPE(nal, is_hevc) \
((is_hevc) ? HEVC_NALU_HDR_GET_TYPE((nal)) \
: H264_NALU_HDR_GET_TYPE((nal)))
int decode_frame_h2645(struct coded_data *cdata, void *decode_data);
struct video_frame *get_sps_pps_frame(const struct video_desc *desc,
struct decode_data_rtsp *decode_data);
@@ -117,4 +102,35 @@ int width_height_from_hevc_sps(int *widthOut, int *heightOut,
}
#endif
// cast just pointers to character types to avoid mistakes
#ifndef __cplusplus
#define RTPDEC_SAFE_CAST(var) \
_Generic((var), \
char *: ((const uint8_t *) (var)), \
unsigned char *: ((const uint8_t *) (var)), \
const char *: ((const uint8_t *) (var)), \
const unsigned char *: ((const uint8_t *) (var)))
#else
template <typename T>
static inline auto
RTPDEC_SAFE_CAST(T var)
{
static_assert(sizeof var[0] == 1);
return (const uint8_t *) var;
}
#endif
#define H264_NALU_HDR_GET_TYPE(nal) (*RTPDEC_SAFE_CAST(nal) & 0x1F)
#define H264_NALU_HDR_GET_NRI(nal) ((*RTPDEC_SAFE_CAST(nal) & 0x60) >> 5)
#define HEVC_NALU_HDR_GET_TYPE(nal) (*RTPDEC_SAFE_CAST(nal) >> 1)
#define HEVC_NALU_HDR_GET_LAYER_ID(nal) \
(((RTPDEC_SAFE_CAST(nal))[0] & 0x1) << 5 | \
(RTPDEC_SAFE_CAST(nal))[1] >> 3)
#define HEVC_NALU_HDR_GET_TID(nal) (RTPDEC_SAFE_CAST(nal)[1] & 0x7)
#define NALU_HDR_GET_TYPE(nal, is_hevc) \
((is_hevc) ? HEVC_NALU_HDR_GET_TYPE((nal)) \
: H264_NALU_HDR_GET_TYPE((nal)))
#endif