int dec_cnk(DEC_CTX * ctx, COM_BITB * bitb, DEC_STAT * stat)
{
COM_BSR *bs;
COM_PIC_HEADER *pic_header;
COM_SQH * sqh;
#if SVAC_SECURITY_PARAM_SET
COM_SEC_PARA_SET* sec_para_set;
#endif
#if SVAC_AUTHENTICATION
COM_AUTH_DATA* auth_data;
#endif
#if HLS_OPT_PPS
COM_PIC_PARA_SET * pps;
#endif
COM_SH_EXT *shext;
COM_CNKH *cnkh;
int ret = COM_OK;
if (stat)
{
com_mset(stat, 0, sizeof(DEC_STAT));
}
bs = &ctx->bs;
sqh = &ctx->info.sqh;
#if HLS_OPT_PPS
pps = &ctx->info.pps[ctx->info.pps_count];
#endif
pic_header = &ctx->info.pic_header;
shext = &ctx->info.shext;
cnkh = &ctx->info.cnkh;
#if SVAC_SECURITY_PARAM_SET
sec_para_set = &ctx->info.sec_para_set;
#endif
#if SVAC_AUTHENTICATION
auth_data = &ctx->info.auth_data;
#endif
/* set error status */
ctx->bs_err = (u8)bitb->err;
#if TRACE_RDO_EXCLUDE_I
if (pic_header->slice_type != SLICE_I)
{
#endif
COM_TRACE_SET(1);
#if TRACE_RDO_EXCLUDE_I
}
else
{
COM_TRACE_SET(0);
}
#endif
/* bitstream reader initialization */
com_bsr_init(bs, bitb->addr, bitb->ssize, NULL);
SET_SBAC_DEC(bs, &ctx->sbac_dec);
#if SVAC_NAL
if (bs->cur[3] == SVAC_SPS)
#else
if (bs->cur[3] == 0xB0)
#endif
{
#if LIB_PIC_MIXBIN
int need_update = COM_CT_CRR_SLICE == cnkh->ctype || COM_CT_CRR_SLICE_IMCOPLETE == cnkh->ctype
#if SVAC_SECURITY_PARAM_SET
|| cnkh->ctype == COM_CT_SEC_PARA_SET
#endif
;
#endif
#if HLS_OPT_PPS
ctx->info.pps_count = 0;
memset(ctx->info.pps, 0, sizeof(ctx->info.pps));
#endif
cnkh->ctype = COM_CT_SQH;
ret = dec_eco_sqh(bs, sqh);
com_assert_rv(COM_SUCCEEDED(ret), ret);
#if LIBVC_ON
ctx->dpm.libvc_data->is_libpic_processing = sqh->library_stream_flag;
ctx->dpm.libvc_data->library_picture_enable_flag = sqh->library_picture_enable_flag;
#if LIBPIC_DISPLAY
ctx->dpm.libvc_data->libpic_mode_index = sqh->library_picture_mode_index;
#endif
#endif
#if EXTENSION_USER_DATA
extension_and_user_data(ctx, bs, 0, sqh, pic_header);
#endif
#if LIB_PIC_MIXBIN
if (sqh->library_stream_flag)
{
if (!ctx->libpic_init_flag)
{
ret = sequence_init(ctx, sqh);
com_assert_rv(COM_SUCCEEDED(ret), ret);
#if MULTI_LAYER_FRAMEWORK
g_DOIPrev[ctx->layer_id] = g_CountDOICyCleTime[ctx->layer_id] = 0;
#else
g_DOIPrev = g_CountDOICyCleTime = 0;
#endif
ctx->libpic_init_flag = 1;
ctx->init_flag = 1;
}
}
else
#endif
if( !ctx->init_flag )
{
ret = sequence_init(ctx, sqh);
com_assert_rv(COM_SUCCEEDED(ret), ret);
#if MULTI_LAYER_FRAMEWORK
g_DOIPrev[ctx->layer_id] = g_CountDOICyCleTime[ctx->layer_id] = 0;
#else
g_DOIPrev = g_CountDOICyCleTime = 0;
#endif
ctx->init_flag = 1;
}
#if LIB_PIC_MIXBIN
if (sqh->library_stream_flag && sqh->library_picture_mixbin_flag) {
memcpy(&ctx->info.libpic_sqh, sqh, sizeof(COM_SQH));
ret = sequence_init(ctx, sqh);
com_assert_rv(COM_SUCCEEDED(ret), ret);
}
else {
memcpy(&ctx->info.normal_sqh, sqh, sizeof(COM_SQH));
if (need_update) {
ret = sequence_init(ctx, sqh);
com_assert_rv(COM_SUCCEEDED(ret), ret);
}
}
#endif
}
#if !SVAC_NAL
else if( bs->cur[3] == 0xB1 )
{
ctx->init_flag = 0;
cnkh->ctype = COM_CT_SEQ_END;
}
#endif
#if HLS_OPT_PPS
else if (bs->cur[3] == SVAC_PPS)
{
cnkh->ctype = COM_CT_PPS;
ret = dec_eco_pps(bs, sqh, pps);
ctx->info.pps_count++;
assert(ctx->info.pps_count <= MAX_PPS_NUM);
com_assert_rv(COM_SUCCEEDED(ret), ret);
#if LIB_PIC_MIXBIN
if (sqh->library_stream_flag)
ctx->info.libpic_pps_idx = ctx->info.pps_count - 1;
else
ctx->info.normal_pps_idx = ctx->info.pps_count - 1;
#endif
}
#endif
#if SVAC_NAL
#if HLS_OPT_PPS
else if (bs->cur[3] == SVAC_PH)
#else
else if (bs->cur[3] == SVAC_PPS)
#endif
#else
else if (bs->cur[3] == 0xB3 || bs->cur[3] == 0xB6)
#endif
{
#if MULTI_LAYER_FRAMEWORK
if (ctx->layer_id)
{
if (!ctx->init_flag)
{
ret = sequence_init(ctx, sqh);
com_assert_rv(COM_SUCCEEDED(ret), ret);
g_DOIPrev[ctx->layer_id] = g_CountDOICyCleTime[ctx->layer_id] = 0;
ctx->init_flag = 1;
if (ctx->layer_id && !sqh->sps_independent_layer_flag[ctx->layer_id])
{
COM_PM* pm = &(ctx->dpm);
int size;
pm->pic_tmp[0] = com_pic_alloc(&pm->pa, &ret);
pm->pic_tmp[1] = com_pic_alloc(&pm->pa, &ret);
size = sizeof(s8) * ctx->info.f_scu * REFP_NUM;
memset(pm->pic_tmp[0]->map_refi, -1, size);
size = sizeof(s16) * ctx->info.f_scu * REFP_NUM * MV_D;
memset(pm->pic_tmp[0]->map_mv, 0, size);
#if CU_LEVEL_PRIVACY
size = sizeof(u8) * ctx->info.f_scu;
memset(pm->pic_tmp[0]->map_privacy, 0, size);
#endif
}
}
}
#endif
#if LIB_PIC_MIXBIN
if (COM_CT_CRR_SLICE == cnkh->ctype || COM_CT_CRR_SLICE_IMCOPLETE == cnkh->ctype) {
assert(sqh->library_picture_mixbin_flag == 1);
memcpy(sqh, &ctx->info.normal_sqh, sizeof(COM_SQH));
ret = sequence_init(ctx, sqh);
com_assert_rv(COM_SUCCEEDED(ret), ret);
#if HLS_OPT_PPS
pps = &ctx->info.pps[ctx->info.normal_pps_idx];
#endif
ctx->dpm.libvc_data->is_libpic_processing = sqh->library_stream_flag;
ctx->dpm.libvc_data->library_picture_enable_flag = sqh->library_picture_enable_flag;
}
#endif
cnkh->ctype = COM_CT_PICTURE;
/* decode slice header */
pic_header->low_delay = sqh->low_delay;
int need_minus_256 = 0;
#if HLS_OPT_PPS
ret = dec_eco_pic_header(bs, ctx, &need_minus_256);
#if MULTI_LAYER_FRAMEWORK
assert(ctx->layer_id == pic_header->layer_id);
if (ctx->layer_id && !sqh->sps_independent_layer_flag[ctx->layer_id] )
{
DEC_CTX* ctx_b = (DEC_CTX*)ctx->ctx_b;
upsample_base_pic(&ctx->dpm, ctx_b->pic, &ctx_b->info, &ctx->info, ctx_b->layer_id, ctx->layer_id);
add_pic(&ctx_b->dpm, &ctx->dpm, ctx_b->pic, ctx_b->layer_id, &ctx_b->info, &ctx->info, ctx_b->info.pic_header.decode_order_index, ctx_b->ptr, ctx->refp, ctx->info.sqh.ref_layer_id[ctx->layer_id], ctx_b->info.poc);
}
#endif
#else
ret = dec_eco_pic_header(bs, pic_header, sqh, &need_minus_256);
#endif
if (need_minus_256)
{
com_picman_dpbpic_doi_minus_cycle_length( &ctx->dpm );
}
#if HLS_OPT_PPS
ctx->wq[0] = ctx->info.pps[pic_header->pic_pps_id].wq_4x4_matrix;
ctx->wq[1] = ctx->info.pps[pic_header->pic_pps_id].wq_8x8_matrix;
#else
ctx->wq[0] = pic_header->wq_4x4_matrix;
ctx->wq[1] = pic_header->wq_8x8_matrix;
#endif
if (!sqh->library_stream_flag)
{
com_picman_check_repeat_doi(&ctx->dpm, pic_header);
}
#if LIB_PIC_MIXBIN
if (sqh->library_stream_flag && sqh->library_picture_mixbin_flag) {
memcpy(&ctx->info.libpic_pic_header, pic_header, sizeof(COM_PIC_HEADER));
memcpy(ctx->libpic_pic_esao_params, ctx->info.pic_header.pic_esao_params, N_C * sizeof(ESAO_BLK_PARAM));
memcpy(ctx->libpic_pic_ccsao_params, ctx->info.pic_header.pic_ccsao_params, (N_C - 1) * sizeof(CCSAO_BLK_PARAM));
for (int comp_idx = 0; comp_idx < N_C; comp_idx++) {
#if ALF_SHAPE
int num_coef = (ctx->info.sqh.adaptive_leveling_filter_enhance_flag) ? ALF_MAX_NUM_COEF_SHAPE2 : ALF_MAX_NUM_COEF;
#endif
copy_alf_param(ctx->dec_alf->libpic_alf_picture_param[comp_idx], ctx->dec_alf->alf_picture_param[comp_idx]
#if ALF_SHAPE
, num_coef
#if ALF_SHIFT
+ (int)ctx->info.sqh.adaptive_leveling_filter_enhance_flag
#endif
#endif
);
}
}
#endif
#if LIBPIC_DISPLAY
ctx->dpm.libvc_data->libpic_index = pic_header->library_picture_index;
#endif
#if HIGH_LEVEL_PRIVACY
memset(ctx->ctx_privacy_data.region_max_num, 0, sizeof(int) * 10);
#endif
#if EXTENSION_USER_DATA && WRITE_MD5_IN_USER_DATA
extension_and_user_data(ctx, bs, 1, sqh, pic_header);
#endif
com_constrcut_ref_list_doi(pic_header);
//add by Yuqun Fan, init rpl list at ph instead of sh
#if HLS_RPL
#if LIBVC_ON
if (!sqh->library_stream_flag)
#endif
{
ret = com_picman_refpic_marking_decoder(&ctx->dpm, pic_header);
com_assert_rv(ret == COM_OK, ret);
}
com_cleanup_useless_pic_buffer_in_pm(&ctx->dpm);
/* reference picture lists construction */
ret = com_picman_refp_rpl_based_init_decoder(&ctx->dpm, pic_header, ctx->refp);
#if AWP
if (ctx->info.pic_header.slice_type == SLICE_P || ctx->info.pic_header.slice_type == SLICE_B)
{
for (int i = 0; i < ctx->dpm.num_refp[REFP_0]; i++)
{
ctx->info.pic_header.ph_poc[REFP_0][i] = ctx->refp[i][REFP_0].ptr;
}
}
if (ctx->info.pic_header.slice_type == SLICE_B)
{
for (int i = 0; i < ctx->dpm.num_refp[REFP_1]; i++)
{
ctx->info.pic_header.ph_poc[REFP_1][i] = ctx->refp[i][REFP_1].ptr;
}
}
#endif
#endif
com_assert_rv(COM_SUCCEEDED(ret), ret);
}
#if SVAC_NAL
else if ((bs->cur[3] == SVAC_IDR || bs->cur[3] == SVAC_NON_RAP || bs->cur[3] == SVAC_RAP_I
#if LIB_PIC_MIXBIN
|| bs->cur[3] == SVAC_CRR_L || bs->cur[3] == SVAC_CRR_RL
#if DISPLAY_L_NAL_TYPE
|| bs->cur[3] == SVAC_CRR_DP
#endif
#if LIB_PIC_ERR_TOL
|| bs->cur[3] == SVAC_CRR_DL
#endif
#endif
) && bs->cur[4] <= 0x8E)
#else
else if (bs->cur[3] >= 0x00 && bs->cur[3] <= 0x8E)
#endif
{
#if LIB_PIC_MIXBIN
#if DISPLAY_L_NAL_TYPE
if (!sqh->library_stream_flag && (bs->cur[3] == SVAC_CRR_L || bs->cur[3] == SVAC_CRR_DP
#if LIB_PIC_ERR_TOL
|| bs->cur[3] == SVAC_CRR_DL
#endif
))
#else
if (!sqh->library_stream_flag && bs->cur[3] == SVAC_CRR_L)
#endif
{
assert(sqh->library_picture_mixbin_flag == 1);
memcpy(sqh, &ctx->info.libpic_sqh, sizeof(COM_SQH));
ret = sequence_init(ctx, sqh);
com_assert_rv(COM_SUCCEEDED(ret), ret);
#if HLS_OPT_PPS
pps = &ctx->info.pps[ctx->info.libpic_pps_idx];
#endif
ctx->dpm.libvc_data->is_libpic_processing = sqh->library_stream_flag;
ctx->dpm.libvc_data->library_picture_enable_flag = sqh->library_picture_enable_flag;
memcpy(pic_header, &ctx->info.libpic_pic_header, sizeof(COM_PIC_HEADER));
memcpy(pic_header->pic_esao_params, ctx->libpic_pic_esao_params, N_C * sizeof(ESAO_BLK_PARAM));
memcpy(pic_header->pic_ccsao_params, ctx->libpic_pic_ccsao_params, (N_C - 1) * sizeof(CCSAO_BLK_PARAM));
memcpy(ctx->pic_alf_on, ctx->libpic_pic_alf_on, N_C * sizeof(int));
for (int comp_idx = 0; comp_idx < N_C; comp_idx++) {
#if ALF_SHAPE
int num_coef = (ctx->info.sqh.adaptive_leveling_filter_enhance_flag) ? ALF_MAX_NUM_COEF_SHAPE2 : ALF_MAX_NUM_COEF;
#endif
copy_alf_param(ctx->dec_alf->alf_picture_param[comp_idx], ctx->dec_alf->libpic_alf_picture_param[comp_idx]
#if ALF_SHAPE
, num_coef
#if ALF_SHIFT
+ (int)ctx->info.sqh.adaptive_leveling_filter_enhance_flag
#endif
#endif
);
memcpy(ctx->info.pic_header.pic_esao_params[comp_idx].lcu_flag, ctx->libpic_esao_lcu_flag[comp_idx], ctx->info.f_lcu * sizeof(int));
if (comp_idx)
memcpy(ctx->info.pic_header.pic_ccsao_params[comp_idx - 1].lcu_flag, ctx->libpic_ccsao_lcu_flag[comp_idx - 1], ctx->info.f_lcu * sizeof(int));
}
for (int lcu_idx = 0; lcu_idx < ctx->info.f_lcu; lcu_idx++) {
copy_sao_param_for_blk(ctx->sao_blk_params[lcu_idx], ctx->libpic_sao_blk_params[lcu_idx]);
copy_sao_param_for_blk(ctx->rec_sao_blk_params[lcu_idx], ctx->libpic_rec_sao_blk_params[lcu_idx]);
memcpy(ctx->dec_alf->alf_lcu_enabled[lcu_idx], ctx->dec_alf->libpic_alf_lcu_enabled[lcu_idx], N_C * sizeof(int));
}
memcpy(ctx->map.map_pb_tb_part, ctx->map.libpic_map_pb_tb_part, ctx->info.f_scu * sizeof(u32));
memcpy(ctx->map.map_patch_idx, ctx->map.libpic_map_patch_idx, ctx->info.f_scu * sizeof(s8));
memcpy(ctx->map.map_split, ctx->map.libpic_map_split, ctx->info.f_lcu * sizeof(s8)* MAX_CU_DEPTH* NUM_BLOCK_SHAPE* MAX_CU_CNT_IN_LCU);
mCabac_ws = MCABAC_SHIFT_I;
mCabac_offset = (1 << (mCabac_ws - 1));
counter_thr1 = 0;
counter_thr2 = COUNTER_THR_I;
#if HLS_OPT_PPS
ctx->wq[0] = ctx->info.pps[pic_header->pic_pps_id].wq_4x4_matrix;
ctx->wq[1] = ctx->info.pps[pic_header->pic_pps_id].wq_8x8_matrix;
#else
ctx->wq[0] = pic_header->wq_4x4_matrix;
ctx->wq[1] = pic_header->wq_8x8_matrix;
#endif
}
#if DISPLAY_L_NAL_TYPE
if (sqh->library_stream_flag && (bs->cur[3] != SVAC_CRR_L && bs->cur[3] != SVAC_CRR_DP
#if LIB_PIC_ERR_TOL
&& bs->cur[3] != SVAC_CRR_DL
#endif
))
#else
if (sqh->library_stream_flag && bs->cur[3] != SVAC_CRR_L)
#endif
{
assert(sqh->library_picture_mixbin_flag == 1);
memcpy(sqh, &ctx->info.normal_sqh, sizeof(COM_SQH));
ret = sequence_init(ctx, sqh);
com_assert_rv(COM_SUCCEEDED(ret), ret);
#if HLS_OPT_PPS
pps = &ctx->info.pps[ctx->info.normal_pps_idx ];
#endif
ctx->dpm.libvc_data->is_libpic_processing = sqh->library_stream_flag;
ctx->dpm.libvc_data->library_picture_enable_flag = sqh->library_picture_enable_flag;
}
#if LIBPIC_DISPLAY
int is_patch_l = sqh->library_stream_flag && sqh->library_picture_mixbin_flag && ctx->info.sqh.library_picture_mode_index != 1;
#else
int is_patch_l = sqh->library_stream_flag && sqh->library_picture_mixbin_flag;
#endif
#endif
cnkh->ctype = COM_CT_SLICE;
#if SVAC_NAL
if (bs->cur[3] == SVAC_IDR)
picman_reset_dpb(&ctx->dpm);
#endif
#if CU_LEVEL_PRIVACY
COM_BSR *bs_privacy = &ctx->bs_privacy;
com_bsr_init(bs_privacy, bitb->addr2, bitb->ssize2, NULL);
SET_SBAC_DEC(bs_privacy, &ctx->sbac_dec_privacy);
if (ctx->user_permission && ctx->info.pic_header.ph_privacy_on)
{
while (com_bsr_next(bs_privacy, 24) != 0x1)
{
ret = com_bsr_read(bs_privacy, 8);
};
unsigned int nalu_type = 0, temporal_id = 0, layer_id = 0;
dec_eco_nalu_header(bs_privacy, &nalu_type, &temporal_id, &layer_id);
assert(nalu_type == SVAC_PRIVACY);
#if TSVC_OPT
assert(temporal_id == ctx->info.pic_header.temporal_id);
#endif
#if MULTI_LAYER_FRAMEWORK
assert(layer_id == ctx->info.pic_header.layer_id);
#endif
}
#endif
#if HLS_OPT_PPS
ret = dec_eco_patch_header(bs, sqh, &ctx->info.pps[pic_header->pic_pps_id], pic_header, shext, ctx->patch);
#else
ret = dec_eco_patch_header(bs, sqh, pic_header, shext, ctx->patch);
#endif
#if LIB_PIC_MIXBIN
if (is_patch_l && ctx->patch->idx + 1 < ctx->patch->rows * ctx->patch->columns)
cnkh->ctype = COM_CT_CRR_SLICE_IMCOPLETE;
#if LIBPIC_DISPLAY
else if (is_patch_l || (sqh->library_stream_flag && ctx->info.sqh.library_picture_mode_index == 1))
#else
else if (is_patch_l)
#endif
cnkh->ctype = COM_CT_CRR_SLICE;
#endif
/* initialize slice */
ret = slice_init(ctx, ctx->core, pic_header);
com_assert_rv(COM_SUCCEEDED(ret), ret);
#if LIB_PIC_MIXBIN
if (is_patch_l && ctx->patch->idx != 0)
{
ctx->pic = ctx->libpic_pic;
}
else
{
#endif
/* get available frame buffer for decoded image */
ctx->pic = com_picman_get_empty_pic(&ctx->dpm, &ret);
com_assert_rv(ctx->pic, ret);
#if LIB_PIC_MIXBIN
if (is_patch_l && ctx->patch->idx == 0)
ctx->libpic_pic = ctx->pic;
}
#endif
/* get available frame buffer for decoded image */
ctx->map.map_refi = ctx->pic->map_refi;
ctx->map.map_mv = ctx->pic->map_mv;
#if CU_LEVEL_PRIVACY
ctx->map.map_privacy = ctx->pic->map_privacy;
#endif
#if CU_LEVEL_PRIVACY
com_mset_x64a(ctx->map.map_privacy_pic_filter[0], 0, sizeof(COM_FILTER_SKIP)* ctx->info.pic_width* ctx->info.pic_height);
com_mset_x64a(ctx->map.map_privacy_pic_filter[1], 0, sizeof(COM_FILTER_SKIP)* ctx->info.pic_width* ctx->info.pic_height);
#endif
/* decode slice layer */
#if HLS_OPT_PPS
ret = dec_pic(ctx, ctx->core, sqh, &ctx->info.pps[pic_header->pic_pps_id], pic_header, shext);
#else
ret = dec_pic(ctx, ctx->core, sqh, pic_header, shext);
#endif
com_assert_rv(COM_SUCCEEDED(ret), ret);
#if LIB_PIC_MIXBIN
if (!is_patch_l || (is_patch_l && ctx->patch->idx + 1 == ctx->patch->rows * ctx->patch->columns))
{
#endif
/* deblocking filter */
#if HLS_OPT_PPS
if (ctx->info.pps[ctx->info.pic_header.pic_pps_id].loop_filter_disable_flag == 0)
#else
if (ctx->info.pic_header.loop_filter_disable_flag == 0)
#endif
{
ret = dec_deblock_avs2(ctx);
com_assert_rv(COM_SUCCEEDED(ret), ret);
}
#if CCSAO
if (ctx->info.pic_header.pic_ccsao_on[U_C-1] || ctx->info.pic_header.pic_ccsao_on[V_C-1])
{
#if CCSAO_ENHANCEMENT
copy_frame_for_ccsao(ctx->pic_ccsao[0], ctx->pic, Y_C);
copy_frame_for_ccsao(ctx->pic_ccsao[0], ctx->pic, U_C);
copy_frame_for_ccsao(ctx->pic_ccsao[0], ctx->pic, V_C);
#else
copy_frame_for_ccsao(ctx->pic_ccsao, ctx->pic, Y_C);
#endif
}
#endif
/* sao filter */
if (ctx->info.sqh.sample_adaptive_offset_enable_flag)
{
ret = dec_sao_avs2(ctx);
com_assert_rv(ret == COM_OK, ret);
}
/* esao filter */
#if ESAO
if (ctx->info.sqh.esao_enable_flag)
{
ret = dec_esao(ctx);
com_assert_rv(ret == COM_OK, ret);
}
#endif
#if CCSAO
/* ccsao filter */
if (ctx->info.sqh.ccsao_enable_flag)
{
ret = dec_ccsao(ctx);
com_assert_rv(ret == COM_OK, ret);
}
#endif
/* ALF */
if (ctx->info.sqh.adaptive_leveling_filter_enable_flag)
{
ret = dec_alf_avs2(ctx, ctx->pic);
com_assert_rv(COM_SUCCEEDED(ret), ret);
}
/* MD5 check for testing encoder-decoder match*/
if (ctx->use_pic_sign && ctx->pic_sign_exist)
{
ret = dec_picbuf_check_signature(ctx->pic, ctx->pic_sign
#if CU_LEVEL_PRIVACY
, ctx->user_permission || !ctx->info.pic_header.ph_privacy_on
#endif
);
com_assert_rv(COM_SUCCEEDED(ret), ret);
ctx->pic_sign_exist = 0; /* reset flag */
}
#if SVAC_UD_MD5_STREAM
extension_and_user_data(ctx, bs, 1, sqh, pic_header);
if (ctx->use_pic_sign && ctx->stream_sign_exist)
{
ctx->stream_sign_check_flag = 1;
unsigned char * concat_buf = malloc((1024 * 1024 * 32));
com_assert_rv(concat_buf != NULL, -1);
unsigned int stream_size = (unsigned int)((u8 *)bitb->addr3 - (u8 *)bitb->addr3_beg);
u8 * stream_p = bitb->addr3_beg;
unsigned char * buffer_p = concat_buf;
while ((stream_p - (u8 *)bitb->addr3_beg) < stream_size)
{
unsigned int nal_size = 1;
while (!(stream_p[nal_size + 0] == 0x00 && stream_p[nal_size + 1] == 0x00 && stream_p[nal_size + 2] == 0x00 && stream_p[nal_size + 3] == 0x01) && !(stream_p[nal_size + 0] == 0x00 && stream_p[nal_size + 1] == 0x00 && stream_p[nal_size + 2] == 0x01 && stream_p[nal_size - 1] != 0))
{
if (!((stream_p - (u8 *)bitb->addr3_beg) < stream_size - nal_size - 4))
{
nal_size += 4;
break;
}
nal_size++;
}
if (stream_p[4] != (0x0c) && stream_p[3] != (0x0c) //sei
&& stream_p[4] != (0x20) && stream_p[3] != (0x20) //eocvs
&& stream_p[4] != (0x16) && stream_p[3] != (0x16) //eos
#if SVAC_SECURITY_PARAM_SET
&& stream_p[4] != (0x52) && stream_p[3] != (0x52) //sec
#endif
#if SVAC_AUTHENTICATION
&& stream_p[4] != (0x14) && stream_p[3] != (0x14) //auth
#endif
)
{
int start_code_len = 4;
if (stream_p[0] == 0x00 && stream_p[1] == 0x00 && stream_p[2] == 0x01)
{
start_code_len = 3;
}
unsigned int raw_nal_size = nal_size - start_code_len;
memcpy(buffer_p, stream_p + start_code_len, raw_nal_size);
buffer_p += raw_nal_size;
}
stream_p += nal_size;
}
int stream_total_size = (int)(buffer_p - concat_buf);
u8 stream_sign[16];
int ret = com_md5_stream(concat_buf, stream_total_size, stream_sign);
com_assert_rv(COM_SUCCEEDED(ret), ret);
if (com_mcmp(ctx->stream_sign, stream_sign, 16) != 0)
{
printf("\n stream signature check failed \n");
}
com_assert_rv(com_mcmp(ctx->stream_sign, stream_sign, 16) == 0, COM_ERR_BAD_CRC);
ctx->stream_sign_exist = 0; /* reset flag */
if (concat_buf) free(concat_buf);
}
bitb->addr3 = bitb->addr3_beg;
#endif
#if PIC_PAD_SIZE_L > 0
/* expand pixels to padding area */
dec_picbuf_expand(ctx, ctx->pic);
#endif
#if LIB_PIC_MIXBIN
}
if (is_patch_l)
{
memcpy(ctx->libpic_pic_alf_on, ctx->pic_alf_on, N_C * sizeof(int));
for (int lcu_idx = 0; lcu_idx < ctx->info.f_lcu; lcu_idx++) {
copy_sao_param_for_blk(ctx->libpic_sao_blk_params[lcu_idx], ctx->sao_blk_params[lcu_idx]);
copy_sao_param_for_blk(ctx->libpic_rec_sao_blk_params[lcu_idx], ctx->rec_sao_blk_params[lcu_idx]);
memcpy(ctx->dec_alf->libpic_alf_lcu_enabled[lcu_idx], ctx->dec_alf->alf_lcu_enabled[lcu_idx], N_C * sizeof(int));
}
for (int comp_idx = 0; comp_idx < N_C; comp_idx++)
{
memcpy(ctx->libpic_esao_lcu_flag[comp_idx], ctx->info.pic_header.pic_esao_params[comp_idx].lcu_flag, ctx->info.f_lcu * sizeof(int));
if (comp_idx)
memcpy(ctx->libpic_ccsao_lcu_flag[comp_idx - 1], ctx->info.pic_header.pic_ccsao_params[comp_idx - 1].lcu_flag, ctx->info.f_lcu * sizeof(int));
}
}
#endif
/* put decoded picture to DPB */
#if LIBVC_ON
if (sqh->library_stream_flag
#if LIB_PIC_MIXBIN
&& (!is_patch_l || (is_patch_l && (ctx->patch->idx + 1) == ctx->patch->rows * ctx->patch->columns))
#endif
)
{
ret = com_picman_put_libpic(&ctx->dpm, ctx->pic, ctx->info.pic_header.slice_type, ctx->ptr, pic_header->decode_order_index, ctx->info.pic_header.temporal_id, 1, ctx->refp, pic_header
#if HLS_OPT_PPS
, pps
#endif
);
}
else
#if LIB_PIC_MIXBIN
if (!sqh->library_stream_flag)
#endif
#endif
{
ret = com_picman_put_pic(&ctx->dpm, ctx->pic, ctx->info.pic_header.slice_type, ctx->ptr, pic_header->decode_order_index
, pic_header->picture_output_delay, ctx->info.pic_header.temporal_id, 1, ctx->refp
#if OBMC
#if CUDQP
, pic_header
#else
, pic_header->picture_qp
#endif
#if HLS_OPT_PPS
, pps
#endif
#endif
);
#if LIBVC_ON
assert((&ctx->dpm)->cur_pb_size + (&ctx->dpm)->cur_libpb_size <= sqh->max_dpb_size);
#else
assert((&ctx->dpm)->cur_pb_size <= sqh->max_dpb_size);
#endif
}
com_assert_rv(COM_SUCCEEDED(ret), ret);
}
#if SVAC_NAL
else if (bs->cur[3] == SVAC_EOS)
{
ctx->init_flag = 0;
ctx->libpic_init_flag = 0;
cnkh->ctype = COM_CT_SEQ_END;
}
else if (bs->cur[3] == SVAC_EOCVS)
{
ctx->init_flag = 0;
ctx->libpic_init_flag = 0;
cnkh->ctype = COM_CT_CVS_END;
}
#endif
#if SVAC_SECURITY_PARAM_SET
else if (bs->cur[3] == SVAC_SEC_PS)
{
dec_eco_sec_parameter_set_init(ctx, bs, pic_header, sec_para_set);
ret = dec_eco_sec_parameter_set(ctx, bs, pic_header, sec_para_set);
com_assert_rv(COM_SUCCEEDED(ret), ret);
cnkh->ctype = COM_CT_SEC_PARA_SET;
}
#endif
#if SVAC_AUTHENTICATION
else if (bs->cur[3] == SVAC_AUTH_DATA)
{
dec_eco_auth_data_init(ctx, bs, pic_header, auth_data);
ret = dec_eco_auth_data(ctx, bs, pic_header, auth_data);
com_assert_rv(COM_SUCCEEDED(ret), ret);
cnkh->ctype = COM_CT_AUTH;
}
#endif
else
{
return COM_ERR_MALFORMED_BITSTREAM;
}
make_stat(ctx, cnkh->ctype, stat);
return ret;
}
最新发布