<div dir="ltr">Please ignore this patch, shared to vlc-devel instead x265-devel by mistake.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Aug 31, 2020 at 3:26 PM Mahesh Pittala <<a href="mailto:mahesh@multicorewareinc.com">mahesh@multicorewareinc.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">From 812cccaa864da47dcf9567dccb81c9fef220c626 Mon Sep 17 00:00:00 2001<br>From: maheshpittala <<a href="mailto:mahesh@multicorewareinc.com" target="_blank">mahesh@multicorewareinc.com</a>><br>Date: Sat, 1 Aug 2020 14:52:48 +0530<br>Subject: [PATCH 1/1] Add support for reusing cutree offsets in all reuse<br> levels 1,2,5<br><br>Depth information required to load cutree offsets so writing depth information<br>but not using in reuse level 1<br>---<br> source/abrEncApp.cpp | 23 ++--<br> source/encoder/analysis.cpp | 2 +-<br> source/encoder/api.cpp | 53 +++++---<br> source/encoder/encoder.cpp | 239 +++++++++++++++++++++---------------<br> 4 files changed, 188 insertions(+), 129 deletions(-)<br><br>diff --git a/source/abrEncApp.cpp b/source/abrEncApp.cpp<br>index fa62ebf63..e26d3adfc 100644<br>--- a/source/abrEncApp.cpp<br>+++ b/source/abrEncApp.cpp<br>@@ -330,15 +330,16 @@ namespace X265_NS {<br> <br> if (src->sliceType == X265_TYPE_IDR || src->sliceType == X265_TYPE_I)<br> {<br>- if (m_param->analysisSaveReuseLevel < 2)<br>- goto ret;<br> x265_analysis_intra_data *intraDst, *intraSrc;<br> intraDst = (x265_analysis_intra_data*)m_analysisInfo->intraData;<br> intraSrc = (x265_analysis_intra_data*)src->intraData;<br>- memcpy(intraDst->depth, intraSrc->depth, sizeof(uint8_t) * src->depthBytes);<br>- memcpy(intraDst->modes, intraSrc->modes, sizeof(uint8_t) * src->numCUsInFrame * src->numPartitions);<br>- memcpy(intraDst->partSizes, intraSrc->partSizes, sizeof(char) * src->depthBytes);<br>- memcpy(intraDst->chromaModes, intraSrc->chromaModes, sizeof(uint8_t) * src->depthBytes);<br>+ memcpy(intraDst->depth, intraSrc->depth, sizeof(uint8_t)* src->depthBytes);<br>+ if (m_param->analysisSaveReuseLevel > 1)<br>+ {<br>+ memcpy(intraDst->modes, intraSrc->modes, sizeof(uint8_t)* src->numCUsInFrame * src->numPartitions);<br>+ memcpy(intraDst->partSizes, intraSrc->partSizes, sizeof(char)* src->depthBytes);<br>+ memcpy(intraDst->chromaModes, intraSrc->chromaModes, sizeof(uint8_t)* src->depthBytes);<br>+ }<br> if (m_param->rc.cuTree)<br> memcpy(intraDst->cuQPOff, intraSrc->cuQPOff, sizeof(int8_t) * src->depthBytes);<br> }<br>@@ -347,13 +348,12 @@ namespace X265_NS {<br> bool bIntraInInter = (src->sliceType == X265_TYPE_P || m_param->bIntraInBFrames);<br> int numDir = src->sliceType == X265_TYPE_P ? 1 : 2;<br> memcpy(m_analysisInfo->wt, src->wt, sizeof(WeightParam) * 3 * numDir);<br>- if (m_param->analysisSaveReuseLevel < 2)<br>- goto ret;<br> x265_analysis_inter_data *interDst, *interSrc;<br> interDst = (x265_analysis_inter_data*)m_analysisInfo->interData;<br> interSrc = (x265_analysis_inter_data*)src->interData;<br>- memcpy(interDst->depth, interSrc->depth, sizeof(uint8_t) * src->depthBytes);<br>- memcpy(interDst->modes, interSrc->modes, sizeof(uint8_t) * src->depthBytes);<br>+ memcpy(interDst->depth, interSrc->depth, sizeof(uint8_t)* src->depthBytes);<br>+ if (m_param->analysisSaveReuseLevel > 1)<br>+ memcpy(interDst->modes, interSrc->modes, sizeof(uint8_t)* src->depthBytes);<br> if (m_param->rc.cuTree)<br> memcpy(interDst->cuQPOff, interSrc->cuQPOff, sizeof(int8_t) * src->depthBytes);<br> if (m_param->analysisSaveReuseLevel > 4)<br>@@ -378,11 +378,10 @@ namespace X265_NS {<br> }<br> }<br> }<br>- if (m_param->analysisSaveReuseLevel != 10)<br>+ if (m_param->analysisSaveReuseLevel != 10 && m_param->analysisSaveReuseLevel > 1)<br> memcpy(interDst->ref, interSrc->ref, sizeof(int32_t) * src->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir);<br> }<br> <br>-ret:<br> //increment analysis Write counter <br> m_parent->m_analysisWriteCnt[m_id].incr();<br> m_parent->m_analysisWrite[m_id][index].incr();<br>diff --git a/source/encoder/analysis.cpp b/source/encoder/analysis.cpp<br>index 157bae8cd..351d8a3c8 100644<br>--- a/source/encoder/analysis.cpp<br>+++ b/source/encoder/analysis.cpp<br>@@ -3645,7 +3645,7 @@ int Analysis::calculateQpforCuSize(const CUData& ctu, const CUGeom& cuGeom, int3<br> qp += distortionData->offset[ctu.m_cuAddr];<br> }<br> <br>- if (m_param->analysisLoadReuseLevel == 10 && m_param->rc.cuTree)<br>+ if (m_param->analysisLoadReuseLevel >= 1 && m_param->rc.cuTree)<br> {<br> int cuIdx = (ctu.m_cuAddr * ctu.m_numPartitions) + cuGeom.absPartIdx;<br> if (ctu.m_slice->m_sliceType == I_SLICE)<br>diff --git a/source/encoder/api.cpp b/source/encoder/api.cpp<br>index a986355e0..4ef3f04bc 100644<br>--- a/source/encoder/api.cpp<br>+++ b/source/encoder/api.cpp<br>@@ -813,35 +813,41 @@ void x265_alloc_analysis_data(x265_param *param, x265_analysis_data* analysis)<br> CHECKED_MALLOC_ZERO(analysis->wt, x265_weight_param, numPlanes * numDir);<br> <br> //Allocate memory for intraData pointer<br>- if ((maxReuseLevel > 1) || isMultiPassOpt)<br>+ if ((maxReuseLevel > 0) || isMultiPassOpt)<br> {<br> CHECKED_MALLOC_ZERO(intraData, x265_analysis_intra_data, 1);<br> CHECKED_MALLOC(intraData->depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br> }<br> <br>- if (maxReuseLevel > 1)<br>+ if (maxReuseLevel > 0)<br> {<br>- CHECKED_MALLOC_ZERO(intraData->modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>- CHECKED_MALLOC_ZERO(intraData->partSizes, char, analysis->numPartitions * analysis->numCUsInFrame);<br>- CHECKED_MALLOC_ZERO(intraData->chromaModes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>+ if (maxReuseLevel > 1)<br>+ {<br>+ CHECKED_MALLOC_ZERO(intraData->modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>+ CHECKED_MALLOC_ZERO(intraData->partSizes, char, analysis->numPartitions * analysis->numCUsInFrame);<br>+ CHECKED_MALLOC_ZERO(intraData->chromaModes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>+ }<br> if (param->rc.cuTree)<br> CHECKED_MALLOC_ZERO(intraData->cuQPOff, int8_t, analysis->numPartitions * analysis->numCUsInFrame);<br> }<br> analysis->intraData = intraData;<br> <br>- if ((maxReuseLevel > 1) || isMultiPassOpt)<br>+ if ((maxReuseLevel > 0) || isMultiPassOpt)<br> {<br> //Allocate memory for interData pointer based on ReuseLevels<br> CHECKED_MALLOC_ZERO(interData, x265_analysis_inter_data, 1);<br> CHECKED_MALLOC(interData->depth, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>- CHECKED_MALLOC_ZERO(interData->modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>-<br> if (param->rc.cuTree && !isMultiPassOpt)<br> CHECKED_MALLOC_ZERO(interData->cuQPOff, int8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>- CHECKED_MALLOC_ZERO(interData->mvpIdx[0], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>- CHECKED_MALLOC_ZERO(interData->mvpIdx[1], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>- CHECKED_MALLOC_ZERO(interData->mv[0], x265_analysis_MV, analysis->numPartitions * analysis->numCUsInFrame);<br>- CHECKED_MALLOC_ZERO(interData->mv[1], x265_analysis_MV, analysis->numPartitions * analysis->numCUsInFrame);<br>+<br>+ if (maxReuseLevel > 1)<br>+ {<br>+ CHECKED_MALLOC_ZERO(interData->modes, uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>+ CHECKED_MALLOC_ZERO(interData->mvpIdx[0], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>+ CHECKED_MALLOC_ZERO(interData->mvpIdx[1], uint8_t, analysis->numPartitions * analysis->numCUsInFrame);<br>+ CHECKED_MALLOC_ZERO(interData->mv[0], x265_analysis_MV, analysis->numPartitions * analysis->numCUsInFrame);<br>+ CHECKED_MALLOC_ZERO(interData->mv[1], x265_analysis_MV, analysis->numPartitions * analysis->numCUsInFrame);<br>+ }<br> }<br> <br> if (maxReuseLevel > 4)<br>@@ -915,9 +921,12 @@ void x265_free_analysis_data(x265_param *param, x265_analysis_data* analysis)<br> X265_FREE((analysis->intraData)->depth);<br> if (!isMultiPassOpt)<br> {<br>- X265_FREE((analysis->intraData)->modes);<br>- X265_FREE((analysis->intraData)->partSizes);<br>- X265_FREE((analysis->intraData)->chromaModes);<br>+ if (maxReuseLevel > 1)<br>+ {<br>+ X265_FREE((analysis->intraData)->modes);<br>+ X265_FREE((analysis->intraData)->partSizes);<br>+ X265_FREE((analysis->intraData)->chromaModes);<br>+ }<br> if (param->rc.cuTree)<br> X265_FREE((analysis->intraData)->cuQPOff);<br> }<br>@@ -929,13 +938,17 @@ void x265_free_analysis_data(x265_param *param, x265_analysis_data* analysis)<br> if (analysis->interData)<br> {<br> X265_FREE((analysis->interData)->depth);<br>- X265_FREE((analysis->interData)->modes);<br> if (!isMultiPassOpt && param->rc.cuTree)<br> X265_FREE((analysis->interData)->cuQPOff);<br>- X265_FREE((analysis->interData)->mvpIdx[0]);<br>- X265_FREE((analysis->interData)->mvpIdx[1]);<br>- X265_FREE((analysis->interData)->mv[0]);<br>- X265_FREE((analysis->interData)->mv[1]);<br>+<br>+ if (maxReuseLevel > 1)<br>+ {<br>+ X265_FREE((analysis->interData)->modes);<br>+ X265_FREE((analysis->interData)->mvpIdx[0]);<br>+ X265_FREE((analysis->interData)->mvpIdx[1]);<br>+ X265_FREE((analysis->interData)->mv[0]);<br>+ X265_FREE((analysis->interData)->mv[1]);<br>+ }<br> <br> if (maxReuseLevel > 4)<br> {<br>diff --git a/source/encoder/encoder.cpp b/source/encoder/encoder.cpp<br>index cf7bfb98d..c87feb84a 100644<br>--- a/source/encoder/encoder.cpp<br>+++ b/source/encoder/encoder.cpp<br>@@ -4448,8 +4448,6 @@ void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc, const x<br> {<br> if (m_param->bAnalysisType == HEVC_INFO)<br> return;<br>- if (m_param->analysisLoadReuseLevel < 2)<br>- return;<br> <br> uint8_t *tempBuf = NULL, *depthBuf = NULL, *modeBuf = NULL, *partSizes = NULL;<br> int8_t *cuQPBuf = NULL;<br>@@ -4462,8 +4460,11 @@ void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc, const x<br> cuQPBuf = X265_MALLOC(int8_t, depthBytes);<br> <br> X265_FREAD(depthBuf, sizeof(uint8_t), depthBytes, m_analysisFileIn, intraPic->depth);<br>- X265_FREAD(modeBuf, sizeof(uint8_t), depthBytes, m_analysisFileIn, intraPic->chromaModes);<br>- X265_FREAD(partSizes, sizeof(uint8_t), depthBytes, m_analysisFileIn, intraPic->partSizes);<br>+ if (m_param->analysisLoadReuseLevel > 1)<br>+ {<br>+ X265_FREAD(modeBuf, sizeof(uint8_t), depthBytes, m_analysisFileIn, intraPic->chromaModes);<br>+ X265_FREAD(partSizes, sizeof(uint8_t), depthBytes, m_analysisFileIn, intraPic->partSizes);<br>+ }<br> if (m_param->rc.cuTree) { X265_FREAD(cuQPBuf, sizeof(int8_t), depthBytes, m_analysisFileIn, intraPic->cuQPOff); }<br> <br> size_t count = 0;<br>@@ -4478,38 +4479,40 @@ void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc, const x<br> partSizes[d] = SIZE_2Nx2N;<br> }<br> memset(&(analysis->intraData)->depth[count], depthBuf[d], bytes);<br>- memset(&(analysis->intraData)->chromaModes[count], modeBuf[d], bytes);<br>- memset(&(analysis->intraData)->partSizes[count], partSizes[d], bytes);<br>+ if (m_param->analysisLoadReuseLevel > 1)<br>+ {<br>+ memset(&(analysis->intraData)->chromaModes[count], modeBuf[d], bytes);<br>+ memset(&(analysis->intraData)->partSizes[count], partSizes[d], bytes);<br>+ }<br> if (m_param->rc.cuTree)<br> memset(&(analysis->intraData)->cuQPOff[count], cuQPBuf[d], bytes);<br> count += bytes;<br> }<br>-<br>- if (!m_param->scaleFactor)<br>- {<br>- X265_FREAD((analysis->intraData)->modes, sizeof(uint8_t), numCUsLoad * analysis->numPartitions, m_analysisFileIn, intraPic->modes);<br>- }<br>- else<br>+ if (m_param->analysisLoadReuseLevel > 1)<br> {<br>- uint8_t *tempLumaBuf = X265_MALLOC(uint8_t, numCUsLoad * scaledNumPartition);<br>- X265_FREAD(tempLumaBuf, sizeof(uint8_t), numCUsLoad * scaledNumPartition, m_analysisFileIn, intraPic->modes);<br>- for (uint32_t ctu32Idx = 0, cnt = 0; ctu32Idx < numCUsLoad * scaledNumPartition; ctu32Idx++, cnt += factor)<br>- memset(&(analysis->intraData)->modes[cnt], tempLumaBuf[ctu32Idx], factor);<br>- X265_FREE(tempLumaBuf);<br>+ if (!m_param->scaleFactor)<br>+ {<br>+ X265_FREAD((analysis->intraData)->modes, sizeof(uint8_t), numCUsLoad * analysis->numPartitions, m_analysisFileIn, intraPic->modes);<br>+ }<br>+ else<br>+ {<br>+ uint8_t *tempLumaBuf = X265_MALLOC(uint8_t, numCUsLoad * scaledNumPartition);<br>+ X265_FREAD(tempLumaBuf, sizeof(uint8_t), numCUsLoad * scaledNumPartition, m_analysisFileIn, intraPic->modes);<br>+ for (uint32_t ctu32Idx = 0, cnt = 0; ctu32Idx < numCUsLoad * scaledNumPartition; ctu32Idx++, cnt += factor)<br>+ memset(&(analysis->intraData)->modes[cnt], tempLumaBuf[ctu32Idx], factor);<br>+ X265_FREE(tempLumaBuf);<br>+ }<br> }<br> if (m_param->rc.cuTree)<br> X265_FREE(cuQPBuf);<br> X265_FREE(tempBuf);<br> consumedBytes += frameRecordSize;<br> }<br>-<br> else<br> {<br> uint32_t numDir = analysis->sliceType == X265_TYPE_P ? 1 : 2;<br> uint32_t numPlanes = m_param->internalCsp == X265_CSP_I400 ? 1 : 3;<br> X265_FREAD((WeightParam*)analysis->wt, sizeof(WeightParam), numPlanes * numDir, m_analysisFileIn, (picIn->analysisData.wt));<br>- if (m_param->analysisLoadReuseLevel < 2)<br>- return;<br> <br> uint8_t *tempBuf = NULL, *depthBuf = NULL, *modeBuf = NULL, *partSize = NULL, *mergeFlag = NULL;<br> uint8_t *interDir = NULL, *chromaDir = NULL, *mvpIdx[2];<br>@@ -4539,9 +4542,11 @@ void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc, const x<br> cuQPBuf = X265_MALLOC(int8_t, depthBytes);<br> <br> X265_FREAD(depthBuf, sizeof(uint8_t), depthBytes, m_analysisFileIn, interPic->depth);<br>- X265_FREAD(modeBuf, sizeof(uint8_t), depthBytes, m_analysisFileIn, interPic->modes);<br>+ if (m_param->analysisLoadReuseLevel > 1)<br>+ X265_FREAD(modeBuf, sizeof(uint8_t), depthBytes, m_analysisFileIn, interPic->modes);<br> if (m_param->rc.cuTree) { X265_FREAD(cuQPBuf, sizeof(int8_t), depthBytes, m_analysisFileIn, interPic->cuQPOff); }<br> <br>+<br> if (m_param->analysisLoadReuseLevel > 4)<br> {<br> partSize = modeBuf + depthBytes;<br>@@ -4577,9 +4582,13 @@ void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc, const x<br> if (m_param->scaleFactor && modeBuf[d] == MODE_INTRA && depthBuf[d] == 0)<br> depthBuf[d] = 1;<br> memset(&(analysis->interData)->depth[count], depthBuf[d], bytes);<br>- memset(&(analysis->interData)->modes[count], modeBuf[d], bytes);<br>+<br>+ if (m_param->analysisLoadReuseLevel > 1)<br>+ memset(&(analysis->interData)->modes[count], modeBuf[d], bytes);<br>+<br> if (m_param->rc.cuTree)<br> memset(&(analysis->interData)->cuQPOff[count], cuQPBuf[d], bytes);<br>+<br> if (m_param->analysisLoadReuseLevel > 4)<br> {<br> if (m_param->scaleFactor && modeBuf[d] == MODE_INTRA && partSize[d] == SIZE_NxN)<br>@@ -4643,7 +4652,7 @@ void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc, const x<br> }<br> }<br> }<br>- else<br>+ else if (m_param->analysisLoadReuseLevel > 1)<br> X265_FREAD((analysis->interData)->ref, sizeof(int32_t), numCUsLoad * X265_MAX_PRED_MODE_PER_CTU * numDir, m_analysisFileIn, interPic->ref);<br> <br> consumedBytes += frameRecordSize;<br>@@ -4810,9 +4819,6 @@ void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc, const x<br> <br> if (analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I)<br> {<br>- if (m_param->analysisLoadReuseLevel < 2)<br>- return;<br>-<br> uint8_t *tempBuf = NULL, *depthBuf = NULL, *modeBuf = NULL, *partSizes = NULL;<br> int8_t *cuQPBuf = NULL;<br> <br>@@ -4824,8 +4830,12 @@ void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc, const x<br> cuQPBuf = X265_MALLOC(int8_t, depthBytes);<br> <br> X265_FREAD(depthBuf, sizeof(uint8_t), depthBytes, m_analysisFileIn, intraPic->depth);<br>- X265_FREAD(modeBuf, sizeof(uint8_t), depthBytes, m_analysisFileIn, intraPic->chromaModes);<br>- X265_FREAD(partSizes, sizeof(uint8_t), depthBytes, m_analysisFileIn, intraPic->partSizes);<br>+<br>+ if (m_param->analysisLoadReuseLevel > 1)<br>+ {<br>+ X265_FREAD(modeBuf, sizeof(uint8_t), depthBytes, m_analysisFileIn, intraPic->chromaModes);<br>+ X265_FREAD(partSizes, sizeof(uint8_t), depthBytes, m_analysisFileIn, intraPic->partSizes);<br>+ }<br> if (m_param->rc.cuTree) { X265_FREAD(cuQPBuf, sizeof(int8_t), depthBytes, m_analysisFileIn, intraPic->cuQPOff); }<br> <br> uint32_t count = 0;<br>@@ -4838,36 +4848,45 @@ void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc, const x<br> bytes /= 4;<br> numCTUCopied = 4;<br> }<br>- if (partSizes[d] == SIZE_NxN)<br>- partSizes[d] = SIZE_2Nx2N;<br>+ if (m_param->analysisLoadReuseLevel > 1)<br>+ {<br>+ if (partSizes[d] == SIZE_NxN)<br>+ partSizes[d] = SIZE_2Nx2N;<br>+ }<br> if ((depthBuf[d] > 1 && m_param->maxCUSize == 64) || (depthBuf[d] && m_param->maxCUSize != 64))<br> depthBuf[d]--;<br> <br> for (int numCTU = 0; numCTU < numCTUCopied; numCTU++)<br> {<br> memset(&(analysis->intraData)->depth[count], depthBuf[d], bytes);<br>- memset(&(analysis->intraData)->chromaModes[count], modeBuf[d], bytes);<br>- memset(&(analysis->intraData)->partSizes[count], partSizes[d], bytes);<br>+ if (m_param->analysisLoadReuseLevel > 1)<br>+ {<br>+ memset(&(analysis->intraData)->chromaModes[count], modeBuf[d], bytes);<br>+ memset(&(analysis->intraData)->partSizes[count], partSizes[d], bytes);<br>+ }<br> if (m_param->rc.cuTree)<br> memset(&(analysis->intraData)->cuQPOff[count], cuQPBuf[d], bytes);<br>+<br> count += bytes;<br> d += getCUIndex(&cuLoc, &count, bytes, 1);<br> }<br> }<br>-<br>- cuLoc.evenRowIndex = 0;<br>- cuLoc.oddRowIndex = m_param->num4x4Partitions * cuLoc.widthInCU;<br>- cuLoc.switchCondition = 0;<br>- uint8_t *tempLumaBuf = X265_MALLOC(uint8_t, analysis->numCUsInFrame * scaledNumPartition);<br>- X265_FREAD(tempLumaBuf, sizeof(uint8_t), analysis->numCUsInFrame * scaledNumPartition, m_analysisFileIn, intraPic->modes);<br>- uint32_t cnt = 0;<br>- for (uint32_t ctu32Idx = 0; ctu32Idx < analysis->numCUsInFrame * scaledNumPartition; ctu32Idx++)<br>+ if (m_param->analysisLoadReuseLevel > 1)<br> {<br>- memset(&(analysis->intraData)->modes[cnt], tempLumaBuf[ctu32Idx], factor);<br>- cnt += factor;<br>- ctu32Idx += getCUIndex(&cuLoc, &cnt, factor, 0);<br>+ cuLoc.evenRowIndex = 0;<br>+ cuLoc.oddRowIndex = m_param->num4x4Partitions * cuLoc.widthInCU;<br>+ cuLoc.switchCondition = 0;<br>+ uint8_t *tempLumaBuf = X265_MALLOC(uint8_t, analysis->numCUsInFrame * scaledNumPartition);<br>+ X265_FREAD(tempLumaBuf, sizeof(uint8_t), analysis->numCUsInFrame * scaledNumPartition, m_analysisFileIn, intraPic->modes);<br>+ uint32_t cnt = 0;<br>+ for (uint32_t ctu32Idx = 0; ctu32Idx < analysis->numCUsInFrame * scaledNumPartition; ctu32Idx++)<br>+ {<br>+ memset(&(analysis->intraData)->modes[cnt], tempLumaBuf[ctu32Idx], factor);<br>+ cnt += factor;<br>+ ctu32Idx += getCUIndex(&cuLoc, &cnt, factor, 0);<br>+ }<br>+ X265_FREE(tempLumaBuf);<br> }<br>- X265_FREE(tempLumaBuf);<br> if (m_param->rc.cuTree)<br> X265_FREE(cuQPBuf);<br> X265_FREE(tempBuf);<br>@@ -4879,8 +4898,6 @@ void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc, const x<br> uint32_t numDir = analysis->sliceType == X265_TYPE_P ? 1 : 2;<br> uint32_t numPlanes = m_param->internalCsp == X265_CSP_I400 ? 1 : 3;<br> X265_FREAD((WeightParam*)analysis->wt, sizeof(WeightParam), numPlanes * numDir, m_analysisFileIn, (picIn->analysisData.wt));<br>- if (m_param->analysisLoadReuseLevel < 2)<br>- return;<br> <br> uint8_t *tempBuf = NULL, *depthBuf = NULL, *modeBuf = NULL, *partSize = NULL, *mergeFlag = NULL;<br> uint8_t *interDir = NULL, *chromaDir = NULL, *mvpIdx[2];<br>@@ -4904,8 +4921,10 @@ void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc, const x<br> cuQPBuf = X265_MALLOC(int8_t, depthBytes);<br> <br> X265_FREAD(depthBuf, sizeof(uint8_t), depthBytes, m_analysisFileIn, interPic->depth);<br>- X265_FREAD(modeBuf, sizeof(uint8_t), depthBytes, m_analysisFileIn, interPic->modes);<br>+ if (m_param->analysisLoadReuseLevel > 1)<br>+ X265_FREAD(modeBuf, sizeof(uint8_t), depthBytes, m_analysisFileIn, interPic->modes);<br> if (m_param->rc.cuTree) { X265_FREAD(cuQPBuf, sizeof(int8_t), depthBytes, m_analysisFileIn, interPic->cuQPOff); }<br>+<br> if (m_param->analysisLoadReuseLevel > 4)<br> {<br> partSize = modeBuf + depthBytes;<br>@@ -4953,7 +4972,9 @@ void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc, const x<br> for (int numCTU = 0; numCTU < numCTUCopied; numCTU++)<br> {<br> memset(&(analysis->interData)->depth[count], writeDepth, bytes);<br>- memset(&(analysis->interData)->modes[count], modeBuf[d], bytes);<br>+ if (m_param->analysisLoadReuseLevel > 1)<br>+ memset(&(analysis->interData)->modes[count], modeBuf[d], bytes);<br>+<br> if (m_param->rc.cuTree)<br> memset(&(analysis->interData)->cuQPOff[count], cuQPBuf[d], bytes);<br> if (m_param->analysisLoadReuseLevel == 10 && bIntraInInter)<br>@@ -5045,7 +5066,7 @@ void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc, const x<br> X265_FREE(tempLumaBuf);<br> }<br> }<br>- else<br>+ else if (m_param->analysisLoadReuseLevel > 1)<br> X265_FREAD((analysis->interData)->ref, sizeof(int32_t), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir, m_analysisFileIn, interPic->ref);<br> <br> consumedBytes += frameRecordSize;<br>@@ -5155,6 +5176,8 @@ int Encoder::validateAnalysisData(x265_analysis_validate* saveParam, int writeFl<br> isIncompatibleReuseLevel = true;<br> else if ((loadLevel >= 2 && loadLevel <= 4) && (saveLevel < 2 || saveLevel > 6))<br> isIncompatibleReuseLevel = true;<br>+ else if (loadLevel == 1 && saveLevel < 1)<br>+ isIncompatibleReuseLevel = true;<br> else if (!saveLevel)<br> isIncompatibleReuseLevel = true;<br> <br>@@ -5167,7 +5190,7 @@ int Encoder::validateAnalysisData(x265_analysis_validate* saveParam, int writeFl<br> <br> int bcutree;<br> X265_FREAD(&bcutree, sizeof(int), 1, m_analysisFileIn, &(saveParam->cuTree));<br>- if (loadLevel == 10 && m_param->rc.cuTree && (!bcutree || saveLevel < 2))<br>+ if (loadLevel >= 1 && m_param->rc.cuTree && (!bcutree || saveLevel < 1))<br> {<br> x265_log(NULL, X265_LOG_ERROR, "Error reading cu-tree info. Disabling cutree offsets. \n");<br> m_param->rc.cuTree = 0;<br>@@ -5510,7 +5533,7 @@ void Encoder::writeAnalysisFile(x265_analysis_data* analysis, FrameData &curEncD<br> analysis->frameRecordSize += analysis->numCUsInFrame * sizeof(sse_t);<br> }<br> <br>- if (m_param->analysisSaveReuseLevel > 1)<br>+ if (m_param->analysisSaveReuseLevel > 0)<br> {<br> <br> if (analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I)<br>@@ -5529,18 +5552,21 @@ void Encoder::writeAnalysisFile(x265_analysis_data* analysis, FrameData &curEncD<br> {<br> depth = ctu->m_cuDepth[absPartIdx];<br> intraDataCTU->depth[depthBytes] = depth;<br>+ if (m_param->analysisSaveReuseLevel > 1)<br>+ {<br>+ mode = ctu->m_chromaIntraDir[absPartIdx];<br>+ intraDataCTU->chromaModes[depthBytes] = mode;<br> <br>- mode = ctu->m_chromaIntraDir[absPartIdx];<br>- intraDataCTU->chromaModes[depthBytes] = mode;<br>-<br>- partSize = ctu->m_partSize[absPartIdx];<br>- intraDataCTU->partSizes[depthBytes] = partSize;<br>-<br>+ partSize = ctu->m_partSize[absPartIdx];<br>+ intraDataCTU->partSizes[depthBytes] = partSize;<br>+ }<br> if (m_param->rc.cuTree)<br> intraDataCTU->cuQPOff[depthBytes] = (int8_t)(ctu->m_qpAnalysis[absPartIdx] - baseQP);<br>+<br> absPartIdx += ctu->m_numPartitions >> (depth * 2);<br> }<br>- memcpy(&intraDataCTU->modes[ctu->m_cuAddr * ctu->m_numPartitions], ctu->m_lumaIntraDir, sizeof(uint8_t)* ctu->m_numPartitions);<br>+ if (m_param->analysisSaveReuseLevel > 1)<br>+ memcpy(&intraDataCTU->modes[ctu->m_cuAddr * ctu->m_numPartitions], ctu->m_lumaIntraDir, sizeof(uint8_t)* ctu->m_numPartitions);<br> }<br> }<br> else<br>@@ -5561,12 +5587,14 @@ void Encoder::writeAnalysisFile(x265_analysis_data* analysis, FrameData &curEncD<br> {<br> depth = ctu->m_cuDepth[absPartIdx];<br> interDataCTU->depth[depthBytes] = depth;<br>+ if (m_param->analysisSaveReuseLevel > 1)<br>+ {<br>+ predMode = ctu->m_predMode[absPartIdx];<br>+ if (m_param->analysisSaveReuseLevel != 10 && ctu->m_refIdx[1][absPartIdx] != -1)<br>+ predMode = 4; // used as indicator if the block is coded as bidir<br> <br>- predMode = ctu->m_predMode[absPartIdx];<br>- if (m_param->analysisSaveReuseLevel != 10 && ctu->m_refIdx[1][absPartIdx] != -1)<br>- predMode = 4; // used as indicator if the block is coded as bidir<br>-<br>- interDataCTU->modes[depthBytes] = predMode;<br>+ interDataCTU->modes[depthBytes] = predMode;<br>+ }<br> if (m_param->rc.cuTree)<br> interDataCTU->cuQPOff[depthBytes] = (int8_t)(ctu->m_qpAnalysis[absPartIdx] - baseQP);<br> <br>@@ -5603,17 +5631,22 @@ void Encoder::writeAnalysisFile(x265_analysis_data* analysis, FrameData &curEncD<br> memcpy(&intraDataCTU->modes[ctu->m_cuAddr * ctu->m_numPartitions], ctu->m_lumaIntraDir, sizeof(uint8_t)* ctu->m_numPartitions);<br> }<br> }<br>-<br>- if ((analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I) && m_param->rc.cuTree)<br>+ if ((analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I) && m_param->rc.cuTree && m_param->analysisSaveReuseLevel == 1)<br>+ analysis->frameRecordSize += depthBytes + (sizeof(int8_t)* depthBytes);<br>+ else if ((analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I) && m_param->analysisSaveReuseLevel == 1)<br>+ analysis->frameRecordSize += depthBytes;<br>+ else if ((analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I) && m_param->rc.cuTree)<br> analysis->frameRecordSize += sizeof(uint8_t)* analysis->numCUsInFrame * analysis->numPartitions + depthBytes * 3 + (sizeof(int8_t) * depthBytes);<br> else if (analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I)<br> analysis->frameRecordSize += sizeof(uint8_t)* analysis->numCUsInFrame * analysis->numPartitions + depthBytes * 3;<br> else<br> {<br> /* Add sizeof depth, modes, partSize, cuQPOffset, mergeFlag */<br>- analysis->frameRecordSize += depthBytes * 2;<br>+ analysis->frameRecordSize += depthBytes;<br> if (m_param->rc.cuTree)<br>- analysis->frameRecordSize += (sizeof(int8_t) * depthBytes);<br>+ analysis->frameRecordSize += (sizeof(int8_t) * depthBytes);<br>+ if (m_param->analysisSaveReuseLevel > 1)<br>+ analysis->frameRecordSize += depthBytes;<br> if (m_param->analysisSaveReuseLevel > 4)<br> analysis->frameRecordSize += (depthBytes * 2);<br> <br>@@ -5627,7 +5660,7 @@ void Encoder::writeAnalysisFile(x265_analysis_data* analysis, FrameData &curEncD<br> if (bIntraInInter)<br> analysis->frameRecordSize += sizeof(uint8_t)* analysis->numCUsInFrame * analysis->numPartitions + depthBytes;<br> }<br>- else<br>+ else if (m_param->analysisSaveReuseLevel > 1)<br> analysis->frameRecordSize += sizeof(int32_t)* analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir;<br> }<br> analysis->depthBytes = depthBytes;<br>@@ -5661,44 +5694,58 @@ void Encoder::writeAnalysisFile(x265_analysis_data* analysis, FrameData &curEncD<br> X265_FWRITE((WeightParam*)analysis->wt, sizeof(WeightParam), numPlanes * numDir, m_analysisFileOut);<br> <br> if (m_param->analysisSaveReuseLevel < 2)<br>- return;<br>-<br>- if (analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I)<br> {<br>- X265_FWRITE((analysis->intraData)->depth, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>- X265_FWRITE((analysis->intraData)->chromaModes, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>- X265_FWRITE((analysis->intraData)->partSizes, sizeof(char), depthBytes, m_analysisFileOut);<br>- if (m_param->rc.cuTree)<br>- X265_FWRITE((analysis->intraData)->cuQPOff, sizeof(int8_t), depthBytes, m_analysisFileOut);<br>- X265_FWRITE((analysis->intraData)->modes, sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions, m_analysisFileOut);<br>+ if (analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I)<br>+ {<br>+ X265_FWRITE((analysis->intraData)->depth, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>+ if (m_param->rc.cuTree)<br>+ X265_FWRITE((analysis->intraData)->cuQPOff, sizeof(int8_t), depthBytes, m_analysisFileOut);<br>+ }<br>+ else<br>+ {<br>+ X265_FWRITE((analysis->interData)->depth, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>+ if (m_param->rc.cuTree)<br>+ X265_FWRITE((analysis->interData)->cuQPOff, sizeof(int8_t), depthBytes, m_analysisFileOut);<br>+ }<br> }<br> else<br> {<br>- X265_FWRITE((analysis->interData)->depth, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>- X265_FWRITE((analysis->interData)->modes, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>- if (m_param->rc.cuTree)<br>- X265_FWRITE((analysis->interData)->cuQPOff, sizeof(int8_t), depthBytes, m_analysisFileOut);<br>- if (m_param->analysisSaveReuseLevel > 4)<br>+ if (analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I)<br> {<br>- X265_FWRITE((analysis->interData)->partSize, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>- X265_FWRITE((analysis->interData)->mergeFlag, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>- if (m_param->analysisSaveReuseLevel == 10)<br>+ X265_FWRITE((analysis->intraData)->depth, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>+ X265_FWRITE((analysis->intraData)->chromaModes, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>+ X265_FWRITE((analysis->intraData)->partSizes, sizeof(char), depthBytes, m_analysisFileOut);<br>+ if (m_param->rc.cuTree)<br>+ X265_FWRITE((analysis->intraData)->cuQPOff, sizeof(int8_t), depthBytes, m_analysisFileOut);<br>+ X265_FWRITE((analysis->intraData)->modes, sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions, m_analysisFileOut);<br>+ }<br>+ else<br>+ {<br>+ X265_FWRITE((analysis->interData)->depth, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>+ X265_FWRITE((analysis->interData)->modes, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>+ if (m_param->rc.cuTree)<br>+ X265_FWRITE((analysis->interData)->cuQPOff, sizeof(int8_t), depthBytes, m_analysisFileOut);<br>+ if (m_param->analysisSaveReuseLevel > 4)<br> {<br>- X265_FWRITE((analysis->interData)->interDir, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>- if (bIntraInInter) X265_FWRITE((analysis->intraData)->chromaModes, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>- for (uint32_t dir = 0; dir < numDir; dir++)<br>+ X265_FWRITE((analysis->interData)->partSize, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>+ X265_FWRITE((analysis->interData)->mergeFlag, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>+ if (m_param->analysisSaveReuseLevel == 10)<br> {<br>- X265_FWRITE((analysis->interData)->mvpIdx[dir], sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>- X265_FWRITE((analysis->interData)->refIdx[dir], sizeof(int8_t), depthBytes, m_analysisFileOut);<br>- X265_FWRITE((analysis->interData)->mv[dir], sizeof(MV), depthBytes, m_analysisFileOut);<br>+ X265_FWRITE((analysis->interData)->interDir, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>+ if (bIntraInInter) X265_FWRITE((analysis->intraData)->chromaModes, sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>+ for (uint32_t dir = 0; dir < numDir; dir++)<br>+ {<br>+ X265_FWRITE((analysis->interData)->mvpIdx[dir], sizeof(uint8_t), depthBytes, m_analysisFileOut);<br>+ X265_FWRITE((analysis->interData)->refIdx[dir], sizeof(int8_t), depthBytes, m_analysisFileOut);<br>+ X265_FWRITE((analysis->interData)->mv[dir], sizeof(MV), depthBytes, m_analysisFileOut);<br>+ }<br>+ if (bIntraInInter)<br>+ X265_FWRITE((analysis->intraData)->modes, sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions, m_analysisFileOut);<br> }<br>- if (bIntraInInter)<br>- X265_FWRITE((analysis->intraData)->modes, sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions, m_analysisFileOut);<br> }<br>+ if (m_param->analysisSaveReuseLevel > 1 && m_param->analysisSaveReuseLevel != 10)<br>+ X265_FWRITE((analysis->interData)->ref, sizeof(int32_t), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir, m_analysisFileOut);<br> }<br>- if (m_param->analysisSaveReuseLevel != 10)<br>- X265_FWRITE((analysis->interData)->ref, sizeof(int32_t), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir, m_analysisFileOut);<br>-<br> }<br> #undef X265_FWRITE<br> }<br>-- <br>2.18.2<br><br></div>
</blockquote></div>