1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
|
/*
* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <media_content.h>
#include <media_info_private.h>
#include <media-svc.h>
#include <audio-svc.h>
#include <audio-svc-error.h>
#include <audio-svc-types.h>
#include <visual-svc-error.h>
#include <visual-svc-types.h>
#include <visual-svc.h>
#include <drm-service.h>
#include <aul.h>
#include <dlog.h>
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "TIZEN_N_MEDIACONTENT"
//extern MediaSvcHandle* db_handle;
#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' "
#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; "
int media_info_insert_to_db(media_content_type_e type,const char* path)
{
int ret= MEDIA_CONTENT_ERROR_NONE;
int storage_type;
int category=0;
minfo_file_type _type;
if(path == NULL)
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
switch(type)
{
case MEDIA_CONTENT_TYPE_IMAGE:
_type = MINFO_ITEM_IMAGE;
ret = minfo_add_media(_content_get_db_handle(), path, _type);
ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
break;
case MEDIA_CONTENT_TYPE_VIDEO:
_type = MINFO_ITEM_VIDEO;
ret = minfo_add_media(_content_get_db_handle(), path, _type);
ret = _content_error_capi(MEDIA_CONTENT_TYPE, ret);
break;
case MEDIA_CONTENT_TYPE_AUDIO:
storage_type = _content_get_storage_type(path);
ret = _content_get_audio_category(path,&category);
if(ret >= 0)
{
ret = audio_svc_insert_item(_content_get_db_handle(), storage_type,path,category);
}
else
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
break;
default:
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
break;
}
return ret;
}
int media_info_destroy(media_info_h item)
{
int ret;
media_info_s* _item = (media_info_s*)item;
if(_item)
{
if(_item->item_id)
{
free(_item->item_id);
}
if(_item->file_path)
{
free(_item->file_path);
}
if(_item->display_name)
{
free(_item->display_name);
}
if(_item->thumbnail)
{
free(_item->thumbnail);
}
free(_item);
ret = MEDIA_CONTENT_ERROR_NONE;
}
else
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
return ret;
}
int media_info_clone(media_info_h* dst, media_info_h src)
{
int ret;
media_info_s* _src = (media_info_s*)src;
if(_src != NULL )
{
media_info_s* _dst = (media_info_s*)calloc(1,sizeof(media_info_s));
if(_dst == NULL)
{
LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
_dst->item_id = strdup(_src->item_id);
if( _dst->item_id == NULL)
{
LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
_dst->date_modified= _src->date_modified;
_dst->favorite = _src->favorite;
_dst->media_type = _src->media_type;
if((_src->file_path != NULL) && (strlen(_src->file_path) > 0))
{
_dst->file_path = strdup(_src->file_path);
if(_dst->file_path == NULL)
{
LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
media_info_destroy((media_info_h)_dst);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
}
if((_src->display_name != NULL) && (strlen(_src->display_name) > 0))
{
_dst->display_name = strdup(_src->display_name);
if(_dst->display_name == NULL)
{
LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
media_info_destroy((media_info_h)_dst);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
}
if((_src->thumbnail != NULL) && (strlen(_src->thumbnail) > 0))
{
_dst->thumbnail = strdup(_src->thumbnail);
if(_dst->thumbnail == NULL)
{
LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
media_info_destroy((media_info_h)_dst);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
}
*dst = (media_info_h)_dst;
ret = MEDIA_CONTENT_ERROR_NONE;
}
else
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
return ret;
}
int media_info_get_file_path(media_info_h item, char** path)
{
int ret;
media_info_s* _item = (media_info_s*)item;
if(_item)
{
if((_item->file_path != NULL) && (strlen(_item->file_path) > 0))
{
*path = strdup(_item->file_path);
if(*path == NULL)
{
LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
}
else
{
*path = NULL;
}
ret = MEDIA_CONTENT_ERROR_NONE;
}
else
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
return ret;
}
int media_info_get_display_name(media_info_h item, char** name)
{
int ret;
media_info_s* _item = (media_info_s*)item;
if(_item)
{
if((_item->display_name != NULL) && (strlen(_item->display_name) > 0))
{
*name = strdup(_item->display_name);
if(*name == NULL)
{
LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
}
else
{
*name = NULL;
}
ret = MEDIA_CONTENT_ERROR_NONE;
}
else
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
return ret;
}
int media_info_get_thumbnail_path(media_info_h item, char** path)
{
int ret;
media_info_s* _item = (media_info_s*)item;
if(_item)
{
if((_item->thumbnail != NULL) && (strlen(_item->thumbnail) > 0))
{
*path = strdup(_item->thumbnail);
if(*path == NULL)
{
LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
}
else
{
*path = NULL;
}
ret = MEDIA_CONTENT_ERROR_NONE;
}
else
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
return ret;
}
int media_info_get_date_modified(media_info_h item, time_t* time)
{
int ret;
media_info_s* _item = (media_info_s*)item;
if(_item)
{
*time = _item->date_modified;
ret = MEDIA_CONTENT_ERROR_NONE;
}
else
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
return ret;
}
int media_info_get_media_type(media_info_h item, int* type)
{
int ret;
media_info_s* _item = (media_info_s*)item;
if(_item)
{
*type = _item->media_type;
ret = MEDIA_CONTENT_ERROR_NONE;
}
else
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
return ret;
}
int media_info_get_favorite(media_info_h media, int* favorite)
{
int ret;
media_info_s* _media = (media_info_s*)media;
if(_media)
{
*favorite = _media->favorite;
ret = MEDIA_CONTENT_ERROR_NONE;
}
else
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
return ret;
}
int media_info_update_favorite_to_db(media_info_h media, int favorite)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
media_info_s* _media = (media_info_s*)media;
if(media != NULL)
{
if(_media->media_type == MEDIA_CONTENT_TYPE_AUDIO)
{
if(favorite)
{
ret = audio_svc_add_item_to_playlist( _content_get_db_handle(), AUDIO_SVC_FAVORITE_LIST_ID, _media->item_id);
}
else
{
ret = audio_svc_remove_item_from_playlist_by_audio_id(_content_get_db_handle(), AUDIO_SVC_FAVORITE_LIST_ID, _media->item_id);
}
}
else
{
ret = minfo_update_media_favorite(_content_get_db_handle(), _media->item_id,favorite);
}
ret = _content_error_capi(MEDIA_CONTENT_TYPE,ret);
if(ret == MEDIA_CONTENT_ERROR_NONE)
{
_media->favorite = favorite;
}
}
else
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
ret = MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
return ret;
}
int media_info_foreach_media_from_db(media_info_filter_h filter,media_info_cb callback, void* user_data)
{
int ret= MEDIA_CONTENT_ERROR_NONE;
char limit_query[MIN_QUERY_SIZE];
char condition_query[DEFAULT_QUERY_SIZE];
char search_query[MAX_KEYWORD_SIZE];
char condition_type[MIN_QUERY_SIZE];
char select_query[DEFAULT_QUERY_SIZE];
char order_query[MIN_QUERY_SIZE];
sqlite3_stmt *stmt = NULL;
media_info_filter_s* _filter = NULL;
if( callback == NULL )
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
if(filter != NULL)
{
_filter = (media_info_filter_s*)filter;
if(!(_filter->media_type & (MEDIA_CONTENT_TYPE_IMAGE | MEDIA_CONTENT_TYPE_VIDEO | MEDIA_CONTENT_TYPE_AUDIO)) )
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
}
else
{
ret = media_info_filter_create((media_info_filter_h*)&_filter);
if(ret != MEDIA_CONTENT_ERROR_NONE)
{
return ret;
}
if(_filter->media_type == 0)
{
_filter->media_type = (MEDIA_CONTENT_TYPE_IMAGE | MEDIA_CONTENT_TYPE_VIDEO | MEDIA_CONTENT_TYPE_AUDIO);
}
}
memset(order_query,0x00,sizeof(order_query));
memset(condition_type,0x00,sizeof(condition_type));
memset(condition_query,0x00,sizeof(condition_query));
memset(limit_query,0x00,sizeof(limit_query));
memset(search_query,0x00,sizeof(search_query));
memset(select_query,0x00,sizeof(select_query));
if((_filter->keyword != NULL) && strlen(_filter->keyword) > 0)
{
if(strlen(_filter->keyword) < sizeof(search_query))
{
snprintf(search_query,sizeof(search_query)," and display_name like '%%%s%%'", _filter->keyword);
}
else
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
if((media_info_filter_s*)filter != _filter)
media_info_filter_destroy((media_info_filter_h)_filter);
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
}
else
{
search_query[0] = ' ';
}
snprintf(limit_query,sizeof(limit_query),"%s %d,%d",QUERY_KEYWORD_LIMIT,_filter->offset,_filter->count);
if(_filter->media_type & MEDIA_CONTENT_TYPE_IMAGE)
{
strncat(condition_type,CONDITION_TYPE_IMAGE,strlen(CONDITION_TYPE_IMAGE));
}
if(_filter->media_type & MEDIA_CONTENT_TYPE_VIDEO)
{
if(strlen(condition_type) > 0 )
{
strncat(condition_type,QUERY_KEYWORD_SPACE, strlen(QUERY_KEYWORD_SPACE));
strncat(condition_type,QUERY_KEYWORD_OR, strlen(QUERY_KEYWORD_OR));
strncat(condition_type,QUERY_KEYWORD_SPACE, strlen(QUERY_KEYWORD_SPACE));
}
strncat(condition_type,CONDITION_TYPE_VIDEO,strlen(CONDITION_TYPE_VIDEO));
}
if(_filter->media_type & MEDIA_CONTENT_TYPE_AUDIO)
{
if(strlen(condition_type) > 0 )
{
strncat(condition_type,QUERY_KEYWORD_SPACE, strlen(QUERY_KEYWORD_SPACE));
strncat(condition_type,QUERY_KEYWORD_OR, strlen(QUERY_KEYWORD_OR));
strncat(condition_type,QUERY_KEYWORD_SPACE, strlen(QUERY_KEYWORD_SPACE));
}
strncat(condition_type,CONDITION_TYPE_AUDIO,strlen(CONDITION_TYPE_AUDIO));
}
snprintf(select_query,sizeof(select_query),"%s", SELECT_MEDIA_ITEM);
snprintf(condition_query,sizeof(condition_query), "%s (%s)", QUERY_KEYWORD_AND, condition_type);
if(_filter->order == MEDIA_CONTENT_SORT_BY_NAME_ASC)
{
snprintf(order_query,sizeof(order_query),"%s %s",QUERY_KEYWORD_ORDER_BY,DB_FILED_DISPLAY_NAME);
}
else if(_filter->order == MEDIA_CONTENT_SORT_BY_NAME_DESC)
{
snprintf(order_query,sizeof(order_query),"%s %s %s",QUERY_KEYWORD_ORDER_BY,DB_FILED_DISPLAY_NAME,QUERY_KEYWORD_DESC);
}
else if(_filter->order == MEDIA_CONTENT_SORT_BY_DATE_ASC)
{
snprintf(order_query,sizeof(order_query),"%s %s",QUERY_KEYWORD_ORDER_BY,DB_FILED_DATE_MODIFIED);
}
else if(_filter->order == MEDIA_CONTENT_SORT_BY_DATE_DESC)
{
snprintf(order_query,sizeof(order_query),"%s %s %s",QUERY_KEYWORD_ORDER_BY,DB_FILED_DATE_MODIFIED,QUERY_KEYWORD_DESC);
}
if((media_info_filter_s*)filter != _filter)
media_info_filter_destroy((media_info_filter_h)_filter);
ret = _content_query_prepare(&stmt,select_query,condition_query, search_query,limit_query,order_query);
if( ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
while( sqlite3_step(stmt) == SQLITE_ROW)
{
media_info_s* item1 = (media_info_s*)calloc(1,sizeof(media_info_s));
if(item1 == NULL)
{
LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
_content_item_get_detail(stmt,(media_info_h)item1);
if( callback((media_info_h)item1,user_data) == false)
{
media_info_destroy((media_info_h) item1);
break;
}
media_info_destroy((media_info_h) item1);
}
if(stmt != NULL)
{
sqlite3_finalize(stmt);
}
return ret;
}
int media_info_get_image_from_db(media_info_h item, image_meta_h* image)
{
int p_ret;
int ret = MEDIA_CONTENT_ERROR_NONE;
Mitem* p_item = NULL;
image_meta_s* _image = NULL;
media_info_s* _item = (media_info_s*)item;
if( _item == NULL )
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
if(_item->media_type != MEDIA_CONTENT_TYPE_IMAGE)
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
p_ret = minfo_get_item_by_id(_content_get_db_handle(), _item->item_id,&p_item);
ret = _content_error_capi(MEDIA_CONTENT_TYPE,p_ret);
if( (ret == MEDIA_CONTENT_ERROR_NONE) && ( p_item != NULL))
{
ret = minfo_get_meta_info(_content_get_db_handle(), _item->item_id,&(p_item->meta_info));
ret = _content_error_capi(MEDIA_CONTENT_TYPE,p_ret);
if( ret != MEDIA_CONTENT_ERROR_NONE)
{
minfo_destroy_mtype_item(p_item);
return ret;
}
_image = (image_meta_s*)calloc(1, sizeof(image_meta_s));
if(_image == NULL)
{
LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
minfo_destroy_mtype_item(p_item);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
_image->image_id = strdup(p_item->uuid);
if(p_item->thumb_url != NULL)
_image->thumbnail = strdup(p_item->thumb_url);
if(p_item->rate > 0)
_image->favorite = true;
else
_image->favorite = false;
if(p_item->meta_info != NULL)
{
_image->longitude = p_item->meta_info->longitude;
_image->latitude = p_item->meta_info->latitude;
_image->width = p_item->meta_info->width;
_image->height = p_item->meta_info->height;
_image->date_taken = p_item->meta_info->datetaken;
if(p_item->meta_info->description != NULL)
_image->description = strdup(p_item->meta_info->description);
}
if((p_item->meta_info != NULL) && (p_item->meta_info->image_info != NULL))
{
_image->orientation = p_item->meta_info->image_info->orientation;
}
*image = (image_meta_h)_image;
p_ret = minfo_destroy_mtype_item(p_item);
ret = _content_error_capi(MEDIA_CONTENT_TYPE,p_ret);
}
return ret;
}
int media_info_get_video_from_db(media_info_h item, video_meta_h* video)
{
int p_ret;
int ret = MEDIA_CONTENT_ERROR_NONE;
Mitem* p_item = NULL;
video_meta_s* _video = NULL;
media_info_s* _item = (media_info_s*)item;
if( _item == NULL )
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
if(_item->media_type != MEDIA_CONTENT_TYPE_VIDEO)
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
p_ret = minfo_get_item_by_id(_content_get_db_handle(), _item->item_id,&p_item);
ret = _content_error_capi(MEDIA_CONTENT_TYPE,p_ret);
if( (ret == MEDIA_CONTENT_ERROR_NONE) && ( p_item != NULL))
{
ret = minfo_get_meta_info(_content_get_db_handle(), _item->item_id,&(p_item->meta_info));
ret = _content_error_capi(MEDIA_CONTENT_TYPE,p_ret);
if( ret != MEDIA_CONTENT_ERROR_NONE)
{
minfo_destroy_mtype_item(p_item);
return ret;
}
_video = (video_meta_s*)calloc(1,sizeof(video_meta_s));
if( _video == NULL)
{
LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
minfo_destroy_mtype_item(p_item);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
_video->video_id = strdup(p_item->uuid);
if(p_item->thumb_url)
_video->thumbnail = strdup(p_item->thumb_url);
if(p_item->rate > 0)
_video->favorite = true;
else
_video->favorite = false;
if(p_item->meta_info != NULL)
{
_video->longitude = p_item->meta_info->longitude;
_video->latitude = p_item->meta_info->latitude;
_video->width = p_item->meta_info->width;
_video->height = p_item->meta_info->height;
_video->date_taken = p_item->meta_info->datetaken;
if(p_item->meta_info->description)
_video->description = strdup(p_item->meta_info->description);
}
if((p_item->meta_info != NULL) && (p_item->meta_info->video_info != NULL))
{
if(p_item->meta_info->video_info->album_name != NULL)
{
_video->album = strdup(p_item->meta_info->video_info->album_name);
}
if(p_item->meta_info->video_info->artist_name != NULL)
_video->artist = strdup(p_item->meta_info->video_info->artist_name);
if(p_item->meta_info->video_info->title != NULL)
_video->title = strdup(p_item->meta_info->video_info->title);
_video->time_played = p_item->meta_info->video_info->last_played_pos;
_video->duration = p_item->meta_info->video_info->duration;
}
*video = (video_meta_h)_video;
p_ret = minfo_destroy_mtype_item(p_item);
ret = _content_error_capi(MEDIA_CONTENT_TYPE,p_ret);
}
return ret;
}
int media_info_get_audio_from_db(media_info_h item, audio_meta_h* audio)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
media_info_s* _item = (media_info_s*)item;
char select_query[DEFAULT_QUERY_SIZE];
sqlite3_stmt *stmt = NULL;
if(_item == NULL)
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
if(_item->media_type != MEDIA_CONTENT_TYPE_AUDIO)
{
LOGE("[%s] the type of media is not an audio.",__func__);
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
memset(select_query,0x00,sizeof(select_query));
snprintf(select_query,sizeof(select_query), SELECT_AUDIO_FROM_MEDIA,_item->item_id);
ret = _content_query_prepare(&stmt,select_query,NULL,NULL,NULL,NULL);
if( ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
audio_meta_s* _audio = (audio_meta_s*)calloc(1,sizeof(audio_meta_s));
if(_audio == NULL)
{
LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
while( sqlite3_step(stmt) == SQLITE_ROW)
{
_audio->audio_id = strdup((const char *)sqlite3_column_text(stmt, 0));
_audio->genre = strdup((const char *)sqlite3_column_text(stmt, 1));
_audio->album = strdup((const char *)sqlite3_column_text(stmt, 2));
_audio->artist= strdup((const char *)sqlite3_column_text(stmt, 3));
_audio->author= strdup((const char *)sqlite3_column_text(stmt, 4));
_audio->year= strdup((const char *)sqlite3_column_text(stmt, 5));
_audio->copyright= strdup((const char *)sqlite3_column_text(stmt, 6));
_audio->description= strdup((const char *)sqlite3_column_text(stmt, 7));
_audio->format= strdup((const char *)sqlite3_column_text(stmt, 8));
_audio->bitrate = (int)sqlite3_column_int(stmt,9);
_audio->track_num = (int)sqlite3_column_int(stmt,10);
_audio->duration = (int)sqlite3_column_int(stmt,11);
_audio->rating = (int)sqlite3_column_int(stmt,12);
_audio->count_played = (int)sqlite3_column_int(stmt,13);
_audio->time_played = (int)sqlite3_column_int(stmt,14);
_audio->time_added = (int)sqlite3_column_int(stmt,15);
_audio->size = (int)sqlite3_column_int(stmt,16);
_audio->category = (int)sqlite3_column_int(stmt,17);
}
*audio = (audio_meta_h)_audio;
if(stmt != NULL)
{
sqlite3_finalize(stmt);
}
return ret;
}
int media_info_foreach_tag_from_db(media_info_h item, media_tag_cb callback, void *user_data)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
char select_query[DEFAULT_QUERY_SIZE];
sqlite3_stmt *stmt = NULL;
media_info_s* _item = (media_info_s*)item;
if(_item == NULL)
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
if(callback == NULL)
{
LOGE("[%s]INVALID_PARAMETER(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_INVALID_PARAMETER);
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
snprintf(select_query,sizeof(select_query),SELECT_TAG_LIST_FROM_MEDIA,_item->item_id);
ret = _content_query_prepare(&stmt,select_query,NULL,NULL,NULL,NULL);
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
while( sqlite3_step(stmt) == SQLITE_ROW)
{
media_tag_s* _tag = (media_tag_s*)calloc(1,sizeof(media_tag_s));
if(_tag == NULL)
{
LOGE("[%s]OUT_OF_MEMORY(0x%08x)", __FUNCTION__, MEDIA_CONTENT_ERROR_OUT_OF_MEMORY);
return MEDIA_CONTENT_ERROR_OUT_OF_MEMORY;
}
_tag->tag_id = (int)sqlite3_column_int(stmt,0);
_tag->name = strdup((const char *)sqlite3_column_text(stmt, 1));
if(callback((media_tag_h)_tag,user_data) == false)
{
media_tag_destroy((media_tag_h) _tag);
break;
}
media_tag_destroy((media_tag_h) _tag);
}
if(stmt != NULL)
{
sqlite3_finalize(stmt);
}
return ret;
}
void _content_item_get_detail(sqlite3_stmt* stmt, media_info_h item)
{
//item_id, file_path, display_name, thumbnail, date_modified,content_type, valid
media_info_s* _item = (media_info_s*)item;
_item->item_id = strdup((const char *)sqlite3_column_text(stmt, 0));
_item->file_path= strdup((const char *)sqlite3_column_text(stmt, 1));
_item->display_name=strdup((const char *)sqlite3_column_text(stmt, 2));
_item->thumbnail=strdup((const char *)sqlite3_column_text(stmt, 3));
_item->date_modified = (int)sqlite3_column_int(stmt,4);
_item->media_type = (int)sqlite3_column_int(stmt,5);
_item->media_type = _item->media_type==3?4:_item->media_type;
_item->favorite = (int)sqlite3_column_int(stmt,6);
}
int _content_get_storage_type(const char* full_path)
{
if (full_path != NULL) {
if (strncmp(full_path, MEDIA_CONTENT_PATH_PHONE , strlen(MEDIA_CONTENT_PATH_PHONE )) == 0)
{
return MEDIA_CONTENT_STORAGE_INTERNAL;
}
else if (strncmp(full_path, MEDIA_CONTENT_PATH_MMC , strlen(MEDIA_CONTENT_PATH_MMC )) == 0)
{
return MEDIA_CONTENT_STORAGE_EXTERNAL;
}
}
return MEDIA_CONTENT_ERROR_INVALID_PARAMETER;
}
#define CONTENT_TYPE_NUM 4
#define FEX_CATEGORY_UNKNOWN 0x00000000 /**< Default */
#define FEX_CATEGORY_ETC 0x00000001 /**< ETC category */
#define FEX_CATEGORY_IMAGE 0x00000002 /**< Image category */
#define FEX_CATEGORY_VIDEO 0x00000004 /**< Video category */
#define FEX_CATEGORY_MUSIC 0x00000008 /**< Music category */
#define FEX_CATEGORY_SOUND 0x00000010 /**< Sound category */
#define FEX_CATEGORY_DRM 0x00000020 /**< DRM category */
#define SOUND_MIME_NUM 1
#define MINE_LENGTH 30
#define MUSIC_MIME_NUM 12
typedef struct
{
char content_type[15];
int category_by_mime;
}fex_content_table_t;
static const fex_content_table_t content_category[CONTENT_TYPE_NUM] = {
{"audio", FEX_CATEGORY_SOUND},
{"image", FEX_CATEGORY_IMAGE},
{"video", FEX_CATEGORY_VIDEO},
{"application", FEX_CATEGORY_ETC},
};
static const char sound_mime_table[SOUND_MIME_NUM][MINE_LENGTH] = {
"x-smaf",
};
static const char music_mime_table[MUSIC_MIME_NUM][MINE_LENGTH] = {
"ac3",
"mp2",
"mpeg",
"ogg",
"vnd.rn-realaudio",
"x-ape",
"x-flac",
"x-flac+ogg",
"x-matroska",
"x-ms-asx",
"x-ms-wma",
"x-vorbis+ogg",
};
#define FMS_DRM_CONTENT_TYPE_LENGTH 100
int _content_get_audio_category(const char* file_full_path,int* category)
{
int i = 0;
char mimetype[255] = {0,};
int result = 0;
bool is_drm = false;
drm_content_info_t contentInfo = {0};
if (file_full_path == NULL)
return FEX_CATEGORY_UNKNOWN;
if (drm_svc_is_drm_file(file_full_path) == DRM_TRUE)
{
// 2008.8.13 han. In this case, use drm_svc_get_content_info api.
result = drm_svc_get_content_info(file_full_path, &contentInfo);
if (result != DRM_RESULT_SUCCESS)
{
*category = FEX_CATEGORY_UNKNOWN;
}
strncpy(mimetype, contentInfo.contentType, strlen(contentInfo.contentType)+1);
*category = *category | FEX_CATEGORY_DRM;
is_drm = true;
}
else
{
result = aul_get_mime_from_file(file_full_path, mimetype, sizeof(mimetype));
if(result < 0)
{
*category = FEX_CATEGORY_UNKNOWN;
}
}
for(i = 0; i < CONTENT_TYPE_NUM; i ++)
{
if (strstr(mimetype, content_category[i].content_type) != NULL)
{
*category = (*category | content_category[i].category_by_mime);
break;
}
}
if (*category & FEX_CATEGORY_ETC)
{
int prefix_len = strlen(content_category[0].content_type);
for(i = 0; i < SOUND_MIME_NUM; i ++)
{
if (strstr(mimetype+prefix_len, sound_mime_table[i]) != NULL)
{
*category = FEX_CATEGORY_SOUND;
break;
}
}
if(is_drm)
*category = *category | FEX_CATEGORY_DRM;;
}
if (!(*category & FEX_CATEGORY_SOUND))
{
return result;
}
else
{
if(is_drm) //if sound file is DRM, it is always music file.
{
*category = FEX_CATEGORY_MUSIC;
*category = *category | FEX_CATEGORY_DRM;
}
else //check music file in sound files.
{
int prefix_len = strlen(content_category[0].content_type);
for(i = 0; i < MUSIC_MIME_NUM; i ++)
{
if (strstr(mimetype+prefix_len, music_mime_table[i]) != NULL)
{
*category = FEX_CATEGORY_MUSIC;
break;
}
}
}
}
return result;
}
|