]> uap-core.de Git - uwplayer.git/commitdiff
shutdown existing player when a new file is opened
authorOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 7 Jan 2022 08:21:05 +0000 (09:21 +0100)
committerOlaf Wintermann <olaf.wintermann@gmail.com>
Fri, 7 Jan 2022 08:21:05 +0000 (09:21 +0100)
application/player.c
application/window.h

index 213d18451d92d4768d06e1fa90c090e3e23637e5..8e03fbc00a0657dc2e1275c45b1bf715e8f26327 100644 (file)
@@ -28,6 +28,7 @@
 #include <sys/fcntl.h>
 #include <spawn.h>
 #include <sys/wait.h>
+#include <signal.h>
 
 #include <pthread.h>
 
@@ -36,6 +37,7 @@ extern char **environ;
 #define WID_ARG_BUFSIZE 24
 
 static void* start_player(void *data);
+static void* player_io_thread(void *data);
 
 void PlayerOpenFile(MainWindow *win) {
     pthread_t tid;
@@ -98,15 +100,33 @@ static void* start_player(void *data) {
     close(pin[0]);
     close(pout[1]);
     player->process = player_pid;
+    player->isactive = TRUE;
     
     if(win->player) {
         PlayerDestroy(win->player);
     }
     win->player = player;
     
+    // start thread for mplayer IO
+    pthread_t tid;
+    if(pthread_create(&tid, NULL, player_io_thread, player)) {
+        perror("pthread_create");
+    }
+    
     return NULL;
 }
 
 void PlayerDestroy(Player *p) {
+    if(p->isactive) {
+        close(p->in);
+        close(p->out);
+        kill(p->process, SIGTERM);
+    }
     free(p);
 }
+
+static void* player_io_thread(void *data) {
+    Player *player = data;
+    
+    return NULL;
+}
index 0ac5cc70631c9ead184ae8a6c59b589ed0db5fc1..eb47127482417d39b5ae2c1fe153944bdb496f7a 100644 (file)
@@ -36,6 +36,7 @@ typedef struct Player {
     pid_t process;
     int in;
     int out;
+    bool isactive;
 } Player;
     
 typedef struct MainWindow {