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

Steve Borho steve at borho.org
Sat May 2 17:35:13 CEST 2015


On 05/02, deepthi at multicorewareinc.com wrote:
> # 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"

removing common.h is probably not correct, other things in this file
need it. This doesn't break the build because param.h includes it
itself, but removing it here is misleading

>  #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 you pass 0 to x265_api_get(), there is no need to check the returned
pointer, it is guarunteed to be non-null. The comment should say - use 0
to get linked libx265 native bit depth

> +    if (!api)
> +    {
> +        /* The appropriate error message has been displayed by x265_api_get() already */
> +        exit(1);

and fwiw, this is main() so you could just return 1

> +    }
>      ReconPlay* reconPlay = NULL;
>      x265_param* param = api->param_alloc();
>      CLIOptions cliopt;
> _______________________________________________
> x265-devel mailing list
> x265-devel at videolan.org
> https://mailman.videolan.org/listinfo/x265-devel

-- 
Steve Borho


More information about the x265-devel mailing list