<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 11, 2017 at 8:09 PM, Divya Manivannan <span dir="ltr"><<a href="mailto:divya@multicorewareinc.com" target="_blank">divya@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 Divya Manivannan <<a href="mailto:divya@multicorewareinc.com">divya@multicorewareinc.com</a>><br>
# Date 1505108539 -19800<br>
#      Mon Sep 11 11:12:19 2017 +0530<br>
# Node ID f8ae7afc1f61ed0db3b2f23f5d5817<wbr>06fe6ed677<br>
# Parent  bac53338585c00d943aa995db5ced8<wbr>744a9d20e9<br>
Add param option for disabling lookahead<br></blockquote><div><br></div><div>Pushed to default branch</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Fixed crash in analysis load mode also in this patch.<br>
<br>
diff -r bac53338585c -r f8ae7afc1f61 source/CMakeLists.txt<br>
--- a/source/CMakeLists.txt     Fri Sep 08 13:56:27 2017 +0530<br>
+++ b/source/CMakeLists.txt     Mon Sep 11 11:12:19 2017 +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 135)<br>
+set(X265_BUILD 136)<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 bac53338585c -r f8ae7afc1f61 source/common/param.cpp<br>
--- a/source/common/param.cpp   Fri Sep 08 13:56:27 2017 +0530<br>
+++ b/source/common/param.cpp   Mon Sep 11 11:12:19 2017 +0530<br>
@@ -287,6 +287,7 @@<br>
     param->bUseAnalysisFile = 1;<br>
     param->csvfpt = NULL;<br>
     param->forceFlush = 0;<br>
+    param->bDisableLookahead = 0;<br>
 }<br>
<br>
 int x265_param_default_preset(<wbr>x265_param* param, const char* preset, const char* tune)<br>
diff -r bac53338585c -r f8ae7afc1f61 source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp        Fri Sep 08 13:56:27 2017 +0530<br>
+++ b/source/encoder/encoder.cpp        Mon Sep 11 11:12:19 2017 +0530<br>
@@ -794,7 +794,7 @@<br>
             sliceType = inFrame->m_analysisData.<wbr>sliceType;<br>
             inFrame->m_lowres.bScenecut = !!inFrame->m_analysisData.<wbr>bScenecut;<br>
             inFrame->m_lowres.satdCost = inFrame->m_analysisData.<wbr>satdCost;<br>
-            if (!m_param->bUseAnalysisFile && m_param->scaleFactor)<br>
+            if (m_param->bDisableLookahead)<br>
             {<br>
                 inFrame->m_lowres.sliceType = sliceType;<br>
                 inFrame->m_lowres.bKeyframe = !!inFrame->m_analysisData.<wbr>lookahead.keyframe;<br>
@@ -901,33 +901,36 @@<br>
                     pic_out->analysisData.<wbr>bScenecut = outFrame->m_lowres.bScenecut;<br>
                     pic_out->analysisData.satdCost  = outFrame->m_lowres.satdCost;<br>
                     pic_out->analysisData.<wbr>numCUsInFrame = outFrame->m_analysisData.<wbr>numCUsInFrame;<br>
-                    pic_out->analysisData.<wbr>numCuInHeight = outFrame->m_analysisData.<wbr>numCuInHeight;<br>
                     pic_out->analysisData.<wbr>numPartitions = outFrame->m_analysisData.<wbr>numPartitions;<br>
                     pic_out->analysisData.wt = outFrame->m_analysisData.wt;<br>
                     pic_out->analysisData.<wbr>interData = outFrame->m_analysisData.<wbr>interData;<br>
                     pic_out->analysisData.<wbr>intraData = outFrame->m_analysisData.<wbr>intraData;<br>
-                    if (!m_param->bUseAnalysisFile && m_param->scaleFactor)<br>
+                    if (m_param->bDisableLookahead)<br>
                     {<br>
-                        pic_out->analysisData.satdCost *= m_param->scaleFactor * 2;<br>
+                        int factor = 1;<br>
+                        if (m_param->scaleFactor)<br>
+                            factor = m_param->scaleFactor * 2;<br>
+                        pic_out->analysisData.<wbr>numCuInHeight = outFrame->m_analysisData.<wbr>numCuInHeight;<br>
+                        pic_out->analysisData.satdCost *= factor;<br>
                         pic_out->analysisData.<wbr>lookahead.keyframe = outFrame->m_lowres.bKeyframe;<br>
                         pic_out->analysisData.<wbr>lookahead.lastMiniGopBFrame = outFrame->m_lowres.<wbr>bLastMiniGopBFrame;<br>
                         int vbvCount = m_param->lookaheadDepth + m_param->bframes + 2;<br>
                         for (int index = 0; index < vbvCount; index++)<br>
                         {<br>
-                            pic_out->analysisData.<wbr>lookahead.plannedSatd[index] = outFrame->m_lowres.<wbr>plannedSatd[index] * m_param->scaleFactor * 2;<br>
+                            pic_out->analysisData.<wbr>lookahead.plannedSatd[index] = outFrame->m_lowres.<wbr>plannedSatd[index] * factor;<br>
                             pic_out->analysisData.<wbr>lookahead.plannedType[index] = outFrame->m_lowres.<wbr>plannedType[index];<br>
                         }<br>
                         for (uint32_t index = 0; index < pic_out->analysisData.<wbr>numCuInHeight; index++)<br>
                         {<br>
-                            outFrame->m_analysisData.<wbr>lookahead.intraSatdForVbv[<wbr>index] = outFrame->m_encData->m_<wbr>rowStat[index].intraSatdForVbv * m_param->scaleFactor * 2;<br>
-                            outFrame->m_analysisData.<wbr>lookahead.satdForVbv[index] = outFrame->m_encData->m_<wbr>rowStat[index].satdForVbv * m_param->scaleFactor * 2;<br>
+                            outFrame->m_analysisData.<wbr>lookahead.intraSatdForVbv[<wbr>index] = outFrame->m_encData->m_<wbr>rowStat[index].intraSatdForVbv * factor;<br>
+                            outFrame->m_analysisData.<wbr>lookahead.satdForVbv[index] = outFrame->m_encData->m_<wbr>rowStat[index].satdForVbv * factor;<br>
                         }<br>
                         pic_out->analysisData.<wbr>lookahead.intraSatdForVbv = outFrame->m_analysisData.<wbr>lookahead.intraSatdForVbv;<br>
                         pic_out->analysisData.<wbr>lookahead.satdForVbv = outFrame->m_analysisData.<wbr>lookahead.satdForVbv;<br>
                         for (uint32_t index = 0; index < pic_out->analysisData.<wbr>numCUsInFrame; index++)<br>
                         {<br>
-                            outFrame->m_analysisData.<wbr>lookahead.intraVbvCost[index] = outFrame->m_encData->m_cuStat[<wbr>index].intraVbvCost * m_param->scaleFactor * 2;<br>
-                            outFrame->m_analysisData.<wbr>lookahead.vbvCost[index] = outFrame->m_encData->m_cuStat[<wbr>index].vbvCost * m_param->scaleFactor * 2;<br>
+                            outFrame->m_analysisData.<wbr>lookahead.intraVbvCost[index] = outFrame->m_encData->m_cuStat[<wbr>index].intraVbvCost * factor;<br>
+                            outFrame->m_analysisData.<wbr>lookahead.vbvCost[index] = outFrame->m_encData->m_cuStat[<wbr>index].vbvCost * factor;<br>
                         }<br>
                         pic_out->analysisData.<wbr>lookahead.intraVbvCost = outFrame->m_analysisData.<wbr>lookahead.intraVbvCost;<br>
                         pic_out->analysisData.<wbr>lookahead.vbvCost = outFrame->m_analysisData.<wbr>lookahead.vbvCost;<br>
@@ -1094,7 +1097,7 @@<br>
                 slice->m_maxNumMergeCand = m_param->maxNumMergeCand;<br>
                 slice->m_endCUAddr = slice->realEndAddress(m_sps.<wbr>numCUsInFrame * m_param->num4x4Partitions);<br>
             }<br>
-            if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD && !m_param->bUseAnalysisFile && m_param->scaleFactor)<br>
+            if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD && m_param->bDisableLookahead)<br>
             {<br>
                 for (uint32_t index = 0; index < frameEnc->m_analysisData.<wbr>numCuInHeight; index++)<br>
                 {<br>
@@ -2758,7 +2761,7 @@<br>
 {<br>
     X265_CHECK(analysis-><wbr>sliceType, "invalid slice type\n");<br>
     analysis->interData = analysis->intraData = NULL;<br>
-    if (!m_param->bUseAnalysisFile && m_param->scaleFactor)<br>
+    if (m_param->bDisableLookahead)<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>
@@ -2830,7 +2833,7 @@<br>
<br>
 void Encoder::freeAnalysis(x265_<wbr>analysis_data* analysis)<br>
 {<br>
-    if (!m_param->bUseAnalysisFile && m_param->scaleFactor)<br>
+    if (m_param->bDisableLookahead)<br>
     {<br>
         X265_FREE(analysis->lookahead.<wbr>satdForVbv);<br>
         X265_FREE(analysis->lookahead.<wbr>intraSatdForVbv);<br>
@@ -3016,10 +3019,10 @@<br>
     X265_FREAD(&analysis-><wbr>bScenecut, sizeof(int), 1, m_analysisFile, &(picData->bScenecut));<br>
     X265_FREAD(&analysis-><wbr>satdCost, sizeof(int64_t), 1, m_analysisFile, &(picData->satdCost));<br>
     X265_FREAD(&analysis-><wbr>numCUsInFrame, sizeof(int), 1, m_analysisFile, &(picData->numCUsInFrame));<br>
-    X265_FREAD(&analysis-><wbr>numCuInHeight, sizeof(uint32_t), 1, m_analysisFile, &(picData->numCuInHeight));<br>
     X265_FREAD(&analysis-><wbr>numPartitions, sizeof(int), 1, m_analysisFile, &(picData->numPartitions));<br>
-    if (!m_param->bUseAnalysisFile && m_param->scaleFactor)<br>
+    if (m_param->bDisableLookahead)<br>
     {<br>
+        X265_FREAD(&analysis-><wbr>numCuInHeight, sizeof(uint32_t), 1, m_analysisFile, &(picData->numCuInHeight));<br>
         X265_FREAD(&analysis-><wbr>lookahead, sizeof(x265_lookahead_data), 1, m_analysisFile, &(picData->lookahead));<br>
     }<br>
     int scaledNumPartition = analysis->numPartitions;<br>
@@ -3030,7 +3033,7 @@<br>
<br>
     /* Memory is allocated for inter and intra analysis data based on the slicetype */<br>
     allocAnalysis(analysis);<br>
-    if (!m_param->bUseAnalysisFile && m_param->scaleFactor)<br>
+    if (m_param->bDisableLookahead)<br>
     {<br>
         X265_FREAD(analysis-><wbr>lookahead.intraVbvCost, sizeof(uint32_t), analysis->numCUsInFrame, m_analysisFile, picData->lookahead.<wbr>intraVbvCost);<br>
         X265_FREAD(analysis-><wbr>lookahead.vbvCost, sizeof(uint32_t), analysis->numCUsInFrame, m_analysisFile, picData->lookahead.vbvCost);<br>
diff -r bac53338585c -r f8ae7afc1f61 source/encoder/frameencoder.<wbr>cpp<br>
--- a/source/encoder/frameencoder.<wbr>cpp   Fri Sep 08 13:56:27 2017 +0530<br>
+++ b/source/encoder/frameencoder.<wbr>cpp   Mon Sep 11 11:12:19 2017 +0530<br>
@@ -1376,7 +1376,7 @@<br>
             /* TODO: use defines from slicetype.h for lowres block size */<br>
             uint32_t block_y = (ctu->m_cuPelY >> m_param->maxLog2CUSize) * noOfBlocks;<br>
             uint32_t block_x = (ctu->m_cuPelX >> m_param->maxLog2CUSize) * noOfBlocks;<br>
-            if (m_param->analysisReuseMode != X265_ANALYSIS_LOAD || m_param->bUseAnalysisFile || !m_param->scaleFactor)<br>
+            if (m_param->analysisReuseMode != X265_ANALYSIS_LOAD || !m_param->bDisableLookahead)<br>
             {<br>
                 cuStat.vbvCost = 0;<br>
                 cuStat.intraVbvCost = 0;<br>
diff -r bac53338585c -r f8ae7afc1f61 source/encoder/slicetype.cpp<br>
--- a/source/encoder/slicetype.cpp      Fri Sep 08 13:56:27 2017 +0530<br>
+++ b/source/encoder/slicetype.cpp      Mon Sep 11 11:12:19 2017 +0530<br>
@@ -742,7 +742,7 @@<br>
 /* Called by API thread */<br>
 void Lookahead::addPicture(Frame& curFrame, int sliceType)<br>
 {<br>
-    if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD && !m_param->bUseAnalysisFile && m_param->scaleFactor)<br>
+    if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD && m_param->bDisableLookahead)<br>
     {<br>
         if (!m_filled)<br>
             m_filled = true;<br>
@@ -843,7 +843,7 @@<br>
             return out;<br>
         }<br>
<br>
-        if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD && !m_param->bUseAnalysisFile && m_param->scaleFactor)<br>
+        if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD && m_param->bDisableLookahead)<br>
             return NULL;<br>
<br>
         findJob(-1); /* run slicetypeDecide() if necessary */<br>
@@ -902,13 +902,13 @@<br>
     default:<br>
         return;<br>
     }<br>
-    if (m_param->analysisReuseMode != X265_ANALYSIS_LOAD || m_param->bUseAnalysisFile || !m_param->scaleFactor)<br>
+    if (m_param->analysisReuseMode != X265_ANALYSIS_LOAD || !m_param->bDisableLookahead)<br>
     {<br>
         X265_CHECK(curFrame->m_lowres.<wbr>costEst[b - p0][p1 - b] > 0, "Slice cost not estimated\n")<br>
         if (m_param->rc.cuTree && !m_param->rc.bStatRead)<br>
             /* update row satds based on cutree offsets */<br>
             curFrame->m_lowres.satdCost = frameCostRecalculate(frames, p0, p1, b);<br>
-        else if (m_param->analysisReuseMode != X265_ANALYSIS_LOAD)<br>
+        else if (m_param->analysisReuseMode != X265_ANALYSIS_LOAD || m_param->scaleFactor)<br>
         {<br>
             if (m_param->rc.aqMode)<br>
                 curFrame->m_lowres.satdCost = curFrame->m_lowres.costEstAq[b - p0][p1 - b];<br>
diff -r bac53338585c -r f8ae7afc1f61 source/x265.h<br>
--- a/source/x265.h     Fri Sep 08 13:56:27 2017 +0530<br>
+++ b/source/x265.h     Mon Sep 11 11:12:19 2017 +0530<br>
@@ -1501,6 +1501,9 @@<br>
<br>
     /* Enable skipping split RD analysis when sum of split CU rdCost larger than none split CU rdCost for Intra CU */<br>
     int       bEnableSplitRdSkip;<br>
+<br>
+    /* Disable lookahead */<br>
+    int       bDisableLookahead;<br>
 } x265_param;<br>
<br>
 /* x265_param_alloc:<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>