git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@417 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-01-20 00:41:30 +00:00
parent 42383b1f15
commit 1e04eb13b5
25 changed files with 3123 additions and 3130 deletions

View File

@ -82,7 +82,8 @@ default:
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;
@ -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);
@ -183,14 +185,12 @@ static void audio_bridge_function(switch_core_session *session, char *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);
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;
@ -230,8 +230,7 @@ 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_channel_test_flag(peer_channel, CF_ANSWERED) && ((time(NULL) - start) < timelimit)) {
switch_yield(20000);
}
@ -273,7 +272,8 @@ static const switch_loadable_module_interface mod_bridgecall_module_interface =
/*.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;

View File

@ -86,12 +86,12 @@ void playback_function(switch_core_session *session, char *data)
interval,
fh.channels,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL,
pool) == SWITCH_STATUS_SUCCESS) {
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;
@ -191,7 +191,8 @@ static const switch_loadable_module_interface mod_playback_module_interface = {
/*.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)

View File

@ -42,7 +42,8 @@ static switch_loadable_module_interface skel_module_interface = {
/*.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;
}

View File

@ -52,9 +52,11 @@
#define SEG_MASK (0x70) /* Segment field mask. */
static short seg_aend[8] = { 0x1F, 0x3F, 0x7F, 0xFF,
0x1FF, 0x3FF, 0x7FF, 0xFFF};
0x1FF, 0x3FF, 0x7FF, 0xFFF
};
static short seg_uend[8] = { 0x3F, 0x7F, 0xFF, 0x1FF,
0x3FF, 0x7FF, 0xFFF, 0x1FFF};
0x3FF, 0x7FF, 0xFFF, 0x1FFF
};
/* copy from CCITT G.711 specifications */
unsigned char _u2a[128] = { /* u- to A-law conversions */
@ -76,7 +78,8 @@ unsigned char _u2a[128] = { /* u- to A-law conversions */
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};
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,
@ -97,12 +100,10 @@ unsigned char _a2u[128] = { /* A- to u-law conversions */
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};
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;
@ -132,9 +133,8 @@ 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) */
{
unsigned char linear2alaw(short pcm_val)
{ /* 2's complement (16-bit range) */
short mask;
short seg;
unsigned char aval;
@ -169,9 +169,7 @@ linear2alaw(short pcm_val) /* 2's complement (16-bit range) */
* 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;
@ -226,10 +224,8 @@ 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) */
{
unsigned char linear2ulaw(short pcm_val)
{ /* 2's complement (16-bit range) */
short mask;
short seg;
unsigned char uval;
@ -242,7 +238,8 @@ linear2ulaw(
} else {
mask = 0xFF;
}
if ( pcm_val > CLIP ) pcm_val = CLIP; /* clip the magnitude */
if (pcm_val > CLIP)
pcm_val = CLIP; /* clip the magnitude */
pcm_val += (BIAS >> 2);
/* Convert the scaled magnitude to segment number. */
@ -270,9 +267,7 @@ 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;
@ -290,23 +285,17 @@ ulaw2linear(
}
/* 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]));
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)));
return (unsigned char) ((uval & 0x80) ? (0xD5 ^ (_u2a[0xFF ^ uval] - 1)) : (0x55 ^ (_u2a[0x7F ^ uval] - 1)));
}
/* ---------- end of g711.c ----------------------------------------------------- */

View File

@ -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;
@ -306,15 +300,11 @@ static switch_loadable_module_interface g711_module_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 = &g711_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}

View File

@ -31,22 +31,18 @@
*/
#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)
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 {
@ -56,33 +52,21 @@ static switch_status switch_g729_init(switch_codec *codec, switch_codec_flag fla
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)
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;
}
@ -92,7 +76,6 @@ static switch_status switch_g729_encode(switch_codec *codec,
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;
@ -108,25 +91,14 @@ static switch_status switch_g729_encode(switch_codec *codec,
}
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)
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;
@ -148,13 +120,11 @@ static switch_status switch_g729_decode(switch_codec *codec,
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len);
}
return SWITCH_STATUS_SUCCESS;
}
/* Registration */
/* Registration */
static const switch_codec_implementation g729_8k_implementation = {
/*.samples_per_second */ 8000,
/*.bits_per_second */ 64000,
@ -170,7 +140,6 @@ static const switch_codec_implementation g729_8k_implementation = {
/*.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,
@ -178,7 +147,6 @@ static const switch_codec_interface g729_codec_interface = {
/*.iananame */ "G729",
/*.implementations */ &g729_8k_implementation,
};
static switch_loadable_module_interface g729_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
@ -187,9 +155,10 @@ static switch_loadable_module_interface g729_module_interface = {
/*.codec_interface */ &g729_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 = &g729_module_interface;
@ -198,6 +167,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul
}

View File

@ -31,63 +31,48 @@
*/
#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)
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();
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);
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)
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;
}
@ -110,28 +95,16 @@ static switch_status switch_gsm_encode(switch_codec *codec,
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)
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;
@ -153,12 +126,11 @@ static switch_status switch_gsm_decode(switch_codec *codec,
} else {
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "yo this frame is an odd size [%d]\n", encoded_data_len);
}
return SWITCH_STATUS_SUCCESS;
}
/* Registration */
/* Registration */
static const switch_codec_implementation gsm_8k_implementation = {
/*.samples_per_second */ 8000,
/*.bits_per_second */ 13200,
@ -174,7 +146,6 @@ static const switch_codec_implementation gsm_8k_implementation = {
/*.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,
@ -182,7 +153,6 @@ static const switch_codec_interface gsm_codec_interface = {
/*.iananame */ "gsm",
/*.implementations */ &gsm_8k_implementation,
};
static switch_loadable_module_interface gsm_module_interface = {
/*.module_name */ modname,
/*.endpoint_interface */ NULL,
@ -191,9 +161,10 @@ static switch_loadable_module_interface gsm_module_interface = {
/*.codec_interface */ &gsm_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 = &gsm_module_interface;
@ -202,6 +173,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul
}

View File

@ -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;
@ -56,9 +57,7 @@ static switch_status switch_raw_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)
{
/* NOOP indicates that the audio in is already the same as the audio out, so no conversion was necessary. */
@ -76,9 +75,7 @@ static switch_status switch_raw_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)
{
if (codec->implementation->samples_per_second != other_codec->implementation->samples_per_second) {
memcpy(decoded_data, encoded_data, encoded_data_len);
@ -201,15 +198,11 @@ static switch_loadable_module_interface raw_module_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 = &raw_module_interface;
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}

View File

@ -72,7 +72,8 @@ 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;
@ -110,14 +111,17 @@ static switch_status switch_speex_init(switch_codec *codec, switch_codec_flag fl
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) {
@ -159,9 +163,7 @@ static switch_status switch_speex_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)
{
struct speex_context *context = codec->private;
short *buf;
@ -178,7 +180,8 @@ static switch_status switch_speex_encode(switch_codec *codec,
}
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);
}
@ -215,9 +218,7 @@ static switch_status switch_speex_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)
{
struct speex_context *context = codec->private;
short *buf;
@ -333,7 +334,8 @@ static switch_loadable_module_interface speex_module_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;

View File

@ -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,7 +77,10 @@ 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;
}
@ -114,7 +118,8 @@ static const switch_loadable_module_interface demo_dialplan_module_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 = &demo_dialplan_module_interface;

View File

@ -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);
@ -81,8 +82,7 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session)
int erroffset = 0;
cleanre();
re = pcre_compile(
val, /* the pattern */
re = pcre_compile(val, /* the pattern */
0, /* default options */
&error, /* for error message */
&erroffset, /* for error offset */
@ -94,8 +94,7 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session)
return NULL;
}
match_count = pcre_exec(
re, /* result of pcre_compile() */
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 */
@ -105,7 +104,8 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session)
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] = "";
@ -126,7 +126,9 @@ 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++) {
newval[y++] = replace[r];
@ -152,7 +154,9 @@ switch_caller_extension *dialplan_hunt(switch_core_session *session)
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;
}
@ -191,7 +195,8 @@ static const switch_loadable_module_interface dialplan_module_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 = &dialplan_module_interface;

View File

@ -144,9 +144,12 @@ static switch_status exosip_on_init(switch_core_session *session);
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 exosip_kill_channel(switch_core_session *session, int sig);
@ -245,14 +248,17 @@ static switch_status exosip_on_init(switch_core_session *session)
/* 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++) {
@ -262,10 +268,12 @@ static switch_status exosip_on_init(switch_core_session *session)
sdp_message_m_payload_add(tech_pvt->local_sdp, 0, osip_strdup(tmp));
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));
}
@ -273,7 +281,9 @@ static switch_status exosip_on_init(switch_core_session *session)
}
/* 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);
}
@ -346,7 +356,8 @@ static switch_status exosip_on_hangup(switch_core_session *session)
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;
}
@ -362,14 +373,16 @@ static switch_status exosip_on_transmit(switch_core_session *session)
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);
@ -457,22 +470,17 @@ static void activate_rtp(struct private_object *tech_pvt)
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 = jrtp4c_new(
tech_pvt->local_sdp_audio_ip,
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->read_codec.implementation->samples_per_second, &err);
if (tech_pvt->rtp_session) {
tech_pvt->ssrc = jrtp4c_get_ssrc(tech_pvt->rtp_session);
@ -521,7 +529,8 @@ static switch_status exosip_answer_channel(switch_core_session *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_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;
@ -553,10 +562,10 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram
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;
@ -598,7 +607,8 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram
}
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;
@ -747,7 +757,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
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) {
@ -798,9 +809,7 @@ static switch_status exosip_create_call(eXosip_event_t *event)
event->request->from->displayname,
event->request->from->url->username,
event->request->from->url->host,
NULL,
NULL,
event->request->req_uri->username))) {
NULL, NULL, event->request->req_uri->username))) {
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
}
@ -824,14 +833,17 @@ static switch_status exosip_create_call(eXosip_event_t *event)
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++);
sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame,
imp->samples_per_second, x++);
}
}
}
@ -850,7 +862,8 @@ static switch_status exosip_create_call(eXosip_event_t *event)
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);
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;
@ -859,7 +872,8 @@ static switch_status exosip_create_call(eXosip_event_t *event)
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);
@ -892,8 +906,7 @@ static switch_status exosip_create_call(eXosip_event_t *event)
globals.codec_ms,
1,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
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;
@ -904,8 +917,7 @@ static switch_status exosip_create_call(eXosip_event_t *event)
globals.codec_ms,
1,
SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE,
NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
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;
@ -914,7 +926,8 @@ static switch_status exosip_create_call(eXosip_event_t *event)
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);
@ -945,7 +958,8 @@ static void destroy_call_by_event(eXosip_event_t *event)
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;
}
@ -987,7 +1001,8 @@ static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **dr
*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;
@ -1057,8 +1072,7 @@ static void handle_answer(eXosip_event_t *event)
globals.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");
switch_channel_hangup(channel);
return;
@ -1118,8 +1132,7 @@ static void log_event(eXosip_event_t *je)
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)) {
} else if (je->type == EXOSIP_MESSAGE_NEW && je->request != NULL && MSG_IS_MESSAGE(je->request)) {
char *tmp = NULL;
if (je->request != NULL) {
@ -1128,8 +1141,7 @@ static void log_event(eXosip_event_t *je)
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);
} else {
@ -1139,26 +1151,22 @@ static void log_event(eXosip_event_t *je)
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);
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_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);
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);
}
@ -1166,8 +1174,7 @@ static void log_event(eXosip_event_t *je)
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);
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;
@ -1181,46 +1188,40 @@ static void log_event(eXosip_event_t *je)
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);
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);
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);
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);
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);
je->cid, je->did, je->sid, je->nid, je->request->sip_method, tmp);
osip_free(tmp);
} else if (je->response != NULL) {
char *tmp = NULL;
@ -1228,8 +1229,7 @@ static void log_event(eXosip_event_t *je)
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);
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",
@ -1403,4 +1403,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
return SWITCH_STATUS_TERM;
}

View File

@ -145,9 +145,12 @@ static switch_status exosip_on_init(switch_core_session *session);
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 exosip_kill_channel(switch_core_session *session, int sig);
@ -245,14 +248,17 @@ static switch_status exosip_on_init(switch_core_session *session)
/* 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++) {
@ -262,10 +268,12 @@ static switch_status exosip_on_init(switch_core_session *session)
sdp_message_m_payload_add(tech_pvt->local_sdp, 0, osip_strdup(tmp));
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));
}
@ -273,7 +281,9 @@ static switch_status exosip_on_init(switch_core_session *session)
}
/* 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);
}
@ -346,7 +356,8 @@ static switch_status exosip_on_hangup(switch_core_session *session)
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;
}
@ -362,7 +373,8 @@ static switch_status exosip_on_transmit(switch_core_session *session)
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;
@ -370,7 +382,8 @@ static switch_status exosip_outgoing_channel(switch_core_session *session, switc
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);
@ -457,22 +470,16 @@ static void activate_rtp(struct private_object *tech_pvt)
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);
@ -517,7 +524,8 @@ static switch_status exosip_answer_channel(switch_core_session *session)
}
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;
@ -547,11 +555,10 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram
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) {
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),
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);
@ -587,7 +594,8 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram
}
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;
@ -739,7 +747,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
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) {
@ -790,8 +799,7 @@ static switch_status exosip_create_call(eXosip_event_t *event)
event->request->from->displayname,
event->request->from->url->username,
event->request->from->url->username,
NULL,
event->request->req_uri->username))) {
NULL, event->request->req_uri->username))) {
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
}
@ -815,14 +823,17 @@ static switch_status exosip_create_call(eXosip_event_t *event)
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++);
sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame,
imp->samples_per_second, x++);
}
}
}
@ -841,7 +852,8 @@ static switch_status exosip_create_call(eXosip_event_t *event)
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);
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;
@ -850,7 +862,8 @@ static switch_status exosip_create_call(eXosip_event_t *event)
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);
@ -900,7 +913,8 @@ static switch_status exosip_create_call(eXosip_event_t *event)
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);
@ -926,7 +940,8 @@ static void destroy_call_by_event(eXosip_event_t *event)
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;
}
@ -968,7 +983,8 @@ static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **dr
*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;
@ -1032,12 +1048,16 @@ static void handle_answer(eXosip_event_t *event)
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;
@ -1083,8 +1103,7 @@ static void log_event(eXosip_event_t *je)
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)) {
} else if (je->type == EXOSIP_MESSAGE_NEW && je->request != NULL && MSG_IS_MESSAGE(je->request)) {
char *tmp = NULL;
if (je->request != NULL) {
@ -1093,8 +1112,7 @@ static void log_event(eXosip_event_t *je)
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);
} else {
@ -1104,26 +1122,22 @@ static void log_event(eXosip_event_t *je)
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);
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_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);
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);
}
@ -1131,8 +1145,7 @@ static void log_event(eXosip_event_t *je)
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);
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;
@ -1146,46 +1159,40 @@ static void log_event(eXosip_event_t *je)
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);
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);
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);
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);
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);
je->cid, je->did, je->sid, je->nid, je->request->sip_method, tmp);
osip_free(tmp);
} else if (je->response != NULL) {
char *tmp = NULL;
@ -1193,8 +1200,7 @@ static void log_event(eXosip_event_t *je)
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);
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",
@ -1371,4 +1377,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
config_exosip(0);
return SWITCH_STATUS_TERM;
}

View File

@ -160,9 +160,12 @@ static switch_status exosip_on_init(switch_core_session *session);
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 exosip_kill_channel(switch_core_session *session, int sig);
@ -260,14 +263,17 @@ static switch_status exosip_on_init(switch_core_session *session)
/* 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++) {
@ -277,10 +283,12 @@ static switch_status exosip_on_init(switch_core_session *session)
sdp_message_m_payload_add(tech_pvt->local_sdp, 0, osip_strdup(tmp));
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));
}
@ -288,7 +296,9 @@ static switch_status exosip_on_init(switch_core_session *session)
}
/* 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);
}
@ -362,7 +372,8 @@ static switch_status exosip_on_hangup(switch_core_session *session)
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;
}
@ -378,7 +389,8 @@ static switch_status exosip_on_transmit(switch_core_session *session)
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;
@ -386,7 +398,8 @@ static switch_status exosip_outgoing_channel(switch_core_session *session, switc
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);
@ -456,7 +469,6 @@ static void rtp_event_handler(struct rtp *session, rtp_event *event)
return;
}
//switch_console_printf(SWITCH_CHANNEL_CONSOLE, "RTP EVENT (%s)\n", event_names[event->type]);
switch (event->type) {
@ -508,8 +520,7 @@ static void activate_rtp(struct private_object *tech_pvt)
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->remote_sdp_audio_ip, tech_pvt->remote_sdp_audio_port);
//switch_mutex_lock(tech_pvt->rtp_lock);
@ -576,7 +587,8 @@ static switch_status exosip_answer_channel(switch_core_session *session)
}
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;
@ -651,7 +663,8 @@ static switch_status exosip_read_frame(switch_core_session *session, switch_fram
}
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;
@ -695,9 +708,7 @@ static switch_status exosip_write_frame(switch_core_session *session, switch_fra
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);
@ -806,7 +817,9 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
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) {
@ -857,8 +870,7 @@ static switch_status exosip_create_call(eXosip_event_t *event)
event->request->from->displayname,
event->request->from->url->username,
event->request->from->url->username,
NULL,
event->request->req_uri->username))) {
NULL, event->request->req_uri->username))) {
switch_channel_set_caller_profile(channel, tech_pvt->caller_profile);
}
@ -882,14 +894,17 @@ static switch_status exosip_create_call(eXosip_event_t *event)
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++);
sdp_add_codec(tech_pvt->sdp_config, codecs[i]->codec_type, codecs[i]->ianacode, codecs[i]->iananame,
imp->samples_per_second, x++);
}
}
}
@ -908,7 +923,8 @@ static switch_status exosip_create_call(eXosip_event_t *event)
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);
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;
@ -917,7 +933,8 @@ static switch_status exosip_create_call(eXosip_event_t *event)
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);
@ -967,7 +984,8 @@ static switch_status exosip_create_call(eXosip_event_t *event)
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);
@ -993,7 +1011,8 @@ static void destroy_call_by_event(eXosip_event_t *event)
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;
}
@ -1035,7 +1054,8 @@ static switch_status parse_sdp_media(sdp_media_t *media, char **dname, char **dr
*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;
@ -1099,12 +1119,16 @@ static void handle_answer(eXosip_event_t *event)
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;
@ -1148,8 +1172,7 @@ static void log_event(eXosip_event_t *je)
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)) {
} else if (je->type == EXOSIP_MESSAGE_NEW && je->request != NULL && MSG_IS_MESSAGE(je->request)) {
char *tmp = NULL;
if (je->request != NULL) {
@ -1158,8 +1181,7 @@ static void log_event(eXosip_event_t *je)
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);
} else {
@ -1169,26 +1191,22 @@ static void log_event(eXosip_event_t *je)
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);
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_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);
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);
}
@ -1196,8 +1214,7 @@ static void log_event(eXosip_event_t *je)
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);
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;
@ -1211,46 +1228,40 @@ static void log_event(eXosip_event_t *je)
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);
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);
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);
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);
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);
je->cid, je->did, je->sid, je->nid, je->request->sip_method, tmp);
osip_free(tmp);
} else if (je->response != NULL) {
char *tmp = NULL;
@ -1258,8 +1269,7 @@ static void log_event(eXosip_event_t *je)
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);
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",
@ -1436,4 +1446,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
config_exosip(0);
return SWITCH_STATUS_TERM;
}

View File

@ -96,7 +96,8 @@ 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",
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",
@ -104,7 +105,8 @@ static char *IAXNAMES[] = {"IAX_EVENT_CONNECT","IAX_EVENT_ACCEPT","IAX_EVENT_HAN
"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"};
"IAX_EVENT_TXREJECT", "IAX_EVENT_TXACCEPT", "IAX_EVENT_TXREADY"
};
struct ast_iana {
@ -114,8 +116,7 @@ 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"},
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"},
@ -200,7 +201,9 @@ typedef enum {
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;
@ -220,7 +223,11 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s
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;
}
@ -345,8 +352,7 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s
0,
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_GENERR;
} else {
@ -356,8 +362,7 @@ static switch_status iax_set_codec(struct private_object *tech_pvt, struct iax_s
0,
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");
switch_core_codec_destroy(&tech_pvt->read_codec);
return SWITCH_STATUS_GENERR;
@ -392,9 +397,12 @@ 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_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);
@ -551,7 +559,8 @@ static switch_status channel_on_transmit(switch_core_session *session)
/* 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;
@ -561,7 +570,8 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit
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);
@ -602,9 +612,7 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit
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_name, caller_profile->destination_number, NULL, 0, req, cap);
switch_channel_set_flag(channel, CF_OUTBOUND);
switch_set_flag(tech_pvt, TFLAG_OUTBOUND);
@ -653,7 +661,8 @@ static switch_status channel_send_dtmf(switch_core_session *session, char *dtmf)
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;
@ -687,7 +696,8 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra
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;
@ -702,13 +712,13 @@ static switch_status channel_write_frame(switch_core_session *session, switch_fr
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);
}
#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;
@ -769,7 +779,8 @@ static const switch_loadable_module_interface channel_module_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");
@ -820,10 +831,12 @@ static switch_status load_config(void)
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);
}
}
}
@ -884,7 +897,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
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;
if (iaxevent->ies.refresh)
refresh = iaxevent->ies.refresh;
break;
case IAX_EVENT_REGREJ:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Registration failed.\n");
@ -896,8 +910,10 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
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);
}
}
@ -916,9 +932,11 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
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));
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_console_printf(SWITCH_CHANNEL_CONSOLE, "Answer %s\n",
switch_channel_get_name(channel));
switch_channel_answer(channel);
}
}
@ -931,20 +949,21 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
"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);
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);
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)))) {
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);
@ -962,19 +981,18 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
iaxevent->ies.calling_number,
iax_get_peer_ip(iaxevent->session),
iaxevent->ies.calling_ani,
NULL,
iaxevent->ies.called_number))) {
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);
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) {
&iaxevent->ies.samprate, IAX_SET) != SWITCH_STATUS_SUCCESS) {
iax_reject(iaxevent->session, "Codec Error!");
switch_core_session_destroy(&session);
} else {
@ -1004,7 +1022,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
//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");
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "No Session? %s\n",
switch_test_flag(tech_pvt, TFLAG_VOICE) ? "yes" : "no");
}
}
break;
@ -1015,7 +1034,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
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) {
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;
@ -1036,7 +1056,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
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_console_printf(SWITCH_CHANNEL_CONSOLE, "%s DTMF %s\n", str,
switch_channel_get_name(channel));
}
switch_channel_queue_dtmf(channel, str);
}
@ -1044,7 +1065,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_runtime(void)
break;
default:
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Don't know what to do with IAX event %d.\n", iaxevent->etype);
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "Don't know what to do with IAX event %d.\n",
iaxevent->etype);
break;
}
@ -1075,4 +1097,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
}
return SWITCH_STATUS_SUCCESS;
}

View File

@ -65,9 +65,12 @@ 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_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);
@ -177,7 +180,8 @@ static switch_status channel_on_transmit(switch_core_session *session)
/* 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;
@ -185,7 +189,8 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit
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);
@ -250,7 +255,8 @@ static switch_status channel_waitfor_write(switch_core_session *session, int ms,
}
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;
@ -266,7 +272,8 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra
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;
@ -338,7 +345,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
}
*/
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;

View File

@ -106,9 +106,13 @@ 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_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);
@ -293,7 +297,8 @@ static switch_status channel_on_transmit(switch_core_session *session)
/* 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;
@ -301,7 +306,8 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit
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);
@ -317,7 +323,9 @@ static switch_status channel_outgoing_channel(switch_core_session *session, swit
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");
@ -368,7 +376,8 @@ static switch_status channel_send_dtmf(switch_core_session *session, char *dtmf)
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;
@ -388,7 +397,9 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra
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))) {
(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;
@ -399,7 +410,8 @@ static switch_status channel_read_frame(switch_core_session *session, switch_fra
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;
@ -413,7 +425,6 @@ static switch_status channel_write_frame(switch_core_session *session, switch_fr
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)));
@ -516,7 +527,8 @@ static const switch_loadable_module_interface channel_module_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");
@ -649,43 +661,47 @@ static int dump_info(void)
const PaDeviceInfo *pdi;
PaError err;
numDevices = Pa_CountDevices();
if( numDevices < 0 )
{
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++ )
{
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");
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
{
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++ )
{
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, ");
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");
}
@ -713,8 +729,7 @@ 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 {
@ -724,14 +739,14 @@ 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");
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));
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);
@ -741,8 +756,12 @@ static switch_status engage_device(struct private_object *tech_pvt)
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) {
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;
@ -796,14 +815,12 @@ 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;

View File

@ -55,9 +55,7 @@
/************************************************************************/
/******** Prototypes ****************************************************/
/************************************************************************/
static int blockingIOCallback( void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
static int blockingIOCallback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer,
PaTimestamp outTime, void *userData);
static PaError PABLIO_InitFIFO(RingBuffer * rbuf, long numFrames, long bytesPerFrame);
static PaError PABLIO_TermFIFO(RingBuffer * rbuf);
@ -69,8 +67,7 @@ static PaError PABLIO_TermFIFO( RingBuffer *rbuf );
/* Called from PortAudio.
* Read and write data only if there is room in FIFOs.
*/
static int blockingIOCallback( void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
static int blockingIOCallback(void *inputBuffer, void *outputBuffer, unsigned long framesPerBuffer,
PaTimestamp outTime, void *userData)
{
PABLIO_Stream * data = (PABLIO_Stream *) userData;
@ -86,34 +83,38 @@ static int blockingIOCallback( void *inputBuffer, void *outputBuffer,
{
int i;
int numRead = RingBuffer_Read(&data->outFIFO, outputBuffer, numBytes);
/* Zero out remainder of buffer if we run out of data. */
for (i = numRead; i < numBytes; i++)
{
((char *) outputBuffer)[i] = 0;
}
}
} }
return 0;
}
/* Allocate buffer. */
static PaError PABLIO_InitFIFO(RingBuffer * rbuf, long numFrames, long bytesPerFrame)
{
long numBytes = numFrames * bytesPerFrame;
char *buffer = (char *) malloc(numBytes);
if( buffer == NULL ) return paInsufficientMemory;
if (buffer == NULL)
return paInsufficientMemory;
memset(buffer, 0, numBytes);
return (PaError) RingBuffer_Init(rbuf, numBytes, buffer);
}
/* Free buffer. */
static PaError PABLIO_TermFIFO(RingBuffer * rbuf)
{
if( rbuf->buffer ) free( rbuf->buffer );
if (rbuf->buffer)
free(rbuf->buffer);
rbuf->buffer = NULL;
return paNoError;
}
/************************************************************
* Write data to ring buffer.
* Will not return until all the data has been written.
@ -128,11 +129,13 @@ long WriteAudioStream( PABLIO_Stream *aStream, void *data, long numFrames )
bytesWritten = RingBuffer_Write(&aStream->outFIFO, p, numBytes);
numBytes -= bytesWritten;
p += bytesWritten;
if( numBytes > 0) Pa_Sleep(10);
if (numBytes > 0)
Pa_Sleep(10);
}
return numFrames;
}
/************************************************************
* Read data from ring buffer.
* Will not return until all the data has been read.
@ -147,11 +150,13 @@ long ReadAudioStream( PABLIO_Stream *aStream, void *data, long numFrames )
bytesRead = RingBuffer_Read(&aStream->inFIFO, p, numBytes);
numBytes -= bytesRead;
p += bytesRead;
if( numBytes > 0) Pa_Sleep(10);
if (numBytes > 0)
Pa_Sleep(10);
}
return numFrames;
}
/************************************************************
* Return the number of frames that could be written to the stream without
* having to wait.
@ -162,6 +167,7 @@ long GetAudioStreamWriteable( PABLIO_Stream *aStream )
return bytesEmpty / aStream->bytesPerFrame;
}
/************************************************************
* Return the number of frames that are available to be read from the
* stream without having to wait.
@ -172,11 +178,13 @@ long GetAudioStreamReadable( PABLIO_Stream *aStream )
return bytesFull / aStream->bytesPerFrame;
}
/************************************************************/
static unsigned long RoundUpToNextPowerOf2(unsigned long n)
{
long numBits = 0;
if( ((n-1) & n) == 0) return n; /* Already Power of two. */
if (((n - 1) & n) == 0)
return n; /* Already Power of two. */
while (n > 0)
{
n = n >> 1;
@ -185,6 +193,7 @@ static unsigned long RoundUpToNextPowerOf2( unsigned long n )
return (1 << numBits);
}
/************************************************************
* Opens a PortAudio stream with default characteristics.
* Allocates PABLIO_Stream structure.
@ -193,8 +202,8 @@ static unsigned long RoundUpToNextPowerOf2( unsigned long n )
* PABLIO_READ, PABLIO_WRITE, or PABLIO_READ_WRITE,
* and either PABLIO_MONO or PABLIO_STEREO
*/
PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate,
PaSampleFormat format, long flags, int indev, int outdev )
PaError OpenAudioStream(PABLIO_Stream ** rwblPtr, double sampleRate, PaSampleFormat format, long flags, int indev,
int outdev)
{
long bytesPerSample;
long doRead = 0;
@ -206,7 +215,8 @@ PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate,
/* Allocate PABLIO_Stream structure for caller. */
aStream = (PABLIO_Stream *) malloc(sizeof(PABLIO_Stream));
if( aStream == NULL ) return paInsufficientMemory;
if (aStream == NULL)
return paInsufficientMemory;
memset(aStream, 0, sizeof(PABLIO_Stream));
/* Determine size of a sample. */
@ -221,13 +231,15 @@ PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate,
/* Initialize PortAudio */
err = Pa_Initialize();
if( err != paNoError ) goto error;
if (err != paNoError)
goto error;
/* Warning: numFrames must be larger than amount of data processed per interrupt
* inside PA to prevent glitches. Just to be safe, adjust size upwards.
*/
minNumBuffers = 2 * Pa_GetMinNumBuffers(FRAMES_PER_BUFFER, sampleRate);
numFrames = minNumBuffers * FRAMES_PER_BUFFER;
/* The PortAudio callback runs in a high priority thread. But PABLIO
* runs in a normal foreground thread. So we may have much worse
* latency in PABLIO. So adjust latency to a safe level.
@ -239,8 +251,7 @@ PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate,
{
numFrames = (int) ((safeLatencyMSec * sampleRate) / 1000);
}
}
numFrames = RoundUpToNextPowerOf2( numFrames );
} numFrames = RoundUpToNextPowerOf2(numFrames);
/* Initialize Ring Buffers */
doRead = ((flags & PABLIO_READ) != 0);
@ -248,13 +259,16 @@ PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate,
if (doRead)
{
err = PABLIO_InitFIFO(&aStream->inFIFO, numFrames, aStream->bytesPerFrame);
if( err != paNoError ) goto error;
if (err != paNoError)
goto error;
}
if (doWrite)
{
long numBytes;
err = PABLIO_InitFIFO(&aStream->outFIFO, numFrames, aStream->bytesPerFrame);
if( err != paNoError ) goto error;
if (err != paNoError)
goto error;
/* Make Write FIFO appear full initially. */
numBytes = RingBuffer_GetWriteAvailable(&aStream->outFIFO);
RingBuffer_AdvanceWriteIndex(&aStream->outFIFO, numBytes);
@ -262,45 +276,36 @@ PaError OpenAudioStream( PABLIO_Stream **rwblPtr, double sampleRate,
/* Open a PortAudio stream that we will use to communicate with the underlying
* audio drivers. */
err = Pa_OpenStream(
&aStream->stream,
err = Pa_OpenStream( &aStream->stream,
(doRead ? (indev > -1) ? indev : Pa_GetDefaultInputDeviceID() : paNoDevice),
(doRead ? aStream->samplesPerFrame : 0 ),
format,
NULL,
(doRead ? aStream->samplesPerFrame : 0), format, NULL,
(doWrite ? (outdev > -1) ? outdev : Pa_GetDefaultOutputDeviceID() : paNoDevice),
(doWrite ? aStream->samplesPerFrame : 0 ),
format,
NULL,
sampleRate,
FRAMES_PER_BUFFER,
minNumBuffers,
paClipOff, /* we won't output out of range samples so don't bother clipping them */
blockingIOCallback,
aStream );
if( err != paNoError ) goto error;
(doWrite ? aStream->samplesPerFrame : 0), format, NULL, sampleRate, FRAMES_PER_BUFFER,
minNumBuffers, paClipOff,
/* we won't output out of range samples so don't bother clipping them */
blockingIOCallback, aStream);
if (err != paNoError)
goto error;
err = Pa_StartStream(aStream->stream);
if( err != paNoError ) goto error;
if (err != paNoError)
goto error;
*rwblPtr = aStream;
return paNoError;
error:
CloseAudioStream( aStream );
error: CloseAudioStream(aStream);
*rwblPtr = NULL;
return err;
}
/************************************************************/
PaError CloseAudioStream(PABLIO_Stream * aStream)
{
PaError err = paNoError;
int bytesEmpty;
int byteSize = aStream->outFIFO.bufferSize;
if (aStream->stream != NULL) /* Make sure stream was opened. PLB021214 */
{
/* If we are writing data, make sure we play everything written. */
if (byteSize > 0)
{
@ -314,14 +319,15 @@ PaError CloseAudioStream( PABLIO_Stream *aStream )
}
}
err = Pa_StopStream(aStream->stream);
if( err != paNoError ) goto error;
if (err != paNoError)
goto error;
err = Pa_CloseStream(aStream->stream);
}
error:
Pa_Terminate();
error: Pa_Terminate();
PABLIO_TermFIFO(&aStream->inFIFO);
PABLIO_TermFIFO(&aStream->outFIFO);
free(aStream);
return err;
}

View File

@ -45,7 +45,8 @@
*/
long RingBuffer_Init(RingBuffer * rbuf, long numBytes, void *dataPtr)
{
if( ((numBytes-1) & numBytes) != 0) return -1; /* Not Power of two. */
if (((numBytes - 1) & numBytes) != 0)
return -1; /* Not Power of two. */
rbuf->bufferSize = numBytes;
rbuf->buffer = (char *) dataPtr;
RingBuffer_Flush(rbuf);
@ -53,12 +54,16 @@ long RingBuffer_Init( RingBuffer *rbuf, long numBytes, void *dataPtr )
rbuf->smallMask = (numBytes) - 1;
return 0;
}
/***************************************************************************
** Return number of bytes available for reading. */
long RingBuffer_GetReadAvailable(RingBuffer * rbuf)
{
return ((rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask);
}
/***************************************************************************
** Return number of bytes available for writing. */
long RingBuffer_GetWriteAvailable(RingBuffer * rbuf)
@ -66,6 +71,7 @@ long RingBuffer_GetWriteAvailable( RingBuffer *rbuf )
return (rbuf->bufferSize - RingBuffer_GetReadAvailable(rbuf));
}
/***************************************************************************
** Clear buffer. Should only be called when buffer is NOT being read. */
void RingBuffer_Flush(RingBuffer * rbuf)
@ -79,17 +85,19 @@ void RingBuffer_Flush( RingBuffer *rbuf )
** If non-contiguous, size2 will be the size of second region.
** Returns room available to be written or numBytes, whichever is smaller.
*/
long RingBuffer_GetWriteRegions( RingBuffer *rbuf, long numBytes,
void **dataPtr1, long *sizePtr1,
void **dataPtr2, long *sizePtr2 )
long RingBuffer_GetWriteRegions(RingBuffer * rbuf, long numBytes, void **dataPtr1, long *sizePtr1, void **dataPtr2,
long *sizePtr2)
{
long index;
long available = RingBuffer_GetWriteAvailable(rbuf);
if( numBytes > available ) numBytes = available;
if (numBytes > available)
numBytes = available;
/* Check to see if write is not contiguous. */
index = rbuf->writeIndex & rbuf->smallMask;
if ((index + numBytes) > rbuf->bufferSize)
{
/* Write data in two blocks that wrap the buffer. */
long firstHalf = rbuf->bufferSize - index;
*dataPtr1 = &rbuf->buffer[index];
@ -97,6 +105,7 @@ long RingBuffer_GetWriteRegions( RingBuffer *rbuf, long numBytes,
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = numBytes - firstHalf;
}
else
{
*dataPtr1 = &rbuf->buffer[index];
@ -115,23 +124,26 @@ long RingBuffer_AdvanceWriteIndex( RingBuffer *rbuf, long numBytes )
return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask;
}
/***************************************************************************
** Get address of region(s) from which we can read data.
** If the region is contiguous, size2 will be zero.
** If non-contiguous, size2 will be the size of second region.
** Returns room available to be written or numBytes, whichever is smaller.
*/
long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes,
void **dataPtr1, long *sizePtr1,
void **dataPtr2, long *sizePtr2 )
long RingBuffer_GetReadRegions(RingBuffer * rbuf, long numBytes, void **dataPtr1, long *sizePtr1, void **dataPtr2,
long *sizePtr2)
{
long index;
long available = RingBuffer_GetReadAvailable(rbuf);
if( numBytes > available ) numBytes = available;
if (numBytes > available)
numBytes = available;
/* Check to see if read is not contiguous. */
index = rbuf->readIndex & rbuf->smallMask;
if ((index + numBytes) > rbuf->bufferSize)
{
/* Write data in two blocks that wrap the buffer. */
long firstHalf = rbuf->bufferSize - index;
*dataPtr1 = &rbuf->buffer[index];
@ -139,6 +151,7 @@ long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes,
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = numBytes - firstHalf;
}
else
{
*dataPtr1 = &rbuf->buffer[index];
@ -148,6 +161,8 @@ long RingBuffer_GetReadRegions( RingBuffer *rbuf, long numBytes,
}
return numBytes;
}
/***************************************************************************
*/
long RingBuffer_AdvanceReadIndex(RingBuffer * rbuf, long numBytes)
@ -155,6 +170,7 @@ long RingBuffer_AdvanceReadIndex( RingBuffer *rbuf, long numBytes )
return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask;
}
/***************************************************************************
** Return bytes written. */
long RingBuffer_Write(RingBuffer * rbuf, void *data, long numBytes)
@ -164,11 +180,11 @@ long RingBuffer_Write( RingBuffer *rbuf, void *data, long numBytes )
numWritten = RingBuffer_GetWriteRegions(rbuf, numBytes, &data1, &size1, &data2, &size2);
if (size2 > 0)
{
memcpy(data1, data, size1);
data = ((char *) data) + size1;
memcpy(data2, data, size2);
}
else
{
memcpy(data1, data, size1);
@ -177,6 +193,7 @@ long RingBuffer_Write( RingBuffer *rbuf, void *data, long numBytes )
return numWritten;
}
/***************************************************************************
** Return bytes read. */
long RingBuffer_Read(RingBuffer * rbuf, void *data, long numBytes)
@ -190,6 +207,7 @@ long RingBuffer_Read( RingBuffer *rbuf, void *data, long numBytes )
data = ((char *) data) + size1;
memcpy(data, data2, size2);
}
else
{
memcpy(data, data1, size1);
@ -197,3 +215,5 @@ long RingBuffer_Read( RingBuffer *rbuf, void *data, long numBytes )
RingBuffer_AdvanceReadIndex(rbuf, numRead);
return numRead;
}

View File

@ -153,9 +153,12 @@ static switch_status wanpipe_on_init(switch_core_session *session);
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 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);
@ -222,8 +225,12 @@ static switch_status wanpipe_on_hangup(switch_core_session *session)
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;
@ -241,7 +248,8 @@ static switch_status wanpipe_on_transmit(switch_core_session *session)
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");
@ -266,7 +274,8 @@ static switch_status wanpipe_answer_channel(switch_core_session *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_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;
@ -291,12 +300,9 @@ static switch_status wanpipe_read_frame(switch_core_session *session, switch_fra
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 {
@ -312,7 +318,8 @@ static switch_status wanpipe_read_frame(switch_core_session *session, switch_fra
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;
@ -329,14 +336,12 @@ static switch_status wanpipe_write_frame(switch_core_session *session, switch_fr
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;
}
@ -385,7 +390,8 @@ static const switch_loadable_module_interface wanpipe_module_interface = {
/*.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) {
@ -453,11 +459,13 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri
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))) {
@ -502,7 +510,6 @@ static int on_ring(struct sangoma_pri *spri, sangoma_pri_event_t event_type, pri
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;
@ -540,7 +547,8 @@ static int on_restart(struct sangoma_pri *spri, sangoma_pri_event_t event_type,
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;
}
@ -608,13 +616,7 @@ static int config_wanpipe(int reload)
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);
@ -632,4 +634,3 @@ Public switch_status switch_module_runtime(void)
config_wanpipe(0);
return SWITCH_STATUS_TERM;
}

View File

@ -171,16 +171,20 @@ static switch_status woomerachan_on_hangup(switch_core_session *session);
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 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);
@ -208,13 +212,17 @@ static switch_status woomerachan_on_init(switch_core_session *session)
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;
@ -322,7 +330,8 @@ static switch_status woomerachan_kill_channel(switch_core_session *session, int
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;
@ -344,14 +353,16 @@ static switch_status woomerachan_on_transmit(switch_core_session *session)
/* 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);
@ -409,7 +420,8 @@ static switch_status woomerachan_waitfor_write(switch_core_session *session, int
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;
@ -434,13 +446,16 @@ static switch_status woomerachan_read_frame(switch_core_session *session, switch
*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) {
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;
@ -507,13 +522,10 @@ static void tech_destroy(private_object *tech_pvt)
}
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) {
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);
}
@ -541,7 +553,8 @@ static void woomera_printf(woomera_profile *profile, switch_socket_t *socket, ch
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);
@ -608,7 +621,8 @@ static int woomera_dequeue_event(woomera_event_queue *event_queue, woomera_messa
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;
@ -647,7 +661,8 @@ static int woomera_message_parse(switch_socket_t *fd, woomera_message *wmsg, int
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)) {
@ -809,7 +824,8 @@ static int woomera_locate_socket(woomera_profile *profile, switch_socket_t **woo
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);
}
@ -817,11 +833,7 @@ static int woomera_locate_socket(woomera_profile *profile, switch_socket_t **woo
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);
@ -889,26 +901,17 @@ static int tech_activate(private_object *tech_pvt)
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;
}
@ -964,14 +967,13 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj)
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;
@ -981,14 +983,13 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj)
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;
@ -997,13 +998,14 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj)
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) {
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);
@ -1016,12 +1018,7 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj)
}
/* 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
))) {
(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);
@ -1070,15 +1067,11 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj)
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);
}
@ -1088,17 +1081,12 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj)
MEDIA_ANSWER,
wmsg.callid,
WOOMERA_LINE_SEPERATOR,
tech_pvt->profile->audio_ip,
tech_pvt->port,
WOOMERA_RECORD_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);
&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;
@ -1129,9 +1117,12 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj)
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);
}
@ -1139,11 +1130,13 @@ static void *woomera_channel_thread_run(switch_thread *thread, void *obj)
}
}
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;
@ -1181,7 +1174,8 @@ static void *woomera_thread_run(void *obj)
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);
}
@ -1197,15 +1191,12 @@ static void *woomera_thread_run(void *obj)
}
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);
@ -1216,18 +1207,16 @@ static void *woomera_thread_run(void *obj)
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;
@ -1248,7 +1237,8 @@ static void *woomera_thread_run(void *obj)
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);
@ -1305,7 +1295,8 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_shutdown(void)
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;
@ -1384,6 +1375,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}

View File

@ -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,9 +113,9 @@ 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;
}
@ -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;
}

View File

@ -131,7 +131,8 @@ SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_jid, globals.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;
}
@ -162,7 +163,8 @@ int on_stream (struct session *sess, int type, iks *node)
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 (opt_use_tls && !iks_is_secure(sess->parser))
break;
if (sess->authorized) {
iks *t;
if (sess->features & IKS_STREAM_BIND) {
@ -193,7 +195,8 @@ int on_stream (struct session *sess, int type, iks *node)
pak = iks_packet(node);
iks_filter_packet(my_filter, pak);
if (sess->job_done == 1) return IKS_HOOK;
if (sess->job_done == 1)
return IKS_HOOK;
}
break;
#if 0
@ -208,7 +211,8 @@ int on_stream (struct session *sess, int type, iks *node)
}
if (node) iks_delete (node);
if (node)
iks_delete(node);
return IKS_OK;
}
@ -242,30 +246,29 @@ int on_error (void *user_data, ikspak *pak)
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");
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)
{
if (my_filter) iks_filter_delete (my_filter);
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_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_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);
IKS_RULE_SUBTYPE, IKS_TYPE_ERROR, IKS_RULE_ID, "auth", IKS_RULE_DONE);
}
static void xmpp_connect(char *jabber_id, char *pass)
@ -275,7 +278,8 @@ static void xmpp_connect (char *jabber_id, char *pass)
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);
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 */
@ -351,7 +355,8 @@ static switch_loadable_module_interface xmpp_event_module_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 = &xmpp_event_module_interface;

View File

@ -103,7 +103,8 @@ switch_status sndfile_file_open(switch_file_handle *handle, char *path)
}
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;
}
@ -231,7 +232,8 @@ static switch_status setup_formats(void)
switch_console_printf(SWITCH_CHANNEL_CONSOLE, "\nLibSndFile Version : %s Supported Formats\n", buffer);
switch_console_printf(SWITCH_CHANNEL_CONSOLE_CLEAN, "================================================================================\n");
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));
@ -273,11 +275,13 @@ static switch_status setup_formats(void)
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) {
@ -291,4 +295,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;
}

View File

@ -113,7 +113,8 @@ static const switch_loadable_module_interface mod_timers_module_interface = {
/*.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;
@ -121,8 +122,3 @@ SWITCH_MOD_DECLARE(switch_status) switch_module_load(const switch_loadable_modul
/* indicate that the module should continue to be loaded */
return SWITCH_STATUS_SUCCESS;
}