changeset 12633:10e354213df2

Add option to get global maxrate This global maxrate can be used for HRD signaling
author Snehaa Giridharan <snehaa@multicorewareinc.com>
date Wed, 18 Mar 2020 18:51:39 +0530
parents 9879e83852b5
children 00b686782ad0
files source/CMakeLists.txt source/common/param.cpp source/encoder/ratecontrol.cpp source/x265.h
diffstat 4 files changed, 12 insertions(+-), 3 deletions(-) [+]
line wrap: on
line diff
--- a/source/CMakeLists.txt	Thu Dec 05 17:55:01 2019 +0530
+++ b/source/CMakeLists.txt	Wed Mar 18 18:51:39 2020 +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 190)
+set(X265_BUILD 191)
 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	Thu Dec 05 17:55:01 2019 +0530
+++ b/source/common/param.cpp	Wed Mar 18 18:51:39 2020 +0530
@@ -286,6 +286,7 @@ void x265_param_default(x265_param* para
     param->rc.bEnableConstVbv = 0;
     param->bResetZoneConfig = 1;
     param->reconfigWindowSize = 0;
+    param->decoderVbvMaxRate = 0;
 
     /* Video Usability Information (VUI) */
     param->vui.aspectRatioIdc = 0;
@@ -1799,6 +1800,7 @@ int x265_check_params(x265_param* param)
     }
     CHECK(param->confWinRightOffset < 0, "Conformance Window Right Offset must be 0 or greater");
     CHECK(param->confWinBottomOffset < 0, "Conformance Window Bottom Offset must be 0 or greater");
+    CHECK(param->decoderVbvMaxRate < 0, "Invalid Decoder Vbv Maxrate. Value can not be less than zero");
     return check_failed;
 }
 
@@ -2219,6 +2221,7 @@ char *x265_param2string(x265_param* p, i
     if (p->bEnableSceneCutAwareQp)
         s += sprintf(s, " scenecut-window=%d max-qp-delta=%d", p->scenecutWindow, p->maxQpDelta);
     s += sprintf(s, "conformance-window-offsets right=%d bottom=%d", p->confWinRightOffset, p->confWinBottomOffset);
+    s += sprintf(s, " decoder-max-rate=%d", p->decoderVbvMaxRate);
 #undef BOOL
     return buf;
 }
@@ -2435,6 +2438,7 @@ void x265_copy_params(x265_param* dst, x
     dst->rc.zonefileCount = src->rc.zonefileCount;
     dst->reconfigWindowSize = src->reconfigWindowSize;
     dst->bResetZoneConfig = src->bResetZoneConfig;
+    dst->decoderVbvMaxRate = src->decoderVbvMaxRate;
 
     if (src->rc.zonefileCount && src->rc.zones)
     {
--- a/source/encoder/ratecontrol.cpp	Thu Dec 05 17:55:01 2019 +0530
+++ b/source/encoder/ratecontrol.cpp	Wed Mar 18 18:51:39 2020 +0530
@@ -335,7 +335,7 @@ bool RateControl::init(const SPS& sps)
         int vbvBufferSize = m_param->rc.vbvBufferSize * 1000;
         int vbvMaxBitrate = m_param->rc.vbvMaxBitrate * 1000;
 
-        if (m_param->bEmitHRDSEI)
+        if (m_param->bEmitHRDSEI && !m_param->decoderVbvMaxRate)
         {
             const HRDInfo* hrd = &sps.vuiParameters.hrdParameters;
             vbvBufferSize = hrd->cpbSizeValue << (hrd->cpbSizeScale + CPB_SHIFT);
@@ -781,8 +781,10 @@ void RateControl::initHRD(SPS& sps)
     // Init HRD
     HRDInfo* hrd = &sps.vuiParameters.hrdParameters;
     hrd->cbrFlag = m_isCbr;
-    if (m_param->reconfigWindowSize)
+    if (m_param->reconfigWindowSize) {
         hrd->cbrFlag = 0;
+        vbvMaxBitrate = m_param->decoderVbvMaxRate * 1000;
+    }
 
     // normalize HRD size and rate to the value / scale notation
     hrd->bitRateScale = x265_clip3(0, 15, calcScale(vbvMaxBitrate) - BR_SHIFT);
--- a/source/x265.h	Thu Dec 05 17:55:01 2019 +0530
+++ b/source/x265.h	Wed Mar 18 18:51:39 2020 +0530
@@ -1905,6 +1905,9 @@ typedef struct x265_param
 
     /* Edge variance threshold for quad tree establishment. */
     float    edgeVarThreshold;
+
+    /* Maxrate that could be signaled to the decoder. Default 0. API only. */
+    int      decoderVbvMaxRate;
 } x265_param;
 
 /* x265_param_alloc: