[x265] [PATCH] zone: Fix memory handling for zones
# HG changeset patch # User Pooja Venkatesan # 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.cppTue Feb 19 20:20:35 2019 +0530 +++ b/source/encoder/api.cppFri 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(, 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.cppTue Feb 19 20:20:35 2019 +0530 +++ b/source/encoder/encoder.cppFri 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
[x265] [PATCH]Fix for zonefile feature Crash
# HG changeset patch # User Dinesh # Date 1551246140 -19800 # Wed Feb 27 11:12:20 2019 +0530 # Node ID c9bc9aef4cde7b812fd97b8eac7a204904aa02ad # Parent 31ab7e09a3b5b15ffcc532826d4dd5d37e611483 Zone: fix for encoder crash diff -r 31ab7e09a3b5 -r c9bc9aef4cde source/common/param.cpp --- a/source/common/param.cpp Tue Feb 26 13:52:24 2019 +0530 +++ b/source/common/param.cpp Wed Feb 27 11:12:20 2019 +0530 @@ -94,6 +94,7 @@ x265_param *x265_param_alloc() { x265_param* param = (x265_param*)x265_malloc(sizeof(x265_param)); + param->rc.zones = (x265_zone*)x265_malloc(sizeof(x265_zone)); #ifdef SVT_HEVC param->svtHevcParam = (EB_H265_ENC_CONFIGURATION*)x265_malloc(sizeof(EB_H265_ENC_CONFIGURATION)); #endif @@ -102,6 +103,7 @@ void x265_param_free(x265_param* p) { + x265_free(p->rc.zones); #ifdef SVT_HEVC x265_free(p->svtHevcParam); #endif @@ -2246,11 +2248,7 @@ if (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; + memcpy(dst->rc.zones, src->rc.zones, sizeof(x265_zone)); } else dst->rc.zones = NULL; diff -r 31ab7e09a3b5 -r c9bc9aef4cde source/encoder/api.cpp --- a/source/encoder/api.cpp Tue Feb 26 13:52:24 2019 +0530 +++ b/source/encoder/api.cpp Wed Feb 27 11:12:20 2019 +0530 @@ -94,7 +94,7 @@ Encoder* encoder = NULL; x265_param* param = PARAM_NS::x265_param_alloc(); -x265_param* latestParam = PARAM_NS::x265_param_alloc(); + x265_param* latestParam = PARAM_NS::x265_param_alloc(); x265_param* zoneParam = PARAM_NS::x265_param_alloc(); if (!param || !latestParam) goto fail; @@ -177,7 +177,7 @@ encoder->create(); -memcpy(zoneParam, param, sizeof(x265_param)); + x265_copy_params(zoneParam, param); for (int i = 0; i < param->rc.zonefileCount; i++) { encoder->configureZone(zoneParam, param->rc.zones[i].zoneParam); @@ -200,11 +200,11 @@ goto fail; x265_print_params(param); -return encoder; + return encoder; fail: delete encoder; -PARAM_NS::x265_param_free(param); + PARAM_NS::x265_param_free(param); PARAM_NS::x265_param_free(latestParam); return NULL; } @@ -287,12 +287,13 @@ bool isReconfigureRc = encoder->isReconfigureRc(encoder->m_latestParam, param_in); if ((encoder->m_reconfigure && !isReconfigureRc) || (encoder->m_reconfigureRc && isReconfigureRc)) /* Reconfigure in progress */ return 1; -x265_copy_params(, encoder->m_latestParam); + + memcpy(, encoder->m_latestParam, sizeof(x265_param)); int ret = encoder->reconfigureParam(encoder->m_latestParam, param_in); if (ret) { /* reconfigure failed, recover saved param set */ -x265_copy_params(encoder->m_latestParam, ); + memcpy(encoder->m_latestParam, , sizeof(x265_param)); ret = -1; } else diff -r 31ab7e09a3b5 -r c9bc9aef4cde source/encoder/encoder.cpp --- a/source/encoder/encoder.cpp Tue Feb 26 13:52:24 2019 +0530 +++ b/source/encoder/encoder.cpp Wed Feb 27 11:12:20 2019 +0530 @@ -850,7 +850,10 @@ free((char*)m_param->toneMapFile); free((char*)m_param->analysisSave); free((char*)m_param->analysisLoad); -PARAM_NS::x265_param_free(m_param); +#ifdef SVT_HEVC + x265_free(m_param->svtHevcParam); +#endif + x265_free(m_param); } } Zone.patch Description: Binary data ___ x265-devel mailing list x265-devel@videolan.org https://mailman.videolan.org/listinfo/x265-devel