Changeset 608 in 3DVCSoftware for trunk/source/Lib/TLibDecoder/SEIread.cpp
- Timestamp:
- 1 Sep 2013, 22:47:26 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibDecoder/SEIread.cpp
r56 r608 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 2, ITU/ISO/IEC6 * Copyright (c) 2010-2013, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 32 32 */ 33 33 34 /** 35 \file SEIread.cpp 36 \brief reading functionality for SEI messages 37 */ 38 39 #include "TLibCommon/CommonDef.h" 34 40 #include "TLibCommon/TComBitStream.h" 35 41 #include "TLibCommon/SEI.h" 42 #include "TLibCommon/TComSlice.h" 43 #include "SyntaxElementParser.h" 36 44 #include "SEIread.h" 37 45 … … 39 47 //! \{ 40 48 41 static void parseSEIuserDataUnregistered(TComInputBitstream& bs, SEIuserDataUnregistered &sei, unsigned payloadSize); 42 static void parseSEIpictureDigest(TComInputBitstream& bs, SEIpictureDigest& sei, unsigned payloadSize); 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 case SEI::SOP_DESCRIPTION: 96 fprintf( g_hTrace, "=========== SOP Description SEI message ===========\n"); 97 break; 98 case SEI::SCALABLE_NESTING: 99 fprintf( g_hTrace, "=========== Scalable Nesting SEI message ===========\n"); 100 break; 101 default: 102 fprintf( g_hTrace, "=========== Unknown SEI message ===========\n"); 103 break; 104 } 105 } 106 #endif 43 107 44 108 /** 45 109 * unmarshal a single SEI message from bitstream bs 46 110 */ 47 void parseSEImessage(TComInputBitstream& bs, SEImessages& seis) 48 { 49 unsigned payloadType = 0; 50 for (unsigned char byte = 0xff; 0xff == byte; ) 51 { 52 payloadType += byte = bs.read(8); 53 } 54 55 unsigned payloadSize = 0; 56 for (unsigned char byte = 0xff; 0xff == byte; ) 57 { 58 payloadSize += byte = bs.read(8); 59 } 60 61 switch (payloadType) 62 { 63 case SEI::USER_DATA_UNREGISTERED: 64 seis.user_data_unregistered = new SEIuserDataUnregistered; 65 parseSEIuserDataUnregistered(bs, *seis.user_data_unregistered, payloadSize); 66 break; 67 case SEI::PICTURE_DIGEST: 68 seis.picture_digest = new SEIpictureDigest; 69 parseSEIpictureDigest(bs, *seis.picture_digest, payloadSize); 70 break; 71 default: 72 assert(!"Unhandled SEI message"); 73 } 111 void SEIReader::parseSEImessage(TComInputBitstream* bs, SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps) 112 { 113 setBitstream(bs); 114 115 assert(!m_pcBitstream->getNumBitsUntilByteAligned()); 116 do 117 { 118 xReadSEImessage(seis, nalUnitType, sps); 119 /* SEI messages are an integer number of bytes, something has failed 120 * in the parsing if bitstream not byte-aligned */ 121 assert(!m_pcBitstream->getNumBitsUntilByteAligned()); 122 } while (m_pcBitstream->getNumBitsLeft() > 8); 123 124 UInt rbspTrailingBits; 125 READ_CODE(8, rbspTrailingBits, "rbsp_trailing_bits"); 126 assert(rbspTrailingBits == 0x80); 127 } 128 129 Void SEIReader::xReadSEImessage(SEIMessages& seis, const NalUnitType nalUnitType, TComSPS *sps) 130 { 131 #if ENC_DEC_TRACE 132 xTraceSEIHeader(); 133 #endif 134 Int payloadType = 0; 135 UInt val = 0; 136 137 do 138 { 139 READ_CODE (8, val, "payload_type"); 140 payloadType += val; 141 } while (val==0xFF); 142 143 UInt payloadSize = 0; 144 do 145 { 146 READ_CODE (8, val, "payload_size"); 147 payloadSize += val; 148 } while (val==0xFF); 149 150 #if ENC_DEC_TRACE 151 xTraceSEIMessageType((SEI::PayloadType)payloadType); 152 #endif 153 154 /* extract the payload for this single SEI message. 155 * This allows greater safety in erroneous parsing of an SEI message 156 * from affecting subsequent messages. 157 * After parsing the payload, bs needs to be restored as the primary 158 * bitstream. 159 */ 160 TComInputBitstream *bs = getBitstream(); 161 setBitstream(bs->extractSubstream(payloadSize * 8)); 162 163 SEI *sei = NULL; 164 165 if(nalUnitType == NAL_UNIT_PREFIX_SEI) 166 { 167 switch (payloadType) 168 { 169 case SEI::USER_DATA_UNREGISTERED: 170 sei = new SEIuserDataUnregistered; 171 xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize); 172 break; 173 case SEI::ACTIVE_PARAMETER_SETS: 174 sei = new SEIActiveParameterSets; 175 xParseSEIActiveParameterSets((SEIActiveParameterSets&) *sei, payloadSize); 176 break; 177 case SEI::DECODING_UNIT_INFO: 178 if (!sps) 179 { 180 printf ("Warning: Found Decoding unit SEI message, but no active SPS is available. Ignoring."); 181 } 182 else 183 { 184 sei = new SEIDecodingUnitInfo; 185 xParseSEIDecodingUnitInfo((SEIDecodingUnitInfo&) *sei, payloadSize, sps); 186 } 187 break; 188 case SEI::BUFFERING_PERIOD: 189 if (!sps) 190 { 191 printf ("Warning: Found Buffering period SEI message, but no active SPS is available. Ignoring."); 192 } 193 else 194 { 195 sei = new SEIBufferingPeriod; 196 xParseSEIBufferingPeriod((SEIBufferingPeriod&) *sei, payloadSize, sps); 197 } 198 break; 199 case SEI::PICTURE_TIMING: 200 if (!sps) 201 { 202 printf ("Warning: Found Picture timing SEI message, but no active SPS is available. Ignoring."); 203 } 204 else 205 { 206 sei = new SEIPictureTiming; 207 xParseSEIPictureTiming((SEIPictureTiming&)*sei, payloadSize, sps); 208 } 209 break; 210 case SEI::RECOVERY_POINT: 211 sei = new SEIRecoveryPoint; 212 xParseSEIRecoveryPoint((SEIRecoveryPoint&) *sei, payloadSize); 213 break; 214 case SEI::FRAME_PACKING: 215 sei = new SEIFramePacking; 216 xParseSEIFramePacking((SEIFramePacking&) *sei, payloadSize); 217 break; 218 case SEI::DISPLAY_ORIENTATION: 219 sei = new SEIDisplayOrientation; 220 xParseSEIDisplayOrientation((SEIDisplayOrientation&) *sei, payloadSize); 221 break; 222 case SEI::TEMPORAL_LEVEL0_INDEX: 223 sei = new SEITemporalLevel0Index; 224 xParseSEITemporalLevel0Index((SEITemporalLevel0Index&) *sei, payloadSize); 225 break; 226 case SEI::REGION_REFRESH_INFO: 227 sei = new SEIGradualDecodingRefreshInfo; 228 xParseSEIGradualDecodingRefreshInfo((SEIGradualDecodingRefreshInfo&) *sei, payloadSize); 229 break; 230 case SEI::TONE_MAPPING_INFO: 231 sei = new SEIToneMappingInfo; 232 xParseSEIToneMappingInfo((SEIToneMappingInfo&) *sei, payloadSize); 233 break; 234 case SEI::SOP_DESCRIPTION: 235 sei = new SEISOPDescription; 236 xParseSEISOPDescription((SEISOPDescription&) *sei, payloadSize); 237 break; 238 case SEI::SCALABLE_NESTING: 239 sei = new SEIScalableNesting; 240 xParseSEIScalableNesting((SEIScalableNesting&) *sei, nalUnitType, payloadSize, sps); 241 break; 242 default: 243 for (UInt i = 0; i < payloadSize; i++) 244 { 245 UInt seiByte; 246 READ_CODE (8, seiByte, "unknown prefix SEI payload byte"); 247 } 248 printf ("Unknown prefix SEI message (payloadType = %d) was found!\n", payloadType); 249 } 250 } 251 else 252 { 253 switch (payloadType) 254 { 255 case SEI::USER_DATA_UNREGISTERED: 256 sei = new SEIuserDataUnregistered; 257 xParseSEIuserDataUnregistered((SEIuserDataUnregistered&) *sei, payloadSize); 258 break; 259 case SEI::DECODED_PICTURE_HASH: 260 sei = new SEIDecodedPictureHash; 261 xParseSEIDecodedPictureHash((SEIDecodedPictureHash&) *sei, payloadSize); 262 break; 263 default: 264 for (UInt i = 0; i < payloadSize; i++) 265 { 266 UInt seiByte; 267 READ_CODE (8, seiByte, "unknown suffix SEI payload byte"); 268 } 269 printf ("Unknown suffix SEI message (payloadType = %d) was found!\n", payloadType); 270 } 271 } 272 if (sei != NULL) 273 { 274 seis.push_back(sei); 275 } 276 277 /* By definition the underlying bitstream terminates in a byte-aligned manner. 278 * 1. Extract all bar the last MIN(bitsremaining,nine) bits as reserved_payload_extension_data 279 * 2. Examine the final 8 bits to determine the payload_bit_equal_to_one marker 280 * 3. Extract the remainingreserved_payload_extension_data bits. 281 * 282 * If there are fewer than 9 bits available, extract them. 283 */ 284 Int payloadBitsRemaining = getBitstream()->getNumBitsLeft(); 285 if (payloadBitsRemaining) /* more_data_in_payload() */ 286 { 287 for (; payloadBitsRemaining > 9; payloadBitsRemaining--) 288 { 289 UInt reservedPayloadExtensionData; 290 READ_CODE (1, reservedPayloadExtensionData, "reserved_payload_extension_data"); 291 } 292 293 /* 2 */ 294 Int finalBits = getBitstream()->peekBits(payloadBitsRemaining); 295 Int finalPayloadBits = 0; 296 for (Int mask = 0xff; finalBits & (mask >> finalPayloadBits); finalPayloadBits++) 297 { 298 continue; 299 } 300 301 /* 3 */ 302 for (; payloadBitsRemaining > 9 - finalPayloadBits; payloadBitsRemaining--) 303 { 304 UInt reservedPayloadExtensionData; 305 READ_FLAG (reservedPayloadExtensionData, "reserved_payload_extension_data"); 306 } 307 308 UInt dummy; 309 READ_FLAG (dummy, "payload_bit_equal_to_one"); payloadBitsRemaining--; 310 while (payloadBitsRemaining) 311 { 312 READ_FLAG (dummy, "payload_bit_equal_to_zero"); payloadBitsRemaining--; 313 } 314 } 315 316 /* restore primary bitstream for sei_message */ 317 delete getBitstream(); 318 setBitstream(bs); 74 319 } 75 320 … … 78 323 * of payloasSize bytes into sei. 79 324 */ 80 static void parseSEIuserDataUnregistered(TComInputBitstream& bs, SEIuserDataUnregistered &sei, unsignedpayloadSize)325 Void SEIReader::xParseSEIuserDataUnregistered(SEIuserDataUnregistered &sei, UInt payloadSize) 81 326 { 82 327 assert(payloadSize >= 16); 83 for (unsigned i = 0; i < 16; i++) 84 { 85 sei.uuid_iso_iec_11578[i] = bs.read(8); 328 UInt val; 329 330 for (UInt i = 0; i < 16; i++) 331 { 332 READ_CODE (8, val, "uuid_iso_iec_11578"); 333 sei.uuid_iso_iec_11578[i] = val; 86 334 } 87 335 … … 93 341 } 94 342 95 sei.userData = new unsigned char[sei.userDataLength]; 96 for (unsigned i = 0; i < sei.userDataLength; i++) 97 { 98 sei.userData[i] = bs.read(8); 343 sei.userData = new UChar[sei.userDataLength]; 344 for (UInt i = 0; i < sei.userDataLength; i++) 345 { 346 READ_CODE (8, val, "user_data" ); 347 sei.userData[i] = val; 99 348 } 100 349 } 101 350 102 351 /** 103 * parse bitstream bs and unpack a picture_digestSEI message352 * parse bitstream bs and unpack a decoded picture hash SEI message 104 353 * of payloadSize bytes into sei. 105 354 */ 106 static void parseSEIpictureDigest(TComInputBitstream& bs, SEIpictureDigest& sei, unsigned payloadSize) 107 { 108 assert(payloadSize >= 17); 109 sei.method = static_cast<SEIpictureDigest::Method>(bs.read(8)); 110 assert(SEIpictureDigest::MD5 == sei.method); 111 for (unsigned i = 0; i < 16; i++) 112 { 113 sei.digest[i] = bs.read(8); 114 } 115 } 116 355 Void SEIReader::xParseSEIDecodedPictureHash(SEIDecodedPictureHash& sei, UInt /*payloadSize*/) 356 { 357 UInt val; 358 READ_CODE (8, val, "hash_type"); 359 sei.method = static_cast<SEIDecodedPictureHash::Method>(val); 360 for(Int yuvIdx = 0; yuvIdx < 3; yuvIdx++) 361 { 362 if(SEIDecodedPictureHash::MD5 == sei.method) 363 { 364 for (UInt i = 0; i < 16; i++) 365 { 366 READ_CODE(8, val, "picture_md5"); 367 sei.digest[yuvIdx][i] = val; 368 } 369 } 370 else if(SEIDecodedPictureHash::CRC == sei.method) 371 { 372 READ_CODE(16, val, "picture_crc"); 373 sei.digest[yuvIdx][0] = val >> 8 & 0xFF; 374 sei.digest[yuvIdx][1] = val & 0xFF; 375 } 376 else if(SEIDecodedPictureHash::CHECKSUM == sei.method) 377 { 378 READ_CODE(32, val, "picture_checksum"); 379 sei.digest[yuvIdx][0] = (val>>24) & 0xff; 380 sei.digest[yuvIdx][1] = (val>>16) & 0xff; 381 sei.digest[yuvIdx][2] = (val>>8) & 0xff; 382 sei.digest[yuvIdx][3] = val & 0xff; 383 } 384 } 385 } 386 Void SEIReader::xParseSEIActiveParameterSets(SEIActiveParameterSets& sei, UInt /*payloadSize*/) 387 { 388 UInt val; 389 READ_CODE(4, val, "active_vps_id"); sei.activeVPSId = val; 390 READ_FLAG( val, "full_random_access_flag"); sei.m_fullRandomAccessFlag = val ? true : false; 391 READ_FLAG( val, "no_param_set_update_flag"); sei.m_noParamSetUpdateFlag = val ? true : false; 392 READ_UVLC( val, "num_sps_ids_minus1"); sei.numSpsIdsMinus1 = val; 393 394 sei.activeSeqParamSetId.resize(sei.numSpsIdsMinus1 + 1); 395 for (Int i=0; i < (sei.numSpsIdsMinus1 + 1); i++) 396 { 397 READ_UVLC(val, "active_seq_param_set_id"); sei.activeSeqParamSetId[i] = val; 398 } 399 400 UInt uibits = m_pcBitstream->getNumBitsUntilByteAligned(); 401 402 while(uibits--) 403 { 404 READ_FLAG(val, "alignment_bit"); 405 } 406 } 407 408 Void SEIReader::xParseSEIDecodingUnitInfo(SEIDecodingUnitInfo& sei, UInt /*payloadSize*/, TComSPS *sps) 409 { 410 UInt val; 411 READ_UVLC(val, "decoding_unit_idx"); 412 sei.m_decodingUnitIdx = val; 413 414 TComVUI *vui = sps->getVuiParameters(); 415 if(vui->getHrdParameters()->getSubPicCpbParamsInPicTimingSEIFlag()) 416 { 417 READ_CODE( ( vui->getHrdParameters()->getDuCpbRemovalDelayLengthMinus1() + 1 ), val, "du_spt_cpb_removal_delay"); 418 sei.m_duSptCpbRemovalDelay = val; 419 } 420 else 421 { 422 sei.m_duSptCpbRemovalDelay = 0; 423 } 424 READ_FLAG( val, "dpb_output_du_delay_present_flag"); sei.m_dpbOutputDuDelayPresentFlag = val ? true : false; 425 if(sei.m_dpbOutputDuDelayPresentFlag) 426 { 427 READ_CODE(vui->getHrdParameters()->getDpbOutputDelayDuLengthMinus1() + 1, val, "pic_spt_dpb_output_du_delay"); 428 sei.m_picSptDpbOutputDuDelay = val; 429 } 430 xParseByteAlign(); 431 } 432 433 Void SEIReader::xParseSEIBufferingPeriod(SEIBufferingPeriod& sei, UInt /*payloadSize*/, TComSPS *sps) 434 { 435 Int i, nalOrVcl; 436 UInt code; 437 438 TComVUI *pVUI = sps->getVuiParameters(); 439 TComHRD *pHRD = pVUI->getHrdParameters(); 440 441 READ_UVLC( code, "bp_seq_parameter_set_id" ); sei.m_bpSeqParameterSetId = code; 442 if( !pHRD->getSubPicCpbParamsPresentFlag() ) 443 { 444 READ_FLAG( code, "rap_cpb_params_present_flag" ); sei.m_rapCpbParamsPresentFlag = code; 445 } 446 //read splicing flag and cpb_removal_delay_delta 447 READ_FLAG( code, "concatenation_flag"); 448 sei.m_concatenationFlag = code; 449 READ_CODE( ( pHRD->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_delta_minus1" ); 450 sei.m_auCpbRemovalDelayDelta = code + 1; 451 if( sei.m_rapCpbParamsPresentFlag ) 452 { 453 READ_CODE( pHRD->getCpbRemovalDelayLengthMinus1() + 1, code, "cpb_delay_offset" ); sei.m_cpbDelayOffset = code; 454 READ_CODE( pHRD->getDpbOutputDelayLengthMinus1() + 1, code, "dpb_delay_offset" ); sei.m_dpbDelayOffset = code; 455 } 456 for( nalOrVcl = 0; nalOrVcl < 2; nalOrVcl ++ ) 457 { 458 if( ( ( nalOrVcl == 0 ) && ( pHRD->getNalHrdParametersPresentFlag() ) ) || 459 ( ( nalOrVcl == 1 ) && ( pHRD->getVclHrdParametersPresentFlag() ) ) ) 460 { 461 for( i = 0; i < ( pHRD->getCpbCntMinus1( 0 ) + 1 ); i ++ ) 462 { 463 READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay" ); 464 sei.m_initialCpbRemovalDelay[i][nalOrVcl] = code; 465 READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_cpb_removal_delay_offset" ); 466 sei.m_initialCpbRemovalDelayOffset[i][nalOrVcl] = code; 467 if( pHRD->getSubPicCpbParamsPresentFlag() || sei.m_rapCpbParamsPresentFlag ) 468 { 469 READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay" ); 470 sei.m_initialAltCpbRemovalDelay[i][nalOrVcl] = code; 471 READ_CODE( ( pHRD->getInitialCpbRemovalDelayLengthMinus1() + 1 ) , code, "initial_alt_cpb_removal_delay_offset" ); 472 sei.m_initialAltCpbRemovalDelayOffset[i][nalOrVcl] = code; 473 } 474 } 475 } 476 } 477 xParseByteAlign(); 478 } 479 Void SEIReader::xParseSEIPictureTiming(SEIPictureTiming& sei, UInt /*payloadSize*/, TComSPS *sps) 480 { 481 Int i; 482 UInt code; 483 484 TComVUI *vui = sps->getVuiParameters(); 485 TComHRD *hrd = vui->getHrdParameters(); 486 487 if( vui->getFrameFieldInfoPresentFlag() ) 488 { 489 READ_CODE( 4, code, "pic_struct" ); sei.m_picStruct = code; 490 READ_CODE( 2, code, "source_scan_type" ); sei.m_sourceScanType = code; 491 READ_FLAG( code, "duplicate_flag" ); sei.m_duplicateFlag = ( code == 1 ? true : false ); 492 } 493 494 if( hrd->getCpbDpbDelaysPresentFlag()) 495 { 496 READ_CODE( ( hrd->getCpbRemovalDelayLengthMinus1() + 1 ), code, "au_cpb_removal_delay_minus1" ); 497 sei.m_auCpbRemovalDelay = code + 1; 498 READ_CODE( ( hrd->getDpbOutputDelayLengthMinus1() + 1 ), code, "pic_dpb_output_delay" ); 499 sei.m_picDpbOutputDelay = code; 500 501 if(hrd->getSubPicCpbParamsPresentFlag()) 502 { 503 READ_CODE(hrd->getDpbOutputDelayDuLengthMinus1()+1, code, "pic_dpb_output_du_delay" ); 504 sei.m_picDpbOutputDuDelay = code; 505 } 506 if( hrd->getSubPicCpbParamsPresentFlag() && hrd->getSubPicCpbParamsInPicTimingSEIFlag() ) 507 { 508 READ_UVLC( code, "num_decoding_units_minus1"); 509 sei.m_numDecodingUnitsMinus1 = code; 510 READ_FLAG( code, "du_common_cpb_removal_delay_flag" ); 511 sei.m_duCommonCpbRemovalDelayFlag = code; 512 if( sei.m_duCommonCpbRemovalDelayFlag ) 513 { 514 READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_common_cpb_removal_delay_minus1" ); 515 sei.m_duCommonCpbRemovalDelayMinus1 = code; 516 } 517 if( sei.m_numNalusInDuMinus1 != NULL ) 518 { 519 delete sei.m_numNalusInDuMinus1; 520 } 521 sei.m_numNalusInDuMinus1 = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ]; 522 if( sei.m_duCpbRemovalDelayMinus1 != NULL ) 523 { 524 delete sei.m_duCpbRemovalDelayMinus1; 525 } 526 sei.m_duCpbRemovalDelayMinus1 = new UInt[ ( sei.m_numDecodingUnitsMinus1 + 1 ) ]; 527 528 for( i = 0; i <= sei.m_numDecodingUnitsMinus1; i ++ ) 529 { 530 READ_UVLC( code, "num_nalus_in_du_minus1"); 531 sei.m_numNalusInDuMinus1[ i ] = code; 532 if( ( !sei.m_duCommonCpbRemovalDelayFlag ) && ( i < sei.m_numDecodingUnitsMinus1 ) ) 533 { 534 READ_CODE( ( hrd->getDuCpbRemovalDelayLengthMinus1() + 1 ), code, "du_cpb_removal_delay_minus1" ); 535 sei.m_duCpbRemovalDelayMinus1[ i ] = code; 536 } 537 } 538 } 539 } 540 xParseByteAlign(); 541 } 542 Void SEIReader::xParseSEIRecoveryPoint(SEIRecoveryPoint& sei, UInt /*payloadSize*/) 543 { 544 Int iCode; 545 UInt uiCode; 546 READ_SVLC( iCode, "recovery_poc_cnt" ); sei.m_recoveryPocCnt = iCode; 547 READ_FLAG( uiCode, "exact_matching_flag" ); sei.m_exactMatchingFlag = uiCode; 548 READ_FLAG( uiCode, "broken_link_flag" ); sei.m_brokenLinkFlag = uiCode; 549 xParseByteAlign(); 550 } 551 Void SEIReader::xParseSEIFramePacking(SEIFramePacking& sei, UInt /*payloadSize*/) 552 { 553 UInt val; 554 READ_UVLC( val, "frame_packing_arrangement_id" ); sei.m_arrangementId = val; 555 READ_FLAG( val, "frame_packing_arrangement_cancel_flag" ); sei.m_arrangementCancelFlag = val; 556 557 if ( !sei.m_arrangementCancelFlag ) 558 { 559 READ_CODE( 7, val, "frame_packing_arrangement_type" ); sei.m_arrangementType = val; 560 assert((sei.m_arrangementType > 2) && (sei.m_arrangementType < 6) ); 561 READ_FLAG( val, "quincunx_sampling_flag" ); sei.m_quincunxSamplingFlag = val; 562 563 READ_CODE( 6, val, "content_interpretation_type" ); sei.m_contentInterpretationType = val; 564 READ_FLAG( val, "spatial_flipping_flag" ); sei.m_spatialFlippingFlag = val; 565 READ_FLAG( val, "frame0_flipped_flag" ); sei.m_frame0FlippedFlag = val; 566 READ_FLAG( val, "field_views_flag" ); sei.m_fieldViewsFlag = val; 567 READ_FLAG( val, "current_frame_is_frame0_flag" ); sei.m_currentFrameIsFrame0Flag = val; 568 READ_FLAG( val, "frame0_self_contained_flag" ); sei.m_frame0SelfContainedFlag = val; 569 READ_FLAG( val, "frame1_self_contained_flag" ); sei.m_frame1SelfContainedFlag = val; 570 571 if ( sei.m_quincunxSamplingFlag == 0 && sei.m_arrangementType != 5) 572 { 573 READ_CODE( 4, val, "frame0_grid_position_x" ); sei.m_frame0GridPositionX = val; 574 READ_CODE( 4, val, "frame0_grid_position_y" ); sei.m_frame0GridPositionY = val; 575 READ_CODE( 4, val, "frame1_grid_position_x" ); sei.m_frame1GridPositionX = val; 576 READ_CODE( 4, val, "frame1_grid_position_y" ); sei.m_frame1GridPositionY = val; 577 } 578 579 READ_CODE( 8, val, "frame_packing_arrangement_reserved_byte" ); sei.m_arrangementReservedByte = val; 580 READ_FLAG( val, "frame_packing_arrangement_persistence_flag" ); sei.m_arrangementPersistenceFlag = val ? true : false; 581 } 582 READ_FLAG( val, "upsampled_aspect_ratio" ); sei.m_upsampledAspectRatio = val; 583 584 xParseByteAlign(); 585 } 586 587 Void SEIReader::xParseSEIDisplayOrientation(SEIDisplayOrientation& sei, UInt /*payloadSize*/) 588 { 589 UInt val; 590 READ_FLAG( val, "display_orientation_cancel_flag" ); sei.cancelFlag = val; 591 if( !sei.cancelFlag ) 592 { 593 READ_FLAG( val, "hor_flip" ); sei.horFlip = val; 594 READ_FLAG( val, "ver_flip" ); sei.verFlip = val; 595 READ_CODE( 16, val, "anticlockwise_rotation" ); sei.anticlockwiseRotation = val; 596 READ_FLAG( val, "display_orientation_persistence_flag" ); sei.persistenceFlag = val; 597 } 598 xParseByteAlign(); 599 } 600 601 Void SEIReader::xParseSEITemporalLevel0Index(SEITemporalLevel0Index& sei, UInt /*payloadSize*/) 602 { 603 UInt val; 604 READ_CODE ( 8, val, "tl0_idx" ); sei.tl0Idx = val; 605 READ_CODE ( 8, val, "rap_idx" ); sei.rapIdx = val; 606 xParseByteAlign(); 607 } 608 609 Void SEIReader::xParseSEIGradualDecodingRefreshInfo(SEIGradualDecodingRefreshInfo& sei, UInt /*payloadSize*/) 610 { 611 UInt val; 612 READ_FLAG( val, "gdr_foreground_flag" ); sei.m_gdrForegroundFlag = val ? 1 : 0; 613 xParseByteAlign(); 614 } 615 616 Void SEIReader::xParseSEIToneMappingInfo(SEIToneMappingInfo& sei, UInt /*payloadSize*/) 617 { 618 Int i; 619 UInt val; 620 READ_UVLC( val, "tone_map_id" ); sei.m_toneMapId = val; 621 READ_FLAG( val, "tone_map_cancel_flag" ); sei.m_toneMapCancelFlag = val; 622 623 if ( !sei.m_toneMapCancelFlag ) 624 { 625 READ_FLAG( val, "tone_map_persistence_flag" ); sei.m_toneMapPersistenceFlag = val; 626 READ_CODE( 8, val, "coded_data_bit_depth" ); sei.m_codedDataBitDepth = val; 627 READ_CODE( 8, val, "target_bit_depth" ); sei.m_targetBitDepth = val; 628 READ_UVLC( val, "model_id" ); sei.m_modelId = val; 629 switch(sei.m_modelId) 630 { 631 case 0: 632 { 633 READ_CODE( 32, val, "min_value" ); sei.m_minValue = val; 634 READ_CODE( 32, val, "max_value" ); sei.m_maxValue = val; 635 break; 636 } 637 case 1: 638 { 639 READ_CODE( 32, val, "sigmoid_midpoint" ); sei.m_sigmoidMidpoint = val; 640 READ_CODE( 32, val, "sigmoid_width" ); sei.m_sigmoidWidth = val; 641 break; 642 } 643 case 2: 644 { 645 UInt num = 1u << sei.m_targetBitDepth; 646 sei.m_startOfCodedInterval.resize(num+1); 647 for(i = 0; i < num; i++) 648 { 649 READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "start_of_coded_interval" ); 650 sei.m_startOfCodedInterval[i] = val; 651 } 652 sei.m_startOfCodedInterval[num] = 1u << sei.m_codedDataBitDepth; 653 break; 654 } 655 case 3: 656 { 657 READ_CODE( 16, val, "num_pivots" ); sei.m_numPivots = val; 658 sei.m_codedPivotValue.resize(sei.m_numPivots); 659 sei.m_targetPivotValue.resize(sei.m_numPivots); 660 for(i = 0; i < sei.m_numPivots; i++ ) 661 { 662 READ_CODE( ((( sei.m_codedDataBitDepth + 7 ) >> 3 ) << 3), val, "coded_pivot_value" ); 663 sei.m_codedPivotValue[i] = val; 664 READ_CODE( ((( sei.m_targetBitDepth + 7 ) >> 3 ) << 3), val, "target_pivot_value" ); 665 sei.m_targetPivotValue[i] = val; 666 } 667 break; 668 } 669 case 4: 670 { 671 READ_CODE( 8, val, "camera_iso_speed_idc" ); sei.m_cameraIsoSpeedValue = val; 672 if( sei.m_cameraIsoSpeedValue == 255) //Extended_ISO 673 { 674 READ_CODE( 32, val, "camera_iso_speed_value" ); sei.m_cameraIsoSpeedValue = val; 675 } 676 READ_FLAG( val, "exposure_compensation_value_sign_flag" ); sei.m_exposureCompensationValueSignFlag = val; 677 READ_CODE( 16, val, "exposure_compensation_value_numerator" ); sei.m_exposureCompensationValueNumerator = val; 678 READ_CODE( 16, val, "exposure_compensation_value_denom_idc" ); sei.m_exposureCompensationValueDenomIdc = val; 679 READ_CODE( 32, val, "ref_screen_luminance_white" ); sei.m_refScreenLuminanceWhite = val; 680 READ_CODE( 32, val, "extended_range_white_level" ); sei.m_extendedRangeWhiteLevel = val; 681 READ_CODE( 16, val, "nominal_black_level_luma_code_value" ); sei.m_nominalBlackLevelLumaCodeValue = val; 682 READ_CODE( 16, val, "nominal_white_level_luma_code_value" ); sei.m_nominalWhiteLevelLumaCodeValue= val; 683 READ_CODE( 16, val, "extended_white_level_luma_code_value" ); sei.m_extendedWhiteLevelLumaCodeValue = val; 684 break; 685 } 686 default: 687 { 688 assert(!"Undefined SEIToneMapModelId"); 689 break; 690 } 691 }//switch model id 692 }// if(!sei.m_toneMapCancelFlag) 693 694 xParseByteAlign(); 695 } 696 697 Void SEIReader::xParseSEISOPDescription(SEISOPDescription &sei, UInt payloadSize) 698 { 699 Int iCode; 700 UInt uiCode; 701 702 READ_UVLC( uiCode, "sop_seq_parameter_set_id" ); sei.m_sopSeqParameterSetId = uiCode; 703 READ_UVLC( uiCode, "num_pics_in_sop_minus1" ); sei.m_numPicsInSopMinus1 = uiCode; 704 for (UInt i = 0; i <= sei.m_numPicsInSopMinus1; i++) 705 { 706 READ_CODE( 6, uiCode, "sop_desc_vcl_nalu_type" ); sei.m_sopDescVclNaluType[i] = uiCode; 707 READ_CODE( 3, sei.m_sopDescTemporalId[i], "sop_desc_temporal_id" ); sei.m_sopDescTemporalId[i] = uiCode; 708 if (sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_W_RADL && sei.m_sopDescVclNaluType[i] != NAL_UNIT_CODED_SLICE_IDR_N_LP) 709 { 710 READ_UVLC( sei.m_sopDescStRpsIdx[i], "sop_desc_st_rps_idx" ); sei.m_sopDescStRpsIdx[i] = uiCode; 711 } 712 if (i > 0) 713 { 714 READ_SVLC( iCode, "sop_desc_poc_delta" ); sei.m_sopDescPocDelta[i] = iCode; 715 } 716 } 717 718 xParseByteAlign(); 719 } 720 721 Void SEIReader::xParseSEIScalableNesting(SEIScalableNesting& sei, const NalUnitType nalUnitType, UInt payloadSize, TComSPS *sps) 722 { 723 UInt uiCode; 724 SEIMessages seis; 725 726 READ_FLAG( uiCode, "bitstream_subset_flag" ); sei.m_bitStreamSubsetFlag = uiCode; 727 READ_FLAG( uiCode, "nesting_op_flag" ); sei.m_nestingOpFlag = uiCode; 728 if (sei.m_nestingOpFlag) 729 { 730 READ_FLAG( uiCode, "default_op_flag" ); sei.m_defaultOpFlag = uiCode; 731 READ_UVLC( uiCode, "nesting_num_ops_minus1" ); sei.m_nestingNumOpsMinus1 = uiCode; 732 for (UInt i = sei.m_defaultOpFlag; i <= sei.m_nestingNumOpsMinus1; i++) 733 { 734 READ_CODE( 3, uiCode, "nesting_max_temporal_id_plus1" ); sei.m_nestingMaxTemporalIdPlus1[i] = uiCode; 735 READ_UVLC( uiCode, "nesting_op_idx" ); sei.m_nestingOpIdx[i] = uiCode; 736 } 737 } 738 else 739 { 740 READ_FLAG( uiCode, "all_layers_flag" ); sei.m_allLayersFlag = uiCode; 741 if (!sei.m_allLayersFlag) 742 { 743 READ_CODE( 3, uiCode, "nesting_no_op_max_temporal_id_plus1" ); sei.m_nestingNoOpMaxTemporalIdPlus1 = uiCode; 744 READ_UVLC( uiCode, "nesting_num_layers_minus1" ); sei.m_nestingNumLayersMinus1 = uiCode; 745 for (UInt i = 0; i <= sei.m_nestingNumLayersMinus1; i++) 746 { 747 READ_CODE( 6, uiCode, "nesting_layer_id" ); sei.m_nestingLayerId[i] = uiCode; 748 } 749 } 750 } 751 752 // byte alignment 753 while ( m_pcBitstream->getNumBitsRead() % 8 != 0 ) 754 { 755 UInt code; 756 READ_FLAG( code, "nesting_zero_bit" ); 757 } 758 759 sei.m_callerOwnsSEIs = false; 760 761 // read nested SEI messages 762 do { 763 xReadSEImessage(sei.m_nestedSEIs, nalUnitType, sps); 764 } while (m_pcBitstream->getNumBitsLeft() > 8); 765 766 } 767 768 Void SEIReader::xParseByteAlign() 769 { 770 UInt code; 771 if( m_pcBitstream->getNumBitsRead() % 8 != 0 ) 772 { 773 READ_FLAG( code, "bit_equal_to_one" ); assert( code == 1 ); 774 } 775 while( m_pcBitstream->getNumBitsRead() % 8 != 0 ) 776 { 777 READ_FLAG( code, "bit_equal_to_zero" ); assert( code == 0 ); 778 } 779 } 117 780 //! \}
Note: See TracChangeset for help on using the changeset viewer.