[x265] [PATCH 3 of 4 RFC] param: make encoder lib use private param functions when not exporting C API

Steve Borho steve at borho.org
Fri Jun 5 20:28:04 CEST 2015


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1433525848 18000
#      Fri Jun 05 12:37:28 2015 -0500
# Node ID 278269d260a3d62530995d167310eb79bba4009f
# Parent  899dba6c252cb75f5efa4ea5c7a575bcb65118eb
param: make encoder lib use private param functions when not exporting C API

diff -r 899dba6c252c -r 278269d260a3 source/common/param.h
--- a/source/common/param.h	Fri Jun 05 13:15:32 2015 -0500
+++ b/source/common/param.h	Fri Jun 05 12:37:28 2015 -0500
@@ -41,6 +41,19 @@
 /* this table is kept internal to avoid confusion, since log level indices start at -1 */
 static const char * const logLevelNames[] = { "none", "error", "warning", "info", "frame", "debug", "full", 0 };
 
+#if EXPORT_C_API
+#define PARAM_NS
+#else
+/* declare param functions within private namespace */
+void x265_param_free(x265_param *);
+x265_param* x265_param_alloc();
+void x265_param_default(x265_param *param);
+int x265_param_default_preset(x265_param *, const char *preset, const char *tune);
+int x265_param_apply_profile(x265_param *, const char *profile);
+int x265_param_parse(x265_param *p, const char *name, const char *value);
+#define PARAM_NS X265_NS
+#endif
+
 #define MAXPARAMSIZE 2000
 }
 
diff -r 899dba6c252c -r 278269d260a3 source/encoder/api.cpp
--- a/source/encoder/api.cpp	Fri Jun 05 13:15:32 2015 -0500
+++ b/source/encoder/api.cpp	Fri Jun 05 12:37:28 2015 -0500
@@ -50,8 +50,8 @@
         return NULL;
 
     Encoder* encoder = NULL;
-    x265_param* param = x265_param_alloc();
-    x265_param* latestParam = x265_param_alloc();
+    x265_param* param = PARAM_NS::x265_param_alloc();
+    x265_param* latestParam = PARAM_NS::x265_param_alloc();
     if (!param || !latestParam)
         goto fail;
 
@@ -69,7 +69,7 @@
 
     encoder = new Encoder;
     if (!param->rc.bEnableSlowFirstPass)
-        x265_param_apply_fastfirstpass(param);
+        PARAM_NS::x265_param_apply_fastfirstpass(param);
 
     // may change params for auto-detect, etc
     encoder->configure(param);
@@ -97,8 +97,8 @@
 
 fail:
     delete encoder;
-    x265_param_free(param);
-    x265_param_free(latestParam);
+    PARAM_NS::x265_param_free(param);
+    PARAM_NS::x265_param_free(latestParam);
     return NULL;
 }
 
@@ -264,12 +264,12 @@
     x265_version_str,
     x265_build_info_str,
 
-    &x265_param_alloc,
-    &x265_param_free,
-    &x265_param_default,
-    &x265_param_parse,
-    &x265_param_apply_profile,
-    &x265_param_default_preset,
+    &PARAM_NS::x265_param_alloc,
+    &PARAM_NS::x265_param_free,
+    &PARAM_NS::x265_param_default,
+    &PARAM_NS::x265_param_parse,
+    &PARAM_NS::x265_param_apply_profile,
+    &PARAM_NS::x265_param_default_preset,
     &x265_picture_alloc,
     &x265_picture_free,
     &x265_picture_init,
diff -r 899dba6c252c -r 278269d260a3 source/encoder/encoder.cpp
--- a/source/encoder/encoder.cpp	Fri Jun 05 13:15:32 2015 -0500
+++ b/source/encoder/encoder.cpp	Fri Jun 05 12:37:28 2015 -0500
@@ -386,10 +386,10 @@
         free((char*)m_param->masteringDisplayColorVolume);
         free((char*)m_param->contentLightLevelInfo);
 
-        x265_param_free(m_param);
+        PARAM_NS::x265_param_free(m_param);
     }
 
-    x265_param_free(m_latestParam);
+    PARAM_NS::x265_param_free(m_latestParam);
 }
 
 void Encoder::updateVbvPlan(RateControl* rc)
diff -r 899dba6c252c -r 278269d260a3 source/encoder/level.cpp
--- a/source/encoder/level.cpp	Fri Jun 05 13:15:32 2015 -0500
+++ b/source/encoder/level.cpp	Fri Jun 05 12:37:28 2015 -0500
@@ -342,8 +342,21 @@
 
     return true;
 }
+}
 
-extern "C"
+#if EXPORT_C_API
+
+/* these functions are exported as C functions (default) */
+using namespace X265_NS;
+extern "C" {
+
+#else
+
+/* these functions exist within private namespace (multilib) */
+namespace X265_NS {
+
+#endif
+
 int x265_param_apply_profile(x265_param *param, const char *profile)
 {
     if (!param || !profile)


More information about the x265-devel mailing list