📄 ldecod.c
字号:
/*
***********************************************************************
* COPYRIGHT AND WARRANTY INFORMATION
*
* Copyright 2001, International Telecommunications Union, Geneva
*
* DISCLAIMER OF WARRANTY
*
* These software programs are available to the user without any
* license fee or royalty on an "as is" basis. The ITU 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
* contributor or the ITU be liable for any incidental, punitive, or
* consequential damages of any kind whatsoever arising from the
* use of these programs.
*
* This disclaimer of warranty extends to the user of these programs
* and user's customers, employees, agents, transferees, successors,
* and assigns.
*
* The ITU does not represent or warrant that the programs furnished
* hereunder are free of infringement of any third-party patents.
* Commercial implementations of ITU-T Recommendations, including
* shareware, may be subject to royalty fees to patent holders.
* Information regarding the ITU-T patent policy is available from
* the ITU Web site at http://www.itu.int.
*
* THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE ITU-T PATENT POLICY.
************************************************************************
*/
/*!
***********************************************************************
* \mainpage
* This is the H.26L decoder reference software. For detailed documentation
* see the comments in each file.
*
* \author
* The main contributors are listed in contributors.h
*
* \version
* JM 2.0
*
* \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 H.26L 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 H.26L 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
* ldecod.c
* \brief
* TML decoder project main()
* \author
* Main contributors (see contributors.h for copyright, address and affiliation details)
* - Inge Lille-Lang鴜 <inge.lille-langoy@telenor.com>
* - Rickard Sjoberg <rickard.sjoberg@era.ericsson.se>
* - Stephan Wenger <stewe@cs.tu-berlin.de>
* - Jani Lainema <jani.lainema@nokia.com>
* - Sebastian Purreiter <sebastian.purreiter@mch.siemens.de>
* - Byeong-Moon Jeon <jeonbm@lge.com>
* - Gabi Blaettermann <blaetter@hhi.de>
* - Ye-Kui Wang <wangy@cs.tut.fi>
*
***********************************************************************
*/
#include "contributors.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/timeb.h>
#if defined WIN32
#include <conio.h>
#endif
#include "global.h"
#include "elements.h"
#include "bitsbuf.h"
#include "rtp.h"
#include "memalloc.h"
#include "mbuffer.h"
#include "leaky_bucket.h"
#include "decodeiff.h"
#if _ERROR_CONCEALMENT_
#include "erc_api.h"
#endif
#define JM "2"
#define VERSION "2.0"
#define LOGFILE "log.dec"
#define DATADECFILE "data.dec"
#define TRACEFILE "trace_dec.txt"
#if _ERROR_CONCEALMENT_
extern objectBuffer_t *erc_object_list;
extern ercVariables_t *erc_errorVar;
#endif
/*!
***********************************************************************
* \brief
* main function for TML decoder
***********************************************************************
*/
int main(int argc, char **argv)
{
extern FILE* bits;
struct inp_par *inp; // input parameters from input configuration file
struct snr_par *snr; // statistics
struct img_par *img; // image parameters
// allocate memory for the structures
if ((inp = (struct inp_par *)calloc(1, sizeof(struct inp_par)))==NULL) no_mem_exit("main: inp");
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");
// 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);
}
// Initializes Configuration Parameters with configuration file
init_conf(inp, argv[1]);
if (inp->of_mode == PAR_OF_RTP)
{
extern FILE *bits;
// Read the first RTP packet conmtaining a header packet, and set the initial parameter set
RTPSequenceHeader (img, inp, bits);
}
if (inp->of_mode == PAR_OF_IFF)
{
// Read the first boxes, and set the initial parameter set
if ( -1 == IFFSequenceHeader( img, inp, bits ) )
{
snprintf(errortext, ET_SIZE, "Error: The input file is not in the Interim File Format\n");
error(errortext, 300);
}
}
// printf ("In main: some pictrue information: %d x %d, with %d reference frames %d\n", img->height, img->width, img->buf_cycle, inp->buf_cycle);
img->UseConstrainedIntraPred = inp->UseConstrainedIntraPred;
// Allocate Slice data struct
malloc_slice(inp,img);
init(img);
img->number=0;
img->type = INTRA_IMG;
img->tr_old = -1; // WYK: Oct. 8, 2001, for detection of a new frame
img->refPicID = -1; // WYK: for detection of a new non-B frame
img->mmco_buffer=NULL;
// B pictures
Bframe_ctr=0;
// time for total decoding session
tot_time = 0;
if ( inp->of_mode == PAR_OF_IFF )
while ( parse_one_box(img, inp, snr, bits) != -1 );
else
while (decode_one_frame(img, inp, snr) != EOS);
// B PICTURE : save the last P picture
write_prev_Pframe(img, p_out);
report(inp, img, snr);
free_slice(inp,img);
free_frame_buffers(inp, img);
free_global_buffers(inp, img);
terminateInterimFile();
CloseBitstreamFile();
fclose(p_out);
if (p_ref)
fclose(p_ref);
#if TRACE
fclose(p_trace);
#endif
#if _ERROR_CONCEALMENT_
ercClose(erc_errorVar);
#endif
free (inp);
free (snr);
free (img);
//while( !kbhit() );
return 0;
}
/*!
***********************************************************************
* \brief
* Initilize some arrays
***********************************************************************
*/
void init(struct img_par *img) //!< image parameters
{
int i;
// initilize quad matrix used in snr routine
for (i=0; i < 256; i++)
{
img->quad[i]=i*i; // fix from TML 1, truncation removed
}
}
/*!
************************************************************************
* \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;
// 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.26L 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]");
// Symbol mode
fscanf(fd,"%d,",&inp->symbol_mode); // 0: UVLC 1: CABAC, may be overwritten ni case of RTP NAL
fscanf(fd,"%*[^\n]");
if (inp->symbol_mode != UVLC && inp->symbol_mode != CABAC)
{
snprintf(errortext, ET_SIZE, "Unsupported symbol mode=%d, use UVLC=0 or CABAC=1",inp->symbol_mode);
error(errortext,1);
}
// UseConstrainedIntraPred
fscanf(fd,"%d,",&inp->UseConstrainedIntraPred); // 0: UsePred 1: ConstrainPred, may be overwritten in case of RTP NAL
fscanf(fd,"%*[^\n]");
if(inp->UseConstrainedIntraPred != 0 && inp->UseConstrainedIntraPred != 1)
{
snprintf(errortext, ET_SIZE, "Unsupported value=%d on constrained intra pred",inp->UseConstrainedIntraPred);
error(errortext,1);
}
// Frame buffer size
fscanf(fd,"%d,",&inp->buf_cycle); // may be overwritten in case of RTP NAL
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -