<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 1526539305 -19800<br>
# Thu May 17 12:11:45 2018 +0530<br>
# Branch stable<br>
# Node ID e70f8897811514877bed1f1f318ed9<wbr>5d24658af0<br>
# Parent 0968a46d6ba40d8eed7bf83729845f<wbr>65f1f647e2<br>
analysis: Throw error messages for invalid analysis data from previous encode<br>
<br>
This patch does the following:<br>
Save encode - In the analysis file, save the param values that are required<br>
to match in the load encode for the data to be reused.<br>
<br>
Load encode - Read the saved param values and compare them with the current<br>
param values. Throw error if there are any mismatches in the param values.<br>
<br>
diff -r 0968a46d6ba4 -r e70f88978115 source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp Fri May 04 14:56:10 2018 +0530<br>
+++ b/source/encoder/encoder.cpp Thu May 17 12:11:45 2018 +0530<br>
@@ -1069,8 +1069,16 @@<br>
/* Load analysis data before lookahead->addPicture, since sliceType has been decided */<br>
if (m_param->analysisLoad)<br>
{<br>
- /* readAnalysisFile reads analysis data for the frame and allocates memory based on slicetype */<br>
- readAnalysisFile(&inFrame->m_<wbr>analysisData, inFrame->m_poc, pic_in);<br>
+ /* reads analysis data for the frame and allocates memory based on slicetype */<br>
+ static int paramBytes = 0;<br>
+ if (!inFrame->m_poc)<br>
+ {<br>
+ x265_analysis_data analysisData = pic_in->analysisData;<br>
+ paramBytes = validateAnalysisData(&<wbr>analysisData, 0);<br>
+ if (paramBytes == -1)<br>
+ m_aborted = true;<br>
+ }<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>
@@ -3310,7 +3318,7 @@<br>
}<br>
}<br>
<br>
-void Encoder::readAnalysisFile(<wbr>x265_analysis_data* analysis, int curPoc, const x265_picture* picIn)<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>
@@ -3330,7 +3338,8 @@<br>
static uint64_t totalConsumedBytes = 0;<br>
uint32_t depthBytes = 0;<br>
if (m_param->bUseAnalysisFile)<br>
- fseeko(m_analysisFileIn, totalConsumedBytes, SEEK_SET);<br>
+ fseeko(m_analysisFileIn, totalConsumedBytes + paramBytes, SEEK_SET);<br>
+<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>
@@ -3348,7 +3357,7 @@<br>
while (poc != curPoc && !feof(m_analysisFileIn))<br>
{<br>
currentOffset += frameRecordSize;<br>
- fseeko(m_analysisFileIn, currentOffset, SEEK_SET);<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>
@@ -3680,6 +3689,57 @@<br>
#undef X265_FREAD<br>
}<br>
<br>
+<br>
+int Encoder::validateAnalysisData(<wbr>x265_analysis_data* analysis, int writeFlag)<br>
+{<br>
+#define X265_PARAM_VALIDATE(<wbr>analysisParam, size, bytes, param)\<br>
+ if(!writeFlag)\<br>
+ {\<br>
+ fileOffset = m_analysisFileIn;\<br>
+ if ((!m_param->bUseAnalysisFile && analysisParam != (int)*param) || \<br>
+ (m_param->bUseAnalysisFile && (fread(&readValue, size, bytes, fileOffset) != bytes || (readValue != (int)*param))))\<br>
+ {\<br>
+ x265_log(NULL, X265_LOG_ERROR, "Error reading analysis data. Mismatch in params.\n");\<br>
+ m_aborted = true;\<br>
+ return -1;\<br>
+ }\<br>
+ }\<br>
+ if(writeFlag)\<br>
+ {\<br>
+ fileOffset = m_analysisFileOut;\<br>
+ if(!m_param->bUseAnalysisFile)<wbr>\<br>
+ analysisParam = *param;\<br>
+ else if(fwrite(param, size, bytes, fileOffset) < bytes)\<br>
+ {\<br>
+ x265_log(NULL, X265_LOG_ERROR, "Error writing analysis data\n"); \<br>
+ m_aborted = true;\<br>
+ return -1; \<br>
+ }\<br>
+ }\<br>
+ count++;\<br>
+<br>
+ x265_analysis_validate saveParam = analysis->saveParam;<br>
+ FILE* fileOffset = NULL;<br>
+ int readValue = 0;<br>
+ int count = 0;<br>
+<br>
+ X265_PARAM_VALIDATE(saveParam.<wbr>maxNumReferences, sizeof(int), 1, &m_param->maxNumReferences);<br>
+ X265_PARAM_VALIDATE(saveParam.<wbr>analysisReuseLevel, sizeof(int), 1, &m_param->analysisReuseLevel);<br>
+ X265_PARAM_VALIDATE(saveParam.<wbr>scaleFactor, sizeof(int), 1, &m_param->scaleFactor);<br>
+ X265_PARAM_VALIDATE(saveParam.<wbr>keyframeMax, sizeof(int), 1, &m_param->keyframeMax);<br>
+ X265_PARAM_VALIDATE(saveParam.<wbr>keyframeMin, sizeof(int), 1, &m_param->keyframeMin);<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>
+ 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>
+ X265_PARAM_VALIDATE(saveParam.<wbr>gopLookahead, sizeof(int), 1, &m_param->gopLookahead);<br>
+ return (count * sizeof(int));<br>
+#undef X265_PARAM_VALIDATE<br>
+}<br>
+<br>
/* Toggle between two consecutive CTU rows. The save's CTU is copied<br>
twice consecutively in the first and second CTU row of load*/<br>
<br>
@@ -3928,6 +3988,9 @@<br>
uint32_t numDir, numPlanes;<br>
bool bIntraInInter = false;<br>
<br>
+ if (!analysis->poc)<br>
+ validateAnalysisData(analysis, 1);<br>
+<br>
/* calculate frameRecordSize */<br>
analysis->frameRecordSize = sizeof(analysis-><wbr>frameRecordSize) + sizeof(depthBytes) + sizeof(analysis->poc) + sizeof(analysis->sliceType) +<br>
sizeof(analysis-><wbr>numCUsInFrame) + sizeof(analysis-><wbr>numPartitions) + sizeof(analysis->bScenecut) + sizeof(analysis->satdCost);<br>
diff -r 0968a46d6ba4 -r e70f88978115 source/encoder/encoder.h<br>
--- a/source/encoder/encoder.h Fri May 04 14:56:10 2018 +0530<br>
+++ b/source/encoder/encoder.h Thu May 17 12:11:45 2018 +0530<br>
@@ -279,7 +279,7 @@<br>
<br>
void freeAnalysis2Pass(x265_<wbr>analysis_2Pass* analysis, int sliceType);<br>
<br>
- void readAnalysisFile(x265_<wbr>analysis_data* analysis, int poc, const x265_picture* picIn);<br>
+ void readAnalysisFile(x265_<wbr>analysis_data* analysis, int poc, const x265_picture* picIn, int paramBytes);<br>
<br>
int getCUIndex(cuLocation* cuLoc, uint32_t* count, int bytes, int flag);<br>
<br>
@@ -290,6 +290,8 @@<br>
void writeAnalysis2PassFile(x265_<wbr>analysis_2Pass* analysis2Pass, FrameData &curEncData, int slicetype);<br>
void finishFrameStats(Frame* pic, FrameEncoder *curEncoder, x265_frame_stats* frameStats, int inPoc);<br>
<br>
+ int validateAnalysisData(x265_<wbr>analysis_data* analysis, int readWriteFlag);<br>
+<br>
void calcRefreshInterval(Frame* frameEnc);<br>
<br>
void initRefIdx();<br>
diff -r 0968a46d6ba4 -r e70f88978115 source/x265.h<br>
--- a/source/x265.h Fri May 04 14:56:10 2018 +0530<br>
+++ b/source/x265.h Thu May 17 12:11:45 2018 +0530<br>
@@ -108,6 +108,23 @@<br>
int64_t reorderedPts;<br>
} x265_lookahead_data;<br>
<br>
+typedef struct x265_analysis_validate<br>
+{<br>
+ int maxNumReferences;<br>
+ int analysisReuseLevel;<br>
+ int scaleFactor;<br>
+ int keyframeMax;<br>
+ int keyframeMin;<br>
+ int openGOP;<br>
+ int bframes;<br>
+ int bPyramid;<br>
+ int maxCUSize;<br>
+ int minCUSize;<br>
+ int radl;<br>
+ int lookaheadDepth;<br>
+ int gopLookahead;<br>
+}x265_analysis_validate;<br>
+<br>
/* Stores all analysis data for a single frame */<br>
typedef struct x265_analysis_data<br>
{<br>
@@ -125,6 +142,7 @@<br>
uint32_t numCuInHeight;<br>
x265_lookahead_data lookahead;<br>
uint8_t* modeFlag[2];<br>
+ x265_analysis_validate saveParam;<br>
} x265_analysis_data;<br>
<br>
/* cu statistics */<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>