gsmopen: fix FS-4150 , deleted a spurious new_inbound_channel(), checked all gsmopen->fs->sip machinery, then I got problems with audio(only in gsmopen->fs->sip not the reverse): I was baffled by a snom bug for a week, then I tested with Xlite and worked, so I grow suspicious, I updated snom320 firmware and worked. Hate those things

This commit is contained in:
Giovanni Maruzzelli 2012-05-03 10:56:37 +02:00
parent 40fff624df
commit f28ba547df
2 changed files with 70 additions and 35 deletions

View File

@ -1093,9 +1093,9 @@ read:
DEBUGA_PBX("just sent GSMOPEN_CONTROL_ANSWER\n", GSMOPEN_P_LOG);
}
} else {
tech_pvt->interface_state = GSMOPEN_STATE_UP;
DEBUGA_PBX("just interface_state UP\n", GSMOPEN_P_LOG);
}
//tech_pvt->interface_state = GSMOPEN_STATE_UP;
//DEBUGA_PBX("just interface_state UP\n", GSMOPEN_P_LOG);
}
if ((strcmp(tech_pvt->line_array.result[i], tech_pvt->at_call_calling) == 0)) {
@ -2528,7 +2528,6 @@ int gsmopen_answer(private_t *tech_pvt)
DEBUGA_PBX("call answered\n", GSMOPEN_P_LOG);
res = 0;
new_inbound_channel(tech_pvt);
if (tech_pvt->owner) {
DEBUGA_PBX("going to send GSMOPEN_STATE_UP\n", GSMOPEN_P_LOG);
ast_setstate(tech_pvt->owner, GSMOPEN_STATE_UP);
@ -2549,13 +2548,10 @@ int gsmopen_ring(private_t *tech_pvt)
switch_core_session_t *session = NULL;
switch_channel_t *channel = NULL;
if (option_debug) {
//DEBUGA_PBX("ENTERING FUNC\n", GSMOPEN_P_LOG);
}
session = switch_core_session_locate(tech_pvt->session_uuid_str);
if (session) {
switch_core_session_rwunlock(session);
//DEBUGA_PBX("got session, let's exit\n", GSMOPEN_P_LOG);
return 0;
}
@ -2570,8 +2566,9 @@ int gsmopen_ring(private_t *tech_pvt)
switch_core_session_queue_indication(session, SWITCH_MESSAGE_INDICATE_RINGING);
if (channel) {
switch_channel_mark_ring_ready(channel);
DEBUGA_GSMOPEN("switch_channel_mark_ring_ready(channel);\n", GSMOPEN_P_LOG);
} else {
ERRORA("no session\n", GSMOPEN_P_LOG);
ERRORA("no channel\n", GSMOPEN_P_LOG);
}
switch_core_session_rwunlock(session);
} else {
@ -2579,9 +2576,6 @@ int gsmopen_ring(private_t *tech_pvt)
}
if (option_debug) {
DEBUGA_PBX("EXITING FUNC\n", GSMOPEN_P_LOG);
}
return res;
}

View File

@ -296,7 +296,9 @@ switch_status_t gsmopen_tech_init(private_t *tech_pvt, switch_core_session_t *se
switch_core_timer_sync(&tech_pvt->timer_write);
switch_mutex_lock(tech_pvt->flag_mutex);
switch_clear_flag(tech_pvt, TFLAG_HANGUP);
switch_mutex_unlock(tech_pvt->flag_mutex);
DEBUGA_GSMOPEN("gsmopen_codec SUCCESS\n", GSMOPEN_P_LOG);
return SWITCH_STATUS_SUCCESS;
}
@ -474,7 +476,9 @@ static switch_status_t channel_on_init(switch_core_session_t *session)
channel = switch_core_session_get_channel(session);
switch_assert(channel != NULL);
//ERRORA("%s CHANNEL INIT\n", GSMOPEN_P_LOG, tech_pvt->name);
switch_mutex_lock(tech_pvt->flag_mutex);
switch_set_flag(tech_pvt, TFLAG_IO);
switch_mutex_unlock(tech_pvt->flag_mutex);
/* Move channel's state machine to ROUTING. This means the call is trying
to get from the initial start where the call because, to the point
@ -549,9 +553,11 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
}
DEBUGA_GSMOPEN("%s CHANNEL HANGUP\n", GSMOPEN_P_LOG, tech_pvt->name);
switch_mutex_lock(tech_pvt->flag_mutex);
switch_clear_flag(tech_pvt, TFLAG_IO);
switch_clear_flag(tech_pvt, TFLAG_VOICE);
switch_set_flag(tech_pvt, TFLAG_HANGUP);
switch_mutex_unlock(tech_pvt->flag_mutex);
gsmopen_hangup(tech_pvt);
@ -621,18 +627,18 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int
switch (sig) {
case SWITCH_SIG_KILL:
DEBUGA_GSMOPEN("%s CHANNEL got SWITCH_SIG_KILL\n", GSMOPEN_P_LOG, switch_channel_get_name(channel));
//switch_mutex_lock(tech_pvt->flag_mutex);
switch_mutex_lock(tech_pvt->flag_mutex);
switch_clear_flag(tech_pvt, TFLAG_IO);
switch_clear_flag(tech_pvt, TFLAG_VOICE);
switch_set_flag(tech_pvt, TFLAG_HANGUP);
//switch_mutex_unlock(tech_pvt->flag_mutex);
switch_mutex_unlock(tech_pvt->flag_mutex);
break;
case SWITCH_SIG_BREAK:
DEBUGA_GSMOPEN("%s CHANNEL got SWITCH_SIG_BREAK\n", GSMOPEN_P_LOG, switch_channel_get_name(channel));
//switch_set_flag(tech_pvt, TFLAG_BREAK);
//switch_mutex_lock(tech_pvt->flag_mutex);
switch_mutex_lock(tech_pvt->flag_mutex);
switch_set_flag(tech_pvt, TFLAG_BREAK);
//switch_mutex_unlock(tech_pvt->flag_mutex);
switch_mutex_unlock(tech_pvt->flag_mutex);
break;
default:
break;
@ -728,7 +734,9 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
samples = 320;
memcpy(tech_pvt->read_frame.data, buffer2, 320);
} else {
DEBUGA_GSMOPEN("read less than 320, samples=%d\n", GSMOPEN_P_LOG, samples);
if (samples != 0) {
DEBUGA_GSMOPEN("read less than 320, samples=%d\n", GSMOPEN_P_LOG, samples);
}
if (tech_pvt->buffer2_full) {
memcpy(tech_pvt->read_frame.data, tech_pvt->buffer2, 320);
tech_pvt->buffer2_full = 0;
@ -744,10 +752,14 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
*frame = &tech_pvt->read_frame;
switch_mutex_lock(tech_pvt->flag_mutex);
switch_set_flag(tech_pvt, TFLAG_VOICE);
switch_mutex_unlock(tech_pvt->flag_mutex);
if (samples != 320) {
DEBUGA_GSMOPEN("samples=%d, goto cng\n", GSMOPEN_P_LOG, samples);
if (samples != 0) {
DEBUGA_GSMOPEN("samples=%d, goto cng\n", GSMOPEN_P_LOG, samples);
}
goto cng;
}
@ -770,15 +782,17 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
switch_channel_queue_dtmf(channel, &dtmf);
p++;
}
NOTICA("DTMF DETECTED: [%s] new_dtmf_timestamp: %u, delta_t: %u\n", GSMOPEN_P_LOG, digit_str, (unsigned int) new_dtmf_timestamp,
DEBUGA_GSMOPEN("DTMF DETECTED: [%s] new_dtmf_timestamp: %u, delta_t: %u\n", GSMOPEN_P_LOG, digit_str, (unsigned int) new_dtmf_timestamp,
(unsigned int) (new_dtmf_timestamp - tech_pvt->old_dtmf_timestamp));
tech_pvt->old_dtmf_timestamp = new_dtmf_timestamp;
}
}
while (switch_test_flag(tech_pvt, TFLAG_IO)) {
if (switch_test_flag(tech_pvt, TFLAG_BREAK)) {
switch_mutex_lock(tech_pvt->flag_mutex);
switch_clear_flag(tech_pvt, TFLAG_BREAK);
DEBUGA_GSMOPEN("CHANNEL READ FRAME goto CNG\n", GSMOPEN_P_LOG);
switch_mutex_unlock(tech_pvt->flag_mutex);
DEBUGA_GSMOPEN("BREAK: CHANNEL READ FRAME goto CNG\n", GSMOPEN_P_LOG);
goto cng;
}
@ -788,7 +802,9 @@ 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)) {
switch_mutex_lock(tech_pvt->flag_mutex);
switch_clear_flag(tech_pvt, TFLAG_VOICE);
switch_mutex_unlock(tech_pvt->flag_mutex);
if (!tech_pvt->read_frame.datalen) {
DEBUGA_GSMOPEN("CHANNEL READ CONTINUE\n", GSMOPEN_P_LOG);
continue;
@ -799,11 +815,10 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
switch_swap_linear((int16_t *) (*frame)->data, (int) (*frame)->datalen / 2);
}
#endif
//WARNINGA("HERE\n", GSMOPEN_P_LOG);
//DEBUGA_GSMOPEN("HERE\n", GSMOPEN_P_LOG);
return SWITCH_STATUS_SUCCESS;
}
WARNINGA("HERE\n", GSMOPEN_P_LOG);
DEBUGA_GSMOPEN("CHANNEL READ no TFLAG_VOICE\n", GSMOPEN_P_LOG);
return SWITCH_STATUS_FALSE;
@ -874,20 +889,23 @@ static switch_status_t channel_answer_channel(switch_core_session_t *session)
switch_assert(tech_pvt != NULL);
//ERRORA("%s CHANNEL INIT\n", GSMOPEN_P_LOG, tech_pvt->name);
switch_mutex_lock(tech_pvt->flag_mutex);
switch_set_flag(tech_pvt, TFLAG_IO);
switch_mutex_unlock(tech_pvt->flag_mutex);
gsmopen_serial_answer(tech_pvt);
/* Move channel's state machine to ROUTING. This means the call is trying
to get from the initial start where the call because, to the point
where a destination has been identified. If the channel is simply
left in the initial state, nothing will happen. */
switch_channel_set_state(channel, CS_ROUTING);
switch_mutex_lock(globals.mutex);
globals.calls++;
switch_mutex_unlock(globals.mutex);
DEBUGA_GSMOPEN("%s CHANNEL ANSWER %s\n", GSMOPEN_P_LOG, tech_pvt->name, switch_core_session_get_uuid(session));
if (channel) {
switch_channel_mark_answered(channel);
}
DEBUGA_GSMOPEN("ANSWERED! \n", GSMOPEN_P_LOG);
return SWITCH_STATUS_SUCCESS;
@ -907,8 +925,21 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
switch (msg->message_id) {
case SWITCH_MESSAGE_INDICATE_ANSWER:
{
DEBUGA_GSMOPEN("MSG_ID=%d, TO BE ANSWERED!\n", GSMOPEN_P_LOG, msg->message_id);
channel_answer_channel(session);
DEBUGA_GSMOPEN("%s CHANNEL got SWITCH_MESSAGE_INDICATE_ANSWER\n", GSMOPEN_P_LOG, switch_channel_get_name(channel));
if(tech_pvt->interface_state != GSMOPEN_STATE_UP && tech_pvt->phone_callflow != CALLFLOW_CALL_ACTIVE){
DEBUGA_GSMOPEN("MSG_ID=%d, TO BE ANSWERED!\n", GSMOPEN_P_LOG, msg->message_id);
channel_answer_channel(session);
}
}
break;
case SWITCH_MESSAGE_INDICATE_PROGRESS:
{
DEBUGA_GSMOPEN("%s CHANNEL got SWITCH_MESSAGE_INDICATE_PROGRESS\n", GSMOPEN_P_LOG, switch_channel_get_name(channel));
if(tech_pvt->interface_state != GSMOPEN_STATE_UP && tech_pvt->phone_callflow != CALLFLOW_CALL_ACTIVE){
DEBUGA_GSMOPEN("MSG_ID=%d, TO BE ANSWERED!\n", GSMOPEN_P_LOG, msg->message_id);
channel_answer_channel(session);
}
}
break;
case SWITCH_MESSAGE_INDICATE_AUDIO_SYNC:
@ -919,9 +950,20 @@ static switch_status_t channel_receive_message(switch_core_session_t *session, s
break;
case SWITCH_MESSAGE_INDICATE_TRANSFER:
DEBUGA_GSMOPEN("%s CHANNEL got SWITCH_MESSAGE_INDICATE_TRANSFER\n", GSMOPEN_P_LOG, switch_channel_get_name(channel));
break;
case SWITCH_MESSAGE_INDICATE_BRIDGE:
DEBUGA_GSMOPEN("%s CHANNEL got SWITCH_MESSAGE_INDICATE_BRIDGE\n", GSMOPEN_P_LOG, switch_channel_get_name(channel));
break;
case SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY:
DEBUGA_GSMOPEN("%s CHANNEL got SWITCH_MESSAGE_INDICATE_TRANSCODING_NECESSARY\n", GSMOPEN_P_LOG, switch_channel_get_name(channel));
break;
default:
{
DEBUGA_GSMOPEN("MSG_ID=%d\n", GSMOPEN_P_LOG, msg->message_id);
if(msg->message_id != SWITCH_MESSAGE_INDICATE_APPLICATION_EXEC && msg->message_id != SWITCH_MESSAGE_INDICATE_APPLICATION_EXEC_COMPLETE){
DEBUGA_GSMOPEN("MSG_ID=%d\n", GSMOPEN_P_LOG, msg->message_id);
}
}
break;
}
@ -1089,7 +1131,9 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
caller_profile = tech_pvt->caller_profile;
caller_profile->destination_number = rdest;
switch_mutex_lock(tech_pvt->flag_mutex);
switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
switch_mutex_unlock(tech_pvt->flag_mutex);
switch_channel_set_state(channel, CS_INIT);
gsmopen_call(tech_pvt, rdest, 30);
switch_mutex_unlock(globals.mutex);
@ -2029,11 +2073,8 @@ int new_inbound_channel(private_t *tech_pvt)
return 0;
}
}
if (channel) {
//switch_channel_mark_answered(channel);
}
DEBUGA_GSMOPEN("new_inbound_channel\n", GSMOPEN_P_LOG);
DEBUGA_GSMOPEN("EXITING new_inbound_channel\n", GSMOPEN_P_LOG);
return 0;
}
@ -2727,7 +2768,7 @@ void *gsmopen_do_gsmopenapi_thread_func(void *obj)
//FIXME }
} else if (tech_pvt->controldevprotocol != PROTOCOL_NO_SERIAL && tech_pvt->interface_state == GSMOPEN_STATE_DIALING) {
WARNINGA("WE'RE DIALING, let's take the earlymedia\n", GSMOPEN_P_LOG);
DEBUGA_GSMOPEN("WE'RE DIALING, let's take the earlymedia\n", GSMOPEN_P_LOG);
tech_pvt->interface_state = CALLFLOW_STATUS_EARLYMEDIA;
remote_party_is_early_media(tech_pvt);
//new_inbound_channel(tech_pvt);
@ -2736,7 +2777,7 @@ void *gsmopen_do_gsmopenapi_thread_func(void *obj)
//FIXME }
} else if (tech_pvt->interface_state == CALLFLOW_CALL_REMOTEANSWER) {
WARNINGA("REMOTE PARTY ANSWERED\n", GSMOPEN_P_LOG);
DEBUGA_GSMOPEN("REMOTE PARTY ANSWERED\n", GSMOPEN_P_LOG);
outbound_channel_answered(tech_pvt);
//new_inbound_channel(tech_pvt);
//FIXME if (!gsmopen_new(p, AST_STATE_RING, tech_pvt->context)) {