]> uap-core.de Git - uwplayer.git/commitdiff
add rpc event handler
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 12 Jan 2022 16:59:34 +0000 (17:59 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 12 Jan 2022 16:59:34 +0000 (17:59 +0100)
application/json.c
application/player.c
application/player.h
application/window.h

index 5099d9b7b26a4a0131dc2ecfd529e85ab2062eb9..719a570252b56e32a7655aaa8b4fb37e9b540ee0 100644 (file)
@@ -900,5 +900,5 @@ int json_strncmp(JSONValue *jsstr, const char *str, size_t slen) {
         return jsstrlen > slen ? 1 : -1;
     }
     
-    return memcmp(jsstr, jsstr->value.string.string, slen);
+    return memcmp(jsstr->value.string.string, str, slen);
 }
index 83a5d4fa934315a10a2f22d8b55a5d178eb3c550..b34ea7bd5278e0c27dc720c4d59da196ab747416 100644 (file)
@@ -55,6 +55,7 @@ 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);
+static void handle_json_rpc_event(Player *player, JSONValue *v, JSONValue *event);
 
 void PlayerOpenFile(MainWindow *win) {
     pthread_t tid;
@@ -273,6 +274,8 @@ static void player_io(Player *p) {
             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;
@@ -289,7 +292,7 @@ static void player_io(Player *p) {
         }
         
         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));
     }
 }
 
@@ -298,6 +301,7 @@ 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");
+    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) {
@@ -305,9 +309,24 @@ static void handle_json_rpc_msg(Player *player, JSONValue *v) {
             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) {
@@ -321,6 +340,29 @@ 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));
     }
 }
 
index 26980a6466168fb17a0cba232af9161cf29c93b7..33090966d1274231b2af0bf7d9fa52d716cdc867 100644 (file)
@@ -32,6 +32,11 @@ extern "C" {
 
 #define REQ_ID_PLAYBACK_TIME     "11"
 #define REQ_ID_PLAYBACK_TIME_INT 11
+#define REQ_ID_WIDTH             "12"
+#define REQ_ID_WIDTH_INT         12
+#define REQ_ID_HEIGHT            "13"
+#define REQ_ID_HEIGHT_INT        13
+    
     
 void PlayerOpenFile(MainWindow *win);
 
index c90dfe5d1dd3f68662fc941ea52082283a88f055..37d6d17803518b204d3311c44baef6f5c06cebce 100644 (file)
@@ -40,6 +40,8 @@ typedef struct Player {
     bool isactive;
     
     double playback_time;
+    int width;
+    int height;
 } Player;
     
 typedef struct MainWindow {