mirror of
https://github.com/signalwire/freeswitch.git
synced 2026-11-08 20:43:51 +00:00
tweaks
git-svn-id: http://svn.openzap.org/svn/openzap/trunk@400 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
1 parent
26997e2bbe
commit
6ec135418a
10 files changed
+72
-281
No files matched your search
@@ -307,21 +307,22 @@ dsp_fsk_sample (dsp_fsk_handle_t *handle, double normalized_sample)
|
||||
if (handle->cellpos > 1.0) {
|
||||
handle->cellpos -= 1.0;
|
||||
|
||||
|
||||
switch (handle->state) {
|
||||
case FSK_STATE_DATA:
|
||||
{
|
||||
{
|
||||
|
||||
(*handle->attr.bithandler) (handle->attr.bithandler_arg, handle->current_bit);
|
||||
}
|
||||
break;
|
||||
case FSK_STATE_CHANSEIZE:
|
||||
{
|
||||
|
||||
if (handle->last_bit != handle->current_bit) {
|
||||
handle->conscutive_state_bits++;
|
||||
} else {
|
||||
handle->conscutive_state_bits = 0;
|
||||
}
|
||||
|
||||
|
||||
if (handle->conscutive_state_bits > 15) {
|
||||
handle->state = FSK_STATE_CARRIERSIG;
|
||||
handle->conscutive_state_bits = 0;
|
||||
|
||||
@@ -493,6 +493,7 @@ zap_status_t zap_channel_set_state(zap_channel_t *zchan, zap_channel_state_t sta
|
||||
zap_status_t zap_span_load_tones(zap_span_t *span, char *mapname);
|
||||
zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t len);
|
||||
zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf);
|
||||
void zap_channel_flush_dtmf(zap_channel_t *zchan);
|
||||
zap_time_t zap_current_time_in_ms(void);
|
||||
zap_status_t zap_span_poll_event(zap_span_t *span, uint32_t ms);
|
||||
zap_status_t zap_span_next_event(zap_span_t *span, zap_event_t **event);
|
||||
@@ -531,6 +532,15 @@ ZIO_CODEC_FUNCTION(zio_alaw2slin);
|
||||
ZIO_CODEC_FUNCTION(zio_ulaw2alaw);
|
||||
ZIO_CODEC_FUNCTION(zio_alaw2ulaw);
|
||||
|
||||
#ifdef DEBUG_LOCKS
|
||||
#define zap_mutex_lock(_x) printf("++++++lock %s:%d\n", __FILE__, __LINE__) && _zap_mutex_lock(_x)
|
||||
#define zap_mutex_trylock(_x) printf("++++++try %s:%d\n", __FILE__, __LINE__) && _zap_mutex_trylock(_x)
|
||||
#define zap_mutex_unlock(_x) printf("------unlock %s:%d\n", __FILE__, __LINE__) && _zap_mutex_unlock(_x)
|
||||
#else
|
||||
#define zap_mutex_lock(_x) _zap_mutex_lock(_x)
|
||||
#define zap_mutex_trylock(_x) _zap_mutex_trylock(_x)
|
||||
#define zap_mutex_unlock(_x) _zap_mutex_unlock(_x)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -32,9 +32,9 @@ zap_status_t zap_thread_create_detached_ex(zap_thread_function_t func, void *dat
|
||||
void zap_thread_override_default_stacksize(zap_size_t size);
|
||||
zap_status_t zap_mutex_create(zap_mutex_t **mutex);
|
||||
zap_status_t zap_mutex_destroy(zap_mutex_t **mutex);
|
||||
zap_status_t zap_mutex_lock(zap_mutex_t *mutex);
|
||||
zap_status_t zap_mutex_trylock(zap_mutex_t *mutex);
|
||||
zap_status_t zap_mutex_unlock(zap_mutex_t *mutex);
|
||||
zap_status_t _zap_mutex_lock(zap_mutex_t *mutex);
|
||||
zap_status_t _zap_mutex_trylock(zap_mutex_t *mutex);
|
||||
zap_status_t _zap_mutex_unlock(zap_mutex_t *mutex);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -43,8 +43,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj);
|
||||
static ZIO_CHANNEL_OUTGOING_CALL_FUNCTION(analog_fxo_outgoing_call)
|
||||
{
|
||||
if (!zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK) && !zap_test_flag(zchan, ZAP_CHANNEL_INTHREAD)) {
|
||||
//zap_channel_command(zchan, ZAP_COMMAND_TRACE_INPUT, "/tmp/inbound.ul");
|
||||
//zap_channel_command(zchan, ZAP_COMMAND_TRACE_OUTPUT, "/tmp/outbound.ul");
|
||||
zap_channel_clear_needed_tones(zchan);
|
||||
zap_channel_clear_detected_tones(zchan);
|
||||
|
||||
@@ -185,7 +183,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
|
||||
ts.buffer = NULL;
|
||||
|
||||
if (zap_channel_open_chan(zchan) != ZAP_SUCCESS) {
|
||||
zap_log(ZAP_LOG_ERROR, "OPEN ERROR\n");
|
||||
zap_log(ZAP_LOG_ERROR, "OPEN ERROR [%s]\n", zchan->last_error);
|
||||
goto done;
|
||||
}
|
||||
|
||||
@@ -226,12 +224,13 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
|
||||
|
||||
elapsed += interval;
|
||||
state_counter += interval;
|
||||
|
||||
|
||||
if (!zap_test_flag(zchan, ZAP_CHANNEL_STATE_CHANGE)) {
|
||||
switch(zchan->state) {
|
||||
case ZAP_CHANNEL_STATE_GET_CALLERID:
|
||||
{
|
||||
if (state_counter > 5000 || !zap_test_flag(zchan, ZAP_CHANNEL_CALLERID_DETECT)) {
|
||||
zap_channel_command(zchan, ZAP_COMMAND_DISABLE_CALLERID_DETECT, NULL);
|
||||
zap_set_state_locked(zchan, ZAP_CHANNEL_STATE_IDLE);
|
||||
}
|
||||
}
|
||||
@@ -355,7 +354,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
|
||||
{
|
||||
zap_channel_use(zchan);
|
||||
zap_channel_clear_needed_tones(zchan);
|
||||
|
||||
zap_channel_flush_dtmf(zchan);
|
||||
|
||||
if (zchan->type == ZAP_CHAN_TYPE_FXO && !zap_test_flag(zchan, ZAP_CHANNEL_OFFHOOK)) {
|
||||
zap_channel_command(zchan, ZAP_COMMAND_OFFHOOK, NULL);
|
||||
}
|
||||
@@ -569,7 +569,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
|
||||
zchan->needed_tones[ZAP_TONEMAP_FAIL1] = 1;
|
||||
zchan->needed_tones[ZAP_TONEMAP_FAIL2] = 1;
|
||||
zchan->needed_tones[ZAP_TONEMAP_FAIL3] = 1;
|
||||
dial_timeout = ((zchan->dtmf_on + zchan->dtmf_off) * strlen(zchan->caller_data.ani)) + 3000;
|
||||
dial_timeout = ((zchan->dtmf_on + zchan->dtmf_off) * strlen(zchan->caller_data.ani)) + 2000;
|
||||
}
|
||||
}
|
||||
} else if (zchan->detected_tones[ZAP_TONEMAP_RING]) {
|
||||
@@ -658,7 +658,8 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even
|
||||
{
|
||||
zap_sigmsg_t sig;
|
||||
zap_analog_data_t *analog_data = event->channel->span->signal_data;
|
||||
|
||||
int locked = 0;
|
||||
|
||||
memset(&sig, 0, sizeof(sig));
|
||||
sig.chan_id = event->channel->chan_id;
|
||||
sig.span_id = event->channel->span_id;
|
||||
@@ -669,15 +670,16 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even
|
||||
zap_oob_event2str(event->enum_id), event->channel->span_id, event->channel->chan_id, zap_channel_state2str(event->channel->state));
|
||||
|
||||
zap_mutex_lock(event->channel->mutex);
|
||||
|
||||
locked++;
|
||||
|
||||
switch(event->enum_id) {
|
||||
case ZAP_OOB_RING_START:
|
||||
{
|
||||
|
||||
if (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD)) {
|
||||
if (!event->channel->ring_count && (event->channel->state == ZAP_CHANNEL_STATE_DOWN && !zap_test_flag(event->channel, ZAP_CHANNEL_INTHREAD))) {
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_GET_CALLERID);
|
||||
event->channel->ring_count = 1;
|
||||
zap_mutex_unlock(event->channel->mutex);
|
||||
locked = 0;
|
||||
zap_thread_create_detached(zap_analog_channel_run, event->channel);
|
||||
} else {
|
||||
event->channel->ring_count++;
|
||||
@@ -693,6 +695,7 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even
|
||||
if (event->channel->state != ZAP_CHANNEL_STATE_DOWN) {
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DOWN);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
case ZAP_OOB_FLASH:
|
||||
@@ -724,6 +727,8 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_UP);
|
||||
} else {
|
||||
zap_set_state_locked(event->channel, ZAP_CHANNEL_STATE_DIALTONE);
|
||||
zap_mutex_unlock(event->channel->mutex);
|
||||
locked = 0;
|
||||
zap_thread_create_detached(zap_analog_channel_run, event->channel);
|
||||
}
|
||||
} else {
|
||||
@@ -736,8 +741,9 @@ static __inline__ zap_status_t process_event(zap_span_t *span, zap_event_t *even
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
zap_mutex_unlock(event->channel->mutex);
|
||||
if (locked) {
|
||||
zap_mutex_unlock(event->channel->mutex);
|
||||
}
|
||||
return ZAP_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ static void fsk_byte_handler (void *x, int data)
|
||||
if (state->dlen) {
|
||||
goto add_byte;
|
||||
}
|
||||
|
||||
|
||||
if (state->bpos == 1) {
|
||||
state->blen = byte;
|
||||
|
||||
|
||||
+21
-13
@@ -436,8 +436,10 @@ zap_status_t zap_span_add_channel(zap_span_t *span, zap_socket_t sockfd, zap_cha
|
||||
if (!new_chan->dtmf_off) {
|
||||
new_chan->dtmf_off = ZAP_DEFAULT_DTMF_OFF;
|
||||
}
|
||||
|
||||
zap_mutex_create(&new_chan->mutex);
|
||||
zap_buffer_create(&new_chan->digit_buffer, 128, 128, 0);
|
||||
|
||||
zap_set_flag(new_chan, ZAP_CHANNEL_CONFIGURED | ZAP_CHANNEL_READY);
|
||||
*chan = new_chan;
|
||||
return ZAP_SUCCESS;
|
||||
@@ -814,10 +816,12 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan)
|
||||
assert(zchan != NULL);
|
||||
|
||||
if (zap_test_flag(zchan, ZAP_CHANNEL_SUSPENDED)) {
|
||||
snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", "Channel is suspended");
|
||||
return ZAP_FAIL;
|
||||
}
|
||||
|
||||
|
||||
if (!zap_test_flag(zchan, ZAP_CHANNEL_READY) || (status = zap_mutex_trylock(zchan->mutex)) != ZAP_SUCCESS) {
|
||||
snprintf(zchan->last_error, sizeof(zchan->last_error), "Channel is not ready or is in use %d %d", zap_test_flag(zchan, ZAP_CHANNEL_READY), status);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -828,9 +832,11 @@ zap_status_t zap_channel_open_chan(zap_channel_t *zchan)
|
||||
if (status == ZAP_SUCCESS) {
|
||||
zap_set_flag(zchan, ZAP_CHANNEL_OPEN);
|
||||
}
|
||||
} else {
|
||||
snprintf(zchan->last_error, sizeof(zchan->last_error), "%s", "Channel is not ready");
|
||||
}
|
||||
zap_mutex_unlock(zchan->mutex);
|
||||
|
||||
zap_mutex_unlock(zchan->mutex);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -894,8 +900,6 @@ zap_status_t zap_channel_outgoing_call(zap_channel_t *zchan)
|
||||
|
||||
zap_status_t zap_channel_done(zap_channel_t *zchan)
|
||||
{
|
||||
int i;
|
||||
|
||||
assert(zchan != NULL);
|
||||
|
||||
memset(&zchan->caller_data, 0, sizeof(zchan->caller_data));
|
||||
@@ -903,12 +907,6 @@ zap_status_t zap_channel_done(zap_channel_t *zchan)
|
||||
zap_clear_flag_locked(zchan, ZAP_CHANNEL_INUSE);
|
||||
zap_clear_flag_locked(zchan, ZAP_CHANNEL_OUTBOUND);
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
if (zchan->fds[i] > -1) {
|
||||
close(zchan->fds[i]);
|
||||
zchan->fds[i] = -1;
|
||||
}
|
||||
}
|
||||
return ZAP_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -1019,7 +1017,8 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo
|
||||
close(zchan->fds[0]);
|
||||
zchan->fds[0] = -1;
|
||||
}
|
||||
if ((zchan->fds[0] = open(path, O_WRONLY|O_CREAT|O_TRUNC, 755)) > -1) {
|
||||
if ((zchan->fds[0] = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
|
||||
zap_log(ZAP_LOG_DEBUG, "Tracing channel %u:%u to [%s]\n", zchan->span_id, zchan->chan_id, path);
|
||||
GOTO_STATUS(done, ZAP_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -1031,10 +1030,11 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo
|
||||
{
|
||||
char *path = (char *) obj;
|
||||
if (zchan->fds[1] > 0) {
|
||||
close(zchan->fds[0]);
|
||||
close(zchan->fds[1]);
|
||||
zchan->fds[1] = -1;
|
||||
}
|
||||
if ((zchan->fds[1] = open(path, O_WRONLY|O_CREAT|O_TRUNC, 755)) > -1) {
|
||||
if ((zchan->fds[1] = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
|
||||
zap_log(ZAP_LOG_DEBUG, "Tracing channel %u:%u to [%s]\n", zchan->span_id, zchan->chan_id, path);
|
||||
GOTO_STATUS(done, ZAP_SUCCESS);
|
||||
}
|
||||
|
||||
@@ -1432,6 +1432,14 @@ zap_size_t zap_channel_dequeue_dtmf(zap_channel_t *zchan, char *dtmf, zap_size_t
|
||||
return bytes;
|
||||
}
|
||||
|
||||
void zap_channel_flush_dtmf(zap_channel_t *zchan)
|
||||
{
|
||||
if (zchan->digit_buffer && zap_buffer_inuse(zchan->digit_buffer)) {
|
||||
zap_mutex_lock(zchan->mutex);
|
||||
zap_buffer_zero(zchan->digit_buffer);
|
||||
zap_mutex_unlock(zchan->mutex);
|
||||
}
|
||||
}
|
||||
|
||||
zap_status_t zap_channel_queue_dtmf(zap_channel_t *zchan, const char *dtmf)
|
||||
{
|
||||
|
||||
@@ -184,7 +184,7 @@ zap_status_t zap_mutex_destroy(zap_mutex_t **mutex)
|
||||
return ZAP_SUCCESS;
|
||||
}
|
||||
|
||||
zap_status_t zap_mutex_lock(zap_mutex_t *mutex)
|
||||
zap_status_t _zap_mutex_lock(zap_mutex_t *mutex)
|
||||
{
|
||||
#ifdef WIN32
|
||||
EnterCriticalSection(&mutex->mutex);
|
||||
@@ -195,7 +195,7 @@ zap_status_t zap_mutex_lock(zap_mutex_t *mutex)
|
||||
return ZAP_SUCCESS;
|
||||
}
|
||||
|
||||
zap_status_t zap_mutex_trylock(zap_mutex_t *mutex)
|
||||
zap_status_t _zap_mutex_trylock(zap_mutex_t *mutex)
|
||||
{
|
||||
#ifdef WIN32
|
||||
if (!TryEnterCriticalSection(&mutex->mutex))
|
||||
@@ -207,7 +207,7 @@ zap_status_t zap_mutex_trylock(zap_mutex_t *mutex)
|
||||
return ZAP_SUCCESS;
|
||||
}
|
||||
|
||||
zap_status_t zap_mutex_unlock(zap_mutex_t *mutex)
|
||||
zap_status_t _zap_mutex_unlock(zap_mutex_t *mutex)
|
||||
{
|
||||
#ifdef WIN32
|
||||
LeaveCriticalSection(&mutex->mutex);
|
||||
@@ -218,6 +218,10 @@ zap_status_t zap_mutex_unlock(zap_mutex_t *mutex)
|
||||
return ZAP_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* For Emacs:
|
||||
* Local Variables:
|
||||
* mode:c
|
||||
|
||||
@@ -88,6 +88,7 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za
|
||||
struct zt_chanconfig cc;
|
||||
memset(&cc, 0, sizeof(cc));
|
||||
cc.chan = cc.master = x;
|
||||
|
||||
switch(type) {
|
||||
case ZAP_CHAN_TYPE_FXS:
|
||||
{
|
||||
@@ -126,11 +127,9 @@ static unsigned zt_open_range(zap_span_t *span, unsigned start, unsigned end, za
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (ioctl(CONTROL_FD, ZT_CHANCONFIG, &cc)) {
|
||||
zap_log(ZAP_LOG_ERROR, "failure configuring device %s chan %d fd %d (%s)\n",
|
||||
path, x, CONTROL_FD, strerror(errno));
|
||||
close(sockfd);
|
||||
break;
|
||||
zap_log(ZAP_LOG_WARNING, "this ioctl fails on older zaptel but is harmless if you used ztcfg\n[device %s chan %d fd %d (%s)]\n", path, x, CONTROL_FD, strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -319,7 +318,7 @@ static ZIO_CONFIGURE_FUNCTION(zt_configure)
|
||||
static ZIO_OPEN_FUNCTION(zt_open)
|
||||
{
|
||||
zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL);
|
||||
|
||||
|
||||
if (zchan->type == ZAP_CHAN_TYPE_DQ921 || zchan->type == ZAP_CHAN_TYPE_DQ931) {
|
||||
zchan->native_codec = zchan->effective_codec = ZAP_CODEC_NONE;
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user