possible fix for FSCORE-221

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10346 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-11-12 11:44:13 +00:00
parent 8a338d4138
commit 9f3f08e7c5
4 changed files with 36 additions and 11 deletions

View File

@ -212,6 +212,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(_In_ switch_cor
*/ */
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(_In_ switch_media_bug_t *bug, _In_ switch_frame_t *frame); SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(_In_ switch_media_bug_t *bug, _In_ switch_frame_t *frame);
SWITCH_DECLARE(void) switch_core_media_bug_flush(_In_ switch_media_bug_t *bug);
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_flush_all(_In_ switch_core_session_t *session);
///\} ///\}
///\defgroup pa1 Port Allocation ///\defgroup pa1 Port Allocation

View File

@ -76,6 +76,12 @@ SWITCH_DECLARE(void *) switch_core_media_bug_get_user_data(switch_media_bug_t *b
return bug->user_data; return bug->user_data;
} }
SWITCH_DECLARE(void) switch_core_media_bug_flush(switch_media_bug_t *bug)
{
switch_buffer_zero(bug->raw_read_buffer);
switch_buffer_zero(bug->raw_write_buffer);
}
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *bug, switch_frame_t *frame) SWITCH_DECLARE(switch_status_t) switch_core_media_bug_read(switch_media_bug_t *bug, switch_frame_t *frame)
{ {
uint32_t bytes = 0; uint32_t bytes = 0;
@ -265,9 +271,27 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_add(switch_core_session_t
} }
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_flush_all(switch_core_session_t *session)
{
switch_media_bug_t *bp;
if (session->bugs) {
switch_thread_rwlock_wrlock(session->bug_rwlock);
for (bp = session->bugs; bp; bp = bp->next) {
switch_core_media_bug_flush(bp);
}
switch_thread_rwlock_unlock(session->bug_rwlock);
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_session_t *session) SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_session_t *session)
{ {
switch_media_bug_t *bp; switch_media_bug_t *bp;
switch_status_t status = SWITCH_STATUS_FALSE;
if (session->bugs) { if (session->bugs) {
switch_thread_rwlock_wrlock(session->bug_rwlock); switch_thread_rwlock_wrlock(session->bug_rwlock);
@ -285,7 +309,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_ses
} }
session->bugs = NULL; session->bugs = NULL;
switch_thread_rwlock_unlock(session->bug_rwlock); switch_thread_rwlock_unlock(session->bug_rwlock);
return SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
} }
if (session->bug_codec.implementation) { if (session->bug_codec.implementation) {
@ -293,7 +317,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_ses
memset(&session->bug_codec, 0, sizeof(session->bug_codec)); memset(&session->bug_codec, 0, sizeof(session->bug_codec));
} }
return SWITCH_STATUS_FALSE; return status;
} }
SWITCH_DECLARE(switch_status_t) switch_core_media_bug_close(switch_media_bug_t **bug) SWITCH_DECLARE(switch_status_t) switch_core_media_bug_close(switch_media_bug_t **bug)

View File

@ -742,6 +742,7 @@ SWITCH_DECLARE(void) switch_core_session_reset(switch_core_session_t *session, s
switch_clear_flag(session, SSF_WARN_TRANSCODE); switch_clear_flag(session, SSF_WARN_TRANSCODE);
switch_ivr_deactivate_unicast(session); switch_ivr_deactivate_unicast(session);
switch_channel_clear_flag(channel, CF_BREAK); switch_channel_clear_flag(channel, CF_BREAK);
switch_core_media_bug_flush_all(session);
} }

View File

@ -913,22 +913,18 @@ typedef struct {
static switch_bool_t inband_dtmf_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type) static switch_bool_t inband_dtmf_callback(switch_media_bug_t *bug, void *user_data, switch_abc_type_t type)
{ {
switch_inband_dtmf_t *pvt = (switch_inband_dtmf_t *) user_data; switch_inband_dtmf_t *pvt = (switch_inband_dtmf_t *) user_data;
uint8_t data[SWITCH_RECOMMENDED_BUFFER_SIZE]; switch_frame_t *frame = NULL;
switch_frame_t frame = { 0 };
char digit_str[80]; char digit_str[80];
switch_channel_t *channel = switch_core_session_get_channel(pvt->session); switch_channel_t *channel = switch_core_session_get_channel(pvt->session);
frame.data = data;
frame.buflen = SWITCH_RECOMMENDED_BUFFER_SIZE;
switch (type) { switch (type) {
case SWITCH_ABC_TYPE_INIT: case SWITCH_ABC_TYPE_INIT:
break; break;
case SWITCH_ABC_TYPE_CLOSE: case SWITCH_ABC_TYPE_CLOSE:
break; break;
case SWITCH_ABC_TYPE_READ: case SWITCH_ABC_TYPE_READ_REPLACE:
if (switch_core_media_bug_read(bug, &frame) == SWITCH_STATUS_SUCCESS) { if ((frame = switch_core_media_bug_get_read_replace_frame(bug))) {
teletone_dtmf_detect(&pvt->dtmf_detect, frame.data, frame.samples); teletone_dtmf_detect(&pvt->dtmf_detect, frame->data, frame->samples);
teletone_dtmf_get(&pvt->dtmf_detect, digit_str, sizeof(digit_str)); teletone_dtmf_get(&pvt->dtmf_detect, digit_str, sizeof(digit_str));
if (digit_str[0]) { if (digit_str[0]) {
char *p = digit_str; char *p = digit_str;
@ -941,6 +937,7 @@ static switch_bool_t inband_dtmf_callback(switch_media_bug_t *bug, void *user_da
} }
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF DETECTED: [%s]\n", digit_str); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "DTMF DETECTED: [%s]\n", digit_str);
} }
switch_core_media_bug_set_read_replace_frame(bug, frame);
} }
break; break;
case SWITCH_ABC_TYPE_WRITE: case SWITCH_ABC_TYPE_WRITE:
@ -984,7 +981,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_inband_dtmf_session(switch_core_sessi
switch_channel_pre_answer(channel); switch_channel_pre_answer(channel);
if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, 0, SMBF_READ_STREAM, &bug)) != SWITCH_STATUS_SUCCESS) { if ((status = switch_core_media_bug_add(session, inband_dtmf_callback, pvt, 0, SMBF_READ_REPLACE, &bug)) != SWITCH_STATUS_SUCCESS) {
return status; return status;
} }