git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7079 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2008-01-04 00:19:09 +00:00
parent 021ab87f2b
commit c4832b4b40
4 changed files with 35 additions and 8 deletions

View File

@ -196,6 +196,7 @@
--> -->
<extension name="unpark"> <extension name="unpark">
<condition field="destination_number" expression="^5901$"> <condition field="destination_number" expression="^5901$">
<action application="answer"/>
<action application="fifo" data="5900@$${domain} out nowait"/> <action application="fifo" data="5900@$${domain} out nowait"/>
</condition> </condition>
</extension> </extension>
@ -209,7 +210,7 @@
--> -->
<extension name="park"> <extension name="park">
<condition field="source" expression="mod_sofia" continue="on-true"/> <condition field="source" expression="mod_sofia" continue="on-true"/>
<condition field="${sip_refer_to}" expression="park\+(.*)@(.*)>" continue="on-true"> <condition field="destination_number" expression="park\+(\d+)" continue="on-true">
<action application="fifo" data="$1@$${domain} in undef $${moh_uri}"/> <action application="fifo" data="$1@$${domain} in undef $${moh_uri}"/>
</condition> </condition>
</extension> </extension>
@ -222,7 +223,7 @@
<condition field="destination_number" expression="^parking$" continue="on-true"/> <condition field="destination_number" expression="^parking$" continue="on-true"/>
<condition field="${sip_to_params}" expression="fifo\=(\d+)"> <condition field="${sip_to_params}" expression="fifo\=(\d+)">
<action application="answer"/> <action application="answer"/>
<action application="fifo" data="$1@$${domain} out undef"/> <action application="fifo" data="$1@$${domain} out nowait"/>
</condition> </condition>
</extension> </extension>

View File

@ -119,6 +119,7 @@ struct switch_core_session {
switch_audio_resampler_t *write_resampler; switch_audio_resampler_t *write_resampler;
switch_mutex_t *mutex; switch_mutex_t *mutex;
switch_mutex_t *resample_mutex;
switch_thread_cond_t *cond; switch_thread_cond_t *cond;
switch_thread_rwlock_t *rwlock; switch_thread_rwlock_t *rwlock;

View File

@ -191,11 +191,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
switch (status) { switch (status) {
case SWITCH_STATUS_RESAMPLE: case SWITCH_STATUS_RESAMPLE:
if (!session->read_resampler) { if (!session->read_resampler) {
if (switch_resample_create(&session->read_resampler, switch_mutex_lock(session->resample_mutex);
read_frame->codec->implementation->actual_samples_per_second, status = switch_resample_create(&session->read_resampler,
read_frame->codec->implementation->bytes_per_frame * 20, read_frame->codec->implementation->actual_samples_per_second,
session->read_codec->implementation->actual_samples_per_second, read_frame->codec->implementation->bytes_per_frame * 20,
session->read_codec->implementation->bytes_per_frame * 20, session->pool) != SWITCH_STATUS_SUCCESS) { session->read_codec->implementation->actual_samples_per_second,
session->read_codec->implementation->bytes_per_frame * 20, session->pool);
switch_mutex_unlock(session->resample_mutex);
if (status != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to allocate resampler\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Unable to allocate resampler\n");
status = SWITCH_STATUS_FALSE; status = SWITCH_STATUS_FALSE;
goto done; goto done;
@ -213,8 +217,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
break; break;
case SWITCH_STATUS_NOOP: case SWITCH_STATUS_NOOP:
if (session->read_resampler) { if (session->read_resampler) {
switch_mutex_lock(session->resample_mutex);
switch_resample_destroy(&session->read_resampler); switch_resample_destroy(&session->read_resampler);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deactivating read resampler\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deactivating read resampler\n");
switch_mutex_unlock(session->resample_mutex);
} }
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
@ -240,6 +246,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
#if 0 #if 0
if (session->read_resampler) { if (session->read_resampler) {
short *data = read_frame->data; short *data = read_frame->data;
switch_mutex_lock(session->resample_mutex);
session->read_resampler->from_len = switch_short_to_float(data, session->read_resampler->from, (int) read_frame->datalen / 2); session->read_resampler->from_len = switch_short_to_float(data, session->read_resampler->from, (int) read_frame->datalen / 2);
session->read_resampler->to_len = session->read_resampler->to_len =
@ -249,6 +256,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
read_frame->samples = session->read_resampler->to_len; read_frame->samples = session->read_resampler->to_len;
read_frame->datalen = session->read_resampler->to_len * 2; read_frame->datalen = session->read_resampler->to_len * 2;
read_frame->rate = session->read_resampler->to_rate; read_frame->rate = session->read_resampler->to_rate;
switch_mutex_unlock(session->resample_mutex);
} }
#endif #endif
@ -514,11 +523,13 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
case SWITCH_STATUS_RESAMPLE: case SWITCH_STATUS_RESAMPLE:
write_frame = &session->raw_write_frame; write_frame = &session->raw_write_frame;
if (!session->write_resampler) { if (!session->write_resampler) {
switch_mutex_lock(session->resample_mutex);
status = switch_resample_create(&session->write_resampler, status = switch_resample_create(&session->write_resampler,
frame->codec->implementation->actual_samples_per_second, frame->codec->implementation->actual_samples_per_second,
frame->codec->implementation->bytes_per_frame * 20, frame->codec->implementation->bytes_per_frame * 20,
session->write_codec->implementation->actual_samples_per_second, session->write_codec->implementation->actual_samples_per_second,
session->write_codec->implementation->bytes_per_frame * 20, session->pool); session->write_codec->implementation->bytes_per_frame * 20, session->pool);
switch_mutex_unlock(session->resample_mutex);
if (status != SWITCH_STATUS_SUCCESS) { if (status != SWITCH_STATUS_SUCCESS) {
goto done; goto done;
} }
@ -538,8 +549,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
return SWITCH_STATUS_SUCCESS; return SWITCH_STATUS_SUCCESS;
case SWITCH_STATUS_NOOP: case SWITCH_STATUS_NOOP:
if (session->write_resampler) { if (session->write_resampler) {
switch_mutex_lock(session->resample_mutex);
switch_resample_destroy(&session->write_resampler); switch_resample_destroy(&session->write_resampler);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deactivating write resampler\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deactivating write resampler\n");
switch_mutex_unlock(session->resample_mutex);
} }
write_frame = frame; write_frame = frame;
status = SWITCH_STATUS_SUCCESS; status = SWITCH_STATUS_SUCCESS;
@ -552,6 +565,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
if (session->write_resampler) { if (session->write_resampler) {
short *data = write_frame->data; short *data = write_frame->data;
switch_mutex_lock(session->resample_mutex);
session->write_resampler->from_len = write_frame->datalen / 2; session->write_resampler->from_len = write_frame->datalen / 2;
switch_short_to_float(data, session->write_resampler->from, session->write_resampler->from_len); switch_short_to_float(data, session->write_resampler->from, session->write_resampler->from_len);
@ -568,6 +583,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
write_frame->samples = session->write_resampler->to_len; write_frame->samples = session->write_resampler->to_len;
write_frame->datalen = write_frame->samples * 2; write_frame->datalen = write_frame->samples * 2;
write_frame->rate = session->write_resampler->to_rate; write_frame->rate = session->write_resampler->to_rate;
switch_mutex_unlock(session->resample_mutex);
} }
if (session->bugs) { if (session->bugs) {
@ -744,11 +760,14 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
session->enc_write_frame.payload = session->write_codec->implementation->ianacode; session->enc_write_frame.payload = session->write_codec->implementation->ianacode;
write_frame = &session->enc_write_frame; write_frame = &session->enc_write_frame;
if (!session->read_resampler) { if (!session->read_resampler) {
switch_mutex_lock(session->resample_mutex);
status = switch_resample_create(&session->read_resampler, status = switch_resample_create(&session->read_resampler,
frame->codec->implementation->actual_samples_per_second, frame->codec->implementation->actual_samples_per_second,
frame->codec->implementation->bytes_per_frame * 20, frame->codec->implementation->bytes_per_frame * 20,
session->write_codec->implementation->actual_samples_per_second, session->write_codec->implementation->actual_samples_per_second,
session->write_codec->implementation->bytes_per_frame * 20, session->pool); session->write_codec->implementation->bytes_per_frame * 20, session->pool);
switch_mutex_unlock(session->resample_mutex);
if (status != SWITCH_STATUS_SUCCESS) { if (status != SWITCH_STATUS_SUCCESS) {
goto done; goto done;
} }
@ -766,8 +785,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
break; break;
case SWITCH_STATUS_NOOP: case SWITCH_STATUS_NOOP:
if (session->read_resampler) { if (session->read_resampler) {
switch_mutex_lock(session->resample_mutex);
switch_resample_destroy(&session->read_resampler); switch_resample_destroy(&session->read_resampler);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deactivating read resampler\n"); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deactivating read resampler\n");
switch_mutex_unlock(session->resample_mutex);
} }
enc_frame->codec = session->write_codec; enc_frame->codec = session->write_codec;
enc_frame->samples = enc_frame->datalen / sizeof(int16_t); enc_frame->samples = enc_frame->datalen / sizeof(int16_t);
@ -788,7 +809,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
if (session->read_resampler) { if (session->read_resampler) {
short *data = write_frame->data; short *data = write_frame->data;
switch_mutex_lock(session->resample_mutex);
session->read_resampler->from_len = session->read_resampler->from_len =
switch_short_to_float(data, session->read_resampler->from, (int) write_frame->datalen / 2); switch_short_to_float(data, session->read_resampler->from, (int) write_frame->datalen / 2);
session->read_resampler->to_len = (uint32_t) session->read_resampler->to_len = (uint32_t)
@ -799,6 +821,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
write_frame->samples = session->read_resampler->to_len; write_frame->samples = session->read_resampler->to_len;
write_frame->datalen = session->read_resampler->to_len * 2; write_frame->datalen = session->read_resampler->to_len * 2;
write_frame->rate = session->read_resampler->to_rate; write_frame->rate = session->read_resampler->to_rate;
switch_mutex_unlock(session->resample_mutex);
} }
if (flag & SFF_CNG) { if (flag & SFF_CNG) {
switch_set_flag(write_frame, SFF_CNG); switch_set_flag(write_frame, SFF_CNG);

View File

@ -813,6 +813,7 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request(const switch
session->enc_read_frame.buflen = sizeof(session->enc_read_buf); session->enc_read_frame.buflen = sizeof(session->enc_read_buf);
switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED, session->pool); switch_mutex_init(&session->mutex, SWITCH_MUTEX_NESTED, session->pool);
switch_mutex_init(&session->resample_mutex, SWITCH_MUTEX_NESTED, session->pool);
switch_thread_rwlock_create(&session->bug_rwlock, session->pool); switch_thread_rwlock_create(&session->bug_rwlock, session->pool);
switch_thread_cond_create(&session->cond, session->pool); switch_thread_cond_create(&session->cond, session->pool);
switch_thread_rwlock_create(&session->rwlock, session->pool); switch_thread_rwlock_create(&session->rwlock, session->pool);