📄 ldecod.c
字号:
/*
***********************************************************************
* COPYRIGHT AND WARRANTY INFORMATION
*
* Copyright 2003, Advanced Audio Video Coding Standard, Part II
*
* DISCLAIMER OF WARRANTY
*
* These software programs are available to the users without any
* license fee or royalty on an "as is" basis. The AVS disclaims
* any and all warranties, whether express, implied, or statutory,
* including any implied warranties of merchantability or of fitness
* for a particular purpose. In no event shall the contributors or
* the AVS be liable for any incidental, punitive, or consequential
* damages of any kind whatsoever arising from the use of this program.
*
* This disclaimer of warranty extends to the user of this program
* and user's customers, employees, agents, transferees, successors,
* and assigns.
*
* The AVS does not represent or warrant that the program furnished
* hereunder are free of infringement of any third-party patents.
* Commercial implementations of AVS, including shareware, may be
* subject to royalty fees to patent holders. Information regarding
* the AVS patent policy is available from the AVS Web site at
* http://www.avs.org.cn
*
* THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE AVS PATENT POLICY.
************************************************************************
*/
/*!
***********************************************************************
* \mainpage
* This is the AVS decoder reference software. For detailed documentation
* see the comments in each file.
*
* \author
* The main contributors are listed in contributors.h
*
* \version
* JM 6.1e
*
* \note
* tags are used for document system "doxygen"
* available at http://www.doxygen.org
*
* \par Limitations:
* Using different NAL's the assignment of partition-id to containing
* syntax elements may got lost, if this information is not transmitted.
* The same has to be stated for the partitionlength if partitions are
* merged by the NAL.
* \par
* The presented solution in Q15-K-16 solves both of this problems as the
* departitioner parses the bitstream before decoding. Due to syntax element
* dependencies both, partition bounds and partitionlength information can
* be parsed by the departitioner.
*
* \par Handling partition information in external file:
* As the TML is still a work in progress, it makes sense to handle this
* information for simplification in an external file, here called partition
* information file, which can be found by the extension .dp extending the
* original encoded AVS bitstream. In this file partition-ids followed by its
* partitionlength is written. Instead of parsing the bitstream we get the
* partition information now out of this file.
* This information is assumed to be never sent over transmission channels
* (simulation scenarios) as it's information we allways get using a
* "real" departitioner before decoding
*
* \par Extension of Interim File Format:
* Therefore a convention has to be made within the interim file format.
* The underlying NAL has to take care of fulfilling these conventions.
* All partitions have to be bytealigned to be readable by the decoder,
* So if the NAL-encoder merges partitions, >>this is only possible to use the
* VLC structure of the AVS bitstream<<, this bitaligned structure has to be
* broken up by the NAL-decoder. In this case the NAL-decoder is responsable to
* read the partitionlength information from the partition information file.
* Partitionlosses are signaled with a partition of zero length containing no
* syntax elements.
*
*/
/*
*************************************************************************************
* File name: ldecod.c
* Function: TML decoder project main()
*
*************************************************************************************
*/
#include "contributors.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.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 "mbuffer.h"
#include "annexb.h"
#define RM "5"
#define VERSION "5.2i"
#define LOGFILE "log.dec"
#define DATADECFILE "dataDec.txt"
#define TRACEFILE "trace_dec.txt"
// I have started to move the inp and img structures into global variables.
// They are declared in the following lines. Since inp is defined in conio.h
// and cannot be overridden globally, it is defined here as input
// Everywhere, input-> and img-> can now be used either globally or with
// the local override through the formal parameter mechanism
extern FILE* bits;
struct inp_par *input; //!< input parameters from input configuration file
struct snr_par *snr; //!< statistics
struct img_par *img; //!< image parameters
Bitstream *currStream;
FILE *reffile,*reffile2;
/*
*************************************************************************
* Function:main function for TML decoder
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
int main(int argc, char **argv)
{
// 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 ((img = (struct img_par *)calloc(1, sizeof(struct img_par)))==NULL) no_mem_exit("main: img");
currStream = AllocBitstream();
eos = 0; //added by Xiaozhen Zheng, HiSilicon, 2007.03.21
// Read Configuration File
if (argc != 2)
{
snprintf(errortext, ET_SIZE,
"Usage: %s <config.dat> \n\t<config.dat> defines decoder parameters",argv[0]);
error(errortext, 300);
}
init_conf(input, argv[1]);
OpenBitstreamFile (input->infile);
// Allocate Slice data struct
init(img);
img->number=0;
img->type = I_IMG;
img->imgtr_last_P = 0;
img->imgtr_next_P = 0;
//img->Bframe_number=0;
// Initial vec_flag
vec_flag = 0;
FrameNum = 0; //added by Xiaozhen Zheng, HiSilicon, 2007.03.21
// B pictures
Bframe_ctr=0;
// time for total decoding session
tot_time = 0;
while (decode_one_frame(img, input, snr) != EOS);
//added by Xiaozhen Zheng HiSilicon, 2007.03.21 Begin
eos = 1;
if (p_ref)
find_snr(snr,img,p_ref); // if ref sequence exist
if(pre_img_type == I_IMG) // I picture
fprintf(stdout,"%3d(I) %3d %5d %7.4f %7.4f %7.4f %5d\n",
FrameNum, pre_img_tr, pre_img_qp,snr->snr_y,snr->snr_u,snr->snr_v,pre_tmp_time);
else if(pre_img_type == P_IMG) // P pictures
{
if (pre_img_types == I_IMG)
fprintf(stdout,"%3d(I) %3d %5d %7.4f %7.4f %7.4f %5d\n",
FrameNum, pre_img_tr, pre_img_qp,snr->snr_y,snr->snr_u,snr->snr_v,pre_tmp_time); //jlzheng 7.3
else
fprintf(stdout,"%3d(P) %3d %5d %7.4f %7.4f %7.4f %5d\n",
FrameNum, pre_img_tr, pre_img_qp,snr->snr_y,snr->snr_u,snr->snr_v,pre_tmp_time);
}
//added by Xiaozhen Zheng HiSilicon, 2007.03.21 End
report_frame(snr,pre_tmp_time);
// B PICTURE : save the last P picture
write_prev_Pframe(img, p_out);
report(input, img, snr);
FreeBitstream();
free_global_buffers(input, img);
CloseBitstreamFile();
fclose(p_out);
if (p_ref)
fclose(p_ref);
#if TRACE
fclose(p_trace);
#endif
free (input);
free (snr);
free (img);
return 0;
}
/*
*************************************************************************
* Function:Initilize some arrays
* Input:
* Output:
* Return:
* Attention:
*************************************************************************
*/
void init(struct img_par *img) //!< image parameters
{
int i;
// initilize quad mat`rix used in snr routine
for (i=0; i < 256; i++)
{
img->quad[i]=i*i;
}
}
/*
*************************************************************************
* Function:Read input from configuration file
* Input:Name of configuration filename
* Output:
* Return:
* Attention:
*************************************************************************
*/
void init_conf(struct inp_par *inp,
char *config_filename)
{
FILE *fd;
// 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); // AVS compressed input bitsream
fscanf(fd,"%*[^\n]");
fscanf(fd,"%s",inp->outfile); // YUV 4:2:2 input format
fscanf(fd,"%*[^\n]");
fscanf(fd,"%s",inp->reffile); // reference file
fscanf(fd,"%*[^\n]");
// Frame buffer size
fscanf(fd,"%d,",&inp->buf_cycle); // may be overwritten in case of RTP NAL
fscanf(fd,"%*[^\n]");
if (inp->buf_cycle < 1)
{
snprintf(errortext, ET_SIZE, "Frame Buffer Size is %d. It has to be at least 1",inp->buf_cycle);
error(errortext,1);
}
fscanf(fd,"%d,",&inp->LFParametersFlag);
fscanf(fd,"%*[^\n]");
#if TRACE
if ((p_trace=fopen(TRACEFILE,"w"))==0) // append new statistic at the end
{
snprintf(errortext, ET_SIZE, "Error open file %s!",TRACEFILE);
error(errortext,500);
}
#endif
if ((p_out=fopen(inp->outfile,"wb"))==0)
{
snprintf(errortext, ET_SIZE, "Error open file %s ",inp->outfile);
error(errortext,500);
}
fprintf(stdout,"--------------------------------------------------------------------------\n");
fprintf(stdout," Decoder config file : %s \n",config_filename);
fprintf(stdout,"--------------------------------------------------------------------------\n");
fprintf(stdout," Input AVS bitstream : %s \n",inp->infile);
fprintf(stdout," Output decoded YUV 4:2:0 : %s \n",inp->outfile);
fprintf(stdout," Output status file : %s \n",LOGFILE);
if ((p_ref=fopen(inp->reffile,"rb"))==0)
{
fprintf(stdout," Input reference file : %s does not exist \n",inp->reffile);
fprintf(stdout," SNR values are not available\n");
}
else
fprintf(stdout," Input reference file : %s \n",inp->reffile);
fprintf(stdout,"--------------------------------------------------------------------------\n");
fprintf(stdout," Frame TR QP SnrY SnrU SnrV Time(ms)\n");
}
/*
*************************************************************************
* Function:Reports the gathered information to appropriate outputs
* Input:
struct inp_par *inp,
struct img_par *img,
struct snr_par *stat
* Output:
* Return:
* Attention:
*************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -