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;
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)) {
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;
- }
+ }
}
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);
}
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)
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);
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;
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;
}
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)) {
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;
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);
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;
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)) {
}
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;
}
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;
//switch_status switch_module_runtime(void)
-
-
-
-
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;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
-
*/
#define SIGN_BIT (0x80) /* Sign bit for a A-law byte. */
#define QUANT_MASK (0xf) /* Quantization field mask. */
-#define NSEGS (8) /* Number of A-law segments. */
-#define SEG_SHIFT (4) /* Left shift for segment number. */
+#define NSEGS (8) /* Number of A-law segments. */
+#define SEG_SHIFT (4) /* Left shift for segment number. */
#define SEG_MASK (0x70) /* Segment field mask. */
-static short seg_aend[8] = {0x1F, 0x3F, 0x7F, 0xFF,
- 0x1FF, 0x3FF, 0x7FF, 0xFFF};
-static short seg_uend[8] = {0x3F, 0x7F, 0xFF, 0x1FF,
- 0x3FF, 0x7FF, 0xFFF, 0x1FFF};
+static short seg_aend[8] = { 0x1F, 0x3F, 0x7F, 0xFF,
+ 0x1FF, 0x3FF, 0x7FF, 0xFFF
+};
+static short seg_uend[8] = { 0x3F, 0x7F, 0xFF, 0x1FF,
+ 0x3FF, 0x7FF, 0xFFF, 0x1FFF
+};
/* copy from CCITT G.711 specifications */
-unsigned char _u2a[128] = { /* u- to A-law conversions */
- 1, 1, 2, 2, 3, 3, 4, 4,
- 5, 5, 6, 6, 7, 7, 8, 8,
- 9, 10, 11, 12, 13, 14, 15, 16,
- 17, 18, 19, 20, 21, 22, 23, 24,
- 25, 27, 29, 31, 33, 34, 35, 36,
- 37, 38, 39, 40, 41, 42, 43, 44,
- 46, 48, 49, 50, 51, 52, 53, 54,
- 55, 56, 57, 58, 59, 60, 61, 62,
- 64, 65, 66, 67, 68, 69, 70, 71,
- 72, 73, 74, 75, 76, 77, 78, 79,
+unsigned char _u2a[128] = { /* u- to A-law conversions */
+ 1, 1, 2, 2, 3, 3, 4, 4,
+ 5, 5, 6, 6, 7, 7, 8, 8,
+ 9, 10, 11, 12, 13, 14, 15, 16,
+ 17, 18, 19, 20, 21, 22, 23, 24,
+ 25, 27, 29, 31, 33, 34, 35, 36,
+ 37, 38, 39, 40, 41, 42, 43, 44,
+ 46, 48, 49, 50, 51, 52, 53, 54,
+ 55, 56, 57, 58, 59, 60, 61, 62,
+ 64, 65, 66, 67, 68, 69, 70, 71,
+ 72, 73, 74, 75, 76, 77, 78, 79,
/* corrected:
81, 82, 83, 84, 85, 86, 87, 88,
should be: */
- 80, 82, 83, 84, 85, 86, 87, 88,
- 89, 90, 91, 92, 93, 94, 95, 96,
- 97, 98, 99, 100, 101, 102, 103, 104,
- 105, 106, 107, 108, 109, 110, 111, 112,
- 113, 114, 115, 116, 117, 118, 119, 120,
- 121, 122, 123, 124, 125, 126, 127, 128};
+ 80, 82, 83, 84, 85, 86, 87, 88,
+ 89, 90, 91, 92, 93, 94, 95, 96,
+ 97, 98, 99, 100, 101, 102, 103, 104,
+ 105, 106, 107, 108, 109, 110, 111, 112,
+ 113, 114, 115, 116, 117, 118, 119, 120,
+ 121, 122, 123, 124, 125, 126, 127, 128
+};
-unsigned char _a2u[128] = { /* A- to u-law conversions */
- 1, 3, 5, 7, 9, 11, 13, 15,
- 16, 17, 18, 19, 20, 21, 22, 23,
- 24, 25, 26, 27, 28, 29, 30, 31,
- 32, 32, 33, 33, 34, 34, 35, 35,
- 36, 37, 38, 39, 40, 41, 42, 43,
- 44, 45, 46, 47, 48, 48, 49, 49,
- 50, 51, 52, 53, 54, 55, 56, 57,
- 58, 59, 60, 61, 62, 63, 64, 64,
- 65, 66, 67, 68, 69, 70, 71, 72,
+unsigned char _a2u[128] = { /* A- to u-law conversions */
+ 1, 3, 5, 7, 9, 11, 13, 15,
+ 16, 17, 18, 19, 20, 21, 22, 23,
+ 24, 25, 26, 27, 28, 29, 30, 31,
+ 32, 32, 33, 33, 34, 34, 35, 35,
+ 36, 37, 38, 39, 40, 41, 42, 43,
+ 44, 45, 46, 47, 48, 48, 49, 49,
+ 50, 51, 52, 53, 54, 55, 56, 57,
+ 58, 59, 60, 61, 62, 63, 64, 64,
+ 65, 66, 67, 68, 69, 70, 71, 72,
/* corrected:
73, 74, 75, 76, 77, 78, 79, 79,
should be: */
- 73, 74, 75, 76, 77, 78, 79, 80,
- 80, 81, 82, 83, 84, 85, 86, 87,
- 88, 89, 90, 91, 92, 93, 94, 95,
- 96, 97, 98, 99, 100, 101, 102, 103,
- 104, 105, 106, 107, 108, 109, 110, 111,
- 112, 113, 114, 115, 116, 117, 118, 119,
- 120, 121, 122, 123, 124, 125, 126, 127};
+ 73, 74, 75, 76, 77, 78, 79, 80,
+ 80, 81, 82, 83, 84, 85, 86, 87,
+ 88, 89, 90, 91, 92, 93, 94, 95,
+ 96, 97, 98, 99, 100, 101, 102, 103,
+ 104, 105, 106, 107, 108, 109, 110, 111,
+ 112, 113, 114, 115, 116, 117, 118, 119,
+ 120, 121, 122, 123, 124, 125, 126, 127
+};
-static short search(
- short val,
- short *table,
- short size)
+static short search(short val, short *table, short size)
{
- short i;
-
- for (i = 0; i < size; i++) {
- if (val <= *table++)
- return (i);
- }
- return (size);
+ short i;
+
+ for (i = 0; i < size; i++) {
+ if (val <= *table++)
+ return (i);
+ }
+ return (size);
}
/*
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley & Sons, pps 98-111 and 472-476.
*/
-unsigned char
-linear2alaw(short pcm_val) /* 2's complement (16-bit range) */
-{
- short mask;
- short seg;
- unsigned char aval;
-
- pcm_val = pcm_val >> 3;
+unsigned char linear2alaw(short pcm_val)
+{ /* 2's complement (16-bit range) */
+ short mask;
+ short seg;
+ unsigned char aval;
+
+ pcm_val = pcm_val >> 3;
+
+ if (pcm_val >= 0) {
+ mask = 0xD5; /* sign (7th) bit = 1 */
+ } else {
+ mask = 0x55; /* sign bit = 0 */
+ pcm_val = -pcm_val - 1;
+ }
- if (pcm_val >= 0) {
- mask = 0xD5; /* sign (7th) bit = 1 */
- } else {
- mask = 0x55; /* sign bit = 0 */
- pcm_val = -pcm_val - 1;
- }
-
- /* Convert the scaled magnitude to segment number. */
- seg = search(pcm_val, seg_aend, 8);
-
- /* Combine the sign, segment, and quantization bits. */
-
- if (seg >= 8) /* out of range, return maximum value. */
- return (unsigned char) (0x7F ^ mask);
- else {
- aval = (unsigned char) seg << SEG_SHIFT;
- if (seg < 2)
- aval |= (pcm_val >> 1) & QUANT_MASK;
- else
- aval |= (pcm_val >> seg) & QUANT_MASK;
- return (aval ^ mask);
- }
+ /* Convert the scaled magnitude to segment number. */
+ seg = search(pcm_val, seg_aend, 8);
+
+ /* Combine the sign, segment, and quantization bits. */
+
+ if (seg >= 8) /* out of range, return maximum value. */
+ return (unsigned char) (0x7F ^ mask);
+ else {
+ aval = (unsigned char) seg << SEG_SHIFT;
+ if (seg < 2)
+ aval |= (pcm_val >> 1) & QUANT_MASK;
+ else
+ aval |= (pcm_val >> seg) & QUANT_MASK;
+ return (aval ^ mask);
+ }
}
/*
* alaw2linear() - Convert an A-law value to 16-bit linear PCM
*
*/
-short
-alaw2linear(
- unsigned char a_val)
+short alaw2linear(unsigned char a_val)
{
- short t;
- short seg;
-
- a_val ^= 0x55;
-
- t = (a_val & QUANT_MASK) << 4;
- seg = ((unsigned)a_val & SEG_MASK) >> SEG_SHIFT;
- switch (seg) {
- case 0:
- t += 8;
- break;
- case 1:
- t += 0x108;
- break;
- default:
- t += 0x108;
- t <<= seg - 1;
- }
- return ((a_val & SIGN_BIT) ? t : -t);
+ short t;
+ short seg;
+
+ a_val ^= 0x55;
+
+ t = (a_val & QUANT_MASK) << 4;
+ seg = ((unsigned) a_val & SEG_MASK) >> SEG_SHIFT;
+ switch (seg) {
+ case 0:
+ t += 8;
+ break;
+ case 1:
+ t += 0x108;
+ break;
+ default:
+ t += 0x108;
+ t <<= seg - 1;
+ }
+ return ((a_val & SIGN_BIT) ? t : -t);
}
#define BIAS (0x84) /* Bias for linear code. */
* For further information see John C. Bellamy's Digital Telephony, 1982,
* John Wiley & Sons, pps 98-111 and 472-476.
*/
-unsigned char
-linear2ulaw(
- short pcm_val) /* 2's complement (16-bit range) */
-{
- short mask;
- short seg;
- unsigned char uval;
-
- /* Get the sign and the magnitude of the value. */
- pcm_val = pcm_val >> 2;
- if (pcm_val < 0) {
- pcm_val = -pcm_val;
- mask = 0x7F;
- } else {
- mask = 0xFF;
- }
- if ( pcm_val > CLIP ) pcm_val = CLIP; /* clip the magnitude */
- pcm_val += (BIAS >> 2);
-
- /* Convert the scaled magnitude to segment number. */
- seg = search(pcm_val, seg_uend, 8);
-
- /*
- * Combine the sign, segment, quantization bits;
- * and complement the code word.
- */
- if (seg >= 8) /* out of range, return maximum value. */
- return (unsigned char) (0x7F ^ mask);
- else {
- uval = (unsigned char) (seg << 4) | ((pcm_val >> (seg + 1)) & 0xF);
- return (uval ^ mask);
- }
-
+unsigned char linear2ulaw(short pcm_val)
+{ /* 2's complement (16-bit range) */
+ short mask;
+ short seg;
+ unsigned char uval;
+
+ /* Get the sign and the magnitude of the value. */
+ pcm_val = pcm_val >> 2;
+ if (pcm_val < 0) {
+ pcm_val = -pcm_val;
+ mask = 0x7F;
+ } else {
+ mask = 0xFF;
+ }
+ if (pcm_val > CLIP)
+ pcm_val = CLIP; /* clip the magnitude */
+ pcm_val += (BIAS >> 2);
+
+ /* Convert the scaled magnitude to segment number. */
+ seg = search(pcm_val, seg_uend, 8);
+
+ /*
+ * Combine the sign, segment, quantization bits;
+ * and complement the code word.
+ */
+ if (seg >= 8) /* out of range, return maximum value. */
+ return (unsigned char) (0x7F ^ mask);
+ else {
+ uval = (unsigned char) (seg << 4) | ((pcm_val >> (seg + 1)) & 0xF);
+ return (uval ^ mask);
+ }
+
}
/*
* Note that this function expects to be passed the complement of the
* original code word. This is in keeping with ISDN conventions.
*/
-short
-ulaw2linear(
- unsigned char u_val)
+short ulaw2linear(unsigned char u_val)
{
- short t;
-
- /* Complement to obtain normal u-law value. */
- u_val = ~u_val;
-
- /*
- * Extract and bias the quantization bits. Then
- * shift up by the segment number and subtract out the bias.
- */
- t = ((u_val & QUANT_MASK) << 3) + BIAS;
- t <<= ((unsigned)u_val & SEG_MASK) >> SEG_SHIFT;
-
- return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS));
+ short t;
+
+ /* Complement to obtain normal u-law value. */
+ u_val = ~u_val;
+
+ /*
+ * Extract and bias the quantization bits. Then
+ * shift up by the segment number and subtract out the bias.
+ */
+ t = ((u_val & QUANT_MASK) << 3) + BIAS;
+ t <<= ((unsigned) u_val & SEG_MASK) >> SEG_SHIFT;
+
+ return ((u_val & SIGN_BIT) ? (BIAS - t) : (t - BIAS));
}
/* A-law to u-law conversion */
-unsigned char
-alaw2ulaw(
- unsigned char aval)
+unsigned char alaw2ulaw(unsigned char aval)
{
- aval &= 0xff;
- return (unsigned char) ((aval & 0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) :
- (0x7F ^ _a2u[aval ^ 0x55]));
+ aval &= 0xff;
+ return (unsigned char) ((aval & 0x80) ? (0xFF ^ _a2u[aval ^ 0xD5]) : (0x7F ^ _a2u[aval ^ 0x55]));
}
/* u-law to A-law conversion */
-unsigned char
-ulaw2alaw(
- unsigned char uval)
+unsigned char ulaw2alaw(unsigned char uval)
{
- uval &= 0xff;
- return (unsigned char) ((uval & 0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) :
- (0x55 ^ (_u2a[0x7F ^ uval] - 1)));
+ uval &= 0xff;
+ return (unsigned char) ((uval & 0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) : (0x55 ^ (_u2a[0x7F ^ uval] - 1)));
}
/* ---------- end of g711.c ----------------------------------------------------- */
static const char modname[] = "mod_g711codec";
-static switch_status switch_g711u_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings)
+static switch_status switch_g711u_init(switch_codec *codec, switch_codec_flag flags,
+ const struct switch_codec_settings *codec_settings)
{
int encoding, decoding;
size_t decoded_data_len,
int decoded_rate,
void *encoded_data,
- size_t *encoded_data_len,
- int *encoded_rate,
- unsigned int *flag)
+ size_t *encoded_data_len, int *encoded_rate, unsigned int *flag)
{
short *dbuf;
unsigned char *ebuf;
size_t encoded_data_len,
int encoded_rate,
void *decoded_data,
- size_t *decoded_data_len,
- int *decoded_rate,
- unsigned int *flag)
+ size_t *decoded_data_len, int *decoded_rate, unsigned int *flag)
{
short *dbuf;
unsigned char *ebuf;
}
-static switch_status switch_g711a_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings)
+static switch_status switch_g711a_init(switch_codec *codec, switch_codec_flag flags,
+ const struct switch_codec_settings *codec_settings)
{
int encoding, decoding;
size_t decoded_data_len,
int decoded_rate,
void *encoded_data,
- size_t *encoded_data_len,
- int *encoded_rate,
- unsigned int *flag)
+ size_t *encoded_data_len, int *encoded_rate, unsigned int *flag)
{
short *dbuf;
unsigned char *ebuf;
size_t encoded_data_len,
int encoded_rate,
void *decoded_data,
- size_t *decoded_data_len,
- int *decoded_rate,
- unsigned int *flag)
+ size_t *decoded_data_len, int *decoded_rate, unsigned int *flag)
{
short *dbuf;
unsigned char *ebuf;
static const switch_codec_implementation g711u_8k_60ms_implementation = {
- /*.samples_per_second*/ 8000,
- /*.bits_per_second*/ 19200,
- /*.microseconds_per_frame*/ 60000,
- /*.samples_per_frame*/ 480,
- /*.bytes_per_frame*/ 960,
- /*.encoded_bytes_per_frame*/ 480,
- /*.number_of_channels*/ 1,
- /*.pref_frames_per_packet*/ 1,
- /*.max_frames_per_packet*/ 1,
- /*.init*/ switch_g711u_init,
- /*.encode*/ switch_g711u_encode,
- /*.decode*/ switch_g711u_decode,
- /*.destroy*/ switch_g711u_destroy
+ /*.samples_per_second */ 8000,
+ /*.bits_per_second */ 19200,
+ /*.microseconds_per_frame */ 60000,
+ /*.samples_per_frame */ 480,
+ /*.bytes_per_frame */ 960,
+ /*.encoded_bytes_per_frame */ 480,
+ /*.number_of_channels */ 1,
+ /*.pref_frames_per_packet */ 1,
+ /*.max_frames_per_packet */ 1,
+ /*.init */ switch_g711u_init,
+ /*.encode */ switch_g711u_encode,
+ /*.decode */ switch_g711u_decode,
+ /*.destroy */ switch_g711u_destroy
};
static const switch_codec_implementation g711u_8k_30ms_implementation = {
- /*.samples_per_second*/ 8000,
- /*.bits_per_second*/ 96000,
- /*.microseconds_per_frame*/ 30000,
- /*.samples_per_frame*/ 240,
- /*.bytes_per_frame*/ 480,
- /*.encoded_bytes_per_frame*/ 240,
- /*.number_of_channels*/ 1,
- /*.pref_frames_per_packet*/ 1,
- /*.max_frames_per_packet*/ 1,
- /*.init*/ switch_g711u_init,
- /*.encode*/ switch_g711u_encode,
- /*.decode*/ switch_g711u_decode,
- /*.destroy*/ switch_g711u_destroy,
- /*.next*/ &g711u_8k_60ms_implementation
+ /*.samples_per_second */ 8000,
+ /*.bits_per_second */ 96000,
+ /*.microseconds_per_frame */ 30000,
+ /*.samples_per_frame */ 240,
+ /*.bytes_per_frame */ 480,
+ /*.encoded_bytes_per_frame */ 240,
+ /*.number_of_channels */ 1,
+ /*.pref_frames_per_packet */ 1,
+ /*.max_frames_per_packet */ 1,
+ /*.init */ switch_g711u_init,
+ /*.encode */ switch_g711u_encode,
+ /*.decode */ switch_g711u_decode,
+ /*.destroy */ switch_g711u_destroy,
+ /*.next */ &g711u_8k_60ms_implementation
};
static const switch_codec_implementation g711u_16k_implementation = {
- /*.samples_per_second*/ 16000,
- /*.bits_per_second*/ 128000,
- /*.microseconds_per_frame*/ 20000,
- /*.samples_per_frame*/ 320,
- /*.bytes_per_frame*/ 640,
- /*.encoded_bytes_per_frame*/ 320,
- /*.number_of_channels*/ 1,
- /*.pref_frames_per_packet*/ 1,
- /*.max_frames_per_packet*/ 1,
- /*.init*/ switch_g711u_init,
- /*.encode*/ switch_g711u_encode,
- /*.decode*/ switch_g711u_decode,
- /*.destroy*/ switch_g711u_destroy,
+ /*.samples_per_second */ 16000,
+ /*.bits_per_second */ 128000,
+ /*.microseconds_per_frame */ 20000,
+ /*.samples_per_frame */ 320,
+ /*.bytes_per_frame */ 640,
+ /*.encoded_bytes_per_frame */ 320,
+ /*.number_of_channels */ 1,
+ /*.pref_frames_per_packet */ 1,
+ /*.max_frames_per_packet */ 1,
+ /*.init */ switch_g711u_init,
+ /*.encode */ switch_g711u_encode,
+ /*.decode */ switch_g711u_decode,
+ /*.destroy */ switch_g711u_destroy,
};
static const switch_codec_implementation g711u_8k_implementation = {
- /*.samples_per_second*/ 8000,
- /*.bits_per_second*/ 64000,
- /*.microseconds_per_frame*/ 20000,
- /*.samples_per_frame*/ 160,
- /*.bytes_per_frame*/ 320,
- /*.encoded_bytes_per_frame*/ 160,
- /*.number_of_channels*/ 1,
- /*.pref_frames_per_packet*/ 1,
- /*.max_frames_per_packet*/ 1,
- /*.init*/ switch_g711u_init,
- /*.encode*/ switch_g711u_encode,
- /*.decode*/ switch_g711u_decode,
- /*.destroy*/ switch_g711u_destroy,
- /*.next*/ &g711u_16k_implementation
+ /*.samples_per_second */ 8000,
+ /*.bits_per_second */ 64000,
+ /*.microseconds_per_frame */ 20000,
+ /*.samples_per_frame */ 160,
+ /*.bytes_per_frame */ 320,
+ /*.encoded_bytes_per_frame */ 160,
+ /*.number_of_channels */ 1,
+ /*.pref_frames_per_packet */ 1,
+ /*.max_frames_per_packet */ 1,
+ /*.init */ switch_g711u_init,
+ /*.encode */ switch_g711u_encode,
+ /*.decode */ switch_g711u_decode,
+ /*.destroy */ switch_g711u_destroy,
+ /*.next */ &g711u_16k_implementation
};
static const switch_codec_implementation g711a_8k_implementation = {
- /*.samples_per_second*/ 8000,
- /*.bits_per_second*/ 64000,
- /*.microseconds_per_frame*/ 20000,
- /*.samples_per_frame*/ 160,
- /*.bytes_per_frame*/ 320,
- /*.encoded_bytes_per_frame*/ 160,
- /*.number_of_channels*/ 1,
- /*.pref_frames_per_packet*/ 1,
- /*.max_frames_per_packet*/ 1,
- /*.init*/ switch_g711a_init,
- /*.encode*/ switch_g711a_encode,
- /*.decode*/ switch_g711a_decode,
- /*.destroy*/ switch_g711a_destroy
+ /*.samples_per_second */ 8000,
+ /*.bits_per_second */ 64000,
+ /*.microseconds_per_frame */ 20000,
+ /*.samples_per_frame */ 160,
+ /*.bytes_per_frame */ 320,
+ /*.encoded_bytes_per_frame */ 160,
+ /*.number_of_channels */ 1,
+ /*.pref_frames_per_packet */ 1,
+ /*.max_frames_per_packet */ 1,
+ /*.init */ switch_g711a_init,
+ /*.encode */ switch_g711a_encode,
+ /*.decode */ switch_g711a_decode,
+ /*.destroy */ switch_g711a_destroy
};
static const switch_codec_interface g711a_codec_interface = {
- /*.interface_name*/ "g711 alaw",
- /*.codec_type*/ SWITCH_CODEC_TYPE_AUDIO,
- /*.ianacode*/ 8,
- /*.iananame*/ "PCMA",
- /*.implementations*/ &g711a_8k_implementation
+ /*.interface_name */ "g711 alaw",
+ /*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+ /*.ianacode */ 8,
+ /*.iananame */ "PCMA",
+ /*.implementations */ &g711a_8k_implementation
};
static const switch_codec_interface g711u_codec_interface = {
- /*.interface_name*/ "g711 ulaw",
- /*.codec_type*/ SWITCH_CODEC_TYPE_AUDIO,
- /*.ianacode*/ 0,
- /*.iananame*/ "PCMU",
- /*.implementations*/ &g711u_8k_implementation,
- /*.next*/ &g711a_codec_interface
+ /*.interface_name */ "g711 ulaw",
+ /*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+ /*.ianacode */ 0,
+ /*.iananame */ "PCMU",
+ /*.implementations */ &g711u_8k_implementation,
+ /*.next */ &g711a_codec_interface
};
static switch_loadable_module_interface g711_module_interface = {
- /*.module_name*/ modname,
- /*.endpoint_interface*/ NULL,
- /*.timer_interface*/ NULL,
- /*.dialplan_interface*/ NULL,
- /*.codec_interface*/ &g711u_codec_interface,
- /*.application_interface*/ NULL
+ /*.module_name */ modname,
+ /*.endpoint_interface */ NULL,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ &g711u_codec_interface,
+ /*.application_interface */ NULL
};
-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 = &g711_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
-
-
-
-
-
*\r
* mod_codec_g729.c -- G729 Codec Module\r
*\r
- */\r
+ */ \r
#include "switch.h"\r
#include "g729.h"\r
-\r
-static const char modname[] = "mod_codec_g729";\r
-\r
-struct g729_context {\r
- struct dec_state decoder_object;\r
- struct cod_state encoder_object;\r
-};\r
-\r
-static switch_status switch_g729_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings)\r
-{\r
- struct g729_context *context = NULL;\r
- int encoding, decoding;\r
-\r
- encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);\r
- decoding = (flags & SWITCH_CODEC_FLAG_DECODE);\r
-\r
- if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct g729_context))))) {\r
- return SWITCH_STATUS_FALSE;\r
- } else {\r
- if (encoding) {\r
- g729_init_coder(&context->encoder_object, 0);\r
- }\r
- if (decoding) {\r
- g729_init_decoder(&context->decoder_object);\r
- }\r
-\r
- codec->private = context;\r
-\r
- return SWITCH_STATUS_SUCCESS;\r
- }\r
-}\r
-\r
-static switch_status switch_g729_destroy(switch_codec *codec)\r
-{\r
- codec->private = NULL;\r
- return SWITCH_STATUS_SUCCESS;\r
-}\r
-\r
-\r
-static switch_status switch_g729_encode(switch_codec *codec,\r
- switch_codec *other_codec,\r
- void *decoded_data,\r
- size_t decoded_data_len,\r
- int decoded_rate,\r
- void *encoded_data,\r
- size_t *encoded_data_len,\r
- int *encoded_rate,\r
- unsigned int *flag)\r
-{\r
- struct g729_context *context = codec->private;\r
- int cbret = 0;\r
-\r
- if (!context) {\r
- return SWITCH_STATUS_FALSE;\r
- }\r
- if (decoded_data_len % 160 == 0) {\r
- unsigned int new_len = 0;\r
- INT16 *ddp = decoded_data;\r
- char *edp = encoded_data;\r
- int x;\r
- int loops = (int) decoded_data_len / 160;\r
-\r
- for(x = 0; x < loops && new_len < *encoded_data_len; x++) {\r
- g729_coder(&context->encoder_object, ddp, edp, &cbret);\r
- edp += 10;\r
- ddp += 80;\r
- new_len += 10;\r
- }\r
- if( new_len <= *encoded_data_len ) {\r
- *encoded_data_len = new_len;\r
- } else {\r
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len);\r
- return SWITCH_STATUS_FALSE; \r
- }\r
- }\r
- return SWITCH_STATUS_SUCCESS;\r
-}\r
-\r
-\r
-static switch_status switch_g729_decode(switch_codec *codec,\r
- switch_codec *other_codec,\r
- void *encoded_data,\r
- size_t encoded_data_len,\r
- int encoded_rate,\r
- void *decoded_data,\r
- size_t *decoded_data_len,\r
- int *decoded_rate,\r
- unsigned int *flag) \r
-{\r
- struct g729_context *context = codec->private;\r
-\r
- if (!context) {\r
- return SWITCH_STATUS_FALSE;\r
- }\r
-\r
-\r
- if (encoded_data_len % 10 == 0) {\r
- int loops = (int) encoded_data_len / 10;\r
- char *edp = encoded_data;\r
- short *ddp = decoded_data;\r
- int x;\r
- unsigned int new_len = 0;\r
- for(x = 0; x < loops && new_len < *decoded_data_len; x++) {\r
- g729_decoder(&context->decoder_object, ddp, edp, 10);\r
- ddp += 80;\r
- edp += 10;\r
- new_len += 160;\r
- }\r
- if (new_len <= *decoded_data_len) {\r
- *decoded_data_len = new_len;\r
- } else {\r
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!!\n");\r
- return SWITCH_STATUS_FALSE;\r
- }\r
- } else {\r
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len);\r
- }\r
-\r
-\r
- return SWITCH_STATUS_SUCCESS;\r
-}\r
-\r
-/* Registration */\r
-\r
-static const switch_codec_implementation g729_8k_implementation = {\r
- /*.samples_per_second*/ 8000,\r
- /*.bits_per_second*/ 64000,\r
- /*.microseconds_per_frame*/ 20000,\r
- /*.samples_per_frame*/ 160,\r
- /*.bytes_per_frame*/ 320,\r
- /*.encoded_bytes_per_frame*/ 20,\r
- /*.number_of_channels*/ 1,\r
- /*.pref_frames_per_packet*/ 1,\r
- /*.max_frames_per_packet*/ 24,\r
- /*.init*/ switch_g729_init,\r
- /*.encode*/ switch_g729_encode,\r
- /*.decode*/ switch_g729_decode,\r
- /*.destroy*/ switch_g729_destroy,\r
-};\r
-\r
-static const switch_codec_interface g729_codec_interface = {\r
- /*.interface_name*/ "g729",\r
- /*.codec_type*/ SWITCH_CODEC_TYPE_AUDIO,\r
- /*.ianacode*/ 18,\r
- /*.iananame*/ "G729",\r
- /*.implementations*/ &g729_8k_implementation,\r
-};\r
-\r
-static switch_loadable_module_interface g729_module_interface = {\r
- /*.module_name*/ modname,\r
- /*.endpoint_interface*/ NULL,\r
- /*.timer_interface*/ NULL,\r
- /*.dialplan_interface*/ NULL,\r
- /*.codec_interface*/ &g729_codec_interface,\r
- /*.application_interface*/ NULL\r
-};\r
-\r
-\r
-SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) {\r
- /* connect my internal structure to the blank pointer passed to me */\r
- *interface = &g729_module_interface;\r
-\r
- /* indicate that the module should continue to be loaded */\r
- return SWITCH_STATUS_SUCCESS;\r
-}\r
-\r
-\r
-\r
-\r
-\r
+\rstatic const char modname[] = "mod_codec_g729";
+\r\rstruct g729_context {
+ \rstruct dec_state decoder_object;
+ \rstruct cod_state encoder_object;
+ \r};
+\r\rstatic switch_status switch_g729_init(switch_codec *codec, switch_codec_flag flags,
+ const struct switch_codec_settings *codec_settings) \r
+{
+ \rstruct g729_context *context = NULL;
+ \rint encoding, decoding;
+ \r\rencoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
+ \rdecoding = (flags & SWITCH_CODEC_FLAG_DECODE);
+ \r\rif (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct g729_context))))) {
+ \rreturn SWITCH_STATUS_FALSE;
+ \r} else {
+ \rif (encoding) {
+ \rg729_init_coder(&context->encoder_object, 0);
+ \r}
+ \rif (decoding) {
+ \rg729_init_decoder(&context->decoder_object);
+ \r}
+ \r\rcodec->private = context;
+ \r\rreturn SWITCH_STATUS_SUCCESS;
+ \r}
+\r}
+\r\rstatic switch_status switch_g729_destroy(switch_codec *codec) \r
+{
+ \rcodec->private = NULL;
+ \rreturn SWITCH_STATUS_SUCCESS;
+\r}
+\r\r\rstatic switch_status switch_g729_encode(switch_codec *codec, \rswitch_codec *other_codec, \rvoid *decoded_data,
+ \rsize_t decoded_data_len, \rint decoded_rate, \rvoid *encoded_data,
+ \rsize_t *encoded_data_len, \rint *encoded_rate, \runsigned int *flag) \r
+{
+ \rstruct g729_context *context = codec->private;
+ \rint cbret = 0;
+ \r\rif (!context) {
+ \rreturn SWITCH_STATUS_FALSE;
+ \r}
+ \rif (decoded_data_len % 160 == 0) {
+ \runsigned int new_len = 0;
+ \rINT16 * ddp = decoded_data;
+ \rchar *edp = encoded_data;
+ \rint x;
+ \rint loops = (int) decoded_data_len / 160;
+ \r\rfor (x = 0; x < loops && new_len < *encoded_data_len; x++) {
+ \rg729_coder(&context->encoder_object, ddp, edp, &cbret);
+ \redp += 10;
+ \rddp += 80;
+ \rnew_len += 10;
+ \r}
+ \rif (new_len <= *encoded_data_len) {
+ \r*encoded_data_len = new_len;
+ \r} else {
+ \rswitch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len);
+ \rreturn SWITCH_STATUS_FALSE;
+ \r}
+ \r}
+ \rreturn SWITCH_STATUS_SUCCESS;
+\r}
+\r\r\rstatic switch_status switch_g729_decode(switch_codec *codec, \rswitch_codec *other_codec, \rvoid *encoded_data,
+ \rsize_t encoded_data_len, \rint encoded_rate, \rvoid *decoded_data,
+ \rsize_t *decoded_data_len, \rint *decoded_rate, \runsigned int *flag) \r
+{
+ \rstruct g729_context *context = codec->private;
+ \r\rif (!context) {
+ \rreturn SWITCH_STATUS_FALSE;
+ \r}
+ \r\r\rif (encoded_data_len % 10 == 0) {
+ \rint loops = (int) encoded_data_len / 10;
+ \rchar *edp = encoded_data;
+ \rshort *ddp = decoded_data;
+ \rint x;
+ \runsigned int new_len = 0;
+ \rfor (x = 0; x < loops && new_len < *decoded_data_len; x++) {
+ \rg729_decoder(&context->decoder_object, ddp, edp, 10);
+ \rddp += 80;
+ \redp += 10;
+ \rnew_len += 160;
+ \r}
+ \rif (new_len <= *decoded_data_len) {
+ \r*decoded_data_len = new_len;
+ \r} else {
+ \rswitch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!!\n");
+ \rreturn SWITCH_STATUS_FALSE;
+ \r}
+ \r} else {
+ \rswitch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len);
+ \r}
+ \r\r\rreturn SWITCH_STATUS_SUCCESS;
+\r}
+
+\r\r
+/* Registration */ \r
+\rstatic const switch_codec_implementation g729_8k_implementation = { \r
+ /*.samples_per_second */ 8000, \r
+ /*.bits_per_second */ 64000, \r
+ /*.microseconds_per_frame */ 20000, \r
+ /*.samples_per_frame */ 160, \r
+ /*.bytes_per_frame */ 320, \r
+ /*.encoded_bytes_per_frame */ 20, \r
+ /*.number_of_channels */ 1, \r
+ /*.pref_frames_per_packet */ 1, \r
+ /*.max_frames_per_packet */ 24, \r
+ /*.init */ switch_g729_init, \r
+ /*.encode */ switch_g729_encode, \r
+ /*.decode */ switch_g729_decode, \r
+ /*.destroy */ switch_g729_destroy, \r
+};
+\r\rstatic const switch_codec_interface g729_codec_interface = { \r
+ /*.interface_name */ "g729", \r
+ /*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, \r
+ /*.ianacode */ 18, \r
+ /*.iananame */ "G729", \r
+ /*.implementations */ &g729_8k_implementation, \r
+};
+\r\rstatic switch_loadable_module_interface g729_module_interface = { \r
+ /*.module_name */ modname, \r
+ /*.endpoint_interface */ NULL, \r
+ /*.timer_interface */ NULL, \r
+ /*.dialplan_interface */ NULL, \r
+ /*.codec_interface */ &g729_codec_interface, \r
+ /*.application_interface */ NULL \r
+};
+\r\r\rSWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface,
+ char *filename)
+{
+ \r
+ /* connect my internal structure to the blank pointer passed to me */ \r
+ *interface = &g729_module_interface;
+ \r\r
+ /* indicate that the module should continue to be loaded */ \r
+ return SWITCH_STATUS_SUCCESS;
+\r}
+
+\r\r\r\r\r\r
*\r
* mod_codec_gsm.c -- gsm Codec Module\r
*\r
- */\r
+ */ \r
#include "switch.h"\r
#include "gsm.h"\r
-\r
-static const char modname[] = "mod_codec_gsm";\r
-\r
-struct gsm_context {\r
- gsm encoder;\r
- gsm decoder;\r
-};\r
-\r
-static switch_status switch_gsm_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings)\r
-{\r
- struct gsm_context *context;\r
- int encoding, decoding;\r
-\r
- encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);\r
- decoding = (flags & SWITCH_CODEC_FLAG_DECODE);\r
-\r
- if (!(encoding || decoding)) {\r
- return SWITCH_STATUS_FALSE;\r
- } else {\r
- context = switch_core_alloc(codec->memory_pool, sizeof(*context));\r
- if (encoding) context->encoder = gsm_create();\r
- if (decoding) context->decoder = gsm_create();\r
- }\r
-\r
- codec->private = context;\r
-\r
- return SWITCH_STATUS_SUCCESS;\r
-\r
-}\r
-\r
-static switch_status switch_gsm_destroy(switch_codec *codec)\r
-{\r
- struct gsm_context *context = codec->private;\r
- int encoding = (codec->flags & SWITCH_CODEC_FLAG_ENCODE);\r
- int decoding = (codec->flags & SWITCH_CODEC_FLAG_DECODE);\r
-\r
- if (encoding) gsm_destroy(context->encoder);\r
- if (decoding) gsm_destroy(context->decoder);\r
-\r
- codec->private = NULL;\r
- return SWITCH_STATUS_SUCCESS;\r
-}\r
-\r
-\r
-static switch_status switch_gsm_encode(switch_codec *codec,\r
- switch_codec *other_codec,\r
- void *decoded_data,\r
- size_t decoded_data_len,\r
- int decoded_rate,\r
- void *encoded_data,\r
- size_t *encoded_data_len,\r
- int *encoded_rate,\r
- unsigned int *flag)\r
-{\r
- struct gsm_context *context = codec->private;\r
- int cbret = 0;\r
-\r
- if (!context) {\r
- return SWITCH_STATUS_FALSE;\r
- }\r
- if (decoded_data_len % 320 == 0) {\r
- unsigned int new_len = 0;\r
- gsm_signal *ddp = decoded_data;\r
- gsm_byte *edp = encoded_data;\r
- int x;\r
- int loops = (int) decoded_data_len / 320;\r
- for(x = 0; x < loops && new_len < *encoded_data_len; x++) {\r
- gsm_encode(context->encoder, ddp, edp);\r
- edp += 33;\r
- ddp += 160;\r
- new_len += 33;\r
- }\r
- if( new_len <= *encoded_data_len ) {\r
- *encoded_data_len = new_len;\r
- } else {\r
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len);\r
- return SWITCH_STATUS_FALSE; \r
- }\r
- }\r
-\r
- return SWITCH_STATUS_SUCCESS;\r
-}\r
-\r
-\r
-static switch_status switch_gsm_decode(switch_codec *codec,\r
- switch_codec *other_codec,\r
- void *encoded_data,\r
- size_t encoded_data_len,\r
- int encoded_rate,\r
- void *decoded_data,\r
- size_t *decoded_data_len,\r
- int *decoded_rate,\r
- unsigned int *flag) \r
-{\r
- struct gsm_context *context = codec->private;\r
-\r
- if (!context) {\r
- return SWITCH_STATUS_FALSE;\r
- }\r
-\r
-\r
- if (encoded_data_len % 33 == 0) {\r
- int loops = (int) encoded_data_len / 33;\r
- gsm_byte *edp = encoded_data;\r
- gsm_signal *ddp = decoded_data;\r
- int x;\r
- unsigned int new_len = 0;\r
- for(x = 0; x < loops && new_len < *decoded_data_len; x++) {\r
- gsm_decode(context->decoder, edp, ddp);\r
- ddp += 160;\r
- edp += 33;\r
- new_len += 320;\r
- }\r
- if (new_len <= *decoded_data_len) {\r
- *decoded_data_len = new_len;\r
- } else {\r
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!!\n");\r
- return SWITCH_STATUS_FALSE;\r
- }\r
- } else {\r
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len);\r
- }\r
-\r
- return SWITCH_STATUS_SUCCESS;\r
-}\r
-\r
-/* Registration */\r
-\r
-static const switch_codec_implementation gsm_8k_implementation = {\r
- /*.samples_per_second*/ 8000,\r
- /*.bits_per_second*/ 13200,\r
- /*.microseconds_per_frame*/ 20000,\r
- /*.samples_per_frame*/ 160,\r
- /*.bytes_per_frame*/ 320,\r
- /*.encoded_bytes_per_frame*/ 33,\r
- /*.number_of_channels*/ 1,\r
- /*.pref_frames_per_packet*/ 1,\r
- /*.max_frames_per_packet*/ 1,\r
- /*.init*/ switch_gsm_init,\r
- /*.encode*/ switch_gsm_encode,\r
- /*.decode*/ switch_gsm_decode,\r
- /*.destroy*/ switch_gsm_destroy,\r
-};\r
-\r
-static const switch_codec_interface gsm_codec_interface = {\r
- /*.interface_name*/ "gsm",\r
- /*.codec_type*/ SWITCH_CODEC_TYPE_AUDIO,\r
- /*.ianacode*/ 3,\r
- /*.iananame*/ "gsm",\r
- /*.implementations*/ &gsm_8k_implementation,\r
-};\r
-\r
-static switch_loadable_module_interface gsm_module_interface = {\r
- /*.module_name*/ modname,\r
- /*.endpoint_interface*/ NULL,\r
- /*.timer_interface*/ NULL,\r
- /*.dialplan_interface*/ NULL,\r
- /*.codec_interface*/ &gsm_codec_interface,\r
- /*.application_interface*/ NULL\r
-};\r
-\r
-\r
-SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) {\r
- /* connect my internal structure to the blank pointer passed to me */\r
- *interface = &gsm_module_interface;\r
-\r
- /* indicate that the module should continue to be loaded */\r
- return SWITCH_STATUS_SUCCESS;\r
-}\r
-\r
-\r
-\r
-\r
-\r
+\rstatic const char modname[] = "mod_codec_gsm";
+\r\rstruct gsm_context {
+ \rgsm encoder;
+ \rgsm decoder;
+\r};
+\r\rstatic switch_status switch_gsm_init(switch_codec *codec, switch_codec_flag flags,
+ const struct switch_codec_settings *codec_settings) \r
+{
+ \rstruct gsm_context *context;
+ \rint encoding, decoding;
+ \r\rencoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
+ \rdecoding = (flags & SWITCH_CODEC_FLAG_DECODE);
+ \r\rif (!(encoding || decoding)) {
+ \rreturn SWITCH_STATUS_FALSE;
+ \r} else {
+ \rcontext = switch_core_alloc(codec->memory_pool, sizeof(*context));
+ \rif (encoding)
+ context->encoder = gsm_create();
+ \rif (decoding)
+ context->decoder = gsm_create();
+ \r}
+ \r\rcodec->private = context;
+ \r\rreturn SWITCH_STATUS_SUCCESS;
+\r\r}
+\r\rstatic switch_status switch_gsm_destroy(switch_codec *codec) \r
+{
+ \rstruct gsm_context *context = codec->private;
+ \rint encoding = (codec->flags & SWITCH_CODEC_FLAG_ENCODE);
+ \rint decoding = (codec->flags & SWITCH_CODEC_FLAG_DECODE);
+ \r\rif (encoding)
+ gsm_destroy(context->encoder);
+ \rif (decoding)
+ gsm_destroy(context->decoder);
+ \r\rcodec->private = NULL;
+ \rreturn SWITCH_STATUS_SUCCESS;
+\r}
+\r\r\rstatic switch_status switch_gsm_encode(switch_codec *codec, \rswitch_codec *other_codec, \rvoid *decoded_data,
+ \rsize_t decoded_data_len, \rint decoded_rate, \rvoid *encoded_data,
+ \rsize_t *encoded_data_len, \rint *encoded_rate, \runsigned int *flag) \r
+{
+ \rstruct gsm_context *context = codec->private;
+ \rint cbret = 0;
+ \r\rif (!context) {
+ \rreturn SWITCH_STATUS_FALSE;
+ \r}
+ \rif (decoded_data_len % 320 == 0) {
+ \runsigned int new_len = 0;
+ \rgsm_signal * ddp = decoded_data;
+ \rgsm_byte * edp = encoded_data;
+ \rint x;
+ \rint loops = (int) decoded_data_len / 320;
+ \rfor (x = 0; x < loops && new_len < *encoded_data_len; x++) {
+ \rgsm_encode(context->encoder, ddp, edp);
+ \redp += 33;
+ \rddp += 160;
+ \rnew_len += 33;
+ \r}
+ \rif (new_len <= *encoded_data_len) {
+ \r*encoded_data_len = new_len;
+ \r} else {
+ \rswitch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len);
+ \rreturn SWITCH_STATUS_FALSE;
+ \r}
+ \r}
+ \r\rreturn SWITCH_STATUS_SUCCESS;
+\r}
+\r\r\rstatic switch_status switch_gsm_decode(switch_codec *codec, \rswitch_codec *other_codec, \rvoid *encoded_data,
+ \rsize_t encoded_data_len, \rint encoded_rate, \rvoid *decoded_data,
+ \rsize_t *decoded_data_len, \rint *decoded_rate, \runsigned int *flag) \r
+{
+ \rstruct gsm_context *context = codec->private;
+ \r\rif (!context) {
+ \rreturn SWITCH_STATUS_FALSE;
+ \r}
+ \r\r\rif (encoded_data_len % 33 == 0) {
+ \rint loops = (int) encoded_data_len / 33;
+ \rgsm_byte * edp = encoded_data;
+ \rgsm_signal * ddp = decoded_data;
+ \rint x;
+ \runsigned int new_len = 0;
+ \rfor (x = 0; x < loops && new_len < *decoded_data_len; x++) {
+ \rgsm_decode(context->decoder, edp, ddp);
+ \rddp += 160;
+ \redp += 33;
+ \rnew_len += 320;
+ \r}
+ \rif (new_len <= *decoded_data_len) {
+ \r*decoded_data_len = new_len;
+ \r} else {
+ \rswitch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!!\n");
+ \rreturn SWITCH_STATUS_FALSE;
+ \r}
+ \r} else {
+ \rswitch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len);
+ \r}
+ \r\rreturn SWITCH_STATUS_SUCCESS;
+\r}
+
+\r\r
+/* Registration */ \r
+\rstatic const switch_codec_implementation gsm_8k_implementation = { \r
+ /*.samples_per_second */ 8000, \r
+ /*.bits_per_second */ 13200, \r
+ /*.microseconds_per_frame */ 20000, \r
+ /*.samples_per_frame */ 160, \r
+ /*.bytes_per_frame */ 320, \r
+ /*.encoded_bytes_per_frame */ 33, \r
+ /*.number_of_channels */ 1, \r
+ /*.pref_frames_per_packet */ 1, \r
+ /*.max_frames_per_packet */ 1, \r
+ /*.init */ switch_gsm_init, \r
+ /*.encode */ switch_gsm_encode, \r
+ /*.decode */ switch_gsm_decode, \r
+ /*.destroy */ switch_gsm_destroy, \r
+};
+\r\rstatic const switch_codec_interface gsm_codec_interface = { \r
+ /*.interface_name */ "gsm", \r
+ /*.codec_type */ SWITCH_CODEC_TYPE_AUDIO, \r
+ /*.ianacode */ 3, \r
+ /*.iananame */ "gsm", \r
+ /*.implementations */ &gsm_8k_implementation, \r
+};
+\r\rstatic switch_loadable_module_interface gsm_module_interface = { \r
+ /*.module_name */ modname, \r
+ /*.endpoint_interface */ NULL, \r
+ /*.timer_interface */ NULL, \r
+ /*.dialplan_interface */ NULL, \r
+ /*.codec_interface */ &gsm_codec_interface, \r
+ /*.application_interface */ NULL \r
+};
+\r\r\rSWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface,
+ char *filename)
+{
+ \r
+ /* connect my internal structure to the blank pointer passed to me */ \r
+ *interface = &gsm_module_interface;
+ \r\r
+ /* indicate that the module should continue to be loaded */ \r
+ return SWITCH_STATUS_SUCCESS;
+\r}
+
+\r\r\r\r\r\r
static const char modname[] = "mod_rawaudio";
-static switch_status switch_raw_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings)
+static switch_status switch_raw_init(switch_codec *codec, switch_codec_flag flags,
+ const struct switch_codec_settings *codec_settings)
{
int encoding, decoding;
struct raw_context *context = NULL;
}
static switch_status switch_raw_encode(switch_codec *codec,
- switch_codec *other_codec,
- void *decoded_data,
- size_t decoded_data_len,
- int decoded_rate,
- void *encoded_data,
- size_t *encoded_data_len,
- int *encoded_rate,
- unsigned int *flag)
+ switch_codec *other_codec,
+ void *decoded_data,
+ size_t decoded_data_len,
+ int decoded_rate,
+ void *encoded_data,
+ size_t *encoded_data_len, int *encoded_rate, unsigned int *flag)
{
- /* NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary.*/
+ /* NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary. */
if (codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
memcpy(encoded_data, decoded_data, decoded_data_len);
*encoded_data_len = decoded_data_len;
}
static switch_status switch_raw_decode(switch_codec *codec,
- switch_codec *other_codec,
- void *encoded_data,
- size_t encoded_data_len,
- int encoded_rate,
- void *decoded_data,
- size_t *decoded_data_len,
- int *decoded_rate,
- unsigned int *flag)
+ switch_codec *other_codec,
+ void *encoded_data,
+ size_t encoded_data_len,
+ int encoded_rate,
+ void *decoded_data,
+ size_t *decoded_data_len, int *decoded_rate, unsigned int *flag)
{
if (codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
memcpy(decoded_data, encoded_data, encoded_data_len);
static switch_status switch_raw_destroy(switch_codec *codec)
{
-
+
return SWITCH_STATUS_SUCCESS;
}
static const switch_codec_implementation raw_32k_implementation = {
- /*.samples_per_second = */ 32000,
+ /*.samples_per_second = */ 32000,
/*.bits_per_second = */ 512000,
/*.microseconds_per_frame = */ 20000,
/*.samples_per_frame = */ 640,
static const switch_codec_implementation raw_8k_30ms_implementation = {
- /*.samples_per_second*/ 8000,
- /*.bits_per_second*/ 128000,
- /*.microseconds_per_frame*/ 30000,
- /*.samples_per_frame*/ 240,
- /*.bytes_per_frame*/ 480,
- /*.encoded_bytes_per_frame*/ 480,
- /*.number_of_channels*/ 1,
- /*.pref_frames_per_packet*/ 1,
- /*.max_frames_per_packet*/ 1,
- /*.init*/ switch_raw_init,
- /*.encode*/ switch_raw_encode,
- /*.decode*/ switch_raw_decode,
- /*.destroy*/ switch_raw_destroy,
- /*.next*/ &raw_8k_implementation
+ /*.samples_per_second */ 8000,
+ /*.bits_per_second */ 128000,
+ /*.microseconds_per_frame */ 30000,
+ /*.samples_per_frame */ 240,
+ /*.bytes_per_frame */ 480,
+ /*.encoded_bytes_per_frame */ 480,
+ /*.number_of_channels */ 1,
+ /*.pref_frames_per_packet */ 1,
+ /*.max_frames_per_packet */ 1,
+ /*.init */ switch_raw_init,
+ /*.encode */ switch_raw_encode,
+ /*.decode */ switch_raw_decode,
+ /*.destroy */ switch_raw_destroy,
+ /*.next */ &raw_8k_implementation
};
static const switch_codec_interface raw_codec_interface = {
- /*.interface_name*/ "raw signed linear (16 bit)",
- /*.codec_type*/ SWITCH_CODEC_TYPE_AUDIO,
- /*.ianacode*/ 10,
- /*.iananame*/ "L16",
- /*.implementations*/ &raw_8k_30ms_implementation
+ /*.interface_name */ "raw signed linear (16 bit)",
+ /*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+ /*.ianacode */ 10,
+ /*.iananame */ "L16",
+ /*.implementations */ &raw_8k_30ms_implementation
};
static switch_loadable_module_interface raw_module_interface = {
- /*.module_name*/ modname,
- /*.endpoint_interface*/ NULL,
- /*.timer_interface*/ NULL,
- /*.dialplan_interface*/ NULL,
- /*.codec_interface*/ &raw_codec_interface,
- /*.application_interface*/ NULL,
- /*.api_interface*/ NULL,
- ///*.file_interface*/ &raw_file_interface
+ /*.module_name */ modname,
+ /*.endpoint_interface */ NULL,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ &raw_codec_interface,
+ /*.application_interface */ NULL,
+ /*.api_interface */ NULL,
+ ///*.file_interface*/ &raw_file_interface
};
-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 */
+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 = &raw_module_interface;
- /* indicate that the module should continue to be loaded */
+ /* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
-
-
-
-
-
static const char modname[] = "mod_speexcodec";
const struct switch_codec_settings default_codec_settings = {
- /*.quality*/ 5,
- /*.complexity*/ 5,
- /*.enhancement*/ 1,
- /*.vad*/ 0,
- /*.vbr*/ 0,
- /*.vbr_quality*/ 4,
- /*.abr*/ 0,
- /*.dtx*/ 0,
- /*.preproc*/ 0,
- /*.pp_vad*/ 0,
- /*.pp_agc*/ 0,
- /*.pp_agc_level*/ 8000,
- /*.pp_denoise*/ 0,
- /*.pp_dereverb*/ 0,
- /*.pp_dereverb_decay*/ 0.4f,
- /*.pp_dereverb_level*/ 0.3f,
+ /*.quality */ 5,
+ /*.complexity */ 5,
+ /*.enhancement */ 1,
+ /*.vad */ 0,
+ /*.vbr */ 0,
+ /*.vbr_quality */ 4,
+ /*.abr */ 0,
+ /*.dtx */ 0,
+ /*.preproc */ 0,
+ /*.pp_vad */ 0,
+ /*.pp_agc */ 0,
+ /*.pp_agc_level */ 8000,
+ /*.pp_denoise */ 0,
+ /*.pp_dereverb */ 0,
+ /*.pp_dereverb_decay */ 0.4f,
+ /*.pp_dereverb_level */ 0.3f,
};
struct speex_context {
int decoder_mode;
};
-static switch_status switch_speex_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings)
+static switch_status switch_speex_init(switch_codec *codec, switch_codec_flag flags,
+ const struct switch_codec_settings *codec_settings)
{
struct speex_context *context = NULL;
int encoding, decoding;
-
+
encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
return SWITCH_STATUS_FALSE;
} else {
const SpeexMode *mode = NULL;
-
+
context->codec = codec;
if (codec->implementation->samples_per_second == 8000) {
mode = &speex_nb_mode;
speex_encoder_ctl(context->encoder_state, SPEEX_GET_FRAME_SIZE, &context->encoder_frame_size);
speex_encoder_ctl(context->encoder_state, SPEEX_SET_COMPLEXITY, &codec->codec_settings.complexity);
if (codec->codec_settings.preproc) {
- context->pp = speex_preprocess_state_init(context->encoder_frame_size, codec->implementation->samples_per_second);
+ context->pp =
+ speex_preprocess_state_init(context->encoder_frame_size, codec->implementation->samples_per_second);
speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_VAD, &codec->codec_settings.pp_vad);
speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_AGC, &codec->codec_settings.pp_agc);
speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_AGC_LEVEL, &codec->codec_settings.pp_agc_level);
speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DENOISE, &codec->codec_settings.pp_denoise);
speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DEREVERB, &codec->codec_settings.pp_dereverb);
- speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DEREVERB_DECAY, &codec->codec_settings.pp_dereverb_decay);
- speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL, &codec->codec_settings.pp_dereverb_level);
+ speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DEREVERB_DECAY,
+ &codec->codec_settings.pp_dereverb_decay);
+ speex_preprocess_ctl(context->pp, SPEEX_PREPROCESS_SET_DEREVERB_LEVEL,
+ &codec->codec_settings.pp_dereverb_level);
}
if (!codec->codec_settings.abr && !codec->codec_settings.vbr) {
speex_encoder_ctl(context->encoder_state, SPEEX_SET_ABR, &codec->codec_settings.abr);
}
if (codec->codec_settings.dtx) {
- speex_encoder_ctl(context->encoder_state, SPEEX_SET_DTX, &codec->codec_settings.dtx);
- }
+ speex_encoder_ctl(context->encoder_state, SPEEX_SET_DTX, &codec->codec_settings.dtx);
+ }
}
if (decoding) {
}
static switch_status switch_speex_encode(switch_codec *codec,
- switch_codec *other_codec,
- void *decoded_data,
- size_t decoded_data_len,
- int decoded_rate,
- void *encoded_data,
- size_t *encoded_data_len,
- int *encoded_rate,
- unsigned int *flag)
+ switch_codec *other_codec,
+ void *decoded_data,
+ size_t decoded_data_len,
+ int decoded_rate,
+ void *encoded_data,
+ size_t *encoded_data_len, int *encoded_rate, unsigned int *flag)
{
struct speex_context *context = codec->private;
short *buf;
}
if (is_speech) {
- is_speech = speex_encode_int(context->encoder_state, buf, &context->encoder_bits) || ! context->codec->codec_settings.dtx;
+ is_speech = speex_encode_int(context->encoder_state, buf, &context->encoder_bits)
+ || !context->codec->codec_settings.dtx;
} else {
speex_bits_pack(&context->encoder_bits, 0, 5);
}
speex_bits_pack(&context->encoder_bits, 15, 5);
- *encoded_data_len = speex_bits_write(&context->encoder_bits, (char *)encoded_data, context->encoder_frame_size);
+ *encoded_data_len = speex_bits_write(&context->encoder_bits, (char *) encoded_data, context->encoder_frame_size);
speex_bits_reset(&context->encoder_bits);
}
static switch_status switch_speex_decode(switch_codec *codec,
- switch_codec *other_codec,
- void *encoded_data,
- size_t encoded_data_len,
- int encoded_rate,
- void *decoded_data,
- size_t *decoded_data_len,
- int *decoded_rate,
- unsigned int *flag)
+ switch_codec *other_codec,
+ void *encoded_data,
+ size_t encoded_data_len,
+ int encoded_rate,
+ void *decoded_data,
+ size_t *decoded_data_len, int *decoded_rate, unsigned int *flag)
{
struct speex_context *context = codec->private;
short *buf;
if (*flag & SWITCH_CODEC_FLAG_SILENCE) {
speex_decode_int(context->decoder_state, NULL, buf);
} else {
- speex_bits_read_from(&context->decoder_bits, (char *)encoded_data, (int)*decoded_data_len);
+ speex_bits_read_from(&context->decoder_bits, (char *) encoded_data, (int) *decoded_data_len);
speex_decode_int(context->decoder_state, &context->decoder_bits, buf);
}
-
+
return SWITCH_STATUS_SUCCESS;
}
}
codec->private = NULL;
-
+
return SWITCH_STATUS_SUCCESS;
}
/* Registration */
static const switch_codec_implementation speex_32k_implementation = {
- /*.samples_per_second*/ 32000,
- /*.bits_per_second*/ 512000,
- /*.nanoseconds_per_frame*/ 20000,
- /*.samples_per_frame*/ 640,
- /*.bytes_per_frame*/ 1280,
- /*.encoded_bytes_per_frame*/ 1280,
- /*.number_of_channels*/ 1,
- /*.pref_frames_per_packet*/ 1,
- /*.max_frames_per_packet*/ 1,
- /*.init*/ switch_speex_init,
- /*.encode*/ switch_speex_encode,
- /*.decode*/ switch_speex_decode,
- /*.destroy*/ switch_speex_destroy
+ /*.samples_per_second */ 32000,
+ /*.bits_per_second */ 512000,
+ /*.nanoseconds_per_frame */ 20000,
+ /*.samples_per_frame */ 640,
+ /*.bytes_per_frame */ 1280,
+ /*.encoded_bytes_per_frame */ 1280,
+ /*.number_of_channels */ 1,
+ /*.pref_frames_per_packet */ 1,
+ /*.max_frames_per_packet */ 1,
+ /*.init */ switch_speex_init,
+ /*.encode */ switch_speex_encode,
+ /*.decode */ switch_speex_decode,
+ /*.destroy */ switch_speex_destroy
};
static const switch_codec_implementation speex_16k_implementation = {
- /*.samples_per_second*/ 16000,
- /*.bits_per_second*/ 256000,
- /*.nanoseconds_per_frame*/ 20000,
- /*.samples_per_frame*/ 320,
- /*.bytes_per_frame*/ 640,
- /*.encoded_bytes_per_frame*/ 640,
- /*.number_of_channels*/ 1,
- /*.pref_frames_per_packet*/ 1,
- /*.max_frames_per_packet*/ 1,
- /*.init*/ switch_speex_init,
- /*.encode*/ switch_speex_encode,
- /*.decode*/ switch_speex_decode,
- /*.destroy*/ switch_speex_destroy,
- /*.next*/ &speex_32k_implementation
+ /*.samples_per_second */ 16000,
+ /*.bits_per_second */ 256000,
+ /*.nanoseconds_per_frame */ 20000,
+ /*.samples_per_frame */ 320,
+ /*.bytes_per_frame */ 640,
+ /*.encoded_bytes_per_frame */ 640,
+ /*.number_of_channels */ 1,
+ /*.pref_frames_per_packet */ 1,
+ /*.max_frames_per_packet */ 1,
+ /*.init */ switch_speex_init,
+ /*.encode */ switch_speex_encode,
+ /*.decode */ switch_speex_decode,
+ /*.destroy */ switch_speex_destroy,
+ /*.next */ &speex_32k_implementation
};
static const switch_codec_implementation speex_8k_implementation = {
- /*.samples_per_second*/ 8000,
- /*.bits_per_second*/ 128000,
- /*.nanoseconds_per_frame*/ 20000,
- /*.samples_per_frame*/ 160,
- /*.bytes_per_frame*/ 320,
- /*.encoded_bytes_per_frame*/ 320,
- /*.number_of_channels*/ 1,
- /*.pref_frames_per_packet*/ 1,
- /*.max_frames_per_packet*/ 1,
- /*.init*/ switch_speex_init,
- /*.encode*/ switch_speex_encode,
- /*.decode*/ switch_speex_decode,
- /*.destroy*/ switch_speex_destroy,
- /*.next*/ &speex_16k_implementation
+ /*.samples_per_second */ 8000,
+ /*.bits_per_second */ 128000,
+ /*.nanoseconds_per_frame */ 20000,
+ /*.samples_per_frame */ 160,
+ /*.bytes_per_frame */ 320,
+ /*.encoded_bytes_per_frame */ 320,
+ /*.number_of_channels */ 1,
+ /*.pref_frames_per_packet */ 1,
+ /*.max_frames_per_packet */ 1,
+ /*.init */ switch_speex_init,
+ /*.encode */ switch_speex_encode,
+ /*.decode */ switch_speex_decode,
+ /*.destroy */ switch_speex_destroy,
+ /*.next */ &speex_16k_implementation
};
static const switch_codec_interface speex_codec_interface = {
- /*.interface_name*/ "speex",
- /*.codec_type*/ SWITCH_CODEC_TYPE_AUDIO,
- /*.ianacode*/ 98,
- /*.iananame*/ "speex",
- /*.implementations*/ &speex_8k_implementation
+ /*.interface_name */ "speex",
+ /*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
+ /*.ianacode */ 98,
+ /*.iananame */ "speex",
+ /*.implementations */ &speex_8k_implementation
};
static switch_loadable_module_interface speex_module_interface = {
- /*.module_name*/ modname,
- /*.endpoint_interface*/ NULL,
- /*.timer_interface*/ NULL,
- /*.dialplan_interface*/ NULL,
- /*.codec_interface*/ &speex_codec_interface,
- /*.application_interface*/ NULL
+ /*.module_name */ modname,
+ /*.endpoint_interface */ NULL,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ &speex_codec_interface,
+ /*.application_interface */ NULL
};
-SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename) {
+SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename)
+{
/* connect my internal structure to the blank pointer passed to me */
*interface = &speex_module_interface;
caller_profile = switch_channel_get_caller_profile(channel);
//switch_channel_set_variable(channel, "pleasework", "yay");
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hello %s You Dialed %s!\n", caller_profile->caller_id_name, caller_profile->destination_number);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hello %s You Dialed %s!\n", caller_profile->caller_id_name,
+ caller_profile->destination_number);
if (!switch_config_open_file(&cfg, cf)) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf);
continue;
}
if (!extension) {
- if (!(extension = switch_caller_extension_new(session, caller_profile->destination_number, caller_profile->destination_number))) {
+ if (!
+ (extension =
+ switch_caller_extension_new(session, caller_profile->destination_number,
+ caller_profile->destination_number))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "memory error!\n");
break;
}
}
switch_caller_extension_add_application(session, extension, app, data);
- }
+ }
}
}
static const switch_dialplan_interface demo_dialplan_interface = {
- /*.interface_name =*/ "demo",
+ /*.interface_name = */ "demo",
/*.hunt_function = */ demo_dialplan_hunt
- /*.next = NULL */
+ /*.next = NULL */
};
static const switch_loadable_module_interface demo_dialplan_module_interface = {
/*.timer_interface = */ NULL,
/*.dialplan_interface = */ &demo_dialplan_interface,
/*.codec_interface = */ NULL,
- /*.application_interface =*/ NULL
+ /*.application_interface = */ NULL
};
-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 = &demo_dialplan_module_interface;
channel = switch_core_session_get_channel(session);
caller_profile = switch_channel_get_caller_profile(channel);
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Processing %s->%s!\n", caller_profile->caller_id_name, caller_profile->destination_number);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Processing %s->%s!\n", caller_profile->caller_id_name,
+ caller_profile->destination_number);
if (!switch_config_open_file(&cfg, cf)) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf);
}
while (switch_config_next_pair(&cfg, &var, &val)) {
- if (cfg.catno != catno) { /* new category */
+ if (cfg.catno != catno) { /* new category */
catno = cfg.catno;
exten_name = cfg.category;
cleanre();
match_count = 0;
}
-
+
if (!strcasecmp(var, "regex")) {
const char *error = NULL;
int erroffset = 0;
-
+
cleanre();
- re = pcre_compile(
- val, /* the pattern */
- 0, /* default options */
- &error, /* for error message */
- &erroffset, /* for error offset */
- NULL); /* use default character tables */
+ re = pcre_compile(val, /* the pattern */
+ 0, /* default options */
+ &error, /* for error message */
+ &erroffset, /* for error offset */
+ NULL); /* use default character tables */
if (error) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "COMPILE ERROR: %d [%s]\n", erroffset, error);
cleanre();
return NULL;
}
- match_count = pcre_exec(
- re, /* result of pcre_compile() */
- NULL, /* we didn't study the pattern */
- caller_profile->destination_number, /* the subject string */
- strlen(caller_profile->destination_number), /* the length of the subject string */
- 0, /* start at offset 0 in the subject */
- 0, /* default options */
- ovector, /* vector of integers for substring information */
- sizeof(ovector) / sizeof(ovector[0])); /* number of elements (NOT size in bytes) */
+ match_count = pcre_exec(re, /* result of pcre_compile() */
+ NULL, /* we didn't study the pattern */
+ caller_profile->destination_number, /* the subject string */
+ strlen(caller_profile->destination_number), /* the length of the subject string */
+ 0, /* start at offset 0 in the subject */
+ 0, /* default options */
+ ovector, /* vector of integers for substring information */
+ sizeof(ovector) / sizeof(ovector[0])); /* number of elements (NOT size in bytes) */
} else if (match_count > 0 && !strcasecmp(var, "match")) {
if (!re) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "ERROR: match without regex in %s line %d\n", cfg.path, cfg.lineno);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "ERROR: match without regex in %s line %d\n", cfg.path,
+ cfg.lineno);
continue;
} else {
char newval[1024] = "";
char index[10] = "";
char replace[128] = "";
- int x, y=0, z=0, num = 0;
+ int x, y = 0, z = 0, num = 0;
char *data;
for (x = 0; x < sizeof(newval) && x < strlen(val);) {
if (val[x] == '$') {
x++;
-
- while(val[x] > 47 && val[x] < 58) {
+
+ while (val[x] > 47 && val[x] < 58) {
index[z++] = val[x];
x++;
}
z = 0;
num = atoi(index);
- if (pcre_copy_substring(caller_profile->destination_number, ovector, match_count, num, replace, sizeof(replace)) > 0) {
+ if (pcre_copy_substring
+ (caller_profile->destination_number, ovector, match_count, num, replace,
+ sizeof(replace)) > 0) {
int r;
- for(r = 0; r < strlen(replace); r++) {
+ for (r = 0; r < strlen(replace); r++) {
newval[y++] = replace[r];
}
}
continue;
}
-
+
if (!extension) {
- if (!(extension = switch_caller_extension_new(session, exten_name, caller_profile->destination_number))) {
+ if (!
+ (extension =
+ switch_caller_extension_new(session, exten_name, caller_profile->destination_number))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "memory error!\n");
break;
}
}
}
}
-
+
switch_config_close_file(&cfg);
if (extension) {
static const switch_dialplan_interface dialplan_interface = {
- /*.interface_name =*/ "pcre",
+ /*.interface_name = */ "pcre",
/*.hunt_function = */ dialplan_hunt
- /*.next = NULL */
+ /*.next = NULL */
};
static const switch_loadable_module_interface dialplan_module_interface = {
/*.timer_interface = */ NULL,
/*.dialplan_interface = */ &dialplan_interface,
/*.codec_interface = */ NULL,
- /*.application_interface =*/ NULL
+ /*.application_interface = */ NULL
};
-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 = &dialplan_module_interface;
TFLAG_DTMF = (1 << 3),
TFLAG_READING = (1 << 4),
TFLAG_WRITING = (1 << 5),
- TFLAG_USING_CODEC = (1 << 6),
+ TFLAG_USING_CODEC = (1 << 6),
TFLAG_RTP = (1 << 7),
TFLAG_BYE = (1 << 8)
} TFLAGS;
} globals;
struct private_object {
- unsigned int flags;
+ unsigned int flags;
switch_core_session *session;
switch_frame read_frame;
switch_codec read_codec;
static switch_status exosip_on_hangup(switch_core_session *session);
static switch_status exosip_on_loopback(switch_core_session *session);
static switch_status exosip_on_transmit(switch_core_session *session);
-static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session);
-static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id);
-static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id);
+static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
+ switch_core_session **new_session);
+static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags, int stream_id);
+static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags, int stream_id);
static int config_exosip(int reload);
-static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload);
+static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **drate, char **dpayload);
static switch_status exosip_kill_channel(switch_core_session *session, int sig);
static void activate_rtp(struct private_object *tech_pvt);
static void deactivate_rtp(struct private_object *tech_pvt);
}
switch (codec_type) {
-case SWITCH_CODEC_TYPE_AUDIO:
- med->m_media = osip_strdup("audio");
- osip_rfc3264_add_audio_media(cnf, med, -1);
- break;
-case SWITCH_CODEC_TYPE_VIDEO:
- med->m_media = osip_strdup("video");
- osip_rfc3264_add_video_media(cnf, med, -1);
- break;
-default:
- break;
+ case SWITCH_CODEC_TYPE_AUDIO:
+ med->m_media = osip_strdup("audio");
+ osip_rfc3264_add_audio_media(cnf, med, -1);
+ break;
+ case SWITCH_CODEC_TYPE_VIDEO:
+ med->m_media = osip_strdup("video");
+ osip_rfc3264_add_video_media(cnf, med, -1);
+ break;
+ default:
+ break;
}
return 0;
}
char *dest_uri;
switch_codec_interface *codecs[SWITCH_MAX_CODECS];
int num_codecs = 0;
- /* do SIP Goodies...*/
+ /* do SIP Goodies... */
/* Generate callerid URI */
eXosip_guess_localip(AF_INET, localip, 128);
/* Initialize SDP */
sdp_message_init(&tech_pvt->local_sdp);
sdp_message_v_version_set(tech_pvt->local_sdp, "0");
- sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", tech_pvt->local_sdp_audio_ip);
+ sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4",
+ tech_pvt->local_sdp_audio_ip);
sdp_message_s_name_set(tech_pvt->local_sdp, "SIP Call");
sdp_message_c_connection_add(tech_pvt->local_sdp, -1, "IN", "IP4", tech_pvt->local_sdp_audio_ip, NULL, NULL);
sdp_message_t_time_descr_add(tech_pvt->local_sdp, "0", "0");
snprintf(port, sizeof(port), "%i", tech_pvt->local_sdp_audio_port);
sdp_message_m_media_add(tech_pvt->local_sdp, "audio", port, NULL, "RTP/AVP");
/* Add in every codec we support on this outbound call */
- if ((num_codecs = switch_loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, sizeof(codecs)/sizeof(codecs[0]))) > 0) {
+ if ((num_codecs =
+ switch_loadable_module_get_codecs(switch_core_session_get_pool(session), codecs,
+ sizeof(codecs) / sizeof(codecs[0]))) > 0) {
int i;
static const switch_codec_implementation *imp;
for (i = 0; i < num_codecs; i++) {
snprintf(tmp, sizeof(tmp), "%i", codecs[i]->ianacode);
sdp_message_m_payload_add(tech_pvt->local_sdp, 0, osip_strdup(tmp));
- for (imp = codecs[i]->implementations ; imp ; imp = imp->next) {
+ for (imp = codecs[i]->implementations; imp; imp = imp->next) {
/* Add to SDP config */
- sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second, x++);
+ sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame,
+ imp->samples_per_second, x++);
/* Add to SDP message */
- snprintf(tmp, sizeof(tmp), "%i %s/%i", codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second);
+ snprintf(tmp, sizeof(tmp), "%i %s/%i", codecs[i]->ianacode, codecs[i]->iananame,
+ imp->samples_per_second);
sdp_message_a_attribute_add(tech_pvt->local_sdp, 0, "rtpmap", osip_strdup(tmp));
memset(tmp, 0, sizeof(tmp));
}
}
/* Setup our INVITE */
eXosip_lock();
- if (!(dest_uri = (char *) switch_core_session_alloc(session, strlen(tech_pvt->caller_profile->destination_number) + 10))) {
+ if (!
+ (dest_uri =
+ (char *) switch_core_session_alloc(session, strlen(tech_pvt->caller_profile->destination_number) + 10))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "AIEEEE!\n");
assert(dest_uri != NULL);
}
switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
tech_pvt->did = -1;
eXosip_unlock();
- }
+ }
/* Let Media Work */
switch_set_flag(tech_pvt, TFLAG_IO);
assert(tech_pvt != NULL);
- switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
+ switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
switch_set_flag(tech_pvt, TFLAG_BYE);
switch_core_codec_destroy(&tech_pvt->write_codec);
}
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "EXOSIP HANGUP %s %d/%d=%d\n", switch_channel_get_name(channel), tech_pvt->cid, tech_pvt->did, i);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "EXOSIP HANGUP %s %d/%d=%d\n", switch_channel_get_name(channel),
+ tech_pvt->cid, tech_pvt->did, i);
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_SUCCESS;
}
-static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session)
+static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
+ switch_core_session **new_session)
{
if ((*new_session = switch_core_session_request(&exosip_endpoint_interface, NULL))) {
struct private_object *tech_pvt;
switch_channel *channel;
switch_core_session_add_stream(*new_session, NULL);
- if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
+ if ((tech_pvt =
+ (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
channel = switch_core_session_get_channel(*new_session);
switch_core_session_set_private(*new_session, tech_pvt);
if (tech_pvt->rtp_session) {
switch_mutex_lock(tech_pvt->rtp_lock);
- while(loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) {
+ while (loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) {
switch_yield(10000);
loops++;
}
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activating RTP %s:%d->%s:%d codec: %d ms: %d\n",
- tech_pvt->local_sdp_audio_ip,
- tech_pvt->local_sdp_audio_port,
- tech_pvt->remote_sdp_audio_ip,
- tech_pvt->remote_sdp_audio_port,
- tech_pvt->read_codec.codec_interface->ianacode,
- ms
- );
+ tech_pvt->local_sdp_audio_ip,
+ tech_pvt->local_sdp_audio_port,
+ tech_pvt->remote_sdp_audio_ip,
+ tech_pvt->remote_sdp_audio_port, tech_pvt->read_codec.codec_interface->ianacode, ms);
- tech_pvt->rtp_session = jrtp4c_new(
- tech_pvt->local_sdp_audio_ip,
- tech_pvt->local_sdp_audio_port,
- tech_pvt->remote_sdp_audio_ip,
- tech_pvt->remote_sdp_audio_port,
- tech_pvt->read_codec.codec_interface->ianacode,
- tech_pvt->read_codec.implementation->samples_per_second,
- &err);
+ tech_pvt->rtp_session = jrtp4c_new(tech_pvt->local_sdp_audio_ip,
+ tech_pvt->local_sdp_audio_port,
+ tech_pvt->remote_sdp_audio_ip,
+ tech_pvt->remote_sdp_audio_port,
+ tech_pvt->read_codec.codec_interface->ianacode,
+ tech_pvt->read_codec.implementation->samples_per_second, &err);
if (tech_pvt->rtp_session) {
tech_pvt->ssrc = jrtp4c_get_ssrc(tech_pvt->rtp_session);
sdp_message_to_str(tech_pvt->local_sdp, &buf);
osip_message_set_body(answer, buf, strlen(buf));
osip_message_set_content_type(answer, "application/sdp");
- free(buf);
+ free(buf);
eXosip_call_send_answer(tech_pvt->tid, 200, answer);
eXosip_unlock();
- }
+ }
return SWITCH_STATUS_SUCCESS;
}
-static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id)
+static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags, int stream_id)
{
struct private_object *tech_pvt = NULL;
- size_t bytes = 0, samples = 0, frames=0, ms=0;
+ size_t bytes = 0, samples = 0, frames = 0, ms = 0;
switch_channel *channel = NULL;
channel = switch_core_session_get_channel(session);
assert(tech_pvt->rtp_session != NULL);
tech_pvt->read_frame.datalen = 0;
- while(!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) {
- tech_pvt->read_frame.datalen = jrtp4c_read(tech_pvt->rtp_session,
- tech_pvt->read_frame.data,
- sizeof(tech_pvt->read_buf));
+ while (!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO)
+ && tech_pvt->read_frame.datalen == 0) {
+ tech_pvt->read_frame.datalen =
+ jrtp4c_read(tech_pvt->rtp_session, tech_pvt->read_frame.data, sizeof(tech_pvt->read_buf));
if (tech_pvt->read_frame.datalen > 0) {
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
frames = (tech_pvt->read_frame.datalen / bytes);
samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
ms = frames * tech_pvt->read_codec.implementation->microseconds_per_frame;
- tech_pvt->timestamp_recv += (int32_t)samples;
- tech_pvt->read_frame.samples = (int)samples;
+ tech_pvt->timestamp_recv += (int32_t) samples;
+ tech_pvt->read_frame.samples = (int) samples;
break;
}
}
-static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id)
+static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags, int stream_id)
{
struct private_object *tech_pvt;
switch_channel *channel = NULL;
switch_status status = SWITCH_STATUS_SUCCESS;
- int bytes=0, samples=0, ms=0, frames=0;
+ int bytes = 0, samples = 0, ms = 0, frames = 0;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
if (switch_test_flag(tech_pvt, TFLAG_USING_CODEC)) {
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
- frames = ((int)frame->datalen / bytes);
+ frames = ((int) frame->datalen / bytes);
samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
ms = frames * tech_pvt->read_codec.implementation->microseconds_per_frame / 1000;
} else {
//printf("%s %s->%s send %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->local_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip, frame->datalen, samples, frames, ms, tech_pvt->timestamp_send);
- jrtp4c_write(tech_pvt->rtp_session, frame->data, (int)frame->datalen, samples);
- tech_pvt->timestamp_send += (int)samples;
+ jrtp4c_write(tech_pvt->rtp_session, frame->data, (int) frame->datalen, samples);
+ tech_pvt->timestamp_send += (int) samples;
switch_clear_flag(tech_pvt, TFLAG_WRITING);
//switch_mutex_unlock(tech_pvt->rtp_lock);
}
static const switch_io_routines exosip_io_routines = {
- /*.outgoing_channel*/ exosip_outgoing_channel,
- /*.answer_channel*/ exosip_answer_channel,
- /*.read_frame*/ exosip_read_frame,
- /*.write_frame*/ exosip_write_frame,
- /*.kill_channel*/ exosip_kill_channel,
- /*.waitfor_read*/ exosip_waitfor_read,
- /*.waitfor_read*/ exosip_waitfor_write
+ /*.outgoing_channel */ exosip_outgoing_channel,
+ /*.answer_channel */ exosip_answer_channel,
+ /*.read_frame */ exosip_read_frame,
+ /*.write_frame */ exosip_write_frame,
+ /*.kill_channel */ exosip_kill_channel,
+ /*.waitfor_read */ exosip_waitfor_read,
+ /*.waitfor_read */ exosip_waitfor_write
};
-static const switch_event_handler_table exosip_event_handlers = {
- /*.on_init*/ exosip_on_init,
- /*.on_ring*/ exosip_on_ring,
- /*.on_execute*/ exosip_on_execute,
- /*.on_hangup*/ exosip_on_hangup,
- /*.on_loopback*/ exosip_on_loopback,
- /*.on_transmit*/ exosip_on_transmit
+static const switch_event_handler_table exosip_event_handlers = {
+ /*.on_init */ exosip_on_init,
+ /*.on_ring */ exosip_on_ring,
+ /*.on_execute */ exosip_on_execute,
+ /*.on_hangup */ exosip_on_hangup,
+ /*.on_loopback */ exosip_on_loopback,
+ /*.on_transmit */ exosip_on_transmit
};
static const switch_endpoint_interface exosip_endpoint_interface = {
- /*.interface_name*/ "exosip",
- /*.io_routines*/ &exosip_io_routines,
- /*.event_handlers*/ &exosip_event_handlers,
- /*.private*/ NULL,
- /*.next*/ NULL
+ /*.interface_name */ "exosip",
+ /*.io_routines */ &exosip_io_routines,
+ /*.event_handlers */ &exosip_event_handlers,
+ /*.private */ NULL,
+ /*.next */ NULL
};
static const switch_loadable_module_interface exosip_module_interface = {
- /*.module_name*/ modname,
- /*.endpoint_interface*/ &exosip_endpoint_interface,
- /*.timer_interface*/ NULL,
- /*.dialplan_interface*/ NULL,
- /*.codec_interface*/ NULL,
- /*.application_interface*/ NULL
+ /*.module_name */ modname,
+ /*.endpoint_interface */ &exosip_endpoint_interface,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ NULL,
+ /*.application_interface */ NULL
};
#if 1
{
if (globals.running) {
globals.running = -1;
- while(globals.running) {
+ while (globals.running) {
switch_yield(100000);
}
}
return SWITCH_STATUS_SUCCESS;
}
#endif
-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)
+{
/* NOTE: **interface is **_interface because the common lib redefines interface to struct in some situations */
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_SUCCESS;
}
-static switch_status exosip_create_call(eXosip_event_t *event)
+static switch_status exosip_create_call(eXosip_event_t * event)
{
switch_core_session *session;
sdp_message_t *remote_sdp = NULL;
}
if ((tech_pvt->caller_profile = switch_caller_profile_new(session,
- globals.dialplan,
- event->request->from->displayname,
- event->request->from->url->username,
- event->request->from->url->host,
- NULL,
- NULL,
- event->request->req_uri->username))) {
- switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
+ globals.dialplan,
+ event->request->from->displayname,
+ event->request->from->url->username,
+ event->request->from->url->host,
+ NULL, NULL, event->request->req_uri->username))) {
+ switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
}
switch_set_flag(tech_pvt, TFLAG_INBOUND);
osip_rfc3264_init(&tech_pvt->sdp_config);
/* Add in what codecs we support locally */
- if ((num_codecs = switch_loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, sizeof(codecs)/sizeof(codecs[0]))) > 0) {
+ if ((num_codecs =
+ switch_loadable_module_get_codecs(switch_core_session_get_pool(session), codecs,
+ sizeof(codecs) / sizeof(codecs[0]))) > 0) {
int i;
static const switch_codec_implementation *imp;
for (i = 0; i < num_codecs; i++) {
int x = 0;
- for (imp = codecs[i]->implementations ; imp ; imp = imp->next) {
- sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second, x++);
+ for (imp = codecs[i]->implementations; imp; imp = imp->next) {
+ sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame,
+ imp->samples_per_second, x++);
}
}
}
sdp_message_parse(tech_pvt->local_sdp, local_sdp_str);
sdp_message_to_str(remote_sdp, &remote_sdp_str);
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "LOCAL SDP:\n%s\nREMOTE SDP:\n%s", local_sdp_str,remote_sdp_str);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "LOCAL SDP:\n%s\nREMOTE SDP:\n%s", local_sdp_str, remote_sdp_str);
mline = 0;
- while (0==osip_rfc3264_match(tech_pvt->sdp_config, remote_sdp, audio_tab, video_tab, t38_tab, app_tab, mline)) {
+ while (0 == osip_rfc3264_match(tech_pvt->sdp_config, remote_sdp, audio_tab, video_tab, t38_tab, app_tab, mline)) {
if (audio_tab[0] == NULL && video_tab[0] == NULL && t38_tab[0] == NULL && app_tab[0] == NULL) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got no compatible codecs!\n");
break;
}
- for (pos=0; audio_tab[pos]!=NULL; pos++) {
- osip_rfc3264_complete_answer(tech_pvt->sdp_config, remote_sdp, tech_pvt->local_sdp, audio_tab[pos], mline);
+ for (pos = 0; audio_tab[pos] != NULL; pos++) {
+ osip_rfc3264_complete_answer(tech_pvt->sdp_config, remote_sdp, tech_pvt->local_sdp, audio_tab[pos],
+ mline);
if (parse_sdp_media(audio_tab[pos], &dname, &drate, &dpayload) == SWITCH_STATUS_SUCCESS) {
tech_pvt->payload_num = atoi(dpayload);
break;
mline++;
}
free(remote_sdp_str);
- sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", tech_pvt->local_sdp_audio_ip);
+ sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4",
+ tech_pvt->local_sdp_audio_ip);
sdp_message_s_name_set(tech_pvt->local_sdp, "SIP Call");
sdp_message_c_connection_add(tech_pvt->local_sdp, -1, "IN", "IP4", tech_pvt->local_sdp_audio_ip, NULL, NULL);
snprintf(port, sizeof(port), "%i", tech_pvt->local_sdp_audio_port);
tech_pvt->remote_sdp_audio_port = atoi(remote_med->m_port);
snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", event->cid);
- switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
+ switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
if (!dname) {
exosip_on_hangup(session);
int rate = atoi(drate);
if (switch_core_codec_init(&tech_pvt->read_codec,
- dname,
- rate,
- globals.codec_ms,
- 1,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+ dname,
+ rate,
+ globals.codec_ms,
+ 1,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
+ switch_channel_hangup(channel);
+ return SWITCH_STATUS_FALSE;
+ } else {
+ if (switch_core_codec_init(&tech_pvt->write_codec,
+ dname,
+ rate,
+ globals.codec_ms,
+ 1,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE;
- } else {
- if (switch_core_codec_init(&tech_pvt->write_codec,
- dname,
- rate,
- globals.codec_ms,
- 1,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
- switch_channel_hangup(channel);
- return SWITCH_STATUS_FALSE;
} else {
int ms;
tech_pvt->read_frame.rate = rate;
switch_set_flag(tech_pvt, TFLAG_USING_CODEC);
ms = tech_pvt->write_codec.implementation->microseconds_per_frame / 1000;
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Inbound Codec %s/%d %d ms\n", dname, rate, ms);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Inbound Codec %s/%d %d ms\n", dname, rate,
+ ms);
tech_pvt->read_frame.codec = &tech_pvt->read_codec;
switch_core_session_set_read_codec(session, &tech_pvt->read_codec);
switch_core_session_set_write_codec(session, &tech_pvt->write_codec);
}
-static void destroy_call_by_event(eXosip_event_t *event)
+static void destroy_call_by_event(eXosip_event_t * event)
{
struct private_object *tech_pvt;
switch_channel *channel = NULL;
if (!(tech_pvt = get_pvt_by_call_id(event->cid))) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Um in case you are interested, Can't find the pvt [%d]!\n", event->cid);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Um in case you are interested, Can't find the pvt [%d]!\n",
+ event->cid);
return;
}
}
-static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload)
+static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **drate, char **dpayload)
{
int pos = 0;
sdp_attribute_t *attr = NULL;
switch_status status = SWITCH_STATUS_GENERR;
while (osip_list_eol(media->a_attributes, pos) == 0) {
- attr = (sdp_attribute_t *)osip_list_get(media->a_attributes, pos);
+ attr = (sdp_attribute_t *) osip_list_get(media->a_attributes, pos);
if (attr != NULL && strcasecmp(attr->a_att_field, "rtpmap") == 0) {
payload = attr->a_att_value;
if ((name = strchr(payload, ' '))) {
*dname = strdup("L16");
*drate = strdup("8000");
}
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Found negotiated codec Payload: %s Name: %s Rate: %s\n", *dpayload, *dname, *drate);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Found negotiated codec Payload: %s Name: %s Rate: %s\n",
+ *dpayload, *dname, *drate);
break;
}
attr = NULL;
return status;
}
-static void handle_answer(eXosip_event_t *event)
+static void handle_answer(eXosip_event_t * event)
{
osip_message_t *ack = NULL;
sdp_message_t *remote_sdp = NULL;
if (switch_core_codec_init(&tech_pvt->read_codec,
- dname,
- rate,
- globals.codec_ms,
- 1,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+ dname,
+ rate,
+ globals.codec_ms,
+ 1,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
+ switch_channel_hangup(channel);
+ return;
+ } else {
+ if (switch_core_codec_init(&tech_pvt->write_codec,
+ dname,
+ rate,
+ globals.codec_ms,
+ 1,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL,
+ switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return;
- } else {
- if (switch_core_codec_init(&tech_pvt->write_codec,
- dname,
- rate,
- globals.codec_ms,
- 1,
- SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
- switch_channel_hangup(channel);
- return;
} else {
int ms;
tech_pvt->read_frame.rate = rate;
}
}
-static void log_event(eXosip_event_t *je)
+static void log_event(eXosip_event_t * je)
{
char buf[100];
buf[0] = '\0';
if (je->type == EXOSIP_CALL_NOANSWER) {
- snprintf (buf, 99, "<- (%i %i) No answer", je->cid, je->did);
+ snprintf(buf, 99, "<- (%i %i) No answer", je->cid, je->did);
} else if (je->type == EXOSIP_CALL_CLOSED) {
- snprintf (buf, 99, "<- (%i %i) Call Closed", je->cid, je->did);
+ snprintf(buf, 99, "<- (%i %i) Call Closed", je->cid, je->did);
} else if (je->type == EXOSIP_CALL_RELEASED) {
- snprintf (buf, 99, "<- (%i %i) Call released", je->cid, je->did);
- } else if (je->type == EXOSIP_MESSAGE_NEW
- && je->request!=NULL && MSG_IS_MESSAGE(je->request)) {
- char *tmp = NULL;
+ snprintf(buf, 99, "<- (%i %i) Call released", je->cid, je->did);
+ } else if (je->type == EXOSIP_MESSAGE_NEW && je->request != NULL && MSG_IS_MESSAGE(je->request)) {
+ char *tmp = NULL;
- if (je->request != NULL) {
- osip_body_t *body;
- osip_from_to_str (je->request->from, &tmp);
+ if (je->request != NULL) {
+ osip_body_t *body;
+ osip_from_to_str(je->request->from, &tmp);
- osip_message_get_body (je->request, 0, &body);
- if (body != NULL && body->body != NULL) {
- snprintf (buf, 99, "<- (%i) from: %s TEXT: %s",
- je->tid, tmp, body->body);
- }
- osip_free (tmp);
- } else {
- snprintf (buf, 99, "<- (%i) New event for unknown request?", je->tid);
+ osip_message_get_body(je->request, 0, &body);
+ if (body != NULL && body->body != NULL) {
+ snprintf(buf, 99, "<- (%i) from: %s TEXT: %s", je->tid, tmp, body->body);
}
+ osip_free(tmp);
+ } else {
+ snprintf(buf, 99, "<- (%i) New event for unknown request?", je->tid);
+ }
} else if (je->type == EXOSIP_MESSAGE_NEW) {
char *tmp = NULL;
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (%i) %s from: %s",
- je->tid, je->request->sip_method, tmp);
- osip_free (tmp);
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (%i) %s from: %s", je->tid, je->request->sip_method, tmp);
+ osip_free(tmp);
} else if (je->type == EXOSIP_MESSAGE_PROCEEDING
- || je->type == EXOSIP_MESSAGE_ANSWERED
- || je->type == EXOSIP_MESSAGE_REDIRECTED
- || je->type == EXOSIP_MESSAGE_REQUESTFAILURE
- || je->type == EXOSIP_MESSAGE_SERVERFAILURE
- || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) {
- if (je->response != NULL && je->request != NULL) {
- char *tmp = NULL;
-
- osip_to_to_str (je->request->to, &tmp);
- snprintf (buf, 99, "<- (%i) [%i %s for %s] to: %s",
- je->tid, je->response->status_code,
- je->response->reason_phrase, je->request->sip_method, tmp);
- osip_free (tmp);
- } else if (je->request != NULL) {
- snprintf (buf, 99, "<- (%i) Error for %s request",
- je->tid, je->request->sip_method);
- } else {
- snprintf (buf, 99, "<- (%i) Error for unknown request", je->tid);
- }
+ || je->type == EXOSIP_MESSAGE_ANSWERED
+ || je->type == EXOSIP_MESSAGE_REDIRECTED
+ || je->type == EXOSIP_MESSAGE_REQUESTFAILURE
+ || je->type == EXOSIP_MESSAGE_SERVERFAILURE || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) {
+ if (je->response != NULL && je->request != NULL) {
+ char *tmp = NULL;
+
+ osip_to_to_str(je->request->to, &tmp);
+ snprintf(buf, 99, "<- (%i) [%i %s for %s] to: %s",
+ je->tid, je->response->status_code, je->response->reason_phrase, je->request->sip_method, tmp);
+ osip_free(tmp);
+ } else if (je->request != NULL) {
+ snprintf(buf, 99, "<- (%i) Error for %s request", je->tid, je->request->sip_method);
+ } else {
+ snprintf(buf, 99, "<- (%i) Error for unknown request", je->tid);
+ }
} else if (je->response == NULL && je->request != NULL && je->cid > 0) {
char *tmp = NULL;
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (%i %i) %s from: %s",
- je->cid, je->did, je->request->cseq->method, tmp);
- osip_free (tmp);
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (%i %i) %s from: %s", je->cid, je->did, je->request->cseq->method, tmp);
+ osip_free(tmp);
} else if (je->response != NULL && je->cid > 0) {
char *tmp = NULL;
- osip_to_to_str (je->request->to, &tmp);
- snprintf (buf, 99, "<- (%i %i) [%i %s] for %s to: %s",
- je->cid, je->did, je->response->status_code,
- je->response->reason_phrase, je->request->sip_method, tmp);
- osip_free (tmp);
+ osip_to_to_str(je->request->to, &tmp);
+ snprintf(buf, 99, "<- (%i %i) [%i %s] for %s to: %s",
+ je->cid, je->did, je->response->status_code,
+ je->response->reason_phrase, je->request->sip_method, tmp);
+ osip_free(tmp);
} else if (je->response == NULL && je->request != NULL && je->rid > 0) {
char *tmp = NULL;
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (%i) %s from: %s",
- je->rid, je->request->cseq->method, tmp);
- osip_free (tmp);
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (%i) %s from: %s", je->rid, je->request->cseq->method, tmp);
+ osip_free(tmp);
} else if (je->response != NULL && je->rid > 0) {
char *tmp = NULL;
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (%i) [%i %s] from: %s",
- je->rid, je->response->status_code,
- je->response->reason_phrase, tmp);
- osip_free (tmp);
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (%i) [%i %s] from: %s",
+ je->rid, je->response->status_code, je->response->reason_phrase, tmp);
+ osip_free(tmp);
} else if (je->response == NULL && je->request != NULL && je->sid > 0) {
char *tmp = NULL;
char *stat = NULL;
osip_header_t *sub_state;
- osip_message_header_get_byname (je->request, "subscription-state",
- 0, &sub_state);
+ osip_message_header_get_byname(je->request, "subscription-state", 0, &sub_state);
if (sub_state != NULL && sub_state->hvalue != NULL)
stat = sub_state->hvalue;
- osip_uri_to_str (je->request->from->url, &tmp);
- snprintf (buf, 99, "<- (%i) [%s] %s from: %s",
- je->sid, stat, je->request->cseq->method, tmp);
- osip_free (tmp);
+ osip_uri_to_str(je->request->from->url, &tmp);
+ snprintf(buf, 99, "<- (%i) [%s] %s from: %s", je->sid, stat, je->request->cseq->method, tmp);
+ osip_free(tmp);
} else if (je->response != NULL && je->sid > 0) {
char *tmp = NULL;
- osip_uri_to_str (je->request->to->url, &tmp);
- snprintf (buf, 99, "<- (%i) [%i %s] from: %s",
- je->sid, je->response->status_code,
- je->response->reason_phrase, tmp);
- osip_free (tmp);
+ osip_uri_to_str(je->request->to->url, &tmp);
+ snprintf(buf, 99, "<- (%i) [%i %s] from: %s",
+ je->sid, je->response->status_code, je->response->reason_phrase, tmp);
+ osip_free(tmp);
} else if (je->response == NULL && je->request != NULL) {
char *tmp = NULL;
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s",
- je->cid, je->did, je->sid, je->nid,
- je->request->sip_method, tmp);
- osip_free (tmp);
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s",
+ je->cid, je->did, je->sid, je->nid, je->request->sip_method, tmp);
+ osip_free(tmp);
} else if (je->response != NULL) {
char *tmp = NULL;
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) [%i %s] for %s from: %s",
- je->cid, je->did, je->sid, je->nid,
- je->response->status_code, je->response->reason_phrase,
- je->request->sip_method, tmp);
- osip_free (tmp);
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) [%i %s] for %s from: %s",
+ je->cid, je->did, je->sid, je->nid,
+ je->response->status_code, je->response->reason_phrase, je->request->sip_method, tmp);
+ osip_free(tmp);
} else {
- snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i|t=%i) %s",
- je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo);
+ snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i|t=%i) %s",
+ je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo);
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\n%s\n", buf);
/* Print it out */
-static int config_exosip(int reload)
+static int config_exosip(int reload)
{
switch_config cfg;
char *var, *val;
config_exosip(0);
- if (eXosip_init ()) {
+ if (eXosip_init()) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_init initialization failed!\n");
return SWITCH_STATUS_TERM;
}
- if (eXosip_listen_addr (IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) {
+ if (eXosip_listen_addr(IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_listen_addr failed!\n");
return SWITCH_STATUS_TERM;
}
-
+
globals.running = 1;
while (globals.running > 0) {
- if (!(event = eXosip_event_wait(0,100))) {
+ if (!(event = eXosip_event_wait(0, 100))) {
switch_yield(1000);
continue;
}
eXosip_lock();
- eXosip_automatic_action ();
+ eXosip_automatic_action();
eXosip_unlock();
log_event(event);
- switch(event->type) {
- case EXOSIP_CALL_INVITE:
- exosip_create_call(event);
- break;
- case EXOSIP_CALL_REINVITE:
- /* See what the reinvite is about - on hold or whatever */
- //handle_reinvite(event);
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got a reinvite.\n");
- break;
- case EXOSIP_CALL_MESSAGE_NEW:
- if (event->request != NULL && MSG_IS_REFER(event->request)) {
- //handle_call_transfer(event);
- }
- break;
- case EXOSIP_CALL_ACK:
- /* If audio is not flowing and this has SDP - fire it up! */
- break;
- case EXOSIP_CALL_ANSWERED:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was answered.\n");
- handle_answer(event);
- break;
- case EXOSIP_CALL_PROCEEDING:
- /* This is like a 100 Trying... yeah */
- break;
- case EXOSIP_CALL_RINGING:
- //handle_ringing(event);
- break;
- case EXOSIP_CALL_REDIRECTED:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call was redirect\n");
- break;
- case EXOSIP_CALL_CLOSED:
- destroy_call_by_event(event);
- break;
- case EXOSIP_CALL_RELEASED:
- destroy_call_by_event(event);
- break;
- case EXOSIP_CALL_NOANSWER:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was not answered.\n");
- destroy_call_by_event(event);
- break;
- case EXOSIP_CALL_REQUESTFAILURE:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Request failure\n");
- destroy_call_by_event(event);
- break;
- case EXOSIP_CALL_SERVERFAILURE:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Server failure\n");
- destroy_call_by_event(event);
- break;
- case EXOSIP_CALL_GLOBALFAILURE:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Global failure\n");
- destroy_call_by_event(event);
- break;
- /* Registration related stuff */
- case EXOSIP_REGISTRATION_NEW:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Received registration attempt\n");
- break;
- default:
- /* Unknown event... casually absorb it for now */
- break;
+ switch (event->type) {
+ case EXOSIP_CALL_INVITE:
+ exosip_create_call(event);
+ break;
+ case EXOSIP_CALL_REINVITE:
+ /* See what the reinvite is about - on hold or whatever */
+ //handle_reinvite(event);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got a reinvite.\n");
+ break;
+ case EXOSIP_CALL_MESSAGE_NEW:
+ if (event->request != NULL && MSG_IS_REFER(event->request)) {
+ //handle_call_transfer(event);
+ }
+ break;
+ case EXOSIP_CALL_ACK:
+ /* If audio is not flowing and this has SDP - fire it up! */
+ break;
+ case EXOSIP_CALL_ANSWERED:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was answered.\n");
+ handle_answer(event);
+ break;
+ case EXOSIP_CALL_PROCEEDING:
+ /* This is like a 100 Trying... yeah */
+ break;
+ case EXOSIP_CALL_RINGING:
+ //handle_ringing(event);
+ break;
+ case EXOSIP_CALL_REDIRECTED:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call was redirect\n");
+ break;
+ case EXOSIP_CALL_CLOSED:
+ destroy_call_by_event(event);
+ break;
+ case EXOSIP_CALL_RELEASED:
+ destroy_call_by_event(event);
+ break;
+ case EXOSIP_CALL_NOANSWER:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "The call was not answered.\n");
+ destroy_call_by_event(event);
+ break;
+ case EXOSIP_CALL_REQUESTFAILURE:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Request failure\n");
+ destroy_call_by_event(event);
+ break;
+ case EXOSIP_CALL_SERVERFAILURE:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Server failure\n");
+ destroy_call_by_event(event);
+ break;
+ case EXOSIP_CALL_GLOBALFAILURE:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Global failure\n");
+ destroy_call_by_event(event);
+ break;
+ /* Registration related stuff */
+ case EXOSIP_REGISTRATION_NEW:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Received registration attempt\n");
+ break;
+ default:
+ /* Unknown event... casually absorb it for now */
+ break;
}
//switch_console_printf(SWITCH_CHANNEL_CONSOLE, "There was an event (%d) [%s]\n", event->type, event->textinfo);
eXosip_quit();
globals.running = 0;
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Monitor Thread Exiting\n");
- //switch_sleep(2000000);
-
+ //switch_sleep(2000000);
+
return SWITCH_STATUS_TERM;
}
-
TFLAG_DTMF = (1 << 3),
TFLAG_READING = (1 << 4),
TFLAG_WRITING = (1 << 5),
- TFLAG_USING_CODEC = (1 << 6),
+ TFLAG_USING_CODEC = (1 << 6),
TFLAG_RTP = (1 << 7),
TFLAG_BYE = (1 << 8)
} TFLAGS;
} globals;
struct private_object {
- unsigned int flags;
+ unsigned int flags;
switch_core_session *session;
switch_frame read_frame;
switch_codec read_codec;
free(globals.dialplan);
globals.dialplan = NULL;
}
-
+
globals.dialplan = strdup(dialplan);
}
static switch_status exosip_on_hangup(switch_core_session *session);
static switch_status exosip_on_loopback(switch_core_session *session);
static switch_status exosip_on_transmit(switch_core_session *session);
-static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session);
-static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags);
-static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags);
+static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
+ switch_core_session **new_session);
+static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags);
+static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags);
static int config_exosip(int reload);
-static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload);
+static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **drate, char **dpayload);
static switch_status exosip_kill_channel(switch_core_session *session, int sig);
static void activate_rtp(struct private_object *tech_pvt);
static void deactivate_rtp(struct private_object *tech_pvt);
default:
break;
}
- return 0;
+ return 0;
}
char *dest_uri;
switch_codec_interface *codecs[512];
int num_codecs = 0;
- /* do SIP Goodies...*/
+ /* do SIP Goodies... */
/* Generate callerid URI */
eXosip_guess_localip(AF_INET, localip, 128);
/* Initialize SDP */
sdp_message_init(&tech_pvt->local_sdp);
sdp_message_v_version_set(tech_pvt->local_sdp, "0");
- sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", tech_pvt->local_sdp_audio_ip);
+ sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4",
+ tech_pvt->local_sdp_audio_ip);
sdp_message_s_name_set(tech_pvt->local_sdp, "SIP Call");
sdp_message_c_connection_add(tech_pvt->local_sdp, -1, "IN", "IP4", tech_pvt->local_sdp_audio_ip, NULL, NULL);
sdp_message_t_time_descr_add(tech_pvt->local_sdp, "0", "0");
snprintf(port, sizeof(port), "%i", tech_pvt->local_sdp_audio_port);
sdp_message_m_media_add(tech_pvt->local_sdp, "audio", port, NULL, "RTP/AVP");
/* Add in every codec we support on this outbound call */
- if ((num_codecs = loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, sizeof(codecs)/sizeof(codecs[0]))) > 0) {
+ if ((num_codecs =
+ loadable_module_get_codecs(switch_core_session_get_pool(session), codecs,
+ sizeof(codecs) / sizeof(codecs[0]))) > 0) {
int i;
static const switch_codec_implementation *imp;
for (i = 0; i < num_codecs; i++) {
snprintf(tmp, sizeof(tmp), "%i", codecs[i]->ianacode);
sdp_message_m_payload_add(tech_pvt->local_sdp, 0, osip_strdup(tmp));
- for (imp = codecs[i]->implementations ; imp ; imp = imp->next) {
+ for (imp = codecs[i]->implementations; imp; imp = imp->next) {
/* Add to SDP config */
- sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second, x++);
+ sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame,
+ imp->samples_per_second, x++);
/* Add to SDP message */
- snprintf(tmp, sizeof(tmp), "%i %s/%i", codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second);
+ snprintf(tmp, sizeof(tmp), "%i %s/%i", codecs[i]->ianacode, codecs[i]->iananame,
+ imp->samples_per_second);
sdp_message_a_attribute_add(tech_pvt->local_sdp, 0, "rtpmap", osip_strdup(tmp));
memset(tmp, 0, sizeof(tmp));
}
}
/* Setup our INVITE */
eXosip_lock();
- if (!(dest_uri = (char *) switch_core_session_alloc(session, strlen(tech_pvt->caller_profile->destination_number) + 10))) {
+ if (!
+ (dest_uri =
+ (char *) switch_core_session_alloc(session, strlen(tech_pvt->caller_profile->destination_number) + 10))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "AIEEEE!\n");
assert(dest_uri != NULL);
}
switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
tech_pvt->did = -1;
eXosip_unlock();
- }
+ }
/* Let Media Work */
switch_set_flag(tech_pvt, TFLAG_IO);
assert(tech_pvt != NULL);
- switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
-
+ switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
+
switch_set_flag(tech_pvt, TFLAG_BYE);
switch_clear_flag(tech_pvt, TFLAG_IO);
switch_core_codec_destroy(&tech_pvt->write_codec);
}
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "EXOSIP HANGUP %s %d/%d=%d\n", switch_channel_get_name(channel), tech_pvt->cid, tech_pvt->did, i);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "EXOSIP HANGUP %s %d/%d=%d\n", switch_channel_get_name(channel),
+ tech_pvt->cid, tech_pvt->did, i);
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_SUCCESS;
}
-static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session)
+static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
+ switch_core_session **new_session)
{
if ((*new_session = switch_core_session_request(&exosip_endpoint_interface, NULL))) {
struct private_object *tech_pvt;
switch_caller_profile *caller_profile, *originator_caller_profile = NULL;
switch_core_session_add_stream(*new_session, NULL);
- if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
+ if ((tech_pvt =
+ (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
channel = switch_core_session_get_channel(*new_session);
switch_core_session_set_private(*new_session, tech_pvt);
switch_channel_set_originator_caller_profile(channel, cloned_profile);
}
}
-
+
switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT);
if (tech_pvt->rtp_session) {
//switch_mutex_lock(tech_pvt->rtp_lock);
- while(loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) {
+ while (loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) {
switch_yield(10000);
loops++;
}
tech_pvt->local_sdp_audio_ip,
tech_pvt->local_sdp_audio_port,
tech_pvt->remote_sdp_audio_ip,
- tech_pvt->remote_sdp_audio_port,
- tech_pvt->read_codec.codec_interface->ianacode,
- ms
- );
+ tech_pvt->remote_sdp_audio_port, tech_pvt->read_codec.codec_interface->ianacode, ms);
- tech_pvt->rtp_session = ccrtp4c_new(
- tech_pvt->local_sdp_audio_ip,
+ tech_pvt->rtp_session = ccrtp4c_new(tech_pvt->local_sdp_audio_ip,
tech_pvt->local_sdp_audio_port,
tech_pvt->remote_sdp_audio_ip,
tech_pvt->remote_sdp_audio_port,
- tech_pvt->read_codec.codec_interface->ianacode,
- ms,
- ms * 15);
+ tech_pvt->read_codec.codec_interface->ianacode, ms, ms * 15);
if (tech_pvt->rtp_session) {
tech_pvt->ssrc = ccrtp4c_get_ssrc(tech_pvt->rtp_session);
sdp_message_to_str(tech_pvt->local_sdp, &buf);
osip_message_set_body(answer, buf, strlen(buf));
osip_message_set_content_type(answer, "application/sdp");
- free(buf);
+ free(buf);
eXosip_call_send_answer(tech_pvt->tid, 200, answer);
eXosip_unlock();
- }
+ }
return SWITCH_STATUS_SUCCESS;
}
-static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags)
+static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags)
{
struct private_object *tech_pvt = NULL;
- size_t bytes = 0, samples = 0, frames=0, ms=0;
+ size_t bytes = 0, samples = 0, frames = 0, ms = 0;
switch_channel *channel = NULL;
channel = switch_core_session_get_channel(session);
assert(tech_pvt->rtp_session != NULL);
tech_pvt->read_frame.datalen = 0;
-
- while(!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO) && tech_pvt->read_frame.datalen == 0) {
- if ((tech_pvt->read_frame.datalen =
- ccrtp4c_read(tech_pvt->rtp_session,
- tech_pvt->read_frame.data,
- sizeof(tech_pvt->read_buf),
+
+ while (!switch_test_flag(tech_pvt, TFLAG_BYE) && switch_test_flag(tech_pvt, TFLAG_IO)
+ && tech_pvt->read_frame.datalen == 0) {
+ if ((tech_pvt->read_frame.datalen =
+ ccrtp4c_read(tech_pvt->rtp_session, tech_pvt->read_frame.data, sizeof(tech_pvt->read_buf),
&tech_pvt->timestamp_recv))) {
bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
frames = (tech_pvt->read_frame.datalen / bytes);
}
switch_yield(100);
}
-
+
//printf("%s %s->%s recv %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->local_sdp_audio_ip, tech_pvt->local_sdp_audio_ip, tech_pvt->read_frame.datalen, samples, frames, ms, tech_pvt->timestamp_recv);
-
+
//switch_mutex_unlock(tech_pvt->rtp_lock);
*frame = &tech_pvt->read_frame;
-
+
return SWITCH_STATUS_SUCCESS;
}
-static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags)
+static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags)
{
struct private_object *tech_pvt;
switch_channel *channel = NULL;
switch_status status = SWITCH_STATUS_SUCCESS;
- int bytes=0, samples=0, ms=0, frames=0;
+ int bytes = 0, samples = 0, ms = 0, frames = 0;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
+
if (!switch_test_flag(tech_pvt, TFLAG_RTP)) {
activate_rtp(tech_pvt);
}
} else {
assert(0);
}
-
+
//printf("%s %s->%s send %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->local_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip, frame->datalen, samples, frames, ms, tech_pvt->timestamp_send);
-
- tech_pvt->timestamp_send += (int)samples;
+
+ tech_pvt->timestamp_send += (int) samples;
ccrtp4c_write(tech_pvt->rtp_session, frame->data, frame->datalen, &tech_pvt->timestamp_send);
-
+
switch_clear_flag(tech_pvt, TFLAG_WRITING);
switch_clear_flag(tech_pvt, TFLAG_IO);
switch_set_flag(tech_pvt, TFLAG_BYE);
-
+
return SWITCH_STATUS_SUCCESS;
}
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
+
return SWITCH_STATUS_SUCCESS;
}
-
+
static const switch_io_routines exosip_io_routines = {
- /*.outgoing_channel*/ exosip_outgoing_channel,
- /*.answer_channel*/ exosip_answer_channel,
- /*.read_frame*/ exosip_read_frame,
- /*.write_frame*/ exosip_write_frame,
- /*.kill_channel*/ exosip_kill_channel,
- /*.waitfor_read*/ exosip_waitfor_read,
- /*.waitfor_read*/ exosip_waitfor_write
+ /*.outgoing_channel */ exosip_outgoing_channel,
+ /*.answer_channel */ exosip_answer_channel,
+ /*.read_frame */ exosip_read_frame,
+ /*.write_frame */ exosip_write_frame,
+ /*.kill_channel */ exosip_kill_channel,
+ /*.waitfor_read */ exosip_waitfor_read,
+ /*.waitfor_read */ exosip_waitfor_write
};
-static const switch_event_handler_table exosip_event_handlers = {
- /*.on_init*/ exosip_on_init,
- /*.on_ring*/ exosip_on_ring,
- /*.on_execute*/ exosip_on_execute,
- /*.on_hangup*/ exosip_on_hangup,
- /*.on_loopback*/ exosip_on_loopback,
- /*.on_transmit*/ exosip_on_transmit
+static const switch_event_handler_table exosip_event_handlers = {
+ /*.on_init */ exosip_on_init,
+ /*.on_ring */ exosip_on_ring,
+ /*.on_execute */ exosip_on_execute,
+ /*.on_hangup */ exosip_on_hangup,
+ /*.on_loopback */ exosip_on_loopback,
+ /*.on_transmit */ exosip_on_transmit
};
static const switch_endpoint_interface exosip_endpoint_interface = {
- /*.interface_name*/ "exosip",
- /*.io_routines*/ &exosip_io_routines,
- /*.event_handlers*/ &exosip_event_handlers,
- /*.private*/ NULL,
- /*.next*/ NULL
+ /*.interface_name */ "exosip",
+ /*.io_routines */ &exosip_io_routines,
+ /*.event_handlers */ &exosip_event_handlers,
+ /*.private */ NULL,
+ /*.next */ NULL
};
static const switch_loadable_module_interface exosip_module_interface = {
- /*.module_name*/ modname,
- /*.endpoint_interface*/ &exosip_endpoint_interface,
- /*.timer_interface*/ NULL,
- /*.dialplan_interface*/ NULL,
- /*.codec_interface*/ NULL,
- /*.application_interface*/ NULL
+ /*.module_name */ modname,
+ /*.endpoint_interface */ &exosip_endpoint_interface,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ NULL,
+ /*.application_interface */ NULL
};
{
if (globals.running) {
globals.running = -1;
- while(globals.running) {
+ while (globals.running) {
switch_yield(1000);
}
}
return SWITCH_STATUS_SUCCESS;
}
-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)
+{
/* NOTE: **interface is **_interface because the common lib redefines interface to struct in some situations */
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n");
return SWITCH_STATUS_TERM;
}
-
+
/* connect my internal structure to the blank pointer passed to me */
*interface = &exosip_module_interface;
return SWITCH_STATUS_SUCCESS;
}
-static switch_status exosip_create_call(eXosip_event_t *event)
+static switch_status exosip_create_call(eXosip_event_t * event)
{
switch_core_session *session;
sdp_message_t *remote_sdp = NULL;
switch_core_session_destroy(&session);
return SWITCH_STATUS_MEMERR;
}
-
+
if ((tech_pvt->caller_profile = switch_caller_profile_new(session,
- globals.dialplan,
- event->request->from->displayname,
- event->request->from->url->username,
- event->request->from->url->username,
- NULL,
- event->request->req_uri->username))) {
+ globals.dialplan,
+ event->request->from->displayname,
+ event->request->from->url->username,
+ event->request->from->url->username,
+ NULL, event->request->req_uri->username))) {
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
}
snprintf(name, sizeof(name), "Exosip/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
switch_channel_set_name(channel, name);
-
+
if (!(remote_sdp = eXosip_get_sdp_info(event->request))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Find Remote SDP!\n");
exosip_on_hangup(session);
tech_pvt->local_sdp_audio_port = next_rtp_port();
osip_rfc3264_init(&tech_pvt->sdp_config);
/* Add in what codecs we support locally */
-
- if ((num_codecs = loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, sizeof(codecs)/sizeof(codecs[0]))) > 0) {
+
+ if ((num_codecs =
+ loadable_module_get_codecs(switch_core_session_get_pool(session), codecs,
+ sizeof(codecs) / sizeof(codecs[0]))) > 0) {
int i;
static const switch_codec_implementation *imp;
for (i = 0; i < num_codecs; i++) {
int x = 0;
- for (imp = codecs[i]->implementations ; imp ; imp = imp->next) {
- sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second, x++);
+ for (imp = codecs[i]->implementations; imp; imp = imp->next) {
+ sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame,
+ imp->samples_per_second, x++);
}
}
}
sdp_message_parse(tech_pvt->local_sdp, local_sdp_str);
sdp_message_to_str(remote_sdp, &remote_sdp_str);
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "LOCAL SDP:\n%s\nREMOTE SDP:\n%s", local_sdp_str,remote_sdp_str);
-
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "LOCAL SDP:\n%s\nREMOTE SDP:\n%s", local_sdp_str, remote_sdp_str);
+
mline = 0;
- while (0==osip_rfc3264_match(tech_pvt->sdp_config, remote_sdp, audio_tab, video_tab, t38_tab, app_tab, mline)) {
+ while (0 == osip_rfc3264_match(tech_pvt->sdp_config, remote_sdp, audio_tab, video_tab, t38_tab, app_tab, mline)) {
if (audio_tab[0] == NULL && video_tab[0] == NULL && t38_tab[0] == NULL && app_tab[0] == NULL) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got no compatible codecs!\n");
break;
}
- for (pos=0; audio_tab[pos]!=NULL; pos++) {
- osip_rfc3264_complete_answer(tech_pvt->sdp_config, remote_sdp, tech_pvt->local_sdp, audio_tab[pos], mline);
+ for (pos = 0; audio_tab[pos] != NULL; pos++) {
+ osip_rfc3264_complete_answer(tech_pvt->sdp_config, remote_sdp, tech_pvt->local_sdp, audio_tab[pos],
+ mline);
if (parse_sdp_media(audio_tab[pos], &dname, &drate, &dpayload) == SWITCH_STATUS_SUCCESS) {
tech_pvt->payload_num = atoi(dpayload);
break;
mline++;
}
free(remote_sdp_str);
- sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", tech_pvt->local_sdp_audio_ip);
+ sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4",
+ tech_pvt->local_sdp_audio_ip);
sdp_message_s_name_set(tech_pvt->local_sdp, "SIP Call");
sdp_message_c_connection_add(tech_pvt->local_sdp, -1, "IN", "IP4", tech_pvt->local_sdp_audio_ip, NULL, NULL);
snprintf(port, sizeof(port), "%i", tech_pvt->local_sdp_audio_port);
snprintf(tech_pvt->remote_sdp_audio_ip, 50, conn->c_addr);
tech_pvt->remote_sdp_audio_port = atoi(remote_med->m_port);
-
+
snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", event->cid);
- switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
+ switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
if (!dname) {
exosip_on_hangup(session);
int rate = atoi(drate);
if (switch_core_codec_init(&tech_pvt->read_codec,
- dname,
- rate,
- globals.codec_ms,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL) != SWITCH_STATUS_SUCCESS) {
+ dname,
+ rate,
+ globals.codec_ms,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE;
} else {
if (switch_core_codec_init(&tech_pvt->write_codec,
- dname,
- rate,
- globals.codec_ms,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL) != SWITCH_STATUS_SUCCESS) {
+ dname,
+ rate,
+ globals.codec_ms,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE;
int ms;
switch_set_flag(tech_pvt, TFLAG_USING_CODEC);
ms = tech_pvt->write_codec.implementation->nanoseconds_per_frame / 1000;
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Inbound Codec %s/%d %d ms\n", dname, rate, ms);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Inbound Codec %s/%d %d ms\n", dname, rate,
+ ms);
tech_pvt->read_frame.codec = &tech_pvt->read_codec;
switch_core_session_set_read_codec(session, &tech_pvt->read_codec);
switch_core_session_set_write_codec(session, &tech_pvt->write_codec);
}
}
}
-
+
switch_core_session_thread_launch(session);
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Create new Inbound Channel!\n");
}
-static void destroy_call_by_event(eXosip_event_t *event)
+static void destroy_call_by_event(eXosip_event_t * event)
{
struct private_object *tech_pvt;
switch_channel *channel = NULL;
if (!(tech_pvt = get_pvt_by_call_id(event->cid))) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Um in case you are interested, Can't find the pvt [%d]!\n", event->cid);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Um in case you are interested, Can't find the pvt [%d]!\n",
+ event->cid);
return;
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "destroy %s\n", switch_channel_get_name(channel));
exosip_kill_channel(tech_pvt->session, SWITCH_SIG_KILL);
switch_channel_hangup(channel);
-
+
}
-static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload)
+static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **drate, char **dpayload)
{
int pos = 0;
sdp_attribute_t *attr = NULL;
switch_status status = SWITCH_STATUS_GENERR;
while (osip_list_eol(media->a_attributes, pos) == 0) {
- attr = (sdp_attribute_t *)osip_list_get(media->a_attributes, pos);
+ attr = (sdp_attribute_t *) osip_list_get(media->a_attributes, pos);
if (attr != NULL && strcasecmp(attr->a_att_field, "rtpmap") == 0) {
payload = attr->a_att_value;
if ((name = strchr(payload, ' '))) {
*dname = strdup("L16");
*drate = strdup("8000");
}
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Found negotiated codec Payload: %s Name: %s Rate: %s\n", *dpayload, *dname, *drate);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Found negotiated codec Payload: %s Name: %s Rate: %s\n",
+ *dpayload, *dname, *drate);
break;
}
attr = NULL;
return status;
}
-static void handle_answer(eXosip_event_t *event)
+static void handle_answer(eXosip_event_t * event)
{
osip_message_t *ack = NULL;
sdp_message_t *remote_sdp = NULL;
/* Assign them thar IDs */
tech_pvt->did = event->did;
tech_pvt->tid = event->tid;
-
+
if (1) {
int rate = atoi(drate);
- if (switch_core_codec_init(&tech_pvt->read_codec, dname, rate, globals.codec_ms, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) {
+ if (switch_core_codec_init
+ (&tech_pvt->read_codec, dname, rate, globals.codec_ms, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return;
} else {
- if (switch_core_codec_init(&tech_pvt->write_codec, dname, rate, globals.codec_ms, SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) {
+ if (switch_core_codec_init
+ (&tech_pvt->write_codec, dname, rate, globals.codec_ms,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return;
eXosip_call_build_ack(event->did, &ack);
eXosip_call_send_ack(event->did, ack);
eXosip_unlock();
-
+
free(dname);
free(drate);
free(dpayload);
}
-static void log_event(eXosip_event_t *je)
+static void log_event(eXosip_event_t * je)
{
char buf[100];
buf[0] = '\0';
if (je->type == EXOSIP_CALL_NOANSWER) {
- snprintf (buf, 99, "<- (%i %i) No answer", je->cid, je->did);
+ snprintf(buf, 99, "<- (%i %i) No answer", je->cid, je->did);
} else if (je->type == EXOSIP_CALL_CLOSED) {
- snprintf (buf, 99, "<- (%i %i) Call Closed", je->cid, je->did);
+ snprintf(buf, 99, "<- (%i %i) Call Closed", je->cid, je->did);
} else if (je->type == EXOSIP_CALL_RELEASED) {
- snprintf (buf, 99, "<- (%i %i) Call released", je->cid, je->did);
- } else if (je->type == EXOSIP_MESSAGE_NEW
- && je->request!=NULL && MSG_IS_MESSAGE(je->request)) {
+ snprintf(buf, 99, "<- (%i %i) Call released", je->cid, je->did);
+ } else if (je->type == EXOSIP_MESSAGE_NEW && je->request != NULL && MSG_IS_MESSAGE(je->request)) {
char *tmp = NULL;
-
+
if (je->request != NULL) {
osip_body_t *body;
- osip_from_to_str (je->request->from, &tmp);
-
- osip_message_get_body (je->request, 0, &body);
+ osip_from_to_str(je->request->from, &tmp);
+
+ osip_message_get_body(je->request, 0, &body);
if (body != NULL && body->body != NULL) {
- snprintf (buf, 99, "<- (%i) from: %s TEXT: %s",
- je->tid, tmp, body->body);
+ snprintf(buf, 99, "<- (%i) from: %s TEXT: %s", je->tid, tmp, body->body);
}
- osip_free (tmp);
+ osip_free(tmp);
} else {
- snprintf (buf, 99, "<- (%i) New event for unknown request?", je->tid);
+ snprintf(buf, 99, "<- (%i) New event for unknown request?", je->tid);
}
} else if (je->type == EXOSIP_MESSAGE_NEW) {
char *tmp = NULL;
-
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (%i) %s from: %s",
- je->tid, je->request->sip_method, tmp);
- osip_free (tmp);
+
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (%i) %s from: %s", je->tid, je->request->sip_method, tmp);
+ osip_free(tmp);
} else if (je->type == EXOSIP_MESSAGE_PROCEEDING
- || je->type == EXOSIP_MESSAGE_ANSWERED
- || je->type == EXOSIP_MESSAGE_REDIRECTED
- || je->type == EXOSIP_MESSAGE_REQUESTFAILURE
- || je->type == EXOSIP_MESSAGE_SERVERFAILURE
- || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) {
+ || je->type == EXOSIP_MESSAGE_ANSWERED
+ || je->type == EXOSIP_MESSAGE_REDIRECTED
+ || je->type == EXOSIP_MESSAGE_REQUESTFAILURE
+ || je->type == EXOSIP_MESSAGE_SERVERFAILURE || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) {
if (je->response != NULL && je->request != NULL) {
char *tmp = NULL;
-
- osip_to_to_str (je->request->to, &tmp);
- snprintf (buf, 99, "<- (%i) [%i %s for %s] to: %s",
- je->tid, je->response->status_code,
- je->response->reason_phrase, je->request->sip_method, tmp);
- osip_free (tmp);
+
+ osip_to_to_str(je->request->to, &tmp);
+ snprintf(buf, 99, "<- (%i) [%i %s for %s] to: %s",
+ je->tid, je->response->status_code, je->response->reason_phrase, je->request->sip_method, tmp);
+ osip_free(tmp);
} else if (je->request != NULL) {
- snprintf (buf, 99, "<- (%i) Error for %s request",
- je->tid, je->request->sip_method);
+ snprintf(buf, 99, "<- (%i) Error for %s request", je->tid, je->request->sip_method);
} else {
- snprintf (buf, 99, "<- (%i) Error for unknown request", je->tid);
+ snprintf(buf, 99, "<- (%i) Error for unknown request", je->tid);
}
} else if (je->response == NULL && je->request != NULL && je->cid > 0) {
char *tmp = NULL;
-
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (%i %i) %s from: %s",
- je->cid, je->did, je->request->cseq->method, tmp);
- osip_free (tmp);
+
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (%i %i) %s from: %s", je->cid, je->did, je->request->cseq->method, tmp);
+ osip_free(tmp);
} else if (je->response != NULL && je->cid > 0) {
char *tmp = NULL;
-
- osip_to_to_str (je->request->to, &tmp);
- snprintf (buf, 99, "<- (%i %i) [%i %s] for %s to: %s",
- je->cid, je->did, je->response->status_code,
- je->response->reason_phrase, je->request->sip_method, tmp);
- osip_free (tmp);
+
+ osip_to_to_str(je->request->to, &tmp);
+ snprintf(buf, 99, "<- (%i %i) [%i %s] for %s to: %s",
+ je->cid, je->did, je->response->status_code,
+ je->response->reason_phrase, je->request->sip_method, tmp);
+ osip_free(tmp);
} else if (je->response == NULL && je->request != NULL && je->rid > 0) {
char *tmp = NULL;
-
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (%i) %s from: %s",
- je->rid, je->request->cseq->method, tmp);
- osip_free (tmp);
+
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (%i) %s from: %s", je->rid, je->request->cseq->method, tmp);
+ osip_free(tmp);
} else if (je->response != NULL && je->rid > 0) {
char *tmp = NULL;
-
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (%i) [%i %s] from: %s",
- je->rid, je->response->status_code,
- je->response->reason_phrase, tmp);
- osip_free (tmp);
+
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (%i) [%i %s] from: %s",
+ je->rid, je->response->status_code, je->response->reason_phrase, tmp);
+ osip_free(tmp);
} else if (je->response == NULL && je->request != NULL && je->sid > 0) {
char *tmp = NULL;
char *stat = NULL;
osip_header_t *sub_state;
-
- osip_message_header_get_byname (je->request, "subscription-state",
- 0, &sub_state);
+
+ osip_message_header_get_byname(je->request, "subscription-state", 0, &sub_state);
if (sub_state != NULL && sub_state->hvalue != NULL)
stat = sub_state->hvalue;
-
- osip_uri_to_str (je->request->from->url, &tmp);
- snprintf (buf, 99, "<- (%i) [%s] %s from: %s",
- je->sid, stat, je->request->cseq->method, tmp);
- osip_free (tmp);
+
+ osip_uri_to_str(je->request->from->url, &tmp);
+ snprintf(buf, 99, "<- (%i) [%s] %s from: %s", je->sid, stat, je->request->cseq->method, tmp);
+ osip_free(tmp);
} else if (je->response != NULL && je->sid > 0) {
char *tmp = NULL;
-
- osip_uri_to_str (je->request->to->url, &tmp);
- snprintf (buf, 99, "<- (%i) [%i %s] from: %s",
- je->sid, je->response->status_code,
- je->response->reason_phrase, tmp);
- osip_free (tmp);
+
+ osip_uri_to_str(je->request->to->url, &tmp);
+ snprintf(buf, 99, "<- (%i) [%i %s] from: %s",
+ je->sid, je->response->status_code, je->response->reason_phrase, tmp);
+ osip_free(tmp);
} else if (je->response == NULL && je->request != NULL) {
char *tmp = NULL;
-
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s",
- je->cid, je->did, je->sid, je->nid,
- je->request->sip_method, tmp);
- osip_free (tmp);
+
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s",
+ je->cid, je->did, je->sid, je->nid, je->request->sip_method, tmp);
+ osip_free(tmp);
} else if (je->response != NULL) {
char *tmp = NULL;
-
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) [%i %s] for %s from: %s",
- je->cid, je->did, je->sid, je->nid,
- je->response->status_code, je->response->reason_phrase,
- je->request->sip_method, tmp);
- osip_free (tmp);
+
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) [%i %s] for %s from: %s",
+ je->cid, je->did, je->sid, je->nid,
+ je->response->status_code, je->response->reason_phrase, je->request->sip_method, tmp);
+ osip_free(tmp);
} else {
- snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i|t=%i) %s",
- je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo);
+ snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i|t=%i) %s",
+ je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo);
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\n%s\n", buf);
/* Print it out */
static void *monitor_thread_run(void)
{
eXosip_event_t *event = NULL;
-
+
globals.running = 1;
while (globals.running > 0) {
- if (!(event = eXosip_event_wait(0,100))) {
+ if (!(event = eXosip_event_wait(0, 100))) {
switch_yield(100);
continue;
}
eXosip_lock();
- eXosip_automatic_action ();
+ eXosip_automatic_action();
eXosip_unlock();
log_event(event);
- switch(event->type) {
+ switch (event->type) {
case EXOSIP_CALL_INVITE:
exosip_create_call(event);
break;
}
-static int config_exosip(int reload)
+static int config_exosip(int reload)
{
switch_config cfg;
char *var, *val;
}
}
}
-
+
if (!globals.codec_ms) {
globals.codec_ms = 20;
}
set_global_dialplan("default");
}
- if (eXosip_init ()) {
+ if (eXosip_init()) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_init initialization failed!\n");
return SWITCH_STATUS_GENERR;
}
- if (eXosip_listen_addr (IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) {
+ if (eXosip_listen_addr(IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_listen_addr failed!\n");
return SWITCH_STATUS_GENERR;
}
config_exosip(0);
return SWITCH_STATUS_TERM;
}
-
TFLAG_DTMF = (1 << 3),
TFLAG_READING = (1 << 4),
TFLAG_WRITING = (1 << 5),
- TFLAG_USING_CODEC = (1 << 6),
+ TFLAG_USING_CODEC = (1 << 6),
TFLAG_RTP = (1 << 7),
TFLAG_BYE = (1 << 8)
} TFLAGS;
} globals;
struct private_object {
- unsigned int flags;
+ unsigned int flags;
switch_core_session *session;
switch_frame read_frame;
switch_codec read_codec;
int32_t timestamp_send;
int32_t timestamp_recv;
int payload_num;
- struct rtp *rtp_session;
+ struct rtp *rtp_session;
struct osip_rfc3264 *sdp_config;
sdp_message_t *remote_sdp;
sdp_message_t *local_sdp;
free(globals.dialplan);
globals.dialplan = NULL;
}
-
+
globals.dialplan = strdup(dialplan);
}
static switch_status exosip_on_hangup(switch_core_session *session);
static switch_status exosip_on_loopback(switch_core_session *session);
static switch_status exosip_on_transmit(switch_core_session *session);
-static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session);
-static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags);
-static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags);
+static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
+ switch_core_session **new_session);
+static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags);
+static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags);
static int config_exosip(int reload);
-static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload);
+static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **drate, char **dpayload);
static switch_status exosip_kill_channel(switch_core_session *session, int sig);
static void activate_rtp(struct private_object *tech_pvt);
static void deactivate_rtp(struct private_object *tech_pvt);
default:
break;
}
- return 0;
+ return 0;
}
char *dest_uri;
switch_codec_interface *codecs[512];
int num_codecs = 0;
- /* do SIP Goodies...*/
+ /* do SIP Goodies... */
/* Generate callerid URI */
eXosip_guess_localip(AF_INET, localip, 128);
/* Initialize SDP */
sdp_message_init(&tech_pvt->local_sdp);
sdp_message_v_version_set(tech_pvt->local_sdp, "0");
- sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", tech_pvt->local_sdp_audio_ip);
+ sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4",
+ tech_pvt->local_sdp_audio_ip);
sdp_message_s_name_set(tech_pvt->local_sdp, "SIP Call");
sdp_message_c_connection_add(tech_pvt->local_sdp, -1, "IN", "IP4", tech_pvt->local_sdp_audio_ip, NULL, NULL);
sdp_message_t_time_descr_add(tech_pvt->local_sdp, "0", "0");
snprintf(port, sizeof(port), "%i", tech_pvt->local_sdp_audio_port);
sdp_message_m_media_add(tech_pvt->local_sdp, "audio", port, NULL, "RTP/AVP");
/* Add in every codec we support on this outbound call */
- if ((num_codecs = loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, sizeof(codecs)/sizeof(codecs[0]))) > 0) {
+ if ((num_codecs =
+ loadable_module_get_codecs(switch_core_session_get_pool(session), codecs,
+ sizeof(codecs) / sizeof(codecs[0]))) > 0) {
int i;
static const switch_codec_implementation *imp;
for (i = 0; i < num_codecs; i++) {
snprintf(tmp, sizeof(tmp), "%i", codecs[i]->ianacode);
sdp_message_m_payload_add(tech_pvt->local_sdp, 0, osip_strdup(tmp));
- for (imp = codecs[i]->implementations ; imp ; imp = imp->next) {
+ for (imp = codecs[i]->implementations; imp; imp = imp->next) {
/* Add to SDP config */
- sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second, x++);
+ sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame,
+ imp->samples_per_second, x++);
/* Add to SDP message */
- snprintf(tmp, sizeof(tmp), "%i %s/%i", codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second);
+ snprintf(tmp, sizeof(tmp), "%i %s/%i", codecs[i]->ianacode, codecs[i]->iananame,
+ imp->samples_per_second);
sdp_message_a_attribute_add(tech_pvt->local_sdp, 0, "rtpmap", osip_strdup(tmp));
memset(tmp, 0, sizeof(tmp));
}
}
/* Setup our INVITE */
eXosip_lock();
- if (!(dest_uri = (char *) switch_core_session_alloc(session, strlen(tech_pvt->caller_profile->destination_number) + 10))) {
+ if (!
+ (dest_uri =
+ (char *) switch_core_session_alloc(session, strlen(tech_pvt->caller_profile->destination_number) + 10))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "AIEEEE!\n");
assert(dest_uri != NULL);
}
switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
tech_pvt->did = -1;
eXosip_unlock();
- }
+ }
/* Let Media Work */
assert(tech_pvt != NULL);
- switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
-
+ switch_core_hash_delete(globals.call_hash, tech_pvt->call_id);
+
switch_set_flag(tech_pvt, TFLAG_BYE);
switch_clear_flag(tech_pvt, TFLAG_IO);
switch_core_codec_destroy(&tech_pvt->write_codec);
}
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "EXOSIP HANGUP %s %d/%d=%d\n", switch_channel_get_name(channel), tech_pvt->cid, tech_pvt->did, i);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "EXOSIP HANGUP %s %d/%d=%d\n", switch_channel_get_name(channel),
+ tech_pvt->cid, tech_pvt->did, i);
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_SUCCESS;
}
-static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session)
+static switch_status exosip_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
+ switch_core_session **new_session)
{
if ((*new_session = switch_core_session_request(&exosip_endpoint_interface, NULL))) {
struct private_object *tech_pvt;
switch_caller_profile *caller_profile, *originator_caller_profile = NULL;
switch_core_session_add_stream(*new_session, NULL);
- if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
+ if ((tech_pvt =
+ (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
channel = switch_core_session_get_channel(*new_session);
switch_core_session_set_private(*new_session, tech_pvt);
switch_channel_set_originator_caller_profile(channel, cloned_profile);
}
}
-
+
switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT);
#if 0
static const char *event_names[] = {
"RX_RTP",
- "RX_SR",
+ "RX_SR",
"RX_RR",
"RX_SDES",
"RX_BYE",
};
#endif
-static void rtp_event_handler(struct rtp *session, rtp_event *event)
+static void rtp_event_handler(struct rtp *session, rtp_event * event)
{
- rtp_packet *packet;
+ rtp_packet *packet;
struct private_object *tech_pvt = (struct private_object *) rtp_get_userdata(session);
if (!session) {
return;
}
+ //switch_console_printf(SWITCH_CHANNEL_CONSOLE, "RTP EVENT (%s)\n", event_names[event->type]);
- //switch_console_printf(SWITCH_CHANNEL_CONSOLE, "RTP EVENT (%s)\n", event_names[event->type]);
-
- switch(event->type) {
+ switch (event->type) {
case RX_RTP:
- if((packet = (rtp_packet *) event->data)) {
+ if ((packet = (rtp_packet *) event->data)) {
if (packet->data_len < 10000) {
memcpy(tech_pvt->read_buf, packet->data, packet->data_len);
tech_pvt->read_frame.datalen = packet->data_len;
} else {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF PACKET LEN %d\n", packet->data_len);
- }
- free(packet); /* xfree() is mandatory to release RTP packet data */
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF PACKET LEN %d\n", packet->data_len);
+ }
+ free(packet); /* xfree() is mandatory to release RTP packet data */
}
- break;
+ break;
case RR_TIMEOUT:
case RX_BYE:
switch_set_flag(tech_pvt, TFLAG_BYE);
if (tech_pvt->rtp_session) {
//switch_mutex_lock(tech_pvt->rtp_lock);
- while(loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) {
+ while (loops < 10 && (switch_test_flag(tech_pvt, TFLAG_READING) || switch_test_flag(tech_pvt, TFLAG_WRITING))) {
switch_yield(10000);
loops++;
}
assert(channel != NULL);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activating RTP %d->%s:%d\n",
- tech_pvt->local_sdp_audio_port,
- tech_pvt->remote_sdp_audio_ip,
- tech_pvt->remote_sdp_audio_port);
+ tech_pvt->local_sdp_audio_port,
+ tech_pvt->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_port);
//switch_mutex_lock(tech_pvt->rtp_lock);
bw *= 8;
}
- tech_pvt->rtp_session = rtp_init(tech_pvt->remote_sdp_audio_ip, /* Host/Group IP address */
+ tech_pvt->rtp_session = rtp_init(tech_pvt->remote_sdp_audio_ip, /* Host/Group IP address */
tech_pvt->local_sdp_audio_port, /* receive port */
tech_pvt->remote_sdp_audio_port, /* transmit port */
- ms * 2, /* time-to-live */
- bw, /* B/W estimate */
- rtp_event_handler, /* RTP event callback */
- (void *) tech_pvt); /* App. specific data */
+ ms * 2, /* time-to-live */
+ bw, /* B/W estimate */
+ rtp_event_handler, /* RTP event callback */
+ (void *) tech_pvt); /* App. specific data */
if (tech_pvt->rtp_session) {
rtp_set_sdes(tech_pvt->rtp_session, tech_pvt->ssrc, RTCP_SDES_NAME, "test", 4);
rtp_set_sdes(tech_pvt->rtp_session, tech_pvt->ssrc, RTCP_SDES_PHONE, "test", 4);
rtp_set_sdes(tech_pvt->rtp_session, tech_pvt->ssrc, RTCP_SDES_TOOL, "test", 4);
- switch_set_flag(tech_pvt, TFLAG_RTP);
+ switch_set_flag(tech_pvt, TFLAG_RTP);
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Oh oh is your port even?\n");
}
sdp_message_to_str(tech_pvt->local_sdp, &buf);
osip_message_set_body(answer, buf, strlen(buf));
osip_message_set_content_type(answer, "application/sdp");
- free(buf);
+ free(buf);
eXosip_call_send_answer(tech_pvt->tid, 200, answer);
eXosip_unlock();
- }
+ }
return SWITCH_STATUS_SUCCESS;
}
-static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags)
+static switch_status exosip_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags)
{
struct private_object *tech_pvt = NULL;
size_t bytes = 0, samples = 0, frames, ms, x;
switch_channel *channel = NULL;
- int ns=0;
+ int ns = 0;
struct timeval tv;
channel = switch_core_session_get_channel(session);
//switch_mutex_lock(tech_pvt->rtp_lock);
tv.tv_sec = 0;
tv.tv_usec = ns;
- while(switch_test_flag(tech_pvt, TFLAG_IO) && !switch_test_flag(tech_pvt, TFLAG_BYE)) {
+ while (switch_test_flag(tech_pvt, TFLAG_IO) && !switch_test_flag(tech_pvt, TFLAG_BYE)) {
x = rtp_recv(tech_pvt->rtp_session, &tv, tech_pvt->timestamp_recv);
- if(x < 0) {
+ if (x < 0) {
break;
}
if (tech_pvt->read_frame.datalen) {
break;
}
}
- tech_pvt->timestamp_recv += (int)samples;
+ tech_pvt->timestamp_recv += (int) samples;
//printf("%s\trecv %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->read_frame.datalen, samples, frames, ms, tech_pvt->timestamp_recv);
//switch_mutex_unlock(tech_pvt->rtp_lock);
}
-static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags)
+static switch_status exosip_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags)
{
struct private_object *tech_pvt;
switch_channel *channel = NULL;
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
+
if (!switch_test_flag(tech_pvt, TFLAG_RTP)) {
activate_rtp(tech_pvt);
}
} else {
assert(0);
}
- tech_pvt->timestamp_send += (int)samples;
+ tech_pvt->timestamp_send += (int) samples;
//printf("%s %s->%s send %d bytes %d samples in %d frames taking up %d ms ts=%d\n", switch_channel_get_name(channel), tech_pvt->local_sdp_audio_ip, tech_pvt->remote_sdp_audio_ip, frame->datalen, samples, frames, ms, tech_pvt->timestamp_recv);
-
+
rtp_send_ctrl(tech_pvt->rtp_session, tech_pvt->timestamp_send, NULL);
x = rtp_send_data(tech_pvt->rtp_session, tech_pvt->timestamp_send, tech_pvt->payload_num,
- 0, 0, 0,
- (char *)frame->data, (int)frame->datalen,
- 0, 0, 0);
+ 0, 0, 0, (char *) frame->data, (int) frame->datalen, 0, 0, 0);
switch_clear_flag(tech_pvt, TFLAG_WRITING);
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
+
return SWITCH_STATUS_SUCCESS;
}
-
+
static const switch_io_routines exosip_io_routines = {
- /*.outgoing_channel*/ exosip_outgoing_channel,
- /*.answer_channel*/ exosip_answer_channel,
- /*.read_frame*/ exosip_read_frame,
- /*.write_frame*/ exosip_write_frame,
- /*.kill_channel*/ exosip_kill_channel,
- /*.waitfor_read*/ exosip_waitfor_read,
- /*.waitfor_read*/ exosip_waitfor_write
+ /*.outgoing_channel */ exosip_outgoing_channel,
+ /*.answer_channel */ exosip_answer_channel,
+ /*.read_frame */ exosip_read_frame,
+ /*.write_frame */ exosip_write_frame,
+ /*.kill_channel */ exosip_kill_channel,
+ /*.waitfor_read */ exosip_waitfor_read,
+ /*.waitfor_read */ exosip_waitfor_write
};
-static const switch_event_handler_table exosip_event_handlers = {
- /*.on_init*/ exosip_on_init,
- /*.on_ring*/ exosip_on_ring,
- /*.on_execute*/ exosip_on_execute,
- /*.on_hangup*/ exosip_on_hangup,
- /*.on_loopback*/ exosip_on_loopback,
- /*.on_transmit*/ exosip_on_transmit
+static const switch_event_handler_table exosip_event_handlers = {
+ /*.on_init */ exosip_on_init,
+ /*.on_ring */ exosip_on_ring,
+ /*.on_execute */ exosip_on_execute,
+ /*.on_hangup */ exosip_on_hangup,
+ /*.on_loopback */ exosip_on_loopback,
+ /*.on_transmit */ exosip_on_transmit
};
static const switch_endpoint_interface exosip_endpoint_interface = {
- /*.interface_name*/ "exosip",
- /*.io_routines*/ &exosip_io_routines,
- /*.event_handlers*/ &exosip_event_handlers,
- /*.private*/ NULL,
- /*.next*/ NULL
+ /*.interface_name */ "exosip",
+ /*.io_routines */ &exosip_io_routines,
+ /*.event_handlers */ &exosip_event_handlers,
+ /*.private */ NULL,
+ /*.next */ NULL
};
static const switch_loadable_module_interface exosip_module_interface = {
- /*.module_name*/ modname,
- /*.endpoint_interface*/ &exosip_endpoint_interface,
- /*.timer_interface*/ NULL,
- /*.dialplan_interface*/ NULL,
- /*.codec_interface*/ NULL,
- /*.application_interface*/ NULL
+ /*.module_name */ modname,
+ /*.endpoint_interface */ &exosip_endpoint_interface,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ NULL,
+ /*.application_interface */ NULL
};
{
if (globals.running) {
globals.running = -1;
- while(globals.running) {
+ while (globals.running) {
switch_yield(1000);
}
}
return SWITCH_STATUS_SUCCESS;
}
-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)
+{
/* NOTE: **interface is **_interface because the common lib redefines interface to struct in some situations */
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n");
return SWITCH_STATUS_TERM;
}
-
+
/* connect my internal structure to the blank pointer passed to me */
*_interface = &exosip_module_interface;
return SWITCH_STATUS_SUCCESS;
}
-static switch_status exosip_create_call(eXosip_event_t *event)
+static switch_status exosip_create_call(eXosip_event_t * event)
{
switch_core_session *session;
sdp_message_t *remote_sdp = NULL;
switch_core_session_destroy(&session);
return SWITCH_STATUS_MEMERR;
}
-
+
if ((tech_pvt->caller_profile = switch_caller_profile_new(session,
- globals.dialplan,
- event->request->from->displayname,
- event->request->from->url->username,
- event->request->from->url->username,
- NULL,
- event->request->req_uri->username))) {
+ globals.dialplan,
+ event->request->from->displayname,
+ event->request->from->url->username,
+ event->request->from->url->username,
+ NULL, event->request->req_uri->username))) {
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
}
snprintf(name, sizeof(name), "Exosip/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
switch_channel_set_name(channel, name);
-
+
if (!(remote_sdp = eXosip_get_sdp_info(event->request))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Find Remote SDP!\n");
exosip_on_hangup(session);
tech_pvt->local_sdp_audio_port = next_rtp_port();
osip_rfc3264_init(&tech_pvt->sdp_config);
/* Add in what codecs we support locally */
-
- if ((num_codecs = loadable_module_get_codecs(switch_core_session_get_pool(session), codecs, sizeof(codecs)/sizeof(codecs[0]))) > 0) {
+
+ if ((num_codecs =
+ loadable_module_get_codecs(switch_core_session_get_pool(session), codecs,
+ sizeof(codecs) / sizeof(codecs[0]))) > 0) {
int i;
static const switch_codec_implementation *imp;
for (i = 0; i < num_codecs; i++) {
int x = 0;
- for (imp = codecs[i]->implementations ; imp ; imp = imp->next) {
- sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame, imp->samples_per_second, x++);
+ for (imp = codecs[i]->implementations; imp; imp = imp->next) {
+ sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame,
+ imp->samples_per_second, x++);
}
}
}
sdp_message_parse(tech_pvt->local_sdp, local_sdp_str);
sdp_message_to_str(remote_sdp, &remote_sdp_str);
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "LOCAL SDP:\n%s\nREMOTE SDP:\n%s", local_sdp_str,remote_sdp_str);
-
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "LOCAL SDP:\n%s\nREMOTE SDP:\n%s", local_sdp_str, remote_sdp_str);
+
mline = 0;
- while (0==osip_rfc3264_match(tech_pvt->sdp_config, remote_sdp, audio_tab, video_tab, t38_tab, app_tab, mline)) {
+ while (0 == osip_rfc3264_match(tech_pvt->sdp_config, remote_sdp, audio_tab, video_tab, t38_tab, app_tab, mline)) {
if (audio_tab[0] == NULL && video_tab[0] == NULL && t38_tab[0] == NULL && app_tab[0] == NULL) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Got no compatible codecs!\n");
break;
}
- for (pos=0; audio_tab[pos]!=NULL; pos++) {
- osip_rfc3264_complete_answer(tech_pvt->sdp_config, remote_sdp, tech_pvt->local_sdp, audio_tab[pos], mline);
+ for (pos = 0; audio_tab[pos] != NULL; pos++) {
+ osip_rfc3264_complete_answer(tech_pvt->sdp_config, remote_sdp, tech_pvt->local_sdp, audio_tab[pos],
+ mline);
if (parse_sdp_media(audio_tab[pos], &dname, &drate, &dpayload) == SWITCH_STATUS_SUCCESS) {
tech_pvt->payload_num = atoi(dpayload);
break;
mline++;
}
free(remote_sdp_str);
- sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4", tech_pvt->local_sdp_audio_ip);
+ sdp_message_o_origin_set(tech_pvt->local_sdp, "OpenSWITCH2", "0", "0", "IN", "IP4",
+ tech_pvt->local_sdp_audio_ip);
sdp_message_s_name_set(tech_pvt->local_sdp, "SIP Call");
sdp_message_c_connection_add(tech_pvt->local_sdp, -1, "IN", "IP4", tech_pvt->local_sdp_audio_ip, NULL, NULL);
snprintf(port, sizeof(port), "%i", tech_pvt->local_sdp_audio_port);
snprintf(tech_pvt->remote_sdp_audio_ip, 50, conn->c_addr);
tech_pvt->remote_sdp_audio_port = atoi(remote_med->m_port);
-
+
snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", event->cid);
- switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
+ switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
if (!dname) {
exosip_on_hangup(session);
int rate = atoi(drate);
if (switch_core_codec_init(&tech_pvt->read_codec,
- dname,
- rate,
- globals.codec_ms,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL) != SWITCH_STATUS_SUCCESS) {
+ dname,
+ rate,
+ globals.codec_ms,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE;
} else {
if (switch_core_codec_init(&tech_pvt->write_codec,
- dname,
- rate,
- globals.codec_ms,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL) != SWITCH_STATUS_SUCCESS) {
+ dname,
+ rate,
+ globals.codec_ms,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE;
int ms;
switch_set_flag(tech_pvt, TFLAG_USING_CODEC);
ms = tech_pvt->write_codec.implementation->nanoseconds_per_frame / 1000;
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Inbound Codec %s/%d %d ms\n", dname, rate, ms);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Activate Inbound Codec %s/%d %d ms\n", dname, rate,
+ ms);
tech_pvt->read_frame.codec = &tech_pvt->read_codec;
switch_core_session_set_read_codec(session, &tech_pvt->read_codec);
switch_core_session_set_write_codec(session, &tech_pvt->write_codec);
}
}
}
-
+
switch_core_session_thread_launch(session);
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Cannot Create new Inbound Channel!\n");
}
-static void destroy_call_by_event(eXosip_event_t *event)
+static void destroy_call_by_event(eXosip_event_t * event)
{
struct private_object *tech_pvt;
switch_channel *channel = NULL;
if (!(tech_pvt = get_pvt_by_call_id(event->cid))) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Um in case you are interested, Can't find the pvt [%d]!\n", event->cid);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Um in case you are interested, Can't find the pvt [%d]!\n",
+ event->cid);
return;
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "destroy %s\n", switch_channel_get_name(channel));
exosip_kill_channel(tech_pvt->session, SWITCH_SIG_KILL);
switch_channel_hangup(channel);
-
+
}
-static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **drate, char **dpayload)
+static switch_status parse_sdp_media(sdp_media_t * media, char **dname, char **drate, char **dpayload)
{
int pos = 0;
sdp_attribute_t *attr = NULL;
switch_status status = SWITCH_STATUS_GENERR;
while (osip_list_eol(media->a_attributes, pos) == 0) {
- attr = (sdp_attribute_t *)osip_list_get(media->a_attributes, pos);
+ attr = (sdp_attribute_t *) osip_list_get(media->a_attributes, pos);
if (attr != NULL && strcasecmp(attr->a_att_field, "rtpmap") == 0) {
payload = attr->a_att_value;
if ((name = strchr(payload, ' '))) {
*dname = strdup("L16");
*drate = strdup("8000");
}
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Found negotiated codec Payload: %s Name: %s Rate: %s\n", *dpayload, *dname, *drate);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Found negotiated codec Payload: %s Name: %s Rate: %s\n",
+ *dpayload, *dname, *drate);
break;
}
attr = NULL;
return status;
}
-static void handle_answer(eXosip_event_t *event)
+static void handle_answer(eXosip_event_t * event)
{
osip_message_t *ack = NULL;
sdp_message_t *remote_sdp = NULL;
/* Assign them thar IDs */
tech_pvt->did = event->did;
tech_pvt->tid = event->tid;
-
+
if (1) {
int rate = atoi(drate);
- if (switch_core_codec_init(&tech_pvt->read_codec, dname, rate, globals.codec_ms, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) {
+ if (switch_core_codec_init
+ (&tech_pvt->read_codec, dname, rate, globals.codec_ms, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return;
} else {
- if (switch_core_codec_init(&tech_pvt->write_codec, dname, rate, globals.codec_ms, SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) {
+ if (switch_core_codec_init
+ (&tech_pvt->write_codec, dname, rate, globals.codec_ms,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
switch_channel_hangup(channel);
return;
eXosip_call_build_ack(event->did, &ack);
eXosip_call_send_ack(event->did, ack);
eXosip_unlock();
-
+
free(dname);
free(drate);
free(dpayload);
}
-static void log_event(eXosip_event_t *je)
+static void log_event(eXosip_event_t * je)
{
char buf[100];
buf[0] = '\0';
if (je->type == EXOSIP_CALL_NOANSWER) {
- snprintf (buf, 99, "<- (%i %i) No answer", je->cid, je->did);
+ snprintf(buf, 99, "<- (%i %i) No answer", je->cid, je->did);
} else if (je->type == EXOSIP_CALL_CLOSED) {
- snprintf (buf, 99, "<- (%i %i) Call Closed", je->cid, je->did);
+ snprintf(buf, 99, "<- (%i %i) Call Closed", je->cid, je->did);
} else if (je->type == EXOSIP_CALL_RELEASED) {
- snprintf (buf, 99, "<- (%i %i) Call released", je->cid, je->did);
- } else if (je->type == EXOSIP_MESSAGE_NEW
- && je->request!=NULL && MSG_IS_MESSAGE(je->request)) {
+ snprintf(buf, 99, "<- (%i %i) Call released", je->cid, je->did);
+ } else if (je->type == EXOSIP_MESSAGE_NEW && je->request != NULL && MSG_IS_MESSAGE(je->request)) {
char *tmp = NULL;
-
+
if (je->request != NULL) {
osip_body_t *body;
- osip_from_to_str (je->request->from, &tmp);
-
- osip_message_get_body (je->request, 0, &body);
+ osip_from_to_str(je->request->from, &tmp);
+
+ osip_message_get_body(je->request, 0, &body);
if (body != NULL && body->body != NULL) {
- snprintf (buf, 99, "<- (%i) from: %s TEXT: %s",
- je->tid, tmp, body->body);
+ snprintf(buf, 99, "<- (%i) from: %s TEXT: %s", je->tid, tmp, body->body);
}
- osip_free (tmp);
+ osip_free(tmp);
} else {
- snprintf (buf, 99, "<- (%i) New event for unknown request?", je->tid);
+ snprintf(buf, 99, "<- (%i) New event for unknown request?", je->tid);
}
} else if (je->type == EXOSIP_MESSAGE_NEW) {
char *tmp = NULL;
-
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (%i) %s from: %s",
- je->tid, je->request->sip_method, tmp);
- osip_free (tmp);
+
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (%i) %s from: %s", je->tid, je->request->sip_method, tmp);
+ osip_free(tmp);
} else if (je->type == EXOSIP_MESSAGE_PROCEEDING
- || je->type == EXOSIP_MESSAGE_ANSWERED
- || je->type == EXOSIP_MESSAGE_REDIRECTED
- || je->type == EXOSIP_MESSAGE_REQUESTFAILURE
- || je->type == EXOSIP_MESSAGE_SERVERFAILURE
- || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) {
+ || je->type == EXOSIP_MESSAGE_ANSWERED
+ || je->type == EXOSIP_MESSAGE_REDIRECTED
+ || je->type == EXOSIP_MESSAGE_REQUESTFAILURE
+ || je->type == EXOSIP_MESSAGE_SERVERFAILURE || je->type == EXOSIP_MESSAGE_GLOBALFAILURE) {
if (je->response != NULL && je->request != NULL) {
char *tmp = NULL;
-
- osip_to_to_str (je->request->to, &tmp);
- snprintf (buf, 99, "<- (%i) [%i %s for %s] to: %s",
- je->tid, je->response->status_code,
- je->response->reason_phrase, je->request->sip_method, tmp);
- osip_free (tmp);
+
+ osip_to_to_str(je->request->to, &tmp);
+ snprintf(buf, 99, "<- (%i) [%i %s for %s] to: %s",
+ je->tid, je->response->status_code, je->response->reason_phrase, je->request->sip_method, tmp);
+ osip_free(tmp);
} else if (je->request != NULL) {
- snprintf (buf, 99, "<- (%i) Error for %s request",
- je->tid, je->request->sip_method);
+ snprintf(buf, 99, "<- (%i) Error for %s request", je->tid, je->request->sip_method);
} else {
- snprintf (buf, 99, "<- (%i) Error for unknown request", je->tid);
+ snprintf(buf, 99, "<- (%i) Error for unknown request", je->tid);
}
} else if (je->response == NULL && je->request != NULL && je->cid > 0) {
char *tmp = NULL;
-
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (%i %i) %s from: %s",
- je->cid, je->did, je->request->cseq->method, tmp);
- osip_free (tmp);
+
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (%i %i) %s from: %s", je->cid, je->did, je->request->cseq->method, tmp);
+ osip_free(tmp);
} else if (je->response != NULL && je->cid > 0) {
char *tmp = NULL;
-
- osip_to_to_str (je->request->to, &tmp);
- snprintf (buf, 99, "<- (%i %i) [%i %s] for %s to: %s",
- je->cid, je->did, je->response->status_code,
- je->response->reason_phrase, je->request->sip_method, tmp);
- osip_free (tmp);
+
+ osip_to_to_str(je->request->to, &tmp);
+ snprintf(buf, 99, "<- (%i %i) [%i %s] for %s to: %s",
+ je->cid, je->did, je->response->status_code,
+ je->response->reason_phrase, je->request->sip_method, tmp);
+ osip_free(tmp);
} else if (je->response == NULL && je->request != NULL && je->rid > 0) {
char *tmp = NULL;
-
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (%i) %s from: %s",
- je->rid, je->request->cseq->method, tmp);
- osip_free (tmp);
+
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (%i) %s from: %s", je->rid, je->request->cseq->method, tmp);
+ osip_free(tmp);
} else if (je->response != NULL && je->rid > 0) {
char *tmp = NULL;
-
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (%i) [%i %s] from: %s",
- je->rid, je->response->status_code,
- je->response->reason_phrase, tmp);
- osip_free (tmp);
+
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (%i) [%i %s] from: %s",
+ je->rid, je->response->status_code, je->response->reason_phrase, tmp);
+ osip_free(tmp);
} else if (je->response == NULL && je->request != NULL && je->sid > 0) {
char *tmp = NULL;
char *stat = NULL;
osip_header_t *sub_state;
-
- osip_message_header_get_byname (je->request, "subscription-state",
- 0, &sub_state);
+
+ osip_message_header_get_byname(je->request, "subscription-state", 0, &sub_state);
if (sub_state != NULL && sub_state->hvalue != NULL)
stat = sub_state->hvalue;
-
- osip_uri_to_str (je->request->from->url, &tmp);
- snprintf (buf, 99, "<- (%i) [%s] %s from: %s",
- je->sid, stat, je->request->cseq->method, tmp);
- osip_free (tmp);
+
+ osip_uri_to_str(je->request->from->url, &tmp);
+ snprintf(buf, 99, "<- (%i) [%s] %s from: %s", je->sid, stat, je->request->cseq->method, tmp);
+ osip_free(tmp);
} else if (je->response != NULL && je->sid > 0) {
char *tmp = NULL;
-
- osip_uri_to_str (je->request->to->url, &tmp);
- snprintf (buf, 99, "<- (%i) [%i %s] from: %s",
- je->sid, je->response->status_code,
- je->response->reason_phrase, tmp);
- osip_free (tmp);
+
+ osip_uri_to_str(je->request->to->url, &tmp);
+ snprintf(buf, 99, "<- (%i) [%i %s] from: %s",
+ je->sid, je->response->status_code, je->response->reason_phrase, tmp);
+ osip_free(tmp);
} else if (je->response == NULL && je->request != NULL) {
char *tmp = NULL;
-
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s",
- je->cid, je->did, je->sid, je->nid,
- je->request->sip_method, tmp);
- osip_free (tmp);
+
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) %s from: %s",
+ je->cid, je->did, je->sid, je->nid, je->request->sip_method, tmp);
+ osip_free(tmp);
} else if (je->response != NULL) {
char *tmp = NULL;
-
- osip_from_to_str (je->request->from, &tmp);
- snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) [%i %s] for %s from: %s",
- je->cid, je->did, je->sid, je->nid,
- je->response->status_code, je->response->reason_phrase,
- je->request->sip_method, tmp);
- osip_free (tmp);
+
+ osip_from_to_str(je->request->from, &tmp);
+ snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i) [%i %s] for %s from: %s",
+ je->cid, je->did, je->sid, je->nid,
+ je->response->status_code, je->response->reason_phrase, je->request->sip_method, tmp);
+ osip_free(tmp);
} else {
- snprintf (buf, 99, "<- (c=%i|d=%i|s=%i|n=%i|t=%i) %s",
- je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo);
+ snprintf(buf, 99, "<- (c=%i|d=%i|s=%i|n=%i|t=%i) %s",
+ je->cid, je->did, je->sid, je->nid, je->tid, je->textinfo);
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\n%s\n", buf);
/* Print it out */
static void *monitor_thread_run(void)
{
eXosip_event_t *event = NULL;
-
+
globals.running = 1;
while (globals.running > 0) {
- if (!(event = eXosip_event_wait(0,100))) {
+ if (!(event = eXosip_event_wait(0, 100))) {
switch_yield(100);
continue;
}
eXosip_lock();
- eXosip_automatic_action ();
+ eXosip_automatic_action();
eXosip_unlock();
log_event(event);
- switch(event->type) {
+ switch (event->type) {
case EXOSIP_CALL_INVITE:
exosip_create_call(event);
break;
}
-static int config_exosip(int reload)
+static int config_exosip(int reload)
{
switch_config cfg;
char *var, *val;
}
}
}
-
+
if (!globals.codec_ms) {
globals.codec_ms = 20;
}
set_global_dialplan("default");
}
- if (eXosip_init ()) {
+ if (eXosip_init()) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_init initialization failed!\n");
return SWITCH_STATUS_GENERR;
}
- if (eXosip_listen_addr (IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) {
+ if (eXosip_listen_addr(IPPROTO_UDP, NULL, globals.port, AF_INET, 0)) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "eXosip_listen_addr failed!\n");
return SWITCH_STATUS_GENERR;
}
config_exosip(0);
return SWITCH_STATUS_TERM;
}
-
unsigned char databuf[SWITCH_RECCOMMENDED_BUFFER_SIZE];
switch_core_session *session;
struct iax_session *iax_session;
- switch_caller_profile *caller_profile;
+ switch_caller_profile *caller_profile;
unsigned int codec;
unsigned int codecs;
unsigned short samprate;
};
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string)
+ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string)
+ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string)
-static char *IAXNAMES[] = {"IAX_EVENT_CONNECT","IAX_EVENT_ACCEPT","IAX_EVENT_HANGUP","IAX_EVENT_REJECT","IAX_EVENT_VOICE",
- "IAX_EVENT_DTMF","IAX_EVENT_TIMEOUT","IAX_EVENT_LAGRQ","IAX_EVENT_LAGRP","IAX_EVENT_RINGA",
- "IAX_EVENT_PING","IAX_EVENT_PONG","IAX_EVENT_BUSY","IAX_EVENT_ANSWER","IAX_EVENT_IMAGE",
- "IAX_EVENT_AUTHRQ","IAX_EVENT_AUTHRP","IAX_EVENT_REGREQ","IAX_EVENT_REGACK",
- "IAX_EVENT_URL","IAX_EVENT_LDCOMPLETE","IAX_EVENT_TRANSFER","IAX_EVENT_DPREQ",
- "IAX_EVENT_DPREP","IAX_EVENT_DIAL","IAX_EVENT_QUELCH","IAX_EVENT_UNQUELCH",
- "IAX_EVENT_UNLINK","IAX_EVENT_LINKREJECT","IAX_EVENT_TEXT","IAX_EVENT_REGREJ",
- "IAX_EVENT_LINKURL","IAX_EVENT_CNG","IAX_EVENT_REREQUEST","IAX_EVENT_TXREPLY",
- "IAX_EVENT_TXREJECT","IAX_EVENT_TXACCEPT","IAX_EVENT_TXREADY"};
+ static char *IAXNAMES[] =
+ { "IAX_EVENT_CONNECT", "IAX_EVENT_ACCEPT", "IAX_EVENT_HANGUP", "IAX_EVENT_REJECT", "IAX_EVENT_VOICE",
+ "IAX_EVENT_DTMF", "IAX_EVENT_TIMEOUT", "IAX_EVENT_LAGRQ", "IAX_EVENT_LAGRP", "IAX_EVENT_RINGA",
+ "IAX_EVENT_PING", "IAX_EVENT_PONG", "IAX_EVENT_BUSY", "IAX_EVENT_ANSWER", "IAX_EVENT_IMAGE",
+ "IAX_EVENT_AUTHRQ", "IAX_EVENT_AUTHRP", "IAX_EVENT_REGREQ", "IAX_EVENT_REGACK",
+ "IAX_EVENT_URL", "IAX_EVENT_LDCOMPLETE", "IAX_EVENT_TRANSFER", "IAX_EVENT_DPREQ",
+ "IAX_EVENT_DPREP", "IAX_EVENT_DIAL", "IAX_EVENT_QUELCH", "IAX_EVENT_UNQUELCH",
+ "IAX_EVENT_UNLINK", "IAX_EVENT_LINKREJECT", "IAX_EVENT_TEXT", "IAX_EVENT_REGREJ",
+ "IAX_EVENT_LINKURL", "IAX_EVENT_CNG", "IAX_EVENT_REREQUEST", "IAX_EVENT_TXREPLY",
+ "IAX_EVENT_TXREJECT", "IAX_EVENT_TXACCEPT", "IAX_EVENT_TXREADY"
+ };
struct ast_iana {
};
//999 means it's wrong nad i dont know the real one
-static struct ast_iana AST_IANA[] =
- {{AST_FORMAT_G723_1, 4, "g723.1"},
- {AST_FORMAT_GSM, 3, "gsm"},
- {AST_FORMAT_ULAW, 0, "ulaw"},
- {AST_FORMAT_ALAW, 8, "alaw"},
- {AST_FORMAT_G726, 999, "g726"},
- {AST_FORMAT_ADPCM, 999, "adpcm"},
- {AST_FORMAT_SLINEAR, 10, "slinear"},
- {AST_FORMAT_LPC10, 7, "lpc10"},
- {AST_FORMAT_G729A, 18, "g729"},
- {AST_FORMAT_SPEEX, 98, "speex"},
- {AST_FORMAT_ILBC, 999, "ilbc"},
- {AST_FORMAT_MAX_AUDIO, 999, ""},
- {AST_FORMAT_JPEG, 999, ""},
- {AST_FORMAT_PNG, 999, ""},
- {AST_FORMAT_H261, 999, ""},
- {AST_FORMAT_H263, 999, ""},
- {AST_FORMAT_MAX_VIDEO, 999, ""},
- {0,0}
- };
+static struct ast_iana AST_IANA[] = { {AST_FORMAT_G723_1, 4, "g723.1"},
+{AST_FORMAT_GSM, 3, "gsm"},
+{AST_FORMAT_ULAW, 0, "ulaw"},
+{AST_FORMAT_ALAW, 8, "alaw"},
+{AST_FORMAT_G726, 999, "g726"},
+{AST_FORMAT_ADPCM, 999, "adpcm"},
+{AST_FORMAT_SLINEAR, 10, "slinear"},
+{AST_FORMAT_LPC10, 7, "lpc10"},
+{AST_FORMAT_G729A, 18, "g729"},
+{AST_FORMAT_SPEEX, 98, "speex"},
+{AST_FORMAT_ILBC, 999, "ilbc"},
+{AST_FORMAT_MAX_AUDIO, 999, ""},
+{AST_FORMAT_JPEG, 999, ""},
+{AST_FORMAT_PNG, 999, ""},
+{AST_FORMAT_H261, 999, ""},
+{AST_FORMAT_H263, 999, ""},
+{AST_FORMAT_MAX_VIDEO, 999, ""},
+{0, 0}
+};
static char *ast2str(unsigned int ast)
{
int x;
- for(x = 0; x < 32; x++) {
+ for (x = 0; x < 32; x++) {
if ((1 << x) == ast) {
return AST_IANA[x].name;
}
int x = 0;
unsigned int ast = 0;
- for(x = 0; AST_IANA[x].ast; x++) {
+ for (x = 0; AST_IANA[x].ast; x++) {
if (AST_IANA[x].iana == iana) {
ast = AST_IANA[x].ast;
break;
return ast;
}
-static unsigned short iax_build_codec_rates(void)
+static unsigned short iax_build_codec_rates(void)
{
int x;
unsigned short samples = 0;
-
+
for (x = 0; x < globals.codec_rates_last; x++) {
int rate = atoi(globals.codec_rates[x]);
switch (rate) {
IAX_QUERY = 2
} iax_io_t;
-static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_session *iax_session, unsigned int *format, unsigned int *cababilities, unsigned short *samprate, iax_io_t io)
+static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_session *iax_session,
+ unsigned int *format, unsigned int *cababilities, unsigned short *samprate,
+ iax_io_t io)
{
char *dname = NULL;
//int rate = 8000;
if (globals.codec_string) {
if (!(num_codecs = switch_loadable_module_get_codecs_sorted(switch_core_session_get_pool(tech_pvt->session),
- codecs,
- SWITCH_MAX_CODECS,
- globals.codec_order,
- globals.codec_order_last)) > 0) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n");
- return SWITCH_STATUS_GENERR;
+ codecs,
+ SWITCH_MAX_CODECS,
+ globals.codec_order,
+ globals.codec_order_last)) > 0) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n");
+ return SWITCH_STATUS_GENERR;
}
- } else if (!(num_codecs = switch_loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), codecs, SWITCH_MAX_CODECS)) > 0) {
+ } else
+ if (!
+ (num_codecs =
+ switch_loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), codecs,
+ SWITCH_MAX_CODECS)) > 0) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NO codecs?\n");
return SWITCH_STATUS_GENERR;
}
len = iax_pref_codec_get(iax_session, prefs, sizeof(prefs));
}
- if (len) { /*they sent us a pref and we don't want to be codec master*/
+ if (len) { /*they sent us a pref and we don't want to be codec master */
char pref_str[256] = "(";
for (x = 0; x < len; x++) {
}
}
} else {
- if (*format & mixed_cap) { /* is the one we asked for here? */
+ if (*format & mixed_cap) { /* is the one we asked for here? */
chosen = *format;
for (x = 0; x < num_codecs; x++) {
unsigned int cap = iana2ast(codecs[x]->ianacode);
dname = codecs[x]->iananame;
}
}
- } else { /* c'mon there has to be SOMETHING...*/
+ } else { /* c'mon there has to be SOMETHING... */
for (x = 0; x < num_codecs; x++) {
unsigned int cap = iana2ast(codecs[x]->ianacode);
if (cap & mixed_cap) {
//printf("\n\n******WTF %u %u %u\n******\n", *samprate, samples, mixed);
srate = 8000;
-
+
if (mixed & IAX_RATE_16KHZ) {
srate = 16000;
}
srate,
0,
1,
- SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
return SWITCH_STATUS_GENERR;
} else {
srate,
0,
1,
- SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
- switch_core_codec_destroy(&tech_pvt->read_codec);
+ switch_core_codec_destroy(&tech_pvt->read_codec);
return SWITCH_STATUS_GENERR;
} else {
int ms;
static switch_status channel_on_ring(switch_core_session *session);
static switch_status channel_on_loopback(switch_core_session *session);
static switch_status channel_on_transmit(switch_core_session *session);
-static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session);
-static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id);
-static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id);
+static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
+ switch_core_session **new_session);
+static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags, int stream_id);
+static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags, int stream_id);
static switch_status channel_kill_channel(switch_core_session *session, int sig);
switch_set_flag(tech_pvt, TFLAG_IO);
switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
- //switch_thread_cond_create(&tech_pvt->cond, switch_core_session_get_pool(session));
+ //switch_thread_cond_create(&tech_pvt->cond, switch_core_session_get_pool(session));
//switch_mutex_lock(tech_pvt->mutex);
/* Move Channel's State Machine to RING */
/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
*/
-static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session)
+static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
+ switch_core_session **new_session)
{
if ((*new_session = switch_core_session_request(&channel_endpoint_interface, NULL))) {
struct private_object *tech_pvt;
unsigned short samprate = 0;
switch_core_session_add_stream(*new_session, NULL);
- if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
+ if ((tech_pvt =
+ (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
channel = switch_core_session_get_channel(*new_session);
switch_core_session_set_private(*new_session, tech_pvt);
}
iax_call(tech_pvt->iax_session,
- caller_profile->caller_id_number,
- caller_profile->caller_id_name,
- caller_profile->destination_number,
- NULL, 0, req, cap);
+ caller_profile->caller_id_number,
+ caller_profile->caller_id_name, caller_profile->destination_number, NULL, 0, req, cap);
switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
if (tech_pvt->iax_session) {
- for(digit = dtmf; *digit; digit++) {
+ for (digit = dtmf; *digit; digit++) {
iax_send_dtmf(tech_pvt->iax_session, *digit);
}
}
return SWITCH_STATUS_SUCCESS;
}
-static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id)
+static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags, int stream_id)
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
while (switch_test_flag(tech_pvt, TFLAG_IO)) {
//switch_thread_cond_wait(tech_pvt->cond, tech_pvt->mutex);
if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
- return SWITCH_STATUS_FALSE;
+ return SWITCH_STATUS_FALSE;
}
-
+
if (switch_test_flag(tech_pvt, TFLAG_IO) && switch_test_flag(tech_pvt, TFLAG_VOICE)) {
switch_clear_flag(tech_pvt, TFLAG_VOICE);
- if(!tech_pvt->read_frame.datalen) {
+ if (!tech_pvt->read_frame.datalen) {
continue;
}
-
+
*frame = &tech_pvt->read_frame;
return SWITCH_STATUS_SUCCESS;
}
switch_yield(1000);
}
-
-
+
+
return SWITCH_STATUS_FALSE;
}
-static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id)
+static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags, int stream_id)
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
- if(!switch_test_flag(tech_pvt, TFLAG_IO)) {
+ if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
return SWITCH_STATUS_FALSE;
}
-
#ifndef BIGENDIAN
if (switch_test_flag(tech_pvt, TFLAG_LINEAR)) {
- switch_swap_linear(frame->data, (int)frame->datalen / 2);
+ switch_swap_linear(frame->data, (int) frame->datalen / 2);
}
#endif
- iax_send_voice(tech_pvt->iax_session, tech_pvt->codec, frame->data, (int)frame->datalen, tech_pvt->write_codec.implementation->samples_per_frame);
+ iax_send_voice(tech_pvt->iax_session, tech_pvt->codec, frame->data, (int) frame->datalen,
+ tech_pvt->write_codec.implementation->samples_per_frame);
return SWITCH_STATUS_SUCCESS;
}
static const switch_event_handler_table channel_event_handlers = {
- /*.on_init*/ channel_on_init,
- /*.on_ring*/ channel_on_ring,
- /*.on_execute*/ channel_on_execute,
- /*.on_hangup*/ channel_on_hangup,
- /*.on_loopback*/ channel_on_loopback,
- /*.on_transmit*/ channel_on_transmit
+ /*.on_init */ channel_on_init,
+ /*.on_ring */ channel_on_ring,
+ /*.on_execute */ channel_on_execute,
+ /*.on_hangup */ channel_on_hangup,
+ /*.on_loopback */ channel_on_loopback,
+ /*.on_transmit */ channel_on_transmit
};
static const switch_io_routines channel_io_routines = {
- /*.outgoing_channel*/ channel_outgoing_channel,
- /*.answer_channel*/ channel_answer_channel,
- /*.read_frame*/ channel_read_frame,
- /*.write_frame*/ channel_write_frame,
- /*.kill_channel*/ channel_kill_channel,
- /*.waitfor_read*/ channel_waitfor_read,
- /*.waitfor_write*/ channel_waitfor_write,
- /*.send_dtmf*/ channel_send_dtmf
+ /*.outgoing_channel */ channel_outgoing_channel,
+ /*.answer_channel */ channel_answer_channel,
+ /*.read_frame */ channel_read_frame,
+ /*.write_frame */ channel_write_frame,
+ /*.kill_channel */ channel_kill_channel,
+ /*.waitfor_read */ channel_waitfor_read,
+ /*.waitfor_write */ channel_waitfor_write,
+ /*.send_dtmf */ channel_send_dtmf
};
static const switch_endpoint_interface channel_endpoint_interface = {
- /*.interface_name*/ "iax",
- /*.io_routines*/ &channel_io_routines,
- /*.event_handlers*/ &channel_event_handlers,
- /*.private*/ NULL,
- /*.next*/ NULL
+ /*.interface_name */ "iax",
+ /*.io_routines */ &channel_io_routines,
+ /*.event_handlers */ &channel_event_handlers,
+ /*.private */ NULL,
+ /*.next */ NULL
};
static const switch_loadable_module_interface channel_module_interface = {
- /*.module_name*/ modname,
- /*.endpoint_interface*/ &channel_endpoint_interface,
- /*.timer_interface*/ NULL,
- /*.dialplan_interface*/ NULL,
- /*.codec_interface*/ NULL,
- /*.application_interface*/ NULL
+ /*.module_name */ modname,
+ /*.endpoint_interface */ &channel_endpoint_interface,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ NULL,
+ /*.application_interface */ NULL
};
-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)
+{
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n");
set_global_dialplan(val);
} else if (!strcmp(var, "codec_prefs")) {
set_global_codec_string(val);
- globals.codec_order_last = switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS);
+ globals.codec_order_last =
+ switch_separate_string(globals.codec_string, ',', globals.codec_order, SWITCH_MAX_CODECS);
} else if (!strcmp(var, "codec_rates")) {
set_global_codec_rates_string(val);
- globals.codec_rates_last = switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS);
+ globals.codec_rates_last =
+ switch_separate_string(globals.codec_rates_string, ',', globals.codec_rates, SWITCH_MAX_CODECS);
}
}
}
iax_set_error(iax_err_cb);
iax_set_output(iax_out_cb);
- netfd = iax_get_fd();
+ netfd = iax_get_fd();
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "IAX Ready Port %d\n", globals.port);
- for(;;) {
+ for (;;) {
if (running == -1) {
break;
}
- /* Wait for an event.*/
+ /* Wait for an event. */
if ((iaxevent = iax_get_event(0)) == NULL) {
switch_yield(1000);
continue;
if (globals.debug && iaxevent->etype != IAX_EVENT_VOICE) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Event %d [%s]!\n",
- iaxevent->etype, IAXNAMES[iaxevent->etype]);
+ iaxevent->etype, IAXNAMES[iaxevent->etype]);
}
switch (iaxevent->etype) {
- case IAX_EVENT_REGACK:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration completed successfully.\n");
- if (iaxevent->ies.refresh) refresh = iaxevent->ies.refresh;
- break;
- case IAX_EVENT_REGREJ:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration failed.\n");
- break;
- case IAX_EVENT_TIMEOUT:
- break;
- case IAX_EVENT_ACCEPT:
- if (tech_pvt) {
- unsigned int cap = iax_session_get_capability(iaxevent->session);
- unsigned int format = iaxevent->ies.format;
+ case IAX_EVENT_REGACK:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration completed successfully.\n");
+ if (iaxevent->ies.refresh)
+ refresh = iaxevent->ies.refresh;
+ break;
+ case IAX_EVENT_REGREJ:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration failed.\n");
+ break;
+ case IAX_EVENT_TIMEOUT:
+ break;
+ case IAX_EVENT_ACCEPT:
+ if (tech_pvt) {
+ unsigned int cap = iax_session_get_capability(iaxevent->session);
+ unsigned int format = iaxevent->ies.format;
+
+ if (iax_set_codec(tech_pvt, iaxevent->session, &format, &cap, &iaxevent->ies.samprate, IAX_SET) !=
+ SWITCH_STATUS_SUCCESS) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF? %d %d\n", iaxevent->ies.format,
+ iaxevent->ies.capability);
+ }
+ }
- if (iax_set_codec(tech_pvt, iaxevent->session, &format, &cap, &iaxevent->ies.samprate, IAX_SET) != SWITCH_STATUS_SUCCESS) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF? %d %d\n",iaxevent->ies.format, iaxevent->ies.capability);
+
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call accepted.\n");
+ break;
+ case IAX_EVENT_RINGA:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Ringing heard.\n");
+ break;
+ case IAX_EVENT_PONG:
+ // informative only
+ break;
+ case IAX_EVENT_ANSWER:
+ // the other side answered our call
+ if (tech_pvt) {
+ switch_channel *channel;
+ if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
+ if (switch_channel_test_flag(channel, CF_ANSWERED)) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF Mutiple Answer %s?\n",
+ switch_channel_get_name(channel));
+ } else {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Answer %s\n",
+ switch_channel_get_name(channel));
+ switch_channel_answer(channel);
}
}
+ }
-
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call accepted.\n");
- break;
- case IAX_EVENT_RINGA:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Ringing heard.\n");
- break;
- case IAX_EVENT_PONG:
- // informative only
- break;
- case IAX_EVENT_ANSWER:
- // the other side answered our call
- if (tech_pvt) {
+ break;
+ case IAX_EVENT_CONNECT:
+ // incoming call detected
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE,
+ "Incoming call connected %s, %s, %s %d/%d\n",
+ iaxevent->ies.called_number,
+ iaxevent->ies.calling_number,
+ iaxevent->ies.calling_name, iaxevent->ies.format, iaxevent->ies.capability);
+
+ if (iaxevent) {
+ switch_core_session *session;
+
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "New Inbound Channel %s!\n",
+ iaxevent->ies.calling_name);
+ if ((session = switch_core_session_request(&channel_endpoint_interface, NULL))) {
+ struct private_object *tech_pvt;
switch_channel *channel;
- if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
- if (switch_channel_test_flag(channel, CF_ANSWERED)) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WTF Mutiple Answer %s?\n", switch_channel_get_name(channel));
- } else {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Answer %s\n", switch_channel_get_name(channel));
- switch_channel_answer(channel);
- }
+
+ switch_core_session_add_stream(session, NULL);
+ if ((tech_pvt =
+ (struct private_object *) switch_core_session_alloc(session,
+ sizeof(struct private_object)))) {
+ memset(tech_pvt, 0, sizeof(*tech_pvt));
+ channel = switch_core_session_get_channel(session);
+ switch_core_session_set_private(session, tech_pvt);
+ tech_pvt->session = session;
+ } else {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hey where is my memory pool?\n");
+ switch_core_session_destroy(&session);
+ break;
}
- }
- break;
- case IAX_EVENT_CONNECT:
- // incoming call detected
- switch_console_printf(SWITCH_CHANNEL_CONSOLE,
- "Incoming call connected %s, %s, %s %d/%d\n",
- iaxevent->ies.called_number,
- iaxevent->ies.calling_number,
- iaxevent->ies.calling_name,
- iaxevent->ies.format,
- iaxevent->ies.capability);
-
- if (iaxevent) {
- switch_core_session *session;
-
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "New Inbound Channel %s!\n", iaxevent->ies.calling_name);
- if ((session = switch_core_session_request(&channel_endpoint_interface, NULL))) {
- struct private_object *tech_pvt;
- switch_channel *channel;
-
- switch_core_session_add_stream(session, NULL);
- if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) {
- memset(tech_pvt, 0, sizeof(*tech_pvt));
- channel = switch_core_session_get_channel(session);
- switch_core_session_set_private(session, tech_pvt);
- tech_pvt->session = session;
- } else {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hey where is my memory pool?\n");
- switch_core_session_destroy(&session);
- break;
- }
-
-
- if ((tech_pvt->caller_profile = switch_caller_profile_new(session,
- globals.dialplan,
- iaxevent->ies.calling_name,
- iaxevent->ies.calling_number,
- iax_get_peer_ip(iaxevent->session),
- iaxevent->ies.calling_ani,
- NULL,
- iaxevent->ies.called_number))) {
- char name[128];
- switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
- snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
- switch_channel_set_name(channel, name);
- }
-
- if (iax_set_codec(tech_pvt, iaxevent->session,
- &iaxevent->ies.format,
- &iaxevent->ies.capability,
- &iaxevent->ies.samprate,
- IAX_SET) != SWITCH_STATUS_SUCCESS) {
- iax_reject(iaxevent->session, "Codec Error!");
- switch_core_session_destroy(&session);
- } else {
- tech_pvt->iax_session = iaxevent->session;
- tech_pvt->session = session;
- iax_accept(tech_pvt->iax_session, tech_pvt->codec);
- iax_ring_announce(tech_pvt->iax_session);
- switch_channel_set_state(channel, CS_INIT);
- switch_core_session_thread_launch(session);
- }
+
+ if ((tech_pvt->caller_profile = switch_caller_profile_new(session,
+ globals.dialplan,
+ iaxevent->ies.calling_name,
+ iaxevent->ies.calling_number,
+ iax_get_peer_ip(iaxevent->session),
+ iaxevent->ies.calling_ani,
+ NULL, iaxevent->ies.called_number))) {
+ char name[128];
+ switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
+ snprintf(name, sizeof(name), "IAX/%s-%04x", tech_pvt->caller_profile->destination_number,
+ rand() & 0xffff);
+ switch_channel_set_name(channel, name);
}
- }
- break;
- case IAX_EVENT_REJECT:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Rejected call.\n");
- case IAX_EVENT_BUSY:
- case IAX_EVENT_HANGUP:
- if (tech_pvt) {
- switch_channel *channel;
- switch_clear_flag(tech_pvt, TFLAG_IO);
- switch_clear_flag(tech_pvt, TFLAG_VOICE);
- if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hangup %s\n", switch_channel_get_name(channel));
- switch_set_flag(tech_pvt, TFLAG_HANGUP);
- switch_channel_hangup(channel);
- //switch_thread_cond_signal(tech_pvt->cond);
- iaxevent->session = NULL;
+ if (iax_set_codec(tech_pvt, iaxevent->session,
+ &iaxevent->ies.format,
+ &iaxevent->ies.capability,
+ &iaxevent->ies.samprate, IAX_SET) != SWITCH_STATUS_SUCCESS) {
+ iax_reject(iaxevent->session, "Codec Error!");
+ switch_core_session_destroy(&session);
} else {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "No Session? %s\n", switch_test_flag(tech_pvt, TFLAG_VOICE) ? "yes" : "no");
+ tech_pvt->iax_session = iaxevent->session;
+ tech_pvt->session = session;
+ iax_accept(tech_pvt->iax_session, tech_pvt->codec);
+ iax_ring_announce(tech_pvt->iax_session);
+ switch_channel_set_state(channel, CS_INIT);
+ switch_core_session_thread_launch(session);
}
}
- break;
- case IAX_EVENT_CNG:
- // pseudo-silence
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "sending silence\n");
- break;
- case IAX_EVENT_VOICE:
- if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen)) {
- switch_channel *channel;
- if ((channel = switch_core_session_get_channel(tech_pvt->session)) && switch_channel_get_state(channel) <= CS_HANGUP) {
- int bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
- int frames = (int)(tech_pvt->read_frame.datalen / bytes);
- tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
- memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen);
- /* wake up the i/o thread*/
- switch_set_flag(tech_pvt, TFLAG_VOICE);
- //switch_thread_cond_signal(tech_pvt->cond);
- }
- }
- break;
- case IAX_EVENT_TRANSFER:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call transfer occurred.\n");
- //session[0] = iaxevent->session;
- break;
- case IAX_EVENT_DTMF:
- if (tech_pvt) {
- switch_channel *channel;
- if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
- char str[2] = {iaxevent->subclass};
- if (globals.debug) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s DTMF %s\n", str, switch_channel_get_name(channel));
- }
- switch_channel_queue_dtmf(channel, str);
+ }
+ break;
+ case IAX_EVENT_REJECT:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Rejected call.\n");
+ case IAX_EVENT_BUSY:
+ case IAX_EVENT_HANGUP:
+ if (tech_pvt) {
+ switch_channel *channel;
+
+ switch_clear_flag(tech_pvt, TFLAG_IO);
+ switch_clear_flag(tech_pvt, TFLAG_VOICE);
+ if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Hangup %s\n", switch_channel_get_name(channel));
+ switch_set_flag(tech_pvt, TFLAG_HANGUP);
+ switch_channel_hangup(channel);
+ //switch_thread_cond_signal(tech_pvt->cond);
+ iaxevent->session = NULL;
+ } else {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "No Session? %s\n",
+ switch_test_flag(tech_pvt, TFLAG_VOICE) ? "yes" : "no");
+ }
+ }
+ break;
+ case IAX_EVENT_CNG:
+ // pseudo-silence
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "sending silence\n");
+ break;
+ case IAX_EVENT_VOICE:
+ if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen)) {
+ switch_channel *channel;
+ if ((channel = switch_core_session_get_channel(tech_pvt->session))
+ && switch_channel_get_state(channel) <= CS_HANGUP) {
+ int bytes = tech_pvt->read_codec.implementation->encoded_bytes_per_frame;
+ int frames = (int) (tech_pvt->read_frame.datalen / bytes);
+ tech_pvt->read_frame.samples = frames * tech_pvt->read_codec.implementation->samples_per_frame;
+ memcpy(tech_pvt->read_frame.data, iaxevent->data, iaxevent->datalen);
+ /* wake up the i/o thread */
+ switch_set_flag(tech_pvt, TFLAG_VOICE);
+ //switch_thread_cond_signal(tech_pvt->cond);
+ }
+ }
+ break;
+ case IAX_EVENT_TRANSFER:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Call transfer occurred.\n");
+ //session[0] = iaxevent->session;
+ break;
+ case IAX_EVENT_DTMF:
+ if (tech_pvt) {
+ switch_channel *channel;
+ if ((channel = switch_core_session_get_channel(tech_pvt->session))) {
+ char str[2] = { iaxevent->subclass };
+ if (globals.debug) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s DTMF %s\n", str,
+ switch_channel_get_name(channel));
}
+ switch_channel_queue_dtmf(channel, str);
}
+ }
- break;
- default:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Don't know what to do with IAX event %d.\n", iaxevent->etype);
- break;
+ break;
+ default:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Don't know what to do with IAX event %d.\n",
+ iaxevent->etype);
+ break;
}
iax_event_free(iaxevent);
}
return SWITCH_STATUS_SUCCESS;
}
-
struct switch_frame frame;
unsigned char databuf[SWITCH_RECCOMMENDED_BUFFER_SIZE];
switch_core_session *session;
- switch_caller_profile *caller_profile;
+ switch_caller_profile *caller_profile;
};
static switch_status channel_on_ring(switch_core_session *session);
static switch_status channel_on_loopback(switch_core_session *session);
static switch_status channel_on_transmit(switch_core_session *session);
-static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session);
-static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id);
-static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id);
+static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
+ switch_core_session **new_session);
+static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags, int stream_id);
+static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags, int stream_id);
static switch_status channel_kill_channel(switch_core_session *session, int sig);
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
+
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel));
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
-
+
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
-
+
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
switch_channel_hangup(channel);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s CHANNEL KILL\n", switch_channel_get_name(channel));
-
+
return SWITCH_STATUS_SUCCESS;
}
/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
*/
-static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session)
+static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
+ switch_core_session **new_session)
{
if ((*new_session = switch_core_session_request(&channel_endpoint_interface, NULL))) {
struct private_object *tech_pvt;
switch_channel *channel, *orig_channel;
switch_caller_profile *caller_profile, *originator_caller_profile = NULL;
-
+
switch_core_session_add_stream(*new_session, NULL);
- if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
+ if ((tech_pvt =
+ (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
channel = switch_core_session_get_channel(*new_session);
switch_core_session_set_private(*new_session, tech_pvt);
switch_channel_set_originator_caller_profile(channel, cloned_profile);
}
}
-
+
switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
switch_channel_set_state(channel, CS_INIT);
}
-static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id)
+static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags, int stream_id)
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
return SWITCH_STATUS_SUCCESS;
}
-static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id)
+static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags, int stream_id)
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
assert(tech_pvt != NULL);
return SWITCH_STATUS_SUCCESS;
-
+
}
static const switch_event_handler_table channel_event_handlers = {
- /*.on_init*/ channel_on_init,
- /*.on_ring*/ channel_on_ring,
- /*.on_execute*/ channel_on_execute,
- /*.on_hangup*/ channel_on_hangup,
- /*.on_loopback*/ channel_on_loopback,
- /*.on_transmit*/ channel_on_transmit
+ /*.on_init */ channel_on_init,
+ /*.on_ring */ channel_on_ring,
+ /*.on_execute */ channel_on_execute,
+ /*.on_hangup */ channel_on_hangup,
+ /*.on_loopback */ channel_on_loopback,
+ /*.on_transmit */ channel_on_transmit
};
static const switch_io_routines channel_io_routines = {
- /*.outgoing_channel*/ channel_outgoing_channel,
- /*.answer_channel*/ NULL,
- /*.read_frame*/ channel_read_frame,
- /*.write_frame*/ channel_write_frame,
- /*.kill_channel*/ channel_kill_channel,
- /*.waitfor_read*/ channel_waitfor_read,
- /*.waitfor_write*/ channel_waitfor_write
+ /*.outgoing_channel */ channel_outgoing_channel,
+ /*.answer_channel */ NULL,
+ /*.read_frame */ channel_read_frame,
+ /*.write_frame */ channel_write_frame,
+ /*.kill_channel */ channel_kill_channel,
+ /*.waitfor_read */ channel_waitfor_read,
+ /*.waitfor_write */ channel_waitfor_write
};
static const switch_endpoint_interface channel_endpoint_interface = {
- /*.interface_name*/ "opal",
- /*.io_routines*/ &channel_io_routines,
- /*.event_handlers*/ &channel_event_handlers,
- /*.private*/ NULL,
- /*.next*/ NULL
+ /*.interface_name */ "opal",
+ /*.io_routines */ &channel_io_routines,
+ /*.event_handlers */ &channel_event_handlers,
+ /*.private */ NULL,
+ /*.next */ NULL
};
static const switch_loadable_module_interface channel_module_interface = {
- /*.module_name*/ modname,
- /*.endpoint_interface*/ &channel_endpoint_interface,
- /*.timer_interface*/ NULL,
- /*.dialplan_interface*/ NULL,
- /*.codec_interface*/ NULL,
- /*.application_interface*/ NULL
+ /*.module_name */ modname,
+ /*.endpoint_interface */ &channel_endpoint_interface,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ NULL,
+ /*.application_interface */ NULL
};
}
*/
-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)
+{
switch_config cfg;
char *var, *val;
char *cf = "opal.conf";
-
+
memset(&globals, 0, sizeof(globals));
-
+
if (!switch_config_open_file(&cfg, cf)) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
}
-
+
while (switch_config_next_pair(&cfg, &var, &val)) {
if (!strcasecmp(cfg.category, "settings")) {
switch_config_close_file(&cfg);
-
+
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n");
return SWITCH_STATUS_TERM;
struct private_object {
unsigned int flags;
switch_codec read_codec;
- switch_codec write_codec;
+ switch_codec write_codec;
struct switch_frame read_frame;
unsigned char databuf[SWITCH_RECCOMMENDED_BUFFER_SIZE];
switch_core_session *session;
- switch_caller_profile *caller_profile;
+ switch_caller_profile *caller_profile;
char call_id[50];
PaError err;
- PABLIO_Stream *audio_in;
- PABLIO_Stream *audio_out;
+ PABLIO_Stream *audio_in;
+ PABLIO_Stream *audio_out;
int indev;
int outdev;
};
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_cid_name, globals.cid_name)
-SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_cid_num, globals.cid_num)
-
-
-static const switch_endpoint_interface channel_endpoint_interface;
-
-static switch_status channel_on_init(switch_core_session *session);
-static switch_status channel_on_hangup(switch_core_session *session);
-static switch_status channel_on_ring(switch_core_session *session);
-static switch_status channel_on_loopback(switch_core_session *session);
-static switch_status channel_on_transmit(switch_core_session *session);
-static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session);
-static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id);
-static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id);
-static switch_status channel_kill_channel(switch_core_session *session, int sig);
-static switch_status engage_device(struct private_object *tech_pvt);
-static int dump_info(void);
-static switch_status load_config(void);
-static int get_dev_by_name(char *name, int in);
-static switch_status place_call(char *dest, char *out, size_t outlen);
-static switch_status hup_call(char *callid, char *out, size_t outlen);
-static switch_status call_info(char *callid, char *out, size_t outlen);
-static switch_status send_dtmf(char *callid, char *out, size_t outlen);
-static switch_status answer_call(char *callid, char *out, size_t outlen);
+ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_cid_name, globals.cid_name)
+ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_cid_num, globals.cid_num)
+
+
+ static const switch_endpoint_interface channel_endpoint_interface;
+
+ static switch_status channel_on_init(switch_core_session *session);
+ static switch_status channel_on_hangup(switch_core_session *session);
+ static switch_status channel_on_ring(switch_core_session *session);
+ static switch_status channel_on_loopback(switch_core_session *session);
+ static switch_status channel_on_transmit(switch_core_session *session);
+ static switch_status channel_outgoing_channel(switch_core_session *session,
+ switch_caller_profile *outbound_profile,
+ switch_core_session **new_session);
+ static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags, int stream_id);
+ static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags, int stream_id);
+ static switch_status channel_kill_channel(switch_core_session *session, int sig);
+ static switch_status engage_device(struct private_object *tech_pvt);
+ static int dump_info(void);
+ static switch_status load_config(void);
+ static int get_dev_by_name(char *name, int in);
+ static switch_status place_call(char *dest, char *out, size_t outlen);
+ static switch_status hup_call(char *callid, char *out, size_t outlen);
+ static switch_status call_info(char *callid, char *out, size_t outlen);
+ static switch_status send_dtmf(char *callid, char *out, size_t outlen);
+ static switch_status answer_call(char *callid, char *out, size_t outlen);
/*
State methods they get called when the state changes to the specific state
returning SWITCH_STATUS_SUCCESS tells the core to execute the standard state method next
so if you fully implement the state you can return SWITCH_STATUS_FALSE to skip it.
*/
-static switch_status channel_on_init(switch_core_session *session)
+ static switch_status channel_on_init(switch_core_session *session)
{
switch_channel *channel;
struct private_object *tech_pvt = NULL;
tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
switch_set_flag(tech_pvt, TFLAG_IO);
-
+
/* Move Channel's State Machine to RING */
switch_channel_set_state(channel, CS_RING);
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
+
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s CHANNEL EXECUTE\n", switch_channel_get_name(channel));
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
-
+
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s CHANNEL KILL\n", switch_channel_get_name(channel));
-
+
return SWITCH_STATUS_SUCCESS;
}
/* Turn on the device */
engage_device(tech_pvt);
- while(switch_channel_get_state(channel) == CS_TRANSMIT && !switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
+ while (switch_channel_get_state(channel) == CS_TRANSMIT && !switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
if (switch_time_now() - last >= waitsec) {
- char buf[512];
- switch_event *event;
+ char buf[512];
+ switch_event *event;
- snprintf(buf, sizeof(buf), "BRRRRING! BRRRRING! call %s\n", tech_pvt->call_id);
+ snprintf(buf, sizeof(buf), "BRRRRING! BRRRRING! call %s\n", tech_pvt->call_id);
- if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_RINGING) == SWITCH_STATUS_SUCCESS) {
- switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_info", buf);
- switch_event_fire(&event);
- }
+ if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_RINGING) == SWITCH_STATUS_SUCCESS) {
+ switch_event_add_header(event, SWITCH_STACK_BOTTOM, "event_info", buf);
+ switch_event_fire(&event);
+ }
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s\n", buf);
- last = switch_time_now();
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s\n", buf);
+ last = switch_time_now();
}
switch_yield(50000);
}
-
+
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "CHANNEL TRANSMIT\n");
/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
*/
-static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session)
+static switch_status channel_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
+ switch_core_session **new_session)
{
if ((*new_session = switch_core_session_request(&channel_endpoint_interface, NULL))) {
struct private_object *tech_pvt;
switch_caller_profile *caller_profile;
switch_core_session_add_stream(*new_session, NULL);
- if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
+ if ((tech_pvt =
+ (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
channel = switch_core_session_get_channel(*new_session);
switch_core_session_set_private(*new_session, tech_pvt);
caller_profile = switch_caller_profile_clone(*new_session, outbound_profile);
switch_channel_set_caller_profile(channel, caller_profile);
tech_pvt->caller_profile = caller_profile;
- snprintf(name, sizeof(name), "PortAudio/%s-%04x", caller_profile->destination_number ? caller_profile->destination_number : modname, rand() & 0xffff);
+ snprintf(name, sizeof(name), "PortAudio/%s-%04x",
+ caller_profile->destination_number ? caller_profile->destination_number : modname,
+ rand() & 0xffff);
switch_channel_set_name(channel, name);
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Doh! no caller profile\n");
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "DTMF ON CALL %s [%s]\n", tech_pvt->call_id, dtmf);
- return SWITCH_STATUS_SUCCESS;
+ return SWITCH_STATUS_SUCCESS;
}
-static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id)
+static switch_status channel_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags, int stream_id)
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
return SWITCH_STATUS_FALSE;
}
-
+
switch_mutex_lock(globals.device_lock);
- if (tech_pvt->audio_in &&
- (samples = ReadAudioStream(tech_pvt->audio_in, tech_pvt->read_frame.data, tech_pvt->read_codec.implementation->samples_per_frame))) {
+ if (tech_pvt->audio_in &&
+ (samples =
+ ReadAudioStream(tech_pvt->audio_in, tech_pvt->read_frame.data,
+ tech_pvt->read_codec.implementation->samples_per_frame))) {
tech_pvt->read_frame.datalen = samples * 2;
tech_pvt->read_frame.samples = samples;
*frame = &tech_pvt->read_frame;
return status;
}
-static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id)
+static switch_status channel_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags, int stream_id)
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
- if(!switch_test_flag(tech_pvt, TFLAG_IO)) {
+ if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
return SWITCH_STATUS_FALSE;
}
-
//switch_mutex_lock(globals.device_lock);
if (tech_pvt->audio_out) {
- WriteAudioStream(tech_pvt->audio_out, (short *)frame->data, (int)(frame->datalen / sizeof(SAMPLE)));
+ WriteAudioStream(tech_pvt->audio_out, (short *) frame->data, (int) (frame->datalen / sizeof(SAMPLE)));
status = SWITCH_STATUS_SUCCESS;
}
//switch_mutex_unlock(globals.device_lock);
return status;
-
+
}
static switch_status channel_answer_channel(switch_core_session *session)
static struct switch_api_interface send_dtmf_interface = {
- /*.interface_name*/ "padtmf",
- /*.desc*/ "PortAudio Dial DTMF",
- /*.function*/ send_dtmf,
- /*.next*/ NULL
+ /*.interface_name */ "padtmf",
+ /*.desc */ "PortAudio Dial DTMF",
+ /*.function */ send_dtmf,
+ /*.next */ NULL
};
static struct switch_api_interface answer_call_interface = {
- /*.interface_name*/ "paoffhook",
- /*.desc*/ "PortAudio Answer Call",
- /*.function*/ answer_call,
- /*.next*/ &send_dtmf_interface
+ /*.interface_name */ "paoffhook",
+ /*.desc */ "PortAudio Answer Call",
+ /*.function */ answer_call,
+ /*.next */ &send_dtmf_interface
};
static struct switch_api_interface channel_info_interface = {
- /*.interface_name*/ "painfo",
- /*.desc*/ "PortAudio Call Info",
- /*.function*/ call_info,
- /*.next*/ &answer_call_interface
+ /*.interface_name */ "painfo",
+ /*.desc */ "PortAudio Call Info",
+ /*.function */ call_info,
+ /*.next */ &answer_call_interface
};
static struct switch_api_interface channel_hup_interface = {
- /*.interface_name*/ "pahup",
- /*.desc*/ "PortAudio Hangup Call",
- /*.function*/ hup_call,
- /*.next*/ &channel_info_interface
+ /*.interface_name */ "pahup",
+ /*.desc */ "PortAudio Hangup Call",
+ /*.function */ hup_call,
+ /*.next */ &channel_info_interface
};
static struct switch_api_interface channel_api_interface = {
- /*.interface_name*/ "pacall",
- /*.desc*/ "PortAudio Call",
- /*.function*/ place_call,
- /*.next*/ &channel_hup_interface
+ /*.interface_name */ "pacall",
+ /*.desc */ "PortAudio Call",
+ /*.function */ place_call,
+ /*.next */ &channel_hup_interface
};
static const switch_event_handler_table channel_event_handlers = {
- /*.on_init*/ channel_on_init,
- /*.on_ring*/ channel_on_ring,
- /*.on_execute*/ channel_on_execute,
- /*.on_hangup*/ channel_on_hangup,
- /*.on_loopback*/ channel_on_loopback,
- /*.on_transmit*/ channel_on_transmit
+ /*.on_init */ channel_on_init,
+ /*.on_ring */ channel_on_ring,
+ /*.on_execute */ channel_on_execute,
+ /*.on_hangup */ channel_on_hangup,
+ /*.on_loopback */ channel_on_loopback,
+ /*.on_transmit */ channel_on_transmit
};
static const switch_io_routines channel_io_routines = {
- /*.outgoing_channel*/ channel_outgoing_channel,
- /*.answer_channel*/ channel_answer_channel,
- /*.read_frame*/ channel_read_frame,
- /*.write_frame*/ channel_write_frame,
- /*.kill_channel*/ channel_kill_channel,
- /*.waitfor_read*/ channel_waitfor_read,
- /*.waitfor_write*/ channel_waitfor_write,
- /*.send_dtmf*/ channel_send_dtmf
+ /*.outgoing_channel */ channel_outgoing_channel,
+ /*.answer_channel */ channel_answer_channel,
+ /*.read_frame */ channel_read_frame,
+ /*.write_frame */ channel_write_frame,
+ /*.kill_channel */ channel_kill_channel,
+ /*.waitfor_read */ channel_waitfor_read,
+ /*.waitfor_write */ channel_waitfor_write,
+ /*.send_dtmf */ channel_send_dtmf
};
static const switch_endpoint_interface channel_endpoint_interface = {
- /*.interface_name*/ "portaudio",
- /*.io_routines*/ &channel_io_routines,
- /*.event_handlers*/ &channel_event_handlers,
- /*.private*/ NULL,
- /*.next*/ NULL
+ /*.interface_name */ "portaudio",
+ /*.io_routines */ &channel_io_routines,
+ /*.event_handlers */ &channel_event_handlers,
+ /*.private */ NULL,
+ /*.next */ NULL
};
static const switch_loadable_module_interface channel_module_interface = {
- /*.module_name*/ modname,
- /*.endpoint_interface*/ &channel_endpoint_interface,
- /*.timer_interface*/ NULL,
- /*.dialplan_interface*/ NULL,
- /*.codec_interface*/ NULL,
- /*.application_interface*/ NULL,
- /*.api_interface*/ &channel_api_interface
+ /*.module_name */ modname,
+ /*.endpoint_interface */ &channel_endpoint_interface,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ NULL,
+ /*.application_interface */ NULL,
+ /*.api_interface */ &channel_api_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)
+{
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n");
load_config();
switch_core_hash_init(&globals.call_hash, module_pool);
switch_mutex_init(&globals.device_lock, SWITCH_MUTEX_NESTED, module_pool);
-
+
dump_info();
if (switch_event_reserve_subclass(MY_EVENT_RINGING) != SWITCH_STATUS_SUCCESS) {
switch_config cfg;
char *var, *val;
char *cf = "portaudio.conf";
-
+
memset(&globals, 0, sizeof(globals));
-
+
if (!switch_config_open_file(&cfg, cf)) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
}
-
+
while (switch_config_next_pair(&cfg, &var, &val)) {
if (!strcasecmp(cfg.category, "settings")) {
if (!strcmp(var, "debug")) {
set_global_cid_num(val);
} else if (!strcmp(var, "indev")) {
if (*val == '#') {
- globals.indev = atoi(val+1);
+ globals.indev = atoi(val + 1);
} else {
globals.indev = get_dev_by_name(val, 1);
}
} else if (!strcmp(var, "outdev")) {
if (*val == '#') {
- globals.outdev = atoi(val+1);
+ globals.outdev = atoi(val + 1);
} else {
globals.outdev = get_dev_by_name(val, 0);
}
if (!globals.dialplan) {
set_global_dialplan("default");
}
-
+
if (!globals.sample_rate) {
globals.sample_rate = 8000;
}
switch_config_close_file(&cfg);
-
+
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
{
- Pa_Terminate();
-
+ Pa_Terminate();
+
return SWITCH_STATUS_SUCCESS;
}
static int get_dev_by_name(char *name, int in)
{
- int i;
- int numDevices;
- const PaDeviceInfo *pdi;
- numDevices = Pa_CountDevices();
-
- if( numDevices < 0 ) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices );
- return -2;
- }
-
- for( i=0; i<numDevices; i++ ) {
- pdi = Pa_GetDeviceInfo( i );
- if(strstr(pdi->name, name)) {
- if(in && pdi->maxInputChannels) {
+ int i;
+ int numDevices;
+ const PaDeviceInfo *pdi;
+ numDevices = Pa_CountDevices();
+
+ if (numDevices < 0) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices);
+ return -2;
+ }
+
+ for (i = 0; i < numDevices; i++) {
+ pdi = Pa_GetDeviceInfo(i);
+ if (strstr(pdi->name, name)) {
+ if (in && pdi->maxInputChannels) {
return i;
} else if (!in && pdi->maxOutputChannels) {
return i;
static int dump_info(void)
{
- int i,j;
- int numDevices;
- const PaDeviceInfo *pdi;
- PaError err;
- numDevices = Pa_CountDevices();
- if( numDevices < 0 )
- {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices );
- err = numDevices;
- goto error;
- }
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Number of devices = %d\n", numDevices );
- for( i=0; i<numDevices; i++ )
- {
- pdi = Pa_GetDeviceInfo( i );
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "---------------------------------------------- #%d", i );
- if( i == Pa_GetDefaultInputDeviceID() ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, " DefaultInput");
- if( i == Pa_GetDefaultOutputDeviceID() ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, " DefaultOutput");
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "\nName = %s\n", pdi->name );
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Max Inputs = %d", pdi->maxInputChannels );
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, ", Max Outputs = %d\n", pdi->maxOutputChannels );
- if( pdi->numSampleRates == -1 )
- {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Sample Rate Range = %f to %f\n", pdi->sampleRates[0], pdi->sampleRates[1] );
- }
- else
- {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Sample Rates =");
- for( j=0; j<pdi->numSampleRates; j++ )
- {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, " %8.2f,", pdi->sampleRates[j] );
- }
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "\n");
- }
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Native Sample Formats = ");
- if( pdi->nativeSampleFormats & paInt8 ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt8, ");
- if( pdi->nativeSampleFormats & paUInt8 ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paUInt8, ");
- if( pdi->nativeSampleFormats & paInt16 ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt16, ");
- if( pdi->nativeSampleFormats & paInt32 ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt32, ");
- if( pdi->nativeSampleFormats & paFloat32 ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paFloat32, ");
- if( pdi->nativeSampleFormats & paInt24 ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt24, ");
- if( pdi->nativeSampleFormats & paPackedInt24 ) switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paPackedInt24, ");
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "\n");
- }
-
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "----------------------------------------------\n");
- return 0;
-error:
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "An error occured while using the portaudio stream\n" );
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Error number: %d\n", err );
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Error message: %s\n", Pa_GetErrorText( err ) );
- return err;
+ int i, j;
+ int numDevices;
+ const PaDeviceInfo *pdi;
+ PaError err;
+ numDevices = Pa_CountDevices();
+ if (numDevices < 0) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "ERROR: Pa_CountDevices returned 0x%x\n", numDevices);
+ err = numDevices;
+ goto error;
+ }
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Number of devices = %d\n", numDevices);
+ for (i = 0; i < numDevices; i++) {
+ pdi = Pa_GetDeviceInfo(i);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "---------------------------------------------- #%d", i);
+ if (i == Pa_GetDefaultInputDeviceID())
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, " DefaultInput");
+ if (i == Pa_GetDefaultOutputDeviceID())
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, " DefaultOutput");
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "\nName = %s\n", pdi->name);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Max Inputs = %d", pdi->maxInputChannels);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, ", Max Outputs = %d\n", pdi->maxOutputChannels);
+ if (pdi->numSampleRates == -1) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Sample Rate Range = %f to %f\n", pdi->sampleRates[0],
+ pdi->sampleRates[1]);
+ } else {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Sample Rates =");
+ for (j = 0; j < pdi->numSampleRates; j++) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, " %8.2f,", pdi->sampleRates[j]);
+ }
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "\n");
+ }
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Native Sample Formats = ");
+ if (pdi->nativeSampleFormats & paInt8)
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt8, ");
+ if (pdi->nativeSampleFormats & paUInt8)
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paUInt8, ");
+ if (pdi->nativeSampleFormats & paInt16)
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt16, ");
+ if (pdi->nativeSampleFormats & paInt32)
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt32, ");
+ if (pdi->nativeSampleFormats & paFloat32)
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paFloat32, ");
+ if (pdi->nativeSampleFormats & paInt24)
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paInt24, ");
+ if (pdi->nativeSampleFormats & paPackedInt24)
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "paPackedInt24, ");
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "\n");
+ }
+
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "----------------------------------------------\n");
+ return 0;
+ error:
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "An error occured while using the portaudio stream\n");
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Error number: %d\n", err);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Error message: %s\n", Pa_GetErrorText(err));
+ return err;
}
static switch_status engage_device(struct private_object *tech_pvt)
codec_ms,
1,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+ NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
+ return SWITCH_STATUS_FALSE;
+ } else {
+ if (switch_core_codec_init(&tech_pvt->write_codec,
+ "L16",
+ sample_rate,
+ codec_ms,
+ 1,
+ SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
+ NULL, switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
+ switch_core_codec_destroy(&tech_pvt->read_codec);
return SWITCH_STATUS_FALSE;
- } else {
- if (switch_core_codec_init(&tech_pvt->write_codec,
- "L16",
- sample_rate,
- codec_ms,
- 1,
- SWITCH_CODEC_FLAG_ENCODE |SWITCH_CODEC_FLAG_DECODE,
- NULL,
- switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't load codec?\n");
- switch_core_codec_destroy(&tech_pvt->read_codec);
- return SWITCH_STATUS_FALSE;
- }
}
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Loaded codec L16 %dhz %dms on %s\n", sample_rate, codec_ms, switch_channel_get_name(channel));
- tech_pvt->read_frame.rate = sample_rate;
- tech_pvt->read_frame.codec = &tech_pvt->read_codec;
- switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
- switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
-
- tech_pvt->indev = globals.indev;
- tech_pvt->outdev = globals.outdev;
-
- switch_mutex_lock(globals.device_lock);
- if ((tech_pvt->err = OpenAudioStream( &tech_pvt->audio_in, sample_rate, SAMPLE_TYPE, PABLIO_READ | PABLIO_MONO, tech_pvt->indev, -1)) == paNoError) {
- if ((tech_pvt->err = OpenAudioStream(&tech_pvt->audio_out, sample_rate, SAMPLE_TYPE, PABLIO_WRITE | PABLIO_MONO, -1, tech_pvt->outdev)) != paNoError) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open audio out [%d]!\n", tech_pvt->outdev);
- CloseAudioStream(tech_pvt->audio_in);
- tech_pvt->audio_in = NULL;
- }
- } else {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open audio in [%d]!\n", tech_pvt->indev);
- }
- switch_mutex_unlock(globals.device_lock);
+ }
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Loaded codec L16 %dhz %dms on %s\n", sample_rate, codec_ms,
+ switch_channel_get_name(channel));
+ tech_pvt->read_frame.rate = sample_rate;
+ tech_pvt->read_frame.codec = &tech_pvt->read_codec;
+ switch_core_session_set_read_codec(tech_pvt->session, &tech_pvt->read_codec);
+ switch_core_session_set_write_codec(tech_pvt->session, &tech_pvt->write_codec);
- if (tech_pvt->err == paNoError) {
- snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", globals.call_id++);
- switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
- return SWITCH_STATUS_SUCCESS;
- } else {
- switch_core_codec_destroy(&tech_pvt->read_codec);
- switch_core_codec_destroy(&tech_pvt->write_codec);
- switch_core_session_destroy(&tech_pvt->session);
+ tech_pvt->indev = globals.indev;
+ tech_pvt->outdev = globals.outdev;
+
+ switch_mutex_lock(globals.device_lock);
+ if ((tech_pvt->err =
+ OpenAudioStream(&tech_pvt->audio_in, sample_rate, SAMPLE_TYPE, PABLIO_READ | PABLIO_MONO, tech_pvt->indev,
+ -1)) == paNoError) {
+ if ((tech_pvt->err =
+ OpenAudioStream(&tech_pvt->audio_out, sample_rate, SAMPLE_TYPE, PABLIO_WRITE | PABLIO_MONO, -1,
+ tech_pvt->outdev)) != paNoError) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open audio out [%d]!\n", tech_pvt->outdev);
+ CloseAudioStream(tech_pvt->audio_in);
+ tech_pvt->audio_in = NULL;
}
-
- return SWITCH_STATUS_FALSE;
+ } else {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open audio in [%d]!\n", tech_pvt->indev);
+ }
+ switch_mutex_unlock(globals.device_lock);
+
+ if (tech_pvt->err == paNoError) {
+ snprintf(tech_pvt->call_id, sizeof(tech_pvt->call_id), "%d", globals.call_id++);
+ switch_core_hash_insert(globals.call_hash, tech_pvt->call_id, tech_pvt);
+ return SWITCH_STATUS_SUCCESS;
+ } else {
+ switch_core_codec_destroy(&tech_pvt->read_codec);
+ switch_core_codec_destroy(&tech_pvt->write_codec);
+ switch_core_session_destroy(&tech_pvt->session);
+ }
+
+ return SWITCH_STATUS_FALSE;
}
static switch_status place_call(char *dest, char *out, size_t outlen)
if ((tech_pvt->caller_profile = switch_caller_profile_new(session,
globals.dialplan,
globals.cid_name,
- globals.cid_num,
- NULL,
- NULL,
- NULL,
- dest))) {
+ globals.cid_num, NULL, NULL, NULL, dest))) {
char name[128];
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
- snprintf(name, sizeof(name), "PortAudio/%s-%04x", tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : modname, rand() & 0xffff);
+ snprintf(name, sizeof(name), "PortAudio/%s-%04x",
+ tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->
+ destination_number : modname, rand() & 0xffff);
switch_channel_set_name(channel, name);
}
tech_pvt->session = session;
switch_core_session_thread_launch(tech_pvt->session);
snprintf(out, outlen, "SUCCESS: %s", tech_pvt->call_id);
}
- }
+ }
return status;
}
callid = tmp;
}
if (!callid || !strcasecmp(callid, "all")) {
- switch_hash_index_t* hi;
+ switch_hash_index_t *hi;
void *val;
int i = 0;
return SWITCH_STATUS_SUCCESS;
}
-
+
if ((tech_pvt = switch_core_hash_find(globals.call_hash, callid))) {
channel = switch_core_session_get_channel(tech_pvt->session);
assert(channel != NULL);
snprintf(out, outlen, "CALL %s\t%s\t%s\t%s\t%s\n",
- tech_pvt->call_id,
+ tech_pvt->call_id,
tech_pvt->caller_profile->caller_id_name ? tech_pvt->caller_profile->caller_id_name : "n/a",
tech_pvt->caller_profile->caller_id_number ? tech_pvt->caller_profile->caller_id_number : "n/a",
tech_pvt->caller_profile->destination_number ? tech_pvt->caller_profile->destination_number : "n/a",
static switch_status call_info(char *callid, char *out, size_t outlen)
{
struct private_object *tech_pvt;
- switch_hash_index_t* hi;
+ switch_hash_index_t *hi;
void *val;
if (!callid || !strcasecmp(callid, "all")) {
for (hi = apr_hash_first(module_pool, globals.call_hash); hi; hi = switch_hash_next(hi)) {
switch_hash_this(hi, NULL, NULL, &val);
tech_pvt = val;
- print_info(tech_pvt, out + strlen(out), outlen - strlen(out));
+ print_info(tech_pvt, out + strlen(out), outlen - strlen(out));
}
} else if ((tech_pvt = switch_core_hash_find(globals.call_hash, callid))) {
print_info(tech_pvt, out, outlen);
} else {
strncpy(out, "NO SUCH CALL", outlen - 1);
}
-
+
return SWITCH_STATUS_SUCCESS;
}
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
*\r
- */\r
-\r
+ */ \r
+ \r
/* History:\r
* PLB021214 - check for valid stream in CloseAudioStream() to prevent hang.\r
* add timeOutMSec to CloseAudioStream() to prevent hang.\r
- */\r
+ */ \r
#include <stdio.h>\r
#include <stdlib.h>\r
#include <math.h>\r
#include "ringbuffer.h"\r
#include "pablio.h"\r
#include <string.h>\r
-\r
-/************************************************************************/\r
-/******** Constants *****************************************************/\r
-/************************************************************************/\r
-\r
+ \r
+/************************************************************************/ \r
+/******** Constants *****************************************************/ \r
+/************************************************************************/ \r
+ \r
#define FRAMES_PER_BUFFER (256)\r
-\r
-/************************************************************************/\r
-/******** Prototypes ****************************************************/\r
-/************************************************************************/\r
-\r
-static int blockingIOCallback( void *inputBuffer, void *outputBuffer,\r
- unsigned long framesPerBuffer,\r
- PaTimestamp outTime, void *userData );\r
-static PaError PABLIO_InitFIFO( RingBuffer *rbuf, long numFrames, long bytesPerFrame );\r
-static PaError PABLIO_TermFIFO( RingBuffer *rbuf );\r
-\r
-/************************************************************************/\r
-/******** Functions *****************************************************/\r
-/************************************************************************/\r
-\r
+ \r
+/************************************************************************/ \r
+/******** Prototypes ****************************************************/ \r
+/************************************************************************/ \r
+\rstatic int blockingIOCallback(void *inputBuffer, void *outputBuffer, \runsigned long framesPerBuffer,
+ \rPaTimestamp outTime, void *userData);
+\rstatic PaError PABLIO_InitFIFO(RingBuffer * rbuf, long numFrames, long bytesPerFrame);
+\rstatic PaError PABLIO_TermFIFO(RingBuffer * rbuf);
+\r\r
+/************************************************************************/ \r
+/******** Functions *****************************************************/ \r
+/************************************************************************/ \r
+ \r
/* Called from PortAudio.\r
* Read and write data only if there is room in FIFOs.\r
- */\r
-static int blockingIOCallback( void *inputBuffer, void *outputBuffer,\r
- unsigned long framesPerBuffer,\r
- PaTimestamp outTime, void *userData )\r
-{\r
- PABLIO_Stream *data = (PABLIO_Stream*)userData;\r
- long numBytes = data->bytesPerFrame * framesPerBuffer;\r
- (void) outTime;\r
-\r
- /* This may get called with NULL inputBuffer during initial setup. */\r
- if( inputBuffer != NULL )\r
- {\r
- RingBuffer_Write( &data->inFIFO, inputBuffer, numBytes );\r
- }\r
- if( outputBuffer != NULL )\r
- {\r
- int i;\r
- int numRead = RingBuffer_Read( &data->outFIFO, outputBuffer, numBytes );\r
- /* Zero out remainder of buffer if we run out of data. */\r
- for( i=numRead; i<numBytes; i++ )\r
- {\r
- ((char *)outputBuffer)[i] = 0;\r
- }\r
- }\r
-\r
- return 0;\r
-}\r
-\r
-/* Allocate buffer. */\r
-static PaError PABLIO_InitFIFO( RingBuffer *rbuf, long numFrames, long bytesPerFrame )\r
-{\r
- long numBytes = numFrames * bytesPerFrame;\r
- char *buffer = (char *) malloc( numBytes );\r
- if( buffer == NULL ) return paInsufficientMemory;\r
- memset( buffer, 0, numBytes );\r
- return (PaError) RingBuffer_Init( rbuf, numBytes, buffer );\r
-}\r
-\r
-/* Free buffer. */\r
-static PaError PABLIO_TermFIFO( RingBuffer *rbuf )\r
-{\r
- if( rbuf->buffer ) free( rbuf->buffer );\r
- rbuf->buffer = NULL;\r
- return paNoError;\r
-}\r
-\r
+ */ \r
+static int blockingIOCallback(void *inputBuffer, void *outputBuffer, \runsigned long framesPerBuffer,
+ \rPaTimestamp outTime, void *userData) \r
+{
+ \rPABLIO_Stream * data = (PABLIO_Stream *) userData;
+ \rlong numBytes = data->bytesPerFrame * framesPerBuffer;
+ \r(void) outTime;
+ \r\r
+ /* This may get called with NULL inputBuffer during initial setup. */ \r
+ if (inputBuffer != NULL)
+ \r {
+ \rRingBuffer_Write(&data->inFIFO, inputBuffer, numBytes);
+ \r}
+ \rif (outputBuffer != NULL)
+ \r {
+ \rint i;
+ \rint numRead = RingBuffer_Read(&data->outFIFO, outputBuffer, numBytes);
+ \r
+ /* Zero out remainder of buffer if we run out of data. */ \r
+ for (i = numRead; i < numBytes; i++)
+ \r {
+ \r((char *) outputBuffer)[i] = 0;
+ \r} \r}
+ \r\rreturn 0;
+\r}
+
+\r\r
+/* Allocate buffer. */ \r
+static PaError PABLIO_InitFIFO(RingBuffer * rbuf, long numFrames, long bytesPerFrame) \r
+{
+ \rlong numBytes = numFrames * bytesPerFrame;
+ \rchar *buffer = (char *) malloc(numBytes);
+ \rif (buffer == NULL)
+ return paInsufficientMemory;
+ \rmemset(buffer, 0, numBytes);
+ \rreturn (PaError) RingBuffer_Init(rbuf, numBytes, buffer);
+\r}
+
+\r\r
+/* Free buffer. */ \r
+static PaError PABLIO_TermFIFO(RingBuffer * rbuf) \r
+{
+ \rif (rbuf->buffer)
+ free(rbuf->buffer);
+ \rrbuf->buffer = NULL;
+ \rreturn paNoError;
+\r}
+
+\r\r
/************************************************************\r
* Write data to ring buffer.\r
* Will not return until all the data has been written.\r
- */\r
-long WriteAudioStream( PABLIO_Stream *aStream, void *data, long numFrames )\r
-{\r
- long bytesWritten;\r
- char *p = (char *) data;\r
- long numBytes = aStream->bytesPerFrame * numFrames;\r
- while( numBytes > 0)\r
- {\r
- bytesWritten = RingBuffer_Write( &aStream->outFIFO, p, numBytes );\r
- numBytes -= bytesWritten;\r
- p += bytesWritten;\r
- if( numBytes > 0) Pa_Sleep(10);\r
- }\r
- return numFrames;\r
-}\r
-\r
+ */ \r
+long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames) \r
+{
+ \rlong bytesWritten;
+ \rchar *p = (char *) data;
+ \rlong numBytes = aStream->bytesPerFrame * numFrames;
+ \rwhile (numBytes > 0)
+ \r {
+ \rbytesWritten = RingBuffer_Write(&aStream->outFIFO, p, numBytes);
+ \rnumBytes -= bytesWritten;
+ \rp += bytesWritten;
+ \rif (numBytes > 0)
+ Pa_Sleep(10);
+ \r}
+ \rreturn numFrames;
+\r}
+
+\r\r
/************************************************************\r
* Read data from ring buffer.\r
* Will not return until all the data has been read.\r
- */\r
-long ReadAudioStream( PABLIO_Stream *aStream, void *data, long numFrames )\r
-{\r
- long bytesRead;\r
- char *p = (char *) data;\r
- long numBytes = aStream->bytesPerFrame * numFrames;\r
- while( numBytes > 0)\r
- {\r
- bytesRead = RingBuffer_Read( &aStream->inFIFO, p, numBytes );\r
- numBytes -= bytesRead;\r
- p += bytesRead;\r
- if( numBytes > 0) Pa_Sleep(10);\r
- }\r
- return numFrames;\r
-}\r
-\r
+ */ \r
+long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames) \r
+{
+ \rlong bytesRead;
+ \rchar *p = (char *) data;
+ \rlong numBytes = aStream->bytesPerFrame * numFrames;
+ \rwhile (numBytes > 0)
+ \r {
+ \rbytesRead = RingBuffer_Read(&aStream->inFIFO, p, numBytes);
+ \rnumBytes -= bytesRead;
+ \rp += bytesRead;
+ \rif (numBytes > 0)
+ Pa_Sleep(10);
+ \r}
+ \rreturn numFrames;
+\r}
+
+\r\r
/************************************************************\r
* Return the number of frames that could be written to the stream without\r
* having to wait.\r
- */\r
-long GetAudioStreamWriteable( PABLIO_Stream *aStream )\r
-{\r
- int bytesEmpty = RingBuffer_GetWriteAvailable( &aStream->outFIFO );\r
- return bytesEmpty / aStream->bytesPerFrame;\r
-}\r
-\r
+ */ \r
+long GetAudioStreamWriteable(PABLIO_Stream * aStream) \r
+{
+ \rint bytesEmpty = RingBuffer_GetWriteAvailable(&aStream->outFIFO);
+ \rreturn bytesEmpty / aStream->bytesPerFrame;
+\r}
+
+\r\r
/************************************************************\r
* Return the number of frames that are available to be read from the\r
* stream without having to wait.\r
- */\r
-long GetAudioStreamReadable( PABLIO_Stream *aStream )\r
-{\r
- int bytesFull = RingBuffer_GetReadAvailable( &aStream->inFIFO );\r
- return bytesFull / aStream->bytesPerFrame;\r
-}\r
-\r
-/************************************************************/\r
-static unsigned long RoundUpToNextPowerOf2( unsigned long n )\r
-{\r
- long numBits = 0;\r
- if( ((n-1) & n) == 0) return n; /* Already Power of two. */\r
- while( n > 0 )\r
- {\r
- n= n>>1;\r
- numBits++;\r
- }\r
- return (1<<numBits);\r
-}\r
-\r
+ */ \r
+long GetAudioStreamReadable(PABLIO_Stream * aStream) \r
+{
+ \rint bytesFull = RingBuffer_GetReadAvailable(&aStream->inFIFO);
+ \rreturn bytesFull / aStream->bytesPerFrame;
+\r}
+
+\r\r
+/************************************************************/ \r
+static unsigned long RoundUpToNextPowerOf2(unsigned long n) \r
+{
+ \rlong numBits = 0;
+ \rif (((n - 1) & n) == 0)
+ return n; /* Already Power of two. */
+ \rwhile (n > 0)
+ \r {
+ \rn = n >> 1;
+ \rnumBits++;
+ \r}
+ \rreturn (1 << numBits);
+\r}
+
+\r\r
/************************************************************\r
* Opens a PortAudio stream with default characteristics.\r
* Allocates PABLIO_Stream structure.\r
* flags parameter can be an ORed combination of:\r
* PABLIO_READ, PABLIO_WRITE, or PABLIO_READ_WRITE,\r
* and either PABLIO_MONO or PABLIO_STEREO\r
- */\r
-PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate,\r
- PaSampleFormat format, long flags, int indev, int outdev )\r
-{\r
- long bytesPerSample;\r
- long doRead = 0;\r
- long doWrite = 0;\r
- PaError err;\r
- PABLIO_Stream *aStream;\r
- long minNumBuffers;\r
- long numFrames;\r
-\r
- /* Allocate PABLIO_Stream structure for caller. */\r
- aStream = (PABLIO_Stream *) malloc( sizeof(PABLIO_Stream) );\r
- if( aStream == NULL ) return paInsufficientMemory;\r
- memset( aStream, 0, sizeof(PABLIO_Stream) );\r
-\r
- /* Determine size of a sample. */\r
- bytesPerSample = Pa_GetSampleSize( format );\r
- if( bytesPerSample < 0 )\r
- {\r
- err = (PaError) bytesPerSample;\r
- goto error;\r
- }\r
- aStream->samplesPerFrame = ((flags&PABLIO_MONO) != 0) ? 1 : 2;\r
- aStream->bytesPerFrame = bytesPerSample * aStream->samplesPerFrame;\r
-\r
- /* Initialize PortAudio */\r
- err = Pa_Initialize();\r
- if( err != paNoError ) goto error;\r
-\r
- /* Warning: numFrames must be larger than amount of data processed per interrupt\r
- * inside PA to prevent glitches. Just to be safe, adjust size upwards.\r
- */\r
- minNumBuffers = 2 * Pa_GetMinNumBuffers( FRAMES_PER_BUFFER, sampleRate );\r
- numFrames = minNumBuffers * FRAMES_PER_BUFFER;\r
- /* The PortAudio callback runs in a high priority thread. But PABLIO\r
- * runs in a normal foreground thread. So we may have much worse\r
- * latency in PABLIO. So adjust latency to a safe level.\r
- */\r
- {\r
- const int safeLatencyMSec = 200;\r
- int minLatencyMSec = (int) ((1000 * numFrames) / sampleRate);\r
- if( minLatencyMSec < safeLatencyMSec )\r
- {\r
- numFrames = (int) ((safeLatencyMSec * sampleRate) / 1000);\r
- }\r
- }\r
- numFrames = RoundUpToNextPowerOf2( numFrames );\r
-\r
- /* Initialize Ring Buffers */\r
- doRead = ((flags & PABLIO_READ) != 0);\r
- doWrite = ((flags & PABLIO_WRITE) != 0);\r
- if(doRead)\r
- {\r
- err = PABLIO_InitFIFO( &aStream->inFIFO, numFrames, aStream->bytesPerFrame );\r
- if( err != paNoError ) goto error;\r
- }\r
- if(doWrite)\r
- {\r
- long numBytes;\r
- err = PABLIO_InitFIFO( &aStream->outFIFO, numFrames, aStream->bytesPerFrame );\r
- if( err != paNoError ) goto error;\r
- /* Make Write FIFO appear full initially. */\r
- numBytes = RingBuffer_GetWriteAvailable( &aStream->outFIFO );\r
- RingBuffer_AdvanceWriteIndex( &aStream->outFIFO, numBytes );\r
- }\r
-\r
- /* Open a PortAudio stream that we will use to communicate with the underlying\r
- * audio drivers. */\r
- err = Pa_OpenStream(\r
- &aStream->stream,\r
- (doRead ? (indev > -1) ? indev : Pa_GetDefaultInputDeviceID() : paNoDevice),\r
- (doRead ? aStream->samplesPerFrame : 0 ),\r
- format,\r
- NULL,\r
- (doWrite ? (outdev > -1) ? outdev : Pa_GetDefaultOutputDeviceID() : paNoDevice),\r
- (doWrite ? aStream->samplesPerFrame : 0 ),\r
- format,\r
- NULL,\r
- sampleRate,\r
- FRAMES_PER_BUFFER,\r
- minNumBuffers,\r
- paClipOff, /* we won't output out of range samples so don't bother clipping them */\r
- blockingIOCallback,\r
- aStream );\r
- if( err != paNoError ) goto error;\r
-\r
- err = Pa_StartStream( aStream->stream );\r
- if( err != paNoError ) goto error;\r
-\r
- *rwblPtr = aStream;\r
- return paNoError;\r
-\r
-error:\r
- CloseAudioStream( aStream );\r
- *rwblPtr = NULL;\r
- return err;\r
-}\r
-\r
-/************************************************************/\r
-PaError CloseAudioStream( PABLIO_Stream *aStream )\r
-{\r
- PaError err = paNoError;\r
- int bytesEmpty;\r
- int byteSize = aStream->outFIFO.bufferSize;\r
-\r
- if( aStream->stream != NULL ) /* Make sure stream was opened. PLB021214 */\r
- {\r
- /* If we are writing data, make sure we play everything written. */\r
- if( byteSize > 0 )\r
- {\r
- int timeOutMSec = 2000;\r
- bytesEmpty = RingBuffer_GetWriteAvailable( &aStream->outFIFO );\r
- while( (bytesEmpty < byteSize) && (timeOutMSec > 0) )\r
- {\r
- Pa_Sleep( 20 );\r
- timeOutMSec -= 20;\r
- bytesEmpty = RingBuffer_GetWriteAvailable( &aStream->outFIFO );\r
- }\r
- }\r
- err = Pa_StopStream( aStream->stream );\r
- if( err != paNoError ) goto error;\r
- err = Pa_CloseStream( aStream->stream );\r
- }\r
+ */ \r
+ PaError OpenAudioStream(PABLIO_Stream ** rwblPtr, double sampleRate, \rPaSampleFormat format, long flags, int indev,
+ int outdev) \r
+{
+ \rlong bytesPerSample;
+ \rlong doRead = 0;
+ \rlong doWrite = 0;
+ \rPaError err;
+ \rPABLIO_Stream * aStream;
+ \rlong minNumBuffers;
+ \rlong numFrames;
+ \r\r
+ /* Allocate PABLIO_Stream structure for caller. */ \r
+ aStream = (PABLIO_Stream *) malloc(sizeof(PABLIO_Stream));
+ \rif (aStream == NULL)
+ return paInsufficientMemory;
+ \rmemset(aStream, 0, sizeof(PABLIO_Stream));
+ \r\r
+ /* Determine size of a sample. */ \r
+ bytesPerSample = Pa_GetSampleSize(format);
+ \rif (bytesPerSample < 0)
+ \r {
+ \rerr = (PaError) bytesPerSample;
+ \rgoto error;
+ \r}
+ \raStream->samplesPerFrame = ((flags & PABLIO_MONO) != 0) ? 1 : 2;
+ \raStream->bytesPerFrame = bytesPerSample * aStream->samplesPerFrame;
+ \r\r
+ /* Initialize PortAudio */ \r
+ err = Pa_Initialize();
+ \rif (err != paNoError)
+ goto error;
+ \r\r
+ /* Warning: numFrames must be larger than amount of data processed per interrupt\r
+ * inside PA to prevent glitches. Just to be safe, adjust size upwards.\r
+ */ \r
+ minNumBuffers = 2 * Pa_GetMinNumBuffers(FRAMES_PER_BUFFER, sampleRate);
+ \rnumFrames = minNumBuffers * FRAMES_PER_BUFFER;
+ \r
+ /* The PortAudio callback runs in a high priority thread. But PABLIO\r
+ * runs in a normal foreground thread. So we may have much worse\r
+ * latency in PABLIO. So adjust latency to a safe level.\r
+ */ \r
+ {
+ \rconst int safeLatencyMSec = 200;
+ \rint minLatencyMSec = (int) ((1000 * numFrames) / sampleRate);
+ \rif (minLatencyMSec < safeLatencyMSec)
+ \r {
+ \rnumFrames = (int) ((safeLatencyMSec * sampleRate) / 1000);
+ \r}
+ \r} \rnumFrames = RoundUpToNextPowerOf2(numFrames);
+ \r\r
+ /* Initialize Ring Buffers */ \r
+ doRead = ((flags & PABLIO_READ) != 0);
+ \rdoWrite = ((flags & PABLIO_WRITE) != 0);
+ \rif (doRead)
+ \r {
+ \rerr = PABLIO_InitFIFO(&aStream->inFIFO, numFrames, aStream->bytesPerFrame);
+ \rif (err != paNoError)
+ goto error;
+ \r}
+ \rif (doWrite)
+ \r {
+ \rlong numBytes;
+ \rerr = PABLIO_InitFIFO(&aStream->outFIFO, numFrames, aStream->bytesPerFrame);
+ \rif (err != paNoError)
+ goto error;
+ \r
+ /* Make Write FIFO appear full initially. */ \r
+ numBytes = RingBuffer_GetWriteAvailable(&aStream->outFIFO);
+ \rRingBuffer_AdvanceWriteIndex(&aStream->outFIFO, numBytes);
+ \r}
+ \r\r
+ /* Open a PortAudio stream that we will use to communicate with the underlying\r
+ * audio drivers. */ \r
+ err = Pa_OpenStream(\r&aStream->stream, \r
+ (doRead ? (indev > -1) ? indev : Pa_GetDefaultInputDeviceID() : paNoDevice), \r
+ (doRead ? aStream->samplesPerFrame : 0), \rformat, \rNULL, \r
+ (doWrite ? (outdev > -1) ? outdev : Pa_GetDefaultOutputDeviceID() : paNoDevice), \r
+ (doWrite ? aStream->samplesPerFrame : 0), \rformat, \rNULL, \rsampleRate, \rFRAMES_PER_BUFFER,
+ \rminNumBuffers, \rpaClipOff,
+ /* we won't output out of range samples so don't bother clipping them */ \r
+ blockingIOCallback, \raStream);
+ \rif (err != paNoError)
+ goto error;
+ \r\rerr = Pa_StartStream(aStream->stream);
+ \rif (err != paNoError)
+ goto error;
+ \r\r*rwblPtr = aStream;
+ \rreturn paNoError;
+ \r\rerror:\rCloseAudioStream(aStream);
+ \r*rwblPtr = NULL;
+ \rreturn err;
+\r}
+
+\r\r
+/************************************************************/ \r
+ PaError CloseAudioStream(PABLIO_Stream * aStream) \r
+{
+ \rPaError err = paNoError;
+ \rint bytesEmpty;
+ \rint byteSize = aStream->outFIFO.bufferSize;
+ \r\rif (aStream->stream != NULL) /* Make sure stream was opened. PLB021214 */
+ \r {
+ \r
+ /* If we are writing data, make sure we play everything written. */ \r
+ if (byteSize > 0)
+ \r {
+ \rint timeOutMSec = 2000;
+ \rbytesEmpty = RingBuffer_GetWriteAvailable(&aStream->outFIFO);
+ \rwhile ((bytesEmpty < byteSize) && (timeOutMSec > 0))
+ \r {
+ \rPa_Sleep(20);
+ \rtimeOutMSec -= 20;
+ \rbytesEmpty = RingBuffer_GetWriteAvailable(&aStream->outFIFO);
+ \r}
+ \r}
+ \rerr = Pa_StopStream(aStream->stream);
+ \rif (err != paNoError)
+ goto error;
+ \rerr = Pa_CloseStream(aStream->stream);
+ \r}
+ \r\rerror:\rPa_Terminate();
+ \rPABLIO_TermFIFO(&aStream->inFIFO);
+ \rPABLIO_TermFIFO(&aStream->outFIFO);
+ \rfree(aStream);
+ \rreturn err;
+\r}
+
\r
-error:\r
- Pa_Terminate();\r
- PABLIO_TermFIFO( &aStream->inFIFO );\r
- PABLIO_TermFIFO( &aStream->outFIFO );\r
- free( aStream );\r
- return err;\r
-}\r
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
*\r
- */\r
+ */ \r
#include <stdio.h>\r
#include <stdlib.h>\r
#include <math.h>\r
#include "ringbuffer.h"\r
#include <string.h>\r
-\r
+ \r
/***************************************************************************\r
* Initialize FIFO.\r
* numBytes must be power of 2, returns -1 if not.\r
- */\r
-long RingBuffer_Init( RingBuffer *rbuf, long numBytes, void *dataPtr )\r
-{\r
- if( ((numBytes-1) & numBytes) != 0) return -1; /* Not Power of two. */\r
- rbuf->bufferSize = numBytes;\r
- rbuf->buffer = (char *)dataPtr;\r
- RingBuffer_Flush( rbuf );\r
- rbuf->bigMask = (numBytes*2)-1;\r
- rbuf->smallMask = (numBytes)-1;\r
- return 0;\r
-}\r
-/***************************************************************************\r
-** Return number of bytes available for reading. */\r
-long RingBuffer_GetReadAvailable( RingBuffer *rbuf )\r
-{\r
- return ( (rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask );\r
-}\r
-/***************************************************************************\r
-** Return number of bytes available for writing. */\r
-long RingBuffer_GetWriteAvailable( RingBuffer *rbuf )\r
-{\r
- return ( rbuf->bufferSize - RingBuffer_GetReadAvailable(rbuf));\r
-}\r
+ */ \r
+long RingBuffer_Init(RingBuffer * rbuf, long numBytes, void *dataPtr) \r
+{
+ \rif (((numBytes - 1) & numBytes) != 0)
+ return -1; /* Not Power of two. */
+ \rrbuf->bufferSize = numBytes;
+ \rrbuf->buffer = (char *) dataPtr;
+ \rRingBuffer_Flush(rbuf);
+ \rrbuf->bigMask = (numBytes * 2) - 1;
+ \rrbuf->smallMask = (numBytes) - 1;
+ \rreturn 0;
+\r}
+
\r
/***************************************************************************\r
-** Clear buffer. Should only be called when buffer is NOT being read. */\r
-void RingBuffer_Flush( RingBuffer *rbuf )\r
-{\r
- rbuf->writeIndex = rbuf->readIndex = 0;\r
-}\r
+** Return number of bytes available for reading. */ \r
+long RingBuffer_GetReadAvailable(RingBuffer * rbuf) \r
+{
+ \rreturn ((rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask);
+\r}
+
\r
+/***************************************************************************\r
+** Return number of bytes available for writing. */ \r
+long RingBuffer_GetWriteAvailable(RingBuffer * rbuf) \r
+{
+ \rreturn (rbuf->bufferSize - RingBuffer_GetReadAvailable(rbuf));
+\r}
+
+\r\r
+/***************************************************************************\r
+** Clear buffer. Should only be called when buffer is NOT being read. */ \r
+void RingBuffer_Flush(RingBuffer * rbuf) \r
+{
+ \rrbuf->writeIndex = rbuf->readIndex = 0;
+\r} \r\r
+
/***************************************************************************\r
** Get address of region(s) to which we can write data.\r
** If the region is contiguous, size2 will be zero.\r
** If non-contiguous, size2 will be the size of second region.\r
** Returns room available to be written or numBytes, whichever is smaller.\r
-*/\r
-long RingBuffer_GetWriteRegions( RingBuffer *rbuf, long numBytes,\r
- void **dataPtr1, long *sizePtr1,\r
- void **dataPtr2, long *sizePtr2 )\r
-{\r
- long index;\r
- long available = RingBuffer_GetWriteAvailable( rbuf );\r
- if( numBytes > available ) numBytes = available;\r
- /* Check to see if write is not contiguous. */\r
- index = rbuf->writeIndex & rbuf->smallMask;\r
- if( (index + numBytes) > rbuf->bufferSize )\r
- {\r
- /* Write data in two blocks that wrap the buffer. */\r
- long firstHalf = rbuf->bufferSize - index;\r
- *dataPtr1 = &rbuf->buffer[index];\r
- *sizePtr1 = firstHalf;\r
- *dataPtr2 = &rbuf->buffer[0];\r
- *sizePtr2 = numBytes - firstHalf;\r
- }\r
- else\r
- {\r
- *dataPtr1 = &rbuf->buffer[index];\r
- *sizePtr1 = numBytes;\r
- *dataPtr2 = NULL;\r
- *sizePtr2 = 0;\r
- }\r
- return numBytes;\r
-}\r
-\r
-\r
+*/ \r
+long RingBuffer_GetWriteRegions(RingBuffer * rbuf, long numBytes, \rvoid **dataPtr1, long *sizePtr1, \rvoid **dataPtr2,
+ long *sizePtr2) \r
+{
+ \rlong index;
+ \rlong available = RingBuffer_GetWriteAvailable(rbuf);
+ \rif (numBytes > available)
+ numBytes = available;
+ \r
+ /* Check to see if write is not contiguous. */ \r
+ index = rbuf->writeIndex & rbuf->smallMask;
+ \rif ((index + numBytes) > rbuf->bufferSize)
+ \r {
+ \r
+ /* Write data in two blocks that wrap the buffer. */ \r
+ long firstHalf = rbuf->bufferSize - index;
+ \r*dataPtr1 = &rbuf->buffer[index];
+ \r*sizePtr1 = firstHalf;
+ \r*dataPtr2 = &rbuf->buffer[0];
+ \r*sizePtr2 = numBytes - firstHalf;
+ \r}
+ \r
+ else
+ \r {
+ \r*dataPtr1 = &rbuf->buffer[index];
+ \r*sizePtr1 = numBytes;
+ \r*dataPtr2 = NULL;
+ \r*sizePtr2 = 0;
+ \r}
+ \rreturn numBytes;
+\r}
+
+\r\r\r
/***************************************************************************\r
-*/\r
-long RingBuffer_AdvanceWriteIndex( RingBuffer *rbuf, long numBytes )\r
-{\r
- return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask;\r
-}\r
-\r
+*/ \r
+long RingBuffer_AdvanceWriteIndex(RingBuffer * rbuf, long numBytes) \r
+{
+ \rreturn rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask;
+\r}
+
+\r\r
/***************************************************************************\r
** Get address of region(s) from which we can read data.\r
** If the region is contiguous, size2 will be zero.\r
** If non-contiguous, size2 will be the size of second region.\r
** Returns room available to be written or numBytes, whichever is smaller.\r
-*/\r
-long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes,\r
- void **dataPtr1, long *sizePtr1,\r
- void **dataPtr2, long *sizePtr2 )\r
-{\r
- long index;\r
- long available = RingBuffer_GetReadAvailable( rbuf );\r
- if( numBytes > available ) numBytes = available;\r
- /* Check to see if read is not contiguous. */\r
- index = rbuf->readIndex & rbuf->smallMask;\r
- if( (index + numBytes) > rbuf->bufferSize )\r
- {\r
- /* Write data in two blocks that wrap the buffer. */\r
- long firstHalf = rbuf->bufferSize - index;\r
- *dataPtr1 = &rbuf->buffer[index];\r
- *sizePtr1 = firstHalf;\r
- *dataPtr2 = &rbuf->buffer[0];\r
- *sizePtr2 = numBytes - firstHalf;\r
- }\r
- else\r
- {\r
- *dataPtr1 = &rbuf->buffer[index];\r
- *sizePtr1 = numBytes;\r
- *dataPtr2 = NULL;\r
- *sizePtr2 = 0;\r
- }\r
- return numBytes;\r
-}\r
-/***************************************************************************\r
-*/\r
-long RingBuffer_AdvanceReadIndex( RingBuffer *rbuf, long numBytes )\r
-{\r
- return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask;\r
-}\r
+*/ \r
+long RingBuffer_GetReadRegions(RingBuffer * rbuf, long numBytes, \rvoid **dataPtr1, long *sizePtr1, \rvoid **dataPtr2,
+ long *sizePtr2) \r
+{
+ \rlong index;
+ \rlong available = RingBuffer_GetReadAvailable(rbuf);
+ \rif (numBytes > available)
+ numBytes = available;
+ \r
+ /* Check to see if read is not contiguous. */ \r
+ index = rbuf->readIndex & rbuf->smallMask;
+ \rif ((index + numBytes) > rbuf->bufferSize)
+ \r {
+ \r
+ /* Write data in two blocks that wrap the buffer. */ \r
+ long firstHalf = rbuf->bufferSize - index;
+ \r*dataPtr1 = &rbuf->buffer[index];
+ \r*sizePtr1 = firstHalf;
+ \r*dataPtr2 = &rbuf->buffer[0];
+ \r*sizePtr2 = numBytes - firstHalf;
+ \r}
+ \r
+ else
+ \r {
+ \r*dataPtr1 = &rbuf->buffer[index];
+ \r*sizePtr1 = numBytes;
+ \r*dataPtr2 = NULL;
+ \r*sizePtr2 = 0;
+ \r}
+ \rreturn numBytes;
+\r}
+
\r
/***************************************************************************\r
-** Return bytes written. */\r
-long RingBuffer_Write( RingBuffer *rbuf, void *data, long numBytes )\r
-{\r
- long size1, size2, numWritten;\r
- void *data1, *data2;\r
- numWritten = RingBuffer_GetWriteRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 );\r
- if( size2 > 0 )\r
- {\r
-\r
- memcpy( data1, data, size1 );\r
- data = ((char *)data) + size1;\r
- memcpy( data2, data, size2 );\r
- }\r
- else\r
- {\r
- memcpy( data1, data, size1 );\r
- }\r
- RingBuffer_AdvanceWriteIndex( rbuf, numWritten );\r
- return numWritten;\r
-}\r
-\r
+*/ \r
+long RingBuffer_AdvanceReadIndex(RingBuffer * rbuf, long numBytes) \r
+{
+ \rreturn rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask;
+\r}
+
+\r\r
+/***************************************************************************\r
+** Return bytes written. */ \r
+long RingBuffer_Write(RingBuffer * rbuf, void *data, long numBytes) \r
+{
+ \rlong size1, size2, numWritten;
+ \rvoid *data1, *data2;
+ \rnumWritten = RingBuffer_GetWriteRegions(rbuf, numBytes, &data1, &size1, &data2, &size2);
+ \rif (size2 > 0)
+ \r {
+ \r\rmemcpy(data1, data, size1);
+ \rdata = ((char *) data) + size1;
+ \rmemcpy(data2, data, size2);
+ \r}
+ \r
+ else
+ \r {
+ \rmemcpy(data1, data, size1);
+ \r}
+ \rRingBuffer_AdvanceWriteIndex(rbuf, numWritten);
+ \rreturn numWritten;
+\r}
+
+\r\r
/***************************************************************************\r
-** Return bytes read. */\r
-long RingBuffer_Read( RingBuffer *rbuf, void *data, long numBytes )\r
-{\r
- long size1, size2, numRead;\r
- void *data1, *data2;\r
- numRead = RingBuffer_GetReadRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 );\r
- if( size2 > 0 )\r
- {\r
- memcpy( data, data1, size1 );\r
- data = ((char *)data) + size1;\r
- memcpy( data, data2, size2 );\r
- }\r
- else\r
- {\r
- memcpy( data, data1, size1 );\r
- }\r
- RingBuffer_AdvanceReadIndex( rbuf, numRead );\r
- return numRead;\r
-}\r
+** Return bytes read. */ \r
+long RingBuffer_Read(RingBuffer * rbuf, void *data, long numBytes) \r
+{
+ \rlong size1, size2, numRead;
+ \rvoid *data1, *data2;
+ \rnumRead = RingBuffer_GetReadRegions(rbuf, numBytes, &data1, &size1, &data2, &size2);
+ \rif (size2 > 0)
+ \r {
+ \rmemcpy(data, data1, size1);
+ \rdata = ((char *) data) + size1;
+ \rmemcpy(data, data2, size2);
+ \r}
+ \r
+ else
+ \r {
+ \rmemcpy(data, data1, size1);
+ \r}
+ \rRingBuffer_AdvanceReadIndex(rbuf, numRead);
+ \rreturn numRead;
+\r}
+
+\r
struct private_object {
- unsigned int flags; /* FLAGS */
- struct switch_frame frame; /* Frame for Writing */
+ unsigned int flags; /* FLAGS */
+ struct switch_frame frame; /* Frame for Writing */
unsigned char databuf[SWITCH_RECCOMMENDED_BUFFER_SIZE];
struct sangoma_pri *spri;
pri_event ring_event;
free(globals.dialplan);
globals.dialplan = NULL;
}
-
+
globals.dialplan = strdup(dialplan);
}
static switch_status wanpipe_on_hangup(switch_core_session *session);
static switch_status wanpipe_on_loopback(switch_core_session *session);
static switch_status wanpipe_on_transmit(switch_core_session *session);
-static switch_status wanpipe_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session);
-static switch_status wanpipe_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id);
-static switch_status wanpipe_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id);
-static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event);
-static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event);
-static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event);
+static switch_status wanpipe_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
+ switch_core_session **new_session);
+static switch_status wanpipe_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags, int stream_id);
+static switch_status wanpipe_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags, int stream_id);
+static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event);
+static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event);
+static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event);
static int check_flags(struct sangoma_pri *spri);
-static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event);
-static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event);
+static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event);
+static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event);
static void *pri_thread_run(switch_thread *thread, void *obj);
static int config_wanpipe(int reload);
assert(tech_pvt != NULL);
tech_pvt->frame.data = tech_pvt->databuf;
-
+
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WANPIPE INIT\n");
-
+
/* Move Channel's State Machine to RING */
switch_channel_set_state(channel, CS_RING);
return SWITCH_STATUS_SUCCESS;
assert(tech_pvt != NULL);
switch_socket_close(&tech_pvt->socket);
-
- pri_hangup(tech_pvt->spri->pri, tech_pvt->hangup_event.hangup.call ? tech_pvt->hangup_event.hangup.call : tech_pvt->ring_event.ring.call, tech_pvt->cause);
- pri_destroycall(tech_pvt->spri->pri, tech_pvt->hangup_event.hangup.call ? tech_pvt->hangup_event.hangup.call : tech_pvt->ring_event.ring.call);
-
+
+ pri_hangup(tech_pvt->spri->pri,
+ tech_pvt->hangup_event.hangup.call ? tech_pvt->hangup_event.hangup.call : tech_pvt->ring_event.ring.call,
+ tech_pvt->cause);
+ pri_destroycall(tech_pvt->spri->pri,
+ tech_pvt->hangup_event.hangup.call ? tech_pvt->hangup_event.hangup.call : tech_pvt->ring_event.ring.
+ call);
+
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "WANPIPE HANGUP\n");
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_SUCCESS;
}
-static switch_status wanpipe_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session)
+static switch_status wanpipe_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
+ switch_core_session **new_session)
{
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "NOT IMPLEMENTED\n");
{
struct private_object *tech_pvt;
switch_channel *channel = NULL;
-
+
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
assert(tech_pvt != NULL);
pri_answer(tech_pvt->spri->pri, tech_pvt->ring_event.ring.call, 0, 1);
-
+
return SWITCH_STATUS_SUCCESS;
}
-static switch_status wanpipe_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id)
+static switch_status wanpipe_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags, int stream_id)
{
struct private_object *tech_pvt;
switch_channel *channel = NULL;
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
+
bp = tech_pvt->databuf;
*frame = NULL;
memset(tech_pvt->databuf, 0, sizeof(tech_pvt->databuf));
while (bytes < globals.bytes_per_frame) {
- if ((res = switch_socket_waitfor(tech_pvt->socket, timeout, POLLIN|POLLERR)) < 0) {
+ if ((res = switch_socket_waitfor(tech_pvt->socket, timeout, POLLIN | POLLERR)) < 0) {
return SWITCH_STATUS_GENERR;
} else if (res == 0) {
tech_pvt->frame.datalen = 0;
return SWITCH_STATUS_SUCCESS;
}
- if ((res = sangoma_readmsg_socket(
- tech_pvt->socket,
+ if ((res = sangoma_readmsg_socket(tech_pvt->socket,
&tech_pvt->hdrframe,
- sizeof(tech_pvt->hdrframe),
- bp,
- sizeof(tech_pvt->databuf) - bytes, 0)) < 0) {
+ sizeof(tech_pvt->hdrframe), bp, sizeof(tech_pvt->databuf) - bytes, 0)) < 0) {
if (errno == EBUSY) {
continue;
} else {
bytes += res;
bp += bytes;
}
- tech_pvt->frame.datalen = bytes;
-
+ tech_pvt->frame.datalen = bytes;
+
*frame = &tech_pvt->frame;
return SWITCH_STATUS_SUCCESS;
}
-static switch_status wanpipe_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id)
+static switch_status wanpipe_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags, int stream_id)
{
struct private_object *tech_pvt;
switch_channel *channel = NULL;
while (bytes > 0) {
switch_socket_waitfor(tech_pvt->socket, -1, POLLOUT | POLLERR | POLLHUP);
- res = sangoma_sendmsg_socket(
- tech_pvt->socket,
- &tech_pvt->hdrframe,
- sizeof(tech_pvt->hdrframe),
- bp,
- PACKET_LEN, 0);
+ res = sangoma_sendmsg_socket(tech_pvt->socket,
+ &tech_pvt->hdrframe, sizeof(tech_pvt->hdrframe), bp, PACKET_LEN, 0);
if (res < 0) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Bad Write frame len %d write %d bytes returned %d errno %d!\n", frame->datalen, PACKET_LEN, res, errno);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE,
+ "Bad Write frame len %d write %d bytes returned %d errno %d!\n", frame->datalen,
+ PACKET_LEN, res, errno);
if (errno == EBUSY) {
continue;
}
return status;
}
-static const switch_io_routines wanpipe_io_routines*/ {
- /*.outgoing_channel*/ wanpipe_outgoing_channel,
- /*.answer_channel*/ wanpipe_answer_channel,
- /*.read_frame*/ wanpipe_read_frame,
- /*.write_frame*/ wanpipe_write_frame
+static const switch_io_routines wanpipe_io_routines */ {
+ /*.outgoing_channel */ wanpipe_outgoing_channel,
+ /*.answer_channel */ wanpipe_answer_channel,
+ /*.read_frame */ wanpipe_read_frame,
+ /*.write_frame */ wanpipe_write_frame
};
-static const switch_event_handler_table wanpipe_event_handlers = {
- /*.on_init*/ wanpipe_on_init,
- /*.on_ring*/ wanpipe_on_ring,
- /*.on_execute*/ NULL,
- /*.on_hangup*/ wanpipe_on_hangup,
- /*.on_loopback*/ wanpipe_on_loopback,
- /*.on_transmit*/ wanpipe_on_transmit
+static const switch_event_handler_table wanpipe_event_handlers = {
+ /*.on_init */ wanpipe_on_init,
+ /*.on_ring */ wanpipe_on_ring,
+ /*.on_execute */ NULL,
+ /*.on_hangup */ wanpipe_on_hangup,
+ /*.on_loopback */ wanpipe_on_loopback,
+ /*.on_transmit */ wanpipe_on_transmit
};
static const switch_endpoint_interface wanpipe_endpoint_interface = {
- /*.interface_name*/ "wanpipe",
- /*.io_routines*/ &wanpipe_io_routines,
- /*.event_handlers*/ &wanpipe_event_handlers,
- /*.private*/ NULL,
- /*.next*/ NULL
+ /*.interface_name */ "wanpipe",
+ /*.io_routines */ &wanpipe_io_routines,
+ /*.event_handlers */ &wanpipe_event_handlers,
+ /*.private */ NULL,
+ /*.next */ NULL
};
static const switch_loadable_module_interface wanpipe_module_interface = {
- /*.module_name*/ modname,
- /*.endpoint_interface*/ &wanpipe_endpoint_interface,
- /*.timer_interface*/ NULL,
- /*.dialplan_interface*/ NULL,
- /*.codec_interface*/ NULL,
- /*.application_interface*/ NULL
+ /*.module_name */ modname,
+ /*.endpoint_interface */ &wanpipe_endpoint_interface,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ NULL,
+ /*.application_interface */ NULL
};
-Public switch_status switch_module_load(const switch_loadable_module_interface **interface, chanr *filename) {
+Public switch_status switch_module_load(const switch_loadable_module_interface **interface, chanr * filename)
+{
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n");
return SWITCH_STATUS_TERM;
}
-
+
/* connect my internal structure to the blank pointer passed to me */
*interface = &wanpipe_module_interface;
/* Event Handlers */
-static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event)
+static int on_info(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event)
{
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "number is: %s\n", event->ring.callednum);
if (strlen(event->ring.callednum) > 3) {
return 0;
}
-static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event)
+static int on_hangup(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event)
{
struct channel_map *chanmap;
switch_core_session *session;
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
+
tech_pvt->cause = event->hangup.cause;
memcpy(&tech_pvt->hangup_event, event, sizeof(*event));
switch_channel_set_state(channel, CS_HANGUP);
}
-
- switch_console_printf(SWITCH_CHANNEL_CONSOLE,"-- Hanging up channel %d\n", event->hangup.channel);
+
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "-- Hanging up channel %d\n", event->hangup.channel);
return 0;
}
-static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event)
+static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event)
{
char name[128];
switch_core_session *session;
chanmap = spri->private;
if (chanmap->map[event->ring.channel]) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE,"--Duplicate Ring on channel %d (ignored)\n", event->ring.channel);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "--Duplicate Ring on channel %d (ignored)\n",
+ event->ring.channel);
return 0;
}
- switch_console_printf(SWITCH_CHANNEL_CONSOLE,"-- Ring on channel %d (from %s to %s)\n", event->ring.channel, event->ring.callingnum, event->ring.callednum);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "-- Ring on channel %d (from %s to %s)\n", event->ring.channel,
+ event->ring.callingnum, event->ring.callednum);
sprintf(name, "w%dg%d", globals.span, event->ring.channel);
if ((session = switch_core_session_request(&wanpipe_endpoint_interface, NULL))) {
switch_core_session_destroy(&session);
return 0;
}
-
+
if (event->ring.ani2 >= 0) {
snprintf(ani2str, 5, "%.2d", event->ring.ani2);
}
if ((tech_pvt->caller_profile = switch_caller_profile_new(session,
- globals.dialplan,
- "wanpipe fixme",
- event->ring.callingnum,
- event->ring.callingani,
- switch_strlen_zero(ani2str) ? NULL : ani2str,
- event->ring.callednum))) {
+ globals.dialplan,
+ "wanpipe fixme",
+ event->ring.callingnum,
+ event->ring.callingani,
+ switch_strlen_zero(ani2str) ? NULL : ani2str,
+ event->ring.callednum))) {
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
}
if ((fd = sangoma_create_socket_intr(spri->span, event->ring.channel)) < 0) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open fd!\n");
}
-
//sangoma_tdm_set_hw_period(fd, &tdm_api, 480);
tech_pvt->socket = fd;
static int check_flags(struct sangoma_pri *spri)
{
-
+
return 0;
}
-static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event)
+static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event)
{
int fd;
- switch_console_printf(SWITCH_CHANNEL_CONSOLE,"-- Restarting channel %d\n", event->restart.channel);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "-- Restarting channel %d\n", event->restart.channel);
if ((fd = sangoma_create_socket_intr(spri->span, event->restart.channel)) < 0) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE,"Can't open fd!\n");
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't open fd!\n");
} else {
close(fd);
}
return 0;
}
-static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event *event)
+static int on_anything(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri_event * event)
{
- switch_console_printf(SWITCH_CHANNEL_CONSOLE,"Caught Event %d (%s)\n", event_type, sangoma_pri_event_str(event_type));
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Caught Event %d (%s)\n", event_type,
+ sangoma_pri_event_str(event_type));
return 0;
}
spri->on_loop = check_flags;
spri->private = &chanmap;
sangoma_run_pri(spri);
-
+
free(spri);
return NULL;
}
-static int config_wanpipe(int reload)
+static int config_wanpipe(int reload)
{
switch_config cfg;
char *var, *val;
globals.bytes_per_frame = atoi(val);
} else if (!strcmp(var, "dialplan")) {
set_global_dialplan(val);
- }
+ }
}
}
set_global_dialplan("default");
}
- if ((spri=switch_core_alloc(module_pool, sizeof(*spri)))) {
+ if ((spri = switch_core_alloc(module_pool, sizeof(*spri)))) {
memset(spri, 0, sizeof(*spri));
- sangoma_init_pri(spri,
- globals.span,
- globals.dchan,
- 23,
- globals.pswitch,
- globals.node,
- globals.debug);
-
+ sangoma_init_pri(spri, globals.span, globals.dchan, 23, globals.pswitch, globals.node, globals.debug);
+
pri_thread_run(NULL, spri);
-
+
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "error!\n");
}
config_wanpipe(0);
return SWITCH_STATUS_TERM;
}
-
#define WOOMERA_LINE_SEPERATOR "\r\n"
#define WOOMERA_RECORD_SEPERATOR "\r\n\r\n"
#define WOOMERA_DEBUG_PREFIX "**[DEBUG]** "
-#define WOOMERA_DEBUG_LINE "--------------------------------------------------------------------------------"
+#define WOOMERA_DEBUG_LINE "--------------------------------------------------------------------------------"
#define WOOMERA_HARD_TIMEOUT -10000
#define WOOMERA_QLEN 10
#define WOOMERA_RECONNECT_TIME 5000000
static struct {
- int next_woomera_port;
+ int next_woomera_port;
int debug;
int panic;
int rtpmode;
int woomera_port;
char audio_ip[WOOMERA_STRLEN];
char dialplan[WOOMERA_STRLEN];
-// pthread_t thread;
+// pthread_t thread;
unsigned int flags;
int thread_running;
struct woomera_event_queue event_queue;
static switch_status woomerachan_on_ring(switch_core_session *session);
static switch_status woomerachan_on_loopback(switch_core_session *session);
static switch_status woomerachan_on_transmit(switch_core_session *session);
-static switch_status woomerachan_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session);
-static switch_status woomerachan_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id);
-static switch_status woomerachan_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id);
+static switch_status woomerachan_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
+ switch_core_session **new_session);
+static switch_status woomerachan_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags, int stream_id);
+static switch_status woomerachan_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags, int stream_id);
static switch_status woomerachan_kill_channel(switch_core_session *session, int sig);
-static void tech_destroy(private_object *tech_pvt);
-static void woomera_printf(woomera_profile *profile, switch_socket_t *socket, char *fmt, ...);
-static char *woomera_message_header(woomera_message *wmsg, char *key);
-static int woomera_enqueue_event(woomera_event_queue *event_queue, woomera_message *wmsg);
-static int woomera_dequeue_event(woomera_event_queue *event_queue, woomera_message *wmsg);
-static int woomera_message_parse(switch_socket_t *fd, woomera_message *wmsg, int timeout, woomera_profile *profile, woomera_event_queue *event_queue);
-static int connect_woomera(switch_socket_t **new_sock, woomera_profile *profile, int flags);
-static int woomera_profile_thread_running(woomera_profile *profile, int set, int new);
-static int woomera_locate_socket(woomera_profile *profile, switch_socket_t **woomera_socket);
-static int tech_create_read_socket(private_object *tech_pvt);
+static void tech_destroy(private_object * tech_pvt);
+static void woomera_printf(woomera_profile * profile, switch_socket_t *socket, char *fmt, ...);
+static char *woomera_message_header(woomera_message * wmsg, char *key);
+static int woomera_enqueue_event(woomera_event_queue * event_queue, woomera_message * wmsg);
+static int woomera_dequeue_event(woomera_event_queue * event_queue, woomera_message * wmsg);
+static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, int timeout, woomera_profile * profile,
+ woomera_event_queue * event_queue);
+static int connect_woomera(switch_socket_t **new_sock, woomera_profile * profile, int flags);
+static int woomera_profile_thread_running(woomera_profile * profile, int set, int new);
+static int woomera_locate_socket(woomera_profile * profile, switch_socket_t **woomera_socket);
+static int tech_create_read_socket(private_object * tech_pvt);
static void *woomera_channel_thread_run(switch_thread *thread, void *obj);
static void *woomera_thread_run(void *obj);
-static int tech_activate(private_object *tech_pvt);
+static int tech_activate(private_object * tech_pvt);
/*
State methods they get called when the state changes to the specific state
tech_pvt->frame.data = tech_pvt->databuf;
- if (switch_core_codec_init(&tech_pvt->read_codec, "L16", rate, 30, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+ if (switch_core_codec_init
+ (&tech_pvt->read_codec, "L16", rate, 30, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
+ switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s Cannot set read codec\n", switch_channel_get_name(channel));
switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE;
}
- if (switch_core_codec_init(&tech_pvt->write_codec, "L16", rate, 30, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
+ if (switch_core_codec_init
+ (&tech_pvt->write_codec, "L16", rate, 30, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
+ switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s Cannot set read codec\n", switch_channel_get_name(channel));
switch_channel_hangup(channel);
return SWITCH_STATUS_FALSE;
switch_set_flag(tech_pvt, TFLAG_ACTIVATE);
switch_core_session_launch_thread(session, woomera_channel_thread_run, session);
-
+
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s WOOMERACHAN INIT\n", switch_channel_get_name(channel));
return SWITCH_STATUS_SUCCESS;
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
-
+
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s WOOMERACHAN EXECUTE\n", switch_channel_get_name(channel));
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
-
+
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
}
-static void udp_socket_close(struct private_object *tech_pvt)
+static void udp_socket_close(struct private_object *tech_pvt)
{
if (tech_pvt->udp_socket) {
apr_socket_shutdown(tech_pvt->udp_socket, APR_SHUTDOWN_READWRITE);
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
-
+
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
udp_socket_close(tech_pvt);
switch_channel_hangup(channel);
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s WOOMERACHAN KILL %d\n", switch_channel_get_name(channel), tech_pvt->udp_socket);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "%s WOOMERACHAN KILL %d\n", switch_channel_get_name(channel),
+ tech_pvt->udp_socket);
+
-
return SWITCH_STATUS_SUCCESS;
}
/* Make sure when you have 2 sessions in the same scope that you pass the appropriate one to the routines
that allocate memory or you will have 1 channel with memory allocated from another channel's pool!
*/
-static switch_status woomerachan_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile, switch_core_session **new_session)
+static switch_status woomerachan_outgoing_channel(switch_core_session *session, switch_caller_profile *outbound_profile,
+ switch_core_session **new_session)
{
if ((*new_session = switch_core_session_request(&woomerachan_endpoint_interface, NULL))) {
struct private_object *tech_pvt;
switch_channel *channel;
-
+
switch_core_session_add_stream(*new_session, NULL);
- if ((tech_pvt = (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
+ if ((tech_pvt =
+ (struct private_object *) switch_core_session_alloc(*new_session, sizeof(struct private_object)))) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
tech_pvt->profile = &default_profile;
channel = switch_core_session_get_channel(*new_session);
return switch_socket_waitfor(&tech_pvt->write_poll, ms);
}
-static switch_status woomerachan_read_frame(switch_core_session *session, switch_frame **frame, int timeout, switch_io_flag flags, int stream_id)
+static switch_status woomerachan_read_frame(switch_core_session *session, switch_frame **frame, int timeout,
+ switch_io_flag flags, int stream_id)
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
return SWITCH_STATUS_GENERR;
}
/*
- if ((status = woomerachan_waitfor_read(session, -1)) != SWITCH_STATUS_SUCCESS) {
- return status;
- }1<
- */
+ if ((status = woomerachan_waitfor_read(session, -1)) != SWITCH_STATUS_SUCCESS) {
+ return status;
+ }1<
+ */
pframe = &tech_pvt->frame;
- *frame = pframe;
-
+ *frame = pframe;
+
pframe->datalen = sizeof(tech_pvt->databuf);
- if ((status = switch_socket_recvfrom (tech_pvt->udpread, tech_pvt->udp_socket, 0, tech_pvt->databuf, &pframe->datalen)) == SWITCH_STATUS_SUCCESS) {
- pframe->samples = (int)pframe->datalen / 2;
+ if ((status =
+ switch_socket_recvfrom(tech_pvt->udpread, tech_pvt->udp_socket, 0, tech_pvt->databuf,
+ &pframe->datalen)) == SWITCH_STATUS_SUCCESS) {
+ pframe->samples = (int) pframe->datalen / 2;
}
return status;
}
-static switch_status woomerachan_write_frame(switch_core_session *session, switch_frame *frame, int timeout, switch_io_flag flags, int stream_id)
+static switch_status woomerachan_write_frame(switch_core_session *session, switch_frame *frame, int timeout,
+ switch_io_flag flags, int stream_id)
{
switch_channel *channel = NULL;
struct private_object *tech_pvt = NULL;
pframe = &tech_pvt->frame;
return switch_socket_sendto(tech_pvt->udp_socket, tech_pvt->udpwrite, 0, frame->data, &frame->datalen);
-
+
}
static const switch_event_handler_table woomerachan_event_handlers = {
- /*.on_init*/ woomerachan_on_init,
- /*.on_ring*/ woomerachan_on_ring,
- /*.on_execute*/ woomerachan_on_execute,
- /*.on_hangup*/ woomerachan_on_hangup,
- /*.on_loopback*/ woomerachan_on_loopback,
- /*.on_transmit*/ woomerachan_on_transmit
+ /*.on_init */ woomerachan_on_init,
+ /*.on_ring */ woomerachan_on_ring,
+ /*.on_execute */ woomerachan_on_execute,
+ /*.on_hangup */ woomerachan_on_hangup,
+ /*.on_loopback */ woomerachan_on_loopback,
+ /*.on_transmit */ woomerachan_on_transmit
};
static const switch_io_routines woomerachan_io_routines = {
- /*.outgoing_channel*/ woomerachan_outgoing_channel,
- /*.answer_channel*/ NULL,
- /*.read_frame*/ woomerachan_read_frame,
- /*.write_frame*/ woomerachan_write_frame,
- /*.kill_channel*/ woomerachan_kill_channel,
- /*.waitfor_read*/ woomerachan_waitfor_read,
- /*.waitfor_write*/ woomerachan_waitfor_write
+ /*.outgoing_channel */ woomerachan_outgoing_channel,
+ /*.answer_channel */ NULL,
+ /*.read_frame */ woomerachan_read_frame,
+ /*.write_frame */ woomerachan_write_frame,
+ /*.kill_channel */ woomerachan_kill_channel,
+ /*.waitfor_read */ woomerachan_waitfor_read,
+ /*.waitfor_write */ woomerachan_waitfor_write
};
static const switch_endpoint_interface woomerachan_endpoint_interface = {
- /*.interface_name*/ "woomera",
- /*.io_routines*/ &woomerachan_io_routines,
- /*.event_handlers*/ &woomerachan_event_handlers,
- /*.private*/ NULL,
- /*.next*/ NULL
+ /*.interface_name */ "woomera",
+ /*.io_routines */ &woomerachan_io_routines,
+ /*.event_handlers */ &woomerachan_event_handlers,
+ /*.private */ NULL,
+ /*.next */ NULL
};
static const switch_loadable_module_interface woomerachan_module_interface = {
- /*.module_name*/ modname,
- /*.endpoint_interface*/ &woomerachan_endpoint_interface,
- /*.timer_interface*/ NULL,
- /*.dialplan_interface*/ NULL,
- /*.codec_interface*/ NULL,
- /*.application_interface*/ NULL
+ /*.module_name */ modname,
+ /*.endpoint_interface */ &woomerachan_endpoint_interface,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ NULL,
+ /*.application_interface */ NULL
};
-static void tech_destroy(private_object *tech_pvt)
+static void tech_destroy(private_object * tech_pvt)
{
woomera_message wmsg;
-
+
if (globals.debug > 1) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "+++DESTROY\n");
}
- woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "hangup %s%s", tech_pvt->call_info.callid, WOOMERA_RECORD_SEPERATOR);
- if(woomera_message_parse(tech_pvt->command_channel,
- &wmsg,
- WOOMERA_HARD_TIMEOUT,
- tech_pvt->profile,
- &tech_pvt->event_queue
- ) < 0) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} Already Disconnected\n", tech_pvt->profile->name);
+ woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "hangup %s%s", tech_pvt->call_info.callid,
+ WOOMERA_RECORD_SEPERATOR);
+ if (woomera_message_parse
+ (tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} Already Disconnected\n", tech_pvt->profile->name);
}
-
+
woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "bye%s", WOOMERA_RECORD_SEPERATOR);
woomera_socket_close(&tech_pvt->command_channel);
udp_socket_close(tech_pvt);
}
-static void woomera_printf(woomera_profile *profile, switch_socket_t *socket, char *fmt, ...)
+static void woomera_printf(woomera_profile * profile, switch_socket_t *socket, char *fmt, ...)
{
char *stuff;
size_t res = 0, len = 0;
va_list ap;
va_start(ap, fmt);
#ifndef vasprintf
- stuff = (char *)malloc(10240);
+ stuff = (char *) malloc(10240);
vsnprintf(stuff, 10240, fmt, ap);
#else
res = vasprintf(&stuff, fmt, ap);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Out of memory\n");
} else {
if (profile && globals.debug) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Send Message: {%s} [%s/%d]\n%s\n%s", profile->name, profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, stuff);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Send Message: {%s} [%s/%d]\n%s\n%s", profile->name,
+ profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, stuff);
}
len = strlen(stuff);
switch_socket_send(socket, stuff, &len);
-
+
free(stuff);
}
}
-static char *woomera_message_header(woomera_message *wmsg, char *key)
+static char *woomera_message_header(woomera_message * wmsg, char *key)
{
int x = 0;
char *value = NULL;
- for (x = 0 ; x < wmsg->last ; x++) {
+ for (x = 0; x < wmsg->last; x++) {
if (!strcasecmp(wmsg->names[x], key)) {
value = wmsg->values[x];
break;
return value;
}
-static int woomera_enqueue_event(woomera_event_queue *event_queue, woomera_message *wmsg)
+static int woomera_enqueue_event(woomera_event_queue * event_queue, woomera_message * wmsg)
{
woomera_message *new, *mptr;
if (!event_queue->head) {
event_queue->head = new;
} else {
- for (mptr = event_queue->head; mptr && mptr->next ; mptr = mptr->next);
+ for (mptr = event_queue->head; mptr && mptr->next; mptr = mptr->next);
mptr->next = new;
}
return 1;
return 0;
}
-static int woomera_dequeue_event(woomera_event_queue *event_queue, woomera_message *wmsg)
+static int woomera_dequeue_event(woomera_event_queue * event_queue, woomera_message * wmsg)
{
woomera_message *mptr = NULL;
-
+
if (event_queue->head) {
mptr = event_queue->head;
event_queue->head = mptr->next;
} else {
memset(wmsg, 0, sizeof(woomera_message));
}
-
+
return 0;
}
-static int woomera_message_parse(switch_socket_t *fd, woomera_message *wmsg, int timeout, woomera_profile *profile, woomera_event_queue *event_queue)
+static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, int timeout, woomera_profile * profile,
+ woomera_event_queue * event_queue)
{
char *cur, *cr, *next = NULL, *eor = NULL;
char buf[2048] = "", *ptr;
memset(wmsg, 0, sizeof(woomera_message));
- if (fd < 0 ) {
+ if (fd < 0) {
return -1;
}
next = buf;
if (globals.debug) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Receive Message: {%s} [%s/%d]\n%s\n%s", profile->name, profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, buf);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Receive Message: {%s} [%s/%d]\n%s\n%s", profile->name,
+ profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, buf);
}
- while((cur = next)) {
+ while ((cur = next)) {
if ((cr = strstr(cur, WOOMERA_LINE_SEPERATOR))) {
*cr = '\0';
next = cr + (sizeof(WOOMERA_LINE_SEPERATOR) - 1);
if (!strcmp(next, WOOMERA_RECORD_SEPERATOR)) {
break;
}
- }
+ }
if (!cur || !cur[0]) {
break;
*val = '\0';
val++;
}
- strncpy(wmsg->values[wmsg->last-1], val, WOOMERA_STRLEN);
+ strncpy(wmsg->values[wmsg->last - 1], val, WOOMERA_STRLEN);
}
- strncpy(wmsg->names[wmsg->last-1], name, WOOMERA_STRLEN);
+ strncpy(wmsg->names[wmsg->last - 1], name, WOOMERA_STRLEN);
if (name && val && !strcasecmp(name, "content-type")) {
switch_set_flag(wmsg, WFLAG_CONTENT);
bytes = atoi(val);
* wmsg will be overwritten but it's ok we just queued it.
*/
return woomera_message_parse(fd, wmsg, timeout, profile, event_queue);
-
+
} else if (wmsg->mval > 99 && wmsg->mval < 200) {
/* reply in the 100's are nice but we need to wait for another reply
call ourself recursively to find the reply > 199 and forget this reply.
- */
+ */
return woomera_message_parse(fd, wmsg, timeout, profile, event_queue);
} else {
return switch_test_flag(wmsg, WFLAG_EXISTS);
}
-static int connect_woomera(switch_socket_t **new_sock, woomera_profile *profile, int flags)
+static int connect_woomera(switch_socket_t **new_sock, woomera_profile * profile, int flags)
{
switch_sockaddr_t *sa;
return -1;
}
/*
- status = switch_socket_bind((*new_sock), sa);
- if (0 && status != SWITCH_STATUS_SUCCESS) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't Bind to %s:%d!\n", profile->woomera_host, profile->woomera_port);
- return -1;
- }
- */
+ status = switch_socket_bind((*new_sock), sa);
+ if (0 && status != SWITCH_STATUS_SUCCESS) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't Bind to %s:%d!\n", profile->woomera_host, profile->woomera_port);
+ return -1;
+ }
+ */
status = switch_socket_connect((*new_sock), sa);
if (status != SWITCH_STATUS_SUCCESS) {
return -1;
return 1;
}
-static int woomera_profile_thread_running(woomera_profile *profile, int set, int new)
+static int woomera_profile_thread_running(woomera_profile * profile, int set, int new)
{
int running = 0;
running = profile->thread_running;
switch_mutex_unlock(profile->iolock);
return running;
-
+
}
-static int woomera_locate_socket(woomera_profile *profile, switch_socket_t **woomera_socket)
+static int woomera_locate_socket(woomera_profile * profile, switch_socket_t **woomera_socket)
{
woomera_message wmsg;
-
+
for (;;) {
while (connect_woomera(woomera_socket, profile, 0) < 0) {
if (!woomera_profile_thread_running(profile, 0, 0)) {
break;
}
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} Cannot Reconnect to Woomera! retry in 5 seconds\n", profile->name);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} Cannot Reconnect to Woomera! retry in 5 seconds\n",
+ profile->name);
switch_sleep(WOOMERA_RECONNECT_TIME);
}
if (switch_test_flag(profile, PFLAG_INBOUND)) {
woomera_printf(profile, *woomera_socket, "LISTEN%s", WOOMERA_RECORD_SEPERATOR);
if (woomera_message_parse(*woomera_socket,
- &wmsg,
- WOOMERA_HARD_TIMEOUT,
- profile,
- &profile->event_queue
- ) < 0) {
+ &wmsg, WOOMERA_HARD_TIMEOUT, profile, &profile->event_queue) < 0) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", profile->name);
globals.panic = 1;
woomera_profile_thread_running(&default_profile, 1, 0);
if (*woomera_socket) {
woomera_socket_close(woomera_socket);
}
-
+
continue;
}
}
}
switch_sleep(100);
break;
- }
+ }
return *woomera_socket ? 1 : 0;
}
-static int tech_create_read_socket(private_object *tech_pvt)
+static int tech_create_read_socket(private_object * tech_pvt)
{
switch_memory_pool *pool = switch_core_session_get_pool(tech_pvt->session);
switch_sockaddr_info_get(&tech_pvt->udpread, tech_pvt->profile->audio_ip, SWITCH_UNSPEC, tech_pvt->port, 0, pool);
if (switch_socket_create(&tech_pvt->udp_socket, AF_INET, SOCK_DGRAM, 0, pool) == SWITCH_STATUS_SUCCESS) {
switch_socket_bind(tech_pvt->udp_socket, tech_pvt->udpread);
- switch_socket_create_pollfd(&tech_pvt->read_poll, tech_pvt->udp_socket, SWITCH_POLLIN|SWITCH_POLLERR, pool);
- switch_socket_create_pollfd(&tech_pvt->write_poll, tech_pvt->udp_socket, SWITCH_POLLOUT|SWITCH_POLLERR, pool);
+ switch_socket_create_pollfd(&tech_pvt->read_poll, tech_pvt->udp_socket, SWITCH_POLLIN | SWITCH_POLLERR, pool);
+ switch_socket_create_pollfd(&tech_pvt->write_poll, tech_pvt->udp_socket, SWITCH_POLLOUT | SWITCH_POLLERR, pool);
}
return 0;
}
-static int tech_activate(private_object *tech_pvt)
+static int tech_activate(private_object * tech_pvt)
{
woomera_message wmsg;
if (tech_pvt) {
- if((connect_woomera(&tech_pvt->command_channel, tech_pvt->profile, 0))) {
+ if ((connect_woomera(&tech_pvt->command_channel, tech_pvt->profile, 0))) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "connected to woomera!\n");
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Can't connect to woomera!\n");
if (switch_test_flag(tech_pvt, TFLAG_OUTBOUND)) {
woomera_printf(tech_pvt->profile,
- tech_pvt->command_channel,
- "CALL %s%sRaw-Audio: %s/%d%sLocal-Name: %s!%s%s",
+ tech_pvt->command_channel,
+ "CALL %s%sRaw-Audio: %s/%d%sLocal-Name: %s!%s%s",
tech_pvt->caller_profile->destination_number,
WOOMERA_LINE_SEPERATOR,
tech_pvt->profile->audio_ip,
tech_pvt->port,
WOOMERA_LINE_SEPERATOR,
tech_pvt->caller_profile->caller_id_name,
- tech_pvt->caller_profile->caller_id_number,
- WOOMERA_RECORD_SEPERATOR
- );
+ tech_pvt->caller_profile->caller_id_number, WOOMERA_RECORD_SEPERATOR);
woomera_message_parse(tech_pvt->command_channel,
- &wmsg,
- WOOMERA_HARD_TIMEOUT,
- tech_pvt->profile,
- &tech_pvt->event_queue
- );
+ &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue);
} else {
switch_set_flag(tech_pvt, TFLAG_PARSE_INCOMING);
woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "LISTEN%s", WOOMERA_RECORD_SEPERATOR);
if (woomera_message_parse(tech_pvt->command_channel,
- &wmsg,
- WOOMERA_HARD_TIMEOUT,
- tech_pvt->profile,
- &tech_pvt->event_queue
- ) < 0) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", tech_pvt->profile->name);
+ &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n",
+ tech_pvt->profile->name);
switch_set_flag(tech_pvt, TFLAG_ABORT);
globals.panic = 1;
}
if (!tech_pvt->udp_socket) {
tech_create_read_socket(tech_pvt);
}
-
- for(;;) {
+
+ for (;;) {
if (globals.panic) {
switch_set_flag(tech_pvt, TFLAG_ABORT);
}
if (switch_test_flag(tech_pvt, TFLAG_ANSWER)) {
switch_clear_flag(tech_pvt, TFLAG_ANSWER);
#ifdef USE_ANSWER
- woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "ANSWER %s%s",tech_pvt->call_info.callid, WOOMERA_RECORD_SEPERATOR);
- if(woomera_message_parse(tech_pvt->command_channel,
- &wmsg,
- WOOMERA_HARD_TIMEOUT,
- tech_pvt->profile,
- &tech_pvt->event_queue
- ) < 0) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", tech_pvt->profile->name);
+ woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "ANSWER %s%s", tech_pvt->call_info.callid,
+ WOOMERA_RECORD_SEPERATOR);
+ if (woomera_message_parse
+ (tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile,
+ &tech_pvt->event_queue) < 0) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n",
+ tech_pvt->profile->name);
switch_set_flag(tech_pvt, TFLAG_ABORT);
globals.panic = 1;
continue;
}
#endif
}
-
+
if (switch_test_flag(tech_pvt, TFLAG_DTMF)) {
switch_mutex_lock(tech_pvt->iolock);
- woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "DTMF %s %s%s",tech_pvt->call_info.callid, tech_pvt->dtmfbuf, WOOMERA_RECORD_SEPERATOR);
- if(woomera_message_parse(tech_pvt->command_channel,
- &wmsg,
- WOOMERA_HARD_TIMEOUT,
- tech_pvt->profile,
- &tech_pvt->event_queue
- ) < 0) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", tech_pvt->profile->name);
+ woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "DTMF %s %s%s", tech_pvt->call_info.callid,
+ tech_pvt->dtmfbuf, WOOMERA_RECORD_SEPERATOR);
+ if (woomera_message_parse
+ (tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile,
+ &tech_pvt->event_queue) < 0) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n",
+ tech_pvt->profile->name);
switch_set_flag(tech_pvt, TFLAG_ABORT);
globals.panic = 1;
continue;
memset(tech_pvt->dtmfbuf, 0, sizeof(tech_pvt->dtmfbuf));
switch_mutex_unlock(tech_pvt->iolock);
}
-
-#if 1==0 /*convert to use switch_time_now */
- if(tech_pvt->timeout) {
+#if 1==0 /*convert to use switch_time_now */
+ if (tech_pvt->timeout) {
struct timeval now;
int elapsed;
gettimeofday(&now, NULL);
- elapsed = (((now.tv_sec * 1000) + now.tv_usec / 1000) - ((tech_pvt->started.tv_sec * 1000) + tech_pvt->started.tv_usec / 1000));
+ elapsed =
+ (((now.tv_sec * 1000) + now.tv_usec / 1000) -
+ ((tech_pvt->started.tv_sec * 1000) + tech_pvt->started.tv_usec / 1000));
if (elapsed > tech_pvt->timeout) {
/* call timed out! */
switch_set_flag(tech_pvt, TFLAG_ABORT);
break;
}
/* Check for events */
- if((res = woomera_dequeue_event(&tech_pvt->event_queue, &wmsg)) ||
- (res = woomera_message_parse(tech_pvt->command_channel,
- &wmsg,
- 100,
- tech_pvt->profile,
- NULL
- ))) {
+ if ((res = woomera_dequeue_event(&tech_pvt->event_queue, &wmsg)) ||
+ (res = woomera_message_parse(tech_pvt->command_channel, &wmsg, 100, tech_pvt->profile, NULL))) {
if (res < 0 || !strcasecmp(wmsg.command, "HANGUP")) {
switch_set_flag(tech_pvt, TFLAG_ABORT);
continue;
} else if (!strcasecmp(wmsg.command, "DTMF")) {
/*
- struct ast_frame dtmf_frame = {AST_FRAME_DTMF};
- int x = 0;
- for (x = 0; x < strlen(wmsg.command_args); x++) {
- dtmf_frame.subclass = wmsg.command_args[x];
- ast_queue_frame(tech_pvt->owner, ast_frdup(&dtmf_frame));
- if (globals.debug > 1) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "SEND DTMF [%c] to %s\n", dtmf_frame.subclass, tech_pvt->owner->name);
- }
- }
- */
+ struct ast_frame dtmf_frame = {AST_FRAME_DTMF};
+ int x = 0;
+ for (x = 0; x < strlen(wmsg.command_args); x++) {
+ dtmf_frame.subclass = wmsg.command_args[x];
+ ast_queue_frame(tech_pvt->owner, ast_frdup(&dtmf_frame));
+ if (globals.debug > 1) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "SEND DTMF [%c] to %s\n", dtmf_frame.subclass, tech_pvt->owner->name);
+ }
+ }
+ */
} else if (!strcasecmp(wmsg.command, "PROCEED")) {
/* This packet has lots of info so well keep it */
tech_pvt->call_info = wmsg;
if ((p = woomera_message_header(&wmsg, "Remote-Name"))) {
strncpy(cid_name, p, sizeof(cid_name));
}
-
+
if ((cid_num = strchr(cid_name, '!'))) {
*cid_num = '\0';
cid_num++;
if ((tech_pvt->caller_profile = switch_caller_profile_new(session,
tech_pvt->profile->dialplan,
- cid_name,
- cid_num,
- ip,
- NULL,
- NULL,
- exten))) {
+ cid_name, cid_num, ip, NULL, NULL, exten))) {
char name[128];
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
- snprintf(name, sizeof(name), "Woomera/%s-%04x", tech_pvt->caller_profile->destination_number, rand() & 0xffff);
+ snprintf(name, sizeof(name), "Woomera/%s-%04x", tech_pvt->caller_profile->destination_number,
+ rand() & 0xffff);
switch_channel_set_name(channel, name);
}
- woomera_printf(tech_pvt->profile, tech_pvt->command_channel,
+ woomera_printf(tech_pvt->profile, tech_pvt->command_channel,
"%s %s%s"
"Raw-Audio: %s/%d%s",
MEDIA_ANSWER,
wmsg.callid,
WOOMERA_LINE_SEPERATOR,
- tech_pvt->profile->audio_ip,
- tech_pvt->port,
- WOOMERA_RECORD_SEPERATOR);
-
- if(woomera_message_parse(tech_pvt->command_channel,
- &wmsg,
- WOOMERA_HARD_TIMEOUT,
- tech_pvt->profile,
- &tech_pvt->event_queue
- ) < 0) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", tech_pvt->profile->name);
+ tech_pvt->profile->audio_ip, tech_pvt->port, WOOMERA_RECORD_SEPERATOR);
+
+ if (woomera_message_parse(tech_pvt->command_channel,
+ &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n",
+ tech_pvt->profile->name);
switch_set_flag(tech_pvt, TFLAG_ABORT);
globals.panic = 1;
continue;
}
-
+
} else if (!strcasecmp(wmsg.command, "CONNECT")) {
} else if (!strcasecmp(wmsg.command, "MEDIA")) {
int port = 0;
strncpy(ip, raw_audio_header, sizeof(ip) - 1);
- if ((ptr=strchr(ip, '/'))) {
+ if ((ptr = strchr(ip, '/'))) {
*ptr = '\0';
ptr++;
port = atoi(ptr);
SWITCH_UNSPEC,
port,
0,
- switch_core_session_get_pool(tech_pvt->session)) != SWITCH_STATUS_SUCCESS) {
+ switch_core_session_get_pool(tech_pvt->session)) !=
+ SWITCH_STATUS_SUCCESS) {
if (globals.debug) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "{%s} Cannot resolve %s\n", tech_pvt->profile->name, ip);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE,
+ WOOMERA_DEBUG_PREFIX "{%s} Cannot resolve %s\n",
+ tech_pvt->profile->name, ip);
}
switch_channel_hangup(channel);
}
}
}
if (globals.debug > 2) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "CHECK {%s}(%d)\n", tech_pvt->profile->name, res);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "CHECK {%s}(%d)\n",
+ tech_pvt->profile->name, res);
}
}
if (globals.debug > 1) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "Monitor thread for %s done.\n", tech_pvt->profile->name);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, WOOMERA_DEBUG_PREFIX "Monitor thread for %s done.\n",
+ tech_pvt->profile->name);
}
return NULL;
}
-
-static void *woomera_thread_run(void *obj)
+
+static void *woomera_thread_run(void *obj)
{
int res = 0;
profile = obj;
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Started Woomera Thread {%s}.\n", profile->name);
-
+
profile->thread_running = 1;
profile->woomera_socket = NULL;
- while(woomera_profile_thread_running(profile, 0, 0)) {
+ while (woomera_profile_thread_running(profile, 0, 0)) {
/* listen on socket and handle events */
if (globals.panic == 2) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Woomera is disabled!\n");
continue;
}
- if (! profile->woomera_socket) {
+ if (!profile->woomera_socket) {
if (woomera_locate_socket(profile, &profile->woomera_socket)) {
globals.panic = 0;
}
if (!woomera_profile_thread_running(profile, 0, 0)) {
break;
}
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Woomera Thread Up {%s} %s/%d\n", profile->name, profile->woomera_host, profile->woomera_port);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Woomera Thread Up {%s} %s/%d\n", profile->name,
+ profile->woomera_host, profile->woomera_port);
}
if (globals.panic) {
if (globals.panic != 2) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Help I'm in a state of panic!\n");
- globals.panic = 0;//fix
+ globals.panic = 0; //fix
}
woomera_socket_close(&profile->woomera_socket);
}
if ((res = woomera_dequeue_event(&profile->event_queue, &wmsg) ||
- (res = woomera_message_parse(profile->woomera_socket,
- &wmsg,
+ (res = woomera_message_parse(profile->woomera_socket, &wmsg,
/* if we are not stingy with threads we can block forever */
- 0,
- profile,
- NULL
- )))) {
+ 0, profile, NULL)))) {
if (res < 0) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! I lost my connection to woomera!\n", profile->name);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! I lost my connection to woomera!\n",
+ profile->name);
woomera_socket_close(&profile->woomera_socket);
//global_set_flag(TFLAG_ABORT);
if (switch_test_flag(profile, PFLAG_INBOUND)) {
woomera_printf(profile, profile->woomera_socket, "LISTEN%s", WOOMERA_RECORD_SEPERATOR);
if (woomera_message_parse(profile->woomera_socket,
- &wmsg,
- WOOMERA_HARD_TIMEOUT,
- profile,
- &profile->event_queue
- ) < 0) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n", profile->name);
+ &wmsg, WOOMERA_HARD_TIMEOUT, profile, &profile->event_queue) < 0) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "{%s} HELP! Woomera is broken!\n",
+ profile->name);
globals.panic = 1;
woomera_socket_close(&profile->woomera_socket);
- }
+ }
}
if (profile->woomera_socket) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Woomera Thread Up {%s} %s/%d\n", profile->name, profile->woomera_host, profile->woomera_port);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Woomera Thread Up {%s} %s/%d\n", profile->name,
+ profile->woomera_host, profile->woomera_port);
}
}
continue;
if (!strcasecmp(wmsg.command, "INCOMING")) {
char *name;
switch_core_session *session;
-
+
if (!(name = woomera_message_header(&wmsg, "Remote-Address"))) {
name = woomera_message_header(&wmsg, "Channel-Name");
}
-
+
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "New Inbound Channel %s!\n", name);
if ((session = switch_core_session_request(&woomerachan_endpoint_interface, NULL))) {
struct private_object *tech_pvt;
switch_core_session_add_stream(session, NULL);
- if ((tech_pvt = (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) {
+ if ((tech_pvt =
+ (struct private_object *) switch_core_session_alloc(session, sizeof(struct private_object)))) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
tech_pvt->profile = &default_profile;
channel = switch_core_session_get_channel(session);
}
}
}
-
+
if (globals.debug > 2) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Main Thread {%s} Select Return %d\n", profile->name, res);
}
switch_yield(100);
}
-
+
if (profile->woomera_socket) {
woomera_printf(profile, profile->woomera_socket, "BYE%s", WOOMERA_RECORD_SEPERATOR);
return SWITCH_STATUS_SUCCESS;
}
-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)
+{
switch_config cfg;
char *var, *val;
struct woomera_profile *profile = &default_profile;
char *cf = "woomera.conf";
-
+
memset(&globals, 0, sizeof(globals));
globals.next_woomera_port = WOOMERA_MIN_PORT;
-
+
if (!switch_config_open_file(&cfg, cf)) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
}
-
+
switch_set_flag(profile, PFLAG_INBOUND | PFLAG_OUTBOUND);
profile->name = "main";
strncpy(profile->dialplan, "default", sizeof(profile->dialplan) - 1);
-
+
while (switch_config_next_pair(&cfg, &var, &val)) {
if (!strcasecmp(cfg.category, "settings")) {
- if (!strcmp(var, "noload") && atoi(val)) {
- return SWITCH_STATUS_TERM;
- }
+ if (!strcmp(var, "noload") && atoi(val)) {
+ return SWITCH_STATUS_TERM;
+ }
if (!strcmp(var, "debug")) {
globals.debug = atoi(val);
}
switch_config_close_file(&cfg);
-
+
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
//switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no pool\n");
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "OH OH no lock\n");
return SWITCH_STATUS_TERM;
}
-
+
/* connect my internal structure to the blank pointer passed to me */
*interface = &woomerachan_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
-
-
-
static const char modname[] = "mod_event_test";
-static void event_handler (switch_event *event)
+static void event_handler(switch_event *event)
{
char buf[1024];
- switch(event->event_id) {
+ switch (event->event_id) {
case SWITCH_EVENT_LOG:
return;
break;
static switch_loadable_module_interface event_test_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
};
#define MY_EVENT_COOL "test::cool"
z = THREADS++;
- while(THREADS > 0) {
+ while (THREADS > 0) {
int x;
- for(x = 0; x < 1; x++) {
+ for (x = 0; x < 1; x++) {
if (switch_event_create_subclass(&event, SWITCH_EVENT_CUSTOM, MY_EVENT_COOL) == SWITCH_STATUS_SUCCESS) {
switch_event_add_header(event, "event_info", "hello world %d %d", z, y++);
switch_event_fire(&event);
#endif
-SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename) {
+SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename)
+{
/* connect my internal structure to the blank pointer passed to me */
*interface = &event_test_module_interface;
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Couldn't register subclass!");
return SWITCH_STATUS_GENERR;
}
-
#ifdef TORTURE_ME
- if (switch_event_bind((char *)modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
+ if (switch_event_bind((char *) modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) !=
+ SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
if (1) {
int x = 0;
- for(x = 0 ; x < TTHREADS ; x++) {
+ for (x = 0; x < TTHREADS; x++) {
switch_core_launch_thread(torture_thread, NULL);
}
}
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
-
struct session session;
} globals;
-static void event_handler (switch_event *event)
+static void event_handler(switch_event *event)
{
char buf[1024];
iks *msg;
}
}
- switch(event->event_id) {
+ switch (event->event_id) {
default:
switch_event_serialize(event, buf, sizeof(buf), NULL);
//switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nEVENT\n--------------------------------\n%s\n", buf);
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_jid, globals.jid)
- SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_target_jid, globals.target_jid)
- SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_passwd, globals.passwd)
+ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_target_jid, globals.target_jid)
+ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_passwd, globals.passwd)
static switch_status load_config(void)
char *cf = "xmpp_event.conf";
int count = 0;
- memset(&globals, 0, sizeof(globals));
+ memset(&globals, 0, sizeof(globals));
if (!switch_config_open_file(&cfg, cf)) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "open of %s failed\n", cf);
return SWITCH_STATUS_TERM;
}
-
+
while (switch_config_next_pair(&cfg, &var, &val)) {
if (!strcasecmp(cfg.category, "settings")) {
if (!strcmp(var, "jid")) {
if (count == 3) {
/* TBD use config to pick what events to bind to */
- if (switch_event_bind((char *)modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
+ if (switch_event_bind((char *) modname, SWITCH_EVENT_ALL, SWITCH_EVENT_SUBCLASS_ANY, event_handler, NULL) !=
+ SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Couldn't bind!\n");
return SWITCH_STATUS_GENERR;
}
-
+
status = SWITCH_STATUS_SUCCESS;
}
return status;
-
+
}
-int on_result (struct session *sess, ikspak *pak)
+int on_result(struct session *sess, ikspak * pak)
{
return IKS_FILTER_EAT;
}
-int on_stream (struct session *sess, int type, iks *node)
+int on_stream(struct session *sess, int type, iks * node)
{
sess->counter = opt_timeout;
switch (type) {
case IKS_NODE_START:
- if (opt_use_tls && !iks_is_secure (sess->parser)) {
- iks_start_tls (sess->parser);
+ if (opt_use_tls && !iks_is_secure(sess->parser)) {
+ iks_start_tls(sess->parser);
}
break;
case IKS_NODE_NORMAL:
- if (strcmp ("stream:features", iks_name (node)) == 0) {
- sess->features = iks_stream_features (node);
- if (opt_use_tls && !iks_is_secure (sess->parser)) break;
+ if (strcmp("stream:features", iks_name(node)) == 0) {
+ sess->features = iks_stream_features(node);
+ if (opt_use_tls && !iks_is_secure(sess->parser))
+ break;
if (sess->authorized) {
iks *t;
if (sess->features & IKS_STREAM_BIND) {
- t = iks_make_resource_bind (sess->acc);
- iks_send (sess->parser, t);
- iks_delete (t);
+ t = iks_make_resource_bind(sess->acc);
+ iks_send(sess->parser, t);
+ iks_delete(t);
}
if (sess->features & IKS_STREAM_SESSION) {
- t = iks_make_session ();
- iks_insert_attrib (t, "id", "auth");
- iks_send (sess->parser, t);
- iks_delete (t);
+ t = iks_make_session();
+ iks_insert_attrib(t, "id", "auth");
+ iks_send(sess->parser, t);
+ iks_delete(t);
}
} else {
if (sess->features & IKS_STREAM_SASL_MD5)
- iks_start_sasl (sess->parser, IKS_SASL_DIGEST_MD5, sess->acc->user, sess->pass);
+ iks_start_sasl(sess->parser, IKS_SASL_DIGEST_MD5, sess->acc->user, sess->pass);
else if (sess->features & IKS_STREAM_SASL_PLAIN)
- iks_start_sasl (sess->parser, IKS_SASL_PLAIN, sess->acc->user, sess->pass);
+ iks_start_sasl(sess->parser, IKS_SASL_PLAIN, sess->acc->user, sess->pass);
}
- } else if (strcmp ("failure", iks_name (node)) == 0) {
+ } else if (strcmp("failure", iks_name(node)) == 0) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "sasl authentication failed\n");
- } else if (strcmp ("success", iks_name (node)) == 0) {
+ } else if (strcmp("success", iks_name(node)) == 0) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "server connected\n");
sess->authorized = 1;
- iks_send_header (sess->parser, sess->acc->server);
+ iks_send_header(sess->parser, sess->acc->server);
} else {
ikspak *pak;
- pak = iks_packet (node);
- iks_filter_packet (my_filter, pak);
- if (sess->job_done == 1) return IKS_HOOK;
+ pak = iks_packet(node);
+ iks_filter_packet(my_filter, pak);
+ if (sess->job_done == 1)
+ return IKS_HOOK;
}
break;
#if 0
case IKS_NODE_STOP:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "server disconnected\n");
break;
-
+
case IKS_NODE_ERROR:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "stream error\n");
break;
}
- if (node) iks_delete (node);
+ if (node)
+ iks_delete(node);
return IKS_OK;
}
-int on_msg (void *user_data, ikspak *pak)
+int on_msg(void *user_data, ikspak * pak)
{
- char *cmd = iks_find_cdata (pak->x, "body");
+ char *cmd = iks_find_cdata(pak->x, "body");
char *arg = NULL;
char retbuf[1024] = "";
char *p;
if ((arg = strchr(cmd, ' '))) {
*arg++ = '\0';
- }
+ }
switch_api_execute(cmd, arg, retbuf, sizeof(retbuf));
return 0;
}
-int on_error (void *user_data, ikspak *pak)
+int on_error(void *user_data, ikspak * pak)
{
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "authorization failed\n");
return IKS_FILTER_EAT;
}
-void on_log (struct session *sess, const char *data, size_t size, int is_incoming)
+void on_log(struct session *sess, const char *data, size_t size, int is_incoming)
{
- if (iks_is_secure (sess->parser)) fprintf (stderr, "Sec");
- if (is_incoming) fprintf (stderr, "RECV"); else fprintf (stderr, "SEND");
- fprintf (stderr, "[%s]\n", data);
+ if (iks_is_secure(sess->parser))
+ fprintf(stderr, "Sec");
+ if (is_incoming)
+ fprintf(stderr, "RECV");
+ else
+ fprintf(stderr, "SEND");
+ fprintf(stderr, "[%s]\n", data);
}
-void j_setup_filter (struct session *sess)
+void j_setup_filter(struct session *sess)
{
- if (my_filter) iks_filter_delete (my_filter);
- my_filter = iks_filter_new ();
- iks_filter_add_rule (my_filter, on_msg, 0,
- IKS_RULE_TYPE, IKS_PAK_MESSAGE,
- IKS_RULE_SUBTYPE, IKS_TYPE_CHAT,
- IKS_RULE_FROM, globals.target_jid,
- IKS_RULE_DONE);
- iks_filter_add_rule (my_filter, (iksFilterHook *) on_result, sess,
- IKS_RULE_TYPE, IKS_PAK_IQ,
- IKS_RULE_SUBTYPE, IKS_TYPE_RESULT,
- IKS_RULE_ID, "auth",
- IKS_RULE_DONE);
- iks_filter_add_rule (my_filter, on_error, sess,
- IKS_RULE_TYPE, IKS_PAK_IQ,
- IKS_RULE_SUBTYPE, IKS_TYPE_ERROR,
- IKS_RULE_ID, "auth",
- IKS_RULE_DONE);
+ if (my_filter)
+ iks_filter_delete(my_filter);
+ my_filter = iks_filter_new();
+ iks_filter_add_rule(my_filter, on_msg, 0,
+ IKS_RULE_TYPE, IKS_PAK_MESSAGE,
+ IKS_RULE_SUBTYPE, IKS_TYPE_CHAT, IKS_RULE_FROM, globals.target_jid, IKS_RULE_DONE);
+ iks_filter_add_rule(my_filter, (iksFilterHook *) on_result, sess,
+ IKS_RULE_TYPE, IKS_PAK_IQ,
+ IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, "auth", IKS_RULE_DONE);
+ iks_filter_add_rule(my_filter, on_error, sess,
+ IKS_RULE_TYPE, IKS_PAK_IQ,
+ IKS_RULE_SUBTYPE, IKS_TYPE_ERROR, IKS_RULE_ID, "auth", IKS_RULE_DONE);
}
-static void xmpp_connect (char *jabber_id, char *pass)
+static void xmpp_connect(char *jabber_id, char *pass)
{
while (RUNNING == 1) {
int e;
- memset (&globals.session, 0, sizeof (globals.session));
- globals.session.parser = iks_stream_new (IKS_NS_CLIENT, &globals.session, (iksStreamHook *) on_stream);
- if (globals.debug) iks_set_log_hook (globals.session.parser, (iksLogHook *) on_log);
- globals.session.acc = iks_id_new (iks_parser_stack (globals.session.parser), jabber_id);
+ memset(&globals.session, 0, sizeof(globals.session));
+ globals.session.parser = iks_stream_new(IKS_NS_CLIENT, &globals.session, (iksStreamHook *) on_stream);
+ if (globals.debug)
+ iks_set_log_hook(globals.session.parser, (iksLogHook *) on_log);
+ globals.session.acc = iks_id_new(iks_parser_stack(globals.session.parser), jabber_id);
if (NULL == globals.session.acc->resource) {
/* user gave no resource name, use the default */
char tmp[512];
- sprintf (tmp, "%s@%s/%s", globals.session.acc->user, globals.session.acc->server, modname);
- globals.session.acc = iks_id_new (iks_parser_stack (globals.session.parser), tmp);
+ sprintf(tmp, "%s@%s/%s", globals.session.acc->user, globals.session.acc->server, modname);
+ globals.session.acc = iks_id_new(iks_parser_stack(globals.session.parser), tmp);
}
globals.session.pass = pass;
- j_setup_filter (&globals.session);
+ j_setup_filter(&globals.session);
- e = iks_connect_tcp (globals.session.parser, globals.session.acc->server, IKS_JABBER_PORT);
+ e = iks_connect_tcp(globals.session.parser, globals.session.acc->server, IKS_JABBER_PORT);
switch (e) {
case IKS_OK:
break;
globals.session.counter = opt_timeout;
while (RUNNING == 1) {
- e = iks_recv (globals.session.parser, 1);
+ e = iks_recv(globals.session.parser, 1);
- if(globals.session.job_done) {
+ if (globals.session.job_done) {
break;
}
- if (IKS_HOOK == e) {
+ if (IKS_HOOK == e) {
break;
}
}
if (!globals.session.authorized) {
- if (IKS_NET_TLSFAIL == e) {
+ if (IKS_NET_TLSFAIL == e) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "tls handshake failed\n");
switch_sleep(5000000);
break;
}
- if (globals.session.counter == 0) {
+ if (globals.session.counter == 0) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "network timeout\n");
switch_sleep(5000000);
break;
}
}
}
-
+
iks_disconnect(globals.session.parser);
- iks_parser_delete (globals.session.parser);
+ iks_parser_delete(globals.session.parser);
globals.session.authorized = 0;
}
RUNNING = 0;
-
+
}
-
+
static switch_loadable_module_interface xmpp_event_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_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename) {
+SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename)
+{
/* connect my internal structure to the blank pointer passed to me */
*interface = &xmpp_event_module_interface;
struct sndfile_context {
SF_INFO sfinfo;
- SNDFILE* handle;
+ SNDFILE *handle;
};
typedef struct sndfile_context sndfile_context;
char *ext;
if (!(ext = strrchr(path, '.'))) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Format\n");
- return SWITCH_STATUS_GENERR;
- }
- ext++;
-
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Invalid Format\n");
+ return SWITCH_STATUS_GENERR;
+ }
+ ext++;
+
if (switch_test_flag(handle, SWITCH_FILE_FLAG_READ)) {
mode += SFM_READ;
}
if (!strcmp(ext, "gsm")) {
- context->sfinfo.format = SF_FORMAT_RAW |SF_FORMAT_GSM610;
+ context->sfinfo.format = SF_FORMAT_RAW | SF_FORMAT_GSM610;
context->sfinfo.channels = 1;
context->sfinfo.samplerate = 8000;
}
if (!(context->handle = sf_open(path, mode, &context->sfinfo))) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error Opening File [%s] [%s]\n", path, sf_strerror(context->handle));
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Error Opening File [%s] [%s]\n", path,
+ sf_strerror(context->handle));
return SWITCH_STATUS_GENERR;
}
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Opening File [%s] %dhz\n", path, context->sfinfo.samplerate);
- handle->samples = (unsigned int)context->sfinfo.frames;
+ handle->samples = (unsigned int) context->sfinfo.frames;
handle->samplerate = context->sfinfo.samplerate;
handle->channels = context->sfinfo.channels;
handle->format = context->sfinfo.format;
sndfile_context *context = handle->private;
sf_close(context->handle);
-
+
return SWITCH_STATUS_SUCCESS;
}
switch_status sndfile_file_seek(switch_file_handle *handle, unsigned int *cur_sample, unsigned int samples, int whence)
{
sndfile_context *context = handle->private;
-
+
if (!handle->seekable) {
return SWITCH_STATUS_NOTIMPL;
}
- *cur_sample = (unsigned int)sf_seek(context->handle, samples, whence);
-
+ *cur_sample = (unsigned int) sf_seek(context->handle, samples, whence);
+
return SWITCH_STATUS_SUCCESS;
}
-switch_status sndfile_file_read (switch_file_handle *handle, void *data, size_t *len)
+switch_status sndfile_file_read(switch_file_handle *handle, void *data, size_t *len)
{
size_t inlen = *len;
sndfile_context *context = handle->private;
- if (switch_test_flag(handle, SWITCH_FILE_DATA_RAW)) {
- *len = (size_t)sf_read_raw (context->handle, data, inlen);
+ if (switch_test_flag(handle, SWITCH_FILE_DATA_RAW)) {
+ *len = (size_t) sf_read_raw(context->handle, data, inlen);
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_INT)) {
- *len = (size_t)sf_readf_int(context->handle, (int *) data, inlen);
+ *len = (size_t) sf_readf_int(context->handle, (int *) data, inlen);
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_SHORT)) {
- *len = (size_t)sf_readf_short(context->handle, (short *) data, inlen);
+ *len = (size_t) sf_readf_short(context->handle, (short *) data, inlen);
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_FLOAT)) {
- *len = (size_t)sf_readf_float(context->handle, (float *) data, inlen);
+ *len = (size_t) sf_readf_float(context->handle, (float *) data, inlen);
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_DOUBLE)) {
- *len = (size_t)sf_readf_double(context->handle, (double *) data, inlen);
+ *len = (size_t) sf_readf_double(context->handle, (double *) data, inlen);
} else {
- *len = (size_t)sf_readf_int(context->handle, (int *) data, inlen);
+ *len = (size_t) sf_readf_int(context->handle, (int *) data, inlen);
}
return SWITCH_STATUS_SUCCESS;
}
-switch_status sndfile_file_write (switch_file_handle *handle, void *data, size_t *len)
+switch_status sndfile_file_write(switch_file_handle *handle, void *data, size_t *len)
{
size_t inlen = *len;
sndfile_context *context = handle->private;
-
- if (switch_test_flag(handle, SWITCH_FILE_DATA_RAW)) {
- *len = (size_t)sf_write_raw (context->handle, data, inlen);
+
+ if (switch_test_flag(handle, SWITCH_FILE_DATA_RAW)) {
+ *len = (size_t) sf_write_raw(context->handle, data, inlen);
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_INT)) {
- *len = (size_t)sf_writef_int(context->handle, (int *) data, inlen);
+ *len = (size_t) sf_writef_int(context->handle, (int *) data, inlen);
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_SHORT)) {
- *len = (size_t)sf_writef_short(context->handle, (short *) data, inlen);
+ *len = (size_t) sf_writef_short(context->handle, (short *) data, inlen);
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_FLOAT)) {
- *len = (size_t)sf_writef_float(context->handle, (float *) data, inlen);
+ *len = (size_t) sf_writef_float(context->handle, (float *) data, inlen);
} else if (switch_test_flag(handle, SWITCH_FILE_DATA_DOUBLE)) {
- *len = (size_t)sf_writef_double(context->handle, (double *) data, inlen);
+ *len = (size_t) sf_writef_double(context->handle, (double *) data, inlen);
} else {
- *len = (size_t)sf_writef_int(context->handle, (int *) data, inlen);
+ *len = (size_t) sf_writef_int(context->handle, (int *) data, inlen);
}
return SWITCH_STATUS_SUCCESS;
static char **supported_formats;
static switch_file_interface sndfile_file_interface = {
- /*.interface_name*/ modname,
- /*.file_open*/ sndfile_file_open,
- /*.file_close*/ sndfile_file_close,
- /*.file_read*/ sndfile_file_read,
- /*.file_write*/ sndfile_file_write,
- /*.file_seek*/ sndfile_file_seek,
- /*.extens*/ NULL,
- /*.next*/ NULL,
+ /*.interface_name */ modname,
+ /*.file_open */ sndfile_file_open,
+ /*.file_close */ sndfile_file_close,
+ /*.file_read */ sndfile_file_read,
+ /*.file_write */ sndfile_file_write,
+ /*.file_seek */ sndfile_file_seek,
+ /*.extens */ NULL,
+ /*.next */ NULL,
};
static switch_loadable_module_interface sndfile_module_interface = {
- /*.module_name*/ modname,
- /*.endpoint_interface*/ NULL,
- /*.timer_interface*/ NULL,
- /*.dialplan_interface*/ NULL,
- /*.codec_interface*/ NULL,
- /*.application_interface*/ NULL,
- /*.api_interface*/ NULL,
- /*.file_interface*/ &sndfile_file_interface
+ /*.module_name */ modname,
+ /*.endpoint_interface */ NULL,
+ /*.timer_interface */ NULL,
+ /*.dialplan_interface */ NULL,
+ /*.codec_interface */ NULL,
+ /*.application_interface */ NULL,
+ /*.api_interface */ NULL,
+ /*.file_interface */ &sndfile_file_interface
};
static switch_status setup_formats(void)
{
- SF_FORMAT_INFO info ;
- SF_INFO sfinfo ;
- char buffer [128] ;
- int format, major_count, subtype_count, m, s ;
- int len,x,skip;
- char *extras[] = {"r8", "r16", "r24", "r32", "gsm", NULL};
+ SF_FORMAT_INFO info;
+ SF_INFO sfinfo;
+ char buffer[128];
+ int format, major_count, subtype_count, m, s;
+ int len, x, skip;
+ char *extras[] = { "r8", "r16", "r24", "r32", "gsm", NULL };
int exlen = (sizeof(extras) / sizeof(extras[0]));
- buffer [0] = 0 ;
- sf_command (NULL, SFC_GET_LIB_VERSION, buffer, sizeof (buffer)) ;
- if (strlen (buffer) < 1) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Line %d: could not retrieve lib version.\n", __LINE__) ;
+ buffer[0] = 0;
+ sf_command(NULL, SFC_GET_LIB_VERSION, buffer, sizeof(buffer));
+ if (strlen(buffer) < 1) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "Line %d: could not retrieve lib version.\n", __LINE__);
return SWITCH_STATUS_FALSE;
}
- switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nLibSndFile Version : %s Supported Formats\n", buffer) ;
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "================================================================================\n");
- sf_command (NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof (int)) ;
- sf_command (NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof (int)) ;
-
- sfinfo.channels = 1 ;
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nLibSndFile Version : %s Supported Formats\n", buffer);
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN,
+ "================================================================================\n");
+ sf_command(NULL, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof(int));
+ sf_command(NULL, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof(int));
+
+ sfinfo.channels = 1;
len = ((major_count + (exlen + 2)) * sizeof(char *));
supported_formats = switch_core_permenant_alloc(len);
len = 0;
- for (m = 0 ; m < major_count ; m++) {
+ for (m = 0; m < major_count; m++) {
skip = 0;
- info.format = m ;
- sf_command (NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof (info)) ;
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "%s (extension \"%s\")\n", info.name, info.extension) ;
- for (x = 0 ; x < len ; x++) {
+ info.format = m;
+ sf_command(NULL, SFC_GET_FORMAT_MAJOR, &info, sizeof(info));
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "%s (extension \"%s\")\n", info.name, info.extension);
+ for (x = 0; x < len; x++) {
if (supported_formats[x] == info.extension) {
skip++;
break;
supported_formats[len++] = (char *) info.extension;
}
format = info.format;
-
- for (s = 0 ; s < subtype_count ; s++) {
- info.format = s ;
- sf_command (NULL, SFC_GET_FORMAT_SUBTYPE, &info, sizeof (info)) ;
- format = (format & SF_FORMAT_TYPEMASK) | info.format ;
- sfinfo.format = format ;
- if (sf_format_check (&sfinfo)) {
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, " %s\n", info.name) ;
+
+ for (s = 0; s < subtype_count; s++) {
+ info.format = s;
+ sf_command(NULL, SFC_GET_FORMAT_SUBTYPE, &info, sizeof(info));
+ format = (format & SF_FORMAT_TYPEMASK) | info.format;
+ sfinfo.format = format;
+ if (sf_format_check(&sfinfo)) {
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, " %s\n", info.name);
}
}
}
- for(m=0; m< exlen; m++) {
+ for (m = 0; m < exlen; m++) {
supported_formats[len++] = extras[m];
}
-
- switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "================================================================================\n");
+
+ switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN,
+ "================================================================================\n");
return SWITCH_STATUS_SUCCESS;
}
-SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename) {
+SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_interface **interface, char *filename)
+{
+
-
if (setup_formats() != SWITCH_STATUS_SUCCESS) {
return SWITCH_STATUS_FALSE;
}
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
-
#ifdef WINTIMER
private->base.QuadPart += timer->interval * (private->freq.QuadPart / 1000);
- for(;;) {
+ for (;;) {
QueryPerformanceCounter(&private->now);
- if(private->now.QuadPart >= private->base.QuadPart) {
+ if (private->now.QuadPart >= private->base.QuadPart) {
break;
}
switch_yield(100);
}
static const switch_timer_interface soft_timer_interface = {
- /*.interface_name*/ "soft",
- /*.timer_init*/ soft_timer_init,
- /*.timer_next*/ soft_timer_next,
- /*.timer_destroy*/ soft_timer_destroy
+ /*.interface_name */ "soft",
+ /*.timer_init */ soft_timer_init,
+ /*.timer_next */ soft_timer_next,
+ /*.timer_destroy */ soft_timer_destroy
};
static const switch_loadable_module_interface mod_timers_module_interface = {
- /*.module_name*/ modname,
- /*.endpoint_interface*/ NULL,
- /*.timer_interface*/ &soft_timer_interface,
- /*.switch_dialplan_interface*/ NULL,
- /*.switch_codec_interface*/ NULL,
- /*.switch_application_interface*/ NULL
+ /*.module_name */ modname,
+ /*.endpoint_interface */ NULL,
+ /*.timer_interface */ &soft_timer_interface,
+ /*.switch_dialplan_interface */ NULL,
+ /*.switch_codec_interface */ NULL,
+ /*.switch_application_interface */ NULL
};
-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_timers_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
-
-
-
-
-