[x265] [PATCH] api: add error message and checks in api_get()

deepthi at multicorewareinc.com deepthi at multicorewareinc.com
Sat May 2 07:10:58 CEST 2015


# HG changeset patch
# User Deepthi Nandakumar <deepthi at multicorewareinc.com>
# Date 1430382464 -19800
#      Thu Apr 30 13:57:44 2015 +0530
# Node ID f00628524cf7fbf3703930f2e1b1d9e249b8ef5b
# Parent  57f8246c759db5fd8386036e92b3c134df02a4da
api: add error message and checks in api_get()

diff -r 57f8246c759d -r f00628524cf7 source/encoder/api.cpp
--- a/source/encoder/api.cpp	Wed Apr 29 19:40:08 2015 -0700
+++ b/source/encoder/api.cpp	Thu Apr 30 13:57:44 2015 +0530
@@ -281,7 +281,10 @@
         else if (bitDepth == 8)
             libname = "libx265_main" ext;
         else
+        {
+            x265_log(NULL, X265_LOG_WARNING, "bitdepth %d not supported\n", bitDepth);
             return NULL;
+        }
 
 #if _WIN32
         HMODULE h = LoadLibraryA(libname);
@@ -289,7 +292,14 @@
         {
             api_get_func get = (api_get_func)GetProcAddress(h, method);
             if (get)
+            {
+                if (bitDepth != get(bitDepth)->max_bit_depth)
+                {
+                    x265_log(NULL, X265_LOG_WARNING, "Detected build %s does not support requested bitDepth %d", libname, bitDepth);
+                    return NULL;
+                }
                 return get(bitDepth);
+            }
             else
                 x265_log(NULL, X265_LOG_WARNING, "Unable to bind %s from %s\n", method, libname);
         }
@@ -301,7 +311,14 @@
         {
             api_get_func get = (api_get_func)dlsym(h, method);
             if (get)
+            {
+                if (bitDepth != get(bitDepth)->max_bit_depth)
+                {
+                    x265_log(NULL, X265_LOG_WARNING, "Detected build %s does not support requested bitDepth %d", libname, bitDepth);
+                    return NULL;
+                }
                 return get(bitDepth);
+            }
             else
                 x265_log(NULL, X265_LOG_WARNING, "Unable to bind %s from %s\n", method, libname);
         }
diff -r 57f8246c759d -r f00628524cf7 source/x265.cpp
--- a/source/x265.cpp	Wed Apr 29 19:40:08 2015 -0700
+++ b/source/x265.cpp	Thu Apr 30 13:57:44 2015 +0530
@@ -29,7 +29,6 @@
 #include "output/output.h"
 #include "output/reconplay.h"
 #include "filters/filters.h"
-#include "common.h"
 #include "param.h"
 #include "cpu.h"
 #include "x265.h"
@@ -458,8 +457,12 @@
     GetConsoleTitle(orgConsoleTitle, CONSOLE_TITLE_SIZE);
     SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED);
 
-    const x265_api* api = x265_api_get(X265_DEPTH); /* Use 0 or X265_DEPTH to get what the cli was compiled against */
-
+    const x265_api* api = x265_api_get(0); /* Use 0 to get what the cli was compiled against */
+    if (!api)
+    {
+        /* The appropriate error message has been displayed by x265_api_get() already */
+        exit(1);
+    }
     ReconPlay* reconPlay = NULL;
     x265_param* param = api->param_alloc();
     CLIOptions cliopt;


More information about the x265-devel mailing list