From 3812ebb958dcc7b9acc93e9b30aede5700f481d1 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Mon, 29 Oct 2012 15:07:50 -0500 Subject: [PATCH] let codecs see current frame via the codec obj --- src/include/switch_module_interfaces.h | 1 + src/switch_core_io.c | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/include/switch_module_interfaces.h b/src/include/switch_module_interfaces.h index deb96e4d47..d9fa1b2abf 100644 --- a/src/include/switch_module_interfaces.h +++ b/src/include/switch_module_interfaces.h @@ -618,6 +618,7 @@ struct switch_codec { switch_mutex_t *mutex; struct switch_codec *next; switch_core_session_t *session; + switch_frame_t *cur_frame; }; /*! \brief A table of settings and callbacks that define a paticular implementation of a codec */ diff --git a/src/switch_core_io.c b/src/switch_core_io.c index 7dbfdb2ac8..f175cf2e07 100644 --- a/src/switch_core_io.c +++ b/src/switch_core_io.c @@ -376,6 +376,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi switch_codec_t *codec = use_codec->implementation?use_codec:read_frame->codec; switch_thread_rwlock_rdlock(session->bug_rwlock); codec->session = session; + codec->cur_frame = read_frame; status = switch_core_codec_decode(codec, session->read_codec, read_frame->data, @@ -384,6 +385,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi session->raw_read_frame.data, &session->raw_read_frame.datalen, &session->raw_read_frame.rate, &read_frame->flags); codec->session = NULL; + codec->cur_frame = NULL; switch_thread_rwlock_unlock(session->bug_rwlock); } @@ -627,12 +629,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi switch_assert(enc_frame != NULL); switch_assert(enc_frame->data != NULL); session->read_codec->session = session; + session->read_codec->cur_frame = enc_frame; status = switch_core_codec_encode(session->read_codec, enc_frame->codec, enc_frame->data, enc_frame->datalen, session->read_impl.actual_samples_per_second, session->enc_read_frame.data, &session->enc_read_frame.datalen, &session->enc_read_frame.rate, &flag); + session->read_codec->cur_frame = NULL; session->read_codec->session = NULL; switch (status) { case SWITCH_STATUS_RESAMPLE: @@ -908,6 +912,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess if (frame->codec) { session->raw_write_frame.datalen = session->raw_write_frame.buflen; frame->codec->session = session; + frame->codec->cur_frame = frame; status = switch_core_codec_decode(frame->codec, session->write_codec, frame->data, @@ -915,6 +920,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess session->write_impl.actual_samples_per_second, session->raw_write_frame.data, &session->raw_write_frame.datalen, &session->raw_write_frame.rate, &frame->flags); frame->codec->session = NULL; + frame->codec->cur_frame = NULL; if (do_resample && status == SWITCH_STATUS_SUCCESS) { status = SWITCH_STATUS_RESAMPLE; @@ -1095,6 +1101,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess enc_frame = write_frame; session->enc_write_frame.datalen = session->enc_write_frame.buflen; session->write_codec->session = session; + session->write_codec->cur_frame = frame; status = switch_core_codec_encode(session->write_codec, frame->codec, enc_frame->data, @@ -1102,9 +1109,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess session->write_impl.actual_samples_per_second, session->enc_write_frame.data, &session->enc_write_frame.datalen, &session->enc_write_frame.rate, &flag); session->write_codec->session = NULL; - - - + session->write_codec->cur_frame = NULL; switch (status) { case SWITCH_STATUS_RESAMPLE: resample++; @@ -1199,6 +1204,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess rate = session->write_impl.actual_samples_per_second; } session->write_codec->session = session; + session->write_codec->cur_frame = frame; status = switch_core_codec_encode(session->write_codec, frame->codec, enc_frame->data, @@ -1206,6 +1212,7 @@ 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); session->write_codec->session = NULL; + session->write_codec->cur_frame = NULL; switch (status) { case SWITCH_STATUS_RESAMPLE: