Implement Media Plugin upload API, update README.md
[src/app-framework-binder.git] / plugins / media / media-rygel.c
1 /*
2  * Copyright (C) 2016 "IoT.bzh"
3  * Author "Manuel Bachmann"
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #include "media-api.h"
20
21 /* -------------- MEDIA RYGEL IMPLEMENTATION ---------------- */
22
23 /* --- PUBLIC FUNCTIONS --- */
24
25 PUBLIC unsigned char _rygel_init (mediaCtxHandleT *ctx) {
26
27     GMainContext *loop;
28     GUPnPContext *context;
29     GUPnPControlPoint *control_point;
30     gint handler_cb;
31     struct timeval tv_start, tv_now;
32
33     context = gupnp_context_new (NULL, NULL, 0, NULL);
34
35     control_point = gupnp_control_point_new (context, URN_MEDIA_SERVER);
36
37     handler_cb = g_signal_connect (control_point, "device-proxy-available",
38                                    G_CALLBACK (_rygel_device_cb), ctx);
39
40     /* start searching for servers */
41     gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (control_point), TRUE);
42
43     loop = g_main_context_default ();
44
45     /* 5 seconds should be sufficient to find Rygel */
46     gettimeofday (&tv_start, NULL);
47     gettimeofday (&tv_now, NULL);
48     while (tv_now.tv_sec - tv_start.tv_sec <= 5) {
49
50         g_main_context_iteration (loop, FALSE);
51
52         if (ctx->media_server)
53             break;
54         gettimeofday (&tv_now, NULL);
55     }
56     /* fail if we found no server */
57     if (!ctx->media_server)
58       return 0;
59
60     /* we have found the server ; stop looking for it... */
61     g_signal_handler_disconnect (control_point, handler_cb);
62
63     dev_ctx[client_count]->loop = loop;
64     dev_ctx[client_count]->context = context;
65     dev_ctx[client_count]->av_transport = NULL;
66     dev_ctx[client_count]->state = STOP;
67     dev_ctx[client_count]->target_state = STOP;
68     dev_ctx[client_count]->transfer_started = 0;
69
70     client_count++;
71
72     return 1;
73 }
74
75 PUBLIC void _rygel_free (mediaCtxHandleT *ctx) {
76
77     dev_ctx_T *dev_ctx_c = (dev_ctx_T*)ctx->media_server;
78
79     client_count--;
80
81     g_main_context_unref (dev_ctx_c->loop);
82     dev_ctx_c->loop = NULL;
83     dev_ctx_c->context = NULL;
84     dev_ctx_c->device_info = NULL;
85     dev_ctx_c->av_transport = NULL;
86     dev_ctx_c->content_dir = NULL;
87     dev_ctx_c->content_res = NULL;
88 }
89
90 PUBLIC char* _rygel_list (mediaCtxHandleT *ctx) {
91
92     dev_ctx_T *dev_ctx_c = (dev_ctx_T*)ctx->media_server;
93     char *raw, *start, *end, *title, *result = NULL;
94     int length, i = 0;
95
96     if (!dev_ctx_c)
97       return NULL;
98
99     raw = _rygel_list_raw (dev_ctx_c, NULL);
100     if (!raw)
101       return NULL;
102
103     start = strstr (raw, "<dc:title>");
104     if (!start)
105       return NULL;
106
107     result = strdup("");
108     while (start) {
109         start = strstr (start, "<dc:title>");
110         if (!start) break;
111         end = strstr (start, "</dc:title>");
112         start += 10;
113         length = end - start;
114
115         title = (char*) malloc (length+1);
116         strncpy (title, start, length);
117         title[length] = '\0';
118
119         asprintf (&result, "%s%02d:%s::", result, i, title);
120
121         free (title); i++;
122     }
123
124     return result;
125 }
126
127 PUBLIC unsigned char _rygel_choose (mediaCtxHandleT *ctx, unsigned int index) {
128
129     dev_ctx_T *dev_ctx_c = (dev_ctx_T*)ctx->media_server;
130     unsigned int count;
131
132     if (!dev_ctx_c)
133       return 0;
134
135     if (!_rygel_list_raw (dev_ctx_c, &count) ||
136         index >= count)
137       return 0;
138
139     if (ctx->index != index)
140       dev_ctx_c->state = STOP;
141
142     return 1;
143 }
144
145 PUBLIC unsigned char _rygel_upload (mediaCtxHandleT *ctx, char *path) {
146
147     dev_ctx_T *dev_ctx_c = (dev_ctx_T*)ctx->media_server;
148     char *raw, *upload_id;
149
150     if (!dev_ctx_c)
151       return 0;
152
153     raw = _rygel_list_raw (dev_ctx_c, NULL);
154     if (!raw)
155       return 0;
156
157     /* for now, we always use the same upload container id */
158     upload_id = _rygel_find_upload_id (dev_ctx_c, raw);
159
160     return _rygel_start_uploading (dev_ctx_c, path, upload_id);
161 }
162
163 PUBLIC unsigned char _rygel_do (mediaCtxHandleT *ctx, State state) {
164
165     dev_ctx_T *dev_ctx_c = (dev_ctx_T*)ctx->media_server;
166     unsigned int index = ctx->index;
167     unsigned int count;
168     char *raw, *id, *metadata, *uri;
169
170     if (!dev_ctx_c || dev_ctx_c->state == state)
171         return 0;
172
173     raw = _rygel_list_raw (dev_ctx_c, &count);
174     if (!raw || index >= count)
175       return 0;
176
177           id = _rygel_find_id_for_index (dev_ctx_c, raw, index);
178     metadata = _rygel_find_metadata_for_id (dev_ctx_c, id);
179          uri = _rygel_find_uri_for_metadata (dev_ctx_c, metadata);
180
181     return _rygel_start_doing (dev_ctx_c, uri, metadata, state);
182 }
183
184 /* --- LOCAL HELPER FUNCTIONS --- */
185
186 STATIC char* _rygel_list_raw (dev_ctx_T* dev_ctx_c, unsigned int *count) {
187
188     GUPnPServiceProxy *content_dir_proxy;
189     struct timeval tv_start, tv_now;
190
191     dev_ctx_c->content_res = NULL;
192     dev_ctx_c->content_num = 0;
193     content_dir_proxy = GUPNP_SERVICE_PROXY (dev_ctx_c->content_dir);
194
195     gupnp_service_proxy_begin_action (content_dir_proxy, "Browse", _rygel_content_cb, dev_ctx_c,
196                                       "ObjectID", G_TYPE_STRING, "Filesystem",
197                                       "BrowseFlag", G_TYPE_STRING, "BrowseDirectChildren",
198                                       "Filter", G_TYPE_STRING, "@childCount",
199                                       "StartingIndex", G_TYPE_UINT, 0,
200                                       "RequestedCount", G_TYPE_UINT, 64,
201                                       "SortCriteria", G_TYPE_STRING, "",
202                                        NULL);
203
204     gettimeofday (&tv_start, NULL);
205     gettimeofday (&tv_now, NULL);
206     while (tv_now.tv_sec - tv_start.tv_sec <= 5) {
207
208         g_main_context_iteration (dev_ctx_c->loop, FALSE);
209
210         if (dev_ctx_c->content_res)
211             break;
212         gettimeofday (&tv_now, NULL);
213     }
214
215     if (count) *count = dev_ctx_c->content_num;
216     return dev_ctx_c->content_res;
217 }
218
219 STATIC char* _rygel_find_upload_id (dev_ctx_T* dev_ctx_c, char *raw) {
220
221     char *found;
222     char id[33];
223
224     found = strstr (raw, "parentID=\"");
225     found += 10;
226
227     /* IDs are 32-bit strings */
228     strncpy (id, found, 32);
229     id[32] = '\0';
230
231     return strdup (id);
232 }
233
234 STATIC char* _rygel_find_id_for_index (dev_ctx_T* dev_ctx_c, char *raw, unsigned int index) {
235
236     char *found = raw;
237     char id[33];
238     int i;
239
240     for (i = 0; i <= index; i++) {
241         found = strstr (found, "item id=");
242         found += 9;
243
244         if (i == index) {
245             /* IDs are 32-bit strings */
246             strncpy (id, found, 32);
247             id[32] = '\0';
248         }
249     }
250
251     return strdup (id);
252 }
253
254 STATIC char* _rygel_find_metadata_for_id (dev_ctx_T* dev_ctx_c, char *id) {
255
256     GUPnPServiceProxy *content_dir_proxy;
257     struct timeval tv_start, tv_now;
258
259     dev_ctx_c->content_res = NULL;
260
261     content_dir_proxy = GUPNP_SERVICE_PROXY (dev_ctx_c->content_dir);
262
263     gupnp_service_proxy_begin_action (content_dir_proxy, "Browse", _rygel_metadata_cb, dev_ctx_c,
264                                       "ObjectID", G_TYPE_STRING, id,
265                                       "BrowseFlag", G_TYPE_STRING, "BrowseMetadata",
266                                       "Filter", G_TYPE_STRING, "*",
267                                       "StartingIndex", G_TYPE_UINT, 0,
268                                       "RequestedCount", G_TYPE_UINT, 0,
269                                       "SortCriteria", G_TYPE_STRING, "",
270                                        NULL);
271
272     gettimeofday (&tv_start, NULL);
273     gettimeofday (&tv_now, NULL);
274     while (tv_now.tv_sec - tv_start.tv_sec <= 5) {
275
276         g_main_context_iteration (dev_ctx_c->loop, FALSE);
277
278         if (dev_ctx_c->content_res)
279             break;
280         gettimeofday (&tv_now, NULL);
281     }
282
283     return dev_ctx_c->content_res;
284 }
285
286 STATIC char* _rygel_find_uri_for_metadata (dev_ctx_T* dev_ctx_c, char *metadata) {
287
288     char *start, *end, *uri = NULL;
289     int length;
290
291     /* position ourselves after the first "<res " tag */
292     start = strstr (metadata, "<res ");
293
294     while (start) {
295         start = strstr (start, "http://");
296         if (!start) break;
297         end = strstr (start, "</res>");
298         length = end - start;
299
300
301         uri = (char *)malloc (length + 1);
302         strncpy (uri, start, length);
303         uri[length] = '\0';
304         /* if the URI contains "primary_http", it is the main one ; stop here...*/
305         if (strstr (uri, "primary_http"))
306           break;
307
308         free (uri); start = end;
309     }
310
311     return uri;
312 }
313
314 STATIC unsigned char _rygel_start_uploading (dev_ctx_T* dev_ctx_c, char *path, char *upload_id) {
315
316     GUPnPServiceProxy *content_dir_proxy;
317     GUPnPDIDLLiteWriter *didl_writer;
318     GUPnPDIDLLiteObject *didl_object;
319     char *didl, *content_type, *mime_type, *upnp_class;
320     struct timeval tv_start, tv_now;
321
322     didl_writer = gupnp_didl_lite_writer_new (NULL);
323     didl_object = GUPNP_DIDL_LITE_OBJECT (gupnp_didl_lite_writer_add_item (didl_writer));
324
325     /* create the metadata for the file */
326     gupnp_didl_lite_object_set_parent_id (didl_object, upload_id);
327     gupnp_didl_lite_object_set_id (didl_object, "");
328     gupnp_didl_lite_object_set_restricted (didl_object, FALSE);
329     gupnp_didl_lite_object_set_title (didl_object, g_path_get_basename (path));
330     /* deduce the UPnP class from the MIME type ("audio/ogg" e.g.) */
331     content_type = g_content_type_guess (path, NULL, 0, NULL);
332     mime_type = g_content_type_get_mime_type (content_type);
333     if (strstr (mime_type, "audio/"))
334       upnp_class = strdup ("object.item.audioItem.musicTrack");
335     else if (strstr (mime_type, "video/"))
336       upnp_class = strdup ("object.item.videoItem");
337     else if (strstr (mime_type, "image/"))
338       upnp_class = strdup ("object.item.imageItem");
339     else
340       upnp_class = strdup ("object.item");
341     gupnp_didl_lite_object_set_upnp_class (didl_object, upnp_class);
342     didl = gupnp_didl_lite_writer_get_string (didl_writer);
343
344     dev_ctx_c->transfer_path = path;
345     dev_ctx_c->transfer_started = 0;
346     content_dir_proxy = GUPNP_SERVICE_PROXY (dev_ctx_c->content_dir);
347
348     gupnp_service_proxy_begin_action (content_dir_proxy, "CreateObject", _rygel_upload_cb, dev_ctx_c,
349                                       "ContainerID", G_TYPE_STRING, upload_id,
350                                       "Elements", G_TYPE_STRING, didl,
351                                        NULL);
352
353     gettimeofday (&tv_start, NULL);
354     gettimeofday (&tv_now, NULL);
355     while (tv_now.tv_sec - tv_start.tv_sec <= 5) {
356
357       g_main_context_iteration (dev_ctx_c->loop, FALSE);
358
359       if (dev_ctx_c->transfer_started)
360         break;
361       gettimeofday (&tv_now, NULL);
362     }
363     if (!dev_ctx_c->transfer_started)
364       return 0;
365
366     return 1;
367 }
368
369 STATIC unsigned char _rygel_start_doing (dev_ctx_T* dev_ctx_c, char *uri, char *metadata, State state) {
370
371     GUPnPServiceProxy *av_transport_proxy;
372     struct timeval tv_start, tv_now;
373
374     if (!dev_ctx_c->av_transport) {
375       if (!_rygel_find_av_transport (dev_ctx_c))
376          return 0;
377     }
378     dev_ctx_c->target_state = state;
379     av_transport_proxy = GUPNP_SERVICE_PROXY (dev_ctx_c->av_transport);
380
381     gupnp_service_proxy_begin_action (av_transport_proxy, "SetAVTransportURI", _rygel_select_cb, dev_ctx_c,
382                                       "InstanceID", G_TYPE_UINT, 0,
383                                       "CurrentURI", G_TYPE_STRING, uri,
384                                       "CurrentURIMetaData", G_TYPE_STRING, metadata,
385                                        NULL);
386
387     gettimeofday (&tv_start, NULL);
388     gettimeofday (&tv_now, NULL);
389     while (tv_now.tv_sec - tv_start.tv_sec <= 5) {
390
391       g_main_context_iteration (dev_ctx_c->loop, FALSE);
392
393       if (dev_ctx_c->state == state)
394         break;
395       gettimeofday (&tv_now, NULL);
396     }
397     if (dev_ctx_c->state != state)
398       return 0;
399
400     return 1;
401 }
402
403 STATIC unsigned char _rygel_find_av_transport (dev_ctx_T* dev_ctx_c) {
404
405     GUPnPControlPoint *control_point;
406     gint handler_cb;
407     struct timeval tv_start, tv_now;
408
409     control_point = gupnp_control_point_new (dev_ctx_c->context, URN_MEDIA_RENDERER);
410
411     handler_cb = g_signal_connect (control_point, "device-proxy-available",
412                                    G_CALLBACK (_rygel_av_transport_cb), dev_ctx_c);
413
414     gssdp_resource_browser_set_active (GSSDP_RESOURCE_BROWSER (control_point), TRUE);
415
416     gettimeofday (&tv_start, NULL);
417     gettimeofday (&tv_now, NULL);
418     while (tv_now.tv_sec - tv_start.tv_sec <= 5) {
419
420         g_main_context_iteration (dev_ctx_c->loop, FALSE);
421
422         if (dev_ctx_c->av_transport)
423             break;
424         gettimeofday (&tv_now, NULL);
425     }
426     g_signal_handler_disconnect (control_point, handler_cb);
427
428     if (!dev_ctx_c->av_transport)
429       return 0;
430
431     return 1;
432 }
433
434
435  /* ---- LOCAL CALLBACK FUNCTIONS ---- */
436
437 STATIC void _rygel_device_cb (GUPnPControlPoint *point, GUPnPDeviceProxy *proxy,
438                               gpointer data) {
439
440     mediaCtxHandleT *ctx = (mediaCtxHandleT*)data;
441     GUPnPDeviceInfo *device_info;
442     GUPnPServiceInfo *content_dir;
443     const char *device_name;
444
445     device_info = GUPNP_DEVICE_INFO (proxy);
446     device_name = gupnp_device_info_get_model_name (device_info);
447     content_dir = gupnp_device_info_get_service (device_info, URN_CONTENT_DIR);
448
449     if (strcmp (device_name, "Rygel") != 0)
450         return;
451     if (!content_dir)
452         return;
453
454     /* allocate the global array if it has not been not done */
455     if (!dev_ctx)
456         dev_ctx = (dev_ctx_T**) malloc (sizeof(dev_ctx_T));
457     else
458         dev_ctx = (dev_ctx_T**) realloc (dev_ctx, (client_count+1)*sizeof(dev_ctx_T));
459
460     /* create an element for the client in the global array */
461     dev_ctx[client_count] = (dev_ctx_T*) malloc (sizeof(dev_ctx_T));
462     dev_ctx[client_count]->device_info = device_info;
463     dev_ctx[client_count]->content_dir = content_dir;
464
465     /* make the client context aware of it */
466     ctx->media_server = (void*)dev_ctx[client_count];
467 }
468
469 STATIC void _rygel_av_transport_cb (GUPnPControlPoint *point, GUPnPDeviceProxy *proxy,
470                                     gpointer data) {
471
472     dev_ctx_T *dev_ctx_c = (dev_ctx_T*)data;
473     GUPnPDeviceInfo *device_info;
474     GUPnPServiceInfo *av_transport;
475
476     device_info = GUPNP_DEVICE_INFO (proxy);
477     av_transport = gupnp_device_info_get_service (device_info, URN_AV_TRANSPORT);
478
479     dev_ctx_c->av_transport = av_transport;
480 }
481
482 STATIC void _rygel_content_cb (GUPnPServiceProxy *content_dir, GUPnPServiceProxyAction *action,
483                                gpointer data) {
484
485     dev_ctx_T *dev_ctx_c = (dev_ctx_T*)data;
486     GUPnPServiceProxy *content_dir_proxy = GUPNP_SERVICE_PROXY (content_dir);
487     GError *error;
488     char *result;
489     guint32 number_returned;
490     guint32 total_matches;
491     char *found;
492     char subid[33];
493
494     gupnp_service_proxy_end_action (content_dir, action, &error,
495                                     "Result", G_TYPE_STRING, &result,
496                                     "NumberReturned", G_TYPE_UINT, &number_returned,
497                                     "TotalMatches", G_TYPE_UINT, &total_matches,
498                                      NULL);
499
500     if (number_returned == 0)
501         return;
502
503     if (number_returned == 1) {
504         found = strstr (result, "id=\"");       
505         found += 4;
506         strncpy (subid, found, 32); subid[32] = '\0';
507
508         gupnp_service_proxy_begin_action (content_dir_proxy, "Browse", _rygel_content_cb, dev_ctx_c,
509                                           "ObjectID", G_TYPE_STRING, subid,
510                                           "BrowseFlag", G_TYPE_STRING, "BrowseDirectChildren",
511                                           "Filter", G_TYPE_STRING, "@childCount",
512                                           "StartingIndex", G_TYPE_UINT, 0,
513                                           "RequestedCount", G_TYPE_UINT, 64,
514                                           "SortCriteria", G_TYPE_STRING, "",
515                                            NULL);
516         return;
517     }
518
519     if (number_returned > 1) {
520         dev_ctx_c->content_res = result;
521         dev_ctx_c->content_num = number_returned;
522     }
523 }
524
525 STATIC void _rygel_metadata_cb (GUPnPServiceProxy *content_dir, GUPnPServiceProxyAction *action,
526                                 gpointer data) {
527
528     dev_ctx_T *dev_ctx_c = (dev_ctx_T*)data;
529     GError *error;
530     char *result;
531
532     gupnp_service_proxy_end_action (content_dir, action, &error,
533                                     "Result", G_TYPE_STRING, &result,
534                                      NULL);
535
536     dev_ctx_c->content_res = result;
537 }
538
539 STATIC void _rygel_select_cb (GUPnPServiceProxy *av_transport, GUPnPServiceProxyAction *action,
540                               gpointer data)
541 {
542
543     dev_ctx_T *dev_ctx_c = (dev_ctx_T*)data;
544     GUPnPServiceProxy *av_transport_proxy;
545     GError *error;
546     struct timeval tv_start, tv_now;
547
548     av_transport_proxy = GUPNP_SERVICE_PROXY (av_transport);
549
550     gupnp_service_proxy_end_action (av_transport, action, &error, NULL);
551
552     switch (dev_ctx_c->target_state) {
553         case PLAY:
554           gupnp_service_proxy_begin_action (av_transport_proxy, "Play", _rygel_do_cb, dev_ctx_c,
555                                            "InstanceID", G_TYPE_UINT, 0,
556                                            "Speed", G_TYPE_STRING, "1",
557                                             NULL);
558           break;
559        case PAUSE:
560           gupnp_service_proxy_begin_action (av_transport_proxy, "Pause", _rygel_do_cb, dev_ctx_c,
561                                            "InstanceID", G_TYPE_UINT, 0,
562                                             NULL);
563           break;
564        case STOP:
565           gupnp_service_proxy_begin_action (av_transport_proxy, "Stop", _rygel_do_cb, dev_ctx_c,
566                                            "InstanceID", G_TYPE_UINT, 0,
567                                             NULL);
568           break;
569        default:
570          break;
571     }
572
573     gettimeofday (&tv_start, NULL);
574     gettimeofday (&tv_now, NULL);
575     while (tv_now.tv_sec - tv_start.tv_sec <= 5) {
576
577         g_main_context_iteration (dev_ctx_c->loop, FALSE);
578
579         if (dev_ctx_c->state == dev_ctx_c->target_state)
580             break;
581         gettimeofday (&tv_now, NULL);
582     }
583 }
584
585 STATIC void _rygel_upload_cb (GUPnPServiceProxy *content_dir, GUPnPServiceProxyAction *action,
586                               gpointer data)
587 {
588     dev_ctx_T *dev_ctx_c = (dev_ctx_T*)data;
589     GUPnPServiceProxy *content_dir_proxy;
590     GError *error;
591     char *result, *start, *end, *dst_uri, *src_uri;
592     int length;
593     struct timeval tv_start, tv_now;
594
595     content_dir_proxy = GUPNP_SERVICE_PROXY (content_dir);
596
597     if (!gupnp_service_proxy_end_action (content_dir, action, &error,
598                                          "Result", G_TYPE_STRING, &result,
599                                           NULL))
600       return;
601
602     start = strstr (result, "<res importUri=\"");
603     if (!start)
604       return;
605
606     start += 16;
607     end = strstr (start, "\"");
608     length = end - start;
609
610     dst_uri = (char*) malloc(length+1);
611     strncpy (dst_uri, start, length);
612     dst_uri[length] = '\0';
613
614     asprintf (&src_uri, "http://%s:%u%s", gupnp_context_get_host_ip (dev_ctx_c->context),
615                                           gupnp_context_get_port (dev_ctx_c->context),
616                                           dev_ctx_c->transfer_path);
617
618     /* host the file */
619     gupnp_context_host_path (dev_ctx_c->context, dev_ctx_c->transfer_path,
620                                                  dev_ctx_c->transfer_path);
621
622     gupnp_service_proxy_begin_action (content_dir_proxy, "ImportResource", _rygel_transfer_cb, dev_ctx_c,
623                                       "SourceURI", G_TYPE_STRING, src_uri,
624                                       "DestinationURI", G_TYPE_STRING, dst_uri,
625                                        NULL);
626
627     gettimeofday (&tv_start, NULL);
628     gettimeofday (&tv_now, NULL);
629     while (tv_now.tv_sec - tv_start.tv_sec <= 5) {
630
631         g_main_context_iteration (dev_ctx_c->loop, FALSE);
632
633         if (dev_ctx_c->transfer_started)
634             break;
635         gettimeofday (&tv_now, NULL);
636     }
637 }
638
639 STATIC void _rygel_transfer_cb (GUPnPServiceProxy *content_dir, GUPnPServiceProxyAction *action,
640                                 gpointer data)
641 {
642     dev_ctx_T *dev_ctx_c = (dev_ctx_T*)data;
643     GError *error;
644     guint transfer_id;
645
646     if (!gupnp_service_proxy_end_action (content_dir, action, &error,
647                                          "TransferID", G_TYPE_UINT, &transfer_id,
648                                           NULL))
649       return;
650
651     dev_ctx_c->transfer_started = 1;
652 }
653
654 STATIC void _rygel_do_cb (GUPnPServiceProxy *av_transport, GUPnPServiceProxyAction *action,
655                           gpointer data)
656 {
657     dev_ctx_T *dev_ctx_c = (dev_ctx_T*)data;
658     GError *error;
659
660     if (!gupnp_service_proxy_end_action (av_transport, action, &error,
661                                          NULL))
662       return;
663
664     dev_ctx_c->state = dev_ctx_c->target_state;
665 }