* @brief This file contains the media info API and related structure and enumeration. \n
* Description of the audio, video,image content involves: album, artist, album_artist, genre and description tags. \n
* Parameters of the recording are also supported, as: format, bitrate, duration, size etc. \n
-* Defenitions of media DB fields and tables, operations with media data relating to DB and handling with media filter attributes.
+* Definitions of media DB fields and tables, operations with media data relating to DB and handling with media filter attributes.
*/
#define LOG_TAG "CAPI_CONTENT_MEDIA_CONTENT"
-#define SAFE_STRLCPY(dst, src, n) ((g_strlcpy(dst, src, n) < n) ? TRUE : FALSE)
+#define SAFE_STRLCPY(dst, src, n) g_strlcpy(dst, src, n);
#define SAFE_STRLCAT(dst, src, n) g_strlcat(dst, src, n);
#define SAFE_FREE(src) {if (src) {free(src); src = NULL; } }
#define STRING_VALID(str) ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
#define MAX_QUERY_SIZE 4096
#define MAX_PATH_LEN 4096
#define DEFAULT_QUERY_SIZE 1024
-#define COLLATE_STR_SIZE 32
#define MEDIA_CONTENT_UUID_SIZE 36
#define BATCH_REQUEST_MAX 300
MEDIA_INFO_SAMPLERATE,
MEDIA_INFO_CHANNEL,
MEDIA_INFO_TIMELINE,
- MEDIA_INFO_SYNC_STATUS,
MEDIA_INFO_STORAGE_UUID,
MEDIA_INFO_IS_360,
MEDIA_INFO_ITEM_MAX,
typedef struct {
char *media_id;
+ char *author;
+ char *publisher;
+ char *date;
+ char *subject;
+} book_meta_s;
+
+typedef struct {
+ char *media_id;
char *file_path;
char *display_name;
media_content_type_e media_type;
int is_drm;
int storage_type;
char *storage_uuid;
- int sync_status;
unsigned int request_id;
unsigned int face_request_id;
int is_360;
image_meta_s *image_meta;
video_meta_s *video_meta;
audio_meta_s *audio_meta;
+ book_meta_s *book_meta;
} media_info_s;
typedef struct {
#define DB_FIELD_MEDIA_LATITUDE "media_latitude"
#define DB_FIELD_MEDIA_ALTITUDE "media_altitude"
-/* DB Query Keyword */
-#define QUERY_KEYWORD_AND "AND"
-#define QUERY_KEYWORD_OR "OR"
-#define QUERY_KEYWORD_ORDER_BY "ORDER BY "
-#define QUERY_KEYWORD_LIMIT "limit"
-#define QUERY_KEYWORD_DESC "DESC"
-#define QUERY_KEYWORD_SPACE " "
-#define QUERY_KEYWORD_OPEN_BRACKET "("
-#define QUERY_KEYWORD_BRACKET ")"
-#define QUERY_KEYWORD_COLLATE " COLLATE "
-
/* DB TABLE JOIN */
#define FOLDER_MEDIA_JOIN DB_TABLE_FOLDER" NATURAL LEFT OUTER JOIN "DB_TABLE_MEDIA" WHERE validity IN (1, 2) "
#define BOOKMARK_MEDIA_JOIN DB_TABLE_BOOKMARK" NATURAL JOIN "DB_TABLE_MEDIA" WHERE validity IN (1, 2) "
#define SELECT_PLAYLIST_COUNT "SELECT COUNT(DISTINCT playlist_id) FROM "DB_VIEW_PLAYLIST" WHERE 1 "
#define SELECT_BOOKMARK_COUNT "SELECT COUNT(*) FROM "BOOKMARK_MEDIA_JOIN
#define SELECT_BOOKMARK_COUNT_BY_STORAGE_ID SELECT_BOOKMARK_COUNT"AND storage_uuid='%s' "
-#define SELECT_MEDIA_GROUP_COUNT "SELECT COUNT(*) FROM ("SELECT_MEDIA_GROUP_LIST
+#define SELECT_MEDIA_GROUP_COUNT "SELECT COUNT(DISTINCT %s) + COUNT(DISTINCT CASE WHEN %s IS NULL THEN 1 END) AS COUNT FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) "
#define SELECT_MEDIA_GROUP_COUNT_BY_STORAGE_ID SELECT_MEDIA_GROUP_COUNT"AND storage_uuid='%s' "
/*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)*/
/* Get Media Count of Group */
-#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" */
+#define SELECT_MEDIA_COUNT_FROM_MEDIA "SELECT COUNT(*) FROM (SELECT media_id FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) "
+#define SELECT_MEDIA_COUNT_FROM_MEDIA_BY_STORAGE_ID SELECT_MEDIA_COUNT_FROM_MEDIA"AND storage_uuid='%s' "
#define SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) "
#define SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE_BY_STORAGE_ID SELECT_MEDIA_COUNT_FROM_MEDIA_SIMPLE"AND storage_uuid='%s' "
#define SELECT_MEDIA_COUNT_FROM_ALBUM "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) AND album_id='%d' "
#define SELECT_MEDIA_COUNT_FROM_GROUP_BY_STORAGE_ID "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP_BY_STORAGE_ID /*to apply limit condition. */
#define SELECT_MEDIA_COUNT_FROM_GROUP_NULL "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP_NULL /* to apply limit condition. */
#define SELECT_MEDIA_COUNT_FROM_GROUP_NULL_BY_STORAGE_ID "SELECT COUNT(*) FROM ("SELECT_MEDIA_FROM_GROUP_NULL_BY_STORAGE_ID /* to apply limit condition. */
-#define SELECT_MEDIA_COUNT_FROM_FOLDER "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) AND folder_id='%q'"
+#define SELECT_MEDIA_COUNT_FROM_FOLDER "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) AND folder_id='%s'"
#define SELECT_MEDIA_COUNT_FROM_FOLDER_BY_STORAGE_ID SELECT_MEDIA_COUNT_FROM_FOLDER" AND storage_uuid='%s' "
-#define SELECT_MEDIA_COUNT_FROM_STORAGE "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) AND storage_uuid='%q'"
+#define SELECT_MEDIA_COUNT_FROM_STORAGE "SELECT COUNT(*) FROM "DB_TABLE_MEDIA" WHERE validity IN (1, 2) AND storage_uuid='%s'"
#define SELECT_MEDIA_COUNT_FROM_TAG "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE (tag_id=%d AND tag_media_count>0) "
#define SELECT_MEDIA_COUNT_FROM_PLAYLIST "SELECT COUNT(*) FROM "DB_VIEW_PLAYLIST" WHERE (playlist_id=%d and playlist_media_count>0) "
#define REMOVE_TAG_ITEM_FROM_TAG_MAP "DELETE FROM "DB_TABLE_TAG_MAP" WHERE tag_id=%d AND media_id='%q';"
#define UPDATE_TAG_NAME_FROM_TAG "UPDATE "DB_TABLE_TAG" SET tag_name='%q' WHERE tag_id=%d;"
#define SELECT_TAG_COUNT_BY_MEDIA_ID "SELECT COUNT(*) FROM "DB_VIEW_TAG" WHERE media_id = '%s'"
-#define SELECT_TAG_LIST_BY_MEDIA_ID "SELECT tag_id, tag_name FROM "DB_VIEW_TAG" WHERE media_id = '%s'"
+#define SELECT_TAG_LIST_BY_MEDIA_ID "SELECT tag_id, tag_name FROM "DB_VIEW_TAG" WHERE media_id = '%s' "
/* Get Media list of Group */
#define MEDIA_INFO_ITEM "media_id, media_path, media_display_name, media_type, media_mime_type, media_size, media_added_time, media_modified_time, media_thumbnail_path, media_description, \
media_rating, media_favourite, media_is_drm, media_storage_type, media_longitude, media_latitude, media_altitude, exposure_time, fnumber, iso, \
model, media_width, media_height, media_datetaken, media_orientation, media_title, media_album, media_artist, media_album_artist, media_genre, \
media_composer, media_year, media_recorded_date, media_copyright, media_track_num, media_bitrate, media_bitpersample, media_duration, media_samplerate, media_channel, \
- media_timeline, sync_status, storage_uuid, media_360"
+ media_timeline, storage_uuid, media_360"
/* Playlist Info */
#define INSERT_PLAYLIST_TO_PLAYLIST "INSERT INTO "DB_TABLE_PLAYLIST" (playlist_name) VALUES (%Q)"
#define UPDATE_MEDIA_INFO_IN_FACE_SCAN_LIST "UPDATE "DB_TABLE_FACE_SCAN_LIST" SET modified_time = 0 WHERE media_id IN (SELECT media_id FROM "DB_TABLE_FACE" WHERE media_face_id=%d)"
#define SELECT_FACE_ID "SELECT media_face_id FROM "DB_TABLE_FACE" WHERE media_id='%q' AND face_rect_x=%d AND face_rect_y=%d AND face_rect_w=%d AND face_rect_h=%d AND face_orientation=%d"
-int _content_query_prepare(char *select_query, char *condition_query, char *option_query, sqlite3_stmt **stmt);
+int _content_query_prepare(const char *select_query, const char *condition_query, const char *option_query, sqlite3_stmt **stmt);
int _content_get_result(char *query, sqlite3_stmt **stmt);
-int _content_error_capi(int content_error);
+int _content_error_capi(int internal_error);
int _content_query_sql(char *query_str);
sqlite3 * _content_get_db_handle(void);
uid_t _content_get_uid(void);
int _media_db_get_storage(filter_h filter, media_storage_cb callback, void *user_data);
int _media_db_get_storage_id_by_media_id(const char *media_id, char **storage_id);
-int _media_filter_attribute_generate(filter_h filter, char **generated_condition);
-int _media_filter_attribute_option_generate(filter_h filter, char **generated_option);
-int _media_filter_attribute_option_generate_with_full_query(filter_h filter, char **generated_option);
+int _media_filter_build_condition(bool is_full, const char *condition, media_content_collation_e collate_type, char **result);
+int _media_filter_build_option(filter_h filter, char **result);
#define FONT_COLOR_RESET "\033[0m"
#define media_content_gettid() syscall(__NR_gettid)
-#define media_content_retv_if(expr, val) do { \
+#define content_retv_if(expr, val) do { \
if (expr) { \
LOGE(FONT_COLOR_RED"[%ld]"FONT_COLOR_RESET, media_content_gettid()); \
return (val); \
} \
} while (0)
-#define media_content_retvm_if(expr, val, fmt, arg...) do { \
+#define content_retvm_if(expr, val, fmt, arg...) do { \
if (expr) { \
LOGE(FONT_COLOR_RED"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg); \
return (val); \
} \
} while (0)
-#define media_content_warn(fmt, arg...) do { \
+#define content_retip_if_fail(expr) do { \
+ if (!(expr)) { \
+ LOGE(FONT_COLOR_RED"[%ld] Invalid [%s]"FONT_COLOR_RESET, media_content_gettid(), #expr); \
+ return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; \
+ } \
+ } while (0)
+
+#define content_retipm_if_fail(expr, fmt, arg...) do { \
+ if (!(expr)) { \
+ LOGE(FONT_COLOR_RED"[%ld] Cond[%s] value["fmt"]"FONT_COLOR_RESET, media_content_gettid(), #expr, ##arg); \
+ return MEDIA_CONTENT_ERROR_INVALID_PARAMETER; \
+ } \
+ } while (0)
+
+#define content_warn(fmt, arg...) do { \
LOGW(FONT_COLOR_GREEN"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg); \
} while (0)
-#define media_content_debug(fmt, arg...) do { \
+#define content_debug(fmt, arg...) do { \
LOGD(FONT_COLOR_RESET"[%ld]"fmt"", media_content_gettid(), ##arg); \
} while (0)
-#define media_content_info(fmt, arg...) do { \
+#define content_info(fmt, arg...) do { \
LOGI(FONT_COLOR_GREEN"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg); \
} while (0)
-#define media_content_error(fmt, arg...) do { \
+#define content_error(fmt, arg...) do { \
LOGE(FONT_COLOR_RED"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg); \
} while (0)
-#define media_content_debug_func() do { \
- LOGD(FONT_COLOR_RESET"[%ld]", media_content_gettid()); \
- } while (0)
-
-#define media_content_sec_debug(fmt, arg...) do { \
+#define content_sec_debug(fmt, arg...) do { \
SECURE_LOGD(FONT_COLOR_CYAN"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg); \
} while (0)
-#define media_content_sec_warn(fmt, arg...) do { \
- SECURE_LOGW(FONT_COLOR_RED"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg); \
- } while (0)
-
-#define media_content_sec_error(fmt, arg...) do { \
+#define content_sec_error(fmt, arg...) do { \
SECURE_LOGE(FONT_COLOR_RED"[%ld]"fmt""FONT_COLOR_RESET, media_content_gettid(), ##arg); \
} while (0)
#define ERR_BUF_LENGTH 256
-#define media_content_stderror(fmt) do { \
+#define content_stderror(fmt) do { \
char media_content_stderror_buf[ERR_BUF_LENGTH] = {0, }; \
strerror_r(errno, media_content_stderror_buf, ERR_BUF_LENGTH); \
LOGE(FONT_COLOR_RED fmt" : STANDARD ERROR [%s]"FONT_COLOR_RESET, media_content_stderror_buf); \