static void player_io(Player *p);
+static void handle_json_rpc_msg(Player *player, JSONValue *v);
+static void handle_json_rpc_reqid(Player *player, JSONValue *v, int reqid);
+
void PlayerOpenFile(MainWindow *win) {
pthread_t tid;
if(pthread_create(&tid, NULL, start_player, win)) {
JSONValue *value;
int ret;
while((ret = json_read_value(js, &value)) == 1) {
- json_print(value, NULL, 0);
+ handle_json_rpc_msg(p, value);
json_value_free(value);
}
}
}
+
+static void handle_json_rpc_msg(Player *player, JSONValue *v) {
+ if(v->type != JSON_OBJECT) return;
+
+ JSONValue *request_id_v = json_obj_get(&v->value.object, "request_id");
+ if(request_id_v && request_id_v->type == JSON_STRING) {
+ int request_id = 0;
+ if(request_id_v->value.string.length == 2) {
+ request_id = 10 * (request_id_v->value.string.string[0] - '0') + (request_id_v->value.string.string[1] - '0');
+ handle_json_rpc_reqid(player, v, request_id);
+ return;
+ }
+ }
+
+ json_print(v, NULL, 0);
+}
+
+static void handle_json_rpc_reqid(Player *player, JSONValue *v, int reqid) {
+ JSONValue *data = json_obj_get(&v->value.object, "data");
+ if(!data) return;
+
+ switch(reqid) {
+ case REQ_ID_PLAYBACK_TIME_INT: {
+ if(data->type == JSON_NUMBER) {
+ player->playback_time = data->value.number.value;
+ }
+ break;
+ }
+ }
+}
+
void PlayerDestroy(Player *p) {
if(p->log >= 0) {
close(p->log);