2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include <media_info.h>
18 #include <media-thumbnail.h>
19 #include <media_info_private.h>
20 #include <media_util_private.h>
22 static void __media_info_insert_completed_cb(media_request_result_s *result, void *user_data);
23 static void __media_info_thumbnail_completed_cb(int error, const char *path, void *user_data);
24 static bool __media_info_delete_batch_cb(media_info_h media, void *user_data);
25 static int __media_info_insert_batch(media_batch_insert_e insert_type, const char **path_array, unsigned int array_length, media_insert_completed_cb completed_cb, void *user_data);
27 static int __media_info_get_media_path_by_id_from_db(const char *media_id, char **path)
29 int ret = MEDIA_CONTENT_ERROR_NONE;
30 sqlite3_stmt *stmt = NULL;
31 char *select_query = NULL;
33 media_content_retvm_if(!STRING_VALID(media_id), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media_id");
35 select_query = sqlite3_mprintf(SELECT_MEDIA_PATH_BY_ID, media_id);
37 ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
38 SQLITE3_SAFE_FREE(select_query);
39 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
41 if (sqlite3_step(stmt) == SQLITE_ROW) {
42 *path = g_strdup((const char *)sqlite3_column_text(stmt, 0));
44 media_content_error("There's no media with this ID : %s", media_id);
46 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
49 SQLITE3_FINALIZE(stmt);
54 static void __media_info_insert_completed_cb(media_request_result_s *result, void *user_data)
56 int ret = MEDIA_CONTENT_ERROR_NONE;
57 media_insert_cb_s *_cb_data = (media_insert_cb_s *)user_data;
61 ret = _content_error_capi(MEDIA_CONTENT_TYPE, result->result);
63 if (_cb_data->insert_completed_cb)
64 _cb_data->insert_completed_cb(ret, _cb_data->user_data);
66 if (STRING_VALID(_cb_data->insert_list_path)) {
67 if (unlink(_cb_data->insert_list_path) < 0)
68 media_content_stderror("failed to delete");
69 SAFE_FREE(_cb_data->insert_list_path);
78 static void __media_info_thumbnail_completed_cb(int error, const char *path, void *user_data)
80 int error_value = MEDIA_CONTENT_ERROR_NONE;
82 media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s *)user_data;
83 media_info_s *media = NULL;
85 if (_thumb_cb != NULL) {
86 media = _thumb_cb->handle;
87 if ((media != NULL) && STRING_VALID(path)) {
88 SAFE_FREE(media->thumbnail_path);
89 media->thumbnail_path = strdup(path);
92 media_content_debug("error [%d], thumbnail_path [%s]", error, path);
93 error_value = _content_error_capi(MEDIA_THUMBNAIL_TYPE, error);
94 if (_thumb_cb->thumbnail_completed_cb)
95 _thumb_cb->thumbnail_completed_cb(error_value, path, _thumb_cb->user_data);
103 static bool __media_info_delete_batch_cb(media_info_h media, void *user_data)
105 int err = MEDIA_CONTENT_ERROR_NONE;
106 char *thumb_path = NULL;
107 media_content_type_e media_type = 0;
108 GArray *thumb_list = (GArray *)user_data;
111 media_content_debug("NO Item");
115 err = media_info_get_media_type(media, &media_type);
116 if (err == MEDIA_CONTENT_ERROR_NONE) {
117 media_content_debug("media_type : [%d]", media_type);
119 media_info_get_thumbnail_path(media, &thumb_path);
120 if (STRING_VALID(thumb_path) && STRING_VALID(MEDIA_CONTENT_THUMB_DEFAULT_PATH)) {
121 if (strncmp(MEDIA_CONTENT_THUMB_DEFAULT_PATH, thumb_path, strlen(MEDIA_CONTENT_THUMB_DEFAULT_PATH)) != 0)
122 g_array_append_val(thumb_list, thumb_path);
125 media_content_error("media_info_get_media_type failed");
131 static int __media_info_insert_batch(media_batch_insert_e insert_type, const char **path_array,
132 unsigned int array_length,
133 media_insert_completed_cb completed_cb,
136 int ret = MEDIA_CONTENT_ERROR_NONE;
138 char list_path[255] = {0, };
139 unsigned int idx = 0;
142 for (idx = 0; idx < BATCH_REQUEST_MAX; idx++) {
143 snprintf(list_path, sizeof(list_path), "%s/request-%ld-%d", MEDIA_CONTENT_INSERT_FILES_PATH, media_content_gettid(), idx);
145 if (g_file_test(list_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
146 memset(list_path, 0x00, sizeof(list_path));
149 media_content_debug("The request file list path : %s", list_path);
154 if (idx == BATCH_REQUEST_MAX) {
155 media_content_error("Too many batch request for one thread");
156 return MEDIA_CONTENT_ERROR_DB_BUSY;
159 fp = fopen(list_path, "w");
161 media_content_error("failed to open file : [%s]", list_path);
162 media_content_stderror("failed to open file");
163 return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
166 for (idx = 0; idx < array_length; idx++) {
167 if (STRING_VALID(path_array[idx])) {
168 int size = strlen(path_array[idx]);
170 ret = _media_util_check_file_exist(path_array[idx]);
171 if (ret != MEDIA_CONTENT_ERROR_NONE) {
173 if (unlink(list_path) < 0)
174 media_content_stderror("failed to delete");
178 nwrites = fwrite(path_array[idx], 1, size, fp);
179 if (nwrites != size) {
180 media_content_stderror("failed to write");
182 if (unlink(list_path) < 0)
183 media_content_stderror("failed to delete");
184 return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
187 nwrites = fwrite("\n", 1, 1, fp);
189 media_content_stderror("failed to write");
191 if (unlink(list_path) < 0)
192 media_content_stderror("failed to delete");
193 return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
196 media_content_error("path[%d] is invalid string", idx);
202 media_insert_cb_s *_cb_data = (media_insert_cb_s *)calloc(1, sizeof(media_insert_cb_s));
203 media_content_retvm_if(_cb_data == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
205 _cb_data->insert_completed_cb = completed_cb;
206 _cb_data->user_data = user_data;
207 _cb_data->insert_list_path = g_strdup(list_path);
209 if (insert_type == MEDIA_BATCH_INSERT_NORMAL)
210 ret = media_files_register(list_path, __media_info_insert_completed_cb, _cb_data, tzplatform_getuid(TZ_USER_NAME));
211 else if (insert_type == MEDIA_BATCH_INSERT_BURSTSHOT)
212 ret = media_burstshot_register(list_path, __media_info_insert_completed_cb, _cb_data, tzplatform_getuid(TZ_USER_NAME));
214 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
216 if (ret != MEDIA_CONTENT_ERROR_NONE) {
217 media_content_error("media_files_register failed : %d", ret);
218 if (unlink(list_path) < 0)
219 media_content_stderror("failed to delete");
220 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
226 void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media)
228 media_info_s *_media = (media_info_s*)media;
230 _media->media_id = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_UUID));
231 _media->file_path = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_PATH));
232 _media->display_name = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_FILE_NAME));
233 _media->media_type = (int)sqlite3_column_int(stmt, MEDIA_INFO_TYPE);
234 _media->mime_type = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_MIME_TYPE));
235 _media->size = (unsigned long long)sqlite3_column_int64(stmt, MEDIA_INFO_SIZE);
236 _media->added_time = (int)sqlite3_column_int(stmt, MEDIA_INFO_ADDED_TIME);
237 _media->modified_time = (int)sqlite3_column_int(stmt, MEDIA_INFO_MODIFIED_TIME);
238 _media->thumbnail_path = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_THUMBNAIL_PATH));
239 _media->description = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_DESCRIPTION));
240 _media->rating = (int)sqlite3_column_int(stmt, MEDIA_INFO_RATING);
241 _media->favourite = (int)sqlite3_column_int(stmt, MEDIA_INFO_FAVOURITE);
242 _media->author = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_AUTHOR));
243 _media->provider = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_PROVIDER));
244 _media->content_name = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_CONTENT_NAME));
245 _media->category = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_CATEGORY));
246 _media->location_tag = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_LOCATION_TAG));
247 _media->age_rating = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_AGE_RATING));
248 _media->keyword = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_KEYWORD));
249 _media->is_drm = (int)sqlite3_column_int(stmt, MEDIA_INFO_IS_DRM);
250 _media->storage_type = (int)sqlite3_column_int(stmt, MEDIA_INFO_STORAGE_TYPE);
251 _media->longitude = (double)sqlite3_column_double(stmt, MEDIA_INFO_LONGITUDE);
252 _media->latitude = (double)sqlite3_column_double(stmt, MEDIA_INFO_LATITUDE);
253 _media->altitude = (double)sqlite3_column_double(stmt, MEDIA_INFO_ALTITUDE);
254 _media->played_count = sqlite3_column_int(stmt, MEDIA_INFO_PLAYED_COUNT);
255 _media->played_time = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_TIME);
256 _media->played_position = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_POSITION);
257 _media->title = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE));
258 _media->timeline = (double)sqlite3_column_double(stmt, MEDIA_INFO_TIMELINE);
259 _media->weather = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_WEATHER));
260 _media->sync_status = (int)sqlite3_column_int(stmt, MEDIA_INFO_SYNC_STATUS);
261 _media->storage_uuid = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_STORAGE_UUID));
263 if (_media->media_type == MEDIA_CONTENT_TYPE_IMAGE) {
264 _media->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
265 if (_media->image_meta) {
266 _media->image_meta->media_id = g_strdup(_media->media_id);
267 _media->image_meta->width = sqlite3_column_int(stmt, MEDIA_INFO_WIDTH);
268 _media->image_meta->height = sqlite3_column_int(stmt, MEDIA_INFO_HEIGHT);
269 _media->image_meta->fnumber = (double)sqlite3_column_double(stmt, MEDIA_INFO_FNUMBER);
270 _media->image_meta->iso = sqlite3_column_int(stmt, MEDIA_INFO_ISO);
271 _media->image_meta->date_taken = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_DATETAKEN));
272 _media->image_meta->orientation = sqlite3_column_int(stmt, MEDIA_INFO_ORIENTATION);
273 _media->image_meta->title = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE));
274 _media->image_meta->burst_id = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_BURST_ID));
275 _media->image_meta->weather = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_WEATHER));
276 _media->image_meta->exposure_time = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_EXPOSURE_TIME));
277 _media->image_meta->model = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_MODEL));
279 } else if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
280 _media->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
281 if (_media->video_meta) {
282 _media->video_meta->media_id = g_strdup(_media->media_id);
283 _media->video_meta->width = sqlite3_column_int(stmt, MEDIA_INFO_WIDTH);
284 _media->video_meta->height = sqlite3_column_int(stmt, MEDIA_INFO_HEIGHT);
285 _media->video_meta->title = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE));
286 _media->video_meta->album = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM));
287 _media->video_meta->artist = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ARTIST));
288 _media->video_meta->album_artist = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM_ARTIST));
289 _media->video_meta->genre = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_GENRE));
290 _media->video_meta->composer = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COMPOSER));
291 _media->video_meta->year = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_YEAR));
292 _media->video_meta->recorded_date = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_RECORDED_DATE));
293 _media->video_meta->copyright = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COPYRIGHT));
294 _media->video_meta->track_num = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TRACK_NUM));
295 _media->video_meta->bitrate = sqlite3_column_int(stmt, MEDIA_INFO_BITRATE);
296 _media->video_meta->duration = sqlite3_column_int(stmt, MEDIA_INFO_DURATION);
297 _media->video_meta->played_count = sqlite3_column_int(stmt, MEDIA_INFO_PLAYED_COUNT);
298 _media->video_meta->played_time = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_TIME);
299 _media->video_meta->played_position = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_POSITION);
302 } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
303 _media->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
304 if (_media->audio_meta) {
305 _media->audio_meta->media_id = g_strdup(_media->media_id);
306 _media->audio_meta->title = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE));
307 _media->audio_meta->album = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM));
308 _media->audio_meta->artist = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ARTIST));
309 _media->audio_meta->album_artist = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM_ARTIST));
310 _media->audio_meta->genre = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_GENRE));
311 _media->audio_meta->composer = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COMPOSER));
312 _media->audio_meta->year = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_YEAR));
313 _media->audio_meta->recorded_date = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_RECORDED_DATE));
314 _media->audio_meta->copyright = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COPYRIGHT));
315 _media->audio_meta->track_num = g_strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TRACK_NUM));
316 _media->audio_meta->bitrate = sqlite3_column_int(stmt, MEDIA_INFO_BITRATE);
317 _media->audio_meta->bitpersample = sqlite3_column_int(stmt, MEDIA_INFO_BITPERSAMPLE);
318 _media->audio_meta->duration = sqlite3_column_int(stmt, MEDIA_INFO_DURATION);
319 _media->audio_meta->played_count = sqlite3_column_int(stmt, MEDIA_INFO_PLAYED_COUNT);
320 _media->audio_meta->played_time = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_TIME);
321 _media->audio_meta->played_position = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_POSITION);
322 _media->audio_meta->samplerate = sqlite3_column_int(stmt, MEDIA_INFO_SAMPLERATE);
323 _media->audio_meta->channel = sqlite3_column_int(stmt, MEDIA_INFO_CHANNEL);
328 int _media_info_get_media_info_from_db(const char *path, const char *storage_id, media_info_h media)
330 int ret = MEDIA_CONTENT_ERROR_NONE;
331 sqlite3_stmt *stmt = NULL;
332 char *select_query = NULL;
333 media_info_s *_media = (media_info_s*)media;
335 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media");
337 select_query = sqlite3_mprintf(SELECT_MEDIA_BY_PATH, storage_id, path);
339 ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
340 SQLITE3_SAFE_FREE(select_query);
341 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
343 if (sqlite3_step(stmt) == SQLITE_ROW) {
344 _media_info_item_get_detail(stmt, (media_info_h)_media);
346 media_content_error("There's no media!!");
347 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
350 SQLITE3_FINALIZE(stmt);
355 int media_info_insert_to_db(const char *path, media_info_h *info)
357 bool ignore_file = FALSE;
358 bool ignore_dir = FALSE;
359 char *folder_path = NULL;
360 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
361 int ret = MEDIA_CONTENT_ERROR_NONE;
363 media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
364 media_content_retvm_if(info == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid info");
366 ret = _media_util_check_ignore_file(path, &ignore_file);
367 media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
369 ret = _media_util_check_file_exist(path);
370 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
372 folder_path = g_path_get_dirname(path);
373 ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
374 SAFE_FREE(folder_path);
376 media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
378 memset(storage_id, 0x00, sizeof(storage_id));
379 ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id);
380 if (ret != MS_MEDIA_ERR_NONE) {
381 media_content_error("media_svc_get_storage_id failed : %d", ret);
382 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
385 ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), storage_id, path);
386 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
387 media_content_sec_debug("media_svc_check_item_exist_by_path : no record : %s", path);
389 media_svc_storage_type_e storage_type = 0;
391 ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
392 if (ret != MS_MEDIA_ERR_NONE) {
393 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
394 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
397 ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, storage_type, path, tzplatform_getuid(TZ_USER_NAME));
399 if (ret != MS_MEDIA_ERR_NONE) {
400 if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
401 media_content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", path);
402 ret = MEDIA_CONTENT_ERROR_NONE;
404 media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, path);
407 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
409 } else if (ret != MS_MEDIA_ERR_NONE) {
410 media_content_sec_error("media_svc_check_item_exist_by_path failed : %d (%s)", ret, path);
411 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
414 media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s));
415 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
417 ret = _media_info_get_media_info_from_db(path, DEFAULT_MEDIA_STORAGE_ID, (media_info_h)_media);
419 *info = (media_info_h)_media;
423 int media_info_insert_batch_to_db(
424 const char **path_array,
425 unsigned int array_length,
426 media_insert_completed_cb completed_cb,
429 media_content_retvm_if(path_array == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path_array");
430 media_content_retvm_if(array_length <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid array_length");
432 return __media_info_insert_batch(MEDIA_BATCH_INSERT_NORMAL, path_array, array_length, completed_cb, user_data);
435 int media_info_insert_burst_shot_to_db(const char **path_array, unsigned int array_length, media_insert_burst_shot_completed_cb callback, void *user_data)
437 media_content_retvm_if(path_array == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path_array");
438 media_content_retvm_if(array_length <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid array_length");
440 return __media_info_insert_batch(MEDIA_BATCH_INSERT_BURSTSHOT, path_array, array_length, callback, user_data);
443 int media_info_delete_from_db(const char *media_id)
445 int ret = MEDIA_CONTENT_ERROR_NONE;
447 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
449 if (!STRING_VALID(media_id)) {
450 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
451 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
454 memset(storage_id, 0x00, sizeof(storage_id));
456 ret = __media_info_get_media_path_by_id_from_db(media_id, &path);
457 if (ret != MEDIA_CONTENT_ERROR_NONE) {
458 media_content_error("__media_info_get_media_path_by_id_from_db failed : %d", ret);
463 ret = _media_db_get_storage_id_by_media_id(media_id, storage_id);
464 if (ret != MEDIA_CONTENT_ERROR_NONE) {
465 media_content_error("_media_db_get_storage_id_by_media_id failed : %d", ret);
470 ret = media_svc_delete_item_by_path(_content_get_db_handle(), storage_id, path, tzplatform_getuid(TZ_USER_NAME));
473 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
476 static int __media_info_delete_thumb_from_list(GArray *thumb_list)
480 char *thumb_path = NULL;
482 if (thumb_list != NULL) {
483 list_len = thumb_list->len;
484 for (i = 0; i < list_len; i++) {
485 thumb_path = g_array_index(thumb_list, char*, i);
486 media_content_debug("thumb path [%s]", thumb_path);
487 if (unlink(thumb_path) < 0)
488 media_content_stderror("failed to delete");
491 return MEDIA_CONTENT_ERROR_NONE;
494 static int __media_info_release_thumb_list(GArray *thumb_list)
498 char *thumb_path = NULL;
500 if (thumb_list != NULL) {
501 list_len = thumb_list->len;
502 for (i = 0; i < list_len; i++) {
503 thumb_path = g_array_index(thumb_list, char*, 0);
504 g_array_remove_index(thumb_list, 0);
505 SAFE_FREE(thumb_path);
508 g_array_free(thumb_list, FALSE);
511 return MEDIA_CONTENT_ERROR_NONE;
514 int media_info_delete_batch_from_db(filter_h filter)
516 int ret = MEDIA_CONTENT_ERROR_NONE;
518 char *query_string = NULL;
519 filter_s *_filter = NULL;
521 char *condition_query = NULL;
522 GArray *thumb_list = NULL;
524 media_content_retvm_if(filter == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid filter");
526 thumb_list = g_array_new(FALSE, FALSE, sizeof(char*));
528 /* Delete thumbnail of each item */
529 ret = _media_db_get_group_item(NULL, filter, __media_info_delete_batch_cb, thumb_list, MEDIA_GROUP_NONE);
531 _filter = (filter_s*)filter;
532 attr = _content_get_attirbute_handle();
534 if (_filter->condition) {
535 ret = _media_filter_attribute_generate(attr, _filter->condition, _filter->condition_collate_type, &condition_query);
536 if (ret != MEDIA_CONTENT_ERROR_NONE) {
537 __media_info_release_thumb_list(thumb_list);
542 if (STRING_VALID(condition_query)) {
543 if (_filter->storage_id == NULL) {
545 query_string = sqlite3_mprintf(DELETE_MEDIA_FROM_MEDIA_BATCH, "media", condition_query);
547 query_string = sqlite3_mprintf(DELETE_MEDIA_FROM_MEDIA_BATCH, _filter->storage_id, condition_query);
550 SAFE_FREE(condition_query);
551 __media_info_release_thumb_list(thumb_list);
553 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
556 ret = _content_query_sql(query_string);
557 if (ret == MEDIA_CONTENT_ERROR_NONE) {
558 /* Send notification for this
559 In this case, send noti for internal storage and external storage
561 media_content_debug("Batch deletion is successfull. Send notification for this");
562 if (_filter->storage_id != NULL) {
563 char *storage_path = NULL;
564 media_svc_get_storage_path(_content_get_db_handle(), _filter->storage_id, &storage_path);
565 if (STRING_VALID(storage_path))
566 media_svc_publish_noti(_content_get_db_handle(), MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, storage_path, -1, NULL, NULL);
568 SAFE_FREE(storage_path);
571 media_svc_publish_noti(_content_get_db_handle(), MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, MEDIA_ROOT_PATH_INTERNAL, -1, NULL, NULL);
572 media_svc_publish_noti(_content_get_db_handle(), MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, MEDIA_ROOT_PATH_SDCARD, -1, NULL, NULL);
575 __media_info_delete_thumb_from_list(thumb_list);
576 __media_info_release_thumb_list(thumb_list);
579 SAFE_FREE(condition_query);
580 SQLITE3_SAFE_FREE(query_string);
585 int media_info_destroy(media_info_h media)
587 int ret = MEDIA_CONTENT_ERROR_NONE;
588 media_info_s *_media = (media_info_s*)media;
591 SAFE_FREE(_media->media_id);
592 SAFE_FREE(_media->file_path);
593 SAFE_FREE(_media->display_name);
594 SAFE_FREE(_media->mime_type);
595 SAFE_FREE(_media->thumbnail_path);
596 SAFE_FREE(_media->description);
597 SAFE_FREE(_media->author);
598 SAFE_FREE(_media->provider);
599 SAFE_FREE(_media->content_name);
600 SAFE_FREE(_media->category);
601 SAFE_FREE(_media->location_tag);
602 SAFE_FREE(_media->age_rating);
603 SAFE_FREE(_media->keyword);
604 SAFE_FREE(_media->title);
605 SAFE_FREE(_media->weather);
606 SAFE_FREE(_media->storage_uuid);
608 if (_media->image_meta) {
609 SAFE_FREE(_media->image_meta->media_id);
610 SAFE_FREE(_media->image_meta->date_taken);
611 SAFE_FREE(_media->image_meta->burst_id);
612 SAFE_FREE(_media->image_meta->exposure_time);
613 SAFE_FREE(_media->image_meta->model);
614 SAFE_FREE(_media->image_meta->title);
615 SAFE_FREE(_media->image_meta->weather);
617 SAFE_FREE(_media->image_meta);
620 if (_media->video_meta) {
621 SAFE_FREE(_media->video_meta->media_id);
622 SAFE_FREE(_media->video_meta->title);
623 SAFE_FREE(_media->video_meta->album);
624 SAFE_FREE(_media->video_meta->artist);
625 SAFE_FREE(_media->video_meta->album_artist);
626 SAFE_FREE(_media->video_meta->genre);
627 SAFE_FREE(_media->video_meta->composer);
628 SAFE_FREE(_media->video_meta->year);
629 SAFE_FREE(_media->video_meta->recorded_date);
630 SAFE_FREE(_media->video_meta->copyright);
631 SAFE_FREE(_media->video_meta->track_num);
633 SAFE_FREE(_media->video_meta);
636 if (_media->audio_meta) {
637 SAFE_FREE(_media->audio_meta->media_id);
638 SAFE_FREE(_media->audio_meta->title);
639 SAFE_FREE(_media->audio_meta->album);
640 SAFE_FREE(_media->audio_meta->artist);
641 SAFE_FREE(_media->audio_meta->album_artist);
642 SAFE_FREE(_media->audio_meta->genre);
643 SAFE_FREE(_media->audio_meta->composer);
644 SAFE_FREE(_media->audio_meta->year);
645 SAFE_FREE(_media->audio_meta->recorded_date);
646 SAFE_FREE(_media->audio_meta->copyright);
647 SAFE_FREE(_media->audio_meta->track_num);
649 SAFE_FREE(_media->audio_meta);
654 ret = MEDIA_CONTENT_ERROR_NONE;
656 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
657 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
663 int media_info_clone(media_info_h *dst, media_info_h src)
665 int ret = MEDIA_CONTENT_ERROR_NONE;
666 media_info_s *_src = (media_info_s*)src;
669 media_info_s *_dst = (media_info_s*)calloc(1, sizeof(media_info_s));
670 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
672 if (STRING_VALID(_src->media_id)) {
673 _dst->media_id = strdup(_src->media_id);
674 if (_dst->media_id == NULL) {
675 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
676 media_info_destroy((media_info_h)_dst);
677 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
680 if (STRING_VALID(_src->file_path)) {
681 _dst->file_path = strdup(_src->file_path);
682 if (_dst->file_path == NULL) {
683 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
684 media_info_destroy((media_info_h)_dst);
685 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
688 if (STRING_VALID(_src->display_name)) {
689 _dst->display_name = strdup(_src->display_name);
690 if (_dst->display_name == NULL) {
691 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
692 media_info_destroy((media_info_h)_dst);
693 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
696 if (STRING_VALID(_src->mime_type)) {
697 _dst->mime_type = strdup(_src->mime_type);
698 if (_dst->mime_type == NULL) {
699 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
700 media_info_destroy((media_info_h)_dst);
701 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
704 if (STRING_VALID(_src->thumbnail_path)) {
705 _dst->thumbnail_path = strdup(_src->thumbnail_path);
706 if (_dst->thumbnail_path == NULL) {
707 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
708 media_info_destroy((media_info_h)_dst);
709 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
712 if (STRING_VALID(_src->description)) {
713 _dst->description = strdup(_src->description);
714 if (_dst->description == NULL) {
715 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
716 media_info_destroy((media_info_h)_dst);
717 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
721 if (STRING_VALID(_src->weather)) {
722 _dst->weather = strdup(_src->weather);
723 if (_dst->weather == NULL) {
724 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
725 media_info_destroy((media_info_h)_dst);
726 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
730 if (STRING_VALID(_src->title)) {
731 _dst->title = strdup(_src->title);
732 if (_dst->title == NULL) {
733 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
734 media_info_destroy((media_info_h)_dst);
735 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
738 if (STRING_VALID(_src->author)) {
739 _dst->author = strdup(_src->author);
740 if (_dst->author == NULL) {
741 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
742 media_info_destroy((media_info_h)_dst);
743 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
746 if (STRING_VALID(_src->provider)) {
747 _dst->provider = strdup(_src->provider);
748 if (_dst->provider == NULL) {
749 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
750 media_info_destroy((media_info_h)_dst);
751 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
754 if (STRING_VALID(_src->content_name)) {
755 _dst->content_name = strdup(_src->content_name);
756 if (_dst->content_name == NULL) {
757 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
758 media_info_destroy((media_info_h)_dst);
759 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
762 if (STRING_VALID(_src->category)) {
763 _dst->category = strdup(_src->category);
764 if (_dst->category == NULL) {
765 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
766 media_info_destroy((media_info_h)_dst);
767 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
770 if (STRING_VALID(_src->location_tag)) {
771 _dst->location_tag = strdup(_src->location_tag);
772 if (_dst->location_tag == NULL) {
773 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
774 media_info_destroy((media_info_h)_dst);
775 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
778 if (STRING_VALID(_src->age_rating)) {
779 _dst->age_rating = strdup(_src->age_rating);
780 if (_dst->age_rating == NULL) {
781 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
782 media_info_destroy((media_info_h)_dst);
783 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
786 if (STRING_VALID(_src->keyword)) {
787 _dst->keyword = strdup(_src->keyword);
788 if (_dst->keyword == NULL) {
789 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
790 media_info_destroy((media_info_h)_dst);
791 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
795 if (STRING_VALID(_src->storage_uuid)) {
796 _dst->storage_uuid = strdup(_src->storage_uuid);
797 if (_dst->storage_uuid == NULL) {
798 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
799 media_info_destroy((media_info_h)_dst);
800 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
804 _dst->media_type = _src->media_type;
805 _dst->size = _src->size;
806 _dst->added_time = _src->added_time;
807 _dst->modified_time = _src->modified_time;
808 _dst->timeline = _src->timeline;
809 _dst->longitude = _src->longitude;
810 _dst->latitude = _src->latitude;
811 _dst->altitude = _src->altitude;
812 _dst->rating = _src->rating;
813 _dst->favourite = _src->favourite;
814 _dst->is_drm = _src->is_drm;
815 _dst->storage_type = _src->storage_type;
816 _dst->played_count = _src->played_count;
817 _dst->played_time = _src->played_time;
818 _dst->played_position = _src->played_position;
819 _dst->sync_status = _src->sync_status;
821 if (_src->media_type == MEDIA_CONTENT_TYPE_IMAGE && _src->image_meta) {
822 _dst->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
823 if (_dst->image_meta == NULL) {
824 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
825 media_info_destroy((media_info_h)_dst);
826 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
829 if (STRING_VALID(_src->image_meta->media_id)) {
830 _dst->image_meta->media_id = strdup(_src->image_meta->media_id);
831 if (_dst->image_meta->media_id == NULL) {
832 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
833 media_info_destroy((media_info_h)_dst);
834 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
838 if (STRING_VALID(_src->image_meta->date_taken)) {
839 _dst->image_meta->date_taken = strdup(_src->image_meta->date_taken);
840 if (_dst->image_meta->date_taken == NULL) {
841 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
842 media_info_destroy((media_info_h)_dst);
843 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
847 if (STRING_VALID(_src->image_meta->burst_id)) {
848 _dst->image_meta->burst_id = strdup(_src->image_meta->burst_id);
849 if (_dst->image_meta->burst_id == NULL) {
850 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
851 media_info_destroy((media_info_h)_dst);
852 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
856 if (STRING_VALID(_src->image_meta->weather)) {
857 _dst->image_meta->weather = strdup(_src->image_meta->weather);
858 if (_dst->image_meta->weather == NULL) {
859 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
860 media_info_destroy((media_info_h)_dst);
861 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
865 if (STRING_VALID(_src->image_meta->exposure_time)) {
866 _dst->image_meta->exposure_time = strdup(_src->image_meta->exposure_time);
867 if (_dst->image_meta->exposure_time == NULL) {
868 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
869 media_info_destroy((media_info_h)_dst);
870 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
874 if (STRING_VALID(_src->image_meta->model)) {
875 _dst->image_meta->model = strdup(_src->image_meta->model);
876 if (_dst->image_meta->model == NULL) {
877 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
878 media_info_destroy((media_info_h)_dst);
879 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
883 _dst->image_meta->fnumber = _src->image_meta->fnumber;
884 _dst->image_meta->iso = _src->image_meta->iso;
885 _dst->image_meta->width = _src->image_meta->width;
886 _dst->image_meta->height = _src->image_meta->height;
887 _dst->image_meta->orientation = _src->image_meta->orientation;
889 } else if (_src->media_type == MEDIA_CONTENT_TYPE_VIDEO && _src->video_meta) {
890 _dst->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
891 if (_dst->video_meta == NULL) {
892 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
893 media_info_destroy((media_info_h)_dst);
894 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
897 if (STRING_VALID(_src->video_meta->media_id)) {
898 _dst->video_meta->media_id = strdup(_src->video_meta->media_id);
899 if (_dst->video_meta->media_id == NULL) {
900 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
901 media_info_destroy((media_info_h)_dst);
902 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
905 if (STRING_VALID(_src->video_meta->title)) {
906 _dst->video_meta->title = strdup(_src->video_meta->title);
907 if (_dst->video_meta->title == NULL) {
908 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
909 media_info_destroy((media_info_h)_dst);
910 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
913 if (STRING_VALID(_src->video_meta->album)) {
914 _dst->video_meta->album = strdup(_src->video_meta->album);
915 if (_dst->video_meta->album == NULL) {
916 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
917 media_info_destroy((media_info_h)_dst);
918 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
921 if (STRING_VALID(_src->video_meta->artist)) {
922 _dst->video_meta->artist = strdup(_src->video_meta->artist);
923 if (_dst->video_meta->artist == NULL) {
924 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
925 media_info_destroy((media_info_h)_dst);
926 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
929 if (STRING_VALID(_src->video_meta->album_artist)) {
930 _dst->video_meta->album_artist = strdup(_src->video_meta->album_artist);
931 if (_dst->video_meta->album_artist == NULL) {
932 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
933 media_info_destroy((media_info_h)_dst);
934 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
937 if (STRING_VALID(_src->video_meta->genre)) {
938 _dst->video_meta->genre = strdup(_src->video_meta->genre);
939 if (_dst->video_meta->genre == NULL) {
940 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
941 media_info_destroy((media_info_h)_dst);
942 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
945 if (STRING_VALID(_src->video_meta->composer)) {
946 _dst->video_meta->composer = strdup(_src->video_meta->composer);
947 if (_dst->video_meta->composer == NULL) {
948 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
949 media_info_destroy((media_info_h)_dst);
950 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
953 if (STRING_VALID(_src->video_meta->year)) {
954 _dst->video_meta->year = strdup(_src->video_meta->year);
955 if (_dst->video_meta->year == NULL) {
956 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
957 media_info_destroy((media_info_h)_dst);
958 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
961 if (STRING_VALID(_src->video_meta->recorded_date)) {
962 _dst->video_meta->recorded_date = strdup(_src->video_meta->recorded_date);
963 if (_dst->video_meta->recorded_date == NULL) {
964 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
965 media_info_destroy((media_info_h)_dst);
966 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
969 if (STRING_VALID(_src->video_meta->copyright)) {
970 _dst->video_meta->copyright = strdup(_src->video_meta->copyright);
971 if (_dst->video_meta->copyright == NULL) {
972 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
973 media_info_destroy((media_info_h)_dst);
974 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
977 if (STRING_VALID(_src->video_meta->track_num)) {
978 _dst->video_meta->track_num = strdup(_src->video_meta->track_num);
979 if (_dst->video_meta->track_num == NULL) {
980 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
981 media_info_destroy((media_info_h)_dst);
982 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
986 _dst->video_meta->width = _src->video_meta->width;
987 _dst->video_meta->height = _src->video_meta->height;
988 _dst->video_meta->duration = _src->video_meta->duration;
989 _dst->video_meta->bitrate = _src->video_meta->bitrate;
990 _dst->video_meta->played_count = _src->video_meta->played_count;
991 _dst->video_meta->played_time = _src->video_meta->played_time;
992 _dst->video_meta->played_position = _src->video_meta->played_position;
994 } else if ((_src->media_type == MEDIA_CONTENT_TYPE_MUSIC || _src->media_type == MEDIA_CONTENT_TYPE_SOUND) && _src->audio_meta) {
995 _dst->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
996 if (_dst->audio_meta == NULL) {
997 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
998 media_info_destroy((media_info_h)_dst);
999 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1002 if (STRING_VALID(_src->audio_meta->media_id)) {
1003 _dst->audio_meta->media_id = strdup(_src->audio_meta->media_id);
1004 if (_dst->audio_meta->media_id == NULL) {
1005 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1006 media_info_destroy((media_info_h)_dst);
1007 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1010 if (STRING_VALID(_src->audio_meta->title)) {
1011 _dst->audio_meta->title = strdup(_src->audio_meta->title);
1012 if (_dst->audio_meta->title == NULL) {
1013 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1014 media_info_destroy((media_info_h)_dst);
1015 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1018 if (STRING_VALID(_src->audio_meta->album)) {
1019 _dst->audio_meta->album = strdup(_src->audio_meta->album);
1020 if (_dst->audio_meta->album == NULL) {
1021 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1022 media_info_destroy((media_info_h)_dst);
1023 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1026 if (STRING_VALID(_src->audio_meta->artist)) {
1027 _dst->audio_meta->artist = strdup(_src->audio_meta->artist);
1028 if (_dst->audio_meta->artist == NULL) {
1029 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1030 media_info_destroy((media_info_h)_dst);
1031 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1034 if (STRING_VALID(_src->audio_meta->album_artist)) {
1035 _dst->audio_meta->album_artist = strdup(_src->audio_meta->album_artist);
1036 if (_dst->audio_meta->album_artist == NULL) {
1037 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1038 media_info_destroy((media_info_h)_dst);
1039 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1042 if (STRING_VALID(_src->audio_meta->genre)) {
1043 _dst->audio_meta->genre = strdup(_src->audio_meta->genre);
1044 if (_dst->audio_meta->genre == NULL) {
1045 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1046 media_info_destroy((media_info_h)_dst);
1047 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1050 if (STRING_VALID(_src->audio_meta->composer)) {
1051 _dst->audio_meta->composer = strdup(_src->audio_meta->composer);
1052 if (_dst->audio_meta->composer == NULL) {
1053 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1054 media_info_destroy((media_info_h)_dst);
1055 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1058 if (STRING_VALID(_src->audio_meta->year)) {
1059 _dst->audio_meta->year = strdup(_src->audio_meta->year);
1060 if (_dst->audio_meta->year == NULL) {
1061 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1062 media_info_destroy((media_info_h)_dst);
1063 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1066 if (STRING_VALID(_src->audio_meta->recorded_date)) {
1067 _dst->audio_meta->recorded_date = strdup(_src->audio_meta->recorded_date);
1068 if (_dst->audio_meta->recorded_date == NULL) {
1069 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1070 media_info_destroy((media_info_h)_dst);
1071 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1074 if (STRING_VALID(_src->audio_meta->copyright)) {
1075 _dst->audio_meta->copyright = strdup(_src->audio_meta->copyright);
1076 if (_dst->audio_meta->copyright == NULL) {
1077 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1078 media_info_destroy((media_info_h)_dst);
1079 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1082 if (STRING_VALID(_src->audio_meta->track_num)) {
1083 _dst->audio_meta->track_num = strdup(_src->audio_meta->track_num);
1084 if (_dst->audio_meta->track_num == NULL) {
1085 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1086 media_info_destroy((media_info_h)_dst);
1087 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1091 _dst->audio_meta->channel = _src->audio_meta->channel;
1092 _dst->audio_meta->samplerate = _src->audio_meta->samplerate;
1093 _dst->audio_meta->duration = _src->audio_meta->duration;
1094 _dst->audio_meta->bitrate = _src->audio_meta->bitrate;
1095 _dst->audio_meta->bitpersample = _src->audio_meta->bitpersample;
1096 _dst->audio_meta->played_count = _src->audio_meta->played_count;
1097 _dst->audio_meta->played_time = _src->audio_meta->played_time;
1098 _dst->audio_meta->played_position = _src->audio_meta->played_position;
1101 *dst = (media_info_h)_dst;
1103 ret = MEDIA_CONTENT_ERROR_NONE;
1105 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1106 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1112 int media_info_get_media_count_from_db(filter_h filter, int *media_count)
1114 int ret = MEDIA_CONTENT_ERROR_NONE;
1116 if (media_count == NULL) {
1117 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1118 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1123 ret = _media_db_get_group_item_count(NULL, filter, MEDIA_GROUP_NONE, media_count);
1128 int media_info_foreach_media_from_db(filter_h filter, media_info_cb callback, void *user_data)
1130 int ret = MEDIA_CONTENT_ERROR_NONE;
1132 media_content_retvm_if(callback == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid callback");
1134 ret = _media_db_get_group_item(NULL, filter, callback, user_data, MEDIA_GROUP_NONE);
1139 int media_info_get_tag_count_from_db(const char *media_id, filter_h filter, int *tag_count)
1141 int ret = MEDIA_CONTENT_ERROR_NONE;
1143 if (STRING_VALID(media_id) && tag_count) {
1144 ret = _media_db_get_group_item_count(media_id, filter, MEDIA_GROUP_TAG_BY_MEDIA_ID, tag_count);
1146 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1147 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1153 int media_info_foreach_tag_from_db(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data)
1155 int ret = MEDIA_CONTENT_ERROR_NONE;
1157 if ((callback != NULL) && STRING_VALID(media_id)) {
1158 ret = _media_db_get_tag(media_id, filter, callback, user_data);
1160 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1161 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1167 int media_info_get_bookmark_count_from_db(const char *media_id, filter_h filter, int *bookmark_count)
1169 int ret = MEDIA_CONTENT_ERROR_NONE;
1171 if (STRING_VALID(media_id) && bookmark_count) {
1172 ret = _media_db_get_group_item_count(media_id, filter, MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID, bookmark_count);
1174 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1175 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1181 int media_info_foreach_bookmark_from_db(const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data)
1183 int ret = MEDIA_CONTENT_ERROR_NONE;
1185 if ((callback != NULL) && STRING_VALID(media_id)) {
1186 ret = _media_db_get_bookmark(media_id, filter, callback, user_data);
1188 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1189 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1195 int media_info_get_face_count_from_db(const char *media_id, filter_h filter, int *face_count)
1197 int ret = MEDIA_CONTENT_ERROR_NONE;
1199 if (STRING_VALID(media_id) && face_count) {
1200 ret = _media_db_get_group_item_count(media_id, filter, MEDIA_GROUP_FACE_BY_MEDIA_ID, face_count);
1202 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1203 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1209 int media_info_foreach_face_from_db(const char *media_id, filter_h filter, media_face_cb callback, void *user_data)
1211 int ret = MEDIA_CONTENT_ERROR_NONE;
1213 if ((callback != NULL) && STRING_VALID(media_id)) {
1214 ret = _media_db_get_face(media_id, filter, callback, user_data);
1216 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1217 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1223 int media_info_get_image(media_info_h media, image_meta_h *image)
1225 int ret = MEDIA_CONTENT_ERROR_NONE;
1227 media_info_s *_media = (media_info_s*)media;
1229 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
1230 media_content_retvm_if(_media->media_type != MEDIA_CONTENT_TYPE_IMAGE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_type");
1231 media_content_retvm_if(_media->image_meta == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid image_meta");
1233 image_meta_s *_image = (image_meta_s*)calloc(1, sizeof(image_meta_s));
1234 media_content_retvm_if(_image == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1236 _image->media_id = g_strdup(_media->media_id);
1237 _image->width = _media->image_meta->width;
1238 _image->height = _media->image_meta->height;
1239 _image->orientation = _media->image_meta->orientation;
1240 _image->fnumber = _media->image_meta->fnumber;
1241 _image->iso = _media->image_meta->iso;
1242 _image->date_taken = g_strdup(_media->image_meta->date_taken);
1243 _image->title = g_strdup(_media->image_meta->title);
1244 _image->burst_id = g_strdup(_media->image_meta->burst_id);
1245 _image->weather = g_strdup(_media->image_meta->weather);
1246 _image->exposure_time = g_strdup(_media->image_meta->exposure_time);
1247 _image->model = g_strdup(_media->image_meta->model);
1249 *image = (image_meta_h)_image;
1254 int media_info_get_video(media_info_h media, video_meta_h *video)
1256 int ret = MEDIA_CONTENT_ERROR_NONE;
1258 media_info_s *_media = (media_info_s*)media;
1260 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
1261 media_content_retvm_if(_media->media_type != MEDIA_CONTENT_TYPE_VIDEO, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_type");
1262 media_content_retvm_if(_media->video_meta == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid video_meta");
1264 video_meta_s *_video = (video_meta_s*)calloc(1, sizeof(video_meta_s));
1265 media_content_retvm_if(_video == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1267 _video->media_id = g_strdup(_media->media_id);
1268 _video->title = g_strdup(_media->video_meta->title);
1269 _video->album = g_strdup(_media->video_meta->album);
1270 _video->artist = g_strdup(_media->video_meta->artist);
1271 _video->album_artist = g_strdup(_media->video_meta->album_artist);
1272 _video->genre = g_strdup(_media->video_meta->genre);
1273 _video->composer = g_strdup(_media->video_meta->composer);
1274 _video->year = g_strdup(_media->video_meta->year);
1275 _video->recorded_date = g_strdup(_media->video_meta->recorded_date);
1276 _video->copyright = g_strdup(_media->video_meta->copyright);
1277 _video->track_num = g_strdup(_media->video_meta->track_num);
1279 _video->width = _media->video_meta->width;
1280 _video->height = _media->video_meta->height;
1281 _video->duration = _media->video_meta->duration;
1282 _video->bitrate = _media->video_meta->bitrate;
1283 _video->played_count = _media->video_meta->played_count;
1284 _video->played_time = _media->video_meta->played_time;
1285 _video->played_position = _media->video_meta->played_position;
1287 *video = (video_meta_h)_video;
1292 int media_info_get_audio(media_info_h media, audio_meta_h *audio)
1294 int ret = MEDIA_CONTENT_ERROR_NONE;
1296 media_info_s *_media = (media_info_s*)media;
1298 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
1299 media_content_retvm_if(_media->media_type != MEDIA_CONTENT_TYPE_MUSIC && _media->media_type != MEDIA_CONTENT_TYPE_SOUND, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_type");
1300 media_content_retvm_if(_media->audio_meta == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid audio_meta");
1302 audio_meta_s *_audio = (audio_meta_s*)calloc(1, sizeof(audio_meta_s));
1303 media_content_retvm_if(_audio == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1305 _audio->media_id = g_strdup(_media->media_id);
1306 _audio->title = g_strdup(_media->audio_meta->title);
1307 _audio->album = g_strdup(_media->audio_meta->album);
1308 _audio->artist = g_strdup(_media->audio_meta->artist);
1309 _audio->album_artist = g_strdup(_media->audio_meta->album_artist);
1310 _audio->genre = g_strdup(_media->audio_meta->genre);
1311 _audio->composer = g_strdup(_media->audio_meta->composer);
1312 _audio->year = g_strdup(_media->audio_meta->year);
1313 _audio->recorded_date = g_strdup(_media->audio_meta->recorded_date);
1314 _audio->copyright = g_strdup(_media->audio_meta->copyright);
1315 _audio->track_num = g_strdup(_media->audio_meta->track_num);
1317 _audio->duration = _media->audio_meta->duration;
1318 _audio->bitrate = _media->audio_meta->bitrate;
1319 _audio->bitpersample = _media->audio_meta->bitpersample;
1320 _audio->samplerate = _media->audio_meta->samplerate;
1321 _audio->channel = _media->audio_meta->channel;
1322 _audio->played_time = _media->audio_meta->played_time;
1323 _audio->played_count = _media->audio_meta->played_count;
1324 _audio->played_position = _media->audio_meta->played_position;
1326 *audio = (audio_meta_h)_audio;
1331 int media_info_get_media_id(media_info_h media, char **media_id)
1333 int ret = MEDIA_CONTENT_ERROR_NONE;
1334 media_info_s *_media = (media_info_s*)media;
1336 if (_media && media_id) {
1337 if (STRING_VALID(_media->media_id)) {
1338 *media_id = strdup(_media->media_id);
1339 media_content_retvm_if(*media_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1343 ret = MEDIA_CONTENT_ERROR_NONE;
1345 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1346 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1352 int media_info_get_file_path(media_info_h media, char **path)
1354 int ret = MEDIA_CONTENT_ERROR_NONE;
1355 media_info_s *_media = (media_info_s*)media;
1357 if (_media && path) {
1358 if (STRING_VALID(_media->file_path)) {
1359 *path = strdup(_media->file_path);
1360 media_content_retvm_if(*path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1364 ret = MEDIA_CONTENT_ERROR_NONE;
1367 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1368 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1374 int media_info_get_display_name(media_info_h media, char **name)
1376 int ret = MEDIA_CONTENT_ERROR_NONE;
1377 media_info_s *_media = (media_info_s*)media;
1378 if (_media && name) {
1379 if (STRING_VALID(_media->display_name)) {
1380 *name = strdup(_media->display_name);
1381 media_content_retvm_if(*name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1385 ret = MEDIA_CONTENT_ERROR_NONE;
1388 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1389 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1395 int media_info_get_media_type(media_info_h media, media_content_type_e *type)
1397 int ret = MEDIA_CONTENT_ERROR_NONE;
1398 media_info_s *_media = (media_info_s*)media;
1399 if (_media && type) {
1400 *type = _media->media_type;
1401 ret = MEDIA_CONTENT_ERROR_NONE;
1403 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1404 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1410 int media_info_get_mime_type(media_info_h media, char **mime_type)
1412 int ret = MEDIA_CONTENT_ERROR_NONE;
1413 media_info_s *_media = (media_info_s*)media;
1415 if (_media && mime_type) {
1416 if (STRING_VALID(_media->mime_type)) {
1417 *mime_type = strdup(_media->mime_type);
1418 media_content_retvm_if(*mime_type == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1422 ret = MEDIA_CONTENT_ERROR_NONE;
1424 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1425 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1431 int media_info_get_size(media_info_h media, unsigned long long *size)
1433 int ret = MEDIA_CONTENT_ERROR_NONE;
1434 media_info_s *_media = (media_info_s*)media;
1436 if (_media && size) {
1437 *size = _media->size;
1438 ret = MEDIA_CONTENT_ERROR_NONE;
1440 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1441 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1447 int media_info_get_added_time(media_info_h media, time_t *added_time)
1449 int ret = MEDIA_CONTENT_ERROR_NONE;
1450 media_info_s *_media = (media_info_s*)media;
1451 if (_media && added_time) {
1452 *added_time = _media->added_time;
1453 ret = MEDIA_CONTENT_ERROR_NONE;
1455 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1456 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1462 int media_info_get_modified_time(media_info_h media, time_t* time)
1464 int ret = MEDIA_CONTENT_ERROR_NONE;
1465 media_info_s *_media = (media_info_s*)media;
1466 if (_media && time) {
1467 *time = _media->modified_time;
1468 ret = MEDIA_CONTENT_ERROR_NONE;
1470 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1471 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1477 int media_info_get_timeline(media_info_h media, time_t* time)
1479 int ret = MEDIA_CONTENT_ERROR_NONE;
1480 media_info_s *_media = (media_info_s*)media;
1481 if (_media && time) {
1482 *time = _media->timeline;
1483 ret = MEDIA_CONTENT_ERROR_NONE;
1485 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1486 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1492 int media_info_get_thumbnail_path(media_info_h media, char **path)
1494 int ret = MEDIA_CONTENT_ERROR_NONE;
1495 media_info_s *_media = (media_info_s*)media;
1496 if (_media && path) {
1497 if (STRING_VALID(_media->thumbnail_path)) {
1498 *path = strdup(_media->thumbnail_path);
1499 media_content_retvm_if(*path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1503 ret = MEDIA_CONTENT_ERROR_NONE;
1506 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1507 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1513 int media_info_get_title(media_info_h media, char **title)
1515 int ret = MEDIA_CONTENT_ERROR_NONE;
1516 media_info_s *_media = (media_info_s*)media;
1518 if (_media && title) { /*title can be empty string*/
1519 if (STRING_VALID(_media->title)) {
1520 *title = strdup(_media->title);
1521 media_content_retvm_if(*title == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1525 ret = MEDIA_CONTENT_ERROR_NONE;
1527 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1528 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1534 int media_info_get_description(media_info_h media, char **description)
1536 int ret = MEDIA_CONTENT_ERROR_NONE;
1537 media_info_s *_media = (media_info_s*)media;
1539 if (_media && description) {
1540 if (STRING_VALID(_media->description)) {
1541 *description = strdup(_media->description);
1542 media_content_retvm_if(*description == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1544 *description = NULL;
1546 ret = MEDIA_CONTENT_ERROR_NONE;
1548 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1549 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1555 int media_info_get_longitude(media_info_h media, double* longitude)
1557 int ret = MEDIA_CONTENT_ERROR_NONE;
1558 media_info_s *_media = (media_info_s*)media;
1560 if (_media && longitude) {
1561 *longitude = _media->longitude;
1562 ret = MEDIA_CONTENT_ERROR_NONE;
1564 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1565 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1570 int media_info_get_latitude(media_info_h media, double* latitude)
1572 int ret = MEDIA_CONTENT_ERROR_NONE;
1573 media_info_s *_media = (media_info_s*)media;
1575 if (_media && latitude) {
1576 *latitude = _media->latitude;
1577 ret = MEDIA_CONTENT_ERROR_NONE;
1579 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1580 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1586 int media_info_get_altitude(media_info_h media, double *altitude)
1588 int ret = MEDIA_CONTENT_ERROR_NONE;
1589 media_info_s *_media = (media_info_s*)media;
1591 if (_media && altitude) {
1592 *altitude = _media->altitude;
1593 ret = MEDIA_CONTENT_ERROR_NONE;
1595 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1596 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1602 int media_info_get_weather(media_info_h media, char **weather)
1604 int ret = MEDIA_CONTENT_ERROR_NONE;
1605 media_info_s *_media = (media_info_s*)media;
1607 if (_media && weather) {
1608 if (STRING_VALID(_media->weather)) {
1609 *weather = strdup(_media->weather);
1610 media_content_retvm_if(*weather == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1614 ret = MEDIA_CONTENT_ERROR_NONE;
1616 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1617 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1623 int media_info_get_rating(media_info_h media, int *rating)
1625 int ret = MEDIA_CONTENT_ERROR_NONE;
1626 media_info_s *_media = (media_info_s*)media;
1628 if (_media && rating) {
1629 *rating = _media->rating;
1630 ret = MEDIA_CONTENT_ERROR_NONE;
1632 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1633 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1639 int media_info_get_favorite(media_info_h media, bool* favorite)
1641 int ret = MEDIA_CONTENT_ERROR_NONE;
1642 media_info_s *_media = (media_info_s*)media;
1644 if (_media && favorite) {
1645 *favorite = _media->favourite;
1646 ret = MEDIA_CONTENT_ERROR_NONE;
1648 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1649 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1655 int media_info_get_author(media_info_h media, char **author)
1657 int ret = MEDIA_CONTENT_ERROR_NONE;
1658 media_info_s *_media = (media_info_s*)media;
1660 if (_media && author) {
1661 if (STRING_VALID(_media->author)) {
1662 *author = strdup(_media->author);
1663 media_content_retvm_if(*author == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1667 ret = MEDIA_CONTENT_ERROR_NONE;
1669 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1670 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1676 int media_info_get_provider(media_info_h media, char **provider)
1678 int ret = MEDIA_CONTENT_ERROR_NONE;
1679 media_info_s *_media = (media_info_s*)media;
1681 if (_media && provider) {
1682 if (STRING_VALID(_media->provider)) {
1683 *provider = strdup(_media->provider);
1684 media_content_retvm_if(*provider == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1688 ret = MEDIA_CONTENT_ERROR_NONE;
1690 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1691 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1697 int media_info_get_content_name(media_info_h media, char **content_name)
1699 int ret = MEDIA_CONTENT_ERROR_NONE;
1700 media_info_s *_media = (media_info_s*)media;
1702 if (_media && content_name) {
1703 if (STRING_VALID(_media->content_name)) {
1704 *content_name = strdup(_media->content_name);
1705 media_content_retvm_if(*content_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1707 *content_name = NULL;
1709 ret = MEDIA_CONTENT_ERROR_NONE;
1711 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1712 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1718 int media_info_get_category(media_info_h media, char **category)
1720 int ret = MEDIA_CONTENT_ERROR_NONE;
1721 media_info_s *_media = (media_info_s*)media;
1723 if (_media && category) {
1724 if (STRING_VALID(_media->category)) {
1725 *category = strdup(_media->category);
1726 media_content_retvm_if(*category == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1730 ret = MEDIA_CONTENT_ERROR_NONE;
1732 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1733 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1739 int media_info_get_location_tag(media_info_h media, char **location_tag)
1741 int ret = MEDIA_CONTENT_ERROR_NONE;
1742 media_info_s *_media = (media_info_s*)media;
1744 if (_media && location_tag) {
1745 if (STRING_VALID(_media->location_tag)) {
1746 *location_tag = strdup(_media->location_tag);
1747 media_content_retvm_if(*location_tag == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1749 *location_tag = NULL;
1751 ret = MEDIA_CONTENT_ERROR_NONE;
1753 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1754 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1760 int media_info_get_age_rating(media_info_h media, char **age_rating)
1762 int ret = MEDIA_CONTENT_ERROR_NONE;
1763 media_info_s *_media = (media_info_s*)media;
1765 if (_media && age_rating) {
1766 if (STRING_VALID(_media->age_rating)) {
1767 *age_rating = strdup(_media->age_rating);
1768 media_content_retvm_if(*age_rating == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1772 ret = MEDIA_CONTENT_ERROR_NONE;
1774 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1775 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1781 int media_info_get_keyword(media_info_h media, char **keyword)
1783 int ret = MEDIA_CONTENT_ERROR_NONE;
1784 media_info_s *_media = (media_info_s*)media;
1786 if (_media && keyword) {
1787 if (STRING_VALID(_media->keyword)) {
1788 *keyword = strdup(_media->keyword);
1789 media_content_retvm_if(*keyword == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1793 ret = MEDIA_CONTENT_ERROR_NONE;
1795 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1796 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1802 int media_info_get_storage_id(media_info_h media, char **storage_id)
1804 int ret = MEDIA_CONTENT_ERROR_NONE;
1805 media_info_s *_media = (media_info_s*)media;
1807 if (_media && storage_id) {
1808 if (STRING_VALID(_media->storage_uuid)) {
1809 *storage_id = strdup(_media->storage_uuid);
1810 media_content_retvm_if(*storage_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1814 ret = MEDIA_CONTENT_ERROR_NONE;
1816 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1817 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1823 int media_info_is_drm(media_info_h media, bool *is_drm)
1825 int ret = MEDIA_CONTENT_ERROR_NONE;
1826 media_info_s *_media = (media_info_s*)media;
1829 *is_drm = _media->is_drm;
1830 ret = MEDIA_CONTENT_ERROR_NONE;
1832 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1833 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1839 int media_info_get_storage_type(media_info_h media, media_content_storage_e *storage_type)
1841 int ret = MEDIA_CONTENT_ERROR_NONE;
1842 media_info_s *_media = (media_info_s*)media;
1844 if (_media && storage_type) {
1845 *storage_type = _media->storage_type;
1846 ret = MEDIA_CONTENT_ERROR_NONE;
1848 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1849 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1855 int media_info_get_played_count(media_info_h media, int *played_count)
1857 int ret = MEDIA_CONTENT_ERROR_NONE;
1858 media_info_s *_media = (media_info_s*)media;
1861 *played_count = _media->played_count;
1862 ret = MEDIA_CONTENT_ERROR_NONE;
1864 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1865 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1871 int media_info_get_played_time(media_info_h media, time_t* played_time)
1873 int ret = MEDIA_CONTENT_ERROR_NONE;
1874 media_info_s *_media = (media_info_s*)media;
1877 *played_time = _media->played_time;
1878 ret = MEDIA_CONTENT_ERROR_NONE;
1880 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1881 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1887 int media_info_increase_played_count(media_info_h media)
1889 int ret = MEDIA_CONTENT_ERROR_NONE;
1891 media_info_s *_media = (media_info_s*)media;
1894 _media->played_count += 1;
1896 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1897 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1903 int media_info_set_played_time(media_info_h media)
1905 int ret = MEDIA_CONTENT_ERROR_NONE;
1906 time_t current_time;
1908 media_info_s *_media = (media_info_s*)media;
1910 if (_media != NULL) {
1911 time(¤t_time);
1912 _media->played_time = current_time;
1914 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1915 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1921 int media_info_get_media_from_db(const char *media_id, media_info_h *media)
1923 int ret = MEDIA_CONTENT_ERROR_NONE;
1924 char select_query[DEFAULT_QUERY_SIZE];
1925 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
1926 sqlite3_stmt *stmt = NULL;
1928 if (!STRING_VALID(media_id) || (media == NULL)) {
1929 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1930 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1933 memset(select_query, 0x00, sizeof(select_query));
1934 memset(storage_id, 0x00, sizeof(storage_id));
1936 ret = _media_db_get_storage_id_by_media_id(media_id, storage_id);
1937 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1939 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_MEDIA, storage_id, media_id);
1941 ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
1942 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
1944 media_info_s *_media = NULL;
1946 while (sqlite3_step(stmt) == SQLITE_ROW) {
1948 media_info_destroy((media_info_h)_media);
1950 _media = (media_info_s*)calloc(1, sizeof(media_info_s));
1952 if (_media == NULL) {
1953 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1954 SQLITE3_FINALIZE(stmt);
1955 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1958 _media_info_item_get_detail(stmt, (media_info_h)_media);
1960 *media = (media_info_h)_media;
1963 SQLITE3_FINALIZE(stmt);
1968 int media_info_set_display_name(media_info_h media, const char *display_name)
1970 int ret = MEDIA_CONTENT_ERROR_NONE;
1971 media_info_s *_media = (media_info_s*)media;
1973 if (_media != NULL && STRING_VALID(display_name)) {
1974 SAFE_FREE(_media->display_name);
1976 _media->display_name = strdup(display_name);
1977 media_content_retvm_if(_media->display_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1979 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1980 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1986 int media_info_set_description(media_info_h media, const char *description)
1988 int ret = MEDIA_CONTENT_ERROR_NONE;
1989 media_info_s *_media = (media_info_s*)media;
1991 if (_media != NULL) {
1992 SAFE_FREE(_media->description);
1994 if (STRING_VALID(description)) {
1995 _media->description = strdup(description);
1996 media_content_retvm_if(_media->description == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1998 _media->description = NULL;
2001 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2002 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2008 int media_info_set_longitude(media_info_h media, double longitude)
2010 int ret = MEDIA_CONTENT_ERROR_NONE;
2011 media_info_s *_media = (media_info_s*)media;
2013 if (_media != NULL) {
2014 _media->longitude = longitude;
2016 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2017 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2023 int media_info_set_latitude(media_info_h media, double latitude)
2025 int ret = MEDIA_CONTENT_ERROR_NONE;
2026 media_info_s *_media = (media_info_s*)media;
2028 if (_media != NULL) {
2029 _media->latitude = latitude;
2031 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2032 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2038 int media_info_set_altitude(media_info_h media, double altitude)
2040 int ret = MEDIA_CONTENT_ERROR_NONE;
2041 media_info_s *_media = (media_info_s*)media;
2043 if (_media != NULL) {
2044 _media->altitude = altitude;
2046 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2047 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2053 int media_info_set_weather(media_info_h media, const char *weather)
2055 int ret = MEDIA_CONTENT_ERROR_NONE;
2056 media_info_s *_media = (media_info_s*)media;
2058 if (_media != NULL) {
2059 SAFE_FREE(_media->weather);
2061 if (STRING_VALID(weather)) {
2062 _media->weather = strdup(weather);
2063 media_content_retvm_if(_media->weather == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2065 _media->weather = NULL;
2068 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2069 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2075 int media_info_set_rating(media_info_h media, int rating)
2077 int ret = MEDIA_CONTENT_ERROR_NONE;
2078 media_info_s *_media = (media_info_s*)media;
2080 if (_media != NULL) {
2081 _media->rating = rating;
2083 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2084 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2090 int media_info_set_added_time(media_info_h media, time_t added_time)
2092 int ret = MEDIA_CONTENT_ERROR_NONE;
2094 media_info_s *_media = (media_info_s*)media;
2096 if ((_media != NULL) && (added_time >= 0)) {
2097 _media->added_time = added_time;
2099 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2100 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2106 int media_info_set_favorite(media_info_h media, bool favorite)
2108 int ret = MEDIA_CONTENT_ERROR_NONE;
2109 media_info_s *_media = (media_info_s*)media;
2111 if (_media != NULL) {
2112 if (favorite == TRUE)
2113 time(&_media->favourite);
2115 _media->favourite = 0;
2117 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2118 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2124 int media_info_set_author(media_info_h media, const char *author)
2126 int ret = MEDIA_CONTENT_ERROR_NONE;
2127 media_info_s *_media = (media_info_s*)media;
2129 if (_media != NULL) {
2130 if (STRING_VALID(author)) {
2131 _media->author = strdup(author);
2132 media_content_retvm_if(_media->author == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2134 _media->author = NULL;
2137 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2138 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2144 int media_info_set_provider(media_info_h media, const char *provider)
2146 int ret = MEDIA_CONTENT_ERROR_NONE;
2147 media_info_s *_media = (media_info_s*)media;
2149 if (_media != NULL) {
2150 SAFE_FREE(_media->provider);
2152 if (STRING_VALID(provider)) {
2153 _media->provider = strdup(provider);
2154 media_content_retvm_if(_media->provider == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2156 _media->provider = NULL;
2159 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2160 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2166 int media_info_set_content_name(media_info_h media, const char *content_name)
2168 int ret = MEDIA_CONTENT_ERROR_NONE;
2169 media_info_s *_media = (media_info_s*)media;
2171 if (_media != NULL) {
2172 SAFE_FREE(_media->content_name);
2174 if (STRING_VALID(content_name)) {
2175 _media->content_name = strdup(content_name);
2176 media_content_retvm_if(_media->content_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2178 _media->content_name = NULL;
2181 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2182 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2188 int media_info_set_category(media_info_h media, const char *category)
2190 int ret = MEDIA_CONTENT_ERROR_NONE;
2191 media_info_s *_media = (media_info_s*)media;
2193 if (_media != NULL) {
2194 SAFE_FREE(_media->category);
2196 if (STRING_VALID(category)) {
2197 _media->category = strdup(category);
2198 media_content_retvm_if(_media->category == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2200 _media->category = NULL;
2203 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2204 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2210 int media_info_set_location_tag(media_info_h media, const char *location_tag)
2212 int ret = MEDIA_CONTENT_ERROR_NONE;
2213 media_info_s *_media = (media_info_s*)media;
2215 if (_media != NULL) {
2216 SAFE_FREE(_media->location_tag);
2218 if (STRING_VALID(location_tag)) {
2219 _media->location_tag = strdup(location_tag);
2220 media_content_retvm_if(_media->location_tag == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2222 _media->location_tag = NULL;
2225 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2226 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2232 int media_info_set_age_rating(media_info_h media, const char *age_rating)
2234 int ret = MEDIA_CONTENT_ERROR_NONE;
2235 media_info_s *_media = (media_info_s*)media;
2237 if (_media != NULL) {
2238 SAFE_FREE(_media->age_rating);
2240 if (STRING_VALID(age_rating)) {
2241 _media->age_rating = strdup(age_rating);
2242 media_content_retvm_if(_media->age_rating == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2244 _media->age_rating = NULL;
2247 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2248 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2254 int media_info_set_keyword(media_info_h media, const char *keyword)
2256 int ret = MEDIA_CONTENT_ERROR_NONE;
2257 media_info_s *_media = (media_info_s*)media;
2259 if (_media != NULL) {
2260 SAFE_FREE(_media->keyword);
2262 if (STRING_VALID(keyword)) {
2263 _media->keyword = strdup(keyword);
2264 media_content_retvm_if(_media->keyword == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2266 _media->keyword = NULL;
2269 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2270 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2276 int media_info_update_to_db(media_info_h media)
2278 int ret = MEDIA_CONTENT_ERROR_NONE;
2279 media_info_s *_media = (media_info_s*)media;
2280 char *set_sql = NULL;
2283 if (_media != NULL && STRING_VALID(_media->media_id)) {
2284 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
2285 /* This code will be removed when sqlite3_mprintf works clearly */
2286 char *test_sql = sqlite3_mprintf("%f, %f, %f", _media->longitude, _media->latitude, _media->altitude);
2287 SQLITE3_SAFE_FREE(test_sql);
2289 /*Update Pinyin If Support Pinyin*/
2290 char *file_name_pinyin = NULL;
2291 char *description_pinyin = NULL;
2292 char *author_pinyin = NULL;
2293 char *provider_pinyin = NULL;
2294 char *content_name_pinyin = NULL;
2295 char *category_pinyin = NULL;
2296 char *location_tag_pinyin = NULL;
2297 char *age_rating_pinyin = NULL;
2298 char *keyword_pinyin = NULL;
2299 bool pinyin_support = FALSE;
2301 /*Update Pinyin If Support Pinyin*/
2302 media_svc_check_pinyin_support(&pinyin_support);
2303 if (pinyin_support) {
2304 if (STRING_VALID(_media->display_name))
2305 media_svc_get_pinyin(_content_get_db_handle(), _media->display_name, &file_name_pinyin);
2306 if (STRING_VALID(_media->description))
2307 media_svc_get_pinyin(_content_get_db_handle(), _media->description, &description_pinyin);
2308 if (STRING_VALID(_media->author))
2309 media_svc_get_pinyin(_content_get_db_handle(), _media->author, &author_pinyin);
2310 if (STRING_VALID(_media->provider))
2311 media_svc_get_pinyin(_content_get_db_handle(), _media->provider, &provider_pinyin);
2312 if (STRING_VALID(_media->content_name))
2313 media_svc_get_pinyin(_content_get_db_handle(), _media->content_name, &content_name_pinyin);
2314 if (STRING_VALID(_media->category))
2315 media_svc_get_pinyin(_content_get_db_handle(), _media->category, &category_pinyin);
2316 if (STRING_VALID(_media->location_tag))
2317 media_svc_get_pinyin(_content_get_db_handle(), _media->location_tag, &location_tag_pinyin);
2318 if (STRING_VALID(_media->age_rating))
2319 media_svc_get_pinyin(_content_get_db_handle(), _media->age_rating, &age_rating_pinyin);
2320 if (STRING_VALID(_media->keyword))
2321 media_svc_get_pinyin(_content_get_db_handle(), _media->keyword, &keyword_pinyin);
2324 set_sql = sqlite3_mprintf("file_name=%Q, added_time=%d, description=%Q, longitude=%f, latitude=%f, altitude=%f, \
2325 played_count=%d, last_played_time=%d, last_played_position=%d, \
2326 rating=%d, favourite=%d, author=%Q, provider=%Q, content_name=%Q, category=%Q, location_tag=%Q, age_rating=%Q, keyword=%Q, weather=%Q, sync_status=%d, \
2327 file_name_pinyin=%Q, description_pinyin=%Q, author_pinyin=%Q, provider_pinyin=%Q, content_name_pinyin=%Q, category_pinyin=%Q, location_tag_pinyin=%Q, age_rating_pinyin=%Q, keyword_pinyin=%Q, title=%Q",
2328 _media->display_name, _media->added_time, _media->description, _media->longitude, _media->latitude, _media->altitude, _media->played_count, _media->played_time, _media->played_position, _media->rating, _media->favourite,
2329 _media->author, _media->provider, _media->content_name, _media->category, _media->location_tag, _media->age_rating, _media->keyword, _media->weather, _media->sync_status,
2330 file_name_pinyin, description_pinyin, author_pinyin, provider_pinyin, content_name_pinyin, category_pinyin, location_tag_pinyin, age_rating_pinyin, keyword_pinyin, _media->title);
2332 sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE media_uuid=%Q", _media->storage_uuid, set_sql, _media->media_id);
2334 ret = _content_query_sql(sql);
2335 SQLITE3_SAFE_FREE(set_sql);
2336 SQLITE3_SAFE_FREE(sql);
2338 SAFE_FREE(description_pinyin);
2339 SAFE_FREE(author_pinyin);
2340 SAFE_FREE(provider_pinyin);
2341 SAFE_FREE(content_name_pinyin);
2342 SAFE_FREE(category_pinyin);
2343 SAFE_FREE(location_tag_pinyin);
2344 SAFE_FREE(age_rating_pinyin);
2345 SAFE_FREE(keyword_pinyin);
2347 if (_media->storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2351 if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
2352 set_sql = sqlite3_mprintf("title=%Q, album=%Q, artist=%Q, genre=%Q, duration=%d, width=%d, height=%d", \
2353 _media->title, _media->video_meta->album, _media->video_meta->artist, _media->video_meta->genre, _media->video_meta->duration, _media->video_meta->width, _media->video_meta->height);
2354 } else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
2355 set_sql = sqlite3_mprintf("title=%Q, album=%Q, artist=%Q, genre=%Q, duration=%d", \
2356 _media->title, _media->audio_meta->album, _media->audio_meta->artist, _media->audio_meta->genre, _media->audio_meta->duration);
2357 } else if (_media->media_type == MEDIA_CONTENT_TYPE_IMAGE) {
2358 set_sql = sqlite3_mprintf("title=%Q, width=%d, height=%d", _media->title, _media->image_meta->width, _media->image_meta->height);
2360 set_sql = sqlite3_mprintf("title=%Q", _media->title);
2363 sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE media_uuid=%Q", _media->storage_uuid, set_sql, _media->media_id);
2365 ret = _content_query_sql(sql);
2367 SQLITE3_SAFE_FREE(set_sql);
2368 SQLITE3_SAFE_FREE(sql);
2371 if (ret == MEDIA_CONTENT_ERROR_NONE) {
2372 /* Send notification for this update */
2373 media_content_debug("Update is successfull. Send notification for this");
2374 if (_media->file_path && _media->mime_type)
2375 media_svc_publish_noti(_content_get_db_handle(), MS_MEDIA_ITEM_FILE, MS_MEDIA_ITEM_UPDATE, _media->file_path, _media->media_type, _media->media_id, _media->mime_type);
2377 media_content_error("Can't Send Noti : path or mime type is NULL");
2380 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2381 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2387 int media_info_refresh_metadata_to_db(const char *media_id)
2389 int ret = MEDIA_CONTENT_ERROR_NONE;
2390 media_info_h media = NULL;
2391 char *file_path = NULL;
2392 media_content_storage_e storage_type = 0;
2393 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
2395 if (!STRING_VALID(media_id)) {
2396 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2397 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2400 ret = media_info_get_media_from_db(media_id, &media);
2401 if (ret != MEDIA_CONTENT_ERROR_NONE) {
2402 media_info_destroy(media);
2406 ret = media_info_get_storage_type(media, &storage_type);
2407 if (ret != MEDIA_CONTENT_ERROR_NONE) {
2408 media_info_destroy(media);
2412 if (storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2413 media_info_destroy(media);
2414 media_content_error("Can't refresh cloud content!!");
2415 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2418 ret = media_info_get_file_path(media, &file_path);
2419 if (ret != MEDIA_CONTENT_ERROR_NONE) {
2420 media_info_destroy(media);
2424 ret = _media_util_check_file_exist(file_path);
2425 if (ret != MEDIA_CONTENT_ERROR_NONE) {
2426 SAFE_FREE(file_path);
2427 media_info_destroy(media);
2431 memset(storage_id, 0x00, sizeof(storage_id));
2432 ret = media_svc_get_storage_id(_content_get_db_handle(), file_path, storage_id);
2433 if (ret != MS_MEDIA_ERR_NONE) {
2434 media_content_error("media_svc_get_storage_id failed : %d", ret);
2435 SAFE_FREE(file_path);
2436 media_info_destroy(media);
2437 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2440 ret = media_svc_refresh_item(_content_get_db_handle(), storage_id, storage_type, file_path, tzplatform_getuid(TZ_USER_NAME));
2441 if (ret != MS_MEDIA_ERR_NONE)
2442 ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2444 SAFE_FREE(file_path);
2445 media_info_destroy(media);
2450 int media_info_move_to_db(media_info_h media, const char* dst_path)
2452 int ret = MEDIA_CONTENT_ERROR_NONE;
2453 bool ignore_file = FALSE;
2454 bool ignore_dir = FALSE;
2455 char *folder_path = NULL;
2456 media_svc_storage_type_e src_storage_type = 0;
2457 media_svc_storage_type_e dst_storage_type = 0;
2458 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
2460 media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media");
2461 media_content_retvm_if(!STRING_VALID(dst_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid dst_path");
2463 media_info_s *_media = (media_info_s*)media;
2465 ret = _media_util_check_ignore_file(dst_path, &ignore_file);
2466 media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
2468 ret = _media_util_check_file_exist(dst_path);
2469 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
2471 folder_path = g_path_get_dirname(dst_path);
2472 ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
2473 SAFE_FREE(folder_path);
2475 media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
2477 ret = media_svc_get_storage_type(_media->file_path, &src_storage_type, tzplatform_getuid(TZ_USER_NAME));
2478 if (ret != MS_MEDIA_ERR_NONE) {
2479 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
2480 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2483 ret = media_svc_get_storage_type(dst_path, &dst_storage_type, tzplatform_getuid(TZ_USER_NAME));
2484 if (ret != MS_MEDIA_ERR_NONE) {
2485 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
2486 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2489 memset(storage_id, 0x00, sizeof(storage_id));
2490 ret = media_svc_get_storage_id(_content_get_db_handle(), _media->file_path, storage_id);
2491 if (ret != MS_MEDIA_ERR_NONE) {
2492 media_content_error("media_svc_get_storage_id failed : %d", ret);
2493 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2496 ret = media_svc_move_item(_content_get_db_handle(), storage_id, src_storage_type, _media->file_path, dst_storage_type, dst_path, tzplatform_getuid(TZ_USER_NAME));
2497 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2500 int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data)
2502 int ret = MEDIA_CONTENT_ERROR_NONE;
2503 media_info_s *_media = (media_info_s*)media;
2505 if (_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path)) {
2506 media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s*)calloc(1, sizeof(media_thumbnail_cb_s));
2507 media_content_retvm_if(_thumb_cb == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2509 _thumb_cb->handle = _media;
2510 _thumb_cb->user_data = user_data;
2511 _thumb_cb->thumbnail_completed_cb = callback;
2513 ret = thumbnail_request_from_db_async(_media->file_path, (ThumbFunc)__media_info_thumbnail_completed_cb, (void *)_thumb_cb, tzplatform_getuid(TZ_USER_NAME));
2514 ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret);
2516 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2517 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2523 int media_info_cancel_thumbnail(media_info_h media)
2525 int ret = MEDIA_CONTENT_ERROR_NONE;
2526 media_info_s *_media = (media_info_s*)media;
2528 if (_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path)) {
2529 ret = thumbnail_request_cancel_media(_media->file_path);
2530 ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret);
2532 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2533 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2539 static int __media_info_map_data_usr_to_svc(media_info_s *media, media_svc_content_info_s **service_content, media_content_storage_e storage_type)
2541 media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
2543 media_svc_content_info_s *svc_content_info = calloc(1, sizeof(media_svc_content_info_s));
2544 media_content_retvm_if(svc_content_info == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2546 svc_content_info->path = g_strdup(media->file_path);
2547 svc_content_info->file_name = g_strdup(media->display_name);
2548 svc_content_info->media_type = media->media_type;
2549 svc_content_info->mime_type = g_strdup(media->mime_type);
2550 svc_content_info->size = media->size;
2551 svc_content_info->storage_type = storage_type;
2552 svc_content_info->storage_uuid = g_strdup(media->storage_uuid);
2554 svc_content_info->added_time = media->added_time;
2555 svc_content_info->modified_time = media->modified_time;
2556 svc_content_info->thumbnail_path = g_strdup(media->thumbnail_path);
2557 svc_content_info->is_drm = media->is_drm;
2558 svc_content_info->last_played_time = media->played_time;
2559 svc_content_info->played_count = media->played_count;
2560 svc_content_info->favourate = media->favourite;
2562 svc_content_info->media_meta.title = g_strdup(media->title);
2563 svc_content_info->media_meta.rating = media->rating;
2564 svc_content_info->media_meta.description = g_strdup(media->description);
2565 svc_content_info->media_meta.longitude = media->longitude;
2566 svc_content_info->media_meta.latitude = media->latitude;
2567 svc_content_info->media_meta.altitude = media->altitude;
2568 svc_content_info->media_meta.weather = g_strdup(media->weather);
2569 svc_content_info->media_meta.category = g_strdup(media->category);
2570 svc_content_info->media_meta.keyword = g_strdup(media->keyword);
2571 svc_content_info->media_meta.location_tag = g_strdup(media->location_tag);
2572 svc_content_info->media_meta.content_name = g_strdup(media->content_name);
2573 svc_content_info->media_meta.age_rating = g_strdup(media->age_rating);
2574 svc_content_info->media_meta.author = g_strdup(media->author);
2575 svc_content_info->media_meta.provider = g_strdup(media->provider);
2577 svc_content_info->media_meta.album = g_strdup(media->audio_meta->album);
2578 svc_content_info->media_meta.artist = g_strdup(media->audio_meta->artist);
2579 svc_content_info->media_meta.genre = g_strdup(media->audio_meta->genre);
2580 svc_content_info->media_meta.recorded_date = g_strdup(media->audio_meta->recorded_date);
2582 if (storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2583 switch (media->media_type) {
2584 case MEDIA_CONTENT_TYPE_IMAGE:
2585 svc_content_info->media_meta.width = media->image_meta->width;
2586 svc_content_info->media_meta.height = media->image_meta->height;
2587 svc_content_info->media_meta.datetaken = g_strdup(media->image_meta->date_taken);
2588 svc_content_info->media_meta.orientation = media->image_meta->orientation;
2590 case MEDIA_CONTENT_TYPE_VIDEO:
2591 svc_content_info->media_meta.album_artist = g_strdup(media->audio_meta->album_artist);
2592 svc_content_info->media_meta.composer = g_strdup(media->audio_meta->composer);
2593 svc_content_info->media_meta.year = g_strdup(media->audio_meta->year);
2594 svc_content_info->media_meta.copyright = g_strdup(media->audio_meta->copyright);
2595 svc_content_info->media_meta.track_num = g_strdup(media->audio_meta->track_num);
2596 svc_content_info->media_meta.bitrate = media->audio_meta->bitrate;
2597 svc_content_info->media_meta.duration = media->audio_meta->duration;
2598 svc_content_info->media_meta.width = media->image_meta->width;
2599 svc_content_info->media_meta.height = media->image_meta->height;
2601 case MEDIA_CONTENT_TYPE_SOUND:
2602 case MEDIA_CONTENT_TYPE_MUSIC:
2603 svc_content_info->media_meta.album_artist = g_strdup(media->audio_meta->album_artist);
2604 svc_content_info->media_meta.composer = g_strdup(media->audio_meta->composer);
2605 svc_content_info->media_meta.year = g_strdup(media->audio_meta->year);
2606 svc_content_info->media_meta.copyright = g_strdup(media->audio_meta->copyright);
2607 svc_content_info->media_meta.track_num = g_strdup(media->audio_meta->track_num);
2608 svc_content_info->media_meta.bitrate = media->audio_meta->bitrate;
2609 svc_content_info->media_meta.duration = media->audio_meta->duration;
2610 svc_content_info->media_meta.channel = media->audio_meta->channel;
2611 svc_content_info->media_meta.samplerate = media->audio_meta->samplerate;
2613 case MEDIA_CONTENT_TYPE_OTHERS:
2619 *service_content = svc_content_info;
2621 return MEDIA_CONTENT_ERROR_NONE;
2624 static int __media_info_set_str_data(media_info_h media, media_info_item_e data_type, const char *str_data)
2626 media_info_s *_media = (media_info_s*)media;
2628 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
2630 switch (data_type) {
2631 case MEDIA_INFO_PATH:
2632 SAFE_FREE(_media->file_path);
2633 if (STRING_VALID(str_data)) {
2634 _media->file_path = strdup(str_data);
2635 media_content_retvm_if(_media->file_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2637 _media->file_path = NULL;
2640 case MEDIA_INFO_MIME_TYPE:
2641 SAFE_FREE(_media->mime_type);
2642 if (STRING_VALID(str_data)) {
2643 _media->mime_type = strdup(str_data);
2644 media_content_retvm_if(_media->mime_type == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2646 _media->mime_type = NULL;
2649 case MEDIA_INFO_THUMBNAIL_PATH:
2650 SAFE_FREE(_media->thumbnail_path);
2651 if (STRING_VALID(str_data)) {
2652 _media->thumbnail_path = strdup(str_data);
2653 media_content_retvm_if(_media->thumbnail_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2655 _media->thumbnail_path = NULL;
2658 case MEDIA_INFO_TITLE:
2659 SAFE_FREE(_media->title);
2660 if (STRING_VALID(str_data)) {
2661 _media->title = strdup(str_data);
2662 media_content_retvm_if(_media->title == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2664 _media->title = NULL;
2667 case MEDIA_INFO_STORAGE_UUID:
2668 SAFE_FREE(_media->storage_uuid);
2669 if (STRING_VALID(str_data)) {
2670 _media->storage_uuid = strdup(str_data);
2671 media_content_retvm_if(_media->storage_uuid == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2673 _media->storage_uuid = NULL;
2676 case MEDIA_INFO_ALBUM:
2677 /* if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) */
2679 SAFE_FREE(_media->video_meta->album);
2680 if (STRING_VALID(str_data)) {
2681 _media->video_meta->album = strdup(str_data);
2682 media_content_retvm_if(_media->video_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2684 _media->video_meta->album = NULL;
2687 /* else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) */
2689 SAFE_FREE(_media->audio_meta->album);
2690 if (STRING_VALID(str_data)) {
2691 _media->audio_meta->album = strdup(str_data);
2692 media_content_retvm_if(_media->audio_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2694 _media->audio_meta->album = NULL;
2698 case MEDIA_INFO_ARTIST:
2699 /* if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) */
2701 SAFE_FREE(_media->video_meta->artist);
2702 if (STRING_VALID(str_data)) {
2703 _media->video_meta->artist = strdup(str_data);
2704 media_content_retvm_if(_media->video_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2706 _media->video_meta->artist = NULL;
2709 /* else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) */
2711 SAFE_FREE(_media->audio_meta->artist);
2712 if (STRING_VALID(str_data)) {
2713 _media->audio_meta->artist = strdup(str_data);
2714 media_content_retvm_if(_media->audio_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2716 _media->audio_meta->artist = NULL;
2720 case MEDIA_INFO_GENRE:
2721 /* if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) */
2723 SAFE_FREE(_media->video_meta->genre);
2724 if (STRING_VALID(str_data)) {
2725 _media->video_meta->genre = strdup(str_data);
2726 media_content_retvm_if(_media->video_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2728 _media->video_meta->genre = NULL;
2731 /* else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) */
2733 SAFE_FREE(_media->audio_meta->genre);
2734 if (STRING_VALID(str_data)) {
2735 _media->audio_meta->genre = strdup(str_data);
2736 media_content_retvm_if(_media->audio_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2738 _media->audio_meta->genre = NULL;
2742 case MEDIA_INFO_RECORDED_DATE:
2743 /* if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) */
2745 SAFE_FREE(_media->video_meta->recorded_date);
2746 if (STRING_VALID(str_data)) {
2747 _media->video_meta->recorded_date = strdup(str_data);
2748 media_content_retvm_if(_media->video_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2750 _media->video_meta->recorded_date = NULL;
2753 /* else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) */
2755 SAFE_FREE(_media->audio_meta->recorded_date);
2756 if (STRING_VALID(str_data)) {
2757 _media->audio_meta->recorded_date = strdup(str_data);
2758 media_content_retvm_if(_media->audio_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2760 _media->audio_meta->recorded_date = NULL;
2765 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2766 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2769 return MEDIA_CONTENT_ERROR_NONE;
2772 static int __media_info_destroy(media_info_h media)
2774 int ret = MEDIA_CONTENT_ERROR_NONE;
2775 media_info_s *_media = (media_info_s*)media;
2778 SAFE_FREE(_media->media_id);
2779 SAFE_FREE(_media->file_path);
2780 SAFE_FREE(_media->display_name);
2781 SAFE_FREE(_media->mime_type);
2782 SAFE_FREE(_media->thumbnail_path);
2783 SAFE_FREE(_media->description);
2784 SAFE_FREE(_media->author);
2785 SAFE_FREE(_media->provider);
2786 SAFE_FREE(_media->content_name);
2787 SAFE_FREE(_media->category);
2788 SAFE_FREE(_media->location_tag);
2789 SAFE_FREE(_media->age_rating);
2790 SAFE_FREE(_media->keyword);
2791 SAFE_FREE(_media->title);
2792 SAFE_FREE(_media->weather);
2793 SAFE_FREE(_media->storage_uuid);
2795 if (_media->image_meta) {
2796 SAFE_FREE(_media->image_meta->media_id);
2797 SAFE_FREE(_media->image_meta->date_taken);
2798 SAFE_FREE(_media->image_meta->burst_id);
2799 SAFE_FREE(_media->image_meta->exposure_time);
2800 SAFE_FREE(_media->image_meta->model);
2801 SAFE_FREE(_media->image_meta->title);
2802 SAFE_FREE(_media->image_meta->weather);
2804 SAFE_FREE(_media->image_meta);
2807 if (_media->video_meta) {
2808 SAFE_FREE(_media->video_meta->media_id);
2809 SAFE_FREE(_media->video_meta->title);
2810 SAFE_FREE(_media->video_meta->album);
2811 SAFE_FREE(_media->video_meta->artist);
2812 SAFE_FREE(_media->video_meta->album_artist);
2813 SAFE_FREE(_media->video_meta->genre);
2814 SAFE_FREE(_media->video_meta->composer);
2815 SAFE_FREE(_media->video_meta->year);
2816 SAFE_FREE(_media->video_meta->recorded_date);
2817 SAFE_FREE(_media->video_meta->copyright);
2818 SAFE_FREE(_media->video_meta->track_num);
2820 SAFE_FREE(_media->video_meta);
2823 if (_media->audio_meta) {
2824 SAFE_FREE(_media->audio_meta->media_id);
2825 SAFE_FREE(_media->audio_meta->title);
2826 SAFE_FREE(_media->audio_meta->album);
2827 SAFE_FREE(_media->audio_meta->artist);
2828 SAFE_FREE(_media->audio_meta->album_artist);
2829 SAFE_FREE(_media->audio_meta->genre);
2830 SAFE_FREE(_media->audio_meta->composer);
2831 SAFE_FREE(_media->audio_meta->year);
2832 SAFE_FREE(_media->audio_meta->recorded_date);
2833 SAFE_FREE(_media->audio_meta->copyright);
2834 SAFE_FREE(_media->audio_meta->track_num);
2836 SAFE_FREE(_media->audio_meta);
2839 ret = MEDIA_CONTENT_ERROR_NONE;
2841 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2842 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2848 int media_info_insert_to_db_with_data(media_info_h media)
2850 int ret = MEDIA_CONTENT_ERROR_NONE;
2852 media_info_s *_media = (media_info_s*)media;
2854 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
2855 media_content_retvm_if(!STRING_VALID(_media->file_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid file_path");
2856 media_content_retvm_if(!STRING_VALID(_media->storage_uuid), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid storage_uuid");
2857 media_content_retvm_if(_media->storage_type < 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid storage_type [%d]", _media->storage_type);
2859 /* Cloud Item should be filled whole info*/
2860 if (_media->storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
2861 media_content_retvm_if(!STRING_VALID(_media->mime_type), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid mime_type");
2862 media_content_retvm_if(!STRING_VALID(_media->title), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid title");
2863 media_content_retvm_if(_media->size <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid size [%d]", _media->size);
2864 media_content_retvm_if(_media->modified_time <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid modified_time [%d]", _media->modified_time);
2866 if ((_media->media_type < MEDIA_CONTENT_TYPE_IMAGE) || (_media->media_type > MEDIA_CONTENT_TYPE_OTHERS)) {
2867 media_content_error("invalid media type [%d]", _media->media_type);
2868 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2872 media_content_sec_debug("storage[%d], path[%s], media_type[%d]", _media->storage_type, _media->file_path, _media->media_type);
2874 media_svc_content_info_s *svc_content_info = NULL;
2876 ret = __media_info_map_data_usr_to_svc(_media, &svc_content_info, _media->storage_type);
2877 media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "__media_info_map_data_usr_to_svc fail");
2879 ret = media_svc_insert_item_immediately_with_data(_content_get_db_handle(), svc_content_info, tzplatform_getuid(TZ_USER_NAME));
2880 if (ret != MS_MEDIA_ERR_NONE) {
2881 media_content_sec_error("media_svc_insert_item_immediately_with_data failed : %d (%s)", ret, _media->file_path);
2882 media_svc_destroy_content_info(svc_content_info);
2883 SAFE_FREE(svc_content_info);
2884 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2886 /*free the svc_content_info*/
2887 media_svc_destroy_content_info(svc_content_info);
2888 SAFE_FREE(svc_content_info);
2890 /*Fill out the handle*/
2891 char *media_file_path = g_strdup(_media->file_path);
2892 char *media_string_uuid = g_strdup(_media->storage_uuid);
2894 __media_info_destroy(media);
2895 ret = _media_info_get_media_info_from_db(media_file_path, media_string_uuid, media);
2896 if (ret != MEDIA_CONTENT_ERROR_NONE)
2897 media_content_error("_media_info_get_media_info_from_db fail", ret);
2899 SAFE_FREE(media_file_path);
2900 SAFE_FREE(media_string_uuid);
2905 int media_info_create(const char *path, media_info_h *media)
2907 int ret = MEDIA_CONTENT_ERROR_NONE;
2908 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
2909 media_svc_storage_type_e storage_type = 0;
2911 media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
2912 media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
2914 memset(storage_id, 0x00, sizeof(storage_id));
2916 if (STRING_VALID(MEDIA_ROOT_PATH_CLOUD) && (strstr(MEDIA_ROOT_PATH_CLOUD, path) == NULL)) {
2917 bool ignore_file = FALSE;
2918 bool ignore_dir = FALSE;
2919 char *folder_path = NULL;
2921 ret = _media_util_check_ignore_file(path, &ignore_file);
2922 media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
2924 ret = _media_util_check_file_exist(path);
2925 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
2927 folder_path = g_path_get_dirname(path);
2928 ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
2929 SAFE_FREE(folder_path);
2930 media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
2932 ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id);
2933 if (ret != MS_MEDIA_ERR_NONE) {
2934 media_content_error("media_svc_get_storage_id failed : %d", ret);
2935 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2938 ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
2939 if (ret != MS_MEDIA_ERR_NONE) {
2940 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
2941 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2945 media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s));
2946 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2948 _media->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
2949 if (_media->audio_meta == NULL) {
2951 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2952 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2955 _media->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
2956 if (_media->video_meta == NULL) {
2957 SAFE_FREE(_media->audio_meta);
2959 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2960 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2963 _media->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
2964 if (_media->image_meta == NULL) {
2965 SAFE_FREE(_media->audio_meta);
2966 SAFE_FREE(_media->video_meta);
2968 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2969 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2972 _media->file_path = g_strdup(path);
2973 _media->storage_type = -1;
2974 _media->media_type = 0;
2975 _media->modified_time = 0;
2977 _media->longitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
2978 _media->latitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
2979 _media->altitude = MEDIA_SVC_DEFAULT_GPS_VALUE;
2981 if (STRING_VALID(storage_id)) {
2982 _media->storage_uuid = g_strdup(storage_id);
2983 _media->storage_type = storage_type;
2986 *media = (media_info_h)_media;
2991 int media_info_set_path(media_info_h media, const char *path)
2993 return __media_info_set_str_data(media, MEDIA_INFO_PATH, path);
2996 int media_info_set_mime_type(media_info_h media, const char *mime_type)
2998 return __media_info_set_str_data(media, MEDIA_INFO_MIME_TYPE, mime_type);
3001 int media_info_set_title(media_info_h media, const char *title)
3003 return __media_info_set_str_data(media, MEDIA_INFO_TITLE, title);
3006 int media_info_set_album(media_info_h media, const char *album)
3008 return __media_info_set_str_data(media, MEDIA_INFO_ALBUM, album);
3011 int media_info_set_artist(media_info_h media, const char *artist)
3013 return __media_info_set_str_data(media, MEDIA_INFO_ARTIST, artist);
3016 int media_info_set_genre(media_info_h media, const char *genre)
3018 return __media_info_set_str_data(media, MEDIA_INFO_GENRE, genre);
3021 int media_info_set_recorded_date(media_info_h media, const char *recorded_date)
3023 return __media_info_set_str_data(media, MEDIA_INFO_RECORDED_DATE, recorded_date);
3026 int media_info_set_thumbnail_path(media_info_h media, const char *thumbnail_path)
3028 return __media_info_set_str_data(media, MEDIA_INFO_THUMBNAIL_PATH, thumbnail_path);
3031 int media_info_set_storage_id(media_info_h media, const char *storage_id)
3033 return __media_info_set_str_data(media, MEDIA_INFO_STORAGE_UUID, storage_id);
3036 int media_info_set_size(media_info_h media, unsigned long long size)
3038 media_info_s *_media = (media_info_s*)media;
3040 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3042 _media->size = size;
3044 return MEDIA_CONTENT_ERROR_NONE;
3047 int media_info_set_modified_time(media_info_h media, time_t modified_time)
3049 media_info_s *_media = (media_info_s*)media;
3051 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3053 _media->modified_time = modified_time;
3055 return MEDIA_CONTENT_ERROR_NONE;
3058 int media_info_set_media_type(media_info_h media, media_content_type_e type)
3060 media_info_s *_media = (media_info_s*)media;
3062 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3064 _media->media_type = type;
3066 return MEDIA_CONTENT_ERROR_NONE;
3069 int media_info_set_duration(media_info_h media, int duration)
3071 media_info_s *_media = (media_info_s*)media;
3073 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3075 if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3076 _media->video_meta->duration = duration;
3077 else if ((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
3078 _media->audio_meta->duration = duration;
3080 media_content_error("Invalid media type");
3081 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3084 return MEDIA_CONTENT_ERROR_NONE;
3087 int media_info_set_width(media_info_h media, int width)
3089 media_info_s *_media = (media_info_s*)media;
3091 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3093 if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3094 _media->video_meta->width = width;
3095 else if (_media->media_type == MEDIA_CONTENT_TYPE_IMAGE)
3096 _media->image_meta->width = width;
3098 media_content_error("Invalid media type");
3099 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3102 return MEDIA_CONTENT_ERROR_NONE;
3105 int media_info_set_height(media_info_h media, int height)
3107 media_info_s *_media = (media_info_s*)media;
3109 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3111 if (_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3112 _media->video_meta->height = height;
3113 else if (_media->media_type == MEDIA_CONTENT_TYPE_IMAGE)
3114 _media->image_meta->height = height;
3116 media_content_error("Invalid media type");
3117 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3120 return MEDIA_CONTENT_ERROR_NONE;
3123 int media_info_set_storage_type(media_info_h media, media_content_storage_e storage_type)
3125 media_info_s *_media = (media_info_s*)media;
3127 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3129 _media->storage_type = storage_type;
3131 return MEDIA_CONTENT_ERROR_NONE;