From 9bbd9e769cf632ad636423c5a575c69e4472255b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 22 Oct 2013 20:49:44 +0500 Subject: [PATCH 01/13] FS-5900 --resolve wow, that's a good find --- src/switch_core_sqldb.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index a8d4c20379..b70444bf76 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -510,8 +510,6 @@ SWITCH_DECLARE(switch_status_t) _switch_cache_db_get_db_handle(switch_cache_db_h switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_DEBUG10, "Create Cached DB handle %s [%s] %s:%d\n", new_dbh->name, switch_cache_db_type_name(type), file, line); - new_dbh = create_handle(type); - if (db) { new_dbh->native_handle.core_db_dbh = db; } else if (odbc_dbh) { From dfce17d325516b6ed7563aa808da0e96e247e4a8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 22 Oct 2013 14:47:00 -0500 Subject: [PATCH 02/13] add in-memory use_count for fifo-events --- src/mod/applications/mod_fifo/mod_fifo.c | 130 ++++++++++++++++++++--- 1 file changed, 115 insertions(+), 15 deletions(-) diff --git a/src/mod/applications/mod_fifo/mod_fifo.c b/src/mod/applications/mod_fifo/mod_fifo.c index 5be2427df3..d3c7a87aa7 100644 --- a/src/mod/applications/mod_fifo/mod_fifo.c +++ b/src/mod/applications/mod_fifo/mod_fifo.c @@ -576,6 +576,8 @@ static struct { switch_hash_t *caller_orig_hash; switch_hash_t *consumer_orig_hash; switch_hash_t *bridge_hash; + switch_hash_t *use_hash; + switch_mutex_t *use_mutex; switch_mutex_t *caller_orig_mutex; switch_mutex_t *consumer_orig_mutex; switch_mutex_t *bridge_mutex; @@ -604,6 +606,66 @@ static struct { +static int fifo_dec_use_count(const char *outbound_id) +{ + int r = 0, *count; + + + switch_mutex_lock(globals.use_mutex); + if ((count = (int *) switch_core_hash_find(globals.use_hash, outbound_id))) { + if (*count > 0) { + r = --(*count); + } + } + switch_mutex_unlock(globals.use_mutex); + + return r; +} + +static int fifo_get_use_count(const char *outbound_id) +{ + int r = 0, *count; + + switch_mutex_lock(globals.use_mutex); + if ((count = (int *) switch_core_hash_find(globals.use_hash, outbound_id))) { + r = *count; + } + switch_mutex_unlock(globals.use_mutex); + + return r; +} + + +static int fifo_inc_use_count(const char *outbound_id) +{ + int r = 0, *count; + + switch_mutex_lock(globals.use_mutex); + if (!(count = (int *) switch_core_hash_find(globals.use_hash, outbound_id))) { + count = switch_core_alloc(globals.pool, sizeof(int)); + switch_core_hash_insert(globals.use_hash, outbound_id, count); + } + + r = ++(*count); + + switch_mutex_unlock(globals.use_mutex); + + return r; +} + +static void fifo_init_use_count(void) +{ + switch_mutex_lock(globals.use_mutex); + if (globals.use_hash) { + switch_core_hash_destroy(&globals.use_hash); + } + switch_core_hash_init(&globals.use_hash, globals.pool); + switch_mutex_unlock(globals.use_mutex); +} + + + + static int check_caller_outbound_call(const char *key) { int x = 0; @@ -961,10 +1023,16 @@ static void do_unbridge(switch_core_session_t *consumer_session, switch_core_ses const char *epoch_start_a = NULL; char *sql; switch_event_t *event; + const char *outbound_id = NULL; + int use_count = 0; switch_channel_clear_app_flag_key(FIFO_APP_KEY, consumer_channel, FIFO_APP_BRIDGE_TAG); switch_channel_set_variable(consumer_channel, "fifo_bridged", NULL); + if ((outbound_id = switch_channel_get_variable(consumer_channel, "fifo_outbound_uuid"))) { + use_count = fifo_get_use_count(outbound_id); + } + ts = switch_micro_time_now(); switch_time_exp_lt(&tm, ts); switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); @@ -999,6 +1067,10 @@ static void do_unbridge(switch_core_session_t *consumer_session, switch_core_ses switch_channel_event_set_data(consumer_channel, event); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-stop"); + if (use_count) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Consumer-Outbound-ID", outbound_id); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Consumer-Use-Count", "%d", use_count); + } switch_event_fire(&event); } @@ -1072,7 +1144,7 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_time_t ts; switch_time_exp_t tm; switch_size_t retsize; - const char *ced_name, *ced_number, *cid_name, *cid_number; + const char *ced_name, *ced_number, *cid_name, *cid_number, *outbound_id; if (switch_channel_test_app_flag_key(FIFO_APP_KEY, consumer_channel, FIFO_APP_BRIDGE_TAG)) { goto end; @@ -1083,6 +1155,7 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_channel_set_variable(consumer_channel, "fifo_bridged", "true"); switch_channel_set_variable(consumer_channel, "fifo_manual_bridge", "true"); switch_channel_set_variable(consumer_channel, "fifo_role", "consumer"); + outbound_id = switch_channel_get_variable(consumer_channel, "fifo_outbound_uuid"); if (caller_channel) { switch_channel_set_variable(caller_channel, "fifo_role", "caller"); @@ -1118,6 +1191,10 @@ static switch_status_t messagehook (switch_core_session_t *session, switch_core_ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-start"); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Caller-CID-Name", ced_name); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Caller-CID-Number", ced_number); + if (outbound_id) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Consumer-Outbound-ID", outbound_id); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Consumer-Use-Count", "%d", fifo_get_use_count(outbound_id)); + } switch_event_fire(&event); } @@ -2144,7 +2221,7 @@ SWITCH_STANDARD_API(fifo_add_outbound_function) static void dec_use_count(switch_core_session_t *session, switch_bool_t send_event) { char *sql; - const char *outbound_id; + const char *outbound_id = NULL; switch_event_t *event; long now = (long) switch_epoch_time_now(NULL); switch_channel_t *channel = switch_core_session_get_channel(session); @@ -2162,6 +2239,7 @@ static void dec_use_count(switch_core_session_t *session, switch_bool_t send_eve sql = switch_mprintf("update fifo_outbound set use_count=use_count-1, stop_time=%ld, next_avail=%ld + lag + 1 where use_count > 0 and uuid='%q'", now, now, outbound_id); fifo_execute_sql_queued(&sql, SWITCH_TRUE, SWITCH_TRUE); + fifo_dec_use_count(outbound_id); } if (send_event) { @@ -2169,6 +2247,10 @@ static void dec_use_count(switch_core_session_t *session, switch_bool_t send_eve switch_channel_event_set_data(channel, event); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", MANUAL_QUEUE_NAME); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "channel-consumer-stop"); + if (outbound_id) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Consumer-Outbound-ID", outbound_id); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Consumer-Use-Count", "%d", fifo_get_use_count(outbound_id)); + } switch_event_fire(&event); } } @@ -2229,7 +2311,7 @@ SWITCH_STANDARD_APP(fifo_track_call_function) sql = switch_mprintf("update fifo_outbound set stop_time=0,start_time=%ld,outbound_fail_count=0,use_count=use_count+1,%s=%s+1,%s=%s+1 where uuid='%q'", (long) switch_epoch_time_now(NULL), col1, col1, col2, col2, data); fifo_execute_sql_queued(&sql, SWITCH_TRUE, SWITCH_TRUE); - + fifo_inc_use_count(data); if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND) { cid_name = switch_channel_get_variable(channel, "destination_number"); @@ -2647,6 +2729,7 @@ SWITCH_STANDARD_APP(fifo_function) const char *url = NULL; const char *caller_uuid = NULL; const char *outbound_id = switch_channel_get_variable(channel, "fifo_outbound_uuid"); + //const char *track_use_count = switch_channel_get_variable(channel, "fifo_track_use_count"); //int do_track = switch_true(track_use_count); @@ -3051,18 +3134,6 @@ SWITCH_STANDARD_APP(fifo_function) switch_process_import(session, other_channel, "fifo_caller_consumer_import", switch_channel_get_variable(channel, "fifo_import_prefix")); switch_process_import(other_session, channel, "fifo_consumer_caller_import", switch_channel_get_variable(other_channel, "fifo_import_prefix")); - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(channel, event); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-start"); - switch_event_fire(&event); - } - if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { - switch_channel_event_set_data(other_channel, event); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); - switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start"); - switch_event_fire(&event); - } if (outbound_id) { cancel_consumer_outbound_call(outbound_id, SWITCH_CAUSE_ORIGINATOR_CANCEL); @@ -3073,8 +3144,29 @@ SWITCH_STANDARD_APP(fifo_function) fifo_execute_sql_queued(&sql, SWITCH_TRUE, SWITCH_TRUE); + fifo_inc_use_count(outbound_id); + } + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-start"); + if (outbound_id) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Consumer-Outbound-ID", outbound_id); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Consumer-Use-Count", "%d", fifo_get_use_count(outbound_id)); + } + + switch_event_fire(&event); + } + if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { + switch_channel_event_set_data(other_channel, event); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-caller-start"); + switch_event_fire(&event); + } + + add_bridge_call(switch_core_session_get_uuid(other_session)); add_bridge_call(switch_core_session_get_uuid(session)); @@ -3125,6 +3217,7 @@ SWITCH_STANDARD_APP(fifo_function) fifo_execute_sql_queued(&sql, SWITCH_TRUE, SWITCH_TRUE); del_bridge_call(outbound_id); + fifo_dec_use_count(outbound_id); } @@ -3136,6 +3229,10 @@ SWITCH_STANDARD_APP(fifo_function) switch_channel_event_set_data(channel, event); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Name", argv[0]); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-stop"); + if (outbound_id) { + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Consumer-Outbound-ID", outbound_id); + switch_event_add_header(event, SWITCH_STACK_BOTTOM, "FIFO-Consumer-Use-Count", "%d", fifo_get_use_count(outbound_id)); + } switch_event_fire(&event); } if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { @@ -4129,6 +4226,7 @@ static switch_status_t load_config(int reload, int del_all) if (!reload) { char *sql= "update fifo_outbound set start_time=0,stop_time=0,ring_count=0,use_count=0,outbound_call_count=0,outbound_fail_count=0 where static=0"; fifo_execute_sql_queued(&sql, SWITCH_FALSE, SWITCH_TRUE); + fifo_init_use_count(); } if (reload) { @@ -4547,11 +4645,13 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_fifo_load) switch_core_hash_init(&globals.caller_orig_hash, globals.pool); switch_core_hash_init(&globals.consumer_orig_hash, globals.pool); switch_core_hash_init(&globals.bridge_hash, globals.pool); + switch_core_hash_init(&globals.use_hash, globals.pool); switch_mutex_init(&globals.caller_orig_mutex, SWITCH_MUTEX_NESTED, globals.pool); switch_mutex_init(&globals.consumer_orig_mutex, SWITCH_MUTEX_NESTED, globals.pool); switch_mutex_init(&globals.bridge_mutex, SWITCH_MUTEX_NESTED, globals.pool); switch_mutex_init(&globals.mutex, SWITCH_MUTEX_NESTED, globals.pool); + switch_mutex_init(&globals.use_mutex, SWITCH_MUTEX_NESTED, globals.pool); switch_mutex_init(&globals.sql_mutex, SWITCH_MUTEX_NESTED, globals.pool); globals.running = 1; From 8715e03c1637c6b6a8d0ffdde8d8aa75a7e63b09 Mon Sep 17 00:00:00 2001 From: Brian West Date: Tue, 22 Oct 2013 15:44:50 -0500 Subject: [PATCH 03/13] Remove duplicated code --- src/mod/endpoints/mod_loopback/mod_loopback.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/mod/endpoints/mod_loopback/mod_loopback.c b/src/mod/endpoints/mod_loopback/mod_loopback.c index c6cbfc8994..90e5cca989 100644 --- a/src/mod/endpoints/mod_loopback/mod_loopback.c +++ b/src/mod/endpoints/mod_loopback/mod_loopback.c @@ -486,7 +486,6 @@ static switch_status_t channel_on_destroy(switch_core_session_t *session) { switch_channel_t *channel = NULL; loopback_private_t *tech_pvt = NULL; - void *pop; switch_event_t *vars; channel = switch_core_session_get_channel(session); @@ -514,10 +513,7 @@ static switch_status_t channel_on_destroy(switch_core_session_t *session) switch_frame_free(&tech_pvt->write_frame); } - while (switch_queue_trypop(tech_pvt->frame_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) { - switch_frame_t *frame = (switch_frame_t *) pop; - switch_frame_free(&frame); - } + clear_queue(tech_pvt); } From 1594887613c1b67060f30492632936642f679854 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 Oct 2013 03:03:21 +0500 Subject: [PATCH 04/13] delete resources on csv mod shutdown --- .../event_handlers/mod_cdr_csv/mod_cdr_csv.c | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c b/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c index a268e8d158..4e6083086a 100644 --- a/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c +++ b/src/mod/event_handlers/mod_cdr_csv/mod_cdr_csv.c @@ -290,6 +290,26 @@ static void do_rotate_all() } +static void do_teardown() +{ + switch_hash_index_t *hi; + void *val; + cdr_fd_t *fd; + switch_mutex_lock(globals.mutex); + for (hi = switch_hash_first(NULL, globals.fd_hash); hi; hi = switch_hash_next(hi)) { + switch_hash_this(hi, NULL, NULL, &val); + fd = (cdr_fd_t *) val; + switch_mutex_lock(fd->mutex); + if (fd->fd > -1) { + close(fd->fd); + fd->fd = -1; + } + switch_mutex_unlock(fd->mutex); + } + switch_mutex_unlock(globals.mutex); +} + + static void event_handler(switch_event_t *event) { const char *sig = switch_event_get_header(event, "Trapped-Signal"); @@ -445,6 +465,9 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_cdr_csv_shutdown) switch_event_unbind_callback(event_handler); switch_core_remove_state_handler(&state_handlers); + do_teardown(); + switch_core_hash_destroy(&globals.fd_hash); + switch_core_hash_destroy(&globals.template_hash); return SWITCH_STATUS_SUCCESS; } From 5dbc5ff066461d5c1fc33626ffbc11a0a8fa4771 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Thu, 17 Oct 2013 00:40:18 +0000 Subject: [PATCH 05/13] Add option to use pkg-config rather than pg_config We shouldn't be using pg_config to get build options for FS from libpq. pg_config just tells us what was used to build postgresql, not what we should use. See: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=725007 Make this optional for now until we're comfortable it works everywhere. FS-5821 --resolve --- configure.in | 61 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 24 deletions(-) diff --git a/configure.in b/configure.in index b3d3cc6509..312c18c4b6 100644 --- a/configure.in +++ b/configure.in @@ -413,32 +413,45 @@ SWITCH_AM_CFLAGS="$LIBUUID_CFLAGS $SWITCH_AM_CFLAGS" AC_ARG_ENABLE(core-pgsql-support, [AS_HELP_STRING([--enable-core-pgsql-support], [Compile with PGSQL Support])],,[enable_core_pgsql_support="no"]) +AC_ARG_ENABLE(core-pgsql-pkgconfig, + [AS_HELP_STRING([--enable-core-pgsql-pkgconfig], [Use pkg-config to get PGQSL build options])],,[enable_core_pgsql_pkgconfig="no"]) if test x"$enable_core_pgsql_support" = x"yes" ; then - -AC_PATH_PROG([PG_CONFIG], [pg_config], [no]) -if test "$PG_CONFIG" != "no"; then - AC_MSG_CHECKING([for PostgreSQL libraries]) - POSTGRESQL_CXXFLAGS="`$PG_CONFIG --cppflags` -I`$PG_CONFIG --includedir`" - POSTGRESQL_LDFLAGS="`$PG_CONFIG --ldflags|sed 's/ -Wl,--as-needed//g'` -L`$PG_CONFIG --libdir` -lpq" - POSTGRESQL_VERSION=`$PG_CONFIG --version | sed -e 's#PostgreSQL ##'` - POSTGRESQL_MAJOR_VERSION=`$PG_CONFIG --version | sed -e 's/devel//' | sed -re 's#PostgreSQL ([0-9]+).[0-9]+.?[0-9]+?#\1#'` - POSTGRESQL_MINOR_VERSION=`$PG_CONFIG --version | sed -e 's/devel//' | sed -re 's#PostgreSQL [0-9]+.([0-9]+).?[0-9]+?#\1#'` - POSTGRESQL_PATCH_VERSION=`$PG_CONFIG --version | sed -e 's/devel//' | sed -re 's#PostgreSQL [0-9]+.[0-9]+.?([0-9]+)?#\1#'` - AC_DEFINE([SWITCH_HAVE_PGSQL], [1], [Define to 1 if PostgreSQL libraries are available]) - AC_DEFINE_UNQUOTED([POSTGRESQL_VERSION], "${POSTGRESQL_VERSION}", [Specifies the version of PostgreSQL we are linking against]) - AC_DEFINE_UNQUOTED([POSTGRESQL_MAJOR_VERSION], ${POSTGRESQL_MAJOR_VERSION}, [Specifies the version of PostgreSQL we are linking against]) - AC_DEFINE_UNQUOTED([POSTGRESQL_MINOR_VERSION], ${POSTGRESQL_MINOR_VERSION}, [Specifies the version of PostgreSQL we are linking against]) - AC_DEFINE_UNQUOTED([POSTGRESQL_PATCH_VERSION], ${POSTGRESQL_PATCH_VERSION}, [Specifies the version of PostgreSQL we are linking against]) - AC_CHECK_LIB([pq], [PQgetvalue],, AC_MSG_ERROR([no usable libpq; please install PostgreSQL devel package or equivalent])) - AC_MSG_RESULT([yes]) - SWITCH_AM_CXXFLAGS="$POSTGRESQL_CXXFLAGS $SWITCH_AM_CXXFLAGS" - SWITCH_AM_LDFLAGS="$POSTGRESQL_LDFLAGS $SWITCH_AM_LDFLAGS" -else - AC_MSG_RESULT([no]) - AC_MSG_FAILURE([Unabled to find pg_config in PATH. Is PostgreSQL installed?]) -fi - + AC_PATH_PROG([PG_CONFIG], [pg_config], [no]) + AC_PATH_PROG([PKG_CONFIG], [pkg-config], [no]) + if test "$PG_CONFIG" = "no"; then + AC_MSG_RESULT([no]) + AC_MSG_FAILURE([Unabled to find pg_config in PATH. Is PostgreSQL installed?]) + else + if test "$PKG_CONFIG" = "no" \ + || test x"$enable_core_pgsql_pkgconfig" = x"no" \ + || ! pkg-config libpq; then + AC_MSG_CHECKING([for PostgreSQL libraries]) + POSTGRESQL_CXXFLAGS="`$PG_CONFIG --cppflags` -I`$PG_CONFIG --includedir`" + POSTGRESQL_LDFLAGS="`$PG_CONFIG --ldflags|sed 's/ -Wl,--as-needed//g'` -L`$PG_CONFIG --libdir` -lpq" + POSTGRESQL_VERSION=`$PG_CONFIG --version | sed -e 's#PostgreSQL ##'` + POSTGRESQL_MAJOR_VERSION=`$PG_CONFIG --version | sed -e 's/devel//' | sed -re 's#PostgreSQL ([0-9]+).[0-9]+.?[0-9]+?#\1#'` + POSTGRESQL_MINOR_VERSION=`$PG_CONFIG --version | sed -e 's/devel//' | sed -re 's#PostgreSQL [0-9]+.([0-9]+).?[0-9]+?#\1#'` + POSTGRESQL_PATCH_VERSION=`$PG_CONFIG --version | sed -e 's/devel//' | sed -re 's#PostgreSQL [0-9]+.[0-9]+.?([0-9]+)?#\1#'` + else + AC_MSG_CHECKING([for PostgreSQL libraries]) + POSTGRESQL_CXXFLAGS="`$PKG_CONFIG --cflags libpq`" + POSTGRESQL_LDFLAGS="`$PKG_CONFIG --libs libpq`" + POSTGRESQL_VERSION="`$PKG_CONFIG --modversion libpq`" + POSTGRESQL_MAJOR_VERSION="`echo $POSTGRESQL_VERSION | cut -d. -f1`" + POSTGRESQL_MINOR_VERSION="`echo $POSTGRESQL_VERSION | cut -d. -f2`" + POSTGRESQL_PATCH_VERSION="`echo $POSTGRESQL_VERSION | cut -d. -f3`" + fi + AC_DEFINE([SWITCH_HAVE_PGSQL], [1], [Define to 1 if PostgreSQL libraries are available]) + AC_DEFINE_UNQUOTED([POSTGRESQL_VERSION], "${POSTGRESQL_VERSION}", [Specifies the version of PostgreSQL we are linking against]) + AC_DEFINE_UNQUOTED([POSTGRESQL_MAJOR_VERSION], ${POSTGRESQL_MAJOR_VERSION}, [Specifies the version of PostgreSQL we are linking against]) + AC_DEFINE_UNQUOTED([POSTGRESQL_MINOR_VERSION], ${POSTGRESQL_MINOR_VERSION}, [Specifies the version of PostgreSQL we are linking against]) + AC_DEFINE_UNQUOTED([POSTGRESQL_PATCH_VERSION], ${POSTGRESQL_PATCH_VERSION}, [Specifies the version of PostgreSQL we are linking against]) + AC_CHECK_LIB([pq], [PQgetvalue],, AC_MSG_ERROR([no usable libpq; please install PostgreSQL devel package or equivalent])) + AC_MSG_RESULT([yes]) + SWITCH_AM_CXXFLAGS="$POSTGRESQL_CXXFLAGS $SWITCH_AM_CXXFLAGS" + SWITCH_AM_LDFLAGS="$POSTGRESQL_LDFLAGS $SWITCH_AM_LDFLAGS" + fi fi AC_ARG_ENABLE(deprecated-core-db-events, From 73a3d59d56e4b61d098a4c11f9971970c4890e49 Mon Sep 17 00:00:00 2001 From: Travis Cross Date: Thu, 17 Oct 2013 00:54:18 +0000 Subject: [PATCH 06/13] Use pkg-config for libpq by default FS-5821 --resolve --- configure.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure.in b/configure.in index 312c18c4b6..a501eaa28e 100644 --- a/configure.in +++ b/configure.in @@ -414,7 +414,7 @@ SWITCH_AM_CFLAGS="$LIBUUID_CFLAGS $SWITCH_AM_CFLAGS" AC_ARG_ENABLE(core-pgsql-support, [AS_HELP_STRING([--enable-core-pgsql-support], [Compile with PGSQL Support])],,[enable_core_pgsql_support="no"]) AC_ARG_ENABLE(core-pgsql-pkgconfig, - [AS_HELP_STRING([--enable-core-pgsql-pkgconfig], [Use pkg-config to get PGQSL build options])],,[enable_core_pgsql_pkgconfig="no"]) + [AS_HELP_STRING([--disable-core-pgsql-pkgconfig], [Use pg_config to get PGQSL build options])],[enable_core_pgsql_pkgconfig="$enableval"],[enable_core_pgsql_pkgconfig="yes"]) if test x"$enable_core_pgsql_support" = x"yes" ; then AC_PATH_PROG([PG_CONFIG], [pg_config], [no]) From 3482cd5b8005324c8a34ed2af4ca983119720871 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 Oct 2013 16:39:20 -0500 Subject: [PATCH 07/13] use the actual_sps not the effective on codec load strings --- src/switch_loadable_module.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index 8ffe90ea11..aad958f983 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -186,10 +186,18 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable } if (load_interface) { for (impl = ptr->implementations; impl; impl = impl->next) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, - "Adding Codec %s %d %s %dhz %dms %dbps\n", - impl->iananame, impl->ianacode, - ptr->interface_name, impl->actual_samples_per_second, impl->microseconds_per_packet / 1000, impl->bits_per_second); + if (impl->bits_per_second) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, + "Adding Codec %s %d %s %dhz %dms %dbps\n", + impl->iananame, impl->ianacode, + ptr->interface_name, impl->actual_samples_per_second, + impl->microseconds_per_packet / 1000, impl->bits_per_second); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, + "Adding Codec %s %d %s %dhz %dms (VBR)\n", + impl->iananame, impl->ianacode, + ptr->interface_name, impl->actual_samples_per_second, impl->microseconds_per_packet / 1000); + } if (!switch_core_hash_find(loadable_modules.codec_hash, impl->iananame)) { switch_core_hash_insert(loadable_modules.codec_hash, impl->iananame, (const void *) ptr); } @@ -2249,7 +2257,7 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_ continue; } - if (((!rate && (uint32_t) imp->samples_per_second != default_rate) || (rate && (uint32_t) imp->samples_per_second != rate))) { + if (((!rate && (uint32_t) imp->actual_samples_per_second != default_rate) || (rate && (uint32_t) imp->actual_samples_per_second != rate))) { continue; } @@ -2273,7 +2281,7 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_ continue; } - if (rate && (uint32_t) imp->samples_per_second != rate) { + if (rate && (uint32_t) imp->actual_samples_per_second != rate) { continue; } From 82c27013d742c8b3d5800d489aaa889b2dad4c3f Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 Oct 2013 05:04:23 +0500 Subject: [PATCH 08/13] make exception for g722 --- src/switch_core_codec.c | 6 ++++-- src/switch_loadable_module.c | 8 +++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/switch_core_codec.c b/src/switch_core_codec.c index 514204dbe4..935f621de0 100644 --- a/src/switch_core_codec.c +++ b/src/switch_core_codec.c @@ -658,7 +658,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_init_with_bitrate(switch_codec /* If no specific codec interval is requested opt for 20ms above all else because lots of stuff assumes it */ if (!ms) { for (iptr = codec_interface->implementations; iptr; iptr = iptr->next) { - if ((!rate || rate == iptr->samples_per_second) && (!bitrate || bitrate == (uint32_t)iptr->bits_per_second) && + uint32_t crate = !strcasecmp(codec_name, "g722") ? iptr->samples_per_second : iptr->actual_samples_per_second; + if ((!rate || rate == crate) && (!bitrate || bitrate == (uint32_t)iptr->bits_per_second) && (20 == (iptr->microseconds_per_packet / 1000)) && (!channels || channels == iptr->number_of_channels)) { implementation = iptr; goto found; @@ -668,7 +669,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_init_with_bitrate(switch_codec /* Either looking for a specific interval or there was no interval specified and there wasn't one @20ms available */ for (iptr = codec_interface->implementations; iptr; iptr = iptr->next) { - if ((!rate || rate == iptr->samples_per_second) && (!bitrate || bitrate == (uint32_t)iptr->bits_per_second) && + uint32_t crate = !strcasecmp(codec_name, "g722") ? iptr->samples_per_second : iptr->actual_samples_per_second; + if ((!rate || rate == crate) && (!bitrate || bitrate == (uint32_t)iptr->bits_per_second) && (!ms || ms == (iptr->microseconds_per_packet / 1000)) && (!channels || channels == iptr->number_of_channels)) { implementation = iptr; break; diff --git a/src/switch_loadable_module.c b/src/switch_loadable_module.c index aad958f983..26c80909e4 100644 --- a/src/switch_loadable_module.c +++ b/src/switch_loadable_module.c @@ -2251,13 +2251,14 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_ uint32_t default_rate = switch_default_rate(imp->iananame, imp->ianacode); if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) { - + uint32_t crate = !strcasecmp(imp->iananame, "g722") ? imp->samples_per_second : imp->actual_samples_per_second; + if ((!interval && (uint32_t) (imp->microseconds_per_packet / 1000) != default_ptime) || (interval && (uint32_t) (imp->microseconds_per_packet / 1000) != interval)) { continue; } - if (((!rate && (uint32_t) imp->actual_samples_per_second != default_rate) || (rate && (uint32_t) imp->actual_samples_per_second != rate))) { + if (((!rate && crate != default_rate) || (rate && (uint32_t) imp->actual_samples_per_second != rate))) { continue; } @@ -2276,12 +2277,13 @@ SWITCH_DECLARE(int) switch_loadable_module_get_codecs_sorted(const switch_codec_ /* Either looking for a specific interval or there was no interval specified and there wasn't one at the default ptime available */ for (imp = codec_interface->implementations; imp; imp = imp->next) { if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) { + uint32_t crate = !strcasecmp(imp->iananame, "g722") ? imp->samples_per_second : imp->actual_samples_per_second; if (interval && (uint32_t) (imp->microseconds_per_packet / 1000) != interval) { continue; } - if (rate && (uint32_t) imp->actual_samples_per_second != rate) { + if (rate && (uint32_t) crate != rate) { continue; } From 9e77e6f3923eda774eb2d46b79679e937fd9fbae Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 Oct 2013 20:45:29 -0500 Subject: [PATCH 09/13] device state tweaks --- src/include/switch_core.h | 22 ++++++++++ src/switch_channel.c | 89 ++++++++++++++++++++++++++++++++++++--- 2 files changed, 106 insertions(+), 5 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 6d7d37e3bd..db3e67c5a8 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -82,18 +82,33 @@ typedef struct device_uuid_node_s { switch_channel_callstate_t callstate; switch_hold_record_t *hold_record; switch_caller_profile_t *hup_profile; + switch_call_direction_t direction; struct switch_device_record_s *parent; struct device_uuid_node_s *next; } switch_device_node_t; typedef struct switch_device_stats_s { uint32_t total; + uint32_t total_in; + uint32_t total_out; uint32_t offhook; + uint32_t offhook_in; + uint32_t offhook_out; uint32_t active; + uint32_t active_in; + uint32_t active_out; uint32_t held; + uint32_t held_in; + uint32_t held_out; uint32_t hup; + uint32_t hup_in; + uint32_t hup_out; uint32_t ringing; + uint32_t ringing_in; + uint32_t ringing_out; uint32_t early; + uint32_t early_in; + uint32_t early_out; } switch_device_stats_t; @@ -102,15 +117,22 @@ typedef struct switch_device_record_s { char *uuid; int refs; switch_device_stats_t stats; + switch_device_stats_t last_stats; switch_device_state_t state; switch_device_state_t last_state; switch_time_t active_start; switch_time_t active_stop; switch_time_t last_call_time; + switch_time_t ring_start; + switch_time_t ring_stop; + switch_time_t hold_start; + switch_time_t hold_stop; + switch_time_t call_start; struct device_uuid_node_s *uuid_list; struct device_uuid_node_s *uuid_tail; switch_mutex_t *mutex; switch_memory_pool_t *pool; + void *user_data; } switch_device_record_t; typedef void(*switch_device_state_function_t)(switch_core_session_t *session, switch_channel_callstate_t callstate, switch_device_record_t *drec); diff --git a/src/switch_channel.c b/src/switch_channel.c index be9e31b1d8..9e2cfcfdc8 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -277,7 +277,11 @@ SWITCH_DECLARE(void) switch_channel_perform_set_callstate(switch_channel_t *chan switch_channel_callstate2str(o_callstate), switch_channel_callstate2str(callstate)); switch_channel_check_device_state(channel, channel->callstate); - + + if (callstate == CCS_HANGUP) { + process_device_hup(channel); + } + if (switch_event_create(&event, SWITCH_EVENT_CHANNEL_CALLSTATE) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Original-Channel-Call-State", switch_channel_callstate2str(o_callstate)); switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Call-State-Number", "%d", callstate); @@ -3102,8 +3106,6 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_hangup(switch_chan channel->state = CS_HANGUP; switch_mutex_unlock(channel->state_mutex); - process_device_hup(channel); - channel->hangup_cause = hangup_cause; switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, switch_channel_get_uuid(channel), SWITCH_LOG_NOTICE, "Hangup %s [%s] [%s]\n", channel->name, state_names[last_state], switch_channel_cause2str(channel->hangup_cause)); @@ -4614,28 +4616,64 @@ static void fetch_device_stats(switch_device_record_t *drec) { switch_device_node_t *np; + memset(&drec->stats, 0, sizeof(switch_device_stats_t)); switch_mutex_lock(drec->mutex); for(np = drec->uuid_list; np; np = np->next) { drec->stats.total++; + if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) { + drec->stats.total_in++; + } else { + drec->stats.total_out++; + } if (!np->hup_profile) { drec->stats.offhook++; + if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) { + drec->stats.offhook_in++; + } else { + drec->stats.offhook_out++; + } if (np->callstate == CCS_HELD) { drec->stats.held++; + if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) { + drec->stats.held_in++; + } else { + drec->stats.held_out++; + } } else { if (np->callstate == CCS_EARLY) { drec->stats.early++; + if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) { + drec->stats.early_in++; + } else { + drec->stats.early_out++; + } } else if (np->callstate == CCS_RINGING) { drec->stats.ringing++; + if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) { + drec->stats.ringing_in++; + } else { + drec->stats.ringing_out++; + } } else if (np->callstate != CCS_DOWN) { drec->stats.active++; + if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) { + drec->stats.active_in++; + } else { + drec->stats.active_out++; + } } } } else { drec->stats.hup++; + if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) { + drec->stats.hup_in++; + } else { + drec->stats.hup_out++; + } } } switch_mutex_unlock(drec->mutex); @@ -4776,7 +4814,7 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_ drec->state = SDS_HANGUP; } else { if (drec->stats.active == 0) { - if ((drec->stats.ringing + drec->stats.early) > 0) { + if ((drec->stats.ringing_out + drec->stats.early_out) > 0) { drec->state = SDS_RINGING; } else { if (drec->stats.held > 0) { @@ -4798,7 +4836,15 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_ return; } + if (!drec->call_start) { + drec->call_start = switch_micro_time_now(); + } + switch(drec->state) { + case SDS_RINGING: + drec->ring_start = switch_micro_time_now(); + drec->ring_stop = 0; + break; case SDS_ACTIVE: case SDS_ACTIVE_MULTI: if (drec->last_state != SDS_HELD && drec->active_start) { @@ -4807,6 +4853,9 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_ drec->active_start = switch_micro_time_now(); } break; + case SDS_HELD: + drec->hold_start = switch_micro_time_now(); + drec->hold_stop = 0; default: if (drec->last_state != SDS_HELD) { drec->active_stop = switch_micro_time_now(); @@ -4814,6 +4863,15 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_ break; } + if (drec->ring_start && !drec->ring_stop && drec->state != SDS_RINGING) { + drec->ring_stop = switch_micro_time_now(); + } + + if (drec->hold_start && !drec->hold_stop && drec->state != SDS_HELD) { + drec->hold_stop = switch_micro_time_now(); + } + + if (switch_event_create(&event, SWITCH_EVENT_DEVICE_STATE) == SWITCH_STATUS_SUCCESS) { switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Device-ID", drec->device_id); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Last-Device-State", switch_channel_device_state2str(drec->last_state)); @@ -4834,7 +4892,8 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_ } switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, - "%s device: %s\nState: %s Dev State: %s/%s Total:%u Offhook:%u Ringing:%u Early:%u Active:%u Held:%u Hungup:%u Dur: %u %s\n", + "%s device: %s\nState: %s Dev State: %s/%s Total:%u Offhook:%u " + "Ringing:%u Early:%u Active:%u Held:%u Hungup:%u Dur: %u Ringtime: %u Holdtime: %u %s\n", switch_channel_get_name(channel), drec->device_id, switch_channel_callstate2str(callstate), @@ -4848,12 +4907,16 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_ drec->stats.held, drec->stats.hup, drec->active_stop ? (uint32_t)(drec->active_stop - drec->active_start) / 1000 : 0, + drec->ring_stop ? (uint32_t)(drec->ring_stop - drec->ring_start) / 1000 : 0, + drec->hold_stop ? (uint32_t)(drec->hold_stop - drec->hold_start) / 1000 : 0, switch_channel_test_flag(channel, CF_FINAL_DEVICE_LEG) ? "FINAL LEG" : ""); for (ptr = globals.device_bindings; ptr; ptr = ptr->next) { ptr->function(channel->session, callstate, drec); } + drec->last_stats = drec->stats; + if (drec->active_stop) { drec->active_start = drec->active_stop = 0; if (drec->state == SDS_ACTIVE || drec->state == SDS_ACTIVE_MULTI) { @@ -4861,6 +4924,20 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_ } } + if (drec->hold_stop) { + drec->hold_start = drec->hold_stop = 0; + if (drec->state == SDS_HELD) { + drec->hold_start = switch_micro_time_now(); + } + } + + if (drec->ring_stop) { + drec->ring_start = drec->ring_stop = 0; + if (drec->state == SDS_RINGING) { + drec->ring_start = switch_micro_time_now(); + } + } + drec->last_call_time = switch_micro_time_now(); drec->last_state = drec->state; @@ -4888,6 +4965,8 @@ static void add_uuid(switch_device_record_t *drec, switch_channel_t *channel) node->uuid = switch_core_strdup(drec->pool, switch_core_session_get_uuid(channel->session)); node->parent = drec; node->callstate = channel->callstate; + node->direction = channel->direction == SWITCH_CALL_DIRECTION_INBOUND ? SWITCH_CALL_DIRECTION_OUTBOUND : SWITCH_CALL_DIRECTION_INBOUND; + channel->device_node = node; if (!drec->uuid_list) { From 2d7af9beef89e63a2d9518c31a58a4007fde7593 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 Oct 2013 23:09:14 -0500 Subject: [PATCH 10/13] tweak to devstate --- src/switch_channel.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/switch_channel.c b/src/switch_channel.c index 9e2cfcfdc8..ae0634d802 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -4658,6 +4658,13 @@ static void fetch_device_stats(switch_device_record_t *drec) } else { drec->stats.ringing_out++; } + } else if (np->callstate == CCS_HANGUP) { + drec->stats.hup++; + if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) { + drec->stats.hup_in++; + } else { + drec->stats.hup_out++; + } } else if (np->callstate != CCS_DOWN) { drec->stats.active++; if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) { From 6f4ed1221323498c1461e43c9960ae1de5c883c8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Wed, 23 Oct 2013 23:21:31 -0500 Subject: [PATCH 11/13] missed a spot --- src/switch_channel.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/switch_channel.c b/src/switch_channel.c index ae0634d802..5f53b22a7a 100644 --- a/src/switch_channel.c +++ b/src/switch_channel.c @@ -4854,7 +4854,7 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_ break; case SDS_ACTIVE: case SDS_ACTIVE_MULTI: - if (drec->last_state != SDS_HELD && drec->active_start) { + if (drec->active_start && drec->last_state != SDS_HELD) { drec->active_stop = switch_micro_time_now(); } else if (!drec->active_start) { drec->active_start = switch_micro_time_now(); @@ -4864,7 +4864,7 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_ drec->hold_start = switch_micro_time_now(); drec->hold_stop = 0; default: - if (drec->last_state != SDS_HELD) { + if (drec->active_start && drec->last_state != SDS_HELD) { drec->active_stop = switch_micro_time_now(); } break; From 6600b0fae077aee0fe07bc9d31c63ead4c5abac1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 Oct 2013 12:19:29 +0500 Subject: [PATCH 12/13] change codec negotiation for edge opus cases --- src/mod/endpoints/mod_sofia/mod_sofia.h | 1 + src/mod/endpoints/mod_sofia/sofia_glue.c | 29 +++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 567ee00ae5..fa826c54fc 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -804,6 +804,7 @@ struct private_object { switch_port_t stun_port; uint32_t stun_flags; unsigned long rm_rate; + unsigned long adv_rm_rate; switch_payload_t pt; switch_mutex_t *flag_mutex; switch_mutex_t *sofia_mutex; diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index e54beabd3d..9839688ca0 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -545,7 +545,7 @@ void sofia_glue_set_local_sdp(private_object_t *tech_pvt, const char *ip, switch switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "\n"); - rate = tech_pvt->rm_rate; + rate = tech_pvt->adv_rm_rate; if (tech_pvt->adv_channels > 1) { switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtpmap:%d %s/%d/%d\n", @@ -1755,6 +1755,7 @@ void sofia_glue_tech_patch_sdp(private_object_t *tech_pvt) } tech_pvt->iananame = switch_core_session_strdup(tech_pvt->session, "PROXY"); tech_pvt->rm_rate = 8000; + tech_pvt->adv_rm_rate = 8000; tech_pvt->codec_ms = 20; } @@ -4666,6 +4667,7 @@ void sofia_glue_proxy_codec(switch_core_session_t *session, const char *r_sdp) for (map = m->m_rtpmaps; map; map = map->rm_next) { tech_pvt->iananame = switch_core_session_strdup(tech_pvt->session, map->rm_encoding); tech_pvt->rm_rate = map->rm_rate; + tech_pvt->adv_rm_rate = map->rm_rate; tech_pvt->codec_ms = ptime; sofia_glue_tech_set_codec(tech_pvt, 0); break; @@ -4750,7 +4752,7 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s int reneg = 1; const switch_codec_implementation_t **codec_array; int total_codecs; - + char *samp = NULL; codec_array = tech_pvt->codecs; total_codecs = tech_pvt->num_codecs; @@ -5273,6 +5275,20 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s match = 0; } + if (!zstr(map->rm_fmtp)) { + samp = strstr(map->rm_fmtp, "samplerate="); + } + if (!strcasecmp(map->rm_encoding, "opus") && !strcasecmp(rm_encoding, imp->iananame) && samp) { + char *rate_str = samp + 11; + + if (rate_str && *rate_str) { + near_rate = atoi(rate_str); + near_match = imp; + match = 0; + goto near_match; + } + } + if (match) { if (scrooge) { switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, @@ -5291,6 +5307,8 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s } } + near_match: + if (!match && near_match) { const switch_codec_implementation_t *search[1]; char *prefs[1]; @@ -5302,7 +5320,7 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s prefs[0] = tmp; num = switch_loadable_module_get_codecs_sorted(search, 1, prefs, 1); - + if (num) { mimp = search[0]; } else { @@ -5333,6 +5351,10 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s tech_pvt->iananame = switch_core_session_strdup(session, (char *) mimp->iananame); tech_pvt->pt = (switch_payload_t) map->rm_pt; tech_pvt->rm_rate = mimp->samples_per_second; + tech_pvt->adv_rm_rate = mimp->samples_per_second; + if (strcasecmp(mimp->iananame, "g722")) { + tech_pvt->rm_rate = mimp->actual_samples_per_second; + } tech_pvt->codec_ms = mimp->microseconds_per_packet / 1000; tech_pvt->bitrate = mimp->bits_per_second; tech_pvt->remote_sdp_audio_ip = switch_core_session_strdup(session, (char *) connection->c_address); @@ -6131,6 +6153,7 @@ int sofia_recover_callback(switch_core_session_t *session) if ((tmp = switch_channel_get_variable(channel, "sip_use_codec_rate"))) { tech_pvt->rm_rate = atoi(tmp); + tech_pvt->adv_rm_rate = tech_pvt->rm_rate; } if ((tmp = switch_channel_get_variable(channel, "sip_use_codec_ptime"))) { From 7d8ff1e1d7dfb1c89959dbd55b9e6187b1176eb8 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 24 Oct 2013 23:55:07 +0500 Subject: [PATCH 13/13] tweak api --- src/switch_core_session.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/switch_core_session.c b/src/switch_core_session.c index 60358ca0dd..f32fe00f8f 100644 --- a/src/switch_core_session.c +++ b/src/switch_core_session.c @@ -264,12 +264,14 @@ SWITCH_DECLARE(switch_console_callback_match_t *) switch_core_session_findall_ma switch_memory_pool_t *pool; struct str_node *head = NULL, *np; switch_console_callback_match_t *my_matches = NULL; + const char *like = NULL; + + if (var_val && *var_val == '~') { + like = var_val + 1; + } switch_core_new_memory_pool(&pool); - if (!var_val) - return NULL; - switch_mutex_lock(runtime.session_hash_mutex); for (hi = switch_hash_first(NULL, session_manager.session_table); hi; hi = switch_hash_next(hi)) { switch_hash_this(hi, NULL, NULL, &val); @@ -290,7 +292,8 @@ SWITCH_DECLARE(switch_console_callback_match_t *) switch_core_session_findall_ma if ((session = switch_core_session_locate(np->str))) { const char *this_val; if (switch_channel_up_nosig(session->channel) && - (this_val = switch_channel_get_variable_dup(session->channel, var_name, SWITCH_FALSE, -1)) && (!strcmp(this_val, var_val))) { + (this_val = switch_channel_get_variable_dup(session->channel, var_name, SWITCH_FALSE, -1)) && + (!var_val || (like && switch_stristr(like, var_val)) || !strcmp(this_val, var_val))) { switch_console_push_match(&my_matches, (const char *) np->str); } switch_core_session_rwunlock(session);