📄 image.c
字号:
#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->disposable_flag) 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
{
switch (img->type)
{
case INTRA_IMG:
stat->bit_ctr_P += stat->bit_ctr - stat->bit_ctr_n;
ReportIntra(tmp_time);
break;
case SP_IMG:
stat->bit_ctr_P += stat->bit_ctr - stat->bit_ctr_n;
ReportSP(tmp_time);
break;
case BS_IMG:
stat->bit_ctr_P += stat->bit_ctr - stat->bit_ctr_n;
ReportBS(tmp_time);
break;
case B_IMG:
stat->bit_ctr_B += stat->bit_ctr - stat->bit_ctr_n;
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;
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;
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
************************************************************************
*/
static void frame_picture (Picture *frame)
{
// int i;
// if more than one B pictures, they will overwrite refFrArr_top, refFrArr_bot
if (input->InterlaceCodingOption != FRAME_CODING && mb_adaptive && img->type == B_IMG)
{
copy_mv_to_or_from_save (TO_SAVE);
}
stat->em_prev_bits_frm = 0;
stat->em_prev_bits = &stat->em_prev_bits_frm;
// Initialize frame with all stat and img variables
// img->total_number_mb =
// (img->width * img->height) / (MB_BLOCK_SIZE * MB_BLOCK_SIZE);
// init_frame ();
init_mref ();
init_Refbuf (img);
copy_mref (img);
CopyFrameToOldImgOrgVariables (srcframe);
if (input->InterlaceCodingOption >= MB_CODING && mb_adaptive)
{
CopyTopFieldToOldImgOrgVariables (srcframe);
CopyBottomFieldToOldImgOrgVariables (srcframe);
}
if (img->type != INTRA_IMG && (input->WeightedPrediction == 1 || (input->WeightedBiprediction > 0 && (img->type == B_IMG || img->type == BS_IMG))))
{
estimate_weighting_factor ();
}
// if (img->type == B_IMG)
// Bframe_ctr++;
// for (i = 0; i < img->currentSlice->max_part_nr; i++)
// ((img->currentSlice)->partArr[i]).bitstream = ((img->currentSlice)->partArr[i]).bitstream_frm; //temp
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_IMG)
{
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
************************************************************************
*/
static void field_picture (Picture *top, Picture *bottom)
{
stat->em_prev_bits_fld = 0;
stat->em_prev_bits = &stat->em_prev_bits_fld;
img->number *= 2;
img->buf_cycle *= 2;
input->no_multpred = 2 * input->no_multpred + 1;
img->height = input->img_height / 2;
img->height_cr = input->img_height / 4;
img->fld_flag = 1;
// Top field
// img->bottom_field_flag = 0;
put_buffer_top ();
init_field ();
if (img->type == B_IMG) //all I- and P-frames
nextP_tr_fld--;
CopyTopFieldToOldImgOrgVariables (srcframe);
if (img->type != INTRA_IMG && (input->WeightedPrediction == 1 || (input->WeightedBiprediction > 0 && (img->type == B_IMG || img->type == BS_IMG))))
{
estimate_weighting_factor ();
}
img->fld_flag = 1;
// img->bottom_field_flag = 0;
code_a_picture(top_pic);
if (img->type != B_IMG) //all I- and P-frames
interpolate_frame_to_fb ();
top->bits_per_picture = 8 * ((((img->currentSlice)->partArr[0]).bitstream)->byte_pos);
// Bottom field
// img->bottom_field_flag = 0;
put_buffer_bot ();
img->number++;
init_field ();
if (img->type == B_IMG) //all I- and P-frames
nextP_tr_fld++; //check once coding B field
if (img->type == INTRA_IMG)
img->type = INTER_IMG;
CopyBottomFieldToOldImgOrgVariables (srcframe);
if (img->type != INTRA_IMG && (input->WeightedPrediction == 1 || (input->WeightedBiprediction > 0 && (img->type == B_IMG || img->type == BS_IMG))))
{
estimate_weighting_factor ();
}
img->fld_flag = 1;
// img->bottom_field_flag = 1;
code_a_picture(bottom_pic);
if (img->type != B_IMG) //all I- and P-frames
interpolate_frame_to_fb ();
bottom->bits_per_picture = 8 * ((((img->currentSlice)->partArr[0]).bitstream)->byte_pos);
// the distortion for a field coded frame (consisting of top and bottom field)
// lives in the top->distortion varaibles, thye bottom-> are dummies
distortion_fld (&top->distortion_y, &top->distortion_u, &top->distortion_v);
}
/*!
************************************************************************
* \brief
* Distortion Field
************************************************************************
*/
static void distortion_fld (float *dis_fld_y, float *dis_fld_u, float *dis_fld_v)
{
img->number /= 2;
img->buf_cycle /= 2;
img->height = input->img_height;
img->height_cr = input->img_height / 2;
img->total_number_mb =
(img->width * img->height) / (MB_BLOCK_SIZE * MB_BLOCK_SIZE);
input->no_multpred = (input->no_multpred - 1) / 2;
combine_field ();
imgY = imgY_com;
imgUV = imgUV_com;
imgY_org = imgY_org_frm;
imgUV_org = imgUV_org_frm;
find_distortion (snr, img); // find snr from original frame picture
*dis_fld_y = snr->snr_y;
*dis_fld_u = snr->snr_u;
*dis_fld_v = snr->snr_v;
}
/*!
************************************************************************
* \brief
* Picture Structure Decision
************************************************************************
*/
static int picture_structure_decision (Picture *frame, Picture *top, Picture *bot)
{
double lambda_picture;
int spframe = (img->type == INTER_IMG && img->types == SP_IMG);
int bframe = (img->type == B_IMG);
float snr_frame, snr_field;
int bit_frame, bit_field;
lambda_picture = 0.85 * pow (2, (img->qp - SHIFT_QP) / 3.0) * (bframe
|| spframe ?
4 : 1);
snr_frame = frame->distortion_y + frame->distortion_u + frame->distortion_v;
//! all distrortions of a field picture are accumulated in the top field
snr_field = top->distortion_y + top->distortion_u + top->distortion_v;
bit_field = top->bits_per_picture + bot->bits_per_picture;
bit_frame = frame->bits_per_picture;
return decide_fld_frame (snr_frame, snr_field, bit_field, bit_frame, lambda_picture);
}
/*!
************************************************************************
* \brief
* Field Mode Buffer
************************************************************************
*/
static void field_mode_buffer (int bit_field, float snr_field_y, float snr_field_u, float snr_field_v)
{
put_buffer_frame ();
imgY = imgY_com;
imgUV = imgUV_com;
if (img->type != B_IMG) //all I- and P-frames
interpolate_frame_to_fb ();
input->no_fields += 1;
snr->snr_y = snr_field_y;
snr->snr_u = snr_field_u;
snr->snr_v = snr_field_v;
}
/*!
************************************************************************
* \brief
* Frame Mode Buffer
************************************************************************
*/
static void frame_mode_buffer (int bit_frame, float snr_frame_y, float snr_frame_u, float snr_frame_v)
{
put_buffer_frame ();
if (img->type != B_IMG) //all I- and P-frames
interpolate_frame_to_fb ();
if (input->InterlaceCodingOption != FRAME_CODING)
{
img->height = img->height / 2;
img->height_cr = img->height_cr / 2;
img->number *= 2;
img->buf_cycle *= 2;
put_buffer_top ();
split_field_top ();
if (img->type != B_IMG) //all I- and P-frames
{
rotate_buffer ();
interpolate_frame ();
}
img->number++;
put_buffer_bot ();
split_field_bot ();
if (img->type != B_IMG) //all I- and P-frames
{
rotate_buffer ();
interpolate_frame ();
}
img->number /= 2; // reset the img->number to field
img->buf_cycle /= 2;
img->height = input->img_height;
img->height_cr = input->img_height / 2;
img->total_number_mb =
(img->width * img->height) / (MB_BLOCK_SIZE * MB_BLOCK_SIZE);
snr->snr_y = snr_frame_y;
snr->snr_u = snr_frame_u;
snr->snr_v = snr_frame_v;
put_buffer_frame ();
}
}
/*!
************************************************************************
* \brief
* mmco initializations should go here
************************************************************************
*/
static void init_mmco()
{
img->mmco_buffer=NULL;
}
/*!
************************************************************************
* \brief
* Initializes the parameters for a new frame
************************************************************************
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -