提交 1e04eb13 authored 作者: Anthony Minessale's avatar Anthony Minessale

indent

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@417 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 42383b1f
......@@ -55,7 +55,7 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj)
session_a = data->objs[0];
session_b = data->objs[1];
stream_id_p = data->objs[2];
if (stream_id_p) {
stream_id = *stream_id_p;
......@@ -64,16 +64,16 @@ static void *audio_bridge_thread(switch_thread *thread, void *obj)
chan_a = switch_core_session_get_channel(session_a);
chan_b = switch_core_session_get_channel(session_b);
while(data->running > 0) {
while (data->running > 0) {
switch_channel_state b_state = switch_channel_get_state(chan_b);
switch (b_state) {
case CS_HANGUP:
data->running = -1;
continue;
break;
default:
break;
case CS_HANGUP:
data->running = -1;
continue;
break;
default:
break;
}
if (switch_channel_has_dtmf(chan_a)) {
......@@ -81,16 +81,17 @@ default:
switch_channel_dequeue_dtmf(chan_a, dtmf, sizeof(dtmf));
switch_core_session_send_dtmf(session_b, dtmf);
}
if (switch_core_session_read_frame(session_a, &read_frame, -1, 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;
}
}
}
......@@ -115,7 +116,8 @@ static switch_status audio_bridge_on_hangup(switch_core_session *session)
other_channel = switch_core_session_get_channel(other_session);
assert(other_channel != NULL);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "CUSTOM HANGUP %s kill %s\n", switch_channel_get_name(channel), switch_channel_get_name(other_channel));
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "CUSTOM HANGUP %s kill %s\n", switch_channel_get_name(channel),
switch_channel_get_name(other_channel));
switch_core_session_kill_channel(other_session, SWITCH_SIG_KILL);
switch_core_session_kill_channel(session, SWITCH_SIG_KILL);
......@@ -143,21 +145,21 @@ static switch_status audio_bridge_on_ring(switch_core_session *session)
}
static const switch_event_handler_table audio_bridge_peer_event_handlers = {
/*.on_init*/ NULL,
/*.on_ring*/ audio_bridge_on_ring,
/*.on_execute*/ NULL,
/*.on_hangup*/ audio_bridge_on_hangup,
/*.on_loopback*/ NULL,
/*.on_transmit*/ NULL
/*.on_init */ NULL,
/*.on_ring */ audio_bridge_on_ring,
/*.on_execute */ NULL,
/*.on_hangup */ audio_bridge_on_hangup,
/*.on_loopback */ NULL,
/*.on_transmit */ NULL
};
static const switch_event_handler_table audio_bridge_caller_event_handlers = {
/*.on_init*/ NULL,
/*.on_ring*/ NULL,
/*.on_execute*/ NULL,
/*.on_hangup*/ audio_bridge_on_hangup,
/*.on_loopback*/ NULL,
/*.on_transmit*/ NULL
/*.on_init */ NULL,
/*.on_ring */ NULL,
/*.on_execute */ NULL,
/*.on_hangup */ audio_bridge_on_hangup,
/*.on_loopback */ NULL,
/*.on_transmit */ NULL
};
static void audio_bridge_function(switch_core_session *session, char *data)
......@@ -165,8 +167,8 @@ static void audio_bridge_function(switch_core_session *session, char *data)
switch_channel *caller_channel, *peer_channel;
switch_core_session *peer_session;
switch_caller_profile *caller_profile, *caller_caller_profile;
char chan_type[128]= {'\0'}, *chan_data;
int timelimit = 60; /* probably a useful option to pass in when there's time */
char chan_type[128] = { '\0' }, *chan_data;
int timelimit = 60; /* probably a useful option to pass in when there's time */
caller_channel = switch_core_session_get_channel(session);
assert(caller_channel != NULL);
......@@ -180,17 +182,15 @@ static void audio_bridge_function(switch_core_session *session, char *data)
caller_caller_profile = switch_channel_get_caller_profile(caller_channel);
caller_profile = switch_caller_profile_new(session,
caller_caller_profile->dialplan,
caller_caller_profile->caller_id_name,
caller_caller_profile->caller_id_number,
caller_caller_profile->network_addr,
NULL,
NULL,
chan_data);
caller_caller_profile->dialplan,
caller_caller_profile->caller_id_name,
caller_caller_profile->caller_id_number,
caller_caller_profile->network_addr, NULL, NULL, chan_data);
if (switch_core_session_outgoing_channel(session, chan_type, caller_profile, &peer_session) != SWITCH_STATUS_SUCCESS) {
if (switch_core_session_outgoing_channel(session, chan_type, caller_profile, &peer_session) !=
SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "DOH!\n");
switch_channel_hangup(caller_channel);
return;
......@@ -215,11 +215,11 @@ static void audio_bridge_function(switch_core_session *session, char *data)
switch_channel_set_private(caller_channel, peer_session);
switch_channel_set_private(peer_channel, session);
switch_channel_set_event_handlers(caller_channel, &audio_bridge_caller_event_handlers);
switch_channel_set_event_handlers(caller_channel, &audio_bridge_caller_event_handlers);
switch_channel_set_event_handlers(peer_channel, &audio_bridge_peer_event_handlers);
switch_core_session_thread_launch(peer_session);
for(;;) {
for (;;) {
int state = switch_channel_get_state(peer_channel);
if (state > CS_RING) {
break;
......@@ -228,11 +228,10 @@ static void audio_bridge_function(switch_core_session *session, char *data)
}
time(&start);
while(switch_channel_get_state(caller_channel) == CS_EXECUTE &&
switch_channel_get_state(peer_channel) == CS_TRANSMIT &&
!switch_channel_test_flag(peer_channel, CF_ANSWERED) &&
((time(NULL) - start) < timelimit)) {
switch_yield(20000);
while (switch_channel_get_state(caller_channel) == CS_EXECUTE &&
switch_channel_get_state(peer_channel) == CS_TRANSMIT &&
!switch_channel_test_flag(peer_channel, CF_ANSWERED) && ((time(NULL) - start) < timelimit)) {
switch_yield(20000);
}
if (switch_channel_test_flag(peer_channel, CF_ANSWERED)) {
......@@ -259,21 +258,22 @@ static void audio_bridge_function(switch_core_session *session, char *data)
static const switch_application_interface bridge_application_interface = {
/*.interface_name*/ "bridge",
/*.application_function*/ audio_bridge_function
/*.interface_name */ "bridge",
/*.application_function */ audio_bridge_function
};
static const switch_loadable_module_interface mod_bridgecall_module_interface = {
/*.module_name = */ modname,
/*.endpoint_interface = */ NULL,
/*.timer_interface = */ NULL,
/*.dialplan_interface = */ NULL,
/*.codec_interface = */ NULL,
/*.application_interface*/ &bridge_application_interface
/*.module_name = */ modname,
/*.endpoint_interface = */ NULL,
/*.timer_interface = */ NULL,
/*.dialplan_interface = */ NULL,
/*.codec_interface = */ NULL,
/*.application_interface */ &bridge_application_interface
};
SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) {
SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*interface = &mod_bridgecall_module_interface;
......
......@@ -59,11 +59,11 @@ void playback_function(switch_core_session *session, char *data)
assert(channel != NULL);
if (switch_core_file_open(&fh,
data,
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel);
return;
data,
SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_channel_hangup(channel);
return;
}
switch_channel_answer(channel);
......@@ -81,17 +81,17 @@ void playback_function(switch_core_session *session, char *data)
codec_name = "L16";
if (switch_core_codec_init(&codec,
codec_name,
fh.samplerate,
interval,
fh.channels,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL,
pool) == SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n");
write_frame.codec = &codec;
codec_name,
fh.samplerate,
interval,
fh.channels,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL, pool) == SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activated\n");
write_frame.codec = &codec;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activation Failed %s@%dhz %d channels %dms\n", codec_name, fh.samplerate, fh.channels, interval);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Raw Codec Activation Failed %s@%dhz %d channels %dms\n",
codec_name, fh.samplerate, fh.channels, interval);
switch_core_file_close(&fh);
switch_channel_hangup(channel);
return;
......@@ -108,11 +108,11 @@ void playback_function(switch_core_session *session, char *data)
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "setup timer success %d bytes per %d ms!\n", len, interval);
/* start a thread to absorb incoming audio */
for(stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
switch_core_service_session(session, &thread_session, stream_id);
}
ilen = samples;
while(switch_channel_get_state(channel) == CS_EXECUTE) {
while (switch_channel_get_state(channel) == CS_EXECUTE) {
int done = 0;
if (switch_channel_has_dtmf(channel)) {
......@@ -139,12 +139,12 @@ void playback_function(switch_core_session *session, char *data)
}
write_frame.datalen = ilen * 2;
write_frame.samples = (int)ilen;
write_frame.samples = (int) ilen;
#ifdef SWAP_LINEAR
switch_swap_linear(write_frame.data, (int)write_frame.datalen / 2);
switch_swap_linear(write_frame.data, (int) write_frame.datalen / 2);
#endif
for(stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
for (stream_id = 0; stream_id < switch_core_session_get_stream_count(session); stream_id++) {
if (switch_core_session_write_frame(session, &write_frame, -1, stream_id) != SWITCH_STATUS_SUCCESS) {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Bad Write\n");
done = 1;
......@@ -178,20 +178,21 @@ void playback_function(switch_core_session *session, char *data)
}
static const switch_application_interface playback_application_interface = {
/*.interface_name*/ "playback",
/*.application_function*/ playback_function
/*.interface_name */ "playback",
/*.application_function */ playback_function
};
static const switch_loadable_module_interface mod_playback_module_interface = {
/*.module_name = */ modname,
/*.endpoint_interface = */ NULL,
/*.timer_interface = */ NULL,
/*.dialplan_interface = */ NULL,
/*.codec_interface = */ NULL,
/*.application_interface*/ &playback_application_interface
/*.module_name = */ modname,
/*.endpoint_interface = */ NULL,
/*.timer_interface = */ NULL,
/*.dialplan_interface = */ NULL,
/*.codec_interface = */ NULL,
/*.application_interface */ &playback_application_interface
};
SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename) {
SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_module_interface **interface, char *filename)
{
/* connect my internal structure to the blank pointer passed to me */
*interface = &mod_playback_module_interface;
......@@ -207,7 +208,3 @@ if it returns anything but SWITCH_STATUS_TERM it will be called again automaticl
//switch_status switch_module_runtime(void)
......@@ -34,15 +34,16 @@
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;
......@@ -51,4 +52,3 @@ switch_status switch_module_load(switch_loadable_module_interface **interface, c
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
......@@ -47,70 +47,71 @@
*/
#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);
}
/*
......@@ -132,66 +133,63 @@ static short search(
* 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. */
......@@ -226,39 +224,38 @@ alaw2linear(
* 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);
}
}
/*
......@@ -270,43 +267,35 @@ linear2ulaw(
* 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 ----------------------------------------------------- */
......@@ -36,7 +36,8 @@
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;
......@@ -57,9 +58,7 @@ static switch_status switch_g711u_encode(switch_codec *codec,
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;
......@@ -83,9 +82,7 @@ static switch_status switch_g711u_decode(switch_codec *codec,
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;
......@@ -114,7 +111,8 @@ static switch_status switch_g711u_destroy(switch_codec *codec)
}
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;
......@@ -135,9 +133,7 @@ static switch_status switch_g711a_encode(switch_codec *codec,
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;
......@@ -161,9 +157,7 @@ static switch_status switch_g711a_decode(switch_codec *codec,
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;
......@@ -195,126 +189,122 @@ static switch_status switch_g711a_destroy(switch_codec *codec)
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;
}
......@@ -28,176 +28,142 @@
*
* mod_codec_g729.c -- G729 Codec Module
*
*/
*/
#include "switch.h"
#include "g729.h"
static const char modname[] = "mod_codec_g729";
struct g729_context {
struct dec_state decoder_object;
struct cod_state encoder_object;
};
static switch_status switch_g729_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings)
{
struct g729_context *context = NULL;
int encoding, decoding;
encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct g729_context))))) {
return SWITCH_STATUS_FALSE;
} else {
if (encoding) {
g729_init_coder(&context->encoder_object, 0);
}
if (decoding) {
g729_init_decoder(&context->decoder_object);
}
codec->private = context;
return SWITCH_STATUS_SUCCESS;
}
}
static switch_status switch_g729_destroy(switch_codec *codec)
{
codec->private = NULL;
return SWITCH_STATUS_SUCCESS;
}
static switch_status switch_g729_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)
{
struct g729_context *context = codec->private;
int cbret = 0;
if (!context) {
return SWITCH_STATUS_FALSE;
}
if (decoded_data_len % 160 == 0) {
unsigned int new_len = 0;
INT16 *ddp = decoded_data;
char *edp = encoded_data;
int x;
int loops = (int) decoded_data_len / 160;
for(x = 0; x < loops && new_len < *encoded_data_len; x++) {
g729_coder(&context->encoder_object, ddp, edp, &cbret);
edp += 10;
ddp += 80;
new_len += 10;
}
if( new_len <= *encoded_data_len ) {
*encoded_data_len = new_len;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len);
return SWITCH_STATUS_FALSE;
}
}
return SWITCH_STATUS_SUCCESS;
}
static switch_status switch_g729_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)
{
struct g729_context *context = codec->private;
if (!context) {
return SWITCH_STATUS_FALSE;
}
if (encoded_data_len % 10 == 0) {
int loops = (int) encoded_data_len / 10;
char *edp = encoded_data;
short *ddp = decoded_data;
int x;
unsigned int new_len = 0;
for(x = 0; x < loops && new_len < *decoded_data_len; x++) {
g729_decoder(&context->decoder_object, ddp, edp, 10);
ddp += 80;
edp += 10;
new_len += 160;
}
if (new_len <= *decoded_data_len) {
*decoded_data_len = new_len;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!!\n");
return SWITCH_STATUS_FALSE;
}
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len);
}
return SWITCH_STATUS_SUCCESS;
}
/* Registration */
static const switch_codec_implementation g729_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*/ 20,
/*.number_of_channels*/ 1,
/*.pref_frames_per_packet*/ 1,
/*.max_frames_per_packet*/ 24,
/*.init*/ switch_g729_init,
/*.encode*/ switch_g729_encode,
/*.decode*/ switch_g729_decode,
/*.destroy*/ switch_g729_destroy,
};
static const switch_codec_interface g729_codec_interface = {
/*.interface_name*/ "g729",
/*.codec_type*/ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode*/ 18,
/*.iananame*/ "G729",
/*.implementations*/ &g729_8k_implementation,
};
static switch_loadable_module_interface g729_module_interface = {
/*.module_name*/ modname,
/*.endpoint_interface*/ NULL,
/*.timer_interface*/ NULL,
/*.dialplan_interface*/ NULL,
/*.codec_interface*/ &g729_codec_interface,
/*.application_interface*/ NULL
};
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 = &g729_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
static const char modname[] = "mod_codec_g729";
struct g729_context {
struct dec_state decoder_object;
struct cod_state encoder_object;
};
static switch_status switch_g729_init(switch_codec *codec, switch_codec_flag flags,
const struct switch_codec_settings *codec_settings)
{
struct g729_context *context = NULL;
int encoding, decoding;
encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
if (!(encoding || decoding) || (!(context = switch_core_alloc(codec->memory_pool, sizeof(struct g729_context))))) {
return SWITCH_STATUS_FALSE;
} else {
if (encoding) {
g729_init_coder(&context->encoder_object, 0);
}
if (decoding) {
g729_init_decoder(&context->decoder_object);
}
codec->private = context;
return SWITCH_STATUS_SUCCESS;
}
}
static switch_status switch_g729_destroy(switch_codec *codec)
{
codec->private = NULL;
return SWITCH_STATUS_SUCCESS;
}
static switch_status switch_g729_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)
{
struct g729_context *context = codec->private;
int cbret = 0;
if (!context) {
return SWITCH_STATUS_FALSE;
}
if (decoded_data_len % 160 == 0) {
unsigned int new_len = 0;
INT16 * ddp = decoded_data;
char *edp = encoded_data;
int x;
int loops = (int) decoded_data_len / 160;
for (x = 0; x < loops && new_len < *encoded_data_len; x++) {
g729_coder(&context->encoder_object, ddp, edp, &cbret);
edp += 10;
ddp += 80;
new_len += 10;
}
if (new_len <= *encoded_data_len) {
*encoded_data_len = new_len;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len);
return SWITCH_STATUS_FALSE;
}
}
return SWITCH_STATUS_SUCCESS;
}
static switch_status switch_g729_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)
{
struct g729_context *context = codec->private;
if (!context) {
return SWITCH_STATUS_FALSE;
}
if (encoded_data_len % 10 == 0) {
int loops = (int) encoded_data_len / 10;
char *edp = encoded_data;
short *ddp = decoded_data;
int x;
unsigned int new_len = 0;
for (x = 0; x < loops && new_len < *decoded_data_len; x++) {
g729_decoder(&context->decoder_object, ddp, edp, 10);
ddp += 80;
edp += 10;
new_len += 160;
}
if (new_len <= *decoded_data_len) {
*decoded_data_len = new_len;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!!\n");
return SWITCH_STATUS_FALSE;
}
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len);
}
return SWITCH_STATUS_SUCCESS;
}
/* Registration */
static const switch_codec_implementation g729_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 */ 20,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 24,
/*.init */ switch_g729_init,
/*.encode */ switch_g729_encode,
/*.decode */ switch_g729_decode,
/*.destroy */ switch_g729_destroy,
};
static const switch_codec_interface g729_codec_interface = {
/*.interface_name */ "g729",
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 18,
/*.iananame */ "G729",
/*.implementations */ &g729_8k_implementation,
};
static switch_loadable_module_interface g729_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &g729_codec_interface,
/*.application_interface */ NULL
};
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 = &g729_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
......
......@@ -28,180 +28,148 @@
*
* mod_codec_gsm.c -- gsm Codec Module
*
*/
*/
#include "switch.h"
#include "gsm.h"
static const char modname[] = "mod_codec_gsm";
struct gsm_context {
gsm encoder;
gsm decoder;
};
static switch_status switch_gsm_init(switch_codec *codec, switch_codec_flag flags, const struct switch_codec_settings *codec_settings)
{
struct gsm_context *context;
int encoding, decoding;
encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
if (!(encoding || decoding)) {
return SWITCH_STATUS_FALSE;
} else {
context = switch_core_alloc(codec->memory_pool, sizeof(*context));
if (encoding) context->encoder = gsm_create();
if (decoding) context->decoder = gsm_create();
}
codec->private = context;
return SWITCH_STATUS_SUCCESS;
}
static switch_status switch_gsm_destroy(switch_codec *codec)
{
struct gsm_context *context = codec->private;
int encoding = (codec->flags & SWITCH_CODEC_FLAG_ENCODE);
int decoding = (codec->flags & SWITCH_CODEC_FLAG_DECODE);
if (encoding) gsm_destroy(context->encoder);
if (decoding) gsm_destroy(context->decoder);
codec->private = NULL;
return SWITCH_STATUS_SUCCESS;
}
static switch_status switch_gsm_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)
{
struct gsm_context *context = codec->private;
int cbret = 0;
if (!context) {
return SWITCH_STATUS_FALSE;
}
if (decoded_data_len % 320 == 0) {
unsigned int new_len = 0;
gsm_signal *ddp = decoded_data;
gsm_byte *edp = encoded_data;
int x;
int loops = (int) decoded_data_len / 320;
for(x = 0; x < loops && new_len < *encoded_data_len; x++) {
gsm_encode(context->encoder, ddp, edp);
edp += 33;
ddp += 160;
new_len += 33;
}
if( new_len <= *encoded_data_len ) {
*encoded_data_len = new_len;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len);
return SWITCH_STATUS_FALSE;
}
}
return SWITCH_STATUS_SUCCESS;
}
static switch_status switch_gsm_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)
{
struct gsm_context *context = codec->private;
if (!context) {
return SWITCH_STATUS_FALSE;
}
if (encoded_data_len % 33 == 0) {
int loops = (int) encoded_data_len / 33;
gsm_byte *edp = encoded_data;
gsm_signal *ddp = decoded_data;
int x;
unsigned int new_len = 0;
for(x = 0; x < loops && new_len < *decoded_data_len; x++) {
gsm_decode(context->decoder, edp, ddp);
ddp += 160;
edp += 33;
new_len += 320;
}
if (new_len <= *decoded_data_len) {
*decoded_data_len = new_len;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!!\n");
return SWITCH_STATUS_FALSE;
}
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len);
}
return SWITCH_STATUS_SUCCESS;
}
/* Registration */
static const switch_codec_implementation gsm_8k_implementation = {
/*.samples_per_second*/ 8000,
/*.bits_per_second*/ 13200,
/*.microseconds_per_frame*/ 20000,
/*.samples_per_frame*/ 160,
/*.bytes_per_frame*/ 320,
/*.encoded_bytes_per_frame*/ 33,
/*.number_of_channels*/ 1,
/*.pref_frames_per_packet*/ 1,
/*.max_frames_per_packet*/ 1,
/*.init*/ switch_gsm_init,
/*.encode*/ switch_gsm_encode,
/*.decode*/ switch_gsm_decode,
/*.destroy*/ switch_gsm_destroy,
};
static const switch_codec_interface gsm_codec_interface = {
/*.interface_name*/ "gsm",
/*.codec_type*/ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode*/ 3,
/*.iananame*/ "gsm",
/*.implementations*/ &gsm_8k_implementation,
};
static switch_loadable_module_interface gsm_module_interface = {
/*.module_name*/ modname,
/*.endpoint_interface*/ NULL,
/*.timer_interface*/ NULL,
/*.dialplan_interface*/ NULL,
/*.codec_interface*/ &gsm_codec_interface,
/*.application_interface*/ NULL
};
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 = &gsm_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
static const char modname[] = "mod_codec_gsm";
struct gsm_context {
gsm encoder;
gsm decoder;
};
static switch_status switch_gsm_init(switch_codec *codec, switch_codec_flag flags,
const struct switch_codec_settings *codec_settings)
{
struct gsm_context *context;
int encoding, decoding;
encoding = (flags & SWITCH_CODEC_FLAG_ENCODE);
decoding = (flags & SWITCH_CODEC_FLAG_DECODE);
if (!(encoding || decoding)) {
return SWITCH_STATUS_FALSE;
} else {
context = switch_core_alloc(codec->memory_pool, sizeof(*context));
if (encoding)
context->encoder = gsm_create();
if (decoding)
context->decoder = gsm_create();
}
codec->private = context;
return SWITCH_STATUS_SUCCESS;
}
static switch_status switch_gsm_destroy(switch_codec *codec)
{
struct gsm_context *context = codec->private;
int encoding = (codec->flags & SWITCH_CODEC_FLAG_ENCODE);
int decoding = (codec->flags & SWITCH_CODEC_FLAG_DECODE);
if (encoding)
gsm_destroy(context->encoder);
if (decoding)
gsm_destroy(context->decoder);
codec->private = NULL;
return SWITCH_STATUS_SUCCESS;
}
static switch_status switch_gsm_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)
{
struct gsm_context *context = codec->private;
int cbret = 0;
if (!context) {
return SWITCH_STATUS_FALSE;
}
if (decoded_data_len % 320 == 0) {
unsigned int new_len = 0;
gsm_signal * ddp = decoded_data;
gsm_byte * edp = encoded_data;
int x;
int loops = (int) decoded_data_len / 320;
for (x = 0; x < loops && new_len < *encoded_data_len; x++) {
gsm_encode(context->encoder, ddp, edp);
edp += 33;
ddp += 160;
new_len += 33;
}
if (new_len <= *encoded_data_len) {
*encoded_data_len = new_len;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!! %u >= %u\n", new_len, *encoded_data_len);
return SWITCH_STATUS_FALSE;
}
}
return SWITCH_STATUS_SUCCESS;
}
static switch_status switch_gsm_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)
{
struct gsm_context *context = codec->private;
if (!context) {
return SWITCH_STATUS_FALSE;
}
if (encoded_data_len % 33 == 0) {
int loops = (int) encoded_data_len / 33;
gsm_byte * edp = encoded_data;
gsm_signal * ddp = decoded_data;
int x;
unsigned int new_len = 0;
for (x = 0; x < loops && new_len < *decoded_data_len; x++) {
gsm_decode(context->decoder, edp, ddp);
ddp += 160;
edp += 33;
new_len += 320;
}
if (new_len <= *decoded_data_len) {
*decoded_data_len = new_len;
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "buffer overflow!!!\n");
return SWITCH_STATUS_FALSE;
}
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len);
}
return SWITCH_STATUS_SUCCESS;
}
/* Registration */
static const switch_codec_implementation gsm_8k_implementation = {
/*.samples_per_second */ 8000,
/*.bits_per_second */ 13200,
/*.microseconds_per_frame */ 20000,
/*.samples_per_frame */ 160,
/*.bytes_per_frame */ 320,
/*.encoded_bytes_per_frame */ 33,
/*.number_of_channels */ 1,
/*.pref_frames_per_packet */ 1,
/*.max_frames_per_packet */ 1,
/*.init */ switch_gsm_init,
/*.encode */ switch_gsm_encode,
/*.decode */ switch_gsm_decode,
/*.destroy */ switch_gsm_destroy,
};
static const switch_codec_interface gsm_codec_interface = {
/*.interface_name */ "gsm",
/*.codec_type */ SWITCH_CODEC_TYPE_AUDIO,
/*.ianacode */ 3,
/*.iananame */ "gsm",
/*.implementations */ &gsm_8k_implementation,
};
static switch_loadable_module_interface gsm_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
/*.timer_interface */ NULL,
/*.dialplan_interface */ NULL,
/*.codec_interface */ &gsm_codec_interface,
/*.application_interface */ NULL
};
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 = &gsm_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
......
......@@ -35,7 +35,8 @@
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;
......@@ -51,17 +52,15 @@ static switch_status switch_raw_init(switch_codec *codec, switch_codec_flag flag
}
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;
......@@ -71,14 +70,12 @@ static switch_status switch_raw_encode(switch_codec *codec,
}
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);
......@@ -91,12 +88,12 @@ static switch_status switch_raw_decode(switch_codec *codec,
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,
......@@ -164,52 +161,48 @@ static const switch_codec_implementation raw_8k_implementation = {
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;
}
......@@ -52,7 +52,8 @@ switch_caller_extension *demo_dialplan_hunt(switch_core_session *session)
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);
......@@ -76,14 +77,17 @@ switch_caller_extension *demo_dialplan_hunt(switch_core_session *session)
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);
}
}
}
}
......@@ -100,9 +104,9 @@ switch_caller_extension *demo_dialplan_hunt(switch_core_session *session)
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 = {
......@@ -111,10 +115,11 @@ 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;
......
......@@ -60,7 +60,8 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session)
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);
......@@ -69,24 +70,23 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session)
}
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();
......@@ -94,31 +94,31 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session)
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++;
}
......@@ -126,9 +126,11 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session)
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];
}
}
......@@ -150,9 +152,11 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session)
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;
}
......@@ -162,7 +166,7 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session)
}
}
}
switch_config_close_file(&cfg);
if (extension) {
......@@ -177,9 +181,9 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session)
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 = {
......@@ -188,10 +192,11 @@ 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;
......
......@@ -33,11 +33,11 @@
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;
......@@ -50,12 +50,12 @@ static void event_handler (switch_event *event)
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"
......@@ -76,9 +76,9 @@ static void *torture_thread(switch_thread *thread, void *obj)
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);
......@@ -104,7 +104,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
#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;
......@@ -112,16 +113,16 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_inte
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);
}
}
......@@ -130,4 +131,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(switch_loadable_module_inte
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}
......@@ -71,9 +71,9 @@ static switch_status soft_timer_next(switch_timer *timer)
#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);
......@@ -98,31 +98,27 @@ static switch_status soft_timer_destroy(switch_timer *timer)
}
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;
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论