[x265] [PATCH] encoder: allocate memory for inter and intra analysis data based on slicetype

gopu at multicorewareinc.com gopu at multicorewareinc.com
Tue Dec 23 07:48:16 CET 2014


# HG changeset patch
# User Gopu Govindaswamy <gopu at multicorewareinc.com>
# Date 1419317228 -19800
#      Tue Dec 23 12:17:08 2014 +0530
# Node ID 09cb790f2242df75ba1f3a1e0415c4f34d0ec729
# Parent  c4ec3f22846beb3eedcb187e86be17bd7636aafa
encoder: allocate memory for inter and intra analysis data based on slicetype

diff -r c4ec3f22846b -r 09cb790f2242 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Tue Dec 23 11:43:32 2014 +0530
+++ b/source/encoder/encoder.cpp	Tue Dec 23 12:17:08 2014 +0530
@@ -462,7 +462,6 @@
         if (m_param->analysisMode == X265_ANALYSIS_LOAD)
         {
             x265_picture* inputPic = const_cast<x265_picture*>(pic_in);
-            allocAnalysis(&inputPic->analysisData);
             readAnalysisFile(&inputPic->analysisData, inFrame->m_poc);
             inFrame->m_analysisData.poc = inFrame->m_poc;
             inFrame->m_analysisData.sliceType = inputPic->analysisData.sliceType;
@@ -624,7 +623,7 @@
         {
             x265_analysis_data* analysis = &frameEnc->m_analysisData;
             analysis->poc = frameEnc->m_poc;
-            analysis->sliceType = frameEnc->m_encData->m_slice->m_poc;
+            analysis->sliceType = frameEnc->m_lowres.sliceType;
             uint32_t widthInCU       = (m_param->sourceWidth  + g_maxCUSize - 1) >> g_maxLog2CUSize;
             uint32_t heightInCU      = (m_param->sourceHeight + g_maxCUSize - 1) >> g_maxLog2CUSize;
 
@@ -1558,15 +1557,21 @@
 
 void Encoder::allocAnalysis(x265_analysis_data* analysis)
 {
-    analysis_intra_data *intraData = (analysis_intra_data*)analysis->intraData;
-    analysis_inter_data *interData = (analysis_inter_data*)analysis->interData;
-    CHECKED_MALLOC_ZERO(intraData, analysis_intra_data, 1);
-    CHECKED_MALLOC(intraData->depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
-    CHECKED_MALLOC(intraData->modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
-    CHECKED_MALLOC(intraData->partSizes, char, analysis->numPartitions * analysis->numCUsInFrame);
-    CHECKED_MALLOC(interData, analysis_inter_data, analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * 2);
-    analysis->intraData = intraData;
-    analysis->interData = interData;
+    if (analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I)
+    {
+        analysis_intra_data *intraData = (analysis_intra_data*)analysis->intraData;
+        CHECKED_MALLOC_ZERO(intraData, analysis_intra_data, 1);
+        CHECKED_MALLOC(intraData->depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
+        CHECKED_MALLOC(intraData->modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
+        CHECKED_MALLOC(intraData->partSizes, char, analysis->numPartitions * analysis->numCUsInFrame);
+        analysis->intraData = intraData;
+    }
+    else
+    {
+        analysis_inter_data *interData = (analysis_inter_data*)analysis->interData;
+        CHECKED_MALLOC(interData, analysis_inter_data, analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * 2);
+        analysis->interData = interData;
+    }
     return;
 
 fail:
@@ -1576,11 +1581,15 @@
 
 void Encoder::freeAnalysis(x265_analysis_data* analysis)
 {
-    X265_FREE(((analysis_intra_data*)analysis->intraData)->depth);
-    X265_FREE(((analysis_intra_data*)analysis->intraData)->modes);
-    X265_FREE(((analysis_intra_data*)analysis->intraData)->partSizes);
-    X265_FREE(analysis->interData);
-    X265_FREE(analysis->intraData);
+    if (analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I)
+    {
+        X265_FREE(((analysis_intra_data*)analysis->intraData)->depth);
+        X265_FREE(((analysis_intra_data*)analysis->intraData)->modes);
+        X265_FREE(((analysis_intra_data*)analysis->intraData)->partSizes);
+        X265_FREE(analysis->intraData);
+    }
+    else
+        X265_FREE(analysis->interData);
 }
 
 void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc)
@@ -1628,6 +1637,9 @@
     X265_FREAD(&analysis->numCUsInFrame, sizeof(int), 1, m_analysisFile);
     X265_FREAD(&analysis->numPartitions, sizeof(int), 1, m_analysisFile);
 
+    /* Once read the Slicetype allocate the memory for inter and intra analysis data based on the Slicetype */
+    allocAnalysis(analysis);
+
     if (analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I)
     {
         X265_FREAD(((analysis_intra_data *)analysis->intraData)->depth, sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions, m_analysisFile);


More information about the x265-devel mailing list