[x265] [PATCH] Allow rc and non-rc reconfigure to occur simultaneously

aruna at multicorewareinc.com aruna at multicorewareinc.com
Fri Jul 14 10:41:44 CEST 2017


# HG changeset patch
# User Aruna Matheswaran <aruna at multicorewareinc.com>
# Date 1498626859 -19800
#      Wed Jun 28 10:44:19 2017 +0530
# Node ID 52ef1f37afc21c8fdf908ed5c9f48de48efe15c3
# Parent  18fa144d453ebd1f47905e2656c34e45794a8966
Allow rc and non-rc reconfigure to occur simultaneously

diff -r 18fa144d453e -r 52ef1f37afc2 source/encoder/api.cpp
--- a/source/encoder/api.cpp	Thu Jul 13 16:50:35 2017 +0530
+++ b/source/encoder/api.cpp	Wed Jun 28 10:44:19 2017 +0530
@@ -188,7 +188,8 @@
 
     x265_param save;
     Encoder* encoder = static_cast<Encoder*>(enc);
-    if (encoder->m_reconfigure || encoder->m_reconfigureRc) /* Reconfigure in progress */
+    bool isReconfigureRc = encoder->isReconfigureRc(encoder->m_latestParam, param_in);
+    if (encoder->m_reconfigure && !isReconfigureRc || encoder->m_reconfigureRc && isReconfigureRc) /* Reconfigure in progress */
         return 1;
     memcpy(&save, encoder->m_latestParam, sizeof(x265_param));
     int ret = encoder->reconfigureParam(encoder->m_latestParam, param_in);
@@ -205,16 +206,22 @@
             if (encoder->m_param->bRepeatHeaders)
             {
                 if (encoder->m_scalingList.parseScalingList(encoder->m_latestParam->scalingLists))
+                {
+                    memcpy(encoder->m_latestParam, &save, sizeof(x265_param));
                     return -1;
+                }
                 encoder->m_scalingList.setupQuantMatrices(encoder->m_param->internalCsp);
             }
             else
             {
                 x265_log(encoder->m_param, X265_LOG_ERROR, "Repeat headers is turned OFF, cannot reconfigure scalinglists\n");
+                memcpy(encoder->m_latestParam, &save, sizeof(x265_param));
                 return -1;
             }
         }
-        if (encoder->m_reconfigureRc)
+        if (!isReconfigureRc)
+            encoder->m_reconfigure = true;
+        else if (encoder->m_reconfigureRc)
         {
             VPS saveVPS;
             memcpy(&saveVPS.ptl, &encoder->m_vps.ptl, sizeof(saveVPS.ptl));
@@ -225,11 +232,11 @@
                 x265_log(encoder->m_param, X265_LOG_WARNING, "Profile/Level/Tier has changed from %d/%d/%s to %d/%d/%s.Cannot reconfigure rate-control.\n",
                          saveVPS.ptl.profileIdc, saveVPS.ptl.levelIdc, saveVPS.ptl.tierFlag ? "High" : "Main", encoder->m_vps.ptl.profileIdc,
                          encoder->m_vps.ptl.levelIdc, encoder->m_vps.ptl.tierFlag ? "High" : "Main");
+                memcpy(encoder->m_latestParam, &save, sizeof(x265_param));
+                memcpy(&encoder->m_vps.ptl, &saveVPS.ptl, sizeof(saveVPS.ptl));
                 encoder->m_reconfigureRc = false;
             }
         }
-        else
-            encoder->m_reconfigure = true;
         encoder->printReconfigureParams();
     }
     return ret;
diff -r 18fa144d453e -r 52ef1f37afc2 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Thu Jul 13 16:50:35 2017 +0530
+++ b/source/encoder/encoder.cpp	Wed Jun 28 10:44:19 2017 +0530
@@ -1130,48 +1130,61 @@
 
 int Encoder::reconfigureParam(x265_param* encParam, x265_param* param)
 {
-    encParam->maxNumReferences = param->maxNumReferences; // never uses more refs than specified in stream headers
-    encParam->bEnableFastIntra = param->bEnableFastIntra;
-    encParam->bEnableEarlySkip = param->bEnableEarlySkip;
-    encParam->bEnableRecursionSkip = param->bEnableRecursionSkip;
-    encParam->searchMethod = param->searchMethod;
-    /* Scratch buffer prevents me_range from being increased for esa/tesa */
-    if (param->searchRange < encParam->searchRange)
-        encParam->searchRange = param->searchRange;
-    /* We can't switch out of subme=0 during encoding. */
-    if (encParam->subpelRefine)
-        encParam->subpelRefine = param->subpelRefine;
-    encParam->rdoqLevel = param->rdoqLevel;
-    encParam->rdLevel = param->rdLevel;
-    encParam->bEnableRectInter = param->bEnableRectInter;
-    encParam->maxNumMergeCand = param->maxNumMergeCand;
-    encParam->bIntraInBFrames = param->bIntraInBFrames;
-    if (param->scalingLists && !encParam->scalingLists)
-        encParam->scalingLists = strdup(param->scalingLists);
-    /* VBV can't be turned ON if it wasn't ON to begin with and can't be turned OFF if it was ON to begin with*/
-    if (param->rc.vbvMaxBitrate > 0 && param->rc.vbvBufferSize > 0 &&
-        encParam->rc.vbvMaxBitrate > 0 && encParam->rc.vbvBufferSize > 0)
+    if (isReconfigureRc(encParam, param))
     {
-        m_reconfigureRc |= encParam->rc.vbvMaxBitrate != param->rc.vbvMaxBitrate;
-        m_reconfigureRc |= encParam->rc.vbvBufferSize != param->rc.vbvBufferSize;
-        if (m_reconfigureRc && m_param->bEmitHRDSEI)
-            x265_log(m_param, X265_LOG_WARNING, "VBV parameters cannot be changed when HRD is in use.\n");
-        else
+        /* VBV can't be turned ON if it wasn't ON to begin with and can't be turned OFF if it was ON to begin with*/
+        if (param->rc.vbvMaxBitrate > 0 && param->rc.vbvBufferSize > 0 &&
+            encParam->rc.vbvMaxBitrate > 0 && encParam->rc.vbvBufferSize > 0)
         {
-            encParam->rc.vbvMaxBitrate = param->rc.vbvMaxBitrate;
-            encParam->rc.vbvBufferSize = param->rc.vbvBufferSize;
+            m_reconfigureRc |= encParam->rc.vbvMaxBitrate != param->rc.vbvMaxBitrate;
+            m_reconfigureRc |= encParam->rc.vbvBufferSize != param->rc.vbvBufferSize;
+            if (m_reconfigureRc && m_param->bEmitHRDSEI)
+                x265_log(m_param, X265_LOG_WARNING, "VBV parameters cannot be changed when HRD is in use.\n");
+            else
+            {
+                encParam->rc.vbvMaxBitrate = param->rc.vbvMaxBitrate;
+                encParam->rc.vbvBufferSize = param->rc.vbvBufferSize;
+            }
         }
+        m_reconfigureRc |= encParam->rc.bitrate != param->rc.bitrate;
+        encParam->rc.bitrate = param->rc.bitrate;
+        m_reconfigureRc |= encParam->rc.rfConstant != param->rc.rfConstant;
+        encParam->rc.rfConstant = param->rc.rfConstant;
     }
-    m_reconfigureRc |= encParam->rc.bitrate != param->rc.bitrate;
-    encParam->rc.bitrate = param->rc.bitrate;
-    m_reconfigureRc |= encParam->rc.rfConstant != param->rc.rfConstant;
-    encParam->rc.rfConstant = param->rc.rfConstant; 
-
+    else
+    {
+        encParam->maxNumReferences = param->maxNumReferences; // never uses more refs than specified in stream headers
+        encParam->bEnableFastIntra = param->bEnableFastIntra;
+        encParam->bEnableEarlySkip = param->bEnableEarlySkip;
+        encParam->bEnableRecursionSkip = param->bEnableRecursionSkip;
+        encParam->searchMethod = param->searchMethod;
+        /* Scratch buffer prevents me_range from being increased for esa/tesa */
+        if (param->searchRange < encParam->searchRange)
+            encParam->searchRange = param->searchRange;
+        /* We can't switch out of subme=0 during encoding. */
+        if (encParam->subpelRefine)
+            encParam->subpelRefine = param->subpelRefine;
+        encParam->rdoqLevel = param->rdoqLevel;
+        encParam->rdLevel = param->rdLevel;
+        encParam->bEnableRectInter = param->bEnableRectInter;
+        encParam->maxNumMergeCand = param->maxNumMergeCand;
+        encParam->bIntraInBFrames = param->bIntraInBFrames;
+        if (param->scalingLists && !encParam->scalingLists)
+            encParam->scalingLists = strdup(param->scalingLists);
+    }
     /* To add: Loop Filter/deblocking controls, transform skip, signhide require PPS to be resent */
     /* To add: SAO, temporal MVP, AMP, TU depths require SPS to be resent, at every CVS boundary */
     return x265_check_params(encParam);
 }
 
+bool Encoder::isReconfigureRc(x265_param* latestParam, x265_param* param_in)
+{
+    return (latestParam->rc.vbvMaxBitrate != param_in->rc.vbvMaxBitrate
+        || latestParam->rc.vbvBufferSize != param_in->rc.vbvBufferSize
+        || latestParam->rc.bitrate != param_in->rc.bitrate
+        || latestParam->rc.rfConstant != param_in->rc.rfConstant);
+}
+
 void Encoder::copyCtuInfo(x265_ctu_info_t** frameCtuInfo, int poc)
 {
     uint32_t widthInCU = (m_param->sourceWidth + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;
diff -r 18fa144d453e -r 52ef1f37afc2 source/encoder/encoder.h
--- a/source/encoder/encoder.h	Thu Jul 13 16:50:35 2017 +0530
+++ b/source/encoder/encoder.h	Wed Jun 28 10:44:19 2017 +0530
@@ -201,6 +201,8 @@
 
     int reconfigureParam(x265_param* encParam, x265_param* param);
 
+    bool isReconfigureRc(x265_param* latestParam, x265_param* param_in);
+
     void copyCtuInfo(x265_ctu_info_t** frameCtuInfo, int poc);
 
     void getStreamHeaders(NALList& list, Entropy& sbacCoder, Bitstream& bs);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: x265_clone.patch
Type: text/x-patch
Size: 8744 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20170714/2d754c44/attachment-0001.bin>


More information about the x265-devel mailing list