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-2013, 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 TEncGOP.cpp |
---|
35 | \brief GOP encoder class |
---|
36 | */ |
---|
37 | |
---|
38 | #include <list> |
---|
39 | #include <algorithm> |
---|
40 | #include <functional> |
---|
41 | |
---|
42 | #include "TEncTop.h" |
---|
43 | #include "TEncGOP.h" |
---|
44 | #include "TEncAnalyze.h" |
---|
45 | #include "libmd5/MD5.h" |
---|
46 | #include "TLibCommon/SEI.h" |
---|
47 | #include "TLibCommon/NAL.h" |
---|
48 | #include "NALwrite.h" |
---|
49 | #include <time.h> |
---|
50 | #include <math.h> |
---|
51 | |
---|
52 | using namespace std; |
---|
53 | //! \ingroup TLibEncoder |
---|
54 | //! \{ |
---|
55 | |
---|
56 | // ==================================================================================================================== |
---|
57 | // Constructor / destructor / initialization / destroy |
---|
58 | // ==================================================================================================================== |
---|
59 | Int getLSB(Int poc, Int maxLSB) |
---|
60 | { |
---|
61 | if (poc >= 0) |
---|
62 | { |
---|
63 | return poc % maxLSB; |
---|
64 | } |
---|
65 | else |
---|
66 | { |
---|
67 | return (maxLSB - ((-poc) % maxLSB)) % maxLSB; |
---|
68 | } |
---|
69 | } |
---|
70 | |
---|
71 | TEncGOP::TEncGOP() |
---|
72 | { |
---|
73 | m_iLastIDR = 0; |
---|
74 | m_iGopSize = 0; |
---|
75 | m_iNumPicCoded = 0; //Niko |
---|
76 | m_bFirst = true; |
---|
77 | |
---|
78 | m_pcCfg = NULL; |
---|
79 | m_pcSliceEncoder = NULL; |
---|
80 | m_pcListPic = NULL; |
---|
81 | |
---|
82 | m_pcEntropyCoder = NULL; |
---|
83 | m_pcCavlcCoder = NULL; |
---|
84 | m_pcSbacCoder = NULL; |
---|
85 | m_pcBinCABAC = NULL; |
---|
86 | |
---|
87 | m_bSeqFirst = true; |
---|
88 | |
---|
89 | m_bRefreshPending = 0; |
---|
90 | m_pocCRA = 0; |
---|
91 | m_numLongTermRefPicSPS = 0; |
---|
92 | ::memset(m_ltRefPicPocLsbSps, 0, sizeof(m_ltRefPicPocLsbSps)); |
---|
93 | ::memset(m_ltRefPicUsedByCurrPicFlag, 0, sizeof(m_ltRefPicUsedByCurrPicFlag)); |
---|
94 | m_cpbRemovalDelay = 0; |
---|
95 | m_lastBPSEI = 0; |
---|
96 | #if L0045_NON_NESTED_SEI_RESTRICTIONS |
---|
97 | xResetNonNestedSEIPresentFlags(); |
---|
98 | #endif |
---|
99 | |
---|
100 | #if H_MV |
---|
101 | m_layerId = 0; |
---|
102 | m_viewId = 0; |
---|
103 | m_pocLastCoded = -1; |
---|
104 | #if H_3D |
---|
105 | m_isDepth = false; |
---|
106 | #endif |
---|
107 | #endif |
---|
108 | |
---|
109 | return; |
---|
110 | } |
---|
111 | |
---|
112 | TEncGOP::~TEncGOP() |
---|
113 | { |
---|
114 | } |
---|
115 | |
---|
116 | /** Create list to contain pointers to LCU start addresses of slice. |
---|
117 | */ |
---|
118 | Void TEncGOP::create() |
---|
119 | { |
---|
120 | m_bLongtermTestPictureHasBeenCoded = 0; |
---|
121 | m_bLongtermTestPictureHasBeenCoded2 = 0; |
---|
122 | } |
---|
123 | |
---|
124 | Void TEncGOP::destroy() |
---|
125 | { |
---|
126 | } |
---|
127 | |
---|
128 | Void TEncGOP::init ( TEncTop* pcTEncTop ) |
---|
129 | { |
---|
130 | m_pcEncTop = pcTEncTop; |
---|
131 | m_pcCfg = pcTEncTop; |
---|
132 | m_pcSliceEncoder = pcTEncTop->getSliceEncoder(); |
---|
133 | m_pcListPic = pcTEncTop->getListPic(); |
---|
134 | |
---|
135 | m_pcEntropyCoder = pcTEncTop->getEntropyCoder(); |
---|
136 | m_pcCavlcCoder = pcTEncTop->getCavlcCoder(); |
---|
137 | m_pcSbacCoder = pcTEncTop->getSbacCoder(); |
---|
138 | m_pcBinCABAC = pcTEncTop->getBinCABAC(); |
---|
139 | m_pcLoopFilter = pcTEncTop->getLoopFilter(); |
---|
140 | m_pcBitCounter = pcTEncTop->getBitCounter(); |
---|
141 | |
---|
142 | //--Adaptive Loop filter |
---|
143 | m_pcSAO = pcTEncTop->getSAO(); |
---|
144 | m_pcRateCtrl = pcTEncTop->getRateCtrl(); |
---|
145 | m_lastBPSEI = 0; |
---|
146 | m_totalCoded = 0; |
---|
147 | |
---|
148 | #if H_MV |
---|
149 | m_ivPicLists = pcTEncTop->getIvPicLists(); |
---|
150 | m_layerId = pcTEncTop->getLayerId(); |
---|
151 | m_viewId = pcTEncTop->getViewId(); |
---|
152 | #if H_3D |
---|
153 | m_isDepth = pcTEncTop->getIsDepth(); |
---|
154 | #endif |
---|
155 | #endif |
---|
156 | } |
---|
157 | |
---|
158 | SEIActiveParameterSets* TEncGOP::xCreateSEIActiveParameterSets (TComSPS *sps) |
---|
159 | { |
---|
160 | SEIActiveParameterSets *seiActiveParameterSets = new SEIActiveParameterSets(); |
---|
161 | seiActiveParameterSets->activeVPSId = m_pcCfg->getVPS()->getVPSId(); |
---|
162 | #if L0047_APS_FLAGS |
---|
163 | seiActiveParameterSets->m_fullRandomAccessFlag = false; |
---|
164 | seiActiveParameterSets->m_noParamSetUpdateFlag = false; |
---|
165 | #endif |
---|
166 | seiActiveParameterSets->numSpsIdsMinus1 = 0; |
---|
167 | seiActiveParameterSets->activeSeqParamSetId.resize(seiActiveParameterSets->numSpsIdsMinus1 + 1); |
---|
168 | seiActiveParameterSets->activeSeqParamSetId[0] = sps->getSPSId(); |
---|
169 | return seiActiveParameterSets; |
---|
170 | } |
---|
171 | |
---|
172 | SEIFramePacking* TEncGOP::xCreateSEIFramePacking() |
---|
173 | { |
---|
174 | SEIFramePacking *seiFramePacking = new SEIFramePacking(); |
---|
175 | seiFramePacking->m_arrangementId = m_pcCfg->getFramePackingArrangementSEIId(); |
---|
176 | seiFramePacking->m_arrangementCancelFlag = 0; |
---|
177 | seiFramePacking->m_arrangementType = m_pcCfg->getFramePackingArrangementSEIType(); |
---|
178 | #if L0444_FPA_TYPE |
---|
179 | assert((seiFramePacking->m_arrangementType > 2) && (seiFramePacking->m_arrangementType < 6) ); |
---|
180 | #endif |
---|
181 | seiFramePacking->m_quincunxSamplingFlag = m_pcCfg->getFramePackingArrangementSEIQuincunx(); |
---|
182 | seiFramePacking->m_contentInterpretationType = m_pcCfg->getFramePackingArrangementSEIInterpretation(); |
---|
183 | seiFramePacking->m_spatialFlippingFlag = 0; |
---|
184 | seiFramePacking->m_frame0FlippedFlag = 0; |
---|
185 | seiFramePacking->m_fieldViewsFlag = (seiFramePacking->m_arrangementType == 2); |
---|
186 | seiFramePacking->m_currentFrameIsFrame0Flag = ((seiFramePacking->m_arrangementType == 5) && m_iNumPicCoded&1); |
---|
187 | seiFramePacking->m_frame0SelfContainedFlag = 0; |
---|
188 | seiFramePacking->m_frame1SelfContainedFlag = 0; |
---|
189 | seiFramePacking->m_frame0GridPositionX = 0; |
---|
190 | seiFramePacking->m_frame0GridPositionY = 0; |
---|
191 | seiFramePacking->m_frame1GridPositionX = 0; |
---|
192 | seiFramePacking->m_frame1GridPositionY = 0; |
---|
193 | seiFramePacking->m_arrangementReservedByte = 0; |
---|
194 | #if L0045_PERSISTENCE_FLAGS |
---|
195 | seiFramePacking->m_arrangementPersistenceFlag = true; |
---|
196 | #else |
---|
197 | seiFramePacking->m_arrangementRepetetionPeriod = 1; |
---|
198 | #endif |
---|
199 | seiFramePacking->m_upsampledAspectRatio = 0; |
---|
200 | return seiFramePacking; |
---|
201 | } |
---|
202 | |
---|
203 | SEIDisplayOrientation* TEncGOP::xCreateSEIDisplayOrientation() |
---|
204 | { |
---|
205 | SEIDisplayOrientation *seiDisplayOrientation = new SEIDisplayOrientation(); |
---|
206 | seiDisplayOrientation->cancelFlag = false; |
---|
207 | seiDisplayOrientation->horFlip = false; |
---|
208 | seiDisplayOrientation->verFlip = false; |
---|
209 | seiDisplayOrientation->anticlockwiseRotation = m_pcCfg->getDisplayOrientationSEIAngle(); |
---|
210 | return seiDisplayOrientation; |
---|
211 | } |
---|
212 | |
---|
213 | Void TEncGOP::xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps) |
---|
214 | { |
---|
215 | OutputNALUnit nalu(NAL_UNIT_SEI); |
---|
216 | |
---|
217 | if(m_pcCfg->getActiveParameterSetsSEIEnabled()) |
---|
218 | { |
---|
219 | SEIActiveParameterSets *sei = xCreateSEIActiveParameterSets (sps); |
---|
220 | |
---|
221 | //nalu = NALUnit(NAL_UNIT_SEI); |
---|
222 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
223 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
224 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
225 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
226 | delete sei; |
---|
227 | #if L0045_NON_NESTED_SEI_RESTRICTIONS |
---|
228 | m_activeParameterSetSEIPresentInAU = true; |
---|
229 | #endif |
---|
230 | } |
---|
231 | |
---|
232 | if(m_pcCfg->getFramePackingArrangementSEIEnabled()) |
---|
233 | { |
---|
234 | SEIFramePacking *sei = xCreateSEIFramePacking (); |
---|
235 | |
---|
236 | nalu = NALUnit(NAL_UNIT_SEI); |
---|
237 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
238 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
239 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
240 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
241 | delete sei; |
---|
242 | } |
---|
243 | if (m_pcCfg->getDisplayOrientationSEIAngle()) |
---|
244 | { |
---|
245 | SEIDisplayOrientation *sei = xCreateSEIDisplayOrientation(); |
---|
246 | |
---|
247 | nalu = NALUnit(NAL_UNIT_SEI); |
---|
248 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
249 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); |
---|
250 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
251 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
252 | delete sei; |
---|
253 | } |
---|
254 | } |
---|
255 | |
---|
256 | // ==================================================================================================================== |
---|
257 | // Public member functions |
---|
258 | // ==================================================================================================================== |
---|
259 | |
---|
260 | #if H_MV |
---|
261 | Void TEncGOP::initGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP) |
---|
262 | { |
---|
263 | xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut ); |
---|
264 | m_iNumPicCoded = 0; |
---|
265 | } |
---|
266 | #endif |
---|
267 | |
---|
268 | #if H_MV |
---|
269 | Void TEncGOP::compressPicInGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid) |
---|
270 | #else |
---|
271 | Void TEncGOP::compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP) |
---|
272 | #endif |
---|
273 | { |
---|
274 | TComPic* pcPic; |
---|
275 | TComPicYuv* pcPicYuvRecOut; |
---|
276 | TComSlice* pcSlice; |
---|
277 | TComOutputBitstream* pcBitstreamRedirect = new TComOutputBitstream; |
---|
278 | AccessUnit::iterator itLocationToPushSliceHeaderNALU; // used to store location where NALU containing slice header is to be inserted |
---|
279 | UInt uiOneBitstreamPerSliceLength = 0; |
---|
280 | TEncSbac* pcSbacCoders = NULL; |
---|
281 | TComOutputBitstream* pcSubstreamsOut = NULL; |
---|
282 | |
---|
283 | #if !H_MV |
---|
284 | xInitGOP( iPOCLast, iNumPicRcvd, rcListPic, rcListPicYuvRecOut ); |
---|
285 | |
---|
286 | m_iNumPicCoded = 0; |
---|
287 | #endif |
---|
288 | |
---|
289 | SEIPictureTiming pictureTimingSEI; |
---|
290 | #if L0044_DU_DPB_OUTPUT_DELAY_HRD |
---|
291 | Int picSptDpbOutputDuDelay = 0; |
---|
292 | #endif |
---|
293 | UInt *accumBitsDU = NULL; |
---|
294 | UInt *accumNalsDU = NULL; |
---|
295 | SEIDecodingUnitInfo decodingUnitInfoSEI; |
---|
296 | |
---|
297 | #if !H_MV |
---|
298 | for ( Int iGOPid=0; iGOPid < m_iGopSize; iGOPid++ ) |
---|
299 | #endif |
---|
300 | |
---|
301 | { |
---|
302 | UInt uiColDir = 1; |
---|
303 | //-- For time output for each slice |
---|
304 | long iBeforeTime = clock(); |
---|
305 | |
---|
306 | //select uiColDir |
---|
307 | Int iCloseLeft=1, iCloseRight=-1; |
---|
308 | for(Int i = 0; i<m_pcCfg->getGOPEntry(iGOPid).m_numRefPics; i++) |
---|
309 | { |
---|
310 | Int iRef = m_pcCfg->getGOPEntry(iGOPid).m_referencePics[i]; |
---|
311 | if(iRef>0&&(iRef<iCloseRight||iCloseRight==-1)) |
---|
312 | { |
---|
313 | iCloseRight=iRef; |
---|
314 | } |
---|
315 | else if(iRef<0&&(iRef>iCloseLeft||iCloseLeft==1)) |
---|
316 | { |
---|
317 | iCloseLeft=iRef; |
---|
318 | } |
---|
319 | } |
---|
320 | if(iCloseRight>-1) |
---|
321 | { |
---|
322 | iCloseRight=iCloseRight+m_pcCfg->getGOPEntry(iGOPid).m_POC-1; |
---|
323 | } |
---|
324 | if(iCloseLeft<1) |
---|
325 | { |
---|
326 | iCloseLeft=iCloseLeft+m_pcCfg->getGOPEntry(iGOPid).m_POC-1; |
---|
327 | while(iCloseLeft<0) |
---|
328 | { |
---|
329 | iCloseLeft+=m_iGopSize; |
---|
330 | } |
---|
331 | } |
---|
332 | Int iLeftQP=0, iRightQP=0; |
---|
333 | for(Int i=0; i<m_iGopSize; i++) |
---|
334 | { |
---|
335 | if(m_pcCfg->getGOPEntry(i).m_POC==(iCloseLeft%m_iGopSize)+1) |
---|
336 | { |
---|
337 | iLeftQP= m_pcCfg->getGOPEntry(i).m_QPOffset; |
---|
338 | } |
---|
339 | if (m_pcCfg->getGOPEntry(i).m_POC==(iCloseRight%m_iGopSize)+1) |
---|
340 | { |
---|
341 | iRightQP=m_pcCfg->getGOPEntry(i).m_QPOffset; |
---|
342 | } |
---|
343 | } |
---|
344 | if(iCloseRight>-1&&iRightQP<iLeftQP) |
---|
345 | { |
---|
346 | uiColDir=0; |
---|
347 | } |
---|
348 | |
---|
349 | /////////////////////////////////////////////////////////////////////////////////////////////////// Initial to start encoding |
---|
350 | Int pocCurr = iPOCLast -iNumPicRcvd+ m_pcCfg->getGOPEntry(iGOPid).m_POC; |
---|
351 | Int iTimeOffset = m_pcCfg->getGOPEntry(iGOPid).m_POC; |
---|
352 | if(iPOCLast == 0) |
---|
353 | { |
---|
354 | pocCurr=0; |
---|
355 | iTimeOffset = 1; |
---|
356 | } |
---|
357 | if(pocCurr>=m_pcCfg->getFramesToBeEncoded()) |
---|
358 | { |
---|
359 | |
---|
360 | #if H_MV |
---|
361 | delete pcBitstreamRedirect; |
---|
362 | return; |
---|
363 | #else |
---|
364 | continue; |
---|
365 | #endif |
---|
366 | |
---|
367 | } |
---|
368 | |
---|
369 | if( getNalUnitType(pocCurr) == NAL_UNIT_CODED_SLICE_IDR || getNalUnitType(pocCurr) == NAL_UNIT_CODED_SLICE_IDR_N_LP ) |
---|
370 | { |
---|
371 | m_iLastIDR = pocCurr; |
---|
372 | } |
---|
373 | // start a new access unit: create an entry in the list of output access units |
---|
374 | accessUnitsInGOP.push_back(AccessUnit()); |
---|
375 | AccessUnit& accessUnit = accessUnitsInGOP.back(); |
---|
376 | xGetBuffer( rcListPic, rcListPicYuvRecOut, iNumPicRcvd, iTimeOffset, pcPic, pcPicYuvRecOut, pocCurr ); |
---|
377 | |
---|
378 | // Slice data initialization |
---|
379 | pcPic->clearSliceBuffer(); |
---|
380 | assert(pcPic->getNumAllocatedSlice() == 1); |
---|
381 | m_pcSliceEncoder->setSliceIdx(0); |
---|
382 | pcPic->setCurrSliceIdx(0); |
---|
383 | |
---|
384 | m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() ); |
---|
385 | pcSlice->setLastIDR(m_iLastIDR); |
---|
386 | pcSlice->setSliceIdx(0); |
---|
387 | |
---|
388 | #if H_MV |
---|
389 | pcPic ->setLayerId ( getLayerId() ); |
---|
390 | pcPic ->setViewId ( getViewId() ); |
---|
391 | pcSlice->setLayerId ( getLayerId() ); |
---|
392 | pcSlice->setViewId ( getViewId() ); |
---|
393 | pcSlice->setVPS ( m_pcEncTop->getVPS() ); |
---|
394 | #if H_3D |
---|
395 | pcPic ->setIsDepth( getIsDepth() ); |
---|
396 | pcSlice->setIsDepth( getIsDepth() ); |
---|
397 | #endif |
---|
398 | #endif |
---|
399 | |
---|
400 | //set default slice level flag to the same as SPS level flag |
---|
401 | pcSlice->setLFCrossSliceBoundaryFlag( pcSlice->getPPS()->getLoopFilterAcrossSlicesEnabledFlag() ); |
---|
402 | pcSlice->setScalingList ( m_pcEncTop->getScalingList() ); |
---|
403 | pcSlice->getScalingList()->setUseTransformSkip(m_pcEncTop->getPPS()->getUseTransformSkip()); |
---|
404 | if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_OFF) |
---|
405 | { |
---|
406 | m_pcEncTop->getTrQuant()->setFlatScalingList(); |
---|
407 | m_pcEncTop->getTrQuant()->setUseScalingList(false); |
---|
408 | m_pcEncTop->getSPS()->setScalingListPresentFlag(false); |
---|
409 | m_pcEncTop->getPPS()->setScalingListPresentFlag(false); |
---|
410 | } |
---|
411 | else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_DEFAULT) |
---|
412 | { |
---|
413 | pcSlice->setDefaultScalingList (); |
---|
414 | m_pcEncTop->getSPS()->setScalingListPresentFlag(false); |
---|
415 | m_pcEncTop->getPPS()->setScalingListPresentFlag(false); |
---|
416 | m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList()); |
---|
417 | m_pcEncTop->getTrQuant()->setUseScalingList(true); |
---|
418 | } |
---|
419 | else if(m_pcEncTop->getUseScalingListId() == SCALING_LIST_FILE_READ) |
---|
420 | { |
---|
421 | if(pcSlice->getScalingList()->xParseScalingList(m_pcCfg->getScalingListFile())) |
---|
422 | { |
---|
423 | pcSlice->setDefaultScalingList (); |
---|
424 | } |
---|
425 | pcSlice->getScalingList()->checkDcOfMatrix(); |
---|
426 | m_pcEncTop->getSPS()->setScalingListPresentFlag(pcSlice->checkDefaultScalingList()); |
---|
427 | m_pcEncTop->getPPS()->setScalingListPresentFlag(false); |
---|
428 | m_pcEncTop->getTrQuant()->setScalingList(pcSlice->getScalingList()); |
---|
429 | m_pcEncTop->getTrQuant()->setUseScalingList(true); |
---|
430 | } |
---|
431 | else |
---|
432 | { |
---|
433 | printf("error : ScalingList == %d no support\n",m_pcEncTop->getUseScalingListId()); |
---|
434 | assert(0); |
---|
435 | } |
---|
436 | |
---|
437 | #if H_MV |
---|
438 | // Set the nal unit type |
---|
439 | pcSlice->setNalUnitType(getNalUnitType(pocCurr)); |
---|
440 | if( pcSlice->getSliceType() == B_SLICE ) |
---|
441 | { |
---|
442 | if( m_pcCfg->getGOPEntry( ( pcSlice->getRapPicFlag() && getLayerId() > 0 ) ? MAX_GOP : iGOPid ).m_sliceType == 'P' ) |
---|
443 | { |
---|
444 | pcSlice->setSliceType( P_SLICE ); |
---|
445 | } |
---|
446 | } |
---|
447 | #else |
---|
448 | if(pcSlice->getSliceType()==B_SLICE&&m_pcCfg->getGOPEntry(iGOPid).m_sliceType=='P') |
---|
449 | { |
---|
450 | pcSlice->setSliceType(P_SLICE); |
---|
451 | } |
---|
452 | // Set the nal unit type |
---|
453 | pcSlice->setNalUnitType(getNalUnitType(pocCurr)); |
---|
454 | #endif |
---|
455 | if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R) |
---|
456 | { |
---|
457 | if(pcSlice->getTemporalLayerNonReferenceFlag()) |
---|
458 | { |
---|
459 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N); |
---|
460 | } |
---|
461 | } |
---|
462 | |
---|
463 | // Do decoding refresh marking if any |
---|
464 | pcSlice->decodingRefreshMarking(m_pocCRA, m_bRefreshPending, rcListPic); |
---|
465 | m_pcEncTop->selectReferencePictureSet(pcSlice, pocCurr, iGOPid); |
---|
466 | pcSlice->getRPS()->setNumberOfLongtermPictures(0); |
---|
467 | |
---|
468 | if(pcSlice->checkThatAllRefPicsAreAvailable(rcListPic, pcSlice->getRPS(), false) != 0) |
---|
469 | { |
---|
470 | pcSlice->createExplicitReferencePictureSetFromReference(rcListPic, pcSlice->getRPS()); |
---|
471 | } |
---|
472 | pcSlice->applyReferencePictureSet(rcListPic, pcSlice->getRPS()); |
---|
473 | |
---|
474 | if(pcSlice->getTLayer() > 0) |
---|
475 | { |
---|
476 | if(pcSlice->isTemporalLayerSwitchingPoint(rcListPic) || pcSlice->getSPS()->getTemporalIdNestingFlag()) |
---|
477 | { |
---|
478 | if(pcSlice->getTemporalLayerNonReferenceFlag()) |
---|
479 | { |
---|
480 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TSA_N); |
---|
481 | } |
---|
482 | else |
---|
483 | { |
---|
484 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA); |
---|
485 | } |
---|
486 | } |
---|
487 | else if(pcSlice->isStepwiseTemporalLayerSwitchingPointCandidate(rcListPic)) |
---|
488 | { |
---|
489 | Bool isSTSA=true; |
---|
490 | for(Int ii=iGOPid+1;(ii<m_pcCfg->getGOPSize() && isSTSA==true);ii++) |
---|
491 | { |
---|
492 | Int lTid= m_pcCfg->getGOPEntry(ii).m_temporalId; |
---|
493 | if(lTid==pcSlice->getTLayer()) |
---|
494 | { |
---|
495 | TComReferencePictureSet* nRPS = pcSlice->getSPS()->getRPSList()->getReferencePictureSet(ii); |
---|
496 | for(Int jj=0;jj<nRPS->getNumberOfPictures();jj++) |
---|
497 | { |
---|
498 | if(nRPS->getUsed(jj)) |
---|
499 | { |
---|
500 | Int tPoc=m_pcCfg->getGOPEntry(ii).m_POC+nRPS->getDeltaPOC(jj); |
---|
501 | Int kk=0; |
---|
502 | for(kk=0;kk<m_pcCfg->getGOPSize();kk++) |
---|
503 | { |
---|
504 | if(m_pcCfg->getGOPEntry(kk).m_POC==tPoc) |
---|
505 | break; |
---|
506 | } |
---|
507 | Int tTid=m_pcCfg->getGOPEntry(kk).m_temporalId; |
---|
508 | if(tTid >= pcSlice->getTLayer()) |
---|
509 | { |
---|
510 | isSTSA=false; |
---|
511 | break; |
---|
512 | } |
---|
513 | } |
---|
514 | } |
---|
515 | } |
---|
516 | } |
---|
517 | if(isSTSA==true) |
---|
518 | { |
---|
519 | if(pcSlice->getTemporalLayerNonReferenceFlag()) |
---|
520 | { |
---|
521 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_N); |
---|
522 | } |
---|
523 | else |
---|
524 | { |
---|
525 | pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_STSA_R); |
---|
526 | } |
---|
527 | } |
---|
528 | } |
---|
529 | } |
---|
530 | arrangeLongtermPicturesInRPS(pcSlice, rcListPic); |
---|
531 | TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification(); |
---|
532 | refPicListModification->setRefPicListModificationFlagL0(0); |
---|
533 | refPicListModification->setRefPicListModificationFlagL1(0); |
---|
534 | #if H_MV |
---|
535 | pcSlice->createAndApplyIvReferencePictureSet( m_ivPicLists, m_refPicSetInterLayer ); |
---|
536 | pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && getLayerId() > 0) ? MAX_GOP : iGOPid ).m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer.size() ) ) ); |
---|
537 | pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && getLayerId() > 0) ? MAX_GOP : iGOPid ).m_numRefPicsActive,( pcSlice->getRPS()->getNumberOfPictures() + (Int) m_refPicSetInterLayer.size() ) ) ); |
---|
538 | xSetRefPicListModificationsMvc( pcSlice, pocCurr, iGOPid ); |
---|
539 | #else |
---|
540 | pcSlice->setNumRefIdx(REF_PIC_LIST_0,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures())); |
---|
541 | pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures())); |
---|
542 | #endif |
---|
543 | |
---|
544 | #if ADAPTIVE_QP_SELECTION |
---|
545 | pcSlice->setTrQuant( m_pcEncTop->getTrQuant() ); |
---|
546 | #endif |
---|
547 | |
---|
548 | // Set reference list |
---|
549 | #if H_MV |
---|
550 | pcSlice->setRefPicList( rcListPic, m_refPicSetInterLayer ); |
---|
551 | #else |
---|
552 | pcSlice->setRefPicList ( rcListPic ); |
---|
553 | #endif |
---|
554 | |
---|
555 | // Slice info. refinement |
---|
556 | #if H_MV |
---|
557 | if ( pcSlice->getSliceType() == B_SLICE ) |
---|
558 | { |
---|
559 | if( m_pcCfg->getGOPEntry( ( pcSlice->getRapPicFlag() == true && getLayerId() > 0 ) ? MAX_GOP : iGOPid ).m_sliceType == 'P' ) |
---|
560 | { |
---|
561 | pcSlice->setSliceType( P_SLICE ); |
---|
562 | } |
---|
563 | } |
---|
564 | #else |
---|
565 | if ( (pcSlice->getSliceType() == B_SLICE) && (pcSlice->getNumRefIdx(REF_PIC_LIST_1) == 0) ) |
---|
566 | { |
---|
567 | pcSlice->setSliceType ( P_SLICE ); |
---|
568 | } |
---|
569 | #endif |
---|
570 | |
---|
571 | if (pcSlice->getSliceType() != B_SLICE || !pcSlice->getSPS()->getUseLComb()) |
---|
572 | { |
---|
573 | pcSlice->setNumRefIdx(REF_PIC_LIST_C, 0); |
---|
574 | pcSlice->setRefPicListCombinationFlag(false); |
---|
575 | pcSlice->setRefPicListModificationFlagLC(false); |
---|
576 | } |
---|
577 | else |
---|
578 | { |
---|
579 | pcSlice->setRefPicListCombinationFlag(pcSlice->getSPS()->getUseLComb()); |
---|
580 | pcSlice->setNumRefIdx(REF_PIC_LIST_C, pcSlice->getNumRefIdx(REF_PIC_LIST_0)); |
---|
581 | } |
---|
582 | |
---|
583 | if (pcSlice->getSliceType() == B_SLICE) |
---|
584 | { |
---|
585 | pcSlice->setColFromL0Flag(1-uiColDir); |
---|
586 | Bool bLowDelay = true; |
---|
587 | Int iCurrPOC = pcSlice->getPOC(); |
---|
588 | Int iRefIdx = 0; |
---|
589 | |
---|
590 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_0) && bLowDelay; iRefIdx++) |
---|
591 | { |
---|
592 | if ( pcSlice->getRefPic(REF_PIC_LIST_0, iRefIdx)->getPOC() > iCurrPOC ) |
---|
593 | { |
---|
594 | bLowDelay = false; |
---|
595 | } |
---|
596 | } |
---|
597 | for (iRefIdx = 0; iRefIdx < pcSlice->getNumRefIdx(REF_PIC_LIST_1) && bLowDelay; iRefIdx++) |
---|
598 | { |
---|
599 | if ( pcSlice->getRefPic(REF_PIC_LIST_1, iRefIdx)->getPOC() > iCurrPOC ) |
---|
600 | { |
---|
601 | bLowDelay = false; |
---|
602 | } |
---|
603 | } |
---|
604 | |
---|
605 | pcSlice->setCheckLDC(bLowDelay); |
---|
606 | } |
---|
607 | |
---|
608 | uiColDir = 1-uiColDir; |
---|
609 | |
---|
610 | //------------------------------------------------------------- |
---|
611 | pcSlice->setRefPOCList(); |
---|
612 | |
---|
613 | pcSlice->setNoBackPredFlag( false ); |
---|
614 | if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag()) |
---|
615 | { |
---|
616 | if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) ) |
---|
617 | { |
---|
618 | pcSlice->setNoBackPredFlag( true ); |
---|
619 | Int i; |
---|
620 | for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ ) |
---|
621 | { |
---|
622 | if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) |
---|
623 | { |
---|
624 | pcSlice->setNoBackPredFlag( false ); |
---|
625 | break; |
---|
626 | } |
---|
627 | } |
---|
628 | } |
---|
629 | } |
---|
630 | |
---|
631 | if(pcSlice->getNoBackPredFlag()) |
---|
632 | { |
---|
633 | pcSlice->setNumRefIdx(REF_PIC_LIST_C, 0); |
---|
634 | } |
---|
635 | pcSlice->generateCombinedList(); |
---|
636 | |
---|
637 | if (m_pcEncTop->getTMVPModeId() == 2) |
---|
638 | { |
---|
639 | if (iGOPid == 0) // first picture in SOP (i.e. forward B) |
---|
640 | { |
---|
641 | pcSlice->setEnableTMVPFlag(0); |
---|
642 | } |
---|
643 | else |
---|
644 | { |
---|
645 | // Note: pcSlice->getColFromL0Flag() is assumed to be always 0 and getcolRefIdx() is always 0. |
---|
646 | pcSlice->setEnableTMVPFlag(1); |
---|
647 | } |
---|
648 | pcSlice->getSPS()->setTMVPFlagsPresent(1); |
---|
649 | } |
---|
650 | else if (m_pcEncTop->getTMVPModeId() == 1) |
---|
651 | { |
---|
652 | pcSlice->getSPS()->setTMVPFlagsPresent(1); |
---|
653 | pcSlice->setEnableTMVPFlag(1); |
---|
654 | } |
---|
655 | else |
---|
656 | { |
---|
657 | pcSlice->getSPS()->setTMVPFlagsPresent(0); |
---|
658 | pcSlice->setEnableTMVPFlag(0); |
---|
659 | } |
---|
660 | /////////////////////////////////////////////////////////////////////////////////////////////////// Compress a slice |
---|
661 | // Slice compression |
---|
662 | if (m_pcCfg->getUseASR()) |
---|
663 | { |
---|
664 | m_pcSliceEncoder->setSearchRange(pcSlice); |
---|
665 | } |
---|
666 | |
---|
667 | Bool bGPBcheck=false; |
---|
668 | if ( pcSlice->getSliceType() == B_SLICE) |
---|
669 | { |
---|
670 | if ( pcSlice->getNumRefIdx(RefPicList( 0 ) ) == pcSlice->getNumRefIdx(RefPicList( 1 ) ) ) |
---|
671 | { |
---|
672 | bGPBcheck=true; |
---|
673 | Int i; |
---|
674 | for ( i=0; i < pcSlice->getNumRefIdx(RefPicList( 1 ) ); i++ ) |
---|
675 | { |
---|
676 | if ( pcSlice->getRefPOC(RefPicList(1), i) != pcSlice->getRefPOC(RefPicList(0), i) ) |
---|
677 | { |
---|
678 | bGPBcheck=false; |
---|
679 | break; |
---|
680 | } |
---|
681 | } |
---|
682 | } |
---|
683 | } |
---|
684 | if(bGPBcheck) |
---|
685 | { |
---|
686 | pcSlice->setMvdL1ZeroFlag(true); |
---|
687 | } |
---|
688 | else |
---|
689 | { |
---|
690 | pcSlice->setMvdL1ZeroFlag(false); |
---|
691 | } |
---|
692 | pcPic->getSlice(pcSlice->getSliceIdx())->setMvdL1ZeroFlag(pcSlice->getMvdL1ZeroFlag()); |
---|
693 | |
---|
694 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
695 | Int sliceQP = pcSlice->getSliceQp(); |
---|
696 | Double lambda = 0.0; |
---|
697 | Int actualHeadBits = 0; |
---|
698 | Int actualTotalBits = 0; |
---|
699 | Int estimatedBits = 0; |
---|
700 | Int tmpBitsBeforeWriting = 0; |
---|
701 | if ( m_pcCfg->getUseRateCtrl() ) |
---|
702 | { |
---|
703 | Int frameLevel = m_pcRateCtrl->getRCSeq()->getGOPID2Level( iGOPid ); |
---|
704 | if ( pcPic->getSlice(0)->getSliceType() == I_SLICE ) |
---|
705 | { |
---|
706 | frameLevel = 0; |
---|
707 | } |
---|
708 | m_pcRateCtrl->initRCPic( frameLevel ); |
---|
709 | estimatedBits = m_pcRateCtrl->getRCPic()->getTargetBits(); |
---|
710 | |
---|
711 | if ( ( pcSlice->getPOC() == 0 && m_pcCfg->getInitialQP() > 0 ) || ( frameLevel == 0 && m_pcCfg->getForceIntraQP() ) ) // QP is specified |
---|
712 | { |
---|
713 | sliceQP = m_pcCfg->getInitialQP(); |
---|
714 | Int NumberBFrames = ( m_pcCfg->getGOPSize() - 1 ); |
---|
715 | Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames ); |
---|
716 | Double dQPFactor = 0.57*dLambda_scale; |
---|
717 | Int SHIFT_QP = 12; |
---|
718 | Int bitdepth_luma_qp_scale = 0; |
---|
719 | Double qp_temp = (Double) sliceQP + bitdepth_luma_qp_scale - SHIFT_QP; |
---|
720 | lambda = dQPFactor*pow( 2.0, qp_temp/3.0 ); |
---|
721 | } |
---|
722 | else if ( frameLevel == 0 ) // intra case, but use the model |
---|
723 | { |
---|
724 | if ( m_pcCfg->getIntraPeriod() != 1 ) // do not refine allocated bits for all intra case |
---|
725 | { |
---|
726 | Int bits = m_pcRateCtrl->getRCSeq()->getLeftAverageBits(); |
---|
727 | bits = m_pcRateCtrl->getRCSeq()->getRefineBitsForIntra( bits ); |
---|
728 | if ( bits < 200 ) |
---|
729 | { |
---|
730 | bits = 200; |
---|
731 | } |
---|
732 | m_pcRateCtrl->getRCPic()->setTargetBits( bits ); |
---|
733 | } |
---|
734 | |
---|
735 | list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); |
---|
736 | lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture ); |
---|
737 | sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); |
---|
738 | } |
---|
739 | else // normal case |
---|
740 | { |
---|
741 | list<TEncRCPic*> listPreviousPicture = m_pcRateCtrl->getPicList(); |
---|
742 | lambda = m_pcRateCtrl->getRCPic()->estimatePicLambda( listPreviousPicture ); |
---|
743 | sliceQP = m_pcRateCtrl->getRCPic()->estimatePicQP( lambda, listPreviousPicture ); |
---|
744 | } |
---|
745 | |
---|
746 | sliceQP = Clip3( -pcSlice->getSPS()->getQpBDOffsetY(), MAX_QP, sliceQP ); |
---|
747 | m_pcRateCtrl->getRCPic()->setPicEstQP( sliceQP ); |
---|
748 | |
---|
749 | m_pcSliceEncoder->resetQP( pcPic, sliceQP, lambda ); |
---|
750 | } |
---|
751 | #endif |
---|
752 | |
---|
753 | UInt uiNumSlices = 1; |
---|
754 | |
---|
755 | UInt uiInternalAddress = pcPic->getNumPartInCU()-4; |
---|
756 | UInt uiExternalAddress = pcPic->getPicSym()->getNumberOfCUsInFrame()-1; |
---|
757 | UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
758 | UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
759 | UInt uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
760 | UInt uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
761 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
762 | { |
---|
763 | uiInternalAddress--; |
---|
764 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
765 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
766 | } |
---|
767 | uiInternalAddress++; |
---|
768 | if(uiInternalAddress==pcPic->getNumPartInCU()) |
---|
769 | { |
---|
770 | uiInternalAddress = 0; |
---|
771 | uiExternalAddress++; |
---|
772 | } |
---|
773 | UInt uiRealEndAddress = uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress; |
---|
774 | |
---|
775 | UInt uiCummulativeTileWidth; |
---|
776 | UInt uiCummulativeTileHeight; |
---|
777 | Int p, j; |
---|
778 | UInt uiEncCUAddr; |
---|
779 | |
---|
780 | //set NumColumnsMinus1 and NumRowsMinus1 |
---|
781 | pcPic->getPicSym()->setNumColumnsMinus1( pcSlice->getPPS()->getNumColumnsMinus1() ); |
---|
782 | pcPic->getPicSym()->setNumRowsMinus1( pcSlice->getPPS()->getNumRowsMinus1() ); |
---|
783 | |
---|
784 | //create the TComTileArray |
---|
785 | pcPic->getPicSym()->xCreateTComTileArray(); |
---|
786 | |
---|
787 | if( pcSlice->getPPS()->getUniformSpacingFlag() == 1 ) |
---|
788 | { |
---|
789 | //set the width for each tile |
---|
790 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
791 | { |
---|
792 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1()+1; p++) |
---|
793 | { |
---|
794 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )-> |
---|
795 | setTileWidth( (p+1)*pcPic->getPicSym()->getFrameWidthInCU()/(pcPic->getPicSym()->getNumColumnsMinus1()+1) |
---|
796 | - (p*pcPic->getPicSym()->getFrameWidthInCU())/(pcPic->getPicSym()->getNumColumnsMinus1()+1) ); |
---|
797 | } |
---|
798 | } |
---|
799 | |
---|
800 | //set the height for each tile |
---|
801 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
802 | { |
---|
803 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1()+1; p++) |
---|
804 | { |
---|
805 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )-> |
---|
806 | setTileHeight( (p+1)*pcPic->getPicSym()->getFrameHeightInCU()/(pcPic->getPicSym()->getNumRowsMinus1()+1) |
---|
807 | - (p*pcPic->getPicSym()->getFrameHeightInCU())/(pcPic->getPicSym()->getNumRowsMinus1()+1) ); |
---|
808 | } |
---|
809 | } |
---|
810 | } |
---|
811 | else |
---|
812 | { |
---|
813 | //set the width for each tile |
---|
814 | for(j=0; j < pcPic->getPicSym()->getNumRowsMinus1()+1; j++) |
---|
815 | { |
---|
816 | uiCummulativeTileWidth = 0; |
---|
817 | for(p=0; p < pcPic->getPicSym()->getNumColumnsMinus1(); p++) |
---|
818 | { |
---|
819 | pcPic->getPicSym()->getTComTile( j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p )->setTileWidth( pcSlice->getPPS()->getColumnWidth(p) ); |
---|
820 | uiCummulativeTileWidth += pcSlice->getPPS()->getColumnWidth(p); |
---|
821 | } |
---|
822 | pcPic->getPicSym()->getTComTile(j * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + p)->setTileWidth( pcPic->getPicSym()->getFrameWidthInCU()-uiCummulativeTileWidth ); |
---|
823 | } |
---|
824 | |
---|
825 | //set the height for each tile |
---|
826 | for(j=0; j < pcPic->getPicSym()->getNumColumnsMinus1()+1; j++) |
---|
827 | { |
---|
828 | uiCummulativeTileHeight = 0; |
---|
829 | for(p=0; p < pcPic->getPicSym()->getNumRowsMinus1(); p++) |
---|
830 | { |
---|
831 | pcPic->getPicSym()->getTComTile( p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j )->setTileHeight( pcSlice->getPPS()->getRowHeight(p) ); |
---|
832 | uiCummulativeTileHeight += pcSlice->getPPS()->getRowHeight(p); |
---|
833 | } |
---|
834 | pcPic->getPicSym()->getTComTile(p * (pcPic->getPicSym()->getNumColumnsMinus1()+1) + j)->setTileHeight( pcPic->getPicSym()->getFrameHeightInCU()-uiCummulativeTileHeight ); |
---|
835 | } |
---|
836 | } |
---|
837 | //intialize each tile of the current picture |
---|
838 | pcPic->getPicSym()->xInitTiles(); |
---|
839 | |
---|
840 | // Allocate some coders, now we know how many tiles there are. |
---|
841 | Int iNumSubstreams = pcSlice->getPPS()->getNumSubstreams(); |
---|
842 | |
---|
843 | //generate the Coding Order Map and Inverse Coding Order Map |
---|
844 | for(p=0, uiEncCUAddr=0; p<pcPic->getPicSym()->getNumberOfCUsInFrame(); p++, uiEncCUAddr = pcPic->getPicSym()->xCalculateNxtCUAddr(uiEncCUAddr)) |
---|
845 | { |
---|
846 | pcPic->getPicSym()->setCUOrderMap(p, uiEncCUAddr); |
---|
847 | pcPic->getPicSym()->setInverseCUOrderMap(uiEncCUAddr, p); |
---|
848 | } |
---|
849 | pcPic->getPicSym()->setCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
850 | pcPic->getPicSym()->setInverseCUOrderMap(pcPic->getPicSym()->getNumberOfCUsInFrame(), pcPic->getPicSym()->getNumberOfCUsInFrame()); |
---|
851 | |
---|
852 | // Allocate some coders, now we know how many tiles there are. |
---|
853 | m_pcEncTop->createWPPCoders(iNumSubstreams); |
---|
854 | pcSbacCoders = m_pcEncTop->getSbacCoders(); |
---|
855 | pcSubstreamsOut = new TComOutputBitstream[iNumSubstreams]; |
---|
856 | |
---|
857 | UInt startCUAddrSliceIdx = 0; // used to index "m_uiStoredStartCUAddrForEncodingSlice" containing locations of slice boundaries |
---|
858 | UInt startCUAddrSlice = 0; // used to keep track of current slice's starting CU addr. |
---|
859 | pcSlice->setSliceCurStartCUAddr( startCUAddrSlice ); // Setting "start CU addr" for current slice |
---|
860 | m_storedStartCUAddrForEncodingSlice.clear(); |
---|
861 | |
---|
862 | UInt startCUAddrSliceSegmentIdx = 0; // used to index "m_uiStoredStartCUAddrForEntropyEncodingSlice" containing locations of slice boundaries |
---|
863 | UInt startCUAddrSliceSegment = 0; // used to keep track of current Dependent slice's starting CU addr. |
---|
864 | pcSlice->setSliceSegmentCurStartCUAddr( startCUAddrSliceSegment ); // Setting "start CU addr" for current Dependent slice |
---|
865 | |
---|
866 | m_storedStartCUAddrForEncodingSliceSegment.clear(); |
---|
867 | UInt nextCUAddr = 0; |
---|
868 | m_storedStartCUAddrForEncodingSlice.push_back (nextCUAddr); |
---|
869 | startCUAddrSliceIdx++; |
---|
870 | m_storedStartCUAddrForEncodingSliceSegment.push_back(nextCUAddr); |
---|
871 | startCUAddrSliceSegmentIdx++; |
---|
872 | |
---|
873 | while(nextCUAddr<uiRealEndAddress) // determine slice boundaries |
---|
874 | { |
---|
875 | pcSlice->setNextSlice ( false ); |
---|
876 | pcSlice->setNextSliceSegment( false ); |
---|
877 | assert(pcPic->getNumAllocatedSlice() == startCUAddrSliceIdx); |
---|
878 | m_pcSliceEncoder->precompressSlice( pcPic ); |
---|
879 | m_pcSliceEncoder->compressSlice ( pcPic ); |
---|
880 | |
---|
881 | Bool bNoBinBitConstraintViolated = (!pcSlice->isNextSlice() && !pcSlice->isNextSliceSegment()); |
---|
882 | if (pcSlice->isNextSlice() || (bNoBinBitConstraintViolated && m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_LCU)) |
---|
883 | { |
---|
884 | startCUAddrSlice = pcSlice->getSliceCurEndCUAddr(); |
---|
885 | // Reconstruction slice |
---|
886 | m_storedStartCUAddrForEncodingSlice.push_back(startCUAddrSlice); |
---|
887 | startCUAddrSliceIdx++; |
---|
888 | // Dependent slice |
---|
889 | if (startCUAddrSliceSegmentIdx>0 && m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx-1] != startCUAddrSlice) |
---|
890 | { |
---|
891 | m_storedStartCUAddrForEncodingSliceSegment.push_back(startCUAddrSlice); |
---|
892 | startCUAddrSliceSegmentIdx++; |
---|
893 | } |
---|
894 | |
---|
895 | if (startCUAddrSlice < uiRealEndAddress) |
---|
896 | { |
---|
897 | pcPic->allocateNewSlice(); |
---|
898 | pcPic->setCurrSliceIdx ( startCUAddrSliceIdx-1 ); |
---|
899 | m_pcSliceEncoder->setSliceIdx ( startCUAddrSliceIdx-1 ); |
---|
900 | pcSlice = pcPic->getSlice ( startCUAddrSliceIdx-1 ); |
---|
901 | pcSlice->copySliceInfo ( pcPic->getSlice(0) ); |
---|
902 | pcSlice->setSliceIdx ( startCUAddrSliceIdx-1 ); |
---|
903 | pcSlice->setSliceCurStartCUAddr ( startCUAddrSlice ); |
---|
904 | pcSlice->setSliceSegmentCurStartCUAddr ( startCUAddrSlice ); |
---|
905 | pcSlice->setSliceBits(0); |
---|
906 | uiNumSlices ++; |
---|
907 | } |
---|
908 | } |
---|
909 | else if (pcSlice->isNextSliceSegment() || (bNoBinBitConstraintViolated && m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_LCU)) |
---|
910 | { |
---|
911 | startCUAddrSliceSegment = pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
912 | m_storedStartCUAddrForEncodingSliceSegment.push_back(startCUAddrSliceSegment); |
---|
913 | startCUAddrSliceSegmentIdx++; |
---|
914 | pcSlice->setSliceSegmentCurStartCUAddr( startCUAddrSliceSegment ); |
---|
915 | } |
---|
916 | else |
---|
917 | { |
---|
918 | startCUAddrSlice = pcSlice->getSliceCurEndCUAddr(); |
---|
919 | startCUAddrSliceSegment = pcSlice->getSliceSegmentCurEndCUAddr(); |
---|
920 | } |
---|
921 | |
---|
922 | nextCUAddr = (startCUAddrSlice > startCUAddrSliceSegment) ? startCUAddrSlice : startCUAddrSliceSegment; |
---|
923 | } |
---|
924 | m_storedStartCUAddrForEncodingSlice.push_back( pcSlice->getSliceCurEndCUAddr()); |
---|
925 | startCUAddrSliceIdx++; |
---|
926 | m_storedStartCUAddrForEncodingSliceSegment.push_back(pcSlice->getSliceCurEndCUAddr()); |
---|
927 | startCUAddrSliceSegmentIdx++; |
---|
928 | |
---|
929 | pcSlice = pcPic->getSlice(0); |
---|
930 | |
---|
931 | // SAO parameter estimation using non-deblocked pixels for LCU bottom and right boundary areas |
---|
932 | if( m_pcCfg->getSaoLcuBasedOptimization() && m_pcCfg->getSaoLcuBoundary() ) |
---|
933 | { |
---|
934 | m_pcSAO->resetStats(); |
---|
935 | m_pcSAO->calcSaoStatsCu_BeforeDblk( pcPic ); |
---|
936 | } |
---|
937 | |
---|
938 | //-- Loop filter |
---|
939 | Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag(); |
---|
940 | m_pcLoopFilter->setCfg(bLFCrossTileBoundary); |
---|
941 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
942 | |
---|
943 | pcSlice = pcPic->getSlice(0); |
---|
944 | if(pcSlice->getSPS()->getUseSAO()) |
---|
945 | { |
---|
946 | std::vector<Bool> LFCrossSliceBoundaryFlag; |
---|
947 | for(Int s=0; s< uiNumSlices; s++) |
---|
948 | { |
---|
949 | LFCrossSliceBoundaryFlag.push_back( ((uiNumSlices==1)?true:pcPic->getSlice(s)->getLFCrossSliceBoundaryFlag()) ); |
---|
950 | } |
---|
951 | m_storedStartCUAddrForEncodingSlice.resize(uiNumSlices+1); |
---|
952 | pcPic->createNonDBFilterInfo(m_storedStartCUAddrForEncodingSlice, 0, &LFCrossSliceBoundaryFlag ,pcPic->getPicSym()->getNumTiles() ,bLFCrossTileBoundary); |
---|
953 | } |
---|
954 | |
---|
955 | |
---|
956 | pcSlice = pcPic->getSlice(0); |
---|
957 | |
---|
958 | if(pcSlice->getSPS()->getUseSAO()) |
---|
959 | { |
---|
960 | m_pcSAO->createPicSaoInfo(pcPic); |
---|
961 | } |
---|
962 | |
---|
963 | /////////////////////////////////////////////////////////////////////////////////////////////////// File writing |
---|
964 | // Set entropy coder |
---|
965 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
966 | |
---|
967 | /* write various header sets. */ |
---|
968 | if ( m_bSeqFirst ) |
---|
969 | { |
---|
970 | OutputNALUnit nalu(NAL_UNIT_VPS); |
---|
971 | #if H_MV |
---|
972 | if( getLayerId() == 0 ) |
---|
973 | { |
---|
974 | #endif |
---|
975 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
976 | m_pcEntropyCoder->encodeVPS(m_pcEncTop->getVPS()); |
---|
977 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
978 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
979 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
980 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
981 | #endif |
---|
982 | |
---|
983 | #if H_MV |
---|
984 | } |
---|
985 | nalu = NALUnit(NAL_UNIT_SPS, 0, getLayerId()); |
---|
986 | #else |
---|
987 | nalu = NALUnit(NAL_UNIT_SPS); |
---|
988 | #endif |
---|
989 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
990 | if (m_bSeqFirst) |
---|
991 | { |
---|
992 | pcSlice->getSPS()->setNumLongTermRefPicSPS(m_numLongTermRefPicSPS); |
---|
993 | for (Int k = 0; k < m_numLongTermRefPicSPS; k++) |
---|
994 | { |
---|
995 | pcSlice->getSPS()->setLtRefPicPocLsbSps(k, m_ltRefPicPocLsbSps[k]); |
---|
996 | pcSlice->getSPS()->setUsedByCurrPicLtSPSFlag(k, m_ltRefPicUsedByCurrPicFlag[k]); |
---|
997 | } |
---|
998 | } |
---|
999 | if( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) |
---|
1000 | { |
---|
1001 | UInt maxCU = m_pcCfg->getSliceArgument() >> ( pcSlice->getSPS()->getMaxCUDepth() << 1); |
---|
1002 | UInt numDU = ( m_pcCfg->getSliceMode() == 1 ) ? ( pcPic->getNumCUsInFrame() / maxCU ) : ( 0 ); |
---|
1003 | if( pcPic->getNumCUsInFrame() % maxCU != 0 ) |
---|
1004 | { |
---|
1005 | numDU ++; |
---|
1006 | } |
---|
1007 | pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->setNumDU( numDU ); |
---|
1008 | pcSlice->getSPS()->setHrdParameters( m_pcCfg->getFrameRate(), numDU, m_pcCfg->getTargetBitrate(), ( m_pcCfg->getIntraPeriod() > 0 ) ); |
---|
1009 | } |
---|
1010 | if( m_pcCfg->getBufferingPeriodSEIEnabled() || m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) |
---|
1011 | { |
---|
1012 | pcSlice->getSPS()->getVuiParameters()->setHrdParametersPresentFlag( true ); |
---|
1013 | } |
---|
1014 | m_pcEntropyCoder->encodeSPS(pcSlice->getSPS()); |
---|
1015 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1016 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1017 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
1018 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
1019 | #endif |
---|
1020 | |
---|
1021 | #if H_MV |
---|
1022 | nalu = NALUnit(NAL_UNIT_PPS, 0, getLayerId()); |
---|
1023 | #else |
---|
1024 | nalu = NALUnit(NAL_UNIT_PPS); |
---|
1025 | #endif |
---|
1026 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1027 | m_pcEntropyCoder->encodePPS(pcSlice->getPPS()); |
---|
1028 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1029 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1030 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
1031 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
1032 | #endif |
---|
1033 | |
---|
1034 | xCreateLeadingSEIMessages(accessUnit, pcSlice->getSPS()); |
---|
1035 | |
---|
1036 | m_bSeqFirst = false; |
---|
1037 | } |
---|
1038 | |
---|
1039 | if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && |
---|
1040 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
1041 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
1042 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) ) |
---|
1043 | { |
---|
1044 | if( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getSubPicCpbParamsPresentFlag() ) |
---|
1045 | { |
---|
1046 | UInt numDU = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNumDU(); |
---|
1047 | pictureTimingSEI.m_numDecodingUnitsMinus1 = ( numDU - 1 ); |
---|
1048 | pictureTimingSEI.m_duCommonCpbRemovalDelayFlag = false; |
---|
1049 | |
---|
1050 | if( pictureTimingSEI.m_numNalusInDuMinus1 == NULL ) |
---|
1051 | { |
---|
1052 | pictureTimingSEI.m_numNalusInDuMinus1 = new UInt[ numDU ]; |
---|
1053 | } |
---|
1054 | if( pictureTimingSEI.m_duCpbRemovalDelayMinus1 == NULL ) |
---|
1055 | { |
---|
1056 | pictureTimingSEI.m_duCpbRemovalDelayMinus1 = new UInt[ numDU ]; |
---|
1057 | } |
---|
1058 | if( accumBitsDU == NULL ) |
---|
1059 | { |
---|
1060 | accumBitsDU = new UInt[ numDU ]; |
---|
1061 | } |
---|
1062 | if( accumNalsDU == NULL ) |
---|
1063 | { |
---|
1064 | accumNalsDU = new UInt[ numDU ]; |
---|
1065 | } |
---|
1066 | } |
---|
1067 | pictureTimingSEI.m_auCpbRemovalDelay = std::max<Int>(1, m_totalCoded - m_lastBPSEI); // Syntax element signalled as minus, hence the . |
---|
1068 | pictureTimingSEI.m_picDpbOutputDelay = pcSlice->getSPS()->getNumReorderPics(0) + pcSlice->getPOC() - m_totalCoded; |
---|
1069 | #if L0044_DU_DPB_OUTPUT_DELAY_HRD |
---|
1070 | Int factor = pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2; |
---|
1071 | pictureTimingSEI.m_picDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay; |
---|
1072 | if( m_pcCfg->getDecodingUnitInfoSEIEnabled() ) |
---|
1073 | { |
---|
1074 | picSptDpbOutputDuDelay = factor * pictureTimingSEI.m_picDpbOutputDelay; |
---|
1075 | } |
---|
1076 | #endif |
---|
1077 | } |
---|
1078 | |
---|
1079 | if( ( m_pcCfg->getBufferingPeriodSEIEnabled() ) && ( pcSlice->getSliceType() == I_SLICE ) && |
---|
1080 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
1081 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
1082 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) ) |
---|
1083 | { |
---|
1084 | OutputNALUnit nalu(NAL_UNIT_SEI); |
---|
1085 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1086 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1087 | |
---|
1088 | SEIBufferingPeriod sei_buffering_period; |
---|
1089 | |
---|
1090 | UInt uiInitialCpbRemovalDelay = (90000/2); // 0.5 sec |
---|
1091 | sei_buffering_period.m_initialCpbRemovalDelay [0][0] = uiInitialCpbRemovalDelay; |
---|
1092 | sei_buffering_period.m_initialCpbRemovalDelayOffset[0][0] = uiInitialCpbRemovalDelay; |
---|
1093 | sei_buffering_period.m_initialCpbRemovalDelay [0][1] = uiInitialCpbRemovalDelay; |
---|
1094 | sei_buffering_period.m_initialCpbRemovalDelayOffset[0][1] = uiInitialCpbRemovalDelay; |
---|
1095 | |
---|
1096 | #if L0043_TIMING_INFO |
---|
1097 | Double dTmp = (Double)pcSlice->getSPS()->getVuiParameters()->getTimingInfo()->getNumUnitsInTick() / (Double)pcSlice->getSPS()->getVuiParameters()->getTimingInfo()->getTimeScale(); |
---|
1098 | #else |
---|
1099 | Double dTmp = (Double)pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNumUnitsInTick() / (Double)pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTimeScale(); |
---|
1100 | #endif |
---|
1101 | |
---|
1102 | UInt uiTmp = (UInt)( dTmp * 90000.0 ); |
---|
1103 | uiInitialCpbRemovalDelay -= uiTmp; |
---|
1104 | uiInitialCpbRemovalDelay -= uiTmp / ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getTickDivisorMinus2() + 2 ); |
---|
1105 | sei_buffering_period.m_initialAltCpbRemovalDelay [0][0] = uiInitialCpbRemovalDelay; |
---|
1106 | sei_buffering_period.m_initialAltCpbRemovalDelayOffset[0][0] = uiInitialCpbRemovalDelay; |
---|
1107 | sei_buffering_period.m_initialAltCpbRemovalDelay [0][1] = uiInitialCpbRemovalDelay; |
---|
1108 | sei_buffering_period.m_initialAltCpbRemovalDelayOffset[0][1] = uiInitialCpbRemovalDelay; |
---|
1109 | |
---|
1110 | sei_buffering_period.m_rapCpbParamsPresentFlag = 0; |
---|
1111 | #if L0328_SPLICING |
---|
1112 | //for the concatenation, it can be set to one during splicing. |
---|
1113 | sei_buffering_period.m_concatenationFlag = 0; |
---|
1114 | //since the temporal layer HRD is not ready, we assumed it is fixed |
---|
1115 | sei_buffering_period.m_auCpbRemovalDelayDelta = 1; |
---|
1116 | #endif |
---|
1117 | #if L0044_CPB_DPB_DELAY_OFFSET |
---|
1118 | sei_buffering_period.m_cpbDelayOffset = 0; |
---|
1119 | sei_buffering_period.m_dpbDelayOffset = 0; |
---|
1120 | #endif |
---|
1121 | |
---|
1122 | m_seiWriter.writeSEImessage( nalu.m_Bitstream, sei_buffering_period, pcSlice->getSPS()); |
---|
1123 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1124 | #if L0045_NON_NESTED_SEI_RESTRICTIONS |
---|
1125 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
1126 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU; // Insert BP SEI after APS SEI |
---|
1127 | AccessUnit::iterator it; |
---|
1128 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
1129 | { |
---|
1130 | it++; |
---|
1131 | } |
---|
1132 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
1133 | m_bufferingPeriodSEIPresentInAU = true; |
---|
1134 | #else |
---|
1135 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1136 | #endif |
---|
1137 | |
---|
1138 | m_lastBPSEI = m_totalCoded; |
---|
1139 | m_cpbRemovalDelay = 0; |
---|
1140 | } |
---|
1141 | m_cpbRemovalDelay ++; |
---|
1142 | if( ( m_pcEncTop->getRecoveryPointSEIEnabled() ) && ( pcSlice->getSliceType() == I_SLICE ) ) |
---|
1143 | { |
---|
1144 | if( m_pcEncTop->getGradualDecodingRefreshInfoEnabled() && !pcSlice->getRapPicFlag() ) |
---|
1145 | { |
---|
1146 | // Gradual decoding refresh SEI |
---|
1147 | OutputNALUnit nalu(NAL_UNIT_SEI); |
---|
1148 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1149 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1150 | |
---|
1151 | SEIGradualDecodingRefreshInfo seiGradualDecodingRefreshInfo; |
---|
1152 | seiGradualDecodingRefreshInfo.m_gdrForegroundFlag = true; // Indicating all "foreground" |
---|
1153 | |
---|
1154 | m_seiWriter.writeSEImessage( nalu.m_Bitstream, seiGradualDecodingRefreshInfo, pcSlice->getSPS() ); |
---|
1155 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1156 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1157 | } |
---|
1158 | // Recovery point SEI |
---|
1159 | OutputNALUnit nalu(NAL_UNIT_SEI); |
---|
1160 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1161 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1162 | |
---|
1163 | SEIRecoveryPoint sei_recovery_point; |
---|
1164 | sei_recovery_point.m_recoveryPocCnt = 0; |
---|
1165 | sei_recovery_point.m_exactMatchingFlag = ( pcSlice->getPOC() == 0 ) ? (true) : (false); |
---|
1166 | sei_recovery_point.m_brokenLinkFlag = false; |
---|
1167 | |
---|
1168 | m_seiWriter.writeSEImessage( nalu.m_Bitstream, sei_recovery_point, pcSlice->getSPS() ); |
---|
1169 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1170 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1171 | } |
---|
1172 | |
---|
1173 | /* use the main bitstream buffer for storing the marshalled picture */ |
---|
1174 | m_pcEntropyCoder->setBitstream(NULL); |
---|
1175 | |
---|
1176 | startCUAddrSliceIdx = 0; |
---|
1177 | startCUAddrSlice = 0; |
---|
1178 | |
---|
1179 | startCUAddrSliceSegmentIdx = 0; |
---|
1180 | startCUAddrSliceSegment = 0; |
---|
1181 | nextCUAddr = 0; |
---|
1182 | pcSlice = pcPic->getSlice(startCUAddrSliceIdx); |
---|
1183 | |
---|
1184 | Int processingState = (pcSlice->getSPS()->getUseSAO())?(EXECUTE_INLOOPFILTER):(ENCODE_SLICE); |
---|
1185 | Bool skippedSlice=false; |
---|
1186 | while (nextCUAddr < uiRealEndAddress) // Iterate over all slices |
---|
1187 | { |
---|
1188 | switch(processingState) |
---|
1189 | { |
---|
1190 | case ENCODE_SLICE: |
---|
1191 | { |
---|
1192 | pcSlice->setNextSlice ( false ); |
---|
1193 | pcSlice->setNextSliceSegment( false ); |
---|
1194 | if (nextCUAddr == m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx]) |
---|
1195 | { |
---|
1196 | pcSlice = pcPic->getSlice(startCUAddrSliceIdx); |
---|
1197 | if(startCUAddrSliceIdx > 0 && pcSlice->getSliceType()!= I_SLICE) |
---|
1198 | { |
---|
1199 | pcSlice->checkColRefIdx(startCUAddrSliceIdx, pcPic); |
---|
1200 | } |
---|
1201 | pcPic->setCurrSliceIdx(startCUAddrSliceIdx); |
---|
1202 | m_pcSliceEncoder->setSliceIdx(startCUAddrSliceIdx); |
---|
1203 | assert(startCUAddrSliceIdx == pcSlice->getSliceIdx()); |
---|
1204 | // Reconstruction slice |
---|
1205 | pcSlice->setSliceCurStartCUAddr( nextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
1206 | pcSlice->setSliceCurEndCUAddr ( m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx+1 ] ); |
---|
1207 | // Dependent slice |
---|
1208 | pcSlice->setSliceSegmentCurStartCUAddr( nextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
1209 | pcSlice->setSliceSegmentCurEndCUAddr ( m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx+1 ] ); |
---|
1210 | |
---|
1211 | pcSlice->setNextSlice ( true ); |
---|
1212 | |
---|
1213 | startCUAddrSliceIdx++; |
---|
1214 | startCUAddrSliceSegmentIdx++; |
---|
1215 | } |
---|
1216 | else if (nextCUAddr == m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx]) |
---|
1217 | { |
---|
1218 | // Dependent slice |
---|
1219 | pcSlice->setSliceSegmentCurStartCUAddr( nextCUAddr ); // to be used in encodeSlice() + context restriction |
---|
1220 | pcSlice->setSliceSegmentCurEndCUAddr ( m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx+1 ] ); |
---|
1221 | |
---|
1222 | pcSlice->setNextSliceSegment( true ); |
---|
1223 | |
---|
1224 | startCUAddrSliceSegmentIdx++; |
---|
1225 | } |
---|
1226 | |
---|
1227 | pcSlice->setRPS(pcPic->getSlice(0)->getRPS()); |
---|
1228 | pcSlice->setRPSidx(pcPic->getSlice(0)->getRPSidx()); |
---|
1229 | UInt uiDummyStartCUAddr; |
---|
1230 | UInt uiDummyBoundingCUAddr; |
---|
1231 | m_pcSliceEncoder->xDetermineStartAndBoundingCUAddr(uiDummyStartCUAddr,uiDummyBoundingCUAddr,pcPic,true); |
---|
1232 | |
---|
1233 | uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) % pcPic->getNumPartInCU(); |
---|
1234 | uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) / pcPic->getNumPartInCU(); |
---|
1235 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1236 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1237 | uiWidth = pcSlice->getSPS()->getPicWidthInLumaSamples(); |
---|
1238 | uiHeight = pcSlice->getSPS()->getPicHeightInLumaSamples(); |
---|
1239 | while(uiPosX>=uiWidth||uiPosY>=uiHeight) |
---|
1240 | { |
---|
1241 | uiInternalAddress--; |
---|
1242 | uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1243 | uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; |
---|
1244 | } |
---|
1245 | uiInternalAddress++; |
---|
1246 | if(uiInternalAddress==pcPic->getNumPartInCU()) |
---|
1247 | { |
---|
1248 | uiInternalAddress = 0; |
---|
1249 | uiExternalAddress = pcPic->getPicSym()->getCUOrderMap(pcPic->getPicSym()->getInverseCUOrderMap(uiExternalAddress)+1); |
---|
1250 | } |
---|
1251 | UInt endAddress = pcPic->getPicSym()->getPicSCUEncOrder(uiExternalAddress*pcPic->getNumPartInCU()+uiInternalAddress); |
---|
1252 | if(endAddress<=pcSlice->getSliceSegmentCurStartCUAddr()) |
---|
1253 | { |
---|
1254 | UInt boundingAddrSlice, boundingAddrSliceSegment; |
---|
1255 | boundingAddrSlice = m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx]; |
---|
1256 | boundingAddrSliceSegment = m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx]; |
---|
1257 | nextCUAddr = min(boundingAddrSlice, boundingAddrSliceSegment); |
---|
1258 | if(pcSlice->isNextSlice()) |
---|
1259 | { |
---|
1260 | skippedSlice=true; |
---|
1261 | } |
---|
1262 | continue; |
---|
1263 | } |
---|
1264 | if(skippedSlice) |
---|
1265 | { |
---|
1266 | pcSlice->setNextSlice ( true ); |
---|
1267 | pcSlice->setNextSliceSegment( false ); |
---|
1268 | } |
---|
1269 | skippedSlice=false; |
---|
1270 | pcSlice->allocSubstreamSizes( iNumSubstreams ); |
---|
1271 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
1272 | { |
---|
1273 | pcSubstreamsOut[ui].clear(); |
---|
1274 | } |
---|
1275 | |
---|
1276 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
1277 | m_pcEntropyCoder->resetEntropy (); |
---|
1278 | /* start slice NALunit */ |
---|
1279 | #if H_MV |
---|
1280 | OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->getTLayer(), getLayerId() ); |
---|
1281 | #else |
---|
1282 | OutputNALUnit nalu( pcSlice->getNalUnitType(), pcSlice->getTLayer() ); |
---|
1283 | #endif |
---|
1284 | Bool sliceSegment = (!pcSlice->isNextSlice()); |
---|
1285 | if (!sliceSegment) |
---|
1286 | { |
---|
1287 | uiOneBitstreamPerSliceLength = 0; // start of a new slice |
---|
1288 | } |
---|
1289 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1290 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
1291 | tmpBitsBeforeWriting = m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1292 | #endif |
---|
1293 | m_pcEntropyCoder->encodeSliceHeader(pcSlice); |
---|
1294 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
1295 | actualHeadBits += ( m_pcEntropyCoder->getNumberOfWrittenBits() - tmpBitsBeforeWriting ); |
---|
1296 | #endif |
---|
1297 | |
---|
1298 | // is it needed? |
---|
1299 | { |
---|
1300 | if (!sliceSegment) |
---|
1301 | { |
---|
1302 | pcBitstreamRedirect->writeAlignOne(); |
---|
1303 | } |
---|
1304 | else |
---|
1305 | { |
---|
1306 | // We've not completed our slice header info yet, do the alignment later. |
---|
1307 | } |
---|
1308 | m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC ); |
---|
1309 | m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); |
---|
1310 | m_pcEntropyCoder->resetEntropy (); |
---|
1311 | for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams() ; ui++ ) |
---|
1312 | { |
---|
1313 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
1314 | m_pcEntropyCoder->resetEntropy (); |
---|
1315 | } |
---|
1316 | } |
---|
1317 | |
---|
1318 | if(pcSlice->isNextSlice()) |
---|
1319 | { |
---|
1320 | // set entropy coder for writing |
---|
1321 | m_pcSbacCoder->init( (TEncBinIf*)m_pcBinCABAC ); |
---|
1322 | { |
---|
1323 | for ( UInt ui = 0 ; ui < pcSlice->getPPS()->getNumSubstreams() ; ui++ ) |
---|
1324 | { |
---|
1325 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
1326 | m_pcEntropyCoder->resetEntropy (); |
---|
1327 | } |
---|
1328 | pcSbacCoders[0].load(m_pcSbacCoder); |
---|
1329 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[0], pcSlice ); //ALF is written in substream #0 with CABAC coder #0 (see ALF param encoding below) |
---|
1330 | } |
---|
1331 | m_pcEntropyCoder->resetEntropy (); |
---|
1332 | // File writing |
---|
1333 | if (!sliceSegment) |
---|
1334 | { |
---|
1335 | m_pcEntropyCoder->setBitstream(pcBitstreamRedirect); |
---|
1336 | } |
---|
1337 | else |
---|
1338 | { |
---|
1339 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1340 | } |
---|
1341 | // for now, override the TILES_DECODER setting in order to write substreams. |
---|
1342 | m_pcEntropyCoder->setBitstream ( &pcSubstreamsOut[0] ); |
---|
1343 | |
---|
1344 | } |
---|
1345 | pcSlice->setFinalized(true); |
---|
1346 | |
---|
1347 | m_pcSbacCoder->load( &pcSbacCoders[0] ); |
---|
1348 | |
---|
1349 | pcSlice->setTileOffstForMultES( uiOneBitstreamPerSliceLength ); |
---|
1350 | if (!sliceSegment) |
---|
1351 | { |
---|
1352 | pcSlice->setTileLocationCount ( 0 ); |
---|
1353 | m_pcSliceEncoder->encodeSlice(pcPic, pcBitstreamRedirect, pcSubstreamsOut); // redirect is only used for CAVLC tile position info. |
---|
1354 | } |
---|
1355 | else |
---|
1356 | { |
---|
1357 | m_pcSliceEncoder->encodeSlice(pcPic, &nalu.m_Bitstream, pcSubstreamsOut); // nalu.m_Bitstream is only used for CAVLC tile position info. |
---|
1358 | } |
---|
1359 | |
---|
1360 | { |
---|
1361 | // Construct the final bitstream by flushing and concatenating substreams. |
---|
1362 | // The final bitstream is either nalu.m_Bitstream or pcBitstreamRedirect; |
---|
1363 | UInt* puiSubstreamSizes = pcSlice->getSubstreamSizes(); |
---|
1364 | UInt uiTotalCodedSize = 0; // for padding calcs. |
---|
1365 | UInt uiNumSubstreamsPerTile = iNumSubstreams; |
---|
1366 | if (iNumSubstreams > 1) |
---|
1367 | { |
---|
1368 | uiNumSubstreamsPerTile /= pcPic->getPicSym()->getNumTiles(); |
---|
1369 | } |
---|
1370 | for ( UInt ui = 0 ; ui < iNumSubstreams; ui++ ) |
---|
1371 | { |
---|
1372 | // Flush all substreams -- this includes empty ones. |
---|
1373 | // Terminating bit and flush. |
---|
1374 | m_pcEntropyCoder->setEntropyCoder ( &pcSbacCoders[ui], pcSlice ); |
---|
1375 | m_pcEntropyCoder->setBitstream ( &pcSubstreamsOut[ui] ); |
---|
1376 | m_pcEntropyCoder->encodeTerminatingBit( 1 ); |
---|
1377 | m_pcEntropyCoder->encodeSliceFinish(); |
---|
1378 | |
---|
1379 | pcSubstreamsOut[ui].writeByteAlignment(); // Byte-alignment in slice_data() at end of sub-stream |
---|
1380 | // Byte alignment is necessary between tiles when tiles are independent. |
---|
1381 | uiTotalCodedSize += pcSubstreamsOut[ui].getNumberOfWrittenBits(); |
---|
1382 | |
---|
1383 | Bool bNextSubstreamInNewTile = ((ui+1) < iNumSubstreams)&& ((ui+1)%uiNumSubstreamsPerTile == 0); |
---|
1384 | if (bNextSubstreamInNewTile) |
---|
1385 | { |
---|
1386 | pcSlice->setTileLocation(ui/uiNumSubstreamsPerTile, pcSlice->getTileOffstForMultES()+(uiTotalCodedSize>>3)); |
---|
1387 | } |
---|
1388 | if (ui+1 < pcSlice->getPPS()->getNumSubstreams()) |
---|
1389 | { |
---|
1390 | puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits(); |
---|
1391 | } |
---|
1392 | } |
---|
1393 | |
---|
1394 | // Complete the slice header info. |
---|
1395 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
1396 | m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); |
---|
1397 | m_pcEntropyCoder->encodeTilesWPPEntryPoint( pcSlice ); |
---|
1398 | |
---|
1399 | // Substreams... |
---|
1400 | TComOutputBitstream *pcOut = pcBitstreamRedirect; |
---|
1401 | Int offs = 0; |
---|
1402 | Int nss = pcSlice->getPPS()->getNumSubstreams(); |
---|
1403 | if (pcSlice->getPPS()->getEntropyCodingSyncEnabledFlag()) |
---|
1404 | { |
---|
1405 | // 1st line present for WPP. |
---|
1406 | offs = pcSlice->getSliceSegmentCurStartCUAddr()/pcSlice->getPic()->getNumPartInCU()/pcSlice->getPic()->getFrameWidthInCU(); |
---|
1407 | nss = pcSlice->getNumEntryPointOffsets()+1; |
---|
1408 | } |
---|
1409 | for ( UInt ui = 0 ; ui < nss; ui++ ) |
---|
1410 | { |
---|
1411 | pcOut->addSubstream(&pcSubstreamsOut[ui+offs]); |
---|
1412 | } |
---|
1413 | } |
---|
1414 | |
---|
1415 | UInt boundingAddrSlice, boundingAddrSliceSegment; |
---|
1416 | boundingAddrSlice = m_storedStartCUAddrForEncodingSlice[startCUAddrSliceIdx]; |
---|
1417 | boundingAddrSliceSegment = m_storedStartCUAddrForEncodingSliceSegment[startCUAddrSliceSegmentIdx]; |
---|
1418 | nextCUAddr = min(boundingAddrSlice, boundingAddrSliceSegment); |
---|
1419 | // If current NALU is the first NALU of slice (containing slice header) and more NALUs exist (due to multiple dependent slices) then buffer it. |
---|
1420 | // If current NALU is the last NALU of slice and a NALU was buffered, then (a) Write current NALU (b) Update an write buffered NALU at approproate location in NALU list. |
---|
1421 | Bool bNALUAlignedWrittenToList = false; // used to ensure current NALU is not written more than once to the NALU list. |
---|
1422 | xWriteTileLocationToSliceHeader(nalu, pcBitstreamRedirect, pcSlice); |
---|
1423 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1424 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
1425 | actualTotalBits += UInt(accessUnit.back()->m_nalUnitData.str().size()) * 8; |
---|
1426 | #endif |
---|
1427 | bNALUAlignedWrittenToList = true; |
---|
1428 | uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits(); // length of bitstream after byte-alignment |
---|
1429 | |
---|
1430 | if (!bNALUAlignedWrittenToList) |
---|
1431 | { |
---|
1432 | { |
---|
1433 | nalu.m_Bitstream.writeAlignZero(); |
---|
1434 | } |
---|
1435 | accessUnit.push_back(new NALUnitEBSP(nalu)); |
---|
1436 | uiOneBitstreamPerSliceLength += nalu.m_Bitstream.getNumberOfWrittenBits() + 24; // length of bitstream after byte-alignment + 3 byte startcode 0x000001 |
---|
1437 | } |
---|
1438 | |
---|
1439 | if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && |
---|
1440 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
1441 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
1442 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) && |
---|
1443 | ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getSubPicCpbParamsPresentFlag() ) ) |
---|
1444 | { |
---|
1445 | UInt numNalus = 0; |
---|
1446 | UInt numRBSPBytes = 0; |
---|
1447 | for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
1448 | { |
---|
1449 | UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size()); |
---|
1450 | if ((*it)->m_nalUnitType != NAL_UNIT_SEI && (*it)->m_nalUnitType != NAL_UNIT_SEI_SUFFIX) |
---|
1451 | { |
---|
1452 | numRBSPBytes += numRBSPBytes_nal; |
---|
1453 | numNalus ++; |
---|
1454 | } |
---|
1455 | } |
---|
1456 | accumBitsDU[ pcSlice->getSliceIdx() ] = ( numRBSPBytes << 3 ); |
---|
1457 | accumNalsDU[ pcSlice->getSliceIdx() ] = numNalus; // SEI not counted for bit count; hence shouldn't be counted for # of NALUs - only for consistency |
---|
1458 | } |
---|
1459 | processingState = ENCODE_SLICE; |
---|
1460 | } |
---|
1461 | break; |
---|
1462 | case EXECUTE_INLOOPFILTER: |
---|
1463 | { |
---|
1464 | // set entropy coder for RD |
---|
1465 | m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); |
---|
1466 | if ( pcSlice->getSPS()->getUseSAO() ) |
---|
1467 | { |
---|
1468 | m_pcEntropyCoder->resetEntropy(); |
---|
1469 | m_pcEntropyCoder->setBitstream( m_pcBitCounter ); |
---|
1470 | m_pcSAO->startSaoEnc(pcPic, m_pcEntropyCoder, m_pcEncTop->getRDSbacCoder(), m_pcEncTop->getRDGoOnSbacCoder()); |
---|
1471 | SAOParam& cSaoParam = *pcSlice->getPic()->getPicSym()->getSaoParam(); |
---|
1472 | |
---|
1473 | #if SAO_CHROMA_LAMBDA |
---|
1474 | #if SAO_ENCODING_CHOICE |
---|
1475 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma(), pcPic->getSlice(0)->getDepth()); |
---|
1476 | #else |
---|
1477 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambdaLuma(), pcPic->getSlice(0)->getLambdaChroma()); |
---|
1478 | #endif |
---|
1479 | #else |
---|
1480 | m_pcSAO->SAOProcess(&cSaoParam, pcPic->getSlice(0)->getLambda()); |
---|
1481 | #endif |
---|
1482 | m_pcSAO->endSaoEnc(); |
---|
1483 | m_pcSAO->PCMLFDisableProcess(pcPic); |
---|
1484 | } |
---|
1485 | #if SAO_RDO |
---|
1486 | m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice ); |
---|
1487 | #endif |
---|
1488 | processingState = ENCODE_SLICE; |
---|
1489 | |
---|
1490 | for(Int s=0; s< uiNumSlices; s++) |
---|
1491 | { |
---|
1492 | if (pcSlice->getSPS()->getUseSAO()) |
---|
1493 | { |
---|
1494 | pcPic->getSlice(s)->setSaoEnabledFlag((pcSlice->getPic()->getPicSym()->getSaoParam()->bSaoFlag[0]==1)?true:false); |
---|
1495 | } |
---|
1496 | } |
---|
1497 | } |
---|
1498 | break; |
---|
1499 | default: |
---|
1500 | { |
---|
1501 | printf("Not a supported encoding state\n"); |
---|
1502 | assert(0); |
---|
1503 | exit(-1); |
---|
1504 | } |
---|
1505 | } |
---|
1506 | } // end iteration over slices |
---|
1507 | |
---|
1508 | if(pcSlice->getSPS()->getUseSAO()) |
---|
1509 | { |
---|
1510 | if(pcSlice->getSPS()->getUseSAO()) |
---|
1511 | { |
---|
1512 | m_pcSAO->destroyPicSaoInfo(); |
---|
1513 | } |
---|
1514 | pcPic->destroyNonDBFilterInfo(); |
---|
1515 | } |
---|
1516 | |
---|
1517 | #if !H_3D |
---|
1518 | pcPic->compressMotion(); |
---|
1519 | #endif |
---|
1520 | |
---|
1521 | #if H_MV |
---|
1522 | m_pocLastCoded = pcPic->getPOC(); |
---|
1523 | #endif |
---|
1524 | |
---|
1525 | //-- For time output for each slice |
---|
1526 | Double dEncTime = (Double)(clock()-iBeforeTime) / CLOCKS_PER_SEC; |
---|
1527 | |
---|
1528 | const Char* digestStr = NULL; |
---|
1529 | if (m_pcCfg->getDecodedPictureHashSEIEnabled()) |
---|
1530 | { |
---|
1531 | /* calculate MD5sum for entire reconstructed picture */ |
---|
1532 | SEIDecodedPictureHash sei_recon_picture_digest; |
---|
1533 | if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 1) |
---|
1534 | { |
---|
1535 | sei_recon_picture_digest.method = SEIDecodedPictureHash::MD5; |
---|
1536 | calcMD5(*pcPic->getPicYuvRec(), sei_recon_picture_digest.digest); |
---|
1537 | digestStr = digestToString(sei_recon_picture_digest.digest, 16); |
---|
1538 | } |
---|
1539 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 2) |
---|
1540 | { |
---|
1541 | sei_recon_picture_digest.method = SEIDecodedPictureHash::CRC; |
---|
1542 | calcCRC(*pcPic->getPicYuvRec(), sei_recon_picture_digest.digest); |
---|
1543 | digestStr = digestToString(sei_recon_picture_digest.digest, 2); |
---|
1544 | } |
---|
1545 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 3) |
---|
1546 | { |
---|
1547 | sei_recon_picture_digest.method = SEIDecodedPictureHash::CHECKSUM; |
---|
1548 | calcChecksum(*pcPic->getPicYuvRec(), sei_recon_picture_digest.digest); |
---|
1549 | digestStr = digestToString(sei_recon_picture_digest.digest, 4); |
---|
1550 | } |
---|
1551 | OutputNALUnit nalu(NAL_UNIT_SEI_SUFFIX, pcSlice->getTLayer()); |
---|
1552 | |
---|
1553 | /* write the SEI messages */ |
---|
1554 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1555 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei_recon_picture_digest, pcSlice->getSPS()); |
---|
1556 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1557 | |
---|
1558 | accessUnit.insert(accessUnit.end(), new NALUnitEBSP(nalu)); |
---|
1559 | } |
---|
1560 | if (m_pcCfg->getTemporalLevel0IndexSEIEnabled()) |
---|
1561 | { |
---|
1562 | SEITemporalLevel0Index sei_temporal_level0_index; |
---|
1563 | if (pcSlice->getRapPicFlag()) |
---|
1564 | { |
---|
1565 | m_tl0Idx = 0; |
---|
1566 | m_rapIdx = (m_rapIdx + 1) & 0xFF; |
---|
1567 | } |
---|
1568 | else |
---|
1569 | { |
---|
1570 | m_tl0Idx = (m_tl0Idx + (pcSlice->getTLayer() ? 0 : 1)) & 0xFF; |
---|
1571 | } |
---|
1572 | sei_temporal_level0_index.tl0Idx = m_tl0Idx; |
---|
1573 | sei_temporal_level0_index.rapIdx = m_rapIdx; |
---|
1574 | |
---|
1575 | OutputNALUnit nalu(NAL_UNIT_SEI); |
---|
1576 | |
---|
1577 | /* write the SEI messages */ |
---|
1578 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1579 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, sei_temporal_level0_index, pcSlice->getSPS()); |
---|
1580 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1581 | |
---|
1582 | /* insert the SEI message NALUnit before any Slice NALUnits */ |
---|
1583 | AccessUnit::iterator it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice)); |
---|
1584 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
1585 | } |
---|
1586 | |
---|
1587 | xCalculateAddPSNR( pcPic, pcPic->getPicYuvRec(), accessUnit, dEncTime ); |
---|
1588 | |
---|
1589 | if (digestStr) |
---|
1590 | { |
---|
1591 | if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 1) |
---|
1592 | { |
---|
1593 | printf(" [MD5:%s]", digestStr); |
---|
1594 | } |
---|
1595 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 2) |
---|
1596 | { |
---|
1597 | printf(" [CRC:%s]", digestStr); |
---|
1598 | } |
---|
1599 | else if(m_pcCfg->getDecodedPictureHashSEIEnabled() == 3) |
---|
1600 | { |
---|
1601 | printf(" [Checksum:%s]", digestStr); |
---|
1602 | } |
---|
1603 | } |
---|
1604 | #if RATE_CONTROL_LAMBDA_DOMAIN |
---|
1605 | if ( m_pcCfg->getUseRateCtrl() ) |
---|
1606 | { |
---|
1607 | Double effectivePercentage = m_pcRateCtrl->getRCPic()->getEffectivePercentage(); |
---|
1608 | Double avgQP = m_pcRateCtrl->getRCPic()->calAverageQP(); |
---|
1609 | Double avgLambda = m_pcRateCtrl->getRCPic()->calAverageLambda(); |
---|
1610 | if ( avgLambda < 0.0 ) |
---|
1611 | { |
---|
1612 | avgLambda = lambda; |
---|
1613 | } |
---|
1614 | m_pcRateCtrl->getRCPic()->updateAfterPicture( actualHeadBits, actualTotalBits, avgQP, avgLambda, effectivePercentage ); |
---|
1615 | m_pcRateCtrl->getRCPic()->addToPictureLsit( m_pcRateCtrl->getPicList() ); |
---|
1616 | |
---|
1617 | m_pcRateCtrl->getRCSeq()->updateAfterPic( actualTotalBits ); |
---|
1618 | if ( pcSlice->getSliceType() != I_SLICE ) |
---|
1619 | { |
---|
1620 | m_pcRateCtrl->getRCGOP()->updateAfterPicture( actualTotalBits ); |
---|
1621 | } |
---|
1622 | else // for intra picture, the estimated bits are used to update the current status in the GOP |
---|
1623 | { |
---|
1624 | m_pcRateCtrl->getRCGOP()->updateAfterPicture( estimatedBits ); |
---|
1625 | } |
---|
1626 | } |
---|
1627 | #else |
---|
1628 | if(m_pcCfg->getUseRateCtrl()) |
---|
1629 | { |
---|
1630 | UInt frameBits = m_vRVM_RP[m_vRVM_RP.size()-1]; |
---|
1631 | m_pcRateCtrl->updataRCFrameStatus((Int)frameBits, pcSlice->getSliceType()); |
---|
1632 | } |
---|
1633 | #endif |
---|
1634 | if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && |
---|
1635 | ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && |
---|
1636 | ( ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getNalHrdParametersPresentFlag() ) |
---|
1637 | || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) ) |
---|
1638 | { |
---|
1639 | TComVUI *vui = pcSlice->getSPS()->getVuiParameters(); |
---|
1640 | TComHRD *hrd = vui->getHrdParameters(); |
---|
1641 | |
---|
1642 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
1643 | { |
---|
1644 | Int i; |
---|
1645 | UInt64 ui64Tmp; |
---|
1646 | UInt uiPrev = 0; |
---|
1647 | UInt numDU = ( pictureTimingSEI.m_numDecodingUnitsMinus1 + 1 ); |
---|
1648 | UInt *pCRD = &pictureTimingSEI.m_duCpbRemovalDelayMinus1[0]; |
---|
1649 | UInt maxDiff = ( hrd->getTickDivisorMinus2() + 2 ) - 1; |
---|
1650 | |
---|
1651 | for( i = 0; i < numDU; i ++ ) |
---|
1652 | { |
---|
1653 | pictureTimingSEI.m_numNalusInDuMinus1[ i ] = ( i == 0 ) ? ( accumNalsDU[ i ] - 1 ) : ( accumNalsDU[ i ] - accumNalsDU[ i - 1] - 1 ); |
---|
1654 | } |
---|
1655 | |
---|
1656 | if( numDU == 1 ) |
---|
1657 | { |
---|
1658 | pCRD[ 0 ] = 0; /* don't care */ |
---|
1659 | } |
---|
1660 | else |
---|
1661 | { |
---|
1662 | pCRD[ numDU - 1 ] = 0;/* by definition */ |
---|
1663 | UInt tmp = 0; |
---|
1664 | UInt accum = 0; |
---|
1665 | |
---|
1666 | for( i = ( numDU - 2 ); i >= 0; i -- ) |
---|
1667 | { |
---|
1668 | #if L0043_TIMING_INFO |
---|
1669 | ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ] - accumBitsDU[ i ] ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) ); |
---|
1670 | #else |
---|
1671 | ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ] - accumBitsDU[ i ] ) * ( hrd->getTimeScale() / hrd->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) ); |
---|
1672 | #endif |
---|
1673 | if( (UInt)ui64Tmp > maxDiff ) |
---|
1674 | { |
---|
1675 | tmp ++; |
---|
1676 | } |
---|
1677 | } |
---|
1678 | uiPrev = 0; |
---|
1679 | |
---|
1680 | UInt flag = 0; |
---|
1681 | for( i = ( numDU - 2 ); i >= 0; i -- ) |
---|
1682 | { |
---|
1683 | flag = 0; |
---|
1684 | #if L0043_TIMING_INFO |
---|
1685 | ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ] - accumBitsDU[ i ] ) * ( vui->getTimingInfo()->getTimeScale() / vui->getTimingInfo()->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) ); |
---|
1686 | #else |
---|
1687 | ui64Tmp = ( ( ( accumBitsDU[ numDU - 1 ] - accumBitsDU[ i ] ) * ( hrd->getTimeScale() / hrd->getNumUnitsInTick() ) * ( hrd->getTickDivisorMinus2() + 2 ) ) / ( m_pcCfg->getTargetBitrate() ) ); |
---|
1688 | #endif |
---|
1689 | |
---|
1690 | if( (UInt)ui64Tmp > maxDiff ) |
---|
1691 | { |
---|
1692 | if(uiPrev >= maxDiff - tmp) |
---|
1693 | { |
---|
1694 | ui64Tmp = uiPrev + 1; |
---|
1695 | flag = 1; |
---|
1696 | } |
---|
1697 | else ui64Tmp = maxDiff - tmp + 1; |
---|
1698 | } |
---|
1699 | pCRD[ i ] = (UInt)ui64Tmp - uiPrev - 1; |
---|
1700 | if( (Int)pCRD[ i ] < 0 ) |
---|
1701 | { |
---|
1702 | pCRD[ i ] = 0; |
---|
1703 | } |
---|
1704 | else if (tmp > 0 && flag == 1) |
---|
1705 | { |
---|
1706 | tmp --; |
---|
1707 | } |
---|
1708 | accum += pCRD[ i ] + 1; |
---|
1709 | uiPrev = accum; |
---|
1710 | } |
---|
1711 | } |
---|
1712 | } |
---|
1713 | if( m_pcCfg->getPictureTimingSEIEnabled() ) |
---|
1714 | { |
---|
1715 | OutputNALUnit nalu(NAL_UNIT_SEI, pcSlice->getTLayer()); |
---|
1716 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1717 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS()); |
---|
1718 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1719 | #if L0045_NON_NESTED_SEI_RESTRICTIONS |
---|
1720 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
1721 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU |
---|
1722 | + m_bufferingPeriodSEIPresentInAU; // Insert PT SEI after APS and BP SEI |
---|
1723 | AccessUnit::iterator it; |
---|
1724 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
1725 | { |
---|
1726 | it++; |
---|
1727 | } |
---|
1728 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
1729 | m_pictureTimingSEIPresentInAU = true; |
---|
1730 | #else |
---|
1731 | AccessUnit::iterator it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice)); |
---|
1732 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
1733 | #endif |
---|
1734 | } |
---|
1735 | if( m_pcCfg->getDecodingUnitInfoSEIEnabled() && hrd->getSubPicCpbParamsPresentFlag() ) |
---|
1736 | { |
---|
1737 | m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); |
---|
1738 | for( Int i = 0; i < ( pictureTimingSEI.m_numDecodingUnitsMinus1 + 1 ); i ++ ) |
---|
1739 | { |
---|
1740 | OutputNALUnit nalu(NAL_UNIT_SEI, pcSlice->getTLayer()); |
---|
1741 | |
---|
1742 | SEIDecodingUnitInfo tempSEI; |
---|
1743 | tempSEI.m_decodingUnitIdx = i; |
---|
1744 | tempSEI.m_duSptCpbRemovalDelay = pictureTimingSEI.m_duCpbRemovalDelayMinus1[i] + 1; |
---|
1745 | #if L0044_DU_DPB_OUTPUT_DELAY_HRD |
---|
1746 | tempSEI.m_dpbOutputDuDelayPresentFlag = false; |
---|
1747 | tempSEI.m_picSptDpbOutputDuDelay = picSptDpbOutputDuDelay; |
---|
1748 | #endif |
---|
1749 | |
---|
1750 | AccessUnit::iterator it; |
---|
1751 | // Insert the first one in the right location, before the first slice |
---|
1752 | if(i == 0) |
---|
1753 | { |
---|
1754 | // Insert before the first slice. |
---|
1755 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, tempSEI, pcSlice->getSPS()); |
---|
1756 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1757 | |
---|
1758 | #if L0045_NON_NESTED_SEI_RESTRICTIONS |
---|
1759 | UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); |
---|
1760 | UInt offsetPosition = m_activeParameterSetSEIPresentInAU |
---|
1761 | + m_bufferingPeriodSEIPresentInAU |
---|
1762 | + m_pictureTimingSEIPresentInAU; // Insert DU info SEI after APS, BP and PT SEI |
---|
1763 | for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) |
---|
1764 | { |
---|
1765 | it++; |
---|
1766 | } |
---|
1767 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
1768 | #else |
---|
1769 | it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice)); |
---|
1770 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
1771 | #endif |
---|
1772 | } |
---|
1773 | else |
---|
1774 | { |
---|
1775 | Int ctr; |
---|
1776 | // For the second decoding unit onwards we know how many NALUs are present |
---|
1777 | for (ctr = 0, it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
1778 | { |
---|
1779 | if(ctr == accumNalsDU[ i - 1 ]) |
---|
1780 | { |
---|
1781 | // Insert before the first slice. |
---|
1782 | m_seiWriter.writeSEImessage(nalu.m_Bitstream, tempSEI, pcSlice->getSPS()); |
---|
1783 | writeRBSPTrailingBits(nalu.m_Bitstream); |
---|
1784 | |
---|
1785 | accessUnit.insert(it, new NALUnitEBSP(nalu)); |
---|
1786 | break; |
---|
1787 | } |
---|
1788 | if ((*it)->m_nalUnitType != NAL_UNIT_SEI && (*it)->m_nalUnitType != NAL_UNIT_SEI_SUFFIX) |
---|
1789 | { |
---|
1790 | ctr++; |
---|
1791 | } |
---|
1792 | } |
---|
1793 | } |
---|
1794 | } |
---|
1795 | } |
---|
1796 | } |
---|
1797 | #if L0045_NON_NESTED_SEI_RESTRICTIONS |
---|
1798 | xResetNonNestedSEIPresentFlags(); |
---|
1799 | #endif |
---|
1800 | pcPic->getPicYuvRec()->copyToPic(pcPicYuvRecOut); |
---|
1801 | |
---|
1802 | pcPic->setReconMark ( true ); |
---|
1803 | #if H_MV |
---|
1804 | TComSlice::markIvRefPicsAsShortTerm( m_refPicSetInterLayer ); |
---|
1805 | std::vector<Int> temp; |
---|
1806 | TComSlice::markIvRefPicsAsUnused ( m_ivPicLists, temp, pcPic->getSlice(0)->getVPS(), m_layerId, pcPic->getPOC() ); |
---|
1807 | #endif |
---|
1808 | m_bFirst = false; |
---|
1809 | m_iNumPicCoded++; |
---|
1810 | m_totalCoded ++; |
---|
1811 | /* logging: insert a newline at end of picture period */ |
---|
1812 | printf("\n"); |
---|
1813 | fflush(stdout); |
---|
1814 | |
---|
1815 | delete[] pcSubstreamsOut; |
---|
1816 | } |
---|
1817 | #if !RATE_CONTROL_LAMBDA_DOMAIN |
---|
1818 | if(m_pcCfg->getUseRateCtrl()) |
---|
1819 | { |
---|
1820 | m_pcRateCtrl->updateRCGOPStatus(); |
---|
1821 | } |
---|
1822 | #endif |
---|
1823 | delete pcBitstreamRedirect; |
---|
1824 | |
---|
1825 | if( accumBitsDU != NULL) delete accumBitsDU; |
---|
1826 | if( accumNalsDU != NULL) delete accumNalsDU; |
---|
1827 | |
---|
1828 | #if !H_MV |
---|
1829 | assert ( m_iNumPicCoded == iNumPicRcvd ); |
---|
1830 | #endif |
---|
1831 | |
---|
1832 | } |
---|
1833 | |
---|
1834 | #if !H_MV |
---|
1835 | Void TEncGOP::printOutSummary(UInt uiNumAllPicCoded) |
---|
1836 | { |
---|
1837 | assert (uiNumAllPicCoded == m_gcAnalyzeAll.getNumPic()); |
---|
1838 | |
---|
1839 | |
---|
1840 | //--CFG_KDY |
---|
1841 | m_gcAnalyzeAll.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
1842 | m_gcAnalyzeI.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
1843 | m_gcAnalyzeP.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
1844 | m_gcAnalyzeB.setFrmRate( m_pcCfg->getFrameRate() ); |
---|
1845 | |
---|
1846 | //-- all |
---|
1847 | printf( "\n\nSUMMARY --------------------------------------------------------\n" ); |
---|
1848 | m_gcAnalyzeAll.printOut('a'); |
---|
1849 | |
---|
1850 | printf( "\n\nI Slices--------------------------------------------------------\n" ); |
---|
1851 | m_gcAnalyzeI.printOut('i'); |
---|
1852 | |
---|
1853 | printf( "\n\nP Slices--------------------------------------------------------\n" ); |
---|
1854 | m_gcAnalyzeP.printOut('p'); |
---|
1855 | |
---|
1856 | printf( "\n\nB Slices--------------------------------------------------------\n" ); |
---|
1857 | m_gcAnalyzeB.printOut('b'); |
---|
1858 | |
---|
1859 | #if _SUMMARY_OUT_ |
---|
1860 | m_gcAnalyzeAll.printSummaryOut(); |
---|
1861 | #endif |
---|
1862 | #if _SUMMARY_PIC_ |
---|
1863 | m_gcAnalyzeI.printSummary('I'); |
---|
1864 | m_gcAnalyzeP.printSummary('P'); |
---|
1865 | m_gcAnalyzeB.printSummary('B'); |
---|
1866 | #endif |
---|
1867 | |
---|
1868 | printf("\nRVM: %.3lf\n" , xCalculateRVM()); |
---|
1869 | } |
---|
1870 | #endif |
---|
1871 | |
---|
1872 | Void TEncGOP::preLoopFilterPicAll( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits ) |
---|
1873 | { |
---|
1874 | TComSlice* pcSlice = pcPic->getSlice(pcPic->getCurrSliceIdx()); |
---|
1875 | Bool bCalcDist = false; |
---|
1876 | m_pcLoopFilter->setCfg(m_pcCfg->getLFCrossTileBoundaryFlag()); |
---|
1877 | m_pcLoopFilter->loopFilterPic( pcPic ); |
---|
1878 | |
---|
1879 | m_pcEntropyCoder->setEntropyCoder ( m_pcEncTop->getRDGoOnSbacCoder(), pcSlice ); |
---|
1880 | m_pcEntropyCoder->resetEntropy (); |
---|
1881 | m_pcEntropyCoder->setBitstream ( m_pcBitCounter ); |
---|
1882 | pcSlice = pcPic->getSlice(0); |
---|
1883 | if(pcSlice->getSPS()->getUseSAO()) |
---|
1884 | { |
---|
1885 | std::vector<Bool> LFCrossSliceBoundaryFlag(1, true); |
---|
1886 | std::vector<Int> sliceStartAddress; |
---|
1887 | sliceStartAddress.push_back(0); |
---|
1888 | sliceStartAddress.push_back(pcPic->getNumCUsInFrame()* pcPic->getNumPartInCU()); |
---|
1889 | pcPic->createNonDBFilterInfo(sliceStartAddress, 0, &LFCrossSliceBoundaryFlag); |
---|
1890 | } |
---|
1891 | |
---|
1892 | if( pcSlice->getSPS()->getUseSAO()) |
---|
1893 | { |
---|
1894 | pcPic->destroyNonDBFilterInfo(); |
---|
1895 | } |
---|
1896 | |
---|
1897 | m_pcEntropyCoder->resetEntropy (); |
---|
1898 | ruiBits += m_pcEntropyCoder->getNumberOfWrittenBits(); |
---|
1899 | |
---|
1900 | if (!bCalcDist) |
---|
1901 | ruiDist = xFindDistortionFrame(pcPic->getPicYuvOrg(), pcPic->getPicYuvRec()); |
---|
1902 | } |
---|
1903 | |
---|
1904 | // ==================================================================================================================== |
---|
1905 | // Protected member functions |
---|
1906 | // ==================================================================================================================== |
---|
1907 | |
---|
1908 | Void TEncGOP::xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut ) |
---|
1909 | { |
---|
1910 | assert( iNumPicRcvd > 0 ); |
---|
1911 | // Exception for the first frame |
---|
1912 | if ( iPOCLast == 0 ) |
---|
1913 | { |
---|
1914 | m_iGopSize = 1; |
---|
1915 | } |
---|
1916 | else |
---|
1917 | m_iGopSize = m_pcCfg->getGOPSize(); |
---|
1918 | |
---|
1919 | assert (m_iGopSize > 0); |
---|
1920 | |
---|
1921 | return; |
---|
1922 | } |
---|
1923 | |
---|
1924 | Void TEncGOP::xGetBuffer( TComList<TComPic*>& rcListPic, |
---|
1925 | TComList<TComPicYuv*>& rcListPicYuvRecOut, |
---|
1926 | Int iNumPicRcvd, |
---|
1927 | Int iTimeOffset, |
---|
1928 | TComPic*& rpcPic, |
---|
1929 | TComPicYuv*& rpcPicYuvRecOut, |
---|
1930 | Int pocCurr ) |
---|
1931 | { |
---|
1932 | Int i; |
---|
1933 | // Rec. output |
---|
1934 | TComList<TComPicYuv*>::iterator iterPicYuvRec = rcListPicYuvRecOut.end(); |
---|
1935 | for ( i = 0; i < iNumPicRcvd - iTimeOffset + 1; i++ ) |
---|
1936 | { |
---|
1937 | iterPicYuvRec--; |
---|
1938 | } |
---|
1939 | |
---|
1940 | rpcPicYuvRecOut = *(iterPicYuvRec); |
---|
1941 | |
---|
1942 | // Current pic. |
---|
1943 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
1944 | while (iterPic != rcListPic.end()) |
---|
1945 | { |
---|
1946 | rpcPic = *(iterPic); |
---|
1947 | rpcPic->setCurrSliceIdx(0); |
---|
1948 | if (rpcPic->getPOC() == pocCurr) |
---|
1949 | { |
---|
1950 | break; |
---|
1951 | } |
---|
1952 | iterPic++; |
---|
1953 | } |
---|
1954 | |
---|
1955 | assert (rpcPic->getPOC() == pocCurr); |
---|
1956 | |
---|
1957 | return; |
---|
1958 | } |
---|
1959 | |
---|
1960 | UInt64 TEncGOP::xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1) |
---|
1961 | { |
---|
1962 | Int x, y; |
---|
1963 | Pel* pSrc0 = pcPic0 ->getLumaAddr(); |
---|
1964 | Pel* pSrc1 = pcPic1 ->getLumaAddr(); |
---|
1965 | UInt uiShift = 2 * DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthY-8); |
---|
1966 | Int iTemp; |
---|
1967 | |
---|
1968 | Int iStride = pcPic0->getStride(); |
---|
1969 | Int iWidth = pcPic0->getWidth(); |
---|
1970 | Int iHeight = pcPic0->getHeight(); |
---|
1971 | |
---|
1972 | UInt64 uiTotalDiff = 0; |
---|
1973 | |
---|
1974 | for( y = 0; y < iHeight; y++ ) |
---|
1975 | { |
---|
1976 | for( x = 0; x < iWidth; x++ ) |
---|
1977 | { |
---|
1978 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
1979 | } |
---|
1980 | pSrc0 += iStride; |
---|
1981 | pSrc1 += iStride; |
---|
1982 | } |
---|
1983 | |
---|
1984 | uiShift = 2 * DISTORTION_PRECISION_ADJUSTMENT(g_bitDepthC-8); |
---|
1985 | iHeight >>= 1; |
---|
1986 | iWidth >>= 1; |
---|
1987 | iStride >>= 1; |
---|
1988 | |
---|
1989 | pSrc0 = pcPic0->getCbAddr(); |
---|
1990 | pSrc1 = pcPic1->getCbAddr(); |
---|
1991 | |
---|
1992 | for( y = 0; y < iHeight; y++ ) |
---|
1993 | { |
---|
1994 | for( x = 0; x < iWidth; x++ ) |
---|
1995 | { |
---|
1996 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
1997 | } |
---|
1998 | pSrc0 += iStride; |
---|
1999 | pSrc1 += iStride; |
---|
2000 | } |
---|
2001 | |
---|
2002 | pSrc0 = pcPic0->getCrAddr(); |
---|
2003 | pSrc1 = pcPic1->getCrAddr(); |
---|
2004 | |
---|
2005 | for( y = 0; y < iHeight; y++ ) |
---|
2006 | { |
---|
2007 | for( x = 0; x < iWidth; x++ ) |
---|
2008 | { |
---|
2009 | iTemp = pSrc0[x] - pSrc1[x]; uiTotalDiff += (iTemp*iTemp) >> uiShift; |
---|
2010 | } |
---|
2011 | pSrc0 += iStride; |
---|
2012 | pSrc1 += iStride; |
---|
2013 | } |
---|
2014 | |
---|
2015 | return uiTotalDiff; |
---|
2016 | } |
---|
2017 | |
---|
2018 | #if VERBOSE_RATE |
---|
2019 | static const Char* nalUnitTypeToString(NalUnitType type) |
---|
2020 | { |
---|
2021 | switch (type) |
---|
2022 | { |
---|
2023 | case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R"; |
---|
2024 | case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N"; |
---|
2025 | case NAL_UNIT_CODED_SLICE_TLA: return "TLA"; |
---|
2026 | case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N"; |
---|
2027 | case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R"; |
---|
2028 | case NAL_UNIT_CODED_SLICE_STSA_N: return "STSA_N"; |
---|
2029 | case NAL_UNIT_CODED_SLICE_BLA: return "BLA"; |
---|
2030 | case NAL_UNIT_CODED_SLICE_BLANT: return "BLANT"; |
---|
2031 | case NAL_UNIT_CODED_SLICE_BLA_N_LP: return "BLA_N_LP"; |
---|
2032 | case NAL_UNIT_CODED_SLICE_IDR: return "IDR"; |
---|
2033 | case NAL_UNIT_CODED_SLICE_IDR_N_LP: return "IDR_N_LP"; |
---|
2034 | case NAL_UNIT_CODED_SLICE_CRA: return "CRA"; |
---|
2035 | case NAL_UNIT_CODED_SLICE_DLP: return "DLP"; |
---|
2036 | case NAL_UNIT_CODED_SLICE_TFD: return "TFD"; |
---|
2037 | case NAL_UNIT_VPS: return "VPS"; |
---|
2038 | case NAL_UNIT_SPS: return "SPS"; |
---|
2039 | case NAL_UNIT_PPS: return "PPS"; |
---|
2040 | case NAL_UNIT_ACCESS_UNIT_DELIMITER: return "AUD"; |
---|
2041 | case NAL_UNIT_EOS: return "EOS"; |
---|
2042 | case NAL_UNIT_EOB: return "EOB"; |
---|
2043 | case NAL_UNIT_FILLER_DATA: return "FILLER"; |
---|
2044 | case NAL_UNIT_SEI: return "SEI"; |
---|
2045 | default: return "UNK"; |
---|
2046 | } |
---|
2047 | } |
---|
2048 | #endif |
---|
2049 | |
---|
2050 | Void TEncGOP::xCalculateAddPSNR( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit& accessUnit, Double dEncTime ) |
---|
2051 | { |
---|
2052 | Int x, y; |
---|
2053 | UInt64 uiSSDY = 0; |
---|
2054 | UInt64 uiSSDU = 0; |
---|
2055 | UInt64 uiSSDV = 0; |
---|
2056 | |
---|
2057 | Double dYPSNR = 0.0; |
---|
2058 | Double dUPSNR = 0.0; |
---|
2059 | Double dVPSNR = 0.0; |
---|
2060 | |
---|
2061 | //===== calculate PSNR ===== |
---|
2062 | Pel* pOrg = pcPic ->getPicYuvOrg()->getLumaAddr(); |
---|
2063 | Pel* pRec = pcPicD->getLumaAddr(); |
---|
2064 | Int iStride = pcPicD->getStride(); |
---|
2065 | |
---|
2066 | Int iWidth; |
---|
2067 | Int iHeight; |
---|
2068 | |
---|
2069 | iWidth = pcPicD->getWidth () - m_pcEncTop->getPad(0); |
---|
2070 | iHeight = pcPicD->getHeight() - m_pcEncTop->getPad(1); |
---|
2071 | |
---|
2072 | Int iSize = iWidth*iHeight; |
---|
2073 | |
---|
2074 | for( y = 0; y < iHeight; y++ ) |
---|
2075 | { |
---|
2076 | for( x = 0; x < iWidth; x++ ) |
---|
2077 | { |
---|
2078 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
2079 | uiSSDY += iDiff * iDiff; |
---|
2080 | } |
---|
2081 | pOrg += iStride; |
---|
2082 | pRec += iStride; |
---|
2083 | } |
---|
2084 | |
---|
2085 | iHeight >>= 1; |
---|
2086 | iWidth >>= 1; |
---|
2087 | iStride >>= 1; |
---|
2088 | pOrg = pcPic ->getPicYuvOrg()->getCbAddr(); |
---|
2089 | pRec = pcPicD->getCbAddr(); |
---|
2090 | |
---|
2091 | for( y = 0; y < iHeight; y++ ) |
---|
2092 | { |
---|
2093 | for( x = 0; x < iWidth; x++ ) |
---|
2094 | { |
---|
2095 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
2096 | uiSSDU += iDiff * iDiff; |
---|
2097 | } |
---|
2098 | pOrg += iStride; |
---|
2099 | pRec += iStride; |
---|
2100 | } |
---|
2101 | |
---|
2102 | pOrg = pcPic ->getPicYuvOrg()->getCrAddr(); |
---|
2103 | pRec = pcPicD->getCrAddr(); |
---|
2104 | |
---|
2105 | for( y = 0; y < iHeight; y++ ) |
---|
2106 | { |
---|
2107 | for( x = 0; x < iWidth; x++ ) |
---|
2108 | { |
---|
2109 | Int iDiff = (Int)( pOrg[x] - pRec[x] ); |
---|
2110 | uiSSDV += iDiff * iDiff; |
---|
2111 | } |
---|
2112 | pOrg += iStride; |
---|
2113 | pRec += iStride; |
---|
2114 | } |
---|
2115 | |
---|
2116 | Int maxvalY = 255 << (g_bitDepthY-8); |
---|
2117 | Int maxvalC = 255 << (g_bitDepthC-8); |
---|
2118 | Double fRefValueY = (Double) maxvalY * maxvalY * iSize; |
---|
2119 | Double fRefValueC = (Double) maxvalC * maxvalC * iSize / 4.0; |
---|
2120 | dYPSNR = ( uiSSDY ? 10.0 * log10( fRefValueY / (Double)uiSSDY ) : 99.99 ); |
---|
2121 | dUPSNR = ( uiSSDU ? 10.0 * log10( fRefValueC / (Double)uiSSDU ) : 99.99 ); |
---|
2122 | dVPSNR = ( uiSSDV ? 10.0 * log10( fRefValueC / (Double)uiSSDV ) : 99.99 ); |
---|
2123 | |
---|
2124 | /* calculate the size of the access unit, excluding: |
---|
2125 | * - any AnnexB contributions (start_code_prefix, zero_byte, etc.,) |
---|
2126 | * - SEI NAL units |
---|
2127 | */ |
---|
2128 | UInt numRBSPBytes = 0; |
---|
2129 | for (AccessUnit::const_iterator it = accessUnit.begin(); it != accessUnit.end(); it++) |
---|
2130 | { |
---|
2131 | UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size()); |
---|
2132 | #if VERBOSE_RATE |
---|
2133 | printf("*** %6s numBytesInNALunit: %u\n", nalUnitTypeToString((*it)->m_nalUnitType), numRBSPBytes_nal); |
---|
2134 | #endif |
---|
2135 | if ((*it)->m_nalUnitType != NAL_UNIT_SEI && (*it)->m_nalUnitType != NAL_UNIT_SEI_SUFFIX) |
---|
2136 | { |
---|
2137 | numRBSPBytes += numRBSPBytes_nal; |
---|
2138 | } |
---|
2139 | } |
---|
2140 | |
---|
2141 | UInt uibits = numRBSPBytes * 8; |
---|
2142 | m_vRVM_RP.push_back( uibits ); |
---|
2143 | |
---|
2144 | //===== add PSNR ===== |
---|
2145 | |
---|
2146 | #if H_MV |
---|
2147 | m_pcEncTop->getAnalyzeAll()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2148 | #else |
---|
2149 | m_gcAnalyzeAll.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2150 | #endif |
---|
2151 | |
---|
2152 | TComSlice* pcSlice = pcPic->getSlice(0); |
---|
2153 | if (pcSlice->isIntra()) |
---|
2154 | { |
---|
2155 | |
---|
2156 | #if H_MV |
---|
2157 | m_pcEncTop->getAnalyzeI()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2158 | #else |
---|
2159 | m_gcAnalyzeI.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2160 | #endif |
---|
2161 | |
---|
2162 | } |
---|
2163 | if (pcSlice->isInterP()) |
---|
2164 | { |
---|
2165 | |
---|
2166 | #if H_MV |
---|
2167 | m_pcEncTop->getAnalyzeP()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2168 | #else |
---|
2169 | m_gcAnalyzeP.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2170 | #endif |
---|
2171 | |
---|
2172 | } |
---|
2173 | if (pcSlice->isInterB()) |
---|
2174 | { |
---|
2175 | |
---|
2176 | #if H_MV |
---|
2177 | m_pcEncTop->getAnalyzeB()->addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2178 | #else |
---|
2179 | m_gcAnalyzeB.addResult (dYPSNR, dUPSNR, dVPSNR, (Double)uibits); |
---|
2180 | #endif |
---|
2181 | |
---|
2182 | } |
---|
2183 | |
---|
2184 | Char c = (pcSlice->isIntra() ? 'I' : pcSlice->isInterP() ? 'P' : 'B'); |
---|
2185 | if (!pcSlice->isReferenced()) c += 32; |
---|
2186 | |
---|
2187 | #if ADAPTIVE_QP_SELECTION |
---|
2188 | |
---|
2189 | #if H_MV |
---|
2190 | printf("Layer %3d POC %4d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits", |
---|
2191 | pcSlice->getLayerId(), |
---|
2192 | pcSlice->getPOC(), |
---|
2193 | pcSlice->getTLayer(), |
---|
2194 | c, |
---|
2195 | pcSlice->getSliceQpBase(), |
---|
2196 | pcSlice->getSliceQp(), |
---|
2197 | uibits ); |
---|
2198 | #else |
---|
2199 | printf("POC %4d TId: %1d ( %c-SLICE, nQP %d QP %d ) %10d bits", |
---|
2200 | pcSlice->getPOC(), |
---|
2201 | pcSlice->getTLayer(), |
---|
2202 | c, |
---|
2203 | pcSlice->getSliceQpBase(), |
---|
2204 | pcSlice->getSliceQp(), |
---|
2205 | uibits ); |
---|
2206 | #endif |
---|
2207 | |
---|
2208 | #else |
---|
2209 | |
---|
2210 | #if H_MV |
---|
2211 | printf("Layer %3d POC %4d TId: %1d ( %c-SLICE, QP %d ) %10d bits", |
---|
2212 | pcSlice->getLayerId(), |
---|
2213 | pcSlice->getPOC()-pcSlice->getLastIDR(), |
---|
2214 | pcSlice->getTLayer(), |
---|
2215 | c, |
---|
2216 | pcSlice->getSliceQp(), |
---|
2217 | uibits ); |
---|
2218 | #else |
---|
2219 | printf("POC %4d TId: %1d ( %c-SLICE, QP %d ) %10d bits", |
---|
2220 | pcSlice->getPOC()-pcSlice->getLastIDR(), |
---|
2221 | pcSlice->getTLayer(), |
---|
2222 | c, |
---|
2223 | pcSlice->getSliceQp(), |
---|
2224 | uibits ); |
---|
2225 | #endif |
---|
2226 | |
---|
2227 | #endif |
---|
2228 | |
---|
2229 | printf(" [Y %6.4lf dB U %6.4lf dB V %6.4lf dB]", dYPSNR, dUPSNR, dVPSNR ); |
---|
2230 | printf(" [ET %5.0f ]", dEncTime ); |
---|
2231 | |
---|
2232 | for (Int iRefList = 0; iRefList < 2; iRefList++) |
---|
2233 | { |
---|
2234 | printf(" [L%d ", iRefList); |
---|
2235 | for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++) |
---|
2236 | { |
---|
2237 | #if H_MV |
---|
2238 | if( pcSlice->getLayerId() != pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) ) |
---|
2239 | { |
---|
2240 | printf( "V%d ", pcSlice->getRefLayerId( RefPicList(iRefList), iRefIndex ) ); |
---|
2241 | } |
---|
2242 | else |
---|
2243 | { |
---|
2244 | #endif |
---|
2245 | printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR()); |
---|
2246 | #if H_MV |
---|
2247 | } |
---|
2248 | #endif |
---|
2249 | } |
---|
2250 | printf("]"); |
---|
2251 | } |
---|
2252 | } |
---|
2253 | |
---|
2254 | /** Function for deciding the nal_unit_type. |
---|
2255 | * \param pocCurr POC of the current picture |
---|
2256 | * \returns the nal unit type of the picture |
---|
2257 | * This function checks the configuration and returns the appropriate nal_unit_type for the picture. |
---|
2258 | */ |
---|
2259 | NalUnitType TEncGOP::getNalUnitType(Int pocCurr) |
---|
2260 | { |
---|
2261 | if (pocCurr == 0) |
---|
2262 | { |
---|
2263 | return NAL_UNIT_CODED_SLICE_IDR; |
---|
2264 | } |
---|
2265 | if (pocCurr % m_pcCfg->getIntraPeriod() == 0) |
---|
2266 | { |
---|
2267 | if (m_pcCfg->getDecodingRefreshType() == 1) |
---|
2268 | { |
---|
2269 | return NAL_UNIT_CODED_SLICE_CRA; |
---|
2270 | } |
---|
2271 | else if (m_pcCfg->getDecodingRefreshType() == 2) |
---|
2272 | { |
---|
2273 | return NAL_UNIT_CODED_SLICE_IDR; |
---|
2274 | } |
---|
2275 | } |
---|
2276 | if(m_pocCRA>0) |
---|
2277 | { |
---|
2278 | if(pocCurr<m_pocCRA) |
---|
2279 | { |
---|
2280 | // All leading pictures are being marked as TFD pictures here since current encoder uses all |
---|
2281 | // reference pictures while encoding leading pictures. An encoder can ensure that a leading |
---|
2282 | // picture can be still decodable when random accessing to a CRA/CRANT/BLA/BLANT picture by |
---|
2283 | // controlling the reference pictures used for encoding that leading picture. Such a leading |
---|
2284 | // picture need not be marked as a TFD picture. |
---|
2285 | return NAL_UNIT_CODED_SLICE_TFD; |
---|
2286 | } |
---|
2287 | } |
---|
2288 | return NAL_UNIT_CODED_SLICE_TRAIL_R; |
---|
2289 | } |
---|
2290 | |
---|
2291 | Double TEncGOP::xCalculateRVM() |
---|
2292 | { |
---|
2293 | Double dRVM = 0; |
---|
2294 | |
---|
2295 | if( m_pcCfg->getGOPSize() == 1 && m_pcCfg->getIntraPeriod() != 1 && m_pcCfg->getFramesToBeEncoded() > RVM_VCEGAM10_M * 2 ) |
---|
2296 | { |
---|
2297 | // calculate RVM only for lowdelay configurations |
---|
2298 | std::vector<Double> vRL , vB; |
---|
2299 | size_t N = m_vRVM_RP.size(); |
---|
2300 | vRL.resize( N ); |
---|
2301 | vB.resize( N ); |
---|
2302 | |
---|
2303 | Int i; |
---|
2304 | Double dRavg = 0 , dBavg = 0; |
---|
2305 | vB[RVM_VCEGAM10_M] = 0; |
---|
2306 | for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ ) |
---|
2307 | { |
---|
2308 | vRL[i] = 0; |
---|
2309 | for( Int j = i - RVM_VCEGAM10_M ; j <= i + RVM_VCEGAM10_M - 1 ; j++ ) |
---|
2310 | vRL[i] += m_vRVM_RP[j]; |
---|
2311 | vRL[i] /= ( 2 * RVM_VCEGAM10_M ); |
---|
2312 | vB[i] = vB[i-1] + m_vRVM_RP[i] - vRL[i]; |
---|
2313 | dRavg += m_vRVM_RP[i]; |
---|
2314 | dBavg += vB[i]; |
---|
2315 | } |
---|
2316 | |
---|
2317 | dRavg /= ( N - 2 * RVM_VCEGAM10_M ); |
---|
2318 | dBavg /= ( N - 2 * RVM_VCEGAM10_M ); |
---|
2319 | |
---|
2320 | Double dSigamB = 0; |
---|
2321 | for( i = RVM_VCEGAM10_M + 1 ; i < N - RVM_VCEGAM10_M + 1 ; i++ ) |
---|
2322 | { |
---|
2323 | Double tmp = vB[i] - dBavg; |
---|
2324 | dSigamB += tmp * tmp; |
---|
2325 | } |
---|
2326 | dSigamB = sqrt( dSigamB / ( N - 2 * RVM_VCEGAM10_M ) ); |
---|
2327 | |
---|
2328 | Double f = sqrt( 12.0 * ( RVM_VCEGAM10_M - 1 ) / ( RVM_VCEGAM10_M + 1 ) ); |
---|
2329 | |
---|
2330 | dRVM = dSigamB / dRavg * f; |
---|
2331 | } |
---|
2332 | |
---|
2333 | return( dRVM ); |
---|
2334 | } |
---|
2335 | |
---|
2336 | /** Determine the difference between consecutive tile sizes (in bytes) and writes it to bistream rNalu [slice header] |
---|
2337 | * \param rpcBitstreamRedirect contains the bitstream to be concatenated to rNalu. rpcBitstreamRedirect contains slice payload. rpcSlice contains tile location information. |
---|
2338 | * \returns Updates rNalu to contain concatenated bitstream. rpcBitstreamRedirect is cleared at the end of this function call. |
---|
2339 | */ |
---|
2340 | Void TEncGOP::xWriteTileLocationToSliceHeader (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect, TComSlice*& rpcSlice) |
---|
2341 | { |
---|
2342 | // Byte-align |
---|
2343 | rNalu.m_Bitstream.writeByteAlignment(); // Slice header byte-alignment |
---|
2344 | |
---|
2345 | // Perform bitstream concatenation |
---|
2346 | if (rpcBitstreamRedirect->getNumberOfWrittenBits() > 0) |
---|
2347 | { |
---|
2348 | UInt uiBitCount = rpcBitstreamRedirect->getNumberOfWrittenBits(); |
---|
2349 | if (rpcBitstreamRedirect->getByteStreamLength()>0) |
---|
2350 | { |
---|
2351 | UChar *pucStart = reinterpret_cast<UChar*>(rpcBitstreamRedirect->getByteStream()); |
---|
2352 | UInt uiWriteByteCount = 0; |
---|
2353 | while (uiWriteByteCount < (uiBitCount >> 3) ) |
---|
2354 | { |
---|
2355 | UInt uiBits = (*pucStart); |
---|
2356 | rNalu.m_Bitstream.write(uiBits, 8); |
---|
2357 | pucStart++; |
---|
2358 | uiWriteByteCount++; |
---|
2359 | } |
---|
2360 | } |
---|
2361 | UInt uiBitsHeld = (uiBitCount & 0x07); |
---|
2362 | for (UInt uiIdx=0; uiIdx < uiBitsHeld; uiIdx++) |
---|
2363 | { |
---|
2364 | rNalu.m_Bitstream.write((rpcBitstreamRedirect->getHeldBits() & (1 << (7-uiIdx))) >> (7-uiIdx), 1); |
---|
2365 | } |
---|
2366 | } |
---|
2367 | |
---|
2368 | m_pcEntropyCoder->setBitstream(&rNalu.m_Bitstream); |
---|
2369 | |
---|
2370 | delete rpcBitstreamRedirect; |
---|
2371 | rpcBitstreamRedirect = new TComOutputBitstream; |
---|
2372 | } |
---|
2373 | |
---|
2374 | // Function will arrange the long-term pictures in the decreasing order of poc_lsb_lt, |
---|
2375 | // and among the pictures with the same lsb, it arranges them in increasing delta_poc_msb_cycle_lt value |
---|
2376 | Void TEncGOP::arrangeLongtermPicturesInRPS(TComSlice *pcSlice, TComList<TComPic*>& rcListPic) |
---|
2377 | { |
---|
2378 | TComReferencePictureSet *rps = pcSlice->getRPS(); |
---|
2379 | if(!rps->getNumberOfLongtermPictures()) |
---|
2380 | { |
---|
2381 | return; |
---|
2382 | } |
---|
2383 | |
---|
2384 | // Arrange long-term reference pictures in the correct order of LSB and MSB, |
---|
2385 | // and assign values for pocLSBLT and MSB present flag |
---|
2386 | Int longtermPicsPoc[MAX_NUM_REF_PICS], longtermPicsLSB[MAX_NUM_REF_PICS], indices[MAX_NUM_REF_PICS]; |
---|
2387 | Int longtermPicsMSB[MAX_NUM_REF_PICS]; |
---|
2388 | Bool mSBPresentFlag[MAX_NUM_REF_PICS]; |
---|
2389 | ::memset(longtermPicsPoc, 0, sizeof(longtermPicsPoc)); // Store POC values of LTRP |
---|
2390 | ::memset(longtermPicsLSB, 0, sizeof(longtermPicsLSB)); // Store POC LSB values of LTRP |
---|
2391 | ::memset(longtermPicsMSB, 0, sizeof(longtermPicsMSB)); // Store POC LSB values of LTRP |
---|
2392 | ::memset(indices , 0, sizeof(indices)); // Indices to aid in tracking sorted LTRPs |
---|
2393 | ::memset(mSBPresentFlag , 0, sizeof(mSBPresentFlag)); // Indicate if MSB needs to be present |
---|
2394 | |
---|
2395 | // Get the long-term reference pictures |
---|
2396 | Int offset = rps->getNumberOfNegativePictures() + rps->getNumberOfPositivePictures(); |
---|
2397 | Int i, ctr = 0; |
---|
2398 | Int maxPicOrderCntLSB = 1 << pcSlice->getSPS()->getBitsForPOC(); |
---|
2399 | for(i = rps->getNumberOfPictures() - 1; i >= offset; i--, ctr++) |
---|
2400 | { |
---|
2401 | longtermPicsPoc[ctr] = rps->getPOC(i); // LTRP POC |
---|
2402 | longtermPicsLSB[ctr] = getLSB(longtermPicsPoc[ctr], maxPicOrderCntLSB); // LTRP POC LSB |
---|
2403 | indices[ctr] = i; |
---|
2404 | longtermPicsMSB[ctr] = longtermPicsPoc[ctr] - longtermPicsLSB[ctr]; |
---|
2405 | } |
---|
2406 | Int numLongPics = rps->getNumberOfLongtermPictures(); |
---|
2407 | assert(ctr == numLongPics); |
---|
2408 | |
---|
2409 | // Arrange pictures in decreasing order of MSB; |
---|
2410 | for(i = 0; i < numLongPics; i++) |
---|
2411 | { |
---|
2412 | for(Int j = 0; j < numLongPics - 1; j++) |
---|
2413 | { |
---|
2414 | if(longtermPicsMSB[j] < longtermPicsMSB[j+1]) |
---|
2415 | { |
---|
2416 | std::swap(longtermPicsPoc[j], longtermPicsPoc[j+1]); |
---|
2417 | std::swap(longtermPicsLSB[j], longtermPicsLSB[j+1]); |
---|
2418 | std::swap(longtermPicsMSB[j], longtermPicsMSB[j+1]); |
---|
2419 | std::swap(indices[j] , indices[j+1] ); |
---|
2420 | } |
---|
2421 | } |
---|
2422 | } |
---|
2423 | |
---|
2424 | for(i = 0; i < numLongPics; i++) |
---|
2425 | { |
---|
2426 | // Check if MSB present flag should be enabled. |
---|
2427 | // Check if the buffer contains any pictures that have the same LSB. |
---|
2428 | TComList<TComPic*>::iterator iterPic = rcListPic.begin(); |
---|
2429 | TComPic* pcPic; |
---|
2430 | while ( iterPic != rcListPic.end() ) |
---|
2431 | { |
---|
2432 | pcPic = *iterPic; |
---|
2433 | if( (getLSB(pcPic->getPOC(), maxPicOrderCntLSB) == longtermPicsLSB[i]) && // Same LSB |
---|
2434 | (pcPic->getSlice(0)->isReferenced()) && // Reference picture |
---|
2435 | (pcPic->getPOC() != longtermPicsPoc[i]) ) // Not the LTRP itself |
---|
2436 | { |
---|
2437 | mSBPresentFlag[i] = true; |
---|
2438 | break; |
---|
2439 | } |
---|
2440 | iterPic++; |
---|
2441 | } |
---|
2442 | } |
---|
2443 | |
---|
2444 | // tempArray for usedByCurr flag |
---|
2445 | Bool tempArray[MAX_NUM_REF_PICS]; ::memset(tempArray, 0, sizeof(tempArray)); |
---|
2446 | for(i = 0; i < numLongPics; i++) |
---|
2447 | { |
---|
2448 | tempArray[i] = rps->getUsed(indices[i]); |
---|
2449 | } |
---|
2450 | // Now write the final values; |
---|
2451 | ctr = 0; |
---|
2452 | Int currMSB = 0, currLSB = 0; |
---|
2453 | // currPicPoc = currMSB + currLSB |
---|
2454 | currLSB = getLSB(pcSlice->getPOC(), maxPicOrderCntLSB); |
---|
2455 | currMSB = pcSlice->getPOC() - currLSB; |
---|
2456 | |
---|
2457 | for(i = rps->getNumberOfPictures() - 1; i >= offset; i--, ctr++) |
---|
2458 | { |
---|
2459 | rps->setPOC (i, longtermPicsPoc[ctr]); |
---|
2460 | rps->setDeltaPOC (i, - pcSlice->getPOC() + longtermPicsPoc[ctr]); |
---|
2461 | rps->setUsed (i, tempArray[ctr]); |
---|
2462 | rps->setPocLSBLT (i, longtermPicsLSB[ctr]); |
---|
2463 | rps->setDeltaPocMSBCycleLT (i, (currMSB - (longtermPicsPoc[ctr] - longtermPicsLSB[ctr])) / maxPicOrderCntLSB); |
---|
2464 | rps->setDeltaPocMSBPresentFlag(i, mSBPresentFlag[ctr]); |
---|
2465 | |
---|
2466 | assert(rps->getDeltaPocMSBCycleLT(i) >= 0); // Non-negative value |
---|
2467 | } |
---|
2468 | for(i = rps->getNumberOfPictures() - 1, ctr = 1; i >= offset; i--, ctr++) |
---|
2469 | { |
---|
2470 | for(Int j = rps->getNumberOfPictures() - 1 - ctr; j >= offset; j--) |
---|
2471 | { |
---|
2472 | // Here at the encoder we know that we have set the full POC value for the LTRPs, hence we |
---|
2473 | // don't have to check the MSB present flag values for this constraint. |
---|
2474 | assert( rps->getPOC(i) != rps->getPOC(j) ); // If assert fails, LTRP entry repeated in RPS!!! |
---|
2475 | } |
---|
2476 | } |
---|
2477 | } |
---|
2478 | |
---|
2479 | #if L0045_NON_NESTED_SEI_RESTRICTIONS |
---|
2480 | /** Function for finding the position to insert the first of APS and non-nested BP, PT, DU info SEI messages. |
---|
2481 | * \param accessUnit Access Unit of the current picture |
---|
2482 | * This function finds the position to insert the first of APS and non-nested BP, PT, DU info SEI messages. |
---|
2483 | */ |
---|
2484 | Int TEncGOP::xGetFirstSeiLocation(AccessUnit &accessUnit) |
---|
2485 | { |
---|
2486 | // Find the location of the first SEI message |
---|
2487 | AccessUnit::iterator it; |
---|
2488 | Int seiStartPos = 0; |
---|
2489 | for(it = accessUnit.begin(); it != accessUnit.end(); it++, seiStartPos++) |
---|
2490 | { |
---|
2491 | if ((*it)->isSei() || (*it)->isVcl()) |
---|
2492 | { |
---|
2493 | break; |
---|
2494 | } |
---|
2495 | } |
---|
2496 | assert(it != accessUnit.end()); |
---|
2497 | return seiStartPos; |
---|
2498 | } |
---|
2499 | #endif |
---|
2500 | |
---|
2501 | #if H_MV |
---|
2502 | Void TEncGOP::xSetRefPicListModificationsMvc( TComSlice* pcSlice, UInt uiPOCCurr, UInt iGOPid ) |
---|
2503 | { |
---|
2504 | TComVPS* vps = pcSlice->getVPS(); |
---|
2505 | Int layer = pcSlice->getLayerIdInVps( ); |
---|
2506 | |
---|
2507 | if( pcSlice->getSliceType() == I_SLICE || !(pcSlice->getPPS()->getListsModificationPresentFlag()) || vps->getNumDirectRefLayers( layer ) == 0 ) |
---|
2508 | { |
---|
2509 | return; |
---|
2510 | } |
---|
2511 | |
---|
2512 | // analyze inter-view modifications |
---|
2513 | GOPEntry ge = m_pcCfg->getGOPEntry( (pcSlice->getRapPicFlag() && ( layer > 0) ) ? MAX_GOP : iGOPid ); |
---|
2514 | |
---|
2515 | TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification(); |
---|
2516 | |
---|
2517 | Int maxRefListSize = pcSlice->getNumRpsCurrTempList(); |
---|
2518 | Int numTemporalRefs = maxRefListSize - vps->getNumDirectRefLayers( layer ); |
---|
2519 | |
---|
2520 | |
---|
2521 | for (Int li = 0; li < 2; li ++) // Loop over lists L0 and L1 |
---|
2522 | { |
---|
2523 | Int numModifications = 0; |
---|
2524 | |
---|
2525 | for( Int k = 0; k < ge.m_numInterViewRefPics; k++ ) |
---|
2526 | { |
---|
2527 | numModifications += ( ge.m_interViewRefPosL[li][k] >= 0 ) ? 1 : 0; |
---|
2528 | } |
---|
2529 | |
---|
2530 | // set inter-view modifications |
---|
2531 | if( (maxRefListSize > 1) && (numModifications > 0) ) |
---|
2532 | { |
---|
2533 | refPicListModification->setRefPicListModificationFlagL( li, true ); |
---|
2534 | Int tempList[16]; |
---|
2535 | for( Int k = 0; k < 16; k++ ) { tempList[k] = -1; } |
---|
2536 | |
---|
2537 | Bool isModified = false; |
---|
2538 | for( Int k = 0; k < ge.m_numInterViewRefPics; k++ ) |
---|
2539 | { |
---|
2540 | if( ge.m_interViewRefPosL[li][k] >= 0 ) |
---|
2541 | { |
---|
2542 | Int orgIdx = numTemporalRefs; |
---|
2543 | Int targetIdx = ge.m_interViewRefPosL[ li ][ k ]; |
---|
2544 | for( Int idx = 0; idx < vps->getNumDirectRefLayers( layer ); idx++ ) |
---|
2545 | { |
---|
2546 | Int refLayer = vps->getLayerIdInVps( vps->getRefLayerId( layer, idx ) ); |
---|
2547 | if( ( layer + ge.m_interViewRefs[ k ]) == refLayer ) |
---|
2548 | { |
---|
2549 | tempList[ targetIdx ] = orgIdx; |
---|
2550 | isModified = ( targetIdx != orgIdx ); |
---|
2551 | } |
---|
2552 | orgIdx++; |
---|
2553 | } |
---|
2554 | } |
---|
2555 | } |
---|
2556 | if( isModified ) |
---|
2557 | { |
---|
2558 | Int temporalRefIdx = 0; |
---|
2559 | for( Int i = 0; i < pcSlice->getNumRefIdx( ( li == 0 ) ? REF_PIC_LIST_0 : REF_PIC_LIST_1 ); i++ ) |
---|
2560 | { |
---|
2561 | if( tempList[i] >= 0 ) |
---|
2562 | { |
---|
2563 | refPicListModification->setRefPicSetIdxL( li, i, tempList[i] ); |
---|
2564 | } |
---|
2565 | else |
---|
2566 | { |
---|
2567 | refPicListModification->setRefPicSetIdxL( li, i, temporalRefIdx ); |
---|
2568 | temporalRefIdx++; |
---|
2569 | } |
---|
2570 | } |
---|
2571 | } |
---|
2572 | else |
---|
2573 | { |
---|
2574 | refPicListModification->setRefPicListModificationFlagL( li, false ); |
---|
2575 | } |
---|
2576 | } |
---|
2577 | } |
---|
2578 | } |
---|
2579 | #endif |
---|
2580 | |
---|
2581 | //! \} |
---|