diff options
Diffstat (limited to 'video_player/src')
-rw-r--r-- | video_player/src/main.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/video_player/src/main.cpp b/video_player/src/main.cpp index 03acd93..33c4d96 100644 --- a/video_player/src/main.cpp +++ b/video_player/src/main.cpp @@ -101,6 +101,20 @@ static Json::Value handle_json_command_sub_add(mpv_handle *mpv_ctx, const Json:: return response_json; } +static Json::Value handle_json_command_cycle_fullscreen(mpv_handle *mpv_ctx) { + const char *args[] = { "cycle", "fullscreen", nullptr }; + const int res = mpv_command_async(mpv_ctx, 0, args); + + Json::Value response_json(Json::objectValue); + if(res < 0) { + response_json["status"] = "error"; + response_json["message"] = mpv_error_string(res); + } else { + response_json["status"] = "success"; + } + return response_json; +} + static void send_error(const std::string &err_msg, std::optional<int64_t> request_id, int fd) { fprintf(stderr, "Error: %s\n", err_msg.c_str()); @@ -151,10 +165,12 @@ static void handle_json_command(mpv_handle *mpv_ctx, const Json::Value &json_roo response_json = handle_json_command_time_pos(mpv_ctx); } else if(strcmp(command_json.asCString(), "sub-add") == 0) { response_json = handle_json_command_sub_add(mpv_ctx, json_root); + } else if(strcmp(command_json.asCString(), "cycle-fullscreen") == 0) { + response_json = handle_json_command_cycle_fullscreen(mpv_ctx); } else { response_json = Json::Value(Json::objectValue); response_json["status"] = "error"; - response_json["message"] = "invalid command " + command_json.asString() + ", expected time-pos or sub-add"; + response_json["message"] = "invalid command " + command_json.asString() + ", expected time-pos, sub-add or cycle-fullscreen"; } if(request_id) @@ -193,9 +209,16 @@ static void handle_request_commands_line_by_line(mpv_handle *mpv_ctx, int fd, ch command_buffer_size = 0; } -static void send_event(const char *event_name, int fd) { +static void send_event(const char *event_name, int fd, const std::vector<std::string> &args = {}) { Json::Value json_root(Json::objectValue); json_root["event"] = event_name; + if(!args.empty()) { + Json::Value args_json(Json::arrayValue); + for(const std::string &arg : args) { + args_json.append(arg); + } + json_root["args"] = std::move(args_json); + } Json::StreamWriterBuilder builder; builder["commentStyle"] = "None"; @@ -292,6 +315,7 @@ int main(int argc, char **argv) { check_error(mpv_command(mpv_ctx, cmd), "loadfile"); check_error(mpv_observe_property(mpv_ctx, 0, "idle-active", MPV_FORMAT_FLAG), "observe idle-active"); + check_error(mpv_observe_property(mpv_ctx, 0, "fullscreen", MPV_FORMAT_FLAG), "observe fullscreen"); char command_buffer[COMMAND_BUFFER_MAX_SIZE]; size_t command_buffer_size = 0; @@ -325,12 +349,14 @@ int main(int argc, char **argv) { } else if(event->event_id == MPV_EVENT_SHUTDOWN) { running = false; break; - } else if(event->event_id == MPV_EVENT_PROPERTY_CHANGE && file_started) { + } else if(event->event_id == MPV_EVENT_PROPERTY_CHANGE) { // End of file (idle) mpv_event_property *property = (mpv_event_property*)event->data; - if(strcmp(property->name, "idle-active") == 0 && *(int*)property->data == 1) { + if(file_started && strcmp(property->name, "idle-active") == 0 && *(int*)property->data == 1) { running = false; break; + } else if(args.ipc_fd && strcmp(property->name, "fullscreen") == 0) { + send_event("fullscreen", args.ipc_fd_num, { *(bool*)property->data ? "yes" : "no" }); } } |