[ACR-644] Add 360 content feature
[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 <errno.h>
34 #include <tzplatform_config.h>
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif /* __cplusplus */
39
40 #ifdef LOG_TAG
41 #undef LOG_TAG
42 #endif
43
44
45 /**
46  * @addtogroup CAPI_CONTENT_MEDIA_INFO_MODULE
47 * @{
48 *
49 * @file media_info_private.h
50 * @brief This file contains the media info API and related structure and enumeration. \n
51 *        Description of the audio, video,image content involves: album, artist, album_artist, author, genre and description tags. \n
52 *        Parameters of the recording are also supported, as: format, bitrate, duration, size etc. \n
53 *        Defenitions of media DB fields and tables, operations with media data relating to DB and handling with media filter attributes.
54 */
55
56
57 #define LOG_TAG "CAPI_CONTENT_MEDIA_CONTENT"
58
59 #define SAFE_STRLCPY(dst, src, n)       ((g_strlcpy(dst, src, n) < n) ? TRUE : FALSE)
60 #define SAFE_STRLCAT(dst, src, n)       g_strlcat(dst, src, n);
61 #define SAFE_FREE(src)          {if (src) {free(src); src = NULL; } }
62 #define STRING_VALID(str)               ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
63 #define SQLITE3_FINALIZE(x)     {if (x != NULL) sqlite3_finalize(x); }
64 #define SQLITE3_SAFE_FREE(x)    {if (x != NULL) {sqlite3_free(x); x = NULL; } }
65
66 #define MEDIA_CONTENT_THUMB_DEFAULT_PATH                tzplatform_mkpath(TZ_USER_SHARE, "media/.thumb/thumb_default.png")
67 #define MEDIA_CONTENT_INSERT_FILES_PATH         tzplatform_getenv(TZ_USER_SHARE)
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_INFO_UUID = 0,
77         MEDIA_INFO_PATH,
78         MEDIA_INFO_FILE_NAME,
79         MEDIA_INFO_TYPE,
80         MEDIA_INFO_MIME_TYPE,
81         MEDIA_INFO_SIZE,
82         MEDIA_INFO_ADDED_TIME,
83         MEDIA_INFO_MODIFIED_TIME,
84         MEDIA_INFO_THUMBNAIL_PATH,
85         MEDIA_INFO_DESCRIPTION,
86         MEDIA_INFO_RATING,
87         MEDIA_INFO_FAVOURITE,
88         MEDIA_INFO_AUTHOR,
89         MEDIA_INFO_PROVIDER,
90         MEDIA_INFO_CONTENT_NAME,
91         MEDIA_INFO_CATEGORY,
92         MEDIA_INFO_LOCATION_TAG,
93         MEDIA_INFO_AGE_RATING,
94         MEDIA_INFO_KEYWORD,
95         MEDIA_INFO_IS_DRM,
96         MEDIA_INFO_STORAGE_TYPE,
97         MEDIA_INFO_LONGITUDE,
98         MEDIA_INFO_LATITUDE,
99         MEDIA_INFO_ALTITUDE,
100         MEDIA_INFO_EXPOSURE_TIME,
101         MEDIA_INFO_FNUMBER,
102         MEDIA_INFO_ISO,
103         MEDIA_INFO_MODEL,
104         MEDIA_INFO_WIDTH,
105         MEDIA_INFO_HEIGHT,
106         MEDIA_INFO_DATETAKEN,
107         MEDIA_INFO_ORIENTATION,
108         MEDIA_INFO_TITLE,
109         MEDIA_INFO_ALBUM,
110         MEDIA_INFO_ARTIST,
111         MEDIA_INFO_ALBUM_ARTIST,
112         MEDIA_INFO_GENRE,
113         MEDIA_INFO_COMPOSER,
114         MEDIA_INFO_YEAR,
115         MEDIA_INFO_RECORDED_DATE,
116         MEDIA_INFO_COPYRIGHT,
117         MEDIA_INFO_TRACK_NUM,
118         MEDIA_INFO_BITRATE,
119         MEDIA_INFO_BITPERSAMPLE,
120         MEDIA_INFO_DURATION,
121         MEDIA_INFO_PLAYED_COUNT,
122         MEDIA_INFO_LAST_PLAYED_TIME,
123         MEDIA_INFO_LAST_PLAYED_POSITION,
124         MEDIA_INFO_SAMPLERATE,
125         MEDIA_INFO_CHANNEL,
126         MEDIA_INFO_BURST_ID,
127         MEDIA_INFO_TIMELINE,
128         MEDIA_INFO_WEATHER,
129         MEDIA_INFO_SYNC_STATUS,
130         MEDIA_INFO_STORAGE_UUID,
131         MEDIA_INFO_IS_360,
132         MEDIA_INFO_ITEM_MAX,
133 } media_info_item_e;
134
135 typedef enum {
136         MEDIA_CONTENT_TYPE = 0,
137         MEDIA_THUMBNAIL_TYPE,
138         MEDIA_REGISTER_TYPE
139 } media_info_error_type_e;
140
141 typedef enum {
142         MEDIA_TAG_ADD,
143         MEDIA_TAG_REMOVE,
144         MEDIA_TAG_UPDATE_TAG_NAME,
145 } tag_function_e;
146
147 typedef enum {
148         MEDIA_PLAYLIST_ADD,
149         MEDIA_PLAYLIST_REMOVE,
150         MEDIA_PLAYLIST_UPDATE_PLAYLIST_NAME,
151         MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH,
152         MEDIA_PLAYLIST_UPDATE_PLAY_ORDER,
153 } playlist_function_e;
154
155 typedef enum {
156         MEDIA_GROUP_NONE,
157         MEDIA_GROUP_ALBUM,
158         MEDIA_GROUP_FOLDER,
159         MEDIA_GROUP_PLAYLIST,
160         MEDIA_GROUP_TAG,
161         MEDIA_GROUP_BOOKMARK,
162         MEDIA_GROUP_TAG_BY_MEDIA_ID,
163         MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID,
164         MEDIA_GROUP_STORAGE,
165         MEDIA_GROUP_FACE_BY_MEDIA_ID,
166 } group_list_e;
167
168 typedef enum {
169         MEDIA_BATCH_INSERT_NORMAL,
170         MEDIA_BATCH_INSERT_BURSTSHOT,
171 } media_batch_insert_e;
172
173 typedef struct _filter_s {
174         char *storage_id;
175         char *condition;
176         char *order_keyword;
177         media_content_order_e order_type;
178         media_content_collation_e condition_collate_type;
179         media_content_collation_e order_collate_type;
180         int offset;
181         int count;
182 } filter_s;
183
184 typedef struct {
185         char *folder_id;
186         char *parent_folder_id;
187         char *path;
188         char *name;
189         time_t modified_time;
190         media_content_storage_e storage_type;
191         char *storage_uuid;
192         int folder_order;
193 } media_folder_s;
194
195 typedef struct {
196         int tag_id;
197         char *name;
198         GList *item_list;
199 } media_tag_s;
200
201 typedef struct {
202         int bookmark_id;
203         char *media_id;
204         time_t marked_time;
205         char *thumbnail_path;
206 } media_bookmark_s;
207
208 typedef struct {
209         int album_id;
210         char *name;
211         char *artist;
212         char *album_art_path;
213 } media_album_s;
214
215 typedef struct {
216         int playlist_id;
217         char *name;
218         char *thumbnail_path;
219         GList *item_list;
220 } media_playlist_s;
221
222 typedef struct {
223         char *media_id;
224         int width;
225         int height;
226         char *date_taken;
227         char *title;
228         char *burst_id;
229         char *weather;
230         char *exposure_time;
231         double fnumber;
232         int iso;
233         char *model;
234         media_content_orientation_e orientation;
235 } image_meta_s;
236
237 typedef struct {
238         char *media_id;
239         char *title;
240         char *album;
241         char *artist;
242         char *album_artist;
243         char *genre;
244         char *composer;
245         char *year;
246         char *recorded_date;
247         char *copyright;
248         char *track_num;
249         int bitrate;
250         int duration;
251         int width;
252         int height;
253         int played_count;
254         time_t played_time;
255         int played_position;
256 } video_meta_s;
257
258 typedef struct {
259         char *media_id;
260         char *title;
261         char *album;
262         char *artist;
263         char *album_artist;
264         char *genre;
265         char *composer;
266         char *year;
267         char *recorded_date;
268         char *copyright;
269         char *track_num;
270         int bitrate;
271         int bitpersample;
272         int samplerate;
273         int channel;
274         int duration;
275         int played_count;
276         time_t played_time;
277         int played_position;
278 } audio_meta_s;
279
280 typedef struct {
281         char *media_id;
282         char *file_path;
283         char *display_name;
284         media_content_type_e media_type;
285         char *mime_type;
286         unsigned long long size;
287         time_t added_time;
288         time_t modified_time;
289         time_t timeline;
290         char *thumbnail_path;
291         char *description;
292         double longitude;
293         double latitude;
294         double altitude;
295         char *weather;
296         int rating;
297         time_t favourite;
298         char *title;
299         char *author;
300         char *provider;
301         char *content_name;
302         char *category;
303         char *location_tag;
304         char *age_rating;
305         char *keyword;
306         int is_drm;
307         int storage_type;
308         int played_count;
309         time_t played_time;
310         int played_position;
311         char *storage_uuid;
312         int sync_status;
313         unsigned int request_id;
314         int is_360;
315         image_meta_s *image_meta;
316         video_meta_s *video_meta;
317         audio_meta_s *audio_meta;
318 } media_info_s;
319
320 typedef struct {
321         char *media_id;
322         int function;
323         char *tag_name;
324 } media_tag_item_s;
325
326 typedef struct {
327         char *media_id;
328         int function;
329         char *playlist_name;
330         char *thumbnail_path;
331         int playlist_member_id;
332         int play_order;
333 } media_playlist_item_s;
334
335 typedef struct {
336         char *storage_id;
337         char *storage_name;
338         char *storage_path;
339         char *storage_account;
340         int storage_type;
341 } media_storage_s;
342
343 typedef struct {
344         char *face_id;                          /* face uuid */
345         char *media_id;                 /* media uuid */
346         unsigned int face_rect_x;       /* x position of face */
347         unsigned int face_rect_y;       /* y position of face */
348         unsigned int face_rect_w;       /* width of face */
349         unsigned int face_rect_h;       /* height of face */
350         int orientation;                        /* orientation */
351         char *face_tag;                 /* face tag */
352 } media_face_s;
353
354 typedef struct _attribute_map_s {
355         GHashTable *attr_map;
356 } attribute_s;
357
358 typedef struct {
359         media_info_s *handle;
360         void *user_data;
361         media_thumbnail_completed_cb thumbnail_completed_cb;
362 } media_thumbnail_cb_s;
363
364 typedef struct {
365         media_insert_completed_cb insert_completed_cb;
366         char *insert_list_path;
367         void *user_data;
368 } media_insert_cb_s;
369
370 typedef struct {
371         media_content_db_update_cb update_noti_cb;
372         void *user_data;
373 } media_noti_cb_s;
374
375 typedef struct attribute_s *attribute_h;
376
377
378 typedef struct _media_content_cb_data {
379         media_scan_completed_cb callback;
380         void *user_data;
381 } media_content_scan_cb_data;
382
383
384 /* DB Table */
385 #define DB_TABLE_MEDIA                  "media"
386 #define DB_TABLE_FOLDER         "folder"
387 #define DB_TABLE_ALBUM                  "album"
388 #define DB_TABLE_TAG                    "tag"
389 #define DB_TABLE_TAG_MAP                "tag_map"
390 #define DB_TABLE_PLAYLIST               "playlist"
391 #define DB_TABLE_PLAYLIST_MAP   "playlist_map"
392 #define DB_TABLE_BOOKMARK               "bookmark"
393 #define DB_TABLE_STORAGE                "storage"
394 #define DB_TABLE_MEDIA_VIEW     "media_view"
395 #define DB_TABLE_FACE                   "face"
396 #define DB_TABLE_FACE_SCAN_LIST "face_scan_list"
397
398 /* DB View */
399 #define DB_VIEW_PLAYLIST        "playlist_view"
400 #define DB_VIEW_TAG                     "tag_view"
401
402 /* DB Table Alias */
403 #define DB_TABLE_ALIAS_MEDIA                    "m"
404 #define DB_TABLE_ALIAS_FOLDER                   "f"
405 #define DB_TABLE_ALIAS_PLAYLIST                 "p"
406 #define DB_TABLE_ALIAS_PLAYLIST_MAP     "pm"
407 #define DB_TABLE_ALIAS_TAG                              "t"
408 #define DB_TABLE_ALIAS_BOOKMARK         "b"
409 #define DB_TABLE_ALIAS_ALBUM                    "a"
410
411 /* DB field for media */
412 #define DB_FIELD_MEDIA_ID                                       "media_uuid"
413 #define DB_FIELD_MEDIA_PATH                             "path"
414 #define DB_FIELD_MEDIA_DISPLAY_NAME             "file_name"
415 #define DB_FIELD_MEDIA_TYPE                                     "media_type"
416 #define DB_FIELD_MEDIA_MIME_TYPE                        "mime_type"
417 #define DB_FIELD_MEDIA_SIZE                                     "size"
418 #define DB_FIELD_MEDIA_ADDED_TIME                       "added_time"
419 #define DB_FIELD_MEDIA_MODIFIED_TIME            "modified_time"
420 #define DB_FIELD_MEDIA_TIMELINE                         "timeline"
421 #define DB_FIELD_MEDIA_THUMBNAIL_PATH   "thumbnail_path"
422 #define DB_FIELD_MEDIA_TITLE                            "title"
423 #define DB_FIELD_MEDIA_ALBUM                            "album"
424 #define DB_FIELD_MEDIA_ARTIST                           "artist"
425 #define DB_FIELD_MEDIA_ALBUM_ARTIST                     "album_artist"
426 #define DB_FIELD_MEDIA_GENRE                            "genre"
427 #define DB_FIELD_MEDIA_COMPOSER                 "composer"
428 #define DB_FIELD_MEDIA_YEAR                             "year"
429 #define DB_FIELD_MEDIA_RECORDED_DATE            "recorded_date"
430 #define DB_FIELD_MEDIA_COPYRIGHT                        "copyright"
431 #define DB_FIELD_MEDIA_TRACK_NUM                        "track_num"
432 #define DB_FIELD_MEDIA_DESCRIPTION                      "description"
433 #define DB_FIELD_MEDIA_BITRATE                          "bitrate"
434 #define DB_FIELD_MEDIA_BITPERSAMPLE             "bitpersample"
435 #define DB_FIELD_MEDIA_SAMPLERATE                       "samplerate"
436 #define DB_FIELD_MEDIA_CHANNEL                  "channel"
437 #define DB_FIELD_MEDIA_DURATION                 "duration"
438 #define DB_FIELD_MEDIA_LONGITUDE                        "longitude"
439 #define DB_FIELD_MEDIA_LATITUDE                 "latitude"
440 #define DB_FIELD_MEDIA_ALTITUDE                 "altitude"
441 #define DB_FIELD_MEDIA_WIDTH                            "width"
442 #define DB_FIELD_MEDIA_HEIGHT                           "height"
443 #define DB_FIELD_MEDIA_DATETAKEN                        "datetaken"
444 #define DB_FIELD_MEDIA_ORIENTATION              "orientation"
445 #define DB_FIELD_MEDIA_BURST_ID                 "burst_id"
446 #define DB_FIELD_MEDIA_PLAYED_COUNT             "played_count"
447 #define DB_FIELD_MEDIA_LAST_PLAYED_TIME         "last_played_time"
448 #define DB_FIELD_MEDIA_LAST_PLAYED_POSITION     "last_played_position"
449 #define DB_FIELD_MEDIA_RATING                           "rating"
450 #define DB_FIELD_MEDIA_FAVOURITE                        "favourite"
451 #define DB_FIELD_MEDIA_AUTHOR                           "author"
452 #define DB_FIELD_MEDIA_PROVIDER                 "provider"
453 #define DB_FIELD_MEDIA_CONTENT_NAME             "content_name"
454 #define DB_FIELD_MEDIA_CATEGORY                 "category"
455 #define DB_FIELD_MEDIA_LOCATION_TAG             "location_tag"
456 #define DB_FIELD_MEDIA_AGE_RATING                       "age_rating"
457 #define DB_FIELD_MEDIA_KEYWORD                  "keyword"
458 #define DB_FIELD_MEDIA_WEATHER                  "weather"
459 #define DB_FIELD_MEDIA_IS_DRM                           "is_drm"
460 #define DB_FIELD_MEDIA_STORAGE_TYPE             "storage_type"
461 #define DB_FIELD_MEDIA_EXPOSURE_TIME    "exposure_time"
462 #define DB_FIELD_MEDIA_FNUMBER                  "fnumber"
463 #define DB_FIELD_MEDIA_ISO                              "iso"
464 #define DB_FIELD_MEDIA_MODEL                    "model"
465 #define DB_FIELD_MEDIA_FILE_NAME_PINYIN                 "file_name_pinyin"
466 #define DB_FIELD_MEDIA_TITLE_PINYIN                                     "title_pinyin"
467 #define DB_FIELD_MEDIA_ALBUM_PINYIN                             "album_pinyin"
468 #define DB_FIELD_MEDIA_ARTIST_PINYIN                            "artist_pinyin"
469 #define DB_FIELD_MEDIA_ALBUM_ARTIST_PINYIN              "album_artist_pinyin"
470 #define DB_FIELD_MEDIA_GENRE_PINYIN                             "genre_pinyin"
471 #define DB_FIELD_MEDIA_COMPOSER_PINYIN                  "composer_pinyin"
472 #define DB_FIELD_MEDIA_COPYRIGHT_PINYIN                 "copyright_pinyin"
473 #define DB_FIELD_MEDIA_DESCRIPTION_PINYIN                       "description_pinyin"
474 #define DB_FIELD_MEDIA_AUTHOR_PINYIN                            "author_pinyin"
475 #define DB_FIELD_MEDIA_PROVIDER_PINYIN                  "provider_pinyin"
476 #define DB_FIELD_MEDIA_CONTENT_NAME_PINYIN              "content_name_pinyin"
477 #define DB_FIELD_MEDIA_CATEGORY_PINYIN                  "category_pinyin"
478 #define DB_FIELD_MEDIA_LOCATION_TAG_PINYIN              "location_tag_pinyin"
479 #define DB_FIELD_MEDIA_AGE_RATING_PINYIN                        "age_rating_pinyin"
480 #define DB_FIELD_MEDIA_KEYWORD_PINYIN                           "keyword_pinyin"
481 #define DB_FIELD_MEDIA_360                                                      "is_360"
482
483 /* DB field for folder */
484 #define DB_FIELD_FOLDER_ID                              "folder_uuid"
485 #define DB_FIELD_FOLDER_PATH                    "path"
486 #define DB_FIELD_FOLDER_NAME                    "name"
487 #define DB_FIELD_FOLDER_MODIFIED_TIME   "modified_time"
488 #define DB_FIELD_FOLDER_STORAGE_TYPE    "storage_type"
489 #define DB_FIELD_FOLDER_NAME_PINYIN     "name_pinyin"
490 #define DB_FIELD_FOLDER_ORDER                   "folder_order"
491 #define DB_FIELD_FOLDER_PARENT_FOLDER_ID        "parent_folder_uuid"
492
493 /* DB field for playlist */
494 #define DB_FIELD_PLAYLIST_ID                                    "playlist_id"
495 #define DB_FIELD_PLAYLIST_NAME                          "name"
496 #define DB_FIELD_PLAYLIST_MEMBER_ORDER  "play_order"
497 #define DB_FIELD_PLAYLIST_MEDIA_COUNT                   "media_count"
498
499 /* DB field for tag */
500 #define DB_FIELD_TAG_ID                 "tag_id"
501 #define DB_FIELD_TAG_NAME               "name"
502 #define DB_FIELD_TAG_MEDIA_COUNT                        "media_count"
503
504 /* DB field for bookmark */
505 #define DB_FIELD_BOOKMARK_ID    "bookmark_id"
506 #define DB_FIELD_BOOKMARK_MARKED_TIME   "marked_time"
507
508 /* DB field for album*/
509 #define DB_FIELD_ALBUM_ID                       "album_id"
510 #define DB_FIELD_ALBUM_NAME             "name"
511 #define DB_FIELD_ALBUM_ARTIST           "artist"
512
513 /* DB field for Storage*/
514 #define DB_FIELD_STORAGE_ID                     "storage_uuid"
515 #define DB_FIELD_STORAGE_PATH           "storage_path"
516
517 /* DB field for Face */
518 #define DB_FIELD_FACE_TAG                       "face_tag"
519
520 /* DB Query Keyword */
521 #define QUERY_KEYWORD_AND "AND"
522 #define QUERY_KEYWORD_OR "OR"
523 #define QUERY_KEYWORD_ORDER_BY "ORDER BY"
524 #define QUERY_KEYWORD_LIMIT "limit"
525 #define QUERY_KEYWORD_DESC "DESC"
526 #define QUERY_KEYWORD_SPACE " "
527 #define QUERY_KEYWORD_OPEN_BRACKET "("
528 #define QUERY_KEYWORD_BRACKET ")"
529
530 /* DB TABLE JOIN */
531 /*#define FOLDER_MEDIA_JOIN                                     "("DB_TABLE_FOLDER" AS f LEFT OUTER JOIN '%s' AS m ON f.folder_uuid=m.folder_uuid AND m.validity=1) WHERE f.storage_uuid IN (SELECT storage_uuid FROM "DB_TABLE_STORAGE" WHERE validity=1) " */
532 #define FOLDER_MEDIA_JOIN                                       "("DB_TABLE_FOLDER" AS f LEFT OUTER JOIN '%s' AS m ON f.folder_uuid=m.folder_uuid AND m.validity=1) WHERE f.validity=1 "
533 #define BOOKMARK_MEDIA_JOIN                             "("DB_TABLE_BOOKMARK" AS b INNER JOIN '%s' AS m \
534                                                                                         ON (b.media_uuid = m.media_uuid)) WHERE m.validity=1"
535 #define ALBUM_MEDIA_JOIN                                        "("DB_TABLE_ALBUM" AS a INNER JOIN '%s' AS m \
536                                                                                         ON (a.album_id = m.album_id)) WHERE m.validity=1"
537 #define FACE_MEDIA_JOIN                                         "("DB_TABLE_FACE" AS fa INNER JOIN '%s' AS m \
538                                                                                                 ON (fa.media_uuid = m.media_uuid)) WHERE m.validity=1"
539
540 /* Get Group List */
541 #define SELECT_ALBUM_LIST                       "SELECT DISTINCT a.album_id, a.name, a.artist, a.album_art FROM "ALBUM_MEDIA_JOIN
542 #define SELECT_MEDIA_GROUP_LIST "SELECT DISTINCT %s FROM '%s' WHERE validity=1 "
543
544 #define SELECT_FOLDER_LIST                      "SELECT DISTINCT f.folder_uuid, f.path, f.name, f.storage_type, f.modified_time, f.storage_uuid, f.folder_order, f.parent_folder_uuid FROM "FOLDER_MEDIA_JOIN
545 #define SELECT_FOLDER_LIST_BY_STORAGE_ID        SELECT_FOLDER_LIST"AND f.storage_uuid='%s' "
546 #define SELECT_TAG_LIST                         "SELECT DISTINCT tag_id, name FROM "DB_VIEW_TAG" WHERE 1 "
547 #define SELECT_PLAYLIST_LIST                    "SELECT DISTINCT playlist_id, name, p_thumbnail_path FROM "DB_VIEW_PLAYLIST" WHERE 1 "
548
549 /* Get Group Count */
550 #define SELECT_ALBUM_COUNT              "SELECT COUNT(DISTINCT a.album_id) FROM "ALBUM_MEDIA_JOIN
551 #define SELECT_FOLDER_COUNT             "SELECT COUNT(DISTINCT f.folder_uuid) FROM "FOLDER_MEDIA_JOIN
552 #define SELECT_FOLDER_COUNT_BY_STORAGE_ID               SELECT_FOLDER_COUNT"AND f.storage_uuid='%s' "
553 #define SELECT_TAG_COUNT                        "SELECT COUNT(DISTINCT tag_id) FROM "DB_VIEW_TAG" WHERE 1 "
554 #define SELECT_PLAYLIST_COUNT           "SELECT COUNT(DISTINCT playlist_id) FROM "DB_VIEW_PLAYLIST" WHERE 1 "
555 #define SELECT_BOOKMARK_COUNT   "SELECT COUNT(DISTINCT b.bookmark_id) FROM "BOOKMARK_MEDIA_JOIN
556 #define SELECT_MEDIA_GROUP_COUNT        "SELECT COUNT(*) FROM ("SELECT_MEDIA_GROUP_LIST
557 /*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)*/
558
559 /* Get Media Count of Group */
560 #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" */
561 #define SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE    "SELECT COUNT(*) FROM '%s' WHERE validity=1 "
562 #define SELECT_MEDIA_COUNT_FROM_ALBUM                   "SELECT COUNT(*) FROM '%s' WHERE validity=1 AND album_id='%d'"
563 #define SELECT_MEDIA_COUNT_FROM_GROUP                   "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP         /*to apply limit condition. */
564 #define SELECT_MEDIA_COUNT_FROM_GROUP_NULL              "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP_NULL    /* to apply limit condition. */
565 #define SELECT_MEDIA_COUNT_FROM_FOLDER                  "SELECT COUNT(*) FROM '%s' WHERE validity=1 AND folder_uuid='%q'"
566 #define SELECT_MEDIA_COUNT_FROM_STORAGE                 "SELECT COUNT(*) FROM '%s' WHERE validity=1 AND storage_uuid='%q'"
567 #define SELECT_MEDIA_COUNT_FROM_TAG                             "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE (tag_id=%d AND media_count>0) "
568 #define SELECT_MEDIA_COUNT_FROM_PLAYLIST                        "SELECT COUNT(*) FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and media_count>0) "
569
570 /* Get Group Info by Group ID*/
571 #define SELECT_ALBUM_FROM_ALBUM         "SELECT * FROM "DB_TABLE_ALBUM" WHERE album_id=%d"
572 #define SELECT_FOLDER_FROM_FOLDER               "SELECT * FROM "DB_TABLE_FOLDER" WHERE folder_uuid='%s'"
573 #define SELECT_FOLDER_BY_PATH                   "SELECT * FROM "DB_TABLE_FOLDER" WHERE path='%q'"
574 #define SELECT_PLAYLIST_FROM_PLAYLIST   "SELECT * FROM "DB_TABLE_PLAYLIST" WHERE playlist_id=%d"
575 #define SELECT_TAG_FROM_TAG                     "SELECT * FROM "DB_TABLE_TAG" WHERE tag_id=%d"
576 #define SELECT_TAG_BY_NAME                              "SELECT * FROM "DB_TABLE_TAG" WHERE name='%q'"
577
578 /* Tag info*/
579 #define INSERT_TAG_TO_TAG                                               "INSERT INTO "DB_TABLE_TAG" (name) VALUES (%Q)"
580 #define REMOVE_TAG_ITEM_FROM_TAG_MAP            "DELETE FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d AND media_uuid='%q';"
581 #define UPDATE_TAG_NAME_FROM_TAG                        "UPDATE "DB_TABLE_TAG" SET name='%q' WHERE tag_id=%d;"
582 #define SELECT_TAG_COUNT_BY_MEDIA_ID                    "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE media_uuid = '%s'"
583 #define SELECT_TAG_LIST_BY_MEDIA_ID                             "SELECT tag_id, name FROM "DB_VIEW_TAG" WHERE media_uuid = '%s'"
584
585 /* Get Media list of Group */
586 #define MEDIA_INFO_ITEM "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, thumbnail_path, description, \
587                                                         rating, favourite, author, provider, content_name, category, location_tag, age_rating, keyword, is_drm, storage_type, longitude, latitude, altitude, exposure_time, fnumber, iso, model, width, height, datetaken, orientation, title, album, artist, album_artist, genre, composer, year, recorded_date, copyright, track_num, bitrate, bitpersample, duration, played_count, last_played_time, last_played_position, samplerate, channel, burst_id, timeline, weather, sync_status, storage_uuid, is_360"
588
589 /*Folder info*/
590 #define UPDATE_FOLDER_ORDER                                     "UPDATE "DB_TABLE_FOLDER" SET folder_order=%d WHERE folder_uuid=%Q"
591
592 /* Playlist Info */
593 #define INSERT_PLAYLIST_TO_PLAYLIST                                             "INSERT INTO "DB_TABLE_PLAYLIST" (name) VALUES (%Q)"
594 #define UPDATE_PLAYLIST_NAME_FROM_PLAYLIST                      "UPDATE "DB_TABLE_PLAYLIST" SET name='%q' WHERE playlist_id=%d;"
595 #define UPDATE_PLAYLIST_THUMBNAIL_FROM_PLAYLIST         "UPDATE "DB_TABLE_PLAYLIST" SET thumbnail_path='%q' WHERE playlist_id=%d;"
596 #define SELECT_PLAYLIST_ID_FROM_PLAYLIST                                "SELECT playlist_id FROM "DB_TABLE_PLAYLIST" WHERE name='%q'"
597 #define SELECT_PLAYLIST_ITEM_ID_FROM_PLAYLIST_VIEW      "SELECT pm_id, media_uuid FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and media_count>0) "
598 #define SELECT_PLAYLIST_ITEM_ALL_FROM_PLAYLIST_VIEW     "SELECT "MEDIA_INFO_ITEM", pm_id FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and media_count>0) "
599 #define SELECT_PLAY_ORDER_FROM_PLAYLIST_VIEW                    "SELECT play_order FROM "DB_VIEW_PLAYLIST" WHERE playlist_id=%d and pm_id=%d"
600 #define SELECT_MAX_PLAY_ORDER_FROM_PLAYLIST_VIEW        "SELECT MAX(play_order) FROM "DB_VIEW_PLAYLIST" WHERE playlist_id=%d"
601 #define REMOVE_PLAYLIST_ITEM_FROM_PLAYLIST_MAP          "DELETE FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d AND _id=%d;"
602 #define UPDATE_PLAYLIST_ORDER_FROM_PLAYLIST_MAP         "UPDATE "DB_TABLE_PLAYLIST_MAP" SET play_order=%d WHERE playlist_id=%d AND _id=%d;"
603
604 /* Bookmark */
605 #define INSERT_BOOKMARK_TO_BOOKMARK                     "INSERT INTO "DB_TABLE_BOOKMARK" (media_uuid, marked_time, thumbnail_path) VALUES ('%q', '%d', %Q)"
606 #define SELECT_BOOKMARK_COUNT_BY_MEDIA_ID               "SELECT COUNT(*) FROM "BOOKMARK_MEDIA_JOIN" AND b.media_uuid='%s'"
607 #define SELECT_BOOKMARK_LIST_BY_MEDIA_ID                        "SELECT b.bookmark_id, b.media_uuid, b.marked_time, b.thumbnail_path FROM "BOOKMARK_MEDIA_JOIN" AND b.media_uuid='%s'"
608
609 /* Update Meta*/
610 #define UPDATE_AV_META_FROM_MEDIA       "UPDATE '%s' SET played_count=%d, last_played_time=%d, last_played_position=%d WHERE media_uuid='%q'"
611 #define UPDATE_IMAGE_META_FROM_MEDIA    "UPDATE '%s' SET orientation=%d, weather=%Q WHERE media_uuid='%q'"
612
613 #define SELECT_MEDIA_ITEM                                       "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1"
614 #define SELECT_MEDIA_FROM_MEDIA                 "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND media_uuid='%s'"
615 #define SELECT_MEDIA_BY_PATH                            "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND path='%q'"
616 #define SELECT_MEDIA_FROM_ALBUM                 "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND album_id=%d"
617 #define SELECT_MEDIA_FROM_GROUP                 "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND %s='%q'"
618 #define SELECT_MEDIA_FROM_GROUP_NULL    "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND %s IS NULL"
619 #define SELECT_MEDIA_FROM_FOLDER                        "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND folder_uuid='%s'"
620 #define SELECT_MEDIA_FROM_STORAGE               "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND storage_uuid='%s'"
621 #define SELECT_MEDIA_FROM_TAG                           "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE media_uuid IN (SELECT media_uuid FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d) AND validity=1"
622 #define SELECT_MEDIA_FROM_PLAYLIST              "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE media_uuid IN (SELECT media_uuid FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d) AND validity=1"
623 #define SELECT_MEDIA_PATH_BY_ID                 "SELECT path FROM "DB_TABLE_MEDIA_VIEW" WHERE media_uuid='%q'"
624 #define SELECT_MEDIA_STORAGE_ID_BY_ID           "SELECT storage_uuid FROM "DB_TABLE_MEDIA_VIEW" WHERE media_uuid='%q'"
625
626 /* Delete */
627 #define DELETE_MEDIA_FROM_MEDIA_BATCH   "DELETE FROM  '%s' WHERE %s"
628 #define DELETE_PLAYLIST_FROM_PLAYLIST           "DELETE FROM "DB_TABLE_PLAYLIST" WHERE playlist_id=%d"
629 #define DELETE_TAG_FROM_TAG                             "DELETE FROM "DB_TABLE_TAG" WHERE tag_id=%d"
630 #define DELETE_BOOKMARK_FROM_BOOKMARK   "DELETE FROM "DB_TABLE_BOOKMARK" WHERE bookmark_id=%d"
631
632 /* Storage*/
633 #define SELECT_STORAGE_COUNT                            "SELECT COUNT(*) FROM "DB_TABLE_STORAGE" WHERE validity=1"
634 #define SELECT_STORAGE_LIST                                     "SELECT * FROM "DB_TABLE_STORAGE" WHERE validity=1"
635 #define SELECT_STORAGE_INFO_FROM_STORAGE        "SELECT * FROM "DB_TABLE_STORAGE" WHERE validity=1 AND storage_uuid='%s'"
636
637 /* Face */
638 #define DELETE_FACE_FROM_FACE                   "DELETE FROM "DB_TABLE_FACE" WHERE face_uuid='%q'"
639 #define INSERT_FACE_TO_FACE                             "INSERT INTO "DB_TABLE_FACE" (face_uuid, media_uuid, face_rect_x , face_rect_y, face_rect_w, face_rect_h, orientation, face_tag) VALUES ('%q', '%q', %d, %d, %d, %d, %d, %Q);"
640 #define UPDATE_FACE_TO_FACE                     "UPDATE "DB_TABLE_FACE" SET face_rect_x=%d, face_rect_y=%d, face_rect_w=%d, face_rect_h=%d, orientation=%d, face_tag=%Q WHERE face_uuid='%q'"
641 #define SELECT_MEDIA_COUNT_FROM_MEDIA_BY_ID             "SELECT COUNT(*) FROM "DB_TABLE_MEDIA_VIEW" WHERE media_uuid='%q' AND validity=1"
642 #define SELECT_FACE_COUNT_BY_MEDIA_ID           "SELECT COUNT(*) FROM "FACE_MEDIA_JOIN" AND fa.media_uuid='%s'"
643 #define SELECT_FACE_LIST_BY_MEDIA_ID            "SELECT fa.face_uuid, fa.media_uuid, fa.face_rect_x, fa.face_rect_y, fa.face_rect_w, fa.face_rect_h, fa.orientation, fa.face_tag FROM "FACE_MEDIA_JOIN" AND fa.media_uuid='%s'"
644
645 #define DEFAULT_MEDIA_STORAGE_ID                        "media"
646
647 int _content_query_prepare(sqlite3_stmt **stmt, char *select_query, char *condition_query, char *option_query);
648 int _content_error_capi(int type, int cotent_error);
649 int _content_query_sql(char *query_str);
650 MediaSvcHandle* _content_get_db_handle(void);
651 attribute_h _content_get_attirbute_handle(void);
652 attribute_h _content_get_alias_attirbute_handle(void);
653 int _media_info_get_media_info_from_db(const char *path, const char *storage_id, media_info_h media);
654 void _media_info_item_get_detail(sqlite3_stmt *stmt, media_info_h media);
655 int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count);
656 int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *group_count);
657 int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_cb callback, void *user_data);
658 int _media_db_get_album(filter_h filter, media_album_cb callback, void *user_data);
659 int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_data);
660 int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *user_data);
661 int _media_db_get_playlist_item(int playlist_id, filter_h filter, playlist_member_cb callback, void *user_data);
662 int _media_db_get_tag(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data);
663 int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data);
664 int _media_db_get_face(const char *media_id, filter_h filter, media_face_cb callback, void *user_data);
665 int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_list_e group_type, int *item_count);
666 int _media_db_get_group_item_count(const char *group_name, filter_h filter, group_list_e group_type, int *item_count);
667 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);
668 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);
669 int _media_db_get_media_group_item_count(const char *group_name, filter_h filter, media_group_e group, int *item_count);
670 int _media_db_get_media_group_item(const char *group_name, filter_h filter, media_group_e group, media_info_cb callback, void *user_data);
671 int _media_db_get_storage(filter_h filter, media_storage_cb callback, void *user_data);
672 int _media_db_get_storage_id_by_media_id(const char *media_id, char *storage_id);
673
674 /**
675  * @internal
676  * @brief Creates a media filter attribute handle.
677  * @details This function creates a media filter attribute handle. The handle can be
678  * used to convert to attributes of database from attributes of user.
679  * @remarks The @a handle must be released with media_filter_attribute_destory() by you.
680  * @param[out] filter A handle to media filter attribute
681  * @return 0 on success, otherwise a negative error value.
682  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
683  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
684  * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory
685  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
686  * @see media_filter_attribute_destory()
687  *
688  */
689 int _media_filter_attribute_create(attribute_h *attr);
690
691 /**
692  * @internal
693  * @brief Add the attributes to the handle.
694  * @details This function add the attribute to handle.
695  * @param[in] filter The handle to media filter attribute
696  * @param[in] user_attr The user attribute
697  * @param[in] platform_attr The platform attribute
698  * @return 0 on success, otherwise a negative error value.
699  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
700  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
701  * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory
702  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
703  * @see media_filter_attribute_remove()
704  *
705  */
706 int _media_filter_attribute_add(attribute_h atrr, const char *user_attr, const char *platform_attr);
707
708 /**
709  * @internal
710  * @brief Destroys a media filter attribute handle.
711  * @details The function frees all resources related to the media filter attribute handle. The filter attribute
712  * handle no longer can be used to perform any operation. A new handle
713  * has to be created before the next usage.
714  *
715  * @param[in] filter The handle to media filter attribute
716  * @return 0 on success, otherwise a negative error value.
717  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
718  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
719  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
720  * @see media_filter_create()
721  *
722  */
723 int _media_filter_attribute_destory(attribute_h attr);
724
725 /**
726  * @internal
727  * @brief Replace to platform attributes from user attributes.
728  * @details This function replace to platform attributes from user attributes to generate the WHERE clause
729  * @param[in] filter The handle to media filter attribute
730  * @param[in] user_attr The user attribute
731  * @param[in] platform_attr The platform attribute
732  * @return 0 on success, otherwise a negative error value.
733  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
734  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
735  * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory
736  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
737  * @see media_filter_attribute_create()
738  * @see media_filter_attribute_destory()
739  *
740  */
741 int _media_filter_attribute_generate(attribute_h attr, char *condition, media_content_collation_e collate_type, char **generated_condition);
742
743
744 /**
745  * @internal
746  * @brief Replace to platform attributes from user attributes.
747  * @details This function replace to platform attributes from user attributes to generate the WHERE clause
748  * @param[in] filter The handle to media filter attribute
749  * @param[in] attr The attribute
750  * @param[in] generated_option The handle to generated option
751  * @return 0 on success, otherwise a negative error value.
752  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
753  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
754  * @retval #MEDIA_CONTENT_ERROR_DB_FAILED Filed DB
755  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
756  * @see media_filter_attribute_create()
757  * @see media_filter_attribute_destory()
758  *
759  */
760
761 int _media_filter_attribute_option_generate(attribute_h attr, filter_h filter, char **generated_option);
762
763 #define FONT_COLOR_RESET    "\033[0m"
764 #define FONT_COLOR_RED      "\033[31m"
765 #define FONT_COLOR_GREEN    "\033[32m"
766 #define FONT_COLOR_YELLOW   "\033[33m"
767 #define FONT_COLOR_BLUE     "\033[34m"
768 #define FONT_COLOR_PURPLE   "\033[35m"
769 #define FONT_COLOR_CYAN     "\033[36m"
770 #define FONT_COLOR_GRAY     "\033[37m"
771
772 #define media_content_gettid() syscall(__NR_gettid)
773
774 #define media_content_retv_if(expr, val) do { \
775                         if (expr) { \
776                                 LOGE(FONT_COLOR_RED"[%d]", media_content_gettid());    \
777                                 return (val); \
778                         } \
779                 } while (0)
780
781 #define media_content_retvm_if(expr, val, fmt, arg...) do { \
782                         if (expr) { \
783                                 LOGE(FONT_COLOR_RED"[%d]"fmt"", media_content_gettid(), ##arg);     \
784                                 return (val); \
785                         } \
786                 } while (0)
787
788 #define media_content_debug(fmt, arg...) do { \
789                         LOGD(FONT_COLOR_RESET"[%d]"fmt"", media_content_gettid(), ##arg);     \
790                 } while (0)
791
792 #define media_content_info(fmt, arg...) do { \
793                         LOGI(FONT_COLOR_GREEN"[%d]"fmt"", media_content_gettid(), ##arg);     \
794                 } while (0)
795
796 #define media_content_error(fmt, arg...) do { \
797                         LOGE(FONT_COLOR_RED"[%d]"fmt"", media_content_gettid(), ##arg);     \
798                 } while (0)
799
800 #define media_content_debug_func() do { \
801                         LOGD(FONT_COLOR_RESET"[%d]", media_content_gettid());     \
802                 } while (0)
803
804 #define media_content_sec_debug(fmt, arg...) do { \
805                         SECURE_LOGD(FONT_COLOR_RESET"[%d]"fmt"", media_content_gettid(), ##arg);     \
806                 } while (0)
807
808 #define media_content_sec_warn(fmt, arg...) do { \
809                         SECURE_LOGW(FONT_COLOR_GREEN"[%d]"fmt"", media_content_gettid(), ##arg);     \
810                 } while (0)
811
812 #define media_content_sec_error(fmt, arg...) do { \
813                         SECURE_LOGE(FONT_COLOR_RED"[%d]"fmt"", media_content_gettid(), ##arg);     \
814                 } while (0)
815
816 #define ERR_BUF_LENGTH 256
817 #define media_content_stderror(fmt) do { \
818                         char media_content_stderror_buf[ERR_BUF_LENGTH] = {0, }; \
819                         strerror_r(errno, media_content_stderror_buf, ERR_BUF_LENGTH);  \
820                         LOGE(FONT_COLOR_RED fmt" : STANDARD ERROR [%s]", media_content_stderror_buf); \
821                 } while (0)
822
823 #ifdef __cplusplus
824 }
825 #endif /* __cplusplus */
826 #endif /*__TIZEN_MEDIA_INFO_PRIVATE_H__*/