提交 86c523fb authored 作者: Anthony Minessale's avatar Anthony Minessale

code reworking do make current

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10487 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 7ca32bb9
...@@ -118,6 +118,8 @@ struct switch_core_session { ...@@ -118,6 +118,8 @@ struct switch_core_session {
switch_mutex_t *mutex; switch_mutex_t *mutex;
switch_mutex_t *resample_mutex; switch_mutex_t *resample_mutex;
switch_mutex_t *codec_read_mutex;
switch_mutex_t *codec_write_mutex;
switch_thread_cond_t *cond; switch_thread_cond_t *cond;
switch_thread_rwlock_t *rwlock; switch_thread_rwlock_t *rwlock;
......
...@@ -732,7 +732,7 @@ CF_EARLY_MEDIA = (1 << 2) - Channel is ready for audio before answer ...@@ -732,7 +732,7 @@ CF_EARLY_MEDIA = (1 << 2) - Channel is ready for audio before answer
CF_ORIGINATOR = (1 << 3) - Channel is an originator CF_ORIGINATOR = (1 << 3) - Channel is an originator
CF_TRANSFER = (1 << 4) - Channel is being transfered CF_TRANSFER = (1 << 4) - Channel is being transfered
CF_ACCEPT_CNG = (1 << 5) - Channel will accept CNG frames CF_ACCEPT_CNG = (1 << 5) - Channel will accept CNG frames
CF_WAIT_FOR_ME = (1 << 6) - Channel wants you to wait CF_REDIRECT = (1 << 6) - Channel is being redirected
CF_BRIDGED = (1 << 7) - Channel in a bridge CF_BRIDGED = (1 << 7) - Channel in a bridge
CF_HOLD = (1 << 8) - Channel is on hold CF_HOLD = (1 << 8) - Channel is on hold
CF_SERVICE = (1 << 9) - Channel has a service thread CF_SERVICE = (1 << 9) - Channel has a service thread
...@@ -763,7 +763,7 @@ typedef enum { ...@@ -763,7 +763,7 @@ typedef enum {
CF_ORIGINATOR = (1 << 3), CF_ORIGINATOR = (1 << 3),
CF_TRANSFER = (1 << 4), CF_TRANSFER = (1 << 4),
CF_ACCEPT_CNG = (1 << 5), CF_ACCEPT_CNG = (1 << 5),
CF_WAIT_FOR_ME = (1 << 6), CF_REDIRECT = (1 << 6),
CF_BRIDGED = (1 << 7), CF_BRIDGED = (1 << 7),
CF_HOLD = (1 << 8), CF_HOLD = (1 << 8),
CF_SERVICE = (1 << 9), CF_SERVICE = (1 << 9),
...@@ -787,12 +787,13 @@ typedef enum { ...@@ -787,12 +787,13 @@ typedef enum {
CF_PROXY_MEDIA = (1 << 27), CF_PROXY_MEDIA = (1 << 27),
CF_INNER_BRIDGE = (1 << 28), CF_INNER_BRIDGE = (1 << 28),
CF_REQ_MEDIA = (1 << 29), CF_REQ_MEDIA = (1 << 29),
CF_VERBOSE_EVENTS = (1 << 30), CF_VERBOSE_EVENTS = (1 << 30)
CF_MASTER = (1 << 31)
} switch_channel_flag_enum_t; } switch_channel_flag_enum_t;
typedef uint32_t switch_channel_flag_t; typedef uint32_t switch_channel_flag_t;
/*! /*!
\enum switch_frame_flag_t \enum switch_frame_flag_t
\brief Frame Flags \brief Frame Flags
......
...@@ -841,7 +841,6 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_running_state( ...@@ -841,7 +841,6 @@ SWITCH_DECLARE(switch_channel_state_t) switch_channel_perform_set_running_state(
switch_clear_flag(channel, CF_TAGGED); switch_clear_flag(channel, CF_TAGGED);
if (channel->state >= CS_ROUTING) { if (channel->state >= CS_ROUTING) {
switch_clear_flag(channel, CF_TRANSFER);
switch_channel_presence(channel, "unknown", (char *) state_names[state], NULL); switch_channel_presence(channel, "unknown", (char *) state_names[state], NULL);
} }
......
...@@ -46,6 +46,7 @@ SWITCH_DECLARE(void) switch_core_session_unset_read_codec(switch_core_session_t ...@@ -46,6 +46,7 @@ SWITCH_DECLARE(void) switch_core_session_unset_read_codec(switch_core_session_t
{ {
switch_mutex_t *mutex = NULL; switch_mutex_t *mutex = NULL;
switch_mutex_lock(session->codec_read_mutex);
if (session->read_codec) mutex = session->read_codec->mutex; if (session->read_codec) mutex = session->read_codec->mutex;
if (mutex) switch_mutex_lock(mutex); if (mutex) switch_mutex_lock(mutex);
session->real_read_codec = session->read_codec = NULL; session->real_read_codec = session->read_codec = NULL;
...@@ -54,16 +55,19 @@ SWITCH_DECLARE(void) switch_core_session_unset_read_codec(switch_core_session_t ...@@ -54,16 +55,19 @@ SWITCH_DECLARE(void) switch_core_session_unset_read_codec(switch_core_session_t
session->enc_read_frame.codec = session->read_codec; session->enc_read_frame.codec = session->read_codec;
session->enc_write_frame.codec = session->read_codec; session->enc_write_frame.codec = session->read_codec;
if (mutex) switch_mutex_unlock(mutex); if (mutex) switch_mutex_unlock(mutex);
switch_mutex_unlock(session->codec_read_mutex);
} }
SWITCH_DECLARE(void) switch_core_session_unset_write_codec(switch_core_session_t *session) SWITCH_DECLARE(void) switch_core_session_unset_write_codec(switch_core_session_t *session)
{ {
switch_mutex_t *mutex = NULL; switch_mutex_t *mutex = NULL;
switch_mutex_lock(session->codec_write_mutex);
if (session->write_codec) mutex = session->write_codec->mutex; if (session->write_codec) mutex = session->write_codec->mutex;
if (mutex) switch_mutex_lock(mutex); if (mutex) switch_mutex_lock(mutex);
session->real_write_codec = session->write_codec = NULL; session->real_write_codec = session->write_codec = NULL;
if (mutex) switch_mutex_unlock(mutex); if (mutex) switch_mutex_unlock(mutex);
switch_mutex_unlock(session->codec_write_mutex);
} }
...@@ -74,6 +78,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s ...@@ -74,6 +78,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s
char tmp[30]; char tmp[30];
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_mutex_lock(session->codec_read_mutex);
if (codec && !codec->implementation) { if (codec && !codec->implementation) {
codec = NULL; codec = NULL;
} }
...@@ -128,6 +134,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s ...@@ -128,6 +134,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s
end: end:
switch_mutex_unlock(session->codec_read_mutex);
return status; return status;
} }
...@@ -192,6 +199,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_ ...@@ -192,6 +199,8 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_
char tmp[30]; char tmp[30];
switch_status_t status = SWITCH_STATUS_SUCCESS; switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_mutex_lock(session->codec_write_mutex);
if (!codec || !codec->implementation) { if (!codec || !codec->implementation) {
if (session->real_write_codec) { if (session->real_write_codec) {
session->write_codec = session->real_write_codec; session->write_codec = session->real_write_codec;
...@@ -241,6 +250,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_ ...@@ -241,6 +250,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_
} }
end: end:
switch_mutex_unlock(session->codec_write_mutex);
return status; return status;
} }
......
...@@ -110,10 +110,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi ...@@ -110,10 +110,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
switch_assert(session != NULL); switch_assert(session != NULL);
if (!(session->read_codec && session->read_codec->implementation)) { if (!(session->read_codec && session->read_codec->implementation)) {
if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) || switch_channel_get_state(session->channel) == CS_HIBERNATE) {
*frame = &runtime.dummy_cng_frame;
return SWITCH_STATUS_SUCCESS;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s has no read codec.\n", switch_channel_get_name(session->channel)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s has no read codec.\n", switch_channel_get_name(session->channel));
return SWITCH_STATUS_FALSE; return SWITCH_STATUS_FALSE;
} }
switch_mutex_lock(session->codec_read_mutex);
switch_mutex_lock(session->read_codec->mutex); switch_mutex_lock(session->read_codec->mutex);
top: top:
...@@ -521,6 +526,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi ...@@ -521,6 +526,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
} }
switch_mutex_unlock(session->read_codec->mutex); switch_mutex_unlock(session->read_codec->mutex);
switch_mutex_unlock(session->codec_read_mutex);
return status; return status;
} }
...@@ -588,6 +594,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess ...@@ -588,6 +594,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
} }
switch_mutex_lock(session->write_codec->mutex); switch_mutex_lock(session->write_codec->mutex);
switch_mutex_lock(frame->codec->mutex); switch_mutex_lock(frame->codec->mutex);
switch_mutex_lock(session->codec_write_mutex);
if ((session->write_codec && frame->codec && session->write_codec->implementation != frame->codec->implementation)) { if ((session->write_codec && frame->codec && session->write_codec->implementation != frame->codec->implementation)) {
need_codec = TRUE; need_codec = TRUE;
...@@ -977,6 +984,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess ...@@ -977,6 +984,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
switch_mutex_unlock(session->write_codec->mutex); switch_mutex_unlock(session->write_codec->mutex);
switch_mutex_unlock(frame->codec->mutex); switch_mutex_unlock(frame->codec->mutex);
switch_mutex_unlock(session->codec_write_mutex);
return status; return status;
} }
......
...@@ -747,6 +747,7 @@ SWITCH_DECLARE(void) switch_core_session_reset(switch_core_session_t *session, s ...@@ -747,6 +747,7 @@ SWITCH_DECLARE(void) switch_core_session_reset(switch_core_session_t *session, s
switch_channel_t *channel = switch_core_session_get_channel(session); switch_channel_t *channel = switch_core_session_get_channel(session);
switch_size_t has; switch_size_t has;
switch_core_session_set_read_codec(session, NULL); switch_core_session_set_read_codec(session, NULL);
/* clear resamplers */ /* clear resamplers */
...@@ -1102,6 +1103,8 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(switch_ ...@@ -1102,6 +1103,8 @@ SWITCH_DECLARE(switch_core_session_t *) switch_core_session_request_uuid(switch_
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_mutex_init(&session->resample_mutex, SWITCH_MUTEX_NESTED, session->pool);
switch_mutex_init(&session->codec_read_mutex, SWITCH_MUTEX_NESTED, session->pool);
switch_mutex_init(&session->codec_write_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);
......
...@@ -185,7 +185,6 @@ static void switch_core_standard_on_park(switch_core_session_t *session) ...@@ -185,7 +185,6 @@ static void switch_core_standard_on_park(switch_core_session_t *session)
{ {
switch_assert(session != NULL); switch_assert(session != NULL);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Standard PARK\n", switch_channel_get_name(session->channel)); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Standard PARK\n", switch_channel_get_name(session->channel));
switch_channel_clear_flag(session->channel, CF_TRANSFER);
switch_core_session_reset(session, SWITCH_TRUE); switch_core_session_reset(session, SWITCH_TRUE);
switch_ivr_park(session, NULL); switch_ivr_park(session, NULL);
} }
...@@ -373,6 +372,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session) ...@@ -373,6 +372,7 @@ SWITCH_DECLARE(void) switch_core_session_run(switch_core_session_t *session)
int do_extra_handlers = 1; int do_extra_handlers = 1;
switch_channel_set_running_state(session->channel, state); switch_channel_set_running_state(session->channel, state);
switch_channel_clear_flag(session->channel, CF_TRANSFER);
switch (state) { switch (state) {
case CS_NEW: /* Just created, Waiting for first instructions */ case CS_NEW: /* Just created, Waiting for first instructions */
......
差异被折叠。
...@@ -231,7 +231,9 @@ static uint8_t check_channel_status(switch_channel_t **peer_channels, ...@@ -231,7 +231,9 @@ static uint8_t check_channel_status(switch_channel_t **peer_channels,
state = switch_channel_get_state(peer_channels[i]); state = switch_channel_get_state(peer_channels[i]);
if (state >= CS_HANGUP || state == CS_RESET || switch_channel_test_flag(peer_channels[i], CF_TRANSFER) || if (state >= CS_HANGUP || state == CS_RESET || switch_channel_test_flag(peer_channels[i], CF_TRANSFER) ||
switch_channel_test_flag(peer_channels[i], CF_BRIDGED) || !switch_channel_test_flag(peer_channels[i], CF_ORIGINATING) switch_channel_test_flag(peer_channels[i], CF_REDIRECT) ||
switch_channel_test_flag(peer_channels[i], CF_BRIDGED) ||
!switch_channel_test_flag(peer_channels[i], CF_ORIGINATING)
) { ) {
(*hups)++; (*hups)++;
} else if ((switch_channel_test_flag(peer_channels[i], CF_ANSWERED) || } else if ((switch_channel_test_flag(peer_channels[i], CF_ANSWERED) ||
...@@ -1453,8 +1455,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess ...@@ -1453,8 +1455,11 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
continue; continue;
} }
if (switch_channel_test_flag(peer_channels[i], CF_TRANSFER) || switch_channel_test_flag(peer_channels[i], CF_BRIDGED) || if (switch_channel_test_flag(peer_channels[i], CF_TRANSFER)
switch_channel_get_state(peer_channels[i]) == CS_RESET || !switch_channel_test_flag(peer_channels[i], CF_ORIGINATING) || switch_channel_test_flag(peer_channels[i], CF_REDIRECT)
|| switch_channel_test_flag(peer_channels[i], CF_BRIDGED) ||
switch_channel_get_state(peer_channels[i]) == CS_RESET ||
!switch_channel_test_flag(peer_channels[i], CF_ORIGINATING)
) { ) {
continue; continue;
} }
...@@ -1652,6 +1657,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess ...@@ -1652,6 +1657,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
} }
} else if ((state=switch_channel_get_state(peer_channels[i])) < CS_HANGUP && switch_channel_test_flag(peer_channels[i], CF_ORIGINATING)) { } else if ((state=switch_channel_get_state(peer_channels[i])) < CS_HANGUP && switch_channel_test_flag(peer_channels[i], CF_ORIGINATING)) {
if (!(state == CS_RESET || switch_channel_test_flag(peer_channels[i], CF_TRANSFER) || if (!(state == CS_RESET || switch_channel_test_flag(peer_channels[i], CF_TRANSFER) ||
switch_channel_test_flag(peer_channels[i], CF_REDIRECT) ||
switch_channel_test_flag(peer_channels[i], CF_BRIDGED))) { switch_channel_test_flag(peer_channels[i], CF_BRIDGED))) {
switch_channel_hangup(peer_channels[i], *cause); switch_channel_hangup(peer_channels[i], *cause);
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论