static void handle_json_rpc_msg(Player *player, JSONValue *v);
static void handle_json_rpc_reqid(Player *player, JSONValue *v, int reqid);
+static void handle_json_rpc_event(Player *player, JSONValue *v, JSONValue *event);
void PlayerOpenFile(MainWindow *win) {
pthread_t tid;
if((r = read(fds[1].fd, buf, PLAYER_IN_BUFSIZE)) <= 0) {
break;
}
+ //fwrite(buf, 1, r, stdout);
+ fflush(stdout);
json_parser_fill(js, buf, r);
JSONValue *value;
}
char *cmd = "{ \"command\": [\"get_property\", \"playback-time\"], request_id=\"" REQ_ID_PLAYBACK_TIME "\" }\n";
- write(p->ipc, cmd, strlen(cmd));
+ //write(p->ipc, cmd, strlen(cmd));
}
}
if(v->type != JSON_OBJECT) return;
JSONValue *request_id_v = json_obj_get(&v->value.object, "request_id");
+ JSONValue *event = NULL;
if(request_id_v && request_id_v->type == JSON_STRING) {
int request_id = 0;
if(request_id_v->value.string.length == 2) {
handle_json_rpc_reqid(player, v, request_id);
return;
}
+ } else if ((event = json_obj_get(&v->value.object, "event")) != NULL) {
+ handle_json_rpc_event(player, v, event);
}
json_print(v, NULL, 0);
+ fflush(stdout);
+}
+
+static void player_set_size(Player *player, int width, int height) {
+ if(width >= 0) {
+ player->width = width;
+ }
+ if(height >= 0) {
+ player->height = height;
+ }
+ if(player->width > 0 && player->height > 0) {
+ printf("TODO: set player size\n");
+ }
}
static void handle_json_rpc_reqid(Player *player, JSONValue *v, int reqid) {
}
break;
}
+ case REQ_ID_WIDTH_INT: {
+ if(data->type == JSON_INTEGER) {
+ player_set_size(player, data->value.integer.value, -1);
+ }
+ break;
+ }
+ case REQ_ID_HEIGHT_INT: {
+ if(data->type == JSON_INTEGER) {
+ player_set_size(player, -1, data->value.integer.value);
+ }
+ break;
+ }
+ }
+}
+
+static void handle_json_rpc_event(Player *p, JSONValue *v, JSONValue *event) {
+ if(!json_strcmp(event, "property-change")) {
+ printf("property change\n");
+ } else if(!json_strcmp(event, "playback-restart")) {
+ char *cmd = "{ \"command\": [\"observe_property\", 1, \"playback-time\"] }\n"
+ "{ \"command\": [\"get_property\", \"width\"], request_id=\"" REQ_ID_WIDTH "\" }\n"
+ "{ \"command\": [\"get_property\", \"height\"], request_id=\"" REQ_ID_HEIGHT "\" }\n";
+ write(p->ipc, cmd, strlen(cmd));
}
}