[Freeswitch-svn] [commit] r10037 - freeswitch/trunk/src
Freeswitch SVN
anthm at freeswitch.org
Wed Oct 15 17:54:27 EDT 2008
Author: anthm
Date: Wed Oct 15 17:54:26 2008
New Revision: 10037
Modified:
freeswitch/trunk/src/switch_core_codec.c
freeswitch/trunk/src/switch_pcm.c
Log:
add mutexes to codec set/get funcs
Modified: freeswitch/trunk/src/switch_core_codec.c
==============================================================================
--- freeswitch/trunk/src/switch_core_codec.c (original)
+++ freeswitch/trunk/src/switch_core_codec.c Wed Oct 15 17:54:26 2008
@@ -44,12 +44,16 @@
SWITCH_DECLARE(void) switch_core_session_unset_read_codec(switch_core_session_t *session)
{
+ 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);
}
@@ -58,10 +62,14 @@
switch_event_t *event;
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) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set UNINITIALIZED codec!\n");
- return SWITCH_STATUS_FALSE;
+ status = SWITCH_STATUS_FALSE;
+ goto end;
}
if (!codec || codec == session->real_read_codec) {
@@ -72,16 +80,19 @@
} 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;
- return SWITCH_STATUS_FALSE;
+ status = SWITCH_STATUS_FALSE;
+ goto end;
}
} else {
- return SWITCH_STATUS_FALSE;
+ status = SWITCH_STATUS_FALSE;
+ goto end;
}
} else if (codec) {
if (session->read_codec != session->real_read_codec) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot double-set codec!\n");
- return SWITCH_STATUS_FALSE;
+ status = SWITCH_STATUS_FALSE;
+ goto end;
}
session->read_codec = codec;
@@ -111,21 +122,31 @@
session->raw_write_frame.codec = session->read_codec;
session->enc_read_frame.codec = session->read_codec;
session->enc_write_frame.codec = session->read_codec;
- return SWITCH_STATUS_SUCCESS;
}
- return SWITCH_STATUS_FALSE;
+ end:
+ switch_mutex_unlock(session->resample_mutex);
+
+ return status;
}
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_effective_read_codec(switch_core_session_t *session)
{
- return session->read_codec;
+ switch_codec_t *codec;
+ switch_mutex_lock(session->resample_mutex);
+ codec = session->read_codec;
+ switch_mutex_unlock(session->resample_mutex);
+ return codec;
}
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_read_codec(switch_core_session_t *session)
{
- return session->real_read_codec ? session->real_read_codec : session->read_codec;
+ 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);
+ return codec;
}
SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_session_t *session, switch_codec_t *codec)
@@ -133,6 +154,9 @@
switch_event_t *event;
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 (session->real_write_codec) {
@@ -140,7 +164,8 @@
session->real_write_codec = NULL;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
- return SWITCH_STATUS_FALSE;
+ status = SWITCH_STATUS_FALSE;
+ goto end;
}
} else if (session->write_codec) {
if (session->real_write_codec) {
@@ -149,7 +174,8 @@
session->real_write_codec = NULL;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot double-set codec!\n");
- return SWITCH_STATUS_FALSE;
+ status = SWITCH_STATUS_FALSE;
+ goto end;
}
} else {
session->real_write_codec = session->write_codec;
@@ -174,18 +200,33 @@
switch_snprintf(tmp, sizeof(tmp), "%d", session->write_codec->implementation->actual_samples_per_second);
switch_channel_set_variable(channel, "write_rate", tmp);
- return SWITCH_STATUS_SUCCESS;
+ end:
+
+ switch_mutex_unlock(session->resample_mutex);
+ return status;
}
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_effective_write_codec(switch_core_session_t *session)
{
- return session->write_codec;
+ switch_codec_t *codec;
+
+ switch_mutex_lock(session->resample_mutex);
+ codec = session->write_codec;
+ switch_mutex_unlock(session->resample_mutex);
+
+ return codec;
}
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_write_codec(switch_core_session_t *session)
{
- return session->real_write_codec ? session->real_write_codec : session->write_codec;
+ 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;
}
@@ -195,14 +236,19 @@
switch_event_t *event;
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 (session->video_read_codec) {
session->video_read_codec = NULL;
- return SWITCH_STATUS_SUCCESS;
+ status = SWITCH_STATUS_SUCCESS;
+ goto end;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
- return SWITCH_STATUS_FALSE;
+ status = SWITCH_STATUS_FALSE;
+ goto end;
}
if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
@@ -218,12 +264,22 @@
session->video_read_codec = codec;
- return SWITCH_STATUS_SUCCESS;
+ 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)
{
- return session->video_read_codec;
+ switch_codec_t *codec;
+
+ switch_mutex_lock(session->resample_mutex);
+ codec = session->video_read_codec;
+ switch_mutex_unlock(session->resample_mutex);
+
+ return codec;
+
}
SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_write_codec(switch_core_session_t *session, switch_codec_t *codec)
@@ -231,14 +287,18 @@
switch_event_t *event;
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 (session->video_write_codec) {
session->video_write_codec = NULL;
- return SWITCH_STATUS_SUCCESS;
+ status = SWITCH_STATUS_SUCCESS;
+ goto end;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
- return SWITCH_STATUS_FALSE;
+ status = SWITCH_STATUS_FALSE;
+ goto end;
}
if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
@@ -253,12 +313,23 @@
switch_channel_set_variable(channel, "video_write_rate", tmp);
session->video_write_codec = codec;
- return SWITCH_STATUS_SUCCESS;
+
+ 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)
{
- return session->video_write_codec;
+ switch_codec_t *codec;
+
+ switch_mutex_lock(session->resample_mutex);
+ codec = session->video_write_codec;
+ switch_mutex_unlock(session->resample_mutex);
+
+ return codec;
+
}
Modified: freeswitch/trunk/src/switch_pcm.c
==============================================================================
--- freeswitch/trunk/src/switch_pcm.c (original)
+++ freeswitch/trunk/src/switch_pcm.c Wed Oct 15 17:54:26 2008
@@ -275,7 +275,7 @@
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 0, "PCMU", NULL, 8000, 8000, 64000,
- mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 1,
+ mpf * count, spf * count, bpf * count, ebpf * count, 1, spf * count, spf * count,
switch_g711u_init, switch_g711u_encode, switch_g711u_decode, switch_g711u_destroy);
}
@@ -283,7 +283,7 @@
for (count = 12; count > 0; count--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, 8, "PCMA", NULL, 8000, 8000, 64000,
- mpf * count, spf * count, bpf * count, ebpf * count, 1, 1, 1,
+ mpf * count, spf * count, bpf * count, ebpf * count, 1, spf * count, spf * count,
switch_g711a_init, switch_g711a_encode, switch_g711a_decode, switch_g711a_destroy);
}
@@ -316,7 +316,7 @@
for (countb = 12; countb > 0; countb--) {
switch_core_codec_add_implementation(pool, codec_interface,
SWITCH_CODEC_TYPE_AUDIO, ianacode[counta], "L16", NULL, rate, rate, bps,
- mpf * countb, spf * countb, bpf * countb, ebpf * countb, 1, 1, 1,
+ mpf * countb, spf * countb, bpf * countb, ebpf * countb, 1, spf * countb, spf * countb,
switch_raw_init, switch_raw_encode, switch_raw_decode, switch_raw_destroy);
}
rate = rate * 2;
More information about the Freeswitch-svn
mailing list