[Freeswitch-svn] [commit] r10045 - in freeswitch/trunk/src: . include include/private
Freeswitch SVN
anthm at freeswitch.org
Thu Oct 16 12:34:52 EDT 2008
Author: anthm
Date: Thu Oct 16 12:34:52 2008
New Revision: 10045
Modified:
freeswitch/trunk/src/include/private/switch_core_pvt.h
freeswitch/trunk/src/include/switch_core.h
freeswitch/trunk/src/switch_core_codec.c
Log:
avoiding deadlock
Modified: freeswitch/trunk/src/include/private/switch_core_pvt.h
==============================================================================
--- freeswitch/trunk/src/include/private/switch_core_pvt.h (original)
+++ freeswitch/trunk/src/include/private/switch_core_pvt.h Thu Oct 16 12:34:52 2008
@@ -111,6 +111,11 @@
switch_codec_t *video_read_codec;
switch_codec_t *video_write_codec;
+ switch_codec_implementation_t read_impl;
+ switch_codec_implementation_t write_impl;
+ switch_codec_implementation_t video_read_impl;
+ switch_codec_implementation_t video_write_impl;
+
switch_audio_resampler_t *read_resampler;
switch_audio_resampler_t *write_resampler;
Modified: freeswitch/trunk/src/include/switch_core.h
==============================================================================
--- freeswitch/trunk/src/include/switch_core.h (original)
+++ freeswitch/trunk/src/include/switch_core.h Thu Oct 16 12:34:52 2008
@@ -1134,6 +1134,13 @@
SWITCH_DECLARE(void) switch_core_session_unset_read_codec(_In_ switch_core_session_t *session);
SWITCH_DECLARE(void) switch_core_session_unset_write_codec(_In_ switch_core_session_t *session);
+
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_video_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_video_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp);
+
+
/*!
\brief Retrieve the read codec from a given session
\param session session to retrieve from
Modified: freeswitch/trunk/src/switch_core_codec.c
==============================================================================
--- freeswitch/trunk/src/switch_core_codec.c (original)
+++ freeswitch/trunk/src/switch_core_codec.c Thu Oct 16 12:34:52 2008
@@ -46,14 +46,11 @@
{
switch_mutex_lock(session->resample_mutex);
session->real_read_codec = session->read_codec = NULL;
- switch_mutex_unlock(session->resample_mutex);
}
SWITCH_DECLARE(void) switch_core_session_unset_write_codec(switch_core_session_t *session)
-{
- switch_mutex_lock(session->resample_mutex);
+{
session->real_write_codec = session->write_codec = NULL;
- switch_mutex_unlock(session->resample_mutex);
}
@@ -64,8 +61,6 @@
char tmp[30];
switch_status_t status = SWITCH_STATUS_SUCCESS;
- switch_mutex_lock(session->resample_mutex);
-
if (codec && !codec->implementation) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set UNINITIALIZED codec!\n");
status = SWITCH_STATUS_FALSE;
@@ -77,6 +72,7 @@
if (session->real_read_codec) {
if (session->real_read_codec->implementation) {
session->read_codec = session->real_read_codec;
+ session->read_impl = *session->real_read_codec->implementation;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "resetting to uninitilized codec, setting to NULL\n");
session->read_codec = session->real_read_codec = NULL;
@@ -96,25 +92,26 @@
}
session->read_codec = codec;
+ session->read_impl = *codec->implementation;
if (!session->real_read_codec) {
session->real_read_codec = session->read_codec;
}
}
- if (session->read_codec && session->read_codec->implementation) {
+ if (session->read_codec && codec && session->read_impl.bytes_per_frame) {
if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
switch_channel_event_set_data(session->channel, event);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-read-codec-name", session->read_codec->implementation->iananame);
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-rate", "%d", session->read_codec->implementation->actual_samples_per_second);
- if (session->read_codec->implementation->actual_samples_per_second != session->read_codec->implementation->samples_per_second) {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-reported-read-codec-rate", "%d", session->read_codec->implementation->samples_per_second);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-read-codec-name", session->read_impl.iananame);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-rate", "%d", session->read_impl.actual_samples_per_second);
+ if (session->read_impl.actual_samples_per_second != session->read_impl.samples_per_second) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-reported-read-codec-rate", "%d", session->read_impl.samples_per_second);
}
switch_event_fire(&event);
}
- switch_channel_set_variable(channel, "read_codec", session->read_codec->implementation->iananame);
- switch_snprintf(tmp, sizeof(tmp), "%d", session->read_codec->implementation->actual_samples_per_second);
+ switch_channel_set_variable(channel, "read_codec", session->read_impl.iananame);
+ switch_snprintf(tmp, sizeof(tmp), "%d", session->read_impl.actual_samples_per_second);
switch_channel_set_variable(channel, "read_rate", tmp);
@@ -125,7 +122,6 @@
}
end:
- switch_mutex_unlock(session->resample_mutex);
return status;
@@ -133,22 +129,57 @@
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_effective_read_codec(switch_core_session_t *session)
{
- switch_codec_t *codec;
- switch_mutex_lock(session->resample_mutex);
- codec = session->read_codec;
- switch_mutex_unlock(session->resample_mutex);
+ switch_codec_t *codec; codec = session->read_codec;
return codec;
}
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_read_codec(switch_core_session_t *session)
{
- switch_codec_t *codec;
- switch_mutex_lock(session->resample_mutex);
- codec = session->real_read_codec ? session->real_read_codec : session->read_codec;
- switch_mutex_unlock(session->resample_mutex);
+ switch_codec_t *codec; codec = session->real_read_codec ? session->real_read_codec : session->read_codec;
return codec;
}
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
+{
+ if (session->read_impl.bytes_per_frame) {
+ *impp = session->read_impl;
+ return SWITCH_STATUS_SUCCESS;
+ }
+
+ return SWITCH_STATUS_FALSE;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
+{
+ if (session->write_impl.bytes_per_frame) {
+ *impp = session->write_impl;
+ return SWITCH_STATUS_SUCCESS;
+ }
+
+ return SWITCH_STATUS_FALSE;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_video_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
+{
+ if (session->video_read_impl.bytes_per_frame) {
+ *impp = session->video_read_impl;
+ return SWITCH_STATUS_SUCCESS;
+ }
+
+ return SWITCH_STATUS_FALSE;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_core_session_get_video_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
+{
+ if (session->video_write_impl.bytes_per_frame) {
+ *impp = session->video_write_impl;
+ return SWITCH_STATUS_SUCCESS;
+ }
+
+ return SWITCH_STATUS_FALSE;
+}
+
+
SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_session_t *session, switch_codec_t *codec)
{
switch_event_t *event;
@@ -156,11 +187,10 @@
char tmp[30];
switch_status_t status = SWITCH_STATUS_SUCCESS;
- switch_mutex_lock(session->resample_mutex);
-
if (!codec || !codec->implementation) {
if (session->real_write_codec) {
session->write_codec = session->real_write_codec;
+ session->write_impl = *session->real_write_codec->implementation;
session->real_write_codec = NULL;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
@@ -171,6 +201,7 @@
if (session->real_write_codec) {
if (codec == session->real_write_codec) {
session->write_codec = codec;
+ session->write_impl = *codec->implementation;
session->real_write_codec = NULL;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot double-set codec!\n");
@@ -180,29 +211,32 @@
} else {
session->real_write_codec = session->write_codec;
session->write_codec = codec;
+ session->write_impl = *codec->implementation;
}
} else {
session->write_codec = codec;
+ session->write_impl = *codec->implementation;
}
- if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
- switch_channel_event_set_data(session->channel, event);
- switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-write-codec-name", session->write_codec->implementation->iananame);
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-write-codec-rate", "%d", session->write_codec->implementation->actual_samples_per_second);
- if (session->write_codec->implementation->actual_samples_per_second != session->write_codec->implementation->samples_per_second) {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-reported-write-codec-rate", "%d",
- session->write_codec->implementation->actual_samples_per_second);
+ if (session->write_codec && codec && session->write_impl.bytes_per_frame) {
+ if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
+ switch_channel_event_set_data(session->channel, event);
+ switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-write-codec-name", session->write_impl.iananame);
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-write-codec-rate", "%d", session->write_impl.actual_samples_per_second);
+ if (session->write_impl.actual_samples_per_second != session->write_impl.samples_per_second) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-reported-write-codec-rate", "%d",
+ session->write_impl.actual_samples_per_second);
+ }
+ switch_event_fire(&event);
}
- switch_event_fire(&event);
- }
- switch_channel_set_variable(channel, "write_codec", session->write_codec->implementation->iananame);
- switch_snprintf(tmp, sizeof(tmp), "%d", session->write_codec->implementation->actual_samples_per_second);
- switch_channel_set_variable(channel, "write_rate", tmp);
+ switch_channel_set_variable(channel, "write_codec", session->write_impl.iananame);
+ switch_snprintf(tmp, sizeof(tmp), "%d", session->write_impl.actual_samples_per_second);
+ switch_channel_set_variable(channel, "write_rate", tmp);
+ }
end:
- switch_mutex_unlock(session->resample_mutex);
return status;
}
@@ -210,10 +244,7 @@
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_effective_write_codec(switch_core_session_t *session)
{
switch_codec_t *codec;
-
- switch_mutex_lock(session->resample_mutex);
codec = session->write_codec;
- switch_mutex_unlock(session->resample_mutex);
return codec;
}
@@ -221,10 +252,7 @@
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_write_codec(switch_core_session_t *session)
{
switch_codec_t *codec;
-
- switch_mutex_lock(session->resample_mutex);
codec = session->real_write_codec ? session->real_write_codec : session->write_codec;
- switch_mutex_unlock(session->resample_mutex);
return codec;
}
@@ -238,8 +266,6 @@
char tmp[30];
switch_status_t status = SWITCH_STATUS_SUCCESS;
- switch_mutex_lock(session->resample_mutex);
-
if (!codec || !codec->implementation) {
if (session->video_read_codec) {
session->video_read_codec = NULL;
@@ -263,20 +289,16 @@
switch_channel_set_variable(channel, "video_read_rate", tmp);
session->video_read_codec = codec;
-
+ session->video_read_impl = *codec->implementation;
end:
- switch_mutex_unlock(session->resample_mutex);
return status;
}
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_video_read_codec(switch_core_session_t *session)
{
switch_codec_t *codec;
-
- switch_mutex_lock(session->resample_mutex);
codec = session->video_read_codec;
- switch_mutex_unlock(session->resample_mutex);
return codec;
@@ -288,9 +310,7 @@
switch_channel_t *channel = switch_core_session_get_channel(session);
char tmp[30];
switch_status_t status = SWITCH_STATUS_SUCCESS;
-
- switch_mutex_lock(session->resample_mutex);
- if (!codec || !codec->implementation) {
+ if (!codec || !codec->implementation) {
if (session->video_write_codec) {
session->video_write_codec = NULL;
status = SWITCH_STATUS_SUCCESS;
@@ -313,20 +333,17 @@
switch_channel_set_variable(channel, "video_write_rate", tmp);
session->video_write_codec = codec;
+ session->video_write_impl = *codec->implementation;
end:
- switch_mutex_unlock(session->resample_mutex);
return status;
}
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_video_write_codec(switch_core_session_t *session)
{
switch_codec_t *codec;
-
- switch_mutex_lock(session->resample_mutex);
codec = session->video_write_codec;
- switch_mutex_unlock(session->resample_mutex);
return codec;
More information about the Freeswitch-svn
mailing list