2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
\r
4 * Licensed under the Apache License, Version 2.0 (the "License");
\r
5 * you may not use this file except in compliance with the License.
\r
6 * You may obtain a copy of the License at
\r
8 * http://www.apache.org/licenses/LICENSE-2.0
\r
10 * Unless required by applicable law or agreed to in writing, software
\r
11 * distributed under the License is distributed on an "AS IS" BASIS,
\r
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
13 * See the License for the specific language governing permissions and
\r
14 * limitations under the License.
\r
18 #include <media_content.h>
\r
19 #include <media_info_private.h>
\r
20 #include <media-svc.h>
\r
21 #include <audio-svc.h>
\r
22 #include <audio-svc-error.h>
\r
23 #include <audio-svc-types.h>
\r
25 #include <visual-svc-error.h>
\r
26 #include <visual-svc-types.h>
\r
27 #include <visual-svc.h>
\r
29 #include <drm-service.h>
\r
38 #define LOG_TAG "TIZEN_N_MEDIACONTENT"
\r
40 extern MediaSvcHandle* db_handle;
\r
43 #define SELECT_AUDIO_FROM_MEDIA "select audio_uuid,genre,album,artist,author,year,copyright,description,format,bitrate,track_num,duration,rating,played_count,last_played_time,added_time,size,category from audio_media where audio_uuid='%s' "
\r
44 #define SELECT_TAG_LIST_FROM_MEDIA "select t._id, t.tag_name from (select _id, tag_name from visual_tag ORDER BY tag_name ASC ) t, ( select visual_uuid, tag_id from visual_tag_map where visual_uuid='%s' ) tm, ( select visual_uuid, folder_uuid from visual_media) m, ( select folder_uuid, lock_status from visual_folder where valid=1 ) f where tm.tag_id = t._id and m.visual_uuid = tm.visual_uuid and m.folder_uuid = f.folder_uuid and f.lock_status=0; "
\r
46 int media_info_insert_to_db(media_content_type_e type,const char* path)
\r
48 int ret= MEDIA_CONTENT_ERROR_NONE;
\r
51 minfo_file_type _type;
\r
54 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
55 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
60 case MEDIA_CONTENT_TYPE_IMAGE:
\r
61 _type = MINFO_ITEM_IMAGE;
\r
62 ret = minfo_add_media(db_handle, path, _type);
\r
63 ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
\r
65 case MEDIA_CONTENT_TYPE_VIDEO:
\r
66 _type = MINFO_ITEM_VIDEO;
\r
67 ret = minfo_add_media(db_handle, path, _type);
\r
68 ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
\r
71 case MEDIA_CONTENT_TYPE_AUDIO:
\r
72 storage_type = _content_get_storage_type(path);
\r
73 ret = _content_get_audio_category(path,&category);
\r
76 ret = audio_svc_insert_item(db_handle, storage_type,path,category);
\r
80 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
81 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
87 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
88 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
99 int media_info_destroy(media_info_h item)
\r
103 media_info_s* _item = (media_info_s*)item;
\r
108 free(_item->item_id);
\r
111 if(_item->file_path)
\r
113 free(_item->file_path);
\r
115 if(_item->display_name)
\r
117 free(_item->display_name);
\r
119 if(_item->thumbnail)
\r
121 free(_item->thumbnail);
\r
124 ret = MEDIA_CONTENT_ERROR_NONE;
\r
128 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
129 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
136 int media_info_clone(media_info_h* dst, media_info_h src)
\r
139 media_info_s* _src = (media_info_s*)src;
\r
144 media_info_s* _dst = (media_info_s*)calloc(1,sizeof(media_info_s));
\r
148 LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
\r
149 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
\r
152 _dst->item_id = strdup(_src->item_id);
\r
153 if( _dst->item_id == NULL)
\r
155 LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
\r
156 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
\r
158 _dst->date_modified= _src->date_modified;
\r
159 _dst->favorite = _src->favorite;
\r
160 _dst->media_type = _src->media_type;
\r
161 if((_src->file_path != NULL) && (strlen(_src->file_path) > 0))
\r
163 _dst->file_path = strdup(_src->file_path);
\r
164 if(_dst->file_path == NULL)
\r
166 LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
\r
167 media_info_destroy((media_info_h)_dst);
\r
168 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
\r
171 if((_src->display_name != NULL) && (strlen(_src->display_name) > 0))
\r
173 _dst->display_name = strdup(_src->display_name);
\r
174 if(_dst->display_name == NULL)
\r
176 LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
\r
177 media_info_destroy((media_info_h)_dst);
\r
178 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
\r
181 if((_src->thumbnail != NULL) && (strlen(_src->thumbnail) > 0))
\r
183 _dst->thumbnail = strdup(_src->thumbnail);
\r
184 if(_dst->thumbnail == NULL)
\r
186 LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
\r
187 media_info_destroy((media_info_h)_dst);
\r
188 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
\r
192 *dst = (media_info_h)_dst;
\r
193 ret = MEDIA_CONTENT_ERROR_NONE;
\r
197 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
198 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
204 int media_info_get_file_path(media_info_h item, char** path)
\r
207 media_info_s* _item = (media_info_s*)item;
\r
211 if((_item->file_path != NULL) && (strlen(_item->file_path) > 0))
\r
213 *path = strdup(_item->file_path);
\r
216 LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
\r
217 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
\r
224 ret = MEDIA_CONTENT_ERROR_NONE;
\r
229 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
230 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
237 int media_info_get_display_name(media_info_h item, char** name)
\r
240 media_info_s* _item = (media_info_s*)item;
\r
243 if((_item->display_name != NULL) && (strlen(_item->display_name) > 0))
\r
245 *name = strdup(_item->display_name);
\r
248 LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
\r
249 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
\r
256 ret = MEDIA_CONTENT_ERROR_NONE;
\r
261 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
262 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
269 int media_info_get_thumbnail_path(media_info_h item, char** path)
\r
272 media_info_s* _item = (media_info_s*)item;
\r
275 if((_item->thumbnail != NULL) && (strlen(_item->thumbnail) > 0))
\r
277 *path = strdup(_item->thumbnail);
\r
280 LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
\r
281 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
\r
288 ret = MEDIA_CONTENT_ERROR_NONE;
\r
293 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
294 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
301 int media_info_get_date_modified(media_info_h item, time_t* time)
\r
304 media_info_s* _item = (media_info_s*)item;
\r
307 *time = _item->date_modified;
\r
308 ret = MEDIA_CONTENT_ERROR_NONE;
\r
312 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
313 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
320 int media_info_get_media_type(media_info_h item, int* type)
\r
323 media_info_s* _item = (media_info_s*)item;
\r
326 *type = _item->media_type;
\r
327 ret = MEDIA_CONTENT_ERROR_NONE;
\r
331 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
332 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
339 int media_info_get_favorite(media_info_h media, int* favorite)
\r
342 media_info_s* _media = (media_info_s*)media;
\r
346 *favorite = _media->favorite;
\r
347 ret = MEDIA_CONTENT_ERROR_NONE;
\r
351 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
352 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
360 int media_info_update_favorite_to_db(media_info_h media, int favorite)
\r
362 int ret = MEDIA_CONTENT_ERROR_NONE;
\r
363 media_info_s* _media = (media_info_s*)media;
\r
367 if(_media->media_type == MEDIA_CONTENT_TYPE_AUDIO)
\r
371 ret = audio_svc_add_item_to_playlist( db_handle, AUDIO_SVC_FAVORITE_LIST_ID, _media->item_id);
\r
375 ret = audio_svc_remove_item_from_playlist_by_audio_id(db_handle, AUDIO_SVC_FAVORITE_LIST_ID, _media->item_id);
\r
380 ret = minfo_update_media_favorite(db_handle, _media->item_id,favorite);
\r
382 ret = _content_error_capi(MEDIA_CONTENT_TYPE,ret);
\r
386 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
387 ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
396 int media_info_foreach_media_from_db(media_info_filter_h filter,media_info_cb callback, void* user_data)
\r
398 int ret= MEDIA_CONTENT_ERROR_NONE;
\r
400 char limit_query[MIN_QUERY_SIZE];
\r
401 char condition_query[DEFAULT_QUERY_SIZE];
\r
402 char search_query[MAX_KEYWORD_SIZE];
\r
403 char condition_type[MIN_QUERY_SIZE];
\r
404 char select_query[DEFAULT_QUERY_SIZE];
\r
405 char order_query[MIN_QUERY_SIZE];
\r
408 sqlite3_stmt *stmt = NULL;
\r
411 media_info_filter_s* _filter = NULL;
\r
413 if( callback == NULL )
\r
415 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
416 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
423 _filter = (media_info_filter_s*)filter;
\r
425 if(!(_filter->media_type & (MEDIA_CONTENT_TYPE_IMAGE | MEDIA_CONTENT_TYPE_VIDEO | MEDIA_CONTENT_TYPE_AUDIO)) )
\r
427 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
428 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
433 ret = media_info_filter_create((media_info_filter_h*)&_filter);
\r
435 if(ret != MEDIA_CONTENT_ERROR_NONE)
\r
440 if(_filter->media_type == 0)
\r
442 _filter->media_type = (MEDIA_CONTENT_TYPE_IMAGE | MEDIA_CONTENT_TYPE_VIDEO | MEDIA_CONTENT_TYPE_AUDIO);
\r
446 memset(order_query,0x00,sizeof(order_query));
\r
447 memset(condition_type,0x00,sizeof(condition_type));
\r
448 memset(condition_query,0x00,sizeof(condition_query));
\r
449 memset(limit_query,0x00,sizeof(limit_query));
\r
450 memset(search_query,0x00,sizeof(search_query));
\r
451 memset(select_query,0x00,sizeof(select_query));
\r
454 if((_filter->keyword != NULL) && strlen(_filter->keyword) > 0)
\r
456 if(strlen(_filter->keyword) < sizeof(search_query))
\r
458 snprintf(search_query,sizeof(search_query)," and display_name like '%%%s%%'", _filter->keyword);
\r
462 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
463 if((media_info_filter_s*)filter != _filter)
\r
464 media_info_filter_destroy((media_info_filter_h)_filter);
\r
465 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
470 search_query[0] = ' ';
\r
473 snprintf(limit_query,sizeof(limit_query),"%s %d,%d",QUERY_KEYWORD_LIMIT,_filter->offset,_filter->count);
\r
476 if(_filter->media_type & MEDIA_CONTENT_TYPE_IMAGE)
\r
478 strncat(condition_type,CONDITION_TYPE_IMAGE,strlen(CONDITION_TYPE_IMAGE));
\r
480 if(_filter->media_type & MEDIA_CONTENT_TYPE_VIDEO)
\r
482 if(strlen(condition_type) > 0 )
\r
484 strncat(condition_type,QUERY_KEYWORD_SPACE, strlen(QUERY_KEYWORD_SPACE));
\r
485 strncat(condition_type,QUERY_KEYWORD_OR, strlen(QUERY_KEYWORD_OR));
\r
486 strncat(condition_type,QUERY_KEYWORD_SPACE, strlen(QUERY_KEYWORD_SPACE));
\r
488 strncat(condition_type,CONDITION_TYPE_VIDEO,strlen(CONDITION_TYPE_VIDEO));
\r
491 if(_filter->media_type & MEDIA_CONTENT_TYPE_AUDIO)
\r
493 if(strlen(condition_type) > 0 )
\r
495 strncat(condition_type,QUERY_KEYWORD_SPACE, strlen(QUERY_KEYWORD_SPACE));
\r
496 strncat(condition_type,QUERY_KEYWORD_OR, strlen(QUERY_KEYWORD_OR));
\r
497 strncat(condition_type,QUERY_KEYWORD_SPACE, strlen(QUERY_KEYWORD_SPACE));
\r
500 strncat(condition_type,CONDITION_TYPE_AUDIO,strlen(CONDITION_TYPE_AUDIO));
\r
504 snprintf(select_query,sizeof(select_query),"%s", SELECT_MEDIA_ITEM);
\r
506 snprintf(condition_query,sizeof(condition_query), "%s (%s)", QUERY_KEYWORD_AND, condition_type);
\r
508 if(_filter->order == MEDIA_CONTENT_SORT_BY_NAME_ASC)
\r
510 snprintf(order_query,sizeof(order_query),"%s %s",QUERY_KEYWORD_ORDER_BY,DB_FILED_DISPLAY_NAME);
\r
512 else if(_filter->order == MEDIA_CONTENT_SORT_BY_NAME_DESC)
\r
514 snprintf(order_query,sizeof(order_query),"%s %s %s",QUERY_KEYWORD_ORDER_BY,DB_FILED_DISPLAY_NAME,QUERY_KEYWORD_DESC);
\r
516 else if(_filter->order == MEDIA_CONTENT_SORT_BY_DATE_ASC)
\r
518 snprintf(order_query,sizeof(order_query),"%s %s",QUERY_KEYWORD_ORDER_BY,DB_FILED_DATE_MODIFIED);
\r
520 else if(_filter->order == MEDIA_CONTENT_SORT_BY_DATE_DESC)
\r
522 snprintf(order_query,sizeof(order_query),"%s %s %s",QUERY_KEYWORD_ORDER_BY,DB_FILED_DATE_MODIFIED,QUERY_KEYWORD_DESC);
\r
526 if((media_info_filter_s*)filter != _filter)
\r
527 media_info_filter_destroy((media_info_filter_h)_filter);
\r
530 ret = _content_query_prepare(&stmt,select_query,condition_query, search_query,limit_query,order_query);
\r
531 if( ret != MEDIA_CONTENT_ERROR_NONE)
\r
535 while( sqlite3_step(stmt) == SQLITE_ROW)
\r
537 media_info_s* item1 = (media_info_s*)calloc(1,sizeof(media_info_s));
\r
541 LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
\r
542 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
\r
544 _content_item_get_detail(stmt,(media_info_h)item1);
\r
546 if( callback((media_info_h)item1,user_data) == false)
\r
548 media_info_destroy((media_info_h) item1);
\r
551 media_info_destroy((media_info_h) item1);
\r
556 sqlite3_finalize(stmt);
\r
565 int media_info_get_image_from_db(media_info_h item, image_meta_h* image)
\r
568 int ret = MEDIA_CONTENT_ERROR_NONE;
\r
569 Mitem* p_item = NULL;
\r
570 image_meta_s* _image = NULL;
\r
574 media_info_s* _item = (media_info_s*)item;
\r
576 if( _item == NULL )
\r
578 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
579 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
582 if(_item->media_type != MEDIA_CONTENT_TYPE_IMAGE)
\r
584 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
585 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
588 p_ret = minfo_get_item_by_id(db_handle, _item->item_id,&p_item);
\r
590 ret = _content_error_capi(MEDIA_CONTENT_TYPE,p_ret);
\r
591 if( (ret == MEDIA_CONTENT_ERROR_NONE) && ( p_item != NULL))
\r
593 ret = minfo_get_meta_info(db_handle, _item->item_id,&(p_item->meta_info));
\r
594 ret = _content_error_capi(MEDIA_CONTENT_TYPE,p_ret);
\r
596 if( ret != MEDIA_CONTENT_ERROR_NONE)
\r
598 minfo_destroy_mtype_item(p_item);
\r
601 _image = (image_meta_s*)calloc(1, sizeof(image_meta_s));
\r
604 LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
\r
605 minfo_destroy_mtype_item(p_item);
\r
606 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
\r
610 _image->image_id = strdup(p_item->uuid);
\r
611 if(p_item->thumb_url != NULL)
\r
612 _image->thumbnail = strdup(p_item->thumb_url);
\r
613 if(p_item->rate > 0)
\r
614 _image->favorite = true;
\r
616 _image->favorite = false;
\r
618 if(p_item->meta_info != NULL)
\r
620 _image->longitude = p_item->meta_info->longitude;
\r
621 _image->latitude = p_item->meta_info->latitude;
\r
622 _image->width = p_item->meta_info->width;
\r
623 _image->height = p_item->meta_info->height;
\r
624 _image->date_taken = p_item->meta_info->datetaken;
\r
625 if(p_item->meta_info->description != NULL)
\r
626 _image->description = strdup(p_item->meta_info->description);
\r
628 if((p_item->meta_info != NULL) && (p_item->meta_info->image_info != NULL))
\r
630 _image->orientation = p_item->meta_info->image_info->orientation;
\r
633 *image = (image_meta_h)_image;
\r
634 p_ret = minfo_destroy_mtype_item(p_item);
\r
635 ret = _content_error_capi(MEDIA_CONTENT_TYPE,p_ret);
\r
643 int media_info_get_video_from_db(media_info_h item, video_meta_h* video)
\r
647 int ret = MEDIA_CONTENT_ERROR_NONE;
\r
648 Mitem* p_item = NULL;
\r
649 video_meta_s* _video = NULL;
\r
652 media_info_s* _item = (media_info_s*)item;
\r
653 if( _item == NULL )
\r
655 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
656 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
659 if(_item->media_type != MEDIA_CONTENT_TYPE_VIDEO)
\r
661 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
662 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
665 p_ret = minfo_get_item_by_id(db_handle, _item->item_id,&p_item);
\r
668 ret = _content_error_capi(MEDIA_CONTENT_TYPE,p_ret);
\r
669 if( (ret == MEDIA_CONTENT_ERROR_NONE) && ( p_item != NULL))
\r
671 ret = minfo_get_meta_info(db_handle, _item->item_id,&(p_item->meta_info));
\r
672 ret = _content_error_capi(MEDIA_CONTENT_TYPE,p_ret);
\r
673 if( ret != MEDIA_CONTENT_ERROR_NONE)
\r
675 minfo_destroy_mtype_item(p_item);
\r
679 _video = (video_meta_s*)calloc(1,sizeof(video_meta_s));
\r
680 if( _video == NULL)
\r
682 LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
\r
683 minfo_destroy_mtype_item(p_item);
\r
684 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
\r
687 _video->video_id = strdup(p_item->uuid);
\r
688 if(p_item->thumb_url)
\r
689 _video->thumbnail = strdup(p_item->thumb_url);
\r
691 if(p_item->rate > 0)
\r
692 _video->favorite = true;
\r
694 _video->favorite = false;
\r
697 if(p_item->meta_info != NULL)
\r
699 _video->longitude = p_item->meta_info->longitude;
\r
700 _video->latitude = p_item->meta_info->latitude;
\r
701 _video->width = p_item->meta_info->width;
\r
702 _video->height = p_item->meta_info->height;
\r
703 _video->date_taken = p_item->meta_info->datetaken;
\r
704 if(p_item->meta_info->description)
\r
705 _video->description = strdup(p_item->meta_info->description);
\r
707 if((p_item->meta_info != NULL) && (p_item->meta_info->video_info != NULL))
\r
709 if(p_item->meta_info->video_info->album_name != NULL)
\r
711 _video->album = strdup(p_item->meta_info->video_info->album_name);
\r
713 if(p_item->meta_info->video_info->artist_name != NULL)
\r
714 _video->artist = strdup(p_item->meta_info->video_info->artist_name);
\r
715 if(p_item->meta_info->video_info->title != NULL)
\r
716 _video->title = strdup(p_item->meta_info->video_info->title);
\r
719 _video->time_played = p_item->meta_info->video_info->last_played_pos;
\r
720 _video->duration = p_item->meta_info->video_info->duration;
\r
722 *video = (video_meta_h)_video;
\r
723 p_ret = minfo_destroy_mtype_item(p_item);
\r
724 ret = _content_error_capi(MEDIA_CONTENT_TYPE,p_ret);
\r
730 int media_info_get_audio_from_db(media_info_h item, audio_meta_h* audio)
\r
732 int ret = MEDIA_CONTENT_ERROR_NONE;
\r
734 media_info_s* _item = (media_info_s*)item;
\r
736 char select_query[DEFAULT_QUERY_SIZE];
\r
737 sqlite3_stmt *stmt = NULL;
\r
741 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
742 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
745 if(_item->media_type != MEDIA_CONTENT_TYPE_AUDIO)
\r
747 LOGE("[%s] the type of media is not an audio.",__func__);
\r
748 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
752 memset(select_query,0x00,sizeof(select_query));
\r
754 snprintf(select_query,sizeof(select_query), SELECT_AUDIO_FROM_MEDIA,_item->item_id);
\r
756 ret = _content_query_prepare(&stmt,select_query,NULL,NULL,NULL,NULL);
\r
759 if( ret != MEDIA_CONTENT_ERROR_NONE)
\r
763 audio_meta_s* _audio = (audio_meta_s*)calloc(1,sizeof(audio_meta_s));
\r
766 LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
\r
767 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
\r
771 while( sqlite3_step(stmt) == SQLITE_ROW)
\r
773 _audio->audio_id = strdup((const char *)sqlite3_column_text(stmt, 0));
\r
774 _audio->genre = strdup((const char *)sqlite3_column_text(stmt, 1));
\r
775 _audio->album = strdup((const char *)sqlite3_column_text(stmt, 2));
\r
776 _audio->artist= strdup((const char *)sqlite3_column_text(stmt, 3));
\r
777 _audio->author= strdup((const char *)sqlite3_column_text(stmt, 4));
\r
778 _audio->year= strdup((const char *)sqlite3_column_text(stmt, 5));
\r
779 _audio->copyright= strdup((const char *)sqlite3_column_text(stmt, 6));
\r
780 _audio->description= strdup((const char *)sqlite3_column_text(stmt, 7));
\r
781 _audio->format= strdup((const char *)sqlite3_column_text(stmt, 8));
\r
782 _audio->bitrate = (int)sqlite3_column_int(stmt,9);
\r
783 _audio->track_num = (int)sqlite3_column_int(stmt,10);
\r
784 _audio->duration = (int)sqlite3_column_int(stmt,11);
\r
785 _audio->rating = (int)sqlite3_column_int(stmt,12);
\r
786 _audio->count_played = (int)sqlite3_column_int(stmt,13);
\r
787 _audio->time_played = (int)sqlite3_column_int(stmt,14);
\r
788 _audio->time_added = (int)sqlite3_column_int(stmt,15);
\r
789 _audio->size = (int)sqlite3_column_int(stmt,16);
\r
790 _audio->category = (int)sqlite3_column_int(stmt,17);
\r
792 *audio = (audio_meta_h)_audio;
\r
795 sqlite3_finalize(stmt);
\r
804 int media_info_foreach_tag_from_db(media_info_h item, media_tag_cb callback, void *user_data)
\r
806 int ret = MEDIA_CONTENT_ERROR_NONE;
\r
807 char select_query[DEFAULT_QUERY_SIZE];
\r
808 sqlite3_stmt *stmt = NULL;
\r
810 media_info_s* _item = (media_info_s*)item;
\r
814 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
815 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
817 if(callback == NULL)
\r
819 LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
\r
820 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
823 snprintf(select_query,sizeof(select_query),SELECT_TAG_LIST_FROM_MEDIA,_item->item_id);
\r
824 ret = _content_query_prepare(&stmt,select_query,NULL,NULL,NULL,NULL);
\r
825 if(ret != MEDIA_CONTENT_ERROR_NONE)
\r
828 while( sqlite3_step(stmt) == SQLITE_ROW)
\r
830 media_tag_s* _tag = (media_tag_s*)calloc(1,sizeof(media_tag_s));
\r
834 LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
\r
835 return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
\r
838 _tag->tag_id = (int)sqlite3_column_int(stmt,0);
\r
839 _tag->name = strdup((const char *)sqlite3_column_text(stmt, 1));
\r
840 if(callback((media_tag_h)_tag,user_data) == false)
\r
842 media_tag_destroy((media_tag_h) _tag);
\r
845 media_tag_destroy((media_tag_h) _tag);
\r
851 sqlite3_finalize(stmt);
\r
858 void _content_item_get_detail(sqlite3_stmt* stmt, media_info_h item)
\r
860 //item_id, file_path, display_name, thumbnail, date_modified,content_type, valid
\r
861 media_info_s* _item = (media_info_s*)item;
\r
862 _item->item_id = strdup((const char *)sqlite3_column_text(stmt, 0));
\r
863 _item->file_path= strdup((const char *)sqlite3_column_text(stmt, 1));
\r
864 _item->display_name=strdup((const char *)sqlite3_column_text(stmt, 2));
\r
865 _item->thumbnail=strdup((const char *)sqlite3_column_text(stmt, 3));
\r
866 _item->date_modified = (int)sqlite3_column_int(stmt,4);
\r
867 _item->media_type = (int)sqlite3_column_int(stmt,5);
\r
868 _item->media_type = _item->media_type==3?4:_item->media_type;
\r
869 _item->favorite = (int)sqlite3_column_int(stmt,6);
\r
872 int _content_get_storage_type(const char* full_path)
\r
874 if (full_path != NULL) {
\r
875 if (strncmp(full_path, MEDIA_CONTENT_PATH_PHONE , strlen(MEDIA_CONTENT_PATH_PHONE )) == 0)
\r
877 return MEDIA_CONTENT_STORAGE_INTERNAL;
\r
879 else if (strncmp(full_path, MEDIA_CONTENT_PATH_MMC , strlen(MEDIA_CONTENT_PATH_MMC )) == 0)
\r
881 return MEDIA_CONTENT_STORAGE_EXTERNAL;
\r
885 return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
\r
889 #define CONTENT_TYPE_NUM 4
\r
890 #define FEX_CATEGORY_UNKNOWN 0x00000000 /**< Default */
\r
891 #define FEX_CATEGORY_ETC 0x00000001 /**< ETC category */
\r
892 #define FEX_CATEGORY_IMAGE 0x00000002 /**< Image category */
\r
893 #define FEX_CATEGORY_VIDEO 0x00000004 /**< Video category */
\r
894 #define FEX_CATEGORY_MUSIC 0x00000008 /**< Music category */
\r
895 #define FEX_CATEGORY_SOUND 0x00000010 /**< Sound category */
\r
896 #define FEX_CATEGORY_DRM 0x00000020 /**< DRM category */
\r
897 #define SOUND_MIME_NUM 1
\r
898 #define MINE_LENGTH 30
\r
899 #define MUSIC_MIME_NUM 12
\r
904 char content_type[15];
\r
905 int category_by_mime;
\r
906 }fex_content_table_t;
\r
908 static const fex_content_table_t content_category[CONTENT_TYPE_NUM] = {
\r
909 {"audio", FEX_CATEGORY_SOUND},
\r
910 {"image", FEX_CATEGORY_IMAGE},
\r
911 {"video", FEX_CATEGORY_VIDEO},
\r
912 {"application", FEX_CATEGORY_ETC},
\r
915 static const char sound_mime_table[SOUND_MIME_NUM][MINE_LENGTH] = {
\r
918 static const char music_mime_table[MUSIC_MIME_NUM][MINE_LENGTH] = {
\r
923 "vnd.rn-realaudio",
\r
933 #define FMS_DRM_CONTENT_TYPE_LENGTH 100
\r
935 int _content_get_audio_category(const char* file_full_path,int* category)
\r
938 char mimetype[255] = {0,};
\r
940 bool is_drm = false;
\r
941 drm_content_info_t contentInfo = {0};
\r
943 if (file_full_path == NULL)
\r
944 return FEX_CATEGORY_UNKNOWN;
\r
947 if (drm_svc_is_drm_file(file_full_path) == DRM_TRUE)
\r
950 // 2008.8.13 han. In this case, use drm_svc_get_content_info api.
\r
951 result = drm_svc_get_content_info(file_full_path, &contentInfo);
\r
952 if (result != DRM_RESULT_SUCCESS)
\r
954 *category = FEX_CATEGORY_UNKNOWN;
\r
957 strncpy(mimetype, contentInfo.contentType, strlen(contentInfo.contentType)+1);
\r
958 *category = *category | FEX_CATEGORY_DRM;
\r
963 result = aul_get_mime_from_file(file_full_path, mimetype, sizeof(mimetype));
\r
966 *category = FEX_CATEGORY_UNKNOWN;
\r
971 for(i = 0; i < CONTENT_TYPE_NUM; i ++)
\r
973 if (strstr(mimetype, content_category[i].content_type) != NULL)
\r
975 *category = (*category | content_category[i].category_by_mime);
\r
979 if (*category & FEX_CATEGORY_ETC)
\r
981 int prefix_len = strlen(content_category[0].content_type);
\r
983 for(i = 0; i < SOUND_MIME_NUM; i ++)
\r
985 if (strstr(mimetype+prefix_len, sound_mime_table[i]) != NULL)
\r
987 *category = FEX_CATEGORY_SOUND;
\r
993 *category = *category | FEX_CATEGORY_DRM;;
\r
996 if (!(*category & FEX_CATEGORY_SOUND))
\r
1002 if(is_drm) //if sound file is DRM, it is always music file.
\r
1004 *category = FEX_CATEGORY_MUSIC;
\r
1005 *category = *category | FEX_CATEGORY_DRM;
\r
1007 else //check music file in sound files.
\r
1009 int prefix_len = strlen(content_category[0].content_type);
\r
1011 for(i = 0; i < MUSIC_MIME_NUM; i ++)
\r
1013 if (strstr(mimetype+prefix_len, music_mime_table[i]) != NULL)
\r
1015 *category = FEX_CATEGORY_MUSIC;
\r