b89764a82548cbbee805e890a56753cdc7b69f92
[platform/core/api/media-content.git] / include_product / 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 #ifdef _USE_TV_PROFILE
36 #include <media_content_type_product.h>
37 #endif
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif /* __cplusplus */
42
43 #ifdef LOG_TAG
44 #undef LOG_TAG
45 #endif
46
47
48 /**
49  * @addtogroup CAPI_CONTENT_MEDIA_INFO_MODULE
50 * @{
51 *
52 * @file media_info_private.h
53 * @brief This file contains the media info API and related structure and enumeration. \n
54 *        Description of the audio, video,image content involves: album, artist, album_artist, author, genre and description tags. \n
55 *        Parameters of the recording are also supported, as: format, bitrate, duration, size etc. \n
56 *        Defenitions of media DB fields and tables, operations with media data relating to DB and handling with media filter attributes.
57 */
58
59
60 #define LOG_TAG "CAPI_CONTENT_MEDIA_CONTENT"
61
62 #define SAFE_STRLCPY(dst, src, n)       ((g_strlcpy(dst, src, n) < n) ? TRUE : FALSE)
63 #define SAFE_STRLCAT(dst, src, n)       g_strlcat(dst, src, n);
64 #define SAFE_FREE(src)          {if (src) {free(src); src = NULL; } }
65 #define SAFE_G_FREE(src)        {if (src) {g_free(src); src = NULL; } }
66 #define STRING_VALID(str)               ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
67 #define SQLITE3_FINALIZE(x)     {if (x != NULL) sqlite3_finalize(x); }
68 #define SQLITE3_SAFE_FREE(x)    {if (x != NULL) {sqlite3_free(x); x = NULL; } }
69
70 #define MEDIA_CONTENT_INSERT_FILES_PATH         "/tmp"
71 #define MEDIA_CONTENT_EMPTY_STRING                      ""
72
73 #define MAX_QUERY_SIZE 4096
74 #define MAX_PATH_LEN 4096
75 #define DEFAULT_QUERY_SIZE 1024
76 #define COLLATE_STR_SIZE 32
77 #define MEDIA_CONTENT_UUID_SIZE 36
78 #define BATCH_REQUEST_MAX 300
79
80 #define EMPTY_STR ""
81
82 typedef enum {
83         MEDIA_INFO_UUID = 0,
84         MEDIA_INFO_PATH,
85         MEDIA_INFO_FILE_NAME,
86         MEDIA_INFO_TYPE,
87         MEDIA_INFO_MIME_TYPE,
88         MEDIA_INFO_SIZE,
89         MEDIA_INFO_ADDED_TIME,
90         MEDIA_INFO_MODIFIED_TIME,
91         MEDIA_INFO_THUMBNAIL_PATH,
92         MEDIA_INFO_DESCRIPTION,
93         MEDIA_INFO_RATING,
94         MEDIA_INFO_FAVOURITE,
95         MEDIA_INFO_AUTHOR,
96         MEDIA_INFO_PROVIDER,
97         MEDIA_INFO_CONTENT_NAME,
98         MEDIA_INFO_CATEGORY,
99         MEDIA_INFO_LOCATION_TAG,
100         MEDIA_INFO_AGE_RATING,
101         MEDIA_INFO_KEYWORD,
102         MEDIA_INFO_IS_DRM,
103         MEDIA_INFO_STORAGE_TYPE,
104         MEDIA_INFO_LONGITUDE,
105         MEDIA_INFO_LATITUDE,
106         MEDIA_INFO_ALTITUDE,
107         MEDIA_INFO_EXPOSURE_TIME,
108         MEDIA_INFO_FNUMBER,
109         MEDIA_INFO_ISO,
110         MEDIA_INFO_MODEL,
111         MEDIA_INFO_WIDTH,
112         MEDIA_INFO_HEIGHT,
113         MEDIA_INFO_DATETAKEN,
114         MEDIA_INFO_ORIENTATION,
115         MEDIA_INFO_TITLE,
116         MEDIA_INFO_ALBUM,
117         MEDIA_INFO_ARTIST,
118         MEDIA_INFO_ALBUM_ARTIST,
119         MEDIA_INFO_GENRE,
120         MEDIA_INFO_COMPOSER,
121         MEDIA_INFO_YEAR,
122         MEDIA_INFO_RECORDED_DATE,
123         MEDIA_INFO_COPYRIGHT,
124         MEDIA_INFO_TRACK_NUM,
125         MEDIA_INFO_BITRATE,
126         MEDIA_INFO_BITPERSAMPLE,
127         MEDIA_INFO_DURATION,
128         MEDIA_INFO_PLAYED_COUNT,
129         MEDIA_INFO_LAST_PLAYED_TIME,
130         MEDIA_INFO_LAST_PLAYED_POSITION,
131         MEDIA_INFO_SAMPLERATE,
132         MEDIA_INFO_CHANNEL,
133         MEDIA_INFO_BURST_ID,
134         MEDIA_INFO_TIMELINE,
135         MEDIA_INFO_WEATHER,
136         MEDIA_INFO_SYNC_STATUS,
137         MEDIA_INFO_STORAGE_UUID,
138         MEDIA_INFO_IS_360,
139         MEDIA_INFO_STITCHED_INFO,
140         MEDIA_INFO_EXTRACT_FLAG,
141         MEDIA_INFO_MODIFIED_MONTH,
142 #ifdef _USE_SENIOR_MODE
143         MEDIA_INFO_CONTACT,
144         MEDIA_INFO_APP_DATA,
145 #endif
146         MEDIA_INFO_ITEM_MAX,
147 } media_info_item_e;
148
149 typedef enum {
150         MEDIA_CONTENT_TYPE = 0,
151         MEDIA_THUMBNAIL_TYPE,
152         MEDIA_REGISTER_TYPE
153 } media_info_error_type_e;
154
155 typedef enum {
156         MEDIA_TAG_ADD,
157         MEDIA_TAG_REMOVE,
158         MEDIA_TAG_UPDATE_TAG_NAME,
159 } tag_function_e;
160
161 typedef enum {
162         MEDIA_PLAYLIST_ADD,
163         MEDIA_PLAYLIST_REMOVE,
164         MEDIA_PLAYLIST_UPDATE_PLAYLIST_NAME,
165         MEDIA_PLAYLIST_UPDATE_THUMBNAIL_PATH,
166         MEDIA_PLAYLIST_UPDATE_PLAY_ORDER,
167 } playlist_function_e;
168
169 typedef enum {
170         MEDIA_GROUP_NONE,
171         MEDIA_GROUP_ALBUM,
172         MEDIA_GROUP_FOLDER,
173         MEDIA_GROUP_PLAYLIST,
174         MEDIA_GROUP_TAG,
175         MEDIA_GROUP_BOOKMARK,
176         MEDIA_GROUP_TAG_BY_MEDIA_ID,
177         MEDIA_GROUP_BOOKMARK_BY_MEDIA_ID,
178         MEDIA_GROUP_STORAGE,
179         MEDIA_GROUP_FACE,
180         MEDIA_GROUP_FACE_BY_MEDIA_ID,
181         MEDIA_GROUP_PVR,
182         MEDIA_GROUP_UHD,
183 } group_list_e;
184
185 typedef enum {
186         MEDIA_BATCH_INSERT_NORMAL,
187         MEDIA_BATCH_INSERT_BURSTSHOT,
188 } media_batch_insert_e;
189
190 typedef struct _filter_s {
191         char *storage_id;
192         char *condition;
193         char *order_keyword;
194         media_content_order_e order_type;
195         media_content_collation_e condition_collate_type;
196         media_content_collation_e order_collate_type;
197         int offset;
198         int count;
199         bool is_full_condition;
200         bool is_full_order;
201 } filter_s;
202
203 typedef struct {
204         char *folder_id;
205         char *path;
206         char *name;
207         time_t modified_time;
208         media_content_storage_e storage_type;
209         char *storage_uuid;
210         int folder_order;
211 } media_folder_s;
212
213 typedef struct {
214         int tag_id;
215         char *name;
216         GList *item_list;
217 } media_tag_s;
218
219 typedef struct {
220         int bookmark_id;
221         char *media_id;
222         time_t marked_time;
223         char *thumbnail_path;
224         char *name;
225 } media_bookmark_s;
226
227 typedef struct {
228         int album_id;
229         char *name;
230         char *artist;
231         char *album_art_path;
232 } media_album_s;
233
234 typedef struct {
235         int playlist_id;
236         char *name;
237         char *thumbnail_path;
238         GList *item_list;
239 } media_playlist_s;
240
241 typedef struct {
242         char *media_id;
243         int width;
244         int height;
245         char *date_taken;
246         char *title;
247         char *burst_id;
248         char *weather;
249         char *exposure_time;
250         double fnumber;
251         int iso;
252         char *model;
253         media_content_orientation_e orientation;
254 } image_meta_s;
255
256 typedef struct _image_mm_meta_s {
257         int width;
258         int height;
259 } image_mm_meta_s;
260
261 typedef struct {
262         char *media_id;
263         char *title;
264         char *album;
265         char *artist;
266         char *album_artist;
267         char *genre;
268         char *composer;
269         char *year;
270         char *recorded_date;
271         char *copyright;
272         char *track_num;
273         int bitrate;
274         int duration;
275         int width;
276         int height;
277         int played_count;
278         int rotation;
279         time_t played_time;
280         int played_position;
281 } video_meta_s;
282
283 typedef struct {
284         char *media_id;
285         char *title;
286         char *album;
287         char *artist;
288         char *album_artist;
289         char *genre;
290         char *composer;
291         char *year;
292         char *recorded_date;
293         char *copyright;
294         char *track_num;
295         int bitrate;
296         int bitpersample;
297         int samplerate;
298         int channel;
299         int duration;
300         int played_count;
301         time_t played_time;
302         int played_position;
303 } audio_meta_s;
304
305 typedef struct {
306         char *media_id;
307         char *file_path;
308         char *display_name;
309         media_content_type_e media_type;
310         char *mime_type;
311         unsigned long long size;
312         time_t added_time;
313         time_t modified_time;
314         time_t timeline;
315         char *thumbnail_path;
316         char *description;
317         double longitude;
318         double latitude;
319         double altitude;
320         char *weather;
321         int rating;
322         time_t favourite;
323         char *title;
324         char *author;
325         char *provider;
326         char *content_name;
327         char *category;
328         char *location_tag;
329         char *age_rating;
330         char *keyword;
331         int is_drm;
332         int storage_type;
333         int played_count;
334         time_t played_time;
335         int played_position;
336         char *modified_month;
337         char *storage_uuid;
338         int sync_status;
339         unsigned int request_id;
340         unsigned int face_request_id;
341         int is_360;
342         int stitched_info;
343         int extract_flag;
344 #ifdef _USE_SENIOR_MODE
345         char* contact;
346         char* app_data;
347 #endif
348         image_meta_s *image_meta;
349         video_meta_s *video_meta;
350         audio_meta_s *audio_meta;
351 } media_info_s;
352
353 typedef struct {
354         char *media_id;
355         int function;
356         char *tag_name;
357 } media_tag_item_s;
358
359 typedef struct {
360         char *media_id;
361         int function;
362         char *playlist_name;
363         char *thumbnail_path;
364         int playlist_member_id;
365         int play_order;
366 } media_playlist_item_s;
367
368 typedef struct {
369         char *storage_id;
370         char *storage_name;
371         char *storage_path;
372         int storage_type;
373 } media_storage_s;
374
375 typedef struct {
376         char *face_id;                          /* face uuid */
377         char *media_id;                 /* media uuid */
378         unsigned int face_rect_x;       /* x position of face */
379         unsigned int face_rect_y;       /* y position of face */
380         unsigned int face_rect_w;       /* width of face */
381         unsigned int face_rect_h;       /* height of face */
382         int orientation;                        /* orientation */
383         char *face_tag;                 /* face tag */
384 } media_face_s;
385
386 typedef struct {
387         char *media_id;
388         char *storage_id;
389         char *path;
390         unsigned long long size;
391         int duration;
392         int timezone;
393         int ptc;
394         int major;
395         int minor;
396         int channel_type;
397         char *channel_name;
398         char *channel_num;
399         char *program_title;
400         int program_num;
401         char *program_crid;
402         char *guidance;
403         char *synopsis;
404         char *genre;
405         char *language;
406         int embargo_time;
407         int expiry_time;
408         int start_time;
409         int program_start_time;
410         int program_end_time;
411         int program_date;
412         int parental_rating;
413         int timer_record;
414         int series_record;
415         int hd;
416         int subtitle;
417         int ttx;
418         int ad;
419         int hard_of_hearing_radio;
420         int data_service;
421         int content_lock;
422         int content_watch;
423         int has_audio_only;
424         int is_local_record;
425         int resolution;
426         int aspectratio;
427         char* modified_month;
428         int sports_type;
429         int guidance_length;
430         int tvmode;
431         int play_count;
432         int highlight;
433         char* private_data;
434 } media_pvr_s;
435
436 typedef struct {
437         char *media_id;
438         char *storage_id;
439         char *path;
440         unsigned long long size;
441         char *content_id;
442         char *content_title;
443         char *file_name;
444         char* release_date;
445         time_t modified_time;
446         int played_position;
447         int sub_type;
448         int played_count;
449 } media_uhd_s;
450
451 typedef struct _attribute_map_s {
452         GHashTable *attr_map;
453 } attribute_s;
454
455 typedef struct {
456         media_info_s *handle;
457         void *user_data;
458         media_thumbnail_completed_cb thumbnail_completed_cb;
459 } media_thumbnail_cb_s;
460
461 typedef struct {
462         media_info_s *handle;
463         void *user_data;
464         media_face_detection_completed_cb face_completed_cb;
465 } media_face_cb_s;
466
467 typedef struct {
468         media_insert_completed_cb insert_completed_cb;
469         char *insert_list_path;
470         void *user_data;
471 } media_insert_cb_s;
472
473 typedef struct {
474         media_content_db_update_cb update_noti_cb;
475         void *user_data;
476 } media_noti_cb_s;
477
478 typedef struct attribute_s *attribute_h;
479
480
481 typedef struct _media_content_cb_data {
482         media_scan_completed_cb callback;
483         void *user_data;
484 } media_content_scan_cb_data;
485
486 typedef struct _media_content_scan_cb_data_v2 {
487         media_scan_completed_cb_v2 callback;
488         void *user_data;
489 } media_content_scan_cb_data_v2;
490
491 /* DB Table */
492 #define DB_TABLE_MEDIA                  "media"
493 #define DB_TABLE_FOLDER         "folder"
494 #define DB_TABLE_ALBUM                  "album"
495 #define DB_TABLE_TAG                    "tag"
496 #define DB_TABLE_TAG_MAP                "tag_map"
497 #define DB_TABLE_PLAYLIST               "playlist"
498 #define DB_TABLE_PLAYLIST_MAP   "playlist_map"
499 #define DB_TABLE_BOOKMARK               "bookmark"
500 #define DB_TABLE_STORAGE                "storage"
501 #define DB_TABLE_MEDIA_VIEW     "media_view"
502 #define DB_TABLE_FACE                   "face"
503 #define DB_TABLE_FACE_SCAN_LIST "face_scan_list"
504 #define DB_TABLE_PVR                            "pvr"
505 #define DB_TABLE_UHD                                            "uhd"
506
507 /* DB View */
508 #define DB_VIEW_PLAYLIST        "playlist_view"
509 #define DB_VIEW_TAG                     "tag_view"
510
511 /* DB Table Alias */
512 #define DB_TABLE_ALIAS_MEDIA                    "m"
513 #define DB_TABLE_ALIAS_FOLDER                   "f"
514 #define DB_TABLE_ALIAS_PLAYLIST                 "p"
515 #define DB_TABLE_ALIAS_PLAYLIST_MAP     "pm"
516 #define DB_TABLE_ALIAS_TAG                              "t"
517 #define DB_TABLE_ALIAS_BOOKMARK         "b"
518 #define DB_TABLE_ALIAS_ALBUM                    "a"
519 #define DB_TABLE_ALIAS_FACE                             "fa"
520
521 /* DB field for media */
522 #define DB_FIELD_MEDIA_ID                                       "media_uuid"
523 #define DB_FIELD_MEDIA_PATH                             "path"
524 #define DB_FIELD_MEDIA_DISPLAY_NAME             "file_name"
525 #define DB_FIELD_MEDIA_TYPE                                     "media_type"
526 #define DB_FIELD_MEDIA_MIME_TYPE                        "mime_type"
527 #define DB_FIELD_MEDIA_SIZE                                     "size"
528 #define DB_FIELD_MEDIA_ADDED_TIME                       "added_time"
529 #define DB_FIELD_MEDIA_MODIFIED_TIME            "modified_time"
530 #define DB_FIELD_MEDIA_FOLDER_ID                        "folder_uuid"
531 #define DB_FIELD_MEDIA_TIMELINE                         "timeline"
532 #define DB_FIELD_MEDIA_THUMBNAIL_PATH   "thumbnail_path"
533 #define DB_FIELD_MEDIA_TITLE                            "title"
534 #define DB_FIELD_MEDIA_ALBUM                            "album"
535 #define DB_FIELD_MEDIA_ARTIST                           "artist"
536 #define DB_FIELD_MEDIA_ALBUM_ARTIST                     "album_artist"
537 #define DB_FIELD_MEDIA_GENRE                            "genre"
538 #define DB_FIELD_MEDIA_COMPOSER                 "composer"
539 #define DB_FIELD_MEDIA_YEAR                             "year"
540 #define DB_FIELD_MEDIA_RECORDED_DATE            "recorded_date"
541 #define DB_FIELD_MEDIA_COPYRIGHT                        "copyright"
542 #define DB_FIELD_MEDIA_TRACK_NUM                        "track_num"
543 #define DB_FIELD_MEDIA_DESCRIPTION                      "description"
544 #define DB_FIELD_MEDIA_BITRATE                          "bitrate"
545 #define DB_FIELD_MEDIA_BITPERSAMPLE             "bitpersample"
546 #define DB_FIELD_MEDIA_SAMPLERATE                       "samplerate"
547 #define DB_FIELD_MEDIA_CHANNEL                  "channel"
548 #define DB_FIELD_MEDIA_DURATION                 "duration"
549 #define DB_FIELD_MEDIA_LONGITUDE                        "longitude"
550 #define DB_FIELD_MEDIA_LATITUDE                 "latitude"
551 #define DB_FIELD_MEDIA_ALTITUDE                 "altitude"
552 #define DB_FIELD_MEDIA_WIDTH                            "width"
553 #define DB_FIELD_MEDIA_HEIGHT                           "height"
554 #define DB_FIELD_MEDIA_DATETAKEN                        "datetaken"
555 #define DB_FIELD_MEDIA_ORIENTATION              "orientation"
556 #define DB_FIELD_MEDIA_BURST_ID                 "burst_id"
557 #define DB_FIELD_MEDIA_PLAYED_COUNT             "played_count"
558 #define DB_FIELD_MEDIA_LAST_PLAYED_TIME         "last_played_time"
559 #define DB_FIELD_MEDIA_LAST_PLAYED_POSITION     "last_played_position"
560 #define DB_FIELD_MEDIA_RATING                           "rating"
561 #define DB_FIELD_MEDIA_FAVOURITE                        "favourite"
562 #define DB_FIELD_MEDIA_AUTHOR                           "author"
563 #define DB_FIELD_MEDIA_PROVIDER                 "provider"
564 #define DB_FIELD_MEDIA_CONTENT_NAME             "content_name"
565 #define DB_FIELD_MEDIA_CATEGORY                 "category"
566 #define DB_FIELD_MEDIA_LOCATION_TAG             "location_tag"
567 #define DB_FIELD_MEDIA_AGE_RATING                       "age_rating"
568 #define DB_FIELD_MEDIA_KEYWORD                  "keyword"
569 #define DB_FIELD_MEDIA_WEATHER                  "weather"
570 #define DB_FIELD_MEDIA_IS_DRM                           "is_drm"
571 #define DB_FIELD_MEDIA_STORAGE_TYPE             "storage_type"
572 #define DB_FIELD_MEDIA_MODIFIED_MONTH   "modified_month"
573 #define DB_FIELD_MEDIA_MODIFIED_DATE    "modified_date"
574 #define DB_FIELD_MEDIA_EXPOSURE_TIME    "exposure_time"
575 #define DB_FIELD_MEDIA_FNUMBER                  "fnumber"
576 #define DB_FIELD_MEDIA_ISO                              "iso"
577 #define DB_FIELD_MEDIA_MODEL                    "model"
578 #define DB_FIELD_MEDIA_FILE_NAME_PINYIN                 "file_name_pinyin"
579 #define DB_FIELD_MEDIA_TITLE_PINYIN                                     "title_pinyin"
580 #define DB_FIELD_MEDIA_ALBUM_PINYIN                             "album_pinyin"
581 #define DB_FIELD_MEDIA_ARTIST_PINYIN                            "artist_pinyin"
582 #define DB_FIELD_MEDIA_ALBUM_ARTIST_PINYIN              "album_artist_pinyin"
583 #define DB_FIELD_MEDIA_GENRE_PINYIN                             "genre_pinyin"
584 #define DB_FIELD_MEDIA_COMPOSER_PINYIN                  "composer_pinyin"
585 #define DB_FIELD_MEDIA_COPYRIGHT_PINYIN                 "copyright_pinyin"
586 #define DB_FIELD_MEDIA_DESCRIPTION_PINYIN                       "description_pinyin"
587 #define DB_FIELD_MEDIA_AUTHOR_PINYIN                            "author_pinyin"
588 #define DB_FIELD_MEDIA_PROVIDER_PINYIN                  "provider_pinyin"
589 #define DB_FIELD_MEDIA_CONTENT_NAME_PINYIN              "content_name_pinyin"
590 #define DB_FIELD_MEDIA_CATEGORY_PINYIN                  "category_pinyin"
591 #define DB_FIELD_MEDIA_LOCATION_TAG_PINYIN              "location_tag_pinyin"
592 #define DB_FIELD_MEDIA_AGE_RATING_PINYIN                        "age_rating_pinyin"
593 #define DB_FIELD_MEDIA_KEYWORD_PINYIN                           "keyword_pinyin"
594 #define DB_FIELD_MEDIA_360                                                      "is_360"
595 #define DB_FIELD_MEDIA_STITCHED_INFO                            "stitched_info"
596 #ifdef _USE_SENIOR_MODE
597 #define DB_FIELD_MEDIA_CONTACT                  "contact"
598 #define DB_FIELD_MEDIA_APP_DATA                 "app_data"
599 #endif
600
601 /* DB field for folder */
602 #define DB_FIELD_FOLDER_ID                              "folder_uuid"
603 #define DB_FIELD_FOLDER_PATH                    "path"
604 #define DB_FIELD_FOLDER_NAME                    "name"
605 #define DB_FIELD_FOLDER_MODIFIED_TIME   "modified_time"
606 #define DB_FIELD_FOLDER_STORAGE_TYPE    "storage_type"
607 #define DB_FIELD_FOLDER_NAME_PINYIN     "name_pinyin"
608 #define DB_FIELD_FOLDER_ORDER                   "folder_order"
609
610 /* DB field for playlist */
611 #define DB_FIELD_PLAYLIST_ID                                    "playlist_id"
612 #define DB_FIELD_PLAYLIST_NAME                          "name"
613 #define DB_FIELD_PLAYLIST_MEMBER_ORDER  "play_order"
614 #define DB_FIELD_PLAYLIST_MEDIA_COUNT                   "media_count"
615
616 /* DB field for tag */
617 #define DB_FIELD_TAG_ID                 "tag_id"
618 #define DB_FIELD_TAG_NAME               "name"
619 #define DB_FIELD_TAG_MEDIA_COUNT                        "media_count"
620
621 /* DB field for bookmark */
622 #define DB_FIELD_BOOKMARK_ID    "bookmark_id"
623 #define DB_FIELD_BOOKMARK_MARKED_TIME   "marked_time"
624 #define DB_FIELD_BOOKMARK_NAME  "name"
625
626 /* DB field for album*/
627 #define DB_FIELD_ALBUM_ID                       "album_id"
628 #define DB_FIELD_ALBUM_NAME             "name"
629 #define DB_FIELD_ALBUM_ARTIST           "artist"
630
631 /* DB field for Storage*/
632 #define DB_FIELD_STORAGE_ID                     "storage_uuid"
633 #define DB_FIELD_STORAGE_PATH           "storage_path"
634
635 /* DB field for Face */
636 #define DB_FIELD_FACE_ID                                "face_uuid"
637 #define DB_FIELD_FACE_TAG                       "face_tag"
638
639 /* DB field for PVR*/
640 #define DB_FIELD_PVR_DURATION                                   "duration"
641 #define DB_FIELD_PVR_TIME_ZONE                                  "timezone"
642 #define DB_FIELD_PVR_PTC                                                "ptc"
643 #define DB_FIELD_PVR_MAJOR                                              "major"
644 #define DB_FIELD_PVR_MINOR                                              "minor"
645 #define DB_FIELD_PVR_CHANNEL_TYPE                               "channel_type"
646 #define DB_FIELD_PVR_CHANNEL_NAME                       "channel_name"
647 #define DB_FIELD_PVR_CHANNEL_NUM                        "channel_num"
648 #define DB_FIELD_PVR_PROGRAM_TITLE                      "program_title"
649 #define DB_FIELD_PVR_PROGRAM_NUM                        "program_num"
650 #define DB_FIELD_PVR_PROGRAM_CRID                               "program_crid"
651 #define DB_FIELD_PVR_GUIDANCE                                   "guidance"
652 #define DB_FIELD_PVR_SYNOPSIS                                   "synopsis"
653 #define DB_FIELD_PVR_GENRE                                              "genre"
654 #define DB_FIELD_PVR_LANGUAGE                                   "language"
655 #define DB_FIELD_PVR_EMBARGO_TIME                               "embargo_time"
656 #define DB_FIELD_PVR_EXPIRY_TIME                                "expiry_time"
657 #define DB_FIELD_PVR_START_TIME                         "start_time"
658 #define DB_FIELD_PVR_PROGRAM_START_TIME         "program_start_time"
659 #define DB_FIELD_PVR_PROGRAM_END_TIME           "program_end_time"
660 #define DB_FIELD_PVR_PROGRAM_DATE                       "program_date"
661 #define DB_FIELD_PVR_PARENTAL_RATING                    "parental_rating"
662 #define DB_FIELD_PVR_TIMER_RECORD                               "timer_record"
663 #define DB_FIELD_PVR_SERIES_RECORD                              "series_record"
664 #define DB_FIELD_PVR_HD                                                 "hd"
665 #define DB_FIELD_PVR_SUBTITLE                                   "subtitle"
666 #define DB_FIELD_PVR_TTX                                                "ttx"
667 #define DB_FIELD_PVR_AD                                                 "ad"
668 #define DB_FIELD_PVR_HARDOF_HEARINGRADIO        "hard_of_hearing_radio"
669 #define DB_FIELD_PVR_DATA_SERVICE                               "data_service"
670 #define DB_FIELD_PVR_CONTENT_LOCK                               "content_lock"
671 #define DB_FIELD_PVR_CONTENT_WATCH                      "content_watch"
672 #define DB_FIELD_PVR_HAS_AUDIO_ONLY                     "has_audio_only"
673 #define DB_FIELD_PVR_IS_LOCAL_RECORD                    "is_local_record"
674 #define DB_FIELD_PVR_RESOLUTION                         "resolution"
675 #define DB_FIELD_PVR_ASPECTRATIO                                "aspectratio"
676 #define DB_FIELD_PVR_MODIFIED_MONTH                     "modified_month"
677 #define DB_FIELD_PVR_MODIFIED_DATE                      "modified_date"
678 #define DB_FIELD_PVR_SPORTS_TYPE                                "sports_type"
679 #define DB_FIELD_PVR_GUIDANCE_LENGTH                    "guidance_length"
680 #define DB_FIELD_PVR_TVMODE                                             "tvmode"
681 #define DB_FIELD_PVR_PLAY_COUNT                                 "play_count"
682 #define DB_FIELD_PVR_PRIVATE_DATA               "private_data"
683
684 /* DB fiedl for UHD */
685 #define DB_FIELD_UHD_CONTENT_TITLE              "content_title"
686 #define DB_FIELD_UHD_RELEASE_DATE                       "release_date"
687 #define DB_FIELD_UHD_SUB_TYPE                   "sub_type"
688 #define DB_FIELD_UHD_FILE_NAME                  "file_name"
689 #define DB_FIELD_UHD_PLAYED_COUNT                       "played_count"
690
691 /* DB Query Keyword */
692 #define QUERY_KEYWORD_AND "AND"
693 #define QUERY_KEYWORD_OR "OR"
694 #define QUERY_KEYWORD_ORDER_BY "ORDER BY "
695 #define QUERY_KEYWORD_LIMIT "limit"
696 #define QUERY_KEYWORD_DESC "DESC"
697 #define QUERY_KEYWORD_SPACE " "
698 #define QUERY_KEYWORD_OPEN_BRACKET "("
699 #define QUERY_KEYWORD_BRACKET ")"
700 #define QUERY_KEYWORD_COLLATE "COLLATE "
701
702 /* DB TABLE JOIN */
703 /*#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) " */
704 #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 "
705 #define BOOKMARK_MEDIA_JOIN                             "("DB_TABLE_BOOKMARK" AS b INNER JOIN '%s' AS m \
706                                                                                         ON (b.media_uuid = m.media_uuid)) WHERE m.validity=1"
707 #define ALBUM_MEDIA_JOIN                                        "("DB_TABLE_ALBUM" AS a INNER JOIN '%s' AS m \
708                                                                                         ON (a.album_id = m.album_id)) WHERE m.validity=1"
709 #define FACE_MEDIA_JOIN                                         "("DB_TABLE_FACE" AS fa INNER JOIN '%s' AS m \
710                                                                                                 ON (fa.media_uuid = m.media_uuid)) WHERE m.validity=1"
711
712 /* Get Group info */
713 #define SELECT_MEDIA_GROUP_AND_COUNT            "SELECT %s, COUNT(*) FROM '%s' WHERE validity=1 "
714
715 /* Get Group List */
716 #define SELECT_ALBUM_LIST                       "SELECT DISTINCT a.album_id, a.name, a.artist, a.album_art FROM "ALBUM_MEDIA_JOIN
717 #define SELECT_MEDIA_GROUP_LIST "SELECT DISTINCT %s FROM '%s' WHERE validity=1 "
718
719 #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 FROM "FOLDER_MEDIA_JOIN
720 #define SELECT_FOLDER_LIST_BY_STORAGE_ID        SELECT_FOLDER_LIST"AND f.storage_uuid='%s' "
721 #define SELECT_TAG_LIST                         "SELECT DISTINCT tag_id, name FROM "DB_VIEW_TAG" WHERE 1 "
722 #define SELECT_PLAYLIST_LIST                    "SELECT DISTINCT playlist_id, name, p_thumbnail_path FROM "DB_VIEW_PLAYLIST" WHERE 1 "
723
724 /* Get Group Count */
725 #define SELECT_ALBUM_COUNT              "SELECT COUNT(DISTINCT a.album_id) FROM "ALBUM_MEDIA_JOIN
726 #define SELECT_FOLDER_COUNT             "SELECT COUNT(DISTINCT f.folder_uuid) FROM "FOLDER_MEDIA_JOIN
727 #define SELECT_FOLDER_COUNT_BY_STORAGE_ID               SELECT_FOLDER_COUNT"AND f.storage_uuid='%s' "
728 #define SELECT_TAG_COUNT                        "SELECT COUNT(DISTINCT tag_id) FROM "DB_VIEW_TAG" WHERE 1 "
729 #define SELECT_PLAYLIST_COUNT           "SELECT COUNT(DISTINCT playlist_id) FROM "DB_VIEW_PLAYLIST" WHERE 1 "
730 #define SELECT_BOOKMARK_COUNT   "SELECT COUNT(DISTINCT b.bookmark_id) FROM "BOOKMARK_MEDIA_JOIN
731 #define SELECT_MEDIA_GROUP_COUNT        "SELECT COUNT(*) FROM ("SELECT_MEDIA_GROUP_LIST
732 /*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)*/
733
734 /* Get Media Count of Group */
735 #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" */
736 #define SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE    "SELECT COUNT(*) FROM '%s' WHERE validity=1 "
737 #define SELECT_MEDIA_COUNT_FROM_ALBUM                   "SELECT COUNT(*) FROM '%s' WHERE validity=1 AND album_id='%d'"
738 #define SELECT_MEDIA_COUNT_FROM_GROUP                   "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP         /*to apply limit condition. */
739 #define SELECT_MEDIA_COUNT_FROM_GROUP_NULL              "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP_NULL    /* to apply limit condition. */
740 #define SELECT_MEDIA_COUNT_FROM_FOLDER                  "SELECT COUNT(*) FROM '%s' WHERE validity=1 AND folder_uuid='%q'"
741 #define SELECT_MEDIA_COUNT_FROM_STORAGE                 "SELECT COUNT(*) FROM '%s' WHERE validity=1 AND storage_uuid='%q'"
742 #define SELECT_MEDIA_COUNT_FROM_TAG                             "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE (tag_id=%d AND media_count>0) "
743 #define SELECT_MEDIA_COUNT_FROM_PLAYLIST                        "SELECT COUNT(*) FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and media_count>0) "
744
745 /* Get Group Info by Group ID*/
746 #define SELECT_ALBUM_FROM_ALBUM         "SELECT * FROM "DB_TABLE_ALBUM" WHERE album_id=%d"
747 #define SELECT_FOLDER_FROM_FOLDER               "SELECT * FROM "DB_TABLE_FOLDER" WHERE folder_uuid='%s'"
748 #define SELECT_FOLDER_BY_PATH                   "SELECT * FROM "DB_TABLE_FOLDER" WHERE path='%q'"
749 #define SELECT_PLAYLIST_FROM_PLAYLIST   "SELECT * FROM "DB_TABLE_PLAYLIST" WHERE playlist_id=%d"
750 #define SELECT_TAG_FROM_TAG                     "SELECT * FROM "DB_TABLE_TAG" WHERE tag_id=%d"
751 #define SELECT_TAG_BY_NAME                              "SELECT * FROM "DB_TABLE_TAG" WHERE name='%q'"
752
753 /* Tag info*/
754 #define INSERT_TAG_TO_TAG                                               "INSERT INTO "DB_TABLE_TAG" (name) VALUES (%Q)"
755 #define REMOVE_TAG_ITEM_FROM_TAG_MAP            "DELETE FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d AND media_uuid='%q';"
756 #define UPDATE_TAG_NAME_FROM_TAG                        "UPDATE "DB_TABLE_TAG" SET name='%q' WHERE tag_id=%d;"
757 #define SELECT_TAG_COUNT_BY_MEDIA_ID                    "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE media_uuid = '%s'"
758 #define SELECT_TAG_LIST_BY_MEDIA_ID                             "SELECT tag_id, name FROM "DB_VIEW_TAG" WHERE media_uuid = '%s'"
759
760 /* Get Media list of Group */
761 #ifdef _USE_SENIOR_MODE
762 #define MEDIA_INFO_ITEM "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, thumbnail_path, description, \
763                                                         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, stitched_info, extract_flag, modified_date, contact, app_data"
764 #else
765 #define MEDIA_INFO_ITEM "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, thumbnail_path, description, \
766                                                         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, stitched_info, extract_flag, modified_date"
767 #endif
768
769 /*Folder info*/
770 #define UPDATE_FOLDER_ORDER                                     "UPDATE "DB_TABLE_FOLDER" SET folder_order=%d WHERE folder_uuid=%Q"
771 #define SELECT_FOLDER_ID_BY_PATH                                "SELECT folder_uuid FROM "DB_TABLE_FOLDER" WHERE path = '%s'"
772
773 /* Playlist Info */
774 #define INSERT_PLAYLIST_TO_PLAYLIST                                             "INSERT INTO "DB_TABLE_PLAYLIST" (name) VALUES (%Q)"
775 #define UPDATE_PLAYLIST_NAME_FROM_PLAYLIST                      "UPDATE "DB_TABLE_PLAYLIST" SET name='%q' WHERE playlist_id=%d;"
776 #define UPDATE_PLAYLIST_THUMBNAIL_FROM_PLAYLIST         "UPDATE "DB_TABLE_PLAYLIST" SET thumbnail_path='%q' WHERE playlist_id=%d;"
777 #define SELECT_PLAYLIST_ID_FROM_PLAYLIST                                "SELECT playlist_id FROM "DB_TABLE_PLAYLIST" WHERE name='%q'"
778 #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) "
779 #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) "
780 #define SELECT_PLAY_ORDER_FROM_PLAYLIST_VIEW                    "SELECT play_order FROM "DB_VIEW_PLAYLIST" WHERE playlist_id=%d and pm_id=%d"
781 #define SELECT_MAX_PLAY_ORDER_FROM_PLAYLIST_VIEW        "SELECT MAX(play_order) FROM "DB_VIEW_PLAYLIST" WHERE playlist_id=%d"
782 #define REMOVE_PLAYLIST_ITEM_FROM_PLAYLIST_MAP          "DELETE FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d AND _id=%d;"
783 #define UPDATE_PLAYLIST_ORDER_FROM_PLAYLIST_MAP         "UPDATE "DB_TABLE_PLAYLIST_MAP" SET play_order=%d WHERE playlist_id=%d AND _id=%d;"
784
785 /* Bookmark */
786 #define INSERT_BOOKMARK_TO_BOOKMARK                     "INSERT INTO "DB_TABLE_BOOKMARK" (media_uuid, marked_time, thumbnail_path, name) VALUES ('%q', '%d', %Q, %Q)"
787 #define SELECT_BOOKMARK_COUNT_BY_MEDIA_ID               "SELECT COUNT(*) FROM "BOOKMARK_MEDIA_JOIN" AND b.media_uuid='%s'"
788 #define SELECT_BOOKMARK_LIST                                            "SELECT b.bookmark_id, b.media_uuid, b.marked_time, b.thumbnail_path, b.name FROM "BOOKMARK_MEDIA_JOIN
789 #define SELECT_BOOKMARK_LIST_BY_MEDIA_ID                        "SELECT b.bookmark_id, b.media_uuid, b.marked_time, b.thumbnail_path, b.name FROM "BOOKMARK_MEDIA_JOIN" AND b.media_uuid='%s'"
790 #define SELECT_BOOKMARK_ID_FROM_BOOKMARK               "SELECT bookmark_id FROM "DB_TABLE_BOOKMARK" WHERE media_uuid='%s' AND marked_time=%d"
791
792 #define UPDATE_BOOKMARK_FROM_BOOKMARK           "UPDATE "DB_TABLE_BOOKMARK" SET name=%Q WHERE bookmark_id=%d;"
793
794 /* Update Meta*/
795 #define UPDATE_AV_META_FROM_MEDIA       "UPDATE '%s' SET played_count=%d, last_played_time=%d, last_played_position=%d WHERE media_uuid='%q'"
796 #define UPDATE_IMAGE_META_FROM_MEDIA    "UPDATE '%s' SET orientation=%d, weather=%Q WHERE media_uuid='%q'"
797
798 #define UPDATE_VIDEO_MM_DATA_FROM_MEDIA         "UPDATE '%s' SET bitrate=%d, duration=%d, width=%d, height=%d WHERE media_uuid='%q'"
799 #define UPDATE_AUDIO_MM_DATA_FROM_MEDIA         "UPDATE '%s' SET duration=%d, bitrate=%d, bitpersample=%d, samplerate=%d, channel=%d WHERE media_uuid='%q'"
800 #define UPDATE_IMAGE_MM_DATA_FROM_MEDIA         "UPDATE '%s' SET width=%d, height=%d WHERE media_uuid='%q'"
801 #define SELECT_VIDEO_MM_DATA_FROM_MEDIA         "SELECT bitrate, duration, width, height FROM '%s' WHERE media_uuid='%q'"
802 #define SELECT_AUDIO_MM_DATA_FROM_MEDIA         "SELECT duration, bitrate, bitpersample, samplerate, channel FROM '%s' WHERE media_uuid='%q'"
803 #define SELECT_IMAGE_MM_DATA_FROM_MEDIA         "SELECT width, height FROM '%s' WHERE media_uuid='%q'"
804
805 #define SELECT_MEDIA_ITEM                                       "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1"
806 #define SELECT_MEDIA_FROM_MEDIA                 "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND media_uuid='%s'"
807 #define SELECT_MEDIA_BY_PATH                            "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND path='%q'"
808 #define SELECT_MEDIA_FROM_ALBUM                 "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND album_id=%d"
809 #define SELECT_MEDIA_FROM_GROUP                 "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND %s='%q'"
810 #define SELECT_MEDIA_FROM_GROUP_NULL    "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND %s IS NULL"
811 #define SELECT_MEDIA_FROM_FOLDER                        "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND folder_uuid='%s'"
812 #define SELECT_MEDIA_FROM_STORAGE               "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND storage_uuid='%s'"
813 #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"
814 #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"
815 #define SELECT_MEDIA_PATH_BY_ID                 "SELECT path FROM "DB_TABLE_MEDIA_VIEW" WHERE media_uuid='%q'"
816 #define SELECT_MEDIA_STORAGE_ID_BY_ID           "SELECT storage_uuid FROM "DB_TABLE_MEDIA_VIEW" WHERE media_uuid='%q'"
817
818 /* Delete */
819 #define DELETE_MEDIA_FROM_MEDIA_BATCH   "DELETE FROM  '%s' WHERE %s AND storage_type = %d"
820 #define DELETE_PLAYLIST_FROM_PLAYLIST           "DELETE FROM "DB_TABLE_PLAYLIST" WHERE playlist_id=%d"
821 #define DELETE_TAG_FROM_TAG                             "DELETE FROM "DB_TABLE_TAG" WHERE tag_id=%d"
822 #define DELETE_BOOKMARK_FROM_BOOKMARK   "DELETE FROM "DB_TABLE_BOOKMARK" WHERE bookmark_id=%d"
823
824 /*For batch remove*/
825 #define SELECT_STORAGE_BY_FILTER        "SELECT DISTINCT storage_uuid, storage_type FROM "DB_TABLE_MEDIA_VIEW" WHERE %s"
826 #define SELECT_THUMBNAIL_BY_FILTER      "SELECT DISTINCT thumbnail_path FROM '%s' WHERE %s AND storage_type = %d"
827
828 /* Storage*/
829 #define SELECT_STORAGE_COUNT                            "SELECT COUNT(*) FROM "DB_TABLE_STORAGE" WHERE validity=1"
830 #define SELECT_STORAGE_LIST                                     "SELECT * FROM "DB_TABLE_STORAGE" WHERE validity=1"
831 #define SELECT_STORAGE_INFO_FROM_STORAGE        "SELECT * FROM "DB_TABLE_STORAGE" WHERE validity=1 AND storage_uuid='%s'"
832
833 /* Face */
834 #define DELETE_FACE_FROM_FACE                   "DELETE FROM "DB_TABLE_FACE" WHERE face_uuid='%q'"
835 #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);"
836 #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'"
837 #define SELECT_MEDIA_COUNT_FROM_MEDIA_BY_ID             "SELECT COUNT(*) FROM "DB_TABLE_MEDIA_VIEW" WHERE media_uuid='%q' AND validity=1"
838 #define SELECT_FACE_COUNT                                       "SELECT COUNT(*) FROM "FACE_MEDIA_JOIN
839 #define SELECT_FACE_COUNT_BY_MEDIA_ID           "SELECT COUNT(*) FROM "FACE_MEDIA_JOIN" AND fa.media_uuid='%s'"
840 #define SELECT_FACE_LIST                                                "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
841 #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'"
842 #define SELECT_FACE_PATH_FROM_MEDIA             "SELECT path FROM "DB_TABLE_MEDIA_VIEW" media_uuid='%s'"
843
844 #define DEFAULT_MEDIA_STORAGE_ID                        "media"
845
846 #define SELECT_VALID_STORAGE_FROM_PVR   "WHERE storage_uuid IN (SELECT storage_uuid FROM "DB_TABLE_STORAGE" WHERE validity=1)"
847 #define SELECT_PVR_COUNT                                        "SELECT COUNT(*) FROM "DB_TABLE_PVR" "SELECT_VALID_STORAGE_FROM_PVR
848 #define SELECT_PVR_LIST                                 "SELECT * FROM "DB_TABLE_PVR" "SELECT_VALID_STORAGE_FROM_PVR
849 #define SELECT_PVR_COUNT_BY_STORAGE_ID  SELECT_PVR_COUNT" AND storage_uuid='%s'"
850 #define SELECT_PVR_LIST_BY_STORAGE_ID           SELECT_PVR_LIST" AND storage_uuid='%s'"
851 #define SELECT_PVR_FROM_PVR                             "SELECT * FROM "DB_TABLE_PVR" WHERE media_uuid='%q'"
852 #define UPDATE_PVR_META_FROM_PVR                "UPDATE "DB_TABLE_PVR" SET program_title=%Q, content_lock=%d, content_watch=%d, play_count=%d, highlight=%d WHERE media_uuid='%q'"
853 #define UPDATE_PVR_LOCAL_RECORD_PVR             "UPDATE "DB_TABLE_PVR" SET is_local_record=%d WHERE path='%q' AND storage_uuid='%q'"
854
855 #define SELECT_PVR_GROUP_LIST                                           "SELECT DISTINCT %s FROM "DB_TABLE_PVR" "SELECT_VALID_STORAGE_FROM_PVR
856 #define SELECT_PVR_GROUP_LIST_BY_STORAGE_ID             "SELECT DISTINCT %s FROM "DB_TABLE_PVR" WHERE storage_uuid='%s'"
857 #define SELECT_PVR_GROUP_COUNT                                  "SELECT COUNT(*) FROM ("SELECT_PVR_GROUP_LIST
858 #define SELECT_PVR_GROUP_COUNT_BY_STORAGE_ID    "SELECT COUNT(*) FROM ("SELECT_PVR_GROUP_LIST_BY_STORAGE_ID
859 #define SELECT_PVR_FROM_GROUP                                           "SELECT * FROM "DB_TABLE_PVR" "SELECT_VALID_STORAGE_FROM_PVR" AND %s='%q'"
860 #define SELECT_PVR_FROM_GROUP_BY_STORAGE_ID             "SELECT * FROM "DB_TABLE_PVR" WHERE storage_uuid='%s' AND %s='%q'"
861 #define SELECT_PVR_COUNT_FROM_GROUP                             "SELECT COUNT(*) FROM ("SELECT_PVR_FROM_GROUP
862 #define SELECT_PVR_COUNT_FROM_GROUP_BY_STORAGE_ID       "SELECT COUNT(*) FROM ("SELECT_PVR_FROM_GROUP_BY_STORAGE_ID
863 #define SELECT_PVR_FROM_GROUP_NULL                                      "SELECT * FROM "DB_TABLE_PVR" "SELECT_VALID_STORAGE_FROM_PVR" AND %s IS NULL"
864 #define SELECT_PVR_FROM_GROUP_NULL_BY_STORAGE_ID        "SELECT * FROM "DB_TABLE_PVR" WHERE storage_uuid='%s' AND %s IS NULL"
865 #define SELECT_PVR_COUNT_FROM_GROUP_NULL                        "SELECT COUNT(*) FROM ("SELECT_PVR_FROM_GROUP_NULL
866 #define SELECT_PVR_COUNT_FROM_GROUP_NULL_BY_STORAGE_ID  "SELECT COUNT(*) FROM ("SELECT_PVR_FROM_GROUP_NULL_BY_STORAGE_ID
867 #define SELECT_PVR_GROUP_AND_COUNT_BY_STORAGE_ID                "SELECT %s, COUNT(*) FROM "DB_TABLE_PVR" WHERE storage_uuid='%s'"
868 #define SELECT_PVR_GROUP_AND_COUNT                                              "SELECT %s, COUNT(*) FROM "DB_TABLE_PVR" "SELECT_VALID_STORAGE_FROM_PVR
869
870 #define SELECT_VALID_STORAGE_FROM_UHD   "WHERE storage_uuid IN (SELECT storage_uuid FROM "DB_TABLE_STORAGE" WHERE validity=1)"
871 #define SELECT_UHD_GROUP_LIST                                           "SELECT DISTINCT %s FROM "DB_TABLE_UHD" "SELECT_VALID_STORAGE_FROM_UHD
872 #define SELECT_UHD_GROUP_LIST_BY_STORAGE_ID             "SELECT DISTINCT %s FROM "DB_TABLE_UHD" WHERE storage_uuid='%s'"
873 #define SELECT_UHD_GROUP_COUNT                                  "SELECT COUNT(*) FROM ("SELECT_UHD_GROUP_LIST
874 #define SELECT_UHD_GROUP_COUNT_BY_STORAGE_ID    "SELECT COUNT(*) FROM ("SELECT_UHD_GROUP_LIST_BY_STORAGE_ID
875 #define SELECT_UHD_FROM_GROUP                                           "SELECT * FROM "DB_TABLE_UHD" "SELECT_VALID_STORAGE_FROM_UHD" AND %s='%q'"
876 #define SELECT_UHD_FROM_GROUP_BY_STORAGE_ID             "SELECT * FROM "DB_TABLE_UHD" WHERE storage_uuid='%s' AND %s='%q'"
877 #define SELECT_UHD_COUNT_FROM_GROUP                             "SELECT COUNT(*) FROM ("SELECT_UHD_FROM_GROUP
878 #define SELECT_UHD_COUNT_FROM_GROUP_BY_STORAGE_ID       "SELECT COUNT(*) FROM ("SELECT_UHD_FROM_GROUP_BY_STORAGE_ID
879 #define SELECT_UHD_FROM_GROUP_NULL                                      "SELECT * FROM "DB_TABLE_UHD" "SELECT_VALID_STORAGE_FROM_UHD" AND %s IS NULL"
880 #define SELECT_UHD_FROM_GROUP_NULL_BY_STORAGE_ID        "SELECT * FROM "DB_TABLE_UHD" WHERE storage_uuid='%s' AND %s IS NULL"
881 #define SELECT_UHD_COUNT_FROM_GROUP_NULL                        "SELECT COUNT(*) FROM ("SELECT_UHD_FROM_GROUP_NULL
882 #define SELECT_UHD_COUNT_FROM_GROUP_NULL_BY_STORAGE_ID  "SELECT COUNT(*) FROM ("SELECT_UHD_FROM_GROUP_NULL_BY_STORAGE_ID
883 #define SELECT_UHD_GROUP_AND_COUNT_BY_STORAGE_ID                "SELECT %s, COUNT(*) FROM "DB_TABLE_UHD" WHERE storage_uuid='%s'"
884 #define SELECT_UHD_GROUP_AND_COUNT                                              "SELECT %s, COUNT(*) FROM "DB_TABLE_UHD" "SELECT_VALID_STORAGE_FROM_UHD
885
886 #define SELECT_UHD_COUNT                                        "SELECT COUNT(*) FROM "DB_TABLE_UHD" "SELECT_VALID_STORAGE_FROM_UHD
887 #define SELECT_UHD_COUNT_BY_STORAGE_ID  SELECT_UHD_COUNT" AND storage_uuid='%s'"
888 #define SELECT_UHD_LIST                                 "SELECT * FROM "DB_TABLE_UHD" "SELECT_VALID_STORAGE_FROM_UHD
889 #define SELECT_UHD_LIST_BY_STORAGE_ID   SELECT_UHD_LIST" AND storage_uuid='%s'"
890 #define SELECT_UHD_FROM_UHD                             "SELECT * FROM "DB_TABLE_UHD" WHERE media_uuid='%q'"
891 #define UPDATE_UHD_META_FROM_UHD                "UPDATE "DB_TABLE_UHD" SET content_title=%Q, release_date=%Q, played_position=%d, sub_type=%d, played_count=%d WHERE media_uuid='%q'"
892
893 int _content_query_prepare(sqlite3_stmt **stmt, char *select_query, char *condition_query, char *option_query);
894 int _content_error_capi(int type, int cotent_error);
895 int _content_query_sql(char *query_str);
896 MediaSvcHandle* _content_get_db_handle(void);
897 attribute_h _content_get_attirbute_handle(void);
898 attribute_h _content_get_alias_attirbute_handle(void);
899 int _media_info_get_media_info_from_db(const char *path, const char *storage_id, media_info_h media);
900 void _media_info_item_get_detail(sqlite3_stmt *stmt, media_info_h media);
901 int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count);
902 int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *group_count);
903 int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_cb callback, void *user_data);
904 int _media_db_get_media_group_and_count(media_group_e group, filter_h filter, media_group_and_count_cb callback, void *user_data);
905 int _media_db_get_album(filter_h filter, media_album_cb callback, void *user_data);
906 int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_data);
907 int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *user_data);
908 int _media_db_get_playlist_item(int playlist_id, filter_h filter, playlist_member_cb callback, void *user_data);
909 int _media_db_get_tag(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data);
910 int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data);
911 int _media_db_get_face(const char *media_id, filter_h filter, media_face_cb callback, void *user_data);
912 int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_list_e group_type, int *item_count);
913 int _media_db_get_group_item_count(const char *group_name, filter_h filter, group_list_e group_type, int *item_count);
914 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);
915 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);
916 #ifdef _USE_SENIOR_MODE
917 int _content_query_prepare_by_union_select(sqlite3_stmt **stmt, char *select_query1, char *condition_query1, char *option_query1, char *select_query2, char *condition_query2, char *option_query2);
918 int _media_db_get_group_item_by_union_select(const char *group_name, filter_h filter1, filter_h filter2, media_info_cb callback, void *user_data);
919 #endif
920 int _media_db_get_media_group_item_count(const char *group_name, filter_h filter, media_group_e group, int *item_count);
921 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);
922 int _media_db_get_storage(filter_h filter, media_storage_cb callback, void *user_data);
923 int _media_db_get_storage_id_by_media_id(const char *media_id, char *storage_id);
924 int _media_db_get_storage(filter_h filter, media_storage_cb callback, void *user_data);
925 int _media_db_get_storage_id_by_media_id(const char *media_id, char *storage_id);
926 int _media_db_get_pvr(filter_h filter, media_pvr_cb callback, void *user_data);
927 void _media_pvr_item_get_detail(sqlite3_stmt* stmt, media_pvr_h pvr);
928 int _media_db_get_pvr_group_item(const char *group_name, filter_h filter, media_group_e group, media_pvr_cb callback, void *user_data);
929 int _media_db_get_uhd(filter_h filter, media_uhd_cb callback, void *user_data);
930 void _media_uhd_item_get_detail(sqlite3_stmt* stmt, media_uhd_h uhd);
931
932 /**
933  * @internal
934  * @brief Creates a media filter attribute handle.
935  * @details This function creates a media filter attribute handle. The handle can be
936  * used to convert to attributes of database from attributes of user.
937  * @remarks The @a handle must be released with media_filter_attribute_destory() by you.
938  * @param[out] filter A handle to media filter attribute
939  * @return 0 on success, otherwise a negative error value.
940  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
941  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
942  * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory
943  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
944  * @see media_filter_attribute_destory()
945  *
946  */
947 int _media_filter_attribute_create(attribute_h *attr);
948
949 /**
950  * @internal
951  * @brief Add the attributes to the handle.
952  * @details This function add the attribute to handle.
953  * @param[in] filter The handle to media filter attribute
954  * @param[in] user_attr The user attribute
955  * @param[in] platform_attr The platform attribute
956  * @return 0 on success, otherwise a negative error value.
957  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
958  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
959  * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory
960  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
961  * @see media_filter_attribute_remove()
962  *
963  */
964 int _media_filter_attribute_add(attribute_h atrr, const char *user_attr, const char *platform_attr);
965
966 /**
967  * @internal
968  * @brief Destroys a media filter attribute handle.
969  * @details The function frees all resources related to the media filter attribute handle. The filter attribute
970  * handle no longer can be used to perform any operation. A new handle
971  * has to be created before the next usage.
972  *
973  * @param[in] filter The handle to media filter attribute
974  * @return 0 on success, otherwise a negative error value.
975  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
976  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
977  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
978  * @see media_filter_create()
979  *
980  */
981 int _media_filter_attribute_destory(attribute_h attr);
982
983 /**
984  * @internal
985  * @brief Replace to platform attributes from user attributes.
986  * @details This function replace to platform attributes from user attributes to generate the WHERE clause
987  * @param[in] filter The handle to media filter attribute
988  * @param[in] user_attr The user attribute
989  * @param[in] platform_attr The platform attribute
990  * @return 0 on success, otherwise a negative error value.
991  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
992  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
993  * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory
994  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
995  * @see media_filter_attribute_create()
996  * @see media_filter_attribute_destory()
997  *
998  */
999 int _media_filter_attribute_generate(attribute_h attr, filter_h filter, char **generated_condition);
1000
1001 /**
1002  * @internal
1003  * @brief Replace to platform attributes from user attributes.
1004  * @details This function replace to platform attributes from user attributes to generate the WHERE clause
1005  * @param[in] filter The handle to media filter attribute
1006  * @param[in] attr The attribute
1007  * @param[in] generated_option The handle to generated option
1008  * @return 0 on success, otherwise a negative error value.
1009  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
1010  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
1011  * @retval #MEDIA_CONTENT_ERROR_DB_FAILED Filed DB
1012  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
1013  * @see media_filter_attribute_create()
1014  * @see media_filter_attribute_destory()
1015  *
1016  */
1017
1018 int _media_filter_attribute_option_generate(attribute_h attr, filter_h filter, char **generated_option);
1019
1020 int _media_filter_attribute_option_generate_with_full_query(attribute_h attr, filter_h filter, char **generated_option);
1021
1022 GMutex* _content_get_db_mutex(void);
1023
1024
1025 #define FONT_COLOR_RESET    "\033[0m"
1026 #define FONT_COLOR_RED      "\033[31m"
1027 #define FONT_COLOR_GREEN    "\033[32m"
1028 #define FONT_COLOR_YELLOW   "\033[33m"
1029 #define FONT_COLOR_BLUE     "\033[34m"
1030 #define FONT_COLOR_PURPLE   "\033[35m"
1031 #define FONT_COLOR_CYAN     "\033[36m"
1032 #define FONT_COLOR_GRAY     "\033[37m"
1033
1034 #define media_content_gettid() syscall(__NR_gettid)
1035
1036 #define media_content_retv_if(expr, val) do { \
1037                         if (expr) { \
1038                                 LOGE(FONT_COLOR_RED"[%ld]"FONT_COLOR_RESET, media_content_gettid());    \
1039                                 return (val); \
1040                         } \
1041                 } while (0)
1042
1043 #define media_content_retvm_if(expr, val, fmt, arg...) do { \
1044                         if (expr) { \
1045                                 LOGE(FONT_COLOR_RED"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg);     \
1046                                 return (val); \
1047                         } \
1048                 } while (0)
1049
1050 #define media_content_warn(fmt, arg...) do { \
1051                         LOGW(FONT_COLOR_GREEN"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg);     \
1052                 } while (0)
1053
1054 #define media_content_debug(fmt, arg...) do { \
1055                         LOGD(FONT_COLOR_RESET"[%ld]"fmt"", media_content_gettid(), ##arg);     \
1056                 } while (0)
1057
1058 #define media_content_info(fmt, arg...) do { \
1059                         LOGI(FONT_COLOR_GREEN"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg);     \
1060                 } while (0)
1061
1062 #define media_content_error(fmt, arg...) do { \
1063                         LOGE(FONT_COLOR_RED"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg);     \
1064                 } while (0)
1065
1066 #define media_content_debug_func() do { \
1067                         LOGD(FONT_COLOR_RESET"[%ld]", media_content_gettid());     \
1068                 } while (0)
1069
1070 #define media_content_sec_debug(fmt, arg...) do { \
1071                         SECURE_LOGD(FONT_COLOR_CYAN"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg);     \
1072                 } while (0)
1073
1074 #define media_content_sec_warn(fmt, arg...) do { \
1075                         SECURE_LOGW(FONT_COLOR_RED"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg);     \
1076                 } while (0)
1077
1078 #define media_content_sec_error(fmt, arg...) do { \
1079                         SECURE_LOGE(FONT_COLOR_RED"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg);     \
1080                 } while (0)
1081
1082 #define ERR_BUF_LENGTH 256
1083 #define media_content_stderror(fmt) do { \
1084                         char media_content_stderror_buf[ERR_BUF_LENGTH] = {0, }; \
1085                         strerror_r(errno, media_content_stderror_buf, ERR_BUF_LENGTH);  \
1086                         LOGE(FONT_COLOR_RED fmt" : STANDARD ERROR [%s]"FONT_COLOR_RESET, media_content_stderror_buf); \
1087                 } while (0)
1088
1089 #ifdef __cplusplus
1090 }
1091 #endif /* __cplusplus */
1092 #endif /*__TIZEN_MEDIA_INFO_PRIVATE_H__*/