[Freeswitch-svn] [commit] r12953 - in freeswitch/trunk/src: . include mod/endpoints/mod_loopback
FreeSWITCH SVN
anthm at freeswitch.org
Wed Apr 8 11:43:11 PDT 2009
Author: anthm
Date: Wed Apr 8 13:43:10 2009
New Revision: 12953
Log:
FSCORE-349
Modified:
freeswitch/trunk/src/include/switch_frame.h
freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c
freeswitch/trunk/src/switch_core_io.c
Modified: freeswitch/trunk/src/include/switch_frame.h
==============================================================================
--- freeswitch/trunk/src/include/switch_frame.h (original)
+++ freeswitch/trunk/src/include/switch_frame.h Wed Apr 8 13:43:10 2009
@@ -68,6 +68,7 @@
switch_bool_t m;
/*! frame flags */
switch_frame_flag_t flags;
+ switch_core_session_t *session;
};
SWITCH_END_EXTERN_C
Modified: freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_loopback/mod_loopback.c Wed Apr 8 13:43:10 2009
@@ -115,12 +115,10 @@
if (tech_pvt->read_codec.implementation) {
switch_core_codec_destroy(&tech_pvt->read_codec);
- memset(&tech_pvt->read_codec, 0, sizeof(tech_pvt->read_codec));
}
if (tech_pvt->write_codec.implementation) {
switch_core_codec_destroy(&tech_pvt->write_codec);
- memset(&tech_pvt->write_codec, 0, sizeof(tech_pvt->write_codec));
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s setup codec %s/%d/%d\n", switch_channel_get_name(channel), iananame, rate, interval);
@@ -161,7 +159,9 @@
tech_pvt->write_frame.data = tech_pvt->write_databuf;
tech_pvt->write_frame.buflen = sizeof(tech_pvt->write_databuf);
+ tech_pvt->write_frame.codec = &tech_pvt->write_codec;
+
tech_pvt->cng_frame.data = tech_pvt->cng_databuf;
tech_pvt->cng_frame.buflen = sizeof(tech_pvt->cng_databuf);
switch_set_flag((&tech_pvt->cng_frame), SFF_CNG);
@@ -362,7 +362,6 @@
switch_clear_flag_locked(tech_pvt->other_tech_pvt, TFLAG_LINKED);
tech_pvt->other_tech_pvt = NULL;
}
- switch_mutex_unlock(tech_pvt->mutex);
if (tech_pvt->other_session) {
switch_channel_hangup(tech_pvt->other_channel, switch_channel_get_cause(channel));
@@ -370,17 +369,16 @@
tech_pvt->other_channel = NULL;
tech_pvt->other_session = NULL;
}
+ switch_mutex_unlock(tech_pvt->mutex);
switch_core_timer_destroy(&tech_pvt->timer);
if (tech_pvt->read_codec.implementation) {
switch_core_codec_destroy(&tech_pvt->read_codec);
- memset(&tech_pvt->read_codec, 0, sizeof(tech_pvt->read_codec));
}
if (tech_pvt->write_codec.implementation) {
switch_core_codec_destroy(&tech_pvt->write_codec);
- memset(&tech_pvt->write_codec, 0, sizeof(tech_pvt->write_codec));
}
return SWITCH_STATUS_SUCCESS;
@@ -518,33 +516,21 @@
mutex = tech_pvt->mutex;
switch_mutex_lock(mutex);
- while(switch_test_flag(tech_pvt, TFLAG_LINKED) && tech_pvt->other_tech_pvt) {
- if (!switch_channel_ready(channel)) {
- goto end;
- }
- if (switch_test_flag(tech_pvt, TFLAG_CNG)) {
- break;
- }
-
- if (tech_pvt->other_tech_pvt && switch_test_flag(tech_pvt->other_tech_pvt, TFLAG_WRITE)) {
- break;
- }
-
- if (switch_core_timer_check(&tech_pvt->timer, SWITCH_TRUE) == SWITCH_STATUS_SUCCESS) {
- switch_set_flag(tech_pvt, TFLAG_CNG);
- break;
- }
+
+ if (!switch_channel_ready(channel)) {
+ goto end;
+ }
- switch_cond_next();
+ if (!switch_test_flag(tech_pvt, TFLAG_CNG) && !switch_test_flag(tech_pvt, TFLAG_WRITE)) {
+ switch_core_timer_next(&tech_pvt->timer);
}
- if (switch_test_flag(tech_pvt, TFLAG_LINKED)) {
- if (tech_pvt->other_tech_pvt && switch_test_flag(tech_pvt->other_tech_pvt, TFLAG_WRITE)) {
- switch_core_timer_sync(&tech_pvt->timer);
- *frame = &tech_pvt->other_tech_pvt->write_frame;
- switch_clear_flag_locked(tech_pvt->other_tech_pvt, TFLAG_WRITE);
- switch_clear_flag_locked(tech_pvt, TFLAG_CNG);
- }
+ if (switch_test_flag(tech_pvt, TFLAG_WRITE)) {
+ *frame = &tech_pvt->write_frame;
+ switch_clear_flag_locked(tech_pvt, TFLAG_WRITE);
+ switch_clear_flag_locked(tech_pvt, TFLAG_CNG);
+ } else {
+ switch_set_flag(tech_pvt, TFLAG_CNG);
}
if (switch_test_flag(tech_pvt, TFLAG_CNG)) {
@@ -555,7 +541,7 @@
}
- if (*frame && switch_test_flag(tech_pvt, TFLAG_LINKED)) {
+ if (*frame) {
status = SWITCH_STATUS_SUCCESS;
} else {
status = SWITCH_STATUS_FALSE;
@@ -624,12 +610,12 @@
tech_init(tech_pvt->other_tech_pvt, tech_pvt->other_session, frame->codec);
}
- memcpy(&tech_pvt->write_frame, frame, sizeof(*frame));
- tech_pvt->write_frame.data = tech_pvt->write_databuf;
- tech_pvt->write_frame.buflen = sizeof(tech_pvt->write_databuf);
- tech_pvt->write_frame.codec = &tech_pvt->write_codec;
- memcpy(tech_pvt->write_frame.data, frame->data, frame->datalen);
- switch_set_flag_locked(tech_pvt, TFLAG_WRITE);
+ memcpy(&tech_pvt->other_tech_pvt->write_frame, frame, sizeof(*frame));
+ tech_pvt->other_tech_pvt->write_frame.data = tech_pvt->other_tech_pvt->write_databuf;
+ tech_pvt->other_tech_pvt->write_frame.buflen = sizeof(tech_pvt->other_tech_pvt->write_databuf);
+ //tech_pvt->other_tech_pvt->write_frame.codec = &tech_pvt->other_tech_pvt->write_codec;
+ memcpy(tech_pvt->other_tech_pvt->write_frame.data, frame->data, frame->datalen);
+ switch_set_flag_locked(tech_pvt->other_tech_pvt, TFLAG_WRITE);
status = SWITCH_STATUS_SUCCESS;
}
Modified: freeswitch/trunk/src/switch_core_io.c
==============================================================================
--- freeswitch/trunk/src/switch_core_io.c (original)
+++ freeswitch/trunk/src/switch_core_io.c Wed Apr 8 13:43:10 2009
@@ -206,11 +206,7 @@
need_codec = TRUE;
}
- if (session->read_codec && !(*frame)->codec) {
- need_codec = TRUE;
- }
-
- if (!session->read_codec && (*frame)->codec) {
+ if (!(session->read_codec && (*frame)->codec && (*frame)->codec->implementation)) {
status = SWITCH_STATUS_FALSE;
goto done;
}
@@ -533,6 +529,8 @@
*frame = &runtime.dummy_cng_frame;
}
+ (*frame)->session = session;
+
switch_mutex_unlock(session->read_codec->mutex);
switch_mutex_unlock(session->codec_read_mutex);
@@ -610,9 +608,8 @@
}
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)) {
if (session->write_impl.codec_id == frame->codec->implementation->codec_id ||
session->write_impl.microseconds_per_packet != frame->codec->implementation->microseconds_per_packet) {
@@ -661,8 +658,8 @@
frame->datalen,
session->write_impl.actual_samples_per_second,
session->raw_write_frame.data, &session->raw_write_frame.datalen, &session->raw_write_frame.rate, &flag);
-
-
+
+
if (do_resample && status == SWITCH_STATUS_SUCCESS) {
@@ -682,6 +679,7 @@
session->write_impl.decoded_bytes_per_packet,
SWITCH_RESAMPLE_QUALITY);
+
switch_mutex_unlock(session->resample_mutex);
if (status != SWITCH_STATUS_SUCCESS) {
goto done;
@@ -725,19 +723,31 @@
}
}
+
+
if (session->write_resampler) {
short *data = write_frame->data;
switch_mutex_lock(session->resample_mutex);
- switch_resample_process(session->write_resampler, data, write_frame->datalen / 2);
- memcpy(data, session->write_resampler->to, session->write_resampler->to_len * 2);
- write_frame->samples = session->write_resampler->to_len;
- write_frame->datalen = write_frame->samples * 2;
- write_frame->rate = session->write_resampler->to_rate;
- did_write_resample = 1;
+ if (session->write_resampler) {
+
+ switch_resample_process(session->write_resampler, data, write_frame->datalen / 2);
+
+ memcpy(data, session->write_resampler->to, session->write_resampler->to_len * 2);
+
+ write_frame->samples = session->write_resampler->to_len;
+
+ write_frame->datalen = write_frame->samples * 2;
+
+ write_frame->rate = session->write_resampler->to_rate;
+
+ did_write_resample = 1;
+ }
switch_mutex_unlock(session->resample_mutex);
}
+
+
if (session->bugs && !switch_channel_test_flag(session->channel, CF_PAUSE_BUGS)) {
switch_media_bug_t *bp, *dp, *last = NULL;
@@ -804,7 +814,9 @@
write_frame->codec->implementation->decoded_bytes_per_packet == session->write_impl.decoded_bytes_per_packet) {
perfect = TRUE;
}
+
+
if (perfect) {
if (write_frame->datalen < session->write_impl.decoded_bytes_per_packet) {
@@ -822,6 +834,9 @@
session->write_impl.actual_samples_per_second,
session->enc_write_frame.data, &session->enc_write_frame.datalen, &session->enc_write_frame.rate, &flag);
+
+
+
switch (status) {
case SWITCH_STATUS_RESAMPLE:
resample++;
@@ -864,6 +879,7 @@
if (flag & SFF_CNG) {
switch_set_flag(write_frame, SFF_CNG);
}
+
status = perform_write(session, write_frame, flags, stream_id);
goto error;
} else {
@@ -924,6 +940,8 @@
&session->enc_write_frame.rate, &flag);
+
+
switch (status) {
case SWITCH_STATUS_RESAMPLE:
resample++;
@@ -935,14 +953,17 @@
write_frame = &session->enc_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,
- session->write_impl.actual_samples_per_second,
- session->write_impl.decoded_bytes_per_packet,
- SWITCH_RESAMPLE_QUALITY);
-
+ if (!session->write_resampler) {
+ status = switch_resample_create(&session->write_resampler,
+ frame->codec->implementation->actual_samples_per_second,
+ session->write_impl.actual_samples_per_second,
+ session->write_impl.decoded_bytes_per_packet,
+ SWITCH_RESAMPLE_QUALITY);
+ }
switch_mutex_unlock(session->resample_mutex);
+
+
if (status != SWITCH_STATUS_SUCCESS) {
goto done;
}
@@ -959,8 +980,10 @@
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");
+ if (session->write_resampler) {
+ 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);
}
enc_frame->codec = session->write_codec;
@@ -985,11 +1008,13 @@
if (!did_write_resample && session->read_resampler) {
short *data = write_frame->data;
switch_mutex_lock(session->resample_mutex);
- switch_resample_process(session->read_resampler, data, write_frame->datalen / 2);
- memcpy(data, session->read_resampler->to, session->read_resampler->to_len * 2);
- 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;
+ if (session->read_resampler) {
+ switch_resample_process(session->read_resampler, data, write_frame->datalen / 2);
+ memcpy(data, session->read_resampler->to, session->read_resampler->to_len * 2);
+ 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);
}
@@ -1002,9 +1027,7 @@
write_frame->timestamp = 0;
}
- status = perform_write(session, write_frame, flags, stream_id);
-
- if (status != SWITCH_STATUS_SUCCESS) {
+ if ((status = perform_write(session, write_frame, flags, stream_id)) != SWITCH_STATUS_SUCCESS) {
break;
}
}
@@ -1021,12 +1044,18 @@
}
if (do_write) {
+
+
+
status = perform_write(session, write_frame, flags, stream_id);
+
+
}
error:
switch_mutex_unlock(session->write_codec->mutex);
+ switch_mutex_unlock(frame->codec->mutex);
switch_mutex_unlock(session->codec_write_mutex);
return status;
More information about the Freeswitch-svn
mailing list