[Freeswitch-svn] [commit] r3019 - freeswitch/trunk/src/mod/endpoints/mod_dingaling
Freeswitch SVN
anthm at freeswitch.org
Mon Oct 9 20:11:42 EDT 2006
Author: anthm
Date: Mon Oct 9 20:11:41 2006
New Revision: 3019
Modified:
freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
Log:
improve dingaling
Modified: freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c Mon Oct 9 20:11:41 2006
@@ -68,6 +68,7 @@
TFLAG_TIMER = ( 1 << 19),
TFLAG_TERM = ( 1 << 20),
TFLAG_TRANSPORT_ACCEPT = (1 << 21),
+ TFLAG_READY = (1 << 22),
} TFLAGS;
typedef enum {
@@ -188,31 +189,25 @@
tech_pvt = switch_core_session_get_private(*session);
+ if (!tech_pvt || !switch_test_flag(tech_pvt, TFLAG_READY)) {
+ switch_core_session_destroy(session);
+ return;
+ }
- if (state < CS_INIT || !switch_core_session_running(*session)) {
- if (state > CS_INIT && state < CS_HANGUP) {
- channel_on_hangup(*session);
- }
+ if (switch_test_flag(tech_pvt, TFLAG_TERM)) {
+ /*once is enough*/
+ return;
+ }
- if (tech_pvt && tech_pvt->dlsession) {
- ldl_session_set_private(tech_pvt->dlsession, NULL);
+ if (tech_pvt->dlsession) {
+ if (!switch_test_flag(tech_pvt, TFLAG_TERM)) {
+ ldl_session_terminate(tech_pvt->dlsession);
}
- switch_core_session_destroy(session);
- } else if (tech_pvt){
- if (switch_test_flag(tech_pvt, TFLAG_TERM)) {
- /*once is enough*/
- return;
- }
-
- if (tech_pvt->dlsession) {
- if (!switch_test_flag(tech_pvt, TFLAG_TERM)) {
- ldl_session_terminate(tech_pvt->dlsession);
- }
- ldl_session_destroy(&tech_pvt->dlsession);
- }
- switch_set_flag_locked(tech_pvt, TFLAG_TERM);
+ ldl_session_destroy(&tech_pvt->dlsession);
}
+ switch_set_flag_locked(tech_pvt, TFLAG_TERM);
+
if (state < CS_HANGUP) {
switch_channel_hangup(channel, cause);
}
@@ -525,22 +520,15 @@
return 1;
}
-static void *SWITCH_THREAD_FUNC negotiate_thread_run(switch_thread_t *thread, void *obj)
+static switch_status_t negotiate_media(switch_core_session_t *session)
{
- switch_core_session_t *session = obj;
-
+ switch_status_t ret = SWITCH_STATUS_FALSE;
switch_channel_t *channel;
struct private_object *tech_pvt = NULL;
switch_time_t started;
switch_time_t now;
unsigned int elapsed;
- if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
- /* too late */
- return NULL;
- }
-
-
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
@@ -592,7 +580,6 @@
goto done;
}
switch_yield(1000);
- //printf("WAIT %s %d %d %d %d\n", switch_channel_get_name(channel), switch_test_flag(tech_pvt, TFLAG_TRANSPORT), switch_test_flag(tech_pvt, TFLAG_CODEC_READY), switch_test_flag(tech_pvt, TFLAG_RTP_READY), switch_test_flag(tech_pvt, TFLAG_ANSWER));
}
if (switch_channel_get_state(channel) >= CS_HANGUP || switch_test_flag(tech_pvt, TFLAG_BYE)) {
@@ -608,36 +595,18 @@
goto out;
}
switch_channel_answer(channel);
- //printf("***************************ANSWER\n");
- } else {
- switch_core_session_thread_launch(session);
- }
- switch_channel_set_state(channel, CS_INIT);
+ }
+ ret = SWITCH_STATUS_SUCCESS;
+
goto done;
out:
terminate_session(&session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
done:
- if (session) {
- switch_core_session_rwunlock(session);
- }
- return NULL;
-}
-
-static void negotiate_thread_launch(switch_core_session_t *session)
-{
- switch_thread_t *thread;
- switch_threadattr_t *thd_attr = NULL;
-
- switch_threadattr_create(&thd_attr, switch_core_session_get_pool(session));
- switch_threadattr_detach_set(thd_attr, 1);
- switch_thread_create(&thread, thd_attr, negotiate_thread_run, session, switch_core_session_get_pool(session));
-
+ return ret;
}
-
-
/*
State methods they get called when the state changes to the specific state
returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
@@ -656,9 +625,13 @@
tech_pvt->read_frame.buflen = SWITCH_RTP_MAX_BUF_LEN;
- /* Move Channel's State Machine to RING */
- switch_channel_set_state(channel, CS_RING);
+ switch_set_flag(tech_pvt, TFLAG_READY);
+ if (negotiate_media(session) == SWITCH_STATUS_SUCCESS) {
+ /* Move Channel's State Machine to RING */
+ switch_channel_set_state(channel, CS_RING);
+ }
+
return SWITCH_STATUS_SUCCESS;
}
@@ -810,14 +783,11 @@
assert(tech_pvt != NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF [%s]\n", dtmf);
- //snprintf(digits, sizeof(digits), "+%s\n", dtmf);
- //ldl_handle_send_msg(tech_pvt->profile->handle, tech_pvt->recip, NULL, digits);
return switch_rtp_queue_rfc2833(tech_pvt->rtp_session,
dtmf,
100 * (tech_pvt->read_codec.implementation->samples_per_second / 1000));
- //return SWITCH_STATUS_SUCCESS;
}
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
@@ -887,7 +857,6 @@
tech_pvt->timestamp_recv += (int32_t) samples;
tech_pvt->read_frame.samples = (int) samples;
tech_pvt->last_read = tech_pvt->read_frame.datalen;
- //printf("READ bytes=%d payload=%d frames=%d samples=%d ms=%d ts=%d sampcount=%d\n", (int)tech_pvt->read_frame.datalen, (int)payload, (int)frames, (int)samples, (int)ms, (int)tech_pvt->timestamp_recv, (int)tech_pvt->read_frame.samples);
break;
}
@@ -946,15 +915,13 @@
samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
- //printf("%s send %d bytes %d samples in %d frames ts=%d\n", switch_channel_get_name(channel), frame->datalen, samples, frames, tech_pvt->timestamp_send);
-
if (switch_rtp_write_frame(tech_pvt->rtp_session, frame, samples) < 0) {
return SWITCH_STATUS_FALSE;
}
tech_pvt->timestamp_send += (int) samples;
switch_clear_flag_locked(tech_pvt, TFLAG_WRITING);
- //switch_mutex_unlock(tech_pvt->rtp_lock);
+
return status;
}
@@ -969,11 +936,6 @@
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
-
- //if (!switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
-
- //}
return SWITCH_STATUS_SUCCESS;
}
@@ -1200,8 +1162,7 @@
terminate_session(new_session, __LINE__, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_GENERR;
}
- //tech_pvt->desc_id = ldl_session_describe(dlsession, NULL, 0, LDL_DESCRIPTION_INITIATE);
- negotiate_thread_launch(*new_session);
+ switch_channel_set_state(channel, CS_INIT);
return SWITCH_STATUS_SUCCESS;
}
@@ -1653,12 +1614,11 @@
status = LDL_STATUS_FALSE;
goto done;
}
-
-
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Creating a session for %s\n", ldl_session_get_id(dlsession));
ldl_session_set_private(dlsession, session);
tech_pvt->dlsession = dlsession;
- negotiate_thread_launch(session);
+ switch_channel_set_state(channel, CS_INIT);
+ switch_core_session_thread_launch(session);
} else {
status = LDL_STATUS_FALSE;
goto done;
More information about the Freeswitch-svn
mailing list