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 | } |
---|
98 | |
---|
99 | // ==================================================================================================================== |
---|
100 | // Public member functions |
---|
101 | // ==================================================================================================================== |
---|
102 | |
---|
103 | /** |
---|
104 | - create internal class |
---|
105 | - initialize internal class |
---|
106 | - until the end of the bitstream, call decoding function in TDecTop class |
---|
107 | - delete allocated buffers |
---|
108 | - destroy internal class |
---|
109 | . |
---|
110 | */ |
---|
111 | Void TAppDecTop::decode() |
---|
112 | { |
---|
113 | Int poc; |
---|
114 | #if H_MV |
---|
115 | poc = -1; |
---|
116 | #endif |
---|
117 | TComList<TComPic*>* pcListPic = NULL; |
---|
118 | |
---|
119 | ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary); |
---|
120 | if (!bitstreamFile) |
---|
121 | { |
---|
122 | fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchBitstreamFile); |
---|
123 | exit(EXIT_FAILURE); |
---|
124 | } |
---|
125 | |
---|
126 | #if H_3D |
---|
127 | if( m_pchScaleOffsetFile ) |
---|
128 | { |
---|
129 | m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" ); |
---|
130 | AOF( m_pScaleOffsetFile ); |
---|
131 | } |
---|
132 | m_cCamParsCollector.init( m_pScaleOffsetFile ); |
---|
133 | #endif |
---|
134 | InputByteStream bytestream(bitstreamFile); |
---|
135 | |
---|
136 | // create & initialize internal classes |
---|
137 | xCreateDecLib(); |
---|
138 | xInitDecLib (); |
---|
139 | #if !H_MV |
---|
140 | m_iPOCLastDisplay += m_iSkipFrame; // set the last displayed POC correctly for skip forward. |
---|
141 | |
---|
142 | // main decoder loop |
---|
143 | Bool recon_opened = false; // reconstruction file not yet opened. (must be performed after SPS is seen) |
---|
144 | #else |
---|
145 | Int pocCurrPic = -MAX_INT; |
---|
146 | Int pocLastPic = -MAX_INT; |
---|
147 | |
---|
148 | Int layerIdCurrPic = 0; |
---|
149 | |
---|
150 | Int decIdxLastPic = 0; |
---|
151 | Int decIdxCurrPic = 0; |
---|
152 | |
---|
153 | Bool firstSlice = true; |
---|
154 | #endif |
---|
155 | |
---|
156 | while (!!bitstreamFile) |
---|
157 | { |
---|
158 | /* location serves to work around a design fault in the decoder, whereby |
---|
159 | * the process of reading a new slice that is the first slice of a new frame |
---|
160 | * requires the TDecTop::decode() method to be called again with the same |
---|
161 | * nal unit. */ |
---|
162 | streampos location = bitstreamFile.tellg(); |
---|
163 | #if H_MV |
---|
164 | #if ENC_DEC_TRACE |
---|
165 | Int64 symCount = g_nSymbolCounter; |
---|
166 | #endif |
---|
167 | #endif |
---|
168 | AnnexBStats stats = AnnexBStats(); |
---|
169 | #if !H_MV |
---|
170 | Bool bPreviousPictureDecoded = false; |
---|
171 | #endif |
---|
172 | |
---|
173 | vector<uint8_t> nalUnit; |
---|
174 | InputNALUnit nalu; |
---|
175 | byteStreamNALUnit(bytestream, nalUnit, stats); |
---|
176 | |
---|
177 | // call actual decoding function |
---|
178 | Bool bNewPicture = false; |
---|
179 | #if H_MV |
---|
180 | Bool newSliceDiffPoc = false; |
---|
181 | Bool newSliceDiffLayer = false; |
---|
182 | Bool allLayersDecoded = false; |
---|
183 | #endif |
---|
184 | if (nalUnit.empty()) |
---|
185 | { |
---|
186 | /* this can happen if the following occur: |
---|
187 | * - empty input file |
---|
188 | * - two back-to-back start_code_prefixes |
---|
189 | * - start_code_prefix immediately followed by EOF |
---|
190 | */ |
---|
191 | fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n"); |
---|
192 | } |
---|
193 | else |
---|
194 | { |
---|
195 | read(nalu, nalUnit); |
---|
196 | #if H_MV |
---|
197 | Int decIdx = xGetDecoderIdx( nalu.m_layerId , true ); |
---|
198 | |
---|
199 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) ) |
---|
200 | { |
---|
201 | bNewPicture = false; |
---|
202 | } |
---|
203 | else |
---|
204 | { |
---|
205 | newSliceDiffLayer = nalu.isSlice() && ( nalu.m_layerId != layerIdCurrPic ) && !firstSlice; |
---|
206 | newSliceDiffPoc = m_tDecTop[decIdx]->decode(nalu, m_iSkipFrame, m_pocLastDisplay[decIdx], newSliceDiffLayer ); |
---|
207 | // decode function only returns true when all of the following conditions are true |
---|
208 | // - poc in particular layer changes |
---|
209 | // - nalu does not belong to first slice in layer |
---|
210 | // - nalu.isSlice() == true |
---|
211 | |
---|
212 | bNewPicture = newSliceDiffLayer || newSliceDiffPoc; |
---|
213 | |
---|
214 | if ( nalu.isSlice() && firstSlice ) |
---|
215 | { |
---|
216 | layerIdCurrPic = nalu.m_layerId; |
---|
217 | pocCurrPic = m_tDecTop[decIdx]->getCurrPoc(); |
---|
218 | decIdxCurrPic = decIdx; |
---|
219 | firstSlice = false; |
---|
220 | } |
---|
221 | |
---|
222 | if ( bNewPicture || !bitstreamFile ) |
---|
223 | { |
---|
224 | layerIdCurrPic = nalu.m_layerId; |
---|
225 | |
---|
226 | pocLastPic = pocCurrPic; |
---|
227 | pocCurrPic = m_tDecTop[decIdx]->getCurrPoc(); |
---|
228 | |
---|
229 | decIdxLastPic = decIdxCurrPic; |
---|
230 | decIdxCurrPic = decIdx; |
---|
231 | |
---|
232 | allLayersDecoded = ( pocCurrPic != pocLastPic ); |
---|
233 | } |
---|
234 | |
---|
235 | |
---|
236 | #else |
---|
237 | if( (m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) || !isNaluWithinTargetDecLayerIdSet(&nalu) ) |
---|
238 | { |
---|
239 | if(bPreviousPictureDecoded) |
---|
240 | { |
---|
241 | bNewPicture = true; |
---|
242 | bPreviousPictureDecoded = false; |
---|
243 | } |
---|
244 | else |
---|
245 | { |
---|
246 | bNewPicture = false; |
---|
247 | } |
---|
248 | } |
---|
249 | else |
---|
250 | { |
---|
251 | bNewPicture = m_cTDecTop.decode(nalu, m_iSkipFrame, m_iPOCLastDisplay); |
---|
252 | #endif |
---|
253 | if (bNewPicture) |
---|
254 | { |
---|
255 | bitstreamFile.clear(); |
---|
256 | /* location points to the current nalunit payload[1] due to the |
---|
257 | * need for the annexB parser to read three extra bytes. |
---|
258 | * [1] except for the first NAL unit in the file |
---|
259 | * (but bNewPicture doesn't happen then) */ |
---|
260 | bitstreamFile.seekg(location-streamoff(3)); |
---|
261 | bytestream.reset(); |
---|
262 | #if H_MV |
---|
263 | #if ENC_DEC_TRACE |
---|
264 | g_nSymbolCounter = symCount; |
---|
265 | #endif |
---|
266 | #endif |
---|
267 | } |
---|
268 | #if !H_MV |
---|
269 | bPreviousPictureDecoded = true; |
---|
270 | #endif |
---|
271 | } |
---|
272 | } |
---|
273 | if (bNewPicture || !bitstreamFile) |
---|
274 | { |
---|
275 | #if H_MV |
---|
276 | assert( decIdxLastPic != -1 ); |
---|
277 | m_tDecTop[decIdxLastPic]->endPicDecoding(poc, pcListPic, m_targetDecLayerIdSet ); |
---|
278 | #else |
---|
279 | m_cTDecTop.executeLoopFilters(poc, pcListPic); |
---|
280 | #endif |
---|
281 | } |
---|
282 | #if H_3D |
---|
283 | if ( allLayersDecoded || !bitstreamFile ) |
---|
284 | { |
---|
285 | for( Int dI = 0; dI < m_numDecoders; dI++ ) |
---|
286 | { |
---|
287 | TComPic* picLastCoded = m_ivPicLists.getPic( m_tDecTop[dI]->getLayerId(), pocLastPic ); |
---|
288 | assert( picLastCoded != NULL ); |
---|
289 | picLastCoded->compressMotion(); |
---|
290 | } |
---|
291 | } |
---|
292 | #endif |
---|
293 | |
---|
294 | if( pcListPic ) |
---|
295 | { |
---|
296 | #if H_MV |
---|
297 | if ( m_pchReconFiles[decIdxLastPic] && !m_reconOpen[decIdxLastPic] ) |
---|
298 | #else |
---|
299 | if ( m_pchReconFile && !recon_opened ) |
---|
300 | #endif |
---|
301 | { |
---|
302 | if (!m_outputBitDepthY) { m_outputBitDepthY = g_bitDepthY; } |
---|
303 | if (!m_outputBitDepthC) { m_outputBitDepthC = g_bitDepthC; } |
---|
304 | |
---|
305 | #if H_MV |
---|
306 | m_tVideoIOYuvReconFile[decIdxLastPic]->open( m_pchReconFiles[decIdxLastPic], true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
307 | m_reconOpen[decIdxLastPic] = true; |
---|
308 | } |
---|
309 | if ( bNewPicture && newSliceDiffPoc && |
---|
310 | #else |
---|
311 | m_cTVideoIOYuvReconFile.open( m_pchReconFile, true, m_outputBitDepthY, m_outputBitDepthC, g_bitDepthY, g_bitDepthC ); // write mode |
---|
312 | recon_opened = true; |
---|
313 | } |
---|
314 | if ( bNewPicture && |
---|
315 | #endif |
---|
316 | ( nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_W_RADL |
---|
317 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR_N_LP |
---|
318 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_N_LP |
---|
319 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_RADL |
---|
320 | || nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_BLA_W_LP ) ) |
---|
321 | { |
---|
322 | #if H_MV |
---|
323 | xFlushOutput( pcListPic, decIdxLastPic ); |
---|
324 | #else |
---|
325 | xFlushOutput( pcListPic ); |
---|
326 | #endif |
---|
327 | } |
---|
328 | // write reconstruction to file |
---|
329 | if(bNewPicture) |
---|
330 | { |
---|
331 | #if H_MV |
---|
332 | xWriteOutput( pcListPic, decIdxLastPic, nalu.m_temporalId ); |
---|
333 | } |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | #if H_3D |
---|
338 | if( m_cCamParsCollector.isInitialized() ) |
---|
339 | { |
---|
340 | m_cCamParsCollector.setSlice( 0 ); |
---|
341 | } |
---|
342 | #endif |
---|
343 | for(UInt decIdx = 0; decIdx < m_numDecoders; decIdx++) |
---|
344 | { |
---|
345 | xFlushOutput( m_tDecTop[decIdx]->getListPic(), decIdx ); |
---|
346 | } |
---|
347 | #else |
---|
348 | xWriteOutput( pcListPic, nalu.m_temporalId ); |
---|
349 | } |
---|
350 | } |
---|
351 | } |
---|
352 | |
---|
353 | xFlushOutput( pcListPic ); |
---|
354 | // delete buffers |
---|
355 | m_cTDecTop.deletePicBuffer(); |
---|
356 | #endif |
---|
357 | |
---|
358 | // destroy internal classes |
---|
359 | xDestroyDecLib(); |
---|
360 | } |
---|
361 | |
---|
362 | // ==================================================================================================================== |
---|
363 | // Protected member functions |
---|
364 | // ==================================================================================================================== |
---|
365 | |
---|
366 | Void TAppDecTop::xCreateDecLib() |
---|
367 | { |
---|
368 | #if H_MV |
---|
369 | // initialize global variables |
---|
370 | initROM(); |
---|
371 | #else |
---|
372 | // create decoder class |
---|
373 | m_cTDecTop.create(); |
---|
374 | #endif |
---|
375 | } |
---|
376 | |
---|
377 | Void TAppDecTop::xDestroyDecLib() |
---|
378 | { |
---|
379 | #if H_MV |
---|
380 | // destroy ROM |
---|
381 | destroyROM(); |
---|
382 | |
---|
383 | for(Int decIdx = 0; decIdx < m_numDecoders ; decIdx++) |
---|
384 | { |
---|
385 | if( m_tVideoIOYuvReconFile[decIdx] ) |
---|
386 | { |
---|
387 | m_tVideoIOYuvReconFile[decIdx]->close(); |
---|
388 | delete m_tVideoIOYuvReconFile[decIdx]; |
---|
389 | m_tVideoIOYuvReconFile[decIdx] = NULL ; |
---|
390 | } |
---|
391 | |
---|
392 | if( m_tDecTop[decIdx] ) |
---|
393 | { |
---|
394 | m_tDecTop[decIdx]->deletePicBuffer(); |
---|
395 | m_tDecTop[decIdx]->destroy() ; |
---|
396 | } |
---|
397 | delete m_tDecTop[decIdx] ; |
---|
398 | m_tDecTop[decIdx] = NULL ; |
---|
399 | } |
---|
400 | #else |
---|
401 | if ( m_pchReconFile ) |
---|
402 | { |
---|
403 | m_cTVideoIOYuvReconFile. close(); |
---|
404 | } |
---|
405 | |
---|
406 | // destroy decoder class |
---|
407 | m_cTDecTop.destroy(); |
---|
408 | #endif |
---|
409 | #if H_3D |
---|
410 | m_cCamParsCollector.uninit(); |
---|
411 | if( m_pScaleOffsetFile ) |
---|
412 | { |
---|
413 | ::fclose( m_pScaleOffsetFile ); |
---|
414 | } |
---|
415 | #endif |
---|
416 | } |
---|
417 | |
---|
418 | Void TAppDecTop::xInitDecLib() |
---|
419 | { |
---|
420 | #if !H_MV |
---|
421 | // initialize decoder class |
---|
422 | m_cTDecTop.init(); |
---|
423 | m_cTDecTop.setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
424 | #endif |
---|
425 | } |
---|
426 | |
---|
427 | /** \param pcListPic list of pictures to be written to file |
---|
428 | \todo DYN_REF_FREE should be revised |
---|
429 | */ |
---|
430 | #if H_MV |
---|
431 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int decIdx, Int tId ) |
---|
432 | #else |
---|
433 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, UInt tId ) |
---|
434 | #endif |
---|
435 | { |
---|
436 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
437 | Int not_displayed = 0; |
---|
438 | |
---|
439 | while (iterPic != pcListPic->end()) |
---|
440 | { |
---|
441 | TComPic* pcPic = *(iterPic); |
---|
442 | #if H_MV |
---|
443 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[decIdx]) |
---|
444 | #else |
---|
445 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_iPOCLastDisplay) |
---|
446 | #endif |
---|
447 | { |
---|
448 | not_displayed++; |
---|
449 | } |
---|
450 | iterPic++; |
---|
451 | } |
---|
452 | iterPic = pcListPic->begin(); |
---|
453 | |
---|
454 | while (iterPic != pcListPic->end()) |
---|
455 | { |
---|
456 | TComPic* pcPic = *(iterPic); |
---|
457 | |
---|
458 | #if H_MV |
---|
459 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[decIdx])) |
---|
460 | #else |
---|
461 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getNumReorderPics(tId) && pcPic->getPOC() > m_iPOCLastDisplay)) |
---|
462 | #endif |
---|
463 | { |
---|
464 | // write to file |
---|
465 | not_displayed--; |
---|
466 | #if H_MV |
---|
467 | if ( m_pchReconFiles[decIdx] ) |
---|
468 | #else |
---|
469 | if ( m_pchReconFile ) |
---|
470 | #endif |
---|
471 | { |
---|
472 | const Window &conf = pcPic->getConformanceWindow(); |
---|
473 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
474 | #if H_MV |
---|
475 | m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(), |
---|
476 | #else |
---|
477 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
478 | #endif |
---|
479 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
480 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
481 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
482 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
483 | } |
---|
484 | |
---|
485 | // update POC of display order |
---|
486 | #if H_MV |
---|
487 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
488 | #else |
---|
489 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
490 | #endif |
---|
491 | |
---|
492 | // erase non-referenced picture in the reference picture list after display |
---|
493 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
494 | { |
---|
495 | #if !DYN_REF_FREE |
---|
496 | pcPic->setReconMark(false); |
---|
497 | |
---|
498 | // mark it should be extended later |
---|
499 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
500 | |
---|
501 | #else |
---|
502 | pcPic->destroy(); |
---|
503 | pcListPic->erase( iterPic ); |
---|
504 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
505 | continue; |
---|
506 | #endif |
---|
507 | } |
---|
508 | pcPic->setOutputMark(false); |
---|
509 | } |
---|
510 | |
---|
511 | iterPic++; |
---|
512 | } |
---|
513 | } |
---|
514 | |
---|
515 | /** \param pcListPic list of pictures to be written to file |
---|
516 | \todo DYN_REF_FREE should be revised |
---|
517 | */ |
---|
518 | #if H_MV |
---|
519 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int decIdx ) |
---|
520 | #else |
---|
521 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic ) |
---|
522 | #endif |
---|
523 | { |
---|
524 | if(!pcListPic) |
---|
525 | { |
---|
526 | return; |
---|
527 | } |
---|
528 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
529 | |
---|
530 | iterPic = pcListPic->begin(); |
---|
531 | |
---|
532 | while (iterPic != pcListPic->end()) |
---|
533 | { |
---|
534 | TComPic* pcPic = *(iterPic); |
---|
535 | |
---|
536 | if ( pcPic->getOutputMark() ) |
---|
537 | { |
---|
538 | // write to file |
---|
539 | #if H_MV |
---|
540 | if ( m_pchReconFiles[decIdx] ) |
---|
541 | #else |
---|
542 | if ( m_pchReconFile ) |
---|
543 | #endif |
---|
544 | { |
---|
545 | const Window &conf = pcPic->getConformanceWindow(); |
---|
546 | const Window &defDisp = m_respectDefDispWindow ? pcPic->getDefDisplayWindow() : Window(); |
---|
547 | #if H_MV |
---|
548 | m_tVideoIOYuvReconFile[decIdx]->write( pcPic->getPicYuvRec(), |
---|
549 | #else |
---|
550 | m_cTVideoIOYuvReconFile.write( pcPic->getPicYuvRec(), |
---|
551 | #endif |
---|
552 | conf.getWindowLeftOffset() + defDisp.getWindowLeftOffset(), |
---|
553 | conf.getWindowRightOffset() + defDisp.getWindowRightOffset(), |
---|
554 | conf.getWindowTopOffset() + defDisp.getWindowTopOffset(), |
---|
555 | conf.getWindowBottomOffset() + defDisp.getWindowBottomOffset() ); |
---|
556 | } |
---|
557 | |
---|
558 | // update POC of display order |
---|
559 | #if H_MV |
---|
560 | m_pocLastDisplay[decIdx] = pcPic->getPOC(); |
---|
561 | #else |
---|
562 | m_iPOCLastDisplay = pcPic->getPOC(); |
---|
563 | #endif |
---|
564 | |
---|
565 | // erase non-referenced picture in the reference picture list after display |
---|
566 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
567 | { |
---|
568 | #if !DYN_REF_FREE |
---|
569 | pcPic->setReconMark(false); |
---|
570 | |
---|
571 | // mark it should be extended later |
---|
572 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
573 | |
---|
574 | #else |
---|
575 | pcPic->destroy(); |
---|
576 | pcListPic->erase( iterPic ); |
---|
577 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
578 | continue; |
---|
579 | #endif |
---|
580 | } |
---|
581 | pcPic->setOutputMark(false); |
---|
582 | } |
---|
583 | #if !H_MV |
---|
584 | #if !DYN_REF_FREE |
---|
585 | if(pcPic) |
---|
586 | { |
---|
587 | pcPic->destroy(); |
---|
588 | delete pcPic; |
---|
589 | pcPic = NULL; |
---|
590 | } |
---|
591 | #endif |
---|
592 | #endif |
---|
593 | iterPic++; |
---|
594 | } |
---|
595 | #if H_MV |
---|
596 | m_pocLastDisplay[decIdx] = -MAX_INT; |
---|
597 | #else |
---|
598 | pcListPic->clear(); |
---|
599 | m_iPOCLastDisplay = -MAX_INT; |
---|
600 | #endif |
---|
601 | } |
---|
602 | |
---|
603 | /** \param nalu Input nalu to check whether its LayerId is within targetDecLayerIdSet |
---|
604 | */ |
---|
605 | Bool TAppDecTop::isNaluWithinTargetDecLayerIdSet( InputNALUnit* nalu ) |
---|
606 | { |
---|
607 | if ( m_targetDecLayerIdSet.size() == 0 ) // By default, the set is empty, meaning all LayerIds are allowed |
---|
608 | { |
---|
609 | return true; |
---|
610 | } |
---|
611 | for (std::vector<Int>::iterator it = m_targetDecLayerIdSet.begin(); it != m_targetDecLayerIdSet.end(); it++) |
---|
612 | { |
---|
613 | #if H_MV |
---|
614 | if ( nalu->m_layerId == (*it) ) |
---|
615 | #else |
---|
616 | if ( nalu->m_reservedZero6Bits == (*it) ) |
---|
617 | #endif |
---|
618 | { |
---|
619 | return true; |
---|
620 | } |
---|
621 | } |
---|
622 | return false; |
---|
623 | } |
---|
624 | |
---|
625 | #if H_MV |
---|
626 | Int TAppDecTop::xGetDecoderIdx( Int layerId, Bool createFlag /*= false */ ) |
---|
627 | { |
---|
628 | Int decIdx = -1; |
---|
629 | if ( m_layerIdToDecIdx[ layerId ] != -1 ) |
---|
630 | { |
---|
631 | decIdx = m_layerIdToDecIdx[ layerId ]; |
---|
632 | } |
---|
633 | else |
---|
634 | { |
---|
635 | assert ( createFlag ); |
---|
636 | assert( m_numDecoders < MAX_NUM_LAYERS ); |
---|
637 | |
---|
638 | decIdx = m_numDecoders; |
---|
639 | |
---|
640 | // Init decoder |
---|
641 | m_tDecTop[ decIdx ] = new TDecTop; |
---|
642 | m_tDecTop[ decIdx ]->create(); |
---|
643 | m_tDecTop[ decIdx ]->init( ); |
---|
644 | m_tDecTop[ decIdx ]->setLayerId( layerId ); |
---|
645 | m_tDecTop[ decIdx ]->setDecodedPictureHashSEIEnabled(m_decodedPictureHashSEIEnabled); |
---|
646 | m_tDecTop[ decIdx ]->setIvPicLists( &m_ivPicLists ); |
---|
647 | #if H_3D |
---|
648 | m_tDecTop[ decIdx ]->setCamParsCollector( &m_cCamParsCollector ); |
---|
649 | #endif |
---|
650 | |
---|
651 | // append pic list of new decoder to PicLists |
---|
652 | assert( m_ivPicLists.size() == m_numDecoders ); |
---|
653 | m_ivPicLists.push_back( m_tDecTop[ decIdx ]->getListPic() ); |
---|
654 | |
---|
655 | // create recon file related stuff |
---|
656 | Char* pchTempFilename = NULL; |
---|
657 | if ( m_pchReconFile ) |
---|
658 | { |
---|
659 | Char buffer[4]; |
---|
660 | sprintf(buffer,"_%i", layerId ); |
---|
661 | assert ( m_pchReconFile ); |
---|
662 | xAppendToFileNameEnd( m_pchReconFile , buffer, pchTempFilename ); |
---|
663 | assert( m_pchReconFiles.size() == m_numDecoders ); |
---|
664 | } |
---|
665 | |
---|
666 | m_pchReconFiles.push_back( pchTempFilename ); |
---|
667 | |
---|
668 | m_tVideoIOYuvReconFile[ decIdx ] = new TVideoIOYuv; |
---|
669 | m_reconOpen [ decIdx ] = false; |
---|
670 | |
---|
671 | // set others |
---|
672 | m_pocLastDisplay [ decIdx ] = -MAX_INT; |
---|
673 | m_layerIdToDecIdx [ layerId ] = decIdx; |
---|
674 | |
---|
675 | m_numDecoders++; |
---|
676 | }; |
---|
677 | return decIdx; |
---|
678 | } |
---|
679 | #endif |
---|
680 | //! \} |
---|