[commit] r12961 - in freeswitch/trunk/src: . include mod/applications/mod_conference mod/applications/mod_esf mod/applications/mod_fax mod/applications/mod_fsv mod/endpoints/mod_alsa mod/endpoints/mod_dingaling mod/endpoints/mod_iax mod/endpoints/mod_loopback mod/endpoints/mod_portaudio mod/endpoints/mod_reference mod/endpoints/mod_skypiax mod/endpoints/mod_sofia mod/endpoints/mod_unicall mod/formats/mod_portaudio_stream
Author: anthm Date: Thu Apr 9 12:17:12 2009 New Revision: 12961 Log: FSCORE-349 add flag to denote if a codec is init or not Modified: freeswitch/trunk/src/include/switch_frame.h freeswitch/trunk/src/include/switch_loadable_module.h freeswitch/trunk/src/include/switch_module_interfaces.h freeswitch/trunk/src/include/switch_types.h freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c freeswitch/trunk/src/mod/applications/mod_fax/mod_fax.c freeswitch/trunk/src/mod/applications/mod_fsv/mod_fsv.c freeswitch/trunk/src/mod/endpoints/mod_alsa/mod_alsa.c freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c freeswitch/trunk/src/mod/endpoints/mod_reference/mod_reference.c freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c freeswitch/trunk/src/mod/endpoints/mod_unicall/mod_unicall.c freeswitch/trunk/src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c freeswitch/trunk/src/switch_core_codec.c freeswitch/trunk/src/switch_core_io.c freeswitch/trunk/src/switch_core_media_bug.c freeswitch/trunk/src/switch_core_session.c freeswitch/trunk/src/switch_ivr.c freeswitch/trunk/src/switch_ivr_originate.c Modified: freeswitch/trunk/src/include/switch_frame.h ============================================================================== --- freeswitch/trunk/src/include/switch_frame.h (original) +++ freeswitch/trunk/src/include/switch_frame.h Thu Apr 9 12:17:12 2009 @@ -68,7 +68,6 @@ switch_bool_t m; /*! frame flags */ switch_frame_flag_t flags; - switch_core_session_t *session; }; SWITCH_END_EXTERN_C Modified: freeswitch/trunk/src/include/switch_loadable_module.h ============================================================================== --- freeswitch/trunk/src/include/switch_loadable_module.h (original) +++ freeswitch/trunk/src/include/switch_loadable_module.h Thu Apr 9 12:17:12 2009 @@ -413,6 +413,7 @@ impl->destroy = destroy; impl->codec_id = codec_interface->codec_id; impl->next = codec_interface->implementations; + impl->impl_id = switch_core_codec_next_id(); codec_interface->implementations = impl; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Rejected codec name: %s rate: %u ptime: %u\n", @@ -427,6 +428,11 @@ } +static inline switch_bool_t switch_core_codec_ready(switch_codec_t *codec) +{ + return (codec->flags & SWITCH_CODEC_FLAG_READY) ? SWITCH_TRUE : SWITCH_FALSE; +} + Modified: freeswitch/trunk/src/include/switch_module_interfaces.h ============================================================================== --- freeswitch/trunk/src/include/switch_module_interfaces.h (original) +++ freeswitch/trunk/src/include/switch_module_interfaces.h Thu Apr 9 12:17:12 2009 @@ -609,6 +609,7 @@ /*! deinitalize a codec handle using this implementation */ switch_core_codec_destroy_func_t destroy; uint32_t codec_id; + uint32_t impl_id; struct switch_codec_implementation *next; }; Modified: freeswitch/trunk/src/include/switch_types.h ============================================================================== --- freeswitch/trunk/src/include/switch_types.h (original) +++ freeswitch/trunk/src/include/switch_types.h Thu Apr 9 12:17:12 2009 @@ -954,7 +954,8 @@ SWITCH_CODEC_FLAG_SILENCE = (1 << 4), SWITCH_CODEC_FLAG_FREE_POOL = (1 << 5), SWITCH_CODEC_FLAG_AAL2 = (1 << 6), - SWITCH_CODEC_FLAG_PASSTHROUGH = (1 << 7) + SWITCH_CODEC_FLAG_PASSTHROUGH = (1 << 7), + SWITCH_CODEC_FLAG_READY = (1 << 8) } switch_codec_flag_enum_t; typedef uint32_t switch_codec_flag_t; Modified: freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c ============================================================================== --- freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c (original) +++ freeswitch/trunk/src/mod/applications/mod_conference/mod_conference.c Thu Apr 9 12:17:12 2009 @@ -4489,7 +4489,7 @@ switch_core_session_reset(member->session, SWITCH_TRUE, SWITCH_FALSE); - if (member->read_codec.implementation) { + if (switch_core_codec_ready(&member->read_codec)) { switch_core_codec_destroy(&member->read_codec); } Modified: freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c ============================================================================== --- freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c (original) +++ freeswitch/trunk/src/mod/applications/mod_esf/mod_esf.c Thu Apr 9 12:17:12 2009 @@ -242,7 +242,7 @@ fail: switch_core_session_set_read_codec(session, NULL); - if (codec.implementation) { + if (switch_core_codec_ready(&codec)) { switch_core_codec_destroy(&codec); } Modified: freeswitch/trunk/src/mod/applications/mod_fax/mod_fax.c ============================================================================== --- freeswitch/trunk/src/mod/applications/mod_fax/mod_fax.c (original) +++ freeswitch/trunk/src/mod/applications/mod_fax/mod_fax.c Thu Apr 9 12:17:12 2009 @@ -678,11 +678,11 @@ switch_core_session_set_read_codec(session, NULL); - if (read_codec.implementation) { + if (switch_core_codec_ready(&read_codec)) { switch_core_codec_destroy(&read_codec); } - if (write_codec.implementation) { + if (switch_core_codec_ready(&write_codec)) { switch_core_codec_destroy(&write_codec); } Modified: freeswitch/trunk/src/mod/applications/mod_fsv/mod_fsv.c ============================================================================== --- freeswitch/trunk/src/mod/applications/mod_fsv/mod_fsv.c (original) +++ freeswitch/trunk/src/mod/applications/mod_fsv/mod_fsv.c Thu Apr 9 12:17:12 2009 @@ -346,11 +346,11 @@ switch_core_session_set_read_codec(session, read_codec); } - if (codec.implementation) { + if (switch_core_codec_ready(&codec)) { switch_core_codec_destroy(&codec); } - if (vid_codec.implementation) { + if (switch_core_codec_ready(&vid_codec)) { switch_core_codec_destroy(&vid_codec); } Modified: freeswitch/trunk/src/mod/endpoints/mod_alsa/mod_alsa.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_alsa/mod_alsa.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_alsa/mod_alsa.c Thu Apr 9 12:17:12 2009 @@ -931,11 +931,11 @@ { deactivate_audio_device(); - if (globals.read_codec.implementation) { + if (switch_core_codec_ready(&globals.read_codec)) { switch_core_codec_destroy(&globals.read_codec); } - if (globals.write_codec.implementation) { + if (switch_core_codec_ready(&globals.write_codec)) { switch_core_codec_destroy(&globals.write_codec); } switch_core_hash_destroy(&globals.call_hash); Modified: freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_dingaling/mod_dingaling.c Thu Apr 9 12:17:12 2009 @@ -1244,11 +1244,11 @@ tech_pvt->rtp_session = NULL; } - if (tech_pvt->read_codec.implementation) { + if (switch_core_codec_ready(&tech_pvt->read_codec)) { switch_core_codec_destroy(&tech_pvt->read_codec); } - if (tech_pvt->write_codec.implementation) { + if (switch_core_codec_ready(&tech_pvt->write_codec)) { switch_core_codec_destroy(&tech_pvt->write_codec); } @@ -1440,7 +1440,7 @@ } } - if (!tech_pvt->read_codec.implementation) { + if (!switch_core_codec_ready(&tech_pvt->read_codec) || !tech_pvt->read_codec.implementation) { return SWITCH_STATUS_GENERR; } Modified: freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_iax/mod_iax.c Thu Apr 9 12:17:12 2009 @@ -498,11 +498,11 @@ switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); switch_clear_flag_locked(tech_pvt, TFLAG_CODEC); - if (tech_pvt->read_codec.implementation) { + if (switch_core_codec_ready(&tech_pvt->read_codec)) { switch_core_codec_destroy(&tech_pvt->read_codec); } - if (tech_pvt->write_codec.implementation) { + if (!switch_core_codec_ready(&tech_pvt->write_codec)) { switch_core_codec_destroy(&tech_pvt->write_codec); } @@ -1084,7 +1084,8 @@ if (channel && switch_channel_up(channel)) { int bytes = 0, frames = 1; - if (!switch_test_flag(tech_pvt, TFLAG_CODEC) || !tech_pvt->read_codec.implementation) { + if (!switch_test_flag(tech_pvt, TFLAG_CODEC) || !tech_pvt->read_codec.implementation || + !switch_core_codec_ready(&tech_pvt->read_codec)) { switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING); break; } Modified: freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c Thu Apr 9 12:17:12 2009 @@ -113,11 +113,11 @@ interval = codec->implementation->microseconds_per_packet / 1000; } - if (tech_pvt->read_codec.implementation) { + if (switch_core_codec_ready(&tech_pvt->read_codec)) { switch_core_codec_destroy(&tech_pvt->read_codec); } - if (tech_pvt->write_codec.implementation) { + if (switch_core_codec_ready(&tech_pvt->write_codec)) { switch_core_codec_destroy(&tech_pvt->write_codec); } @@ -133,7 +133,7 @@ NULL, switch_core_session_get_pool(session)); - if (status != SWITCH_STATUS_SUCCESS || !tech_pvt->read_codec.implementation) { + if (status != SWITCH_STATUS_SUCCESS || !tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) { goto end; } @@ -373,11 +373,11 @@ switch_core_timer_destroy(&tech_pvt->timer); - if (tech_pvt->read_codec.implementation) { + if (switch_core_codec_ready(&tech_pvt->read_codec)) { switch_core_codec_destroy(&tech_pvt->read_codec); } - if (tech_pvt->write_codec.implementation) { + if (switch_core_codec_ready(&tech_pvt->write_codec)) { switch_core_codec_destroy(&tech_pvt->write_codec); } Modified: freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_portaudio/mod_portaudio.c Thu Apr 9 12:17:12 2009 @@ -348,11 +348,11 @@ static void destroy_codecs(void) { - if (globals.read_codec.implementation) { + if (switch_core_codec_ready(&globals.read_codec)) { switch_core_codec_destroy(&globals.read_codec); } - if (globals.write_codec.implementation) { + if (switch_core_codec_ready(&globals.write_codec)) { switch_core_codec_destroy(&globals.write_codec); } @@ -1294,7 +1294,7 @@ return SWITCH_STATUS_SUCCESS; } - if (!globals.read_codec.implementation) { + if (!switch_core_codec_ready(&globals.read_codec))) { if (switch_core_codec_init(&globals.read_codec, "L16", NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, @@ -1306,7 +1306,7 @@ switch_assert(globals.read_codec.implementation); - if (!globals.write_codec.implementation) { + if (!switch_core_codec_ready(&globals.write_codec)) { if (switch_core_codec_init(&globals.write_codec, "L16", NULL, Modified: freeswitch/trunk/src/mod/endpoints/mod_reference/mod_reference.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_reference/mod_reference.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_reference/mod_reference.c Thu Apr 9 12:17:12 2009 @@ -200,11 +200,11 @@ switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); //switch_thread_cond_signal(tech_pvt->cond); - if (tech_pvt->read_codec.implementation) { + if (switch_core_codec_ready(&tech_pvt->read_codec)) { switch_core_codec_destroy(&tech_pvt->read_codec); } - if (tech_pvt->write_codec.implementation) { + if (switch_core_codec_ready(&tech_pvt->write_codec)) { switch_core_codec_destroy(&tech_pvt->write_codec); } Modified: freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_skypiax/mod_skypiax.c Thu Apr 9 12:17:12 2009 @@ -205,12 +205,12 @@ skypiax_signaling_write(tech_pvt, msg_to_skype); } - if (tech_pvt->read_codec.implementation) { - switch_core_codec_destroy(&tech_pvt->read_codec); + if (switch_core_codec_ready(&tech_pvt->read_codec)) { + switch_core_codec_destroy(&tech_pvt->read_codec); } - if (tech_pvt->write_codec.implementation) { - switch_core_codec_destroy(&tech_pvt->write_codec); + if (switch_core_codec_ready(&tech_pvt->write_codec)) { + switch_core_codec_destroy(&tech_pvt->write_codec); } memset(tech_pvt->session_uuid_str, '\0', sizeof(tech_pvt->session_uuid_str)); Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c Thu Apr 9 12:17:12 2009 @@ -379,11 +379,11 @@ sofia_clear_flag(tech_pvt, TFLAG_IO); - if (tech_pvt->read_codec.implementation) { + if (switch_core_codec_ready(&tech_pvt->read_codec)) { switch_core_codec_destroy(&tech_pvt->read_codec); } - if (tech_pvt->write_codec.implementation) { + if (switch_core_codec_ready(&tech_pvt->write_codec)) { switch_core_codec_destroy(&tech_pvt->write_codec); } @@ -665,7 +665,8 @@ tech_pvt->read_frame.datalen = 0; sofia_set_flag_locked(tech_pvt, TFLAG_READING); - if (sofia_test_flag(tech_pvt, TFLAG_HUP) || sofia_test_flag(tech_pvt, TFLAG_BYE) || !tech_pvt->read_codec.implementation) { + if (sofia_test_flag(tech_pvt, TFLAG_HUP) || sofia_test_flag(tech_pvt, TFLAG_BYE) || !tech_pvt->read_codec.implementation || + !switch_core_codec_ready(&tech_pvt->read_codec)) { return SWITCH_STATUS_FALSE; } @@ -711,7 +712,7 @@ int frames = 1; if (!switch_test_flag((&tech_pvt->read_frame), SFF_CNG)) { - if (!tech_pvt->read_codec.implementation) { + if (!tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) { *frame = NULL; return SWITCH_STATUS_GENERR; } @@ -872,7 +873,7 @@ } } - if (!tech_pvt->read_codec.implementation) { + if (!tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) { return SWITCH_STATUS_GENERR; } @@ -888,7 +889,7 @@ return SWITCH_STATUS_SUCCESS; } - if (sofia_test_flag(tech_pvt, TFLAG_BYE) || !tech_pvt->read_codec.implementation) { + if (sofia_test_flag(tech_pvt, TFLAG_BYE) || !tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) { return SWITCH_STATUS_FALSE; } Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Thu Apr 9 12:17:12 2009 @@ -1752,7 +1752,7 @@ switch_status_t sofia_glue_tech_set_video_codec(private_object_t *tech_pvt, int force) { - if (tech_pvt->video_read_codec.implementation) { + if (tech_pvt->video_read_codec.implementation && switch_core_codec_ready(&tech_pvt->video_read_codec)) { if (!force) { return SWITCH_STATUS_SUCCESS; } @@ -1825,7 +1825,7 @@ switch_goto_status(SWITCH_STATUS_FALSE, end); } - if (tech_pvt->read_codec.implementation) { + if (tech_pvt->read_codec.implementation && switch_core_codec_ready(&tech_pvt->read_codec)) { if (!force) { switch_goto_status(SWITCH_STATUS_SUCCESS, end); } @@ -1885,7 +1885,7 @@ tech_pvt->read_frame.rate = tech_pvt->rm_rate; ms = tech_pvt->write_codec.implementation->microseconds_per_packet / 1000; - if (!tech_pvt->read_codec.implementation) { + if (!switch_core_codec_ready(&tech_pvt->read_codec)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n"); switch_goto_status(SWITCH_STATUS_FALSE, end); } Modified: freeswitch/trunk/src/mod/endpoints/mod_unicall/mod_unicall.c ============================================================================== --- freeswitch/trunk/src/mod/endpoints/mod_unicall/mod_unicall.c (original) +++ freeswitch/trunk/src/mod/endpoints/mod_unicall/mod_unicall.c Thu Apr 9 12:17:12 2009 @@ -948,11 +948,11 @@ switch_clear_flag_locked(tech_pvt, TFLAG_VOICE); //switch_thread_cond_signal(tech_pvt->cond); - if (tech_pvt->read_codec.implementation) + if (switch_core_codec_ready(&tech_pvt->read_codec)) switch_core_codec_destroy(&tech_pvt->read_codec); - if (tech_pvt->write_codec.implementation) + if (switch_core_codec_ready(&tech_pvt->write_codec) switch_core_codec_destroy(&tech_pvt->write_codec); - + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s channel hangup\n", switch_channel_get_name(channel)); #if 0 Modified: freeswitch/trunk/src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c ============================================================================== --- freeswitch/trunk/src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c (original) +++ freeswitch/trunk/src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c Thu Apr 9 12:17:12 2009 @@ -171,7 +171,7 @@ return SWITCH_STATUS_SUCCESS; } - if (!source->read_codec.implementation) { + if (!switch_core_codec_ready(&source->read_codec)) { if (switch_core_codec_init(&source->read_codec, "L16", NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, @@ -183,7 +183,7 @@ switch_assert(source->read_codec.implementation); - if (!source->write_codec.implementation) { + if (!switch_core_codec_ready(&source->write_codec) { if (switch_core_codec_init(&source->write_codec, "L16", NULL, @@ -340,11 +340,11 @@ switch_mutex_lock(source->device_lock); CloseAudioStream(source->audio_stream); - if (source->read_codec.implementation) { + if (switch_core_codec_ready(&source->read_codec)) { switch_core_codec_destroy(&source->read_codec); switch_core_codec_destroy(&source->write_codec); } - if (source->write_codec.implementation) { + if (switch_core_codec_ready(&source->write_codec) { switch_core_codec_destroy(&source->write_codec); } switch_mutex_unlock(source->device_lock); Modified: freeswitch/trunk/src/switch_core_codec.c ============================================================================== --- freeswitch/trunk/src/switch_core_codec.c (original) +++ freeswitch/trunk/src/switch_core_codec.c Thu Apr 9 12:17:12 2009 @@ -100,7 +100,7 @@ switch_mutex_lock(session->codec_read_mutex); - if (codec && !codec->implementation) { + if (codec && (!codec->implementation || !switch_core_codec_ready(codec))) { codec = NULL; } @@ -221,7 +221,7 @@ switch_mutex_lock(session->codec_write_mutex); - if (!codec || !codec->implementation) { + if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) { if (session->real_write_codec) { session->write_codec = session->real_write_codec; session->write_impl = *session->real_write_codec->implementation; @@ -301,7 +301,7 @@ char tmp[30]; switch_status_t status = SWITCH_STATUS_SUCCESS; - if (!codec || !codec->implementation) { + if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) { if (session->video_read_codec) { session->video_read_codec = NULL; status = SWITCH_STATUS_SUCCESS; @@ -345,7 +345,7 @@ switch_channel_t *channel = switch_core_session_get_channel(session); char tmp[30]; switch_status_t status = SWITCH_STATUS_SUCCESS; - if (!codec || !codec->implementation) { + if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) { if (session->video_write_codec) { session->video_write_codec = NULL; status = SWITCH_STATUS_SUCCESS; @@ -493,7 +493,7 @@ implementation->init(codec, flags, codec_settings); switch_mutex_init(&codec->mutex, SWITCH_MUTEX_NESTED, codec->memory_pool); - + switch_set_flag(codec, SWITCH_CODEC_FLAG_READY); return SWITCH_STATUS_SUCCESS; } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec %s Exists but not at the desired implementation. %dhz %dms\n", codec_name, rate, @@ -518,7 +518,7 @@ switch_assert(encoded_data != NULL); switch_assert(decoded_data != NULL); - if (!codec->implementation) { + if (!codec->implementation || !switch_core_codec_ready(codec)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initialized!\n"); return SWITCH_STATUS_NOT_INITALIZED; } @@ -550,7 +550,7 @@ switch_assert(encoded_data != NULL); switch_assert(decoded_data != NULL); - if (!codec->implementation) { + if (!codec->implementation || !switch_core_codec_ready(codec)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initialized!\n"); return SWITCH_STATUS_NOT_INITALIZED; } @@ -576,7 +576,7 @@ switch_assert(codec != NULL); - if (!codec->implementation) { + if (!codec->implementation || !switch_core_codec_ready(codec)) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec is not initialized!\n"); return SWITCH_STATUS_NOT_INITALIZED; } @@ -591,11 +591,10 @@ if (mutex) switch_mutex_lock(mutex); codec->implementation->destroy(codec); + switch_clear_flag(codec, SWITCH_CODEC_FLAG_READY); UNPROTECT_INTERFACE(codec->codec_interface); - memset(codec, 0, sizeof(*codec)); - if (mutex) switch_mutex_unlock(mutex); if (free_pool) { Modified: freeswitch/trunk/src/switch_core_io.c ============================================================================== --- freeswitch/trunk/src/switch_core_io.c (original) +++ freeswitch/trunk/src/switch_core_io.c Thu Apr 9 12:17:12 2009 @@ -106,10 +106,11 @@ switch_status_t status = SWITCH_STATUS_FALSE; int need_codec, perfect, do_bugs = 0, do_resample = 0, is_cng = 0; unsigned int flag = 0; + switch_codec_implementation_t codec_impl; switch_assert(session != NULL); - if (!(session->read_codec && session->read_codec->implementation)) { + if (!(session->read_codec && session->read_codec->implementation && switch_core_codec_ready(session->read_codec))) { if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) || switch_channel_get_state(session->channel) == CS_HIBERNATE) { *frame = &runtime.dummy_cng_frame; return SWITCH_STATUS_SUCCESS; @@ -202,16 +203,21 @@ switch_assert((*frame)->codec != NULL); - if (((*frame)->codec && session->read_codec->implementation != (*frame)->codec->implementation)) { - need_codec = TRUE; - } - - if (!(session->read_codec && (*frame)->codec && (*frame)->codec->implementation)) { + switch_mutex_lock((*frame)->codec->mutex); + if (!(session->read_codec && (*frame)->codec && (*frame)->codec->implementation) && switch_core_codec_ready((*frame)->codec)) { status = SWITCH_STATUS_FALSE; + switch_mutex_unlock((*frame)->codec->mutex); goto done; } - if ((*frame)->codec->implementation->actual_samples_per_second != session->read_impl.actual_samples_per_second) { + codec_impl = *(*frame)->codec->implementation; + switch_mutex_unlock((*frame)->codec->mutex); + + if (session->read_codec->implementation->impl_id != codec_impl.impl_id) { + need_codec = TRUE; + } + + if (codec_impl.actual_samples_per_second != session->read_impl.actual_samples_per_second) { do_resample = 1; } @@ -243,7 +249,7 @@ } else { switch_codec_t *use_codec = read_frame->codec; if (do_bugs) { - if (!session->bug_codec.implementation) { + if (!switch_core_codec_ready(&session->bug_codec)) { switch_core_codec_copy(read_frame->codec, &session->bug_codec, switch_core_session_get_pool(session)); } use_codec = &session->bug_codec; @@ -525,12 +531,10 @@ even_more_done: - if (!*frame || !(*frame)->codec || !(*frame)->codec->implementation) { + if (!*frame || !(*frame)->codec || !(*frame)->codec->implementation || !switch_core_codec_ready((*frame)->codec)) { *frame = &runtime.dummy_cng_frame; } - (*frame)->session = session; - switch_mutex_unlock(session->read_codec->mutex); switch_mutex_unlock(session->codec_read_mutex); @@ -579,7 +583,7 @@ return SWITCH_STATUS_SUCCESS; } - if (!(session->write_codec && session->write_codec->implementation) && !pass_cng) { + if (!(session->write_codec && switch_core_codec_ready(session->write_codec)) && !pass_cng) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s has no write codec.\n", switch_channel_get_name(session->channel)); return SWITCH_STATUS_FALSE; } @@ -924,7 +928,7 @@ - if (frame->codec && frame->codec->implementation) { + if (frame->codec && frame->codec->implementation && switch_core_codec_ready(frame->codec)) { rate = frame->codec->implementation->actual_samples_per_second; } else { rate = session->write_impl.actual_samples_per_second; Modified: freeswitch/trunk/src/switch_core_media_bug.c ============================================================================== --- freeswitch/trunk/src/switch_core_media_bug.c (original) +++ freeswitch/trunk/src/switch_core_media_bug.c Thu Apr 9 12:17:12 2009 @@ -334,7 +334,7 @@ status = SWITCH_STATUS_SUCCESS; } - if (session->bug_codec.implementation) { + if (switch_core_codec_ready(&session->bug_codec)) { switch_core_codec_destroy(&session->bug_codec); memset(&session->bug_codec, 0, sizeof(session->bug_codec)); } @@ -389,7 +389,7 @@ } } - if (!session->bugs && session->bug_codec.implementation) { + if (!session->bugs && switch_core_codec_ready(&session->bug_codec)) { switch_core_codec_destroy(&session->bug_codec); memset(&session->bug_codec, 0, sizeof(session->bug_codec)); } @@ -427,7 +427,7 @@ switch_thread_rwlock_unlock(session->bug_rwlock); } - if (!session->bugs && session->bug_codec.implementation) { + if (!session->bugs && switch_core_codec_ready(&session->bug_codec)) { switch_core_codec_destroy(&session->bug_codec); memset(&session->bug_codec, 0, sizeof(session->bug_codec)); } Modified: freeswitch/trunk/src/switch_core_session.c ============================================================================== --- freeswitch/trunk/src/switch_core_session.c (original) +++ freeswitch/trunk/src/switch_core_session.c Thu Apr 9 12:17:12 2009 @@ -399,11 +399,11 @@ vid_read_codec = switch_core_session_get_video_read_codec(session); - if (read_codec && read_codec->implementation) { + if (read_codec && read_codec->implementation && switch_core_codec_ready(read_codec)) { char rc[80] = "", vrc[80] = "", tmp[160] = ""; switch_codec2str(read_codec, rc, sizeof(rc)); - if (vid_read_codec && vid_read_codec->implementation) { + if (vid_read_codec && vid_read_codec->implementation && switch_core_codec_ready(vid_read_codec)) { vrc[0] = ','; switch_codec2str(read_codec, vrc+1, sizeof(vrc) - 1); switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_VIDEO_CODEC_VARIABLE, vrc+1); Modified: freeswitch/trunk/src/switch_ivr.c ============================================================================== --- freeswitch/trunk/src/switch_ivr.c (original) +++ freeswitch/trunk/src/switch_ivr.c Thu Apr 9 12:17:12 2009 @@ -342,7 +342,7 @@ break; } } - if (conninfo->read_codec.implementation) { + if (switch_core_codec_ready(&conninfo->read_codec)) { switch_core_codec_destroy(&conninfo->read_codec); } switch_socket_close(conninfo->socket); Modified: freeswitch/trunk/src/switch_ivr_originate.c ============================================================================== --- freeswitch/trunk/src/switch_ivr_originate.c (original) +++ freeswitch/trunk/src/switch_ivr_originate.c Thu Apr 9 12:17:12 2009 @@ -833,7 +833,7 @@ switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE); - if (write_codec.implementation) { + if (switch_core_codec_ready(&write_codec)) { switch_core_codec_destroy(&write_codec); } @@ -2102,7 +2102,7 @@ switch_core_session_reset(oglobals.session, SWITCH_FALSE, SWITCH_TRUE); } - if (write_codec.implementation) { + if (switch_core_codec_ready(&write_codec)) { switch_core_codec_destroy(&write_codec); }
participants (1)
-
FreeSWITCH SVN