[x265] [PATCH] analysis: simplify inter analysis structure to share more inter analysis data

gopu at multicorewareinc.com gopu at multicorewareinc.com
Wed Dec 24 06:05:09 CET 2014


# HG changeset patch
# User Gopu Govindaswamy <gopu at multicorewareinc.com>
# Date 1419397499 -19800
#      Wed Dec 24 10:34:59 2014 +0530
# Node ID f75dc9609ebc8a6ca32921b352a55831e7dd199e
# Parent  5f9f7194267b76f733e9ffb0f9e8b474dfe89a71
analysis: simplify inter analysis structure to share more inter analysis data

diff -r 5f9f7194267b -r f75dc9609ebc source/common/common.h
--- a/source/common/common.h	Tue Dec 23 17:40:53 2014 +0900
+++ b/source/common/common.h	Wed Dec 24 10:34:59 2014 +0530
@@ -362,7 +362,7 @@
 /* Stores inter (motion estimation) analysis data for a single frame */
 struct analysis_inter_data
 {
-    int      ref;
+    int32_t*    ref;
 };
 
 /* Stores intra analysis data for a single frame. This struct needs better packing */
diff -r 5f9f7194267b -r f75dc9609ebc source/encoder/analysis.cpp
--- a/source/encoder/analysis.cpp	Tue Dec 23 17:40:53 2014 +0900
+++ b/source/encoder/analysis.cpp	Wed Dec 24 10:34:59 2014 +0530
@@ -133,9 +133,14 @@
     uint32_t numPartition = ctu.m_numPartitions;
     if (m_param->analysisMode)
     {
-        m_reuseIntraDataCTU = (analysis_intra_data *)m_frame->m_analysisData.intraData;
-        int numPredDir = m_slice->isInterP() ? 1 : 2;
-        m_reuseInterDataCTU = (analysis_inter_data *)m_frame->m_analysisData.interData + ctu.m_cuAddr * X265_MAX_PRED_MODE_PER_CTU * numPredDir;
+        if (m_slice->m_sliceType == I_SLICE)
+            m_reuseIntraDataCTU = (analysis_intra_data *)m_frame->m_analysisData.intraData;
+        else
+        {
+            int numPredDir = m_slice->isInterP() ? 1 : 2;
+            m_reuseInterDataCTU = (analysis_inter_data *)m_frame->m_analysisData.interData;
+            reuseRef = &m_reuseInterDataCTU->ref[ctu.m_cuAddr * X265_MAX_PRED_MODE_PER_CTU * numPredDir];
+        }
     }
 
     if (m_slice->m_sliceType == I_SLICE)
@@ -1437,8 +1442,8 @@
             MotionData* bestME = interMode.bestME[part];
             for (int32_t i = 0; i < numPredDir; i++)
             {
-                bestME[i].ref = m_reuseInterDataCTU->ref;
-                m_reuseInterDataCTU++;
+                bestME[i].ref = *reuseRef;
+                reuseRef++;
             }
         }
     }
@@ -1465,8 +1470,8 @@
                 MotionData* bestME = interMode.bestME[puIdx];
                 for (int32_t i = 0; i < numPredDir; i++)
                 {
-                    m_reuseInterDataCTU->ref = bestME[i].ref;
-                    m_reuseInterDataCTU++;
+                    *reuseRef = bestME[i].ref;
+                    reuseRef++;
                 }
             }
         }
@@ -1492,8 +1497,8 @@
             MotionData* bestME = interMode.bestME[puIdx];
             for (int32_t i = 0; i < numPredDir; i++)
             {
-                bestME[i].ref = m_reuseInterDataCTU->ref;
-                m_reuseInterDataCTU++;
+                bestME[i].ref = *reuseRef;
+                reuseRef++;
             }
         }
     }
@@ -1509,8 +1514,8 @@
                 MotionData* bestME = interMode.bestME[puIdx];
                 for (int32_t i = 0; i < numPredDir; i++)
                 {
-                    m_reuseInterDataCTU->ref = bestME[i].ref;
-                    m_reuseInterDataCTU++;
+                    *reuseRef = bestME[i].ref;
+                    reuseRef++;
                 }
             }
         }
diff -r 5f9f7194267b -r f75dc9609ebc source/encoder/analysis.h
--- a/source/encoder/analysis.h	Tue Dec 23 17:40:53 2014 +0900
+++ b/source/encoder/analysis.h	Wed Dec 24 10:34:59 2014 +0530
@@ -77,6 +77,7 @@
     /* Analysis data for load/save modes, keeps getting incremented as CTU analysis proceeds and data is consumed or read */
     analysis_intra_data* m_reuseIntraDataCTU;
     analysis_inter_data* m_reuseInterDataCTU;
+    int32_t* reuseRef;
     Analysis();
     bool create(ThreadLocalData* tld);
     void destroy();
diff -r 5f9f7194267b -r f75dc9609ebc source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Tue Dec 23 17:40:53 2014 +0900
+++ b/source/encoder/encoder.cpp	Wed Dec 24 10:34:59 2014 +0530
@@ -1570,7 +1570,8 @@
     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);
+        CHECKED_MALLOC_ZERO(interData, analysis_inter_data, 1);
+        CHECKED_MALLOC(interData->ref, int32_t, analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * 2);
         analysis->interData = interData;
     }
     return;
@@ -1590,7 +1591,10 @@
         X265_FREE(analysis->intraData);
     }
     else
+    {
+        X265_FREE(((analysis_inter_data*)analysis->interData)->ref);
         X265_FREE(analysis->interData);
+    }
 }
 
 void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc)
@@ -1651,13 +1655,13 @@
     }
     else if (analysis->sliceType == X265_TYPE_P)
     {
-        X265_FREAD(analysis->interData, sizeof(analysis_inter_data), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU, m_analysisFile);
+        X265_FREAD(((analysis_inter_data *)analysis->interData)->ref, sizeof(int32_t), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU, m_analysisFile);
         consumedBytes += frameRecordSize;
         totalConsumedBytes = consumedBytes;
     }
     else
     {
-        X265_FREAD(analysis->interData, sizeof(analysis_inter_data), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * 2, m_analysisFile);
+        X265_FREAD(((analysis_inter_data *)analysis->interData)->ref, sizeof(int32_t), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * 2, m_analysisFile);
         consumedBytes += frameRecordSize;
     }
 #undef X265_FREAD
@@ -1681,9 +1685,9 @@
     if (analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I)
         analysis->frameRecordSize += sizeof(uint8_t) * analysis->numCUsInFrame * analysis->numPartitions * 3;
     else if (analysis->sliceType == X265_TYPE_P)
-        analysis->frameRecordSize += sizeof(analysis_inter_data) * analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU;
+        analysis->frameRecordSize += sizeof(int32_t) * analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU;
     else
-        analysis->frameRecordSize += sizeof(analysis_inter_data) * analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * 2;
+        analysis->frameRecordSize += sizeof(int32_t) * analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * 2;
 
     X265_FWRITE(&analysis->frameRecordSize, sizeof(uint32_t), 1, m_analysisFile);
     X265_FWRITE(&analysis->poc, sizeof(int), 1, m_analysisFile);
@@ -1699,11 +1703,11 @@
     }
     else if (analysis->sliceType == X265_TYPE_P)
     {
-        X265_FWRITE(analysis->interData, sizeof(analysis_inter_data), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU, m_analysisFile);
+        X265_FWRITE(((analysis_inter_data *)analysis->interData)->ref, sizeof(int32_t), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU, m_analysisFile);
     }
     else
     {
-        X265_FWRITE(analysis->interData, sizeof(analysis_inter_data), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * 2, m_analysisFile);
+        X265_FWRITE(((analysis_inter_data *)analysis->interData)->ref, sizeof(int32_t), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * 2, m_analysisFile);
     }
 #undef X265_FWRITE
 }


More information about the x265-devel mailing list