summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMinje Ahn <minje.ahn@samsung.com>2017-05-22 06:22:48 (GMT)
committerMinje Ahn <minje.ahn@samsung.com>2017-05-22 06:27:34 (GMT)
commitbddb7b6537d4d96c29c3343ce454a1b1462c07a4 (patch)
treec87d747ef15ab3b7cc7399853f3397ea052dab94
parent8a2d56bc350e48c3109d4381f670b676494dd39e (diff)
downloadlibmedia-thumbnail-bddb7b6537d4d96c29c3343ce454a1b1462c07a4.zip
libmedia-thumbnail-bddb7b6537d4d96c29c3343ce454a1b1462c07a4.tar.gz
libmedia-thumbnail-bddb7b6537d4d96c29c3343ce454a1b1462c07a4.tar.bz2
Remove and merge DB operationrefs/changes/62/130362/2
Change-Id: I86b50705f05f68307a0b0d76df244e740626026c Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
-rw-r--r--packaging/libmedia-thumbnail.spec2
-rwxr-xr-xsrc/include/util/media-thumb-db.h5
-rwxr-xr-xsrc/util/media-thumb-db.c312
3 files changed, 26 insertions, 293 deletions
diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec
index 30a0f12..6495587 100644
--- a/packaging/libmedia-thumbnail.spec
+++ b/packaging/libmedia-thumbnail.spec
@@ -1,6 +1,6 @@
Name: libmedia-thumbnail
Summary: Media thumbnail service library for multimedia applications
-Version: 0.2.6
+Version: 0.2.7
Release: 0
Group: Multimedia/Libraries
License: Apache-2.0 and PD
diff --git a/src/include/util/media-thumb-db.h b/src/include/util/media-thumb-db.h
index 03cca1f..b3d2d71 100755
--- a/src/include/util/media-thumb-db.h
+++ b/src/include/util/media-thumb-db.h
@@ -28,11 +28,8 @@
#define STRING_VALID(str) \
((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
-#define SELECT_MEDIA_BY_PATH "SELECT thumbnail_path FROM media WHERE path='%q';"
-#define SELECT_TYPE_BY_PATH "SELECT media_type FROM media WHERE path='%q';"
-#define SELECT_WH_BY_PATH "SELECT width, height FROM media WHERE path='%q';"
+#define SELECT_THUMB_BY_PATH "SELECT thumbnail_path, width, height FROM media WHERE path='%q';"
#define UPDATE_THUMB_BY_PATH "UPDATE media SET thumbnail_path = '%q' WHERE path='%q';"
-#define UPDATE_WH_BY_PATH "UPDATE media SET width=%d,height=%d WHERE path='%q';"
#define UPDATE_THUMB_WH_BY_PATH "UPDATE media SET thumbnail_path = '%q', width=%d,height=%d WHERE path='%q';"
sqlite3 *_media_thumb_db_get_handle();
diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c
index 540d31b..33d00ca 100755
--- a/src/util/media-thumb-db.c
+++ b/src/util/media-thumb-db.c
@@ -34,165 +34,37 @@ sqlite3 *_media_thumb_db_get_handle()
return db_handle;
}
-int _media_thumb_get_type_from_db(sqlite3 *handle,
- const char *origin_path,
- int *type)
-{
- int err = MS_MEDIA_ERR_NONE;
- char *path_string = NULL;
- char *query_string = NULL;
- sqlite3_stmt *stmt = NULL;
-
- thumb_dbg_slog("Origin path : %s", origin_path);
-
- if (handle == NULL) {
- thumb_err("DB handle is NULL");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
- if (!STRING_VALID(origin_path)) {
- thumb_err("Invalid origin_path");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- path_string = sqlite3_mprintf("%s", origin_path);
- if (!STRING_VALID(path_string)) {
- thumb_err("Memory allocation is failed");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
- query_string = sqlite3_mprintf(SELECT_TYPE_BY_PATH, path_string);
- if (!STRING_VALID(query_string)) {
- thumb_err("Memory allocation is failed");
- sqlite3_free(path_string);
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- thumb_dbg("Query: %s", query_string);
-
- err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL);
-
- sqlite3_free(query_string);
- sqlite3_free(path_string);
-
- if (SQLITE_OK != err) {
- thumb_err("prepare error [%s]", sqlite3_errmsg(handle));
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
-
- err = sqlite3_step(stmt);
- if (err != SQLITE_ROW) {
- thumb_err("end of row [%s]", sqlite3_errmsg(handle));
- sqlite3_finalize(stmt);
- return MS_MEDIA_ERR_DB_NO_RECORD;
- }
-
- *type = sqlite3_column_int(stmt, 0);
- sqlite3_finalize(stmt);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-
-int _media_thumb_get_wh_from_db(sqlite3 *handle,
+int _media_thumb_get_thumb_path_wh_from_db(sqlite3 *handle,
const char *origin_path,
+ char *thumb_path,
+ int max_length,
int *width,
int *height)
{
- thumb_dbg_slog("Origin path : %s", origin_path);
-
- if (handle == NULL) {
- thumb_err("DB handle is NULL");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
- if (!STRING_VALID(origin_path)) {
- thumb_err("Invalid origin_path");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
int err = MS_MEDIA_ERR_NONE;
- char *path_string = NULL;
char *query_string = NULL;
sqlite3_stmt *stmt = NULL;
- path_string = sqlite3_mprintf("%s", origin_path);
- if (!STRING_VALID(path_string)) {
- thumb_err("Memory allocation is failed");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- query_string = sqlite3_mprintf(SELECT_WH_BY_PATH, path_string);
- if (!STRING_VALID(query_string)) {
- thumb_err("Memory allocation is failed");
- sqlite3_free(path_string);
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- thumb_dbg_slog("Query: %s", query_string);
-
- err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL);
-
- sqlite3_free(query_string);
- sqlite3_free(path_string);
-
- if (SQLITE_OK != err) {
- thumb_err("prepare error [%s]", sqlite3_errmsg(handle));
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
-
- err = sqlite3_step(stmt);
- if (err != SQLITE_ROW) {
- thumb_err("end of row [%s]", sqlite3_errmsg(handle));
- sqlite3_finalize(stmt);
- return MS_MEDIA_ERR_DB_INTERNAL;
- }
-
- *width = sqlite3_column_int(stmt, 0);
- *height = sqlite3_column_int(stmt, 1);
- sqlite3_finalize(stmt);
-
- return MS_MEDIA_ERR_NONE;
-}
-
-int _media_thumb_get_thumb_path_from_db(sqlite3 *handle,
- const char *origin_path,
- char *thumb_path,
- int max_length)
-{
- thumb_dbg_slog("Origin path : %s", origin_path);
-
if (handle == NULL) {
thumb_err("DB handle is NULL");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
+
if (!STRING_VALID(origin_path)) {
thumb_err("Invalid origin_path");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- int err = MS_MEDIA_ERR_NONE;
- char *path_string = NULL;
- char *query_string = NULL;
- sqlite3_stmt *stmt = NULL;
-
- path_string = sqlite3_mprintf("%s", origin_path);
- if (!STRING_VALID(path_string)) {
- thumb_err("Memory allocation is failed");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- query_string = sqlite3_mprintf(SELECT_MEDIA_BY_PATH, path_string);
+ query_string = sqlite3_mprintf(SELECT_THUMB_BY_PATH, origin_path);
if (!STRING_VALID(query_string)) {
thumb_err("Memory allocation is failed");
- sqlite3_free(path_string);
return MS_MEDIA_ERR_OUT_OF_MEMORY;
}
thumb_dbg_slog("Query: %s", query_string);
-
err = sqlite3_prepare_v2(handle, query_string, strlen(query_string), &stmt, NULL);
-
sqlite3_free(query_string);
- sqlite3_free(path_string);
-
if (SQLITE_OK != err) {
thumb_err("prepare error [%s]", sqlite3_errmsg(handle));
return MS_MEDIA_ERR_DB_INTERNAL;
@@ -205,112 +77,21 @@ int _media_thumb_get_thumb_path_from_db(sqlite3 *handle,
return MS_MEDIA_ERR_DB_INTERNAL;
}
- if (sqlite3_column_text(stmt, 0))
+ if (sqlite3_column_text(stmt, 0)) {
strncpy(thumb_path, (const char *)sqlite3_column_text(stmt, 0), max_length);
- else
+ *width = sqlite3_column_int(stmt, 1);
+ *height = sqlite3_column_int(stmt, 2);
+ } else {
thumb_path[0] = '\0';
+ *width = 0;
+ *height = 0;
+ }
sqlite3_finalize(stmt);
return MS_MEDIA_ERR_NONE;
}
-int _media_thumb_update_thumb_path_to_db(sqlite3 *handle,
- const char *origin_path,
- char *thumb_path,
- uid_t uid)
-{
- int err = MS_MEDIA_ERR_NONE;
- char *path_string = NULL;
- char *thumbpath_string = NULL;
- char *query_string = NULL;
-
- if (handle == NULL) {
- thumb_err("DB handle is NULL");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
- if (!STRING_VALID(origin_path)) {
- thumb_err("Invalid origin_path");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- path_string = sqlite3_mprintf("%s", origin_path);
- if (!STRING_VALID(path_string)) {
- thumb_err("Memory allocation is failed");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
- thumbpath_string = sqlite3_mprintf("%s", thumb_path);
- if (!STRING_VALID(thumbpath_string)) {
- thumb_err("Memory allocation is failed");
- sqlite3_free(path_string);
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
- query_string = sqlite3_mprintf(UPDATE_THUMB_BY_PATH, thumbpath_string, path_string);
- if (!STRING_VALID(query_string)) {
- thumb_err("Memory allocation is failed");
- sqlite3_free(path_string);
- sqlite3_free(thumbpath_string);
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- err = media_db_request_update_db(query_string, uid);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("media_db_request_update_db failed : %d", err);
- } else {
- thumb_dbg("Query success");
- }
-
- sqlite3_free(path_string);
- sqlite3_free(thumbpath_string);
- sqlite3_free(query_string);
-
- return err;
-}
-
-int _media_thumb_update_wh_to_db(sqlite3 *handle,
- const char *origin_path,
- int width,
- int height,
- uid_t uid)
-{
- int err = MS_MEDIA_ERR_NONE;
- char *path_string = NULL;
- char *query_string = NULL;
-
- if (handle == NULL) {
- thumb_err("DB handle is NULL");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
- if (!STRING_VALID(origin_path)) {
- thumb_err("Invalid origin_path");
- return MS_MEDIA_ERR_INVALID_PARAMETER;
- }
-
- path_string = sqlite3_mprintf("%s", origin_path);
- if (!STRING_VALID(path_string)) {
- thumb_err("Memory allocation is failed");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
- query_string = sqlite3_mprintf(UPDATE_WH_BY_PATH, width, height, path_string);
- if (!STRING_VALID(query_string)) {
- thumb_err("Memory allocation is failed");
- sqlite3_free(path_string);
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
-
- err = media_db_request_update_db(query_string, uid);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("media_db_request_update_db failed : %d", err);
- } else {
- thumb_dbg("Query success");
- }
-
- sqlite3_free(path_string);
- sqlite3_free(query_string);
-
- return err;
-}
-
int _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle,
const char *origin_path,
char *thumb_path,
@@ -319,7 +100,6 @@ int _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle,
uid_t uid)
{
int err = MS_MEDIA_ERR_NONE;
- char *path_string = NULL;
char *query_string = NULL;
if (handle == NULL) {
@@ -331,15 +111,13 @@ int _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle,
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- path_string = sqlite3_mprintf("%s", origin_path);
- if (!STRING_VALID(path_string)) {
- thumb_err("Memory allocation is failed");
- return MS_MEDIA_ERR_OUT_OF_MEMORY;
- }
- query_string = sqlite3_mprintf(UPDATE_THUMB_WH_BY_PATH, thumb_path, width, height, path_string);
+ if (width > 0 && height > 0)
+ query_string = sqlite3_mprintf(UPDATE_THUMB_WH_BY_PATH, thumb_path, width, height, origin_path);
+ else
+ query_string = sqlite3_mprintf(UPDATE_THUMB_BY_PATH, thumb_path, origin_path);
+
if (!STRING_VALID(query_string)) {
thumb_err("Memory allocation is failed");
- sqlite3_free(path_string);
return MS_MEDIA_ERR_OUT_OF_MEMORY;
}
@@ -350,7 +128,6 @@ int _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle,
thumb_dbg("Query success");
}
- sqlite3_free(path_string);
sqlite3_free(query_string);
return err;
@@ -377,8 +154,6 @@ int _media_thumb_db_disconnect()
err = media_db_disconnect(db_handle);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("media_db_disconnect failed: %d", err);
- db_handle = NULL;
- return err;
}
db_handle = NULL;
@@ -393,9 +168,10 @@ int _media_thumb_get_thumb_from_db_with_size(const char *origin_path,
int *height)
{
int err = MS_MEDIA_ERR_NONE;
+ int orig_w = 0;
+ int orig_h = 0;
- //err = minfo_get_thumb_path(mb_svc_handle, origin_path, thumb_path, max_length);
- err = _media_thumb_get_thumb_path_from_db(db_handle, origin_path, thumb_path, max_length);
+ err = _media_thumb_get_thumb_path_wh_from_db(db_handle, origin_path, thumb_path, max_length, &orig_w, &orig_h);
if (err != MS_MEDIA_ERR_NONE) {
thumb_warn("Original path doesn't exist in DB");
return err;
@@ -415,17 +191,8 @@ int _media_thumb_get_thumb_from_db_with_size(const char *origin_path,
return MS_MEDIA_ERR_INTERNAL;
} else {
thumb_dbg("This thumb path already exist");
- int orig_w = 0;
- int orig_h = 0;
-
- err = _media_thumb_get_wh_from_db(db_handle, origin_path, &orig_w, &orig_h);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_get_wh_from_db failed : %d", err);
- } else {
- thumb_err("_media_thumb_get_wh_from_db Success ( w:%d, h:%d )", orig_w, orig_h);
- *width = orig_w;
- *height = orig_h;
- }
+ *width = orig_w;
+ *height = orig_h;
}
return MS_MEDIA_ERR_NONE;
@@ -438,44 +205,13 @@ int _media_thumb_update_db(const char *origin_path,
uid_t uid)
{
int err = MS_MEDIA_ERR_NONE;
- int media_type = THUMB_NONE_TYPE;
- err = _media_thumb_get_type_from_db(db_handle, origin_path, &media_type);
+ err = _media_thumb_update_thumb_path_wh_to_db(db_handle, origin_path, thumb_path, width, height, uid);
if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_get_type_from_db (%s) failed: %d", origin_path, err);
- return err;
- }
-
-#if 0
- err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path);
- if (err < 0) {
- thumb_err("_media_thumb_update_thumb_path_to_db (%s) failed: %d", origin_path, err);
+ thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err);
return err;
}
- if (media_type == THUMB_IMAGE_TYPE && width > 0 && height > 0) {
- err = _media_thumb_update_wh_to_db(db_handle, origin_path, width, height);
- if (err < 0) {
- thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err);
- return err;
- }
- }
-#else
- if (media_type == THUMB_IMAGE_TYPE && width > 0 && height > 0) {
- err = _media_thumb_update_thumb_path_wh_to_db(db_handle, origin_path, thumb_path, width, height, uid);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err);
- return err;
- }
- } else {
- err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path, uid);
- if (err != MS_MEDIA_ERR_NONE) {
- thumb_err("_media_thumb_update_thumb_path_to_db (%s) failed: %d", origin_path, err);
- return err;
- }
- }
-#endif
-
thumb_dbg("_media_thumb_update_db success");
return MS_MEDIA_ERR_NONE;