From f9d1c7990d76348387c437afbf6862913bbe6782 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 14 Oct 2008 18:03:14 +0000 Subject: [PATCH] cleanup git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10009 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_core.h | 1 + src/switch_core_codec.c | 17 +++++++++++++++-- src/switch_core_io.c | 1 - src/switch_ivr_originate.c | 12 +++++++++++- 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/include/switch_core.h b/src/include/switch_core.h index aa1cf3097c..d3cc18df78 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -1132,6 +1132,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec) SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(_In_ switch_core_session_t *session, switch_codec_t *codec); SWITCH_DECLARE(void) switch_core_session_unset_read_codec(_In_ switch_core_session_t *session); +SWITCH_DECLARE(void) switch_core_session_unset_write_codec(_In_ switch_core_session_t *session); /*! \brief Retrieve the read codec from a given session diff --git a/src/switch_core_codec.c b/src/switch_core_codec.c index d727d2526f..6bcb1cf53e 100644 --- a/src/switch_core_codec.c +++ b/src/switch_core_codec.c @@ -47,6 +47,11 @@ SWITCH_DECLARE(void) switch_core_session_unset_read_codec(switch_core_session_t session->real_read_codec = session->read_codec = NULL; } +SWITCH_DECLARE(void) switch_core_session_unset_write_codec(switch_core_session_t *session) +{ + session->real_write_codec = session->write_codec = NULL; +} + SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_session_t *session, switch_codec_t *codec) { @@ -55,16 +60,24 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s char tmp[30]; if (codec && !codec->implementation) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set INITIALIZED codec!\n"); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set UNINITIALIZED codec!\n"); return SWITCH_STATUS_FALSE; } if (!codec || codec == session->real_read_codec) { + if (session->real_read_codec) { - session->read_codec = session->real_read_codec; + if (session->real_read_codec->implementation) { + session->read_codec = session->real_read_codec; + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "resetting to uninitilized codec, setting to NULL\n"); + session->read_codec = session->real_read_codec = NULL; + return SWITCH_STATUS_FALSE; + } } else { return SWITCH_STATUS_FALSE; } + } else if (codec) { if (session->read_codec != session->real_read_codec) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot double-set codec!\n"); diff --git a/src/switch_core_io.c b/src/switch_core_io.c index 75f6bd6ddd..95f8f5c965 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -180,7 +180,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi if (!(session->read_codec && session->read_codec->implementation)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s has no read codec.\n", switch_channel_get_name(session->channel)); - abort(); return SWITCH_STATUS_FALSE; } diff --git a/src/switch_ivr_originate.c b/src/switch_ivr_originate.c index cbac3a1ca2..14b459a534 100644 --- a/src/switch_ivr_originate.c +++ b/src/switch_ivr_originate.c @@ -88,6 +88,14 @@ static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t *thread, void char buf[10] = SWITCH_BLANK_STRING; char *p, term; + if (collect->session) { + if (switch_core_session_read_lock(collect->session) != SWITCH_STATUS_SUCCESS) { + return NULL; + } + } else { + return NULL; + } + if (!strcasecmp(collect->key, "exec")) { char *data; const switch_application_interface_t *application_interface; @@ -147,7 +155,9 @@ static void *SWITCH_THREAD_FUNC collect_thread_run(switch_thread_t *thread, void } } } - wbreak: + wbreak: + + switch_core_session_rwunlock(collect->session); return NULL; }