Remove unused API & update description
[platform/core/api/media-content.git] / include / media_info_private.h
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18 #ifndef __TIZEN_MEDIA_INFO_PRIVATE_H__
19 #define __TIZEN_MEDIA_INFO_PRIVATE_H__
20
21
22 #include <unistd.h>
23 #include <asm/unistd.h>
24 #include <string.h>
25 #include <sqlite3.h>
26 #include <stdlib.h>
27 #include <stdio.h>
28 #include <glib.h>
29 #include <media-svc.h>
30 #include <media_content_type.h>
31 #include <dlog.h>
32 #include <media-util.h>
33 #include <tzplatform_config.h>
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif /* __cplusplus */
38
39 #ifdef LOG_TAG
40 #undef LOG_TAG
41 #endif
42
43
44 /**
45  * @addtogroup CAPI_CONTENT_MEDIA_INFO_MODULE
46 * @{
47 *
48 * @file media_info_private.h
49 * @brief This file contains the media info API and related structure and enumeration. \n
50 *        Description of the audio, video,image content involves: album, artist, album_artist, author, genre and description tags. \n
51 *        Parameters of the recording are also supported, as: format, bitrate, duration, size etc. \n
52 *        Defenitions of media DB fields and tables, operations with media data relating to DB and handling with media filter attributes.
53 */
54
55
56 #define LOG_TAG "CAPI_CONTENT_MEDIA_CONTENT"
57
58 #define SAFE_STRLCPY(dst, src, n)       ((g_strlcpy(dst, src, n) < n) ? TRUE : FALSE)
59 #define SAFE_STRLCAT(dst, src, n)       g_strlcat(dst, src, n);
60 #define SAFE_FREE(src)          {if(src) {free(src); src = NULL;}}
61 #define STRING_VALID(str)               ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
62 #define SQLITE3_FINALIZE(x)     {if(x != NULL) {sqlite3_finalize(x);}}
63
64 #define MEDIA_CONTENT_PATH_PHONE        MEDIA_ROOT_PATH_INTERNAL        /**< File path prefix of files stored in phone */
65 #define MEDIA_CONTENT_PATH_MMC          MEDIA_ROOT_PATH_SDCARD          /**< File path prefix of files stored in mmc card */
66 #define MEDIA_CONTENT_THUMB_DEFAULT_PATH        tzplatform_mkpath(TZ_SYS_DATA, "file-manager-service/.thumb/thumb_default.png")
67 #define MEDIA_CONTENT_INSERT_FILES_PATH         tzplatform_mkpath(TZ_USER_DATA, "file-manager-service/")
68
69 #define MAX_QUERY_SIZE 4096
70 #define DEFAULT_QUERY_SIZE 1024
71 #define COLLATE_STR_SIZE 32
72 #define MEDIA_CONTENT_UUID_SIZE 36
73 #define BATCH_REQUEST_MAX 300
74
75 typedef enum {
76         MEDIA_CONTENT_TYPE = 0,
77         MEDIA_THUMBNAIL_TYPE,
78         MEDIA_REGISTER_TYPE
79 } media_info_error_type_e;
80
81 typedef enum {
82         MEDIA_TAG_ADD,
83         MEDIA_TAG_REMOVE,
84         MEDIA_TAG_UPDATE_TAG_NAME,
85 } tag_function_e;
86
87 typedef enum {
88         MEDIA_PLAYLIST_ADD,
89         MEDIA_PLAYLIST_REMOVE,
90         MEDIA_PLAYLIST_UPDATE_PLAYLIST_NAME,
91         MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH,
92         MEDIA_PLAYLIST_UPDATE_PLAY_ORDER,
93 } playlist_function_e;
94
95 typedef enum {
96         MEDIA_GROUP_NONE,
97         MEDIA_GROUP_ALBUM,
98         MEDIA_GROUP_FOLDER,
99         MEDIA_GROUP_PLAYLIST,
100         MEDIA_GROUP_TAG,
101         MEDIA_GROUP_BOOKMARK,
102         MEDIA_GROUP_TAG_BY_MEDIA_ID,
103         MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID,
104 } group_list_e;
105
106 typedef enum {
107         MEDIA_BATCH_INSERT_NORMAL,
108         MEDIA_BATCH_INSERT_BURSTSHOT,
109 } media_batch_insert_e;
110
111 typedef struct _filter_s
112 {
113         char *condition;
114         char *order_keyword;
115         media_content_order_e order_type;
116         media_content_collation_e condition_collate_type;
117         media_content_collation_e order_collate_type;
118         int offset;
119         int count;
120 }filter_s;
121
122 typedef struct
123 {
124         char *folder_id;                                //image id, audio id, video id
125         char *path;
126         char *name;
127         time_t modified_time;
128         media_content_storage_e storage_type;
129 }media_folder_s;
130
131 typedef struct
132 {
133         int tag_id;
134         char *name;
135 }media_tag_s;
136
137 typedef struct
138 {
139         int bookmark_id;
140         char *media_id;
141         time_t marked_time;
142         char *thumbnail_path;
143 }media_bookmark_s;
144
145 typedef struct
146 {
147         int album_id;
148         char *name;
149         char *artist;
150         char *album_art_path;
151 }media_album_s;
152
153 typedef struct
154 {
155         int playlist_id;        //playlist id
156         char *name;             // playlist name
157         char *thumbnail_path;           //playlist thumbnail path
158 }media_playlist_s;
159
160 typedef struct
161 {
162         char *media_id;
163         int width;
164         int height;
165         char *date_taken;
166         char *title;
167         char *burst_id;
168         media_content_orientation_e orientation;
169 }image_meta_s;
170
171 typedef struct
172 {
173         char *media_id;
174         char *title;
175         char *album;
176         char *artist;
177         char *genre;
178         char *composer;
179         char *year;
180         char *recorded_date;
181         char *copyright;
182         char *track_num;
183         int bitrate;
184         int duration;
185         int width;
186         int height;
187         int played_count;
188         time_t played_time;
189         int played_position;
190 }video_meta_s;
191
192 typedef struct
193 {
194         char *media_id;
195         char *title;
196         char *album;
197         char *artist;
198         char *genre;
199         char *composer;
200         char *year;
201         char *recorded_date;
202         char *copyright;
203         char *track_num;
204         int bitrate;
205         int samplerate;
206         int channel;
207         int duration;
208         int played_count;
209         time_t played_time;
210         int played_position;
211 }audio_meta_s;
212
213 typedef struct
214 {
215         char *media_id;                         //image id, audio id, video id
216         char *file_path;
217         char *display_name;
218         media_content_type_e media_type;
219         char *mime_type;
220         unsigned long long size;
221         time_t added_time;
222         time_t modified_time;
223         char *thumbnail_path;
224         char *description;
225         double longitude;
226         double latitude;
227         double altitude;
228         int rating;
229         int favourite;
230         char *title;
231         char *author;
232         char *provider;
233         char *content_name;
234         char *category;
235         char *location_tag;
236         char *age_rating;
237         char *keyword;
238         int is_drm;
239         int storage_type;
240         image_meta_s *image_meta;
241         video_meta_s *video_meta;
242         audio_meta_s *audio_meta;
243 }media_info_s;
244
245 typedef struct
246 {
247         char *media_id;         // media_uuid
248         int function;                   // Add, remove, modify
249         char *tag_name;         // tag_name
250 }media_tag_item_s;
251
252 typedef struct
253 {
254         char *media_id;         // media_uuid
255         int function;                   // Add, remove, modify
256         char *playlist_name;    // playlist_name
257         char *thumbnail_path;           //playlist thumbnail path
258         int playlist_member_id; // playlist unique id of media. Same content which has same media_id can be added to Playlist
259         int play_order;         //play_order
260 }media_playlist_item_s;
261
262 typedef struct _attribute_map_s
263 {
264         GHashTable *attr_map;
265 }attribute_s;
266
267 typedef struct
268 {
269         media_info_s *handle;
270         void *user_data;
271         media_thumbnail_completed_cb thumbnail_completed_cb;
272 }media_thumbnail_cb_s;
273
274 typedef struct
275 {
276         media_insert_completed_cb insert_completed_cb;
277         char *insert_list_path;
278         void *user_data;
279 } media_insert_cb_s;
280
281 typedef struct
282 {
283         media_content_db_update_cb update_noti_cb;
284         void *user_data;
285 } media_noti_cb_s;
286
287 typedef struct attribute_s *attribute_h;
288
289
290 typedef struct _media_content_cb_data {
291         media_scan_completed_cb callback;
292         void *user_data;
293 } media_content_scan_cb_data;
294
295
296 /* DB Table */
297 #define DB_TABLE_MEDIA                  "media"
298 #define DB_TABLE_FOLDER         "folder"
299 #define DB_TABLE_ALBUM                  "album"
300 #define DB_TABLE_TAG                    "tag"
301 #define DB_TABLE_TAG_MAP                "tag_map"
302 #define DB_TABLE_PLAYLIST               "playlist"
303 #define DB_TABLE_PLAYLIST_MAP   "playlist_map"
304 #define DB_TABLE_BOOKMARK               "bookmark"
305
306 /* DB View */
307 #define DB_VIEW_PLAYLIST        "playlist_view"
308 #define DB_VIEW_TAG                     "tag_view"
309
310 /* DB Table Alias */
311 #define DB_TABLE_ALIAS_MEDIA                    "m"
312 #define DB_TABLE_ALIAS_FOLDER                   "f"
313 #define DB_TABLE_ALIAS_PLAYLIST                 "p"
314 #define DB_TABLE_ALIAS_PLAYLIST_MAP     "pm"
315 #define DB_TABLE_ALIAS_TAG                              "t"
316 #define DB_TABLE_ALIAS_BOOKMARK         "b"
317 #define DB_TABLE_ALIAS_ALBUM                    "a"
318
319 /* DB field for media */
320 #define DB_FIELD_MEDIA_ID                                       "media_uuid"
321 #define DB_FIELD_MEDIA_PATH                             "path"
322 #define DB_FIELD_MEDIA_DISPLAY_NAME             "file_name"
323 #define DB_FIELD_MEDIA_TYPE                                     "media_type"
324 #define DB_FIELD_MEDIA_MIME_TYPE                        "mime_type"
325 #define DB_FIELD_MEDIA_SIZE                                     "size"
326 #define DB_FIELD_MEDIA_ADDED_TIME                       "added_time"
327 #define DB_FIELD_MEDIA_MODIFIED_TIME            "modified_time"
328 #define DB_FIELD_MEDIA_THUMBNAIL_PATH   "thumbnail_path"
329 #define DB_FIELD_MEDIA_TITLE                            "title"
330 #define DB_FIELD_MEDIA_ALBUM                            "album"
331 #define DB_FIELD_MEDIA_ARTIST                           "artist"
332 #define DB_FIELD_MEDIA_GENRE                            "genre"
333 #define DB_FIELD_MEDIA_COMPOSER                 "composer"
334 #define DB_FIELD_MEDIA_YEAR                             "year"
335 #define DB_FIELD_MEDIA_RECORDED_DATE            "recorded_date"
336 #define DB_FIELD_MEDIA_COPYRIGHT                        "copyright"
337 #define DB_FIELD_MEDIA_TRACK_NUM                        "track_num"
338 #define DB_FIELD_MEDIA_DESCRIPTION                      "description"
339 #define DB_FIELD_MEDIA_BITRATE                          "bitrate"
340 #define DB_FIELD_MEDIA_SAMPLERATE                       "samplerate"
341 #define DB_FIELD_MEDIA_CHANNEL                  "channel"
342 #define DB_FIELD_MEDIA_DURATION                 "duration"
343 #define DB_FIELD_MEDIA_LONGITUDE                        "longitude"
344 #define DB_FIELD_MEDIA_LATITUDE                 "latitude"
345 #define DB_FIELD_MEDIA_ALTITUDE                 "altitude"
346 #define DB_FIELD_MEDIA_WIDTH                            "width"
347 #define DB_FIELD_MEDIA_HEIGHT                           "height"
348 #define DB_FIELD_MEDIA_DATETAKEN                        "datetaken"
349 #define DB_FIELD_MEDIA_ORIENTATION              "orientation"
350 #define DB_FIELD_MEDIA_BURST_ID                 "burst_id"
351 #define DB_FIELD_MEDIA_PLAYED_COUNT             "played_count"
352 #define DB_FIELD_MEDIA_LAST_PLAYED_TIME         "last_played_time"
353 #define DB_FIELD_MEDIA_LAST_PLAYED_POSITION     "last_played_position"
354 #define DB_FIELD_MEDIA_RATING                           "rating"
355 #define DB_FIELD_MEDIA_FAVOURITE                        "favourite"
356 #define DB_FIELD_MEDIA_AUTHOR                           "author"
357 #define DB_FIELD_MEDIA_PROVIDER                 "provider"
358 #define DB_FIELD_MEDIA_CONTENT_NAME             "content_name"
359 #define DB_FIELD_MEDIA_CATEGORY                 "category"
360 #define DB_FIELD_MEDIA_LOCATION_TAG             "location_tag"
361 #define DB_FIELD_MEDIA_AGE_RATING                       "age_rating"
362 #define DB_FIELD_MEDIA_KEYWORD                  "keyword"
363 #define DB_FIELD_MEDIA_IS_DRM                           "is_drm"
364 #define DB_FIELD_MEDIA_STORAGE_TYPE             "storage_type"
365
366 /* DB field for folder */
367 #define DB_FIELD_FOLDER_ID                              "folder_uuid"
368 #define DB_FIELD_FOLDER_PATH                    "path"
369 #define DB_FIELD_FOLDER_NAME                    "name"
370 #define DB_FIELD_FOLDER_MODIFIED_TIME   "modified_time"
371 #define DB_FIELD_FOLDER_STORAGE_TYPE    "storage_type"
372
373 /* DB field for playlist */
374 #define DB_FIELD_PLAYLIST_ID                                    "playlist_id"
375 #define DB_FIELD_PLAYLIST_NAME                          "name"
376 #define DB_FIELD_PLAYLIST_MEMBER_ORDER  "play_order"
377 #define DB_FIELD_PLAYLIST_MEDIA_COUNT                   "media_count"
378
379 /* DB field for tag */
380 #define DB_FIELD_TAG_ID                 "tag_id"
381 #define DB_FIELD_TAG_NAME               "name"
382 #define DB_FIELD_TAG_MEDIA_COUNT                        "media_count"
383
384 /* DB field for bookmark */
385 #define DB_FIELD_BOOKMARK_ID    "bookmark_id"
386 #define DB_FIELD_BOOKMARK_MARKED_TIME   "marked_time"
387
388 /* DB field for album*/
389 #define DB_FIELD_ALBUM_ID                       "album_id"
390 #define DB_FIELD_ALBUM_NAME             "name"
391 #define DB_FIELD_ALBUM_ARTIST           "artist"
392
393 /* DB Query Keyword */
394 #define QUERY_KEYWORD_AND "AND"
395 #define QUERY_KEYWORD_OR "OR"
396 #define QUERY_KEYWORD_ORDER_BY "ORDER BY"
397 #define QUERY_KEYWORD_LIMIT "limit"
398 #define QUERY_KEYWORD_DESC "DESC"
399 #define QUERY_KEYWORD_SPACE " "
400 #define QUERY_KEYWORD_BRACKET ")"
401 #define UPDATE_SQL "UPDATE %s SET %s WHERE %s"
402
403 /* DB TABLE JOIN */
404 #define SELECT_EMPTY_PLAYLIST           "SELECT playlist_id, name FROM "DB_TABLE_PLAYLIST" WHERE playlist_id NOT IN (select playlist_id from "DB_TABLE_PLAYLIST_MAP")"
405 #define SELECT_EMPTY_TAG                        "SELECT tag_id, name FROM "DB_TABLE_TAG" WHERE tag_id NOT IN (SELECT tag_id FROM "DB_TABLE_TAG_MAP")"
406 #define FOLDER_MEDIA_JOIN                                       "("DB_TABLE_FOLDER" AS f INNER JOIN "DB_TABLE_MEDIA" AS m ON f.folder_uuid=m.folder_uuid) WHERE m.validity=1"
407 #define PLAYLISTMAP_MEDIA_JOIN                          "("DB_TABLE_PLAYLIST_MAP" AS pm INNER JOIN "DB_TABLE_MEDIA" AS m \
408                                                                                         ON (pm.media_uuid = m.media_uuid)) WHERE m.validity=1"
409 #define SELECT_PLAYLIST_FROM_PLAYLIST_PLAYLISTMAP_MEDIA_JOIN            "SELECT DISTINCT p.playlist_id, p.name FROM "DB_TABLE_PLAYLIST" AS p INNER JOIN "DB_TABLE_PLAYLIST_MAP" AS pm INNER JOIN "DB_TABLE_MEDIA" AS m \
410                                                                                         ON (p.playlist_id=pm.playlist_id AND pm.media_uuid = m.media_uuid) WHERE m.validity=1"
411 #define SELECT_TAG_FROM_TAG_TAGMAP_MEDIA_JOIN                                   "SELECT DISTINCT t.tag_id, t.name FROM "DB_TABLE_TAG" AS t INNER JOIN "DB_TABLE_MEDIA" AS m INNER JOIN "DB_TABLE_TAG_MAP" AS tm \
412                                                                                         ON (tm.media_uuid = m.media_uuid and tm.tag_id=t.tag_id) WHERE m.validity=1"
413 #define BOOKMARK_MEDIA_JOIN                             "("DB_TABLE_BOOKMARK" AS b INNER JOIN "DB_TABLE_MEDIA" AS m \
414                                                                                         ON (b.media_uuid = m.media_uuid)) WHERE m.validity=1"
415 #define ALBUM_MEDIA_JOIN                                        "("DB_TABLE_ALBUM" AS a INNER JOIN "DB_TABLE_MEDIA" AS m \
416                                                                                         ON (a.album_id = m.album_id)) WHERE m.validity=1"
417
418 /* Get Group List */
419 #define SELECT_ALBUM_LIST                       "SELECT DISTINCT a.album_id, a.name, a.artist, a.album_art FROM "ALBUM_MEDIA_JOIN
420 #define SELECT_ARTIST_LIST                      "SELECT DISTINCT artist FROM "DB_TABLE_MEDIA" WHERE validity=1"
421 #define SELECT_GENRE_LIST                       "SELECT DISTINCT genre FROM "DB_TABLE_MEDIA" WHERE validity=1"
422 #define SELECT_COMPOSER_LIST            "SELECT DISTINCT composer FROM "DB_TABLE_MEDIA" WHERE validity=1 "
423 #define SELECT_YEAR_LIST                                "SELECT DISTINCT year FROM "DB_TABLE_MEDIA" WHERE validity=1 "
424 #define SELECT_MEDIA_GROUP_LIST "SELECT DISTINCT %s FROM "DB_TABLE_MEDIA" WHERE validity=1 "
425
426 #define SELECT_FOLDER_LIST                      "SELECT DISTINCT f.folder_uuid, f.path, f.name, f.storage_type, f.modified_time FROM "FOLDER_MEDIA_JOIN
427 //#define SELECT_TAG_LIST                               SELECT_EMPTY_TAG" UNION "SELECT_TAG_FROM_TAG_TAGMAP_MEDIA_JOIN
428 //#define SELECT_PLAYLIST_LIST                  SELECT_EMPTY_PLAYLIST" UNION "SELECT_PLAYLIST_FROM_PLAYLIST_PLAYLISTMAP_MEDIA_JOIN
429 #define SELECT_TAG_LIST                         "SELECT DISTINCT tag_id, name FROM "DB_VIEW_TAG" WHERE 1 "
430 #define SELECT_PLAYLIST_LIST            "SELECT DISTINCT playlist_id, name, thumbnail_path FROM "DB_VIEW_PLAYLIST" WHERE 1 "
431 #define SELECT_BOOKMARK_LIST            "SELECT DISTINCT b.bookmark_id, b.media_uuid, b.marked_time, b.thumbnail_path FROM "BOOKMARK_MEDIA_JOIN
432
433 /* Get Group Count */
434 #define SELECT_ALBUM_COUNT              "SELECT COUNT(DISTINCT a.album_id) FROM "ALBUM_MEDIA_JOIN
435 #define SELECT_ARTIST_COUNT             "SELECT COUNT(DISTINCT artist) FROM "DB_TABLE_MEDIA" WHERE validity=1"
436 #define SELECT_GENRE_COUNT                      "SELECT COUNT(DISTINCT genre) FROM "DB_TABLE_MEDIA" WHERE validity=1"
437 #define SELECT_COMPOSER_COUNT   "SELECT COUNT(DISTINCT composer) FROM "DB_TABLE_MEDIA" WHERE validity=1"
438 #define SELECT_YEAR_COUNT                       "SELECT COUNT(DISTINCT year) FROM "DB_TABLE_MEDIA" WHERE validity=1"
439 #define SELECT_FOLDER_COUNT             "SELECT COUNT(DISTINCT f.folder_uuid) FROM "FOLDER_MEDIA_JOIN
440 //#define SELECT_TAG_COUNT                      "SELECT COUNT(*) FROM ("SELECT_TAG_LIST
441 //#define SELECT_PLAYLIST_COUNT         "SELECT COUNT(*) FROM ("SELECT_PLAYLIST_LIST
442 #define SELECT_TAG_COUNT                        "SELECT COUNT(DISTINCT tag_id) FROM "DB_VIEW_TAG" WHERE 1 "
443 #define SELECT_PLAYLIST_COUNT           "SELECT COUNT(DISTINCT playlist_id) FROM "DB_VIEW_PLAYLIST" WHERE 1 "
444 #define SELECT_BOOKMARK_COUNT   "SELECT COUNT(DISTINCT b.bookmark_id) FROM "BOOKMARK_MEDIA_JOIN
445 #define SELECT_MEDIA_GROUP_COUNT        "SELECT COUNT(*) FROM ("SELECT_MEDIA_GROUP_LIST
446 /*count(distinct x) count only non-null values, but select distinct X returns include null. so sync the result of count and list, don't use count(distinct x)*/
447
448 /* Get Media Count of Group */
449 #define SELECT_MEDIA_COUNT_FROM_MEDIA                   "SELECT COUNT(*) FROM ("SELECT_MEDIA_ITEM               //to apply limit condition. "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1"
450 #define SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE    "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 "
451 #define SELECT_MEDIA_COUNT_FROM_ALBUM                   "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 AND album_id='%d'"
452 #define SELECT_MEDIA_COUNT_FROM_ARTIST                  "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 AND artist='%q'"
453 #define SELECT_MEDIA_COUNT_FROM_GENRE                   "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 AND genre='%q'"
454 #define SELECT_MEDIA_COUNT_FROM_COMPOSER                "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 AND composer='%q'"
455 #define SELECT_MEDIA_COUNT_FROM_YEAR                            "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 AND year='%q'"
456 #define SELECT_MEDIA_COUNT_FROM_GROUP                   "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP         //to apply limit condition.
457 #define SELECT_MEDIA_COUNT_FROM_GROUP_NULL              "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP_NULL    //to apply limit condition.
458 #define SELECT_MEDIA_COUNT_FROM_FOLDER                  "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity=1 AND folder_uuid='%q'"
459 //#define SELECT_MEDIA_COUNT_FROM_TAG                           "SELECT COUNT(*) FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d AND media_uuid IN                                                                                                      (SELECT media_uuid FROM "DB_TABLE_MEDIA" WHERE validity=1"
460 //#define SELECT_MEDIA_COUNT_FROM_PLAYLIST              "SELECT COUNT(*) FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d AND media_uuid IN                                                                                                    (SELECT media_uuid FROM "DB_TABLE_MEDIA" WHERE validity=1"
461 #define SELECT_MEDIA_COUNT_FROM_TAG                             "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE (tag_id=%d AND media_count>0) "
462 #define SELECT_MEDIA_COUNT_FROM_PLAYLIST                "SELECT COUNT(*) FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and media_count>0) "
463
464 /* Get Group Info by Group ID*/
465 #define SELECT_ALBUM_FROM_ALBUM         "SELECT * FROM "DB_TABLE_ALBUM" WHERE album_id=%d"
466 #define SELECT_FOLDER_FROM_FOLDER               "SELECT * FROM "DB_TABLE_FOLDER" WHERE folder_uuid='%s'"
467 #define SELECT_FOLDER_BY_PATH                   "SELECT * FROM "DB_TABLE_FOLDER" WHERE path='%q'"
468 #define SELECT_PLAYLIST_FROM_PLAYLIST   "SELECT * FROM "DB_TABLE_PLAYLIST" WHERE playlist_id=%d"
469 #define SELECT_TAG_FROM_TAG                     "SELECT * FROM "DB_TABLE_TAG" WHERE tag_id=%d"
470 #define SELECT_TAG_BY_NAME                              "SELECT * FROM "DB_TABLE_TAG" WHERE name='%q'"
471
472 /* Tag info*/
473 #define INSERT_TAG_TO_TAG                                               "INSERT INTO "DB_TABLE_TAG" (name) VALUES (%Q)"
474 #define REMOVE_TAG_ITEM_FROM_TAG_MAP            "DELETE FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d AND media_uuid='%q'"
475 #define UPDATE_TAG_NAME_FROM_TAG                        "UPDATE "DB_TABLE_TAG" SET name='%q' WHERE tag_id=%d"
476 //#define SELECT_TAG_COUNT_BY_MEDIA_ID                  "SELECT COUNT(*) FROM "DB_TABLE_TAG" WHERE tag_id IN (SELECT tag_id FROM "DB_TABLE_TAG_MAP" WHERE media_uuid = '%q')"
477 //#define SELECT_TAG_LIST_BY_MEDIA_ID                           "SELECT * FROM "DB_TABLE_TAG" WHERE tag_id IN (SELECT tag_id FROM "DB_TABLE_TAG_MAP" WHERE media_uuid = '%s')"
478 #define SELECT_TAG_COUNT_BY_MEDIA_ID                    "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE media_uuid = '%q'"
479 #define SELECT_TAG_LIST_BY_MEDIA_ID                             "SELECT tag_id, name FROM "DB_VIEW_TAG" WHERE media_uuid = '%s'"
480
481 /* Playlist Info */
482 #define INSERT_PLAYLIST_TO_PLAYLIST                                             "INSERT INTO "DB_TABLE_PLAYLIST" (name) VALUES (%Q)"
483 #define UPDATE_PLAYLIST_NAME_FROM_PLAYLIST                      "UPDATE "DB_TABLE_PLAYLIST" SET name='%q' WHERE playlist_id=%d"
484 #define UPDATE_PLAYLIST_THUMBNAIL_FROM_PLAYLIST                 "UPDATE "DB_TABLE_PLAYLIST" SET thumbnail_path='%q' WHERE playlist_id=%d"
485 #define SELECT_PLAYLIST_ID_FROM_PLAYLIST                                "SELECT playlist_id FROM "DB_TABLE_PLAYLIST" WHERE name='%q'"
486 //#define SELECT_PLAYLIST_ITEM_ID_FROM_PLAYLIST_MAP             "SELECT pm._id, pm.media_uuid FROM "PLAYLISTMAP_MEDIA_JOIN" AND pm.playlist_id=%d"
487 #define SELECT_PLAYLIST_ITEM_ID_FROM_PLAYLIST_VIEW              "SELECT pm_id, media_uuid FROM "DB_VIEW_PLAYLIST" WHERE playlist_id=%d "
488
489 //#define SELECT_PLAY_ORDER_FROM_PLAYLIST_MAP                   "SELECT play_order FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d and _id=%d"
490 #define SELECT_PLAY_ORDER_FROM_PLAYLIST_VIEW                    "SELECT play_order FROM "DB_VIEW_PLAYLIST" WHERE playlist_id=%d and pm_id=%d"
491 //#define SELECT_MAX_PLAY_ORDER_FROM_PLAYLIST_MAP       "SELECT MAX(play_order) FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d"
492 #define SELECT_MAX_PLAY_ORDER_FROM_PLAYLIST_VIEW        "SELECT MAX(play_order) FROM "DB_VIEW_PLAYLIST" WHERE playlist_id=%d"
493 #define REMOVE_PLAYLIST_ITEM_FROM_PLAYLIST_MAP          "DELETE FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d AND _id=%d"
494 #define UPDATE_PLAYLIST_ORDER_FROM_PLAYLIST_MAP         "UPDATE "DB_TABLE_PLAYLIST_MAP" SET play_order=%d WHERE playlist_id=%d AND _id=%d"
495
496 /* Bookmark */
497 #define INSERT_BOOKMARK_TO_BOOKMARK     "INSERT INTO "DB_TABLE_BOOKMARK" (media_uuid, marked_time, thumbnail_path) VALUES ('%q', '%d', %Q)"
498 #define SELECT_BOOKMARK_COUNT_BY_MEDIA_ID       "SELECT COUNT(*) FROM "DB_TABLE_BOOKMARK" WHERE media_uuid='%q'"
499 #define SELECT_BOOKMARK_LIST_BY_MEDIA_ID        "SELECT * FROM "DB_TABLE_BOOKMARK" WHERE media_uuid='%q'"
500 #define SELECT_BOOKMARK_LIST_BY_MEDIA_ID_USUAL  "SELECT * FROM "DB_TABLE_BOOKMARK" WHERE media_uuid='%s'"
501
502 /* Get Meta */
503 #define MEDIA_AV_META                   "media_uuid, title, album, artist, genre, composer, year, recorded_date, copyright, track_num, bitrate, duration, played_count, last_played_time, last_played_position"
504 #define MEDIA_IMAGE_META                "media_uuid, width, height, datetaken, orientation"
505 #define SELECT_IMAGE_FROM_MEDIA "SELECT "MEDIA_IMAGE_META" FROM "DB_TABLE_MEDIA" WHERE media_uuid='%s'"
506 #define SELECT_AUDIO_FROM_MEDIA "SELECT "MEDIA_AV_META", samplerate, channel FROM "DB_TABLE_MEDIA" WHERE media_uuid='%s'"
507 #define SELECT_VIDEO_FROM_MEDIA "SELECT "MEDIA_AV_META", width, height FROM "DB_TABLE_MEDIA" WHERE media_uuid='%s'"
508
509 /* Update Meta*/
510 #define UPDATE_AV_META_FROM_MEDIA       "UPDATE "DB_TABLE_MEDIA" SET played_count=%d, last_played_time=%d, last_played_position=%d WHERE media_uuid='%q'"
511 #define UPDATE_IMAGE_META_FROM_MEDIA    "UPDATE "DB_TABLE_MEDIA" SET orientation=%d WHERE media_uuid='%q'"
512
513 /* Get Media list of Group */
514 //#define MEDIA_INFO_ITEM "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, thumbnail_path, description,
515 //                                                      rating, favourite, author, provider, content_name, category, location_tag, age_rating, is_drm, storage_type"
516 #define MEDIA_INFO_ITEM "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, thumbnail_path, description, \
517                                                         rating, favourite, author, provider, content_name, category, location_tag, age_rating, keyword, is_drm, storage_type, longitude, latitude, altitude, width, height, datetaken, orientation, title, album, artist, genre, composer, year, recorded_date, copyright, track_num, bitrate, duration, played_count, last_played_time, last_played_position, samplerate, channel, burst_id"
518
519 #define SELECT_MEDIA_ITEM                                       "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1"
520 #define SELECT_MEDIA_FROM_MEDIA                 "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND media_uuid='%s'"
521 #define SELECT_MEDIA_BY_PATH                            "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND path='%q'"
522 #define SELECT_MEDIA_FROM_ALBUM                 "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND album_id=%d"
523 #define SELECT_MEDIA_FROM_GROUP                 "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND %s='%q'"
524 #define SELECT_MEDIA_FROM_GROUP_NULL    "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND %s IS NULL"
525 #define SELECT_MEDIA_FROM_FOLDER                        "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE validity=1 AND folder_uuid='%q'"
526 #define SELECT_MEDIA_FROM_TAG                           "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE media_uuid IN (SELECT media_uuid FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d) AND validity=1"
527 #define SELECT_MEDIA_FROM_PLAYLIST              "SELECT "MEDIA_INFO_ITEM" FROM "DB_TABLE_MEDIA" WHERE media_uuid IN (SELECT media_uuid FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d) AND validity=1"
528 #define SELECT_MEDIA_PATH_BY_ID                 "SELECT path FROM "DB_TABLE_MEDIA" WHERE media_uuid='%q'"
529
530 /* Delete */
531 #define DELETE_MEDIA_FROM_MEDIA                         "DELETE FROM "DB_TABLE_MEDIA" WHERE media_uuid='%q'"
532 #define DELETE_MEDIA_FROM_MEDIA_BATCH           "DELETE FROM "DB_TABLE_MEDIA" WHERE %s"
533 #define DELETE_FOLDER_FROM_FOLDER                       "DELETE FROM "DB_TABLE_FOLDER" WHERE folder_uuid='%q'"
534 #define DELETE_PLAYLIST_FROM_PLAYLIST                   "DELETE FROM "DB_TABLE_PLAYLIST" WHERE playlist_id=%d"
535 #define DELETE_TAG_FROM_TAG                                     "DELETE FROM "DB_TABLE_TAG" WHERE tag_id=%d"
536 #define DELETE_BOOKMARK_FROM_BOOKMARK           "DELETE FROM "DB_TABLE_BOOKMARK" WHERE bookmark_id=%d"
537
538
539 /**
540  *@internal
541  */
542 int _content_query_prepare(sqlite3_stmt **stmt, char *select_query, char *condition_query, char *option_query);
543
544 /**
545  *@internal
546  */
547 int _content_error_capi(int type, int cotent_error);
548
549 /**
550  *@internal
551  */
552 int _content_query_sql(char *query_str);
553
554 /**
555  *@internal
556  */
557 MediaSvcHandle* _content_get_db_handle(void);
558
559 /**
560  *@internal
561  */
562 attribute_h _content_get_attirbute_handle(void);
563
564 /**
565  *@internal
566  */
567 attribute_h _content_get_alias_attirbute_handle(void);
568
569 /**
570  *@internal
571  */
572 void _media_info_item_get_detail(sqlite3_stmt *stmt, media_info_h media);
573
574 /**
575  *@internal
576  */
577 int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count);
578
579 /**
580  *@internal
581  */
582 int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *group_count);
583
584 /**
585  *@internal
586  */
587 int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_cb callback, void *user_data);
588
589 /**
590  *@internal
591  */
592 int _media_db_get_album(filter_h filter, media_album_cb callback, void *user_data);
593
594 /**
595  *@internal
596  */
597 int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_data);
598
599 /**
600  *@internal
601  */
602 int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *user_data);
603
604 /**
605  *@internal
606  */
607 int _media_db_get_playlist_item(int playlist_id, filter_h filter, playlist_member_cb callback, void *user_data);
608
609 /**
610  *@internal
611  */
612 int _media_db_get_tag(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data);
613
614 /**
615  *@internal
616  */
617 int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data);
618
619 /**
620  *@internal
621  */
622 int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_list_e group_type, int *item_count);
623
624 /**
625  *@internal
626  */
627 int _media_db_get_group_item_count(const char *group_name, filter_h filter, group_list_e group_type, int *item_count);
628
629 /**
630  *@internal
631  */
632 int _media_db_get_group_item_by_id(int group_id, filter_h filter, media_info_cb callback, void *user_data, group_list_e group_type);
633
634 /**
635  *@internal
636  */
637 int _media_db_get_group_item(const char *group_name, filter_h filter, media_info_cb callback, void *user_data, group_list_e group_type);
638
639 /**
640  *@internal
641  */
642 int _media_db_get_media_group_item_count(const char *group_name, media_group_e group, filter_h filter, int *item_count);
643
644 /**
645  *@internal
646  */
647 int _media_db_get_media_group_item(const char *group_name, media_group_e group, filter_h filter, media_info_cb callback, void *user_data);
648
649 /**
650  * @internal
651  * @brief Creates a media filter attribute handle.
652  * @details This function creates a media filter attribute handle. The handle can be
653  * used to convert to attributes of database from attributes of user.
654  * @remarks The @a handle must be released with media_filter_attribute_destory() by you.
655  * @param[out] filter A handle to media filter attribute
656  * @return 0 on success, otherwise a negative error value.
657  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
658  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
659  * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory
660  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
661  * @see media_filter_attribute_destory()
662  *
663  */
664 int _media_filter_attribute_create(attribute_h *attr);
665
666 /**
667  * @internal
668  * @brief Add the attributes to the handle.
669  * @details This function add the attribute to handle.
670  * @param[in] filter The handle to media filter attribute
671  * @param[in] user_attr The user attribute
672  * @param[in] platform_attr The platform attribute
673  * @return 0 on success, otherwise a negative error value.
674  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
675  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
676  * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory
677  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
678  * @see media_filter_attribute_remove()
679  *
680  */
681 int _media_filter_attribute_add(attribute_h atrr, char *user_attr, char *platform_attr);
682
683 /**
684  * @internal
685  * @brief Destroys a media filter attribute handle.
686  * @details The function frees all resources related to the media filter attribute handle. The filter attribute
687  * handle no longer can be used to perform any operation. A new handle
688  * has to be created before the next usage.
689  *
690  * @param[in] filter The handle to media filter attribute
691  * @return 0 on success, otherwise a negative error value.
692  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
693  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
694  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
695  * @see media_filter_create()
696  *
697  */
698 int _media_filter_attribute_destory(attribute_h attr);
699
700 /**
701  * @internal
702  * @brief Replace to platform attributes from user attributes.
703  * @details This function replace to platform attributes from user attributes to generate the WHERE clause
704  * @param[in] filter The handle to media filter attribute
705  * @param[in] user_attr The user attribute
706  * @param[in] platform_attr The platform attribute
707  * @return 0 on success, otherwise a negative error value.
708  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
709  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
710  * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory
711  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
712  * @see media_filter_attribute_create()
713  * @see media_filter_attribute_destory()
714  *
715  */
716 int _media_filter_attribute_generate(attribute_h attr, char *condition, media_content_collation_e collate_type, char **generated_condition);
717
718
719 /**
720  * @internal
721  * @brief Replace to platform attributes from user attributes.
722  * @details This function replace to platform attributes from user attributes to generate the WHERE clause
723  * @param[in] filter The handle to media filter attribute
724  * @param[in] attr The attribute
725  * @param[in] generated_option The handle to generated option
726  * @return 0 on success, otherwise a negative error value.
727  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
728  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
729  * @retval #MEDIA_CONTENT_ERROR_DB_FAILED Filed DB
730  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
731  * @see media_filter_attribute_create()
732  * @see media_filter_attribute_destory()
733  *
734  */
735
736 int _media_filter_attribute_option_generate(attribute_h attr, filter_h filter, char **generated_option);
737
738 #define FONT_COLOR_RESET    "\033[0m"
739 #define FONT_COLOR_RED      "\033[31m"
740 #define FONT_COLOR_GREEN    "\033[32m"
741 #define FONT_COLOR_YELLOW   "\033[33m"
742 #define FONT_COLOR_BLUE     "\033[34m"
743 #define FONT_COLOR_PURPLE   "\033[35m"
744 #define FONT_COLOR_CYAN     "\033[36m"
745 #define FONT_COLOR_GRAY     "\033[37m"
746
747 #define media_content_gettid() syscall(__NR_gettid)
748
749 #define media_content_retv_if(expr, val) do { \
750                         if(expr) { \
751                                 LOGE(FONT_COLOR_RED"[%d]", media_content_gettid());    \
752                                 return (val); \
753                         } \
754                 } while (0)
755
756 #define media_content_debug(fmt, arg...) do { \
757                         LOGD(FONT_COLOR_RESET"[%d]"fmt"", media_content_gettid(), ##arg);     \
758                 } while (0)
759
760 #define media_content_info(fmt, arg...) do { \
761                         LOGD(FONT_COLOR_GREEN"[%d]"fmt"", media_content_gettid() ,##arg);     \
762                 } while (0)
763
764 #define media_content_error(fmt, arg...) do { \
765                         LOGE(FONT_COLOR_RED"[%d]"fmt"",media_content_gettid(), ##arg);     \
766                 } while (0)
767
768 #define media_content_debug_func() do { \
769                         LOGD(FONT_COLOR_RESET"[%d]", media_content_gettid());     \
770                 } while (0)
771
772
773
774 #ifdef __cplusplus
775 }
776 #endif /* __cplusplus */
777 #endif /*__TIZEN_MEDIA_INFO_PRIVATE_H__*/