aboutsummaryrefslogtreecommitdiffstats
path: root/binding
diff options
context:
space:
mode:
Diffstat (limited to 'binding')
-rw-r--r--binding/media-api.c113
-rw-r--r--binding/media-manager.c54
-rw-r--r--binding/media-manager.h32
3 files changed, 175 insertions, 24 deletions
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; i<len; ++i){
+ gint t = get_scan_type(request, json_object_array_get_idx(jtypes,i));
+ if(t != 0) { ret |= t; } else { return -1;}
+ }
+ return ret;
+ } else if(json_object_is_type(jtypes,json_type_string)) {
+ gint t = get_scan_type(request,jtypes);
+ if(t != 0) {return t;} else {return -1;}
+ } else {
+ afb_req_fail(request, "failed", "invalid scan-types format");
+ return -1;
+ }
+}
+
/*
* @brief Subscribe for an event
*
@@ -38,6 +104,8 @@ static afb_event_t media_removed_event;
static void subscribe(afb_req_t request)
{
const char *value = afb_req_value(request, "value");
+ gint scantype = 0;
+
if(value) {
if(!strcasecmp(value, "media_added")) {
afb_req_subscribe(request, media_added_event);
@@ -48,7 +116,13 @@ static void subscribe(afb_req_t request)
return;
}
}
- afb_req_success(request, NULL, NULL);
+
+ //Get scan types & append them to scan config
+ scantype = get_scan_types(request);
+ if(scantype < 0) return;
+
+ ScanTypeAppend(scantype);
+ afb_req_success(request, NULL, NULL);
}
/*
@@ -59,7 +133,26 @@ static void subscribe(afb_req_t request)
*/
static void unsubscribe(afb_req_t request)
{
- const char *value = afb_req_value(request, "value");
+ json_object *jrequest = afb_req_json(request);
+ char *value = NULL;
+
+ if( json_object_object_get_ex(jrequest,"value",NULL) &&
+ json_object_object_get_ex(jrequest,"types",NULL) ) {
+ //If 'types' is provided, We just remove the specified types.
+ gint scantype = get_scan_types(request);
+ if(scantype < 0) return;
+
+ /*
+ * If any scan type remained, we escape unsubscribe the event
+ * otherwise continue to unsubscribe the event
+ */
+ if(ScanTypeRemove(scantype)) {
+ afb_req_success(request, NULL, NULL);
+ return;
+ }
+ }
+
+ value = afb_req_value(request, "value");
if(value) {
if(!strcasecmp(value, "media_added")) {
afb_req_unsubscribe(request, media_added_event);
@@ -88,7 +181,7 @@ static json_object *new_json_object_from_device(GList *list)
jstring = json_object_new_string(item->path);
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