[Freeswitch-svn] [commit] r1762 - freeswitch/branches/stkn/src/mod/endpoints/mod_pjsip

Freeswitch SVN stkn at freeswitch.org
Wed Jul 5 18:34:25 EDT 2006


Author: stkn
Date: Wed Jul  5 18:34:24 2006
New Revision: 1762

Modified:
   freeswitch/branches/stkn/src/mod/endpoints/mod_pjsip/mod_pjsip.c

Log:
Small cleanups and state handling changed.

Modified: freeswitch/branches/stkn/src/mod/endpoints/mod_pjsip/mod_pjsip.c
==============================================================================
--- freeswitch/branches/stkn/src/mod/endpoints/mod_pjsip/mod_pjsip.c	(original)
+++ freeswitch/branches/stkn/src/mod/endpoints/mod_pjsip/mod_pjsip.c	Wed Jul  5 18:34:24 2006
@@ -1,3 +1,4 @@
+
 /*
  * Experimental PJSIP channel module for FreeSWITCH
  *
@@ -92,10 +93,10 @@
                                              switch_core_session_t **new_session, switch_memory_pool_t *pool);
 
 static switch_status_t pjsip_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
-                                             switch_io_flag_t flags, int stream_id); // unimplemented
+                                             switch_io_flag_t flags, int stream_id);
 
 static switch_status_t pjsip_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
-                                             switch_io_flag_t flags, int stream_id); // unimplemented
+                                             switch_io_flag_t flags, int stream_id);
 
 static switch_status_t pjsip_answer_channel(switch_core_session_t *session);
 static switch_status_t pjsip_kill_channel(switch_core_session_t *session, int sig);	
@@ -170,11 +171,10 @@
 	{
 		pjsip_tx_data *txdata = NULL;
 		pjmedia_sdp_session *sdp = NULL;
-//		pjsip_sip_uri *dst_uri;
 		char tmp[50];
 		pj_str_t dst;
 
-		pj_ansi_sprintf( tmp, "<sip:%s:%d>", pvt->caller_profile->destination_number, 2054 );
+		pj_ansi_sprintf( tmp, "<sip:%s:%d>", pvt->caller_profile->destination_number, 5060 );
 		pj_cstr( &dst, tmp );
 
 		pvt->sip_ua = pjsip_ua_instance();
@@ -260,8 +260,6 @@
 	/* add call to hash */
 	switch_core_hash_insert( globals.call_hash, pvt->call_id, pvt );
 
-	switch_channel_set_state( channel, CS_RING );
-
 	return SWITCH_STATUS_SUCCESS;
 } 
 
@@ -270,9 +268,14 @@
 	struct pjsip_tech_pvt *pvt;
 	switch_channel_t *channel;
 
+	assert( session != NULL );
+
 	channel = switch_core_session_get_channel( session );
+	assert( channel != NULL );
 
 	pvt = switch_core_session_get_private( session );
+	assert( pvt != NULL );
+
 #if 0 /* fix this, pjsip_inv_* is wrong here */
 	if( !switch_channel_test_flag( channel, CF_OUTBOUND ) ) {
 		pj_status_t status;
@@ -361,6 +364,8 @@
 	struct pjsip_tech_pvt *pvt;
 	switch_channel_t *channel;
 
+	assert( session != NULL );
+
 	channel = switch_core_session_get_channel( session );
 	assert( channel != NULL );
 
@@ -378,6 +383,8 @@
 	struct pjsip_tech_pvt *pvt;
 	switch_channel_t *channel;
 
+	assert( session != NULL );
+
 	channel = switch_core_session_get_channel( session );
 	assert( channel != NULL );
 
@@ -409,6 +416,7 @@
 		}
 		switch_set_flag( pvt, TFLAG_ANSWERED );
 	}
+
 	return SWITCH_STATUS_SUCCESS;
 }
 
@@ -418,6 +426,8 @@
 	struct pjsip_tech_pvt *pvt;
 	switch_channel_t *channel;
 
+	assert( session != NULL );
+
 	channel = switch_core_session_get_channel( session );
 	assert( channel != NULL );
 
@@ -425,12 +435,8 @@
 	assert( pvt != NULL );
 
 	switch_clear_flag( pvt, TFLAG_IO );
+	switch_set_flag( pvt, TFLAG_BYE );
 
-	if( !switch_test_flag( pvt, TFLAG_BYE ) ) {
-		switch_set_flag( pvt, TFLAG_BYE );
-		switch_channel_hangup( channel, SWITCH_CAUSE_NORMAL_CLEARING );
-	}
-
 	if( pvt->rtp_session ) {
 		switch_rtp_kill_socket( pvt->rtp_session );
 	}
@@ -484,9 +490,6 @@
 
 	if( outbound_profile ) {
 		switch_caller_profile_t *caller_profile = NULL;
-//		pjsip_dialog *dialog = NULL;
-//		pj_status_t status;
-//		pj_str_t dst_uri;
 		char name[128];
 
 		/* create channel name, copy profile and parse destination number (?) */
@@ -582,7 +585,6 @@
 	switch_set_flag( pvt, TFLAG_WRITING );
 
 	if( switch_test_flag( pvt, TFLAG_IO ) ) {
-//		switch_status_t status;
 		int samples, frames, bytes;
 
 		assert( pvt->rtp_session != NULL );
@@ -738,7 +740,6 @@
 						"\n** Our initial SDP **\n%s\n*********************\n", tmp_sdp );
 			}
 		}
-
 		switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Starting session thread for call %s\n", pvt->call_id );
 
 		/* set initial state */
@@ -828,8 +829,16 @@
 	{
 	case PJSIP_INV_STATE_DISCONNECTED:
 		switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "* Call %s has been disconnected\n", pvt->call_id );
-		switch_channel_hangup( channel, SWITCH_CAUSE_NORMAL_CLEARING );
-		/* -> hangup */
+		if( !switch_test_flag( pvt, TFLAG_BYE ) ) {
+			switch_call_cause_t cause;
+
+			switch( evt->body.rx_msg.rdata->msg_info.msg->line.status.code )
+			{
+			default:
+				cause = SWITCH_CAUSE_NORMAL_CLEARING;
+			}
+			switch_channel_hangup( channel, cause );
+		}
 		break;
 	case PJSIP_INV_STATE_CONFIRMED:
 		/* -> connected */
@@ -837,6 +846,9 @@
 		switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "* Call %s has been connected\n", pvt->call_id );
 		break;
 	case PJSIP_INV_STATE_EARLY:
+		switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "* Call %s, state %s\n", pvt->call_id, pjsip_inv_state_name( inv->state ) );
+		break;
+
 	case PJSIP_INV_STATE_CONNECTING:
 		switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "* Call %s, state %s\n", pvt->call_id, pjsip_inv_state_name( inv->state ) );
 		break;
@@ -851,10 +863,6 @@
 { 
 	struct pjsip_tech_pvt *pvt;
 	const pjmedia_sdp_session *remote_sdp, *local_sdp;
-#if 0
-	pjmedia_stream_info streaminfo;
-	pj_in_addr rem_addr;
-#endif
 	pj_pool_t *pool;
 	const switch_codec_interface_t *codec;
 	const switch_codec_implementation_t *imp;
@@ -865,8 +873,9 @@
 	pj_sockaddr addr;
 
 	pvt = inv->mod_data[globals.mod_app.id];
-	pool = inv->dlg->pool;
 	assert( pvt != NULL );
+
+	pool = inv->dlg->pool;
 	assert( pool != NULL );
 
 	session = pvt->session;
@@ -878,6 +887,10 @@
 	switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "-- SDP negotiation status change %s (state %s, status %d)\n", pvt->call_id,
 					pjmedia_sdp_neg_state_str(pjmedia_sdp_neg_get_state( inv->neg )), status );
 
+	if( pjmedia_sdp_neg_get_state( inv->neg ) != PJMEDIA_SDP_NEG_STATE_DONE ) {
+		switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "---- SDP negotiation still ongoing for call %s\n", pvt->call_id );
+	}
+
 	if( status != PJ_SUCCESS ) {
 		char tmp[1024];
 		pj_strerror( status, tmp, sizeof(tmp) );
@@ -981,13 +994,11 @@
 	}
 	switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Codec %s, %s:%d\n", codec->implementations->iananame, pvt->remote_sdp_audio_addr, pvt->remote_sdp_audio_port );
 
-	assert( channel != NULL );
-
+	/* start rtp */
 	start_rtp( pvt );
-#if 0
-	if( !switch_channel_test_flag( channel, CF_OUTBOUND ) )
-		switch_channel_set_state( channel, CS_RING );
-#endif
+
+	/* put channel into RING state */
+	switch_channel_set_state( channel, CS_RING );
 }
 
 static switch_status_t pjsip_receive_message(switch_core_session_t *session, switch_core_session_message_t *msg)



More information about the Freeswitch-svn mailing list