From: Haejeong Kim Date: Mon, 5 Jun 2017 07:46:30 +0000 (+0900) Subject: Add APIs to support C# X-Git-Tag: accepted/tizen/unified/20170608.072432^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F42%2F132442%2F4;p=platform%2Fcore%2Fapi%2Fmedia-content.git Add APIs to support C# Change-Id: Ifc6bbfe55dc60c04a89ef8b9e4f95fb5e6d85f01 --- diff --git a/include/media_content_internal.h b/include/media_content_internal.h index a3260ec..e8d4a3e 100755 --- a/include/media_content_internal.h +++ b/include/media_content_internal.h @@ -38,8 +38,15 @@ int media_bookmark_set_thumbnail_path(media_bookmark_h bookmark, const char *pat int media_bookmark_insert_to_db_v2(media_bookmark_h bookmark); /*Playlist for C#*/ -int media_playlist_create(const char *name, media_playlist_h *playlist); +int media_playlist_create(media_playlist_h *playlist); +int media_playlist_get_play_order_v2(int playlist_id, int playlist_member_id, int *play_order); int media_playlist_insert_to_db_v2(media_playlist_h playlist); +int media_playlist_update_to_db_v2(int playlist_id, media_playlist_h playlist); + +/*Tag for C#*/ +int media_tag_create(media_tag_h *tag); +int media_tag_insert_to_db_v2(media_tag_h tag); +int media_tag_update_to_db_v2(int tag_id, media_tag_h tag); #ifdef __cplusplus } diff --git a/include_product/media_content_internal.h b/include_product/media_content_internal.h index a3260ec..e8d4a3e 100755 --- a/include_product/media_content_internal.h +++ b/include_product/media_content_internal.h @@ -38,8 +38,15 @@ int media_bookmark_set_thumbnail_path(media_bookmark_h bookmark, const char *pat int media_bookmark_insert_to_db_v2(media_bookmark_h bookmark); /*Playlist for C#*/ -int media_playlist_create(const char *name, media_playlist_h *playlist); +int media_playlist_create(media_playlist_h *playlist); +int media_playlist_get_play_order_v2(int playlist_id, int playlist_member_id, int *play_order); int media_playlist_insert_to_db_v2(media_playlist_h playlist); +int media_playlist_update_to_db_v2(int playlist_id, media_playlist_h playlist); + +/*Tag for C#*/ +int media_tag_create(media_tag_h *tag); +int media_tag_insert_to_db_v2(media_tag_h tag); +int media_tag_update_to_db_v2(int tag_id, media_tag_h tag); #ifdef __cplusplus } diff --git a/packaging/capi-content-media-content.spec b/packaging/capi-content-media-content.spec index f1351fd..b36928b 100755 --- a/packaging/capi-content-media-content.spec +++ b/packaging/capi-content-media-content.spec @@ -1,6 +1,6 @@ Name: capi-content-media-content Summary: A Media content library in Tizen Native API -Version: 0.3.11 +Version: 0.3.12 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/media_bookmark.c b/src/media_bookmark.c index a1b70fb..2edeb29 100755 --- a/src/media_bookmark.c +++ b/src/media_bookmark.c @@ -17,6 +17,31 @@ #include +static int __media_bookmark_check_media_id(const char *media_id); + +static int __media_bookmark_check_media_id(const char *media_id) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + char *query_str = NULL; + sqlite3_stmt *stmt = NULL; + int item_count = 0; + + media_content_retvm_if(!STRING_VALID(media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media_id"); + + query_str = sqlite3_mprintf(SELECT_MEDIA_COUNT_FROM_MEDIA_BY_ID, media_id); + ret = _content_query_prepare(&stmt, query_str, NULL, NULL); + SQLITE3_SAFE_FREE(query_str); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while (sqlite3_step(stmt) == SQLITE_ROW) + item_count = (int)sqlite3_column_int(stmt, 0); + + SQLITE3_FINALIZE(stmt); + + media_content_retvm_if(item_count == 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_id"); + + return MEDIA_CONTENT_ERROR_NONE; +} int media_bookmark_insert_to_db(const char *media_id, time_t time, const char *thumbnail_path) { @@ -252,6 +277,9 @@ int media_bookmark_create(const char *media_id, time_t time, media_bookmark_h *b media_content_retvm_if(!STRING_VALID(media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media_id"); media_content_retvm_if(bookmark == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid bookmark"); + ret = __media_bookmark_check_media_id(media_id); + media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Not exist media_id"); + media_bookmark_s *_bookmark = (media_bookmark_s*)calloc(1, sizeof(media_bookmark_s)); media_content_retvm_if(_bookmark == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); diff --git a/src/media_playlist.c b/src/media_playlist.c index e958458..47d8aa4 100755 --- a/src/media_playlist.c +++ b/src/media_playlist.c @@ -954,27 +954,47 @@ int media_playlist_export_to_file(media_playlist_h playlist, const char* path) return ret; } -int media_playlist_create(const char *name, media_playlist_h *playlist) +int media_playlist_create(media_playlist_h *playlist) { int ret = MEDIA_CONTENT_ERROR_NONE; - media_content_retvm_if(!STRING_VALID(name), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid name"); media_content_retvm_if(playlist == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid playlist"); media_playlist_s *_playlist = (media_playlist_s*)calloc(1, sizeof(media_playlist_s)); media_content_retvm_if(_playlist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); _playlist->playlist_id = -1; - _playlist->name = strdup(name); + _playlist->name = NULL; + _playlist->thumbnail_path = NULL; _playlist->item_list = NULL; - if (_playlist->name == NULL) { - SAFE_FREE(_playlist); - media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY); - return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY; + *playlist = (media_playlist_h)_playlist; + + return ret; +} + +int media_playlist_get_play_order_v2(int playlist_id, int playlist_member_id, int *play_order) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + sqlite3_stmt *stmt = NULL; + char select_query[DEFAULT_QUERY_SIZE] = {0, }; + + if ((playlist_id < 0) || (playlist_member_id < 0) || (play_order == NULL)) { + media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER); + return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; } - *playlist = (media_playlist_h)_playlist; + memset(select_query, 0x00, sizeof(select_query)); + + snprintf(select_query, sizeof(select_query), SELECT_PLAY_ORDER_FROM_PLAYLIST_VIEW, playlist_id, playlist_member_id); + + ret = _content_query_prepare(&stmt, select_query, NULL, NULL); + media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret); + + while (sqlite3_step(stmt) == SQLITE_ROW) + *play_order = (int)sqlite3_column_int(stmt, 0); + + SQLITE3_FINALIZE(stmt); return ret; } @@ -990,7 +1010,11 @@ int media_playlist_insert_to_db_v2(media_playlist_h playlist) media_content_retvm_if(_playlist->playlist_id != -1, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid playlist insert"); ret = __media_playlist_insert_playlist_record(_playlist->name, &playlist_id); - media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "Insert playlist Fail"); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + __media_playlist_item_release(_playlist); + media_content_error("Insert playlist Fail"); + return ret; + } _playlist->playlist_id = playlist_id; @@ -998,3 +1022,15 @@ int media_playlist_insert_to_db_v2(media_playlist_h playlist) return ret; } + +int media_playlist_update_to_db_v2(int playlist_id, media_playlist_h playlist) +{ + media_playlist_s *_playlist = (media_playlist_s*)playlist; + + media_content_retvm_if(_playlist == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid playlist"); + media_content_retvm_if(!STRING_VALID(_playlist->name), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid playlist name"); + + _playlist->playlist_id = playlist_id; + + return media_playlist_update_to_db(playlist); +} diff --git a/src/media_tag.c b/src/media_tag.c index 56dfb94..7564963 100755 --- a/src/media_tag.c +++ b/src/media_tag.c @@ -487,3 +487,68 @@ int media_tag_update_to_db(media_tag_h tag) return _content_error_capi(MEDIA_CONTENT_TYPE, ret); } + +int media_tag_create(media_tag_h *tag) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + + media_content_retvm_if(tag == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid tag"); + + media_tag_s *_tag = (media_tag_s*)calloc(1, sizeof(media_tag_s)); + media_content_retvm_if(_tag == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY"); + + _tag->tag_id = -1; + _tag->name = NULL; + _tag->item_list = NULL; + + *tag = (media_tag_h)_tag; + + return ret; +} + +int media_tag_insert_to_db_v2(media_tag_h tag) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_tag_s *_tag = (media_tag_s*)tag; + media_tag_h tag_1; + int tag_id = -1; + + media_content_retvm_if(_tag == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid tag"); + media_content_retvm_if(!STRING_VALID(_tag->name), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid tag name"); + media_content_retvm_if(_tag->tag_id != -1, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid tag insert"); + + ret = media_tag_insert_to_db(_tag->name, &tag_1); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("fail media_tag_insert_to_db"); + goto ERROR; + } + + ret = media_tag_get_tag_id(tag_1, &tag_id); + if (ret != MEDIA_CONTENT_ERROR_NONE) { + media_content_error("fail media_tag_get_tag_id"); + goto ERROR; + } + + _tag->tag_id = tag_id; + + ret = media_tag_update_to_db(tag); + +ERROR: + __media_tag_item_release(_tag); + media_tag_destroy(tag_1); + + return ret; +} + +int media_tag_update_to_db_v2(int tag_id, media_tag_h tag) +{ + media_tag_s *_tag = (media_tag_s*)tag; + + media_content_retvm_if(_tag == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid tag"); + media_content_retvm_if(!STRING_VALID(_tag->name), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid tag name"); + media_content_retvm_if(tag_id == -1, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid tag update"); + + _tag->tag_id = tag_id; + + return media_tag_update_to_db(tag); +} diff --git a/test/media-content_test.c b/test/media-content_test.c index 7baf733..c8493cb 100755 --- a/test/media-content_test.c +++ b/test/media-content_test.c @@ -34,8 +34,8 @@ GMainLoop *g_loop = NULL; static int g_cnt = 0; static int g_media_cnt = 0; -#define test_audio_id "0f999626-6218-450c-a4ad-181a3bab6ebf" -#define test_video_id "22aa5ba1-8b54-4a62-b0e4-d15f7169f7d3" +#define test_audio_id "3304285f-1070-41af-8b4e-f0086cc768f3" +#define test_video_id "53c43e7e-53d2-4194-80a6-55d5dcde0def" #define test_image_id "db1c184c-6f31-43b4-b924-8c00ac5b6197" media_folder_h g_folder = NULL; @@ -1883,13 +1883,18 @@ int test_playlist_operation_v2(void) media_playlist_h playlist_1 = NULL; const char *playlist_name_1 = "myPlaylist_1"; const char *playlist_thumb_path = tzplatform_mkpath(TZ_USER_CONTENT, "Images/Default.jpg"); + int playlist_id = 0; media_content_debug("\n============Playlist Test V2============\n\n"); - ret = media_playlist_create(playlist_name_1, &playlist_1); + ret = media_playlist_create(&playlist_1); if (ret != MEDIA_CONTENT_ERROR_NONE) media_content_error("error media_playlist_create : [%d]", ret); + ret = media_playlist_set_name(playlist_1, playlist_name_1); + if (ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_playlist_set_name : [%d]", ret); + ret = media_playlist_set_thumbnail_path(playlist_1, playlist_thumb_path); if (ret != MEDIA_CONTENT_ERROR_NONE) media_content_error("error media_playlist_set_thumbnail_path : [%d]", ret); @@ -1902,9 +1907,13 @@ int test_playlist_operation_v2(void) if (ret != MEDIA_CONTENT_ERROR_NONE) media_content_error("error media_playlist_set_name : [%d]", ret); - ret = media_playlist_update_to_db(playlist_1); + ret = media_playlist_get_playlist_id(playlist_1, &playlist_id); + if (ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_playlist_get_playlist_id : [%d]", ret); + + ret = media_playlist_update_to_db_v2(playlist_id, playlist_1); if (ret != MEDIA_CONTENT_ERROR_NONE) - media_content_error("error media_playlist_update_to_db : [%d]", ret); + media_content_error("error media_playlist_update_to_db_v2 : [%d]", ret); ret = media_playlist_destroy(playlist_1); if (ret != MEDIA_CONTENT_ERROR_NONE) @@ -2025,7 +2034,7 @@ int test_tag_operation(void) ret = media_tag_add_media(tag_2, test_video_id); if (ret != MEDIA_CONTENT_ERROR_NONE) media_content_error("error media_tag_add_media : [%d]", ret); - ret = media_tag_set_name(tag_2, (char *)"test_tag"); + ret = media_tag_set_name(tag_2, "test_tag"); if (ret != MEDIA_CONTENT_ERROR_NONE) media_content_error("error media_tag_set_name : [%d]", ret); ret = media_tag_update_to_db(tag_2); @@ -2058,6 +2067,57 @@ int test_tag_operation(void) return ret; } +int test_tag_operation_v2(void) +{ + int ret = MEDIA_CONTENT_ERROR_NONE; + media_tag_h tag_1; + const char *tag_name_1 = "myTag_1"; + int tag_id = -1; + + media_content_debug("\n============Tag Test V2============\n\n"); + + /* Create Tag */ + ret = media_tag_create(&tag_1); + if (ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_create : [%d]", ret); + + ret = media_tag_set_name(tag_1, tag_name_1); + if (ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_set_name : [%d]", ret); + + /* Add media to Tag */ + ret = media_tag_add_media(tag_1, test_audio_id); + if (ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_add_media : [%d]", ret); + + ret = media_tag_add_media(tag_1, test_video_id); + if (ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_add_media : [%d]", ret); + + ret = media_tag_insert_to_db_v2(tag_1); + if (ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_insert_to_db_v2 : [%d]", ret); + +#if 1 + ret = media_tag_get_tag_id(tag_1, &tag_id); + if (ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_get_tag_id : [%d]", ret); + + ret = media_tag_remove_media(tag_1, test_video_id); + if (ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_add_media : [%d]", ret); + + ret = media_tag_update_to_db_v2(tag_id, tag_1); + if (ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_update_to_db_v2 : [%d]", ret); +#endif + + ret = media_tag_destroy(tag_1); + if (ret != MEDIA_CONTENT_ERROR_NONE) + media_content_error("error media_tag_destroy : [%d]", ret); + + return ret; +} int test_bookmark_operation(void) { @@ -4075,6 +4135,10 @@ int main(int argc, char *argv[]) ret = test_bookmark_operation_v2(); if (ret != MEDIA_CONTENT_ERROR_NONE) return MEDIA_CONTENT_ERROR_NONE; + + ret = test_tag_operation_v2(); + if (ret != MEDIA_CONTENT_ERROR_NONE) + return MEDIA_CONTENT_ERROR_NONE; #endif ret = test_disconnect_database();