[x265] [PATCH] zone: Fix memory handling for zones

pooja at multicorewareinc.com pooja at multicorewareinc.com
Fri Mar 1 12:50:44 CET 2019


# HG changeset patch
# User Pooja Venkatesan <pooja at multicorewareinc.com>
# Date 1551424899 -19800
#      Fri Mar 01 12:51:39 2019 +0530
# Node ID b758e88462f0110207db6e3a3eaf69e7cfd130a3
# Parent  cb3e172a5f51c6a4bf8adb7953fe53277f5a1979
zone: Fix memory handling for zones

This patch does the following:
Allocate and free memory for zones
Copy of zone and zone params

diff -r cb3e172a5f51 -r b758e88462f0 source/common/param.cpp
--- a/source/common/param.cpp	Tue Feb 19 20:20:35 2019 +0530
+++ b/source/common/param.cpp	Fri Mar 01 12:51:39 2019 +0530
@@ -102,6 +102,7 @@
 
 void x265_param_free(x265_param* p)
 {
+    x265_zone_free(p);
 #ifdef SVT_HEVC
      x265_free(p->svtHevcParam);
 #endif
@@ -2240,13 +2241,24 @@
     dst->rc.zoneCount = src->rc.zoneCount;
     dst->rc.zonefileCount = src->rc.zonefileCount;
 
-    if (src->rc.zones)
+    if (src->rc.zonefileCount && src->rc.zones)
     {
-        dst->rc.zones->startFrame = src->rc.zones->startFrame;
-        dst->rc.zones->endFrame = src->rc.zones->endFrame;
-        dst->rc.zones->bForceQp = src->rc.zones->bForceQp;
-        dst->rc.zones->qp = src->rc.zones->qp;
-        dst->rc.zones->bitrateFactor = src->rc.zones->bitrateFactor;
+        for (int i = 0; i < src->rc.zonefileCount; i++)
+        {
+            dst->rc.zones[i].startFrame = src->rc.zones[i].startFrame;
+            memcpy(dst->rc.zones[i].zoneParam, src->rc.zones[i].zoneParam, sizeof(x265_param));
+        }
+    }
+    else if (src->rc.zoneCount && src->rc.zones)
+    {
+        for (int i = 0; i < src->rc.zoneCount; i++)
+        {
+            dst->rc.zones[i].startFrame = src->rc.zones[i].startFrame;
+            dst->rc.zones[i].endFrame = src->rc.zones[i].endFrame;
+            dst->rc.zones[i].bForceQp = src->rc.zones[i].bForceQp;
+            dst->rc.zones[i].qp = src->rc.zones[i].qp;
+            dst->rc.zones[i].bitrateFactor = src->rc.zones[i].bitrateFactor;
+        }
     }
     else
         dst->rc.zones = NULL;
diff -r cb3e172a5f51 -r b758e88462f0 source/encoder/api.cpp
--- a/source/encoder/api.cpp	Tue Feb 19 20:20:35 2019 +0530
+++ b/source/encoder/api.cpp	Fri Mar 01 12:51:39 2019 +0530
@@ -98,6 +98,12 @@
     x265_param* zoneParam = PARAM_NS::x265_param_alloc();
     if (!param || !latestParam)
         goto fail;
+    if (p->rc.zoneCount || p->rc.zonefileCount)
+    {
+        int zoneCount = p->rc.zonefileCount ? p->rc.zonefileCount : p->rc.zoneCount;
+        param->rc.zones = x265_zone_alloc(zoneCount, p->rc.zonefileCount ? true : false);
+        latestParam->rc.zones = x265_zone_alloc(zoneCount, p->rc.zonefileCount ? true : false);
+    }
 
     x265_copy_params(param, p);
     x265_log(param, X265_LOG_INFO, "HEVC encoder version %s\n", PFX(version_str));
@@ -287,6 +293,11 @@
     bool isReconfigureRc = encoder->isReconfigureRc(encoder->m_latestParam, param_in);
     if ((encoder->m_reconfigure && !isReconfigureRc) || (encoder->m_reconfigureRc && isReconfigureRc)) /* Reconfigure in progress */
         return 1;
+    if (encoder->m_latestParam->rc.zoneCount || encoder->m_latestParam->rc.zonefileCount)
+    {
+        int zoneCount = encoder->m_latestParam->rc.zonefileCount ? encoder->m_latestParam->rc.zonefileCount : encoder->m_latestParam->rc.zoneCount;
+        save.rc.zones = x265_zone_alloc(zoneCount, encoder->m_latestParam->rc.zonefileCount ? true : false);
+    }
     x265_copy_params(&save, encoder->m_latestParam);
     int ret = encoder->reconfigureParam(encoder->m_latestParam, param_in);
     if (ret)
@@ -922,6 +933,26 @@
     return x265_free(p);
 }
 
+x265_zone *x265_zone_alloc(int zoneCount, bool isZoneFile)
+{
+    x265_zone* zone = (x265_zone*)x265_malloc(sizeof(x265_zone) * zoneCount);
+    if (isZoneFile) {
+        for (int i = 0; i < zoneCount; i++)
+            zone[i].zoneParam = (x265_param*)x265_malloc(sizeof(x265_param));
+    }
+    return zone;
+}
+
+void x265_zone_free(x265_param *param)
+{
+    if (param->rc.zonefileCount) {
+        for (int i = 0; i < param->rc.zonefileCount; i++)
+            x265_free(param->rc.zones[i].zoneParam);
+    }
+    if (param->rc.zoneCount || param->rc.zonefileCount)
+        x265_free(param->rc.zones);
+}
+
 static const x265_api libapi =
 {
     X265_MAJOR_VERSION,
diff -r cb3e172a5f51 -r b758e88462f0 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Tue Feb 19 20:20:35 2019 +0530
+++ b/source/encoder/encoder.cpp	Fri Mar 01 12:51:39 2019 +0530
@@ -3356,6 +3356,12 @@
     if (p->dolbyProfile)     // Default disabled.
         configureDolbyVisionParams(p);
 
+    if (p->rc.zonefileCount && p->rc.zoneCount)
+    {
+        p->rc.zoneCount = 0;
+        x265_log(p, X265_LOG_WARNING, "Only zone or zonefile can be used. Enabling only zonefile\n");
+    }
+
     if (m_param->rc.zonefileCount && p->bOpenGOP)
     {
         p->bOpenGOP = 0;
diff -r cb3e172a5f51 -r b758e88462f0 source/x265.h
--- a/source/x265.h	Tue Feb 19 20:20:35 2019 +0530
+++ b/source/x265.h	Fri Mar 01 12:51:39 2019 +0530
@@ -1798,6 +1798,10 @@
 #define X265_PARAM_BAD_VALUE (-2)
 int x265_param_parse(x265_param *p, const char *name, const char *value);
 
+x265_zone *x265_zone_alloc(int zoneCount, bool isZoneFile);
+
+void x265_zone_free(x265_param *param);
+
 int x265_zone_param_parse(x265_param* p, const char* name, const char* value);
 
 static const char * const x265_profile_names[] = {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: x265.patch
Type: text/x-patch
Size: 5365 bytes
Desc: not available
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20190301/3a7b3dae/attachment.bin>


More information about the x265-devel mailing list