source: 3DVCSoftware/branches/0.3-poznan-univ/source/Lib/TLibEncoder/TEncTop.cpp @ 461

Last change on this file since 461 was 48, checked in by poznan-univ, 13 years ago

some bug fix on high level syntax
fixed some compiler warning issues under windows and linux

  • Property svn:eol-style set to native
File size: 27.4 KB
Line 
1/* The copyright in this software is being made available under the BSD
2 * License, included below. This software may be subject to other third party
3 * and contributor rights, including patent rights, and no such rights are
4 * granted under this license.
5 *
6 * Copyright (c) 2010-2011, ISO/IEC
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright notice,
13 *    this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above copyright notice,
15 *    this list of conditions and the following disclaimer in the documentation
16 *    and/or other materials provided with the distribution.
17 *  * Neither the name of the ISO/IEC nor the names of its contributors may
18 *    be used to endorse or promote products derived from this software without
19 *    specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34
35
36/** \file     TEncTop.cpp
37    \brief    encoder class
38*/
39
40#include "../TLibCommon/CommonDef.h"
41#include "TEncTop.h"
42
43#include "TEncGOP.h"
44#include "../../App/TAppEncoder/TAppEncTop.h"
45
46// ====================================================================================================================
47// Constructor / destructor / create / destroy
48// ====================================================================================================================
49
50TEncTop::TEncTop()
51{
52  m_iPOCLast          = -1;
53  m_iNumPicRcvd       =  0;
54  m_uiNumAllPicCoded  =  0;
55  m_pppcRDSbacCoder   =  NULL;
56  m_pppcBinCoderCABAC =  NULL;
57  m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC );
58#if ENC_DEC_TRACE
59  g_hTrace = fopen( "TraceEnc.txt", "wb" );
60  g_bJustDoIt = g_bEncDecTraceDisable;
61  g_nSymbolCounter = 0;
62#endif
63  m_bSeqFirst = true;
64  m_iFrameNumInCodingOrder = 0;
65   
66#if POZNAN_MP
67  m_pcMP=NULL;
68#endif
69
70}
71
72TEncTop::~TEncTop()
73{
74#if ENC_DEC_TRACE
75  fclose( g_hTrace );
76#endif
77}
78
79Void TEncTop::create ()
80{
81  // initialize global variables
82  if(m_uiViewId<1 && !m_bIsDepth)
83    initROM();
84
85  // create processing unit classes
86  m_cPicEncoder.        create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight );
87  m_cSliceEncoder.      create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
88  m_cCuEncoder.         create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
89#if MTK_SAO
90  if (m_bUseSAO)
91  {
92    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
93    m_cEncSAO.createEncBuffer();
94  }
95#endif
96  m_cAdaptiveLoopFilter.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
97  m_cLoopFilter.        create( g_uiMaxCUDepth );
98#if DEPTH_MAP_GENERATION
99  m_cDepthMapGenerator. create( false, getSourceWidth(), getSourceHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement, PDM_SUB_SAMP_EXP_X(m_uiPredDepthMapGeneration), PDM_SUB_SAMP_EXP_Y(m_uiPredDepthMapGeneration) );
100#endif
101#if HHI_INTER_VIEW_RESIDUAL_PRED
102  m_cResidualGenerator. create( false, getSourceWidth(), getSourceHeight(), g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiBitDepth + g_uiBitIncrement );
103#endif
104
105#if POZNAN_MP
106  m_pcMP                                = NULL;
107#endif
108
109#if MQT_BA_RA && MQT_ALF_NPASS
110  if(m_bUseALF)
111  {
112    m_cAdaptiveLoopFilter.createAlfGlobalBuffers(m_iALFEncodePassReduction);
113  }
114#endif
115
116  // if SBAC-based RD optimization is used
117  if( m_bUseSBACRD )
118  {
119    UInt uiNumCEnc = 1 + Max( g_uiMaxCUDepth, AO_MAX_DEPTH ); // HS: prevents crash in SAO for small maximum CU sizes
120    m_pppcRDSbacCoder = new TEncSbac** [uiNumCEnc];
121    m_pppcBinCoderCABAC = new TEncBinCABAC** [uiNumCEnc];
122
123    for ( Int iDepth = 0; iDepth < uiNumCEnc; iDepth++ )
124    {
125      m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
126      m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
127
128      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
129      {
130        m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
131        m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
132        m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
133      }
134    }
135  }
136
137#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
138  if( g_aacWedgeLists.empty() && m_bUseDMM && m_bIsDepth )
139  {
140    initWedgeLists();
141  }
142#endif
143}
144
145Void TEncTop::destroy ()
146{
147#if MQT_BA_RA && MQT_ALF_NPASS
148  if(m_bUseALF)
149  {
150    m_cAdaptiveLoopFilter.destroyAlfGlobalBuffers();
151  }
152#endif
153
154  // destroy processing unit classes
155  m_cPicEncoder.        destroy();
156  m_cSliceEncoder.      destroy();
157  m_cCuEncoder.         destroy();
158#if MTK_SAO
159  if (m_cSPS.getUseSAO())
160  {
161    m_cEncSAO.destroy();
162    m_cEncSAO.destoryEncBuffer();
163  }
164#endif
165  m_cAdaptiveLoopFilter.destroy();
166  m_cLoopFilter.        destroy();
167#if DEPTH_MAP_GENERATION
168  m_cDepthMapGenerator. destroy();
169#endif
170#if HHI_INTER_VIEW_RESIDUAL_PRED
171  m_cResidualGenerator. destroy();
172#endif
173
174#if POZNAN_MP
175  m_pcMP=NULL;
176#endif
177
178  // SBAC RD
179  if( m_bUseSBACRD )
180  {
181    Int iDepth;
182    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
183    {
184      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
185      {
186        delete m_pppcRDSbacCoder[iDepth][iCIIdx];
187        delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
188      }
189    }
190
191    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
192    {
193      delete [] m_pppcRDSbacCoder[iDepth];
194      delete [] m_pppcBinCoderCABAC[iDepth];
195    }
196
197    delete [] m_pppcRDSbacCoder;
198    delete [] m_pppcBinCoderCABAC;
199  }
200
201  // destroy ROM
202  if(m_uiViewId<1 && !m_bIsDepth)
203    destroyROM();
204
205  return;
206}
207
208Void TEncTop::init( TAppEncTop* pcTAppEncTop )
209{
210  UInt *aTable4=NULL, *aTable8=NULL;
211#if QC_MOD_LCEC
212  UInt* aTableLastPosVlcIndex=NULL;
213#endif
214  // initialize SPS
215  xInitSPS();
216
217#if CONSTRAINED_INTRA_PRED
218  // initialize PPS
219  xInitPPS();
220#endif
221
222#if POZNAN_MP
223  m_pcMP = pcTAppEncTop->getMP();
224#endif
225
226  // initialize processing unit classes
227  m_cPicEncoder.  init( this );
228  m_cSliceEncoder.init( this );
229  m_cCuEncoder.   init( this );
230
231  m_pcTAppEncTop = pcTAppEncTop;
232#if DEPTH_MAP_GENERATION
233  m_cDepthMapGenerator.init( (TComPrediction*)this->getPredSearch(), m_pcTAppEncTop->getSPSAccess(), m_pcTAppEncTop->getAUPicAccess() );
234#endif
235#if HHI_INTER_VIEW_RESIDUAL_PRED
236  m_cResidualGenerator.init( &m_cTrQuant, &m_cDepthMapGenerator );
237#endif
238
239  // initialize transform & quantization class
240  m_pcCavlcCoder = getCavlcCoder();
241#if !CAVLC_COEF_LRG_BLK
242  aTable8 = m_pcCavlcCoder->GetLP8Table();
243#endif
244  aTable4 = m_pcCavlcCoder->GetLP4Table();
245#if QC_MOD_LCEC
246  aTableLastPosVlcIndex=m_pcCavlcCoder->GetLastPosVlcIndexTable();
247
248  m_cTrQuant.init( g_uiMaxCUWidth, g_uiMaxCUHeight, 1 << m_uiQuadtreeTULog2MaxSize, m_iSymbolMode, aTable4, aTable8,
249    aTableLastPosVlcIndex, m_bUseRDOQ, true );
250#else
251  m_cTrQuant.init( g_uiMaxCUWidth, g_uiMaxCUHeight, 1 << m_uiQuadtreeTULog2MaxSize, m_iSymbolMode, aTable4, aTable8, m_bUseRDOQ, true );
252#endif
253
254  // initialize encoder search class
255  m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() );
256  m_cSeqIter  = TEncSeqStructure::Iterator( m_cSequenceStructure, 0, 0 );
257  m_bPicWaitingForCoding = false ;
258
259#if MQT_ALF_NPASS
260  if(m_bUseALF)
261  {
262    m_cAdaptiveLoopFilter.setALFEncodePassReduction( m_iALFEncodePassReduction );
263  }
264#endif
265}
266
267// ====================================================================================================================
268// Public member functions
269// ====================================================================================================================
270
271Void TEncTop::deletePicBuffer()
272{
273  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
274  Int iSize = Int( m_cListPic.size() );
275
276  for ( Int i = 0; i < iSize; i++ )
277  {
278    TComPic* pcPic = *(iterPic++);
279
280    pcPic->destroy();
281    delete pcPic;
282    pcPic = NULL;
283  }
284}
285
286/**
287 - Application has picture buffer list with size of GOP + 1
288 - Picture buffer list acts like as ring buffer
289 - End of the list has the latest picture
290 .
291 \param   bEos                true if end-of-sequence is reached
292 \param   pcPicYuvOrg         original YUV picture
293 \retval  rcListPicYuvRecOut  list of reconstruction YUV pictures
294 \retval  rcListBitstreamOut  list of output bitstreams
295 \retval  iNumEncoded         number of encoded pictures
296 */
297Void TEncTop::encode( bool bEos, std::map<PicOrderCnt, TComPicYuv*>& rcMapPicYuvRecOut, TComBitstream* pcBitstreamOut, Bool& bNewPicNeeded )
298{
299
300  //  TComBitstream*  pcBitstreamOut ;
301  TComPicYuv*     pcPicYuvRecOut;
302  TComPic*        pcOrgRefList[2][MAX_REF_PIC_NUM];  //GT: not used?
303  TComPic*        pcPic ;
304
305  bool bSomethingCoded = false ;
306#if FLEX_CODING_ORDER 
307  if (TEncTop::m_bPicWaitingForCoding )
308#else
309  if (m_bPicWaitingForCoding )
310#endif
311  {
312    std::map<Int, TComPic*>::iterator cIter = m_acInputPicMap.find( (Int)m_cSeqIter.getPoc() );
313    const bool bPictureAvailable = cIter != m_acInputPicMap.end();
314    if (bPictureAvailable) //GT: it is possible that poc to code is not in input-picmap, but m_bPicWaitingForCoding is true, since current poc is beyond sequence-end
315    {
316      assert( m_acOutputPicMap.find( m_cSeqIter.getPoc() ) != m_acOutputPicMap.end() );
317      pcPicYuvRecOut = m_acOutputPicMap[m_cSeqIter.getPoc()];
318      m_acOutputPicMap.erase( m_cSeqIter.getPoc() );
319      pcPic          = cIter->second ;
320
321#if DEPTH_MAP_GENERATION
322      // add extra pic buffers
323      Bool  bNeedPrdDepthMapBuf = ( m_uiPredDepthMapGeneration > 0 );
324      if( bNeedPrdDepthMapBuf && !pcPic->getPredDepthMap() )
325      {
326        pcPic->addPrdDepthMapBuffer( PDM_SUB_SAMP_EXP_X(m_uiPredDepthMapGeneration), PDM_SUB_SAMP_EXP_Y(m_uiPredDepthMapGeneration) );
327      }
328#endif
329
330      // needed? dont think so
331      TComPicYuv      cPicOrg;
332      cPicOrg.create( pcPic->getPicYuvOrg()->getWidth(), pcPic->getPicYuvOrg()->getHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
333      pcPic->getPicYuvOrg()->copyToPic( &cPicOrg );
334      xSetPicProperties( pcPic) ;
335      m_cPicEncoder.compressPic( pcBitstreamOut, cPicOrg, pcPic, pcPicYuvRecOut, pcOrgRefList,  m_bSeqFirst,  m_cListPic);
336      bSomethingCoded = true;
337      m_acInputPicMap.erase( cIter );
338      cPicOrg.destroy() ;
339      assert( rcMapPicYuvRecOut.find( pcPic->getPOC() ) == rcMapPicYuvRecOut.end() );
340      rcMapPicYuvRecOut[pcPic->getPOC()] = pcPicYuvRecOut;
341    }
342    else if(m_uiViewId==-1)
343      printf("\nPOC %4d skipped due to sequence end", Int(m_cSeqIter.getPoc()) );
344    else
345    {
346      if( m_bIsDepth )
347      {
348        printf("\nDepth View \t%4d\t POC %4d skipped due to sequence end", m_uiViewId, Int(m_cSeqIter.getPoc() ));
349      }
350      else
351      {
352        printf("\nView \t\t%4d\t POC %4d skipped due to sequence end", m_uiViewId, Int(m_cSeqIter.getPoc() ));
353      }
354    }
355    ++m_cSeqIter; //GT: increment, even bPictureAvailable might be false, (POC beyond sequence end);
356
357    Bool hitSeqEndButHasToCode = bEos && !m_acInputPicMap.empty();
358    if( (m_acInputPicMap.find( (Int)m_cSeqIter.getPoc() ) != m_acInputPicMap.end()) || hitSeqEndButHasToCode ) //GT: new poc also in InputList
359    {
360      m_bPicWaitingForCoding = true;
361      bNewPicNeeded = false ;
362    }
363    else
364    {
365      m_bPicWaitingForCoding = false;
366      bNewPicNeeded = true ;
367    }
368  }
369
370
371  if(bSomethingCoded && !m_bPicWaitingForCoding ) //GT: no gaps any more
372  {
373    m_uiNumAllPicCoded += m_iNumPicRcvd;
374    m_iNumPicRcvd       = 0;
375  }
376
377
378  if (bEos&&m_uiViewId==-1)
379  {
380    printOutSummary (m_uiNumAllPicCoded);
381  }
382}
383
384
385Void TEncTop::receivePic( bool bEos, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvRec, TComPicYuv* pcOrgPdmDepth )
386{
387  if( !m_bPicWaitingForCoding ) //GT: insert pcPicYuvOrg in m_acInputPicMap and m_cListPic
388  {
389    TComPic* pcPicCurr = NULL;
390    xGetNewPicBuffer( pcPicCurr ); //GT: assigns next POC to input pic and stores it in m_cListPic
391    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
392#if HHI_INTER_VIEW_MOTION_PRED
393    if( m_uiMultiviewMvRegMode )
394    {
395      AOF( pcOrgPdmDepth );
396      AOF( pcPicCurr->getOrgDepthMap() );
397      pcOrgPdmDepth->copyToPic( pcPicCurr->getOrgDepthMap() );
398    }
399    else
400    {
401      AOT( pcOrgPdmDepth );
402      AOT( pcPicCurr->getOrgDepthMap() );
403    }
404#endif
405    m_acInputPicMap.insert( std::make_pair(pcPicCurr->getPOC(), pcPicCurr)); //GT: input pic to m_acInputPicMap
406    assert( m_acOutputPicMap.find( pcPicCurr->getPOC() ) == m_acOutputPicMap.end() );
407    m_acOutputPicMap[pcPicCurr->getPOC()] = pcPicYuvRec;
408  }
409
410  bool hitSeqEndButHasToCode = bEos && !m_acInputPicMap.empty();  //GT: End of sequence has been reached, but still pictures to code left
411  m_bPicWaitingForCoding = m_bPicWaitingForCoding || hitSeqEndButHasToCode ;
412
413  if( m_acInputPicMap.find( (Int)m_cSeqIter.getPoc() ) != m_acInputPicMap.end() ) //GT: If poc to code is in input-picmap; not necessary
414  {
415    m_bPicWaitingForCoding = true;
416  }
417}
418
419
420Void
421TEncTop::deleteExtraPicBuffers( Int iPoc )
422{
423  TComPic*                      pcPic = 0;
424  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
425  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
426  for( ; cIter != cEnd; cIter++ )
427  {
428    if( (*cIter)->getPOC() == iPoc )
429    {
430      pcPic = *cIter;
431      break;
432    }
433  }
434  AOF( pcPic );
435  if ( pcPic )
436  {
437    pcPic->removeOriginalBuffer   ();
438#if POZNAN_AVAIL_MAP
439    pcPic->removeAvailabilityBuffer();
440#endif
441#if POZNAN_SYNTH_VIEW
442    pcPic->removeSynthesisBuffer();
443#endif
444#if POZNAN_TEXTURE_TU_DELTA_QP_ACCORDING_TO_DEPTH
445    pcPic->removeSynthesisDepthBuffer();
446#endif
447#if HHI_INTER_VIEW_MOTION_PRED
448    pcPic->removeOrgDepthMapBuffer();
449#endif
450#if HHI_INTER_VIEW_RESIDUAL_PRED
451    pcPic->removeResidualBuffer   ();
452#endif
453#if HHI_INTERVIEW_SKIP
454    pcPic->removeUsedPelsMapBuffer();
455#endif
456  }
457}
458
459
460#if AMVP_BUFFERCOMPRESS
461Void
462TEncTop::compressMotion( Int iPoc )
463{
464  TComPic*                      pcPic = 0;
465  TComList<TComPic*>::iterator  cIter = m_cListPic.begin();
466  TComList<TComPic*>::iterator  cEnd  = m_cListPic.end  ();
467  for( ; cIter != cEnd; cIter++ )
468  {
469    if( (*cIter)->getPOC() == iPoc )
470    {
471      pcPic = *cIter;
472      break;
473    }
474  }
475  AOF( pcPic );
476  if ( pcPic )
477  {
478    pcPic->compressMotion();
479  }
480}
481#endif
482
483
484
485// ====================================================================================================================
486// Protected member functions
487// ====================================================================================================================
488
489/**
490 - Application has picture buffer list with size of GOP + 1
491 - Picture buffer list acts like as ring buffer
492 - End of the list has the latest picture
493 .
494 \retval rpcPic obtained picture buffer
495 */
496Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic )
497{
498  TComSlice::sortPicList(m_cListPic);
499
500  // bug-fix - erase frame memory (previous GOP) which is not used for reference any more
501  if (m_cListPic.size() >=  m_uiCodedPictureStoreSize )  // 2)   //  K. Lee bug fix - for multiple reference > 2
502  {
503    rpcPic = m_cListPic.popFront();
504
505    // is it necessary without long-term reference?
506  }
507  else
508  {
509    rpcPic = new TComPic;
510    rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
511  }
512
513  m_cListPic.pushBack( rpcPic );
514  rpcPic->setReconMark (false);
515
516  m_iPOCLast++;
517  m_iNumPicRcvd++;
518
519  rpcPic->addOriginalBuffer();
520#if HHI_INTER_VIEW_MOTION_PRED
521  if( m_uiMultiviewMvRegMode )
522  {
523    rpcPic->addOrgDepthMapBuffer();
524  }
525#endif
526
527#if HHI_INTERVIEW_SKIP
528  if( getInterViewSkip() )
529  {
530    rpcPic->addUsedPelsMapBuffer();
531  }
532#endif
533
534  rpcPic->setCurrSliceIdx( 0 ); // MW
535  rpcPic->getSlice(0)->setPOC( m_iPOCLast );
536
537  // mark it should be extended
538  rpcPic->getPicYuvRec()->setBorderExtension(false);
539
540#if POZNAN_MP
541  rpcPic->getSlice(0)->setMP(m_pcMP);
542#endif
543}
544
545
546Void TEncTop::xInitSPS()
547{
548  m_cSPS.setWidth         ( m_iSourceWidth      );
549  m_cSPS.setHeight        ( m_iSourceHeight     );
550  m_cSPS.setPad           ( m_aiPad             );
551  m_cSPS.setMaxCUWidth    ( g_uiMaxCUWidth      );
552  m_cSPS.setMaxCUHeight   ( g_uiMaxCUHeight     );
553  m_cSPS.setMaxCUDepth    ( g_uiMaxCUDepth      );
554  m_cSPS.setMinTrDepth    ( 0                   );
555  m_cSPS.setMaxTrDepth    ( 1                   );
556
557  m_cSPS.setUseALF        ( m_bUseALF           );
558
559  m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize );
560  m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize );
561  m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter    );
562  m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra    );
563
564  m_cSPS.setUseDQP        ( m_iMaxDeltaQP != 0  );
565#if !HHI_NO_LowDelayCoding
566  m_cSPS.setUseLDC        ( m_bUseLDC           );
567#endif
568  m_cSPS.setUsePAD        ( m_bUsePAD           );
569
570  m_cSPS.setUseMRG        ( m_bUseMRG           ); // SOPH:
571
572#if LM_CHROMA
573  m_cSPS.setUseLMChroma   ( m_bUseLMChroma           );
574#endif
575
576  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
577
578#if BITSTREAM_EXTRACTION
579  m_cSPS.setLayerId( m_uiLayerId );
580#endif
581
582  if( m_bIsDepth )
583  {
584#if FLEXCO_CAMPARAM_IN_DEPTH
585    //m_cSPS.initMultiviewSPSDepth    ( m_uiViewId, m_iViewOrderIdx );
586    m_cSPS.initMultiviewSPS         ( m_uiViewId, m_iViewOrderIdx, m_uiCamParPrecision, m_bCamParInSliceHeader, m_aaiCodedScale, m_aaiCodedOffset, true );
587#else
588    m_cSPS.initMultiviewSPSDepth    ( m_uiViewId, m_iViewOrderIdx );
589#endif
590#if DEPTH_MAP_GENERATION
591    m_cSPS.setPredDepthMapGeneration( m_uiViewId, true );
592#endif
593#if HHI_INTER_VIEW_RESIDUAL_PRED
594    m_cSPS.setMultiviewResPredMode  ( 0 );
595#endif
596  }
597  else
598  {
599    m_cSPS.initMultiviewSPS           ( m_uiViewId, m_iViewOrderIdx, m_uiCamParPrecision, m_bCamParInSliceHeader, m_aaiCodedScale, m_aaiCodedOffset );
600    if( m_uiViewId )
601    {
602#if DEPTH_MAP_GENERATION
603#if HHI_INTER_VIEW_MOTION_PRED
604      m_cSPS.setPredDepthMapGeneration( m_uiViewId, false, m_uiPredDepthMapGeneration, m_uiMultiviewMvPredMode, m_uiPdmPrecision, m_aaiPdmScaleNomDelta, m_aaiPdmOffset );
605#else
606      m_cSPS.setPredDepthMapGeneration( m_uiViewId, false, m_uiPredDepthMapGeneration, 0, m_uiPdmPrecision, m_aaiPdmScaleNomDelta, m_aaiPdmOffset );
607#endif
608#endif
609#if HHI_INTER_VIEW_RESIDUAL_PRED
610      m_cSPS.setMultiviewResPredMode  ( m_uiMultiviewResPredMode );
611#endif
612    }
613    else
614    {
615#if DEPTH_MAP_GENERATION
616      m_cSPS.setPredDepthMapGeneration( m_uiViewId, false );
617#endif
618#if HHI_INTER_VIEW_RESIDUAL_PRED
619      m_cSPS.setMultiviewResPredMode  ( 0 );
620#endif
621    }
622  }
623
624#if POZNAN_DBMP
625  m_cSPS.setDBMP  ( m_uiDBMP );
626#endif
627
628  m_cSPS.setSPSId( ( m_uiViewId << 1 ) + ( m_bIsDepth ? 1 : 0 ) );
629
630#if DCM_COMB_LIST
631  m_cSPS.setUseLComb    ( m_bUseLComb           );
632  m_cSPS.setLCMod       ( m_bLCMod   );
633#endif
634
635  Int i;
636#if HHI_AMVP_OFF
637  for ( i = 0; i < g_uiMaxCUDepth; i++ )
638  {
639    m_cSPS.setAMVPMode( i, AM_NONE );
640  }
641#else
642  for ( i = 0; i < g_uiMaxCUDepth; i++ )
643  {
644    m_cSPS.setAMVPMode( i, AM_EXPL );
645  }
646#endif
647
648
649#if HHI_RMP_SWITCH
650  m_cSPS.setUseRMP( m_bUseRMP );
651#endif
652
653  m_cSPS.setBitDepth    ( g_uiBitDepth        );
654  m_cSPS.setBitIncrement( g_uiBitIncrement    );
655
656#if MTK_NONCROSS_INLOOP_FILTER
657  m_cSPS.setLFCrossSliceBoundaryFlag( m_bLFCrossSliceBoundaryFlag );
658#endif
659#if MTK_SAO
660  m_cSPS.setUseSAO             ( m_bUseSAO         );
661#endif
662#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
663  m_cSPS.setUseDMM( m_bUseDMM );
664#endif
665#if HHI_DMM_PRED_TEX && FLEX_CODING_ORDER
666  m_cSPS.setUseDMM34( m_bUseDMM34 );
667#endif
668#if HHI_MPI
669  m_cSPS.setUseMVI( m_bUseMVI );
670#endif
671
672#if POZNAN_ENCODE_ONLY_DISOCCLUDED_CU
673  m_cSPS.setUseCUSkip( m_uiUseCUSkip );
674#endif
675
676#if POZNAN_NONLINEAR_DEPTH
677  m_cSPS.setNonlinearDepthModel  ( m_cNonlinearDepthModel );
678  m_cSPS.setUseNonlinearDepth    ( m_bUseNonlinearDepth );
679  // OLGIERD: ToDo - QP-Tex should not use getNonlinearDepthModel() from texture SPS.
680#endif
681
682#if POZNAN_TEXTURE_TU_DELTA_QP_ACCORDING_TO_DEPTH
683  m_cSPS.setUseTexDqpAccordingToDepth  ( m_bUseTexDqpAccordingToDepth );
684#endif
685
686  m_cSPS.setCodedPictureBufferSize( m_uiCodedPictureStoreSize );
687}
688
689#if CONSTRAINED_INTRA_PRED
690Void TEncTop::xInitPPS()
691{
692#if BITSTREAM_EXTRACTION
693  m_cPPS.setLayerId( m_uiLayerId );
694#endif
695
696  m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
697  m_cPPS.setPPSId( ( m_uiViewId << 1 ) + ( m_bIsDepth ? 1 : 0 ) );
698  m_cPPS.setSPSId( ( m_uiViewId << 1 ) + ( m_bIsDepth ? 1 : 0 ) );
699
700#ifdef WEIGHT_PRED
701  m_cPPS.setUseWP( m_bUseWeightPred );
702  m_cPPS.setWPBiPredIdc( m_uiBiPredIdc );
703#endif
704}
705#endif
706
707
708Void TEncTop::setTEncTopList(std::vector<TEncTop*>* pacTEncTopList )
709{
710  assert(m_uiViewId!=-1); // not to be set for single view coding
711
712  m_pacTEncTopList=pacTEncTopList;
713
714}
715
716
717Void TEncTop::printOutSummary(UInt uiNumAllPicCoded)
718{
719  assert (uiNumAllPicCoded == m_cAnalyzeAll.getNumPic());
720
721  //--CFG_KDY
722  m_cAnalyzeAll.setFrmRate( getFrameRate() );
723  m_cAnalyzeI.setFrmRate( getFrameRate() );
724  m_cAnalyzeP.setFrmRate( getFrameRate() );
725  m_cAnalyzeB.setFrmRate( getFrameRate() );
726
727  //-- all
728  if(m_uiViewId==-1)
729    printf( "\n\nSUMMARY --------------------------------------------------------\n" );
730  else {
731    if ( m_bIsDepth )
732    {
733      printf( "\n\nSUMMARY ---------------------------------------------- DEPTH %2d\n", m_uiViewId );
734    }
735    else
736    {
737      printf( "\n\nSUMMARY ---------------------------------------------- VIDEO %2d\n", m_uiViewId );
738    }
739  };
740  m_cAnalyzeAll.printOut('a');
741
742  printf( "\n\nI Slices--------------------------------------------------------\n" );
743  m_cAnalyzeI.printOut('i');
744
745  printf( "\n\nP Slices--------------------------------------------------------\n" );
746  m_cAnalyzeP.printOut('p');
747
748  printf( "\n\nB Slices--------------------------------------------------------\n" );
749  m_cAnalyzeB.printOut('b');
750
751#if _SUMMARY_OUT_
752  m_cAnalyzeAll.printSummaryOut();
753#endif
754#if _SUMMARY_PIC_
755  m_cAnalyzeI.printSummary('I');
756  m_cAnalyzeP.printSummary('P');
757  m_cAnalyzeB.printSummary('B');
758#endif
759}
760
761Void TEncTop::xSetRefPics( TComPic* pcPic, RefPicList eRefPicList )
762{
763  assert(m_cSeqIter.getFrameDescriptor().getAllowedRelativeRefPocs( eRefPicList, pcPic->getViewIdx() ).size() == m_cSeqIter.getFrameDescriptor().getAllowedReferenceViewIdx( eRefPicList, pcPic->getViewIdx()).size());
764#if 1
765  // check if refPic is available
766  Int iNumberOfRefs = 0;
767  std::vector<Int> aiRefPocs ;
768  std::vector<Int> aiRefViews ;
769
770  for( Int i=0; i<(Int)m_cSeqIter.getFrameDescriptor().getAllowedRelativeRefPocs( eRefPicList, pcPic->getViewIdx() ).size(); i++ )
771  {
772    Int iRefPoc  = m_cSeqIter.getFrameDescriptor().getAllowedRelativeRefPocs( eRefPicList, pcPic->getViewIdx() )[i]+pcPic->getPOC() ;
773    Int iRefViewIdx = m_cSeqIter.getFrameDescriptor().getAllowedReferenceViewIdx( eRefPicList, pcPic->getViewIdx() )[i];
774    Bool bFoundRefPic = false;
775
776    if( iRefPoc == pcPic->getPOC() ) // interview
777    {
778      assert( iRefViewIdx < (Int)m_uiViewId );
779      aiRefPocs.push_back(iRefPoc);
780      aiRefViews.push_back(iRefViewIdx);
781      iNumberOfRefs++ ;
782      bFoundRefPic = true ;
783      continue;
784    }
785    else if ( iRefViewIdx < 0 ) // temporal
786    {
787      for( TComList<TComPic*>::iterator it = m_cListPic.begin(); it!=m_cListPic.end(); it++)
788      {
789        if( (*it)->getViewIdx() == pcPic->getViewIdx() && (*it)->getPOC() == iRefPoc && (*it)->getReconMark() )
790        {
791          aiRefPocs.push_back(iRefPoc);
792          aiRefViews.push_back(m_uiViewId);
793          bFoundRefPic = true ;
794          iNumberOfRefs++ ;
795          break;
796        }
797      }
798      if( (iRefPoc < pcPic->getPOC()) && !bFoundRefPic )
799      {
800        printf("\nInconsistence in GOP-String!");
801        assert(0);
802      }
803    }
804  }
805  for ( Int i=0; i< iNumberOfRefs; i++)
806  {
807    pcPic->setRefViewIdx( aiRefViews[i], eRefPicList, i );
808    pcPic->setRefPOC(aiRefPocs[i], eRefPicList, i );
809  }
810  pcPic->setNumRefs( iNumberOfRefs, eRefPicList );
811#else
812  for( Int i=0; i<(Int)m_cSeqIter.getFrameDescriptor().getAllowedRelativeRefPocs( eRefPicList, pcPic->getViewIdx() ).size(); i++ )
813  {
814    const int iRefViewIdx = m_cSeqIter.getFrameDescriptor().getAllowedReferenceViewIdx( eRefPicList, pcPic->getViewIdx() )[i];
815    if( iRefViewIdx < 0 )
816    {
817      // temporal reference from current view
818      pcPic->setRefViewIdx( m_iViewIdx, eRefPicList, i );
819    }
820    else
821    {
822      pcPic->setRefViewIdx( iRefViewIdx, eRefPicList, i );
823    }
824    pcPic->setRefPOC(m_cSeqIter.getFrameDescriptor().getAllowedRelativeRefPocs( eRefPicList, pcPic->getViewIdx() )[i]+pcPic->getPOC(), eRefPicList, i );
825  }
826  pcPic->setNumRefs( m_cSeqIter.getFrameDescriptor().getAllowedRelativeRefPocs( eRefPicList, pcPic->getViewIdx() ).size(), eRefPicList );
827#endif
828}
829
830Void TEncTop::xCheckSliceType(TComPic* pcPic)
831{
832  if( pcPic->getNumRefs(REF_PIC_LIST_0) == 0 && pcPic->getNumRefs(REF_PIC_LIST_1) == 0 && pcPic->getSliceType() == I_SLICE )
833  {
834    return ;
835  }
836  if( pcPic->getNumRefs(REF_PIC_LIST_0) != 0 && pcPic->getNumRefs(REF_PIC_LIST_1) == 0 && pcPic->getSliceType() == P_SLICE )
837  {
838    return ;
839  }
840  if( pcPic->getNumRefs(REF_PIC_LIST_0) != 0 && pcPic->getNumRefs(REF_PIC_LIST_1) != 0 && pcPic->getSliceType() == B_SLICE )
841  {
842    return ;
843  }
844  if( pcPic->getNumRefs(REF_PIC_LIST_0) == 0 && pcPic->getNumRefs(REF_PIC_LIST_1) == 0 )
845  {
846    pcPic->setSliceType(I_SLICE) ;
847    return;
848  }
849  if( pcPic->getNumRefs(REF_PIC_LIST_0) != 0 && pcPic->getNumRefs(REF_PIC_LIST_1) == 0 )
850  {
851    pcPic->setSliceType(P_SLICE) ;
852    return;
853  }
854
855  assert(0);
856}
857
858
859Void TEncTop::xSetPicProperties(TComPic* pcPic)
860{
861  pcPic->setSliceType( m_cSeqIter.getFrameDescriptor().getSliceType(m_uiViewId) );
862  pcPic->setReferenced( m_cSeqIter.getFrameDescriptor().getStoreForRef(m_uiViewId) );
863  pcPic->setColDir( m_cSeqIter.getFrameDescriptor().getColDir() ) ;
864  const Bool bQpChangePointPassed = m_iFrameNumInCodingOrder++ >= getQpChangeFrame();
865  const Int  iQpChangeOffset      = bQpChangePointPassed ? ( m_bIsDepth ? getQpChangeOffsetDepth() : getQpChangeOffsetVideo() ) : 0;
866  pcPic->setQP(max(MIN_QP,min(MAX_QP, m_iQP+ m_aiTLayerQPOffset[m_cSeqIter.getFrameDescriptor().getTEncSeqStructureLayer(m_uiViewId)] + iQpChangeOffset )) );
867  pcPic->setViewIdx( m_uiViewId );
868#if SONY_COLPIC_AVAILABILITY
869  pcPic->setViewOrderIdx(m_iViewOrderIdx);
870#endif
871#if 0
872  pcPic->setNumRefs(0, REF_PIC_LIST_0);
873  pcPic->setNumRefs(0, REF_PIC_LIST_1);
874
875
876  if( m_cSeqIter.getFrameDescriptor().getSliceType(m_iViewIdx)== P_SLICE || m_cSeqIter.getFrameDescriptor().getSliceType(m_iViewIdx)== B_SLICE)
877  {
878    xSetRefPics( pcPic, REF_PIC_LIST_0 );
879  }
880  if( m_cSeqIter.getFrameDescriptor().getSliceType(m_iViewIdx)== B_SLICE)
881  {
882    xSetRefPics( pcPic, REF_PIC_LIST_1 );
883  }
884#else
885  xSetRefPics( pcPic, REF_PIC_LIST_0 );
886  xSetRefPics( pcPic, REF_PIC_LIST_1 );
887  xCheckSliceType( pcPic );
888#endif
889
890  pcPic->setScaleOffset( m_aaiCodedScale, m_aaiCodedOffset );
891
892#if POZNAN_TEXTURE_TU_DELTA_QP_PARAM_IN_CFG_FOR_ENC
893    pcPic->setTexDqpAccordingToDepthOffset( getTexDqpAccordingToDepthOffset() );
894    pcPic->setTexDqpAccordingToDepthMul   ( getTexDqpAccordingToDepthMul() );
895    pcPic->setTexDqpAccordingToDepthTopBottomRow( getTexDqpAccordingToDepthTopBottomRow() ); 
896#endif
897}
Note: See TracBrowser for help on using the repository browser.