📄 decode.c
字号:
fprintf(p_log, "%3d %2d %2d %2.2f %2.2f %2.2f %5d "
"%2.2f %2.2f %2.2f %5d "
"%2.2f %2.2f %2.2f %5d %.3f\n",
pgImage->number, 0, pgImage->qp,
snr->snr_y1,
snr->snr_u1,
snr->snr_v1,
0,
0.0,
0.0,
0.0,
0,
snr->snr_ya,
snr->snr_ua,
snr->snr_va,
0,
(double)0.001*tot_time/pgImage->number);
fclose(p_log);
}
/*!
*************************************************************************************
* \brief : Allocates a Bitstream
*************************************************************************************
*/
Bitstream *AllocBitstream()
{
Bitstream *bitstream;
bitstream = (Bitstream *) calloc(1, sizeof(Bitstream));
if (bitstream == NULL)
{
snprintf(errortext, ET_SIZE, "AllocBitstream: Memory allocation for Bitstream failed");
error(errortext, 100);
}
bitstream->streamBuffer = (byte *) calloc(MAX_CODED_FRAME_SIZE, sizeof(byte));
if (bitstream->streamBuffer == NULL)
{
snprintf(errortext, ET_SIZE, "AllocBitstream: Memory allocation for streamBuffer failed");
error(errortext, 100);
}
return bitstream;
}
/*!
*************************************************************************************
* \brief : Frees a partition structure (array).
*************************************************************************************
*/
void FreeBitstream ()
{
assert (currStream!= NULL);
assert (currStream->streamBuffer != NULL);
free (currStream->streamBuffer);
free (currStream);
}
/*!
*************************************************************************************
* \brief :
* Dynamic memory allocation of frame size related global buffers
* buffers are defined in global.h, allocated memory must be freed in
* void free_global_buffers()
*************************************************************************************
*/
int init_global_buffers()
{
int i;
int refnum;
int memory_size=0;
// allocate memory for reference frames of each block: refFrArr
memory_size += get_mem2Dint(&refFrArr, vertical_size/BLOCK_SIZE, pgImage->width/BLOCK_SIZE); //zhangnan
// allocate memory for reference frame in find_snr
memory_size += get_mem2D(&imgY_ref, vertical_size, pgImage->width);
memory_size += get_mem3D(&imgUV_ref, 2, vertical_size/2, pgImage->width_cr);
// allocate memory in structure pgImage
if(((mb_data) = (Macroblock *) calloc((pgImage->width/MB_BLOCK_SIZE) * (vertical_size/MB_BLOCK_SIZE),sizeof(Macroblock))) == NULL)
no_mem_exit("init_global_buffers: mb_data");
memory_size += get_mem3Dint(&(pgImage->mv),pgImage->width/BLOCK_SIZE +4, vertical_size/BLOCK_SIZE,3); //zhangnan
memory_size += get_mem2Dint(&(pgImage->ipredmode),pgImage->width/BLOCK_SIZE +2 , vertical_size/BLOCK_SIZE +2); //qwang 2004-3-9
// allocate frame buffer
for(refnum=0; refnum<3; refnum++)
for (i=0; i<3; i++)
{
if (i==0)
get_mem2D(&reference_frame[refnum][i],vertical_size,pgImage->width);
else
get_mem2D(&reference_frame[refnum][i],vertical_size/2,pgImage->width_cr);
}
//forward reference frame buffer
current_frame = reference_frame[2];
//cbzhu 0412
#ifdef _ISOLATED_REGION_
if(iREGenable)
memory_size+=get_mem2Dint(&iREGmap,pgImage->height/MB_BLOCK_SIZE,pgImage->width/MB_BLOCK_SIZE);
#endif //_ISOLATED_REGION_
return (memory_size);
}
/*!
*************************************************************************************
* \brief :
* Free allocated memory of frame size related global buffers
* buffers are defined in global.h, allocated memory is allocated in
* int init_global_buffers()
*************************************************************************************
*/
void free_global_buffers()
{
int i,j;
free_mem2D (imgY_ref);
free_mem3D (imgUV_ref,2);
// free mem, allocated for structure pgImage
if (mb_data != NULL) free(mb_data);
free_mem3Dint (pgImage->mv,pgImage->width/B8_SIZE + 4);
free_mem2Dint (pgImage->ipredmode);
for (i=0; i<3; i++)
for(j=0;j<3; j++)
free_mem2D(reference_frame[i][j]);
}
/*!
*************************************************************************************
* \brief :
* update the decoder picture buffer
*************************************************************************************
*/
void Update_Picture_Buffers()
{
unsigned char **tmp;
int i;
if (pgImage->idr_flag == 1) /* accurate? */
pgImage->is_ref0_an_IDR = 1;
else
pgImage->is_ref0_an_IDR = 0; /* check current picture is IDR frame or not */
//fprintf(stdout,"%d\n",pgImage->is_ref0_an_IDR);
/* update picture bufffer for next frame decoding */
if (!pgImage->pic_ref_flag) /* pic_ref_flag = 0 --> to be used as reference frame */
{
if (pgImage->active_num_ref_frames == sps->num_ref_frames)
{
if(pgImage->ssw == 2)
{
for(i=0; i<3; i++)
{
tmp = reference_frame[1][i];
reference_frame[1][i] = reference_frame[0][i];
reference_frame[0][i] = current_frame[i];
current_frame[i] = tmp;
}
}
else if (pgImage->ssw == 1)
{
for(i=0; i<3; i++)
{
tmp = reference_frame[0][i];
reference_frame[0][i] = current_frame[i];
current_frame[i] = tmp;
}
}
}
else
{
for(i=0; i<3; i++)
{
tmp = reference_frame[1][i];
reference_frame[1][i] = reference_frame[0][i];
reference_frame[0][i] = current_frame[i];
current_frame[i] = tmp;
}
}
}
if(pgImage->idr_flag == 1)
{
pgImage->active_num_ref_frames = 1;
}
else if(!pgImage->pic_ref_flag)
{
pgImage->active_num_ref_frames++ ;
pgImage->active_num_ref_frames = min(pgImage->active_num_ref_frames , sps->num_ref_frames);
}
}
/*!
*************************************************************************************
* \brief :
* Initialize decoder
*************************************************************************************
*/
void init_decoder(char *config_file)
{
int i;
seq_parameter_set *sps_t[16];
pic_parameter_set *pps_t[128];
// allocate memory for the structures
if ((input = (struct inp_par *)calloc(1, sizeof(struct inp_par)))==NULL) no_mem_exit("main: input");
if ((snr = (struct snr_par *)calloc(1, sizeof(struct snr_par)))==NULL) no_mem_exit("main: snr");
if ((pgImage = (struct img_par *)calloc(1, sizeof(struct img_par)))==NULL) no_mem_exit("main: pgImage");
if ((stat_parameter = (StatParameter *)calloc(1, sizeof(StatParameter)))==NULL) no_mem_exit("main: bistream conformance stat");
//read config file
//mapping the configurable parameter to decoding structure.
read_configfile(config_file);
OpenAnnexbFile("c:\\avs-m\\test.avs");
//allocate stream buffer
currStream = AllocBitstream();
for(i=0;i<16;i++)
{
sps_t[i] = AllocSPS();
sps_buf[i] = sps_t[i];
}
for(i=0;i<128;i++)
{
pps_t[i] = AllocPPS();
pps_buf[i] = pps_t[i];
}
// initilize quad matrix used in snr routine
for (i=0; i < 256; i++)
{
pgImage->quad[i]=i*i;
}
//initialize image number
pgImage->number=0;
// Global time for total decoding session
tot_time = 0;
}
/*!
*************************************************************************************
* \brief :
* release decoder
*************************************************************************************
*/
void release_decoder()
{
FreePPS(pps);
FreeSPS(sps);
report_seq(snr);
FreeBitstream();
free_global_buffers();
CloseAnnexbFile();
//fclose (bits);
fclose(p_out);
if (p_ref)
fclose(p_ref);
#if TRACE
fclose(p_trace);
#endif
free (input);
free (snr);
free (pgImage);
#ifdef _HRD_
end_hrd();
free_dpb();
#endif // _HRD_
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -