⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ldecod.c

📁 JM 11.0 KTA 2.1 Source Code
💻 C
📖 第 1 页 / 共 3 页
字号:

/*!
***********************************************************************
*  \mainpage
*     This is the H.264/AVC decoder reference software. For detailed documentation
*     see the comments in each file.
*
*  \author
*     The main contributors are listed in contributors.h
*
*  \version
*     JM 11.0 KTA 2.1
*
*  \note
*     tags are used for document system "doxygen"
*     available at http://www.doxygen.org
*/
/*!
*  \file
*     ldecod.c
*  \brief
*     H.264/AVC reference 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             <wyk@ieee.org>
*     - Valeri George           <george@hhi.de>
*     - Karsten Suehring        <suehring@hhi.de>
*
***********************************************************************
*/

#include "contributors.h"

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <sys/timeb.h>

#if defined WIN32
#include <io.h>
#else
#include <unistd.h>
#endif
#include <sys/stat.h>
#include <fcntl.h>


#include <assert.h>

#include "global.h"
#include "rtp.h"
#include "memalloc.h"
#include "mbuffer.h"
#include "leaky_bucket.h"
#include "fmo.h"
#include "annexb.h"
#include "output.h"
#include "cabac.h"

#include "erc_api.h"


#define VERSION "11.0"

#ifdef MV_COMPETITION
#include "mv_competition.h"
#endif

#ifdef ADAPTIVE_FILTER
#include "adaptive_filter.h"
#endif

#define JM       "11 (kta2.1)"
#define EXT_VERSION "(kta2.1)"

#define LOGFILE     "log.dec"
#define DATADECFILE "dataDec.txt"
#define TRACEFILE   "trace_dec.txt"

extern objectBuffer_t *erc_object_list;
extern ercVariables_t *erc_errorVar;
extern ColocatedParams *Co_located;

// 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;
extern StorablePicture* dec_picture;

struct inp_par    *input;       //!< input parameters from input configuration file
struct snr_par    *snr;         //!< statistics
struct img_par    *img;         //!< image parameters

int global_init_done = 0;

/*!
***********************************************************************
* \brief
*   print help message and exit
***********************************************************************
*/
void JMDecHelpExit ()
{
  fprintf( stderr, "\n   ldecod [-h] {[defdec.cfg] | {[-i bitstream.264]...[-o output.yuv] [-r reference.yuv] [-uv]}}\n\n"    
    "## Parameters\n\n"
    
    "## Options\n"
    "   -h  :  prints function usage\n"
    "       :  parse <defdec.cfg> for decoder operation.\n"
    "   -i  :  Input file name. \n"
    "   -o  :  Output file name. If not specified default output is set as test_dec.yuv\n\n"
    "   -r  :  Reference file name. If not specified default output is set as test_rec.yuv\n\n"
    "   -uv :  write chroma components for monochrome streams(4:2:0)\n\n"
    
    "## Supported video file formats\n"
    "   Input : .264 -> H.264 bitstream files. \n"
    "   Output: .yuv -> RAW file. Format depends on bitstream information. \n\n"
    
    "## Examples of usage:\n"
    "   ldecod\n"
    "   ldecod  -h\n"
    "   ldecod  default.cfg\n"
    "   ldecod  -i bitstream.264 -o output.yuv -r reference.yuv\n");
  
  exit(-1);
}


void Configure(int ac, char *av[])
{
  int CLcount;
  char *config_filename=NULL;
  CLcount = 1;
  
  
  strcpy(input->infile,"test.264");      //! set default bitstream name
  strcpy(input->outfile,"test_dec.yuv"); //! set default output file name
  strcpy(input->reffile,"test_rec.yuv"); //! set default reference file name
  input->FileFormat = PAR_OF_ANNEXB;
  input->ref_offset=0;
  input->poc_scale=1;
  
#ifdef _LEAKYBUCKET_
  input->R_decoder=500000;          //! Decoder rate
  input->B_decoder=104000;          //! Decoder buffer size
  input->F_decoder=73000;           //! Decoder initial delay
  strcpy(input->LeakyBucketParamFile,"leakybucketparam.cfg");    // file where Leaky Bucket params (computed by encoder) are stored
#endif
#ifdef  INTERNAL_BIT_DEPTH_INCREASE
  input->output_bitdepth = 8;
#endif
  
  if (ac==2)
  {
    if (0 == strncmp (av[1], "-h", 2))
    {
      JMDecHelpExit();
    }
    else
    {
      config_filename=av[1];
      init_conf(input, av[1]);
    }
    CLcount=2;
  }
  
  if (ac>=3)
  {
    if (0 == strncmp (av[1], "-i", 2))
    {
      strcpy(input->infile,av[2]);
      CLcount = 3;
    }
    if (0 == strncmp (av[1], "-h", 2))
    {
      JMDecHelpExit();
    }
  }
  
  // Parse the command line
  
  while (CLcount < ac)
  {
    if (0 == strncmp (av[CLcount], "-h", 2))
    {
      JMDecHelpExit();
    }
    
    if (0 == strncmp (av[CLcount], "-i", 2))  //! Input file
    {
      strcpy(input->infile,av[CLcount+1]);      
      CLcount += 2;
    } 
    else if (0 == strncmp (av[CLcount], "-o", 2))  //! Output File
    {
      strcpy(input->outfile,av[CLcount+1]);
      CLcount += 2;
    }
    else if (0 == strncmp (av[CLcount], "-r", 2))  //! Reference File
    {
      strcpy(input->reffile,av[CLcount+1]);
      CLcount += 2;
    }
    else if (0 == strncmp (av[CLcount], "-uv", 3))  //! indicate UV writing for 4:0:0
    {
      input->write_uv = 1;
      CLcount ++;
    }
#ifdef  INTERNAL_BIT_DEPTH_INCREASE
    else if (0 == strncmp (av[CLcount], "-b", 2))  //! Output Bit Depth
    {
      input->output_bitdepth = atoi(av[CLcount+1]);
      CLcount += 2;
    }
#endif
    else
    {
      //config_filename=av[CLcount];
      //init_conf(input, config_filename);
      snprintf(errortext, ET_SIZE, "Invalid syntax. Use ldecod -h for proper usage");
      error(errortext, 300);
    }
  }
  
  
#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=open(input->outfile, OPENFLAGS_WRITE, OPEN_PERMISSIONS))==-1)
  {
    snprintf(errortext, ET_SIZE, "Error open file %s ",input->outfile);
    error(errortext,500);
  }
  /*  if ((p_out2=fopen("out.yuv","wb"))==0)
  {
  snprintf(errortext, ET_SIZE, "Error open file %s ",input->outfile);
  error(errortext,500);
  }*/
  
  
  fprintf(stdout,"----------------------------- JM %s %s -----------------------------\n", VERSION, EXT_VERSION);
  fprintf(stdout," Decoder config file                    : %s \n",config_filename);
  fprintf(stdout,"--------------------------------------------------------------------------\n");
  fprintf(stdout," Input H.264 bitstream                  : %s \n",input->infile);
  fprintf(stdout," Output decoded YUV                     : %s \n",input->outfile);
  fprintf(stdout," Output status file                     : %s \n",LOGFILE);
  if ((p_ref=open(input->reffile,OPENFLAGS_READ))==-1)
  {
    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");
#ifdef _LEAKYBUCKET_
  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
  fprintf(stdout,"POC must = frame# or field# for SNRs to be correct\n");
  fprintf(stdout,"--------------------------------------------------------------------------\n");
  fprintf(stdout,"  Frame       POC   Pic#   QP   SnrY    SnrU    SnrV   Y:U:V  Time(ms)\n");
  fprintf(stdout,"--------------------------------------------------------------------------\n");
  
}

/*!
***********************************************************************
* \brief
*    main function for TML decoder
***********************************************************************
*/
int main(int argc, char **argv)
{
  int i;
  
  // 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");
  
  
  Configure (argc, argv);
  
  init_old_slice();
  
  switch (input->FileFormat)
  {
  case 0:
    OpenBitstreamFile (input->infile);
    break;
  case 1:
    OpenRTPFile (input->infile);
    break;
  default:
    printf ("Unsupported file format %d, exit\n", input->FileFormat);
  }
  
  // Allocate Slice data struct
  malloc_slice(input,img);
  
  init(img);
  
#ifdef ADAPTIVE_FILTER
  InitAdaptiveFilter();
#endif
  
#ifdef MV_COMPETITION
  init_MV_Competition();
#endif

#ifdef USE_POST_FILTER
  img->filterbitstream = NULL;
#endif

  dec_picture = NULL;
  
  dpb.init_done = 0;
  g_nFrame = 0;
  
  init_out_buffer();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -