add resize func

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@14871 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2009-09-15 18:45:19 +00:00
parent e4258a83a9
commit 74c7d58adf
2 changed files with 54 additions and 1 deletions

View File

@ -54,6 +54,22 @@ struct stfu_instance {
};
static stfu_status_t stfu_n_resize_aqueue(stfu_queue_t *queue, uint32_t qlen)
{
unsigned char *m;
if (qlen <= queue->array_size) {
return STFU_IT_FAILED;;
}
m = realloc(queue->array, qlen * sizeof(struct stfu_frame));
assert(m);
memset(m + queue->array_size, 0, qlen * sizeof(struct stfu_frame) - queue->array_size);
queue->array = (struct stfu_frame *) m;
queue->array_size = qlen;
return STFU_IT_WORKED;
}
static void stfu_n_init_aqueue(stfu_queue_t *queue, uint32_t qlen)
{
queue->array = calloc(qlen, sizeof(struct stfu_frame));
@ -76,6 +92,26 @@ void stfu_n_destroy(stfu_instance_t **i)
}
}
void stfu_n_report(stfu_instance_t *i, stfu_report_t *r)
{
assert(i);
r->in_len = i->in_queue->array_len;
r->in_size = i->in_queue->array_size;
r->out_len = i->out_queue->array_len;
r->out_size = i->out_queue->array_size;
}
stfu_status_t stfu_n_resize(stfu_instance_t *i, uint32_t qlen)
{
stfu_status_t s;
if ((s = stfu_n_resize_aqueue(&i->a_queue, qlen)) == STFU_IT_WORKED) {
s = stfu_n_resize_aqueue(&i->b_queue, qlen);
}
return s;
}
stfu_instance_t *stfu_n_init(uint32_t qlen)
{
struct stfu_instance *i;
@ -165,7 +201,13 @@ stfu_status_t stfu_n_add_data(stfu_instance_t *i, uint32_t ts, void *data, size_
i->miss_count = 0;
if (stfu_n_process(i, i->out_queue) < 0) {
return STFU_IT_FAILED;
if (i->in_queue->array_len == i->in_queue->array_size && i->out_queue->array_len == i->out_queue->array_size) {
stfu_n_resize(i, i->out_queue->array_size * 2);
printf("DOH RESIZE\n");
}
//return STFU_IT_FAILED;
}
for(index = 0; index < i->out_queue->array_len; index++) {
i->out_queue->array[index].was_read = 0;

View File

@ -84,8 +84,19 @@ typedef struct stfu_frame stfu_frame_t;
struct stfu_instance;
typedef struct stfu_instance stfu_instance_t;
typedef struct {
uint32_t in_len;
uint32_t in_size;
uint32_t out_len;
uint32_t out_size;
} stfu_report_t;
void stfu_n_report(stfu_instance_t *i, stfu_report_t *r);
void stfu_n_destroy(stfu_instance_t **i);
stfu_instance_t *stfu_n_init(uint32_t qlen);
stfu_status_t stfu_n_resize(stfu_instance_t *i, uint32_t qlen);
stfu_status_t stfu_n_add_data(stfu_instance_t *i, uint32_t ts, void *data, size_t datalen, int last);
stfu_frame_t *stfu_n_read_a_frame(stfu_instance_t *i);
void stfu_n_reset(stfu_instance_t *i);