[x265] [PATCH 5 of 7] use param to replace MACRO NUM_4x4_PARTITIONS

kavitha at multicorewareinc.com kavitha at multicorewareinc.com
Wed Jun 21 08:44:55 CEST 2017


# HG changeset patch
# User Kavitha Sampath <kavitha at multicorewareinc.com>
# Date 1496127278 -19800
#      Tue May 30 12:24:38 2017 +0530
# Node ID 4b3d1a1f4838ee86cc9528643b6abb1f31670ada
# Parent  005dfda46203772f81f94a28dd86b6303aadfef5
use param to replace MACRO NUM_4x4_PARTITIONS

diff -r 005dfda46203 -r 4b3d1a1f4838 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Tue May 30 10:58:25 2017 +0530
+++ b/source/CMakeLists.txt	Tue May 30 12:24:38 2017 +0530
@@ -29,7 +29,7 @@
 option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 125)
+set(X265_BUILD 126)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r 005dfda46203 -r 4b3d1a1f4838 source/common/cudata.cpp
--- a/source/common/cudata.cpp	Tue May 30 10:58:25 2017 +0530
+++ b/source/common/cudata.cpp	Tue May 30 12:24:38 2017 +0530
@@ -125,7 +125,7 @@
     m_chromaFormat  = csp;
     m_hChromaShift  = CHROMA_H_SHIFT(csp);
     m_vChromaShift  = CHROMA_V_SHIFT(csp);
-    m_numPartitions = NUM_4x4_PARTITIONS >> (depth * 2);
+    m_numPartitions = param.num4x4Partitions >> (depth * 2);
 
     if (!s_partSet[0])
     {
@@ -283,7 +283,7 @@
     m_cuPelX        = (cuAddr % m_slice->m_sps->numCuInWidth) << m_slice->m_param->maxLog2CUSize;
     m_cuPelY        = (cuAddr / m_slice->m_sps->numCuInWidth) << m_slice->m_param->maxLog2CUSize;
     m_absIdxInCTU   = 0;
-    m_numPartitions = NUM_4x4_PARTITIONS;
+    m_numPartitions = m_encData->m_param->num4x4Partitions;
     m_bFirstRowInSlice = (uint8_t)firstRowInSlice;
     m_bLastRowInSlice  = (uint8_t)lastRowInSlice;
     m_bLastCuInSlice   = (uint8_t)lastCuInSlice;
@@ -658,7 +658,7 @@
         return m_cuLeft;
     }
 
-    alPartUnitIdx = NUM_4x4_PARTITIONS - 1;
+    alPartUnitIdx = m_encData->m_param->num4x4Partitions - 1;
     return m_cuAboveLeft;
 }
 
@@ -867,7 +867,7 @@
         if (m_absIdxInCTU)
             return m_encData->getPicCTU(m_cuAddr)->getLastCodedQP(m_absIdxInCTU);
         else if (m_cuAddr > 0 && !(m_slice->m_pps->bEntropyCodingSyncEnabled && !(m_cuAddr % m_slice->m_sps->numCuInWidth)))
-            return m_encData->getPicCTU(m_cuAddr - 1)->getLastCodedQP(NUM_4x4_PARTITIONS);
+            return m_encData->getPicCTU(m_cuAddr - 1)->getLastCodedQP(m_encData->m_param->num4x4Partitions);
         else
             return (int8_t)m_slice->m_sliceQp;
     }
@@ -999,7 +999,7 @@
 
 bool CUData::setQPSubCUs(int8_t qp, uint32_t absPartIdx, uint32_t depth)
 {
-    uint32_t curPartNumb = NUM_4x4_PARTITIONS >> (depth << 1);
+    uint32_t curPartNumb = m_encData->m_param->num4x4Partitions >> (depth << 1);
     uint32_t curPartNumQ = curPartNumb >> 2;
 
     if (m_cuDepth[absPartIdx] > depth)
@@ -2103,6 +2103,8 @@
 
 void CUData::calcCTUGeoms(uint32_t ctuWidth, uint32_t ctuHeight, uint32_t maxCUSize, uint32_t minCUSize, CUGeom cuDataArray[CUGeom::MAX_GEOMS])
 {
+    uint32_t num4x4Partition = (1U << ((g_log2Size[maxCUSize] - LOG2_UNIT_SIZE) << 1));
+
     // Initialize the coding blocks inside the CTB
     for (uint32_t log2CUSize = g_log2Size[maxCUSize], rangeCUIdx = 0; log2CUSize >= g_log2Size[minCUSize]; log2CUSize--)
     {
@@ -2131,7 +2133,7 @@
                 cu->log2CUSize = log2CUSize;
                 cu->childOffset = childIdx - cuIdx;
                 cu->absPartIdx = g_depthScanIdx[yOffset][xOffset] * 4;
-                cu->numPartitions = (NUM_4x4_PARTITIONS >> ((g_log2Size[maxCUSize] - cu->log2CUSize) * 2));
+                cu->numPartitions = (num4x4Partition >> ((g_log2Size[maxCUSize] - cu->log2CUSize) * 2));
                 cu->depth = g_log2Size[maxCUSize] - log2CUSize;
                 cu->geomRecurId = cuIdx;
 
diff -r 005dfda46203 -r 4b3d1a1f4838 source/common/cudata.h
--- a/source/common/cudata.h	Tue May 30 10:58:25 2017 +0530
+++ b/source/common/cudata.h	Tue May 30 12:24:38 2017 +0530
@@ -352,7 +352,7 @@
 
     bool create(uint32_t depth, uint32_t csp, uint32_t numInstances, const x265_param& param)
     {
-        uint32_t numPartition = NUM_4x4_PARTITIONS >> (depth * 2);
+        uint32_t numPartition = param.num4x4Partitions >> (depth * 2);
         uint32_t cuSize = param.maxCUSize >> depth;
         uint32_t sizeL = cuSize * cuSize;
         if (csp == X265_CSP_I400)
diff -r 005dfda46203 -r 4b3d1a1f4838 source/common/frame.cpp
--- a/source/common/frame.cpp	Tue May 30 10:58:25 2017 +0530
+++ b/source/common/frame.cpp	Tue May 30 12:24:38 2017 +0530
@@ -71,9 +71,9 @@
         CHECKED_MALLOC_ZERO(m_addOnPrevChange, int *, numCTUsInFrame);
         for (uint32_t i = 0; i < numCTUsInFrame; i++)
         {
-            CHECKED_MALLOC_ZERO(m_addOnDepth[i], uint8_t, uint32_t(NUM_4x4_PARTITIONS));
-            CHECKED_MALLOC_ZERO(m_addOnCtuInfo[i], uint8_t, uint32_t(NUM_4x4_PARTITIONS));
-            CHECKED_MALLOC_ZERO(m_addOnPrevChange[i], int, uint32_t(NUM_4x4_PARTITIONS));
+            CHECKED_MALLOC_ZERO(m_addOnDepth[i], uint8_t, uint32_t(param->num4x4Partitions));
+            CHECKED_MALLOC_ZERO(m_addOnCtuInfo[i], uint8_t, uint32_t(param->num4x4Partitions));
+            CHECKED_MALLOC_ZERO(m_addOnPrevChange[i], int, uint32_t(param->num4x4Partitions));
         }
     }
 
diff -r 005dfda46203 -r 4b3d1a1f4838 source/common/slice.cpp
--- a/source/common/slice.cpp	Tue May 30 10:58:25 2017 +0530
+++ b/source/common/slice.cpp	Tue May 30 12:24:38 2017 +0530
@@ -185,8 +185,8 @@
 uint32_t Slice::realEndAddress(uint32_t endCUAddr) const
 {
     // Calculate end address
-    uint32_t internalAddress = (endCUAddr - 1) % NUM_4x4_PARTITIONS;
-    uint32_t externalAddress = (endCUAddr - 1) / NUM_4x4_PARTITIONS;
+    uint32_t internalAddress = (endCUAddr - 1) % m_param->num4x4Partitions;
+    uint32_t externalAddress = (endCUAddr - 1) / m_param->num4x4Partitions;
     uint32_t xmax = m_sps->picWidthInLumaSamples - (externalAddress % m_sps->numCuInWidth) * m_param->maxCUSize;
     uint32_t ymax = m_sps->picHeightInLumaSamples - (externalAddress / m_sps->numCuInWidth) * m_param->maxCUSize;
 
@@ -194,13 +194,13 @@
         internalAddress--;
 
     internalAddress++;
-    if (internalAddress == NUM_4x4_PARTITIONS)
+    if (internalAddress == m_param->num4x4Partitions)
     {
         internalAddress = 0;
         externalAddress++;
     }
 
-    return externalAddress * NUM_4x4_PARTITIONS + internalAddress;
+    return externalAddress * m_param->num4x4Partitions + internalAddress;
 }
 
 
diff -r 005dfda46203 -r 4b3d1a1f4838 source/encoder/api.cpp
--- a/source/encoder/api.cpp	Tue May 30 10:58:25 2017 +0530
+++ b/source/encoder/api.cpp	Tue May 30 12:24:38 2017 +0530
@@ -366,7 +366,7 @@
 
         uint32_t numCUsInFrame   = widthInCU * heightInCU;
         pic->analysisData.numCUsInFrame = numCUsInFrame;
-        pic->analysisData.numPartitions = NUM_4x4_PARTITIONS;
+        pic->analysisData.numPartitions = param->num4x4Partitions;
     }
 }
 
diff -r 005dfda46203 -r 4b3d1a1f4838 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Tue May 30 10:58:25 2017 +0530
+++ b/source/encoder/encoder.cpp	Tue May 30 12:24:38 2017 +0530
@@ -1037,7 +1037,7 @@
                 slice->m_pps = &m_pps;
                 slice->m_param = m_param;
                 slice->m_maxNumMergeCand = m_param->maxNumMergeCand;
-                slice->m_endCUAddr = slice->realEndAddress(m_sps.numCUsInFrame * NUM_4x4_PARTITIONS);
+                slice->m_endCUAddr = slice->realEndAddress(m_sps.numCUsInFrame * m_param->num4x4Partitions);
             }
 
             if (m_param->searchMethod == X265_SEA && frameEnc->m_lowres.sliceType != X265_TYPE_B)
@@ -1114,7 +1114,7 @@
 
                 uint32_t numCUsInFrame   = widthInCU * heightInCU;
                 analysis->numCUsInFrame  = numCUsInFrame;
-                analysis->numPartitions  = NUM_4x4_PARTITIONS;
+                analysis->numPartitions  = m_param->num4x4Partitions;
                 allocAnalysis(analysis);
             }
             /* determine references, setup RPS, etc */
@@ -1985,7 +1985,7 @@
     sps->numCuInWidth = (m_param->sourceWidth + m_param->maxCUSize - 1) / m_param->maxCUSize;
     sps->numCuInHeight = (m_param->sourceHeight + m_param->maxCUSize - 1) / m_param->maxCUSize;
     sps->numCUsInFrame = sps->numCuInWidth * sps->numCuInHeight;
-    sps->numPartitions = NUM_4x4_PARTITIONS;
+    sps->numPartitions = m_param->num4x4Partitions;
     sps->numPartInCUSize = 1 << m_param->unitSizeDepth;
 
     sps->log2MinCodingBlockSize = m_param->maxLog2CUSize - m_param->maxCUDepth;
@@ -2645,6 +2645,7 @@
     p->maxLog2CUSize = g_log2Size[p->maxCUSize];
     p->maxCUDepth    = p->maxLog2CUSize - g_log2Size[p->minCUSize];
     p->unitSizeDepth = p->maxLog2CUSize - LOG2_UNIT_SIZE;
+    p->num4x4Partitions = (1U << (p->unitSizeDepth << 1));
 }
 
 void Encoder::allocAnalysis(x265_analysis_data* analysis)
@@ -2781,8 +2782,8 @@
 
     uint32_t numCUsInFrame = widthInCU * heightInCU;
     CHECKED_MALLOC_ZERO(analysisFrameData, analysis2PassFrameData, 1);
-    CHECKED_MALLOC_ZERO(analysisFrameData->depth, uint8_t, NUM_4x4_PARTITIONS * numCUsInFrame);
-    CHECKED_MALLOC_ZERO(analysisFrameData->distortion, sse_t, NUM_4x4_PARTITIONS * numCUsInFrame);
+    CHECKED_MALLOC_ZERO(analysisFrameData->depth, uint8_t, m_param->num4x4Partitions * numCUsInFrame);
+    CHECKED_MALLOC_ZERO(analysisFrameData->distortion, sse_t, m_param->num4x4Partitions * numCUsInFrame);
     if (m_param->rc.bStatRead)
     {
         CHECKED_MALLOC_ZERO(analysisFrameData->ctuDistortion, sse_t, numCUsInFrame);
@@ -2792,13 +2793,13 @@
     }
     if (!IS_X265_TYPE_I(sliceType))
     {
-        CHECKED_MALLOC_ZERO(analysisFrameData->m_mv[0], MV, NUM_4x4_PARTITIONS * numCUsInFrame);
-        CHECKED_MALLOC_ZERO(analysisFrameData->m_mv[1], MV, NUM_4x4_PARTITIONS * numCUsInFrame);
-        CHECKED_MALLOC_ZERO(analysisFrameData->mvpIdx[0], int, NUM_4x4_PARTITIONS * numCUsInFrame);
-        CHECKED_MALLOC_ZERO(analysisFrameData->mvpIdx[1], int, NUM_4x4_PARTITIONS * numCUsInFrame);
-        CHECKED_MALLOC_ZERO(analysisFrameData->ref[0], int32_t, NUM_4x4_PARTITIONS * numCUsInFrame);
-        CHECKED_MALLOC_ZERO(analysisFrameData->ref[1], int32_t, NUM_4x4_PARTITIONS * numCUsInFrame);
-        CHECKED_MALLOC(analysisFrameData->modes, uint8_t, NUM_4x4_PARTITIONS * numCUsInFrame);
+        CHECKED_MALLOC_ZERO(analysisFrameData->m_mv[0], MV, m_param->num4x4Partitions * numCUsInFrame);
+        CHECKED_MALLOC_ZERO(analysisFrameData->m_mv[1], MV, m_param->num4x4Partitions * numCUsInFrame);
+        CHECKED_MALLOC_ZERO(analysisFrameData->mvpIdx[0], int, m_param->num4x4Partitions * numCUsInFrame);
+        CHECKED_MALLOC_ZERO(analysisFrameData->mvpIdx[1], int, m_param->num4x4Partitions * numCUsInFrame);
+        CHECKED_MALLOC_ZERO(analysisFrameData->ref[0], int32_t, m_param->num4x4Partitions * numCUsInFrame);
+        CHECKED_MALLOC_ZERO(analysisFrameData->ref[1], int32_t, m_param->num4x4Partitions * numCUsInFrame);
+        CHECKED_MALLOC(analysisFrameData->modes, uint8_t, m_param->num4x4Partitions * numCUsInFrame);
     }
 
     analysis->analysisFramedata = analysisFrameData;
@@ -3109,12 +3110,12 @@
     double sum = 0, sqrSum = 0;
     for (uint32_t d = 0; d < depthBytes; d++)
     {
-        int bytes = NUM_4x4_PARTITIONS >> (depthBuf[d] * 2);
+        int bytes = m_param->num4x4Partitions >> (depthBuf[d] * 2);
         memset(&analysisFrameData->depth[count], depthBuf[d], bytes);
         analysisFrameData->distortion[count] = distortionBuf[d];
         analysisFrameData->ctuDistortion[ctuCount] += analysisFrameData->distortion[count];
         count += bytes;
-        if ((count % (unsigned)NUM_4x4_PARTITIONS) == 0)
+        if ((count % (unsigned)m_param->num4x4Partitions) == 0)
         {
             analysisFrameData->scaledDistortion[ctuCount] = X265_LOG2(X265_MAX(analysisFrameData->ctuDistortion[ctuCount], 1));
             sum += analysisFrameData->scaledDistortion[ctuCount];
@@ -3162,7 +3163,7 @@
         count = 0;
         for (uint32_t d = 0; d < depthBytes; d++)
         {
-            size_t bytes = NUM_4x4_PARTITIONS >> (depthBuf[d] * 2);
+            size_t bytes = m_param->num4x4Partitions >> (depthBuf[d] * 2);
             for (int i = 0; i < numDir; i++)
             {
                 for (size_t j = count, k = 0; k < bytes; j++, k++)
diff -r 005dfda46203 -r 4b3d1a1f4838 source/encoder/entropy.cpp
--- a/source/encoder/entropy.cpp	Tue May 30 10:58:25 2017 +0530
+++ b/source/encoder/entropy.cpp	Tue May 30 12:24:38 2017 +0530
@@ -902,7 +902,7 @@
     {
         // Encode slice finish
         uint32_t bTerminateSlice = ctu.m_bLastCuInSlice;
-        if (cuAddr + (NUM_4x4_PARTITIONS >> (depth << 1)) == realEndAddress)
+        if (cuAddr + (slice->m_param->num4x4Partitions >> (depth << 1)) == realEndAddress)
             bTerminateSlice = 1;
 
         // The 1-terminating bit is added to all streams, so don't add it here when it's 1.
diff -r 005dfda46203 -r 4b3d1a1f4838 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Tue May 30 10:58:25 2017 +0530
+++ b/source/encoder/frameencoder.cpp	Tue May 30 12:24:38 2017 +0530
@@ -1111,7 +1111,7 @@
 {
     Slice* slice = m_frame->m_encData->m_slice;
     const uint32_t widthInLCUs = slice->m_sps->numCuInWidth;
-    const uint32_t lastCUAddr = (slice->m_endCUAddr + NUM_4x4_PARTITIONS - 1) / NUM_4x4_PARTITIONS;
+    const uint32_t lastCUAddr = (slice->m_endCUAddr + m_param->num4x4Partitions - 1) / m_param->num4x4Partitions;
     const uint32_t numSubstreams = m_param->bEnableWavefront ? slice->m_sps->numCuInHeight : 1;
 
     SAOParam* saoParam = slice->m_sps->bUseSAO ? m_frame->m_encData->m_saoParam : NULL;
diff -r 005dfda46203 -r 4b3d1a1f4838 source/encoder/ratecontrol.cpp
--- a/source/encoder/ratecontrol.cpp	Tue May 30 10:58:25 2017 +0530
+++ b/source/encoder/ratecontrol.cpp	Tue May 30 12:24:38 2017 +0530
@@ -2613,7 +2613,7 @@
             for (uint32_t i = 0; i < slice->m_sps->numCuInHeight; i++)
                 avgQpAq += curEncData.m_rowStat[i].sumQpAq;
 
-            avgQpAq /= (slice->m_sps->numCUsInFrame * NUM_4x4_PARTITIONS);
+            avgQpAq /= (slice->m_sps->numCUsInFrame * m_param->num4x4Partitions);
             curEncData.m_avgQpAq = avgQpAq;
         }
         else
diff -r 005dfda46203 -r 4b3d1a1f4838 source/x265.h
--- a/source/x265.h	Tue May 30 10:58:25 2017 +0530
+++ b/source/x265.h	Tue May 30 12:24:38 2017 +0530
@@ -1468,6 +1468,9 @@
     /* CU depth with respect to maximum transform size */
     uint32_t  unitSizeDepth;
 
+    /* Number of 4x4 units in maximum CU size */
+    uint32_t  num4x4Partitions;
+
 } x265_param;
 
 /* x265_param_alloc:


More information about the x265-devel mailing list