1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** |
---|
35 | \file SEIread.cpp |
---|
36 | \brief reading functionality for SEI messages |
---|
37 | */ |
---|
38 | |
---|
39 | #include "TLibCommon/CommonDef.h" |
---|
40 | #include "TLibCommon/TComBitStream.h" |
---|
41 | #include "TLibCommon/SEI.h" |
---|
42 | #include "TLibCommon/TComSlice.h" |
---|
43 | #include "SyntaxElementParser.h" |
---|
44 | #include "SEIread.h" |
---|
45 | |
---|
46 | //! \ingroup TLibDecoder |
---|
47 | //! \{ |
---|
48 | |
---|
49 | #if ENC_DEC_TRACE |
---|
50 | Void xTraceSEIHeader() |
---|
51 | { |
---|
52 | fprintf( g_hTrace, "=========== SEI message ===========\n"); |
---|
53 | } |
---|
54 | |
---|
55 | Void xTraceSEIMessageType(SEI::PayloadType payloadType) |
---|
56 | { |
---|
57 | switch (payloadType) |
---|
58 | { |
---|
59 | case SEI::DECODED_PICTURE_HASH: |
---|
60 | fprintf( g_hTrace, "=========== Decoded picture hash SEI message ===========\n"); |
---|
61 | break; |
---|
62 | case SEI::USER_DATA_UNREGISTERED: |
---|
63 | fprintf( g_hTrace, "=========== User Data Unregistered SEI message ===========\n"); |
---|
64 | break; |
---|
65 | case SEI::ACTIVE_PARAMETER_SETS: |
---|
66 | fprintf( g_hTrace, "=========== Active Parameter sets SEI message ===========\n"); |
---|
67 | break; |
---|
68 | case SEI::BUFFERING_PERIOD: |
---|
69 | fprintf( g_hTrace, "=========== Buffering period SEI message ===========\n"); |
---|
70 | break; |
---|
71 | case SEI::PICTURE_TIMING: |
---|
72 | fprintf( g_hTrace, "=========== Picture timing SEI message ===========\n"); |
---|
73 | break; |
---|
74 | case SEI::RECOVERY_POINT: |
---|
75 | fprintf( g_hTrace, "=========== Recovery point SEI message ===========\n"); |
---|
76 | break; |
---|
77 | case SEI::FRAME_PACKING: |
---|
78 | fprintf( g_hTrace, "=========== Frame Packing Arrangement SEI message ===========\n"); |
---|
79 | break; |
---|
80 | case SEI::DISPLAY_ORIENTATION: |
---|
81 | fprintf( g_hTrace, "=========== Display Orientation SEI message ===========\n"); |
---|
82 | break; |
---|
83 | case SEI::TEMPORAL_LEVEL0_INDEX: |
---|
84 | fprintf( g_hTrace, "=========== Temporal Level Zero Index SEI message ===========\n"); |
---|
85 | break; |
---|
86 | case SEI::REGION_REFRESH_INFO: |
---|
87 | fprintf( g_hTrace, "=========== Gradual Decoding Refresh Information SEI message ===========\n"); |
---|
88 | break; |
---|
89 | case SEI::DECODING_UNIT_INFO: |
---|
90 | fprintf( g_hTrace, "=========== Decoding Unit Information SEI message ===========\n"); |
---|
91 | break; |
---|
92 | case SEI::TONE_MAPPING_INFO: |
---|
93 | fprintf( g_hTrace, "===========Tone Mapping Info SEI message ===========\n"); |
---|
94 | break; |
---|
95 | #if P0050_KNEE_FUNCTION_SEI |
---|
96 | case SEI::KNEE_FUNCTION_INFO: |
---|
97 | fprintf( g_hTrace, "=========== Knee Function Information SEI message ===========\n"); |
---|
98 | break; |
---|
99 | #endif |
---|
100 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
101 | case SEI::COLOUR_REMAPPING_INFO: |
---|
102 | fprintf( g_hTrace, "===========Colour Remapping Information SEI message ===========\n"); |
---|
103 | break; |
---|
104 | #endif |
---|
105 | case SEI::SOP_DESCRIPTION: |
---|
106 | fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n"); |
---|
107 | break; |
---|
108 | case SEI::SCALABLE_NESTING: |
---|
109 | fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n"); |
---|
110 | break; |
---|
111 | #if SVC_EXTENSION |
---|
112 | #if LAYERS_NOT_PRESENT_SEI |
---|
113 | case SEI::LAYERS_NOT_PRESENT: |
---|
114 | fprintf( g_hTrace, "=========== Layers Present SEI message ===========\n"); |
---|
115 | break; |
---|
116 | #endif |
---|
117 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
118 | case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS: |
---|
119 | fprintf( g_hTrace, "=========== Inter Layer Constrained Tile Sets SEI message ===========\n"); |
---|
120 | break; |
---|
121 | #endif |
---|
122 | #if SUB_BITSTREAM_PROPERTY_SEI |
---|
123 | case SEI::SUB_BITSTREAM_PROPERTY: |
---|
124 | fprintf( g_hTrace, "=========== Sub-bitstream property SEI message ===========\n"); |
---|
125 | break; |
---|
126 | #endif |
---|
127 | #if O0164_MULTI_LAYER_HRD |
---|
128 | case SEI::BSP_NESTING: |
---|
129 | fprintf( g_hTrace, "=========== Bitstream parition nesting SEI message ===========\n"); |
---|
130 | break; |
---|
131 | case SEI::BSP_INITIAL_ARRIVAL_TIME: |
---|
132 | fprintf( g_hTrace, "=========== Bitstream parition initial arrival time SEI message ===========\n"); |
---|
133 | break; |
---|
134 | #if !REMOVE_BSP_HRD_SEI |
---|
135 | case SEI::BSP_HRD: |
---|
136 | fprintf( g_hTrace, "=========== Bitstream parition HRD parameters SEI message ===========\n"); |
---|
137 | break; |
---|
138 | #endif |
---|
139 | #endif |
---|
140 | #if Q0078_ADD_LAYER_SETS |
---|
141 | case SEI::OUTPUT_LAYER_SET_NESTING: |
---|
142 | fprintf(g_hTrace, "=========== Output layer set nesting SEI message ===========\n"); |
---|
143 | break; |
---|
144 | case SEI::VPS_REWRITING: |
---|
145 | fprintf(g_hTrace, "=========== VPS rewriting SEI message ===========\n"); |
---|
146 | break; |
---|
147 | #endif |
---|
148 | #endif //SVC_EXTENSION |
---|
149 | default: |
---|
150 | fprintf( g_hTrace, "=========== Unknown SEI message ===========\n"); |
---|
151 | break; |
---|
152 | } |
---|
153 | } |
---|
154 | #endif |
---|
155 | |
---|
156 | /** |
---|
157 | * unmarshal a single SEI message from bitstream bs |
---|
158 | */ |
---|
159 | #if LAYERS_NOT_PRESENT_SEI |
---|
160 | void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps) |
---|
161 | #else |
---|
162 | void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps) |
---|
163 | #endif |
---|
164 | { |
---|
165 | setBitstream(bs); |
---|
166 | |
---|
167 | assert(!m_pcBitstream->getNumBitsUntilByteAligned()); |
---|
168 | do |
---|
169 | { |
---|
170 | #if LAYERS_NOT_PRESENT_SEI |
---|
171 | xReadSEImessage(seis, nalUnitType, vps, sps); |
---|
172 | #else |
---|
173 | xReadSEImessage(seis, nalUnitType, sps); |
---|
174 | #endif |
---|
175 | /* SEI messages are an integer number of bytes, something has failed |
---|
176 | * in the parsing if bitstream not byte-aligned */ |
---|
177 | assert(!m_pcBitstream->getNumBitsUntilByteAligned()); |
---|
178 | } while (m_pcBitstream->getNumBitsLeft() > 8); |
---|
179 | |
---|
180 | UInt rbspTrailingBits; |
---|
181 | READ_CODE(8, rbspTrailingBits, "rbsp_trailing_bits"); |
---|
182 | assert(rbspTrailingBits == 0x80); |
---|
183 | } |
---|
184 | |
---|
185 | #if O0164_MULTI_LAYER_HRD |
---|
186 | #if LAYERS_NOT_PRESENT_SEI |
---|
187 | Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, const SEIScalableNesting *nestingSei, const SEIBspNesting *bspNestingSei) |
---|
188 | #else |
---|
189 | Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps, const SEIScalableNesting *nestingSei) |
---|
190 | #endif |
---|
191 | #else |
---|
192 | #if LAYERS_NOT_PRESENT_SEI |
---|
193 | Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps) |
---|
194 | #else |
---|
195 | Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps) |
---|
196 | #endif |
---|
197 | #endif |
---|
198 | { |
---|
199 | #if ENC_DEC_TRACE |
---|
200 | xTraceSEIHeader(); |
---|
201 | #endif |
---|
202 | Int payloadType = 0; |
---|
203 | UInt val = 0; |
---|
204 | |
---|
205 | do |
---|
206 | { |
---|
207 | READ_CODE (8, val, "payload_type"); |
---|
208 | payloadType += val; |
---|
209 | } while (val==0xFF); |
---|
210 | |
---|
211 | UInt payloadSize = 0; |
---|
212 | do |
---|
213 | { |
---|
214 | READ_CODE (8, val, "payload_size"); |
---|
215 | payloadSize += val; |
---|
216 | } while (val==0xFF); |
---|
217 | |
---|
218 | #if ENC_DEC_TRACE |
---|
219 | xTraceSEIMessageType((SEI::PayloadType)payloadType); |
---|
220 | #endif |
---|
221 | |
---|
222 | /* extract the payload for this single SEI message. |
---|
223 | * This allows greater safety in erroneous parsing of an SEI message |
---|
224 | * from affecting subsequent messages. |
---|
225 | * After parsing the payload, bs needs to be restored as the primary |
---|
226 | * bitstream. |
---|
227 | */ |
---|
228 | TComInputBitstream *bs = getBitstream(); |
---|
229 | setBitstream(bs->extractSubstream(payloadSize * 8)); |
---|
230 | |
---|
231 | SEI *sei = NULL; |
---|
232 | |
---|
233 | if(nalUnitType == NAL_UNIT_PREFIX_SEI) |
---|
234 | { |
---|
235 | switch (payloadType) |
---|
236 | { |
---|
237 | case SEI::USER_DATA_UNREGISTERED: |
---|
238 | sei = new SEIuserDataUnregistered; |
---|
239 | xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize); |
---|
240 | break; |
---|
241 | case SEI::ACTIVE_PARAMETER_SETS: |
---|
242 | sei = new SEIActiveParameterSets; |
---|
243 | xParseSEIActiveParameterSets((SEIActiveParameterSets&) *sei, payloadSize); |
---|
244 | break; |
---|
245 | case SEI::DECODING_UNIT_INFO: |
---|
246 | if (!sps) |
---|
247 | { |
---|
248 | printf ("Warning: Found Decoding unit SEI message, but no active SPS is available. Ignoring."); |
---|
249 | } |
---|
250 | else |
---|
251 | { |
---|
252 | sei = new SEIDecodingUnitInfo; |
---|
253 | xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps); |
---|
254 | } |
---|
255 | break; |
---|
256 | case SEI::BUFFERING_PERIOD: |
---|
257 | if (!sps) |
---|
258 | { |
---|
259 | printf ("Warning: Found Buffering period SEI message, but no active SPS is available. Ignoring."); |
---|
260 | } |
---|
261 | else |
---|
262 | { |
---|
263 | sei = new SEIBufferingPeriod; |
---|
264 | xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps); |
---|
265 | } |
---|
266 | break; |
---|
267 | case SEI::PICTURE_TIMING: |
---|
268 | if (!sps) |
---|
269 | { |
---|
270 | printf ("Warning: Found Picture timing SEI message, but no active SPS is available. Ignoring."); |
---|
271 | } |
---|
272 | else |
---|
273 | { |
---|
274 | sei = new SEIPictureTiming; |
---|
275 | xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps); |
---|
276 | } |
---|
277 | break; |
---|
278 | case SEI::RECOVERY_POINT: |
---|
279 | sei = new SEIRecoveryPoint; |
---|
280 | xParseSEIRecoveryPoint((SEIRecoveryPoint&) *sei, payloadSize); |
---|
281 | break; |
---|
282 | case SEI::FRAME_PACKING: |
---|
283 | sei = new SEIFramePacking; |
---|
284 | xParseSEIFramePacking((SEIFramePacking&) *sei, payloadSize); |
---|
285 | break; |
---|
286 | case SEI::DISPLAY_ORIENTATION: |
---|
287 | sei = new SEIDisplayOrientation; |
---|
288 | xParseSEIDisplayOrientation((SEIDisplayOrientation&) *sei, payloadSize); |
---|
289 | break; |
---|
290 | case SEI::TEMPORAL_LEVEL0_INDEX: |
---|
291 | sei = new SEITemporalLevel0Index; |
---|
292 | xParseSEITemporalLevel0Index((SEITemporalLevel0Index&) *sei, payloadSize); |
---|
293 | break; |
---|
294 | case SEI::REGION_REFRESH_INFO: |
---|
295 | sei = new SEIGradualDecodingRefreshInfo; |
---|
296 | xParseSEIGradualDecodingRefreshInfo((SEIGradualDecodingRefreshInfo&) *sei, payloadSize); |
---|
297 | break; |
---|
298 | case SEI::TONE_MAPPING_INFO: |
---|
299 | sei = new SEIToneMappingInfo; |
---|
300 | xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize); |
---|
301 | break; |
---|
302 | #if P0050_KNEE_FUNCTION_SEI |
---|
303 | case SEI::KNEE_FUNCTION_INFO: |
---|
304 | sei = new SEIKneeFunctionInfo; |
---|
305 | xParseSEIKneeFunctionInfo((SEIKneeFunctionInfo&) *sei, payloadSize); |
---|
306 | break; |
---|
307 | #endif |
---|
308 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
309 | case SEI::COLOUR_REMAPPING_INFO: |
---|
310 | sei = new SEIColourRemappingInfo; |
---|
311 | xParseSEIColourRemappingInfo((SEIColourRemappingInfo&) *sei, payloadSize); |
---|
312 | break; |
---|
313 | #endif |
---|
314 | case SEI::SOP_DESCRIPTION: |
---|
315 | sei = new SEISOPDescription; |
---|
316 | xParseSEISOPDescription((SEISOPDescription&) *sei, payloadSize); |
---|
317 | break; |
---|
318 | case SEI::SCALABLE_NESTING: |
---|
319 | sei = new SEIScalableNesting; |
---|
320 | #if LAYERS_NOT_PRESENT_SEI |
---|
321 | xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, vps, sps); |
---|
322 | #else |
---|
323 | xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps); |
---|
324 | #endif |
---|
325 | break; |
---|
326 | #if SVC_EXTENSION |
---|
327 | #if LAYERS_NOT_PRESENT_SEI |
---|
328 | case SEI::LAYERS_NOT_PRESENT: |
---|
329 | if (!vps) |
---|
330 | { |
---|
331 | printf ("Warning: Found Layers not present SEI message, but no active VPS is available. Ignoring."); |
---|
332 | } |
---|
333 | else |
---|
334 | { |
---|
335 | sei = new SEILayersNotPresent; |
---|
336 | xParseSEILayersNotPresent((SEILayersNotPresent&) *sei, payloadSize, vps); |
---|
337 | } |
---|
338 | break; |
---|
339 | #endif |
---|
340 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
341 | case SEI::INTER_LAYER_CONSTRAINED_TILE_SETS: |
---|
342 | sei = new SEIInterLayerConstrainedTileSets; |
---|
343 | xParseSEIInterLayerConstrainedTileSets((SEIInterLayerConstrainedTileSets&) *sei, payloadSize); |
---|
344 | break; |
---|
345 | #endif |
---|
346 | #if SUB_BITSTREAM_PROPERTY_SEI |
---|
347 | case SEI::SUB_BITSTREAM_PROPERTY: |
---|
348 | sei = new SEISubBitstreamProperty; |
---|
349 | xParseSEISubBitstreamProperty((SEISubBitstreamProperty&) *sei); |
---|
350 | break; |
---|
351 | #endif |
---|
352 | #if O0164_MULTI_LAYER_HRD |
---|
353 | case SEI::BSP_NESTING: |
---|
354 | sei = new SEIBspNesting; |
---|
355 | #if LAYERS_NOT_PRESENT_SEI |
---|
356 | xParseSEIBspNesting((SEIBspNesting&) *sei, nalUnitType, vps, sps, *nestingSei); |
---|
357 | #else |
---|
358 | xParseSEIBspNesting((SEIBspNesting&) *sei, nalUnitType, sps, *nestingSei); |
---|
359 | #endif |
---|
360 | break; |
---|
361 | case SEI::BSP_INITIAL_ARRIVAL_TIME: |
---|
362 | sei = new SEIBspInitialArrivalTime; |
---|
363 | xParseSEIBspInitialArrivalTime((SEIBspInitialArrivalTime&) *sei, vps, sps, *nestingSei, *bspNestingSei); |
---|
364 | break; |
---|
365 | #if !REMOVE_BSP_HRD_SEI |
---|
366 | case SEI::BSP_HRD: |
---|
367 | sei = new SEIBspHrd; |
---|
368 | xParseSEIBspHrd((SEIBspHrd&) *sei, sps, *nestingSei); |
---|
369 | break; |
---|
370 | #endif |
---|
371 | #endif |
---|
372 | #if Q0078_ADD_LAYER_SETS |
---|
373 | case SEI::OUTPUT_LAYER_SET_NESTING: |
---|
374 | sei = new SEIOutputLayerSetNesting; |
---|
375 | #if LAYERS_NOT_PRESENT_SEI |
---|
376 | xParseSEIOutputLayerSetNesting((SEIOutputLayerSetNesting&)*sei, nalUnitType, vps, sps); |
---|
377 | #else |
---|
378 | xParseSEIOutputLayerSetNesting((SEIOutputLayerSetNesting&)*sei, nalUnitType, sps); |
---|
379 | #endif |
---|
380 | break; |
---|
381 | case SEI::VPS_REWRITING: |
---|
382 | sei = new SEIVPSRewriting; |
---|
383 | xParseSEIVPSRewriting((SEIVPSRewriting&)*sei); |
---|
384 | break; |
---|
385 | #endif |
---|
386 | #if Q0189_TMVP_CONSTRAINTS |
---|
387 | case SEI::TMVP_CONSTRAINTS: |
---|
388 | sei = new SEITMVPConstrains; |
---|
389 | xParseSEITMVPConstraints((SEITMVPConstrains&) *sei, payloadSize); |
---|
390 | break; |
---|
391 | #endif |
---|
392 | #if Q0247_FRAME_FIELD_INFO |
---|
393 | case SEI::FRAME_FIELD_INFO: |
---|
394 | sei = new SEIFrameFieldInfo; |
---|
395 | xParseSEIFrameFieldInfo ((SEIFrameFieldInfo&) *sei, payloadSize); |
---|
396 | break; |
---|
397 | #endif |
---|
398 | #endif //SVC_EXTENSION |
---|
399 | break; |
---|
400 | default: |
---|
401 | for (UInt i = 0; i < payloadSize; i++) |
---|
402 | { |
---|
403 | UInt seiByte; |
---|
404 | READ_CODE (8, seiByte, "unknown prefix SEI payload byte"); |
---|
405 | } |
---|
406 | printf ("Unknown prefix SEI message (payloadType = %d) was found!\n", payloadType); |
---|
407 | } |
---|
408 | } |
---|
409 | else |
---|
410 | { |
---|
411 | switch (payloadType) |
---|
412 | { |
---|
413 | case SEI::USER_DATA_UNREGISTERED: |
---|
414 | sei = new SEIuserDataUnregistered; |
---|
415 | xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize); |
---|
416 | break; |
---|
417 | case SEI::DECODED_PICTURE_HASH: |
---|
418 | sei = new SEIDecodedPictureHash; |
---|
419 | xParseSEIDecodedPictureHash((SEIDecodedPictureHash&) *sei, payloadSize); |
---|
420 | break; |
---|
421 | default: |
---|
422 | for (UInt i = 0; i < payloadSize; i++) |
---|
423 | { |
---|
424 | UInt seiByte; |
---|
425 | READ_CODE (8, seiByte, "unknown suffix SEI payload byte"); |
---|
426 | } |
---|
427 | printf ("Unknown suffix SEI message (payloadType = %d) was found!\n", payloadType); |
---|
428 | } |
---|
429 | } |
---|
430 | if (sei != NULL) |
---|
431 | { |
---|
432 | seis.push_back(sei); |
---|
433 | } |
---|
434 | |
---|
435 | /* By definition the underlying bitstream terminates in a byte-aligned manner. |
---|
436 | * 1. Extract all bar the last MIN(bitsremaining,nine) bits as reserved_payload_extension_data |
---|
437 | * 2. Examine the final 8 bits to determine the payload_bit_equal_to_one marker |
---|
438 | * 3. Extract the remainingreserved_payload_extension_data bits. |
---|
439 | * |
---|
440 | * If there are fewer than 9 bits available, extract them. |
---|
441 | */ |
---|
442 | Int payloadBitsRemaining = getBitstream()->getNumBitsLeft(); |
---|
443 | if (payloadBitsRemaining) /* more_data_in_payload() */ |
---|
444 | { |
---|
445 | for (; payloadBitsRemaining > 9; payloadBitsRemaining--) |
---|
446 | { |
---|
447 | UInt reservedPayloadExtensionData; |
---|
448 | READ_CODE (1, reservedPayloadExtensionData, "reserved_payload_extension_data"); |
---|
449 | } |
---|
450 | |
---|
451 | /* 2 */ |
---|
452 | Int finalBits = getBitstream()->peekBits(payloadBitsRemaining); |
---|
453 | Int finalPayloadBits = 0; |
---|
454 | for (Int mask = 0xff; finalBits & (mask >> finalPayloadBits); finalPayloadBits++) |
---|
455 | { |
---|
456 | continue; |
---|
457 | } |
---|
458 | |
---|
459 | /* 3 */ |
---|
460 | for (; payloadBitsRemaining > 9 - finalPayloadBits; payloadBitsRemaining--) |
---|
461 | { |
---|
462 | UInt reservedPayloadExtensionData; |
---|
463 | READ_FLAG (reservedPayloadExtensionData, "reserved_payload_extension_data"); |
---|
464 | } |
---|
465 | |
---|
466 | UInt dummy; |
---|
467 | READ_FLAG (dummy, "payload_bit_equal_to_one"); payloadBitsRemaining--; |
---|
468 | while (payloadBitsRemaining) |
---|
469 | { |
---|
470 | READ_FLAG (dummy, "payload_bit_equal_to_zero"); payloadBitsRemaining--; |
---|
471 | } |
---|
472 | } |
---|
473 | |
---|
474 | /* restore primary bitstream for sei_message */ |
---|
475 | getBitstream()->deleteFifo(); |
---|
476 | delete getBitstream(); |
---|
477 | setBitstream(bs); |
---|
478 | } |
---|
479 | |
---|
480 | #if P0138_USE_ALT_CPB_PARAMS_FLAG |
---|
481 | /** |
---|
482 | * Check if SEI message contains payload extension |
---|
483 | */ |
---|
484 | Bool SEIReader::xPayloadExtensionPresent() |
---|
485 | { |
---|
486 | Int payloadBitsRemaining = getBitstream()->getNumBitsLeft(); |
---|
487 | Bool payloadExtensionPresent = false; |
---|
488 | |
---|
489 | if (payloadBitsRemaining > 8) |
---|
490 | { |
---|
491 | payloadExtensionPresent = true; |
---|
492 | } |
---|
493 | else |
---|
494 | { |
---|
495 | Int finalBits = getBitstream()->peekBits(payloadBitsRemaining); |
---|
496 | while (payloadBitsRemaining && (finalBits & 1) == 0) |
---|
497 | { |
---|
498 | payloadBitsRemaining--; |
---|
499 | finalBits >>= 1; |
---|
500 | } |
---|
501 | payloadBitsRemaining--; |
---|
502 | if (payloadBitsRemaining > 0) |
---|
503 | { |
---|
504 | payloadExtensionPresent = true; |
---|
505 | } |
---|
506 | } |
---|
507 | |
---|
508 | return payloadExtensionPresent; |
---|
509 | } |
---|
510 | #endif |
---|
511 | |
---|
512 | /** |
---|
513 | * parse bitstream bs and unpack a user_data_unregistered SEI message |
---|
514 | * of payloasSize bytes into sei. |
---|
515 | */ |
---|
516 | Void SEIReader::xParseSEIuserDataUnregistered(SEIuserDataUnregistered &sei, UInt payloadSize) |
---|
517 | { |
---|
518 | assert(payloadSize >= 16); |
---|
519 | UInt val; |
---|
520 | |
---|
521 | for (UInt i = 0; i < 16; i++) |
---|
522 | { |
---|
523 | READ_CODE (8, val, "uuid_iso_iec_11578"); |
---|
524 | sei.uuid_iso_iec_11578[i] = val; |
---|
525 | } |
---|
526 | |
---|
527 | sei.userDataLength = payloadSize - 16; |
---|
528 | if (!sei.userDataLength) |
---|
529 | { |
---|
530 | sei.userData = 0; |
---|
531 | return; |
---|
532 | } |
---|
533 | |
---|
534 | sei.userData = new UChar[sei.userDataLength]; |
---|
535 | for (UInt i = 0; i < sei.userDataLength; i++) |
---|
536 | { |
---|
537 | READ_CODE (8, val, "user_data" ); |
---|
538 | sei.userData[i] = val; |
---|
539 | } |
---|
540 | } |
---|
541 | |
---|
542 | /** |
---|
543 | * parse bitstream bs and unpack a decoded picture hash SEI message |
---|
544 | * of payloadSize bytes into sei. |
---|
545 | */ |
---|
546 | Void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, UInt /*payloadSize*/) |
---|
547 | { |
---|
548 | UInt val; |
---|
549 | READ_CODE (8, val, "hash_type"); |
---|
550 | sei.method = static_cast<SEIDecodedPictureHash::Method>(val); |
---|
551 | for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++) |
---|
552 | { |
---|
553 | if(SEIDecodedPictureHash::MD5 == sei.method) |
---|
554 | { |
---|
555 | for (UInt i = 0; i < 16; i++) |
---|
556 | { |
---|
557 | READ_CODE(8, val, "picture_md5"); |
---|
558 | sei.digest[yuvIdx][i] = val; |
---|
559 | } |
---|
560 | } |
---|
561 | else if(SEIDecodedPictureHash::CRC == sei.method) |
---|
562 | { |
---|
563 | READ_CODE(16, val, "picture_crc"); |
---|
564 | sei.digest[yuvIdx][0] = val >> 8 & 0xFF; |
---|
565 | sei.digest[yuvIdx][1] = val & 0xFF; |
---|
566 | } |
---|
567 | else if(SEIDecodedPictureHash::CHECKSUM == sei.method) |
---|
568 | { |
---|
569 | READ_CODE(32, val, "picture_checksum"); |
---|
570 | sei.digest[yuvIdx][0] = (val>>24) & 0xff; |
---|
571 | sei.digest[yuvIdx][1] = (val>>16) & 0xff; |
---|
572 | sei.digest[yuvIdx][2] = (val>>8) & 0xff; |
---|
573 | sei.digest[yuvIdx][3] = val & 0xff; |
---|
574 | } |
---|
575 | } |
---|
576 | } |
---|
577 | Void SEIReader::xParseSEIActiveParameterSets(SEIActiveParameterSets& sei, UInt /*payloadSize*/) |
---|
578 | { |
---|
579 | UInt val; |
---|
580 | READ_CODE(4, val, "active_video_parameter_set_id"); sei.activeVPSId = val; |
---|
581 | READ_FLAG( val, "self_contained_cvs_flag"); sei.m_selfContainedCvsFlag = val ? true : false; |
---|
582 | READ_FLAG( val, "no_parameter_set_update_flag"); sei.m_noParameterSetUpdateFlag = val ? true : false; |
---|
583 | READ_UVLC( val, "num_sps_ids_minus1"); sei.numSpsIdsMinus1 = val; |
---|
584 | |
---|
585 | sei.activeSeqParameterSetId.resize(sei.numSpsIdsMinus1 + 1); |
---|
586 | for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++) |
---|
587 | { |
---|
588 | READ_UVLC(val, "active_seq_parameter_set_id"); sei.activeSeqParameterSetId[i] = val; |
---|
589 | } |
---|
590 | |
---|
591 | xParseByteAlign(); |
---|
592 | } |
---|
593 | |
---|
594 | Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt /*payloadSize*/, TComSPS *sps) |
---|
595 | { |
---|
596 | UInt val; |
---|
597 | READ_UVLC(val, "decoding_unit_idx"); |
---|
598 | sei.m_decodingUnitIdx = val; |
---|
599 | |
---|
600 | TComVUI *vui = sps->getVuiParameters(); |
---|
601 | if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag()) |
---|
602 | { |
---|
603 | READ_CODE( ( vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay"); |
---|
604 | sei.m_duSptCpbRemovalDelay = val; |
---|
605 | } |
---|
606 | else |
---|
607 | { |
---|
608 | sei.m_duSptCpbRemovalDelay = 0; |
---|
609 | } |
---|
610 | READ_FLAG( val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = val ? true : false; |
---|
611 | if(sei.m_dpbOutputDuDelayPresentFlag) |
---|
612 | { |
---|
613 | READ_CODE(vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay"); |
---|
614 | sei.m_picSptDpbOutputDuDelay = val; |
---|
615 | } |
---|
616 | xParseByteAlign(); |
---|
617 | } |
---|
618 | |
---|
619 | Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt /*payloadSize*/, TComSPS *sps) |
---|
620 | { |
---|
621 | Int i, nalOrVcl; |
---|
622 | UInt code; |
---|
623 | |
---|
624 | TComVUI *pVUI = sps->getVuiParameters(); |
---|
625 | TComHRD *pHRD = pVUI->getHrdParameters(); |
---|
626 | |
---|
627 | READ_UVLC( code, "bp_seq_parameter_set_id" ); sei.m_bpSeqParameterSetId = code; |
---|
628 | if( !pHRD->getSubPicCpbParamsPresentFlag() ) |
---|
629 | { |
---|
630 | READ_FLAG( code, "irap_cpb_params_present_flag" ); sei.m_rapCpbParamsPresentFlag = code; |
---|
631 | } |
---|
632 | if( sei.m_rapCpbParamsPresentFlag ) |
---|
633 | { |
---|
634 | READ_CODE( pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" ); sei.m_cpbDelayOffset = code; |
---|
635 | READ_CODE( pHRD->getDpbOutputDelayLengthMinus1() + 1, code, "dpb_delay_offset" ); sei.m_dpbDelayOffset = code; |
---|
636 | } |
---|
637 | //read splicing flag and cpb_removal_delay_delta |
---|
638 | READ_FLAG( code, "concatenation_flag"); |
---|
639 | sei.m_concatenationFlag = code; |
---|
640 | READ_CODE( ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" ); |
---|
641 | sei.m_auCpbRemovalDelayDelta = code + 1; |
---|
642 | for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ ) |
---|
643 | { |
---|
644 | if( ( ( nalOrVcl == 0 ) && ( pHRD->getNalHrdParametersPresentFlag() ) ) || |
---|
645 | ( ( nalOrVcl == 1 ) && ( pHRD->getVclHrdParametersPresentFlag() ) ) ) |
---|
646 | { |
---|
647 | for( i = 0; i < ( pHRD->getCpbCntMinus1( 0 ) + 1 ); i ++ ) |
---|
648 | { |
---|
649 | READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay" ); |
---|
650 | sei.m_initialCpbRemovalDelay[i][nalOrVcl] = code; |
---|
651 | READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay_offset" ); |
---|
652 | sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl] = code; |
---|
653 | if( pHRD->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag ) |
---|
654 | { |
---|
655 | READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay" ); |
---|
656 | sei.m_initialAltCpbRemovalDelay[i][nalOrVcl] = code; |
---|
657 | READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay_offset" ); |
---|
658 | sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl] = code; |
---|
659 | } |
---|
660 | } |
---|
661 | } |
---|
662 | } |
---|
663 | |
---|
664 | #if P0138_USE_ALT_CPB_PARAMS_FLAG |
---|
665 | sei.m_useAltCpbParamsFlag = false; |
---|
666 | sei.m_useAltCpbParamsFlagPresent = false; |
---|
667 | if (xPayloadExtensionPresent()) |
---|
668 | { |
---|
669 | READ_FLAG (code, "use_alt_cpb_params_flag"); |
---|
670 | sei.m_useAltCpbParamsFlag = code; |
---|
671 | sei.m_useAltCpbParamsFlagPresent = true; |
---|
672 | } |
---|
673 | #endif |
---|
674 | |
---|
675 | xParseByteAlign(); |
---|
676 | } |
---|
677 | Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt /*payloadSize*/, TComSPS *sps) |
---|
678 | { |
---|
679 | Int i; |
---|
680 | UInt code; |
---|
681 | |
---|
682 | TComVUI *vui = sps->getVuiParameters(); |
---|
683 | TComHRD *hrd = vui->getHrdParameters(); |
---|
684 | |
---|
685 | if( vui->getFrameFieldInfoPresentFlag() ) |
---|
686 | { |
---|
687 | READ_CODE( 4, code, "pic_struct" ); sei.m_picStruct = code; |
---|
688 | READ_CODE( 2, code, "source_scan_type" ); sei.m_sourceScanType = code; |
---|
689 | READ_FLAG( code, "duplicate_flag" ); sei.m_duplicateFlag = ( code == 1 ? true : false ); |
---|
690 | } |
---|
691 | |
---|
692 | if( hrd->getCpbDpbDelaysPresentFlag()) |
---|
693 | { |
---|
694 | READ_CODE( ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_minus1" ); |
---|
695 | sei.m_auCpbRemovalDelay = code + 1; |
---|
696 | READ_CODE( ( hrd->getDpbOutputDelayLengthMinus1() + 1 ), code, "pic_dpb_output_delay" ); |
---|
697 | sei.m_picDpbOutputDelay = code; |
---|
698 | |
---|
699 | if(hrd->getSubPicCpbParamsPresentFlag()) |
---|
700 | { |
---|
701 | READ_CODE(hrd->getDpbOutputDelayDuLengthMinus1()+1, code, "pic_dpb_output_du_delay" ); |
---|
702 | sei.m_picDpbOutputDuDelay = code; |
---|
703 | } |
---|
704 | if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() ) |
---|
705 | { |
---|
706 | READ_UVLC( code, "num_decoding_units_minus1"); |
---|
707 | sei.m_numDecodingUnitsMinus1 = code; |
---|
708 | READ_FLAG( code, "du_common_cpb_removal_delay_flag" ); |
---|
709 | sei.m_duCommonCpbRemovalDelayFlag = code; |
---|
710 | if( sei.m_duCommonCpbRemovalDelayFlag ) |
---|
711 | { |
---|
712 | READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_common_cpb_removal_delay_minus1" ); |
---|
713 | sei.m_duCommonCpbRemovalDelayMinus1 = code; |
---|
714 | } |
---|
715 | if( sei.m_numNalusInDuMinus1 != NULL ) |
---|
716 | { |
---|
717 | delete sei.m_numNalusInDuMinus1; |
---|
718 | } |
---|
719 | sei.m_numNalusInDuMinus1 = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ]; |
---|
720 | if( sei.m_duCpbRemovalDelayMinus1 != NULL ) |
---|
721 | { |
---|
722 | delete sei.m_duCpbRemovalDelayMinus1; |
---|
723 | } |
---|
724 | sei.m_duCpbRemovalDelayMinus1 = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ]; |
---|
725 | |
---|
726 | for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ ) |
---|
727 | { |
---|
728 | READ_UVLC( code, "num_nalus_in_du_minus1"); |
---|
729 | sei.m_numNalusInDuMinus1[ i ] = code; |
---|
730 | if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) ) |
---|
731 | { |
---|
732 | READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_cpb_removal_delay_minus1" ); |
---|
733 | sei.m_duCpbRemovalDelayMinus1[ i ] = code; |
---|
734 | } |
---|
735 | } |
---|
736 | } |
---|
737 | } |
---|
738 | xParseByteAlign(); |
---|
739 | } |
---|
740 | Void SEIReader::xParseSEIRecoveryPoint(SEIRecoveryPoint& sei, UInt /*payloadSize*/) |
---|
741 | { |
---|
742 | Int iCode; |
---|
743 | UInt uiCode; |
---|
744 | READ_SVLC( iCode, "recovery_poc_cnt" ); sei.m_recoveryPocCnt = iCode; |
---|
745 | READ_FLAG( uiCode, "exact_matching_flag" ); sei.m_exactMatchingFlag = uiCode; |
---|
746 | READ_FLAG( uiCode, "broken_link_flag" ); sei.m_brokenLinkFlag = uiCode; |
---|
747 | xParseByteAlign(); |
---|
748 | } |
---|
749 | Void SEIReader::xParseSEIFramePacking(SEIFramePacking& sei, UInt /*payloadSize*/) |
---|
750 | { |
---|
751 | UInt val; |
---|
752 | READ_UVLC( val, "frame_packing_arrangement_id" ); sei.m_arrangementId = val; |
---|
753 | READ_FLAG( val, "frame_packing_arrangement_cancel_flag" ); sei.m_arrangementCancelFlag = val; |
---|
754 | |
---|
755 | if ( !sei.m_arrangementCancelFlag ) |
---|
756 | { |
---|
757 | READ_CODE( 7, val, "frame_packing_arrangement_type" ); sei.m_arrangementType = val; |
---|
758 | assert((sei.m_arrangementType > 2) && (sei.m_arrangementType < 6) ); |
---|
759 | READ_FLAG( val, "quincunx_sampling_flag" ); sei.m_quincunxSamplingFlag = val; |
---|
760 | |
---|
761 | READ_CODE( 6, val, "content_interpretation_type" ); sei.m_contentInterpretationType = val; |
---|
762 | READ_FLAG( val, "spatial_flipping_flag" ); sei.m_spatialFlippingFlag = val; |
---|
763 | READ_FLAG( val, "frame0_flipped_flag" ); sei.m_frame0FlippedFlag = val; |
---|
764 | READ_FLAG( val, "field_views_flag" ); sei.m_fieldViewsFlag = val; |
---|
765 | READ_FLAG( val, "current_frame_is_frame0_flag" ); sei.m_currentFrameIsFrame0Flag = val; |
---|
766 | READ_FLAG( val, "frame0_self_contained_flag" ); sei.m_frame0SelfContainedFlag = val; |
---|
767 | READ_FLAG( val, "frame1_self_contained_flag" ); sei.m_frame1SelfContainedFlag = val; |
---|
768 | |
---|
769 | if ( sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5) |
---|
770 | { |
---|
771 | READ_CODE( 4, val, "frame0_grid_position_x" ); sei.m_frame0GridPositionX = val; |
---|
772 | READ_CODE( 4, val, "frame0_grid_position_y" ); sei.m_frame0GridPositionY = val; |
---|
773 | READ_CODE( 4, val, "frame1_grid_position_x" ); sei.m_frame1GridPositionX = val; |
---|
774 | READ_CODE( 4, val, "frame1_grid_position_y" ); sei.m_frame1GridPositionY = val; |
---|
775 | } |
---|
776 | |
---|
777 | READ_CODE( 8, val, "frame_packing_arrangement_reserved_byte" ); sei.m_arrangementReservedByte = val; |
---|
778 | READ_FLAG( val, "frame_packing_arrangement_persistence_flag" ); sei.m_arrangementPersistenceFlag = val ? true : false; |
---|
779 | } |
---|
780 | READ_FLAG( val, "upsampled_aspect_ratio" ); sei.m_upsampledAspectRatio = val; |
---|
781 | |
---|
782 | xParseByteAlign(); |
---|
783 | } |
---|
784 | |
---|
785 | Void SEIReader::xParseSEIDisplayOrientation(SEIDisplayOrientation& sei, UInt /*payloadSize*/) |
---|
786 | { |
---|
787 | UInt val; |
---|
788 | READ_FLAG( val, "display_orientation_cancel_flag" ); sei.cancelFlag = val; |
---|
789 | if( !sei.cancelFlag ) |
---|
790 | { |
---|
791 | READ_FLAG( val, "hor_flip" ); sei.horFlip = val; |
---|
792 | READ_FLAG( val, "ver_flip" ); sei.verFlip = val; |
---|
793 | READ_CODE( 16, val, "anticlockwise_rotation" ); sei.anticlockwiseRotation = val; |
---|
794 | READ_FLAG( val, "display_orientation_persistence_flag" ); sei.persistenceFlag = val; |
---|
795 | } |
---|
796 | xParseByteAlign(); |
---|
797 | } |
---|
798 | |
---|
799 | Void SEIReader::xParseSEITemporalLevel0Index(SEITemporalLevel0Index& sei, UInt /*payloadSize*/) |
---|
800 | { |
---|
801 | UInt val; |
---|
802 | READ_CODE ( 8, val, "tl0_idx" ); sei.tl0Idx = val; |
---|
803 | READ_CODE ( 8, val, "rap_idx" ); sei.rapIdx = val; |
---|
804 | xParseByteAlign(); |
---|
805 | } |
---|
806 | |
---|
807 | Void SEIReader::xParseSEIGradualDecodingRefreshInfo(SEIGradualDecodingRefreshInfo& sei, UInt /*payloadSize*/) |
---|
808 | { |
---|
809 | UInt val; |
---|
810 | READ_FLAG( val, "gdr_foreground_flag" ); sei.m_gdrForegroundFlag = val ? 1 : 0; |
---|
811 | xParseByteAlign(); |
---|
812 | } |
---|
813 | |
---|
814 | Void SEIReader::xParseSEIToneMappingInfo(SEIToneMappingInfo& sei, UInt /*payloadSize*/) |
---|
815 | { |
---|
816 | Int i; |
---|
817 | UInt val; |
---|
818 | READ_UVLC( val, "tone_map_id" ); sei.m_toneMapId = val; |
---|
819 | READ_FLAG( val, "tone_map_cancel_flag" ); sei.m_toneMapCancelFlag = val; |
---|
820 | |
---|
821 | if ( !sei.m_toneMapCancelFlag ) |
---|
822 | { |
---|
823 | READ_FLAG( val, "tone_map_persistence_flag" ); sei.m_toneMapPersistenceFlag = val; |
---|
824 | READ_CODE( 8, val, "coded_data_bit_depth" ); sei.m_codedDataBitDepth = val; |
---|
825 | READ_CODE( 8, val, "target_bit_depth" ); sei.m_targetBitDepth = val; |
---|
826 | READ_UVLC( val, "model_id" ); sei.m_modelId = val; |
---|
827 | switch(sei.m_modelId) |
---|
828 | { |
---|
829 | case 0: |
---|
830 | { |
---|
831 | READ_CODE( 32, val, "min_value" ); sei.m_minValue = val; |
---|
832 | READ_CODE( 32, val, "max_value" ); sei.m_maxValue = val; |
---|
833 | break; |
---|
834 | } |
---|
835 | case 1: |
---|
836 | { |
---|
837 | READ_CODE( 32, val, "sigmoid_midpoint" ); sei.m_sigmoidMidpoint = val; |
---|
838 | READ_CODE( 32, val, "sigmoid_width" ); sei.m_sigmoidWidth = val; |
---|
839 | break; |
---|
840 | } |
---|
841 | case 2: |
---|
842 | { |
---|
843 | UInt num = 1u << sei.m_targetBitDepth; |
---|
844 | sei.m_startOfCodedInterval.resize(num+1); |
---|
845 | for(i = 0; i < num; i++) |
---|
846 | { |
---|
847 | READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "start_of_coded_interval" ); |
---|
848 | sei.m_startOfCodedInterval[i] = val; |
---|
849 | } |
---|
850 | sei.m_startOfCodedInterval[num] = 1u << sei.m_codedDataBitDepth; |
---|
851 | break; |
---|
852 | } |
---|
853 | case 3: |
---|
854 | { |
---|
855 | READ_CODE( 16, val, "num_pivots" ); sei.m_numPivots = val; |
---|
856 | sei.m_codedPivotValue.resize(sei.m_numPivots); |
---|
857 | sei.m_targetPivotValue.resize(sei.m_numPivots); |
---|
858 | for(i = 0; i < sei.m_numPivots; i++ ) |
---|
859 | { |
---|
860 | READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "coded_pivot_value" ); |
---|
861 | sei.m_codedPivotValue[i] = val; |
---|
862 | READ_CODE( ((( sei.m_targetBitDepth + 7 ) >> 3 ) << 3), val, "target_pivot_value" ); |
---|
863 | sei.m_targetPivotValue[i] = val; |
---|
864 | } |
---|
865 | break; |
---|
866 | } |
---|
867 | case 4: |
---|
868 | { |
---|
869 | READ_CODE( 8, val, "camera_iso_speed_idc" ); sei.m_cameraIsoSpeedIdc = val; |
---|
870 | if( sei.m_cameraIsoSpeedIdc == 255) //Extended_ISO |
---|
871 | { |
---|
872 | READ_CODE( 32, val, "camera_iso_speed_value" ); sei.m_cameraIsoSpeedValue = val; |
---|
873 | } |
---|
874 | READ_CODE( 8, val, "exposure_index_idc" ); sei.m_exposureIndexIdc = val; |
---|
875 | if( sei.m_exposureIndexIdc == 255) //Extended_ISO |
---|
876 | { |
---|
877 | READ_CODE( 32, val, "exposure_index_value" ); sei.m_exposureIndexValue = val; |
---|
878 | } |
---|
879 | READ_FLAG( val, "exposure_compensation_value_sign_flag" ); sei.m_exposureCompensationValueSignFlag = val; |
---|
880 | READ_CODE( 16, val, "exposure_compensation_value_numerator" ); sei.m_exposureCompensationValueNumerator = val; |
---|
881 | READ_CODE( 16, val, "exposure_compensation_value_denom_idc" ); sei.m_exposureCompensationValueDenomIdc = val; |
---|
882 | READ_CODE( 32, val, "ref_screen_luminance_white" ); sei.m_refScreenLuminanceWhite = val; |
---|
883 | READ_CODE( 32, val, "extended_range_white_level" ); sei.m_extendedRangeWhiteLevel = val; |
---|
884 | READ_CODE( 16, val, "nominal_black_level_luma_code_value" ); sei.m_nominalBlackLevelLumaCodeValue = val; |
---|
885 | READ_CODE( 16, val, "nominal_white_level_luma_code_value" ); sei.m_nominalWhiteLevelLumaCodeValue= val; |
---|
886 | READ_CODE( 16, val, "extended_white_level_luma_code_value" ); sei.m_extendedWhiteLevelLumaCodeValue = val; |
---|
887 | break; |
---|
888 | } |
---|
889 | default: |
---|
890 | { |
---|
891 | assert(!"Undefined SEIToneMapModelId"); |
---|
892 | break; |
---|
893 | } |
---|
894 | }//switch model id |
---|
895 | }// if(!sei.m_toneMapCancelFlag) |
---|
896 | |
---|
897 | xParseByteAlign(); |
---|
898 | } |
---|
899 | |
---|
900 | #if P0050_KNEE_FUNCTION_SEI |
---|
901 | Void SEIReader::xParseSEIKneeFunctionInfo(SEIKneeFunctionInfo& sei, UInt /*payloadSize*/){ |
---|
902 | Int i; |
---|
903 | UInt val; |
---|
904 | READ_UVLC( val, "knee_function_id" ); sei.m_kneeId = val; |
---|
905 | READ_FLAG( val, "knee_function_cancel_flag" ); sei.m_kneeCancelFlag = val; |
---|
906 | if ( !sei.m_kneeCancelFlag ) |
---|
907 | { |
---|
908 | READ_FLAG( val, "knee_function_persistence_flag" ); sei.m_kneePersistenceFlag = val; |
---|
909 | READ_FLAG( val, "mapping_flag" ); sei.m_kneeMappingFlag = val; |
---|
910 | READ_CODE( 32, val, "input_d_range" ); sei.m_kneeInputDrange = val; |
---|
911 | READ_CODE( 32, val, "input_disp_luminance" ); sei.m_kneeInputDispLuminance = val; |
---|
912 | READ_CODE( 32, val, "output_d_range" ); sei.m_kneeOutputDrange = val; |
---|
913 | READ_CODE( 32, val, "output_disp_luminance" ); sei.m_kneeOutputDispLuminance = val; |
---|
914 | READ_UVLC( val, "num_knee_points_minus1" ); sei.m_kneeNumKneePointsMinus1 = val; |
---|
915 | assert( sei.m_kneeNumKneePointsMinus1 > 0 ); |
---|
916 | sei.m_kneeInputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1); |
---|
917 | sei.m_kneeOutputKneePoint.resize(sei.m_kneeNumKneePointsMinus1+1); |
---|
918 | for(i = 0; i <= sei.m_kneeNumKneePointsMinus1; i++ ) |
---|
919 | { |
---|
920 | READ_CODE( 10, val, "input_knee_point" ); sei.m_kneeInputKneePoint[i] = val; |
---|
921 | READ_CODE( 10, val, "output_knee_point" ); sei.m_kneeOutputKneePoint[i] = val; |
---|
922 | } |
---|
923 | } |
---|
924 | } |
---|
925 | #endif |
---|
926 | |
---|
927 | #if Q0074_COLOUR_REMAPPING_SEI |
---|
928 | Void SEIReader::xParseSEIColourRemappingInfo(SEIColourRemappingInfo& sei, UInt /*payloadSize*/) |
---|
929 | { |
---|
930 | UInt uiVal; |
---|
931 | Int iVal; |
---|
932 | |
---|
933 | READ_UVLC( uiVal, "colour_remap_id" ); sei.m_colourRemapId = uiVal; |
---|
934 | READ_FLAG( uiVal, "colour_remap_cancel_flag" ); sei.m_colourRemapCancelFlag = uiVal; |
---|
935 | if( !sei.m_colourRemapCancelFlag ) |
---|
936 | { |
---|
937 | READ_FLAG( uiVal, "colour_remap_persistence_flag" ); sei.m_colourRemapPersistenceFlag = uiVal; |
---|
938 | READ_FLAG( uiVal, "colour_remap_video_signal_type_present_flag" ); sei.m_colourRemapVideoSignalTypePresentFlag = uiVal; |
---|
939 | if ( sei.m_colourRemapVideoSignalTypePresentFlag ) |
---|
940 | { |
---|
941 | READ_FLAG( uiVal, "colour_remap_video_full_range_flag" ); sei.m_colourRemapVideoFullRangeFlag = uiVal; |
---|
942 | READ_CODE( 8, uiVal, "colour_remap_primaries" ); sei.m_colourRemapPrimaries = uiVal; |
---|
943 | READ_CODE( 8, uiVal, "colour_remap_transfer_characteristics" ); sei.m_colourRemapTransferCharacteristics = uiVal; |
---|
944 | READ_CODE( 8, uiVal, "colour_remap_matrix_coeffs" ); sei.m_colourRemapMatrixCoeffs = uiVal; |
---|
945 | } |
---|
946 | READ_CODE( 8, uiVal, "colour_remap_coded_data_bit_depth" ); sei.m_colourRemapCodedDataBitDepth = uiVal; |
---|
947 | READ_CODE( 8, uiVal, "colour_remap_target_bit_depth" ); sei.m_colourRemapTargetBitDepth = uiVal; |
---|
948 | |
---|
949 | for( Int c=0 ; c<3 ; c++ ) |
---|
950 | { |
---|
951 | READ_CODE( 8, uiVal, "pre_lut_num_val_minus1[c]" ); sei.m_preLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal; |
---|
952 | sei.m_preLutCodedValue[c].resize(sei.m_preLutNumValMinus1[c]+1); |
---|
953 | sei.m_preLutTargetValue[c].resize(sei.m_preLutNumValMinus1[c]+1); |
---|
954 | if( uiVal> 0 ) |
---|
955 | for ( Int i=0 ; i<=sei.m_preLutNumValMinus1[c] ; i++ ) |
---|
956 | { |
---|
957 | READ_CODE( (( sei.m_colourRemapCodedDataBitDepth + 7 ) >> 3 ) << 3, uiVal, "pre_lut_coded_value[c][i]" ); sei.m_preLutCodedValue[c][i] = uiVal; |
---|
958 | READ_CODE( (( sei.m_colourRemapTargetBitDepth + 7 ) >> 3 ) << 3, uiVal, "pre_lut_target_value[c][i]" ); sei.m_preLutTargetValue[c][i] = uiVal; |
---|
959 | } |
---|
960 | else // pre_lut_num_val_minus1[c] == 0 |
---|
961 | { |
---|
962 | sei.m_preLutCodedValue[c][0] = 0; |
---|
963 | sei.m_preLutTargetValue[c][0] = 0; |
---|
964 | sei.m_preLutCodedValue[c][1] = (1 << sei.m_colourRemapCodedDataBitDepth) - 1 ; |
---|
965 | sei.m_preLutTargetValue[c][1] = (1 << sei.m_colourRemapTargetBitDepth) - 1 ; |
---|
966 | } |
---|
967 | } |
---|
968 | |
---|
969 | READ_FLAG( uiVal, "colour_remap_matrix_present_flag" ); sei.m_colourRemapMatrixPresentFlag = uiVal; |
---|
970 | if( sei.m_colourRemapMatrixPresentFlag ) |
---|
971 | { |
---|
972 | READ_CODE( 4, uiVal, "log2_matrix_denom" ); sei.m_log2MatrixDenom = uiVal; |
---|
973 | for ( Int c=0 ; c<3 ; c++ ) |
---|
974 | for ( Int i=0 ; i<3 ; i++ ) |
---|
975 | { |
---|
976 | READ_SVLC( iVal, "colour_remap_coeffs[c][i]" ); sei.m_colourRemapCoeffs[c][i] = iVal; |
---|
977 | } |
---|
978 | } |
---|
979 | else // setting default matrix (I3) |
---|
980 | { |
---|
981 | sei.m_log2MatrixDenom = 0; |
---|
982 | for ( Int c=0 ; c<3 ; c++ ) |
---|
983 | for ( Int i=0 ; i<3 ; i++ ) |
---|
984 | sei.m_colourRemapCoeffs[c][i] = (c==i) ? 1 : 0; |
---|
985 | } |
---|
986 | for( Int c=0 ; c<3 ; c++ ) |
---|
987 | { |
---|
988 | READ_CODE( 8, uiVal, "post_lut_num_val_minus1[c]" ); sei.m_postLutNumValMinus1[c] = (uiVal==0) ? 1 : uiVal; |
---|
989 | sei.m_postLutCodedValue[c].resize(sei.m_postLutNumValMinus1[c]+1); |
---|
990 | sei.m_postLutTargetValue[c].resize(sei.m_postLutNumValMinus1[c]+1); |
---|
991 | if( uiVal > 0 ) |
---|
992 | for ( Int i=0 ; i<=sei.m_postLutNumValMinus1[c] ; i++ ) |
---|
993 | { |
---|
994 | READ_CODE( (( sei.m_colourRemapTargetBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_coded_value[c][i]" ); sei.m_postLutCodedValue[c][i] = uiVal; |
---|
995 | READ_CODE( (( sei.m_colourRemapTargetBitDepth + 7 ) >> 3 ) << 3, uiVal, "post_lut_target_value[c][i]" ); sei.m_postLutTargetValue[c][i] = uiVal; |
---|
996 | } |
---|
997 | else |
---|
998 | { |
---|
999 | sei.m_postLutCodedValue[c][0] = 0; |
---|
1000 | sei.m_postLutTargetValue[c][0] = 0; |
---|
1001 | sei.m_postLutTargetValue[c][1] = (1 << sei.m_colourRemapTargetBitDepth) - 1; |
---|
1002 | sei.m_postLutCodedValue[c][1] = (1 << sei.m_colourRemapTargetBitDepth) - 1; |
---|
1003 | } |
---|
1004 | } |
---|
1005 | } |
---|
1006 | |
---|
1007 | xParseByteAlign(); |
---|
1008 | } |
---|
1009 | #endif |
---|
1010 | |
---|
1011 | Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize) |
---|
1012 | { |
---|
1013 | Int iCode; |
---|
1014 | UInt uiCode; |
---|
1015 | |
---|
1016 | READ_UVLC( uiCode, "sop_seq_parameter_set_id" ); sei.m_sopSeqParameterSetId = uiCode; |
---|
1017 | READ_UVLC( uiCode, "num_pics_in_sop_minus1" ); sei.m_numPicsInSopMinus1 = uiCode; |
---|
1018 | for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++) |
---|
1019 | { |
---|
1020 | READ_CODE( 6, uiCode, "sop_desc_vcl_nalu_type" ); sei.m_sopDescVclNaluType[i] = uiCode; |
---|
1021 | READ_CODE( 3, sei.m_sopDescTemporalId[i], "sop_desc_temporal_id" ); sei.m_sopDescTemporalId[i] = uiCode; |
---|
1022 | if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP) |
---|
1023 | { |
---|
1024 | READ_UVLC( sei.m_sopDescStRpsIdx[i], "sop_desc_st_rps_idx" ); sei.m_sopDescStRpsIdx[i] = uiCode; |
---|
1025 | } |
---|
1026 | if (i > 0) |
---|
1027 | { |
---|
1028 | READ_SVLC( iCode, "sop_desc_poc_delta" ); sei.m_sopDescPocDelta[i] = iCode; |
---|
1029 | } |
---|
1030 | } |
---|
1031 | |
---|
1032 | xParseByteAlign(); |
---|
1033 | } |
---|
1034 | |
---|
1035 | #if Q0189_TMVP_CONSTRAINTS |
---|
1036 | Void SEIReader::xParseSEITMVPConstraints (SEITMVPConstrains& sei, UInt payloadSize) |
---|
1037 | { |
---|
1038 | UInt uiCode; |
---|
1039 | READ_UVLC( uiCode, "prev_pics_not_used_flag" ); sei.prev_pics_not_used_flag = uiCode; |
---|
1040 | READ_UVLC( uiCode, "no_intra_layer_col_pic_flag" ); sei.no_intra_layer_col_pic_flag = uiCode; |
---|
1041 | xParseByteAlign(); |
---|
1042 | } |
---|
1043 | #endif |
---|
1044 | |
---|
1045 | #if Q0247_FRAME_FIELD_INFO |
---|
1046 | Void SEIReader::xParseSEIFrameFieldInfo (SEIFrameFieldInfo& sei, UInt payloadSize) |
---|
1047 | { |
---|
1048 | UInt code; |
---|
1049 | READ_CODE( 4, code, "ffinfo_pic_struct" ); sei.m_ffinfo_picStruct = code; |
---|
1050 | READ_CODE( 2, code, "ffinfo_source_scan_type" ); sei.m_ffinfo_sourceScanType = code; |
---|
1051 | READ_FLAG( code, "ffinfo_duplicate_flag" ); sei.m_ffinfo_duplicateFlag = ( code == 1 ? true : false ); |
---|
1052 | xParseByteAlign(); |
---|
1053 | } |
---|
1054 | #endif |
---|
1055 | |
---|
1056 | #if LAYERS_NOT_PRESENT_SEI |
---|
1057 | Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComVPS *vps, TComSPS *sps) |
---|
1058 | #else |
---|
1059 | Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps) |
---|
1060 | #endif |
---|
1061 | { |
---|
1062 | UInt uiCode; |
---|
1063 | SEIMessages seis; |
---|
1064 | |
---|
1065 | READ_FLAG( uiCode, "bitstream_subset_flag" ); sei.m_bitStreamSubsetFlag = uiCode; |
---|
1066 | READ_FLAG( uiCode, "nesting_op_flag" ); sei.m_nestingOpFlag = uiCode; |
---|
1067 | if (sei.m_nestingOpFlag) |
---|
1068 | { |
---|
1069 | READ_FLAG( uiCode, "default_op_flag" ); sei.m_defaultOpFlag = uiCode; |
---|
1070 | READ_UVLC( uiCode, "nesting_num_ops_minus1" ); sei.m_nestingNumOpsMinus1 = uiCode; |
---|
1071 | for (UInt i = sei.m_defaultOpFlag; i <= sei.m_nestingNumOpsMinus1; i++) |
---|
1072 | { |
---|
1073 | READ_CODE( 3, uiCode, "nesting_max_temporal_id_plus1" ); sei.m_nestingMaxTemporalIdPlus1[i] = uiCode; |
---|
1074 | READ_UVLC( uiCode, "nesting_op_idx" ); sei.m_nestingOpIdx[i] = uiCode; |
---|
1075 | } |
---|
1076 | } |
---|
1077 | else |
---|
1078 | { |
---|
1079 | READ_FLAG( uiCode, "all_layers_flag" ); sei.m_allLayersFlag = uiCode; |
---|
1080 | if (!sei.m_allLayersFlag) |
---|
1081 | { |
---|
1082 | READ_CODE( 3, uiCode, "nesting_no_op_max_temporal_id_plus1" ); sei.m_nestingNoOpMaxTemporalIdPlus1 = uiCode; |
---|
1083 | READ_UVLC( uiCode, "nesting_num_layers_minus1" ); sei.m_nestingNumLayersMinus1 = uiCode; |
---|
1084 | for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++) |
---|
1085 | { |
---|
1086 | READ_CODE( 6, uiCode, "nesting_layer_id" ); sei.m_nestingLayerId[i] = uiCode; |
---|
1087 | } |
---|
1088 | } |
---|
1089 | } |
---|
1090 | |
---|
1091 | // byte alignment |
---|
1092 | while ( m_pcBitstream->getNumBitsRead() % 8 != 0 ) |
---|
1093 | { |
---|
1094 | UInt code; |
---|
1095 | READ_FLAG( code, "nesting_zero_bit" ); |
---|
1096 | } |
---|
1097 | |
---|
1098 | sei.m_callerOwnsSEIs = false; |
---|
1099 | |
---|
1100 | // read nested SEI messages |
---|
1101 | do { |
---|
1102 | #if O0164_MULTI_LAYER_HRD |
---|
1103 | #if LAYERS_NOT_PRESENT_SEI |
---|
1104 | xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, &sei); |
---|
1105 | #else |
---|
1106 | xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, &sei); |
---|
1107 | #endif |
---|
1108 | #else |
---|
1109 | #if LAYERS_NOT_PRESENT_SEI |
---|
1110 | xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps); |
---|
1111 | #else |
---|
1112 | xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps); |
---|
1113 | #endif |
---|
1114 | #endif |
---|
1115 | } while (m_pcBitstream->getNumBitsLeft() > 8); |
---|
1116 | |
---|
1117 | } |
---|
1118 | |
---|
1119 | Void SEIReader::xParseByteAlign() |
---|
1120 | { |
---|
1121 | UInt code; |
---|
1122 | if( m_pcBitstream->getNumBitsRead() % 8 != 0 ) |
---|
1123 | { |
---|
1124 | READ_FLAG( code, "bit_equal_to_one" ); assert( code == 1 ); |
---|
1125 | } |
---|
1126 | while( m_pcBitstream->getNumBitsRead() % 8 != 0 ) |
---|
1127 | { |
---|
1128 | READ_FLAG( code, "bit_equal_to_zero" ); assert( code == 0 ); |
---|
1129 | } |
---|
1130 | } |
---|
1131 | |
---|
1132 | #if SVC_EXTENSION |
---|
1133 | #if LAYERS_NOT_PRESENT_SEI |
---|
1134 | Void SEIReader::xParseSEILayersNotPresent(SEILayersNotPresent &sei, UInt payloadSize, TComVPS *vps) |
---|
1135 | { |
---|
1136 | UInt uiCode; |
---|
1137 | UInt i = 0; |
---|
1138 | |
---|
1139 | READ_UVLC( uiCode, "lp_sei_active_vps_id" ); sei.m_activeVpsId = uiCode; |
---|
1140 | assert(vps->getVPSId() == sei.m_activeVpsId); |
---|
1141 | sei.m_vpsMaxLayers = vps->getMaxLayers(); |
---|
1142 | for (; i < sei.m_vpsMaxLayers; i++) |
---|
1143 | { |
---|
1144 | READ_FLAG( uiCode, "layer_not_present_flag" ); sei.m_layerNotPresentFlag[i] = uiCode ? true : false; |
---|
1145 | } |
---|
1146 | for (; i < MAX_LAYERS; i++) |
---|
1147 | { |
---|
1148 | sei.m_layerNotPresentFlag[i] = false; |
---|
1149 | } |
---|
1150 | xParseByteAlign(); |
---|
1151 | } |
---|
1152 | #endif |
---|
1153 | #if N0383_IL_CONSTRAINED_TILE_SETS_SEI |
---|
1154 | Void SEIReader::xParseSEIInterLayerConstrainedTileSets (SEIInterLayerConstrainedTileSets &sei, UInt payloadSize) |
---|
1155 | { |
---|
1156 | UInt uiCode; |
---|
1157 | |
---|
1158 | READ_FLAG( uiCode, "il_all_tiles_exact_sample_value_match_flag" ); sei.m_ilAllTilesExactSampleValueMatchFlag = uiCode; |
---|
1159 | READ_FLAG( uiCode, "il_one_tile_per_tile_set_flag" ); sei.m_ilOneTilePerTileSetFlag = uiCode; |
---|
1160 | if( !sei.m_ilOneTilePerTileSetFlag ) |
---|
1161 | { |
---|
1162 | READ_UVLC( uiCode, "il_num_sets_in_message_minus1" ); sei.m_ilNumSetsInMessageMinus1 = uiCode; |
---|
1163 | if( sei.m_ilNumSetsInMessageMinus1 ) |
---|
1164 | { |
---|
1165 | READ_FLAG( uiCode, "skipped_tile_set_present_flag" ); sei.m_skippedTileSetPresentFlag = uiCode; |
---|
1166 | } |
---|
1167 | else |
---|
1168 | { |
---|
1169 | sei.m_skippedTileSetPresentFlag = false; |
---|
1170 | } |
---|
1171 | UInt numSignificantSets = sei.m_ilNumSetsInMessageMinus1 - (sei.m_skippedTileSetPresentFlag ? 1 : 0) + 1; |
---|
1172 | for( UInt i = 0; i < numSignificantSets; i++ ) |
---|
1173 | { |
---|
1174 | READ_UVLC( uiCode, "ilcts_id" ); sei.m_ilctsId[i] = uiCode; |
---|
1175 | READ_UVLC( uiCode, "il_num_tile_rects_in_set_minus1" ) ;sei.m_ilNumTileRectsInSetMinus1[i] = uiCode; |
---|
1176 | for( UInt j = 0; j <= sei.m_ilNumTileRectsInSetMinus1[i]; j++ ) |
---|
1177 | { |
---|
1178 | READ_UVLC( uiCode, "il_top_left_tile_index" ); sei.m_ilTopLeftTileIndex[i][j] = uiCode; |
---|
1179 | READ_UVLC( uiCode, "il_bottom_right_tile_index" ); sei.m_ilBottomRightTileIndex[i][j] = uiCode; |
---|
1180 | } |
---|
1181 | READ_CODE( 2, uiCode, "ilc_idc" ); sei.m_ilcIdc[i] = uiCode; |
---|
1182 | if( sei.m_ilAllTilesExactSampleValueMatchFlag ) |
---|
1183 | { |
---|
1184 | READ_FLAG( uiCode, "il_exact_sample_value_match_flag" ); sei.m_ilExactSampleValueMatchFlag[i] = uiCode; |
---|
1185 | } |
---|
1186 | } |
---|
1187 | } |
---|
1188 | else |
---|
1189 | { |
---|
1190 | READ_CODE( 2, uiCode, "all_tiles_ilc_idc" ); sei.m_allTilesIlcIdc = uiCode; |
---|
1191 | } |
---|
1192 | |
---|
1193 | xParseByteAlign(); |
---|
1194 | } |
---|
1195 | #endif |
---|
1196 | #if SUB_BITSTREAM_PROPERTY_SEI |
---|
1197 | Void SEIReader::xParseSEISubBitstreamProperty(SEISubBitstreamProperty &sei) |
---|
1198 | { |
---|
1199 | UInt uiCode; |
---|
1200 | READ_CODE( 4, uiCode, "active_vps_id" ); sei.m_activeVpsId = uiCode; |
---|
1201 | READ_UVLC( uiCode, "num_additional_sub_streams_minus1" ); sei.m_numAdditionalSubStreams = uiCode + 1; |
---|
1202 | |
---|
1203 | for( Int i = 0; i < sei.m_numAdditionalSubStreams; i++ ) |
---|
1204 | { |
---|
1205 | READ_CODE( 2, uiCode, "sub_bitstream_mode[i]" ); sei.m_subBitstreamMode[i] = uiCode; |
---|
1206 | READ_UVLC( uiCode, "output_layer_set_idx_to_vps[i]" ); sei.m_outputLayerSetIdxToVps[i] = uiCode; |
---|
1207 | READ_CODE( 3, uiCode, "highest_sub_layer_id[i]" ); sei.m_highestSublayerId[i] = uiCode; |
---|
1208 | READ_CODE( 16, uiCode, "avg_bit_rate[i]" ); sei.m_avgBitRate[i] = uiCode; |
---|
1209 | READ_CODE( 16, uiCode, "max_bit_rate[i]" ); sei.m_maxBitRate[i] = uiCode; |
---|
1210 | } |
---|
1211 | xParseByteAlign(); |
---|
1212 | } |
---|
1213 | #endif |
---|
1214 | |
---|
1215 | #if O0164_MULTI_LAYER_HRD |
---|
1216 | #if LAYERS_NOT_PRESENT_SEI |
---|
1217 | Void SEIReader::xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei) |
---|
1218 | #else |
---|
1219 | Void SEIReader::xParseSEIBspNesting(SEIBspNesting &sei, const NalUnitType nalUnitType, TComSPS *sps, const SEIScalableNesting &nestingSei) |
---|
1220 | #endif |
---|
1221 | { |
---|
1222 | UInt uiCode; |
---|
1223 | READ_UVLC( uiCode, "bsp_idx" ); sei.m_bspIdx = uiCode; |
---|
1224 | |
---|
1225 | // byte alignment |
---|
1226 | while ( m_pcBitstream->getNumBitsRead() % 8 != 0 ) |
---|
1227 | { |
---|
1228 | UInt code; |
---|
1229 | READ_FLAG( code, "bsp_nesting_zero_bit" ); |
---|
1230 | } |
---|
1231 | |
---|
1232 | sei.m_callerOwnsSEIs = false; |
---|
1233 | |
---|
1234 | // read nested SEI messages |
---|
1235 | #if NESTING_SEI_EXTENSIBILITY |
---|
1236 | Int numSeiMessages = 0; |
---|
1237 | READ_UVLC( uiCode, "num_seis_in_bsp_minus1" ); assert( uiCode <= MAX_SEIS_IN_BSP_NESTING ); |
---|
1238 | numSeiMessages = uiCode; |
---|
1239 | for(Int i = 0; i < numSeiMessages; i++) |
---|
1240 | { |
---|
1241 | xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, &nestingSei, &sei); |
---|
1242 | } |
---|
1243 | #else |
---|
1244 | do { |
---|
1245 | #if LAYERS_NOT_PRESENT_SEI |
---|
1246 | xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps, &nestingSei, &sei); |
---|
1247 | #else |
---|
1248 | xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps, &nestingSei); |
---|
1249 | #endif |
---|
1250 | } while (m_pcBitstream->getNumBitsLeft() > 8); |
---|
1251 | #endif |
---|
1252 | } |
---|
1253 | |
---|
1254 | Void SEIReader::xParseSEIBspInitialArrivalTime(SEIBspInitialArrivalTime &sei, TComVPS *vps, TComSPS *sps, const SEIScalableNesting &nestingSei, const SEIBspNesting &bspNestingSei) |
---|
1255 | { |
---|
1256 | assert(vps->getVpsVuiPresentFlag()); |
---|
1257 | |
---|
1258 | UInt schedCombCnt = vps->getNumBspSchedCombinations(nestingSei.m_nestingOpIdx[0]); |
---|
1259 | UInt len; |
---|
1260 | UInt hrdIdx; |
---|
1261 | UInt uiCode; |
---|
1262 | |
---|
1263 | if (schedCombCnt > 0) |
---|
1264 | { |
---|
1265 | hrdIdx = vps->getBspCombHrdIdx(nestingSei.m_nestingOpIdx[0], 0, bspNestingSei.m_bspIdx); |
---|
1266 | } |
---|
1267 | else |
---|
1268 | { |
---|
1269 | hrdIdx = 0; |
---|
1270 | } |
---|
1271 | |
---|
1272 | TComHRD *hrd = vps->getBspHrd(hrdIdx); |
---|
1273 | |
---|
1274 | if (hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag()) |
---|
1275 | { |
---|
1276 | len = hrd->getInitialCpbRemovalDelayLengthMinus1() + 1; |
---|
1277 | } |
---|
1278 | else |
---|
1279 | { |
---|
1280 | len = 23 + 1; |
---|
1281 | } |
---|
1282 | |
---|
1283 | if (hrd->getNalHrdParametersPresentFlag()) |
---|
1284 | { |
---|
1285 | for(UInt i = 0; i < schedCombCnt; i++) |
---|
1286 | { |
---|
1287 | READ_CODE( len, uiCode, "nal_initial_arrival_delay" ); sei.m_nalInitialArrivalDelay[i] = uiCode; |
---|
1288 | } |
---|
1289 | } |
---|
1290 | else |
---|
1291 | { |
---|
1292 | for(UInt i = 0; i < schedCombCnt; i++) |
---|
1293 | { |
---|
1294 | READ_CODE( len, uiCode, "vcl_initial_arrival_delay" ); sei.m_vclInitialArrivalDelay[i] = uiCode; |
---|
1295 | } |
---|
1296 | } |
---|
1297 | } |
---|
1298 | |
---|
1299 | #if !REMOVE_BSP_HRD_SEI |
---|
1300 | Void SEIReader::xParseSEIBspHrd(SEIBspHrd &sei, TComSPS *sps, const SEIScalableNesting &nestingSei) |
---|
1301 | { |
---|
1302 | UInt uiCode; |
---|
1303 | READ_UVLC( uiCode, "sei_num_bsp_hrd_parameters_minus1" ); sei.m_seiNumBspHrdParametersMinus1 = uiCode; |
---|
1304 | for (UInt i = 0; i <= sei.m_seiNumBspHrdParametersMinus1; i++) |
---|
1305 | { |
---|
1306 | if (i > 0) |
---|
1307 | { |
---|
1308 | READ_FLAG( uiCode, "sei_bsp_cprms_present_flag" ); sei.m_seiBspCprmsPresentFlag[i] = uiCode; |
---|
1309 | } |
---|
1310 | xParseHrdParameters(sei.hrd, i==0 ? 1 : sei.m_seiBspCprmsPresentFlag[i], nestingSei.m_nestingMaxTemporalIdPlus1[0]-1); |
---|
1311 | } |
---|
1312 | for (UInt h = 0; h <= nestingSei.m_nestingNumOpsMinus1; h++) |
---|
1313 | { |
---|
1314 | UInt lsIdx = nestingSei.m_nestingOpIdx[h]; |
---|
1315 | READ_UVLC( uiCode, "num_sei_bitstream_partitions_minus1[i]"); sei.m_seiNumBitstreamPartitionsMinus1[lsIdx] = uiCode; |
---|
1316 | #if HRD_BPB |
---|
1317 | Int chkPart=0; |
---|
1318 | #endif |
---|
1319 | UInt i; |
---|
1320 | for(i = 0; i <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; i++) |
---|
1321 | { |
---|
1322 | #if HRD_BPB |
---|
1323 | UInt nl=0; UInt j; |
---|
1324 | for(j = 0; j < sei.m_vpsMaxLayers; j++) |
---|
1325 | { |
---|
1326 | if (sei.m_layerIdIncludedFlag[lsIdx][j]) |
---|
1327 | { |
---|
1328 | nl++; |
---|
1329 | } |
---|
1330 | } |
---|
1331 | for (j = 0; j < nl; j++) |
---|
1332 | { |
---|
1333 | #else |
---|
1334 | for (UInt j = 0; j < sei.m_vpsMaxLayers; j++) |
---|
1335 | { |
---|
1336 | if (sei.m_layerIdIncludedFlag[lsIdx][j]) |
---|
1337 | { |
---|
1338 | #endif |
---|
1339 | READ_FLAG( uiCode, "sei_layer_in_bsp_flag[lsIdx][i][j]" ); sei.m_seiLayerInBspFlag[lsIdx][i][j] = uiCode; |
---|
1340 | } |
---|
1341 | #if !HRD_BPB |
---|
1342 | } |
---|
1343 | #endif |
---|
1344 | #if HRD_BPB |
---|
1345 | chkPart+=sei.m_seiLayerInBspFlag[lsIdx][i][j]; |
---|
1346 | #endif |
---|
1347 | } |
---|
1348 | #if HRD_BPB |
---|
1349 | assert(chkPart<=1); |
---|
1350 | #endif |
---|
1351 | #if HRD_BPB |
---|
1352 | if(sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]==0) |
---|
1353 | { |
---|
1354 | Int chkPartition1=0; Int chkPartition2=0; |
---|
1355 | for (UInt j = 0; j < sei.m_vpsMaxLayers; j++) |
---|
1356 | { |
---|
1357 | if( sei.m_layerIdIncludedFlag[lsIdx][j] ) |
---|
1358 | { |
---|
1359 | chkPartition1+=sei.m_seiLayerInBspFlag[lsIdx][0][j]; |
---|
1360 | chkPartition2++; |
---|
1361 | } |
---|
1362 | } |
---|
1363 | assert(chkPartition1!=chkPartition2); |
---|
1364 | } |
---|
1365 | #endif |
---|
1366 | |
---|
1367 | READ_UVLC( uiCode, "sei_num_bsp_sched_combinations_minus1[i]"); sei.m_seiNumBspSchedCombinationsMinus1[lsIdx] = uiCode; |
---|
1368 | for (i = 0; i <= sei.m_seiNumBspSchedCombinationsMinus1[lsIdx]; i++) |
---|
1369 | { |
---|
1370 | for (UInt j = 0; j <= sei.m_seiNumBitstreamPartitionsMinus1[lsIdx]; j++) |
---|
1371 | { |
---|
1372 | READ_UVLC( uiCode, "sei_bsp_comb_hrd_idx[lsIdx][i][j]"); sei.m_seiBspCombHrdIdx[lsIdx][i][j] = uiCode; |
---|
1373 | #if HRD_BPB |
---|
1374 | assert(uiCode <= sei.m_seiNumBspHrdParametersMinus1); |
---|
1375 | #endif |
---|
1376 | READ_UVLC( uiCode, "sei_bsp_comb_sched_idx[lsIdx][i][j]"); sei.m_seiBspCombScheddx[lsIdx][i][j] = uiCode; |
---|
1377 | #if HRD_BPB |
---|
1378 | assert(uiCode <= sei.hrd->getCpbCntMinus1( sps->getMaxTLayers()-1 )); |
---|
1379 | #endif |
---|
1380 | |
---|
1381 | } |
---|
1382 | } |
---|
1383 | } |
---|
1384 | } |
---|
1385 | #endif |
---|
1386 | |
---|
1387 | Void SEIReader::xParseHrdParameters(TComHRD *hrd, Bool commonInfPresentFlag, UInt maxNumSubLayersMinus1) |
---|
1388 | { |
---|
1389 | UInt uiCode; |
---|
1390 | if( commonInfPresentFlag ) |
---|
1391 | { |
---|
1392 | READ_FLAG( uiCode, "nal_hrd_parameters_present_flag" ); hrd->setNalHrdParametersPresentFlag( uiCode == 1 ? true : false ); |
---|
1393 | READ_FLAG( uiCode, "vcl_hrd_parameters_present_flag" ); hrd->setVclHrdParametersPresentFlag( uiCode == 1 ? true : false ); |
---|
1394 | if( hrd->getNalHrdParametersPresentFlag() || hrd->getVclHrdParametersPresentFlag() ) |
---|
1395 | { |
---|
1396 | READ_FLAG( uiCode, "sub_pic_cpb_params_present_flag" ); hrd->setSubPicCpbParamsPresentFlag( uiCode == 1 ? true : false ); |
---|
1397 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
1398 | { |
---|
1399 | READ_CODE( 8, uiCode, "tick_divisor_minus2" ); hrd->setTickDivisorMinus2( uiCode ); |
---|
1400 | READ_CODE( 5, uiCode, "du_cpb_removal_delay_length_minus1" ); hrd->setDuCpbRemovalDelayLengthMinus1( uiCode ); |
---|
1401 | READ_FLAG( uiCode, "sub_pic_cpb_params_in_pic_timing_sei_flag" ); hrd->setSubPicCpbParamsInPicTimingSEIFlag( uiCode == 1 ? true : false ); |
---|
1402 | READ_CODE( 5, uiCode, "dpb_output_delay_du_length_minus1" ); hrd->setDpbOutputDelayDuLengthMinus1( uiCode ); |
---|
1403 | } |
---|
1404 | READ_CODE( 4, uiCode, "bit_rate_scale" ); hrd->setBitRateScale( uiCode ); |
---|
1405 | READ_CODE( 4, uiCode, "cpb_size_scale" ); hrd->setCpbSizeScale( uiCode ); |
---|
1406 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
1407 | { |
---|
1408 | READ_CODE( 4, uiCode, "cpb_size_du_scale" ); hrd->setDuCpbSizeScale( uiCode ); |
---|
1409 | } |
---|
1410 | READ_CODE( 5, uiCode, "initial_cpb_removal_delay_length_minus1" ); hrd->setInitialCpbRemovalDelayLengthMinus1( uiCode ); |
---|
1411 | READ_CODE( 5, uiCode, "au_cpb_removal_delay_length_minus1" ); hrd->setCpbRemovalDelayLengthMinus1( uiCode ); |
---|
1412 | READ_CODE( 5, uiCode, "dpb_output_delay_length_minus1" ); hrd->setDpbOutputDelayLengthMinus1( uiCode ); |
---|
1413 | } |
---|
1414 | } |
---|
1415 | Int i, j, nalOrVcl; |
---|
1416 | for( i = 0; i <= maxNumSubLayersMinus1; i ++ ) |
---|
1417 | { |
---|
1418 | READ_FLAG( uiCode, "fixed_pic_rate_general_flag" ); hrd->setFixedPicRateFlag( i, uiCode == 1 ? true : false ); |
---|
1419 | if( !hrd->getFixedPicRateFlag( i ) ) |
---|
1420 | { |
---|
1421 | READ_FLAG( uiCode, "fixed_pic_rate_within_cvs_flag" ); hrd->setFixedPicRateWithinCvsFlag( i, uiCode == 1 ? true : false ); |
---|
1422 | } |
---|
1423 | else |
---|
1424 | { |
---|
1425 | hrd->setFixedPicRateWithinCvsFlag( i, true ); |
---|
1426 | } |
---|
1427 | hrd->setLowDelayHrdFlag( i, 0 ); // Infered to be 0 when not present |
---|
1428 | hrd->setCpbCntMinus1 ( i, 0 ); // Infered to be 0 when not present |
---|
1429 | if( hrd->getFixedPicRateWithinCvsFlag( i ) ) |
---|
1430 | { |
---|
1431 | READ_UVLC( uiCode, "elemental_duration_in_tc_minus1" ); hrd->setPicDurationInTcMinus1( i, uiCode ); |
---|
1432 | } |
---|
1433 | else |
---|
1434 | { |
---|
1435 | READ_FLAG( uiCode, "low_delay_hrd_flag" ); hrd->setLowDelayHrdFlag( i, uiCode == 1 ? true : false ); |
---|
1436 | } |
---|
1437 | if (!hrd->getLowDelayHrdFlag( i )) |
---|
1438 | { |
---|
1439 | READ_UVLC( uiCode, "cpb_cnt_minus1" ); hrd->setCpbCntMinus1( i, uiCode ); |
---|
1440 | } |
---|
1441 | for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ ) |
---|
1442 | { |
---|
1443 | if( ( ( nalOrVcl == 0 ) && ( hrd->getNalHrdParametersPresentFlag() ) ) || |
---|
1444 | ( ( nalOrVcl == 1 ) && ( hrd->getVclHrdParametersPresentFlag() ) ) ) |
---|
1445 | { |
---|
1446 | for( j = 0; j <= ( hrd->getCpbCntMinus1( i ) ); j ++ ) |
---|
1447 | { |
---|
1448 | READ_UVLC( uiCode, "bit_rate_value_minus1" ); hrd->setBitRateValueMinus1( i, j, nalOrVcl, uiCode ); |
---|
1449 | READ_UVLC( uiCode, "cpb_size_value_minus1" ); hrd->setCpbSizeValueMinus1( i, j, nalOrVcl, uiCode ); |
---|
1450 | if( hrd->getSubPicCpbParamsPresentFlag() ) |
---|
1451 | { |
---|
1452 | READ_UVLC( uiCode, "cpb_size_du_value_minus1" ); hrd->setDuCpbSizeValueMinus1( i, j, nalOrVcl, uiCode ); |
---|
1453 | READ_UVLC( uiCode, "bit_rate_du_value_minus1" ); hrd->setDuBitRateValueMinus1( i, j, nalOrVcl, uiCode ); |
---|
1454 | } |
---|
1455 | READ_FLAG( uiCode, "cbr_flag" ); hrd->setCbrFlag( i, j, nalOrVcl, uiCode == 1 ? true : false ); |
---|
1456 | } |
---|
1457 | } |
---|
1458 | } |
---|
1459 | } |
---|
1460 | } |
---|
1461 | #endif |
---|
1462 | |
---|
1463 | #if Q0078_ADD_LAYER_SETS |
---|
1464 | |
---|
1465 | #if LAYERS_NOT_PRESENT_SEI |
---|
1466 | Void SEIReader::xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComVPS *vps, TComSPS *sps) |
---|
1467 | #else |
---|
1468 | Void SEIReader::xParseSEIOutputLayerSetNesting(SEIOutputLayerSetNesting& sei, const NalUnitType nalUnitType, TComSPS *sps) |
---|
1469 | #endif |
---|
1470 | { |
---|
1471 | UInt uiCode; |
---|
1472 | SEIMessages seis; |
---|
1473 | |
---|
1474 | READ_FLAG(uiCode, "ols_flag"); sei.m_olsFlag = uiCode; |
---|
1475 | READ_UVLC(uiCode, "num_ols_indices_minus1"); sei.m_numOlsIndicesMinus1 = uiCode; |
---|
1476 | |
---|
1477 | for (Int i = 0; i <= sei.m_numOlsIndicesMinus1; i++) |
---|
1478 | { |
---|
1479 | READ_UVLC(uiCode, "ols_idx[i]"); sei.m_olsIdx[i] = uiCode; |
---|
1480 | } |
---|
1481 | |
---|
1482 | // byte alignment |
---|
1483 | while (m_pcBitstream->getNumBitsRead() % 8 != 0) |
---|
1484 | { |
---|
1485 | UInt code; |
---|
1486 | READ_FLAG(code, "ols_nesting_zero_bit"); |
---|
1487 | } |
---|
1488 | |
---|
1489 | sei.m_callerOwnsSEIs = false; |
---|
1490 | |
---|
1491 | // read nested SEI messages |
---|
1492 | do { |
---|
1493 | #if O0164_MULTI_LAYER_HRD |
---|
1494 | #if LAYERS_NOT_PRESENT_SEI |
---|
1495 | xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps); |
---|
1496 | #else |
---|
1497 | xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps); |
---|
1498 | #endif |
---|
1499 | #else |
---|
1500 | #if LAYERS_NOT_PRESENT_SEI |
---|
1501 | xReadSEImessage(sei.m_nestedSEIs, nalUnitType, vps, sps); |
---|
1502 | #else |
---|
1503 | xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps); |
---|
1504 | #endif |
---|
1505 | #endif |
---|
1506 | } while (m_pcBitstream->getNumBitsLeft() > 8); |
---|
1507 | |
---|
1508 | } |
---|
1509 | |
---|
1510 | Void SEIReader::xParseSEIVPSRewriting(SEIVPSRewriting &sei) |
---|
1511 | { |
---|
1512 | } |
---|
1513 | |
---|
1514 | #endif |
---|
1515 | |
---|
1516 | #endif //SVC_EXTENSION |
---|
1517 | |
---|
1518 | //! \} |
---|