* Copyright (C) 2016 "IoT.bzh"
* Author "Manuel Bachmann"
*
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
#include "media-api.h"
dev_ctx[client_count]->av_transport = NULL;
dev_ctx[client_count]->state = STOP;
dev_ctx[client_count]->target_state = STOP;
+ dev_ctx[client_count]->action_args = NULL;
dev_ctx[client_count]->transfer_started = 0;
client_count++;
dev_ctx_c->content_res = NULL;
}
-PUBLIC char* _rygel_list (mediaCtxHandleT *ctx) {
+PUBLIC json_object* _rygel_list (mediaCtxHandleT *ctx) {
dev_ctx_T *dev_ctx_c = (dev_ctx_T*)ctx->media_server;
- char *raw, *start, *end, *title, *result = NULL;
+ json_object *json_o, *json_a;
+ char *raw, *start, *end, *id, *title;
int length, i = 0;
if (!dev_ctx_c)
if (!start)
return NULL;
- result = strdup("");
+ json_o = json_object_new_object ();
+ json_a = json_object_new_array ();
while (start) {
+ json_object *json_i, *json_id, *json_title;
+
start = strstr (start, "<dc:title>");
if (!start) break;
end = strstr (start, "</dc:title>");
start += 10;
length = end - start;
+ asprintf (&id, "%02d", i);
+
title = (char*) malloc (length+1);
strncpy (title, start, length);
title[length] = '\0';
- asprintf (&result, "%s%02d:%s::", result, i, title);
+ json_i = json_object_new_object ();
+ json_id = json_object_new_string (id);
+ json_title = json_object_new_string (title);
+ json_object_object_add (json_i, "id", json_id);
+ json_object_object_add (json_i, "title", json_title);
+ json_object_array_add (json_a, json_i);
- free (title); i++;
+ free (id); free (title);
+ i++;
}
- return result;
+ json_object_object_add (json_o, "list", json_a);
+
+ return json_o;
}
-PUBLIC unsigned char _rygel_choose (mediaCtxHandleT *ctx, unsigned int index) {
+PUBLIC unsigned char _rygel_select (mediaCtxHandleT *ctx, unsigned int index) {
dev_ctx_T *dev_ctx_c = (dev_ctx_T*)ctx->media_server;
unsigned int count;
return _rygel_start_uploading (dev_ctx_c, path, upload_id);
}
-PUBLIC unsigned char _rygel_do (mediaCtxHandleT *ctx, State state) {
+PUBLIC unsigned char _rygel_do (mediaCtxHandleT *ctx, State state, char *args) {
dev_ctx_T *dev_ctx_c = (dev_ctx_T*)ctx->media_server;
unsigned int index = ctx->index;
metadata = _rygel_find_metadata_for_id (dev_ctx_c, id);
uri = _rygel_find_uri_for_metadata (dev_ctx_c, metadata);
- return _rygel_start_doing (dev_ctx_c, uri, metadata, state);
+ return _rygel_start_doing (dev_ctx_c, uri, metadata, state, args);
}
/* --- LOCAL HELPER FUNCTIONS --- */
return uri;
}
+STATIC char * _rygel_time_for_string (char *string) {
+
+ int total_seconds;
+ unsigned int hours, minutes, seconds;
+ char *time;
+
+ total_seconds = atoi (string);
+ hours = total_seconds / 3600;
+ minutes = (total_seconds / 60) - (hours * 60);
+ seconds = total_seconds - (hours * 3600) - (minutes * 60);
+
+ asprintf (&time, "%u:%02u:%02u", hours, minutes, seconds);
+
+ return time;
+}
+
STATIC unsigned char _rygel_start_uploading (dev_ctx_T* dev_ctx_c, char *path, char *upload_id) {
GUPnPServiceProxy *content_dir_proxy;
return 1;
}
-STATIC unsigned char _rygel_start_doing (dev_ctx_T* dev_ctx_c, char *uri, char *metadata, State state) {
+STATIC unsigned char _rygel_start_doing (dev_ctx_T* dev_ctx_c, char *uri, char *metadata, State state, char *args) {
GUPnPServiceProxy *av_transport_proxy;
struct timeval tv_start, tv_now;
return 0;
}
dev_ctx_c->target_state = state;
+ dev_ctx_c->action_args = args;
av_transport_proxy = GUPNP_SERVICE_PROXY (dev_ctx_c->av_transport);
gupnp_service_proxy_begin_action (av_transport_proxy, "SetAVTransportURI", _rygel_select_cb, dev_ctx_c,
dev_ctx_T *dev_ctx_c = (dev_ctx_T*)data;
GUPnPServiceProxy *av_transport_proxy;
GError *error;
+ char *time;
struct timeval tv_start, tv_now;
av_transport_proxy = GUPNP_SERVICE_PROXY (av_transport);
"InstanceID", G_TYPE_UINT, 0,
NULL);
break;
+ case SEEK:
+ time = _rygel_time_for_string (dev_ctx_c->action_args);
+ gupnp_service_proxy_begin_action (av_transport_proxy, "Seek", _rygel_do_cb, dev_ctx_c,
+ "InstanceID", G_TYPE_UINT, 0,
+ "Unit", G_TYPE_STRING, "ABS_TIME",
+ "Target", G_TYPE_STRING, time,
+ NULL);
default:
break;
}