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
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
|
/*
* 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 <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <media_content.h>
#include <media_info_private.h>
#include <dlog.h>
#include <pthread.h>
#include <glib.h>
#ifdef LOG_TAG
#undef LOG_TAG
#endif
#define LOG_TAG "TIZEN_N_MEDIACONTENT"
filter_h g_filter = NULL;
filter_h g_filter_g = NULL; //filter for group like folder, tag, playlist, album, year ...
GMainLoop *g_loop = NULL;
static int g_cnt = 0;
static int g_media_cnt = 0;
#define test_audio_id "0f999626-6218-450c-a4ad-181a3bab6ebf"
#define test_video_id "c1a92494-cc5b-4d74-aa7d-253199234548"
#define test_image_id "db1c184c-6f31-43b4-b924-8c00ac5b6197"
bool get_audio_meta(audio_meta_h audio)
{
char *c_value = NULL;
int i_value = 0;
time_t t_value = 0;
media_content_debug("=== audio meta === \n");
audio_meta_get_media_id(audio, &c_value);
media_content_debug("audio_id : [%s] \n", c_value);
SAFE_FREE(c_value);
audio_meta_get_title(audio, &c_value);
media_content_debug("title : [%s] \n", c_value);
SAFE_FREE(c_value);
audio_meta_get_album(audio, &c_value);
media_content_debug("album : [%s] \n", c_value);
SAFE_FREE(c_value);
audio_meta_get_artist(audio, &c_value);
media_content_debug("artist : [%s] \n", c_value);
SAFE_FREE(c_value);
audio_meta_get_genre(audio, &c_value);
media_content_debug("genre : [%s] \n", c_value);
SAFE_FREE(c_value);
audio_meta_get_composer(audio, &c_value);
media_content_debug("composer : [%s] \n", c_value);
SAFE_FREE(c_value);
audio_meta_get_year(audio, &c_value);
media_content_debug("year : [%s] \n", c_value);
SAFE_FREE(c_value);
audio_meta_get_recorded_date(audio, &c_value);
media_content_debug("recorded_date : [%s] \n", c_value);
SAFE_FREE(c_value);
audio_meta_get_copyright(audio, &c_value);
media_content_debug("copyright : [%s] \n", c_value);
SAFE_FREE(c_value);
audio_meta_get_track_num(audio, &c_value);
media_content_debug("track_num : [%s] \n", c_value);
SAFE_FREE(c_value);
audio_meta_get_bit_rate(audio, &i_value);
media_content_debug("bitrate : [%d] \n", i_value);
audio_meta_get_sample_rate(audio, &i_value);
media_content_debug("samplerate : [%d] \n", i_value);
audio_meta_get_channel(audio, &i_value);
media_content_debug("channel : [%d] \n", i_value);
audio_meta_get_duration(audio, &i_value);
media_content_debug("duration : [%d] \n", i_value);
audio_meta_get_played_count(audio, &i_value);
media_content_debug("played_count : [%d] \n", i_value);
audio_meta_get_played_time(audio, &t_value);
media_content_debug("played_time : [%d] \n", t_value);
audio_meta_get_played_position(audio, &i_value);
media_content_debug("played_position : [%d] \n", i_value);
return true;
}
bool get_video_meta(video_meta_h video)
{
char *c_value = NULL;
int i_value = 0;
time_t t_value = 0;
media_content_debug("=== video meta === \n");
video_meta_get_media_id(video, &c_value);
media_content_debug("video_id : [%s] \n", c_value);
SAFE_FREE(c_value);
video_meta_get_title(video, &c_value);
media_content_debug("title : [%s] \n", c_value);
SAFE_FREE(c_value);
video_meta_get_album(video, &c_value);
media_content_debug("album : [%s] \n", c_value);
SAFE_FREE(c_value);
video_meta_get_artist(video, &c_value);
media_content_debug("artist : [%s] \n", c_value);
SAFE_FREE(c_value);
video_meta_get_genre(video, &c_value);
media_content_debug("genre : [%s] \n", c_value);
SAFE_FREE(c_value);
video_meta_get_composer(video, &c_value);
media_content_debug("omposer : [%s] \n", c_value);
SAFE_FREE(c_value);
video_meta_get_year(video, &c_value);
media_content_debug("year : [%s] \n", c_value);
SAFE_FREE(c_value);
video_meta_get_recorded_date(video, &c_value);
media_content_debug("recorded_date : [%s] \n", c_value);
SAFE_FREE(c_value);
video_meta_get_copyright(video, &c_value);
media_content_debug("copyright : [%s] \n", c_value);
SAFE_FREE(c_value);
video_meta_get_track_num(video, &c_value);
media_content_debug("track_num : [%s] \n", c_value);
SAFE_FREE(c_value);
video_meta_get_bit_rate(video, &i_value);
media_content_debug("bitrate : [%d] \n", i_value);
video_meta_get_duration(video, &i_value);
media_content_debug("duration : [%d] \n", i_value);
video_meta_get_width(video, &i_value);
media_content_debug("width : [%d] \n", i_value);
video_meta_get_height(video, &i_value);
media_content_debug("height : [%d] \n", i_value);
video_meta_get_played_count(video, &i_value);
media_content_debug("played_count : [%d] \n", i_value);
video_meta_get_played_time(video, &t_value);
media_content_debug("played_time : [%d] \n", t_value);
video_meta_get_played_position(video, &i_value);
media_content_debug("played_position : [%d] \n", i_value);
return true;
}
bool gallery_folder_list_cb(media_folder_h folder, void *user_data)
{
media_folder_h new_folder = NULL;
media_folder_clone(&new_folder, folder);
GList **list = (GList**)user_data;
*list = g_list_append(*list, new_folder);
return true;
}
bool gallery_media_item_cb(media_info_h media, void *user_data)
{
media_info_h new_media = NULL;
media_info_clone(&new_media, media);
GList **list = (GList**)user_data;
*list = g_list_append(*list, new_media);
return true;
}
bool gallery_tag_item_cb(media_tag_h tag, void *user_data)
{
media_tag_h new_tag = NULL;
media_tag_clone(&new_tag, tag);
GList **list = (GList**)user_data;
*list = g_list_append(*list, new_tag);
return true;
}
bool gallery_bookmarks_cb(media_bookmark_h bookmark, void *user_data)
{
media_bookmark_h new_bm = NULL;
media_bookmark_clone(&new_bm, bookmark);
GList **list = (GList**)user_data;
*list = g_list_append(*list, new_bm);
return true;
}
bool media_item_cb(media_info_h media, void *user_data)
{
char *c_value = NULL;
char *media_id = NULL;
int i_value = 0;
time_t t_value = 0;
bool b_value = false;
media_content_type_e media_type = 0;
unsigned long long size = 0;
if(media == NULL)
{
media_content_debug("NO Item \n");
return true;
}
media_info_get_media_type(media, &media_type);
media_content_debug("media_type : [%d] \n", media_type);
media_info_get_media_id(media, &media_id);
media_content_debug("media_id : [%s] \n", media_id);
#if 1
if(media_type == MEDIA_CONTENT_TYPE_MUSIC)
{
audio_meta_h audio;
if(media_info_get_audio(media, &audio) == MEDIA_CONTENT_ERROR_NONE)
{
get_audio_meta(audio);
audio_meta_destroy(audio);
}
else
media_content_error("[audio_error] \n");
}
else if(media_type == MEDIA_CONTENT_TYPE_IMAGE)
{
image_meta_h image;
media_content_orientation_e orientation = 0;
if(media_info_get_image(media, &image) == MEDIA_CONTENT_ERROR_NONE)
{
image_meta_get_orientation(image, &orientation);
media_content_debug("[image] orientation : %d\n", orientation);
image_meta_destroy(image);
}
else
media_content_error("[image_error] \n");
}
else if(media_type == MEDIA_CONTENT_TYPE_VIDEO)
{
video_meta_h video;
if(media_info_get_video(media, &video) == MEDIA_CONTENT_ERROR_NONE)
{
get_video_meta(video);
video_meta_destroy(video);
}
else
media_content_error("[video_error] \n");
}
else
{
media_content_debug("Other Content");
}
media_content_debug("=== media_info === \n");
media_info_get_file_path(media, &c_value);
media_content_debug("file_path : [%s] \n", c_value);
SAFE_FREE(c_value);
media_info_get_display_name(media, &c_value);
media_content_debug("display_name : [%s] \n", c_value);
SAFE_FREE(c_value);
media_info_get_mime_type(media, &c_value);
media_content_debug("mime_type : [%s] \n", c_value);
SAFE_FREE(c_value);
media_info_get_thumbnail_path(media, &c_value);
media_content_debug("thumbnail_path : [%s] \n", c_value);
SAFE_FREE(c_value);
media_info_get_description(media, &c_value);
media_content_debug("description : [%s] \n", c_value);
SAFE_FREE(c_value);
media_info_get_author(media, &c_value);
media_content_debug("author : [%s] \n", c_value);
SAFE_FREE(c_value);
media_info_get_provider(media, &c_value);
media_content_debug("provider : [%s] \n", c_value);
SAFE_FREE(c_value);
media_info_get_content_name(media, &c_value);
media_content_debug("content_name : [%s] \n", c_value);
SAFE_FREE(c_value);
media_info_get_category(media, &c_value);
media_content_debug("category : [%s] \n", c_value);
SAFE_FREE(c_value);
media_info_get_location_tag(media, &c_value);
media_content_debug("location_tag : [%s] \n", c_value);
SAFE_FREE(c_value);
media_info_get_age_rating(media, &c_value);
media_content_debug("age_rating : [%s] \n", c_value);
SAFE_FREE(c_value);
media_info_get_keyword(media, &c_value);
media_content_debug("keyword : [%s] \n", c_value);
SAFE_FREE(c_value);
media_info_get_size(media, &size);
media_content_debug("size : [%lld] \n", size);
media_info_get_added_time(media, &t_value);
media_content_debug("added_time : [%d] \n", t_value);
media_info_get_modified_time(media, &t_value);
media_content_debug("modified_time : [%d] \n", t_value);
media_info_get_rating(media, &i_value);
media_content_debug("rating : [%d] \n", i_value);
media_info_get_favorite(media, &b_value);
media_content_debug("favorite : [%d] \n", b_value);
media_info_is_drm(media, &b_value);
media_content_debug("is_drm : [%d] \n", b_value);
media_info_set_location_tag(media, "Test location tag");
media_info_update_to_db(media);
SAFE_FREE(media_id);
#endif
return true;
}
bool folder_list_cb(media_folder_h folder, void *user_data)
{
int item_count;
char *folder_id = NULL;
char *folder_path = NULL;
char *folder_name = NULL;
media_content_storage_e storage_type;
bool ret;
media_folder_h *_folder = (media_folder_h*)user_data;
if(folder != NULL)
{
media_folder_clone(_folder, folder);
if(media_folder_get_folder_id(folder, &folder_id) != MEDIA_CONTENT_ERROR_NONE)
{
media_content_error("[ERROR] media_folder_get_folder_id is failed\n");
return false;
}
media_content_debug("folder_id = [%s] \n", folder_id);
if(media_folder_get_path(folder, &folder_path) != MEDIA_CONTENT_ERROR_NONE)
{
media_content_error("[ERROR] media_folder_get_path is failed\n");
return false;
}
media_content_debug("folder_path = [%s] \n", folder_path);
SAFE_FREE(folder_path);
if(media_folder_get_name(folder, &folder_name) != MEDIA_CONTENT_ERROR_NONE)
{
media_content_error("[ERROR] media_folder_get_name is failed\n");
return false;
}
media_content_debug("folder_name = [%s] \n", folder_name);
SAFE_FREE(folder_name);
if(media_folder_get_storage_type(folder, &storage_type) != MEDIA_CONTENT_ERROR_NONE)
{
media_content_error("[ERROR] media_folder_get_storage_type is failed\n");
return false;
}
media_content_debug("storage_type = [%d] \n", storage_type);
if(media_folder_get_media_count_from_db(folder_id, g_filter, &item_count) != MEDIA_CONTENT_ERROR_NONE)
{
media_content_error("[ERROR] media_folder_get_media_count_from_db is failed\n");
return false;
}
media_folder_foreach_media_from_db(folder_id, g_filter, media_item_cb, NULL);
SAFE_FREE(folder_id);
ret = true;
}
else
{
ret = false;
}
return ret;
}
bool test_album_from_db(int album_id)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
media_album_h album_h;
int test_album_id = 0;
char *album_name = NULL;
char *artist = NULL;
ret = media_album_get_album_from_db(album_id, &album_h);
if(ret != MEDIA_CONTENT_ERROR_NONE)
{
media_content_error("error when get album \n");
return false;
}
if(media_album_get_album_id(album_h, &test_album_id) != MEDIA_CONTENT_ERROR_NONE)
return false;
media_content_debug("test_album_id : [%d] \n", test_album_id);
if(media_album_get_name(album_h, &album_name) != MEDIA_CONTENT_ERROR_NONE)
return false;
media_content_debug("album_name : [%s] \n", album_name);
if(media_album_get_artist(album_h, &artist) != MEDIA_CONTENT_ERROR_NONE)
return false;
media_content_debug("artist : [%s] \n", artist);
SAFE_FREE(album_name);
SAFE_FREE(artist);
media_album_destroy(album_h);
return true;
}
bool playlist_list_cb(media_playlist_h playlist, void *user_data)
{
int playlist_id = 0;
char *playlist_name = NULL;
media_playlist_h playlist_h;
media_content_debug("playlist_list_cb ====== \n");
GList **list = (GList**)user_data;
if(playlist == NULL)
{
media_content_debug(" playlist handle is NULL \n");
return false;
}
media_playlist_get_playlist_id(playlist, &playlist_id);
media_content_debug("playlist_id : %d \n", playlist_id);
if(user_data != NULL)
*list = g_list_append(*list, (gpointer)playlist_id);
media_playlist_get_name(playlist, &playlist_name);
media_content_debug("playlist_name : %s \n", playlist_name);
SAFE_FREE(playlist_name);
media_playlist_get_playlist_from_db(playlist_id, NULL, &playlist_h);
media_playlist_destroy(playlist_h);
return true;
}
bool tag_list_cb(media_tag_h tag, void *user_data)
{
int tag_id = 0;
char *tag_name = NULL;
if(tag == NULL)
{
media_content_debug(" tag handle is NULL \n");
return false;
}
media_tag_get_tag_id(tag, &tag_id);
media_content_debug("tag_id : %d \n", tag_id);
media_tag_get_name(tag, &tag_name);
media_content_debug("tag_name : %s \n", tag_name);
SAFE_FREE(tag_name);
return true;
}
bool bookmarks_cb(media_bookmark_h bookmark, void *user_data)
{
media_bookmark_h *_bookmark = (media_bookmark_h*)bookmark;
if(_bookmark != NULL)
{
char *name = NULL;
time_t time = 0;
int bookmark_id = 0;
media_bookmark_get_bookmark_id(bookmark, &bookmark_id);
media_content_debug("bookmark_id : %d \n", bookmark_id);
media_bookmark_get_thumbnail_path(bookmark, &name);
media_content_debug("bookmark thumbnail_path : %s \n", name);
SAFE_FREE(name);
media_bookmark_get_marked_time(bookmark, &time);
media_content_debug("bookmark marked_time : %d \n", time);
}
return true;
}
bool album_list_cb(media_album_h album, void *user_data)
{
int album_id = 0;
char *album_name = NULL;
char *artist = NULL;
char *album_art = NULL;
int media_count = 0;
int ret = MEDIA_CONTENT_ERROR_NONE;
filter_h filter;
/*Set Filter*/
char *condition = "MEDIA_TYPE=3"; /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
ret = media_filter_create(&filter);
if(ret != MEDIA_CONTENT_ERROR_NONE) {
media_content_error("Fail to create filter \n");
return ret;
}
ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
if(ret != MEDIA_CONTENT_ERROR_NONE) {
media_content_error("Fail to set condition \n");
return ret;
}
ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_NOCASE);
if(ret != MEDIA_CONTENT_ERROR_NONE) {
media_content_error("Fail to set order \n");
return ret;
}
if(album != NULL)
{
if(media_album_get_album_id(album, &album_id) != MEDIA_CONTENT_ERROR_NONE)
return false;
media_content_debug("album_id : [%d] \n", album_id);
if(media_album_get_name(album, &album_name) != MEDIA_CONTENT_ERROR_NONE)
return false;
media_content_debug("album_name : [%s] \n", album_name);
if(media_album_get_artist(album, &artist) != MEDIA_CONTENT_ERROR_NONE)
return false;
media_content_debug("artist : [%s] \n", artist);
if(media_album_get_album_art(album, &album_art) != MEDIA_CONTENT_ERROR_NONE)
return false;
media_content_debug("album_art : [%s] \n", album_art);
SAFE_FREE(album_name);
SAFE_FREE(artist);
SAFE_FREE(album_art);
if(media_album_get_media_count_from_db(album_id, filter, &media_count) != MEDIA_CONTENT_ERROR_NONE)
return false;
media_content_debug("media_count : [%d] \n", media_count);
if(media_album_foreach_media_from_db(album_id, filter, media_item_cb, NULL) != MEDIA_CONTENT_ERROR_NONE)
return false;
test_album_from_db(album_id);
}
else
{
media_content_error("album item not Found!!\n");
return true;
}
return true;
}
bool group_list_cb(const char *group_name, void *user_data)
{
int media_count = 0;
int *idx = user_data;
media_content_debug("group item : [%s] [%d]\n", group_name, *idx);
if(media_group_get_media_count_from_db(group_name, *idx, g_filter, &media_count) != MEDIA_CONTENT_ERROR_NONE)
return false;
media_content_debug("media_count : [%d] \n", media_count);
if(media_group_foreach_media_from_db(group_name, *idx, g_filter, media_item_cb, NULL) != MEDIA_CONTENT_ERROR_NONE)
return false;
return true;
}
bool playlist_item_cb(int playlist_member_id, media_info_h media, void *user_data)
{
media_content_debug("playlist_member_id : [%d] \n", playlist_member_id);
GList **list = (GList**)user_data;
*list = g_list_append(*list, (gpointer)playlist_member_id);
//media_item_cb(media, user_data);
return true;
}
int test_filter_create(void)
{
media_content_debug("\n============Filter Create============\n\n");
int ret = MEDIA_CONTENT_ERROR_NONE;
/* Filter for media */
char *condition = "MEDIA_TYPE=0"; /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
ret = media_filter_create(&g_filter);
/* Set condition and collate
* Condition string : You can make where statement of sql.
* Colation : You can use collation when comparing.
* Ex) In case of FILE_NAME='Samsung' as condition string,
* if you want to compare with NOCASE collation,
* call media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_NOCASE);
* if you want to compare in case-sensitive,
* call media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
*/
ret = media_filter_set_condition(g_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
/* Collation of ordering
* If you want to get list, which is sorted by NOCASE,
* call media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_NOCASE);
* Or,
* call media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_DEFAULT);
*/
ret = media_filter_set_order(g_filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ARTIST, MEDIA_CONTENT_COLLATE_DEFAULT);
/* Filter for group */
char *g_condition = "TAG_NAME like \"\%my\%\"";
//char *g_condition = "BOOKMARK_MARKED_TIME > 300";
ret = media_filter_create(&g_filter_g);
ret = media_filter_set_condition(g_filter_g, g_condition, MEDIA_CONTENT_COLLATE_DEFAULT);
ret = media_filter_set_order(g_filter_g, MEDIA_CONTENT_ORDER_DESC, TAG_NAME, MEDIA_CONTENT_COLLATE_DEFAULT);
return ret;
}
int test_filter_destroy(void)
{
media_content_debug("\n============Filter Create============\n\n");
int ret = MEDIA_CONTENT_ERROR_NONE;
ret = media_filter_destroy(g_filter);
return ret;
}
int test_connect_database(void)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
media_content_debug("\n============DB Connection Test============\n\n");
ret = media_content_connect();
if(ret == MEDIA_CONTENT_ERROR_NONE)
{
media_content_debug("connection is success\n\n");
}
else
media_content_error("connection is failed\n\n");
return ret;
}
int test_gallery_scenario(void)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
int i;
filter_h filter = NULL;
int count;
GList *folder_list = NULL;
media_folder_h folder_handle = NULL;
/* First, Get folder list */
ret = media_folder_foreach_folder_from_db(filter, gallery_folder_list_cb, &folder_list);
if(ret < 0) {
media_content_error("media_folder_foreach_folder_from_db failed: %d", ret);
return -1;
} else {
media_content_debug("media_folder_foreach_folder_from_db success!!");
char *folder_id;
char *folder_name;
char *folder_path;
for(i = 0; i < g_list_length(folder_list); i++) {
folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
media_folder_get_folder_id(folder_handle, &folder_id);
media_folder_get_name(folder_handle, &folder_name);
media_folder_get_path(folder_handle, &folder_path);
media_content_debug("folder_id [%d] : %s\n", i, folder_id);
media_content_debug("folder_name [%d] : %s\n", i, folder_name);
media_content_debug("folder_path [%d] : %s\n", i, folder_path);
ret = media_folder_get_media_count_from_db(folder_id, filter, &count);
/* User should free these string */
SAFE_FREE(folder_id);
SAFE_FREE(folder_name);
SAFE_FREE(folder_path);
if(ret < 0) {
media_content_error("media_folder_get_media_count_from_db failed: %d", ret);
return -1;
} else {
media_content_debug("media count [%d] : %d\n", i, count);
}
}
}
/* To check performance */
struct timeval start, end;
gettimeofday(&start, NULL);
/* Second, Get all item list */
media_info_h media_handle = NULL;
GList *all_item_list = NULL;
media_content_collation_e collate_type = MEDIA_CONTENT_COLLATE_NOCASE;
media_content_order_e order_type = MEDIA_CONTENT_ORDER_DESC;
media_filter_create(&filter);
//media_filter_set_condition(filter, "MEDIA_TYPE = 0", collate_type);
media_filter_set_order(filter, order_type, MEDIA_DISPLAY_NAME, collate_type);
//media_filter_set_collate(filter, collate_type);
ret = media_info_foreach_media_from_db(filter, gallery_media_item_cb, &all_item_list);
if(ret < 0) {
media_content_error("media_info_foreach_media_from_db failed: %d", ret);
return -1;
} else {
media_content_debug("media_info_foreach_media_from_db success");
media_content_type_e media_type;
char *media_id = NULL;
char *media_name = NULL;
char *media_path = NULL;
for(i = 0; i < g_list_length(all_item_list); i++) {
media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
media_info_get_media_id(media_handle, &media_id);
media_info_get_media_type(media_handle, &media_type);
media_info_get_display_name(media_handle, &media_name);
media_info_get_file_path(media_handle, &media_path);
if(media_type == MEDIA_CONTENT_TYPE_IMAGE) {
image_meta_h image_handle;
int width, height;
media_content_orientation_e orientation;
char *datetaken;
ret = media_info_get_image(media_handle, &image_handle);
if(ret < 0) {
media_content_error("media_info_get_image failed: %d", ret);
} else {
image_meta_get_width(image_handle, &width);
image_meta_get_height(image_handle, &height);
image_meta_get_orientation(image_handle, &orientation);
image_meta_get_date_taken(image_handle, &datetaken);
media_content_debug("This is Image\n");
media_content_debug("Width : %d, Height : %d, Orientation : %d, Date taken : %s\n", width, height, orientation, datetaken);
}
SAFE_FREE(datetaken);
image_meta_destroy(image_handle);
} else if(media_type == MEDIA_CONTENT_TYPE_VIDEO) {
video_meta_h video_handle;
char *title, *artist, *album;
int duration;
time_t time_played;
ret = media_info_get_video(media_handle, &video_handle);
if(ret < 0) {
media_content_error("media_info_get_video failed: %d", ret);
} else {
video_meta_get_title(video_handle, &title);
video_meta_get_artist(video_handle, &artist);
video_meta_get_album(video_handle, &album);
video_meta_get_duration(video_handle, &duration);
video_meta_get_played_time(video_handle, &time_played);
media_content_debug("This is Video\n");
media_content_debug("Title: %s, Album: %s, Artist: %s\nDuration: %d, Played time: %d\n", title, artist, album, duration, time_played);
}
SAFE_FREE(title);
SAFE_FREE(artist);
SAFE_FREE(album);
video_meta_destroy(video_handle);
}
//media_content_debug("media_id [%d] : %s\n", i, media_id);
//media_content_debug("media_name [%d] : %s\n", i, media_name);
//media_content_debug("media_path [%d] : %s\n", i, media_path);
SAFE_FREE(media_id);
SAFE_FREE(media_name);
SAFE_FREE(media_path);
}
}
media_filter_destroy(filter);
filter = NULL;
/* To check performance */
gettimeofday(&end, NULL);
long time = (end.tv_sec * 1000000 + end.tv_usec) - (start.tv_sec * 1000000 + start.tv_usec);
printf("Time : %ld\n", time);
/* Third, Get item list of a folder */
GList *item_list = NULL;
for(i = 0; i < g_list_length(folder_list); i++) {
int j;
char *folder_name;
char *folder_id;
folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
media_folder_get_folder_id(folder_handle, &folder_id);
media_folder_get_name(folder_handle, &folder_name);
ret = media_folder_foreach_media_from_db(folder_id, filter, gallery_media_item_cb, &item_list);
SAFE_FREE(folder_id);
SAFE_FREE(folder_name);
if(ret < 0) {
media_content_error("media_folder_foreach_media_from_db failed: %d", ret);
return -1;
} else {
media_content_error("media_folder_foreach_media_from_db success!", ret);
char *media_id = NULL;
char *media_name = NULL;
char *media_path = NULL;
media_content_type_e media_type = 0;
for(j = 0; j < g_list_length(item_list); j++) {
media_handle = (media_info_h)g_list_nth_data(item_list, j);
media_info_get_media_id(media_handle, &media_id);
media_info_get_display_name(media_handle, &media_name);
media_info_get_file_path(media_handle, &media_path);
media_info_get_media_type(media_handle, &media_type);
media_content_debug("[%s] media_id [%d] : %s\n", folder_name, j, media_id);
media_content_debug("[%s] media_type [%d] : %d\n", folder_name, j, media_type);
media_content_debug("[%s] media_name [%d] : %s\n", folder_name, j, media_name);
media_content_debug("[%s] media_path [%d] : %s\n", folder_name, j, media_path);
if(media_type == MEDIA_CONTENT_TYPE_IMAGE) {
image_meta_h image_handle;
int width, height;
media_content_orientation_e orientation;
char *datetaken;
ret = media_info_get_image(media_handle, &image_handle);
if(ret < 0) {
media_content_error("media_info_get_image failed: %d", ret);
} else {
image_meta_get_width(image_handle, &width);
image_meta_get_height(image_handle, &height);
image_meta_get_orientation(image_handle, &orientation);
image_meta_get_date_taken(image_handle, &datetaken);
media_content_debug("This is Image\n");
media_content_debug("Width : %d, Height : %d, Orientation : %d, Date taken : %s\n", width, height, orientation, datetaken);
}
SAFE_FREE(datetaken);
image_meta_destroy(image_handle);
} else if(media_type == MEDIA_CONTENT_TYPE_VIDEO) {
video_meta_h video_handle;
char *title, *artist, *album;
int duration;
time_t time_played;
ret = media_info_get_video(media_handle, &video_handle);
if(ret < 0) {
media_content_error("media_info_get_video failed: %d", ret);
} else {
video_meta_get_title(video_handle, &title);
video_meta_get_artist(video_handle, &artist);
video_meta_get_album(video_handle, &album);
video_meta_get_duration(video_handle, &duration);
video_meta_get_played_time(video_handle, &time_played);
media_content_debug("This is Video\n");
media_content_debug("Title: %s, Album: %s, Artist: %s\nDuration: %d, Played time: %d\n", title, artist, album, duration, time_played);
}
SAFE_FREE(title);
SAFE_FREE(artist);
SAFE_FREE(album);
video_meta_destroy(video_handle);
/* Get bookmar list in case of video */
media_bookmark_h bm_handle;
GList *bm_list = NULL;
ret = media_info_foreach_bookmark_from_db(media_id, filter, gallery_bookmarks_cb, &bm_list);
if(ret < 0) {
media_content_error("media_info_foreach_bookmark_from_db failed: %d", ret);
} else {
media_content_error("media_info_foreach_bookmark_from_db success");
int k;
for(k = 0; k < g_list_length(bm_list); k++) {
bm_handle = (media_bookmark_h)g_list_nth_data(bm_list, k);
time_t marked_time;
char *thumb_path = NULL;
media_bookmark_get_marked_time(bm_handle, &marked_time);
media_bookmark_get_thumbnail_path(bm_handle, &thumb_path);
media_content_error("Bookmark time : %d\nBookmar thumb: %s\n", marked_time, thumb_path);
SAFE_FREE(thumb_path);
}
/* Remove bookmark list */
int l = 0;
if(bm_list) {
for(l = 0; l < g_list_length(bm_list); l++) {
bm_handle = (media_bookmark_h)g_list_nth_data(bm_list, l);
media_bookmark_destroy(bm_handle);
}
g_list_free(bm_list);
}
}
}
SAFE_FREE(media_id);
SAFE_FREE(media_name);
SAFE_FREE(media_path);
}
}
}
/* Get tag list */
media_tag_h tag_handle = NULL;
GList *tag_list = NULL;
GList *media_list_in_tag = NULL;
ret = media_tag_foreach_tag_from_db (filter, gallery_tag_item_cb, &tag_list);
if(ret < 0) {
media_content_error("media_tag_foreach_tag_from_db failed: %d", ret);
return -1;
} else {
media_content_error("media_tag_foreach_tag_from_db success");
char *tag_name;
int tag_id;
for(i = 0; i < g_list_length(tag_list); i++) {
tag_handle = (media_tag_h)g_list_nth_data(tag_list, i);
media_tag_get_tag_id(tag_handle, &tag_id);
media_tag_get_name(tag_handle, &tag_name);
printf("[%d] %s", tag_id, tag_name);
ret = media_tag_foreach_media_from_db(tag_id, filter, gallery_media_item_cb, &media_list_in_tag);
if(ret < 0) {
media_content_error("media_tag_foreach_media_from_db failed: %d", ret);
return -1;
} else {
media_content_error("media_tag_foreach_media_from_db success");
int j = 0;
media_info_h tag_media_handle;
char *media_id = NULL;
char *media_name = NULL;
char *media_path = NULL;
media_content_type_e media_type = 0;
for(j = 0; j < g_list_length(media_list_in_tag); j++) {
tag_media_handle = (media_info_h)g_list_nth_data(media_list_in_tag, j);
media_info_get_media_id(tag_media_handle, &media_id);
media_info_get_display_name(tag_media_handle, &media_name);
media_info_get_file_path(tag_media_handle, &media_path);
media_info_get_media_type(tag_media_handle, &media_type);
media_content_debug("[%s] media_id [%d] : %s\n", tag_name, j, media_id);
media_content_debug("[%s] media_type [%d] : %d\n", tag_name, j, media_type);
media_content_debug("[%s] media_name [%d] : %s\n", tag_name, j, media_name);
media_content_debug("[%s] media_path [%d] : %s\n", tag_name, j, media_path);
}
SAFE_FREE(media_id);
SAFE_FREE(media_name);
SAFE_FREE(media_path);
}
SAFE_FREE(tag_name);
}
}
/* Remove folder list */
if(folder_list) {
for(i = 0; i < g_list_length(folder_list); i++) {
folder_handle = (media_folder_h)g_list_nth_data(folder_list, i);
media_folder_destroy(folder_handle);
}
g_list_free(folder_list);
}
/* Remove all items list */
if(all_item_list) {
for(i = 0; i < g_list_length(all_item_list); i++) {
media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
media_info_destroy(media_handle);
}
g_list_free(all_item_list);
}
/* Remove items list */
if(item_list) {
for(i = 0; i < g_list_length(item_list); i++) {
media_handle = (media_info_h)g_list_nth_data(item_list, i);
media_info_destroy(media_handle);
}
g_list_free(item_list);
}
/* Remove tag list */
if(tag_list) {
for(i = 0; i < g_list_length(tag_list); i++) {
tag_handle = (media_tag_h)g_list_nth_data(tag_list, i);
media_tag_destroy(tag_handle);
}
g_list_free(tag_list);
}
/* Remove media list in a tag */
if(media_list_in_tag) {
for(i = 0; i < g_list_length(media_list_in_tag); i++) {
media_handle = (media_info_h)g_list_nth_data(media_list_in_tag, i);
media_info_destroy(media_handle);
}
g_list_free(media_list_in_tag);
}
return MEDIA_CONTENT_ERROR_NONE;
}
/*Get All Music file. sort by Title and not case sensitive*/
int test_get_all_music_files(void)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
int media_count = 0;
filter_h filter;
/*Set Filter*/
char *condition = "MEDIA_TYPE=3"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/
ret = media_filter_create(&filter);
if(ret != MEDIA_CONTENT_ERROR_NONE) {
media_content_error("Fail to create filter \n");
return ret;
}
ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
if(ret != MEDIA_CONTENT_ERROR_NONE) {
media_content_error("Fail to set condition \n");
return ret;
}
ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_TITLE, MEDIA_CONTENT_COLLATE_NOCASE);
if(ret != MEDIA_CONTENT_ERROR_NONE) {
media_content_error("Fail to set order \n");
return ret;
}
/*Get Media Count*/
ret = media_info_get_media_count_from_db(filter, &media_count);
if(ret != MEDIA_CONTENT_ERROR_NONE) {
media_filter_destroy(filter);
media_content_error("Fail to get media count \n");
return ret;
}
media_content_debug("media_count : [%d],\n", media_count);
ret = media_info_foreach_media_from_db(filter, media_item_cb, NULL);
if(ret != MEDIA_CONTENT_ERROR_NONE) {
media_filter_destroy(filter);
media_content_error("Fail to get media \n");
return ret;
}
return ret;
}
int test_media_info_operation(void)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
int media_count = 0;
media_content_debug("\n============Media info Test============\n\n");
test_filter_create();
media_info_get_media_count_from_db(g_filter, &media_count);
media_content_debug("media_count : [%d],\n", media_count);
ret = media_info_foreach_media_from_db(g_filter, media_item_cb, NULL);
if(ret == MEDIA_CONTENT_ERROR_NONE)
media_content_debug("media_info_foreach_media_from_db is success\n\n");
else
media_content_error("media_info_foreach_media_from_db is failed\n\n");
test_filter_destroy();
return ret;
}
int test_media_info_operation_2(void)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
int bookmark_count = 0;
media_content_debug("\n============Media info Test 2============\n\n");
test_filter_create();
#if 0
/* Bookmark */
char *thumbnail_path1 = "/opt/media/Images and videos/My video clips/teat11.jpg";
media_bookmark_insert_to_db(test_video_id, 100, thumbnail_path1);
media_bookmark_insert_to_db(test_video_id, 200, thumbnail_path1);
media_info_get_bookmark_count_from_db(test_video_id, g_filter_g, &bookmark_count);
media_content_debug("bookmark_count : [%d],\n", bookmark_count);
ret = media_info_foreach_bookmark_from_db(test_video_id, g_filter_g, bookmarks_cb, NULL);
#endif
/* Tag */
media_info_get_tag_count_from_db(test_audio_id, g_filter_g, &bookmark_count);
media_content_debug("tag_count : [%d],\n", bookmark_count);
ret = media_info_foreach_tag_from_db(test_audio_id, g_filter_g, tag_list_cb, NULL);
test_filter_destroy();
return ret;
}
int test_folder_operation(void)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
filter_h filter;
media_folder_h folder = NULL;
char *folder_id = NULL;
int folder_count = 0;
media_content_debug("\n============Folder Test============\n\n");
test_filter_create();
ret = media_filter_create(&filter);
if(ret != MEDIA_CONTENT_ERROR_NONE)
{
media_content_error("[ERROR] media_folder_filter_create is failed\n");
return ret;
}
media_filter_set_condition(filter, "(MEDIA_TYPE = 0 or MEDIA_TYPE = 1) and MEDIA_STORAGE_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT); /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
media_filter_set_offset(filter, 0,5);
media_filter_set_order(filter,MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE);
ret = media_folder_get_folder_count_from_db(filter, &folder_count);
media_content_debug("Folder count : %d", folder_count);
ret = media_folder_foreach_folder_from_db(filter, folder_list_cb, &folder);
//test.3 get the media list in first folder
filter_h m_filter = NULL;
ret = media_filter_create(&m_filter);
if(ret != MEDIA_CONTENT_ERROR_NONE)
{
media_content_error("[ERROR] media_info_filter_create is failed\n");
return ret;
}
media_filter_set_condition(m_filter, "MEDIA_TYPE=1 and MEDIA_STORAGE_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT); /*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
media_filter_set_offset(m_filter, 0,5);
media_filter_set_order(m_filter,MEDIA_CONTENT_ORDER_DESC, MEDIA_PATH, MEDIA_CONTENT_COLLATE_NOCASE);
media_folder_get_folder_id(folder, &folder_id);
media_content_debug("folder_id : %s", folder_id);
ret = media_folder_foreach_media_from_db(folder_id, m_filter, media_item_cb, NULL);
if(ret != MEDIA_CONTENT_ERROR_NONE)
{
media_content_error("[ERROR] media_folder_foreach_media_from_db is failed, error code : %d\n", ret);
}
media_filter_destroy(filter);
media_filter_destroy(m_filter);
test_filter_create();
return ret;
}
int test_playlist_operation(void)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
media_playlist_h playlist_1 = NULL;
media_playlist_h playlist_2 = NULL;
media_playlist_h playlist_3 = NULL;
int playlist_id_1 = 0;
int playlist_id_2 = 0;
int playlist_id_3 = 0;
char *playlist_name_1 = "myPlaylist_1";
char *playlist_name_2 = "myPlaylist_2";
char *playlist_name_3 = "myPlaylist_3";
int playlist_count = 0;
int media_count = 0;
int order_1 = 0;
int order_2 = 0;
int order_3 = 0;
int order_4 = 0;
int order_5 = 0;
filter_h filter = NULL;
filter_h m_filter = NULL;
media_content_debug("\n============Playlist Test============\n\n");
/* Filter for playlist */
char *condition = "(MEDIA_TYPE=1 or MEDIA_TYPE=3)"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/
#if 0
ret = media_filter_create(&filter);
ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_NOCASE);
ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, PLAYLIST_NAME, MEDIA_CONTENT_COLLATE_NOCASE);
#endif
/* Create Playlist */
media_playlist_insert_to_db(playlist_name_1, &playlist_1);
media_playlist_insert_to_db(playlist_name_2, &playlist_2);
media_playlist_insert_to_db(playlist_name_3, &playlist_3);
if(playlist_1 != NULL)
{
/* Add media to Playlist */
media_playlist_add_media(playlist_1, test_audio_id);
media_playlist_add_media(playlist_1, test_audio_id);
media_playlist_add_media(playlist_1, test_video_id);
media_playlist_update_to_db(playlist_1);
}
if(playlist_2 != NULL)
{
media_playlist_add_media(playlist_2, test_audio_id);
media_playlist_add_media(playlist_2, test_audio_id);
media_playlist_update_to_db(playlist_2);
}
/* Get Playlist Count*/
media_playlist_get_playlist_count_from_db(filter, &playlist_count);
media_content_debug("playlist_count [%d] \n", playlist_count);
/* Get Playlist*/
GList *playlist_id_list = NULL;
media_playlist_foreach_playlist_from_db(filter, playlist_list_cb, &playlist_id_list);
/* Get Playlist id*/
playlist_id_1 = (int)g_list_nth_data(playlist_id_list, 0);
playlist_id_2 = (int)g_list_nth_data(playlist_id_list, 1);
playlist_id_3 = (int)g_list_nth_data(playlist_id_list, 2);
media_content_debug("playlist_id_1 [%d] \n", playlist_id_1);
media_content_debug("playlist_id_2 [%d] \n", playlist_id_2);
media_content_debug("playlist_id_3 [%d] \n", playlist_id_3);
/* Filter for media*/
ret = media_filter_create(&m_filter);
ret = media_filter_set_condition(m_filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
ret = media_filter_set_order(m_filter, MEDIA_CONTENT_ORDER_ASC, PLAYLIST_MEMBER_ORDER, MEDIA_CONTENT_COLLATE_DEFAULT);
/* Get media count */
media_playlist_get_media_count_from_db(playlist_id_1, m_filter, &media_count);
media_content_debug("playlist_1_media_count [%d] \n", media_count);
media_playlist_get_media_count_from_db(playlist_id_2, m_filter, &media_count);
media_content_debug("playlist_2_media_count [%d] \n", media_count);
media_playlist_get_media_count_from_db(playlist_id_3, m_filter, &media_count);
media_content_debug("playlist_3_media_count [%d] \n", media_count);
/* Get media of playlist */
GList *playlist_member_id_list = NULL;
GList *playlist_member_id_list_1 = NULL;
media_playlist_foreach_media_from_db(playlist_id_1, m_filter, playlist_item_cb, &playlist_member_id_list);
media_playlist_foreach_media_from_db(playlist_id_2, m_filter, playlist_item_cb, &playlist_member_id_list_1);
int playlist_member_id_1_1 =0;
int playlist_member_id_1_2 =0;
int playlist_member_id_1_3 =0;
int playlist_member_id_2_1 =0;
int playlist_member_id_2_2 =0;
playlist_member_id_1_1 = (int)g_list_nth_data(playlist_member_id_list, 0);
playlist_member_id_1_2 = (int)g_list_nth_data(playlist_member_id_list, 1);
playlist_member_id_1_3 = (int)g_list_nth_data(playlist_member_id_list, 2);
playlist_member_id_2_1 = (int)g_list_nth_data(playlist_member_id_list_1, 0);
playlist_member_id_2_2 = (int)g_list_nth_data(playlist_member_id_list_1, 1);
media_content_debug("playlist_member_id_1_1 [%d] \n", playlist_member_id_1_1);
media_content_debug("playlist_member_id_1_2 [%d] \n", playlist_member_id_1_2);
media_content_debug("playlist_member_id_1_3 [%d] \n", playlist_member_id_1_3);
media_content_debug("playlist_member_id_2_1 [%d] \n", playlist_member_id_2_1);
media_content_debug("playlist_member_id_2_2 [%d] \n", playlist_member_id_2_2);
media_playlist_get_play_order(playlist_1, playlist_member_id_1_1, &order_1);
media_playlist_get_play_order(playlist_1, playlist_member_id_1_2, &order_2);
media_playlist_get_play_order(playlist_1, playlist_member_id_1_3, &order_3);
media_playlist_get_play_order(playlist_2, playlist_member_id_2_1, &order_4);
media_playlist_get_play_order(playlist_2, playlist_member_id_2_2, &order_5);
media_content_debug("order_1 [%d] order_2 [%d] order_3 [%d] order_4 [%d] order_5 [%d]\n", order_1, order_2, order_3, order_4, order_5);
/* Update Playlist */
media_playlist_remove_media(playlist_2, playlist_member_id_2_1);
media_playlist_add_media(playlist_2, test_video_id);
media_playlist_set_name(playlist_2, "test_playlist");
media_playlist_set_play_order(playlist_2, playlist_member_id_2_2, order_5+100);
media_playlist_update_to_db(playlist_2);
/* Get Updated Playlist*/
media_playlist_foreach_playlist_from_db(filter, playlist_list_cb, NULL);
/* deletes the playlist */
//media_playlist_delete_from_db(playlist_id_1);
//media_playlist_delete_from_db(playlist_id_2);
if(playlist_1 != NULL)
media_playlist_destroy(playlist_1);
if(playlist_2 != NULL)
media_playlist_destroy(playlist_2);
if(playlist_3 != NULL)
media_playlist_destroy(playlist_3);
g_list_free(playlist_id_list);
g_list_free(playlist_member_id_list);
g_list_free(playlist_member_id_list_1);
if(filter != NULL)
ret = media_filter_destroy(filter);
if(m_filter != NULL)
ret = media_filter_destroy(m_filter);
return ret;
}
int test_tag_operation(void)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
media_tag_h tag_1;
media_tag_h tag_2;
media_tag_h tag_3;
int tag_id_1 = 0;
int tag_id_2 = 0;
int tag_id_3 = 0;
char *tag_name_1 = "myTag_1";
char *tag_name_2 = "myTag_2";
char *tag_name_3 = "myTag_3";
int tag_count = 0;
int media_count = 0;
filter_h filter;
media_content_debug("\n============Tag Test============\n\n");
char *g_condition = "TAG_NAME like \"%%my%%\"";
ret = media_filter_create(&filter);
ret = media_filter_set_condition(filter, g_condition, MEDIA_CONTENT_COLLATE_DEFAULT);
ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, TAG_NAME, MEDIA_CONTENT_COLLATE_DEFAULT);
/* Create Tag */
media_tag_insert_to_db(tag_name_1, &tag_1);
media_tag_insert_to_db(tag_name_2, &tag_2);
media_tag_insert_to_db(tag_name_3, &tag_3);
/* Add media to Tag */
media_tag_add_media(tag_1, test_audio_id);
media_tag_add_media(tag_1, test_video_id);
media_tag_update_to_db(tag_1);
media_tag_add_media(tag_2, test_audio_id);
media_tag_update_to_db(tag_2);
/* Get Tag Count*/
media_tag_get_tag_count_from_db(filter, &tag_count);
media_content_debug("tag_count [%d] \n", tag_count);
/* Get Tag*/
media_tag_foreach_tag_from_db(filter, tag_list_cb, NULL);
/* Get Tag id*/
media_tag_get_tag_id(tag_1, &tag_id_1);
media_content_debug("tag_id_1 [%d] \n", tag_id_1);
media_tag_get_tag_id(tag_2, &tag_id_2);
media_content_debug("tag_id_2 [%d] \n", tag_id_2);
media_tag_get_tag_id(tag_3, &tag_id_3);
media_content_debug("tag_id_3 [%d] \n", tag_id_3);
/* Get media count */
media_tag_get_media_count_from_db(tag_id_1, NULL, &media_count);
media_content_debug("tag_1_media_count [%d] \n", media_count);
media_tag_get_media_count_from_db(tag_id_2, NULL, &media_count);
media_content_debug("tag_2_media_count [%d] \n", media_count);
/* Get media of Tag */
media_tag_foreach_media_from_db(tag_id_1, NULL, media_item_cb, NULL);
media_tag_foreach_media_from_db(tag_id_2, NULL, media_item_cb, NULL);
/* Update Tag */
media_tag_add_media(tag_2, test_video_id);
media_tag_set_name(tag_2, "test_tag");
media_tag_update_to_db(tag_2);
/* Get Updated Tag*/
media_tag_foreach_tag_from_db(filter, tag_list_cb, NULL);
/* deletes the tag */
media_tag_delete_from_db(tag_id_1);
media_tag_delete_from_db(tag_id_2);
media_tag_destroy(tag_1);
media_tag_destroy(tag_2);
ret = media_filter_destroy(filter);
return ret;
}
int test_bookmark_operation(void)
{
//bookmark is only supported for video information.
int ret = MEDIA_CONTENT_ERROR_NONE;
int bookmark_count = 0;
filter_h filter;
media_content_debug("\n============Bookmark Test============\n\n");
char *g_condition = "BOOKMARK_MARKED_TIME > 300";
ret = media_filter_create(&filter);
ret = media_filter_set_condition(filter, g_condition, MEDIA_CONTENT_COLLATE_DEFAULT);
ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_DESC, BOOKMARK_MARKED_TIME, MEDIA_CONTENT_COLLATE_DEFAULT);
//insert bookmark to video
char *thumbnail_path1 = "/opt/media/Images and videos/My video clips/teat11.jpg";
media_bookmark_insert_to_db(test_video_id, 400, thumbnail_path1);
media_bookmark_insert_to_db(test_video_id, 600, thumbnail_path1);
media_bookmark_get_bookmark_count_from_db(filter, &bookmark_count);
media_content_debug("bookmark_count = [%d]\n", bookmark_count);
media_filter_destroy(filter);
return ret;
}
int test_album_list(void)
{
media_content_debug("\n============Album Test============\n\n");
int ret = MEDIA_CONTENT_ERROR_NONE;
int album_count = 0;
filter_h filter;
/*Set Filter*/
char *condition = "MEDIA_TYPE=3"; /*0-image, 1-video, 2-sound, 3-music, 4-other*/
ret = media_filter_create(&filter);
if(ret != MEDIA_CONTENT_ERROR_NONE) {
media_content_error("Fail to create filter \n");
return ret;
}
ret = media_filter_set_condition(filter, condition, MEDIA_CONTENT_COLLATE_DEFAULT);
if(ret != MEDIA_CONTENT_ERROR_NONE) {
media_content_error("Fail to set condition \n");
return ret;
}
ret = media_filter_set_order(filter, MEDIA_CONTENT_ORDER_ASC, MEDIA_ALBUM, MEDIA_CONTENT_COLLATE_NOCASE);
if(ret != MEDIA_CONTENT_ERROR_NONE) {
media_content_error("Fail to set order \n");
return ret;
}
ret = media_album_get_album_count_from_db(filter, &album_count);
if(ret != MEDIA_CONTENT_ERROR_NONE) {
media_filter_destroy(filter);
return ret;
} else {
media_content_debug("album_count [%d] \n", album_count);
}
ret = media_album_foreach_album_from_db(filter, album_list_cb, NULL);
ret = media_filter_destroy(filter);
return ret;
}
int test_group_operation(void)
{
media_content_debug("\n============Group Test============\n\n");
int ret = MEDIA_CONTENT_ERROR_NONE;
int group_count = 0;
int idx = 0;
ret = test_filter_create();
if(ret != MEDIA_CONTENT_ERROR_NONE) {
media_content_error("[%d]error(0x%08x)", __LINE__, ret);
return ret;
}
for(idx = 0; idx <= MEDIA_CONTENT_GROUP_KEYWORD; idx++)
{
ret = media_group_get_group_count_from_db(g_filter, idx, &group_count);
if(ret != MEDIA_CONTENT_ERROR_NONE) {
test_filter_destroy();
media_content_error("media_group_get_group_count_from_db fail. idx=[%d]", ret, idx);
return ret;
} else {
media_content_debug("[%2d]group_count [%d] \n", idx, group_count);
}
ret = media_group_foreach_group_from_db(g_filter, idx, group_list_cb, &idx);
}
ret = test_filter_destroy();
return ret;
}
int test_update_operation()
{
int ret = MEDIA_CONTENT_ERROR_NONE;
int i;
media_info_h media_handle = NULL;
GList *all_item_list = NULL;
/* Get all item list */
ret = media_info_foreach_media_from_db(NULL, gallery_media_item_cb, &all_item_list);
if(ret < 0) {
media_content_error("media_info_foreach_media_from_db failed: %d", ret);
return -1;
} else {
media_content_debug("media_info_foreach_media_from_db success");
char *media_id = NULL;
char *media_path = NULL;
media_content_type_e media_type = 0;
for(i = 0; i < g_list_length(all_item_list); i++) {
media_handle = (media_info_h)g_list_nth_data(all_item_list, i);
media_info_get_media_id(media_handle, &media_id);
media_info_get_file_path(media_handle, &media_path);
media_info_get_media_type(media_handle, &media_type);
media_content_debug("media_id [%d] : %s\n", i, media_id);
media_content_debug("media_type [%d] : %d\n", i, media_type);
media_content_debug("media_path [%d] : %s\n", i, media_path);
#if 0
if(media_type == MEDIA_CONTENT_TYPE_IMAGE) {
image_meta_h image_handle;
media_content_orientation_e orientation;
ret = media_info_get_image(media_handle, &image_handle);
if(ret < 0) {
media_content_error("media_info_get_image failed: %d", ret);
} else {
media_content_debug("media_info_get_image success");
//update image meta
orientation = MEDIA_CONTENT_ORIENTATION_ROT_180;
image_meta_set_orientation(image_handle, orientation);
ret = image_meta_update_to_db(image_handle);
if(ret < 0) {
media_content_error("image_meta_update_to_db failed: %d", ret);
} else {
media_content_debug("image_meta_update_to_db success");
}
}
} else if(media_type == MEDIA_CONTENT_TYPE_VIDEO) {
video_meta_h video_handle;
ret = media_info_get_video(media_handle, &video_handle);
if(ret < 0) {
media_content_error("media_info_get_video failed: %d", ret);
} else {
media_content_debug("media_info_get_video success");
//update video meta
video_meta_set_played_count(video_handle,5);
video_meta_set_played_time(video_handle,5);
video_meta_set_played_position(video_handle,5);
video_meta_update_to_db(video_handle);
ret = video_meta_update_to_db(video_handle);
if(ret < 0) {
media_content_error("video_meta_update_to_db failed: %d", ret);
} else {
media_content_debug("video_meta_update_to_db success");
}
}
} else if(media_type == MEDIA_CONTENT_TYPE_MUSIC) {//update audio meta
audio_meta_h audio_handle = NULL;
ret = media_info_get_audio(media_handle, &audio_handle);
if(ret < 0) {
media_content_error("media_info_get_audio failed: %d", ret);
} else {
media_content_debug("media_info_get_audio success");
audio_meta_set_played_count(audio_handle,5);
audio_meta_set_played_time(audio_handle,1000);
audio_meta_set_played_position(audio_handle,180);
ret = audio_meta_update_to_db(audio_handle);
if(ret < 0) {
media_content_error("audio_meta_update_to_db failed: %d", ret);
} else {
media_content_debug("audio_meta_update_to_db success");
}
}
}
#endif
}
}
return MEDIA_CONTENT_ERROR_NONE;
}
int test_insert(void)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
//char *path = "/opt/media/Images/Default.jpg";
char *path = "/opt/media/Others/other.txt";
//char *path = NULL;
media_info_h media_item = NULL;
media_content_debug("\n============DB Insert Test============\n\n");
ret = media_info_insert_to_db(path, &media_item);
if(ret == MEDIA_CONTENT_ERROR_NONE)
media_content_debug("Insertion is success\n\n");
else
media_content_error("Insertion is failed\n\n");
char *media_id = NULL;
media_info_get_media_id(media_item, &media_id);
printf("Media ID: %s\n", media_id);
ret = media_info_update_to_db(media_item);
if(ret == MEDIA_CONTENT_ERROR_NONE)
media_content_debug("media_info_update_to_db is success\n");
else
media_content_error("media_info_update_to_db is failed\n");
return ret;
}
int test_move(void)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
const char *move_media_id = "60aea677-4742-408e-b5f7-f2628062d06d";
char *dst_path = "/opt/media/Images/XX/Default1.jpg";
media_info_h move_media = NULL;
ret = media_info_get_media_from_db(move_media_id, &move_media);
if(ret == MEDIA_CONTENT_ERROR_NONE)
media_content_debug("media_info_get_media_from_db success\n\n");
else
media_content_error("media_info_get_media_from_db failed: %d\n\n", ret);
media_content_debug("\n============DB Move Test============\n\n");
if(move_media) {
ret = media_info_move_to_db(move_media, dst_path);
if(ret == MEDIA_CONTENT_ERROR_NONE)
media_content_debug("Move is success\n\n");
else
media_content_error("Move is failed\n\n");
} else {
media_content_debug("There is no item : %s\n", move_media_id);
}
return ret;
}
void thumbnail_completed_cb(media_content_error_e error, const char *path, void *user_data)
{
char *thumbnail_path = NULL;
g_cnt++;
printf("=================[%d][%d]\n", g_media_cnt, g_cnt);
printf("error_code [%d]\n", error);
printf("thumbnail_path [%s]\n", path);
if(user_data != NULL)
{
media_info_h media = (media_info_h)user_data;
media_info_get_thumbnail_path(media, &thumbnail_path);
printf("thumbnail_path get from media[%s]\n", thumbnail_path);
SAFE_FREE(thumbnail_path);
media_info_destroy(media);
}
if(g_cnt == g_media_cnt)
g_main_loop_quit(g_loop);
return;
}
bool thumbnail_create_cb(media_info_h media, void *user_data)
{
char *media_id = NULL;
media_info_h dst = NULL;
if(media == NULL)
{
media_content_debug("NO Item \n");
return true;
}
media_info_get_media_id(media, &media_id);
media_content_debug("media_id : [%s] \n", media_id);
media_info_clone(&dst, media);
media_info_create_thumbnail(dst, thumbnail_completed_cb, dst);
return true;
}
gboolean create_thumbnail_start(gpointer data)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
ret = media_info_foreach_media_from_db(g_filter, thumbnail_create_cb, NULL);
if(ret == MEDIA_CONTENT_ERROR_NONE)
media_content_debug("media_info_foreach_media_from_db is success\n\n");
else
media_content_error("media_info_foreach_media_from_db is failed\n\n");
return false;
}
int test_create_thumbnail(void)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
GSource *source = NULL;
GMainContext *context = NULL;
test_filter_create();
media_info_get_media_count_from_db(g_filter, &g_media_cnt);
media_content_debug("media_count : [%d],\n", g_media_cnt);
g_loop = g_main_loop_new(NULL, FALSE);
context = g_main_loop_get_context(g_loop);
source = g_idle_source_new();
g_source_set_callback (source, create_thumbnail_start, NULL, NULL);
g_source_attach (source, context);
g_main_loop_run(g_loop);
g_main_loop_unref(g_loop);
test_filter_destroy();
return ret;
}
int test_disconnect_database(void)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
media_content_debug("\n============DB Disconnection Test============\n\n");
ret = media_content_disconnect();
if(ret == MEDIA_CONTENT_ERROR_NONE)
media_content_debug("disconnection is success\n\n");
else
media_content_error("disconnection is failed\n\n");
return ret;
}
int g_total_photo_size = 0;
int g_total_video_size = 0;
int g_total_mp3_size = 0;
int g_total_voice_memo_size = 0;
bool dft_cb(media_info_h media, void *user_data)
{
unsigned long long file_size = 0;
media_content_type_e media_type = -1;
char *mime_type = NULL;
if(media == NULL)
{
return true;
}
media_info_get_media_type(media, &media_type);
media_info_get_size(media, &file_size);
media_info_get_mime_type(media, &mime_type);
if(media_type == MEDIA_CONTENT_TYPE_IMAGE)
{
g_total_photo_size += file_size;
}
else if(media_type == MEDIA_CONTENT_TYPE_VIDEO)
{
g_total_video_size += file_size;
}
else if(media_type == MEDIA_CONTENT_TYPE_SOUND)
{
g_total_voice_memo_size += file_size;
}
else if(media_type == MEDIA_CONTENT_TYPE_MUSIC)
{
if((mime_type != NULL) && (!strcmp("audio/mpeg", mime_type)))
{
g_total_mp3_size += file_size;
}
else
{
g_total_voice_memo_size += file_size;
}
}
else
{
printf("invalid media_type\n");
}
if(mime_type != NULL)
free(mime_type);
return true;
}
int DFT_test(void)
{
int ret = MEDIA_CONTENT_ERROR_NONE;
printf("\n============DFT_test============\n\n");
filter_h filter = NULL;
int media_cnt = 0;
/*MEDIA_TYPE 0-image, 1-video, 2-sound, 3-music, 4-other*/
ret = media_filter_create(&filter);
/*Internal Memory*/
printf("[Internal Memory]\n");
/*1. Photo ============================================================*/
ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT);
/*Get Photo Count*/
ret = media_info_get_media_count_from_db(filter, &media_cnt);
printf("Photo count = [%d]\n", media_cnt);
/*Get Photo Size*/
ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
printf("Photo size = [%d]\n", g_total_photo_size);
/*2. Video ============================================================*/
ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT);
/*Get Video Count*/
ret = media_info_get_media_count_from_db(filter, &media_cnt);
printf("Video count = [%d]\n", media_cnt);
/*Get Video Size*/
ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
printf("Video size = [%d]\n", g_total_video_size);
/*3. MP3 ============================================================*/
ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT);
/*Get MP3 Count*/
ret = media_info_get_media_count_from_db(filter, &media_cnt);
printf("MP3 count = [%d]\n", media_cnt);
/*Get MP3 Size*/
ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
printf("MP3 size = [%d]\n", g_total_mp3_size);
/*4. Voice Memo ============================================================*/
ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=0 AND (MEDIA_MIME_TYPE=\"audio/AMR\" OR MEDIA_MIME_TYPE=\"audio/mp4\")", MEDIA_CONTENT_COLLATE_DEFAULT);
/*Get Voice Memo Count*/
ret = media_info_get_media_count_from_db(filter, &media_cnt);
printf("Voice Memo count = [%d]\n", media_cnt);
/*Get Voice Memo Size*/
ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
printf("Voice Memo size = [%d]\n", g_total_voice_memo_size);
g_total_photo_size = 0;
g_total_video_size = 0;
g_total_mp3_size = 0;
g_total_voice_memo_size = 0;
/*External Memory*/
printf("\n[External Memory]\n");
/*1. Photo ============================================================*/
ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND MEDIA_TYPE=0", MEDIA_CONTENT_COLLATE_DEFAULT);
/*Get Photo Count*/
ret = media_info_get_media_count_from_db(filter, &media_cnt);
printf("Photo count = [%d]\n", media_cnt);
/*Get Photo Size*/
ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
printf("Photo size = [%d]\n", g_total_photo_size);
/*2. Video ============================================================*/
ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND MEDIA_TYPE=1", MEDIA_CONTENT_COLLATE_DEFAULT);
/*Get Video Count*/
ret = media_info_get_media_count_from_db(filter, &media_cnt);
printf("Video count = [%d]\n", media_cnt);
/*Get Video Size*/
ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
printf("Video size = [%d]\n", g_total_video_size);
/*3. MP3 ============================================================*/
ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND MEDIA_TYPE=3 AND MEDIA_MIME_TYPE=\"audio/mpeg\"", MEDIA_CONTENT_COLLATE_DEFAULT);
/*Get MP3 Count*/
ret = media_info_get_media_count_from_db(filter, &media_cnt);
printf("MP3 count = [%d]\n", media_cnt);
/*Get MP3 Size*/
ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
printf("MP3 size = [%d]\n", g_total_mp3_size);
/*4. Voice Memo ============================================================*/
ret = media_filter_set_condition(filter, "MEDIA_STORAGE_TYPE=1 AND (MEDIA_MIME_TYPE=\"audio/AMR\" OR MEDIA_MIME_TYPE=\"audio/mp4\")", MEDIA_CONTENT_COLLATE_DEFAULT);
/*Get Voice Memo Count*/
ret = media_info_get_media_count_from_db(filter, &media_cnt);
printf("Voice Memo count = [%d]\n", media_cnt);
/*Get Voice Memo Size*/
ret = media_info_foreach_media_from_db(filter, dft_cb, NULL);
printf("Voice Memo size = [%d]\n", g_total_voice_memo_size);
ret = media_filter_destroy(filter);
return 0;
}
int main(int argc, char *argv[])
{
int ret = MEDIA_CONTENT_ERROR_NONE;
media_content_debug("--- content manager test start ---\n\n");
ret = test_connect_database();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return MEDIA_CONTENT_ERROR_NONE;
#if 0
ret = test_move();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
ret = test_gallery_scenario();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
ret = test_get_all_music_files();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
ret = test_media_info_operation();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
ret = test_folder_operation();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
ret = test_playlist_operation();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
ret = test_tag_operation();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
ret = test_bookmark_operation();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
ret = test_album_list();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
ret = test_group_operation();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
ret = test_update_operation();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
ret = test_insert();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
ret = test_move();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
ret = test_create_thumbnail();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
ret = DFT_test();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
#endif
ret = test_disconnect_database();
if(ret != MEDIA_CONTENT_ERROR_NONE)
return ret;
media_content_debug("--- content manager test end ---\n");
return ret;
}
|