📄 image.c
字号:
if (input->InterlaceCodingOption == FRAME_CODING
&& input->SparePictureOption && img->type != B_SLICE)
CalculateSparePicture ();
*/
//Rate control
if(input->RCEnable)
{
if((input->symbol_mode == 0)&&(input->of_mode ==0))
bits = bits_frm; //UVLC && Bitstream output mode
else
bits = stat->bit_ctr-stat->bit_ctr_n;//CABAC*/
rc_update_pict_frame(bits);
}
if (input->InterlaceCodingOption != FRAME_CODING)
{
store_field_MV (IMG_NUMBER); // assume that img->number = frame_number
}
else
store_direct_moving_flag (IMG_NUMBER);
if (input->InterlaceCodingOption >= MB_CODING && img->number != 0 && input->successive_Bframe != 0 && img->type != B_SLICE)
{
copy_mv_to_or_from_save (FROM_SAVE);
}
if (input->InterlaceCodingOption == FRAME_CODING)
{
if (input->rdopt == 2 && img->type != B_SLICE)
UpdateDecoders (); // simulate packet losses and move decoded image to reference buffers
if (input->RestrictRef)
UpdatePixelMap ();
}
find_snr ();
time (<ime2); // end time sec
#ifdef WIN32
_ftime (&tstruct2); // end time ms
#else
ftime (&tstruct2); // end time ms
#endif
tmp_time = (ltime2 * 1000 + tstruct2.millitm) - (ltime1 * 1000 + tstruct1.millitm);
tot_time = tot_time + tmp_time;
// Write reconstructed images
if (input->InterlaceCodingOption == FIELD_CODING)
{
store_picture_in_dpb(enc_bottom_picture);
enc_picture = enc_top_picture = enc_bottom_picture = NULL;
}else if (input->InterlaceCodingOption == ADAPTIVE_CODING || input->InterlaceCodingOption==MB_CODING)//sw paff
{
if (!img->fld_flag)
{
dpb.used_size--;
store_picture_in_dpb(enc_frame_picture);
}else
store_picture_in_dpb(enc_bottom_picture);
enc_picture = enc_frame_picture = NULL;
}else
{
if (img->fld_flag)
{
store_picture_in_dpb(enc_top_picture);
store_picture_in_dpb(enc_bottom_picture);
enc_picture = enc_top_picture = enc_bottom_picture = NULL;
if (enc_frame_picture)
{
free_storable_picture(enc_frame_picture);
enc_frame_picture = NULL;
}
}
else
{
store_picture_in_dpb(enc_frame_picture);
enc_picture = enc_frame_picture = NULL;
if (enc_top_picture)
{
free_storable_picture(enc_top_picture);
enc_top_picture = NULL;
}
if (enc_bottom_picture)
{
free_storable_picture(enc_bottom_picture);
enc_bottom_picture = NULL;
}
}
}
#ifdef _LEAKYBUCKET_
// Store bits used for this frame and increment counter of no. of coded frames
Bit_Buffer[total_frame_buffer] = stat->bit_ctr - stat->bit_ctr_n;
total_frame_buffer++;
#endif
// POC200301: Verify that POC coding type 2 is not used if more than one consecutive
// non-reference frame is requested or if decoding order is different from output order
if (img->pic_order_cnt_type == 2)
{
if (!img->nal_reference_idc) consecutive_non_reference_pictures++;
else consecutive_non_reference_pictures = 0;
if (frame_no < prev_frame_no || consecutive_non_reference_pictures>1)
error("POC type 2 cannot be applied for the coding pattern where the encoding /decoding order of pictures are different from the output order.\n", -1);
prev_frame_no = frame_no;
}
if (IMG_NUMBER == 0)
ReportFirstframe(tmp_time);
else
{
//Rate control
if(input->RCEnable)
{
if(!input->InterlaceCodingOption)
bits=stat->bit_ctr-stat->bit_ctr_n;
else
{
bits = stat->bit_ctr -Pprev_bits; // used for rate control update */
Pprev_bits = stat->bit_ctr;
}
}
switch (img->type)
{
case I_SLICE:
stat->bit_ctr_P += stat->bit_ctr - stat->bit_ctr_n;
ReportIntra(tmp_time);
break;
case SP_SLICE:
stat->bit_ctr_P += stat->bit_ctr - stat->bit_ctr_n;
ReportSP(tmp_time);
break;
case B_SLICE:
stat->bit_ctr_B += stat->bit_ctr - stat->bit_ctr_n;
if (img->nal_reference_idc>0)
ReportBS(tmp_time);
else
ReportB(tmp_time);
break;
default: // P, P_MULTPRED?
stat->bit_ctr_P += stat->bit_ctr - stat->bit_ctr_n;
ReportP(tmp_time);
}
}
stat->bit_ctr_n = stat->bit_ctr;
//Rate control
if(input->RCEnable)
{
rc_update_pict(bits);
/*update the parameters of quadratic R-D model*/
if((img->type==P_SLICE)&&(!input->InterlaceCodingOption))
updateRCModel();
else if((img->type==P_SLICE)&&input->InterlaceCodingOption\
&&(img->IFLAG==0))
updateRCModel();
}
FreeSourceframe (srcframe);
if (IMG_NUMBER == 0)
return 0;
else
return 1;
}
/*!
************************************************************************
* \brief
* This function write out a picture
* \return
* 0 if OK, \n
* 1 in case of error
*
************************************************************************
*/
static int writeout_picture(Picture *pic)
{
Bitstream *currStream;
int partition, slice;
Slice *currSlice;
img->currentPicture=pic;
for (slice=0; slice<pic->no_slices; slice++)
{
currSlice = pic->slices[slice];
for (partition=0; partition<currSlice->max_part_nr; partition++)
{
currStream = (currSlice->partArr[partition]).bitstream;
assert (currStream->bits_to_go = 8); //! should always be the case, the
//! byte alignment is done in terminate_slice
writeUnit (currSlice->partArr[partition].bitstream);
} // partition loop
} // slice loop
return 0;
}
/*!
************************************************************************
* \brief
* Encodes a frame picture
************************************************************************
*/
void frame_picture (Picture *frame)
{
// if more than one B pictures, they will overwrite refFrArr_top, refFrArr_bot
if (input->InterlaceCodingOption != FRAME_CODING && mb_adaptive && img->type == B_SLICE)
{
copy_mv_to_or_from_save (TO_SAVE);
}
img->structure = FRAME;
enc_frame_picture = alloc_storable_picture (img->structure, img->width, img->height, img->width_cr, img->height_cr);
enc_frame_picture->poc=img->framepoc;
enc_frame_picture->pic_num = img->frame_num;
enc_frame_picture->coded_frame = 1;
img->PicSizeInMbs = img->FrameSizeInMbs;
enc_frame_picture->mb_adaptive_frame_field_flag = img->MbaffFrameFlag = (input->InterlaceCodingOption == MB_CODING);
enc_picture=enc_frame_picture;
//sw PAFF
if(input->InterlaceCodingOption==MB_CODING)
{
enc_top_picture = alloc_storable_picture (img->structure, img->width, img->height, img->width_cr, img->height_cr);
enc_top_picture->poc=img->toppoc;
enc_top_picture->pic_num = img->frame_num;
enc_top_picture->coded_frame = 1;
enc_top_picture->mb_adaptive_frame_field_flag = img->MbaffFrameFlag = (input->InterlaceCodingOption == MB_CODING);
enc_bottom_picture = alloc_storable_picture (img->structure, img->width, img->height, img->width_cr, img->height_cr);
enc_bottom_picture->poc=img->bottompoc;
enc_bottom_picture->pic_num = img->frame_num;
enc_bottom_picture->coded_frame = 1;
enc_bottom_picture->mb_adaptive_frame_field_flag = img->MbaffFrameFlag = (input->InterlaceCodingOption == MB_CODING);
}
stat->em_prev_bits_frm = 0;
stat->em_prev_bits = &stat->em_prev_bits_frm;
if (img->MbaffFrameFlag)
{
CopyTopFieldToOldImgOrgVariables (srcframe);
CopyBottomFieldToOldImgOrgVariables (srcframe);
}
if (img->type != I_SLICE && (input->WeightedPrediction == 1 || (input->WeightedBiprediction > 0 && (img->type == B_SLICE))))
{
estimate_weighting_factor ();
}
img->fld_flag = 0;
code_a_picture(frame);
if (input->InterlaceCodingOption >= MB_CODING && mb_adaptive && img->number != 0 && input->successive_Bframe != 0 && img->type != B_SLICE)
{
copy_mv_to_or_from_save (TO_SAVE);
}
frame->bits_per_picture = 8 * ((((img->currentSlice)->partArr[0]).bitstream)->byte_pos);
if (input->InterlaceCodingOption != FRAME_CODING)
{
find_distortion (snr, img);
frame->distortion_y = snr->snr_y;
frame->distortion_u = snr->snr_u;
frame->distortion_v = snr->snr_v;
}
}
/*!
************************************************************************
* \brief
* Encodes a field picture, consisting of top and bottom field
************************************************************************
*/
void field_picture (Picture *top, Picture *bottom)
{
//Rate control
int old_pic_type; // picture type of top field used for rate control
int TopFieldBits;
//Rate control
old_pic_type = img->type;
stat->em_prev_bits_fld = 0;
stat->em_prev_bits = &stat->em_prev_bits_fld;
img->number *= 2;
img->buf_cycle *= 2;
input->num_reference_frames = input->num_reference_frames;
img->height = input->img_height / 2;
img->height_cr = input->img_height / 4;
img->fld_flag = 1;
img->PicSizeInMbs = img->FrameSizeInMbs/2;
// Top field
// img->bottom_field_flag = 0;
enc_top_picture = alloc_storable_picture (img->structure, img->width, img->height, img->width_cr, img->height_cr);
enc_top_picture->poc=img->toppoc;
enc_top_picture->pic_num = img->frame_num;
enc_top_picture->coded_frame = 1;
enc_top_picture->mb_adaptive_frame_field_flag = img->MbaffFrameFlag = (input->InterlaceCodingOption == MB_CODING);
img->ThisPOC = img->toppoc;
enc_picture = enc_top_picture;
put_buffer_top ();
init_field ();
if (img->type == B_SLICE) //all I- and P-frames
nextP_tr_fld--;
CopyTopFieldToOldImgOrgVariables (srcframe);
if (img->type != I_SLICE && (input->WeightedPrediction == 1 || (input->WeightedBiprediction > 0 && (img->type == B_SLICE)))) if (img->type == B_SLICE)
{
estimate_weighting_factor ();
}
img->fld_flag = 1;
// img->bottom_field_flag = 0;
//Rate control
if(input->RCEnable)
{
img->BasicUnit=input->basicunit;
if(input->InterlaceCodingOption==2)
rc_init_pict(0,1,1);
else
rc_init_pict(0,1,0);
img->qp = updateQuantizationParameter(1);
}
img->TopFieldFlag=1;
code_a_picture(top_pic);
enc_picture->structure = 1;
//interpolate_frame_to_fb ();
store_picture_in_dpb(enc_top_picture);
top->bits_per_picture = 8 * ((((img->currentSlice)->partArr[0]).bitstream)->byte_pos);
//Rate control
TopFieldBits=top->bits_per_picture;
// Bottom field
// img->bottom_field_flag = 0;
enc_bottom_picture = alloc_storable_picture (img->structure, img->width, img->height, img->width_cr, img->height_cr);
enc_bottom_picture->poc=img->bottompoc;
enc_bottom_picture->pic_num = img->frame_num;
enc_bottom_picture->coded_frame = 1;
enc_bottom_picture->mb_adaptive_frame_field_flag = img->MbaffFrameFlag = (input->InterlaceCodingOption == MB_CODING);
img->ThisPOC = img->bottompoc;
enc_picture = enc_bottom_picture;
put_buffer_bot ();
img->number++;
init_field ();
if (img->type == B_SLICE) //all I- and P-frames
nextP_tr_fld++; //check once coding B field
if (img->type == I_SLICE)
img->type = P_SLICE;
CopyBottomFieldToOldImgOrgVariables (srcframe);
if (img->type != I_SLICE && (input->WeightedPrediction == 1 || (input->WeightedBiprediction > 0 && (img->type == B_SLICE))))
{
estimate_weighting_factor ();
}
img->fld_flag = 1;
// img->bottom_field_flag = 1;
//Rate control
if(input->RCEnable) setbitscount(TopFieldBits);
if(input->RCEnable)
{
rc_init_pict(0,0,0);
img->qp = updateQuantizationParameter(0);
}
img->TopFieldFlag=0;
enc_picture->structure = 2;
code_a_picture(bottom_pic);
bottom->bits_per_picture = 8 * ((((img->currentSlice)->partArr[0]).bitstream)->byte_pos);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -