1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2013, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file 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 | ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag)); |
---|
63 | #if H_MV |
---|
64 | for (Int i = 0; i < MAX_NUM_LAYER_IDS; i++) m_layerIdToDecIdx[i] = -1; |
---|
65 | #endif |
---|
66 | #if H_3D |
---|
67 | m_pScaleOffsetFile = 0; |
---|
68 | #endif |
---|
69 | } |
---|
70 | |
---|
71 | Void TAppDecTop::create() |
---|
72 | { |
---|
73 | } |
---|
74 | |
---|
75 | Void TAppDecTop::destroy() |
---|
76 | { |
---|
77 | if (m_pchBitstreamFile) |
---|
78 | { |
---|
79 | free (m_pchBitstreamFile); |
---|
80 | m_pchBitstreamFile = NULL; |
---|
81 | } |
---|
82 | #if H_MV |
---|
83 | for (Int decIdx = 0; decIdx < m_numDecoders; decIdx++) |
---|
84 | { |
---|
85 | if (m_pchReconFiles[decIdx]) |
---|
86 | { |
---|
87 | free (m_pchReconFiles[decIdx]); |
---|
88 | m_pchReconFiles[decIdx] = NULL; |
---|
89 | } |
---|
90 | } |
---|
91 | #endif |
---|
92 | if (m_pchReconFile) |
---|
93 | { |
---|
94 | free (m_pchReconFile); |
---|
95 | m_pchReconFile = NULL; |
---|
96 | } |
---|
97 | #if H_3D_FIX |
---|
98 | if (m_pchScaleOffsetFile) |
---|
99 | { |
---|
100 | free (m_pchScaleOffsetFile); |
---|
101 | m_pchScaleOffsetFile = NULL; |
---|
102 | } |
---|
103 | #endif |
---|
104 | } |
---|
105 | |
---|
106 | // ==================================================================================================================== |
---|
107 | // Public member functions |
---|
108 | // ==================================================================================================================== |
---|
109 | |
---|
110 | /** |
---|
111 | - create internal class |
---|
112 | - initialize internal class |
---|
113 | - until the end of the bitstream, call decoding function in TDecTop class |
---|
114 | - delete allocated buffers |
---|
115 | - destroy internal class |
---|
116 | . |
---|
117 | */ |
---|
118 | Void TAppDecTop::decode() |
---|
119 | { |
---|
120 | Int poc; |
---|
121 | #if H_MV |
---|
122 | poc = -1; |
---|
123 | #endif |
---|
124 | TComList<TComPic*>* pcListPic = NULL; |
---|
125 | |
---|
126 | ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary); |
---|
127 | if (!bitstreamFile) |
---|
128 | { |
---|
129 | fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchBitstreamFile); |
---|
130 | exit(EXIT_FAILURE); |
---|
131 | } |
---|
132 | |
---|
133 | #if H_3D |
---|
134 | if( m_pchScaleOffsetFile ) |
---|
135 | { |
---|
136 | m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" ); |
---|
137 | AOF( m_pScaleOffsetFile ); |
---|
138 | } |
---|
139 | m_cCamParsCollector.init( m_pScaleOffsetFile ); |
---|
140 | #endif |
---|
141 | InputByteStream bytestream(bitstreamFile); |
---|
142 | |
---|
143 | // create & initialize internal classes |
---|
144 | xCreateDecLib(); |
---|
145 | xInitDecLib (); |
---|
146 | #if !H_MV |
---|
147 | m_iPOCLastDisplay += m_iSkipFrame; // set the last displayed POC correctly for skip forward. |
---|
148 | |
---|
149 | // main decoder loop |
---|
150 | Bool recon_opened = false; // reconstruction file not yet opened. (must be performed after SPS is seen) |
---|
151 | #else |
---|
152 | #if H_3D |
---|
153 | Int pocCurrPic = -MAX_INT; |
---|
154 | Int pocLastPic = -MAX_INT; |
---|
155 | #endif |
---|
156 | |
---|
157 | Int layerIdCurrPic = 0; |
---|
158 | |
---|
159 | Int decIdxLastPic = 0; |
---|
160 | Int decIdxCurrPic = 0; |
---|
161 | |
---|
162 | Bool firstSlice = true; |
---|
163 | #endif |
---|
164 | |
---|
165 | while (!!bitstreamFile) |
---|
166 | { |
---|
167 | /* location serves to work around a design fault in the decoder, whereby |
---|
168 | * the process of reading a new slice that is the first slice of a new frame |
---|
169 | * requires the TDecTop::decode() method to be called again with the same |
---|
170 | * nal unit. */ |
---|
171 | streampos location = bitstreamFile.tellg(); |
---|
172 | #if H_MV |
---|
173 | #if ENC_DEC_TRACE |
---|
174 | Int64 symCount = g_nSymbolCounter; |
---|
175 | #endif |
---|
176 | #endif |
---|
177 | AnnexBStats stats = AnnexBStats(); |
---|
178 | #if !H_MV |
---|
179 | Bool bPreviousPictureDecoded = false; |
---|
180 | #endif |
---|
181 | |
---|
182 | vector<uint8_t> nalUnit; |
---|
183 | InputNALUnit nalu; |
---|
184 | byteStreamNALUnit(bytestream, nalUnit, stats); |
---|
185 | |
---|
186 | // call actual decoding function |
---|
187 | Bool bNewPicture = false; |
---|
188 | #if H_MV |
---|
189 | Bool newSliceDiffPoc = false; |
---|
190 | Bool newSliceDiffLayer = false; |
---|
191 | #if H_3D |
---|
192 | Bool allLayersDecoded = false; |
---|
193 | #endif |
---|
194 | #endif |
---|
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 H_MV |
---|
208 | Int decIdx = xGetDecoderIdx( nalu.m_layerId , true ); |
---|
209 | |
---|
210 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) ) |
---|
211 | { |
---|
212 | bNewPicture = false; |
---|
213 | } |
---|
214 | else |
---|
215 | { |
---|
216 | newSliceDiffLayer = nalu.isSlice() && ( nalu.m_layerId != layerIdCurrPic ) && !firstSlice; |
---|
217 | newSliceDiffPoc = m_tDecTop[decIdx]->decode(nalu, m_iSkipFrame, m_pocLastDisplay[decIdx], newSliceDiffLayer ); |
---|
218 | // decode function only returns true when all of the following conditions are true |
---|
219 | // - poc in particular layer changes |
---|
220 | // - nalu does not belong to first slice in layer |
---|
221 | // - nalu.isSlice() == true |
---|
222 | |
---|
223 | bNewPicture = newSliceDiffLayer || newSliceDiffPoc; |
---|
224 | |
---|
225 | if ( nalu.isSlice() && firstSlice ) |
---|
226 | { |
---|
227 | layerIdCurrPic = nalu.m_layerId; |
---|
228 | #if H_3D |
---|
229 | pocCurrPic = m_tDecTop[decIdx]->getCurrPoc(); |
---|
230 | #endif |
---|
231 | decIdxCurrPic = decIdx; |
---|
232 | firstSlice = false; |
---|
233 | } |
---|
234 | |
---|
235 | if ( bNewPicture || !bitstreamFile ) |
---|
236 | { |
---|
237 | layerIdCurrPic = nalu.m_layerId; |
---|
238 | #if H_3D |
---|
239 | pocLastPic = pocCurrPic; |
---|
240 | pocCurrPic = m_tDecTop[decIdx]->getCurrPoc(); |
---|
241 | #endif |
---|
242 | decIdxLastPic = decIdxCurrPic; |
---|
243 | decIdxCurrPic = decIdx; |
---|
244 | #if H_3D |
---|
245 | allLayersDecoded = ( pocCurrPic != pocLastPic ); |
---|
246 | #endif |
---|
247 | } |
---|
248 | |
---|
249 | |
---|
250 | #else |
---|
251 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) ) |
---|
252 | { |
---|
253 | if(bPreviousPictureDecoded) |
---|
254 | { |
---|
255 | bNewPicture = true; |
---|
256 | bPreviousPictureDecoded = false; |
---|
257 | } |
---|
258 | else |
---|
259 | { |
---|
260 | bNewPicture = false; |
---|
261 | } |
---|
262 | } |
---|
263 | else |
---|
264 | { |
---|
265 | bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay); |
---|
266 | #endif |
---|
267 | if (bNewPicture) |
---|
268 | { |
---|
269 | bitstreamFile.clear(); |
---|
270 | /* location points to the current nalunit payload[1] due to the |
---|
271 | * need for the annexB parser to read three extra bytes. |
---|
272 | * [1] except for the first NAL unit in the file |
---|
273 | * (but bNewPicture doesn't happen then) */ |
---|
274 | bitstreamFile.seekg(location-streamoff(3)); |
---|
275 | bytestream.reset(); |
---|
276 | #if H_MV |
---|
277 | #if ENC_DEC_TRACE |
---|
278 | g_nSymbolCounter = symCount; |
---|
279 | #endif |
---|
280 | #endif |
---|
281 | } |
---|
282 | #if !H_MV |
---|
283 | bPreviousPictureDecoded = true; |
---|
284 | #endif |
---|
285 | } |
---|
286 | } |
---|
287 | if (bNewPicture || !bitstreamFile) |
---|
288 | { |
---|
289 | #if H_MV |
---|
290 | assert( decIdxLastPic != -1 ); |
---|
291 | m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet ); |
---|
292 | #else |
---|
293 | m_cTDecTop.executeLoopFilters(poc, pcListPic); |
---|
294 | #endif |
---|
295 | } |
---|
296 | #if H_3D |
---|
297 | if ( allLayersDecoded || !bitstreamFile ) |
---|
298 | { |
---|
299 | for( Int dI = 0; dI < m_numDecoders; dI++ ) |
---|
300 | { |
---|
301 | TComPic* picLastCoded = m_ivPicLists.getPic( m_tDecTop[dI]->getLayerId(), pocLastPic ); |
---|
302 | assert( picLastCoded != NULL ); |
---|
303 | picLastCoded->compressMotion(); |
---|
304 | } |
---|
305 | } |
---|
306 | #endif |
---|
307 | |
---|
308 | if( pcListPic ) |
---|
309 | { |
---|
310 | #if H_MV |
---|
311 | if ( m_pchReconFiles[decIdxLastPic] && !m_reconOpen[decIdxLastPic] ) |
---|
312 | #else |
---|
313 | if ( m_pchReconFile && !recon_opened ) |
---|
314 | #endif |
---|
315 | { |
---|
316 | if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; } |
---|
317 | if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; } |
---|
318 | |
---|
319 | #if H_MV |
---|
320 | m_tVideoIOYuvReconFile[decIdxLastPic]->open( m_pchReconFiles[decIdxLastPic], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
321 | m_reconOpen[decIdxLastPic] = true; |
---|
322 | } |
---|
323 | if ( bNewPicture && newSliceDiffPoc && |
---|
324 | #else |
---|
325 | m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
326 | recon_opened = true; |
---|
327 | } |
---|
328 | if ( bNewPicture && |
---|
329 | #endif |
---|
330 | ( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
331 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
332 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
333 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
334 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) ) |
---|
335 | { |
---|
336 | #if H_MV |
---|
337 | xFlushOutput( pcListPic, decIdxLastPic ); |
---|
338 | #else |
---|
339 | xFlushOutput( pcListPic ); |
---|
340 | #endif |
---|
341 | } |
---|
342 | // write reconstruction to file |
---|
343 | if(bNewPicture) |
---|
344 | { |
---|
345 | #if H_MV |
---|
346 | xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId ); |
---|
347 | } |
---|
348 | } |
---|
349 | } |
---|
350 | |
---|
351 | #if H_3D |
---|
352 | if( m_cCamParsCollector.isInitialized() ) |
---|
353 | { |
---|
354 | m_cCamParsCollector.setSlice( 0 ); |
---|
355 | } |
---|
356 | #endif |
---|
357 | for(UInt decIdx = 0; decIdx < m_numDecoders; decIdx++) |
---|
358 | { |
---|
359 | xFlushOutput( m_tDecTop[decIdx]->getListPic(), decIdx ); |
---|
360 | } |
---|
361 | #else |
---|
362 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
363 | } |
---|
364 | } |
---|
365 | } |
---|
366 | |
---|
367 | xFlushOutput( pcListPic ); |
---|
368 | // delete buffers |
---|
369 | m_cTDecTop.deletePicBuffer(); |
---|
370 | #endif |
---|
371 | |
---|
372 | // destroy internal classes |
---|
373 | xDestroyDecLib(); |
---|
374 | } |
---|
375 | |
---|
376 | // ==================================================================================================================== |
---|
377 | // Protected member functions |
---|
378 | // ==================================================================================================================== |
---|
379 | |
---|
380 | Void TAppDecTop::xCreateDecLib() |
---|
381 | { |
---|
382 | #if H_MV |
---|
383 | // initialize global variables |
---|
384 | initROM(); |
---|
385 | #else |
---|
386 | // create decoder class |
---|
387 | m_cTDecTop.create(); |
---|
388 | #endif |
---|
389 | } |
---|
390 | |
---|
391 | Void TAppDecTop::xDestroyDecLib() |
---|
392 | { |
---|
393 | #if H_MV |
---|
394 | // destroy ROM |
---|
395 | destroyROM(); |
---|
396 | |
---|
397 | for(Int decIdx = 0; decIdx < m_numDecoders ; decIdx++) |
---|
398 | { |
---|
399 | if( m_tVideoIOYuvReconFile[decIdx] ) |
---|
400 | { |
---|
401 | m_tVideoIOYuvReconFile[decIdx]->close(); |
---|
402 | delete m_tVideoIOYuvReconFile[decIdx]; |
---|
403 | m_tVideoIOYuvReconFile[decIdx] = NULL ; |
---|
404 | } |
---|
405 | |
---|
406 | if( m_tDecTop[decIdx] ) |
---|
407 | { |
---|
408 | m_tDecTop[decIdx]->deletePicBuffer(); |
---|
409 | m_tDecTop[decIdx]->destroy() ; |
---|
410 | } |
---|
411 | delete m_tDecTop[decIdx] ; |
---|
412 | m_tDecTop[decIdx] = NULL ; |
---|
413 | } |
---|
414 | #else |
---|
415 | if ( m_pchReconFile ) |
---|
416 | { |
---|
417 | m_cTVideoIOYuvReconFile. close(); |
---|
418 | } |
---|
419 | |
---|
420 | // destroy decoder class |
---|
421 | m_cTDecTop.destroy(); |
---|
422 | #endif |
---|
423 | #if H_3D |
---|
424 | m_cCamParsCollector.uninit(); |
---|
425 | if( m_pScaleOffsetFile ) |
---|
426 | { |
---|
427 | ::fclose( m_pScaleOffsetFile ); |
---|
428 | } |
---|
429 | #endif |
---|
430 | } |
---|
431 | |
---|
432 | Void TAppDecTop::xInitDecLib() |
---|
433 | { |
---|
434 | #if !H_MV |
---|
435 | // initialize decoder class |
---|
436 | m_cTDecTop.init(); |
---|
437 | m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
438 | #endif |
---|
439 | } |
---|
440 | |
---|
441 | /** \param pcListPic list of pictures to be written to file |
---|
442 | \todo DYN_REF_FREE should be revised |
---|
443 | */ |
---|
444 | #if H_MV |
---|
445 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int decIdx, Int tId ) |
---|
446 | #else |
---|
447 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId ) |
---|
448 | #endif |
---|
449 | { |
---|
450 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
451 | Int not_displayed = 0; |
---|
452 | |
---|
453 | while (iterPic != pcListPic->end()) |
---|
454 | { |
---|
455 | TComPic* pcPic = *(iterPic); |
---|
456 | #if H_MV |
---|
457 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx]) |
---|
458 | #else |
---|
459 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay) |
---|
460 | #endif |
---|
461 | { |
---|
462 | not_displayed++; |
---|
463 | } |
---|
464 | iterPic++; |
---|
465 | } |
---|
466 | iterPic = pcListPic->begin(); |
---|
467 | |
---|
468 | while (iterPic != pcListPic->end()) |
---|
469 | { |
---|
470 | TComPic* pcPic = *(iterPic); |
---|
471 | |
---|
472 | #if H_MV |
---|
473 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[decIdx])) |
---|
474 | #else |
---|
475 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay)) |
---|
476 | #endif |
---|
477 | { |
---|
478 | // write to file |
---|
479 | not_displayed--; |
---|
480 | #if H_MV |
---|
481 | if ( m_pchReconFiles[decIdx] ) |
---|
482 | #else |
---|
483 | if ( m_pchReconFile ) |
---|
484 | #endif |
---|
485 | { |
---|
486 | const Window &conf = pcPic->getConformanceWindow(); |
---|
487 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
488 | #if H_MV |
---|
489 | m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(), |
---|
490 | #else |
---|
491 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
492 | #endif |
---|
493 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
494 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
495 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
496 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
497 | } |
---|
498 | |
---|
499 | // update POC of display order |
---|
500 | #if H_MV |
---|
501 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
502 | #else |
---|
503 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
504 | #endif |
---|
505 | |
---|
506 | // erase non-referenced picture in the reference picture list after display |
---|
507 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
508 | { |
---|
509 | #if !DYN_REF_FREE |
---|
510 | pcPic->setReconMark(false); |
---|
511 | |
---|
512 | // mark it should be extended later |
---|
513 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
514 | |
---|
515 | #else |
---|
516 | pcPic->destroy(); |
---|
517 | pcListPic->erase( iterPic ); |
---|
518 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
519 | continue; |
---|
520 | #endif |
---|
521 | } |
---|
522 | pcPic->setOutputMark(false); |
---|
523 | } |
---|
524 | |
---|
525 | iterPic++; |
---|
526 | } |
---|
527 | } |
---|
528 | |
---|
529 | /** \param pcListPic list of pictures to be written to file |
---|
530 | \todo DYN_REF_FREE should be revised |
---|
531 | */ |
---|
532 | #if H_MV |
---|
533 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int decIdx ) |
---|
534 | #else |
---|
535 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic ) |
---|
536 | #endif |
---|
537 | { |
---|
538 | if(!pcListPic) |
---|
539 | { |
---|
540 | return; |
---|
541 | } |
---|
542 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
543 | |
---|
544 | iterPic = pcListPic->begin(); |
---|
545 | |
---|
546 | while (iterPic != pcListPic->end()) |
---|
547 | { |
---|
548 | TComPic* pcPic = *(iterPic); |
---|
549 | |
---|
550 | if ( pcPic->getOutputMark() ) |
---|
551 | { |
---|
552 | // write to file |
---|
553 | #if H_MV |
---|
554 | if ( m_pchReconFiles[decIdx] ) |
---|
555 | #else |
---|
556 | if ( m_pchReconFile ) |
---|
557 | #endif |
---|
558 | { |
---|
559 | const Window &conf = pcPic->getConformanceWindow(); |
---|
560 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
561 | #if H_MV |
---|
562 | m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(), |
---|
563 | #else |
---|
564 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
565 | #endif |
---|
566 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
567 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
568 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
569 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
570 | } |
---|
571 | |
---|
572 | // update POC of display order |
---|
573 | #if H_MV |
---|
574 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
575 | #else |
---|
576 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
577 | #endif |
---|
578 | |
---|
579 | // erase non-referenced picture in the reference picture list after display |
---|
580 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
581 | { |
---|
582 | #if !DYN_REF_FREE |
---|
583 | pcPic->setReconMark(false); |
---|
584 | |
---|
585 | // mark it should be extended later |
---|
586 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
587 | |
---|
588 | #else |
---|
589 | pcPic->destroy(); |
---|
590 | pcListPic->erase( iterPic ); |
---|
591 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
592 | continue; |
---|
593 | #endif |
---|
594 | } |
---|
595 | pcPic->setOutputMark(false); |
---|
596 | } |
---|
597 | #if !H_MV |
---|
598 | #if !DYN_REF_FREE |
---|
599 | if(pcPic) |
---|
600 | { |
---|
601 | pcPic->destroy(); |
---|
602 | delete pcPic; |
---|
603 | pcPic = NULL; |
---|
604 | } |
---|
605 | #endif |
---|
606 | #endif |
---|
607 | iterPic++; |
---|
608 | } |
---|
609 | #if H_MV |
---|
610 | m_pocLastDisplay[decIdx] = -MAX_INT; |
---|
611 | #else |
---|
612 | pcListPic->clear(); |
---|
613 | m_iPOCLastDisplay = -MAX_INT; |
---|
614 | #endif |
---|
615 | } |
---|
616 | |
---|
617 | /** \param nalu Input nalu to check whether its LayerId is within targetDecLayerIdSet |
---|
618 | */ |
---|
619 | Bool TAppDecTop::isNaluWithinTargetDecLayerIdSet( InputNALUnit* nalu ) |
---|
620 | { |
---|
621 | if ( m_targetDecLayerIdSet.size() == 0 ) // By default, the set is empty, meaning all LayerIds are allowed |
---|
622 | { |
---|
623 | return true; |
---|
624 | } |
---|
625 | for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++) |
---|
626 | { |
---|
627 | #if H_MV |
---|
628 | if ( nalu->m_layerId == (*it) ) |
---|
629 | #else |
---|
630 | if ( nalu->m_reservedZero6Bits == (*it) ) |
---|
631 | #endif |
---|
632 | { |
---|
633 | return true; |
---|
634 | } |
---|
635 | } |
---|
636 | return false; |
---|
637 | } |
---|
638 | |
---|
639 | #if H_MV |
---|
640 | Int TAppDecTop::xGetDecoderIdx( Int layerId, Bool createFlag /*= false */ ) |
---|
641 | { |
---|
642 | Int decIdx = -1; |
---|
643 | if ( m_layerIdToDecIdx[ layerId ] != -1 ) |
---|
644 | { |
---|
645 | decIdx = m_layerIdToDecIdx[ layerId ]; |
---|
646 | } |
---|
647 | else |
---|
648 | { |
---|
649 | assert ( createFlag ); |
---|
650 | assert( m_numDecoders < MAX_NUM_LAYERS ); |
---|
651 | |
---|
652 | decIdx = m_numDecoders; |
---|
653 | |
---|
654 | // Init decoder |
---|
655 | m_tDecTop[ decIdx ] = new TDecTop; |
---|
656 | m_tDecTop[ decIdx ]->create(); |
---|
657 | m_tDecTop[ decIdx ]->init( ); |
---|
658 | m_tDecTop[ decIdx ]->setLayerId( layerId ); |
---|
659 | m_tDecTop[ decIdx ]->setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
660 | m_tDecTop[ decIdx ]->setIvPicLists( &m_ivPicLists ); |
---|
661 | #if H_3D |
---|
662 | m_tDecTop[ decIdx ]->setCamParsCollector( &m_cCamParsCollector ); |
---|
663 | #endif |
---|
664 | |
---|
665 | // append pic list of new decoder to PicLists |
---|
666 | assert( m_ivPicLists.size() == m_numDecoders ); |
---|
667 | m_ivPicLists.push_back( m_tDecTop[ decIdx ]->getListPic() ); |
---|
668 | |
---|
669 | // create recon file related stuff |
---|
670 | Char* pchTempFilename = NULL; |
---|
671 | if ( m_pchReconFile ) |
---|
672 | { |
---|
673 | Char buffer[4]; |
---|
674 | sprintf(buffer,"_%i", layerId ); |
---|
675 | assert ( m_pchReconFile ); |
---|
676 | xAppendToFileNameEnd( m_pchReconFile , buffer, pchTempFilename ); |
---|
677 | assert( m_pchReconFiles.size() == m_numDecoders ); |
---|
678 | } |
---|
679 | |
---|
680 | m_pchReconFiles.push_back( pchTempFilename ); |
---|
681 | |
---|
682 | m_tVideoIOYuvReconFile[ decIdx ] = new TVideoIOYuv; |
---|
683 | m_reconOpen [ decIdx ] = false; |
---|
684 | |
---|
685 | // set others |
---|
686 | m_pocLastDisplay [ decIdx ] = -MAX_INT; |
---|
687 | m_layerIdToDecIdx [ layerId ] = decIdx; |
---|
688 | |
---|
689 | m_numDecoders++; |
---|
690 | }; |
---|
691 | return decIdx; |
---|
692 | } |
---|
693 | #endif |
---|
694 | //! \} |
---|