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

📄 mbuffer.c

📁 H.264编码实现
💻 C
📖 第 1 页 / 共 5 页
字号:
  s->size_x = size_x;
  s->size_y = size_y;
  s->size_x_padded = size_x + 2 * IMG_PAD_SIZE;
  s->size_y_padded = size_y + 2 * IMG_PAD_SIZE;
  s->size_x_pad = size_x + 2 * IMG_PAD_SIZE - 1 - MB_BLOCK_SIZE;
  s->size_y_pad = size_y + 2 * IMG_PAD_SIZE - 1 - MB_BLOCK_SIZE;
  s->size_x_cr = size_x_cr;
  s->size_y_cr = size_y_cr;
  s->size_x_cr_pad = (int) (size_x_cr - 1) + (img_pad_size_uv_x << 1) - (img->mb_cr_size_x);
  s->size_y_cr_pad = (int) (size_y_cr - 1) + (img_pad_size_uv_y << 1) - (img->mb_cr_size_y);

  s->top_field    = NULL;
  s->bottom_field = NULL;
  s->frame        = NULL;

  s->coded_frame    = 0;
  s->MbaffFrameFlag = 0;

  init_stats(&s->stats);
  return s;
}

/*!
 ************************************************************************
 * \brief
 *    Free frame store memory.
 *
 * \param f
 *    FrameStore to be freed
 *
 ************************************************************************
 */
void free_frame_store(FrameStore* f)
{
  if (f)
  {
    if (f->frame)
    {
      free_storable_picture(f->frame);
      f->frame=NULL;
    }
    if (f->top_field)
    {
      free_storable_picture(f->top_field);
      f->top_field=NULL;
    }
    if (f->bottom_field)
    {
      free_storable_picture(f->bottom_field);
      f->bottom_field=NULL;
    }
    free(f);
  }
}

void free_pic_motion(PicMotionParams *motion)
{

  if (motion->ref_pic_id)
  {
    free_mem3Dint64 (motion->ref_pic_id);
    motion->ref_pic_id = NULL;
  }
  if (motion->ref_id)
  {
    free_mem3Dint64 (motion->ref_id);
    motion->ref_id = NULL;
  }

  if (motion->mv)
  {
    free_mem4Dshort (motion->mv);
    motion->mv = NULL;
  }

  if (motion->ref_idx)
  {
    free_mem3D ((byte***)motion->ref_idx);
    motion->ref_idx = NULL;
  }

  if (motion->mb_field)
  {
    free(motion->mb_field);
    motion->mb_field=NULL;
  }

  if (motion->field_frame)
  {
    free_mem2D (motion->field_frame);
    motion->field_frame=NULL;
  }
}


/*!
 ************************************************************************
 * \brief
 *    Free picture memory.
 *
 * \param p
 *    Picture to be freed
 *
 ************************************************************************
 */
void free_storable_picture(StorablePicture* p)
{
  int nplane;
  if (p)
  {
    free_mem3Dmp (p->mv_info);
    free_pic_motion(&p->motion);

    if( IS_INDEPENDENT(params) )
    {
      for( nplane=0; nplane<MAX_PLANE; nplane++ )
      {
        free_pic_motion(&p->JVmotion[nplane]);
      }
    }

    if (p->imgY)
    {      
      free_mem2Dpel (p->imgY);
      p->imgY=NULL;      
    }    

    if( IS_INDEPENDENT(params) )
    {
      if (p->imgY_sub)
      {
        free_mem4Dpel (p->imgY_sub);
        p->imgY_sub=NULL;
      }
      if (p->imgUV_sub)
      {
        free_mem5Dpel (p->imgUV_sub);
        p->imgUV_sub = NULL;
      }

      p->p_curr_img     = NULL;
      p->p_curr_img_sub = NULL;
      p->p_img[0]       = NULL;
      p->p_img[1]       = NULL;
      p->p_img[2]       = NULL;
      p->p_img_sub[0]   = NULL;
      p->p_img_sub[1]   = NULL;
      p->p_img_sub[2]   = NULL;
    }
    else
    {
      if (p->imgY_sub)
      {
        free_mem4Dpel (p->imgY_sub);
        p->imgY_sub=NULL;
      }

      if ( p->imgUV_sub && img->yuv_format != YUV400 && params->ChromaMCBuffer )
      {
        free_mem5Dpel (p->imgUV_sub);
        p->imgUV_sub = NULL;
      }
    }

    if (p->imgUV)
    {
      free_mem3Dpel (p->imgUV);
      p->imgUV=NULL;
    }

    if (p->dec_imgY)
    {
      free_mem3Dpel(p->dec_imgY);
    }
    if (p->dec_imgUV)
    {
      free_mem4Dpel(p->dec_imgUV);
    }
    for (nplane = 0; nplane < 3; nplane++)
    {
      if (p->p_dec_img[nplane])
      {  
        free(p->p_dec_img[nplane]);
        p->p_dec_img[nplane] = NULL;
      }
    }
    if (p->mb_error_map)
    {
      free_mem3D(p->mb_error_map);
    }

    p->mb_error_map = NULL;
    p->dec_imgY   = NULL;
    p->dec_imgUV  = NULL;

    free(p);
    p = NULL;
  }
}

/*!
 ************************************************************************
 * \brief
 *    mark FrameStore unused for reference
 *
 ************************************************************************
 */
static void unmark_for_reference(FrameStore* fs)
{

  if (fs->is_used & 1)
  {
    if (fs->top_field)
    {
      fs->top_field->used_for_reference = 0;
    }
  }
  if (fs->is_used & 2)
  {
    if (fs->bottom_field)
    {
      fs->bottom_field->used_for_reference = 0;
    }
  }
  if (fs->is_used == 3)
  {
    if (fs->top_field && fs->bottom_field)
    {
      fs->top_field->used_for_reference = 0;
      fs->bottom_field->used_for_reference = 0;
    }
    fs->frame->used_for_reference = 0;
  }

  fs->is_reference = 0;

  if(fs->frame)
  {
    if (fs->frame->imgY_sub)
    {
      free_mem4Dpel (fs->frame->imgY_sub);
      fs->frame->imgY_sub=NULL;
    }

    if (fs->frame->imgUV_sub)
    {
      free_mem5Dpel (fs->frame->imgUV_sub);
      fs->frame->imgUV_sub = NULL;
    }

    free_pic_motion(&fs->frame->motion);
  }

  if (fs->top_field)
  {
    if (fs->top_field->imgY_sub)
    {
      free_mem4Dpel (fs->top_field->imgY_sub);
      fs->top_field->imgY_sub=NULL;
    }

    if (fs->top_field->imgUV_sub)
    {
      free_mem5Dpel (fs->top_field->imgUV_sub);
      fs->top_field->imgUV_sub = NULL;
    }

    free_pic_motion(&fs->top_field->motion);
  }
  if (fs->bottom_field)
  {
    if (fs->bottom_field->imgY_sub)
    {
      free_mem4Dpel (fs->bottom_field->imgY_sub);
      fs->bottom_field->imgY_sub=NULL;
    }
    if (fs->bottom_field->imgUV_sub)
    {
      free_mem5Dpel (fs->bottom_field->imgUV_sub);
      fs->bottom_field->imgUV_sub = NULL;
    }

    free_pic_motion(&fs->bottom_field->motion);
  }
}


/*!
 ************************************************************************
 * \brief
 *    mark FrameStore unused for reference and reset long term flags
 *
 ************************************************************************
 */
static void unmark_for_long_term_reference(FrameStore* fs)
{

  if (fs->is_used & 1)
  {
    if (fs->top_field)
    {
      fs->top_field->used_for_reference = 0;
      fs->top_field->is_long_term = 0;
    }
  }
  if (fs->is_used & 2)
  {
    if (fs->bottom_field)
    {
      fs->bottom_field->used_for_reference = 0;
      fs->bottom_field->is_long_term = 0;
    }
  }
  if (fs->is_used == 3)
  {
    if (fs->top_field && fs->bottom_field)
    {
      fs->top_field->used_for_reference = 0;
      fs->top_field->is_long_term = 0;
      fs->bottom_field->used_for_reference = 0;
      fs->bottom_field->is_long_term = 0;
    }
    fs->frame->used_for_reference = 0;
    fs->frame->is_long_term = 0;
  }

  fs->is_reference = 0;
  fs->is_long_term = 0;
}


/*!
 ************************************************************************
 * \brief
 *    compares two stored pictures by picture number for qsort in descending order
 *
 ************************************************************************
 */
static int compare_pic_by_pic_num_desc( const void *arg1, const void *arg2 )
{
  if ( (*(StorablePicture**)arg1)->pic_num < (*(StorablePicture**)arg2)->pic_num)
    return 1;
  if ( (*(StorablePicture**)arg1)->pic_num > (*(StorablePicture**)arg2)->pic_num)
    return -1;
  else
    return 0;
}

/*!
 ************************************************************************
 * \brief
 *    compares two stored pictures by picture number for qsort in descending order
 *
 ************************************************************************
 */
static int compare_pic_by_lt_pic_num_asc( const void *arg1, const void *arg2 )
{
  if ( (*(StorablePicture**)arg1)->long_term_pic_num < (*(StorablePicture**)arg2)->long_term_pic_num)
    return -1;
  if ( (*(StorablePicture**)arg1)->long_term_pic_num > (*(StorablePicture**)arg2)->long_term_pic_num)
    return 1;
  else
    return 0;
}

/*!
 ************************************************************************
 * \brief
 *    compares two frame stores by pic_num for qsort in descending order
 *
 ************************************************************************
 */
static int compare_fs_by_frame_num_desc( const void *arg1, const void *arg2 )
{
  if ( (*(FrameStore**)arg1)->frame_num_wrap < (*(FrameStore**)arg2)->frame_num_wrap)
    return 1;
  if ( (*(FrameStore**)arg1)->frame_num_wrap > (*(FrameStore**)arg2)->frame_num_wrap)
    return -1;
  else
    return 0;
}


/*!
 ************************************************************************
 * \brief
 *    compares two frame stores by lt_pic_num for qsort in descending order
 *
 ************************************************************************
 */
static int compare_fs_by_lt_pic_idx_asc( const void *arg1, const void *arg2 )
{
  if ( (*(FrameStore**)arg1)->long_term_frame_idx < (*(FrameStore**)arg2)->long_term_frame_idx)
    return -1;
  if ( (*(FrameStore**)arg1)->long_term_frame_idx > (*(FrameStore**)arg2)->long_term_frame_idx)
    return 1;
  else
    return 0;
}


/*!
 ************************************************************************
 * \brief
 *    compares two stored pictures by poc for qsort in ascending order
 *
 ************************************************************************
 */
static int compare_pic_by_poc_asc( const void *arg1, const void *arg2 )
{
  if ( (*(StorablePicture**)arg1)->poc < (*(StorablePicture**)arg2)->poc)
    return -1;
  if ( (*(StorablePicture**)arg1)->poc > (*(StorablePicture**)arg2)->poc)
    return 1;
  else
    return 0;
}


/*!
 ************************************************************************
 * \brief
 *    compares two stored pictures by poc for qsort in descending order
 *
 ************************************************************************
 */
static int compare_pic_by_poc_desc( const void *arg1, const void *arg2 )
{
  if ( (*(StorablePicture**)arg1)->poc < (*(StorablePicture**)arg2)->poc)
    return 1;
  if ( (*(StorablePicture**)arg1)->poc > (*(StorablePicture**)arg2)->poc)
    return -1;
  else
    return 0;
}


/*!
 ************************************************************************
 * \brief
 *    compares two frame stores by poc for qsort in ascending order
 *
 ************************************************************************
 */
static int compare_fs_by_poc_asc( const void *arg1, const void *arg2 )
{
  if ( (*(FrameStore**)arg1)->poc < (*(FrameStore**)arg2)->poc)
    return -1;
  if ( (*(FrameStore**)arg1)->poc > (*(FrameStore**)arg2)->poc)
    return 1;
  else
    return 0;
}


/*!
 ************************************************************************
 * \brief
 *    compares two frame stores by poc for qsort in descending order
 *
 ************************************************************************
 */
static int compare_fs_by_poc_desc( const void *arg1, const void *arg2 )
{
  if ( (*(FrameStore**)arg1)->poc < (*(FrameStore**)arg2)->poc)
    return 1;

⌨️ 快捷键说明

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