[x265] [PATCH 2 of 4] api: introduce x265_alloc_analysis_data and x265_free_analysis_data methods to allocate and free analysis info

Steve Borho steve at borho.org
Wed Sep 10 15:27:35 CEST 2014


On 09/10, sagar at multicorewareinc.com wrote:
> # HG changeset patch
> # User Sagar Kotecha <sagar at multicorewareinc.com>
> # Date 1410350810 -19800
> #      Wed Sep 10 17:36:50 2014 +0530
> # Node ID 3e8e21de35c0dcae20dd0e3a8e2ccede69612da7
> # Parent  177916d7a3089e90c973dd5dc7428bf68df728d0
> api: introduce x265_alloc_analysis_data and x265_free_analysis_data methods to allocate and free analysis info
> 
> diff -r 177916d7a308 -r 3e8e21de35c0 source/CMakeLists.txt
> --- a/source/CMakeLists.txt	Wed Sep 10 17:35:15 2014 +0530
> +++ b/source/CMakeLists.txt	Wed Sep 10 17:36:50 2014 +0530
> @@ -21,7 +21,7 @@
>  include(CheckCXXCompilerFlag)
>  
>  # X265_BUILD must be incremented each time the public API is changed
> -set(X265_BUILD 31)
> +set(X265_BUILD 32)
>  configure_file("${PROJECT_SOURCE_DIR}/x265.def.in"
>                 "${PROJECT_BINARY_DIR}/x265.def")
>  configure_file("${PROJECT_SOURCE_DIR}/x265_config.h.in"
> diff -r 177916d7a308 -r 3e8e21de35c0 source/encoder/api.cpp
> --- a/source/encoder/api.cpp	Wed Sep 10 17:35:15 2014 +0530
> +++ b/source/encoder/api.cpp	Wed Sep 10 17:36:50 2014 +0530
> @@ -196,3 +196,52 @@
>  {
>      return x265_free(p);
>  }
> +
> +int x265_alloc_analysis_data(x265_picture* pic, x265_param* param)
> +{
> +    uint32_t numPartitions   = 1 << g_maxFullDepth * 2;
> +    uint32_t widthInCU       = (param->sourceWidth  + g_maxCUSize - 1) >> g_maxLog2CUSize;
> +    uint32_t heightInCU      = (param->sourceHeight + g_maxCUSize - 1) >> g_maxLog2CUSize;
> +
> +    uint32_t numCUsInFrame   = widthInCU * heightInCU;
> +    pic->analysisData.numCUsInFrame = numCUsInFrame;
> +    pic->analysisData.numPartitions = numPartitions;
> +
> +    CHECKED_MALLOC(pic->analysisData.interData, x265_inter_data, numCUsInFrame * 85);
> +    CHECKED_MALLOC(pic->analysisData.intraData, x265_intra_data, 1);
> +    pic->analysisData.intraData->cuAddr     = NULL;
> +    pic->analysisData.intraData->depth      = NULL;
> +    pic->analysisData.intraData->modes      = NULL;
> +    pic->analysisData.intraData->partSizes  = NULL;
> +    pic->analysisData.intraData->poc        = NULL;
> +    CHECKED_MALLOC(pic->analysisData.intraData->depth, uint8_t, numPartitions * numCUsInFrame);
> +    CHECKED_MALLOC(pic->analysisData.intraData->modes, uint8_t, numPartitions * numCUsInFrame);
> +    CHECKED_MALLOC(pic->analysisData.intraData->partSizes, char, numPartitions * numCUsInFrame);
> +    CHECKED_MALLOC(pic->analysisData.intraData->cuAddr, uint32_t, numCUsInFrame);
> +    CHECKED_MALLOC(pic->analysisData.intraData->poc, int, numCUsInFrame);
> +    return 1;
> +
> +fail:
> +    x265_log(NULL, X265_LOG_WARNING, "unable to allocate memory analysis buffers");

the log is redundant, CHECKED_MALLOC() will squawk if a malloc fails

> +    x265_free_analysis_data(pic);
> +    return 0;
> +}
> +
> +void x265_free_analysis_data(x265_picture* pic)
> +{
> +    if (pic->analysisData.interData)
> +        X265_FREE(pic->analysisData.interData);

the if() is redundant, null is checked inside X265_FREE

> +
> +    if (pic->analysisData.intraData)
> +    {
> +        X265_FREE(pic->analysisData.intraData->depth);
> +        X265_FREE(pic->analysisData.intraData->modes);
> +        X265_FREE(pic->analysisData.intraData->partSizes);
> +        X265_FREE(pic->analysisData.intraData->cuAddr);
> +        X265_FREE(pic->analysisData.intraData->poc);
> +        X265_FREE(pic->analysisData.intraData);
> +    }
> +
> +    pic->analysisData.interData = NULL;
> +    pic->analysisData.intraData = NULL;
> +}
> diff -r 177916d7a308 -r 3e8e21de35c0 source/x265.def.in
> --- a/source/x265.def.in	Wed Sep 10 17:35:15 2014 +0530
> +++ b/source/x265.def.in	Wed Sep 10 17:36:50 2014 +0530
> @@ -9,6 +9,8 @@
>  x265_picture_init
>  x265_picture_alloc
>  x265_picture_free
> +x265_alloc_analysis_data
> +x265_free_analysis_data
>  x265_param_apply_profile
>  x265_max_bit_depth
>  x265_version_str
> diff -r 177916d7a308 -r 3e8e21de35c0 source/x265.h
> --- a/source/x265.h	Wed Sep 10 17:35:15 2014 +0530
> +++ b/source/x265.h	Wed Sep 10 17:36:50 2014 +0530
> @@ -1029,6 +1029,15 @@
>   *  allocated by x265_picture_alloc() */
>  void x265_picture_free(x265_picture *);
>  
> +/* x265_alloc_analysis_data:
> + *  Allocate memory to hold analysis meta data, returns 1 on success else 0 */
> +int x265_alloc_analysis_data(x265_picture*, x265_param*);
> +
> +/* x265_free_analysis_data:
> + *  Use x265_free_analysis_data to release storage of members allocated by
> + *  x265_alloc_analysis_data */
> +void x265_free_analysis_data(x265_picture*);
> +
>  /***
>   * Initialize an x265_picture structure to default values. It sets the pixel
>   * depth and color space to the encoder's internal values and sets the slice
> _______________________________________________
> 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