forked from Mirrors/freeswitch
add lock
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@7079 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
021ab87f2b
commit
c4832b4b40
@ -196,6 +196,7 @@
|
||||
-->
|
||||
<extension name="unpark">
|
||||
<condition field="destination_number" expression="^5901$">
|
||||
<action application="answer"/>
|
||||
<action application="fifo" data="5900@$${domain} out nowait"/>
|
||||
</condition>
|
||||
</extension>
|
||||
@ -209,7 +210,7 @@
|
||||
-->
|
||||
<extension name="park">
|
||||
<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}"/>
|
||||
</condition>
|
||||
</extension>
|
||||
@ -222,7 +223,7 @@
|
||||
<condition field="destination_number" expression="^parking$" continue="on-true"/>
|
||||
<condition field="${sip_to_params}" expression="fifo\=(\d+)">
|
||||
<action application="answer"/>
|
||||
<action application="fifo" data="$1@$${domain} out undef"/>
|
||||
<action application="fifo" data="$1@$${domain} out nowait"/>
|
||||
</condition>
|
||||
</extension>
|
||||
|
||||
|
@ -119,6 +119,7 @@ struct switch_core_session {
|
||||
switch_audio_resampler_t *write_resampler;
|
||||
|
||||
switch_mutex_t *mutex;
|
||||
switch_mutex_t *resample_mutex;
|
||||
switch_thread_cond_t *cond;
|
||||
|
||||
switch_thread_rwlock_t *rwlock;
|
||||
|
@ -191,11 +191,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
|
||||
switch (status) {
|
||||
case SWITCH_STATUS_RESAMPLE:
|
||||
if (!session->read_resampler) {
|
||||
if (switch_resample_create(&session->read_resampler,
|
||||
read_frame->codec->implementation->actual_samples_per_second,
|
||||
read_frame->codec->implementation->bytes_per_frame * 20,
|
||||
session->read_codec->implementation->actual_samples_per_second,
|
||||
session->read_codec->implementation->bytes_per_frame * 20, session->pool) != SWITCH_STATUS_SUCCESS) {
|
||||
switch_mutex_lock(session->resample_mutex);
|
||||
status = switch_resample_create(&session->read_resampler,
|
||||
read_frame->codec->implementation->actual_samples_per_second,
|
||||
read_frame->codec->implementation->bytes_per_frame * 20,
|
||||
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");
|
||||
status = SWITCH_STATUS_FALSE;
|
||||
goto done;
|
||||
@ -213,8 +217,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
|
||||
break;
|
||||
case SWITCH_STATUS_NOOP:
|
||||
if (session->read_resampler) {
|
||||
switch_mutex_lock(session->resample_mutex);
|
||||
switch_resample_destroy(&session->read_resampler);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deactivating read resampler\n");
|
||||
switch_mutex_unlock(session->resample_mutex);
|
||||
}
|
||||
|
||||
status = SWITCH_STATUS_SUCCESS;
|
||||
@ -240,6 +246,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
|
||||
#if 0
|
||||
if (session->read_resampler) {
|
||||
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->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->datalen = session->read_resampler->to_len * 2;
|
||||
read_frame->rate = session->read_resampler->to_rate;
|
||||
switch_mutex_unlock(session->resample_mutex);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -514,11 +523,13 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
||||
case SWITCH_STATUS_RESAMPLE:
|
||||
write_frame = &session->raw_write_frame;
|
||||
if (!session->write_resampler) {
|
||||
switch_mutex_lock(session->resample_mutex);
|
||||
status = switch_resample_create(&session->write_resampler,
|
||||
frame->codec->implementation->actual_samples_per_second,
|
||||
frame->codec->implementation->bytes_per_frame * 20,
|
||||
session->write_codec->implementation->actual_samples_per_second,
|
||||
session->write_codec->implementation->bytes_per_frame * 20, session->pool);
|
||||
switch_mutex_unlock(session->resample_mutex);
|
||||
if (status != SWITCH_STATUS_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
@ -538,8 +549,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
case SWITCH_STATUS_NOOP:
|
||||
if (session->write_resampler) {
|
||||
switch_mutex_lock(session->resample_mutex);
|
||||
switch_resample_destroy(&session->write_resampler);
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Deactivating write resampler\n");
|
||||
switch_mutex_unlock(session->resample_mutex);
|
||||
}
|
||||
write_frame = frame;
|
||||
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) {
|
||||
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);
|
||||
@ -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->datalen = write_frame->samples * 2;
|
||||
write_frame->rate = session->write_resampler->to_rate;
|
||||
switch_mutex_unlock(session->resample_mutex);
|
||||
}
|
||||
|
||||
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;
|
||||
write_frame = &session->enc_write_frame;
|
||||
if (!session->read_resampler) {
|
||||
switch_mutex_lock(session->resample_mutex);
|
||||
status = switch_resample_create(&session->read_resampler,
|
||||
frame->codec->implementation->actual_samples_per_second,
|
||||
frame->codec->implementation->bytes_per_frame * 20,
|
||||
session->write_codec->implementation->actual_samples_per_second,
|
||||
session->write_codec->implementation->bytes_per_frame * 20, session->pool);
|
||||
switch_mutex_unlock(session->resample_mutex);
|
||||
|
||||
if (status != SWITCH_STATUS_SUCCESS) {
|
||||
goto done;
|
||||
}
|
||||
@ -766,8 +785,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
||||
break;
|
||||
case SWITCH_STATUS_NOOP:
|
||||
if (session->read_resampler) {
|
||||
switch_mutex_lock(session->resample_mutex);
|
||||
switch_resample_destroy(&session->read_resampler);
|
||||
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->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) {
|
||||
short *data = write_frame->data;
|
||||
|
||||
switch_mutex_lock(session->resample_mutex);
|
||||
|
||||
session->read_resampler->from_len =
|
||||
switch_short_to_float(data, session->read_resampler->from, (int) write_frame->datalen / 2);
|
||||
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->datalen = session->read_resampler->to_len * 2;
|
||||
write_frame->rate = session->read_resampler->to_rate;
|
||||
switch_mutex_unlock(session->resample_mutex);
|
||||
|
||||
}
|
||||
if (flag & SFF_CNG) {
|
||||
switch_set_flag(write_frame, SFF_CNG);
|
||||
|
@ -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);
|
||||
|
||||
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_cond_create(&session->cond, session->pool);
|
||||
switch_thread_rwlock_create(&session->rwlock, session->pool);
|
||||
|
Loading…
Reference in New Issue
Block a user