[x265] [PATCH] api: introduce x265_encoder_parameters(), copy param earlier to avoid mods

Steve Borho steve at borho.org
Thu May 15 16:34:22 CEST 2014


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1400123049 -19800
#      Thu May 15 08:34:09 2014 +0530
# Node ID d05faf9cdf56ab30be0fab2369574fa383a1be2a
# Parent  81fea15ba686be53e4f83e5d9fc903725a49b586
api: introduce x265_encoder_parameters(), copy param earlier to avoid mods

in x265_encoder_open(), make a copy of the provided param structure much earlier
to avoid making any changes to the param strucutre provided by the user, in
case they want to use that same param again to allocate another encoder.

diff -r 81fea15ba686 -r d05faf9cdf56 doc/reST/api.rst
--- a/doc/reST/api.rst	Thu May 15 07:48:51 2014 +0530
+++ b/doc/reST/api.rst	Thu May 15 08:34:09 2014 +0530
@@ -136,7 +136,7 @@
 	int x265_param_parse(x265_param *p, const char *name, const char *value);
 
 See :ref:`string options <string-options-ref>` for the list of options (and their
-descriptions) which can be set by **x265_param_parse**.
+descriptions) which can be set by **x265_param_parse()**.
 
 After the encoder has been created, you may release the param structure::
 
@@ -153,6 +153,18 @@
 	x265 that does not match the version of the header you are compiling
 	against. This is function of the X265_BUILD macro.
 
+**x265_encoder_parameters()** may be used to get a copy of the param
+structure from the encoder after it has been opened, in order to see the
+changes made to the parameters for auto-detection and other reasons::
+
+	/* x265_encoder_parameters:
+	 *      copies the current internal set of parameters to the pointer provided
+	 *      by the caller.  useful when the calling application needs to know
+	 *      how x265_encoder_open has changed the parameters.
+	 *      note that the data accessible through pointers in the returned param struct
+	 *      (e.g. filenames) should not be modified by the calling application. */
+	void x265_encoder_parameters(x265_encoder *, x265_param *);                                                                      
+
 Pictures
 ========
 
diff -r 81fea15ba686 -r d05faf9cdf56 source/CMakeLists.txt
--- a/source/CMakeLists.txt	Thu May 15 07:48:51 2014 +0530
+++ b/source/CMakeLists.txt	Thu May 15 08:34:09 2014 +0530
@@ -19,7 +19,7 @@
 include(CheckCXXCompilerFlag)
 
 # X265_BUILD must be incremented each time the public API is changed
-set(X265_BUILD 17)
+set(X265_BUILD 18)
 configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
                "${PROJECT_BINARY_DIR}/x265.def")
 configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
diff -r 81fea15ba686 -r d05faf9cdf56 source/encoder/api.cpp
--- a/source/encoder/api.cpp	Thu May 15 07:48:51 2014 +0530
+++ b/source/encoder/api.cpp	Thu May 15 08:34:09 2014 +0530
@@ -30,11 +30,16 @@
 using namespace x265;
 
 extern "C"
-x265_encoder *x265_encoder_open(x265_param *param)
+x265_encoder *x265_encoder_open(x265_param *p)
 {
+    if (!p)
+        return NULL;
+
+    x265_param *param = X265_MALLOC(x265_param, 1);
     if (!param)
         return NULL;
 
+    memcpy(param, p, sizeof(x265_param));
     x265_log(param, X265_LOG_INFO, "HEVC encoder version %s\n", x265_version_str);
     x265_log(param, X265_LOG_INFO, "build info %s\n", x265_build_info_str);
 
@@ -53,14 +58,6 @@
         encoder->configure(param);
         determineLevel(*param, encoder->m_profile, encoder->m_level, encoder->m_levelTier);
 
-        encoder->param = X265_MALLOC(x265_param, 1);
-        if (!encoder->param)
-        {
-            encoder->destroy();
-            return NULL;
-        }
-
-        memcpy(encoder->param, param, sizeof(x265_param));
         x265_print_params(param);
         encoder->create();
         encoder->init();
@@ -104,6 +101,16 @@
 }
 
 extern "C"
+void x265_encoder_parameters(x265_encoder *enc, x265_param *out)
+{
+    if (enc && out)
+    {
+        Encoder *encoder = static_cast<Encoder*>(enc);
+        memcpy(out, encoder->param, sizeof(x265_param));
+    }
+}
+
+extern "C"
 int x265_encoder_encode(x265_encoder *enc, x265_nal **pp_nal, uint32_t *pi_nal, x265_picture *pic_in, x265_picture *pic_out)
 {
     if (!enc)
diff -r 81fea15ba686 -r d05faf9cdf56 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Thu May 15 07:48:51 2014 +0530
+++ b/source/encoder/encoder.cpp	Thu May 15 08:34:09 2014 +0530
@@ -1199,6 +1199,8 @@
 
 void Encoder::configure(x265_param *p)
 {
+    this->param = p;
+
     // Trim the thread pool if WPP is disabled
     if (!p->bEnableWavefront)
         p->poolNumThreads = 1;
diff -r 81fea15ba686 -r d05faf9cdf56 source/x265.def.in
--- a/source/x265.def.in	Thu May 15 07:48:51 2014 +0530
+++ b/source/x265.def.in	Thu May 15 08:34:09 2014 +0530
@@ -14,6 +14,7 @@
 x265_version_str
 x265_build_info_str
 x265_encoder_headers
+x265_encoder_parameters
 x265_encoder_encode
 x265_encoder_get_stats
 x265_encoder_log
diff -r 81fea15ba686 -r d05faf9cdf56 source/x265.h
--- a/source/x265.h	Thu May 15 07:48:51 2014 +0530
+++ b/source/x265.h	Thu May 15 08:34:09 2014 +0530
@@ -915,6 +915,14 @@
  *      create a new encoder handler, all parameters from x265_param are copied */
 x265_encoder* x265_encoder_open(x265_param *);
 
+/* x265_encoder_parameters:
+ *      copies the current internal set of parameters to the pointer provided
+ *      by the caller.  useful when the calling application needs to know
+ *      how x265_encoder_open has changed the parameters.
+ *      note that the data accessible through pointers in the returned param struct
+ *      (e.g. filenames) should not be modified by the calling application. */
+void x265_encoder_parameters(x265_encoder *, x265_param *);                                                                      
+
 /* x265_encoder_headers:
  *      return the SPS and PPS that will be used for the whole stream.
  *      *pi_nal is the number of NAL units outputted in pp_nal.


More information about the x265-devel mailing list