Numerous little changes to spandsp that haven't been pushed to Freeswitch for a

while. The only big changes are a majorly rewritten V.42 and V.42bis which are
now basically functional.
This commit is contained in:
Steve Underwood committed 2011-07-02 14:45:27 +08:00
1 parent 6f62f39139
commit d30e82e226
68 files changed
+2513 -2114

No files matched your search

+5 -13
View File
@@ -23,11 +23,11 @@ LIBS += $(TESTLIBS)
noinst_DATA = sound_c1_8k.wav sound_c3_8k.wav
EXTRA_DIST = regression_tests.sh \
EXTRA_DIST = fax_tests.sh \
regression_tests.sh \
tsb85_extra_tests.sh \
v42bis_tests.sh \
fax_tests.sh \
tsb85_tests.sh \
v42bis_tests.sh \
msvc/adsi_tests.vcproj \
msvc/complex_tests.vcproj \
msvc/complex_vector_float_tests.vcproj \
@@ -102,15 +102,15 @@ noinst_PROGRAMS = adsi_tests \
super_tone_rx_tests \
super_tone_tx_tests \
swept_tone_tests \
t4_tests \
t31_tests \
t38_decode \
t38_core_tests \
t38_decode \
t38_gateway_tests \
t38_gateway_to_terminal_tests \
t38_non_ecm_buffer_tests \
t38_terminal_tests \
t38_terminal_to_gateway_tests \
t4_tests \
time_scale_tests \
timezone_tests \
tone_detect_tests \
@@ -126,8 +126,6 @@ noinst_PROGRAMS = adsi_tests \
v8_tests \
vector_float_tests \
vector_int_tests \
testadsi \
testfax \
tsb85_tests
noinst_HEADERS = echo_monitor.h \
@@ -364,12 +362,6 @@ vector_float_tests_LDADD = $(LIBDIR) -lspandsp
vector_int_tests_SOURCES = vector_int_tests.c
vector_int_tests_LDADD = $(LIBDIR) -lspandsp
testadsi_SOURCES = testadsi.c
testadsi_LDADD = $(LIBDIR) -lspandsp
testfax_SOURCES = testfax.c
testfax_LDADD = $(LIBDIR) -lspandsp
# We need to create the CSS files for echo cancellation tests.
sound_c1_8k.wav sound_c3_8k.wav: make_g168_css$(EXEEXT)
+3 -3
View File
@@ -80,7 +80,7 @@ static int phase_b_handler(t30_state_t *s, void *user_data, int result)
char tag[20];
i = (int) (intptr_t) user_data;
snprintf(tag, sizeof(tag), "%c: Phase B:", i);
snprintf(tag, sizeof(tag), "%c: Phase B", i);
printf("%c: Phase B handler on channel %c - (0x%X) %s\n", i, i, result, t30_frametype(result));
log_rx_parameters(s, tag);
return T30_ERR_OK;
@@ -93,7 +93,7 @@ static int phase_d_handler(t30_state_t *s, void *user_data, int result)
char tag[20];
i = (int) (intptr_t) user_data;
snprintf(tag, sizeof(tag), "%c: Phase D:", i);
snprintf(tag, sizeof(tag), "%c: Phase D", i);
printf("%c: Phase D handler on channel %c - (0x%X) %s\n", i, i, result, t30_frametype(result));
log_transfer_statistics(s, tag);
log_tx_parameters(s, tag);
@@ -136,7 +136,7 @@ static void phase_e_handler(t30_state_t *s, void *user_data, int result)
char tag[20];
i = (intptr_t) user_data;
snprintf(tag, sizeof(tag), "%c: Phase E:", i);
snprintf(tag, sizeof(tag), "%c: Phase E", i);
printf("%c: Phase E handler on channel %c - (%d) %s\n", i, i, result, t30_completion_code_to_str(result));
log_transfer_statistics(s, tag);
log_tx_parameters(s, tag);
+3
View File
@@ -123,6 +123,9 @@ int main(int argc, char *argv[])
}
}
encoded_fd = -1;
inhandle = NULL;
oki_enc_state = NULL;
if (encoded_file_name)
{
if ((encoded_fd = open(encoded_file_name, O_RDONLY)) < 0)
+82 -13
View File
@@ -34,14 +34,17 @@
#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#if defined(HAVE_PCAP_H)
#include <pcap.h>
#endif
#include <netinet/in.h>
#include <netinet/udp.h>
#if defined(__HPUX) || defined(__CYGWIN) || defined(__FreeBSD__)
#if defined(__HPUX) || defined(__CYGWIN__) || defined(__FreeBSD__)
#include <netinet/in_systm.h>
#endif
#include <netinet/ip.h>
#ifndef __CYGWIN
#if !defined(__CYGWIN__)
#include <netinet/ip6.h>
#endif
#include <string.h>
@@ -55,7 +58,7 @@
#include "spandsp.h"
#include "pcap_parse.h"
#if defined(__HPUX) || defined(__DARWIN) || defined(__CYGWIN) || defined(__FreeBSD__)
#if defined(__HPUX) || defined(__DARWIN) || defined(__CYGWIN__) || defined(__FreeBSD__)
struct iphdr
{
@@ -90,15 +93,22 @@ typedef struct _ether_hdr
{
char ether_dst[6];
char ether_src[6];
u_int16_t ether_type; /* we only need the type, so we can determine, if the next header is IPv4 or IPv6 */
u_int16_t ether_type;
} ether_hdr;
typedef struct _null_hdr
{
uint32_t pf_type;
} null_hdr;
#if !defined(__CYGWIN__)
typedef struct _ipv6_hdr
{
char dontcare[6];
u_int8_t nxt_header; /* we only need the next header, so we can determine, if the next header is UDP or not */
char dontcare2[33];
} ipv6_hdr;
#endif
char errbuf[PCAP_ERRBUF_SIZE];
@@ -119,9 +129,14 @@ int pcap_scan_pkts(const char *file,
int total_pkts;
uint32_t pktlen;
ether_hdr *ethhdr;
null_hdr *nullhdr;
struct iphdr *iphdr;
#if !defined(__CYGWIN__)
ipv6_hdr *ip6hdr;
#endif
struct udphdr *udphdr;
int datalink;
int packet_type;
total_pkts = 0;
if ((pcap = pcap_open_offline(file, errbuf)) == NULL)
@@ -129,6 +144,15 @@ int pcap_scan_pkts(const char *file,
fprintf(stderr, "Can't open PCAP file '%s'\n", file);
return -1;
}
datalink = pcap_datalink(pcap);
/* DLT_EN10MB seems to apply to all forms of ethernet, not just the 10MB kind. */
if (datalink != DLT_EN10MB && datalink != DLT_NULL)
{
fprintf(stderr, "Unsupported data link type %d\n", datalink);
return -1;
}
printf("Datalink type %d\n", datalink);
pkthdr = NULL;
pktdata = NULL;
#if defined(HAVE_PCAP_NEXT_EX)
@@ -143,14 +167,43 @@ int pcap_scan_pkts(const char *file,
while ((pktdata = (uint8_t *) pcap_next(pcap, pkthdr)) != NULL)
{
#endif
ethhdr = (ether_hdr *) pktdata;
if (ntohs(ethhdr->ether_type) != 0x0800 /* IPv4 */
&&
ntohs(ethhdr->ether_type) != 0x86dd) /* IPv6 */
if (datalink == DLT_EN10MB)
{
ethhdr = (ether_hdr *) pktdata;
packet_type = ntohs(ethhdr->ether_type);
#if !defined(__CYGWIN__)
if (packet_type != 0x0800 /* IPv4 */
&&
packet_type != 0x86DD) /* IPv6 */
#else
if (packet_type != 0x0800) /* IPv4 */
#endif
{
continue;
}
iphdr = (struct iphdr *) ((uint8_t *) ethhdr + sizeof(*ethhdr));
}
else if (datalink == DLT_NULL)
{
nullhdr = (null_hdr *) pktdata;
if (nullhdr->pf_type != PF_INET && nullhdr->pf_type != PF_INET6)
continue;
iphdr = (struct iphdr *) ((uint8_t *) nullhdr + sizeof(*nullhdr));
}
else
{
continue;
}
iphdr = (struct iphdr *) ((uint8_t *) ethhdr + sizeof(*ethhdr));
#if 0
{
int i;
printf("--- %d -", pkthdr->caplen);
for (i = 0; i < pkthdr->caplen; i++)
printf(" %02x", pktdata[i]);
printf("\n");
}
#endif
#if !defined(__CYGWIN__)
if (iphdr && iphdr->version == 6)
{
/* ipv6 */
@@ -161,11 +214,12 @@ int pcap_scan_pkts(const char *file,
udphdr = (struct udphdr *) ((uint8_t *) ip6hdr + sizeof(*ip6hdr));
}
else
#endif
{
/* ipv4 */
if (iphdr->protocol != IPPROTO_UDP)
continue;
#if defined(__DARWIN) || defined(__CYGWIN) || defined(__FreeBSD__)
#if defined(__DARWIN) || defined(__CYGWIN__) || defined(__FreeBSD__)
udphdr = (struct udphdr *) ((uint8_t *) iphdr + (iphdr->ihl << 2) + 4);
pktlen = (uint32_t) ntohs(udphdr->uh_ulen);
#elif defined ( __HPUX)
@@ -176,24 +230,39 @@ int pcap_scan_pkts(const char *file,
pktlen = (uint32_t) ntohs(udphdr->len);
#endif
}
timing_update_handler(user_data, &pkthdr->ts);
if (src_addr && ntohl(iphdr->saddr) != src_addr)
continue;
#if defined(__DARWIN) || defined(__CYGWIN__) || defined(__FreeBSD__)
if (src_port && ntohs(udphdr->uh_sport) != src_port)
#else
if (src_port && ntohs(udphdr->source) != src_port)
#endif
continue;
if (dest_addr && ntohl(iphdr->daddr) != dest_addr)
continue;
#if defined(__DARWIN) || defined(__CYGWIN__) || defined(__FreeBSD__)
if (dest_port && ntohs(udphdr->uh_dport) != dest_port)
#else
if (dest_port && ntohs(udphdr->dest) != dest_port)
#endif
continue;
if (pkthdr->len != pkthdr->caplen)
{
fprintf(stderr, "Truncated packet - total len = %d, captured len = %d\n", pkthdr->len, pkthdr->caplen);
exit(2);
}
body = (const uint8_t *) udphdr;
body += sizeof(udphdr);
body_len = pktlen - sizeof(udphdr);
body += sizeof(struct udphdr);
body_len = pktlen - sizeof(struct udphdr);
packet_handler(user_data, body, body_len);
total_pkts++;
}
fprintf(stderr, "In pcap %s, npkts %d\n", file, total_pkts);
fprintf(stderr, "In pcap %s there were %d accepted packets\n", file, total_pkts);
pcap_close(pcap);
return 0;
+16 -18
View File
@@ -846,25 +846,23 @@ echo v29_tests completed OK
#fi
#echo v32bis_tests completed OK
#./v42_tests >$STDOUT_DEST 2>$STDERR_DEST
#RETVAL=$?
#if [ $RETVAL != 0 ]
#then
# echo v42_tests failed!
# exit $RETVAL
#fi
#echo v42_tests completed OK
echo v42_tests not enabled
./v42_tests >$STDOUT_DEST 2>$STDERR_DEST
RETVAL=$?
if [ $RETVAL != 0 ]
then
echo v42_tests failed!
exit $RETVAL
fi
echo v42_tests completed OK
#./v42bis_tests.sh >/dev/null
#RETVAL=$?
#if [ $RETVAL != 0 ]
#then
# echo v42bis_tests failed!
# exit $RETVAL
#fi
#echo v42bis_tests completed OK
echo v42bis_tests not enabled
./v42bis_tests.sh >/dev/null
RETVAL=$?
if [ $RETVAL != 0 ]
then
echo v42bis_tests failed!
exit $RETVAL
fi
echo v42bis_tests completed OK
./v8_tests >$STDOUT_DEST 2>$STDERR_DEST
RETVAL=$?
+3 -3
View File
@@ -280,7 +280,7 @@ static int phase_b_handler(t30_state_t *s, void *user_data, int result)
char tag[20];
i = (int) (intptr_t) user_data;
snprintf(tag, sizeof(tag), "%c: Phase B:", i);
snprintf(tag, sizeof(tag), "%c: Phase B", i);
printf("%c: Phase B handler on channel %c - (0x%X) %s\n", i, i, result, t30_frametype(result));
log_rx_parameters(s, tag);
return T30_ERR_OK;
@@ -293,7 +293,7 @@ static int phase_d_handler(t30_state_t *s, void *user_data, int result)
char tag[20];
i = (int) (intptr_t) user_data;
snprintf(tag, sizeof(tag), "%c: Phase D:", i);
snprintf(tag, sizeof(tag), "%c: Phase D", i);
printf("%c: Phase D handler on channel %c - (0x%X) %s\n", i, i, result, t30_frametype(result));
log_transfer_statistics(s, tag);
log_tx_parameters(s, tag);
@@ -308,7 +308,7 @@ static void phase_e_handler(t30_state_t *s, void *user_data, int result)
char tag[20];
i = (intptr_t) user_data;
snprintf(tag, sizeof(tag), "%c: Phase E:", i);
snprintf(tag, sizeof(tag), "%c: Phase E", i);
printf("Phase E handler on channel %c\n", i);
log_transfer_statistics(s, tag);
log_tx_parameters(s, tag);
+21 -7
View File
@@ -1,7 +1,7 @@
/*
* SpanDSP - a series of DSP components for telephony
*
* pcap-parse.c
* t38_decode.c
*
* Written by Steve Underwood <steveu@coppice.org>
*
@@ -53,6 +53,7 @@
#define OUTPUT_FILE_NAME "t38pcap.tif"
t38_terminal_state_t *t38_state;
struct timeval now;
static int phase_b_handler(t30_state_t *s, void *user_data, int result)
{
@@ -110,29 +111,35 @@ static int timing_update(void *user_data, struct timeval *ts)
t38_core_state_t *t38_core;
logging_state_t *logging;
int samples;
int partial;
static int64_t current = 0;
int64_t when;
int64_t diff;
memcpy(&now, ts, sizeof(now));
when = ts->tv_sec*1000000LL + ts->tv_usec;
if (current == 0)
current = when;
diff = when - current;
samples = diff/125LL;
if (samples > 0)
while (samples > 0)
{
partial = (samples > 160) ? 160 : samples;
//fprintf(stderr, "Update time by %d samples\n", partial);
logging = t38_terminal_get_logging_state(t38_state);
span_log_bump_samples(logging, samples);
span_log_bump_samples(logging, partial);
t38_core = t38_terminal_get_t38_core_state(t38_state);
logging = t38_core_get_logging_state(t38_core);
span_log_bump_samples(logging, samples);
span_log_bump_samples(logging, partial);
t30 = t38_terminal_get_t30_state(t38_state);
logging = t30_get_logging_state(t30);
span_log_bump_samples(logging, samples);
span_log_bump_samples(logging, partial);
t38_terminal_send_timeout(t38_state, samples);
t38_terminal_send_timeout(t38_state, partial);
current = when;
samples -= partial;
}
return 0;
}
@@ -188,6 +195,7 @@ int main(int argc, char *argv[])
use_ecm = FALSE;
t38_version = 1;
options = 0;
input_file_name = INPUT_FILE_NAME;
fill_removal = FALSE;
use_tep = FALSE;
@@ -196,7 +204,7 @@ int main(int argc, char *argv[])
src_port = 0;
dest_addr = 0;
dest_port = 0;
while ((opt = getopt(argc, argv, "D:d:eFi:m:S:s:tv:")) != -1)
while ((opt = getopt(argc, argv, "D:d:eFi:m:oS:s:tv:")) != -1)
{
switch (opt)
{
@@ -218,6 +226,9 @@ int main(int argc, char *argv[])
case 'm':
supported_modems = atoi(optarg);
break;
case 'o':
options = atoi(optarg);
break;
case 'S':
src_addr = atoi(optarg);
break;
@@ -272,6 +283,9 @@ int main(int argc, char *argv[])
if (pcap_scan_pkts(input_file_name, src_addr, src_port, dest_addr, dest_port, timing_update, process_packet, NULL))
exit(2);
/* Push the time along, to flush out any remaining activity from the application. */
now.tv_sec += 60;
timing_update(NULL, &now);
}
/*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/
@@ -595,7 +595,7 @@ int main(int argc, char *argv[])
logging = t38_core_get_logging_state(t38_core);
span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
logging = &t38_state_a->audio.modems.v17_rx.logging;
span_log_bump_samples(logging, t30_len_a);
span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
logging = t38_terminal_get_logging_state(t38_state_b);
span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
+86 -86
View File
@@ -1,86 +1,86 @@
/*
* SpanDSP - a series of DSP components for telephony
*
* timezone_tests.c - Timezone handling for time interpretation
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2010 Steve Underwood
*
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*! \page timezone_tests_page Timezone handling tests
\section timezone_tests_page_sec_1 What does it do?
*/
#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif
#include <stdlib.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
//#if defined(WITH_SPANDSP_INTERNALS)
#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
//#endif
#include "spandsp.h"
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
int main(int argc, char *argv[])
{
struct tm tms;
struct tm *tmp = &tms;
time_t ltime;
tz_t *tz;
/* Get the current time */
ltime = time(NULL);
/* Compute the local current time now for several localities, based on Posix tz strings */
tz = tz_init(NULL, "GMT0GMT0,M10.5.0,M3.5.0");
tz_localtime(tz, tmp, ltime);
printf("Local time is %02d:%02d:%02d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
printf("Time zone is %s\n", tz_tzname(tz, tmp->tm_isdst));
tz_init(tz, "CST-8CST-8,M10.5.0,M3.5.0");
tz_localtime(tz, tmp, ltime);
printf("Local time is %02d:%02d:%02d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
printf("Time zone is %s\n", tz_tzname(tz, tmp->tm_isdst));
tz_init(tz, "AEST-10AEDT-11,M10.5.0,M3.5.0");
tz_localtime(tz, tmp, ltime);
printf("Local time is %02d:%02d:%02d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
printf("Time zone is %s\n", tz_tzname(tz, tmp->tm_isdst));
tz_free(tz);
return 0;
}
/*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/
/*
* SpanDSP - a series of DSP components for telephony
*
* timezone_tests.c - Timezone handling for time interpretation
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2010 Steve Underwood
*
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 2.1,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*! \page timezone_tests_page Timezone handling tests
\section timezone_tests_page_sec_1 What does it do?
*/
#if defined(HAVE_CONFIG_H)
#include "config.h"
#endif
#include <stdlib.h>
#include <inttypes.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
//#if defined(WITH_SPANDSP_INTERNALS)
#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
//#endif
#include "spandsp.h"
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE (!FALSE)
#endif
int main(int argc, char *argv[])
{
struct tm tms;
struct tm *tmp = &tms;
time_t ltime;
tz_t *tz;
/* Get the current time */
ltime = time(NULL);
/* Compute the local current time now for several localities, based on Posix tz strings */
tz = tz_init(NULL, "GMT0GMT0,M10.5.0,M3.5.0");
tz_localtime(tz, tmp, ltime);
printf("Local time is %02d:%02d:%02d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
printf("Time zone is %s\n", tz_tzname(tz, tmp->tm_isdst));
tz_init(tz, "CST-8CST-8,M10.5.0,M3.5.0");
tz_localtime(tz, tmp, ltime);
printf("Local time is %02d:%02d:%02d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
printf("Time zone is %s\n", tz_tzname(tz, tmp->tm_isdst));
tz_init(tz, "AEST-10AEDT-11,M10.5.0,M3.5.0");
tz_localtime(tz, tmp, ltime);
printf("Local time is %02d:%02d:%02d\n", tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
printf("Time zone is %s\n", tz_tzname(tz, tmp->tm_isdst));
tz_free(tz);
return 0;
}
/*- End of function --------------------------------------------------------*/
/*- End of file ------------------------------------------------------------*/
+2 -2
View File
@@ -217,7 +217,7 @@ static int phase_d_handler(t30_state_t *s, void *user_data, int result)
char tag[20];
i = (intptr_t) user_data;
snprintf(tag, sizeof(tag), "%c: Phase D:", i);
snprintf(tag, sizeof(tag), "%c: Phase D", i);
printf("%c: Phase D handler on channel %c - (0x%X) %s\n", i, i, result, t30_frametype(result));
log_transfer_statistics(s, tag);
@@ -260,7 +260,7 @@ static void phase_e_handler(t30_state_t *s, void *user_data, int result)
char tag[20];
i = (intptr_t) user_data;
snprintf(tag, sizeof(tag), "%c: Phase E:", i);
snprintf(tag, sizeof(tag), "%c: Phase E", i);
printf("%c: Phase E handler on channel %c - (%d) %s\n", i, i, result, t30_completion_code_to_str(result));
log_transfer_statistics(s, tag);
log_tx_parameters(s, tag);
+1
View File
@@ -63,6 +63,7 @@ display of modem status is maintained.
#include <sndfile.h>
#include <signal.h>
#if defined(HAVE_FENV_H)
#define __USE_GNU
#include <fenv.h>
#endif
+1
View File
@@ -62,6 +62,7 @@ display of modem status is maintained.
#include <sndfile.h>
#include <signal.h>
#if defined(HAVE_FENV_H)
#define __USE_GNU
#include <fenv.h>
#endif
+1
View File
@@ -62,6 +62,7 @@ display of modem status is maintained.
#include <sndfile.h>
#include <signal.h>
#if defined(HAVE_FENV_H)
#define __USE_GNU
#include <fenv.h>
#endif
+90 -34
View File
@@ -5,7 +5,7 @@
*
* Written by Steve Underwood <steveu@coppice.org>
*
* Copyright (C) 2004 Steve Underwood
* Copyright (C) 2004, 2011 Steve Underwood
*
* All rights reserved.
*
@@ -32,10 +32,11 @@ then exchanged between them.
*/
#if defined(HAVE_CONFIG_H)
#include <config.h>
#include "config.h"
#endif
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
@@ -48,6 +49,7 @@ then exchanged between them.
v42_state_t caller;
v42_state_t answerer;
int variable_length;
int rx_next[3] = {0};
int tx_next[3] = {0};
@@ -55,66 +57,120 @@ int tx_next[3] = {0};
static void v42_status(void *user_data, int status)
{
int x;
x = (intptr_t) user_data;
printf("%d: Status is '%s' (%d)\n", x, lapm_status_to_str(status), status);
//if (status == LAPM_DATA)
// lapm_tx_iframe((x == 1) ? &caller.lapm : &answerer.lapm, "ABCDEFGHIJ", 10, 1);
}
static void v42_frames(void *user_data, const uint8_t *msg, int len)
x = (intptr_t) user_data;
if (status < 0)
printf("%d: Status is '%s' (%d)\n", x, signal_status_to_str(status), status);
else
printf("%d: Status is '%s' (%d)\n", x, lapm_status_to_str(status), status);
}
/*- End of function --------------------------------------------------------*/
static int v42_get_frames(void *user_data, uint8_t *msg, int len)
{
int i;
int j;
int k;
int x;
if (len < 0)
{
v42_status(user_data, len);
return 0;
}
x = (intptr_t) user_data;
if (variable_length)
{
j = make_mask32(len);
do
k = j & rand();
while (k > len);
}
else
{
k = len;
}
for (i = 0; i < k; i++)
msg[i] = tx_next[x]++;
return k;
}
/*- End of function --------------------------------------------------------*/
static void v42_put_frames(void *user_data, const uint8_t *msg, int len)
{
int i;
int x;
if (len < 0)
{
v42_status(user_data, len);
return;
}
x = (intptr_t) user_data;
for (i = 0; i < len; i++)
{
if (msg[i] != (rx_next[x] & 0xFF))
{
printf("%d: Mismatch 0x%02X 0x%02X\n", x, msg[i], rx_next[x] & 0xFF);
exit(2);
}
rx_next[x]++;
}
printf("%d: Got frame len %d\n", x, len);
}
/*- End of function --------------------------------------------------------*/
int main(int argc, char *argv[])
{
int i;
int bit;
uint8_t buf[1024];
int insert_caller_bit_errors;
int insert_answerer_bit_errors;
int opt;
v42_init(&caller, TRUE, TRUE, v42_frames, (void *) 1);
v42_init(&answerer, FALSE, TRUE, v42_frames, (void *) 2);
insert_caller_bit_errors = FALSE;
insert_answerer_bit_errors = FALSE;
variable_length = FALSE;
while ((opt = getopt(argc, argv, "bv")) != -1)
{
switch (opt)
{
case 'b':
insert_caller_bit_errors = 11000;
insert_answerer_bit_errors = 10000;
break;
case 'v':
variable_length = TRUE;
break;
default:
//usage();
exit(2);
break;
}
}
v42_init(&caller, TRUE, TRUE, v42_get_frames, v42_put_frames, (void *) 1);
v42_init(&answerer, FALSE, TRUE, v42_get_frames, v42_put_frames, (void *) 2);
v42_set_status_callback(&caller, v42_status, (void *) 1);
v42_set_status_callback(&answerer, v42_status, (void *) 2);
span_log_set_level(&caller.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_DEBUG);
v42_restart(&caller);
v42_restart(&answerer);
span_log_set_level(&caller.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_DEBUG);
span_log_set_tag(&caller.logging, "caller");
span_log_set_level(&caller.lapm.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_DEBUG);
span_log_set_tag(&caller.lapm.logging, "caller");
span_log_set_level(&caller.lapm.sched.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_DEBUG);
span_log_set_tag(&caller.lapm.sched.logging, "caller");
span_log_set_level(&answerer.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_DEBUG);
span_log_set_level(&answerer.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_DEBUG);
span_log_set_tag(&answerer.logging, "answerer");
span_log_set_level(&answerer.lapm.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_DEBUG);
span_log_set_tag(&answerer.lapm.logging, "answerer");
span_log_set_level(&answerer.lapm.sched.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_DEBUG);
span_log_set_tag(&answerer.lapm.sched.logging, "answerer");
for (i = 0; i < 100000; i++)
for (i = 0; i < 1000000; i++)
{
bit = v42_tx_bit(&caller);
if (insert_caller_bit_errors && i%insert_caller_bit_errors == 0)
bit ^= 1;
v42_rx_bit(&answerer, bit);
bit = v42_tx_bit(&answerer);
//if (i%10000 == 0)
// bit ^= 1;
if (insert_answerer_bit_errors && i%insert_answerer_bit_errors == 0)
bit ^= 1;
v42_rx_bit(&caller, bit);
span_schedule_update(&caller.lapm.sched, 4);
span_schedule_update(&answerer.lapm.sched, 4);
buf[0] = tx_next[1];
if (lapm_tx(&caller.lapm, buf, 1) == 1)
tx_next[1]++;
buf[0] = tx_next[2];
if (lapm_tx(&answerer.lapm, buf, 1) == 1)
tx_next[2]++;
}
return 0;
}
+82 -18
View File
@@ -34,7 +34,7 @@ of this file should exactly match the original file.
*/
#if defined(HAVE_CONFIG_H)
#include <config.h>
#include "config.h"
#endif
#include <stdlib.h>
@@ -46,12 +46,14 @@ of this file should exactly match the original file.
#include <ctype.h>
#include <assert.h>
//#if defined(WITH_SPANDSP_INTERNALS)
#define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
//#endif
#include "spandsp.h"
#include "spandsp/private/v42bis.h"
#define COMPRESSED_FILE_NAME "v42bis_tests.v42bis"
#define OUTPUT_FILE_NAME "v42bis_tests.out"
#define DECOMPRESSED_FILE_NAME "v42bis_tests.out"
int in_octets_to_date = 0;
int out_octets_to_date = 0;
@@ -85,36 +87,96 @@ int main(int argc, char *argv[])
int out_fd;
int do_compression;
int do_decompression;
int stutter_compression;
int stutter_time;
int seg;
int opt;
time_t now;
const char *argv0;
const char *original_file;
const char *compressed_file;
const char *decompressed_file;
do_compression = TRUE;
do_decompression = TRUE;
if (argc < 2)
argv0 = argv[0];
do_compression = FALSE;
do_decompression = FALSE;
stutter_compression = FALSE;
while ((opt = getopt(argc, argv, "cds")) != -1)
{
fprintf(stderr, "Usage: %s <file>\n", argv[0]);
switch (opt)
{
case 'c':
do_compression = TRUE;
break;
case 'd':
do_decompression = TRUE;
break;
case 's':
stutter_compression = TRUE;
break;
default:
//usage();
exit(2);
break;
}
}
argc -= optind;
argv += optind;
if (argc < 1)
{
fprintf(stderr, "Usage: %s [-c] [-d] [-s] <in-file> [<out-file>]\n", argv0);
exit(2);
}
if (do_compression)
{
if ((in_fd = open(argv[1], O_RDONLY)) < 0)
original_file = argv[0];
compressed_file = COMPRESSED_FILE_NAME;
}
else
{
original_file = NULL;
compressed_file = argv[0];
}
decompressed_file = (argc > 1) ? argv[1] : DECOMPRESSED_FILE_NAME;
if (do_compression)
{
stutter_time = rand() & 0x3FF;
if ((in_fd = open(argv[0], O_RDONLY)) < 0)
{
fprintf(stderr, "Error opening file '%s'.\n", argv[1]);
fprintf(stderr, "Error opening file '%s'.\n", original_file);
exit(2);
}
if ((v42bis_fd = open(COMPRESSED_FILE_NAME, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
if ((v42bis_fd = open(compressed_file, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
{
fprintf(stderr, "Error opening file '%s'.\n", COMPRESSED_FILE_NAME);
fprintf(stderr, "Error opening file '%s'.\n", compressed_file);
exit(2);
}
time(&now);
v42bis_init(&state_a, 3, 512, 6, frame_handler, (void *) (intptr_t) v42bis_fd, 512, data_handler, NULL, 512);
v42bis_compression_control(&state_a, V42BIS_COMPRESSION_MODE_ALWAYS);
span_log_set_level(&state_a.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
span_log_set_tag(&state_a.logging, "XXX");
//v42bis_compression_control(&state_a, V42BIS_COMPRESSION_MODE_ALWAYS);
in_octets_to_date = 0;
out_octets_to_date = 0;
while ((len = read(in_fd, buf, 1024)) > 0)
{
if (v42bis_compress(&state_a, buf, len))
seg = 0;
if (stutter_compression)
{
while ((len - seg) >= stutter_time)
{
if (v42bis_compress(&state_a, buf + seg, stutter_time))
{
fprintf(stderr, "Bad return code from compression\n");
exit(2);
}
v42bis_compress_flush(&state_a);
seg += stutter_time;
stutter_time = rand() & 0x3FF;
}
}
if (v42bis_compress(&state_a, buf + seg, len - seg))
{
fprintf(stderr, "Bad return code from compression\n");
exit(2);
@@ -130,19 +192,21 @@ int main(int argc, char *argv[])
if (do_decompression)
{
/* Now open the files for the decompression. */
if ((v42bis_fd = open(COMPRESSED_FILE_NAME, O_RDONLY)) < 0)
if ((v42bis_fd = open(compressed_file, O_RDONLY)) < 0)
{
fprintf(stderr, "Error opening file '%s'.\n", COMPRESSED_FILE_NAME);
fprintf(stderr, "Error opening file '%s'.\n", compressed_file);
exit(2);
}
if ((out_fd = open(OUTPUT_FILE_NAME, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
if ((out_fd = open(decompressed_file, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0)
{
fprintf(stderr, "Error opening file '%s'.\n", OUTPUT_FILE_NAME);
fprintf(stderr, "Error opening file '%s'.\n", decompressed_file);
exit(2);
}
time(&now);
v42bis_init(&state_b, 3, 512, 6, frame_handler, (void *) (intptr_t) v42bis_fd, 512, data_handler, (void *) (intptr_t) out_fd, 512);
span_log_set_level(&state_b.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW);
span_log_set_tag(&state_b.logging, "XXX");
in_octets_to_date = 0;
out_octets_to_date = 0;
while ((len = read(v42bis_fd, buf, 1024)) > 0)
+12 -11
View File
@@ -17,7 +17,7 @@
BASE=../test-data/itu/v56ter
./v42bis_tests ${BASE}/1.TST
./v42bis_tests -c -d ${BASE}/1.TST
RETVAL=$?
if [ $RETVAL != 0 ]
then
@@ -29,7 +29,7 @@ if [ $RETVAL != 0 ]
then
exit $RETVAL
fi
./v42bis_tests ${BASE}/1X04.TST
./v42bis_tests -c -d ${BASE}/1X04.TST
RETVAL=$?
if [ $RETVAL != 0 ]
then
@@ -41,7 +41,7 @@ if [ $RETVAL != 0 ]
then
exit $RETVAL
fi
./v42bis_tests ${BASE}/1X30.TST
./v42bis_tests -c -d ${BASE}/1X30.TST
RETVAL=$?
if [ $RETVAL != 0 ]
then
@@ -53,7 +53,7 @@ if [ $RETVAL != 0 ]
then
exit $RETVAL
fi
./v42bis_tests ${BASE}/2.TST
./v42bis_tests -c -d ${BASE}/2.TST
RETVAL=$?
if [ $RETVAL != 0 ]
then
@@ -65,8 +65,9 @@ if [ $RETVAL != 0 ]
then
exit $RETVAL
fi
./v42bis_tests ${BASE}/2X10.TST
./v42bis_tests -c -d ${BASE}/2X10.TST
RETVAL=$?
if [ $RETVAL != 0 ]
then
exit $RETVAL
@@ -77,7 +78,7 @@ if [ $RETVAL != 0 ]
then
exit $RETVAL
fi
./v42bis_tests ${BASE}/3.TST
./v42bis_tests -c -d ${BASE}/3.TST
RETVAL=$?
if [ $RETVAL != 0 ]
then
@@ -89,7 +90,7 @@ if [ $RETVAL != 0 ]
then
exit $RETVAL
fi
./v42bis_tests ${BASE}/3X06.TST
./v42bis_tests -c -d ${BASE}/3X06.TST
RETVAL=$?
if [ $RETVAL != 0 ]
then
@@ -101,7 +102,7 @@ if [ $RETVAL != 0 ]
then
exit $RETVAL
fi
./v42bis_tests ${BASE}/4.TST
./v42bis_tests -c -d ${BASE}/4.TST
RETVAL=$?
if [ $RETVAL != 0 ]
then
@@ -113,7 +114,7 @@ if [ $RETVAL != 0 ]
then
exit $RETVAL
fi
./v42bis_tests ${BASE}/4X04.TST
./v42bis_tests -c -d ${BASE}/4X04.TST
RETVAL=$?
if [ $RETVAL != 0 ]
then
@@ -125,7 +126,7 @@ if [ $RETVAL != 0 ]
then
exit $RETVAL
fi
./v42bis_tests ${BASE}/5.TST
./v42bis_tests -c -d ${BASE}/5.TST
RETVAL=$?
if [ $RETVAL != 0 ]
then
@@ -137,7 +138,7 @@ if [ $RETVAL != 0 ]
then
exit $RETVAL
fi
./v42bis_tests ${BASE}/5X16.TST
./v42bis_tests -c -d ${BASE}/5X16.TST
RETVAL=$?
if [ $RETVAL != 0 ]
then