]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
update
authorAnthony Minessale <anthony.minessale@gmail.com>
Mon, 17 Mar 2008 23:26:38 +0000 (23:26 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Mon, 17 Mar 2008 23:26:38 +0000 (23:26 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7908 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/private/switch_core_pvt.h
src/include/switch_core.h
src/switch_core_codec.c
src/switch_core_io.c
src/switch_core_media_bug.c

index 4852afaa4d79dfd34aae3c3abd0504caaa04f73d..18fe82b6eaea7afe26a8fd6404b72f21fa7589c0 100644 (file)
@@ -138,6 +138,7 @@ struct switch_core_session {
        switch_frame_t enc_read_frame;
        uint8_t raw_read_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
        uint8_t enc_read_buf[SWITCH_RECOMMENDED_BUFFER_SIZE];
+       switch_codec_t bug_codec;
 };
 
 struct switch_media_bug {
index 0fa6dae535c7070392a8f1aca6158b8fc1282afd..1762b53540cf6f927517e66c8becf180f4c5d871 100644 (file)
@@ -1025,6 +1025,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_init(switch_codec_t *codec,
                                                                                                           int channels,
                                                                                                           uint32_t flags, const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool);
 
+SWITCH_DECLARE(switch_status_t) switch_core_codec_copy(switch_codec_t *codec, switch_codec_t *new_codec, switch_memory_pool_t *pool);
+
 /*! 
   \brief Encode data using a codec handle
   \param codec the codec handle to use
index 7015ca85e1afacfdf538761254c1260a6c90c66c..1b97958e6031c858fb4148442d6600ee4153b299 100644 (file)
@@ -154,6 +154,35 @@ SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_video_write_codec(switc
 }
 
 
+SWITCH_DECLARE(switch_status_t) switch_core_codec_copy(switch_codec_t *codec, switch_codec_t *new_codec, switch_memory_pool_t *pool)
+{
+       switch_status_t status;
+
+       switch_assert(codec != NULL);
+       switch_assert(new_codec != NULL);
+
+       if (pool) {
+               new_codec->memory_pool = pool;
+       } else {
+               if ((status = switch_core_new_memory_pool(&new_codec->memory_pool)) != SWITCH_STATUS_SUCCESS) {
+                       return status;
+               }
+               switch_set_flag(new_codec, SWITCH_CODEC_FLAG_FREE_POOL);
+       }
+
+       new_codec->codec_interface = codec->codec_interface;
+       new_codec->implementation = codec->implementation;
+       new_codec->flags = codec->flags;
+       
+       if (codec->fmtp_in) {
+               new_codec->fmtp_in = switch_core_strdup(new_codec->memory_pool, codec->fmtp_in);
+       }
+       
+       new_codec->implementation->init(new_codec, new_codec->flags, NULL);
+       
+       return SWITCH_STATUS_SUCCESS;   
+}
+
 SWITCH_DECLARE(switch_status_t) switch_core_codec_init(switch_codec_t *codec, char *codec_name, char *fmtp,
                                                                                                           uint32_t rate, int ms, int channels, uint32_t flags,
                                                                                                           const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool)
@@ -305,6 +334,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec)
                switch_core_destroy_memory_pool(&codec->memory_pool);
        }
 
+       memset(codec, 0, sizeof(*codec));
+
        return SWITCH_STATUS_SUCCESS;
 }
 
index cb93861ec19ee1952c95cc4816de300c38b9f5e0..1fb50f50e5e452cbdbdac7626a0b4ee844e54971 100644 (file)
@@ -186,7 +186,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
 
                if (read_frame->codec || is_cng) {
                        session->raw_read_frame.datalen = session->raw_read_frame.buflen;
-
+                       
                        if (is_cng) {
                                memset(session->raw_read_frame.data, 255, read_frame->codec->implementation->bytes_per_frame);
                                session->raw_read_frame.datalen = read_frame->codec->implementation->bytes_per_frame;
@@ -194,7 +194,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
                                read_frame = &session->raw_read_frame;
                                status = SWITCH_STATUS_SUCCESS;
                        } else {
-                               status = switch_core_codec_decode(read_frame->codec,
+                               switch_codec_t *use_codec = read_frame->codec;
+                               if (do_bugs) {
+                                       if (!session->bug_codec.implementation) {
+                                               switch_core_codec_copy(read_frame->codec, &session->bug_codec, switch_core_session_get_pool(session));
+                                       }
+                                       use_codec = &session->bug_codec;
+                               }
+
+                               status = switch_core_codec_decode(use_codec,
                                                                                                  session->read_codec,
                                                                                                  read_frame->data,
                                                                                                  read_frame->datalen,
index a509ae750fab9caef175c6b9195baf4370ee82ca..35c7be8573e7a9eab8b14c44ad5577dbc1c4e8f3 100644 (file)
@@ -288,6 +288,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_ses
                return SWITCH_STATUS_SUCCESS;
        }
        
+       if (session->bug_codec.implementation) {
+               switch_core_codec_destroy(&session->bug_codec);
+       }
+
        return SWITCH_STATUS_FALSE;
 }
 
@@ -342,6 +346,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(switch_core_session
                switch_thread_rwlock_unlock(session->bug_rwlock);
                status = switch_core_media_bug_close(&bp);
        }
+
+       if (!session->bugs && session->bug_codec.implementation) {
+               switch_core_codec_destroy(&session->bug_codec);
+       }
        
        return status;
 }