<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, May 17, 2018 at 12:23 PM, <span dir="ltr"><<a href="mailto:bhavna@multicorewareinc.com" target="_blank">bhavna@multicorewareinc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"># HG changeset patch<br>
# User Bhavna Hariharan <<a href="mailto:bhavna@multicorewareinc.com">bhavna@multicorewareinc.com</a>><br>
# Date 1526539714 -19800<br>
# Thu May 17 12:18:34 2018 +0530<br>
# Branch stable<br>
# Node ID 3cef29225ef431c820c8e5593b00c3<wbr>c225bfffdc<br>
# Parent e70f8897811514877bed1f1f318ed9<wbr>5d24658af0<br>
analysis: enable scaled save and load runs with different max CU sizes<br>
<br>
This patch allows either of the following:<br>
(i) The CTU size of save and load encodes are the same.<br>
(or)<br>
(ii) The CTU size of load encode is double the CTU size of save encode.<br>
<br>
diff -r e70f88978115 -r 3cef29225ef4 doc/reST/cli.rst<br>
--- a/doc/reST/cli.rst Thu May 17 12:11:45 2018 +0530<br>
+++ b/doc/reST/cli.rst Thu May 17 12:18:34 2018 +0530<br>
@@ -911,9 +911,10 @@<br>
<br>
.. option:: --scale-factor<br>
<br>
- Factor by which input video is scaled down for analysis save mode.<br>
- This option should be coupled with analysis-reuse-mode option, --analysis-reuse-level 10.<br>
- The ctu size of load should be double the size of save. Default 0.<br>
+ Factor by which input video is scaled down for analysis save mode.<br>
+ This option should be coupled with analysis-reuse-mode option, <br>
+ --analysis-reuse-level 10. The ctu size of load can either be the <br>
+ same as that of save or double the size of save. Default 0.<br>
<br>
.. option:: --refine-intra <0..4><br>
<br>
diff -r e70f88978115 -r 3cef29225ef4 source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp Thu May 17 12:11:45 2018 +0530<br>
+++ b/source/encoder/encoder.cpp Thu May 17 12:18:34 2018 +0530<br>
@@ -97,6 +97,7 @@<br>
<br>
m_prevTonemapPayload.payload = NULL;<br>
m_startPoint = 0;<br>
+ m_saveCTUSize = 0;<br>
}<br>
inline char *strcatFilename(const char *input, const char *suffix)<br>
{<br>
@@ -1078,7 +1079,23 @@<br>
if (paramBytes == -1)<br>
m_aborted = true;<br>
}<br>
- readAnalysisFile(&inFrame->m_<wbr>analysisData, inFrame->m_poc, pic_in, paramBytes);<br>
+ if (m_saveCTUSize)<br>
+ {<br>
+ cuLocation cuLocInFrame;<br>
+ cuLocInFrame.init(m_param);<br>
+ /* Set skipWidth/skipHeight flags when the out of bound pixels in lowRes is greater than half of maxCUSize */<br>
+ int extendedWidth = ((m_param->sourceWidth / 2 + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize) * m_param->maxCUSize;<br>
+ int extendedHeight = ((m_param->sourceHeight / 2 + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize) * m_param->maxCUSize;<br>
+ uint32_t outOfBoundaryLowres = extendedWidth - m_param->sourceWidth / 2;<br>
+ if (outOfBoundaryLowres * 2 >= m_param->maxCUSize)<br>
+ cuLocInFrame.skipWidth = true;<br>
+ uint32_t outOfBoundaryLowresH = extendedHeight - m_param->sourceHeight / 2;<br>
+ if (outOfBoundaryLowresH * 2 >= m_param->maxCUSize)<br>
+ cuLocInFrame.skipHeight = true;<br>
+ readAnalysisFile(&inFrame->m_<wbr>analysisData, inFrame->m_poc, pic_in, paramBytes, cuLocInFrame);<br>
+ }<br>
+ else<br>
+ readAnalysisFile(&inFrame->m_<wbr>analysisData, inFrame->m_poc, pic_in, paramBytes);<br>
inFrame->m_poc = inFrame->m_analysisData.poc;<br>
sliceType = inFrame->m_analysisData.<wbr>sliceType;<br>
inFrame->m_lowres.bScenecut = !!inFrame->m_analysisData.<wbr>bScenecut;<br>
@@ -3320,7 +3337,265 @@<br>
<br>
void Encoder::readAnalysisFile(<wbr>x265_analysis_data* analysis, int curPoc, const x265_picture* picIn, int paramBytes)<br>
{<br>
-<br>
+#define X265_FREAD(val, size, readSize, fileOffset, src)\<br>
+ if (!m_param->bUseAnalysisFile)\<br>
+ {\<br>
+ memcpy(val, src, (size * readSize));\<br>
+ }\<br>
+ else if (fread(val, size, readSize, fileOffset) != readSize)\<br>
+ {\<br>
+ x265_log(NULL, X265_LOG_ERROR, "Error reading analysis data\n");\<br>
+ freeAnalysis(analysis);\<br>
+ m_aborted = true;\<br>
+ return;\<br>
+ }\<br>
+<br>
+ static uint64_t consumedBytes = 0;<br>
+ static uint64_t totalConsumedBytes = 0;<br>
+ uint32_t depthBytes = 0;<br>
+ if (m_param->bUseAnalysisFile)<br>
+ fseeko(m_analysisFileIn, totalConsumedBytes + paramBytes, SEEK_SET);<br>
+ const x265_analysis_data *picData = &(picIn->analysisData);<br>
+ analysis_intra_data *intraPic = (analysis_intra_data *)picData->intraData;<br>
+ analysis_inter_data *interPic = (analysis_inter_data *)picData->interData;<br>
+<br>
+ int poc; uint32_t frameRecordSize;<br>
+ X265_FREAD(&frameRecordSize, sizeof(uint32_t), 1, m_analysisFileIn, &(picData->frameRecordSize));<br>
+ X265_FREAD(&depthBytes, sizeof(uint32_t), 1, m_analysisFileIn, &(picData->depthBytes));<br>
+ X265_FREAD(&poc, sizeof(int), 1, m_analysisFileIn, &(picData->poc));<br>
+<br>
+ if (m_param->bUseAnalysisFile)<br>
+ {<br>
+ uint64_t currentOffset = totalConsumedBytes;<br>
+<br>
+ /* Seeking to the right frame Record */<br>
+ while (poc != curPoc && !feof(m_analysisFileIn))<br>
+ {<br>
+ currentOffset += frameRecordSize;<br>
+ fseeko(m_analysisFileIn, currentOffset + paramBytes, SEEK_SET);<br>
+ X265_FREAD(&frameRecordSize, sizeof(uint32_t), 1, m_analysisFileIn, &(picData->frameRecordSize));<br>
+ X265_FREAD(&depthBytes, sizeof(uint32_t), 1, m_analysisFileIn, &(picData->depthBytes));<br>
+ X265_FREAD(&poc, sizeof(int), 1, m_analysisFileIn, &(picData->poc));<br>
+ }<br>
+ if (poc != curPoc || feof(m_analysisFileIn))<br>
+ {<br>
+ x265_log(NULL, X265_LOG_WARNING, "Error reading analysis data: Cannot find POC %d\n", curPoc);<br>
+ freeAnalysis(analysis);<br>
+ return;<br>
+ }<br>
+ }<br>
+<br>
+ /* Now arrived at the right frame, read the record */<br>
+ analysis->poc = poc;<br>
+ analysis->frameRecordSize = frameRecordSize;<br>
+ X265_FREAD(&analysis-><wbr>sliceType, sizeof(int), 1, m_analysisFileIn, &(picData->sliceType));<br>
+ X265_FREAD(&analysis-><wbr>bScenecut, sizeof(int), 1, m_analysisFileIn, &(picData->bScenecut));<br>
+ X265_FREAD(&analysis-><wbr>satdCost, sizeof(int64_t), 1, m_analysisFileIn, &(picData->satdCost));<br>
+ X265_FREAD(&analysis-><wbr>numCUsInFrame, sizeof(int), 1, m_analysisFileIn, &(picData->numCUsInFrame));<br>
+ X265_FREAD(&analysis-><wbr>numPartitions, sizeof(int), 1, m_analysisFileIn, &(picData->numPartitions));<br>
+ if (m_param->bDisableLookahead)<br>
+ {<br>
+ X265_FREAD(&analysis-><wbr>numCuInHeight, sizeof(uint32_t), 1, m_analysisFileIn, &(picData->numCuInHeight));<br>
+ X265_FREAD(&analysis-><wbr>lookahead, sizeof(x265_lookahead_data), 1, m_analysisFileIn, &(picData->lookahead));<br>
+ }<br>
+ int scaledNumPartition = analysis->numPartitions;<br>
+ int factor = 1 << m_param->scaleFactor;<br>
+<br>
+ if (m_param->scaleFactor)<br>
+ analysis->numPartitions *= factor;<br>
+ /* Memory is allocated for inter and intra analysis data based on the slicetype */<br>
+ allocAnalysis(analysis);<br>
+ if (m_param->bDisableLookahead && m_rateControl->m_isVbv)<br>
+ {<br>
+ X265_FREAD(analysis-><wbr>lookahead.intraVbvCost, sizeof(uint32_t), analysis->numCUsInFrame, m_analysisFileIn, picData->lookahead.<wbr>intraVbvCost);<br>
+ X265_FREAD(analysis-><wbr>lookahead.vbvCost, sizeof(uint32_t), analysis->numCUsInFrame, m_analysisFileIn, picData->lookahead.vbvCost);<br>
+ X265_FREAD(analysis-><wbr>lookahead.satdForVbv, sizeof(uint32_t), analysis->numCuInHeight, m_analysisFileIn, picData->lookahead.satdForVbv)<wbr>;<br>
+ X265_FREAD(analysis-><wbr>lookahead.intraSatdForVbv, sizeof(uint32_t), analysis->numCuInHeight, m_analysisFileIn, picData->lookahead.<wbr>intraSatdForVbv);<br>
+ }<br>
+ if (analysis->sliceType == X265_TYPE_IDR || analysis->sliceType == X265_TYPE_I)<br>
+ {<br>
+ if (m_param->analysisReuseLevel < 2)<br>
+ return;<br>
+<br>
+ uint8_t *tempBuf = NULL, *depthBuf = NULL, *modeBuf = NULL, *partSizes = NULL;<br>
+<br>
+ tempBuf = X265_MALLOC(uint8_t, depthBytes * 3);<br>
+ depthBuf = tempBuf;<br>
+ modeBuf = tempBuf + depthBytes;<br>
+ partSizes = tempBuf + 2 * 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>
+ size_t count = 0;<br>
+ for (uint32_t d = 0; d < depthBytes; d++)<br>
+ {<br>
+ int bytes = analysis->numPartitions >> (depthBuf[d] * 2);<br>
+ if (m_param->scaleFactor)<br>
+ {<br>
+ if (depthBuf[d] == 0)<br>
+ depthBuf[d] = 1;<br>
+ if (partSizes[d] == SIZE_NxN)<br>
+ partSizes[d] = SIZE_2Nx2N;<br>
+ }<br>
+ memset(&((analysis_intra_data *)analysis->intraData)->depth[<wbr>count], depthBuf[d], bytes);<br>
+ memset(&((analysis_intra_data *)analysis->intraData)-><wbr>chromaModes[count], modeBuf[d], bytes);<br>
+ memset(&((analysis_intra_data *)analysis->intraData)-><wbr>partSizes[count], partSizes[d], bytes);<br>
+ count += bytes;<br>
+ }<br>
+<br>
+ if (!m_param->scaleFactor)<br>
+ {<br>
+ X265_FREAD(((analysis_intra_<wbr>data *)analysis->intraData)->modes, sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions, m_analysisFileIn, intraPic->modes);<br>
+ }<br>
+ else<br>
+ {<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>
+ for (uint32_t ctu32Idx = 0, cnt = 0; ctu32Idx < analysis->numCUsInFrame * scaledNumPartition; ctu32Idx++, cnt += factor)<br>
+ memset(&((analysis_intra_data *)analysis->intraData)->modes[<wbr>cnt], tempLumaBuf[ctu32Idx], factor);<br>
+ X265_FREE(tempLumaBuf);<br>
+ }<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*)<wbr>analysis->wt, sizeof(WeightParam), numPlanes * numDir, m_analysisFileIn, (picIn->analysisData.wt));<br>
+ if (m_param->analysisReuseLevel < 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>
+ MV* mv[2];<br>
+ int8_t* refIdx[2];<br>
+<br>
+ int numBuf = m_param->analysisReuseLevel > 4 ? 4 : 2;<br>
+ bool bIntraInInter = false;<br>
+ if (m_param->analysisReuseLevel == 10)<br>
+ {<br>
+ numBuf++;<br>
+ bIntraInInter = (analysis->sliceType == X265_TYPE_P || m_param->bIntraInBFrames);<br>
+ if (bIntraInInter) numBuf++;<br>
+ }<br>
+<br>
+ tempBuf = X265_MALLOC(uint8_t, depthBytes * numBuf);<br>
+ depthBuf = tempBuf;<br>
+ modeBuf = tempBuf + 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>
+<br>
+ if (m_param->analysisReuseLevel > 4)<br>
+ {<br>
+ partSize = modeBuf + depthBytes;<br>
+ mergeFlag = partSize + depthBytes;<br>
+ X265_FREAD(partSize, sizeof(uint8_t), depthBytes, m_analysisFileIn, interPic->partSize);<br>
+ X265_FREAD(mergeFlag, sizeof(uint8_t), depthBytes, m_analysisFileIn, interPic->mergeFlag);<br>
+<br>
+ if (m_param->analysisReuseLevel == 10)<br>
+ {<br>
+ interDir = mergeFlag + depthBytes;<br>
+ X265_FREAD(interDir, sizeof(uint8_t), depthBytes, m_analysisFileIn, interPic->interDir);<br>
+ if (bIntraInInter)<br>
+ {<br>
+ chromaDir = interDir + depthBytes;<br>
+ X265_FREAD(chromaDir, sizeof(uint8_t), depthBytes, m_analysisFileIn, intraPic->chromaModes);<br>
+ }<br>
+ for (uint32_t i = 0; i < numDir; i++)<br>
+ {<br>
+ mvpIdx[i] = X265_MALLOC(uint8_t, depthBytes);<br>
+ refIdx[i] = X265_MALLOC(int8_t, depthBytes);<br>
+ mv[i] = X265_MALLOC(MV, depthBytes);<br>
+ X265_FREAD(mvpIdx[i], sizeof(uint8_t), depthBytes, m_analysisFileIn, interPic->mvpIdx[i]);<br>
+ X265_FREAD(refIdx[i], sizeof(int8_t), depthBytes, m_analysisFileIn, interPic->refIdx[i]);<br>
+ X265_FREAD(mv[i], sizeof(MV), depthBytes, m_analysisFileIn, interPic->mv[i]);<br>
+ }<br>
+ }<br>
+ }<br>
+<br>
+ size_t count = 0;<br>
+ for (uint32_t d = 0; d < depthBytes; d++)<br>
+ {<br>
+ int bytes = analysis->numPartitions >> (depthBuf[d] * 2);<br>
+ if (m_param->scaleFactor && modeBuf[d] == MODE_INTRA && depthBuf[d] == 0)<br>
+ depthBuf[d] = 1;<br>
+ memset(&((analysis_inter_data *)analysis->interData)->depth[<wbr>count], depthBuf[d], bytes);<br>
+ memset(&((analysis_inter_data *)analysis->interData)->modes[<wbr>count], modeBuf[d], bytes);<br>
+ if (m_param->analysisReuseLevel > 4)<br>
+ {<br>
+ if (m_param->scaleFactor && modeBuf[d] == MODE_INTRA && partSize[d] == SIZE_NxN)<br>
+ partSize[d] = SIZE_2Nx2N;<br>
+ memset(&((analysis_inter_data *)analysis->interData)-><wbr>partSize[count], partSize[d], bytes);<br>
+ int numPU = (modeBuf[d] == MODE_INTRA) ? 1 : nbPartsTable[(int)partSize[d]]<wbr>;<br>
+ for (int pu = 0; pu < numPU; pu++)<br>
+ {<br>
+ if (pu) d++;<br>
+ ((analysis_inter_data *)analysis->interData)-><wbr>mergeFlag[count + pu] = mergeFlag[d];<br>
+ if (m_param->analysisReuseLevel == 10)<br>
+ {<br>
+ ((analysis_inter_data *)analysis->interData)-><wbr>interDir[count + pu] = interDir[d];<br>
+ for (uint32_t i = 0; i < numDir; i++)<br>
+ {<br>
+ ((analysis_inter_data *)analysis->interData)-><wbr>mvpIdx[i][count + pu] = mvpIdx[i][d];<br>
+ ((analysis_inter_data *)analysis->interData)-><wbr>refIdx[i][count + pu] = refIdx[i][d];<br>
+ if (m_param->scaleFactor)<br>
+ {<br>
+ mv[i][d].x *= (int16_t)m_param->scaleFactor;<br>
+ mv[i][d].y *= (int16_t)m_param->scaleFactor;<br>
+ }<br>
+ memcpy(&((analysis_inter_data *)analysis->interData)->mv[i][<wbr>count + pu], &mv[i][d], sizeof(MV));<br>
+ }<br>
+ }<br>
+ }<br>
+ if (m_param->analysisReuseLevel == 10 && bIntraInInter)<br>
+ memset(&((analysis_intra_data *)analysis->intraData)-><wbr>chromaModes[count], chromaDir[d], bytes);<br>
+ }<br>
+ count += bytes;<br>
+ }<br>
+<br>
+ X265_FREE(tempBuf);<br>
+<br>
+ if (m_param->analysisReuseLevel == 10)<br>
+ {<br>
+ for (uint32_t i = 0; i < numDir; i++)<br>
+ {<br>
+ X265_FREE(mvpIdx[i]);<br>
+ X265_FREE(refIdx[i]);<br>
+ X265_FREE(mv[i]);<br>
+ }<br>
+ if (bIntraInInter)<br>
+ {<br>
+ if (!m_param->scaleFactor)<br>
+ {<br>
+ X265_FREAD(((analysis_intra_<wbr>data *)analysis->intraData)->modes, sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions, m_analysisFileIn, intraPic->modes);<br>
+ }<br>
+ else<br>
+ {<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>
+ for (uint32_t ctu32Idx = 0, cnt = 0; ctu32Idx < analysis->numCUsInFrame * scaledNumPartition; ctu32Idx++, cnt += factor)<br>
+ memset(&((analysis_intra_data *)analysis->intraData)->modes[<wbr>cnt], tempLumaBuf[ctu32Idx], factor);<br>
+ X265_FREE(tempLumaBuf);<br>
+ }<br>
+ }<br>
+ }<br>
+ else<br>
+ X265_FREAD(((analysis_inter_<wbr>data *)analysis->interData)->ref, sizeof(int32_t), analysis->numCUsInFrame * X265_MAX_PRED_MODE_PER_CTU * numDir, m_analysisFileIn, interPic->ref);<br>
+<br>
+ consumedBytes += frameRecordSize;<br>
+ if (numDir == 1)<br>
+ totalConsumedBytes = consumedBytes;<br>
+ }<br>
+#undef X265_FREAD<br>
+}<br>
+<br>
+void Encoder::readAnalysisFile(<wbr>x265_analysis_data* analysis, int curPoc, const x265_picture* picIn, int paramBytes, cuLocation cuLoc)<br>
+{<br>
#define X265_FREAD(val, size, readSize, fileOffset, src)\<br>
if (!m_param->bUseAnalysisFile)\<br>
{\<br>
@@ -3388,25 +3663,9 @@<br>
<br>
int numPartitions = analysis->numPartitions;<br>
int numCUsInFrame = analysis->numCUsInFrame;<br>
- cuLocation cuLoc;<br>
- cuLoc.init(m_param);<br>
-<br>
- if (m_param->scaleFactor)<br>
- {<br>
- /* Allocate memory for scaled resoultion's numPartitions and numCUsInFrame*/<br>
- analysis->numPartitions = m_param->num4x4Partitions;<br>
- analysis->numCUsInFrame = cuLoc.heightInCU * cuLoc.widthInCU;<br>
-<br>
- /* Set skipWidth/skipHeight flags when the out of bound pixels in lowRes is greater than half of maxCUSize */<br>
- int extendedWidth = ((m_param->sourceWidth / 2 + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize) * m_param->maxCUSize;<br>
- int extendedHeight = ((m_param->sourceHeight / 2 + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize) * m_param->maxCUSize;<br>
- uint32_t outOfBoundaryLowres = extendedWidth - m_param->sourceWidth / 2;<br>
- if (outOfBoundaryLowres * 2 >= m_param->maxCUSize)<br>
- cuLoc.skipWidth = true;<br>
- uint32_t outOfBoundaryLowresH = extendedHeight - m_param->sourceHeight / 2;<br>
- if (outOfBoundaryLowresH * 2 >= m_param->maxCUSize)<br>
- cuLoc.skipHeight = true;<br>
- }<br>
+ /* Allocate memory for scaled resoultion's numPartitions and numCUsInFrame*/<br>
+ analysis->numPartitions = m_param->num4x4Partitions;<br>
+ analysis->numCUsInFrame = cuLoc.heightInCU * cuLoc.widthInCU;<br>
<br>
/* Memory is allocated for inter and intra analysis data based on the slicetype */<br>
allocAnalysis(analysis);<br>
@@ -3442,51 +3701,39 @@<br>
{<br>
int bytes = analysis->numPartitions >> (depthBuf[d] * 2);<br>
int numCTUCopied = 1;<br>
-<br>
- if (m_param->scaleFactor)<br>
+ if (!depthBuf[d]) //copy data of one 64x64 to four scaled 64x64 CTUs.<br>
{<br>
- if (!depthBuf[d]) //copy data of one 64x64 to four scaled 64x64 CTUs.<br>
- {<br>
- bytes /= 4;<br>
- numCTUCopied = 4;<br>
- }<br>
-<br>
- if (partSizes[d] == SIZE_NxN)<br>
- partSizes[d] = SIZE_2Nx2N;<br>
- if ((depthBuf[d] > 1 && m_param->maxCUSize == 64) || (depthBuf[d] && m_param->maxCUSize != 64))<br>
- depthBuf[d]--;<br>
+ bytes /= 4;<br>
+ numCTUCopied = 4;<br>
}<br>
+ if (partSizes[d] == SIZE_NxN)<br>
+ partSizes[d] = SIZE_2Nx2N;<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_intra_data *)analysis->intraData)->depth[<wbr>count], depthBuf[d], bytes);<br>
memset(&((analysis_intra_data *)analysis->intraData)-><wbr>chromaModes[count], modeBuf[d], bytes);<br>
memset(&((analysis_intra_data *)analysis->intraData)-><wbr>partSizes[count], partSizes[d], bytes);<br>
count += bytes;<br>
- if (m_param->scaleFactor)<br>
- d += getCUIndex(&cuLoc, &count, bytes, 1);<br>
+ d += getCUIndex(&cuLoc, &count, bytes, 1);<br>
}<br>
}<br>
<br>
- if (!m_param->scaleFactor)<br>
- {<br>
- X265_FREAD(((analysis_intra_<wbr>data *)analysis->intraData)->modes, sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions, m_analysisFileIn, intraPic->modes);<br>
- }<br>
- else<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>
- 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_intra_data *)analysis->intraData)->modes[<wbr>cnt], tempLumaBuf[ctu32Idx], factor);<br>
- cnt += factor;<br>
- ctu32Idx += getCUIndex(&cuLoc, &cnt, factor, 0);<br>
- }<br>
- X265_FREE(tempLumaBuf);<br>
+ memset(&((analysis_intra_data *)analysis->intraData)->modes[<wbr>cnt], tempLumaBuf[ctu32Idx], factor);<br>
+ cnt += factor;<br>
+ ctu32Idx += getCUIndex(&cuLoc, &cnt, factor, 0);<br>
}<br>
+ X265_FREE(tempLumaBuf);<br>
X265_FREE(tempBuf);<br>
consumedBytes += frameRecordSize;<br>
}<br>
@@ -3519,14 +3766,12 @@<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>
-<br>
if (m_param->analysisReuseLevel > 4)<br>
{<br>
partSize = modeBuf + depthBytes;<br>
mergeFlag = partSize + depthBytes;<br>
X265_FREAD(partSize, sizeof(uint8_t), depthBytes, m_analysisFileIn, interPic->partSize);<br>
X265_FREAD(mergeFlag, sizeof(uint8_t), depthBytes, m_analysisFileIn, interPic->mergeFlag);<br>
-<br>
if (m_param->analysisReuseLevel == 10)<br>
{<br>
interDir = mergeFlag + depthBytes;<br>
@@ -3556,17 +3801,14 @@<br>
bool isScaledMaxCUSize = false;<br>
int numCTUCopied = 1;<br>
int writeDepth = depthBuf[d];<br>
- if (m_param->scaleFactor)<br>
+ if (!depthBuf[d]) //copy data of one 64x64 to four scaled 64x64 CTUs.<br>
{<br>
- if (!depthBuf[d]) //copy data of one 64x64 to four scaled 64x64 CTUs.<br>
- {<br>
- isScaledMaxCUSize = true;<br>
- bytes /= 4;<br>
- numCTUCopied = 4;<br>
- }<br>
- if ((modeBuf[d] != MODE_INTRA && depthBuf[d] != 0) || (modeBuf[d] == MODE_INTRA && depthBuf[d] > 1))<br>
- writeDepth--;<br>
+ isScaledMaxCUSize = true;<br>
+ bytes /= 4;<br>
+ numCTUCopied = 4;<br>
}<br>
+ if ((modeBuf[d] != MODE_INTRA && depthBuf[d] != 0) || (modeBuf[d] == MODE_INTRA && depthBuf[d] > 1))<br>
+ writeDepth--;<br>
<br>
for (int numCTU = 0; numCTU < numCTUCopied; numCTU++)<br>
{<br>
@@ -3579,7 +3821,7 @@<br>
{<br>
puOrientation puOrient;<br>
puOrient.init();<br>
- if (m_param->scaleFactor && modeBuf[d] == MODE_INTRA && partSize[d] == SIZE_NxN)<br>
+ if (modeBuf[d] == MODE_INTRA && partSize[d] == SIZE_NxN)<br>
partSize[d] = SIZE_2Nx2N;<br>
int partitionSize = partSize[d];<br>
if (isScaledMaxCUSize && partSize[d] != SIZE_2Nx2N)<br>
@@ -3609,13 +3851,8 @@<br>
{<br>
((analysis_inter_data *)analysis->interData)-><wbr>mvpIdx[i][count + pu] = mvpIdx[i][d];<br>
((analysis_inter_data *)analysis->interData)-><wbr>refIdx[i][count + pu] = refIdx[i][d];<br>
- mvCopy[i].x = mv[i][d].x;<br>
- mvCopy[i].y = mv[i][d].y;<br>
- if (m_param->scaleFactor)<br>
- {<br>
- mvCopy[i].x = mv[i][d].x * (int16_t)m_param->scaleFactor;<br>
- mvCopy[i].y = mv[i][d].y * (int16_t)m_param->scaleFactor;<br>
- }<br>
+ mvCopy[i].x = mv[i][d].x * (int16_t)m_param->scaleFactor;<br>
+ mvCopy[i].y = mv[i][d].y * (int16_t)m_param->scaleFactor;<br>
memcpy(&((analysis_inter_data *)analysis->interData)->mv[i][<wbr>count + pu], &mvCopy[i], sizeof(MV));<br>
}<br>
}<br>
@@ -3633,8 +3870,7 @@<br>
}<br>
}<br>
count += bytes;<br>
- if (m_param->scaleFactor)<br>
- d += getCUIndex(&cuLoc, &count, bytes, 1);<br>
+ d += getCUIndex(&cuLoc, &count, bytes, 1);<br>
}<br>
}<br>
<br>
@@ -3650,26 +3886,19 @@<br>
}<br>
if (bIntraInInter)<br>
{<br>
- if (!m_param->scaleFactor)<br>
- {<br>
- X265_FREAD(((analysis_intra_<wbr>data *)analysis->intraData)->modes, sizeof(uint8_t), analysis->numCUsInFrame * analysis->numPartitions, m_analysisFileIn, intraPic->modes);<br>
- }<br>
- else<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>
- 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_intra_data *)analysis->intraData)->modes[<wbr>cnt], tempLumaBuf[ctu32Idx], factor);<br>
- cnt += factor;<br>
- ctu32Idx += getCUIndex(&cuLoc, &cnt, factor, 0);<br>
- }<br>
- X265_FREE(tempLumaBuf);<br>
+ memset(&((analysis_intra_data *)analysis->intraData)->modes[<wbr>cnt], tempLumaBuf[ctu32Idx], factor);<br>
+ cnt += factor;<br>
+ ctu32Idx += getCUIndex(&cuLoc, &cnt, factor, 0);<br>
}<br>
+ X265_FREE(tempLumaBuf);<br>
}<br>
}<br>
else<br>
@@ -3681,11 +3910,8 @@<br>
}<br>
<br>
/* Restore to the current encode's numPartitions and numCUsInFrame */<br>
- if (m_param->scaleFactor)<br>
- {<br>
- analysis->numPartitions = m_param->num4x4Partitions;<br>
- analysis->numCUsInFrame = cuLoc.heightInCU * cuLoc.widthInCU;<br>
- }<br>
+ analysis->numPartitions = m_param->num4x4Partitions;<br>
+ analysis->numCUsInFrame = cuLoc.heightInCU * cuLoc.widthInCU;<br>
#undef X265_FREAD<br>
}<br>
<br>
@@ -3731,7 +3957,32 @@<br>
X265_PARAM_VALIDATE(saveParam.<wbr>openGOP, sizeof(int), 1, &m_param->bOpenGOP);<br>
X265_PARAM_VALIDATE(saveParam.<wbr>bframes, sizeof(int), 1, &m_param->bframes);<br>
X265_PARAM_VALIDATE(saveParam.<wbr>bPyramid, sizeof(int), 1, &m_param->bBPyramid);<br>
- X265_PARAM_VALIDATE(saveParam.<wbr>maxCUSize, sizeof(int), 1, &m_param->maxCUSize);<br>
+ /* Enable m_saveCTUSize if the save and load encodes have the same maxCU size */<br>
+ if (writeFlag)<br>
+ {<br>
+ X265_PARAM_VALIDATE(saveParam.<wbr>maxCUSize, sizeof(int), 1, &m_param->maxCUSize);<br>
+ }<br>
+ else<br>
+ {<br>
+ fileOffset = m_analysisFileIn;<br>
+ if (m_param->bUseAnalysisFile && fread(&readValue, sizeof(int), 1, fileOffset) != 1)<br>
+ {<br>
+ x265_log(NULL, X265_LOG_ERROR, "Error reading analysis data.\n");<br>
+ m_aborted = true;<br>
+ }<br>
+ else if (!m_param->bUseAnalysisFile)<br>
+ readValue = saveParam.maxCUSize;<br>
+<br>
+ m_saveCTUSize = 0;<br>
+ if (m_param->scaleFactor && g_log2Size[m_param->maxCUSize] == g_log2Size[readValue])<br>
+ m_saveCTUSize = 1;<br>
+ else if (readValue != (int)m_param->maxCUSize && (g_log2Size[m_param-><wbr>maxCUSize] - g_log2Size[readValue]) != 1)<br>
+ {<br>
+ x265_log(NULL, X265_LOG_ERROR, "Error reading analysis data. Mismatch in params.\n");<br>
+ m_aborted = true;<br>
+ }<br>
+ count++;<br>
+ }<br>
X265_PARAM_VALIDATE(saveParam.<wbr>minCUSize, sizeof(int), 1, &m_param->minCUSize);<br>
X265_PARAM_VALIDATE(saveParam.<wbr>radl, sizeof(int), 1, &m_param->radl);<br>
X265_PARAM_VALIDATE(saveParam.<wbr>lookaheadDepth, sizeof(int), 1, &m_param->lookaheadDepth);<br>
diff -r e70f88978115 -r 3cef29225ef4 source/encoder/encoder.h<br>
--- a/source/encoder/encoder.h Thu May 17 12:11:45 2018 +0530<br>
+++ b/source/encoder/encoder.h Thu May 17 12:18:34 2018 +0530<br>
@@ -228,6 +228,8 @@<br>
int32_t m_startPoint;<br>
Lock m_dynamicRefineLock;<br>
<br>
+ bool m_saveCTUSize;<br>
+<br>
Encoder();<br>
~Encoder()<br>
{<br>
@@ -281,6 +283,8 @@<br>
<br>
void readAnalysisFile(x265_<wbr>analysis_data* analysis, int poc, const x265_picture* picIn, int paramBytes);<br>
<br>
+ void readAnalysisFile(x265_<wbr>analysis_data* analysis, int poc, const x265_picture* picIn, int paramBytes, cuLocation cuLoc);<br>
+<br>
int getCUIndex(cuLocation* cuLoc, uint32_t* count, int bytes, int flag);<br>
<br>
int getPuShape(puOrientation* puOrient, int partSize, int numCTU);<br>
<br>______________________________<wbr>_________________<br>
x265-devel mailing list<br>
<a href="mailto:x265-devel@videolan.org">x265-devel@videolan.org</a><br>
<a href="https://mailman.videolan.org/listinfo/x265-devel" rel="noreferrer" target="_blank">https://mailman.videolan.org/<wbr>listinfo/x265-devel</a><br>
<br></blockquote></div><br></div><div class="gmail_extra"><br></div><div class="gmail_extra">Pushed.</div></div>