📄 slice.c
字号:
{
if (listX[0][i]->poc < img->last_valid_reference && img->ThisPOC > img->last_valid_reference)
{
listXsize[0] = img->num_ref_idx_l0_active = imax(1,i);
break;
}
}
for (i = 0; i<listXsize[1]; i++)
{
if (listX[1][i]->poc < img->last_valid_reference && img->ThisPOC > img->last_valid_reference)
{
listXsize[1] = img->num_ref_idx_l1_active = imax(1,i);
break;
}
}
}
init_ref_pic_list_reordering();
//Perform reordering based on poc distances for HierarchicalCoding
//if (img->type==P_SLICE && input->HierarchicalCoding && input->ReferenceReorder)
if (img->type==P_SLICE && input->ReferenceReorder)
{
int i, num_ref;
alloc_ref_pic_list_reordering_buffer(currSlice);
if ((img->type != I_SLICE) && (img->type !=SI_SLICE))
{
for (i=0; i<img->num_ref_idx_l0_active + 1; i++)
{
currSlice->reordering_of_pic_nums_idc_l0[i] = 3;
currSlice->abs_diff_pic_num_minus1_l0[i] = 0;
currSlice->long_term_pic_idx_l0[i] = 0;
}
if (img->type == B_SLICE)
{
for (i=0; i<img->num_ref_idx_l1_active + 1; i++)
{
currSlice->reordering_of_pic_nums_idc_l1[i] = 3;
currSlice->abs_diff_pic_num_minus1_l1[i] = 0;
currSlice->long_term_pic_idx_l1[i] = 0;
}
}
}
if ((img->type != I_SLICE) && (img->type !=SI_SLICE))
{
num_ref = img->num_ref_idx_l0_active;
poc_ref_pic_reorder(listX[LIST_0],
num_ref,
currSlice->reordering_of_pic_nums_idc_l0,
currSlice->abs_diff_pic_num_minus1_l0,
currSlice->long_term_pic_idx_l0, LIST_0);
//reference picture reordering
reorder_ref_pic_list(listX[LIST_0], &listXsize[LIST_0],
img->num_ref_idx_l0_active - 1,
currSlice->reordering_of_pic_nums_idc_l0,
currSlice->abs_diff_pic_num_minus1_l0,
currSlice->long_term_pic_idx_l0);
// This is not necessary since order is already poc based...
if (img->type == B_SLICE)
{
num_ref = img->num_ref_idx_l1_active;
poc_ref_pic_reorder(listX[LIST_1],
num_ref,
currSlice->reordering_of_pic_nums_idc_l1,
currSlice->abs_diff_pic_num_minus1_l1,
currSlice->long_term_pic_idx_l1, LIST_1);
//reference picture reordering
reorder_ref_pic_list(listX[LIST_1], &listXsize[LIST_1],
img->num_ref_idx_l1_active - 1,
currSlice->reordering_of_pic_nums_idc_l1,
currSlice->abs_diff_pic_num_minus1_l1,
currSlice->long_term_pic_idx_l1);
}
}
}
//if (img->MbaffFrameFlag)
if (img->structure==FRAME)
init_mbaff_lists();
if (img->type != I_SLICE && (active_pps->weighted_pred_flag == 1 || (active_pps->weighted_bipred_idc > 0 && (img->type == B_SLICE))))
{
if (img->type==P_SLICE || img->type==SP_SLICE)
{
if (input->GenerateMultiplePPS && input->RDPictureDecision)
{
if (enc_picture == enc_frame_picture[1])
estimate_weighting_factor_P_slice (0);
else
estimate_weighting_factor_P_slice (1);
}
else
estimate_weighting_factor_P_slice (0);
}
else
estimate_weighting_factor_B_slice ();
}
set_ref_pic_num();
if (img->type == B_SLICE)
{
if( IS_INDEPENDENT(input) )
{
compute_colocated_JV(Co_located, listX);
}
else
{
compute_colocated(Co_located, listX);
}
}
if (img->type != I_SLICE && input->SearchMode == EPZS)
EPZSSliceInit(EPZSCo_located, listX);
if (input->symbol_mode == UVLC)
{
writeMB_typeInfo = writeSE_UVLC;
writeIntraPredMode = writeIntraPredMode_CAVLC;
writeB8_typeInfo = writeSE_UVLC;
for (i=0; i<6; i++)
{
switch (listXsize[i])
{
case 0:
writeRefFrame[i] = NULL;
break;
case 1:
writeRefFrame[i] = writeSE_Dummy;
break;
case 2:
writeRefFrame[i] = writeSE_invFlag;
break;
default:
writeRefFrame[i] = writeSE_UVLC;
break;
}
}
writeMVD = writeSE_SVLC;
writeCBP = writeCBP_VLC;
writeDquant = writeSE_SVLC;
writeCIPredMode = writeSE_UVLC;
writeFieldModeInfo = writeSE_Flag;
writeMB_transform_size = writeSE_Flag;
}
else
{
writeMB_typeInfo = writeMB_typeInfo_CABAC;
writeIntraPredMode = writeIntraPredMode_CABAC;
writeB8_typeInfo = writeB8_typeInfo_CABAC;
for (i=0; i<6; i++)
{
switch (listXsize[i])
{
case 0:
writeRefFrame[i] = NULL;
case 1:
writeRefFrame[i] = writeSE_Dummy;
break;
default:
writeRefFrame[i] = writeRefFrame_CABAC;
}
}
writeMVD = writeMVD_CABAC;
writeCBP = writeCBP_CABAC;
writeDquant = writeDquant_CABAC;
writeCIPredMode = writeCIPredMode_CABAC;
writeFieldModeInfo = writeFieldModeInfo_CABAC;
writeMB_transform_size = writeMB_transform_size_CABAC;
}
// assign luma common reference picture pointers to be used for ME/sub-pel interpolation
if( IS_INDEPENDENT(input) )
{
for(i=0; i<6; i++)
for(j=0; j<listXsize[i]; j++)
{
if( listX[i][j] )
listX[i][j]->curr_imgY_sub = listX[i][j]->p_imgY_sub[img->colour_plane_id];
}
}
else
{
for(i=0; i<6; i++)
for(j=0; j<listXsize[i]; j++)
{
if( listX[i][j] )
listX[i][j]->curr_imgY_sub = listX[i][j]->imgY_sub;
}
}
}
/*!
************************************************************************
* \brief
* Allocates a slice structure along with its dependent data structures
* \return
* Pointer to a Slice
************************************************************************
*/
static Slice *malloc_slice()
{
int i;
DataPartition *dataPart;
Slice *slice;
int cr_size = IS_INDEPENDENT( input ) ? 0 : 512;
// const int buffer_size = (img->size * 4); // AH 190202: There can be data expansion with
// low QP values. So, we make sure that buffer
// does not overflow. 4 is probably safe multiplier.
int buffer_size;
switch (input->slice_mode)
{
case 2:
//buffer_size = imax(2 * input->slice_argument, 500 + (128 + 256 * img->bitdepth_luma + 512 * img->bitdepth_chroma));
buffer_size = imax(2 * input->slice_argument, 764);
break;
case 1:
buffer_size = 500 + input->slice_argument * (128 + 256 * img->bitdepth_luma + cr_size * img->bitdepth_chroma);
break;
default:
buffer_size = 500 + img->FrameSizeInMbs * (128 + 256 * img->bitdepth_luma + cr_size * img->bitdepth_chroma);
break;
}
// KS: this is approx. max. allowed code picture size
if ((slice = (Slice *) calloc(1, sizeof(Slice))) == NULL) no_mem_exit ("malloc_slice: slice structure");
if (input->symbol_mode == CABAC)
{
// create all context models
slice->mot_ctx = create_contexts_MotionInfo();
slice->tex_ctx = create_contexts_TextureInfo();
}
slice->max_part_nr = input->partition_mode==0?1:3;
//for IDR img there should be only one partition
if(img->currentPicture->idr_flag)
slice->max_part_nr = 1;
assignSE2partition[0] = assignSE2partition_NoDP;
//ZL
//for IDR img all the syntax element should be mapped to one partition
if(!img->currentPicture->idr_flag&&input->partition_mode==1)
assignSE2partition[1] = assignSE2partition_DP;
else
assignSE2partition[1] = assignSE2partition_NoDP;
slice->num_mb = 0; // no coded MBs so far
if ((slice->partArr = (DataPartition *) calloc(slice->max_part_nr, sizeof(DataPartition))) == NULL) no_mem_exit ("malloc_slice: partArr");
for (i=0; i<slice->max_part_nr; i++) // loop over all data partitions
{
dataPart = &(slice->partArr[i]);
if ((dataPart->bitstream = (Bitstream *) calloc(1, sizeof(Bitstream))) == NULL) no_mem_exit ("malloc_slice: Bitstream");
if ((dataPart->bitstream->streamBuffer = (byte *) calloc(buffer_size, sizeof(byte))) == NULL) no_mem_exit ("malloc_slice: StreamBuffer");
// Initialize storage of bitstream parameters
}
return slice;
}
/*!
************************************************************************
* \brief
* Memory frees of all Slice structures and of its dependent
* data structures
* \par Input:
* Image Parameters struct struct img_par *img
************************************************************************
*/
void free_slice_list(Picture *currPic)
{
int i;
for (i=0; i<currPic->no_slices; i++)
{
free_slice (currPic->slices[i]);
currPic->slices[i]=NULL;
}
}
/*!
************************************************************************
* \brief
* Memory frees of the Slice structure and of its dependent
* data structures
* \param slice:
* Slice to be freed
************************************************************************
*/
static void free_slice(Slice *slice)
{
int i;
DataPartition *dataPart;
if (slice != NULL)
{
for (i=0; i<slice->max_part_nr; i++) // loop over all data partitions
{
dataPart = &(slice->partArr[i]);
if (dataPart != NULL)
{
if (dataPart->bitstream != NULL)
{
if (dataPart->bitstream->streamBuffer != NULL)
free(dataPart->bitstream->streamBuffer);
free(dataPart->bitstream);
}
}
}
if (slice->partArr != NULL)
free(slice->partArr);
if (input->symbol_mode == CABAC)
{
delete_contexts_MotionInfo(slice->mot_ctx);
delete_contexts_TextureInfo(slice->tex_ctx);
}
free(slice);
}
}
void set_ref_pic_num()
{
int i,j;
StorablePicture *this_ref;
//! need to add field ref_pic_num that handles field pair.
for (i=0;i<listXsize[LIST_0];i++)
{
this_ref = listX[LIST_0][i];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -