Merge remote branch 'ssh/v1.2.stable-em_management' into v1.2.stable-em_management

This commit is contained in:
Moises Silva 2013-11-01 02:20:21 -04:00
commit 6edf3341a6
12 changed files with 346 additions and 69 deletions

View File

@ -413,32 +413,45 @@ SWITCH_AM_CFLAGS="$LIBUUID_CFLAGS $SWITCH_AM_CFLAGS"
AC_ARG_ENABLE(core-pgsql-support, AC_ARG_ENABLE(core-pgsql-support,
[AS_HELP_STRING([--enable-core-pgsql-support], [Compile with PGSQL Support])],,[enable_core_pgsql_support="no"]) [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([--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 if test x"$enable_core_pgsql_support" = x"yes" ; then
AC_PATH_PROG([PG_CONFIG], [pg_config], [no])
AC_PATH_PROG([PG_CONFIG], [pg_config], [no]) AC_PATH_PROG([PKG_CONFIG], [pkg-config], [no])
if test "$PG_CONFIG" != "no"; then if test "$PG_CONFIG" = "no"; then
AC_MSG_CHECKING([for PostgreSQL libraries]) AC_MSG_RESULT([no])
POSTGRESQL_CXXFLAGS="`$PG_CONFIG --cppflags` -I`$PG_CONFIG --includedir`" AC_MSG_FAILURE([Unabled to find pg_config in PATH. Is PostgreSQL installed?])
POSTGRESQL_LDFLAGS="`$PG_CONFIG --ldflags|sed 's/ -Wl,--as-needed//g'` -L`$PG_CONFIG --libdir` -lpq" else
POSTGRESQL_VERSION=`$PG_CONFIG --version | sed -e 's#PostgreSQL ##'` if test "$PKG_CONFIG" = "no" \
POSTGRESQL_MAJOR_VERSION=`$PG_CONFIG --version | sed -e 's/devel//' | sed -re 's#PostgreSQL ([0-9]+).[0-9]+.?[0-9]+?#\1#'` || test x"$enable_core_pgsql_pkgconfig" = x"no" \
POSTGRESQL_MINOR_VERSION=`$PG_CONFIG --version | sed -e 's/devel//' | sed -re 's#PostgreSQL [0-9]+.([0-9]+).?[0-9]+?#\1#'` || ! pkg-config libpq; then
POSTGRESQL_PATCH_VERSION=`$PG_CONFIG --version | sed -e 's/devel//' | sed -re 's#PostgreSQL [0-9]+.[0-9]+.?([0-9]+)?#\1#'` AC_MSG_CHECKING([for PostgreSQL libraries])
AC_DEFINE([SWITCH_HAVE_PGSQL], [1], [Define to 1 if PostgreSQL libraries are available]) POSTGRESQL_CXXFLAGS="`$PG_CONFIG --cppflags` -I`$PG_CONFIG --includedir`"
AC_DEFINE_UNQUOTED([POSTGRESQL_VERSION], "${POSTGRESQL_VERSION}", [Specifies the version of PostgreSQL we are linking against]) POSTGRESQL_LDFLAGS="`$PG_CONFIG --ldflags|sed 's/ -Wl,--as-needed//g'` -L`$PG_CONFIG --libdir` -lpq"
AC_DEFINE_UNQUOTED([POSTGRESQL_MAJOR_VERSION], ${POSTGRESQL_MAJOR_VERSION}, [Specifies the version of PostgreSQL we are linking against]) POSTGRESQL_VERSION=`$PG_CONFIG --version | sed -e 's#PostgreSQL ##'`
AC_DEFINE_UNQUOTED([POSTGRESQL_MINOR_VERSION], ${POSTGRESQL_MINOR_VERSION}, [Specifies the version of PostgreSQL we are linking against]) POSTGRESQL_MAJOR_VERSION=`$PG_CONFIG --version | sed -e 's/devel//' | sed -re 's#PostgreSQL ([0-9]+).[0-9]+.?[0-9]+?#\1#'`
AC_DEFINE_UNQUOTED([POSTGRESQL_PATCH_VERSION], ${POSTGRESQL_PATCH_VERSION}, [Specifies the version of PostgreSQL we are linking against]) POSTGRESQL_MINOR_VERSION=`$PG_CONFIG --version | sed -e 's/devel//' | sed -re 's#PostgreSQL [0-9]+.([0-9]+).?[0-9]+?#\1#'`
AC_CHECK_LIB([pq], [PQgetvalue],, AC_MSG_ERROR([no usable libpq; please install PostgreSQL devel package or equivalent])) POSTGRESQL_PATCH_VERSION=`$PG_CONFIG --version | sed -e 's/devel//' | sed -re 's#PostgreSQL [0-9]+.[0-9]+.?([0-9]+)?#\1#'`
AC_MSG_RESULT([yes]) else
SWITCH_AM_CXXFLAGS="$POSTGRESQL_CXXFLAGS $SWITCH_AM_CXXFLAGS" AC_MSG_CHECKING([for PostgreSQL libraries])
SWITCH_AM_LDFLAGS="$POSTGRESQL_LDFLAGS $SWITCH_AM_LDFLAGS" POSTGRESQL_CXXFLAGS="`$PKG_CONFIG --cflags libpq`"
else POSTGRESQL_LDFLAGS="`$PKG_CONFIG --libs libpq`"
AC_MSG_RESULT([no]) POSTGRESQL_VERSION="`$PKG_CONFIG --modversion libpq`"
AC_MSG_FAILURE([Unabled to find pg_config in PATH. Is PostgreSQL installed?]) POSTGRESQL_MAJOR_VERSION="`echo $POSTGRESQL_VERSION | cut -d. -f1`"
fi 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 fi
AC_ARG_ENABLE(deprecated-core-db-events, AC_ARG_ENABLE(deprecated-core-db-events,

View File

@ -82,18 +82,33 @@ typedef struct device_uuid_node_s {
switch_channel_callstate_t callstate; switch_channel_callstate_t callstate;
switch_hold_record_t *hold_record; switch_hold_record_t *hold_record;
switch_caller_profile_t *hup_profile; switch_caller_profile_t *hup_profile;
switch_call_direction_t direction;
struct switch_device_record_s *parent; struct switch_device_record_s *parent;
struct device_uuid_node_s *next; struct device_uuid_node_s *next;
} switch_device_node_t; } switch_device_node_t;
typedef struct switch_device_stats_s { typedef struct switch_device_stats_s {
uint32_t total; uint32_t total;
uint32_t total_in;
uint32_t total_out;
uint32_t offhook; uint32_t offhook;
uint32_t offhook_in;
uint32_t offhook_out;
uint32_t active; uint32_t active;
uint32_t active_in;
uint32_t active_out;
uint32_t held; uint32_t held;
uint32_t held_in;
uint32_t held_out;
uint32_t hup; uint32_t hup;
uint32_t hup_in;
uint32_t hup_out;
uint32_t ringing; uint32_t ringing;
uint32_t ringing_in;
uint32_t ringing_out;
uint32_t early; uint32_t early;
uint32_t early_in;
uint32_t early_out;
} switch_device_stats_t; } switch_device_stats_t;
@ -102,15 +117,22 @@ typedef struct switch_device_record_s {
char *uuid; char *uuid;
int refs; int refs;
switch_device_stats_t stats; switch_device_stats_t stats;
switch_device_stats_t last_stats;
switch_device_state_t state; switch_device_state_t state;
switch_device_state_t last_state; switch_device_state_t last_state;
switch_time_t active_start; switch_time_t active_start;
switch_time_t active_stop; switch_time_t active_stop;
switch_time_t last_call_time; 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_list;
struct device_uuid_node_s *uuid_tail; struct device_uuid_node_s *uuid_tail;
switch_mutex_t *mutex; switch_mutex_t *mutex;
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
void *user_data;
} switch_device_record_t; } 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); typedef void(*switch_device_state_function_t)(switch_core_session_t *session, switch_channel_callstate_t callstate, switch_device_record_t *drec);

View File

@ -576,6 +576,8 @@ static struct {
switch_hash_t *caller_orig_hash; switch_hash_t *caller_orig_hash;
switch_hash_t *consumer_orig_hash; switch_hash_t *consumer_orig_hash;
switch_hash_t *bridge_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 *caller_orig_mutex;
switch_mutex_t *consumer_orig_mutex; switch_mutex_t *consumer_orig_mutex;
switch_mutex_t *bridge_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) static int check_caller_outbound_call(const char *key)
{ {
int x = 0; 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; const char *epoch_start_a = NULL;
char *sql; char *sql;
switch_event_t *event; 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_clear_app_flag_key(FIFO_APP_KEY, consumer_channel, FIFO_APP_BRIDGE_TAG);
switch_channel_set_variable(consumer_channel, "fifo_bridged", NULL); 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(); ts = switch_micro_time_now();
switch_time_exp_lt(&tm, ts); switch_time_exp_lt(&tm, ts);
switch_strftime_nocheck(date, &retsize, sizeof(date), "%Y-%m-%d %T", &tm); 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_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-Name", MANUAL_QUEUE_NAME);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-stop"); 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); 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_t ts;
switch_time_exp_t tm; switch_time_exp_t tm;
switch_size_t retsize; 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)) { if (switch_channel_test_app_flag_key(FIFO_APP_KEY, consumer_channel, FIFO_APP_BRIDGE_TAG)) {
goto end; 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_bridged", "true");
switch_channel_set_variable(consumer_channel, "fifo_manual_bridge", "true"); switch_channel_set_variable(consumer_channel, "fifo_manual_bridge", "true");
switch_channel_set_variable(consumer_channel, "fifo_role", "consumer"); switch_channel_set_variable(consumer_channel, "fifo_role", "consumer");
outbound_id = switch_channel_get_variable(consumer_channel, "fifo_outbound_uuid");
if (caller_channel) { if (caller_channel) {
switch_channel_set_variable(caller_channel, "fifo_role", "caller"); 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-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-Name", ced_name);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Caller-CID-Number", ced_number); 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); 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) static void dec_use_count(switch_core_session_t *session, switch_bool_t send_event)
{ {
char *sql; char *sql;
const char *outbound_id; const char *outbound_id = NULL;
switch_event_t *event; switch_event_t *event;
long now = (long) switch_epoch_time_now(NULL); long now = (long) switch_epoch_time_now(NULL);
switch_channel_t *channel = switch_core_session_get_channel(session); 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'", 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); now, now, outbound_id);
fifo_execute_sql_queued(&sql, SWITCH_TRUE, SWITCH_TRUE); fifo_execute_sql_queued(&sql, SWITCH_TRUE, SWITCH_TRUE);
fifo_dec_use_count(outbound_id);
} }
if (send_event) { 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_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-Name", MANUAL_QUEUE_NAME);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "channel-consumer-stop"); 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); 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'", 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); (long) switch_epoch_time_now(NULL), col1, col1, col2, col2, data);
fifo_execute_sql_queued(&sql, SWITCH_TRUE, SWITCH_TRUE); fifo_execute_sql_queued(&sql, SWITCH_TRUE, SWITCH_TRUE);
fifo_inc_use_count(data);
if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND) { if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_INBOUND) {
cid_name = switch_channel_get_variable(channel, "destination_number"); cid_name = switch_channel_get_variable(channel, "destination_number");
@ -2647,6 +2729,7 @@ SWITCH_STANDARD_APP(fifo_function)
const char *url = NULL; const char *url = NULL;
const char *caller_uuid = NULL; const char *caller_uuid = NULL;
const char *outbound_id = switch_channel_get_variable(channel, "fifo_outbound_uuid"); 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"); //const char *track_use_count = switch_channel_get_variable(channel, "fifo_track_use_count");
//int do_track = switch_true(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(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")); 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) { if (outbound_id) {
cancel_consumer_outbound_call(outbound_id, SWITCH_CAUSE_ORIGINATOR_CANCEL); 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_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(other_session));
add_bridge_call(switch_core_session_get_uuid(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); fifo_execute_sql_queued(&sql, SWITCH_TRUE, SWITCH_TRUE);
del_bridge_call(outbound_id); 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_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-Name", argv[0]);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "FIFO-Action", "bridge-consumer-stop"); 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); switch_event_fire(&event);
} }
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, FIFO_EVENT) == SWITCH_STATUS_SUCCESS) { 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) { 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"; 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_execute_sql_queued(&sql, SWITCH_FALSE, SWITCH_TRUE);
fifo_init_use_count();
} }
if (reload) { 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.caller_orig_hash, globals.pool);
switch_core_hash_init(&globals.consumer_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.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.caller_orig_mutex, SWITCH_MUTEX_NESTED, globals.pool);
switch_mutex_init(&globals.consumer_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.bridge_mutex, SWITCH_MUTEX_NESTED, globals.pool);
switch_mutex_init(&globals.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); switch_mutex_init(&globals.sql_mutex, SWITCH_MUTEX_NESTED, globals.pool);
globals.running = 1; globals.running = 1;

View File

@ -486,7 +486,6 @@ static switch_status_t channel_on_destroy(switch_core_session_t *session)
{ {
switch_channel_t *channel = NULL; switch_channel_t *channel = NULL;
loopback_private_t *tech_pvt = NULL; loopback_private_t *tech_pvt = NULL;
void *pop;
switch_event_t *vars; switch_event_t *vars;
channel = switch_core_session_get_channel(session); 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); switch_frame_free(&tech_pvt->write_frame);
} }
while (switch_queue_trypop(tech_pvt->frame_queue, &pop) == SWITCH_STATUS_SUCCESS && pop) { clear_queue(tech_pvt);
switch_frame_t *frame = (switch_frame_t *) pop;
switch_frame_free(&frame);
}
} }

View File

@ -804,6 +804,7 @@ struct private_object {
switch_port_t stun_port; switch_port_t stun_port;
uint32_t stun_flags; uint32_t stun_flags;
unsigned long rm_rate; unsigned long rm_rate;
unsigned long adv_rm_rate;
switch_payload_t pt; switch_payload_t pt;
switch_mutex_t *flag_mutex; switch_mutex_t *flag_mutex;
switch_mutex_t *sofia_mutex; switch_mutex_t *sofia_mutex;

View File

@ -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"); 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) { if (tech_pvt->adv_channels > 1) {
switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=rtpmap:%d %s/%d/%d\n", 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->iananame = switch_core_session_strdup(tech_pvt->session, "PROXY");
tech_pvt->rm_rate = 8000; tech_pvt->rm_rate = 8000;
tech_pvt->adv_rm_rate = 8000;
tech_pvt->codec_ms = 20; 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) { 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->iananame = switch_core_session_strdup(tech_pvt->session, map->rm_encoding);
tech_pvt->rm_rate = map->rm_rate; tech_pvt->rm_rate = map->rm_rate;
tech_pvt->adv_rm_rate = map->rm_rate;
tech_pvt->codec_ms = ptime; tech_pvt->codec_ms = ptime;
sofia_glue_tech_set_codec(tech_pvt, 0); sofia_glue_tech_set_codec(tech_pvt, 0);
break; break;
@ -4750,7 +4752,7 @@ uint8_t sofia_glue_negotiate_sdp(switch_core_session_t *session, const char *r_s
int reneg = 1; int reneg = 1;
const switch_codec_implementation_t **codec_array; const switch_codec_implementation_t **codec_array;
int total_codecs; int total_codecs;
char *samp = NULL;
codec_array = tech_pvt->codecs; codec_array = tech_pvt->codecs;
total_codecs = tech_pvt->num_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; 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 (match) {
if (scrooge) { if (scrooge) {
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, 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) { if (!match && near_match) {
const switch_codec_implementation_t *search[1]; const switch_codec_implementation_t *search[1];
char *prefs[1]; char *prefs[1];
@ -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->iananame = switch_core_session_strdup(session, (char *) mimp->iananame);
tech_pvt->pt = (switch_payload_t) map->rm_pt; tech_pvt->pt = (switch_payload_t) map->rm_pt;
tech_pvt->rm_rate = mimp->samples_per_second; 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->codec_ms = mimp->microseconds_per_packet / 1000;
tech_pvt->bitrate = mimp->bits_per_second; tech_pvt->bitrate = mimp->bits_per_second;
tech_pvt->remote_sdp_audio_ip = switch_core_session_strdup(session, (char *) connection->c_address); 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"))) { if ((tmp = switch_channel_get_variable(channel, "sip_use_codec_rate"))) {
tech_pvt->rm_rate = atoi(tmp); 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"))) { if ((tmp = switch_channel_get_variable(channel, "sip_use_codec_ptime"))) {

View File

@ -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) static void event_handler(switch_event_t *event)
{ {
const char *sig = switch_event_get_header(event, "Trapped-Signal"); 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_event_unbind_callback(event_handler);
switch_core_remove_state_handler(&state_handlers); 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; return SWITCH_STATUS_SUCCESS;
} }

View File

@ -278,6 +278,10 @@ SWITCH_DECLARE(void) switch_channel_perform_set_callstate(switch_channel_t *chan
switch_channel_check_device_state(channel, channel->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) { 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_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); 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; channel->state = CS_HANGUP;
switch_mutex_unlock(channel->state_mutex); switch_mutex_unlock(channel->state_mutex);
process_device_hup(channel);
channel->hangup_cause = hangup_cause; 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", 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)); channel->name, state_names[last_state], switch_channel_cause2str(channel->hangup_cause));
@ -4614,28 +4616,71 @@ static void fetch_device_stats(switch_device_record_t *drec)
{ {
switch_device_node_t *np; switch_device_node_t *np;
memset(&drec->stats, 0, sizeof(switch_device_stats_t)); memset(&drec->stats, 0, sizeof(switch_device_stats_t));
switch_mutex_lock(drec->mutex); switch_mutex_lock(drec->mutex);
for(np = drec->uuid_list; np; np = np->next) { for(np = drec->uuid_list; np; np = np->next) {
drec->stats.total++; drec->stats.total++;
if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) {
drec->stats.total_in++;
} else {
drec->stats.total_out++;
}
if (!np->hup_profile) { if (!np->hup_profile) {
drec->stats.offhook++; drec->stats.offhook++;
if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) {
drec->stats.offhook_in++;
} else {
drec->stats.offhook_out++;
}
if (np->callstate == CCS_HELD) { if (np->callstate == CCS_HELD) {
drec->stats.held++; drec->stats.held++;
if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) {
drec->stats.held_in++;
} else {
drec->stats.held_out++;
}
} else { } else {
if (np->callstate == CCS_EARLY) { if (np->callstate == CCS_EARLY) {
drec->stats.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) { } else if (np->callstate == CCS_RINGING) {
drec->stats.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_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) { } else if (np->callstate != CCS_DOWN) {
drec->stats.active++; drec->stats.active++;
if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) {
drec->stats.active_in++;
} else {
drec->stats.active_out++;
}
} }
} }
} else { } else {
drec->stats.hup++; drec->stats.hup++;
if (np->direction == SWITCH_CALL_DIRECTION_INBOUND) {
drec->stats.hup_in++;
} else {
drec->stats.hup_out++;
}
} }
} }
switch_mutex_unlock(drec->mutex); switch_mutex_unlock(drec->mutex);
@ -4776,7 +4821,7 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_
drec->state = SDS_HANGUP; drec->state = SDS_HANGUP;
} else { } else {
if (drec->stats.active == 0) { 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; drec->state = SDS_RINGING;
} else { } else {
if (drec->stats.held > 0) { if (drec->stats.held > 0) {
@ -4798,22 +4843,42 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_
return; return;
} }
if (!drec->call_start) {
drec->call_start = switch_micro_time_now();
}
switch(drec->state) { switch(drec->state) {
case SDS_RINGING:
drec->ring_start = switch_micro_time_now();
drec->ring_stop = 0;
break;
case SDS_ACTIVE: case SDS_ACTIVE:
case SDS_ACTIVE_MULTI: 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(); drec->active_stop = switch_micro_time_now();
} else if (!drec->active_start) { } else if (!drec->active_start) {
drec->active_start = switch_micro_time_now(); drec->active_start = switch_micro_time_now();
} }
break; break;
case SDS_HELD:
drec->hold_start = switch_micro_time_now();
drec->hold_stop = 0;
default: default:
if (drec->last_state != SDS_HELD) { if (drec->active_start && drec->last_state != SDS_HELD) {
drec->active_stop = switch_micro_time_now(); drec->active_stop = switch_micro_time_now();
} }
break; 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) { 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, "Device-ID", drec->device_id);
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Last-Device-State", switch_channel_device_state2str(drec->last_state)); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Last-Device-State", switch_channel_device_state2str(drec->last_state));
@ -4834,7 +4899,8 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_
} }
switch_log_printf(SWITCH_CHANNEL_CHANNEL_LOG(channel), SWITCH_LOG_DEBUG1, 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), switch_channel_get_name(channel),
drec->device_id, drec->device_id,
switch_channel_callstate2str(callstate), switch_channel_callstate2str(callstate),
@ -4848,12 +4914,16 @@ static void switch_channel_check_device_state(switch_channel_t *channel, switch_
drec->stats.held, drec->stats.held,
drec->stats.hup, drec->stats.hup,
drec->active_stop ? (uint32_t)(drec->active_stop - drec->active_start) / 1000 : 0, 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" : ""); switch_channel_test_flag(channel, CF_FINAL_DEVICE_LEG) ? "FINAL LEG" : "");
for (ptr = globals.device_bindings; ptr; ptr = ptr->next) { for (ptr = globals.device_bindings; ptr; ptr = ptr->next) {
ptr->function(channel->session, callstate, drec); ptr->function(channel->session, callstate, drec);
} }
drec->last_stats = drec->stats;
if (drec->active_stop) { if (drec->active_stop) {
drec->active_start = drec->active_stop = 0; drec->active_start = drec->active_stop = 0;
if (drec->state == SDS_ACTIVE || drec->state == SDS_ACTIVE_MULTI) { if (drec->state == SDS_ACTIVE || drec->state == SDS_ACTIVE_MULTI) {
@ -4861,6 +4931,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_call_time = switch_micro_time_now();
drec->last_state = drec->state; drec->last_state = drec->state;
@ -4888,6 +4972,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->uuid = switch_core_strdup(drec->pool, switch_core_session_get_uuid(channel->session));
node->parent = drec; node->parent = drec;
node->callstate = channel->callstate; node->callstate = channel->callstate;
node->direction = channel->direction == SWITCH_CALL_DIRECTION_INBOUND ? SWITCH_CALL_DIRECTION_OUTBOUND : SWITCH_CALL_DIRECTION_INBOUND;
channel->device_node = node; channel->device_node = node;
if (!drec->uuid_list) { if (!drec->uuid_list) {

View File

@ -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 no specific codec interval is requested opt for 20ms above all else because lots of stuff assumes it */
if (!ms) { if (!ms) {
for (iptr = codec_interface->implementations; iptr; iptr = iptr->next) { 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)) { (20 == (iptr->microseconds_per_packet / 1000)) && (!channels || channels == iptr->number_of_channels)) {
implementation = iptr; implementation = iptr;
goto found; 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 */ /* 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) { 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)) { (!ms || ms == (iptr->microseconds_per_packet / 1000)) && (!channels || channels == iptr->number_of_channels)) {
implementation = iptr; implementation = iptr;
break; break;

View File

@ -264,12 +264,14 @@ SWITCH_DECLARE(switch_console_callback_match_t *) switch_core_session_findall_ma
switch_memory_pool_t *pool; switch_memory_pool_t *pool;
struct str_node *head = NULL, *np; struct str_node *head = NULL, *np;
switch_console_callback_match_t *my_matches = NULL; 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); switch_core_new_memory_pool(&pool);
if (!var_val)
return NULL;
switch_mutex_lock(runtime.session_hash_mutex); switch_mutex_lock(runtime.session_hash_mutex);
for (hi = switch_hash_first(NULL, session_manager.session_table); hi; hi = switch_hash_next(hi)) { for (hi = switch_hash_first(NULL, session_manager.session_table); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val); 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))) { if ((session = switch_core_session_locate(np->str))) {
const char *this_val; const char *this_val;
if (switch_channel_up_nosig(session->channel) && 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_console_push_match(&my_matches, (const char *) np->str);
} }
switch_core_session_rwunlock(session); switch_core_session_rwunlock(session);

View File

@ -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, 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); "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) { if (db) {
new_dbh->native_handle.core_db_dbh = db; new_dbh->native_handle.core_db_dbh = db;
} else if (odbc_dbh) { } else if (odbc_dbh) {

View File

@ -186,10 +186,18 @@ static switch_status_t switch_loadable_module_process(char *key, switch_loadable
} }
if (load_interface) { if (load_interface) {
for (impl = ptr->implementations; impl; impl = impl->next) { for (impl = ptr->implementations; impl; impl = impl->next) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, if (impl->bits_per_second) {
"Adding Codec %s %d %s %dhz %dms %dbps\n", switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
impl->iananame, impl->ianacode, "Adding Codec %s %d %s %dhz %dms %dbps\n",
ptr->interface_name, impl->actual_samples_per_second, impl->microseconds_per_packet / 1000, impl->bits_per_second); 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)) { if (!switch_core_hash_find(loadable_modules.codec_hash, impl->iananame)) {
switch_core_hash_insert(loadable_modules.codec_hash, impl->iananame, (const void *) ptr); switch_core_hash_insert(loadable_modules.codec_hash, impl->iananame, (const void *) ptr);
} }
@ -2243,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); uint32_t default_rate = switch_default_rate(imp->iananame, imp->ianacode);
if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) { 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) || if ((!interval && (uint32_t) (imp->microseconds_per_packet / 1000) != default_ptime) ||
(interval && (uint32_t) (imp->microseconds_per_packet / 1000) != interval)) { (interval && (uint32_t) (imp->microseconds_per_packet / 1000) != interval)) {
continue; continue;
} }
if (((!rate && (uint32_t) imp->samples_per_second != default_rate) || (rate && (uint32_t) imp->samples_per_second != rate))) { if (((!rate && crate != default_rate) || (rate && (uint32_t) imp->actual_samples_per_second != rate))) {
continue; continue;
} }
@ -2268,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 */ /* 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) { for (imp = codec_interface->implementations; imp; imp = imp->next) {
if (imp->codec_type != SWITCH_CODEC_TYPE_VIDEO) { 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) { if (interval && (uint32_t) (imp->microseconds_per_packet / 1000) != interval) {
continue; continue;
} }
if (rate && (uint32_t) imp->samples_per_second != rate) { if (rate && (uint32_t) crate != rate) {
continue; continue;
} }