aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/media
diff options
context:
space:
mode:
authorManuel Bachmann <manuel.bachmann@iot.bzh>2016-01-20 16:31:00 +0100
committerManuel Bachmann <manuel.bachmann@iot.bzh>2016-01-20 16:31:00 +0100
commit9c066241bc2c1195f1bee5c17b39b023d257bd9e (patch)
tree3f689153cd1cebfbf013d1966a31ed8b2c428a8f /plugins/media
parenta5a5383bba11e69379e27919f101c5e7718f8bf2 (diff)
Fix Media Plugin content list API
Listing content had various pointer-related issues. Signed-off-by: Manuel Bachmann <manuel.bachmann@iot.bzh>
Diffstat (limited to 'plugins/media')
-rw-r--r--plugins/media/media-api.c8
-rw-r--r--plugins/media/media-api.h2
-rw-r--r--plugins/media/media-rygel.c31
-rw-r--r--plugins/media/media-rygel.h3
4 files changed, 36 insertions, 8 deletions
diff --git a/plugins/media/media-api.c b/plugins/media/media-api.c
index 60228a07..4365862a 100644
--- a/plugins/media/media-api.c
+++ b/plugins/media/media-api.c
@@ -57,11 +57,17 @@ STATIC json_object* init (AFB_request *request) { /* AFB_SESSION_CHECK */
STATIC json_object* list (AFB_request *request) { /* AFB_SESSION_CHECK */
+ json_object *jresp;
char *result;
result = _rygel_list (request->context);
- return jsonNewMessage(AFB_SUCCESS, result);
+ if (!result)
+ return jsonNewMessage(AFB_FAIL, "No content found in media server");
+
+ jresp = json_object_new_object();
+ json_object_object_add(jresp, "list", json_object_new_string (result));
+ return jresp;
}
STATIC json_object* ping (AFB_request *request) { /* AFB_SESSION_NONE */
diff --git a/plugins/media/media-api.h b/plugins/media/media-api.h
index e40c0dce..ae19a311 100644
--- a/plugins/media/media-api.h
+++ b/plugins/media/media-api.h
@@ -28,4 +28,6 @@ typedef struct {
void *media_server; /* handle to implementation (Rygel...) */
} mediaCtxHandleT;
+PUBLIC char* _rygel_list (mediaCtxHandleT *);
+
#endif /* MEDIA_API_H */
diff --git a/plugins/media/media-rygel.c b/plugins/media/media-rygel.c
index 51d718ba..0af1f4ad 100644
--- a/plugins/media/media-rygel.c
+++ b/plugins/media/media-rygel.c
@@ -33,8 +33,8 @@ PUBLIC unsigned char _rygel_init (mediaCtxHandleT *ctx) {
control_point = gupnp_control_point_new (context, URN_MEDIA_SERVER);
- g_signal_connect (control_point, "device-proxy-available",
- G_CALLBACK (_rygel_device_cb), ctx);
+ handler_cb = g_signal_connect (control_point, "device-proxy-available",
+ G_CALLBACK (_rygel_device_cb), ctx);
/* start searching for servers */
gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (control_point), TRUE);
@@ -50,6 +50,7 @@ PUBLIC unsigned char _rygel_init (mediaCtxHandleT *ctx) {
if (ctx->media_server)
break;
+ gettimeofday (&tv_now, NULL);
}
/* fail if we found no server */
if (!ctx->media_server)
@@ -74,14 +75,21 @@ PUBLIC void _rygel_free (mediaCtxHandleT *ctx) {
dev_ctx_c->context = NULL;
dev_ctx_c->device_info = NULL;
dev_ctx_c->content_dir = NULL;
+ if (dev_ctx_c->content_res)
+ free (dev_ctx_c->content_res);
+ dev_ctx_c->content_res = NULL;
}
PUBLIC char* _rygel_list (mediaCtxHandleT *ctx) {
dev_ctx_T *dev_ctx_c = (dev_ctx_T*)ctx->media_server;
GUPnPServiceProxy *content_dir_proxy;
+ struct timeval tv_start, tv_now;
+ if (dev_ctx_c->content_res)
+ free (dev_ctx_c->content_res);
dev_ctx_c->content_res = NULL;
+
content_dir_proxy = GUPNP_SERVICE_PROXY (dev_ctx_c->content_dir);
gupnp_service_proxy_begin_action (content_dir_proxy, "Browse", _rygel_content_cb, dev_ctx_c,
@@ -93,8 +101,16 @@ PUBLIC char* _rygel_list (mediaCtxHandleT *ctx) {
"SortCriteria", G_TYPE_STRING, "",
NULL);
- while (!dev_ctx_c->content_res)
- g_main_context_iteration (dev_ctx_c->loop, FALSE);
+ gettimeofday (&tv_start, NULL);
+ gettimeofday (&tv_now, NULL);
+ while (tv_now.tv_sec - tv_start.tv_sec <= 5) {
+
+ g_main_context_iteration (dev_ctx_c->loop, FALSE);
+
+ if (dev_ctx_c->content_res)
+ break;
+ gettimeofday (&tv_now, NULL);
+ }
return dev_ctx_c->content_res;
}
@@ -118,6 +134,9 @@ STATIC void _rygel_device_cb (GUPnPControlPoint *point, GUPnPDeviceProxy *proxy,
if (!content_dir)
return;
+ /* we have found Rygel ; stop looking for it... */
+ g_signal_handler_disconnect (point, handler_cb);
+
/* allocate the global array if it has not been not done */
if (!dev_ctx)
dev_ctx = (dev_ctx_T**) malloc (sizeof(dev_ctx_T));
@@ -125,7 +144,7 @@ STATIC void _rygel_device_cb (GUPnPControlPoint *point, GUPnPDeviceProxy *proxy,
dev_ctx = (dev_ctx_T**) realloc (dev_ctx, (client_count+1)*sizeof(dev_ctx_T));
/* create an element for the client in the global array */
- dev_ctx[client_count] = malloc (sizeof(dev_ctx_T));
+ dev_ctx[client_count] = (dev_ctx_T*) malloc (sizeof(dev_ctx_T));
dev_ctx[client_count]->device_info = device_info;
dev_ctx[client_count]->content_dir = content_dir;
@@ -159,7 +178,7 @@ STATIC void _rygel_content_cb (GUPnPServiceProxy *content_dir, GUPnPServiceProxy
found += 4;
strncpy (subid, found, 32); subid[32] = '\0';
- gupnp_service_proxy_begin_action (content_dir_proxy, "Browse", _rygel_content_cb, NULL,
+ gupnp_service_proxy_begin_action (content_dir_proxy, "Browse", _rygel_content_cb, dev_ctx_c,
"ObjectID", G_TYPE_STRING, subid,
"BrowseFlag", G_TYPE_STRING, "BrowseDirectChildren",
"Filter", G_TYPE_STRING, "@childCount",
diff --git a/plugins/media/media-rygel.h b/plugins/media/media-rygel.h
index c9705a4a..37fa53c4 100644
--- a/plugins/media/media-rygel.h
+++ b/plugins/media/media-rygel.h
@@ -42,7 +42,8 @@ struct dev_ctx {
STATIC void _rygel_device_cb (GUPnPControlPoint *, GUPnPDeviceProxy *, gpointer);
STATIC void _rygel_content_cb (GUPnPServiceProxy *, GUPnPServiceProxyAction *, gpointer);
-static struct dev_ctx **dev_ctx = NULL;
+static gint handler_cb;
static unsigned int client_count = 0;
+static struct dev_ctx **dev_ctx = NULL;
#endif /* MEDIA_RYGEL_H */