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