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

📄 lencod.c

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

/*!
***********************************************************************
*  \mainpage
*     This is the H.264/AVC encoder 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
*     lencod.c
*  \brief
*     H.264/AVC reference encoder project main()
*  \author
*   Main contributors (see contributors.h for copyright, address and affiliation details)
*   - Inge Lille-Langoy               <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>
*   - Byeong-Moon Jeon                <jeonbm@lge.com>
*   - Yoon-Seong Soh                  <yunsung@lge.com>
*   - Thomas Stockhammer              <stockhammer@ei.tum.de>
*   - Detlev Marpe                    <marpe@hhi.de>
*   - Guido Heising                   <heising@hhi.de>
*   - Valeri George                   <george@hhi.de>
*   - Karsten Suehring                <suehring@hhi.de>
*   - Alexis Michael Tourapis         <alexismt@ieee.org>
***********************************************************************
*/

#include "contributors.h"

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

#ifdef WIN32
#include <io.h>
#else
#include <unistd.h>
#endif

#include "global.h"

#ifdef ADAPTIVE_FD_SD_CODING
#include "cabac.h"
#endif

#ifdef RDO_Q
#include "cabac.h"
#endif

#include "configfile.h"
#include "leaky_bucket.h"
#include "memalloc.h"
#include "intrarefresh.h"
#include "fmo.h"
#include "sei.h"
#include "parset.h"
#include "image.h"
#include "output.h"
#include "fast_me.h"
#include "simplified_fast_me.h"
#include "ratectl.h"
#include "explicit_gop.h"
#include "epzs.h"

#ifdef MV_COMPETITION
#include "mv_competition.h"
extern MV_Competition mv_comp;
#endif

#define VERSION "11.0"

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

#ifdef USE_POST_FILTER
#include "postprocessing.h"
#endif
#define JM          "11 (kta2.1)"
#define EXT_VERSION "(kta2.1)"



InputParameters inputs,      *input = &inputs;
ImageParameters images,      *img   = &images;
StatParameters  statistics,  *stats = &statistics;
SNRParameters   snrs,        *snr   = &snrs;
Decoders decoders, *decs=&decoders;


#ifdef _ADAPT_LAST_GROUP_
int initial_Bframes = 0;
#endif

Boolean In2ndIGOP = FALSE;
int    start_frame_no_in_this_IGOP = 0;
int    start_tr_in_this_IGOP = 0;
int    FirstFrameIn2ndIGOP=0;
int    cabac_encoding = 0;
int    frame_statistic_start;
extern ColocatedParams *Co_located;

void Init_Motion_Search_Module (void);
void Clear_Motion_Search_Module (void);
void report_frame_statistic(void);
void SetLevelIndices(void);
#ifdef ADAPTIVE_QUANTIZATION
void InitAdaptiveQuantParam();
int  ParamCheck();
#endif
void init_stats(void)
{
  stats->successive_Bframe = input->successive_Bframe;
  stats->bit_ctr_I = 0;
  stats->bit_ctr_P = 0;
  stats->bit_ctr_B = 0;
  snr->snr_y = 0.0;
  snr->snr_u = 0.0;
  snr->snr_v = 0.0;
  snr->snr_y1 = 0.0;
  snr->snr_u1 = 0.0;
  snr->snr_v1 = 0.0;
  snr->snr_ya = 0.0;
  snr->snr_ua = 0.0;
  snr->snr_va = 0.0;
  snr->sse_y  = 0.0;
  snr->sse_u  = 0.0;
  snr->sse_v  = 0.0;
  snr->msse_y = 0.0;
  snr->msse_u = 0.0;
  snr->msse_v = 0.0;
  snr->frame_ctr = 0;
}
/*!
***********************************************************************
* \brief
*    Main function for encoder.
* \param argc
*    number of command line arguments
* \param argv
*    command line arguments
* \return
*    exit code
***********************************************************************
*/
int main(int argc,char **argv)
{
  int M,N,n,np,nb;           //Rate control
  int primary_disp = 0;
  int i;
  giRDOpt_B8OnlyFlag = 0;
#ifdef ADAPTIVE_FD_SD_CODING
  adaptive_f_spatial_domain_4x4[0]=0.0;
  adaptive_f_spatial_domain_4x4[1]=0.0;
  adaptive_f_spatial_domain_8x8[0]=0.0;
  adaptive_f_spatial_domain_8x8[1]=0.0;
#endif
  
  p_dec = p_in = -1;
  
  p_stat = p_log = p_trace = NULL;
  
  frame_statistic_start = 1;
  
  Configure (argc, argv);
#ifdef ADAPTIVE_QUANTIZATION
  InitAdaptiveQuantParam();
  if(ParamCheck()<0)
    return -1;
#endif
  Init_QMatrix();
  Init_QOffsetMatrix();

  AllocNalPayloadBuffer();
  
  init_poc();
  GenerateParameterSets();
  SetLevelIndices();
  
  init_img();
  frame_pic_1= malloc_picture();
#ifdef ADAPTIVE_FILTER
  frame_pic_aif= malloc_picture();
#endif  
#ifdef MV_COMPETITION
  init_MV_Competition();
#endif
  
  if (input->RDPictureDecision)
  {
    frame_pic_2 = malloc_picture();
    frame_pic_3 = malloc_picture();
  }
#ifdef ADAPTIVE_QUANTIZATION
  if (input->UseAdaptiveQuantMatrix)
  {
    frame_pic_aqms = malloc_picture();
  }
#endif
  si_frame_indicator=0; //indicates whether the frame is SP or SI

#ifdef BUG_FIX_FOR_FREXT
  if(!input->RDPictureDecision) // over allocation bug fix when RDPictureDecision is equal to 1. by A.T
#endif
    frame_pic_2 = malloc_picture();//holds the encoded SI frame
  
  //allocation of lrec and lrec_uv for SI frames
  lrec = (int **) malloc(img->height * sizeof(int *));
  for(i=0;i<img->height;i++)
  {
    lrec[i] = (int *) malloc(img->width * sizeof(int ));
  }
  lrec_uv = (int ***) malloc(2 * sizeof(int **));
  for(i=0;i<2;i++)
  {
    lrec_uv[i] = (int **) malloc(img->height * sizeof(int *));
  }
  for(i=0;i<img->height;i++)
  {
    lrec_uv[0][i]=(int *) malloc(img->width * sizeof(int ));
    lrec_uv[1][i]=(int *) malloc(img->width * sizeof(int ));
  }
  number_sp2_frames=0;
  if (input->PicInterlace != FRAME_CODING)
  {
    top_pic = malloc_picture();
    bottom_pic = malloc_picture();
  }
  init_rdopt ();
#ifdef _LEAKYBUCKET_
  Bit_Buffer = malloc((input->no_frames * (input->successive_Bframe + 1) + 1) * sizeof(long));
#endif
  
  if (input->HierarchicalCoding )
  {
    init_gop_structure();
    if (input->HierarchicalCoding == 3)
    {
      interpret_gop_structure();
    }
    else
    {
      create_hierarchy();
    }
  }  
  
  dpb.init_done = 0;
  init_dpb();
  init_out_buffer();
  init_stats();
  
  enc_picture = enc_frame_picture = enc_top_picture = enc_bottom_picture = NULL;
  
  init_global_buffers();
  
  create_context_memory ();
  
  Init_Motion_Search_Module ();
  
  information_init();
  
#ifdef RDO_Q
  if(input->UseRDO_Q)
    precalculate_unary_exp_golomb_level();
#endif
  
  //Rate control 
  if(input->RCEnable)
    rc_init_seq();
  
  if(input->FMEnable == 1)
    DefineThreshold();
  
  // Init frame type counter. Only supports single slice per frame.
  memset(frame_ctr, 0, 5 * sizeof(int));
  
  img->last_valid_reference = 0;
  tot_time=0;                 // time for total encoding session
  
#ifdef _ADAPT_LAST_GROUP_
  if (input->last_frame > 0)
    input->no_frames = 1 + (input->last_frame + input->jumpd) / (input->jumpd + 1);
  initial_Bframes = input->successive_Bframe;
#endif
  
  PatchInputNoFrames();
  
  // Write sequence header (with parameter sets)
  stats->bit_ctr_parametersets = 0;
  stats->bit_slice = start_sequence();
  stats->bit_ctr_parametersets += stats->bit_ctr_parametersets_n;
  start_frame_no_in_this_IGOP = 0;
  
  for (img->number=0; img->number < input->no_frames; img->number++)
  {
    //img->nal_reference_idc = 1;
    if (input->intra_period)
      img->nal_reference_idc = ((IMG_NUMBER % input->intra_period) && input->DisposableP) ? (img->number + 1)% 2 : 1;
    else
      img->nal_reference_idc = (img->number && input->DisposableP) ? (img->number + 1)% 2 : 1;
    
    //much of this can go in init_frame() or init_field()?
    //poc for this frame or field
    img->toppoc = (input->intra_period && input->idr_enable ? IMG_NUMBER % input->intra_period : IMG_NUMBER) * (2*(input->jumpd+1)); 
    
    if ((input->PicInterlace==FRAME_CODING)&&(input->MbInterlace==FRAME_CODING))
      img->bottompoc = img->toppoc;     //progressive
    else 
      img->bottompoc = img->toppoc+1;   //hard coded
    
    img->framepoc = min (img->toppoc, img->bottompoc);
    
    //frame_num for this frame
    //if (input->BRefPictures== 0 || input->successive_Bframe == 0 || img-> number < 2)
    if ((input->BRefPictures != 1 &&  input->HierarchicalCoding == 0) || input->successive_Bframe == 0 || img-> number < 2)// ||  input->HierarchicalCoding == 0)
    {
      if (input->intra_period && input->idr_enable)
      {
        img->frame_num =  ((IMG_NUMBER - primary_disp)  % input->intra_period ) % (1 << (log2_max_frame_num_minus4 + 4)); 
        if (IMG_NUMBER % input->intra_period  == 0)
        {
          img->frame_num = 0;
          primary_disp   = 0;
        }
      }
      else
        img->frame_num = (IMG_NUMBER - primary_disp) % (1 << (log2_max_frame_num_minus4 + 4)); 
      
    }
    else 

⌨️ 快捷键说明

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