changeset 11903:e98cb4ce88b5

add new CLI refine-mv-type
author Santhoshini Sekar <santhoshini@multicorewareinc.com>
date Mon, 06 Nov 2017 13:52:22 +0530
parents 51316ca938c8
children 702fe36ec3be
files doc/reST/cli.rst source/CMakeLists.txt source/common/frame.cpp source/common/param.cpp source/encoder/analysis.cpp source/encoder/api.cpp source/encoder/encoder.cpp source/encoder/search.cpp source/x265.h source/x265cli.h
diffstat 10 files changed, 51 insertions(+-), 9 deletions(-) [+]
line wrap: on
line diff
--- a/doc/reST/cli.rst	Wed Aug 09 11:38:58 2017 +0530
+++ b/doc/reST/cli.rst	Mon Nov 06 13:52:22 2017 +0530
@@ -887,6 +887,11 @@ will not reuse analysis if slice type pa
 	| 10     | Level 5 + Full CU analysis-info         |
 	+--------+-----------------------------------------+
 
+.. option:: --refine-mv-type <string>
+
+    Reuse MV information received through API call. Currently receives information for AVC size and the accepted 
+    string input is "avc". Default is disabled.
+
 .. option:: --scale-factor
 
        Factor by which input video is scaled down for analysis save mode.
--- a/source/CMakeLists.txt	Wed Aug 09 11:38:58 2017 +0530
+++ b/source/CMakeLists.txt	Mon Nov 06 13:52:22 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 140)
+set(X265_BUILD 141)
 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/frame.cpp	Wed Aug 09 11:38:58 2017 +0530
+++ b/source/common/frame.cpp	Mon Nov 06 13:52:22 2017 +0530
@@ -77,6 +77,14 @@ bool Frame::create(x265_param *param, fl
         }
     }
 
+    if (param->bMVType == AVC_INFO)
+    {
+        m_analysisData.wt = NULL;
+        m_analysisData.intraData = NULL;
+        m_analysisData.interData = NULL;
+        m_analysis2Pass.analysisFramedata = NULL;
+    }
+
     if (m_fencPic->create(param) && m_lowres.create(m_fencPic, param->bframes, !!param->rc.aqMode || !!param->bAQMotion, param->rc.qgSize))
     {
         X265_CHECK((m_reconColCount == NULL), "m_reconColCount was initialized");
--- a/source/common/param.cpp	Wed Aug 09 11:38:58 2017 +0530
+++ b/source/common/param.cpp	Mon Nov 06 13:52:22 2017 +0530
@@ -293,6 +293,7 @@ void x265_param_default(x265_param* para
 
     /* DCT Approximations */
     param->bLowPassDct = 0;
+    param->bMVType = 0;
 }
 
 int x265_param_default_preset(x265_param* param, const char* preset, const char* tune)
@@ -986,6 +987,21 @@ int x265_param_parse(x265_param* p, cons
 		OPT("lowpass-dct") p->bLowPassDct = atobool(value);
         OPT("vbv-end") p->vbvBufferEnd = atof(value);
         OPT("vbv-end-fr-adj") p->vbvEndFrameAdjust = atof(value);
+        OPT("refine-mv-type")
+        {
+            if (strcmp(strdup(value), "avc") == 0)
+            {
+                p->bMVType = AVC_INFO;
+            }
+            else if (strcmp(strdup(value), "off") == 0)
+            {
+                p->bMVType = NO_INFO;
+            }
+            else
+            {
+                bError = true;
+            }
+         }
         else
             return X265_PARAM_BAD_NAME;
     }
@@ -1474,6 +1490,8 @@ void x265_print_params(x265_param* param
     TOOLVAL(param->lookaheadSlices, "lslices=%d");
     TOOLVAL(param->lookaheadThreads, "lthreads=%d")
     TOOLVAL(param->bCTUInfo, "ctu-info=%d");
+    if (param->bMVType == AVC_INFO)
+        TOOLOPT(param->bMVType, "refine-mv-type=avc");
     if (param->maxSlices > 1)
         TOOLVAL(param->maxSlices, "slices=%d");
     if (param->bEnableLoopFilter)
@@ -1699,6 +1717,7 @@ char *x265_param2string(x265_param* p, i
     BOOL(p->bLimitSAO, "limit-sao");
     s += sprintf(s, " ctu-info=%d", p->bCTUInfo);
     BOOL(p->bLowPassDct, "lowpass-dct");
+    s += sprintf(s, " refine-mv-type=%d", p->bMVType);
 #undef BOOL
     return buf;
 }
--- a/source/encoder/analysis.cpp	Wed Aug 09 11:38:58 2017 +0530
+++ b/source/encoder/analysis.cpp	Mon Nov 06 13:52:22 2017 +0530
@@ -250,14 +250,14 @@ Mode& Analysis::compressCTU(CUData& ctu,
             /* generate residual for entire CTU at once and copy to reconPic */
             encodeResidue(ctu, cuGeom);
         }
-        else if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD && m_param->analysisReuseLevel == 10)
+        else if ((m_param->analysisReuseMode == X265_ANALYSIS_LOAD && m_param->analysisReuseLevel == 10) || ((m_param->bMVType == AVC_INFO) && m_param->analysisReuseLevel >= 7))
         {
             analysis_inter_data* interDataCTU = (analysis_inter_data*)m_frame->m_analysisData.interData;
             int posCTU = ctu.m_cuAddr * numPartition;
             memcpy(ctu.m_cuDepth, &interDataCTU->depth[posCTU], sizeof(uint8_t) * numPartition);
             memcpy(ctu.m_predMode, &interDataCTU->modes[posCTU], sizeof(uint8_t) * numPartition);
             memcpy(ctu.m_partSize, &interDataCTU->partSize[posCTU], sizeof(uint8_t) * numPartition);
-            if (m_slice->m_sliceType == P_SLICE || m_param->bIntraInBFrames)
+            if ((m_slice->m_sliceType == P_SLICE || m_param->bIntraInBFrames) && !(m_param->bMVType == AVC_INFO))
             {
                 analysis_intra_data* intraDataCTU = (analysis_intra_data*)m_frame->m_analysisData.intraData;
                 memcpy(ctu.m_lumaIntraDir, &intraDataCTU->modes[posCTU], sizeof(uint8_t) * numPartition);
@@ -1227,7 +1227,7 @@ SplitData Analysis::compressInterCU_rd0_
             mightSplit &= !bDecidedDepth;
         }
     }
-    if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD && m_param->analysisReuseLevel > 1 && m_param->analysisReuseLevel != 10)
+    if ((m_param->analysisReuseMode == X265_ANALYSIS_LOAD && m_param->analysisReuseLevel > 1 && m_param->analysisReuseLevel != 10))
     {
         if (mightNotSplit && depth == m_reuseDepth[cuGeom.absPartIdx])
         {
--- a/source/encoder/api.cpp	Wed Aug 09 11:38:58 2017 +0530
+++ b/source/encoder/api.cpp	Mon Nov 06 13:52:22 2017 +0530
@@ -380,7 +380,7 @@ void x265_picture_init(x265_param *param
     pic->userSEI.payloads = NULL;
     pic->userSEI.numPayloads = 0;
 
-    if (param->analysisReuseMode)
+    if (param->analysisReuseMode || (param->bMVType == AVC_INFO))
     {
         uint32_t widthInCU = (param->sourceWidth + param->maxCUSize - 1) >> param->maxLog2CUSize;
         uint32_t heightInCU = (param->sourceHeight + param->maxCUSize - 1) >> param->maxLog2CUSize;
--- a/source/encoder/encoder.cpp	Wed Aug 09 11:38:58 2017 +0530
+++ b/source/encoder/encoder.cpp	Mon Nov 06 13:52:22 2017 +0530
@@ -1015,7 +1015,7 @@ int Encoder::encode(const x265_picture* 
             x265_frame_stats* frameData = NULL;
 
             /* Free up pic_in->analysisData since it has already been used */
-            if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD)
+            if (m_param->analysisReuseMode == X265_ANALYSIS_LOAD || (m_param->bMVType && slice->m_sliceType != I_SLICE))
                 freeAnalysis(&outFrame->m_analysisData);
 
             if (pic_out)
@@ -2937,7 +2937,8 @@ void Encoder::allocAnalysis(x265_analysi
     {
         int numDir = analysis->sliceType == X265_TYPE_P ? 1 : 2;
         uint32_t numPlanes = m_param->internalCsp == X265_CSP_I400 ? 1 : 3;
-        CHECKED_MALLOC_ZERO(analysis->wt, WeightParam, numPlanes * numDir);
+        if (!(m_param->bMVType == AVC_INFO))
+            CHECKED_MALLOC_ZERO(analysis->wt, WeightParam, numPlanes * numDir);
         if (m_param->analysisReuseLevel < 2)
             return;
 
@@ -2993,7 +2994,7 @@ void Encoder::freeAnalysis(x265_analysis
         X265_FREE(analysis->lookahead.intraVbvCost);
     }
     /* Early exit freeing weights alone if level is 1 (when there is no analysis inter/intra) */
-    if (analysis->sliceType > X265_TYPE_I && analysis->wt)
+    if (analysis->sliceType > X265_TYPE_I && analysis->wt && !(m_param->bMVType == AVC_INFO))
         X265_FREE(analysis->wt);
     if (m_param->analysisReuseLevel < 2)
         return;
--- a/source/encoder/search.cpp	Wed Aug 09 11:38:58 2017 +0530
+++ b/source/encoder/search.cpp	Mon Nov 06 13:52:22 2017 +0530
@@ -2162,7 +2162,7 @@ void Search::predInterSearch(Mode& inter
 
         /* Uni-directional prediction */
         if ((m_param->analysisReuseMode == X265_ANALYSIS_LOAD && m_param->analysisReuseLevel > 1 && m_param->analysisReuseLevel != 10)
-            || (m_param->analysisMultiPassRefine && m_param->rc.bStatRead))
+            || (m_param->analysisMultiPassRefine && m_param->rc.bStatRead) || (m_param->bMVType == AVC_INFO))
         {
             for (int list = 0; list < numPredDir; list++)
             {
--- a/source/x265.h	Wed Aug 09 11:38:58 2017 +0530
+++ b/source/x265.h	Mon Nov 06 13:52:22 2017 +0530
@@ -223,6 +223,11 @@ typedef enum
     CTU_INFO_CHANGE = 2,
 }CTUInfo;
 
+typedef enum
+{
+    NO_INFO = 0,
+    AVC_INFO = 1,
+}MVRefineType;
 
 /* Arbitrary User SEI
  * Payload size is in bytes and the payload pointer must be non-NULL. 
@@ -1524,6 +1529,9 @@ typedef struct x265_param
     /* Frame from which qp has to be adjusted to hit final decode buffer emptiness.
     * Specified as a fraction of the total frames. Default 0 */
     double    vbvEndFrameAdjust;
+
+    /* Reuse MV information obtained through API */
+    int       bMVType;
 } x265_param;
 
 /* x265_param_alloc:
--- a/source/x265cli.h	Wed Aug 09 11:38:58 2017 +0530
+++ b/source/x265cli.h	Mon Nov 06 13:52:22 2017 +0530
@@ -285,6 +285,7 @@ static const struct option long_options[
     { "splitrd-skip",         no_argument, NULL, 0 },
     { "no-splitrd-skip",      no_argument, NULL, 0 },
     { "lowpass-dct",          no_argument, NULL, 0 },
+    { "refine-mv-type", required_argument, NULL, 0 },
     { 0, 0, 0, 0 },
     { 0, 0, 0, 0 },
     { 0, 0, 0, 0 },