From c6d8b0225ec926e8b6e7db96717332ee974808bc Mon Sep 17 00:00:00 2001 From: "jiyong.min" Date: Mon, 2 May 2022 10:04:27 +0900 Subject: [PATCH] Add to get the num of threads from media-config Change-Id: I748320a5a02be3367c541b107233770f00db3685 --- common/CMakeLists.txt | 2 +- common/include/mm_util_private.h | 3 +++ common/mm_util_private.c | 25 +++++++++++++++++++++++++ jxl/mm_util_jxl.c | 31 ++++++++++++++++++++++++++----- packaging/libmm-utility.spec | 5 +++-- 5 files changed, 58 insertions(+), 8 deletions(-) diff --git a/common/CMakeLists.txt b/common/CMakeLists.txt index 96f40d1..d49debb 100755 --- a/common/CMakeLists.txt +++ b/common/CMakeLists.txt @@ -13,7 +13,7 @@ SET(INC_DIR ) INCLUDE_DIRECTORIES(${INC_DIR}) -SET(dependents "dlog glib-2.0") +SET(dependents "dlog glib-2.0 iniparser") INCLUDE(FindPkgConfig) pkg_check_modules(${fw_name} REQUIRED ${dependents}) diff --git a/common/include/mm_util_private.h b/common/include/mm_util_private.h index 520e84d..091f62d 100644 --- a/common/include/mm_util_private.h +++ b/common/include/mm_util_private.h @@ -88,6 +88,9 @@ void mm_util_safe_fclose(FILE *fp); int mm_util_file_read(const char *path, void **data, size_t *size); int mm_util_file_write(const char *path, void *data, size_t size); +// for reading ini +int mm_util_ini_get_int(const char *category, const char *item, int default_value); + #ifdef __cplusplus } #endif diff --git a/common/mm_util_private.c b/common/mm_util_private.c index ec02f22..5a7d14b 100644 --- a/common/mm_util_private.c +++ b/common/mm_util_private.c @@ -20,9 +20,12 @@ */ #include +#include #include "mm_util_private.h" +#define IMAGE_UTIL_INI_PATH SYSCONFDIR"/multimedia/mmfw_image_util.ini" + gboolean mm_util_is_valid_color_format(mm_util_color_format_e color) { if ((color < MM_UTIL_COLOR_YUV420) || (color >= MM_UTIL_COLOR_NUM)) { @@ -128,3 +131,25 @@ int mm_util_file_write(const char *path, void *data, size_t size) return MM_UTIL_ERROR_NONE; } +int mm_util_ini_get_int(const char *category, const char *item, int default_value) +{ + gchar *path = NULL; + int val; + dictionary *dict = NULL; + + mm_util_retvm_if(!category, default_value, "category is NULL"); + mm_util_retvm_if(!item, default_value, "item is NULL"); + + dict = iniparser_load(IMAGE_UTIL_INI_PATH); + mm_util_retvm_if(!dict, default_value, "could not open ini[%s], use default values[%d]", IMAGE_UTIL_INI_PATH, default_value); + + path = g_strconcat(category, ":", item, NULL); + + val = iniparser_getint(dict, path, default_value); + mm_util_info("[INI] %s = %d", path, val); + + g_free(path); + iniparser_freedict(dict); + + return val; +} diff --git a/jxl/mm_util_jxl.c b/jxl/mm_util_jxl.c index 9d17871..0157430 100644 --- a/jxl/mm_util_jxl.c +++ b/jxl/mm_util_jxl.c @@ -28,9 +28,10 @@ #include "mm_util_jxl.h" #include "mm_util_private.h" -// TODO: it will be moved into .ini of mmfw_config -#define NUM_OF_THREADS 4 - +#define DEFAULT_THREAD 1 +#define INI_CATEGORY_JPEG_XL "jpeg-xl" +#define INI_ITEM_NUM_OF_DECODING_TRHEADS "decoding_threads" +#define INI_ITEM_NUM_OF_ENCODING_TRHEADS "encoding_threads" static JxlPixelFormat jxl_formats[] = { [MM_UTIL_COLOR_RGB24] = {3, JXL_TYPE_UINT8, JXL_BIG_ENDIAN, 0}, // RGB -> RGB @@ -90,6 +91,26 @@ static int __convert_enc_error(JxlEncoderStatus status) return err; } +static size_t __get_decoding_threads_configuration(void) +{ + static int num_of_decoding_threads = -1; + + if (num_of_decoding_threads != -1) + return num_of_decoding_threads; + + return (size_t)(num_of_decoding_threads = mm_util_ini_get_int(INI_CATEGORY_JPEG_XL, INI_ITEM_NUM_OF_DECODING_TRHEADS, DEFAULT_THREAD)); +} + +static size_t __get_encoding_threads_configuration(void) +{ + static int num_of_encoding_threads = -1; + + if (num_of_encoding_threads != -1) + return num_of_encoding_threads; + + return (size_t)(num_of_encoding_threads = mm_util_ini_get_int(INI_CATEGORY_JPEG_XL, INI_ITEM_NUM_OF_ENCODING_TRHEADS, DEFAULT_THREAD)); +} + static int __get_decoded_data(mm_util_image_h decoded, uint32_t *width, uint32_t *height, JxlPixelFormat *format, uint8_t **pixels, size_t *pixels_size) { mm_image_info_s *_image = (mm_image_info_s *)decoded; @@ -133,7 +154,7 @@ static int __mm_util_decode_jpegxl(const void *buf, size_t buf_size, mm_util_col goto Exit; } - jxl_thread = JxlThreadParallelRunnerCreate(NULL, NUM_OF_THREADS); + jxl_thread = JxlThreadParallelRunnerCreate(NULL, __get_decoding_threads_configuration()); if (!jxl_thread) { mm_util_error("failed to JxlThreadParallelRunnerCreate"); goto Exit; @@ -279,7 +300,7 @@ static int __mm_util_encode_jpegxl(mm_util_image_h decoded_image, mm_util_enc_op goto Exit; } - jxl_thread = JxlThreadParallelRunnerCreate(NULL, NUM_OF_THREADS); + jxl_thread = JxlThreadParallelRunnerCreate(NULL, __get_encoding_threads_configuration()); if (!jxl_thread) { mm_util_error("failed to JxlThreadParallelRunnerCreate"); goto Exit; diff --git a/packaging/libmm-utility.spec b/packaging/libmm-utility.spec index c66ca75..f235689 100644 --- a/packaging/libmm-utility.spec +++ b/packaging/libmm-utility.spec @@ -1,6 +1,6 @@ Name: libmm-utility Summary: Multimedia Framework Utility Library -Version: 0.4.3 +Version: 0.4.4 Release: 0 Group: System/Libraries License: Apache-2.0 @@ -15,6 +15,7 @@ BuildRequires: pkgconfig(dlog) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(gio-2.0) BuildRequires: pkgconfig(gmodule-2.0) +BuildRequires: pkgconfig(iniparser) BuildRequires: libjpeg-turbo-devel BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(opencv) >= 3.4.1 @@ -46,7 +47,7 @@ Multimedia Framework Utility Library - Development files. cp %{SOURCE1001} . %build -export CFLAGS="$CFLAGS -DGMAGICK_DEBUG=0 -D_FORTIFY_SOURCE=2" +export CFLAGS="$CFLAGS -DGMAGICK_DEBUG=0 -D_FORTIFY_SOURCE=2 -DSYSCONFDIR=\\\"%{_hal_sysconfdir}\\\"" %cmake . -DBUILD_GTESTS=%{?gtests:1}%{!?gtests:0} make %{?jobs:-j%jobs} -- 2.7.4