[x265] [PATCH] API: 'x265_set_analysis_data' to capture analysis information

praveen at multicorewareinc.com praveen at multicorewareinc.com
Mon Nov 13 07:51:25 CET 2017


# HG changeset patch
# User Praveen Tiwari <praveen at multicorewareinc.com>
# Date 1510555850 -19800
#      Mon Nov 13 12:20:50 2017 +0530
# Node ID 5ea4fdbdea99a8bdd91d0d7961bcf50764d445b6
# Parent  563cbe1f4a21dcfe2117ccaa874b713d94434f92
API: 'x265_set_analysis_data' to capture analysis information

diff -r 563cbe1f4a21 -r 5ea4fdbdea99 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Wed Nov 08 17:08:18 2017 +0530
+++ b/source/CMakeLists.txt	Mon Nov 13 12:20:50 2017 +0530
@@ -29,7 +29,7 @@
 option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 143)
+set(X265_BUILD 144)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r 563cbe1f4a21 -r 5ea4fdbdea99 source/encoder/api.cpp
--- a/source/encoder/api.cpp	Wed Nov 08 17:08:18 2017 +0530
+++ b/source/encoder/api.cpp	Mon Nov 13 12:20:50 2017 +0530
@@ -365,6 +365,18 @@
     return encoder->getRefFrameList((PicYuv**)l0, (PicYuv**)l1, sliceType, poc);
 }
 
+int x265_set_analysis_data(x265_encoder *enc, x265_analysis_data *analysis_data, int poc, uint32_t cuBytes)
+{
+    if (!enc)
+        return -1;
+
+    Encoder *encoder = static_cast<Encoder*>(enc);
+    if (!encoder->setAnalysisData(analysis_data, poc, cuBytes))
+        return 0;
+
+    return -1;
+}
+
 void x265_cleanup(void)
 {
     BitCost::destroy();
@@ -444,6 +456,7 @@
     &x265_csvlog_frame,
     &x265_csvlog_encode,
     &x265_dither_image,
+    &x265_set_analysis_data
 };
 
 typedef const x265_api* (*api_get_func)(int bitDepth);
diff -r 563cbe1f4a21 -r 5ea4fdbdea99 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Wed Nov 08 17:08:18 2017 +0530
+++ b/source/encoder/encoder.cpp	Mon Nov 13 12:20:50 2017 +0530
@@ -576,6 +576,85 @@
     return 0;
 }
 
+int Encoder::setAnalysisData(x265_analysis_data *analysis_data, int poc, uint32_t cuBytes)
+{
+    uint32_t widthInCU = (m_param->sourceWidth + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;
+    uint32_t heightInCU = (m_param->sourceHeight + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;
+
+    Frame* curFrame = m_dpb->m_picList.getPOC(poc);
+    if (curFrame != NULL)
+    {
+        curFrame->m_analysisData = (*analysis_data);
+        curFrame->m_analysisData.numCUsInFrame = widthInCU * heightInCU;
+        curFrame->m_analysisData.numPartitions = m_param->num4x4Partitions;
+        allocAnalysis(&curFrame->m_analysisData);
+        if (m_param->maxCUSize == 16)
+        {
+            if (analysis_data->sliceType == X265_TYPE_IDR || analysis_data->sliceType == X265_TYPE_I)
+            {
+                curFrame->m_analysisData.sliceType = X265_TYPE_I;
+                if (m_param->analysisReuseLevel < 2)
+                    return -1;
+
+                curFrame->m_analysisData.numPartitions = m_param->num4x4Partitions;
+                size_t count = 0;
+                for (uint32_t d = 0; d < cuBytes; d++)
+                {
+                    int bytes = curFrame->m_analysisData.numPartitions >> (((analysis_intra_data *)analysis_data->intraData)->depth[d] * 2);
+                    memset(&((analysis_intra_data *)curFrame->m_analysisData.intraData)->depth[count], ((analysis_intra_data *)analysis_data->intraData)->depth[d], bytes);
+                    memset(&((analysis_intra_data *)curFrame->m_analysisData.intraData)->chromaModes[count], ((analysis_intra_data *)analysis_data->intraData)->chromaModes[d], bytes);
+                    memset(&((analysis_intra_data *)curFrame->m_analysisData.intraData)->partSizes[count], ((analysis_intra_data *)analysis_data->intraData)->partSizes[d], bytes);
+                    memset(&((analysis_intra_data *)curFrame->m_analysisData.intraData)->partSizes[count], ((analysis_intra_data *)analysis_data->intraData)->partSizes[d], bytes);
+                    count += bytes;
+                }
+                memcpy(&((analysis_intra_data *)curFrame->m_analysisData.intraData)->modes, ((analysis_intra_data *)analysis_data->intraData)->modes, curFrame->m_analysisData.numPartitions * analysis_data->numCUsInFrame);
+            }
+            else
+            {
+                uint32_t numDir = analysis_data->sliceType == X265_TYPE_P ? 1 : 2;
+                if (m_param->analysisReuseLevel < 2)
+                    return -1;
+
+                curFrame->m_analysisData.numPartitions = m_param->num4x4Partitions;
+                size_t count = 0;
+                for (uint32_t d = 0; d < cuBytes; d++)
+                {
+                    int bytes = curFrame->m_analysisData.numPartitions >> (((analysis_inter_data *)analysis_data->interData)->depth[d] * 2);
+                    memset(&((analysis_inter_data *)curFrame->m_analysisData.interData)->depth[count], ((analysis_inter_data*)analysis_data->interData)->depth[d], bytes);
+                    memset(&((analysis_inter_data *)curFrame->m_analysisData.interData)->modes[count], ((analysis_inter_data*)analysis_data->interData)->modes[d], bytes);
+                    if (m_param->analysisReuseLevel > 4)
+                    {
+                        memset(&((analysis_inter_data *)curFrame->m_analysisData.interData)->partSize[count], ((analysis_inter_data*)analysis_data->interData)->partSize[d], bytes);
+                        int numPU = nbPartsTable[((analysis_inter_data*)analysis_data->interData)->partSize[d]];
+                        for (int pu = 0; pu < numPU; pu++)
+                        {
+                            if (pu) d++;
+                            ((analysis_inter_data *)curFrame->m_analysisData.interData)->mergeFlag[count + pu] = ((analysis_inter_data*)analysis_data->interData)->mergeFlag[d];
+                            if (m_param->analysisReuseLevel >= 7)
+                            {
+                                ((analysis_inter_data *)curFrame->m_analysisData.interData)->interDir[count + pu] = ((analysis_inter_data*)analysis_data->interData)->interDir[d];
+                                for (uint32_t i = 0; i < numDir; i++)
+                                {
+                                    ((analysis_inter_data *)curFrame->m_analysisData.interData)->mvpIdx[i][count + pu] = ((analysis_inter_data*)analysis_data->interData)->mvpIdx[i][d];
+                                    ((analysis_inter_data *)curFrame->m_analysisData.interData)->refIdx[i][count + pu] = ((analysis_inter_data*)analysis_data->interData)->refIdx[i][d];
+                                    memcpy(&((analysis_inter_data *)curFrame->m_analysisData.interData)->mv[i][count + pu], &((analysis_inter_data*)analysis_data->interData)->mv[i][d], sizeof(MV));
+                                }
+                            }
+                        }
+                    }
+                    count += bytes;
+                }
+            }
+        }
+        else
+            setAnalysisDataAfterZScan(analysis_data, curFrame);
+
+        curFrame->m_copyMVType.trigger();
+        return 0;
+    }
+    return -1;
+}
+
 void Encoder::destroy()
 {
 #if ENABLE_HDR10_PLUS
diff -r 563cbe1f4a21 -r 5ea4fdbdea99 source/encoder/encoder.h
--- a/source/encoder/encoder.h	Wed Nov 08 17:08:18 2017 +0530
+++ b/source/encoder/encoder.h	Mon Nov 13 12:20:50 2017 +0530
@@ -212,6 +212,8 @@
 
     int setAnalysisDataAfterZScan(x265_analysis_data *analysis_data, Frame* curFrame);
 
+    int setAnalysisData(x265_analysis_data *analysis_data, int poc, uint32_t cuBytes);
+
     void getStreamHeaders(NALList& list, Entropy& sbacCoder, Bitstream& bs);
 
     void fetchStats(x265_stats* stats, size_t statsSizeBytes);
diff -r 563cbe1f4a21 -r 5ea4fdbdea99 source/x265.def.in
--- a/source/x265.def.in	Wed Nov 08 17:08:18 2017 +0530
+++ b/source/x265.def.in	Mon Nov 13 12:20:50 2017 +0530
@@ -30,3 +30,4 @@
 x265_csvlog_frame
 x265_csvlog_encode
 x265_dither_image
+x265_set_analysis_data
diff -r 563cbe1f4a21 -r 5ea4fdbdea99 source/x265.h
--- a/source/x265.h	Wed Nov 08 17:08:18 2017 +0530
+++ b/source/x265.h	Mon Nov 13 12:20:50 2017 +0530
@@ -1743,6 +1743,11 @@
  *     This API must be called after(poc >= lookaheadDepth + bframes + 2) condition check */
 int x265_get_ref_frame_list(x265_encoder *encoder, x265_picyuv**, x265_picyuv**, int, int);
 
+/* x265_set_analysis_data:
+ *     set the analysis data,
+ *     returns negative on error, 0 access unit were output. */
+int x265_set_analysis_data(x265_encoder *encoder, x265_analysis_data *analysis_data, int poc, uint32_t cuBytes);
+
 void x265_cleanup(void);
 
 /* Open a CSV log file. On success it returns a file handle which must be passed
@@ -1816,6 +1821,7 @@
     void          (*csvlog_frame)(const x265_param&, const x265_picture&);
     void          (*csvlog_encode)(x265_encoder*, const x265_stats&, int, char**);
     void          (*dither_image)(x265_picture&, int, int, int16_t*, int);
+    int           (*set_analysis_data)(x265_encoder *encoder, x265_analysis_data *analysis_data, int poc, uint32_t cuBytes);
     /* add new pointers to the end, or increment X265_MAJOR_VERSION */
 } x265_api;
 


More information about the x265-devel mailing list