<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 20, 2018 at 2:22 PM,  <span dir="ltr"><<a href="mailto:aasaipriya@multicorewareinc.com" target="_blank">aasaipriya@multicorewareinc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Aasaipriya Chandran <<a href="mailto:aasaipriya@multicorewareinc.com">aasaipriya@multicorewareinc.<wbr>com</a>><br>
# Date 1532076622 -19800<br>
#      Fri Jul 20 14:20:22 2018 +0530<br>
# Node ID fb1530b0e1b4ebd179b8098015213b<wbr>aeeb37c8d2<br>
# Parent  e2759ae31c3638518d4a6358a884f5<wbr>69efae1298<br>
Create API function for allocating and freeing x265_analysis_data.<br>
1. Merge the two overloaded functions existed for allocAnalysis and moved as API function - x265_alloc_analysis_data<br>
2. Merge the two overloaded functions existed for freeAnalysis and moved as API function - x265_free_analysis_data<br>
3. Bump up the build number as new API functions are added<br>
4. Update the document<br>
<br>
diff -r e2759ae31c36 -r fb1530b0e1b4 doc/reST/api.rst<br>
--- a/doc/reST/api.rst  Thu Jul 19 12:25:26 2018 +0530<br>
+++ b/doc/reST/api.rst  Fri Jul 20 14:20:22 2018 +0530<br>
@@ -223,6 +223,18 @@<br>
      *     returns negative on error, 0 access unit were output.*/<br>
      int x265_set_analysis_data(x265_<wbr>encoder *encoder, x265_analysis_data *analysis_data, int poc, uint32_t cuBytes);<br>
<br>
+**x265_alloc_analysis_data()*<wbr>* may be used to allocate memory for the x265_analysis_data::<br>
+<br>
+    /* x265_alloc_analysis_data:<br>
+     *     Allocate memory for the x265_analysis_data object's internal structures. */<br>
+     void x265_alloc_analysis_data(x265_<wbr>param *param, x265_analysis_data* analysis);<br>
+<br>
+**x265_free_analysis_data()** may be used to free memory for the x265_analysis_data::<br>
+<br>
+    /* x265_free_analysis_data:<br>
+     *    Free the allocated memory for x265_analysis_data object's internal structures. */<br>
+     void x265_free_analysis_data(x265_<wbr>param *param, x265_analysis_data* analysis);<br>
+<br>
 Pictures<br>
 ========<br>
<br>
diff -r e2759ae31c36 -r fb1530b0e1b4 source/CMakeLists.txt<br>
--- a/source/CMakeLists.txt     Thu Jul 19 12:25:26 2018 +0530<br>
+++ b/source/CMakeLists.txt     Fri Jul 20 14:20:22 2018 +0530<br>
@@ -29,7 +29,7 @@<br>
 option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)<br>
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)<br>
 # X265_BUILD must be incremented each time the public API is changed<br>
-set(X265_BUILD 162)<br>
+set(X265_BUILD 163)<br>
 configure_file("${PROJECT_<wbr>SOURCE_DIR}/<a href="http://x265.def.in" rel="noreferrer" target="_blank">x265.def.in</a>"<br>
                "${PROJECT_BINARY_DIR}/x265.<wbr>def")<br>
 configure_file("${PROJECT_<wbr>SOURCE_DIR}/<a href="http://x265_config.h.in" rel="noreferrer" target="_blank">x265_config.h.in</a>"<br>
diff -r e2759ae31c36 -r fb1530b0e1b4 source/encoder/api.cpp<br>
--- a/source/encoder/api.cpp    Thu Jul 19 12:25:26 2018 +0530<br>
+++ b/source/encoder/api.cpp    Fri Jul 20 14:20:22 2018 +0530<br>
@@ -403,6 +403,175 @@<br>
     return -1;<br>
 }<br>
<br>
+void x265_alloc_analysis_data(x265_<wbr>param *param, x265_analysis_data* analysis)<br>
+{<br>
+    X265_CHECK(analysis-><wbr>sliceType, "invalid slice type\n");<br>
+    analysis->interData = analysis->intraData = analysis->distortionData = NULL;<br>
+    bool isVbv = param->rc.vbvMaxBitrate > 0 && param->rc.vbvBufferSize > 0;<br>
+    int numDir = 2; //irrespective of P or B slices set direction as 2<br>
+    uint32_t numPlanes = param->internalCsp == X265_CSP_I400 ? 1 : 3;<br>
+<br>
+    //Allocate memory for distortionData pointer<br>
+    analysisDistortionData *distortionData = (analysisDistortionData*)<wbr>analysis->distortionData;<br>
+    CHECKED_MALLOC_ZERO(<wbr>distortionData, analysisDistortionData, 1);<br>
+    CHECKED_MALLOC_ZERO(<wbr>distortionData->distortion, sse_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+    if (param->rc.bStatRead)<br>
+    {<br>
+        CHECKED_MALLOC_ZERO(<wbr>distortionData->ctuDistortion, sse_t, analysis->numCUsInFrame);<br>
+        CHECKED_MALLOC_ZERO(<wbr>distortionData-><wbr>scaledDistortion, double, analysis->numCUsInFrame);<br>
+        CHECKED_MALLOC_ZERO(<wbr>distortionData->offset, double, analysis->numCUsInFrame);<br>
+        CHECKED_MALLOC_ZERO(<wbr>distortionData->threshold, double, analysis->numCUsInFrame);<br>
+    }<br>
+    analysis->distortionData = distortionData;<br>
+<br>
+    if (param->bDisableLookahead && isVbv)<br>
+    {<br>
+        CHECKED_MALLOC_ZERO(analysis-><wbr>lookahead.intraSatdForVbv, uint32_t, analysis->numCuInHeight);<br>
+        CHECKED_MALLOC_ZERO(analysis-><wbr>lookahead.satdForVbv, uint32_t, analysis->numCuInHeight);<br>
+        CHECKED_MALLOC_ZERO(analysis-><wbr>lookahead.intraVbvCost, uint32_t, analysis->numCUsInFrame);<br>
+        CHECKED_MALLOC_ZERO(analysis-><wbr>lookahead.vbvCost, uint32_t, analysis->numCUsInFrame);<br>
+    }<br>
+<br>
+    //Allocate memory for weightParam pointer<br>
+    if (!(param->bMVType == AVC_INFO))<br>
+        CHECKED_MALLOC_ZERO(analysis-><wbr>wt, WeightParam, numPlanes * numDir);<br>
+<br>
+    if (param->analysisReuseLevel < 2)<br>
+        return;<br>
+<br>
+    //Allocate memory for intraData pointer<br>
+    analysis_intra_data *intraData = (analysis_intra_data*)<wbr>analysis->intraData;<br>
+    CHECKED_MALLOC_ZERO(intraData, analysis_intra_data, 1);<br>
+    CHECKED_MALLOC(intraData-><wbr>depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+    CHECKED_MALLOC(intraData-><wbr>modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+    CHECKED_MALLOC(intraData-><wbr>partSizes, char, analysis->numPartitions * analysis->numCUsInFrame);<br>
+    CHECKED_MALLOC(intraData-><wbr>chromaModes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+    analysis->intraData = intraData;<br>
+<br>
+    //Allocate memory for interData pointer based on ReuseLevels<br>
+    analysis_inter_data *interData = (analysis_inter_data*)<wbr>analysis->interData;<br>
+    CHECKED_MALLOC_ZERO(interData, analysis_inter_data, 1);<br>
+    CHECKED_MALLOC(interData-><wbr>depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+    CHECKED_MALLOC(interData-><wbr>modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+<br>
+    CHECKED_MALLOC_ZERO(interData-<wbr>>mvpIdx[0], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+    CHECKED_MALLOC_ZERO(interData-<wbr>>mvpIdx[1], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+    CHECKED_MALLOC_ZERO(interData-<wbr>>mv[0], MV, analysis->numPartitions * analysis->numCUsInFrame);<br>
+    CHECKED_MALLOC_ZERO(interData-<wbr>>mv[1], MV, analysis->numPartitions * analysis->numCUsInFrame);<br>
+<br>
+    if (param->analysisReuseLevel > 4)<br>
+    {<br>
+        CHECKED_MALLOC(interData-><wbr>partSize, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+        CHECKED_MALLOC_ZERO(interData-<wbr>>mergeFlag, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+    }<br>
+    if (param->analysisReuseLevel >= 7)<br>
+    {<br>
+        CHECKED_MALLOC(interData-><wbr>interDir, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+        CHECKED_MALLOC(interData-><wbr>sadCost, int64_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+        for (int dir = 0; dir < numDir; dir++)<br>
+        {<br>
+            CHECKED_MALLOC(interData-><wbr>refIdx[dir], int8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+            CHECKED_MALLOC_ZERO(analysis-><wbr>modeFlag[dir], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
+        }<br>
+    }<br>
+    else<br>
+    {<br>
+        if (param-><wbr>analysisMultiPassRefine || param-><wbr>analysisMultiPassDistortion){<br>
+            CHECKED_MALLOC_ZERO(interData-<wbr>>ref, int32_t, 2 * analysis->numPartitions * analysis->numCUsInFrame);<br>
+        }<br>
+        else<br>
+            CHECKED_MALLOC_ZERO(interData-<wbr>>ref, int32_t, analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir);<br>
+    }<br>
+    analysis->interData = interData;<br>
+<br>
+    return;<br>
+<br>
+fail:<br>
+    x265_free_analysis_data(param, analysis);<br>
+}<br>
+<br>
+void x265_free_analysis_data(x265_<wbr>param *param, x265_analysis_data* analysis)<br>
+{<br>
+    bool isVbv = param->rc.vbvMaxBitrate > 0 && param->rc.vbvBufferSize > 0;<br>
+<br>
+    //Free memory for Lookahead pointers<br>
+    if (param->bDisableLookahead && isVbv)<br>
+    {<br>
+        X265_FREE(analysis->lookahead.<wbr>satdForVbv);<br>
+        X265_FREE(analysis->lookahead.<wbr>intraSatdForVbv);<br>
+        X265_FREE(analysis->lookahead.<wbr>vbvCost);<br>
+        X265_FREE(analysis->lookahead.<wbr>intraVbvCost);<br>
+    }<br>
+<br>
+    //Free memory for distortionData pointers<br>
+    if (analysis->distortionData)<br>
+    {<br>
+        X265_FREE(((<wbr>analysisDistortionData*)<wbr>analysis->distortionData)-><wbr>distortion);<br>
+        if (param->rc.bStatRead)<br>
+        {<br>
+            X265_FREE(((<wbr>analysisDistortionData*)<wbr>analysis->distortionData)-><wbr>ctuDistortion);<br>
+            X265_FREE(((<wbr>analysisDistortionData*)<wbr>analysis->distortionData)-><wbr>scaledDistortion);<br>
+            X265_FREE(((<wbr>analysisDistortionData*)<wbr>analysis->distortionData)-><wbr>offset);<br>
+            X265_FREE(((<wbr>analysisDistortionData*)<wbr>analysis->distortionData)-><wbr>threshold);<br>
+        }<br>
+        X265_FREE(analysis-><wbr>distortionData);<br>
+    }<br>
+<br>
+    /* Early exit freeing weights alone if level is 1 (when there is no analysis inter/intra) */<br>
+    if (analysis->wt && !(param->bMVType == AVC_INFO))<br>
+        X265_FREE(analysis->wt);<br>
+<br>
+    if (param->analysisReuseLevel < 2)<br>
+        return;<br>
+<br>
+    //Free memory for intraData pointers<br>
+    if (analysis->intraData)<br>
+    {<br>
+        X265_FREE(((analysis_intra_<wbr>data*)analysis->intraData)-><wbr>depth);<br>
+        X265_FREE(((analysis_intra_<wbr>data*)analysis->intraData)-><wbr>modes);<br>
+        X265_FREE(((analysis_intra_<wbr>data*)analysis->intraData)-><wbr>partSizes);<br>
+        X265_FREE(((analysis_intra_<wbr>data*)analysis->intraData)-><wbr>chromaModes);<br>
+        X265_FREE(analysis->intraData)<wbr>;<br>
+        analysis->intraData = NULL;<br>
+    }<br>
+<br>
+    //Free interData pointers<br>
+    if (analysis->interData)<br>
+    {<br>
+        X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>depth);<br>
+        X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>modes);<br>
+        X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mvpIdx[0]);<br>
+        X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mvpIdx[1]);<br>
+        X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mv[0]);<br>
+        X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mv[1]);<br>
+<br>
+        if (param->analysisReuseLevel > 4)<br>
+        {<br>
+            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mergeFlag);<br>
+            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>partSize);<br>
+        }<br>
+        if (param->analysisReuseLevel >= 7)<br>
+        {<br>
+            int numDir = 2;<br>
+            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>interDir);<br>
+            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>sadCost);<br>
+            for (int dir = 0; dir < numDir; dir++)<br>
+            {<br>
+                X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>refIdx[dir]);<br>
+                if (analysis->modeFlag[dir] != NULL)<br>
+                {<br>
+                    X265_FREE(analysis->modeFlag[<wbr>dir]);<br>
+                    analysis->modeFlag[dir] = NULL;<br>
+                }<br>
+            }<br>
+        }<br>
+        else<br>
+            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>ref);<br>
+        X265_FREE(analysis->interData)<wbr>;<br>
+        analysis->interData = NULL;<br>
+    }<br>
+}<br>
+<br>
 void x265_cleanup(void)<br>
 {<br>
     BitCost::destroy();<br>
diff -r e2759ae31c36 -r fb1530b0e1b4 source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp        Thu Jul 19 12:25:26 2018 +0530<br>
+++ b/source/encoder/encoder.cpp        Fri Jul 20 14:20:22 2018 +0530<br>
@@ -641,7 +641,7 @@<br>
         curFrame->m_analysisData = (*analysis_data);<br>
         curFrame->m_analysisData.<wbr>numCUsInFrame = widthInCU * heightInCU;<br>
         curFrame->m_analysisData.<wbr>numPartitions = m_param->num4x4Partitions;<br>
-        allocAnalysis(&curFrame->m_<wbr>analysisData);<br>
+        x265_alloc_analysis_data(m_<wbr>param, &curFrame->m_analysisData);<br>
         if (m_param->maxCUSize == 16)<br>
         {<br>
             if (analysis_data->sliceType == X265_TYPE_IDR || analysis_data->sliceType == X265_TYPE_I)<br>
@@ -901,7 +901,7 @@<br>
     if (m_exportedPic)<br>
     {<br>
         if (!m_param->bUseAnalysisFile && m_param->analysisSave)<br>
-            freeAnalysis(&m_exportedPic-><wbr>m_analysisData);<br>
+            x265_free_analysis_data(m_<wbr>param, &m_exportedPic->m_<wbr>analysisData);<br>
         ATOMIC_DEC(&m_exportedPic->m_<wbr>countRefEncoders);<br>
         m_exportedPic = NULL;<br>
         m_dpb->recycleUnreferenced();<br>
@@ -1209,7 +1209,7 @@<br>
<br>
             /* Free up pic_in->analysisData since it has already been used */<br>
             if ((m_param->analysisLoad && !m_param->analysisSave) || (m_param->bMVType && slice->m_sliceType != I_SLICE))<br>
-                freeAnalysis(&outFrame->m_<wbr>analysisData);<br>
+                x265_free_analysis_data(m_<wbr>param, &outFrame->m_analysisData);<br>
<br>
             if (pic_out)<br>
             {<br>
@@ -1248,6 +1248,7 @@<br>
                     pic_out->analysisData.<wbr>intraData = outFrame->m_analysisData.<wbr>intraData;<br>
                     pic_out->analysisData.<wbr>modeFlag[0] = outFrame->m_analysisData.<wbr>modeFlag[0];<br>
                     pic_out->analysisData.<wbr>modeFlag[1] = outFrame->m_analysisData.<wbr>modeFlag[1];<br>
+                    pic_out->analysisData.<wbr>distortionData = outFrame->m_analysisData.<wbr>distortionData;<br>
                     if (m_param->bDisableLookahead)<br>
                     {<br>
                         int factor = 1;<br>
@@ -1286,7 +1287,7 @@<br>
                     writeAnalysisFile(&pic_out-><wbr>analysisData, *outFrame->m_encData);<br>
                     pic_out->analysisData.<wbr>saveParam = pic_out->analysisData.<wbr>saveParam;<br>
                     if (m_param->bUseAnalysisFile)<br>
-                        freeAnalysis(&pic_out-><wbr>analysisData);<br>
+                        x265_free_analysis_data(m_<wbr>param, &pic_out->analysisData);<br>
                 }<br>
             }<br>
             if (m_param->rc.bStatWrite && (m_param-><wbr>analysisMultiPassRefine || m_param-><wbr>analysisMultiPassDistortion))<br>
@@ -1298,10 +1299,10 @@<br>
                     pic_out->analysisData.<wbr>intraData = outFrame->m_analysisData.<wbr>intraData;<br>
                     pic_out->analysisData.<wbr>distortionData = outFrame->m_analysisData.<wbr>distortionData;<br>
                 }<br>
-                writeAnalysisFile(&outFrame-><wbr>m_analysisData, *outFrame->m_encData, outFrame->m_lowres.sliceType);<br>
+                writeAnalysisFileRefine(&<wbr>outFrame->m_analysisData, *outFrame->m_encData);<br>
             }<br>
             if (m_param-><wbr>analysisMultiPassRefine || m_param-><wbr>analysisMultiPassDistortion)<br>
-                freeAnalysis(&outFrame->m_<wbr>analysisData, outFrame->m_lowres.sliceType);<br>
+                x265_free_analysis_data(m_<wbr>param, &outFrame->m_analysisData);<br>
             if (m_param->internalCsp == X265_CSP_I400)<br>
             {<br>
                 if (slice->m_sliceType == P_SLICE)<br>
@@ -1410,7 +1411,7 @@<br>
                 uint32_t heightInCU = (m_param->sourceHeight + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;<br>
                 frameEnc->m_analysisData.<wbr>numCUsInFrame = widthInCU * heightInCU;<br>
                 frameEnc->m_analysisData.<wbr>numPartitions = m_param->num4x4Partitions;<br>
-                allocAnalysis(&frameEnc->m_<wbr>analysisData, frameEnc->m_lowres.sliceType);<br>
+                x265_alloc_analysis_data(m_<wbr>param, &frameEnc->m_analysisData);<br>
                 frameEnc->m_analysisData.poc = frameEnc->m_poc;<br>
                 if (m_param->rc.bStatRead)<br>
                     readAnalysisFile(&frameEnc->m_<wbr>analysisData, frameEnc->m_poc, frameEnc->m_lowres.sliceType);<br>
@@ -1555,7 +1556,7 @@<br>
                 analysis->numCUsInFrame  = numCUsInFrame;<br>
                 analysis->numCuInHeight = heightInCU;<br>
                 analysis->numPartitions  = m_param->num4x4Partitions;<br>
-                allocAnalysis(analysis);<br>
+                x265_alloc_analysis_data(m_<wbr>param, analysis);<br>
             }<br>
             /* determine references, setup RPS, etc */<br>
             m_dpb->prepareEncode(frameEnc)<wbr>;<br>
@@ -3181,232 +3182,6 @@<br>
<br>
 }<br>
<br>
-void Encoder::allocAnalysis(x265_<wbr>analysis_data* analysis)<br>
-{<br>
-    X265_CHECK(analysis-><wbr>sliceType, "invalid slice type\n");<br>
-    analysis->interData = analysis->intraData = NULL;<br>
-    if (m_param->bDisableLookahead && m_rateControl->m_isVbv)<br>
-    {<br>
-        CHECKED_MALLOC_ZERO(analysis-><wbr>lookahead.intraSatdForVbv, uint32_t, analysis->numCuInHeight);<br>
-        CHECKED_MALLOC_ZERO(analysis-><wbr>lookahead.satdForVbv, uint32_t, analysis->numCuInHeight);<br>
-        CHECKED_MALLOC_ZERO(analysis-><wbr>lookahead.intraVbvCost, uint32_t, analysis->numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(analysis-><wbr>lookahead.vbvCost, uint32_t, analysis->numCUsInFrame);<br>
-    }<br>
-    if (analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I)<br>
-    {<br>
-        if (m_param->analysisReuseLevel < 2)<br>
-            return;<br>
-<br>
-        analysis_intra_data *intraData = (analysis_intra_data*)<wbr>analysis->intraData;<br>
-        CHECKED_MALLOC_ZERO(intraData, analysis_intra_data, 1);<br>
-        CHECKED_MALLOC(intraData-><wbr>depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-        CHECKED_MALLOC(intraData-><wbr>modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-        CHECKED_MALLOC(intraData-><wbr>partSizes, char, analysis->numPartitions * analysis->numCUsInFrame);<br>
-        CHECKED_MALLOC(intraData-><wbr>chromaModes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-        analysis->intraData = intraData;<br>
-    }<br>
-    else<br>
-    {<br>
-        int numDir = analysis->sliceType == X265_TYPE_P ? 1 : 2;<br>
-        uint32_t numPlanes = m_param->internalCsp == X265_CSP_I400 ? 1 : 3;<br>
-        if (!(m_param->bMVType == AVC_INFO))<br>
-            CHECKED_MALLOC_ZERO(analysis-><wbr>wt, WeightParam, numPlanes * numDir);<br>
-        if (m_param->analysisReuseLevel < 2)<br>
-            return;<br>
-<br>
-        analysis_inter_data *interData = (analysis_inter_data*)<wbr>analysis->interData;<br>
-        CHECKED_MALLOC_ZERO(interData, analysis_inter_data, 1);<br>
-        CHECKED_MALLOC(interData-><wbr>depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-        CHECKED_MALLOC(interData-><wbr>modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-        if (m_param->analysisReuseLevel > 4)<br>
-        {<br>
-            CHECKED_MALLOC(interData-><wbr>partSize, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-            CHECKED_MALLOC_ZERO(interData-<wbr>>mergeFlag, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-        }<br>
-        if (m_param->analysisReuseLevel >= 7)<br>
-        {<br>
-            CHECKED_MALLOC(interData-><wbr>interDir, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-            CHECKED_MALLOC(interData-><wbr>sadCost, int64_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-            for (int dir = 0; dir < numDir; dir++)<br>
-            {<br>
-                CHECKED_MALLOC(interData-><wbr>mvpIdx[dir], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-                CHECKED_MALLOC(interData-><wbr>refIdx[dir], int8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-                CHECKED_MALLOC(interData->mv[<wbr>dir], MV, analysis->numPartitions * analysis->numCUsInFrame);<br>
-                CHECKED_MALLOC_ZERO(analysis-><wbr>modeFlag[dir], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-            }<br>
-            /* Allocate intra in inter */<br>
-            if (analysis->sliceType == X265_TYPE_P || m_param->bIntraInBFrames)<br>
-            {<br>
-                analysis_intra_data *intraData = (analysis_intra_data*)<wbr>analysis->intraData;<br>
-                CHECKED_MALLOC_ZERO(intraData, analysis_intra_data, 1);<br>
-                CHECKED_MALLOC(intraData-><wbr>modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-                CHECKED_MALLOC(intraData-><wbr>chromaModes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-                analysis->intraData = intraData;<br>
-            }<br>
-        }<br>
-        else<br>
-            CHECKED_MALLOC_ZERO(interData-<wbr>>ref, int32_t, analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir);<br>
-<br>
-        analysis->interData = interData;<br>
-    }<br>
-    return;<br>
-<br>
-fail:<br>
-    freeAnalysis(analysis);<br>
-    m_aborted = true;<br>
-}<br>
-void Encoder::freeAnalysis(x265_<wbr>analysis_data* analysis)<br>
-{<br>
-    if (m_param->bDisableLookahead && m_rateControl->m_isVbv)<br>
-    {<br>
-        X265_FREE(analysis->lookahead.<wbr>satdForVbv);<br>
-        X265_FREE(analysis->lookahead.<wbr>intraSatdForVbv);<br>
-        X265_FREE(analysis->lookahead.<wbr>vbvCost);<br>
-        X265_FREE(analysis->lookahead.<wbr>intraVbvCost);<br>
-    }<br>
-    /* Early exit freeing weights alone if level is 1 (when there is no analysis inter/intra) */<br>
-    if (analysis->sliceType > X265_TYPE_I && analysis->wt && !(m_param->bMVType == AVC_INFO))<br>
-        X265_FREE(analysis->wt);<br>
-    if (m_param->analysisReuseLevel < 2)<br>
-        return;<br>
-<br>
-    if (analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I)<br>
-    {<br>
-        if (analysis->intraData)<br>
-        {<br>
-            X265_FREE(((analysis_intra_<wbr>data*)analysis->intraData)-><wbr>depth);<br>
-            X265_FREE(((analysis_intra_<wbr>data*)analysis->intraData)-><wbr>modes);<br>
-            X265_FREE(((analysis_intra_<wbr>data*)analysis->intraData)-><wbr>partSizes);<br>
-            X265_FREE(((analysis_intra_<wbr>data*)analysis->intraData)-><wbr>chromaModes);<br>
-            X265_FREE(analysis->intraData)<wbr>;<br>
-            analysis->intraData = NULL;<br>
-        }<br>
-    }<br>
-    else<br>
-    {<br>
-        if (analysis->intraData)<br>
-        {<br>
-            X265_FREE(((analysis_intra_<wbr>data*)analysis->intraData)-><wbr>modes);<br>
-            X265_FREE(((analysis_intra_<wbr>data*)analysis->intraData)-><wbr>chromaModes);<br>
-            X265_FREE(analysis->intraData)<wbr>;<br>
-            analysis->intraData = NULL;<br>
-        }<br>
-        if (analysis->interData)<br>
-        {<br>
-            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>depth);<br>
-            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>modes);<br>
-            if (m_param->analysisReuseLevel > 4)<br>
-            {<br>
-                X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mergeFlag);<br>
-                X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>partSize);<br>
-            }<br>
-            if (m_param->analysisReuseLevel >= 7)<br>
-            {<br>
-                X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>interDir);<br>
-                X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>sadCost);<br>
-                int numDir = analysis->sliceType == X265_TYPE_P ? 1 : 2;<br>
-                for (int dir = 0; dir < numDir; dir++)<br>
-                {<br>
-                    X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mvpIdx[dir]);<br>
-                    X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>refIdx[dir]);<br>
-                    X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mv[dir]);<br>
-                    if (analysis->modeFlag[dir] != NULL)<br>
-                    {<br>
-                        X265_FREE(analysis->modeFlag[<wbr>dir]);<br>
-                        analysis->modeFlag[dir] = NULL;<br>
-                    }<br>
-                }<br>
-            }<br>
-            else<br>
-                X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>ref);<br>
-<br>
-            X265_FREE(analysis->interData)<wbr>;<br>
-            analysis->interData = NULL;<br>
-        }<br>
-    }<br>
-}<br>
-<br>
-void Encoder::allocAnalysis(x265_<wbr>analysis_data* analysis, int sliceType)<br>
-{<br>
-    analysis->interData = analysis->intraData = analysis->distortionData = NULL;<br>
-<br>
-    analysisDistortionData *distortionData = (analysisDistortionData*)<wbr>analysis->distortionData;<br>
-    CHECKED_MALLOC_ZERO(<wbr>distortionData, analysisDistortionData, 1);<br>
-    CHECKED_MALLOC_ZERO(<wbr>distortionData->distortion, sse_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-    if (m_param->rc.bStatRead)<br>
-    {<br>
-        CHECKED_MALLOC_ZERO(<wbr>distortionData->ctuDistortion, sse_t, analysis->numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(<wbr>distortionData-><wbr>scaledDistortion, double, analysis->numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(<wbr>distortionData->offset, double, analysis->numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(<wbr>distortionData->threshold, double, analysis->numCUsInFrame);<br>
-    }<br>
-    analysis->distortionData = distortionData;<br>
-<br>
-    if (IS_X265_TYPE_I(sliceType))<br>
-    {<br>
-        analysis_intra_data *intraData = (analysis_intra_data*)<wbr>analysis->intraData;<br>
-        CHECKED_MALLOC_ZERO(intraData, analysis_intra_data, 1);<br>
-        CHECKED_MALLOC(intraData-><wbr>depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-        analysis->intraData = intraData;<br>
-    }<br>
-    else<br>
-    {<br>
-        analysis_inter_data *interData = (analysis_inter_data*)<wbr>analysis->interData;<br>
-        CHECKED_MALLOC_ZERO(interData, analysis_inter_data, 1);<br>
-        CHECKED_MALLOC_ZERO(interData-<wbr>>depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-        CHECKED_MALLOC(interData-><wbr>modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(interData-<wbr>>mvpIdx[0], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(interData-<wbr>>mvpIdx[1], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(interData-<wbr>>mv[0], MV, analysis->numPartitions * analysis->numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(interData-<wbr>>mv[1], MV, analysis->numPartitions * analysis->numCUsInFrame);<br>
-        CHECKED_MALLOC_ZERO(interData-<wbr>>ref, int32_t, 2 * analysis->numPartitions * analysis->numCUsInFrame);<br>
-        analysis->interData = interData;<br>
-    }<br>
-    return;<br>
-<br>
-fail:<br>
-    freeAnalysis(analysis, sliceType);<br>
-    m_aborted = true;<br>
-}<br>
-<br>
-void Encoder::freeAnalysis(x265_<wbr>analysis_data* analysis, int sliceType)<br>
-{<br>
-    if (analysis->distortionData)<br>
-    {<br>
-        X265_FREE(((<wbr>analysisDistortionData*)<wbr>analysis->distortionData)-><wbr>distortion);<br>
-        if (m_param->rc.bStatRead)<br>
-        {<br>
-            X265_FREE(((<wbr>analysisDistortionData*)<wbr>analysis->distortionData)-><wbr>ctuDistortion);<br>
-            X265_FREE(((<wbr>analysisDistortionData*)<wbr>analysis->distortionData)-><wbr>scaledDistortion);<br>
-            X265_FREE(((<wbr>analysisDistortionData*)<wbr>analysis->distortionData)-><wbr>offset);<br>
-            X265_FREE(((<wbr>analysisDistortionData*)<wbr>analysis->distortionData)-><wbr>threshold);<br>
-        }<br>
-        X265_FREE(analysis-><wbr>distortionData);<br>
-    }<br>
-    if (IS_X265_TYPE_I(sliceType))<br>
-    {<br>
-        if (analysis->intraData)<br>
-        {<br>
-            X265_FREE(((analysis_intra_<wbr>data*)analysis->intraData)-><wbr>depth);<br>
-            X265_FREE(analysis->intraData)<wbr>;<br>
-        }<br>
-    }<br>
-    else<br>
-    {<br>
-        if (analysis->interData)<br>
-        {<br>
-            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mvpIdx[0]);<br>
-            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mvpIdx[1]);<br>
-            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mv[0]);<br>
-            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>mv[1]);<br>
-            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>ref);<br>
-            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>depth);<br>
-            X265_FREE(((analysis_inter_<wbr>data*)analysis->interData)-><wbr>modes);<br>
-            X265_FREE(analysis->interData)<wbr>;<br>
-        }<br>
-    }<br>
-}<br>
-<br>
 void Encoder::readAnalysisFile(<wbr>x265_analysis_data* analysis, int curPoc, const x265_picture* picIn, int paramBytes)<br>
 {<br>
 #define X265_FREAD(val, size, readSize, fileOffset, src)\<br>
@@ -3417,7 +3192,7 @@<br>
         else if (fread(val, size, readSize, fileOffset) != readSize)\<br>
     {\<br>
         x265_log(NULL, X265_LOG_ERROR, "Error reading analysis data\n");\<br>
-        freeAnalysis(analysis);\<br>
+        x265_free_analysis_data(m_<wbr>param, analysis);\<br>
         m_aborted = true;\<br>
         return;\<br>
     }\<br>
@@ -3452,7 +3227,7 @@<br>
         if (poc != curPoc || feof(m_analysisFileIn))<br>
         {<br>
             x265_log(NULL, X265_LOG_WARNING, "Error reading analysis data: Cannot find POC %d\n", curPoc);<br>
-            freeAnalysis(analysis);<br>
+            x265_free_analysis_data(m_<wbr>param, analysis);<br>
             return;<br>
         }<br>
     }<br>
@@ -3476,7 +3251,7 @@<br>
     if (m_param->scaleFactor)<br>
         analysis->numPartitions *= factor;<br>
     /* Memory is allocated for inter and intra analysis data based on the slicetype */<br>
-    allocAnalysis(analysis);<br>
+    x265_alloc_analysis_data(m_<wbr>param, analysis);<br>
     if (m_param->bDisableLookahead && m_rateControl->m_isVbv)<br>
     {<br>
         size_t vbvCount = m_param->lookaheadDepth + m_param->bframes + 2;<br>
@@ -3695,7 +3470,7 @@<br>
     else if (fread(val, size, readSize, fileOffset) != readSize)\<br>
     {\<br>
         x265_log(NULL, X265_LOG_ERROR, "Error reading analysis data\n");\<br>
-        freeAnalysis(analysis);\<br>
+        x265_free_analysis_data(m_<wbr>param, analysis);\<br>
         m_aborted = true;\<br>
         return;\<br>
     }\<br>
@@ -3731,7 +3506,7 @@<br>
         if (poc != curPoc || feof(m_analysisFileIn))<br>
         {<br>
             x265_log(NULL, X265_LOG_WARNING, "Error reading analysis data: Cannot find POC %d\n", curPoc);<br>
-            freeAnalysis(analysis);<br>
+            x265_free_analysis_data(m_<wbr>param, analysis);<br>
             return;<br>
         }<br>
     }<br>
@@ -3761,7 +3536,7 @@<br>
     analysis->numCuInHeight = cuLoc.heightInCU;<br>
<br>
     /* Memory is allocated for inter and intra analysis data based on the slicetype */<br>
-    allocAnalysis(analysis);<br>
+    x265_alloc_analysis_data(m_<wbr>param, analysis);<br>
<br>
     analysis->numPartitions = numPartitions * factor;<br>
     analysis->numCUsInFrame = numCUsInFrame;<br>
@@ -4275,7 +4050,7 @@<br>
     if (fread(val, size, readSize, fileOffset) != readSize)\<br>
     {\<br>
     x265_log(NULL, X265_LOG_ERROR, "Error reading analysis 2 pass data\n"); \<br>
-    freeAnalysis(analysis, sliceType); \<br>
+    x265_alloc_analysis_data(m_<wbr>param, analysis); \<br>
     m_aborted = true; \<br>
     return; \<br>
 }\<br>
@@ -4289,7 +4064,7 @@<br>
     if (poc != curPoc || feof(m_analysisFileIn))<br>
     {<br>
         x265_log(NULL, X265_LOG_WARNING, "Error reading analysis 2 pass data: Cannot find POC %d\n", curPoc);<br>
-        freeAnalysis(analysis, sliceType);<br>
+        x265_free_analysis_data(m_<wbr>param, analysis);<br>
         return;<br>
     }<br>
     /* Now arrived at the right frame, read the record */<br>
@@ -4405,7 +4180,7 @@<br>
     if (fwrite(val, size, writeSize, fileOffset) < writeSize)\<br>
     {\<br>
         x265_log(NULL, X265_LOG_ERROR, "Error writing analysis data\n");\<br>
-        freeAnalysis(analysis);\<br>
+        x265_free_analysis_data(m_<wbr>param, analysis);\<br>
         m_aborted = true;\<br>
         return;\<br>
     }\<br>
@@ -4598,13 +4373,13 @@<br>
 #undef X265_FWRITE<br>
 }<br>
<br>
-void Encoder::writeAnalysisFile(<wbr>x265_analysis_data* analysis, FrameData &curEncData, int slicetype)<br>
+void Encoder::<wbr>writeAnalysisFileRefine(x265_<wbr>analysis_data* analysis, FrameData &curEncData)<br>
 {<br>
 #define X265_FWRITE(val, size, writeSize, fileOffset)\<br>
     if (fwrite(val, size, writeSize, fileOffset) < writeSize)\<br>
     {\<br>
     x265_log(NULL, X265_LOG_ERROR, "Error writing analysis 2 pass data\n"); \<br>
-    freeAnalysis(analysis, slicetype); \<br>
+    x265_free_analysis_data(m_<wbr>param, analysis); \<br>
     m_aborted = true; \<br>
     return; \<br>
 }\<br>
diff -r e2759ae31c36 -r fb1530b0e1b4 source/encoder/encoder.h<br>
--- a/source/encoder/encoder.h  Thu Jul 19 12:25:26 2018 +0530<br>
+++ b/source/encoder/encoder.h  Fri Jul 20 14:20:22 2018 +0530<br>
@@ -275,14 +275,6 @@<br>
<br>
     void updateVbvPlan(RateControl* rc);<br>
<br>
-    void allocAnalysis(x265_analysis_<wbr>data* analysis);<br>
-<br>
-    void allocAnalysis(x265_analysis_<wbr>data* analysis, int sliceType);<br>
-<br>
-    void freeAnalysis(x265_analysis_<wbr>data* analysis);<br>
-<br>
-    void freeAnalysis(x265_analysis_<wbr>data* analysis, int sliceType);<br>
-<br>
     void readAnalysisFile(x265_<wbr>analysis_data* analysis, int poc, int sliceType);<br>
<br>
     void readAnalysisFile(x265_<wbr>analysis_data* analysis, int poc, const x265_picture* picIn, int paramBytes);<br>
@@ -295,7 +287,7 @@<br>
<br>
     void writeAnalysisFile(x265_<wbr>analysis_data* analysis, FrameData &curEncData);<br>
<br>
-    void writeAnalysisFile(x265_<wbr>analysis_data* analysis, FrameData &curEncData, int slicetype);<br>
+    void writeAnalysisFileRefine(x265_<wbr>analysis_data* analysis, FrameData &curEncData);<br>
<br>
     void finishFrameStats(Frame* pic, FrameEncoder *curEncoder, x265_frame_stats* frameStats, int inPoc);<br>
<br>
diff -r e2759ae31c36 -r fb1530b0e1b4 source/x265.h<br>
--- a/source/x265.h     Thu Jul 19 12:25:26 2018 +0530<br>
+++ b/source/x265.h     Fri Jul 20 14:20:22 2018 +0530<br>
@@ -1757,6 +1757,14 @@<br>
  *      A static string describing the compiler and target architecture */<br>
 X265_API extern const char *x265_build_info_str;<br>
<br>
+/* x265_alloc_analysis_data:<br>
+*     Allocate memory for the x265_analysis_data object's internal structures. */<br>
+void x265_alloc_analysis_data(x265_<wbr>param *param, x265_analysis_data* analysis);<br>
+<br>
+/*<br>
+*    Free the allocated memory for x265_analysis_data object's internal structures. */<br>
+void x265_free_analysis_data(x265_<wbr>param *param, x265_analysis_data* analysis);<br>
+<br>
 /* Force a link error in the case of linking against an incompatible API version.<br>
  * Glue #defines exist to force correct macro expansion; the final output of the macro<br>
  * is x265_encoder_open_##X265_BUILD (for purposes of dlopen). */<br>
<br>______________________________<wbr>_________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/<wbr>listinfo/x265-devel</a><br>
<br></blockquote></div><br></div><div class="gmail_extra">Thank you. Pushed to default.</div></div>