Merge branch 'master' into netborder

This commit is contained in:
Moises Silva
2010-12-15 11:20:29 -05:00
17 changed files with 202 additions and 84 deletions
+15 -12
View File
@@ -2715,7 +2715,8 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_command(ftdm_channel_t *ftdmchan, ftdm_co
close(ftdmchan->fds[FTDM_READ_TRACE_INDEX]);
ftdmchan->fds[FTDM_READ_TRACE_INDEX] = -1;
}
if ((ftdmchan->fds[FTDM_READ_TRACE_INDEX] = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
if ((ftdmchan->fds[FTDM_READ_TRACE_INDEX] = open(path, O_WRONLY | O_CREAT | O_TRUNC
| FTDM_O_BINARY, S_IRUSR | S_IWUSR)) > -1) {
ftdm_log(FTDM_LOG_DEBUG, "Tracing channel %u:%u input to [%s]\n", ftdmchan->span_id, ftdmchan->chan_id, path);
GOTO_STATUS(done, FTDM_SUCCESS);
}
@@ -2731,7 +2732,8 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_command(ftdm_channel_t *ftdmchan, ftdm_co
close(ftdmchan->fds[FTDM_WRITE_TRACE_INDEX]);
ftdmchan->fds[FTDM_WRITE_TRACE_INDEX] = -1;
}
if ((ftdmchan->fds[FTDM_WRITE_TRACE_INDEX] = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR)) > -1) {
if ((ftdmchan->fds[FTDM_WRITE_TRACE_INDEX] = open(path, O_WRONLY | O_CREAT | O_TRUNC
| FTDM_O_BINARY, S_IRUSR | S_IWUSR)) > -1) {
ftdm_log(FTDM_LOG_DEBUG, "Tracing channel %u:%u output to [%s]\n", ftdmchan->span_id, ftdmchan->chan_id, path);
GOTO_STATUS(done, FTDM_SUCCESS);
}
@@ -2799,10 +2801,10 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_command(ftdm_channel_t *ftdmchan, ftdm_co
GOTO_STATUS(done, FTDM_FAIL);
}
if (start_chan_io_dump(ftdmchan, &ftdmchan->rxdump, size) != FTDM_SUCCESS) {
ftdm_log_chan(ftdmchan, FTDM_LOG_ERROR, "Failed to enable input dump of size %zd\n", size);
ftdm_log_chan(ftdmchan, FTDM_LOG_ERROR, "Failed to enable input dump of size %"FTDM_SIZE_FMT"\n", size);
GOTO_STATUS(done, FTDM_FAIL);
}
ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Enabled input dump with size %zd\n", size);
ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Enabled input dump with size %"FTDM_SIZE_FMT"\n", size);
GOTO_STATUS(done, FTDM_SUCCESS);
}
break;
@@ -2814,7 +2816,8 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_command(ftdm_channel_t *ftdmchan, ftdm_co
ftdm_log_chan_msg(ftdmchan, FTDM_LOG_DEBUG, "No need to disable input dump\n");
GOTO_STATUS(done, FTDM_SUCCESS);
}
ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Disabled input dump of size %zd\n", ftdmchan->rxdump.size);
ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Disabled input dump of size %"FTDM_SIZE_FMT"\n",
ftdmchan->rxdump.size);
stop_chan_io_dump(&ftdmchan->rxdump);
GOTO_STATUS(done, FTDM_SUCCESS);
}
@@ -2832,7 +2835,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_command(ftdm_channel_t *ftdmchan, ftdm_co
ftdm_log_chan(ftdmchan, FTDM_LOG_ERROR, "Failed to enable output dump of size %d\n", size);
GOTO_STATUS(done, FTDM_FAIL);
}
ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Enabled output dump with size %zd\n", size);
ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Enabled output dump with size %"FTDM_SIZE_FMT"\n", size);
GOTO_STATUS(done, FTDM_SUCCESS);
}
break;
@@ -2844,7 +2847,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_command(ftdm_channel_t *ftdmchan, ftdm_co
ftdm_log_chan_msg(ftdmchan, FTDM_LOG_DEBUG, "No need to disable output dump\n");
GOTO_STATUS(done, FTDM_SUCCESS);
}
ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Disabled output dump of size %zd\n", ftdmchan->rxdump.size);
ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Disabled output dump of size %"FTDM_SIZE_FMT"\n", ftdmchan->rxdump.size);
stop_chan_io_dump(&ftdmchan->txdump);
GOTO_STATUS(done, FTDM_SUCCESS);
}
@@ -2877,7 +2880,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_command(ftdm_channel_t *ftdmchan, ftdm_co
GOTO_STATUS(done, FTDM_FAIL);
}
dump_chan_io_to_file(ftdmchan, &ftdmchan->txdump, obj);
ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Dumped input of size %zd to file %p\n", ftdmchan->txdump.size, obj);
ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Dumped input of size %"FTDM_SIZE_FMT" to file %p\n", ftdmchan->txdump.size, obj);
GOTO_STATUS(done, FTDM_SUCCESS);
}
break;
@@ -3376,7 +3379,7 @@ FT_DECLARE(ftdm_status_t) ftdm_channel_queue_dtmf(ftdm_channel_t *ftdmchan, cons
ftdmchan->span_id, ftdmchan->chan_id,
currtime.tm_year-100, currtime.tm_mon+1, currtime.tm_mday,
currtime.tm_hour, currtime.tm_min, currtime.tm_sec, ftdmchan->native_codec == FTDM_CODEC_ULAW ? "ulaw" : ftdmchan->native_codec == FTDM_CODEC_ALAW ? "alaw" : "sln");
ftdmchan->dtmfdbg.file = fopen(dfile, "w");
ftdmchan->dtmfdbg.file = fopen(dfile, "wb");
if (!ftdmchan->dtmfdbg.file) {
ftdm_log_chan(ftdmchan, FTDM_LOG_ERROR, "failed to open debug dtmf file %s\n", dfile);
} else {
@@ -3446,7 +3449,7 @@ static FIO_WRITE_FUNCTION(ftdm_raw_write)
}
if (ftdmchan->fds[FTDM_WRITE_TRACE_INDEX] > -1) {
if ((write(ftdmchan->fds[FTDM_WRITE_TRACE_INDEX], data, dlen)) != dlen) {
ftdm_log(FTDM_LOG_WARNING, "Raw output trace failed to write all of the %zd bytes\n", dlen);
ftdm_log(FTDM_LOG_WARNING, "Raw output trace failed to write all of the %"FTDM_SIZE_FMT" bytes\n", dlen);
}
}
write_chan_io_dump(&ftdmchan->txdump, data, dlen);
@@ -3459,7 +3462,7 @@ static FIO_READ_FUNCTION(ftdm_raw_read)
if (status == FTDM_SUCCESS && ftdmchan->fds[FTDM_READ_TRACE_INDEX] > -1) {
ftdm_size_t dlen = *datalen;
if ((ftdm_size_t)write(ftdmchan->fds[FTDM_READ_TRACE_INDEX], data, (int)dlen) != dlen) {
ftdm_log(FTDM_LOG_WARNING, "Raw input trace failed to write all of the %zd bytes\n", dlen);
ftdm_log(FTDM_LOG_WARNING, "Raw input trace failed to write all of the %"FTDM_SIZE_FMT" bytes\n", dlen);
}
}
@@ -4700,7 +4703,7 @@ static ftdm_status_t load_config(void)
len = strlen(val);
if (len >= FTDM_MAX_NAME_STR_SZ) {
len = FTDM_MAX_NAME_STR_SZ - 1;
ftdm_log(FTDM_LOG_WARNING, "Truncating group name %s to %zd length\n", val, len);
ftdm_log(FTDM_LOG_WARNING, "Truncating group name %s to %"FTDM_SIZE_FMT" length\n", val, len);
}
memcpy(chan_config.group_name, val, len);
chan_config.group_name[len] = '\0';
+11 -4
View File
@@ -568,14 +568,14 @@ static void dump_mf(openr2_chan_t *r2chan)
ftdm_log_chan(ftdmchan, FTDM_LOG_ERROR, "Dumping IO output in prefix %s\n", logname);
snprintf(dfile, sizeof(dfile), logname ? "%s.s%dc%d.input.alaw" : "%s/s%dc%d.input.alaw",
logname ? logname : r2data->logdir, ftdmchan->span_id, ftdmchan->chan_id);
f = fopen(dfile, "w");
f = fopen(dfile, "wb");
ftdm_log_chan(ftdmchan, FTDM_LOG_ERROR, "Dumping IO input in file %s\n", dfile);
ftdm_channel_command(ftdmchan, FTDM_COMMAND_DUMP_INPUT, f);
fclose(f);
snprintf(dfile, sizeof(dfile), logname ? "%s.s%dc%d.output.alaw" : "%s/s%dc%d.output.alaw",
logname ? logname : r2data->logdir, ftdmchan->span_id, ftdmchan->chan_id);
f = fopen(dfile, "w");
f = fopen(dfile, "wb");
ftdm_log_chan(ftdmchan, FTDM_LOG_ERROR, "Dumping IO output in file %s\n", dfile);
ftdm_channel_command(ftdmchan, FTDM_COMMAND_DUMP_OUTPUT, f);
fclose(f);
@@ -585,6 +585,8 @@ static void dump_mf(openr2_chan_t *r2chan)
static void ftdm_r2_on_call_accepted(openr2_chan_t *r2chan, openr2_call_mode_t mode)
{
ftdm_channel_t *ftdmchan = openr2_chan_get_client_data(r2chan);
ftdm_r2_data_t *r2data = ftdmchan->span->signal_data;
ftdm_log_chan_msg(ftdmchan, FTDM_LOG_NOTICE, "Call accepted\n");
clear_accept_pending(ftdmchan);
@@ -607,6 +609,11 @@ static void ftdm_r2_on_call_accepted(openr2_chan_t *r2chan, openr2_call_mode_t m
return;
}
} else {
/* nothing went wrong during call setup, MF has ended, we can and must disable the MF dump */
if (r2data->mf_dump_size) {
ftdm_channel_command(ftdmchan, FTDM_COMMAND_DISABLE_INPUT_DUMP, NULL);
ftdm_channel_command(ftdmchan, FTDM_COMMAND_DISABLE_OUTPUT_DUMP, NULL);
}
ftdm_set_state(ftdmchan, FTDM_CHANNEL_STATE_PROGRESS_MEDIA);
}
}
@@ -665,7 +672,7 @@ static void ftdm_r2_on_call_read(openr2_chan_t *r2chan, const unsigned char *buf
static void ftdm_r2_on_hardware_alarm(openr2_chan_t *r2chan, int alarm)
{
ftdm_channel_t *ftdmchan = openr2_chan_get_client_data(r2chan);
ftdm_log_chan(ftdmchan, FTDM_LOG_WARNING, "Alarm notification: %d\n", alarm);
ftdm_log_chan(ftdmchan, FTDM_LOG_DEBUG, "Alarm notification: %d\n", alarm);
}
static void ftdm_r2_on_os_error(openr2_chan_t *r2chan, int errorcode)
@@ -1955,7 +1962,7 @@ static FIO_API_FUNCTION(ftdm_r2_api)
"Max DNIS: %d\n"
"ANI First: %s\n"
"Immediate Accept: %s\n"
"Job Thread: %lu\n"
"Job Thread: %u\n"
"Job Max ms: %d\n"
"Job Loops: %lu\n",
openr2_proto_get_variant_string(r2variant),
+4
View File
@@ -158,12 +158,16 @@ typedef __int64 int64_t;
typedef __int32 int32_t;
typedef __int16 int16_t;
typedef __int8 int8_t;
#define FTDM_O_BINARY O_BINARY
#define FTDM_SIZE_FMT "Id"
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#else
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
#endif /* _MSC_VER */
#else /* __WINDOWS__ */
#define FTDM_O_BINARY 0
#define FTDM_SIZE_FMT "zd"
#define FTDM_INVALID_SOCKET -1
typedef int ftdm_socket_t;
#include <stdio.h>
+60 -23
View File
@@ -28,6 +28,11 @@
#include "stfu.h"
//#define DB_JB 1
#ifndef UINT_MAX
# define UINT_MAX 4294967295U
#endif
#ifdef _MSC_VER
/* warning C4706: assignment within conditional expression*/
#pragma warning(disable: 4706)
@@ -123,6 +128,7 @@ static stfu_status_t stfu_n_resize_aqueue(stfu_queue_t *queue, uint32_t qlen)
static void stfu_n_init_aqueue(stfu_queue_t *queue, uint32_t qlen)
{
queue->array = calloc(qlen, sizeof(struct stfu_frame));
assert(queue->array != NULL);
memset(queue->array, 0, sizeof(struct stfu_frame) * qlen);
@@ -166,6 +172,7 @@ stfu_status_t stfu_n_resize(stfu_instance_t *i, uint32_t qlen)
stfu_status_t s;
if (i->qlen == i->max_qlen) {
printf("FUCKER1\n");
return STFU_IT_FAILED;
}
@@ -173,6 +180,7 @@ stfu_status_t stfu_n_resize(stfu_instance_t *i, uint32_t qlen)
if (i->qlen < i->max_qlen) {
qlen = i->max_qlen;
} else {
printf("FUCKER2\n");
return STFU_IT_FAILED;
}
}
@@ -196,6 +204,12 @@ stfu_instance_t *stfu_n_init(uint32_t qlen, uint32_t max_qlen, uint32_t samples_
return NULL;
}
memset(i, 0, sizeof(*i));
#ifdef DB_JB
printf("INIT %u %u\n", qlen, max_qlen);
#endif
i->qlen = qlen;
i->max_qlen = max_qlen;
i->orig_qlen = qlen;
@@ -281,10 +295,11 @@ stfu_status_t stfu_n_sync(stfu_instance_t *i, uint32_t packets)
stfu_status_t stfu_n_add_data(stfu_instance_t *i, uint32_t ts, uint32_t seq, uint32_t pt, void *data, size_t datalen, int last)
{
uint32_t index;
uint32_t index = 0;
stfu_frame_t *frame;
size_t cplen = 0;
int good_seq = 0, good_ts = 0;
uint32_t min_seq = UINT_MAX, min_ts = UINT_MAX, min_index = 0;
if (!i->samples_per_packet && ts && i->last_rd_ts) {
i->ts_diff = ts - i->last_rd_ts;
@@ -305,11 +320,11 @@ stfu_status_t stfu_n_add_data(stfu_instance_t *i, uint32_t ts, uint32_t seq, uin
}
}
if (seq && seq == i->last_seq + 1) {
if ((seq && seq == i->last_seq + 1) || (i->last_seq > 65500 && seq == 0)) {
good_seq = 1;
}
if (ts && ts == i->last_rd_ts + i->samples_per_packet) {
if ((ts && ts == i->last_rd_ts + i->samples_per_packet) || (i->last_rd_ts > 4294900000 && ts < 5000)) {
good_ts = 1;
}
@@ -322,21 +337,20 @@ stfu_status_t stfu_n_add_data(stfu_instance_t *i, uint32_t ts, uint32_t seq, uin
i->period_packet_in_count++;
i->session_packet_in_count++;
if (i->session_packet_in_count == 150) {
return STFU_IT_WORKED;
}
i->period_need_range_avg = i->period_need_range / (i->period_missing_count || 1);
if (i->period_missing_count > i->qlen * 2) {
#ifdef DB_JB
printf("resize %u %u\n", i->qlen, i->qlen + 1);
#endif
stfu_n_resize(i, i->qlen + 1);
stfu_n_reset_counters(i);
}
if (i->qlen > i->orig_qlen && (i->consecutive_good_count > i->decrement_time || i->period_clean_count > i->decrement_time)) {
stfu_n_resize(i, i->qlen - 1);
stfu_n_reset_counters(i);
stfu_n_sync(i, i->qlen);
} else {
if (i->qlen > i->orig_qlen && (i->consecutive_good_count > i->decrement_time || i->period_clean_count > i->decrement_time)) {
stfu_n_resize(i, i->qlen - 1);
stfu_n_reset_counters(i);
stfu_n_sync(i, i->qlen);
}
}
if ((i->period_packet_in_count > i->period_time)) {
@@ -379,13 +393,31 @@ stfu_status_t stfu_n_add_data(stfu_instance_t *i, uint32_t ts, uint32_t seq, uin
return STFU_IM_DONE;
}
for(index = 0; index < i->out_queue->array_size; index++) {
for(index = 0; index < i->in_queue->array_size; index++) {
if (i->in_queue->array[index].was_read) {
min_index = index;
break;
}
if (i->in_queue->array[index].seq < min_seq) {
min_seq = i->in_queue->array[index].seq;
min_index = index;
}
if (i->in_queue->array[index].ts < min_ts) {
min_ts = i->in_queue->array[index].ts;
min_index = index;
}
}
index = i->in_queue->array_len++;
index = min_index;
if (i->in_queue->array_len < i->in_queue->array_size) {
i->in_queue->array_len++;
}
assert(index < i->in_queue->array_size);
frame = &i->in_queue->array[index];
@@ -450,7 +482,7 @@ static int stfu_n_find_frame(stfu_instance_t *in, stfu_queue_t *queue, uint32_t
for(i = 0; i < queue->real_array_size; i++) {
frame = &queue->array[i];
if ((seq && frame->seq == seq) || frame->ts == ts) {
if (((seq || in->last_seq) && frame->seq == seq) || frame->ts == ts) {
*r_frame = frame;
queue->last_index = i;
frame->was_read = 1;
@@ -468,7 +500,8 @@ stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i)
stfu_frame_t *rframe = NULL;
int found = 0;
if (!i->samples_per_packet || ((i->out_queue->wr_len == i->out_queue->array_len) || !i->out_queue->array_len)) {
if (!i->samples_per_packet || !i->out_queue->array_len) {
//|| ((i->out_queue->wr_len == i->out_queue->array_len) || !i->out_queue->array_len)) {
return NULL;
}
@@ -481,7 +514,11 @@ stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i)
if (i->cur_seq == 0) {
i->cur_seq = i->out_queue->array[0].seq;
} else {
i->cur_seq++;
i->cur_seq++;
/* if we bother using this for anything that doesn't have 16 bit seq, we'll make this a param */
if (i->cur_seq == 65535) {
i->cur_seq = 0;
}
}
if (!(found = stfu_n_find_frame(i, i->out_queue, i->cur_ts, i->cur_seq, &rframe))) {
@@ -496,7 +533,7 @@ stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i)
i->cur_seq = rframe->seq;
i->cur_ts = rframe->ts;
}
i->sync--;
i->sync = 0;
}
@@ -546,8 +583,7 @@ stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i)
#ifdef DB_JB
if (found) {
printf("O: %u:%u %u\n", rframe->seq, rframe->seq, rframe->plc);
assert(found && rframe->seq);
printf("O: %u:%u %u %d\n", rframe->seq, rframe->ts, rframe->plc, rframe->seq - i->last_seq);
} else {
printf("DATA: %u %u %d %s %d\n", i->packet_count, i->consecutive_good_count, i->out_queue->last_jitter, found ? "found" : "not found", i->qlen);
}
@@ -579,6 +615,7 @@ stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i)
rframe = &i->out_queue->int_frame;
rframe->dlen = i->plc_len;
#if 0
if (i->last_frame) {
/* poor man's plc.. Copy the last frame, but we flag it so you can use a better one if you wish */
if (i->miss_count) {
@@ -587,7 +624,7 @@ stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i)
memcpy(rframe->data, i->last_frame->data, rframe->dlen);
}
}
#endif
rframe->ts = i->cur_ts;
i->miss_count++;