[x265] [PATCH 3 of 8] multi-level refinement: support for level 3, 4

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


# HG changeset patch
# User Kavitha Sampath <kavitha at multicorewareinc.com>
# Date 1486043072 -19800
#      Thu Feb 02 19:14:32 2017 +0530
# Node ID 4e18273a7e0318e6a8a46d3f6450d5d451d160d7
# Parent  6051ce2d7864cb3b019c66117661bc5752d1932c
multi-level refinement: support for level 3, 4

Level 3 stores and reuses lookahead info, weights, CU analysis info including
partSize, mergeflag(exclusively for this level). Level 4 currently performs
the same level of refinement as level 3.

diff -r 6051ce2d7864 -r 4e18273a7e03 source/encoder/analysis.cpp
--- a/source/encoder/analysis.cpp	Thu Feb 23 10:42:32 2017 +0530
+++ b/source/encoder/analysis.cpp	Thu Feb 02 19:14:32 2017 +0530
@@ -174,8 +174,11 @@
         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];
-        m_reusePartSize = &m_reuseInterDataCTU->partSize[ctu.m_cuAddr * ctu.m_numPartitions];
-        m_reuseMergeFlag = &m_reuseInterDataCTU->mergeFlag[ctu.m_cuAddr * ctu.m_numPartitions];
+        if (m_param->analysisRefineLevel > 2)
+        {
+            m_reusePartSize = &m_reuseInterDataCTU->partSize[ctu.m_cuAddr * ctu.m_numPartitions];
+            m_reuseMergeFlag = &m_reuseInterDataCTU->mergeFlag[ctu.m_cuAddr * ctu.m_numPartitions];
+        }
         if (m_param->analysisMode == X265_ANALYSIS_SAVE)
             for (int i = 0; i < X265_MAX_PRED_MODE_PER_CTU * numPredDir; i++)
                 m_reuseRef[i] = -1;
@@ -1029,7 +1032,7 @@
                 if (m_param->rdLevel)
                     skipModes = m_param->bEnableEarlySkip && md.bestMode;
             }
-            if (m_reusePartSize[cuGeom.absPartIdx] == SIZE_2Nx2N)
+            if (m_param->analysisRefineLevel > 2 && m_reusePartSize[cuGeom.absPartIdx] == SIZE_2Nx2N)
             {
                 if (m_reuseModes[cuGeom.absPartIdx] != MODE_INTRA  && m_reuseModes[cuGeom.absPartIdx] != 4)
                 {
@@ -1600,7 +1603,7 @@
                 if (m_param->bEnableRecursionSkip && depth && m_modeDepth[depth - 1].bestMode)
                     skipRecursion = md.bestMode && !md.bestMode->cu.getQtRootCbf(0);
             }
-            if (m_reusePartSize[cuGeom.absPartIdx] == SIZE_2Nx2N)
+            if (m_param->analysisRefineLevel > 2 && m_reusePartSize[cuGeom.absPartIdx] == SIZE_2Nx2N)
                 skipRectAmp = true && !!md.bestMode;
         }
     }
diff -r 6051ce2d7864 -r 4e18273a7e03 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Thu Feb 23 10:42:32 2017 +0530
+++ b/source/encoder/encoder.cpp	Thu Feb 02 19:14:32 2017 +0530
@@ -2339,8 +2339,11 @@
         CHECKED_MALLOC_ZERO(interData->ref, int32_t, analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir);
         CHECKED_MALLOC(interData->depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
         CHECKED_MALLOC(interData->modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
-        CHECKED_MALLOC(interData->partSize, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
-        CHECKED_MALLOC(interData->mergeFlag, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
+        if (m_param->analysisRefineLevel > 2)
+        {
+            CHECKED_MALLOC(interData->partSize, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
+            CHECKED_MALLOC(interData->mergeFlag, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
+        }
         uint32_t numPlanes = m_param->internalCsp == X265_CSP_I400 ? 1 : 3;
         CHECKED_MALLOC_ZERO(analysis->wt, WeightParam, numPlanes * numDir);
         analysis->interData = interData;
@@ -2367,8 +2370,11 @@
         X265_FREE(((analysis_inter_data*)analysis->interData)->ref);
         X265_FREE(((analysis_inter_data*)analysis->interData)->depth);
         X265_FREE(((analysis_inter_data*)analysis->interData)->modes);
-        X265_FREE(((analysis_inter_data*)analysis->interData)->mergeFlag);
-        X265_FREE(((analysis_inter_data*)analysis->interData)->partSize);
+        if (m_param->analysisRefineLevel > 2)
+        {
+            X265_FREE(((analysis_inter_data*)analysis->interData)->mergeFlag);
+            X265_FREE(((analysis_inter_data*)analysis->interData)->partSize);
+        }
         X265_FREE(analysis->wt);
         X265_FREE(analysis->interData);
     }
@@ -2522,13 +2528,17 @@
     {
         uint8_t *tempBuf = NULL, *depthBuf = NULL, *modeBuf = NULL, *partSize = NULL, *mergeFlag = NULL;
 
-        tempBuf = X265_MALLOC(uint8_t, depthBytes * 4);
-        X265_FREAD(tempBuf, sizeof(uint8_t), depthBytes * 4, m_analysisFile);
+        int numBuf = m_param->analysisRefineLevel > 2 ? 4 : 2;
+        tempBuf = X265_MALLOC(uint8_t, depthBytes * numBuf);
+        X265_FREAD(tempBuf, sizeof(uint8_t), depthBytes * numBuf, m_analysisFile);
 
         depthBuf = tempBuf;
         modeBuf = tempBuf + depthBytes;
-        partSize = modeBuf + depthBytes;
-        mergeFlag = partSize + depthBytes;
+        if (m_param->analysisRefineLevel > 2)
+        {
+            partSize = modeBuf + depthBytes;
+            mergeFlag = partSize + depthBytes;
+        }
 
         size_t count = 0;
         for (uint32_t d = 0; d < depthBytes; d++)
@@ -2536,8 +2546,11 @@
             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);
-            memset(&((analysis_inter_data *)analysis->interData)->partSize[count], partSize[d], bytes);
-            memset(&((analysis_inter_data *)analysis->interData)->mergeFlag[count], mergeFlag[d], bytes);
+            if (m_param->analysisRefineLevel > 2)
+            {
+                memset(&((analysis_inter_data *)analysis->interData)->partSize[count], partSize[d], bytes);
+                memset(&((analysis_inter_data *)analysis->interData)->mergeFlag[count], mergeFlag[d], bytes);
+            }
             count += bytes;
         }
 
@@ -2742,11 +2755,14 @@
 
                 interDataCTU->modes[depthBytes] = predMode;
 
-                partSize = ctu->m_partSize[absPartIdx];
-                interDataCTU->partSize[depthBytes] = partSize;
-
-                mergeFlag = ctu->m_mergeFlag[absPartIdx];
-                interDataCTU->mergeFlag[depthBytes] = mergeFlag;
+                if (m_param->analysisRefineLevel > 2)
+                {
+                    partSize = ctu->m_partSize[absPartIdx];
+                    interDataCTU->partSize[depthBytes] = partSize;
+
+                    mergeFlag = ctu->m_mergeFlag[absPartIdx];
+                    interDataCTU->mergeFlag[depthBytes] = mergeFlag;
+                }
 
                 absPartIdx += ctu->m_numPartitions >> (depth * 2);
             }
@@ -2761,7 +2777,8 @@
     else
     {
         int numDir = (analysis->sliceType == X265_TYPE_P) ? 1 : 2;
-        analysis->frameRecordSize += depthBytes * 4;
+        int numBuf = m_param->analysisRefineLevel > 2 ? 4 : 2;
+        analysis->frameRecordSize += depthBytes * numBuf;
         analysis->frameRecordSize += sizeof(int32_t)* analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir;
         analysis->frameRecordSize += sizeof(WeightParam)* 3 * numDir;
     }
@@ -2786,8 +2803,11 @@
         int numDir = analysis->sliceType == X265_TYPE_P ? 1 : 2;
         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);
-        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 > 2)
+        {
+            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);
+        }
         X265_FWRITE(((analysis_inter_data*)analysis->interData)->ref, sizeof(int32_t), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir, m_analysisFile);
         uint32_t numPlanes = m_param->internalCsp == X265_CSP_I400 ? 1 : 3;
         X265_FWRITE((WeightParam*)analysis->wt, sizeof(WeightParam), numPlanes * numDir, m_analysisFile);


More information about the x265-devel mailing list