]> uap-core.de Git - uwplayer.git/commitdiff
handle playback-time messages
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 8 Jan 2022 17:13:28 +0000 (18:13 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Sat, 8 Jan 2022 17:13:28 +0000 (18:13 +0100)
application/player.c
application/player.h
application/window.h

index 38b3a0c4f95731eca334839ec05e5b711427fce1..83a5d4fa934315a10a2f22d8b55a5d178eb3c550 100644 (file)
@@ -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);
index dc608272508ea0ce452e961e91b3e0eb9ba9e9de..26980a6466168fb17a0cba232af9161cf29c93b7 100644 (file)
@@ -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);
 
index f63add547cf422dc03f7b7aa5f33d07d22c25180..c90dfe5d1dd3f68662fc941ea52082283a88f055 100644 (file)
@@ -38,6 +38,8 @@ typedef struct Player {
     int log;
     int ipc;
     bool isactive;
+    
+    double playback_time;
 } Player;
     
 typedef struct MainWindow {