From 7051b6f8422fdb742bf70077eacfd1249ac21d21 Mon Sep 17 00:00:00 2001 From: Farshid Monhaseri Date: Thu, 2 Jan 2020 21:37:11 +0330 Subject: Add scan-type(audio,video,image,all) to scanner Bug-AGL: SPEC-3096 User can pass 'types' as a request property with 'audio','video', 'image','all' values as a single 'string' value or as an array of 'string' values along 'media_result','subscribe','unsubscribe' verbs to scan or register the events with those scan-types. If the user doesn't provide the 'types' request property, the API will function as before with 'audio' and 'video' scan-types. Change-Id: I8ff49f89e2696f600dfb2935403d8b0c8246c07d Signed-off-by: Farshid Monhaseri --- binding/media-api.c | 113 +++++++++++++++++++++++++++++++++++++++++++++--- binding/media-manager.c | 54 ++++++++++++++++------- binding/media-manager.h | 32 ++++++++++++-- 3 files changed, 175 insertions(+), 24 deletions(-) (limited to 'binding') diff --git a/binding/media-api.c b/binding/media-api.c index d02ad93..05fbba2 100644 --- a/binding/media-api.c +++ b/binding/media-api.c @@ -29,6 +29,72 @@ static afb_event_t media_added_event; static afb_event_t media_removed_event; +static gint get_scan_type(afb_req_t request, json_object *jtype) { + gint ret = 0; + const *stype = NULL; + if(!json_object_is_type(jtype,json_type_string)) { + afb_req_fail(request,"failed", "invalid scan-type type"); + return ret; + } + stype = json_object_get_string(jtype); + + if(!strcasecmp(stype,MEDIA_ALL)) { + ret = LMS_ALL_SCAN; + } else if(!strcasecmp(stype,MEDIA_AUDIO)) { + ret = LMS_AUDIO_SCAN; + } else if(!strcasecmp(stype,MEDIA_VIDEO)) { + ret = LMS_VIDEO_SCAN; + } else if(!strcasecmp(stype,MEDIA_IMAGE)) { + ret = LMS_IMAGE_SCAN; + } else { + afb_req_fail(request,"failed","invalid scan-type value"); + } + return ret; +} + +static gint get_scan_types(afb_req_t request) { + + json_object *jtypes = NULL; + gint ret = 0; + + if(!afb_req_is_valid(request)) { + afb_req_fail(request, "failed", "invalid request"); + return -1; + } + + if(!json_object_object_get_ex(afb_req_json(request),"types",&jtypes)) { + /* + * Considering 'audio' & 'video' scan types as default + * if the user doesn't provide 'types' property, + * for sake of compability with previeus versions + */ + ret = (LMS_AUDIO_SCAN | LMS_VIDEO_SCAN); + return ret; + } + + if(json_object_is_type(jtypes,json_type_array)) { + const gint len = json_object_array_length(jtypes); + size_t i; + + if(len > LMS_SCAN_COUNT) { + afb_req_fail(request, "failed", "too many scan-types"); + return -1; + } + + for(i=0; ipath); json_object_object_add(jdict, "path", jstring); - jstring = json_object_new_string(lms_scan_types[item->type]); + jstring = json_object_new_string(item->type); json_object_object_add(jdict, "type", jstring); if (item->metadata.title) { @@ -131,10 +224,20 @@ static void media_results_get (afb_req_t request) { GList *list = NULL; json_object *jresp = NULL; + gint scan_type = 0; + + scan_type = get_scan_types(request); + if(scan_type < 0) return; ListLock(); - list = media_lightmediascanner_scan(list, NULL, LMS_AUDIO_SCAN); - list = media_lightmediascanner_scan(list, NULL, LMS_VIDEO_SCAN); + + if(scan_type & LMS_AUDIO_SCAN) + list = media_lightmediascanner_scan(list, NULL, LMS_AUDIO_SCAN); + if(scan_type & LMS_VIDEO_SCAN) + list = media_lightmediascanner_scan(list, NULL, LMS_VIDEO_SCAN); + if(scan_type & LMS_IMAGE_SCAN) + list = media_lightmediascanner_scan(list, NULL, LMS_IMAGE_SCAN); + if (list == NULL) { afb_req_fail(request, "failed", "media scan error"); ListUnlock(); diff --git a/binding/media-manager.c b/binding/media-manager.c index 549153b..fbe4bb7 100644 --- a/binding/media-manager.c +++ b/binding/media-manager.c @@ -33,9 +33,10 @@ #include "media-manager.h" -const char *lms_scan_types[] = { - "audio", - "video", +const gchar *lms_scan_types[] = { + MEDIA_AUDIO, + MEDIA_VIDEO, + MEDIA_IMAGE }; static Binding_RegisterCallback_t g_RegisterCallback = { 0 }; @@ -96,6 +97,7 @@ GList* media_lightmediascanner_scan(GList *list, gchar *uri, int scan_type) const char *tail; const gchar *db_path; gchar *query; + gchar *media_type; int ret = 0; db_path = scanner1_get_data_base_path(MediaPlayerManage.lms_proxy); @@ -107,12 +109,18 @@ GList* media_lightmediascanner_scan(GList *list, gchar *uri, int scan_type) } switch (scan_type) { - case LMS_VIDEO_SCAN: - query = g_strdup_printf(VIDEO_SQL_QUERY, uri ? uri : ""); - break; - case LMS_AUDIO_SCAN: - default: - query = g_strdup_printf(AUDIO_SQL_QUERY, uri ? uri : ""); + case LMS_VIDEO_SCAN: + query = g_strdup_printf(VIDEO_SQL_QUERY, uri ? uri : ""); + media_type = lms_scan_types[LMS_VIDEO_ID]; + break; + case LMS_IMAGE_SCAN: + query = g_strdup_printf(IMAGE_SQL_QUERY, uri ? uri : ""); + media_type = lms_scan_types[LMS_IMAGE_ID]; + break; + case LMS_AUDIO_SCAN: + default: + query = g_strdup_printf(AUDIO_SQL_QUERY, uri ? uri : ""); + media_type = lms_scan_types[LMS_AUDIO_ID]; } if (!query) { @@ -142,7 +150,7 @@ GList* media_lightmediascanner_scan(GList *list, gchar *uri, int scan_type) item->path = g_strdup_printf("file://%s", tmp); g_free(tmp); - item->type = scan_type; + item->type = media_type; item->metadata.title = g_strdup((gchar *) sqlite3_column_text(res, 1)); item->metadata.artist = g_strdup((gchar *) sqlite3_column_text(res, 2)); item->metadata.album = g_strdup((gchar *) sqlite3_column_text(res, 3)); @@ -150,7 +158,6 @@ GList* media_lightmediascanner_scan(GList *list, gchar *uri, int scan_type) item->metadata.duration = sqlite3_column_int(res, 5) * 1000; list = g_list_append(list, item); } - g_free(query); return list; @@ -173,6 +180,9 @@ on_interface_proxy_properties_changed (GDBusProxy *proxy, GVariant *changed_properties, const gchar* const *invalidated_properties) { + if(!(MediaPlayerManage.type_filter & LMS_ALL_SCAN)) + return; + GVariantIter iter; const gchar *key; GVariant *subValue; @@ -200,9 +210,12 @@ on_interface_proxy_properties_changed (GDBusProxy *proxy, } ListLock(); - - list = media_lightmediascanner_scan(list, MediaPlayerManage.uri_filter, LMS_AUDIO_SCAN); - list = media_lightmediascanner_scan(list, MediaPlayerManage.uri_filter, LMS_VIDEO_SCAN); + if(MediaPlayerManage.type_filter & LMS_AUDIO_SCAN) + list = media_lightmediascanner_scan(list, MediaPlayerManage.uri_filter, LMS_AUDIO_SCAN); + if(MediaPlayerManage.type_filter & LMS_VIDEO_SCAN) + list = media_lightmediascanner_scan(list, MediaPlayerManage.uri_filter, LMS_VIDEO_SCAN); + if(MediaPlayerManage.type_filter & LMS_IMAGE_SCAN) + list = media_lightmediascanner_scan(list, MediaPlayerManage.uri_filter, LMS_IMAGE_SCAN); g_free(MediaPlayerManage.uri_filter); MediaPlayerManage.uri_filter = NULL; @@ -277,7 +290,7 @@ unmount_cb (GFileMonitor *mon, /* * Create MediaPlayer Manager Thread - * Note: mediaplayer-api should do MediaPlayerManagerInit() before any other + * Note: mediaplayer-api should do MediaPlayerManagerInit() before any other * API calls * Returns: 0 - success or error conditions */ @@ -323,3 +336,14 @@ void BindingAPIRegister(const Binding_RegisterCallback_t* pstRegisterCallback) } } } + +gint ScanTypeAppend(gint type) +{ + return MediaPlayerManage.type_filter |= (type & LMS_ALL_SCAN); +} + +gint ScanTypeRemove(gint type) +{ + MediaPlayerManage.type_filter = (MediaPlayerManage.type_filter & (~type)) & LMS_ALL_SCAN; + return MediaPlayerManage.type_filter; +} \ No newline at end of file diff --git a/binding/media-manager.h b/binding/media-manager.h index 4b381dc..c5b6778 100644 --- a/binding/media-manager.h +++ b/binding/media-manager.h @@ -97,9 +97,18 @@ void DebugTraceSendMsg(int level, gchar* message); "ORDER BY " \ "videos.title" +#define IMAGE_SQL_QUERY \ + "SELECT files.path, images.title, \"\", \"\", " \ + " \"\" FROM files " \ + "INNER JOIN images ON images.id = files.id " \ + "WHERE files.path LIKE '%s/%%' " \ + "ORDER BY " \ + "images.title" + typedef struct { GList *list; gchar *uri_filter; + gint type_filter; GMutex m; Scanner1 *lms_proxy; } stMediaPlayerManage; @@ -114,6 +123,9 @@ typedef struct tagBinding_RegisterCallback void BindingAPIRegister(const Binding_RegisterCallback_t* pstRegisterCallback); int MediaPlayerManagerInit(void); +gint ScanTypeAppend(gint); +gint ScanTypeRemove(gint); + void ListLock(); void ListUnlock(); @@ -121,7 +133,7 @@ GList* media_lightmediascanner_scan(GList *list, gchar *uri, int scan_type); struct Media_Item { gchar *path; - gint type; + gchar *type; struct { gchar *title; gchar *artist; @@ -132,11 +144,23 @@ struct Media_Item { }; enum { - LMS_AUDIO_SCAN, - LMS_VIDEO_SCAN, - LMS_SCAN_COUNT, + LMS_AUDIO_ID, + LMS_VIDEO_ID, + LMS_IMAGE_ID, + LMS_SCAN_COUNT }; +#define LMS_AUDIO_SCAN (1 << LMS_AUDIO_ID) +#define LMS_VIDEO_SCAN (1 << LMS_VIDEO_ID) +#define LMS_IMAGE_SCAN (1 << LMS_IMAGE_ID) + +#define LMS_ALL_SCAN ( LMS_AUDIO_SCAN | LMS_VIDEO_SCAN | LMS_IMAGE_SCAN ) + +#define MEDIA_AUDIO "audio" +#define MEDIA_VIDEO "video" +#define MEDIA_IMAGE "image" +#define MEDIA_ALL "all" + extern const char *lms_scan_types[LMS_SCAN_COUNT]; #endif -- cgit 1.2.3-korg