]> uap-core.de Git - uwplayer.git/commitdiff
detect player end
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 12 Jan 2022 17:15:57 +0000 (18:15 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Wed, 12 Jan 2022 17:15:57 +0000 (18:15 +0100)
application/player.c
application/player.h
application/window.h

index b34ea7bd5278e0c27dc720c4d59da196ab747416..e07b946418c317d3c97bf26843fc4ee9cc2215f1 100644 (file)
@@ -101,6 +101,17 @@ static int prepare_player(Player *player, char *log_arg, char *ipc_arg) {
     return 0;
 }
 
+static void* wait_for_process(void *data) {
+    Player *player = data;
+    int status = 0;
+    waitpid(player->process, &status, 0);
+
+    player->isactive = FALSE;
+    player->status = status;
+    
+    return NULL;
+}
+
 static int start_player_process(Player *player, MainWindow *win) {
     char log_arg[STR_BUFSIZE];
     char ipc_arg[STR_BUFSIZE];
@@ -146,6 +157,11 @@ static int start_player_process(Player *player, MainWindow *win) {
     player->process = player_pid;
     player->isactive = TRUE;
     
+    pthread_t tid;
+    if(pthread_create(&tid, NULL, wait_for_process, player)) {
+        perror("pthread_create");
+    }
+    
     return 0;
 }
 
@@ -263,7 +279,7 @@ static void player_io(Player *p) {
     JSONParser *js = json_parser_new();
     
     char buf[PLAYER_IN_BUFSIZE];
-    while(poll(fds, 2, PLAYER_POLL_TIMEOUT)) {
+    while(p->isactive && poll(fds, 2, PLAYER_POLL_TIMEOUT)) {
         if(fds[0].revents == POLLIN) {
             // clean up fifo
             read(fds[0].fd, buf, PLAYER_IN_BUFSIZE);
@@ -294,6 +310,9 @@ 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));
     }
+    
+    printf("PlayerEnd\n");
+    fflush(stdout);
 }
 
 
@@ -363,6 +382,11 @@ static void handle_json_rpc_event(Player *p, JSONValue *v, JSONValue *event) {
                     "{ \"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));
+    } else if(!json_strcmp(event, "end-file")) {
+        JSONValue *reason = json_obj_get(&v->value.object, "reason");
+        if(reason && !json_strcmp(reason, "eof")) {
+            PlayerEOF(p);
+        }
     }
 }
 
@@ -450,3 +474,7 @@ static void json_print(JSONValue *value, char *name, int indent) {
     }
 }
 
+void PlayerEOF(Player *p) {
+    char *cmd = "{ \"command\": [\"set_property\", \"pause\"], true }\n";
+    //write(p->ipc, cmd, strlen(cmd));
+}
index 33090966d1274231b2af0bf7d9fa52d716cdc867..98584919e27e5d8231211ac93654048f22d6fc81 100644 (file)
@@ -42,6 +42,8 @@ void PlayerOpenFile(MainWindow *win);
 
 void PlayerDestroy(Player *p);
 
+void PlayerEOF(Player *p);
+
 
 #ifdef __cplusplus
 }
index 37d6d17803518b204d3311c44baef6f5c06cebce..66db8aea8cd695be0eba3b8c5e610492cbcccac3 100644 (file)
@@ -37,6 +37,7 @@ typedef struct Player {
     pid_t process;
     int log;
     int ipc;
+    int status;
     bool isactive;
     
     double playback_time;