changeset 11879:f8ae7afc1f61 draft

Add param option for disabling lookahead Fixed crash in analysis load mode also in this patch.
author Divya Manivannan <divya@multicorewareinc.com>
date Mon, 11 Sep 2017 11:12:19 +0530
parents bac53338585c
children 1a7edb6fd993
files source/CMakeLists.txt source/common/param.cpp source/encoder/encoder.cpp source/encoder/frameencoder.cpp source/encoder/slicetype.cpp source/x265.h
diffstat 6 files changed, 28 insertions(+-), 21 deletions(-) [+]
line wrap: on
line diff
--- 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(NATIVE_BUILD "Target the build CP
 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"
--- 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 @@ void x265_param_default(x265_param* para
     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)
--- 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 @@ int Encoder::encode(const x265_picture* 
             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 @@ int Encoder::encode(const x265_picture* 
                     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 @@ int Encoder::encode(const x265_picture* 
                 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 @@ void Encoder::allocAnalysis(x265_analysi
 {
     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 @@ fail:
 
 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 @@ void Encoder::readAnalysisFile(x265_anal
     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 @@ void Encoder::readAnalysisFile(x265_anal
 
     /* 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);
--- 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 @@ void FrameEncoder::processRowEncoder(int
             /* 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;
--- 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 @@ void Lookahead::destroy()
 /* 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 @@ Frame* Lookahead::getDecidedPicture()
             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 @@ void Lookahead::getEstimatedPictureCost(
     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];
--- 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 @@ typedef struct x265_param
 
     /* 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: