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

📄 explicit_gop.c

📁 压缩JM12.3d的完整的全部C语言的代码文档,用于嵌入式系统的压缩编解码
💻 C
📖 第 1 页 / 共 2 页
字号:
            }
            stored_read = 1;
          }
          else if (stored_read == 1 && qp_read == 0)
          {
            if (isdigit((int)(*(input->ExplicitHierarchyFormat+i))))
            {
              sscanf(input->ExplicitHierarchyFormat+i,"%d",&dqp);

              if (gop_structure[coded_frame].slice_type == I_SLICE)
                gop_structure[coded_frame].slice_qp = input->qp0;
              else if (gop_structure[coded_frame].slice_type == P_SLICE)
                gop_structure[coded_frame].slice_qp = input->qpN;
              else
                gop_structure[coded_frame].slice_qp = input->qpB;

              gop_structure[coded_frame].slice_qp = iClip3(-img->bitdepth_luma_qp_scale, 51,gop_structure[coded_frame].slice_qp + dqp);
                qp_read = 1;
            }
            else
            {
              snprintf(errortext, ET_SIZE, "Reference_IDC needs to be followed by QP. Please check configuration file.");
              error (errortext, 400);
            }
          }
          else if (stored_read == 1 && qp_read == 1 && !(isdigit((int)(*(input->ExplicitHierarchyFormat+i)))) && (i < nLength - 2))
          {
            stored_read =0;
            qp_read=0;
            order_read=0;
            slice_read=0;
            i--;
            coded_frame ++;
            if (coded_frame >= input->jumpd )
            {
              snprintf(errortext, ET_SIZE, "Total number of frames in Enhancement GOP need to be fewer or equal to FrameSkip parameter.");
              error (errortext, 400);
            }
          }
        }
      }
    }
  }
  else
  {
    snprintf(errortext, ET_SIZE, "ExplicitHierarchyFormat is empty. Please check configuration file.");
    error (errortext, 400);
  }

  input->successive_Bframe = coded_frame + 1;
}


/*!
************************************************************************
* \brief
*    Encode Enhancement Layer.
************************************************************************
*/
void encode_enhancement_layer()
{
  //int previous_ref_idc = 1;

  if ((input->successive_Bframe != 0) && (IMG_NUMBER > 0) && (input->EnableIDRGOP == 0 || img->idr_gop_number)) // B-frame(s) to encode
  {
    img->type = ( input->PReplaceBSlice ) ? P_SLICE : B_SLICE;            // set slice type
    img->layer = (input->NumFramesInELSubSeq == 0) ? 0 : 1;
    img->nal_reference_idc = NALU_PRIORITY_DISPOSABLE;

    if (input->HierarchicalCoding)
    {
      for(img->b_frame_to_code = 1; img->b_frame_to_code <= input->successive_Bframe; img->b_frame_to_code++)
      {
        img->nal_reference_idc = NALU_PRIORITY_DISPOSABLE;
        img->type = gop_structure[img->b_frame_to_code - 1].slice_type;

        if (img->last_ref_idc == 1)
        {
          img->frame_num++;                 //increment frame_num for each stored B slice
          img->frame_num %= max_frame_num;
        }
        
        img->nal_reference_idc = gop_structure[img->b_frame_to_code - 1].reference_idc;
        img->b_interval = ((double) (input->jumpd + 1) / (input->successive_Bframe + 1.0) );

        if (input->HierarchicalCoding == 3)
          img->b_interval = 1.0;

        if (IMG_NUMBER && (IMG_NUMBER <= input->intra_delay))
        {
          if(input->idr_period && ( img->frm_number - img->lastIDRnumber ) % input->idr_period == 0)
            img->toppoc = (int)(img->b_interval * (double)(1 + gop_structure[img->b_frame_to_code - 1].display_no));
          else
            img->toppoc = 2*((-img->frm_number + img->lastIDRnumber)*(input->jumpd + 1) 
            + (int)(img->b_interval * (double)(1 + gop_structure[img->b_frame_to_code -1].display_no)));

          if (img->b_frame_to_code == 1)
            img->delta_pic_order_cnt[0] = img->toppoc - 2*(start_tr_in_this_IGOP  + (input->intra_delay - IMG_NUMBER)*((input->jumpd + 1)));
          else
            img->delta_pic_order_cnt[0] = img->toppoc - 2*(start_tr_in_this_IGOP  + (input->intra_delay - IMG_NUMBER)*((input->jumpd + 1)) 
            + (int) (2.0 *img->b_interval * (double) (1+ gop_structure[img->b_frame_to_code - 2].display_no)));
        }
        else
        {
          if(input->idr_period)
            img->toppoc = 2*((( ( img->frm_number - img->lastIDRnumber - input->intra_delay) % input->idr_period ) - 1)*(input->jumpd + 1) 
            + (int)(img->b_interval * (double)(1 + gop_structure[img->b_frame_to_code - 1].display_no)));
          else
            img->toppoc = 2*((img->frm_number - img->lastIDRnumber - 1 - input->intra_delay)*(input->jumpd + 1) 
            + (int)(img->b_interval * (double)(1 + gop_structure[img->b_frame_to_code -1].display_no)));

          if (img->b_frame_to_code == 1)
            img->delta_pic_order_cnt[0] = img->toppoc - 2*(start_tr_in_this_IGOP  + (img->frm_number - img->lastIDRnumber)*((input->jumpd + 1)));
          else
            img->delta_pic_order_cnt[0] = img->toppoc - 2*(start_tr_in_this_IGOP  + (img->frm_number - img->lastIDRnumber - 1)*((input->jumpd + 1)) 
            + (int) (2.0 *img->b_interval * (double) (1+ gop_structure[img->b_frame_to_code - 2].display_no)));
        }

        img->bottompoc = ((input->PicInterlace==FRAME_CODING)&&(input->MbInterlace==FRAME_CODING)) ? img->toppoc : img->toppoc + 1;
        img->framepoc = imin (img->toppoc, img->bottompoc);

        img->delta_pic_order_cnt[1]= 0;   
        FrameNumberInFile = CalculateFrameNumber();

        encode_one_frame();  // encode one frame
        
        img->last_ref_idc = img->nal_reference_idc ? 1 : 0;

        if (input->ReportFrameStats)
          report_frame_statistic();
      }
      img->b_frame_to_code = 0;
    }
    else
    {
      for(img->b_frame_to_code = 1; img->b_frame_to_code <= input->successive_Bframe; img->b_frame_to_code++)
      {
        img->nal_reference_idc = (input->BRefPictures == 1 ) ? NALU_PRIORITY_LOW : NALU_PRIORITY_DISPOSABLE;
        
        if (img->last_ref_idc)
        {
          img->frame_num++;                 //increment frame_num once for B-frames
          img->frame_num %= max_frame_num;
        }

        img->b_interval =
          ((double) (input->jumpd + 1) / (input->successive_Bframe + 1.0) );

        if (input->HierarchicalCoding == 3)
          img->b_interval = 1.0;

        if (IMG_NUMBER && (IMG_NUMBER <= input->intra_delay))
        { 
          if(input->idr_period && ( img->frm_number - img->lastIDRnumber ) % input->idr_period == 0)
            img->toppoc = (int) (img->b_interval * (double)img->b_frame_to_code);
          else
            img->toppoc = 2*((-img->frm_number + img->lastIDRnumber)*(input->jumpd + 1) 
            + (int) (img->b_interval * (double)img->b_frame_to_code));
        }
        else
        {
          if(input->idr_period)
            img->toppoc = 2*((( ( img->frm_number - img->lastIDRnumber - input->intra_delay) % input->idr_period )-1)*(input->jumpd+1) + (int) (img->b_interval * (double)img->b_frame_to_code));
          else
            img->toppoc = 2*((img->frm_number - img->lastIDRnumber - 1 - input->intra_delay)*(input->jumpd+1) + (int) (img->b_interval * (double)img->b_frame_to_code));
        }

        if ((input->PicInterlace==FRAME_CODING)&&(input->MbInterlace==FRAME_CODING))
          img->bottompoc = img->toppoc;     //progressive
        else
          img->bottompoc = img->toppoc+1;

        img->framepoc = imin (img->toppoc, img->bottompoc);

        //the following is sent in the slice header
        if (input->BRefPictures != 1)
        {
          img->delta_pic_order_cnt[0]= 2 * (img->b_frame_to_code - 1);
        }
        else
        {
          img->delta_pic_order_cnt[0]= -2;
        }

        img->delta_pic_order_cnt[1]= 0;   // POC200301
        FrameNumberInFile = CalculateFrameNumber();

        encode_one_frame();  // encode one B-frame
        
        img->last_ref_idc = img->nal_reference_idc ? 1 : 0;

        if (input->ReportFrameStats)
          report_frame_statistic();
      }
    }
  }
  img->b_frame_to_code = 0;
}


void poc_based_ref_management(int current_pic_num)
{
  unsigned i, pic_num = 0;

  int min_poc=INT_MAX;
  DecRefPicMarking_t *tmp_drpm,*tmp_drpm2;

  if (img->dec_ref_pic_marking_buffer!=NULL)
    return;

  if ((dpb.ref_frames_in_buffer+dpb.ltref_frames_in_buffer)==0)
    return;

  for (i=0; i<dpb.used_size;i++)
  {
    if (dpb.fs[i]->is_reference  && (!(dpb.fs[i]->is_long_term)) && dpb.fs[i]->poc < min_poc)
    {
      min_poc = dpb.fs[i]->frame->poc ;
      pic_num =  dpb.fs[i]->frame->pic_num;
    }
  }

  if (NULL==(tmp_drpm=(DecRefPicMarking_t*)calloc (1,sizeof (DecRefPicMarking_t)))) no_mem_exit("poc_based_ref_management: tmp_drpm");
  tmp_drpm->Next=NULL;

  tmp_drpm->memory_management_control_operation = 0;

  if (NULL==(tmp_drpm2=(DecRefPicMarking_t*)calloc (1,sizeof (DecRefPicMarking_t)))) no_mem_exit("poc_based_ref_management: tmp_drpm2");
  tmp_drpm2->Next=tmp_drpm;

  tmp_drpm2->memory_management_control_operation = 1;
  tmp_drpm2->difference_of_pic_nums_minus1 = current_pic_num - pic_num - 1;
  img->dec_ref_pic_marking_buffer = tmp_drpm2;

}

⌨️ 快捷键说明

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