analog update

git-svn-id: http://svn.openzap.org/svn/openzap/trunk@155 a93c3328-9c30-0410-af19-c9cd2b2d52af
This commit is contained in:
Anthony Minessale 2007-05-26 03:27:31 +00:00
parent 479628543d
commit 08e7a925ec
3 changed files with 47 additions and 46 deletions

View File

@ -93,7 +93,8 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
zap_channel_t *closed_chan; zap_channel_t *closed_chan;
uint32_t state_counter = 0, elapsed = 0, interval = 0, last_digit = 0, indicate = 0; uint32_t state_counter = 0, elapsed = 0, interval = 0, last_digit = 0, indicate = 0;
zap_sigmsg_t sig; zap_sigmsg_t sig;
zap_status_t status;
zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n"); zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread starting.\n");
if (zap_channel_open_chan(chan) != ZAP_SUCCESS) { if (zap_channel_open_chan(chan) != ZAP_SUCCESS) {
@ -101,10 +102,12 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
} }
if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) { if (zap_buffer_create(&dt_buffer, 1024, 3192, 0) != ZAP_SUCCESS) {
snprintf(chan->last_error, sizeof(chan->last_error), "memory error!");
goto done; goto done;
} }
if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_TONE_DETECT, &tt) != ZAP_SUCCESS) { if (zap_channel_command(chan, ZAP_COMMAND_ENABLE_TONE_DETECT, &tt) != ZAP_SUCCESS) {
snprintf(chan->last_error, sizeof(chan->last_error), "error initilizing tone detector!");
goto done; goto done;
} }
@ -143,18 +146,17 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
case ZAP_CHANNEL_STATE_UP: case ZAP_CHANNEL_STATE_UP:
case ZAP_CHANNEL_STATE_IDLE: case ZAP_CHANNEL_STATE_IDLE:
{ {
zap_sleep(interval); zap_sleep(interval);
continue; continue;
} }
break; break;
default: default:
break; break;
} }
} else { } else {
zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE); zap_clear_flag_locked(chan, ZAP_CHANNEL_STATE_CHANGE);
indicate = 0;
state_counter = 0;
switch(chan->state) { switch(chan->state) {
case ZAP_CHANNEL_STATE_UP: case ZAP_CHANNEL_STATE_UP:
{ {
@ -191,7 +193,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
indicate = 1; indicate = 1;
} }
break; break;
case ZAP_CHANNEL_STATE_RING: case ZAP_CHANNEL_STATE_RING:
{ {
zap_buffer_zero(dt_buffer); zap_buffer_zero(dt_buffer);
@ -199,7 +200,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
indicate = 1; indicate = 1;
} }
break; break;
case ZAP_CHANNEL_STATE_BUSY: case ZAP_CHANNEL_STATE_BUSY:
{ {
zap_buffer_zero(dt_buffer); zap_buffer_zero(dt_buffer);
@ -207,7 +207,6 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
indicate = 1; indicate = 1;
} }
break; break;
case ZAP_CHANNEL_STATE_ATTN: case ZAP_CHANNEL_STATE_ATTN:
{ {
zap_buffer_zero(dt_buffer); zap_buffer_zero(dt_buffer);
@ -216,13 +215,9 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
} }
break; break;
default: default:
indicate = 0;
break; break;
} }
state_counter = 0;
} }
if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) { if ((dlen = zap_channel_dequeue_dtmf(chan, dtmf + dtmf_offset, sizeof(dtmf) - strlen(dtmf)))) {
if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) { if (chan->state == ZAP_CHANNEL_STATE_DIALTONE || chan->state == ZAP_CHANNEL_STATE_COLLECT) {
@ -241,55 +236,59 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
last_digit = 0; last_digit = 0;
} }
if (zap_channel_wait(chan, &flags, -1) == ZAP_FAIL) { if (zap_channel_wait(chan, &flags, interval * 2) == ZAP_FAIL) {
goto done; goto done;
} }
if (flags & ZAP_READ) { if (!(flags & ZAP_READ)) {
if (zap_channel_read(chan, frame, &len) == ZAP_SUCCESS) { continue;
if (chan->effective_codec != ZAP_CODEC_SLIN) { }
len *= 2;
}
rlen = zap_buffer_read_loop(dt_buffer, frame, len);
if (indicate) {
zio_codec_t codec_func = NULL;
zap_status_t status;
if (chan->effective_codec != ZAP_CODEC_SLIN) {
if (chan->native_codec == ZAP_CODEC_ULAW) {
codec_func = zio_slin2ulaw;
} else if (chan->native_codec == ZAP_CODEC_ALAW) {
codec_func = zio_slin2alaw;
}
if (codec_func) {
status = codec_func(frame, sizeof(frame), &rlen);
} else {
snprintf(chan->last_error, sizeof(chan->last_error), "codec error!");
status = ZAP_FAIL;
}
}
zap_channel_write(chan, frame, &rlen); if (zap_channel_read(chan, frame, &len) != ZAP_SUCCESS) {
} goto done;
}
if (!indicate) {
continue;
}
if (chan->effective_codec != ZAP_CODEC_SLIN) {
len *= 2;
}
rlen = zap_buffer_read_loop(dt_buffer, frame, len);
if (chan->effective_codec != ZAP_CODEC_SLIN) {
zio_codec_t codec_func = NULL;
if (chan->native_codec == ZAP_CODEC_ULAW) {
codec_func = zio_slin2ulaw;
} else if (chan->native_codec == ZAP_CODEC_ALAW) {
codec_func = zio_slin2alaw;
}
if (codec_func) {
status = codec_func(frame, sizeof(frame), &rlen);
} else { } else {
snprintf(chan->last_error, sizeof(chan->last_error), "codec error!");
goto done; goto done;
} }
} }
}
done:
zap_channel_write(chan, frame, &rlen);
}
done:
closed_chan = chan; closed_chan = chan;
zap_channel_close(&chan); zap_channel_close(&chan);
zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL); zap_channel_command(closed_chan, ZAP_COMMAND_SET_NATIVE_CODEC, NULL);
if (ts.buffer) { if (ts.buffer) {
teletone_destroy_session(&ts); teletone_destroy_session(&ts);
} }
if (dt_buffer) { if (dt_buffer) {
zap_buffer_destroy(&dt_buffer); zap_buffer_destroy(&dt_buffer);
} }
@ -297,6 +296,7 @@ static void *zap_analog_channel_run(zap_thread_t *me, void *obj)
zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD); zap_clear_flag(closed_chan, ZAP_CHANNEL_INTHREAD);
zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended.\n"); zap_log(ZAP_LOG_DEBUG, "ANALOG CHANNEL thread ended.\n");
return NULL; return NULL;
} }

View File

@ -242,6 +242,7 @@ void zap_buffer_zero(zap_buffer_t *buffer)
assert(buffer->data != NULL); assert(buffer->data != NULL);
buffer->used = 0; buffer->used = 0;
buffer->actually_used = 0;
buffer->head = buffer->data; buffer->head = buffer->data;
} }

View File

@ -1081,7 +1081,7 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data
} }
if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) { if (zap_test_flag(zchan, ZAP_CHANNEL_DTMF_DETECT)) {
uint8_t sln_buf[2048] = {0}; uint8_t sln_buf[1024] = {0};
int16_t *sln; int16_t *sln;
zap_size_t slen = 0; zap_size_t slen = 0;
char digit_str[80] = ""; char digit_str[80] = "";
@ -1094,11 +1094,11 @@ zap_status_t zap_channel_read(zap_channel_t *zchan, void *data, zap_size_t *data
uint32_t i; uint32_t i;
uint8_t *lp = data; uint8_t *lp = data;
slen = sizeof(sln_buf); slen = sizeof(sln_buf) / 2;
if (len > slen) { if (len > slen) {
len = slen; len = slen;
} }
sln = (int16_t *) sln_buf; sln = (int16_t *) sln_buf;
for(i = 0; i < len; i++) { for(i = 0; i < len; i++) {
if (zchan->effective_codec == ZAP_CODEC_ULAW) { if (zchan->effective_codec == ZAP_CODEC_ULAW) {