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