[Freeswitch-svn] [commit] r10465 - in freeswitch/trunk/src: . include
FreeSWITCH SVN
anthm at freeswitch.org
Wed Nov 19 12:12:20 PST 2008
Author: anthm
Date: Wed Nov 19 15:12:20 2008
New Revision: 10465
Log:
update
Modified:
freeswitch/trunk/src/include/switch_types.h
freeswitch/trunk/src/switch_core_codec.c
freeswitch/trunk/src/switch_core_io.c
freeswitch/trunk/src/switch_ivr_bridge.c
Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h (original)
+++ freeswitch/trunk/src/include/switch_types.h Wed Nov 19 15:12:20 2008
@@ -784,7 +784,8 @@
CF_PROXY_MEDIA = (1 << 27),
CF_INNER_BRIDGE = (1 << 28),
CF_REQ_MEDIA = (1 << 29),
- CF_VERBOSE_EVENTS = (1 << 30)
+ CF_VERBOSE_EVENTS = (1 << 30),
+ CF_MASTER = (1 << 31)
} switch_channel_flag_enum_t;
typedef uint32_t switch_channel_flag_t;
Modified: freeswitch/trunk/src/switch_core_codec.c
==============================================================================
--- freeswitch/trunk/src/switch_core_codec.c (original)
+++ freeswitch/trunk/src/switch_core_codec.c Wed Nov 19 15:12:20 2008
@@ -44,16 +44,26 @@
SWITCH_DECLARE(void) switch_core_session_unset_read_codec(switch_core_session_t *session)
{
+ switch_mutex_t *mutex = NULL;
+
+ if (session->read_codec) mutex = session->read_codec->mutex;
+ if (mutex) switch_mutex_lock(mutex);
session->real_read_codec = session->read_codec = NULL;
session->raw_read_frame.codec = session->read_codec;
session->raw_write_frame.codec = session->read_codec;
session->enc_read_frame.codec = session->read_codec;
session->enc_write_frame.codec = session->read_codec;
+ if (mutex) switch_mutex_unlock(mutex);
}
SWITCH_DECLARE(void) switch_core_session_unset_write_codec(switch_core_session_t *session)
{
+ switch_mutex_t *mutex = NULL;
+
+ if (session->write_codec) mutex = session->write_codec->mutex;
+ if (mutex) switch_mutex_lock(mutex);
session->real_write_codec = session->write_codec = NULL;
+ if (mutex) switch_mutex_unlock(mutex);
}
Modified: freeswitch/trunk/src/switch_core_io.c
==============================================================================
--- freeswitch/trunk/src/switch_core_io.c (original)
+++ freeswitch/trunk/src/switch_core_io.c Wed Nov 19 15:12:20 2008
@@ -103,17 +103,24 @@
int stream_id)
{
switch_io_event_hook_read_frame_t *ptr;
- switch_status_t status;
+ switch_status_t status = SWITCH_STATUS_FALSE;
int need_codec, perfect, do_bugs = 0, do_resample = 0, is_cng = 0;
unsigned int flag = 0;
switch_assert(session != NULL);
+ if (!(session->read_codec && session->read_codec->implementation)) {
+ 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;
+ }
+
+ switch_mutex_lock(session->read_codec->mutex);
+
top:
if (switch_channel_get_state(session->channel) >= CS_HANGUP) {
*frame = NULL;
- return SWITCH_STATUS_FALSE;
+ status = SWITCH_STATUS_FALSE; goto even_more_done;
}
@@ -178,10 +185,6 @@
switch_assert((*frame)->codec != NULL);
- if (!(session->read_codec && session->read_codec->implementation)) {
- 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;
- }
if (((*frame)->codec && session->read_codec->implementation != (*frame)->codec->implementation)) {
need_codec = TRUE;
@@ -517,6 +520,8 @@
*frame = &runtime.dummy_cng_frame;
}
+ switch_mutex_unlock(session->read_codec->mutex);
+
return status;
}
@@ -578,6 +583,12 @@
switch_assert(frame->codec != NULL);
switch_assert(frame->codec->implementation != NULL);
+ if (!(session->write_codec && frame->codec)) {
+ return SWITCH_STATUS_FALSE;
+ }
+ switch_mutex_lock(session->write_codec->mutex);
+ switch_mutex_lock(frame->codec->mutex);
+
if ((session->write_codec && frame->codec && session->write_codec->implementation != frame->codec->implementation)) {
need_codec = TRUE;
if (session->write_codec->implementation->codec_id == frame->codec->implementation->codec_id) {
@@ -589,10 +600,6 @@
need_codec = TRUE;
}
- if (!session->write_codec && frame->codec) {
- return SWITCH_STATUS_FALSE;
- }
-
if (session->bugs && !need_codec) {
do_bugs = TRUE;
need_codec = TRUE;
@@ -655,7 +662,7 @@
write_frame = &session->raw_write_frame;
break;
case SWITCH_STATUS_BREAK:
- return SWITCH_STATUS_SUCCESS;
+ status = SWITCH_STATUS_SUCCESS; goto error;
case SWITCH_STATUS_NOOP:
if (session->write_resampler) {
switch_mutex_lock(session->resample_mutex);
@@ -669,15 +676,15 @@
default:
if (status == SWITCH_STATUS_NOT_INITALIZED) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec init error!\n");
- return status;
+ goto error;
}
if (ptime_mismatch) {
status = perform_write(session, frame, flags, stream_id);
- return SWITCH_STATUS_SUCCESS;
+ status = SWITCH_STATUS_SUCCESS; goto error;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s decoder error!\n", frame->codec->codec_interface->interface_name);
- return status;
+ goto error;
}
}
@@ -775,13 +782,13 @@
bytes * SWITCH_BUFFER_BLOCK_FRAMES,
bytes * SWITCH_BUFFER_START_FRAMES, 0)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Write Buffer Failed!\n");
- return status;
+ goto error;
}
}
if (!(switch_buffer_write(session->raw_write_buffer, write_frame->data, write_frame->datalen))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Write Buffer %u bytes Failed!\n", write_frame->datalen);
- return SWITCH_STATUS_MEMERR;
+ status = SWITCH_STATUS_MEMERR; goto error;
}
}
@@ -827,18 +834,18 @@
case SWITCH_STATUS_NOT_INITALIZED:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec init error!\n");
write_frame = NULL;
- return status;
+ goto error;
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s encoder error!\n",
session->read_codec->codec_interface->interface_name);
write_frame = NULL;
- return status;
+ goto error;
}
if (flag & SFF_CNG) {
switch_set_flag(write_frame, SFF_CNG);
}
status = perform_write(session, write_frame, flags, stream_id);
- return status;
+ goto error;
} else {
switch_size_t used = switch_buffer_inuse(session->raw_write_buffer);
uint32_t bytes = session->write_codec->implementation->decoded_bytes_per_packet;
@@ -846,7 +853,7 @@
status = SWITCH_STATUS_SUCCESS;
if (!frames) {
- return status;
+ goto error;
} else {
switch_size_t x;
for (x = 0; x < frames; x++) {
@@ -918,12 +925,12 @@
case SWITCH_STATUS_NOT_INITALIZED:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec init error!\n");
write_frame = NULL;
- return status;
+ goto error;
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s encoder error %d!\n",
session->read_codec->codec_interface->interface_name, status);
write_frame = NULL;
- return status;
+ goto error;
}
if (session->read_resampler) {
@@ -952,7 +959,7 @@
}
}
}
- return status;
+ goto error;
}
}
}
@@ -960,11 +967,17 @@
do_write = TRUE;
}
- done:
+ done:
if (do_write) {
- return perform_write(session, frame, flags, stream_id);
+ status = perform_write(session, frame, flags, stream_id);
}
+
+ error:
+
+ switch_mutex_unlock(session->write_codec->mutex);
+ switch_mutex_unlock(frame->codec->mutex);
+
return status;
}
Modified: freeswitch/trunk/src/switch_ivr_bridge.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_bridge.c (original)
+++ freeswitch/trunk/src/switch_ivr_bridge.c Wed Nov 19 15:12:20 2008
@@ -529,7 +529,7 @@
switch_channel_clear_flag(channel, CF_TRANSFER);
switch_channel_clear_flag(channel, CF_ORIGINATING);
- if (switch_channel_test_flag(channel, CF_ORIGINATOR)) {
+ if (switch_channel_test_flag(channel, CF_MASTER)) {
switch_channel_set_state(channel, CS_SOFT_EXECUTE);
}
@@ -547,10 +547,12 @@
switch_channel_clear_flag(channel, CF_TRANSFER);
- if (!switch_channel_test_flag(channel, CF_ORIGINATOR)) {
+ if (!switch_channel_test_flag(channel, CF_MASTER)) {
return SWITCH_STATUS_SUCCESS;
}
+ switch_channel_clear_flag(channel, CF_MASTER);
+
if ((other_uuid = switch_channel_get_variable(channel, SWITCH_UUID_BRIDGE)) && (other_session = switch_core_session_locate(other_uuid))) {
switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
switch_event_t *event;
@@ -724,7 +726,7 @@
switch_channel_set_variable(caller_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, switch_core_session_get_uuid(peer_session));
switch_channel_set_variable(peer_channel, SWITCH_SIGNAL_BRIDGE_VARIABLE, switch_core_session_get_uuid(session));
- switch_channel_set_state_flag(caller_channel, CF_ORIGINATOR);
+ switch_channel_set_flag(caller_channel, CF_ORIGINATOR);
switch_channel_clear_state_handler(caller_channel, NULL);
switch_channel_clear_state_handler(peer_channel, NULL);
@@ -1033,8 +1035,8 @@
switch_channel_clear_state_handler(originator_channel, NULL);
switch_channel_clear_state_handler(originatee_channel, NULL);
- switch_channel_set_state_flag(originator_channel, CF_ORIGINATOR);
- switch_channel_clear_flag(originatee_channel, CF_ORIGINATOR);
+ switch_channel_set_state_flag(originator_channel, CF_MASTER);
+ switch_channel_clear_flag(originatee_channel, CF_MASTER);
switch_channel_add_state_handler(originator_channel, &uuid_bridge_state_handlers);
switch_channel_add_state_handler(originatee_channel, &uuid_bridge_state_handlers);
switch_channel_set_variable(originator_channel, SWITCH_UUID_BRIDGE, switch_core_session_get_uuid(originatee_session));
More information about the Freeswitch-svn
mailing list