[x265] [PATCH] analysis: Throw error messages for invalid analysis data from previous encode
Ashok Kumar Mishra
ashok at multicorewareinc.com
Thu May 17 17:36:22 CEST 2018
On Thu, May 17, 2018 at 12:23 PM, <bhavna at multicorewareinc.com> wrote:
> # HG changeset patch
> # User Bhavna Hariharan <bhavna at multicorewareinc.com>
> # Date 1526539305 -19800
> # Thu May 17 12:11:45 2018 +0530
> # Branch stable
> # Node ID e70f8897811514877bed1f1f318ed95d24658af0
> # Parent 0968a46d6ba40d8eed7bf83729845f65f1f647e2
> analysis: Throw error messages for invalid analysis data from previous
> encode
>
> This patch does the following:
> Save encode - In the analysis file, save the param values that are required
> to match in the load encode for the data to be reused.
>
> Load encode - Read the saved param values and compare them with the current
> param values. Throw error if there are any mismatches in the param values.
>
> diff -r 0968a46d6ba4 -r e70f88978115 source/encoder/encoder.cpp
> --- a/source/encoder/encoder.cpp Fri May 04 14:56:10 2018 +0530
> +++ b/source/encoder/encoder.cpp Thu May 17 12:11:45 2018 +0530
> @@ -1069,8 +1069,16 @@
> /* Load analysis data before lookahead->addPicture, since
> sliceType has been decided */
> if (m_param->analysisLoad)
> {
> - /* readAnalysisFile reads analysis data for the frame and
> allocates memory based on slicetype */
> - readAnalysisFile(&inFrame->m_analysisData, inFrame->m_poc,
> pic_in);
> + /* reads analysis data for the frame and allocates memory
> based on slicetype */
> + static int paramBytes = 0;
> + if (!inFrame->m_poc)
> + {
> + x265_analysis_data analysisData = pic_in->analysisData;
> + paramBytes = validateAnalysisData(&analysisData, 0);
> + if (paramBytes == -1)
> + m_aborted = true;
> + }
> + readAnalysisFile(&inFrame->m_analysisData, inFrame->m_poc,
> pic_in, paramBytes);
> inFrame->m_poc = inFrame->m_analysisData.poc;
> sliceType = inFrame->m_analysisData.sliceType;
> inFrame->m_lowres.bScenecut = !!inFrame->m_analysisData.
> bScenecut;
> @@ -3310,7 +3318,7 @@
> }
> }
>
> -void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc,
> const x265_picture* picIn)
> +void Encoder::readAnalysisFile(x265_analysis_data* analysis, int curPoc,
> const x265_picture* picIn, int paramBytes)
> {
>
> #define X265_FREAD(val, size, readSize, fileOffset, src)\
> @@ -3330,7 +3338,8 @@
> static uint64_t totalConsumedBytes = 0;
> uint32_t depthBytes = 0;
> if (m_param->bUseAnalysisFile)
> - fseeko(m_analysisFileIn, totalConsumedBytes, SEEK_SET);
> + fseeko(m_analysisFileIn, totalConsumedBytes + paramBytes,
> SEEK_SET);
> +
> const x265_analysis_data *picData = &(picIn->analysisData);
> analysis_intra_data *intraPic = (analysis_intra_data
> *)picData->intraData;
> analysis_inter_data *interPic = (analysis_inter_data
> *)picData->interData;
> @@ -3348,7 +3357,7 @@
> while (poc != curPoc && !feof(m_analysisFileIn))
> {
> currentOffset += frameRecordSize;
> - fseeko(m_analysisFileIn, currentOffset, SEEK_SET);
> + fseeko(m_analysisFileIn, currentOffset + paramBytes,
> SEEK_SET);
> X265_FREAD(&frameRecordSize, sizeof(uint32_t), 1,
> m_analysisFileIn, &(picData->frameRecordSize));
> X265_FREAD(&depthBytes, sizeof(uint32_t), 1,
> m_analysisFileIn, &(picData->depthBytes));
> X265_FREAD(&poc, sizeof(int), 1, m_analysisFileIn,
> &(picData->poc));
> @@ -3680,6 +3689,57 @@
> #undef X265_FREAD
> }
>
> +
> +int Encoder::validateAnalysisData(x265_analysis_data* analysis, int
> writeFlag)
> +{
> +#define X265_PARAM_VALIDATE(analysisParam, size, bytes, param)\
> + if(!writeFlag)\
> + {\
> + fileOffset = m_analysisFileIn;\
> + if ((!m_param->bUseAnalysisFile && analysisParam != (int)*param)
> || \
> + (m_param->bUseAnalysisFile && (fread(&readValue, size, bytes,
> fileOffset) != bytes || (readValue != (int)*param))))\
> + {\
> + x265_log(NULL, X265_LOG_ERROR, "Error reading analysis data.
> Mismatch in params.\n");\
> + m_aborted = true;\
> + return -1;\
> + }\
> + }\
> + if(writeFlag)\
> + {\
> + fileOffset = m_analysisFileOut;\
> + if(!m_param->bUseAnalysisFile)\
> + analysisParam = *param;\
> + else if(fwrite(param, size, bytes, fileOffset) < bytes)\
> + {\
> + x265_log(NULL, X265_LOG_ERROR, "Error writing analysis
> data\n"); \
> + m_aborted = true;\
> + return -1; \
> + }\
> + }\
> + count++;\
> +
> + x265_analysis_validate saveParam = analysis->saveParam;
> + FILE* fileOffset = NULL;
> + int readValue = 0;
> + int count = 0;
> +
> + X265_PARAM_VALIDATE(saveParam.maxNumReferences, sizeof(int), 1,
> &m_param->maxNumReferences);
> + X265_PARAM_VALIDATE(saveParam.analysisReuseLevel, sizeof(int), 1,
> &m_param->analysisReuseLevel);
> + X265_PARAM_VALIDATE(saveParam.scaleFactor, sizeof(int), 1,
> &m_param->scaleFactor);
> + X265_PARAM_VALIDATE(saveParam.keyframeMax, sizeof(int), 1,
> &m_param->keyframeMax);
> + X265_PARAM_VALIDATE(saveParam.keyframeMin, sizeof(int), 1,
> &m_param->keyframeMin);
> + X265_PARAM_VALIDATE(saveParam.openGOP, sizeof(int), 1,
> &m_param->bOpenGOP);
> + X265_PARAM_VALIDATE(saveParam.bframes, sizeof(int), 1,
> &m_param->bframes);
> + X265_PARAM_VALIDATE(saveParam.bPyramid, sizeof(int), 1,
> &m_param->bBPyramid);
> + X265_PARAM_VALIDATE(saveParam.maxCUSize, sizeof(int), 1,
> &m_param->maxCUSize);
> + X265_PARAM_VALIDATE(saveParam.minCUSize, sizeof(int), 1,
> &m_param->minCUSize);
> + X265_PARAM_VALIDATE(saveParam.radl, sizeof(int), 1, &m_param->radl);
> + X265_PARAM_VALIDATE(saveParam.lookaheadDepth, sizeof(int), 1,
> &m_param->lookaheadDepth);
> + X265_PARAM_VALIDATE(saveParam.gopLookahead, sizeof(int), 1,
> &m_param->gopLookahead);
> + return (count * sizeof(int));
> +#undef X265_PARAM_VALIDATE
> +}
> +
> /* Toggle between two consecutive CTU rows. The save's CTU is copied
> twice consecutively in the first and second CTU row of load*/
>
> @@ -3928,6 +3988,9 @@
> uint32_t numDir, numPlanes;
> bool bIntraInInter = false;
>
> + if (!analysis->poc)
> + validateAnalysisData(analysis, 1);
> +
> /* calculate frameRecordSize */
> analysis->frameRecordSize = sizeof(analysis->frameRecordSize) +
> sizeof(depthBytes) + sizeof(analysis->poc) + sizeof(analysis->sliceType) +
> sizeof(analysis->numCUsInFrame) + sizeof(analysis->numPartitions)
> + sizeof(analysis->bScenecut) + sizeof(analysis->satdCost);
> diff -r 0968a46d6ba4 -r e70f88978115 source/encoder/encoder.h
> --- a/source/encoder/encoder.h Fri May 04 14:56:10 2018 +0530
> +++ b/source/encoder/encoder.h Thu May 17 12:11:45 2018 +0530
> @@ -279,7 +279,7 @@
>
> void freeAnalysis2Pass(x265_analysis_2Pass* analysis, int sliceType);
>
> - void readAnalysisFile(x265_analysis_data* analysis, int poc, const
> x265_picture* picIn);
> + void readAnalysisFile(x265_analysis_data* analysis, int poc, const
> x265_picture* picIn, int paramBytes);
>
> int getCUIndex(cuLocation* cuLoc, uint32_t* count, int bytes, int
> flag);
>
> @@ -290,6 +290,8 @@
> void writeAnalysis2PassFile(x265_analysis_2Pass* analysis2Pass,
> FrameData &curEncData, int slicetype);
> void finishFrameStats(Frame* pic, FrameEncoder *curEncoder,
> x265_frame_stats* frameStats, int inPoc);
>
> + int validateAnalysisData(x265_analysis_data* analysis, int
> readWriteFlag);
> +
> void calcRefreshInterval(Frame* frameEnc);
>
> void initRefIdx();
> diff -r 0968a46d6ba4 -r e70f88978115 source/x265.h
> --- a/source/x265.h Fri May 04 14:56:10 2018 +0530
> +++ b/source/x265.h Thu May 17 12:11:45 2018 +0530
> @@ -108,6 +108,23 @@
> int64_t reorderedPts;
> } x265_lookahead_data;
>
> +typedef struct x265_analysis_validate
> +{
> + int maxNumReferences;
> + int analysisReuseLevel;
> + int scaleFactor;
> + int keyframeMax;
> + int keyframeMin;
> + int openGOP;
> + int bframes;
> + int bPyramid;
> + int maxCUSize;
> + int minCUSize;
> + int radl;
> + int lookaheadDepth;
> + int gopLookahead;
> +}x265_analysis_validate;
> +
> /* Stores all analysis data for a single frame */
> typedef struct x265_analysis_data
> {
> @@ -125,6 +142,7 @@
> uint32_t numCuInHeight;
> x265_lookahead_data lookahead;
> uint8_t* modeFlag[2];
> + x265_analysis_validate saveParam;
> } x265_analysis_data;
>
> /* cu statistics */
>
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel
>
>
Pushed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.videolan.org/pipermail/x265-devel/attachments/20180517/f51f83e5/attachment.html>
More information about the x265-devel
mailing list