]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FSCORE-349 add flag to denote if a codec is init or not
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 9 Apr 2009 17:17:12 +0000 (17:17 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 9 Apr 2009 17:17:12 +0000 (17:17 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12961 d0543943-73ff-0310-b7d9-9358b9ac24b2

25 files changed:
src/include/switch_frame.h
src/include/switch_loadable_module.h
src/include/switch_module_interfaces.h
src/include/switch_types.h
src/mod/applications/mod_conference/mod_conference.c
src/mod/applications/mod_esf/mod_esf.c
src/mod/applications/mod_fax/mod_fax.c
src/mod/applications/mod_fsv/mod_fsv.c
src/mod/endpoints/mod_alsa/mod_alsa.c
src/mod/endpoints/mod_dingaling/mod_dingaling.c
src/mod/endpoints/mod_iax/mod_iax.c
src/mod/endpoints/mod_loopback/mod_loopback.c
src/mod/endpoints/mod_portaudio/mod_portaudio.c
src/mod/endpoints/mod_reference/mod_reference.c
src/mod/endpoints/mod_skypiax/mod_skypiax.c
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/sofia_glue.c
src/mod/endpoints/mod_unicall/mod_unicall.c
src/mod/formats/mod_portaudio_stream/mod_portaudio_stream.c
src/switch_core_codec.c
src/switch_core_io.c
src/switch_core_media_bug.c
src/switch_core_session.c
src/switch_ivr.c
src/switch_ivr_originate.c

index f78ddc08ca2c4b7a3e0454f072998a89d3790fcb..19701374d8fb836d24568e06047e7d3a1cb12fe7 100644 (file)
@@ -68,7 +68,6 @@ SWITCH_BEGIN_EXTERN_C
        switch_bool_t m;
        /*! frame flags */
        switch_frame_flag_t flags;
-       switch_core_session_t *session;
 };
 
 SWITCH_END_EXTERN_C
index 219e5d030daf185f6cdc755323cda40aa5c8e03e..03925838700c0780036bd5c7d7c8d8f76b43280f 100644 (file)
@@ -413,6 +413,7 @@ static inline void switch_core_codec_add_implementation(switch_memory_pool_t *po
                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 void switch_core_codec_add_implementation(switch_memory_pool_t *po
        }
 
 
+static inline switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
+{
+       return (codec->flags & SWITCH_CODEC_FLAG_READY) ? SWITCH_TRUE : SWITCH_FALSE;
+}
+
 
 
 
index ed0dcc3a5777de1c8da821fde25d65fdf0e931be..fa85ce42e23e73cee492239862ef640c1b950aa4 100644 (file)
@@ -609,6 +609,7 @@ struct switch_codec_implementation {
        /*! 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;
 };
 
index 6ebf7997afbc945ed468acce0be788f102d22d93..a9617174b63d1fd256f7eed279b81cd4859176c6 100644 (file)
@@ -954,7 +954,8 @@ typedef enum {
        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;
 
index f653227b0df4604c41fd1b79c66531a85ea4660c..1b524495c51f5627eac98d38582c5bfdeea406ee 100644 (file)
@@ -4489,7 +4489,7 @@ static int setup_media(conference_member_t *member, conference_obj_t *conference
 
        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);
        }
 
index a011fa5d05294be3b32ae02c85cd314a96308384..71abfd8c7b91fc9e8817e1400b3394571754d9cb 100644 (file)
@@ -242,7 +242,7 @@ SWITCH_STANDARD_APP(bcast_function)
   fail:
 
        switch_core_session_set_read_codec(session, NULL);
-       if (codec.implementation) {
+       if (switch_core_codec_ready(&codec)) {
                switch_core_codec_destroy(&codec);
        }
 
index 51d0b5c04cdcb136643d318a0a1b2031eab6804d..0b485dfa8e85a752ab178fee1133307346d0754d 100644 (file)
@@ -678,11 +678,11 @@ void process_fax(switch_core_session_t *session, const char *data, application_m
 
     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);
        }
 
index d3c20569f5b17b223fd3e5d3ee6a3d4518b2f625..704e453937b53423b6501651b0b74456ef9e018a 100644 (file)
@@ -346,11 +346,11 @@ SWITCH_STANDARD_APP(play_fsv_function)
                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);
        }
 
index 85060919fd5d8068734f799f4e8daaf8b8164f5a..a0260c0886d8a40a83ee178d432741821810d035 100644 (file)
@@ -931,11 +931,11 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_alsa_shutdown)
 {
        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);
index 3054955c8d05313bfdee76420a2664aca7a483a9..dc033325ac8f5c8d6855ffdcf13a93b0db4280bd 100644 (file)
@@ -1244,11 +1244,11 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
                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 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
                }
        }
 
-       if (!tech_pvt->read_codec.implementation) {
+       if (!switch_core_codec_ready(&tech_pvt->read_codec) || !tech_pvt->read_codec.implementation) {
                return SWITCH_STATUS_GENERR;
        }
 
index a7e4b8d0b1dc9d6b11f892e66f968b5f4b3825fc..7749a95aa66d0c5fe620396b36557791d0b79bf9 100644 (file)
@@ -498,11 +498,11 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
        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 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime)
                                        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;
                                                }
index 46d64872cde726f84df942b1b10d95185c2af612..82d8aaebdd65a5b72ab7bd2d57d7cfd2d2e871fa 100644 (file)
@@ -113,11 +113,11 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses
                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 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses
                                                                        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 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
 
        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);
        }
 
index 3c4c603e990aae3d74997e33f8ab39b9371d1d1b..644a4ba1513e51d2da17dbd34f78fc15be8459b5 100644 (file)
@@ -348,11 +348,11 @@ static void deactivate_audio_device(void)
 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 @@ static switch_status_t engage_device(int restart)
                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 @@ static switch_status_t engage_device(int restart)
 
        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,
index 470ebbc732f86bd795c7839d99557fec01b8a363..6d264ea50b88ee1f3c3517f249df47c78198badb 100644 (file)
@@ -200,11 +200,11 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
        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);
        }
 
index c183e67c97a4b3641a80e2a834a55192cd1e0f07..d90b24f19d31d974bfeb17456f12b66f7c7aae3b 100644 (file)
@@ -205,12 +205,12 @@ static switch_status_t channel_on_hangup(switch_core_session_t * session)
     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));
index fd9e34d774a2cbcc5622f7cbaac6a47a4316fc4f..f256622de9814c6ec53ff10ef810e6bdfe5437a4 100644 (file)
@@ -379,11 +379,11 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
 
        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 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
        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 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
                                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 @@ static switch_status_t sofia_write_frame(switch_core_session_t *session, switch_
                }
        }
 
-       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 @@ static switch_status_t sofia_write_frame(switch_core_session_t *session, switch_
                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;
        }
 
index dc80541e9ca8f761b133062183a6fa85bb2fed58..dc1910dea8655e5c754c122d0e6d12a9e3011ea9 100644 (file)
@@ -1752,7 +1752,7 @@ void sofia_glue_deactivate_rtp(private_object_t *tech_pvt)
 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_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
                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 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
        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);
        }
index 8198b12284689c2b22d597c7c87af5000b6beaba..55ff75a9dc938be0c86bfddd4ecaeb3dfac92a72 100644 (file)
@@ -948,11 +948,11 @@ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_hangup(%p)\n"
     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
index ceaab8947a015ad4573616acec373a0985c1b2c9..f5b990106eebcff80413d40a4cfe8bb730323f7c 100644 (file)
@@ -171,7 +171,7 @@ static switch_status_t engage_device(portaudio_stream_source_t *source,int resta
                return SWITCH_STATUS_SUCCESS;\r
        }\r
 \r
-       if (!source->read_codec.implementation) {\r
+       if (!switch_core_codec_ready(&source->read_codec)) {\r
                if (switch_core_codec_init(&source->read_codec,\r
                                                                   "L16",\r
                                                                   NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,\r
@@ -183,7 +183,7 @@ static switch_status_t engage_device(portaudio_stream_source_t *source,int resta
 \r
        switch_assert(source->read_codec.implementation);\r
 \r
-       if (!source->write_codec.implementation) {\r
+       if (!switch_core_codec_ready(&source->write_codec) {\r
                if (switch_core_codec_init(&source->write_codec,\r
                                                                   "L16",\r
                                                                   NULL,\r
@@ -340,11 +340,11 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
 \r
        switch_mutex_lock(source->device_lock);\r
        CloseAudioStream(source->audio_stream);\r
-       if (source->read_codec.implementation) {\r
+       if (switch_core_codec_ready(&source->read_codec)) {\r
                switch_core_codec_destroy(&source->read_codec);\r
                switch_core_codec_destroy(&source->write_codec);\r
        }\r
-       if (source->write_codec.implementation) {\r
+       if (switch_core_codec_ready(&source->write_codec) {\r
                switch_core_codec_destroy(&source->write_codec);\r
        }\r
        switch_mutex_unlock(source->device_lock);\r
index 9462327e10e7c6d855177bdf7c184ec3e9897ec4..4bcd43084fcc8655504267f2acab2a8c5c117257 100644 (file)
@@ -100,7 +100,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s
 
        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_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_
 
        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 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_read_codec(switch_
        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_DECLARE(switch_status_t) switch_core_session_set_video_write_codec(switch
        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 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_init(switch_codec_t *codec, co
 
                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_DECLARE(switch_status_t) switch_core_codec_encode(switch_codec_t *codec,
        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_DECLARE(switch_status_t) switch_core_codec_decode(switch_codec_t *codec,
        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_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec)
        
        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 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec)
        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) {
index 3c2c835671a4ff3f738aa386a2d1fbb9f57f2ba7..221d1d71f88e4afde754fe83a0937c772770a324 100644 (file)
@@ -106,10 +106,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
        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_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
        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 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
                        } 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 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
 
   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 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
                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 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
                                                
 
                                                
-                                               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;
index e5e6da45b95fe6cc1347e8e292fa14834363f0dd..06d32fa607064fad07e97ae983852bf89bda1fc8 100644 (file)
@@ -334,7 +334,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_ses
                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 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(switch_core_session
                }
        }
        
-       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_DECLARE(switch_status_t) switch_core_media_bug_remove_callback(switch_cor
                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));
        }
index 7189e10653a0518e9e30373eb7285ce05e6a4409..965cffe4720f04ab75fac76a6c6e5e8aa3a05e40 100644 (file)
@@ -399,11 +399,11 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_
 
                        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);
index bc761d75cf4623b63548d3b0e6fae022e9c511ee..9c4f2d5d254f49c9bf17375b22829147a4d1a71f 100644 (file)
@@ -342,7 +342,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_deactivate_unicast(switch_core_sessio
                                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);
index 91bb3e4ebf9681f012d0875b1f9734d241c760b1..8de666cfb24ceb2e901898957c89e86bd86d11e8 100644 (file)
@@ -833,7 +833,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
 
        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_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
                                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);
                        }