Remove unused parameter when request face detection
[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_TVPD_MODE
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 *exposure_time;
249         double fnumber;
250         int iso;
251         char *model;
252         media_content_orientation_e orientation;
253 } image_meta_s;
254
255 typedef struct _image_mm_meta_s {
256         int width;
257         int height;
258 } image_mm_meta_s;
259
260 typedef struct {
261         char *media_id;
262         char *title;
263         char *album;
264         char *artist;
265         char *album_artist;
266         char *genre;
267         char *composer;
268         char *year;
269         char *recorded_date;
270         char *copyright;
271         char *track_num;
272         int bitrate;
273         int duration;
274         int width;
275         int height;
276         int played_count;
277         int rotation;
278         time_t played_time;
279         int played_position;
280 } video_meta_s;
281
282 typedef struct {
283         char *media_id;
284         char *title;
285         char *album;
286         char *artist;
287         char *album_artist;
288         char *genre;
289         char *composer;
290         char *year;
291         char *recorded_date;
292         char *copyright;
293         char *track_num;
294         int bitrate;
295         int bitpersample;
296         int samplerate;
297         int channel;
298         int duration;
299         int played_count;
300         time_t played_time;
301         int played_position;
302 } audio_meta_s;
303
304 typedef struct {
305         char *media_id;
306         char *file_path;
307         char *display_name;
308         media_content_type_e media_type;
309         char *mime_type;
310         unsigned long long size;
311         time_t added_time;
312         time_t modified_time;
313         time_t timeline;
314         char *thumbnail_path;
315         char *description;
316         double longitude;
317         double latitude;
318         double altitude;
319         char *weather;
320         int rating;
321         time_t favourite;
322         char *title;
323         char *author;
324         char *provider;
325         char *content_name;
326         char *category;
327         char *location_tag;
328         char *age_rating;
329         char *keyword;
330         int is_drm;
331         int storage_type;
332         int played_count;
333         time_t played_time;
334         int played_position;
335         char *modified_month;
336         char *storage_uuid;
337         int sync_status;
338         unsigned int request_id;
339         unsigned int face_request_id;
340         int is_360;
341         int stitched_info;
342         int extract_flag;
343 #ifdef _USE_SENIOR_MODE
344         char* contact;
345         char* app_data;
346 #endif
347         image_meta_s *image_meta;
348         video_meta_s *video_meta;
349         audio_meta_s *audio_meta;
350 } media_info_s;
351
352 typedef struct {
353         char *media_id;
354         int function;
355         char *tag_name;
356 } media_tag_item_s;
357
358 typedef struct {
359         char *media_id;
360         int function;
361         char *playlist_name;
362         char *thumbnail_path;
363         int playlist_member_id;
364         int play_order;
365 } media_playlist_item_s;
366
367 typedef struct {
368         char *storage_id;
369         char *storage_path;
370         int storage_type;
371 } media_storage_s;
372
373 typedef struct {
374         int face_id;                            /* face id */
375         char *media_id;                 /* media uuid */
376         unsigned int face_rect_x;       /* x position of face */
377         unsigned int face_rect_y;       /* y position of face */
378         unsigned int face_rect_w;       /* width of face */
379         unsigned int face_rect_h;       /* height of face */
380         int orientation;                        /* orientation */
381         char *face_tag;                 /* face tag */
382 } media_face_s;
383
384 typedef struct {
385         char *media_id;
386         char *storage_id;
387         char *path;
388         unsigned long long size;
389         int duration;
390         int timezone;
391         int ptc;
392         int major;
393         int minor;
394         int channel_type;
395         char *channel_name;
396         char *channel_num;
397         char *program_title;
398         int program_num;
399         char *program_crid;
400         char *guidance;
401         char *synopsis;
402         char *genre;
403         char *language;
404         int embargo_time;
405         int expiry_time;
406         int start_time;
407         int program_start_time;
408         int program_end_time;
409         int program_date;
410         int parental_rating;
411         int timer_record;
412         int series_record;
413         int hd;
414         int subtitle;
415         int ttx;
416         int ad;
417         int hard_of_hearing_radio;
418         int data_service;
419         int content_lock;
420         int content_watch;
421         int has_audio_only;
422         int is_local_record;
423         int resolution;
424         int aspectratio;
425         char* modified_month;
426         int sports_type;
427         int guidance_length;
428         int tvmode;
429         int play_count;
430         int highlight;
431         char* private_data;
432 } media_pvr_s;
433
434 typedef struct {
435         char *media_id;
436         char *storage_id;
437         char *path;
438         unsigned long long size;
439         char *content_id;
440         char *content_title;
441         char *file_name;
442         char* release_date;
443         time_t modified_time;
444         int played_position;
445         int sub_type;
446         int played_count;
447 } media_uhd_s;
448
449 typedef struct _attribute_map_s {
450         GHashTable *attr_map;
451 } attribute_s;
452
453 typedef struct {
454         media_info_s *handle;
455         void *user_data;
456         media_thumbnail_completed_cb thumbnail_completed_cb;
457 } media_thumbnail_cb_s;
458
459 typedef struct {
460         void *user_data;
461         media_face_detection_completed_cb face_completed_cb;
462 } media_face_cb_s;
463
464 typedef struct {
465         media_insert_completed_cb insert_completed_cb;
466         char *insert_list_path;
467         void *user_data;
468 } media_insert_cb_s;
469
470 typedef struct {
471         media_content_db_update_cb update_noti_cb;
472         void *user_data;
473 } media_noti_cb_s;
474
475 typedef struct attribute_s *attribute_h;
476
477
478 typedef struct _media_content_cb_data {
479         media_scan_completed_cb callback;
480         void *user_data;
481 } media_content_scan_cb_data;
482
483 typedef struct _media_content_scan_cb_data_v2 {
484         media_scan_completed_cb_v2 callback;
485         void *user_data;
486 } media_content_scan_cb_data_v2;
487
488 /* DB Table */
489 #define DB_TABLE_MEDIA                  "media"
490 #define DB_TABLE_FOLDER         "folder"
491 #define DB_TABLE_ALBUM                  "album"
492 #define DB_TABLE_TAG                    "tag"
493 #define DB_TABLE_TAG_MAP                "tag_map"
494 #define DB_TABLE_PLAYLIST               "playlist"
495 #define DB_TABLE_PLAYLIST_MAP   "playlist_map"
496 #define DB_TABLE_BOOKMARK               "bookmark"
497 #define DB_TABLE_STORAGE                "storage"
498 #define DB_TABLE_MEDIA_VIEW     "media_view"
499 #define DB_TABLE_FACE                   "face"
500 #define DB_TABLE_FACE_SCAN_LIST "face_scan_list"
501 #define DB_TABLE_PVR                            "pvr"
502 #define DB_TABLE_UHD                                            "uhd"
503
504 /* DB View */
505 #define DB_VIEW_PLAYLIST        "playlist_view"
506 #define DB_VIEW_TAG                     "tag_view"
507
508 /* DB Table Alias */
509 #define DB_TABLE_ALIAS_MEDIA                    "m"
510 #define DB_TABLE_ALIAS_FOLDER                   "f"
511 #define DB_TABLE_ALIAS_PLAYLIST                 "p"
512 #define DB_TABLE_ALIAS_PLAYLIST_MAP     "pm"
513 #define DB_TABLE_ALIAS_TAG                              "t"
514 #define DB_TABLE_ALIAS_BOOKMARK         "b"
515 #define DB_TABLE_ALIAS_ALBUM                    "a"
516 #define DB_TABLE_ALIAS_FACE                             "fa"
517
518 /* DB field for media */
519 #define DB_FIELD_MEDIA_ID                                       "media_uuid"
520 #define DB_FIELD_MEDIA_PATH                             "path"
521 #define DB_FIELD_MEDIA_DISPLAY_NAME             "file_name"
522 #define DB_FIELD_MEDIA_TYPE                                     "media_type"
523 #define DB_FIELD_MEDIA_MIME_TYPE                        "mime_type"
524 #define DB_FIELD_MEDIA_SIZE                                     "size"
525 #define DB_FIELD_MEDIA_ADDED_TIME                       "added_time"
526 #define DB_FIELD_MEDIA_MODIFIED_TIME            "modified_time"
527 #define DB_FIELD_MEDIA_FOLDER_ID                        "folder_uuid"
528 #define DB_FIELD_MEDIA_TIMELINE                         "timeline"
529 #define DB_FIELD_MEDIA_THUMBNAIL_PATH   "thumbnail_path"
530 #define DB_FIELD_MEDIA_TITLE                            "title"
531 #define DB_FIELD_MEDIA_ALBUM                            "album"
532 #define DB_FIELD_MEDIA_ARTIST                           "artist"
533 #define DB_FIELD_MEDIA_ALBUM_ARTIST                     "album_artist"
534 #define DB_FIELD_MEDIA_GENRE                            "genre"
535 #define DB_FIELD_MEDIA_COMPOSER                 "composer"
536 #define DB_FIELD_MEDIA_YEAR                             "year"
537 #define DB_FIELD_MEDIA_RECORDED_DATE            "recorded_date"
538 #define DB_FIELD_MEDIA_COPYRIGHT                        "copyright"
539 #define DB_FIELD_MEDIA_TRACK_NUM                        "track_num"
540 #define DB_FIELD_MEDIA_DESCRIPTION                      "description"
541 #define DB_FIELD_MEDIA_BITRATE                          "bitrate"
542 #define DB_FIELD_MEDIA_BITPERSAMPLE             "bitpersample"
543 #define DB_FIELD_MEDIA_SAMPLERATE                       "samplerate"
544 #define DB_FIELD_MEDIA_CHANNEL                  "channel"
545 #define DB_FIELD_MEDIA_DURATION                 "duration"
546 #define DB_FIELD_MEDIA_LONGITUDE                        "longitude"
547 #define DB_FIELD_MEDIA_LATITUDE                 "latitude"
548 #define DB_FIELD_MEDIA_ALTITUDE                 "altitude"
549 #define DB_FIELD_MEDIA_WIDTH                            "width"
550 #define DB_FIELD_MEDIA_HEIGHT                           "height"
551 #define DB_FIELD_MEDIA_DATETAKEN                        "datetaken"
552 #define DB_FIELD_MEDIA_ORIENTATION              "orientation"
553 #define DB_FIELD_MEDIA_BURST_ID                 "burst_id"
554 #define DB_FIELD_MEDIA_PLAYED_COUNT             "played_count"
555 #define DB_FIELD_MEDIA_LAST_PLAYED_TIME         "last_played_time"
556 #define DB_FIELD_MEDIA_LAST_PLAYED_POSITION     "last_played_position"
557 #define DB_FIELD_MEDIA_RATING                           "rating"
558 #define DB_FIELD_MEDIA_FAVOURITE                        "favourite"
559 #define DB_FIELD_MEDIA_AUTHOR                           "author"
560 #define DB_FIELD_MEDIA_PROVIDER                 "provider"
561 #define DB_FIELD_MEDIA_CONTENT_NAME             "content_name"
562 #define DB_FIELD_MEDIA_CATEGORY                 "category"
563 #define DB_FIELD_MEDIA_LOCATION_TAG             "location_tag"
564 #define DB_FIELD_MEDIA_AGE_RATING                       "age_rating"
565 #define DB_FIELD_MEDIA_KEYWORD                  "keyword"
566 #define DB_FIELD_MEDIA_WEATHER                  "weather"
567 #define DB_FIELD_MEDIA_IS_DRM                           "is_drm"
568 #define DB_FIELD_MEDIA_STORAGE_TYPE             "storage_type"
569 #define DB_FIELD_MEDIA_MODIFIED_MONTH   "modified_month"
570 #define DB_FIELD_MEDIA_MODIFIED_DATE    "modified_date"
571 #define DB_FIELD_MEDIA_EXPOSURE_TIME    "exposure_time"
572 #define DB_FIELD_MEDIA_FNUMBER                  "fnumber"
573 #define DB_FIELD_MEDIA_ISO                              "iso"
574 #define DB_FIELD_MEDIA_MODEL                    "model"
575 #define DB_FIELD_MEDIA_FILE_NAME_PINYIN                 "file_name_pinyin"
576 #define DB_FIELD_MEDIA_TITLE_PINYIN                                     "title_pinyin"
577 #define DB_FIELD_MEDIA_ALBUM_PINYIN                             "album_pinyin"
578 #define DB_FIELD_MEDIA_ARTIST_PINYIN                            "artist_pinyin"
579 #define DB_FIELD_MEDIA_ALBUM_ARTIST_PINYIN              "album_artist_pinyin"
580 #define DB_FIELD_MEDIA_GENRE_PINYIN                             "genre_pinyin"
581 #define DB_FIELD_MEDIA_COMPOSER_PINYIN                  "composer_pinyin"
582 #define DB_FIELD_MEDIA_COPYRIGHT_PINYIN                 "copyright_pinyin"
583 #define DB_FIELD_MEDIA_DESCRIPTION_PINYIN                       "description_pinyin"
584 #define DB_FIELD_MEDIA_AUTHOR_PINYIN                            "author_pinyin"
585 #define DB_FIELD_MEDIA_PROVIDER_PINYIN                  "provider_pinyin"
586 #define DB_FIELD_MEDIA_CONTENT_NAME_PINYIN              "content_name_pinyin"
587 #define DB_FIELD_MEDIA_CATEGORY_PINYIN                  "category_pinyin"
588 #define DB_FIELD_MEDIA_LOCATION_TAG_PINYIN              "location_tag_pinyin"
589 #define DB_FIELD_MEDIA_AGE_RATING_PINYIN                        "age_rating_pinyin"
590 #define DB_FIELD_MEDIA_KEYWORD_PINYIN                           "keyword_pinyin"
591 #define DB_FIELD_MEDIA_360                                                      "is_360"
592 #define DB_FIELD_MEDIA_STITCHED_INFO                            "stitched_info"
593 #ifdef _USE_SENIOR_MODE
594 #define DB_FIELD_MEDIA_CONTACT                  "contact"
595 #define DB_FIELD_MEDIA_APP_DATA                 "app_data"
596 #endif
597
598 /* DB field for folder */
599 #define DB_FIELD_FOLDER_ID                              "folder_uuid"
600 #define DB_FIELD_FOLDER_PATH                    "path"
601 #define DB_FIELD_FOLDER_NAME                    "name"
602 #define DB_FIELD_FOLDER_MODIFIED_TIME   "modified_time"
603 #define DB_FIELD_FOLDER_STORAGE_TYPE    "storage_type"
604 #define DB_FIELD_FOLDER_NAME_PINYIN     "name_pinyin"
605 #define DB_FIELD_FOLDER_ORDER                   "folder_order"
606
607 /* DB field for playlist */
608 #define DB_FIELD_PLAYLIST_ID                                    "playlist_id"
609 #define DB_FIELD_PLAYLIST_NAME                          "name"
610 #define DB_FIELD_PLAYLIST_MEMBER_ORDER  "play_order"
611 #define DB_FIELD_PLAYLIST_MEDIA_COUNT                   "media_count"
612
613 /* DB field for tag */
614 #define DB_FIELD_TAG_ID                 "tag_id"
615 #define DB_FIELD_TAG_NAME               "name"
616 #define DB_FIELD_TAG_MEDIA_COUNT                        "media_count"
617
618 /* DB field for bookmark */
619 #define DB_FIELD_BOOKMARK_ID    "bookmark_id"
620 #define DB_FIELD_BOOKMARK_MARKED_TIME   "marked_time"
621 #define DB_FIELD_BOOKMARK_NAME  "name"
622
623 /* DB field for album*/
624 #define DB_FIELD_ALBUM_ID                       "album_id"
625 #define DB_FIELD_ALBUM_NAME             "name"
626 #define DB_FIELD_ALBUM_ARTIST           "artist"
627
628 /* DB field for Storage*/
629 #define DB_FIELD_STORAGE_ID                     "storage_uuid"
630 #define DB_FIELD_STORAGE_PATH           "storage_path"
631
632 /* DB field for Face */
633 #define DB_FIELD_FACE_ID                                "face_id"
634 #define DB_FIELD_FACE_TAG                       "face_tag"
635
636 /* DB field for PVR*/
637 #define DB_FIELD_PVR_DURATION                                   "duration"
638 #define DB_FIELD_PVR_TIME_ZONE                                  "timezone"
639 #define DB_FIELD_PVR_PTC                                                "ptc"
640 #define DB_FIELD_PVR_MAJOR                                              "major"
641 #define DB_FIELD_PVR_MINOR                                              "minor"
642 #define DB_FIELD_PVR_CHANNEL_TYPE                               "channel_type"
643 #define DB_FIELD_PVR_CHANNEL_NAME                       "channel_name"
644 #define DB_FIELD_PVR_CHANNEL_NUM                        "channel_num"
645 #define DB_FIELD_PVR_PROGRAM_TITLE                      "program_title"
646 #define DB_FIELD_PVR_PROGRAM_NUM                        "program_num"
647 #define DB_FIELD_PVR_PROGRAM_CRID                               "program_crid"
648 #define DB_FIELD_PVR_GUIDANCE                                   "guidance"
649 #define DB_FIELD_PVR_SYNOPSIS                                   "synopsis"
650 #define DB_FIELD_PVR_GENRE                                              "genre"
651 #define DB_FIELD_PVR_LANGUAGE                                   "language"
652 #define DB_FIELD_PVR_EMBARGO_TIME                               "embargo_time"
653 #define DB_FIELD_PVR_EXPIRY_TIME                                "expiry_time"
654 #define DB_FIELD_PVR_START_TIME                         "start_time"
655 #define DB_FIELD_PVR_PROGRAM_START_TIME         "program_start_time"
656 #define DB_FIELD_PVR_PROGRAM_END_TIME           "program_end_time"
657 #define DB_FIELD_PVR_PROGRAM_DATE                       "program_date"
658 #define DB_FIELD_PVR_PARENTAL_RATING                    "parental_rating"
659 #define DB_FIELD_PVR_TIMER_RECORD                               "timer_record"
660 #define DB_FIELD_PVR_SERIES_RECORD                              "series_record"
661 #define DB_FIELD_PVR_HD                                                 "hd"
662 #define DB_FIELD_PVR_SUBTITLE                                   "subtitle"
663 #define DB_FIELD_PVR_TTX                                                "ttx"
664 #define DB_FIELD_PVR_AD                                                 "ad"
665 #define DB_FIELD_PVR_HARDOF_HEARINGRADIO        "hard_of_hearing_radio"
666 #define DB_FIELD_PVR_DATA_SERVICE                               "data_service"
667 #define DB_FIELD_PVR_CONTENT_LOCK                               "content_lock"
668 #define DB_FIELD_PVR_CONTENT_WATCH                      "content_watch"
669 #define DB_FIELD_PVR_HAS_AUDIO_ONLY                     "has_audio_only"
670 #define DB_FIELD_PVR_IS_LOCAL_RECORD                    "is_local_record"
671 #define DB_FIELD_PVR_RESOLUTION                         "resolution"
672 #define DB_FIELD_PVR_ASPECTRATIO                                "aspectratio"
673 #define DB_FIELD_PVR_MODIFIED_MONTH                     "modified_month"
674 #define DB_FIELD_PVR_MODIFIED_DATE                      "modified_date"
675 #define DB_FIELD_PVR_SPORTS_TYPE                                "sports_type"
676 #define DB_FIELD_PVR_GUIDANCE_LENGTH                    "guidance_length"
677 #define DB_FIELD_PVR_TVMODE                                             "tvmode"
678 #define DB_FIELD_PVR_PLAY_COUNT                                 "play_count"
679 #define DB_FIELD_PVR_PRIVATE_DATA               "private_data"
680
681 /* DB fiedl for UHD */
682 #define DB_FIELD_UHD_CONTENT_TITLE              "content_title"
683 #define DB_FIELD_UHD_RELEASE_DATE                       "release_date"
684 #define DB_FIELD_UHD_SUB_TYPE                   "sub_type"
685 #define DB_FIELD_UHD_FILE_NAME                  "file_name"
686 #define DB_FIELD_UHD_PLAYED_COUNT                       "played_count"
687
688 /* DB Query Keyword */
689 #define QUERY_KEYWORD_AND "AND"
690 #define QUERY_KEYWORD_OR "OR"
691 #define QUERY_KEYWORD_ORDER_BY "ORDER BY "
692 #define QUERY_KEYWORD_LIMIT "limit"
693 #define QUERY_KEYWORD_DESC "DESC"
694 #define QUERY_KEYWORD_SPACE " "
695 #define QUERY_KEYWORD_OPEN_BRACKET "("
696 #define QUERY_KEYWORD_BRACKET ")"
697 #define QUERY_KEYWORD_COLLATE "COLLATE "
698
699 /* DB TABLE JOIN */
700 /*#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) " */
701 #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 "
702 #define BOOKMARK_MEDIA_JOIN                             "("DB_TABLE_BOOKMARK" AS b INNER JOIN '%s' AS m ON (b.media_uuid = m.media_uuid)) WHERE m.validity=1"
703 #define ALBUM_MEDIA_JOIN                                        "("DB_TABLE_ALBUM" AS a INNER JOIN '%s' AS m ON (a.album_id = m.album_id)) WHERE m.validity=1"
704 #define FACE_MEDIA_JOIN                                         "("DB_TABLE_FACE" AS fa INNER JOIN '%s' AS m ON (fa.media_uuid = m.media_uuid)) WHERE m.validity=1"
705
706 /* Get Group info */
707 #define SELECT_MEDIA_GROUP_AND_COUNT            "SELECT %s, COUNT(*) FROM '%s' WHERE validity=1 "
708
709 /* Get Group List */
710 #define SELECT_ALBUM_LIST                       "SELECT DISTINCT a.album_id, a.name, a.artist, a.album_art FROM "ALBUM_MEDIA_JOIN
711 #define SELECT_MEDIA_GROUP_LIST "SELECT DISTINCT %s FROM '%s' WHERE validity=1 "
712
713 #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
714 #define SELECT_FOLDER_LIST_BY_STORAGE_ID        SELECT_FOLDER_LIST"AND f.storage_uuid='%s' "
715 #define SELECT_TAG_LIST                         "SELECT DISTINCT tag_id, name FROM "DB_VIEW_TAG" WHERE 1 "
716 #define SELECT_PLAYLIST_LIST                    "SELECT DISTINCT playlist_id, name, p_thumbnail_path FROM "DB_VIEW_PLAYLIST" WHERE 1 "
717
718 /* Get Group Count */
719 #define SELECT_ALBUM_COUNT              "SELECT COUNT(DISTINCT a.album_id) FROM "ALBUM_MEDIA_JOIN
720 #define SELECT_FOLDER_COUNT             "SELECT COUNT(DISTINCT f.folder_uuid) FROM "FOLDER_MEDIA_JOIN
721 #define SELECT_FOLDER_COUNT_BY_STORAGE_ID               SELECT_FOLDER_COUNT"AND f.storage_uuid='%s' "
722 #define SELECT_TAG_COUNT                        "SELECT COUNT(DISTINCT tag_id) FROM "DB_VIEW_TAG" WHERE 1 "
723 #define SELECT_PLAYLIST_COUNT           "SELECT COUNT(DISTINCT playlist_id) FROM "DB_VIEW_PLAYLIST" WHERE 1 "
724 #define SELECT_BOOKMARK_COUNT   "SELECT COUNT(DISTINCT b.bookmark_id) FROM "BOOKMARK_MEDIA_JOIN
725 #define SELECT_MEDIA_GROUP_COUNT        "SELECT COUNT(*) FROM ("SELECT_MEDIA_GROUP_LIST
726 /*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)*/
727
728 /* Get Media Count of Group */
729 #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" */
730 #define SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE    "SELECT COUNT(*) FROM '%s' WHERE validity=1 "
731 #define SELECT_MEDIA_COUNT_FROM_ALBUM                   "SELECT COUNT(*) FROM '%s' WHERE validity=1 AND album_id='%d'"
732 #define SELECT_MEDIA_COUNT_FROM_GROUP                   "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP         /*to apply limit condition. */
733 #define SELECT_MEDIA_COUNT_FROM_GROUP_NULL              "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP_NULL    /* to apply limit condition. */
734 #define SELECT_MEDIA_COUNT_FROM_FOLDER                  "SELECT COUNT(*) FROM '%s' WHERE validity=1 AND folder_uuid='%q'"
735 #define SELECT_MEDIA_COUNT_FROM_STORAGE                 "SELECT COUNT(*) FROM '%s' WHERE validity=1 AND storage_uuid='%q'"
736 #define SELECT_MEDIA_COUNT_FROM_TAG                             "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE (tag_id=%d AND media_count>0) "
737 #define SELECT_MEDIA_COUNT_FROM_PLAYLIST                        "SELECT COUNT(*) FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and media_count>0) "
738
739 /* Get Group Info by Group ID*/
740 #define SELECT_ALBUM_FROM_ALBUM         "SELECT * FROM "DB_TABLE_ALBUM" WHERE album_id=%d"
741 #define SELECT_FOLDER_FROM_FOLDER               "SELECT * FROM "DB_TABLE_FOLDER" WHERE folder_uuid='%s'"
742 #define SELECT_FOLDER_BY_PATH                   "SELECT * FROM "DB_TABLE_FOLDER" WHERE path='%q'"
743 #define SELECT_PLAYLIST_FROM_PLAYLIST   "SELECT * FROM "DB_TABLE_PLAYLIST" WHERE playlist_id=%d"
744 #define SELECT_TAG_FROM_TAG                     "SELECT * FROM "DB_TABLE_TAG" WHERE tag_id=%d"
745 #define SELECT_TAG_BY_NAME                              "SELECT * FROM "DB_TABLE_TAG" WHERE name='%q'"
746
747 /* Tag info*/
748 #define INSERT_TAG_TO_TAG                                               "INSERT INTO "DB_TABLE_TAG" (name) VALUES (%Q)"
749 #define REMOVE_TAG_ITEM_FROM_TAG_MAP            "DELETE FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d AND media_uuid='%q';"
750 #define UPDATE_TAG_NAME_FROM_TAG                        "UPDATE "DB_TABLE_TAG" SET name='%q' WHERE tag_id=%d;"
751 #define SELECT_TAG_COUNT_BY_MEDIA_ID                    "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE media_uuid = '%s'"
752 #define SELECT_TAG_LIST_BY_MEDIA_ID                             "SELECT tag_id, name FROM "DB_VIEW_TAG" WHERE media_uuid = '%s'"
753
754 /* Get Media list of Group */
755 #ifdef _USE_SENIOR_MODE
756 #define MEDIA_INFO_ITEM "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, thumbnail_path, description, \
757                                                         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"
758 #else
759 #define MEDIA_INFO_ITEM "media_uuid, path, file_name, media_type, mime_type, size, added_time, modified_time, thumbnail_path, description, \
760                                                         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"
761 #endif
762
763 /*Folder info*/
764 #define UPDATE_FOLDER_ORDER                                     "UPDATE "DB_TABLE_FOLDER" SET folder_order=%d WHERE folder_uuid=%Q"
765 #define SELECT_FOLDER_ID_BY_PATH                                "SELECT folder_uuid FROM "DB_TABLE_FOLDER" WHERE path = '%s'"
766
767 /* Playlist Info */
768 #define INSERT_PLAYLIST_TO_PLAYLIST                                             "INSERT INTO "DB_TABLE_PLAYLIST" (name) VALUES (%Q)"
769 #define UPDATE_PLAYLIST_NAME_FROM_PLAYLIST                      "UPDATE "DB_TABLE_PLAYLIST" SET name='%q' WHERE playlist_id=%d;"
770 #define UPDATE_PLAYLIST_THUMBNAIL_FROM_PLAYLIST         "UPDATE "DB_TABLE_PLAYLIST" SET thumbnail_path='%q' WHERE playlist_id=%d;"
771 #define SELECT_PLAYLIST_ID_FROM_PLAYLIST                                "SELECT playlist_id FROM "DB_TABLE_PLAYLIST" WHERE name='%q'"
772 #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) "
773 #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) "
774 #define SELECT_PLAY_ORDER_FROM_PLAYLIST_VIEW                    "SELECT play_order FROM "DB_VIEW_PLAYLIST" WHERE playlist_id=%d and pm_id=%d"
775 #define SELECT_MAX_PLAY_ORDER_FROM_PLAYLIST_VIEW        "SELECT MAX(play_order) FROM "DB_VIEW_PLAYLIST" WHERE playlist_id=%d"
776 #define REMOVE_PLAYLIST_ITEM_FROM_PLAYLIST_MAP          "DELETE FROM "DB_TABLE_PLAYLIST_MAP" WHERE playlist_id=%d AND _id=%d;"
777 #define UPDATE_PLAYLIST_ORDER_FROM_PLAYLIST_MAP         "UPDATE "DB_TABLE_PLAYLIST_MAP" SET play_order=%d WHERE playlist_id=%d AND _id=%d;"
778
779 /* Bookmark */
780 #define INSERT_BOOKMARK_TO_BOOKMARK                     "INSERT INTO "DB_TABLE_BOOKMARK" (media_uuid, marked_time, thumbnail_path, name) VALUES ('%q', '%d', %Q, %Q)"
781 #define SELECT_BOOKMARK_COUNT_BY_MEDIA_ID               "SELECT COUNT(*) FROM "BOOKMARK_MEDIA_JOIN" AND b.media_uuid='%s'"
782 #define SELECT_BOOKMARK_LIST                                            "SELECT b.bookmark_id, b.media_uuid, b.marked_time, b.thumbnail_path, b.name FROM "BOOKMARK_MEDIA_JOIN
783 #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'"
784 #define SELECT_BOOKMARK_ID_FROM_BOOKMARK               "SELECT bookmark_id FROM "DB_TABLE_BOOKMARK" WHERE media_uuid='%s' AND marked_time=%d"
785
786 #define UPDATE_BOOKMARK_FROM_BOOKMARK           "UPDATE "DB_TABLE_BOOKMARK" SET name=%Q WHERE bookmark_id=%d;"
787
788 /* Update Meta*/
789 #define UPDATE_AV_META_FROM_MEDIA       "UPDATE '%s' SET played_count=%d, last_played_time=%d, last_played_position=%d WHERE media_uuid='%q'"
790 #define UPDATE_IMAGE_META_FROM_MEDIA    "UPDATE '%s' SET orientation=%d WHERE media_uuid='%q'"
791
792 #define UPDATE_VIDEO_MM_DATA_FROM_MEDIA         "UPDATE '%s' SET bitrate=%d, duration=%d, width=%d, height=%d WHERE media_uuid='%q'"
793 #define UPDATE_AUDIO_MM_DATA_FROM_MEDIA         "UPDATE '%s' SET duration=%d, bitrate=%d, bitpersample=%d, samplerate=%d, channel=%d WHERE media_uuid='%q'"
794 #define UPDATE_IMAGE_MM_DATA_FROM_MEDIA         "UPDATE '%s' SET width=%d, height=%d WHERE media_uuid='%q'"
795 #define SELECT_VIDEO_MM_DATA_FROM_MEDIA         "SELECT bitrate, duration, width, height FROM '%s' WHERE media_uuid='%q'"
796 #define SELECT_AUDIO_MM_DATA_FROM_MEDIA         "SELECT duration, bitrate, bitpersample, samplerate, channel FROM '%s' WHERE media_uuid='%q'"
797 #define SELECT_IMAGE_MM_DATA_FROM_MEDIA         "SELECT width, height FROM '%s' WHERE media_uuid='%q'"
798
799 #define SELECT_MEDIA_ITEM                                       "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1"
800 #define SELECT_MEDIA_FROM_MEDIA                 "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND media_uuid='%s'"
801 #define SELECT_MEDIA_BY_PATH                            "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND path='%q'"
802 #define SELECT_MEDIA_FROM_ALBUM                 "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND album_id=%d"
803 #define SELECT_MEDIA_FROM_GROUP                 "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND %s='%q'"
804 #define SELECT_MEDIA_FROM_GROUP_NULL    "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND %s IS NULL"
805 #define SELECT_MEDIA_FROM_FOLDER                        "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND folder_uuid='%s'"
806 #define SELECT_MEDIA_FROM_STORAGE               "SELECT "MEDIA_INFO_ITEM" FROM '%s' WHERE validity=1 AND storage_uuid='%s'"
807 #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"
808 #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"
809 #define SELECT_MEDIA_PATH_BY_ID                 "SELECT path FROM "DB_TABLE_MEDIA_VIEW" WHERE media_uuid='%q'"
810 #define SELECT_MEDIA_STORAGE_ID_BY_ID           "SELECT storage_uuid FROM "DB_TABLE_MEDIA_VIEW" WHERE media_uuid='%q'"
811
812 /* Delete */
813 #define DELETE_MEDIA_FROM_MEDIA_BATCH   "DELETE FROM  '%s' WHERE %s AND storage_type = %d"
814 #define DELETE_PLAYLIST_FROM_PLAYLIST           "DELETE FROM "DB_TABLE_PLAYLIST" WHERE playlist_id=%d"
815 #define DELETE_TAG_FROM_TAG                             "DELETE FROM "DB_TABLE_TAG" WHERE tag_id=%d"
816 #define DELETE_BOOKMARK_FROM_BOOKMARK   "DELETE FROM "DB_TABLE_BOOKMARK" WHERE bookmark_id=%d"
817
818 /*For batch remove*/
819 #define SELECT_STORAGE_BY_FILTER        "SELECT DISTINCT storage_uuid, storage_type FROM "DB_TABLE_MEDIA_VIEW" WHERE %s"
820 #define SELECT_THUMBNAIL_BY_FILTER      "SELECT DISTINCT thumbnail_path FROM '%s' WHERE %s AND storage_type = %d"
821
822 /* Storage*/
823 #define SELECT_STORAGE_COUNT                            "SELECT COUNT(*) FROM "DB_TABLE_STORAGE" WHERE validity=1"
824 #define SELECT_STORAGE_LIST                                     "SELECT storage_uuid, storage_path, storage_type FROM "DB_TABLE_STORAGE" WHERE validity=1"
825 #define SELECT_STORAGE_INFO_FROM_STORAGE        "SELECT storage_uuid, storage_path, storage_type FROM "DB_TABLE_STORAGE" WHERE validity=1 AND storage_uuid='%s'"
826
827 /* Face */
828 #define DELETE_FACE_FROM_FACE                   "DELETE FROM "DB_TABLE_FACE" WHERE face_id=%d"
829 #define INSERT_FACE_TO_FACE                             "INSERT INTO "DB_TABLE_FACE" (media_uuid, face_rect_x , face_rect_y, face_rect_w, face_rect_h, orientation, face_tag) VALUES ('%q', %d, %d, %d, %d, %d, %Q);"
830 #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_id=%d"
831 #define SELECT_MEDIA_COUNT_FROM_MEDIA_BY_ID             "SELECT COUNT(*) FROM "DB_TABLE_MEDIA_VIEW" WHERE media_uuid='%q' AND validity=1"
832 #define SELECT_FACE_COUNT                                       "SELECT COUNT(*) FROM "FACE_MEDIA_JOIN
833 #define SELECT_FACE_COUNT_BY_MEDIA_ID           "SELECT COUNT(*) FROM "FACE_MEDIA_JOIN" AND fa.media_uuid='%s'"
834 #define SELECT_FACE_LIST                                                "SELECT fa.face_id, 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
835 #define SELECT_FACE_LIST_BY_MEDIA_ID            "SELECT fa.face_id, 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'"
836 #define SELECT_FACE_PATH_FROM_MEDIA             "SELECT path FROM "DB_TABLE_MEDIA_VIEW" media_uuid='%s'"
837 #define SELECT_MEDIA_FROM_FACE                  "SELECT media_uuid FROM "DB_TABLE_FACE" WHERE face_id=%d"
838 #define UPDATE_MEDIA_INFO_IN_FACE_SCAN_LIST     "UPDATE "DB_TABLE_FACE_SCAN_LIST" SET modified_time = 0 WHERE media_uuid='%q'"
839 #define SELECT_FACE_ID                  "SELECT face_id FROM "DB_TABLE_FACE" WHERE media_uuid='%q' AND face_rect_x=%d AND face_rect_y=%d AND face_rect_w=%d AND face_rect_h=%d AND orientation=%d"
840
841 #define DEFAULT_MEDIA_STORAGE_ID                        "media"
842
843 #define SELECT_VALID_STORAGE_FROM_PVR   "WHERE storage_uuid IN (SELECT storage_uuid FROM "DB_TABLE_STORAGE" WHERE validity=1)"
844 #define SELECT_PVR_COUNT                                        "SELECT COUNT(*) FROM "DB_TABLE_PVR" "SELECT_VALID_STORAGE_FROM_PVR
845 #define SELECT_PVR_LIST                                 "SELECT * FROM "DB_TABLE_PVR" "SELECT_VALID_STORAGE_FROM_PVR
846 #define SELECT_PVR_COUNT_BY_STORAGE_ID  SELECT_PVR_COUNT" AND storage_uuid='%s'"
847 #define SELECT_PVR_LIST_BY_STORAGE_ID           SELECT_PVR_LIST" AND storage_uuid='%s'"
848 #define SELECT_PVR_FROM_PVR                             "SELECT * FROM "DB_TABLE_PVR" WHERE media_uuid='%q'"
849 #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'"
850 #define UPDATE_PVR_LOCAL_RECORD_PVR             "UPDATE "DB_TABLE_PVR" SET is_local_record=%d WHERE path='%q' AND storage_uuid='%q'"
851
852 #define SELECT_PVR_GROUP_LIST                                           "SELECT DISTINCT %s FROM "DB_TABLE_PVR" "SELECT_VALID_STORAGE_FROM_PVR
853 #define SELECT_PVR_GROUP_LIST_BY_STORAGE_ID             "SELECT DISTINCT %s FROM "DB_TABLE_PVR" WHERE storage_uuid='%s'"
854 #define SELECT_PVR_GROUP_COUNT                                  "SELECT COUNT(*) FROM ("SELECT_PVR_GROUP_LIST
855 #define SELECT_PVR_GROUP_COUNT_BY_STORAGE_ID    "SELECT COUNT(*) FROM ("SELECT_PVR_GROUP_LIST_BY_STORAGE_ID
856 #define SELECT_PVR_FROM_GROUP                                           "SELECT * FROM "DB_TABLE_PVR" "SELECT_VALID_STORAGE_FROM_PVR" AND %s='%q'"
857 #define SELECT_PVR_FROM_GROUP_BY_STORAGE_ID             "SELECT * FROM "DB_TABLE_PVR" WHERE storage_uuid='%s' AND %s='%q'"
858 #define SELECT_PVR_COUNT_FROM_GROUP                             "SELECT COUNT(*) FROM ("SELECT_PVR_FROM_GROUP
859 #define SELECT_PVR_COUNT_FROM_GROUP_BY_STORAGE_ID       "SELECT COUNT(*) FROM ("SELECT_PVR_FROM_GROUP_BY_STORAGE_ID
860 #define SELECT_PVR_FROM_GROUP_NULL                                      "SELECT * FROM "DB_TABLE_PVR" "SELECT_VALID_STORAGE_FROM_PVR" AND %s IS NULL"
861 #define SELECT_PVR_FROM_GROUP_NULL_BY_STORAGE_ID        "SELECT * FROM "DB_TABLE_PVR" WHERE storage_uuid='%s' AND %s IS NULL"
862 #define SELECT_PVR_COUNT_FROM_GROUP_NULL                        "SELECT COUNT(*) FROM ("SELECT_PVR_FROM_GROUP_NULL
863 #define SELECT_PVR_COUNT_FROM_GROUP_NULL_BY_STORAGE_ID  "SELECT COUNT(*) FROM ("SELECT_PVR_FROM_GROUP_NULL_BY_STORAGE_ID
864 #define SELECT_PVR_GROUP_AND_COUNT_BY_STORAGE_ID                "SELECT %s, COUNT(*) FROM "DB_TABLE_PVR" WHERE storage_uuid='%s'"
865 #define SELECT_PVR_GROUP_AND_COUNT                                              "SELECT %s, COUNT(*) FROM "DB_TABLE_PVR" "SELECT_VALID_STORAGE_FROM_PVR
866
867 #define SELECT_VALID_STORAGE_FROM_UHD   "WHERE storage_uuid IN (SELECT storage_uuid FROM "DB_TABLE_STORAGE" WHERE validity=1)"
868 #define SELECT_UHD_GROUP_LIST                                           "SELECT DISTINCT %s FROM "DB_TABLE_UHD" "SELECT_VALID_STORAGE_FROM_UHD
869 #define SELECT_UHD_GROUP_LIST_BY_STORAGE_ID             "SELECT DISTINCT %s FROM "DB_TABLE_UHD" WHERE storage_uuid='%s'"
870 #define SELECT_UHD_GROUP_COUNT                                  "SELECT COUNT(*) FROM ("SELECT_UHD_GROUP_LIST
871 #define SELECT_UHD_GROUP_COUNT_BY_STORAGE_ID    "SELECT COUNT(*) FROM ("SELECT_UHD_GROUP_LIST_BY_STORAGE_ID
872 #define SELECT_UHD_FROM_GROUP                                           "SELECT * FROM "DB_TABLE_UHD" "SELECT_VALID_STORAGE_FROM_UHD" AND %s='%q'"
873 #define SELECT_UHD_FROM_GROUP_BY_STORAGE_ID             "SELECT * FROM "DB_TABLE_UHD" WHERE storage_uuid='%s' AND %s='%q'"
874 #define SELECT_UHD_COUNT_FROM_GROUP                             "SELECT COUNT(*) FROM ("SELECT_UHD_FROM_GROUP
875 #define SELECT_UHD_COUNT_FROM_GROUP_BY_STORAGE_ID       "SELECT COUNT(*) FROM ("SELECT_UHD_FROM_GROUP_BY_STORAGE_ID
876 #define SELECT_UHD_FROM_GROUP_NULL                                      "SELECT * FROM "DB_TABLE_UHD" "SELECT_VALID_STORAGE_FROM_UHD" AND %s IS NULL"
877 #define SELECT_UHD_FROM_GROUP_NULL_BY_STORAGE_ID        "SELECT * FROM "DB_TABLE_UHD" WHERE storage_uuid='%s' AND %s IS NULL"
878 #define SELECT_UHD_COUNT_FROM_GROUP_NULL                        "SELECT COUNT(*) FROM ("SELECT_UHD_FROM_GROUP_NULL
879 #define SELECT_UHD_COUNT_FROM_GROUP_NULL_BY_STORAGE_ID  "SELECT COUNT(*) FROM ("SELECT_UHD_FROM_GROUP_NULL_BY_STORAGE_ID
880 #define SELECT_UHD_GROUP_AND_COUNT_BY_STORAGE_ID                "SELECT %s, COUNT(*) FROM "DB_TABLE_UHD" WHERE storage_uuid='%s'"
881 #define SELECT_UHD_GROUP_AND_COUNT                                              "SELECT %s, COUNT(*) FROM "DB_TABLE_UHD" "SELECT_VALID_STORAGE_FROM_UHD
882
883 #define SELECT_UHD_COUNT                                        "SELECT COUNT(*) FROM "DB_TABLE_UHD" "SELECT_VALID_STORAGE_FROM_UHD
884 #define SELECT_UHD_COUNT_BY_STORAGE_ID  SELECT_UHD_COUNT" AND storage_uuid='%s'"
885 #define SELECT_UHD_LIST                                 "SELECT * FROM "DB_TABLE_UHD" "SELECT_VALID_STORAGE_FROM_UHD
886 #define SELECT_UHD_LIST_BY_STORAGE_ID   SELECT_UHD_LIST" AND storage_uuid='%s'"
887 #define SELECT_UHD_FROM_UHD                             "SELECT * FROM "DB_TABLE_UHD" WHERE media_uuid='%q'"
888 #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'"
889
890 int _content_query_prepare(sqlite3_stmt **stmt, char *select_query, char *condition_query, char *option_query);
891 int _content_error_capi(int type, int cotent_error);
892 int _content_query_sql(char *query_str);
893 MediaSvcHandle* _content_get_db_handle(void);
894 uid_t _content_get_uid(void);
895 attribute_h _content_get_attirbute_handle(void);
896 attribute_h _content_get_alias_attirbute_handle(void);
897 int _media_info_get_media_info_from_db(const char *path, const char *storage_id, media_info_h media);
898 void _media_info_item_get_detail(sqlite3_stmt *stmt, media_info_h media);
899 int _media_db_get_group_count(filter_h filter, group_list_e group_type, int *group_count);
900 int _media_db_get_media_group_count(media_group_e group, filter_h filter, int *group_count);
901 int _media_db_get_media_group(media_group_e group, filter_h filter, media_group_cb callback, void *user_data);
902 int _media_db_get_media_group_and_count(media_group_e group, filter_h filter, media_group_and_count_cb callback, void *user_data);
903 int _media_db_get_album(filter_h filter, media_album_cb callback, void *user_data);
904 int _media_db_get_folder(filter_h filter, media_folder_cb callback, void *user_data);
905 int _media_db_get_playlist(filter_h filter, media_playlist_cb callback, void *user_data);
906 int _media_db_get_playlist_item(int playlist_id, filter_h filter, playlist_member_cb callback, void *user_data);
907 int _media_db_get_tag(const char *media_id, filter_h filter, media_tag_cb callback, void *user_data);
908 int _media_db_get_bookmark(const char *media_id, filter_h filter, media_bookmark_cb callback, void *user_data);
909 int _media_db_get_face(const char *media_id, filter_h filter, media_face_cb callback, void *user_data);
910 int _media_db_get_group_item_count_by_id(int group_id, filter_h filter, group_list_e group_type, int *item_count);
911 int _media_db_get_group_item_count(const char *group_name, filter_h filter, group_list_e group_type, int *item_count);
912 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);
913 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);
914 #ifdef _USE_SENIOR_MODE
915 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);
916 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);
917 #endif
918 int _media_db_get_media_group_item_count(const char *group_name, filter_h filter, media_group_e group, int *item_count);
919 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);
920 int _media_db_get_storage(filter_h filter, media_storage_cb callback, void *user_data);
921 int _media_db_get_storage_id_by_media_id(const char *media_id, char *storage_id);
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_pvr(filter_h filter, media_pvr_cb callback, void *user_data);
925 void _media_pvr_item_get_detail(sqlite3_stmt* stmt, media_pvr_h pvr);
926 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);
927 int _media_db_get_uhd(filter_h filter, media_uhd_cb callback, void *user_data);
928 void _media_uhd_item_get_detail(sqlite3_stmt* stmt, media_uhd_h uhd);
929
930 /**
931  * @internal
932  * @brief Creates a media filter attribute handle.
933  * @details This function creates a media filter attribute handle. The handle can be
934  * used to convert to attributes of database from attributes of user.
935  * @remarks The @a handle must be released with media_filter_attribute_destory() by you.
936  * @param[out] filter A handle to media filter attribute
937  * @return 0 on success, otherwise a negative error value.
938  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
939  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
940  * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory
941  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
942  * @see media_filter_attribute_destory()
943  *
944  */
945 int _media_filter_attribute_create(attribute_h *attr);
946
947 /**
948  * @internal
949  * @brief Add the attributes to the handle.
950  * @details This function add the attribute to handle.
951  * @param[in] filter The handle to media filter attribute
952  * @param[in] user_attr The user attribute
953  * @param[in] platform_attr The platform attribute
954  * @return 0 on success, otherwise a negative error value.
955  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
956  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
957  * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory
958  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
959  * @see media_filter_attribute_remove()
960  *
961  */
962 int _media_filter_attribute_add(attribute_h atrr, const char *user_attr, const char *platform_attr);
963
964 /**
965  * @internal
966  * @brief Destroys a media filter attribute handle.
967  * @details The function frees all resources related to the media filter attribute handle. The filter attribute
968  * handle no longer can be used to perform any operation. A new handle
969  * has to be created before the next usage.
970  *
971  * @param[in] filter The handle to media filter attribute
972  * @return 0 on success, otherwise a negative error value.
973  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
974  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
975  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
976  * @see media_filter_create()
977  *
978  */
979 int _media_filter_attribute_destory(attribute_h attr);
980
981 /**
982  * @internal
983  * @brief Replace to platform attributes from user attributes.
984  * @details This function replace to platform attributes from user attributes to generate the WHERE clause
985  * @param[in] filter The handle to media filter attribute
986  * @param[in] user_attr The user attribute
987  * @param[in] platform_attr The platform attribute
988  * @return 0 on success, otherwise a negative error value.
989  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
990  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
991  * @retval #MEDIA_CONTENT_ERROR_OUT_OF_MEMORY Out of memory
992  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
993  * @see media_filter_attribute_create()
994  * @see media_filter_attribute_destory()
995  *
996  */
997 int _media_filter_attribute_generate(attribute_h attr, filter_h filter, char **generated_condition);
998
999 /**
1000  * @internal
1001  * @brief Replace to platform attributes from user attributes.
1002  * @details This function replace to platform attributes from user attributes to generate the WHERE clause
1003  * @param[in] filter The handle to media filter attribute
1004  * @param[in] attr The attribute
1005  * @param[in] generated_option The handle to generated option
1006  * @return 0 on success, otherwise a negative error value.
1007  * @retval #MEDIA_CONTENT_ERROR_NONE Successful
1008  * @retval #MEDIA_CONTENT_ERROR_INVALID_PARAMETER Invalid parameter
1009  * @retval #MEDIA_CONTENT_ERROR_DB_FAILED Filed DB
1010  * @retval #MEDIA_CONTENT_ERROR_PERMISSION_DENIED Permission denied
1011  * @see media_filter_attribute_create()
1012  * @see media_filter_attribute_destory()
1013  *
1014  */
1015
1016 int _media_filter_attribute_option_generate(attribute_h attr, filter_h filter, char **generated_option);
1017
1018 int _media_filter_attribute_option_generate_with_full_query(attribute_h attr, filter_h filter, char **generated_option);
1019
1020 GMutex* _content_get_db_mutex(void);
1021
1022
1023 #define FONT_COLOR_RESET    "\033[0m"
1024 #define FONT_COLOR_RED      "\033[31m"
1025 #define FONT_COLOR_GREEN    "\033[32m"
1026 #define FONT_COLOR_YELLOW   "\033[33m"
1027 #define FONT_COLOR_BLUE     "\033[34m"
1028 #define FONT_COLOR_PURPLE   "\033[35m"
1029 #define FONT_COLOR_CYAN     "\033[36m"
1030 #define FONT_COLOR_GRAY     "\033[37m"
1031
1032 #define media_content_gettid() syscall(__NR_gettid)
1033
1034 #define media_content_retv_if(expr, val) do { \
1035                         if (expr) { \
1036                                 LOGE(FONT_COLOR_RED"[%ld]"FONT_COLOR_RESET, media_content_gettid());    \
1037                                 return (val); \
1038                         } \
1039                 } while (0)
1040
1041 #define media_content_retvm_if(expr, val, fmt, arg...) do { \
1042                         if (expr) { \
1043                                 LOGE(FONT_COLOR_RED"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg);     \
1044                                 return (val); \
1045                         } \
1046                 } while (0)
1047
1048 #define media_content_warn(fmt, arg...) do { \
1049                         LOGW(FONT_COLOR_GREEN"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg);     \
1050                 } while (0)
1051
1052 #define media_content_debug(fmt, arg...) do { \
1053                         LOGD(FONT_COLOR_RESET"[%ld]"fmt"", media_content_gettid(), ##arg);     \
1054                 } while (0)
1055
1056 #define media_content_info(fmt, arg...) do { \
1057                         LOGI(FONT_COLOR_GREEN"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg);     \
1058                 } while (0)
1059
1060 #define media_content_error(fmt, arg...) do { \
1061                         LOGE(FONT_COLOR_RED"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg);     \
1062                 } while (0)
1063
1064 #define media_content_debug_func() do { \
1065                         LOGD(FONT_COLOR_RESET"[%ld]", media_content_gettid());     \
1066                 } while (0)
1067
1068 #define media_content_sec_debug(fmt, arg...) do { \
1069                         SECURE_LOGD(FONT_COLOR_CYAN"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg);     \
1070                 } while (0)
1071
1072 #define media_content_sec_warn(fmt, arg...) do { \
1073                         SECURE_LOGW(FONT_COLOR_RED"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg);     \
1074                 } while (0)
1075
1076 #define media_content_sec_error(fmt, arg...) do { \
1077                         SECURE_LOGE(FONT_COLOR_RED"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg);     \
1078                 } while (0)
1079
1080 #define ERR_BUF_LENGTH 256
1081 #define media_content_stderror(fmt) do { \
1082                         char media_content_stderror_buf[ERR_BUF_LENGTH] = {0, }; \
1083                         strerror_r(errno, media_content_stderror_buf, ERR_BUF_LENGTH);  \
1084                         LOGE(FONT_COLOR_RED fmt" : STANDARD ERROR [%s]"FONT_COLOR_RESET, media_content_stderror_buf); \
1085                 } while (0)
1086
1087 #ifdef __cplusplus
1088 }
1089 #endif /* __cplusplus */
1090 #endif /*__TIZEN_MEDIA_INFO_PRIVATE_H__*/