Remove glib dependency 17/306017/2 accepted/tizen/unified/20240216.161336 accepted/tizen/unified/x/20240220.145917
authorminje.ahn <minje.ahn@samsung.com>
Thu, 15 Feb 2024 06:09:36 +0000 (15:09 +0900)
committerminje.ahn <minje.ahn@samsung.com>
Fri, 16 Feb 2024 00:31:55 +0000 (09:31 +0900)
Change-Id: Id48dff54bb093ecef31d910b2a7518b36e173b5d
Signed-off-by: minje.ahn <minje.ahn@samsung.com>
CMakeLists.txt
packaging/libmedia-thumbnail.spec
src/media-thumbnail.c
unittest/CMakeLists.txt
unittest/libmedia_thumbnail_unittest.cpp

index 2d6569687a32e49d35f551a75453e4f76c923699..3daef0c77b9aedb9d133f1ef7dcd81925e083ec2 100644 (file)
@@ -28,10 +28,10 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
 
 IF(WITH_DA_PROFILE)
 INCLUDE(FindPkgConfig)
-       pkg_check_modules(pkgs REQUIRED glib-2.0 dlog mm-fileinfo aul mmutil-common mmutil-magick mmutil-gif mmutil-jpeg libexif)
+       pkg_check_modules(pkgs REQUIRED dlog mm-fileinfo aul mmutil-common mmutil-magick mmutil-gif mmutil-jpeg libexif)
 ELSE(WITH_DA_PROFILE)
 INCLUDE(FindPkgConfig)
-       pkg_check_modules(pkgs REQUIRED glib-2.0 dlog mm-fileinfo aul mmutil-common mmutil-magick)
+       pkg_check_modules(pkgs REQUIRED dlog mm-fileinfo aul mmutil-common mmutil-magick)
 ENDIF(WITH_DA_PROFILE)
 
 FOREACH(flag ${pkgs_CFLAGS})
index 6abc27e7718f2ef6c12ab6ef7e02e9a514d212d4..90da5db0589a93fcf7d5ac03c0f325fc0d9698d8 100644 (file)
@@ -1,6 +1,6 @@
 Name:       libmedia-thumbnail
 Summary:    Media thumbnail service library for multimedia applications
-Version:    0.4.7
+Version:    0.4.8
 Release:    0
 Group:      Multimedia/Libraries
 License:    Apache-2.0
@@ -15,6 +15,7 @@ BuildRequires: pkgconfig(aul)
 BuildRequires: pkgconfig(mmutil-common)
 BuildRequires: pkgconfig(mmutil-magick)
 %if 0%{?gtests:1}
+BuildRequires: pkgconfig(libtzplatform-config)
 BuildRequires: pkgconfig(gmock)
 %endif
 %if 0%{?_with_da_profile:1}
index 4473f5994d464f0d4296e0d2e219c5673471104f..93d2c813505f1bd7c5b0a44f13c865628a1dc753 100755 (executable)
  *
  */
 
-#include "media-thumbnail.h"
-#include "media-thumbnail-debug.h"
-
 #include <aul.h>
+#include <limits.h>
+#include <malloc.h>
+#include <string.h>
+#include <regex.h>
 #include <mm_file.h>
 #include <mm_util_magick.h>
 #if defined(USE_MEMORY_USAGE_REDUCTION)
@@ -29,6 +30,9 @@
 #include <libexif/exif-data.h>
 #endif
 
+#include "media-thumbnail.h"
+#include "media-thumbnail-debug.h"
+
 #define MAX_THUMB_SIZE 2000
 #define MIME_TYPE_TIFF "image/tiff"
 #define MIME_TYPE_ASF "application/vnd.ms-asf"
@@ -81,6 +85,7 @@ static int __get_video_meta(const char *path, int *video_track_num, unsigned int
        unsigned int _height = 0;
        size_t _frame_size = 0;
        void *_frame = NULL;
+       void *_copied = NULL;
 
        err = mm_file_create_content_attrs(&content, path);
        thumb_retvm_if(err != FILEINFO_ERROR_NONE, THUMB_FAIL, "mm_file_create_content_attrs fails : %d", err);
@@ -105,16 +110,24 @@ static int __get_video_meta(const char *path, int *video_track_num, unsigned int
                return THUMB_OK;
        }
 
-       if (!_frame || !_width || !_height) {
+       if (!_frame || _width == 0 || _height == 0 || _frame_size == 0) {
                thumb_err("wrong video info W[%d] H[%d] Size[%zu] Frame[%p]", _width, _height, _frame_size, _frame);
                mm_file_destroy_content_attrs(content);
                return THUMB_FAIL;
        }
 
+       _copied = malloc(_frame_size);
+       if (!_copied) {
+               thumb_err("allocation failed");
+               mm_file_destroy_content_attrs(content);
+               return THUMB_FAIL;
+       }
+
        *width = _width;
        *height = _height;
        *frame_size = _frame_size;
-       *frame = g_memdup2(_frame, _frame_size);
+       memcpy(_copied, _frame, _frame_size);
+       *frame = _copied;
 
        mm_file_destroy_content_attrs(content);
 
@@ -244,29 +257,37 @@ static int __check_path_validity(const char *path)
 
 static int __check_thumb_path_validity(const char *path)
 {
-       char *dir_name = NULL;
-       int ret = THUMB_OK;
+       char dir_name[PATH_MAX + 1] = { 0, };
+       int len = 0;
 
        if (!path || strlen(path) == 0) {
                thumb_err("Invalid path");
                return THUMB_FAIL;
        }
 
-       dir_name = g_path_get_dirname(path);
+       strncpy(dir_name, path, PATH_MAX);
+       len = strlen(dir_name);
+       while (--len) {
+               if (dir_name[len] == '/') {
+                       dir_name[len] = '\0';
+                       break;
+               }
+       }
+
+       if (len == 0)
+               return THUMB_FAIL;
 
        if (access(dir_name, W_OK) != 0) {
                if (errno == EACCES || errno == EPERM) {
                        thumb_err("No permission to write[%s]", dir_name);
-                       ret = THUMB_PERM;
+                       return THUMB_PERM;
                } else {
                        thumb_err("Does not exists[%s]", dir_name);
-                       ret = THUMB_FAIL;
+                       return THUMB_FAIL;
                }
        }
 
-       g_free(dir_name);
-
-       return ret;
+       return THUMB_OK;
 }
 
 static int __check_parameter_validity_for_file(const char *path, unsigned int width, unsigned int height, const char *thumb_path)
@@ -320,7 +341,8 @@ int create_video_thumbnail_to_file(const char *path, unsigned int width, unsigne
 
        //Extract thumbnail
        err = __get_video_thumb_to_file(video_width, video_height, frame, frame_size, rot_type, thumb_path, width, height);
-       g_free(frame);
+       if (frame)
+               free(frame);
 
        return err;
 }
@@ -351,7 +373,9 @@ int create_video_thumbnail_to_buffer(const char *path,
 
        //Extract thumbnail
        err = __get_video_thumb_to_buffer(video_w, video_h, frame, frame_size, width, height, &img);
-       g_free(frame);
+       if (frame)
+               free(frame);
+
        if (err != THUMB_OK)
                return err;
 
@@ -649,6 +673,7 @@ int create_thumbnail_to_buffer(const char *path, unsigned int width, unsigned in
 int create_thumbnail_to_file(const char *path, unsigned int width, unsigned int height, const char *thumb_path)
 {
        int ret = THUMB_OK;
+       regex_t regex;
        thumbnail_media_type_e type = MEDIA_THUMB_INVALID;
 
        ret = __get_media_type(path, &type);
@@ -657,10 +682,16 @@ int create_thumbnail_to_file(const char *path, unsigned int width, unsigned int
        if (type == MEDIA_THUMB_IMAGE)
                return create_image_thumbnail_to_file(path, width, height, thumb_path, false);
 
-       if (!g_regex_match_simple("[^/]\\.jpe?g$", thumb_path, G_REGEX_CASELESS, 0)) {
+       if (regcomp(&regex, "[^/]\\.jpe?g$", REG_ICASE | REG_EXTENDED) != 0) {
+               thumb_err("regcomp failed");
+               return THUMB_FAIL;
+       }
+
+       if (regexec(&regex, thumb_path, 0, NULL, 0) == REG_NOMATCH) {
                thumb_err("Unsupported path or extensions [%s]", thumb_path);
                return THUMB_FAIL;
        }
 
+       regfree(&regex);
        return create_video_thumbnail_to_file(path, width, height, thumb_path, false);
 }
index 24a05543c4ac03e1eab68f4ca5ddac2b890f2736..43ab95782a17d5aeef799fc785fd69df6c01a35a 100644 (file)
@@ -5,11 +5,8 @@ SET(GTEST_TEST "gtest-libmedia-thumbnail")
 ADD_DEFINITIONS("-DUSE_DLOG")
 
 SET(REQUIRES_LIST ${REQUIRES_LIST}
-       glib-2.0
-       gio-2.0
        gmock
        dlog
-       libmedia-utils
        libtzplatform-config
 )
 
index 6f7f83a855811c54cf532f67ae3d65d012f7d5d8..13cb0a08e3796b52ef815686c981ef9faafa5eff 100755 (executable)
@@ -17,7 +17,6 @@
 #include <tzplatform_config.h>
 
 #include "libmedia_thumbnail_unittest.h"
-#include "media-util.h"
 #include "media-thumbnail.h"
 
 #define GTEST_IMAGE_FILE_PATH          tzplatform_mkpath(TZ_SYS_BIN, "libmedia-thumbnail-unittest.jpg")
@@ -42,24 +41,24 @@ class libmedia_thumbnail_Test : public ::testing::Test {
 
 TEST(libmedia_thumbnail_Test, create_image_thumbnail_to_buffer_n)
 {
-       int ret = MS_MEDIA_ERR_NONE;
+       int ret = THUMB_OK;
        unsigned char *buffer = NULL;
        size_t size = 0;
        unsigned int w, h;
 
        ret = create_image_thumbnail_to_buffer(NULL, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, &buffer, &size, &w, &h);
-       EXPECT_EQ(ret, MS_MEDIA_ERR_INVALID_PARAMETER);
+       EXPECT_EQ(ret, THUMB_FAIL);
 }
 
 TEST(libmedia_thumbnail_Test, create_image_thumbnail_to_buffer_p)
 {
-       int ret = MS_MEDIA_ERR_NONE;
+       int ret = THUMB_OK;
        unsigned char *buffer = NULL;
        size_t size = 0;
        unsigned int w, h;
 
        ret = create_image_thumbnail_to_buffer(GTEST_IMAGE_FILE_PATH, THUMBNAIL_WIDTH, THUMBNAIL_HEIGHT, &buffer, &size, &w, &h);
-       EXPECT_EQ(ret, MS_MEDIA_ERR_NONE);
+       EXPECT_EQ(ret, THUMB_OK);
 
        if (buffer)
                free(buffer);