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