📄 decode.c
字号:
/*!
*************************************************************************************
* \file
* decode.c
* \brief
* AVS-M decoder main function including memory initialization,
* variable definition and declaration etc.
*
*
*
*
*************************************************************************************
*/
#include <stdlib.h>
#include <time.h>
//#include <sys/timeb.h>
#include <assert.h>
#if defined WIN32
#include <conio.h>
#endif
#include "global.h"
#include "memalloc.h"
#include "header.h"
#include "parset.h"
#include "global_define.h"
#ifdef _ISOLATED_REGION_
#include "IREG.h"
#endif
#ifdef _HRD_
#include "HRD.h"
#endif
#define RM "AVS-M WM"
#define VERSION "3.3"
#define LOGFILE "log.dec"
#define DATADECFILE "dataDec.txt"
#define TRACEFILE "trace_dec.txt" /* bitstream decoding processing statistics */
#define ERRFILE "error_report.txt" /* bitstream conformance statistics */
extern void InitiREG();
/*!
************************************************************************
* \brief
* main function for AVS-M decoder.
************************************************************************
*/
int main(int argc, char **argv)
{
int current_header;
init_decoder("c:\\avs-m\\decoderavs-m.cfg");
//sequence header, first I picture header
//picture header decoding
//SPS PPS initialization
current_header = read_new_byte_stream();
/* global memory allocation -- temporary location -- Aug 21st */
init_global_buffers();
#ifdef _HRD_
init_dpb();
#endif
//cbzhu 0412
#ifdef _ISOLATED_REGION_
if(iREGenable)
InitiREG();
#endif //_ISOLATED_REGION_
while (current_header==SOP||current_header==LPOS)//WJP FOR NAL
{
//cbzhu 0412
#ifdef _ISOLATED_REGION_
if(iREGenable)
{
if(pgImage->number== 0)
iREGstate=0;
}
#endif //_ISOLATED_REGION_
decode_one_picture(snr);// != EOS
if(current_header==LPOS)//WJP FOR NAL
break;
current_header = read_new_byte_stream();
}
/* bistream conformance checking */
stat_parameter->tot_frame_number = pgImage->number;
#if ERR_REPORT
CheckBitstreamStatus(p_err); /* Bitstream Conformance Statistics Printout */
#endif
release_decoder();
return 0;
}
/*!
*************************************************************************************
* \brief : :Read input from configuration file
*************************************************************************************
*/
void read_configfile(char *config_filename)
{
FILE *fd;
// read the decoder configuration file
if( NULL == (fd=fopen(config_filename,"r")) )
{
snprintf(errortext, ET_SIZE, "Error: Control file %s not found\n",config_filename);
error(errortext, 300);
}
fscanf(fd,"%s",input->infile); // input bitstream file
fscanf(fd,"%*[^\n]");
fscanf(fd,"%s",input->outfile); // output picture file
fscanf(fd,"%*[^\n]");
fscanf(fd,"%s",input->reffile); // reference file
fscanf(fd,"%*[^\n]");
#ifdef _ISOLATED_REGION_
fscanf(fd,"%d",&iREGenable);
fscanf(fd,"%*[^\n]");
fscanf(fd,"%d",&iREGrate);
fscanf(fd,"%*[^\n]");
#endif
#ifdef _HRD_
fscanf(fd,"%ld,",&input->R_decoder); // Decoder rate
fscanf(fd, "%*[^\n]");
fscanf(fd,"%ld,",&input->B_decoder); // Decoder buffer size
fscanf(fd, "%*[^\n]");
fscanf(fd,"%ld,",&input->F_decoder); // Decoder initial delay
fscanf(fd, "%*[^\n]");
fscanf(fd,"%s",input->LeakyBucketParamFile); // file where Leaky Bucket params (computed by encoder) are stored
fscanf(fd,"%*[^\n]");
#endif // _HRD_
#if TRACE
if ( NULL == (p_trace=fopen(TRACEFILE,"w")) ) //!<write trace file in ASCII format
{
snprintf(errortext, ET_SIZE, "Error open file %s!",TRACEFILE);
error(errortext,500);
}
#endif
#if ERR_REPORT
if ( NULL == (p_err=fopen(ERRFILE,"w")) )
{
snprintf(errortext, ET_SIZE, "Error open file %s!",ERRFILE);
error(errortext,500);
}
#endif
// if ( NULL == (bits=fopen(input->infile, "rb")) ) //!< open bitstream file in bit format
// {
// snprintf (errortext, ET_SIZE, "Cannot open Annex B ByteStream file '%s'", input->infile);
// error(errortext,500);
// }
if ( NULL ==(p_out=fopen(input->outfile,"wb")) ) //!< write out dec.yuv in bit format
{
snprintf(errortext, ET_SIZE, "Error open file %s ",input->outfile);
error(errortext,500);
}
fprintf(stdout,"--------------------------------------------------------------------------\n");
fprintf(stdout," Decoder config file : %s \n",config_filename);
fprintf(stdout,"--------------------------------------------------------------------------\n");
fprintf(stdout," Input bitstream file : %s \n",input->infile);
fprintf(stdout," Output decoded YUV 4:2:0 : %s \n",input->outfile);
fprintf(stdout," Output status file : %s \n",LOGFILE);
if ((p_ref=fopen(input->reffile,"rb"))==0)
{
fprintf(stdout," Input reference file : %s does not exist \n",input->reffile);
fprintf(stdout," SNR values are not available\n");
}
else
fprintf(stdout," Input reference file : %s \n",input->reffile);
fprintf(stdout,"--------------------------------------------------------------------------\n");
//added by yiwang, 2005.3.19
#ifdef _HRD_
if(fopen(input->LeakyBucketParamFile,"rb"))
{
fprintf(stdout," Rate_decoder : %8ld \n",input->R_decoder);
fprintf(stdout," B_decoder : %8ld \n",input->B_decoder);
fprintf(stdout," F_decoder : %8ld \n",input->F_decoder);
fprintf(stdout," LeakyBucketParamFile: %s \n",input->LeakyBucketParamFile); // Leaky Bucket Param file
calc_buffer(input);
fprintf(stdout,"--------------------------------------------------------------------------\n");
}
#endif // _HRD_
#ifndef _PSNR_YUV_
fprintf(stdout," Frame QP SnrY SnrU SnrV Time(ms)\n");
#else
fprintf(stdout," Frame QP SnrY SnrU SnrV SnrYUV Time(ms)\n");
#endif // _PSNR_YUV_
}
/*!
*************************************************************************************
* \brief : Reports the gathered information to appropriate outputs
*************************************************************************************
*/
void report_seq(struct snr_par *snr)
{
#define OUTSTRING_SIZE 255
char string[OUTSTRING_SIZE];
FILE *p_log;
#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);
#ifdef _PSNR_YUV_
fprintf(stdout," SNR YUV(dB) : %5.2f\n",snr->snr_yuva);
#endif // _PSNR_YUV_
fprintf(stdout," Total decoding time : %.3f sec \n",tot_time*0.001);
fprintf(stdout," Decoding Frames/sec : %.3f fps \n",stat_parameter->tot_frame_number/(tot_time*0.001));
fprintf(stdout,"--------------------------------------------------------------------------\n");
fprintf(stdout," Exit %s decoder, ver %s \n",RM,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
{
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,"| Date | Time | Sequence |#Img|Format|SNRY 1|SNRU 1|SNRV 1|SNRY N|SNRU N|SNRV N|\n");
fprintf(p_log," ------------------------------------------------------------------------------------------\n");
}
}
else
{
fclose(p_log);
p_log=fopen(string,"a"); // File exist,just open for appending
}
#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 );
strftime (string, sizeof string, "%H:%M:%S", l_time);
fprintf(p_log,"| %1.5s |",string );
#endif
fprintf(p_log,"%20.20s|",input->infile);
fprintf(p_log,"%3d |",pgImage->number);
fprintf(p_log,"%6.3f|",snr->snr_y1);
fprintf(p_log,"%6.3f|",snr->snr_u1);
fprintf(p_log,"%6.3f|",snr->snr_v1);
fprintf(p_log,"%6.3f|",snr->snr_ya);
fprintf(p_log,"%6.3f|",snr->snr_ua);
fprintf(p_log,"%6.3f|\n",snr->snr_va);
fclose(p_log);
snprintf(string, OUTSTRING_SIZE,"%s", DATADECFILE);
p_log=fopen(string,"a");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -