*
*/
-#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)
#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"
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);
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);
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)
//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;
}
//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;
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);
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(®ex, "[^/]\\.jpe?g$", REG_ICASE | REG_EXTENDED) != 0) {
+ thumb_err("regcomp failed");
+ return THUMB_FAIL;
+ }
+
+ if (regexec(®ex, thumb_path, 0, NULL, 0) == REG_NOMATCH) {
thumb_err("Unsupported path or extensions [%s]", thumb_path);
return THUMB_FAIL;
}
+ regfree(®ex);
return create_video_thumbnail_to_file(path, width, height, thumb_path, false);
}
#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")
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);