<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 13, 2017 at 12:21 PM,  <span dir="ltr"><<a href="mailto:praveen@multicorewareinc.com" target="_blank">praveen@multicorewareinc.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"># HG changeset patch<br>
# User Praveen Tiwari <<a href="mailto:praveen@multicorewareinc.com">praveen@multicorewareinc.com</a>><br>
# Date 1510555850 -19800<br>
#      Mon Nov 13 12:20:50 2017 +0530<br>
# Node ID 5ea4fdbdea99a8bdd91d0d7961bcf5<wbr>0764d445b6<br>
# Parent  563cbe1f4a21dcfe2117ccaa874b71<wbr>3d94434f92<br>
API: 'x265_set_analysis_data' to capture analysis information<br>
<br>
diff -r 563cbe1f4a21 -r 5ea4fdbdea99 source/CMakeLists.txt<br>
--- a/source/CMakeLists.txt     Wed Nov 08 17:08:18 2017 +0530<br>
+++ b/source/CMakeLists.txt     Mon Nov 13 12:20:50 2017 +0530<br>
@@ -29,7 +29,7 @@<br>
 option(STATIC_LINK_CRT "Statically link C runtime for release builds" OFF)<br>
 mark_as_advanced(FPROFILE_USE FPROFILE_GENERATE NATIVE_BUILD)<br>
 # X265_BUILD must be incremented each time the public API is changed<br>
-set(X265_BUILD 143)<br>
+set(X265_BUILD 144)<br>
 configure_file("${PROJECT_<wbr>SOURCE_DIR}/<a href="http://x265.def.in" rel="noreferrer" target="_blank">x265.def.in</a>"<br>
                "${PROJECT_BINARY_DIR}/x265.<wbr>def")<br>
 configure_file("${PROJECT_<wbr>SOURCE_DIR}/<a href="http://x265_config.h.in" rel="noreferrer" target="_blank">x265_config.h.in</a>"<br>
diff -r 563cbe1f4a21 -r 5ea4fdbdea99 source/encoder/api.cpp<br>
--- a/source/encoder/api.cpp    Wed Nov 08 17:08:18 2017 +0530<br>
+++ b/source/encoder/api.cpp    Mon Nov 13 12:20:50 2017 +0530<br>
@@ -365,6 +365,18 @@<br>
     return encoder->getRefFrameList((<wbr>PicYuv**)l0, (PicYuv**)l1, sliceType, poc);<br>
 }<br>
<br>
+int x265_set_analysis_data(x265_<wbr>encoder *enc, x265_analysis_data *analysis_data, int poc, uint32_t cuBytes)<br>
+{<br>
+    if (!enc)<br>
+        return -1;<br>
+<br>
+    Encoder *encoder = static_cast<Encoder*>(enc);<br>
+    if (!encoder->setAnalysisData(<wbr>analysis_data, poc, cuBytes))<br>
+        return 0;<br>
+<br>
+    return -1;<br>
+}<br>
+<br>
 void x265_cleanup(void)<br>
 {<br>
     BitCost::destroy();<br>
@@ -444,6 +456,7 @@<br>
     &x265_csvlog_frame,<br>
     &x265_csvlog_encode,<br>
     &x265_dither_image,<br>
+    &x265_set_analysis_data<br>
 };<br>
<br>
 typedef const x265_api* (*api_get_func)(int bitDepth);<br>
diff -r 563cbe1f4a21 -r 5ea4fdbdea99 source/encoder/encoder.cpp<br>
--- a/source/encoder/encoder.cpp        Wed Nov 08 17:08:18 2017 +0530<br>
+++ b/source/encoder/encoder.cpp        Mon Nov 13 12:20:50 2017 +0530<br>
@@ -576,6 +576,85 @@<br>
     return 0;<br>
 }<br>
<br>
+int Encoder::setAnalysisData(x265_<wbr>analysis_data *analysis_data, int poc, uint32_t cuBytes)<br>
+{<br>
+    uint32_t widthInCU = (m_param->sourceWidth + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;<br>
+    uint32_t heightInCU = (m_param->sourceHeight + m_param->maxCUSize - 1) >> m_param->maxLog2CUSize;<br>
+<br>
+    Frame* curFrame = m_dpb->m_picList.getPOC(poc);<br>
+    if (curFrame != NULL)<br>
+    {<br>
+        curFrame->m_analysisData = (*analysis_data);<br>
+        curFrame->m_analysisData.<wbr>numCUsInFrame = widthInCU * heightInCU;<br>
+        curFrame->m_analysisData.<wbr>numPartitions = m_param->num4x4Partitions;<br>
+        allocAnalysis(&curFrame->m_<wbr>analysisData);<br>
+        if (m_param->maxCUSize == 16)<br>
+        {<br>
+            if (analysis_data->sliceType == X265_TYPE_IDR || analysis_data->sliceType == X265_TYPE_I)<br>
+            {<br>
+                curFrame->m_analysisData.<wbr>sliceType = X265_TYPE_I;<br>
+                if (m_param->analysisReuseLevel < 2)<br>
+                    return -1;<br>
+<br>
+                curFrame->m_analysisData.<wbr>numPartitions = m_param->num4x4Partitions;<br>
+                size_t count = 0;<br>
+                for (uint32_t d = 0; d < cuBytes; d++)<br>
+                {<br>
+                    int bytes = curFrame->m_analysisData.<wbr>numPartitions >> (((analysis_intra_data *)analysis_data->intraData)-><wbr>depth[d] * 2);<br>
+                    memset(&((analysis_intra_data *)curFrame->m_analysisData.<wbr>intraData)->depth[count], ((analysis_intra_data *)analysis_data->intraData)-><wbr>depth[d], bytes);<br>
+                    memset(&((analysis_intra_data *)curFrame->m_analysisData.<wbr>intraData)->chromaModes[count]<wbr>, ((analysis_intra_data *)analysis_data->intraData)-><wbr>chromaModes[d], bytes);<br>
+                    memset(&((analysis_intra_data *)curFrame->m_analysisData.<wbr>intraData)->partSizes[count], ((analysis_intra_data *)analysis_data->intraData)-><wbr>partSizes[d], bytes);<br>
+                    memset(&((analysis_intra_data *)curFrame->m_analysisData.<wbr>intraData)->partSizes[count], ((analysis_intra_data *)analysis_data->intraData)-><wbr>partSizes[d], bytes);<br>
+                    count += bytes;<br>
+                }<br>
+                memcpy(&((analysis_intra_data *)curFrame->m_analysisData.<wbr>intraData)->modes, ((analysis_intra_data *)analysis_data->intraData)-><wbr>modes, curFrame->m_analysisData.<wbr>numPartitions * analysis_data->numCUsInFrame);<br>
+            }<br>
+            else<br>
+            {<br>
+                uint32_t numDir = analysis_data->sliceType == X265_TYPE_P ? 1 : 2;<br>
+                if (m_param->analysisReuseLevel < 2)<br>
+                    return -1;<br>
+<br>
+                curFrame->m_analysisData.<wbr>numPartitions = m_param->num4x4Partitions;<br>
+                size_t count = 0;<br>
+                for (uint32_t d = 0; d < cuBytes; d++)<br>
+                {<br>
+                    int bytes = curFrame->m_analysisData.<wbr>numPartitions >> (((analysis_inter_data *)analysis_data->interData)-><wbr>depth[d] * 2);<br>
+                    memset(&((analysis_inter_data *)curFrame->m_analysisData.<wbr>interData)->depth[count], ((analysis_inter_data*)<wbr>analysis_data->interData)-><wbr>depth[d], bytes);<br>
+                    memset(&((analysis_inter_data *)curFrame->m_analysisData.<wbr>interData)->modes[count], ((analysis_inter_data*)<wbr>analysis_data->interData)-><wbr>modes[d], bytes);<br>
+                    if (m_param->analysisReuseLevel > 4)<br>
+                    {<br>
+                        memset(&((analysis_inter_data *)curFrame->m_analysisData.<wbr>interData)->partSize[count], ((analysis_inter_data*)<wbr>analysis_data->interData)-><wbr>partSize[d], bytes);<br>
+                        int numPU = nbPartsTable[((analysis_inter_<wbr>data*)analysis_data-><wbr>interData)->partSize[d]];<br>
+                        for (int pu = 0; pu < numPU; pu++)<br>
+                        {<br>
+                            if (pu) d++;<br></blockquote><div> </div><div>Increment of d can be inserted in for loop statement. </div><div>for (int pu = 0; pu < numPU; pu++, d++)<br></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+                            ((analysis_inter_data *)curFrame->m_analysisData.<wbr>interData)->mergeFlag[count + pu] = ((analysis_inter_data*)<wbr>analysis_data->interData)-><wbr>mergeFlag[d];<br>
+                            if (m_param->analysisReuseLevel >= 7)<br>
+                            {<br>
+                                ((analysis_inter_data *)curFrame->m_analysisData.<wbr>interData)->interDir[count + pu] = ((analysis_inter_data*)<wbr>analysis_data->interData)-><wbr>interDir[d];<br>
+                                for (uint32_t i = 0; i < numDir; i++)<br>
+                                {<br>
+                                    ((analysis_inter_data *)curFrame->m_analysisData.<wbr>interData)->mvpIdx[i][count + pu] = ((analysis_inter_data*)<wbr>analysis_data->interData)-><wbr>mvpIdx[i][d];<br>
+                                    ((analysis_inter_data *)curFrame->m_analysisData.<wbr>interData)->refIdx[i][count + pu] = ((analysis_inter_data*)<wbr>analysis_data->interData)-><wbr>refIdx[i][d];<br>
+                                    memcpy(&((analysis_inter_data *)curFrame->m_analysisData.<wbr>interData)->mv[i][count + pu], &((analysis_inter_data*)<wbr>analysis_data->interData)->mv[<wbr>i][d], sizeof(MV));<br>
</blockquote><div><br></div><div>Better to use a local pointer of type analysis_inter_data*.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">+                                }<br>
+                            }<br>
+                        }<br>
+                    }<br>
+                    count += bytes;<br>
+                }<br>
+            }<br>
+        }<br>
+        else<br>
+            setAnalysisDataAfterZScan(<wbr>analysis_data, curFrame);<br>
+<br>
+        curFrame->m_copyMVType.<wbr>trigger();<br>
+        return 0;<br>
+    }<br>
+    return -1;<br>
+}<br>
+<br>
 void Encoder::destroy()<br>
 {<br>
 #if ENABLE_HDR10_PLUS<br>
diff -r 563cbe1f4a21 -r 5ea4fdbdea99 source/encoder/encoder.h<br>
--- a/source/encoder/encoder.h  Wed Nov 08 17:08:18 2017 +0530<br>
+++ b/source/encoder/encoder.h  Mon Nov 13 12:20:50 2017 +0530<br>
@@ -212,6 +212,8 @@<br>
<br>
     int setAnalysisDataAfterZScan(<wbr>x265_analysis_data *analysis_data, Frame* curFrame);<br>
<br>
+    int setAnalysisData(x265_analysis_<wbr>data *analysis_data, int poc, uint32_t cuBytes);<br>
+<br>
     void getStreamHeaders(NALList& list, Entropy& sbacCoder, Bitstream& bs);<br>
<br>
     void fetchStats(x265_stats* stats, size_t statsSizeBytes);<br>
diff -r 563cbe1f4a21 -r 5ea4fdbdea99 source/<a href="http://x265.def.in" rel="noreferrer" target="_blank">x265.def.in</a><br>
--- a/source/<a href="http://x265.def.in" rel="noreferrer" target="_blank">x265.def.in</a>        Wed Nov 08 17:08:18 2017 +0530<br>
+++ b/source/<a href="http://x265.def.in" rel="noreferrer" target="_blank">x265.def.in</a>        Mon Nov 13 12:20:50 2017 +0530<br>
@@ -30,3 +30,4 @@<br>
 x265_csvlog_frame<br>
 x265_csvlog_encode<br>
 x265_dither_image<br>
+x265_set_analysis_data<br>
diff -r 563cbe1f4a21 -r 5ea4fdbdea99 source/x265.h<br>
--- a/source/x265.h     Wed Nov 08 17:08:18 2017 +0530<br>
+++ b/source/x265.h     Mon Nov 13 12:20:50 2017 +0530<br>
@@ -1743,6 +1743,11 @@<br>
  *     This API must be called after(poc >= lookaheadDepth + bframes + 2) condition check */<br>
 int x265_get_ref_frame_list(x265_<wbr>encoder *encoder, x265_picyuv**, x265_picyuv**, int, int);<br>
<br>
+/* x265_set_analysis_data:<br>
+ *     set the analysis data,<br>
+ *     returns negative on error, 0 access unit were output. */<br>
+int x265_set_analysis_data(x265_<wbr>encoder *encoder, x265_analysis_data *analysis_data, int poc, uint32_t cuBytes);<br>
+<br>
 void x265_cleanup(void);<br>
<br>
 /* Open a CSV log file. On success it returns a file handle which must be passed<br>
@@ -1816,6 +1821,7 @@<br>
     void          (*csvlog_frame)(const x265_param&, const x265_picture&);<br>
     void          (*csvlog_encode)(x265_encoder*<wbr>, const x265_stats&, int, char**);<br>
     void          (*dither_image)(x265_picture&, int, int, int16_t*, int);<br>
+    int           (*set_analysis_data)(x265_<wbr>encoder *encoder, x265_analysis_data *analysis_data, int poc, uint32_t cuBytes);<br>
     /* add new pointers to the end, or increment X265_MAJOR_VERSION */<br>
 } x265_api;<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>
</blockquote></div><br></div></div>