[Freeswitch-svn] [commit] r2265 - freeswitch/branches/bennylp/src/mod/endpoints/mod_pjsip
Freeswitch SVN
bennylp at freeswitch.org
Fri Aug 11 17:19:50 EDT 2006
Author: bennylp
Date: Fri Aug 11 17:19:49 2006
New Revision: 2265
Modified:
freeswitch/branches/bennylp/src/mod/endpoints/mod_pjsip/mod_pjsip.c
Log:
Handle codec nego failure more gracefully
Modified: freeswitch/branches/bennylp/src/mod/endpoints/mod_pjsip/mod_pjsip.c
==============================================================================
--- freeswitch/branches/bennylp/src/mod/endpoints/mod_pjsip/mod_pjsip.c (original)
+++ freeswitch/branches/bennylp/src/mod/endpoints/mod_pjsip/mod_pjsip.c Fri Aug 11 17:19:49 2006
@@ -1045,6 +1045,25 @@
status = pjsip_inv_answer( tech_pvt->sip_invite, 183, NULL, NULL, &txdata );
pjsip_tx_data_dec_ref(txdata);
+ /* Check that media has been negotiated successfully */
+ if (switch_channel_get_state( channel ) >= CS_HANGUP) {
+ /* Media negotiation failed */
+ status = pjsip_inv_answer(tech_pvt->sip_invite, PJSIP_SC_NOT_ACCEPTABLE, NULL, NULL, &txdata);
+ if (status == PJ_SUCCESS) {
+ status = pjsip_inv_send_msg(tech_pvt->sip_invite, txdata);
+ if (status != PJ_SUCCESS)
+ pjsip_tx_data_dec_ref(txdata);
+ }
+
+ if (status != PJ_SUCCESS) {
+ pjsip_inv_terminate( tech_pvt->sip_invite, PJSIP_SC_NOT_ACCEPTABLE, PJ_FALSE );
+ }
+
+ switch_core_session_destroy( &session );
+ pjsip_dlg_dec_lock(dialog);
+ goto on_return;
+ }
+
/* Send 180 Ring */
status = pjsip_inv_answer( tech_pvt->sip_invite, 180, NULL, NULL, &txdata );
if( status != PJ_SUCCESS ) {
@@ -1059,6 +1078,7 @@
pjsip_inv_terminate( tech_pvt->sip_invite, 500, PJ_FALSE );
switch_core_session_destroy( &session );
+ pjsip_dlg_dec_lock(dialog);
goto on_return;
}
add_server_header(txdata);
@@ -1066,6 +1086,7 @@
if( status != PJ_SUCCESS ) {
perror_(tech_pvt->sip_invite->dlg->obj_name, "pjsip_inv_send_msg error", status);
switch_core_session_destroy( &session );
+ pjsip_dlg_dec_lock(dialog);
goto on_return;
}
@@ -2010,11 +2031,24 @@
+/* PJSIP worker thread */
+static int pjsip_worker_thread(void *arg)
+{
+ while ( globals.running > 0 ) {
+ pj_time_val timeout = { 1, 0 };
+ TRACE_((THIS_FILE, "ENTER pjsip_endpt_handle_events"));
+ pjsip_endpt_handle_events( globals.sip_endpt, &timeout );
+ TRACE_((THIS_FILE, "LEAVE pjsip_endpt_handle_events"));
+ }
+ return 0;
+}
-
SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
{
+ enum { WORKER_COUNT=0 };
+ pj_thread_t *worker_threads[16];
+ int i;
switch_hash_index_t *p_entry;
pj_status_t status;
@@ -2180,8 +2214,18 @@
switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Monitor thread running\n" );
- /* main loop */
globals.running = 1;
+
+ /* Create PJSIP from worker threads */
+ for (i=0; i<WORKER_COUNT; ++i) {
+ status = pj_thread_create(pjsip_pool, "sip%p", &pjsip_worker_thread, NULL, 0, 0, &worker_threads[i]);
+ if (status != PJ_SUCCESS) {
+ perror_(THIS_FILE, "Unable to create thread!", status);
+ return SWITCH_STATUS_TERM;
+ }
+ }
+
+ /* Another worker */
while ( globals.running > 0 ) {
pj_time_val timeout = { 1, 0 };
TRACE_((THIS_FILE, "ENTER pjsip_endpt_handle_events"));
@@ -2189,6 +2233,12 @@
TRACE_((THIS_FILE, "LEAVE pjsip_endpt_handle_events"));
}
globals.running = 0;
+
+ /* Wait for all worker threads to quit */
+ for (i=0; i<WORKER_COUNT; ++i) {
+ status = pj_thread_join(worker_threads[i]);
+ }
+
switch_log_printf( SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Monitor thread exiting\n" );
More information about the Freeswitch-svn
mailing list