inter session communication goodies

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@309 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2006-01-09 19:48:20 +00:00
1 parent 73b4b25b15
commit 061c1ecb1b
6 files changed
+140 -10

No files matched your search

@@ -46,6 +46,8 @@ struct audio_bridge_data {
static void *audio_bridge_thread(switch_thread *thread, void *obj)
{
struct switch_core_thread_session *data = obj;
int *stream_id_p;
int stream_id = *stream_id_p;
switch_channel *chan_a, *chan_b;
switch_frame *read_frame;
@@ -53,6 +55,8 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj)
session_a = data->objs[0];
session_b = data->objs[1];
stream_id = data->objs[2];
chan_a = switch_core_session_get_channel(session_a);
chan_b = switch_core_session_get_channel(session_b);
@@ -74,8 +78,9 @@ default:
switch_channel_dequeue_dtmf(chan_a, dtmf, sizeof(dtmf));
switch_core_session_send_dtmf(session_b, dtmf);
}
if (switch_core_session_read_frame(session_a, &read_frame, -1) == SWITCH_STATUS_SUCCESS && read_frame->datalen) {
if (switch_core_session_write_frame(session_b, read_frame, -1) != SWITCH_STATUS_SUCCESS) {
if (switch_core_session_read_frame(session_a, &read_frame, -1, stream_id) == SWITCH_STATUS_SUCCESS && read_frame->datalen) {
if (switch_core_session_write_frame(session_b, read_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "write: Bad Frame.... %d Bubye!\n", read_frame->datalen);
data->running = -1;
}
@@ -83,6 +88,7 @@ default:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "read: Bad Frame.... %d Bubye!\n", read_frame->datalen);
data->running = -1;
}
}
switch_channel_hangup(chan_b);
@@ -188,16 +194,19 @@ static void audio_bridge_function(switch_core_session *session, char *data)
} else {
struct switch_core_thread_session this_audio_thread, other_audio_thread;
time_t start;
int stream_id = 0;
peer_channel = switch_core_session_get_channel(peer_session);
memset(&other_audio_thread, 0, sizeof(other_audio_thread));
memset(&this_audio_thread, 0, sizeof(this_audio_thread));
other_audio_thread.objs[0] = session;
other_audio_thread.objs[1] = peer_session;
other_audio_thread.objs[2] = &stream_id;
other_audio_thread.running = 5;
this_audio_thread.objs[0] = peer_session;
this_audio_thread.objs[1] = session;
this_audio_thread.objs[2] = &stream_id;
this_audio_thread.running = 2;
@@ -53,6 +53,7 @@ void playback_function(switch_core_session *session, char *data)
switch_file_handle fh;
char *codec_name;
int x;
int stream_id;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
@@ -107,7 +108,9 @@ void playback_function(switch_core_session *session, char *data)
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer success %d bytes per %d ms!\n", len, interval);
/* start a thread to absorb incoming audio */
switch_core_service_session(session, &thread_session);
for(stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
switch_core_service_session(session, &thread_session, stream_id);
}
ilen = samples;
while(switch_channel_get_state(channel) == CS_EXECUTE) {
int done = 0;
@@ -140,9 +143,17 @@ void playback_function(switch_core_session *session, char *data)
#ifdef SWAP_LINEAR
switch_swap_linear(write_frame.data, (int)write_frame.datalen / 2);
#endif
if (switch_core_session_write_frame(session, &write_frame, -1) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Bad Write\n");
break;
for(stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
if (switch_core_session_write_frame(session, &write_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Bad Write\n");
done = 1;
break;
}
if (done) {
break;
}
}
if ((x = switch_core_timer_next(&timer)) < 0) {