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-2012, 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 | { |
---|
57 | ::memset (m_abDecFlag, 0, sizeof (m_abDecFlag)); |
---|
58 | m_useDepth = false; |
---|
59 | m_pScaleOffsetFile = 0; |
---|
60 | } |
---|
61 | |
---|
62 | Void TAppDecTop::create() |
---|
63 | { |
---|
64 | } |
---|
65 | |
---|
66 | Void TAppDecTop::destroy() |
---|
67 | { |
---|
68 | } |
---|
69 | |
---|
70 | // ==================================================================================================================== |
---|
71 | // Public member functions |
---|
72 | // ==================================================================================================================== |
---|
73 | |
---|
74 | /** |
---|
75 | - create internal class |
---|
76 | - initialize internal class |
---|
77 | - until the end of the bitstream, call decoding function in TDecTop class |
---|
78 | - delete allocated buffers |
---|
79 | - destroy internal class |
---|
80 | . |
---|
81 | */ |
---|
82 | Void TAppDecTop::decode() |
---|
83 | { |
---|
84 | #if VIDYO_VPS_INTEGRATION |
---|
85 | increaseNumberOfViews( 0, 0, 0 ); |
---|
86 | #else |
---|
87 | increaseNumberOfViews( 1 ); |
---|
88 | #endif |
---|
89 | |
---|
90 | #if SONY_COLPIC_AVAILABILITY |
---|
91 | m_tDecTop[0]->setViewOrderIdx(0); |
---|
92 | #endif |
---|
93 | Int viewDepthId = 0; |
---|
94 | Int previousViewDepthId = 0; |
---|
95 | UInt uiPOC[MAX_VIEW_NUM*2]; |
---|
96 | TComList<TComPic*>* pcListPic[MAX_VIEW_NUM*2]; |
---|
97 | Bool newPicture[MAX_VIEW_NUM*2]; |
---|
98 | Bool previousPictureDecoded = false; |
---|
99 | for( Int i = 0; i < MAX_VIEW_NUM*2; i++ ) |
---|
100 | { |
---|
101 | uiPOC[i] = 0; |
---|
102 | pcListPic[i] = NULL; |
---|
103 | newPicture[i] = false; |
---|
104 | } |
---|
105 | |
---|
106 | ifstream bitstreamFile(m_pchBitstreamFile, ifstream::in | ifstream::binary); |
---|
107 | if (!bitstreamFile) |
---|
108 | { |
---|
109 | fprintf(stderr, "\nfailed to open bitstream file `%s' for reading\n", m_pchBitstreamFile); |
---|
110 | exit(EXIT_FAILURE); |
---|
111 | } |
---|
112 | |
---|
113 | if( m_pchScaleOffsetFile ) |
---|
114 | { |
---|
115 | m_pScaleOffsetFile = ::fopen( m_pchScaleOffsetFile, "wt" ); |
---|
116 | AOF( m_pScaleOffsetFile ); |
---|
117 | } |
---|
118 | m_cCamParsCollector.init( m_pScaleOffsetFile ); |
---|
119 | |
---|
120 | InputByteStream bytestream(bitstreamFile); |
---|
121 | |
---|
122 | while (!!bitstreamFile) |
---|
123 | { |
---|
124 | /* location serves to work around a design fault in the decoder, whereby |
---|
125 | * the process of reading a new slice that is the first slice of a new frame |
---|
126 | * requires the TDecTop::decode() method to be called again with the same |
---|
127 | * nal unit. */ |
---|
128 | streampos location = bitstreamFile.tellg(); |
---|
129 | AnnexBStats stats = AnnexBStats(); |
---|
130 | vector<uint8_t> nalUnit; |
---|
131 | InputNALUnit nalu; |
---|
132 | byteStreamNALUnit(bytestream, nalUnit, stats); |
---|
133 | |
---|
134 | // call actual decoding function |
---|
135 | if (nalUnit.empty()) |
---|
136 | { |
---|
137 | /* this can happen if the following occur: |
---|
138 | * - empty input file |
---|
139 | * - two back-to-back start_code_prefixes |
---|
140 | * - start_code_prefix immediately followed by EOF |
---|
141 | */ |
---|
142 | fprintf(stderr, "Warning: Attempt to decode an empty NAL unit\n"); |
---|
143 | } |
---|
144 | else |
---|
145 | { |
---|
146 | read(nalu, nalUnit); |
---|
147 | #if VIDYO_VPS_INTEGRATION |
---|
148 | Int viewId = 0; |
---|
149 | Int depth = 0; |
---|
150 | |
---|
151 | if(nalu.m_nalUnitType != NAL_UNIT_VPS || nalu.m_layerId) |
---|
152 | { |
---|
153 | // code assumes that the first nal unit is VPS |
---|
154 | // currently, this is a hack that requires non-first VPSs have non-zero layer_id |
---|
155 | viewId = getVPSAccess()->getActiveVPS()->getViewId(nalu.m_layerId); |
---|
156 | depth = getVPSAccess()->getActiveVPS()->getDepthFlag(nalu.m_layerId); |
---|
157 | } |
---|
158 | viewDepthId = nalu.m_layerId; // coding order T0D0T1D1T2D2 |
---|
159 | #else |
---|
160 | Int viewId = nalu.m_viewId; |
---|
161 | Int depth = nalu.m_isDepth ? 1 : 0; |
---|
162 | viewDepthId = viewId * 2 + depth; // coding order T0D0T1D1T2D2 |
---|
163 | #endif |
---|
164 | |
---|
165 | newPicture[viewDepthId] = false; |
---|
166 | if( viewDepthId >= m_tDecTop.size() ) |
---|
167 | { |
---|
168 | #if VIDYO_VPS_INTEGRATION |
---|
169 | increaseNumberOfViews( viewDepthId, viewId, depth ); |
---|
170 | #else |
---|
171 | increaseNumberOfViews( viewDepthId +1 ); |
---|
172 | #endif |
---|
173 | } |
---|
174 | if(m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) |
---|
175 | { |
---|
176 | previousPictureDecoded = false; |
---|
177 | } |
---|
178 | if(m_tDecTop.size() > 1 && (viewDepthId != previousViewDepthId) && previousPictureDecoded ) |
---|
179 | { |
---|
180 | m_tDecTop[previousViewDepthId]->executeDeblockAndAlf(uiPOC[previousViewDepthId], pcListPic[previousViewDepthId], m_iSkipFrame, m_pocLastDisplay[previousViewDepthId]); |
---|
181 | } |
---|
182 | if( ( viewDepthId == 0 && (viewDepthId != previousViewDepthId) ) || m_tDecTop.size() == 1 ) |
---|
183 | { |
---|
184 | #if HHI_INTER_VIEW_RESIDUAL_PRED |
---|
185 | for( Int i = 0; i < m_tDecTop.size(); i++ ) |
---|
186 | { |
---|
187 | m_tDecTop[i]->deleteExtraPicBuffers( uiPOC[i] ); |
---|
188 | } |
---|
189 | #endif |
---|
190 | for( Int i = 0; i < m_tDecTop.size(); i++ ) |
---|
191 | { |
---|
192 | m_tDecTop[i]->compressMotion( uiPOC[i] ); |
---|
193 | } |
---|
194 | } |
---|
195 | if( !(m_iMaxTemporalLayer >= 0 && nalu.m_temporalId > m_iMaxTemporalLayer) ) |
---|
196 | { |
---|
197 | newPicture[viewDepthId] = m_tDecTop[viewDepthId]->decode(nalu, m_iSkipFrame, m_pocLastDisplay[viewDepthId]); |
---|
198 | if (newPicture[viewDepthId]) |
---|
199 | { |
---|
200 | bitstreamFile.clear(); |
---|
201 | /* location points to the current nalunit payload[1] due to the |
---|
202 | * need for the annexB parser to read three extra bytes. |
---|
203 | * [1] except for the first NAL unit in the file |
---|
204 | * (but bNewPicture doesn't happen then) */ |
---|
205 | bitstreamFile.seekg(location-streamoff(3)); |
---|
206 | bytestream.reset(); |
---|
207 | } |
---|
208 | if( nalu.isSlice() ) |
---|
209 | { |
---|
210 | previousPictureDecoded = true; |
---|
211 | } |
---|
212 | } |
---|
213 | } |
---|
214 | if( ( (newPicture[viewDepthId] || !bitstreamFile) && m_tDecTop.size() == 1) || (!bitstreamFile && previousPictureDecoded == true) ) |
---|
215 | { |
---|
216 | m_tDecTop[viewDepthId]->executeDeblockAndAlf(uiPOC[viewDepthId], pcListPic[viewDepthId], m_iSkipFrame, m_pocLastDisplay[viewDepthId]); |
---|
217 | } |
---|
218 | if( pcListPic[viewDepthId] ) |
---|
219 | { |
---|
220 | if( newPicture[viewDepthId] && (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDR || (nalu.m_nalUnitType == NAL_UNIT_CODED_SLICE_IDV && m_tDecTop[viewDepthId]->getNalUnitTypeBaseView() == NAL_UNIT_CODED_SLICE_IDR)) ) |
---|
221 | { |
---|
222 | xFlushOutput( pcListPic[viewDepthId], viewDepthId ); |
---|
223 | } |
---|
224 | // write reconstruction to file |
---|
225 | if(newPicture[viewDepthId]) |
---|
226 | { |
---|
227 | #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER |
---|
228 | xWriteOutput( pcListPic[viewDepthId], viewDepthId, nalu.m_temporalId ); |
---|
229 | #else |
---|
230 | xWriteOutput( pcListPic[viewDepthId], viewDepthId ); |
---|
231 | #endif |
---|
232 | } |
---|
233 | } |
---|
234 | previousViewDepthId = viewDepthId; |
---|
235 | } |
---|
236 | if( m_cCamParsCollector.isInitialized() ) |
---|
237 | { |
---|
238 | m_cCamParsCollector.setSlice( 0 ); |
---|
239 | } |
---|
240 | // last frame |
---|
241 | for( Int viewDepthIdx = 0; viewDepthIdx < m_tDecTop.size(); viewDepthIdx++ ) |
---|
242 | { |
---|
243 | xFlushOutput( pcListPic[viewDepthIdx], viewDepthIdx ); |
---|
244 | } |
---|
245 | xDestroyDecLib(); |
---|
246 | } |
---|
247 | |
---|
248 | // ==================================================================================================================== |
---|
249 | // Protected member functions |
---|
250 | // ==================================================================================================================== |
---|
251 | |
---|
252 | Void TAppDecTop::xDestroyDecLib() |
---|
253 | { |
---|
254 | |
---|
255 | for(Int viewDepthIdx=0; viewDepthIdx<m_tVideoIOYuvReconFile.size() ; viewDepthIdx++) |
---|
256 | { |
---|
257 | if( m_tVideoIOYuvReconFile[viewDepthIdx] ) |
---|
258 | { |
---|
259 | m_tVideoIOYuvReconFile[viewDepthIdx]->close(); |
---|
260 | delete m_tVideoIOYuvReconFile[viewDepthIdx]; |
---|
261 | m_tVideoIOYuvReconFile[viewDepthIdx] = NULL ; |
---|
262 | } |
---|
263 | } |
---|
264 | #if DEBUGIMGOUT |
---|
265 | for(Int viewDepthIdx=0; viewDepthIdx<m_tVideoIOYuvReconDbgFile.size() ; viewDepthIdx++) |
---|
266 | { |
---|
267 | if( m_tVideoIOYuvReconDbgFile[viewDepthIdx] ) |
---|
268 | { |
---|
269 | m_tVideoIOYuvReconDbgFile[viewDepthIdx]->close(); |
---|
270 | delete m_tVideoIOYuvReconDbgFile[viewDepthIdx]; |
---|
271 | m_tVideoIOYuvReconDbgFile[viewDepthIdx] = NULL ; |
---|
272 | } |
---|
273 | } |
---|
274 | #endif |
---|
275 | |
---|
276 | for(Int viewDepthIdx=0; viewDepthIdx<m_tDecTop.size() ; viewDepthIdx++) |
---|
277 | { |
---|
278 | if( m_tDecTop[viewDepthIdx] ) |
---|
279 | { |
---|
280 | if( !m_useDepth && (viewDepthIdx % 2 == 1) ) |
---|
281 | { |
---|
282 | } |
---|
283 | else |
---|
284 | { |
---|
285 | m_tDecTop[viewDepthIdx]->deletePicBuffer(); |
---|
286 | m_tDecTop[viewDepthIdx]->destroy() ; |
---|
287 | } |
---|
288 | delete m_tDecTop[viewDepthIdx] ; |
---|
289 | m_tDecTop[viewDepthIdx] = NULL ; |
---|
290 | } |
---|
291 | } |
---|
292 | |
---|
293 | m_cCamParsCollector.uninit(); |
---|
294 | if( m_pScaleOffsetFile ) |
---|
295 | { |
---|
296 | ::fclose( m_pScaleOffsetFile ); |
---|
297 | } |
---|
298 | } |
---|
299 | |
---|
300 | #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER |
---|
301 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int viewDepthId, UInt tId ) |
---|
302 | #else |
---|
303 | Void TAppDecTop::xWriteOutput( TComList<TComPic*>* pcListPic, Int viewDepthId ) |
---|
304 | #endif |
---|
305 | { |
---|
306 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
307 | Int not_displayed = 0; |
---|
308 | |
---|
309 | while (iterPic != pcListPic->end()) |
---|
310 | { |
---|
311 | TComPic* pcPic = *(iterPic); |
---|
312 | if(pcPic->getOutputMark() && pcPic->getPOC() > m_pocLastDisplay[viewDepthId]) |
---|
313 | { |
---|
314 | not_displayed++; |
---|
315 | } |
---|
316 | iterPic++; |
---|
317 | } |
---|
318 | iterPic = pcListPic->begin(); |
---|
319 | |
---|
320 | while (iterPic != pcListPic->end()) |
---|
321 | { |
---|
322 | TComPic* pcPic = *(iterPic); |
---|
323 | #if PIC_CROPPING |
---|
324 | TComSPS *sps = pcPic->getSlice(0)->getSPS(); |
---|
325 | #endif |
---|
326 | |
---|
327 | #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER |
---|
328 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getSlice(0)->getSPS()->getNumReorderPics(tId) && pcPic->getPOC() > m_pocLastDisplay[viewDepthId])) |
---|
329 | #else |
---|
330 | if ( pcPic->getOutputMark() && (not_displayed > pcPic->getSlice(0)->getSPS()->getNumReorderFrames() && pcPic->getPOC() > m_pocLastDisplay[viewDepthId])) |
---|
331 | #endif |
---|
332 | { |
---|
333 | // write to file |
---|
334 | not_displayed--; |
---|
335 | if ( m_pchReconFile ) |
---|
336 | { |
---|
337 | #if PIC_CROPPING |
---|
338 | m_tVideoIOYuvReconFile[viewDepthId]->write( pcPic->getPicYuvRec(), sps->getPicCropLeftOffset(), sps->getPicCropRightOffset(), sps->getPicCropTopOffset(), sps->getPicCropBottomOffset() ); |
---|
339 | #else |
---|
340 | m_tVideoIOYuvReconFile[viewDepthId]->write( pcPic->getPicYuvRec(), pcPic->getSlice(0)->getSPS()->getPad() ); |
---|
341 | #endif |
---|
342 | } |
---|
343 | #if DEBUGIMGOUT |
---|
344 | #if PIC_CROPPING |
---|
345 | m_tVideoIOYuvReconDbgFile[viewDepthId]->write( pcPic->getPicYuvRecDbg(), sps->getPicCropLeftOffset(), sps->getPicCropRightOffset(), sps->getPicCropTopOffset(), sps->getPicCropBottomOffset() ); |
---|
346 | #else |
---|
347 | m_tVideoIOYuvReconDbgFile[viewDepthId]->write( pcPic->getPicYuvRecDbg(), pcPic->getSlice(0)->getSPS()->getPad() ); |
---|
348 | #endif |
---|
349 | #endif |
---|
350 | |
---|
351 | // update POC of display order |
---|
352 | m_pocLastDisplay[viewDepthId] = pcPic->getPOC(); |
---|
353 | |
---|
354 | // erase non-referenced picture in the reference picture list after display |
---|
355 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
356 | { |
---|
357 | #if !DYN_REF_FREE |
---|
358 | pcPic->setReconMark(false); |
---|
359 | |
---|
360 | // mark it should be extended later |
---|
361 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
362 | |
---|
363 | #else |
---|
364 | pcPic->destroy(); |
---|
365 | pcListPic->erase( iterPic ); |
---|
366 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
367 | continue; |
---|
368 | #endif |
---|
369 | } |
---|
370 | pcPic->setOutputMark(false); |
---|
371 | } |
---|
372 | |
---|
373 | iterPic++; |
---|
374 | } |
---|
375 | } |
---|
376 | |
---|
377 | /** \param pcListPic list of pictures to be written to file |
---|
378 | \todo DYN_REF_FREE should be revised |
---|
379 | */ |
---|
380 | Void TAppDecTop::xFlushOutput( TComList<TComPic*>* pcListPic, Int viewDepthId ) |
---|
381 | { |
---|
382 | if(!pcListPic) |
---|
383 | { |
---|
384 | return; |
---|
385 | } |
---|
386 | TComList<TComPic*>::iterator iterPic = pcListPic->begin(); |
---|
387 | |
---|
388 | iterPic = pcListPic->begin(); |
---|
389 | |
---|
390 | while (iterPic != pcListPic->end()) |
---|
391 | { |
---|
392 | TComPic* pcPic = *(iterPic); |
---|
393 | #if PIC_CROPPING |
---|
394 | TComSPS *sps = pcPic->getSlice(0)->getSPS(); |
---|
395 | #endif |
---|
396 | |
---|
397 | if ( pcPic->getOutputMark() ) |
---|
398 | { |
---|
399 | // write to file |
---|
400 | if ( m_pchReconFile ) |
---|
401 | { |
---|
402 | #if PIC_CROPPING |
---|
403 | m_tVideoIOYuvReconFile[viewDepthId]->write( pcPic->getPicYuvRec(), sps->getPicCropLeftOffset(), sps->getPicCropRightOffset(), sps->getPicCropTopOffset(), sps->getPicCropBottomOffset() ); |
---|
404 | #else |
---|
405 | m_tVideoIOYuvReconFile[viewDepthId]->write( pcPic->getPicYuvRec(), pcPic->getSlice(0)->getSPS()->getPad() ); |
---|
406 | #endif |
---|
407 | } |
---|
408 | #if DEBUGIMGOUT |
---|
409 | #if PIC_CROPPING |
---|
410 | m_tVideoIOYuvReconDbgFile[viewDepthId]->write( pcPic->getPicYuvRecDbg(), sps->getPicCropLeftOffset(), sps->getPicCropRightOffset(), sps->getPicCropTopOffset(), sps->getPicCropBottomOffset() ); |
---|
411 | #else |
---|
412 | m_tVideoIOYuvReconDbgFile[viewDepthId]->write( pcPic->getPicYuvRecDbg(), pcPic->getSlice(0)->getSPS()->getPad() ); |
---|
413 | #endif |
---|
414 | #endif |
---|
415 | |
---|
416 | // update POC of display order |
---|
417 | m_pocLastDisplay[viewDepthId] = pcPic->getPOC(); |
---|
418 | |
---|
419 | // erase non-referenced picture in the reference picture list after display |
---|
420 | if ( !pcPic->getSlice(0)->isReferenced() && pcPic->getReconMark() == true ) |
---|
421 | { |
---|
422 | #if !DYN_REF_FREE |
---|
423 | pcPic->setReconMark(false); |
---|
424 | |
---|
425 | // mark it should be extended later |
---|
426 | pcPic->getPicYuvRec()->setBorderExtension( false ); |
---|
427 | |
---|
428 | #else |
---|
429 | pcPic->destroy(); |
---|
430 | pcListPic->erase( iterPic ); |
---|
431 | iterPic = pcListPic->begin(); // to the beginning, non-efficient way, have to be revised! |
---|
432 | continue; |
---|
433 | #endif |
---|
434 | } |
---|
435 | pcPic->setOutputMark(false); |
---|
436 | } |
---|
437 | |
---|
438 | iterPic++; |
---|
439 | } |
---|
440 | pcListPic->clear(); |
---|
441 | m_pocLastDisplay[viewDepthId] = -MAX_INT; |
---|
442 | } |
---|
443 | #if VIDYO_VPS_INTEGRATION |
---|
444 | Void TAppDecTop::increaseNumberOfViews ( UInt layerId, UInt viewId, UInt isDepth ) |
---|
445 | #else |
---|
446 | Void TAppDecTop::increaseNumberOfViews ( Int newNumberOfViewDepth ) |
---|
447 | #endif |
---|
448 | { |
---|
449 | #if VIDYO_VPS_INTEGRATION |
---|
450 | Int newNumberOfViewDepth = layerId + 1; |
---|
451 | #endif |
---|
452 | if ( m_outputBitDepth == 0 ) |
---|
453 | { |
---|
454 | m_outputBitDepth = g_uiBitDepth + g_uiBitIncrement; |
---|
455 | } |
---|
456 | #if !VIDYO_VPS_INTEGRATION |
---|
457 | Int viewId = (newNumberOfViewDepth-1)>>1; // coding order T0D0T1D1T2D2 |
---|
458 | Bool isDepth = ((newNumberOfViewDepth % 2) == 0); // coding order T0D0T1D1T2D2 |
---|
459 | #endif |
---|
460 | if( isDepth ) |
---|
461 | m_useDepth = true; |
---|
462 | |
---|
463 | #if FIX_DECODING_WO_WRITING |
---|
464 | if ( m_pchReconFile ) |
---|
465 | { |
---|
466 | #endif |
---|
467 | while( m_tVideoIOYuvReconFile.size() < newNumberOfViewDepth) |
---|
468 | { |
---|
469 | m_tVideoIOYuvReconFile.push_back(new TVideoIOYuv); |
---|
470 | Char buffer[4]; |
---|
471 | #if VIDYO_VPS_INTEGRATION |
---|
472 | sprintf(buffer,"_%i", viewId ); |
---|
473 | #else |
---|
474 | sprintf(buffer,"_%i", (Int)(m_tVideoIOYuvReconFile.size()-1) / 2 ); |
---|
475 | #endif |
---|
476 | Char* nextFilename = NULL; |
---|
477 | #if VIDYO_VPS_INTEGRATION |
---|
478 | if( isDepth) |
---|
479 | #else |
---|
480 | if( (m_tVideoIOYuvReconFile.size() % 2) == 0 ) |
---|
481 | #endif |
---|
482 | { |
---|
483 | Char* pchTempFilename = NULL; |
---|
484 | xAppendToFileNameEnd( m_pchReconFile, "_depth", pchTempFilename); |
---|
485 | xAppendToFileNameEnd( pchTempFilename, buffer, nextFilename); |
---|
486 | free ( pchTempFilename ); |
---|
487 | } |
---|
488 | else |
---|
489 | { |
---|
490 | xAppendToFileNameEnd( m_pchReconFile, buffer, nextFilename); |
---|
491 | } |
---|
492 | #if !VIDYO_VPS_INTEGRATION |
---|
493 | if( isDepth || ( !isDepth && (m_tVideoIOYuvReconFile.size() % 2) == 1 ) ) |
---|
494 | #endif |
---|
495 | { |
---|
496 | m_tVideoIOYuvReconFile.back()->open( nextFilename, true, m_outputBitDepth, g_uiBitDepth + g_uiBitIncrement ); |
---|
497 | } |
---|
498 | free ( nextFilename ); |
---|
499 | } |
---|
500 | #if FIX_DECODING_WO_WRITING |
---|
501 | } |
---|
502 | #endif |
---|
503 | #if DEBUGIMGOUT |
---|
504 | while( m_tVideoIOYuvReconDbgFile.size() < newNumberOfViewDepth) |
---|
505 | { |
---|
506 | m_tVideoIOYuvReconDbgFile.push_back(new TVideoIOYuv); |
---|
507 | Char buffer[4]; |
---|
508 | sprintf(buffer,"_%i", (Int)(m_tVideoIOYuvReconDbgFile.size()-1) / 2 ); |
---|
509 | Char* nextFilename = NULL; |
---|
510 | if( (m_tVideoIOYuvReconDbgFile.size() % 2) == 0 ) |
---|
511 | { |
---|
512 | Char* pchTempFilename = NULL; |
---|
513 | xAppendToFileNameEnd( "DebugImg.yuv", "_depth", pchTempFilename); |
---|
514 | xAppendToFileNameEnd( pchTempFilename, buffer, nextFilename); |
---|
515 | free ( pchTempFilename ); |
---|
516 | } |
---|
517 | else |
---|
518 | { |
---|
519 | xAppendToFileNameEnd( "DebugImg.yuv", buffer, nextFilename); |
---|
520 | } |
---|
521 | if( isDepth || ( !isDepth && (m_tVideoIOYuvReconDbgFile.size() % 2) == 1 ) ) |
---|
522 | { |
---|
523 | m_tVideoIOYuvReconDbgFile.back()->open( nextFilename, true, m_outputBitDepth, g_uiBitDepth + g_uiBitIncrement ); |
---|
524 | } |
---|
525 | free ( nextFilename ); |
---|
526 | } |
---|
527 | #endif |
---|
528 | while( m_pocLastDisplay.size() < newNumberOfViewDepth ) |
---|
529 | { |
---|
530 | m_pocLastDisplay.push_back(-MAX_INT+m_iSkipFrame); |
---|
531 | } |
---|
532 | while( m_tDecTop.size() < newNumberOfViewDepth) |
---|
533 | { |
---|
534 | m_tDecTop.push_back(new TDecTop); |
---|
535 | #if !VIDYO_VPS_INTEGRATION |
---|
536 | if( isDepth || ( !isDepth && (m_tVideoIOYuvReconFile.size() % 2) == 1 ) ) |
---|
537 | { |
---|
538 | #endif |
---|
539 | m_tDecTop.back()->create(); |
---|
540 | m_tDecTop.back()->init( this, newNumberOfViewDepth == 1); |
---|
541 | m_tDecTop.back()->setViewId( viewId ); |
---|
542 | m_tDecTop.back()->setIsDepth( isDepth ); |
---|
543 | m_tDecTop.back()->setPictureDigestEnabled(m_pictureDigestEnabled); |
---|
544 | m_tDecTop.back()->setCamParsCollector( &m_cCamParsCollector ); |
---|
545 | #if !VIDYO_VPS_INTEGRATION |
---|
546 | } |
---|
547 | #endif |
---|
548 | } |
---|
549 | } |
---|
550 | |
---|
551 | TDecTop* TAppDecTop::getTDecTop( Int viewId, Bool isDepth ) |
---|
552 | { |
---|
553 | return m_tDecTop[(isDepth ? 1 : 0) + viewId * 2]; // coding order T0D0T1D1T2D2 |
---|
554 | } |
---|
555 | |
---|
556 | std::vector<TComPic*> TAppDecTop::getInterViewRefPics( Int viewId, Int poc, Bool isDepth, TComSPS* sps ) |
---|
557 | { |
---|
558 | std::vector<TComPic*> apcRefPics( sps->getNumberOfUsableInterViewRefs(), (TComPic*)NULL ); |
---|
559 | for( Int k = 0; k < sps->getNumberOfUsableInterViewRefs(); k++ ) |
---|
560 | { |
---|
561 | TComPic* pcRefPic = xGetPicFromView( sps->getUsableInterViewRef( k ) + viewId, poc, isDepth ); |
---|
562 | assert( pcRefPic != NULL ); |
---|
563 | apcRefPics[k] = pcRefPic; |
---|
564 | } |
---|
565 | return apcRefPics; |
---|
566 | } |
---|
567 | |
---|
568 | TComPic* TAppDecTop::xGetPicFromView( Int viewId, Int poc, Bool isDepth ) |
---|
569 | { |
---|
570 | assert( ( viewId >= 0 ) ); |
---|
571 | |
---|
572 | TComList<TComPic*>* apcListPic = getTDecTop( viewId, isDepth )->getListPic(); |
---|
573 | TComPic* pcPic = NULL; |
---|
574 | for( TComList<TComPic*>::iterator it=apcListPic->begin(); it!=apcListPic->end(); it++ ) |
---|
575 | { |
---|
576 | if( (*it)->getPOC() == poc ) |
---|
577 | { |
---|
578 | pcPic = *it; |
---|
579 | break; |
---|
580 | } |
---|
581 | } |
---|
582 | return pcPic; |
---|
583 | } |
---|
584 | |
---|
585 | #if VSP_N |
---|
586 | Void TAppDecTop::storeVSPInBuffer(TComPic* pcPicVSP, TComPic* pcPicAvail, Int iCodedViewIdx, Int iCoddedViewOrderIdx, Int iCurPoc, Bool bDepth) |
---|
587 | { |
---|
588 | //first view does not have VSP |
---|
589 | #if VSP_TEXT_ONLY |
---|
590 | if((iCodedViewIdx == 0)||(bDepth)) |
---|
591 | #else |
---|
592 | if((iCodedViewIdx == 0)) |
---|
593 | #endif |
---|
594 | return; |
---|
595 | pcPicVSP->getSlice(0)->setPOC( iCurPoc ); |
---|
596 | Int iNeighborViewId = 0; |
---|
597 | Bool bRenderFromLeft; |
---|
598 | //check if the neighboring view is situated to the left of the current view |
---|
599 | bRenderFromLeft = ((iCoddedViewOrderIdx)>0); |
---|
600 | //pointers to buffers |
---|
601 | TComPicYuv* pcPicYuvVideo = getPicFromView(iNeighborViewId, iCurPoc, bDepth)->getPicYuvRec(); |
---|
602 | TComPicYuv* pcPicYuvDepth = getPicFromView(iNeighborViewId, iCurPoc, true)->getPicYuvRec(); |
---|
603 | TComPicYuv* pcPicYuvVSP = pcPicVSP->getPicYuvRec(); |
---|
604 | TComPicYuv* pcPicYuvAvail = pcPicAvail->getPicYuvRec(); |
---|
605 | //verifying buffers |
---|
606 | AOF(pcPicYuvVideo); |
---|
607 | AOF(pcPicYuvDepth); |
---|
608 | AOF(pcPicYuvVSP); |
---|
609 | AOF(pcPicYuvAvail); |
---|
610 | |
---|
611 | TComPic* pcPic = getPicFromView( iCodedViewIdx, iCurPoc, bDepth ); |
---|
612 | pcPic->setPicYuvSynth( pcPicYuvVSP ); |
---|
613 | pcPic->setPicYuvAvail( pcPicYuvAvail ); |
---|
614 | |
---|
615 | //setting look-up table |
---|
616 | #if 0 |
---|
617 | m_cVSPRendererTop.setShiftLUTs( |
---|
618 | m_cCamParsCollector.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx], |
---|
619 | m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx], |
---|
620 | m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx], |
---|
621 | m_cCamParsCollector.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx], |
---|
622 | m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx], |
---|
623 | m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx], |
---|
624 | -1 |
---|
625 | ); |
---|
626 | #else |
---|
627 | #if NTT_SUBPEL |
---|
628 | m_cVSPRendererTop.setShiftLUTs( |
---|
629 | m_cCamParsCollector.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx], |
---|
630 | m_cCamParsCollector.getBaseViewIPelLUT ()[iNeighborViewId][iCodedViewIdx], |
---|
631 | NULL, |
---|
632 | m_cCamParsCollector.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx], |
---|
633 | m_cCamParsCollector.getBaseViewIPelLUT ()[iNeighborViewId][iCodedViewIdx], |
---|
634 | NULL, |
---|
635 | -1 |
---|
636 | ); |
---|
637 | m_cVSPRendererTop.setFposLUTs( |
---|
638 | m_cCamParsCollector.getBaseViewFPosLUT()[iNeighborViewId][iCodedViewIdx], |
---|
639 | m_cCamParsCollector.getBaseViewFPosLUT()[iNeighborViewId][iCodedViewIdx] |
---|
640 | ); |
---|
641 | #else |
---|
642 | m_cVSPRendererTop.setShiftLUTs( |
---|
643 | m_cCamParsCollector.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx], |
---|
644 | m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx], |
---|
645 | NULL, |
---|
646 | m_cCamParsCollector.getBaseViewShiftLUTD()[iNeighborViewId][iCodedViewIdx], |
---|
647 | m_cCamParsCollector.getBaseViewShiftLUTI()[iNeighborViewId][iCodedViewIdx], |
---|
648 | NULL, |
---|
649 | -1 |
---|
650 | ); |
---|
651 | #endif |
---|
652 | #endif |
---|
653 | |
---|
654 | #if NTT_SUBPEL |
---|
655 | m_cVSPRendererTop.setInterpolationMode( (bDepth ? 0 : 5) ); |
---|
656 | #endif |
---|
657 | |
---|
658 | //extrapolate from view iNeighborViewId to the current view, storing in the VSP buffer |
---|
659 | //m_cVSPRendererTop.extrapolateView(pcPicYuvVideo,pcPicYuvDepth, pcPicYuvVSP, bRenderFromLeft); |
---|
660 | m_cVSPRendererTop.extrapolateAvailabilityView(pcPicYuvVideo,pcPicYuvDepth, pcPicYuvVSP, pcPicYuvAvail, bRenderFromLeft); |
---|
661 | |
---|
662 | // mark it should be extended |
---|
663 | pcPicVSP->getPicYuvRec()->setBorderExtension(false); |
---|
664 | pcPicVSP->getPicYuvRec()->extendPicBorder(); //will extend the border for prediction using pixels outside the frame |
---|
665 | pcPicAvail->getPicYuvRec()->setBorderExtension(false); |
---|
666 | pcPicAvail->getPicYuvRec()->extendPicBorder(); |
---|
667 | #if VSP_N_DUMP |
---|
668 | { |
---|
669 | Char acFilenameBase[1024]; |
---|
670 | ::sprintf(acFilenameBase,"VSP_dec_%sv%d_%dx%d_%04d.yuv",(bDepth?"D":"T"),iCodedViewIdx,pcPicYuvVSP->getWidth(), pcPicYuvVSP->getHeight(), iCurPoc); |
---|
671 | pcPicYuvVSP->dump(acFilenameBase,0); |
---|
672 | //pcPicYuvAvail->dump(acFilenameBase,iCurPoc!=0); |
---|
673 | } |
---|
674 | #endif |
---|
675 | } |
---|
676 | #endif |
---|
677 | |
---|
678 | //! \} |
---|