FSCORE-403
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14331 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
14c5052db5
commit
0573d3cf09
|
@ -80,10 +80,11 @@ typedef struct {
|
||||||
SWITCH_DECLARE(switch_status_t) switch_resample_perform_create(switch_audio_resampler_t **new_resampler,
|
SWITCH_DECLARE(switch_status_t) switch_resample_perform_create(switch_audio_resampler_t **new_resampler,
|
||||||
uint32_t from_rate, uint32_t to_rate, uint32_t to_size,
|
uint32_t from_rate, uint32_t to_rate, uint32_t to_size,
|
||||||
int quality,
|
int quality,
|
||||||
|
uint32_t channels,
|
||||||
const char *file, const char *func, int line);
|
const char *file, const char *func, int line);
|
||||||
|
|
||||||
|
|
||||||
#define switch_resample_create(_n, _fr, _tr, _ts, _q) switch_resample_perform_create(_n, _fr, _tr, _ts, _q, __FILE__, __SWITCH_FUNC__, __LINE__)
|
#define switch_resample_create(_n, _fr, _tr, _ts, _q, _c) switch_resample_perform_create(_n, _fr, _tr, _ts, _q, _c, __FILE__, __SWITCH_FUNC__, __LINE__)
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Destroy an existing resampler handle
|
\brief Destroy an existing resampler handle
|
||||||
|
|
|
@ -4795,7 +4795,7 @@ static int setup_media(conference_member_t *member, conference_obj_t *conference
|
||||||
if (read_impl.actual_samples_per_second != conference->rate) {
|
if (read_impl.actual_samples_per_second != conference->rate) {
|
||||||
if (switch_resample_create(&member->read_resampler,
|
if (switch_resample_create(&member->read_resampler,
|
||||||
read_impl.actual_samples_per_second,
|
read_impl.actual_samples_per_second,
|
||||||
conference->rate, member->frame_size, SWITCH_RESAMPLE_QUALITY) != SWITCH_STATUS_SUCCESS) {
|
conference->rate, member->frame_size, SWITCH_RESAMPLE_QUALITY, 1) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
|
@ -123,6 +123,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (fh->pre_buffer_datalen) {
|
||||||
|
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Prebuffering %d bytes\n", (int)fh->pre_buffer_datalen);
|
||||||
|
switch_buffer_create_dynamic(&fh->pre_buffer, fh->pre_buffer_datalen * fh->channels, fh->pre_buffer_datalen * fh->channels / 2, 0);
|
||||||
|
fh->pre_buffer_data = switch_core_alloc(fh->memory_pool, fh->pre_buffer_datalen * fh->channels);
|
||||||
|
}
|
||||||
|
|
||||||
if (fh->channels > 1 && (flags & SWITCH_FILE_FLAG_READ)) {
|
if (fh->channels > 1 && (flags & SWITCH_FILE_FLAG_READ)) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "File has %d channels, muxing to mono will occur.\n", fh->channels);
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "File has %d channels, muxing to mono will occur.\n", fh->channels);
|
||||||
}
|
}
|
||||||
|
@ -212,7 +218,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_read(switch_file_handle_t *fh,
|
||||||
if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->native_rate != fh->samplerate) {
|
if (!switch_test_flag(fh, SWITCH_FILE_NATIVE) && fh->native_rate != fh->samplerate) {
|
||||||
if (!fh->resampler) {
|
if (!fh->resampler) {
|
||||||
if (switch_resample_create(&fh->resampler,
|
if (switch_resample_create(&fh->resampler,
|
||||||
fh->native_rate, fh->samplerate, (uint32_t) orig_len, SWITCH_RESAMPLE_QUALITY) != SWITCH_STATUS_SUCCESS) {
|
fh->native_rate, fh->samplerate, (uint32_t) orig_len, SWITCH_RESAMPLE_QUALITY, 1) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
|
||||||
return SWITCH_STATUS_GENERR;
|
return SWITCH_STATUS_GENERR;
|
||||||
}
|
}
|
||||||
|
@ -273,31 +279,31 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
|
||||||
if (switch_resample_create(&fh->resampler,
|
if (switch_resample_create(&fh->resampler,
|
||||||
fh->native_rate,
|
fh->native_rate,
|
||||||
fh->samplerate,
|
fh->samplerate,
|
||||||
(uint32_t) orig_len *fh->channels,
|
(uint32_t) orig_len * 2 * fh->channels,
|
||||||
SWITCH_RESAMPLE_QUALITY) != SWITCH_STATUS_SUCCESS) {
|
SWITCH_RESAMPLE_QUALITY, fh->channels) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
|
||||||
return SWITCH_STATUS_GENERR;
|
return SWITCH_STATUS_GENERR;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
switch_resample_process(fh->resampler, data, (uint32_t)(*len * fh->channels));
|
|
||||||
|
|
||||||
if (fh->resampler->to_len > orig_len * fh->channels) {
|
switch_resample_process(fh->resampler, data, (uint32_t)*len);
|
||||||
|
|
||||||
|
if (fh->resampler->to_len > orig_len) {
|
||||||
if (!fh->dbuf) {
|
if (!fh->dbuf) {
|
||||||
void *mem;
|
void *mem;
|
||||||
fh->dbuflen = fh->resampler->to_len * 2;
|
fh->dbuflen = fh->resampler->to_len * 2 * fh->channels;
|
||||||
mem = realloc(fh->dbuf, fh->dbuflen);
|
mem = realloc(fh->dbuf, fh->dbuflen);
|
||||||
switch_assert(mem);
|
switch_assert(mem);
|
||||||
fh->dbuf = mem;
|
fh->dbuf = mem;
|
||||||
}
|
}
|
||||||
switch_assert(fh->resampler->to_len * 2 <= fh->dbuflen);
|
switch_assert(fh->resampler->to_len * 2 <= fh->dbuflen);
|
||||||
memcpy(fh->dbuf, fh->resampler->to, fh->resampler->to_len * 2);
|
memcpy(fh->dbuf, fh->resampler->to, fh->resampler->to_len * 2 * fh->channels);
|
||||||
data = fh->dbuf;
|
data = fh->dbuf;
|
||||||
} else {
|
} else {
|
||||||
memcpy(data, fh->resampler->to, fh->resampler->to_len * 2);
|
memcpy(data, fh->resampler->to, fh->resampler->to_len * 2 * fh->channels);
|
||||||
}
|
}
|
||||||
|
|
||||||
*len = fh->resampler->to_len / fh->channels;
|
*len = fh->resampler->to_len;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!*len) {
|
if (!*len) {
|
||||||
|
@ -316,7 +322,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
|
||||||
if (rlen >= fh->pre_buffer_datalen) {
|
if (rlen >= fh->pre_buffer_datalen) {
|
||||||
if ((blen = switch_buffer_read(fh->pre_buffer, fh->pre_buffer_data, fh->pre_buffer_datalen))) {
|
if ((blen = switch_buffer_read(fh->pre_buffer, fh->pre_buffer_data, fh->pre_buffer_datalen))) {
|
||||||
if (!asis) blen /= 2;
|
if (!asis) blen /= 2;
|
||||||
if (fh->channels) blen /= fh->channels;
|
if (fh->channels > 1) blen /= fh->channels;
|
||||||
if ((status = fh->file_interface->file_write(fh, fh->pre_buffer_data, &blen)) != SWITCH_STATUS_SUCCESS) {
|
if ((status = fh->file_interface->file_write(fh, fh->pre_buffer_data, &blen)) != SWITCH_STATUS_SUCCESS) {
|
||||||
*len = 0;
|
*len = 0;
|
||||||
}
|
}
|
||||||
|
@ -427,7 +433,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_close(switch_file_handle_t *fh)
|
||||||
while((rlen = switch_buffer_inuse(fh->pre_buffer))) {
|
while((rlen = switch_buffer_inuse(fh->pre_buffer))) {
|
||||||
if ((blen = switch_buffer_read(fh->pre_buffer, fh->pre_buffer_data, fh->pre_buffer_datalen))) {
|
if ((blen = switch_buffer_read(fh->pre_buffer, fh->pre_buffer_data, fh->pre_buffer_datalen))) {
|
||||||
if (!asis) blen /= 2;
|
if (!asis) blen /= 2;
|
||||||
if (fh->channels) blen /= fh->channels;
|
if (fh->channels > 1) blen /= fh->channels;
|
||||||
if (fh->file_interface->file_write(fh, fh->pre_buffer_data, &blen) != SWITCH_STATUS_SUCCESS) {
|
if (fh->file_interface->file_write(fh, fh->pre_buffer_data, &blen) != SWITCH_STATUS_SUCCESS) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -271,7 +271,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
|
||||||
read_frame->codec->implementation->actual_samples_per_second,
|
read_frame->codec->implementation->actual_samples_per_second,
|
||||||
session->read_impl.actual_samples_per_second,
|
session->read_impl.actual_samples_per_second,
|
||||||
session->read_impl.decoded_bytes_per_packet,
|
session->read_impl.decoded_bytes_per_packet,
|
||||||
SWITCH_RESAMPLE_QUALITY);
|
SWITCH_RESAMPLE_QUALITY, 1);
|
||||||
|
|
||||||
switch_mutex_unlock(session->resample_mutex);
|
switch_mutex_unlock(session->resample_mutex);
|
||||||
|
|
||||||
|
@ -677,7 +677,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
||||||
frame->codec->implementation->actual_samples_per_second,
|
frame->codec->implementation->actual_samples_per_second,
|
||||||
session->write_impl.actual_samples_per_second,
|
session->write_impl.actual_samples_per_second,
|
||||||
session->write_impl.decoded_bytes_per_packet,
|
session->write_impl.decoded_bytes_per_packet,
|
||||||
SWITCH_RESAMPLE_QUALITY);
|
SWITCH_RESAMPLE_QUALITY, 1);
|
||||||
|
|
||||||
|
|
||||||
switch_mutex_unlock(session->resample_mutex);
|
switch_mutex_unlock(session->resample_mutex);
|
||||||
|
@ -961,7 +961,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
||||||
frame->codec->implementation->actual_samples_per_second,
|
frame->codec->implementation->actual_samples_per_second,
|
||||||
session->write_impl.actual_samples_per_second,
|
session->write_impl.actual_samples_per_second,
|
||||||
session->write_impl.decoded_bytes_per_packet,
|
session->write_impl.decoded_bytes_per_packet,
|
||||||
SWITCH_RESAMPLE_QUALITY);
|
SWITCH_RESAMPLE_QUALITY, 1);
|
||||||
}
|
}
|
||||||
switch_mutex_unlock(session->resample_mutex);
|
switch_mutex_unlock(session->resample_mutex);
|
||||||
|
|
||||||
|
|
|
@ -227,7 +227,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_speech_read_tts(switch_speech_handle
|
||||||
if (sh->native_rate && sh->samplerate && sh->native_rate != sh->samplerate) {
|
if (sh->native_rate && sh->samplerate && sh->native_rate != sh->samplerate) {
|
||||||
if (!sh->resampler) {
|
if (!sh->resampler) {
|
||||||
if (switch_resample_create(&sh->resampler,
|
if (switch_resample_create(&sh->resampler,
|
||||||
sh->native_rate, sh->samplerate, (uint32_t) orig_len, SWITCH_RESAMPLE_QUALITY) != SWITCH_STATUS_SUCCESS) {
|
sh->native_rate, sh->samplerate, (uint32_t) orig_len, SWITCH_RESAMPLE_QUALITY, 1) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Unable to create resampler!\n");
|
||||||
return SWITCH_STATUS_GENERR;
|
return SWITCH_STATUS_GENERR;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ SWITCH_DECLARE(switch_status_t) switch_resample_perform_create(switch_audio_resa
|
||||||
uint32_t from_rate, uint32_t to_rate,
|
uint32_t from_rate, uint32_t to_rate,
|
||||||
uint32_t to_size,
|
uint32_t to_size,
|
||||||
int quality,
|
int quality,
|
||||||
|
uint32_t channels,
|
||||||
const char *file, const char *func, int line)
|
const char *file, const char *func, int line)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
@ -64,7 +65,7 @@ SWITCH_DECLARE(switch_status_t) switch_resample_perform_create(switch_audio_resa
|
||||||
|
|
||||||
switch_zmalloc(resampler, sizeof(*resampler));
|
switch_zmalloc(resampler, sizeof(*resampler));
|
||||||
|
|
||||||
resampler->resampler = speex_resampler_init(1, from_rate, to_rate, quality, &err);
|
resampler->resampler = speex_resampler_init(channels ? channels : 1, from_rate, to_rate, quality, &err);
|
||||||
|
|
||||||
if (!resampler->resampler) {
|
if (!resampler->resampler) {
|
||||||
free(resampler);
|
free(resampler);
|
||||||
|
@ -88,7 +89,7 @@ SWITCH_DECLARE(switch_status_t) switch_resample_perform_create(switch_audio_resa
|
||||||
SWITCH_DECLARE(uint32_t) switch_resample_process(switch_audio_resampler_t *resampler, int16_t *src, uint32_t srclen)
|
SWITCH_DECLARE(uint32_t) switch_resample_process(switch_audio_resampler_t *resampler, int16_t *src, uint32_t srclen)
|
||||||
{
|
{
|
||||||
resampler->to_len = resampler->to_size;
|
resampler->to_len = resampler->to_size;
|
||||||
speex_resampler_process_int(resampler->resampler, 0, src, &srclen, resampler->to, &resampler->to_len);
|
speex_resampler_process_interleaved_int(resampler->resampler, src, &srclen, resampler->to, &resampler->to_len);
|
||||||
return resampler->to_len;
|
return resampler->to_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue