AVS3中的patch(片)

本文详细介绍了AVS3标准中替代slice的patch结构,包括其定义、语法特性以及在序列头中的表示。patch是图像的矩形区域,其尺寸和位置有特定规则。在解码过程中,patch的起始码、位置计算和边界处理被详细阐述。此外,还讨论了patch对相邻块预测的影响,强调了帧内预测和块复制的限制条件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  对比AVS3和AVS2标准,我们发现AVS2中的slice语法结构在AVS3中被替换为patch(片)。

片的定义

  片是图像中的矩形区域,包含若干最大编码单元在图像内的部分,片之间不应重叠。片结构见图1。

图1、AVS3中的片结构示意图

片在AVS3中的使用

一、序列头中关于patch的语法

    ... ... 

    cross_patch_loop_filter_enable_flag

u(1)

    ref_colocated_patch_flag

u(1)

    stable_patch_flag

u(1)

    if (stable_patch_flag == '1') {

 

        uniform_patch_flag

u(1)

        if (uniform_patch_flag == '1') {

 

            marker_bit

f(1)

            patch_width_minus1

ue(v)

            patch_height_minus1

ue(v)

        }

 

    }

 

cross_patch_loop_filter_enable_flag  跨片环路滤波允许标志 

  二值变量。值为‘1’时表示可跨越片边界进行Deblock、SAO及ALF;值为‘0’表示不应跨越片边界进行Deblock、SAO及ALF。

ref_colocated_patch_flag  参考同位置片标志 

  二值变量。值为‘1’时表示进行帧间预测时只使用参考图像同位置片边界内的采样值进行参考;值为‘0’表示进行帧间预测时可使用参考图像同位置片边界外的采样值进行参考。

stable_patch_flag  片划分一致性标志 

  二值变量。值为‘1’时表示当前视频序列中所有图像划分为片的方式均应相同;值为‘0’表示当前视频序列中图像划分为片的方式可不相同。事实上,在目前AVS3标准中的所有profile内,都要求stable_patch_flag等于1

uniform_patch_flag 统一片大小标志 

  二值变量。值为‘1’时表示除最右边和最下边的片外,图像中其他片的大小应相同;值为‘0’表示片的大小可不同。事实上,在目前AVS3标准中的所有profile内,都要求uniform_patch_flag等于1

patch_width_minus1  片宽度 

patch_height_minus1  片高度 

  片的宽度和高度,以LCU为单位。patch_width_minus1的值应小于256,patch_height_minus1的值应小于144。

 

二、如何计算以LCU为单位的每个片的宽、高以及位置等信息

  序列头中已经定义了patch_width_minus1和patch_height_minus1,利用这两个参数可以计算出每个patch的位置,只是需要注意图像右边界和下边界的处理方式存在差异。

  没遇到边界,patch是均匀划分的。

  1、如果图像宽度不是整数个patch width的宽度,则右边存在多余的LCU,将多余LCU合并到最右边的patch中。可以计算出图像中包含了NumPatchColumns 列的Patch。

  2、如果图像高度不是整数个patch height的高度,则下边存在多余的LCU,在图像下边新增一行patch。所以图像中实际的patch的行数NumPatchColumns,可能等于patch_height_minus1 + 2。

  3、将每个Patch的(x, y, w, h)信息存入PatchSizeInLCU[i][j]数组中。(x, y)为以LCU为单位的Patch起始点坐标, w、h为Patch以LCU为单位的宽高大小。

  Patch位置计算过程如下动画所示:

三、Patch的解码过程

  1、首先从Intra Picture或者Inter Picture数据找到片起始码(4 Byte),为00 00 01 00 ~ 00 00 01 7F,其中最后1Byte为patch_idx。

  2、根据Patch_idx,计算Patch首LCU的位置:

       PatchIndexX = Patch_index % NumPatchColumns

       PatchIndexY = Patch_index / NumPatchColumns

       LcuRow = PatchSizeInLCU[PatchIndexY][PatchIndexX]->PosY

       LcuColumn = PatchSizeInLCU[PatchIndexY][PatchIndexX]->PosX

  3、计算Patch首个LCU的LcuIdx

       LcuIdx = LcuRow * PictureWidthInLcu + LcuColumn

  4、计算Patch边界:

       PatchLeftInLcu     = LcuIdx % PictureWidthInLcu  (Patch内部,LcuIdx满足此公式,则该Lcu在Patch的左边界)

       PatchRightInLcu   = PatchLeftInLcu + PatchSizeInLCU[PatchIndexY][PatchIndexX]->Width    

       PatchAboveInLcu = LcuIdx / PictureWidthInLcu

       PatchBelowInLcu = PatchAboveInLcu + PatchSizeInLCU[PatchIndexY][PatchIndexX]->Height

四、片对获取相邻块的影响

图2、块E和相邻块的空间位置关系

 

  相邻块X(X为A、B、C、D、F或G)“存在”指该块应在图像内并且该块应与块E属于同一片;否则相邻块“不存在”。

  如果块“不存在”或者尚未解码,则此块“不可用”;否则此块“可用”。如果图像样本所在的块“不存在”或者此样本尚未解码,则此样本“不可用”;否则此样本“可用”。

  1、根据AVS3标准中的定义,帧内预测不能使用相邻片的相邻像素做参考

  2、块复制帧内预测的限制:从符合本部分的位流中解码得到的块矢量指向的参考块应限制在当前最大编码单元或左边N个最大编码单元的范围内。参考块的所有参考样本均应与当前块的样本属于同一个片,且已完全重建。

 

 

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; }
最新发布
07-16
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ITRonnie

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值