[x265-commits] [x265] Create API function for allocating and freeing x265_analy...

Aasaipriya Chandran aasaipriya at multicorewareinc.com
Sat Jul 21 01:03:03 CEST 2018


details:   http://hg.videolan.org/x265/rev/b0d31e2bc0df
branches:  
changeset: 12396:b0d31e2bc0df
user:      Aasaipriya Chandran <aasaipriya at multicorewareinc.com>
date:      Fri Jul 20 14:20:22 2018 +0530
description:
Create API function for allocating and freeing x265_analysis_data.
1. Merge the two overloaded functions existed for allocAnalysis and moved as API function - x265_alloc_analysis_data
2. Merge the two overloaded functions existed for freeAnalysis and moved as API function - x265_free_analysis_data
3. Bump up the build number as new API functions are added
4. Update the document
Subject: [x265] Expose WeightParam, analysis_inter_data, analysis_intra_data and analysisDistortionData structures in API

details:   http://hg.videolan.org/x265/rev/5d34bbf671f7
branches:  
changeset: 12397:5d34bbf671f7
user:      Aasaipriya Chandran <aasaipriya at multicorewareinc.com>
date:      Fri Jul 20 14:03:53 2018 +0530
description:
Expose WeightParam, analysis_inter_data, analysis_intra_data and analysisDistortionData structures in API

diffstat:

 doc/reST/api.rst            |   12 +
 source/CMakeLists.txt       |    2 +-
 source/common/framedata.h   |   37 ---
 source/encoder/analysis.cpp |   41 ++-
 source/encoder/analysis.h   |   14 +-
 source/encoder/api.cpp      |  171 +++++++++++++++++
 source/encoder/encoder.cpp  |  436 ++++++++++---------------------------------
 source/encoder/encoder.h    |   10 +-
 source/encoder/search.cpp   |    8 +-
 source/x265.h               |  105 ++++++++-
 10 files changed, 421 insertions(+), 415 deletions(-)

diffs (truncated from 1479 to 300 lines):

diff -r e2759ae31c36 -r 5d34bbf671f7 doc/reST/api.rst
--- a/doc/reST/api.rst	Thu Jul 19 12:25:26 2018 +0530
+++ b/doc/reST/api.rst	Fri Jul 20 14:03:53 2018 +0530
@@ -223,6 +223,18 @@ changes made to the parameters for auto-
      *     returns negative on error, 0 access unit were output.*/
      int x265_set_analysis_data(x265_encoder *encoder, x265_analysis_data *analysis_data, int poc, uint32_t cuBytes);
 
+**x265_alloc_analysis_data()** may be used to allocate memory for the x265_analysis_data::
+
+    /* x265_alloc_analysis_data:
+     *     Allocate memory for the x265_analysis_data object's internal structures. */
+     void x265_alloc_analysis_data(x265_param *param, x265_analysis_data* analysis);
+
+**x265_free_analysis_data()** may be used to free memory for the x265_analysis_data::
+
+    /* x265_free_analysis_data:
+     *    Free the allocated memory for x265_analysis_data object's internal structures. */
+     void x265_free_analysis_data(x265_param *param, x265_analysis_data* analysis);
+
 Pictures
 ========
 
diff -r e2759ae31c36 -r 5d34bbf671f7 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Thu Jul 19 12:25:26 2018 +0530
+++ b/source/CMakeLists.txt	Fri Jul 20 14:03:53 2018 +0530
@@ -29,7 +29,7 @@ option(NATIVE_BUILD "Target the build CP
 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 162)
+set(X265_BUILD 163)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r e2759ae31c36 -r 5d34bbf671f7 source/common/framedata.h
--- a/source/common/framedata.h	Thu Jul 19 12:25:26 2018 +0530
+++ b/source/common/framedata.h	Fri Jul 20 14:03:53 2018 +0530
@@ -179,42 +179,5 @@ public:
     inline CUData* getPicCTU(uint32_t ctuAddr) { return &m_picCTU[ctuAddr]; }
 };
 
-/* Stores intra analysis data for a single frame. This struct needs better packing */
-struct analysis_intra_data
-{
-    uint8_t*  depth;
-    uint8_t*  modes;
-    char*     partSizes;
-    uint8_t*  chromaModes;
-};
-
-/* Stores inter analysis data for a single frame */
-struct analysis_inter_data
-{
-    int32_t*    ref;
-    uint8_t*    depth;
-    uint8_t*    modes;
-    uint8_t*    partSize;
-    uint8_t*    mergeFlag;
-    uint8_t*    interDir;
-    uint8_t*    mvpIdx[2];
-    int8_t*     refIdx[2];
-    MV*         mv[2];
-   int64_t*     sadCost;
-};
-
-struct analysisDistortionData
-{
-    sse_t*        distortion;
-    sse_t*        ctuDistortion;
-    double*       scaledDistortion;
-    double        averageDistortion;
-    double        sdDistortion;
-    uint32_t      highDistortionCtuCount;
-    uint32_t      lowDistortionCtuCount;
-    double*       offset;
-    double*       threshold;
-};
-
 }
 #endif // ifndef X265_FRAMEDATA_H
diff -r e2759ae31c36 -r 5d34bbf671f7 source/encoder/analysis.cpp
--- a/source/encoder/analysis.cpp	Thu Jul 19 12:25:26 2018 +0530
+++ b/source/encoder/analysis.cpp	Fri Jul 20 14:03:53 2018 +0530
@@ -37,7 +37,7 @@
 using namespace X265_NS;
 
 /* An explanation of rate distortion levels (--rd-level)
- * 
+ *
  * rd-level 0 generates no recon per CU (NO RDO or Quant)
  *
  *   sa8d selection between merge / skip / inter / intra and split
@@ -70,6 +70,12 @@ using namespace X265_NS;
  * rd-level 5,6 does RDO for each inter mode
  */
 
+#define COPY_TO_MV(s1, s2, d1, d2)\
+    {\
+        d1 = s1; \
+        d2 = s2; \
+    }
+
 Analysis::Analysis()
 {
     m_reuseInterDataCTU = NULL;
@@ -190,7 +196,7 @@ Mode& Analysis::compressCTU(CUData& ctu,
     if (m_param->analysisMultiPassRefine && m_param->rc.bStatRead && (m_slice->m_sliceType != I_SLICE))
     {
         int numPredDir = m_slice->isInterP() ? 1 : 2;
-        m_reuseInterDataCTU = (analysis_inter_data*)m_frame->m_analysisData.interData;
+        m_reuseInterDataCTU = m_frame->m_analysisData.interData;
         for (int dir = 0; dir < numPredDir; dir++)
         {
             m_reuseMv[dir] = &m_reuseInterDataCTU->mv[dir][ctu.m_cuAddr * ctu.m_numPartitions];
@@ -204,7 +210,7 @@ Mode& Analysis::compressCTU(CUData& ctu,
     if ((m_param->analysisSave || m_param->analysisLoad) && m_slice->m_sliceType != I_SLICE && m_param->analysisReuseLevel > 1 && m_param->analysisReuseLevel < 10)
     {
         int numPredDir = m_slice->isInterP() ? 1 : 2;
-        m_reuseInterDataCTU = (analysis_inter_data*)m_frame->m_analysisData.interData;
+        m_reuseInterDataCTU = 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];
@@ -221,7 +227,7 @@ Mode& Analysis::compressCTU(CUData& ctu,
 
     if (m_slice->m_sliceType == I_SLICE)
     {
-        analysis_intra_data* intraDataCTU = (analysis_intra_data*)m_frame->m_analysisData.intraData;
+        x265_analysis_intra_data* intraDataCTU = m_frame->m_analysisData.intraData;
         if (m_param->analysisLoad && m_param->analysisReuseLevel > 1)
         {
             memcpy(ctu.m_cuDepth, &intraDataCTU->depth[ctu.m_cuAddr * numPartition], sizeof(uint8_t) * numPartition);
@@ -240,7 +246,7 @@ Mode& Analysis::compressCTU(CUData& ctu,
 
         if (bCopyAnalysis)
         {
-            analysis_inter_data* interDataCTU = (analysis_inter_data*)m_frame->m_analysisData.interData;
+            x265_analysis_inter_data* interDataCTU = m_frame->m_analysisData.interData;
             int posCTU = ctu.m_cuAddr * numPartition;
             memcpy(ctu.m_cuDepth, &interDataCTU->depth[posCTU], sizeof(uint8_t) * numPartition);
             memcpy(ctu.m_predMode, &interDataCTU->modes[posCTU], sizeof(uint8_t) * numPartition);
@@ -250,7 +256,7 @@ Mode& Analysis::compressCTU(CUData& ctu,
 
             if ((m_slice->m_sliceType == P_SLICE || m_param->bIntraInBFrames) && !m_param->bMVType)
             {
-                analysis_intra_data* intraDataCTU = (analysis_intra_data*)m_frame->m_analysisData.intraData;
+                x265_analysis_intra_data* intraDataCTU = m_frame->m_analysisData.intraData;
                 memcpy(ctu.m_lumaIntraDir, &intraDataCTU->modes[posCTU], sizeof(uint8_t) * numPartition);
                 memcpy(ctu.m_chromaIntraDir, &intraDataCTU->chromaModes[posCTU], sizeof(uint8_t) * numPartition);
             }
@@ -276,14 +282,14 @@ Mode& Analysis::compressCTU(CUData& ctu,
         }
         else if ((m_param->analysisLoad && m_param->analysisReuseLevel == 10) || ((m_param->bMVType == AVC_INFO) && m_param->analysisReuseLevel >= 7 && ctu.m_numPartitions <= 16))
         {
-            analysis_inter_data* interDataCTU = (analysis_inter_data*)m_frame->m_analysisData.interData;
+            x265_analysis_inter_data* interDataCTU = m_frame->m_analysisData.interData;
             int posCTU = ctu.m_cuAddr * numPartition;
             memcpy(ctu.m_cuDepth, &interDataCTU->depth[posCTU], sizeof(uint8_t) * numPartition);
             memcpy(ctu.m_predMode, &interDataCTU->modes[posCTU], sizeof(uint8_t) * numPartition);
             memcpy(ctu.m_partSize, &interDataCTU->partSize[posCTU], sizeof(uint8_t) * numPartition);
             if ((m_slice->m_sliceType == P_SLICE || m_param->bIntraInBFrames) && !(m_param->bMVType == AVC_INFO))
             {
-                analysis_intra_data* intraDataCTU = (analysis_intra_data*)m_frame->m_analysisData.intraData;
+                x265_analysis_intra_data* intraDataCTU = m_frame->m_analysisData.intraData;
                 memcpy(ctu.m_lumaIntraDir, &intraDataCTU->modes[posCTU], sizeof(uint8_t) * numPartition);
                 memcpy(ctu.m_chromaIntraDir, &intraDataCTU->chromaModes[posCTU], sizeof(uint8_t) * numPartition);
             }
@@ -2455,13 +2461,15 @@ void Analysis::recodeCU(const CUData& pa
                 PredictionUnit pu(mode.cu, cuGeom, part);
                 if ((m_param->analysisLoad && m_param->analysisReuseLevel == 10) || (m_param->bMVType == AVC_INFO && m_param->analysisReuseLevel >= 7))
                 {
-                    analysis_inter_data* interDataCTU = (analysis_inter_data*)m_frame->m_analysisData.interData;
+                    x265_analysis_inter_data* interDataCTU = m_frame->m_analysisData.interData;
                     int cuIdx = (mode.cu.m_cuAddr * parentCTU.m_numPartitions) + cuGeom.absPartIdx;
                     mode.cu.m_mergeFlag[pu.puAbsPartIdx] = interDataCTU->mergeFlag[cuIdx + part];
                     mode.cu.setPUInterDir(interDataCTU->interDir[cuIdx + part], pu.puAbsPartIdx, part);
                     for (int list = 0; list < m_slice->isInterB() + 1; list++)
                     {
-                        mode.cu.setPUMv(list, interDataCTU->mv[list][cuIdx + part], pu.puAbsPartIdx, part);
+                        MV dst; x265_analysis_MV src = interDataCTU->mv[list][cuIdx + part];
+                        COPY_TO_MV(src.x, src.y, dst.x, dst.y);
+                        mode.cu.setPUMv(list, dst, pu.puAbsPartIdx, part);
                         mode.cu.setPURefIdx(list, interDataCTU->refIdx[list][cuIdx + part], pu.puAbsPartIdx, part);
                         mode.cu.m_mvpIdx[list][pu.puAbsPartIdx] = interDataCTU->mvpIdx[list][cuIdx + part];
                     }
@@ -2483,7 +2491,10 @@ void Analysis::recodeCU(const CUData& pa
                             if (m_param->interRefine != 1)
                                 mvp = mode.amvpCand[list][ref][mode.cu.m_mvpIdx[list][pu.puAbsPartIdx]];
                             else
-                                mvp = interDataCTU->mv[list][cuIdx + part];
+                            {
+                                x265_analysis_MV src = interDataCTU->mv[list][cuIdx + part];
+                                COPY_TO_MV(src.x, src.y, mvp.x, mvp.y);
+                            }
                             if (m_param->mvRefine || m_param->interRefine == 1)
                             {
                                 MV outmv;
@@ -3021,8 +3032,9 @@ void Analysis::checkInter_rd0_4(Mode& in
             for (int32_t i = 0; i < numPredDir; i++)
             {
                 int* ref = &m_reuseRef[i * m_frame->m_analysisData.numPartitions * m_frame->m_analysisData.numCUsInFrame];
+                x265_analysis_MV src = m_reuseMv[i][cuGeom.absPartIdx]; MV dst = bestME[i].mv;
                 bestME[i].ref = ref[cuGeom.absPartIdx];
-                bestME[i].mv = m_reuseMv[i][cuGeom.absPartIdx];
+                COPY_TO_MV(src.x, src.y, dst.x, dst.y);
                 bestME[i].mvpIdx = m_reuseMvpIdx[i][cuGeom.absPartIdx];
             }
         }
@@ -3085,9 +3097,10 @@ void Analysis::checkInter_rd5_6(Mode& in
             MotionData* bestME = interMode.bestME[part];
             for (int32_t i = 0; i < numPredDir; i++)
             {
+                x265_analysis_MV src = m_reuseMv[i][cuGeom.absPartIdx]; MV dst = bestME[i].mv;
                 int* ref = &m_reuseRef[i * m_frame->m_analysisData.numPartitions * m_frame->m_analysisData.numCUsInFrame];
                 bestME[i].ref = ref[cuGeom.absPartIdx];
-                bestME[i].mv = m_reuseMv[i][cuGeom.absPartIdx];
+                COPY_TO_MV(src.x, src.y, dst.x, dst.y);
                 bestME[i].mvpIdx = m_reuseMvpIdx[i][cuGeom.absPartIdx];
             }
         }
@@ -3562,7 +3575,7 @@ int Analysis::calculateQpforCuSize(const
 
     if (m_param->analysisMultiPassDistortion && m_param->rc.bStatRead)
     {
-        analysisDistortionData* distortionData = (analysisDistortionData*)m_frame->m_analysisData.distortionData;
+        x265_analysis_distortion_data* distortionData = m_frame->m_analysisData.distortionData;
         if ((distortionData->threshold[ctu.m_cuAddr] < 0.9 || distortionData->threshold[ctu.m_cuAddr] > 1.1)
             && distortionData->highDistortionCtuCount && distortionData->lowDistortionCtuCount)
             qp += distortionData->offset[ctu.m_cuAddr];
diff -r e2759ae31c36 -r 5d34bbf671f7 source/encoder/analysis.h
--- a/source/encoder/analysis.h	Thu Jul 19 12:25:26 2018 +0530
+++ b/source/encoder/analysis.h	Fri Jul 20 14:03:53 2018 +0530
@@ -123,13 +123,13 @@ public:
 
 protected:
     /* Analysis data for save/load mode, writes/reads data based on absPartIdx */
-    analysis_inter_data* m_reuseInterDataCTU;
-    int32_t*             m_reuseRef;
-    uint8_t*             m_reuseDepth;
-    uint8_t*             m_reuseModes;
-    uint8_t*             m_reusePartSize;
-    uint8_t*             m_reuseMergeFlag;
-    MV*                  m_reuseMv[2];
+    x265_analysis_inter_data*  m_reuseInterDataCTU;
+    int32_t*                   m_reuseRef;
+    uint8_t*                   m_reuseDepth;
+    uint8_t*                   m_reuseModes;
+    uint8_t*                   m_reusePartSize;
+    uint8_t*                   m_reuseMergeFlag;
+    x265_analysis_MV*          m_reuseMv[2];
     uint8_t*             m_reuseMvpIdx[2];
 
     uint32_t             m_splitRefIdx[4];
diff -r e2759ae31c36 -r 5d34bbf671f7 source/encoder/api.cpp
--- a/source/encoder/api.cpp	Thu Jul 19 12:25:26 2018 +0530
+++ b/source/encoder/api.cpp	Fri Jul 20 14:03:53 2018 +0530
@@ -403,6 +403,177 @@ int x265_set_analysis_data(x265_encoder 
     return -1;
 }
 
+void x265_alloc_analysis_data(x265_param *param, x265_analysis_data* analysis)
+{
+    X265_CHECK(analysis->sliceType, "invalid slice type\n");
+    analysis->interData = NULL;
+    analysis->intraData = NULL;
+    analysis->distortionData = NULL;
+    bool isVbv = param->rc.vbvMaxBitrate > 0 && param->rc.vbvBufferSize > 0;
+    int numDir = 2; //irrespective of P or B slices set direction as 2
+    uint32_t numPlanes = param->internalCsp == X265_CSP_I400 ? 1 : 3;
+
+    //Allocate memory for distortionData pointer
+    x265_analysis_distortion_data *distortionData = analysis->distortionData;
+    CHECKED_MALLOC_ZERO(distortionData, x265_analysis_distortion_data, 1);
+    CHECKED_MALLOC_ZERO(distortionData->distortion, sse_t, analysis->numPartitions * analysis->numCUsInFrame);
+    if (param->rc.bStatRead)
+    {
+        CHECKED_MALLOC_ZERO(distortionData->ctuDistortion, sse_t, analysis->numCUsInFrame);
+        CHECKED_MALLOC_ZERO(distortionData->scaledDistortion, double, analysis->numCUsInFrame);
+        CHECKED_MALLOC_ZERO(distortionData->offset, double, analysis->numCUsInFrame);
+        CHECKED_MALLOC_ZERO(distortionData->threshold, double, analysis->numCUsInFrame);
+    }
+    analysis->distortionData = distortionData;
+
+    if (param->bDisableLookahead && isVbv)
+    {
+        CHECKED_MALLOC_ZERO(analysis->lookahead.intraSatdForVbv, uint32_t, analysis->numCuInHeight);
+        CHECKED_MALLOC_ZERO(analysis->lookahead.satdForVbv, uint32_t, analysis->numCuInHeight);
+        CHECKED_MALLOC_ZERO(analysis->lookahead.intraVbvCost, uint32_t, analysis->numCUsInFrame);
+        CHECKED_MALLOC_ZERO(analysis->lookahead.vbvCost, uint32_t, analysis->numCUsInFrame);
+    }
+
+    //Allocate memory for weightParam pointer
+    if (!(param->bMVType == AVC_INFO))
+        CHECKED_MALLOC_ZERO(analysis->wt, x265_weight_param, numPlanes * numDir);
+
+    if (param->analysisReuseLevel < 2)
+        return;
+
+    //Allocate memory for intraData pointer
+    x265_analysis_intra_data *intraData = analysis->intraData;


More information about the x265-commits mailing list