提交 4799ec8b authored 作者: Anthony Minessale's avatar Anthony Minessale

break everything

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@720 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 b77747e0
...@@ -8,8 +8,10 @@ $ip and $port or die "Usage $0: <ip> <port>\n"; ...@@ -8,8 +8,10 @@ $ip and $port or die "Usage $0: <ip> <port>\n";
$socket = new IO::Socket::INET->new( PeerPort => $port, $socket = new IO::Socket::INET->new( PeerPort => $port,
Proto => 'udp', Proto => 'udp',
PeerAddr => $ip); PeerAddr => $ip);
open(I, $file);
my $buf = `cat $file`; $/ = undef;
my $buf = <I>;
close(I);
$socket->send("$buf\n"); $socket->send("$buf\n");
...@@ -134,7 +134,7 @@ extern "C" { ...@@ -134,7 +134,7 @@ extern "C" {
/*! /*!
\brief Create a new caller profile object \brief Create a new caller profile object
\param session session associated with the profile (bound by scope) \param pool memory pool to use
\param dialplan name of the dialplan module in use \param dialplan name of the dialplan module in use
\param caller_id_name caller ID name \param caller_id_name caller ID name
\param caller_id_number caller ID number \param caller_id_number caller ID number
...@@ -144,7 +144,7 @@ extern "C" { ...@@ -144,7 +144,7 @@ extern "C" {
\param destination_number destination number \param destination_number destination number
\return a new profile object allocated from the session's memory pool \return a new profile object allocated from the session's memory pool
*/ */
SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_new(switch_core_session *session, SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_new(switch_memory_pool *pool,
char *dialplan, char *dialplan,
char *caller_id_name, char *caller_id_name,
char *caller_id_number, char *caller_id_number,
......
...@@ -65,6 +65,13 @@ typedef struct { ...@@ -65,6 +65,13 @@ typedef struct {
*/ */
SWITCH_DECLARE(switch_channel_state) switch_channel_get_state(switch_channel *channel); SWITCH_DECLARE(switch_channel_state) switch_channel_get_state(switch_channel *channel);
/*!
\brief Determine if a channel is ready for io
\param channel channel to test
\return true if the channel is ready
*/
SWITCH_DECLARE(unsigned int) switch_channel_ready(switch_channel *channel);
/*! /*!
\brief Set the current state of a channel \brief Set the current state of a channel
\param channel channel to set state of \param channel channel to set state of
......
...@@ -157,6 +157,12 @@ SWITCH_DECLARE(switch_status) switch_core_destroy_memory_pool(switch_memory_pool ...@@ -157,6 +157,12 @@ SWITCH_DECLARE(switch_status) switch_core_destroy_memory_pool(switch_memory_pool
*/ */
SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session); SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session);
/*!
\brief determine if the session's state machine is running
\param session the session on which to check
*/
SWITCH_DECLARE(unsigned int) switch_core_session_runing(switch_core_session *session);
/*! /*!
\brief Allocate memory from the main pool with no intention of returning it \brief Allocate memory from the main pool with no intention of returning it
\param memory the number of bytes to allocate \param memory the number of bytes to allocate
......
...@@ -239,6 +239,8 @@ CF_RECV_AUDIO = (1 << 1) - Channel will receive audio ...@@ -239,6 +239,8 @@ CF_RECV_AUDIO = (1 << 1) - Channel will receive audio
CF_ANSWERED = (1 << 2) - Channel is answered CF_ANSWERED = (1 << 2) - Channel is answered
CF_OUTBOUND = (1 << 3) - Channel is an outbound channel CF_OUTBOUND = (1 << 3) - Channel is an outbound channel
CF_EARLY_MEDIA = (1 << 4) - Channel is ready for audio before answer CF_EARLY_MEDIA = (1 << 4) - Channel is ready for audio before answer
CF_ORIGINATOR = (1 << 5) - Channel is an originator
CF_TRANSFER = (1 << 6) - Channel is being transfered
</pre> </pre>
*/ */
...@@ -247,7 +249,9 @@ typedef enum { ...@@ -247,7 +249,9 @@ typedef enum {
CF_RECV_AUDIO = (1 << 1), CF_RECV_AUDIO = (1 << 1),
CF_ANSWERED = (1 << 2), CF_ANSWERED = (1 << 2),
CF_OUTBOUND = (1 << 3), CF_OUTBOUND = (1 << 3),
CF_EARLY_MEDIA = (1 << 4) CF_EARLY_MEDIA = (1 << 4),
CF_ORIGINATOR = (1 << 5),
CF_TRANSFER = (1 << 6)
} switch_channel_flag; } switch_channel_flag;
......
...@@ -55,7 +55,7 @@ static void audio_bridge_function(switch_core_session *session, char *data) ...@@ -55,7 +55,7 @@ static void audio_bridge_function(switch_core_session *session, char *data)
} }
caller_caller_profile = switch_channel_get_caller_profile(caller_channel); caller_caller_profile = switch_channel_get_caller_profile(caller_channel);
caller_profile = switch_caller_profile_new(session, caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
caller_caller_profile->dialplan, caller_caller_profile->dialplan,
caller_caller_profile->caller_id_name, caller_caller_profile->caller_id_name,
caller_caller_profile->caller_id_number, caller_caller_profile->caller_id_number,
......
...@@ -550,7 +550,6 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram ...@@ -550,7 +550,6 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram
&& tech_pvt->read_frame.datalen == 0) { && tech_pvt->read_frame.datalen == 0) {
tech_pvt->read_frame.datalen = tech_pvt->read_frame.datalen =
jrtp4c_read(tech_pvt->rtp_session, tech_pvt->read_frame.data, sizeof(tech_pvt->read_buf), &payload); jrtp4c_read(tech_pvt->rtp_session, tech_pvt->read_frame.data, sizeof(tech_pvt->read_buf), &payload);
/* RFC2833 ... TBD try harder to honor the duration etc.*/ /* RFC2833 ... TBD try harder to honor the duration etc.*/
if (payload == 101) { if (payload == 101) {
unsigned char *packet = tech_pvt->read_frame.data; unsigned char *packet = tech_pvt->read_frame.data;
...@@ -732,7 +731,6 @@ static switch_status exosip_kill_channel(switch_core_session *session, int sig) ...@@ -732,7 +731,6 @@ static switch_status exosip_kill_channel(switch_core_session *session, int sig)
tech_pvt = switch_core_session_get_private(session); tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL); assert(tech_pvt != NULL);
switch_clear_flag(tech_pvt, TFLAG_IO); switch_clear_flag(tech_pvt, TFLAG_IO);
switch_set_flag(tech_pvt, TFLAG_BYE); switch_set_flag(tech_pvt, TFLAG_BYE);
...@@ -1008,7 +1006,7 @@ static switch_status exosip_create_call(eXosip_event_t * event) ...@@ -1008,7 +1006,7 @@ static switch_status exosip_create_call(eXosip_event_t * event)
snprintf(name, sizeof(name), "Exosip/%s-%04x", event->request->from->url->username, rand() & 0xffff); snprintf(name, sizeof(name), "Exosip/%s-%04x", event->request->from->url->username, rand() & 0xffff);
switch_channel_set_name(channel, name); switch_channel_set_name(channel, name);
if ((tech_pvt->caller_profile = switch_caller_profile_new(session, if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
globals.dialplan, globals.dialplan,
event->request->from->displayname, event->request->from->displayname,
event->request->from->url->username, event->request->from->url->username,
......
...@@ -979,7 +979,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void) ...@@ -979,7 +979,7 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
} }
if ((tech_pvt->caller_profile = switch_caller_profile_new(session, if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
globals.dialplan, globals.dialplan,
iaxevent->ies.calling_name, iaxevent->ies.calling_name,
iaxevent->ies.calling_number, iaxevent->ies.calling_number,
......
...@@ -808,7 +808,7 @@ static switch_status place_call(char *dest, char *out, size_t outlen) ...@@ -808,7 +808,7 @@ static switch_status place_call(char *dest, char *out, size_t outlen)
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
if ((tech_pvt->caller_profile = switch_caller_profile_new(session, if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
globals.dialplan, globals.dialplan,
globals.cid_name, globals.cid_name,
globals.cid_num, NULL, NULL, NULL, dest)) != 0) { globals.cid_num, NULL, NULL, NULL, dest)) != 0) {
......
...@@ -973,7 +973,7 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri ...@@ -973,7 +973,7 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri
snprintf(ani2str, 5, "%.2d", event->ring.ani2); snprintf(ani2str, 5, "%.2d", event->ring.ani2);
} }
if ((tech_pvt->caller_profile = switch_caller_profile_new(session, if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
globals.dialplan, globals.dialplan,
"wanpipe fixme", "wanpipe fixme",
event->ring.callingnum, event->ring.callingnum,
......
...@@ -1064,7 +1064,7 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj) ...@@ -1064,7 +1064,7 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj)
} }
ip = woomera_message_header(&wmsg, "Remote-Address"); ip = woomera_message_header(&wmsg, "Remote-Address");
if ((tech_pvt->caller_profile = switch_caller_profile_new(session, if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
tech_pvt->profile->dialplan, tech_pvt->profile->dialplan,
cid_name, cid_num, ip, NULL, NULL, exten)) != 0) { cid_name, cid_num, ip, NULL, NULL, exten)) != 0) {
char name[128]; char name[128];
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
*/ */
#include <switch_caller.h> #include <switch_caller.h>
SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_new(switch_core_session *session, SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_new(switch_memory_pool *pool,
char *dialplan, char *dialplan,
char *caller_id_name, char *caller_id_name,
char *caller_id_number, char *caller_id_number,
...@@ -42,14 +42,14 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_new(switch_core_se ...@@ -42,14 +42,14 @@ SWITCH_DECLARE(switch_caller_profile *) switch_caller_profile_new(switch_core_se
switch_caller_profile *profile = NULL; switch_caller_profile *profile = NULL;
if ((profile = switch_core_session_alloc(session, sizeof(switch_caller_profile))) != 0) { if ((profile = switch_core_alloc(pool, sizeof(switch_caller_profile))) != 0) {
profile->dialplan = switch_core_session_strdup(session, dialplan); profile->dialplan = switch_core_strdup(pool, dialplan);
profile->caller_id_name = switch_core_session_strdup(session, caller_id_name); profile->caller_id_name = switch_core_strdup(pool, caller_id_name);
profile->caller_id_number = switch_core_session_strdup(session, caller_id_number); profile->caller_id_number = switch_core_strdup(pool, caller_id_number);
profile->network_addr = switch_core_session_strdup(session, network_addr); profile->network_addr = switch_core_strdup(pool, network_addr);
profile->ani = switch_core_session_strdup(session, ani); profile->ani = switch_core_strdup(pool, ani);
profile->ani2 = switch_core_session_strdup(session, ani2); profile->ani2 = switch_core_strdup(pool, ani2);
profile->destination_number = switch_core_session_strdup(session, destination_number); profile->destination_number = switch_core_strdup(pool, destination_number);
} }
return profile; return profile;
......
...@@ -248,6 +248,12 @@ SWITCH_DECLARE(switch_channel_state) switch_channel_get_state(switch_channel *ch ...@@ -248,6 +248,12 @@ SWITCH_DECLARE(switch_channel_state) switch_channel_get_state(switch_channel *ch
return channel->state; return channel->state;
} }
SWITCH_DECLARE(unsigned int) switch_channel_ready(switch_channel *channel)
{
assert(channel != NULL);
return (channel->state > CS_RING && channel->state < CS_HANGUP) ? 1 : 0;
}
static const char *state_names[] = { static const char *state_names[] = {
"CS_NEW", "CS_NEW",
"CS_INIT", "CS_INIT",
......
...@@ -42,6 +42,7 @@ EXTERN_C void xs_init(pTHX); ...@@ -42,6 +42,7 @@ EXTERN_C void xs_init(pTHX);
struct switch_core_session { struct switch_core_session {
unsigned long id; unsigned long id;
char name[80]; char name[80];
int thread_running;
switch_memory_pool *pool; switch_memory_pool *pool;
switch_channel *channel; switch_channel *channel;
switch_thread *thread; switch_thread *thread;
...@@ -714,9 +715,9 @@ SWITCH_DECLARE(char *) switch_core_session_strdup(switch_core_session *session, ...@@ -714,9 +715,9 @@ SWITCH_DECLARE(char *) switch_core_session_strdup(switch_core_session *session,
assert(session != NULL); assert(session != NULL);
assert(session->pool != NULL); assert(session->pool != NULL);
if (!todup) if (!todup) {
return NULL; return NULL;
}
len = strlen(todup) + 1; len = strlen(todup) + 1;
if (todup && (duped = apr_palloc(session->pool, len)) != 0) { if (todup && (duped = apr_palloc(session->pool, len)) != 0) {
...@@ -731,10 +732,11 @@ SWITCH_DECLARE(char *) switch_core_strdup(switch_memory_pool *pool, char *todup) ...@@ -731,10 +732,11 @@ SWITCH_DECLARE(char *) switch_core_strdup(switch_memory_pool *pool, char *todup)
char *duped = NULL; char *duped = NULL;
size_t len; size_t len;
assert(pool != NULL); assert(pool != NULL);
assert(todup != NULL);
if (!todup) if (!todup) {
return NULL; return NULL;
}
len = strlen(todup) + 1; len = strlen(todup) + 1;
if (todup && (duped = apr_palloc(pool, len)) != 0) { if (todup && (duped = apr_palloc(pool, len)) != 0) {
...@@ -792,9 +794,11 @@ SWITCH_DECLARE(switch_status) switch_core_session_outgoing_channel(switch_core_s ...@@ -792,9 +794,11 @@ SWITCH_DECLARE(switch_status) switch_core_session_outgoing_channel(switch_core_s
if ((status = if ((status =
endpoint_interface->io_routines->outgoing_channel(session, caller_profile, endpoint_interface->io_routines->outgoing_channel(session, caller_profile,
new_session)) == SWITCH_STATUS_SUCCESS) { new_session)) == SWITCH_STATUS_SUCCESS) {
for (ptr = session->event_hooks.outgoing_channel; ptr; ptr = ptr->next) { if (session) {
if ((status = ptr->outgoing_channel(session, caller_profile, *new_session)) != SWITCH_STATUS_SUCCESS) { for (ptr = session->event_hooks.outgoing_channel; ptr; ptr = ptr->next) {
break; if ((status = ptr->outgoing_channel(session, caller_profile, *new_session)) != SWITCH_STATUS_SUCCESS) {
break;
}
} }
} }
} else { } else {
...@@ -806,7 +810,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_outgoing_channel(switch_core_s ...@@ -806,7 +810,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_outgoing_channel(switch_core_s
switch_caller_profile *profile = NULL, *peer_profile = NULL, *cloned_profile = NULL; switch_caller_profile *profile = NULL, *peer_profile = NULL, *cloned_profile = NULL;
switch_channel *channel = NULL, *peer_channel = NULL; switch_channel *channel = NULL, *peer_channel = NULL;
if ((channel = switch_core_session_get_channel(session)) != 0) { if (session && (channel = switch_core_session_get_channel(session)) != 0) {
profile = switch_channel_get_caller_profile(channel); profile = switch_channel_get_caller_profile(channel);
} }
if ((peer_channel = switch_core_session_get_channel(*new_session)) != 0) { if ((peer_channel = switch_core_session_get_channel(*new_session)) != 0) {
...@@ -820,7 +824,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_outgoing_channel(switch_core_s ...@@ -820,7 +824,7 @@ SWITCH_DECLARE(switch_status) switch_core_session_outgoing_channel(switch_core_s
} }
} }
if (peer_profile) { if (peer_profile) {
if ((cloned_profile = switch_caller_profile_clone(session, peer_profile)) != 0) { if (session && (cloned_profile = switch_caller_profile_clone(session, peer_profile)) != 0) {
switch_channel_set_originatee_caller_profile(channel, cloned_profile); switch_channel_set_originatee_caller_profile(channel, cloned_profile);
} }
} }
...@@ -1536,7 +1540,7 @@ SWITCH_DECLARE(switch_status) switch_core_new_memory_pool(switch_memory_pool **p ...@@ -1536,7 +1540,7 @@ SWITCH_DECLARE(switch_status) switch_core_new_memory_pool(switch_memory_pool **p
return SWITCH_STATUS_MEMERR; return SWITCH_STATUS_MEMERR;
} }
if ((apr_pool_create(pool, runtime.memory_pool)) != APR_SUCCESS) { if ((apr_pool_create(pool, runtime.memory_pool)) != SWITCH_STATUS_SUCCESS) {
*pool = NULL; *pool = NULL;
return SWITCH_STATUS_MEMERR; return SWITCH_STATUS_MEMERR;
} }
...@@ -1574,6 +1578,12 @@ static void switch_core_standard_on_ring(switch_core_session *session) ...@@ -1574,6 +1578,12 @@ static void switch_core_standard_on_ring(switch_core_session *session)
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Standard RING %s\n", switch_channel_get_name(session->channel)); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Standard RING %s\n", switch_channel_get_name(session->channel));
if (switch_channel_test_flag(session->channel, CF_OUTBOUND)) {
switch_channel_set_state(session->channel, CS_TRANSMIT);
return;
}
if ((caller_profile = switch_channel_get_caller_profile(session->channel)) == 0) { if ((caller_profile = switch_channel_get_caller_profile(session->channel)) == 0) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't get profile!\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't get profile!\n");
switch_channel_set_state(session->channel, CS_HANGUP); switch_channel_set_state(session->channel, CS_HANGUP);
...@@ -1656,6 +1666,11 @@ SWITCH_DECLARE(void) switch_core_session_signal_state_change(switch_core_session ...@@ -1656,6 +1666,11 @@ SWITCH_DECLARE(void) switch_core_session_signal_state_change(switch_core_session
switch_thread_cond_signal(session->cond); switch_thread_cond_signal(session->cond);
} }
SWITCH_DECLARE(unsigned int) switch_core_session_runing(switch_core_session *session)
{
return session->thread_running;
}
SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session) SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
{ {
switch_channel_state state = CS_NEW, laststate = CS_HANGUP, midstate = CS_DONE; switch_channel_state state = CS_NEW, laststate = CS_HANGUP, midstate = CS_DONE;
...@@ -1679,8 +1694,8 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session) ...@@ -1679,8 +1694,8 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
*/ */
assert(session != NULL); assert(session != NULL);
session->thread_running = 1;
endpoint_interface = session->endpoint_interface; endpoint_interface = session->endpoint_interface;
assert(endpoint_interface != NULL); assert(endpoint_interface != NULL);
...@@ -1943,7 +1958,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session) ...@@ -1943,7 +1958,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session *session)
switch_thread_cond_wait(session->cond, session->mutex); switch_thread_cond_wait(session->cond, session->mutex);
} }
} }
session->thread_running = 0;
} }
SWITCH_DECLARE(void) switch_core_session_destroy(switch_core_session **session) SWITCH_DECLARE(void) switch_core_session_destroy(switch_core_session **session)
...@@ -2065,10 +2080,11 @@ SWITCH_DECLARE(void) switch_core_session_thread_launch(switch_core_session *sess ...@@ -2065,10 +2080,11 @@ SWITCH_DECLARE(void) switch_core_session_thread_launch(switch_core_session *sess
switch_threadattr_create(&thd_attr, session->pool); switch_threadattr_create(&thd_attr, session->pool);
switch_threadattr_detach_set(thd_attr, 1); switch_threadattr_detach_set(thd_attr, 1);
if (switch_thread_create(&thread, thd_attr, switch_core_session_thread, session, session->pool) != APR_SUCCESS) { if (! session->thread_running) {
switch_core_session_destroy(&session); if (switch_thread_create(&thread, thd_attr, switch_core_session_thread, session, session->pool) != SWITCH_STATUS_SUCCESS) {
switch_core_session_destroy(&session);
}
} }
} }
SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session *session, switch_thread_start_t func, SWITCH_DECLARE(void) switch_core_session_launch_thread(switch_core_session *session, switch_thread_start_t func,
...@@ -2227,12 +2243,12 @@ SWITCH_DECLARE(switch_status) switch_core_init(char *console) ...@@ -2227,12 +2243,12 @@ SWITCH_DECLARE(switch_status) switch_core_init(char *console)
} }
/* INIT APR and Create the pool context */ /* INIT APR and Create the pool context */
if (apr_initialize() != APR_SUCCESS) { if (apr_initialize() != SWITCH_STATUS_SUCCESS) {
apr_terminate(); apr_terminate();
return SWITCH_STATUS_MEMERR; return SWITCH_STATUS_MEMERR;
} }
if (apr_pool_create(&runtime.memory_pool, NULL) != APR_SUCCESS) { if (apr_pool_create(&runtime.memory_pool, NULL) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Could not allocate memory pool\n");
switch_core_destroy(); switch_core_destroy();
return SWITCH_STATUS_MEMERR; return SWITCH_STATUS_MEMERR;
......
...@@ -50,7 +50,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_collect_digits_callback(switch_core_ses ...@@ -50,7 +50,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_collect_digits_callback(switch_core_ses
return SWITCH_STATUS_GENERR; return SWITCH_STATUS_GENERR;
} }
while (switch_channel_get_state(channel) == CS_EXECUTE) { while(switch_channel_ready(channel)) {
switch_frame *read_frame; switch_frame *read_frame;
char dtmf[128]; char dtmf[128];
...@@ -105,7 +105,8 @@ SWITCH_DECLARE(switch_status) switch_ivr_collect_digits_count(switch_core_sessio ...@@ -105,7 +105,8 @@ SWITCH_DECLARE(switch_status) switch_ivr_collect_digits_count(switch_core_sessio
if (timeout) { if (timeout) {
started = switch_time_now(); started = switch_time_now();
} }
while (switch_channel_get_state(channel) == CS_EXECUTE) {
while(switch_channel_ready(channel)) {
switch_frame *read_frame; switch_frame *read_frame;
if (timeout) { if (timeout) {
...@@ -161,7 +162,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_record_file(switch_core_session *sessio ...@@ -161,7 +162,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_record_file(switch_core_session *sessio
switch_codec codec, *read_codec; switch_codec codec, *read_codec;
char *codec_name; char *codec_name;
switch_status status = SWITCH_STATUS_SUCCESS; switch_status status = SWITCH_STATUS_SUCCESS;
if (!fh) { if (!fh) {
fh = &lfh; fh = &lfh;
} }
...@@ -206,7 +207,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_record_file(switch_core_session *sessio ...@@ -206,7 +207,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_record_file(switch_core_session *sessio
} }
while (switch_channel_get_state(channel) == CS_EXECUTE) { while(switch_channel_ready(channel)) {
size_t len; size_t len;
if (dtmf_callback || buf) { if (dtmf_callback || buf) {
...@@ -267,7 +268,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_play_file(switch_core_session *session, ...@@ -267,7 +268,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_play_file(switch_core_session *session,
int stream_id; int stream_id;
switch_status status = SWITCH_STATUS_SUCCESS; switch_status status = SWITCH_STATUS_SUCCESS;
switch_file_handle lfh; switch_file_handle lfh;
if (!fh) { if (!fh) {
fh = &lfh; fh = &lfh;
memset(fh, 0, sizeof(lfh)); memset(fh, 0, sizeof(lfh));
...@@ -332,7 +333,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_play_file(switch_core_session *session, ...@@ -332,7 +333,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_play_file(switch_core_session *session,
} }
ilen = samples; ilen = samples;
while (switch_channel_get_state(channel) == CS_EXECUTE) { while(switch_channel_ready(channel)) {
int done = 0; int done = 0;
int do_speed = 1; int do_speed = 1;
int last_speed = -1; int last_speed = -1;
...@@ -586,8 +587,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_speak_text(switch_core_session *session ...@@ -586,8 +587,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_speak_text(switch_core_session *session
} }
ilen = len; ilen = len;
while (switch_channel_get_state(channel) == CS_EXECUTE) { while(switch_channel_ready(channel)) {
if (dtmf_callback || buf) { if (dtmf_callback || buf) {
...@@ -667,7 +667,6 @@ SWITCH_DECLARE(switch_status) switch_ivr_speak_text(switch_core_session *session ...@@ -667,7 +667,6 @@ SWITCH_DECLARE(switch_status) switch_ivr_speak_text(switch_core_session *session
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "done speaking text\n"); switch_console_printf(SWITCH_CHANNEL_CONSOLE, "done speaking text\n");
switch_core_codec_destroy(&codec); switch_core_codec_destroy(&codec);
flags = 0; flags = 0;
switch_core_codec_destroy(&codec);
if (timer_name) { if (timer_name) {
/* End the audio absorbing thread */ /* End the audio absorbing thread */
...@@ -798,9 +797,11 @@ static switch_status audio_bridge_on_hangup(switch_core_session *session) ...@@ -798,9 +797,11 @@ static switch_status audio_bridge_on_hangup(switch_core_session *session)
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "CUSTOM HANGUP %s kill %s\n", switch_channel_get_name(channel), switch_console_printf(SWITCH_CHANNEL_CONSOLE, "CUSTOM HANGUP %s kill %s\n", switch_channel_get_name(channel),
switch_channel_get_name(other_channel)); switch_channel_get_name(other_channel));
switch_core_session_kill_channel(other_session, SWITCH_SIG_KILL); //switch_core_session_kill_channel(other_session, SWITCH_SIG_KILL);
switch_core_session_kill_channel(session, SWITCH_SIG_KILL); //switch_core_session_kill_channel(session, SWITCH_SIG_KILL);
if (switch_channel_test_flag(channel, CF_ORIGINATOR) && !switch_channel_test_flag(other_channel, CF_TRANSFER)) {
switch_core_session_kill_channel(other_session, SWITCH_SIG_KILL);
}
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
} }
...@@ -855,6 +856,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi ...@@ -855,6 +856,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi
switch_channel *caller_channel, *peer_channel; switch_channel *caller_channel, *peer_channel;
time_t start; time_t start;
int stream_id = 0; int stream_id = 0;
switch_frame *read_frame;
caller_channel = switch_core_session_get_channel(session); caller_channel = switch_core_session_get_channel(session);
assert(caller_channel != NULL); assert(caller_channel != NULL);
...@@ -895,12 +897,15 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi ...@@ -895,12 +897,15 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi
} }
time(&start); time(&start);
while (switch_channel_get_state(caller_channel) == CS_EXECUTE && while (switch_channel_ready(caller_channel) &&
switch_channel_get_state(peer_channel) == CS_TRANSMIT && switch_channel_ready(peer_channel) &&
!switch_channel_test_flag(peer_channel, CF_ANSWERED) && !switch_channel_test_flag(peer_channel, CF_ANSWERED) &&
!switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA) && !switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA) &&
((time(NULL) - start) < timelimit)) { ((time(NULL) - start) < timelimit)) {
switch_yield(20000); if (switch_core_session_read_frame(session, &read_frame, 1000, 0) != SWITCH_STATUS_SUCCESS) {
break;
}
switch_yield(1000);
} }
if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) { if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
...@@ -913,7 +918,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi ...@@ -913,7 +918,7 @@ SWITCH_DECLARE(switch_status) switch_ivr_multi_threaded_bridge(switch_core_sessi
switch_core_session_launch_thread(session, audio_bridge_thread, (void *) &other_audio_thread); switch_core_session_launch_thread(session, audio_bridge_thread, (void *) &other_audio_thread);
audio_bridge_thread(NULL, (void *) &this_audio_thread); audio_bridge_thread(NULL, (void *) &this_audio_thread);
switch_channel_hangup(peer_channel); //switch_channel_hangup(peer_channel);
if (other_audio_thread.running > 0) { if (other_audio_thread.running > 0) {
other_audio_thread.running = -1; other_audio_thread.running = -1;
/* wait for the other audio thread */ /* wait for the other audio thread */
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论