Changeset 125 in SHVCSoftware for trunk/source/Lib/TLibEncoder/TEncCu.cpp
- Timestamp:
- 16 Apr 2013, 06:39:31 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibEncoder/TEncCu.cpp
r30 r125 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 * … … 95 95 96 96 m_bEncodeDQP = false; 97 m_checkBurstIPCMFlag = false; 97 #if RATE_CONTROL_LAMBDA_DOMAIN 98 m_LCUPredictionSAD = 0; 99 m_addSADDepth = 0; 100 m_temporalSAD = 0; 101 #endif 98 102 99 103 // initialize partition order. … … 104 108 // initialize conversion matrix from partition index to pel 105 109 initRasterToPelXY( uiMaxWidth, uiMaxHeight, m_uhTotalDepth ); 106 initMotionReferIdx ( uiMaxWidth, uiMaxHeight, m_uhTotalDepth );107 110 } 108 111 … … 207 210 m_pcBitCounter = pcEncTop->getBitCounter(); 208 211 m_pcRdCost = pcEncTop->getRdCost(); 209 212 210 213 #if SVC_EXTENSION 211 214 m_ppcTEncTop = pcEncTop->getLayerEnc(); … … 241 244 m_ppcTempCU[0]->initCU( rpcCU->getPic(), rpcCU->getAddr() ); 242 245 246 #if RATE_CONTROL_LAMBDA_DOMAIN 247 m_addSADDepth = 0; 248 m_LCUPredictionSAD = 0; 249 m_temporalSAD = 0; 250 #endif 251 243 252 // analysis of CU 244 253 xCompressCU( m_ppcBestCU[0], m_ppcTempCU[0], 0 ); … … 254 263 #endif 255 264 } 256 /** \param pcCU pointer of CU data class , bForceTerminate when set to true terminates slice (default is false).265 /** \param pcCU pointer of CU data class 257 266 */ 258 Void TEncCu::encodeCU ( TComDataCU* pcCU , Bool bForceTerminate)267 Void TEncCu::encodeCU ( TComDataCU* pcCU ) 259 268 { 260 269 if ( pcCU->getSlice()->getPPS()->getUseDQP() ) … … 262 271 setdQPFlag(true); 263 272 } 264 265 TComPic* pcPic = pcCU->getPic();266 Bool checkBurstIPCMFlag = (pcPic->getSlice(0)->getSPS()->getUsePCM())? true : false;267 268 setCheckBurstIPCMFlag( checkBurstIPCMFlag );269 270 pcCU->setNumSucIPCM(0);271 pcCU->setLastCUSucIPCMFlag(false);272 273 273 274 // Encode CU data 274 275 xEncodeCU( pcCU, 0, 0 ); 275 276 bool bTerminateSlice = bForceTerminate;277 UInt uiCUAddr = pcCU->getAddr();278 /* If at the end of an LCU line but not at the end of a substream, perform CABAC flush */279 if (!bTerminateSlice && pcCU->getSlice()->getPPS()->getNumSubstreams() > 1)280 {281 Int iNumSubstreams = pcCU->getSlice()->getPPS()->getNumSubstreams();282 UInt uiWidthInLCUs = pcCU->getPic()->getPicSym()->getFrameWidthInCU();283 UInt uiCol = uiCUAddr % uiWidthInLCUs;284 UInt uiLin = uiCUAddr / uiWidthInLCUs;285 UInt uiTileStartLCU = pcCU->getPic()->getPicSym()->getTComTile(pcCU->getPic()->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();286 UInt uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;287 UInt uiTileLCUY = uiTileStartLCU / uiWidthInLCUs;288 UInt uiTileWidth = pcCU->getPic()->getPicSym()->getTComTile(pcCU->getPic()->getPicSym()->getTileIdxMap(uiCUAddr))->getTileWidth();289 UInt uiTileHeight = pcCU->getPic()->getPicSym()->getTComTile(pcCU->getPic()->getPicSym()->getTileIdxMap(uiCUAddr))->getTileHeight();290 Int iNumSubstreamsPerTile = iNumSubstreams;291 if (pcCU->getSlice()->getPPS()->getNumSubstreams() > 1)292 {293 iNumSubstreamsPerTile /= pcCU->getPic()->getPicSym()->getNumTiles();294 }295 if ((uiCol == uiTileLCUX+uiTileWidth-1) && (uiLin+iNumSubstreamsPerTile < uiTileLCUY+uiTileHeight))296 {297 m_pcEntropyCoder->encodeFlush();298 }299 }300 276 } 301 277 … … 447 423 isAddLowestQP = true; 448 424 iMinQP = iMinQP - 1; 449 450 425 } 451 426 } … … 456 431 } 457 432 433 #if RATE_CONTROL_LAMBDA_DOMAIN 434 if ( m_pcEncCfg->getUseRateCtrl() ) 435 { 436 iMinQP = m_pcRateCtrl->getRCQP(); 437 iMaxQP = m_pcRateCtrl->getRCQP(); 438 } 439 #else 458 440 if(m_pcEncCfg->getUseRateCtrl()) 459 441 { … … 462 444 iMaxQP = Clip3( MIN_QP, MAX_QP, qp); 463 445 } 446 #endif 464 447 465 448 // If slice start or slice end is within this cu... 466 449 TComSlice * pcSlice = rpcTempCU->getPic()->getSlice(rpcTempCU->getPic()->getCurrSliceIdx()); 467 Bool bSliceStart = pcSlice->get DependentSliceCurStartCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getDependentSliceCurStartCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart();468 Bool bSliceEnd = (pcSlice->get DependentSliceCurEndCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getDependentSliceCurEndCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart());450 Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurStartCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart(); 451 Bool bSliceEnd = (pcSlice->getSliceSegmentCurEndCUAddr()>rpcTempCU->getSCUAddr()&&pcSlice->getSliceSegmentCurEndCUAddr()<rpcTempCU->getSCUAddr()+rpcTempCU->getTotalNumPart()); 469 452 Bool bInsidePicture = ( uiRPelX < rpcBestCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < rpcBestCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ); 470 453 // We need to split, so don't try these modes. … … 526 509 #endif 527 510 528 if(!m_pcEncCfg->getUseEarlySkipDetection()) 529 { 530 // 2Nx2N, NxN 531 if ( !bEarlySkip ) 532 { 533 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData( uiDepth, iQP ); 534 if(m_pcEncCfg->getUseCbfFastMode()) 511 if(!m_pcEncCfg->getUseEarlySkipDetection()) 512 { 513 // 2Nx2N, NxN 514 if ( !bEarlySkip ) 535 515 { 536 doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; 516 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); rpcTempCU->initEstData( uiDepth, iQP ); 517 if(m_pcEncCfg->getUseCbfFastMode()) 518 { 519 doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; 520 } 537 521 } 538 522 } 539 }540 523 #if (ENCODER_FAST_MODE == 2) 541 524 } … … 561 544 } 562 545 563 if(!earlyDetectionSkipMode) 564 { 565 for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) 566 { 567 if (isAddLowestQP && (iQP == iMinQP)) 568 { 569 iQP = lowestQP; 570 } 571 rpcTempCU->initEstData( uiDepth, iQP ); 572 573 // do inter modes, NxN, 2NxN, and Nx2N 546 #if RATE_CONTROL_LAMBDA_DOMAIN 547 if ( uiDepth <= m_addSADDepth ) 548 { 549 m_LCUPredictionSAD += m_temporalSAD; 550 m_addSADDepth = uiDepth; 551 } 552 #endif 553 554 if(!earlyDetectionSkipMode) 555 { 556 for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) 557 { 558 if (isAddLowestQP && (iQP == iMinQP)) 559 { 560 iQP = lowestQP; 561 } 562 rpcTempCU->initEstData( uiDepth, iQP ); 563 564 // do inter modes, NxN, 2NxN, and Nx2N 574 565 #if (ENCODER_FAST_MODE) 575 566 if( rpcBestCU->getSlice()->getSliceType() != I_SLICE && testInter ) 576 567 #else 577 if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) 578 #endif 579 { 580 // 2Nx2N, NxN 581 if ( !bEarlySkip ) 582 { 583 if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) )) 584 { 585 if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu) 568 if( rpcBestCU->getSlice()->getSliceType() != I_SLICE ) 569 #endif 570 { 571 // 2Nx2N, NxN 572 if ( !bEarlySkip ) 586 573 { 587 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); 588 rpcTempCU->initEstData( uiDepth, iQP ); 574 if(!( (rpcBestCU->getWidth(0)==8) && (rpcBestCU->getHeight(0)==8) )) 575 { 576 if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth && doNotBlockPu) 577 { 578 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_NxN ); 579 rpcTempCU->initEstData( uiDepth, iQP ); 580 } 581 } 589 582 } 590 } 591 } 592 593 { // 2NxN, Nx2N 583 584 // 2NxN, Nx2N 594 585 if(doNotBlockPu) 595 586 { … … 610 601 } 611 602 } 612 }613 603 614 604 #if 1 615 //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N)616 if( pcPic->getSlice(0)->getSPS()->getAMPAcc(uiDepth) )617 {605 //! Try AMP (SIZE_2NxnU, SIZE_2NxnD, SIZE_nLx2N, SIZE_nRx2N) 606 if( pcPic->getSlice(0)->getSPS()->getAMPAcc(uiDepth) ) 607 { 618 608 #if AMP_ENC_SPEEDUP 619 Bool bTestAMP_Hor = false, bTestAMP_Ver = false;609 Bool bTestAMP_Hor = false, bTestAMP_Ver = false; 620 610 621 611 #if AMP_MRG 622 Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false;623 624 deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver);612 Bool bTestMergeAMP_Hor = false, bTestMergeAMP_Ver = false; 613 614 deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver, bTestMergeAMP_Hor, bTestMergeAMP_Ver); 625 615 #else 626 deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver); 627 #endif 628 629 //! Do horizontal AMP 630 if ( bTestAMP_Hor ) 631 { 632 if(doNotBlockPu) 616 deriveTestModeAMP (rpcBestCU, eParentPartSize, bTestAMP_Hor, bTestAMP_Ver); 617 #endif 618 619 //! Do horizontal AMP 620 if ( bTestAMP_Hor ) 633 621 { 634 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); 635 rpcTempCU->initEstData( uiDepth, iQP ); 636 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) 622 if(doNotBlockPu) 637 623 { 638 doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; 624 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); 625 rpcTempCU->initEstData( uiDepth, iQP ); 626 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) 627 { 628 doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; 629 } 630 } 631 if(doNotBlockPu) 632 { 633 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); 634 rpcTempCU->initEstData( uiDepth, iQP ); 635 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) 636 { 637 doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; 638 } 639 639 } 640 640 } 641 if(doNotBlockPu) 641 #if AMP_MRG 642 else if ( bTestMergeAMP_Hor ) 642 643 { 643 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); 644 rpcTempCU->initEstData( uiDepth, iQP ); 645 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) 644 if(doNotBlockPu) 646 645 { 647 doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; 646 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true ); 647 rpcTempCU->initEstData( uiDepth, iQP ); 648 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) 649 { 650 doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; 651 } 652 } 653 if(doNotBlockPu) 654 { 655 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true ); 656 rpcTempCU->initEstData( uiDepth, iQP ); 657 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) 658 { 659 doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; 660 } 648 661 } 649 662 } 650 } 651 #if AMP_MRG 652 else if ( bTestMergeAMP_Hor ) 653 { 654 if(doNotBlockPu) 663 #endif 664 665 //! Do horizontal AMP 666 if ( bTestAMP_Ver ) 655 667 { 656 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU, true ); 657 rpcTempCU->initEstData( uiDepth, iQP ); 658 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnU ) 668 if(doNotBlockPu) 659 669 { 660 doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; 670 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); 671 rpcTempCU->initEstData( uiDepth, iQP ); 672 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) 673 { 674 doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; 675 } 676 } 677 if(doNotBlockPu) 678 { 679 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); 680 rpcTempCU->initEstData( uiDepth, iQP ); 661 681 } 662 682 } 663 if(doNotBlockPu) 683 #if AMP_MRG 684 else if ( bTestMergeAMP_Ver ) 664 685 { 665 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD, true ); 666 rpcTempCU->initEstData( uiDepth, iQP ); 667 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_2NxnD ) 686 if(doNotBlockPu) 668 687 { 669 doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; 688 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true ); 689 rpcTempCU->initEstData( uiDepth, iQP ); 690 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N ) 691 { 692 doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0; 693 } 694 } 695 if(doNotBlockPu) 696 { 697 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true ); 698 rpcTempCU->initEstData( uiDepth, iQP ); 670 699 } 671 700 } 672 }673 #endif674 675 //! Do horizontal AMP676 if ( bTestAMP_Ver )677 {678 if(doNotBlockPu)679 {680 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N );681 rpcTempCU->initEstData( uiDepth, iQP );682 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N )683 {684 doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;685 }686 }687 if(doNotBlockPu)688 {689 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N );690 rpcTempCU->initEstData( uiDepth, iQP );691 }692 }693 #if AMP_MRG694 else if ( bTestMergeAMP_Ver )695 {696 if(doNotBlockPu)697 {698 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N, true );699 rpcTempCU->initEstData( uiDepth, iQP );700 if(m_pcEncCfg->getUseCbfFastMode() && rpcBestCU->getPartitionSize(0) == SIZE_nLx2N )701 {702 doNotBlockPu = rpcBestCU->getQtRootCbf( 0 ) != 0;703 }704 }705 if(doNotBlockPu)706 {707 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N, true );708 rpcTempCU->initEstData( uiDepth, iQP );709 }710 }711 701 #endif 712 702 713 703 #else 714 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); 715 rpcTempCU->initEstData( uiDepth, iQP ); 716 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); 717 rpcTempCU->initEstData( uiDepth, iQP ); 718 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); 719 rpcTempCU->initEstData( uiDepth, iQP ); 720 721 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); 722 rpcTempCU->initEstData( uiDepth, iQP ); 723 724 #endif 725 } 726 #endif 727 } 728 729 // initialize PCM flag 730 rpcTempCU->setIPCMFlag( 0, false); 731 rpcTempCU->setIPCMFlagSubParts ( false, 0, uiDepth); //SUB_LCU_DQP 732 733 // do normal intra modes 734 if ( !bEarlySkip ) 735 { 736 // speedup for inter frames 704 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnU ); 705 rpcTempCU->initEstData( uiDepth, iQP ); 706 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_2NxnD ); 707 rpcTempCU->initEstData( uiDepth, iQP ); 708 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nLx2N ); 709 rpcTempCU->initEstData( uiDepth, iQP ); 710 711 xCheckRDCostInter( rpcBestCU, rpcTempCU, SIZE_nRx2N ); 712 rpcTempCU->initEstData( uiDepth, iQP ); 713 714 #endif 715 } 716 #endif 717 } 718 719 // do normal intra modes 720 if ( !bEarlySkip ) 721 { 722 // speedup for inter frames 737 723 #if (ENCODER_FAST_MODE) 738 724 if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || … … 742 728 rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) // avoid very complex intra if it is unlikely 743 729 #else 744 if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || 745 rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || 746 rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || 747 rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) // avoid very complex intra if it is unlikely 748 #endif 749 { 750 xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); 751 rpcTempCU->initEstData( uiDepth, iQP ); 752 if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) 730 if( rpcBestCU->getSlice()->getSliceType() == I_SLICE || 731 rpcBestCU->getCbf( 0, TEXT_LUMA ) != 0 || 732 rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0 || 733 rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) // avoid very complex intra if it is unlikely 734 #endif 753 735 { 754 if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) ) 736 xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_2Nx2N ); 737 rpcTempCU->initEstData( uiDepth, iQP ); 738 if( uiDepth == g_uiMaxCUDepth - g_uiAddCUDepth ) 755 739 { 756 xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN ); 757 rpcTempCU->initEstData( uiDepth, iQP ); 740 if( rpcTempCU->getWidth(0) > ( 1 << rpcTempCU->getSlice()->getSPS()->getQuadtreeTULog2MinSize() ) ) 741 { 742 xCheckRDCostIntra( rpcBestCU, rpcTempCU, SIZE_NxN ); 743 rpcTempCU->initEstData( uiDepth, iQP ); 744 } 758 745 } 759 746 } 760 747 } 761 } 762 763 // test PCM764 if(pcPic->getSlice(0)->getSPS()->getUsePCM()765 && rpcTempCU->getWidth(0) <= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MaxSize())766 && rpcTempCU->getWidth(0) >= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MinSize()) )767 {768 UInt uiRawBits = (g_uiBitDepth * rpcBestCU->getWidth(0) * rpcBestCU->getHeight(0) * 3 / 2);769 UInt uiBestBits = rpcBestCU->getTotalBits();770 if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0)))771 {772 xCheckIntraPCM (rpcBestCU, rpcTempCU);773 rpcTempCU->initEstData( uiDepth, iQP );748 749 // test PCM 750 if(pcPic->getSlice(0)->getSPS()->getUsePCM() 751 && rpcTempCU->getWidth(0) <= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MaxSize()) 752 && rpcTempCU->getWidth(0) >= (1<<pcPic->getSlice(0)->getSPS()->getPCMLog2MinSize()) ) 753 { 754 UInt uiRawBits = (2 * g_bitDepthY + g_bitDepthC) * rpcBestCU->getWidth(0) * rpcBestCU->getHeight(0) / 2; 755 UInt uiBestBits = rpcBestCU->getTotalBits(); 756 if((uiBestBits > uiRawBits) || (rpcBestCU->getTotalCost() > m_pcRdCost->calcRdCost(uiRawBits, 0))) 757 { 758 xCheckIntraPCM (rpcBestCU, rpcTempCU); 759 rpcTempCU->initEstData( uiDepth, iQP ); 760 } 774 761 } 775 }776 762 #if INTRA_BL 777 763 if(m_pcPicYuvRecBase) … … 790 776 #endif 791 777 792 if (isAddLowestQP && (iQP == lowestQP)) 793 { 794 iQP = iMinQP; 795 } 796 } 797 798 } 778 if (isAddLowestQP && (iQP == lowestQP)) 779 { 780 iQP = iMinQP; 781 } 782 } 783 } 799 784 800 785 m_pcEntropyCoder->resetBits(); … … 831 816 { 832 817 bBoundary = true; 818 #if RATE_CONTROL_LAMBDA_DOMAIN 819 m_addSADDepth++; 820 #endif 833 821 } 834 822 … … 857 845 { 858 846 Int iStartQP; 859 if( pcPic->getCU( rpcTempCU->getAddr() )->get DependentSliceStartCU(rpcTempCU->getZorderIdxInCU()) == pcSlice->getDependentSliceCurStartCUAddr())847 if( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) == pcSlice->getSliceSegmentCurStartCUAddr()) 860 848 { 861 849 iStartQP = rpcTempCU->getQP(0); … … 863 851 else 864 852 { 865 UInt uiCurSliceStartPartIdx = pcSlice->get DependentSliceCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU();853 UInt uiCurSliceStartPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); 866 854 iStartQP = rpcTempCU->getQP(uiCurSliceStartPartIdx); 867 855 } … … 869 857 iMaxQP = iStartQP; 870 858 } 859 #if RATE_CONTROL_LAMBDA_DOMAIN 860 if ( m_pcEncCfg->getUseRateCtrl() ) 861 { 862 iMinQP = m_pcRateCtrl->getRCQP(); 863 iMaxQP = m_pcRateCtrl->getRCQP(); 864 } 865 #else 871 866 if(m_pcEncCfg->getUseRateCtrl()) 872 867 { … … 875 870 iMaxQP = Clip3( MIN_QP, MAX_QP, qp); 876 871 } 872 #endif 877 873 for (Int iQP=iMinQP; iQP<=iMaxQP; iQP++) 878 874 { 879 880 881 882 875 if (isAddLowestQP && (iQP == iMinQP)) 876 { 877 iQP = lowestQP; 878 } 883 879 rpcTempCU->initEstData( uiDepth, iQP ); 884 880 … … 895 891 pcSubTempPartCU->initSubCU( rpcTempCU, uiPartUnitIdx, uhNextDepth, iQP ); // clear sub partition datas or init. 896 892 897 Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->get DependentSliceCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getDependentSliceCurEndCUAddr();893 Bool bInSlice = pcSubBestPartCU->getSCUAddr()+pcSubBestPartCU->getTotalNumPart()>pcSlice->getSliceSegmentCurStartCUAddr()&&pcSubBestPartCU->getSCUAddr()<pcSlice->getSliceSegmentCurEndCUAddr(); 898 894 if(bInSlice && ( pcSubBestPartCU->getCUPelX() < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( pcSubBestPartCU->getCUPelY() < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) 899 895 { … … 951 947 for( UInt uiBlkIdx = 0; uiBlkIdx < rpcTempCU->getTotalNumPart(); uiBlkIdx ++) 952 948 { 953 if( ( pcPic->getCU( rpcTempCU->getAddr() )->get DependentSliceStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getDependentSliceCurStartCUAddr() ) &&949 if( ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(uiBlkIdx+rpcTempCU->getZorderIdxInCU()) == rpcTempCU->getSlice()->getSliceSegmentCurStartCUAddr() ) && 954 950 ( rpcTempCU->getCbf( uiBlkIdx, TEXT_LUMA ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_U ) || rpcTempCU->getCbf( uiBlkIdx, TEXT_CHROMA_V ) ) ) 955 951 { … … 960 956 961 957 UInt uiTargetPartIdx; 962 if ( pcPic->getCU( rpcTempCU->getAddr() )->get DependentSliceStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getDependentSliceCurStartCUAddr() )963 { 964 uiTargetPartIdx = pcSlice->get DependentSliceCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU();958 if ( pcPic->getCU( rpcTempCU->getAddr() )->getSliceSegmentStartCU(rpcTempCU->getZorderIdxInCU()) != pcSlice->getSliceSegmentCurStartCUAddr() ) 959 { 960 uiTargetPartIdx = pcSlice->getSliceSegmentCurStartCUAddr() % pcPic->getNumPartInCU() - rpcTempCU->getZorderIdxInCU(); 965 961 } 966 962 else … … 995 991 m_pppcRDSbacCoder[uhNextDepth][CI_NEXT_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); 996 992 } 997 Bool bEntropyLimit=false; 998 Bool bSliceLimit=false; 999 bSliceLimit=rpcBestCU->getSlice()->getSliceMode()==AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE&&(rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3); 1000 if(rpcBestCU->getSlice()->getDependentSliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_DEPENDENT_SLICE&&m_pcEncCfg->getUseSBACRD()) 1001 { 1002 if(rpcBestCU->getTotalBins()>rpcBestCU->getSlice()->getDependentSliceArgument()) 1003 { 1004 bEntropyLimit=true; 1005 } 1006 } 1007 else if(rpcBestCU->getSlice()->getDependentSliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_DEPENDENT_SLICE) 1008 { 1009 if(rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getDependentSliceArgument()) 1010 { 1011 bEntropyLimit=true; 1012 } 1013 } 1014 #if !REMOVE_FGS 1015 if(rpcBestCU->getDepth(0)>=rpcBestCU->getSlice()->getPPS()->getSliceGranularity()) 1016 #endif 1017 { 1018 bSliceLimit=false; 1019 bEntropyLimit=false; 1020 } 1021 if(bSliceLimit||bEntropyLimit) 993 Bool isEndOfSlice = rpcBestCU->getSlice()->getSliceMode()==FIXED_NUMBER_OF_BYTES 994 && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceArgument()<<3); 995 Bool isEndOfSliceSegment = rpcBestCU->getSlice()->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES 996 && (rpcBestCU->getTotalBits()>rpcBestCU->getSlice()->getSliceSegmentArgument()<<3); 997 if(isEndOfSlice||isEndOfSliceSegment) 1022 998 { 1023 999 rpcBestCU->getTotalCost()=rpcTempCU->getTotalCost()+1; … … 1025 1001 xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth); // RD compare current larger prediction 1026 1002 } // with sub partitioned prediction. 1027 1028 1029 1030 1003 if (isAddLowestQP && (iQP == lowestQP)) 1004 { 1005 iQP = iMinQP; 1006 } 1031 1007 } 1032 1008 … … 1060 1036 UInt uiCUAddr = pcCU->getSCUAddr()+uiAbsPartIdx; 1061 1037 1062 UInt uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->get DependentSliceCurEndCUAddr()-1) % pcPic->getNumPartInCU();1063 UInt uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->get DependentSliceCurEndCUAddr()-1) / pcPic->getNumPartInCU();1038 UInt uiInternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) % pcPic->getNumPartInCU(); 1039 UInt uiExternalAddress = pcPic->getPicSym()->getPicSCUAddr(pcSlice->getSliceSegmentCurEndCUAddr()-1) / pcPic->getNumPartInCU(); 1064 1040 UInt uiPosX = ( uiExternalAddress % pcPic->getFrameWidthInCU() ) * g_uiMaxCUWidth+ g_auiRasterToPelX[ g_auiZscanToRaster[uiInternalAddress] ]; 1065 1041 UInt uiPosY = ( uiExternalAddress / pcPic->getFrameWidthInCU() ) * g_uiMaxCUHeight+ g_auiRasterToPelY[ g_auiZscanToRaster[uiInternalAddress] ]; … … 1086 1062 bTerminateSlice = true; 1087 1063 } 1088 #if REMOVE_FGS1089 1064 UInt uiGranularityWidth = g_uiMaxCUWidth; 1090 #else1091 UInt uiGranularityWidth = g_uiMaxCUWidth>>(pcSlice->getPPS()->getSliceGranularity());1092 #endif1093 1065 uiPosX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; 1094 1066 uiPosY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; … … 1096 1068 &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight)); 1097 1069 1098 if(granularityBoundary && (!(pcCU->getIPCMFlag(uiAbsPartIdx) && ( pcCU->getNumSucIPCM() > 1 ))))1070 if(granularityBoundary) 1099 1071 { 1100 1072 // The 1-terminating bit is added to all streams, so don't add it here when it's 1. … … 1110 1082 1111 1083 // Calculate slice end IF this CU puts us over slice bit size. 1112 #if REMOVE_FGS 1113 unsigned iGranularitySize = pcCU->getPic()->getNumPartInCU(); 1114 #else 1115 unsigned iGranularitySize = pcCU->getPic()->getNumPartInCU()>>(pcSlice->getPPS()->getSliceGranularity()<<1); 1116 #endif 1117 int iGranularityEnd = ((pcCU->getSCUAddr()+uiAbsPartIdx)/iGranularitySize)*iGranularitySize; 1118 if(iGranularityEnd<=pcSlice->getDependentSliceCurStartCUAddr()) 1084 UInt iGranularitySize = pcCU->getPic()->getNumPartInCU(); 1085 Int iGranularityEnd = ((pcCU->getSCUAddr()+uiAbsPartIdx)/iGranularitySize)*iGranularitySize; 1086 if(iGranularityEnd<=pcSlice->getSliceSegmentCurStartCUAddr()) 1119 1087 { 1120 1088 iGranularityEnd+=max(iGranularitySize,(pcCU->getPic()->getNumPartInCU()>>(uiDepth<<1))); 1121 1089 } 1122 1090 // Set slice end parameter 1123 if(pcSlice->getSliceMode()== AD_HOC_SLICES_FIXED_NUMBER_OF_BYTES_IN_SLICE&&!pcSlice->getFinalized()&&pcSlice->getSliceBits()+numberOfWrittenBits>pcSlice->getSliceArgument()<<3)1124 { 1125 pcSlice->set DependentSliceCurEndCUAddr(iGranularityEnd);1091 if(pcSlice->getSliceMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceBits()+numberOfWrittenBits>pcSlice->getSliceArgument()<<3) 1092 { 1093 pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd); 1126 1094 pcSlice->setSliceCurEndCUAddr(iGranularityEnd); 1127 1095 return; 1128 1096 } 1129 1097 // Set dependent slice end parameter 1130 if(m_pcEncCfg->getUseSBACRD()) 1131 { 1132 TEncBinCABAC *pppcRDSbacCoder = (TEncBinCABAC *) m_pppcRDSbacCoder[0][CI_CURR_BEST]->getEncBinIf(); 1133 UInt uiBinsCoded = pppcRDSbacCoder->getBinsCoded(); 1134 if(pcSlice->getDependentSliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_DEPENDENT_SLICE&&!pcSlice->getFinalized()&&pcSlice->getDependentSliceCounter()+uiBinsCoded>pcSlice->getDependentSliceArgument()) 1135 { 1136 pcSlice->setDependentSliceCurEndCUAddr(iGranularityEnd); 1137 return; 1138 } 1139 } 1140 else 1141 { 1142 if(pcSlice->getDependentSliceMode()==SHARP_MULTIPLE_CONSTRAINT_BASED_DEPENDENT_SLICE&&!pcSlice->getFinalized()&&pcSlice->getDependentSliceCounter()+numberOfWrittenBits>pcSlice->getDependentSliceArgument()) 1143 { 1144 pcSlice->setDependentSliceCurEndCUAddr(iGranularityEnd); 1145 return; 1146 } 1098 if(pcSlice->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES&&!pcSlice->getFinalized()&&pcSlice->getSliceSegmentBits()+numberOfWrittenBits > pcSlice->getSliceSegmentArgument()<<3) 1099 { 1100 pcSlice->setSliceSegmentCurEndCUAddr(iGranularityEnd); 1101 return; 1147 1102 } 1148 1103 if(granularityBoundary) 1149 1104 { 1150 1105 pcSlice->setSliceBits( (UInt)(pcSlice->getSliceBits() + numberOfWrittenBits) ); 1151 if(m_pcEncCfg->getUseSBACRD()) 1152 { 1153 TEncBinCABAC *pppcRDSbacCoder = (TEncBinCABAC *) m_pppcRDSbacCoder[0][CI_CURR_BEST]->getEncBinIf(); 1154 pcSlice->setDependentSliceCounter(pcSlice->getDependentSliceCounter()+pppcRDSbacCoder->getBinsCoded()); 1155 pppcRDSbacCoder->setBinsCoded( 0 ); 1156 } 1157 else 1158 { 1159 pcSlice->setDependentSliceCounter(pcSlice->getDependentSliceCounter()+numberOfWrittenBits); 1160 } 1106 pcSlice->setSliceSegmentBits(pcSlice->getSliceSegmentBits()+numberOfWrittenBits); 1161 1107 if (m_pcBitCounter) 1162 1108 { … … 1211 1157 UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; 1212 1158 1213 if( getCheckBurstIPCMFlag() )1214 {1215 pcCU->setLastCUSucIPCMFlag( checkLastCUSucIPCM( pcCU, uiAbsPartIdx ));1216 pcCU->setNumSucIPCM( countNumSucIPCM ( pcCU, uiAbsPartIdx ) );1217 }1218 1219 1159 TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); 1220 1160 // If slice start is within this cu... 1221 Bool bSliceStart = pcSlice->get DependentSliceCurStartCUAddr() > pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx &&1222 pcSlice->get DependentSliceCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) );1161 Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && 1162 pcSlice->getSliceSegmentCurStartCUAddr() < pcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcPic->getNumPartInCU() >> (uiDepth<<1) ); 1223 1163 // We need to split, so don't try these modes. 1224 1164 if(!bSliceStart&&( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) … … 1238 1178 setdQPFlag(true); 1239 1179 } 1240 pcCU->setNumSucIPCM(0);1241 pcCU->setLastCUSucIPCMFlag(false);1242 1180 for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) 1243 1181 { 1244 1182 uiLPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[uiAbsPartIdx] ]; 1245 1183 uiTPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[uiAbsPartIdx] ]; 1246 Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->get DependentSliceCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getDependentSliceCurEndCUAddr();1184 Bool bInSlice = pcCU->getSCUAddr()+uiAbsPartIdx+uiQNumParts>pcSlice->getSliceSegmentCurStartCUAddr()&&pcCU->getSCUAddr()+uiAbsPartIdx<pcSlice->getSliceSegmentCurEndCUAddr(); 1247 1185 if(bInSlice&&( uiLPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) 1248 1186 { … … 1268 1206 if( pcCU->isSkipped( uiAbsPartIdx ) ) 1269 1207 { 1270 m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx , 0);1208 m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx ); 1271 1209 finishCU(pcCU,uiAbsPartIdx,uiDepth); 1272 1210 return; … … 1327 1265 rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level 1328 1266 rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth ); 1329 rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth,cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );1267 rpcTempCU->getInterMergeCandidates( 0, 0, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand ); 1330 1268 1331 1269 Int mergeCandBuffer[MRG_MAX_NUM_CANDS]; … … 1391 1329 } 1392 1330 1393 #if SKIP_FLAG1394 1331 rpcTempCU->setSkipFlagSubParts( rpcTempCU->getQtRootCbf(0) == 0, 0, uhDepth ); 1395 #endif1396 1332 Int orgQP = rpcTempCU->getQP( 0 ); 1397 1333 xCheckDQP( rpcTempCU ); … … 1408 1344 } 1409 1345 #if REF_IDX_ME_ZEROMV 1410 }1411 #endif1412 1346 } 1347 #endif 1348 } 1413 1349 1414 1350 if(uiNoResidual == 0 && m_pcEncCfg->getUseEarlySkipDetection()) … … 1455 1391 rpcTempCU->setDepthSubParts( uhDepth, 0 ); 1456 1392 1457 #if SKIP_FLAG1458 1393 rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); 1459 #endif1460 1394 1461 1395 rpcTempCU->setPartSizeSubParts ( ePartSize, 0, uhDepth ); … … 1477 1411 #endif 1478 1412 1413 #if RATE_CONTROL_LAMBDA_DOMAIN 1414 if ( m_pcEncCfg->getUseRateCtrl() && m_pcEncCfg->getLCULevelRC() && ePartSize == SIZE_2Nx2N && uhDepth <= m_addSADDepth ) 1415 { 1416 UInt SAD = m_pcRdCost->getSADPart( g_bitDepthY, m_ppcPredYuvTemp[uhDepth]->getLumaAddr(), m_ppcPredYuvTemp[uhDepth]->getStride(), 1417 m_ppcOrigYuv[uhDepth]->getLumaAddr(), m_ppcOrigYuv[uhDepth]->getStride(), 1418 rpcTempCU->getWidth(0), rpcTempCU->getHeight(0) ); 1419 m_temporalSAD = (Int)SAD; 1420 } 1421 #endif 1422 1479 1423 m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); 1480 1424 rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); … … 1483 1427 xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); 1484 1428 } 1485 #if (ENCODER_FAST_MODE) 1486 Void TEncCu::xCheckRDCostILRUni(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU) 1487 { 1488 UChar uhDepth = rpcTempCU->getDepth( 0 ); 1489 1490 rpcTempCU->setDepthSubParts( uhDepth, 0 ); 1491 1492 #if SKIP_FLAG 1493 rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); 1494 #endif 1495 1496 rpcTempCU->setPartSizeSubParts ( SIZE_2Nx2N, 0, uhDepth ); //2Nx2N 1497 rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); 1498 rpcTempCU->setCUTransquantBypassSubParts ( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth ); 1499 1500 Bool exitILR = m_pcPredSearch->predInterSearchILRUni( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); 1501 1502 if(!exitILR) 1503 return; 1504 1505 m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); 1506 1507 rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); 1508 1509 xCheckDQP( rpcTempCU ); 1510 xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); 1511 1512 return; 1513 } 1514 #endif 1429 1515 1430 Void TEncCu::xCheckRDCostIntra( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, PartSize eSize ) 1516 1431 { 1517 1432 UInt uiDepth = rpcTempCU->getDepth( 0 ); 1518 1433 1519 #if SKIP_FLAG1520 1434 rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); 1521 #endif1522 1435 1523 1436 rpcTempCU->setPartSizeSubParts( eSize, 0, uiDepth ); … … 1568 1481 xCheckBestMode(rpcBestCU, rpcTempCU, uiDepth); 1569 1482 } 1483 1484 /** Check R-D costs for a CU with PCM mode. 1485 * \param rpcBestCU pointer to best mode CU data structure 1486 * \param rpcTempCU pointer to testing mode CU data structure 1487 * \returns Void 1488 * 1489 * \note Current PCM implementation encodes sample values in a lossless way. The distortion of PCM mode CUs are zero. PCM mode is selected if the best mode yields bits greater than that of PCM mode. 1490 */ 1491 Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) 1492 { 1493 UInt uiDepth = rpcTempCU->getDepth( 0 ); 1494 1495 rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); 1496 1497 rpcTempCU->setIPCMFlag(0, true); 1498 rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0)); 1499 rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); 1500 rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); 1501 rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth ); 1502 rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth ); 1503 1504 m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); 1505 1506 if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); 1507 1508 m_pcEntropyCoder->resetBits(); 1509 #if INTRA_BL 1510 m_pcEntropyCoder->encodeIntraBLFlag ( rpcTempCU, 0, true ); 1511 #endif 1512 if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) 1513 { 1514 m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); 1515 } 1516 m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); 1517 m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true ); 1518 m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true ); 1519 m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); 1520 1521 if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); 1522 1523 rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); 1524 if(m_pcEncCfg->getUseSBACRD()) 1525 { 1526 rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 1527 } 1528 rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); 1529 1530 xCheckDQP( rpcTempCU ); 1531 xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); 1532 } 1533 1534 /** check whether current try is the best with identifying the depth of current try 1535 * \param rpcBestCU 1536 * \param rpcTempCU 1537 * \returns Void 1538 */ 1539 Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) 1540 { 1541 if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) 1542 { 1543 TComYuv* pcYuv; 1544 // Change Information data 1545 TComDataCU* pcCU = rpcBestCU; 1546 rpcBestCU = rpcTempCU; 1547 rpcTempCU = pcCU; 1548 1549 // Change Prediction data 1550 pcYuv = m_ppcPredYuvBest[uiDepth]; 1551 m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth]; 1552 m_ppcPredYuvTemp[uiDepth] = pcYuv; 1553 1554 // Change Reconstruction data 1555 pcYuv = m_ppcRecoYuvBest[uiDepth]; 1556 m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth]; 1557 m_ppcRecoYuvTemp[uiDepth] = pcYuv; 1558 1559 pcYuv = NULL; 1560 pcCU = NULL; 1561 1562 if( m_bUseSBACRD ) // store temp best CI for next CU coding 1563 m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); 1564 } 1565 } 1566 1567 Void TEncCu::xCheckDQP( TComDataCU* pcCU ) 1568 { 1569 UInt uiDepth = pcCU->getDepth( 0 ); 1570 1571 if( pcCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() ) 1572 { 1573 if ( pcCU->getCbf( 0, TEXT_LUMA, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_U, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_V, 0 ) ) 1574 { 1575 #if !RDO_WITHOUT_DQP_BITS 1576 m_pcEntropyCoder->resetBits(); 1577 m_pcEntropyCoder->encodeQP( pcCU, 0, false ); 1578 pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits 1579 if(m_pcEncCfg->getUseSBACRD()) 1580 { 1581 pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 1582 } 1583 pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); 1584 #endif 1585 } 1586 else 1587 { 1588 pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP 1589 } 1590 } 1591 } 1592 1593 Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) 1594 { 1595 pDst->iN = pSrc->iN; 1596 for (Int i = 0; i < pSrc->iN; i++) 1597 { 1598 pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; 1599 } 1600 } 1601 Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY ) 1602 { 1603 UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; 1604 UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; 1605 TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); 1606 Bool bSliceStart = pcSlice->getSliceSegmentCurStartCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && 1607 pcSlice->getSliceSegmentCurStartCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); 1608 Bool bSliceEnd = pcSlice->getSliceSegmentCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && 1609 pcSlice->getSliceSegmentCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); 1610 if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) 1611 { 1612 UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx]; 1613 UInt uiSrcBlkWidth = rpcPic->getNumPartInWidth() >> (uiSrcDepth); 1614 UInt uiBlkWidth = rpcPic->getNumPartInWidth() >> (uiDepth); 1615 UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; 1616 UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; 1617 UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX; 1618 m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); 1619 } 1620 else 1621 { 1622 UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) )>>2; 1623 1624 for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) 1625 { 1626 UInt uiSubCULPelX = uiLPelX + ( g_uiMaxCUWidth >>(uiDepth+1) )*( uiPartUnitIdx & 1 ); 1627 UInt uiSubCUTPelY = uiTPelY + ( g_uiMaxCUHeight>>(uiDepth+1) )*( uiPartUnitIdx >> 1 ); 1628 1629 Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getSliceSegmentCurStartCUAddr() && 1630 rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getSliceSegmentCurEndCUAddr(); 1631 if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) 1632 { 1633 xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY ); // Copy Yuv data to picture Yuv 1634 } 1635 } 1636 } 1637 } 1638 1639 Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) 1640 { 1641 UInt uiCurrDepth = uiNextDepth - 1; 1642 m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); 1643 } 1644 1645 /** Function for filling the PCM buffer of a CU using its original sample array 1646 * \param pcCU pointer to current CU 1647 * \param pcOrgYuv pointer to original sample array 1648 * \returns Void 1649 */ 1650 Void TEncCu::xFillPCMBuffer ( TComDataCU*& pCU, TComYuv* pOrgYuv ) 1651 { 1652 1653 UInt width = pCU->getWidth(0); 1654 UInt height = pCU->getHeight(0); 1655 1656 Pel* pSrcY = pOrgYuv->getLumaAddr(0, width); 1657 Pel* pDstY = pCU->getPCMSampleY(); 1658 UInt srcStride = pOrgYuv->getStride(); 1659 1660 for(Int y = 0; y < height; y++ ) 1661 { 1662 for(Int x = 0; x < width; x++ ) 1663 { 1664 pDstY[x] = pSrcY[x]; 1665 } 1666 pDstY += width; 1667 pSrcY += srcStride; 1668 } 1669 1670 Pel* pSrcCb = pOrgYuv->getCbAddr(); 1671 Pel* pSrcCr = pOrgYuv->getCrAddr();; 1672 1673 Pel* pDstCb = pCU->getPCMSampleCb(); 1674 Pel* pDstCr = pCU->getPCMSampleCr();; 1675 1676 UInt srcStrideC = pOrgYuv->getCStride(); 1677 UInt heightC = height >> 1; 1678 UInt widthC = width >> 1; 1679 1680 for(Int y = 0; y < heightC; y++ ) 1681 { 1682 for(Int x = 0; x < widthC; x++ ) 1683 { 1684 pDstCb[x] = pSrcCb[x]; 1685 pDstCr[x] = pSrcCr[x]; 1686 } 1687 pDstCb += widthC; 1688 pDstCr += widthC; 1689 pSrcCb += srcStrideC; 1690 pSrcCr += srcStrideC; 1691 } 1692 } 1693 1694 #if ADAPTIVE_QP_SELECTION 1695 /** Collect ARL statistics from one block 1696 */ 1697 Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, Int* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ) 1698 { 1699 for( Int n = 0; n < NumCoeffInCU; n++ ) 1700 { 1701 Int u = abs( rpcCoeff[ n ] ); 1702 Int absc = rpcArlCoeff[ n ]; 1703 1704 if( u != 0 ) 1705 { 1706 if( u < LEVEL_RANGE ) 1707 { 1708 cSum[ u ] += ( Double )absc; 1709 numSamples[ u ]++; 1710 } 1711 else 1712 { 1713 cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION ); 1714 numSamples[ LEVEL_RANGE ]++; 1715 } 1716 } 1717 } 1718 1719 return 0; 1720 } 1721 1722 /** Collect ARL statistics from one LCU 1723 * \param pcCU 1724 */ 1725 Void TEncCu::xLcuCollectARLStats(TComDataCU* rpcCU ) 1726 { 1727 Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to datatype and quantization output 1728 UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output 1729 1730 TCoeff* pCoeffY = rpcCU->getCoeffY(); 1731 Int* pArlCoeffY = rpcCU->getArlCoeffY(); 1732 1733 UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth; 1734 UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; 1735 1736 memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) ); 1737 memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) ); 1738 1739 // Collect stats to cSum[][] and numSamples[][] 1740 for(Int i = 0; i < rpcCU->getTotalNumPart(); i ++ ) 1741 { 1742 UInt uiTrIdx = rpcCU->getTransformIdx(i); 1743 1744 if(rpcCU->getPredictionMode(i) == MODE_INTER) 1745 if( rpcCU->getCbf( i, TEXT_LUMA, uiTrIdx ) ) 1746 { 1747 xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples); 1748 }//Note that only InterY is processed. QP rounding is based on InterY data only. 1749 1750 pCoeffY += uiMinNumCoeffInCU; 1751 pArlCoeffY += uiMinNumCoeffInCU; 1752 } 1753 1754 for(Int u=1; u<LEVEL_RANGE;u++) 1755 { 1756 m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ; 1757 m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ; 1758 } 1759 m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ; 1760 m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ; 1761 } 1762 #endif 1763 1570 1764 #if INTRA_BL 1571 1765 Void TEncCu::xCheckRDCostIntraBL( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) 1572 1766 { 1573 1767 UInt uiDepth = rpcTempCU->getDepth( 0 ); 1574 #if SKIP_FLAG 1575 rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); 1576 #endif 1577 1768 rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); 1578 1769 rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); 1579 1770 rpcTempCU->setPredModeSubParts( MODE_INTRA_BL, 0, uiDepth ); … … 1622 1813 #endif 1623 1814 1624 1625 /** Check R-D costs for a CU with PCM mode. 1626 * \param rpcBestCU pointer to best mode CU data structure 1627 * \param rpcTempCU pointer to testing mode CU data structure 1628 * \returns Void 1629 * 1630 * \note Current PCM implementation encodes sample values in a lossless way. The distortion of PCM mode CUs are zero. PCM mode is selected if the best mode yields bits greater than that of PCM mode. 1631 */ 1632 Void TEncCu::xCheckIntraPCM( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) 1633 { 1634 UInt uiDepth = rpcTempCU->getDepth( 0 ); 1635 1636 rpcTempCU->setCUTransquantBypassSubParts(false, 0, uiDepth); 1815 #if (ENCODER_FAST_MODE) 1816 Void TEncCu::xCheckRDCostILRUni(TComDataCU *&rpcBestCU, TComDataCU *&rpcTempCU) 1817 { 1818 UChar uhDepth = rpcTempCU->getDepth( 0 ); 1819 1820 rpcTempCU->setDepthSubParts( uhDepth, 0 ); 1637 1821 1638 1822 #if SKIP_FLAG 1639 rpcTempCU->setSkipFlagSubParts( false, 0, uiDepth ); 1640 #endif 1641 1642 rpcTempCU->setIPCMFlag(0, true); 1643 rpcTempCU->setIPCMFlagSubParts (true, 0, rpcTempCU->getDepth(0)); 1644 rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uiDepth ); 1645 rpcTempCU->setPredModeSubParts( MODE_INTRA, 0, uiDepth ); 1646 rpcTempCU->setTrIdxSubParts ( 0, 0, uiDepth ); 1647 rpcTempCU->setCUTransquantBypassSubParts( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uiDepth ); 1648 1649 m_pcPredSearch->IPCMSearch( rpcTempCU, m_ppcOrigYuv[uiDepth], m_ppcPredYuvTemp[uiDepth], m_ppcResiYuvTemp[uiDepth], m_ppcRecoYuvTemp[uiDepth]); 1650 1651 if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->load(m_pppcRDSbacCoder[uiDepth][CI_CURR_BEST]); 1652 1653 m_pcEntropyCoder->resetBits(); 1654 #if INTRA_BL 1655 m_pcEntropyCoder->encodeIntraBLFlag ( rpcTempCU, 0, true ); 1656 #endif 1657 if ( rpcTempCU->getSlice()->getPPS()->getTransquantBypassEnableFlag()) 1658 { 1659 m_pcEntropyCoder->encodeCUTransquantBypassFlag( rpcTempCU, 0, true ); 1660 } 1661 m_pcEntropyCoder->encodeSkipFlag ( rpcTempCU, 0, true ); 1662 m_pcEntropyCoder->encodePredMode ( rpcTempCU, 0, true ); 1663 m_pcEntropyCoder->encodePartSize ( rpcTempCU, 0, uiDepth, true ); 1664 m_pcEntropyCoder->encodeIPCMInfo ( rpcTempCU, 0, true ); 1665 1666 if( m_bUseSBACRD ) m_pcRDGoOnSbacCoder->store(m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]); 1667 1668 rpcTempCU->getTotalBits() = m_pcEntropyCoder->getNumberOfWrittenBits(); 1669 if(m_pcEncCfg->getUseSBACRD()) 1670 { 1671 rpcTempCU->getTotalBins() = ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 1672 } 1673 rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); 1823 rpcTempCU->setSkipFlagSubParts( false, 0, uhDepth ); 1824 #endif 1825 1826 rpcTempCU->setPartSizeSubParts ( SIZE_2Nx2N, 0, uhDepth ); //2Nx2N 1827 rpcTempCU->setPredModeSubParts ( MODE_INTER, 0, uhDepth ); 1828 rpcTempCU->setCUTransquantBypassSubParts ( m_pcEncCfg->getCUTransquantBypassFlagValue(), 0, uhDepth ); 1829 1830 Bool exitILR = m_pcPredSearch->predInterSearchILRUni( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth] ); 1831 1832 if(!exitILR) 1833 { 1834 return; 1835 } 1836 1837 m_pcPredSearch->encodeResAndCalcRdInterCU( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcResiYuvBest[uhDepth], m_ppcRecoYuvTemp[uhDepth], false ); 1838 1839 rpcTempCU->getTotalCost() = m_pcRdCost->calcRdCost( rpcTempCU->getTotalBits(), rpcTempCU->getTotalDistortion() ); 1674 1840 1675 1841 xCheckDQP( rpcTempCU ); 1676 xCheckBestMode( rpcBestCU, rpcTempCU, uiDepth ); 1677 } 1678 1679 // check whether current try is the best 1680 Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU ) 1681 { 1682 if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) 1683 { 1684 TComYuv* pcYuv; 1685 UChar uhDepth = rpcBestCU->getDepth(0); 1686 1687 // Change Information data 1688 TComDataCU* pcCU = rpcBestCU; 1689 rpcBestCU = rpcTempCU; 1690 rpcTempCU = pcCU; 1691 1692 // Change Prediction data 1693 pcYuv = m_ppcPredYuvBest[uhDepth]; 1694 m_ppcPredYuvBest[uhDepth] = m_ppcPredYuvTemp[uhDepth]; 1695 m_ppcPredYuvTemp[uhDepth] = pcYuv; 1696 1697 // Change Reconstruction data 1698 pcYuv = m_ppcRecoYuvBest[uhDepth]; 1699 m_ppcRecoYuvBest[uhDepth] = m_ppcRecoYuvTemp[uhDepth]; 1700 m_ppcRecoYuvTemp[uhDepth] = pcYuv; 1701 1702 pcYuv = NULL; 1703 pcCU = NULL; 1704 1705 if( m_bUseSBACRD ) // store temp best CI for next CU coding 1706 m_pppcRDSbacCoder[uhDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uhDepth][CI_NEXT_BEST]); 1707 } 1708 } 1709 1710 /** check whether current try is the best with identifying the depth of current try 1711 * \param rpcBestCU 1712 * \param rpcTempCU 1713 * \returns Void 1714 */ 1715 Void TEncCu::xCheckBestMode( TComDataCU*& rpcBestCU, TComDataCU*& rpcTempCU, UInt uiDepth ) 1716 { 1717 if( rpcTempCU->getTotalCost() < rpcBestCU->getTotalCost() ) 1718 { 1719 TComYuv* pcYuv; 1720 // Change Information data 1721 TComDataCU* pcCU = rpcBestCU; 1722 rpcBestCU = rpcTempCU; 1723 rpcTempCU = pcCU; 1724 1725 // Change Prediction data 1726 pcYuv = m_ppcPredYuvBest[uiDepth]; 1727 m_ppcPredYuvBest[uiDepth] = m_ppcPredYuvTemp[uiDepth]; 1728 m_ppcPredYuvTemp[uiDepth] = pcYuv; 1729 1730 // Change Reconstruction data 1731 pcYuv = m_ppcRecoYuvBest[uiDepth]; 1732 m_ppcRecoYuvBest[uiDepth] = m_ppcRecoYuvTemp[uiDepth]; 1733 m_ppcRecoYuvTemp[uiDepth] = pcYuv; 1734 1735 pcYuv = NULL; 1736 pcCU = NULL; 1737 1738 if( m_bUseSBACRD ) // store temp best CI for next CU coding 1739 m_pppcRDSbacCoder[uiDepth][CI_TEMP_BEST]->store(m_pppcRDSbacCoder[uiDepth][CI_NEXT_BEST]); 1740 } 1741 } 1742 1743 Void TEncCu::xCheckDQP( TComDataCU* pcCU ) 1744 { 1745 UInt uiDepth = pcCU->getDepth( 0 ); 1746 1747 if( pcCU->getSlice()->getPPS()->getUseDQP() && (g_uiMaxCUWidth>>uiDepth) >= pcCU->getSlice()->getPPS()->getMinCuDQPSize() ) 1748 { 1749 if ( pcCU->getCbf( 0, TEXT_LUMA, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_U, 0 ) || pcCU->getCbf( 0, TEXT_CHROMA_V, 0 ) ) 1750 { 1751 #if !RDO_WITHOUT_DQP_BITS 1752 m_pcEntropyCoder->resetBits(); 1753 m_pcEntropyCoder->encodeQP( pcCU, 0, false ); 1754 pcCU->getTotalBits() += m_pcEntropyCoder->getNumberOfWrittenBits(); // dQP bits 1755 if(m_pcEncCfg->getUseSBACRD()) 1756 { 1757 pcCU->getTotalBins() += ((TEncBinCABAC *)((TEncSbac*)m_pcEntropyCoder->m_pcEntropyCoderIf)->getEncBinIf())->getBinsCoded(); 1758 } 1759 pcCU->getTotalCost() = m_pcRdCost->calcRdCost( pcCU->getTotalBits(), pcCU->getTotalDistortion() ); 1760 #endif 1761 } 1762 else 1763 { 1764 pcCU->setQPSubParts( pcCU->getRefQP( 0 ), 0, uiDepth ); // set QP to default QP 1765 } 1766 } 1767 } 1768 1769 /** Check whether the last CU shares the same root as the current CU and is IPCM or not. 1770 * \param pcCU 1771 * \param uiCurAbsPartIdx 1772 * \returns Bool 1773 */ 1774 Bool TEncCu::checkLastCUSucIPCM( TComDataCU* pcCU, UInt uiCurAbsPartIdx ) 1775 { 1776 Bool lastCUSucIPCMFlag = false; 1777 1778 UInt curDepth = pcCU->getDepth(uiCurAbsPartIdx); 1779 UInt shift = ((pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx())->getSPS()->getMaxCUDepth() - curDepth)<<1); 1780 UInt startPartUnitIdx = ((uiCurAbsPartIdx&(0x03<<shift))>>shift); 1781 1782 TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); 1783 if( pcSlice->getDependentSliceCurStartCUAddr() == ( pcCU->getSCUAddr() + uiCurAbsPartIdx ) ) 1784 { 1785 return false; 1786 } 1787 1788 if(curDepth > 0 && startPartUnitIdx > 0) 1789 { 1790 Int lastValidPartIdx = pcCU->getLastValidPartIdx((Int) uiCurAbsPartIdx ); 1791 1792 if( lastValidPartIdx >= 0 ) 1793 { 1794 if(( pcCU->getSliceStartCU( uiCurAbsPartIdx ) == pcCU->getSliceStartCU( (UInt) lastValidPartIdx )) 1795 && 1796 ( pcCU->getDepth( uiCurAbsPartIdx ) == pcCU->getDepth( (UInt) lastValidPartIdx )) 1797 && 1798 pcCU->getIPCMFlag( (UInt) lastValidPartIdx ) ) 1799 { 1800 lastCUSucIPCMFlag = true; 1801 } 1802 } 1803 } 1804 1805 return lastCUSucIPCMFlag; 1806 } 1807 1808 /** Count the number of successive IPCM CUs sharing the same root. 1809 * \param pcCU 1810 * \param uiCurAbsPartIdx 1811 * \returns Int 1812 */ 1813 Int TEncCu::countNumSucIPCM ( TComDataCU* pcCU, UInt uiCurAbsPartIdx ) 1814 { 1815 Int numSucIPCM = 0; 1816 UInt CurDepth = pcCU->getDepth(uiCurAbsPartIdx); 1817 1818 if( pcCU->getIPCMFlag(uiCurAbsPartIdx) ) 1819 { 1820 if(CurDepth == 0) 1821 { 1822 numSucIPCM = 1; 1823 } 1824 else 1825 { 1826 TComPic* pcPic = pcCU->getPic(); 1827 TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); 1828 UInt qNumParts = ( pcPic->getNumPartInCU() >> ((CurDepth-1)<<1) )>>2; 1829 1830 Bool continueFlag = true; 1831 UInt absPartIdx = uiCurAbsPartIdx; 1832 UInt shift = ((pcSlice->getSPS()->getMaxCUDepth() - CurDepth)<<1); 1833 UInt startPartUnitIdx = ((uiCurAbsPartIdx&(0x03<<shift))>>shift); 1834 1835 for ( UInt partUnitIdx = startPartUnitIdx; partUnitIdx < 4 && continueFlag; partUnitIdx++, absPartIdx+=qNumParts ) 1836 { 1837 UInt lPelX = pcCU->getCUPelX() + g_auiRasterToPelX[ g_auiZscanToRaster[absPartIdx] ]; 1838 UInt tPelY = pcCU->getCUPelY() + g_auiRasterToPelY[ g_auiZscanToRaster[absPartIdx] ]; 1839 Bool inSliceFlag = ( pcCU->getSCUAddr()+absPartIdx+qNumParts>pcSlice->getDependentSliceCurStartCUAddr() ) && ( pcCU->getSCUAddr()+absPartIdx < pcSlice->getDependentSliceCurEndCUAddr()); 1840 1841 if( inSliceFlag && ( lPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( tPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) 1842 { 1843 UInt uiDepth = pcCU->getDepth(absPartIdx); 1844 1845 if( ( CurDepth == uiDepth) && pcCU->getIPCMFlag( absPartIdx ) ) 1846 { 1847 numSucIPCM++; 1848 } 1849 else 1850 { 1851 continueFlag = false; 1852 } 1853 } 1854 } 1855 } 1856 } 1857 1858 return numSucIPCM; 1859 } 1860 1861 Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst) 1862 { 1863 pDst->iN = pSrc->iN; 1864 for (Int i = 0; i < pSrc->iN; i++) 1865 { 1866 pDst->m_acMvCand[i] = pSrc->m_acMvCand[i]; 1867 } 1868 } 1869 Void TEncCu::xCopyYuv2Pic(TComPic* rpcPic, UInt uiCUAddr, UInt uiAbsPartIdx, UInt uiDepth, UInt uiSrcDepth, TComDataCU* pcCU, UInt uiLPelX, UInt uiTPelY ) 1870 { 1871 UInt uiRPelX = uiLPelX + (g_uiMaxCUWidth>>uiDepth) - 1; 1872 UInt uiBPelY = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1; 1873 TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx()); 1874 Bool bSliceStart = pcSlice->getDependentSliceCurStartCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && 1875 pcSlice->getDependentSliceCurStartCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); 1876 Bool bSliceEnd = pcSlice->getDependentSliceCurEndCUAddr() > rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx && 1877 pcSlice->getDependentSliceCurEndCUAddr() < rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) ); 1878 if(!bSliceEnd && !bSliceStart && ( uiRPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiBPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) 1879 { 1880 UInt uiAbsPartIdxInRaster = g_auiZscanToRaster[uiAbsPartIdx]; 1881 UInt uiSrcBlkWidth = rpcPic->getNumPartInWidth() >> (uiSrcDepth); 1882 UInt uiBlkWidth = rpcPic->getNumPartInWidth() >> (uiDepth); 1883 UInt uiPartIdxX = ( ( uiAbsPartIdxInRaster % rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; 1884 UInt uiPartIdxY = ( ( uiAbsPartIdxInRaster / rpcPic->getNumPartInWidth() ) % uiSrcBlkWidth) / uiBlkWidth; 1885 UInt uiPartIdx = uiPartIdxY * ( uiSrcBlkWidth / uiBlkWidth ) + uiPartIdxX; 1886 m_ppcRecoYuvBest[uiSrcDepth]->copyToPicYuv( rpcPic->getPicYuvRec (), uiCUAddr, uiAbsPartIdx, uiDepth - uiSrcDepth, uiPartIdx); 1887 } 1888 else 1889 { 1890 UInt uiQNumParts = ( pcCU->getPic()->getNumPartInCU() >> (uiDepth<<1) )>>2; 1891 1892 for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts ) 1893 { 1894 UInt uiSubCULPelX = uiLPelX + ( g_uiMaxCUWidth >>(uiDepth+1) )*( uiPartUnitIdx & 1 ); 1895 UInt uiSubCUTPelY = uiTPelY + ( g_uiMaxCUHeight>>(uiDepth+1) )*( uiPartUnitIdx >> 1 ); 1896 1897 Bool bInSlice = rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx+uiQNumParts > pcSlice->getDependentSliceCurStartCUAddr() && 1898 rpcPic->getPicSym()->getInverseCUOrderMap(pcCU->getAddr())*pcCU->getPic()->getNumPartInCU()+uiAbsPartIdx < pcSlice->getDependentSliceCurEndCUAddr(); 1899 if(bInSlice&&( uiSubCULPelX < pcSlice->getSPS()->getPicWidthInLumaSamples() ) && ( uiSubCUTPelY < pcSlice->getSPS()->getPicHeightInLumaSamples() ) ) 1900 { 1901 xCopyYuv2Pic( rpcPic, uiCUAddr, uiAbsPartIdx, uiDepth+1, uiSrcDepth, pcCU, uiSubCULPelX, uiSubCUTPelY ); // Copy Yuv data to picture Yuv 1902 } 1903 } 1904 } 1905 } 1906 1907 Void TEncCu::xCopyYuv2Tmp( UInt uiPartUnitIdx, UInt uiNextDepth ) 1908 { 1909 UInt uiCurrDepth = uiNextDepth - 1; 1910 m_ppcRecoYuvBest[uiNextDepth]->copyToPartYuv( m_ppcRecoYuvTemp[uiCurrDepth], uiPartUnitIdx ); 1911 } 1912 1913 /** Function for filling the PCM buffer of a CU using its original sample array 1914 * \param pcCU pointer to current CU 1915 * \param pcOrgYuv pointer to original sample array 1916 * \returns Void 1917 */ 1918 Void TEncCu::xFillPCMBuffer ( TComDataCU*& pCU, TComYuv* pOrgYuv ) 1919 { 1920 1921 UInt width = pCU->getWidth(0); 1922 UInt height = pCU->getHeight(0); 1923 1924 Pel* pSrcY = pOrgYuv->getLumaAddr(0, width); 1925 Pel* pDstY = pCU->getPCMSampleY(); 1926 UInt srcStride = pOrgYuv->getStride(); 1927 1928 for(Int y = 0; y < height; y++ ) 1929 { 1930 for(Int x = 0; x < width; x++ ) 1931 { 1932 pDstY[x] = pSrcY[x]; 1933 } 1934 pDstY += width; 1935 pSrcY += srcStride; 1936 } 1937 1938 Pel* pSrcCb = pOrgYuv->getCbAddr(); 1939 Pel* pSrcCr = pOrgYuv->getCrAddr();; 1940 1941 Pel* pDstCb = pCU->getPCMSampleCb(); 1942 Pel* pDstCr = pCU->getPCMSampleCr();; 1943 1944 UInt srcStrideC = pOrgYuv->getCStride(); 1945 UInt heightC = height >> 1; 1946 UInt widthC = width >> 1; 1947 1948 for(Int y = 0; y < heightC; y++ ) 1949 { 1950 for(Int x = 0; x < widthC; x++ ) 1951 { 1952 pDstCb[x] = pSrcCb[x]; 1953 pDstCr[x] = pSrcCr[x]; 1954 } 1955 pDstCb += widthC; 1956 pDstCr += widthC; 1957 pSrcCb += srcStrideC; 1958 pSrcCr += srcStrideC; 1959 } 1960 } 1961 1962 #if ADAPTIVE_QP_SELECTION 1963 /** Collect ARL statistics from one block 1964 */ 1965 Int TEncCu::xTuCollectARLStats(TCoeff* rpcCoeff, Int* rpcArlCoeff, Int NumCoeffInCU, Double* cSum, UInt* numSamples ) 1966 { 1967 for( Int n = 0; n < NumCoeffInCU; n++ ) 1968 { 1969 Int u = abs( rpcCoeff[ n ] ); 1970 Int absc = rpcArlCoeff[ n ]; 1971 1972 if( u != 0 ) 1973 { 1974 if( u < LEVEL_RANGE ) 1975 { 1976 cSum[ u ] += ( Double )absc; 1977 numSamples[ u ]++; 1978 } 1979 else 1980 { 1981 cSum[ LEVEL_RANGE ] += ( Double )absc - ( Double )( u << ARL_C_PRECISION ); 1982 numSamples[ LEVEL_RANGE ]++; 1983 } 1984 } 1985 } 1986 1987 return 0; 1988 } 1989 1990 /** Collect ARL statistics from one LCU 1991 * \param pcCU 1992 */ 1993 Void TEncCu::xLcuCollectARLStats(TComDataCU* rpcCU ) 1994 { 1995 Double cSum[ LEVEL_RANGE + 1 ]; //: the sum of DCT coefficients corresponding to datatype and quantization output 1996 UInt numSamples[ LEVEL_RANGE + 1 ]; //: the number of coefficients corresponding to datatype and quantization output 1997 1998 TCoeff* pCoeffY = rpcCU->getCoeffY(); 1999 Int* pArlCoeffY = rpcCU->getArlCoeffY(); 2000 2001 UInt uiMinCUWidth = g_uiMaxCUWidth >> g_uiMaxCUDepth; 2002 UInt uiMinNumCoeffInCU = 1 << uiMinCUWidth; 2003 2004 memset( cSum, 0, sizeof( Double )*(LEVEL_RANGE+1) ); 2005 memset( numSamples, 0, sizeof( UInt )*(LEVEL_RANGE+1) ); 2006 2007 // Collect stats to cSum[][] and numSamples[][] 2008 for(Int i = 0; i < rpcCU->getTotalNumPart(); i ++ ) 2009 { 2010 UInt uiTrIdx = rpcCU->getTransformIdx(i); 2011 2012 if(rpcCU->getPredictionMode(i) == MODE_INTER) 2013 if( rpcCU->getCbf( i, TEXT_LUMA, uiTrIdx ) ) 2014 { 2015 xTuCollectARLStats(pCoeffY, pArlCoeffY, uiMinNumCoeffInCU, cSum, numSamples); 2016 }//Note that only InterY is processed. QP rounding is based on InterY data only. 2017 2018 pCoeffY += uiMinNumCoeffInCU; 2019 pArlCoeffY += uiMinNumCoeffInCU; 2020 } 2021 2022 for(Int u=1; u<LEVEL_RANGE;u++) 2023 { 2024 m_pcTrQuant->getSliceSumC()[u] += cSum[ u ] ; 2025 m_pcTrQuant->getSliceNSamples()[u] += numSamples[ u ] ; 2026 } 2027 m_pcTrQuant->getSliceSumC()[LEVEL_RANGE] += cSum[ LEVEL_RANGE ] ; 2028 m_pcTrQuant->getSliceNSamples()[LEVEL_RANGE] += numSamples[ LEVEL_RANGE ] ; 2029 } 2030 #endif 1842 xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth); 1843 1844 return; 1845 } 1846 #endif 1847 1848 2031 1849 //! \}
Note: See TracChangeset for help on using the changeset viewer.