[x265] [PATCH 2 of 4] api: introduce x265_alloc_analysis_data and x265_free_analysis_data methods to allocate and free analysis buffers

sagar at multicorewareinc.com sagar at multicorewareinc.com
Thu Sep 11 15:55:16 CEST 2014


# HG changeset patch
# User Sagar Kotecha <sagar at multicorewareinc.com>
# Date 1410443497 -19800
#      Thu Sep 11 19:21:37 2014 +0530
# Node ID 707d9fe762d987803aef15760cb4a6ff01965c32
# Parent  5524e76b14e4b532925cd094da039fe8fa0d2edc
api: introduce x265_alloc_analysis_data and x265_free_analysis_data methods to allocate and free analysis buffers

diff -r 5524e76b14e4 -r 707d9fe762d9 doc/reST/api.rst
--- a/doc/reST/api.rst	Thu Sep 11 19:18:40 2014 +0530
+++ b/doc/reST/api.rst	Thu Sep 11 19:21:37 2014 +0530
@@ -223,6 +223,37 @@
 	void x265_picture_free(x265_picture *);
 
 
+Analysis Buffers
+================
+
+Some of the analysis information can be reused to encode same clip with
+different bitrate. The best trend is to record the analysis information
+of higher bitrate encode and reuse it in future calls of lower bitrate
+encodes.
+
+The analysis information which can be reused among different bitrate is
+slice type, CU split decisions and luma directions for I frames and Motion 
+vectors for the P and B frames.
+
+Storage for analysis buffers of x265_picture can be allocated using::
+
+	/* x265_alloc_analysis_data:
+	 *  Allocate memory to hold analysis meta data, returns 1 on success else 0 */
+	int x265_alloc_analysis_data(x265_picture*);
+
+Analysis buffer can only be reused or released once they are available
+through output **x265_picture** as x265 does not allocate memory 
+for analysis buffer inside encoder.
+
+Analysis buffers allocated while recording or reusing should eventually be
+released::
+
+	/* x265_free_analysis_data:
+	 *  Use x265_free_analysis_data to release storage of members allocated by
+	 *  x265_alloc_analysis_data */
+	void x265_free_analysis_data(x265_picture*);
+
+
 Encode Process
 ==============
 
diff -r 5524e76b14e4 -r 707d9fe762d9 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Thu Sep 11 19:18:40 2014 +0530
+++ b/source/CMakeLists.txt	Thu Sep 11 19:21:37 2014 +0530
@@ -21,7 +21,7 @@
 include(CheckCXXCompilerFlag)
 
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 31)
+set(X265_BUILD 32)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r 5524e76b14e4 -r 707d9fe762d9 source/encoder/api.cpp
--- a/source/encoder/api.cpp	Thu Sep 11 19:18:40 2014 +0530
+++ b/source/encoder/api.cpp	Thu Sep 11 19:21:37 2014 +0530
@@ -189,6 +189,16 @@
     pic->bitDepth = param->internalBitDepth;
     pic->colorSpace = param->internalCsp;
     pic->forceqp = X265_QP_AUTO;
+    if (param->analysisMode)
+    {
+        uint32_t numPartitions   = 1 << g_maxFullDepth * 2;
+        uint32_t widthInCU       = (param->sourceWidth  + g_maxCUSize - 1) >> g_maxLog2CUSize;
+        uint32_t heightInCU      = (param->sourceHeight + g_maxCUSize - 1) >> g_maxLog2CUSize;
+
+        uint32_t numCUsInFrame   = widthInCU * heightInCU;
+        pic->analysisData.numCUsInFrame = numCUsInFrame;
+        pic->analysisData.numPartitions = numPartitions;
+    }
 }
 
 extern "C"
@@ -196,3 +206,36 @@
 {
     return x265_free(p);
 }
+
+int x265_alloc_analysis_data(x265_picture* pic)
+{
+    CHECKED_MALLOC(pic->analysisData.interData, x265_inter_data, pic->analysisData.numCUsInFrame * 85);
+    CHECKED_MALLOC(pic->analysisData.intraData, x265_intra_data, 1);
+    pic->analysisData.intraData->cuAddr     = NULL;
+    pic->analysisData.intraData->depth      = NULL;
+    pic->analysisData.intraData->modes      = NULL;
+    pic->analysisData.intraData->partSizes  = NULL;
+    pic->analysisData.intraData->poc        = NULL;
+    CHECKED_MALLOC(pic->analysisData.intraData->depth, uint8_t, pic->analysisData.numPartitions * pic->analysisData.numCUsInFrame);
+    CHECKED_MALLOC(pic->analysisData.intraData->modes, uint8_t, pic->analysisData.numPartitions * pic->analysisData.numCUsInFrame);
+    CHECKED_MALLOC(pic->analysisData.intraData->partSizes, char, pic->analysisData.numPartitions * pic->analysisData.numCUsInFrame);
+    CHECKED_MALLOC(pic->analysisData.intraData->cuAddr, uint32_t, pic->analysisData.numCUsInFrame);
+    CHECKED_MALLOC(pic->analysisData.intraData->poc, int, pic->analysisData.numCUsInFrame);
+    return 1;
+fail:
+    x265_free_analysis_data(pic);
+    return 0;
+}
+
+void x265_free_analysis_data(x265_picture* pic)
+{
+    X265_FREE(pic->analysisData.interData);
+    pic->analysisData.interData = NULL;
+    X265_FREE(pic->analysisData.intraData->depth);
+    X265_FREE(pic->analysisData.intraData->modes);
+    X265_FREE(pic->analysisData.intraData->partSizes);
+    X265_FREE(pic->analysisData.intraData->cuAddr);
+    X265_FREE(pic->analysisData.intraData->poc);
+    X265_FREE(pic->analysisData.intraData);
+    pic->analysisData.intraData = NULL;
+}
diff -r 5524e76b14e4 -r 707d9fe762d9 source/x265.def.in
--- a/source/x265.def.in	Thu Sep 11 19:18:40 2014 +0530
+++ b/source/x265.def.in	Thu Sep 11 19:21:37 2014 +0530
@@ -9,6 +9,8 @@
 x265_picture_init
 x265_picture_alloc
 x265_picture_free
+x265_alloc_analysis_data
+x265_free_analysis_data
 x265_param_apply_profile
 x265_max_bit_depth
 x265_version_str
diff -r 5524e76b14e4 -r 707d9fe762d9 source/x265.h
--- a/source/x265.h	Thu Sep 11 19:18:40 2014 +0530
+++ b/source/x265.h	Thu Sep 11 19:21:37 2014 +0530
@@ -1027,6 +1027,15 @@
  *  allocated by x265_picture_alloc() */
 void x265_picture_free(x265_picture *);
 
+/* x265_alloc_analysis_data:
+ *  Allocate memory to hold analysis data, returns 1 on success else 0 */
+int x265_alloc_analysis_data(x265_picture*);
+
+/* x265_free_analysis_data:
+ *  Use x265_free_analysis_data to release storage of members allocated by
+ *  x265_alloc_analysis_data */
+void x265_free_analysis_data(x265_picture*);
+
 /***
  * Initialize an x265_picture structure to default values. It sets the pixel
  * depth and color space to the encoder's internal values and sets the slice


More information about the x265-devel mailing list