From 426739b6b9614d1d3bf6aab98d9bca4d56d5fb1b Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Sun, 20 May 2007 01:50:01 +0000 Subject: [PATCH] interval git-svn-id: http://svn.openzap.org/svn/openzap/trunk@41 a93c3328-9c30-0410-af19-c9cd2b2d52af --- libs/openzap/src/include/openzap.h | 3 +++ libs/openzap/src/include/zap_types.h | 6 ++++-- libs/openzap/src/openzap.c | 25 ++++++++++++++++++++++++- libs/openzap/src/zap_wanpipe.c | 7 +++++-- 4 files changed, 36 insertions(+), 5 deletions(-) diff --git a/libs/openzap/src/include/openzap.h b/libs/openzap/src/include/openzap.h index d2a6fc08e6..8f4b012a80 100644 --- a/libs/openzap/src/include/openzap.h +++ b/libs/openzap/src/include/openzap.h @@ -166,6 +166,9 @@ struct zap_channel { zap_channel_feature_t features; zap_codec_t effective_codec; zap_codec_t native_codec; + uint32_t effective_interval; + uint32_t native_interval; + uint32_t packet_len; teletone_dtmf_detect_state_t dtmf_detect; zap_event_t event_header; char last_error[256]; diff --git a/libs/openzap/src/include/zap_types.h b/libs/openzap/src/include/zap_types.h index 1d274de2b6..a4fdae24fd 100644 --- a/libs/openzap/src/include/zap_types.h +++ b/libs/openzap/src/include/zap_types.h @@ -109,7 +109,8 @@ typedef enum { typedef enum { ZAP_CHANNEL_FEATURE_DTMF = (1 << 0), - ZAP_CHANNEL_FEATURE_CODECS = (1 << 1) + ZAP_CHANNEL_FEATURE_CODECS = (1 << 1), + ZAP_CHANNEL_FEATURE_INTERVAL = (1 << 2) } zap_channel_feature_t; typedef enum { @@ -118,7 +119,8 @@ typedef enum { ZAP_CHANNEL_OPEN = (1 << 2), ZAP_CHANNEL_DTMF_DETECT = (1 << 3), ZAP_CHANNEL_SUPRESS_DTMF = (1 << 4), - ZAP_CHANNEL_TRANSCODE = (1 << 5) + ZAP_CHANNEL_TRANSCODE = (1 << 5), + ZAP_CHANNEL_BUFFER = (1 << 6) } zap_channel_flag_t; typedef struct zap_channel zap_channel_t; diff --git a/libs/openzap/src/openzap.c b/libs/openzap/src/openzap.c index eb32bb35ec..b10227bb63 100644 --- a/libs/openzap/src/openzap.c +++ b/libs/openzap/src/openzap.c @@ -414,7 +414,29 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } switch(command) { - case ZAP_COMMAND_SET_CODEC: + case ZAP_COMMAND_SET_INTERVAL: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL)) { + zchan->effective_interval = ZAP_COMMAND_OBJ_INT; + if (zchan->effective_interval == zchan->native_interval) { + zap_clear_flag(zchan, ZAP_CHANNEL_BUFFER); + } else { + zap_set_flag(zchan, ZAP_CHANNEL_BUFFER); + } + zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); + return ZAP_SUCCESS; + } + } + break; + case ZAP_COMMAND_GET_INTERVAL: + { + if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL)) { + ZAP_COMMAND_OBJ_INT = zchan->effective_interval; + return ZAP_SUCCESS; + } + } + break; + case ZAP_COMMAND_SET_CODEC: { if (!zap_channel_test_feature(zchan, ZAP_CHANNEL_FEATURE_CODECS)) { zchan->effective_codec = ZAP_COMMAND_OBJ_INT; @@ -423,6 +445,7 @@ zap_status_t zap_channel_command(zap_channel_t *zchan, zap_command_t command, vo } else { zap_set_flag(zchan, ZAP_CHANNEL_TRANSCODE); } + zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); return ZAP_SUCCESS; } } diff --git a/libs/openzap/src/zap_wanpipe.c b/libs/openzap/src/zap_wanpipe.c index e9f879effb..7d5c9a8de9 100644 --- a/libs/openzap/src/zap_wanpipe.c +++ b/libs/openzap/src/zap_wanpipe.c @@ -76,7 +76,6 @@ static unsigned wp_open_range(zap_span_t *span, unsigned spanno, unsigned start, if (sockfd != WP_INVALID_SOCKET && zap_span_add_channel(span, sockfd, type, &chan) == ZAP_SUCCESS) { zap_log(ZAP_LOG_INFO, "configuring device s%dc%d as OpenZAP device %d:%d fd:%d\n", spanno, x, chan->span_id, chan->chan_id, sockfd); configured++; - } else { zap_log(ZAP_LOG_ERROR, "failure configuring device s%dc%d\n", spanno, x); } @@ -250,7 +249,10 @@ static ZINT_OPEN_FUNCTION(wanpipe_open) tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; tdm_api.wp_tdm_cmd.usr_period = wp_globals.codec_ms; wp_tdm_cmd_exec(zchan, &tdm_api); - + zap_channel_set_feature(zchan, ZAP_CHANNEL_FEATURE_INTERVAL); + zchan->effective_interval = zchan->native_interval = wp_globals.codec_ms; + zchan->packet_len = zchan->native_interval * 8; + tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_GET_HW_CODING; if (tdm_api.wp_tdm_cmd.hw_tdm_coding) { zchan->native_codec = zchan->effective_codec = ZAP_CODEC_ULAW; @@ -293,6 +295,7 @@ static ZINT_COMMAND_FUNCTION(wanpipe_command) tdm_api.wp_tdm_cmd.cmd = SIOC_WP_TDM_SET_USR_PERIOD; tdm_api.wp_tdm_cmd.usr_period = ZAP_COMMAND_OBJ_INT; err = wp_tdm_cmd_exec(zchan, &tdm_api); + zchan->packet_len = zchan->native_interval * (zchan->effective_codec == ZAP_CODEC_SLIN ? 16 : 8); } break; default: