<div dir="ltr"><div dir="ltr">On Fri, Mar 1, 2019 at 5:21 PM <<a href="mailto:pooja@multicorewareinc.com">pooja@multicorewareinc.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"># HG changeset patch<br>
# User Pooja Venkatesan <<a href="mailto:pooja@multicorewareinc.com" target="_blank">pooja@multicorewareinc.com</a>><br>
# Date 1551424899 -19800<br>
# Fri Mar 01 12:51:39 2019 +0530<br>
# Node ID b758e88462f0110207db6e3a3eaf69e7cfd130a3<br>
# Parent cb3e172a5f51c6a4bf8adb7953fe53277f5a1979<br>
zone: Fix memory handling for zones<br>
<br>
This patch does the following:<br>
Allocate and free memory for zones<br>
Copy of zone and zone params<br></blockquote><div><br></div><div>Patch missed out on increasing build # due to API change.</div><div>Added the fix, and pushed patch to default branch.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
diff -r cb3e172a5f51 -r b758e88462f0 source/common/param.cpp<br>
--- a/source/common/param.cpp Tue Feb 19 20:20:35 2019 +0530<br>
+++ b/source/common/param.cpp Fri Mar 01 12:51:39 2019 +0530<br>
@@ -102,6 +102,7 @@<br>
<br>
void x265_param_free(x265_param* p)<br>
{<br>
+ x265_zone_free(p);<br>
#ifdef SVT_HEVC<br>
x265_free(p->svtHevcParam);<br>
#endif<br>
@@ -2240,13 +2241,24 @@<br>
dst->rc.zoneCount = src->rc.zoneCount;<br>
dst->rc.zonefileCount = src->rc.zonefileCount;<br>
<br>
- if (src->rc.zones)<br>
+ if (src->rc.zonefileCount && src->rc.zones)<br>
{<br>
- dst->rc.zones->startFrame = src->rc.zones->startFrame;<br>
- dst->rc.zones->endFrame = src->rc.zones->endFrame;<br>
- dst->rc.zones->bForceQp = src->rc.zones->bForceQp;<br>
- dst->rc.zones->qp = src->rc.zones->qp;<br>
- dst->rc.zones->bitrateFactor = src->rc.zones->bitrateFactor;<br>
+ for (int i = 0; i < src->rc.zonefileCount; i++)<br>
+ {<br>
+ dst->rc.zones[i].startFrame = src->rc.zones[i].startFrame;<br>
+ memcpy(dst->rc.zones[i].zoneParam, src->rc.zones[i].zoneParam, sizeof(x265_param));<br>
+ }<br>
+ }<br>
+ else if (src->rc.zoneCount && src->rc.zones)<br>
+ {<br>
+ for (int i = 0; i < src->rc.zoneCount; i++)<br>
+ {<br>
+ dst->rc.zones[i].startFrame = src->rc.zones[i].startFrame;<br>
+ dst->rc.zones[i].endFrame = src->rc.zones[i].endFrame;<br>
+ dst->rc.zones[i].bForceQp = src->rc.zones[i].bForceQp;<br>
+ dst->rc.zones[i].qp = src->rc.zones[i].qp;<br>
+ dst->rc.zones[i].bitrateFactor = src->rc.zones[i].bitrateFactor;<br>
+ }<br>
}<br>
else<br>
dst->rc.zones = NULL;<br>
diff -r cb3e172a5f51 -r b758e88462f0 source/encoder/api.cpp<br>
--- a/source/encoder/api.cpp Tue Feb 19 20:20:35 2019 +0530<br>
+++ b/source/encoder/api.cpp Fri Mar 01 12:51:39 2019 +0530<br>
@@ -98,6 +98,12 @@<br>
x265_param* zoneParam = PARAM_NS::x265_param_alloc();<br>
if (!param || !latestParam)<br>
goto fail;<br>
+ if (p->rc.zoneCount || p->rc.zonefileCount)<br>
+ {<br>
+ int zoneCount = p->rc.zonefileCount ? p->rc.zonefileCount : p->rc.zoneCount;<br>
+ param->rc.zones = x265_zone_alloc(zoneCount, p->rc.zonefileCount ? true : false);<br>
+ latestParam->rc.zones = x265_zone_alloc(zoneCount, p->rc.zonefileCount ? true : false);<br>
+ }<br>
<br>
x265_copy_params(param, p);<br>
x265_log(param, X265_LOG_INFO, "HEVC encoder version %s\n", PFX(version_str));<br>
@@ -287,6 +293,11 @@<br>
bool isReconfigureRc = encoder->isReconfigureRc(encoder->m_latestParam, param_in);<br>
if ((encoder->m_reconfigure && !isReconfigureRc) || (encoder->m_reconfigureRc && isReconfigureRc)) /* Reconfigure in progress */<br>
return 1;<br>
+ if (encoder->m_latestParam->rc.zoneCount || encoder->m_latestParam->rc.zonefileCount)<br>
+ {<br>
+ int zoneCount = encoder->m_latestParam->rc.zonefileCount ? encoder->m_latestParam->rc.zonefileCount : encoder->m_latestParam->rc.zoneCount;<br>
+ save.rc.zones = x265_zone_alloc(zoneCount, encoder->m_latestParam->rc.zonefileCount ? true : false);<br>
+ }<br>
x265_copy_params(&save, encoder->m_latestParam);<br>
int ret = encoder->reconfigureParam(encoder->m_latestParam, param_in);<br>
if (ret)<br>
@@ -922,6 +933,26 @@<br>
return x265_free(p);<br>
}<br>
<br>
+x265_zone *x265_zone_alloc(int zoneCount, bool isZoneFile)<br>
+{<br>
+ x265_zone* zone = (x265_zone*)x265_malloc(sizeof(x265_zone) * zoneCount);<br>
+ if (isZoneFile) {<br>
+ for (int i = 0; i < zoneCount; i++)<br>
+ zone[i].zoneParam = (x265_param*)x265_malloc(sizeof(x265_param));<br>
+ }<br>
+ return zone;<br>
+}<br>
+<br>
+void x265_zone_free(x265_param *param)<br>
+{<br>
+ if (param->rc.zonefileCount) {<br>
+ for (int i = 0; i < param->rc.zonefileCount; i++)<br>
+ x265_free(param->rc.zones[i].zoneParam);<br>
+ }<br>
+ if (param->rc.zoneCount || param->rc.zonefileCount)<br>
+ x265_free(param->rc.zones);<br>
+}<br>
+<br>
static const x265_api libapi =<br>
{<br>
X265_MAJOR_VERSION,<br>
diff -r cb3e172a5f51 -r b758e88462f0 source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp Tue Feb 19 20:20:35 2019 +0530<br>
+++ b/source/encoder/encoder.cpp Fri Mar 01 12:51:39 2019 +0530<br>
@@ -3356,6 +3356,12 @@<br>
if (p->dolbyProfile) // Default disabled.<br>
configureDolbyVisionParams(p);<br>
<br>
+ if (p->rc.zonefileCount && p->rc.zoneCount)<br>
+ {<br>
+ p->rc.zoneCount = 0;<br>
+ x265_log(p, X265_LOG_WARNING, "Only zone or zonefile can be used. Enabling only zonefile\n");<br>
+ }<br>
+<br>
if (m_param->rc.zonefileCount && p->bOpenGOP)<br>
{<br>
p->bOpenGOP = 0;<br>
diff -r cb3e172a5f51 -r b758e88462f0 source/x265.h<br>
--- a/source/x265.h Tue Feb 19 20:20:35 2019 +0530<br>
+++ b/source/x265.h Fri Mar 01 12:51:39 2019 +0530<br>
@@ -1798,6 +1798,10 @@<br>
#define X265_PARAM_BAD_VALUE (-2)<br>
int x265_param_parse(x265_param *p, const char *name, const char *value);<br>
<br>
+x265_zone *x265_zone_alloc(int zoneCount, bool isZoneFile);<br>
+<br>
+void x265_zone_free(x265_param *param);<br>
+<br>
int x265_zone_param_parse(x265_param* p, const char* name, const char* value);<br>
<br>
static const char * const x265_profile_names[] = {<br>
_______________________________________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org" target="_blank">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/listinfo/x265-devel</a><br>
</blockquote></div></div>