From 5352d1ae0ceb4a13c1532d26cbe131779772175e Mon Sep 17 00:00:00 2001 From: Sarabjeet Singh Date: Thu, 20 Sep 2018 20:47:25 -0700 Subject: [PATCH] Updated XMA code merged from git enterprise --- src/xma/CMakeLists.txt | 1 - src/xma/include/app/xmabuffers.h | 11 ++++++++--- src/xma/include/app/xmadecoder.h | 5 +++++ src/xma/include/app/xmaencoder.h | 6 ++++++ src/xma/include/app/xmakernel.h | 11 ++++++++--- src/xma/include/app/xmascaler.h | 28 ++++++++++++++++++++-------- src/xma/src/xmaapi/xmaapi.c | 2 +- src/xma/src/xmaapi/xmabuffer.c | 11 +++++++++++ src/xma/src/xmaapi/xmahw_hal.cpp | 2 +- src/xma/src/xmaapi/xmaxclbin.cpp | 18 ++++++++---------- 10 files changed, 68 insertions(+), 27 deletions(-) diff --git a/src/xma/CMakeLists.txt b/src/xma/CMakeLists.txt index 60051f8bb2b..e3c0bf99e24 100644 --- a/src/xma/CMakeLists.txt +++ b/src/xma/CMakeLists.txt @@ -14,7 +14,6 @@ add_compile_options("-fPIC") add_compile_options("-Wall" "-Werror") set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -DXMA_RES_TEST -DXMA_DEBUG") -#Uncomment when dep xml2 yaml are installed add_subdirectory(src) set (CMAKE_SHARED_LINKER_FLAGS "-Wl,-Bsymbolic") diff --git a/src/xma/include/app/xmabuffers.h b/src/xma/include/app/xmabuffers.h index 9c1b52fd95f..8d8e75f0107 100644 --- a/src/xma/include/app/xmabuffers.h +++ b/src/xma/include/app/xmabuffers.h @@ -17,6 +17,7 @@ #ifndef _XMA_BUFFERS_H_ #define _XMA_BUFFERS_H_ +#include #include #include #include "lib/xmalimits.h" @@ -95,12 +96,14 @@ typedef enum XmaBufferType /** * @struct XmaBufferRef * Reference counted buffer used in XmaFrame and XmaDataBuffer + * */ typedef struct XmaBufferRef { int32_t refcount; /**< references to buffer */ XmaBufferType buffer_type; /**< location of buffer */ void *buffer; /**< data */ + bool is_clone; /**< buffer member allocated externally */ } XmaBufferRef; /** @@ -212,9 +215,9 @@ xma_frame_from_buffers_clone(XmaFrameProperties *frame_props, * * @param frame frame instance to free * - * @todo frame contains buffer pointers that are not freed. Consider - * freeing or adding flag to arg list to indicate that they should - * be freed. Operation is also not atomic and not thread safe. + * @note: A buffer with is_clone flag set will not be freed + * by XMA when the refcount is == 0. Any XMA container with + * references to this buffer will be freed (e.g. XmaFrame), however. */ void xma_frame_free(XmaFrame *frame); @@ -246,6 +249,8 @@ xma_data_from_buffer_clone(uint8_t *data, size_t size); * * @param data structure to be freed * + * @note: A buffer with is_clone flag set will not be freed + * by XMA when the refcount is == 0. */ void xma_data_buffer_free(XmaDataBuffer *data); diff --git a/src/xma/include/app/xmadecoder.h b/src/xma/include/app/xmadecoder.h index 4cf72d6debc..e1c9893d71f 100644 --- a/src/xma/include/app/xmadecoder.h +++ b/src/xma/include/app/xmadecoder.h @@ -24,6 +24,7 @@ */ #include "app/xmabuffers.h" +#include "app/xmaparam.h" #include "lib/xmalimits.h" #ifdef __cplusplus @@ -247,6 +248,10 @@ typedef struct XmaDecoderProperties char hwvendor_string[MAX_VENDOR_NAME]; /** todo */ int32_t intraOnly; + /** array of kernel-specific custom initialization parameters */ + XmaParameter *params; + /** count of custom parameters for port */ + uint32_t param_cnt; } XmaDecoderProperties; /* Forward declaration */ diff --git a/src/xma/include/app/xmaencoder.h b/src/xma/include/app/xmaencoder.h index 6883aef75fa..fec6de9462c 100644 --- a/src/xma/include/app/xmaencoder.h +++ b/src/xma/include/app/xmaencoder.h @@ -24,6 +24,7 @@ */ #include "app/xmabuffers.h" +#include "app/xmaparam.h" #include "lib/xmalimits.h" #ifdef __cplusplus @@ -284,7 +285,12 @@ typedef struct XmaEncoderProperties /** aq_mode */ int32_t aq_mode; int32_t minQP; + /** force property values to be accepted by encoder plugin */ int32_t force_param; + /** array of kernel-specific custom initialization parameters */ + XmaParameter *params; + /** count of custom parameters for port */ + uint32_t param_cnt; } XmaEncoderProperties; /* Forward declaration */ diff --git a/src/xma/include/app/xmakernel.h b/src/xma/include/app/xmakernel.h index 303274b02d9..2c8f28a6862 100644 --- a/src/xma/include/app/xmakernel.h +++ b/src/xma/include/app/xmakernel.h @@ -282,9 +282,14 @@ typedef enum XmaKernelType */ typedef struct XmaKernelProperties { - XmaKernelType hwkernel_type; /**< requested kernel type */ - char hwvendor_string[MAX_VENDOR_NAME]; /**< requested vendor */ - XmaParameter *param; /**< kernel-specific custom initialization parameters */ + /** requested kernel type */ + XmaKernelType hwkernel_type; + /** requested vendor */ + char hwvendor_string[MAX_VENDOR_NAME]; + /** array of kernel-specific custom initialization parameters */ + XmaParameter *params; + /** count of custom parameters for port */ + uint32_t param_cnt; } XmaKernelProperties; /** * @} diff --git a/src/xma/include/app/xmascaler.h b/src/xma/include/app/xmascaler.h index d05cc5f3c40..8fee1ef7c78 100644 --- a/src/xma/include/app/xmascaler.h +++ b/src/xma/include/app/xmascaler.h @@ -317,14 +317,26 @@ typedef struct XmaScalerSession XmaScalerSession; */ typedef struct XmaScalerProperties { - XmaScalerType hwscaler_type; /**< specific filter function requested */ - XmaSession *destination; /**< downstream kernel receiving data from this filter */ - uint32_t max_dest_cnt; /**< maximum number of scaled outputs */ - char hwvendor_string[MAX_VENDOR_NAME]; /**< specific vendor filter originated from */ - int32_t num_outputs; /**< number of actual scaled outputs */ - XmaScalerFilterProperties filter_coefficients; /**< application-specified filter coefficients */ - XmaScalerInOutProperties input; /**< input properties */ - XmaScalerInOutProperties output[MAX_SCALER_OUTPUTS]; /**< output properties array */ + /** specific filter function requested */ + XmaScalerType hwscaler_type; + /** downstream kernel receiving data from this filter */ + XmaSession *destination; + /** maximum number of scaled outputs */ + uint32_t max_dest_cnt; + /** specific vendor filter originated from */ + char hwvendor_string[MAX_VENDOR_NAME]; + /** number of actual scaled outputs */ + int32_t num_outputs; + /** application-specified filter coefficients */ + XmaScalerFilterProperties filter_coefficients; + /** input properties */ + XmaScalerInOutProperties input; + /** output properties array */ + XmaScalerInOutProperties output[MAX_SCALER_OUTPUTS]; + /** array of kernel-specific custom initialization parameters */ + XmaParameter *params; + /** count of custom parameters for port */ + uint32_t param_cnt; } XmaScalerProperties; /** diff --git a/src/xma/src/xmaapi/xmaapi.c b/src/xma/src/xmaapi/xmaapi.c index 3890cd271ba..4883bfa698f 100644 --- a/src/xma/src/xmaapi/xmaapi.c +++ b/src/xma/src/xmaapi/xmaapi.c @@ -25,7 +25,7 @@ #include "lib/xmahw_hal.h" #include "lib/xmasignal.h" -#define XMA_CFG_DEFAULT "/etc/xma/xma_def_sys_cfg.yaml" +#define XMA_CFG_DEFAULT "/var/tmp/xma_cfg.yaml" #define XMAAPI_MOD "xmaapi" XmaSingleton *g_xma_singleton; diff --git a/src/xma/src/xmaapi/xmabuffer.c b/src/xma/src/xmaapi/xmabuffer.c index 75425b31dfd..58c9c25ebe6 100644 --- a/src/xma/src/xmaapi/xmabuffer.c +++ b/src/xma/src/xmaapi/xmabuffer.c @@ -53,6 +53,7 @@ xma_frame_alloc(XmaFrameProperties *frame_props) { frame->data[i].refcount++; frame->data[i].buffer_type = XMA_HOST_BUFFER_TYPE; + frame->data[i].is_clone = false; // TODO: Get plane size for each plane frame->data[i].buffer = malloc(frame_props->width * frame_props->height); @@ -80,6 +81,7 @@ xma_frame_from_buffers_clone(XmaFrameProperties *frame_props, frame->data[i].refcount++; frame->data[i].buffer_type = XMA_HOST_BUFFER_TYPE; frame->data[i].buffer = frame_data->data[i]; + frame->data[i].is_clone = true; } return frame; @@ -100,6 +102,9 @@ xma_frame_free(XmaFrame *frame) if (frame->data[0].refcount > 0) return; + for (int32_t i = 0; i < num_planes && !frame->data[i].is_clone; i++) + free(frame->data[i].buffer); + free(frame); } @@ -113,6 +118,7 @@ xma_data_from_buffer_clone(uint8_t *data, size_t size) memset(buffer, 0, sizeof(XmaDataBuffer)); buffer->data.refcount++; buffer->data.buffer_type = XMA_HOST_BUFFER_TYPE; + buffer->data.is_clone = true; buffer->data.buffer = data; buffer->alloc_size = size; @@ -128,6 +134,7 @@ xma_data_buffer_alloc(size_t size) memset(buffer, 0, sizeof(XmaDataBuffer)); buffer->data.refcount++; buffer->data.buffer_type = XMA_HOST_BUFFER_TYPE; + buffer->data.is_clone = false; buffer->data.buffer = malloc(size); buffer->alloc_size = size; @@ -142,6 +149,10 @@ xma_data_buffer_free(XmaDataBuffer *data) data->data.refcount--; if (data->data.refcount > 0) return; + + if (!data->data.is_clone) + free(data->data.buffer); + free(data); } diff --git a/src/xma/src/xmaapi/xmahw_hal.cpp b/src/xma/src/xmaapi/xmahw_hal.cpp index 4065b269557..5700282bc60 100644 --- a/src/xma/src/xmaapi/xmahw_hal.cpp +++ b/src/xma/src/xmaapi/xmahw_hal.cpp @@ -198,7 +198,7 @@ bool hal_configure(XmaHwCfg *hwcfg, XmaSystemCfg *systemcfg, bool hw_configured) return false; } int32_t rc = xma_xclbin_info_get(buffer, &info); - if (rc != 0) + if (rc != XMA_SUCCESS) { xma_logmsg("Could not get info for xclbin file %s\n", xclfullname.c_str()); diff --git a/src/xma/src/xmaapi/xmaxclbin.cpp b/src/xma/src/xmaapi/xmaxclbin.cpp index 59bf6f19c32..0e59339c66a 100644 --- a/src/xma/src/xmaapi/xmaxclbin.cpp +++ b/src/xma/src/xmaapi/xmaxclbin.cpp @@ -49,17 +49,12 @@ char *xma_xclbin_file_open(const char *xclbin_name) int xma_xclbin_info_get(char *buffer, XmaXclbinInfo *info) { - int rc; - - rc = get_xclbin_iplayout(buffer, info->ip_layout); - if (rc != 0) - return rc; - return XMA_SUCCESS; + return get_xclbin_iplayout(buffer, info->ip_layout); } static int get_xclbin_iplayout(char *buffer, XmaIpLayout *layout) { - int rc = 0; + //int rc = XMA_SUCCESS; axlf *xclbin = reinterpret_cast(buffer); const axlf_section_header *ip_hdr = xclbin::get_axlf_section(xclbin, @@ -79,8 +74,11 @@ static int get_xclbin_iplayout(char *buffer, XmaIpLayout *layout) } } else - rc = XMA_ERROR; + { + printf("Could not find IP_LAYOUT in xclbin ip_hdr=%p\n", ip_hdr); + //rc = XMA_ERROR; + return XMA_ERROR; + } - return rc; + return XMA_SUCCESS; } -