X-Git-Url: https://develop.uap-core.de/gitweb/uwplayer.git/blobdiff_plain/6f0f043866279eb17db4e95964c9e9817923c0d8..1a310acf08a2d12cba26c745c0d29030238675f0:/application/player.c diff --git a/application/player.c b/application/player.c index e07b946..9e47049 100644 --- a/application/player.c +++ b/application/player.c @@ -21,6 +21,7 @@ */ #include "player.h" +#include "main.h" #include #include @@ -246,6 +247,7 @@ static void* start_player(void *data) { PlayerDestroy(player); return NULL; } + close(player->log); if(connect_to_ipc(player)) { PlayerDestroy(player); @@ -265,29 +267,17 @@ static void* start_player(void *data) { } static void player_io(Player *p) { - int flags = fcntl(p->log, F_GETFL, 0); - fcntl(p->log, F_SETFL, flags | O_NONBLOCK); - struct pollfd fds[2]; - fds[0].fd = p->log; + fds[0].fd = p->ipc; fds[0].events = POLLIN; fds[0].revents = 0; - fds[1].fd = p->ipc; - 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)) { if(fds[0].revents == POLLIN) { - // clean up fifo - read(fds[0].fd, buf, PLAYER_IN_BUFSIZE); - } - - if(fds[1].revents == POLLIN) { ssize_t r; - if((r = read(fds[1].fd, buf, PLAYER_IN_BUFSIZE)) <= 0) { + if((r = read(fds[0].fd, buf, PLAYER_IN_BUFSIZE)) <= 0) { break; } //fwrite(buf, 1, r, stdout); @@ -311,14 +301,15 @@ static void player_io(Player *p) { //write(p->ipc, cmd, strlen(cmd)); } - printf("PlayerEnd\n"); + + printf("PlayerEnd: %s\n", strerror(errno)); fflush(stdout); } 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) { @@ -332,10 +323,39 @@ static void handle_json_rpc_msg(Player *player, JSONValue *v) { handle_json_rpc_event(player, v, event); } - json_print(v, NULL, 0); + //json_print(v, NULL, 0); fflush(stdout); } +static Boolean player_widget_set_size(XtPointer data) { + Player *player = data; + MainWindow *win = GetMainWindow(); + + Dimension win_width, win_height; + XtVaGetValues(win->window, XmNwidth, &win_width, XmNheight, &win_height, NULL); + Dimension player_width, player_height; + XtVaGetValues(win->player_widget, XmNwidth, &player_width, XmNheight, &player_height, NULL); + + Dimension new_width = player->width + win_width - player_width; + Dimension new_height = player->height + win_height - player_height; + + // set window size + XtVaSetValues(win->window, XmNwidth, new_width, XmNheight, new_height, NULL); + + // set window aspect ratio + XSizeHints hints; + hints.flags = PAspect; + hints.min_aspect.x = new_width; + hints.min_aspect.y = new_height; + hints.max_aspect.x = new_width; + hints.max_aspect.y = new_height; + XSetWMNormalHints(XtDisplay(win->window), XtWindow(win->window), &hints); + + return 0; +} + + + static void player_set_size(Player *player, int width, int height) { if(width >= 0) { player->width = width; @@ -344,7 +364,7 @@ static void player_set_size(Player *player, int width, int height) { player->height = height; } if(player->width > 0 && player->height > 0) { - printf("TODO: set player size\n"); + AppExecProc(player_widget_set_size, player); } } @@ -374,19 +394,42 @@ static void handle_json_rpc_reqid(Player *player, JSONValue *v, int reqid) { } } +static Boolean get_player_window(XtPointer data) { + Player *p = data; + MainWindow *win = GetMainWindow(); + + Widget player_wid = win->player_widget; + Window root, parent; + Window *child; + unsigned int nchild; + XQueryTree(XtDisplay(player_wid), XtWindow(player_wid), &root, &parent, &child, &nchild); + if(nchild > 0) { + p->window = child[0]; + XFree(child); + } + + return 0; +} + 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")) { + JSONValue *name = json_obj_get(&v->value.object, "name"); + JSONValue *data = json_obj_get(&v->value.object, "data"); + if(!json_strcmp(name, "eof-reached")) { + if(data && data->type == JSON_LITERAL && data->value.literal.literal == JSON_TRUE) { + PlayerEOF(p); + } + } + } else if(!p->isstarted && !json_strcmp(event, "playback-restart")) { char *cmd = "{ \"command\": [\"observe_property\", 1, \"playback-time\"] }\n" + "{ \"command\": [\"observe_property\", 1, \"eof-reached\"] }\n" "{ \"command\": [\"get_property\", \"width\"], request_id=\"" REQ_ID_WIDTH "\" }\n" - "{ \"command\": [\"get_property\", \"height\"], request_id=\"" REQ_ID_HEIGHT "\" }\n"; + "{ \"command\": [\"get_property\", \"height\"], request_id=\"" REQ_ID_HEIGHT "\" }\n" + "{ \"command\": [\"set_property\", \"keep-open\", true] }\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); - } + p->isstarted = TRUE; + + AppExecProc(get_player_window, p); } } @@ -464,7 +507,13 @@ static void json_print(JSONValue *value, char *name, int indent) { break; } case JSON_LITERAL: { - printf("%s\n", "literal\n"); + char *lit = "NULL"; + switch(value->value.literal.literal) { + case JSON_NULL: break; + case JSON_TRUE: lit = "true"; break; + case JSON_FALSE: lit = "false"; break; + } + printf("%s\n", lit); break; } } @@ -475,6 +524,10 @@ 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)); + char *cmd = "{ \"command\": [\"set_property\", \"playback-time\", 0] }\n"; + write(p->ipc, cmd, strlen(cmd)); +} + +void PlayerHandleInput(MainWindow *win, Player *p, XmDrawingAreaCallbackStruct *cb) { + }