[x265] [PATCH] Add param option for disabling lookahead

Divya Manivannan divya at multicorewareinc.com
Mon Sep 11 16:39:25 CEST 2017


# HG changeset patch
# User Divya Manivannan <divya at multicorewareinc.com>
# Date 1505108539 -19800
#      Mon Sep 11 11:12:19 2017 +0530
# Node ID f8ae7afc1f61ed0db3b2f23f5d581706fe6ed677
# Parent  bac53338585c00d943aa995db5ced8744a9d20e9
Add param option for disabling lookahead

Fixed crash in analysis load mode also in this patch.

diff -r bac53338585c -r f8ae7afc1f61 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Fri Sep 08 13:56:27 2017 +0530
+++ b/source/CMakeLists.txt	Mon Sep 11 11:12:19 2017 +0530
@@ -29,7 +29,7 @@
 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 135)
+set(X265_BUILD 136)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r bac53338585c -r f8ae7afc1f61 source/common/param.cpp
--- a/source/common/param.cpp	Fri Sep 08 13:56:27 2017 +0530
+++ b/source/common/param.cpp	Mon Sep 11 11:12:19 2017 +0530
@@ -287,6 +287,7 @@
     param->bUseAnalysisFile = 1;
     param->csvfpt = NULL;
     param->forceFlush = 0;
+    param->bDisableLookahead = 0;
 }
 
 int x265_param_default_preset(x265_param* param, const char* preset, const char* tune)
diff -r bac53338585c -r f8ae7afc1f61 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Fri Sep 08 13:56:27 2017 +0530
+++ b/source/encoder/encoder.cpp	Mon Sep 11 11:12:19 2017 +0530
@@ -794,7 +794,7 @@
             sliceType = inFrame->m_analysisData.sliceType;
             inFrame->m_lowres.bScenecut = !!inFrame->m_analysisData.bScenecut;
             inFrame->m_lowres.satdCost = inFrame->m_analysisData.satdCost;
-            if (!m_param->bUseAnalysisFile && m_param->scaleFactor)
+            if (m_param->bDisableLookahead)
             {
                 inFrame->m_lowres.sliceType = sliceType;
                 inFrame->m_lowres.bKeyframe = !!inFrame->m_analysisData.lookahead.keyframe;
@@ -901,33 +901,36 @@
                     pic_out->analysisData.bScenecut = outFrame->m_lowres.bScenecut;
                     pic_out->analysisData.satdCost  = outFrame->m_lowres.satdCost;
                     pic_out->analysisData.numCUsInFrame = outFrame->m_analysisData.numCUsInFrame;
-                    pic_out->analysisData.numCuInHeight = outFrame->m_analysisData.numCuInHeight;
                     pic_out->analysisData.numPartitions = outFrame->m_analysisData.numPartitions;
                     pic_out->analysisData.wt = outFrame->m_analysisData.wt;
                     pic_out->analysisData.interData = outFrame->m_analysisData.interData;
                     pic_out->analysisData.intraData = outFrame->m_analysisData.intraData;
-                    if (!m_param->bUseAnalysisFile && m_param->scaleFactor)
+                    if (m_param->bDisableLookahead)
                     {
-                        pic_out->analysisData.satdCost *= m_param->scaleFactor * 2;
+                        int factor = 1;
+                        if (m_param->scaleFactor)
+                            factor = m_param->scaleFactor * 2;
+                        pic_out->analysisData.numCuInHeight = outFrame->m_analysisData.numCuInHeight;
+                        pic_out->analysisData.satdCost *= factor;
                         pic_out->analysisData.lookahead.keyframe = outFrame->m_lowres.bKeyframe;
                         pic_out->analysisData.lookahead.lastMiniGopBFrame = outFrame->m_lowres.bLastMiniGopBFrame;
                         int vbvCount = m_param->lookaheadDepth + m_param->bframes + 2;
                         for (int index = 0; index < vbvCount; index++)
                         {
-                            pic_out->analysisData.lookahead.plannedSatd[index] = outFrame->m_lowres.plannedSatd[index] * m_param->scaleFactor * 2;
+                            pic_out->analysisData.lookahead.plannedSatd[index] = outFrame->m_lowres.plannedSatd[index] * factor;
                             pic_out->analysisData.lookahead.plannedType[index] = outFrame->m_lowres.plannedType[index];
                         }
                         for (uint32_t index = 0; index < pic_out->analysisData.numCuInHeight; index++)
                         {
-                            outFrame->m_analysisData.lookahead.intraSatdForVbv[index] = outFrame->m_encData->m_rowStat[index].intraSatdForVbv * m_param->scaleFactor * 2;
-                            outFrame->m_analysisData.lookahead.satdForVbv[index] = outFrame->m_encData->m_rowStat[index].satdForVbv * m_param->scaleFactor * 2;
+                            outFrame->m_analysisData.lookahead.intraSatdForVbv[index] = outFrame->m_encData->m_rowStat[index].intraSatdForVbv * factor;
+                            outFrame->m_analysisData.lookahead.satdForVbv[index] = outFrame->m_encData->m_rowStat[index].satdForVbv * factor;
                         }
                         pic_out->analysisData.lookahead.intraSatdForVbv = outFrame->m_analysisData.lookahead.intraSatdForVbv;
                         pic_out->analysisData.lookahead.satdForVbv = outFrame->m_analysisData.lookahead.satdForVbv;
                         for (uint32_t index = 0; index < pic_out->analysisData.numCUsInFrame; index++)
                         {
-                            outFrame->m_analysisData.lookahead.intraVbvCost[index] = outFrame->m_encData->m_cuStat[index].intraVbvCost * m_param->scaleFactor * 2;
-                            outFrame->m_analysisData.lookahead.vbvCost[index] = outFrame->m_encData->m_cuStat[index].vbvCost * m_param->scaleFactor * 2;
+                            outFrame->m_analysisData.lookahead.intraVbvCost[index] = outFrame->m_encData->m_cuStat[index].intraVbvCost * factor;
+                            outFrame->m_analysisData.lookahead.vbvCost[index] = outFrame->m_encData->m_cuStat[index].vbvCost * factor;
                         }
                         pic_out->analysisData.lookahead.intraVbvCost = outFrame->m_analysisData.lookahead.intraVbvCost;
                         pic_out->analysisData.lookahead.vbvCost = outFrame->m_analysisData.lookahead.vbvCost;
@@ -1094,7 +1097,7 @@
                 slice->m_maxNumMergeCand = m_param->maxNumMergeCand;
                 slice->m_endCUAddr = slice->realEndAddress(m_sps.numCUsInFrame * m_param->num4x4Partitions);
             }
-            if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD && !m_param->bUseAnalysisFile && m_param->scaleFactor)
+            if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD && m_param->bDisableLookahead)
             {
                 for (uint32_t index = 0; index < frameEnc->m_analysisData.numCuInHeight; index++)
                 {
@@ -2758,7 +2761,7 @@
 {
     X265_CHECK(analysis->sliceType, "invalid slice type\n");
     analysis->interData = analysis->intraData = NULL;
-    if (!m_param->bUseAnalysisFile && m_param->scaleFactor)
+    if (m_param->bDisableLookahead)
     {
         CHECKED_MALLOC_ZERO(analysis->lookahead.intraSatdForVbv, uint32_t, analysis->numCuInHeight);
         CHECKED_MALLOC_ZERO(analysis->lookahead.satdForVbv, uint32_t, analysis->numCuInHeight);
@@ -2830,7 +2833,7 @@
 
 void Encoder::freeAnalysis(x265_analysis_data* analysis)
 {
-    if (!m_param->bUseAnalysisFile && m_param->scaleFactor)
+    if (m_param->bDisableLookahead)
     {
         X265_FREE(analysis->lookahead.satdForVbv);
         X265_FREE(analysis->lookahead.intraSatdForVbv);
@@ -3016,10 +3019,10 @@
     X265_FREAD(&analysis->bScenecut, sizeof(int), 1, m_analysisFile, &(picData->bScenecut));
     X265_FREAD(&analysis->satdCost, sizeof(int64_t), 1, m_analysisFile, &(picData->satdCost));
     X265_FREAD(&analysis->numCUsInFrame, sizeof(int), 1, m_analysisFile, &(picData->numCUsInFrame));
-    X265_FREAD(&analysis->numCuInHeight, sizeof(uint32_t), 1, m_analysisFile, &(picData->numCuInHeight));
     X265_FREAD(&analysis->numPartitions, sizeof(int), 1, m_analysisFile, &(picData->numPartitions));
-    if (!m_param->bUseAnalysisFile && m_param->scaleFactor)
+    if (m_param->bDisableLookahead)
     {
+        X265_FREAD(&analysis->numCuInHeight, sizeof(uint32_t), 1, m_analysisFile, &(picData->numCuInHeight));
         X265_FREAD(&analysis->lookahead, sizeof(x265_lookahead_data), 1, m_analysisFile, &(picData->lookahead));
     }
     int scaledNumPartition = analysis->numPartitions;
@@ -3030,7 +3033,7 @@
 
     /* Memory is allocated for inter and intra analysis data based on the slicetype */
     allocAnalysis(analysis);
-    if (!m_param->bUseAnalysisFile && m_param->scaleFactor)
+    if (m_param->bDisableLookahead)
     {
         X265_FREAD(analysis->lookahead.intraVbvCost, sizeof(uint32_t), analysis->numCUsInFrame, m_analysisFile, picData->lookahead.intraVbvCost);
         X265_FREAD(analysis->lookahead.vbvCost, sizeof(uint32_t), analysis->numCUsInFrame, m_analysisFile, picData->lookahead.vbvCost);
diff -r bac53338585c -r f8ae7afc1f61 source/encoder/frameencoder.cpp
--- a/source/encoder/frameencoder.cpp	Fri Sep 08 13:56:27 2017 +0530
+++ b/source/encoder/frameencoder.cpp	Mon Sep 11 11:12:19 2017 +0530
@@ -1376,7 +1376,7 @@
             /* TODO: use defines from slicetype.h for lowres block size */
             uint32_t block_y = (ctu->m_cuPelY >> m_param->maxLog2CUSize) * noOfBlocks;
             uint32_t block_x = (ctu->m_cuPelX >> m_param->maxLog2CUSize) * noOfBlocks;
-            if (m_param->analysisReuseMode != X265_ANALYSIS_LOAD || m_param->bUseAnalysisFile || !m_param->scaleFactor)
+            if (m_param->analysisReuseMode != X265_ANALYSIS_LOAD || !m_param->bDisableLookahead)
             {
                 cuStat.vbvCost = 0;
                 cuStat.intraVbvCost = 0;
diff -r bac53338585c -r f8ae7afc1f61 source/encoder/slicetype.cpp
--- a/source/encoder/slicetype.cpp	Fri Sep 08 13:56:27 2017 +0530
+++ b/source/encoder/slicetype.cpp	Mon Sep 11 11:12:19 2017 +0530
@@ -742,7 +742,7 @@
 /* Called by API thread */
 void Lookahead::addPicture(Frame& curFrame, int sliceType)
 {
-    if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD && !m_param->bUseAnalysisFile && m_param->scaleFactor)
+    if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD && m_param->bDisableLookahead)
     {
         if (!m_filled)
             m_filled = true;
@@ -843,7 +843,7 @@
             return out;
         }
 
-        if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD && !m_param->bUseAnalysisFile && m_param->scaleFactor)
+        if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD && m_param->bDisableLookahead)
             return NULL;
 
         findJob(-1); /* run slicetypeDecide() if necessary */
@@ -902,13 +902,13 @@
     default:
         return;
     }
-    if (m_param->analysisReuseMode != X265_ANALYSIS_LOAD || m_param->bUseAnalysisFile || !m_param->scaleFactor)
+    if (m_param->analysisReuseMode != X265_ANALYSIS_LOAD || !m_param->bDisableLookahead)
     {
         X265_CHECK(curFrame->m_lowres.costEst[b - p0][p1 - b] > 0, "Slice cost not estimated\n")
         if (m_param->rc.cuTree && !m_param->rc.bStatRead)
             /* update row satds based on cutree offsets */
             curFrame->m_lowres.satdCost = frameCostRecalculate(frames, p0, p1, b);
-        else if (m_param->analysisReuseMode != X265_ANALYSIS_LOAD)
+        else if (m_param->analysisReuseMode != X265_ANALYSIS_LOAD || m_param->scaleFactor)
         {
             if (m_param->rc.aqMode)
                 curFrame->m_lowres.satdCost = curFrame->m_lowres.costEstAq[b - p0][p1 - b];
diff -r bac53338585c -r f8ae7afc1f61 source/x265.h
--- a/source/x265.h	Fri Sep 08 13:56:27 2017 +0530
+++ b/source/x265.h	Mon Sep 11 11:12:19 2017 +0530
@@ -1501,6 +1501,9 @@
 
     /* Enable skipping split RD analysis when sum of split CU rdCost larger than none split CU rdCost for Intra CU */
     int       bEnableSplitRdSkip;
+
+    /* Disable lookahead */
+    int       bDisableLookahead;
 } x265_param;
 
 /* x265_param_alloc:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: x265-clone.patch
Type: text/x-patch
Size: 12020 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20170911/d32da765/attachment.bin>


More information about the x265-devel mailing list