Add to get the num of threads from media-config 25/274525/5 accepted/tizen/unified/20220608.140042 submit/tizen/20220508.225238 submit/tizen/20220526.000316 submit/tizen/20220606.223347
authorjiyong.min <jiyong.min@samsung.com>
Mon, 2 May 2022 01:04:27 +0000 (10:04 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Tue, 3 May 2022 07:11:00 +0000 (16:11 +0900)
Change-Id: I748320a5a02be3367c541b107233770f00db3685

common/CMakeLists.txt
common/include/mm_util_private.h
common/mm_util_private.c
jxl/mm_util_jxl.c
packaging/libmm-utility.spec

index 96f40d1..d49debb 100755 (executable)
@@ -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})
index 520e84d..091f62d 100644 (file)
@@ -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
index ec02f22..5a7d14b 100644 (file)
  */
 
 #include <stdio.h>
+#include <iniparser.h>
 
 #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;
+}
index 9d17871..0157430 100644 (file)
 #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;
index c66ca75..f235689 100644 (file)
@@ -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}