[x265] [PATCH 3 of 3] api: introduce x265_api_get()
Steve Borho
steve at borho.org
Wed Apr 1 22:39:14 CEST 2015
# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1427916381 18000
# Wed Apr 01 14:26:21 2015 -0500
# Node ID 87d5faa366339aca529c6798b4d95b8944b6e16f
# Parent 6cdd761a469295dc1bca00b15cea97b7f3dc97f3
api: introduce x265_api_get()
diff -r 6cdd761a4692 -r 87d5faa36633 source/encoder/api.cpp
--- a/source/encoder/api.cpp Wed Apr 01 14:44:19 2015 -0500
+++ b/source/encoder/api.cpp Wed Apr 01 14:26:21 2015 -0500
@@ -218,3 +218,45 @@
{
return x265_free(p);
}
+
+static const x265_api libapi =
+{
+ &x265_param_alloc,
+ &x265_param_free,
+ &x265_param_default,
+ &x265_param_parse,
+ &x265_param_apply_profile,
+ &x265_param_default_preset,
+ &x265_picture_alloc,
+ &x265_picture_free,
+ &x265_picture_init,
+ &x265_encoder_open,
+ &x265_encoder_parameters,
+ &x265_encoder_headers,
+ &x265_encoder_encode,
+ &x265_encoder_get_stats,
+ &x265_encoder_log,
+ &x265_encoder_close,
+ &x265_cleanup,
+ x265_version_str,
+ x265_build_info_str,
+ x265_max_bit_depth,
+};
+
+extern "C"
+const x265_api* x265_api_get(int buildNum, x265_param* p, int* err)
+{
+ if (buildNum != X265_BUILD)
+ {
+ if (err) *err = X265_API_VERSION_MISMATCH;
+ return NULL;
+ }
+
+ if (p && p->internalBitDepth != X265_DEPTH)
+ {
+ if (err) *err = X265_API_BITDEPTH_MISMATCH;
+ return NULL;
+ }
+
+ return &libapi;
+}
diff -r 6cdd761a4692 -r 87d5faa36633 source/x265.def.in
--- a/source/x265.def.in Wed Apr 01 14:44:19 2015 -0500
+++ b/source/x265.def.in Wed Apr 01 14:26:21 2015 -0500
@@ -19,3 +19,4 @@
x265_encoder_log
x265_encoder_close
x265_cleanup
+x265_api_get_${X265_BUILD}
diff -r 6cdd761a4692 -r 87d5faa36633 source/x265.h
--- a/source/x265.h Wed Apr 01 14:44:19 2015 -0500
+++ b/source/x265.h Wed Apr 01 14:26:21 2015 -0500
@@ -1232,6 +1232,62 @@
* release library static allocations, reset configured CTU size */
void x265_cleanup(void);
+
+/* === Multi-lib API ===
+ * By using this method to gain access to the libx265 interfaces, you allow shim
+ * implementations of x265_api_get() to choose between various available libx265
+ * libraries based on the encoder parameters. The most likely use case is to
+ * choose between 8bpp and 16bpp builds of libx265. */
+
+typedef struct x265_api
+{
+ /* libx265 public API functions, documented above with x265_ prefixes */
+ x265_param* (*param_alloc)(void);
+ void (*param_free)(x265_param*);
+ void (*param_default)(x265_param*);
+ int (*param_parse)(x265_param*, const char*, const char*);
+ int (*param_apply_profile)(x265_param*, const char*);
+ int (*param_default_preset)(x265_param*, const char*, const char *);
+ x265_picture* (*picture_alloc)(void);
+ void (*picture_free)(x265_picture*);
+ void (*picture_init)(x265_param*, x265_picture*);
+ x265_encoder* (*encoder_open)(x265_param*);
+ void (*encoder_parameters)(x265_encoder*, x265_param*);
+ int (*encoder_headers)(x265_encoder*, x265_nal**, uint32_t*);
+ int (*encoder_encode)(x265_encoder*, x265_nal**, uint32_t*, x265_picture*, x265_picture*);
+ void (*encoder_get_stats)(x265_encoder*, x265_stats*, uint32_t);
+ void (*encoder_log)(x265_encoder*, int, char**);
+ void (*encoder_close)(x265_encoder*);
+ void (*cleanup)(void);
+ const char* version_str;
+ const char* build_info_str;
+ int max_bit_depth;
+} x265_api;
+
+/* Force a link error in the case of linking against an incompatible API version.
+ * Glue #defines exist to force correct macro expansion; the final output of the macro
+ * is x265_api_get_##X265_BUILD (for purposes of dlopen). */
+#define x265_api_glue1(x, y) x ## y
+#define x265_api_glue2(x, y) x265_api_glue1(x, y)
+#define x265_api_get x265_api_glue2(x265_api_get_, X265_BUILD)
+
+/* x265_api_get:
+ * Retrieve the programming interface for a linked x265 library.
+ * If an API version mismatch is
+ * detected between the X265_BUILD number in the x265.h header you are
+ * compiling against and the library you are linking with, it will return NULL
+ * and set err to X265_API_VERSION_MISMATCH. If the param's internalBitDepth
+ * is not supported by any available library, it will return NULL and set err
+ * to X265_API_BITDEPTH_MISMATCH.
+ *
+ * buildNum must be set to X265_BUILD
+ * p may be NULL, in which case you will get the default libx265 API
+ * err may be NULL */
+#define X265_API_NO_ERROR 0
+#define X265_API_BITDEPTH_MISMATCH 1
+#define X265_API_VERSION_MISMATCH 2
+const x265_api* x265_api_get(int buildNum, x265_param* p, int* err);
+
#ifdef __cplusplus
}
#endif
More information about the x265-devel
mailing list