spring cleaning

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@4795 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale
2007-03-29 22:31:56 +00:00
parent a021945cef
commit 3a54126261
143 changed files with 22413 additions and 31567 deletions
File diff suppressed because it is too large Load Diff
+127 -114
View File
@@ -98,9 +98,9 @@ typedef struct private_object private_t;
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_dialplan, globals.dialplan)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ip, globals.ip)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_string, globals.codec_string)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_codec_rates_string, globals.codec_rates_string)
SWITCH_DECLARE_GLOBAL_STRING_FUNC(set_global_ip, globals.ip)
static char *IAXNAMES[] =
@@ -209,9 +209,9 @@ typedef enum {
IAX_QUERY = 2
} iax_io_t;
static switch_status_t iax_set_codec(private_t *tech_pvt, struct iax_session *iax_session,
unsigned int *format, unsigned int *cababilities, unsigned short *samprate,
iax_io_t io)
static switch_status_t iax_set_codec(private_t * 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;
@@ -225,15 +225,16 @@ static switch_status_t iax_set_codec(private_t *tech_pvt, struct iax_session *ia
if (globals.codec_string) {
if ((num_codecs = switch_loadable_module_get_codecs_sorted(codecs,
SWITCH_MAX_CODECS,
globals.codec_order,
globals.codec_order_last)) <= 0) {
SWITCH_MAX_CODECS,
globals.codec_order,
globals.codec_order_last)) <= 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "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) {
switch_loadable_module_get_codecs(switch_core_session_get_pool(tech_pvt->session), codecs,
SWITCH_MAX_CODECS))) <= 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "NO codecs?\n");
return SWITCH_STATUS_GENERR;
}
@@ -244,7 +245,7 @@ static switch_status_t iax_set_codec(private_t *tech_pvt, struct iax_session *ia
unsigned int codec = iana2ast(imp->ianacode);
if (io == IAX_QUERY && !(codec & local_cap)) {
iax_pref_codec_add(iax_session, codec);
}
}
local_cap |= codec;
}
}
@@ -422,12 +423,13 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session);
static switch_status_t channel_on_ring(switch_core_session_t *session);
static switch_status_t channel_on_loopback(switch_core_session_t *session);
static switch_status_t channel_on_transmit(switch_core_session_t *session);
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool);
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
switch_io_flag_t flags, int stream_id);
switch_io_flag_t flags, int stream_id);
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
switch_io_flag_t flags, int stream_id);
switch_io_flag_t flags, int stream_id);
static switch_status_t channel_kill_channel(switch_core_session_t *session, int sig);
@@ -443,14 +445,14 @@ static void iax_out_cb(const char *s)
}
}
static void tech_init(private_t *tech_pvt, switch_core_session_t *session)
static void tech_init(private_t * tech_pvt, switch_core_session_t *session)
{
tech_pvt->read_frame.data = tech_pvt->databuf;
tech_pvt->read_frame.buflen = sizeof(tech_pvt->databuf);
switch_mutex_init(&tech_pvt->mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
switch_core_session_set_private(session, tech_pvt);
tech_pvt->session = session;
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
switch_core_session_set_private(session, tech_pvt);
tech_pvt->session = session;
}
/*
@@ -559,7 +561,7 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
globals.calls = 0;
}
switch_mutex_unlock(globals.mutex);
return SWITCH_STATUS_SUCCESS;
}
@@ -574,20 +576,20 @@ static switch_status_t channel_kill_channel(switch_core_session_t *session, int
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
switch(sig) {
case SWITCH_SIG_KILL:
switch_clear_flag_locked(tech_pvt, TFLAG_IO);
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
//switch_thread_cond_signal(tech_pvt->cond);
break;
case SWITCH_SIG_BREAK:
switch_set_flag_locked(tech_pvt, TFLAG_BREAK);
break;
default:
break;
}
switch (sig) {
case SWITCH_SIG_KILL:
switch_clear_flag_locked(tech_pvt, TFLAG_IO);
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
//switch_thread_cond_signal(tech_pvt->cond);
break;
case SWITCH_SIG_BREAK:
switch_set_flag_locked(tech_pvt, TFLAG_BREAK);
break;
default:
break;
}
return SWITCH_STATUS_SUCCESS;
}
@@ -641,33 +643,33 @@ static switch_status_t channel_send_dtmf(switch_core_session_t *session, char *d
}
static switch_status_t channel_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
switch_io_flag_t flags, int stream_id)
switch_io_flag_t flags, int stream_id)
{
switch_channel_t *channel = NULL;
private_t *tech_pvt = NULL;
switch_time_t started = switch_time_now();
unsigned int elapsed;
switch_byte_t *data;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
tech_pvt = switch_core_session_get_private(session);
assert(tech_pvt != NULL);
tech_pvt->read_frame.flags = SFF_NONE;
*frame = NULL;
tech_pvt->read_frame.flags = SFF_NONE;
*frame = NULL;
while (switch_test_flag(tech_pvt, TFLAG_IO)) {
if (!switch_test_flag(tech_pvt, TFLAG_CODEC)) {
switch_yield(1000);
continue;
}
if (!switch_test_flag(tech_pvt, TFLAG_CODEC)) {
switch_yield(1000);
continue;
}
//switch_thread_cond_wait(tech_pvt->cond, tech_pvt->mutex);
if (switch_test_flag(tech_pvt, TFLAG_BREAK)) {
switch_clear_flag(tech_pvt, TFLAG_BREAK);
goto cng;
}
switch_clear_flag(tech_pvt, TFLAG_BREAK);
goto cng;
}
if (!switch_test_flag(tech_pvt, TFLAG_IO)) {
return SWITCH_STATUS_FALSE;
@@ -688,12 +690,12 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
}
if (timeout > -1) {
elapsed = (unsigned int)((switch_time_now() - started) / 1000);
if (elapsed >= (unsigned int)timeout) {
elapsed = (unsigned int) ((switch_time_now() - started) / 1000);
if (elapsed >= (unsigned int) timeout) {
return SWITCH_STATUS_SUCCESS;
}
}
switch_yield(1000);
}
@@ -701,19 +703,19 @@ static switch_status_t channel_read_frame(switch_core_session_t *session, switch
return SWITCH_STATUS_FALSE;
cng:
cng:
data = (switch_byte_t *) tech_pvt->read_frame.data;
data[0] = 65;
data[1] = 0;
tech_pvt->read_frame.datalen = 2;
tech_pvt->read_frame.flags = SFF_CNG;
*frame = &tech_pvt->read_frame;
return SWITCH_STATUS_SUCCESS;
tech_pvt->read_frame.datalen = 2;
tech_pvt->read_frame.flags = SFF_CNG;
*frame = &tech_pvt->read_frame;
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t channel_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
switch_io_flag_t flags, int stream_id)
switch_io_flag_t flags, int stream_id)
{
switch_channel_t *channel = NULL;
private_t *tech_pvt = NULL;
@@ -799,7 +801,8 @@ static const switch_loadable_module_interface_t channel_module_interface = {
/* 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_call_cause_t channel_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *session,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool)
{
if ((*new_session = switch_core_session_request(&channel_endpoint_interface, pool)) != 0) {
@@ -812,7 +815,7 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
switch_core_session_add_stream(*new_session, NULL);
if ((tech_pvt = (private_t *) switch_core_session_alloc(*new_session, sizeof(private_t))) != 0) {
channel = switch_core_session_get_channel(*new_session);
tech_init(tech_pvt, *new_session);
tech_init(tech_pvt, *new_session);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
switch_core_session_destroy(new_session);
@@ -863,7 +866,8 @@ static switch_call_cause_t channel_outgoing_channel(switch_core_session_t *sessi
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
if (switch_core_new_memory_pool(&module_pool) != SWITCH_STATUS_SUCCESS) {
@@ -871,7 +875,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
return SWITCH_STATUS_TERM;
}
/* connect my internal structure to the blank pointer passed to me */
*module_interface = &channel_module_interface;
@@ -943,18 +947,21 @@ static switch_status_t load_config(void)
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t tech_media(private_t *tech_pvt, struct iax_event *iaxevent)
static switch_status_t tech_media(private_t * tech_pvt, struct iax_event *iaxevent)
{
unsigned int cap = iax_session_get_capability(iaxevent->session);
unsigned int format = iaxevent->ies.format;
unsigned int cap = iax_session_get_capability(iaxevent->session);
unsigned int format = iaxevent->ies.format;
switch_status_t status = SWITCH_STATUS_SUCCESS;
if (!switch_test_flag(tech_pvt, TFLAG_CODEC) &&
(status = iax_set_codec(tech_pvt, iaxevent->session, &format, &cap, &iaxevent->ies.samprate, IAX_SET)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Error %u %u\n", iaxevent->ies.format, iaxevent->ies.capability);
}
return status;
if (!switch_test_flag(tech_pvt, TFLAG_CODEC) &&
(status =
iax_set_codec(tech_pvt, iaxevent->session, &format, &cap, &iaxevent->ies.samprate,
IAX_SET)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec Error %u %u\n", iaxevent->ies.format,
iaxevent->ies.capability);
}
return status;
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
@@ -994,7 +1001,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
/* Wait for an event. */
if ((iaxevent = iax_get_event(0)) == NULL) {
int waitlen = 0;
if (globals.calls == 0) {
waitlen = 10000;
} else if (globals.calls < 10) {
@@ -1007,12 +1014,12 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
continue;
} else {
private_t *tech_pvt = NULL;
switch_channel_t *channel = NULL;
switch_channel_t *channel = NULL;
if ((tech_pvt = iax_get_private(iaxevent->session))) {
channel = switch_core_session_get_channel(tech_pvt->session);
}
if ((tech_pvt = iax_get_private(iaxevent->session))) {
channel = switch_core_session_get_channel(tech_pvt->session);
}
if (globals.debug && iaxevent->etype != IAX_EVENT_VOICE) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Event %d [%s]!\n",
iaxevent->etype, IAXNAMES[iaxevent->etype]);
@@ -1031,11 +1038,11 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
break;
case IAX_EVENT_ACCEPT:
if (channel && !switch_channel_test_flag(channel, CF_ANSWERED)) {
if (tech_media(tech_pvt, iaxevent) == SWITCH_STATUS_SUCCESS) {
switch_channel_mark_pre_answered(channel);
} else {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
if (tech_media(tech_pvt, iaxevent) == SWITCH_STATUS_SUCCESS) {
switch_channel_mark_pre_answered(channel);
} else {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Call accepted.\n");
break;
@@ -1052,32 +1059,34 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
case IAX_EVENT_ANSWER:
// the other side answered our call
if (channel) {
if (tech_media(tech_pvt, iaxevent) == SWITCH_STATUS_SUCCESS) {
if (switch_channel_test_flag(channel, CF_ANSWERED)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "WTF Mutiple Answer %s?\n", switch_channel_get_name(channel));
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Answer %s\n", switch_channel_get_name(channel));
switch_channel_mark_answered(channel);
}
} else {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
}
if (tech_media(tech_pvt, iaxevent) == SWITCH_STATUS_SUCCESS) {
if (switch_channel_test_flag(channel, CF_ANSWERED)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "WTF Mutiple Answer %s?\n",
switch_channel_get_name(channel));
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Answer %s\n",
switch_channel_get_name(channel));
switch_channel_mark_answered(channel);
}
} else {
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
}
}
break;
case IAX_EVENT_CONNECT:
// incoming call detected
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE,
"Incoming call connected %s, %s, %s %u/%u\n",
iaxevent->ies.called_number,
iaxevent->ies.calling_number,
iaxevent->ies.calling_name, iaxevent->ies.format, iaxevent->ies.capability);
"Incoming call connected %s, %s, %s %u/%u\n",
iaxevent->ies.called_number,
iaxevent->ies.calling_number,
iaxevent->ies.calling_name, iaxevent->ies.format, iaxevent->ies.capability);
if (iaxevent) {
switch_core_session_t *session;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "New Inbound Channel %s!\n",
iaxevent->ies.calling_name);
iaxevent->ies.calling_name);
if ((session = switch_core_session_request(&channel_endpoint_interface, NULL)) != 0) {
private_t *tech_pvt;
switch_channel_t *channel;
@@ -1085,7 +1094,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
switch_core_session_add_stream(session, NULL);
if ((tech_pvt = (private_t *) switch_core_session_alloc(session, sizeof(private_t))) != 0) {
channel = switch_core_session_get_channel(session);
tech_init(tech_pvt, session);
tech_init(tech_pvt, session);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Hey where is my memory pool?\n");
switch_core_session_destroy(&session);
@@ -1100,9 +1109,9 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
iaxevent->ies.calling_number,
iax_get_peer_ip(iaxevent->session),
iaxevent->ies.calling_ani,
NULL,
NULL,
(char *)modname,
NULL,
(char *) modname,
iaxevent->ies.called_context,
iaxevent->ies.called_number)) != 0) {
char name[128];
@@ -1141,11 +1150,15 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
switch_mutex_unlock(tech_pvt->flag_mutex);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s\n", switch_channel_get_name(channel));
switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
switch_channel_hangup(channel, iaxevent->etype == IAX_EVENT_HANGUP ? SWITCH_CAUSE_NORMAL_CLEARING : SWITCH_CAUSE_FACILITY_REJECTED);
//switch_thread_cond_signal(tech_pvt->cond);
iaxevent->session = NULL;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hangup %s\n",
switch_channel_get_name(channel));
switch_set_flag_locked(tech_pvt, TFLAG_HANGUP);
switch_channel_hangup(channel,
iaxevent->etype ==
IAX_EVENT_HANGUP ? SWITCH_CAUSE_NORMAL_CLEARING :
SWITCH_CAUSE_FACILITY_REJECTED);
//switch_thread_cond_signal(tech_pvt->cond);
iaxevent->session = NULL;
}
break;
case IAX_EVENT_CNG:
@@ -1156,7 +1169,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
if (tech_pvt && (tech_pvt->read_frame.datalen = iaxevent->datalen) != 0) {
if (channel && switch_channel_get_state(channel) <= CS_HANGUP) {
int bytes, frames;
if (!switch_test_flag(tech_pvt, TFLAG_CODEC)) {
//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "audio with no codec yet!\n");
break;
@@ -1183,18 +1196,18 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_runtime(void)
break;
case IAX_EVENT_DTMF:
if (channel) {
char str[2] = { (char)iaxevent->subclass };
if (globals.debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s DTMF %s\n", str,
switch_channel_get_name(channel));
}
switch_channel_queue_dtmf(channel, str);
char str[2] = { (char) iaxevent->subclass };
if (globals.debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "%s DTMF %s\n", str,
switch_channel_get_name(channel));
}
switch_channel_queue_dtmf(channel, str);
}
break;
default:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Don't know what to do with IAX event %d.\n",
iaxevent->etype);
iaxevent->etype);
break;
}
@@ -1216,7 +1229,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
running = -1;
if (globals.fd) {
/* Die Mutha $%#$@% Die Mutha $#%#$^ Die*/
/* Die Mutha $%#$@% Die Mutha $#%#$^ Die */
shutdown(globals.fd, 2);
}
iax_shutdown();
File diff suppressed because it is too large Load Diff
+102 -111
View File
@@ -81,17 +81,17 @@
# define PaUtil_WriteMemoryBarrier()
#else
#if defined(__APPLE__) //|| defined(__FreeBSD__)
#if defined(__APPLE__) //|| defined(__FreeBSD__)
# include <libkern/OSAtomic.h>
/* Here are the memory barrier functions. Mac OS X and FreeBSD only provide
full memory barriers, so the three types of barriers are the same. */
/* Here are the memory barrier functions. Mac OS X and FreeBSD only provide
full memory barriers, so the three types of barriers are the same. */
# define PaUtil_FullMemoryBarrier() OSMemoryBarrier()
# define PaUtil_ReadMemoryBarrier() OSMemoryBarrier()
# define PaUtil_WriteMemoryBarrier() OSMemoryBarrier()
#elif defined(__GNUC__)
/* GCC understands volatile asm and "memory" to mean it
* should not reorder memory read/writes */
/* GCC understands volatile asm and "memory" to mean it
* should not reorder memory read/writes */
# if defined( __PPC__ )
# define PaUtil_FullMemoryBarrier() __asm__ volatile("sync":::"memory")
# define PaUtil_ReadMemoryBarrier() __asm__ volatile("sync":::"memory")
@@ -123,37 +123,39 @@
* Initialize FIFO.
* numBytes must be power of 2, returns -1 if not.
*/
long PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, long numBytes, void *dataPtr )
long PaUtil_InitializeRingBuffer(PaUtilRingBuffer * rbuf, long numBytes, void *dataPtr)
{
if( ((numBytes-1) & numBytes) != 0) return -1; /* Not Power of two. */
rbuf->bufferSize = numBytes;
rbuf->buffer = (char *)dataPtr;
PaUtil_FlushRingBuffer( rbuf );
rbuf->bigMask = (numBytes*2)-1;
rbuf->smallMask = (numBytes)-1;
return 0;
if (((numBytes - 1) & numBytes) != 0)
return -1; /* Not Power of two. */
rbuf->bufferSize = numBytes;
rbuf->buffer = (char *) dataPtr;
PaUtil_FlushRingBuffer(rbuf);
rbuf->bigMask = (numBytes * 2) - 1;
rbuf->smallMask = (numBytes) - 1;
return 0;
}
/***************************************************************************
** Return number of bytes available for reading. */
long PaUtil_GetRingBufferReadAvailable( PaUtilRingBuffer *rbuf )
long PaUtil_GetRingBufferReadAvailable(PaUtilRingBuffer * rbuf)
{
PaUtil_ReadMemoryBarrier();
return ( (rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask );
PaUtil_ReadMemoryBarrier();
return ((rbuf->writeIndex - rbuf->readIndex) & rbuf->bigMask);
}
/***************************************************************************
** Return number of bytes available for writing. */
long PaUtil_GetRingBufferWriteAvailable( PaUtilRingBuffer *rbuf )
long PaUtil_GetRingBufferWriteAvailable(PaUtilRingBuffer * rbuf)
{
/* Since we are calling PaUtil_GetRingBufferReadAvailable, we don't need an aditional MB */
return ( rbuf->bufferSize - PaUtil_GetRingBufferReadAvailable(rbuf));
/* Since we are calling PaUtil_GetRingBufferReadAvailable, we don't need an aditional MB */
return (rbuf->bufferSize - PaUtil_GetRingBufferReadAvailable(rbuf));
}
/***************************************************************************
** Clear buffer. Should only be called when buffer is NOT being read. */
void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf )
void PaUtil_FlushRingBuffer(PaUtilRingBuffer * rbuf)
{
rbuf->writeIndex = rbuf->readIndex = 0;
rbuf->writeIndex = rbuf->readIndex = 0;
}
/***************************************************************************
@@ -162,42 +164,39 @@ void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf )
** If non-contiguous, size2 will be the size of second region.
** Returns room available to be written or numBytes, whichever is smaller.
*/
long PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, long numBytes,
void **dataPtr1, long *sizePtr1,
void **dataPtr2, long *sizePtr2 )
long PaUtil_GetRingBufferWriteRegions(PaUtilRingBuffer * rbuf, long numBytes,
void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2)
{
long index;
long available = PaUtil_GetRingBufferWriteAvailable( rbuf );
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];
*sizePtr1 = firstHalf;
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = numBytes - firstHalf;
}
else
{
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = numBytes;
*dataPtr2 = NULL;
*sizePtr2 = 0;
}
return numBytes;
long index;
long available = PaUtil_GetRingBufferWriteAvailable(rbuf);
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];
*sizePtr1 = firstHalf;
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = numBytes - firstHalf;
} else {
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = numBytes;
*dataPtr2 = NULL;
*sizePtr2 = 0;
}
return numBytes;
}
/***************************************************************************
*/
long PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, long numBytes )
long PaUtil_AdvanceRingBufferWriteIndex(PaUtilRingBuffer * rbuf, long numBytes)
{
/* we need to ensure that previous writes are seen before we update the write index */
PaUtil_WriteMemoryBarrier();
return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask;
/* we need to ensure that previous writes are seen before we update the write index */
PaUtil_WriteMemoryBarrier();
return rbuf->writeIndex = (rbuf->writeIndex + numBytes) & rbuf->bigMask;
}
/***************************************************************************
@@ -206,81 +205,73 @@ long PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, long numBytes )
** If non-contiguous, size2 will be the size of second region.
** Returns room available to be written or numBytes, whichever is smaller.
*/
long PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, long numBytes,
void **dataPtr1, long *sizePtr1,
void **dataPtr2, long *sizePtr2 )
long PaUtil_GetRingBufferReadRegions(PaUtilRingBuffer * rbuf, long numBytes,
void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2)
{
long index;
long available = PaUtil_GetRingBufferReadAvailable( rbuf );
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];
*sizePtr1 = firstHalf;
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = numBytes - firstHalf;
}
else
{
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = numBytes;
*dataPtr2 = NULL;
*sizePtr2 = 0;
}
return numBytes;
long index;
long available = PaUtil_GetRingBufferReadAvailable(rbuf);
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];
*sizePtr1 = firstHalf;
*dataPtr2 = &rbuf->buffer[0];
*sizePtr2 = numBytes - firstHalf;
} else {
*dataPtr1 = &rbuf->buffer[index];
*sizePtr1 = numBytes;
*dataPtr2 = NULL;
*sizePtr2 = 0;
}
return numBytes;
}
/***************************************************************************
*/
long PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, long numBytes )
long PaUtil_AdvanceRingBufferReadIndex(PaUtilRingBuffer * rbuf, long numBytes)
{
/* we need to ensure that previous writes are always seen before updating the index. */
PaUtil_WriteMemoryBarrier();
return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask;
/* we need to ensure that previous writes are always seen before updating the index. */
PaUtil_WriteMemoryBarrier();
return rbuf->readIndex = (rbuf->readIndex + numBytes) & rbuf->bigMask;
}
/***************************************************************************
** Return bytes written. */
long PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, long numBytes )
long PaUtil_WriteRingBuffer(PaUtilRingBuffer * rbuf, const void *data, long numBytes)
{
long size1, size2, numWritten;
void *data1, *data2;
numWritten = PaUtil_GetRingBufferWriteRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 );
if( size2 > 0 )
{
long size1, size2, numWritten;
void *data1, *data2;
numWritten = PaUtil_GetRingBufferWriteRegions(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 );
}
PaUtil_AdvanceRingBufferWriteIndex( rbuf, numWritten );
return numWritten;
memcpy(data1, data, size1);
data = ((char *) data) + size1;
memcpy(data2, data, size2);
} else {
memcpy(data1, data, size1);
}
PaUtil_AdvanceRingBufferWriteIndex(rbuf, numWritten);
return numWritten;
}
/***************************************************************************
** Return bytes read. */
long PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, long numBytes )
long PaUtil_ReadRingBuffer(PaUtilRingBuffer * rbuf, void *data, long numBytes)
{
long size1, size2, numRead;
void *data1, *data2;
numRead = PaUtil_GetRingBufferReadRegions( rbuf, numBytes, &data1, &size1, &data2, &size2 );
if( size2 > 0 )
{
memcpy( data, data1, size1 );
data = ((char *)data) + size1;
memcpy( data, data2, size2 );
}
else
{
memcpy( data, data1, size1 );
}
PaUtil_AdvanceRingBufferReadIndex( rbuf, numRead );
return numRead;
long size1, size2, numRead;
void *data1, *data2;
numRead = PaUtil_GetRingBufferReadRegions(rbuf, numBytes, &data1, &size1, &data2, &size2);
if (size2 > 0) {
memcpy(data, data1, size1);
data = ((char *) data) + size1;
memcpy(data, data2, size2);
} else {
memcpy(data, data1, size1);
}
PaUtil_AdvanceRingBufferReadIndex(rbuf, numRead);
return numRead;
}
+24 -28
View File
@@ -51,19 +51,17 @@
*/
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
extern "C" {
#endif /* __cplusplus */
typedef struct PaUtilRingBuffer
{
long bufferSize; /* Number of bytes in FIFO. Power of 2. Set by PaUtil_InitRingBuffer. */
long writeIndex; /* Index of next writable byte. Set by PaUtil_AdvanceRingBufferWriteIndex. */
long readIndex; /* Index of next readable byte. Set by PaUtil_AdvanceRingBufferReadIndex. */
long bigMask; /* Used for wrapping indices with extra bit to distinguish full/empty. */
long smallMask; /* Used for fitting indices to buffer. */
char *buffer;
}PaUtilRingBuffer;
typedef struct PaUtilRingBuffer {
long bufferSize; /* Number of bytes in FIFO. Power of 2. Set by PaUtil_InitRingBuffer. */
long writeIndex; /* Index of next writable byte. Set by PaUtil_AdvanceRingBufferWriteIndex. */
long readIndex; /* Index of next readable byte. Set by PaUtil_AdvanceRingBufferReadIndex. */
long bigMask; /* Used for wrapping indices with extra bit to distinguish full/empty. */
long smallMask; /* Used for fitting indices to buffer. */
char *buffer;
} PaUtilRingBuffer;
/** Initialize Ring Buffer.
@@ -76,13 +74,13 @@ typedef struct PaUtilRingBuffer
@return -1 if numBytes is not a power of 2, otherwise 0.
*/
long PaUtil_InitializeRingBuffer( PaUtilRingBuffer *rbuf, long numBytes, void *dataPtr );
long PaUtil_InitializeRingBuffer(PaUtilRingBuffer * rbuf, long numBytes, void *dataPtr);
/** Clear buffer. Should only be called when buffer is NOT being read.
@param rbuf The ring buffer.
*/
void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf );
void PaUtil_FlushRingBuffer(PaUtilRingBuffer * rbuf);
/** Retrieve the number of bytes available in the ring buffer for writing.
@@ -90,7 +88,7 @@ void PaUtil_FlushRingBuffer( PaUtilRingBuffer *rbuf );
@return The number of bytes available for writing.
*/
long PaUtil_GetRingBufferWriteAvailable( PaUtilRingBuffer *rbuf );
long PaUtil_GetRingBufferWriteAvailable(PaUtilRingBuffer * rbuf);
/** Retrieve the number of bytes available in the ring buffer for reading.
@@ -98,7 +96,7 @@ long PaUtil_GetRingBufferWriteAvailable( PaUtilRingBuffer *rbuf );
@return The number of bytes available for reading.
*/
long PaUtil_GetRingBufferReadAvailable( PaUtilRingBuffer *rbuf );
long PaUtil_GetRingBufferReadAvailable(PaUtilRingBuffer * rbuf);
/** Write data to the ring buffer.
@@ -110,7 +108,7 @@ long PaUtil_GetRingBufferReadAvailable( PaUtilRingBuffer *rbuf );
@return The number of bytes written.
*/
long PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, long numBytes );
long PaUtil_WriteRingBuffer(PaUtilRingBuffer * rbuf, const void *data, long numBytes);
/** Read data from the ring buffer.
@@ -122,7 +120,7 @@ long PaUtil_WriteRingBuffer( PaUtilRingBuffer *rbuf, const void *data, long numB
@return The number of bytes read.
*/
long PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, long numBytes );
long PaUtil_ReadRingBuffer(PaUtilRingBuffer * rbuf, void *data, long numBytes);
/** Get address of region(s) to which we can write data.
@@ -144,9 +142,8 @@ long PaUtil_ReadRingBuffer( PaUtilRingBuffer *rbuf, void *data, long numBytes );
@return The room available to be written or numBytes, whichever is smaller.
*/
long PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, long numBytes,
void **dataPtr1, long *sizePtr1,
void **dataPtr2, long *sizePtr2 );
long PaUtil_GetRingBufferWriteRegions(PaUtilRingBuffer * rbuf, long numBytes,
void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2);
/** Advance the write index to the next location to be written.
@@ -156,7 +153,7 @@ long PaUtil_GetRingBufferWriteRegions( PaUtilRingBuffer *rbuf, long numBytes,
@return The new position.
*/
long PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, long numBytes );
long PaUtil_AdvanceRingBufferWriteIndex(PaUtilRingBuffer * rbuf, long numBytes);
/** Get address of region(s) from which we can write data.
@@ -178,9 +175,8 @@ long PaUtil_AdvanceRingBufferWriteIndex( PaUtilRingBuffer *rbuf, long numBytes )
@return The number of bytes available for reading.
*/
long PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, long numBytes,
void **dataPtr1, long *sizePtr1,
void **dataPtr2, long *sizePtr2 );
long PaUtil_GetRingBufferReadRegions(PaUtilRingBuffer * rbuf, long numBytes,
void **dataPtr1, long *sizePtr1, void **dataPtr2, long *sizePtr2);
/** Advance the read index to the next location to be read.
@@ -190,9 +186,9 @@ long PaUtil_GetRingBufferReadRegions( PaUtilRingBuffer *rbuf, long numBytes,
@return The new position.
*/
long PaUtil_AdvanceRingBufferReadIndex( PaUtilRingBuffer *rbuf, long numBytes );
long PaUtil_AdvanceRingBufferReadIndex(PaUtilRingBuffer * rbuf, long numBytes);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* PA_RINGBUFFER_H */
#endif /* __cplusplus */
#endif /* PA_RINGBUFFER_H */
+145 -150
View File
@@ -59,13 +59,12 @@
/******** Prototypes ****************************************************/
/************************************************************************/
static int blockingIOCallback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData );
static PaError PABLIO_InitFIFO( PaUtilRingBuffer *rbuf, long numFrames, long bytesPerFrame );
static PaError PABLIO_TermFIFO( PaUtilRingBuffer *rbuf );
static int blockingIOCallback(const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo * timeInfo,
PaStreamCallbackFlags statusFlags, void *userData);
static PaError PABLIO_InitFIFO(PaUtilRingBuffer * rbuf, long numFrames, long bytesPerFrame);
static PaError PABLIO_TermFIFO(PaUtilRingBuffer * rbuf);
/************************************************************************/
/******** Functions *****************************************************/
@@ -74,122 +73,120 @@ static PaError PABLIO_TermFIFO( PaUtilRingBuffer *rbuf );
/* Called from PortAudio.
* Read and write data only if there is room in FIFOs.
*/
static int blockingIOCallback( const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags,
void *userData )
static int blockingIOCallback(const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo * timeInfo,
PaStreamCallbackFlags statusFlags, void *userData)
{
PABLIO_Stream *data = (PABLIO_Stream*)userData;
long numBytes = data->bytesPerFrame * framesPerBuffer;
PABLIO_Stream *data = (PABLIO_Stream *) userData;
long numBytes = data->bytesPerFrame * framesPerBuffer;
/* This may get called with NULL inputBuffer during initial setup. */
if( inputBuffer != NULL )
{
PaUtil_WriteRingBuffer( &data->inFIFO, inputBuffer, numBytes );
}
if( outputBuffer != NULL )
{
int i;
int numRead = PaUtil_ReadRingBuffer( &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;
}
}
/* This may get called with NULL inputBuffer during initial setup. */
if (inputBuffer != NULL) {
PaUtil_WriteRingBuffer(&data->inFIFO, inputBuffer, numBytes);
}
if (outputBuffer != NULL) {
int i;
int numRead = PaUtil_ReadRingBuffer(&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;
return 0;
}
/* Allocate buffer. */
static PaError PABLIO_InitFIFO( PaUtilRingBuffer *rbuf, long numFrames, long bytesPerFrame )
static PaError PABLIO_InitFIFO(PaUtilRingBuffer * rbuf, long numFrames, long bytesPerFrame)
{
long numBytes = numFrames * bytesPerFrame;
char *buffer = (char *) malloc( numBytes );
if( buffer == NULL ) return paInsufficientMemory;
memset( buffer, 0, numBytes );
return (PaError) PaUtil_InitializeRingBuffer( rbuf, numBytes, buffer );
long numBytes = numFrames * bytesPerFrame;
char *buffer = (char *) malloc(numBytes);
if (buffer == NULL)
return paInsufficientMemory;
memset(buffer, 0, numBytes);
return (PaError) PaUtil_InitializeRingBuffer(rbuf, numBytes, buffer);
}
/* Free buffer. */
static PaError PABLIO_TermFIFO( PaUtilRingBuffer *rbuf )
static PaError PABLIO_TermFIFO(PaUtilRingBuffer * rbuf)
{
if( rbuf->buffer ) free( rbuf->buffer );
rbuf->buffer = NULL;
return paNoError;
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.
*/
long WriteAudioStream( PABLIO_Stream *aStream, void *data, long numFrames )
long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames)
{
long bytesWritten;
char *p = (char *) data;
long numBytes = aStream->bytesPerFrame * numFrames;
while( numBytes > 0)
{
bytesWritten = PaUtil_WriteRingBuffer( &aStream->outFIFO, p, numBytes );
numBytes -= bytesWritten;
p += bytesWritten;
if( numBytes > 0) Pa_Sleep(10);
}
return numFrames;
long bytesWritten;
char *p = (char *) data;
long numBytes = aStream->bytesPerFrame * numFrames;
while (numBytes > 0) {
bytesWritten = PaUtil_WriteRingBuffer(&aStream->outFIFO, p, numBytes);
numBytes -= bytesWritten;
p += bytesWritten;
if (numBytes > 0)
Pa_Sleep(10);
}
return numFrames;
}
/************************************************************
* Read data from ring buffer.
* Will not return until all the data has been read.
*/
long ReadAudioStream( PABLIO_Stream *aStream, void *data, long numFrames )
long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames)
{
long bytesRead;
char *p = (char *) data;
long numBytes = aStream->bytesPerFrame * numFrames;
long bytesRead;
char *p = (char *) data;
long numBytes = aStream->bytesPerFrame * numFrames;
while( numBytes > 0)
{
bytesRead = PaUtil_ReadRingBuffer( &aStream->inFIFO, p, numBytes );
numBytes -= bytesRead;
p += bytesRead;
if( numBytes > 0) Pa_Sleep(10);
}
return numFrames;
while (numBytes > 0) {
bytesRead = PaUtil_ReadRingBuffer(&aStream->inFIFO, p, numBytes);
numBytes -= bytesRead;
p += bytesRead;
if (numBytes > 0)
Pa_Sleep(10);
}
return numFrames;
}
/************************************************************
* Return the number of frames that could be written to the stream without
* having to wait.
*/
long GetAudioStreamWriteable( PABLIO_Stream *aStream )
long GetAudioStreamWriteable(PABLIO_Stream * aStream)
{
int bytesEmpty = PaUtil_GetRingBufferWriteAvailable( &aStream->outFIFO );
return bytesEmpty / aStream->bytesPerFrame;
int bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
return bytesEmpty / aStream->bytesPerFrame;
}
/************************************************************
* Return the number of frames that are available to be read from the
* stream without having to wait.
*/
long GetAudioStreamReadable( PABLIO_Stream *aStream )
long GetAudioStreamReadable(PABLIO_Stream * aStream)
{
int bytesFull = PaUtil_GetRingBufferReadAvailable( &aStream->inFIFO );
return bytesFull / aStream->bytesPerFrame;
int bytesFull = PaUtil_GetRingBufferReadAvailable(&aStream->inFIFO);
return bytesFull / aStream->bytesPerFrame;
}
/************************************************************/
static unsigned long RoundUpToNextPowerOf2( unsigned long n )
static unsigned long RoundUpToNextPowerOf2(unsigned long n)
{
long numBits = 0;
if( ((n-1) & n) == 0) return n; /* Already Power of two. */
while( n > 0 )
{
n= n>>1;
numBits++;
}
return (1<<numBits);
long numBits = 0;
if (((n - 1) & n) == 0)
return n; /* Already Power of two. */
while (n > 0) {
n = n >> 1;
numBits++;
}
return (1 << numBits);
}
/************************************************************
@@ -197,27 +194,27 @@ static unsigned long RoundUpToNextPowerOf2( unsigned long n )
* Allocates PABLIO_Stream structure.
*
*/
PaError OpenAudioStream( PABLIO_Stream **rwblPtr,
const PaStreamParameters *inputParameters,
const PaStreamParameters *outputParameters,
double sampleRate,
PaStreamFlags streamFlags)
PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
const PaStreamParameters * inputParameters,
const PaStreamParameters * outputParameters, double sampleRate, PaStreamFlags streamFlags)
{
long bytesPerSample;
PaError err;
PABLIO_Stream *aStream;
long numFrames;
long bytesPerSample;
PaError err;
PABLIO_Stream *aStream;
long numFrames;
long numBytes;
int channels = 1;
/* Allocate PABLIO_Stream structure for caller. */
aStream = (PABLIO_Stream *) malloc( sizeof(PABLIO_Stream) );
if( aStream == NULL ) return paInsufficientMemory;
memset( aStream, 0, sizeof(PABLIO_Stream) );
/* Allocate PABLIO_Stream structure for caller. */
aStream = (PABLIO_Stream *) malloc(sizeof(PABLIO_Stream));
if (aStream == NULL)
return paInsufficientMemory;
memset(aStream, 0, sizeof(PABLIO_Stream));
/* Initialize PortAudio */
err = Pa_Initialize();
if( err != paNoError ) goto error;
/* Initialize PortAudio */
err = Pa_Initialize();
if (err != paNoError)
goto error;
if (inputParameters) {
channels = inputParameters->channelCount;
@@ -225,81 +222,79 @@ PaError OpenAudioStream( PABLIO_Stream **rwblPtr,
channels = outputParameters->channelCount;
}
numFrames = 4 * FRAMES_PER_BUFFER;
numFrames = RoundUpToNextPowerOf2( numFrames );
numFrames = 4 * FRAMES_PER_BUFFER;
numFrames = RoundUpToNextPowerOf2(numFrames);
bytesPerSample = 2;
aStream->samplesPerFrame = channels;
aStream->bytesPerFrame = bytesPerSample * aStream->samplesPerFrame;
aStream->bytesPerFrame = bytesPerSample * aStream->samplesPerFrame;
/* Initialize Ring Buffers */
/* Initialize Ring Buffers */
if (inputParameters) {
err = PABLIO_InitFIFO( &aStream->inFIFO, numFrames, aStream->bytesPerFrame );
if( err != paNoError ) goto error;
err = PABLIO_InitFIFO(&aStream->inFIFO, numFrames, aStream->bytesPerFrame);
if (err != paNoError)
goto error;
}
if (outputParameters) {
err = PABLIO_InitFIFO( &aStream->outFIFO, numFrames, aStream->bytesPerFrame );
if( err != paNoError ) goto error;
err = PABLIO_InitFIFO(&aStream->outFIFO, numFrames, aStream->bytesPerFrame);
if (err != paNoError)
goto error;
}
/* Make Write FIFO appear full initially. */
numBytes = PaUtil_GetRingBufferWriteAvailable( &aStream->outFIFO );
PaUtil_AdvanceRingBufferWriteIndex( &aStream->outFIFO, numBytes );
numBytes = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
PaUtil_AdvanceRingBufferWriteIndex(&aStream->outFIFO, numBytes);
/* Open a PortAudio stream that we will use to communicate with the underlying
* audio drivers. */
err = Pa_OpenStream(
&aStream->stream,
inputParameters,
outputParameters,
sampleRate,
FRAMES_PER_BUFFER,
streamFlags,
blockingIOCallback,
aStream );
if( err != paNoError ) goto error;
err = Pa_StartStream( aStream->stream );
if( err != paNoError ) goto error;
*rwblPtr = aStream;
return paNoError;
/* Open a PortAudio stream that we will use to communicate with the underlying
* audio drivers. */
err = Pa_OpenStream(&aStream->stream,
inputParameters,
outputParameters, sampleRate, FRAMES_PER_BUFFER, streamFlags, blockingIOCallback, aStream);
if (err != paNoError)
goto error;
error:
CloseAudioStream( aStream );
*rwblPtr = NULL;
return err;
err = Pa_StartStream(aStream->stream);
if (err != paNoError)
goto error;
*rwblPtr = aStream;
return paNoError;
error:
CloseAudioStream(aStream);
*rwblPtr = NULL;
return err;
}
/************************************************************/
PaError CloseAudioStream( PABLIO_Stream *aStream )
PaError CloseAudioStream(PABLIO_Stream * aStream)
{
PaError err;
int bytesEmpty;
int byteSize = aStream->outFIFO.bufferSize;
PaError err;
int bytesEmpty;
int byteSize = aStream->outFIFO.bufferSize;
/* If we are writing data, make sure we play everything written. */
if( byteSize > 0 )
{
bytesEmpty = PaUtil_GetRingBufferWriteAvailable( &aStream->outFIFO );
while( bytesEmpty < byteSize )
{
Pa_Sleep( 10 );
bytesEmpty = PaUtil_GetRingBufferWriteAvailable( &aStream->outFIFO );
}
}
/* If we are writing data, make sure we play everything written. */
if (byteSize > 0) {
bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
while (bytesEmpty < byteSize) {
Pa_Sleep(10);
bytesEmpty = PaUtil_GetRingBufferWriteAvailable(&aStream->outFIFO);
}
}
err = Pa_StopStream( aStream->stream );
if( err != paNoError ) goto error;
err = Pa_CloseStream( aStream->stream );
if( err != paNoError ) goto error;
Pa_Terminate();
err = Pa_StopStream(aStream->stream);
if (err != paNoError)
goto error;
err = Pa_CloseStream(aStream->stream);
if (err != paNoError)
goto error;
Pa_Terminate();
error:
PABLIO_TermFIFO( &aStream->inFIFO );
PABLIO_TermFIFO( &aStream->outFIFO );
free( aStream );
return err;
error:
PABLIO_TermFIFO(&aStream->inFIFO);
PABLIO_TermFIFO(&aStream->outFIFO);
free(aStream);
return err;
}
+20 -24
View File
@@ -2,9 +2,8 @@
#define _PABLIO_H
#ifdef __cplusplus
extern "C"
{
#endif /* __cplusplus */
extern "C" {
#endif /* __cplusplus */
/*
* $Id: pablio.h 1083 2006-08-23 07:30:49Z rossb $
@@ -57,15 +56,13 @@ extern "C"
#include <string.h>
typedef struct
{
PaUtilRingBuffer inFIFO;
PaUtilRingBuffer outFIFO;
PaStream *stream;
int bytesPerFrame;
int samplesPerFrame;
}
PABLIO_Stream;
typedef struct {
PaUtilRingBuffer inFIFO;
PaUtilRingBuffer outFIFO;
PaStream *stream;
int bytesPerFrame;
int samplesPerFrame;
} PABLIO_Stream;
/* Values for flags for OpenAudioStream(). */
#define PABLIO_READ (1<<0)
@@ -78,25 +75,25 @@ PABLIO_Stream;
* Write data to ring buffer.
* Will not return until all the data has been written.
*/
long WriteAudioStream( PABLIO_Stream *aStream, void *data, long numFrames );
long WriteAudioStream(PABLIO_Stream * aStream, void *data, long numFrames);
/************************************************************
* Read data from ring buffer.
* Will not return until all the data has been read.
*/
long ReadAudioStream( PABLIO_Stream *aStream, void *data, long numFrames );
long ReadAudioStream(PABLIO_Stream * aStream, void *data, long numFrames);
/************************************************************
* Return the number of frames that could be written to the stream without
* having to wait.
*/
long GetAudioStreamWriteable( PABLIO_Stream *aStream );
long GetAudioStreamWriteable(PABLIO_Stream * aStream);
/************************************************************
* Return the number of frames that are available to be read from the
* stream without having to wait.
*/
long GetAudioStreamReadable( PABLIO_Stream *aStream );
long GetAudioStreamReadable(PABLIO_Stream * aStream);
/************************************************************
* Opens a PortAudio stream with default characteristics.
@@ -106,15 +103,14 @@ long GetAudioStreamReadable( PABLIO_Stream *aStream );
* PABLIO_READ, PABLIO_WRITE, or PABLIO_READ_WRITE,
* and either PABLIO_MONO or PABLIO_STEREO
*/
PaError OpenAudioStream( PABLIO_Stream **rwblPtr,
const PaStreamParameters *inputParameters,
const PaStreamParameters *outputParameters,
double sampleRate,
PaStreamCallbackFlags statusFlags);
PaError OpenAudioStream(PABLIO_Stream ** rwblPtr,
const PaStreamParameters * inputParameters,
const PaStreamParameters * outputParameters,
double sampleRate, PaStreamCallbackFlags statusFlags);
PaError CloseAudioStream( PABLIO_Stream *aStream );
PaError CloseAudioStream(PABLIO_Stream * aStream);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _PABLIO_H */
#endif /* __cplusplus */
#endif /* _PABLIO_H */
File diff suppressed because it is too large Load Diff
+166 -205
View File
@@ -50,137 +50,110 @@ extern "C" {
#ifndef __inline__
#define __inline__ __inline
#endif
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef unsigned __int16 uint16_t;
typedef unsigned __int8 uint8_t;
typedef __int16 int16_t;
typedef __int32 int32_t;
typedef unsigned __int16 uint16_t;
#endif
#if defined(__i386__)
/*! \brief Find the bit position of the highest set bit in a word
\param bits The word to be searched
\return The bit number of the highest set bit, or -1 if the word is zero. */
static __inline__ int top_bit(unsigned int bits)
{
int res;
static __inline__ int top_bit(unsigned int bits) {
int res;
__asm__ __volatile__(" movl $-1,%%edx;\n"
" bsrl %%eax,%%edx;\n"
: "=d" (res)
: "a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*/
__asm__ __volatile__(" movl $-1,%%edx;\n" " bsrl %%eax,%%edx;\n":"=d"(res)
:"a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*//*! \brief Find the bit position of the lowest set bit in a word
\param bits The word to be searched
\return The bit number of the lowest set bit, or -1 if the word is zero. */
static __inline__ int bottom_bit(unsigned int bits) {
int res;
/*! \brief Find the bit position of the lowest set bit in a word
\param bits The word to be searched
\return The bit number of the lowest set bit, or -1 if the word is zero. */
static __inline__ int bottom_bit(unsigned int bits)
{
int res;
__asm__ __volatile__(" movl $-1,%%edx;\n"
" bsfl %%eax,%%edx;\n"
: "=d" (res)
: "a" (bits));
return res;
}
__asm__ __volatile__(" movl $-1,%%edx;\n" " bsfl %%eax,%%edx;\n":"=d"(res)
:"a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*/
#elif defined(__x86_64__)
static __inline__ int top_bit(unsigned int bits)
{
int res;
static __inline__ int top_bit(unsigned int bits) {
int res;
__asm__ __volatile__(" movq $-1,%%rdx;\n"
" bsrq %%rax,%%rdx;\n"
: "=d" (res)
: "a" (bits));
return res;
}
__asm__ __volatile__(" movq $-1,%%rdx;\n" " bsrq %%rax,%%rdx;\n":"=d"(res)
:"a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*/
static __inline__ int bottom_bit(unsigned int bits) {
int res;
static __inline__ int bottom_bit(unsigned int bits)
{
int res;
__asm__ __volatile__(" movq $-1,%%rdx;\n"
" bsfq %%rax,%%rdx;\n"
: "=d" (res)
: "a" (bits));
return res;
}
__asm__ __volatile__(" movq $-1,%%rdx;\n" " bsfq %%rax,%%rdx;\n":"=d"(res)
:"a" (bits));
return res;
}
/*- End of function --------------------------------------------------------*/
#else
static __inline__ int top_bit(unsigned int bits)
{
int i;
if (bits == 0)
return -1;
i = 0;
if (bits & 0xFFFF0000)
{
bits &= 0xFFFF0000;
i += 16;
}
if (bits & 0xFF00FF00)
{
bits &= 0xFF00FF00;
i += 8;
}
if (bits & 0xF0F0F0F0)
{
bits &= 0xF0F0F0F0;
i += 4;
}
if (bits & 0xCCCCCCCC)
{
bits &= 0xCCCCCCCC;
i += 2;
}
if (bits & 0xAAAAAAAA)
{
bits &= 0xAAAAAAAA;
i += 1;
}
return i;
}
static __inline__ int top_bit(unsigned int bits) {
int i;
if (bits == 0)
return -1;
i = 0;
if (bits & 0xFFFF0000) {
bits &= 0xFFFF0000;
i += 16;
}
if (bits & 0xFF00FF00) {
bits &= 0xFF00FF00;
i += 8;
}
if (bits & 0xF0F0F0F0) {
bits &= 0xF0F0F0F0;
i += 4;
}
if (bits & 0xCCCCCCCC) {
bits &= 0xCCCCCCCC;
i += 2;
}
if (bits & 0xAAAAAAAA) {
bits &= 0xAAAAAAAA;
i += 1;
}
return i;
}
/*- End of function --------------------------------------------------------*/
static __inline__ int bottom_bit(unsigned int bits)
{
int i;
if (bits == 0)
return -1;
i = 32;
if (bits & 0x0000FFFF)
{
bits &= 0x0000FFFF;
i -= 16;
}
if (bits & 0x00FF00FF)
{
bits &= 0x00FF00FF;
i -= 8;
}
if (bits & 0x0F0F0F0F)
{
bits &= 0x0F0F0F0F;
i -= 4;
}
if (bits & 0x33333333)
{
bits &= 0x33333333;
i -= 2;
}
if (bits & 0x55555555)
{
bits &= 0x55555555;
i -= 1;
}
return i;
}
static __inline__ int bottom_bit(unsigned int bits) {
int i;
if (bits == 0)
return -1;
i = 32;
if (bits & 0x0000FFFF) {
bits &= 0x0000FFFF;
i -= 16;
}
if (bits & 0x00FF00FF) {
bits &= 0x00FF00FF;
i -= 8;
}
if (bits & 0x0F0F0F0F) {
bits &= 0x0F0F0F0F;
i -= 4;
}
if (bits & 0x33333333) {
bits &= 0x33333333;
i -= 2;
}
if (bits & 0x55555555) {
bits &= 0x55555555;
i -= 1;
}
return i;
}
/*- End of function --------------------------------------------------------*/
#endif
@@ -194,7 +167,7 @@ static __inline__ int bottom_bit(unsigned int bits)
* segment, but a little inline assembly can fix that on an i386, x86_64 and
* many other modern processors.
*/
/*
* Mu-law is basically as follows:
*
@@ -222,66 +195,61 @@ static __inline__ int bottom_bit(unsigned int bits)
*/
//#define ULAW_ZEROTRAP /* turn on the trap as per the MIL-STD */
#define ULAW_BIAS 0x84 /* Bias for linear code. */
#define ULAW_BIAS 0x84 /* Bias for linear code. */
/*! \brief Encode a linear sample to u-law
\param linear The sample to encode.
\return The u-law value.
*/
static __inline__ uint8_t linear_to_ulaw(int linear)
{
uint8_t u_val;
int mask;
int seg;
static __inline__ uint8_t linear_to_ulaw(int linear) {
uint8_t u_val;
int mask;
int seg;
/* Get the sign and the magnitude of the value. */
if (linear < 0)
{
linear = ULAW_BIAS - linear;
mask = 0x7F;
}
else
{
linear = ULAW_BIAS + linear;
mask = 0xFF;
}
/* Get the sign and the magnitude of the value. */
if (linear < 0) {
linear = ULAW_BIAS - linear;
mask = 0x7F;
} else {
linear = ULAW_BIAS + linear;
mask = 0xFF;
}
seg = top_bit(linear | 0xFF) - 7;
seg = top_bit(linear | 0xFF) - 7;
/*
* Combine the sign, segment, quantization bits,
* and complement the code word.
*/
if (seg >= 8)
u_val = (uint8_t) (0x7F ^ mask);
else
u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask);
/*
* Combine the sign, segment, quantization bits,
* and complement the code word.
*/
if (seg >= 8)
u_val = (uint8_t) (0x7F ^ mask);
else
u_val = (uint8_t) (((seg << 4) | ((linear >> (seg + 3)) & 0xF)) ^ mask);
#ifdef ULAW_ZEROTRAP
/* Optional ITU trap */
if (u_val == 0)
u_val = 0x02;
/* Optional ITU trap */
if (u_val == 0)
u_val = 0x02;
#endif
return u_val;
}
return u_val;
}
/*- End of function --------------------------------------------------------*/
/*! \brief Decode an u-law sample to a linear value.
\param ulaw The u-law sample to decode.
\return The linear value.
*/
static __inline__ int16_t ulaw_to_linear(uint8_t ulaw)
{
int t;
/* Complement to obtain normal u-law value. */
ulaw = ~ulaw;
/*
* Extract and bias the quantization bits. Then
* shift up by the segment number and subtract out the bias.
*/
t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4);
return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS));
}
static __inline__ int16_t ulaw_to_linear(uint8_t ulaw) {
int t;
/* Complement to obtain normal u-law value. */
ulaw = ~ulaw;
/*
* Extract and bias the quantization bits. Then
* shift up by the segment number and subtract out the bias.
*/
t = (((ulaw & 0x0F) << 3) + ULAW_BIAS) << (((int) ulaw & 0x70) >> 4);
return (int16_t) ((ulaw & 0x80) ? (ULAW_BIAS - t) : (t - ULAW_BIAS));
}
/*- End of function --------------------------------------------------------*/
/*
@@ -308,71 +276,64 @@ static __inline__ int16_t ulaw_to_linear(uint8_t ulaw)
\param linear The sample to encode.
\return The A-law value.
*/
static __inline__ uint8_t linear_to_alaw(int linear)
{
int mask;
int seg;
if (linear >= 0)
{
/* Sign (bit 7) bit = 1 */
mask = ALAW_AMI_MASK | 0x80;
}
else
{
/* Sign (bit 7) bit = 0 */
mask = ALAW_AMI_MASK;
linear = -linear - 8;
}
static __inline__ uint8_t linear_to_alaw(int linear) {
int mask;
int seg;
/* Convert the scaled magnitude to segment number. */
seg = top_bit(linear | 0xFF) - 7;
if (seg >= 8)
{
if (linear >= 0)
{
/* Out of range. Return maximum value. */
return (uint8_t) (0x7F ^ mask);
}
/* We must be just a tiny step below zero */
return (uint8_t) (0x00 ^ mask);
}
/* Combine the sign, segment, and quantization bits. */
return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask);
}
if (linear >= 0) {
/* Sign (bit 7) bit = 1 */
mask = ALAW_AMI_MASK | 0x80;
} else {
/* Sign (bit 7) bit = 0 */
mask = ALAW_AMI_MASK;
linear = -linear - 8;
}
/* Convert the scaled magnitude to segment number. */
seg = top_bit(linear | 0xFF) - 7;
if (seg >= 8) {
if (linear >= 0) {
/* Out of range. Return maximum value. */
return (uint8_t) (0x7F ^ mask);
}
/* We must be just a tiny step below zero */
return (uint8_t) (0x00 ^ mask);
}
/* Combine the sign, segment, and quantization bits. */
return (uint8_t) (((seg << 4) | ((linear >> ((seg) ? (seg + 3) : 4)) & 0x0F)) ^ mask);
}
/*- End of function --------------------------------------------------------*/
/*! \brief Decode an A-law sample to a linear value.
\param alaw The A-law sample to decode.
\return The linear value.
*/
static __inline__ int16_t alaw_to_linear(uint8_t alaw)
{
int i;
int seg;
static __inline__ int16_t alaw_to_linear(uint8_t alaw) {
int i;
int seg;
alaw ^= ALAW_AMI_MASK;
i = ((alaw & 0x0F) << 4);
seg = (((int) alaw & 0x70) >> 4);
if (seg)
i = (i + 0x108) << (seg - 1);
else
i += 8;
return (int16_t) ((alaw & 0x80) ? i : -i);
}
alaw ^= ALAW_AMI_MASK;
i = ((alaw & 0x0F) << 4);
seg = (((int) alaw & 0x70) >> 4);
if (seg)
i = (i + 0x108) << (seg - 1);
else
i += 8;
return (int16_t) ((alaw & 0x80) ? i : -i);
}
/*- End of function --------------------------------------------------------*/
/*! \brief Transcode from A-law to u-law, using the procedure defined in G.711.
\param alaw The A-law sample to transcode.
\return The best matching u-law value.
*/
uint8_t alaw_to_ulaw(uint8_t alaw);
uint8_t alaw_to_ulaw(uint8_t alaw);
/*! \brief Transcode from u-law to A-law, using the procedure defined in G.711.
\param alaw The u-law sample to transcode.
\return The best matching A-law value.
*/
uint8_t ulaw_to_alaw(uint8_t ulaw);
uint8_t ulaw_to_alaw(uint8_t ulaw);
#ifdef __cplusplus
}
File diff suppressed because it is too large Load Diff
@@ -34,7 +34,7 @@ typedef unsigned __int32 u_int32_t;
#ifdef WANPIPE_TDM_API
#include <wanpipe_tdm_api.h> //for TDMV API
#endif
#include <sang_status_defines.h>//return codes
#include <sang_status_defines.h> //return codes
#include <sang_api.h> //for IOCTL codes
#include <sdla_te1_pmc.h> //RBS definitions
#include <sdla_te1.h> //TE1 macros
@@ -94,7 +94,7 @@ sng_fd_t sangoma_create_socket_by_name(char *device, char *card);
/* Open Span/Chan devices
* open_tdmapi_span_chan: open device based on span chan values
* sangoma_open_tdmapi_span: open first available device on span
*/
*/
sng_fd_t sangoma_open_tdmapi_span_chan(int span, int chan);
sng_fd_t sangoma_open_tdmapi_span(int span);
@@ -104,67 +104,65 @@ sng_fd_t sangoma_open_tdmapi_span(int span);
/* Device Rx/Tx functions
* writemsg_tdm: tx header + data from separate buffers
* readmsg_tdm: rx header + data to separate buffers
*/
int sangoma_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen,
void *databuf, unsigned short datalen, int flag);
int sangoma_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen,
void *databuf, int datalen, int flag);
*/
int sangoma_writemsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, unsigned short datalen, int flag);
int sangoma_readmsg_tdm(sng_fd_t fd, void *hdrbuf, int hdrlen, void *databuf, int datalen, int flag);
#define sangoma_readmsg_socket sangoma_readmsg_tdm
#define sangoma_sendmsg_socket sangoma_writemsg_tdm
#ifdef WANPIPE_TDM_API
void sangoma_socket_close(sng_fd_t *sp);
void sangoma_socket_close(sng_fd_t * sp);
int sangoma_socket_waitfor(sng_fd_t fd, int timeout, int flags);
/* Get Full TDM API configuration per chan */
int sangoma_get_full_cfg(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_get_full_cfg(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* Get/Set TDM Codec per chan */
int sangoma_tdm_set_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int codec);
int sangoma_tdm_get_codec(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_set_codec(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int codec);
int sangoma_tdm_get_codec(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* Get/Set USR Tx/Rx Period in milliseconds */
int sangoma_tdm_set_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int period);
int sangoma_tdm_get_usr_period(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_set_usr_period(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int period);
int sangoma_tdm_get_usr_period(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* Get user MTU/MRU values in bytes */
int sangoma_tdm_get_usr_mtu_mru(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_get_usr_mtu_mru(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* Not supported yet */
int sangoma_tdm_set_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int power);
int sangoma_tdm_get_power_level(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_set_power_level(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int power);
int sangoma_tdm_get_power_level(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* Flush buffers from current channel */
int sangoma_tdm_flush_bufs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_flush_bufs(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
int sangoma_tdm_enable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, int poll_in_sec);
int sangoma_tdm_disable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_enable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, int poll_in_sec);
int sangoma_tdm_disable_rbs_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
int sangoma_tdm_write_rbs(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api, unsigned char rbs);
int sangoma_tdm_write_rbs(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api, unsigned char rbs);
int sangoma_tdm_read_event(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_read_event(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* DTMF Detection on Octasic chip */
int sangoma_tdm_enable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_disable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_enable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
int sangoma_tdm_disable_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* DTMF Detection on A200 (SLIC) chip */
int sangoma_tdm_enable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_disable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_enable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
int sangoma_tdm_disable_rm_dtmf_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
/* On/Off hook events on A200 (Analog) card */
int sangoma_tdm_enable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_enable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
int sangoma_tdm_disable_rxhook_events(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_get_fe_alarms(sng_fd_t fd, wanpipe_tdm_api_t * tdm_api);
#ifndef LIBSANGOMA_GET_HWCODING
#define LIBSANGOMA_GET_HWCODING 1
#endif
int sangoma_tdm_get_hw_coding(int fd, wanpipe_tdm_api_t *tdm_api);
int sangoma_tdm_get_hw_coding(int fd, wanpipe_tdm_api_t * tdm_api);
#endif /* WANPIPE_TDM_API */
#endif /* WANPIPE_TDM_API */
#endif
@@ -23,20 +23,21 @@
static __inline int gettimeofday(struct timeval *tp, void *nothing)
{
#ifdef WITHOUT_MM_LIB
SYSTEMTIME st;
time_t tt;
struct tm tmtm;
/* mktime converts local to UTC */
GetLocalTime (&st);
tmtm.tm_sec = st.wSecond;
tmtm.tm_min = st.wMinute;
tmtm.tm_hour = st.wHour;
tmtm.tm_mday = st.wDay;
tmtm.tm_mon = st.wMonth - 1;
tmtm.tm_year = st.wYear - 1900; tmtm.tm_isdst = -1;
tt = mktime (&tmtm);
tp->tv_sec = tt;
tp->tv_usec = st.wMilliseconds * 1000;
SYSTEMTIME st;
time_t tt;
struct tm tmtm;
/* mktime converts local to UTC */
GetLocalTime(&st);
tmtm.tm_sec = st.wSecond;
tmtm.tm_min = st.wMinute;
tmtm.tm_hour = st.wHour;
tmtm.tm_mday = st.wDay;
tmtm.tm_mon = st.wMonth - 1;
tmtm.tm_year = st.wYear - 1900;
tmtm.tm_isdst = -1;
tt = mktime(&tmtm);
tp->tv_sec = tt;
tp->tv_usec = st.wMilliseconds * 1000;
#else
/**
** The earlier time calculations using GetLocalTime
@@ -44,18 +45,18 @@ static __inline int gettimeofday(struct timeval *tp, void *nothing)
** of multimedia apis offer a better time resolution
** of 1ms.Need to link against winmm.lib for this
**/
unsigned long Ticks = 0;
unsigned long Sec =0;
unsigned long Usec = 0;
Ticks = timeGetTime();
unsigned long Ticks = 0;
unsigned long Sec = 0;
unsigned long Usec = 0;
Ticks = timeGetTime();
Sec = Ticks/1000;
Usec = (Ticks - (Sec*1000))*1000;
tp->tv_sec = Sec;
tp->tv_usec = Usec;
Sec = Ticks / 1000;
Usec = (Ticks - (Sec * 1000)) * 1000;
tp->tv_sec = Sec;
tp->tv_usec = Usec;
#endif /* WITHOUT_MM_LIB */
(void)nothing;
return 0;
(void) nothing;
return 0;
}
#endif /* WIN32 */
#endif /* HAVE_GETTIMEOFDAY */
@@ -84,37 +85,37 @@ static struct sangoma_pri_event_list SANGOMA_PRI_EVENT_LIST[] = {
char *sangoma_pri_event_str(sangoma_pri_event_t event_id)
{
{
return SANGOMA_PRI_EVENT_LIST[event_id].name;
}
static int __pri_sangoma_read(struct pri *pri, void *buf, int buflen)
{
unsigned char tmpbuf[sizeof(wp_tdm_api_rx_hdr_t)];
/* NOTE: This code will be different for A104
* A104 receives data + 2byte CRC + 1 byte flag
* A101/2 receives data only */
int res = sangoma_readmsg_socket((sng_fd_t)(pri->fd),
tmpbuf, sizeof(wp_tdm_api_rx_hdr_t),
buf, buflen,
0);
if (res > 0){
* A101/2 receives data only */
int res = sangoma_readmsg_socket((sng_fd_t) (pri->fd),
tmpbuf, sizeof(wp_tdm_api_rx_hdr_t),
buf, buflen,
0);
if (res > 0) {
#ifdef WANPIPE_LEGACY_A104
/* Prior 2.3.4 release A104 API passed up
* 3 extra bytes: 2 CRC + 1 FLAG,
* PRI is expecting only 2 CRC bytes, thus we
* must remove 1 flag byte */
* 3 extra bytes: 2 CRC + 1 FLAG,
* PRI is expecting only 2 CRC bytes, thus we
* must remove 1 flag byte */
res--;
#else
/* Add 2 byte CRC and set it to ZERO */
memset(&((unsigned char*)buf)[res],0,2);
res+=2;
/* Add 2 byte CRC and set it to ZERO */
memset(&((unsigned char *) buf)[res], 0, 2);
res += 2;
#endif
}else{
res=0;
} else {
res = 0;
}
return res;
@@ -126,25 +127,23 @@ static int __pri_sangoma_write(struct pri *pri, void *buf, int buflen)
int res;
memset(&tmpbuf[0],0,sizeof(wp_tdm_api_rx_hdr_t));
memset(&tmpbuf[0], 0, sizeof(wp_tdm_api_rx_hdr_t));
if (buflen < 1){
if (buflen < 1) {
/* HDLC Frame must be greater than 2byte CRC */
fprintf(stderr,"%s: Got short frame %i\n",__FUNCTION__,buflen);
fprintf(stderr, "%s: Got short frame %i\n", __FUNCTION__, buflen);
return 0;
}
/* FIXME: This might cause problems with other libraries
* We must remove 2 bytes from buflen because
* libpri sends 2 fake CRC bytes */
res=sangoma_sendmsg_socket((sng_fd_t)(pri->fd),
tmpbuf, sizeof(wp_tdm_api_rx_hdr_t),
buf, (unsigned short)buflen-2,
0);
if (res > 0){
res=buflen;
res = sangoma_sendmsg_socket((sng_fd_t) (pri->fd),
tmpbuf, sizeof(wp_tdm_api_rx_hdr_t), buf, (unsigned short) buflen - 2, 0);
if (res > 0) {
res = buflen;
}
return res;
}
@@ -155,10 +154,10 @@ int sangoma_init_pri(struct sangoma_pri *spri, int span, int dchan, int swtype,
memset(spri, 0, sizeof(struct sangoma_pri));
if((dfd = sangoma_open_tdmapi_span_chan(span, dchan)) < 0) {
if ((dfd = sangoma_open_tdmapi_span_chan(span, dchan)) < 0) {
fprintf(stderr, "Unable to open DCHAN %d for span %d (%s)\n", dchan, span, strerror(errno));
} else {
if ((spri->pri = pri_new_cb((int)dfd, node, swtype, __pri_sangoma_read, __pri_sangoma_write, NULL))){
if ((spri->pri = pri_new_cb((int) dfd, node, swtype, __pri_sangoma_read, __pri_sangoma_write, NULL))) {
spri->span = span;
pri_set_debug(spri->pri, debug);
ret = 0;
@@ -173,10 +172,10 @@ int sangoma_init_pri(struct sangoma_pri *spri, int span, int dchan, int swtype,
int sangoma_one_loop(struct sangoma_pri *spri)
{
fd_set rfds, efds;
struct timeval now = {0,0}, *next;
struct timeval now = { 0, 0 }, *next;
pri_event *event;
int sel;
int sel;
if (spri->on_loop) {
spri->on_loop(spri);
}
@@ -223,10 +222,11 @@ int sangoma_one_loop(struct sangoma_pri *spri)
if (event) {
event_handler handler;
/* 0 is catchall event handler */
if ((handler = spri->eventmap[event->e] ? spri->eventmap[event->e] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) {
if ((handler =
spri->eventmap[event->e] ? spri->eventmap[event->e] : spri->eventmap[0] ? spri->eventmap[0] : NULL)) {
handler(spri, event->e, event);
} else {
fprintf(stderr,"No event handler found for event %d.\n", event->e);
fprintf(stderr, "No event handler found for event %d.\n", event->e);
}
}
@@ -237,23 +237,22 @@ int sangoma_run_pri(struct sangoma_pri *spri)
{
int ret = 0;
for (;;){
ret=sangoma_one_loop(spri);
if (ret < 0){
for (;;) {
ret = sangoma_one_loop(spri);
if (ret < 0) {
#ifndef WIN32 //This needs to be adressed fror WIN32 still
if (errno == EINTR){
#ifndef WIN32 //This needs to be adressed fror WIN32 still
if (errno == EINTR) {
/* Igonore an interrupted system call */
continue;
}
#endif
printf("Error = %i\n",ret);
#endif
printf("Error = %i\n", ret);
perror("Sangoma Run Pri: ");
break;
break;
}
}
return ret;
}
@@ -50,7 +50,7 @@ typedef enum {
typedef enum {
SANGOMA_PRI_SWITCH_UNKNOWN = PRI_SWITCH_UNKNOWN,
SANGOMA_PRI_SWITCH_NI2 = PRI_SWITCH_NI2,
SANGOMA_PRI_SWITCH_NI2 = PRI_SWITCH_NI2,
SANGOMA_PRI_SWITCH_DMS100 = PRI_SWITCH_DMS100,
SANGOMA_PRI_SWITCH_LUCENT5E = PRI_SWITCH_LUCENT5E,
SANGOMA_PRI_SWITCH_ATT4ESS = PRI_SWITCH_ATT4ESS,
@@ -67,8 +67,8 @@ typedef enum {
} sangoma_pri_flag_t;
struct sangoma_pri;
typedef int (*event_handler)(struct sangoma_pri *, sangoma_pri_event_t, pri_event *);
typedef int (*loop_handler)(struct sangoma_pri *);
typedef int (*event_handler) (struct sangoma_pri *, sangoma_pri_event_t, pri_event *);
typedef int (*loop_handler) (struct sangoma_pri *);
#define MAX_EVENT 18
struct sangoma_pri {
@@ -77,7 +77,7 @@ struct sangoma_pri {
int dchan;
unsigned int flags;
void *private_info;
event_handler eventmap[MAX_EVENT+1];
event_handler eventmap[MAX_EVENT + 1];
loop_handler on_loop;
};
@@ -11,228 +11,159 @@
#ifndef _WIN_API_COMMON_H
#define _WIN_API_COMMON_H
static
int
tdmv_api_ioctl(
HANDLE fd,
wanpipe_tdm_api_cmd_t *tdm_api_cmd
)
static
int tdmv_api_ioctl(HANDLE fd, wanpipe_tdm_api_cmd_t * tdm_api_cmd)
{
DWORD ln;
unsigned char id = 0;
int err = 0;
DWORD ln;
unsigned char id = 0;
int err = 0;
wan_udp.wan_udphdr_request_reply = 0x01;
wan_udp.wan_udphdr_id = id;
wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
wan_udp.wan_udphdr_id = id;
wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL;
wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t);
wan_udp.wan_udphdr_command = WAN_TDMV_API_IOCTL;
wan_udp.wan_udphdr_data_len = sizeof(wanpipe_tdm_api_cmd_t);
//copy data from caller's buffer to driver's buffer
memcpy( wan_udp.wan_udphdr_data,
(void*)tdm_api_cmd,
sizeof(wanpipe_tdm_api_cmd_t));
memcpy(wan_udp.wan_udphdr_data, (void *) tdm_api_cmd, sizeof(wanpipe_tdm_api_cmd_t));
if(DeviceIoControl(
fd,
IoctlManagementCommand,
(LPVOID)&wan_udp,
sizeof(wan_udp_hdr_t),
(LPVOID)&wan_udp,
sizeof(wan_udp_hdr_t),
(LPDWORD)(&ln),
(LPOVERLAPPED)NULL
) == FALSE){
if (DeviceIoControl(fd,
IoctlManagementCommand,
(LPVOID) & wan_udp,
sizeof(wan_udp_hdr_t),
(LPVOID) & wan_udp, sizeof(wan_udp_hdr_t), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
//actual ioctl failed
err = 1;
prn(1, "Error: tdmv_api_ioctl(): DeviceIoControl failed!!\n");
return err;
}else{
} else {
err = 0;
}
if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){
if (wan_udp.wan_udphdr_return_code != WAN_CMD_OK) {
//ioctl ok, but command failed
prn(1, "Error: tdmv_api_ioctl(): command failed! Return code: 0x%X.\n",
wan_udp.wan_udphdr_return_code);
prn(1, "Error: tdmv_api_ioctl(): command failed! Return code: 0x%X.\n", wan_udp.wan_udphdr_return_code);
return 2;
}
//copy data from driver's buffer to caller's buffer
memcpy( (void*)tdm_api_cmd,
wan_udp.wan_udphdr_data,
sizeof(wanpipe_tdm_api_cmd_t));
memcpy((void *) tdm_api_cmd, wan_udp.wan_udphdr_data, sizeof(wanpipe_tdm_api_cmd_t));
return 0;
}
static
int
wanpipe_api_ioctl(
HANDLE fd,
wan_cmd_api_t *api_cmd
)
static
int wanpipe_api_ioctl(HANDLE fd, wan_cmd_api_t * api_cmd)
{
DWORD ln;
unsigned char id = 0;
int err = 0;
DWORD ln;
unsigned char id = 0;
int err = 0;
wan_udp.wan_udphdr_request_reply = 0x01;
wan_udp.wan_udphdr_id = id;
wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
wan_udp.wan_udphdr_id = id;
wan_udp.wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
wan_udp.wan_udphdr_command = SIOC_WANPIPE_API;
wan_udp.wan_udphdr_data_len = sizeof(wan_cmd_api_t);
wan_udp.wan_udphdr_command = SIOC_WANPIPE_API;
wan_udp.wan_udphdr_data_len = sizeof(wan_cmd_api_t);
//copy data from caller's buffer to driver's buffer
memcpy( wan_udp.wan_udphdr_data,
(void*)api_cmd,
sizeof(wan_cmd_api_t));
memcpy(wan_udp.wan_udphdr_data, (void *) api_cmd, sizeof(wan_cmd_api_t));
if(DeviceIoControl(
fd,
IoctlManagementCommand,
(LPVOID)&wan_udp,
sizeof(wan_udp_hdr_t),
(LPVOID)&wan_udp,
sizeof(wan_udp_hdr_t),
(LPDWORD)(&ln),
(LPOVERLAPPED)NULL
) == FALSE){
if (DeviceIoControl(fd,
IoctlManagementCommand,
(LPVOID) & wan_udp,
sizeof(wan_udp_hdr_t),
(LPVOID) & wan_udp, sizeof(wan_udp_hdr_t), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
err = 1;
prn(1, "Error: wanpipe_api_ioctl(): DeviceIoControl failed!!\n");
return err;
}else{
} else {
err = 0;
}
if(wan_udp.wan_udphdr_return_code != WAN_CMD_OK){
prn(1, "Error: wanpipe_api_ioctl(): command failed! Return code: 0x%X.\n",
wan_udp.wan_udphdr_return_code);
if (wan_udp.wan_udphdr_return_code != WAN_CMD_OK) {
prn(1, "Error: wanpipe_api_ioctl(): command failed! Return code: 0x%X.\n", wan_udp.wan_udphdr_return_code);
return 2;
}
//copy data from driver's buffer to caller's buffer
memcpy( (void*)api_cmd,
wan_udp.wan_udphdr_data,
sizeof(wan_cmd_api_t));
memcpy((void *) api_cmd, wan_udp.wan_udphdr_data, sizeof(wan_cmd_api_t));
return 0;
}
// Blocking read command. If used after DoApiPollCommand(),
// it will return immediatly, without blocking.
static
USHORT
DoReadCommand(
HANDLE drv,
RX_DATA_STRUCT * pRx
)
static USHORT DoReadCommand(HANDLE drv, RX_DATA_STRUCT * pRx)
{
DWORD ln;
if (DeviceIoControl(
drv,
IoctlReadCommand,
(LPVOID)NULL,
0L,
(LPVOID)pRx,
sizeof(RX_DATA_STRUCT),
(LPDWORD)(&ln),
(LPOVERLAPPED)NULL
) == FALSE){
if (DeviceIoControl(drv,
IoctlReadCommand,
(LPVOID) NULL,
0L, (LPVOID) pRx, sizeof(RX_DATA_STRUCT), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
//check messages log
prn(1, "Error: DoReadCommand(): DeviceIoControl failed!\n");
return 1;
}else{
} else {
return 0;
}
}
// Blocking write command. If used after DoApiPollCommand(),
// it will return immediatly, without blocking.
static
UCHAR
DoWriteCommand(
HANDLE drv,
TX_DATA_STRUCT * pTx
)
static UCHAR DoWriteCommand(HANDLE drv, TX_DATA_STRUCT * pTx)
{
DWORD ln;
if(DeviceIoControl(
drv,
IoctlWriteCommand,
(LPVOID)pTx,
(ULONG)sizeof(TX_DATA_STRUCT),
(LPVOID)pTx,
sizeof(TX_DATA_STRUCT),
(LPDWORD)(&ln),
(LPOVERLAPPED)NULL
) == FALSE){
if (DeviceIoControl(drv,
IoctlWriteCommand,
(LPVOID) pTx,
(ULONG) sizeof(TX_DATA_STRUCT),
(LPVOID) pTx, sizeof(TX_DATA_STRUCT), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
//check messages log
prn(1, "Error: DoWriteCommand(): DeviceIoControl failed!\n");
return 1;
}else{
} else {
return 0;
}
}
// Blocking API Poll command.
static
USHORT
DoApiPollCommand(
HANDLE drv,
API_POLL_STRUCT *api_poll_ptr
)
static USHORT DoApiPollCommand(HANDLE drv, API_POLL_STRUCT * api_poll_ptr)
{
DWORD ln;
if (DeviceIoControl(
drv,
IoctlApiPoll,
(LPVOID)NULL,
0L,
(LPVOID)api_poll_ptr,
sizeof(API_POLL_STRUCT),
(LPDWORD)(&ln),
(LPOVERLAPPED)NULL
) == FALSE){
if (DeviceIoControl(drv,
IoctlApiPoll,
(LPVOID) NULL,
0L,
(LPVOID) api_poll_ptr,
sizeof(API_POLL_STRUCT), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
//check messages log
prn(1, "Error: DoApiPollCommand(): DeviceIoControl failed!\n");
return 1;
}else{
} else {
return 0;
}
}
static
int
DoManagementCommand(
HANDLE drv,
wan_udp_hdr_t* wan_udp
)
int DoManagementCommand(HANDLE drv, wan_udp_hdr_t * wan_udp)
{
DWORD ln;
static unsigned char id = 0;
static unsigned char id = 0;
wan_udp->wan_udphdr_request_reply = 0x01;
wan_udp->wan_udphdr_id = id++;
wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
wan_udp->wan_udphdr_return_code = WAN_UDP_TIMEOUT_CMD;
if(DeviceIoControl(
drv,
IoctlManagementCommand,
(LPVOID)wan_udp,
sizeof(wan_udp_hdr_t),
(LPVOID)wan_udp,
sizeof(wan_udp_hdr_t),
(LPDWORD)(&ln),
(LPOVERLAPPED)NULL
) == FALSE){
if (DeviceIoControl(drv,
IoctlManagementCommand,
(LPVOID) wan_udp,
sizeof(wan_udp_hdr_t),
(LPVOID) wan_udp, sizeof(wan_udp_hdr_t), (LPDWORD) (&ln), (LPOVERLAPPED) NULL) == FALSE) {
//check messages log
prn(1, "Error: DoManagementCommand(): DeviceIoControl failed!\n");
return 1;
}else{
} else {
return 0;
}
}
File diff suppressed because it is too large Load Diff
+39 -43
View File
@@ -16,38 +16,35 @@
#include <stdint.h>
enum e_sigboost_event_id_values
{
SIGBOOST_EVENT_CALL_START = 0x80, /*128*/
SIGBOOST_EVENT_CALL_START_ACK = 0x81, /*129*/
SIGBOOST_EVENT_CALL_START_NACK = 0x82, /*130*/
SIGBOOST_EVENT_CALL_START_NACK_ACK = 0x83, /*131*/
SIGBOOST_EVENT_CALL_ANSWERED = 0x84, /*132*/
SIGBOOST_EVENT_CALL_STOPPED = 0x85, /*133*/
SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134*/
SIGBOOST_EVENT_SYSTEM_RESTART = 0x87, /*135*/
SIGBOOST_EVENT_HEARTBEAT = 0x88, /*136*/
enum e_sigboost_event_id_values {
SIGBOOST_EVENT_CALL_START = 0x80, /*128 */
SIGBOOST_EVENT_CALL_START_ACK = 0x81, /*129 */
SIGBOOST_EVENT_CALL_START_NACK = 0x82, /*130 */
SIGBOOST_EVENT_CALL_START_NACK_ACK = 0x83, /*131 */
SIGBOOST_EVENT_CALL_ANSWERED = 0x84, /*132 */
SIGBOOST_EVENT_CALL_STOPPED = 0x85, /*133 */
SIGBOOST_EVENT_CALL_STOPPED_ACK = 0x86, /*134 */
SIGBOOST_EVENT_SYSTEM_RESTART = 0x87, /*135 */
SIGBOOST_EVENT_HEARTBEAT = 0x88, /*136 */
};
enum e_sigboost_release_cause_values
{
SIGBOOST_RELEASE_CAUSE_UNDEFINED = 0x00,
SIGBOOST_RELEASE_CAUSE_NORMAL = 0x90,
SIGBOOST_RELEASE_CAUSE_BUSY = 0x91,
SIGBOOST_RELEASE_CAUSE_CALLED_NOT_EXIST = 0x92,
SIGBOOST_RELEASE_CAUSE_CIRCUIT_RESET = 0x93,
SIGBOOST_RELEASE_CAUSE_NOANSWER = 0x94
enum e_sigboost_release_cause_values {
SIGBOOST_RELEASE_CAUSE_UNDEFINED = 0x00,
SIGBOOST_RELEASE_CAUSE_NORMAL = 0x90,
SIGBOOST_RELEASE_CAUSE_BUSY = 0x91,
SIGBOOST_RELEASE_CAUSE_CALLED_NOT_EXIST = 0x92,
SIGBOOST_RELEASE_CAUSE_CIRCUIT_RESET = 0x93,
SIGBOOST_RELEASE_CAUSE_NOANSWER = 0x94
};
enum e_sigboost_call_setup_ack_nack_cause_values
{
SIGBOOST_CALL_SETUP_CIRCUIT_RESET = 0x10,
SIGBOOST_CALL_SETUP_NACK_CKT_START_TIMEOUT = 0x11,
SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY = 0x12,
SIGBOOST_CALL_SETUP_NACK_CALLED_NUM_TOO_BIG = 0x13,
SIGBOOST_CALL_SETUP_NACK_CALLING_NUM_TOO_BIG = 0x14,
SIGBOOST_CALL_SETUP_NACK_CALLED_NUM_TOO_SMALL = 0x15,
SIGBOOST_CALL_SETUP_NACK_CALLING_NUM_TOO_SMALL = 0x16,
enum e_sigboost_call_setup_ack_nack_cause_values {
SIGBOOST_CALL_SETUP_CIRCUIT_RESET = 0x10,
SIGBOOST_CALL_SETUP_NACK_CKT_START_TIMEOUT = 0x11,
SIGBOOST_CALL_SETUP_NACK_ALL_CKTS_BUSY = 0x12,
SIGBOOST_CALL_SETUP_NACK_CALLED_NUM_TOO_BIG = 0x13,
SIGBOOST_CALL_SETUP_NACK_CALLING_NUM_TOO_BIG = 0x14,
SIGBOOST_CALL_SETUP_NACK_CALLED_NUM_TOO_SMALL = 0x15,
SIGBOOST_CALL_SETUP_NACK_CALLING_NUM_TOO_SMALL = 0x16,
};
#define MAX_DIALED_DIGITS 31
@@ -61,21 +58,20 @@ enum e_sigboost_call_setup_ack_nack_cause_values
/* 0..(MAX_PENDING_CALLS-1) is range of call_setup_id below */
#pragma pack(1)
typedef struct
{
uint32_t event_id;
uint32_t seqno;
uint32_t call_setup_id;
uint32_t trunk_group;
uint32_t span;
uint32_t chan;
uint32_t called_number_digits_count;
int8_t called_number_digits [MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */
uint32_t calling_number_digits_count; /* it's an array */
int8_t calling_number_digits [MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */
uint32_t release_cause;
struct timeval tv;
uint32_t calling_number_presentation;
typedef struct {
uint32_t event_id;
uint32_t seqno;
uint32_t call_setup_id;
uint32_t trunk_group;
uint32_t span;
uint32_t chan;
uint32_t called_number_digits_count;
int8_t called_number_digits[MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */
uint32_t calling_number_digits_count; /* it's an array */
int8_t calling_number_digits[MAX_DIALED_DIGITS + 1]; /* it's a null terminated string */
uint32_t release_cause;
struct timeval tv;
uint32_t calling_number_presentation;
} t_sigboost;
#pragma pack()
+49 -54
View File
@@ -52,23 +52,25 @@ static struct ss7boost_client_map ss7boost_client_table[] = {
{SIGBOOST_EVENT_CALL_STOPPED_ACK, "CALL_STOPPED_ACK"},
{SIGBOOST_EVENT_SYSTEM_RESTART, "SYSTEM_RESTART"},
{SIGBOOST_EVENT_HEARTBEAT, "HEARTBEAT"},
};
};
static switch_status_t create_udp_socket(ss7boost_client_connection_t *mcon, char *local_ip, int local_port, char *ip, int port)
static switch_status_t create_udp_socket(ss7boost_client_connection_t * mcon, char *local_ip, int local_port, char *ip,
int port)
{
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "connect %s:%d->%s:%d\n", local_ip, local_port, ip, port);
if (switch_sockaddr_info_get(&mcon->local_addr, local_ip, SWITCH_UNSPEC, local_port, 0, mcon->pool) != SWITCH_STATUS_SUCCESS) {
if (switch_sockaddr_info_get(&mcon->local_addr, local_ip, SWITCH_UNSPEC, local_port, 0, mcon->pool) !=
SWITCH_STATUS_SUCCESS) {
goto fail;
}
if (switch_sockaddr_info_get(&mcon->remote_addr, ip, SWITCH_UNSPEC, port, 0, mcon->pool) != SWITCH_STATUS_SUCCESS) {
goto fail;
}
if (switch_socket_create(&mcon->socket, AF_INET, SOCK_DGRAM, 0, mcon->pool) == SWITCH_STATUS_SUCCESS) {
if (switch_socket_bind(mcon->socket, mcon->local_addr) != SWITCH_STATUS_SUCCESS) {
goto fail;
@@ -77,18 +79,20 @@ static switch_status_t create_udp_socket(ss7boost_client_connection_t *mcon, cha
goto fail;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Created boost connection %s:%d->%s:%d\n", local_ip, local_port, ip, port);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Created boost connection %s:%d->%s:%d\n", local_ip,
local_port, ip, port);
return SWITCH_STATUS_SUCCESS;
fail:
fail:
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure creating boost connection %s:%d->%s:%d\n", local_ip, local_port, ip, port);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Failure creating boost connection %s:%d->%s:%d\n", local_ip,
local_port, ip, port);
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t *mcon)
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t * mcon)
{
switch_socket_close(mcon->socket);
mcon->socket = NULL;
@@ -97,12 +101,10 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client
return SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t *mcon,
char *local_ip,
int local_port,
char *ip,
int port,
switch_memory_pool_t *pool)
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t * mcon,
char *local_ip,
int local_port,
char *ip, int port, switch_memory_pool_t *pool)
{
memset(mcon, 0, sizeof(*mcon));
mcon->pool = pool;
@@ -111,32 +113,30 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_
switch_mutex_init(&mcon->mutex, SWITCH_MUTEX_NESTED, mcon->pool);
return SWITCH_STATUS_SUCCESS;
}
memset(mcon, 0, sizeof(*mcon));
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t *mcon, ss7boost_client_event_t **event)
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t * mcon,
ss7boost_client_event_t ** event)
{
unsigned int fromlen = sizeof(struct sockaddr_in);
switch_size_t bytes = 0;
bytes = sizeof(mcon->event);
if (switch_socket_recvfrom(mcon->local_addr, mcon->socket, 0, (void *)&mcon->event, &bytes) != SWITCH_STATUS_SUCCESS) {
if (switch_socket_recvfrom(mcon->local_addr, mcon->socket, 0, (void *) &mcon->event, &bytes) !=
SWITCH_STATUS_SUCCESS) {
bytes = 0;
}
if (bytes == sizeof(mcon->event) ||
bytes == (sizeof(mcon->event)-sizeof(uint32_t))) {
if (bytes == sizeof(mcon->event) || bytes == (sizeof(mcon->event) - sizeof(uint32_t))) {
if (rxseq != mcon->event.seqno) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"------------------------------------------\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"Critical Error: Invalid Sequence Number Expect=%i Rx=%i\n",
rxseq,mcon->event.seqno);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"------------------------------------------\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"Critical Error: Invalid Sequence Number Expect=%i Rx=%i\n", rxseq, mcon->event.seqno);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
}
rxseq++;
@@ -147,7 +147,8 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_
return SWITCH_STATUS_FALSE;
}
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t *mcon, ss7boost_client_event_t *event)
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t * mcon,
ss7boost_client_event_t * event)
{
int err;
switch_size_t len;
@@ -158,23 +159,19 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client
}
if (event->span < 0 || event->chan < 0 || event->span > 7 || event->chan > 30) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"------------------------------------------\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"Critical Error: Invalid Span=%i Chan=%i\n",
event->span,event->chan);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"------------------------------------------\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT,
"Critical Error: Invalid Span=%i Chan=%i\n", event->span, event->chan);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "------------------------------------------\n");
}
#ifdef WIN32
//TODO set the tv with win func
#else
gettimeofday(&event->tv,NULL);
#else
gettimeofday(&event->tv, NULL);
#endif
switch_mutex_lock(mcon->mutex);
event->seqno=txseq++;
event->seqno = txseq++;
len = sizeof(*event);
if (switch_socket_sendto(mcon->socket, mcon->remote_addr, 0, (void *) event, &len) != SWITCH_STATUS_SUCCESS) {
err = -1;
@@ -182,7 +179,8 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client
switch_mutex_unlock(mcon->mutex);
if (len != sizeof(ss7boost_client_event_t)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Write Error: [%d][%d][%s]\n", mcon->socket, errno, strerror(errno));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Write Error: [%d][%d][%s]\n", mcon->socket, errno,
strerror(errno));
err = -1;
}
@@ -204,42 +202,39 @@ SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client
"\n",
ss7boost_client_event_id_name(event->event_id),
event->event_id,
event->span+1,
event->chan+1,
event->span + 1,
event->chan + 1,
(event->called_number_digits_count ? (char *) event->called_number_digits : "N/A"),
(event->calling_number_digits_count ? (char *) event->calling_number_digits : "N/A"),
event->release_cause,
event->span+1,
event->chan+1,
event->event_id,
event->call_setup_id,
event->seqno
);
event->span + 1, event->chan + 1, event->event_id, event->call_setup_id, event->seqno);
return err ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
}
SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t *event, char *calling, char *called, int setup_id)
SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t * event, char *calling, char *called,
int setup_id)
{
memset(event, 0, sizeof(ss7boost_client_event_t));
event->event_id = SIGBOOST_EVENT_CALL_START;
if (calling) {
strncpy((char*)event->calling_number_digits, calling, sizeof(event->calling_number_digits)-1);
strncpy((char *) event->calling_number_digits, calling, sizeof(event->calling_number_digits) - 1);
event->calling_number_digits_count = strlen(calling);
}
if (called) {
strncpy((char*)event->called_number_digits, called, sizeof(event->called_number_digits)-1);
strncpy((char *) event->called_number_digits, called, sizeof(event->called_number_digits) - 1);
event->called_number_digits_count = strlen(called);
}
event->call_setup_id = setup_id;
}
SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t *event, ss7boost_client_event_id_t event_id, int chan, int span)
SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t * event, ss7boost_client_event_id_t event_id,
int chan, int span)
{
memset(event, 0, sizeof(ss7boost_client_event_t));
event->event_id = event_id;
@@ -252,7 +247,7 @@ SWITCH_DECLARE(char *) ss7boost_client_event_id_name(uint32_t event_id)
int x;
char *ret = NULL;
for (x = 0 ; x < sizeof(ss7boost_client_table)/sizeof(struct ss7boost_client_map); x++) {
for (x = 0; x < sizeof(ss7boost_client_table) / sizeof(struct ss7boost_client_map); x++) {
if (ss7boost_client_table[x].event_id == event_id) {
ret = ss7boost_client_table[x].name;
break;
+15 -15
View File
@@ -70,7 +70,7 @@
(dest)->flags |= ((src)->flags & (flagz)); \
} while (0)
typedef t_sigboost ss7boost_client_event_t;
typedef t_sigboost ss7boost_client_event_t;
typedef uint32_t ss7boost_client_event_id_t;
struct ss7boost_client_connection {
@@ -80,7 +80,7 @@ struct ss7boost_client_connection {
ss7boost_client_event_t event;
unsigned int flags;
switch_mutex_t *mutex;
switch_memory_pool_t * pool;
switch_memory_pool_t *pool;
};
typedef enum {
@@ -89,19 +89,19 @@ typedef enum {
typedef struct ss7boost_client_connection ss7boost_client_connection_t;
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t *mcon);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t *mcon,
char *local_ip,
int local_port,
char *ip,
int port,
switch_memory_pool_t *pool);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t *mcon, ss7boost_client_event_t **event);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t *mcon, ss7boost_client_event_t *event);
SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t *event, ss7boost_client_event_id_t event_id, int chan, int span);
SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t *event, char *calling, char *called, int setup_id);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_close(ss7boost_client_connection_t * mcon);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_open(ss7boost_client_connection_t * mcon,
char *local_ip,
int local_port,
char *ip, int port, switch_memory_pool_t *pool);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_read(ss7boost_client_connection_t * mcon,
ss7boost_client_event_t ** event);
SWITCH_DECLARE(switch_status_t) ss7boost_client_connection_write(ss7boost_client_connection_t * mcon,
ss7boost_client_event_t * event);
SWITCH_DECLARE(void) ss7boost_client_event_init(ss7boost_client_event_t * event, ss7boost_client_event_id_t event_id,
int chan, int span);
SWITCH_DECLARE(void) ss7boost_client_call_init(ss7boost_client_event_t * event, char *calling, char *called,
int setup_id);
SWITCH_DECLARE(char *) ss7boost_client_event_id_name(uint32_t event_id);
#endif
+84 -70
View File
@@ -169,12 +169,13 @@ static switch_status_t woomera_on_hangup(switch_core_session_t *session);
static switch_status_t woomera_on_ring(switch_core_session_t *session);
static switch_status_t woomera_on_loopback(switch_core_session_t *session);
static switch_status_t woomera_on_transmit(switch_core_session_t *session);
static switch_call_cause_t woomera_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
static switch_call_cause_t woomera_outgoing_channel(switch_core_session_t *session,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool);
static switch_status_t woomera_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
switch_io_flag_t flags, int stream_id);
switch_io_flag_t flags, int stream_id);
static switch_status_t woomera_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
switch_io_flag_t flags, int stream_id);
switch_io_flag_t flags, int stream_id);
static switch_status_t woomera_kill_channel(switch_core_session_t *session, int sig);
static void tech_destroy(private_object * tech_pvt);
static void woomera_printf(woomera_profile * profile, switch_socket_t *socket, char *fmt, ...);
@@ -213,7 +214,8 @@ static switch_status_t woomera_on_init(switch_core_session_t *session)
if (switch_core_codec_init
(&tech_pvt->read_codec, "L16", NULL, rate, 30, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n", switch_channel_get_name(channel));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n",
switch_channel_get_name(channel));
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_FALSE;
}
@@ -221,7 +223,8 @@ static switch_status_t woomera_on_init(switch_core_session_t *session)
if (switch_core_codec_init
(&tech_pvt->write_codec, "L16", NULL, rate, 30, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n", switch_channel_get_name(channel));
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Cannot set read codec\n",
switch_channel_get_name(channel));
switch_channel_hangup(channel, SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER);
return SWITCH_STATUS_FALSE;
}
@@ -327,19 +330,19 @@ static switch_status_t woomera_kill_channel(switch_core_session_t *session, int
return SWITCH_STATUS_FALSE;
}
switch(sig) {
case SWITCH_SIG_KILL:
udp_socket_close(tech_pvt);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s WOOMERA KILL\n", switch_channel_get_name(channel));
break;
case SWITCH_SIG_BREAK:
{
const char p = 0;
switch_size_t len = sizeof(p);
switch_socket_sendto(tech_pvt->udp_socket, tech_pvt->udpwrite, 0, &p, &len);
}
break;
}
switch (sig) {
case SWITCH_SIG_KILL:
udp_socket_close(tech_pvt);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s WOOMERA KILL\n", switch_channel_get_name(channel));
break;
case SWITCH_SIG_BREAK:
{
const char p = 0;
switch_size_t len = sizeof(p);
switch_socket_sendto(tech_pvt->udp_socket, tech_pvt->udpwrite, 0, &p, &len);
}
break;
}
return SWITCH_STATUS_SUCCESS;
@@ -375,11 +378,11 @@ static switch_status_t woomera_waitfor_write(switch_core_session_t *session, int
assert(tech_pvt != NULL);
return SWITCH_STATUS_SUCCESS;
// return switch_socket_waitfor(tech_pvt->write_poll, ms);
// return switch_socket_waitfor(tech_pvt->write_poll, ms);
}
static switch_status_t woomera_read_frame(switch_core_session_t *session, switch_frame_t **frame, int timeout,
switch_io_flag_t flags, int stream_id)
switch_io_flag_t flags, int stream_id)
{
switch_channel_t *channel = NULL;
struct private_object *tech_pvt = NULL;
@@ -404,8 +407,9 @@ static switch_status_t woomera_read_frame(switch_core_session_t *session, switch
*frame = pframe;
len = sizeof(tech_pvt->databuf);
if (switch_socket_recvfrom(tech_pvt->udpread, tech_pvt->udp_socket, 0, tech_pvt->databuf, &len) == SWITCH_STATUS_SUCCESS) {
pframe->datalen = (uint32_t)len;
if (switch_socket_recvfrom(tech_pvt->udpread, tech_pvt->udp_socket, 0, tech_pvt->databuf, &len) ==
SWITCH_STATUS_SUCCESS) {
pframe->datalen = (uint32_t) len;
pframe->samples = (int) pframe->datalen / 2;
return SWITCH_STATUS_SUCCESS;
}
@@ -414,13 +418,13 @@ static switch_status_t woomera_read_frame(switch_core_session_t *session, switch
}
static switch_status_t woomera_write_frame(switch_core_session_t *session, switch_frame_t *frame, int timeout,
switch_io_flag_t flags, int stream_id)
switch_io_flag_t flags, int stream_id)
{
switch_channel_t *channel = NULL;
struct private_object *tech_pvt = NULL;
switch_size_t len;
//switch_frame_t *pframe;
channel = switch_core_session_get_channel(session);
assert(channel != NULL);
@@ -430,11 +434,10 @@ static switch_status_t woomera_write_frame(switch_core_session_t *session, switc
if (!tech_pvt->udp_socket) {
return SWITCH_STATUS_GENERR;
}
//pframe = &tech_pvt->frame;
len = frame->datalen;
if (switch_socket_sendto(tech_pvt->udp_socket, tech_pvt->udpwrite, 0, frame->data, &len) == SWITCH_STATUS_SUCCESS) {
frame->datalen = (uint32_t)len;
frame->datalen = (uint32_t) len;
return SWITCH_STATUS_SUCCESS;
}
@@ -481,7 +484,8 @@ static const switch_loadable_module_interface_t woomera_module_interface = {
/* 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_call_cause_t woomera_outgoing_channel(switch_core_session_t *session, switch_caller_profile_t *outbound_profile,
static switch_call_cause_t woomera_outgoing_channel(switch_core_session_t *session,
switch_caller_profile_t *outbound_profile,
switch_core_session_t **new_session, switch_memory_pool_t **pool)
{
if ((*new_session = switch_core_session_request(&woomera_endpoint_interface, pool)) != 0) {
@@ -542,7 +546,8 @@ static void tech_destroy(private_object * tech_pvt)
WOOMERA_RECORD_SEPERATOR);
if (woomera_message_parse
(tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "{%s} Already Disconnected\n", tech_pvt->profile->name);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "{%s} Already Disconnected\n",
tech_pvt->profile->name);
}
woomera_printf(tech_pvt->profile, tech_pvt->command_channel, "bye%s", WOOMERA_RECORD_SEPERATOR);
@@ -570,7 +575,7 @@ static void woomera_printf(woomera_profile * profile, switch_socket_t *socket, c
} else {
if (profile && globals.debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Send Message: {%s} [%s/%d]\n%s\n%s", profile->name,
profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, stuff);
profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, stuff);
}
len = strlen(stuff);
switch_socket_send(socket, stuff, &len);
@@ -660,7 +665,7 @@ static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, in
bytes = 0;
while (!strstr(buf, WOOMERA_RECORD_SEPERATOR)) {
size_t len = 1;
switch_status_t status;
switch_status_t status;
if (!profile->thread_running) {
return -1;
@@ -668,16 +673,16 @@ static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, in
status = switch_socket_recv(fd, ptr, &len);
if (status == 70007) {
char bbuf = '\n';
switch_size_t blen = sizeof(bbuf);
switch_socket_send(fd, &bbuf, &blen);
continue;
}
if (status != SWITCH_STATUS_SUCCESS) {
return -1;
}
if (status == 70007) {
char bbuf = '\n';
switch_size_t blen = sizeof(bbuf);
switch_socket_send(fd, &bbuf, &blen);
continue;
}
if (status != SWITCH_STATUS_SUCCESS) {
return -1;
}
ptr++;
bytes++;
@@ -687,7 +692,7 @@ static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, in
if (globals.debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Receive Message: {%s} [%s/%d]\n%s\n%s", profile->name,
profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, buf);
profile->woomera_host, profile->woomera_port, WOOMERA_DEBUG_LINE, buf);
}
while ((cur = next) != 0) {
@@ -775,7 +780,8 @@ static int woomera_message_parse(switch_socket_t *fd, woomera_message * wmsg, in
if (event_queue && switch_test_flag(wmsg, WFLAG_EVENT)) {
if (globals.debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Queue Event: {%s} [%s]\n", profile->name, wmsg->command);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Queue Event: {%s} [%s]\n", profile->name,
wmsg->command);
}
/* we don't want events we want a reply so we will stash them for later */
woomera_enqueue_event(event_queue, wmsg);
@@ -801,7 +807,8 @@ static int connect_woomera(switch_socket_t **new_sock, woomera_profile * profile
switch_sockaddr_t *sa;
if (switch_sockaddr_info_get(&sa, profile->woomera_host, AF_INET, profile->woomera_port, 0, module_pool) != SWITCH_STATUS_SUCCESS) {
if (switch_sockaddr_info_get(&sa, profile->woomera_host, AF_INET, profile->woomera_port, 0, module_pool) !=
SWITCH_STATUS_SUCCESS) {
return -1;
}
@@ -809,8 +816,8 @@ static int connect_woomera(switch_socket_t **new_sock, woomera_profile * profile
return -1;
}
switch_socket_timeout_set((*new_sock), 10000000);
switch_socket_opt_set((*new_sock), SWITCH_SO_KEEPALIVE, 1);
switch_socket_timeout_set((*new_sock), 10000000);
switch_socket_opt_set((*new_sock), SWITCH_SO_KEEPALIVE, 1);
/*
status = switch_socket_bind((*new_sock), sa);
@@ -851,8 +858,8 @@ static int woomera_locate_socket(woomera_profile * profile, switch_socket_t **wo
if (!woomera_profile_thread_running(profile, 0, 0)) {
break;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "{%s} Cannot Reconnect to Woomera! retry in 5 seconds\n",
profile->name);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
"{%s} Cannot Reconnect to Woomera! retry in 5 seconds\n", profile->name);
switch_sleep(WOOMERA_RECONNECT_TIME);
}
@@ -861,7 +868,8 @@ static int woomera_locate_socket(woomera_profile * profile, switch_socket_t **wo
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) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n", profile->name);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
profile->name);
globals.panic = 1;
woomera_profile_thread_running(&default_profile, 1, 0);
switch_sleep(WOOMERA_RECONNECT_TIME);
@@ -890,7 +898,8 @@ static int tech_create_read_socket(private_object * tech_pvt)
tech_pvt->port = globals.next_woomera_port = WOOMERA_MIN_PORT;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "connect %s:%d\n", tech_pvt->profile->audio_ip, tech_pvt->port);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "connect %s:%d\n", tech_pvt->profile->audio_ip,
tech_pvt->port);
//tech_pvt->udp_socket = create_udp_socket(tech_pvt->profile->audio_ip, tech_pvt->port, &tech_pvt->udpread, 0);
switch_sockaddr_info_get(&tech_pvt->udpread, tech_pvt->profile->audio_ip, SWITCH_UNSPEC, tech_pvt->port, 0, pool);
@@ -938,7 +947,7 @@ static int tech_activate(private_object * tech_pvt)
if (woomera_message_parse(tech_pvt->command_channel,
&wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
tech_pvt->profile->name);
tech_pvt->profile->name);
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
globals.panic = 1;
}
@@ -998,7 +1007,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
(tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile,
&tech_pvt->event_queue) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
tech_pvt->profile->name);
tech_pvt->profile->name);
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
globals.panic = 1;
continue;
@@ -1014,7 +1023,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
(tech_pvt->command_channel, &wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile,
&tech_pvt->event_queue) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
tech_pvt->profile->name);
tech_pvt->profile->name);
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
globals.panic = 1;
continue;
@@ -1095,7 +1104,8 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
if ((tech_pvt->caller_profile = switch_caller_profile_new(switch_core_session_get_pool(session),
NULL,
tech_pvt->profile->dialplan,
cid_name, cid_num, ip, NULL, NULL, NULL, (char *)modname, NULL, exten)) != 0) {
cid_name, cid_num, ip, NULL, NULL, NULL,
(char *) modname, NULL, exten)) != 0) {
char name[128];
snprintf(name, sizeof(name), "Woomera/%s-%04x", tech_pvt->caller_profile->destination_number,
rand() & 0xffff);
@@ -1115,7 +1125,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
if (woomera_message_parse(tech_pvt->command_channel,
&wmsg, WOOMERA_HARD_TIMEOUT, tech_pvt->profile, &tech_pvt->event_queue) < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! Woomera is broken!\n",
tech_pvt->profile->name);
tech_pvt->profile->name);
switch_set_flag_locked(tech_pvt, TFLAG_ABORT);
globals.panic = 1;
continue;
@@ -1135,7 +1145,7 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
if ((ptr = strchr(ip, '/')) != 0) {
*ptr = '\0';
ptr++;
port = (switch_port_t)atoi(ptr);
port = (switch_port_t) atoi(ptr);
}
/* Move Channel's State Machine to RING */
switch_channel_answer(channel);
@@ -1150,8 +1160,8 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
SWITCH_STATUS_SUCCESS) {
if (globals.debug) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
WOOMERA_DEBUG_PREFIX "{%s} Cannot resolve %s\n",
tech_pvt->profile->name, ip);
WOOMERA_DEBUG_PREFIX "{%s} Cannot resolve %s\n",
tech_pvt->profile->name, ip);
}
switch_channel_hangup(channel, SWITCH_CAUSE_NETWORK_OUT_OF_ORDER);
}
@@ -1160,12 +1170,12 @@ static void *woomera_channel_thread_run(switch_thread_t *thread, void *obj)
}
if (globals.debug > 2) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, WOOMERA_DEBUG_PREFIX "CHECK {%s}(%d)\n",
tech_pvt->profile->name, res);
tech_pvt->profile->name, res);
}
}
if (globals.debug > 1) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, WOOMERA_DEBUG_PREFIX "Monitor thread for %s done.\n",
tech_pvt->profile->name);
tech_pvt->profile->name);
}
return NULL;
@@ -1204,7 +1214,7 @@ static void *woomera_thread_run(void *obj)
break;
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Woomera Thread Up {%s} %s/%d\n", profile->name,
profile->woomera_host, profile->woomera_port);
profile->woomera_host, profile->woomera_port);
}
@@ -1221,18 +1231,18 @@ static void *woomera_thread_run(void *obj)
if ((((res = woomera_dequeue_event(&profile->event_queue, &wmsg)) != 0) ||
((res = woomera_message_parse(profile->woomera_socket, &wmsg,
/* if we are not stingy with threads we can block forever */
0, profile, NULL))) != 0)) {
/* if we are not stingy with threads we can block forever */
0, profile, NULL))) != 0)) {
if (res < 0) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ALERT, "{%s} HELP! I lost my connection to woomera!\n",
profile->name);
profile->name);
woomera_socket_close(&profile->woomera_socket);
//global_set_flag(TFLAG_ABORT);
globals.panic = 1;
continue;
/* Can't get to the following code --Commented out for now.*/
/* Can't get to the following code --Commented out for now. */
/* if (profile->woomera_socket)
if (switch_test_flag(profile, PFLAG_INBOUND)) {
woomera_printf(profile, profile->woomera_socket, "LISTEN%s", WOOMERA_RECORD_SEPERATOR);
@@ -1268,9 +1278,11 @@ 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))) != 0) {
(struct private_object *) switch_core_session_alloc(session,
sizeof(struct private_object))) != 0) {
memset(tech_pvt, 0, sizeof(*tech_pvt));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
switch_mutex_init(&tech_pvt->flag_mutex, SWITCH_MUTEX_NESTED,
switch_core_session_get_pool(session));
tech_pvt->profile = &default_profile;
channel = switch_core_session_get_channel(session);
switch_core_session_set_private(session, tech_pvt);
@@ -1287,7 +1299,8 @@ static void *woomera_thread_run(void *obj)
}
if (globals.debug > 2) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Main Thread {%s} Select Return %d\n", profile->name, res);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Main Thread {%s} Select Return %d\n",
profile->name, res);
}
switch_yield(100);
@@ -1326,7 +1339,8 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_shutdown(void)
return SWITCH_STATUS_SUCCESS;
}
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface, char *filename)
SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_module_interface_t **module_interface,
char *filename)
{
struct woomera_profile *profile = &default_profile;
@@ -1346,7 +1360,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
strncpy(profile->dialplan, "default", sizeof(profile->dialplan) - 1);
strncpy(profile->audio_ip, "127.0.0.1", sizeof(profile->audio_ip) - 1);
strncpy(profile->woomera_host, "127.0.0.1", sizeof(profile->woomera_host) - 1);
profile->woomera_port = (switch_port_t)42420;
profile->woomera_port = (switch_port_t) 42420;
if ((settings = switch_xml_child(cfg, "settings"))) {
for (param = switch_xml_child(settings, "param"); param; param = param->next) {
@@ -1371,7 +1385,7 @@ SWITCH_MOD_DECLARE(switch_status_t) switch_module_load(const switch_loadable_mod
} else if (!strcmp(var, "host")) {
strncpy(profile->woomera_host, val, sizeof(profile->woomera_host) - 1);
} else if (!strcmp(var, "port")) {
profile->woomera_port = (switch_port_t)atoi(val);
profile->woomera_port = (switch_port_t) atoi(val);
} else if (!strcmp(var, "disabled")) {
if (atoi(val) > 0) {
switch_set_flag(profile, PFLAG_DISABLED);