From: Olaf Wintermann Date: Wed, 12 Jan 2022 17:15:57 +0000 (+0100) Subject: detect player end X-Git-Url: https://develop.uap-core.de/gitweb/uwplayer.git/commitdiff_plain/6f0f043866279eb17db4e95964c9e9817923c0d8 detect player end --- diff --git a/application/player.c b/application/player.c index b34ea7b..e07b946 100644 --- a/application/player.c +++ b/application/player.c @@ -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)); +} diff --git a/application/player.h b/application/player.h index 3309096..9858491 100644 --- a/application/player.h +++ b/application/player.h @@ -42,6 +42,8 @@ void PlayerOpenFile(MainWindow *win); void PlayerDestroy(Player *p); +void PlayerEOF(Player *p); + #ifdef __cplusplus } diff --git a/application/window.h b/application/window.h index 37d6d17..66db8ae 100644 --- a/application/window.h +++ b/application/window.h @@ -37,6 +37,7 @@ typedef struct Player { pid_t process; int log; int ipc; + int status; bool isactive; double playback_time;