From: Olaf Wintermann Date: Sat, 8 Jan 2022 17:13:28 +0000 (+0100) Subject: handle playback-time messages X-Git-Url: https://uap-core.de/gitweb/?a=commitdiff_plain;h=2a56f611dc3fe723d5b52c54a74845ecd7714e25;p=uwplayer.git handle playback-time messages --- diff --git a/application/player.c b/application/player.c index 38b3a0c..83a5d4f 100644 --- a/application/player.c +++ b/application/player.c @@ -53,6 +53,9 @@ static void* start_player(void *data); 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)) { @@ -275,7 +278,7 @@ static void player_io(Player *p) { 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); } @@ -290,6 +293,37 @@ static void player_io(Player *p) { } } + +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); diff --git a/application/player.h b/application/player.h index dc60827..26980a6 100644 --- a/application/player.h +++ b/application/player.h @@ -30,7 +30,8 @@ extern "C" { #endif -#define REQ_ID_PLAYBACK_TIME "11" +#define REQ_ID_PLAYBACK_TIME "11" +#define REQ_ID_PLAYBACK_TIME_INT 11 void PlayerOpenFile(MainWindow *win); diff --git a/application/window.h b/application/window.h index f63add5..c90dfe5 100644 --- a/application/window.h +++ b/application/window.h @@ -38,6 +38,8 @@ typedef struct Player { int log; int ipc; bool isactive; + + double playback_time; } Player; typedef struct MainWindow {