<div dir="ltr">Ping^2</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Dec 1, 2023 at 10:12 AM Damiano Galassi <<a href="mailto:damiog@gmail.com">damiog@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">---<br>
source/common/frame.cpp | 5 +++<br>
source/common/param.cpp | 65 ++++++++++++++++++++--------------<br>
source/encoder/api.cpp | 3 +-<br>
source/encoder/encoder.cpp | 27 +++++++-------<br>
source/encoder/framefilter.cpp | 8 ++---<br>
source/encoder/slicetype.cpp | 6 ++++<br>
6 files changed, 67 insertions(+), 47 deletions(-)<br>
<br>
diff --git a/source/common/frame.cpp b/source/common/frame.cpp<br>
index ae3773e83..74580cc54 100644<br>
--- a/source/common/frame.cpp<br>
+++ b/source/common/frame.cpp<br>
@@ -302,6 +302,11 @@ void Frame::destroy()<br>
delete[] m_userSEI.payloads;<br>
}<br>
<br>
+ if (m_rpu.payloadSize)<br>
+ {<br>
+ delete[] m_rpu.payload;<br>
+ }<br>
+<br>
if (m_ctuInfo)<br>
{<br>
uint32_t widthInCU = (m_param->sourceWidth + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;<br>
diff --git a/source/common/param.cpp b/source/common/param.cpp<br>
index 1a4df4cdc..e189b390b 100755<br>
--- a/source/common/param.cpp<br>
+++ b/source/common/param.cpp<br>
@@ -102,6 +102,19 @@ x265_param *x265_param_alloc()<br>
<br>
void x265_param_free(x265_param* p)<br>
{<br>
+ /* release string arguments that were strdup'd */<br>
+ free((char*)p->rc.lambdaFileName);<br>
+ free((char*)p->rc.statFileName);<br>
+ free((char*)p->rc.sharedMemName);<br>
+ free((char*)p->analysisReuseFileName);<br>
+ free((char*)p->scalingLists);<br>
+ free((char*)p->csvfn);<br>
+ free((char*)p->numaPools);<br>
+ free((char*)p->masteringDisplayColorVolume);<br>
+ free((char*)p->toneMapFile);<br>
+ free((char*)p->analysisSave);<br>
+ free((char*)p->analysisLoad);<br>
+ free((char*)p->videoSignalTypePreset);<br>
x265_zone_free(p);<br>
#ifdef SVT_HEVC<br>
x265_free(p->svtHevcParam);<br>
@@ -2554,12 +2567,24 @@ bool parseMaskingStrength(x265_param* p, const char* value)<br>
return bError;<br>
}<br>
<br>
+void copy_str(const char **dst, const char *src)<br>
+{<br>
+ if (*dst)<br>
+ {<br>
+ free((void *)*dst);<br>
+ *dst = NULL;<br>
+ }<br>
+ if (src)<br>
+ {<br>
+ *dst = strdup(src);<br>
+ }<br>
+}<br>
+<br>
void x265_copy_params(x265_param* dst, x265_param* src)<br>
{<br>
dst->cpuid = src->cpuid;<br>
dst->frameNumThreads = src->frameNumThreads;<br>
- if (src->numaPools) dst->numaPools = strdup(src->numaPools);<br>
- else dst->numaPools = NULL;<br>
+ copy_str(&dst->numaPools, src->numaPools);<br>
<br>
dst->bEnableWavefront = src->bEnableWavefront;<br>
dst->bDistributeModeAnalysis = src->bDistributeModeAnalysis;<br>
@@ -2569,8 +2594,7 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>
dst->bEnableSsim = src->bEnableSsim;<br>
dst->logLevel = src->logLevel;<br>
dst->csvLogLevel = src->csvLogLevel;<br>
- if (src->csvfn) dst->csvfn = strdup(src->csvfn);<br>
- else dst->csvfn = NULL;<br>
+ copy_str(&dst->csvfn, src->csvfn);<br>
dst->internalBitDepth = src->internalBitDepth;<br>
dst->sourceBitDepth = src->sourceBitDepth;<br>
dst->internalCsp = src->internalCsp;<br>
@@ -2619,8 +2643,7 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>
dst->bEnableTransformSkip = src->bEnableTransformSkip;<br>
dst->noiseReductionInter = src->noiseReductionInter;<br>
dst->noiseReductionIntra = src->noiseReductionIntra;<br>
- if (src->scalingLists) dst->scalingLists = strdup(src->scalingLists);<br>
- else dst->scalingLists = NULL;<br>
+ copy_str(&dst->scalingLists, src->scalingLists);<br>
dst->bEnableStrongIntraSmoothing = src->bEnableStrongIntraSmoothing;<br>
dst->bEnableConstrainedIntra = src->bEnableConstrainedIntra;<br>
dst->maxNumMergeCand = src->maxNumMergeCand;<br>
@@ -2662,8 +2685,7 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>
dst->psyRdoq = src->psyRdoq;<br>
dst->bEnableRdRefine = src->bEnableRdRefine;<br>
dst->analysisReuseMode = src->analysisReuseMode;<br>
- if (src->analysisReuseFileName) dst->analysisReuseFileName=strdup(src->analysisReuseFileName);<br>
- else dst->analysisReuseFileName = NULL;<br>
+ copy_str(&dst->analysisReuseFileName, src->analysisReuseFileName);<br>
dst->bLossless = src->bLossless;<br>
dst->cbQpOffset = src->cbQpOffset;<br>
dst->crQpOffset = src->crQpOffset;<br>
@@ -2692,10 +2714,8 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>
dst->rc.bStatWrite = src->rc.bStatWrite;<br>
dst->rc.bStatRead = src->rc.bStatRead;<br>
dst->rc.dataShareMode = src->rc.dataShareMode;<br>
- if (src->rc.statFileName) dst->rc.statFileName=strdup(src->rc.statFileName);<br>
- else dst->rc.statFileName = NULL;<br>
- if (src->rc.sharedMemName) dst->rc.sharedMemName = strdup(src->rc.sharedMemName);<br>
- else dst->rc.sharedMemName = NULL;<br>
+ copy_str(&dst->rc.statFileName, src->rc.statFileName);<br>
+ copy_str(&dst->rc.sharedMemName, src->rc.sharedMemName);<br>
dst->rc.qblur = src->rc.qblur;<br>
dst->rc.complexityBlur = src->rc.complexityBlur;<br>
dst->rc.bEnableSlowFirstPass = src->rc.bEnableSlowFirstPass;<br>
@@ -2729,8 +2749,7 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>
else<br>
dst->rc.zones = NULL;<br>
<br>
- if (src->rc.lambdaFileName) dst->rc.lambdaFileName = strdup(src->rc.lambdaFileName);<br>
- else dst->rc.lambdaFileName = NULL;<br>
+ copy_str(&dst->rc.lambdaFileName, src->rc.lambdaFileName);<br>
dst->rc.bStrictCbr = src->rc.bStrictCbr;<br>
dst->rc.qgSize = src->rc.qgSize;<br>
dst->rc.bEnableGrain = src->rc.bEnableGrain;<br>
@@ -2761,8 +2780,7 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>
dst->vui.defDispWinRightOffset = src->vui.defDispWinRightOffset;<br>
dst->vui.defDispWinTopOffset = src->vui.defDispWinTopOffset;<br>
<br>
- if (src->masteringDisplayColorVolume) dst->masteringDisplayColorVolume=strdup( src->masteringDisplayColorVolume);<br>
- else dst->masteringDisplayColorVolume = NULL;<br>
+ copy_str(&dst->masteringDisplayColorVolume, src->masteringDisplayColorVolume);<br>
dst->maxLuma = src->maxLuma;<br>
dst->minLuma = src->minLuma;<br>
dst->bEmitCLL = src->bEmitCLL;<br>
@@ -2791,8 +2809,7 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>
dst->analysisSaveReuseLevel = src->analysisSaveReuseLevel;<br>
dst->analysisLoadReuseLevel = src->analysisLoadReuseLevel;<br>
dst->bLimitSAO = src->bLimitSAO;<br>
- if (src->toneMapFile) dst->toneMapFile = strdup(src->toneMapFile);<br>
- else dst->toneMapFile = NULL;<br>
+ copy_str(&dst->toneMapFile, src->toneMapFile);<br>
dst->bDhdr10opt = src->bDhdr10opt;<br>
dst->bCTUInfo = src->bCTUInfo;<br>
dst->bUseRcStats = src->bUseRcStats;<br>
@@ -2814,10 +2831,8 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>
dst->vbvEndFrameAdjust = src->vbvEndFrameAdjust;<br>
dst->bAnalysisType = src->bAnalysisType;<br>
dst->bCopyPicToFrame = src->bCopyPicToFrame;<br>
- if (src->analysisSave) dst->analysisSave=strdup(src->analysisSave);<br>
- else dst->analysisSave = NULL;<br>
- if (src->analysisLoad) dst->analysisLoad=strdup(src->analysisLoad);<br>
- else dst->analysisLoad = NULL;<br>
+ copy_str(&dst->analysisSave, src->analysisSave);<br>
+ copy_str(&dst->analysisLoad, src->analysisLoad);<br>
dst->gopLookahead = src->gopLookahead;<br>
dst->radl = src->radl;<br>
dst->selectiveSAO = src->selectiveSAO;<br>
@@ -2827,8 +2842,7 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>
dst->bSingleSeiNal = src->bSingleSeiNal;<br>
dst->chunkStart = src->chunkStart;<br>
dst->chunkEnd = src->chunkEnd;<br>
- if (src->naluFile) dst->naluFile=strdup(src->naluFile);<br>
- else dst->naluFile = NULL;<br>
+ copy_str(&dst->naluFile, src->naluFile);<br>
dst->scaleFactor = src->scaleFactor;<br>
dst->ctuDistortionRefine = src->ctuDistortionRefine;<br>
dst->bEnableHRDConcatFlag = src->bEnableHRDConcatFlag;<br>
@@ -2854,8 +2868,7 @@ void x265_copy_params(x265_param* dst, x265_param* src)<br>
dst->confWinBottomOffset = src->confWinBottomOffset;<br>
dst->bliveVBV2pass = src->bliveVBV2pass;<br>
<br>
- if (src->videoSignalTypePreset) dst->videoSignalTypePreset = strdup(src->videoSignalTypePreset);<br>
- else dst->videoSignalTypePreset = NULL;<br>
+ copy_str(&dst->videoSignalTypePreset, src->videoSignalTypePreset);<br>
#ifdef SVT_HEVC<br>
memcpy(dst->svtHevcParam, src->svtHevcParam, sizeof(EB_H265_ENC_CONFIGURATION));<br>
#endif<br>
diff --git a/source/encoder/api.cpp b/source/encoder/api.cpp<br>
index 15b898a3c..6ad4ea590 100644<br>
--- a/source/encoder/api.cpp<br>
+++ b/source/encoder/api.cpp<br>
@@ -205,11 +205,12 @@ x265_encoder *x265_encoder_open(x265_param *p)<br>
}<br>
}<br>
<br>
- memcpy(zoneParam, param, sizeof(x265_param));<br>
+ x265_copy_params(zoneParam, param);<br>
for (int i = 0; i < param->rc.zonefileCount; i++)<br>
{<br>
encoder->configureZone(zoneParam, param->rc.zones[i].zoneParam);<br>
}<br>
+ PARAM_NS::x265_param_free(zoneParam);<br>
<br>
/* Try to open CSV file handle */<br>
if (encoder->m_param->csvfn)<br>
diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp<br>
index 8ec01bebe..6e497c5aa 100644<br>
--- a/source/encoder/encoder.cpp<br>
+++ b/source/encoder/encoder.cpp<br>
@@ -973,18 +973,6 @@ void Encoder::destroy()<br>
if (m_param->csvfpt)<br>
fclose(m_param->csvfpt);<br>
/* release string arguments that were strdup'd */<br>
- free((char*)m_param->rc.lambdaFileName);<br>
- free((char*)m_param->rc.statFileName);<br>
- free((char*)m_param->rc.sharedMemName);<br>
- free((char*)m_param->analysisReuseFileName);<br>
- free((char*)m_param->scalingLists);<br>
- free((char*)m_param->csvfn);<br>
- free((char*)m_param->numaPools);<br>
- free((char*)m_param->masteringDisplayColorVolume);<br>
- free((char*)m_param->toneMapFile);<br>
- free((char*)m_param->analysisSave);<br>
- free((char*)m_param->analysisLoad);<br>
- free((char*)m_param->videoSignalTypePreset);<br>
PARAM_NS::x265_param_free(m_param);<br>
}<br>
}<br>
@@ -1673,11 +1661,20 @@ int Encoder::encode(const x265_picture* pic_in, x265_picture* pic_out)<br>
<br>
copyUserSEIMessages(inFrame, inputPic);<br>
<br>
- /*Copy Dolby Vision RPU from inputPic to frame*/<br>
+ /* Copy Dolby Vision RPU from inputPic to frame. */<br>
+ if (inFrame->m_rpu.payload && inFrame->m_rpu.payloadSize < inputPic->rpu.payloadSize)<br>
+ {<br>
+ delete[] inFrame->m_rpu.payload;<br>
+ inFrame->m_rpu.payload = NULL;<br>
+ }<br>
+<br>
if (inputPic->rpu.payloadSize)<br>
{<br>
+ if (inFrame->m_rpu.payload == NULL)<br>
+ {<br>
+ inFrame->m_rpu.payload = new uint8_t[inputPic->rpu.payloadSize];<br>
+ }<br>
inFrame->m_rpu.payloadSize = inputPic->rpu.payloadSize;<br>
- inFrame->m_rpu.payload = new uint8_t[inputPic->rpu.payloadSize];<br>
memcpy(inFrame->m_rpu.payload, inputPic->rpu.payload, inputPic->rpu.payloadSize);<br>
}<br>
<br>
@@ -3513,7 +3510,7 @@ void Encoder::configureZone(x265_param *p, x265_param *zone)<br>
}<br>
p->radl = zone->radl;<br>
}<br>
- memcpy(zone, p, sizeof(x265_param));<br>
+ x265_copy_params(zone, p);<br>
}<br>
<br>
void Encoder::configureDolbyVisionParams(x265_param* p)<br>
diff --git a/source/encoder/framefilter.cpp b/source/encoder/framefilter.cpp<br>
index 8a09f5b51..cf83930b7 100644<br>
--- a/source/encoder/framefilter.cpp<br>
+++ b/source/encoder/framefilter.cpp<br>
@@ -162,11 +162,9 @@ void FrameFilter::destroy()<br>
<br>
if (m_parallelFilter)<br>
{<br>
- if (m_useSao)<br>
- {<br>
- for(int row = 0; row < m_numRows; row++)<br>
- m_parallelFilter[row].m_sao.destroy((row == 0 ? 1 : 0));<br>
- }<br>
+<br>
+ for(int row = 0; row < m_numRows; row++)<br>
+ m_parallelFilter[row].m_sao.destroy((row == 0 ? 1 : 0));<br>
<br>
delete[] m_parallelFilter;<br>
m_parallelFilter = NULL;<br>
diff --git a/source/encoder/slicetype.cpp b/source/encoder/slicetype.cpp<br>
index caf4cbf29..77e6cb96e 100644<br>
--- a/source/encoder/slicetype.cpp<br>
+++ b/source/encoder/slicetype.cpp<br>
@@ -1165,6 +1165,12 @@ void Lookahead::destroy()<br>
delete curFrame;<br>
}<br>
<br>
+ X265_FREE(m_accHistDiffRunningAvgCb[0]);<br>
+ X265_FREE(m_accHistDiffRunningAvgCb);<br>
+ X265_FREE(m_accHistDiffRunningAvgCr[0]);<br>
+ X265_FREE(m_accHistDiffRunningAvgCr);<br>
+ X265_FREE(m_accHistDiffRunningAvg[0]);<br>
+ X265_FREE(m_accHistDiffRunningAvg);<br>
X265_FREE(m_scratch);<br>
delete [] m_tld;<br>
if (m_param->lookaheadThreads > 0)<br>
-- <br>
2.39.3 (Apple Git-145)<br>
<br>
</blockquote></div>