Code clean up header files and memory allocations 20/159320/4 submit/tizen/20171110.043613
authorJiyong Min <jiyong.min@samsung.com>
Wed, 8 Nov 2017 07:18:13 +0000 (16:18 +0900)
committerJiyong Min <jiyong.min@samsung.com>
Fri, 10 Nov 2017 01:06:15 +0000 (10:06 +0900)
Change-Id: I958b612a5d56c2ae84a0ee0bd0de7e2fee74aa9a
Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
37 files changed:
bmp/Makefile.am
bmp/include/mm_util_bmp.h
bmp/mm_util_bmp.c
bmp/test/Makefile.am
bmp/test/mm_util_bmp_testsuite.c
common/include/mm_util_debug.h [moved from imgp/include/mm_util_debug.h with 89% similarity]
common/include/mm_util_private.h [new file with mode: 0755]
common/include/mm_util_type.h [new file with mode: 0755]
configure.ac
gif/Makefile.am
gif/include/mm_util_gif.h
gif/mm_util_gif.c
gif/test/Makefile.am
gif/test/mm_util_gif_testsuite.c
imgcv/Makefile.am
imgcv/include/mm_util_imgcv.h
imgcv/include/mm_util_imgcv_internal.h
imgcv/mm_util_imgcv.c
imgcv/test/Makefile.am
imgcv/test/mm_util_imgcv_testsuite.c
imgp/Makefile.am
imgp/include/mm_util_imgp.h
imgp/include/mm_util_imgp_internal.h
imgp/mm_util_imgp.c
imgp/test/Makefile.am
imgp/test/mm_util_imgp_testsuite.c
jpeg/Makefile.am
jpeg/include/mm_util_jpeg.h
jpeg/mm_util_jpeg.c
jpeg/test/Makefile.am
jpeg/test/mm_util_jpeg_testsuite.c
packaging/libmm-utility.spec
png/Makefile.am
png/include/mm_util_png.h
png/mm_util_png.c
png/test/Makefile.am
png/test/mm_util_png_testsuite.c

index 596bf7d..92ec53a 100644 (file)
@@ -3,21 +3,20 @@ ACLOCAL_AMFLAGS='-I m4'
 lib_LTLIBRARIES = libmmutil_bmp.la
 
 installmmutil_bmpdir = $(includedir)/mmf
-installmmutil_bmp_HEADERS = include/mm_util_bmp.h
+installmmutil_bmp_HEADERS = include/mm_util_bmp.h \
+                            ../common/include/mm_util_type.h
 
 libmmutil_bmp_la_SOURCES = mm_util_bmp.c
 
 libmmutil_bmp_la_CFLAGS = -I$(srcdir)/include \
-                               -I$(srcdir)/../imgp/include \
+                               -I$(srcdir)/../common/include \
                                $(GLIB_CFLAGS) \
                                $(MEDIA_CFLAGS) \
                                -I/usr/include \
-                               $(SYSTEMINFO_CFLAGS) \
                                $(srcdir)/../imgp/libmmutil_imgp.la
 
 libmmutil_bmp_la_LIBADD = $(GLIB_LIBS) -lnsbmp -lbmp -ldl -lttrace\
                                $(GMODULE_LIBS) \
-                               $(SYSTEMINFO_LIBS)\
                                $(MEDIA_LIBS)
 
 libmmutil_bmp_la_CFLAGS += -DLIBPREFIX=\"$(libdir)\"
index 935ac4c..16eb713 100755 (executable)
@@ -25,7 +25,7 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-#include "mm_util_imgp.h"
+#include "mm_util_type.h"
 #include "libnsbmp.h"
 #include "bmpfile.h"
 
index 946b310..8749a40 100755 (executable)
  *
  */
 
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
+#include <stdio.h>
 #include <sys/stat.h>
-#include <sys/mman.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#include <sys/times.h>
-#include <fcntl.h>
 #include <unistd.h>
-#include <errno.h>
-#include <stdio.h>                             /* fopen() */
-#include <system_info.h>
 
 #include "mm_util_bmp.h"
-#include "mm_util_debug.h"
+#include "mm_util_private.h"
 
 #define BYTES_PER_PIXEL 4
 
-#define BMP_SAFE_FREE(src) { if (src != NULL) {free(src); src = NULL; } }
-
 void *__bitmap_create(int width, int height, unsigned int state);
 unsigned char *__bitmap_get_buffer(void *bitmap);
 size_t __bitmap_get_bpp(void *bitmap);
@@ -66,7 +54,7 @@ static unsigned char *__load_file(const char *path, size_t * data_size)
        }
        size = sb.st_size;
 
-       buffer = malloc(size);
+       buffer = calloc(1, size);
        if (!buffer) {
                mm_util_error("Unable to allocate %lld bytes", (long long)size);
                fclose(fd);
@@ -76,7 +64,7 @@ static unsigned char *__load_file(const char *path, size_t * data_size)
        n = fread(buffer, 1, size, fd);
        if (n != size) {
                mm_util_error("file read failed");
-               BMP_SAFE_FREE(buffer);
+               MMUTIL_SAFE_FREE(buffer);
                fclose(fd);
                return NULL;
        }
@@ -121,7 +109,7 @@ size_t __bitmap_get_bpp(void *bitmap)
 
 void __bitmap_destroy(void *bitmap)
 {
-       BMP_SAFE_FREE(bitmap);
+       MMUTIL_SAFE_FREE(bitmap);
 }
 
 static int __read_bmp(mm_util_bmp_data *decoded, const char *filename, void *memory, unsigned long long src_size)
@@ -173,7 +161,7 @@ static int __read_bmp(mm_util_bmp_data *decoded, const char *filename, void *mem
        decoded->width = bmp.width;
        decoded->height = bmp.height;
        decoded->size = bmp.width * bmp.height * BYTES_PER_PIXEL;
-       decoded->data = malloc(decoded->size);
+       decoded->data = calloc(1, decoded->size);
        if (decoded->data == NULL) {
                mm_util_error("Failed to saved memory allocation");
                res = MM_UTIL_ERROR_OUT_OF_MEMORY;
@@ -184,7 +172,7 @@ static int __read_bmp(mm_util_bmp_data *decoded, const char *filename, void *mem
  cleanup:
        bmp_finalise(&bmp);
        if (filename)
-               BMP_SAFE_FREE(data);
+               MMUTIL_SAFE_FREE(data);
        return res;
 }
 
@@ -285,7 +273,7 @@ int mm_util_encode_bmp_to_memory(mm_util_bmp_data *encoded, void **buffer, size_
        if (bmp_save2(bmp, buffer, size) == false) {
                mm_util_error("Saving bmp was failed.");
                bmp_destroy(bmp);
-               BMP_SAFE_FREE(*buffer);
+               MMUTIL_SAFE_FREE(*buffer);
                *size = 0;
                return MM_UTIL_ERROR_INVALID_OPERATION;
        }
index 5a0f193..e2ab817 100755 (executable)
@@ -3,7 +3,7 @@ bin_PROGRAMS = mm_util_bmp_testsuite
 mm_util_bmp_testsuite_SOURCES = mm_util_bmp_testsuite.c
 
 mm_util_bmp_testsuite_CFLAGS = -I$(srcdir)/../include \
-                               -I$(srcdir)/../../imgp/include
+                               -I$(srcdir)/../../common/include
 mm_util_bmp_testsuite_CFLAGS += $(MEDIA_CFLAGS) \
                                 -fPIE -pie \
                                 $(TZ_PLATFORM_CONFIG_FLAGS)
index 94029a5..4fd70fb 100755 (executable)
@@ -22,8 +22,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
-#include <errno.h>
-#include <sys/types.h>
 #include <sys/stat.h>
 #include <mm_util_bmp.h>
 
similarity index 89%
rename from imgp/include/mm_util_debug.h
rename to common/include/mm_util_debug.h
index ca9e747..e5ca94b 100755 (executable)
@@ -22,6 +22,7 @@
 #define __MM_UTILITY_DEBUG_H__
 
 #include <dlog.h>
+#include <errno.h>
 
 #ifdef __cplusplus
 extern "C"
@@ -75,7 +76,13 @@ extern "C"
                } \
        } while (0)
 
-#define MMUTIL_SAFE_FREE(x)                            { if (x) { free(x); x = NULL; } }
+#define ERR_BUF_LENGHT 256
+#define mm_util_stderror(fmt) do { \
+               char buf[ERR_BUF_LENGHT] = {0,}; \
+               strerror_r(errno, buf, ERR_BUF_LENGHT); \
+               mm_util_error(fmt" : standard error= [%s]", buf); \
+       } while (0)
+
 /**
 * @}
 */
diff --git a/common/include/mm_util_private.h b/common/include/mm_util_private.h
new file mode 100755 (executable)
index 0000000..d47a6a6
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * libmm-utility
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: YoungHun Kim <yh8004.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MM_UTIL_PRIVATE_H__
+#define __MM_UTIL_PRIVATE_H__
+
+#include <glib.h>
+#include <stdlib.h>
+#include "mm_util_debug.h"
+#include "mm_util_type.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MMUTIL_SAFE_FREE(x)                            { if (x) { free(x); x = NULL; } }
+#define MMUTIL_SAFE_G_FREE(x)                  { if (x) { g_free(x); x = NULL; } }
+#define MMUTIL_SAFE_STRCPY(dst, src, n)        g_strlcpy(dst, src, n)
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif   /*__MM_UTIL_PRIVATE_H__*/
diff --git a/common/include/mm_util_type.h b/common/include/mm_util_type.h
new file mode 100755 (executable)
index 0000000..26c6b37
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * libmm-utility
+ *
+ * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Contact: YoungHun Kim <yh8004.kim@samsung.com>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __MM_UTIL_TYPE_H__
+#define __MM_UTIL_TYPE_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * error type
+ */
+typedef enum {
+       MM_UTIL_ERROR_NONE =              0,       /**< Successful */
+       MM_UTIL_ERROR_INVALID_PARAMETER = -1,      /**< Invalid parameter */
+       MM_UTIL_ERROR_OUT_OF_MEMORY = -2,          /**< Out of memory */
+       MM_UTIL_ERROR_NO_SUCH_FILE  = -3,                  /**< No such file */
+       MM_UTIL_ERROR_INVALID_OPERATION = -4,      /**< Internal error */
+       MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT = -5,   /**< Not supported format */
+} mm_util_error_e;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif   /*__MM_UTIL_TYPE_H__*/
index b5048a9..5559e74 100755 (executable)
@@ -53,18 +53,10 @@ PKG_CHECK_MODULES(MEDIA, capi-media-tool)
 AC_SUBST(MEDIA_CFLAGS)
 AC_SUBST(MEDIA_LIBS)
 
-PKG_CHECK_MODULES(TBM, libtbm)
-AC_SUBST(TBM_CFLAGS)
-AC_SUBST(TBM_LIBS)
-
 PKG_CHECK_MODULES(OPENCV, opencv)
 AC_SUBST(OPENCV_CFLAGS)
 AC_SUBST(OPENCV_LIBS)
 
-PKG_CHECK_MODULES(SYSTEMINFO, capi-system-info)
-AC_SUBST(SYSTEMINFO_CFLAGS)
-AC_SUBST(SYSTEMINFO_LIBS)
-
 PKG_CHECK_MODULES(TTRACE, [ttrace], AC_DEFINE(ENABLE_TTRACE, 1, [ttrace available]))
 AC_SUBST(TTRACE)
 
index bb27b50..c6d923b 100644 (file)
@@ -3,23 +3,22 @@ ACLOCAL_AMFLAGS='-I m4'
 lib_LTLIBRARIES = libmmutil_gif.la
 
 installmmutil_gifdir = $(includedir)/mmf
-installmmutil_gif_HEADERS = include/mm_util_gif.h
+installmmutil_gif_HEADERS = include/mm_util_gif.h \
+                            ../common/include/mm_util_type.h
 
 libmmutil_gif_la_SOURCES = mm_util_gif.c
 
 libmmutil_gif_la_CFLAGS = -I$(srcdir)/include \
-                               -I$(srcdir)/../imgp/include \
+                               -I$(srcdir)/../common/include \
                                $(GLIB_CFLAGS) \
                                $(GIO_CFLAGS) \
                                $(MEDIA_CFLAGS) \
                                -I/usr/include \
-                               $(SYSTEMINFO_CFLAGS) \
                                $(srcdir)/../imgp/libmmutil_imgp.la
 
 libmmutil_gif_la_LIBADD = $(GLIB_LIBS) -lgif -ldl -lttrace\
                                $(GIO_LIBS) \
                                $(GMODULE_LIBS) \
-                               $(SYSTEMINFO_LIBS)\
                                $(MEDIA_LIBS)
 
 libmmutil_gif_la_CFLAGS += -DLIBPREFIX=\"$(libdir)\"
index dd7611a..39889e1 100755 (executable)
@@ -28,7 +28,7 @@ extern "C" {
 
 #include <glib.h>
 #include "gif_lib.h"
-#include "mm_util_imgp.h"
+#include "mm_util_type.h"
 
 /**
     @addtogroup UTILITY
index 99c782c..2ac934c 100755 (executable)
  *
  */
 
-#include <stdlib.h>
 #include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#include <sys/times.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
 #include <gio/gio.h>
 
 #include "mm_util_gif.h"
 #include "mm_util_gif_private.h"
-#include "mm_util_debug.h"
+#include "mm_util_private.h"
 
 #include <limits.h>
 #define GIF_TMP_FILE   "/tmp/.libmm_gif.gif"
@@ -51,7 +41,7 @@ static int __convert_gif_to_rgba(mm_util_gif_data *decoded, ColorMapObject *colo
        GifByteType *buffer;
 
        mm_util_debug("__convert_gif_to_rgba");
-       if ((decoded->data = (void *)malloc(width * height * 4)) == NULL) {
+       if ((decoded->data = (void *)calloc(1, width * height * 4)) == NULL) {
                mm_util_error("Failed to allocate memory required, aborted.");
                return MM_UTIL_ERROR_OUT_OF_MEMORY;
        }
@@ -119,7 +109,7 @@ static int __read_gif(mm_util_gif_data *decoded, const char *filename, void *mem
        decoded->size = (unsigned long long)GifFile->SWidth * (unsigned long long)GifFile->SHeight * 4;
 
        if ((screen_buffer = (GifRowType *)
-                malloc(GifFile->SHeight * sizeof(GifRowType))) == NULL) {
+                calloc(1, GifFile->SHeight * sizeof(GifRowType))) == NULL) {
                mm_util_error("Failed to allocate memory required, aborted.");
                ret = MM_UTIL_ERROR_INVALID_OPERATION;
                goto error;
@@ -1232,6 +1222,6 @@ void mm_util_gif_encode_destroy(mm_gif_file_h gif_file_h)
 
        COLORMAP_FREE(gif_file->color_map);
 
-       MMUTIL_SAFE_FREE(gif_file->filename);
+       MMUTIL_SAFE_G_FREE(gif_file->filename);
        MMUTIL_SAFE_FREE(gif_file->buffer);
 }
index dbee4d8..8acca79 100755 (executable)
@@ -3,7 +3,7 @@ bin_PROGRAMS = mm_util_gif_testsuite
 mm_util_gif_testsuite_SOURCES = mm_util_gif_testsuite.c
 
 mm_util_gif_testsuite_CFLAGS = -I$(srcdir)/../include \
-                               -I$(srcdir)/../../imgp/include
+                               -I$(srcdir)/../../common/include
 mm_util_gif_testsuite_CFLAGS += $(GLIB_CFLAGS) \
                                 $(MEDIA_CFLAGS) \
                                 -fPIE -pie \
index d42d995..ff20f44 100755 (executable)
@@ -24,8 +24,6 @@
 #include <string.h>
 #include <errno.h>
 #include <limits.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <mm_util_gif.h>
 
 #define ENCODED_FILEPATH               "/opt/usr/home/owner/media/mm_util_test.gif"
index f50648b..9192a91 100755 (executable)
@@ -3,13 +3,14 @@ ACLOCAL_AMFLAGS='-I m4'
 lib_LTLIBRARIES = libmmutil_imgcv.la
 
 installmmutil_imgcvdir = $(includedir)/mmf
-installmmutil_imgcv_HEADERS = include/mm_util_imgcv.h
+installmmutil_imgcv_HEADERS = include/mm_util_imgcv.h \
+                            ../common/include/mm_util_type.h
 noinst_HEADERS = include/mm_util_imgcv_internal.h
 
 libmmutil_imgcv_la_SOURCES = mm_util_imgcv.c
 
 libmmutil_imgcv_la_CFLAGS = -I$(srcdir)/include \
-                               -I$(srcdir)/../imgp/include \
+                               -I$(srcdir)/../common/include \
                                $(GLIB_CFLAGS) \
                                $(GMODULE_CFLAGS) \
                                $(MEDIA_CFLAGS) \
index 22058ab..b9f65ea 100755 (executable)
@@ -21,6 +21,8 @@
 #ifndef __MM_UTILITY_IMGCV_H__
 #define __MM_UTILITY_IMGCV_H__
 
+#include "mm_util_type.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
index b1c8dc1..edd9fee 100755 (executable)
@@ -20,7 +20,6 @@
  */
 
 #include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 
 #ifdef __cplusplus
index 8a37702..21a15ff 100755 (executable)
@@ -20,8 +20,7 @@
  */
 #include <limits.h>
 #include <math.h>
-#include "mm_util_debug.h"
-#include "mm_util_imgp.h"
+#include "mm_util_private.h"
 #include "mm_util_imgcv.h"
 #include "mm_util_imgcv_internal.h"
 
@@ -220,7 +219,7 @@ int mm_util_cv_extract_representative_color(void *image_buffer, int width, int h
                return MM_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       mm_util_imgcv_s *handle = (mm_util_imgcv_s *)malloc(sizeof(mm_util_imgcv_s));
+       mm_util_imgcv_s *handle = (mm_util_imgcv_s *)calloc(1, sizeof(mm_util_imgcv_s));
        if (handle == NULL) {
                mm_util_error("#ERROR#: fail to create handle");
 
index c2393cf..9d660ed 100755 (executable)
@@ -4,7 +4,7 @@ mm_util_imgcv_testsuite_SOURCES = mm_util_imgcv_testsuite.c
 
 mm_util_imgcv_testsuite_CFLAGS = -I$(srcdir)/../include \
                                                                -I$(srcdir)/../../jpeg/include \
-                                                               -I$(srcdir)/../../imgp/include
+                                                               -I$(srcdir)/../../common/include
 
 mm_util_imgcv_testsuite_CFLAGS += $(MMCOMON_CFLAGS) \
                                                                -fPIE -pie
index 19ad5e0..d237775 100755 (executable)
@@ -19,7 +19,6 @@
  *
  */
 #include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 
 #include <mm_util_jpeg.h>
index b518eb1..eaf13fb 100755 (executable)
@@ -3,13 +3,14 @@ ACLOCAL_AMFLAGS='-I m4'
 lib_LTLIBRARIES = libmmutil_imgp.la
 
 installmmutil_imgpdir = $(includedir)/mmf
-installmmutil_imgp_HEADERS = include/mm_util_imgp.h
-noinst_HEADERS = include/mm_util_imgp_internal.h \
-                 include/mm_util_debug.h
+installmmutil_imgp_HEADERS = include/mm_util_imgp.h \
+                             ../common/include/mm_util_type.h
+noinst_HEADERS = include/mm_util_imgp_internal.h
 
 libmmutil_imgp_la_SOURCES = mm_util_imgp.c
 
-libmmutil_imgp_la_CFLAGS = -I$(srcdir)/include \
+libmmutil_imgp_la_CFLAGS = -I$(srcdir)/../common/include \
+                           -I$(srcdir)/include \
                           -I$(includedir)/drm \
                            $(GLIB_CFLAGS) \
                            $(GMODULE_CFLAGS) \
@@ -19,7 +20,6 @@ libmmutil_imgp_la_CFLAGS = -I$(srcdir)/include \
                            $(XFIXES_CFLAGS) \
                            $(DRI2PROTO_CFLAGS) \
                            $(DRI2_CFLAGS) \
-                           $(TBM_CFLAGS) \
                            $(DLOG_CFLAGS)
 
 libmmutil_imgp_la_LIBADD = $(GLIB_LIBS) \
@@ -30,7 +30,6 @@ libmmutil_imgp_la_LIBADD = $(GLIB_LIBS) \
                            $(XFIXES_LIBS) \
                            $(DRI2PROTO_LIBS) \
                            $(DRI2_LIBS) \
-                           $(TBM_LIBS) \
                            $(DLOG_LIBS)
 
 libmmutil_imgp_la_CFLAGS += -lcapi-media-tool -lttrace -DLIBPREFIX=\"$(libdir)\"
index f8e70be..33777f2 100755 (executable)
@@ -27,6 +27,7 @@ extern "C" {
 #endif
 
 #include <media_packet.h>
+#include "mm_util_type.h"
 
 typedef void *mm_util_imgp_h;
 
@@ -40,18 +41,6 @@ typedef bool (*mm_util_completed_callback)(media_packet_h *dst, int error, void
  */
 
 /**
- * error type
- */
-typedef enum {
-       MM_UTIL_ERROR_NONE =              0,       /**< Successful */
-       MM_UTIL_ERROR_INVALID_PARAMETER = -1,      /**< Invalid parameter */
-       MM_UTIL_ERROR_OUT_OF_MEMORY = -2,          /**< Out of memory */
-       MM_UTIL_ERROR_NO_SUCH_FILE  = -3,                  /**< No such file */
-       MM_UTIL_ERROR_INVALID_OPERATION = -4,      /**< Internal error */
-       MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT = -5,   /**< Not supported format */
-} mm_util_error_e;
-
-/**
  * Image formats
  */
 typedef enum {
index 77b58ad..2f35ddb 100755 (executable)
 #endif
 
 #include <gmodule.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <time.h>
 #include <unistd.h>
-#include <stdint.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/ioctl.h>
-/* tbm */
-#include <tbm_surface_internal.h>
 
 #define PATH_NEON_LIB                                  LIBPREFIX  "/libmmutil_imgp_neon.so"
 #define PATH_GSTCS_LIB                                 LIBPREFIX "/libmmutil_imgp_gstcs.so"
 
 #define IMGP_FUNC_NAME                         "mm_imgp"
-#define IMGP_FREE(src) { if (src != NULL) {g_free(src); src = NULL; } }
-#define SAFE_STRCPY(dst, src, n)       g_strlcpy(dst, src, n)
 
 /**
  * Image Process Info for dlopen
index 2b960a0..bfb51ca 100755 (executable)
  * limitations under the License.
  *
  */
+
+#include <gmodule.h>
 #include <limits.h>
-#include "mm_util_debug.h"
+#include "mm_util_private.h"
 #include "mm_util_imgp.h"
 #include "mm_util_imgp_internal.h"
 
@@ -58,7 +60,7 @@ static void __mm_destroy_temp_buffer(unsigned char *buffer[])
        int i = 0;
 
        for (i = 0; i < 4; i++)
-               IMGP_FREE(buffer[i]);
+               MMUTIL_SAFE_FREE(buffer[i]);
 }
 
 static gboolean __mm_cannot_convert_format(mm_util_img_format src_format, mm_util_img_format dst_format)
@@ -580,22 +582,22 @@ static int __mm_set_format_label(imgp_info_s *_imgp_info_s, mm_util_img_format s
                unsigned int src_fmt_len = strlen(src_fmt_lable) + 1;
                unsigned int dst_fmt_len = strlen(dst_fmt_lable) + 1;
                mm_util_debug("src_fmt_lable: %s dst_fmt_lable: %s", src_fmt_lable, dst_fmt_lable);
-               _imgp_info_s->input_format_label = (char *)malloc(src_fmt_len);
+               _imgp_info_s->input_format_label = (char *)calloc(1, src_fmt_len);
                if (_imgp_info_s->input_format_label == NULL) {
                        mm_util_error("[input] input_format_label is null");
                        return MM_UTIL_ERROR_OUT_OF_MEMORY;
                }
                memset(_imgp_info_s->input_format_label, 0, src_fmt_len);
-               SAFE_STRCPY(_imgp_info_s->input_format_label, src_fmt_lable, src_fmt_len);
+               MMUTIL_SAFE_STRCPY(_imgp_info_s->input_format_label, src_fmt_lable, src_fmt_len);
 
-               _imgp_info_s->output_format_label = (char *)malloc(dst_fmt_len);
+               _imgp_info_s->output_format_label = (char *)calloc(1, dst_fmt_len);
                if (_imgp_info_s->output_format_label == NULL) {
                        mm_util_error("[input] input_format_label is null");
-                       IMGP_FREE(_imgp_info_s->input_format_label);
+                       MMUTIL_SAFE_G_FREE(_imgp_info_s->input_format_label);
                        return MM_UTIL_ERROR_OUT_OF_MEMORY;
                }
                memset(_imgp_info_s->output_format_label, 0, dst_fmt_len);
-               SAFE_STRCPY(_imgp_info_s->output_format_label, dst_fmt_lable, dst_fmt_len);
+               MMUTIL_SAFE_STRCPY(_imgp_info_s->output_format_label, dst_fmt_lable, dst_fmt_len);
 
                mm_util_debug("input_format_label: %s output_format_label: %s", _imgp_info_s->input_format_label, _imgp_info_s->output_format_label);
        } else {
@@ -693,9 +695,9 @@ static int __mm_util_imgp_finalize(GModule *module, imgp_info_s *_imgp_info_s)
                ret = MM_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       IMGP_FREE(_imgp_info_s->input_format_label);
-       IMGP_FREE(_imgp_info_s->output_format_label);
-       IMGP_FREE(_imgp_info_s);
+       MMUTIL_SAFE_G_FREE(_imgp_info_s->input_format_label);
+       MMUTIL_SAFE_G_FREE(_imgp_info_s->output_format_label);
+       MMUTIL_SAFE_FREE(_imgp_info_s);
 
        return ret;
 }
@@ -1047,7 +1049,7 @@ static int __mm_util_processing(mm_util_s *handle)
 
        mm_util_debug("src: %p, dst: %p", handle->src, handle->dst);
 
-       dst_buf[src_index] = g_malloc(handle->src_buf_size);
+       dst_buf[src_index] = calloc(1, handle->src_buf_size);
        src_width = handle->src_width;
        src_height = handle->src_height;
        src_format = handle->src_format;
@@ -1059,7 +1061,7 @@ static int __mm_util_processing(mm_util_s *handle)
        if (handle->set_crop) {
                dst_index++;
                __mm_util_get_crop_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
-               dst_buf[dst_index] = g_malloc(dst_buf_size);
+               dst_buf[dst_index] = calloc(1, dst_buf_size);
                if (dst_buf[dst_index] == NULL) {
                        mm_util_error("[multi func] memory allocation error");
                        __mm_destroy_temp_buffer(dst_buf);
@@ -1078,7 +1080,7 @@ static int __mm_util_processing(mm_util_s *handle)
        } else if (handle->set_resize) {
                dst_index++;
                mm_util_get_image_size(src_format, handle->dst_width, handle->dst_height, &dst_buf_size);
-               dst_buf[dst_index] = g_malloc(dst_buf_size);
+               dst_buf[dst_index] = calloc(1, dst_buf_size);
                if (dst_buf[dst_index] == NULL) {
                        mm_util_error("[multi func] memory allocation error");
                        __mm_destroy_temp_buffer(dst_buf);
@@ -1098,7 +1100,7 @@ static int __mm_util_processing(mm_util_s *handle)
        if (handle->set_convert) {
                dst_index++;
                mm_util_get_image_size(handle->dst_format, src_width, src_height, &dst_buf_size);
-               dst_buf[dst_index] = g_malloc(dst_buf_size);
+               dst_buf[dst_index] = calloc(1, dst_buf_size);
                if (dst_buf[dst_index] == NULL) {
                        mm_util_error("[multi func] memory allocation error");
                        __mm_destroy_temp_buffer(dst_buf);
@@ -1130,7 +1132,7 @@ static int __mm_util_processing(mm_util_s *handle)
                        }
                }
                mm_util_get_image_size(src_format, src_width, src_height, &dst_buf_size);
-               dst_buf[dst_index] = g_malloc(dst_buf_size);
+               dst_buf[dst_index] = calloc(1, dst_buf_size);
                if (dst_buf[dst_index] == NULL) {
                        mm_util_error("[multi func] memory allocation error");
                        __mm_destroy_temp_buffer(dst_buf);
@@ -1340,7 +1342,7 @@ static int __mm_util_transform_exec(mm_util_s *handle, media_packet_h src_packet
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("__mm_create_media_format failed");
                media_format_unref(src_fmt);
-               IMGP_FREE(handle->dst);
+               MMUTIL_SAFE_FREE(handle->dst);
                return ret;
        }
        media_format_unref(src_fmt);
@@ -1349,12 +1351,12 @@ static int __mm_util_transform_exec(mm_util_s *handle, media_packet_h src_packet
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("__mm_create_media_packet failed");
                media_format_unref(dst_fmt);
-               IMGP_FREE(handle->dst);
+               MMUTIL_SAFE_FREE(handle->dst);
                return ret;
        }
 
        media_format_unref(dst_fmt);
-       IMGP_FREE(handle->dst);
+       MMUTIL_SAFE_FREE(handle->dst);
 
        return ret;
 }
@@ -1407,7 +1409,7 @@ int mm_util_create(mm_util_imgp_h *imgp_handle)
        ret = __mm_util_handle_init(handle);
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("_mm_util_handle_init failed");
-               IMGP_FREE(handle);
+               MMUTIL_SAFE_FREE(handle);
                TTRACE_END();
                return ret;
        }
@@ -1550,8 +1552,8 @@ int mm_util_transform(mm_util_imgp_h imgp_handle, media_packet_h src_packet, mm_
                return MM_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       IMGP_FREE(handle->_util_cb);
-       handle->_util_cb = (mm_util_cb_s *)malloc(sizeof(mm_util_cb_s));
+       MMUTIL_SAFE_FREE(handle->_util_cb);
+       handle->_util_cb = (mm_util_cb_s *)calloc(1, sizeof(mm_util_cb_s));
        if (handle->_util_cb) {
                handle->_util_cb->completed_cb = completed_callback;
                handle->_util_cb->user_data = user_data;
@@ -1624,8 +1626,8 @@ int mm_util_destroy(mm_util_imgp_h imgp_handle)
                return MM_UTIL_ERROR_INVALID_PARAMETER;
        }
 
-       IMGP_FREE(handle->_util_cb);
-       IMGP_FREE(handle);
+       MMUTIL_SAFE_FREE(handle->_util_cb);
+       MMUTIL_SAFE_FREE(handle);
        mm_util_debug("Success - Destroy Handle");
 
        TTRACE_END();
@@ -1662,7 +1664,7 @@ EXPORT_API int mm_util_convert_colorspace(const unsigned char *src, unsigned int
 
        mm_util_debug("(%d x %d)", src_width, src_height);
 
-       imgp_info_s *_imgp_info_s = (imgp_info_s *) g_malloc0(sizeof(imgp_info_s));
+       imgp_info_s *_imgp_info_s = (imgp_info_s *) calloc(1, sizeof(imgp_info_s));
        if (_imgp_info_s == NULL) {
                mm_util_error("ERROR - alloc handle");
                TTRACE_END();
@@ -1708,14 +1710,14 @@ EXPORT_API int mm_util_convert_colorspace(const unsigned char *src, unsigned int
                return ret;
        }
 
-       output_buffer = (unsigned char *) malloc(output_buffer_size);
+       output_buffer = (unsigned char *) calloc(1, output_buffer_size);
        if (output_buffer == NULL) {
-               mm_util_error("malloc failed");
+               mm_util_error("memory allocation failed");
                __mm_util_imgp_finalize(_module, _imgp_info_s);
                TTRACE_END();
                return MM_UTIL_ERROR_OUT_OF_MEMORY;
        }
-       mm_util_debug("malloc outputbuffer: %p (%d)", output_buffer, output_buffer_size);
+       mm_util_debug("memory allocation outputbuffer: %p (%d)", output_buffer, output_buffer_size);
 
        /* image processing */
        _mm_util_imgp_func = __mm_util_imgp_process(_module);
@@ -1726,14 +1728,14 @@ EXPORT_API int mm_util_convert_colorspace(const unsigned char *src, unsigned int
                if (ret != MM_UTIL_ERROR_NONE) {
                        mm_util_error("image processing failed");
                        __mm_util_imgp_finalize(_module, _imgp_info_s);
-                       IMGP_FREE(output_buffer);
+                       MMUTIL_SAFE_FREE(output_buffer);
                        TTRACE_END();
                        return ret;
                }
        } else {
                mm_util_error("g_module_symbol failed");
                __mm_util_imgp_finalize(_module, _imgp_info_s);
-               IMGP_FREE(output_buffer);
+               MMUTIL_SAFE_FREE(output_buffer);
                TTRACE_END();
                return MM_UTIL_ERROR_INVALID_PARAMETER;
        }
@@ -1742,7 +1744,7 @@ EXPORT_API int mm_util_convert_colorspace(const unsigned char *src, unsigned int
                ret = mm_util_crop_image(output_buffer, _imgp_info_s->output_stride, _imgp_info_s->output_elevation, dst_format, 0, 0, &_imgp_info_s->dst_width, &_imgp_info_s->dst_height, dst);
                if (ret != MM_UTIL_ERROR_NONE) {
                        mm_util_error("__mm_util_imgp_finalize failed");
-                       IMGP_FREE(output_buffer);
+                       MMUTIL_SAFE_FREE(output_buffer);
                        TTRACE_END();
                        return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
                }
@@ -1758,12 +1760,12 @@ EXPORT_API int mm_util_convert_colorspace(const unsigned char *src, unsigned int
        ret = __mm_util_imgp_finalize(_module, _imgp_info_s);
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("__mm_util_imgp_finalize failed");
-               IMGP_FREE(output_buffer);
+               MMUTIL_SAFE_FREE(output_buffer);
                TTRACE_END();
                return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
        }
 
-       IMGP_FREE(output_buffer);
+       MMUTIL_SAFE_FREE(output_buffer);
 
        mm_util_fleave();
 
@@ -1808,7 +1810,7 @@ EXPORT_API int mm_util_resize_image(const unsigned char *src, unsigned int src_w
 
        mm_util_debug("(%d x %d)", src_width, src_height);
 
-       imgp_info_s *_imgp_info_s = (imgp_info_s *) g_malloc0(sizeof(imgp_info_s));
+       imgp_info_s *_imgp_info_s = (imgp_info_s *) calloc(1, sizeof(imgp_info_s));
        if (_imgp_info_s == NULL) {
                mm_util_error("ERROR - alloc handle");
                TTRACE_END();
@@ -1864,15 +1866,15 @@ EXPORT_API int mm_util_resize_image(const unsigned char *src, unsigned int src_w
                return ret;
        }
 
-       output_buffer = (unsigned char *) malloc(output_buffer_size);
+       output_buffer = (unsigned char *) calloc(1, output_buffer_size);
        if (output_buffer == NULL) {
-               mm_util_error("malloc failed");
+               mm_util_error("memory allocation failed");
                __mm_util_imgp_finalize(_module, _imgp_info_s);
                TTRACE_END();
                return MM_UTIL_ERROR_OUT_OF_MEMORY;
        }
 
-       mm_util_debug("malloc outputbuffer: %p (%d)", output_buffer, output_buffer_size);
+       mm_util_debug("memory allocation outputbuffer: %p (%d)", output_buffer, output_buffer_size);
 
        /* image processing */
        _mm_util_imgp_func = __mm_util_imgp_process(_module);
@@ -1883,14 +1885,14 @@ EXPORT_API int mm_util_resize_image(const unsigned char *src, unsigned int src_w
                if (ret != MM_UTIL_ERROR_NONE) {
                        mm_util_error("image processing failed");
                        __mm_util_imgp_finalize(_module, _imgp_info_s);
-                       IMGP_FREE(output_buffer);
+                       MMUTIL_SAFE_FREE(output_buffer);
                        TTRACE_END();
                        return ret;
                }
        } else {
                mm_util_error("g_module_symbol failed");
                __mm_util_imgp_finalize(_module, _imgp_info_s);
-               IMGP_FREE(output_buffer);
+               MMUTIL_SAFE_FREE(output_buffer);
                TTRACE_END();
                return MM_UTIL_ERROR_INVALID_PARAMETER;
        }
@@ -1913,12 +1915,12 @@ EXPORT_API int mm_util_resize_image(const unsigned char *src, unsigned int src_w
        ret = __mm_util_imgp_finalize(_module, _imgp_info_s);
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("__mm_util_imgp_finalize failed");
-               IMGP_FREE(output_buffer);
+               MMUTIL_SAFE_FREE(output_buffer);
                TTRACE_END();
                return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
        }
 
-       IMGP_FREE(output_buffer);
+       MMUTIL_SAFE_FREE(output_buffer);
 
        mm_util_fenter();
 
@@ -1969,7 +1971,7 @@ EXPORT_API int mm_util_rotate_image(const unsigned char *src, unsigned int src_w
 
        mm_util_debug("(%d x %d)", src_width, src_height);
 
-       imgp_info_s *_imgp_info_s = (imgp_info_s *) g_malloc0(sizeof(imgp_info_s));
+       imgp_info_s *_imgp_info_s = (imgp_info_s *) calloc(1, sizeof(imgp_info_s));
        if (_imgp_info_s == NULL) {
                mm_util_error("ERROR - alloc handle");
                TTRACE_END();
@@ -2031,15 +2033,15 @@ EXPORT_API int mm_util_rotate_image(const unsigned char *src, unsigned int src_w
                return ret;
        }
 
-       output_buffer = (unsigned char *) malloc(output_buffer_size);
+       output_buffer = (unsigned char *) calloc(1, output_buffer_size);
        if (output_buffer == NULL) {
-               mm_util_error("malloc failed");
+               mm_util_error("memory allocation failed");
                __mm_util_imgp_finalize(_module, _imgp_info_s);
                TTRACE_END();
                return MM_UTIL_ERROR_OUT_OF_MEMORY;
        }
 
-       mm_util_debug("malloc outputbuffer: %p (%d)", output_buffer, output_buffer_size);
+       mm_util_debug("memory allocation outputbuffer: %p (%d)", output_buffer, output_buffer_size);
 
        /* image processing */
        _mm_util_imgp_func = __mm_util_imgp_process(_module);
@@ -2049,14 +2051,14 @@ EXPORT_API int mm_util_rotate_image(const unsigned char *src, unsigned int src_w
                if (ret != MM_UTIL_ERROR_NONE) {
                        mm_util_error("image processing failed");
                        __mm_util_imgp_finalize(_module, _imgp_info_s);
-                       IMGP_FREE(output_buffer);
+                       MMUTIL_SAFE_FREE(output_buffer);
                        TTRACE_END();
                        return ret;
                }
        } else {
                mm_util_error("g_module_symbol failed");
                __mm_util_imgp_finalize(_module, _imgp_info_s);
-               IMGP_FREE(output_buffer);
+               MMUTIL_SAFE_FREE(output_buffer);
                TTRACE_END();
                return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
        }
@@ -2091,12 +2093,12 @@ EXPORT_API int mm_util_rotate_image(const unsigned char *src, unsigned int src_w
        ret = __mm_util_imgp_finalize(_module, _imgp_info_s);
        if (ret != MM_UTIL_ERROR_NONE) {
                mm_util_error("__mm_util_imgp_finalize failed");
-               IMGP_FREE(output_buffer);
+               MMUTIL_SAFE_FREE(output_buffer);
                TTRACE_END();
                return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
        }
 
-       IMGP_FREE(output_buffer);
+       MMUTIL_SAFE_FREE(output_buffer);
 
        mm_util_fleave();
 
index 08dcce4..fceabac 100755 (executable)
@@ -3,6 +3,7 @@ bin_PROGRAMS = mm_util_imgp_testsuite
 mm_util_imgp_testsuite_SOURCES = mm_util_imgp_testsuite.c
 
 mm_util_imgp_testsuite_CFLAGS = -I$(srcdir)/../include \
+                                -I$(srcdir)/../../common/include \
                                 -I$(includedir)/drm \
                                  $(GMODULE_CFLAGS) \
                                  $(MMCAMCORDER_CFLAGS) \
@@ -12,7 +13,6 @@ mm_util_imgp_testsuite_CFLAGS = -I$(srcdir)/../include \
                                  $(XFIXES_CFLAGS) \
                                  $(DRI2PROTO_CFLAGS) \
                                  $(DRI2_CFLAGS) \
-                                 $(TBM_CFLAGS) \
                                  -fPIE -pie
 
 ############################################
@@ -28,6 +28,5 @@ mm_util_imgp_testsuite_LDADD = $(srcdir)/../libmmutil_imgp.la \
                               $(XFIXES_LIBS) \
                               $(DRI2PROTO_LIBS) \
                               $(DRI2_LIBS) \
-                              $(TBM_LIBS) \
                               $(MMLOG_LIBS)
 
index ef4f84f..9745b9c 100755 (executable)
  * limitations under the License.
  *
  */
+
+#include <glib.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <media_packet.h>
 #include "mm_util_imgp.h"
-#include "mm_util_imgp_internal.h"
-#include "mm_util_debug.h"
 
 #define MAX_STRING_LEN 128
 #define IMAGE_FORMAT_LABEL_BUFFER_SIZE 4
+#define IMGP_FREE(src) { if (src != NULL) {g_free(src); src = NULL; } }
+
 mm_util_imgp_h imgp_handle = 0;
 bool completed = false;
 
@@ -87,17 +94,17 @@ media_format_mimetype_e _format_to_mime(mm_util_img_format colorspace)
        case MM_UTIL_IMG_FMT_NV61:
        default:
                mimetype = -1;
-               mm_util_debug("Not Supported Format");
+               fprintf(stderr, "Not Supported Format\n");
                break;
        }
 
-       mm_util_debug("imgp fmt: %d mimetype fmt: %d", colorspace, mimetype);
+       fprintf(stderr, "imgp fmt: %d mimetype fmt: %d\n", colorspace, mimetype);
        return mimetype;
 }
 
 int _packet_finalize_callback(media_packet_h packet, int err, void *user_data)
 {
-       mm_util_debug("==> finalize callback func is called [%d] \n", err);
+       fprintf(stderr, "==> finalize callback func is called [%d] \n", err);
        return MEDIA_PACKET_FINALIZE;
 }
 
@@ -105,12 +112,12 @@ bool _transform_completed_cb(media_packet_h *packet, int error, void *user_data)
 {
        uint64_t size = 0;
        char* output_file = (char *)user_data;
-       mm_util_debug("imgp_handle: %p", imgp_handle);
+       fprintf(stderr, "imgp_handle: %p\n", imgp_handle);
 
-       mm_util_debug("output_file: %s", output_file);
+       fprintf(stderr, "output_file: %s\n", output_file);
 
        if (error == MM_UTIL_ERROR_NONE) {
-               mm_util_debug("completed");
+               fprintf(stderr, "completed\n");
                FILE *fp = fopen(output_file, "w");
                if (fp) {
                        media_packet_get_buffer_size(*packet, &size);
@@ -119,23 +126,23 @@ bool _transform_completed_cb(media_packet_h *packet, int error, void *user_data)
                        if (err != MEDIA_PACKET_ERROR_NONE) {
                                IMGP_FREE(dst);
                                fclose(fp);
-                               mm_util_error("Error media_packet_get_buffer_data_ptr (%d)", err);
+                               fprintf(stderr, "Error media_packet_get_buffer_data_ptr (%d)\n", err);
                                _signal();
                                return FALSE;
                        }
-                       mm_util_debug("dst: %p [%llu]", dst, size);
+                       fprintf(stderr, "dst: %p [%llu]\n", dst, size);
                        fwrite(dst, 1, size, fp);
-                       mm_util_debug("FREE");
+                       fprintf(stderr, "FREE\n");
                        fclose(fp);
                }
 
-               mm_util_debug("write result");
+               fprintf(stderr, "write result\n");
        } else {
-               mm_util_error("[Error] complete cb (%d)", error);
+               fprintf(stderr, "[Error] complete cb (%d)\n", error);
        }
 
        completed = true;
-       mm_util_debug("Destory - dst packet");
+       fprintf(stderr, "Destory - dst packet\n");
        media_packet_destroy(*packet);
 
        _signal();
@@ -179,42 +186,42 @@ int main(int argc, char *argv[])
 
        unsigned int size = 0;
 
-       mm_util_debug("command: %s src_width: %d, src_height: %d, src_format: %d, dst_width: %d, dst_height: %d, dst_format:%d, rotation:%d", command, src_width, src_height, src_format, dst_width, dst_height, dst_format, rotation);
+       fprintf(stderr, "command: %s src_width: %d, src_height: %d, src_format: %d, dst_width: %d, dst_height: %d, dst_format:%d, rotation:%d\n", command, src_width, src_height, src_format, dst_width, dst_height, dst_format, rotation);
 
        /* mem allocation for src dst buffer */
        mm_util_get_image_size(src_format, src_width, src_height, &size);
        src_size = (uint64_t)size;
        mm_util_get_image_size(dst_format, dst_width, dst_height, &size);
        dst_size = (uint64_t)size;
-       src = malloc(src_size);
-       dst = malloc(dst_size);
+       src = calloc(1, src_size);
+       dst = calloc(1, dst_size);
 
        { /* read input file */
                FILE *fp = fopen(filename, "r");
                if (fp == NULL) {
-                       mm_util_debug("\tfile open failed %d\n", errno);
+                       fprintf(stderr, "\tfile open failed %d\n", errno);
                        goto TEST_FAIL;
                }
 
                if (src == NULL) {
-                       mm_util_debug("\tmemory allocation failed\n");
+                       fprintf(stderr, "\tmemory allocation failed\n");
                        goto TEST_FAIL;
                }
 
                if (fread(src, 1, (int)src_size, fp) == src_size)
-                       mm_util_debug("#Success# fread");
+                       fprintf(stderr, "#Success# fread\n");
                else
-                       mm_util_error("#Error# fread");
+                       fprintf(stderr, "#Error# fread\n");
 
                if (src == NULL || src_size <= 0) {
-                       mm_util_error("#Error# fread");
+                       fprintf(stderr, "#Error# fread\n");
                        goto TEST_FAIL;
                }
 
        }
 
        {  /* ready output file */
-               char *output_fmt = (char *) g_malloc(sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE);
+               char *output_fmt = (char *) calloc(1, sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE);
                memset(output_fmt, 0, IMAGE_FORMAT_LABEL_BUFFER_SIZE);
                if (dst_format == MM_UTIL_IMG_FMT_YUV420 ||
                        dst_format == MM_UTIL_IMG_FMT_YUV422 ||
@@ -227,7 +234,7 @@ int main(int argc, char *argv[])
        }
 
        if (sync_mode) {
-               mm_util_debug("SYNC");
+               fprintf(stderr, "SYNC\n");
                if (strcmp(command, "convert") == 0)
                        ret = mm_util_convert_colorspace(src, src_width, src_height, src_format, dst, dst_format);
                else if (strcmp(command, "resize") == 0)
@@ -238,105 +245,105 @@ int main(int argc, char *argv[])
                        ret = mm_util_crop_image(src, src_width, src_height, src_format, start_x, start_y, &dst_width, &dst_height, dst);
 
                if (ret == MM_UTIL_ERROR_NONE) {
-                       mm_util_debug("Success - %s", command);
+                       fprintf(stderr, "Success - %s\n", command);
                } else {
-                       mm_util_debug("ERROR - %s", command);
+                       fprintf(stderr, "ERROR - %s\n", command);
                        goto TEST_FAIL;
                }
 
                {  /* write output file */
                        FILE *fpout = fopen(output_file, "w");
                        if (fpout) {
-                               mm_util_debug("dst: %p [%llu]", dst, dst_size);
+                               fprintf(stderr, "dst: %p [%llu]\n", dst, dst_size);
                                fwrite(dst, 1, dst_size, fpout);
-                               mm_util_debug("FREE");
+                               fprintf(stderr, "FREE\n");
                                fclose(fpout);
                        }
                }
        } else {  /* Async mode */
-               mm_util_debug("ASYNC");
+               fprintf(stderr, "ASYNC\n");
 
                /* Create Transform */
                ret = mm_util_create(&imgp_handle);
                if (ret == MM_UTIL_ERROR_NONE) {
-                       mm_util_debug("Success - Create Transcode Handle [imgp_handle: %p]", imgp_handle);
+                       fprintf(stderr, "Success - Create Transcode Handle [imgp_handle: %p]\n", imgp_handle);
                } else {
-                       mm_util_debug("ERROR - Create Transcode Handle");
+                       fprintf(stderr, "ERROR - Create Transcode Handle\n");
                        goto TEST_FAIL;
                }
                if (media_format_create(&fmt) == MEDIA_FORMAT_ERROR_NONE) {
                        if (media_format_set_video_mime(fmt, _format_to_mime(src_format)) != MEDIA_FORMAT_ERROR_NONE) {
                                media_format_unref(fmt);
-                               mm_util_error("[Error] Set - video mime");
+                               fprintf(stderr, "[Error] Set - video mime\n");
                                goto TEST_FAIL;
                        }
 
                        if (media_format_set_video_width(fmt, src_width) != MEDIA_FORMAT_ERROR_NONE) {
                                media_format_unref(fmt);
-                               mm_util_error("[Error] Set - video width");
+                               fprintf(stderr, "[Error] Set - video width\n");
                                goto TEST_FAIL;
                        }
 
                        if (media_format_set_video_height(fmt, src_height) != MEDIA_FORMAT_ERROR_NONE) {
                                media_format_unref(fmt);
-                               mm_util_error("[Error] Set - video height");
+                               fprintf(stderr, "[Error] Set - video height\n");
                                goto TEST_FAIL;
                        }
 
                        if (media_format_set_video_avg_bps(fmt, 15000000) != MEDIA_FORMAT_ERROR_NONE) {
                                media_format_unref(fmt);
-                               mm_util_error("[Error] Set - video avg bps");
+                               fprintf(stderr, "[Error] Set - video avg bps\n");
                                goto TEST_FAIL;
                        }
 
                        if (media_format_set_video_max_bps(fmt, 20000000) != MEDIA_FORMAT_ERROR_NONE) {
                                media_format_unref(fmt);
-                               mm_util_error("[Error] Set - video max bps");
+                               fprintf(stderr, "[Error] Set - video max bps\n");
                                goto TEST_FAIL;
                        }
 
-                       mm_util_debug("media_format_set_video_info success! w:%d, h:%d, format:%d\n", src_width, src_height, src_format);
+                       fprintf(stderr, "media_format_set_video_info success! w:%d, h:%d, format:%d\n", src_width, src_height, src_format);
                } else {
-                       mm_util_error("media_format_create failed...");
+                       fprintf(stderr, "media_format_create failed...\n");
                }
 
                /* Set Source */
                ret = media_packet_create_alloc(fmt, (media_packet_finalize_cb)_packet_finalize_callback, NULL, &src_packet);
                if (ret == MM_UTIL_ERROR_NONE) {
-                       mm_util_debug("Success - Create Media Packet(%p)", src_packet);
+                       fprintf(stderr, "Success - Create Media Packet(%p)\n", src_packet);
                        uint64_t buffer_size = (uint64_t)size;
                        if (media_packet_get_buffer_size(src_packet, &buffer_size) == MEDIA_PACKET_ERROR_NONE) {
-                               ptr = malloc(buffer_size);
+                               ptr = calloc(1, buffer_size);
                                if (ptr == NULL) {
-                                       mm_util_debug("\tmemory allocation failed\n");
+                                       fprintf(stderr, "\tmemory allocation failed\n");
                                        goto TEST_FAIL;
                                }
                                if (media_packet_get_buffer_data_ptr(src_packet, &ptr) == MEDIA_PACKET_ERROR_NONE) {
                                        if (src != NULL && src_size > 0) {
                                                memcpy(ptr, src, buffer_size);
-                                               mm_util_debug("memcpy");
+                                               fprintf(stderr, "memcpy\n");
                                        }
                                }
                        }
                } else {
-                       mm_util_debug("ERROR - Create Media Packet");
+                       fprintf(stderr, "ERROR - Create Media Packet\n");
                        return ret;
                }
 
                ret = mm_util_set_hardware_acceleration(imgp_handle, FALSE);
                if (ret == MM_UTIL_ERROR_NONE) {
-                       mm_util_debug("Success - Set hardware_acceleration");
+                       fprintf(stderr, "Success - Set hardware_acceleration\n");
                } else {
-                       mm_util_debug("ERROR - Set hardware_acceleration");
+                       fprintf(stderr, "ERROR - Set hardware_acceleration\n");
                        goto TEST_FAIL;
                }
 
                if (strcmp(command, "convert") == 0) {
                        ret = mm_util_set_colorspace_convert(imgp_handle, dst_format);
                        if (ret == MM_UTIL_ERROR_NONE) {
-                               mm_util_debug("Success - Set colorspace Info");
+                               fprintf(stderr, "Success - Set colorspace Info\n");
                        } else {
-                               mm_util_debug("ERROR - Set colorspace Info");
+                               fprintf(stderr, "ERROR - Set colorspace Info\n");
                                goto TEST_FAIL;
                        }
                }
@@ -344,9 +351,9 @@ int main(int argc, char *argv[])
                if (strcmp(command, "crop") == 0) {
                        ret = mm_util_set_crop_area(imgp_handle, start_x, start_y, (start_x + dst_width), (start_y + dst_height));
                        if (ret == MM_UTIL_ERROR_NONE) {
-                               mm_util_debug("Success - Set crop Info");
+                               fprintf(stderr, "Success - Set crop Info\n");
                        } else {
-                               mm_util_debug("ERROR - Set crop Info");
+                               fprintf(stderr, "ERROR - Set crop Info\n");
                                goto TEST_FAIL;
                        }
                }
@@ -354,9 +361,9 @@ int main(int argc, char *argv[])
                if (strcmp(command, "resize") == 0) {
                        ret = mm_util_set_resolution(imgp_handle, dst_width, dst_height);
                        if (ret == MM_UTIL_ERROR_NONE) {
-                               mm_util_debug("Success - Set resolution Info");
+                               fprintf(stderr, "Success - Set resolution Info\n");
                        } else {
-                               mm_util_debug("ERROR - Set resolution Info");
+                               fprintf(stderr, "ERROR - Set resolution Info\n");
                                goto TEST_FAIL;
                        }
                }
@@ -364,9 +371,9 @@ int main(int argc, char *argv[])
                if (strcmp(command, "rotate") == 0) {
                        ret = mm_util_set_rotation(imgp_handle, rotation);
                        if (ret == MM_UTIL_ERROR_NONE) {
-                               mm_util_debug("Success - Set rotation Info");
+                               fprintf(stderr, "Success - Set rotation Info\n");
                        } else {
-                               mm_util_debug("ERROR - Set rotation Info");
+                               fprintf(stderr, "ERROR - Set rotation Info\n");
                                goto TEST_FAIL;
                        }
                }
@@ -374,13 +381,13 @@ int main(int argc, char *argv[])
                /* Transform */
                ret = mm_util_transform(imgp_handle, src_packet, (mm_util_completed_callback) _transform_completed_cb, output_file);
                if (ret == MM_UTIL_ERROR_NONE) {
-                       mm_util_debug("Success - Transform");
+                       fprintf(stderr, "Success - Transform\n");
                } else {
-                       mm_util_error("ERROR - Transform");
+                       fprintf(stderr, "ERROR - Transform\n");
                        goto TEST_FAIL;
                }
 
-               mm_util_debug("Wait...");
+               fprintf(stderr, "Wait...\n");
                g_mutex_init(&g_thread_mutex);
                g_cond_init(&g_thread_cond);
                _wait();
@@ -389,9 +396,9 @@ int main(int argc, char *argv[])
 
                ret = mm_util_destroy(imgp_handle);
                if (ret == MM_UTIL_ERROR_NONE) {
-                       mm_util_debug("Success - Destroy");
+                       fprintf(stderr, "Success - Destroy\n");
                } else {
-                       mm_util_error("ERROR - Destroy");
+                       fprintf(stderr, "ERROR - Destroy\n");
                        goto TEST_FAIL;
                }
 
@@ -404,9 +411,9 @@ TEST_FAIL:
        IMGP_FREE(filename);
        if (!sync_mode) {
                media_format_unref(fmt);
-               mm_util_debug("Destory - src packet");
+               fprintf(stderr, "Destory - src packet\n");
                media_packet_destroy(src_packet);
-               mm_util_debug("destroy");
+               fprintf(stderr, "destroy\n");
        }
 
        return 0;
index 7690579..8218336 100755 (executable)
@@ -8,16 +8,15 @@ installmmutil_jpeg_HEADERS = include/mm_util_jpeg.h
 libmmutil_jpeg_la_SOURCES = mm_util_jpeg.c
 
 libmmutil_jpeg_la_CFLAGS = -I$(srcdir)/include \
+                               -I$(srcdir)/../common/include \
                                -I$(srcdir)/../imgp/include \
                                $(GLIB_CFLAGS) \
                                $(MEDIA_CFLAGS) \
                                -I/usr/include \
-                               $(SYSTEMINFO_CFLAGS) \
                                $(srcdir)/../imgp/libmmutil_imgp.la
 
 libmmutil_jpeg_la_LIBADD = $(GLIB_LIBS) -ljpeg -ldl -lttrace -lturbojpeg\
                                $(GMODULE_LIBS) \
-                               $(SYSTEMINFO_LIBS)\
                                $(MEDIA_LIBS)
 
 libmmutil_jpeg_la_CFLAGS += -DLIBPREFIX=\"$(libdir)\"
index bc1549a..b90b81a 100755 (executable)
@@ -22,6 +22,8 @@
 #ifndef __MM_UTIL_JPEG_H__
 #define __MM_UTIL_JPEG_H__
 
+#include "mm_util_type.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
index 95fc080..647df2e 100755 (executable)
  *
  */
 
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#include <sys/times.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
-#include <stdio.h> /* fopen() */
+#include <stdio.h>
+#include <unistd.h> /* fsync() */
 #include <jpeglib.h>
 #define LIBJPEG_TURBO 0
 #define ENC_MAX_LEN 8192
@@ -43,7 +33,7 @@
 #include <glib.h>
 #include "mm_util_jpeg.h"
 #include "mm_util_imgp.h"
-#include "mm_util_debug.h"
+#include "mm_util_private.h"
 #ifdef ENABLE_TTRACE
 #include <ttrace.h>
 #define TTRACE_BEGIN(NAME) traceBegin(TTRACE_TAG_IMAGE, NAME)
 #define MM_JPEG_ROUND_DOWN_4(num) ((num)&(~3))
 #define MM_JPEG_ROUND_DOWN_16(num) ((num)&(~15))
 
-#define ERR_BUF_LENGHT 256
-#define mm_util_stderror(fmt) do { \
-                       char buf[ERR_BUF_LENGHT] = {0,}; \
-                       strerror_r(errno, buf, ERR_BUF_LENGHT); \
-                       mm_util_error(fmt" : standard error= [%s]", buf); \
-               } while (0)
-
-#define IMG_JPEG_FREE(src) { if (src != NULL) {free(src); src = NULL; } }
-
 #if LIBJPEG_TURBO
 #define PAD(v, p) ((v+(p)-1)&(~((p)-1)))
 #define _throwtj() {printf("TurboJPEG ERROR:\n%s\n", tjGetErrorStr()); }
@@ -183,7 +164,7 @@ static void __mm_decode_libjpeg_turbo_decompress(tjhandle handle, unsigned char
                mm_util_debug("MM_UTIL_JPEG_FMT_RGB888 dstSize: %d _hdrsubsamp:%d", dstSize, _hdrsubsamp);
        }
 
-       if ((decoded_data->data = (void *)malloc(dstSize)) == NULL) {
+       if ((decoded_data->data = (void *)calloc(1, dstSize)) == NULL) {
                mm_util_error("dstBuf is NULL");
                return;
        }
@@ -256,7 +237,7 @@ static int __mm_image_decode_from_jpeg_file_with_libjpeg_turbo(mm_util_jpeg_yuv_
                mm_util_error("dhandle=tjInitDecompress()) is NULL");
                return MM_UTIL_ERROR_INVALID_PARAMETER;
        }
-       srcBuf = (unsigned char *) malloc(sizeof(char) * jpegSize);
+       srcBuf = (unsigned char *) calloc(1, sizeof(char) * jpegSize);
        if (srcBuf == NULL) {
                fclose(src);
                tjDestroy(dhandle);
@@ -297,7 +278,7 @@ static int __mm_image_decode_from_jpeg_memory_with_libjpeg_turbo(mm_util_jpeg_yu
                mm_util_error("dhandle=tjInitDecompress()) is NULL");
                return MM_UTIL_ERROR_INVALID_PARAMETER;
        }
-       srcBuf = (unsigned char *) malloc(sizeof(char) * size);
+       srcBuf = (unsigned char *) calloc(1, sizeof(char) * size);
        if (srcBuf == NULL) {
                fclose(src);
                tjDestroy(dhandle);
@@ -322,7 +303,7 @@ static void _mm_encode_libjpeg_turbo_compress(tjhandle handle, void *src, unsign
        unsigned long jpegSize = 0;
 
        jpegSize = w*h*tjPixelSize[TJPF_RGB];
-       srcBuf = (unsigned char *)malloc(jpegSize);
+       srcBuf = (unsigned char *)calloc(1, jpegSize);
 
        if (srcBuf == NULL) {
                mm_util_error("srcBuf is NULL");
@@ -334,7 +315,7 @@ static void _mm_encode_libjpeg_turbo_compress(tjhandle handle, void *src, unsign
                } else if (fmt == MM_UTIL_JPEG_FMT_YUV420 || fmt == MM_UTIL_JPEG_FMT_YUV422) {
                        __initBuf(srcBuf, w, h, TJPF_GRAY, flags);
                } else {
-                       IMG_JPEG_FREE(srcBuf);
+                       MMUTIL_SAFE_FREE(srcBuf);
                        mm_util_error("[%s][%05d] We can't support the IMAGE format");
                        return;
                }
@@ -359,7 +340,7 @@ static void _mm_encode_libjpeg_turbo_compress(tjhandle handle, void *src, unsign
                mm_util_error("fmt:%d is wrong", fmt);
        }
 
-       IMG_JPEG_FREE(srcBuf);
+       MMUTIL_SAFE_FREE(srcBuf);
 }
 
 static int __mm_image_encode_to_jpeg_file_with_libjpeg_turbo(const char *filename, void* src, int width, int height, mm_util_jpeg_yuv_format fmt, int quality)
@@ -547,12 +528,12 @@ static int __mm_image_encode_to_jpeg_file_with_libjpeg(const char *pFileName, vo
                mm_util_debug("jpeg_start_compress");
 
                if (flag) {
-                       void *large_rect = malloc(width);
-                       void *small_rect = malloc(width);
+                       void *large_rect = calloc(1, width);
+                       void *small_rect = calloc(1, width);
                        if (large_rect) {
                                memset(large_rect, 0x10, width);
                        } else {
-                               IMG_JPEG_FREE(small_rect);
+                               MMUTIL_SAFE_FREE(small_rect);
                                fclose(fpWriter);
                                mm_util_error("large rectangle memory");
                                return MM_UTIL_ERROR_INVALID_PARAMETER;
@@ -560,7 +541,7 @@ static int __mm_image_encode_to_jpeg_file_with_libjpeg(const char *pFileName, vo
                        if (small_rect) {
                                memset(small_rect, 0x80, width);
                        } else {
-                               IMG_JPEG_FREE(large_rect);
+                               MMUTIL_SAFE_FREE(large_rect);
                                fclose(fpWriter);
                                mm_util_error("small rectangle memory");
                                return MM_UTIL_ERROR_INVALID_PARAMETER;
@@ -591,8 +572,8 @@ static int __mm_image_encode_to_jpeg_file_with_libjpeg(const char *pFileName, vo
                                }
                        }
                        jpeg_write_raw_data(&cinfo, data, 16);
-                       IMG_JPEG_FREE(large_rect);
-                       IMG_JPEG_FREE(small_rect);
+                       MMUTIL_SAFE_FREE(large_rect);
+                       MMUTIL_SAFE_FREE(small_rect);
                } else {
                        for (j = 0; j < height; j += 16) {
                                for (i = 0; i < 16; i++) {
@@ -746,19 +727,19 @@ static int __mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, unsigned in
                mm_util_debug("jpeg_start_compress");
 
                if (flag) {
-                       void *large_rect = malloc(width);
-                       void *small_rect = malloc(width);
+                       void *large_rect = calloc(1, width);
+                       void *small_rect = calloc(1, width);
                        if (large_rect) {
                                memset(large_rect, 0x10, width);
                        } else {
-                               IMG_JPEG_FREE(small_rect);
+                               MMUTIL_SAFE_FREE(small_rect);
                                mm_util_error("large rectangle memory");
                                return MM_UTIL_ERROR_INVALID_PARAMETER;
                        }
                        if (small_rect) {
                                memset(small_rect, 0x80, width);
                        } else {
-                               IMG_JPEG_FREE(large_rect);
+                               MMUTIL_SAFE_FREE(large_rect);
                                mm_util_error("small rectangle memory");
                                return MM_UTIL_ERROR_INVALID_PARAMETER;
                        }
@@ -788,8 +769,8 @@ static int __mm_image_encode_to_jpeg_memory_with_libjpeg(void **mem, unsigned in
                                }
                        }
                        jpeg_write_raw_data(&cinfo, data, 16);
-                       IMG_JPEG_FREE(large_rect);
-                       IMG_JPEG_FREE(small_rect);
+                       MMUTIL_SAFE_FREE(large_rect);
+                       MMUTIL_SAFE_FREE(small_rect);
                } else {
                        for (j = 0; j < height; j += 16) {
                                for (i = 0; i < 16; i++) {
@@ -912,7 +893,7 @@ static int __mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data *
                /* If we get here, the JPEG code has signaled an error. We need to clean up the JPEG object, close the input file, and return.*/
                mm_util_debug("setjmp");
                jpeg_destroy_decompress(&dinfo);
-               IMG_JPEG_FREE(decoded_data->data);
+               MMUTIL_SAFE_FREE(decoded_data->data);
                fclose(infile);
                mm_util_debug("fclose");
                return MM_UTIL_ERROR_INVALID_PARAMETER;
@@ -1004,7 +985,7 @@ static int __mm_image_decode_from_jpeg_file_with_libjpeg(mm_util_jpeg_yuv_data *
                return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
        }
 
-       decoded_data->data = (void *) g_malloc0(decoded_data->size);
+       decoded_data->data = (void *) calloc(1, decoded_data->size);
        decoded_data->format = input_fmt;
 
        if (decoded_data->data == NULL) {
@@ -1096,7 +1077,7 @@ static int __mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data
        if (setjmp(jerr.setjmp_buffer)) {
                /* If we get here, the JPEG code has signaled an error.  We need to clean up the JPEG object, close the input file, and return.*/
                mm_util_debug("setjmp");
-               IMG_JPEG_FREE(decoded_data->data);
+               MMUTIL_SAFE_FREE(decoded_data->data);
                jpeg_destroy_decompress(&dinfo);
                return MM_UTIL_ERROR_NO_SUCH_FILE;
        }
@@ -1188,7 +1169,7 @@ static int __mm_image_decode_from_jpeg_memory_with_libjpeg(mm_util_jpeg_yuv_data
                return MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
        }
 
-       decoded_data->data = (void *) g_malloc0(decoded_data->size);
+       decoded_data->data = (void *) calloc(1, decoded_data->size);
        decoded_data->format = input_fmt;
 
        if (decoded_data->data == NULL) {
@@ -1288,11 +1269,11 @@ EXPORT_API int mm_util_jpeg_encode_to_file(const char *filename, void* src, int
                unsigned int dst_size = 0;
                ret = mm_util_get_image_size(MM_UTIL_IMG_FMT_NV12, (unsigned int)width, (unsigned int)height, &dst_size);
                unsigned char *dst = NULL;
-               dst = malloc(dst_size);
+               dst = calloc(1, dst_size);
                if (dst) {
                        ret = mm_util_convert_colorspace(src, width, height, MM_UTIL_IMG_FMT_NV12, dst, MM_UTIL_IMG_FMT_YUV420);
                        ret = __mm_image_encode_to_jpeg_file_with_libjpeg(filename, dst, width, height, MM_UTIL_JPEG_FMT_YUV420, quality);
-                       IMG_JPEG_FREE(dst);
+                       MMUTIL_SAFE_FREE(dst);
                } else {
                        TTRACE_END();
                        return MM_UTIL_ERROR_OUT_OF_MEMORY;
@@ -1349,11 +1330,11 @@ EXPORT_API int mm_util_jpeg_encode_to_memory(void **mem, unsigned int *size, voi
                unsigned int dst_size = 0;
                ret = mm_util_get_image_size(MM_UTIL_IMG_FMT_NV12, (unsigned int)width, (unsigned int)height, &dst_size);
                unsigned char *dst = NULL;
-               dst = malloc(dst_size);
+               dst = calloc(1, dst_size);
                if (dst) {
                        ret = mm_util_convert_colorspace(src, width, height, MM_UTIL_IMG_FMT_NV12, dst, MM_UTIL_IMG_FMT_YUV420);
                        ret = __mm_image_encode_to_jpeg_memory_with_libjpeg(mem, size, dst, width, height, MM_UTIL_JPEG_FMT_YUV420, quality);
-                       IMG_JPEG_FREE(dst);
+                       MMUTIL_SAFE_FREE(dst);
                } else {
                        TTRACE_END();
                        return MM_UTIL_ERROR_OUT_OF_MEMORY;
@@ -1424,20 +1405,20 @@ EXPORT_API int mm_util_decode_from_jpeg_file(mm_util_jpeg_yuv_data *decoded, con
                                        mm_util_error("fail mm_util_get_image_size");
 
                                unsigned char *dst = NULL;
-                               dst = malloc(dst_size);
+                               dst = calloc(1, dst_size);
                                if (dst) {
                                        ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
-                                       IMG_JPEG_FREE(decoded->data);
-                                       decoded->data = malloc(dst_size);
+                                       MMUTIL_SAFE_FREE(decoded->data);
+                                       decoded->data = calloc(1, dst_size);
                                        if (decoded->data == NULL) {
                                                mm_util_debug("memory allocation failed");
-                                               IMG_JPEG_FREE(dst);
+                                               MMUTIL_SAFE_FREE(dst);
                                                TTRACE_END();
                                                return MM_UTIL_ERROR_OUT_OF_MEMORY;
                                        }
                                        memcpy(decoded->data, dst, dst_size);
                                        decoded->size = dst_size;
-                                       IMG_JPEG_FREE(dst);
+                                       MMUTIL_SAFE_FREE(dst);
                                } else {
                                        mm_util_debug("memory allocation failed");
                                        TTRACE_END();
@@ -1507,20 +1488,20 @@ EXPORT_API int mm_util_decode_from_jpeg_memory(mm_util_jpeg_yuv_data *decoded, v
                        if (err != MM_UTIL_ERROR_NONE)
                                        mm_util_error("fail mm_util_get_image_size");
 
-                       dst = malloc(dst_size);
+                       dst = calloc(1, dst_size);
                        if (dst) {
                                ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
-                               IMG_JPEG_FREE(decoded->data);
-                               decoded->data = malloc(dst_size);
+                               MMUTIL_SAFE_FREE(decoded->data);
+                               decoded->data = calloc(1, dst_size);
                                if (decoded->data == NULL) {
                                        mm_util_debug("memory allocation failed");
-                                       IMG_JPEG_FREE(dst);
+                                       MMUTIL_SAFE_FREE(dst);
                                        TTRACE_END();
                                        return MM_UTIL_ERROR_OUT_OF_MEMORY;
                                }
                                memcpy(decoded->data, dst, dst_size);
                                decoded->size = dst_size;
-                               IMG_JPEG_FREE(dst);
+                               MMUTIL_SAFE_FREE(dst);
                        } else {
                                mm_util_debug("memory allocation failed");
                                TTRACE_END();
@@ -1598,20 +1579,20 @@ EXPORT_API int mm_util_decode_from_jpeg_file_with_downscale(mm_util_jpeg_yuv_dat
                                        mm_util_error("fail mm_util_get_image_size");
 
                                unsigned char *dst = NULL;
-                               dst = malloc(dst_size);
+                               dst = calloc(1, dst_size);
                                if (dst) {
                                        ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
-                                       IMG_JPEG_FREE(decoded->data);
-                                       decoded->data = malloc(dst_size);
+                                       MMUTIL_SAFE_FREE(decoded->data);
+                                       decoded->data = calloc(1, dst_size);
                                        if (decoded->data == NULL) {
                                                mm_util_debug("memory allocation failed");
-                                               IMG_JPEG_FREE(dst);
+                                               MMUTIL_SAFE_FREE(dst);
                                                TTRACE_END();
                                                return MM_UTIL_ERROR_OUT_OF_MEMORY;
                                        }
                                        memcpy(decoded->data, dst, dst_size);
                                        decoded->size = dst_size;
-                                       IMG_JPEG_FREE(dst);
+                                       MMUTIL_SAFE_FREE(dst);
                                } else {
                                        mm_util_debug("memory allocation failed");
                                        TTRACE_END();
@@ -1688,20 +1669,20 @@ EXPORT_API int mm_util_decode_from_jpeg_memory_with_downscale(mm_util_jpeg_yuv_d
                        if (err != MM_UTIL_ERROR_NONE)
                                        mm_util_error("fail mm_util_get_image_size");
 
-                       dst = malloc(dst_size);
+                       dst = calloc(1, dst_size);
                        if (dst) {
                                ret = mm_util_convert_colorspace(decoded->data, decoded->width, decoded->height, MM_UTIL_IMG_FMT_YUV420, dst, MM_UTIL_IMG_FMT_NV12);
-                               IMG_JPEG_FREE(decoded->data);
-                               decoded->data = malloc(dst_size);
+                               MMUTIL_SAFE_FREE(decoded->data);
+                               decoded->data = calloc(1, dst_size);
                                if (decoded->data == NULL) {
                                        mm_util_debug("memory allocation failed");
-                                       IMG_JPEG_FREE(dst);
+                                       MMUTIL_SAFE_FREE(dst);
                                        TTRACE_END();
                                        return MM_UTIL_ERROR_OUT_OF_MEMORY;
                                }
                                memcpy(decoded->data, dst, dst_size);
                                decoded->size = dst_size;
-                               IMG_JPEG_FREE(dst);
+                               MMUTIL_SAFE_FREE(dst);
                        } else {
                                mm_util_debug("memory allocation failed");
                                TTRACE_END();
index 2448e6d..60c7fd9 100755 (executable)
@@ -3,7 +3,7 @@ bin_PROGRAMS = mm_util_jpeg_testsuite
 mm_util_jpeg_testsuite_SOURCES = mm_util_jpeg_testsuite.c
 
 mm_util_jpeg_testsuite_CFLAGS = -I$(srcdir)/../include \
-                               -I$(srcdir)/../../imgp/include
+                               -I$(srcdir)/../../common/include
 mm_util_jpeg_testsuite_CFLAGS += $(MEDIA_CFLAGS) \
                                 -fPIE -pie \
                                 $(TZ_PLATFORM_CONFIG_FLAGS)
index 29aea88..1504314 100755 (executable)
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <unistd.h>
 #include <mm_util_jpeg.h>
-#include <mm_util_imgp.h>
 #include <tzplatform_config.h>
 
 #define ENCODE_RESULT_PATH tzplatform_mkpath(TZ_USER_CONTENT, "encode_test.jpg")
@@ -65,9 +60,9 @@ static int _read_file(char *file_name, void **data, unsigned int *data_size)
        file_size = ftell(fp);
        if (file_size > -1L) {
                rewind(fp);
-               *data = (void *)malloc(file_size);
+               *data = (void *)calloc(1, file_size);
                if (*data == NULL) {
-                       fprintf(stderr, "\tmalloc failed %d\n", errno);
+                       fprintf(stderr, "\tmemory allocation failed %d\n", errno);
                        fclose(fp);
                        fp = NULL;
                        return FALSE;
index f0ac97a..0cb6501 100755 (executable)
@@ -16,9 +16,7 @@ BuildRequires:  pkgconfig(gmodule-2.0)
 BuildRequires:  libjpeg-turbo-devel
 BuildRequires:  pkgconfig(libtzplatform-config)
 BuildRequires:  pkgconfig(capi-media-tool)
-BuildRequires:  pkgconfig(libtbm)
 BuildRequires:  pkgconfig(opencv)
-BuildRequires:  pkgconfig(capi-system-info)
 BuildRequires:  pkgconfig(ttrace)
 BuildRequires:  libpng-devel
 BuildRequires:  giflib-devel
index 0a1733b..9a4c57b 100644 (file)
@@ -3,21 +3,20 @@ ACLOCAL_AMFLAGS='-I m4'
 lib_LTLIBRARIES = libmmutil_png.la
 
 installmmutil_pngdir = $(includedir)/mmf
-installmmutil_png_HEADERS = include/mm_util_png.h
+installmmutil_png_HEADERS = include/mm_util_png.h \
+                            ../common/include/mm_util_type.h
 
 libmmutil_png_la_SOURCES = mm_util_png.c
 
 libmmutil_png_la_CFLAGS = -I$(srcdir)/include \
-                               -I$(srcdir)/../imgp/include \
+                               -I$(srcdir)/../common/include \
                                $(GLIB_CFLAGS) \
                                $(MEDIA_CFLAGS) \
                                -I/usr/include \
-                               $(SYSTEMINFO_CFLAGS) \
                                $(srcdir)/../imgp/libmmutil_imgp.la
 
 libmmutil_png_la_LIBADD = $(GLIB_LIBS) -lpng -ldl -lttrace\
                                $(GMODULE_LIBS) \
-                               $(SYSTEMINFO_LIBS)\
                                $(MEDIA_LIBS)
 
 libmmutil_png_la_CFLAGS += -DLIBPREFIX=\"$(libdir)\"
index 0141b73..a678774 100755 (executable)
@@ -25,8 +25,8 @@
 #ifdef __cplusplus
 extern "C" {
 #endif
-#include "mm_util_imgp.h"
 #include "png.h"
+#include "mm_util_type.h"
 
 /**
     @addtogroup UTILITY
index 01c6f39..80cb8d3 100755 (executable)
  *
  */
 
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <sys/ioctl.h>
-#include <sys/time.h>
-#include <sys/times.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
 #include <stdio.h>                             /* fopen() */
-#include <system_info.h>
 
 #include <glib.h>
 
 #include "mm_util_png.h"
-#include "mm_util_debug.h"
+#include "mm_util_private.h"
 
 #define MM_UTIL_PNG_BYTES_TO_CHECK 4
 #define MM_UTIL_PROGRESSIVE_BYTES_DEFAULT 1024
index d74868e..947982b 100755 (executable)
@@ -3,7 +3,7 @@ bin_PROGRAMS = mm_util_png_testsuite
 mm_util_png_testsuite_SOURCES = mm_util_png_testsuite.c
 
 mm_util_png_testsuite_CFLAGS = -I$(srcdir)/../include \
-                               -I$(srcdir)/../../imgp/include
+                               -I$(srcdir)/../../common/include
 mm_util_png_testsuite_CFLAGS += $(MEDIA_CFLAGS) \
                                 -fPIE -pie \
                                 $(TZ_PLATFORM_CONFIG_FLAGS)
index dc73899..c44310f 100755 (executable)
@@ -23,8 +23,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <mm_util_png.h>
 
 #define DECODE_RESULT_PATH "/media/decode_test."
@@ -60,9 +58,9 @@ static int _read_file(char *file_name, void **data, int *data_size)
        file_size = ftell(fp);
        if (file_size > -1L) {
                rewind(fp);
-               *data = (void *)malloc(file_size);
+               *data = (void *)calloc(1, file_size);
                if (*data == NULL) {
-                       fprintf(stderr, "\tmalloc failed %d\n", errno);
+                       fprintf(stderr, "\tmemory allocation failed %d\n", errno);
                        fclose(fp);
                        fp = NULL;
                        return FALSE;
@@ -178,7 +176,7 @@ int main(int argc, char *argv[])
                                        snprintf(filename, BUFFER_SIZE, "%s%s", DECODE_RESULT_PATH, "png");
                                }
 
-                               data = malloc(decoded_data.size);
+                               data = calloc(1, decoded_data.size);
                                memcpy(data, decoded_data.data, decoded_data.size);
 
                                mm_util_init_encode_png(&encoded_data);