[x265] [PATCH 2 of 2] api: fallback to multilib library if profile-named library not found (refs #156)
Steve Borho
steve at borho.org
Fri Aug 14 15:12:25 CEST 2015
# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1439550912 -19800
# Fri Aug 14 16:45:12 2015 +0530
# Node ID b7c1efea98a9c91d92983dab02828c03a7a44139
# Parent 598a3eee33da4bb4b5bea2ad098fa30724a0cb2f
api: fallback to multilib library if profile-named library not found (refs #156)
If you call x265_api_get(10) and libx265_main10.dll is not found, it will now
fallback to trying to bind libx265.dll and request bitDepth 10 from that library
(in the hope that it is a multilib library supporting all bit depths)
diff -r 598a3eee33da -r b7c1efea98a9 doc/reST/api.rst
--- a/doc/reST/api.rst Fri Aug 14 16:28:19 2015 +0530
+++ b/doc/reST/api.rst Fri Aug 14 16:45:12 2015 +0530
@@ -485,6 +485,10 @@
10-bit: libx265_main10
12-bit: libx265_main12
+If the profile-named library is not found, it will then try to bind a
+generic libx265 in the hopes that it is a multilib library with all bit
+depths.
+
Packaging and Distribution
--------------------------
diff -r 598a3eee33da -r b7c1efea98a9 source/encoder/api.cpp
--- a/source/encoder/api.cpp Fri Aug 14 16:28:19 2015 +0530
+++ b/source/encoder/api.cpp Fri Aug 14 16:45:12 2015 +0530
@@ -353,6 +353,7 @@
const char* libname = NULL;
const char* method = "x265_api_get_" xstr(X265_BUILD);
+ const char* multilibname = "libx265" ext;
if (bitDepth == 12)
libname = "libx265_main12" ext;
@@ -364,22 +365,33 @@
return NULL;
const x265_api* api = NULL;
+ int reqDepth = 0;
#if _WIN32
HMODULE h = LoadLibraryA(libname);
+ if (!h)
+ {
+ h = LoadLibraryA(multilibname);
+ reqDepth = bitDepth;
+ }
if (h)
{
api_get_func get = (api_get_func)GetProcAddress(h, method);
if (get)
- api = get(0);
+ api = get(reqDepth);
}
#else
void* h = dlopen(libname, RTLD_LAZY | RTLD_LOCAL);
+ if (!h)
+ {
+ h = dlopen(multilibname, RTLD_LAZY | RTLD_LOCAL);
+ reqDepth = bitDepth;
+ }
if (h)
{
api_get_func get = (api_get_func)dlsym(h, method);
if (get)
- api = get(0);
+ api = get(reqDepth);
}
#endif
@@ -420,6 +432,7 @@
const char* libname = NULL;
const char* method = "x265_api_query";
+ const char* multilibname = "libx265" ext;
if (bitDepth == 12)
libname = "libx265_main12" ext;
@@ -434,25 +447,36 @@
}
const x265_api* api = NULL;
+ int reqDepth = 0;
int e = X265_API_QUERY_ERR_LIB_NOT_FOUND;
#if _WIN32
HMODULE h = LoadLibraryA(libname);
+ if (!h)
+ {
+ h = LoadLibraryA(multilibname);
+ reqDepth = bitDepth;
+ }
if (h)
{
e = X265_API_QUERY_ERR_FUNC_NOT_FOUND;
api_query_func query = (api_query_func)GetProcAddress(h, method);
if (query)
- api = query(bitDepth, apiVersion, err);
+ api = query(reqDepth, apiVersion, err);
}
#else
void* h = dlopen(libname, RTLD_LAZY | RTLD_LOCAL);
+ if (!h)
+ {
+ h = dlopen(multilibname, RTLD_LAZY | RTLD_LOCAL);
+ reqDepth = bitDepth;
+ }
if (h)
{
e = X265_API_QUERY_ERR_FUNC_NOT_FOUND;
api_query_func query = (api_query_func)dlsym(h, method);
if (query)
- api = query(bitDepth, apiVersion, err);
+ api = query(reqDepth, apiVersion, err);
}
#endif
More information about the x265-devel
mailing list