FSCORE-288
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@11723 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
bc1e93bf5d
commit
6e80c32ae2
|
@ -85,8 +85,11 @@ SWITCH_BEGIN_EXTERN_C
|
|||
\param pool the memory pool to use for buffer allocation
|
||||
\return SWITCH_STATUS_SUCCESS if the handle was created
|
||||
*/
|
||||
SWITCH_DECLARE(switch_status_t) switch_resample_create(switch_audio_resampler_t **new_resampler,
|
||||
int from_rate, switch_size_t from_size, int to_rate, uint32_t to_size, switch_memory_pool_t *pool);
|
||||
SWITCH_DECLARE(switch_status_t) switch_resample_perform_create(switch_audio_resampler_t **new_resampler,
|
||||
int from_rate, switch_size_t from_size, int to_rate,
|
||||
uint32_t to_size, switch_memory_pool_t *pool, const char *file, const char *func, int line);
|
||||
|
||||
#define switch_resample_create(_n, _fr, _fs, _tr, _ts, _p) switch_resample_perform_create(_n, _fr, _fs, _tr, _ts, _p, __FILE__, __SWITCH_FUNC__, __LINE__)
|
||||
|
||||
/*!
|
||||
\brief Destroy an existing resampler handle
|
||||
|
|
|
@ -568,6 +568,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, ptime_mismatch = 0, pass_cng = 0, resample = 0;
|
||||
int did_write_resample = 0;
|
||||
|
||||
switch_assert(session != NULL);
|
||||
switch_assert(frame != NULL);
|
||||
|
@ -675,6 +676,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
|||
case SWITCH_STATUS_RESAMPLE:
|
||||
resample++;
|
||||
write_frame = &session->raw_write_frame;
|
||||
write_frame->rate = frame->codec->implementation->actual_samples_per_second;
|
||||
if (!session->write_resampler) {
|
||||
switch_mutex_lock(session->resample_mutex);
|
||||
status = switch_resample_create(&session->write_resampler,
|
||||
|
@ -729,7 +731,6 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
|||
short *data = write_frame->data;
|
||||
|
||||
switch_mutex_lock(session->resample_mutex);
|
||||
|
||||
session->write_resampler->from_len = write_frame->datalen / 2;
|
||||
switch_short_to_float(data, session->write_resampler->from, session->write_resampler->from_len);
|
||||
|
||||
|
@ -742,6 +743,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
|||
write_frame->samples = session->write_resampler->to_len;
|
||||
write_frame->datalen = write_frame->samples * 2;
|
||||
write_frame->rate = session->write_resampler->to_rate;
|
||||
did_write_resample = 1;
|
||||
switch_mutex_unlock(session->resample_mutex);
|
||||
}
|
||||
|
||||
|
@ -913,6 +915,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
|||
session->raw_write_frame.rate = session->write_impl.actual_samples_per_second;
|
||||
session->enc_write_frame.datalen = session->enc_write_frame.buflen;
|
||||
|
||||
|
||||
|
||||
if (frame->codec && frame->codec->implementation) {
|
||||
rate = frame->codec->implementation->actual_samples_per_second;
|
||||
} else {
|
||||
|
@ -925,7 +929,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
|||
enc_frame->datalen,
|
||||
rate,
|
||||
session->enc_write_frame.data,
|
||||
&session->enc_write_frame.datalen, &session->enc_write_frame.rate, &flag);
|
||||
&session->enc_write_frame.datalen,
|
||||
&session->enc_write_frame.rate, &flag);
|
||||
|
||||
|
||||
switch (status) {
|
||||
case SWITCH_STATUS_RESAMPLE:
|
||||
resample++;
|
||||
|
@ -983,7 +990,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
|||
goto error;
|
||||
}
|
||||
|
||||
if (session->read_resampler) {
|
||||
if (!did_write_resample && session->read_resampler) {
|
||||
short *data = write_frame->data;
|
||||
switch_mutex_lock(session->resample_mutex);
|
||||
|
||||
|
|
|
@ -556,7 +556,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
|
|||
switch_core_session_t *tsession;
|
||||
switch_status_t status = SWITCH_STATUS_FALSE;
|
||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||
switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
|
||||
int codec_initialized = 0;
|
||||
|
||||
if ((tsession = switch_core_session_locate(uuid))) {
|
||||
|
@ -566,10 +565,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
|
|||
switch_frame_t *read_frame, write_frame = { 0 };
|
||||
switch_codec_t codec = { 0 };
|
||||
int16_t buf[SWITCH_RECOMMENDED_BUFFER_SIZE / 2];
|
||||
switch_codec_t *tread_codec = switch_core_session_get_read_codec(tsession);
|
||||
uint32_t tlen;
|
||||
const char *macro_name = "eavesdrop_announce";
|
||||
const char *id_name = NULL;
|
||||
switch_codec_implementation_t tread_impl = {0}, read_impl = {0};
|
||||
|
||||
|
||||
if (!switch_channel_media_ready(channel)) {
|
||||
goto end;
|
||||
|
@ -579,6 +579,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
|
|||
goto end;
|
||||
}
|
||||
|
||||
switch_core_session_get_read_impl(tsession, &tread_impl);
|
||||
switch_core_session_get_read_impl(session, &read_impl);
|
||||
|
||||
if ((id_name = switch_channel_get_variable(tchannel, "eavesdrop_announce_id"))) {
|
||||
const char *tmp = switch_channel_get_variable(tchannel, "eavesdrop_annnounce_macro");
|
||||
if (tmp) {
|
||||
|
@ -622,16 +625,16 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
|
|||
|
||||
ep = switch_core_session_alloc(session, sizeof(*ep));
|
||||
|
||||
tlen = tread_codec->implementation->decoded_bytes_per_packet;
|
||||
tlen = tread_impl.decoded_bytes_per_packet;
|
||||
|
||||
switch_channel_pre_answer(channel);
|
||||
|
||||
if (switch_core_codec_init(&codec,
|
||||
"L16",
|
||||
NULL,
|
||||
tread_codec->implementation->actual_samples_per_second,
|
||||
tread_codec->implementation->microseconds_per_packet / 1000,
|
||||
tread_codec->implementation->number_of_channels,
|
||||
tread_impl.actual_samples_per_second,
|
||||
tread_impl.microseconds_per_packet / 1000,
|
||||
tread_impl.number_of_channels,
|
||||
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
|
||||
NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot init codec\n");
|
||||
|
@ -645,7 +648,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
|
|||
write_frame.codec = &codec;
|
||||
write_frame.data = buf;
|
||||
write_frame.buflen = sizeof(buf);
|
||||
write_frame.rate = read_codec->implementation->actual_samples_per_second;
|
||||
write_frame.rate = codec.implementation->actual_samples_per_second;
|
||||
|
||||
ep->flags = flags;
|
||||
switch_mutex_init(&ep->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(tsession));
|
||||
|
@ -760,6 +763,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_eavesdrop_session(switch_core_session
|
|||
while (switch_buffer_inuse(ep->buffer) >= len) {
|
||||
write_frame.datalen = (uint32_t) switch_buffer_read(ep->buffer, buf, len);
|
||||
write_frame.samples = write_frame.datalen / 2;
|
||||
|
||||
if ((status = switch_core_session_write_frame(session, &write_frame, SWITCH_IO_FLAG_NONE, 0)) != SWITCH_STATUS_SUCCESS) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -53,8 +53,9 @@
|
|||
|
||||
#define resample_buffer(a, b, c) a > b ? ((a / 1000) / 2) * c : ((b / 1000) / 2) * c
|
||||
|
||||
SWITCH_DECLARE(switch_status_t) switch_resample_create(switch_audio_resampler_t **new_resampler,
|
||||
int from_rate, switch_size_t from_size, int to_rate, uint32_t to_size, switch_memory_pool_t *pool)
|
||||
SWITCH_DECLARE(switch_status_t) switch_resample_perform_create(switch_audio_resampler_t **new_resampler,
|
||||
int from_rate, switch_size_t from_size, int to_rate,
|
||||
uint32_t to_size, switch_memory_pool_t *pool, const char *file, const char *func, int line)
|
||||
{
|
||||
#ifdef DISABLE_RESAMPLE
|
||||
*new_resampler = NULL;
|
||||
|
@ -75,8 +76,8 @@ SWITCH_DECLARE(switch_status_t) switch_resample_create(switch_audio_resampler_t
|
|||
resampler->rfactor = (lfrom_rate / lto_rate);
|
||||
|
||||
resampler->resampler = resample_open(QUALITY, resampler->factor, resampler->factor);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Activate Resampler %d->%d %f\n", resampler->from_rate, resampler->to_rate,
|
||||
resampler->factor);
|
||||
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_NOTICE,
|
||||
"Activate Resampler %d->%d %f\n", resampler->from_rate, resampler->to_rate, resampler->factor);
|
||||
resampler->from_size = resample_buffer(to_rate, from_rate, (uint32_t) from_size);
|
||||
resampler->from = (float *) switch_core_alloc(pool, resampler->from_size * sizeof(float));
|
||||
resampler->to_size = resample_buffer(to_rate, from_rate, (uint32_t) to_size);;
|
||||
|
|
Loading…
Reference in New Issue