From d96a88673cb1bb8aec6243f54964bdf8aa951283 Mon Sep 17 00:00:00 2001 From: Yandong Lin Date: Mon, 3 Apr 2023 15:41:04 +0800 Subject: [PATCH] feat[h264d]: support hdr meta parse Signed-off-by: Yandong Lin Change-Id: Id17781edfe480c859a2e89909e517030ea07c43b --- mpp/base/mpp_dec_hdr_meta.c | 25 +++++++++++++------ mpp/codec/dec/h264/h264d_api.c | 1 + mpp/codec/dec/h264/h264d_global.h | 2 ++ mpp/codec/dec/h264/h264d_init.c | 8 ++++++ mpp/codec/dec/h264/h264d_parse.c | 41 +++++++++++++++++++++++++++++++ mpp/common/h264_syntax.h | 3 ++- 6 files changed, 72 insertions(+), 8 deletions(-) diff --git a/mpp/base/mpp_dec_hdr_meta.c b/mpp/base/mpp_dec_hdr_meta.c index e64821fa..3161ff7e 100644 --- a/mpp/base/mpp_dec_hdr_meta.c +++ b/mpp/base/mpp_dec_hdr_meta.c @@ -114,15 +114,26 @@ void fill_hdr_meta_to_frame(MppFrame frame, MppCodingType in_type) * hevc trc = 18 * avs trc = 14 * hdr10: - * hevc trc = 16 + * hevc/h264 trc = 16 * avs trc = 12 */ - if ((codec_type == HDR_HEVC && static_meta->color_trc == MPP_FRAME_TRC_ARIB_STD_B67) || - (codec_type == HDR_AVS2 && static_meta->color_trc == MPP_FRAME_TRC_BT2020_10)) - hdr_format = HLG; - if ((codec_type == HDR_HEVC && static_meta->color_trc == MPP_FRAME_TRC_SMPTEST2084) || - (codec_type == HDR_AVS2 && static_meta->color_trc == MPP_FRAME_TRC_BT1361_ECG)) - hdr_format = HDR10; + switch (codec_type) { + case HDR_HEVC : + case HDR_H264 : { + if (static_meta->color_trc == MPP_FRAME_TRC_ARIB_STD_B67) + hdr_format = HLG; + else if (static_meta->color_trc == MPP_FRAME_TRC_SMPTEST2084) + hdr_format = HDR10; + } break; + case HDR_AVS2 : { + if (static_meta->color_trc == MPP_FRAME_TRC_BT2020_10) + hdr_format = HLG; + else if (static_meta->color_trc == MPP_FRAME_TRC_BT1361_ECG) + hdr_format = HDR10; + } break; + default : { + } break; + } } off += hdr_static_meta_header->size; diff --git a/mpp/codec/dec/h264/h264d_api.c b/mpp/codec/dec/h264/h264d_api.c index 7e9c24df..df2250fb 100644 --- a/mpp/codec/dec/h264/h264d_api.c +++ b/mpp/codec/dec/h264/h264d_api.c @@ -89,6 +89,7 @@ static MPP_RET free_cur_ctx(H264dCurCtx_t *p_Cur) MPP_FREE(p_Cur->subsps); MPP_FREE(p_Cur->sei); + MPP_FREE(p_Cur->hdr_dynamic_meta); } __RETURN: diff --git a/mpp/codec/dec/h264/h264d_global.h b/mpp/codec/dec/h264/h264d_global.h index e3d7f16a..8126d983 100644 --- a/mpp/codec/dec/h264/h264d_global.h +++ b/mpp/codec/dec/h264/h264d_global.h @@ -971,6 +971,8 @@ typedef struct h264d_cur_ctx_t { RK_S32 abs_diff_view_idx_minus1[2][MAX_REORDER_TIMES]; struct h264_drpm_t *dec_ref_pic_marking_buffer[MAX_MARKING_TIMES]; + MppFrameHdrDynamicMeta *hdr_dynamic_meta; + RK_U32 hdr_dynamic; } H264dCurCtx_t; //!< parameters for video decoder diff --git a/mpp/codec/dec/h264/h264d_init.c b/mpp/codec/dec/h264/h264d_init.c index 768d1970..4158036a 100644 --- a/mpp/codec/dec/h264/h264d_init.c +++ b/mpp/codec/dec/h264/h264d_init.c @@ -546,6 +546,8 @@ static MPP_RET dpb_mark_malloc(H264dVideoCtx_t *p_Vid, H264_StorePic_t *dec_pic) impl->color_primaries = p->colour_primaries; impl->color_trc = p->transfer_characteristics; impl->colorspace = p->matrix_coefficients; + if (impl->color_trc == MPP_FRAME_TRC_SMPTEST2084) + impl->fmt |= MPP_FRAME_HDR; } else { impl->color_primaries = MPP_FRAME_PRI_UNSPECIFIED; impl->color_trc = MPP_FRAME_TRC_UNSPECIFIED; @@ -553,6 +555,12 @@ static MPP_RET dpb_mark_malloc(H264dVideoCtx_t *p_Vid, H264_StorePic_t *dec_pic) } } + if (p_Vid->p_Cur->hdr_dynamic && p_Vid->p_Cur->hdr_dynamic_meta) { + impl->hdr_dynamic_meta = p_Vid->p_Cur->hdr_dynamic_meta; + p_Vid->p_Cur->hdr_dynamic = 0; + impl->fmt |= MPP_FRAME_HDR; + } + impl->poc = dec_pic->poc; impl->viewid = dec_pic->layer_id; impl->status.is_intra = dec_pic->slice_type == H264_I_SLICE; diff --git a/mpp/codec/dec/h264/h264d_parse.c b/mpp/codec/dec/h264/h264d_parse.c index 4fd8116a..91b14a06 100644 --- a/mpp/codec/dec/h264/h264d_parse.c +++ b/mpp/codec/dec/h264/h264d_parse.c @@ -32,6 +32,7 @@ #include "h264d_sei.h" #include "h264d_init.h" #include "h264d_fill.h" +#include "rk_hdr_meta_com.h" #define HEAD_SYNTAX_MAX_SIZE (12800) #define NALU_TYPE_NORMAL_LENGTH (1) @@ -336,6 +337,41 @@ __FAILED: return ret; } +void mpp_h264d_fill_dynamic_meta(H264dCurCtx_t *p_Cur, const RK_U8 *data, RK_U32 size, RK_U32 hdr_fmt) +{ + MppFrameHdrDynamicMeta *hdr_dynamic_meta = p_Cur->hdr_dynamic_meta; + + if (hdr_fmt == DOLBY) + size += 4; + + if (hdr_dynamic_meta && (hdr_dynamic_meta->size < size)) { + mpp_free(hdr_dynamic_meta); + hdr_dynamic_meta = NULL; + } + + if (!hdr_dynamic_meta) { + hdr_dynamic_meta = mpp_calloc_size(MppFrameHdrDynamicMeta, + sizeof(MppFrameHdrDynamicMeta) + size); + if (!hdr_dynamic_meta) { + mpp_err_f("malloc hdr dynamic data failed!\n"); + return; + } + } + if (size && data) { + if (hdr_fmt == DOLBY) { + RK_U8 start_code[4] = {0, 0, 0, 1}; + + memcpy((RK_U8*)hdr_dynamic_meta->data, start_code, 4); + memcpy((RK_U8*)hdr_dynamic_meta->data + 4, (RK_U8*)data, size - 4); + } else + memcpy((RK_U8*)hdr_dynamic_meta->data, (RK_U8*)data, size); + hdr_dynamic_meta->size = size; + hdr_dynamic_meta->hdr_fmt = hdr_fmt; + } + p_Cur->hdr_dynamic_meta = hdr_dynamic_meta; + p_Cur->hdr_dynamic = 1; +} + static MPP_RET store_cur_nalu(H264dCurCtx_t *p_Cur, H264dCurStream_t *p_strm, H264dDxvaCtx_t *dxva_ctx) { MPP_RET ret = MPP_ERR_UNKNOW; @@ -405,6 +441,11 @@ static MPP_RET store_cur_nalu(H264dCurCtx_t *p_Cur, H264dCurStream_t *p_strm, H2 memcpy(p_des + sizeof(g_start_precode), p_strm->nalu_buf, p_strm->nalu_len); dxva_ctx->strm_offset += add_size; } + + /* Dolby Vision RPUs masquerade as unregistered NALs of type 28. */ + if (p_strm->nalu_type == H264_NALU_TYPE_UNSPECIFIED28) + mpp_h264d_fill_dynamic_meta(p_Cur, p_strm->nalu_buf + 2, p_strm->nalu_len - 2, DOLBY); + if (h264d_debug & H264D_DBG_WRITE_ES_EN) { H264dInputCtx_t *p_Inp = p_Cur->p_Inp; if ((p_strm->nalu_type == H264_NALU_TYPE_SPS) diff --git a/mpp/common/h264_syntax.h b/mpp/common/h264_syntax.h index 4c9474ad..ac1f85c9 100644 --- a/mpp/common/h264_syntax.h +++ b/mpp/common/h264_syntax.h @@ -94,7 +94,8 @@ typedef enum H264NaluType_e { H264_NALU_TYPE_SUB_SPS = 15, H264_NALU_TYPE_SLICE_AUX = 19, H264_NALU_TYPE_SLC_EXT = 20, // slice extensive - H264_NALU_TYPE_VDRD = 24 // View and Dependency Representation Delimiter NAL Unit + H264_NALU_TYPE_VDRD = 24, // View and Dependency Representation Delimiter NAL Unit + H264_NALU_TYPE_UNSPECIFIED28 = 28, } H264NaluType; typedef enum H264ChromaFmt_e {