changeset 12612:ba9cb149de98

analysis-save/load: Enforce resolution and maxCUSize constraints in non-dyadic analysis load only if analysis-load-reuse-level > 1. This patch removes resolution and maxCUSize constraints in analysis-load-reuse-level 1 as it re-uses only frame level info. It also fixes the encoder crashes that were present earlier due to 1) Unwanted analysis load validation failures in re-use level 10 2) Incorrect memory allocation for multi-pass-opt-analysis/distortion
author Aruna Matheswaran <aruna@multicorewareinc.com>
date Tue, 21 Jan 2020 23:35:37 +0530
parents acc5d16999e2
children 0aa6c346df23
files source/encoder/api.cpp source/encoder/encoder.cpp
diffstat 2 files changed, 22 insertions(+-), 21 deletions(-) [+]
line wrap: on
line diff
--- a/source/encoder/api.cpp	Mon Jan 20 18:07:59 2020 +0530
+++ b/source/encoder/api.cpp	Tue Jan 21 23:35:37 2020 +0530
@@ -812,13 +812,14 @@ void x265_alloc_analysis_data(x265_param
     if (!isMultiPassOpt && !(param->bAnalysisType == AVC_INFO))
         CHECKED_MALLOC_ZERO(analysis->wt, x265_weight_param, numPlanes * numDir);
 
-    if (maxReuseLevel < 2)
-        return;
+    //Allocate memory for intraData pointer
+    if ((maxReuseLevel > 1) || isMultiPassOpt)
+    {
+        CHECKED_MALLOC_ZERO(intraData, x265_analysis_intra_data, 1);
+        CHECKED_MALLOC(intraData->depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
+    }
 
-    //Allocate memory for intraData pointer
-    CHECKED_MALLOC_ZERO(intraData, x265_analysis_intra_data, 1);
-    CHECKED_MALLOC(intraData->depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
-    if (!isMultiPassOpt)
+    if (maxReuseLevel > 1)
     {
         CHECKED_MALLOC_ZERO(intraData->modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
         CHECKED_MALLOC_ZERO(intraData->partSizes, char, analysis->numPartitions * analysis->numCUsInFrame);
@@ -828,17 +829,20 @@ void x265_alloc_analysis_data(x265_param
     }
     analysis->intraData = intraData;
 
-    //Allocate memory for interData pointer based on ReuseLevels
-    CHECKED_MALLOC_ZERO(interData, x265_analysis_inter_data, 1);
-    CHECKED_MALLOC(interData->depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
-    CHECKED_MALLOC_ZERO(interData->modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
+    if ((maxReuseLevel > 1) || isMultiPassOpt)
+    {
+        //Allocate memory for interData pointer based on ReuseLevels
+        CHECKED_MALLOC_ZERO(interData, x265_analysis_inter_data, 1);
+        CHECKED_MALLOC(interData->depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
+        CHECKED_MALLOC_ZERO(interData->modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
 
-    if (param->rc.cuTree && !isMultiPassOpt)
-        CHECKED_MALLOC_ZERO(interData->cuQPOff, int8_t, analysis->numPartitions * analysis->numCUsInFrame);
-    CHECKED_MALLOC_ZERO(interData->mvpIdx[0], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
-    CHECKED_MALLOC_ZERO(interData->mvpIdx[1], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
-    CHECKED_MALLOC_ZERO(interData->mv[0], x265_analysis_MV, analysis->numPartitions * analysis->numCUsInFrame);
-    CHECKED_MALLOC_ZERO(interData->mv[1], x265_analysis_MV, analysis->numPartitions * analysis->numCUsInFrame);
+        if (param->rc.cuTree && !isMultiPassOpt)
+            CHECKED_MALLOC_ZERO(interData->cuQPOff, int8_t, analysis->numPartitions * analysis->numCUsInFrame);
+        CHECKED_MALLOC_ZERO(interData->mvpIdx[0], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
+        CHECKED_MALLOC_ZERO(interData->mvpIdx[1], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);
+        CHECKED_MALLOC_ZERO(interData->mv[0], x265_analysis_MV, analysis->numPartitions * analysis->numCUsInFrame);
+        CHECKED_MALLOC_ZERO(interData->mv[1], x265_analysis_MV, analysis->numPartitions * analysis->numCUsInFrame);
+    }
 
     if (maxReuseLevel > 4)
     {
@@ -905,9 +909,6 @@ void x265_free_analysis_data(x265_param 
     if (!isMultiPassOpt && analysis->wt && !(param->bAnalysisType == AVC_INFO))
         X265_FREE(analysis->wt);
 
-    if (maxReuseLevel < 2)
-        return;
-
     //Free memory for intraData pointers
     if (analysis->intraData)
     {
--- a/source/encoder/encoder.cpp	Mon Jan 20 18:07:59 2020 +0530
+++ b/source/encoder/encoder.cpp	Tue Jan 21 23:35:37 2020 +0530
@@ -4990,8 +4990,8 @@ int Encoder::validateAnalysisData(x265_a
         X265_FREAD(&readValue, sizeof(int), 1, m_analysisFileIn, &(saveParam->maxCUSize));
 
         bool isScaledRes = (2 * sourceHeight == curSourceHeight) && (2 * sourceWidth == curSourceWidth);
-        if (!isScaledRes && (sourceHeight != curSourceHeight || sourceWidth != curSourceWidth 
-                            || readValue != (int)m_param->maxCUSize || m_param->scaleFactor))
+        if (!isScaledRes && (m_param->analysisLoadReuseLevel > 1) && (sourceHeight != curSourceHeight
+            || sourceWidth != curSourceWidth || readValue != (int)m_param->maxCUSize || m_param->scaleFactor))
             error = true;
         else if (isScaledRes && !m_param->scaleFactor)
             error = true;