add more mutexed flag ops
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@1664 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
4052fc3e2d
commit
ce2a9d2636
|
@ -117,7 +117,10 @@ SWITCH_DECLARE(unsigned char) switch_char_to_rfc2833(char key);
|
||||||
\param obj the object to set the flags on
|
\param obj the object to set the flags on
|
||||||
\param flag the or'd list of flags to set
|
\param flag the or'd list of flags to set
|
||||||
*/
|
*/
|
||||||
#define switch_set_flag_locked(obj, flag) switch_mutex_lock(obj->flag_mutex); (obj)->flags |= (flag); switch_mutex_unlock(obj->flag_mutex);
|
#define switch_set_flag_locked(obj, flag) assert(obj->flag_mutex != NULL);\
|
||||||
|
switch_mutex_lock(obj->flag_mutex);\
|
||||||
|
(obj)->flags |= (flag);\
|
||||||
|
switch_mutex_unlock(obj->flag_mutex);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Clear a flag on an arbitrary object
|
\brief Clear a flag on an arbitrary object
|
||||||
|
|
|
@ -138,6 +138,7 @@ struct private_object {
|
||||||
char *recip;
|
char *recip;
|
||||||
char *dnis;
|
char *dnis;
|
||||||
uint16_t stun_port;
|
uint16_t stun_port;
|
||||||
|
switch_mutex_t *flag_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct rfc2833_digit {
|
struct rfc2833_digit {
|
||||||
|
@ -309,7 +310,7 @@ static int activate_rtp(struct private_object *tech_pvt)
|
||||||
switch_rtp_activate_ice(tech_pvt->rtp_session, tech_pvt->remote_user, tech_pvt->local_user);
|
switch_rtp_activate_ice(tech_pvt->rtp_session, tech_pvt->remote_user, tech_pvt->local_user);
|
||||||
if ((vad_in && inb) || (vad_out && !inb)) {
|
if ((vad_in && inb) || (vad_out && !inb)) {
|
||||||
switch_rtp_enable_vad(tech_pvt->rtp_session, tech_pvt->session, &tech_pvt->read_codec, SWITCH_VAD_FLAG_TALKING);
|
switch_rtp_enable_vad(tech_pvt->rtp_session, tech_pvt->session, &tech_pvt->read_codec, SWITCH_VAD_FLAG_TALKING);
|
||||||
switch_set_flag(tech_pvt, TFLAG_VAD);
|
switch_set_flag_locked(tech_pvt, TFLAG_VAD);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -333,7 +334,7 @@ static int do_candidates(struct private_object *tech_pvt, int force)
|
||||||
if (switch_test_flag(tech_pvt, TFLAG_BYE)) {
|
if (switch_test_flag(tech_pvt, TFLAG_BYE)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
switch_set_flag(tech_pvt, TFLAG_DO_CAND);
|
switch_set_flag_locked(tech_pvt, TFLAG_DO_CAND);
|
||||||
|
|
||||||
if (force || !switch_test_flag(tech_pvt, TFLAG_RTP_READY)) {
|
if (force || !switch_test_flag(tech_pvt, TFLAG_RTP_READY)) {
|
||||||
ldl_candidate_t cand[1];
|
ldl_candidate_t cand[1];
|
||||||
|
@ -393,9 +394,9 @@ static int do_candidates(struct private_object *tech_pvt, int force)
|
||||||
cand[0].protocol = "udp";
|
cand[0].protocol = "udp";
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send Candidate %s:%d [%s]\n", cand[0].address, cand[0].port, cand[0].username);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send Candidate %s:%d [%s]\n", cand[0].address, cand[0].port, cand[0].username);
|
||||||
tech_pvt->cand_id = ldl_session_candidates(tech_pvt->dlsession, cand, 1);
|
tech_pvt->cand_id = ldl_session_candidates(tech_pvt->dlsession, cand, 1);
|
||||||
switch_set_flag(tech_pvt, TFLAG_RTP_READY);
|
switch_set_flag_locked(tech_pvt, TFLAG_RTP_READY);
|
||||||
}
|
}
|
||||||
switch_clear_flag(tech_pvt, TFLAG_DO_CAND);
|
switch_clear_flag_locked(tech_pvt, TFLAG_DO_CAND);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -425,13 +426,13 @@ static int do_describe(struct private_object *tech_pvt, int force)
|
||||||
}
|
}
|
||||||
|
|
||||||
memset(payloads, 0, sizeof(payloads));
|
memset(payloads, 0, sizeof(payloads));
|
||||||
switch_set_flag(tech_pvt, TFLAG_DO_CAND);
|
switch_set_flag_locked(tech_pvt, TFLAG_DO_CAND);
|
||||||
if (!tech_pvt->num_codecs) {
|
if (!tech_pvt->num_codecs) {
|
||||||
get_codecs(tech_pvt);
|
get_codecs(tech_pvt);
|
||||||
if (!tech_pvt->num_codecs) {
|
if (!tech_pvt->num_codecs) {
|
||||||
switch_channel_hangup(channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
|
switch_channel_hangup(channel, SWITCH_CAUSE_INCOMPATIBLE_DESTINATION);
|
||||||
switch_set_flag(tech_pvt, TFLAG_BYE);
|
switch_set_flag_locked(tech_pvt, TFLAG_BYE);
|
||||||
switch_clear_flag(tech_pvt, TFLAG_IO);
|
switch_clear_flag_locked(tech_pvt, TFLAG_IO);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -455,9 +456,9 @@ static int do_describe(struct private_object *tech_pvt, int force)
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send Describe [%s]\n", payloads[0].name);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send Describe [%s]\n", payloads[0].name);
|
||||||
tech_pvt->desc_id = ldl_session_describe(tech_pvt->dlsession, payloads, 1,
|
tech_pvt->desc_id = ldl_session_describe(tech_pvt->dlsession, payloads, 1,
|
||||||
switch_test_flag(tech_pvt, TFLAG_OUTBOUND) ? LDL_DESCRIPTION_INITIATE : LDL_DESCRIPTION_ACCEPT);
|
switch_test_flag(tech_pvt, TFLAG_OUTBOUND) ? LDL_DESCRIPTION_INITIATE : LDL_DESCRIPTION_ACCEPT);
|
||||||
switch_set_flag(tech_pvt, TFLAG_CODEC_READY);
|
switch_set_flag_locked(tech_pvt, TFLAG_CODEC_READY);
|
||||||
}
|
}
|
||||||
switch_clear_flag(tech_pvt, TFLAG_DO_CAND);
|
switch_clear_flag_locked(tech_pvt, TFLAG_DO_CAND);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -477,7 +478,7 @@ static void *SWITCH_THREAD_FUNC negotiate_thread_run(switch_thread_t *thread, vo
|
||||||
channel = switch_core_session_get_channel(session);
|
channel = switch_core_session_get_channel(session);
|
||||||
assert(channel != NULL);
|
assert(channel != NULL);
|
||||||
|
|
||||||
switch_set_flag(tech_pvt, TFLAG_IO);
|
switch_set_flag_locked(tech_pvt, TFLAG_IO);
|
||||||
|
|
||||||
started = switch_time_now();
|
started = switch_time_now();
|
||||||
|
|
||||||
|
@ -513,8 +514,8 @@ static void *SWITCH_THREAD_FUNC negotiate_thread_run(switch_thread_t *thread, vo
|
||||||
}
|
}
|
||||||
if (elapsed > 60000) {
|
if (elapsed > 60000) {
|
||||||
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
||||||
switch_set_flag(tech_pvt, TFLAG_BYE);
|
switch_set_flag_locked(tech_pvt, TFLAG_BYE);
|
||||||
switch_clear_flag(tech_pvt, TFLAG_IO);
|
switch_clear_flag_locked(tech_pvt, TFLAG_IO);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (switch_test_flag(tech_pvt, TFLAG_BYE) || ! switch_test_flag(tech_pvt, TFLAG_IO)) {
|
if (switch_test_flag(tech_pvt, TFLAG_BYE) || ! switch_test_flag(tech_pvt, TFLAG_IO)) {
|
||||||
|
@ -624,9 +625,9 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
|
||||||
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_locked(tech_pvt, TFLAG_IO);
|
||||||
switch_clear_flag(tech_pvt, TFLAG_VOICE);
|
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
|
||||||
switch_set_flag(tech_pvt, TFLAG_BYE);
|
switch_set_flag_locked(tech_pvt, TFLAG_BYE);
|
||||||
|
|
||||||
if (tech_pvt->dlsession) {
|
if (tech_pvt->dlsession) {
|
||||||
ldl_session_terminate(tech_pvt->dlsession);
|
ldl_session_terminate(tech_pvt->dlsession);
|
||||||
|
@ -659,9 +660,9 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int
|
||||||
|
|
||||||
if ((channel = switch_core_session_get_channel(session))) {
|
if ((channel = switch_core_session_get_channel(session))) {
|
||||||
if ((tech_pvt = switch_core_session_get_private(session))) {
|
if ((tech_pvt = switch_core_session_get_private(session))) {
|
||||||
switch_clear_flag(tech_pvt, TFLAG_IO);
|
switch_clear_flag_locked(tech_pvt, TFLAG_IO);
|
||||||
switch_clear_flag(tech_pvt, TFLAG_VOICE);
|
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
|
||||||
switch_set_flag(tech_pvt, TFLAG_BYE);
|
switch_set_flag_locked(tech_pvt, TFLAG_BYE);
|
||||||
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
||||||
if (tech_pvt->dlsession) {
|
if (tech_pvt->dlsession) {
|
||||||
ldl_session_terminate(tech_pvt->dlsession);
|
ldl_session_terminate(tech_pvt->dlsession);
|
||||||
|
@ -749,7 +750,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
|
||||||
}
|
}
|
||||||
|
|
||||||
tech_pvt->read_frame.datalen = 0;
|
tech_pvt->read_frame.datalen = 0;
|
||||||
switch_set_flag(tech_pvt, TFLAG_READING);
|
switch_set_flag_locked(tech_pvt, TFLAG_READING);
|
||||||
|
|
||||||
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
|
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
|
||||||
samples = tech_pvt->read_codec.implementation->samples_per_frame;
|
samples = tech_pvt->read_codec.implementation->samples_per_frame;
|
||||||
|
@ -770,11 +771,11 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
|
||||||
char dtmf[128];
|
char dtmf[128];
|
||||||
switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, dtmf, sizeof(dtmf));
|
switch_rtp_dequeue_dtmf(tech_pvt->rtp_session, dtmf, sizeof(dtmf));
|
||||||
switch_channel_queue_dtmf(channel, dtmf);
|
switch_channel_queue_dtmf(channel, dtmf);
|
||||||
switch_set_flag(tech_pvt, TFLAG_DTMF);
|
switch_set_flag_locked(tech_pvt, TFLAG_DTMF);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switch_test_flag(tech_pvt, TFLAG_DTMF)) {
|
if (switch_test_flag(tech_pvt, TFLAG_DTMF)) {
|
||||||
switch_clear_flag(tech_pvt, TFLAG_DTMF);
|
switch_clear_flag_locked(tech_pvt, TFLAG_DTMF);
|
||||||
return SWITCH_STATUS_BREAK;
|
return SWITCH_STATUS_BREAK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -798,7 +799,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch_clear_flag(tech_pvt, TFLAG_READING);
|
switch_clear_flag_locked(tech_pvt, TFLAG_READING);
|
||||||
|
|
||||||
if (switch_test_flag(tech_pvt, TFLAG_BYE)) {
|
if (switch_test_flag(tech_pvt, TFLAG_BYE)) {
|
||||||
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
||||||
|
@ -838,7 +839,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
|
||||||
return SWITCH_STATUS_FALSE;
|
return SWITCH_STATUS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_set_flag(tech_pvt, TFLAG_WRITING);
|
switch_set_flag_locked(tech_pvt, TFLAG_WRITING);
|
||||||
|
|
||||||
|
|
||||||
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
|
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
|
||||||
|
@ -852,7 +853,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
|
||||||
}
|
}
|
||||||
tech_pvt->timestamp_send += (int) samples;
|
tech_pvt->timestamp_send += (int) samples;
|
||||||
|
|
||||||
switch_clear_flag(tech_pvt, TFLAG_WRITING);
|
switch_clear_flag_locked(tech_pvt, TFLAG_WRITING);
|
||||||
//switch_mutex_unlock(tech_pvt->rtp_lock);
|
//switch_mutex_unlock(tech_pvt->rtp_lock);
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
@ -1022,6 +1023,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
|
||||||
switch_core_session_add_stream(*new_session, NULL);
|
switch_core_session_add_stream(*new_session, NULL);
|
||||||
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
|
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
|
||||||
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
||||||
|
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
|
||||||
tech_pvt->flags |= globals.flags;
|
tech_pvt->flags |= globals.flags;
|
||||||
tech_pvt->flags |= mdl_profile->flags;
|
tech_pvt->flags |= mdl_profile->flags;
|
||||||
channel = switch_core_session_get_channel(*new_session);
|
channel = switch_core_session_get_channel(*new_session);
|
||||||
|
@ -1053,7 +1055,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_channel_set_flag(channel, CF_OUTBOUND);
|
switch_channel_set_flag(channel, CF_OUTBOUND);
|
||||||
switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
|
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
|
||||||
|
|
||||||
switch_stun_random_string(sess_id, 10, "0123456789");
|
switch_stun_random_string(sess_id, 10, "0123456789");
|
||||||
|
|
||||||
|
@ -1466,6 +1468,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
|
||||||
switch_core_session_add_stream(session, NULL);
|
switch_core_session_add_stream(session, NULL);
|
||||||
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
|
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
|
||||||
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
||||||
|
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
|
||||||
tech_pvt->flags |= globals.flags;
|
tech_pvt->flags |= globals.flags;
|
||||||
tech_pvt->flags |= profile->flags;
|
tech_pvt->flags |= profile->flags;
|
||||||
channel = switch_core_session_get_channel(session);
|
channel = switch_core_session_get_channel(session);
|
||||||
|
@ -1474,7 +1477,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
|
||||||
tech_pvt->codec_index = -1;
|
tech_pvt->codec_index = -1;
|
||||||
tech_pvt->profile = profile;
|
tech_pvt->profile = profile;
|
||||||
tech_pvt->local_port = switch_rtp_request_port();
|
tech_pvt->local_port = switch_rtp_request_port();
|
||||||
switch_set_flag(tech_pvt, TFLAG_ANSWER);
|
switch_set_flag_locked(tech_pvt, TFLAG_ANSWER);
|
||||||
tech_pvt->recip = switch_core_session_strdup(session, from);
|
tech_pvt->recip = switch_core_session_strdup(session, from);
|
||||||
} else {
|
} else {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Hey where is my memory pool?\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Hey where is my memory pool?\n");
|
||||||
|
@ -1495,7 +1498,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
|
||||||
if (msg) {
|
if (msg) {
|
||||||
if (*msg == '+') {
|
if (*msg == '+') {
|
||||||
switch_channel_queue_dtmf(channel, msg + 1);
|
switch_channel_queue_dtmf(channel, msg + 1);
|
||||||
switch_set_flag(tech_pvt, TFLAG_DTMF);
|
switch_set_flag_locked(tech_pvt, TFLAG_DTMF);
|
||||||
switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_BREAK);
|
switch_rtp_set_flag(tech_pvt->rtp_session, SWITCH_RTP_FLAG_BREAK);
|
||||||
}
|
}
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "SESSION MSG [%s]\n", msg);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "SESSION MSG [%s]\n", msg);
|
||||||
|
@ -1519,7 +1522,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
|
||||||
|
|
||||||
if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
|
if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
|
||||||
if (!strcasecmp(msg, "accept")) {
|
if (!strcasecmp(msg, "accept")) {
|
||||||
switch_set_flag(tech_pvt, TFLAG_ANSWER);
|
switch_set_flag_locked(tech_pvt, TFLAG_ANSWER);
|
||||||
do_candidates(tech_pvt, 0);
|
do_candidates(tech_pvt, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1665,7 +1668,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lanaddr) {
|
if (lanaddr) {
|
||||||
switch_set_flag(tech_pvt, TFLAG_LANADDR);
|
switch_set_flag_locked(tech_pvt, TFLAG_LANADDR);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!tech_pvt->num_codecs) {
|
if (!tech_pvt->num_codecs) {
|
||||||
|
@ -1683,7 +1686,7 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
|
||||||
if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
|
if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
|
||||||
do_candidates(tech_pvt, 0);
|
do_candidates(tech_pvt, 0);
|
||||||
}
|
}
|
||||||
switch_set_flag(tech_pvt, TFLAG_TRANSPORT);
|
switch_set_flag_locked(tech_pvt, TFLAG_TRANSPORT);
|
||||||
|
|
||||||
return LDL_STATUS_SUCCESS;
|
return LDL_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -1696,8 +1699,10 @@ static ldl_status handle_signalling(ldl_handle_t *handle, ldl_session_t *dlsessi
|
||||||
if (channel) {
|
if (channel) {
|
||||||
switch_channel_state_t state = switch_channel_get_state(channel);
|
switch_channel_state_t state = switch_channel_get_state(channel);
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hungup %s %u %d\n", switch_channel_get_name(channel), state, CS_INIT);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "hungup %s %u %d\n", switch_channel_get_name(channel), state, CS_INIT);
|
||||||
|
switch_mutex_lock(tech_pvt->flag_mutex);
|
||||||
switch_set_flag(tech_pvt, TFLAG_BYE);
|
switch_set_flag(tech_pvt, TFLAG_BYE);
|
||||||
switch_clear_flag(tech_pvt, TFLAG_IO);
|
switch_clear_flag(tech_pvt, TFLAG_IO);
|
||||||
|
switch_mutex_unlock(tech_pvt->flag_mutex);
|
||||||
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
||||||
|
|
||||||
if (state <= CS_INIT && !switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
|
if (state <= CS_INIT && !switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
|
||||||
|
|
|
@ -90,6 +90,7 @@ struct private_object {
|
||||||
unsigned int codecs;
|
unsigned int codecs;
|
||||||
unsigned short samprate;
|
unsigned short samprate;
|
||||||
switch_mutex_t *mutex;
|
switch_mutex_t *mutex;
|
||||||
|
switch_mutex_t *flag_mutex;
|
||||||
//switch_thread_cond_t *cond;
|
//switch_thread_cond_t *cond;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -344,7 +345,7 @@ static switch_status_t iax_set_codec(struct private_object *tech_pvt, struct iax
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!strcasecmp(dname, "l16")) {
|
if (!strcasecmp(dname, "l16")) {
|
||||||
switch_set_flag(tech_pvt, TFLAG_LINEAR);
|
switch_set_flag_locked(tech_pvt, TFLAG_LINEAR);
|
||||||
}
|
}
|
||||||
if (switch_core_codec_init(&tech_pvt->read_codec,
|
if (switch_core_codec_init(&tech_pvt->read_codec,
|
||||||
dname,
|
dname,
|
||||||
|
@ -376,7 +377,7 @@ static switch_status_t iax_set_codec(struct private_object *tech_pvt, struct iax
|
||||||
tech_pvt->read_frame.codec = &tech_pvt->read_codec;
|
tech_pvt->read_frame.codec = &tech_pvt->read_codec;
|
||||||
switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
|
switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
|
||||||
switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
|
switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
|
||||||
switch_set_flag(tech_pvt, TFLAG_CODEC);
|
switch_set_flag_locked(tech_pvt, TFLAG_CODEC);
|
||||||
}
|
}
|
||||||
tech_pvt->codec = chosen;
|
tech_pvt->codec = chosen;
|
||||||
tech_pvt->codecs = local_cap;
|
tech_pvt->codecs = local_cap;
|
||||||
|
@ -437,7 +438,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session)
|
||||||
tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
|
tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
|
||||||
iax_set_private(tech_pvt->iax_session, tech_pvt);
|
iax_set_private(tech_pvt->iax_session, tech_pvt);
|
||||||
|
|
||||||
switch_set_flag(tech_pvt, TFLAG_IO);
|
switch_set_flag_locked(tech_pvt, TFLAG_IO);
|
||||||
|
|
||||||
switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
|
switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
|
||||||
//switch_thread_cond_create(&tech_pvt->cond, switch_core_session_get_pool(session));
|
//switch_thread_cond_create(&tech_pvt->cond, switch_core_session_get_pool(session));
|
||||||
|
@ -494,8 +495,8 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
|
||||||
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_locked(tech_pvt, TFLAG_IO);
|
||||||
switch_clear_flag(tech_pvt, TFLAG_VOICE);
|
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
|
||||||
//switch_thread_cond_signal(tech_pvt->cond);
|
//switch_thread_cond_signal(tech_pvt->cond);
|
||||||
|
|
||||||
if (tech_pvt->read_codec.implementation) {
|
if (tech_pvt->read_codec.implementation) {
|
||||||
|
@ -509,7 +510,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
|
||||||
if (tech_pvt->iax_session) {
|
if (tech_pvt->iax_session) {
|
||||||
if (!switch_test_flag(tech_pvt, TFLAG_HANGUP)) {
|
if (!switch_test_flag(tech_pvt, TFLAG_HANGUP)) {
|
||||||
iax_hangup(tech_pvt->iax_session, "Hangup");
|
iax_hangup(tech_pvt->iax_session, "Hangup");
|
||||||
switch_set_flag(tech_pvt, TFLAG_HANGUP);
|
switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
|
||||||
}
|
}
|
||||||
iax_session_destroy(&tech_pvt->iax_session);
|
iax_session_destroy(&tech_pvt->iax_session);
|
||||||
}
|
}
|
||||||
|
@ -530,8 +531,8 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int
|
||||||
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_locked(tech_pvt, TFLAG_IO);
|
||||||
switch_clear_flag(tech_pvt, TFLAG_VOICE);
|
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
|
||||||
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
||||||
//switch_thread_cond_signal(tech_pvt->cond);
|
//switch_thread_cond_signal(tech_pvt->cond);
|
||||||
|
|
||||||
|
@ -612,7 +613,7 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) {
|
if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) {
|
||||||
switch_clear_flag(tech_pvt, TFLAG_VOICE);
|
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
|
||||||
if (!tech_pvt->read_frame.datalen) {
|
if (!tech_pvt->read_frame.datalen) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -737,6 +738,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
|
||||||
if ((tech_pvt =
|
if ((tech_pvt =
|
||||||
(struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
|
(struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
|
||||||
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
||||||
|
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
|
||||||
channel = switch_core_session_get_channel(*new_session);
|
channel = switch_core_session_get_channel(*new_session);
|
||||||
switch_core_session_set_private(*new_session, tech_pvt);
|
switch_core_session_set_private(*new_session, tech_pvt);
|
||||||
tech_pvt->session = *new_session;
|
tech_pvt->session = *new_session;
|
||||||
|
@ -781,7 +783,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
|
||||||
caller_profile->caller_id_name, caller_profile->destination_number, NULL, 0, req, cap);
|
caller_profile->caller_id_name, caller_profile->destination_number, NULL, 0, req, cap);
|
||||||
|
|
||||||
switch_channel_set_flag(channel, CF_OUTBOUND);
|
switch_channel_set_flag(channel, CF_OUTBOUND);
|
||||||
switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
|
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
|
||||||
switch_channel_set_state(channel, CS_INIT);
|
switch_channel_set_state(channel, CS_INIT);
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -988,6 +990,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
|
||||||
(struct private_object *) switch_core_session_alloc(session,
|
(struct private_object *) switch_core_session_alloc(session,
|
||||||
sizeof(struct private_object))) != 0) {
|
sizeof(struct private_object))) != 0) {
|
||||||
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
||||||
|
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
|
||||||
channel = switch_core_session_get_channel(session);
|
channel = switch_core_session_get_channel(session);
|
||||||
switch_core_session_set_private(session, tech_pvt);
|
switch_core_session_set_private(session, tech_pvt);
|
||||||
tech_pvt->session = session;
|
tech_pvt->session = session;
|
||||||
|
@ -1041,12 +1044,15 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
|
||||||
case IAX_EVENT_HANGUP:
|
case IAX_EVENT_HANGUP:
|
||||||
if (tech_pvt) {
|
if (tech_pvt) {
|
||||||
switch_channel_t *channel;
|
switch_channel_t *channel;
|
||||||
|
|
||||||
|
switch_mutex_lock(tech_pvt->flag_mutex);
|
||||||
switch_clear_flag(tech_pvt, TFLAG_IO);
|
switch_clear_flag(tech_pvt, TFLAG_IO);
|
||||||
switch_clear_flag(tech_pvt, TFLAG_VOICE);
|
switch_clear_flag(tech_pvt, TFLAG_VOICE);
|
||||||
|
switch_mutex_unlock(tech_pvt->flag_mutex);
|
||||||
|
|
||||||
if ((channel = switch_core_session_get_channel(tech_pvt->session)) != 0) {
|
if ((channel = switch_core_session_get_channel(tech_pvt->session)) != 0) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s\n", switch_channel_get_name(channel));
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s\n", switch_channel_get_name(channel));
|
||||||
switch_set_flag(tech_pvt, TFLAG_HANGUP);
|
switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
|
||||||
switch_channel_hangup(channel, iaxevent->etype == IAX_EVENT_HANGUP ? SWITCH_CAUSE_NORMAL_CLEARING : SWITCH_CAUSE_FACILITY_REJECTED);
|
switch_channel_hangup(channel, iaxevent->etype == IAX_EVENT_HANGUP ? SWITCH_CAUSE_NORMAL_CLEARING : SWITCH_CAUSE_FACILITY_REJECTED);
|
||||||
//switch_thread_cond_signal(tech_pvt->cond);
|
//switch_thread_cond_signal(tech_pvt->cond);
|
||||||
iaxevent->session = NULL;
|
iaxevent->session = NULL;
|
||||||
|
@ -1079,7 +1085,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
|
||||||
tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
|
tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
|
||||||
memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen);
|
memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen);
|
||||||
/* wake up the i/o thread */
|
/* wake up the i/o thread */
|
||||||
switch_set_flag(tech_pvt, TFLAG_VOICE);
|
switch_set_flag_locked(tech_pvt, TFLAG_VOICE);
|
||||||
//switch_thread_cond_signal(tech_pvt->cond);
|
//switch_thread_cond_signal(tech_pvt->cond);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,6 +92,7 @@ struct private_object {
|
||||||
PABLIO_Stream *audio_out;
|
PABLIO_Stream *audio_out;
|
||||||
int indev;
|
int indev;
|
||||||
int outdev;
|
int outdev;
|
||||||
|
switch_mutex_t *flag_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
|
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
|
||||||
|
@ -177,7 +178,7 @@ static switch_status_t channel_on_init(switch_core_session_t *session)
|
||||||
if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND) && !switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
|
if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND) && !switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
|
||||||
switch_channel_hangup(channel, SWITCH_CAUSE_NO_ANSWER);
|
switch_channel_hangup(channel, SWITCH_CAUSE_NO_ANSWER);
|
||||||
} else {
|
} else {
|
||||||
switch_set_flag(tech_pvt, TFLAG_IO);
|
switch_set_flag_locked(tech_pvt, TFLAG_IO);
|
||||||
|
|
||||||
/* Move Channel's State Machine to RING */
|
/* Move Channel's State Machine to RING */
|
||||||
switch_channel_set_state(channel, CS_RING);
|
switch_channel_set_state(channel, CS_RING);
|
||||||
|
@ -245,7 +246,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
|
||||||
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_locked(tech_pvt, TFLAG_IO);
|
||||||
switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
|
switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
|
||||||
|
|
||||||
switch_core_codec_destroy(&tech_pvt->read_codec);
|
switch_core_codec_destroy(&tech_pvt->read_codec);
|
||||||
|
@ -269,7 +270,7 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int
|
||||||
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_locked(tech_pvt, TFLAG_IO);
|
||||||
deactivate_audio_device(tech_pvt);
|
deactivate_audio_device(tech_pvt);
|
||||||
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
|
||||||
|
|
||||||
|
@ -425,7 +426,7 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
|
||||||
case SWITCH_MESSAGE_INDICATE_PROGRESS:
|
case SWITCH_MESSAGE_INDICATE_PROGRESS:
|
||||||
{
|
{
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Engage Early Media\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Engage Early Media\n");
|
||||||
switch_set_flag(tech_pvt, TFLAG_IO);
|
switch_set_flag_locked(tech_pvt, TFLAG_IO);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -524,6 +525,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
|
||||||
if ((tech_pvt =
|
if ((tech_pvt =
|
||||||
(struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
|
(struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
|
||||||
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
||||||
|
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
|
||||||
channel = switch_core_session_get_channel(*new_session);
|
channel = switch_core_session_get_channel(*new_session);
|
||||||
switch_core_session_set_private(*new_session, tech_pvt);
|
switch_core_session_set_private(*new_session, tech_pvt);
|
||||||
tech_pvt->session = *new_session;
|
tech_pvt->session = *new_session;
|
||||||
|
@ -550,7 +552,7 @@ static switch_status_t channel_outgoing_channel(switch_core_session_t *session,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_channel_set_flag(channel, CF_OUTBOUND);
|
switch_channel_set_flag(channel, CF_OUTBOUND);
|
||||||
switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
|
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
|
||||||
switch_channel_set_state(channel, CS_INIT);
|
switch_channel_set_state(channel, CS_INIT);
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -838,6 +840,7 @@ static switch_status_t place_call(char *dest, switch_stream_handle_t *stream)
|
||||||
switch_core_session_add_stream(session, NULL);
|
switch_core_session_add_stream(session, NULL);
|
||||||
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
|
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
|
||||||
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
||||||
|
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
|
||||||
channel = switch_core_session_get_channel(session);
|
channel = switch_core_session_get_channel(session);
|
||||||
switch_core_session_set_private(session, tech_pvt);
|
switch_core_session_set_private(session, tech_pvt);
|
||||||
tech_pvt->session = session;
|
tech_pvt->session = session;
|
||||||
|
@ -947,7 +950,7 @@ static switch_status_t answer_call(char *callid, switch_stream_handle_t *stream)
|
||||||
if ((tech_pvt = switch_core_hash_find(globals.call_hash, callid)) != 0) {
|
if ((tech_pvt = switch_core_hash_find(globals.call_hash, callid)) != 0) {
|
||||||
channel = switch_core_session_get_channel(tech_pvt->session);
|
channel = switch_core_session_get_channel(tech_pvt->session);
|
||||||
assert(channel != NULL);
|
assert(channel != NULL);
|
||||||
switch_set_flag(tech_pvt, TFLAG_ANSWER);
|
switch_set_flag_locked(tech_pvt, TFLAG_ANSWER);
|
||||||
switch_channel_answer(channel);
|
switch_channel_answer(channel);
|
||||||
} else {
|
} else {
|
||||||
stream->write_function(stream, "NO SUCH CALL");
|
stream->write_function(stream, "NO SUCH CALL");
|
||||||
|
|
|
@ -116,6 +116,7 @@ struct private_object {
|
||||||
switch_buffer_t *dtmf_buffer;
|
switch_buffer_t *dtmf_buffer;
|
||||||
unsigned int skip_read_frames;
|
unsigned int skip_read_frames;
|
||||||
unsigned int skip_write_frames;
|
unsigned int skip_write_frames;
|
||||||
|
switch_mutex_t *flag_mutex;
|
||||||
#ifdef DOTRACE
|
#ifdef DOTRACE
|
||||||
int fd;
|
int fd;
|
||||||
int fd2;
|
int fd2;
|
||||||
|
@ -337,7 +338,7 @@ static switch_status_t wanpipe_on_hangup(switch_core_session_t *session)
|
||||||
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_set_flag(tech_pvt, TFLAG_BYE);
|
switch_set_flag_locked(tech_pvt, TFLAG_BYE);
|
||||||
|
|
||||||
if (!switch_test_flag(tech_pvt, TFLAG_NOSIG)) {
|
if (!switch_test_flag(tech_pvt, TFLAG_NOSIG)) {
|
||||||
chanmap = tech_pvt->spri->private_info;
|
chanmap = tech_pvt->spri->private_info;
|
||||||
|
@ -656,9 +657,11 @@ static switch_status_t wanpipe_kill_channel(switch_core_session_t *session, int
|
||||||
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_mutex_lock(tech_pvt->flag_mutex);
|
||||||
switch_set_flag(tech_pvt, TFLAG_BYE);
|
switch_set_flag(tech_pvt, TFLAG_BYE);
|
||||||
switch_clear_flag(tech_pvt, TFLAG_MEDIA);
|
switch_clear_flag(tech_pvt, TFLAG_MEDIA);
|
||||||
|
switch_mutex_unlock(tech_pvt->flag_mutex);
|
||||||
|
|
||||||
sangoma_socket_close(&tech_pvt->socket);
|
sangoma_socket_close(&tech_pvt->socket);
|
||||||
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
|
@ -737,6 +740,7 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session,
|
||||||
switch_core_session_add_stream(*new_session, NULL);
|
switch_core_session_add_stream(*new_session, NULL);
|
||||||
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
|
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
|
||||||
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
||||||
|
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
|
||||||
channel = switch_core_session_get_channel(*new_session);
|
channel = switch_core_session_get_channel(*new_session);
|
||||||
switch_core_session_set_private(*new_session, tech_pvt);
|
switch_core_session_set_private(*new_session, tech_pvt);
|
||||||
tech_pvt->session = *new_session;
|
tech_pvt->session = *new_session;
|
||||||
|
@ -806,7 +810,7 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session,
|
||||||
switch_core_session_destroy(new_session);
|
switch_core_session_destroy(new_session);
|
||||||
return SWITCH_STATUS_GENERR;
|
return SWITCH_STATUS_GENERR;
|
||||||
}
|
}
|
||||||
switch_set_flag(tech_pvt, TFLAG_NOSIG);
|
switch_set_flag_locked(tech_pvt, TFLAG_NOSIG);
|
||||||
snprintf(name, sizeof(name), "WanPipe/%s/nosig-%04x", bchan, rand() & 0xffff);
|
snprintf(name, sizeof(name), "WanPipe/%s/nosig-%04x", bchan, rand() & 0xffff);
|
||||||
switch_channel_set_name(channel, name);
|
switch_channel_set_name(channel, name);
|
||||||
switch_channel_set_caller_profile(channel, caller_profile);
|
switch_channel_set_caller_profile(channel, caller_profile);
|
||||||
|
@ -901,7 +905,7 @@ static switch_status_t wanpipe_outgoing_channel(switch_core_session_t *session,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_channel_set_flag(channel, CF_OUTBOUND);
|
switch_channel_set_flag(channel, CF_OUTBOUND);
|
||||||
switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
|
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
|
||||||
switch_channel_set_state(channel, CS_INIT);
|
switch_channel_set_state(channel, CS_INIT);
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -1118,6 +1122,7 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri
|
||||||
switch_core_session_add_stream(session, NULL);
|
switch_core_session_add_stream(session, NULL);
|
||||||
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) {
|
if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) {
|
||||||
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
||||||
|
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
|
||||||
channel = switch_core_session_get_channel(session);
|
channel = switch_core_session_get_channel(session);
|
||||||
switch_core_session_set_private(session, tech_pvt);
|
switch_core_session_set_private(session, tech_pvt);
|
||||||
sprintf(name, "s%dc%d", spri->span, event->ring.channel);
|
sprintf(name, "s%dc%d", spri->span, event->ring.channel);
|
||||||
|
@ -1148,7 +1153,7 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri
|
||||||
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
|
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_set_flag(tech_pvt, TFLAG_INBOUND);
|
switch_set_flag_locked(tech_pvt, TFLAG_INBOUND);
|
||||||
tech_pvt->spri = spri;
|
tech_pvt->spri = spri;
|
||||||
tech_pvt->cause = -1;
|
tech_pvt->cause = -1;
|
||||||
|
|
||||||
|
|
|
@ -154,6 +154,7 @@ struct private_object {
|
||||||
char dtmfbuf[WOOMERA_STRLEN];
|
char dtmfbuf[WOOMERA_STRLEN];
|
||||||
switch_caller_profile_t *caller_profile;
|
switch_caller_profile_t *caller_profile;
|
||||||
struct woomera_event_queue event_queue;
|
struct woomera_event_queue event_queue;
|
||||||
|
switch_mutex_t *flag_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct private_object private_object;
|
typedef struct private_object private_object;
|
||||||
|
@ -230,7 +231,7 @@ static switch_status_t woomerachan_on_init(switch_core_session_t *session)
|
||||||
switch_core_session_set_write_codec(session, &tech_pvt->write_codec);
|
switch_core_session_set_write_codec(session, &tech_pvt->write_codec);
|
||||||
|
|
||||||
|
|
||||||
switch_set_flag(tech_pvt, TFLAG_ACTIVATE);
|
switch_set_flag_locked(tech_pvt, TFLAG_ACTIVATE);
|
||||||
|
|
||||||
switch_core_session_launch_thread(session, woomera_channel_thread_run, session);
|
switch_core_session_launch_thread(session, woomera_channel_thread_run, session);
|
||||||
|
|
||||||
|
@ -483,6 +484,7 @@ static switch_status_t woomerachan_outgoing_channel(switch_core_session_t *sessi
|
||||||
if ((tech_pvt =
|
if ((tech_pvt =
|
||||||
(struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
|
(struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object))) != 0) {
|
||||||
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
||||||
|
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(*new_session));
|
||||||
tech_pvt->profile = &default_profile;
|
tech_pvt->profile = &default_profile;
|
||||||
channel = switch_core_session_get_channel(*new_session);
|
channel = switch_core_session_get_channel(*new_session);
|
||||||
switch_core_session_set_private(*new_session, tech_pvt);
|
switch_core_session_set_private(*new_session, tech_pvt);
|
||||||
|
@ -510,7 +512,7 @@ static switch_status_t woomerachan_outgoing_channel(switch_core_session_t *sessi
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_channel_set_flag(channel, CF_OUTBOUND);
|
switch_channel_set_flag(channel, CF_OUTBOUND);
|
||||||
switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
|
switch_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
|
||||||
switch_channel_set_state(channel, CS_INIT);
|
switch_channel_set_state(channel, CS_INIT);
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -907,13 +909,13 @@ static int tech_activate(private_object * tech_pvt)
|
||||||
woomera_message_parse(tech_pvt->command_channel,
|
woomera_message_parse(tech_pvt->command_channel,
|
||||||
&wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue);
|
&wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue);
|
||||||
} else {
|
} else {
|
||||||
switch_set_flag(tech_pvt, TFLAG_PARSE_INCOMING);
|
switch_set_flag_locked(tech_pvt, TFLAG_PARSE_INCOMING);
|
||||||
woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "LISTEN%s", WOOMERA_RECORD_SEPERATOR);
|
woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "LISTEN%s", WOOMERA_RECORD_SEPERATOR);
|
||||||
if (woomera_message_parse(tech_pvt->command_channel,
|
if (woomera_message_parse(tech_pvt->command_channel,
|
||||||
&wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
|
&wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
|
||||||
tech_pvt->profile->name);
|
tech_pvt->profile->name);
|
||||||
switch_set_flag(tech_pvt, TFLAG_ABORT);
|
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
|
||||||
globals.panic = 1;
|
globals.panic = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -949,7 +951,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (globals.panic) {
|
if (globals.panic) {
|
||||||
switch_set_flag(tech_pvt, TFLAG_ABORT);
|
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switch_test_flag(tech_pvt, TFLAG_ABORT)) {
|
if (switch_test_flag(tech_pvt, TFLAG_ABORT)) {
|
||||||
|
@ -959,12 +961,12 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switch_test_flag(tech_pvt, TFLAG_ACTIVATE)) {
|
if (switch_test_flag(tech_pvt, TFLAG_ACTIVATE)) {
|
||||||
switch_clear_flag(tech_pvt, TFLAG_ACTIVATE);
|
switch_clear_flag_locked(tech_pvt, TFLAG_ACTIVATE);
|
||||||
tech_activate(tech_pvt);
|
tech_activate(tech_pvt);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
|
if (switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
|
||||||
switch_clear_flag(tech_pvt, TFLAG_ANSWER);
|
switch_clear_flag_locked(tech_pvt, TFLAG_ANSWER);
|
||||||
#ifdef USE_ANSWER
|
#ifdef USE_ANSWER
|
||||||
woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "ANSWER %s%s", tech_pvt->call_info.callid,
|
woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "ANSWER %s%s", tech_pvt->call_info.callid,
|
||||||
WOOMERA_RECORD_SEPERATOR);
|
WOOMERA_RECORD_SEPERATOR);
|
||||||
|
@ -973,7 +975,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
|
||||||
&tech_pvt->event_queue) < 0) {
|
&tech_pvt->event_queue) < 0) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
|
||||||
tech_pvt->profile->name);
|
tech_pvt->profile->name);
|
||||||
switch_set_flag(tech_pvt, TFLAG_ABORT);
|
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
|
||||||
globals.panic = 1;
|
globals.panic = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -989,11 +991,11 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
|
||||||
&tech_pvt->event_queue) < 0) {
|
&tech_pvt->event_queue) < 0) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
|
||||||
tech_pvt->profile->name);
|
tech_pvt->profile->name);
|
||||||
switch_set_flag(tech_pvt, TFLAG_ABORT);
|
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
|
||||||
globals.panic = 1;
|
globals.panic = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
switch_clear_flag(tech_pvt, TFLAG_DTMF);
|
switch_clear_flag_locked(tech_pvt, TFLAG_DTMF);
|
||||||
memset(tech_pvt->dtmfbuf, 0, sizeof(tech_pvt->dtmfbuf));
|
memset(tech_pvt->dtmfbuf, 0, sizeof(tech_pvt->dtmfbuf));
|
||||||
switch_mutex_unlock(tech_pvt->iolock);
|
switch_mutex_unlock(tech_pvt->iolock);
|
||||||
}
|
}
|
||||||
|
@ -1007,7 +1009,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
|
||||||
((tech_pvt->started.tv_sec * 1000) + tech_pvt->started.tv_usec / 1000));
|
((tech_pvt->started.tv_sec * 1000) + tech_pvt->started.tv_usec / 1000));
|
||||||
if (elapsed > tech_pvt->timeout) {
|
if (elapsed > tech_pvt->timeout) {
|
||||||
/* call timed out! */
|
/* call timed out! */
|
||||||
switch_set_flag(tech_pvt, TFLAG_ABORT);
|
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1020,7 +1022,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
|
||||||
(res = woomera_message_parse(tech_pvt->command_channel, &wmsg, 100, tech_pvt->profile, NULL)) != 0) {
|
(res = woomera_message_parse(tech_pvt->command_channel, &wmsg, 100, tech_pvt->profile, NULL)) != 0) {
|
||||||
|
|
||||||
if (res < 0 || !strcasecmp(wmsg.command, "HANGUP")) {
|
if (res < 0 || !strcasecmp(wmsg.command, "HANGUP")) {
|
||||||
switch_set_flag(tech_pvt, TFLAG_ABORT);
|
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
|
||||||
continue;
|
continue;
|
||||||
} else if (!strcasecmp(wmsg.command, "DTMF")) {
|
} else if (!strcasecmp(wmsg.command, "DTMF")) {
|
||||||
/*
|
/*
|
||||||
|
@ -1043,8 +1045,8 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
|
||||||
char *cid_num;
|
char *cid_num;
|
||||||
char *ip;
|
char *ip;
|
||||||
char *p;
|
char *p;
|
||||||
switch_clear_flag(tech_pvt, TFLAG_PARSE_INCOMING);
|
switch_clear_flag_locked(tech_pvt, TFLAG_PARSE_INCOMING);
|
||||||
switch_set_flag(tech_pvt, TFLAG_INCOMING);
|
switch_set_flag_locked(tech_pvt, TFLAG_INCOMING);
|
||||||
tech_pvt->call_info = wmsg;
|
tech_pvt->call_info = wmsg;
|
||||||
|
|
||||||
exten = woomera_message_header(&wmsg, "Local-Number");
|
exten = woomera_message_header(&wmsg, "Local-Number");
|
||||||
|
@ -1088,7 +1090,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
|
||||||
&wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
|
&wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
|
||||||
tech_pvt->profile->name);
|
tech_pvt->profile->name);
|
||||||
switch_set_flag(tech_pvt, TFLAG_ABORT);
|
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
|
||||||
globals.panic = 1;
|
globals.panic = 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -1242,6 +1244,7 @@ static void *woomera_thread_run(void *obj)
|
||||||
if ((tech_pvt =
|
if ((tech_pvt =
|
||||||
(struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
|
(struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object))) != 0) {
|
||||||
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
memset(tech_pvt, 0, sizeof(*tech_pvt));
|
||||||
|
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
|
||||||
tech_pvt->profile = &default_profile;
|
tech_pvt->profile = &default_profile;
|
||||||
channel = switch_core_session_get_channel(session);
|
channel = switch_core_session_get_channel(session);
|
||||||
switch_core_session_set_private(session, tech_pvt);
|
switch_core_session_set_private(session, tech_pvt);
|
||||||
|
|
Loading…
Reference in New Issue