From e3c427ad288e41485c32a96c56e682b1566837be Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Fri, 8 Oct 2010 17:04:22 -0500 Subject: [PATCH] fix default ptime for iLBC and make new configurable global map in switch.conf.xml --- conf/autoload_configs/switch.conf.xml | 5 +++ src/include/private/switch_core_pvt.h | 1 + src/include/switch_core.h | 1 + src/include/switch_utils.h | 9 ----- src/switch_core.c | 47 +++++++++++++++++++++++++++ 5 files changed, 54 insertions(+), 9 deletions(-) diff --git a/conf/autoload_configs/switch.conf.xml b/conf/autoload_configs/switch.conf.xml index 7a68a7f2bd..e861b1b61a 100644 --- a/conf/autoload_configs/switch.conf.xml +++ b/conf/autoload_configs/switch.conf.xml @@ -15,6 +15,11 @@ + + + + + diff --git a/src/include/private/switch_core_pvt.h b/src/include/private/switch_core_pvt.h index 6a9bdc35a0..ea02f22fa0 100644 --- a/src/include/private/switch_core_pvt.h +++ b/src/include/private/switch_core_pvt.h @@ -199,6 +199,7 @@ struct switch_runtime { int64_t offset; switch_event_t *global_vars; switch_hash_t *mime_types; + switch_hash_t *ptimes; switch_memory_pool_t *memory_pool; const switch_state_handler_table_t *state_handlers[SWITCH_MAX_STATE_HANDLERS]; int state_handler_index; diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 04991ed186..3f636d00c4 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -2168,6 +2168,7 @@ SWITCH_DECLARE(uint32_t) switch_core_debug_level(void); SWITCH_DECLARE(void) switch_cache_db_flush_handles(void); SWITCH_DECLARE(const char *) switch_core_banner(void); SWITCH_DECLARE(switch_bool_t) switch_core_session_in_thread(switch_core_session_t *session); +SWITCH_DECLARE(uint32_t) switch_default_ptime(const char *name, uint32_t number); SWITCH_END_EXTERN_C #endif diff --git a/src/include/switch_utils.h b/src/include/switch_utils.h index e5d70c43cc..945583ee07 100644 --- a/src/include/switch_utils.h +++ b/src/include/switch_utils.h @@ -376,15 +376,6 @@ switch_mutex_unlock(obj->flag_mutex); #define switch_set_string(_dst, _src) switch_copy_string(_dst, _src, sizeof(_dst)) -static inline uint32_t switch_default_ptime(const char *name, uint32_t number) -{ - if (!strcasecmp(name, "G723")) { - return 30; - } - - return 20; -} - static inline char *switch_sanitize_number(char *number) { char *p = number, *q; diff --git a/src/switch_core.c b/src/switch_core.c index 2c33b341de..567fcfd14a 100644 --- a/src/switch_core.c +++ b/src/switch_core.c @@ -1275,6 +1275,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_init(switch_core_flag_t flags, switc switch_core_session_init(runtime.memory_pool); switch_event_create_plain(&runtime.global_vars, SWITCH_EVENT_CHANNEL_DATA); switch_core_hash_init(&runtime.mime_types, runtime.memory_pool); + switch_core_hash_init_case(&runtime.ptimes, runtime.memory_pool, SWITCH_FALSE); load_mime_types(); runtime.flags |= flags; runtime.sps_total = 30; @@ -1405,13 +1406,58 @@ static void handle_SIGHUP(int sig) } +SWITCH_DECLARE(uint32_t) switch_default_ptime(const char *name, uint32_t number) +{ + uint32_t *p; + + if ((p = switch_core_hash_find(runtime.ptimes, name))) { + return *p; + } + + return 20; +} + +static uint32_t d_30 = 30; + static void switch_load_core_config(const char *file) { switch_xml_t xml = NULL, cfg = NULL; + switch_core_hash_insert(runtime.ptimes, "ilbc", &d_30); + switch_core_hash_insert(runtime.ptimes, "G723", &d_30); + + + if ((xml = switch_xml_open_cfg(file, &cfg, NULL))) { switch_xml_t settings, param; + if ((settings = switch_xml_child(cfg, "default-ptimes"))) { + for (param = switch_xml_child(settings, "codec"); param; param = param->next) { + const char *var = switch_xml_attr_soft(param, "name"); + const char *val = switch_xml_attr_soft(param, "ptime"); + + if (!zstr(var) && !zstr(val)) { + uint32_t *p; + uint32_t v = (unsigned long) atol(val); + + if (!strcasecmp(var, "G723") || !strcasecmp(var, "iLBC")) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error adding %s, defaults cannot be changed\n", var); + continue; + } + + if (v < 0) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Error adding %s, invalid ptime\n", var); + continue; + } + + p = switch_core_alloc(runtime.memory_pool, sizeof(*p)); + *p = v; + switch_core_hash_insert(runtime.ptimes, var, p); + } + + } + } + if ((settings = switch_xml_child(cfg, "settings"))) { for (param = switch_xml_child(settings, "param"); param; param = param->next) { const char *var = switch_xml_attr_soft(param, "name"); @@ -1973,6 +2019,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_destroy(void) switch_safe_free(SWITCH_GLOBAL_dirs.temp_dir); switch_event_destroy(&runtime.global_vars); + switch_core_hash_destroy(&runtime.ptimes); switch_core_hash_destroy(&runtime.mime_types); if (IP_LIST.hash) {