Changeset 852 in 3DVCSoftware for branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncSlice.cpp
- Timestamp:
- 13 Feb 2014, 22:34:17 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HTM-10.0-dev0/source/Lib/TLibEncoder/TEncSlice.cpp
r773 r852 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-2013, ITU/ISO/IEC6 * Copyright (c) 2010-2014, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 266 266 267 267 eSliceType=B_SLICE; 268 eSliceType = (pocLast == 0 || pocCurr% m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;268 eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType; 269 269 270 270 rpcSlice->setSliceType ( eSliceType ); … … 296 296 if(eSliceType!=I_SLICE) 297 297 { 298 if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->get SPS()->getUseLossless())))298 if (!(( m_pcCfg->getMaxDeltaQP() == 0 ) && (dQP == -rpcSlice->getSPS()->getQpBDOffsetY() ) && (rpcSlice->getPPS()->getTransquantBypassEnableFlag()))) 299 299 { 300 300 #if H_MV … … 312 312 dQP += pdQPs[ rpcSlice->getPOC() ]; 313 313 } 314 #if !RATE_CONTROL_LAMBDA_DOMAIN315 if ( m_pcCfg->getUseRateCtrl())316 {317 dQP = m_pcRateCtrl->getFrameQP(rpcSlice->isReferenced(), rpcSlice->getPOC());318 }319 #endif320 314 // ------------------------------------------------------------------------------------------------------------------ 321 315 // Lambda computation … … 419 413 #endif 420 414 421 #if WEIGHTED_CHROMA_DISTORTION422 415 // for RDO 423 416 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 424 Double weight = 1.0;417 Double weight[2] = { 1.0, 1.0 }; 425 418 Int qpc; 426 419 Int chromaQPOffset; … … 428 421 chromaQPOffset = rpcSlice->getPPS()->getChromaCbQpOffset() + rpcSlice->getSliceQpDeltaCb(); 429 422 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 430 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset431 m_pcRdCost->setCbDistortionWeight(weight );423 weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 424 m_pcRdCost->setCbDistortionWeight(weight[0]); 432 425 433 426 chromaQPOffset = rpcSlice->getPPS()->getChromaCrQpOffset() + rpcSlice->getSliceQpDeltaCr(); 434 427 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 435 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 436 m_pcRdCost->setCrDistortionWeight(weight); 437 #endif 428 weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 429 m_pcRdCost->setCrDistortionWeight(weight[1]); 430 431 const Double lambdaArray[3] = {dLambda, (dLambda / weight[0]), (dLambda / weight[1])}; 438 432 439 433 #if RDOQ_CHROMA_LAMBDA 440 434 // for RDOQ 441 m_pcTrQuant->setLambda ( dLambda, dLambda / weight );435 m_pcTrQuant->setLambdas( lambdaArray ); 442 436 #else 443 437 m_pcTrQuant->setLambda( dLambda ); 444 438 #endif 445 439 446 #if SAO_CHROMA_LAMBDA447 440 // For SAO 448 rpcSlice ->setLambda( dLambda, dLambda / weight ); 449 #else 450 rpcSlice ->setLambda( dLambda ); 451 #endif 441 rpcSlice->setLambdas( lambdaArray ); 452 442 453 443 #if HB_LAMBDA_FOR_LDC … … 460 450 } 461 451 #else 462 eSliceType = (pocLast == 0 || pocCurr% m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType;452 eSliceType = (pocLast == 0 || (pocCurr - isField) % m_pcCfg->getIntraPeriod() == 0 || m_pcGOPEncoder->getGOPSize() == 0) ? I_SLICE : eSliceType; 463 453 #endif 464 454 … … 570 560 } 571 561 572 #if RATE_CONTROL_LAMBDA_DOMAIN573 562 Void TEncSlice::resetQP( TComPic* pic, Int sliceQP, Double lambda ) 574 563 { … … 579 568 slice->setSliceQpBase ( sliceQP ); 580 569 m_pcRdCost ->setLambda( lambda ); 581 #if WEIGHTED_CHROMA_DISTORTION582 570 // for RDO 583 571 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 584 Double weight ;572 Double weight[2] = { 1.0, 1.0 }; 585 573 Int qpc; 586 574 Int chromaQPOffset; … … 588 576 chromaQPOffset = slice->getPPS()->getChromaCbQpOffset() + slice->getSliceQpDeltaCb(); 589 577 qpc = Clip3( 0, 57, sliceQP + chromaQPOffset); 590 weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset591 m_pcRdCost->setCbDistortionWeight(weight );578 weight[0] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 579 m_pcRdCost->setCbDistortionWeight(weight[0]); 592 580 593 581 chromaQPOffset = slice->getPPS()->getChromaCrQpOffset() + slice->getSliceQpDeltaCr(); 594 582 qpc = Clip3( 0, 57, sliceQP + chromaQPOffset); 595 weight = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 596 m_pcRdCost->setCrDistortionWeight(weight); 597 #endif 583 weight[1] = pow( 2.0, (sliceQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 584 m_pcRdCost->setCrDistortionWeight(weight[1]); 585 586 const Double lambdaArray[3] = {lambda, (lambda / weight[0]), (lambda / weight[1])}; 598 587 599 588 #if RDOQ_CHROMA_LAMBDA 600 589 // for RDOQ 601 m_pcTrQuant->setLambda ( lambda, lambda / weight);590 m_pcTrQuant->setLambdas( lambdaArray ); 602 591 #else 603 592 m_pcTrQuant->setLambda( lambda ); 604 593 #endif 605 594 606 #if SAO_CHROMA_LAMBDA607 595 // For SAO 608 slice ->setLambda( lambda, lambda / weight ); 609 #else 610 slice ->setLambda( lambda ); 611 #endif 596 slice->setLambdas( lambdaArray ); 612 597 } 613 #else614 /**615 - lambda re-computation based on rate control QP616 */617 Void TEncSlice::xLamdaRecalculation(Int changeQP, Int idGOP, Int depth, SliceType eSliceType, TComSPS* pcSPS, TComSlice* pcSlice)618 {619 Int qp;620 Double recalQP= (Double)changeQP;621 Double origQP = (Double)recalQP;622 Double lambda;623 624 // pre-compute lambda and QP values for all possible QP candidates625 for ( Int deltqQpIdx = 0; deltqQpIdx < 2 * m_pcCfg->getDeltaQpRD() + 1; deltqQpIdx++ )626 {627 // compute QP value628 recalQP = origQP + ((deltqQpIdx+1)>>1)*(deltqQpIdx%2 ? -1 : 1);629 630 // compute lambda value631 Int NumberBFrames = ( m_pcCfg->getGOPSize() - 1 );632 Int SHIFT_QP = 12;633 Double dLambda_scale = 1.0 - Clip3( 0.0, 0.5, 0.05*(Double)NumberBFrames );634 #if FULL_NBIT635 Int bitdepth_luma_qp_scale = 6 * (g_bitDepth - 8);636 #else637 Int bitdepth_luma_qp_scale = 0;638 #endif639 Double qp_temp = (Double) recalQP + bitdepth_luma_qp_scale - SHIFT_QP;640 #if FULL_NBIT641 Double qp_temp_orig = (Double) recalQP - SHIFT_QP;642 #endif643 // Case #1: I or P-slices (key-frame)644 Double dQPFactor = m_pcCfg->getGOPEntry(idGOP).m_QPFactor;645 if ( eSliceType==I_SLICE )646 {647 dQPFactor=0.57*dLambda_scale;648 }649 lambda = dQPFactor*pow( 2.0, qp_temp/3.0 );650 651 if ( depth>0 )652 {653 #if FULL_NBIT654 lambda *= Clip3( 2.00, 4.00, (qp_temp_orig / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )655 #else656 lambda *= Clip3( 2.00, 4.00, (qp_temp / 6.0) ); // (j == B_SLICE && p_cur_frm->layer != 0 )657 #endif658 }659 660 // if hadamard is used in ME process661 if ( !m_pcCfg->getUseHADME() )662 {663 lambda *= 0.95;664 }665 666 qp = max( -pcSPS->getQpBDOffsetY(), min( MAX_QP, (Int) floor( recalQP + 0.5 ) ) );667 668 m_pdRdPicLambda[deltqQpIdx] = lambda;669 m_pdRdPicQp [deltqQpIdx] = recalQP;670 m_piRdPicQp [deltqQpIdx] = qp;671 }672 673 // obtain dQP = 0 case674 lambda = m_pdRdPicLambda[0];675 recalQP = m_pdRdPicQp [0];676 qp = m_piRdPicQp [0];677 678 if( pcSlice->getSliceType( ) != I_SLICE )679 {680 lambda *= m_pcCfg->getLambdaModifier( depth );681 }682 683 // store lambda684 m_pcRdCost ->setLambda( lambda );685 #if WEIGHTED_CHROMA_DISTORTION686 // for RDO687 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma.688 Double weight = 1.0;689 Int qpc;690 Int chromaQPOffset;691 692 chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb();693 qpc = Clip3( 0, 57, qp + chromaQPOffset);694 weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset695 m_pcRdCost->setCbDistortionWeight(weight);696 697 chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr();698 qpc = Clip3( 0, 57, qp + chromaQPOffset);699 weight = pow( 2.0, (qp-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset700 m_pcRdCost->setCrDistortionWeight(weight);701 #endif702 703 #if RDOQ_CHROMA_LAMBDA704 // for RDOQ705 m_pcTrQuant->setLambda( lambda, lambda / weight );706 #else707 m_pcTrQuant->setLambda( lambda );708 #endif709 710 #if SAO_CHROMA_LAMBDA711 // For SAO712 pcSlice ->setLambda( lambda, lambda / weight );713 #else714 pcSlice ->setLambda( lambda );715 #endif716 }717 #endif718 598 // ==================================================================================================================== 719 599 // Public member functions … … 755 635 } 756 636 757 #if RATE_CONTROL_LAMBDA_DOMAIN758 637 if ( m_pcCfg->getUseRateCtrl() ) 759 638 { … … 761 640 assert(0); 762 641 } 763 #endif764 642 765 643 TComSlice* pcSlice = rpcPic->getSlice(getSliceIdx()); … … 793 671 #endif 794 672 m_pcRdCost ->setLambda ( m_pdRdPicLambda[uiQpIdx] ); 795 #if WEIGHTED_CHROMA_DISTORTION796 673 // for RDO 797 674 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 798 675 Int iQP = m_piRdPicQp [uiQpIdx]; 799 Double weight = 1.0;676 Double weight[2] = { 1.0, 1.0 }; 800 677 Int qpc; 801 678 Int chromaQPOffset; … … 803 680 chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb(); 804 681 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 805 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset806 m_pcRdCost->setCbDistortionWeight(weight );682 weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 683 m_pcRdCost->setCbDistortionWeight(weight[0]); 807 684 808 685 chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr(); 809 686 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 810 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset811 m_pcRdCost->setCrDistortionWeight(weight );812 #endif 813 687 weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 688 m_pcRdCost->setCrDistortionWeight(weight[1]); 689 690 const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdx], (m_pdRdPicLambda[uiQpIdx] / weight[0]), (m_pdRdPicLambda[uiQpIdx] / weight[1])}; 814 691 #if RDOQ_CHROMA_LAMBDA 815 692 // for RDOQ 816 m_pcTrQuant ->setLambda( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight);693 m_pcTrQuant->setLambdas( lambdaArray ); 817 694 #else 818 695 m_pcTrQuant ->setLambda ( m_pdRdPicLambda[uiQpIdx] ); 819 696 #endif 820 #if SAO_CHROMA_LAMBDA821 697 // For SAO 822 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdx], m_pdRdPicLambda[uiQpIdx] / weight ); 823 #else 824 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdx] ); 825 #endif 698 pcSlice->setLambdas( lambdaArray ); 826 699 827 700 // try compress … … 857 730 #endif 858 731 m_pcRdCost ->setLambda ( m_pdRdPicLambda[uiQpIdxBest] ); 859 #if WEIGHTED_CHROMA_DISTORTION860 732 // in RdCost there is only one lambda because the luma and chroma bits are not separated, instead we weight the distortion of chroma. 861 733 Int iQP = m_piRdPicQp [uiQpIdxBest]; 862 Double weight = 1.0;734 Double weight[2] = { 1.0, 1.0 }; 863 735 Int qpc; 864 736 Int chromaQPOffset; … … 866 738 chromaQPOffset = pcSlice->getPPS()->getChromaCbQpOffset() + pcSlice->getSliceQpDeltaCb(); 867 739 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 868 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset869 m_pcRdCost->setCbDistortionWeight(weight );740 weight[0] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 741 m_pcRdCost->setCbDistortionWeight(weight[0]); 870 742 871 743 chromaQPOffset = pcSlice->getPPS()->getChromaCrQpOffset() + pcSlice->getSliceQpDeltaCr(); 872 744 qpc = Clip3( 0, 57, iQP + chromaQPOffset); 873 weight = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset874 m_pcRdCost->setCrDistortionWeight(weight );875 #endif 876 745 weight[1] = pow( 2.0, (iQP-g_aucChromaScale[qpc])/3.0 ); // takes into account of the chroma qp mapping and chroma qp Offset 746 m_pcRdCost->setCrDistortionWeight(weight[1]); 747 748 const Double lambdaArray[3] = {m_pdRdPicLambda[uiQpIdxBest], (m_pdRdPicLambda[uiQpIdxBest] / weight[0]), (m_pdRdPicLambda[uiQpIdxBest] / weight[1])}; 877 749 #if RDOQ_CHROMA_LAMBDA 878 750 // for RDOQ 879 m_pcTrQuant ->setLambda( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight );751 m_pcTrQuant->setLambdas( lambdaArray ); 880 752 #else 881 753 m_pcTrQuant ->setLambda ( m_pdRdPicLambda[uiQpIdxBest] ); 882 754 #endif 883 #if SAO_CHROMA_LAMBDA884 755 // For SAO 885 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdxBest], m_pdRdPicLambda[uiQpIdxBest] / weight ); 886 #else 887 pcSlice ->setLambda ( m_pdRdPicLambda[uiQpIdxBest] ); 888 #endif 756 pcSlice->setLambdas( lambdaArray ); 889 757 } 890 758 891 759 /** \param rpcPic picture class 892 760 */ 893 #if RATE_CONTROL_INTRA894 761 Void TEncSlice::calCostSliceI(TComPic*& rpcPic) 895 762 { … … 925 792 m_pcRateCtrl->getRCPic()->setTotalIntraCost(iSumHadSlice); 926 793 } 927 #endif928 794 929 795 Void TEncSlice::compressSlice( TComPic*& rpcPic ) … … 943 809 944 810 // set entropy coder 945 if( m_pcCfg->getUseSBACRD() )946 {947 811 m_pcSbacCoder->init( m_pcBinCABAC ); 948 812 m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); … … 952 816 pppcRDSbacCoder->setBinCountingEnableFlag( false ); 953 817 pppcRDSbacCoder->setBinsCoded( 0 ); 954 }955 else956 {957 m_pcEntropyCoder->setEntropyCoder ( m_pcCavlcCoder, pcSlice );958 m_pcEntropyCoder->resetEntropy ();959 m_pcEntropyCoder->setBitstream ( m_pcBitCounter );960 }961 818 962 819 //------------------------------------------------------------------------------ … … 1016 873 } 1017 874 #endif 1018 if( m_pcCfg->getUseSBACRD() )1019 {1020 875 iNumSubstreams = pcSlice->getPPS()->getNumSubstreams(); 1021 876 uiTilesAcross = rpcPic->getPicSym()->getNumColumnsMinus1()+1; … … 1037 892 ppppcRDSbacCoders[ui][0][CI_CURR_BEST]->load(m_pppcRDSbacCoder[0][CI_CURR_BEST]); 1038 893 } 1039 }1040 //if( m_pcCfg->getUseSBACRD() )1041 {1042 894 delete[] m_pcBufferLowLatSbacCoders; 1043 895 delete[] m_pcBufferLowLatBinCoderCABACs; … … 1050 902 for (UInt ui = 0; ui < uiTilesAcross; ui++) 1051 903 m_pcBufferLowLatSbacCoders[ui].load(m_pppcRDSbacCoder[0][CI_CURR_BEST]); //init. state 1052 } 904 1053 905 UInt uiWidthInLCUs = rpcPic->getPicSym()->getFrameWidthInCU(); 1054 906 //UInt uiHeightInLCUs = rpcPic->getPicSym()->getFrameHeightInCU(); … … 1121 973 } 1122 974 #endif 1123 #if !RATE_CONTROL_LAMBDA_DOMAIN1124 if(m_pcCfg->getUseRateCtrl())1125 {1126 #if KWU_RC_MADPRED_E02271127 if(pcSlice->getLayerId() != 0 && m_pcCfg->getUseDepthMADPred() && !pcSlice->getIsDepth())1128 {1129 Double zn, zf, focallength, position, camshift;1130 Double basepos;1131 Bool bInterpolated;1132 Int direction = pcSlice->getViewId() - pcCU->getSlice()->getIvPic(false, 0)->getViewId();1133 1134 pcEncTop->getCamParam()->xGetZNearZFar(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), zn, zf);1135 pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[0], pcSlice->getPOC(), focallength, basepos, camshift, bInterpolated);1136 pcEncTop->getCamParam()->xGetGeometryData(pcEncTop->getCamParam()->getBaseViewNumbers()[pcSlice->getViewIndex()], pcSlice->getPOC(), focallength, position, camshift, bInterpolated);1137 1138 m_pcRateCtrl->updateLCUDataEnhancedView(pcCU, pcCU->getTotalBits(), pcCU->getQP(0), basepos, position, focallength, zn, zf, (direction > 0 ? 1 : -1));1139 }1140 #endif1141 if(m_pcRateCtrl->calculateUnitQP())1142 {1143 xLamdaRecalculation(m_pcRateCtrl->getUnitQP(), m_pcRateCtrl->getGOPId(), pcSlice->getDepth(), pcSlice->getSliceType(), pcSlice->getSPS(), pcSlice );1144 }1145 }1146 #endif1147 975 // inherit from TR if necessary, select substream to use. 1148 if( m_pcCfg->getUseSBACRD() )1149 {1150 976 uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in? 1151 977 uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr(); … … 1192 1018 } 1193 1019 m_pppcRDSbacCoder[0][CI_CURR_BEST]->load( ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST] ); //this load is used to simplify the code 1194 }1195 1020 1196 1021 // reset the entropy coder … … 1210 1035 m_pcEntropyCoder->setEntropyCoder ( m_pcSbacCoder, pcSlice ); 1211 1036 } 1212 // if RD based on SBAC is used 1213 if( m_pcCfg->getUseSBACRD() ) 1214 { 1037 1215 1038 // set go-on entropy coder 1216 1039 m_pcEntropyCoder->setEntropyCoder ( m_pcRDGoOnSbacCoder, pcSlice ); … … 1219 1042 ((TEncBinCABAC*)m_pcRDGoOnSbacCoder->getEncBinIf())->setBinCountingEnableFlag(true); 1220 1043 1221 #if RATE_CONTROL_LAMBDA_DOMAIN1222 1044 Double oldLambda = m_pcRdCost->getLambda(); 1223 1045 if ( m_pcCfg->getUseRateCtrl() ) … … 1227 1049 Double bpp = -1.0; 1228 1050 1229 #if M0036_RC_IMPROVEMENT1230 1051 if ( ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE && m_pcCfg->getForceIntraQP() ) || !m_pcCfg->getLCULevelRC() ) 1231 #else1232 if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE || !m_pcCfg->getLCULevelRC() )1233 #endif1234 1052 { 1235 1053 estQP = pcSlice->getSliceQp(); … … 1255 1073 { 1256 1074 #endif 1257 #if RATE_CONTROL_INTRA1258 1075 bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp(pcSlice->getSliceType()); 1259 1076 if ( rpcPic->getSlice( 0 )->getSliceType() == I_SLICE) … … 1266 1083 estQP = m_pcRateCtrl->getRCPic()->getLCUEstQP ( estLambda, pcSlice->getSliceQp() ); 1267 1084 } 1268 #else1269 bpp = m_pcRateCtrl->getRCPic()->getLCUTargetBpp();1270 estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp );1271 estQP = m_pcRateCtrl->getRCPic()->getLCUEstQP ( estLambda, pcSlice->getSliceQp() );1272 #endif1273 #if KWU_RC_MADPRED_E02271274 }1275 #endif1276 1085 #if KWU_RC_MADPRED_E0227 1277 1086 estLambda = m_pcRateCtrl->getRCPic()->getLCUEstLambda( bpp ); … … 1281 1090 1282 1091 m_pcRdCost->setLambda(estLambda); 1283 #if M0036_RC_IMPROVEMENT1284 1092 #if RDOQ_CHROMA_LAMBDA 1285 1093 // set lambda for RDOQ 1286 1094 Double weight=m_pcRdCost->getChromaWeight(); 1287 m_pcTrQuant->setLambda( estLambda, estLambda / weight ); 1095 const Double lambdaArray[3] = { estLambda, (estLambda / weight), (estLambda / weight) }; 1096 m_pcTrQuant->setLambdas( lambdaArray ); 1288 1097 #else 1289 1098 m_pcTrQuant->setLambda( estLambda ); 1290 #endif1291 1099 #endif 1292 1100 } … … 1295 1103 pcCU->getSlice()->setSliceQpBase( estQP ); 1296 1104 } 1297 #endif1298 1105 1299 1106 // run CU encoder 1300 1107 m_pcCuEncoder->compressCU( pcCU ); 1301 1108 1302 #if !TICKET_1090_FIX1303 #if RATE_CONTROL_LAMBDA_DOMAIN1304 if ( m_pcCfg->getUseRateCtrl() )1305 {1306 #if !M0036_RC_IMPROVEMENT1307 UInt SAD = m_pcCuEncoder->getLCUPredictionSAD();1308 Int height = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() );1309 Int width = min( pcSlice->getSPS()->getMaxCUWidth(),pcSlice->getSPS()->getPicWidthInLumaSamples() - uiCUAddr % rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUWidth() );1310 Double MAD = (Double)SAD / (Double)(height * width);1311 MAD = MAD * MAD;1312 ( m_pcRateCtrl->getRCPic()->getLCU(uiCUAddr) ).m_MAD = MAD;1313 #endif1314 1315 Int actualQP = g_RCInvalidQPValue;1316 Double actualLambda = m_pcRdCost->getLambda();1317 Int actualBits = pcCU->getTotalBits();1318 Int numberOfEffectivePixels = 0;1319 for ( Int idx = 0; idx < rpcPic->getNumPartInCU(); idx++ )1320 {1321 if ( pcCU->getPredictionMode( idx ) != MODE_NONE && ( !pcCU->isSkipped( idx ) ) )1322 {1323 numberOfEffectivePixels = numberOfEffectivePixels + 16;1324 break;1325 }1326 }1327 1328 if ( numberOfEffectivePixels == 0 )1329 {1330 actualQP = g_RCInvalidQPValue;1331 }1332 else1333 {1334 actualQP = pcCU->getQP( 0 );1335 }1336 m_pcRdCost->setLambda(oldLambda);1337 #if RATE_CONTROL_INTRA1338 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda,1339 pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() );1340 #else1341 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );1342 #endif1343 }1344 #endif1345 #endif1346 1347 1109 // restore entropy coder to an initial stage 1348 1110 m_pcEntropyCoder->setEntropyCoder ( m_pppcRDSbacCoder[0][CI_CURR_BEST], pcSlice ); … … 1366 1128 break; 1367 1129 } 1368 if( m_pcCfg->getUseSBACRD() )1369 {1370 ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] );1371 1130 1131 ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]->load( m_pppcRDSbacCoder[0][CI_CURR_BEST] ); 1372 1132 //Store probabilties of second LCU in line into buffer 1373 1133 if ( ( uiCol == uiTileLCUX+1) && (depSliceSegmentsEnabled || (pcSlice->getPPS()->getNumSubstreams() > 1)) && m_pcCfg->getWaveFrontsynchro()) … … 1375 1135 m_pcBufferSbacCoders[uiTileCol].loadContexts(ppppcRDSbacCoders[uiSubStrm][0][CI_CURR_BEST]); 1376 1136 } 1377 } 1378 1379 #if TICKET_1090_FIX 1380 #if RATE_CONTROL_LAMBDA_DOMAIN 1137 1381 1138 if ( m_pcCfg->getUseRateCtrl() ) 1382 1139 { 1383 #if !M0036_RC_IMPROVEMENT ||KWU_RC_MADPRED_E02271140 #if KWU_RC_MADPRED_E0227 1384 1141 UInt SAD = m_pcCuEncoder->getLCUPredictionSAD(); 1385 1142 Int height = min( pcSlice->getSPS()->getMaxCUHeight(),pcSlice->getSPS()->getPicHeightInLumaSamples() - uiCUAddr / rpcPic->getFrameWidthInCU() * pcSlice->getSPS()->getMaxCUHeight() ); … … 1413 1170 m_pcRdCost->setLambda(oldLambda); 1414 1171 1415 #if RATE_CONTROL_INTRA1416 1172 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, 1417 1173 pcCU->getSlice()->getSliceType() == I_SLICE ? 0 : m_pcCfg->getLCULevelRC() ); 1418 #else1419 m_pcRateCtrl->getRCPic()->updateAfterLCU( m_pcRateCtrl->getRCPic()->getLCUCoded(), actualBits, actualQP, actualLambda, m_pcCfg->getLCULevelRC() );1420 #endif1421 }1422 #endif1423 #endif1424 }1425 // other case: encodeCU is not called1426 else1427 {1428 m_pcCuEncoder->compressCU( pcCU );1429 m_pcCuEncoder->encodeCU( pcCU );1430 if (m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES && ( ( pcSlice->getSliceBits()+ m_pcEntropyCoder->getNumberOfWrittenBits() ) ) > m_pcCfg->getSliceArgument()<<3)1431 {1432 pcSlice->setNextSlice( true );1433 break;1434 }1435 if (m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES && pcSlice->getSliceSegmentBits()+ m_pcEntropyCoder->getNumberOfWrittenBits()> m_pcCfg->getSliceSegmentArgument()<<3 &&pcSlice->getSliceCurEndCUAddr()!=pcSlice->getSliceSegmentCurEndCUAddr())1436 {1437 pcSlice->setNextSliceSegment( true );1438 break;1439 }1440 1174 } 1441 1175 … … 1443 1177 m_dPicRdCost += pcCU->getTotalCost(); 1444 1178 m_uiPicDist += pcCU->getTotalDistortion(); 1445 #if !RATE_CONTROL_LAMBDA_DOMAIN1446 if(m_pcCfg->getUseRateCtrl())1447 {1448 m_pcRateCtrl->updateLCUData(pcCU, pcCU->getTotalBits(), pcCU->getQP(0));1449 m_pcRateCtrl->updataRCUnitStatus();1450 }1451 #endif1452 1179 } 1453 1180 if ((pcSlice->getPPS()->getNumSubstreams() > 1) && !depSliceSegmentsEnabled) … … 1455 1182 pcSlice->setNextSlice( true ); 1456 1183 } 1184 if(m_pcCfg->getSliceMode()==FIXED_NUMBER_OF_BYTES || m_pcCfg->getSliceSegmentMode()==FIXED_NUMBER_OF_BYTES) 1185 { 1186 if(pcSlice->getSliceCurEndCUAddr()<=pcSlice->getSliceSegmentCurEndCUAddr()) 1187 { 1188 pcSlice->setNextSlice( true ); 1189 } 1190 else 1191 { 1192 pcSlice->setNextSliceSegment( true ); 1193 } 1194 } 1457 1195 if( depSliceSegmentsEnabled ) 1458 1196 { … … 1464 1202 } 1465 1203 xRestoreWPparam( pcSlice ); 1466 #if !RATE_CONTROL_LAMBDA_DOMAIN1467 if(m_pcCfg->getUseRateCtrl())1468 {1469 m_pcRateCtrl->updateFrameData(m_uiPicTotalBits);1470 }1471 #endif1472 1204 } 1473 1205 … … 1582 1314 uiCUAddr = rpcPic->getPicSym()->getCUOrderMap(++uiEncCUOrder) ) 1583 1315 { 1584 if( m_pcCfg->getUseSBACRD() )1585 {1586 1316 uiTileCol = rpcPic->getPicSym()->getTileIdxMap(uiCUAddr) % (rpcPic->getPicSym()->getNumColumnsMinus1()+1); // what column of tiles are we in? 1587 1317 uiTileStartLCU = rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr(); … … 1632 1362 } 1633 1363 m_pcSbacCoder->load(&pcSbacCoders[uiSubStrm]); //this load is used to simplify the code (avoid to change all the call to m_pcSbacCoder) 1634 } 1364 1635 1365 // reset the entropy coder 1636 1366 if( uiCUAddr == rpcPic->getPicSym()->getTComTile(rpcPic->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr() && // must be first CU of tile … … 1676 1406 #endif 1677 1407 TComDataCU*& pcCU = rpcPic->getCU( uiCUAddr ); 1678 if ( pcSlice->getSPS()->getUseSAO() && (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) ) 1679 { 1680 SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam(); 1681 Int iNumCuInWidth = saoParam->numCuInWidth; 1682 Int iCUAddrInSlice = uiCUAddr - rpcPic->getPicSym()->getCUOrderMap(pcSlice->getSliceCurStartCUAddr()/rpcPic->getNumPartInCU()); 1683 Int iCUAddrUpInSlice = iCUAddrInSlice - iNumCuInWidth; 1684 Int rx = uiCUAddr % iNumCuInWidth; 1685 Int ry = uiCUAddr / iNumCuInWidth; 1686 Int allowMergeLeft = 1; 1687 Int allowMergeUp = 1; 1688 if (rx!=0) 1689 { 1690 if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-1) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)) 1691 { 1692 allowMergeLeft = 0; 1693 } 1694 } 1695 if (ry!=0) 1696 { 1697 if (rpcPic->getPicSym()->getTileIdxMap(uiCUAddr-iNumCuInWidth) != rpcPic->getPicSym()->getTileIdxMap(uiCUAddr)) 1698 { 1699 allowMergeUp = 0; 1700 } 1701 } 1702 Int addr = pcCU->getAddr(); 1703 allowMergeLeft = allowMergeLeft && (rx>0) && (iCUAddrInSlice!=0); 1704 allowMergeUp = allowMergeUp && (ry>0) && (iCUAddrUpInSlice>=0); 1705 if( saoParam->bSaoFlag[0] || saoParam->bSaoFlag[1] ) 1706 { 1707 Int mergeLeft = saoParam->saoLcuParam[0][addr].mergeLeftFlag; 1708 Int mergeUp = saoParam->saoLcuParam[0][addr].mergeUpFlag; 1709 if (allowMergeLeft) 1710 { 1711 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeLeft); 1712 } 1713 else 1714 { 1715 mergeLeft = 0; 1716 } 1717 if(mergeLeft == 0) 1718 { 1719 if (allowMergeUp) 1720 { 1721 m_pcEntropyCoder->m_pcEntropyCoderIf->codeSaoMerge(mergeUp); 1722 } 1723 else 1724 { 1725 mergeUp = 0; 1726 } 1727 if(mergeUp == 0) 1728 { 1729 for (Int compIdx=0;compIdx<3;compIdx++) 1730 { 1731 if( (compIdx == 0 && saoParam->bSaoFlag[0]) || (compIdx > 0 && saoParam->bSaoFlag[1])) 1732 { 1733 m_pcEntropyCoder->encodeSaoOffset(&saoParam->saoLcuParam[compIdx][addr], compIdx); 1734 } 1735 } 1736 } 1737 } 1738 } 1739 } 1740 else if (pcSlice->getSPS()->getUseSAO()) 1741 { 1742 Int addr = pcCU->getAddr(); 1743 SAOParam *saoParam = pcSlice->getPic()->getPicSym()->getSaoParam(); 1744 for (Int cIdx=0; cIdx<3; cIdx++) 1745 { 1746 SaoLcuParam *saoLcuParam = &(saoParam->saoLcuParam[cIdx][addr]); 1747 if ( ((cIdx == 0) && !pcSlice->getSaoEnabledFlag()) || ((cIdx == 1 || cIdx == 2) && !pcSlice->getSaoEnabledFlagChroma())) 1748 { 1749 saoLcuParam->mergeUpFlag = 0; 1750 saoLcuParam->mergeLeftFlag = 0; 1751 saoLcuParam->subTypeIdx = 0; 1752 saoLcuParam->typeIdx = -1; 1753 saoLcuParam->offset[0] = 0; 1754 saoLcuParam->offset[1] = 0; 1755 saoLcuParam->offset[2] = 0; 1756 saoLcuParam->offset[3] = 0; 1757 } 1408 if ( pcSlice->getSPS()->getUseSAO() ) 1409 { 1410 if (pcSlice->getSaoEnabledFlag()||pcSlice->getSaoEnabledFlagChroma()) 1411 { 1412 SAOBlkParam& saoblkParam = (rpcPic->getPicSym()->getSAOBlkParam())[uiCUAddr]; 1413 Bool sliceEnabled[NUM_SAO_COMPONENTS]; 1414 sliceEnabled[SAO_Y] = pcSlice->getSaoEnabledFlag(); 1415 sliceEnabled[SAO_Cb]= sliceEnabled[SAO_Cr]= pcSlice->getSaoEnabledFlagChroma(); 1416 1417 Bool leftMergeAvail = false; 1418 Bool aboveMergeAvail= false; 1419 //merge left condition 1420 Int rx = (uiCUAddr % uiWidthInLCUs); 1421 if(rx > 0) 1422 { 1423 leftMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-1); 1424 } 1425 1426 //merge up condition 1427 Int ry = (uiCUAddr / uiWidthInLCUs); 1428 if(ry > 0) 1429 { 1430 aboveMergeAvail = rpcPic->getSAOMergeAvailability(uiCUAddr, uiCUAddr-uiWidthInLCUs); 1431 } 1432 1433 m_pcEntropyCoder->encodeSAOBlkParam(saoblkParam,sliceEnabled, leftMergeAvail, aboveMergeAvail); 1758 1434 } 1759 1435 } … … 1773 1449 g_bJustDoIt = g_bEncDecTraceDisable; 1774 1450 #endif 1775 if( m_pcCfg->getUseSBACRD() )1776 {1777 1451 pcSbacCoders[uiSubStrm].load(m_pcSbacCoder); //load back status of the entropy coder after encoding the LCU into relevant bitstream entropy coder 1778 1452 … … 1783 1457 m_pcBufferSbacCoders[uiTileCol].loadContexts( &pcSbacCoders[uiSubStrm] ); 1784 1458 } 1785 }1786 1459 #if H_3D_QTLPC 1787 1460 rpcPic->setReduceBitsFlag(false);
Note: See TracChangeset for help on using the changeset viewer.