1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TAppDecTop.cpp |
---|
35 | \brief Decoder application class |
---|
36 | */ |
---|
37 | |
---|
38 | #include <list> |
---|
39 | #include <vector> |
---|
40 | #include <stdio.h> |
---|
41 | #include <fcntl.h> |
---|
42 | #include <assert.h> |
---|
43 | |
---|
44 | #include "TAppDecTop.h" |
---|
45 | #include "TLibDecoder/AnnexBread.h" |
---|
46 | #include "TLibDecoder/NALread.h" |
---|
47 | |
---|
48 | //! \ingroup TAppDecoder |
---|
49 | //! \{ |
---|
50 | |
---|
51 | // ==================================================================================================================== |
---|
52 | // Constructor / destructor / initialization / destroy |
---|
53 | // ==================================================================================================================== |
---|
54 | |
---|
55 | TAppDecTop::TAppDecTop() |
---|
56 | #if !H_MV |
---|
57 | : m_iPOCLastDisplay(-MAX_INT) |
---|
58 | #else |
---|
59 | : m_numDecoders( 0 ) |
---|
60 | #endif |
---|
61 | { |
---|
62 | #if H_MV |
---|
63 | for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++) |
---|
64 | { |
---|
65 | m_layerIdToDecIdx[i] = -1; |
---|
66 | m_layerInitilizedFlags[i] = false; |
---|
67 | } |
---|
68 | #endif |
---|
69 | #if H_3D |
---|
70 | m_pScaleOffsetFile = 0; |
---|
71 | #endif |
---|
72 | |
---|
73 | #if H_MV |
---|
74 | m_markedForOutput = false; |
---|
75 | #endif |
---|
76 | |
---|
77 | } |
---|
78 | |
---|
79 | Void TAppDecTop::create() |
---|
80 | { |
---|
81 | } |
---|
82 | |
---|
83 | Void TAppDecTop::destroy() |
---|
84 | { |
---|
85 | if (m_pchBitstreamFile) |
---|
86 | { |
---|
87 | free (m_pchBitstreamFile); |
---|
88 | m_pchBitstreamFile = NULL; |
---|
89 | } |
---|
90 | #if H_MV |
---|
91 | for (Int decIdx = 0; decIdx < m_numDecoders; decIdx++) |
---|
92 | { |
---|
93 | if (m_pchReconFiles[decIdx]) |
---|
94 | { |
---|
95 | free (m_pchReconFiles[decIdx]); |
---|
96 | m_pchReconFiles[decIdx] = NULL; |
---|
97 | } |
---|
98 | } |
---|
99 | #endif |
---|
100 | if (m_pchReconFile) |
---|
101 | { |
---|
102 | free (m_pchReconFile); |
---|
103 | m_pchReconFile = NULL; |
---|
104 | } |
---|
105 | #if H_3D |
---|
106 | if (m_pchScaleOffsetFile) |
---|
107 | { |
---|
108 | free (m_pchScaleOffsetFile); |
---|
109 | m_pchScaleOffsetFile = NULL; |
---|
110 | } |
---|
111 | #endif |
---|
112 | } |
---|
113 | |
---|
114 | // ==================================================================================================================== |
---|
115 | // Public member functions |
---|
116 | // ==================================================================================================================== |
---|
117 | |
---|
118 | /** |
---|
119 | - create internal class |
---|
120 | - initialize internal class |
---|
121 | - until the end of the bitstream, call decoding function in TDecTop class |
---|
122 | - delete allocated buffers |
---|
123 | - destroy internal class |
---|
124 | . |
---|
125 | */ |
---|
126 | Void TAppDecTop::decode() |
---|
127 | { |
---|
128 | Int poc; |
---|
129 | #if H_MV |
---|
130 | poc = -1; |
---|
131 | #endif |
---|
132 | TComList<TComPic*>* pcListPic = NULL; |
---|
133 | |
---|
134 | ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary); |
---|
135 | if (!bitstreamFile) |
---|
136 | { |
---|
137 | fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchBitstreamFile); |
---|
138 | exit(EXIT_FAILURE); |
---|
139 | } |
---|
140 | |
---|
141 | #if H_3D |
---|
142 | if( m_pchScaleOffsetFile ) |
---|
143 | { |
---|
144 | m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" ); |
---|
145 | AOF( m_pScaleOffsetFile ); |
---|
146 | } |
---|
147 | #endif |
---|
148 | InputByteStream bytestream(bitstreamFile); |
---|
149 | |
---|
150 | // create & initialize internal classes |
---|
151 | xCreateDecLib(); |
---|
152 | xInitDecLib (); |
---|
153 | #if !H_MV |
---|
154 | m_iPOCLastDisplay += m_iSkipFrame; // set the last displayed POC correctly for skip forward. |
---|
155 | |
---|
156 | // main decoder loop |
---|
157 | Bool openedReconFile = false; // reconstruction file not yet opened. (must be performed after SPS is seen) |
---|
158 | #else |
---|
159 | |
---|
160 | Int pocCurrPic = -MAX_INT; |
---|
161 | Int pocLastPic = -MAX_INT; |
---|
162 | |
---|
163 | Int layerIdLastPic = -MAX_INT; |
---|
164 | Int layerIdCurrPic = 0; |
---|
165 | |
---|
166 | Int decIdxLastPic = 0; |
---|
167 | Int decIdxCurrPic = 0; |
---|
168 | |
---|
169 | Bool firstSlice = true; |
---|
170 | #endif |
---|
171 | Bool loopFiltered = false; |
---|
172 | |
---|
173 | while (!!bitstreamFile) |
---|
174 | { |
---|
175 | /* location serves to work around a design fault in the decoder, whereby |
---|
176 | * the process of reading a new slice that is the first slice of a new frame |
---|
177 | * requires the TDecTop::decode() method to be called again with the same |
---|
178 | * nal unit. */ |
---|
179 | streampos location = bitstreamFile.tellg(); |
---|
180 | #if H_MV |
---|
181 | #if ENC_DEC_TRACE |
---|
182 | Int64 symCount = g_nSymbolCounter; |
---|
183 | #endif |
---|
184 | #endif |
---|
185 | AnnexBStats stats = AnnexBStats(); |
---|
186 | vector<uint8_t> nalUnit; |
---|
187 | InputNALUnit nalu; |
---|
188 | byteStreamNALUnit(bytestream, nalUnit, stats); |
---|
189 | |
---|
190 | // call actual decoding function |
---|
191 | Bool bNewPicture = false; |
---|
192 | #if H_MV |
---|
193 | Bool newSliceDiffPoc = false; |
---|
194 | Bool newSliceDiffLayer = false; |
---|
195 | Bool sliceSkippedFlag = false; |
---|
196 | Bool allLayersDecoded = false; |
---|
197 | #endif |
---|
198 | if (nalUnit.empty()) |
---|
199 | { |
---|
200 | /* this can happen if the following occur: |
---|
201 | * - empty input file |
---|
202 | * - two back-to-back start_code_prefixes |
---|
203 | * - start_code_prefix immediately followed by EOF |
---|
204 | */ |
---|
205 | fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n"); |
---|
206 | } |
---|
207 | else |
---|
208 | { |
---|
209 | read(nalu, nalUnit); |
---|
210 | #if H_MV |
---|
211 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) |
---|
212 | || !isNaluWithinTargetDecLayerIdSet(&nalu) |
---|
213 | || nalu.m_layerId > MAX_NUM_LAYER_IDS-1 |
---|
214 | || (nalu.m_nalUnitType == NAL_UNIT_VPS && nalu.m_layerId > 0) |
---|
215 | || (nalu.m_nalUnitType == NAL_UNIT_EOB && nalu.m_layerId > 0) |
---|
216 | || (nalu.m_nalUnitType == NAL_UNIT_EOS && nalu.m_layerId > 0) |
---|
217 | ) |
---|
218 | { |
---|
219 | bNewPicture = false; |
---|
220 | if ( !bitstreamFile ) |
---|
221 | { |
---|
222 | decIdxLastPic = decIdxCurrPic; |
---|
223 | } |
---|
224 | } |
---|
225 | else |
---|
226 | { |
---|
227 | Int decIdx = xGetDecoderIdx( nalu.m_layerId , true ); |
---|
228 | newSliceDiffLayer = nalu.isSlice() && ( nalu.m_layerId != layerIdCurrPic ) && !firstSlice; |
---|
229 | newSliceDiffPoc = m_tDecTop[decIdx]->decode(nalu, m_iSkipFrame, m_pocLastDisplay[decIdx], newSliceDiffLayer, sliceSkippedFlag ); |
---|
230 | // decode function only returns true when all of the following conditions are true |
---|
231 | // - poc in particular layer changes |
---|
232 | // - nalu does not belong to first slice in layer |
---|
233 | // - nalu.isSlice() == true |
---|
234 | |
---|
235 | if ( nalu.m_nalUnitType == NAL_UNIT_VPS ) |
---|
236 | { |
---|
237 | m_vps = m_tDecTop[decIdx]->getPrefetchedVPS(); |
---|
238 | if ( m_targetDecLayerIdSetFileEmpty ) |
---|
239 | { |
---|
240 | TComVPS* vps = m_vps; |
---|
241 | if ( m_targetOptLayerSetIdx == -1 ) |
---|
242 | { |
---|
243 | // Not normative! Corresponds to specification by "External Means". (Should be set equal to 0, when no external means available. ) |
---|
244 | m_targetOptLayerSetIdx = vps->getVpsNumLayerSetsMinus1(); |
---|
245 | } |
---|
246 | |
---|
247 | for (Int dI = 0; dI < m_numDecoders; dI++ ) |
---|
248 | { |
---|
249 | m_tDecTop[decIdx]->setTargetOptLayerSetIdx( m_targetOptLayerSetIdx ); |
---|
250 | } |
---|
251 | |
---|
252 | if ( m_targetOptLayerSetIdx < 0 || m_targetOptLayerSetIdx >= vps->getNumOutputLayerSets() ) |
---|
253 | { |
---|
254 | fprintf(stderr, "\ntarget output layer set index must be in the range of 0 to %d, inclusive \n", vps->getNumOutputLayerSets() - 1 ); |
---|
255 | exit(EXIT_FAILURE); |
---|
256 | } |
---|
257 | m_targetDecLayerIdSet = vps->getTargetDecLayerIdList( m_targetOptLayerSetIdx ); |
---|
258 | } |
---|
259 | } |
---|
260 | #if H_3D |
---|
261 | if (nalu.m_nalUnitType == NAL_UNIT_VPS ) |
---|
262 | { |
---|
263 | m_cCamParsCollector.init( m_pScaleOffsetFile, m_tDecTop[decIdx]->getPrefetchedVPS() ); |
---|
264 | } |
---|
265 | #endif |
---|
266 | bNewPicture = ( newSliceDiffLayer || newSliceDiffPoc ) && !sliceSkippedFlag; |
---|
267 | if ( nalu.isSlice() && firstSlice && !sliceSkippedFlag ) |
---|
268 | { |
---|
269 | layerIdCurrPic = nalu.m_layerId; |
---|
270 | pocCurrPic = m_tDecTop[decIdx]->getCurrPoc(); |
---|
271 | decIdxCurrPic = decIdx; |
---|
272 | firstSlice = false; |
---|
273 | } |
---|
274 | |
---|
275 | if ( bNewPicture || !bitstreamFile ) |
---|
276 | { |
---|
277 | layerIdLastPic = layerIdCurrPic; |
---|
278 | layerIdCurrPic = nalu.m_layerId; |
---|
279 | pocLastPic = pocCurrPic; |
---|
280 | pocCurrPic = m_tDecTop[decIdx]->getCurrPoc(); |
---|
281 | decIdxLastPic = decIdxCurrPic; |
---|
282 | decIdxCurrPic = decIdx; |
---|
283 | allLayersDecoded = ( pocCurrPic != pocLastPic ); |
---|
284 | } |
---|
285 | #else |
---|
286 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) ) |
---|
287 | { |
---|
288 | bNewPicture = false; |
---|
289 | } |
---|
290 | else |
---|
291 | { |
---|
292 | bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay); |
---|
293 | #endif |
---|
294 | if (bNewPicture) |
---|
295 | { |
---|
296 | bitstreamFile.clear(); |
---|
297 | /* location points to the current nalunit payload[1] due to the |
---|
298 | * need for the annexB parser to read three extra bytes. |
---|
299 | * [1] except for the first NAL unit in the file |
---|
300 | * (but bNewPicture doesn't happen then) */ |
---|
301 | bitstreamFile.seekg(location-streamoff(3)); |
---|
302 | bytestream.reset(); |
---|
303 | #if H_MV_ENC_DEC_TRAC |
---|
304 | #if ENC_DEC_TRACE |
---|
305 | const Bool resetCounter = false; |
---|
306 | if ( resetCounter ) |
---|
307 | { |
---|
308 | g_nSymbolCounter = symCount; // Only reset counter SH becomes traced twice |
---|
309 | } |
---|
310 | else |
---|
311 | { |
---|
312 | g_disableHLSTrace = true; // Tracing of second parsing of SH is not carried out |
---|
313 | } |
---|
314 | #endif |
---|
315 | #endif |
---|
316 | } |
---|
317 | } |
---|
318 | } |
---|
319 | if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS ) |
---|
320 | { |
---|
321 | if (!loopFiltered || bitstreamFile) |
---|
322 | { |
---|
323 | #if H_MV |
---|
324 | assert( decIdxLastPic != -1 ); |
---|
325 | m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet ); |
---|
326 | xMarkForOutput( allLayersDecoded, poc, layerIdLastPic ); |
---|
327 | #else |
---|
328 | m_cTDecTop.executeLoopFilters(poc, pcListPic); |
---|
329 | #endif |
---|
330 | } |
---|
331 | loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS); |
---|
332 | } |
---|
333 | #if !FIX_WRITING_OUTPUT |
---|
334 | #if SETTING_NO_OUT_PIC_PRIOR |
---|
335 | if (bNewPicture && m_cTDecTop.getIsNoOutputPriorPics()) |
---|
336 | { |
---|
337 | m_cTDecTop.checkNoOutputPriorPics( pcListPic ); |
---|
338 | } |
---|
339 | #endif |
---|
340 | #endif |
---|
341 | #if H_3D |
---|
342 | if ( allLayersDecoded || !bitstreamFile ) |
---|
343 | { |
---|
344 | for( Int dI = 0; dI < m_numDecoders; dI++ ) |
---|
345 | { |
---|
346 | TComPic* picLastCoded = m_ivPicLists.getPic( m_tDecTop[dI]->getLayerId(), pocLastPic ); |
---|
347 | assert( picLastCoded != NULL ); |
---|
348 | picLastCoded->compressMotion(1); |
---|
349 | } |
---|
350 | } |
---|
351 | #endif |
---|
352 | |
---|
353 | if( pcListPic ) |
---|
354 | { |
---|
355 | #if H_MV |
---|
356 | if ( m_pchReconFiles[decIdxLastPic] && !m_reconOpen[decIdxLastPic] ) |
---|
357 | #else |
---|
358 | if ( m_pchReconFile && !openedReconFile ) |
---|
359 | #endif |
---|
360 | { |
---|
361 | if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; } |
---|
362 | if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; } |
---|
363 | |
---|
364 | #if H_MV |
---|
365 | m_tVideoIOYuvReconFile[decIdxLastPic]->open( m_pchReconFiles[decIdxLastPic], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
366 | m_reconOpen[decIdxLastPic] = true; |
---|
367 | } |
---|
368 | #if FIX_WRITING_OUTPUT |
---|
369 | // write reconstruction to file |
---|
370 | if( bNewPicture ) |
---|
371 | { |
---|
372 | // Bumping after picture has been decoded |
---|
373 | #if ENC_DEC_TRACE |
---|
374 | g_bJustDoIt = true; |
---|
375 | writeToTraceFile( "Bumping after decoding \n", g_decTracePicOutput ); |
---|
376 | g_bJustDoIt = false; |
---|
377 | #endif |
---|
378 | xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId ); |
---|
379 | } |
---|
380 | #if SETTING_NO_OUT_PIC_PRIOR |
---|
381 | if ( (bNewPicture || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA) && m_tDecTop[decIdxLastPic]->getNoOutputPriorPicsFlag() ) |
---|
382 | { |
---|
383 | m_tDecTop[decIdxLastPic]->checkNoOutputPriorPics( pcListPic ); |
---|
384 | m_tDecTop[decIdxLastPic]->setNoOutputPriorPicsFlag (false); |
---|
385 | } |
---|
386 | #endif |
---|
387 | #endif |
---|
388 | if ( bNewPicture && newSliceDiffPoc && |
---|
389 | #else |
---|
390 | m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
391 | openedReconFile = true; |
---|
392 | } |
---|
393 | #if FIX_WRITING_OUTPUT |
---|
394 | // write reconstruction to file |
---|
395 | if( bNewPicture ) |
---|
396 | { |
---|
397 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
398 | } |
---|
399 | #if SETTING_NO_OUT_PIC_PRIOR |
---|
400 | if ( (bNewPicture || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA) && m_cTDecTop.getNoOutputPriorPicsFlag() ) |
---|
401 | { |
---|
402 | m_cTDecTop.checkNoOutputPriorPics( pcListPic ); |
---|
403 | m_cTDecTop.setNoOutputPriorPicsFlag (false); |
---|
404 | } |
---|
405 | #endif |
---|
406 | #endif |
---|
407 | if ( bNewPicture && |
---|
408 | #endif |
---|
409 | ( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
410 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
411 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
412 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
413 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) ) |
---|
414 | { |
---|
415 | #if H_MV |
---|
416 | xFlushOutput( pcListPic, decIdxLastPic ); |
---|
417 | #else |
---|
418 | xFlushOutput( pcListPic ); |
---|
419 | #endif |
---|
420 | } |
---|
421 | if (nalu.m_nalUnitType == NAL_UNIT_EOS) |
---|
422 | { |
---|
423 | #if H_MV |
---|
424 | #if FIX_OUTPUT_EOS |
---|
425 | xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId ); |
---|
426 | #else |
---|
427 | xFlushOutput( pcListPic, decIdxLastPic ); |
---|
428 | #endif |
---|
429 | #else |
---|
430 | #if FIX_OUTPUT_EOS |
---|
431 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
432 | #else |
---|
433 | xFlushOutput( pcListPic ); |
---|
434 | #endif |
---|
435 | |
---|
436 | #endif |
---|
437 | } |
---|
438 | // write reconstruction to file -- for additional bumping as defined in C.5.2.3 |
---|
439 | #if H_MV |
---|
440 | // Above comment seems to be wrong |
---|
441 | #endif |
---|
442 | #if FIX_WRITING_OUTPUT |
---|
443 | if(!bNewPicture && nalu.m_nalUnitType >= NAL_UNIT_CODED_SLICE_TRAIL_N && nalu.m_nalUnitType <= NAL_UNIT_RESERVED_VCL31) |
---|
444 | #else |
---|
445 | if(bNewPicture) |
---|
446 | #endif |
---|
447 | { |
---|
448 | #if H_MV |
---|
449 | // Bumping after reference picture set has been applied (here after first vcl nalu. |
---|
450 | #if ENC_DEC_TRACE |
---|
451 | g_bJustDoIt = true; |
---|
452 | writeToTraceFile( "Bumping after reference picture set has been applied \n", g_decTracePicOutput ); |
---|
453 | g_bJustDoIt = false; |
---|
454 | #endif |
---|
455 | |
---|
456 | xWriteOutput( m_tDecTop[decIdxCurrPic]->getListPic(), decIdxCurrPic, nalu.m_temporalId ); |
---|
457 | #else |
---|
458 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
459 | #endif |
---|
460 | } |
---|
461 | } |
---|
462 | } |
---|
463 | #if H_MV |
---|
464 | #if H_3D |
---|
465 | if( m_cCamParsCollector.isInitialized() ) |
---|
466 | { |
---|
467 | m_cCamParsCollector.setSlice( 0 ); |
---|
468 | } |
---|
469 | #endif |
---|
470 | for(UInt decIdx = 0; decIdx < m_numDecoders; decIdx++) |
---|
471 | { |
---|
472 | xFlushOutput( m_tDecTop[decIdx]->getListPic(), decIdx ); |
---|
473 | } |
---|
474 | #else |
---|
475 | xFlushOutput( pcListPic ); |
---|
476 | // delete buffers |
---|
477 | m_cTDecTop.deletePicBuffer(); |
---|
478 | #endif |
---|
479 | |
---|
480 | // destroy internal classes |
---|
481 | xDestroyDecLib(); |
---|
482 | } |
---|
483 | |
---|
484 | // ==================================================================================================================== |
---|
485 | // Protected member functions |
---|
486 | // ==================================================================================================================== |
---|
487 | |
---|
488 | Void TAppDecTop::xCreateDecLib() |
---|
489 | { |
---|
490 | #if H_MV |
---|
491 | // initialize global variables |
---|
492 | initROM(); |
---|
493 | #if H_3D_DIM_DMM |
---|
494 | initWedgeLists(); |
---|
495 | #endif |
---|
496 | #else |
---|
497 | // create decoder class |
---|
498 | m_cTDecTop.create(); |
---|
499 | #endif |
---|
500 | } |
---|
501 | |
---|
502 | Void TAppDecTop::xDestroyDecLib() |
---|
503 | { |
---|
504 | #if H_MV |
---|
505 | // destroy ROM |
---|
506 | destroyROM(); |
---|
507 | |
---|
508 | for(Int decIdx = 0; decIdx < m_numDecoders ; decIdx++) |
---|
509 | { |
---|
510 | if( m_tVideoIOYuvReconFile[decIdx] ) |
---|
511 | { |
---|
512 | m_tVideoIOYuvReconFile[decIdx]->close(); |
---|
513 | delete m_tVideoIOYuvReconFile[decIdx]; |
---|
514 | m_tVideoIOYuvReconFile[decIdx] = NULL ; |
---|
515 | } |
---|
516 | |
---|
517 | if( m_tDecTop[decIdx] ) |
---|
518 | { |
---|
519 | m_tDecTop[decIdx]->deletePicBuffer(); |
---|
520 | m_tDecTop[decIdx]->destroy() ; |
---|
521 | } |
---|
522 | delete m_tDecTop[decIdx] ; |
---|
523 | m_tDecTop[decIdx] = NULL ; |
---|
524 | } |
---|
525 | #else |
---|
526 | if ( m_pchReconFile ) |
---|
527 | { |
---|
528 | m_cTVideoIOYuvReconFile. close(); |
---|
529 | } |
---|
530 | |
---|
531 | // destroy decoder class |
---|
532 | m_cTDecTop.destroy(); |
---|
533 | #endif |
---|
534 | #if H_3D |
---|
535 | m_cCamParsCollector.uninit(); |
---|
536 | if( m_pScaleOffsetFile ) |
---|
537 | { |
---|
538 | ::fclose( m_pScaleOffsetFile ); |
---|
539 | } |
---|
540 | #endif |
---|
541 | } |
---|
542 | |
---|
543 | Void TAppDecTop::xInitDecLib() |
---|
544 | { |
---|
545 | #if !H_MV |
---|
546 | // initialize decoder class |
---|
547 | m_cTDecTop.init(); |
---|
548 | m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
549 | #endif |
---|
550 | } |
---|
551 | |
---|
552 | /** \param pcListPic list of pictures to be written to file |
---|
553 | \todo DYN_REF_FREE should be revised |
---|
554 | */ |
---|
555 | #if H_MV |
---|
556 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int decIdx, Int tId ) |
---|
557 | #else |
---|
558 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId ) |
---|
559 | #endif |
---|
560 | { |
---|
561 | |
---|
562 | if (pcListPic->empty()) |
---|
563 | { |
---|
564 | return; |
---|
565 | } |
---|
566 | |
---|
567 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
568 | Int numPicsNotYetDisplayed = 0; |
---|
569 | Int dpbFullness = 0; |
---|
570 | #if H_MV |
---|
571 | // preliminary fix |
---|
572 | TComSPS* activeSPS = m_tDecTop[0]->getActiveSPS(); |
---|
573 | #else |
---|
574 | TComSPS* activeSPS = m_cTDecTop.getActiveSPS(); |
---|
575 | #endif |
---|
576 | UInt numReorderPicsHighestTid; |
---|
577 | UInt maxDecPicBufferingHighestTid; |
---|
578 | UInt maxNrSublayers = activeSPS->getMaxTLayers(); |
---|
579 | |
---|
580 | if(m_iMaxTemporalLayer == -1 || m_iMaxTemporalLayer >= maxNrSublayers) |
---|
581 | { |
---|
582 | numReorderPicsHighestTid = activeSPS->getNumReorderPics(maxNrSublayers-1); |
---|
583 | maxDecPicBufferingHighestTid = activeSPS->getMaxDecPicBuffering(maxNrSublayers-1); |
---|
584 | } |
---|
585 | else |
---|
586 | { |
---|
587 | numReorderPicsHighestTid = activeSPS->getNumReorderPics(m_iMaxTemporalLayer); |
---|
588 | maxDecPicBufferingHighestTid = activeSPS->getMaxDecPicBuffering(m_iMaxTemporalLayer); |
---|
589 | } |
---|
590 | |
---|
591 | while (iterPic != pcListPic->end()) |
---|
592 | { |
---|
593 | TComPic* pcPic = *(iterPic); |
---|
594 | #if H_MV |
---|
595 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx]) |
---|
596 | #else |
---|
597 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay) |
---|
598 | #endif |
---|
599 | { |
---|
600 | numPicsNotYetDisplayed++; |
---|
601 | dpbFullness++; |
---|
602 | } |
---|
603 | else if(pcPic->getSlice( 0 )->isReferenced()) |
---|
604 | { |
---|
605 | dpbFullness++; |
---|
606 | } |
---|
607 | iterPic++; |
---|
608 | } |
---|
609 | iterPic = pcListPic->begin(); |
---|
610 | if (numPicsNotYetDisplayed>2) |
---|
611 | { |
---|
612 | iterPic++; |
---|
613 | } |
---|
614 | |
---|
615 | TComPic* pcPic = *(iterPic); |
---|
616 | if (numPicsNotYetDisplayed>2 && pcPic->isField()) //Field Decoding |
---|
617 | { |
---|
618 | TComList<TComPic*>::iterator endPic = pcListPic->end(); |
---|
619 | endPic--; |
---|
620 | iterPic = pcListPic->begin(); |
---|
621 | while (iterPic != endPic) |
---|
622 | { |
---|
623 | TComPic* pcPicTop = *(iterPic); |
---|
624 | iterPic++; |
---|
625 | TComPic* pcPicBottom = *(iterPic); |
---|
626 | |
---|
627 | #if H_MV |
---|
628 | if ( pcPicTop->getOutputMark() && (numPicsNotYetDisplayed > pcPicTop->getNumReorderPics(tId) && !(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) |
---|
629 | && pcPicBottom->getOutputMark() && (numPicsNotYetDisplayed > pcPicBottom->getNumReorderPics(tId) && (pcPicTop->getPOC() == m_pocLastDisplay[decIdx]+1 || m_pocLastDisplay[decIdx]<0))) |
---|
630 | #else |
---|
631 | if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && |
---|
632 | (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) && |
---|
633 | (!(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) && |
---|
634 | (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay < 0)) |
---|
635 | #endif |
---|
636 | { |
---|
637 | // write to file |
---|
638 | numPicsNotYetDisplayed = numPicsNotYetDisplayed-2; |
---|
639 | #if H_MV |
---|
640 | if ( m_pchReconFiles[decIdx] ) |
---|
641 | #else |
---|
642 | if ( m_pchReconFile ) |
---|
643 | #endif |
---|
644 | { |
---|
645 | const Window &conf = pcPicTop->getConformanceWindow(); |
---|
646 | const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window(); |
---|
647 | |
---|
648 | const Bool isTff = pcPicTop->isTopField(); |
---|
649 | #if H_MV |
---|
650 | assert( conf .getScaledFlag() ); |
---|
651 | assert( defDisp.getScaledFlag() ); |
---|
652 | #if ENC_DEC_TRACE |
---|
653 | g_bJustDoIt = true; |
---|
654 | writeToTraceFile( "OutputPic Poc" , pcPic->getPOC (), g_decTracePicOutput ); |
---|
655 | writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput ); |
---|
656 | g_bJustDoIt = false; |
---|
657 | #endif |
---|
658 | m_tVideoIOYuvReconFile[decIdx]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
659 | #else |
---|
660 | m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
661 | #endif |
---|
662 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
663 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
664 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
665 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff ); |
---|
666 | } |
---|
667 | |
---|
668 | // update POC of display order |
---|
669 | #if H_MV |
---|
670 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
671 | #else |
---|
672 | m_iPOCLastDisplay = pcPicBottom->getPOC(); |
---|
673 | #endif |
---|
674 | |
---|
675 | // erase non-referenced picture in the reference picture list after display |
---|
676 | if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true ) |
---|
677 | { |
---|
678 | #if !DYN_REF_FREE |
---|
679 | pcPicTop->setReconMark(false); |
---|
680 | |
---|
681 | // mark it should be extended later |
---|
682 | pcPicTop->getPicYuvRec()->setBorderExtension( false ); |
---|
683 | |
---|
684 | #else |
---|
685 | pcPicTop->destroy(); |
---|
686 | pcListPic->erase( iterPic ); |
---|
687 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
688 | continue; |
---|
689 | #endif |
---|
690 | } |
---|
691 | if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true ) |
---|
692 | { |
---|
693 | #if !DYN_REF_FREE |
---|
694 | pcPicBottom->setReconMark(false); |
---|
695 | |
---|
696 | // mark it should be extended later |
---|
697 | pcPicBottom->getPicYuvRec()->setBorderExtension( false ); |
---|
698 | |
---|
699 | #else |
---|
700 | pcPicBottom->destroy(); |
---|
701 | pcListPic->erase( iterPic ); |
---|
702 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
703 | continue; |
---|
704 | #endif |
---|
705 | } |
---|
706 | pcPicTop->setOutputMark(false); |
---|
707 | pcPicBottom->setOutputMark(false); |
---|
708 | } |
---|
709 | } |
---|
710 | } |
---|
711 | else if (!pcPic->isField()) //Frame Decoding |
---|
712 | { |
---|
713 | iterPic = pcListPic->begin(); |
---|
714 | while (iterPic != pcListPic->end()) |
---|
715 | { |
---|
716 | pcPic = *(iterPic); |
---|
717 | |
---|
718 | #if H_MV |
---|
719 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx] && |
---|
720 | (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid)) |
---|
721 | #else |
---|
722 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay && |
---|
723 | (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid)) |
---|
724 | #endif |
---|
725 | { |
---|
726 | // write to file |
---|
727 | numPicsNotYetDisplayed--; |
---|
728 | if(pcPic->getSlice(0)->isReferenced() == false) |
---|
729 | { |
---|
730 | dpbFullness--; |
---|
731 | } |
---|
732 | #if H_MV |
---|
733 | if ( m_pchReconFiles[decIdx] ) |
---|
734 | #else |
---|
735 | if ( m_pchReconFile ) |
---|
736 | #endif |
---|
737 | { |
---|
738 | const Window &conf = pcPic->getConformanceWindow(); |
---|
739 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
740 | #if H_MV |
---|
741 | assert( conf .getScaledFlag() ); |
---|
742 | assert( defDisp.getScaledFlag() ); |
---|
743 | #if ENC_DEC_TRACE |
---|
744 | g_bJustDoIt = true; |
---|
745 | writeToTraceFile( "OutputPic Poc" , pcPic->getPOC (), g_decTracePicOutput ); |
---|
746 | writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput ); |
---|
747 | g_bJustDoIt = false; |
---|
748 | #endif |
---|
749 | m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(), |
---|
750 | #else |
---|
751 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
752 | #endif |
---|
753 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
754 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
755 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
756 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
757 | } |
---|
758 | |
---|
759 | // update POC of display order |
---|
760 | #if H_MV |
---|
761 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
762 | #else |
---|
763 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
764 | #endif |
---|
765 | |
---|
766 | // erase non-referenced picture in the reference picture list after display |
---|
767 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
768 | { |
---|
769 | #if !DYN_REF_FREE |
---|
770 | pcPic->setReconMark(false); |
---|
771 | |
---|
772 | // mark it should be extended later |
---|
773 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
774 | |
---|
775 | #else |
---|
776 | pcPic->destroy(); |
---|
777 | pcListPic->erase( iterPic ); |
---|
778 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
779 | continue; |
---|
780 | #endif |
---|
781 | } |
---|
782 | pcPic->setOutputMark(false); |
---|
783 | #if H_MV |
---|
784 | pcPic->setPicOutputFlag(false); |
---|
785 | #endif |
---|
786 | } |
---|
787 | |
---|
788 | iterPic++; |
---|
789 | } |
---|
790 | } |
---|
791 | } |
---|
792 | /** \param pcListPic list of pictures to be written to file |
---|
793 | \todo DYN_REF_FREE should be revised |
---|
794 | */ |
---|
795 | #if H_MV |
---|
796 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int decIdx ) |
---|
797 | #else |
---|
798 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic ) |
---|
799 | #endif |
---|
800 | { |
---|
801 | if(!pcListPic || pcListPic->empty()) |
---|
802 | { |
---|
803 | return; |
---|
804 | } |
---|
805 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
806 | |
---|
807 | iterPic = pcListPic->begin(); |
---|
808 | TComPic* pcPic = *(iterPic); |
---|
809 | |
---|
810 | if (pcPic->isField()) //Field Decoding |
---|
811 | { |
---|
812 | TComList<TComPic*>::iterator endPic = pcListPic->end(); |
---|
813 | endPic--; |
---|
814 | TComPic *pcPicTop, *pcPicBottom = NULL; |
---|
815 | while (iterPic != endPic) |
---|
816 | { |
---|
817 | pcPicTop = *(iterPic); |
---|
818 | iterPic++; |
---|
819 | pcPicBottom = *(iterPic); |
---|
820 | |
---|
821 | if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && !(pcPicTop->getPOC()%2) && (pcPicBottom->getPOC() == pcPicTop->getPOC()+1) ) |
---|
822 | { |
---|
823 | // write to file |
---|
824 | #if H_MV |
---|
825 | if ( m_pchReconFiles[decIdx] ) |
---|
826 | #else |
---|
827 | if ( m_pchReconFile ) |
---|
828 | #endif |
---|
829 | { |
---|
830 | const Window &conf = pcPicTop->getConformanceWindow(); |
---|
831 | const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window(); |
---|
832 | const Bool isTff = pcPicTop->isTopField(); |
---|
833 | #if H_MV |
---|
834 | assert( conf .getScaledFlag() ); |
---|
835 | assert( defDisp.getScaledFlag() ); |
---|
836 | #if ENC_DEC_TRACE |
---|
837 | g_bJustDoIt = true; |
---|
838 | writeToTraceFile( "OutputPic Poc" , pcPic->getPOC (), g_decTracePicOutput ); |
---|
839 | writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput ); |
---|
840 | g_bJustDoIt = false; |
---|
841 | #endif |
---|
842 | m_tVideoIOYuvReconFile[decIdx]->write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
843 | #else |
---|
844 | m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
845 | #endif |
---|
846 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
847 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
848 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
849 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff ); |
---|
850 | } |
---|
851 | |
---|
852 | // update POC of display order |
---|
853 | #if H_MV |
---|
854 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
855 | #else |
---|
856 | m_iPOCLastDisplay = pcPicBottom->getPOC(); |
---|
857 | #endif |
---|
858 | // erase non-referenced picture in the reference picture list after display |
---|
859 | if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true ) |
---|
860 | { |
---|
861 | #if !DYN_REF_FREE |
---|
862 | pcPicTop->setReconMark(false); |
---|
863 | |
---|
864 | // mark it should be extended later |
---|
865 | pcPicTop->getPicYuvRec()->setBorderExtension( false ); |
---|
866 | |
---|
867 | #else |
---|
868 | pcPicTop->destroy(); |
---|
869 | pcListPic->erase( iterPic ); |
---|
870 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
871 | continue; |
---|
872 | #endif |
---|
873 | } |
---|
874 | if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true ) |
---|
875 | { |
---|
876 | #if !DYN_REF_FREE |
---|
877 | pcPicBottom->setReconMark(false); |
---|
878 | |
---|
879 | // mark it should be extended later |
---|
880 | pcPicBottom->getPicYuvRec()->setBorderExtension( false ); |
---|
881 | |
---|
882 | #else |
---|
883 | pcPicBottom->destroy(); |
---|
884 | pcListPic->erase( iterPic ); |
---|
885 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
886 | continue; |
---|
887 | #endif |
---|
888 | } |
---|
889 | pcPicTop->setOutputMark(false); |
---|
890 | pcPicBottom->setOutputMark(false); |
---|
891 | |
---|
892 | #if !DYN_REF_FREE |
---|
893 | if(pcPicTop) |
---|
894 | { |
---|
895 | pcPicTop->destroy(); |
---|
896 | delete pcPicTop; |
---|
897 | pcPicTop = NULL; |
---|
898 | } |
---|
899 | #endif |
---|
900 | } |
---|
901 | } |
---|
902 | if(pcPicBottom) |
---|
903 | { |
---|
904 | pcPicBottom->destroy(); |
---|
905 | delete pcPicBottom; |
---|
906 | pcPicBottom = NULL; |
---|
907 | } |
---|
908 | } |
---|
909 | else //Frame decoding |
---|
910 | { |
---|
911 | while (iterPic != pcListPic->end()) |
---|
912 | { |
---|
913 | pcPic = *(iterPic); |
---|
914 | |
---|
915 | if ( pcPic->getOutputMark() ) |
---|
916 | { |
---|
917 | // write to file |
---|
918 | #if H_MV |
---|
919 | if ( m_pchReconFiles[decIdx] ) |
---|
920 | #else |
---|
921 | if ( m_pchReconFile ) |
---|
922 | #endif |
---|
923 | { |
---|
924 | const Window &conf = pcPic->getConformanceWindow(); |
---|
925 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
926 | #if H_MV |
---|
927 | assert( conf .getScaledFlag() ); |
---|
928 | assert( defDisp.getScaledFlag() ); |
---|
929 | #if ENC_DEC_TRACE |
---|
930 | g_bJustDoIt = true; |
---|
931 | writeToTraceFile( "OutputPic Poc" , pcPic->getPOC (), g_decTracePicOutput ); |
---|
932 | writeToTraceFile( "OutputPic LayerId", pcPic->getLayerId(), g_decTracePicOutput ); |
---|
933 | g_bJustDoIt = false; |
---|
934 | #endif |
---|
935 | m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(), |
---|
936 | #else |
---|
937 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
938 | #endif |
---|
939 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
940 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
941 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
942 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
943 | } |
---|
944 | |
---|
945 | // update POC of display order |
---|
946 | #if H_MV |
---|
947 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
948 | #else |
---|
949 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
950 | #endif |
---|
951 | |
---|
952 | // erase non-referenced picture in the reference picture list after display |
---|
953 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
954 | { |
---|
955 | #if !DYN_REF_FREE |
---|
956 | pcPic->setReconMark(false); |
---|
957 | |
---|
958 | // mark it should be extended later |
---|
959 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
960 | |
---|
961 | #else |
---|
962 | pcPic->destroy(); |
---|
963 | pcListPic->erase( iterPic ); |
---|
964 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
965 | continue; |
---|
966 | #endif |
---|
967 | } |
---|
968 | pcPic->setOutputMark(false); |
---|
969 | #if H_MV |
---|
970 | pcPic->setPicOutputFlag(false); |
---|
971 | #endif |
---|
972 | } |
---|
973 | #if !H_MV |
---|
974 | #if !DYN_REF_FREE |
---|
975 | if(pcPic) |
---|
976 | { |
---|
977 | pcPic->destroy(); |
---|
978 | delete pcPic; |
---|
979 | pcPic = NULL; |
---|
980 | } |
---|
981 | #endif |
---|
982 | #endif |
---|
983 | iterPic++; |
---|
984 | } |
---|
985 | } |
---|
986 | #if H_MV |
---|
987 | m_pocLastDisplay[decIdx] = -MAX_INT; |
---|
988 | #else |
---|
989 | pcListPic->clear(); |
---|
990 | m_iPOCLastDisplay = -MAX_INT; |
---|
991 | #endif |
---|
992 | } |
---|
993 | |
---|
994 | /** \param nalu Input nalu to check whether its LayerId is within targetDecLayerIdSet |
---|
995 | */ |
---|
996 | Bool TAppDecTop::isNaluWithinTargetDecLayerIdSet( InputNALUnit* nalu ) |
---|
997 | { |
---|
998 | if ( m_targetDecLayerIdSet.size() == 0 ) // By default, the set is empty, meaning all LayerIds are allowed |
---|
999 | { |
---|
1000 | return true; |
---|
1001 | } |
---|
1002 | for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++) |
---|
1003 | { |
---|
1004 | #if H_MV |
---|
1005 | if ( nalu->m_layerId == (*it) ) |
---|
1006 | #else |
---|
1007 | if ( nalu->m_reservedZero6Bits == (*it) ) |
---|
1008 | #endif |
---|
1009 | { |
---|
1010 | return true; |
---|
1011 | } |
---|
1012 | } |
---|
1013 | return false; |
---|
1014 | } |
---|
1015 | |
---|
1016 | #if H_MV |
---|
1017 | Int TAppDecTop::xGetDecoderIdx( Int layerId, Bool createFlag /*= false */ ) |
---|
1018 | { |
---|
1019 | Int decIdx = -1; |
---|
1020 | |
---|
1021 | if ( layerId > MAX_NUM_LAYER_IDS-1 ) |
---|
1022 | { |
---|
1023 | return decIdx; |
---|
1024 | } |
---|
1025 | |
---|
1026 | if ( m_layerIdToDecIdx[ layerId ] != -1 ) |
---|
1027 | { |
---|
1028 | decIdx = m_layerIdToDecIdx[ layerId ]; |
---|
1029 | } |
---|
1030 | else |
---|
1031 | { |
---|
1032 | assert ( createFlag ); |
---|
1033 | assert( m_numDecoders < MAX_NUM_LAYERS ); |
---|
1034 | |
---|
1035 | decIdx = m_numDecoders; |
---|
1036 | |
---|
1037 | // Init decoder |
---|
1038 | m_tDecTop[ decIdx ] = new TDecTop; |
---|
1039 | m_tDecTop[ decIdx ]->create(); |
---|
1040 | m_tDecTop[ decIdx ]->init( ); |
---|
1041 | m_tDecTop[ decIdx ]->setLayerId( layerId ); |
---|
1042 | m_tDecTop[ decIdx ]->setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
1043 | m_tDecTop[ decIdx ]->setIvPicLists( &m_ivPicLists ); |
---|
1044 | m_tDecTop[ decIdx ]->setLayerInitilizedFlags( m_layerInitilizedFlags ); |
---|
1045 | m_tDecTop[ decIdx ]->setTargetOptLayerSetIdx( m_targetOptLayerSetIdx ); |
---|
1046 | |
---|
1047 | #if H_3D |
---|
1048 | m_tDecTop[ decIdx ]->setCamParsCollector( &m_cCamParsCollector ); |
---|
1049 | #endif |
---|
1050 | |
---|
1051 | // append pic list of new decoder to PicLists |
---|
1052 | assert( m_ivPicLists.size() == m_numDecoders ); |
---|
1053 | m_ivPicLists.push_back( m_tDecTop[ decIdx ]->getListPic() ); |
---|
1054 | |
---|
1055 | // create recon file related stuff |
---|
1056 | Char* pchTempFilename = NULL; |
---|
1057 | if ( m_pchReconFile ) |
---|
1058 | { |
---|
1059 | Char buffer[4]; |
---|
1060 | sprintf(buffer,"_%i", layerId ); |
---|
1061 | assert ( m_pchReconFile ); |
---|
1062 | xAppendToFileNameEnd( m_pchReconFile , buffer, pchTempFilename ); |
---|
1063 | assert( m_pchReconFiles.size() == m_numDecoders ); |
---|
1064 | } |
---|
1065 | |
---|
1066 | m_pchReconFiles.push_back( pchTempFilename ); |
---|
1067 | |
---|
1068 | m_tVideoIOYuvReconFile[ decIdx ] = new TVideoIOYuv; |
---|
1069 | m_reconOpen [ decIdx ] = false; |
---|
1070 | |
---|
1071 | // set others |
---|
1072 | m_pocLastDisplay [ decIdx ] = -MAX_INT; |
---|
1073 | m_layerIdToDecIdx [ layerId ] = decIdx; |
---|
1074 | |
---|
1075 | m_numDecoders++; |
---|
1076 | }; |
---|
1077 | return decIdx; |
---|
1078 | |
---|
1079 | } |
---|
1080 | |
---|
1081 | Void TAppDecTop::xMarkForOutput( Bool allLayersDecoded, Int pocLastPic, Int layerIdLastPic ) |
---|
1082 | { |
---|
1083 | vector<Int> targetOptLayerIdList = m_vps->getTargetOptLayerIdList( m_targetOptLayerSetIdx ); |
---|
1084 | |
---|
1085 | if (m_vps->getAltOutputLayerFlagVar( m_targetOptLayerSetIdx ) ) |
---|
1086 | { |
---|
1087 | assert( targetOptLayerIdList.size() == 1 ); |
---|
1088 | Int targetLayerId = targetOptLayerIdList[0]; |
---|
1089 | |
---|
1090 | TComPic* curPic = m_ivPicLists.getPic( layerIdLastPic, pocLastPic ); |
---|
1091 | assert( curPic != NULL ); |
---|
1092 | |
---|
1093 | if ( layerIdLastPic == targetLayerId ) |
---|
1094 | { |
---|
1095 | if ( curPic->getPicOutputFlag() ) |
---|
1096 | { |
---|
1097 | curPic->setOutputMark( true ); |
---|
1098 | } |
---|
1099 | else |
---|
1100 | { |
---|
1101 | xMarkAltOutPic( targetLayerId, pocLastPic ); |
---|
1102 | } |
---|
1103 | m_markedForOutput = true; |
---|
1104 | } |
---|
1105 | else if ( ( layerIdLastPic > targetLayerId || allLayersDecoded ) && !m_markedForOutput ) |
---|
1106 | { |
---|
1107 | xMarkAltOutPic( targetLayerId, pocLastPic ); |
---|
1108 | } |
---|
1109 | |
---|
1110 | if ( allLayersDecoded ) |
---|
1111 | { |
---|
1112 | m_markedForOutput = false; |
---|
1113 | } |
---|
1114 | } |
---|
1115 | else |
---|
1116 | { |
---|
1117 | for( Int dI = 0; dI < m_numDecoders; dI++ ) |
---|
1118 | { |
---|
1119 | Int layerId = m_tDecTop[dI]->getLayerId(); |
---|
1120 | TComPic* curPic = m_ivPicLists.getPic( layerId, pocLastPic ); |
---|
1121 | if ( curPic != NULL ) |
---|
1122 | { |
---|
1123 | if ( curPic->getReconMark() ) |
---|
1124 | { |
---|
1125 | Bool isTargetOptLayer = std::find(targetOptLayerIdList.begin(), targetOptLayerIdList.end(), layerId) != targetOptLayerIdList.end(); |
---|
1126 | curPic->setOutputMark( isTargetOptLayer ? curPic->getPicOutputFlag() : false ); |
---|
1127 | } |
---|
1128 | } |
---|
1129 | } |
---|
1130 | } |
---|
1131 | } |
---|
1132 | |
---|
1133 | Void TAppDecTop::xMarkAltOutPic( Int targetOutputLayer, Int pocLastPic ) |
---|
1134 | { |
---|
1135 | Int optLayerIdxInVps = m_vps->getLayerIdInNuh( targetOutputLayer ); |
---|
1136 | Int highestNuhLayerId = -1; |
---|
1137 | TComPic* picWithHighestNuhLayerId = NULL; |
---|
1138 | for (Int dIdx = 0; dIdx < m_numDecoders; dIdx++) |
---|
1139 | { |
---|
1140 | Int curLayerId = m_tDecTop[dIdx]->getLayerId(); |
---|
1141 | Int curLayerIdxInVps = m_vps->getLayerIdInNuh( curLayerId ); |
---|
1142 | if ( m_vps->getInDirectDependencyFlag(optLayerIdxInVps, curLayerIdxInVps ) ) |
---|
1143 | { |
---|
1144 | TComPic* curPic = m_ivPicLists.getPic( curLayerId, pocLastPic ); |
---|
1145 | if (curPic != NULL) |
---|
1146 | { |
---|
1147 | if (curPic->getReconMark() && curPic->getPicOutputFlag() ) |
---|
1148 | { |
---|
1149 | curPic->setOutputMark ( false ); |
---|
1150 | curPic->setPicOutputFlag( false ); |
---|
1151 | if ( curLayerId > highestNuhLayerId) |
---|
1152 | { |
---|
1153 | highestNuhLayerId = curLayerId ; |
---|
1154 | picWithHighestNuhLayerId = curPic; |
---|
1155 | } |
---|
1156 | } |
---|
1157 | } |
---|
1158 | } |
---|
1159 | } |
---|
1160 | if ( picWithHighestNuhLayerId != NULL ) |
---|
1161 | { |
---|
1162 | picWithHighestNuhLayerId->setPicOutputFlag(true); |
---|
1163 | picWithHighestNuhLayerId->setOutputMark (true); |
---|
1164 | } |
---|
1165 | } |
---|
1166 | |
---|
1167 | #endif |
---|
1168 | //! \} |
---|