source: SHVCSoftware/branches/SHM-dev/source/Lib/TLibEncoder/TEncTop.cpp @ 871

Last change on this file since 871 was 869, checked in by seregin, 11 years ago

Move conformance window signalling to the rep_format (JCTVC-R0156), patch was provided by Danny Hong <danny@…>

  • Property svn:eol-style set to native
File size: 59.0 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-2014, ITU/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 ITU/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/** \file     TEncTop.cpp
35    \brief    encoder class
36*/
37
38#include "TLibCommon/CommonDef.h"
39#include "TEncTop.h"
40#include "TEncPic.h"
41#if FAST_BIT_EST
42#include "TLibCommon/ContextModel.h"
43#endif
44
45//! \ingroup TLibEncoder
46//! \{
47#if SVC_EXTENSION 
48Int TEncTop::m_iSPSIdCnt = 0;
49Int TEncTop::m_iPPSIdCnt = 0;
50TComVPS TEncCfg::m_cVPS;
51#endif
52
53// ====================================================================================================================
54// Constructor / destructor / create / destroy
55// ====================================================================================================================
56
57TEncTop::TEncTop()
58{
59  m_iPOCLast          = -1;
60  m_iNumPicRcvd       =  0;
61  m_uiNumAllPicCoded  =  0;
62  m_pppcRDSbacCoder   =  NULL;
63  m_pppcBinCoderCABAC =  NULL;
64  m_cRDGoOnSbacCoder.init( &m_cRDGoOnBinCoderCABAC );
65#if ENC_DEC_TRACE
66  g_hTrace = fopen( "TraceEnc.txt", "wb" );
67  g_bJustDoIt = g_bEncDecTraceDisable;
68  g_nSymbolCounter = 0;
69#endif
70
71  m_iMaxRefPicNum     = 0;
72
73#if FAST_BIT_EST
74  ContextModel::buildNextStateTable();
75#endif
76
77  m_pcSbacCoders           = NULL;
78  m_pcBinCoderCABACs       = NULL;
79  m_ppppcRDSbacCoders      = NULL;
80  m_ppppcBinCodersCABAC    = NULL;
81  m_pcRDGoOnSbacCoders     = NULL;
82  m_pcRDGoOnBinCodersCABAC = NULL;
83  m_pcBitCounters          = NULL;
84  m_pcRdCosts              = NULL;
85#if SVC_EXTENSION
86  memset(m_cIlpPic, 0, sizeof(m_cIlpPic));
87#if REF_IDX_MFM
88  m_bMFMEnabledFlag = false;
89#endif
90  m_numScaledRefLayerOffsets = 0;
91#if POC_RESET_FLAG || POC_RESET_IDC_ENCODER
92  m_pocAdjustmentValue     = 0;
93#endif
94#if NO_CLRAS_OUTPUT_FLAG
95  m_noClrasOutputFlag          = false;
96  m_layerInitializedFlag       = false;
97  m_firstPicInLayerDecodedFlag = false;
98  m_noOutputOfPriorPicsFlags   = false;
99#endif
100#endif //SVC_EXTENSION
101}
102
103TEncTop::~TEncTop()
104{
105#if ENC_DEC_TRACE
106  fclose( g_hTrace );
107#endif
108}
109
110Void TEncTop::create ()
111{
112#if !SVC_EXTENSION
113  // initialize global variables
114  initROM();
115#endif
116
117  // create processing unit classes
118#if SVC_EXTENSION
119  m_cGOPEncoder.        create( m_layerId );
120#else
121  m_cGOPEncoder.        create();
122#endif
123#if AUXILIARY_PICTURES
124  m_cSliceEncoder.      create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
125#else
126  m_cSliceEncoder.      create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
127#endif
128  m_cCuEncoder.         create( g_uiMaxCUDepth, g_uiMaxCUWidth, g_uiMaxCUHeight );
129  if (m_bUseSAO)
130  {
131#if AUXILIARY_PICTURES
132    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
133#else
134    m_cEncSAO.create( getSourceWidth(), getSourceHeight(), g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
135#endif
136#if SAO_ENCODE_ALLOW_USE_PREDEBLOCK
137    m_cEncSAO.createEncData(getSaoLcuBoundary());
138#else
139    m_cEncSAO.createEncData();
140#endif
141  }
142#if ADAPTIVE_QP_SELECTION
143  if (m_bUseAdaptQpSelect)
144  {
145    m_cTrQuant.initSliceQpDelta();
146  }
147#endif
148  m_cLoopFilter.        create( g_uiMaxCUDepth );
149 
150  if ( m_RCEnableRateControl )
151  {
152    m_cRateCtrl.init( m_framesToBeEncoded, m_RCTargetBitrate, m_iFrameRate, m_iGOPSize, m_iSourceWidth, m_iSourceHeight,
153                      g_uiMaxCUWidth, g_uiMaxCUHeight, m_RCKeepHierarchicalBit, m_RCUseLCUSeparateModel, m_GOPList );
154  }
155
156  m_pppcRDSbacCoder = new TEncSbac** [g_uiMaxCUDepth+1];
157#if FAST_BIT_EST
158  m_pppcBinCoderCABAC = new TEncBinCABACCounter** [g_uiMaxCUDepth+1];
159#else
160  m_pppcBinCoderCABAC = new TEncBinCABAC** [g_uiMaxCUDepth+1];
161#endif
162
163  for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
164  {
165    m_pppcRDSbacCoder[iDepth] = new TEncSbac* [CI_NUM];
166#if FAST_BIT_EST
167    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABACCounter* [CI_NUM];
168#else
169    m_pppcBinCoderCABAC[iDepth] = new TEncBinCABAC* [CI_NUM];
170#endif
171
172    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
173    {
174      m_pppcRDSbacCoder[iDepth][iCIIdx] = new TEncSbac;
175#if FAST_BIT_EST
176      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABACCounter;
177#else
178      m_pppcBinCoderCABAC [iDepth][iCIIdx] = new TEncBinCABAC;
179#endif
180      m_pppcRDSbacCoder   [iDepth][iCIIdx]->init( m_pppcBinCoderCABAC [iDepth][iCIIdx] );
181    }
182  }
183
184#if LAYER_CTB
185  memcpy(g_auiLayerZscanToRaster[m_layerId], g_auiZscanToRaster, sizeof( g_auiZscanToRaster ) );
186  memcpy(g_auiLayerRasterToZscan[m_layerId], g_auiRasterToZscan, sizeof( g_auiRasterToZscan ) );
187  memcpy(g_auiLayerRasterToPelX[m_layerId],  g_auiRasterToPelX,  sizeof( g_auiRasterToPelX ) );
188  memcpy(g_auiLayerRasterToPelY[m_layerId],  g_auiRasterToPelY,  sizeof( g_auiRasterToPelY ) );
189#endif
190}
191
192/**
193 - Allocate coders required for wavefront for the nominated number of substreams.
194 .
195 \param iNumSubstreams Determines how much information to allocate.
196 */
197Void TEncTop::createWPPCoders(Int iNumSubstreams)
198{
199  if (m_pcSbacCoders != NULL)
200  {
201    return; // already generated.
202  }
203
204  m_iNumSubstreams         = iNumSubstreams;
205  m_pcSbacCoders           = new TEncSbac       [iNumSubstreams];
206  m_pcBinCoderCABACs       = new TEncBinCABAC   [iNumSubstreams];
207  m_pcRDGoOnSbacCoders     = new TEncSbac       [iNumSubstreams];
208  m_pcRDGoOnBinCodersCABAC = new TEncBinCABAC   [iNumSubstreams];
209  m_pcBitCounters          = new TComBitCounter [iNumSubstreams];
210  m_pcRdCosts              = new TComRdCost     [iNumSubstreams];
211
212  for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ )
213  {
214    m_pcRDGoOnSbacCoders[ui].init( &m_pcRDGoOnBinCodersCABAC[ui] );
215    m_pcSbacCoders[ui].init( &m_pcBinCoderCABACs[ui] );
216  }
217
218  m_ppppcRDSbacCoders      = new TEncSbac***    [iNumSubstreams];
219  m_ppppcBinCodersCABAC    = new TEncBinCABAC***[iNumSubstreams];
220  for ( UInt ui = 0 ; ui < iNumSubstreams ; ui++ )
221  {
222    m_ppppcRDSbacCoders[ui]  = new TEncSbac** [g_uiMaxCUDepth+1];
223    m_ppppcBinCodersCABAC[ui]= new TEncBinCABAC** [g_uiMaxCUDepth+1];
224
225    for ( Int iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
226    {
227      m_ppppcRDSbacCoders[ui][iDepth]  = new TEncSbac*     [CI_NUM];
228      m_ppppcBinCodersCABAC[ui][iDepth]= new TEncBinCABAC* [CI_NUM];
229
230      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
231      {
232        m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx] = new TEncSbac;
233        m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] = new TEncBinCABAC;
234        m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx]->init( m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx] );
235      }
236    }
237  }
238}
239
240Void TEncTop::destroy ()
241{
242  // destroy processing unit classes
243  m_cGOPEncoder.        destroy();
244  m_cSliceEncoder.      destroy();
245  m_cCuEncoder.         destroy();
246  if (m_cSPS.getUseSAO())
247  {
248    m_cEncSAO.destroyEncData();
249    m_cEncSAO.destroy();
250  }
251  m_cLoopFilter.        destroy();
252  m_cRateCtrl.          destroy();
253
254  Int iDepth;
255  for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
256  {
257    for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
258    {
259      delete m_pppcRDSbacCoder[iDepth][iCIIdx];
260      delete m_pppcBinCoderCABAC[iDepth][iCIIdx];
261    }
262  }
263
264  for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
265  {
266    delete [] m_pppcRDSbacCoder[iDepth];
267    delete [] m_pppcBinCoderCABAC[iDepth];
268  }
269
270  delete [] m_pppcRDSbacCoder;
271  delete [] m_pppcBinCoderCABAC;
272
273  for ( UInt ui = 0; ui < m_iNumSubstreams; ui++ )
274  {
275    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
276    {
277      for (Int iCIIdx = 0; iCIIdx < CI_NUM; iCIIdx ++ )
278      {
279        delete m_ppppcRDSbacCoders  [ui][iDepth][iCIIdx];
280        delete m_ppppcBinCodersCABAC[ui][iDepth][iCIIdx];
281      }
282    }
283
284    for ( iDepth = 0; iDepth < g_uiMaxCUDepth+1; iDepth++ )
285    {
286      delete [] m_ppppcRDSbacCoders  [ui][iDepth];
287      delete [] m_ppppcBinCodersCABAC[ui][iDepth];
288    }
289    delete[] m_ppppcRDSbacCoders  [ui];
290    delete[] m_ppppcBinCodersCABAC[ui];
291  }
292  delete[] m_ppppcRDSbacCoders;
293  delete[] m_ppppcBinCodersCABAC;
294  delete[] m_pcSbacCoders;
295  delete[] m_pcBinCoderCABACs;
296  delete[] m_pcRDGoOnSbacCoders; 
297  delete[] m_pcRDGoOnBinCodersCABAC;
298  delete[] m_pcBitCounters;
299  delete[] m_pcRdCosts;
300 
301#if SVC_EXTENSION
302  for(Int i=0; i<MAX_NUM_REF; i++)
303  {
304    if(m_cIlpPic[i])
305    {
306      m_cIlpPic[i]->destroy();
307      delete m_cIlpPic[i];
308      m_cIlpPic[i] = NULL;
309    }
310  }
311#else
312  // destroy ROM
313  destroyROM();
314#endif
315  return;
316}
317
318Void TEncTop::init(Bool isFieldCoding)
319{
320  // initialize SPS
321  xInitSPS();
322 
323  /* set the VPS profile information */
324  *m_cVPS.getPTL() = *m_cSPS.getPTL();
325  m_cVPS.getTimingInfo()->setTimingInfoPresentFlag       ( false );
326  // initialize PPS
327  m_cPPS.setSPS(&m_cSPS);
328  xInitPPS();
329  xInitRPS(isFieldCoding);
330
331  xInitPPSforTiles();
332
333  // initialize processing unit classes
334  m_cGOPEncoder.  init( this );
335  m_cSliceEncoder.init( this );
336  m_cCuEncoder.   init( this );
337 
338  // initialize transform & quantization class
339  m_pcCavlcCoder = getCavlcCoder();
340 
341  m_cTrQuant.init( 1 << m_uiQuadtreeTULog2MaxSize,
342                  m_useRDOQ, 
343                  m_useRDOQTS,
344                  true 
345                  ,m_useTransformSkipFast
346#if ADAPTIVE_QP_SELECTION                 
347                  , m_bUseAdaptQpSelect
348#endif
349                  );
350 
351  // initialize encoder search class
352  m_cSearch.init( this, &m_cTrQuant, m_iSearchRange, m_bipredSearchRange, m_iFastSearch, 0, &m_cEntropyCoder, &m_cRdCost, getRDSbacCoder(), getRDGoOnSbacCoder() );
353
354  m_iMaxRefPicNum = 0;
355#if SVC_EXTENSION
356  m_iSPSIdCnt ++;
357  m_iPPSIdCnt ++;
358  xInitILRP();
359#endif
360}
361
362// ====================================================================================================================
363// Public member functions
364// ====================================================================================================================
365
366Void TEncTop::deletePicBuffer()
367{
368  TComList<TComPic*>::iterator iterPic = m_cListPic.begin();
369  Int iSize = Int( m_cListPic.size() );
370 
371  for ( Int i = 0; i < iSize; i++ )
372  {
373    TComPic* pcPic = *(iterPic++);
374   
375    pcPic->destroy();
376    delete pcPic;
377    pcPic = NULL;
378  }
379}
380
381/**
382 - Application has picture buffer list with size of GOP + 1
383 - Picture buffer list acts like as ring buffer
384 - End of the list has the latest picture
385 .
386 \param   flush               cause encoder to encode a partial GOP
387 \param   pcPicYuvOrg         original YUV picture
388 \retval  rcListPicYuvRecOut  list of reconstruction YUV pictures
389 \retval  rcListBitstreamOut  list of output bitstreams
390 \retval  iNumEncoded         number of encoded pictures
391 */
392#if SVC_EXTENSION
393Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP )
394{
395  // compress GOP
396#if !RC_SHVC_HARMONIZATION
397  if ( m_RCEnableRateControl )
398  {
399    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
400  }
401#endif
402
403  // compress GOP
404  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
405
406#if !RC_SHVC_HARMONIZATION
407  if ( m_RCEnableRateControl )
408  {
409    m_cRateCtrl.destroyRCGOP();
410  }
411#endif
412 
413  m_uiNumAllPicCoded ++;
414}
415
416Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg )
417{
418  if (pcPicYuvOrg) 
419  {
420    // get original YUV
421    TComPic* pcPicCurr = NULL;
422    xGetNewPicBuffer( pcPicCurr );
423    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
424
425    // compute image characteristics
426    if ( getUseAdaptiveQP() )
427    {
428      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
429    }
430  }
431}
432#else
433Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded )
434{
435  if (pcPicYuvOrg) {
436    // get original YUV
437    TComPic* pcPicCurr = NULL;
438    xGetNewPicBuffer( pcPicCurr );
439    pcPicYuvOrg->copyToPic( pcPicCurr->getPicYuvOrg() );
440
441    // compute image characteristics
442    if ( getUseAdaptiveQP() )
443    {
444      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcPicCurr ) );
445    }
446  }
447 
448  if (!m_iNumPicRcvd || (!flush && m_iPOCLast != 0 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize))
449  {
450    iNumEncoded = 0;
451    return;
452  }
453 
454  if ( m_RCEnableRateControl )
455  {
456    m_cRateCtrl.initRCGOP( m_iNumPicRcvd );
457  }
458
459  // compress GOP
460
461  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, false, false);
462
463  if ( m_RCEnableRateControl )
464  {
465    m_cRateCtrl.destroyRCGOP();
466  }
467 
468  iNumEncoded         = m_iNumPicRcvd;
469  m_iNumPicRcvd       = 0;
470  m_uiNumAllPicCoded += iNumEncoded;
471}
472#endif
473
474/**------------------------------------------------
475 Separate interlaced frame into two fields
476 -------------------------------------------------**/
477void separateFields(Pel* org, Pel* dstField, UInt stride, UInt width, UInt height, Bool isTop)
478{
479  if (!isTop)
480  {
481    org += stride;
482  }
483  for (Int y = 0; y < height>>1; y++)
484  {
485    for (Int x = 0; x < width; x++)
486    {
487      dstField[x] = org[x];
488    }
489   
490    dstField += stride;
491    org += stride*2;
492  }
493 
494}
495
496#if SVC_EXTENSION
497Void TEncTop::encodePrep( TComPicYuv* pcPicYuvOrg, Bool isTff )
498{
499  if (pcPicYuvOrg)
500  {
501    /* -- TOP FIELD -- */
502    /* -- Top field initialization -- */
503   
504    TComPic *pcTopField;
505    xGetNewPicBuffer( pcTopField );
506    pcTopField->setReconMark (false);
507   
508    pcTopField->getSlice(0)->setPOC( m_iPOCLast );
509    pcTopField->getPicYuvRec()->setBorderExtension(false);
510    pcTopField->setTopField(isTff);
511   
512    Int nHeight = pcPicYuvOrg->getHeight();
513    Int nWidth = pcPicYuvOrg->getWidth();
514    Int nStride = pcPicYuvOrg->getStride();
515    Int nPadLuma = pcPicYuvOrg->getLumaMargin();
516    Int nPadChroma = pcPicYuvOrg->getChromaMargin();
517   
518    // Get pointers
519    Pel * PicBufY = pcPicYuvOrg->getBufY();
520    Pel * PicBufU = pcPicYuvOrg->getBufU();
521    Pel * PicBufV = pcPicYuvOrg->getBufV();
522   
523    Pel * pcTopFieldY =  pcTopField->getPicYuvOrg()->getLumaAddr();
524    Pel * pcTopFieldU =  pcTopField->getPicYuvOrg()->getCbAddr();
525    Pel * pcTopFieldV =  pcTopField->getPicYuvOrg()->getCrAddr();
526
527    // compute image characteristics
528    if ( getUseAdaptiveQP() )
529    {
530      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
531    }   
532
533    /* -- Defield -- */
534   
535    Bool isTop = isTff;
536   
537    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcTopFieldY, nStride, nWidth, nHeight, isTop);
538    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
539    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
540
541    /* -- BOTTOM FIELD -- */
542    /* -- Bottom field initialization -- */
543   
544    TComPic* pcBottomField;
545    xGetNewPicBuffer( pcBottomField );
546    pcBottomField->setReconMark (false);
547   
548    pcBottomField->getSlice(0)->setPOC( m_iPOCLast);
549    pcBottomField->getPicYuvRec()->setBorderExtension(false);
550    pcBottomField->setTopField(!isTff);
551   
552    nHeight = pcPicYuvOrg->getHeight();
553    nWidth = pcPicYuvOrg->getWidth();
554    nStride = pcPicYuvOrg->getStride();
555    nPadLuma = pcPicYuvOrg->getLumaMargin();
556    nPadChroma = pcPicYuvOrg->getChromaMargin();
557   
558    // Get pointers
559    PicBufY = pcPicYuvOrg->getBufY();
560    PicBufU = pcPicYuvOrg->getBufU();
561    PicBufV = pcPicYuvOrg->getBufV();
562   
563    Pel * pcBottomFieldY =  pcBottomField->getPicYuvOrg()->getLumaAddr();
564    Pel * pcBottomFieldU =  pcBottomField->getPicYuvOrg()->getCbAddr();
565    Pel * pcBottomFieldV =  pcBottomField->getPicYuvOrg()->getCrAddr();
566
567    // compute image characteristics
568    if ( getUseAdaptiveQP() )
569    {
570      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
571    }       
572
573    /* -- Defield -- */
574   
575    isTop = !isTff;
576   
577    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcBottomFieldY, nStride, nWidth, nHeight, isTop);
578    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
579    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
580   
581  }
582}
583
584Void TEncTop::encode( TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int iPicIdInGOP, Bool isTff )
585{
586  // compress GOP
587  if (m_iPOCLast == 0) // compress field 0
588  {
589    m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
590  }
591
592  if (pcPicYuvOrg)
593  {
594    TComPicYuv* rpcPicYuvRec = new TComPicYuv;
595    if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize )
596    {
597      rpcPicYuvRec = rcListPicYuvRecOut.popFront();
598    }
599    else
600    {
601#if AUXILIARY_PICTURES
602      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
603#else
604      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
605#endif
606    }
607    rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
608  }
609 
610  // compress GOP
611  m_cGOPEncoder.compressGOP(iPicIdInGOP, m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
612
613  m_uiNumAllPicCoded ++;
614}
615#else
616Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff)
617{
618  /* -- TOP FIELD -- */
619 
620  if (pcPicYuvOrg)
621  {
622   
623    /* -- Top field initialization -- */
624   
625    TComPic *pcTopField;
626    xGetNewPicBuffer( pcTopField );
627    pcTopField->setReconMark (false);
628   
629    pcTopField->getSlice(0)->setPOC( m_iPOCLast );
630    pcTopField->getPicYuvRec()->setBorderExtension(false);
631    pcTopField->setTopField(isTff);
632   
633    Int nHeight = pcPicYuvOrg->getHeight();
634    Int nWidth = pcPicYuvOrg->getWidth();
635    Int nStride = pcPicYuvOrg->getStride();
636    Int nPadLuma = pcPicYuvOrg->getLumaMargin();
637    Int nPadChroma = pcPicYuvOrg->getChromaMargin();
638   
639    // Get pointers
640    Pel * PicBufY = pcPicYuvOrg->getBufY();
641    Pel * PicBufU = pcPicYuvOrg->getBufU();
642    Pel * PicBufV = pcPicYuvOrg->getBufV();
643   
644    Pel * pcTopFieldY =  pcTopField->getPicYuvOrg()->getLumaAddr();
645    Pel * pcTopFieldU =  pcTopField->getPicYuvOrg()->getCbAddr();
646    Pel * pcTopFieldV =  pcTopField->getPicYuvOrg()->getCrAddr();
647   
648    // compute image characteristics
649    if ( getUseAdaptiveQP() )
650    {
651      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcTopField ) );
652    }
653   
654    /* -- Defield -- */
655   
656    Bool isTop = isTff;
657   
658    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcTopFieldY, nStride, nWidth, nHeight, isTop);
659    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
660    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcTopFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
661   
662  }
663 
664  if (m_iPOCLast == 0) // compress field 0
665  {
666    m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
667  }
668 
669  /* -- BOTTOM FIELD -- */
670 
671  if (pcPicYuvOrg)
672  {
673   
674    /* -- Bottom field initialization -- */
675   
676    TComPic* pcBottomField;
677    xGetNewPicBuffer( pcBottomField );
678    pcBottomField->setReconMark (false);
679   
680    TComPicYuv* rpcPicYuvRec;
681    if ( rcListPicYuvRecOut.size() == (UInt)m_iGOPSize )
682    {
683      rpcPicYuvRec = rcListPicYuvRecOut.popFront();
684    }
685    else
686    {
687      rpcPicYuvRec = new TComPicYuv;
688      rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth );
689    }
690    rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
691   
692    pcBottomField->getSlice(0)->setPOC( m_iPOCLast);
693    pcBottomField->getPicYuvRec()->setBorderExtension(false);
694    pcBottomField->setTopField(!isTff);
695   
696    int nHeight = pcPicYuvOrg->getHeight();
697    int nWidth = pcPicYuvOrg->getWidth();
698    int nStride = pcPicYuvOrg->getStride();
699    int nPadLuma = pcPicYuvOrg->getLumaMargin();
700    int nPadChroma = pcPicYuvOrg->getChromaMargin();
701   
702    // Get pointers
703    Pel * PicBufY = pcPicYuvOrg->getBufY();
704    Pel * PicBufU = pcPicYuvOrg->getBufU();
705    Pel * PicBufV = pcPicYuvOrg->getBufV();
706   
707    Pel * pcBottomFieldY =  pcBottomField->getPicYuvOrg()->getLumaAddr();
708    Pel * pcBottomFieldU =  pcBottomField->getPicYuvOrg()->getCbAddr();
709    Pel * pcBottomFieldV =  pcBottomField->getPicYuvOrg()->getCrAddr();
710   
711    // Compute image characteristics
712    if ( getUseAdaptiveQP() )
713    {
714      m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcBottomField ) );
715    }
716   
717    /* -- Defield -- */
718   
719    Bool isTop = !isTff;
720   
721    separateFields(PicBufY + nPadLuma + nStride*nPadLuma, pcBottomFieldY, nStride, nWidth, nHeight, isTop);
722    separateFields(PicBufU + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldU, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
723    separateFields(PicBufV + nPadChroma + (nStride >> 1)*nPadChroma, pcBottomFieldV, nStride >> 1, nWidth >> 1, nHeight >> 1, isTop);
724   
725  }
726 
727  if ( ( !(m_iNumPicRcvd) || (!flush && m_iPOCLast != 1 && m_iNumPicRcvd != m_iGOPSize && m_iGOPSize)) )
728  {
729    iNumEncoded = 0;
730    return;
731  }
732 
733  // compress GOP
734  m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff);
735 
736  iNumEncoded = m_iNumPicRcvd;
737  m_iNumPicRcvd = 0;
738  m_uiNumAllPicCoded += iNumEncoded;
739}
740#endif
741
742// ====================================================================================================================
743// Protected member functions
744// ====================================================================================================================
745
746/**
747 - Application has picture buffer list with size of GOP + 1
748 - Picture buffer list acts like as ring buffer
749 - End of the list has the latest picture
750 .
751 \retval rpcPic obtained picture buffer
752 */
753Void TEncTop::xGetNewPicBuffer ( TComPic*& rpcPic )
754{
755  TComSlice::sortPicList(m_cListPic);
756 
757  if (m_cListPic.size() >= (UInt)(m_iGOPSize + getMaxDecPicBuffering(MAX_TLAYER-1) + 2) )
758  {
759    TComList<TComPic*>::iterator iterPic  = m_cListPic.begin();
760    Int iSize = Int( m_cListPic.size() );
761    for ( Int i = 0; i < iSize; i++ )
762    {
763      rpcPic = *(iterPic++);
764      if(rpcPic->getSlice(0)->isReferenced() == false)
765      {
766        break;
767      }
768    }
769  }
770  else
771  {
772    if ( getUseAdaptiveQP() )
773    {
774      TEncPic* pcEPic = new TEncPic;
775
776#if SVC_EXTENSION //Temporal solution, should be modified
777      if(m_layerId > 0)
778      {
779        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
780        {
781#if MOVE_SCALED_OFFSET_TO_PPS
782#if O0098_SCALED_REF_LAYER_ID
783          const Window scalEL = getPPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
784#else
785          const Window scalEL = getPPS()->getScaledRefLayerWindow(i);
786#endif
787#else
788#if O0098_SCALED_REF_LAYER_ID
789          const Window scalEL = getSPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
790#else
791          const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
792#endif
793#endif
794#if REF_REGION_OFFSET
795          const Window altRL  = getPPS()->getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
796          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0
797                               && altRL.getWindowLeftOffset() == 0 && altRL.getWindowRightOffset() == 0 && altRL.getWindowTopOffset() == 0 && altRL.getWindowBottomOffset() == 0);
798#else
799          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
800#endif
801
802#if VPS_EXTN_DIRECT_REF_LAYERS
803          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
804#else
805          TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
806#endif
807#if O0194_DIFFERENT_BITDEPTH_EL_BL
808          UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i);
809          Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
810
811          if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets || !sameBitDepths
812#if Q0048_CGS_3D_ASYMLUT
813            || m_cPPS.getCGSFlag() > 0
814#endif
815#if LAYER_CTB
816            || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth()
817#endif
818            )
819#else
820          if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
821#endif
822          {
823            pcEPic->setSpatialEnhLayerFlag( i, true );
824
825            //only for scalable extension
826            assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true );
827          }
828        }
829      }
830#endif
831
832#if SVC_EXTENSION
833#if AUXILIARY_PICTURES
834      pcEPic->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
835                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
836#else
837      pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
838                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
839#endif
840#else  //SVC_EXTENSION
841      pcEPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, m_cPPS.getMaxCuDQPDepth()+1 ,
842                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
843#endif //SVC_EXTENSION
844      rpcPic = pcEPic;
845    }
846    else
847    {
848      rpcPic = new TComPic;
849
850#if SVC_EXTENSION //Temporal solution, should be modified
851      if(m_layerId > 0)
852      {
853        for(UInt i = 0; i < m_cVPS.getNumDirectRefLayers( m_layerId ); i++ )
854        {
855#if MOVE_SCALED_OFFSET_TO_PPS
856#if O0098_SCALED_REF_LAYER_ID
857          const Window scalEL = getPPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
858#else
859          const Window scalEL = getPPS()->getScaledRefLayerWindow(i);
860#endif
861#else
862#if O0098_SCALED_REF_LAYER_ID
863          const Window scalEL = getSPS()->getScaledRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
864#else
865          const Window scalEL = getSPS()->getScaledRefLayerWindow(i);
866#endif
867#endif
868#if REF_REGION_OFFSET
869          const Window altRL  = getPPS()->getRefLayerWindowForLayer(m_cVPS.getRefLayerId(m_layerId, i));
870          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0
871                               && altRL.getWindowLeftOffset() == 0 && altRL.getWindowRightOffset() == 0 && altRL.getWindowTopOffset() == 0 && altRL.getWindowBottomOffset() == 0);
872#else
873          Bool zeroOffsets = ( scalEL.getWindowLeftOffset() == 0 && scalEL.getWindowRightOffset() == 0 && scalEL.getWindowTopOffset() == 0 && scalEL.getWindowBottomOffset() == 0 );
874#endif
875
876#if VPS_EXTN_DIRECT_REF_LAYERS
877          TEncTop *pcEncTopBase = (TEncTop *)getRefLayerEnc( i );
878#else
879          TEncTop *pcEncTopBase = (TEncTop *)getLayerEnc( m_layerId-1 );
880#endif
881#if O0194_DIFFERENT_BITDEPTH_EL_BL
882          UInt refLayerId = m_cVPS.getRefLayerId(m_layerId, i);
883          Bool sameBitDepths = ( g_bitDepthYLayer[m_layerId] == g_bitDepthYLayer[refLayerId] ) && ( g_bitDepthCLayer[m_layerId] == g_bitDepthCLayer[refLayerId] );
884
885          if( m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets || !sameBitDepths
886#if Q0048_CGS_3D_ASYMLUT
887            || m_cPPS.getCGSFlag() > 0
888#endif
889#if LAYER_CTB
890            || pcEncTopBase->getSPS()->getMaxCUWidth() != m_cSPS.getMaxCUWidth() || pcEncTopBase->getSPS()->getMaxCUHeight() != m_cSPS.getMaxCUHeight() || pcEncTopBase->getSPS()->getMaxCUDepth() != m_cSPS.getMaxCUDepth()
891#endif
892)
893#else
894          if(m_iSourceWidth != pcEncTopBase->getSourceWidth() || m_iSourceHeight != pcEncTopBase->getSourceHeight() || !zeroOffsets )
895#endif
896          {
897            rpcPic->setSpatialEnhLayerFlag( i, true );
898
899            //only for scalable extension
900            assert( m_cVPS.getScalabilityMask( SCALABILITY_ID ) == true );
901          }
902        }
903      }
904#endif
905
906#if SVC_EXTENSION
907#if AUXILIARY_PICTURES
908      rpcPic->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
909                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
910#else
911      rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
912                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics, &m_cSPS);
913#endif
914#else  //SVC_EXTENSION
915      rpcPic->create( m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, 
916                      m_conformanceWindow, m_defaultDisplayWindow, m_numReorderPics);
917#endif //SVC_EXTENSION
918    }
919    m_cListPic.pushBack( rpcPic );
920  }
921  rpcPic->setReconMark (false);
922 
923  m_iPOCLast++;
924  m_iNumPicRcvd++;
925 
926  rpcPic->getSlice(0)->setPOC( m_iPOCLast );
927  // mark it should be extended
928  rpcPic->getPicYuvRec()->setBorderExtension(false);
929}
930
931Void TEncTop::xInitSPS()
932{
933#if SVC_EXTENSION
934  m_cSPS.setExtensionFlag( m_layerId > 0 ? true : false );
935
936#if Q0078_ADD_LAYER_SETS
937  if( !m_numDirectRefLayers && m_numAddLayerSets )
938  {
939    m_cSPS.setLayerId(0); // layer ID 0 for independent layers
940  }
941  else
942  {
943    m_cSPS.setLayerId(m_layerId);
944  }
945#else
946  m_cSPS.setLayerId(m_layerId);
947#endif
948#if !MOVE_SCALED_OFFSET_TO_PPS
949  m_cSPS.setNumScaledRefLayerOffsets(m_numScaledRefLayerOffsets);
950  for(Int i = 0; i < m_cSPS.getNumScaledRefLayerOffsets(); i++)
951  {
952#if O0098_SCALED_REF_LAYER_ID
953    m_cSPS.setScaledRefLayerId(i, m_scaledRefLayerId[i]);
954#endif
955    m_cSPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
956#if P0312_VERT_PHASE_ADJ
957    m_cSPS.setVertPhasePositionEnableFlag( m_scaledRefLayerId[i], m_scaledRefLayerWindow[i].getVertPhasePositionEnableFlag() );
958#endif
959  }
960#endif
961#endif //SVC_EXTENSION
962  ProfileTierLevel& profileTierLevel = *m_cSPS.getPTL()->getGeneralPTL();
963  profileTierLevel.setLevelIdc(m_level);
964  profileTierLevel.setTierFlag(m_levelTier);
965  profileTierLevel.setProfileIdc(m_profile);
966  profileTierLevel.setProfileCompatibilityFlag(m_profile, 1);
967  profileTierLevel.setProgressiveSourceFlag(m_progressiveSourceFlag);
968  profileTierLevel.setInterlacedSourceFlag(m_interlacedSourceFlag);
969  profileTierLevel.setNonPackedConstraintFlag(m_nonPackedConstraintFlag);
970  profileTierLevel.setFrameOnlyConstraintFlag(m_frameOnlyConstraintFlag);
971 
972  if (m_profile == Profile::MAIN10 && g_bitDepthY == 8 && g_bitDepthC == 8)
973  {
974    /* The above constraint is equal to Profile::MAIN */
975    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN, 1);
976  }
977  if (m_profile == Profile::MAIN)
978  {
979    /* A Profile::MAIN10 decoder can always decode Profile::MAIN */
980    profileTierLevel.setProfileCompatibilityFlag(Profile::MAIN10, 1);
981  }
982  /* XXX: should Main be marked as compatible with still picture? */
983  /* XXX: may be a good idea to refactor the above into a function
984   * that chooses the actual compatibility based upon options */
985
986  m_cSPS.setPicWidthInLumaSamples         ( m_iSourceWidth      );
987  m_cSPS.setPicHeightInLumaSamples        ( m_iSourceHeight     );
988  m_cSPS.setConformanceWindow             ( m_conformanceWindow );
989  m_cSPS.setMaxCUWidth    ( g_uiMaxCUWidth      );
990  m_cSPS.setMaxCUHeight   ( g_uiMaxCUHeight     );
991  m_cSPS.setMaxCUDepth    ( g_uiMaxCUDepth      );
992#if AUXILIARY_PICTURES
993  m_cSPS.setChromaFormatIdc( m_chromaFormatIDC);
994#endif
995
996  Int minCUSize = m_cSPS.getMaxCUWidth() >> ( m_cSPS.getMaxCUDepth()-g_uiAddCUDepth );
997  Int log2MinCUSize = 0;
998  while(minCUSize > 1)
999  {
1000    minCUSize >>= 1;
1001    log2MinCUSize++;
1002  }
1003
1004  m_cSPS.setLog2MinCodingBlockSize(log2MinCUSize);
1005  m_cSPS.setLog2DiffMaxMinCodingBlockSize(m_cSPS.getMaxCUDepth()-g_uiAddCUDepth);
1006#if SVC_EXTENSION
1007  m_cSPS.setSPSId         ( m_iSPSIdCnt       );
1008#endif
1009 
1010  m_cSPS.setPCMLog2MinSize (m_uiPCMLog2MinSize);
1011  m_cSPS.setUsePCM        ( m_usePCM           );
1012  m_cSPS.setPCMLog2MaxSize( m_pcmLog2MaxSize  );
1013
1014  m_cSPS.setQuadtreeTULog2MaxSize( m_uiQuadtreeTULog2MaxSize );
1015  m_cSPS.setQuadtreeTULog2MinSize( m_uiQuadtreeTULog2MinSize );
1016  m_cSPS.setQuadtreeTUMaxDepthInter( m_uiQuadtreeTUMaxDepthInter    );
1017  m_cSPS.setQuadtreeTUMaxDepthIntra( m_uiQuadtreeTUMaxDepthIntra    );
1018 
1019  m_cSPS.setTMVPFlagsPresent(false);
1020
1021  m_cSPS.setMaxTrSize   ( 1 << m_uiQuadtreeTULog2MaxSize );
1022 
1023  Int i;
1024 
1025  for (i = 0; i < g_uiMaxCUDepth-g_uiAddCUDepth; i++ )
1026  {
1027    m_cSPS.setAMPAcc( i, m_useAMP );
1028    //m_cSPS.setAMPAcc( i, 1 );
1029  }
1030
1031  m_cSPS.setUseAMP ( m_useAMP );
1032
1033  for (i = g_uiMaxCUDepth-g_uiAddCUDepth; i < g_uiMaxCUDepth; i++ )
1034  {
1035    m_cSPS.setAMPAcc(i, 0);
1036  }
1037
1038#if REPN_FORMAT_IN_VPS
1039  m_cSPS.setBitDepthY( m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma() );
1040  m_cSPS.setBitDepthC( m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsChroma()  );
1041
1042  m_cSPS.setQpBDOffsetY ( 6*(m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsLuma()  - 8) );
1043  m_cSPS.setQpBDOffsetC ( 6*(m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) )->getBitDepthVpsChroma()  - 8) );
1044#else
1045  m_cSPS.setBitDepthY( g_bitDepthY );
1046  m_cSPS.setBitDepthC( g_bitDepthC );
1047
1048  m_cSPS.setQpBDOffsetY ( 6*(g_bitDepthY - 8) );
1049  m_cSPS.setQpBDOffsetC ( 6*(g_bitDepthC - 8) );
1050#endif
1051
1052  m_cSPS.setUseSAO( m_bUseSAO );
1053
1054  m_cSPS.setMaxTLayers( m_maxTempLayer );
1055  m_cSPS.setTemporalIdNestingFlag( ( m_maxTempLayer == 1 ) ? true : false );
1056  for ( i = 0; i < min(m_cSPS.getMaxTLayers(),(UInt) MAX_TLAYER); i++ )
1057  {
1058    m_cSPS.setMaxDecPicBuffering(m_maxDecPicBuffering[i], i);
1059    m_cSPS.setNumReorderPics(m_numReorderPics[i], i);
1060  }
1061  m_cSPS.setPCMBitDepthLuma (g_uiPCMBitDepthLuma);
1062  m_cSPS.setPCMBitDepthChroma (g_uiPCMBitDepthChroma);
1063  m_cSPS.setPCMFilterDisableFlag  ( m_bPCMFilterDisableFlag );
1064
1065  m_cSPS.setScalingListFlag ( (m_useScalingListId == 0) ? 0 : 1 );
1066
1067  m_cSPS.setUseStrongIntraSmoothing( m_useStrongIntraSmoothing );
1068
1069  m_cSPS.setVuiParametersPresentFlag(getVuiParametersPresentFlag());
1070  if (m_cSPS.getVuiParametersPresentFlag())
1071  {
1072    TComVUI* pcVUI = m_cSPS.getVuiParameters();
1073    pcVUI->setAspectRatioInfoPresentFlag(getAspectRatioInfoPresentFlag());
1074    pcVUI->setAspectRatioIdc(getAspectRatioIdc());
1075    pcVUI->setSarWidth(getSarWidth());
1076    pcVUI->setSarHeight(getSarHeight());
1077    pcVUI->setOverscanInfoPresentFlag(getOverscanInfoPresentFlag());
1078    pcVUI->setOverscanAppropriateFlag(getOverscanAppropriateFlag());
1079    pcVUI->setVideoSignalTypePresentFlag(getVideoSignalTypePresentFlag());
1080    pcVUI->setVideoFormat(getVideoFormat());
1081    pcVUI->setVideoFullRangeFlag(getVideoFullRangeFlag());
1082    pcVUI->setColourDescriptionPresentFlag(getColourDescriptionPresentFlag());
1083    pcVUI->setColourPrimaries(getColourPrimaries());
1084    pcVUI->setTransferCharacteristics(getTransferCharacteristics());
1085    pcVUI->setMatrixCoefficients(getMatrixCoefficients());
1086    pcVUI->setChromaLocInfoPresentFlag(getChromaLocInfoPresentFlag());
1087    pcVUI->setChromaSampleLocTypeTopField(getChromaSampleLocTypeTopField());
1088    pcVUI->setChromaSampleLocTypeBottomField(getChromaSampleLocTypeBottomField());
1089    pcVUI->setNeutralChromaIndicationFlag(getNeutralChromaIndicationFlag());
1090    pcVUI->setDefaultDisplayWindow(getDefaultDisplayWindow());
1091    pcVUI->setFrameFieldInfoPresentFlag(getFrameFieldInfoPresentFlag());
1092    pcVUI->setFieldSeqFlag(false);
1093    pcVUI->setHrdParametersPresentFlag(false);
1094    pcVUI->getTimingInfo()->setPocProportionalToTimingFlag(getPocProportionalToTimingFlag());
1095    pcVUI->getTimingInfo()->setNumTicksPocDiffOneMinus1   (getNumTicksPocDiffOneMinus1()   );
1096    pcVUI->setBitstreamRestrictionFlag(getBitstreamRestrictionFlag());
1097    pcVUI->setTilesFixedStructureFlag(getTilesFixedStructureFlag());
1098    pcVUI->setMotionVectorsOverPicBoundariesFlag(getMotionVectorsOverPicBoundariesFlag());
1099    pcVUI->setMinSpatialSegmentationIdc(getMinSpatialSegmentationIdc());
1100    pcVUI->setMaxBytesPerPicDenom(getMaxBytesPerPicDenom());
1101    pcVUI->setMaxBitsPerMinCuDenom(getMaxBitsPerMinCuDenom());
1102    pcVUI->setLog2MaxMvLengthHorizontal(getLog2MaxMvLengthHorizontal());
1103    pcVUI->setLog2MaxMvLengthVertical(getLog2MaxMvLengthVertical());
1104  }
1105}
1106
1107Void TEncTop::xInitPPS()
1108{
1109  m_cPPS.setConstrainedIntraPred( m_bUseConstrainedIntraPred );
1110  Bool bUseDQP = (getMaxCuDQPDepth() > 0)? true : false;
1111
1112  if((getMaxDeltaQP() != 0 )|| getUseAdaptiveQP())
1113  {
1114    bUseDQP = true;
1115  }
1116
1117  if(bUseDQP)
1118  {
1119    m_cPPS.setUseDQP(true);
1120    m_cPPS.setMaxCuDQPDepth( m_iMaxCuDQPDepth );
1121    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
1122  }
1123  else
1124  {
1125    m_cPPS.setUseDQP(false);
1126    m_cPPS.setMaxCuDQPDepth( 0 );
1127    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
1128  }
1129
1130  if ( m_RCEnableRateControl )
1131  {
1132    m_cPPS.setUseDQP(true);
1133    m_cPPS.setMaxCuDQPDepth( 0 );
1134    m_cPPS.setMinCuDQPSize( m_cPPS.getSPS()->getMaxCUWidth() >> ( m_cPPS.getMaxCuDQPDepth()) );
1135  } 
1136
1137  m_cPPS.setChromaCbQpOffset( m_chromaCbQpOffset );
1138  m_cPPS.setChromaCrQpOffset( m_chromaCrQpOffset );
1139
1140  m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams);
1141  m_cPPS.setEntropyCodingSyncEnabledFlag( m_iWaveFrontSynchro > 0 );
1142  m_cPPS.setTilesEnabledFlag( (m_iNumColumnsMinus1 > 0 || m_iNumRowsMinus1 > 0) );
1143  m_cPPS.setUseWP( m_useWeightedPred );
1144  m_cPPS.setWPBiPred( m_useWeightedBiPred );
1145  m_cPPS.setOutputFlagPresentFlag( false );
1146  m_cPPS.setSignHideFlag(getSignHideFlag());
1147  if ( getDeblockingFilterMetric() )
1148  {
1149    m_cPPS.setDeblockingFilterControlPresentFlag (true);
1150    m_cPPS.setDeblockingFilterOverrideEnabledFlag(true);
1151    m_cPPS.setPicDisableDeblockingFilterFlag(false);
1152    m_cPPS.setDeblockingFilterBetaOffsetDiv2(0);
1153    m_cPPS.setDeblockingFilterTcOffsetDiv2(0);
1154  } 
1155  else
1156  {
1157  m_cPPS.setDeblockingFilterControlPresentFlag (m_DeblockingFilterControlPresent );
1158  }
1159  m_cPPS.setLog2ParallelMergeLevelMinus2   (m_log2ParallelMergeLevelMinus2 );
1160  m_cPPS.setCabacInitPresentFlag(CABAC_INIT_PRESENT_FLAG);
1161  m_cPPS.setLoopFilterAcrossSlicesEnabledFlag( m_bLFCrossSliceBoundaryFlag );
1162  Int histogram[MAX_NUM_REF + 1];
1163  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1164  {
1165    histogram[i]=0;
1166  }
1167  for( Int i = 0; i < getGOPSize(); i++ )
1168  {
1169    assert(getGOPEntry(i).m_numRefPicsActive >= 0 && getGOPEntry(i).m_numRefPicsActive <= MAX_NUM_REF);
1170    histogram[getGOPEntry(i).m_numRefPicsActive]++;
1171  }
1172  Int maxHist=-1;
1173  Int bestPos=0;
1174  for( Int i = 0; i <= MAX_NUM_REF; i++ )
1175  {
1176    if(histogram[i]>maxHist)
1177    {
1178      maxHist=histogram[i];
1179      bestPos=i;
1180    }
1181  }
1182  assert(bestPos <= 15);
1183  m_cPPS.setNumRefIdxL0DefaultActive(bestPos);
1184  m_cPPS.setNumRefIdxL1DefaultActive(bestPos);
1185  m_cPPS.setTransquantBypassEnableFlag(getTransquantBypassEnableFlag());
1186  m_cPPS.setUseTransformSkip( m_useTransformSkip );
1187  if (m_sliceSegmentMode)
1188  {
1189    m_cPPS.setDependentSliceSegmentsEnabledFlag( true );
1190  }
1191  if( m_cPPS.getDependentSliceSegmentsEnabledFlag() )
1192  {
1193    Int NumCtx = m_cPPS.getEntropyCodingSyncEnabledFlag()?2:1;
1194    m_cSliceEncoder.initCtxMem( NumCtx );
1195    for ( UInt st = 0; st < NumCtx; st++ )
1196    {
1197      TEncSbac* ctx = NULL;
1198      ctx = new TEncSbac;
1199      ctx->init( &m_cBinCoderCABAC );
1200      m_cSliceEncoder.setCtxMem( ctx, st );
1201    }
1202  }
1203#if SVC_EXTENSION
1204#if SCALINGLIST_INFERRING
1205  m_cPPS.setLayerId( m_layerId );
1206#endif
1207
1208#if Q0078_ADD_LAYER_SETS
1209  if( !m_numDirectRefLayers && m_numAddLayerSets )
1210  {
1211    m_cPPS.setLayerId(0); // layer ID 0 for independent layers
1212  }
1213#endif
1214
1215  if( m_layerId > 0 )
1216  {
1217    m_cPPS.setListsModificationPresentFlag(true);
1218    m_cPPS.setExtensionFlag(true);
1219  }
1220  else
1221  {
1222    m_cPPS.setListsModificationPresentFlag(false);
1223    m_cPPS.setExtensionFlag(false);
1224  }
1225
1226  m_cPPS.setPPSId( m_iPPSIdCnt );
1227  m_cPPS.setSPSId( m_iSPSIdCnt );
1228#if POC_RESET_FLAG
1229  m_cPPS.setNumExtraSliceHeaderBits( 2 );
1230#endif
1231#if O0149_CROSS_LAYER_BLA_FLAG
1232  if (m_crossLayerBLAFlag)
1233  {
1234    m_cPPS.setNumExtraSliceHeaderBits( 3 );
1235  }
1236#endif
1237#if MOVE_SCALED_OFFSET_TO_PPS
1238  m_cPPS.setNumScaledRefLayerOffsets(m_numScaledRefLayerOffsets);
1239  for(Int i = 0; i < m_cPPS.getNumScaledRefLayerOffsets(); i++)
1240  {
1241#if O0098_SCALED_REF_LAYER_ID
1242    m_cPPS.setScaledRefLayerId(i, m_scaledRefLayerId[i]);
1243#endif
1244    m_cPPS.getScaledRefLayerWindow(i) = m_scaledRefLayerWindow[i];
1245#if REF_REGION_OFFSET
1246    m_cPPS.getRefLayerWindow(i) = m_refLayerWindow[i];
1247    m_cPPS.setScaledRefLayerOffsetPresentFlag( m_scaledRefLayerId[i], m_scaledRefLayerOffsetPresentFlag[i] );
1248    m_cPPS.setRefRegionOffsetPresentFlag( m_scaledRefLayerId[i], m_refRegionOffsetPresentFlag[i] );
1249#endif
1250#if R0209_GENERIC_PHASE
1251    m_cPPS.setResamplePhaseSetPresentFlag( m_scaledRefLayerId[i], m_resamplePhaseSetPresentFlag[i] );
1252    m_cPPS.setPhaseHorLuma( m_scaledRefLayerId[i], m_phaseHorLuma[i] );
1253    m_cPPS.setPhaseVerLuma( m_scaledRefLayerId[i], m_phaseVerLuma[i] );
1254    m_cPPS.setPhaseHorChroma( m_scaledRefLayerId[i], m_phaseHorChroma[i] );
1255    m_cPPS.setPhaseVerChroma( m_scaledRefLayerId[i], m_phaseVerChroma[i] );
1256#endif
1257#if P0312_VERT_PHASE_ADJ
1258    m_cPPS.setVertPhasePositionEnableFlag( m_scaledRefLayerId[i], m_scaledRefLayerWindow[i].getVertPhasePositionEnableFlag() );
1259#endif
1260  }
1261#endif
1262#if Q0048_CGS_3D_ASYMLUT
1263  m_cPPS.setCGSFlag( m_nCGSFlag );
1264#endif
1265#if POC_RESET_IDC_ENCODER
1266  m_cPPS.setPocResetInfoPresentFlag( true );
1267  m_cPPS.setExtensionFlag( true );
1268  m_cPPS.setSliceHeaderExtensionPresentFlag( true );
1269#endif
1270#endif //SVC_EXTENSION
1271}
1272
1273//Function for initializing m_RPSList, a list of TComReferencePictureSet, based on the GOPEntry objects read from the config file.
1274Void TEncTop::xInitRPS(Bool isFieldCoding)
1275{
1276  TComReferencePictureSet*      rps;
1277 
1278  m_cSPS.createRPSList(getGOPSize()+m_extraRPSs+1);
1279  TComRPSList* rpsList = m_cSPS.getRPSList();
1280
1281  for( Int i = 0; i < getGOPSize()+m_extraRPSs; i++) 
1282  {
1283    GOPEntry ge = getGOPEntry(i);
1284    rps = rpsList->getReferencePictureSet(i);
1285    rps->setNumberOfPictures(ge.m_numRefPics);
1286    rps->setNumRefIdc(ge.m_numRefIdc);
1287    Int numNeg = 0;
1288    Int numPos = 0;
1289    for( Int j = 0; j < ge.m_numRefPics; j++)
1290    {
1291      rps->setDeltaPOC(j,ge.m_referencePics[j]);
1292      rps->setUsed(j,ge.m_usedByCurrPic[j]);
1293      if(ge.m_referencePics[j]>0)
1294      {
1295        numPos++;
1296      }
1297      else
1298      {
1299        numNeg++;
1300      }
1301    }
1302    rps->setNumberOfNegativePictures(numNeg);
1303    rps->setNumberOfPositivePictures(numPos);
1304
1305    // handle inter RPS intialization from the config file.
1306#if AUTO_INTER_RPS
1307    rps->setInterRPSPrediction(ge.m_interRPSPrediction > 0);  // not very clean, converting anything > 0 to true.
1308    rps->setDeltaRIdxMinus1(0);                               // index to the Reference RPS is always the previous one.
1309    TComReferencePictureSet*     RPSRef = rpsList->getReferencePictureSet(i-1);  // get the reference RPS
1310
1311    if (ge.m_interRPSPrediction == 2)  // Automatic generation of the inter RPS idc based on the RIdx provided.
1312    {
1313      Int deltaRPS = getGOPEntry(i-1).m_POC - ge.m_POC;  // the ref POC - current POC
1314      Int numRefDeltaPOC = RPSRef->getNumberOfPictures();
1315
1316      rps->setDeltaRPS(deltaRPS);           // set delta RPS
1317      rps->setNumRefIdc(numRefDeltaPOC+1);  // set the numRefIdc to the number of pictures in the reference RPS + 1.
1318      Int count=0;
1319      for (Int j = 0; j <= numRefDeltaPOC; j++ ) // cycle through pics in reference RPS.
1320      {
1321        Int RefDeltaPOC = (j<numRefDeltaPOC)? RPSRef->getDeltaPOC(j): 0;  // if it is the last decoded picture, set RefDeltaPOC = 0
1322        rps->setRefIdc(j, 0);
1323        for (Int k = 0; k < rps->getNumberOfPictures(); k++ )  // cycle through pics in current RPS.
1324        {
1325          if (rps->getDeltaPOC(k) == ( RefDeltaPOC + deltaRPS))  // if the current RPS has a same picture as the reference RPS.
1326          {
1327              rps->setRefIdc(j, (rps->getUsed(k)?1:2));
1328              count++;
1329              break;
1330          }
1331        }
1332      }
1333      if (count != rps->getNumberOfPictures())
1334      {
1335        printf("Warning: Unable fully predict all delta POCs using the reference RPS index given in the config file.  Setting Inter RPS to false for this RPS.\n");
1336        rps->setInterRPSPrediction(0);
1337      }
1338    }
1339    else if (ge.m_interRPSPrediction == 1)  // inter RPS idc based on the RefIdc values provided in config file.
1340    {
1341      rps->setDeltaRPS(ge.m_deltaRPS);
1342      rps->setNumRefIdc(ge.m_numRefIdc);
1343      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1344      {
1345        rps->setRefIdc(j, ge.m_refIdc[j]);
1346      }
1347#if WRITE_BACK
1348      // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones
1349      // computed from the RefIdc.  A warning is printed if they are not identical.
1350      numNeg = 0;
1351      numPos = 0;
1352      TComReferencePictureSet      RPSTemp;  // temporary variable
1353
1354      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1355      {
1356        if (ge.m_refIdc[j])
1357        {
1358          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
1359          RPSTemp.setDeltaPOC((numNeg+numPos),deltaPOC);
1360          RPSTemp.setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
1361          if (deltaPOC<0)
1362          {
1363            numNeg++;
1364          }
1365          else
1366          {
1367            numPos++;
1368          }
1369        }
1370      }
1371      if (numNeg != rps->getNumberOfNegativePictures())
1372      {
1373        printf("Warning: number of negative pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1374        rps->setNumberOfNegativePictures(numNeg);
1375        rps->setNumberOfPictures(numNeg+numPos);
1376      }
1377      if (numPos != rps->getNumberOfPositivePictures())
1378      {
1379        printf("Warning: number of positive pictures in RPS is different between intra and inter RPS specified in the config file.\n");
1380        rps->setNumberOfPositivePictures(numPos);
1381        rps->setNumberOfPictures(numNeg+numPos);
1382      }
1383      RPSTemp.setNumberOfPictures(numNeg+numPos);
1384      RPSTemp.setNumberOfNegativePictures(numNeg);
1385      RPSTemp.sortDeltaPOC();     // sort the created delta POC before comparing
1386      // check if Delta POC and Used are the same
1387      // print warning if they are not.
1388      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1389      {
1390        if (RPSTemp.getDeltaPOC(j) != rps->getDeltaPOC(j))
1391        {
1392          printf("Warning: delta POC is different between intra RPS and inter RPS specified in the config file.\n");
1393          rps->setDeltaPOC(j,RPSTemp.getDeltaPOC(j));
1394        }
1395        if (RPSTemp.getUsed(j) != rps->getUsed(j))
1396        {
1397          printf("Warning: Used by Current in RPS is different between intra and inter RPS specified in the config file.\n");
1398          rps->setUsed(j,RPSTemp.getUsed(j));
1399        }
1400      }
1401#endif
1402    }
1403#else
1404    rps->setInterRPSPrediction(ge.m_interRPSPrediction);
1405    if (ge.m_interRPSPrediction)
1406    {
1407      rps->setDeltaRIdxMinus1(0);
1408      rps->setDeltaRPS(ge.m_deltaRPS);
1409      rps->setNumRefIdc(ge.m_numRefIdc);
1410      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1411      {
1412        rps->setRefIdc(j, ge.m_refIdc[j]);
1413      }
1414#if WRITE_BACK
1415      // the folowing code overwrite the deltaPOC and Used by current values read from the config file with the ones
1416      // computed from the RefIdc.  This is not necessary if both are identical. Currently there is no check to see if they are identical.
1417      numNeg = 0;
1418      numPos = 0;
1419      TComReferencePictureSet*     RPSRef = m_RPSList.getReferencePictureSet(i-1);
1420
1421      for (Int j = 0; j < ge.m_numRefIdc; j++ )
1422      {
1423        if (ge.m_refIdc[j])
1424        {
1425          Int deltaPOC = ge.m_deltaRPS + ((j < RPSRef->getNumberOfPictures())? RPSRef->getDeltaPOC(j) : 0);
1426          rps->setDeltaPOC((numNeg+numPos),deltaPOC);
1427          rps->setUsed((numNeg+numPos),ge.m_refIdc[j]==1?1:0);
1428          if (deltaPOC<0)
1429          {
1430            numNeg++;
1431          }
1432          else
1433          {
1434            numPos++;
1435          }
1436        }
1437      }
1438      rps->setNumberOfNegativePictures(numNeg);
1439      rps->setNumberOfPositivePictures(numPos);
1440      rps->sortDeltaPOC();
1441#endif
1442    }
1443#endif //INTER_RPS_AUTO
1444  }
1445  //In case of field coding, we need to set special parameters for the first bottom field of the sequence, since it is not specified in the cfg file.
1446  //The position = GOPSize + extraRPSs which is (a priori) unused is reserved for this field in the RPS.
1447  if (isFieldCoding) 
1448  {
1449    rps = rpsList->getReferencePictureSet(getGOPSize()+m_extraRPSs);
1450    rps->setNumberOfPictures(1);
1451    rps->setNumberOfNegativePictures(1);
1452    rps->setNumberOfPositivePictures(0);
1453    rps->setNumberOfLongtermPictures(0);
1454    rps->setDeltaPOC(0,-1);
1455    rps->setPOC(0,0);
1456    rps->setUsed(0,true);
1457    rps->setInterRPSPrediction(false);
1458    rps->setDeltaRIdxMinus1(0);
1459    rps->setDeltaRPS(0);
1460    rps->setNumRefIdc(0);
1461}
1462}
1463
1464   // This is a function that
1465   // determines what Reference Picture Set to use
1466   // for a specific slice (with POC = POCCurr)
1467Void TEncTop::selectReferencePictureSet(TComSlice* slice, Int POCCurr, Int GOPid )
1468{
1469  slice->setRPSidx(GOPid);
1470  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1471  {   
1472    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1473    {
1474      Int POCIndex = POCCurr%m_uiIntraPeriod;
1475      if(POCIndex == 0)
1476      {
1477        POCIndex = m_uiIntraPeriod;
1478      }
1479      if(POCIndex == m_GOPList[extraNum].m_POC)
1480      {
1481        slice->setRPSidx(extraNum);
1482      }
1483    }
1484    else
1485    {
1486      if(POCCurr==m_GOPList[extraNum].m_POC)
1487      {
1488        slice->setRPSidx(extraNum);
1489      }
1490    }
1491  }
1492
1493  if(POCCurr == 1 && slice->getPic()->isField())
1494  {
1495    slice->setRPSidx(m_iGOPSize+m_extraRPSs);
1496  }
1497
1498  slice->setRPS(getSPS()->getRPSList()->getReferencePictureSet(slice->getRPSidx()));
1499  slice->getRPS()->setNumberOfPictures(slice->getRPS()->getNumberOfNegativePictures()+slice->getRPS()->getNumberOfPositivePictures());
1500}
1501
1502Int TEncTop::getReferencePictureSetIdxForSOP(TComSlice* slice, Int POCCurr, Int GOPid )
1503{
1504  int rpsIdx = GOPid;
1505
1506  for(Int extraNum=m_iGOPSize; extraNum<m_extraRPSs+m_iGOPSize; extraNum++)
1507  {   
1508    if(m_uiIntraPeriod > 0 && getDecodingRefreshType() > 0)
1509    {
1510      Int POCIndex = POCCurr%m_uiIntraPeriod;
1511      if(POCIndex == 0)
1512      {
1513        POCIndex = m_uiIntraPeriod;
1514      }
1515      if(POCIndex == m_GOPList[extraNum].m_POC)
1516      {
1517        rpsIdx = extraNum;
1518      }
1519    }
1520    else
1521    {
1522      if(POCCurr==m_GOPList[extraNum].m_POC)
1523      {
1524        rpsIdx = extraNum;
1525      }
1526    }
1527  }
1528
1529  return rpsIdx;
1530}
1531
1532Void  TEncTop::xInitPPSforTiles()
1533{
1534  m_cPPS.setTileUniformSpacingFlag( m_tileUniformSpacingFlag );
1535  m_cPPS.setNumTileColumnsMinus1( m_iNumColumnsMinus1 );
1536  m_cPPS.setNumTileRowsMinus1( m_iNumRowsMinus1 );
1537  if( !m_tileUniformSpacingFlag )
1538  {
1539    m_cPPS.setTileColumnWidth( m_tileColumnWidth );
1540    m_cPPS.setTileRowHeight( m_tileRowHeight );
1541  }
1542  m_cPPS.setLoopFilterAcrossTilesEnabledFlag( m_loopFilterAcrossTilesEnabledFlag );
1543
1544  // # substreams is "per tile" when tiles are independent.
1545  if (m_iWaveFrontSynchro )
1546  {
1547    m_cPPS.setNumSubstreams(m_iWaveFrontSubstreams * (m_iNumColumnsMinus1+1));
1548  }
1549}
1550
1551Void  TEncCfg::xCheckGSParameters()
1552{
1553  Int   iWidthInCU = ( m_iSourceWidth%g_uiMaxCUWidth ) ? m_iSourceWidth/g_uiMaxCUWidth + 1 : m_iSourceWidth/g_uiMaxCUWidth;
1554  Int   iHeightInCU = ( m_iSourceHeight%g_uiMaxCUHeight ) ? m_iSourceHeight/g_uiMaxCUHeight + 1 : m_iSourceHeight/g_uiMaxCUHeight;
1555  UInt  uiCummulativeColumnWidth = 0;
1556  UInt  uiCummulativeRowHeight = 0;
1557
1558  //check the column relative parameters
1559  if( m_iNumColumnsMinus1 >= (1<<(LOG2_MAX_NUM_COLUMNS_MINUS1+1)) )
1560  {
1561    printf( "The number of columns is larger than the maximum allowed number of columns.\n" );
1562    exit( EXIT_FAILURE );
1563  }
1564
1565  if( m_iNumColumnsMinus1 >= iWidthInCU )
1566  {
1567    printf( "The current picture can not have so many columns.\n" );
1568    exit( EXIT_FAILURE );
1569  }
1570
1571  if( m_iNumColumnsMinus1 && !m_tileUniformSpacingFlag )
1572  {
1573    for(Int i=0; i<m_iNumColumnsMinus1; i++)
1574    {
1575      uiCummulativeColumnWidth += m_tileColumnWidth[i];
1576    }
1577
1578    if( uiCummulativeColumnWidth >= iWidthInCU )
1579    {
1580      printf( "The width of the column is too large.\n" );
1581      exit( EXIT_FAILURE );
1582    }
1583  }
1584
1585  //check the row relative parameters
1586  if( m_iNumRowsMinus1 >= (1<<(LOG2_MAX_NUM_ROWS_MINUS1+1)) )
1587  {
1588    printf( "The number of rows is larger than the maximum allowed number of rows.\n" );
1589    exit( EXIT_FAILURE );
1590  }
1591
1592  if( m_iNumRowsMinus1 >= iHeightInCU )
1593  {
1594    printf( "The current picture can not have so many rows.\n" );
1595    exit( EXIT_FAILURE );
1596  }
1597
1598  if( m_iNumRowsMinus1 && !m_tileUniformSpacingFlag )
1599  {
1600    for(Int i=0; i<m_iNumRowsMinus1; i++)
1601      uiCummulativeRowHeight += m_tileRowHeight[i];
1602
1603    if( uiCummulativeRowHeight >= iHeightInCU )
1604    {
1605      printf( "The height of the row is too large.\n" );
1606      exit( EXIT_FAILURE );
1607    }
1608  }
1609}
1610
1611#if SVC_EXTENSION
1612#if VPS_EXTN_DIRECT_REF_LAYERS
1613TEncTop* TEncTop::getRefLayerEnc( UInt refLayerIdc )
1614{
1615  if( m_ppcTEncTop[m_layerId]->getNumDirectRefLayers() <= 0 )
1616  {
1617    return (TEncTop *)getLayerEnc( 0 );
1618  }
1619
1620  return (TEncTop *)getLayerEnc( m_cVPS.getRefLayerId( m_layerId, refLayerIdc ) );
1621}
1622#endif
1623
1624#if !REPN_FORMAT_IN_VPS
1625Void TEncTop::xInitILRP()
1626{
1627  if(m_layerId>0)
1628  {
1629    g_bitDepthY     = m_cSPS.getBitDepthY();
1630    g_bitDepthC     = m_cSPS.getBitDepthC();
1631    g_uiMaxCUWidth  = m_cSPS.getMaxCUWidth();
1632    g_uiMaxCUHeight = m_cSPS.getMaxCUHeight();
1633    g_uiMaxCUDepth  = m_cSPS.getMaxCUDepth();
1634    g_uiAddCUDepth  = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() );
1635
1636    Int  numReorderPics[MAX_TLAYER];
1637    Window &conformanceWindow = m_cSPS.getConformanceWindow();
1638    Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window();
1639
1640    if (m_cIlpPic[0] == NULL)
1641    {
1642      for (Int j=0; j < m_numLayer; j++) // consider to set to NumDirectRefLayers[LayerIdInVps[nuh_layer_id]]
1643      {
1644        m_cIlpPic[j] = new  TComPic;
1645#if AUXILIARY_PICTURES
1646        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
1647#else
1648        m_cIlpPic[j]->create(m_iSourceWidth, m_iSourceHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
1649#endif
1650        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
1651        {
1652          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
1653        }
1654      }
1655    }
1656  }
1657}
1658#else
1659Void TEncTop::xInitILRP()
1660{
1661#if O0096_REP_FORMAT_INDEX
1662  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_cSPS.getUpdateRepFormatFlag() ? m_cSPS.getUpdateRepFormatIndex() : m_layerId ) );
1663#else
1664  RepFormat *repFormat = m_cVPS.getVpsRepFormat( m_cVPS.getVpsRepFormatIdx( m_layerId ) );
1665#endif
1666  Int bitDepthY,bitDepthC,picWidth,picHeight;
1667
1668#if O0096_REP_FORMAT_INDEX
1669  bitDepthY   = repFormat->getBitDepthVpsLuma();
1670  bitDepthC   = repFormat->getBitDepthVpsChroma();
1671  picWidth    = repFormat->getPicWidthVpsInLumaSamples();
1672  picHeight   = repFormat->getPicHeightVpsInLumaSamples();
1673#else
1674  if( m_cSPS.getUpdateRepFormatFlag() )
1675  {
1676    bitDepthY   = m_cSPS.getBitDepthY();
1677    bitDepthC   = m_cSPS.getBitDepthC();
1678    picWidth    = m_cSPS.getPicWidthInLumaSamples();
1679    picHeight   = m_cSPS.getPicHeightInLumaSamples();
1680  }
1681  else
1682  {
1683    bitDepthY   = repFormat->getBitDepthVpsLuma();
1684    bitDepthC   = repFormat->getBitDepthVpsChroma();
1685    picWidth    = repFormat->getPicWidthVpsInLumaSamples();
1686    picHeight   = repFormat->getPicHeightVpsInLumaSamples();
1687  }
1688#endif
1689 
1690  if(m_layerId > 0)
1691  {
1692    g_bitDepthY     = bitDepthY;
1693    g_bitDepthC     = bitDepthC;
1694    g_uiMaxCUWidth  = m_cSPS.getMaxCUWidth();
1695    g_uiMaxCUHeight = m_cSPS.getMaxCUHeight();
1696    g_uiMaxCUDepth  = m_cSPS.getMaxCUDepth();
1697    g_uiAddCUDepth  = max (0, m_cSPS.getLog2MinCodingBlockSize() - (Int)m_cSPS.getQuadtreeTULog2MinSize() );
1698
1699    Int  numReorderPics[MAX_TLAYER];
1700#if R0156_CONF_WINDOW_IN_REP_FORMAT
1701    Window &conformanceWindow = repFormat->getConformanceWindowVps();
1702#else
1703    Window &conformanceWindow = m_cSPS.getConformanceWindow();
1704#endif
1705    Window defaultDisplayWindow = m_cSPS.getVuiParametersPresentFlag() ? m_cSPS.getVuiParameters()->getDefaultDisplayWindow() : Window();
1706
1707    if (m_cIlpPic[0] == NULL)
1708    {
1709      for (Int j=0; j < m_numDirectRefLayers; j++)
1710      {
1711        m_cIlpPic[j] = new  TComPic;
1712#if AUXILIARY_PICTURES
1713        m_cIlpPic[j]->create(picWidth, picHeight, m_chromaFormatIDC, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
1714#else
1715        m_cIlpPic[j]->create(picWidth, picHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth, conformanceWindow, defaultDisplayWindow, numReorderPics, &m_cSPS, true);
1716#endif
1717        for (Int i=0; i<m_cIlpPic[j]->getPicSym()->getNumberOfCUsInFrame(); i++)
1718        {
1719          m_cIlpPic[j]->getPicSym()->getCU(i)->initCU(m_cIlpPic[j], i);
1720        }
1721      }
1722    }
1723  }
1724}
1725#endif
1726
1727#if O0098_SCALED_REF_LAYER_ID
1728Window& TEncTop::getScaledRefLayerWindowForLayer(Int layerId)
1729{
1730  static Window win;
1731
1732  for (Int i = 0; i < m_numScaledRefLayerOffsets; i++)
1733  {
1734    if (layerId == m_scaledRefLayerId[i])
1735    {
1736      return m_scaledRefLayerWindow[i];
1737    }
1738  }
1739
1740  win.resetWindow();  // scaled reference layer offsets are inferred to be zero when not present
1741  return win;
1742}
1743#if REF_REGION_OFFSET
1744Window& TEncTop::getRefLayerWindowForLayer(Int layerId)
1745{
1746  static Window win;
1747
1748  for (Int i = 0; i < m_numScaledRefLayerOffsets; i++)
1749  {
1750    if (layerId == m_refLayerId[i])
1751    {
1752      return m_refLayerWindow[i];
1753    }
1754  }
1755
1756  win.resetWindow();  // reference offsets are inferred to be zero when not present
1757  return win;
1758}
1759#endif
1760#endif
1761
1762#endif //SVC_EXTENSION
1763//! \}
Note: See TracBrowser for help on using the repository browser.