[x265] [PATCH 7 of 8] multi-level: increase maximum level from 5 to 10

kavitha at multicorewareinc.com kavitha at multicorewareinc.com
Mon Feb 27 15:05:23 CET 2017


# HG changeset patch
# User Kavitha Sampath <kavitha at multicorewareinc.com>
# Date 1487828698 -19800
#      Thu Feb 23 11:14:58 2017 +0530
# Node ID 727bd2d8128a99d2dcd1c4dbd3d571a662eade6a
# Parent  fec542968fecc4cda76264fe9b746952718a64f7
multi-level: increase maximum level from 5 to 10

diff -r fec542968fec -r 727bd2d8128a doc/reST/cli.rst
--- a/doc/reST/cli.rst	Sat Feb 04 22:12:22 2017 +0530
+++ b/doc/reST/cli.rst	Thu Feb 23 11:14:58 2017 +0530
@@ -816,26 +816,24 @@
 	Specify a filename for analysis data (see :option:`--analysis-mode`)
 	If no filename is specified, x265_analysis.dat is used.
 
-.. option:: --refine-level <1..5>
+.. option:: --refine-level <1..10>
 
 	Amount of information stored/reused in :option:`--analysis-mode` is distributed across levels.
-	Higher the value, higher the information stored/reused, faster the encode. Default 3.
+	Higher the value, higher the information stored/reused, faster the encode. Default 5.
 
 	Note that --refine-level must be paired with analysis-mode.
 
-	+-------+-----------------------------------------+
-	| Level | Description                             |
-	+=======+=========================================+
-	| 1     | Lookahead information                   |
-	+-------+-----------------------------------------+
-	| 2     | Level 1 + intra/inter modes, ref's      |
-	+-------+-----------------------------------------+
-	| 3     | Level 2 + rect-amp                      |
-	+-------+-----------------------------------------+
-	| 4     | Currently same as 3                     |
-	+-------+-----------------------------------------+
-	| 5     | Level 4 + Entire CU analysis-info       |
-	+-------+-----------------------------------------+
+	+--------+-----------------------------------------+
+	| Level  | Description                             |
+	+========+=========================================+
+	| 1      | Lookahead information                   |
+	+--------+-----------------------------------------+
+	| 2 to 4 | Level 1 + intra/inter modes, ref's      |
+	+--------+-----------------------------------------+
+	| 5 to 9 | Level 2 + rect-amp                      |
+	+--------+-----------------------------------------+
+	| 10     | Level 5 + Full CU analysis-info         |
+	+--------+-----------------------------------------+
 
 Options which affect the transform unit quad-tree, sometimes referred to
 as the residual quad-tree (RQT).
diff -r fec542968fec -r 727bd2d8128a source/common/param.cpp
--- a/source/common/param.cpp	Sat Feb 04 22:12:22 2017 +0530
+++ b/source/common/param.cpp	Thu Feb 23 11:14:58 2017 +0530
@@ -271,7 +271,7 @@
     param->bOptCUDeltaQP        = 0;
     param->bAQMotion = 0;
     param->bHDROpt = 0;
-    param->analysisRefineLevel = 3;
+    param->analysisRefineLevel = 5;
 
 }
 
@@ -1279,8 +1279,8 @@
           "Strict-cbr cannot be applied without specifying target bitrate or vbv bufsize");
     CHECK(param->analysisMode && (param->analysisMode < X265_ANALYSIS_OFF || param->analysisMode > X265_ANALYSIS_LOAD),
         "Invalid analysis mode. Analysis mode 0: OFF 1: SAVE : 2 LOAD");
-    CHECK(param->analysisMode && (param->analysisRefineLevel < 1 || param->analysisRefineLevel > 5),
-        "Invalid analysis refine level. Value must be between 1 and 5 (inclusive)");
+    CHECK(param->analysisMode && (param->analysisRefineLevel < 1 || param->analysisRefineLevel > 10),
+        "Invalid analysis refine level. Value must be between 1 and 10 (inclusive)");
     CHECK(param->rc.qpMax < QP_MIN || param->rc.qpMax > QP_MAX_MAX,
         "qpmax exceeds supported range (0 to 69)");
     CHECK(param->rc.qpMin < QP_MIN || param->rc.qpMin > QP_MAX_MAX,
diff -r fec542968fec -r 727bd2d8128a source/encoder/analysis.cpp
--- a/source/encoder/analysis.cpp	Sat Feb 04 22:12:22 2017 +0530
+++ b/source/encoder/analysis.cpp	Thu Feb 23 11:14:58 2017 +0530
@@ -167,14 +167,14 @@
         }
     }
 
-    if (m_param->analysisMode && m_slice->m_sliceType != I_SLICE && m_param->analysisRefineLevel > 1 && m_param->analysisRefineLevel < 5)
+    if (m_param->analysisMode && m_slice->m_sliceType != I_SLICE && m_param->analysisRefineLevel > 1 && m_param->analysisRefineLevel < 10)
     {
         int numPredDir = m_slice->isInterP() ? 1 : 2;
         m_reuseInterDataCTU = (analysis_inter_data*)m_frame->m_analysisData.interData;
         m_reuseRef = &m_reuseInterDataCTU->ref[ctu.m_cuAddr * X265_MAX_PRED_MODE_PER_CTU * numPredDir];
         m_reuseDepth = &m_reuseInterDataCTU->depth[ctu.m_cuAddr * ctu.m_numPartitions];
         m_reuseModes = &m_reuseInterDataCTU->modes[ctu.m_cuAddr * ctu.m_numPartitions];
-        if (m_param->analysisRefineLevel > 2)
+        if (m_param->analysisRefineLevel > 4)
         {
             m_reusePartSize = &m_reuseInterDataCTU->partSize[ctu.m_cuAddr * ctu.m_numPartitions];
             m_reuseMergeFlag = &m_reuseInterDataCTU->mergeFlag[ctu.m_cuAddr * ctu.m_numPartitions];
@@ -214,7 +214,7 @@
             /* generate residual for entire CTU at once and copy to reconPic */
             encodeResidue(ctu, cuGeom);
         }
-        else if (m_param->analysisMode == X265_ANALYSIS_LOAD && m_param->analysisRefineLevel == 5)
+        else if (m_param->analysisMode == X265_ANALYSIS_LOAD && m_param->analysisRefineLevel == 10)
         {
             analysis_inter_data* interDataCTU = (analysis_inter_data*)m_frame->m_analysisData.interData;
             int posCTU = ctu.m_cuAddr * numPartition;
@@ -336,7 +336,7 @@
     int lambdaQP = lqp;
 
     bool doQPRefine = (bDecidedDepth && depth <= m_slice->m_pps->maxCuDQPDepth) || (!bDecidedDepth && depth == m_slice->m_pps->maxCuDQPDepth);
-    if (m_param->analysisRefineLevel == 5)
+    if (m_param->analysisRefineLevel == 10)
         doQPRefine = false;
 
     if (doQPRefine)
@@ -1054,7 +1054,7 @@
                 if (m_param->rdLevel)
                     skipModes = m_param->bEnableEarlySkip && md.bestMode;
             }
-            if (m_param->analysisRefineLevel > 2 && m_reusePartSize[cuGeom.absPartIdx] == SIZE_2Nx2N)
+            if (m_param->analysisRefineLevel > 4 && m_reusePartSize[cuGeom.absPartIdx] == SIZE_2Nx2N)
             {
                 if (m_reuseModes[cuGeom.absPartIdx] != MODE_INTRA  && m_reuseModes[cuGeom.absPartIdx] != 4)
                 {
@@ -1625,7 +1625,7 @@
                 if (m_param->bEnableRecursionSkip && depth && m_modeDepth[depth - 1].bestMode)
                     skipRecursion = md.bestMode && !md.bestMode->cu.getQtRootCbf(0);
             }
-            if (m_param->analysisRefineLevel > 2 && m_reusePartSize[cuGeom.absPartIdx] == SIZE_2Nx2N)
+            if (m_param->analysisRefineLevel > 4 && m_reusePartSize[cuGeom.absPartIdx] == SIZE_2Nx2N)
                 skipRectAmp = true && !!md.bestMode;
         }
     }
@@ -2033,7 +2033,7 @@
             for (uint32_t part = 0; part < numPU; part++)
             {
                 PredictionUnit pu(mode.cu, cuGeom, part);
-                if (m_param->analysisRefineLevel == 5)
+                if (m_param->analysisRefineLevel == 10)
                 {
                     analysis_inter_data* interDataCTU = (analysis_inter_data*)m_frame->m_analysisData.interData;
                     int cuIdx = (mode.cu.m_cuAddr * parentCTU.m_numPartitions) + cuGeom.absPartIdx;
@@ -2109,7 +2109,7 @@
                 if (m_slice->m_pps->bUseDQP && nextDepth <= m_slice->m_pps->maxCuDQPDepth)
                     nextQP = setLambdaFromQP(parentCTU, calculateQpforCuSize(parentCTU, childGeom));
 
-                int lamdaQP = m_param->analysisRefineLevel == 5 ? nextQP : lqp;
+                int lamdaQP = m_param->analysisRefineLevel == 10 ? nextQP : lqp;
                 qprdRefine(parentCTU, childGeom, nextQP, lamdaQP);
 
                 // Save best CU and pred data for this sub CU
diff -r fec542968fec -r 727bd2d8128a source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Sat Feb 04 22:12:22 2017 +0530
+++ b/source/encoder/encoder.cpp	Thu Feb 23 11:14:58 2017 +0530
@@ -2021,9 +2021,6 @@
         p->rc.cuTree = 0;
     }
 
-    if (p->analysisMode == X265_ANALYSIS_OFF && p->analysisRefineLevel)
-        x265_log(p, X265_LOG_WARNING, "refine-level option works only with analysis-mode load/save\n");
-
     if (p->analysisMode && (p->analysisMultiPassRefine || p->analysisMultiPassDistortion))
     {
         x265_log(p, X265_LOG_WARNING, "Cannot use Analysis load/save option and multi-pass-opt-analysis/multi-pass-opt-distortion together,"
@@ -2346,13 +2343,13 @@
         CHECKED_MALLOC_ZERO(interData, analysis_inter_data, 1);
         CHECKED_MALLOC(interData->depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
         CHECKED_MALLOC(interData->modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
-        if (m_param->analysisRefineLevel > 2)
+        if (m_param->analysisRefineLevel > 4)
         {
             CHECKED_MALLOC(interData->partSize, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
             CHECKED_MALLOC(interData->mergeFlag, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
         }
 
-        if (m_param->analysisRefineLevel == 5)
+        if (m_param->analysisRefineLevel == 10)
         {
             CHECKED_MALLOC(interData->interDir, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
             for (int dir = 0; dir < numDir; dir++)
@@ -2405,16 +2402,15 @@
     }
     else if (analysis->interData)
     {
-        X265_FREE(((analysis_inter_data*)analysis->interData)->ref);
         X265_FREE(((analysis_inter_data*)analysis->interData)->depth);
         X265_FREE(((analysis_inter_data*)analysis->interData)->modes);
-        if (m_param->analysisRefineLevel > 2)
+        if (m_param->analysisRefineLevel > 4)
         {
             X265_FREE(((analysis_inter_data*)analysis->interData)->mergeFlag);
             X265_FREE(((analysis_inter_data*)analysis->interData)->partSize);
         }
 
-        if (m_param->analysisRefineLevel == 5)
+        if (m_param->analysisRefineLevel == 10)
         {
             X265_FREE(((analysis_inter_data*)analysis->interData)->interDir);
             int numDir = analysis->sliceType == X265_TYPE_P ? 1 : 2;
@@ -2431,6 +2427,8 @@
                 X265_FREE(analysis->intraData);
             }
         }
+        else
+            X265_FREE(((analysis_inter_data*)analysis->interData)->ref);
 
         X265_FREE(analysis->interData);
     }
@@ -2596,9 +2594,9 @@
         MV* mv[2];
         int8_t* refIdx[2];
 
-        int numBuf = m_param->analysisRefineLevel > 2 ? 4 : 2;
+        int numBuf = m_param->analysisRefineLevel > 4 ? 4 : 2;
         bool bIntraInInter = false;
-        if (m_param->analysisRefineLevel == 5)
+        if (m_param->analysisRefineLevel == 10)
         {
             numBuf++;
             bIntraInInter = (analysis->sliceType == X265_TYPE_P || m_param->bIntraInBFrames);
@@ -2610,11 +2608,11 @@
 
         depthBuf = tempBuf;
         modeBuf = tempBuf + depthBytes;
-        if (m_param->analysisRefineLevel > 2)
+        if (m_param->analysisRefineLevel > 4)
         {
             partSize = modeBuf + depthBytes;
             mergeFlag = partSize + depthBytes;
-            if (m_param->analysisRefineLevel == 5)
+            if (m_param->analysisRefineLevel == 10)
             {
                 interDir = mergeFlag + depthBytes;
                 if (bIntraInInter) chromaDir = interDir + depthBytes;
@@ -2636,7 +2634,7 @@
             int bytes = analysis->numPartitions >> (depthBuf[d] * 2);
             memset(&((analysis_inter_data *)analysis->interData)->depth[count], depthBuf[d], bytes);
             memset(&((analysis_inter_data *)analysis->interData)->modes[count], modeBuf[d], bytes);
-            if (m_param->analysisRefineLevel > 2)
+            if (m_param->analysisRefineLevel > 4)
             {
                 memset(&((analysis_inter_data *)analysis->interData)->partSize[count], partSize[d], bytes);
                 int numPU = nbPartsTable[(int)partSize[d]];
@@ -2644,7 +2642,7 @@
                 {
                     if (pu) d++;
                     ((analysis_inter_data *)analysis->interData)->mergeFlag[count + pu] = mergeFlag[d];
-                    if (m_param->analysisRefineLevel == 5)
+                    if (m_param->analysisRefineLevel == 10)
                     {
                         ((analysis_inter_data *)analysis->interData)->interDir[count + pu] = interDir[d];
                         for (uint32_t i = 0; i < numDir; i++)
@@ -2655,7 +2653,7 @@
                         }
                     }
                 }
-                if (m_param->analysisRefineLevel == 5 && bIntraInInter)
+                if (m_param->analysisRefineLevel == 10 && bIntraInInter)
                     memset(&((analysis_intra_data *)analysis->intraData)->chromaModes[count], chromaDir[d], bytes);
             }
             count += bytes;
@@ -2663,7 +2661,7 @@
 
         X265_FREE(tempBuf);
 
-        if (m_param->analysisRefineLevel == 5)
+        if (m_param->analysisRefineLevel == 10)
         {
             for (uint32_t i = 0; i < numDir; i++)
             {
@@ -2822,7 +2820,7 @@
     }\
 
     uint32_t depthBytes = 0;
-    int numDir, numPlanes;
+    uint32_t numDir, numPlanes;
     bool bIntraInInter = false;
 
     /* calculate frameRecordSize */
@@ -2883,12 +2881,12 @@
                     interDataCTU->depth[depthBytes] = depth;
 
                     predMode = ctu->m_predMode[absPartIdx];
-                    if (m_param->analysisRefineLevel != 5 && ctu->m_refIdx[1][absPartIdx] != -1)
+                    if (m_param->analysisRefineLevel != 10 && ctu->m_refIdx[1][absPartIdx] != -1)
                         predMode = 4; // used as indiacator if the block is coded as bidir
 
                     interDataCTU->modes[depthBytes] = predMode;
 
-                    if (m_param->analysisRefineLevel > 2)
+                    if (m_param->analysisRefineLevel > 4)
                     {
                         partSize = ctu->m_partSize[absPartIdx];
                         interDataCTU->partSize[depthBytes] = partSize;
@@ -2901,10 +2899,10 @@
                             if (puIdx) depthBytes++;
                             interDataCTU->mergeFlag[depthBytes] = ctu->m_mergeFlag[puabsPartIdx];
 
-                            if (m_param->analysisRefineLevel == 5)
+                            if (m_param->analysisRefineLevel == 10)
                             {
                                 interDataCTU->interDir[depthBytes] = ctu->m_interDir[puabsPartIdx];
-                                for (int dir = 0; dir < numDir; dir++)
+                                for (uint32_t dir = 0; dir < numDir; dir++)
                                 {
                                     interDataCTU->mvpIdx[dir][depthBytes] = ctu->m_mvpIdx[dir][puabsPartIdx];
                                     interDataCTU->refIdx[dir][depthBytes] = ctu->m_refIdx[dir][puabsPartIdx];
@@ -2912,12 +2910,12 @@
                                 }
                             }
                         }
-                        if (m_param->analysisRefineLevel == 5 && bIntraInInter)
+                        if (m_param->analysisRefineLevel == 10 && bIntraInInter)
                             intraDataCTU->chromaModes[depthBytes] = ctu->m_chromaIntraDir[absPartIdx];
                     }
                     absPartIdx += ctu->m_numPartitions >> (depth * 2);
                 }
-                if (m_param->analysisRefineLevel == 5 && bIntraInInter)
+                if (m_param->analysisRefineLevel == 10 && bIntraInInter)
                     memcpy(&intraDataCTU->modes[ctu->m_cuAddr * ctu->m_numPartitions], ctu->m_lumaIntraDir, sizeof(uint8_t)* ctu->m_numPartitions);
             }
         }
@@ -2928,10 +2926,10 @@
         {
             /* Add sizeof depth, modes, partSize, mergeFlag */
             analysis->frameRecordSize += depthBytes * 2;
-            if (m_param->analysisRefineLevel > 2)
+            if (m_param->analysisRefineLevel > 4)
                 analysis->frameRecordSize += (depthBytes * 2);
 
-            if (m_param->analysisRefineLevel == 5)
+            if (m_param->analysisRefineLevel == 10)
             {
                 /* Add Size of interDir, mvpIdx, refIdx, mv, luma and chroma modes */
                 analysis->frameRecordSize += depthBytes;
@@ -2970,15 +2968,15 @@
     {
         X265_FWRITE(((analysis_inter_data*)analysis->interData)->depth, sizeof(uint8_t), depthBytes, m_analysisFile);
         X265_FWRITE(((analysis_inter_data*)analysis->interData)->modes, sizeof(uint8_t), depthBytes, m_analysisFile);
-        if (m_param->analysisRefineLevel > 2)
+        if (m_param->analysisRefineLevel > 4)
         {
             X265_FWRITE(((analysis_inter_data*)analysis->interData)->partSize, sizeof(uint8_t), depthBytes, m_analysisFile);
             X265_FWRITE(((analysis_inter_data*)analysis->interData)->mergeFlag, sizeof(uint8_t), depthBytes, m_analysisFile);
-            if (m_param->analysisRefineLevel == 5)
+            if (m_param->analysisRefineLevel == 10)
             {
                 X265_FWRITE(((analysis_inter_data*)analysis->interData)->interDir, sizeof(uint8_t), depthBytes, m_analysisFile);
                 if (bIntraInInter) X265_FWRITE(((analysis_intra_data*)analysis->intraData)->chromaModes, sizeof(uint8_t), depthBytes, m_analysisFile);
-                for (int dir = 0; dir < numDir; dir++)
+                for (uint32_t dir = 0; dir < numDir; dir++)
                 {
                     X265_FWRITE(((analysis_inter_data*)analysis->interData)->mvpIdx[dir], sizeof(uint8_t), depthBytes, m_analysisFile);
                     X265_FWRITE(((analysis_inter_data*)analysis->interData)->refIdx[dir], sizeof(int8_t), depthBytes, m_analysisFile);
@@ -2988,7 +2986,7 @@
                     X265_FWRITE(((analysis_intra_data*)analysis->intraData)->modes, sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions, m_analysisFile);
             }
         }
-        if (m_param->analysisRefineLevel != 5)
+        if (m_param->analysisRefineLevel != 10)
             X265_FWRITE(((analysis_inter_data*)analysis->interData)->ref, sizeof(int32_t), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir, m_analysisFile);
 
     }
diff -r fec542968fec -r 727bd2d8128a source/x265.h
--- a/source/x265.h	Sat Feb 04 22:12:22 2017 +0530
+++ b/source/x265.h	Thu Feb 23 11:14:58 2017 +0530
@@ -1385,9 +1385,9 @@
      * Default is disabled */
     int       bHDROpt;
 
-    /* A value between 1 and 5 (both inclusive) determines the level of
+    /* A value between 1 and 10 (both inclusive) determines the level of
     * information stored/reused in save/load analysis-mode. Higher the refine
-    * level higher the informtion stored/reused. Default is 3 */
+    * level higher the informtion stored/reused. Default is 5 */
     int       analysisRefineLevel;
 
 } x265_param;
diff -r fec542968fec -r 727bd2d8128a source/x265cli.h
--- a/source/x265cli.h	Sat Feb 04 22:12:22 2017 +0530
+++ b/source/x265cli.h	Thu Feb 23 11:14:58 2017 +0530
@@ -424,7 +424,7 @@
     H0("   --[no-]strict-cbr             Enable stricter conditions and tolerance for bitrate deviations in CBR mode. Default %s\n", OPT(param->rc.bStrictCbr));
     H0("   --analysis-mode <string|int>  save - Dump analysis info into file, load - Load analysis buffers from the file. Default %d\n", param->analysisMode);
     H0("   --analysis-file <filename>    Specify file name used for either dumping or reading analysis data.\n");
-    H0("   --refine-level <1..5>         Level of analyis refinement indicates amount of info stored/reused in save/load mode, 1:least....5:most. Default %d\n", param->analysisRefineLevel);
+    H0("   --refine-level <1..10>        Level of analyis refinement indicates amount of info stored/reused in save/load mode, 1:least....10:most. Default %d\n", param->analysisRefineLevel);
     H0("   --aq-mode <integer>           Mode for Adaptive Quantization - 0:none 1:uniform AQ 2:auto variance 3:auto variance with bias to dark scenes. Default %d\n", param->rc.aqMode);
     H0("   --aq-strength <float>         Reduces blocking and blurring in flat and textured areas (0 to 3.0). Default %.2f\n", param->rc.aqStrength);
     H0("   --[no-]aq-motion              Adaptive Quantization based on the relative motion of each CU w.r.t., frame. Default %s\n", OPT(param->bOptCUDeltaQP));


More information about the x265-devel mailing list