Skip to content

Commit

Permalink
Revise alphacc_config - Added optional fields
Browse files Browse the repository at this point in the history
- Revise config parser to include default and optional values
  • Loading branch information
Zhongyang Xia committed Nov 17, 2020
1 parent 31743fc commit c5e137b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 47 deletions.
56 changes: 30 additions & 26 deletions api/alphacc_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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;
Expand Down
42 changes: 21 additions & 21 deletions api/alphacc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
Empty file added outvideo.mp4
Empty file.

0 comments on commit c5e137b

Please sign in to comment.