git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@418 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale committed 2006-01-20 02:02:03 +00:00
1 parent 1e04eb13b5
commit 0ea203849f
43 files changed
+3940 -4103

No files matched your search

@@ -55,7 +55,7 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj)
session_a = data->objs[0];
session_b = data->objs[1];
stream_id_p = data->objs[2];
if (stream_id_p) {
stream_id = *stream_id_p;
@@ -64,16 +64,16 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj)
chan_a = switch_core_session_get_channel(session_a);
chan_b = switch_core_session_get_channel(session_b);
while (data->running > 0) {
while(data->running > 0) {
switch_channel_state b_state = switch_channel_get_state(chan_b);
switch (b_state) {
case CS_HANGUP:
data->running = -1;
continue;
break;
default:
break;
case CS_HANGUP:
data->running = -1;
continue;
break;
default:
break;
}
if (switch_channel_has_dtmf(chan_a)) {
@@ -81,17 +81,16 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj)
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, stream_id) == SWITCH_STATUS_SUCCESS
&& read_frame->datalen) {
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.... Bubye!\n");
data->running = -1;
}
} else {
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "read: Bad Frame.... Bubye!\n");
data->running = -1;
}
}
}
@@ -116,8 +115,7 @@ static switch_status audio_bridge_on_hangup(switch_core_session *session)
other_channel = switch_core_session_get_channel(other_session);
assert(other_channel != NULL);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "CUSTOM HANGUP %s kill %s\n", switch_channel_get_name(channel),
switch_channel_get_name(other_channel));
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "CUSTOM HANGUP %s kill %s\n", switch_channel_get_name(channel), switch_channel_get_name(other_channel));
switch_core_session_kill_channel(other_session, SWITCH_SIG_KILL);
switch_core_session_kill_channel(session, SWITCH_SIG_KILL);
@@ -145,21 +143,21 @@ static switch_status audio_bridge_on_ring(switch_core_session *session)
}
static const switch_event_handler_table audio_bridge_peer_event_handlers = {
/*.on_init */ NULL,
/*.on_ring */ audio_bridge_on_ring,
/*.on_execute */ NULL,
/*.on_hangup */ audio_bridge_on_hangup,
/*.on_loopback */ NULL,
/*.on_transmit */ NULL
/*.on_init*/ NULL,
/*.on_ring*/ audio_bridge_on_ring,
/*.on_execute*/ NULL,
/*.on_hangup*/ audio_bridge_on_hangup,
/*.on_loopback*/ NULL,
/*.on_transmit*/ NULL
};
static const switch_event_handler_table audio_bridge_caller_event_handlers = {
/*.on_init */ NULL,
/*.on_ring */ NULL,
/*.on_execute */ NULL,
/*.on_hangup */ audio_bridge_on_hangup,
/*.on_loopback */ NULL,
/*.on_transmit */ NULL
/*.on_init*/ NULL,
/*.on_ring*/ NULL,
/*.on_execute*/ NULL,
/*.on_hangup*/ audio_bridge_on_hangup,
/*.on_loopback*/ NULL,
/*.on_transmit*/ NULL
};
static void audio_bridge_function(switch_core_session *session, char *data)
@@ -167,8 +165,8 @@ static void audio_bridge_function(switch_core_session *session, char *data)
switch_channel *caller_channel, *peer_channel;
switch_core_session *peer_session;
switch_caller_profile *caller_profile, *caller_caller_profile;
char chan_type[128] = { '\0' }, *chan_data;
int timelimit = 60; /* probably a useful option to pass in when there's time */
char chan_type[128]= {'\0'}, *chan_data;
int timelimit = 60; /* probably a useful option to pass in when there's time */
caller_channel = switch_core_session_get_channel(session);
assert(caller_channel != NULL);
@@ -182,15 +180,17 @@ static void audio_bridge_function(switch_core_session *session, char *data)
caller_caller_profile = switch_channel_get_caller_profile(caller_channel);
caller_profile = switch_caller_profile_new(session,
caller_caller_profile->dialplan,
caller_caller_profile->caller_id_name,
caller_caller_profile->caller_id_number,
caller_caller_profile->network_addr, NULL, NULL, chan_data);
caller_caller_profile->dialplan,
caller_caller_profile->caller_id_name,
caller_caller_profile->caller_id_number,
caller_caller_profile->network_addr,
NULL,
NULL,
chan_data);
if (switch_core_session_outgoing_channel(session, chan_type, caller_profile, &peer_session) !=
SWITCH_STATUS_SUCCESS) {
if (switch_core_session_outgoing_channel(session, chan_type, caller_profile, &peer_session) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "DOH!\n");
switch_channel_hangup(caller_channel);
return;
@@ -215,11 +215,11 @@ static void audio_bridge_function(switch_core_session *session, char *data)
switch_channel_set_private(caller_channel, peer_session);
switch_channel_set_private(peer_channel, session);
switch_channel_set_event_handlers(caller_channel, &audio_bridge_caller_event_handlers);
switch_channel_set_event_handlers(caller_channel, &audio_bridge_caller_event_handlers);
switch_channel_set_event_handlers(peer_channel, &audio_bridge_peer_event_handlers);
switch_core_session_thread_launch(peer_session);
for (;;) {
for(;;) {
int state = switch_channel_get_state(peer_channel);
if (state > CS_RING) {
break;
@@ -228,10 +228,11 @@ static void audio_bridge_function(switch_core_session *session, char *data)
}
time(&start);
while (switch_channel_get_state(caller_channel) == CS_EXECUTE &&
switch_channel_get_state(peer_channel) == CS_TRANSMIT &&
!switch_channel_test_flag(peer_channel, CF_ANSWERED) && ((time(NULL) - start) < timelimit)) {
switch_yield(20000);
while(switch_channel_get_state(caller_channel) == CS_EXECUTE &&
switch_channel_get_state(peer_channel) == CS_TRANSMIT &&
!switch_channel_test_flag(peer_channel, CF_ANSWERED) &&
((time(NULL) - start) < timelimit)) {
switch_yield(20000);
}
if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
@@ -258,22 +259,21 @@ static void audio_bridge_function(switch_core_session *session, char *data)
static const switch_application_interface bridge_application_interface = {
/*.interface_name */ "bridge",
/*.application_function */ audio_bridge_function
/*.interface_name*/ "bridge",
/*.application_function*/ audio_bridge_function
};
static const switch_loadable_module_interface mod_bridgecall_module_interface = {
/*.module_name = */ modname,
/*.endpoint_interface = */ NULL,
/*.timer_interface = */ NULL,
/*.dialplan_interface = */ NULL,
/*.codec_interface = */ NULL,
/*.application_interface */ &bridge_application_interface
/*.module_name = */ modname,
/*.endpoint_interface = */ NULL,
/*.timer_interface = */ NULL,
/*.dialplan_interface = */ NULL,
/*.codec_interface = */ NULL,
/*.application_interface*/ &bridge_application_interface
};
SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename)
{
SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) {
/* connect my internal structure to the blank pointer passed to me */
*interface = &mod_bridgecall_module_interface;
@@ -59,11 +59,11 @@ void playback_function(switch_core_session *session, char *data)
assert(channel != NULL);
if (switch_core_file_open(&fh,
data,
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel);
return;
data,
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel);
return;
}
switch_channel_answer(channel);
@@ -81,17 +81,17 @@ void playback_function(switch_core_session *session, char *data)
codec_name = "L16";
if (switch_core_codec_init(&codec,
codec_name,
fh.samplerate,
interval,
fh.channels,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL, pool) == SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n");
write_frame.codec = &codec;
codec_name,
fh.samplerate,
interval,
fh.channels,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL,
pool) == SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n");
write_frame.codec = &codec;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activation Failed %s@%dhz %d channels %dms\n",
codec_name, fh.samplerate, fh.channels, interval);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activation Failed %s@%dhz %d channels %dms\n", codec_name, fh.samplerate, fh.channels, interval);
switch_core_file_close(&fh);
switch_channel_hangup(channel);
return;
@@ -108,11 +108,11 @@ 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 */
for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
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) {
while(switch_channel_get_state(channel) == CS_EXECUTE) {
int done = 0;
if (switch_channel_has_dtmf(channel)) {
@@ -139,12 +139,12 @@ void playback_function(switch_core_session *session, char *data)
}
write_frame.datalen = ilen * 2;
write_frame.samples = (int) ilen;
write_frame.samples = (int)ilen;
#ifdef SWAP_LINEAR
switch_swap_linear(write_frame.data, (int) write_frame.datalen / 2);
switch_swap_linear(write_frame.data, (int)write_frame.datalen / 2);
#endif
for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
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;
@@ -178,21 +178,20 @@ void playback_function(switch_core_session *session, char *data)
}
static const switch_application_interface playback_application_interface = {
/*.interface_name */ "playback",
/*.application_function */ playback_function
/*.interface_name*/ "playback",
/*.application_function*/ playback_function
};
static const switch_loadable_module_interface mod_playback_module_interface = {
/*.module_name = */ modname,
/*.endpoint_interface = */ NULL,
/*.timer_interface = */ NULL,
/*.dialplan_interface = */ NULL,
/*.codec_interface = */ NULL,
/*.application_interface */ &playback_application_interface
/*.module_name = */ modname,
/*.endpoint_interface = */ NULL,
/*.timer_interface = */ NULL,
/*.dialplan_interface = */ NULL,
/*.codec_interface = */ NULL,
/*.application_interface*/ &playback_application_interface
};
SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename)
{
SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) {
/* connect my internal structure to the blank pointer passed to me */
*interface = &mod_playback_module_interface;
@@ -208,3 +207,7 @@ if it returns anything but SWITCH_STATUS_TERM it will be called again automaticl
//switch_status switch_module_runtime(void)
+8 -8
View File
@@ -34,16 +34,15 @@
static const char modname[] = "mod_skel";
static switch_loadable_module_interface skel_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ NULL,
/*.application_interface */ NULL
/*.module_name*/ modname,
/*.endpoint_interface*/ NULL,
/*.timer_interface*/ NULL,
/*.dialplan_interface*/ NULL,
/*.codec_interface*/ NULL,
/*.application_interface*/ NULL
};
switch_status switch_module_load(switch_loadable_module_interface **interface, char *filename)
{
switch_status switch_module_load(switch_loadable_module_interface **interface, char *filename) {
/* connect my internal structure to the blank pointer passed to me */
*interface = &skel_module_interface;
@@ -52,3 +51,4 @@ switch_status switch_module_load(switch_loadable_module_interface **interface, c
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}