X-Git-Url: https://develop.uap-core.de/gitweb/uwplayer.git/blobdiff_plain/e8e14035551f3e683c48eeedb1cedc07a95916cb..cb369bf7e3802b795a02017f3123869af2634626:/application/player.c diff --git a/application/player.c b/application/player.c index 6cdba87..255f7cb 100644 --- a/application/player.c +++ b/application/player.c @@ -39,6 +39,7 @@ #include #include "json.h" +#include "utils.h" #include "settings.h" extern char **environ; @@ -107,6 +108,8 @@ static void* wait_for_process(void *data) { Player *player = data; int status = 0; waitpid(player->process, &status, 0); + + printf("waitpid: %d\n", status); player->isactive = FALSE; player->status = status; @@ -138,14 +141,16 @@ static int start_player_process(Player *player, MainWindow *win) { // create player arg list char *args[32]; - args[0] = player_bin; - args[1] = "-wid"; - args[2] = wid_arg; - args[3] = "--no-terminal"; - args[4] = log_arg; - args[5] = ipc_arg; - args[6] = win->file; - args[7] = NULL; + int ac = 0; + args[ac++] = player_bin; + args[ac++] = "-wid"; + args[ac++] = wid_arg; + //args[ac++] = "--no-terminal"; + args[ac++] = "--player-operation-mode=pseudo-gui"; + args[ac++] = log_arg; + args[ac++] = ipc_arg; + args[ac++] = win->file; + args[ac++] = NULL; posix_spawn_file_actions_t actions; posix_spawn_file_actions_init(&actions); @@ -212,7 +217,7 @@ static int wait_for_ipc(Player *player) { return 0; } -static int connect_to_ipc(Player *player) { +static int connect_to_ipc(Player *player) { // connect to IPC socket int fd_ipc = socket(AF_UNIX, SOCK_STREAM, 0); if(fd_ipc < 0) { @@ -253,7 +258,7 @@ static void* start_player(void *data) { PlayerDestroy(player); return NULL; } - close(player->log); + //close(player->log); if(connect_to_ipc(player)) { PlayerDestroy(player); @@ -277,10 +282,13 @@ static void player_io(Player *p) { fds[0].fd = p->ipc; fds[0].events = POLLIN; fds[0].revents = 0; + fds[1].fd = p->log; + fds[1].events = POLLIN; + fds[1].revents = 0; JSONParser *js = json_parser_new(); - + char buf[PLAYER_IN_BUFSIZE]; - while(p->isactive && poll(fds, 2, PLAYER_POLL_TIMEOUT)) { + while(p->isactive && (poll(fds, 2, PLAYER_POLL_TIMEOUT) >= 0)) { if(fds[0].revents == POLLIN) { ssize_t r; if((r = read(fds[0].fd, buf, PLAYER_IN_BUFSIZE)) <= 0) { @@ -302,8 +310,12 @@ static void player_io(Player *p) { break; } } + if(fds[1].revents == POLLIN) { + // just read to clean the log pipe + read(fds[1].fd, buf, PLAYER_IN_BUFSIZE); + } - char *cmd = "{ \"command\": [\"get_property\", \"playback-time\"], request_id=\"" REQ_ID_PLAYBACK_TIME "\" }\n"; + //char *cmd = "{ \"command\": [\"get_property\", \"playback-time\"], request_id=\"" REQ_ID_PLAYBACK_TIME "\" }\n"; //write(p->ipc, cmd, strlen(cmd)); } @@ -419,6 +431,23 @@ static Boolean get_player_window(XtPointer data) { return 0; } +#define CURSOR_AUTOHIDE_THRESHOLD_SEC 4 + +static Boolean hide_cursor(XtPointer data) { + MainWindow *win = data; + WindowHidePlayerCursor(win); + return 0; +} + +static void check_hide_cursor(Player *p) { + MainWindow *win = GetMainWindow(); + if(win->cursorhidden) return; + + if(p->playback_time - win->motion_playback_time > CURSOR_AUTOHIDE_THRESHOLD_SEC) { + AppExecProc(hide_cursor, win); + } +} + static void handle_json_rpc_event(Player *p, JSONValue *v, JSONValue *event) { if(!json_strcmp(event, "property-change")) { JSONValue *name = json_obj_get(&v->value.object, "name"); @@ -427,6 +456,7 @@ static void handle_json_rpc_event(Player *p, JSONValue *v, JSONValue *event) { if(data && data->type == JSON_NUMBER) { p->playback_time = data->value.number.value; //printf("playback-time: %f\n", p->playback_time); + check_hide_cursor(p); } } else if(!json_strcmp(name, "eof-reached")) { if(data && data->type == JSON_LITERAL && data->value.literal.literal == JSON_TRUE) { @@ -542,9 +572,28 @@ static void json_print(JSONValue *value, char *name, int indent) { } } +static Boolean open_next_file(XtPointer data) { + char *file = data; + MainWindow *win = GetMainWindow(); + if(win->file) { + free(file); + } + win->file = file; + PlayerOpenFile(win); + return 0; +} + void PlayerEOF(Player *p) { - char *cmd = "{ \"command\": [\"set_property\", \"playback-time\", 0] }\n"; - write(p->ipc, cmd, strlen(cmd)); + MainWindow *win = GetMainWindow(); + if(win->repeatTrack) { + char *cmd = "{ \"command\": [\"set_property\", \"playback-time\", 0] }\n"; + write(p->ipc, cmd, strlen(cmd)); + } else if(win->autoplayFolder) { + char *next_file = util_find_next_file(win->file); + if(next_file) { + AppExecProc(open_next_file, next_file); + } + } } void PlayerHandleInput(MainWindow *win, Player *p, XmDrawingAreaCallbackStruct *cb) {