update to spandsp-0.0.6pre12

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13311 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris
2009-05-14 21:52:52 +00:00
parent 92955376b2
commit 5d21a6e4b2
11 changed files with 618 additions and 368 deletions
+2 -2
View File
@@ -22,7 +22,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Id: fax_decode.c,v 1.54 2009/02/10 13:06:47 steveu Exp $
* $Id: fax_decode.c,v 1.55 2009/04/29 12:37:45 steveu Exp $
*/
/*! \page fax_decode_page FAX decoder
@@ -229,7 +229,7 @@ static void hdlc_accept(void *user_data, const uint8_t *msg, int len, int ok)
{
if (msg[0] != 0xFF || !(msg[1] == 0x03 || msg[1] == 0x13))
{
fprintf(stderr, "Bad frame header - %02x %02x", msg[0], msg[1]);
fprintf(stderr, "Bad frame header - %02x %02x\n", msg[0], msg[1]);
return;
}
print_frame("HDLC: ", msg, len);
+263 -190
View File
@@ -137,7 +137,6 @@ static void display_page_stats(t4_state_t *s)
}
/*- End of function --------------------------------------------------------*/
#if 0
static int row_read_handler(void *user_data, uint8_t buf[], size_t len)
{
int i;
@@ -189,22 +188,108 @@ static int row_write_handler(void *user_data, const uint8_t buf[], size_t len)
printf("Oops - '%c' at end of row %d\n", *s, row);
if (memcmp(buf, ref, len))
{
printf("Failed at row %d\n", row);
printf("Test failed at row %d\n", row);
exit(2);
}
return len;
}
/*- End of function --------------------------------------------------------*/
#endif
static int detect_page_end(int bit, int page_ended)
{
static int consecutive_eols;
static int max_consecutive_eols;
static int consecutive_zeros;
static int consecutive_ones;
static int eol_zeros;
static int eol_ones;
static int expected_eols;
static int end_marks;
/* Check the EOLs are added properly to the end of an image. We can't rely on the
decoder giving the right answer, as a full set of EOLs is not needed for the
decoder to work. */
if (bit == -1000000)
{
/* Reset */
consecutive_eols = 0;
max_consecutive_eols = 0;
consecutive_zeros = 0;
consecutive_ones = 0;
end_marks = 0;
eol_zeros = 11;
eol_ones = (page_ended == T4_COMPRESSION_ITU_T4_2D) ? 2 : 1;
expected_eols = (page_ended == T4_COMPRESSION_ITU_T6) ? 2 : 6;
return FALSE;
}
/* Monitor whether the EOLs are there in the correct amount */
if (bit == 0)
{
consecutive_zeros++;
consecutive_ones = 0;
}
else if (bit == 1)
{
if (++consecutive_ones == eol_ones)
{
if (consecutive_eols == 0 && consecutive_zeros >= eol_zeros)
consecutive_eols++;
else if (consecutive_zeros == eol_zeros)
consecutive_eols++;
else
consecutive_eols = 0;
consecutive_zeros = 0;
consecutive_ones = 0;
}
if (max_consecutive_eols < consecutive_eols)
max_consecutive_eols = consecutive_eols;
}
else if (bit == SIG_STATUS_END_OF_DATA)
{
if (end_marks == 0)
{
if (max_consecutive_eols != expected_eols)
{
printf("Only %d EOLs (should be %d)\n", max_consecutive_eols, expected_eols);
return 2;
}
consecutive_zeros = 0;
consecutive_eols = 0;
max_consecutive_eols = 0;
}
if (!page_ended)
{
/* We might need to push a few bits to get the receiver to report the
end of page condition (at least with T.6). */
if (++end_marks > 50)
{
printf("Receiver missed the end of page mark\n");
return 2;
}
return 0;
}
return 1;
}
return 0;
}
/*- End of function --------------------------------------------------------*/
int main(int argc, char *argv[])
{
static const int compression_sequence[] =
{
T4_COMPRESSION_ITU_T4_1D,
T4_COMPRESSION_ITU_T4_2D,
T4_COMPRESSION_ITU_T6
};
int sends;
int page_no;
int bit;
int end_of_page;
int end_marks;
int decode_test;
int res;
int compression;
int compression_step;
int add_page_headers;
@@ -214,6 +299,7 @@ int main(int argc, char *argv[])
char buf[1024];
uint8_t block[1024];
const char *in_file_name;
const char *decode_file_name;
int opt;
int i;
int bit_error_rate;
@@ -221,29 +307,37 @@ int main(int argc, char *argv[])
int tests_failed;
unsigned int last_pkt_no;
unsigned int pkt_no;
int page_ended;
FILE *file;
tests_failed = 0;
decode_test = FALSE;
compression = -1;
compression_step = 0;
add_page_headers = FALSE;
restart_pages = FALSE;
in_file_name = IN_FILE_NAME;
min_row_bits = 0;
decode_file_name = NULL;
/* Use a non-zero default minimum row length to ensure we test the consecutive EOLs part
properly. */
min_row_bits = 50;
block_size = 0;
bit_error_rate = 0;
dump_as_xxx = FALSE;
while ((opt = getopt(argc, argv, "126b:dehri:m:x")) != -1)
while ((opt = getopt(argc, argv, "126b:d:ehri:m:x")) != -1)
{
switch (opt)
{
case '1':
compression = T4_COMPRESSION_ITU_T4_1D;
compression_step = -1;
break;
case '2':
compression = T4_COMPRESSION_ITU_T4_2D;
compression_step = -1;
break;
case '6':
compression = T4_COMPRESSION_ITU_T6;
compression_step = -1;
break;
case 'b':
block_size = atoi(optarg);
@@ -251,7 +345,7 @@ int main(int argc, char *argv[])
block_size = 1024;
break;
case 'd':
decode_test = TRUE;
decode_file_name = optarg;
break;
case 'e':
bit_error_rate = 0x3FF;
@@ -282,7 +376,7 @@ int main(int argc, char *argv[])
memset(&receive_state, 0, sizeof(receive_state));
end_of_page = FALSE;
if (decode_test)
if (decode_file_name)
{
if (compression < 0)
compression = T4_COMPRESSION_ITU_T4_1D;
@@ -302,7 +396,8 @@ int main(int argc, char *argv[])
page_no = 1;
t4_rx_start_page(&receive_state);
last_pkt_no = 0;
while (fgets(buf, 1024, stdin))
file = fopen(decode_file_name, "r");
while (fgets(buf, 1024, file))
{
if (sscanf(buf, "HDLC: FCD: 06 %x", &pkt_no) == 1)
{
@@ -361,6 +456,7 @@ int main(int argc, char *argv[])
}
}
}
fclose(file);
if (dump_as_xxx)
dump_image_as_xxx(&receive_state);
t4_rx_end_page(&receive_state);
@@ -370,165 +466,8 @@ int main(int argc, char *argv[])
else
{
#if 1
/* Send end gets TIFF from a file */
if (t4_tx_init(&send_state, in_file_name, -1, -1) == NULL)
{
printf("Failed to init T.4 send\n");
exit(2);
}
span_log_set_level(&send_state.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
t4_tx_set_min_row_bits(&send_state, min_row_bits);
t4_tx_set_local_ident(&send_state, "111 2222 3333");
/* Receive end puts TIFF to a new file. */
if (t4_rx_init(&receive_state, OUT_FILE_NAME, T4_COMPRESSION_ITU_T4_2D) == NULL)
{
printf("Failed to init T.4 rx\n");
exit(2);
}
span_log_set_level(&receive_state.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
t4_rx_set_x_resolution(&receive_state, t4_tx_get_x_resolution(&send_state));
t4_rx_set_y_resolution(&receive_state, t4_tx_get_y_resolution(&send_state));
t4_rx_set_image_width(&receive_state, t4_tx_get_image_width(&send_state));
/* Now send and receive all the pages in the source TIFF file */
page_no = 1;
sends = 0;
/* Select whether we step round the compression schemes, or use a single specified one. */
compression_step = (compression < 0) ? 0 : -1;
for (;;)
{
end_marks = 0;
/* Add a header line to alternate pages, if required */
if (add_page_headers && (sends & 2))
t4_tx_set_header_info(&send_state, "Header");
else
t4_tx_set_header_info(&send_state, NULL);
if (restart_pages && (sends & 1))
{
/* Use restart, to send the page a second time */
if (t4_tx_restart_page(&send_state))
break;
}
else
{
switch (compression_step)
{
case 0:
compression = T4_COMPRESSION_ITU_T4_1D;
compression_step++;
break;
case 1:
compression = T4_COMPRESSION_ITU_T4_2D;
compression_step++;
break;
case 2:
compression = T4_COMPRESSION_ITU_T6;
compression_step = 0;
break;
}
t4_tx_set_tx_encoding(&send_state, compression);
t4_rx_set_rx_encoding(&receive_state, compression);
if (t4_tx_start_page(&send_state))
break;
}
t4_rx_start_page(&receive_state);
if (block_size == 0)
{
do
{
bit = t4_tx_get_bit(&send_state);
if (bit == SIG_STATUS_END_OF_DATA)
{
/* T.6 data does not contain an image termination sequence.
T.4 1D and 2D do, and should locate that sequence. */
if (compression == T4_COMPRESSION_ITU_T6)
break;
if (++end_marks > 50)
{
printf("Receiver missed the end of page mark\n");
tests_failed++;
break;
}
}
if (bit_error_rate)
{
if ((rand() % bit_error_rate) == 0)
bit ^= 1;
}
end_of_page = t4_rx_put_bit(&receive_state, bit & 1);
}
while (!end_of_page);
}
else if (block_size == 1)
{
do
{
bit = t4_tx_get_byte(&send_state);
if ((bit & 0x100))
{
/* T.6 data does not contain an image termination sequence.
T.4 1D and 2D do, and should locate that sequence. */
if (compression == T4_COMPRESSION_ITU_T6)
break;
if (++end_marks > 50)
{
printf("Receiver missed the end of page mark\n");
tests_failed++;
break;
}
}
end_of_page = t4_rx_put_byte(&receive_state, bit & 0xFF);
}
while (!end_of_page);
}
else
{
do
{
bit = t4_tx_get_chunk(&send_state, block, block_size);
if (bit > 0)
end_of_page = t4_rx_put_chunk(&receive_state, block, bit);
if (bit < block_size)
{
/* T.6 data does not contain an image termination sequence.
T.4 1D and 2D do, and should locate that sequence. */
if (compression == T4_COMPRESSION_ITU_T6)
break;
if (++end_marks > 50)
{
printf("Receiver missed the end of page mark\n");
tests_failed++;
break;
}
}
}
while (!end_of_page);
}
if (dump_as_xxx)
dump_image_as_xxx(&receive_state);
display_page_stats(&receive_state);
if (!restart_pages || (sends & 1))
t4_tx_end_page(&send_state);
t4_rx_end_page(&receive_state);
sends++;
}
t4_tx_release(&send_state);
t4_rx_release(&receive_state);
/* And we should now have a matching received TIFF file. Note this will only match
at the image level. TIFF files allow a lot of ways to express the same thing,
so bit matching of the files is not the normal case. */
fflush(stdout);
sprintf(buf, "tiffcmp -t %s " OUT_FILE_NAME, in_file_name);
if (tests_failed)// || system(buf))
{
printf("Tests failed\n");
exit(2);
}
#endif
#if 0
/* Send end gets TIFF from a function */
printf("Testing image_function->compress->decompress->image_function\n");
/* Send end gets image from a function */
if (t4_tx_init(&send_state, in_file_name, -1, -1) == NULL)
{
printf("Failed to init T.4 tx\n");
@@ -553,26 +492,17 @@ int main(int argc, char *argv[])
/* Now send and receive all the pages in the source TIFF file */
page_no = 1;
/* Select whether we step round the compression schemes, or use a single specified one. */
compression_step = (compression < 0) ? 0 : -1;
/* If we are stepping around the compression schemes, reset to the start of the sequence. */
if (compression_step > 0)
compression_step = 0;
for (;;)
{
end_marks = 0;
/* Add a header line to alternate pages, if required */
switch (compression_step)
if (compression_step >= 0)
{
case 0:
compression = T4_COMPRESSION_ITU_T4_1D;
compression_step++;
break;
case 1:
compression = T4_COMPRESSION_ITU_T4_2D;
compression_step++;
break;
case 2:
compression = T4_COMPRESSION_ITU_T6;
compression_step = 0;
break;
compression = compression_sequence[compression_step++];
if (compression_step > 3)
break;
}
t4_tx_set_tx_encoding(&send_state, compression);
t4_rx_set_rx_encoding(&receive_state, compression);
@@ -585,10 +515,6 @@ int main(int argc, char *argv[])
bit = t4_tx_get_bit(&send_state);
if (bit == SIG_STATUS_END_OF_DATA)
{
/* T.6 data does not contain an image termination sequence.
T.4 1D and 2D do, and should locate that sequence. */
if (compression == T4_COMPRESSION_ITU_T6)
break;
if (++end_marks > 50)
{
printf("Receiver missed the end of page mark\n");
@@ -601,12 +527,159 @@ int main(int argc, char *argv[])
while (!end_of_page);
t4_tx_end_page(&send_state);
t4_rx_end_page(&receive_state);
break;
if (compression_step < 0)
break;
}
t4_tx_release(&send_state);
t4_rx_release(&receive_state);
#endif
#if 1
printf("Testing TIFF->compress->decompress->TIFF cycle\n");
/* Send end gets TIFF from a file */
if (t4_tx_init(&send_state, in_file_name, -1, -1) == NULL)
{
printf("Failed to init T.4 send\n");
exit(2);
}
span_log_set_level(&send_state.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
t4_tx_set_min_row_bits(&send_state, min_row_bits);
t4_tx_set_local_ident(&send_state, "111 2222 3333");
/* Receive end puts TIFF to a new file. */
if (t4_rx_init(&receive_state, OUT_FILE_NAME, T4_COMPRESSION_ITU_T4_2D) == NULL)
{
printf("Failed to init T.4 rx for '%s'\n", OUT_FILE_NAME);
exit(2);
}
span_log_set_level(&receive_state.logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW);
t4_rx_set_x_resolution(&receive_state, t4_tx_get_x_resolution(&send_state));
t4_rx_set_y_resolution(&receive_state, t4_tx_get_y_resolution(&send_state));
t4_rx_set_image_width(&receive_state, t4_tx_get_image_width(&send_state));
/* Now send and receive all the pages in the source TIFF file */
page_no = 1;
sends = 0;
/* If we are stepping around the compression schemes, reset to the start of the sequence. */
if (compression_step > 0)
compression_step = 0;
for (;;)
{
end_marks = 0;
/* Add a header line to alternate pages, if required */
if (add_page_headers && (sends & 2))
t4_tx_set_header_info(&send_state, "Header");
else
t4_tx_set_header_info(&send_state, NULL);
if (restart_pages && (sends & 1))
{
/* Use restart, to send the page a second time */
if (t4_tx_restart_page(&send_state))
break;
}
else
{
if (compression_step >= 0)
{
compression = compression_sequence[compression_step++];
if (compression_step > 2)
compression_step = 0;
}
t4_tx_set_tx_encoding(&send_state, compression);
t4_rx_set_rx_encoding(&receive_state, compression);
if (t4_tx_start_page(&send_state))
break;
}
t4_rx_start_page(&receive_state);
detect_page_end(-1000000, compression);
page_ended = FALSE;
if (block_size == 0)
{
for (;;)
{
bit = t4_tx_get_bit(&send_state);
/* Monitor whether the EOLs are there in the correct amount */
if ((res = detect_page_end(bit, page_ended)))
{
tests_failed += (res - 1);
break;
}
if (!page_ended)
{
if (bit_error_rate)
{
if ((rand() % bit_error_rate) == 0)
bit ^= 1;
}
if (t4_rx_put_bit(&receive_state, bit & 1))
page_ended = TRUE;
}
}
/* Now throw junk at the receive context, to ensure stuff occuring
after the end of page condition has no bad effect. */
for (i = 0; i < 1000; i++)
{
t4_rx_put_bit(&receive_state, (rand() >> 10) & 1);
}
}
else if (block_size == 1)
{
do
{
bit = t4_tx_get_byte(&send_state);
if ((bit & 0x100))
{
if (++end_marks > 50)
{
printf("Receiver missed the end of page mark\n");
tests_failed++;
break;
}
}
end_of_page = t4_rx_put_byte(&receive_state, bit & 0xFF);
}
while (!end_of_page);
}
else
{
do
{
bit = t4_tx_get_chunk(&send_state, block, block_size);
if (bit > 0)
end_of_page = t4_rx_put_chunk(&receive_state, block, bit);
if (bit < block_size)
{
if (++end_marks > 50)
{
printf("Receiver missed the end of page mark\n");
tests_failed++;
break;
}
}
}
while (!end_of_page);
}
if (dump_as_xxx)
dump_image_as_xxx(&receive_state);
display_page_stats(&receive_state);
if (!restart_pages || (sends & 1))
t4_tx_end_page(&send_state);
t4_rx_end_page(&receive_state);
sends++;
}
t4_tx_release(&send_state);
t4_rx_release(&receive_state);
/* And we should now have a matching received TIFF file. Note this will only match
at the image level. TIFF files allow a lot of ways to express the same thing,
so bit matching of the files is not the normal case. */
fflush(stdout);
sprintf(buf, "tiffcmp -t %s %s", in_file_name, OUT_FILE_NAME);
if (tests_failed || system(buf))
{
printf("Tests failed\n");
exit(2);
}
#endif
printf("Tests passed\n");
}
return 0;
+5 -3
View File
@@ -15,7 +15,7 @@
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# $Id: tsb85_tests.sh,v 1.6 2008/09/11 15:13:42 steveu Exp $
# $Id: tsb85_tests.sh,v 1.7 2009/04/30 15:04:20 steveu Exp $
#
run_tsb85_test()
@@ -54,11 +54,12 @@ for TEST in OREN01 OREN02 OREN03 OREN04 OREN05 OREN06 OREN07 OREN08 OREN09 OREN1
run_tsb85_test
done
# MRGX03 is failing because the V.27ter modemsays it trained on HDLC
# MRGX05 is failing because we don't distinguish MPS immediately after MCF from MPS after
# a corrupt image signal.
#for TEST in MRGX01 MRGX02 MRGX03 MRGX04 MRGX05 MRGX06 MRGX07 MRGX08 ; do
for TEST in MRGX01 MRGX02 MRGX03 MRGX04 MRGX06 MRGX07 MRGX08 ; do
for TEST in MRGX01 MRGX02 MRGX04 MRGX06 MRGX07 MRGX08 ; do
run_tsb85_test
done
@@ -94,7 +95,8 @@ for TEST in OTGC10 OTGC11 ; do
run_tsb85_test
done
for TEST in OTEN01 OTEN02 OTEN03 OTEN04 OTEN05 OTEN06 ; do
#for TEST in OTEN01 OTEN02 OTEN03 OTEN04 OTEN05 OTEN06 ; do
for TEST in OTEN01 OTEN03 OTEN04 OTEN05 OTEN06 ; do
run_tsb85_test
done