[x265] [PATCH] api: allow x265_cleanup() to reset the configured CTU size (closes #110)

Steve Borho steve at borho.org
Wed Mar 18 02:10:14 CET 2015


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1426640887 18000
#      Tue Mar 17 20:08:07 2015 -0500
# Node ID c4892a23733c006bccc52fd4fa74cab6c20ac7da
# Parent  a981d35ef9d035f9db809740952cdd95777639c2
api: allow x265_cleanup() to reset the configured CTU size (closes #110)

x265_cleanup() is intended to be called after all encoders are closed, so it is
safe to 'forget' the global CTU configuration.

diff -r a981d35ef9d0 -r c4892a23733c doc/reST/api.rst
--- a/doc/reST/api.rst	Tue Mar 17 19:30:51 2015 -0500
+++ b/doc/reST/api.rst	Tue Mar 17 20:08:07 2015 -0500
@@ -72,6 +72,8 @@
 	process. All of the encoders must use the same maximum CTU size
 	because many global variables are configured based on this size.
 	Encoder allocation will fail if a mis-matched CTU size is attempted.
+	If no encoders are open, **x265_cleanup()** can be called to reset
+	the configured CTU size so a new size can be used.
 
 An encoder is allocated by calling **x265_encoder_open()**::
 
@@ -337,10 +339,12 @@
 	void x265_encoder_close(x265_encoder *);
 
 When the application has completed all encodes, it should call
-**x265_cleanup()** to free process global resources like the thread pool;
-particularly if a memory-leak detection tool is being used::
+**x265_cleanup()** to free process global, particularly if a memory-leak
+detection tool is being used. **x265_cleanup()** also resets the saved
+CTU size so it will be possible to create a new encoder with a different
+CTU size::
 
 	/***
-	 * Release library static allocations
+	 * Release library static allocations, reset configured CTU size
 	 */
 	void x265_cleanup(void);
diff -r a981d35ef9d0 -r c4892a23733c source/CMakeLists.txt
--- a/source/CMakeLists.txt	Tue Mar 17 19:30:51 2015 -0500
+++ b/source/CMakeLists.txt	Tue Mar 17 20:08:07 2015 -0500
@@ -21,7 +21,7 @@
 include(CheckCXXCompilerFlag)
 
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 48)
+set(X265_BUILD 49)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r a981d35ef9d0 -r c4892a23733c source/common/constants.cpp
--- a/source/common/constants.cpp	Tue Mar 17 19:30:51 2015 -0500
+++ b/source/common/constants.cpp	Tue Mar 17 20:08:07 2015 -0500
@@ -119,6 +119,7 @@
     65535
 };
 
+int      g_ctuSizeConfigured = 0;
 uint32_t g_maxLog2CUSize = MAX_LOG2_CU_SIZE;
 uint32_t g_maxCUSize     = MAX_CU_SIZE;
 uint32_t g_unitSizeDepth = NUM_CU_DEPTH;
diff -r a981d35ef9d0 -r c4892a23733c source/common/constants.h
--- a/source/common/constants.h	Tue Mar 17 19:30:51 2015 -0500
+++ b/source/common/constants.h	Tue Mar 17 20:08:07 2015 -0500
@@ -29,6 +29,8 @@
 namespace x265 {
 // private namespace
 
+extern int g_ctuSizeConfigured;
+
 void initZscanToRaster(uint32_t maxFullDepth, uint32_t depth, uint32_t startVal, uint32_t*& curIdx);
 void initRasterToZscan(uint32_t maxFullDepth);
 
diff -r a981d35ef9d0 -r c4892a23733c source/common/param.cpp
--- a/source/common/param.cpp	Tue Mar 17 19:30:51 2015 -0500
+++ b/source/common/param.cpp	Tue Mar 17 20:08:07 2015 -0500
@@ -1172,12 +1172,10 @@
 
 int x265_set_globals(x265_param* param)
 {
-    static int once /* = 0 */;
-
     uint32_t maxLog2CUSize = (uint32_t)g_log2Size[param->maxCUSize];
     uint32_t minLog2CUSize = (uint32_t)g_log2Size[param->minCUSize];
 
-    if (ATOMIC_INC(&once) > 1)
+    if (g_ctuSizeConfigured || ATOMIC_INC(&g_ctuSizeConfigured) > 1)
     {
         if (g_maxCUSize != param->maxCUSize)
         {
diff -r a981d35ef9d0 -r c4892a23733c source/encoder/api.cpp
--- a/source/encoder/api.cpp	Tue Mar 17 19:30:51 2015 -0500
+++ b/source/encoder/api.cpp	Tue Mar 17 20:08:07 2015 -0500
@@ -184,6 +184,8 @@
 void x265_cleanup(void)
 {
     BitCost::destroy();
+    CUData::s_partSet[0] = NULL; /* allow CUData to adjust to new CTU size */
+    g_ctuSizeConfigured = 0;
 }
 
 extern "C"
diff -r a981d35ef9d0 -r c4892a23733c source/x265.h
--- a/source/x265.h	Tue Mar 17 19:30:51 2015 -0500
+++ b/source/x265.h	Tue Mar 17 20:08:07 2015 -0500
@@ -622,7 +622,8 @@
      * complexity, greatly improving compression efficiency at large
      * resolutions.  The smaller the size, the more effective wavefront and
      * frame parallelism will become because of the increase in rows. default 64
-     * All encoders within the same process must use the same maxCUSize. */
+     * All encoders within the same process must use the same maxCUSize, until
+     * all encoders are closed and x265_cleanup() is called to reset the value. */
     uint32_t  maxCUSize;
 
     /* Miniumum CU width and height in pixels.  The size must be 64, 32, 16, or
@@ -1225,7 +1226,7 @@
 void x265_encoder_close(x265_encoder *);
 
 /***
- * Release library static allocations
+ * Release library static allocations, reset configured CTU size
  */
 void x265_cleanup(void);
 


More information about the x265-devel mailing list