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_image(media_info_h media, image_meta_h *image)
1437 int ret = MEDIA_CONTENT_ERROR_NONE;
1439 media_info_s *_media = (media_info_s*)media;
1441 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
1442 media_content_retvm_if(_media->media_type != MEDIA_CONTENT_TYPE_IMAGE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_type");
1443 media_content_retvm_if(_media->image_meta == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid image_meta");
1445 image_meta_s *_image = (image_meta_s*)calloc(1, sizeof(image_meta_s));
1446 media_content_retvm_if(_image == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1448 if(STRING_VALID(_media->media_id)) {
1449 _image->media_id = strdup(_media->media_id);
1452 _image->width = _media->image_meta->width;
1453 _image->height = _media->image_meta->height;
1454 _image->orientation = _media->image_meta->orientation;
1455 _image->fnumber = _media->image_meta->fnumber;
1456 _image->iso = _media->image_meta->iso;
1458 if(STRING_VALID(_media->image_meta->date_taken)) {
1459 _image->date_taken = strdup(_media->image_meta->date_taken);
1462 if(STRING_VALID(_media->image_meta->title)) {
1463 _image->title = strdup(_media->image_meta->title);
1466 if(STRING_VALID(_media->image_meta->burst_id)) {
1467 _image->burst_id = strdup(_media->image_meta->burst_id);
1470 if(STRING_VALID(_media->image_meta->weather)) {
1471 _image->weather = strdup(_media->image_meta->weather);
1474 if(STRING_VALID(_media->image_meta->exposure_time)) {
1475 _image->exposure_time = strdup(_media->image_meta->exposure_time);
1478 if(STRING_VALID(_media->image_meta->model)) {
1479 _image->model = strdup(_media->image_meta->model);
1482 *image = (image_meta_h)_image;
1487 int media_info_get_video(media_info_h media, video_meta_h *video)
1489 int ret = MEDIA_CONTENT_ERROR_NONE;
1491 media_info_s *_media = (media_info_s*)media;
1493 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
1494 media_content_retvm_if(_media->media_type != MEDIA_CONTENT_TYPE_VIDEO, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media_type");
1495 media_content_retvm_if(_media->video_meta == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid video_meta");
1497 video_meta_s *_video = (video_meta_s*)calloc(1, sizeof(video_meta_s));
1498 media_content_retvm_if(_video == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1500 if(STRING_VALID(_media->media_id)) {
1501 _video->media_id = strdup(_media->media_id);
1504 if(STRING_VALID(_media->video_meta->title)) {
1505 _video->title = strdup(_media->video_meta->title);
1507 if(STRING_VALID(_media->video_meta->album)) {
1508 _video->album = strdup(_media->video_meta->album);
1510 if(STRING_VALID(_media->video_meta->artist)) {
1511 _video->artist = strdup(_media->video_meta->artist);
1513 if(STRING_VALID(_media->video_meta->album_artist)) {
1514 _video->album_artist = strdup(_media->video_meta->album_artist);
1516 if(STRING_VALID(_media->video_meta->genre)) {
1517 _video->genre = strdup(_media->video_meta->genre);
1519 if(STRING_VALID(_media->video_meta->composer)) {
1520 _video->composer = strdup(_media->video_meta->composer);
1522 if(STRING_VALID(_media->video_meta->year)) {
1523 _video->year = strdup(_media->video_meta->year);
1525 if(STRING_VALID(_media->video_meta->recorded_date)) {
1526 _video->recorded_date = strdup(_media->video_meta->recorded_date);
1528 if(STRING_VALID(_media->video_meta->copyright)) {
1529 _video->copyright = strdup(_media->video_meta->copyright);
1531 if(STRING_VALID(_media->video_meta->track_num)) {
1532 _video->track_num = strdup(_media->video_meta->track_num);
1535 _video->width = _media->video_meta->width;
1536 _video->height = _media->video_meta->height;
1537 _video->duration = _media->video_meta->duration;
1538 _video->bitrate = _media->video_meta->bitrate;
1539 _video->played_count = _media->video_meta->played_count;
1540 _video->played_time = _media->video_meta->played_time;
1541 _video->played_position = _media->video_meta->played_position;
1543 *video = (video_meta_h)_video;
1548 int media_info_get_audio(media_info_h media, audio_meta_h *audio)
1550 int ret = MEDIA_CONTENT_ERROR_NONE;
1552 media_info_s *_media = (media_info_s*)media;
1555 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
1556 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");
1557 media_content_retvm_if(_media->audio_meta == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid audio_meta");
1559 audio_meta_s *_audio = (audio_meta_s*)calloc(1, sizeof(audio_meta_s));
1560 media_content_retvm_if(_audio == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1562 if(STRING_VALID(_media->media_id)) {
1563 _audio->media_id = strdup(_media->media_id);
1566 if(STRING_VALID(_media->audio_meta->title)) {
1567 _audio->title = strdup(_media->audio_meta->title);
1569 if(STRING_VALID(_media->audio_meta->album)) {
1570 _audio->album = strdup(_media->audio_meta->album);
1572 if(STRING_VALID(_media->audio_meta->artist)) {
1573 _audio->artist = strdup(_media->audio_meta->artist);
1575 if(STRING_VALID(_media->audio_meta->album_artist)) {
1576 _audio->album_artist = strdup(_media->audio_meta->album_artist);
1578 if(STRING_VALID(_media->audio_meta->genre)) {
1579 _audio->genre = strdup(_media->audio_meta->genre);
1581 if(STRING_VALID(_media->audio_meta->composer)) {
1582 _audio->composer = strdup(_media->audio_meta->composer);
1584 if(STRING_VALID(_media->audio_meta->year)) {
1585 _audio->year = strdup(_media->audio_meta->year);
1587 if(STRING_VALID(_media->audio_meta->recorded_date)) {
1588 _audio->recorded_date = strdup(_media->audio_meta->recorded_date);
1590 if(STRING_VALID(_media->audio_meta->copyright)) {
1591 _audio->copyright = strdup(_media->audio_meta->copyright);
1593 if(STRING_VALID(_media->audio_meta->track_num)) {
1594 _audio->track_num = strdup(_media->audio_meta->track_num);
1597 _audio->duration = _media->audio_meta->duration;
1598 _audio->bitrate = _media->audio_meta->bitrate;
1599 _audio->bitpersample = _media->audio_meta->bitpersample;
1600 _audio->samplerate = _media->audio_meta->samplerate;
1601 _audio->channel = _media->audio_meta->channel;
1602 _audio->played_time = _media->audio_meta->played_time;
1603 _audio->played_count = _media->audio_meta->played_count;
1604 _audio->played_position = _media->audio_meta->played_position;
1606 *audio = (audio_meta_h)_audio;
1611 int media_info_get_media_id(media_info_h media, char **media_id)
1613 int ret = MEDIA_CONTENT_ERROR_NONE;
1614 media_info_s *_media = (media_info_s*)media;
1616 if(_media && media_id)
1618 if(STRING_VALID(_media->media_id))
1620 *media_id = strdup(_media->media_id);
1621 media_content_retvm_if(*media_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1627 ret = MEDIA_CONTENT_ERROR_NONE;
1631 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1632 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1638 int media_info_get_file_path(media_info_h media, char **path)
1640 int ret = MEDIA_CONTENT_ERROR_NONE;
1641 media_info_s *_media = (media_info_s*)media;
1645 if(STRING_VALID(_media->file_path))
1647 *path = strdup(_media->file_path);
1648 media_content_retvm_if(*path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1654 ret = MEDIA_CONTENT_ERROR_NONE;
1659 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1660 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1666 int media_info_get_display_name(media_info_h media, char **name)
1668 int ret = MEDIA_CONTENT_ERROR_NONE;
1669 media_info_s *_media = (media_info_s*)media;
1672 if(STRING_VALID(_media->display_name))
1674 *name = strdup(_media->display_name);
1675 media_content_retvm_if(*name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1681 ret = MEDIA_CONTENT_ERROR_NONE;
1686 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1687 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1693 int media_info_get_media_type(media_info_h media, media_content_type_e *type)
1695 int ret = MEDIA_CONTENT_ERROR_NONE;
1696 media_info_s *_media = (media_info_s*)media;
1699 *type = _media->media_type;
1700 ret = MEDIA_CONTENT_ERROR_NONE;
1704 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1705 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1711 int media_info_get_mime_type(media_info_h media, char **mime_type)
1713 int ret = MEDIA_CONTENT_ERROR_NONE;
1714 media_info_s *_media = (media_info_s*)media;
1716 if(_media && mime_type)
1718 if(STRING_VALID(_media->mime_type))
1720 *mime_type = strdup(_media->mime_type);
1721 media_content_retvm_if(*mime_type == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1727 ret = MEDIA_CONTENT_ERROR_NONE;
1731 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1732 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1738 int media_info_get_size(media_info_h media, unsigned long long *size)
1740 int ret = MEDIA_CONTENT_ERROR_NONE;
1741 media_info_s *_media = (media_info_s*)media;
1745 *size = _media->size;
1746 ret = MEDIA_CONTENT_ERROR_NONE;
1750 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1751 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1757 int media_info_get_added_time(media_info_h media, time_t *added_time)
1759 int ret = MEDIA_CONTENT_ERROR_NONE;
1760 media_info_s *_media = (media_info_s*)media;
1761 if(_media && added_time)
1763 *added_time = _media->added_time;
1764 ret = MEDIA_CONTENT_ERROR_NONE;
1768 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1769 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1775 int media_info_get_modified_time(media_info_h media, time_t* time)
1777 int ret = MEDIA_CONTENT_ERROR_NONE;
1778 media_info_s *_media = (media_info_s*)media;
1781 *time = _media->modified_time;
1782 ret = MEDIA_CONTENT_ERROR_NONE;
1786 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1787 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1793 int media_info_get_timeline(media_info_h media, time_t* time)
1795 int ret = MEDIA_CONTENT_ERROR_NONE;
1796 media_info_s *_media = (media_info_s*)media;
1799 *time = _media->timeline;
1800 ret = MEDIA_CONTENT_ERROR_NONE;
1804 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1805 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1811 int media_info_get_thumbnail_path(media_info_h media, char **path)
1813 int ret = MEDIA_CONTENT_ERROR_NONE;
1814 media_info_s *_media = (media_info_s*)media;
1817 if(STRING_VALID(_media->thumbnail_path))
1819 *path = strdup(_media->thumbnail_path);
1820 media_content_retvm_if(*path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1826 ret = MEDIA_CONTENT_ERROR_NONE;
1831 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1832 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1838 int media_info_get_title(media_info_h media, char **title)
1840 int ret = MEDIA_CONTENT_ERROR_NONE;
1841 media_info_s *_media = (media_info_s*)media;
1845 if(STRING_VALID(_media->title))
1847 *title = strdup(_media->title);
1848 media_content_retvm_if(*title == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1854 ret = MEDIA_CONTENT_ERROR_NONE;
1858 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1859 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1865 int media_info_get_description(media_info_h media, char **description)
1867 int ret = MEDIA_CONTENT_ERROR_NONE;
1868 media_info_s *_media = (media_info_s*)media;
1870 if(_media && description)
1872 if(STRING_VALID(_media->description))
1874 *description = strdup(_media->description);
1875 media_content_retvm_if(*description == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1879 *description = NULL;
1881 ret = MEDIA_CONTENT_ERROR_NONE;
1885 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1886 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1892 int media_info_get_longitude(media_info_h media, double* longitude)
1894 int ret = MEDIA_CONTENT_ERROR_NONE;
1895 media_info_s *_media = (media_info_s*)media;
1897 if(_media && longitude)
1899 *longitude = _media->longitude;
1900 ret = MEDIA_CONTENT_ERROR_NONE;
1904 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1905 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1910 int media_info_get_latitude(media_info_h media, double* latitude)
1912 int ret = MEDIA_CONTENT_ERROR_NONE;
1913 media_info_s *_media = (media_info_s*)media;
1915 if(_media && latitude)
1917 *latitude = _media->latitude;
1918 ret = MEDIA_CONTENT_ERROR_NONE;
1922 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1923 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1929 int media_info_get_altitude(media_info_h media, double *altitude)
1931 int ret = MEDIA_CONTENT_ERROR_NONE;
1932 media_info_s *_media = (media_info_s*)media;
1934 if(_media && altitude)
1936 *altitude = _media->altitude;
1937 ret = MEDIA_CONTENT_ERROR_NONE;
1941 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1942 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1948 int media_info_get_weather(media_info_h media, char **weather)
1950 int ret = MEDIA_CONTENT_ERROR_NONE;
1951 media_info_s *_media = (media_info_s*)media;
1953 if(_media && weather)
1955 if(STRING_VALID(_media->weather))
1957 *weather = strdup(_media->weather);
1958 media_content_retvm_if(*weather == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
1964 ret = MEDIA_CONTENT_ERROR_NONE;
1968 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1969 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1975 int media_info_get_rating(media_info_h media, int *rating)
1977 int ret = MEDIA_CONTENT_ERROR_NONE;
1978 media_info_s *_media = (media_info_s*)media;
1980 if(_media && rating)
1982 *rating = _media->rating;
1983 ret = MEDIA_CONTENT_ERROR_NONE;
1987 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
1988 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
1994 int media_info_get_favorite(media_info_h media, bool* favorite)
1996 int ret = MEDIA_CONTENT_ERROR_NONE;
1997 media_info_s *_media = (media_info_s*)media;
1999 if(_media && favorite)
2002 *favorite = _media->favourite;
2003 ret = MEDIA_CONTENT_ERROR_NONE;
2007 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2008 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2014 int media_info_get_author(media_info_h media, char **author)
2016 int ret = MEDIA_CONTENT_ERROR_NONE;
2017 media_info_s *_media = (media_info_s*)media;
2019 if(_media && author)
2021 if(STRING_VALID(_media->author))
2023 *author = strdup(_media->author);
2024 media_content_retvm_if(*author == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2030 ret = MEDIA_CONTENT_ERROR_NONE;
2034 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2035 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2041 int media_info_get_provider(media_info_h media, char **provider)
2043 int ret = MEDIA_CONTENT_ERROR_NONE;
2044 media_info_s *_media = (media_info_s*)media;
2046 if(_media && provider)
2048 if(STRING_VALID(_media->provider))
2050 *provider = strdup(_media->provider);
2051 media_content_retvm_if(*provider == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2057 ret = MEDIA_CONTENT_ERROR_NONE;
2061 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2062 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2068 int media_info_get_content_name(media_info_h media, char **content_name)
2070 int ret = MEDIA_CONTENT_ERROR_NONE;
2071 media_info_s *_media = (media_info_s*)media;
2073 if(_media && content_name)
2075 if(STRING_VALID(_media->content_name))
2077 *content_name = strdup(_media->content_name);
2078 media_content_retvm_if(*content_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2082 *content_name = NULL;
2084 ret = MEDIA_CONTENT_ERROR_NONE;
2088 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2089 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2095 int media_info_get_category(media_info_h media, char **category)
2097 int ret = MEDIA_CONTENT_ERROR_NONE;
2098 media_info_s *_media = (media_info_s*)media;
2100 if(_media && category)
2102 if(STRING_VALID(_media->category))
2104 *category = strdup(_media->category);
2105 media_content_retvm_if(*category == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2111 ret = MEDIA_CONTENT_ERROR_NONE;
2115 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2116 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2122 int media_info_get_location_tag(media_info_h media, char **location_tag)
2124 int ret = MEDIA_CONTENT_ERROR_NONE;
2125 media_info_s *_media = (media_info_s*)media;
2127 if(_media && location_tag)
2129 if(STRING_VALID(_media->location_tag))
2131 *location_tag = strdup(_media->location_tag);
2132 media_content_retvm_if(*location_tag == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2136 *location_tag = NULL;
2138 ret = MEDIA_CONTENT_ERROR_NONE;
2142 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2143 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2149 int media_info_get_age_rating(media_info_h media, char **age_rating)
2151 int ret = MEDIA_CONTENT_ERROR_NONE;
2152 media_info_s *_media = (media_info_s*)media;
2154 if(_media && age_rating)
2156 if(STRING_VALID(_media->age_rating))
2158 *age_rating = strdup(_media->age_rating);
2159 media_content_retvm_if(*age_rating == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2165 ret = MEDIA_CONTENT_ERROR_NONE;
2169 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2170 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2176 int media_info_get_keyword(media_info_h media, char **keyword)
2178 int ret = MEDIA_CONTENT_ERROR_NONE;
2179 media_info_s *_media = (media_info_s*)media;
2181 if(_media && keyword)
2183 if(STRING_VALID(_media->keyword))
2185 *keyword = strdup(_media->keyword);
2186 media_content_retvm_if(*keyword == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2192 ret = MEDIA_CONTENT_ERROR_NONE;
2196 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2197 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2203 int media_info_get_storage_id(media_info_h media, char **storage_id)
2205 int ret = MEDIA_CONTENT_ERROR_NONE;
2206 media_info_s *_media = (media_info_s*)media;
2208 if(_media && storage_id)
2210 if(STRING_VALID(_media->storage_uuid))
2212 *storage_id = strdup(_media->storage_uuid);
2213 media_content_retvm_if(*storage_id == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2219 ret = MEDIA_CONTENT_ERROR_NONE;
2223 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2224 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2230 int media_info_is_drm(media_info_h media, bool *is_drm)
2232 int ret = MEDIA_CONTENT_ERROR_NONE;
2233 media_info_s *_media = (media_info_s*)media;
2237 *is_drm = _media->is_drm;
2238 ret = MEDIA_CONTENT_ERROR_NONE;
2242 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2243 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2249 int media_info_get_storage_type(media_info_h media, media_content_storage_e *storage_type)
2251 int ret = MEDIA_CONTENT_ERROR_NONE;
2252 media_info_s *_media = (media_info_s*)media;
2254 if(_media && storage_type)
2256 *storage_type = _media->storage_type;
2257 ret = MEDIA_CONTENT_ERROR_NONE;
2261 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2262 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2268 int media_info_get_played_count(media_info_h media, int *played_count)
2270 int ret = MEDIA_CONTENT_ERROR_NONE;
2271 media_info_s *_media = (media_info_s*)media;
2275 *played_count = _media->played_count;
2276 ret = MEDIA_CONTENT_ERROR_NONE;
2280 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2281 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2287 int media_info_get_played_time(media_info_h media, time_t* played_time)
2289 int ret = MEDIA_CONTENT_ERROR_NONE;
2290 media_info_s *_media = (media_info_s*)media;
2294 *played_time = _media->played_time;
2295 ret = MEDIA_CONTENT_ERROR_NONE;
2299 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2300 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2306 int media_info_increase_played_count(media_info_h media)
2308 int ret = MEDIA_CONTENT_ERROR_NONE;
2310 media_info_s *_media = (media_info_s*)media;
2314 _media->played_count += 1;
2318 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2319 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2325 int media_info_set_played_time(media_info_h media)
2327 int ret = MEDIA_CONTENT_ERROR_NONE;
2328 time_t current_time;
2330 media_info_s *_media = (media_info_s*)media;
2334 time(¤t_time);
2335 _media->played_time = current_time;
2339 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2340 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2346 int media_info_get_media_from_db(const char *media_id, media_info_h *media)
2348 int ret = MEDIA_CONTENT_ERROR_NONE;
2349 char select_query[DEFAULT_QUERY_SIZE];
2350 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
2351 sqlite3_stmt *stmt = NULL;
2353 if(!STRING_VALID(media_id) || (media == NULL))
2355 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2356 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2359 memset(select_query, 0x00, sizeof(select_query));
2360 memset(storage_id, 0x00, sizeof(storage_id));
2362 ret = _media_db_get_storage_id_by_media_id(media_id, storage_id);
2363 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
2365 snprintf(select_query, sizeof(select_query), SELECT_MEDIA_FROM_MEDIA, storage_id, media_id);
2367 ret = _content_query_prepare(&stmt, select_query, NULL, NULL);
2368 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
2370 media_info_s *_media = NULL;
2372 while(sqlite3_step(stmt) == SQLITE_ROW)
2375 media_info_destroy((media_info_h)_media);
2377 _media = (media_info_s*)calloc(1, sizeof(media_info_s));
2381 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
2382 SQLITE3_FINALIZE(stmt);
2383 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
2386 _media_info_item_get_detail(stmt, (media_info_h)_media);
2388 *media = (media_info_h)_media;
2391 SQLITE3_FINALIZE(stmt);
2396 int media_info_set_display_name(media_info_h media, const char *display_name)
2398 int ret = MEDIA_CONTENT_ERROR_NONE;
2399 media_info_s *_media = (media_info_s*)media;
2401 if(_media != NULL && STRING_VALID(display_name))
2403 SAFE_FREE(_media->display_name);
2405 _media->display_name = strdup(display_name);
2406 media_content_retvm_if(_media->display_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2410 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2411 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2417 int media_info_set_description(media_info_h media, const char *description)
2419 int ret = MEDIA_CONTENT_ERROR_NONE;
2420 media_info_s *_media = (media_info_s*)media;
2424 SAFE_FREE(_media->description);
2426 if(STRING_VALID(description))
2428 _media->description = strdup(description);
2429 media_content_retvm_if(_media->description == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2433 _media->description = NULL;
2438 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2439 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2445 int media_info_set_longitude(media_info_h media, double longitude)
2447 int ret = MEDIA_CONTENT_ERROR_NONE;
2448 media_info_s *_media = (media_info_s*)media;
2452 _media->longitude = longitude;
2456 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2457 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2463 int media_info_set_latitude(media_info_h media, double latitude)
2465 int ret = MEDIA_CONTENT_ERROR_NONE;
2466 media_info_s *_media = (media_info_s*)media;
2470 _media->latitude = latitude;
2474 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2475 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2481 int media_info_set_altitude(media_info_h media, double altitude)
2483 int ret = MEDIA_CONTENT_ERROR_NONE;
2484 media_info_s *_media = (media_info_s*)media;
2488 _media->altitude = altitude;
2492 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2493 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2499 int media_info_set_weather(media_info_h media, const char *weather)
2501 int ret = MEDIA_CONTENT_ERROR_NONE;
2502 media_info_s *_media = (media_info_s*)media;
2506 SAFE_FREE(_media->weather);
2508 if(STRING_VALID(weather))
2510 _media->weather = strdup(weather);
2511 media_content_retvm_if(_media->weather == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2515 _media->weather = NULL;
2520 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2521 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2527 int media_info_set_rating(media_info_h media, int rating)
2529 int ret = MEDIA_CONTENT_ERROR_NONE;
2530 media_info_s *_media = (media_info_s*)media;
2534 _media->rating = rating;
2538 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2539 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2545 int media_info_set_added_time(media_info_h media, time_t added_time)
2547 int ret = MEDIA_CONTENT_ERROR_NONE;
2549 media_info_s *_media = (media_info_s*)media;
2551 if((_media != NULL) && (added_time >= 0))
2553 _media->added_time = added_time;
2557 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2558 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2564 int media_info_set_favorite(media_info_h media, bool favorite)
2566 int ret = MEDIA_CONTENT_ERROR_NONE;
2567 media_info_s *_media = (media_info_s*)media;
2571 if(favorite == TRUE)
2573 time(&_media->favourite);
2577 _media->favourite = 0;
2582 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2583 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2589 int media_info_set_author(media_info_h media, const char *author)
2591 int ret = MEDIA_CONTENT_ERROR_NONE;
2592 media_info_s *_media = (media_info_s*)media;
2596 if(STRING_VALID(author))
2598 _media->author = strdup(author);
2599 media_content_retvm_if(_media->author == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2603 _media->author = NULL;
2608 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2609 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2615 int media_info_set_provider(media_info_h media, const char *provider)
2617 int ret = MEDIA_CONTENT_ERROR_NONE;
2618 media_info_s *_media = (media_info_s*)media;
2622 SAFE_FREE(_media->provider);
2624 if(STRING_VALID(provider))
2626 _media->provider = strdup(provider);
2627 media_content_retvm_if(_media->provider == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2631 _media->provider = NULL;
2636 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2637 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2643 int media_info_set_content_name(media_info_h media, const char *content_name)
2645 int ret = MEDIA_CONTENT_ERROR_NONE;
2646 media_info_s *_media = (media_info_s*)media;
2650 SAFE_FREE(_media->content_name);
2652 if(STRING_VALID(content_name))
2654 _media->content_name = strdup(content_name);
2655 media_content_retvm_if(_media->content_name == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2659 _media->content_name = NULL;
2664 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2665 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2671 int media_info_set_category(media_info_h media, const char *category)
2673 int ret = MEDIA_CONTENT_ERROR_NONE;
2674 media_info_s *_media = (media_info_s*)media;
2678 SAFE_FREE(_media->category);
2680 if(STRING_VALID(category))
2682 _media->category = strdup(category);
2683 media_content_retvm_if(_media->category == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2687 _media->category = NULL;
2692 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2693 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2699 int media_info_set_location_tag(media_info_h media, const char *location_tag)
2701 int ret = MEDIA_CONTENT_ERROR_NONE;
2702 media_info_s *_media = (media_info_s*)media;
2706 SAFE_FREE(_media->location_tag);
2708 if(STRING_VALID(location_tag))
2710 _media->location_tag = strdup(location_tag);
2711 media_content_retvm_if(_media->location_tag == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2715 _media->location_tag = NULL;
2720 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2721 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2727 int media_info_set_age_rating(media_info_h media, const char *age_rating)
2729 int ret = MEDIA_CONTENT_ERROR_NONE;
2730 media_info_s *_media = (media_info_s*)media;
2734 SAFE_FREE(_media->age_rating);
2736 if(STRING_VALID(age_rating))
2738 _media->age_rating = strdup(age_rating);
2739 media_content_retvm_if(_media->age_rating == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2743 _media->age_rating = NULL;
2748 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2749 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2755 int media_info_set_keyword(media_info_h media, const char *keyword)
2757 int ret = MEDIA_CONTENT_ERROR_NONE;
2758 media_info_s *_media = (media_info_s*)media;
2762 SAFE_FREE(_media->keyword);
2764 if(STRING_VALID(keyword))
2766 _media->keyword = strdup(keyword);
2767 media_content_retvm_if(_media->keyword == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
2771 _media->keyword = NULL;
2776 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2777 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2783 int media_info_update_to_db(media_info_h media)
2785 int ret = MEDIA_CONTENT_ERROR_NONE;
2786 media_info_s *_media = (media_info_s*)media;
2787 char *set_sql = NULL;
2790 if(_media != NULL && STRING_VALID(_media->media_id))
2792 /* This sql is due to sqlite3_mprintf's wrong operation when using floating point in the text format */
2793 /* This code will be removed when sqlite3_mprintf works clearly */
2794 char *test_sql = sqlite3_mprintf("%f, %f, %f", _media->longitude, _media->latitude, _media->altitude);
2795 SQLITE3_SAFE_FREE(test_sql);
2797 /*Update Pinyin If Support Pinyin*/
2798 char *file_name_pinyin = NULL;
2799 char *description_pinyin = NULL;
2800 char *author_pinyin = NULL;
2801 char *provider_pinyin = NULL;
2802 char *content_name_pinyin = NULL;
2803 char *category_pinyin = NULL;
2804 char *location_tag_pinyin = NULL;
2805 char *age_rating_pinyin = NULL;
2806 char *keyword_pinyin = NULL;
2807 bool pinyin_support = FALSE;
2809 /*Update Pinyin If Support Pinyin*/
2810 media_svc_check_pinyin_support(&pinyin_support);
2813 if(STRING_VALID(_media->display_name))
2814 media_svc_get_pinyin(_content_get_db_handle(), _media->display_name, &file_name_pinyin);
2815 if(STRING_VALID(_media->description))
2816 media_svc_get_pinyin(_content_get_db_handle(), _media->description, &description_pinyin);
2817 if(STRING_VALID(_media->author))
2818 media_svc_get_pinyin(_content_get_db_handle(), _media->author, &author_pinyin);
2819 if(STRING_VALID(_media->provider))
2820 media_svc_get_pinyin(_content_get_db_handle(), _media->provider, &provider_pinyin);
2821 if(STRING_VALID(_media->content_name))
2822 media_svc_get_pinyin(_content_get_db_handle(), _media->content_name, &content_name_pinyin);
2823 if(STRING_VALID(_media->category))
2824 media_svc_get_pinyin(_content_get_db_handle(), _media->category, &category_pinyin);
2825 if(STRING_VALID(_media->location_tag))
2826 media_svc_get_pinyin(_content_get_db_handle(), _media->location_tag, &location_tag_pinyin);
2827 if(STRING_VALID(_media->age_rating))
2828 media_svc_get_pinyin(_content_get_db_handle(), _media->age_rating, &age_rating_pinyin);
2829 if(STRING_VALID(_media->keyword))
2830 media_svc_get_pinyin(_content_get_db_handle(), _media->keyword, &keyword_pinyin);
2833 set_sql = sqlite3_mprintf("file_name=%Q, added_time=%d, description=%Q, longitude=%f, latitude=%f, altitude=%f, \
2834 played_count=%d, last_played_time=%d, last_played_position=%d, \
2835 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, \
2836 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",
2837 _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,
2838 _media->author, _media->provider, _media->content_name, _media->category, _media->location_tag, _media->age_rating, _media->keyword, _media->weather, _media->sync_status,
2839 file_name_pinyin, description_pinyin, author_pinyin, provider_pinyin, content_name_pinyin, category_pinyin, location_tag_pinyin, age_rating_pinyin, keyword_pinyin, _media->title);
2841 sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE media_uuid=%Q", _media->storage_uuid, set_sql, _media->media_id);
2843 ret = _content_query_sql(sql);
2844 SQLITE3_SAFE_FREE(set_sql);
2845 SQLITE3_SAFE_FREE(sql);
2847 SAFE_FREE(description_pinyin);
2848 SAFE_FREE(author_pinyin);
2849 SAFE_FREE(provider_pinyin);
2850 SAFE_FREE(content_name_pinyin);
2851 SAFE_FREE(category_pinyin);
2852 SAFE_FREE(location_tag_pinyin);
2853 SAFE_FREE(age_rating_pinyin);
2854 SAFE_FREE(keyword_pinyin);
2856 if(_media->storage_type == MEDIA_CONTENT_STORAGE_CLOUD)
2861 if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
2863 set_sql = sqlite3_mprintf("title=%Q, album=%Q, artist=%Q, genre=%Q, duration=%d, width=%d, height=%d", \
2864 _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);
2866 else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
2868 set_sql = sqlite3_mprintf("title=%Q, album=%Q, artist=%Q, genre=%Q, duration=%d", \
2869 _media->title, _media->audio_meta->album, _media->audio_meta->artist, _media->audio_meta->genre, _media->audio_meta->duration);
2871 else if(_media->media_type == MEDIA_CONTENT_TYPE_IMAGE)
2873 set_sql = sqlite3_mprintf("title=%Q, width=%d, height=%d", _media->title, _media->image_meta->width, _media->image_meta->height);
2877 set_sql = sqlite3_mprintf("title=%Q", _media->title);
2880 sql = sqlite3_mprintf("UPDATE %Q SET %s WHERE media_uuid=%Q", _media->storage_uuid, set_sql, _media->media_id);
2882 ret = _content_query_sql(sql);
2884 SQLITE3_SAFE_FREE(set_sql);
2885 SQLITE3_SAFE_FREE(sql);
2888 if (ret == MEDIA_CONTENT_ERROR_NONE) {
2889 /* Send notification for this update */
2890 media_content_debug("Update is successfull. Send notification for this");
2891 if (_media->file_path && _media->mime_type) {
2892 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);
2894 media_content_error("Can't Send Noti : path or mime type is NULL");
2900 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2901 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2907 int media_info_refresh_metadata_to_db(const char *media_id)
2909 int ret = MEDIA_CONTENT_ERROR_NONE;
2910 media_info_h media = NULL;
2911 char *file_path = NULL;
2912 media_content_storage_e storage_type = 0;
2913 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
2915 if(!STRING_VALID(media_id))
2917 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
2918 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2921 ret = media_info_get_media_from_db(media_id, &media);
2922 if(ret != MEDIA_CONTENT_ERROR_NONE)
2924 media_info_destroy(media);
2928 ret = media_info_get_storage_type(media, &storage_type);
2929 if(ret != MEDIA_CONTENT_ERROR_NONE)
2931 media_info_destroy(media);
2935 if(storage_type == MEDIA_CONTENT_STORAGE_CLOUD)
2937 media_info_destroy(media);
2938 media_content_error("Can't refresh cloud content!!");
2939 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
2942 ret = media_info_get_file_path(media, &file_path);
2943 if(ret != MEDIA_CONTENT_ERROR_NONE)
2945 media_info_destroy(media);
2949 ret = _media_util_check_file_exist(file_path);
2950 if (ret != MEDIA_CONTENT_ERROR_NONE) {
2951 SAFE_FREE(file_path);
2952 media_info_destroy(media);
2956 memset(storage_id, 0x00, sizeof(storage_id));
2957 ret = media_svc_get_storage_id(_content_get_db_handle(), file_path, storage_id);
2958 if(ret != MS_MEDIA_ERR_NONE)
2960 media_content_error("media_svc_get_storage_id failed : %d", ret);
2961 SAFE_FREE(file_path);
2962 media_info_destroy(media);
2963 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2966 ret = media_svc_refresh_item(_content_get_db_handle(), storage_id, storage_type, file_path, tzplatform_getuid(TZ_USER_NAME));
2967 if (ret != MS_MEDIA_ERR_NONE)
2969 ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
2972 SAFE_FREE(file_path);
2973 media_info_destroy(media);
2978 int media_info_move_to_db(media_info_h media, const char* dst_path)
2980 int ret = MEDIA_CONTENT_ERROR_NONE;
2981 bool ignore_file = FALSE;
2982 bool ignore_dir = FALSE;
2983 char *folder_path = NULL;
2984 media_svc_storage_type_e src_storage_type = 0;
2985 media_svc_storage_type_e dst_storage_type = 0;
2986 char storage_id[MEDIA_CONTENT_UUID_SIZE+1] = {0,};
2988 media_content_retvm_if(media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid media");
2989 media_content_retvm_if(!STRING_VALID(dst_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "invalid dst_path");
2991 media_info_s *_media = (media_info_s*)media;
2993 ret = _media_util_check_ignore_file(dst_path, &ignore_file);
2994 media_content_retvm_if(ignore_file == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid path");
2996 ret = _media_util_check_file_exist(dst_path);
2997 media_content_retv_if(ret != MEDIA_CONTENT_ERROR_NONE, ret);
2999 folder_path = g_path_get_dirname(dst_path);
3000 ret = _media_util_check_ignore_dir(folder_path, &ignore_dir);
3001 SAFE_FREE(folder_path);
3003 media_content_retvm_if(ignore_dir == TRUE, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid folder path");
3005 ret = media_svc_get_storage_type(_media->file_path, &src_storage_type, tzplatform_getuid(TZ_USER_NAME));
3006 if(ret != MS_MEDIA_ERR_NONE)
3008 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
3009 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3012 ret = media_svc_get_storage_type(dst_path, &dst_storage_type, tzplatform_getuid(TZ_USER_NAME));
3013 if(ret != MS_MEDIA_ERR_NONE)
3015 media_content_sec_error("media_svc_get_storage_type failed : %d", ret);
3016 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3019 memset(storage_id, 0x00, sizeof(storage_id));
3020 ret = media_svc_get_storage_id(_content_get_db_handle(), _media->file_path, storage_id);
3021 if(ret != MS_MEDIA_ERR_NONE)
3023 media_content_error("media_svc_get_storage_id failed : %d", ret);
3024 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3027 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));
3028 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3031 int media_info_create_thumbnail(media_info_h media, media_thumbnail_completed_cb callback, void *user_data)
3033 int ret = MEDIA_CONTENT_ERROR_NONE;
3034 media_info_s *_media = (media_info_s*)media;
3036 if(_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path))
3038 media_thumbnail_cb_s *_thumb_cb = (media_thumbnail_cb_s*)calloc(1, sizeof(media_thumbnail_cb_s));
3039 media_content_retvm_if(_thumb_cb == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3041 _thumb_cb->handle = _media;
3042 _thumb_cb->user_data = user_data;
3043 _thumb_cb->thumbnail_completed_cb = callback;
3045 ret = thumbnail_request_from_db_async(_media->file_path, (ThumbFunc)__media_info_thumbnail_completed_cb, (void *)_thumb_cb, tzplatform_getuid(TZ_USER_NAME));
3046 ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret);
3050 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3051 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3057 int media_info_cancel_thumbnail(media_info_h media)
3059 int ret = MEDIA_CONTENT_ERROR_NONE;
3060 media_info_s *_media = (media_info_s*)media;
3062 if(_media != NULL && STRING_VALID(_media->media_id) && STRING_VALID(_media->file_path))
3064 ret = thumbnail_request_cancel_media(_media->file_path);
3065 ret = _content_error_capi(MEDIA_THUMBNAIL_TYPE, ret);
3069 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3070 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3076 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)
3080 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3081 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3084 media_svc_content_info_s *svc_content_info = calloc(1, sizeof(media_svc_content_info_s));
3085 media_content_retvm_if(svc_content_info == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3087 svc_content_info->path = g_strdup(media->file_path);
3088 svc_content_info->media_type = media->media_type;
3089 svc_content_info->mime_type = g_strdup(media->mime_type);
3090 svc_content_info->size = media->size;
3091 svc_content_info->storage_type = storage_type;
3092 svc_content_info->storage_uuid = g_strdup(media->storage_uuid);
3094 svc_content_info->added_time = media->added_time;
3095 svc_content_info->modified_time = media->modified_time;
3096 svc_content_info->thumbnail_path = g_strdup(media->thumbnail_path);
3097 svc_content_info->is_drm = media->is_drm;
3099 svc_content_info->media_meta.title = g_strdup(media->title);
3100 svc_content_info->media_meta.rating = media->rating;
3101 svc_content_info->media_meta.description = g_strdup(media->description);
3102 svc_content_info->media_meta.longitude = media->longitude;
3103 svc_content_info->media_meta.latitude = media->latitude;
3104 svc_content_info->media_meta.altitude = media->altitude;
3105 svc_content_info->media_meta.weather = g_strdup(media->weather);
3107 switch(media->media_type)
3109 case MEDIA_CONTENT_TYPE_IMAGE:
3110 svc_content_info->media_meta.width = media->image_meta->width;
3111 svc_content_info->media_meta.height = media->image_meta->height;
3112 svc_content_info->media_meta.datetaken = g_strdup(media->image_meta->date_taken);
3113 svc_content_info->media_meta.orientation = media->image_meta->orientation;
3115 case MEDIA_CONTENT_TYPE_VIDEO:
3116 svc_content_info->media_meta.album = g_strdup(media->audio_meta->album);
3117 svc_content_info->media_meta.artist = g_strdup(media->audio_meta->artist);
3118 svc_content_info->media_meta.album_artist = g_strdup(media->audio_meta->album_artist);
3119 svc_content_info->media_meta.genre = g_strdup(media->audio_meta->genre);
3120 svc_content_info->media_meta.composer = g_strdup(media->audio_meta->composer);
3121 svc_content_info->media_meta.year = g_strdup(media->audio_meta->year);
3122 svc_content_info->media_meta.recorded_date = g_strdup(media->audio_meta->recorded_date);
3123 svc_content_info->media_meta.copyright = g_strdup(media->audio_meta->copyright);
3124 svc_content_info->media_meta.track_num = g_strdup(media->audio_meta->track_num);
3125 svc_content_info->media_meta.bitrate = media->audio_meta->bitrate;
3126 svc_content_info->media_meta.duration = media->audio_meta->duration;
3127 svc_content_info->media_meta.width = media->image_meta->width;
3128 svc_content_info->media_meta.height = media->image_meta->height;
3130 case MEDIA_CONTENT_TYPE_SOUND:
3131 case MEDIA_CONTENT_TYPE_MUSIC:
3132 svc_content_info->media_meta.album = g_strdup(media->audio_meta->album);
3133 svc_content_info->media_meta.artist = g_strdup(media->audio_meta->artist);
3134 svc_content_info->media_meta.album_artist = g_strdup(media->audio_meta->album_artist);
3135 svc_content_info->media_meta.genre = g_strdup(media->audio_meta->genre);
3136 svc_content_info->media_meta.composer = g_strdup(media->audio_meta->composer);
3137 svc_content_info->media_meta.year = g_strdup(media->audio_meta->year);
3138 svc_content_info->media_meta.recorded_date = g_strdup(media->audio_meta->recorded_date);
3139 svc_content_info->media_meta.copyright = g_strdup(media->audio_meta->copyright);
3140 svc_content_info->media_meta.track_num = g_strdup(media->audio_meta->track_num);
3141 svc_content_info->media_meta.bitrate = media->audio_meta->bitrate;
3142 svc_content_info->media_meta.duration = media->audio_meta->duration;
3143 svc_content_info->media_meta.channel = media->audio_meta->channel;
3144 svc_content_info->media_meta.samplerate = media->audio_meta->samplerate;
3146 case MEDIA_CONTENT_TYPE_OTHERS:
3151 *service_content = svc_content_info;
3152 return MEDIA_CONTENT_ERROR_NONE;
3155 static int __media_info_set_str_data(media_info_h media, media_info_item_e data_type, const char *str_data)
3157 media_info_s *_media = (media_info_s*)media;
3161 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3162 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3167 case MEDIA_INFO_PATH:
3168 SAFE_FREE(_media->file_path);
3169 if(STRING_VALID(str_data))
3171 _media->file_path = strdup(str_data);
3172 media_content_retvm_if(_media->file_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3176 _media->file_path = NULL;
3179 case MEDIA_INFO_MIME_TYPE:
3180 SAFE_FREE(_media->mime_type);
3181 if(STRING_VALID(str_data))
3183 _media->mime_type = strdup(str_data);
3184 media_content_retvm_if(_media->mime_type == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3188 _media->mime_type = NULL;
3191 case MEDIA_INFO_THUMBNAIL_PATH:
3192 SAFE_FREE(_media->thumbnail_path);
3193 if(STRING_VALID(str_data))
3195 _media->thumbnail_path = strdup(str_data);
3196 media_content_retvm_if(_media->thumbnail_path == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3200 _media->thumbnail_path = NULL;
3203 case MEDIA_INFO_TITLE:
3204 SAFE_FREE(_media->title);
3205 if(STRING_VALID(str_data))
3207 _media->title = strdup(str_data);
3208 media_content_retvm_if(_media->title == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3212 _media->title = NULL;
3215 case MEDIA_INFO_STORAGE_UUID:
3216 SAFE_FREE(_media->storage_uuid);
3217 if(STRING_VALID(str_data))
3219 _media->storage_uuid = strdup(str_data);
3220 media_content_retvm_if(_media->storage_uuid == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3224 _media->storage_uuid = NULL;
3227 case MEDIA_INFO_ALBUM:
3228 if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3230 SAFE_FREE(_media->video_meta->album);
3231 if(STRING_VALID(str_data))
3233 _media->video_meta->album = strdup(str_data);
3234 media_content_retvm_if(_media->video_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3238 _media->video_meta->album = NULL;
3241 else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
3243 SAFE_FREE(_media->audio_meta->album);
3244 if(STRING_VALID(str_data))
3246 _media->audio_meta->album = strdup(str_data);
3247 media_content_retvm_if(_media->audio_meta->album == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3251 _media->audio_meta->album = NULL;
3256 media_content_error("Invalid media type");
3257 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3260 case MEDIA_INFO_ARTIST:
3261 if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3263 SAFE_FREE(_media->video_meta->artist);
3264 if(STRING_VALID(str_data))
3266 _media->video_meta->artist = strdup(str_data);
3267 media_content_retvm_if(_media->video_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3271 _media->video_meta->artist = NULL;
3274 else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
3276 SAFE_FREE(_media->audio_meta->artist);
3277 if(STRING_VALID(str_data))
3279 _media->audio_meta->artist = strdup(str_data);
3280 media_content_retvm_if(_media->audio_meta->artist == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3284 _media->audio_meta->artist = NULL;
3289 media_content_error("Invalid media type");
3290 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3293 case MEDIA_INFO_GENRE:
3294 if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3296 SAFE_FREE(_media->video_meta->genre);
3297 if(STRING_VALID(str_data))
3299 _media->video_meta->genre = strdup(str_data);
3300 media_content_retvm_if(_media->video_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3304 _media->video_meta->genre = NULL;
3307 else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
3309 SAFE_FREE(_media->audio_meta->genre);
3310 if(STRING_VALID(str_data))
3312 _media->audio_meta->genre = strdup(str_data);
3313 media_content_retvm_if(_media->audio_meta->genre == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3317 _media->audio_meta->genre = NULL;
3322 media_content_error("Invalid media type");
3323 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3326 case MEDIA_INFO_RECORDED_DATE:
3327 if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3329 SAFE_FREE(_media->video_meta->recorded_date);
3330 if(STRING_VALID(str_data))
3332 _media->video_meta->recorded_date = strdup(str_data);
3333 media_content_retvm_if(_media->video_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3337 _media->video_meta->recorded_date = NULL;
3340 else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
3342 SAFE_FREE(_media->audio_meta->recorded_date);
3343 if(STRING_VALID(str_data))
3345 _media->audio_meta->recorded_date = strdup(str_data);
3346 media_content_retvm_if(_media->audio_meta->recorded_date == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3350 _media->audio_meta->recorded_date = NULL;
3355 media_content_error("Invalid media type");
3356 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3360 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3361 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3364 return MEDIA_CONTENT_ERROR_NONE;
3367 int media_info_insert_to_db_with_data(media_info_h media, media_info_h *info)
3369 int ret = MEDIA_CONTENT_ERROR_NONE;
3371 media_info_s *_media = (media_info_s*)media;
3373 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid media");
3374 media_content_retvm_if(!STRING_VALID(_media->file_path), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid file_path");
3375 media_content_retvm_if(!STRING_VALID(_media->mime_type), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid mime_type");
3376 media_content_retvm_if(!STRING_VALID(_media->storage_uuid), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid storage_uuid");
3377 media_content_retvm_if(!STRING_VALID(_media->title), MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid title");
3378 media_content_retvm_if(_media->storage_type < 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid storage_type [%d]", _media->storage_type);
3379 media_content_retvm_if(_media->size <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid size [%d]", _media->size);
3380 media_content_retvm_if(_media->modified_time <= 0, MEDIA_CONTENT_ERROR_INVALID_PARAMETER, "Invalid modified_time [%d]", _media->modified_time);
3382 if ((_media->media_type < MEDIA_CONTENT_TYPE_IMAGE) || (_media->media_type > MEDIA_CONTENT_TYPE_OTHERS))
3384 media_content_error("invalid media type [%d]", _media->media_type);
3385 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3388 media_content_sec_debug("storage[%d], path[%s], media_type[%d]", _media->storage_type, _media->file_path, _media->media_type);
3390 media_svc_content_info_s *svc_content_info = NULL;
3392 ret = __media_info_map_data_usr_to_svc(_media, &svc_content_info, _media->storage_type);
3393 media_content_retvm_if(ret != MEDIA_CONTENT_ERROR_NONE, ret, "__media_info_map_data_usr_to_svc fail");
3395 if(svc_content_info == NULL)
3397 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3398 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3401 ret = media_svc_insert_item_immediately_with_data(_content_get_db_handle(), svc_content_info, tzplatform_getuid(TZ_USER_NAME));
3402 if(ret != MS_MEDIA_ERR_NONE) {
3403 media_content_sec_error("media_svc_insert_item_immediately_with_data failed : %d (%s)", ret, _media->file_path);
3404 media_svc_destroy_content_info(svc_content_info);
3405 SAFE_FREE(svc_content_info);
3406 return _content_error_capi(MEDIA_CONTENT_TYPE, ret);
3408 /*free the svc_content_info*/
3409 media_svc_destroy_content_info(svc_content_info);
3410 SAFE_FREE(svc_content_info);
3414 media_info_s *_get_media = (media_info_s*)calloc(1, sizeof(media_info_s));
3415 media_content_retvm_if(_get_media == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3417 ret = _media_info_get_media_info_from_db(_media->file_path, _media->storage_uuid, (media_info_h)_get_media);
3419 *info = (media_info_h)_get_media;
3425 int media_info_create_handle(media_info_h *media)
3427 int ret = MEDIA_CONTENT_ERROR_NONE;
3431 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3432 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3435 media_info_s *_media = (media_info_s*)calloc(1,sizeof(media_info_s));
3436 media_content_retvm_if(_media == NULL, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY");
3438 _media->audio_meta = (audio_meta_s *)calloc(1, sizeof(audio_meta_s));
3439 if(_media->audio_meta == NULL)
3442 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
3443 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
3446 _media->video_meta = (video_meta_s *)calloc(1, sizeof(video_meta_s));
3447 if(_media->video_meta == NULL)
3449 SAFE_FREE(_media->audio_meta);
3451 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
3452 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
3455 _media->image_meta = (image_meta_s *)calloc(1, sizeof(image_meta_s));
3456 if(_media->image_meta == NULL)
3458 SAFE_FREE(_media->audio_meta);
3459 SAFE_FREE(_media->video_meta);
3461 media_content_error("OUT_OF_MEMORY(0x%08x)", MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
3462 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
3465 _media->storage_type = -1;
3466 _media->media_type = -1;
3467 _media->modified_time = -1;
3470 *media = (media_info_h)_media;
3475 int media_info_set_path(media_info_h media, const char *path)
3477 return __media_info_set_str_data(media, MEDIA_INFO_PATH, path);
3480 int media_info_set_mime_type(media_info_h media, const char *mime_type)
3482 return __media_info_set_str_data(media, MEDIA_INFO_MIME_TYPE, mime_type);
3485 int media_info_set_title(media_info_h media, const char *title)
3487 return __media_info_set_str_data(media, MEDIA_INFO_TITLE, title);
3490 int media_info_set_album(media_info_h media, const char *album)
3492 return __media_info_set_str_data(media, MEDIA_INFO_ALBUM, album);
3495 int media_info_set_artist(media_info_h media, const char *artist)
3497 return __media_info_set_str_data(media, MEDIA_INFO_ARTIST, artist);
3500 int media_info_set_genre(media_info_h media, const char *genre)
3502 return __media_info_set_str_data(media, MEDIA_INFO_GENRE, genre);
3505 int media_info_set_recorded_date(media_info_h media, const char *recorded_date)
3507 return __media_info_set_str_data(media, MEDIA_INFO_RECORDED_DATE, recorded_date);
3510 int media_info_set_thumbnail_path(media_info_h media, const char *thumbnail_path)
3512 return __media_info_set_str_data(media, MEDIA_INFO_THUMBNAIL_PATH, thumbnail_path);
3515 int media_info_set_storage_id(media_info_h media, const char *storage_id)
3517 return __media_info_set_str_data(media, MEDIA_INFO_STORAGE_UUID, storage_id);
3520 int media_info_set_size(media_info_h media, unsigned long long size)
3522 media_info_s *_media = (media_info_s*)media;
3526 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3527 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3530 _media->size = size;
3532 return MEDIA_CONTENT_ERROR_NONE;
3535 int media_info_set_modified_time(media_info_h media, time_t modified_time)
3537 media_info_s *_media = (media_info_s*)media;
3541 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3542 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3545 _media->modified_time = modified_time;
3547 return MEDIA_CONTENT_ERROR_NONE;
3550 int media_info_set_media_type(media_info_h media, media_content_type_e type)
3552 media_info_s *_media = (media_info_s*)media;
3556 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3557 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3560 _media->media_type = type;
3562 return MEDIA_CONTENT_ERROR_NONE;
3565 int media_info_set_duration(media_info_h media, int duration)
3567 media_info_s *_media = (media_info_s*)media;
3571 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3572 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3575 if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3576 _media->video_meta->duration = duration;
3577 else if((_media->media_type == MEDIA_CONTENT_TYPE_MUSIC) || (_media->media_type == MEDIA_CONTENT_TYPE_SOUND))
3578 _media->audio_meta->duration = duration;
3581 media_content_error("Invalid media type");
3582 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3585 return MEDIA_CONTENT_ERROR_NONE;
3588 int media_info_set_width(media_info_h media, int width)
3590 media_info_s *_media = (media_info_s*)media;
3594 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3595 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3598 if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3599 _media->video_meta->width = width;
3600 else if(_media->media_type == MEDIA_CONTENT_TYPE_IMAGE)
3601 _media->image_meta->width = width;
3604 media_content_error("Invalid media type");
3605 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3608 return MEDIA_CONTENT_ERROR_NONE;
3611 int media_info_set_height(media_info_h media, int height)
3613 media_info_s *_media = (media_info_s*)media;
3617 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3618 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3621 if(_media->media_type == MEDIA_CONTENT_TYPE_VIDEO)
3622 _media->video_meta->height = height;
3623 else if(_media->media_type == MEDIA_CONTENT_TYPE_IMAGE)
3624 _media->image_meta->height = height;
3627 media_content_error("Invalid media type");
3628 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3631 return MEDIA_CONTENT_ERROR_NONE;
3634 int media_info_set_storage_type(media_info_h media, media_content_storage_e storage_type)
3636 media_info_s *_media = (media_info_s*)media;
3640 media_content_error("INVALID_PARAMETER(0x%08x)", MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
3641 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
3644 _media->storage_type = storage_type;
3646 return MEDIA_CONTENT_ERROR_NONE;