diff options
Diffstat (limited to 'src/VideoPlayer.cpp')
-rw-r--r-- | src/VideoPlayer.cpp | 49 |
1 files changed, 37 insertions, 12 deletions
diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp index 2c0fe44..26e2013 100644 --- a/src/VideoPlayer.cpp +++ b/src/VideoPlayer.cpp @@ -96,8 +96,8 @@ namespace QuickMedia { video_process_id(-1), connect_tries(0), find_window_tries(0), - event_callback(_event_callback), - window_create_callback(_window_create_callback), + event_callback(std::move(_event_callback)), + window_create_callback(std::move(_window_create_callback)), window_handle(0), display(nullptr), request_id_counter(1), @@ -364,6 +364,21 @@ namespace QuickMedia { return Error::OK; } + static std::vector<std::string> json_array_to_string_list(const Json::Value &json) { + std::vector<std::string> result; + if(!json.isArray()) + return result; + + for(const Json::Value &item : json) { + if(!item.isString()) + continue; + + result.push_back(item.asString()); + } + + return result; + } + VideoPlayer::Error VideoPlayer::read_ipc_func() { Json::Value json_root; Json::CharReaderBuilder json_builder; @@ -386,18 +401,26 @@ namespace QuickMedia { if(json_reader->parse(buffer + start, buffer + i, &json_root, &json_errors) && json_root.isObject()) { const Json::Value &event = json_root["event"]; - const Json::Value &request_id_json = json_root["request_id"]; + const Json::Value &args = json_root["args"]; if(event.isString()) { if(event_callback) - event_callback(event.asCString()); + event_callback(event.asCString(), json_array_to_string_list(args)); } + const Json::Value &request_id_json = json_root["request_id"]; if(expected_request_id != 0 && request_id_json.isNumeric() && request_id_json.asUInt() == expected_request_id) { const Json::Value &status_json = json_root["status"]; - if(!status_json.isString() || strcmp(status_json.asCString(), "error") == 0) + if(!status_json.isString() || strcmp(status_json.asCString(), "error") == 0) { response_data_status = ResponseDataStatus::ERROR; - else + const char *err_msg = "Unknown"; + const Json::Value &message_json = json_root["message"]; + if(message_json.isString()) + err_msg = message_json.asCString(); + + fprintf(stderr, "VideoPlayer::send_command failed, error from video player: %s\n", err_msg); + } else { response_data_status = ResponseDataStatus::OK; + } request_response_data = json_root["data"]; } } else { @@ -440,6 +463,14 @@ namespace QuickMedia { return send_command(json_root, &result, Json::ValueType::nullValue); } + VideoPlayer::Error VideoPlayer::cycle_fullscreen() { + Json::Value json_root(Json::objectValue); + json_root["command"] = "cycle-fullscreen"; + + Json::Value result; + return send_command(json_root, &result, Json::ValueType::nullValue); + } + uint32_t VideoPlayer::get_next_request_id() { unsigned int cmd_request_id = request_id_counter; ++request_id_counter; @@ -483,12 +514,6 @@ namespace QuickMedia { else err = Error::READ_INCORRECT_TYPE; } else if(response_data_status == ResponseDataStatus::ERROR) { - const char *err_msg = "Unknown"; - const Json::Value &message_json = request_response_data["message"]; - if(message_json.isString()) - err_msg = message_json.asCString(); - - fprintf(stderr, "VideoPlayer::send_command failed, error from video player: %s\n", err_msg); err = Error::READ_RESPONSE_ERROR; goto cleanup; } else { |