From c5e137bbcf9abe7b6389f95c96c429acf82f7616 Mon Sep 17 00:00:00 2001 From: Zhongyang Xia Date: Tue, 17 Nov 2020 07:34:39 +0000 Subject: [PATCH] Revise alphacc_config - Added optional fields - Revise config parser to include default and optional values --- api/alphacc_config.cc | 56 +++++++++++++++++++++++-------------------- api/alphacc_config.h | 42 ++++++++++++++++---------------- outvideo.mp4 | 0 3 files changed, 51 insertions(+), 47 deletions(-) create mode 100644 outvideo.mp4 diff --git a/api/alphacc_config.cc b/api/alphacc_config.cc index 03a0ac4ce0..d3157544b7 100644 --- a/api/alphacc_config.cc +++ b/api/alphacc_config.cc @@ -37,29 +37,32 @@ bool ParseAlphaCCConfig(const std::string& file_path) { RETURN_ON_FAIL(reader.parse(is, top)); - RETURN_ON_FAIL(GetValue(top, "server_connection", &second)); - RETURN_ON_FAIL(GetString(second, "ip", &config->conn_server_ip)); - RETURN_ON_FAIL(GetInt(second, "port", &config->conn_server_port)); - RETURN_ON_FAIL(GetBool(second, "autoconnect", &config->conn_autoconnect)); - RETURN_ON_FAIL(GetBool(second, "autocall", &config->conn_autocall)); - RETURN_ON_FAIL(GetInt(second, "autoclose", &config->conn_autoclose)); + if (GetValue(top, "server_connection", &second)) { + RETURN_ON_FAIL(GetString(second, "ip", &config->conn_server_ip)); + RETURN_ON_FAIL(GetInt(second, "port", &config->conn_server_port)); + RETURN_ON_FAIL(GetBool(second, "autoconnect", &config->conn_autoconnect)); + RETURN_ON_FAIL(GetBool(second, "autocall", &config->conn_autocall)); + RETURN_ON_FAIL(GetInt(second, "autoclose", &config->conn_autoclose)); + } second.clear(); - RETURN_ON_FAIL(GetValue(top, "serverless_connection", &second)); - RETURN_ON_FAIL(GetValue(second, "sender", &third)); - RETURN_ON_FAIL(GetBool(third, "enabled", &config->is_sender)); - if (config->is_sender) { - RETURN_ON_FAIL(GetString(third, "dest_ip", &config->dest_ip)); - RETURN_ON_FAIL(GetInt(third, "dest_port", &config->dest_port)); - } - third.clear(); - RETURN_ON_FAIL(GetValue(second, "receiver", &third)); - RETURN_ON_FAIL(GetBool(third, "enabled", &config->is_receiver)); - if (config->is_receiver) { - RETURN_ON_FAIL(GetString(third, "listening_ip", &config->listening_ip)); - RETURN_ON_FAIL(GetInt(third, "listening_port", &config->listening_port)); + if (GetValue(top, "serverless_connection", &second)) { + RETURN_ON_FAIL(GetInt(second, "autoclose", &config->conn_autoclose)); + RETURN_ON_FAIL(GetValue(second, "sender", &third)); + RETURN_ON_FAIL(GetBool(third, "enabled", &config->is_sender)); + if (config->is_sender) { + RETURN_ON_FAIL(GetString(third, "dest_ip", &config->dest_ip)); + RETURN_ON_FAIL(GetInt(third, "dest_port", &config->dest_port)); + } + third.clear(); + RETURN_ON_FAIL(GetValue(second, "receiver", &third)); + RETURN_ON_FAIL(GetBool(third, "enabled", &config->is_receiver)); + if (config->is_receiver) { + RETURN_ON_FAIL(GetString(third, "listening_ip", &config->listening_ip)); + RETURN_ON_FAIL(GetInt(third, "listening_port", &config->listening_port)); + } + third.clear(); } - third.clear(); second.clear(); RETURN_ON_FAIL( @@ -70,12 +73,13 @@ bool ParseAlphaCCConfig(const std::string& file_path) { GetString(second, "onnx_model_path", &config->onnx_model_path)); second.clear(); - RETURN_ON_FAIL(GetValue(top, "redis", &second)); - RETURN_ON_FAIL(GetString(second, "ip", &config->redis_ip)); - RETURN_ON_FAIL(GetInt(second, "port", &config->redis_port)); - RETURN_ON_FAIL(GetString(second, "session_id", &config->redis_sid)); - RETURN_ON_FAIL(GetInt(second, "redis_update_duration", - &config->redis_update_duration_ms)); + if (GetValue(top, "redis", &second)) { + RETURN_ON_FAIL(GetString(second, "ip", &config->redis_ip)); + RETURN_ON_FAIL(GetInt(second, "port", &config->redis_port)); + RETURN_ON_FAIL(GetString(second, "session_id", &config->redis_sid)); + RETURN_ON_FAIL(GetInt(second, "redis_update_duration", + &config->redis_update_duration_ms)); + } second.clear(); bool enabled = false; diff --git a/api/alphacc_config.h b/api/alphacc_config.h index e54efe155d..b516dc15fb 100644 --- a/api/alphacc_config.h +++ b/api/alphacc_config.h @@ -20,7 +20,7 @@ struct AlphaCCConfig { ~AlphaCCConfig() = default; // The server to connect - std::string conn_server_ip; + std::string conn_server_ip = ""; int conn_server_port = 0; // Connect to the server without user intervention. bool conn_autoconnect = false; @@ -36,40 +36,40 @@ struct AlphaCCConfig { bool is_receiver = false; // The address to connect to - std::string dest_ip; - int dest_port; - std::string listening_ip; - int listening_port; + std::string dest_ip = ""; + int dest_port = 0; + std::string listening_ip = ""; + int listening_port = 0; // Redis server configuration - std::string redis_ip; - int redis_port; + std::string redis_ip = ""; + int redis_port = 0; // Redis session id - std::string redis_sid; - int redis_update_duration_ms; + std::string redis_sid = ""; + int redis_update_duration_ms = 0; - int bwe_feedback_duration_ms; - std::string onnx_model_path; + int bwe_feedback_duration_ms = 0; + std::string onnx_model_path = ""; enum class VideoSourceOption { kVideoDisabled, kWebcam, kVideoFile, } video_source_option; - int video_height; - int video_width; - int video_fps; - std::string video_file_path; + int video_height = 0; + int video_width = 0; + int video_fps = 0; + std::string video_file_path = ""; enum class AudioSourceOption { kMicrophone, kAudioFile } audio_source_option; - std::string audio_file_path; + std::string audio_file_path = ""; bool save_to_file = false; - std::string video_output_path; - std::string audio_output_path; - int video_output_height; - int video_output_width; - int video_output_fps; + std::string video_output_path = ""; + std::string audio_output_path = ""; + int video_output_height = 0; + int video_output_width = 0; + int video_output_fps = 0; }; // Get alphaCC global configurations diff --git a/outvideo.mp4 b/outvideo.mp4 new file mode 100644 index 0000000000..e69de29bb2