]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix some stuff
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 27 Mar 2008 22:22:46 +0000 (22:22 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 27 Mar 2008 22:22:46 +0000 (22:22 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7973 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_loadable_module.h
src/include/switch_module_interfaces.h
src/switch_core_codec.c
src/switch_core_io.c

index 19514d7fb3ec503105498466da0c41dc9fb7e604..07903e933a3a0739642db8b4db09d5d11fdd962f 100644 (file)
@@ -306,11 +306,14 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void);
        break; \
        }
 
+SWITCH_DECLARE(uint32_t) switch_core_codec_next_id(void);
+
 #define SWITCH_ADD_CODEC(codec_int, int_name) \
        for (;;) { \
-       codec_int = (switch_codec_interface_t *)switch_loadable_module_create_interface(*module_interface, SWITCH_CODEC_INTERFACE); \
-       codec_int->interface_name = switch_core_strdup(pool, int_name); \
-       break; \
+               codec_int = (switch_codec_interface_t *)switch_loadable_module_create_interface(*module_interface, SWITCH_CODEC_INTERFACE); \
+               codec_int->interface_name = switch_core_strdup(pool, int_name); \
+               codec_int->codec_id = switch_core_codec_next_id();                              \
+               break;                                                                                                                  \
        }
 
 
@@ -373,7 +376,7 @@ static inline void switch_core_codec_add_implementation(switch_memory_pool_t *po
                impl->encode = encode;
                impl->decode = decode;
                impl->destroy = destroy;
-               
+               impl->codec_id = codec_interface->codec_id;
                impl->next = codec_interface->implementations;
                codec_interface->implementations = impl;
        }
index 26a375467c813589c06fdf3fc50673492c32234c..2dc0e8c3b226bb7d5ee8042d02ee78766ffe28f6 100644 (file)
@@ -560,6 +560,7 @@ struct switch_codec_implementation {
     switch_core_codec_decode_func_t decode;
        /*! deinitalize a codec handle using this implementation */
     switch_core_codec_destroy_func_t destroy;
+       uint32_t codec_id;
        struct switch_codec_implementation *next;
 };
 
@@ -569,6 +570,7 @@ struct switch_codec_interface {
        const char *interface_name;
        /*! a list of codec implementations related to the codec */
        switch_codec_implementation_t *implementations;
+       uint32_t codec_id;
        struct switch_codec_interface *next;
 };
 
index 01f3fb3e0e43eb94dfeb4fe2c48f3145830bc09e..c7dbe59268ab304caf76a521a4e46a650f72c7cf 100644 (file)
 #include <switch.h>
 #include "private/switch_core_pvt.h"
 
+static uint32_t CODEC_ID = 0;
+
+SWITCH_DECLARE(uint32_t) switch_core_codec_next_id(void)
+{
+       return CODEC_ID++;
+}
+
+
 SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_session_t *session, switch_codec_t *codec)
 {
        switch_event_t *event;
index 06dfc5cc760cf945e6b551e8a87391d2419997b7..acce6ed66a3302d4fe5656f759eb618e3fe8bbf0 100644 (file)
@@ -323,7 +323,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
                }
 
                if (session->read_codec) {
-            
             if (session->read_resampler) {
                 short *data = read_frame->data;
                 switch_mutex_lock(session->resample_mutex);
@@ -353,6 +352,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
                                        goto done;
                                }
                        }
+                       
 
                        if (perfect || switch_buffer_inuse(session->raw_read_buffer) >= session->read_codec->implementation->bytes_per_frame) {
                                if (perfect) {
@@ -484,7 +484,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
 
        switch_status_t status = SWITCH_STATUS_FALSE;
        switch_frame_t *enc_frame = NULL, *write_frame = frame;
-       unsigned int flag = 0, need_codec = 0, perfect = 0, do_bugs = 0, do_write = 0, do_resample = 0;
+       unsigned int flag = 0, need_codec = 0, perfect = 0, do_bugs = 0, do_write = 0, do_resample = 0, ptime_mismatch = 0;
        switch_io_flag_t io_flag = SWITCH_IO_FLAG_NOOP;
 
        switch_assert(session != NULL);
@@ -514,6 +514,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
 
        if ((session->write_codec && frame->codec && session->write_codec->implementation != frame->codec->implementation)) {
                need_codec = TRUE;
+               if (session->write_codec->implementation->codec_id == frame->codec->implementation->codec_id) {
+                       ptime_mismatch = TRUE;
+               }
        }
 
        if (session->write_codec && !frame->codec) {
@@ -525,13 +528,13 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
        }
 
        if (session->bugs && !need_codec) {
-               do_bugs = 1;
-               need_codec = 1;
+               do_bugs = TRUE;
+               need_codec = TRUE;
        }
 
        if (frame->codec->implementation->actual_samples_per_second != session->write_codec->implementation->actual_samples_per_second) {
-               need_codec = 1;
-               do_resample = 1;
+               need_codec = TRUE;
+               do_resample = TRUE;
        }
 
        if (need_codec) {
@@ -671,7 +674,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
                }
 
                if (do_bugs) {
-                       do_write = 1;
+                       do_write = TRUE;
                        write_frame = frame;
                        goto done;
                }
@@ -768,7 +771,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
                                                        } else {
                                                                rate = session->write_codec->implementation->actual_samples_per_second;
                                                        } 
-
+                                                       
                                                        status = switch_core_codec_encode(session->write_codec,
                                                                                                                          frame->codec,
                                                                                                                          enc_frame->data,
@@ -776,7 +779,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
                                                                                                                          rate,
                                                                                                                          session->enc_write_frame.data,
                                                                                                                          &session->enc_write_frame.datalen, &session->enc_write_frame.rate, &flag);
-
                                                        switch (status) {
                                                        case SWITCH_STATUS_RESAMPLE:
                                                                session->enc_write_frame.codec = session->write_codec;
@@ -804,10 +806,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
                                                        case SWITCH_STATUS_SUCCESS:
                                                                session->enc_write_frame.codec = session->write_codec;
                                                                session->enc_write_frame.samples = enc_frame->datalen / sizeof(int16_t);
-                                                               session->enc_write_frame.timestamp = frame->timestamp;
+                                                               if (!ptime_mismatch) {
+                                                                       session->enc_write_frame.timestamp = frame->timestamp;
+                                                                       session->enc_write_frame.seq = frame->seq;
+                                                               }
                                                                session->enc_write_frame.m = frame->m;
                                                                session->enc_write_frame.ssrc = frame->ssrc;
-                                                               session->enc_write_frame.seq = frame->seq;
                                                                session->enc_write_frame.payload = session->write_codec->implementation->ianacode;
                                                                write_frame = &session->enc_write_frame;
                                                                break;
@@ -855,6 +859,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
                                                        if (flag & SFF_CNG) {
                                                                switch_set_flag(write_frame, SFF_CNG);
                                                        }
+
                                                        if ((status = perform_write(session, write_frame, timeout, io_flag, stream_id)) != SWITCH_STATUS_SUCCESS) {
                                                                break;
                                                        }
@@ -865,7 +870,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
                        }
                }
        } else {
-               do_write = 1;
+               do_write = TRUE;
        }
 
   done: