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

📄 recpicbuffer.cpp

📁 JMVM MPEG MVC/3DAV 测试平台 国际通用标准
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/*
********************************************************************************

NOTE - One of the two copyright statements below may be chosen
that applies for the software.

********************************************************************************

This software module was originally developed by

Heiko Schwarz    (Fraunhofer HHI),
Tobias Hinz      (Fraunhofer HHI),
Karsten Suehring (Fraunhofer HHI)

in the course of development of the ISO/IEC 14496-10:2005 Amd.1 (Scalable Video
Coding) for reference purposes and its performance may not have been optimized.
This software module is an implementation of one or more tools as specified by
the ISO/IEC 14496-10:2005 Amd.1 (Scalable Video Coding).

Those intending to use this software module in products are advised that its
use may infringe existing patents. ISO/IEC have no liability for use of this
software module or modifications thereof.

Assurance that the originally developed software module can be used
(1) in the ISO/IEC 14496-10:2005 Amd.1 (Scalable Video Coding) once the
ISO/IEC 14496-10:2005 Amd.1 (Scalable Video Coding) has been adopted; and
(2) to develop the ISO/IEC 14496-10:2005 Amd.1 (Scalable Video Coding): 

To the extent that Fraunhofer HHI owns patent rights that would be required to
make, use, or sell the originally developed software module or portions thereof
included in the ISO/IEC 14496-10:2005 Amd.1 (Scalable Video Coding) in a
conforming product, Fraunhofer HHI will assure the ISO/IEC that it is willing
to negotiate licenses under reasonable and non-discriminatory terms and
conditions with applicants throughout the world.

Fraunhofer HHI retains full right to modify and use the code for its own
purpose, assign or donate the code to a third party and to inhibit third
parties from using the code for products that do not conform to MPEG-related
ITU Recommendations and/or ISO/IEC International Standards. 

This copyright notice must be included in all copies or derivative works.
Copyright (c) ISO/IEC 2005. 

********************************************************************************

COPYRIGHT AND WARRANTY INFORMATION

Copyright 2005, International Telecommunications Union, Geneva

The Fraunhofer HHI hereby donate this source code to the ITU, with the following
understanding:
1. Fraunhofer HHI retain the right to do whatever they wish with the
contributed source code, without limit.
2. Fraunhofer HHI retain full patent rights (if any exist) in the technical
content of techniques and algorithms herein.
3. The ITU shall make this code available to anyone, free of license or
royalty fees.

DISCLAIMER OF WARRANTY

These software programs are available to the user without any license fee or
royalty on an "as is" basis. The ITU disclaims any and all warranties, whether
express, implied, or statutory, including any implied warranties of
merchantability or of fitness for a particular purpose. In no event shall the
contributor or the ITU be liable for any incidental, punitive, or consequential
damages of any kind whatsoever arising from the use of these programs.

This disclaimer of warranty extends to the user of these programs and user's
customers, employees, agents, transferees, successors, and assigns.

The ITU does not represent or warrant that the programs furnished hereunder are
free of infringement of any third-party patents. Commercial implementations of
ITU-T Recommendations, including shareware, may be subject to royalty fees to
patent holders. Information regarding the ITU-T patent policy is available from 
the ITU Web site at http://www.itu.int.

THIS IS NOT A GRANT OF PATENT RIGHTS - SEE THE ITU-T PATENT POLICY.

********************************************************************************
*/



#include "H264AVCEncoderLib.h"
#include "H264AVCCommonLib.h"
#include "RecPicBuffer.h"
#include "PicEncoder.h"  //JVT-W056  Samsung

H264AVC_NAMESPACE_BEGIN


RecPicBufUnit::RecPicBufUnit()
: m_iPoc                  ( MSYS_INT_MIN )
, m_uiFrameNum            ( MSYS_UINT_MAX )
, m_bExisting             ( false )
, m_bNeededForReference   ( false )
, m_bOutputted            ( false )
, m_pcReconstructedFrame  ( NULL )
, m_pcMbDataCtrl          ( NULL )
, m_pcPicBuffer           ( NULL )
, m_uiViewId              ( 0 )
{
}


RecPicBufUnit::~RecPicBufUnit()
{
  if( m_pcMbDataCtrl )
  {
    m_pcMbDataCtrl->uninit();
  }
  if( m_pcReconstructedFrame )
  {
    m_pcReconstructedFrame->uninit();
  }
  delete m_pcMbDataCtrl;
  delete m_pcReconstructedFrame;
}


ErrVal
RecPicBufUnit::create( RecPicBufUnit*&              rpcRecPicBufUnit,
                       YuvBufferCtrl&               rcYuvBufferCtrlFullPel,
                       YuvBufferCtrl&               rcYuvBufferCtrlHalfPel,
                       const SequenceParameterSet&  rcSPS )
{
  rpcRecPicBufUnit = new RecPicBufUnit();
  ROF( rpcRecPicBufUnit );

  rpcRecPicBufUnit->m_pcReconstructedFrame  = new IntFrame  ( rcYuvBufferCtrlFullPel,
                                                              rcYuvBufferCtrlHalfPel );
  rpcRecPicBufUnit->m_pcMbDataCtrl          = new MbDataCtrl();
  ROF( rpcRecPicBufUnit->m_pcReconstructedFrame );
  ROF( rpcRecPicBufUnit->m_pcMbDataCtrl );
    
  RNOK( rpcRecPicBufUnit->m_pcReconstructedFrame  ->init() );
  RNOK( rpcRecPicBufUnit->m_pcMbDataCtrl          ->init( rcSPS ) );

  rpcRecPicBufUnit->m_pcReconstructedFrame->setRecPicBufUnit( rpcRecPicBufUnit );

  return Err::m_nOK;
}


ErrVal
RecPicBufUnit::destroy()
{
  delete this;
  return Err::m_nOK;
}


ErrVal
RecPicBufUnit::init( SliceHeader* pcSliceHeader,
                     PicBuffer*   pcPicBuffer )
{
  m_iPoc                  = pcSliceHeader->getPoc();
  m_uiFrameNum            = pcSliceHeader->getFrameNum();
  m_bExisting             = true;
  m_bNeededForReference   = pcSliceHeader->getNalRefIdc() != NAL_REF_IDC_PRIORITY_LOWEST;
  m_bOutputted            = false;
  m_pcPicBuffer           = pcPicBuffer;
  m_multiviewRefDirection = NOT_MULTIVIEW;


  m_pcReconstructedFrame->setPOC( m_iPoc );

  m_uiViewId              = pcSliceHeader->getViewId();
  m_pcReconstructedFrame->setViewId(pcSliceHeader->getViewId());

  return Err::m_nOK;
}


ErrVal
RecPicBufUnit::initNonEx( Int   iPoc,
                          UInt  uiFrameNum )
{
  m_iPoc                  = iPoc;
  m_uiFrameNum            = uiFrameNum;
  m_bExisting             = false;
  m_bNeededForReference   = true;
  m_bOutputted            = false;
  m_pcPicBuffer           = NULL;
  m_multiviewRefDirection = NOT_MULTIVIEW;
  m_pcReconstructedFrame->setPOC( m_iPoc );

  return Err::m_nOK;
}


ErrVal
RecPicBufUnit::uninit()
{
  m_iPoc                  = MSYS_INT_MIN;
  m_uiFrameNum            = MSYS_UINT_MAX;
  m_bExisting             = false;
  m_bNeededForReference   = false;
  m_bOutputted            = false;
  m_pcPicBuffer           = NULL;
  m_multiviewRefDirection = NOT_MULTIVIEW;


  return Err::m_nOK;
}


ErrVal
RecPicBufUnit::markNonRef()
{
  ROF( m_bNeededForReference );
  m_bNeededForReference = false;
  return Err::m_nOK;
}


ErrVal
RecPicBufUnit::markOutputted()
{
  ROT( m_bOutputted );
  m_bOutputted  = true;
  m_pcPicBuffer = NULL;
  return Err::m_nOK;
}














RecPicBuffer::RecPicBuffer()
: m_bInitDone               ( false )
, m_pcYuvBufferCtrlFullPel  ( NULL )
, m_pcYuvBufferCtrlHalfPel  ( NULL )
, m_uiNumRefFrames          ( 0 )
, m_uiMaxFrameNum           ( 0 )
, m_uiLastRefFrameNum       ( MSYS_UINT_MAX )
, m_pcCurrRecPicBufUnit     ( NULL )
, m_codeAsVFrame          ( false )

{
}

RecPicBuffer::~RecPicBuffer()
{
}

ErrVal
RecPicBuffer::create( RecPicBuffer*& rpcRecPicBuffer )
{
  rpcRecPicBuffer = new RecPicBuffer();
  ROF( rpcRecPicBuffer );
  return Err::m_nOK;
}

ErrVal
RecPicBuffer::destroy()
{
  ROT( m_bInitDone );
  delete this;
  return Err::m_nOK;
}


ErrVal
RecPicBuffer::init( YuvBufferCtrl*  pcYuvBufferCtrlFullPel,
                    YuvBufferCtrl*  pcYuvBufferCtrlHalfPel )
{
  ROT( m_bInitDone );
  ROF( pcYuvBufferCtrlFullPel );
  ROF( pcYuvBufferCtrlHalfPel );

  m_pcYuvBufferCtrlFullPel  = pcYuvBufferCtrlFullPel;
  m_pcYuvBufferCtrlHalfPel  = pcYuvBufferCtrlHalfPel;
  m_uiNumRefFrames          = 0;
  m_uiMaxFrameNum           = 0;
  m_uiLastRefFrameNum       = MSYS_UINT_MAX;
  m_pcCurrRecPicBufUnit     = NULL;
  m_bInitDone               = true;
  m_codeAsVFrame            = false;

  return Err::m_nOK;
}


ErrVal
RecPicBuffer::initSPS( const SequenceParameterSet& rcSPS )
{
  ROF( m_bInitDone );

  UInt uiMaxFramesInDPB = rcSPS.getMaxDPBSize();
  RNOK( xCreateData( uiMaxFramesInDPB, rcSPS ) );
  m_uiNumRefFrames      = rcSPS.getNumRefFrames();
  m_uiMaxFrameNum       = ( 1 << ( rcSPS.getLog2MaxFrameNum() ) );

  return Err::m_nOK;
}


ErrVal
RecPicBuffer::uninit()
{
  ROF( m_bInitDone );

  RNOK( xDeleteData() );

  m_pcYuvBufferCtrlFullPel  = NULL;
  m_pcYuvBufferCtrlHalfPel  = NULL;
  m_uiNumRefFrames          = 0;
  m_uiMaxFrameNum           = 0;
  m_uiLastRefFrameNum       = MSYS_UINT_MAX;
  m_bInitDone               = false;
  m_codeAsVFrame            = false;

  return Err::m_nOK;
}


ErrVal
RecPicBuffer::clear( PicBufferList& rcOutputList,
                     PicBufferList& rcUnusedList )
{
  RNOK( xClearOutputAll( rcOutputList, rcUnusedList ) );
  return Err::m_nOK;
}


RecPicBufUnit*
RecPicBuffer::getLastUnit()
{
  ROTRS( m_cUsedRecPicBufUnitList.empty(), NULL );
  return m_cUsedRecPicBufUnitList.back();
}


RecPicBufUnit*
RecPicBuffer::getCurrUnit()
{
  return m_pcCurrRecPicBufUnit;
}


RecPicBufUnit*
RecPicBuffer::getRecPicBufUnit( Int iPoc )
{
  RecPicBufUnit*            pcRecPicBufUnit = 0;
  RecPicBufUnitList::iterator iter  = m_cUsedRecPicBufUnitList.begin();
  RecPicBufUnitList::iterator end   = m_cUsedRecPicBufUnitList.end  ();
  for( ; iter != end; iter++ )
  {
    if( (*iter)->getPoc() == iPoc )
    {
      pcRecPicBufUnit = *iter;
      break;
    }
  }
  return pcRecPicBufUnit;
}


ErrVal
RecPicBuffer::initCurrRecPicBufUnit( RecPicBufUnit*&  rpcCurrRecPicBufUnit,
                                     PicBuffer*       pcPicBuffer,
                                     SliceHeader*     pcSliceHeader,
                                     PicBufferList&   rcOutputList,
                                     PicBufferList&   rcUnusedList, 
									 MultiviewReferenceDirection refDirection)
{
  ROF( m_bInitDone );
  ROF( pcPicBuffer );
  ROF( pcSliceHeader );

  //===== check for missing pictures =====
  if (NOT_MULTIVIEW == refDirection) {
    // Do not check for missing pics if we are initializing for a 
    // multiview reference because the frame numbers are not meaningful
    // for multiview references and errors will result.
    RNOK( xCheckMissingPics( pcSliceHeader, rcOutputList, rcUnusedList ) );
  }

  

  //===== initialize current DPB unit =====
  RNOK( m_pcCurrRecPicBufUnit->init( pcSliceHeader, pcPicBuffer ) );

  //===== load picture =====
  RNOK( m_pcCurrRecPicBufUnit->getRecFrame()->load( pcPicBuffer ) );


  m_pcCurrRecPicBufUnit->SetMultiviewReferenceDirection(refDirection);

// the set of refDirection to NOT_MULTIVIEW has been done too much times, many of them are unnecessary
  //===== set reference =====
  rpcCurrRecPicBufUnit = m_pcCurrRecPicBufUnit;

  return Err::m_nOK;
}


ErrVal
RecPicBuffer::store( RecPicBufUnit*   pcRecPicBufUnit,
                     SliceHeader*     pcSliceHeader,
                     PicBufferList&   rcOutputList,
                     PicBufferList&   rcUnusedList, 
					 MultiviewReferenceDirection refDirection
					 )
{
  RNOK( xStorePicture( pcRecPicBufUnit, rcOutputList, rcUnusedList, pcSliceHeader, pcSliceHeader->isIdrNalUnit() ) );
  
  if( pcRecPicBufUnit->isNeededForRef()
      && (refDirection == NOT_MULTIVIEW) )
    { // Do not update this for multiview references because multiview
      // references will be pulled out immediately after encoding/
      // Also, the frame numbers for multiview references are not very
      // meaningful and errors will result if you put them.

    m_uiLastRefFrameNum = pcRecPicBufUnit->getFrameNum();
  }

  return Err::m_nOK;
}

// JVT-V043 and some cleanup
ErrVal
RecPicBuffer::getRefLists( RefFrameList&  rcList0,
                           RefFrameList&  rcList1,
                           SliceHeader&   rcSliceHeader )

⌨️ 快捷键说明

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