📄 ldecod.c
字号:
img->idr_psnr_number=input->ref_offset;
img->psnr_number=0;
img->number=0;
img->type = I_SLICE;
img->dec_ref_pic_marking_buffer = NULL;
// B pictures
Bframe_ctr=snr->frame_ctr=0;
// time for total decoding session
tot_time = 0;
// reference flag initialization
for(i=0;i<17;i++)
{
ref_flag[i]=1;
}
while (decode_one_frame(img, input, snr) != EOS)
;
report(input, img, snr);
free_slice(input,img);
FmoFinit();
free_global_buffers();
flush_dpb();
#ifdef PAIR_FIELDS_IN_OUTPUT
flush_pending_output(p_out);
#endif
CloseBitstreamFile();
close(p_out);
// fclose(p_out2);
if (p_ref!=-1)
close(p_ref);
#if TRACE
fclose(p_trace);
#endif
#ifdef MV_COMPETITION
close_MV_Competition();
#endif
ercClose(erc_errorVar);
free_dpb();
uninit_out_buffer();
free_colocated(Co_located);
free (input);
free (snr);
free (img);
//while( !kbhit() );
return 0;
}
/*!
***********************************************************************
* \brief
* Initilize some arrays
***********************************************************************
*/
void init(struct img_par *img) //!< image parameters
{
img->oldFrameSizeInMbs = -1;
imgY_ref = NULL;
imgUV_ref = NULL;
img->recovery_point = 0;
img->recovery_point_found = 0;
img->recovery_poc = 0x7fffffff; /* set to a max value */
}
/*!
***********************************************************************
* \brief
* Initialize FREXT variables
***********************************************************************
*/
void init_frext(struct img_par *img) //!< image parameters
{
//pel bitdepth init
img->bitdepth_luma_qp_scale = 6*(img->bitdepth_luma - 8);
#ifdef INTERNAL_BIT_DEPTH_INCREASE
if (img->BitDepthIncrease>0 || img->BitDepthIncreaseChroma>0)
{
img->pic_unit_bitsize_on_disk = (input->output_bitdepth > 8)? 16:8;
}
else
{
if(img->bitdepth_luma > img->bitdepth_chroma || active_sps->chroma_format_idc == YUV400)
img->pic_unit_bitsize_on_disk = (img->bitdepth_luma > 8)? 16:8;
else
img->pic_unit_bitsize_on_disk = (img->bitdepth_chroma > 8)? 16:8;
}
#else
if(img->bitdepth_luma > img->bitdepth_chroma || active_sps->chroma_format_idc == YUV400)
img->pic_unit_bitsize_on_disk = (img->bitdepth_luma > 8)? 16:8;
else
img->pic_unit_bitsize_on_disk = (img->bitdepth_chroma > 8)? 16:8;
#endif
img->dc_pred_value_luma = 1<<(img->bitdepth_luma - 1);
img->max_imgpel_value = (1<<img->bitdepth_luma) - 1;
if (active_sps->chroma_format_idc != YUV400)
{
//for chrominance part
img->bitdepth_chroma_qp_scale = 6*(img->bitdepth_chroma - 8);
img->dc_pred_value_chroma = 1<<(img->bitdepth_chroma - 1);
img->max_imgpel_value_uv = (1<<img->bitdepth_chroma) - 1;
img->num_blk8x8_uv = (1<<active_sps->chroma_format_idc)&(~(0x1));
img->num_cdc_coeff = img->num_blk8x8_uv<<1;
img->mb_cr_size_x = (active_sps->chroma_format_idc==YUV420 || active_sps->chroma_format_idc==YUV422)? 8:16;
img->mb_cr_size_y = (active_sps->chroma_format_idc==YUV444 || active_sps->chroma_format_idc==YUV422)? 16:8;
// Residue Color Transform
if(img->residue_transform_flag)
img->bitdepth_chroma_qp_scale += 6;
}
else
{
img->bitdepth_chroma_qp_scale = 0;
img->max_imgpel_value_uv = 0;
img->num_blk8x8_uv = 0;
img->num_cdc_coeff = 0;
img->mb_cr_size_x = 0;
img->mb_cr_size_y = 0;
}
}
/*!
************************************************************************
* \brief
* Read input from configuration file
*
* \par Input:
* Name of configuration filename
*
* \par Output
* none
************************************************************************
*/
void init_conf(struct inp_par *inp, char *config_filename)
{
FILE *fd;
int NAL_mode;
// picture error concealment
long int temp;
char tempval[100];
// read the decoder configuration file
if((fd=fopen(config_filename,"r")) == NULL)
{
snprintf(errortext, ET_SIZE, "Error: Control file %s not found\n",config_filename);
error(errortext, 300);
}
fscanf(fd,"%s",inp->infile); // H.264 compressed input bitstream
fscanf(fd,"%*[^\n]");
fscanf(fd,"%s",inp->outfile); // RAW (YUV/RGB) output file
fscanf(fd,"%*[^\n]");
fscanf(fd,"%s",inp->reffile); // reference file
fscanf(fd,"%*[^\n]");
fscanf(fd,"%d",&(inp->write_uv)); // write UV in YUV 4:0:0 mode
fscanf(fd,"%*[^\n]");
fscanf(fd,"%d",&(NAL_mode)); // NAL mode
fscanf(fd,"%*[^\n]");
switch(NAL_mode)
{
case 0:
inp->FileFormat = PAR_OF_ANNEXB;
break;
case 1:
inp->FileFormat = PAR_OF_RTP;
break;
default:
snprintf(errortext, ET_SIZE, "NAL mode %i is not supported", NAL_mode);
error(errortext,400);
}
fscanf(fd,"%d,",&inp->ref_offset); // offset used for SNR computation
fscanf(fd,"%*[^\n]");
fscanf(fd,"%d,",&inp->poc_scale); // offset used for SNR computation
fscanf(fd,"%*[^\n]");
if (inp->poc_scale < 1 || inp->poc_scale > 10)
{
snprintf(errortext, ET_SIZE, "Poc Scale is %d. It has to be within range 1 to 10",inp->poc_scale);
error(errortext,1);
}
inp->write_uv=1;
// picture error concealment
img->conceal_mode = inp->conceal_mode = 0;
img->ref_poc_gap = inp->ref_poc_gap = 2;
img->poc_gap = inp->poc_gap = 2;
#ifdef _LEAKYBUCKET_
fscanf(fd,"%ld,",&inp->R_decoder); // Decoder rate
fscanf(fd, "%*[^\n]");
fscanf(fd,"%ld,",&inp->B_decoder); // Decoder buffer size
fscanf(fd, "%*[^\n]");
fscanf(fd,"%ld,",&inp->F_decoder); // Decoder initial delay
fscanf(fd, "%*[^\n]");
fscanf(fd,"%s",inp->LeakyBucketParamFile); // file where Leaky Bucket params (computed by encoder) are stored
fscanf(fd,"%*[^\n]");
#endif
/* since error concealment parameters are added at the end of
decoder conf file we need to read the leakybucket params to get to
those parameters */
#ifndef _LEAKYBUCKET_
fscanf(fd,"%ld,",&temp);
fscanf(fd, "%*[^\n]");
fscanf(fd,"%ld,",&temp);
fscanf(fd, "%*[^\n]");
fscanf(fd,"%ld,",&temp);
fscanf(fd, "%*[^\n]");
fscanf(fd,"%s",tempval);
fscanf(fd,"%*[^\n]");
#endif
fscanf(fd,"%d",&inp->conceal_mode); // Mode of Error Concealment
fscanf(fd,"%*[^\n]");
img->conceal_mode = inp->conceal_mode;
fscanf(fd,"%d",&inp->ref_poc_gap); // POC gap depending on pattern
fscanf(fd,"%*[^\n]");
img->ref_poc_gap = inp->ref_poc_gap;
fscanf(fd,"%d",&inp->poc_gap); // POC gap between consecutive frames in display order
fscanf(fd,"%*[^\n]");
img->poc_gap = inp->poc_gap;
#ifdef INTERNAL_BIT_DEPTH_INCREASE
inp->output_bitdepth = -1;
fscanf(fd,"%d",&inp->output_bitdepth); // Output bit depth
fscanf(fd,"%*[^\n]");
#endif
fclose (fd);
}
/*!
************************************************************************
* \brief
* Reports the gathered information to appropriate outputs
*
* \par Input:
* struct inp_par *inp,
* struct img_par *img,
* struct snr_par *stat
*
* \par Output:
* None
************************************************************************
*/
void report(struct inp_par *inp, struct img_par *img, struct snr_par *snr)
{
#define OUTSTRING_SIZE 255
char string[OUTSTRING_SIZE];
FILE *p_log;
char yuv_formats[4][4]= { {"400"}, {"420"}, {"422"}, {"444"} };
#ifndef WIN32
time_t now;
struct tm *l_time;
#else
char timebuf[128];
#endif
fprintf(stdout,"-------------------- Average SNR all frames ------------------------------\n");
fprintf(stdout," SNR Y(dB) : %5.2f\n",snr->snr_ya);
fprintf(stdout," SNR U(dB) : %5.2f\n",snr->snr_ua);
fprintf(stdout," SNR V(dB) : %5.2f\n",snr->snr_va);
fprintf(stdout," Total decoding time : %.3f sec \n",tot_time*0.001);
fprintf(stdout,"--------------------------------------------------------------------------\n");
fprintf(stdout," Exit JM %s decoder, ver %s ",JM, VERSION);
fprintf(stdout,"\n");
// write to log file
snprintf(string, OUTSTRING_SIZE, "%s", LOGFILE);
if ((p_log=fopen(string,"r"))==0) // check if file exist
{
if ((p_log=fopen(string,"a"))==0)
{
snprintf(errortext, ET_SIZE, "Error open file %s for appending",string);
error(errortext, 500);
}
else // Create header to new file
{
#ifdef ADAPTIVE_FILTER
fprintf(p_log," -------------------------------------------------------------------------------------------------------------------------------\n");
fprintf(p_log,"| Decoder statistics. This file is made first time, later runs are appended |\n");
fprintf(p_log," ------------------------------------------------------------------------------------------------------------------------------- \n");
fprintf(p_log,"| ver | Date | Time | Sequence |#Img| Format | YUV |Coding|AIF|SNRY 1|SNRU 1|SNRV 1|SNRY N|SNRU N|SNRV N|\n");
fprintf(p_log," -------------------------------------------------------------------------------------------------------------------------------\n");
#else
fprintf(p_log," -------------------------------------------------------------------------------------------------------------------\n");
fprintf(p_log,"| Decoder statistics. This file is made first time, later runs are appended |\n");
fprintf(p_log," ------------------------------------------------------------------------------------------------------------------- \n");
fprintf(p_log,"| ver | Date | Time | Sequence |#Img| Format | YUV |Coding|SNRY 1|SNRU 1|SNRV 1|SNRY N|SNRU N|SNRV N|\n");
fprintf(p_log," -------------------------------------------------------------------------------------------------------------------\n");
#endif
}
}
else
{
fclose(p_log);
p_log=fopen(string,"a"); // File exist,just open for appending
}
fprintf(p_log,"|%s/%-4s", VERSION, EXT_VERSION);
#ifdef WIN32
_strdate( timebuf );
fprintf(p_log,"| %1.5s |",timebuf );
_strtime( timebuf);
fprintf(p_log," % 1.5s |",timebuf);
#else
now = time ((time_t *) NULL); // Get the system time and put it into 'now' as 'calender time'
time (&now);
l_time = localtime (&now);
strftime (string, sizeof string, "%d-%b-%Y", l_time);
fprintf(p_log,"| %1.5s |",string );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -