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 | #include <iostream> |
---|
44 | #include "TAppDecTop.h" |
---|
45 | #include "TLibDecoder/AnnexBread.h" |
---|
46 | #include "TLibDecoder/NALread.h" |
---|
47 | //! \ingroup TAppDecoder |
---|
48 | //! \{ |
---|
49 | |
---|
50 | // ==================================================================================================================== |
---|
51 | // Constructor / destructor / initialization / destroy |
---|
52 | // ==================================================================================================================== |
---|
53 | |
---|
54 | #if SVC_EXTENSION |
---|
55 | TAppDecTop::TAppDecTop() |
---|
56 | { |
---|
57 | for(UInt layer=0; layer < MAX_LAYERS; layer++) |
---|
58 | { |
---|
59 | m_aiPOCLastDisplay[layer] = -MAX_INT; |
---|
60 | m_apcTDecTop[layer] = &m_acTDecTop[layer]; |
---|
61 | } |
---|
62 | } |
---|
63 | #else |
---|
64 | TAppDecTop::TAppDecTop() |
---|
65 | : m_iPOCLastDisplay(-MAX_INT) |
---|
66 | { |
---|
67 | } |
---|
68 | #endif |
---|
69 | |
---|
70 | Void TAppDecTop::create() |
---|
71 | { |
---|
72 | } |
---|
73 | |
---|
74 | Void TAppDecTop::destroy() |
---|
75 | { |
---|
76 | if (m_pchBitstreamFile) |
---|
77 | { |
---|
78 | free (m_pchBitstreamFile); |
---|
79 | m_pchBitstreamFile = NULL; |
---|
80 | } |
---|
81 | #if SVC_EXTENSION |
---|
82 | for( Int i = 0; i <= m_tgtLayerId; i++ ) |
---|
83 | { |
---|
84 | if( m_pchReconFile[i] ) |
---|
85 | { |
---|
86 | free ( m_pchReconFile[i] ); |
---|
87 | m_pchReconFile[i] = NULL; |
---|
88 | } |
---|
89 | } |
---|
90 | #if AVC_BASE |
---|
91 | if( m_pchBLReconFile ) |
---|
92 | { |
---|
93 | free ( m_pchBLReconFile ); |
---|
94 | m_pchBLReconFile = NULL; |
---|
95 | } |
---|
96 | #endif |
---|
97 | #else |
---|
98 | if (m_pchReconFile) |
---|
99 | { |
---|
100 | free (m_pchReconFile); |
---|
101 | m_pchReconFile = NULL; |
---|
102 | } |
---|
103 | #endif |
---|
104 | #if AVC_SYNTAX || SYNTAX_OUTPUT |
---|
105 | if( m_pchBLSyntaxFile ) |
---|
106 | { |
---|
107 | free ( m_pchBLSyntaxFile ); |
---|
108 | m_pchBLSyntaxFile = NULL; |
---|
109 | } |
---|
110 | #endif |
---|
111 | } |
---|
112 | |
---|
113 | // ==================================================================================================================== |
---|
114 | // Public member functions |
---|
115 | // ==================================================================================================================== |
---|
116 | |
---|
117 | /** |
---|
118 | - create internal class |
---|
119 | - initialize internal class |
---|
120 | - until the end of the bitstream, call decoding function in TDecTop class |
---|
121 | - delete allocated buffers |
---|
122 | - destroy internal class |
---|
123 | . |
---|
124 | */ |
---|
125 | #if SVC_EXTENSION |
---|
126 | Void TAppDecTop::decode() |
---|
127 | { |
---|
128 | Int poc; |
---|
129 | TComList<TComPic*>* pcListPic = NULL; |
---|
130 | |
---|
131 | ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary); |
---|
132 | if (!bitstreamFile) |
---|
133 | { |
---|
134 | fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchBitstreamFile); |
---|
135 | exit(EXIT_FAILURE); |
---|
136 | } |
---|
137 | |
---|
138 | InputByteStream bytestream(bitstreamFile); |
---|
139 | |
---|
140 | // create & initialize internal classes |
---|
141 | xCreateDecLib(); |
---|
142 | xInitDecLib (); |
---|
143 | |
---|
144 | // main decoder loop |
---|
145 | Bool openedReconFile[MAX_LAYERS]; // reconstruction file not yet opened. (must be performed after SPS is seen) |
---|
146 | Bool loopFiltered[MAX_LAYERS]; |
---|
147 | memset( loopFiltered, false, sizeof( loopFiltered ) ); |
---|
148 | |
---|
149 | for(UInt layer=0; layer<=m_tgtLayerId; layer++) |
---|
150 | { |
---|
151 | openedReconFile[layer] = false; |
---|
152 | m_aiPOCLastDisplay[layer] += m_iSkipFrame; // set the last displayed POC correctly for skip forward. |
---|
153 | } |
---|
154 | |
---|
155 | UInt curLayerId = 0; // current layer to be reconstructed |
---|
156 | |
---|
157 | #if AVC_BASE |
---|
158 | TComPic pcBLPic; |
---|
159 | fstream streamYUV; |
---|
160 | if( m_pchBLReconFile ) |
---|
161 | { |
---|
162 | streamYUV.open( m_pchBLReconFile, fstream::in | fstream::binary ); |
---|
163 | } |
---|
164 | TComList<TComPic*> *cListPic = m_acTDecTop[0].getListPic(); |
---|
165 | m_acTDecTop[0].setBLsize( m_iBLSourceWidth, m_iBLSourceHeight ); |
---|
166 | m_acTDecTop[0].setBLReconFile( &streamYUV ); |
---|
167 | pcBLPic.setLayerId( 0 ); |
---|
168 | cListPic->pushBack( &pcBLPic ); |
---|
169 | #if AVC_SYNTAX |
---|
170 | fstream streamSyntaxFile; |
---|
171 | if( m_pchBLSyntaxFile ) |
---|
172 | { |
---|
173 | streamSyntaxFile.open( m_pchBLSyntaxFile, fstream::in | fstream::binary ); |
---|
174 | } |
---|
175 | m_acTDecTop[0].setBLSyntaxFile( &streamSyntaxFile ); |
---|
176 | #endif |
---|
177 | #endif |
---|
178 | |
---|
179 | while (!!bitstreamFile) |
---|
180 | { |
---|
181 | /* location serves to work around a design fault in the decoder, whereby |
---|
182 | * the process of reading a new slice that is the first slice of a new frame |
---|
183 | * requires the TDecTop::decode() method to be called again with the same |
---|
184 | * nal unit. */ |
---|
185 | streampos location = bitstreamFile.tellg(); |
---|
186 | AnnexBStats stats = AnnexBStats(); |
---|
187 | |
---|
188 | vector<uint8_t> nalUnit; |
---|
189 | InputNALUnit nalu; |
---|
190 | byteStreamNALUnit(bytestream, nalUnit, stats); |
---|
191 | |
---|
192 | // call actual decoding function |
---|
193 | Bool bNewPicture = false; |
---|
194 | Bool bNewPOC = false; |
---|
195 | if (nalUnit.empty()) |
---|
196 | { |
---|
197 | /* this can happen if the following occur: |
---|
198 | * - empty input file |
---|
199 | * - two back-to-back start_code_prefixes |
---|
200 | * - start_code_prefix immediately followed by EOF |
---|
201 | */ |
---|
202 | fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n"); |
---|
203 | } |
---|
204 | else |
---|
205 | { |
---|
206 | read(nalu, nalUnit); |
---|
207 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) || |
---|
208 | (nalu.m_layerId > m_tgtLayerId) ) |
---|
209 | { |
---|
210 | bNewPicture = false; |
---|
211 | } |
---|
212 | else |
---|
213 | { |
---|
214 | bNewPicture = m_acTDecTop[nalu.m_layerId].decode(nalu, m_iSkipFrame, m_aiPOCLastDisplay[nalu.m_layerId], curLayerId, bNewPOC); |
---|
215 | if (bNewPicture) |
---|
216 | { |
---|
217 | bitstreamFile.clear(); |
---|
218 | /* location points to the current nalunit payload[1] due to the |
---|
219 | * need for the annexB parser to read three extra bytes. |
---|
220 | * [1] except for the first NAL unit in the file |
---|
221 | * (but bNewPicture doesn't happen then) */ |
---|
222 | bitstreamFile.seekg(location-streamoff(3)); |
---|
223 | bytestream.reset(); |
---|
224 | } |
---|
225 | } |
---|
226 | } |
---|
227 | |
---|
228 | if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS) |
---|
229 | { |
---|
230 | #if O0194_DIFFERENT_BITDEPTH_EL_BL |
---|
231 | //Bug fix: The bit depth was not set correctly for each layer when doing DBF |
---|
232 | g_bitDepthY = g_bitDepthYLayer[curLayerId]; |
---|
233 | g_bitDepthC = g_bitDepthCLayer[curLayerId]; |
---|
234 | #endif |
---|
235 | if (!loopFiltered[curLayerId] || bitstreamFile) |
---|
236 | { |
---|
237 | m_acTDecTop[curLayerId].executeLoopFilters(poc, pcListPic); |
---|
238 | } |
---|
239 | loopFiltered[curLayerId] = (nalu.m_nalUnitType == NAL_UNIT_EOS); |
---|
240 | #if EARLY_REF_PIC_MARKING |
---|
241 | m_acTDecTop[curLayerId].earlyPicMarking(m_iMaxTemporalLayer, m_targetDecLayerIdSet); |
---|
242 | #endif |
---|
243 | } |
---|
244 | |
---|
245 | if( pcListPic ) |
---|
246 | { |
---|
247 | if ( m_pchReconFile[curLayerId] && !openedReconFile[curLayerId] ) |
---|
248 | { |
---|
249 | if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; } |
---|
250 | if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; } |
---|
251 | |
---|
252 | m_acTVideoIOYuvReconFile[curLayerId].open( m_pchReconFile[curLayerId], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
253 | |
---|
254 | openedReconFile[curLayerId] = true; |
---|
255 | } |
---|
256 | #if ALIGNED_BUMPING |
---|
257 | Bool outputPicturesFlag = true; |
---|
258 | #if NO_OUTPUT_OF_PRIOR_PICS |
---|
259 | if( m_acTDecTop[nalu.m_layerId].getNoOutputPriorPicsFlag() ) |
---|
260 | { |
---|
261 | outputPicturesFlag = false; |
---|
262 | } |
---|
263 | #endif |
---|
264 | |
---|
265 | if (nalu.m_nalUnitType == NAL_UNIT_EOS) // End of sequence |
---|
266 | { |
---|
267 | flushAllPictures( nalu.m_layerId, outputPicturesFlag ); |
---|
268 | } |
---|
269 | if( bNewPicture ) // New picture, slice header parsed but picture not decoded |
---|
270 | { |
---|
271 | #if NO_OUTPUT_OF_PRIOR_PICS |
---|
272 | if( |
---|
273 | #else |
---|
274 | if ( bNewPOC && |
---|
275 | #endif |
---|
276 | ( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
277 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
278 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
279 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
280 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) ) |
---|
281 | { |
---|
282 | flushAllPictures( nalu.m_layerId, outputPicturesFlag ); |
---|
283 | } |
---|
284 | else |
---|
285 | { |
---|
286 | this->checkOutputBeforeDecoding( nalu.m_layerId ); |
---|
287 | } |
---|
288 | } |
---|
289 | |
---|
290 | /* The following code has to be executed when the last DU of the picture is decoded |
---|
291 | TODO: Need code to identify end of decoding a picture |
---|
292 | { |
---|
293 | this->checkOutputAfterDecoding( ); |
---|
294 | } */ |
---|
295 | #else |
---|
296 | if ( bNewPicture && bNewPOC && |
---|
297 | ( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
298 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
299 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
300 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
301 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) ) |
---|
302 | { |
---|
303 | xFlushOutput( pcListPic, curLayerId ); |
---|
304 | } |
---|
305 | if (nalu.m_nalUnitType == NAL_UNIT_EOS) |
---|
306 | { |
---|
307 | xFlushOutput( pcListPic, curLayerId ); |
---|
308 | } |
---|
309 | // write reconstruction to file |
---|
310 | if(bNewPicture) |
---|
311 | { |
---|
312 | xWriteOutput( pcListPic, curLayerId, nalu.m_temporalId ); |
---|
313 | } |
---|
314 | #endif |
---|
315 | } |
---|
316 | } |
---|
317 | #if ALIGNED_BUMPING |
---|
318 | flushAllPictures( true ); |
---|
319 | #else |
---|
320 | for(UInt layer = 0; layer <= m_tgtLayerId; layer++) |
---|
321 | { |
---|
322 | xFlushOutput( m_acTDecTop[layer].getListPic(), layer ); |
---|
323 | } |
---|
324 | #endif |
---|
325 | // delete buffers |
---|
326 | #if AVC_BASE |
---|
327 | UInt layerIdmin = m_acTDecTop[0].getBLReconFile()->is_open() ? 1 : 0; |
---|
328 | |
---|
329 | if( streamYUV.is_open() ) |
---|
330 | { |
---|
331 | streamYUV.close(); |
---|
332 | } |
---|
333 | #if AVC_SYNTAX |
---|
334 | if( streamSyntaxFile.is_open() ) |
---|
335 | { |
---|
336 | streamSyntaxFile.close(); |
---|
337 | } |
---|
338 | #endif |
---|
339 | pcBLPic.destroy(); |
---|
340 | |
---|
341 | for(UInt layer = layerIdmin; layer <= m_tgtLayerId; layer++) |
---|
342 | #else |
---|
343 | for(UInt layer = 0; layer <= m_tgtLayerId; layer++) |
---|
344 | #endif |
---|
345 | { |
---|
346 | m_acTDecTop[layer].deletePicBuffer(); |
---|
347 | } |
---|
348 | |
---|
349 | // destroy internal classes |
---|
350 | xDestroyDecLib(); |
---|
351 | } |
---|
352 | #else |
---|
353 | Void TAppDecTop::decode() |
---|
354 | { |
---|
355 | Int poc; |
---|
356 | TComList<TComPic*>* pcListPic = NULL; |
---|
357 | |
---|
358 | ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary); |
---|
359 | if (!bitstreamFile) |
---|
360 | { |
---|
361 | fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchBitstreamFile); |
---|
362 | exit(EXIT_FAILURE); |
---|
363 | } |
---|
364 | |
---|
365 | InputByteStream bytestream(bitstreamFile); |
---|
366 | |
---|
367 | // create & initialize internal classes |
---|
368 | xCreateDecLib(); |
---|
369 | xInitDecLib (); |
---|
370 | m_iPOCLastDisplay += m_iSkipFrame; // set the last displayed POC correctly for skip forward. |
---|
371 | |
---|
372 | // main decoder loop |
---|
373 | Bool openedReconFile = false; // reconstruction file not yet opened. (must be performed after SPS is seen) |
---|
374 | Bool loopFiltered = false; |
---|
375 | |
---|
376 | #if SYNTAX_OUTPUT |
---|
377 | if( !m_pchBLSyntaxFile ) |
---|
378 | { |
---|
379 | printf( "Wrong base layer syntax file\n" ); |
---|
380 | exit(EXIT_FAILURE); |
---|
381 | } |
---|
382 | fstream streamSyntaxFile( m_pchBLSyntaxFile, fstream::out | fstream::binary ); |
---|
383 | if( !streamSyntaxFile.good() ) |
---|
384 | { |
---|
385 | printf( "Base layer syntax input reading error\n" ); |
---|
386 | exit(EXIT_FAILURE); |
---|
387 | } |
---|
388 | m_cTDecTop.setBLSyntaxFile( &streamSyntaxFile ); |
---|
389 | |
---|
390 | for( Int i = m_iBLFrames * m_iBLSourceWidth * m_iBLSourceHeight * SYNTAX_BYTES / 16; i >= 0; i-- ) |
---|
391 | { |
---|
392 | streamSyntaxFile.put( 0 ); |
---|
393 | } |
---|
394 | streamSyntaxFile.seekp( 0 ); |
---|
395 | #endif |
---|
396 | |
---|
397 | while (!!bitstreamFile) |
---|
398 | { |
---|
399 | /* location serves to work around a design fault in the decoder, whereby |
---|
400 | * the process of reading a new slice that is the first slice of a new frame |
---|
401 | * requires the TDecTop::decode() method to be called again with the same |
---|
402 | * nal unit. */ |
---|
403 | streampos location = bitstreamFile.tellg(); |
---|
404 | AnnexBStats stats = AnnexBStats(); |
---|
405 | |
---|
406 | vector<uint8_t> nalUnit; |
---|
407 | InputNALUnit nalu; |
---|
408 | byteStreamNALUnit(bytestream, nalUnit, stats); |
---|
409 | |
---|
410 | // call actual decoding function |
---|
411 | Bool bNewPicture = false; |
---|
412 | if (nalUnit.empty()) |
---|
413 | { |
---|
414 | /* this can happen if the following occur: |
---|
415 | * - empty input file |
---|
416 | * - two back-to-back start_code_prefixes |
---|
417 | * - start_code_prefix immediately followed by EOF |
---|
418 | */ |
---|
419 | fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n"); |
---|
420 | } |
---|
421 | else |
---|
422 | { |
---|
423 | read(nalu, nalUnit); |
---|
424 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) ) |
---|
425 | { |
---|
426 | bNewPicture = false; |
---|
427 | } |
---|
428 | else |
---|
429 | { |
---|
430 | bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay); |
---|
431 | if (bNewPicture) |
---|
432 | { |
---|
433 | bitstreamFile.clear(); |
---|
434 | /* location points to the current nalunit payload[1] due to the |
---|
435 | * need for the annexB parser to read three extra bytes. |
---|
436 | * [1] except for the first NAL unit in the file |
---|
437 | * (but bNewPicture doesn't happen then) */ |
---|
438 | bitstreamFile.seekg(location-streamoff(3)); |
---|
439 | bytestream.reset(); |
---|
440 | } |
---|
441 | } |
---|
442 | } |
---|
443 | if (bNewPicture || !bitstreamFile || nalu.m_nalUnitType == NAL_UNIT_EOS) |
---|
444 | { |
---|
445 | if (!loopFiltered || bitstreamFile) |
---|
446 | { |
---|
447 | m_cTDecTop.executeLoopFilters(poc, pcListPic); |
---|
448 | } |
---|
449 | loopFiltered = (nalu.m_nalUnitType == NAL_UNIT_EOS); |
---|
450 | } |
---|
451 | #if !FIX_WRITING_OUTPUT |
---|
452 | #if SETTING_NO_OUT_PIC_PRIOR |
---|
453 | if (bNewPicture && m_cTDecTop.getNoOutputPriorPicsFlag()) |
---|
454 | { |
---|
455 | m_cTDecTop.checkNoOutputPriorPics( pcListPic ); |
---|
456 | } |
---|
457 | #endif |
---|
458 | #endif |
---|
459 | |
---|
460 | if( pcListPic ) |
---|
461 | { |
---|
462 | if ( m_pchReconFile && !openedReconFile ) |
---|
463 | { |
---|
464 | if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; } |
---|
465 | if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; } |
---|
466 | |
---|
467 | m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
468 | openedReconFile = true; |
---|
469 | } |
---|
470 | #if FIX_WRITING_OUTPUT |
---|
471 | // write reconstruction to file |
---|
472 | if( bNewPicture ) |
---|
473 | { |
---|
474 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
475 | } |
---|
476 | #if SETTING_NO_OUT_PIC_PRIOR |
---|
477 | if ( (bNewPicture || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_CRA) && m_cTDecTop.getNoOutputPriorPicsFlag() ) |
---|
478 | { |
---|
479 | m_cTDecTop.checkNoOutputPriorPics( pcListPic ); |
---|
480 | m_cTDecTop.setNoOutputPriorPicsFlag (false); |
---|
481 | } |
---|
482 | #endif |
---|
483 | #endif |
---|
484 | if ( bNewPicture && |
---|
485 | ( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
486 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
487 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
488 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
489 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) ) |
---|
490 | { |
---|
491 | xFlushOutput( pcListPic ); |
---|
492 | } |
---|
493 | if (nalu.m_nalUnitType == NAL_UNIT_EOS) |
---|
494 | { |
---|
495 | #if FIX_OUTPUT_EOS |
---|
496 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
497 | #else |
---|
498 | xFlushOutput( pcListPic ); |
---|
499 | #endif |
---|
500 | } |
---|
501 | // write reconstruction to file -- for additional bumping as defined in C.5.2.3 |
---|
502 | #if FIX_WRITING_OUTPUT |
---|
503 | if(!bNewPicture && nalu.m_nalUnitType >= NAL_UNIT_CODED_SLICE_TRAIL_N && nalu.m_nalUnitType <= NAL_UNIT_RESERVED_VCL31) |
---|
504 | #else |
---|
505 | if(bNewPicture) |
---|
506 | #endif |
---|
507 | { |
---|
508 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
509 | } |
---|
510 | } |
---|
511 | } |
---|
512 | |
---|
513 | #if SYNTAX_OUTPUT |
---|
514 | if( streamSyntaxFile.is_open() ) |
---|
515 | { |
---|
516 | streamSyntaxFile.close(); |
---|
517 | } |
---|
518 | #endif |
---|
519 | |
---|
520 | xFlushOutput( pcListPic ); |
---|
521 | // delete buffers |
---|
522 | m_cTDecTop.deletePicBuffer(); |
---|
523 | |
---|
524 | // destroy internal classes |
---|
525 | xDestroyDecLib(); |
---|
526 | } |
---|
527 | #endif |
---|
528 | |
---|
529 | // ==================================================================================================================== |
---|
530 | // Protected member functions |
---|
531 | // ==================================================================================================================== |
---|
532 | |
---|
533 | Void TAppDecTop::xCreateDecLib() |
---|
534 | { |
---|
535 | #if SVC_EXTENSION |
---|
536 | // initialize global variables |
---|
537 | initROM(); |
---|
538 | |
---|
539 | for(UInt layer = 0; layer <= m_tgtLayerId; layer++) |
---|
540 | { |
---|
541 | // set layer ID |
---|
542 | m_acTDecTop[layer].setLayerId ( layer ); |
---|
543 | |
---|
544 | // create decoder class |
---|
545 | m_acTDecTop[layer].create(); |
---|
546 | |
---|
547 | m_acTDecTop[layer].setLayerDec(m_apcTDecTop); |
---|
548 | } |
---|
549 | #else |
---|
550 | // create decoder class |
---|
551 | m_cTDecTop.create(); |
---|
552 | #endif |
---|
553 | } |
---|
554 | |
---|
555 | Void TAppDecTop::xDestroyDecLib() |
---|
556 | { |
---|
557 | #if SVC_EXTENSION |
---|
558 | // destroy ROM |
---|
559 | destroyROM(); |
---|
560 | |
---|
561 | for(UInt layer = 0; layer <= m_tgtLayerId; layer++) |
---|
562 | { |
---|
563 | if ( m_pchReconFile[layer] ) |
---|
564 | { |
---|
565 | m_acTVideoIOYuvReconFile[layer].close(); |
---|
566 | } |
---|
567 | |
---|
568 | // destroy decoder class |
---|
569 | m_acTDecTop[layer].destroy(); |
---|
570 | } |
---|
571 | #else |
---|
572 | if ( m_pchReconFile ) |
---|
573 | { |
---|
574 | m_cTVideoIOYuvReconFile. close(); |
---|
575 | } |
---|
576 | |
---|
577 | // destroy decoder class |
---|
578 | m_cTDecTop.destroy(); |
---|
579 | #endif |
---|
580 | } |
---|
581 | |
---|
582 | Void TAppDecTop::xInitDecLib() |
---|
583 | { |
---|
584 | // initialize decoder class |
---|
585 | #if SVC_EXTENSION |
---|
586 | for(UInt layer = 0; layer <= m_tgtLayerId; layer++) |
---|
587 | { |
---|
588 | m_acTDecTop[layer].init(); |
---|
589 | m_acTDecTop[layer].setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
590 | m_acTDecTop[layer].setNumLayer( m_tgtLayerId + 1 ); |
---|
591 | #if OUTPUT_LAYER_SET_INDEX |
---|
592 | m_acTDecTop[layer].setCommonDecoderParams( this->getCommonDecoderParams() ); |
---|
593 | #endif |
---|
594 | } |
---|
595 | |
---|
596 | #else |
---|
597 | m_cTDecTop.init(); |
---|
598 | m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
599 | #endif |
---|
600 | } |
---|
601 | |
---|
602 | /** \param pcListPic list of pictures to be written to file |
---|
603 | \todo DYN_REF_FREE should be revised |
---|
604 | */ |
---|
605 | #if SVC_EXTENSION |
---|
606 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt layerId, UInt tId ) |
---|
607 | #else |
---|
608 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId ) |
---|
609 | #endif |
---|
610 | { |
---|
611 | if (pcListPic->empty()) |
---|
612 | { |
---|
613 | return; |
---|
614 | } |
---|
615 | |
---|
616 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
617 | Int numPicsNotYetDisplayed = 0; |
---|
618 | Int dpbFullness = 0; |
---|
619 | #if SVC_EXTENSION |
---|
620 | TComSPS* activeSPS = m_acTDecTop[layerId].getActiveSPS(); |
---|
621 | #else |
---|
622 | TComSPS* activeSPS = m_cTDecTop.getActiveSPS(); |
---|
623 | #endif |
---|
624 | UInt numReorderPicsHighestTid; |
---|
625 | UInt maxDecPicBufferingHighestTid; |
---|
626 | UInt maxNrSublayers = activeSPS->getMaxTLayers(); |
---|
627 | |
---|
628 | if(m_iMaxTemporalLayer == -1 || m_iMaxTemporalLayer >= maxNrSublayers) |
---|
629 | { |
---|
630 | numReorderPicsHighestTid = activeSPS->getNumReorderPics(maxNrSublayers-1); |
---|
631 | maxDecPicBufferingHighestTid = activeSPS->getMaxDecPicBuffering(maxNrSublayers-1); |
---|
632 | } |
---|
633 | else |
---|
634 | { |
---|
635 | numReorderPicsHighestTid = activeSPS->getNumReorderPics(m_iMaxTemporalLayer); |
---|
636 | maxDecPicBufferingHighestTid = activeSPS->getMaxDecPicBuffering(m_iMaxTemporalLayer); |
---|
637 | } |
---|
638 | |
---|
639 | while (iterPic != pcListPic->end()) |
---|
640 | { |
---|
641 | TComPic* pcPic = *(iterPic); |
---|
642 | #if SVC_EXTENSION |
---|
643 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_aiPOCLastDisplay[layerId]) |
---|
644 | #else |
---|
645 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay) |
---|
646 | #endif |
---|
647 | { |
---|
648 | numPicsNotYetDisplayed++; |
---|
649 | dpbFullness++; |
---|
650 | } |
---|
651 | else if(pcPic->getSlice( 0 )->isReferenced()) |
---|
652 | { |
---|
653 | dpbFullness++; |
---|
654 | } |
---|
655 | iterPic++; |
---|
656 | } |
---|
657 | iterPic = pcListPic->begin(); |
---|
658 | if (numPicsNotYetDisplayed>2) |
---|
659 | { |
---|
660 | iterPic++; |
---|
661 | } |
---|
662 | |
---|
663 | TComPic* pcPic = *(iterPic); |
---|
664 | if (numPicsNotYetDisplayed>2 && pcPic->isField()) //Field Decoding |
---|
665 | { |
---|
666 | TComList<TComPic*>::iterator endPic = pcListPic->end(); |
---|
667 | endPic--; |
---|
668 | iterPic = pcListPic->begin(); |
---|
669 | while (iterPic != endPic) |
---|
670 | { |
---|
671 | TComPic* pcPicTop = *(iterPic); |
---|
672 | iterPic++; |
---|
673 | TComPic* pcPicBottom = *(iterPic); |
---|
674 | |
---|
675 | #if SVC_EXTENSION |
---|
676 | if( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && |
---|
677 | (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) && |
---|
678 | (!(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) && |
---|
679 | (pcPicTop->getPOC() == m_aiPOCLastDisplay[layerId]+1 || m_aiPOCLastDisplay[layerId]<0) ) |
---|
680 | #else |
---|
681 | if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && |
---|
682 | (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) && |
---|
683 | (!(pcPicTop->getPOC()%2) && pcPicBottom->getPOC() == pcPicTop->getPOC()+1) && |
---|
684 | (pcPicTop->getPOC() == m_iPOCLastDisplay+1 || m_iPOCLastDisplay < 0)) |
---|
685 | #endif |
---|
686 | { |
---|
687 | // write to file |
---|
688 | numPicsNotYetDisplayed = numPicsNotYetDisplayed-2; |
---|
689 | #if SVC_EXTENSION |
---|
690 | if ( m_pchReconFile[layerId] ) |
---|
691 | { |
---|
692 | const Window &conf = pcPicTop->getConformanceWindow(); |
---|
693 | const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window(); |
---|
694 | const Bool isTff = pcPicTop->isTopField(); |
---|
695 | #if REPN_FORMAT_IN_VPS |
---|
696 | #if Q0200_CONFORMANCE_BL_SIZE |
---|
697 | Int xScal=1,yScal=1; |
---|
698 | #else |
---|
699 | UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc(); |
---|
700 | Int xScal = TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc ); |
---|
701 | #endif |
---|
702 | m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
703 | conf.getWindowLeftOffset() * xScal + defDisp.getWindowLeftOffset(), |
---|
704 | conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(), |
---|
705 | conf.getWindowTopOffset() * yScal + defDisp.getWindowTopOffset(), |
---|
706 | conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset(), isTff ); |
---|
707 | #else |
---|
708 | #if O0194_DIFFERENT_BITDEPTH_EL_BL |
---|
709 | // Compile time bug-fix |
---|
710 | m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
711 | #else |
---|
712 | m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
713 | #endif |
---|
714 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
715 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
716 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
717 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff ); |
---|
718 | #endif |
---|
719 | } |
---|
720 | |
---|
721 | // update POC of display order |
---|
722 | m_aiPOCLastDisplay[layerId] = pcPicBottom->getPOC(); |
---|
723 | #else |
---|
724 | if ( m_pchReconFile ) |
---|
725 | { |
---|
726 | const Window &conf = pcPicTop->getConformanceWindow(); |
---|
727 | const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window(); |
---|
728 | const Bool isTff = pcPicTop->isTopField(); |
---|
729 | m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
730 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
731 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
732 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
733 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff ); |
---|
734 | } |
---|
735 | |
---|
736 | // update POC of display order |
---|
737 | m_iPOCLastDisplay = pcPicBottom->getPOC(); |
---|
738 | #endif |
---|
739 | |
---|
740 | // erase non-referenced picture in the reference picture list after display |
---|
741 | if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true ) |
---|
742 | { |
---|
743 | #if !DYN_REF_FREE |
---|
744 | pcPicTop->setReconMark(false); |
---|
745 | |
---|
746 | // mark it should be extended later |
---|
747 | pcPicTop->getPicYuvRec()->setBorderExtension( false ); |
---|
748 | |
---|
749 | #else |
---|
750 | pcPicTop->destroy(); |
---|
751 | pcListPic->erase( iterPic ); |
---|
752 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
753 | continue; |
---|
754 | #endif |
---|
755 | } |
---|
756 | if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true ) |
---|
757 | { |
---|
758 | #if !DYN_REF_FREE |
---|
759 | pcPicBottom->setReconMark(false); |
---|
760 | |
---|
761 | // mark it should be extended later |
---|
762 | pcPicBottom->getPicYuvRec()->setBorderExtension( false ); |
---|
763 | |
---|
764 | #else |
---|
765 | pcPicBottom->destroy(); |
---|
766 | pcListPic->erase( iterPic ); |
---|
767 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
768 | continue; |
---|
769 | #endif |
---|
770 | } |
---|
771 | pcPicTop->setOutputMark(false); |
---|
772 | pcPicBottom->setOutputMark(false); |
---|
773 | } |
---|
774 | } |
---|
775 | } |
---|
776 | else if (!pcPic->isField()) //Frame Decoding |
---|
777 | { |
---|
778 | iterPic = pcListPic->begin(); |
---|
779 | while (iterPic != pcListPic->end()) |
---|
780 | { |
---|
781 | pcPic = *(iterPic); |
---|
782 | |
---|
783 | #if SVC_EXTENSION |
---|
784 | if( pcPic->getOutputMark() && pcPic->getPOC() > m_aiPOCLastDisplay[layerId] && |
---|
785 | (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid) ) |
---|
786 | #else |
---|
787 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay && |
---|
788 | (numPicsNotYetDisplayed > numReorderPicsHighestTid || dpbFullness > maxDecPicBufferingHighestTid)) |
---|
789 | #endif |
---|
790 | { |
---|
791 | // write to file |
---|
792 | numPicsNotYetDisplayed--; |
---|
793 | if(pcPic->getSlice(0)->isReferenced() == false) |
---|
794 | { |
---|
795 | dpbFullness--; |
---|
796 | } |
---|
797 | #if SVC_EXTENSION |
---|
798 | if( m_pchReconFile[layerId] ) |
---|
799 | { |
---|
800 | const Window &conf = pcPic->getConformanceWindow(); |
---|
801 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
802 | #if REPN_FORMAT_IN_VPS |
---|
803 | #if Q0200_CONFORMANCE_BL_SIZE |
---|
804 | Int xScal=1,yScal=1; |
---|
805 | #else |
---|
806 | UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc(); |
---|
807 | Int xScal = TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc ); |
---|
808 | #endif |
---|
809 | m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(), |
---|
810 | conf.getWindowLeftOffset() * xScal + defDisp.getWindowLeftOffset(), |
---|
811 | conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(), |
---|
812 | conf.getWindowTopOffset() * yScal + defDisp.getWindowTopOffset(), |
---|
813 | conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset() ); |
---|
814 | #else |
---|
815 | m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(), |
---|
816 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
817 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
818 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
819 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
820 | #endif |
---|
821 | } |
---|
822 | |
---|
823 | // update POC of display order |
---|
824 | m_aiPOCLastDisplay[layerId] = pcPic->getPOC(); |
---|
825 | #else |
---|
826 | if ( m_pchReconFile ) |
---|
827 | { |
---|
828 | #if SYNTAX_OUTPUT |
---|
829 | const Window &conf = pcPic->getConformanceWindow(); |
---|
830 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
831 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
832 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
833 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
834 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
835 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
836 | #endif |
---|
837 | } |
---|
838 | |
---|
839 | // update POC of display order |
---|
840 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
841 | #endif |
---|
842 | |
---|
843 | // erase non-referenced picture in the reference picture list after display |
---|
844 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
845 | { |
---|
846 | #if !DYN_REF_FREE |
---|
847 | pcPic->setReconMark(false); |
---|
848 | |
---|
849 | // mark it should be extended later |
---|
850 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
851 | |
---|
852 | #else |
---|
853 | pcPic->destroy(); |
---|
854 | pcListPic->erase( iterPic ); |
---|
855 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
856 | continue; |
---|
857 | #endif |
---|
858 | } |
---|
859 | pcPic->setOutputMark(false); |
---|
860 | } |
---|
861 | |
---|
862 | iterPic++; |
---|
863 | } |
---|
864 | } |
---|
865 | } |
---|
866 | |
---|
867 | /** \param pcListPic list of pictures to be written to file |
---|
868 | \todo DYN_REF_FREE should be revised |
---|
869 | */ |
---|
870 | #if SVC_EXTENSION |
---|
871 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, UInt layerId ) |
---|
872 | #else |
---|
873 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic ) |
---|
874 | #endif |
---|
875 | { |
---|
876 | if(!pcListPic || pcListPic->empty()) |
---|
877 | { |
---|
878 | return; |
---|
879 | } |
---|
880 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
881 | |
---|
882 | iterPic = pcListPic->begin(); |
---|
883 | TComPic* pcPic = *(iterPic); |
---|
884 | |
---|
885 | if (pcPic->isField()) //Field Decoding |
---|
886 | { |
---|
887 | TComList<TComPic*>::iterator endPic = pcListPic->end(); |
---|
888 | endPic--; |
---|
889 | TComPic *pcPicTop, *pcPicBottom = NULL; |
---|
890 | while (iterPic != endPic) |
---|
891 | { |
---|
892 | pcPicTop = *(iterPic); |
---|
893 | iterPic++; |
---|
894 | pcPicBottom = *(iterPic); |
---|
895 | |
---|
896 | if ( pcPicTop->getOutputMark() && pcPicBottom->getOutputMark() && !(pcPicTop->getPOC()%2) && (pcPicBottom->getPOC() == pcPicTop->getPOC()+1) ) |
---|
897 | { |
---|
898 | // write to file |
---|
899 | #if SVC_EXTENSION |
---|
900 | if ( m_pchReconFile[layerId] ) |
---|
901 | { |
---|
902 | const Window &conf = pcPicTop->getConformanceWindow(); |
---|
903 | const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window(); |
---|
904 | const Bool isTff = pcPicTop->isTopField(); |
---|
905 | #if REPN_FORMAT_IN_VPS |
---|
906 | #if Q0200_CONFORMANCE_BL_SIZE |
---|
907 | Int xScal=1,yScal=1; |
---|
908 | #else |
---|
909 | UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc(); |
---|
910 | Int xScal = TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc ); |
---|
911 | #endif |
---|
912 | m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
913 | conf.getWindowLeftOffset() *xScal + defDisp.getWindowLeftOffset(), |
---|
914 | conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(), |
---|
915 | conf.getWindowTopOffset() *yScal + defDisp.getWindowTopOffset(), |
---|
916 | conf.getWindowBottomOffset()*yScal + defDisp.getWindowBottomOffset(), isTff ); |
---|
917 | #else |
---|
918 | #if O0194_DIFFERENT_BITDEPTH_EL_BL |
---|
919 | // Compile time bug-fix |
---|
920 | m_acTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
921 | #else |
---|
922 | m_cTVideoIOYuvReconFile[layerId].write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
923 | #endif |
---|
924 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
925 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
926 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
927 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff ); |
---|
928 | #endif |
---|
929 | } |
---|
930 | |
---|
931 | // update POC of display order |
---|
932 | m_aiPOCLastDisplay[layerId] = pcPicBottom->getPOC(); |
---|
933 | #else |
---|
934 | if ( m_pchReconFile ) |
---|
935 | { |
---|
936 | const Window &conf = pcPicTop->getConformanceWindow(); |
---|
937 | const Window &defDisp = m_respectDefDispWindow ? pcPicTop->getDefDisplayWindow() : Window(); |
---|
938 | const Bool isTff = pcPicTop->isTopField(); |
---|
939 | m_cTVideoIOYuvReconFile.write( pcPicTop->getPicYuvRec(), pcPicBottom->getPicYuvRec(), |
---|
940 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
941 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
942 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
943 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset(), isTff ); |
---|
944 | } |
---|
945 | |
---|
946 | // update POC of display order |
---|
947 | m_iPOCLastDisplay = pcPicBottom->getPOC(); |
---|
948 | #endif |
---|
949 | |
---|
950 | // erase non-referenced picture in the reference picture list after display |
---|
951 | if ( !pcPicTop->getSlice(0)->isReferenced() && pcPicTop->getReconMark() == true ) |
---|
952 | { |
---|
953 | #if !DYN_REF_FREE |
---|
954 | pcPicTop->setReconMark(false); |
---|
955 | |
---|
956 | // mark it should be extended later |
---|
957 | pcPicTop->getPicYuvRec()->setBorderExtension( false ); |
---|
958 | |
---|
959 | #else |
---|
960 | pcPicTop->destroy(); |
---|
961 | pcListPic->erase( iterPic ); |
---|
962 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
963 | continue; |
---|
964 | #endif |
---|
965 | } |
---|
966 | if ( !pcPicBottom->getSlice(0)->isReferenced() && pcPicBottom->getReconMark() == true ) |
---|
967 | { |
---|
968 | #if !DYN_REF_FREE |
---|
969 | pcPicBottom->setReconMark(false); |
---|
970 | |
---|
971 | // mark it should be extended later |
---|
972 | pcPicBottom->getPicYuvRec()->setBorderExtension( false ); |
---|
973 | |
---|
974 | #else |
---|
975 | pcPicBottom->destroy(); |
---|
976 | pcListPic->erase( iterPic ); |
---|
977 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
978 | continue; |
---|
979 | #endif |
---|
980 | } |
---|
981 | pcPicTop->setOutputMark(false); |
---|
982 | pcPicBottom->setOutputMark(false); |
---|
983 | |
---|
984 | #if !DYN_REF_FREE |
---|
985 | if(pcPicTop) |
---|
986 | { |
---|
987 | pcPicTop->destroy(); |
---|
988 | delete pcPicTop; |
---|
989 | pcPicTop = NULL; |
---|
990 | } |
---|
991 | #endif |
---|
992 | } |
---|
993 | } |
---|
994 | if(pcPicBottom) |
---|
995 | { |
---|
996 | pcPicBottom->destroy(); |
---|
997 | delete pcPicBottom; |
---|
998 | pcPicBottom = NULL; |
---|
999 | } |
---|
1000 | } |
---|
1001 | else //Frame decoding |
---|
1002 | { |
---|
1003 | while (iterPic != pcListPic->end()) |
---|
1004 | { |
---|
1005 | pcPic = *(iterPic); |
---|
1006 | |
---|
1007 | if ( pcPic->getOutputMark() ) |
---|
1008 | { |
---|
1009 | // write to file |
---|
1010 | #if SVC_EXTENSION |
---|
1011 | if ( m_pchReconFile[layerId] ) |
---|
1012 | { |
---|
1013 | const Window &conf = pcPic->getConformanceWindow(); |
---|
1014 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
1015 | #if REPN_FORMAT_IN_VPS |
---|
1016 | #if Q0200_CONFORMANCE_BL_SIZE |
---|
1017 | Int xScal=1,yScal=1; |
---|
1018 | #else |
---|
1019 | UInt chromaFormatIdc = pcPic->getSlice(0)->getChromaFormatIdc(); |
---|
1020 | Int xScal = TComSPS::getWinUnitX( chromaFormatIdc ), yScal = TComSPS::getWinUnitY( chromaFormatIdc ); |
---|
1021 | #endif |
---|
1022 | m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(), |
---|
1023 | conf.getWindowLeftOffset() *xScal + defDisp.getWindowLeftOffset(), |
---|
1024 | conf.getWindowRightOffset() *xScal + defDisp.getWindowRightOffset(), |
---|
1025 | conf.getWindowTopOffset() *yScal + defDisp.getWindowTopOffset(), |
---|
1026 | conf.getWindowBottomOffset()*yScal + defDisp.getWindowBottomOffset() ); |
---|
1027 | #else |
---|
1028 | m_acTVideoIOYuvReconFile[layerId].write( pcPic->getPicYuvRec(), |
---|
1029 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
1030 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
1031 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
1032 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
1033 | #endif |
---|
1034 | } |
---|
1035 | |
---|
1036 | // update POC of display order |
---|
1037 | m_aiPOCLastDisplay[layerId] = pcPic->getPOC(); |
---|
1038 | #else |
---|
1039 | if ( m_pchReconFile ) |
---|
1040 | { |
---|
1041 | const Window &conf = pcPic->getConformanceWindow(); |
---|
1042 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
1043 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
1044 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
1045 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
1046 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
1047 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
1048 | } |
---|
1049 | |
---|
1050 | // update POC of display order |
---|
1051 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
1052 | #endif |
---|
1053 | |
---|
1054 | // erase non-referenced picture in the reference picture list after display |
---|
1055 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
1056 | { |
---|
1057 | #if !DYN_REF_FREE |
---|
1058 | pcPic->setReconMark(false); |
---|
1059 | |
---|
1060 | // mark it should be extended later |
---|
1061 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
1062 | |
---|
1063 | #else |
---|
1064 | pcPic->destroy(); |
---|
1065 | pcListPic->erase( iterPic ); |
---|
1066 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
1067 | continue; |
---|
1068 | #endif |
---|
1069 | } |
---|
1070 | pcPic->setOutputMark(false); |
---|
1071 | } |
---|
1072 | #if !SVC_EXTENSION |
---|
1073 | #if !DYN_REF_FREE |
---|
1074 | if(pcPic) |
---|
1075 | { |
---|
1076 | pcPic->destroy(); |
---|
1077 | delete pcPic; |
---|
1078 | pcPic = NULL; |
---|
1079 | } |
---|
1080 | #endif |
---|
1081 | #endif |
---|
1082 | iterPic++; |
---|
1083 | } |
---|
1084 | } |
---|
1085 | #if SVC_EXTENSION |
---|
1086 | m_aiPOCLastDisplay[layerId] = -MAX_INT; |
---|
1087 | #else |
---|
1088 | pcListPic->clear(); |
---|
1089 | m_iPOCLastDisplay = -MAX_INT; |
---|
1090 | #endif |
---|
1091 | } |
---|
1092 | |
---|
1093 | /** \param nalu Input nalu to check whether its LayerId is within targetDecLayerIdSet |
---|
1094 | */ |
---|
1095 | Bool TAppDecTop::isNaluWithinTargetDecLayerIdSet( InputNALUnit* nalu ) |
---|
1096 | { |
---|
1097 | if ( m_targetDecLayerIdSet.size() == 0 ) // By default, the set is empty, meaning all LayerIds are allowed |
---|
1098 | { |
---|
1099 | return true; |
---|
1100 | } |
---|
1101 | for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++) |
---|
1102 | { |
---|
1103 | if ( nalu->m_reservedZero6Bits == (*it) ) |
---|
1104 | { |
---|
1105 | return true; |
---|
1106 | } |
---|
1107 | } |
---|
1108 | return false; |
---|
1109 | } |
---|
1110 | #if ALIGNED_BUMPING |
---|
1111 | // Function outputs a picture, and marks it as not needed for output. |
---|
1112 | Void TAppDecTop::xOutputAndMarkPic( TComPic *pic, const Char *reconFile, const Int layerIdx, Int &pocLastDisplay, DpbStatus &dpbStatus ) |
---|
1113 | { |
---|
1114 | if ( reconFile ) |
---|
1115 | { |
---|
1116 | const Window &conf = pic->getConformanceWindow(); |
---|
1117 | const Window &defDisp = m_respectDefDispWindow ? pic->getDefDisplayWindow() : Window(); |
---|
1118 | Int xScal = 1, yScal = 1; |
---|
1119 | #if REPN_FORMAT_IN_VPS && !Q0200_CONFORMANCE_BL_SIZE |
---|
1120 | UInt chromaFormatIdc = pic->getSlice(0)->getChromaFormatIdc(); |
---|
1121 | xScal = TComSPS::getWinUnitX( chromaFormatIdc ); |
---|
1122 | yScal = TComSPS::getWinUnitY( chromaFormatIdc ); |
---|
1123 | #endif |
---|
1124 | m_acTVideoIOYuvReconFile[layerIdx].write( pic->getPicYuvRec(), |
---|
1125 | conf.getWindowLeftOffset() * xScal + defDisp.getWindowLeftOffset(), |
---|
1126 | conf.getWindowRightOffset() * xScal + defDisp.getWindowRightOffset(), |
---|
1127 | conf.getWindowTopOffset() * yScal + defDisp.getWindowTopOffset(), |
---|
1128 | conf.getWindowBottomOffset()* yScal + defDisp.getWindowBottomOffset() ); |
---|
1129 | } |
---|
1130 | // update POC of display order |
---|
1131 | pocLastDisplay = pic->getPOC(); |
---|
1132 | |
---|
1133 | // Mark as not needed for output |
---|
1134 | pic->setOutputMark(false); |
---|
1135 | |
---|
1136 | // "erase" non-referenced picture in the reference picture list after display |
---|
1137 | if ( !pic->getSlice(0)->isReferenced() && pic->getReconMark() == true ) |
---|
1138 | { |
---|
1139 | pic->setReconMark(false); |
---|
1140 | |
---|
1141 | // mark it should be extended later |
---|
1142 | pic->getPicYuvRec()->setBorderExtension( false ); |
---|
1143 | |
---|
1144 | dpbStatus.m_numPicsInLayer[layerIdx]--; |
---|
1145 | } |
---|
1146 | } |
---|
1147 | |
---|
1148 | Void TAppDecTop::flushAllPictures(Int layerId, Bool outputPictures) |
---|
1149 | { |
---|
1150 | // First "empty" all pictures that are not used for reference and not needed for output |
---|
1151 | emptyUnusedPicturesNotNeededForOutput(); |
---|
1152 | |
---|
1153 | if( outputPictures ) // All pictures in the DPB in that layer are to be output; this means other pictures would also be output |
---|
1154 | { |
---|
1155 | std::vector<Int> listOfPocs; |
---|
1156 | std::vector<Int> listOfPocsInEachLayer[MAX_LAYERS]; |
---|
1157 | std::vector<Int> listOfPocsPositionInEachLayer[MAX_LAYERS]; |
---|
1158 | DpbStatus dpbStatus; |
---|
1159 | |
---|
1160 | // Find the status of the DPB |
---|
1161 | xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus); |
---|
1162 | |
---|
1163 | if( listOfPocs.size() ) |
---|
1164 | { |
---|
1165 | while( listOfPocsInEachLayer[layerId].size() ) // As long as there picture in the layer to be output |
---|
1166 | { |
---|
1167 | bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus ); |
---|
1168 | } |
---|
1169 | } |
---|
1170 | } |
---|
1171 | |
---|
1172 | // Now remove all pictures from the layer DPB? |
---|
1173 | markAllPicturesAsErased(layerId); |
---|
1174 | } |
---|
1175 | Void TAppDecTop::flushAllPictures(Bool outputPictures) |
---|
1176 | { |
---|
1177 | // First "empty" all pictures that are not used for reference and not needed for output |
---|
1178 | emptyUnusedPicturesNotNeededForOutput(); |
---|
1179 | |
---|
1180 | if( outputPictures ) // All pictures in the DPB are to be output |
---|
1181 | { |
---|
1182 | std::vector<Int> listOfPocs; |
---|
1183 | std::vector<Int> listOfPocsInEachLayer[MAX_LAYERS]; |
---|
1184 | std::vector<Int> listOfPocsPositionInEachLayer[MAX_LAYERS]; |
---|
1185 | DpbStatus dpbStatus; |
---|
1186 | |
---|
1187 | // Find the status of the DPB |
---|
1188 | xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus); |
---|
1189 | |
---|
1190 | while( dpbStatus.m_numAUsNotDisplayed ) |
---|
1191 | { |
---|
1192 | bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus ); |
---|
1193 | } |
---|
1194 | } |
---|
1195 | |
---|
1196 | // Now remove all pictures from the DPB? |
---|
1197 | markAllPicturesAsErased(); |
---|
1198 | } |
---|
1199 | |
---|
1200 | Void TAppDecTop::markAllPicturesAsErased() |
---|
1201 | { |
---|
1202 | for(Int i = 0; i < MAX_LAYERS; i++) |
---|
1203 | { |
---|
1204 | m_acTDecTop[i].getListPic()->clear(); |
---|
1205 | } |
---|
1206 | } |
---|
1207 | |
---|
1208 | Void TAppDecTop::markAllPicturesAsErased(Int layerIdx) |
---|
1209 | { |
---|
1210 | m_acTDecTop[layerIdx].getListPic()->clear(); |
---|
1211 | } |
---|
1212 | |
---|
1213 | Void TAppDecTop::checkOutputBeforeDecoding(Int layerIdx) |
---|
1214 | { |
---|
1215 | |
---|
1216 | std::vector<Int> listOfPocs; |
---|
1217 | std::vector<Int> listOfPocsInEachLayer[MAX_LAYERS]; |
---|
1218 | std::vector<Int> listOfPocsPositionInEachLayer[MAX_LAYERS]; |
---|
1219 | DpbStatus dpbStatus; |
---|
1220 | |
---|
1221 | // First "empty" all pictures that are not used for reference and not needed for output |
---|
1222 | emptyUnusedPicturesNotNeededForOutput(); |
---|
1223 | |
---|
1224 | // Find the status of the DPB |
---|
1225 | xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus); |
---|
1226 | |
---|
1227 | // If not picture to be output, return |
---|
1228 | if( listOfPocs.size() == 0 ) |
---|
1229 | { |
---|
1230 | return; |
---|
1231 | } |
---|
1232 | |
---|
1233 | // Find DPB-information from the VPS |
---|
1234 | DpbStatus maxDpbLimit; |
---|
1235 | Int targetLsIdx, subDpbIdx; |
---|
1236 | TComVPS *vps = findDpbParametersFromVps(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, maxDpbLimit); |
---|
1237 | if( getCommonDecoderParams()->getTargetOutputLayerSetIdx() == 0 ) |
---|
1238 | { |
---|
1239 | targetLsIdx = 0; |
---|
1240 | subDpbIdx = 0; |
---|
1241 | } |
---|
1242 | else |
---|
1243 | { |
---|
1244 | targetLsIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() ); |
---|
1245 | subDpbIdx = vps->getSubDpbAssigned( targetLsIdx, layerIdx ); |
---|
1246 | } |
---|
1247 | // Assume that listOfPocs is sorted in increasing order - if not have to sort it. |
---|
1248 | while( ifInvokeBumpingBeforeDecoding(dpbStatus, maxDpbLimit, layerIdx, subDpbIdx) ) |
---|
1249 | { |
---|
1250 | bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus ); |
---|
1251 | } |
---|
1252 | } |
---|
1253 | |
---|
1254 | Void TAppDecTop::checkOutputAfterDecoding() |
---|
1255 | { |
---|
1256 | std::vector<Int> listOfPocs; |
---|
1257 | std::vector<Int> listOfPocsInEachLayer[MAX_LAYERS]; |
---|
1258 | std::vector<Int> listOfPocsPositionInEachLayer[MAX_LAYERS]; |
---|
1259 | DpbStatus dpbStatus; |
---|
1260 | |
---|
1261 | // First "empty" all pictures that are not used for reference and not needed for output |
---|
1262 | emptyUnusedPicturesNotNeededForOutput(); |
---|
1263 | |
---|
1264 | // Find the status of the DPB |
---|
1265 | xFindDPBStatus(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus); |
---|
1266 | |
---|
1267 | // If not picture to be output, return |
---|
1268 | if( listOfPocs.size() == 0 ) |
---|
1269 | { |
---|
1270 | return; |
---|
1271 | } |
---|
1272 | |
---|
1273 | // Find DPB-information from the VPS |
---|
1274 | DpbStatus maxDpbLimit; |
---|
1275 | findDpbParametersFromVps(listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, maxDpbLimit); |
---|
1276 | |
---|
1277 | // Assume that listOfPocs is sorted in increasing order - if not have to sort it. |
---|
1278 | while( ifInvokeBumpingAfterDecoding(dpbStatus, maxDpbLimit) ) |
---|
1279 | { |
---|
1280 | bumpingProcess( listOfPocs, listOfPocsInEachLayer, listOfPocsPositionInEachLayer, dpbStatus ); |
---|
1281 | } |
---|
1282 | } |
---|
1283 | |
---|
1284 | Void TAppDecTop::bumpingProcess(std::vector<Int> &listOfPocs, std::vector<Int> *listOfPocsInEachLayer, std::vector<Int> *listOfPocsPositionInEachLayer, DpbStatus &dpbStatus) |
---|
1285 | { |
---|
1286 | // Choose the smallest POC value |
---|
1287 | Int pocValue = *(listOfPocs.begin()); |
---|
1288 | std::vector<int>::iterator it; |
---|
1289 | TComList<TComPic*>::iterator iterPic; |
---|
1290 | for( Int layerIdx = 0; layerIdx < dpbStatus.m_numLayers; layerIdx++) |
---|
1291 | { |
---|
1292 | // Check if picture with pocValue is present. |
---|
1293 | it = find( listOfPocsInEachLayer[layerIdx].begin(), listOfPocsInEachLayer[layerIdx].end(), pocValue ); |
---|
1294 | if( it != listOfPocsInEachLayer[layerIdx].end() ) // picture found. |
---|
1295 | { |
---|
1296 | Int picPosition = std::distance( listOfPocsInEachLayer[layerIdx].begin(), it ); |
---|
1297 | Int j; |
---|
1298 | for(j = 0, iterPic = m_acTDecTop[layerIdx].getListPic()->begin(); j < listOfPocsPositionInEachLayer[layerIdx][picPosition]; j++) // Picture to be output |
---|
1299 | { |
---|
1300 | iterPic++; |
---|
1301 | } |
---|
1302 | TComPic *pic = *iterPic; |
---|
1303 | |
---|
1304 | xOutputAndMarkPic( pic, m_pchReconFile[layerIdx], layerIdx, m_aiPOCLastDisplay[layerIdx], dpbStatus ); |
---|
1305 | |
---|
1306 | listOfPocsInEachLayer[layerIdx].erase( it ); |
---|
1307 | listOfPocsPositionInEachLayer[layerIdx].erase( listOfPocsPositionInEachLayer[layerIdx].begin() + picPosition ); |
---|
1308 | } |
---|
1309 | } |
---|
1310 | // Update sub-DPB status |
---|
1311 | for( Int subDpbIdx = 0; subDpbIdx < dpbStatus.m_numSubDpbs; subDpbIdx++) |
---|
1312 | { |
---|
1313 | dpbStatus.m_numPicsInSubDpb[subDpbIdx]--; |
---|
1314 | } |
---|
1315 | dpbStatus.m_numAUsNotDisplayed--; |
---|
1316 | |
---|
1317 | // Remove the picture from the listOfPocs |
---|
1318 | listOfPocs.erase( listOfPocs.begin() ); |
---|
1319 | } |
---|
1320 | |
---|
1321 | TComVPS *TAppDecTop::findDpbParametersFromVps(std::vector<Int> const &listOfPocs, std::vector<Int> const *listOfPocsInEachLayer, std::vector<Int> const *listOfPocsPositionInEachLayer, DpbStatus &maxDpbLimit) |
---|
1322 | { |
---|
1323 | Int targetOutputLsIdx = getCommonDecoderParams()->getTargetOutputLayerSetIdx(); |
---|
1324 | TComVPS *vps = NULL; |
---|
1325 | |
---|
1326 | if( targetOutputLsIdx == 0 ) // Only base layer is output |
---|
1327 | { |
---|
1328 | TComSPS *sps = NULL; |
---|
1329 | assert( listOfPocsInEachLayer[0].size() != 0 ); |
---|
1330 | TComList<TComPic*>::iterator iterPic; |
---|
1331 | Int j; |
---|
1332 | for(j = 0, iterPic = m_acTDecTop[0].getListPic()->begin(); j < listOfPocsPositionInEachLayer[0][0]; j++) // Picture to be output |
---|
1333 | { |
---|
1334 | iterPic++; |
---|
1335 | } |
---|
1336 | TComPic *pic = *iterPic; |
---|
1337 | sps = pic->getSlice(0)->getSPS(); assert( sps->getLayerId() == 0 ); |
---|
1338 | vps = pic->getSlice(0)->getVPS(); |
---|
1339 | Int highestTId = sps->getMaxTLayers() - 1; |
---|
1340 | |
---|
1341 | maxDpbLimit.m_numAUsNotDisplayed = sps->getNumReorderPics( highestTId ); // m_numAUsNotDisplayed is only variable name - stores reorderpics |
---|
1342 | maxDpbLimit.m_maxLatencyIncrease = sps->getMaxLatencyIncrease( highestTId ) > 0; |
---|
1343 | if( maxDpbLimit.m_maxLatencyIncrease ) |
---|
1344 | { |
---|
1345 | maxDpbLimit.m_maxLatencyPictures = sps->getMaxLatencyIncrease( highestTId ) + sps->getNumReorderPics( highestTId ) - 1; |
---|
1346 | } |
---|
1347 | maxDpbLimit.m_numPicsInLayer[0] = sps->getMaxDecPicBuffering( highestTId ); |
---|
1348 | maxDpbLimit.m_numPicsInSubDpb[0] = sps->getMaxDecPicBuffering( highestTId ); |
---|
1349 | } |
---|
1350 | else |
---|
1351 | { |
---|
1352 | // ------------------------------------- |
---|
1353 | // Find the VPS used for the pictures |
---|
1354 | // ------------------------------------- |
---|
1355 | for(Int i = 0; i < MAX_LAYERS; i++) |
---|
1356 | { |
---|
1357 | if( m_acTDecTop[i].getListPic()->empty() ) |
---|
1358 | { |
---|
1359 | assert( listOfPocsInEachLayer[i].size() == 0 ); |
---|
1360 | continue; |
---|
1361 | } |
---|
1362 | std::vector<Int>::const_iterator it; |
---|
1363 | it = find( listOfPocsInEachLayer[i].begin(), listOfPocsInEachLayer[i].end(), listOfPocs[0] ); |
---|
1364 | TComList<TComPic*>::iterator iterPic; |
---|
1365 | if( it != listOfPocsInEachLayer[i].end() ) |
---|
1366 | { |
---|
1367 | Int picPosition = std::distance( listOfPocsInEachLayer[i].begin(), it ); |
---|
1368 | Int j; |
---|
1369 | for(j = 0, iterPic = m_acTDecTop[i].getListPic()->begin(); j < listOfPocsPositionInEachLayer[i][picPosition]; j++) // Picture to be output |
---|
1370 | { |
---|
1371 | iterPic++; |
---|
1372 | } |
---|
1373 | TComPic *pic = *iterPic; |
---|
1374 | vps = pic->getSlice(0)->getVPS(); |
---|
1375 | break; |
---|
1376 | } |
---|
1377 | } |
---|
1378 | |
---|
1379 | Int targetLsIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() ); |
---|
1380 | Int highestTId = vps->getMaxTLayers() - 1; |
---|
1381 | |
---|
1382 | maxDpbLimit.m_numAUsNotDisplayed = vps->getMaxVpsNumReorderPics( targetOutputLsIdx, highestTId ); // m_numAUsNotDisplayed is only variable name - stores reorderpics |
---|
1383 | maxDpbLimit.m_maxLatencyIncrease = vps->getMaxVpsLatencyIncreasePlus1(targetOutputLsIdx, highestTId ) > 0; |
---|
1384 | if( maxDpbLimit.m_maxLatencyIncrease ) |
---|
1385 | { |
---|
1386 | maxDpbLimit.m_maxLatencyPictures = vps->getMaxVpsNumReorderPics( targetOutputLsIdx, highestTId ) + vps->getMaxVpsLatencyIncreasePlus1(targetOutputLsIdx, highestTId ) - 1; |
---|
1387 | } |
---|
1388 | for(Int i = 0; i < vps->getNumLayersInIdList( targetLsIdx ); i++) |
---|
1389 | { |
---|
1390 | maxDpbLimit.m_numPicsInLayer[i] = vps->getMaxVpsLayerDecPicBuffMinus1( targetOutputLsIdx, i, highestTId ) + 1; |
---|
1391 | maxDpbLimit.m_numPicsInSubDpb[vps->getSubDpbAssigned( targetLsIdx, i )] = vps->getMaxVpsDecPicBufferingMinus1( targetOutputLsIdx, vps->getSubDpbAssigned( targetLsIdx, i ), highestTId) + 1; |
---|
1392 | } |
---|
1393 | // ------------------------------------- |
---|
1394 | } |
---|
1395 | return vps; |
---|
1396 | } |
---|
1397 | Void TAppDecTop::emptyUnusedPicturesNotNeededForOutput() |
---|
1398 | { |
---|
1399 | for(Int layerIdx = 0; layerIdx < MAX_LAYERS; layerIdx++) |
---|
1400 | { |
---|
1401 | TComList <TComPic*> *pcListPic = m_acTDecTop[layerIdx].getListPic(); |
---|
1402 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
1403 | while ( iterPic != pcListPic->end() ) |
---|
1404 | { |
---|
1405 | TComPic *pic = *iterPic; |
---|
1406 | if( !pic->getSlice(0)->isReferenced() && !pic->getOutputMark() ) |
---|
1407 | { |
---|
1408 | // Emtpy the picture buffer |
---|
1409 | pic->setReconMark( false ); |
---|
1410 | } |
---|
1411 | iterPic++; |
---|
1412 | } |
---|
1413 | } |
---|
1414 | } |
---|
1415 | |
---|
1416 | Bool TAppDecTop::ifInvokeBumpingBeforeDecoding( const DpbStatus &dpbStatus, const DpbStatus &dpbLimit, const Int layerIdx, const Int subDpbIdx ) |
---|
1417 | { |
---|
1418 | Bool retVal = false; |
---|
1419 | // Number of reorder picutres |
---|
1420 | retVal |= ( dpbStatus.m_numAUsNotDisplayed > dpbLimit.m_numAUsNotDisplayed ); |
---|
1421 | |
---|
1422 | // Number of pictures in each sub-DPB |
---|
1423 | retVal |= ( dpbStatus.m_numPicsInSubDpb[subDpbIdx] >= dpbLimit.m_numPicsInSubDpb[subDpbIdx] ); |
---|
1424 | |
---|
1425 | // Number of pictures in each layer |
---|
1426 | retVal |= ( dpbStatus.m_numPicsInLayer[layerIdx] >= dpbLimit.m_numPicsInLayer[layerIdx]); |
---|
1427 | |
---|
1428 | return retVal; |
---|
1429 | } |
---|
1430 | |
---|
1431 | Bool TAppDecTop::ifInvokeBumpingAfterDecoding( const DpbStatus &dpbStatus, const DpbStatus &dpbLimit ) |
---|
1432 | { |
---|
1433 | Bool retVal = false; |
---|
1434 | |
---|
1435 | // Number of reorder picutres |
---|
1436 | retVal |= ( dpbStatus.m_numAUsNotDisplayed > dpbLimit.m_numAUsNotDisplayed ); |
---|
1437 | |
---|
1438 | return retVal; |
---|
1439 | } |
---|
1440 | |
---|
1441 | Void TAppDecTop::xFindDPBStatus( std::vector<Int> &listOfPocs |
---|
1442 | , std::vector<Int> *listOfPocsInEachLayer |
---|
1443 | , std::vector<Int> *listOfPocsPositionInEachLayer |
---|
1444 | , DpbStatus &dpbStatus |
---|
1445 | ) |
---|
1446 | { |
---|
1447 | TComVPS *vps = NULL; |
---|
1448 | dpbStatus.init(); |
---|
1449 | for( Int i = 0; i < MAX_LAYERS; i++ ) |
---|
1450 | { |
---|
1451 | if( m_acTDecTop[i].getListPic()->empty() ) |
---|
1452 | { |
---|
1453 | continue; |
---|
1454 | } |
---|
1455 | |
---|
1456 | // To check # AUs that have at least one picture not output, |
---|
1457 | // For each layer, populate listOfPOcs if not already present |
---|
1458 | TComList<TComPic*>::iterator iterPic = m_acTDecTop[i].getListPic()->begin(); |
---|
1459 | Int picPositionInList = 0; |
---|
1460 | while (iterPic != m_acTDecTop[i].getListPic()->end()) |
---|
1461 | { |
---|
1462 | TComPic* pic = *(iterPic); |
---|
1463 | if( pic->getReconMark() ) |
---|
1464 | { |
---|
1465 | if( vps == NULL ) |
---|
1466 | { |
---|
1467 | vps = pic->getSlice(0)->getVPS(); |
---|
1468 | } |
---|
1469 | |
---|
1470 | std::vector<Int>::iterator it; |
---|
1471 | if( pic->getOutputMark() ) // && pic->getPOC() > m_aiPOCLastDisplay[i]) |
---|
1472 | { |
---|
1473 | it = find( listOfPocs.begin(), listOfPocs.end(), pic->getPOC() ); // Check if already included |
---|
1474 | if( it == listOfPocs.end() ) // New POC value - i.e. new AU - add to the list |
---|
1475 | { |
---|
1476 | listOfPocs.push_back( pic->getPOC() ); |
---|
1477 | } |
---|
1478 | listOfPocsInEachLayer [i].push_back( pic->getPOC() ); // POC to be output in each layer |
---|
1479 | listOfPocsPositionInEachLayer [i].push_back( picPositionInList ); // For ease of access |
---|
1480 | } |
---|
1481 | if( pic->getSlice(0)->isReferenced() || pic->getOutputMark() ) |
---|
1482 | { |
---|
1483 | dpbStatus.m_numPicsInLayer[i]++; // Count pictures that are "used for reference" or "needed for output" |
---|
1484 | } |
---|
1485 | } |
---|
1486 | iterPic++; |
---|
1487 | picPositionInList++; |
---|
1488 | } |
---|
1489 | } |
---|
1490 | |
---|
1491 | assert( vps != NULL ); // No picture in any DPB? |
---|
1492 | std::sort( listOfPocs.begin(), listOfPocs.end() ); // Sort in increasing order of POC |
---|
1493 | Int targetLsIdx = vps->getOutputLayerSetIdx( getCommonDecoderParams()->getTargetOutputLayerSetIdx() ); |
---|
1494 | // Update status |
---|
1495 | dpbStatus.m_numAUsNotDisplayed = listOfPocs.size(); // Number of AUs not displayed |
---|
1496 | dpbStatus.m_numLayers = vps->getNumLayersInIdList( targetLsIdx ); |
---|
1497 | dpbStatus.m_numSubDpbs = vps->getNumSubDpbs( vps->getOutputLayerSetIdx( |
---|
1498 | this->getCommonDecoderParams()->getTargetOutputLayerSetIdx() ) ); |
---|
1499 | |
---|
1500 | for(Int i = 0; i < dpbStatus.m_numLayers; i++) |
---|
1501 | { |
---|
1502 | dpbStatus.m_numPicsNotDisplayedInLayer[i] = listOfPocsInEachLayer[i].size(); |
---|
1503 | dpbStatus.m_numPicsInSubDpb[vps->getSubDpbAssigned(targetLsIdx,i)] += dpbStatus.m_numPicsInLayer[i]; |
---|
1504 | } |
---|
1505 | assert( dpbStatus.m_numAUsNotDisplayed != -1 ); |
---|
1506 | |
---|
1507 | |
---|
1508 | } |
---|
1509 | #endif |
---|
1510 | //! \} |
---|