H.264參考幀列表管理分析 —— JM中相關函數解析(中)

本文解析幾個與參考幀重排序的相關函數。

  1. /*! 
  2.  ************************************************************************ 
  3.  * \brief 
  4.  *    Reordering process for short-term reference pictures 短期參考幀重排序 
  5.  * 
  6.  ************************************************************************ 
  7.  */  
  8. static void reorder_short_term(StorablePicture **RefPicListX, int num_ref_idx_lX_active_minus1, int picNumLX, int *refIdxLX)  
  9. {  
  10.   int cIdx, nIdx;  
  11.   
  12.   StorablePicture *picLX;  
  13.   
  14.   picLX = get_short_term_pic(picNumLX); //!< 根據給定的picNumLX獲取相應的短期參考幀  
  15.   
  16.   for( cIdx = num_ref_idx_lX_active_minus1+1; cIdx > *refIdxLX; cIdx-- )  
  17.     RefPicListX[ cIdx ] = RefPicListX[ cIdx - 1];    //!< 將refIdxLX位置之後的參考幀依次後移  
  18.     
  19.   RefPicListX[ (*refIdxLX)++ ] = picLX; //!< 將給定的picNumLX短期參考幀存至refIdxLX位置  
  20.   
  21.   nIdx = *refIdxLX;  
  22.   
  23.   for( cIdx = *refIdxLX; cIdx <= num_ref_idx_lX_active_minus1+1; cIdx++ )  
  24.     if (RefPicListX[ cIdx ])  
  25.       if( (RefPicListX[ cIdx ]->is_long_term ) ||  (RefPicListX[ cIdx ]->pic_num != picNumLX ))    //!< 該操作可將參考幀列表中重複的序號爲picNumLX的參考幀覆蓋掉  
  26.         RefPicListX[ nIdx++ ] = RefPicListX[ cIdx ];  
  27.   
  28. }  

 

  1.  /*! 
  2.  ************************************************************************ 
  3.  * \brief 
  4.  *    Returns short term pic with given picNum 返回給定picNum序號的短期參考幀 
  5.  * 
  6.  ************************************************************************ 
  7.  */  
  8. static StorablePicture*  get_short_term_pic(int picNum)  
  9. {  
  10.   unsigned i;  
  11.   
  12.   for (i=0; i<dpb.ref_frames_in_buffer; i++) //!< 遍歷dpb中的參考幀  
  13.   {  
  14.     if (img->structure==FRAME) //!< 幀模式  
  15.     {  
  16.       if (dpb.fs_ref[i]->is_reference == 3)  
  17.         if ((!dpb.fs_ref[i]->frame->is_long_term)&&(dpb.fs_ref[i]->frame->pic_num == picNum))  
  18.           return dpb.fs_ref[i]->frame; //!< 找到pic_num等於picNum且不是長期參考幀的短期參考幀,返回  
  19.     }  
  20.     else //!< 場模式(略過)  
  21.     {  
  22.       if (dpb.fs_ref[i]->is_reference & 1)  
  23.         if ((!dpb.fs_ref[i]->top_field->is_long_term)&&(dpb.fs_ref[i]->top_field->pic_num == picNum))  
  24.           return dpb.fs_ref[i]->top_field;  
  25.       if (dpb.fs_ref[i]->is_reference & 2)  
  26.         if ((!dpb.fs_ref[i]->bottom_field->is_long_term)&&(dpb.fs_ref[i]->bottom_field->pic_num == picNum))  
  27.           return dpb.fs_ref[i]->bottom_field;  
  28.     }  
  29.   }  
  30. //  return NULL;  
  31.   return no_reference_picture;  
  32. }  


 

  1. /*! 
  2.  ************************************************************************ 
  3.  * \brief 
  4.  *    Reordering process for long-term reference pictures 長期參考幀重排序 
  5.  * 
  6.  ************************************************************************ 
  7.  */  
  8. static void reorder_long_term(StorablePicture **RefPicListX, int num_ref_idx_lX_active_minus1, int LongTermPicNum, int *refIdxLX)  
  9. {  
  10.   int cIdx, nIdx;  
  11.   
  12.   StorablePicture *picLX;  
  13.   
  14.   picLX = get_long_term_pic(LongTermPicNum); //!< 獲取給定LongTermPicNum的相應的長期參考幀  
  15.   
  16.   for( cIdx = num_ref_idx_lX_active_minus1+1; cIdx > *refIdxLX; cIdx-- )  
  17.     RefPicListX[ cIdx ] = RefPicListX[ cIdx - 1]; //!< 將refIdxLX之後的參考幀依次右移  
  18.     
  19.   RefPicListX[ (*refIdxLX)++ ] = picLX; //!< 將LongTermPicNum對應的長期參考幀存至refIdxLX位置  
  20.   
  21.   nIdx = *refIdxLX;  
  22.   
  23.   for( cIdx = *refIdxLX; cIdx <= num_ref_idx_lX_active_minus1+1; cIdx++ )  
  24.     if (RefPicListX[ cIdx ])  
  25.       if( (!RefPicListX[ cIdx ]->is_long_term ) ||  (RefPicListX[ cIdx ]->long_term_pic_num != LongTermPicNum )) //!< 可將序號爲LongTermPicNum重複的參考幀覆蓋掉  
  26.         RefPicListX[ nIdx++ ] = RefPicListX[ cIdx ];  
  27. }  
  1. <pre class="cpp" name="code">/*! 
  2.  ************************************************************************ 
  3.  * \brief 
  4.  *    Returns long term pic with given LongtermPicNum 
  5.  * 
  6.  ************************************************************************ 
  7.  */  
  8. static StorablePicture*  get_long_term_pic(int LongtermPicNum)  
  9. {  
  10.   unsigned i;  
  11.   
  12.   for (i=0; i<dpb.ltref_frames_in_buffer; i++) //!< 遍歷dpb中所有的長期參考幀  
  13.   {  
  14.     if (img->structure==FRAME) //!< 幀模式  
  15.     {  
  16.       if (dpb.fs_ltref[i]->is_reference == 3)  
  17.         if ((dpb.fs_ltref[i]->frame->is_long_term)&&(dpb.fs_ltref[i]->frame->long_term_pic_num == LongtermPicNum))  
  18.           return dpb.fs_ltref[i]->frame; //!< 找到long_term_pic_num等於LongtermPicNum的長期參考幀,返回  
  19.     }  
  20.     else //!< 場模式(略過)  
  21.     {  
  22.       if (dpb.fs_ltref[i]->is_reference & 1)  
  23.         if ((dpb.fs_ltref[i]->top_field->is_long_term)&&(dpb.fs_ltref[i]->top_field->long_term_pic_num == LongtermPicNum))  
  24.           return dpb.fs_ltref[i]->top_field;  
  25.       if (dpb.fs_ltref[i]->is_reference & 2)  
  26.         if ((dpb.fs_ltref[i]->bottom_field->is_long_term)&&(dpb.fs_ltref[i]->bottom_field->long_term_pic_num == LongtermPicNum))  
  27.           return dpb.fs_ltref[i]->bottom_field;  
  28.     }  
  29.   }  
  30.   return NULL;  
  31. }</pre><pre class="cpp" name="code"> </pre>  
  32. <pre></pre>  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章