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)
43 if(STRING_VALID((const char *)sqlite3_column_text(stmt, 0)))
44 *path = strdup((const char *)sqlite3_column_text(stmt, 0));
46 media_content_error("There's no media with this ID : %s", media_id);
48 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
51 SQLITE3_FINALIZE(stmt);
56 static void __media_info_insert_completed_cb(media_request_result_s *result, void *user_data)
58 int ret = MEDIA_CONTENT_ERROR_NONE;
59 media_insert_cb_s *_cb_data = (media_insert_cb_s *)user_data;
63 ret = _content_error_capi(MEDIA_CONTENT_TYPE, result->result);
66 if (_cb_data->insert_completed_cb)
67 _cb_data->insert_completed_cb(ret, _cb_data->user_data);
69 if (STRING_VALID(_cb_data->insert_list_path)) {
70 if (unlink(_cb_data->insert_list_path) < 0) {
71 media_content_stderror("failed to delete");
73 SAFE_FREE(_cb_data->insert_list_path);
82 static void __media_info_thumbnail_completed_cb(int error, const char *path, void *user_data)
84 int error_value = MEDIA_CONTENT_ERROR_NONE;
86 media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s *)user_data;
87 media_info_s *media = NULL;
91 media = _thumb_cb->handle;
92 if((media != NULL) && STRING_VALID(path))
94 SAFE_FREE(media->thumbnail_path);
95 media->thumbnail_path = strdup(path);
98 media_content_debug("error [%d], thumbnail_path [%s]", error, path);
99 error_value = _content_error_capi(MEDIA_THUMBNAIL_TYPE, error);
100 if (_thumb_cb->thumbnail_completed_cb)
101 _thumb_cb->thumbnail_completed_cb(error_value, path, _thumb_cb->user_data);
104 SAFE_FREE(_thumb_cb);
109 static bool __media_info_delete_batch_cb(media_info_h media, void *user_data)
111 int err = MEDIA_CONTENT_ERROR_NONE;
112 char *thumb_path = NULL;
113 media_content_type_e media_type = 0;
114 GArray *thumb_list = (GArray *)user_data;
118 media_content_debug("NO Item");
122 err = media_info_get_media_type(media, &media_type);
123 if (err == MEDIA_CONTENT_ERROR_NONE) {
124 media_content_debug("media_type : [%d]", media_type);
126 media_info_get_thumbnail_path(media, &thumb_path);
127 if (STRING_VALID(thumb_path)) {
128 if (strncmp(MEDIA_CONTENT_THUMB_DEFAULT_PATH, thumb_path, strlen(MEDIA_CONTENT_THUMB_DEFAULT_PATH)) != 0) {
129 g_array_append_val(thumb_list, thumb_path);
133 media_content_error("media_info_get_media_type failed");
139 static int __media_info_insert_batch(media_batch_insert_e insert_type, const char **path_array,
140 unsigned int array_length,
141 media_insert_completed_cb completed_cb,
144 int ret = MEDIA_CONTENT_ERROR_NONE;
146 char list_path[255] = {0, };
147 unsigned int idx = 0;
150 for (idx = 0; idx < BATCH_REQUEST_MAX; idx++) {
151 snprintf(list_path, sizeof(list_path), "%s/request-%ld-%d", MEDIA_CONTENT_INSERT_FILES_PATH, media_content_gettid(), idx);
153 if (g_file_test(list_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
154 memset(list_path, 0x00, sizeof(list_path));
157 media_content_debug("The request file list path : %s", list_path);
162 if (idx == BATCH_REQUEST_MAX) {
163 media_content_error("Too many batch request for one thread");
164 return MEDIA_CONTENT_ERROR_DB_BUSY;
167 fp = fopen(list_path, "w");
169 media_content_error("failed to open file : [%s]", list_path);
170 media_content_stderror("failed to open file");
171 return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
174 for (idx = 0; idx < array_length; idx++) {
175 if (STRING_VALID(path_array[idx])) {
176 int size = strlen(path_array[idx]);
178 ret = _media_util_check_file_exist(path_array[idx]);
179 if (ret != MEDIA_CONTENT_ERROR_NONE) {
181 if (unlink(list_path) < 0) {
182 media_content_stderror("failed to delete");
187 nwrites = fwrite(path_array[idx], 1, size, fp);
188 if (nwrites != size) {
189 media_content_stderror("failed to write");
191 if (unlink(list_path) < 0) {
192 media_content_stderror("failed to delete");
194 return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
197 nwrites = fwrite("\n", 1, 1, fp);
199 media_content_stderror("failed to write");
201 if (unlink(list_path) < 0) {
202 media_content_stderror("failed to delete");
204 return MEDIA_CONTENT_ERROR_INVALID_OPERATION;
207 media_content_error("path[%d] is invalid string", idx);
213 media_insert_cb_s *_cb_data = (media_insert_cb_s *)calloc(1, sizeof(media_insert_cb_s));
214 media_content_retvm_if(_cb_data == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
216 _cb_data->insert_completed_cb = completed_cb;
217 _cb_data->user_data = user_data;
218 _cb_data->insert_list_path = strdup(list_path);
220 if(insert_type == MEDIA_BATCH_INSERT_NORMAL)
221 ret = media_files_register(list_path, __media_info_insert_completed_cb, _cb_data, tzplatform_getuid(TZ_USER_NAME));
222 else if(insert_type == MEDIA_BATCH_INSERT_BURSTSHOT)
223 ret = media_burstshot_register(list_path, __media_info_insert_completed_cb, _cb_data, tzplatform_getuid(TZ_USER_NAME));
225 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
227 if (ret != MEDIA_CONTENT_ERROR_NONE) {
228 media_content_error("media_files_register failed : %d", ret);
229 if (unlink(list_path) < 0) {
230 media_content_stderror("failed to delete");
232 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
238 void _media_info_item_get_detail(sqlite3_stmt* stmt, media_info_h media)
240 media_info_s *_media = (media_info_s*)media;
242 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_UUID)))
243 _media->media_id = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_UUID));
245 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_PATH)))
246 _media->file_path = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_PATH));
248 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_FILE_NAME)))
249 _media->display_name = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_FILE_NAME));
251 _media->media_type = (int)sqlite3_column_int(stmt, MEDIA_INFO_TYPE);
253 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_MIME_TYPE)))
254 _media->mime_type = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_MIME_TYPE));
256 _media->size = (unsigned long long)sqlite3_column_int64(stmt, MEDIA_INFO_SIZE);
258 _media->added_time = (int)sqlite3_column_int(stmt, MEDIA_INFO_ADDED_TIME);
260 _media->modified_time = (int)sqlite3_column_int(stmt, MEDIA_INFO_MODIFIED_TIME);
262 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_THUMBNAIL_PATH)))
263 _media->thumbnail_path= strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_THUMBNAIL_PATH));
265 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_DESCRIPTION)))
266 _media->description = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_DESCRIPTION));
268 _media->rating = (int)sqlite3_column_int(stmt, MEDIA_INFO_RATING);
270 _media->favourite = (int)sqlite3_column_int(stmt, MEDIA_INFO_FAVOURITE);
272 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_AUTHOR)))
273 _media->author = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_AUTHOR));
275 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_PROVIDER)))
276 _media->provider = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_PROVIDER));
278 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_CONTENT_NAME)))
279 _media->content_name = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_CONTENT_NAME));
281 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_CATEGORY)))
282 _media->category = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_CATEGORY));
284 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_LOCATION_TAG)))
285 _media->location_tag = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_LOCATION_TAG));
287 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_AGE_RATING)))
288 _media->age_rating = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_AGE_RATING));
290 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_KEYWORD)))
291 _media->keyword = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_KEYWORD));
293 _media->is_drm = (int)sqlite3_column_int(stmt, MEDIA_INFO_IS_DRM);
295 _media->storage_type = (int)sqlite3_column_int(stmt, MEDIA_INFO_STORAGE_TYPE);
297 _media->longitude = (double)sqlite3_column_double(stmt, MEDIA_INFO_LONGITUDE);
298 _media->latitude = (double)sqlite3_column_double(stmt, MEDIA_INFO_LATITUDE);
299 _media->altitude = (double)sqlite3_column_double(stmt, MEDIA_INFO_ALTITUDE);
301 _media->played_count = sqlite3_column_int(stmt, MEDIA_INFO_PLAYED_COUNT);
302 _media->played_time = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_TIME);
303 _media->played_position = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_POSITION);
305 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE)))
306 _media->title = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE));
308 _media->timeline = (double)sqlite3_column_double(stmt, MEDIA_INFO_TIMELINE);
310 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_WEATHER)))
311 _media->weather = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_WEATHER));
313 _media->sync_status = (int)sqlite3_column_int(stmt, MEDIA_INFO_SYNC_STATUS);
315 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_STORAGE_UUID)))
316 _media->storage_uuid = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_STORAGE_UUID));
318 if(_media->media_type == MEDIA_CONTENT_TYPE_IMAGE) {
319 _media->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
320 if(_media->image_meta) {
321 if(STRING_VALID(_media->media_id))
322 _media->image_meta->media_id = strdup(_media->media_id);
324 _media->image_meta->width = sqlite3_column_int(stmt, MEDIA_INFO_WIDTH);
325 _media->image_meta->height = sqlite3_column_int(stmt, MEDIA_INFO_HEIGHT);
326 _media->image_meta->fnumber = (double)sqlite3_column_double(stmt, MEDIA_INFO_FNUMBER);
327 _media->image_meta->iso = sqlite3_column_int(stmt, MEDIA_INFO_ISO);
329 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_DATETAKEN)))
330 _media->image_meta->date_taken = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_DATETAKEN));
332 _media->image_meta->orientation = sqlite3_column_int(stmt, MEDIA_INFO_ORIENTATION);
334 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE)))
335 _media->image_meta->title = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE));
337 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_BURST_ID)))
338 _media->image_meta->burst_id = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_BURST_ID));
340 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_WEATHER)))
341 _media->image_meta->weather = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_WEATHER));
343 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_EXPOSURE_TIME)))
344 _media->image_meta->exposure_time = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_EXPOSURE_TIME));
346 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_MODEL)))
347 _media->image_meta->model = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_MODEL));
350 } else if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO) {
351 _media->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
352 if(_media->video_meta) {
353 if(STRING_VALID(_media->media_id))
354 _media->video_meta->media_id = strdup(_media->media_id);
356 _media->video_meta->width = sqlite3_column_int(stmt, MEDIA_INFO_WIDTH);
357 _media->video_meta->height = sqlite3_column_int(stmt, MEDIA_INFO_HEIGHT);
359 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE)))
360 _media->video_meta->title = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE));
362 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM)))
363 _media->video_meta->album = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM));
365 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ARTIST)))
366 _media->video_meta->artist = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ARTIST));
368 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM_ARTIST)))
369 _media->video_meta->album_artist = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM_ARTIST));
371 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_GENRE)))
372 _media->video_meta->genre = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_GENRE));
374 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COMPOSER)))
375 _media->video_meta->composer = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COMPOSER));
377 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_YEAR)))
378 _media->video_meta->year = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_YEAR));
380 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_RECORDED_DATE)))
381 _media->video_meta->recorded_date = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_RECORDED_DATE));
383 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COPYRIGHT)))
384 _media->video_meta->copyright = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COPYRIGHT));
386 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TRACK_NUM)))
387 _media->video_meta->track_num = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TRACK_NUM));
389 _media->video_meta->bitrate = sqlite3_column_int(stmt, MEDIA_INFO_BITRATE);
390 _media->video_meta->duration = sqlite3_column_int(stmt, MEDIA_INFO_DURATION);
391 _media->video_meta->played_count = sqlite3_column_int(stmt, MEDIA_INFO_PLAYED_COUNT);
392 _media->video_meta->played_time = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_TIME);
393 _media->video_meta->played_position = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_POSITION);
397 else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND)) {
398 _media->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
399 if(_media->audio_meta) {
400 if(STRING_VALID(_media->media_id))
401 _media->audio_meta->media_id = strdup(_media->media_id);
403 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE)))
404 _media->audio_meta->title = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TITLE));
406 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM)))
407 _media->audio_meta->album = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM));
409 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ARTIST)))
410 _media->audio_meta->artist = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ARTIST));
412 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM_ARTIST)))
413 _media->audio_meta->album_artist = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_ALBUM_ARTIST));
415 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_GENRE)))
416 _media->audio_meta->genre = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_GENRE));
418 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COMPOSER)))
419 _media->audio_meta->composer = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COMPOSER));
421 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_YEAR)))
422 _media->audio_meta->year = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_YEAR));
424 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_RECORDED_DATE)))
425 _media->audio_meta->recorded_date = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_RECORDED_DATE));
427 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COPYRIGHT)))
428 _media->audio_meta->copyright = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_COPYRIGHT));
430 if(STRING_VALID((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TRACK_NUM)))
431 _media->audio_meta->track_num = strdup((const char *)sqlite3_column_text(stmt, MEDIA_INFO_TRACK_NUM));
433 _media->audio_meta->bitrate = sqlite3_column_int(stmt, MEDIA_INFO_BITRATE);
434 _media->audio_meta->bitpersample = sqlite3_column_int(stmt, MEDIA_INFO_BITPERSAMPLE);
435 _media->audio_meta->duration = sqlite3_column_int(stmt, MEDIA_INFO_DURATION);
436 _media->audio_meta->played_count = sqlite3_column_int(stmt, MEDIA_INFO_PLAYED_COUNT);
437 _media->audio_meta->played_time = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_TIME);
438 _media->audio_meta->played_position = sqlite3_column_int(stmt, MEDIA_INFO_LAST_PLAYED_POSITION);
439 _media->audio_meta->samplerate = sqlite3_column_int(stmt, MEDIA_INFO_SAMPLERATE);
440 _media->audio_meta->channel = sqlite3_column_int(stmt, MEDIA_INFO_CHANNEL);
445 int _media_info_get_media_info_from_db(const char *path, const char *storage_id, media_info_h media)
447 int ret = MEDIA_CONTENT_ERROR_NONE;
448 sqlite3_stmt *stmt = NULL;
449 char *select_query = NULL;
450 media_info_s *_media = (media_info_s*)media;
452 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media");
454 select_query = sqlite3_mprintf(SELECT_MEDIA_BY_PATH, storage_id, path);
456 ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
457 SQLITE3_SAFE_FREE(select_query);
458 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
460 if(sqlite3_step(stmt) == SQLITE_ROW)
462 _media_info_item_get_detail(stmt, (media_info_h)_media);
464 media_content_error("There's no media!!");
465 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
468 SQLITE3_FINALIZE(stmt);
473 int media_info_insert_to_db(const char *path, media_info_h *info)
475 bool ignore_file = FALSE;
476 bool ignore_dir = FALSE;
477 char *folder_path = NULL;
478 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
479 int ret = MEDIA_CONTENT_ERROR_NONE;
481 media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid path");
482 media_content_retvm_if(info == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid info");
484 ret = _media_util_check_ignore_file(path, &ignore_file);
485 media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
487 ret = _media_util_check_file_exist(path);
488 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
490 folder_path = g_path_get_dirname(path);
491 ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
492 SAFE_FREE(folder_path);
494 media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
496 memset(storage_id, 0x00, sizeof(storage_id));
497 ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id);
498 if(ret != MS_MEDIA_ERR_NONE)
500 media_content_error("media_svc_get_storage_id failed : %d", ret);
501 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
504 ret = media_svc_check_item_exist_by_path(_content_get_db_handle(), storage_id, path);
505 if (ret == MS_MEDIA_ERR_DB_NO_RECORD) {
506 media_content_sec_debug("media_svc_check_item_exist_by_path : no record : %s", path);
508 media_svc_storage_type_e storage_type = 0;
510 ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
511 if(ret != MS_MEDIA_ERR_NONE) {
512 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
513 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
516 ret = media_svc_insert_item_immediately(_content_get_db_handle(), storage_id, storage_type, path, tzplatform_getuid(TZ_USER_NAME));
518 if(ret != MS_MEDIA_ERR_NONE) {
519 if (ret == MS_MEDIA_ERR_DB_CONSTRAINT_FAIL) {
520 media_content_sec_error("This item is already inserted. This may be normal operation because other process already did this (%s)", path);
521 ret = MEDIA_CONTENT_ERROR_NONE;
523 media_content_sec_error("media_svc_insert_item_immediately failed : %d (%s)", ret, path);
526 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
528 } else if (ret != MS_MEDIA_ERR_NONE) {
529 media_content_sec_error("media_svc_check_item_exist_by_path failed : %d (%s)", ret, path);
530 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
533 media_info_s *_media = (media_info_s*)calloc(1, sizeof(media_info_s));
534 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
536 ret = _media_info_get_media_info_from_db(path, DEFAULT_MEDIA_STORAGE_ID, (media_info_h)_media);
538 *info = (media_info_h)_media;
542 int media_info_insert_batch_to_db(
543 const char **path_array,
544 unsigned int array_length,
545 media_insert_completed_cb completed_cb,
548 media_content_retvm_if(path_array == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path_array");
549 media_content_retvm_if(array_length <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid array_length");
551 return __media_info_insert_batch(MEDIA_BATCH_INSERT_NORMAL, path_array, array_length, completed_cb, user_data);
554 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)
556 media_content_retvm_if(path_array == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path_array");
557 media_content_retvm_if(array_length <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid array_length");
559 return __media_info_insert_batch(MEDIA_BATCH_INSERT_BURSTSHOT, path_array, array_length, callback, user_data);
562 int media_info_delete_from_db(const char *media_id)
564 int ret = MEDIA_CONTENT_ERROR_NONE;
566 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
568 if(!STRING_VALID(media_id))
570 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
571 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
574 memset(storage_id, 0x00, sizeof(storage_id));
576 ret = __media_info_get_media_path_by_id_from_db(media_id, &path);
577 if(ret != MEDIA_CONTENT_ERROR_NONE) {
578 media_content_error("__media_info_get_media_path_by_id_from_db failed : %d", ret);
583 ret = _media_db_get_storage_id_by_media_id(media_id, storage_id);
584 if(ret != MEDIA_CONTENT_ERROR_NONE) {
585 media_content_error("_media_db_get_storage_id_by_media_id failed : %d", ret);
590 ret = media_svc_delete_item_by_path(_content_get_db_handle(), storage_id, path, tzplatform_getuid(TZ_USER_NAME));
593 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
596 static int __media_info_delete_thumb_from_list(GArray *thumb_list)
600 char *thumb_path = NULL;
602 if (thumb_list != NULL) {
604 list_len = thumb_list->len;
606 for (i = 0; i < list_len; i ++) {
607 thumb_path = g_array_index(thumb_list, char*, i);
608 media_content_debug("thumb path [%s]", thumb_path);
609 if (unlink(thumb_path) < 0) {
610 media_content_stderror("failed to delete");
614 return MEDIA_CONTENT_ERROR_NONE;
617 static int __media_info_release_thumb_list(GArray *thumb_list)
621 char *thumb_path = NULL;
623 if (thumb_list != NULL) {
625 list_len = thumb_list->len;
627 for (i = 0; i < list_len; i ++) {
628 thumb_path = g_array_index(thumb_list, char*, 0);
629 g_array_remove_index(thumb_list,0);
630 SAFE_FREE(thumb_path);
633 g_array_free(thumb_list, FALSE);
636 return MEDIA_CONTENT_ERROR_NONE;
639 int media_info_delete_batch_from_db(filter_h filter)
641 int ret = MEDIA_CONTENT_ERROR_NONE;
643 char *query_string = NULL;
644 filter_s *_filter = NULL;
646 char *condition_query = NULL;
647 GArray *thumb_list = NULL;
649 media_content_retvm_if(filter == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid filter");
651 thumb_list = g_array_new(FALSE, FALSE, sizeof(char*));
653 /* Delete thumbnail of each item */
654 ret = _media_db_get_group_item(NULL, filter, __media_info_delete_batch_cb, thumb_list, MEDIA_GROUP_NONE);
656 _filter = (filter_s*)filter;
657 attr = _content_get_attirbute_handle();
659 if(_filter->condition)
661 ret = _media_filter_attribute_generate(attr, _filter->condition, _filter->condition_collate_type, &condition_query);
662 if (ret != MEDIA_CONTENT_ERROR_NONE) {
663 __media_info_release_thumb_list(thumb_list);
668 if(STRING_VALID(condition_query))
670 if (_filter->storage_id == NULL) {
672 query_string = sqlite3_mprintf(DELETE_MEDIA_FROM_MEDIA_BATCH, "media", condition_query);
674 query_string = sqlite3_mprintf(DELETE_MEDIA_FROM_MEDIA_BATCH, _filter->storage_id, condition_query);
679 SAFE_FREE(condition_query);
680 __media_info_release_thumb_list(thumb_list);
682 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
685 ret = _content_query_sql(query_string);
686 if (ret == MEDIA_CONTENT_ERROR_NONE) {
687 /* Send notification for this
688 In this case, send noti for internal storage and external storage
690 media_content_debug("Batch deletion is successfull. Send notification for this");
691 if (_filter->storage_id != NULL) {
692 char *storage_path = NULL;
693 media_svc_get_storage_path(_content_get_db_handle(), _filter->storage_id, &storage_path);
694 if (STRING_VALID(storage_path))
695 media_svc_publish_noti(_content_get_db_handle(), MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, storage_path, -1, NULL, NULL);
697 SAFE_FREE(storage_path);
700 media_svc_publish_noti(_content_get_db_handle(), MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, MEDIA_ROOT_PATH_INTERNAL, -1, NULL, NULL);
701 media_svc_publish_noti(_content_get_db_handle(), MS_MEDIA_ITEM_DIRECTORY, MS_MEDIA_ITEM_UPDATE, MEDIA_ROOT_PATH_SDCARD, -1, NULL, NULL);
704 __media_info_delete_thumb_from_list(thumb_list);
705 __media_info_release_thumb_list(thumb_list);
708 SAFE_FREE(condition_query);
709 SQLITE3_SAFE_FREE(query_string);
714 int media_info_destroy(media_info_h media)
716 int ret = MEDIA_CONTENT_ERROR_NONE;
717 media_info_s *_media = (media_info_s*)media;
721 SAFE_FREE(_media->media_id);
722 SAFE_FREE(_media->file_path);
723 SAFE_FREE(_media->display_name);
724 SAFE_FREE(_media->mime_type);
725 SAFE_FREE(_media->thumbnail_path);
726 SAFE_FREE(_media->description);
727 SAFE_FREE(_media->author);
728 SAFE_FREE(_media->provider);
729 SAFE_FREE(_media->content_name);
730 SAFE_FREE(_media->category);
731 SAFE_FREE(_media->location_tag);
732 SAFE_FREE(_media->age_rating);
733 SAFE_FREE(_media->keyword);
734 SAFE_FREE(_media->title);
735 SAFE_FREE(_media->weather);
736 SAFE_FREE(_media->storage_uuid);
738 if(_media->image_meta) {
739 SAFE_FREE(_media->image_meta->media_id);
740 SAFE_FREE(_media->image_meta->date_taken);
741 SAFE_FREE(_media->image_meta->burst_id);
742 SAFE_FREE(_media->image_meta->exposure_time);
743 SAFE_FREE(_media->image_meta->model);
744 SAFE_FREE(_media->image_meta->title);
745 SAFE_FREE(_media->image_meta->weather);
747 SAFE_FREE(_media->image_meta);
750 if(_media->video_meta) {
751 SAFE_FREE(_media->video_meta->media_id);
752 SAFE_FREE(_media->video_meta->title);
753 SAFE_FREE(_media->video_meta->album);
754 SAFE_FREE(_media->video_meta->artist);
755 SAFE_FREE(_media->video_meta->album_artist);
756 SAFE_FREE(_media->video_meta->genre);
757 SAFE_FREE(_media->video_meta->composer);
758 SAFE_FREE(_media->video_meta->year);
759 SAFE_FREE(_media->video_meta->recorded_date);
760 SAFE_FREE(_media->video_meta->copyright);
761 SAFE_FREE(_media->video_meta->track_num);
763 SAFE_FREE(_media->video_meta);
766 if(_media->audio_meta) {
767 SAFE_FREE(_media->audio_meta->media_id);
768 SAFE_FREE(_media->audio_meta->title);
769 SAFE_FREE(_media->audio_meta->album);
770 SAFE_FREE(_media->audio_meta->artist);
771 SAFE_FREE(_media->audio_meta->album_artist);
772 SAFE_FREE(_media->audio_meta->genre);
773 SAFE_FREE(_media->audio_meta->composer);
774 SAFE_FREE(_media->audio_meta->year);
775 SAFE_FREE(_media->audio_meta->recorded_date);
776 SAFE_FREE(_media->audio_meta->copyright);
777 SAFE_FREE(_media->audio_meta->track_num);
779 SAFE_FREE(_media->audio_meta);
784 ret = MEDIA_CONTENT_ERROR_NONE;
788 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
789 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
795 int media_info_clone(media_info_h *dst, media_info_h src)
797 int ret = MEDIA_CONTENT_ERROR_NONE;
798 media_info_s *_src = (media_info_s*)src;
803 media_info_s *_dst = (media_info_s*)calloc(1, sizeof(media_info_s));
804 media_content_retvm_if(_dst == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
806 if(STRING_VALID(_src->media_id))
808 _dst->media_id = strdup(_src->media_id);
809 if(_dst->media_id == NULL)
811 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
812 media_info_destroy((media_info_h)_dst);
813 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
816 if(STRING_VALID(_src->file_path))
818 _dst->file_path = strdup(_src->file_path);
819 if(_dst->file_path == NULL)
821 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
822 media_info_destroy((media_info_h)_dst);
823 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
826 if(STRING_VALID(_src->display_name))
828 _dst->display_name = strdup(_src->display_name);
829 if(_dst->display_name == NULL)
831 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
832 media_info_destroy((media_info_h)_dst);
833 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
836 if(STRING_VALID(_src->mime_type))
838 _dst->mime_type = strdup(_src->mime_type);
839 if(_dst->mime_type == 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;
846 if(STRING_VALID(_src->thumbnail_path))
848 _dst->thumbnail_path = strdup(_src->thumbnail_path);
849 if(_dst->thumbnail_path == NULL)
851 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
852 media_info_destroy((media_info_h)_dst);
853 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
856 if(STRING_VALID(_src->description))
858 _dst->description = strdup(_src->description);
859 if(_dst->description == NULL)
861 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
862 media_info_destroy((media_info_h)_dst);
863 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
867 if(STRING_VALID(_src->weather))
869 _dst->weather = strdup(_src->weather);
870 if(_dst->weather == NULL)
872 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
873 media_info_destroy((media_info_h)_dst);
874 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
878 if(STRING_VALID(_src->title))
880 _dst->title = strdup(_src->title);
881 if(_dst->title == NULL)
883 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
884 media_info_destroy((media_info_h)_dst);
885 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
888 if(STRING_VALID(_src->author))
890 _dst->author = strdup(_src->author);
891 if(_dst->author == NULL)
893 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
894 media_info_destroy((media_info_h)_dst);
895 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
898 if(STRING_VALID(_src->provider))
900 _dst->provider = strdup(_src->provider);
901 if(_dst->provider == NULL)
903 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
904 media_info_destroy((media_info_h)_dst);
905 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
908 if(STRING_VALID(_src->content_name))
910 _dst->content_name = strdup(_src->content_name);
911 if(_dst->content_name == NULL)
913 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
914 media_info_destroy((media_info_h)_dst);
915 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
918 if(STRING_VALID(_src->category))
920 _dst->category = strdup(_src->category);
921 if(_dst->category == NULL)
923 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
924 media_info_destroy((media_info_h)_dst);
925 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
928 if(STRING_VALID(_src->location_tag))
930 _dst->location_tag = strdup(_src->location_tag);
931 if(_dst->location_tag == NULL)
933 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
934 media_info_destroy((media_info_h)_dst);
935 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
938 if(STRING_VALID(_src->age_rating))
940 _dst->age_rating = strdup(_src->age_rating);
941 if(_dst->age_rating == NULL)
943 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
944 media_info_destroy((media_info_h)_dst);
945 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
948 if(STRING_VALID(_src->keyword))
950 _dst->keyword = strdup(_src->keyword);
951 if(_dst->keyword == NULL)
953 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
954 media_info_destroy((media_info_h)_dst);
955 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
959 if(STRING_VALID(_src->storage_uuid))
961 _dst->storage_uuid = strdup(_src->storage_uuid);
962 if(_dst->storage_uuid == 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;
970 _dst->media_type = _src->media_type;
971 _dst->size = _src->size;
972 _dst->added_time = _src->added_time;
973 _dst->modified_time = _src->modified_time;
974 _dst->timeline = _src->timeline;
975 _dst->longitude = _src->longitude;
976 _dst->latitude = _src->latitude;
977 _dst->altitude = _src->altitude;
978 _dst->rating = _src->rating;
979 _dst->favourite = _src->favourite;
980 _dst->is_drm = _src->is_drm;
981 _dst->storage_type = _src->storage_type;
982 _dst->played_count = _src->played_count;
983 _dst->played_time = _src->played_time;
984 _dst->played_position = _src->played_position;
985 _dst->sync_status = _src->sync_status;
987 if(_src->media_type == MEDIA_CONTENT_TYPE_IMAGE && _src->image_meta) {
988 _dst->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
989 if(_dst->image_meta == NULL)
991 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
992 media_info_destroy((media_info_h)_dst);
993 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
996 if(STRING_VALID(_src->image_meta->media_id))
998 _dst->image_meta->media_id = strdup(_src->image_meta->media_id);
999 if(_dst->image_meta->media_id == NULL)
1001 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1002 media_info_destroy((media_info_h)_dst);
1003 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1007 if(STRING_VALID(_src->image_meta->date_taken))
1009 _dst->image_meta->date_taken = strdup(_src->image_meta->date_taken);
1010 if(_dst->image_meta->date_taken == NULL)
1012 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1013 media_info_destroy((media_info_h)_dst);
1014 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1018 if(STRING_VALID(_src->image_meta->burst_id))
1020 _dst->image_meta->burst_id = strdup(_src->image_meta->burst_id);
1021 if(_dst->image_meta->burst_id == NULL)
1023 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1024 media_info_destroy((media_info_h)_dst);
1025 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1029 if(STRING_VALID(_src->image_meta->weather))
1031 _dst->image_meta->weather = strdup(_src->image_meta->weather);
1032 if(_dst->image_meta->weather == NULL)
1034 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1035 media_info_destroy((media_info_h)_dst);
1036 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1040 if(STRING_VALID(_src->image_meta->exposure_time))
1042 _dst->image_meta->exposure_time = strdup(_src->image_meta->exposure_time);
1043 if(_dst->image_meta->exposure_time == 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;
1051 if(STRING_VALID(_src->image_meta->model))
1053 _dst->image_meta->model = strdup(_src->image_meta->model);
1054 if(_dst->image_meta->model == NULL)
1056 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1057 media_info_destroy((media_info_h)_dst);
1058 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1062 _dst->image_meta->fnumber = _src->image_meta->fnumber;
1063 _dst->image_meta->iso = _src->image_meta->iso;
1064 _dst->image_meta->width = _src->image_meta->width;
1065 _dst->image_meta->height = _src->image_meta->height;
1066 _dst->image_meta->orientation = _src->image_meta->orientation;
1068 } else if(_src->media_type == MEDIA_CONTENT_TYPE_VIDEO && _src->video_meta) {
1069 _dst->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
1070 if(_dst->video_meta == NULL)
1072 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1073 media_info_destroy((media_info_h)_dst);
1074 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1077 if(STRING_VALID(_src->video_meta->media_id))
1079 _dst->video_meta->media_id = strdup(_src->video_meta->media_id);
1080 if(_dst->video_meta->media_id == NULL)
1082 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1083 media_info_destroy((media_info_h)_dst);
1084 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1087 if(STRING_VALID(_src->video_meta->title))
1089 _dst->video_meta->title = strdup(_src->video_meta->title);
1090 if(_dst->video_meta->title == NULL)
1092 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1093 media_info_destroy((media_info_h)_dst);
1094 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1097 if(STRING_VALID(_src->video_meta->album))
1099 _dst->video_meta->album = strdup(_src->video_meta->album);
1100 if(_dst->video_meta->album == NULL)
1102 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1103 media_info_destroy((media_info_h)_dst);
1104 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1107 if(STRING_VALID(_src->video_meta->artist))
1109 _dst->video_meta->artist = strdup(_src->video_meta->artist);
1110 if(_dst->video_meta->artist == NULL)
1112 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1113 media_info_destroy((media_info_h)_dst);
1114 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1117 if(STRING_VALID(_src->video_meta->album_artist))
1119 _dst->video_meta->album_artist = strdup(_src->video_meta->album_artist);
1120 if(_dst->video_meta->album_artist == NULL)
1122 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1123 media_info_destroy((media_info_h)_dst);
1124 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1127 if(STRING_VALID(_src->video_meta->genre))
1129 _dst->video_meta->genre = strdup(_src->video_meta->genre);
1130 if(_dst->video_meta->genre == NULL)
1132 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1133 media_info_destroy((media_info_h)_dst);
1134 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1137 if(STRING_VALID(_src->video_meta->composer))
1139 _dst->video_meta->composer = strdup(_src->video_meta->composer);
1140 if(_dst->video_meta->composer == NULL)
1142 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1143 media_info_destroy((media_info_h)_dst);
1144 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1147 if(STRING_VALID(_src->video_meta->year))
1149 _dst->video_meta->year = strdup(_src->video_meta->year);
1150 if(_dst->video_meta->year == NULL)
1152 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1153 media_info_destroy((media_info_h)_dst);
1154 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1157 if(STRING_VALID(_src->video_meta->recorded_date))
1159 _dst->video_meta->recorded_date = strdup(_src->video_meta->recorded_date);
1160 if(_dst->video_meta->recorded_date == NULL)
1162 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1163 media_info_destroy((media_info_h)_dst);
1164 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1167 if(STRING_VALID(_src->video_meta->copyright))
1169 _dst->video_meta->copyright = strdup(_src->video_meta->copyright);
1170 if(_dst->video_meta->copyright == NULL)
1172 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1173 media_info_destroy((media_info_h)_dst);
1174 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1177 if(STRING_VALID(_src->video_meta->track_num))
1179 _dst->video_meta->track_num = strdup(_src->video_meta->track_num);
1180 if(_dst->video_meta->track_num == NULL)
1182 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1183 media_info_destroy((media_info_h)_dst);
1184 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1188 _dst->video_meta->width = _src->video_meta->width;
1189 _dst->video_meta->height = _src->video_meta->height;
1190 _dst->video_meta->duration = _src->video_meta->duration;
1191 _dst->video_meta->bitrate = _src->video_meta->bitrate;
1192 _dst->video_meta->played_count = _src->video_meta->played_count;
1193 _dst->video_meta->played_time = _src->video_meta->played_time;
1194 _dst->video_meta->played_position = _src->video_meta->played_position;
1196 } else if((_src->media_type == MEDIA_CONTENT_TYPE_MUSIC || _src->media_type == MEDIA_CONTENT_TYPE_SOUND) && _src->audio_meta) {
1197 _dst->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
1198 if(_dst->audio_meta == NULL)
1200 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1201 media_info_destroy((media_info_h)_dst);
1202 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1205 if(STRING_VALID(_src->audio_meta->media_id))
1207 _dst->audio_meta->media_id = strdup(_src->audio_meta->media_id);
1208 if(_dst->audio_meta->media_id == NULL)
1210 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1211 media_info_destroy((media_info_h)_dst);
1212 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1215 if(STRING_VALID(_src->audio_meta->title))
1217 _dst->audio_meta->title = strdup(_src->audio_meta->title);
1218 if(_dst->audio_meta->title == NULL)
1220 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1221 media_info_destroy((media_info_h)_dst);
1222 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1225 if(STRING_VALID(_src->audio_meta->album))
1227 _dst->audio_meta->album = strdup(_src->audio_meta->album);
1228 if(_dst->audio_meta->album == NULL)
1230 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1231 media_info_destroy((media_info_h)_dst);
1232 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1235 if(STRING_VALID(_src->audio_meta->artist))
1237 _dst->audio_meta->artist = strdup(_src->audio_meta->artist);
1238 if(_dst->audio_meta->artist == NULL)
1240 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1241 media_info_destroy((media_info_h)_dst);
1242 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1245 if(STRING_VALID(_src->audio_meta->album_artist))
1247 _dst->audio_meta->album_artist = strdup(_src->audio_meta->album_artist);
1248 if(_dst->audio_meta->album_artist == NULL)
1250 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1251 media_info_destroy((media_info_h)_dst);
1252 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1255 if(STRING_VALID(_src->audio_meta->genre))
1257 _dst->audio_meta->genre = strdup(_src->audio_meta->genre);
1258 if(_dst->audio_meta->genre == NULL)
1260 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1261 media_info_destroy((media_info_h)_dst);
1262 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1265 if(STRING_VALID(_src->audio_meta->composer))
1267 _dst->audio_meta->composer = strdup(_src->audio_meta->composer);
1268 if(_dst->audio_meta->composer == NULL)
1270 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1271 media_info_destroy((media_info_h)_dst);
1272 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1275 if(STRING_VALID(_src->audio_meta->year))
1277 _dst->audio_meta->year = strdup(_src->audio_meta->year);
1278 if(_dst->audio_meta->year == NULL)
1280 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1281 media_info_destroy((media_info_h)_dst);
1282 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1285 if(STRING_VALID(_src->audio_meta->recorded_date))
1287 _dst->audio_meta->recorded_date = strdup(_src->audio_meta->recorded_date);
1288 if(_dst->audio_meta->recorded_date == NULL)
1290 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1291 media_info_destroy((media_info_h)_dst);
1292 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1295 if(STRING_VALID(_src->audio_meta->copyright))
1297 _dst->audio_meta->copyright = strdup(_src->audio_meta->copyright);
1298 if(_dst->audio_meta->copyright == NULL)
1300 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1301 media_info_destroy((media_info_h)_dst);
1302 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1305 if(STRING_VALID(_src->audio_meta->track_num))
1307 _dst->audio_meta->track_num = strdup(_src->audio_meta->track_num);
1308 if(_dst->audio_meta->track_num == NULL)
1310 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
1311 media_info_destroy((media_info_h)_dst);
1312 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
1316 _dst->audio_meta->channel = _src->audio_meta->channel;
1317 _dst->audio_meta->samplerate = _src->audio_meta->samplerate;
1318 _dst->audio_meta->duration = _src->audio_meta->duration;
1319 _dst->audio_meta->bitrate = _src->audio_meta->bitrate;
1320 _dst->audio_meta->bitpersample = _src->audio_meta->bitpersample;
1321 _dst->audio_meta->played_count = _src->audio_meta->played_count;
1322 _dst->audio_meta->played_time = _src->audio_meta->played_time;
1323 _dst->audio_meta->played_position = _src->audio_meta->played_position;
1326 *dst = (media_info_h)_dst;
1328 ret = MEDIA_CONTENT_ERROR_NONE;
1332 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1333 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1339 int media_info_get_media_count_from_db(filter_h filter, int *media_count)
1341 int ret = MEDIA_CONTENT_ERROR_NONE;
1343 if(media_count == NULL)
1345 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1346 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1351 ret = _media_db_get_group_item_count(NULL, filter, MEDIA_GROUP_NONE, media_count);
1356 int media_info_foreach_media_from_db(filter_h filter, media_info_cb callback, void *user_data)
1358 int ret = MEDIA_CONTENT_ERROR_NONE;
1360 media_content_retvm_if(callback == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid callback");
1362 ret = _media_db_get_group_item(NULL, filter, callback, user_data, MEDIA_GROUP_NONE);
1367 int media_info_get_tag_count_from_db(const char *media_id, filter_h filter, int *tag_count)
1369 int ret = MEDIA_CONTENT_ERROR_NONE;
1371 if(STRING_VALID(media_id) && tag_count)
1373 ret = _media_db_get_group_item_count(media_id, filter, MEDIA_GROUP_TAG_BY_MEDIA_ID, tag_count);
1377 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1378 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1384 int media_info_foreach_tag_from_db(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data)
1386 int ret = MEDIA_CONTENT_ERROR_NONE;
1388 if((callback != NULL) && STRING_VALID(media_id))
1390 ret = _media_db_get_tag(media_id, filter, callback, user_data);
1394 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1395 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1401 int media_info_get_bookmark_count_from_db(const char *media_id, filter_h filter, int *bookmark_count)
1403 int ret = MEDIA_CONTENT_ERROR_NONE;
1405 if(STRING_VALID(media_id) && bookmark_count)
1407 ret = _media_db_get_group_item_count(media_id, filter, MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID, bookmark_count);
1411 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1412 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1418 int media_info_foreach_bookmark_from_db (const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data)
1420 int ret = MEDIA_CONTENT_ERROR_NONE;
1422 if((callback != NULL) && STRING_VALID(media_id))
1424 ret = _media_db_get_bookmark(media_id, filter, callback, user_data);
1428 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1429 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1435 int media_info_get_face_count_from_db(const char *media_id, filter_h filter, int *face_count)
1437 int ret = MEDIA_CONTENT_ERROR_NONE;
1439 if(STRING_VALID(media_id) && face_count)
1441 ret = _media_db_get_group_item_count(media_id, filter, MEDIA_GROUP_FACE_BY_MEDIA_ID, face_count);
1445 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1446 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1452 int media_info_foreach_face_from_db (const char *media_id, filter_h filter, media_face_cb callback, void *user_data)
1454 int ret = MEDIA_CONTENT_ERROR_NONE;
1456 if((callback != NULL) && STRING_VALID(media_id))
1458 ret = _media_db_get_face(media_id, filter, callback, user_data);
1462 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1463 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1469 int media_info_get_image(media_info_h media, image_meta_h *image)
1471 int ret = MEDIA_CONTENT_ERROR_NONE;
1473 media_info_s *_media = (media_info_s*)media;
1475 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
1476 media_content_retvm_if(_media->media_type != MEDIA_CONTENT_TYPE_IMAGE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_type");
1477 media_content_retvm_if(_media->image_meta == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid image_meta");
1479 image_meta_s *_image = (image_meta_s*)calloc(1, sizeof(image_meta_s));
1480 media_content_retvm_if(_image == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1482 if(STRING_VALID(_media->media_id)) {
1483 _image->media_id = strdup(_media->media_id);
1486 _image->width = _media->image_meta->width;
1487 _image->height = _media->image_meta->height;
1488 _image->orientation = _media->image_meta->orientation;
1489 _image->fnumber = _media->image_meta->fnumber;
1490 _image->iso = _media->image_meta->iso;
1492 if(STRING_VALID(_media->image_meta->date_taken)) {
1493 _image->date_taken = strdup(_media->image_meta->date_taken);
1496 if(STRING_VALID(_media->image_meta->title)) {
1497 _image->title = strdup(_media->image_meta->title);
1500 if(STRING_VALID(_media->image_meta->burst_id)) {
1501 _image->burst_id = strdup(_media->image_meta->burst_id);
1504 if(STRING_VALID(_media->image_meta->weather)) {
1505 _image->weather = strdup(_media->image_meta->weather);
1508 if(STRING_VALID(_media->image_meta->exposure_time)) {
1509 _image->exposure_time = strdup(_media->image_meta->exposure_time);
1512 if(STRING_VALID(_media->image_meta->model)) {
1513 _image->model = strdup(_media->image_meta->model);
1516 *image = (image_meta_h)_image;
1521 int media_info_get_video(media_info_h media, video_meta_h *video)
1523 int ret = MEDIA_CONTENT_ERROR_NONE;
1525 media_info_s *_media = (media_info_s*)media;
1527 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
1528 media_content_retvm_if(_media->media_type != MEDIA_CONTENT_TYPE_VIDEO, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_type");
1529 media_content_retvm_if(_media->video_meta == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid video_meta");
1531 video_meta_s *_video = (video_meta_s*)calloc(1, sizeof(video_meta_s));
1532 media_content_retvm_if(_video == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1534 if(STRING_VALID(_media->media_id)) {
1535 _video->media_id = strdup(_media->media_id);
1538 if(STRING_VALID(_media->video_meta->title)) {
1539 _video->title = strdup(_media->video_meta->title);
1541 if(STRING_VALID(_media->video_meta->album)) {
1542 _video->album = strdup(_media->video_meta->album);
1544 if(STRING_VALID(_media->video_meta->artist)) {
1545 _video->artist = strdup(_media->video_meta->artist);
1547 if(STRING_VALID(_media->video_meta->album_artist)) {
1548 _video->album_artist = strdup(_media->video_meta->album_artist);
1550 if(STRING_VALID(_media->video_meta->genre)) {
1551 _video->genre = strdup(_media->video_meta->genre);
1553 if(STRING_VALID(_media->video_meta->composer)) {
1554 _video->composer = strdup(_media->video_meta->composer);
1556 if(STRING_VALID(_media->video_meta->year)) {
1557 _video->year = strdup(_media->video_meta->year);
1559 if(STRING_VALID(_media->video_meta->recorded_date)) {
1560 _video->recorded_date = strdup(_media->video_meta->recorded_date);
1562 if(STRING_VALID(_media->video_meta->copyright)) {
1563 _video->copyright = strdup(_media->video_meta->copyright);
1565 if(STRING_VALID(_media->video_meta->track_num)) {
1566 _video->track_num = strdup(_media->video_meta->track_num);
1569 _video->width = _media->video_meta->width;
1570 _video->height = _media->video_meta->height;
1571 _video->duration = _media->video_meta->duration;
1572 _video->bitrate = _media->video_meta->bitrate;
1573 _video->played_count = _media->video_meta->played_count;
1574 _video->played_time = _media->video_meta->played_time;
1575 _video->played_position = _media->video_meta->played_position;
1577 *video = (video_meta_h)_video;
1582 int media_info_get_audio(media_info_h media, audio_meta_h *audio)
1584 int ret = MEDIA_CONTENT_ERROR_NONE;
1586 media_info_s *_media = (media_info_s*)media;
1589 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
1590 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");
1591 media_content_retvm_if(_media->audio_meta == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid audio_meta");
1593 audio_meta_s *_audio = (audio_meta_s*)calloc(1, sizeof(audio_meta_s));
1594 media_content_retvm_if(_audio == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1596 if(STRING_VALID(_media->media_id)) {
1597 _audio->media_id = strdup(_media->media_id);
1600 if(STRING_VALID(_media->audio_meta->title)) {
1601 _audio->title = strdup(_media->audio_meta->title);
1603 if(STRING_VALID(_media->audio_meta->album)) {
1604 _audio->album = strdup(_media->audio_meta->album);
1606 if(STRING_VALID(_media->audio_meta->artist)) {
1607 _audio->artist = strdup(_media->audio_meta->artist);
1609 if(STRING_VALID(_media->audio_meta->album_artist)) {
1610 _audio->album_artist = strdup(_media->audio_meta->album_artist);
1612 if(STRING_VALID(_media->audio_meta->genre)) {
1613 _audio->genre = strdup(_media->audio_meta->genre);
1615 if(STRING_VALID(_media->audio_meta->composer)) {
1616 _audio->composer = strdup(_media->audio_meta->composer);
1618 if(STRING_VALID(_media->audio_meta->year)) {
1619 _audio->year = strdup(_media->audio_meta->year);
1621 if(STRING_VALID(_media->audio_meta->recorded_date)) {
1622 _audio->recorded_date = strdup(_media->audio_meta->recorded_date);
1624 if(STRING_VALID(_media->audio_meta->copyright)) {
1625 _audio->copyright = strdup(_media->audio_meta->copyright);
1627 if(STRING_VALID(_media->audio_meta->track_num)) {
1628 _audio->track_num = strdup(_media->audio_meta->track_num);
1631 _audio->duration = _media->audio_meta->duration;
1632 _audio->bitrate = _media->audio_meta->bitrate;
1633 _audio->bitpersample = _media->audio_meta->bitpersample;
1634 _audio->samplerate = _media->audio_meta->samplerate;
1635 _audio->channel = _media->audio_meta->channel;
1636 _audio->played_time = _media->audio_meta->played_time;
1637 _audio->played_count = _media->audio_meta->played_count;
1638 _audio->played_position = _media->audio_meta->played_position;
1640 *audio = (audio_meta_h)_audio;
1645 int media_info_get_media_id(media_info_h media, char **media_id)
1647 int ret = MEDIA_CONTENT_ERROR_NONE;
1648 media_info_s *_media = (media_info_s*)media;
1650 if(_media && media_id)
1652 if(STRING_VALID(_media->media_id))
1654 *media_id = strdup(_media->media_id);
1655 media_content_retvm_if(*media_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1661 ret = MEDIA_CONTENT_ERROR_NONE;
1665 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1666 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1672 int media_info_get_file_path(media_info_h media, char **path)
1674 int ret = MEDIA_CONTENT_ERROR_NONE;
1675 media_info_s *_media = (media_info_s*)media;
1679 if(STRING_VALID(_media->file_path))
1681 *path = strdup(_media->file_path);
1682 media_content_retvm_if(*path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1688 ret = MEDIA_CONTENT_ERROR_NONE;
1693 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1694 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1700 int media_info_get_display_name(media_info_h media, char **name)
1702 int ret = MEDIA_CONTENT_ERROR_NONE;
1703 media_info_s *_media = (media_info_s*)media;
1706 if(STRING_VALID(_media->display_name))
1708 *name = strdup(_media->display_name);
1709 media_content_retvm_if(*name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1715 ret = MEDIA_CONTENT_ERROR_NONE;
1720 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1721 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1727 int media_info_get_media_type(media_info_h media, media_content_type_e *type)
1729 int ret = MEDIA_CONTENT_ERROR_NONE;
1730 media_info_s *_media = (media_info_s*)media;
1733 *type = _media->media_type;
1734 ret = MEDIA_CONTENT_ERROR_NONE;
1738 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1739 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1745 int media_info_get_mime_type(media_info_h media, char **mime_type)
1747 int ret = MEDIA_CONTENT_ERROR_NONE;
1748 media_info_s *_media = (media_info_s*)media;
1750 if(_media && mime_type)
1752 if(STRING_VALID(_media->mime_type))
1754 *mime_type = strdup(_media->mime_type);
1755 media_content_retvm_if(*mime_type == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1761 ret = MEDIA_CONTENT_ERROR_NONE;
1765 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1766 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1772 int media_info_get_size(media_info_h media, unsigned long long *size)
1774 int ret = MEDIA_CONTENT_ERROR_NONE;
1775 media_info_s *_media = (media_info_s*)media;
1779 *size = _media->size;
1780 ret = MEDIA_CONTENT_ERROR_NONE;
1784 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1785 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1791 int media_info_get_added_time(media_info_h media, time_t *added_time)
1793 int ret = MEDIA_CONTENT_ERROR_NONE;
1794 media_info_s *_media = (media_info_s*)media;
1795 if(_media && added_time)
1797 *added_time = _media->added_time;
1798 ret = MEDIA_CONTENT_ERROR_NONE;
1802 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1803 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1809 int media_info_get_modified_time(media_info_h media, time_t* time)
1811 int ret = MEDIA_CONTENT_ERROR_NONE;
1812 media_info_s *_media = (media_info_s*)media;
1815 *time = _media->modified_time;
1816 ret = MEDIA_CONTENT_ERROR_NONE;
1820 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1821 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1827 int media_info_get_timeline(media_info_h media, time_t* time)
1829 int ret = MEDIA_CONTENT_ERROR_NONE;
1830 media_info_s *_media = (media_info_s*)media;
1833 *time = _media->timeline;
1834 ret = MEDIA_CONTENT_ERROR_NONE;
1838 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1839 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1845 int media_info_get_thumbnail_path(media_info_h media, char **path)
1847 int ret = MEDIA_CONTENT_ERROR_NONE;
1848 media_info_s *_media = (media_info_s*)media;
1851 if(STRING_VALID(_media->thumbnail_path))
1853 *path = strdup(_media->thumbnail_path);
1854 media_content_retvm_if(*path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1860 ret = MEDIA_CONTENT_ERROR_NONE;
1865 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1866 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1872 int media_info_get_title(media_info_h media, char **title)
1874 int ret = MEDIA_CONTENT_ERROR_NONE;
1875 media_info_s *_media = (media_info_s*)media;
1879 if(STRING_VALID(_media->title))
1881 *title = strdup(_media->title);
1882 media_content_retvm_if(*title == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1888 ret = MEDIA_CONTENT_ERROR_NONE;
1892 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1893 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1899 int media_info_get_description(media_info_h media, char **description)
1901 int ret = MEDIA_CONTENT_ERROR_NONE;
1902 media_info_s *_media = (media_info_s*)media;
1904 if(_media && description)
1906 if(STRING_VALID(_media->description))
1908 *description = strdup(_media->description);
1909 media_content_retvm_if(*description == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1913 *description = NULL;
1915 ret = MEDIA_CONTENT_ERROR_NONE;
1919 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1920 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1926 int media_info_get_longitude(media_info_h media, double* longitude)
1928 int ret = MEDIA_CONTENT_ERROR_NONE;
1929 media_info_s *_media = (media_info_s*)media;
1931 if(_media && longitude)
1933 *longitude = _media->longitude;
1934 ret = MEDIA_CONTENT_ERROR_NONE;
1938 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1939 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1944 int media_info_get_latitude(media_info_h media, double* latitude)
1946 int ret = MEDIA_CONTENT_ERROR_NONE;
1947 media_info_s *_media = (media_info_s*)media;
1949 if(_media && latitude)
1951 *latitude = _media->latitude;
1952 ret = MEDIA_CONTENT_ERROR_NONE;
1956 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1957 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1963 int media_info_get_altitude(media_info_h media, double *altitude)
1965 int ret = MEDIA_CONTENT_ERROR_NONE;
1966 media_info_s *_media = (media_info_s*)media;
1968 if(_media && altitude)
1970 *altitude = _media->altitude;
1971 ret = MEDIA_CONTENT_ERROR_NONE;
1975 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1976 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1982 int media_info_get_weather(media_info_h media, char **weather)
1984 int ret = MEDIA_CONTENT_ERROR_NONE;
1985 media_info_s *_media = (media_info_s*)media;
1987 if(_media && weather)
1989 if(STRING_VALID(_media->weather))
1991 *weather = strdup(_media->weather);
1992 media_content_retvm_if(*weather == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1998 ret = MEDIA_CONTENT_ERROR_NONE;
2002 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2003 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2009 int media_info_get_rating(media_info_h media, int *rating)
2011 int ret = MEDIA_CONTENT_ERROR_NONE;
2012 media_info_s *_media = (media_info_s*)media;
2014 if(_media && rating)
2016 *rating = _media->rating;
2017 ret = MEDIA_CONTENT_ERROR_NONE;
2021 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2022 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2028 int media_info_get_favorite(media_info_h media, bool* favorite)
2030 int ret = MEDIA_CONTENT_ERROR_NONE;
2031 media_info_s *_media = (media_info_s*)media;
2033 if(_media && favorite)
2036 *favorite = _media->favourite;
2037 ret = MEDIA_CONTENT_ERROR_NONE;
2041 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2042 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2048 int media_info_get_author(media_info_h media, char **author)
2050 int ret = MEDIA_CONTENT_ERROR_NONE;
2051 media_info_s *_media = (media_info_s*)media;
2053 if(_media && author)
2055 if(STRING_VALID(_media->author))
2057 *author = strdup(_media->author);
2058 media_content_retvm_if(*author == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2064 ret = MEDIA_CONTENT_ERROR_NONE;
2068 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2069 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2075 int media_info_get_provider(media_info_h media, char **provider)
2077 int ret = MEDIA_CONTENT_ERROR_NONE;
2078 media_info_s *_media = (media_info_s*)media;
2080 if(_media && provider)
2082 if(STRING_VALID(_media->provider))
2084 *provider = strdup(_media->provider);
2085 media_content_retvm_if(*provider == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2091 ret = MEDIA_CONTENT_ERROR_NONE;
2095 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2096 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2102 int media_info_get_content_name(media_info_h media, char **content_name)
2104 int ret = MEDIA_CONTENT_ERROR_NONE;
2105 media_info_s *_media = (media_info_s*)media;
2107 if(_media && content_name)
2109 if(STRING_VALID(_media->content_name))
2111 *content_name = strdup(_media->content_name);
2112 media_content_retvm_if(*content_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2116 *content_name = NULL;
2118 ret = MEDIA_CONTENT_ERROR_NONE;
2122 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2123 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2129 int media_info_get_category(media_info_h media, char **category)
2131 int ret = MEDIA_CONTENT_ERROR_NONE;
2132 media_info_s *_media = (media_info_s*)media;
2134 if(_media && category)
2136 if(STRING_VALID(_media->category))
2138 *category = strdup(_media->category);
2139 media_content_retvm_if(*category == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2145 ret = MEDIA_CONTENT_ERROR_NONE;
2149 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2150 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2156 int media_info_get_location_tag(media_info_h media, char **location_tag)
2158 int ret = MEDIA_CONTENT_ERROR_NONE;
2159 media_info_s *_media = (media_info_s*)media;
2161 if(_media && location_tag)
2163 if(STRING_VALID(_media->location_tag))
2165 *location_tag = strdup(_media->location_tag);
2166 media_content_retvm_if(*location_tag == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2170 *location_tag = NULL;
2172 ret = MEDIA_CONTENT_ERROR_NONE;
2176 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2177 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2183 int media_info_get_age_rating(media_info_h media, char **age_rating)
2185 int ret = MEDIA_CONTENT_ERROR_NONE;
2186 media_info_s *_media = (media_info_s*)media;
2188 if(_media && age_rating)
2190 if(STRING_VALID(_media->age_rating))
2192 *age_rating = strdup(_media->age_rating);
2193 media_content_retvm_if(*age_rating == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2199 ret = MEDIA_CONTENT_ERROR_NONE;
2203 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2204 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2210 int media_info_get_keyword(media_info_h media, char **keyword)
2212 int ret = MEDIA_CONTENT_ERROR_NONE;
2213 media_info_s *_media = (media_info_s*)media;
2215 if(_media && keyword)
2217 if(STRING_VALID(_media->keyword))
2219 *keyword = strdup(_media->keyword);
2220 media_content_retvm_if(*keyword == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2226 ret = MEDIA_CONTENT_ERROR_NONE;
2230 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2231 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2237 int media_info_get_storage_id(media_info_h media, char **storage_id)
2239 int ret = MEDIA_CONTENT_ERROR_NONE;
2240 media_info_s *_media = (media_info_s*)media;
2242 if(_media && storage_id)
2244 if(STRING_VALID(_media->storage_uuid))
2246 *storage_id = strdup(_media->storage_uuid);
2247 media_content_retvm_if(*storage_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2253 ret = MEDIA_CONTENT_ERROR_NONE;
2257 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2258 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2264 int media_info_is_drm(media_info_h media, bool *is_drm)
2266 int ret = MEDIA_CONTENT_ERROR_NONE;
2267 media_info_s *_media = (media_info_s*)media;
2271 *is_drm = _media->is_drm;
2272 ret = MEDIA_CONTENT_ERROR_NONE;
2276 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2277 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2283 int media_info_get_storage_type(media_info_h media, media_content_storage_e *storage_type)
2285 int ret = MEDIA_CONTENT_ERROR_NONE;
2286 media_info_s *_media = (media_info_s*)media;
2288 if(_media && storage_type)
2290 *storage_type = _media->storage_type;
2291 ret = MEDIA_CONTENT_ERROR_NONE;
2295 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2296 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2302 int media_info_get_played_count(media_info_h media, int *played_count)
2304 int ret = MEDIA_CONTENT_ERROR_NONE;
2305 media_info_s *_media = (media_info_s*)media;
2309 *played_count = _media->played_count;
2310 ret = MEDIA_CONTENT_ERROR_NONE;
2314 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2315 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2321 int media_info_get_played_time(media_info_h media, time_t* played_time)
2323 int ret = MEDIA_CONTENT_ERROR_NONE;
2324 media_info_s *_media = (media_info_s*)media;
2328 *played_time = _media->played_time;
2329 ret = MEDIA_CONTENT_ERROR_NONE;
2333 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2334 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2340 int media_info_increase_played_count(media_info_h media)
2342 int ret = MEDIA_CONTENT_ERROR_NONE;
2344 media_info_s *_media = (media_info_s*)media;
2348 _media->played_count += 1;
2352 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2353 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2359 int media_info_set_played_time(media_info_h media)
2361 int ret = MEDIA_CONTENT_ERROR_NONE;
2362 time_t current_time;
2364 media_info_s *_media = (media_info_s*)media;
2368 time(¤t_time);
2369 _media->played_time = current_time;
2373 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2374 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2380 int media_info_get_media_from_db(const char *media_id, media_info_h *media)
2382 int ret = MEDIA_CONTENT_ERROR_NONE;
2383 char select_query[DEFAULT_QUERY_SIZE];
2384 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
2385 sqlite3_stmt *stmt = NULL;
2387 if(!STRING_VALID(media_id) || (media == NULL))
2389 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2390 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2393 memset(select_query, 0x00, sizeof(select_query));
2394 memset(storage_id, 0x00, sizeof(storage_id));
2396 ret = _media_db_get_storage_id_by_media_id(media_id, storage_id);
2397 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
2399 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_MEDIA, storage_id, media_id);
2401 ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
2402 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
2404 media_info_s *_media = NULL;
2406 while(sqlite3_step(stmt) == SQLITE_ROW)
2409 media_info_destroy((media_info_h)_media);
2411 _media = (media_info_s*)calloc(1, sizeof(media_info_s));
2415 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2416 SQLITE3_FINALIZE(stmt);
2417 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2420 _media_info_item_get_detail(stmt, (media_info_h)_media);
2422 *media = (media_info_h)_media;
2425 SQLITE3_FINALIZE(stmt);
2430 int media_info_set_display_name(media_info_h media, const char *display_name)
2432 int ret = MEDIA_CONTENT_ERROR_NONE;
2433 media_info_s *_media = (media_info_s*)media;
2435 if(_media != NULL && STRING_VALID(display_name))
2437 SAFE_FREE(_media->display_name);
2439 _media->display_name = strdup(display_name);
2440 media_content_retvm_if(_media->display_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2444 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2445 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2451 int media_info_set_description(media_info_h media, const char *description)
2453 int ret = MEDIA_CONTENT_ERROR_NONE;
2454 media_info_s *_media = (media_info_s*)media;
2458 SAFE_FREE(_media->description);
2460 if(STRING_VALID(description))
2462 _media->description = strdup(description);
2463 media_content_retvm_if(_media->description == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2467 _media->description = NULL;
2472 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2473 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2479 int media_info_set_longitude(media_info_h media, double longitude)
2481 int ret = MEDIA_CONTENT_ERROR_NONE;
2482 media_info_s *_media = (media_info_s*)media;
2486 _media->longitude = longitude;
2490 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2491 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2497 int media_info_set_latitude(media_info_h media, double latitude)
2499 int ret = MEDIA_CONTENT_ERROR_NONE;
2500 media_info_s *_media = (media_info_s*)media;
2504 _media->latitude = latitude;
2508 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2509 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2515 int media_info_set_altitude(media_info_h media, double altitude)
2517 int ret = MEDIA_CONTENT_ERROR_NONE;
2518 media_info_s *_media = (media_info_s*)media;
2522 _media->altitude = altitude;
2526 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2527 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2533 int media_info_set_weather(media_info_h media, const char *weather)
2535 int ret = MEDIA_CONTENT_ERROR_NONE;
2536 media_info_s *_media = (media_info_s*)media;
2540 SAFE_FREE(_media->weather);
2542 if(STRING_VALID(weather))
2544 _media->weather = strdup(weather);
2545 media_content_retvm_if(_media->weather == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2549 _media->weather = NULL;
2554 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2555 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2561 int media_info_set_rating(media_info_h media, int rating)
2563 int ret = MEDIA_CONTENT_ERROR_NONE;
2564 media_info_s *_media = (media_info_s*)media;
2568 _media->rating = rating;
2572 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2573 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2579 int media_info_set_added_time(media_info_h media, time_t added_time)
2581 int ret = MEDIA_CONTENT_ERROR_NONE;
2583 media_info_s *_media = (media_info_s*)media;
2585 if((_media != NULL) && (added_time >= 0))
2587 _media->added_time = added_time;
2591 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2592 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2598 int media_info_set_favorite(media_info_h media, bool favorite)
2600 int ret = MEDIA_CONTENT_ERROR_NONE;
2601 media_info_s *_media = (media_info_s*)media;
2605 if(favorite == TRUE)
2607 time(&_media->favourite);
2611 _media->favourite = 0;
2616 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2617 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2623 int media_info_set_author(media_info_h media, const char *author)
2625 int ret = MEDIA_CONTENT_ERROR_NONE;
2626 media_info_s *_media = (media_info_s*)media;
2630 if(STRING_VALID(author))
2632 _media->author = strdup(author);
2633 media_content_retvm_if(_media->author == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2637 _media->author = NULL;
2642 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2643 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2649 int media_info_set_provider(media_info_h media, const char *provider)
2651 int ret = MEDIA_CONTENT_ERROR_NONE;
2652 media_info_s *_media = (media_info_s*)media;
2656 SAFE_FREE(_media->provider);
2658 if(STRING_VALID(provider))
2660 _media->provider = strdup(provider);
2661 media_content_retvm_if(_media->provider == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2665 _media->provider = NULL;
2670 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2671 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2677 int media_info_set_content_name(media_info_h media, const char *content_name)
2679 int ret = MEDIA_CONTENT_ERROR_NONE;
2680 media_info_s *_media = (media_info_s*)media;
2684 SAFE_FREE(_media->content_name);
2686 if(STRING_VALID(content_name))
2688 _media->content_name = strdup(content_name);
2689 media_content_retvm_if(_media->content_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2693 _media->content_name = NULL;
2698 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2699 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2705 int media_info_set_category(media_info_h media, const char *category)
2707 int ret = MEDIA_CONTENT_ERROR_NONE;
2708 media_info_s *_media = (media_info_s*)media;
2712 SAFE_FREE(_media->category);
2714 if(STRING_VALID(category))
2716 _media->category = strdup(category);
2717 media_content_retvm_if(_media->category == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2721 _media->category = NULL;
2726 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2727 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2733 int media_info_set_location_tag(media_info_h media, const char *location_tag)
2735 int ret = MEDIA_CONTENT_ERROR_NONE;
2736 media_info_s *_media = (media_info_s*)media;
2740 SAFE_FREE(_media->location_tag);
2742 if(STRING_VALID(location_tag))
2744 _media->location_tag = strdup(location_tag);
2745 media_content_retvm_if(_media->location_tag == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2749 _media->location_tag = NULL;
2754 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2755 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2761 int media_info_set_age_rating(media_info_h media, const char *age_rating)
2763 int ret = MEDIA_CONTENT_ERROR_NONE;
2764 media_info_s *_media = (media_info_s*)media;
2768 SAFE_FREE(_media->age_rating);
2770 if(STRING_VALID(age_rating))
2772 _media->age_rating = strdup(age_rating);
2773 media_content_retvm_if(_media->age_rating == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2777 _media->age_rating = NULL;
2782 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2783 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2789 int media_info_set_keyword(media_info_h media, const char *keyword)
2791 int ret = MEDIA_CONTENT_ERROR_NONE;
2792 media_info_s *_media = (media_info_s*)media;
2796 SAFE_FREE(_media->keyword);
2798 if(STRING_VALID(keyword))
2800 _media->keyword = strdup(keyword);
2801 media_content_retvm_if(_media->keyword == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2805 _media->keyword = NULL;
2810 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2811 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2817 int media_info_update_to_db(media_info_h media)
2819 int ret = MEDIA_CONTENT_ERROR_NONE;
2820 media_info_s *_media = (media_info_s*)media;
2821 char *set_sql = NULL;
2824 if(_media != NULL && STRING_VALID(_media->media_id))
2826 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
2827 /* This code will be removed when sqlite3_mprintf works clearly */
2828 char *test_sql = sqlite3_mprintf("%f, %f, %f", _media->longitude, _media->latitude, _media->altitude);
2829 SQLITE3_SAFE_FREE(test_sql);
2831 /*Update Pinyin If Support Pinyin*/
2832 char *file_name_pinyin = NULL;
2833 char *description_pinyin = NULL;
2834 char *author_pinyin = NULL;
2835 char *provider_pinyin = NULL;
2836 char *content_name_pinyin = NULL;
2837 char *category_pinyin = NULL;
2838 char *location_tag_pinyin = NULL;
2839 char *age_rating_pinyin = NULL;
2840 char *keyword_pinyin = NULL;
2841 bool pinyin_support = FALSE;
2843 /*Update Pinyin If Support Pinyin*/
2844 media_svc_check_pinyin_support(&pinyin_support);
2847 if(STRING_VALID(_media->display_name))
2848 media_svc_get_pinyin(_content_get_db_handle(), _media->display_name, &file_name_pinyin);
2849 if(STRING_VALID(_media->description))
2850 media_svc_get_pinyin(_content_get_db_handle(), _media->description, &description_pinyin);
2851 if(STRING_VALID(_media->author))
2852 media_svc_get_pinyin(_content_get_db_handle(), _media->author, &author_pinyin);
2853 if(STRING_VALID(_media->provider))
2854 media_svc_get_pinyin(_content_get_db_handle(), _media->provider, &provider_pinyin);
2855 if(STRING_VALID(_media->content_name))
2856 media_svc_get_pinyin(_content_get_db_handle(), _media->content_name, &content_name_pinyin);
2857 if(STRING_VALID(_media->category))
2858 media_svc_get_pinyin(_content_get_db_handle(), _media->category, &category_pinyin);
2859 if(STRING_VALID(_media->location_tag))
2860 media_svc_get_pinyin(_content_get_db_handle(), _media->location_tag, &location_tag_pinyin);
2861 if(STRING_VALID(_media->age_rating))
2862 media_svc_get_pinyin(_content_get_db_handle(), _media->age_rating, &age_rating_pinyin);
2863 if(STRING_VALID(_media->keyword))
2864 media_svc_get_pinyin(_content_get_db_handle(), _media->keyword, &keyword_pinyin);
2867 set_sql = sqlite3_mprintf("file_name=%Q, added_time=%d, description=%Q, longitude=%f, latitude=%f, altitude=%f, \
2868 played_count=%d, last_played_time=%d, last_played_position=%d, \
2869 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, \
2870 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",
2871 _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,
2872 _media->author, _media->provider, _media->content_name, _media->category, _media->location_tag, _media->age_rating, _media->keyword, _media->weather, _media->sync_status,
2873 file_name_pinyin, description_pinyin, author_pinyin, provider_pinyin, content_name_pinyin, category_pinyin, location_tag_pinyin, age_rating_pinyin, keyword_pinyin, _media->title);
2875 sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE media_uuid=%Q", _media->storage_uuid, set_sql, _media->media_id);
2877 ret = _content_query_sql(sql);
2878 SQLITE3_SAFE_FREE(set_sql);
2879 SQLITE3_SAFE_FREE(sql);
2881 SAFE_FREE(description_pinyin);
2882 SAFE_FREE(author_pinyin);
2883 SAFE_FREE(provider_pinyin);
2884 SAFE_FREE(content_name_pinyin);
2885 SAFE_FREE(category_pinyin);
2886 SAFE_FREE(location_tag_pinyin);
2887 SAFE_FREE(age_rating_pinyin);
2888 SAFE_FREE(keyword_pinyin);
2890 if(_media->storage_type == MEDIA_CONTENT_STORAGE_CLOUD)
2895 if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
2897 set_sql = sqlite3_mprintf("title=%Q, album=%Q, artist=%Q, genre=%Q, duration=%d, width=%d, height=%d", \
2898 _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);
2900 else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
2902 set_sql = sqlite3_mprintf("title=%Q, album=%Q, artist=%Q, genre=%Q, duration=%d", \
2903 _media->title, _media->audio_meta->album, _media->audio_meta->artist, _media->audio_meta->genre, _media->audio_meta->duration);
2905 else if(_media->media_type == MEDIA_CONTENT_TYPE_IMAGE)
2907 set_sql = sqlite3_mprintf("title=%Q, width=%d, height=%d", _media->title, _media->image_meta->width, _media->image_meta->height);
2911 set_sql = sqlite3_mprintf("title=%Q", _media->title);
2914 sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE media_uuid=%Q", _media->storage_uuid, set_sql, _media->media_id);
2916 ret = _content_query_sql(sql);
2918 SQLITE3_SAFE_FREE(set_sql);
2919 SQLITE3_SAFE_FREE(sql);
2922 if (ret == MEDIA_CONTENT_ERROR_NONE) {
2923 /* Send notification for this update */
2924 media_content_debug("Update is successfull. Send notification for this");
2925 if (_media->file_path && _media->mime_type) {
2926 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);
2928 media_content_error("Can't Send Noti : path or mime type is NULL");
2934 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2935 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2941 int media_info_refresh_metadata_to_db(const char *media_id)
2943 int ret = MEDIA_CONTENT_ERROR_NONE;
2944 media_info_h media = NULL;
2945 char *file_path = NULL;
2946 media_content_storage_e storage_type = 0;
2947 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
2949 if(!STRING_VALID(media_id))
2951 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2952 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2955 ret = media_info_get_media_from_db(media_id, &media);
2956 if(ret != MEDIA_CONTENT_ERROR_NONE)
2958 media_info_destroy(media);
2962 ret = media_info_get_storage_type(media, &storage_type);
2963 if(ret != MEDIA_CONTENT_ERROR_NONE)
2965 media_info_destroy(media);
2969 if(storage_type == MEDIA_CONTENT_STORAGE_CLOUD)
2971 media_info_destroy(media);
2972 media_content_error("Can't refresh cloud content!!");
2973 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2976 ret = media_info_get_file_path(media, &file_path);
2977 if(ret != MEDIA_CONTENT_ERROR_NONE)
2979 media_info_destroy(media);
2983 ret = _media_util_check_file_exist(file_path);
2984 if (ret != MEDIA_CONTENT_ERROR_NONE) {
2985 SAFE_FREE(file_path);
2986 media_info_destroy(media);
2990 memset(storage_id, 0x00, sizeof(storage_id));
2991 ret = media_svc_get_storage_id(_content_get_db_handle(), file_path, storage_id);
2992 if(ret != MS_MEDIA_ERR_NONE)
2994 media_content_error("media_svc_get_storage_id failed : %d", ret);
2995 SAFE_FREE(file_path);
2996 media_info_destroy(media);
2997 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3000 ret = media_svc_refresh_item(_content_get_db_handle(), storage_id, storage_type, file_path, tzplatform_getuid(TZ_USER_NAME));
3001 if (ret != MS_MEDIA_ERR_NONE)
3003 ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3006 SAFE_FREE(file_path);
3007 media_info_destroy(media);
3012 int media_info_move_to_db(media_info_h media, const char* dst_path)
3014 int ret = MEDIA_CONTENT_ERROR_NONE;
3015 bool ignore_file = FALSE;
3016 bool ignore_dir = FALSE;
3017 char *folder_path = NULL;
3018 media_svc_storage_type_e src_storage_type = 0;
3019 media_svc_storage_type_e dst_storage_type = 0;
3020 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
3022 media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media");
3023 media_content_retvm_if(!STRING_VALID(dst_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid dst_path");
3025 media_info_s *_media = (media_info_s*)media;
3027 ret = _media_util_check_ignore_file(dst_path, &ignore_file);
3028 media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
3030 ret = _media_util_check_file_exist(dst_path);
3031 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
3033 folder_path = g_path_get_dirname(dst_path);
3034 ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
3035 SAFE_FREE(folder_path);
3037 media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
3039 ret = media_svc_get_storage_type(_media->file_path, &src_storage_type, tzplatform_getuid(TZ_USER_NAME));
3040 if(ret != MS_MEDIA_ERR_NONE)
3042 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
3043 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3046 ret = media_svc_get_storage_type(dst_path, &dst_storage_type, tzplatform_getuid(TZ_USER_NAME));
3047 if(ret != MS_MEDIA_ERR_NONE)
3049 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
3050 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3053 memset(storage_id, 0x00, sizeof(storage_id));
3054 ret = media_svc_get_storage_id(_content_get_db_handle(), _media->file_path, storage_id);
3055 if(ret != MS_MEDIA_ERR_NONE)
3057 media_content_error("media_svc_get_storage_id failed : %d", ret);
3058 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3061 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));
3062 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3065 int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data)
3067 int ret = MEDIA_CONTENT_ERROR_NONE;
3068 media_info_s *_media = (media_info_s*)media;
3070 if(_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path))
3072 media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s*)calloc(1, sizeof(media_thumbnail_cb_s));
3073 media_content_retvm_if(_thumb_cb == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3075 _thumb_cb->handle = _media;
3076 _thumb_cb->user_data = user_data;
3077 _thumb_cb->thumbnail_completed_cb = callback;
3079 ret = thumbnail_request_from_db_async(_media->file_path, (ThumbFunc)__media_info_thumbnail_completed_cb, (void *)_thumb_cb, tzplatform_getuid(TZ_USER_NAME));
3080 ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret);
3084 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3085 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3091 int media_info_cancel_thumbnail(media_info_h media)
3093 int ret = MEDIA_CONTENT_ERROR_NONE;
3094 media_info_s *_media = (media_info_s*)media;
3096 if(_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path))
3098 ret = thumbnail_request_cancel_media(_media->file_path);
3099 ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret);
3103 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3104 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3110 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)
3112 media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
3114 media_svc_content_info_s *svc_content_info = calloc(1, sizeof(media_svc_content_info_s));
3115 media_content_retvm_if(svc_content_info == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3117 svc_content_info->path = g_strdup(media->file_path);
3118 svc_content_info->media_type = media->media_type;
3119 svc_content_info->mime_type = g_strdup(media->mime_type);
3120 svc_content_info->size = media->size;
3121 svc_content_info->storage_type = storage_type;
3122 svc_content_info->storage_uuid = g_strdup(media->storage_uuid);
3124 svc_content_info->added_time = media->added_time;
3125 svc_content_info->modified_time = media->modified_time;
3126 svc_content_info->thumbnail_path = g_strdup(media->thumbnail_path);
3127 svc_content_info->is_drm = media->is_drm;
3129 svc_content_info->media_meta.title = g_strdup(media->title);
3130 svc_content_info->media_meta.rating = media->rating;
3131 svc_content_info->media_meta.description = g_strdup(media->description);
3132 svc_content_info->media_meta.longitude = media->longitude;
3133 svc_content_info->media_meta.latitude = media->latitude;
3134 svc_content_info->media_meta.altitude = media->altitude;
3135 svc_content_info->media_meta.weather = g_strdup(media->weather);
3137 svc_content_info->media_meta.album = g_strdup(media->audio_meta->album);
3138 svc_content_info->media_meta.artist = g_strdup(media->audio_meta->artist);
3139 svc_content_info->media_meta.genre = g_strdup(media->audio_meta->genre);
3140 svc_content_info->media_meta.recorded_date = g_strdup(media->audio_meta->recorded_date);
3142 if(storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
3143 switch(media->media_type)
3145 case MEDIA_CONTENT_TYPE_IMAGE:
3146 svc_content_info->media_meta.width = media->image_meta->width;
3147 svc_content_info->media_meta.height = media->image_meta->height;
3148 svc_content_info->media_meta.datetaken = g_strdup(media->image_meta->date_taken);
3149 svc_content_info->media_meta.orientation = media->image_meta->orientation;
3151 case MEDIA_CONTENT_TYPE_VIDEO:
3152 svc_content_info->media_meta.album_artist = g_strdup(media->audio_meta->album_artist);
3153 svc_content_info->media_meta.composer = g_strdup(media->audio_meta->composer);
3154 svc_content_info->media_meta.year = g_strdup(media->audio_meta->year);
3155 svc_content_info->media_meta.copyright = g_strdup(media->audio_meta->copyright);
3156 svc_content_info->media_meta.track_num = g_strdup(media->audio_meta->track_num);
3157 svc_content_info->media_meta.bitrate = media->audio_meta->bitrate;
3158 svc_content_info->media_meta.duration = media->audio_meta->duration;
3159 svc_content_info->media_meta.width = media->image_meta->width;
3160 svc_content_info->media_meta.height = media->image_meta->height;
3162 case MEDIA_CONTENT_TYPE_SOUND:
3163 case MEDIA_CONTENT_TYPE_MUSIC:
3164 svc_content_info->media_meta.album_artist = g_strdup(media->audio_meta->album_artist);
3165 svc_content_info->media_meta.composer = g_strdup(media->audio_meta->composer);
3166 svc_content_info->media_meta.year = g_strdup(media->audio_meta->year);
3167 svc_content_info->media_meta.copyright = g_strdup(media->audio_meta->copyright);
3168 svc_content_info->media_meta.track_num = g_strdup(media->audio_meta->track_num);
3169 svc_content_info->media_meta.bitrate = media->audio_meta->bitrate;
3170 svc_content_info->media_meta.duration = media->audio_meta->duration;
3171 svc_content_info->media_meta.channel = media->audio_meta->channel;
3172 svc_content_info->media_meta.samplerate = media->audio_meta->samplerate;
3174 case MEDIA_CONTENT_TYPE_OTHERS:
3180 *service_content = svc_content_info;
3182 return MEDIA_CONTENT_ERROR_NONE;
3185 static int __media_info_set_str_data(media_info_h media, media_info_item_e data_type, const char *str_data)
3187 media_info_s *_media = (media_info_s*)media;
3189 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3193 case MEDIA_INFO_PATH:
3194 SAFE_FREE(_media->file_path);
3195 if(STRING_VALID(str_data))
3197 _media->file_path = strdup(str_data);
3198 media_content_retvm_if(_media->file_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3202 _media->file_path = NULL;
3205 case MEDIA_INFO_MIME_TYPE:
3206 SAFE_FREE(_media->mime_type);
3207 if(STRING_VALID(str_data))
3209 _media->mime_type = strdup(str_data);
3210 media_content_retvm_if(_media->mime_type == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3214 _media->mime_type = NULL;
3217 case MEDIA_INFO_THUMBNAIL_PATH:
3218 SAFE_FREE(_media->thumbnail_path);
3219 if(STRING_VALID(str_data))
3221 _media->thumbnail_path = strdup(str_data);
3222 media_content_retvm_if(_media->thumbnail_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3226 _media->thumbnail_path = NULL;
3229 case MEDIA_INFO_TITLE:
3230 SAFE_FREE(_media->title);
3231 if(STRING_VALID(str_data))
3233 _media->title = strdup(str_data);
3234 media_content_retvm_if(_media->title == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3238 _media->title = NULL;
3241 case MEDIA_INFO_STORAGE_UUID:
3242 SAFE_FREE(_media->storage_uuid);
3243 if(STRING_VALID(str_data))
3245 _media->storage_uuid = strdup(str_data);
3246 media_content_retvm_if(_media->storage_uuid == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3250 _media->storage_uuid = NULL;
3253 case MEDIA_INFO_ALBUM:
3254 //if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3256 SAFE_FREE(_media->video_meta->album);
3257 if(STRING_VALID(str_data))
3259 _media->video_meta->album = strdup(str_data);
3260 media_content_retvm_if(_media->video_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3264 _media->video_meta->album = NULL;
3267 //else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
3269 SAFE_FREE(_media->audio_meta->album);
3270 if(STRING_VALID(str_data))
3272 _media->audio_meta->album = strdup(str_data);
3273 media_content_retvm_if(_media->audio_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3277 _media->audio_meta->album = NULL;
3281 case MEDIA_INFO_ARTIST:
3282 //if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3284 SAFE_FREE(_media->video_meta->artist);
3285 if(STRING_VALID(str_data))
3287 _media->video_meta->artist = strdup(str_data);
3288 media_content_retvm_if(_media->video_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3292 _media->video_meta->artist = NULL;
3295 //else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
3297 SAFE_FREE(_media->audio_meta->artist);
3298 if(STRING_VALID(str_data))
3300 _media->audio_meta->artist = strdup(str_data);
3301 media_content_retvm_if(_media->audio_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3305 _media->audio_meta->artist = NULL;
3309 case MEDIA_INFO_GENRE:
3310 //if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3312 SAFE_FREE(_media->video_meta->genre);
3313 if(STRING_VALID(str_data))
3315 _media->video_meta->genre = strdup(str_data);
3316 media_content_retvm_if(_media->video_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3320 _media->video_meta->genre = NULL;
3323 //else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
3325 SAFE_FREE(_media->audio_meta->genre);
3326 if(STRING_VALID(str_data))
3328 _media->audio_meta->genre = strdup(str_data);
3329 media_content_retvm_if(_media->audio_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3333 _media->audio_meta->genre = NULL;
3337 case MEDIA_INFO_RECORDED_DATE:
3338 //if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3340 SAFE_FREE(_media->video_meta->recorded_date);
3341 if(STRING_VALID(str_data))
3343 _media->video_meta->recorded_date = strdup(str_data);
3344 media_content_retvm_if(_media->video_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3348 _media->video_meta->recorded_date = NULL;
3351 //else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
3353 SAFE_FREE(_media->audio_meta->recorded_date);
3354 if(STRING_VALID(str_data))
3356 _media->audio_meta->recorded_date = strdup(str_data);
3357 media_content_retvm_if(_media->audio_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3361 _media->audio_meta->recorded_date = NULL;
3366 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3367 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3370 return MEDIA_CONTENT_ERROR_NONE;
3373 int media_info_insert_to_db_with_data(media_info_h media, media_info_h *info)
3375 int ret = MEDIA_CONTENT_ERROR_NONE;
3377 media_info_s *_media = (media_info_s*)media;
3379 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3380 media_content_retvm_if(!STRING_VALID(_media->file_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid file_path");
3381 media_content_retvm_if(!STRING_VALID(_media->storage_uuid), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid storage_uuid");
3382 media_content_retvm_if(_media->storage_type < 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid storage_type [%d]", _media->storage_type);
3384 /* Cloud Item should be filled whole info*/
3385 if (_media->storage_type == MEDIA_CONTENT_STORAGE_CLOUD) {
3386 media_content_retvm_if(!STRING_VALID(_media->mime_type), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid mime_type");
3387 media_content_retvm_if(!STRING_VALID(_media->title), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid title");
3388 media_content_retvm_if(_media->size <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid size [%d]", _media->size);
3389 media_content_retvm_if(_media->modified_time <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid modified_time [%d]", _media->modified_time);
3391 if ((_media->media_type < MEDIA_CONTENT_TYPE_IMAGE) || (_media->media_type > MEDIA_CONTENT_TYPE_OTHERS))
3393 media_content_error("invalid media type [%d]", _media->media_type);
3394 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3398 media_content_sec_debug("storage[%d], path[%s], media_type[%d]", _media->storage_type, _media->file_path, _media->media_type);
3400 media_svc_content_info_s *svc_content_info = NULL;
3402 ret = __media_info_map_data_usr_to_svc(_media, &svc_content_info, _media->storage_type);
3403 media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "__media_info_map_data_usr_to_svc fail");
3405 ret = media_svc_insert_item_immediately_with_data(_content_get_db_handle(), svc_content_info, tzplatform_getuid(TZ_USER_NAME));
3406 if(ret != MS_MEDIA_ERR_NONE) {
3407 media_content_sec_error("media_svc_insert_item_immediately_with_data failed : %d (%s)", ret, _media->file_path);
3408 media_svc_destroy_content_info(svc_content_info);
3409 SAFE_FREE(svc_content_info);
3410 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3412 /*free the svc_content_info*/
3413 media_svc_destroy_content_info(svc_content_info);
3414 SAFE_FREE(svc_content_info);
3418 media_info_s *_get_media = (media_info_s*)calloc(1, sizeof(media_info_s));
3419 media_content_retvm_if(_get_media == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3421 ret = _media_info_get_media_info_from_db(_media->file_path, _media->storage_uuid, (media_info_h)_get_media);
3423 *info = (media_info_h)_get_media;
3429 int media_info_create(const char *path, media_info_h *media)
3431 int ret = MEDIA_CONTENT_ERROR_NONE;
3432 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0, };
3433 media_svc_storage_type_e storage_type = 0;
3435 media_content_retvm_if(!STRING_VALID(path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
3436 media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3438 memset(storage_id, 0x00, sizeof(storage_id));
3440 if (strstr(MEDIA_ROOT_PATH_CLOUD, path) == NULL) {
3441 bool ignore_file = FALSE;
3442 bool ignore_dir = FALSE;
3443 char *folder_path = NULL;
3445 ret = _media_util_check_ignore_file(path, &ignore_file);
3446 media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
3448 ret = _media_util_check_file_exist(path);
3449 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
3451 folder_path = g_path_get_dirname(path);
3452 ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
3453 SAFE_FREE(folder_path);
3454 media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
3456 ret = media_svc_get_storage_id(_content_get_db_handle(), path, storage_id);
3457 if(ret != MS_MEDIA_ERR_NONE)
3459 media_content_error("media_svc_get_storage_id failed : %d", ret);
3460 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3463 ret = media_svc_get_storage_type(path, &storage_type, tzplatform_getuid(TZ_USER_NAME));
3464 if(ret != MS_MEDIA_ERR_NONE) {
3465 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
3466 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3470 media_info_s *_media = (media_info_s*)calloc(1,sizeof(media_info_s));
3471 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3473 _media->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
3474 if(_media->audio_meta == NULL)
3477 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
3478 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
3481 _media->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
3482 if(_media->video_meta == NULL)
3484 SAFE_FREE(_media->audio_meta);
3486 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
3487 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
3490 _media->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
3491 if(_media->image_meta == NULL)
3493 SAFE_FREE(_media->audio_meta);
3494 SAFE_FREE(_media->video_meta);
3496 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
3497 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
3500 _media->file_path = g_strdup(path);
3501 _media->storage_type = -1;
3502 _media->media_type = -1;
3503 _media->modified_time = -1;
3506 if(STRING_VALID(storage_id)) {
3507 _media->storage_uuid = g_strdup(storage_id);
3508 _media->storage_type = storage_type;
3511 *media = (media_info_h)_media;
3516 int media_info_create_handle(media_info_h *media)
3518 int ret = MEDIA_CONTENT_ERROR_NONE;
3520 media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid handle");
3522 media_info_s *_media = (media_info_s*)calloc(1,sizeof(media_info_s));
3523 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3525 _media->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
3526 if(_media->audio_meta == NULL)
3529 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
3530 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
3533 _media->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
3534 if(_media->video_meta == NULL)
3536 SAFE_FREE(_media->audio_meta);
3538 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
3539 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
3542 _media->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
3543 if(_media->image_meta == NULL)
3545 SAFE_FREE(_media->audio_meta);
3546 SAFE_FREE(_media->video_meta);
3548 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
3549 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
3552 _media->storage_type = -1;
3553 _media->media_type = -1;
3554 _media->modified_time = -1;
3557 *media = (media_info_h)_media;
3562 int media_info_set_path(media_info_h media, const char *path)
3564 return __media_info_set_str_data(media, MEDIA_INFO_PATH, path);
3567 int media_info_set_mime_type(media_info_h media, const char *mime_type)
3569 return __media_info_set_str_data(media, MEDIA_INFO_MIME_TYPE, mime_type);
3572 int media_info_set_title(media_info_h media, const char *title)
3574 return __media_info_set_str_data(media, MEDIA_INFO_TITLE, title);
3577 int media_info_set_album(media_info_h media, const char *album)
3579 return __media_info_set_str_data(media, MEDIA_INFO_ALBUM, album);
3582 int media_info_set_artist(media_info_h media, const char *artist)
3584 return __media_info_set_str_data(media, MEDIA_INFO_ARTIST, artist);
3587 int media_info_set_genre(media_info_h media, const char *genre)
3589 return __media_info_set_str_data(media, MEDIA_INFO_GENRE, genre);
3592 int media_info_set_recorded_date(media_info_h media, const char *recorded_date)
3594 return __media_info_set_str_data(media, MEDIA_INFO_RECORDED_DATE, recorded_date);
3597 int media_info_set_thumbnail_path(media_info_h media, const char *thumbnail_path)
3599 return __media_info_set_str_data(media, MEDIA_INFO_THUMBNAIL_PATH, thumbnail_path);
3602 int media_info_set_storage_id(media_info_h media, const char *storage_id)
3604 return __media_info_set_str_data(media, MEDIA_INFO_STORAGE_UUID, storage_id);
3607 int media_info_set_size(media_info_h media, unsigned long long size)
3609 media_info_s *_media = (media_info_s*)media;
3611 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3613 _media->size = size;
3615 return MEDIA_CONTENT_ERROR_NONE;
3618 int media_info_set_modified_time(media_info_h media, time_t modified_time)
3620 media_info_s *_media = (media_info_s*)media;
3622 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3624 _media->modified_time = modified_time;
3626 return MEDIA_CONTENT_ERROR_NONE;
3629 int media_info_set_media_type(media_info_h media, media_content_type_e type)
3631 media_info_s *_media = (media_info_s*)media;
3633 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3635 _media->media_type = type;
3637 return MEDIA_CONTENT_ERROR_NONE;
3640 int media_info_set_duration(media_info_h media, int duration)
3642 media_info_s *_media = (media_info_s*)media;
3644 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3646 if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3647 _media->video_meta->duration = duration;
3648 else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
3649 _media->audio_meta->duration = duration;
3652 media_content_error("Invalid media type");
3653 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3656 return MEDIA_CONTENT_ERROR_NONE;
3659 int media_info_set_width(media_info_h media, int width)
3661 media_info_s *_media = (media_info_s*)media;
3663 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3665 if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3666 _media->video_meta->width = width;
3667 else if(_media->media_type == MEDIA_CONTENT_TYPE_IMAGE)
3668 _media->image_meta->width = width;
3671 media_content_error("Invalid media type");
3672 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3675 return MEDIA_CONTENT_ERROR_NONE;
3678 int media_info_set_height(media_info_h media, int height)
3680 media_info_s *_media = (media_info_s*)media;
3682 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3684 if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3685 _media->video_meta->height = height;
3686 else if(_media->media_type == MEDIA_CONTENT_TYPE_IMAGE)
3687 _media->image_meta->height = height;
3690 media_content_error("Invalid media type");
3691 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3694 return MEDIA_CONTENT_ERROR_NONE;
3697 int media_info_set_storage_type(media_info_h media, media_content_storage_e storage_type)
3699 media_info_s *_media = (media_info_s*)media;
3701 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3703 _media->storage_type = storage_type;
3705 return MEDIA_CONTENT_ERROR_NONE;