From 8592c5d822079d76b3af4ac3ea83a32771f8dbb6 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Thu, 27 Mar 2008 22:22:46 +0000 Subject: [PATCH] fix some stuff git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7973 d0543943-73ff-0310-b7d9-9358b9ac24b2 --- src/include/switch_loadable_module.h | 11 ++++++---- src/include/switch_module_interfaces.h | 2 ++ src/switch_core_codec.c | 8 +++++++ src/switch_core_io.c | 29 +++++++++++++++----------- 4 files changed, 34 insertions(+), 16 deletions(-) diff --git a/src/include/switch_loadable_module.h b/src/include/switch_loadable_module.h index 19514d7fb3..07903e933a 100644 --- a/src/include/switch_loadable_module.h +++ b/src/include/switch_loadable_module.h @@ -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; } diff --git a/src/include/switch_module_interfaces.h b/src/include/switch_module_interfaces.h index 26a375467c..2dc0e8c3b2 100644 --- a/src/include/switch_module_interfaces.h +++ b/src/include/switch_module_interfaces.h @@ -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; }; diff --git a/src/switch_core_codec.c b/src/switch_core_codec.c index 01f3fb3e0e..c7dbe59268 100644 --- a/src/switch_core_codec.c +++ b/src/switch_core_codec.c @@ -35,6 +35,14 @@ #include #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; diff --git a/src/switch_core_io.c b/src/switch_core_io.c index 06dfc5cc76..acce6ed66a 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -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: