changeset 5461:04350bfb3147

Merge branch 'X'
author Min Chen <chenm003@163.com>
date Tue, 03 Dec 2013 21:36:57 +0800
parents 78aa21f66013 (current diff) 86d23688b017 (diff)
children c9fe21f4676e
files
diffstat 11 files changed, 74 insertions(+-), 54 deletions(-) [+]
line wrap: on
line diff
--- a/source/Lib/TLibEncoder/TEncCfg.h	Tue Dec 03 21:03:13 2013 +0550
+++ b/source/Lib/TLibEncoder/TEncCfg.h	Tue Dec 03 21:36:57 2013 +0800
@@ -156,6 +156,9 @@ public:
     /* copy of parameters used to create encoder */
     x265_param param;
 
+    int       bEnableRDOQ;
+    int       bEnableRDOQTS;
+
     int       m_pad[2];
     Window    m_conformanceWindow;
 
--- a/source/Lib/TLibEncoder/TEncCu.cpp	Tue Dec 03 21:03:13 2013 +0550
+++ b/source/Lib/TLibEncoder/TEncCu.cpp	Tue Dec 03 21:36:57 2013 +0800
@@ -361,7 +361,7 @@ void TEncCu::compressCU(TComDataCU* cu)
         xCompressIntraCU(m_bestCU[0], m_tempCU[0], 0);
     else
     {
-        if (!m_cfg->param.bEnableRDO)
+        if (m_cfg->param.rdLevel < 5)
         {
             TComDataCU* outBestCU = NULL;
 
@@ -643,7 +643,6 @@ void TEncCu::xCompressIntraCU(TComDataCU
                 else
                     m_log->cntIntraNxN--;
             }
-
             m_log->cntIntra[depth + 1] += boundaryCu;
         }
         xCheckBestMode(outBestCU, outTempCU, depth); // RD compare current prediction with split prediction.
--- a/source/Lib/TLibEncoder/TEncSearch.cpp	Tue Dec 03 21:03:13 2013 +0550
+++ b/source/Lib/TLibEncoder/TEncSearch.cpp	Tue Dec 03 21:36:57 2013 +0800
@@ -431,7 +431,6 @@ void TEncSearch::xIntraCodingLumaBlk(TCo
     TCoeff*  coeff          = m_qtTempCoeffY[qtLayer] + numCoeffPerInc * absPartIdx;
 
     int16_t* reconQt        = m_qtTempTComYuv[qtLayer].getLumaAddr(absPartIdx);
-
     assert(m_qtTempTComYuv[qtLayer].m_width == MAX_CU_SIZE);
 
     uint32_t zorder           = cu->getZorderIdxInCU() + absPartIdx;
@@ -466,7 +465,7 @@ void TEncSearch::xIntraCodingLumaBlk(TCo
 
     //===== transform and quantization =====
     //--- init rate estimation arrays for RDOQ ---
-    if (useTransformSkip ? m_cfg->param.bEnableRDOQTS : m_cfg->param.bEnableRDOQ)
+    if (useTransformSkip ? m_cfg->bEnableRDOQTS : m_cfg->bEnableRDOQ)
     {
         m_entropyCoder->estimateBit(m_trQuant->m_estBitsSbac, width, width, TEXT_LUMA);
     }
@@ -596,7 +595,7 @@ void TEncSearch::xIntraCodingChromaBlk(T
     //===== transform and quantization =====
     {
         //--- init rate estimation arrays for RDOQ ---
-        if (useTransformSkipChroma ? m_cfg->param.bEnableRDOQTS : m_cfg->param.bEnableRDOQ)
+        if (useTransformSkipChroma ? m_cfg->bEnableRDOQTS : m_cfg->bEnableRDOQ)
         {
             m_entropyCoder->estimateBit(m_trQuant->m_estBitsSbac, width, width, ttype);
         }
@@ -1290,7 +1289,7 @@ void TEncSearch::xRecurIntraChromaCoding
 
     if (trMode == trDepth)
     {
-        bool checkTransformSkip = cu->getSlice()->getPPS()->getUseTransformSkip();
+        bool checkTransformSkip = false; //cu->getSlice()->getPPS()->getUseTransformSkip();
         uint32_t trSizeLog2 = g_convertToBit[cu->getSlice()->getSPS()->getMaxCUWidth() >> fullDepth] + 2;
 
         uint32_t actualTrDepth = trDepth;
@@ -3108,7 +3107,7 @@ void TEncSearch::xEstimateResidualQT(TCo
             cu->setTransformSkipSubParts(0, TEXT_CHROMA_V, absPartIdx, cu->getDepth(0) + trModeC);
         }
 
-        if (m_cfg->param.bEnableRDOQ && curuseRDOQ)
+        if (m_cfg->bEnableRDOQ && curuseRDOQ)
         {
             m_entropyCoder->estimateBit(m_trQuant->m_estBitsSbac, trWidth, trHeight, TEXT_LUMA);
         }
@@ -3123,7 +3122,7 @@ void TEncSearch::xEstimateResidualQT(TCo
 
         if (bCodeChroma)
         {
-            if (m_cfg->param.bEnableRDOQ && curuseRDOQ)
+            if (m_cfg->bEnableRDOQ && curuseRDOQ)
             {
                 m_entropyCoder->estimateBit(m_trQuant->m_estBitsSbac, trWidthC, trHeightC, TEXT_CHROMA);
             }
@@ -3405,7 +3404,7 @@ void TEncSearch::xEstimateResidualQT(TCo
 
             cu->setTransformSkipSubParts(1, TEXT_LUMA, absPartIdx, depth);
 
-            if (m_cfg->param.bEnableRDOQTS)
+            if (m_cfg->bEnableRDOQTS)
             {
                 m_entropyCoder->estimateBit(m_trQuant->m_estBitsSbac, trWidth, trHeight, TEXT_LUMA);
             }
@@ -3485,7 +3484,7 @@ void TEncSearch::xEstimateResidualQT(TCo
             cu->setTransformSkipSubParts(1, TEXT_CHROMA_U, absPartIdx, cu->getDepth(0) + trModeC);
             cu->setTransformSkipSubParts(1, TEXT_CHROMA_V, absPartIdx, cu->getDepth(0) + trModeC);
 
-            if (m_cfg->param.bEnableRDOQTS)
+            if (m_cfg->bEnableRDOQTS)
             {
                 m_entropyCoder->estimateBit(m_trQuant->m_estBitsSbac, trWidthC, trHeightC, TEXT_CHROMA);
             }
--- a/source/common/common.cpp	Tue Dec 03 21:03:13 2013 +0550
+++ b/source/common/common.cpp	Tue Dec 03 21:36:57 2013 +0800
@@ -182,10 +182,7 @@ void x265_param_default(x265_param *para
     param->bEnableCbfFastMode = 0;
     param->bEnableAMP = 1;
     param->bEnableRectInter = 1;
-    param->rdLevel = X265_NO_RDO_NO_RDOQ;
-    param->bEnableRDO = 0;
-    param->bEnableRDOQ = 0;
-    param->bEnableRDOQTS = 0;
+    param->rdLevel = 3;
     param->bEnableSignHiding = 1;
     param->bEnableTransformSkip = 0;
     param->bEnableTSkipFast = 0;
@@ -345,7 +342,7 @@ int x265_param_default_preset(x265_param
         {
             param->lookaheadDepth = 25;
             param->bframes = 4;
-            param->rdLevel = 1;
+            param->rdLevel = 4;
             param->subpelRefine = 3;
             param->maxNumMergeCand = 3;
             param->searchMethod = X265_STAR_SEARCH;
@@ -356,7 +353,7 @@ int x265_param_default_preset(x265_param
             param->bframes = 8;
             param->tuQTMaxInterDepth = 2;
             param->tuQTMaxIntraDepth = 2;
-            param->rdLevel = 2;
+            param->rdLevel = 6;
             param->subpelRefine = 3;
             param->maxNumMergeCand = 3;
             param->searchMethod = X265_STAR_SEARCH;
@@ -367,7 +364,7 @@ int x265_param_default_preset(x265_param
             param->bframes = 8;
             param->tuQTMaxInterDepth = 3;
             param->tuQTMaxIntraDepth = 3;
-            param->rdLevel = 2;
+            param->rdLevel = 6;
             param->subpelRefine = 4;
             param->maxNumMergeCand = 4;
             param->searchMethod = X265_STAR_SEARCH;
@@ -380,12 +377,11 @@ int x265_param_default_preset(x265_param
             param->bframes = 8;
             param->tuQTMaxInterDepth = 4;
             param->tuQTMaxIntraDepth = 4;
-            param->rdLevel = 2;
+            param->rdLevel = 6;
             param->subpelRefine = 5;
             param->maxNumMergeCand = 5;
             param->searchMethod = X265_STAR_SEARCH;
             param->bEnableTransformSkip = 1;
-            param->bEnableRDOQTS = 1;
             param->maxNumReferences = 5;
             // TODO: optimized esa
         }
@@ -398,6 +394,7 @@ int x265_param_default_preset(x265_param
         {
             //currently the default
             param->rc.aqMode = X265_AQ_NONE;
+            param->rc.cuTree = 0;
         }
         else if (!strcmp(tune, "ssim"))
         {
@@ -490,7 +487,7 @@ int x265_check_params(x265_param *param)
 
     CHECK(param->rc.rateControlMode<X265_RC_ABR || param->rc.rateControlMode> X265_RC_CRF,
           "Rate control mode is out of range");
-    CHECK(param->rdLevel<X265_NO_RDO_NO_RDOQ || param->rdLevel> X265_FULL_RDO,
+    CHECK(param->rdLevel < 0 || param->rdLevel > 6,
           "RD Level is out of range");
     CHECK(param->bframes > param->lookaheadDepth,
           "Lookahead depth must be greater than the max consecutive bframe count");
@@ -632,12 +629,8 @@ void x265_print_params(x265_param *param
     TOOLOPT(param->bEnableSignHiding, "sign-hide");
     if (param->bEnableTransformSkip)
     {
-        if (param->bEnableTSkipFast && param->bEnableRDOQTS)
-            fprintf(stderr, "tskip(fast+rdo) ");
-        else if (param->bEnableTSkipFast)
+        if (param->bEnableTSkipFast)
             fprintf(stderr, "tskip(fast) ");
-        else if (param->bEnableRDOQTS)
-            fprintf(stderr, "tskip(rdo) ");
         else
             fprintf(stderr, "tskip ");
     }
--- a/source/encoder/cturow.cpp	Tue Dec 03 21:03:13 2013 +0550
+++ b/source/encoder/cturow.cpp	Tue Dec 03 21:36:57 2013 +0800
@@ -33,7 +33,7 @@ void CTURow::create(Encoder* top)
 {
     m_rdGoOnSbacCoder.init(&m_rdGoOnBinCodersCABAC);
     m_sbacCoder.init(&m_binCoderCABAC);
-    m_trQuant.init(1 << top->getQuadtreeTULog2MaxSize(), top->param.bEnableRDOQ, top->param.bEnableRDOQTS, top->param.bEnableTSkipFast);
+    m_trQuant.init(1 << top->getQuadtreeTULog2MaxSize(), top->bEnableRDOQ, top->bEnableRDOQTS, top->param.bEnableTSkipFast);
 
     m_rdSbacCoders = new TEncSbac * *[g_maxCUDepth + 1];
     m_binCodersCABAC = new TEncBinCABAC * *[g_maxCUDepth + 1];
--- a/source/encoder/encoder.cpp	Tue Dec 03 21:03:13 2013 +0550
+++ b/source/encoder/encoder.cpp	Tue Dec 03 21:36:57 2013 +0800
@@ -1234,11 +1234,6 @@ void Encoder::configure(x265_param *_par
     {
         _param->bEnableAMP = false;
     }
-
-    if (!(_param->bEnableRDOQ && _param->bEnableTransformSkip))
-    {
-        _param->bEnableRDOQTS = 0;
-    }
     if (_param->bBPyramid && !_param->bframes)
     {
         _param->bBPyramid = 0;
@@ -1246,16 +1241,32 @@ void Encoder::configure(x265_param *_par
     /* Set flags according to RDLevel specified - check_params has verified that RDLevel is within range */
     switch (_param->rdLevel)
     {
-    case X265_NO_RDO_NO_RDOQ:
-        _param->bEnableRDO = _param->bEnableRDOQ = 0;
+    case 6:
+        bEnableRDOQ = bEnableRDOQTS = 1;
         break;
-    case X265_NO_RDO:
-        _param->bEnableRDO = 0;
-        _param->bEnableRDOQ = 1;
+    case 5:
+        bEnableRDOQ = bEnableRDOQTS = 1;
         break;
-    case X265_FULL_RDO:
-        _param->bEnableRDO = _param->bEnableRDOQ = 1;
+    case 4:
+        bEnableRDOQ = bEnableRDOQTS = 1;   
         break;
+    case 3:
+        bEnableRDOQ = bEnableRDOQTS = 0;
+        break; 
+    case 2:
+        bEnableRDOQ = bEnableRDOQTS = 0;
+        break; 
+    case 1:
+        bEnableRDOQ = bEnableRDOQTS = 0;
+        break; 
+    case 0:
+        bEnableRDOQ = bEnableRDOQTS = 0;
+        break;
+    }
+
+    if (!(bEnableRDOQ && _param->bEnableTransformSkip))
+    {
+        bEnableRDOQTS = 0;
     }
 
     //====== Coding Tools ========
--- a/source/encoder/ratecontrol.cpp	Tue Dec 03 21:03:13 2013 +0550
+++ b/source/encoder/ratecontrol.cpp	Tue Dec 03 21:36:57 2013 +0800
@@ -110,6 +110,7 @@ void RateControl::calcAdaptiveQuantFrame
             if (cfg->param.rc.aqMode)
             {
                 pic->m_lowres.qpAqOffset[block_xy] = qp_adj;
+                pic->m_lowres.qpOffset[block_xy] = qp_adj;
                 pic->m_lowres.invQscaleFactor[block_xy] = x265_exp2fix8(qp_adj);
                 block_xy++;
             }
@@ -133,6 +134,14 @@ RateControl::RateControl(TEncCfg * _cfg)
     this->cfg = _cfg;
     ncu = (int)((cfg->param.sourceHeight * cfg->param.sourceWidth) / pow((int)16, 2.0));
 
+    if (cfg->param.rc.cuTree)
+    {
+        qCompress = 1;
+        cfg->param.rc.pbFactor = 1;
+    }
+    else
+        qCompress = cfg->param.rc.qCompress;
+
     // validate for cfg->param.rc, maybe it is need to add a function like x265_parameters_valiate()
     cfg->param.rc.rfConstant = Clip3((double)-QP_BD_OFFSET, (double)51, cfg->param.rc.rfConstant);
     if (cfg->param.rc.rateControlMode == X265_RC_CRF)
@@ -141,8 +150,8 @@ RateControl::RateControl(TEncCfg * _cfg)
         cfg->param.rc.bitrate = 0;
 
         double baseCplx = ncu * (cfg->param.bframes ? 120 : 80);
-        double mbtree_offset = 0; // added later
-        rateFactorConstant = pow(baseCplx, 1 - cfg->param.rc.qCompress) /
+        double mbtree_offset = cfg->param.rc.cuTree ? (1.0 - cfg->param.rc.qCompress) * 13.5 : 0;
+        rateFactorConstant = pow(baseCplx, 1 - qCompress) /
             qp2qScale(cfg->param.rc.rfConstant + mbtree_offset + QP_BD_OFFSET);
     }
 
@@ -240,7 +249,7 @@ RateControl::RateControl(TEncCfg * _cfg)
         accumPNorm = .01;
         accumPQp = (ABR_INIT_QP_MIN)*accumPNorm;
         /* estimated ratio that produces a reasonable QP for the first I-frame */
-        cplxrSum = .01 * pow(7.0e5, cfg->param.rc.qCompress) * pow(ncu, 0.5);
+        cplxrSum = .01 * pow(7.0e5, qCompress) * pow(ncu, 0.5);
         wantedBitsWindow = bitrate * frameDuration;
     }
     else if (cfg->param.rc.rateControlMode == X265_RC_CRF)
@@ -249,7 +258,7 @@ RateControl::RateControl(TEncCfg * _cfg)
         accumPNorm = .01;
         accumPQp = ABR_INIT_QP * accumPNorm;
         /* estimated ratio that produces a reasonable QP for the first I-frame */
-        cplxrSum = .01 * pow(7.0e5, cfg->param.rc.qCompress) * pow(ncu, 0.5);
+        cplxrSum = .01 * pow(7.0e5, qCompress) * pow(ncu, 0.5);
         wantedBitsWindow = bitrate * frameDuration;
     }
 
@@ -343,9 +352,9 @@ double RateControl::rateEstimateQscale(R
         double q0 = prevRefSlice->getSliceQp();
         double q1 = nextRefSlice->getSliceQp();
 
-        if (prevRefSlice->getSliceType() == B_SLICE && prevRefSlice->isReferenced())
+        if (prevRefSlice->getSliceType() == X265_TYPE_BREF && prevRefSlice->isReferenced())
             q0 -= pbOffset / 2;
-        if (nextRefSlice->getSliceType() == B_SLICE && nextRefSlice->isReferenced())
+        if (nextRefSlice->getSliceType() == X265_TYPE_BREF && nextRefSlice->isReferenced())
             q1 -= pbOffset / 2;
         if (i0 && i1)
             q = (q0 + q1) / 2 + ipOffset;
@@ -445,7 +454,7 @@ double RateControl::rateEstimateQscale(R
                 q = Clip3(lqmin, lqmax, q);
             }
         }
-        else if (cfg->param.rc.rateControlMode == X265_RC_CRF && cfg->param.rc.qCompress != 1)
+        else if (cfg->param.rc.rateControlMode == X265_RC_CRF && qCompress != 1)
         {
             q = qp2qScale(ABR_INIT_QP) / fabs(cfg->param.rc.ipFactor);
         }
@@ -557,7 +566,15 @@ double RateControl::getQScale(RateContro
 {
     double q;
 
-    q = pow(rce->blurredComplexity, 1 - cfg->param.rc.qCompress);
+    if (cfg->param.rc.cuTree)
+    {
+        double scale = curSlice->getSPS()->getVuiParameters()->getTimingInfo()->getTimeScale();
+        double units = curSlice->getSPS()->getVuiParameters()->getTimingInfo()->getNumUnitsInTick();
+        double timescale = units / scale;
+        q = pow(BASE_FRAME_DURATION / CLIP_DURATION(2 * timescale), 1 - cfg->param.rc.qCompress);
+    }
+    else
+        q = pow(rce->blurredComplexity, 1 - cfg->param.rc.qCompress);
 
     // avoid NaN's in the rc_eq
     if (rce->texBits + rce->mvBits == 0)
--- a/source/encoder/ratecontrol.h	Tue Dec 03 21:03:13 2013 +0550
+++ b/source/encoder/ratecontrol.h	Tue Dec 03 21:36:57 2013 +0800
@@ -115,6 +115,7 @@ struct RateControl
     int64_t totalBits;        /* totalbits used for already encoded frames */
     double lastRceq;
     int framesDone;           /* framesDone keeps track of # of frames passed through RateCotrol already */
+    double qCompress;
     RateControl(TEncCfg * _cfg);
 
     // to be called for each frame to process RateControl and set QP
--- a/source/encoder/slicetype.cpp	Tue Dec 03 21:03:13 2013 +0550
+++ b/source/encoder/slicetype.cpp	Tue Dec 03 21:36:57 2013 +0800
@@ -1366,7 +1366,7 @@ void Lookahead::cuTree(Lowres **Frames, 
     }
 
     cuTreeFinish(Frames[lastnonb], averageDuration, lastnonb);
-    if (cfg->param.bBPyramid && bframes > 1 /* && !h->param.rc.i_vbv_buffer_size */)
+    if (cfg->param.bBPyramid && bframes > 1 && !cfg->param.rc.vbvBufferSize)
         cuTreeFinish(Frames[lastnonb + (bframes + 1) / 2], averageDuration, 0);
 }
 
@@ -1464,7 +1464,7 @@ void Lookahead::estimateCUPropagate(Lowr
         }
     }
 
-    if(/*h->param.rc.i_vbv_buffer_size &&*/ cfg->param.logLevel && referenced)
+    if(cfg->param.rc.vbvBufferSize && cfg->param.logLevel && referenced)
         cuTreeFinish(Frames[b], averageDuration, b == p1 ? b - p0 : 0);
 
 }
@@ -1481,7 +1481,8 @@ void Lookahead::cuTreeFinish(Lowres *Fra
      * concepts are very similar. */
 
     int cuCount = widthInCU * heightInCU;
-    double strength = 5.0f * (1.0f - cfg->param.rc.qCompress);
+    double strength = 5.0 * (1.0 - cfg->param.rc.qCompress);
+
     for (int cuIndex = 0; cuIndex < cuCount; cuIndex++)
     {
         int intracost = (Frame->intraCost[cuIndex] * Frame->invQscaleFactor[cuIndex] + 128) >> 8;
--- a/source/x265.cpp	Tue Dec 03 21:03:13 2013 +0550
+++ b/source/x265.cpp	Tue Dec 03 21:36:57 2013 +0800
@@ -323,7 +323,7 @@ void CLIOptions::showHelp(x265_param *pa
     H0("   --aq-strength                 Reduces blocking and blurring in flat and textured areas.(0 to 3.0)<double> . Default %f\n", param->rc.aqStrength);
     H0("   --cbqpoffs                    Chroma Cb QP Offset. Default %d\n", param->cbQpOffset);
     H0("   --crqpoffs                    Chroma Cr QP Offset. Default %d\n", param->crQpOffset);
-    H0("   --rd                          Level of RD in mode decision 0:least....2:full RDO. Default %d\n", param->rdLevel);
+    H0("   --rd                          Level of RD in mode decision 0:least....6:full RDO. Default %d\n", param->rdLevel);
     H0("   --[no-]signhide               Hide sign bit of one coeff per TU (rdo). Default %s\n", OPT(param->bEnableSignHiding));
     H0("\nLoop filter:\n");
     H0("   --[no-]lft                    Enable Loop Filter. Default %s\n", OPT(param->bEnableLoopFilter));
--- a/source/x265.h	Tue Dec 03 21:03:13 2013 +0550
+++ b/source/x265.h	Tue Dec 03 21:36:57 2013 +0800
@@ -508,10 +508,6 @@ typedef struct x265_param
      * efficiency at a major cost of performance. Default is no RDO (0) */
     int       rdLevel;
 
-    int       bEnableRDO;    // obsolete
-    int       bEnableRDOQ;   // obsolete
-    int       bEnableRDOQTS; // obsolete
-
     /*== Coding tools ==*/
 
     /* Enable the implicit signaling of the sign bit of the last coefficient of