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

📄 mbuffer.c

📁 This program can encode the YUV vdieo format to H.264 and decode it.
💻 C
📖 第 1 页 / 共 5 页
字号:
 * \param p
 *    Picture to be freed
 *
 ************************************************************************
 */
void free_storable_picture(StorablePicture* p)
{
  int nplane;
  if (p)
  {
    if (p->ref_idx)
    {
      free_mem3D ((byte***)p->ref_idx, 2);
      p->ref_idx = NULL;
    }

    if (p->ref_pic_id)
    {
      free_mem3Dint64 (p->ref_pic_id, 6);
      p->ref_pic_id = NULL;
    }
    if (p->ref_id)
    {
      free_mem3Dint64 (p->ref_id, 6);
      p->ref_id = NULL;
    }
    if (p->mv)
    {
      free_mem4Dshort (p->mv, 2, p->size_y / BLOCK_SIZE);
      p->mv = NULL;
    }

    if( IS_INDEPENDENT(input) )
    {
      for( nplane=0; nplane<MAX_PLANE; nplane++ )
      {
        if (p->ref_idx_JV[nplane])
        {
          free_mem3D ((byte***)p->ref_idx_JV[nplane], 2);
          p->ref_idx_JV[nplane] = NULL;
        }
    
        if (p->ref_pic_id_JV[nplane])
        {
          free_mem3Dint64 (p->ref_pic_id_JV[nplane], 6);
          p->ref_pic_id_JV[nplane] = NULL;
        }
        if (p->ref_id_JV[nplane])
        {
          free_mem3Dint64 (p->ref_id_JV[nplane], 6);
          p->ref_id_JV[nplane] = NULL;
        }
        if (p->mv_JV[nplane])
        {
          free_mem4Dshort (p->mv_JV[nplane], 2, p->size_y / BLOCK_SIZE);
          p->mv_JV[nplane] = NULL;
        }
      }
    }

    if (p->moving_block)
    {
      free_mem2D (p->moving_block);
      p->moving_block=NULL;
    }

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

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

    if( IS_INDEPENDENT(input) )
    {
      if (p->imgY_sub)
      {
        free_mem4Dpel (p->imgY_sub,4,4);
        p->imgY_sub=NULL;
      }
      if (p->imgUV_sub)
      {
        free_mem5Dpel (p->imgUV_sub, 2, 4, 4 );
        p->imgUV_sub = NULL;
      }
      p->p_imgY_sub[0] = NULL;
      p->p_imgY_sub[1] = NULL;
      p->p_imgY_sub[2] = NULL;
    }
    else
    {
      if (p->imgY_sub)
      {
        free_mem4Dpel (p->imgY_sub,4,4);
        p->imgY_sub=NULL;
      }
      if ( p->imgUV_sub && img->yuv_format != YUV400 && input->ChromaMCBuffer )
      {
        if ( img->yuv_format == YUV420 )
        {
          free_mem5Dpel (p->imgUV_sub, 2, 8, 8 );
          p->imgUV_sub = NULL;
        }
        else if ( img->yuv_format == YUV422 )
        {
          free_mem5Dpel (p->imgUV_sub, 2, 4, 8 );
          p->imgUV_sub = NULL;
        }
        else
        { // YUV444
          free_mem5Dpel (p->imgUV_sub, 2, 4, 4 );
          p->imgUV_sub = NULL;
        }
      }
    }

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

    if (p->mb_field)
    {
      free(p->mb_field);
      p->mb_field=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, 4, 4);
      fs->frame->imgY_sub=NULL;
    }

    if (fs->frame->ref_pic_id)
    {
      free_mem3Dint64 (fs->frame->ref_pic_id, 6);
      fs->frame->ref_pic_id = NULL;
    }
    if (fs->frame->ref_id)
    {
      free_mem3Dint64 (fs->frame->ref_id, 6);
      fs->frame->ref_id = NULL;
    }
  }

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

    if (fs->top_field->ref_pic_id)
    {
      free_mem3Dint64 (fs->top_field->ref_pic_id, 6);
      fs->top_field->ref_pic_id = NULL;
    }
    if (fs->top_field->ref_id)
    {
      free_mem3Dint64 (fs->top_field->ref_id, 6);
      fs->top_field->ref_id = NULL;
    }

  }
  if (fs->bottom_field)
  {
    if (fs->bottom_field->imgY_sub)
    {
      free_mem4Dpel (fs->bottom_field->imgY_sub, 4, 4);
      fs->bottom_field->imgY_sub=NULL;
    }
    if (fs->bottom_field->ref_pic_id)
    {
      free_mem3Dint64 (fs->bottom_field->ref_pic_id, 6);
      fs->bottom_field->ref_pic_id = NULL;
    }
    if (fs->bottom_field->ref_id)
    {
      free_mem3Dint64 (fs->bottom_field->ref_id, 6);
      fs->bottom_field->ref_id = NULL;
    }
  }

}


/*!
 ************************************************************************
 * \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;
  if ( (*(FrameStore**)arg1)->poc > (*(FrameStore**)arg2)->poc)
    return -1;
  else
    return 0;
}


/*!
 ************************************************************************
 * \brief
 *    returns true, if picture is short term reference picture
 *
 ************************************************************************
 */
int is_short_ref(StorablePicture *s)
{
  return ((s->used_for_reference) && (!(s->is_long_term)));
}


/*!
 ************************************************************************
 * \brief
 *    returns true, if picture is long term reference picture
 *
 ************************************************************************
 */
int is_long_ref(StorablePicture *s)
{
  return ((s->used_for_reference) && (s->is_long_term));
}


/*!
 ************************************************************************
 * \brief
 *    Generates a alternating field list from a given FrameStore list
 *
 ************************************************************************
 */
static void gen_pic_list_from_frame_list(PictureStructure currStrcture, FrameStore **fs_list, int list_idx, StorablePicture **list, int *list_size, int long_term)
{
  int top_idx = 0;
  int bot_idx = 0;

  int (*is_ref)(StorablePicture *s);

  if (long_term)
    is_ref=is_long_ref;

⌨️ 快捷键说明

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