Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/config/ctrlm_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,18 @@ void ctrlm_config_t::destroy_instance() {

ctrlm_config_t::ctrlm_config_t() {
this->root = NULL;
this->local_config = false;
}

ctrlm_config_t::~ctrlm_config_t() {
if(this->root) {
json_decref(this->root);
this->root = NULL;
}
this->local_config = false;
}

bool ctrlm_config_t::load_config(const std::string &file_path, bool verbose) {
bool ctrlm_config_t::load_config(const std::string &file_path, bool local_config, bool verbose) {
bool ret = false;
std::string contents = file_to_string(file_path);
if(this->root) {
Expand All @@ -73,6 +75,7 @@ bool ctrlm_config_t::load_config(const std::string &file_path, bool verbose) {
if(verbose) {
XLOGD_INFO("config loaded successfully as JSON for <%s>", file_path.c_str());
}
this->local_config = local_config;
ret = true;
} else {
XLOGD_ERROR("JSON ERROR: Line <%u> Column <%u> Text <%s> Contents <%s>", json_error.line, json_error.column, json_error.text, contents.c_str());
Expand All @@ -83,7 +86,7 @@ bool ctrlm_config_t::load_config(const std::string &file_path, bool verbose) {
return(ret);
}

bool ctrlm_config_t::append_config(const std::string &file_path, bool verbose) {
bool ctrlm_config_t::append_config(const std::string &file_path, bool local_config, bool verbose) {
if(this->root == NULL) {
XLOGD_ERROR("no config file loaded");
return(false);
Expand All @@ -109,6 +112,7 @@ bool ctrlm_config_t::append_config(const std::string &file_path, bool verbose) {
if(verbose) {
XLOGD_INFO("config appended successfully as JSON for <%s>", file_path.c_str());
}
this->local_config |= local_config;
ret = true;
}
json_decref(append_root);
Expand All @@ -121,6 +125,10 @@ bool ctrlm_config_t::path_exists(const std::string &path) {
return(ctrlm_utils_json_from_path(this->root, path, false) != NULL ? true : false);
}

bool ctrlm_config_t::has_local_config() const {
return(this->local_config);
}

json_t *ctrlm_config_t::json_from_path(const std::string &path, bool add_ref) {
return(ctrlm_utils_json_from_path(this->root, path, add_ref));
}
Expand Down
14 changes: 12 additions & 2 deletions src/config/ctrlm_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,24 @@ class ctrlm_config_t {
/**
* Function which loads a configuration file into the configuration object.
* @param file_path The path to the configuration file
* @param local_config True if the configuration file is a local config, else False
* @param verbose True to enable verbose logging, else False
* @return True on success, otherwise False
*/
bool load_config(const std::string &file_path, bool verbose = false);
bool load_config(const std::string &file_path, bool local_config = false, bool verbose = false);
/**
* Function which appends a configuration file into the configuration object.
* @param file_path The path to the configuration file
* @param local_config True if the configuration file is a local config, else False
* @param verbose True to enable verbose logging, else False
* @return True on success, otherwise False
*/
bool append_config(const std::string &file_path, bool verbose = false);
bool append_config(const std::string &file_path, bool local_config = false, bool verbose = false);
Comment thread
dwolaver marked this conversation as resolved.
/**
* Function to check if local config exists
* @return True if the local config exists, else False
*/
bool has_local_config() const;
/**
* Function to check if object exists from a path
* @param path A period seperated string used to navigate a JSON object i.e. "network_rf4ce.polling.enabled"
Expand Down Expand Up @@ -83,6 +92,7 @@ class ctrlm_config_t {

private:
json_t *root;
bool local_config;
};

#endif
5 changes: 3 additions & 2 deletions src/ctrlm_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1614,16 +1614,17 @@ gboolean ctrlm_load_config(json_t **json_obj_root, json_t **json_obj_net_rf4ce,

// Check for OPT config file override
if(opt_append) {
bool local_config = true;
if(!oem_append) {
XLOGD_INFO("Loading OPT configuration from <%s>", config_fn_opt.c_str());
if(!ctrlm_config->load_config(config_fn_opt)) {
if(!ctrlm_config->load_config(config_fn_opt, local_config)) {
XLOGD_ERROR("Failed to load OPT configuration from <%s>", config_fn_opt.c_str());
return(false);
}
} else {
XLOGD_INFO("Appending OPT configuration from <%s>", config_fn_opt.c_str());

if(!ctrlm_config->append_config(config_fn_opt)) {
if(!ctrlm_config->append_config(config_fn_opt, local_config)) {
XLOGD_ERROR("Failed to append OPT configuration from <%s>", config_fn_opt.c_str());
return(false);
}
Expand Down
8 changes: 5 additions & 3 deletions src/rfc/ctrlm_rfc_attr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ bool ctrlm_rfc_attr_t::check_config_file(const std::string &path) const {
bool ret = false;
ctrlm_config_t *config = ctrlm_config_t::get_instance();
if(config) {
ret = config->path_exists(this->config_key + std::string(JSON_PATH_SEPERATOR) + path);
if(ret) {
XLOGD_DEBUG("%s exists in the config file", path.c_str());
if(config->has_local_config()) {
ret = config->path_exists(this->config_key + std::string(JSON_PATH_SEPERATOR) + path);
if(ret) {
XLOGD_WARN("%s exists in the config file", path.c_str());
Comment thread
dwolaver marked this conversation as resolved.
Comment thread
dwolaver marked this conversation as resolved.
Comment thread
dwolaver marked this conversation as resolved.
}
}
Comment thread
dwolaver marked this conversation as resolved.
} else {
XLOGD_ERROR("config object is NULL");
Expand Down
73 changes: 44 additions & 29 deletions src/voice/ctrlm_voice_obj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3959,7 +3959,8 @@ xrsr_power_mode_t voice_xrsr_power_map(ctrlm_power_state_t ctrlm_power_state) {

void ctrlm_voice_t::voice_rfc_retrieved_handler(const ctrlm_rfc_attr_t& attr) {
bool enabled = true;
bool reroute = false;

XLOGD_INFO("processing RFC values");

attr.get_rfc_value(JSON_INT_NAME_VOICE_VREX_REQUEST_TIMEOUT, this->prefs.timeout_vrex_connect,0);
attr.get_rfc_value(JSON_INT_NAME_VOICE_VREX_RESPONSE_TIMEOUT, this->prefs.timeout_vrex_session,0);
Expand Down Expand Up @@ -4007,22 +4008,34 @@ void ctrlm_voice_t::voice_rfc_retrieved_handler(const ctrlm_rfc_attr_t& attr) {
}

attr.get_rfc_value(JSON_INT_NAME_VOICE_PACKET_LOSS_THRESHOLD, this->packet_loss_threshold, 0);
if(attr.get_rfc_value(JSON_INT_NAME_VOICE_AUDIO_MODE, this->audio_mode) |
attr.get_rfc_value(JSON_INT_NAME_VOICE_AUDIO_TIMING, this->audio_timing) |
attr.get_rfc_value(JSON_FLOAT_NAME_VOICE_AUDIO_CONFIDENCE_THRESHOLD, this->audio_confidence_threshold, 0.0, 1.0) |
attr.get_rfc_value(JSON_INT_NAME_VOICE_AUDIO_DUCKING_TYPE, this->audio_ducking_type, CTRLM_VOICE_AUDIO_DUCKING_TYPE_ABSOLUTE, CTRLM_VOICE_AUDIO_DUCKING_TYPE_RELATIVE) |
attr.get_rfc_value(JSON_FLOAT_NAME_VOICE_AUDIO_DUCKING_LEVEL, this->audio_ducking_level, 0.0, 1.0) |
attr.get_rfc_value(JSON_BOOL_NAME_VOICE_AUDIO_DUCKING_BEEP, this->audio_ducking_beep_enabled)) {

bool audio_mode_updated = false;
audio_mode_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_AUDIO_MODE, this->audio_mode);
audio_mode_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_AUDIO_TIMING, this->audio_timing);
audio_mode_updated |= attr.get_rfc_value(JSON_FLOAT_NAME_VOICE_AUDIO_CONFIDENCE_THRESHOLD, this->audio_confidence_threshold, 0.0, 1.0);
audio_mode_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_AUDIO_DUCKING_TYPE, this->audio_ducking_type, CTRLM_VOICE_AUDIO_DUCKING_TYPE_ABSOLUTE, CTRLM_VOICE_AUDIO_DUCKING_TYPE_RELATIVE);
audio_mode_updated |= attr.get_rfc_value(JSON_FLOAT_NAME_VOICE_AUDIO_DUCKING_LEVEL, this->audio_ducking_level, 0.0, 1.0);

// JSON_BOOL_NAME_VOICE_AUDIO_DUCKING_BEEP is updated via Voice Control plugin so it cannot be overridden via RFC

Comment thread
dwolaver marked this conversation as resolved.
Comment thread
dwolaver marked this conversation as resolved.
XLOGD_INFO("audio mode updated <%s>", audio_mode_updated ? "YES" : "NO");

if(audio_mode_updated) {
Comment thread
dwolaver marked this conversation as resolved.
ctrlm_voice_audio_settings_t audio_settings = {this->audio_mode, this->audio_timing, this->audio_confidence_threshold, this->audio_ducking_type, this->audio_ducking_level, this->audio_ducking_beep_enabled};
this->set_audio_mode(&audio_settings);
}

// All attributes that need capture configuration to be set
if(attr.get_rfc_value(JSON_ARRAY_NAME_VOICE_SAVE_LAST_UTTERANCE, this->prefs.utterance_save, ctrlm_is_production_build() ? CTRLM_JSON_ARRAY_INDEX_PRD : CTRLM_JSON_ARRAY_INDEX_DEV) |
attr.get_rfc_value(JSON_BOOL_NAME_VOICE_UTTERANCE_USE_CURTAIL, this->prefs.utterance_use_curtail) |
attr.get_rfc_value(JSON_INT_NAME_VOICE_UTTERANCE_FILE_QTY_MAX, this->prefs.utterance_file_qty_max, 1, 100000) |
attr.get_rfc_value(JSON_INT_NAME_VOICE_UTTERANCE_FILE_SIZE_MAX, this->prefs.utterance_file_size_max, 4 * 1024) |
attr.get_rfc_value(JSON_STR_NAME_VOICE_UTTERANCE_PATH, this->prefs.utterance_path)) {
bool capture_config_updated = false;
capture_config_updated |= attr.get_rfc_value(JSON_ARRAY_NAME_VOICE_SAVE_LAST_UTTERANCE, this->prefs.utterance_save, ctrlm_is_production_build() ? CTRLM_JSON_ARRAY_INDEX_PRD : CTRLM_JSON_ARRAY_INDEX_DEV);
capture_config_updated |= attr.get_rfc_value(JSON_BOOL_NAME_VOICE_UTTERANCE_USE_CURTAIL, this->prefs.utterance_use_curtail);
capture_config_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_UTTERANCE_FILE_QTY_MAX, this->prefs.utterance_file_qty_max, 1, 100000);
capture_config_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_UTTERANCE_FILE_SIZE_MAX, this->prefs.utterance_file_size_max, 4 * 1024);
capture_config_updated |= attr.get_rfc_value(JSON_STR_NAME_VOICE_UTTERANCE_PATH, this->prefs.utterance_path);

XLOGD_INFO("capture config updated <%s>", capture_config_updated ? "YES" : "NO");

if(capture_config_updated) {
xrsr_capture_config_t capture_config = {
.delete_files = !this->prefs.utterance_save,
.enable = this->prefs.utterance_save,
Expand All @@ -4045,22 +4058,21 @@ void ctrlm_voice_t::voice_rfc_retrieved_handler(const ctrlm_rfc_attr_t& attr) {
}

// All attributes that need a re-route to apply
if(attr.get_rfc_value(JSON_INT_NAME_VOICE_MINIMUM_DURATION, this->prefs.utterance_duration_min) |
attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_STANDBY_CONNECT_CHECK_INTERVAL, this->prefs.dst_params_standby.connect_check_interval) |
attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_STANDBY_TIMEOUT_CONNECT, this->prefs.dst_params_standby.timeout_connect) |
attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_STANDBY_TIMEOUT_INACTIVITY, this->prefs.dst_params_standby.timeout_inactivity) |
attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_STANDBY_TIMEOUT_SESSION, this->prefs.dst_params_standby.timeout_session) |
attr.get_rfc_value(JSON_BOOL_NAME_VOICE_DST_PARAMS_STANDBY_IPV4_FALLBACK, this->prefs.dst_params_standby.ipv4_fallback) |
attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_STANDBY_BACKOFF_DELAY, this->prefs.dst_params_standby.backoff_delay) |
bool routing_config_updated = false;
routing_config_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_MINIMUM_DURATION, this->prefs.utterance_duration_min);
routing_config_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_STANDBY_CONNECT_CHECK_INTERVAL, this->prefs.dst_params_standby.connect_check_interval);
routing_config_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_STANDBY_TIMEOUT_CONNECT, this->prefs.dst_params_standby.timeout_connect);
routing_config_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_STANDBY_TIMEOUT_INACTIVITY, this->prefs.dst_params_standby.timeout_inactivity);
routing_config_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_STANDBY_TIMEOUT_SESSION, this->prefs.dst_params_standby.timeout_session);
routing_config_updated |= attr.get_rfc_value(JSON_BOOL_NAME_VOICE_DST_PARAMS_STANDBY_IPV4_FALLBACK, this->prefs.dst_params_standby.ipv4_fallback);
routing_config_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_STANDBY_BACKOFF_DELAY, this->prefs.dst_params_standby.backoff_delay);

attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_LOW_LATENCY_CONNECT_CHECK_INTERVAL, this->prefs.dst_params_low_latency.connect_check_interval) |
attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_LOW_LATENCY_TIMEOUT_CONNECT, this->prefs.dst_params_low_latency.timeout_connect) |
attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_LOW_LATENCY_TIMEOUT_INACTIVITY, this->prefs.dst_params_low_latency.timeout_inactivity) |
attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_LOW_LATENCY_TIMEOUT_SESSION, this->prefs.dst_params_low_latency.timeout_session) |
attr.get_rfc_value(JSON_BOOL_NAME_VOICE_DST_PARAMS_LOW_LATENCY_IPV4_FALLBACK, this->prefs.dst_params_low_latency.ipv4_fallback) |
attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_LOW_LATENCY_BACKOFF_DELAY, this->prefs.dst_params_low_latency.backoff_delay)) {
reroute = true;
}
routing_config_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_LOW_LATENCY_CONNECT_CHECK_INTERVAL, this->prefs.dst_params_low_latency.connect_check_interval);
routing_config_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_LOW_LATENCY_TIMEOUT_CONNECT, this->prefs.dst_params_low_latency.timeout_connect);
routing_config_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_LOW_LATENCY_TIMEOUT_INACTIVITY, this->prefs.dst_params_low_latency.timeout_inactivity);
routing_config_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_LOW_LATENCY_TIMEOUT_SESSION, this->prefs.dst_params_low_latency.timeout_session);
routing_config_updated |= attr.get_rfc_value(JSON_BOOL_NAME_VOICE_DST_PARAMS_LOW_LATENCY_IPV4_FALLBACK, this->prefs.dst_params_low_latency.ipv4_fallback);
routing_config_updated |= attr.get_rfc_value(JSON_INT_NAME_VOICE_DST_PARAMS_LOW_LATENCY_BACKOFF_DELAY, this->prefs.dst_params_low_latency.backoff_delay);

std::vector<std::string> obj_server_hosts;
if(attr.get_rfc_value(JSON_ARRAY_NAME_VOICE_SERVER_HOSTS, obj_server_hosts)) {
Expand All @@ -4078,9 +4090,12 @@ void ctrlm_voice_t::voice_rfc_retrieved_handler(const ctrlm_rfc_attr_t& attr) {
this->voice_device_disable((ctrlm_voice_device_t)i, true, NULL);
}
}
reroute = true;
routing_config_updated = true;
}
if(reroute) {

XLOGD_INFO("routing config updated <%s>", routing_config_updated ? "YES" : "NO");

if(routing_config_updated) {
this->voice_sdk_update_routes();
}
}
Expand Down
Loading