[x265] api: change name of 32-bit dll from libx265.dll to libx265-32.dll

Mateusz mateuszb at poczta.onet.pl
Sun May 29 08:51:27 CEST 2016


# HG changeset patch
# User Ma0 <mateuszb at poczta.onet.pl>
# Date 1464479547 -7200
#      Sun May 29 01:52:27 2016 +0200
# Node ID ef28abdc61591385c52b8ba8324ab326be1df8df
# Parent  aeade2e8d8688ebffb8455b8948d89d6a72e2c38
api: change name of 32-bit dll from libx265.dll to libx265-32.dll

diff -r aeade2e8d868 -r ef28abdc6159 source/encoder/api.cpp
--- a/source/encoder/api.cpp    Thu May 26 16:45:09 2016 +0530
+++ b/source/encoder/api.cpp    Sun May 29 01:52:27 2016 +0200
@@ -351,7 +351,11 @@
 #define ext ".so"
 #endif
 
-static int g_recursion /* = 0 */;
+#if X265_ARCH_X86 && !X86_64
+#define X265_DLL_BASENAME "libx265-32"
+#else
+#define X265_DLL_BASENAME "libx265"
+#endif
 
 const x265_api* x265_api_get(int bitDepth)
 {
@@ -369,50 +373,70 @@
 
         const char* libname = NULL;
         const char* method = "x265_api_get_" xstr(X265_BUILD);
-        const char* multilibname = "libx265" ext;
+        const char* multilibname = X265_DLL_BASENAME ext;
 
         if (bitDepth == 12)
-            libname = "libx265_main12" ext;
+            libname = X265_DLL_BASENAME "_main12" ext;
         else if (bitDepth == 10)
-            libname = "libx265_main10" ext;
+            libname = X265_DLL_BASENAME "_main10" ext;
         else if (bitDepth == 8)
-            libname = "libx265_main" ext;
+            libname = X265_DLL_BASENAME "_main" ext;
         else
             return NULL;
 
         const x265_api* api = NULL;
-        int reqDepth = 0;
+        static int g_recursion /* = 0 */;
 
-        if (g_recursion > 1)
+        if (g_recursion)
             return NULL;
         else
             g_recursion++;
 
 #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(reqDepth);
+                api = get(bitDepth);
+        }
+        if (!api)
+        {
+            if (h)
+                FreeLibrary(h);
+            libname = multilibname;
+            h = LoadLibraryA(libname);
+            if (h)
+            {
+                api_get_func get = (api_get_func)GetProcAddress(h, method);
+                if (get)
+                    api = get(bitDepth);
+                if (!api)
+                    FreeLibrary(h);
+            }
         }
 #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(reqDepth);
+                api = get(bitDepth);
+        }
+        if (!api)
+        {
+            if (h)
+                dlclose(h);
+            libname = multilibname;
+            h = dlopen(libname, RTLD_LAZY | RTLD_LOCAL);
+            if (h)
+            {
+                api_get_func get = (api_get_func)dlsym(h, method);
+                if (get)
+                    api = get(bitDepth);
+                if (!api)
+                    dlclose(h);
+            }
         }
 #endif
 
@@ -455,14 +479,14 @@
 
         const char* libname = NULL;
         const char* method = "x265_api_query";
-        const char* multilibname = "libx265" ext;
+        const char* multilibname = X265_DLL_BASENAME ext;
 
         if (bitDepth == 12)
-            libname = "libx265_main12" ext;
+            libname = X265_DLL_BASENAME "_main12" ext;
         else if (bitDepth == 10)
-            libname = "libx265_main10" ext;
+            libname = X265_DLL_BASENAME "_main10" ext;
         else if (bitDepth == 8)
-            libname = "libx265_main" ext;
+            libname = X265_DLL_BASENAME "_main" ext;
         else
         {
             if (err) *err = X265_API_QUERY_ERR_LIB_NOT_FOUND;
@@ -470,10 +494,10 @@
         }
 
         const x265_api* api = NULL;
-        int reqDepth = 0;
         int e = X265_API_QUERY_ERR_LIB_NOT_FOUND;
+        static int g_recursion /* = 0 */;
 
-        if (g_recursion > 1)
+        if (g_recursion)
         {
             if (err) *err = X265_API_QUERY_ERR_LIB_NOT_FOUND;
             return NULL;
@@ -483,31 +507,53 @@
 
 #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(reqDepth, apiVersion, err);
+                api = query(bitDepth, apiVersion, err);
+        }
+        if (!api)
+        {
+            if (h)
+                FreeLibrary(h);
+            libname = multilibname;
+            h = LoadLibraryA(libname);
+            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);
+                if (!api)
+                    FreeLibrary(h);
+            }
         }
 #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(reqDepth, apiVersion, err);
+                api = query(bitDepth, apiVersion, err);
+        }
+        if (!api)
+        {
+            if (h)
+                dlclose(h);
+            libname = multilibname;
+            h = dlopen(libname, RTLD_LAZY | RTLD_LOCAL);
+            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);
+                if (!api)
+                    dlclose(h);
+            }
         }
 #endif
 



More information about the x265-devel mailing list