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

📄 lencod.c

📁 JM 11.0 KTA 2.1 Source Code
💻 C
📖 第 1 页 / 共 5 页
字号:
    {
      //img->frame_num ++;
      if (input->intra_period && input->idr_enable)
      {
        if (0== (img->number % input->intra_period))
        {
          img->frame_num=0;
          primary_disp   = 0;
        }
      }
      img->frame_num %= (1 << (log2_max_frame_num_minus4 + 4)); 
    }
    
    //the following is sent in the slice header
    img->delta_pic_order_cnt[0]=0;
    
    if (input->BRefPictures == 1)
    {
      if (img->number)
      {
        img->delta_pic_order_cnt[0]=+2 * input->successive_Bframe;
      }
    }
    
    SetImgType();
#ifdef ADAPTIVE_FILTER
    InitAdaptiveFilter(input);
#endif
    
#ifdef _ADAPT_LAST_GROUP_
    if (input->successive_Bframe && input->last_frame && IMG_NUMBER+1 == input->no_frames)
    {                                           
      int bi = (int)((float)(input->jumpd+1)/(input->successive_Bframe+1.0)+0.499999);
      
      input->successive_Bframe = (input->last_frame-(img->number-1)*(input->jumpd+1))/bi-1;
      
      //about to code the last ref frame, adjust delta poc         
      img->delta_pic_order_cnt[0]= -2*(initial_Bframes - input->successive_Bframe);
      img->toppoc += img->delta_pic_order_cnt[0];
      img->bottompoc += img->delta_pic_order_cnt[0];
      img->framepoc = min (img->toppoc, img->bottompoc);
    }
#endif
    
    //Rate control
    if (img->type == I_SLICE)
    {
      if(input->RCEnable)
      {
        if (input->intra_period == 0)
        {
          n = input->no_frames + (input->no_frames - 1) * input->successive_Bframe;
          
          /* number of P frames */
          np = input->no_frames-1; 
          
          /* number of B frames */
          nb = (input->no_frames - 1) * input->successive_Bframe;
        }
        else
        {
          N = input->intra_period*(input->successive_Bframe+1);
          M = input->successive_Bframe+1;
          n = (img->number==0) ? N - ( M - 1) : N;
          
          /* last GOP may contain less frames */
          if(img->number/input->intra_period >= input->no_frames / input->intra_period)
          {
            if (img->number != 0)
              n = (input->no_frames - img->number) + (input->no_frames - img->number - 1) * input->successive_Bframe + input->successive_Bframe;
            else
              n = input->no_frames  + (input->no_frames - 1) * input->successive_Bframe;
          }
          
          /* number of P frames */
          if (img->number == 0)
            np = (n + 2 * (M - 1)) / M - 1; /* first GOP */
          else
            np = (n + (M - 1)) / M - 1;
          
          /* number of B frames */
          nb = n - np - 1;
        }
        rc_init_GOP(np,nb);
      }
    }
    
    
    // which layer the image belonged to?
    if ( IMG_NUMBER % (input->NumFramesInELSubSeq+1) == 0 )
      img->layer = 0;
    else
      img->layer = 1;
    
    // redundant frame initialization and allocation
    if(input->redundant_pic_flag)
    {
      Init_redundant_frame();
      Set_redundant_frame();
    }
    
    encode_one_frame(); // encode one I- or P-frame
    
    // if key frame is encoded, encode one redundant frame
    if(input->redundant_pic_flag && key_frame)
    {
      encode_one_redundant_frame();
    }
    
    if (img->type == I_SLICE && input->EnableOpenGOP)
      img->last_valid_reference = img->ThisPOC;
    
    if (input->ReportFrameStats)
      report_frame_statistic();
    
    if (img->nal_reference_idc == 0)
    {
      primary_disp ++;
      img->frame_num -= 1;
      img->frame_num %= (1 << (log2_max_frame_num_minus4 + 4));
    }    
    encode_enhancement_layer();
    
    process_2nd_IGOP();
  }
  // terminate sequence
  terminate_sequence();
  
  flush_dpb();
#ifdef USE_POST_FILTER
  if(input->UsePostFilter)
    Apply_postfilter();
#endif 
  close(p_in);
  if (-1!=p_dec)
    close(p_dec);
  if (p_trace)
    fclose(p_trace);
  
  Clear_Motion_Search_Module ();
  
  RandomIntraUninit();
  FmoUninit();
  
  if (input->HierarchicalCoding)
    clear_gop_structure ();
  
  // free structure for rd-opt. mode decision
  clear_rdopt ();
  
#ifdef _LEAKYBUCKET_
  calc_buffer();
#endif
  
  // report everything
  report();
  
#ifdef _LEAKYBUCKET_
  free(Bit_Buffer);
#endif
  free_picture (frame_pic_1);
#ifdef ADAPTIVE_FILTER
  free_picture (frame_pic_aif);
#endif
  if (input->RDPictureDecision)
  {
    free_picture (frame_pic_2);
    free_picture (frame_pic_3);
  }
#ifdef ADAPTIVE_QUANTIZATION
  if (input->UseAdaptiveQuantMatrix)
    free_picture (frame_pic_aqms);
#endif
#ifdef MV_COMPETITION
  close_MV_Competition();
#endif
  
  if (top_pic)
    free_picture (top_pic);
  if (bottom_pic)
    free_picture (bottom_pic);
  
  free_dpb();
  free_colocated(Co_located);
  uninit_out_buffer();
  
  free_global_buffers();
#ifdef ADAPTIVE_FILTER
  FreeAdaptiveFilter();
#endif  
  
  // free image mem
  free_img ();
  free_context_memory ();
  FreeNalPayloadBuffer();
  FreeParameterSets();
  return 0;                         //encode JM73_FME version
}
/*!
***********************************************************************
* \brief
*    Terminates and reports statistics on error.
* 
***********************************************************************
*/
void report_stats_on_error(void)
{
  input->no_frames=img->number;
  terminate_sequence();
  
  flush_dpb();
  
  close(p_in);
  if (-1!=p_dec)
    close(p_dec);
  
  if (p_trace)
    fclose(p_trace);
  
  Clear_Motion_Search_Module ();
  
  RandomIntraUninit();
  FmoUninit();
  
  if (input->HierarchicalCoding)
    clear_gop_structure ();
  
  // free structure for rd-opt. mode decision
  clear_rdopt ();
  
#ifdef _LEAKYBUCKET_
  calc_buffer();
#endif
  
  if (input->ReportFrameStats)
    report_frame_statistic();
  
  // report everything
  report();
  
  free_picture (frame_pic_1);
  if (top_pic)
    free_picture (top_pic);
  if (bottom_pic)
    free_picture (bottom_pic);
  
  free_dpb();
  free_colocated(Co_located);
  uninit_out_buffer();
  
  free_global_buffers();
  
  // free image mem
  free_img ();
  free_context_memory ();
  FreeNalPayloadBuffer();
  FreeParameterSets();
}

/*!
***********************************************************************
* \brief
*    Initializes the POC structure with appropriate parameters.
* 
***********************************************************************
*/
void init_poc()
{
  //the following should probably go in sequence parameters
  // frame poc's increase by 2, field poc's by 1
  
  img->pic_order_cnt_type=input->pic_order_cnt_type;
  
  img->delta_pic_order_always_zero_flag=0;
  img->num_ref_frames_in_pic_order_cnt_cycle= 1;
  
  if (input->BRefPictures == 1)
  {
    img->offset_for_non_ref_pic  =   0;
    img->offset_for_ref_frame[0] =   2;
  }
  else
  {
    img->offset_for_non_ref_pic  =  -2*(input->successive_Bframe);
    img->offset_for_ref_frame[0] =   2*(input->successive_Bframe+1);
  }
  
  if ((input->PicInterlace==FRAME_CODING)&&(input->MbInterlace==FRAME_CODING))
    img->offset_for_top_to_bottom_field=0;
  else    
    img->offset_for_top_to_bottom_field=1;
  
  if ((input->PicInterlace==FRAME_CODING)&&(input->MbInterlace==FRAME_CODING))
  {
    img->pic_order_present_flag=0;
    img->delta_pic_order_cnt_bottom = 0;
  }
  else    
  {
    img->pic_order_present_flag=1;
    img->delta_pic_order_cnt_bottom = 1;
  }
}


/*!
***********************************************************************
* \brief
*    Initializes the img->nz_coeff
* \par Input:
*    none
* \par  Output:
*    none
* \ side effects
*    sets omg->nz_coef[][][][] to -1
***********************************************************************
*/
void CAVLC_init(void)
{
  unsigned int i, k, l;
  
  for (i=0;i < img->PicSizeInMbs; i++)
    for (k=0;k<4;k++)
      for (l=0;l < (4 + (unsigned int)img->num_blk8x8_uv);l++)
        img->nz_coeff[i][k][l]=0;
}


/*!
***********************************************************************
* \brief
*    Initializes the Image structure with appropriate parameters.
* \par Input:
*    Input Parameters struct inp_par *inp
* \par  Output:
*    Image Parameters struct img_par *img
***********************************************************************
*/
void init_img()
{
  int i,j;
  int byte_abs_range;
  
  static int mb_width_cr[4] = {0,8, 8,16};

⌨️ 快捷键说明

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