Changeset 189 in SHVCSoftware for trunk/source/Lib/TLibEncoder/TEncGOP.cpp
- Timestamp:
- 13 May 2013, 16:58:44 (12 years ago)
- Location:
- trunk/source
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source
- Property svn:mergeinfo changed
/branches/SHM-2.0-dev/source (added) merged: 133-167,169-182,184-188
- Property svn:mergeinfo changed
-
trunk/source/Lib/TLibEncoder/TEncGOP.cpp
r125 r189 96 96 #if L0045_NON_NESTED_SEI_RESTRICTIONS 97 97 xResetNonNestedSEIPresentFlags(); 98 #if K0180_SCALABLE_NESTING_SEI 99 xResetNestedSEIPresentFlags(); 100 #endif 98 101 #endif 99 102 #if SVC_UPSAMPLING … … 134 137 m_pcSliceEncoder = pcTEncTop->getSliceEncoder(); 135 138 m_pcListPic = pcTEncTop->getListPic(); 139 136 140 m_pcEntropyCoder = pcTEncTop->getEntropyCoder(); 137 141 m_pcCavlcCoder = pcTEncTop->getCavlcCoder(); … … 210 214 } 211 215 216 #if J0149_TONE_MAPPING_SEI 217 SEIToneMappingInfo* TEncGOP::xCreateSEIToneMappingInfo() 218 { 219 SEIToneMappingInfo *seiToneMappingInfo = new SEIToneMappingInfo(); 220 seiToneMappingInfo->m_toneMapId = m_pcCfg->getTMISEIToneMapId(); 221 seiToneMappingInfo->m_toneMapCancelFlag = m_pcCfg->getTMISEIToneMapCancelFlag(); 222 seiToneMappingInfo->m_toneMapPersistenceFlag = m_pcCfg->getTMISEIToneMapPersistenceFlag(); 223 224 seiToneMappingInfo->m_codedDataBitDepth = m_pcCfg->getTMISEICodedDataBitDepth(); 225 assert(seiToneMappingInfo->m_codedDataBitDepth >= 8 && seiToneMappingInfo->m_codedDataBitDepth <= 14); 226 seiToneMappingInfo->m_targetBitDepth = m_pcCfg->getTMISEITargetBitDepth(); 227 assert( (seiToneMappingInfo->m_targetBitDepth >= 1 && seiToneMappingInfo->m_targetBitDepth <= 17) || (seiToneMappingInfo->m_targetBitDepth == 255) ); 228 seiToneMappingInfo->m_modelId = m_pcCfg->getTMISEIModelID(); 229 assert(seiToneMappingInfo->m_modelId >=0 &&seiToneMappingInfo->m_modelId<=4); 230 231 switch( seiToneMappingInfo->m_modelId) 232 { 233 case 0: 234 { 235 seiToneMappingInfo->m_minValue = m_pcCfg->getTMISEIMinValue(); 236 seiToneMappingInfo->m_maxValue = m_pcCfg->getTMISEIMaxValue(); 237 break; 238 } 239 case 1: 240 { 241 seiToneMappingInfo->m_sigmoidMidpoint = m_pcCfg->getTMISEISigmoidMidpoint(); 242 seiToneMappingInfo->m_sigmoidWidth = m_pcCfg->getTMISEISigmoidWidth(); 243 break; 244 } 245 case 2: 246 { 247 UInt num = 1u<<(seiToneMappingInfo->m_targetBitDepth); 248 seiToneMappingInfo->m_startOfCodedInterval.resize(num); 249 Int* ptmp = m_pcCfg->getTMISEIStartOfCodedInterva(); 250 if(ptmp) 251 { 252 for(int i=0; i<num;i++) 253 { 254 seiToneMappingInfo->m_startOfCodedInterval[i] = ptmp[i]; 255 } 256 } 257 break; 258 } 259 case 3: 260 { 261 seiToneMappingInfo->m_numPivots = m_pcCfg->getTMISEINumPivots(); 262 seiToneMappingInfo->m_codedPivotValue.resize(seiToneMappingInfo->m_numPivots); 263 seiToneMappingInfo->m_targetPivotValue.resize(seiToneMappingInfo->m_numPivots); 264 Int* ptmpcoded = m_pcCfg->getTMISEICodedPivotValue(); 265 Int* ptmptarget = m_pcCfg->getTMISEITargetPivotValue(); 266 if(ptmpcoded&&ptmptarget) 267 { 268 for(int i=0; i<(seiToneMappingInfo->m_numPivots);i++) 269 { 270 seiToneMappingInfo->m_codedPivotValue[i]=ptmpcoded[i]; 271 seiToneMappingInfo->m_targetPivotValue[i]=ptmptarget[i]; 272 } 273 } 274 break; 275 } 276 case 4: 277 { 278 seiToneMappingInfo->m_cameraIsoSpeedIdc = m_pcCfg->getTMISEICameraIsoSpeedIdc(); 279 seiToneMappingInfo->m_cameraIsoSpeedValue = m_pcCfg->getTMISEICameraIsoSpeedValue(); 280 assert( seiToneMappingInfo->m_cameraIsoSpeedValue !=0 ); 281 seiToneMappingInfo->m_exposureCompensationValueSignFlag = m_pcCfg->getTMISEIExposureCompensationValueSignFlag(); 282 seiToneMappingInfo->m_exposureCompensationValueNumerator = m_pcCfg->getTMISEIExposureCompensationValueNumerator(); 283 seiToneMappingInfo->m_exposureCompensationValueDenomIdc = m_pcCfg->getTMISEIExposureCompensationValueDenomIdc(); 284 seiToneMappingInfo->m_refScreenLuminanceWhite = m_pcCfg->getTMISEIRefScreenLuminanceWhite(); 285 seiToneMappingInfo->m_extendedRangeWhiteLevel = m_pcCfg->getTMISEIExtendedRangeWhiteLevel(); 286 assert( seiToneMappingInfo->m_extendedRangeWhiteLevel >= 100 ); 287 seiToneMappingInfo->m_nominalBlackLevelLumaCodeValue = m_pcCfg->getTMISEINominalBlackLevelLumaCodeValue(); 288 seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue = m_pcCfg->getTMISEINominalWhiteLevelLumaCodeValue(); 289 assert( seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue > seiToneMappingInfo->m_nominalBlackLevelLumaCodeValue ); 290 seiToneMappingInfo->m_extendedWhiteLevelLumaCodeValue = m_pcCfg->getTMISEIExtendedWhiteLevelLumaCodeValue(); 291 assert( seiToneMappingInfo->m_extendedWhiteLevelLumaCodeValue >= seiToneMappingInfo->m_nominalWhiteLevelLumaCodeValue ); 292 break; 293 } 294 default: 295 { 296 assert(!"Undefined SEIToneMapModelId"); 297 break; 298 } 299 } 300 return seiToneMappingInfo; 301 } 302 #endif 212 303 Void TEncGOP::xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps) 213 304 { 214 OutputNALUnit nalu(NAL_UNIT_ SEI);305 OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); 215 306 216 307 if(m_pcCfg->getActiveParameterSetsSEIEnabled()) … … 233 324 SEIFramePacking *sei = xCreateSEIFramePacking (); 234 325 235 nalu = NALUnit(NAL_UNIT_ SEI);326 nalu = NALUnit(NAL_UNIT_PREFIX_SEI); 236 327 m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); 237 328 m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); … … 244 335 SEIDisplayOrientation *sei = xCreateSEIDisplayOrientation(); 245 336 246 nalu = NALUnit(NAL_UNIT_ SEI);337 nalu = NALUnit(NAL_UNIT_PREFIX_SEI); 247 338 m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); 248 339 m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); … … 251 342 delete sei; 252 343 } 344 #if J0149_TONE_MAPPING_SEI 345 if(m_pcCfg->getToneMappingInfoSEIEnabled()) 346 { 347 SEIToneMappingInfo *sei = xCreateSEIToneMappingInfo (); 348 349 nalu = NALUnit(NAL_UNIT_PREFIX_SEI); 350 m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); 351 m_seiWriter.writeSEImessage(nalu.m_Bitstream, *sei, sps); 352 writeRBSPTrailingBits(nalu.m_Bitstream); 353 accessUnit.push_back(new NALUnitEBSP(nalu)); 354 delete sei; 355 } 356 #endif 253 357 } 254 358 … … 276 380 m_iNumPicCoded = 0; 277 381 SEIPictureTiming pictureTimingSEI; 382 #if L0208_SOP_DESCRIPTION_SEI 383 Bool writeSOP = m_pcCfg->getSOPDescriptionSEIEnabled(); 384 #endif 385 #if K0180_SCALABLE_NESTING_SEI 386 // Initialize Scalable Nesting SEI with single layer values 387 SEIScalableNesting scalableNestingSEI; 388 scalableNestingSEI.m_bitStreamSubsetFlag = 1; // If the nested SEI messages are picture buffereing SEI mesages, picure timing SEI messages or sub-picture timing SEI messages, bitstream_subset_flag shall be equal to 1 389 scalableNestingSEI.m_nestingOpFlag = 0; 390 scalableNestingSEI.m_nestingNumOpsMinus1 = 0; //nesting_num_ops_minus1 391 scalableNestingSEI.m_allLayersFlag = 0; 392 scalableNestingSEI.m_nestingNoOpMaxTemporalIdPlus1 = 6 + 1; //nesting_no_op_max_temporal_id_plus1 393 scalableNestingSEI.m_nestingNumLayersMinus1 = 1 - 1; //nesting_num_layers_minus1 394 scalableNestingSEI.m_nestingLayerId[0] = 0; 395 scalableNestingSEI.m_callerOwnsSEIs = true; 396 #endif 278 397 #if L0044_DU_DPB_OUTPUT_DELAY_HRD 279 398 Int picSptDpbOutputDuDelay = 0; … … 348 467 } 349 468 350 if( getNalUnitType(pocCurr ) == NAL_UNIT_CODED_SLICE_IDR || getNalUnitType(pocCurr) == NAL_UNIT_CODED_SLICE_IDR_N_LP )469 if( getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_W_RADL || getNalUnitType(pocCurr, m_iLastIDR) == NAL_UNIT_CODED_SLICE_IDR_N_LP ) 351 470 { 352 471 m_iLastIDR = pocCurr; … … 364 483 #if SVC_EXTENSION 365 484 pcPic->setLayerId( m_layerId ); 366 #endif 367 485 m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS(), m_pcEncTop->getVPS() ); 486 #else 368 487 m_pcSliceEncoder->initEncSlice ( pcPic, iPOCLast, pocCurr, iNumPicRcvd, iGOPid, pcSlice, m_pcEncTop->getSPS(), m_pcEncTop->getPPS() ); 488 #endif 369 489 pcSlice->setLastIDR(m_iLastIDR); 370 490 pcSlice->setSliceIdx(0); … … 411 531 } 412 532 // Set the nal unit type 413 pcSlice->setNalUnitType(getNalUnitType(pocCurr ));533 pcSlice->setNalUnitType(getNalUnitType(pocCurr, m_iLastIDR)); 414 534 #if IDR_ALIGNMENT 415 535 if (m_layerId > 0) 416 536 { 537 #if VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE 538 TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId]->getRefLayerEnc(m_layerId)->getListPic(); 539 #else 417 540 TComList<TComPic*> *cListPic = m_ppcTEncTop[m_layerId-1]->getListPic(); 541 #endif 418 542 pcSlice->setBaseColPic (*cListPic, m_layerId ); 419 543 } … … 424 548 { 425 549 #if IDR_ALIGNMENT 426 if( pcSlice->getBaseColPic()->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR )427 { 428 pcSlice->setNalUnitType( NAL_UNIT_CODED_SLICE_IDR);550 if( pcSlice->getBaseColPic()->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_W_RADL || pcSlice->getBaseColPic()->getSlice(0)->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR_N_LP ) 551 { 552 pcSlice->setNalUnitType(pcSlice->getBaseColPic()->getSlice(0)->getNalUnitType()); 429 553 } 430 554 else … … 432 556 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_CRA); 433 557 } 558 #if ZERO_NUM_DIRECT_LAYERS 559 if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() == 0 && pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) 560 { 561 pcSlice->setSliceType(I_SLICE); 562 } 563 else 564 #endif 434 565 if( m_layerId > 0 && !m_pcEncTop->getElRapSliceTypeB() ) 435 566 { 436 if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA ) &&567 if( (pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) && 437 568 (pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) && 438 569 pcSlice->getSliceType() == B_SLICE ) … … 442 573 } 443 574 #endif 444 if(pcSlice->get NalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R)445 { 446 if(pcSlice->get TemporalLayerNonReferenceFlag())575 if(pcSlice->getTemporalLayerNonReferenceFlag()) 576 { 577 if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_TRAIL_R) 447 578 { 448 579 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TRAIL_N); 580 } 581 if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RADL_R) 582 { 583 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RADL_N); 584 } 585 if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_RASL_R) 586 { 587 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_RASL_N); 449 588 } 450 589 } … … 471 610 else 472 611 { 473 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA );612 pcSlice->setNalUnitType(NAL_UNIT_CODED_SLICE_TLA_R); 474 613 } 475 614 } … … 524 663 pcSlice->setNumRefIdx(REF_PIC_LIST_1,min(m_pcCfg->getGOPEntry(iGOPid).m_numRefPicsActive,pcSlice->getRPS()->getNumberOfPictures())); 525 664 526 #if REF_LIST_BUGFIX 665 #if REF_IDX_FRAMEWORK 666 #if ZERO_NUM_DIRECT_LAYERS 667 if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() ) 668 #else 527 669 if(m_layerId > 0) 528 { 529 if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) 670 #endif 671 { 672 #if JCTVC_M0458_INTERLAYER_RPS_SIG 673 if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) 674 { 675 pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getActiveNumILRRefIdx()); 676 pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getActiveNumILRRefIdx()); 677 } 678 else 679 { 680 pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumRefIdx(REF_PIC_LIST_0)+pcSlice->getActiveNumILRRefIdx()); 681 pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumRefIdx(REF_PIC_LIST_1)+pcSlice->getActiveNumILRRefIdx()); 682 } 683 #else 684 if( pcSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pcSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA ) 530 685 { 531 686 pcSlice->setNumRefIdx(REF_PIC_LIST_0, pcSlice->getNumILRRefIdx()); … … 537 692 pcSlice->setNumRefIdx(REF_PIC_LIST_1, pcSlice->getNumRefIdx(REF_PIC_LIST_1)+pcSlice->getNumILRRefIdx()); 538 693 } 694 #endif 539 695 } 540 696 #endif … … 545 701 546 702 #if SVC_EXTENSION 703 #if ZERO_NUM_DIRECT_LAYERS 704 if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() ) 705 #else 547 706 if(m_layerId > 0) 707 #endif 548 708 { 549 709 #if !IDR_ALIGNMENT … … 553 713 #if SVC_UPSAMPLING 554 714 if ( pcPic->isSpatialEnhLayer()) 555 { 715 { 716 #if SCALED_REF_LAYER_OFFSETS 717 m_pcPredSearch->upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec(), pcSlice->getSPS()->getScaledRefLayerWindow() ); 718 #else 556 719 m_pcPredSearch->upsampleBasePic( pcPic->getFullPelBaseRec(), pcSlice->getBaseColPic()->getPicYuvRec(), pcPic->getPicYuvRec() ); 720 #endif 557 721 } 558 722 else … … 573 737 574 738 // Set reference list 575 #if REF_LIST_BUGFIX 739 #if REF_IDX_FRAMEWORK 740 #if ZERO_NUM_DIRECT_LAYERS 741 if(m_layerId == 0 || ( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() == 0 ) ) 742 #else 576 743 if(m_layerId == 0) 744 #endif 577 745 { 578 746 pcSlice->setRefPicList( rcListPic); … … 582 750 #endif 583 751 #if REF_IDX_FRAMEWORK 752 #if ZERO_NUM_DIRECT_LAYERS 753 if( m_layerId > 0 && pcSlice->getActiveNumILRRefIdx() ) 754 #else 584 755 if(m_layerId > 0) 756 #endif 585 757 { 586 758 m_pcEncTop->setILRPic(pcPic); … … 592 764 } 593 765 #endif 594 #if REF_LIST_BUGFIX595 766 pcSlice->setRefPicListModificationSvc(); 596 pcSlice->setRefPicListSvc( rcListPic, m_pcEncTop->getIlpList() ); 597 #else 598 pcSlice->addRefPicList ( m_pcEncTop->getIlpList(), 1); 599 #endif 767 pcSlice->setRefPicList( rcListPic, false, m_pcEncTop->getIlpList()); 600 768 601 769 #if REF_IDX_MFM … … 607 775 for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) 608 776 { 609 if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR( ) )777 if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) ) 610 778 { 611 779 ColRefIdx = colIdx; … … 620 788 for(Int colIdx = 0; colIdx < pcSlice->getNumRefIdx( RefPicList(1 - ColFromL0Flag) ); colIdx++) 621 789 { 622 if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR( ) )790 if( pcSlice->getRefPic( RefPicList(1 - ColFromL0Flag), colIdx)->isILR(m_layerId) ) 623 791 { 624 792 ColRefIdx = colIdx; … … 644 812 pcSlice->setSliceType ( P_SLICE ); 645 813 } 646 814 #if !L0034_COMBINED_LIST_CLEANUP 647 815 if (pcSlice->getSliceType() != B_SLICE || !pcSlice->getSPS()->getUseLComb()) 648 816 { … … 656 824 pcSlice->setNumRefIdx(REF_PIC_LIST_C, pcSlice->getNumRefIdx(REF_PIC_LIST_0)); 657 825 } 826 #endif 658 827 659 828 if (pcSlice->getSliceType() == B_SLICE) … … 683 852 pcSlice->setCheckLDC(bLowDelay); 684 853 } 854 else 855 { 856 pcSlice->setCheckLDC(true); 857 } 685 858 686 859 uiColDir = 1-uiColDir; … … 689 862 pcSlice->setRefPOCList(); 690 863 864 #if L0034_COMBINED_LIST_CLEANUP 865 pcSlice->setList1IdxToList0Idx(); 866 #else 691 867 pcSlice->setNoBackPredFlag( false ); 692 868 if ( pcSlice->getSliceType() == B_SLICE && !pcSlice->getRefPicListCombinationFlag()) … … 712 888 } 713 889 pcSlice->generateCombinedList(); 890 #endif 714 891 715 892 if (m_pcEncTop->getTMVPModeId() == 2) … … 831 1008 UInt uiNumSlices = 1; 832 1009 1010 #if SIMPLIFIED_MV_POS_SCALING 1011 if (m_layerId > 0) 1012 { 1013 #if SCALED_REF_LAYER_OFFSETS 1014 const Window &scalEL = m_pcEncTop->getScaledRefLayerWindow(); 1015 1016 Int widthBL = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth(); 1017 Int heightBL = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight(); 1018 1019 Int widthEL = pcPic->getPicYuvRec()->getWidth() - scalEL.getWindowLeftOffset() - scalEL.getWindowRightOffset(); 1020 Int heightEL = pcPic->getPicYuvRec()->getHeight() - scalEL.getWindowTopOffset() - scalEL.getWindowBottomOffset(); 1021 #else 1022 const Window &confBL = pcSlice->getBaseColPic()->getPicYuvRec()->getConformanceWindow(); 1023 const Window &confEL = pcPic->getPicYuvRec()->getConformanceWindow(); 1024 1025 Int widthBL = pcSlice->getBaseColPic()->getPicYuvRec()->getWidth () - confBL.getWindowLeftOffset() - confBL.getWindowRightOffset(); 1026 Int heightBL = pcSlice->getBaseColPic()->getPicYuvRec()->getHeight() - confBL.getWindowTopOffset() - confBL.getWindowBottomOffset(); 1027 1028 Int widthEL = pcPic->getPicYuvRec()->getWidth() - confEL.getWindowLeftOffset() - confEL.getWindowRightOffset(); 1029 Int heightEL = pcPic->getPicYuvRec()->getHeight() - confEL.getWindowTopOffset() - confEL.getWindowBottomOffset(); 1030 #endif 1031 g_mvScalingFactor[m_layerId][0] = Clip3(-4096, 4095, ((widthEL << 8) + (widthBL >> 1)) / widthBL); 1032 g_mvScalingFactor[m_layerId][1] = Clip3(-4096, 4095, ((heightEL << 8) + (heightBL >> 1)) / heightBL); 1033 1034 g_posScalingFactor[m_layerId][0] = ((widthBL << 16) + (widthEL >> 1)) / widthEL; 1035 g_posScalingFactor[m_layerId][1] = ((heightBL << 16) + (heightEL >> 1)) / heightEL; 1036 } 1037 #endif 1038 833 1039 UInt uiInternalAddress = pcPic->getNumPartInCU()-4; 834 1040 UInt uiExternalAddress = pcPic->getPicSym()->getNumberOfCUsInFrame()-1; … … 949 1155 startCUAddrSliceSegmentIdx++; 950 1156 #if AVC_BASE 951 if( m_layerId == 0 )1157 if( m_layerId == 0 && m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) 952 1158 { 953 1159 pcPic->getPicYuvOrg()->copyToPic( pcPic->getPicYuvRec() ); … … 1027 1233 Bool bLFCrossTileBoundary = pcSlice->getPPS()->getLoopFilterAcrossTilesEnabledFlag(); 1028 1234 m_pcLoopFilter->setCfg(bLFCrossTileBoundary); 1235 #if L0386_DB_METRIC 1236 if ( m_pcCfg->getDeblockingFilterMetric() ) 1237 { 1238 dblMetric(pcPic, uiNumSlices); 1239 } 1240 #endif 1029 1241 m_pcLoopFilter->loopFilterPic( pcPic ); 1030 1242 … … 1059 1271 OutputNALUnit nalu(NAL_UNIT_VPS, 0, m_layerId); 1060 1272 #if AVC_BASE 1061 if( m_layerId == 1)1273 if( ( m_layerId == 1 && m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) || ( m_layerId == 0 && !m_pcEncTop->getVPS()->getAvcBaseLayerFlag() ) ) 1062 1274 #else 1063 1275 if( m_layerId == 0 ) … … 1133 1345 } 1134 1346 1347 #if L0208_SOP_DESCRIPTION_SEI 1348 if (writeSOP) // write SOP description SEI (if enabled) at the beginning of GOP 1349 { 1350 Int SOPcurrPOC = pocCurr; 1351 1352 OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); 1353 m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); 1354 m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); 1355 1356 SEISOPDescription SOPDescriptionSEI; 1357 SOPDescriptionSEI.m_sopSeqParameterSetId = pcSlice->getSPS()->getSPSId(); 1358 1359 UInt i = 0; 1360 UInt prevEntryId = iGOPid; 1361 for (j = iGOPid; j < m_iGopSize; j++) 1362 { 1363 Int deltaPOC = m_pcCfg->getGOPEntry(j).m_POC - m_pcCfg->getGOPEntry(prevEntryId).m_POC; 1364 if ((SOPcurrPOC + deltaPOC) < m_pcCfg->getFramesToBeEncoded()) 1365 { 1366 SOPcurrPOC += deltaPOC; 1367 SOPDescriptionSEI.m_sopDescVclNaluType[i] = getNalUnitType(SOPcurrPOC, m_iLastIDR); 1368 SOPDescriptionSEI.m_sopDescTemporalId[i] = m_pcCfg->getGOPEntry(j).m_temporalId; 1369 SOPDescriptionSEI.m_sopDescStRpsIdx[i] = m_pcEncTop->getReferencePictureSetIdxForSOP(pcSlice, SOPcurrPOC, j); 1370 SOPDescriptionSEI.m_sopDescPocDelta[i] = deltaPOC; 1371 1372 prevEntryId = j; 1373 i++; 1374 } 1375 } 1376 1377 SOPDescriptionSEI.m_numPicsInSopMinus1 = i - 1; 1378 1379 m_seiWriter.writeSEImessage( nalu.m_Bitstream, SOPDescriptionSEI, pcSlice->getSPS()); 1380 writeRBSPTrailingBits(nalu.m_Bitstream); 1381 accessUnit.push_back(new NALUnitEBSP(nalu)); 1382 1383 writeSOP = false; 1384 } 1385 #endif 1386 1135 1387 if( ( m_pcCfg->getPictureTimingSEIEnabled() || m_pcCfg->getDecodingUnitInfoSEIEnabled() ) && 1136 1388 ( pcSlice->getSPS()->getVuiParametersPresentFlag() ) && … … 1178 1430 || ( pcSlice->getSPS()->getVuiParameters()->getHrdParameters()->getVclHrdParametersPresentFlag() ) ) ) 1179 1431 { 1180 OutputNALUnit nalu(NAL_UNIT_ SEI);1432 OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); 1181 1433 m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); 1182 1434 m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); … … 1219 1471 writeRBSPTrailingBits(nalu.m_Bitstream); 1220 1472 #if L0045_NON_NESTED_SEI_RESTRICTIONS 1473 { 1221 1474 UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); 1222 1475 UInt offsetPosition = m_activeParameterSetSEIPresentInAU; // Insert BP SEI after APS SEI … … 1228 1481 accessUnit.insert(it, new NALUnitEBSP(nalu)); 1229 1482 m_bufferingPeriodSEIPresentInAU = true; 1483 } 1230 1484 #else 1231 1485 accessUnit.push_back(new NALUnitEBSP(nalu)); 1486 #endif 1487 1488 #if K0180_SCALABLE_NESTING_SEI 1489 if (m_pcCfg->getScalableNestingSEIEnabled()) 1490 { 1491 OutputNALUnit naluTmp(NAL_UNIT_PREFIX_SEI); 1492 m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); 1493 m_pcEntropyCoder->setBitstream(&naluTmp.m_Bitstream); 1494 scalableNestingSEI.m_nestedSEIs.clear(); 1495 scalableNestingSEI.m_nestedSEIs.push_back(&sei_buffering_period); 1496 m_seiWriter.writeSEImessage( naluTmp.m_Bitstream, scalableNestingSEI, pcSlice->getSPS()); 1497 writeRBSPTrailingBits(naluTmp.m_Bitstream); 1498 #if L0045_NON_NESTED_SEI_RESTRICTIONS 1499 UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); 1500 UInt offsetPosition = m_activeParameterSetSEIPresentInAU + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU; // Insert BP SEI after non-nested APS, BP and PT SEIs 1501 AccessUnit::iterator it; 1502 for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) 1503 { 1504 it++; 1505 } 1506 accessUnit.insert(it, new NALUnitEBSP(naluTmp)); 1507 m_nestedBufferingPeriodSEIPresentInAU = true; 1508 #else 1509 accessUnit.push_back(new NALUnitEBSP(naluTmp)); 1510 #endif 1511 } 1232 1512 #endif 1233 1513 … … 1241 1521 { 1242 1522 // Gradual decoding refresh SEI 1243 OutputNALUnit nalu(NAL_UNIT_ SEI);1523 OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); 1244 1524 m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); 1245 1525 m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); … … 1253 1533 } 1254 1534 // Recovery point SEI 1255 OutputNALUnit nalu(NAL_UNIT_ SEI);1535 OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); 1256 1536 m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); 1257 1537 m_pcEntropyCoder->setBitstream(&nalu.m_Bitstream); … … 1444 1724 1445 1725 pcSlice->setTileOffstForMultES( uiOneBitstreamPerSliceLength ); 1446 if (!sliceSegment)1447 {1448 1726 pcSlice->setTileLocationCount ( 0 ); 1449 m_pcSliceEncoder->encodeSlice(pcPic, pcBitstreamRedirect, pcSubstreamsOut); // redirect is only used for CAVLC tile position info. 1450 } 1451 else 1452 { 1453 m_pcSliceEncoder->encodeSlice(pcPic, &nalu.m_Bitstream, pcSubstreamsOut); // nalu.m_Bitstream is only used for CAVLC tile position info. 1454 } 1727 m_pcSliceEncoder->encodeSlice(pcPic, pcSubstreamsOut); 1455 1728 1456 1729 { … … 1484 1757 if (ui+1 < pcSlice->getPPS()->getNumSubstreams()) 1485 1758 { 1486 puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits() ;1759 puiSubstreamSizes[ui] = pcSubstreamsOut[ui].getNumberOfWrittenBits() + (pcSubstreamsOut[ui].countStartCodeEmulations()<<3); 1487 1760 } 1488 1761 } … … 1516 1789 // If current NALU is the last NALU of slice and a NALU was buffered, then (a) Write current NALU (b) Update an write buffered NALU at approproate location in NALU list. 1517 1790 Bool bNALUAlignedWrittenToList = false; // used to ensure current NALU is not written more than once to the NALU list. 1518 x WriteTileLocationToSliceHeader(nalu, pcBitstreamRedirect, pcSlice);1791 xAttachSliceDataToNalUnit(nalu, pcBitstreamRedirect); 1519 1792 accessUnit.push_back(new NALUnitEBSP(nalu)); 1520 1793 #if RATE_CONTROL_LAMBDA_DOMAIN … … 1544 1817 { 1545 1818 UInt numRBSPBytes_nal = UInt((*it)->m_nalUnitData.str().size()); 1546 if ((*it)->m_nalUnitType != NAL_UNIT_ SEI && (*it)->m_nalUnitType != NAL_UNIT_SEI_SUFFIX)1819 if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI) 1547 1820 { 1548 1821 numRBSPBytes += numRBSPBytes_nal; … … 1640 1913 } 1641 1914 #if SVC_EXTENSION 1642 OutputNALUnit nalu(NAL_UNIT_S EI_SUFFIX, pcSlice->getTLayer(), m_layerId);1643 #else 1644 OutputNALUnit nalu(NAL_UNIT_S EI_SUFFIX, pcSlice->getTLayer());1915 OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer(), m_layerId); 1916 #else 1917 OutputNALUnit nalu(NAL_UNIT_SUFFIX_SEI, pcSlice->getTLayer()); 1645 1918 #endif 1646 1919 … … 1667 1940 sei_temporal_level0_index.rapIdx = m_rapIdx; 1668 1941 1669 OutputNALUnit nalu(NAL_UNIT_ SEI);1942 OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI); 1670 1943 1671 1944 /* write the SEI messages */ … … 1807 2080 if( m_pcCfg->getPictureTimingSEIEnabled() ) 1808 2081 { 1809 OutputNALUnit nalu(NAL_UNIT_SEI, pcSlice->getTLayer()); 2082 { 2083 OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer()); 1810 2084 m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); 1811 2085 m_seiWriter.writeSEImessage(nalu.m_Bitstream, pictureTimingSEI, pcSlice->getSPS()); … … 1827 2101 #endif 1828 2102 } 2103 #if K0180_SCALABLE_NESTING_SEI 2104 if ( m_pcCfg->getScalableNestingSEIEnabled() ) // put picture timing SEI into scalable nesting SEI 2105 { 2106 OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer()); 2107 m_pcEntropyCoder->setEntropyCoder(m_pcCavlcCoder, pcSlice); 2108 scalableNestingSEI.m_nestedSEIs.clear(); 2109 scalableNestingSEI.m_nestedSEIs.push_back(&pictureTimingSEI); 2110 m_seiWriter.writeSEImessage(nalu.m_Bitstream, scalableNestingSEI, pcSlice->getSPS()); 2111 writeRBSPTrailingBits(nalu.m_Bitstream); 2112 #if L0045_NON_NESTED_SEI_RESTRICTIONS 2113 UInt seiPositionInAu = xGetFirstSeiLocation(accessUnit); 2114 UInt offsetPosition = m_activeParameterSetSEIPresentInAU 2115 + m_bufferingPeriodSEIPresentInAU + m_pictureTimingSEIPresentInAU + m_nestedBufferingPeriodSEIPresentInAU; // Insert PT SEI after APS and BP SEI 2116 AccessUnit::iterator it; 2117 for(j = 0, it = accessUnit.begin(); j < seiPositionInAu + offsetPosition; j++) 2118 { 2119 it++; 2120 } 2121 accessUnit.insert(it, new NALUnitEBSP(nalu)); 2122 m_nestedPictureTimingSEIPresentInAU = true; 2123 #else 2124 AccessUnit::iterator it = find_if(accessUnit.begin(), accessUnit.end(), mem_fun(&NALUnit::isSlice)); 2125 accessUnit.insert(it, new NALUnitEBSP(nalu)); 2126 #endif 2127 } 2128 #endif 2129 2130 } 1829 2131 if( m_pcCfg->getDecodingUnitInfoSEIEnabled() && hrd->getSubPicCpbParamsPresentFlag() ) 1830 2132 { … … 1832 2134 for( Int i = 0; i < ( pictureTimingSEI.m_numDecodingUnitsMinus1 + 1 ); i ++ ) 1833 2135 { 1834 OutputNALUnit nalu(NAL_UNIT_ SEI, pcSlice->getTLayer());2136 OutputNALUnit nalu(NAL_UNIT_PREFIX_SEI, pcSlice->getTLayer()); 1835 2137 1836 2138 SEIDecodingUnitInfo tempSEI; … … 1880 2182 break; 1881 2183 } 1882 if ((*it)->m_nalUnitType != NAL_UNIT_ SEI && (*it)->m_nalUnitType != NAL_UNIT_SEI_SUFFIX)2184 if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI) 1883 2185 { 1884 2186 ctr++; … … 1891 2193 #if L0045_NON_NESTED_SEI_RESTRICTIONS 1892 2194 xResetNonNestedSEIPresentFlags(); 2195 #if K0180_SCALABLE_NESTING_SEI 2196 xResetNestedSEIPresentFlags(); 2197 #endif 1893 2198 #endif 1894 2199 pcPic->getPicYuvRec()->copyToPic(pcPicYuvRecOut); … … 2113 2418 case NAL_UNIT_CODED_SLICE_TRAIL_R: return "TRAIL_R"; 2114 2419 case NAL_UNIT_CODED_SLICE_TRAIL_N: return "TRAIL_N"; 2115 case NAL_UNIT_CODED_SLICE_TLA : return "TLA";2420 case NAL_UNIT_CODED_SLICE_TLA_R: return "TLA_R"; 2116 2421 case NAL_UNIT_CODED_SLICE_TSA_N: return "TSA_N"; 2117 2422 case NAL_UNIT_CODED_SLICE_STSA_R: return "STSA_R"; 2118 2423 case NAL_UNIT_CODED_SLICE_STSA_N: return "STSA_N"; 2119 case NAL_UNIT_CODED_SLICE_BLA : return "BLA";2120 case NAL_UNIT_CODED_SLICE_BLA NT: return "BLANT";2424 case NAL_UNIT_CODED_SLICE_BLA_W_LP: return "BLA_W_LP"; 2425 case NAL_UNIT_CODED_SLICE_BLA_W_RADL: return "BLA_W_RADL"; 2121 2426 case NAL_UNIT_CODED_SLICE_BLA_N_LP: return "BLA_N_LP"; 2122 case NAL_UNIT_CODED_SLICE_IDR : return "IDR";2427 case NAL_UNIT_CODED_SLICE_IDR_W_RADL: return "IDR_W_RADL"; 2123 2428 case NAL_UNIT_CODED_SLICE_IDR_N_LP: return "IDR_N_LP"; 2124 2429 case NAL_UNIT_CODED_SLICE_CRA: return "CRA"; 2125 case NAL_UNIT_CODED_SLICE_ DLP: return "DLP";2126 case NAL_UNIT_CODED_SLICE_ TFD: return "TFD";2430 case NAL_UNIT_CODED_SLICE_RADL_R: return "RADL_R"; 2431 case NAL_UNIT_CODED_SLICE_RASL_R: return "RASL_R"; 2127 2432 case NAL_UNIT_VPS: return "VPS"; 2128 2433 case NAL_UNIT_SPS: return "SPS"; … … 2132 2437 case NAL_UNIT_EOB: return "EOB"; 2133 2438 case NAL_UNIT_FILLER_DATA: return "FILLER"; 2134 case NAL_UNIT_SEI: return "SEI"; 2439 case NAL_UNIT_PREFIX_SEI: return "SEI"; 2440 case NAL_UNIT_SUFFIX_SEI: return "SEI"; 2135 2441 default: return "UNK"; 2136 2442 } … … 2223 2529 printf("*** %6s numBytesInNALunit: %u\n", nalUnitTypeToString((*it)->m_nalUnitType), numRBSPBytes_nal); 2224 2530 #endif 2225 if ((*it)->m_nalUnitType != NAL_UNIT_ SEI && (*it)->m_nalUnitType != NAL_UNIT_SEI_SUFFIX)2531 if ((*it)->m_nalUnitType != NAL_UNIT_PREFIX_SEI && (*it)->m_nalUnitType != NAL_UNIT_SUFFIX_SEI) 2226 2532 { 2227 2533 numRBSPBytes += numRBSPBytes_nal; … … 2314 2620 for (Int iRefIndex = 0; iRefIndex < pcSlice->getNumRefIdx(RefPicList(iRefList)); iRefIndex++) 2315 2621 { 2622 #if REF_IDX_FRAMEWORK && VPS_EXTN_DIRECT_REF_LAYERS_CONTINUE 2623 if( pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->isILR(m_layerId) ) 2624 { 2625 printf( "%d(%d) ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR(), pcSlice->getRefPic(RefPicList(iRefList), iRefIndex)->getLayerId() ); 2626 } 2627 else 2628 #endif 2316 2629 printf ("%d ", pcSlice->getRefPOC(RefPicList(iRefList), iRefIndex)-pcSlice->getLastIDR()); 2317 2630 } … … 2325 2638 * This function checks the configuration and returns the appropriate nal_unit_type for the picture. 2326 2639 */ 2327 NalUnitType TEncGOP::getNalUnitType(Int pocCurr )2640 NalUnitType TEncGOP::getNalUnitType(Int pocCurr, Int lastIDR) 2328 2641 { 2329 2642 if (pocCurr == 0) 2330 2643 { 2331 return NAL_UNIT_CODED_SLICE_IDR ;2644 return NAL_UNIT_CODED_SLICE_IDR_W_RADL; 2332 2645 } 2333 2646 if (pocCurr % m_pcCfg->getIntraPeriod() == 0) … … 2339 2652 else if (m_pcCfg->getDecodingRefreshType() == 2) 2340 2653 { 2341 return NAL_UNIT_CODED_SLICE_IDR ;2654 return NAL_UNIT_CODED_SLICE_IDR_W_RADL; 2342 2655 } 2343 2656 } … … 2351 2664 // controlling the reference pictures used for encoding that leading picture. Such a leading 2352 2665 // picture need not be marked as a TFD picture. 2353 return NAL_UNIT_CODED_SLICE_TFD; 2666 return NAL_UNIT_CODED_SLICE_RASL_R; 2667 } 2668 } 2669 if (lastIDR>0) 2670 { 2671 if (pocCurr < lastIDR) 2672 { 2673 return NAL_UNIT_CODED_SLICE_RADL_R; 2354 2674 } 2355 2675 } … … 2402 2722 } 2403 2723 2404 /** Determine the difference between consecutive tile sizes (in bytes) and writes it to bistream rNalu [slice header] 2405 * \param rpcBitstreamRedirect contains the bitstream to be concatenated to rNalu. rpcBitstreamRedirect contains slice payload. rpcSlice contains tile location information. 2406 * \returns Updates rNalu to contain concatenated bitstream. rpcBitstreamRedirect is cleared at the end of this function call. 2724 /** Attaches the input bitstream to the stream in the output NAL unit 2725 Updates rNalu to contain concatenated bitstream. rpcBitstreamRedirect is cleared at the end of this function call. 2726 * \param codedSliceData contains the coded slice data (bitstream) to be concatenated to rNalu 2727 * \param rNalu target NAL unit 2407 2728 */ 2408 Void TEncGOP::x WriteTileLocationToSliceHeader (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect, TComSlice*& rpcSlice)2729 Void TEncGOP::xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& codedSliceData) 2409 2730 { 2410 2731 // Byte-align … … 2412 2733 2413 2734 // Perform bitstream concatenation 2414 if (rpcBitstreamRedirect->getNumberOfWrittenBits() > 0) 2415 { 2416 UInt uiBitCount = rpcBitstreamRedirect->getNumberOfWrittenBits(); 2417 if (rpcBitstreamRedirect->getByteStreamLength()>0) 2418 { 2419 UChar *pucStart = reinterpret_cast<UChar*>(rpcBitstreamRedirect->getByteStream()); 2420 UInt uiWriteByteCount = 0; 2421 while (uiWriteByteCount < (uiBitCount >> 3) ) 2422 { 2423 UInt uiBits = (*pucStart); 2424 rNalu.m_Bitstream.write(uiBits, 8); 2425 pucStart++; 2426 uiWriteByteCount++; 2427 } 2428 } 2429 UInt uiBitsHeld = (uiBitCount & 0x07); 2430 for (UInt uiIdx=0; uiIdx < uiBitsHeld; uiIdx++) 2431 { 2432 rNalu.m_Bitstream.write((rpcBitstreamRedirect->getHeldBits() & (1 << (7-uiIdx))) >> (7-uiIdx), 1); 2433 } 2735 if (codedSliceData->getNumberOfWrittenBits() > 0) 2736 { 2737 rNalu.m_Bitstream.addSubstream(codedSliceData); 2434 2738 } 2435 2739 2436 2740 m_pcEntropyCoder->setBitstream(&rNalu.m_Bitstream); 2437 2741 2438 delete rpcBitstreamRedirect; 2439 rpcBitstreamRedirect = new TComOutputBitstream; 2742 codedSliceData->clear(); 2440 2743 } 2441 2744 … … 2562 2865 } 2563 2866 } 2564 assert(it != accessUnit.end()); 2867 // assert(it != accessUnit.end()); // Triggers with some legit configurations 2565 2868 return seiStartPos; 2566 2869 } 2567 2870 #endif 2871 2872 #if L0386_DB_METRIC 2873 Void TEncGOP::dblMetric( TComPic* pcPic, UInt uiNumSlices ) 2874 { 2875 TComPicYuv* pcPicYuvRec = pcPic->getPicYuvRec(); 2876 Pel* Rec = pcPicYuvRec->getLumaAddr( 0 ); 2877 Pel* tempRec = Rec; 2878 Int stride = pcPicYuvRec->getStride(); 2879 UInt log2maxTB = pcPic->getSlice(0)->getSPS()->getQuadtreeTULog2MaxSize(); 2880 UInt maxTBsize = (1<<log2maxTB); 2881 const UInt minBlockArtSize = 8; 2882 const UInt picWidth = pcPicYuvRec->getWidth(); 2883 const UInt picHeight = pcPicYuvRec->getHeight(); 2884 const UInt noCol = (picWidth>>log2maxTB); 2885 const UInt noRows = (picHeight>>log2maxTB); 2886 UInt64 *colSAD = (UInt64*)malloc(noCol*sizeof(UInt64)); 2887 UInt64 *rowSAD = (UInt64*)malloc(noRows*sizeof(UInt64)); 2888 UInt colIdx = 0; 2889 UInt rowIdx = 0; 2890 Pel p0, p1, p2, q0, q1, q2; 2891 2892 Int qp = pcPic->getSlice(0)->getSliceQp(); 2893 Int bitdepthScale = 1 << (g_bitDepthY-8); 2894 Int beta = TComLoopFilter::getBeta( qp ) * bitdepthScale; 2895 const Int thr2 = (beta>>2); 2896 const Int thr1 = 2*bitdepthScale; 2897 UInt a = 0; 2898 2899 memset(colSAD, 0, noCol*sizeof(UInt64)); 2900 memset(rowSAD, 0, noRows*sizeof(UInt64)); 2901 2902 if (maxTBsize > minBlockArtSize) 2903 { 2904 // Analyze vertical artifact edges 2905 for(Int c = maxTBsize; c < picWidth; c += maxTBsize) 2906 { 2907 for(Int r = 0; r < picHeight; r++) 2908 { 2909 p2 = Rec[c-3]; 2910 p1 = Rec[c-2]; 2911 p0 = Rec[c-1]; 2912 q0 = Rec[c]; 2913 q1 = Rec[c+1]; 2914 q2 = Rec[c+2]; 2915 a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1); 2916 if ( thr1 < a && a < thr2) 2917 { 2918 colSAD[colIdx] += abs(p0 - q0); 2919 } 2920 Rec += stride; 2921 } 2922 colIdx++; 2923 Rec = tempRec; 2924 } 2925 2926 // Analyze horizontal artifact edges 2927 for(Int r = maxTBsize; r < picHeight; r += maxTBsize) 2928 { 2929 for(Int c = 0; c < picWidth; c++) 2930 { 2931 p2 = Rec[c + (r-3)*stride]; 2932 p1 = Rec[c + (r-2)*stride]; 2933 p0 = Rec[c + (r-1)*stride]; 2934 q0 = Rec[c + r*stride]; 2935 q1 = Rec[c + (r+1)*stride]; 2936 q2 = Rec[c + (r+2)*stride]; 2937 a = ((abs(p2-(p1<<1)+p0)+abs(q0-(q1<<1)+q2))<<1); 2938 if (thr1 < a && a < thr2) 2939 { 2940 rowSAD[rowIdx] += abs(p0 - q0); 2941 } 2942 } 2943 rowIdx++; 2944 } 2945 } 2946 2947 UInt64 colSADsum = 0; 2948 UInt64 rowSADsum = 0; 2949 for(Int c = 0; c < noCol-1; c++) 2950 { 2951 colSADsum += colSAD[c]; 2952 } 2953 for(Int r = 0; r < noRows-1; r++) 2954 { 2955 rowSADsum += rowSAD[r]; 2956 } 2957 2958 colSADsum <<= 10; 2959 rowSADsum <<= 10; 2960 colSADsum /= (noCol-1); 2961 colSADsum /= picHeight; 2962 rowSADsum /= (noRows-1); 2963 rowSADsum /= picWidth; 2964 2965 UInt64 avgSAD = ((colSADsum + rowSADsum)>>1); 2966 avgSAD >>= (g_bitDepthY-8); 2967 2968 if ( avgSAD > 2048 ) 2969 { 2970 avgSAD >>= 9; 2971 Int offset = Clip3(2,6,(Int)avgSAD); 2972 for (Int i=0; i<uiNumSlices; i++) 2973 { 2974 pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(true); 2975 pcPic->getSlice(i)->setDeblockingFilterDisable(false); 2976 pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( offset ); 2977 pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( offset ); 2978 } 2979 } 2980 else 2981 { 2982 for (Int i=0; i<uiNumSlices; i++) 2983 { 2984 pcPic->getSlice(i)->setDeblockingFilterOverrideFlag(false); 2985 pcPic->getSlice(i)->setDeblockingFilterDisable( pcPic->getSlice(i)->getPPS()->getPicDisableDeblockingFilterFlag() ); 2986 pcPic->getSlice(i)->setDeblockingFilterBetaOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterBetaOffsetDiv2() ); 2987 pcPic->getSlice(i)->setDeblockingFilterTcOffsetDiv2( pcPic->getSlice(i)->getPPS()->getDeblockingFilterTcOffsetDiv2() ); 2988 } 2989 } 2990 2991 free(colSAD); 2992 free(rowSAD); 2993 } 2994 #endif 2568 2995 //! \}
Note: See TracChangeset for help on using the changeset viewer.