From 5394b2cae6c482ccb835335b769469977e6802ae Mon Sep 17 00:00:00 2001 From: Steve Underwood Date: Wed, 18 Oct 2023 19:52:47 +0100 Subject: [PATCH] Various tidying up jobs. V.150.1 has moved forward, but is still a work in progress. The various modules using Goertzel filters were not using a harmonised approach to setting thresholds and measuring power levels. This has been improved. --- src/Makefile.am | 6 +- src/ademco_contactid.c | 16 +- src/bell_r2_mf.c | 50 +- src/dtmf.c | 87 +- src/fax.c | 4 +- src/modem_connect_tones.c | 22 +- src/spandsp/expose.h | 2 +- src/spandsp/private/sprt.h | 8 +- src/spandsp/private/ssl_fax.h | 10 +- src/spandsp/private/t30.h | 5 + src/spandsp/private/v150_1.h | 217 +++- src/spandsp/private/v150_1_sse.h | 164 +-- src/spandsp/private/v18.h | 2 +- src/spandsp/sprt.h | 14 +- src/spandsp/ssl_fax.h | 14 +- src/spandsp/t30_api.h | 14 +- src/spandsp/telephony.h | 12 + src/spandsp/tone_detect.h | 20 + src/spandsp/v150_1.h | 119 +- src/spandsp/v150_1_sse.h | 237 ++-- src/spandsp/v18.h | 2 +- src/sprt.c | 27 +- src/ssl_fax.c | 64 +- src/super_tone_rx.c | 27 +- src/t30.c | 28 +- src/t30_api.c | 12 + src/t4_t6_encode.c | 7 +- src/tone_detect.c | 6 +- src/v150_1.c | 1730 ++++++++++++++++++++++------ src/v150_1_local.h | 36 + src/v150_1_sse.c | 1413 +++++++++++------------ src/v18.c | 24 +- tests/Makefile.am | 12 +- tests/ademco_contactid_tests.c | 32 + tests/adsi_tests.c | 69 ++ tests/at_interpreter_tests.c | 7 + tests/awgn_tests.c | 21 +- tests/bell_mf_rx_tests.c | 53 + tests/bell_mf_tx_tests.c | 17 + tests/bert_tests.c | 61 + tests/bit_operations_tests.c | 34 + tests/bitstream_tests.c | 12 + tests/complex_vector_float_tests.c | 8 + tests/complex_vector_int_tests.c | 8 + tests/data_modems_tests.c | 24 + tests/dc_restore_tests.c | 8 +- tests/dds_tests.c | 34 +- tests/dtmf_rx_tests.c | 80 +- tests/dtmf_tx_tests.c | 20 + tests/echo_monitor.cpp | 28 + tests/echo_tests.c | 78 ++ tests/fax_decode.c | 2 - tests/fax_tester.c | 65 +- tests/fax_tests.c | 147 ++- tests/fax_utils.c | 17 + tests/g1050_tests.c | 19 + tests/g168_tests.c | 12 + tests/g711_tests.c | 64 + tests/g722_tests.c | 70 ++ tests/g726_tests.c | 32 + tests/gsm0610_tests.c | 56 + tests/ima_adpcm_tests.c | 15 + tests/image_translate_tests.c | 66 ++ tests/line_model_monitor.cpp | 28 + tests/line_model_tests.c | 37 + tests/logging_tests.c | 23 + tests/media_monitor.cpp | 14 + tests/noise_tests.c | 22 + tests/oki_adpcm_tests.c | 30 + tests/playout_tests.c | 24 + tests/plc_tests.c | 17 + tests/power_meter_tests.c | 39 + tests/r2_mf_rx_tests.c | 62 + tests/r2_mf_tx_tests.c | 8 + tests/rfc2198_sim_tests.c | 17 + tests/saturated_tests.c | 19 + tests/schedule_tests.c | 4 + tests/sig_tone_tests.c | 15 + tests/sprt_decode.c | 55 +- tests/sprt_tests.c | 21 +- tests/super_tone_rx_tests.c | 50 +- tests/super_tone_tx_tests.c | 15 + tests/swept_tone_tests.c | 5 + tests/t31_pseudo_terminal_tests.c | 66 ++ tests/t31_tests.c | 72 ++ tests/t35_tests.c | 7 + tests/t38_core_tests.c | 74 ++ tests/t38_non_ecm_buffer_tests.c | 85 ++ tests/t42_tests.c | 45 + tests/t43_tests.c | 145 ++- tests/t4_t6_tests.c | 44 + tests/t4_tests.c | 6 + tests/t81_t82_arith_coding_tests.c | 22 + tests/t85_tests.c | 31 + tests/time_scale_tests.c | 17 + tests/tone_detect_tests.c | 8 + tests/tone_generate_tests.c | 18 + tests/tsb85_tests.c | 7 + tests/tsb85_tests.sh | 29 +- tests/v150_1_sse_tests.c | 84 +- tests/v150_1_tests.c | 937 ++++++++++++--- tests/v17_tests.c | 42 + tests/v22bis_tests.c | 40 + tests/v27ter_tests.c | 43 + tests/v29_tests.c | 37 + tests/v32bis_tests.c | 31 + tests/v34_tests.c | 1 + tests/v42_tests.c | 15 + tests/v42bis_tests.c | 19 + tests/v8_tests.c | 2 + tests/vector_float_tests.c | 70 ++ tests/vector_int_tests.c | 11 + 112 files changed, 6106 insertions(+), 1977 deletions(-) create mode 100644 src/v150_1_local.h diff --git a/src/Makefile.am b/src/Makefile.am index c866582c..e56d32c2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -236,11 +236,11 @@ nobase_include_HEADERS = spandsp/ademco_contactid.h \ spandsp/queue.h \ spandsp/saturated.h \ spandsp/schedule.h \ - spandsp/stdbool.h \ spandsp/sig_tone.h \ spandsp/silence_gen.h \ - spandsp/ssl_fax.h \ spandsp/sprt.h \ + spandsp/ssl_fax.h \ + spandsp/stdbool.h \ spandsp/super_tone_rx.h \ spandsp/super_tone_tx.h \ spandsp/swept_tone.h \ @@ -322,8 +322,8 @@ nobase_include_HEADERS = spandsp/ademco_contactid.h \ spandsp/private/schedule.h \ spandsp/private/sig_tone.h \ spandsp/private/silence_gen.h \ - spandsp/private/ssl_fax.h \ spandsp/private/sprt.h \ + spandsp/private/ssl_fax.h \ spandsp/private/super_tone_rx.h \ spandsp/private/super_tone_tx.h \ spandsp/private/swept_tone.h \ diff --git a/src/ademco_contactid.c b/src/ademco_contactid.c index 69ab8fa3..168b9270 100644 --- a/src/ademco_contactid.c +++ b/src/ademco_contactid.c @@ -443,14 +443,14 @@ static const struct ademco_code_s ademco_codes[] = {-1, "???"} }; -#define GOERTZEL_SAMPLES_PER_BLOCK 55 /* We need to detect over a +-5% range */ +#define GOERTZEL_SAMPLES_PER_BLOCK 55 /* We need to detect over a +-5% range */ #if defined(SPANDSP_USE_FIXED_POINT) -#define DETECTION_THRESHOLD 3035 /* -42dBm0 */ -#define TONE_TO_TOTAL_ENERGY 45.2233f /* -0.85dB */ +static const int detection_threshold = goertzel_threshold_dbm0(GOERTZEL_SAMPLES_PER_BLOCK, -42.0f); +static const float tone_to_total_energy = GOERTZEL_SAMPLES_PER_BLOCK*db_to_power_ratio(-0.85f); #else -#define DETECTION_THRESHOLD 49728296.6f /* -42dBm0 [((GOERTZEL_SAMPLES_PER_BLOCK*32768.0/1.4142)*10^((-42 - DBM0_MAX_SINE_POWER)/20.0))^2] */ -#define TONE_TO_TOTAL_ENERGY 45.2233f /* -0.85dB [GOERTZEL_SAMPLES_PER_BLOCK*10^(-0.85/10.0)] */ +static const float detection_threshold = goertzel_threshold_dbm0(GOERTZEL_SAMPLES_PER_BLOCK, -42.0f); +static const float tone_to_total_energy = GOERTZEL_SAMPLES_PER_BLOCK*db_to_power_ratio(-0.85f); #endif static int tone_rx_init = false; @@ -906,17 +906,17 @@ SPAN_DECLARE(int) ademco_contactid_sender_rx(ademco_contactid_sender_state_t *s, energy_1400 = goertzel_result(&s->tone_1400); energy_2300 = goertzel_result(&s->tone_2300); hit = 0; - if (energy_1400 > DETECTION_THRESHOLD || energy_2300 > DETECTION_THRESHOLD) + if (energy_1400 > detection_threshold || energy_2300 > detection_threshold) { if (energy_1400 > energy_2300) { - if (energy_1400 > TONE_TO_TOTAL_ENERGY*s->energy) + if (energy_1400 > tone_to_total_energy*s->energy) hit = 1; /*endif*/ } else { - if (energy_2300 > TONE_TO_TOTAL_ENERGY*s->energy) + if (energy_2300 > tone_to_total_energy*s->energy) hit = 2; /*endif*/ } diff --git a/src/bell_r2_mf.c b/src/bell_r2_mf.c index 911c6ab3..a7d913fb 100644 --- a/src/bell_r2_mf.c +++ b/src/bell_r2_mf.c @@ -201,26 +201,26 @@ static const mf_digit_tones_t socotel_tones[] = static char socotel_mf_tone_codes[] = "1234567890ABCDEFG"; #endif -#if defined(SPANDSP_USE_FIXED_POINT) -#define BELL_MF_THRESHOLD 204089 /* -30.5dBm0 */ -#define BELL_MF_TWIST 3.981f /* 6dB */ -#define BELL_MF_RELATIVE_PEAK 12.589f /* 11dB */ #define BELL_MF_SAMPLES_PER_BLOCK 120 -#define R2_MF_THRESHOLD 62974 /* -36.5dBm0 */ -#define R2_MF_TWIST 5.012f /* 7dB */ -#define R2_MF_RELATIVE_PEAK 12.589f /* 11dB */ #define R2_MF_SAMPLES_PER_BLOCK 133 + +#if defined(SPANDSP_USE_FIXED_POINT) +static const int bell_mf_threshold = goertzel_threshold_dbm0(BELL_MF_SAMPLES_PER_BLOCK, -30.5f); +static const float bell_mf_twist = db_to_power_ratio(6.0f); +static const float bell_mf_relative_peak = db_to_power_ratio(11.0f); + +static const int r2_mf_threshold = goertzel_threshold_dbm0(R2_MF_SAMPLES_PER_BLOCK, -36.5f); +static const float r2_mf_twist = db_to_power_ratio(7.0f); +static const float r2_mf_relative_peak = db_to_power_ratio(11.0f); #else -#define BELL_MF_THRESHOLD 3343803100.0f /* -30.5dBm0 [((120.0*32768.0/1.4142)*10^((-30.5 - DBM0_MAX_SINE_POWER)/20.0))^2 => 3343803100.0] */ -#define BELL_MF_TWIST 3.981f /* 6dB [10^(6/10) => 3.981] */ -#define BELL_MF_RELATIVE_PEAK 12.589f /* 11dB */ -#define BELL_MF_SAMPLES_PER_BLOCK 120 +static const float bell_mf_threshold = goertzel_threshold_dbm0(BELL_MF_SAMPLES_PER_BLOCK, -30.5f); +static const float bell_mf_twist = db_to_power_ratio(6.0f); +static const float bell_mf_relative_peak = db_to_power_ratio(11.0f); -#define R2_MF_THRESHOLD 1031766650.0f /* -36.5dBm0 [((133.0*32768.0/1.4142)*10^((-36.5 - DBM0_MAX_SINE_POWER)/20.0))^2 => 1031766650.0] */ -#define R2_MF_TWIST 5.012f /* 7dB */ -#define R2_MF_RELATIVE_PEAK 12.589f /* 11dB */ -#define R2_MF_SAMPLES_PER_BLOCK 133 +static const float r2_mf_threshold = goertzel_threshold_dbm0(R2_MF_SAMPLES_PER_BLOCK, -36.5f); +static const float r2_mf_twist = db_to_power_ratio(7.0f); +static const float r2_mf_relative_peak = db_to_power_ratio(11.0f); #endif static goertzel_descriptor_t bell_mf_detect_desc[6]; @@ -561,13 +561,13 @@ SPAN_DECLARE(int) bell_mf_rx(bell_mf_rx_state_t *s, const int16_t amp[], int sam /*endfor*/ /* Basic signal level and twist tests */ hit = 0; - if (energy[best] >= BELL_MF_THRESHOLD + if (energy[best] >= bell_mf_threshold && - energy[second_best] >= BELL_MF_THRESHOLD + energy[second_best] >= bell_mf_threshold && - energy[best] < energy[second_best]*BELL_MF_TWIST + energy[best] < energy[second_best]*bell_mf_twist && - energy[best]*BELL_MF_TWIST > energy[second_best]) + energy[best]*bell_mf_twist > energy[second_best]) { /* Relative peak test */ hit = 'X'; @@ -575,7 +575,7 @@ SPAN_DECLARE(int) bell_mf_rx(bell_mf_rx_state_t *s, const int16_t amp[], int sam { if (i != best && i != second_best) { - if (energy[i]*BELL_MF_RELATIVE_PEAK >= energy[second_best]) + if (energy[i]*bell_mf_relative_peak >= energy[second_best]) { /* The best two are not clearly the best */ hit = 0; @@ -801,13 +801,13 @@ SPAN_DECLARE(int) r2_mf_rx(r2_mf_rx_state_t *s, const int16_t amp[], int samples /*endfor*/ /* Basic signal level and twist tests */ hit = false; - if (energy[best] >= R2_MF_THRESHOLD + if (energy[best] >= r2_mf_threshold && - energy[second_best] >= R2_MF_THRESHOLD + energy[second_best] >= r2_mf_threshold && - energy[best] < energy[second_best]*R2_MF_TWIST + energy[best] < energy[second_best]*r2_mf_twist && - energy[best]*R2_MF_TWIST > energy[second_best]) + energy[best]*r2_mf_twist > energy[second_best]) { /* Relative peak test */ hit = true; @@ -815,7 +815,7 @@ SPAN_DECLARE(int) r2_mf_rx(r2_mf_rx_state_t *s, const int16_t amp[], int samples { if (i != best && i != second_best) { - if (energy[i]*R2_MF_RELATIVE_PEAK >= energy[second_best]) + if (energy[i]*r2_mf_relative_peak >= energy[second_best]) { /* The best two are not clearly the best */ hit = false; diff --git a/src/dtmf.c b/src/dtmf.c index 95ad96f8..44cde486 100644 --- a/src/dtmf.c +++ b/src/dtmf.c @@ -64,31 +64,31 @@ #include "spandsp/private/tone_generate.h" #include "spandsp/private/dtmf.h" -#define DEFAULT_DTMF_TX_LEVEL -10 -#define DEFAULT_DTMF_TX_ON_TIME 50 -#define DEFAULT_DTMF_TX_OFF_TIME 55 +#define DEFAULT_DTMF_TX_LEVEL -10 /* In dBm0 */ +#define DEFAULT_DTMF_TX_ON_TIME 50 /* in ms */ +#define DEFAULT_DTMF_TX_OFF_TIME 55 /* in ms */ + +#define DTMF_SAMPLES_PER_BLOCK 102 #if defined(SPANDSP_USE_FIXED_POINT) /* The fixed point version scales the 16 bit signal down by 7 bits, so the Goertzels will fit in a 32 bit word */ -#define FP_SCALE(x) ((int16_t) (x/128.0 + ((x >= 0.0) ? 0.5 : -0.5))) -#define DTMF_THRESHOLD 10438 /* -42dBm0 [((DTMF_SAMPLES_PER_BLOCK*32768.0/1.4142)*10^((-42 - DBM0_MAX_SINE_POWER)/20.0)/128.0)^2]*/ -#define DTMF_NORMAL_TWIST 6.309f /* 8dB [10.0^(8.0/10.0)] */ -#define DTMF_REVERSE_TWIST 2.512f /* 4dB [10.0^(4.0/10.0)] */ -#define DTMF_RELATIVE_PEAK_ROW 6.309f /* 8dB [10.0^(8.0/10.0)] */ -#define DTMF_RELATIVE_PEAK_COL 6.309f /* 8dB [10.0^(8.0/10.0)] */ -#define DTMF_TO_TOTAL_ENERGY 83.868f /* -0.85dB [DTMF_SAMPLES_PER_BLOCK*10^(-0.85/10.0)] */ -#define DTMF_POWER_OFFSET 68.251f /* 10*log(((32768.0/128.0)^2)*DTMF_SAMPLES_PER_BLOCK) */ -#define DTMF_SAMPLES_PER_BLOCK 102 +#define FP_SCALE(x) ((int16_t) (x/128.0 + ((x >= 0.0) ? 0.5 : -0.5))) +static const float dtmf_threshold = goertzel_threshold_dbm0(DTMF_SAMPLES_PER_BLOCK, -42.0f); +static const float dtmf_normal_twist = db_to_power_ratio(8.0f); +static const float dtmf_reverse_twist = db_to_power_ratio(4.0f); +static const float dtmf_relative_peak_row = db_to_power_ratio(8.0f); +static const float dtmf_relative_peak_col = db_to_power_ratio(8.0f); +static const float dtmf_to_total_energy = DTMF_SAMPLES_PER_BLOCK*db_to_power_ratio(-0.85f); +static const float dtmf_power_offset = (power_ratio_to_db(256.0f*256.0f*DTMF_SAMPLES_PER_BLOCK) - DBM0_MAX_SINE_POWER); #else -#define FP_SCALE(x) (x) -#define DTMF_THRESHOLD 171032462.0f /* -42dBm0 [((DTMF_SAMPLES_PER_BLOCK*32768.0/1.4142)*10^((-42 - DBM0_MAX_SINE_POWER)/20.0))^2] */ -#define DTMF_NORMAL_TWIST 6.309f /* 8dB [10.0^(8.0/10.0)] */ -#define DTMF_REVERSE_TWIST 2.512f /* 4dB [10.0^(4.0/10.0)] */ -#define DTMF_RELATIVE_PEAK_ROW 6.309f /* 8dB [10.0^(8.0/10.0)] */ -#define DTMF_RELATIVE_PEAK_COL 6.309f /* 8dB [10.0^(8.0/10.0)] */ -#define DTMF_TO_TOTAL_ENERGY 83.868f /* -0.85dB [DTMF_SAMPLES_PER_BLOCK*10^(-0.85/10.0)] */ -#define DTMF_POWER_OFFSET 110.395f /* 10*log((32768.0^2)*DTMF_SAMPLES_PER_BLOCK) */ -#define DTMF_SAMPLES_PER_BLOCK 102 +#define FP_SCALE(x) (x) +static const float dtmf_threshold = goertzel_threshold_dbm0(DTMF_SAMPLES_PER_BLOCK, -42.0f); +static const float dtmf_normal_twist = db_to_power_ratio(8.0f); +static const float dtmf_reverse_twist = db_to_power_ratio(4.0f); +static const float dtmf_relative_peak_row = db_to_power_ratio(8.0f); +static const float dtmf_relative_peak_col = db_to_power_ratio(8.0f); +static const float dtmf_to_total_energy = DTMF_SAMPLES_PER_BLOCK*db_to_power_ratio(-0.85f); +static const float dtmf_power_offset = (power_ratio_to_db(32768.0f*32768.0f*DTMF_SAMPLES_PER_BLOCK) - DBM0_MAX_SINE_POWER); #endif static const float dtmf_row[] = @@ -217,9 +217,9 @@ SPAN_DECLARE(int) dtmf_rx(dtmf_rx_state_t *s, const int16_t amp[], int samples) /* Relative peak test ... */ for (i = 0; i < 4; i++) { - if ((i != best_col && col_energy[i]*DTMF_RELATIVE_PEAK_COL > col_energy[best_col]) + if ((i != best_col && col_energy[i]*dtmf_relative_peak_col > col_energy[best_col]) || - (i != best_row && row_energy[i]*DTMF_RELATIVE_PEAK_ROW > row_energy[best_row])) + (i != best_row && row_energy[i]*dtmf_relative_peak_row > row_energy[best_row])) { break; } @@ -229,7 +229,7 @@ SPAN_DECLARE(int) dtmf_rx(dtmf_rx_state_t *s, const int16_t amp[], int samples) /* ... and fraction of total energy test */ if (i >= 4 && - (row_energy[best_row] + col_energy[best_col]) > DTMF_TO_TOTAL_ENERGY*s->energy) + (row_energy[best_row] + col_energy[best_col]) > dtmf_to_total_energy*s->energy) { /* Got a hit */ hit = dtmf_positions[(best_row << 2) + best_col]; @@ -237,19 +237,19 @@ SPAN_DECLARE(int) dtmf_rx(dtmf_rx_state_t *s, const int16_t amp[], int samples) /*endif*/ } /*endif*/ - if (span_log_test(&s->logging, SPAN_LOG_FLOW)) + if (span_log_test(&s->logging, SPAN_LOG_DEBUG)) { /* Log information about the quality of the signal, to aid analysis of detection problems */ /* Logging at this point filters the total no-hoper frames out of the log, and leaves anything which might feasibly be a DTMF digit. The log will then contain a list of the total, row and coloumn power levels for detailed analysis of detection problems. */ span_log(&s->logging, - SPAN_LOG_FLOW, + SPAN_LOG_DEBUG, "Potentially '%c' - total %.2fdB, row %.2fdB, col %.2fdB, duration %d - %s\n", dtmf_positions[(best_row << 2) + best_col], - log10f(s->energy)*10.0f - DTMF_POWER_OFFSET + DBM0_MAX_POWER, - log10f(row_energy[best_row]/DTMF_TO_TOTAL_ENERGY)*10.0f - DTMF_POWER_OFFSET + DBM0_MAX_POWER, - log10f(col_energy[best_col]/DTMF_TO_TOTAL_ENERGY)*10.0f - DTMF_POWER_OFFSET + DBM0_MAX_POWER, + power_ratio_to_db(s->energy) - dtmf_power_offset, + power_ratio_to_db(row_energy[best_row]/dtmf_to_total_energy) - dtmf_power_offset, + power_ratio_to_db(col_energy[best_col]/dtmf_to_total_energy) - dtmf_power_offset, s->duration, (hit) ? "hit" : "miss"); } @@ -291,7 +291,7 @@ SPAN_DECLARE(int) dtmf_rx(dtmf_rx_state_t *s, const int16_t amp[], int samples) /* Avoid reporting multiple no digit conditions on flaky hits */ if (s->in_digit || hit) { - i = (s->in_digit && !hit) ? -99 : lfastrintf(log10f(s->energy)*10.0f - DTMF_POWER_OFFSET + DBM0_MAX_POWER); + i = (s->in_digit && !hit) ? -99 : lfastrintf(power_ratio_to_db(s->energy) - dtmf_power_offset); s->realtime_callback(s->realtime_callback_data, hit, i, s->duration); s->duration = 0; } @@ -404,8 +404,6 @@ SPAN_DECLARE(void) dtmf_rx_parms(dtmf_rx_state_t *s, float reverse_twist, float threshold) { - float x; - if (filter_dialtone >= 0) { s->z350[0] = 0.0f; @@ -415,21 +413,14 @@ SPAN_DECLARE(void) dtmf_rx_parms(dtmf_rx_state_t *s, s->filter_dialtone = filter_dialtone; } /*endif*/ - if (twist >= 0) - s->normal_twist = powf(10.0f, twist/10.0f); + if (twist >= 0.0f) + s->normal_twist = db_to_power_ratio(twist); /*endif*/ - if (reverse_twist >= 0) - s->reverse_twist = powf(10.0f, reverse_twist/10.0f); + if (reverse_twist >= 0.0f) + s->reverse_twist = db_to_power_ratio(reverse_twist); /*endif*/ - if (threshold > -99) - { -#if defined(SPANDSP_USE_FIXED_POINT) - x = (DTMF_SAMPLES_PER_BLOCK*32768.0f/(128.0f*1.4142f))*powf(10.0f, (threshold - DBM0_MAX_SINE_POWER)/20.0f); -#else - x = (DTMF_SAMPLES_PER_BLOCK*32768.0f/1.4142f)*powf(10.0f, (threshold - DBM0_MAX_SINE_POWER)/20.0f); -#endif - s->threshold = x*x; - } + if (threshold > -99.0f) + s->threshold = goertzel_threshold_dbm0(DTMF_SAMPLES_PER_BLOCK, threshold); /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -461,9 +452,9 @@ SPAN_DECLARE(dtmf_rx_state_t *) dtmf_rx_init(dtmf_rx_state_t *s, s->realtime_callback = NULL; s->realtime_callback_data = NULL; s->filter_dialtone = false; - s->normal_twist = DTMF_NORMAL_TWIST; - s->reverse_twist = DTMF_REVERSE_TWIST; - s->threshold = DTMF_THRESHOLD; + s->normal_twist = dtmf_normal_twist; + s->reverse_twist = dtmf_reverse_twist; + s->threshold = dtmf_threshold; s->in_digit = 0; s->last_hit = 0; diff --git a/src/fax.c b/src/fax.c index 78252e1f..ec214da1 100644 --- a/src/fax.c +++ b/src/fax.c @@ -274,7 +274,7 @@ static void fax_set_rx_type(void *user_data, int type, int bit_rate, int short_t { span_log(&s->logging, SPAN_LOG_FLOW, "Set fallback rx type %d%s\n", type, use_hdlc ? " (HDLC)" : ""); fax_modems_set_rx_handler(t, (span_rx_handler_t) &sslfax_rx, &s->t30.sslfax, (span_rx_fillin_handler_t) NULL, &s->t30.sslfax); - sslfax_setup(&s->t30.sslfax, &s->t30, t30_non_ecm_put, t30_non_ecm_get, t30_hdlc_accept, hdlc_underflow_handler, s->t30.sslfax.tx_use_hdlc, use_hdlc, fax_get_phase); + sslfax_setup(&s->t30.sslfax, t30_non_ecm_put, t30_non_ecm_get, t30_hdlc_accept, hdlc_underflow_handler, s->t30.sslfax.tx_use_hdlc, use_hdlc, fax_get_phase, &s->t30); t->rx_bit_rate = bit_rate; t->current_rx_type = type; if (use_hdlc) @@ -334,7 +334,7 @@ static void fax_set_tx_type(void *user_data, int type, int bit_rate, int short_t span_log(&s->logging, SPAN_LOG_FLOW, "Set fallback tx type %d%s\n", type, use_hdlc ? " (HDLC)" : ""); fax_modems_set_tx_handler(t, (span_tx_handler_t) &sslfax_tx, &s->t30.sslfax); fax_modems_set_next_tx_handler(t, (span_tx_handler_t) &sslfax_tx, &s->t30.sslfax); - sslfax_setup(&s->t30.sslfax, &s->t30, t30_non_ecm_put, t30_non_ecm_get, t30_hdlc_accept, hdlc_underflow_handler, use_hdlc, s->t30.sslfax.rx_use_hdlc, fax_get_phase); + sslfax_setup(&s->t30.sslfax, t30_non_ecm_put, t30_non_ecm_get, t30_hdlc_accept, hdlc_underflow_handler, use_hdlc, s->t30.sslfax.rx_use_hdlc, fax_get_phase, &s->t30); t->transmit = true; t->tx_bit_rate = bit_rate; t->current_tx_type = type; diff --git a/src/modem_connect_tones.c b/src/modem_connect_tones.c index ba2081b8..c3954a8b 100644 --- a/src/modem_connect_tones.c +++ b/src/modem_connect_tones.c @@ -555,7 +555,11 @@ SPAN_DECLARE(int) modem_connect_tones_rx(modem_connect_tones_rx_state_t *s, if (s->tone_present != MODEM_CONNECT_TONES_FAX_CNG) { if (++s->tone_cycle_duration >= milliseconds_to_samples(415)) - report_tone_state(s, MODEM_CONNECT_TONES_FAX_CNG, lfastrintf(((s->channel_level == 0) ? (-96.329f + DBM0_MAX_POWER) : log10f(s->channel_level/32768.0f)*20.0f) + DBM0_MAX_POWER + 0.8f)); + { + report_tone_state(s, + MODEM_CONNECT_TONES_FAX_CNG, + lfastrintf(((s->channel_level == 0) ? (-96.329f + DBM0_MAX_POWER) : amplitude_ratio_to_db(s->channel_level/32768.0f)) + DBM0_MAX_POWER + 0.8f)); + } /*endif*/ } /*endif*/ @@ -641,7 +645,7 @@ SPAN_DECLARE(int) modem_connect_tones_rx(modem_connect_tones_rx_state_t *s, { report_tone_state(s, (s->am_level*15/256 > s->channel_level) ? MODEM_CONNECT_TONES_ANSAM_PR : MODEM_CONNECT_TONES_ANS_PR, - lfastrintf(((s->channel_level == 0) ? (-96.329f + DBM0_MAX_POWER) : log10f(s->channel_level/32768.0f)*20.0f) + DBM0_MAX_POWER + 0.8f)); + lfastrintf(((s->channel_level == 0) ? (-96.329f + DBM0_MAX_POWER) : amplitude_ratio_to_db(s->channel_level/32768.0f)) + DBM0_MAX_POWER + 0.8f)); } /*endif*/ } @@ -661,7 +665,7 @@ SPAN_DECLARE(int) modem_connect_tones_rx(modem_connect_tones_rx_state_t *s, { report_tone_state(s, (s->am_level*15/256 > s->channel_level) ? MODEM_CONNECT_TONES_ANSAM : MODEM_CONNECT_TONES_ANS, - lfastrintf(((s->channel_level == 0) ? (-96.329f + DBM0_MAX_POWER) : log10f(s->channel_level/32768.0f)*20.0f) + DBM0_MAX_POWER + 0.8f)); + lfastrintf(((s->channel_level == 0) ? (-96.329f + DBM0_MAX_POWER) : amplitude_ratio_to_db(s->channel_level/32768.0f)) + DBM0_MAX_POWER + 0.8f)); } /*endif*/ s->good_cycles = 0; @@ -723,7 +727,11 @@ SPAN_DECLARE(int) modem_connect_tones_rx(modem_connect_tones_rx_state_t *s, if (s->tone_present != MODEM_CONNECT_TONES_BELL_ANS) { if (++s->tone_cycle_duration >= milliseconds_to_samples(415)) - report_tone_state(s, MODEM_CONNECT_TONES_BELL_ANS, lfastrintf(((s->channel_level == 0) ? (-96.329f + DBM0_MAX_POWER) : log10f(s->channel_level/32768.0f)*20.0f) + DBM0_MAX_POWER + 0.8f)); + { + report_tone_state(s, + MODEM_CONNECT_TONES_BELL_ANS, + lfastrintf(((s->channel_level == 0) ? (-96.329f + DBM0_MAX_POWER) : amplitude_ratio_to_db(s->channel_level/32768.0f)) + DBM0_MAX_POWER + 0.8f)); + } /*endif*/ } /*endif*/ @@ -766,7 +774,11 @@ SPAN_DECLARE(int) modem_connect_tones_rx(modem_connect_tones_rx_state_t *s, if (s->tone_present != MODEM_CONNECT_TONES_CALLING_TONE) { if (++s->tone_cycle_duration >= milliseconds_to_samples(415)) - report_tone_state(s, MODEM_CONNECT_TONES_CALLING_TONE, lfastrintf(((s->channel_level == 0) ? (-96.329f + DBM0_MAX_POWER) : log10f(s->channel_level/32768.0f)*20.0f) + DBM0_MAX_POWER + 0.8f)); + { + report_tone_state(s, + MODEM_CONNECT_TONES_CALLING_TONE, + lfastrintf(((s->channel_level == 0) ? (-96.329f + DBM0_MAX_POWER) : amplitude_ratio_to_db(s->channel_level/32768.0f)) + DBM0_MAX_POWER + 0.8f)); + } /*endif*/ } /*endif*/ diff --git a/src/spandsp/expose.h b/src/spandsp/expose.h index 48365e59..544d809c 100644 --- a/src/spandsp/expose.h +++ b/src/spandsp/expose.h @@ -107,8 +107,8 @@ #include #include #include -#include #include +#include #endif /*- End of file ------------------------------------------------------------*/ diff --git a/src/spandsp/private/sprt.h b/src/spandsp/private/sprt.h index 46135ca0..d4504936 100644 --- a/src/spandsp/private/sprt.h +++ b/src/spandsp/private/sprt.h @@ -107,15 +107,15 @@ struct sprt_state_s struct { - int subsession_id; - int payload_type; + uint8_t subsession_id; + uint8_t payload_type; sprt_chan_t chan[SPRT_CHANNELS]; } rx; struct { - int subsession_id; - int payload_type; + uint8_t subsession_id; + uint8_t payload_type; sprt_chan_t chan[SPRT_CHANNELS]; diff --git a/src/spandsp/private/ssl_fax.h b/src/spandsp/private/ssl_fax.h index 82267f80..59302932 100644 --- a/src/spandsp/private/ssl_fax.h +++ b/src/spandsp/private/ssl_fax.h @@ -99,19 +99,19 @@ struct sslfax_state_s bool do_underflow; bool cleanup; - get_byte_func_t get_phase; + span_get_byte_func_t get_phase; - /*! \brief A user specified opaque pointer passed to the put, get, and hdlc routines. */ - void *msg_user_data; /*! \brief The callback function used to get bytes to be transmitted. */ - get_msg_func_t get_msg; + span_get_msg_func_t get_msg; /*! \brief The callback function used to put bytes received. */ - put_msg_func_t put_msg; + span_put_msg_func_t put_msg; /*! \brief The callback function used to accept HDLC frames. */ hdlc_frame_handler_t hdlc_accept; /*! \brief The callback function used for HDLC underflow indication. */ hdlc_underflow_handler_t hdlc_tx_underflow; /*! \brief Whether or not the data represents HDLC or not. */ + /*! \brief A user specified opaque pointer passed to the put, get, and hdlc routines. */ + void *user_data; bool tx_use_hdlc; bool rx_use_hdlc; diff --git a/src/spandsp/private/t30.h b/src/spandsp/private/t30.h index 88d83e59..6dddaa50 100644 --- a/src/spandsp/private/t30.h +++ b/src/spandsp/private/t30.h @@ -151,6 +151,11 @@ struct t30_state_s /*! \brief An opaque pointer passed to the document delivery handler. */ void *document_put_user_data; + /*! \brief The maximum permitted number of retries of a single command allowed. */ + int max_command_tries; + /*! \brief The maximum permitted number of retries of a single response request allowed. */ + int max_response_tries; + /*! \brief The DIS code for the minimum scan row time we require. This is usually 0ms, but if we are trying to simulate another type of FAX machine, we may need a non-zero value here. */ diff --git a/src/spandsp/private/v150_1.h b/src/spandsp/private/v150_1.h index 538681c7..d77c67d1 100644 --- a/src/spandsp/private/v150_1.h +++ b/src/spandsp/private/v150_1.h @@ -1,7 +1,7 @@ /* * SpanDSP - a series of DSP components for telephony * - * private/v150_1.h + * private/v150_1.h - An implementation of V.150.1. * * Written by Steve Underwood * @@ -26,8 +26,187 @@ #if !defined(_SPANDSP_PRIVATE_V150_1_H_) #define _SPANDSP_PRIVATE_V150_1_H_ +/* + telephone network + ^ + | + | + v + +-----------------------------------+ + | | + | Signal processing entity (SPE) | + | | + +-----------------------------------+ + | ^ + | | + Signal list 1 | | Signal list 2 + | | + v | + +-----------------------------------+ Signal list 5 +-----------------------------------+ + | | ----------------->| | + | SSE protocol state machine (P) | | Gateway state machine (s,s') | + | |<------------------| | + +-----------------------------------+ Signal list 6 +-----------------------------------+ + | ^ + | | + Signal list 3 | | Signal list 4 + | | + v | + +-----------------------------------+ + | | + | IP network processor | + | | + +-----------------------------------+ + ^ + | + | + v + IP network +*/ + +enum V150_1_SIGNAL_e +{ + /* Signal list 1 - SPE to SSE protocol state engine */ + + /* SPE has detected 2100Hz tone for a duration less than 50ms */ + V150_1_SIGNAL_TONE_2100HZ = 1, + /* SPE has detected 2225Hz tone for a duration less than 50ms */ + V150_1_SIGNAL_TONE_2225HZ, + /* SPE has verified presence of V.25 ANS type answer tone */ + V150_1_SIGNAL_ANS, + /* SPE has detected a 180-degree phase reversal in a verified ANS type answer tone */ + V150_1_SIGNAL_ANS_PR, + /* SPE has verified presence of V.8 ANSam type answer tone */ + V150_1_SIGNAL_ANSAM, + /* SPE has detected a 180-degree phase reversal in a verified ANSam type answer tone */ + V150_1_SIGNAL_ANSAM_PR, + /* SPE has detected a V.8 CI signal */ + V150_1_SIGNAL_CI, + /* SPE has detected a V.8 CM signal */ + V150_1_SIGNAL_CM, + /* SPE has detected a V.8 JM signal */ + V150_1_SIGNAL_JM, + /* SPE has detected a V.21 low channel signal */ + V150_1_SIGNAL_V21_LOW, + /* SPE has detected a V.21 high channel signal */ + V150_1_SIGNAL_V21_HIGH, + /* SPE has detected a V.23 low channel signal */ + V150_1_SIGNAL_V23_LOW, + /* SPE has detected a V.23 high channel signal */ + V150_1_SIGNAL_V23_HIGH, + /* SPE has detected a V.22bis scrambled binary one's signal */ + V150_1_SIGNAL_SB1, + /* SPE has detected a V.22bis unscrambled binary one's signal */ + V150_1_SIGNAL_USB1, + /* SPE has detected a V.22bis S1 signal */ + V150_1_SIGNAL_S1, + /* SPE has detected a V.32/V.32bis AA signal */ + V150_1_SIGNAL_AA, + /* SPE has detected a V.32/V.32bis AC signal */ + V150_1_SIGNAL_AC, + /* Call discrimination time-out */ + V150_1_SIGNAL_CALL_DISCRIMINATION_TIMEOUT, + /* SPE has detected an unknown or unsupported signal */ + V150_1_SIGNAL_UNKNOWN, + /* SPE has detected silence */ + V150_1_SIGNAL_SILENCE, + /* SPE has initiated an abort request */ + V150_1_SIGNAL_ABORT, + + /* Signal list 2 - SSE protocol state engine to SPE */ + + /* SPE requested to generate a V.25 ANS type answer tone signal */ + V150_1_SIGNAL_ANS_GEN, + /* SPE requested to generate a V.25 ANS type answer tone signal with 180-degree phase reversals every 450 ms */ + V150_1_SIGNAL_ANS_PR_GEN, + /* SPE requested to generate a V.8 ANSam type answer tone signal */ + V150_1_SIGNAL_ANSAM_GEN, + /* SPE requested to generate a V.8 ANSam type answer tone signal with 180-degree phase reversals every 450 ms */ + V150_1_SIGNAL_ANSAM_PR_GEN, + /* SPE requested to generate a 2225Hz tone */ + V150_1_SIGNAL_2225HZ_GEN, + /* SPE requested to prevent any modem signal to be output to the telephony side of the gateway */ + V150_1_SIGNAL_CONCEAL_MODEM, + /* SPE requested to block 2100Hz tone */ + V150_1_SIGNAL_BLOCK_2100HZ_TONE, + /* SPE requested to enable automode function */ + V150_1_SIGNAL_AUTOMODE_ENABLE, + + /* Signal list 3 - SSE protocol state engine to IP network */ + + /* Send audio state with reason code */ + V150_1_SIGNAL_AUDIO_GEN, + /* Send facsimile relay state with reason code */ + V150_1_SIGNAL_FAX_RELAY_GEN, + /* Send indeterminate state with reason code */ + V150_1_SIGNAL_INDETERMINATE_GEN, + /* Send modem relay state with reason code */ + V150_1_SIGNAL_MODEM_RELAY_GEN, + /* Send text relay state with reason code */ + V150_1_SIGNAL_TEXT_RELAY_GEN, + /* Send VBD state with reason code */ + V150_1_SIGNAL_VBD_GEN, + /* Send RFC4733 ANS event */ + V150_1_SIGNAL_RFC4733_ANS_GEN, + /* Send RFC4733 ANS with phase reversals event */ + V150_1_SIGNAL_RFC4733_ANS_PR_GEN, + /* Send RFC4733 ANSam event */ + V150_1_SIGNAL_RFC4733_ANSAM_GEN, + /* Send RFC4733 ANSam with phase reversals event */ + V150_1_SIGNAL_RFC4733_ANSAM_PR_GEN, + /* Send RFC4733 tone */ + V150_1_SIGNAL_RFC4733_TONE_GEN, + + /* Signal list 4 - IP network to SSE protocol state engine */ + + /* Audio state detected with reason code */ + V150_1_SIGNAL_AUDIO, + /* Facsimile relay state detected with reason code */ + V150_1_SIGNAL_FAX_RELAY, + /* Indeterminate state detected with reason code */ + V150_1_SIGNAL_INDETERMINATE, + /* Modem relay state detected with reason code */ + V150_1_SIGNAL_MODEM_RELAY, + /* Text relay state detected with reason code */ + V150_1_SIGNAL_TEXT_RELAY, + /* VBD state detected with reason code */ + V150_1_SIGNAL_VBD, + /* An RFC4733 ANS event detected with reason code */ + V150_1_SIGNAL_RFC4733_ANS, + /* An RFC4733 ANS with phase reversals event detected */ + V150_1_SIGNAL_RFC4733_ANS_PR, + /* An RFC4733 ANSam event detected */ + V150_1_SIGNAL_RFC4733_ANSAM, + /* An RFC4733 ANSam with phase reversals event detected */ + V150_1_SIGNAL_RFC4733_ANSAM_PR, + /* An RFC4733 tone detected */ + V150_1_SIGNAL_RFC4733_TONE, + + /* Lists 5 and 6 have the same contents */ + /* Signal list 5 - SSE protocol state engine to gateway */ + /* Signal list 6 - Gateway to SSE protocol state engine */ + + /* Audio state */ + V150_1_SIGNAL_AUDIO_STATE, + /* Facsimile relay state */ + V150_1_SIGNAL_FAX_RELAY_STATE, + /* Indeterminate state */ + V150_1_SIGNAL_INDETERMINATE_STATE, + /* Modem relay state */ + V150_1_SIGNAL_MODEM_RELAY_STATE, + /* Text relay state */ + V150_1_SIGNAL_TEXT_RELAY_STATE, + /* VBD state */ + V150_1_SIGNAL_VBD_STATE, + + /* Signal not listed in V.150.1 */ + V150_1_SIGNAL_CALL_DISCRIMINATION_TIMER_EXPIRED +}; + typedef struct { + v150_1_cdscselect_t cdscselect; + bool v42_lapm_supported; /* Annex A was removed from the V.42 spec. in 2002, so it won't be supported. */ bool v42_annex_a_supported; @@ -110,18 +289,38 @@ typedef struct bool busy; + int sprt_subsession_id; + uint8_t sprt_payload_type; + int connection_state; int cleardown_reason; } v150_1_near_far_t; struct v150_1_state_s { - v150_1_tx_packet_handler_t tx_packet_handler; - void *tx_packet_user_data; - v150_1_rx_octet_handler_t rx_octet_handler; - void *rx_octet_handler_user_data; + v150_1_rx_data_handler_t rx_data_handler; + void *rx_data_handler_user_data; v150_1_rx_status_report_handler_t rx_status_report_handler; void *rx_status_report_user_data; + v150_1_timer_handler_t timer_handler; + void *timer_user_data; + + v150_1_cdscselect_t cdscselect; + /* True if RFC4733 is preferred */ + bool rfc4733_preferred; + int call_discrimination_timeout; + + /* The current media state of the local node (i.e., the value that will be sent to the remote + node in the event field of an SSE message) */ + uint8_t local_media_state; /* See V.150.1 C.4.3.1 */ + /* The last known media state of the remote node, as known by the local node (i.e. the value + that will be sent to the remote node in the remote media state field of an SSE extension + field with explicit acknowledgement) */ + uint8_t remote_media_state; /* See V.150.1 C.4.3.1 */ + /* The last known mode of the local node known by the remote node, as known by the local node + (i.e., the value that was received from the remote node in the remote media state field of + an SSE extension field with explicit acknowledgement) */ + uint8_t remote_ack; /* See V.150.1 C.4.3.1 */ struct { @@ -147,6 +346,14 @@ struct v150_1_state_s int break_duration; } far; int joint_connection_state; + + v150_1_sse_state_t sse; + sprt_state_t sprt; + + span_timestamp_t latest_timer; + span_timestamp_t call_discrimination_timer; + span_timestamp_t sse_timer; + span_timestamp_t sprt_timer; /*! \brief Error and flow logging control */ logging_state_t logging; }; diff --git a/src/spandsp/private/v150_1_sse.h b/src/spandsp/private/v150_1_sse.h index 522786a3..b3d6b611 100644 --- a/src/spandsp/private/v150_1_sse.h +++ b/src/spandsp/private/v150_1_sse.h @@ -1,8 +1,9 @@ /* * SpanDSP - a series of DSP components for telephony * - * private/v150_1_sse.h - An implementation of the SSE protocol defined in V.150.1 - * Annex C, less the packet exchange part + * private/v150_1_sse.h - An implementation of the state signaling events + * (SSE), protocol defined in V.150.1 Annex C, less + * the packet exchange part * * Written by Steve Underwood * @@ -27,140 +28,6 @@ #if !defined(_SPANDSP_PRIVATE_V150_1_SSE_H_) #define _SPANDSP_PRIVATE_V150_1_SSE_H_ -enum v150_1_sse_signal_e -{ - /* Signal list 1 */ - - /* SPE has detected 2100Hz tone for a duration less than 50ms */ - V150_1_SSE_SIGNAL_TONE_2100HZ = 1, - /* SPE has detected 2225Hz tone for a duration less than 50ms */ - V150_1_SSE_SIGNAL_TONE_2225HZ, - /* SPE has verified presence of V.25 ANS type answer tone */ - V150_1_SSE_SIGNAL_ANS, - /* SPE has detected a 180-degree phase reversal in a verified ANS type answer tone */ - V150_1_SSE_SIGNAL_ANS_PR, - /* SPE has verified presence of V.8 ANSam type answer tone */ - V150_1_SSE_SIGNAL_ANSAM, - /* SPE has detected a 180-degree phase reversal in a verified ANSam type answer tone */ - V150_1_SSE_SIGNAL_ANSAM_PR, - /* SPE has detected a V.8 CI signal */ - V150_1_SSE_SIGNAL_CI, - /* SPE has detected a V.8 CM signal */ - V150_1_SSE_SIGNAL_CM, - /* SPE has detected a V.8 JM signal */ - V150_1_SSE_SIGNAL_JM, - /* SPE has detected a V.21 low channel signal */ - V150_1_SSE_SIGNAL_V21_LOW, - /* SPE has detected a V.21 high channel signal */ - V150_1_SSE_SIGNAL_V21_HIGH, - /* SPE has detected a V.23 low channel signal */ - V150_1_SSE_SIGNAL_V23_LOW, - /* SPE has detected a V.23 high channel signal */ - V150_1_SSE_SIGNAL_V23_HIGH, - /* SPE has detected a V.22 bis scrambled binary one's signal */ - V150_1_SSE_SIGNAL_SB1, - /* SPE has detected a V.22 bis unscrambled binary one's signal */ - V150_1_SSE_SIGNAL_USB1, - /* SPE has detected a V.22 bis S1 signal */ - V150_1_SSE_SIGNAL_S1, - /* SPE has detected a V.32/V.32 bis AA signal */ - V150_1_SSE_SIGNAL_AA, - /* SPE has detected a V.32/V.32 bis AC signal */ - V150_1_SSE_SIGNAL_AC, - /* Call discrimination time-out */ - V150_1_SSE_SIGNAL_CALL_DISCRIMINATION_TIMEOUT, - /* SPE has detected an unknown or unsupported signal */ - V150_1_SSE_SIGNAL_UNKNOWN, - /* SPE has detected silence */ - V150_1_SSE_SIGNAL_SILENCE, - /* SPE has initiated an abort request */ - V150_1_SSE_SIGNAL_ABORT, - - /* Signal list 2 */ - - /* SPE requested to generate a V.25 ANS type answer tone signal */ - V150_1_SSE_SIGNAL_ANS_GEN, - /* SPE requested to generate a V.25 ANS type answer tone signal with 180-degree phase reversals every 450 ms */ - V150_1_SSE_SIGNAL_ANS_PR_GEN, - /* SPE requested to generate a V.8 ANSam type answer tone signal */ - V150_1_SSE_SIGNAL_ANSAM_GEN, - /* SPE requested to generate a V.8 ANSam type answer tone signal with 180-degree phase reversals every 450 ms */ - V150_1_SSE_SIGNAL_ANSAM_PR_GEN, - /* SPE requested to generate a 2225Hz tone */ - V150_1_SSE_SIGNAL_2225HZ_GEN, - /* SPE requested to prevent any modem signal to be output to the telephony side of the gateway */ - V150_1_SSE_SIGNAL_CONCEAL_MODEM, - /* SPE requested to block 2100Hz tone */ - V150_1_SSE_SIGNAL_BLOCK_2100HZ_TONE, - /* SPE requested to enable automode function */ - V150_1_SSE_SIGNAL_AUTOMODE_ENABLE, - - /* Signal list 3 */ - - /* Send audio state with reason code */ - V150_1_SSE_SIGNAL_A_GEN, - /* Send facsimile relay state with reason code */ - V150_1_SSE_SIGNAL_F_GEN, - /* Send indeterminate state with reason code */ - V150_1_SSE_SIGNAL_I_GEN, - /* Send modem relay state with reason code */ - V150_1_SSE_SIGNAL_M_GEN, - /* Send text relay state with reason code */ - V150_1_SSE_SIGNAL_T_GEN, - /* Send VBD state with reason code */ - V150_1_SSE_SIGNAL_V_GEN, - /* Send RFC2833 ANS event */ - V150_1_SSE_SIGNAL_RFC4733_ANS_GEN, - /* Send RFC2833 ANS with phase reversals event */ - V150_1_SSE_SIGNAL_RFC4733_ANS_PR_GEN, - /* Send RFC2833 ANSam event */ - V150_1_SSE_SIGNAL_RFC4733_ANSAM_GEN, - /* Send RFC2833 ANSam with phase reversals event */ - V150_1_SSE_SIGNAL_RFC4733_ANSAM_PR_GEN, - /* Send RFC2833 tone */ - V150_1_SSE_SIGNAL_RFC4733_TONE_GEN, - - /* Signal list 4 */ - - /* Audio state detected with reason code */ - V150_1_SSE_SIGNAL_A, - /* Facsimile relay state detected with reason code */ - V150_1_SSE_SIGNAL_F, - /* Indeterminate state detected with reason code */ - V150_1_SSE_SIGNAL_I, - /* Modem relay state detected with reason code */ - V150_1_SSE_SIGNAL_M, - /* Text relay state detected with reason code */ - V150_1_SSE_SIGNAL_T, - /* VBD state detected with reason code */ - V150_1_SSE_SIGNAL_V, - /* An RFC4733 ANS event detected with reason code */ - V150_1_SSE_SIGNAL_RFC4733_ANS, - /* An RFC4733 ANS with phase reversals event detected */ - V150_1_SSE_SIGNAL_RFC4733_ANS_PR, - /* An RFC4733 ANSam event detected */ - V150_1_SSE_SIGNAL_RFC4733_ANSAM, - /* An RFC4733 ANSam with phase reversals event detected */ - V150_1_SSE_SIGNAL_RFC4733_ANSAM_PR, - /* An RFC4733 tone detected */ - V150_1_SSE_SIGNAL_RFC4733_TONE, - - /* Signal lists 5 and 6 */ - - /* Audio state */ - V150_1_SSE_SIGNAL_A_STATE, - /* Facsimile relay state */ - V150_1_SSE_SIGNAL_F_STATE, - /* Indeterminate state */ - V150_1_SSE_SIGNAL_I_STATE, - /* Modem relay state */ - V150_1_SSE_SIGNAL_M_STATE, - /* Text relay state */ - V150_1_SSE_SIGNAL_T_STATE, - /* VBD state */ - V150_1_SSE_SIGNAL_V_STATE -}; - struct v150_1_sse_state_s { int reliability_method; @@ -178,24 +45,8 @@ struct v150_1_sse_state_s span_timestamp_t latest_timer; - /* True is voice band bata (VBD) is allowed */ - bool vbd_available; - /* True is voice band bata (VBD) is preferred */ - bool vbd_preferred; - /* Explicit acknowledgement variables. */ bool explicit_ack_enabled; - /* The current media state of the local node (i.e., the value that will be sent to the remote - node in the event field of an SSE message) */ - uint8_t lcl_mode; /* See V.150.1 C.4.3.1 */ - /* The last known media state of the remote node, as known by the local node (i.e. the value - that will be sent to the remote node in the remote media state field of an SSE extension - field with explicit acknowledgement) */ - uint8_t rmt_mode; /* See V.150.1 C.4.3.1 */ - /* The last known mode of the local node known by the remote node, as known by the local node - (i.e., the value that was received from the remote node in the remote media state field of - an SSE extension field with explicit acknowledgement) */ - uint8_t rmt_ack; /* See V.150.1 C.4.3.1 */ span_timestamp_t recovery_timer_t1; /* See V.150.1 C.5.4.1 */ span_timestamp_t recovery_timer_t2; /* See V.150.1 C.5.4.1 */ @@ -222,15 +73,8 @@ struct v150_1_sse_state_s /* The last timestamp received from the remote gateway or endpoint */ uint32_t previous_rx_timestamp; - v150_1_sse_packet_handler_t tx_packet_handler; + v150_1_sse_tx_packet_handler_t tx_packet_handler; void *tx_packet_user_data; - v150_1_sse_status_handler_t status_handler; - void *status_user_data; - v150_1_sse_timer_handler_t timer_handler; - void *timer_user_data; - - /*! \brief Error and flow logging control */ - logging_state_t logging; }; #endif diff --git a/src/spandsp/private/v18.h b/src/spandsp/private/v18.h index a0ec6dbc..f7b9d952 100644 --- a/src/spandsp/private/v18.h +++ b/src/spandsp/private/v18.h @@ -79,7 +79,7 @@ struct v18_state_s bool repeat_shifts; bool autobauding; /* The stored message is used during probing. See V.18/5.2.12.1 */ - uint8_t stored_message[81]; + char stored_message[81]; int current_mode; int tx_state; int rx_state; diff --git a/src/spandsp/sprt.h b/src/spandsp/sprt.h index efd0ae88..cab00eb4 100644 --- a/src/spandsp/sprt.h +++ b/src/spandsp/sprt.h @@ -70,6 +70,14 @@ #define SPRT_MAX_MAX_TRIES 20 #define SPRT_DEFAULT_MAX_TRIES 10 +enum sprt_status_e +{ + SPRT_STATUS_OK = 0, + SPRT_STATUS_EXCESS_RETRIES = 1, + SPRT_STATUS_SUBSESSION_CHANGED = 2, + SPRT_STATUS_OUT_OF_SEQUENCE = 3 +}; + /* This view of the transmission channels divides them into an overall range, and a reliable subset range within the overall range. */ enum sprt_tcid_range_view_e @@ -190,9 +198,9 @@ SPAN_DECLARE(logging_state_t *) sprt_get_logging_state(sprt_state_t *s); \param status_user_data An opaque pointer supplied to status_handler. \return A pointer to the SPRT context, or NULL if there was a problem. */ SPAN_DECLARE(sprt_state_t *) sprt_init(sprt_state_t *s, - int subsession_id, - int rx_payload_type, - int tx_payload_type, + uint8_t subsession_id, + uint8_t rx_payload_type, + uint8_t tx_payload_type, channel_parms_t parms[SPRT_CHANNELS], sprt_tx_packet_handler_t tx_packet_handler, void *tx_user_data, diff --git a/src/spandsp/ssl_fax.h b/src/spandsp/ssl_fax.h index a89a6b16..a5deda68 100644 --- a/src/spandsp/ssl_fax.h +++ b/src/spandsp/ssl_fax.h @@ -56,11 +56,19 @@ SPAN_DECLARE(int) sslfax_tx(sslfax_state_t *s, int16_t amp[], int len); SPAN_DECLARE(int) sslfax_rx(sslfax_state_t *s, const int16_t amp[], int len); -SPAN_DECLARE(void) sslfax_setup(sslfax_state_t *s, void *msg_user_data, put_msg_func_t put_msg, get_msg_func_t get_msg, hdlc_frame_handler_t hdlc_accept, hdlc_underflow_handler_t hdlc_tx_underflow, bool tx_use_hdlc, bool rx_use_hdlc, get_byte_func_t get_phase); +SPAN_DECLARE(void) sslfax_setup(sslfax_state_t *s, + span_put_msg_func_t put_msg, + span_get_msg_func_t get_msg, + hdlc_frame_handler_t hdlc_accept, + hdlc_underflow_handler_t hdlc_tx_underflow, + bool tx_use_hdlc, + bool rx_use_hdlc, + span_get_byte_func_t get_phase, + void *user_data); -SPAN_DECLARE(int) sslfax_write(sslfax_state_t *s, const uint8_t *buf, unsigned int count, int modemFd, long ms, bool filter, bool sustain); +SPAN_DECLARE(int) sslfax_write(sslfax_state_t *s, const uint8_t *buf, unsigned int count, int modem_fd, long int ms, bool filter, bool sustain); -SPAN_DECLARE(int) sslfax_read(sslfax_state_t *s, void *buf, size_t count, int modemFd, long ms, bool sustain, bool carryon); +SPAN_DECLARE(int) sslfax_read(sslfax_state_t *s, void *buf, size_t count, int modem_fd, long ms, bool sustain, bool carryon); #if defined(__cplusplus) } diff --git a/src/spandsp/t30_api.h b/src/spandsp/t30_api.h index 69ddb344..19fbec63 100644 --- a/src/spandsp/t30_api.h +++ b/src/spandsp/t30_api.h @@ -465,11 +465,23 @@ SPAN_DECLARE(void) t30_set_iaf_mode(t30_state_t *s, int iaf); SPAN_DECLARE(int) t30_set_ecm_capability(t30_state_t *s, bool enabled); /*! Specify if page retransmission is allowed by a T.30 context. - \brief Select page regtransmission capable. + \brief Select page retransmission capable. \param s The T.30 context. \param enabled True for retransmit capable, or false for not retransmit capable. */ SPAN_DECLARE(void) t30_set_retransmit_capable(t30_state_t *s, bool enabled); +/*! Specify the maximum number of times a command will be tried by a T.30 context before giving up. + \brief Select maximum command tries. + \param s The T.30 context. + \param tries The mmaximum number of tries. Default is 3 */ +SPAN_DECLARE(void) t30_set_max_command_tries(t30_state_t *s, int tries); + +/*! Specify the maximum number of times a response will be tried by a T.30 context before giving up. + \brief Select maximum response tries. + \param s The T.30 context. + \param tries The mmaximum number of tries. Default is 6 */ +SPAN_DECLARE(void) t30_set_max_response_tries(t30_state_t *s, int tries); + /*! Specify the output encoding for TIFF files created during FAX reception. \brief Specify the output encoding for TIFF files created during FAX reception. \param s The T.30 context. diff --git a/src/spandsp/telephony.h b/src/spandsp/telephony.h index 9a543ab2..69d1deab 100644 --- a/src/spandsp/telephony.h +++ b/src/spandsp/telephony.h @@ -131,6 +131,18 @@ typedef int (*span_tx_handler_t)(void *s, int16_t amp[], int max_len); #define FP_Q2_30(x) ((int32_t) (65536.0*16384.0*(x) + (((x) >= 0.0) ? 0.5 : -0.5))) #define FP_Q1_31(x) ((int32_t) (65536.0*32768.0*(x) + (((x) >= 0.0) ? 0.5 : -0.5))) +#if defined(SPANDSP_USE_FIXED_POINT) +#define db_to_power_ratio(val) powf(10.0f, val/10.0f) +#define db_to_amplitude_ratio(val) powf(10.0f, val/20.0f) +#define power_ratio_to_db(val) (10.0f*log10f(val)) +#define amplitude_ratio_to_db(val) (20.0f*log10f(val)) +#else +#define db_to_power_ratio(val) powf(10.0f, val/10.0f) +#define db_to_amplitude_ratio(val) powf(10.0f, val/20.0f) +#define power_ratio_to_db(val) (10.0f*log10f(val)) +#define amplitude_ratio_to_db(val) (20.0f*log10f(val)) +#endif + #if defined(__cplusplus) /* C++ doesn't seem to have sane rounding functions/macros yet */ #if !defined(WIN32) diff --git a/src/spandsp/tone_detect.h b/src/spandsp/tone_detect.h index 7df69468..38226f70 100644 --- a/src/spandsp/tone_detect.h +++ b/src/spandsp/tone_detect.h @@ -57,6 +57,26 @@ struct goertzel_state_s int current_sample; }; +/* Convert a power level in dBm0 or dBov to the equivalent result from a Goertzel filter. This is len*len times the actual power, since + the DFT calculation accumulates at the square of the number of samples. */ +#if defined(SPANDSP_USE_FIXED_POINT) +#define goertzel_threshold_dbm0(len,thresh) (int) ((len*len*256.0*256.0/2.0*pow(10.0, (thresh - DBM0_MAX_SINE_POWER)/10.0)) +#define goertzel_threshold_dbmov(len,thresh) (int) ((len*len*256.0*256.0/2.0*pow(10.0, (thresh - DBMOV_MAX_SINE_POWER)/10.0)) +#else +#define goertzel_threshold_dbm0(len,thresh) (float) ((len*len*32768.0*32768.0/2.0)*pow(10.0, (thresh - DBM0_MAX_SINE_POWER)/10.0)) +#define goertzel_threshold_dbmov(len,thresh) (float) ((len*len*32768.0*32768.0/2.0)*pow(10.0, (thresh - DBMOV_MAX_SINE_POWER)/10.0)) +#endif + +/* Convert a power level in dBm0 or dBov to the equivalent energy to expect from an integration over len samples. So, this is len + times the actual power. */ +#if defined(SPANDSP_USE_FIXED_POINT) +#define energy_threshold_dbm0(len,thresh) (int) ((len*256.0*256.0/2.0)*pow(10.0, (thresh - DBM0_MAX_SINE_POWER)/10.0)) +#define energy_threshold_dbmov(len,thresh) (int) ((len*256.0*256.0/2.0)*pow(10.0, (thresh - DBMOV_MAX_SINE_POWER)/10.0)) +#else +#define energy_threshold_dbm0(len,thresh) (float) ((len*32768.0*32768.0/2.0)*pow(10.0, (thresh - DBM0_MAX_SINE_POWER)/10.0)) +#define energy_threshold_dbmov(len,thresh) (float) ((len*32768.0*32768.0/2.0)*pow(10.0, (thresh - DBMOV_MAX_SINE_POWER)/10.0)) +#endif + /*! Goertzel filter descriptor. */ diff --git a/src/spandsp/v150_1.h b/src/spandsp/v150_1.h index c4f9e7dd..6a3bddd5 100644 --- a/src/spandsp/v150_1.h +++ b/src/spandsp/v150_1.h @@ -1,7 +1,7 @@ /* * SpanDSP - a series of DSP components for telephony * - * v150_1.h + * v150_1.h - An implementation of V.150.1. * * Written by Steve Underwood * @@ -34,15 +34,20 @@ typedef struct { struct { - int bits; - int parity_code; - int stop_bits; - } data_format_change; + int local_state; + int remote_state; + } media_state_change; struct { int state; int cleardown_reason; - } state_change; + } connection_state_change; + struct + { + int bits; + int parity_code; + int stop_bits; + } data_format_change; struct { int source; @@ -97,10 +102,16 @@ typedef struct typedef int (*v150_1_tx_packet_handler_t) (void *user_data, int channel, const uint8_t msg[], int len); -typedef int (*v150_1_rx_octet_handler_t) (void *user_data, const uint8_t msg[], int len, int fill); +typedef int (*v150_1_rx_data_handler_t) (void *user_data, const uint8_t msg[], int len, int fill); typedef int (*v150_1_rx_status_report_handler_t) (void *user_data, v150_1_status_t *report); +typedef int (*v150_1_sse_tx_packet_handler_t) (void *user_data, bool repeat, const uint8_t pkt[], int len); + +typedef int (*v150_1_sse_status_handler_t) (void *user_data, int status); + +typedef span_timestamp_t (*v150_1_timer_handler_t) (void *user_data, span_timestamp_t timeout); + typedef struct v150_1_state_s v150_1_state_t; /* The information packet types are: @@ -138,6 +149,19 @@ typedef struct v150_1_state_s v150_1_state_t; maximum allowed for a V.150.1 packet. */ +#define V150_1_CALL_DISCRIMINATION_DEFAULT_TIMEOUT 60000000 + +/* Indeterminate is the initial state before the correct value has been determined. The other values are from + Table 32/V.150.1 */ +typedef enum v150_1_cdscselect_e +{ + V150_1_CDSCSELECT_INDETERMINATE = 0, + V150_1_CDSCSELECT_AUDIO = 1, + V150_1_CDSCSELECT_AUDIO_RFC4733 = 2, + V150_1_CDSCSELECT_VBD_SELECT = 3, + V150_1_CDSCSELECT_MIXED = 4 +} v150_1_cdscselect_t; + enum v150_1_msgid_e { V150_1_MSGID_NULL = 0, /* Transport channel N/A */ @@ -379,6 +403,23 @@ enum v150_1_state_e V150_1_STATE_CONNECTED = 5 }; +/* Table C.1/V.150.1 plus amendments */ +enum v150_1_media_states_e +{ + V150_1_MEDIA_STATE_ITU_RESERVED_0 = 0, /* Reserved for future use by ITU-T */ + V150_1_MEDIA_STATE_INITIAL_AUDIO = 1, /* Initial Audio */ + V150_1_MEDIA_STATE_VOICE_BAND_DATA = 2, /* Voice Band Data (VBD) */ + V150_1_MEDIA_STATE_MODEM_RELAY = 3, /* Modem Relay */ + V150_1_MEDIA_STATE_FAX_RELAY = 4, /* Fax Relay */ + V150_1_MEDIA_STATE_TEXT_RELAY = 5, /* Text Relay */ + V150_1_MEDIA_STATE_TEXT_PROBE = 6, /* Text Probe (Amendment 2) */ + V150_1_MEDIA_STATE_ITU_RESERVED_MIN = 7, /* Start of ITU reserved range */ + V150_1_MEDIA_STATE_ITU_RESERVED_MAX = 31, /* End of ITU reserved range */ + V150_1_MEDIA_STATE_RESERVED_MIN = 32, /* Start of vendor defined reserved range */ + V150_1_MEDIA_STATE_RESERVED_MAX = 63, /* End of vendor defined reserved range */ + V150_1_MEDIA_STATE_INDETERMINATE = 64 /* Indeterminate */ +}; + /* Definitions for the mrmods field used in the SDP which controls V.150.1 */ enum v150_1_mrmods_e { @@ -404,20 +445,23 @@ enum v150_1_mrmods_e enum v150_1_status_reason_e { V150_1_STATUS_REASON_NULL = 0, - V150_1_STATUS_REASON_STATE_CHANGED = 1, - V150_1_STATUS_REASON_DATA_FORMAT_CHANGED = 2, - V150_1_STATUS_REASON_BREAK_RECEIVED = 3, - V150_1_STATUS_REASON_RATE_RETRAIN_RECEIVED = 4, - V150_1_STATUS_REASON_RATE_RENEGOTIATION_RECEIVED = 5, - V150_1_STATUS_REASON_BUSY_CHANGED = 6, - V150_1_STATUS_REASON_PHYSUP = 7, - V150_1_STATUS_REASON_CONNECTED = 8 + V150_1_STATUS_REASON_MEDIA_STATE_CHANGED = 1, + V150_1_STATUS_REASON_CONNECTION_STATE_CHANGED = 2, + V150_1_STATUS_REASON_DATA_FORMAT_CHANGED = 3, + V150_1_STATUS_REASON_BREAK_RECEIVED = 4, + V150_1_STATUS_REASON_RATE_RETRAIN_RECEIVED = 5, + V150_1_STATUS_REASON_RATE_RENEGOTIATION_RECEIVED = 6, + V150_1_STATUS_REASON_BUSY_CHANGED = 7, + V150_1_STATUS_REASON_CONNECTION_STATE_PHYSUP = 8, + V150_1_STATUS_REASON_CONNECTION_STATE_CONNECTED = 9 }; #if defined(__cplusplus) extern "C" { #endif +SPAN_DECLARE(int) v150_1_state_machine(v150_1_state_t *s, int signal, const uint8_t *msg, int len); + SPAN_DECLARE(const char *) v150_1_msg_id_to_str(int msg_id); SPAN_DECLARE(const char *) v150_1_data_bits_to_str(int code); @@ -452,6 +496,10 @@ SPAN_DECLARE(const char *) v150_1_jm_category_to_str(int category); SPAN_DECLARE(const char *) v150_1_jm_info_modulation_to_str(int modulation); +SPAN_DECLARE(const char *) v150_1_signal_to_str(int modulation); + +SPAN_DECLARE(const char *) v150_1_media_state_to_str(int modulation); + SPAN_DECLARE(int) v150_1_set_parity(v150_1_state_t *s, int mode); SPAN_DECLARE(int) v150_1_set_stop_bits(v150_1_state_t *s, int bits); @@ -520,13 +568,46 @@ SPAN_DECLARE(int) v150_1_set_tx_data_signalling_rate(v150_1_state_t *s, int rate SPAN_DECLARE(int) v150_1_set_rx_data_signalling_rate(v150_1_state_t *s, int rate); +SPAN_DECLARE(void) v150_1_set_near_cdscselect(v150_1_state_t *s, v150_1_cdscselect_t select); + +SPAN_DECLARE(void) v150_1_set_far_cdscselect(v150_1_state_t *s, v150_1_cdscselect_t select); + +SPAN_DECLARE(void) v150_1_set_call_discrimination_timeout(v150_1_state_t *s, int timeout); + +SPAN_DECLARE(int) v150_1_timer_expired(v150_1_state_t *s, span_timestamp_t now); + SPAN_DECLARE(logging_state_t *) v150_1_get_logging_state(v150_1_state_t *s); +SPAN_DECLARE(int) v150_1_test_rx_sprt_msg(v150_1_state_t *s, int chan, int seq_no, const uint8_t buf[], int len); + +/*! Initialise a V.150.1 context. This must be called before the first use of the context, to + initialise its contents. + \brief Initialise a V.150.1 context. + \param s The V.150.1 context. + \param sprt_tx_packet_handler Callback routine to handle the transmission of SPRT packets. + \param sprt_tx_packet_handler_user_data An opaque pointer, passed in calls to the SPRT packet tx handler + \param sprt_tx_payload_type The payload type for transmitted SPRT packets. + \param sprt_rx_payload_type The payload type expected in received SPRT packets. + \param sse_tx_packet_handler Callback routine to handle the transmission of SSE packets. + \param sse_tx_packet_user_data An opaque pointer, passed in calls to the SSE tx packet handler + \param v150_1_timer_handler Callback routine to control SPRT, SSE and overall V.150.1 timers. + \param v150_1_timer_user_data An opaque pointer, passed in calls to the timer handler + \param rx_data_handler Callback routine to handle the octet stream from an SPRT interaction + \param rx_data_handler_user_data An opaque pointer, passed in calls to the rx octet handler. + \param rx_status_report_handler Callback routine for V.150.1 protocol status reports + \param rx_status_report_user_data An opaque pointer, passed in calls to the rx status report handler + \return A pointer to the V.150.1 context, or NULL if there was a problem. */ SPAN_DECLARE(v150_1_state_t *) v150_1_init(v150_1_state_t *s, - v150_1_tx_packet_handler_t tx_packet_handler, - void *tx_packet_user_data, - v150_1_rx_octet_handler_t rx_octet_handler, - void *rx_octet_handler_user_data, + sprt_tx_packet_handler_t sprt_tx_packet_handler, + void *sprt_tx_packet_handler_user_data, + uint8_t sprt_tx_payload_type, + uint8_t sprt_rx_payload_type, + v150_1_sse_tx_packet_handler_t sse_tx_packet_handler, + void *sse_tx_packet_user_data, + v150_1_timer_handler_t v150_1_timer_handler, + void *v150_1_timer_user_data, + v150_1_rx_data_handler_t rx_data_handler, + void *rx_data_handler_user_data, v150_1_rx_status_report_handler_t rx_status_report_handler, void *rx_status_report_user_data); diff --git a/src/spandsp/v150_1_sse.h b/src/spandsp/v150_1_sse.h index 18775bcb..8d62fd33 100644 --- a/src/spandsp/v150_1_sse.h +++ b/src/spandsp/v150_1_sse.h @@ -1,8 +1,9 @@ /* * SpanDSP - a series of DSP components for telephony * - * v150_1_sse.h - An implementation of the SSE protocol defined in V.150.1 - * Annex C, less the packet exchange part + * v150_1_sse.h - An implementation of the state signaling events (SSE), + * protocol defined in V.150.1 Annex C, less the packet + * exchange part * * Written by Steve Underwood * @@ -27,12 +28,10 @@ #if !defined(_SPANDSP_V150_1_SSE_H_) #define _SPANDSP_V150_1_SSE_H_ -typedef int (*v150_1_sse_packet_handler_t) (void *user_data, bool repeat, const uint8_t pkt[], int len); +typedef int (*v150_1_sse_tx_packet_handler_t) (void *user_data, bool repeat, const uint8_t pkt[], int len); typedef int (*v150_1_sse_status_handler_t) (void *user_data, int status); -typedef span_timestamp_t (*v150_1_sse_timer_handler_t) (void *user_data, span_timestamp_t timeout); - /* V.150.1 C.4.1 */ #define V150_1_SSE_DEFAULT_REPETITIONS 3 #define V150_1_SSE_DEFAULT_REPETITION_INTERVAL 20000 @@ -47,159 +46,143 @@ typedef span_timestamp_t (*v150_1_sse_timer_handler_t) (void *user_data, span_ti #define V150_1_SSE_DEFAULT_RECOVERY_T1 1000000 #define V150_1_SSE_DEFAULT_RECOVERY_T2 1000000 -/* V.150.1 C.5.3 */ -enum v150_1_states_e -{ - V150_1_STATE_INITIAL_AUDIO = 'a', - V150_1_STATE_VOICE_BAND_DATA = 'v', - V150_1_STATE_MODEM_RELAY = 'm', - V150_1_STATE_FAX_RELAY = 'f', - V150_1_STATE_TEXT_RELAY = 't', - V150_1_STATE_INDETERMINATE = 'i' -}; - -/* Table C.1/V.150.1 plus amendments */ -enum v150_1_sse_media_states_e -{ - V150_1_SSE_MEDIA_STATE_ITU_RESERVED_0 = 0, /* Reserved for future use by ITU-T */ - V150_1_SSE_MEDIA_STATE_INITIAL_AUDIO = 1, /* Initial Audio */ - V150_1_SSE_MEDIA_STATE_VOICE_BAND_DATA = 2, /* Voice Band Data (VBD) */ - V150_1_SSE_MEDIA_STATE_MODEM_RELAY = 3, /* Modem Relay */ - V150_1_SSE_MEDIA_STATE_FAX_RELAY = 4, /* Fax Relay */ - V150_1_SSE_MEDIA_STATE_TEXT_RELAY = 5, /* Text Relay */ - V150_1_SSE_MEDIA_STATE_TEXT_PROBE = 6, /* Text Probe (Amendment 2) */ - V150_1_SSE_MEDIA_STATE_ITU_RESERVED_MIN = 7, /* Start of ITU reserved range */ - V150_1_SSE_MEDIA_STATE_ITU_RESERVED_MAX = 31, /* End of ITU reserved range */ - V150_1_SSE_MEDIA_STATE_RESERVED_MIN = 32, /* Start of vendor defined reserved range */ - V150_1_SSE_MEDIA_STATE_RESERVED_MAX = 63 /* End of vendor defined reserved range */ -}; - -/* Table 12/V.150.1 plus amendments - SSE RIC codes for MoIP */ -enum v150_1_sse_ric_code_e +/* Table 12/V.150.1 plus amendments - SSE RIC codes for MoIP and ToIP (as per 15.2.1/V.151) */ +enum v150_1_sse_moip_ric_code_e { /* Additional info: Available modulation modes as indicated in the CM sequence (Format is defined in Table 13) */ - V150_1_SSE_RIC_V8_CM = 1, + V150_1_SSE_MOIP_RIC_V8_CM = 1, /* Additional info: Available modulation modes as indicated in the JM sequence (Format is defined in Table 13) */ - V150_1_SSE_RIC_V8_JM = 2, + V150_1_SSE_MOIP_RIC_V8_JM = 2, /* Additional info: None */ - V150_1_SSE_RIC_V32BIS_AA = 3, + V150_1_SSE_MOIP_RIC_V32BIS_AA = 3, /* Additional info: None */ - V150_1_SSE_RIC_V32BIS_AC = 4, + V150_1_SSE_MOIP_RIC_V32BIS_AC = 4, /* Additional info: None */ - V150_1_SSE_RIC_V22BIS_USB1 = 5, + V150_1_SSE_MOIP_RIC_V22BIS_USB1 = 5, /* Additional info: None */ - V150_1_SSE_RIC_V22BIS_SB1 = 6, + V150_1_SSE_MOIP_RIC_V22BIS_SB1 = 6, /* Additional info: None */ - V150_1_SSE_RIC_V22BIS_S1 = 7, + V150_1_SSE_MOIP_RIC_V22BIS_S1 = 7, /* Additional info: None */ - V150_1_SSE_RIC_V21_CH2 = 8, + V150_1_SSE_MOIP_RIC_V21_CH2 = 8, /* Additional info: None */ - V150_1_SSE_RIC_V21_CH1 = 9, + V150_1_SSE_MOIP_RIC_V21_CH1 = 9, /* Additional info: None */ - V150_1_SSE_RIC_V23_HIGH_CHANNEL = 10, + V150_1_SSE_MOIP_RIC_V23_HIGH_CHANNEL = 10, /* Additional info: None */ - V150_1_SSE_RIC_V23_LOW_CHANNEL = 11, + V150_1_SSE_MOIP_RIC_V23_LOW_CHANNEL = 11, /* Additional info: None */ - V150_1_SSE_RIC_TONE_2225HZ = 12, + V150_1_SSE_MOIP_RIC_TONE_2225HZ = 12, /* Additional info: None */ - V150_1_SSE_RIC_V21_CH2_HDLC_FLAGS = 13, + V150_1_SSE_MOIP_RIC_V21_CH2_HDLC_FLAGS = 13, /* Additional info: None */ - V150_1_SSE_RIC_INDETERMINATE_SIGNAL = 14, + V150_1_SSE_MOIP_RIC_INDETERMINATE_SIGNAL = 14, /* Additional info: None */ - V150_1_SSE_RIC_SILENCE = 15, + V150_1_SSE_MOIP_RIC_SILENCE = 15, /* Additional info: None */ - V150_1_SSE_RIC_CNG = 16, + V150_1_SSE_MOIP_RIC_CNG = 16, /* Additional info: None */ - V150_1_SSE_RIC_VOICE = 17, + V150_1_SSE_MOIP_RIC_VOICE = 17, /* Additional info: The timeout event (Format is defined in Table 14) */ - V150_1_SSE_RIC_TIMEOUT = 18, + V150_1_SSE_MOIP_RIC_TIMEOUT = 18, /* Additional info: None */ - V150_1_SSE_RIC_P_STATE_TRANSITION = 19, + V150_1_SSE_MOIP_RIC_P_STATE_TRANSITION = 19, /* Additional info: Reason for clear down (Format is defined in Table 15) */ - V150_1_SSE_RIC_CLEARDOWN = 20, + V150_1_SSE_MOIP_RIC_CLEARDOWN = 20, /* Additional info: None */ - V150_1_SSE_RIC_ANS_CED = 21, + V150_1_SSE_MOIP_RIC_ANS_CED = 21, /* Additional info: None */ - V150_1_SSE_RIC_ANSAM = 22, + V150_1_SSE_MOIP_RIC_ANSAM = 22, /* Additional info: None */ - V150_1_SSE_RIC_ANS_PR = 23, + V150_1_SSE_MOIP_RIC_ANS_PR = 23, /* Additional info: None */ - V150_1_SSE_RIC_ANSAM_PR = 24, + V150_1_SSE_MOIP_RIC_ANSAM_PR = 24, /* Additional info: None */ - V150_1_SSE_RIC_V92_QC1A = 25, + V150_1_SSE_MOIP_RIC_V92_QC1A = 25, /* Additional info: None */ - V150_1_SSE_RIC_V92_QC1D = 26, + V150_1_SSE_MOIP_RIC_V92_QC1D = 26, /* Additional info: None */ - V150_1_SSE_RIC_V92_QC2A = 27, + V150_1_SSE_MOIP_RIC_V92_QC2A = 27, /* Additional info: None */ - V150_1_SSE_RIC_V92_QC2D = 28, + V150_1_SSE_MOIP_RIC_V92_QC2D = 28, /* Additional info: None */ - V150_1_SSE_RIC_V8BIS_CRE = 29, + V150_1_SSE_MOIP_RIC_V8BIS_CRE = 29, /* Additional info: None */ - V150_1_SSE_RIC_V8BIS_CRD = 30, + V150_1_SSE_MOIP_RIC_V8BIS_CRD = 30, /* Additional info: None */ - V150_1_SSE_RIC_TIA825A_45_45BPS = 31, + V150_1_SSE_MOIP_RIC_TIA825A_45_45BPS = 31, /* Additional info: None */ - V150_1_SSE_RIC_TIA825A_50BPS = 32, + V150_1_SSE_MOIP_RIC_TIA825A_50BPS = 32, /* Additional info: None */ - V150_1_SSE_RIC_EDT = 33, + V150_1_SSE_MOIP_RIC_EDT = 33, /* Additional info: None */ - V150_1_SSE_RIC_BELL103 = 34, + V150_1_SSE_MOIP_RIC_BELL103 = 34, /* Additional info: None */ - V150_1_SSE_RIC_V21_TEXT_TELEPHONE = 35, + V150_1_SSE_MOIP_RIC_V21_TEXT_TELEPHONE = 35, /* Additional info: None */ - V150_1_SSE_RIC_V23_MINITEL = 36, + V150_1_SSE_MOIP_RIC_V23_MINITEL = 36, /* Additional info: None */ - V150_1_SSE_RIC_V18_TEXT_TELEPHONE = 37, + V150_1_SSE_MOIP_RIC_V18_TEXT_TELEPHONE = 37, /* Additional info: None */ - V150_1_SSE_RIC_V18_DTMF_TEXT_RELAY = 38, + V150_1_SSE_MOIP_RIC_V18_DTMF_TEXT_RELAY = 38, /* Additional info: None */ - V150_1_SSE_RIC_CTM = 39, - V150_1_SSE_RIC_VENDOR_MIN = 128, - V150_1_SSE_RIC_VENDOR_MAX = 255 + V150_1_SSE_MOIP_RIC_CTM = 39, + V150_1_SSE_MOIP_RIC_VENDOR_MIN = 128, + V150_1_SSE_MOIP_RIC_VENDOR_MAX = 255 +}; + +/* Annex F/T.38 - SSE RIC codes for FoIP */ +enum v150_1_sse_foip_ric_code_e +{ + /* Additional info: Available modulation modes as indicated in the CM sequence (Format is defined in Table 13) */ + V150_1_SSE_FOIP_RIC_V21_FLAGS = 1, + /* Additional info: Available modulation modes as indicated in the JM sequence (Format is defined in Table 13) */ + V150_1_SSE_FOIP_RIC_V8_CM = 2, + /* Additional info: None */ + V150_1_SSE_FOIP_RIC_P_STATE_TRANSITION = 19 }; /* Table 13/V.150.1 - CM and JM additional information format in SSE payloads */ -enum v150_1_sse_ric_info_v8_cm_code_e +enum v150_1_sse_moip_ric_info_v8_cm_code_e { - V150_1_SSE_RIC_INFO_V8_CM_PCM_MODE = 0x8000, - V150_1_SSE_RIC_INFO_V8_CM_V34_DUPLEX = 0x4000, - V150_1_SSE_RIC_INFO_V8_CM_V34_HALF_DUPLEX = 0x2000, - V150_1_SSE_RIC_INFO_V8_CM_V32BIS = 0x1000, - V150_1_SSE_RIC_INFO_V8_CM_V22BIS = 0x0800, - V150_1_SSE_RIC_INFO_V8_CM_V17 = 0x0400, - V150_1_SSE_RIC_INFO_V8_CM_V29 = 0x0200, - V150_1_SSE_RIC_INFO_V8_CM_V27TER = 0x0100, - V150_1_SSE_RIC_INFO_V8_CM_V26TER = 0x0080, - V150_1_SSE_RIC_INFO_V8_CM_V26BIS = 0x0040, - V150_1_SSE_RIC_INFO_V8_CM_V23_DUPLEX = 0x0020, - V150_1_SSE_RIC_INFO_V8_CM_V23_HALF_DUPLEX = 0x0010, - V150_1_SSE_RIC_INFO_V8_CM_V21 = 0x0008, - V150_1_SSE_RIC_INFO_V8_CM_V90_V92_ANALOGUE = 0x0004, - V150_1_SSE_RIC_INFO_V8_CM_V90_V92_DIGITAL = 0x0002, - V150_1_SSE_RIC_INFO_V8_CM_V91 = 0x0001 + V150_1_SSE_MOIP_RIC_INFO_V8_CM_PCM_MODE = 0x8000, + V150_1_SSE_MOIP_RIC_INFO_V8_CM_V34_DUPLEX = 0x4000, + V150_1_SSE_MOIP_RIC_INFO_V8_CM_V34_HALF_DUPLEX = 0x2000, + V150_1_SSE_MOIP_RIC_INFO_V8_CM_V32BIS = 0x1000, + V150_1_SSE_MOIP_RIC_INFO_V8_CM_V22BIS = 0x0800, + V150_1_SSE_MOIP_RIC_INFO_V8_CM_V17 = 0x0400, + V150_1_SSE_MOIP_RIC_INFO_V8_CM_V29 = 0x0200, + V150_1_SSE_MOIP_RIC_INFO_V8_CM_V27TER = 0x0100, + V150_1_SSE_MOIP_RIC_INFO_V8_CM_V26TER = 0x0080, + V150_1_SSE_MOIP_RIC_INFO_V8_CM_V26BIS = 0x0040, + V150_1_SSE_MOIP_RIC_INFO_V8_CM_V23_DUPLEX = 0x0020, + V150_1_SSE_MOIP_RIC_INFO_V8_CM_V23_HALF_DUPLEX = 0x0010, + V150_1_SSE_MOIP_RIC_INFO_V8_CM_V21 = 0x0008, + V150_1_SSE_MOIP_RIC_INFO_V8_CM_V90_V92_ANALOGUE = 0x0004, + V150_1_SSE_MOIP_RIC_INFO_V8_CM_V90_V92_DIGITAL = 0x0002, + V150_1_SSE_MOIP_RIC_INFO_V8_CM_V91 = 0x0001 }; /* Table 14/V.150.1 - SSE timeout reason code definitions in SSE payload */ -enum v150_1_sse_ric_info_v8_timeout_reason_code_e +enum v150_1_sse_moip_ric_info_v8_timeout_reason_code_e { - V150_1_SSE_RIC_INFO_TIMEOUT_NULL = 0, - V150_1_SSE_RIC_INFO_TIMEOUT_CALL_DISCRIMINATION_TIMEOUT = 1, - V150_1_SSE_RIC_INFO_TIMEOUT_IP_TLP = 2, - V150_1_SSE_RIC_INFO_TIMEOUT_SSE_EXPLICIT_ACK_TIMEOUT = 3 + V150_1_SSE_MOIP_RIC_INFO_TIMEOUT_NULL = 0, + V150_1_SSE_MOIP_RIC_INFO_TIMEOUT_CALL_DISCRIMINATION_TIMEOUT = 1, + V150_1_SSE_MOIP_RIC_INFO_TIMEOUT_IP_TLP = 2, + V150_1_SSE_MOIP_RIC_INFO_TIMEOUT_SSE_EXPLICIT_ACK_TIMEOUT = 3 }; /* Table 28/V.150.1 - SSE cleardown reason code definitions in SSE payload */ -enum v150_1_sse_ric_info_v8_cleardown_reason_code_e +enum v150_1_sse_moip_ric_info_v8_cleardown_reason_code_e { - V150_1_SSE_RIC_INFO_CLEARDOWN_UNKNOWN = 0, - V150_1_SSE_RIC_INFO_CLEARDOWN_PHYSICAL_LAYER_RELEASE = 1, - V150_1_SSE_RIC_INFO_CLEARDOWN_LINK_LAYER_DISCONNECT = 2, - V150_1_SSE_RIC_INFO_CLEARDOWN_COMPRESSION_DISCONNECT = 3, - V150_1_SSE_RIC_INFO_CLEARDOWN_ABORT = 4, - V150_1_SSE_RIC_INFO_CLEARDOWN_ON_HOOK = 5, - V150_1_SSE_RIC_INFO_CLEARDOWN_NETWORK_LAYER_TERMINATION = 6, - V150_1_SSE_RIC_INFO_CLEARDOWN_ADMINISTRATIVE = 7 + V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_UNKNOWN = 0, + V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_PHYSICAL_LAYER_RELEASE = 1, + V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_LINK_LAYER_DISCONNECT = 2, + V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_COMPRESSION_DISCONNECT = 3, + V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_ABORT = 4, + V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_ON_HOOK = 5, + V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_NETWORK_LAYER_TERMINATION = 6, + V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_ADMINISTRATIVE = 7 }; /* V.150.1 C.4 */ @@ -243,46 +226,50 @@ extern "C" { SPAN_DECLARE(const char *) v150_1_sse_media_state_to_str(int state); -SPAN_DECLARE(const char *) v150_1_sse_ric_to_str(int ric); +SPAN_DECLARE(const char *) v150_1_sse_moip_ric_to_str(int ric); -SPAN_DECLARE(const char *) v150_1_sse_timeout_reason_to_str(int ric); +SPAN_DECLARE(const char *) v150_1_sse_timeout_reason_to_str(int reason); -SPAN_DECLARE(const char *) v150_1_sse_cleardown_reason_to_str(int ric); +SPAN_DECLARE(const char *) v150_1_sse_cleardown_reason_to_str(int reason); -SPAN_DECLARE(int) v150_1_sse_rx_packet(v150_1_sse_state_t *s, +SPAN_DECLARE(const char *) v150_1_sse_status_to_str(int status); + +/*! Receive an SSE packet, broken out of an RTP stream. + \brief Receive an SSE packet. + \param s V.150.1 SSE context. + \param seq_no + \param timestamp + \param pkt + \param len */ +SPAN_DECLARE(int) v150_1_rx_sse_packet(v150_1_state_t *s, uint16_t seq_no, uint32_t timestamp, const uint8_t pkt[], int len); -SPAN_DECLARE(int) v150_1_sse_tx_packet(v150_1_sse_state_t *s, int event, int ric, int ricinfo); - -SPAN_DECLARE(int) v150_1_sse_timer_expired(v150_1_sse_state_t *s, span_timestamp_t now); +/*! Transmit an SSE packet, for insertion into an RTP packet. This is normally needed by an + application. + \brief Transmit an SSE packet. + \param s V.150.1 SSE context. + \param event + \param ric + \param ricinfo */ +SPAN_DECLARE(int) v150_1_tx_sse_packet(v150_1_state_t *s, int event, int ric, int ricinfo); /*! Select one of the reliability schemes from V.150.1/C.4. \brief Select one of the reliability schemes from V.150.1/C.4. - \param s V.160.1 SSE context. + \param s V.150.1 SSE context. \param method The chosen method. \param parm1 maximum transmissions. \param parm2 delay between transmissions, or T0, in microseconds. \param parm3 T1, in microseconds. \return 0 for Ok, else negative. */ -SPAN_DECLARE(int) v150_1_sse_set_reliability_method(v150_1_sse_state_t *s, +SPAN_DECLARE(int) v150_1_set_sse_reliability_method(v150_1_state_t *s, enum v150_1_sse_reliability_option_e method, int parm1, int parm2, int parm3); -SPAN_DECLARE(logging_state_t *) v150_1_sse_get_logging_state(v150_1_sse_state_t *s); - -SPAN_DECLARE(v150_1_sse_state_t *) v150_1_sse_init(v150_1_sse_state_t *s, - v150_1_sse_packet_handler_t packet_handler, - void *packet_user_data, - v150_1_sse_status_handler_t status_handler, - void *status_user_data, - v150_1_sse_timer_handler_t timer_handler, - void *timer_user_data); - #if defined(__cplusplus) } #endif diff --git a/src/spandsp/v18.h b/src/spandsp/v18.h index 61770817..e40f1320 100644 --- a/src/spandsp/v18.h +++ b/src/spandsp/v18.h @@ -198,7 +198,7 @@ SPAN_DECLARE(int) v18_put(v18_state_t *s, const char msg[], int len); \param s The V.18 context. \param msg The string to be set. */ -SPAN_DECLARE(int) v18_set_stored_message(v18_state_t *s, uint8_t *msg); +SPAN_DECLARE(int) v18_set_stored_message(v18_state_t *s, const char *msg); /*! \brief Get the current mode of a V.18 connection. \param s The V.18 context. diff --git a/src/sprt.c b/src/sprt.c index 3599ae92..f7f44919 100644 --- a/src/sprt.c +++ b/src/sprt.c @@ -40,6 +40,7 @@ #endif #define SPANDSP_FULLY_DEFINE_SPRT_STATE_T + #include "spandsp/telephony.h" #include "spandsp/alloc.h" #include "spandsp/unaligned.h" @@ -419,7 +420,7 @@ static bool retransmit_the_unacknowledged(sprt_state_t *s, int channel, span_tim { /* TODO: take action on too many retries */ if (s->status_handler) - s->status_handler(s->status_user_data, /* TODO: */ 1235); + s->status_handler(s->status_user_data, SPRT_STATUS_EXCESS_RETRIES); /*endif*/ } else @@ -655,9 +656,9 @@ SPAN_DECLARE(int) sprt_rx_packet(sprt_state_t *s, const uint8_t pkt[], int len) { int i; int header_extension_bit; - int subsession_id; int reserved_bit; - int payload_type; + uint8_t subsession_id; + uint8_t payload_type; int channel; uint16_t base_sequence_no; uint16_t sequence_no; @@ -703,7 +704,7 @@ SPAN_DECLARE(int) sprt_rx_packet(sprt_state_t *s, const uint8_t pkt[], int len) return -1; } /*endif*/ - if (s->rx.subsession_id < 0) + if (s->rx.subsession_id == 0xFF) { /* This is the first subsession ID we have seen, so accept it going forwards as the subsession ID to be expected for future packets. The spec says the IDs start at zero, @@ -721,7 +722,7 @@ SPAN_DECLARE(int) sprt_rx_packet(sprt_state_t *s, const uint8_t pkt[], int len) a new subsession ID, rather than garbage? */ span_log(&s->logging, SPAN_LOG_FLOW, "Rx subsession ID %d, expected %d\n", subsession_id, s->rx.subsession_id); if (s->status_handler) - s->status_handler(s->status_user_data, /* TODO: */ 1234); + s->status_handler(s->status_user_data, SPRT_STATUS_SUBSESSION_CHANGED); /*endif*/ sprt_rx_reinit(s); return -1; @@ -768,16 +769,16 @@ SPAN_DECLARE(int) sprt_rx_packet(sprt_state_t *s, const uint8_t pkt[], int len) process_acknowledgements(s, noa, tcn, sqn); } /*endif*/ - span_log(&s->logging, SPAN_LOG_FLOW, "Rx ch %d seq %d len %d header len %d - noa %d\n", channel, sequence_no, len, header_len, noa); - - /* Deal with the payload, if any, in the packet */ payload_len = len - header_len; + span_log(&s->logging, SPAN_LOG_FLOW, "Rx ch %d seq %d noa %d len %d\n", channel, sequence_no, noa, payload_len); + /* Deal with the payload, if any, in the packet */ /* V.150.1 says SPRT_TCID_UNRELIABLE_UNSEQUENCED should be used for ACK only packets, but in the real world you should expect any of the transport channel IDs. These ACK only packets have the sequence number set to zero, regardless of where the sequence number for that channel currently stands. (figure B.3/V.150.1) */ if (payload_len > 0) { + /* There is a payload to process */ if (payload_len > chan->max_payload_bytes) { span_log(&s->logging, SPAN_LOG_ERROR, "Payload too long %d (%d)\n", payload_len, chan->max_payload_bytes); @@ -860,7 +861,7 @@ SPAN_DECLARE(int) sprt_rx_packet(sprt_state_t *s, const uint8_t pkt[], int len) its probably a repeat for a packet where the far end missed the previous ACK we sent. */ queue_acknowledgement(s, channel, sequence_no); if (s->status_handler) - s->status_handler(s->status_user_data, /* TODO: */ 1236); + s->status_handler(s->status_user_data, SPRT_STATUS_OUT_OF_SEQUENCE); /*endif*/ } else @@ -1202,9 +1203,9 @@ SPAN_DECLARE(logging_state_t *) sprt_get_logging_state(sprt_state_t *s) /*- End of function --------------------------------------------------------*/ SPAN_DECLARE(sprt_state_t *) sprt_init(sprt_state_t *s, - int subsession_id, - int rx_payload_type, - int tx_payload_type, + uint8_t subsession_id, + uint8_t rx_payload_type, + uint8_t tx_payload_type, channel_parms_t parms[SPRT_CHANNELS], sprt_tx_packet_handler_t tx_packet_handler, void *tx_user_data, @@ -1272,7 +1273,7 @@ SPAN_DECLARE(sprt_state_t *) sprt_init(sprt_state_t *s, s->rx.chan[SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED].buff = s->tc2_rx_buff; s->rx.chan[SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED].buff_len = s->tc2_rx_buff_len; - s->rx.subsession_id = -1; + s->rx.subsession_id = 0xFF; s->tx.subsession_id = subsession_id; s->rx.payload_type = rx_payload_type; s->tx.payload_type = tx_payload_type; diff --git a/src/ssl_fax.c b/src/ssl_fax.c index a5907015..e4ef0cde 100644 --- a/src/ssl_fax.c +++ b/src/ssl_fax.c @@ -180,9 +180,16 @@ static char *ssl_err_string(void) } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(void) sslfax_setup(sslfax_state_t *s, void *msg_user_data, put_msg_func_t put_msg, get_msg_func_t get_msg, hdlc_frame_handler_t hdlc_accept, hdlc_underflow_handler_t hdlc_tx_underflow, bool tx_use_hdlc, bool rx_use_hdlc, get_byte_func_t get_phase) +SPAN_DECLARE(void) sslfax_setup(sslfax_state_t *s, + span_put_msg_func_t put_msg, + span_get_msg_func_t get_msg, + hdlc_frame_handler_t hdlc_accept, + hdlc_underflow_handler_t hdlc_tx_underflow, + bool tx_use_hdlc, + bool rx_use_hdlc, + span_get_byte_func_t get_phase, + void *user_data) { - s->msg_user_data = msg_user_data; s->put_msg = put_msg; s->get_msg = get_msg; s->hdlc_accept = hdlc_accept; @@ -190,6 +197,7 @@ SPAN_DECLARE(void) sslfax_setup(sslfax_state_t *s, void *msg_user_data, put_msg_ s->tx_use_hdlc = tx_use_hdlc; s->rx_use_hdlc = rx_use_hdlc; s->get_phase = get_phase; + s->user_data = user_data; } /*- End of function --------------------------------------------------------*/ @@ -216,7 +224,7 @@ SPAN_DECLARE(int) sslfax_tx(sslfax_state_t *s, int16_t amp[], int len) { s->do_underflow = false; /* hdlc_tx_underflow may trigger another, so set it to false before. */ if (s->hdlc_tx_underflow) - s->hdlc_tx_underflow(s->msg_user_data); + s->hdlc_tx_underflow(s->user_data); } if (s->signal) { @@ -237,7 +245,7 @@ SPAN_DECLARE(int) sslfax_tx(sslfax_state_t *s, int16_t amp[], int len) { if (! s->tx_use_hdlc) { - while (s->get_msg && s->get_msg(s->msg_user_data, buf, 1) == 1) + while (s->get_msg && s->get_msg(s->user_data, buf, 1) == 1) { sent = true; sslfax_write(s, buf, 1, 0, 60000, true, false); @@ -279,7 +287,7 @@ SPAN_DECLARE(int) sslfax_rx(sslfax_state_t *s, const int16_t amp[], int len) int pos = 0; int r; - if (s->get_phase(s->msg_user_data) == 7) /* T30_PHASE_C_ECM_RX */ + if (s->get_phase(s->user_data) == 7) /* T30_PHASE_C_ECM_RX */ { /* We need to read the data stream, unstuff the zero bits, and break into frames on flags. */ skipbit = false; @@ -299,7 +307,7 @@ SPAN_DECLARE(int) sslfax_rx(sslfax_state_t *s, const int16_t amp[], int len) if (rbuf[0] == 0x03) { if (s->hdlc_accept) - s->hdlc_accept(s->msg_user_data, NULL, SIG_STATUS_CARRIER_DOWN, true); + s->hdlc_accept(s->user_data, NULL, SIG_STATUS_CARRIER_DOWN, true); /*endif*/ break; } @@ -341,7 +349,7 @@ SPAN_DECLARE(int) sslfax_rx(sslfax_state_t *s, const int16_t amp[], int len) j++; if (s->hdlc_accept && pos > 2) - s->hdlc_accept(s->msg_user_data, buf, pos-2, crc_itu16_check(buf, pos)); + s->hdlc_accept(s->user_data, buf, pos-2, crc_itu16_check(buf, pos)); /*endif*/ ones = 0; pos = 0; @@ -378,7 +386,7 @@ SPAN_DECLARE(int) sslfax_rx(sslfax_state_t *s, const int16_t amp[], int len) if (! s->rx_use_hdlc) { if (s->put_msg) - s->put_msg(s->msg_user_data, NULL, SIG_STATUS_CARRIER_DOWN); + s->put_msg(s->user_data, NULL, SIG_STATUS_CARRIER_DOWN); /*endif*/ return 0; } @@ -391,12 +399,12 @@ SPAN_DECLARE(int) sslfax_rx(sslfax_state_t *s, const int16_t amp[], int len) } /*endif*/ if (s->hdlc_accept && pos > 2) - s->hdlc_accept(s->msg_user_data, buf, pos-2, crc_itu16_check(buf, pos)); + s->hdlc_accept(s->user_data, buf, pos-2, crc_itu16_check(buf, pos)); /*endif*/ if ((pos > 0) && (buf[1] != 0x03)) /* 0x03 == CONTROL_FIELD_NON_FINAL_FRAME */ { if (s->hdlc_accept) - s->hdlc_accept(s->msg_user_data, NULL, SIG_STATUS_CARRIER_DOWN, true); + s->hdlc_accept(s->user_data, NULL, SIG_STATUS_CARRIER_DOWN, true); /*endif*/ return 0; } @@ -410,7 +418,7 @@ SPAN_DECLARE(int) sslfax_rx(sslfax_state_t *s, const int16_t amp[], int len) if (! s->rx_use_hdlc) { if (s->put_msg) - s->put_msg(s->msg_user_data, &buf[pos], 1); + s->put_msg(s->user_data, &buf[pos], 1); /*endif*/ pos--; } @@ -427,7 +435,7 @@ SPAN_DECLARE(int) sslfax_rx(sslfax_state_t *s, const int16_t amp[], int len) } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(int) sslfax_read(sslfax_state_t *s, void *buf, size_t count, int modemFd, long ms, bool sustain, bool carryon) +SPAN_DECLARE(int) sslfax_read(sslfax_state_t *s, void *buf, size_t count, int modem_fd, long ms, bool sustain, bool carryon) { /* * We cannot just use select() on the socket to see if there is data waiting @@ -450,7 +458,7 @@ SPAN_DECLARE(int) sslfax_read(sslfax_state_t *s, void *buf, size_t count, int mo * modem for activity, since that would indicate failure of the SSL Fax * communication. * - * The special modemFd value of "0" tells us to not monitor the modem. + * The special modem_fd value of "0" tells us to not monitor the modem. * This is necessary because we can't select() a modem file descriptor if * it's at an EOF (it will always be readable). The modem file descriptor * will be at an EOF if it is in command mode after an "OK" after a command @@ -480,7 +488,9 @@ SPAN_DECLARE(int) sslfax_read(sslfax_state_t *s, void *buf, size_t count, int mo int selret; fd_set rfds; FD_ZERO(&rfds); - if (modemFd) FD_SET(modemFd, &rfds); + if (modem_fd) + FD_SET(modem_fd, &rfds); + /*endif*/ struct timeval curTime; struct timeval tv; gettimeofday(&curTime, 0); @@ -492,7 +502,7 @@ SPAN_DECLARE(int) sslfax_read(sslfax_state_t *s, void *buf, size_t count, int mo { /* wait for the socket to be readable */ FD_SET(sslfd, &rfds); - selret = select((modemFd > sslfd) ? modemFd+1 : sslfd+1, &rfds, NULL, NULL, &tv); + selret = select((modem_fd > sslfd) ? modem_fd + 1 : sslfd + 1, &rfds, NULL, NULL, &tv); } else { @@ -500,7 +510,7 @@ SPAN_DECLARE(int) sslfax_read(sslfax_state_t *s, void *buf, size_t count, int mo fd_set wfds; FD_ZERO(&wfds); FD_SET(sslfd, &wfds); - selret = select((modemFd > sslfd) ? modemFd+1 : sslfd+1, &rfds, &wfds, NULL, &tv); + selret = select((modem_fd > sslfd) ? modem_fd + 1 : sslfd + 1, &rfds, &wfds, NULL, &tv); } /*endif*/ if (!selret) @@ -516,7 +526,7 @@ SPAN_DECLARE(int) sslfax_read(sslfax_state_t *s, void *buf, size_t count, int mo return (0); } /*endif*/ - if (modemFd && FD_ISSET(modemFd, &rfds)) + if (modem_fd && FD_ISSET(modem_fd, &rfds)) { /* The modem got a signal. This probably means that SSL Fax is not happening. */ if (!carryon) @@ -553,7 +563,7 @@ SPAN_DECLARE(int) sslfax_read(sslfax_state_t *s, void *buf, size_t count, int mo } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(int) sslfax_write(sslfax_state_t *s, const uint8_t *buf, unsigned int count, int modemFd, long ms, bool filter, bool sustain) +SPAN_DECLARE(int) sslfax_write(sslfax_state_t *s, const uint8_t *buf, unsigned int count, int modem_fd, long ms, bool filter, bool sustain) { /* * Similar approach here as with read() above; however... @@ -587,7 +597,9 @@ SPAN_DECLARE(int) sslfax_write(sslfax_state_t *s, const uint8_t *buf, unsigned i int selret; fd_set rfds; FD_ZERO(&rfds); - if (modemFd) FD_SET(modemFd, &rfds); + if (modem_fd) + FD_SET(modem_fd, &rfds); + /*endif*/ struct timeval curTime; struct timeval tv; @@ -600,7 +612,7 @@ SPAN_DECLARE(int) sslfax_write(sslfax_state_t *s, const uint8_t *buf, unsigned i { /* wait for the socket to be readable */ FD_SET(sslfd, &rfds); - selret = select((modemFd > sslfd) ? modemFd+1 : sslfd+1, &rfds, NULL, NULL, &tv); + selret = select((modem_fd > sslfd) ? modem_fd + 1 : sslfd + 1, &rfds, NULL, NULL, &tv); } else { @@ -608,7 +620,7 @@ SPAN_DECLARE(int) sslfax_write(sslfax_state_t *s, const uint8_t *buf, unsigned i fd_set wfds; FD_ZERO(&wfds); FD_SET(sslfd, &wfds); - selret = select((modemFd > sslfd) ? modemFd+1 : sslfd+1, &rfds, &wfds, NULL, &tv); + selret = select((modem_fd > sslfd) ? modem_fd + 1 : sslfd + 1, &rfds, &wfds, NULL, &tv); } /*endif*/ if (selret == 0) @@ -625,7 +637,7 @@ SPAN_DECLARE(int) sslfax_write(sslfax_state_t *s, const uint8_t *buf, unsigned i return (0); } /*endif*/ - if (modemFd && FD_ISSET(modemFd, &rfds)) + if (modem_fd && FD_ISSET(modem_fd, &rfds)) { /* The modem got a signal. This probably means that SSL Fax is not happening. */ span_log(&s->logging, SPAN_LOG_FLOW, "Modem has data when waiting for SSL Fax write. Terminating SSL Fax.\n"); @@ -837,7 +849,7 @@ SPAN_DECLARE(sslfax_state_t *) sslfax_init(sslfax_state_t *s) s->ecm_ones = 0; s->ecm_bitpos = 0; s->ecm_byte = 0; - s->msg_user_data = NULL; + s->user_data = NULL; s->get_msg = NULL; s->put_msg = NULL; s->hdlc_accept = NULL; @@ -873,18 +885,18 @@ SPAN_DECLARE(void) sslfax_cleanup(sslfax_state_t *s, bool sustain) } // int times = 3; -// while (times-- && s->hdlc_tx_underflow && s->msg_user_data && s->do_underflow) +// while (times-- && s->hdlc_tx_underflow && s->user_data && s->do_underflow) // { // s->do_underflow = false; /* hdlc_tx_underflow may trigger another, so set it to false before. */ // if (s->hdlc_tx_underflow) -// s->hdlc_tx_underflow(s->msg_user_data); +// s->hdlc_tx_underflow(s->user_data); // } s->rcp_count = 0; s->ecm_ones = 0; s->ecm_bitpos = 0; s->ecm_byte = 0; - s->msg_user_data = NULL; + s->user_data = NULL; s->get_msg = NULL; s->put_msg = NULL; s->hdlc_accept = NULL; diff --git a/src/super_tone_rx.c b/src/super_tone_rx.c index a5b61411..6f2053f3 100644 --- a/src/super_tone_rx.c +++ b/src/super_tone_rx.c @@ -57,13 +57,13 @@ #include "spandsp/private/super_tone_rx.h" #if defined(SPANDSP_USE_FIXED_POINT) -#define DETECTION_THRESHOLD 16439 /* -42dBm0 [((SUPER_TONE_BINS*SUPER_TONE_BINS*32768.0/(1.4142*128.0))*10^((-42 - DBM0_MAX_SINE_POWER)/20.0))^2] */ -#define TONE_TWIST 4 /* 6dB */ -#define TONE_TO_TOTAL_ENERGY 64 /* -3dB */ +static const int detection_threshold = energy_threshold_dbm0(SUPER_TONE_BINS, -42); +static const int tone_twist = 4; +static const int tone_to_total_energy = SUPER_TONE_BINS*64; #else -#define DETECTION_THRESHOLD 2104205.6f /* -42dBm0 [((SUPER_TONE_BINS*SUPER_TONE_BINS*32768.0/1.4142)*10^((-42 - DBM0_MAX_SINE_POWER)/20.0))^2] */ -#define TONE_TWIST 3.981f /* 6dB */ -#define TONE_TO_TOTAL_ENERGY 1.995f /* 3dB */ +static const float detection_threshold = energy_threshold_dbm0(SUPER_TONE_BINS, -42); +static const float tone_twist = db_to_power_ratio(6.0f); +static const float tone_to_total_energy = SUPER_TONE_BINS*db_to_power_ratio(-3.0f); #endif static int add_super_tone_freq(super_tone_rx_descriptor_t *desc, int freq) @@ -286,8 +286,9 @@ static void super_tone_chunk(super_tone_rx_state_t *s) float res[SUPER_TONE_BINS/2]; #endif - if (s->energy < DETECTION_THRESHOLD) + if (s->energy < detection_threshold) { + /* The total energy is too low to be considered a tone detection. */ k1 = -1; k2 = -1; for (i = 0; i < s->desc->monitored_frequencies; i++) @@ -327,18 +328,17 @@ static void super_tone_chunk(super_tone_rx_state_t *s) } else if (res[j] >= res[k2]) { - k1 = k2 = j; } /*endif*/ } /*endfor*/ - if ((res[k1] + res[k2]) < TONE_TO_TOTAL_ENERGY*s->energy) + if ((res[k1] + res[k2]) < tone_to_total_energy*s->energy) { k1 = -1; k2 = -1; } - else if (res[k1] > TONE_TWIST*res[k2]) + else if (res[k1] > tone_twist*res[k2]) { k2 = -1; } @@ -454,7 +454,7 @@ SPAN_DECLARE(int) super_tone_rx(super_tone_rx_state_t *s, const int16_t amp[], i for (sample = 0; sample < samples; sample += x) { for (i = 0; i < s->desc->monitored_frequencies; i++) - x = goertzel_update(&s->state[i], amp + sample, samples - sample); + x = goertzel_update(&s->state[i], &[sample], samples - sample); /*endfor*/ for (i = 0; i < x; i++) { @@ -470,11 +470,6 @@ SPAN_DECLARE(int) super_tone_rx(super_tone_rx_state_t *s, const int16_t amp[], i { /* We have finished a Goertzel block. */ super_tone_chunk(s); -#if defined(SPANDSP_USE_FIXED_POINT) - s->energy = 0; -#else - s->energy = 0.0f; -#endif } /*endif*/ } diff --git a/src/t30.c b/src/t30.c index 1089ff35..7c324314 100644 --- a/src/t30.c +++ b/src/t30.c @@ -100,12 +100,12 @@ #include "t30_local.h" /*! The maximum permitted number of retries of a single command allowed. */ -#define MAX_COMMAND_TRIES 6 +#define DEFAULT_MAX_COMMAND_TRIES 3 /*! The maximum permitted number of retries of a single response request allowed. This is not specified in T.30. However, if you don't apply some limit a messed up FAX terminal could keep you retrying all day. Its a backstop protection. */ -#define MAX_RESPONSE_TRIES 6 +#define DEFAULT_MAX_RESPONSE_TRIES 6 /* T.30 defines the following call phases: Phase A: Call set-up. @@ -527,7 +527,7 @@ static void t30_sslfax_real_time_frame_handler(void *user_data, bool incoming, c s = (t30_state_t *) user_data; if (s->sslfax.server) { - if (! incoming) + if (!incoming) { memcpy(buf, msg, len); len = crc_itu16_append(buf, len); @@ -1738,6 +1738,7 @@ static int build_dcs(t30_state_t *s) set_ctrl_bit(s->dcs_frame, T30_DCS_BIT_T38); /*endif*/ #endif + #if defined(SPANDSP_SUPPORT_SSLFAX) /* Check for SSL Fax. */ if (sslfax_enabled(s) && test_ctrl_bit(s->far_dis_dtc_frame, T30_DIS_BIT_T37) && test_ctrl_bit(s->far_dis_dtc_frame, T30_DIS_BIT_T38)) @@ -2649,17 +2650,8 @@ static int analyze_rx_dcs(t30_state_t *s, const uint8_t *msg, int len) static void send_dcn(t30_state_t *s) { - if (s->state == T30_STATE_R) - { - /* We need to wait until after TCF. */ - queue_phase(s, T30_PHASE_IDLE); - } - else - { - queue_phase(s, T30_PHASE_D_TX); - set_state(s, T30_STATE_C); - } - /*endif*/ + queue_phase(s, T30_PHASE_D_TX); + set_state(s, T30_STATE_C); send_simple_frame(s, T30_DCN); #if defined(SPANDSP_SUPPORT_SSLFAX) if (s->sslfax.server) @@ -4077,7 +4069,7 @@ static void process_state_d_post_tcf(t30_state_t *s, const uint8_t *msg, int len break; case T30_DIS: /* It appears they didn't see what we sent - retry the TCF */ - if (++s->retries >= MAX_COMMAND_TRIES) + if (++s->retries >= s->max_command_tries) { span_log(&s->logging, SPAN_LOG_FLOW, "Too many retries. Giving up.\n"); t30_set_status(s, T30_ERR_RETRYDCN); @@ -5999,7 +5991,7 @@ static void repeat_last_command(t30_state_t *s) /* If T0 or T1 are in progress we do not want to apply a limit to the maximum number of retries. We let T0 or T1 terminate things if the far end doesn't communicate. */ s->retries++; - if (s->timer_t0_t1 == 0 && s->retries >= MAX_COMMAND_TRIES) + if (s->timer_t0_t1 == 0 && s->retries >= s->max_command_tries) { span_log(&s->logging, SPAN_LOG_FLOW, "Too many retries. Giving up.\n"); switch (s->state) @@ -6024,7 +6016,7 @@ static void repeat_last_command(t30_state_t *s) return; } /*endif*/ - span_log(&s->logging, SPAN_LOG_FLOW, "Retry number %d\n", s->retries); + span_log(&s->logging, SPAN_LOG_FLOW, "Command reattempt number %d\n", s->retries); switch (s->state) { case T30_STATE_R: @@ -7630,6 +7622,8 @@ SPAN_DECLARE(t30_state_t *) t30_init(t30_state_t *s, get 1D and 2D encoding right. Quite a lot get other things wrong. */ s->supported_output_compressions = T4_COMPRESSION_T4_2D | T4_COMPRESSION_JPEG; s->local_min_scan_time_code = T30_MIN_SCAN_0MS; + s->max_command_tries = DEFAULT_MAX_COMMAND_TRIES; + s->max_response_tries = DEFAULT_MAX_RESPONSE_TRIES; span_log_init(&s->logging, SPAN_LOG_NONE, NULL); span_log_set_protocol(&s->logging, "T.30"); diff --git a/src/t30_api.c b/src/t30_api.c index 9a0d7f60..0fdb1a85 100644 --- a/src/t30_api.c +++ b/src/t30_api.c @@ -797,6 +797,18 @@ SPAN_DECLARE(void) t30_set_retransmit_capable(t30_state_t *s, bool enabled) } /*- End of function --------------------------------------------------------*/ +SPAN_DECLARE(void) t30_set_max_command_tries(t30_state_t *s, int tries) +{ + s->max_command_tries = tries; +} +/*- End of function --------------------------------------------------------*/ + +SPAN_DECLARE(void) t30_set_max_response_tries(t30_state_t *s, int tries) +{ + s->max_response_tries = tries; +} +/*- End of function --------------------------------------------------------*/ + SPAN_DECLARE(void) t30_set_keep_bad_quality_pages(t30_state_t *s, bool keep_bad_pages) { s->keep_bad_pages = keep_bad_pages; diff --git a/src/t4_t6_encode.c b/src/t4_t6_encode.c index e2525d0e..c87e04e2 100644 --- a/src/t4_t6_encode.c +++ b/src/t4_t6_encode.c @@ -81,6 +81,7 @@ #include #include "spandsp/telephony.h" +#include "spandsp/unaligned.h" #include "spandsp/alloc.h" #include "spandsp/logging.h" #include "spandsp/bit_operations.h" @@ -469,13 +470,9 @@ static int row_to_run_lengths(uint32_t list[], const uint8_t row[], int width) pos = 0; for (i = 0; i < limit; i += sizeof(uint32_t)) { - x = *((uint32_t *) &row[i]); + x = get_net_unaligned_uint32(&row[i]); if (x != flip) { - x = ((uint32_t) row[i] << 24) - | ((uint32_t) row[i + 1] << 16) - | ((uint32_t) row[i + 2] << 8) - | ((uint32_t) row[i + 3]); /* We know we are going to find at least one transition. */ frag = 31 - top_bit(x ^ flip); pos += ((i << 3) - span + frag); diff --git a/src/tone_detect.c b/src/tone_detect.c index d123891d..afddcd8b 100644 --- a/src/tone_detect.c +++ b/src/tone_detect.c @@ -132,6 +132,7 @@ SPAN_DECLARE(int) goertzel_update(goertzel_state_t *s, float v1; #endif + /* Adjust the length, so we don't run off the end of a processing block */ if (samples > s->samples - s->current_sample) samples = s->samples - s->current_sample; /*endif*/ @@ -180,7 +181,8 @@ SPAN_DECLARE(float) goertzel_result(goertzel_state_t *s) #endif /* Now calculate the non-recursive side of the filter. */ /* The result here is not scaled down to allow for the magnification - effect of the filter (the usual DFT magnification effect). */ + effect of the filter (the usual DFT magnification effect). So, + the result will be s->samples times the true energy. */ #if defined(SPANDSP_USE_FIXED_POINT) x = (int32_t) s->v3*s->v3; y = (int32_t) s->v2*s->v2; @@ -196,7 +198,7 @@ SPAN_DECLARE(float) goertzel_result(goertzel_state_t *s) return x; #else v1 = s->v3*s->v3 + s->v2*s->v2 - s->v2*s->v3*s->fac; - v1 *= 2.0; + v1 *= 2.0f; goertzel_reset(s); return v1; #endif diff --git a/src/v150_1.c b/src/v150_1.c index b84a571c..0c078884 100644 --- a/src/v150_1.c +++ b/src/v150_1.c @@ -1,12 +1,11 @@ /* * SpanDSP - a series of DSP components for telephony * - * v150_1.c - An implementation of the main part of V.150.1. SPRT is not included in - * this code. + * v150_1.c - An implementation of V.150.1. * * Written by Steve Underwood * - * Copyright (C) 2022 Steve Underwood + * Copyright (C) 2022, 2023 Steve Underwood * * All rights reserved. * @@ -39,6 +38,8 @@ #include #endif +#define SPANDSP_FULLY_DEFINE_SPRT_STATE_T + #include "spandsp/telephony.h" #include "spandsp/alloc.h" #include "spandsp/unaligned.h" @@ -46,10 +47,15 @@ #include "spandsp/async.h" #include "spandsp/sprt.h" #include "spandsp/v150_1.h" +#include "spandsp/v150_1_sse.h" #include "spandsp/private/logging.h" +#include "spandsp/private/sprt.h" +#include "spandsp/private/v150_1_sse.h" #include "spandsp/private/v150_1.h" +#include "v150_1_local.h" + /* Terminology V.150.1 has several components. The terms used for these are: @@ -297,21 +303,21 @@ Establishing Modem Relay with V.32 Modem | | | | | | |<-------------ANS--------------| | |<--------RFC4733 ANS----------| | - |<-----------ANS--------------| | | + |<------------ANS-------------| | | | | |<------------/ANS--------------| | |<--------RFC4733 /ANS---------| | |<-----------/ANS-------------| | | | | | | | | | | - |<<---- V.32 signals ------->>| | | + |<<----- V.32 signals ------>>| | | | |-------SSE MR(m,a) AA-------->| | | | |<<------ V.32 signals ------->>| | |<------SSE MR(m,m) p'---------| | - |<<---- V.32 signals ------->>| | | + |<<----- V.32 signals ------>>| | | | |-----------SPRT:INIT--------->|<<------ V.32 signals ------->>| | | | | | |<----------SPRT:INIT----------| | - |<<---- V.32 signals ------->>| |<<------ V.32 signals ------->>| + |<<----- V.32 signals ------>>| |<<------ V.32 signals ------->>| | |<--SPRT:MR_EVENT(PHYSUPv32)---| | | | | | | |---SPRT:MR_EVENT(PHYSUPv32)-->| | @@ -405,24 +411,24 @@ Establishing Modem Relay with ITU V.90 Modem M1 G1 G2 M2 | | | | - | | |<------------ANS---------------| + | | |<-------------ANS--------------| | |<--------RFC4733 ANS----------| | - |<-----------ANS--------------| | | + |<------------ANS-------------| | | | | |<------------/ANS--------------| | |<--------RFC4733 /ANS---------| | |<-----------/ANS-------------| | | | | | | - |------------CM-------------->| | | + |-------------CM------------->| | | | |--SSE MR(m,a) CM(v90 or v92)->| | - | ` | |-------------CM--------------->| + | ` | |--------------CM-------------->| | |<------SSE MR(m,m) p'---------| | | | | | | |-----------SPRT:INIT--------->| | | | | | | |<----------SPRT:INIT----------| | - | | |<------------JM----------------| + | | |<-------------JM---------------| | |<--SPRT:JM_INFO (v90 or v92)--| | - |<-----------JM---------------| | | + |<------------JM--------------| | | | | | | |<<----- V.90 signals ------>>| |<<------ V.90 signals ------->>| | |<--SPRT:MR_EVENT(PHYSUPv90)---| | @@ -444,24 +450,24 @@ Establishing Modem Relay with ITU V.92 Modem M1 G1 G2 M2 | | | | - | | |<-------------ANS--------------| + | | |<--------------ANS-------------| | |<--------RFC4733 ANS----------| | - |<-----------ANS--------------| | | + |<------------ANS-------------| | | | | |<-------------/ANS-------------| | |<--------RFC4733 /ANS---------| | |<-----------/ANS-------------| | | | | | | - |------------CM-------------->| | | + |-------------CM------------->| | | | |--SSE MR(m,a) CM(v90 or v92)->| | - | | |--------------CM-------------->| + | | |---------------CM------------->| | |<------SSE MR(m,m) p'---------| | | | | | | |-----------SPRT:INIT--------->| | | | | | | |<----------SPRT:INIT----------| | - | | |<-------------JM---------------| + | | |<--------------JM--------------| | |<--SPRT:JM_INFO (v90 or v92)--| | - |<-----------JM---------------| | | + |<------------JM--------------| | | | | | | |<<----- V.92 signals ------>>| |<<------- V.92 signals ------>>| | |<--SPRT:MR_EVENT(PHYSUPv92)---| | @@ -472,109 +478,63 @@ Establishing Modem Relay with ITU V.92 Modem | | | | | |-------SPRT:CONNECT(v90)----->| | | | | | - |<<------- V.92 data ------->>|<<-------- SPRT:data ------->>|<<------- V.92 data --------->>| + |<<------- V.92 data ------->>|<<-------- SPRT:data ------->>|<<-------- V.92 data -------->>| | | | | | | | | */ -#if 0 - -ASN.1 definition, from V.150.1 +/* + telephone network + ^ + | + | + v + +-----------------------------------+ + | | + | Signal processing entity (SPE) | + | | + +-----------------------------------+ + | ^ + | | + Signal list 1 | | Signal list 2 + | | + v | + +-----------------------------------+ Signal list 5 +-----------------------------------+ + | | ----------------->| | + | SSE protocol state machine (P) | | Gateway state machine (s,s') | + | |<------------------| | + +-----------------------------------+ Signal list 6 +-----------------------------------+ + | ^ + | | + Signal list 3 | | Signal list 4 + | | + v | + +-----------------------------------+ + | | + | IP network processor | + | | + +-----------------------------------+ + ^ + | + | + v + IP network +*/ -V150MOIP-CAPABILITY DEFINITIONS AUTOMATIC TAGS ::= BEGIN -IMPORTS - NonStandardParameter FROM MULTIMEDIA-SYSTEM-CONTROL; -V150MoIPCapability ::= SEQUENCE -{ - nonStandard SEQUENCE OF NonStandardParameter OPTIONAL, - modemRelayType CHOICE - { - v-mr NULL, - u-mr NULL, - ... - }, - gatewayType CHOICE - { - ntcx NULL, -- No Transcompression - stcx NULL, -- Single Transcompression - dtcx CHOICE -- Double Transcompression - { - single NULL, -- Preferred mode between two gateways - double NULL, -- with double transcompression ability - ... - }, - ... - }, - callDiscriminationMode CHOICE - { - audio NULL, - g2-choice NULL, - combination NULL, - ... - }, - sprtParameters SEQUENCE - { - maxPayloadSizeChannel0 INTEGER(140..256) OPTIONAL, -- Default 140 - maxPayloadSizeChannel1 INTEGER(132..256) OPTIONAL, -- Default 132 - maxWindowSizeChannel1 INTEGER(32..96) OPTIONAL, -- Default 32 - maxPayloadSizeChannel2 INTEGER(132..256) OPTIONAL, -- Default 132 - maxWindowSizeChannel2 INTEGER(8..32) OPTIONAL, -- Default 8 - maxPayloadSizeChannel3 INTEGER(140..256) OPTIONAL, -- Default 140 - ... - } OPTIONAL, - modulationSupport SEQUENCE - { - v34FullDuplex NULL OPTIONAL, - v34HalfDuplex NULL OPTIONAL, - v32bis-v32 NULL OPTIONAL, - v22bis-v22 NULL OPTIONAL, - v17 NULL OPTIONAL, - v29HalfDuplex NULL OPTIONAL, - v27ter NULL OPTIONAL, - v26ter NULL OPTIONAL, - v26bis NULL OPTIONAL, - v23FullDuplex NULL OPTIONAL, - v23HalfDuplex NULL OPTIONAL, - v21 NULL OPTIONAL, - v90Analog NULL OPTIONAL, - v90Digital NULL OPTIONAL, - v92Analog NULL OPTIONAL, - v92Digital NULL OPTIONAL, - v91 NULL OPTIONAL, - ... - }, - compressionMode SEQUENCE - { - -- Including a SEQUENCE for a particular compression mode, but not - -- including any of the optional parameters within the SEQUENCE, - -- indicates support for the specific compression mode, but assumes that - -- all parameter values are set to their default values - mnp5 NULL OPTIONAL, - v44 SEQUENCE - { - numTxCodewords INTEGER(256..65535), - numRxCodewords INTEGER(256..65535), - maxTxStringLength INTEGER(32..255), - maxRxStringLength INTEGER(32..255), - lenTxHistory INTEGER(512..65535), - lenRxHistory INTEGER(512..65535), - ... - } OPTIONAL, - v42bis SEQUENCE - { - numCodewords INTEGER(512..65535) OPTIONAL, - maxStringLength INTEGER(6..250) OPTIONAL, - ... - } OPTIONAL, - ... - } OPTIONAL, - delayedJMEnabled BOOLEAN, - ... -} -#endif +/* + Table 31/V.150.1 - MoIP initial modes. + + <<<<<<<< Additional modes supported >>>>>>>> Starting mode + FoIP (T.38) and/or ToIP (V.151) VoIP + ----------------------------------------------------------------------------- + No No MoIP + No Yes VoIP + Yes No MoIP + Yes Yes VoIP + */ -/* Used to verify the message type is compatible with the transmission - control channel it arrived on */ +/* Used to verify if a message type is compatible with the transmission + control channel it arrives on */ static uint8_t channel_check[25] = { 0x0F, /* V150_1_MSGID_NULL */ @@ -628,6 +588,8 @@ static struct } }; +static span_timestamp_t update_call_discrimination_timer(v150_1_state_t *s, span_timestamp_t timeout); + SPAN_DECLARE(const char *) v150_1_msg_id_to_str(int msg_id) { const char *res; @@ -1103,8 +1065,11 @@ SPAN_DECLARE(const char *) v150_1_status_reason_to_str(int status) case V150_1_STATUS_REASON_NULL: res = "NULL"; break; - case V150_1_STATUS_REASON_STATE_CHANGED: - res = "state changed"; + case V150_1_STATUS_REASON_MEDIA_STATE_CHANGED: + res = "media state changed"; + break; + case V150_1_STATUS_REASON_CONNECTION_STATE_CHANGED: + res = "connection state changed"; break; case V150_1_STATUS_REASON_DATA_FORMAT_CHANGED: res = "format changed"; @@ -1121,10 +1086,10 @@ SPAN_DECLARE(const char *) v150_1_status_reason_to_str(int status) case V150_1_STATUS_REASON_BUSY_CHANGED: res = "busy changed"; break; - case V150_1_STATUS_REASON_PHYSUP: + case V150_1_STATUS_REASON_CONNECTION_STATE_PHYSUP: res = "physically up"; break; - case V150_1_STATUS_REASON_CONNECTED: + case V150_1_STATUS_REASON_CONNECTION_STATE_CONNECTED: res = "connected"; break; } @@ -1213,35 +1178,232 @@ SPAN_DECLARE(const char *) v150_1_jm_info_modulation_to_str(int modulation) } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(int) v150_1_set_bits_per_character(v150_1_state_t *s, int bits) +SPAN_DECLARE(const char *) v150_1_signal_to_str(int modulation) { - if (bits < 5 || bits > 8) - return -1; - /*endif*/ - bits -= 5; - s->near.parms.data_format_code &= 0x9F; - s->near.parms.data_format_code |= ((bits << 5) & 0x60); - return 0; -} -/*- End of function --------------------------------------------------------*/ + const char *res; -SPAN_DECLARE(int) v150_1_set_parity(v150_1_state_t *s, int mode) -{ - s->near.parms.data_format_code &= 0xE3; - s->near.parms.data_format_code |= ((mode << 2) & 0x1C); - return 0; + res = "unknown"; + switch (modulation) + { + case V150_1_SIGNAL_TONE_2100HZ: + res = "2100Hz detected"; + break; + case V150_1_SIGNAL_TONE_2225HZ: + res = "2225Hz detected"; + break; + case V150_1_SIGNAL_ANS: + res = "V.25 ANS detected"; + break; + case V150_1_SIGNAL_ANS_PR: + res = "V.25 ANS reversal detected"; + break; + case V150_1_SIGNAL_ANSAM: + res = "V.8 ANSam detected"; + break; + case V150_1_SIGNAL_ANSAM_PR: + res = "V.8 ANSam reversal detected"; + break; + case V150_1_SIGNAL_CI: + res = "V.8 CI detected"; + break; + case V150_1_SIGNAL_CM: + res = "V.8 CM detected"; + break; + case V150_1_SIGNAL_JM: + res = "V.8 JM detected"; + break; + case V150_1_SIGNAL_V21_LOW: + res = "V.21 low channel detected"; + break; + case V150_1_SIGNAL_V21_HIGH: + res = "V.21 high channel detected"; + break; + case V150_1_SIGNAL_V23_LOW: + res = "V.23 low channel detected"; + break; + case V150_1_SIGNAL_V23_HIGH: + res = "V.23 high channel detected"; + break; + case V150_1_SIGNAL_SB1: + res = "V.22bis scrambled ones detected"; + break; + case V150_1_SIGNAL_USB1: + res = "V.22bis unscrambled ones detected"; + break; + case V150_1_SIGNAL_S1: + res = "V.22bis S1 detected"; + break; + case V150_1_SIGNAL_AA: + res = "V.32/V.32bis AA detected"; + break; + case V150_1_SIGNAL_AC: + res = "V.32/V.32bis AC detected"; + break; + case V150_1_SIGNAL_CALL_DISCRIMINATION_TIMEOUT: + res = "Call discrimination time-out"; + break; + case V150_1_SIGNAL_UNKNOWN: + res = "unrecognised signal detected"; + break; + case V150_1_SIGNAL_SILENCE: + res = "silence detected"; + break; + case V150_1_SIGNAL_ABORT: + res = "SPE has initiated an abort request"; + break; + + case V150_1_SIGNAL_ANS_GEN: + res = "Generate V.25 ANS"; + break; + case V150_1_SIGNAL_ANS_PR_GEN: + res = "Generate V.25 ANS reversal"; + break; + case V150_1_SIGNAL_ANSAM_GEN: + res = "Generate V.8 ANSam"; + break; + case V150_1_SIGNAL_ANSAM_PR_GEN: + res = "Generate V.8 ANSam reversal"; + break; + case V150_1_SIGNAL_2225HZ_GEN: + res = "Generate 2225Hz"; + break; + case V150_1_SIGNAL_CONCEAL_MODEM: + res = "Block modem signal"; + break; + case V150_1_SIGNAL_BLOCK_2100HZ_TONE: + res = "Block 2100Hz"; + break; + case V150_1_SIGNAL_AUTOMODE_ENABLE: + res = "Enable automode"; + break; + + case V150_1_SIGNAL_AUDIO_GEN: + res = "Send audio state"; + break; + case V150_1_SIGNAL_FAX_RELAY_GEN: + res = "Send fax relay state"; + break; + case V150_1_SIGNAL_INDETERMINATE_GEN: + res = "Send indeterminate state"; + break; + case V150_1_SIGNAL_MODEM_RELAY_GEN: + res = "Send modem relay state"; + break; + case V150_1_SIGNAL_TEXT_RELAY_GEN: + res = "Send text relay state"; + break; + case V150_1_SIGNAL_VBD_GEN: + res = "Send VBD state"; + break; + case V150_1_SIGNAL_RFC4733_ANS_GEN: + res = "Send RFC4733 ANS"; + break; + case V150_1_SIGNAL_RFC4733_ANS_PR_GEN: + res = "Send RFC4733 ANS reversal"; + break; + case V150_1_SIGNAL_RFC4733_ANSAM_GEN: + res = "Send RFC4733 ANSam"; + break; + case V150_1_SIGNAL_RFC4733_ANSAM_PR_GEN: + res = "Send RFC4733 ANSam reversal"; + break; + case V150_1_SIGNAL_RFC4733_TONE_GEN: + res = "Send RFC4733 tone"; + break; + + case V150_1_SIGNAL_AUDIO: + res = "Audio state detected"; + break; + case V150_1_SIGNAL_FAX_RELAY: + res = "Facsimile relay state detected"; + break; + case V150_1_SIGNAL_INDETERMINATE: + res = "Indeterminate state detected"; + break; + case V150_1_SIGNAL_MODEM_RELAY: + res = "Modem relay state detected"; + break; + case V150_1_SIGNAL_TEXT_RELAY: + res = "Text relay state detected"; + break; + case V150_1_SIGNAL_VBD: + res = "VBD state detected"; + break; + case V150_1_SIGNAL_RFC4733_ANS: + res = "RFC4733 ANS event detected"; + break; + case V150_1_SIGNAL_RFC4733_ANS_PR: + res = "RFC4733 ANS reversal detected"; + break; + case V150_1_SIGNAL_RFC4733_ANSAM: + res = "RFC4733 ANSam detected"; + break; + case V150_1_SIGNAL_RFC4733_ANSAM_PR: + res = "RFC4733 ANSam reversal detected"; + break; + case V150_1_SIGNAL_RFC4733_TONE: + res = "RFC4733 tone detected"; + break; + + case V150_1_SIGNAL_AUDIO_STATE: + res = "Audio"; + break; + case V150_1_SIGNAL_FAX_RELAY_STATE: + res = "Fax relay"; + break; + case V150_1_SIGNAL_INDETERMINATE_STATE: + res = "Indeterminate"; + break; + case V150_1_SIGNAL_MODEM_RELAY_STATE: + res = "Modem relay"; + break; + case V150_1_SIGNAL_TEXT_RELAY_STATE: + res = "Text relay"; + break; + case V150_1_SIGNAL_VBD_STATE: + res = "VBD"; + break; + + case V150_1_SIGNAL_CALL_DISCRIMINATION_TIMER_EXPIRED: + res = "Call discrimination timer exposed"; + break; + } + /*endswitch*/ + return res; } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(int) v150_1_set_stop_bits(v150_1_state_t *s, int bits) +SPAN_DECLARE(const char *) v150_1_media_state_to_str(int state) { - if (bits < 1 || bits > 2) - return -1; - /*endif*/ - bits -= 1; - s->near.parms.data_format_code &= 0xFC; - s->near.parms.data_format_code |= (bits & 0x03); - return 0; + const char *res; + + res = "unknown"; + switch (state) + { + case V150_1_MEDIA_STATE_INITIAL_AUDIO: + res = "Initial Audio"; + break; + case V150_1_MEDIA_STATE_VOICE_BAND_DATA: + res = "Voice Band Data (VBD)"; + break; + case V150_1_MEDIA_STATE_MODEM_RELAY: + res = "Modem Relay"; + break; + case V150_1_MEDIA_STATE_FAX_RELAY: + res = "Fax Relay"; + break; + case V150_1_MEDIA_STATE_TEXT_RELAY: + res = "Text Relay"; + break; + case V150_1_MEDIA_STATE_TEXT_PROBE: + res = "Text Probe"; + break; + case V150_1_MEDIA_STATE_INDETERMINATE: + res = "Indeterminate"; + break; + } + /*endswitch*/ + return res; } /*- End of function --------------------------------------------------------*/ @@ -1252,29 +1414,15 @@ static int status_report(v150_1_state_t *s, int reason) report.reason = reason; switch (reason) { - case V150_1_STATUS_REASON_STATE_CHANGED: - report.state_change.state = s->far.parms.connection_state; - report.state_change.cleardown_reason = s->far.parms.cleardown_reason; + case V150_1_STATUS_REASON_MEDIA_STATE_CHANGED: + report.media_state_change.local_state = s->local_media_state; + report.media_state_change.remote_state = s->remote_media_state; break; - case V150_1_STATUS_REASON_DATA_FORMAT_CHANGED: - report.data_format_change.bits = 5 + ((s->far.parms.data_format_code >> 5) & 0x03); - report.data_format_change.parity_code = (s->far.parms.data_format_code >> 2) & 0x07; - report.data_format_change.stop_bits = 1 + (s->far.parms.data_format_code & 0x03); - break; - case V150_1_STATUS_REASON_BREAK_RECEIVED: - report.break_received.source = s->far.break_source; - report.break_received.type = s->far.break_type; - report.break_received.duration = s->far.break_duration*10; - break; - case V150_1_STATUS_REASON_RATE_RETRAIN_RECEIVED: - break; - case V150_1_STATUS_REASON_RATE_RENEGOTIATION_RECEIVED: - break; - case V150_1_STATUS_REASON_BUSY_CHANGED: - report.busy_change.local_busy = s->near.parms.busy; - report.busy_change.far_busy = s->far.parms.busy; + case V150_1_STATUS_REASON_CONNECTION_STATE_CHANGED: + report.connection_state_change.state = s->far.parms.connection_state; + report.connection_state_change.cleardown_reason = s->far.parms.cleardown_reason; break; - case V150_1_STATUS_REASON_PHYSUP: + case V150_1_STATUS_REASON_CONNECTION_STATE_PHYSUP: report.physup_parameters.selmod = s->far.parms.selmod; report.physup_parameters.tdsr = s->far.parms.tdsr; report.physup_parameters.rdsr = s->far.parms.rdsr; @@ -1284,7 +1432,7 @@ static int status_report(v150_1_state_t *s, int reason) report.physup_parameters.rxsen = s->far.parms.rxsen; report.physup_parameters.rxsr = s->far.parms.rxsr; break; - case V150_1_STATUS_REASON_CONNECTED: + case V150_1_STATUS_REASON_CONNECTION_STATE_CONNECTED: report.connect_parameters.selmod = s->far.parms.selmod; report.connect_parameters.tdsr = s->far.parms.tdsr; report.connect_parameters.rdsr = s->far.parms.rdsr; @@ -1315,12 +1463,733 @@ static int status_report(v150_1_state_t *s, int reason) report.connect_parameters.i_char_stat_cs_available = s->far.parms.i_char_stat_cs_available; report.connect_parameters.i_char_dyn_cs_available = s->far.parms.i_char_dyn_cs_available; break; + case V150_1_STATUS_REASON_DATA_FORMAT_CHANGED: + report.data_format_change.bits = 5 + ((s->far.parms.data_format_code >> 5) & 0x03); + report.data_format_change.parity_code = (s->far.parms.data_format_code >> 2) & 0x07; + report.data_format_change.stop_bits = 1 + (s->far.parms.data_format_code & 0x03); + break; + case V150_1_STATUS_REASON_BREAK_RECEIVED: + report.break_received.source = s->far.break_source; + report.break_received.type = s->far.break_type; + report.break_received.duration = s->far.break_duration*10; + break; + case V150_1_STATUS_REASON_RATE_RETRAIN_RECEIVED: + break; + case V150_1_STATUS_REASON_RATE_RENEGOTIATION_RECEIVED: + break; + case V150_1_STATUS_REASON_BUSY_CHANGED: + report.busy_change.local_busy = s->near.parms.busy; + report.busy_change.far_busy = s->far.parms.busy; + break; + } + /*endswitch*/ + if (s->rx_status_report_handler) + s->rx_status_report_handler(s->rx_status_report_user_data, &report); + /*endif*/ + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int send_spe_signal(v150_1_state_t *s, int signal) +{ + span_log(&s->logging, SPAN_LOG_FLOW, "Signal to SPE %s\n", v150_1_signal_to_str(signal)); + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int send_ip_signal(v150_1_state_t *s, int signal) +{ + span_log(&s->logging, SPAN_LOG_FLOW, "Signal to IP %s\n", v150_1_signal_to_str(signal)); + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int stop_timer(v150_1_state_t *s) +{ + span_log(&s->logging, SPAN_LOG_FLOW, "Stop timer\n"); + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int generic_macro(v150_1_state_t *s, int signal, int ric) +{ + span_timestamp_t now; + + /* Figure 25/V.150.1 */ + span_log(&s->logging, + SPAN_LOG_FLOW, + "IP signal %s(%s, %s)\n", + v150_1_media_state_to_str(s->local_media_state), + v150_1_signal_to_str(signal), + v150_1_sse_moip_ric_to_str(ric)); + if (s->local_media_state == s->remote_media_state) + { + /* Stop the call discrimination timer */ + s->call_discrimination_timer = 0; + update_call_discrimination_timer(s, s->call_discrimination_timer); + } + else + { + /* Start the call discrimination timer */ + if (s->call_discrimination_timer == 0) + { + now = update_call_discrimination_timer(s, ~0); + s->call_discrimination_timer = now + s->call_discrimination_timeout; + update_call_discrimination_timer(s, s->call_discrimination_timer); + } + /*endif*/ + } + /*endif*/ + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static void update_media_states(v150_1_state_t *s, int local, int remote) +{ + if (local != s->local_media_state || remote != s->remote_media_state) + { + s->remote_media_state = remote; + s->local_media_state = local; + status_report(s, V150_1_STATUS_REASON_MEDIA_STATE_CHANGED); + } + /*endif*/ +} +/*- End of function --------------------------------------------------------*/ + +static int v150_1_figures_26_to_31(v150_1_state_t *s, int signal, const uint8_t *msg, int len) +{ + /* Figure 26/V.150.1 to 31/V.150.1 */ + switch (signal) + { + case V150_1_SIGNAL_TONE_2100HZ: + if (s->cdscselect == V150_1_CDSCSELECT_VBD_SELECT + || + s->cdscselect == V150_1_CDSCSELECT_MIXED) + { + update_media_states(s, V150_1_MEDIA_STATE_VOICE_BAND_DATA, s->remote_media_state); + //send ANS or ANSam + generic_macro(s, V150_1_SIGNAL_ANS, 0); + } + else + { + send_spe_signal(s, V150_1_SIGNAL_BLOCK_2100HZ_TONE); + } + /*endif*/ + break; + case V150_1_SIGNAL_ANS: + if (s->cdscselect == V150_1_CDSCSELECT_VBD_SELECT + || + s->cdscselect == V150_1_CDSCSELECT_MIXED) + { + update_media_states(s, V150_1_MEDIA_STATE_VOICE_BAND_DATA, s->remote_media_state); + generic_macro(s, V150_1_SIGNAL_ANS, 0); + } + else + { + generic_macro(s, V150_1_SIGNAL_RFC4733_ANS_GEN, 0); + send_spe_signal(s, V150_1_SIGNAL_CONCEAL_MODEM); + } + /*endif*/ + break; + case V150_1_SIGNAL_ANSAM: + if (s->cdscselect == V150_1_CDSCSELECT_VBD_SELECT + || + s->cdscselect == V150_1_CDSCSELECT_MIXED) + { + update_media_states(s, V150_1_MEDIA_STATE_VOICE_BAND_DATA, s->remote_media_state); + generic_macro(s, V150_1_SIGNAL_ANSAM, 0); + } + else + { + generic_macro(s, V150_1_SIGNAL_RFC4733_ANSAM_GEN, 0); + send_spe_signal(s, V150_1_SIGNAL_CONCEAL_MODEM); + } + /*endif*/ + break; + case V150_1_SIGNAL_RFC4733_ANS: + send_spe_signal(s, V150_1_SIGNAL_ANS_GEN); + send_spe_signal(s, V150_1_SIGNAL_CONCEAL_MODEM); + break; + case V150_1_SIGNAL_RFC4733_ANSAM: + send_spe_signal(s, V150_1_SIGNAL_ANSAM_GEN); + send_spe_signal(s, V150_1_SIGNAL_CONCEAL_MODEM); + break; + case V150_1_SIGNAL_RFC4733_ANS_PR: + send_spe_signal(s, V150_1_SIGNAL_ANS_PR_GEN); + send_spe_signal(s, V150_1_SIGNAL_CONCEAL_MODEM); + break; + case V150_1_SIGNAL_RFC4733_ANSAM_PR: + send_spe_signal(s, V150_1_SIGNAL_ANSAM_PR_GEN); + send_spe_signal(s, V150_1_SIGNAL_CONCEAL_MODEM); + break; + case V150_1_SIGNAL_ANS_PR: + break; + case V150_1_SIGNAL_ANSAM_PR: + break; + case V150_1_SIGNAL_UNKNOWN: + case V150_1_SIGNAL_CALL_DISCRIMINATION_TIMEOUT: + if (s->cdscselect == V150_1_CDSCSELECT_VBD_SELECT + || + s->cdscselect == V150_1_CDSCSELECT_MIXED) + { + update_media_states(s, V150_1_MEDIA_STATE_VOICE_BAND_DATA, s->remote_media_state); + generic_macro(s, signal, 0); + } + /*endif*/ + break; + case V150_1_SIGNAL_VBD: + if (s->cdscselect == V150_1_CDSCSELECT_VBD_SELECT + || + s->cdscselect == V150_1_CDSCSELECT_MIXED) + { + update_media_states(s, V150_1_MEDIA_STATE_VOICE_BAND_DATA, V150_1_MEDIA_STATE_VOICE_BAND_DATA); + generic_macro(s, signal, 0); + } + else + { + update_media_states(s, V150_1_MEDIA_STATE_VOICE_BAND_DATA, s->remote_media_state); + generic_macro(s, signal, 0); + } + /*endif*/ + break; + case V150_1_SIGNAL_MODEM_RELAY: + span_log(&s->logging, SPAN_LOG_FLOW, "Modem relay signal %s\n", v150_1_signal_to_str(signal)); + break; + case V150_1_SIGNAL_CM: + span_log(&s->logging, SPAN_LOG_FLOW, "SPE signal %s\n", v150_1_signal_to_str(signal)); + if (s->cdscselect == V150_1_CDSCSELECT_VBD_SELECT + || + s->cdscselect == V150_1_CDSCSELECT_MIXED) + { + update_media_states(s, V150_1_MEDIA_STATE_VOICE_BAND_DATA, V150_1_MEDIA_STATE_MODEM_RELAY); + generic_macro(s, V150_1_SIGNAL_MODEM_RELAY_GEN, V150_1_SSE_MOIP_RIC_V8_CM); + } + else + { + update_media_states(s, V150_1_MEDIA_STATE_MODEM_RELAY, V150_1_MEDIA_STATE_MODEM_RELAY); + generic_macro(s, V150_1_SIGNAL_MODEM_RELAY_GEN, V150_1_SSE_MOIP_RIC_V8_CM); + } + /*endif*/ + break; + /*supported modulations */ + default: + span_log(&s->logging, SPAN_LOG_FLOW, "Unexpected signal %s\n", v150_1_signal_to_str(signal)); + break; + } + /*endswitch*/ + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int v150_1_figure_32(v150_1_state_t *s, int signal, const uint8_t *msg, int len) +{ + /* Figure 32/V.150.1 */ + switch (signal) + { + case V150_1_SIGNAL_AUDIO: + //send SSE p' + generic_macro(s, signal, 0); + break; + default: + span_log(&s->logging, SPAN_LOG_FLOW, "Unexpected signal %s\n", v150_1_signal_to_str(signal)); + break; + } + /*endswitch*/ + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int v150_1_figure_33(v150_1_state_t *s, int signal, const uint8_t *msg, int len) +{ + /* Figure 33/V.150.1 */ + switch (signal) + { + case V150_1_SIGNAL_AUDIO: + //send SSE p' + generic_macro(s, signal, 0); + break; + default: + span_log(&s->logging, SPAN_LOG_FLOW, "Unexpected signal %s\n", v150_1_signal_to_str(signal)); + break; + } + /*endswitch*/ + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int v150_1_figure_34(v150_1_state_t *s, int signal, const uint8_t *msg, int len) +{ + /* Figure 34/V.150.1 */ + switch (signal) + { + case V150_1_SIGNAL_AUDIO: + //send SSE p' + generic_macro(s, signal, 0); + break; + case V150_1_SIGNAL_MODEM_RELAY: + stop_timer(s); + break; + case V150_1_SIGNAL_VBD: + //send SSE RC + generic_macro(s, signal, 0); + break; + default: + span_log(&s->logging, SPAN_LOG_FLOW, "Unexpected signal %s\n", v150_1_signal_to_str(signal)); + break; + } + /*endswitch*/ + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int v150_1_figure_35(v150_1_state_t *s, int signal, const uint8_t *msg, int len) +{ + /* Figure 35/V.150.1 */ + switch (signal) + { + case V150_1_SIGNAL_JM: + if (s->cdscselect == V150_1_CDSCSELECT_VBD_SELECT + || + s->cdscselect == V150_1_CDSCSELECT_MIXED) + { + } + else + { + } + /*endif*/ + break; + case V150_1_SIGNAL_VBD: + update_media_states(s, s->local_media_state, V150_1_MEDIA_STATE_VOICE_BAND_DATA); + break; + default: + span_log(&s->logging, SPAN_LOG_FLOW, "Unexpected signal %s\n", v150_1_signal_to_str(signal)); + break; + } + /*endswitch*/ + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int v150_1_figure_36(v150_1_state_t *s, int signal, const uint8_t *msg, int len) +{ + /* Figure 36/V.150.1 */ + switch (signal) + { + case V150_1_SIGNAL_AUDIO: + update_media_states(s, V150_1_MEDIA_STATE_INITIAL_AUDIO, V150_1_MEDIA_STATE_VOICE_BAND_DATA); + break; + case V150_1_SIGNAL_MODEM_RELAY: + stop_timer(s); + break; + case V150_1_SIGNAL_VBD: + stop_timer(s); + update_media_states(s, V150_1_MEDIA_STATE_INITIAL_AUDIO, V150_1_MEDIA_STATE_VOICE_BAND_DATA); + // send sse p' + generic_macro(s, signal, 0); + break; + default: + span_log(&s->logging, SPAN_LOG_FLOW, "Unexpected signal %s\n", v150_1_signal_to_str(signal)); + break; + } + /*endswitch*/ + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int v150_1_figure_37(v150_1_state_t *s, int signal, const uint8_t *msg, int len) +{ + /* Figure 37/V.150.1 */ + switch (signal) + { + case V150_1_SIGNAL_AUDIO: + update_media_states(s, V150_1_MEDIA_STATE_INITIAL_AUDIO, V150_1_MEDIA_STATE_INITIAL_AUDIO); + break; + case V150_1_SIGNAL_MODEM_RELAY: + stop_timer(s); + break; + case V150_1_SIGNAL_VBD: + stop_timer(s); + break; + default: + span_log(&s->logging, SPAN_LOG_FLOW, "Unexpected signal %s\n", v150_1_signal_to_str(signal)); + break; + } + /*endswitch*/ + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int v150_1_figure_38(v150_1_state_t *s, int signal, const uint8_t *msg, int len) +{ + /* Figure 38/V.150.1 */ + switch (signal) + { + case V150_1_SIGNAL_AUDIO: + update_media_states(s, V150_1_MEDIA_STATE_INITIAL_AUDIO, V150_1_MEDIA_STATE_INITIAL_AUDIO); + break; + case V150_1_SIGNAL_VBD: + stop_timer(s); + break; + default: + span_log(&s->logging, SPAN_LOG_FLOW, "Unexpected signal %s\n", v150_1_signal_to_str(signal)); + break; + } + /*endswitch*/ + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int v150_1_figure_39(v150_1_state_t *s, int signal, const uint8_t *msg, int len) +{ + /* Figure 39/V.150.1 */ + switch (signal) + { + case V150_1_SIGNAL_MODEM_RELAY: + break; + case V150_1_SIGNAL_CM: + break; + case V150_1_SIGNAL_RFC4733_ANS: + send_spe_signal(s, V150_1_SIGNAL_ANS_GEN); + break; + case V150_1_SIGNAL_RFC4733_ANSAM: + send_spe_signal(s, V150_1_SIGNAL_ANSAM_GEN); + break; + case V150_1_SIGNAL_RFC4733_ANS_PR: + send_spe_signal(s, V150_1_SIGNAL_ANS_GEN); + break; + case V150_1_SIGNAL_RFC4733_ANSAM_PR: + send_spe_signal(s, V150_1_SIGNAL_ANSAM_GEN); + break; + case V150_1_SIGNAL_ANS: + if (s->rfc4733_preferred) + { + generic_macro(s, V150_1_SIGNAL_RFC4733_ANS_GEN, 0); + } + else + { + /* Pass the audio through */ + } + /*endif*/ + break; + case V150_1_SIGNAL_ANSAM: + if (s->rfc4733_preferred) + { + generic_macro(s, V150_1_SIGNAL_RFC4733_ANSAM_GEN, 0); + } + else + { + /* Pass the audio through */ + } + /*endif*/ + break; + case V150_1_SIGNAL_ANS_PR: + if (s->rfc4733_preferred) + { + generic_macro(s, V150_1_SIGNAL_RFC4733_ANS_PR_GEN, 0); + } + else + { + /* Pass the audio through */ + } + /*endif*/ + break; + case V150_1_SIGNAL_ANSAM_PR: + if (s->rfc4733_preferred) + { + generic_macro(s, V150_1_SIGNAL_RFC4733_ANSAM_PR_GEN, 0); + } + else + { + /* Pass the audio through */ + } + /*endif*/ + break; + default: + span_log(&s->logging, SPAN_LOG_FLOW, "Unexpected signal %s\n", v150_1_signal_to_str(signal)); + break; + } + /*endswitch*/ + return 0; +} +/*- End of function --------------------------------------------------------*/ + +SPAN_DECLARE(int) v150_1_state_machine(v150_1_state_t *s, int signal, const uint8_t *msg, int len) +{ + span_log(&s->logging, + SPAN_LOG_FLOW, + "State machine - %s %s %s\n", + v150_1_media_state_to_str(s->local_media_state), + v150_1_media_state_to_str(s->remote_media_state), + v150_1_signal_to_str(signal)); + /* Figure 40/V.150.1, leading out to the other SDL figures */ + switch (signal) + { + case V150_1_SIGNAL_SILENCE: + if (s->local_media_state != V150_1_MEDIA_STATE_INITIAL_AUDIO + || + s->remote_media_state != V150_1_MEDIA_STATE_INITIAL_AUDIO) + { + s->remote_media_state = V150_1_MEDIA_STATE_INDETERMINATE; + s->local_media_state = V150_1_MEDIA_STATE_INITIAL_AUDIO; + status_report(s, V150_1_STATUS_REASON_MEDIA_STATE_CHANGED); + generic_macro(s, signal, 0); + } + /*endif*/ + break; + case V150_1_SIGNAL_ABORT: + s->remote_media_state = V150_1_MEDIA_STATE_INDETERMINATE; + s->local_media_state = V150_1_MEDIA_STATE_INITIAL_AUDIO; + status_report(s, V150_1_STATUS_REASON_MEDIA_STATE_CHANGED); + generic_macro(s, signal, 0); + break; + case V150_1_SIGNAL_CALL_DISCRIMINATION_TIMER_EXPIRED: + /* Time to give up with negotiation, and go with the flow */ + s->remote_media_state = V150_1_MEDIA_STATE_INDETERMINATE; + s->local_media_state = V150_1_MEDIA_STATE_INITIAL_AUDIO; + status_report(s, V150_1_STATUS_REASON_MEDIA_STATE_CHANGED); + break; + default: + switch (s->local_media_state) + { + case V150_1_MEDIA_STATE_INDETERMINATE: + switch (s->remote_media_state) + { + case V150_1_MEDIA_STATE_INDETERMINATE: + break; + case V150_1_MEDIA_STATE_INITIAL_AUDIO: + break; + case V150_1_MEDIA_STATE_VOICE_BAND_DATA: + break; + case V150_1_MEDIA_STATE_FAX_RELAY: + break; + case V150_1_MEDIA_STATE_MODEM_RELAY: + break; + case V150_1_MEDIA_STATE_TEXT_RELAY: + break; + } + /*endswitch*/ + break; + case V150_1_MEDIA_STATE_INITIAL_AUDIO: + switch (s->remote_media_state) + { + case V150_1_MEDIA_STATE_INDETERMINATE: + break; + case V150_1_MEDIA_STATE_INITIAL_AUDIO: + v150_1_figures_26_to_31(s, signal, msg, len); + break; + case V150_1_MEDIA_STATE_VOICE_BAND_DATA: + v150_1_figure_33(s, signal, msg, len); + break; + case V150_1_MEDIA_STATE_FAX_RELAY: + break; + case V150_1_MEDIA_STATE_MODEM_RELAY: + v150_1_figure_32(s, signal, msg, len); + break; + case V150_1_MEDIA_STATE_TEXT_RELAY: + break; + } + /*endswitch*/ + break; + case V150_1_MEDIA_STATE_VOICE_BAND_DATA: + switch (s->remote_media_state) + { + case V150_1_MEDIA_STATE_INDETERMINATE: + break; + case V150_1_MEDIA_STATE_INITIAL_AUDIO: + v150_1_figure_37(s, signal, msg, len); + break; + case V150_1_MEDIA_STATE_VOICE_BAND_DATA: + v150_1_figure_39(s, signal, msg, len); + break; + case V150_1_MEDIA_STATE_FAX_RELAY: + break; + case V150_1_MEDIA_STATE_MODEM_RELAY: + v150_1_figure_38(s, signal, msg, len); + break; + case V150_1_MEDIA_STATE_TEXT_RELAY: + break; + } + /*endswitch*/ + break; + case V150_1_MEDIA_STATE_FAX_RELAY: + switch (s->remote_media_state) + { + case V150_1_MEDIA_STATE_INDETERMINATE: + break; + case V150_1_MEDIA_STATE_INITIAL_AUDIO: + break; + case V150_1_MEDIA_STATE_VOICE_BAND_DATA: + break; + case V150_1_MEDIA_STATE_FAX_RELAY: + break; + case V150_1_MEDIA_STATE_MODEM_RELAY: + break; + case V150_1_MEDIA_STATE_TEXT_RELAY: + break; + } + /*endswitch*/ + break; + case V150_1_MEDIA_STATE_MODEM_RELAY: + switch (s->remote_media_state) + { + case V150_1_MEDIA_STATE_INDETERMINATE: + break; + case V150_1_MEDIA_STATE_INITIAL_AUDIO: + v150_1_figure_34(s, signal, msg, len); + break; + case V150_1_MEDIA_STATE_VOICE_BAND_DATA: + v150_1_figure_36(s, signal, msg, len); + break; + case V150_1_MEDIA_STATE_FAX_RELAY: + break; + case V150_1_MEDIA_STATE_MODEM_RELAY: + v150_1_figure_35(s, signal, msg, len); + break; + case V150_1_MEDIA_STATE_TEXT_RELAY: + break; + } + /*endswitch*/ + break; + case V150_1_MEDIA_STATE_TEXT_RELAY: + switch (s->remote_media_state) + { + case V150_1_MEDIA_STATE_INDETERMINATE: + break; + case V150_1_MEDIA_STATE_INITIAL_AUDIO: + break; + case V150_1_MEDIA_STATE_VOICE_BAND_DATA: + break; + case V150_1_MEDIA_STATE_FAX_RELAY: + break; + case V150_1_MEDIA_STATE_MODEM_RELAY: + break; + case V150_1_MEDIA_STATE_TEXT_RELAY: + break; + } + /*endswitch*/ + break; + } + /*endswitch*/ + } + /*endswitch*/ + return 0; +} +/*- End of function --------------------------------------------------------*/ + +SPAN_DECLARE(int) v150_1_set_bits_per_character(v150_1_state_t *s, int bits) +{ + if (bits < 5 || bits > 8) + return -1; + /*endif*/ + bits -= 5; + s->near.parms.data_format_code &= 0x9F; + s->near.parms.data_format_code |= ((bits << 5) & 0x60); + return 0; +} +/*- End of function --------------------------------------------------------*/ + +SPAN_DECLARE(int) v150_1_set_parity(v150_1_state_t *s, int mode) +{ + s->near.parms.data_format_code &= 0xE3; + s->near.parms.data_format_code |= ((mode << 2) & 0x1C); + return 0; +} +/*- End of function --------------------------------------------------------*/ + +SPAN_DECLARE(int) v150_1_set_stop_bits(v150_1_state_t *s, int bits) +{ + if (bits < 1 || bits > 2) + return -1; + /*endif*/ + bits -= 1; + s->near.parms.data_format_code &= 0xFC; + s->near.parms.data_format_code |= (bits & 0x03); + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int select_info_msg_type(v150_1_state_t *s) +{ + int i; + + /* Select the first available information message type we find in the preferences list */ + for (i = 0; i < 10 && s->near.info_msg_preferences[i] >= 0; i++) + { + switch (s->near.info_msg_preferences[i]) + { + case V150_1_MSGID_I_RAW_OCTET: + /* This is always supported */ + s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; + return 0; + case V150_1_MSGID_I_RAW_BIT: + if (s->near.parms.i_raw_bit_available) + { + s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; + return 0; + } + /*endif*/ + break; + case V150_1_MSGID_I_OCTET: + /* This is always supported */ + s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; + return 0; + case V150_1_MSGID_I_CHAR_STAT: + if (s->near.parms.i_char_stat_available) + { + s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; + return 0; + } + /*endif*/ + break; + case V150_1_MSGID_I_CHAR_DYN: + if (s->near.parms.i_char_dyn_available) + { + s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; + return 0; + } + /*endif*/ + break; + case V150_1_MSGID_I_FRAME: + if (s->near.parms.i_frame_available) + { + s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; + return 0; + } + /*endif*/ + break; + case V150_1_MSGID_I_OCTET_CS: + if (s->near.parms.i_octet_cs_available) + { + s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; + return 0; + } + /*endif*/ + break; + case V150_1_MSGID_I_CHAR_STAT_CS: + if (s->near.parms.i_char_stat_cs_available) + { + s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; + return 0; + } + /*endif*/ + break; + case V150_1_MSGID_I_CHAR_DYN_CS: + if (s->near.parms.i_char_dyn_cs_available) + { + s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; + return 0; + } + /*endif*/ + break; + default: + s->near.info_stream_msg_id = -1; + return -1; + } + /*endswitch*/ } - /*endswitch*/ - if (s->rx_status_report_handler) - s->rx_status_report_handler(s->rx_status_report_user_data, &report); - /*endif*/ - return 0; + /*endfor*/ + s->near.info_stream_msg_id = -1; + return -1; } /*- End of function --------------------------------------------------------*/ @@ -1350,9 +2219,7 @@ SPAN_DECLARE(int) v150_1_tx_null(v150_1_state_t *s) res = -1; /* This isn't a real message. Its marked as reserved by the ITU-T in V.150.1 */ pkt[0] = V150_1_MSGID_NULL; - if (s->tx_packet_handler) - res = s->tx_packet_handler(s->tx_packet_user_data, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 1); - /*endif*/ + res = sprt_tx(&s->sprt, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 1); span_log(&s->logging, SPAN_LOG_FLOW, "NULL sent\n"); return res; } @@ -1406,14 +2273,15 @@ SPAN_DECLARE(int) v150_1_tx_init(v150_1_state_t *s) pkt[2] = i; span_log(&s->logging, SPAN_LOG_FLOW, "Sending INIT\n"); log_init(s, &s->near.parms); - if (s->tx_packet_handler) - res = s->tx_packet_handler(s->tx_packet_user_data, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 3); - /*endif*/ + res = sprt_tx(&s->sprt, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 3); if (res >= 0) { s->near.parms.connection_state = V150_1_STATE_INITED; if (s->far.parms.connection_state >= V150_1_STATE_INITED) + { + select_info_msg_type(s); s->joint_connection_state = V150_1_STATE_INITED; + } /*endif*/ } /*endif*/ @@ -1471,9 +2339,7 @@ SPAN_DECLARE(int) v150_1_tx_xid_xchg(v150_1_state_t *s) memset(&pkt[7], 0, 12); } /*endif*/ - if (s->tx_packet_handler) - res = s->tx_packet_handler(s->tx_packet_user_data, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 19); - /*endif*/ + res = sprt_tx(&s->sprt, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 19); span_log(&s->logging, SPAN_LOG_FLOW, "XID xchg sent\n"); return res; } @@ -1526,9 +2392,7 @@ SPAN_DECLARE(int) v150_1_tx_jm_info(v150_1_state_t *s) } /*endif*/ } - if (s->tx_packet_handler) - res = s->tx_packet_handler(s->tx_packet_user_data, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, len); - /*endif*/ + res = sprt_tx(&s->sprt, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, len); span_log(&s->logging, SPAN_LOG_FLOW, "JM info sent\n"); return res; } @@ -1540,11 +2404,13 @@ SPAN_DECLARE(int) v150_1_tx_start_jm(v150_1_state_t *s) uint8_t pkt[256]; res = -1; - pkt[0] = V150_1_MSGID_START_JM; - if (s->tx_packet_handler) - res = s->tx_packet_handler(s->tx_packet_user_data, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 1); + if (s->near.parms.connection_state != V150_1_STATE_IDLE) + { + pkt[0] = V150_1_MSGID_START_JM; + res = sprt_tx(&s->sprt, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 1); + span_log(&s->logging, SPAN_LOG_FLOW, "Start JM sent\n"); + } /*endif*/ - span_log(&s->logging, SPAN_LOG_FLOW, "Start JM sent\n"); return res; } /*- End of function --------------------------------------------------------*/ @@ -1611,18 +2477,16 @@ SPAN_DECLARE(int) v150_1_tx_connect(v150_1_state_t *s) len += 4; } /*endif*/ - if (s->tx_packet_handler) - res = s->tx_packet_handler(s->tx_packet_user_data, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, len); - /*endif*/ + res = sprt_tx(&s->sprt, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, len); if (res >= 0) { s->near.parms.connection_state = V150_1_STATE_CONNECTED; if (s->near.parms.connection_state >= V150_1_STATE_CONNECTED) s->joint_connection_state = V150_1_STATE_CONNECTED; /*endif*/ + span_log(&s->logging, SPAN_LOG_FLOW, "Connect sent\n"); } /*endif*/ - span_log(&s->logging, SPAN_LOG_FLOW, "Connect sent\n"); return res; } /*- End of function --------------------------------------------------------*/ @@ -1633,13 +2497,19 @@ SPAN_DECLARE(int) v150_1_tx_break(v150_1_state_t *s, int source, int type, int d uint8_t pkt[256]; res = -1; - pkt[0] = V150_1_MSGID_BREAK; - pkt[1] = (source << 4) | type; - pkt[2] = duration/10; - if (s->tx_packet_handler) - res = s->tx_packet_handler(s->tx_packet_user_data, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 3); + if (s->near.parms.connection_state != V150_1_STATE_IDLE) + { + pkt[0] = V150_1_MSGID_BREAK; + pkt[1] = (source << 4) | type; + pkt[2] = duration/10; + res = sprt_tx(&s->sprt, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 3); + if (res >= 0) + { + span_log(&s->logging, SPAN_LOG_FLOW, "Break sent\n"); + } + /*endif*/ + } /*endif*/ - span_log(&s->logging, SPAN_LOG_FLOW, "Break sent\n"); return res; } /*- End of function --------------------------------------------------------*/ @@ -1650,11 +2520,17 @@ SPAN_DECLARE(int) v150_1_tx_break_ack(v150_1_state_t *s) uint8_t pkt[256]; res = -1; - pkt[0] = V150_1_MSGID_BREAKACK; - if (s->tx_packet_handler) - res = s->tx_packet_handler(s->tx_packet_user_data, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 1); + if (s->near.parms.connection_state != V150_1_STATE_IDLE) + { + pkt[0] = V150_1_MSGID_BREAKACK; + res = sprt_tx(&s->sprt, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 1); + if (res >= 0) + { + span_log(&s->logging, SPAN_LOG_FLOW, "Break ACK sent\n"); + } + /*endif*/ + } /*endif*/ - span_log(&s->logging, SPAN_LOG_FLOW, "Break ACK sent\n"); return res; } /*- End of function --------------------------------------------------------*/ @@ -1710,10 +2586,12 @@ SPAN_DECLARE(int) v150_1_tx_mr_event(v150_1_state_t *s, int event_id) break; } /*endswitch*/ - if (s->tx_packet_handler) - res = s->tx_packet_handler(s->tx_packet_user_data, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, len); + res = sprt_tx(&s->sprt, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, len); + if (res >= 0) + { + span_log(&s->logging, SPAN_LOG_FLOW, "MR-event %s (%d) sent\n", v150_1_mr_event_type_to_str(event_id), event_id); + } /*endif*/ - span_log(&s->logging, SPAN_LOG_FLOW, "MR-event sent\n"); return res; } /*- End of function --------------------------------------------------------*/ @@ -1725,17 +2603,21 @@ SPAN_DECLARE(int) v150_1_tx_cleardown(v150_1_state_t *s, int reason) res = -1; - pkt[0] = V150_1_MSGID_CLEARDOWN; - pkt[1] = reason; - pkt[2] = 0; /* Vendor tag */ - pkt[3] = 0; /* Vendor info */ - if (s->tx_packet_handler) - res = s->tx_packet_handler(s->tx_packet_user_data, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 4); - /*endif*/ - if (res >= 0) - s->near.parms.connection_state = V150_1_STATE_IDLE; + if (s->near.parms.connection_state != V150_1_STATE_IDLE) + { + pkt[0] = V150_1_MSGID_CLEARDOWN; + pkt[1] = reason; + pkt[2] = 0; /* Vendor tag */ + pkt[3] = 0; /* Vendor info */ + res = sprt_tx(&s->sprt, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 4); + if (res >= 0) + { + s->near.parms.connection_state = V150_1_STATE_IDLE; + span_log(&s->logging, SPAN_LOG_FLOW, "Cleardown sent\n"); + } + /*endif*/ + } /*endif*/ - span_log(&s->logging, SPAN_LOG_FLOW, "Cleardown sent\n"); return res; } /*- End of function --------------------------------------------------------*/ @@ -1794,9 +2676,7 @@ SPAN_DECLARE(int) v150_1_tx_prof_xchg(v150_1_state_t *s) memset(&pkt[7], 0, 12); } /*endif*/ - if (s->tx_packet_handler) - res = s->tx_packet_handler(s->tx_packet_user_data, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 19); - /*endif*/ + res = sprt_tx(&s->sprt, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, pkt, 19); span_log(&s->logging, SPAN_LOG_FLOW, "Prof xchg sent\n"); return res; } @@ -2018,9 +2898,7 @@ SPAN_DECLARE(int) v150_1_tx_info_stream(v150_1_state_t *s, const uint8_t buf[], /*endswitch*/ if (res >= 0) { - if (s->tx_packet_handler) - res = s->tx_packet_handler(s->tx_packet_user_data, s->near.info_stream_channel, pkt, res); - /*endif*/ + res = sprt_tx(&s->sprt, s->near.info_stream_channel, pkt, res); } else { @@ -2031,91 +2909,6 @@ SPAN_DECLARE(int) v150_1_tx_info_stream(v150_1_state_t *s, const uint8_t buf[], } /*- End of function --------------------------------------------------------*/ -static int select_info_msg_type(v150_1_state_t *s) -{ - int i; - - /* Select the first available information message type we find in the preferences list */ - for (i = 0; i < 10 && s->near.info_msg_preferences[i] >= 0; i++) - { - switch (s->near.info_msg_preferences[i]) - { - case V150_1_MSGID_I_RAW_OCTET: - /* This is always supported */ - s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; - return 0; - case V150_1_MSGID_I_RAW_BIT: - if (s->near.parms.i_raw_bit_available) - { - s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; - return 0; - } - /*endif*/ - break; - case V150_1_MSGID_I_OCTET: - /* This is always supported */ - s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; - return 0; - case V150_1_MSGID_I_CHAR_STAT: - if (s->near.parms.i_char_stat_available) - { - s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; - return 0; - } - /*endif*/ - break; - case V150_1_MSGID_I_CHAR_DYN: - if (s->near.parms.i_char_dyn_available) - { - s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; - return 0; - } - /*endif*/ - break; - case V150_1_MSGID_I_FRAME: - if (s->near.parms.i_frame_available) - { - s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; - return 0; - } - /*endif*/ - break; - case V150_1_MSGID_I_OCTET_CS: - if (s->near.parms.i_octet_cs_available) - { - s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; - return 0; - } - /*endif*/ - break; - case V150_1_MSGID_I_CHAR_STAT_CS: - if (s->near.parms.i_char_stat_cs_available) - { - s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; - return 0; - } - /*endif*/ - break; - case V150_1_MSGID_I_CHAR_DYN_CS: - if (s->near.parms.i_char_dyn_cs_available) - { - s->near.info_stream_msg_id = s->near.info_msg_preferences[i]; - return 0; - } - /*endif*/ - break; - default: - s->near.info_stream_msg_id = -1; - return -1; - } - /*endswitch*/ - } - /*endfor*/ - s->near.info_stream_msg_id = -1; - return -1; -} -/*- End of function --------------------------------------------------------*/ - static int v150_1_process_null(v150_1_state_t *s, const uint8_t buf[], int len) { if (len != 1) @@ -2156,7 +2949,9 @@ static int v150_1_process_init(v150_1_state_t *s, const uint8_t buf[], int len) s->near.parms.i_char_stat_cs_available = s->near.parms.i_char_stat_cs_supported && s->far.parms.i_char_stat_cs_supported; s->near.parms.i_char_dyn_cs_available = s->near.parms.i_char_dyn_cs_supported && s->far.parms.i_char_dyn_cs_supported; - select_info_msg_type(s); + if (s->far.parms.connection_state >= V150_1_STATE_INITED) + select_info_msg_type(s); + /*endif*/ span_log(&s->logging, SPAN_LOG_FLOW, "Received INIT\n"); log_init(s, &s->far.parms); @@ -2164,7 +2959,7 @@ static int v150_1_process_init(v150_1_state_t *s, const uint8_t buf[], int len) if (s->near.parms.connection_state >= V150_1_STATE_INITED) s->joint_connection_state = V150_1_STATE_INITED; /*endif*/ - status_report(s, V150_1_STATUS_REASON_STATE_CHANGED); + status_report(s, V150_1_STATUS_REASON_CONNECTION_STATE_CHANGED); return 0; } /*- End of function --------------------------------------------------------*/ @@ -2410,7 +3205,7 @@ static int v150_1_process_connect(v150_1_state_t *s, const uint8_t buf[], int le if (s->near.parms.connection_state >= V150_1_STATE_CONNECTED) s->joint_connection_state = V150_1_STATE_CONNECTED; /*endif*/ - status_report(s, V150_1_STATUS_REASON_STATE_CHANGED); + status_report(s, V150_1_STATUS_REASON_CONNECTION_STATE_CONNECTED); return 0; } /*- End of function --------------------------------------------------------*/ @@ -2479,13 +3274,13 @@ static int v150_1_process_mr_event(v150_1_state_t *s, const uint8_t buf[], int l /*endif*/ event = buf[1]; - span_log(&s->logging, SPAN_LOG_FLOW, "MR_EVENT type %s (%d) received\n", v150_1_mr_event_type_to_str(event), event); + span_log(&s->logging, SPAN_LOG_FLOW, "MR-event %s (%d) received\n", v150_1_mr_event_type_to_str(event), event); switch (event) { case V150_1_MR_EVENT_ID_NULL: if (len != 3) { - span_log(&s->logging, SPAN_LOG_WARNING, "Invalid MR_EVENT message length %d\n", len); + span_log(&s->logging, SPAN_LOG_WARNING, "Invalid MR-event message length %d\n", len); return -1; } /*endif*/ @@ -2494,7 +3289,7 @@ static int v150_1_process_mr_event(v150_1_state_t *s, const uint8_t buf[], int l case V150_1_MR_EVENT_ID_RETRAIN: if (len != 3) { - span_log(&s->logging, SPAN_LOG_WARNING, "Invalid MR_EVENT message length %d\n", len); + span_log(&s->logging, SPAN_LOG_WARNING, "Invalid MR-event message length %d\n", len); return -1; } /*endif*/ @@ -2517,7 +3312,7 @@ static int v150_1_process_mr_event(v150_1_state_t *s, const uint8_t buf[], int l case V150_1_MR_EVENT_ID_PHYSUP: if (len != 10) { - span_log(&s->logging, SPAN_LOG_WARNING, "Invalid MR_EVENT message length %d\n", len); + span_log(&s->logging, SPAN_LOG_WARNING, "Invalid MR-event message length %d\n", len); return -1; } /*endif*/ @@ -2545,10 +3340,10 @@ static int v150_1_process_mr_event(v150_1_state_t *s, const uint8_t buf[], int l if (s->near.parms.connection_state >= V150_1_STATE_PHYSUP) s->joint_connection_state = V150_1_STATE_PHYSUP; /*endif*/ - status_report(s, V150_1_STATUS_REASON_STATE_CHANGED); + status_report(s, V150_1_STATUS_REASON_CONNECTION_STATE_PHYSUP); break; default: - span_log(&s->logging, SPAN_LOG_WARNING, "Unknown MR_EVENT type %d received\n", event); + span_log(&s->logging, SPAN_LOG_WARNING, "Unknown MR-event type %d received\n", event); break; } /*endif*/ @@ -2580,7 +3375,7 @@ static int v150_1_process_cleardown(v150_1_state_t *s, const uint8_t buf[], int // vendor_info = buf[3]; /* A cleardown moves everything back to square one. */ s->far.parms.connection_state = V150_1_STATE_IDLE; - status_report(s, V150_1_STATUS_REASON_STATE_CHANGED); + status_report(s, V150_1_STATUS_REASON_CONNECTION_STATE_CHANGED); return 0; } /*- End of function --------------------------------------------------------*/ @@ -2681,8 +3476,8 @@ static int v150_1_process_i_raw_octet(v150_1_state_t *s, const uint8_t buf[], in /*endif*/ for (i = 0; i < n; i++) { - if (s->rx_octet_handler) - s->rx_octet_handler(s->rx_octet_handler_user_data, &buf[header], len - header, -1); + if (s->rx_data_handler) + s->rx_data_handler(s->rx_data_handler_user_data, &buf[header], len - header, -1); /*endif*/ } /*endif*/ @@ -2742,8 +3537,8 @@ static int v150_1_process_i_raw_bit(v150_1_state_t *s, const uint8_t buf[], int /*endif*/ for (i = 0; i < n; i++) { - if (s->rx_octet_handler) - s->rx_octet_handler(s->rx_octet_handler_user_data, &buf[header], len - header, -1); + if (s->rx_data_handler) + s->rx_data_handler(s->rx_data_handler_user_data, &buf[header], len - header, -1); /*endif*/ } /*endfor*/ @@ -2801,8 +3596,8 @@ static int v150_1_process_i_octet(v150_1_state_t *s, const uint8_t buf[], int le /*endif*/ if (len > header) { - if (s->rx_octet_handler) - s->rx_octet_handler(s->rx_octet_handler_user_data, &buf[header], len - header, -1); + if (s->rx_data_handler) + s->rx_data_handler(s->rx_data_handler_user_data, &buf[header], len - header, -1); /*endif*/ } /*endif*/ @@ -2833,8 +3628,8 @@ static int v150_1_process_i_char_stat(v150_1_state_t *s, const uint8_t buf[], in /*endif*/ if (len > 2) { - if (s->rx_octet_handler) - s->rx_octet_handler(s->rx_octet_handler_user_data, &buf[2], len - 2, -1); + if (s->rx_data_handler) + s->rx_data_handler(s->rx_data_handler_user_data, &buf[2], len - 2, -1); /*endif*/ } /*endif*/ @@ -2864,8 +3659,8 @@ static int v150_1_process_i_char_dyn(v150_1_state_t *s, const uint8_t buf[], int /*endif*/ if (len > 2) { - if (s->rx_octet_handler) - s->rx_octet_handler(s->rx_octet_handler_user_data, &buf[2], len - 2, -1); + if (s->rx_data_handler) + s->rx_data_handler(s->rx_data_handler_user_data, &buf[2], len - 2, -1); /*endif*/ } /*endif*/ @@ -2897,8 +3692,8 @@ static int v150_1_process_i_frame(v150_1_state_t *s, const uint8_t buf[], int le data_frame_state = buf[1] & 0x03; if (len > 2) { - if (s->rx_octet_handler) - s->rx_octet_handler(s->rx_octet_handler_user_data, &buf[2], len - 2, -1); + if (s->rx_data_handler) + s->rx_data_handler(s->rx_data_handler_user_data, &buf[2], len - 2, -1); /*endif*/ } /*endif*/ @@ -2926,8 +3721,8 @@ static int v150_1_process_i_octet_cs(v150_1_state_t *s, const uint8_t buf[], int character_seq_no = get_net_unaligned_uint16(&buf[1]); /* Check for a gap in the data */ fill = (character_seq_no - s->far.parms.octet_cs_next_seq_no) & 0xFFFF; - if (s->rx_octet_handler) - s->rx_octet_handler(s->rx_octet_handler_user_data, &buf[3], len - 3, fill); + if (s->rx_data_handler) + s->rx_data_handler(s->rx_data_handler_user_data, &buf[3], len - 3, fill); /*endif*/ s->far.parms.octet_cs_next_seq_no = (character_seq_no + len - 3) & 0xFFFF; return 0; @@ -2961,8 +3756,8 @@ static int v150_1_process_i_char_stat_cs(v150_1_state_t *s, const uint8_t buf[], character_seq_no = get_net_unaligned_uint16(&buf[2]); /* Check for a gap in the data */ fill = (character_seq_no - s->far.parms.octet_cs_next_seq_no) & 0xFFFF; - if (s->rx_octet_handler) - s->rx_octet_handler(s->rx_octet_handler_user_data, &buf[4], len - 4, fill); + if (s->rx_data_handler) + s->rx_data_handler(s->rx_data_handler_user_data, &buf[4], len - 4, fill); /*endif*/ s->far.parms.octet_cs_next_seq_no = (character_seq_no + len - 4) & 0xFFFF; return 0; @@ -2995,18 +3790,24 @@ static int v150_1_process_i_char_dyn_cs(v150_1_state_t *s, const uint8_t buf[], character_seq_no = get_net_unaligned_uint16(&buf[2]); /* Check for a gap in the data */ fill = (character_seq_no - s->far.parms.octet_cs_next_seq_no) & 0xFFFF; - if (s->rx_octet_handler) - s->rx_octet_handler(s->rx_octet_handler_user_data, &buf[4], len - 4, fill); + if (s->rx_data_handler) + s->rx_data_handler(s->rx_data_handler_user_data, &buf[4], len - 4, fill); /*endif*/ s->far.parms.octet_cs_next_seq_no = (character_seq_no + len - 4) & 0xFFFF; return 0; } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(int) v150_1_process_rx_msg(v150_1_state_t *s, int chan, int seq_no, const uint8_t buf[], int len) +static int process_rx_sprt_msg(void *user_data, int chan, int seq_no, const uint8_t buf[], int len) { int res; int msg_id; + v150_1_state_t *s; + + s = (v150_1_state_t *) user_data; + + span_log(&s->logging, SPAN_LOG_FLOW, "%s (%d) seq %d\n", sprt_transmission_channel_to_str(chan), chan, seq_no); + span_log_buf(&s->logging, SPAN_LOG_FLOW, "", buf, len); if (chan < SPRT_TCID_MIN || chan > SPRT_TCID_MAX) { @@ -3109,6 +3910,13 @@ SPAN_DECLARE(int) v150_1_process_rx_msg(v150_1_state_t *s, int chan, int seq_no, } /*- End of function --------------------------------------------------------*/ +SPAN_DECLARE(int) v150_1_test_rx_sprt_msg(v150_1_state_t *s, int chan, int seq_no, const uint8_t buf[], int len) +{ + process_rx_sprt_msg((void *) s, chan, seq_no, buf, len); + return 0; +} +/*- End of function --------------------------------------------------------*/ + SPAN_DECLARE(int) v150_1_set_local_busy(v150_1_state_t *s, bool busy) { bool previous_busy; @@ -3292,21 +4100,231 @@ SPAN_DECLARE(int) v150_1_set_rx_data_signalling_rate(v150_1_state_t *s, int rate } /*- End of function --------------------------------------------------------*/ +static void set_joint_cdscselect(v150_1_state_t *s) +{ + /* See Table 32/V.150.1 */ + if (s->near.parms.cdscselect == V150_1_CDSCSELECT_INDETERMINATE + || + s->far.parms.cdscselect == V150_1_CDSCSELECT_INDETERMINATE) + { + s->cdscselect = V150_1_CDSCSELECT_INDETERMINATE; + } + else if (s->near.parms.cdscselect == V150_1_CDSCSELECT_AUDIO_RFC4733 + || + s->far.parms.cdscselect == V150_1_CDSCSELECT_AUDIO_RFC4733) + { + s->cdscselect = V150_1_CDSCSELECT_AUDIO_RFC4733; + } + else if (s->near.parms.cdscselect == V150_1_CDSCSELECT_VBD_SELECT + || + s->far.parms.cdscselect == V150_1_CDSCSELECT_VBD_SELECT) + { + s->cdscselect = V150_1_CDSCSELECT_VBD_SELECT; + } + else + { + s->cdscselect = V150_1_CDSCSELECT_MIXED; + } + /*endif*/ +} +/*- End of function --------------------------------------------------------*/ + +SPAN_DECLARE(void) v150_1_set_near_cdscselect(v150_1_state_t *s, v150_1_cdscselect_t select) +{ + s->near.parms.cdscselect = select; + set_joint_cdscselect(s); +} +/*- End of function --------------------------------------------------------*/ + +SPAN_DECLARE(void) v150_1_set_far_cdscselect(v150_1_state_t *s, v150_1_cdscselect_t select) +{ + s->far.parms.cdscselect = select; + set_joint_cdscselect(s); +} +/*- End of function --------------------------------------------------------*/ + +SPAN_DECLARE(void) v150_1_set_call_discrimination_timeout(v150_1_state_t *s, int timeout) +{ + s->call_discrimination_timeout = timeout; +} +/*- End of function --------------------------------------------------------*/ + SPAN_DECLARE(logging_state_t *) v150_1_get_logging_state(v150_1_state_t *s) { return &s->logging; } /*- End of function --------------------------------------------------------*/ +int sse_status_handler(v150_1_state_t *s, int status) +{ + span_log(&s->logging, SPAN_LOG_FLOW, "SSE status event %s\n", v150_1_sse_status_to_str(status)); + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static void sprt_status_handler(void *user_data, int status) +{ + v150_1_state_t *s; + + s = (v150_1_state_t *) user_data; + span_log(&s->logging, SPAN_LOG_FLOW, "SPRT status event %d\n", status); +} +/*- End of function --------------------------------------------------------*/ + +static void call_discrimination_timer_expired(v150_1_state_t *s, span_timestamp_t now) +{ + v150_1_state_machine(s, V150_1_SIGNAL_CALL_DISCRIMINATION_TIMER_EXPIRED, NULL, 0); +} +/*- End of function --------------------------------------------------------*/ + +SPAN_DECLARE(int) v150_1_timer_expired(v150_1_state_t *s, span_timestamp_t now) +{ + span_log(&s->logging, SPAN_LOG_FLOW, "V.150.1 timer expired at %lu\n", now); + + if (now < s->latest_timer) + { + span_log(&s->logging, SPAN_LOG_FLOW, "V.150.1 timer returned %luus early\n", s->latest_timer - now); + /* Request the same timeout point again. */ + if (s->timer_handler) + s->timer_handler(s->timer_user_data, s->latest_timer); + /*endif*/ + return 0; + } + /*endif*/ + + if (s->call_discrimination_timer != 0 && s->call_discrimination_timer <= now) + { + span_log(&s->logging, SPAN_LOG_FLOW, "Call discrimination timer expired\n"); + call_discrimination_timer_expired(s, now); + } + /*endif*/ + if (s->sse_timer != 0 && s->sse_timer <= now) + { + span_log(&s->logging, SPAN_LOG_FLOW, "SSE timer expired\n"); + v150_1_sse_timer_expired(s, now); + } + /*endif*/ + if (s->sprt_timer != 0 && s->sprt_timer <= now) + { + span_log(&s->logging, SPAN_LOG_FLOW, "SPRT timer expired\n"); + sprt_timer_expired(&s->sprt, now); + } + /*endif*/ + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static span_timestamp_t select_timer(v150_1_state_t *s) +{ + span_timestamp_t shortest; + int shortest_is; + + /* Find the earliest expiring of the active timers, and set the timeout to that. */ + shortest = ~0; + shortest_is = 0; + if (s->sprt_timer && s->sprt_timer < shortest) + { + shortest = s->sprt_timer; + shortest_is = 0; + } + /*endif*/ + if (s->sse_timer && s->sse_timer < shortest) + { + shortest = s->sse_timer; + shortest_is = 1; + } + /*endif*/ + if (s->call_discrimination_timer && s->call_discrimination_timer < shortest) + { + shortest = s->call_discrimination_timer; + shortest_is = 2; + } + /*endif*/ + + /* If we haven't shrunk shortest from maximum, we have no timer to set, so we stop the timer, + if its set. */ + if (shortest == ~0) + shortest = 0; + /*endif*/ + span_log(&s->logging, SPAN_LOG_FLOW, "Update timer to %lu (%d)\n", shortest, shortest_is); + s->latest_timer = shortest; + return shortest; +} +/*- End of function --------------------------------------------------------*/ + +static span_timestamp_t update_call_discrimination_timer(v150_1_state_t *s, span_timestamp_t timeout) +{ + span_timestamp_t res; + + if (timeout != ~0) + { + s->call_discrimination_timer = timeout; + timeout = select_timer(s); + } + /*endif*/ + res = 0; + if (s->timer_handler) + res = s->timer_handler(s->timer_user_data, timeout); + /*endif*/ + return res; +} +/*- End of function --------------------------------------------------------*/ + +span_timestamp_t update_sse_timer(void *user_data, span_timestamp_t timeout) +{ + v150_1_state_t *s; + span_timestamp_t res; + + s = (v150_1_state_t *) user_data; + if (timeout != ~0) + { + s->sse_timer = timeout; + timeout = select_timer(s); + } + /*endif*/ + res = 0; + if (s->timer_handler) + res = s->timer_handler(s->timer_user_data, timeout); + /*endif*/ + return res; +} +/*- End of function --------------------------------------------------------*/ + +static span_timestamp_t update_sprt_timer(void *user_data, span_timestamp_t timeout) +{ + v150_1_state_t *s; + span_timestamp_t res; + + s = (v150_1_state_t *) user_data; + if (timeout != ~0) + { + s->sprt_timer = timeout; + timeout = select_timer(s); + } + /*endif*/ + res = 0; + if (s->timer_handler) + res = s->timer_handler(s->timer_user_data, timeout); + /*endif*/ + return res; +} +/*- End of function --------------------------------------------------------*/ + SPAN_DECLARE(v150_1_state_t *) v150_1_init(v150_1_state_t *s, - v150_1_tx_packet_handler_t tx_packet_handler, - void *tx_packet_user_data, - v150_1_rx_octet_handler_t rx_octet_handler, - void *rx_octet_handler_user_data, + sprt_tx_packet_handler_t sprt_tx_packet_handler, + void *sprt_tx_packet_handler_user_data, + uint8_t sprt_tx_payload_type, + uint8_t sprt_rx_payload_type, + v150_1_sse_tx_packet_handler_t sse_tx_packet_handler, + void *sse_tx_packet_user_data, + v150_1_timer_handler_t v150_1_timer_handler, + void *v150_1_timer_user_data, + v150_1_rx_data_handler_t rx_data_handler, + void *rx_data_handler_user_data, v150_1_rx_status_report_handler_t rx_status_report_handler, void *rx_status_report_user_data) { - if (tx_packet_handler == NULL || rx_octet_handler == NULL || rx_status_report_handler == NULL) + if (sprt_tx_packet_handler == NULL || rx_data_handler == NULL || rx_status_report_handler == NULL) return NULL; /*endif*/ if (s == NULL) @@ -3400,13 +4418,41 @@ SPAN_DECLARE(v150_1_state_t *) v150_1_init(v150_1_state_t *s, | V150_1_STOP_BITS_1; s->far.parms.data_format_code = -1; - s->tx_packet_handler = tx_packet_handler; - s->tx_packet_user_data = tx_packet_user_data; - s->rx_octet_handler = rx_octet_handler; - s->rx_octet_handler_user_data = rx_octet_handler_user_data; + s->remote_media_state = V150_1_MEDIA_STATE_INITIAL_AUDIO; + s->local_media_state = V150_1_MEDIA_STATE_INITIAL_AUDIO; + + s->call_discrimination_timeout = V150_1_CALL_DISCRIMINATION_DEFAULT_TIMEOUT; + + s->near.parms.sprt_subsession_id = 0; + s->near.parms.sprt_payload_type = sprt_tx_payload_type; + s->far.parms.sprt_payload_type = sprt_rx_payload_type; + + s->rx_data_handler = rx_data_handler; + s->rx_data_handler_user_data = rx_data_handler_user_data; s->rx_status_report_handler = rx_status_report_handler; s->rx_status_report_user_data = rx_status_report_user_data; + s->timer_handler = v150_1_timer_handler; + s->timer_user_data = v150_1_timer_user_data; + + v150_1_sse_init(s, + sse_tx_packet_handler, + sse_tx_packet_user_data); + + sprt_init(&s->sprt, + s->near.parms.sprt_subsession_id, + s->near.parms.sprt_payload_type, + s->far.parms.sprt_payload_type, + NULL /* Use default params */, + sprt_tx_packet_handler, + sprt_tx_packet_handler_user_data, + process_rx_sprt_msg, + s, + update_sprt_timer, + s, + sprt_status_handler, + s); + return s; } /*- End of function --------------------------------------------------------*/ diff --git a/src/v150_1_local.h b/src/v150_1_local.h new file mode 100644 index 00000000..58d04aff --- /dev/null +++ b/src/v150_1_local.h @@ -0,0 +1,36 @@ +/* + * SpanDSP - a series of DSP components for telephony + * + * v150_1_local.h - V.150.1 + * + * Written by Steve Underwood + * + * Copyright (C) 2023 Steve Underwood + * + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +int sse_status_handler(v150_1_state_t *s, int status); + +span_timestamp_t update_sse_timer(void *user_data, span_timestamp_t timeout); + +int v150_1_sse_timer_expired(v150_1_state_t *s, span_timestamp_t now); + +void v150_1_sse_init(v150_1_state_t *s, + v150_1_sse_tx_packet_handler_t tx_packet_handler, + void *tx_packet_user_data); + +/*- End of file ------------------------------------------------------------*/ diff --git a/src/v150_1_sse.c b/src/v150_1_sse.c index 90a7b73d..2d1408e3 100644 --- a/src/v150_1_sse.c +++ b/src/v150_1_sse.c @@ -1,12 +1,13 @@ /* * SpanDSP - a series of DSP components for telephony * - * v150_1_sse.c - An implementation of the SSE protocol defined in V.150.1 - * Annex C, less the packet exchange part + * v150_1_sse.c - An implementation of the state signaling events (SSE), + * protocol defined in V.150.1 Annex C, less the packet + * exchange part * * Written by Steve Underwood * - * Copyright (C) 2022 Steve Underwood + * Copyright (C) 2022, 2023 Steve Underwood * * All rights reserved. * @@ -39,22 +40,30 @@ #include #endif +#define SPANDSP_FULLY_DEFINE_SPRT_STATE_T + #include "spandsp/telephony.h" #include "spandsp/alloc.h" #include "spandsp/unaligned.h" #include "spandsp/logging.h" #include "spandsp/async.h" +#include "spandsp/sprt.h" +#include "spandsp/v150_1.h" #include "spandsp/v150_1_sse.h" #include "spandsp/private/logging.h" +#include "spandsp/private/sprt.h" #include "spandsp/private/v150_1_sse.h" +#include "spandsp/private/v150_1.h" + +#include "v150_1_local.h" /* If the explicit acknowledgement procedure is being used for a call, the endpoints shall execute the following procedures. When an endpoint's MoIP application goes to a new mode, it: - sends an SSE message containing the current value of the variables lcl_mode and rmt_mode + sends an SSE message containing the current value of the variables local_media_state and remote_media_state to the other endpoint, with the must respond flag set to FALSE sets counter n0 to the value n0count sets timer t0 to t0interval (even if it was non-zero) @@ -66,7 +75,7 @@ When an endpoint's MoIP application goes to a new mode, it: and counter n0 is not equal to 0 and - the value of lcl_mode is not equal to the value of rmt_ack + the value of local_media_state is not equal to the value of remote_ack then The endpoint sends an SSE message to the other endpoint exactly as above except o counter n0 is decremented rather than set to n0count @@ -82,7 +91,7 @@ NOTE - If timer t0 decrements to 0 and counter n0 is equal to zero, no action is and counter n0 is equal to 0 and - the value of lcl_mode is not equal to the value of rmt_ack. + the value of local_media_state is not equal to the value of remote_ack. then The endpoint sends an SSE message to the other endpoint exactly as first given above except o counter n0 is not decremented, it is left equal to zero @@ -96,499 +105,144 @@ Upon receipt of an SSE message from the other endpoint then the endpoint ignores the received message else - set the values of rmt_mode and rmt_ack to the values in the message + set the values of remote_media_state and remote_ack to the values in the message if the message contained a new value for the remote endpoint's mode then or the message's must respond flag is set to TRUE then the endpoint sends an SSE message to the other endpoint exactly as first given above, except counter n0 and timers t0 and t1 are not (re)set. -*/ - -/* - telephone network - ^ - | - | - v - +-----------------------------------+ - | | - | Signal processing entity | - | | - +-----------------------------------+ - | ^ - | | - Signal list 1 | | Signal list 2 - | | - v | - +-----------------------------------+ Signal list 5 +-----------------------------------+ - | | ----------------->| | - | SSE protocol state machine (P) | | Gateway state machine (s,s') | - | |<------------------| | - +-----------------------------------+ Signal list 6 +-----------------------------------+ - | ^ - | | - Signal list 3 | | Signal list 4 - | | - v | - +-----------------------------------+ - | | - | IP network processor | - | | - +-----------------------------------+ - ^ - | - | - v - IP network -*/ - -#if 0 - -int generic_macro(int local, int remote, int cause) -{ -} - - switch (s->lcl_mode) - { - case V150_1_SSE_SIGNAL_A_STATE: - switch (s->rmt_mode) - { - case V150_1_SSE_SIGNAL_A_STATE: - /* Figure 26/V.150.1 to 31/V.150.1 */ - switch (signal) - { - case V150_1_SSE_SIGNAL_2100HZ: - if (s->vbd_available && s->vbd_preferred) - { - s->local_mode = V150_1_SSE_SIGNAL_V_STATE; - generic_macro(s->local_mode, s->rmt_mode, signal); - send ANS or ANSam - } - else - { - block_tone(); - } - /*endif*/ - break; - case V150_1_SSE_SIGNAL_ANS: - if (s->vbd_available && s->vbd_preferred) - { - s->local_mode = V150_1_SSE_SIGNAL_V_STATE; - generic_macro(s->local_mode, s->rmt_mode, signal); - send ANS - } - else - { - send RFC4733_ANS - conceal_modem(); - } - /*endif*/ - break; - case V150_1_SSE_SIGNAL_ANSAM: - if (s->vbd_available && s->vbd_preferred) - { - s->local_mode = V150_1_SSE_SIGNAL_V_STATE; - generic_macro(s->local_mode, s->rmt_mode, signal); - send ANS - } - else - { - send RFC4733_ANSAM - conceal_modem(); - } - /*endif*/ - break; - case V150_1_SSE_SIGNAL_RFC4733_ANS: - case V150_1_SSE_SIGNAL_RFC4733_ANSAM: - send ANS or ANSAM - conceal_modem(); - break; - case V150_1_SSE_SIGNAL_RFC4733_ANS_PR: - case V150_1_SSE_SIGNAL_RFC4733_ANSAM_PR: - send /ANS or /ANSAM - conceal_modem(); - break; - case V150_1_SSE_SIGNAL_ANS: - case V150_1_SSE_SIGNAL_ANSAM: - break; - case V150_1_SSE_SIGNAL_ANS_PR: - case V150_1_SSE_SIGNAL_ANSAM_PR: - break; - case V150_1_SSE_SIGNAL_UNKNOWN: - case V150_1_SSE_SIGNAL_CALL_DISCRIMINATION_TIMEOUT: - if (s->vbd_preferred) - { - s->local_mode = V150_1_SSE_SIGNAL_V_STATE; - generic_macro(s->local_mode, s->rmt_mode, signal); - } - /*endif*/ - break; - case V150_1_SSE_SIGNAL_V: - if (s->vbd_preferred) - { - s->remote_mode = V150_1_SSE_SIGNAL_V_STATE; - s->local_mode = V150_1_SSE_SIGNAL_V_STATE; - generic_macro(s->local_mode, s->rmt_mode, signal); - } - else - { - s->local_mode = V150_1_SSE_SIGNAL_V_STATE; - generic_macro(s->local_mode, s->rmt_mode, signal); - } - /*endif*/ - break; - case V150_1_SSE_SIGNAL_M: - break; - } - /*endswitch*/ - break; - case V150_1_SSE_SIGNAL_F_STATE: - break; - case V150_1_SSE_SIGNAL_I_STATE: - break; - case V150_1_SSE_SIGNAL_M_STATE: - /* Figure 32/V.150.1 */ - switch (signal) - { - case V150_1_SSE_SIGNAL_A: - break; - } - /*endswitch*/ - break; - case V150_1_SSE_SIGNAL_T_STATE: - break; - case V150_1_SSE_SIGNAL_V_STATE: - /* Figure 33/V.150.1 */ - switch (signal) - { - case V150_1_SSE_SIGNAL_A: - break; - } - /*endswitch*/ - break; - } - /*endswitch*/ - break; - case V150_1_SSE_SIGNAL_F_STATE: - switch (s->rmt_mode) - { - case V150_1_SSE_SIGNAL_A_STATE: - break; - case V150_1_SSE_SIGNAL_F_STATE: - break; - case V150_1_SSE_SIGNAL_I_STATE: - break; - case V150_1_SSE_SIGNAL_M_STATE: - break; - case V150_1_SSE_SIGNAL_T_STATE: - break; - case V150_1_SSE_SIGNAL_V_STATE: - break; - } - /*endswitch*/ - break; - case V150_1_SSE_SIGNAL_I_STATE: - switch (s->rmt_mode) - { - case V150_1_SSE_SIGNAL_A_STATE: - break; - case V150_1_SSE_SIGNAL_F_STATE: - break; - case V150_1_SSE_SIGNAL_I_STATE: - break; - case V150_1_SSE_SIGNAL_M_STATE: - break; - case V150_1_SSE_SIGNAL_T_STATE: - break; - case V150_1_SSE_SIGNAL_V_STATE: - break; - } - /*endswitch*/ - break; - case V150_1_SSE_SIGNAL_M_STATE: - switch (s->rmt_mode) - { - case V150_1_SSE_SIGNAL_A_STATE: - /* Figure 34/V.150.1 */ - switch (signal) - { - case V150_1_SSE_SIGNAL_A: - break; - case V150_1_SSE_SIGNAL_M: - break; - case V150_1_SSE_SIGNAL_V: - break; - } - /*endswitch*/ - break; - case V150_1_SSE_SIGNAL_F_STATE: - break; - case V150_1_SSE_SIGNAL_I_STATE: - break; - case V150_1_SSE_SIGNAL_M_STATE: - /* Figure 35/V.150.1 */ - switch (signal) - { - case V150_1_SSE_SIGNAL_JM: - break; - case V150_1_SSE_SIGNAL_V: - break; - } - /*endswitch*/ - break; - case V150_1_SSE_SIGNAL_T_STATE: - break; - case V150_1_SSE_SIGNAL_V_STATE: - /* Figure 36/V.150.1 */ - switch (signal) - { - case V150_1_SSE_SIGNAL_A: - break; - case V150_1_SSE_SIGNAL_M: - break; - case V150_1_SSE_SIGNAL_V: - break; - } - /*endswitch*/ - break; - } - /*endswitch*/ - break; - case V150_1_SSE_SIGNAL_T_STATE: - switch (s->rmt_mode) - { - case V150_1_SSE_SIGNAL_A_STATE: - break; - case V150_1_SSE_SIGNAL_F_STATE: - break; - case V150_1_SSE_SIGNAL_I_STATE: - break; - case V150_1_SSE_SIGNAL_M_STATE: - break; - case V150_1_SSE_SIGNAL_T_STATE: - break; - case V150_1_SSE_SIGNAL_V_STATE: - break; - } - /*endswitch*/ - break; - case V150_1_SSE_SIGNAL_V_STATE: - switch (s->rmt_mode) - { - case V150_1_SSE_SIGNAL_A_STATE: - /* Figure 37/V.150.1 */ - switch (signal) - { - case V150_1_SSE_SIGNAL_A: - break; - case V150_1_SSE_SIGNAL_M: - break; - case V150_1_SSE_SIGNAL_V: - break; - } - /*endswitch*/ - break; - case V150_1_SSE_SIGNAL_F_STATE: - break; - case V150_1_SSE_SIGNAL_I_STATE: - break; - case V150_1_SSE_SIGNAL_M_STATE: - /* Figure 38/V.150.1 */ - switch (signal) - { - case V150_1_SSE_SIGNAL_A: - break; - case V150_1_SSE_SIGNAL_V: - break; - } - /*endswitch*/ - break; - case V150_1_SSE_SIGNAL_T_STATE: - break; - case V150_1_SSE_SIGNAL_V_STATE: - /* Figure 39/V.150.1 */ - switch (signal) - { - case V150_1_SSE_SIGNAL_M: - break; - case V150_1_SSE_SIGNAL_CM: - break; - case V150_1_SSE_SIGNAL_RFC4733_ANS_PR: - case V150_1_SSE_SIGNAL_RFC4733_ANSAM_PR: - break; - case V150_1_SSE_SIGNAL_ANS_PR: - case V150_1_SSE_SIGNAL_ANSAM_PR: - break; - case V150_1_SSE_SIGNAL_RFC4733_ANS: - case V150_1_SSE_SIGNAL_RFC4733_ANSAM: - break; - } - /*endswitch*/ - break; - } - /*endswitch*/ - break; - } - /*endswitch*/ -#endif -static int v150_1_sse_tx_modem_relay_packet(v150_1_sse_state_t *s, int x, int ric, int ricinfo); -static int v150_1_sse_tx_fax_relay_packet(v150_1_sse_state_t *s, int x, int ric, int ricinfo); -SPAN_DECLARE(const char *) v150_1_sse_media_state_to_str(int state) -{ - const char *res; +V.150.1 uses the terms "media states" and "SSE events". These SSE events are just changes of the media state. +So, media states map 1:1 to SSE events. +*/ - res = "unknown"; - switch (state) - { - case V150_1_SSE_MEDIA_STATE_INITIAL_AUDIO: - res = "Initial audio"; - break; - case V150_1_SSE_MEDIA_STATE_VOICE_BAND_DATA: - res = "Voice band data"; - break; - case V150_1_SSE_MEDIA_STATE_MODEM_RELAY: - res = "Modem relay"; - break; - case V150_1_SSE_MEDIA_STATE_FAX_RELAY: - res = "Fax relay"; - break; - case V150_1_SSE_MEDIA_STATE_TEXT_RELAY: - res = "Text relay"; - break; - case V150_1_SSE_MEDIA_STATE_TEXT_PROBE: - res = "Text probe"; - break; - } - /*endswitch*/ - return res; -} -/*- End of function --------------------------------------------------------*/ +static int v150_1_sse_tx_modem_relay_packet(v150_1_state_t *s, int x, int ric, int ricinfo); +static int v150_1_sse_tx_fax_relay_packet(v150_1_state_t *s, int x, int ric, int ricinfo); -SPAN_DECLARE(const char *) v150_1_sse_ric_to_str(int ric) +SPAN_DECLARE(const char *) v150_1_sse_moip_ric_to_str(int ric) { const char *res; res = "unknown"; switch (ric) { - case V150_1_SSE_RIC_V8_CM: + case V150_1_SSE_MOIP_RIC_V8_CM: res = "V.8 CM"; break; - case V150_1_SSE_RIC_V8_JM: + case V150_1_SSE_MOIP_RIC_V8_JM: res = "V.8 JM"; break; - case V150_1_SSE_RIC_V32BIS_AA: + case V150_1_SSE_MOIP_RIC_V32BIS_AA: res = "V.32/V.32bis AA"; break; - case V150_1_SSE_RIC_V32BIS_AC: + case V150_1_SSE_MOIP_RIC_V32BIS_AC: res = "V.32/V.32bis AC"; break; - case V150_1_SSE_RIC_V22BIS_USB1: + case V150_1_SSE_MOIP_RIC_V22BIS_USB1: res = "V.22bis USB1"; break; - case V150_1_SSE_RIC_V22BIS_SB1: + case V150_1_SSE_MOIP_RIC_V22BIS_SB1: res = "V.22bis SB1"; break; - case V150_1_SSE_RIC_V22BIS_S1: + case V150_1_SSE_MOIP_RIC_V22BIS_S1: res = "V.22bis S1"; break; - case V150_1_SSE_RIC_V21_CH2: + case V150_1_SSE_MOIP_RIC_V21_CH2: res = "V.21 Ch2"; break; - case V150_1_SSE_RIC_V21_CH1: + case V150_1_SSE_MOIP_RIC_V21_CH1: res = "V.21 Ch1"; break; - case V150_1_SSE_RIC_V23_HIGH_CHANNEL: + case V150_1_SSE_MOIP_RIC_V23_HIGH_CHANNEL: res = "V.23 high channel"; break; - case V150_1_SSE_RIC_V23_LOW_CHANNEL: + case V150_1_SSE_MOIP_RIC_V23_LOW_CHANNEL: res = "V.23 low channel"; break; - case V150_1_SSE_RIC_TONE_2225HZ: + case V150_1_SSE_MOIP_RIC_TONE_2225HZ: res = "2225Hz tone"; break; - case V150_1_SSE_RIC_V21_CH2_HDLC_FLAGS: + case V150_1_SSE_MOIP_RIC_V21_CH2_HDLC_FLAGS: res = "V.21 Ch2 HDLC flags"; break; - case V150_1_SSE_RIC_INDETERMINATE_SIGNAL: + case V150_1_SSE_MOIP_RIC_INDETERMINATE_SIGNAL: res = "Indeterminate signal"; break; - case V150_1_SSE_RIC_SILENCE: + case V150_1_SSE_MOIP_RIC_SILENCE: res = "Silence"; break; - case V150_1_SSE_RIC_CNG: + case V150_1_SSE_MOIP_RIC_CNG: res = "CNG"; break; - case V150_1_SSE_RIC_VOICE: + case V150_1_SSE_MOIP_RIC_VOICE: res = "Voice"; break; - case V150_1_SSE_RIC_TIMEOUT: + case V150_1_SSE_MOIP_RIC_TIMEOUT: res = "Time-out"; break; - case V150_1_SSE_RIC_P_STATE_TRANSITION: + case V150_1_SSE_MOIP_RIC_P_STATE_TRANSITION: res = "P' state transition"; break; - case V150_1_SSE_RIC_CLEARDOWN: + case V150_1_SSE_MOIP_RIC_CLEARDOWN: res = "Cleardown"; break; - case V150_1_SSE_RIC_ANS_CED: + case V150_1_SSE_MOIP_RIC_ANS_CED: res = "CED"; break; - case V150_1_SSE_RIC_ANSAM: + case V150_1_SSE_MOIP_RIC_ANSAM: res = "ANSam"; break; - case V150_1_SSE_RIC_ANS_PR: + case V150_1_SSE_MOIP_RIC_ANS_PR: res = "/ANS"; break; - case V150_1_SSE_RIC_ANSAM_PR: + case V150_1_SSE_MOIP_RIC_ANSAM_PR: res = "/ANSam"; break; - case V150_1_SSE_RIC_V92_QC1A: + case V150_1_SSE_MOIP_RIC_V92_QC1A: res = "V.92 QC1a"; break; - case V150_1_SSE_RIC_V92_QC1D: + case V150_1_SSE_MOIP_RIC_V92_QC1D: res = "V.92 QC1d"; break; - case V150_1_SSE_RIC_V92_QC2A: + case V150_1_SSE_MOIP_RIC_V92_QC2A: res = "V.92 QC2a"; break; - case V150_1_SSE_RIC_V92_QC2D: + case V150_1_SSE_MOIP_RIC_V92_QC2D: res = "V.92 QC2d"; break; - case V150_1_SSE_RIC_V8BIS_CRE: + case V150_1_SSE_MOIP_RIC_V8BIS_CRE: res = "V.8bis Cre"; break; - case V150_1_SSE_RIC_V8BIS_CRD: + case V150_1_SSE_MOIP_RIC_V8BIS_CRD: res = "V.8bis CRd"; break; - case V150_1_SSE_RIC_TIA825A_45_45BPS: + case V150_1_SSE_MOIP_RIC_TIA825A_45_45BPS: res = "TIA825A 45.45BPS"; break; - case V150_1_SSE_RIC_TIA825A_50BPS: + case V150_1_SSE_MOIP_RIC_TIA825A_50BPS: res = "TIA825A 50BPS"; break; - case V150_1_SSE_RIC_EDT: + case V150_1_SSE_MOIP_RIC_EDT: res = "EDT"; break; - case V150_1_SSE_RIC_BELL103: + case V150_1_SSE_MOIP_RIC_BELL103: res = "Bell 103"; break; - case V150_1_SSE_RIC_V21_TEXT_TELEPHONE: + case V150_1_SSE_MOIP_RIC_V21_TEXT_TELEPHONE: res = "Text telephone"; break; - case V150_1_SSE_RIC_V23_MINITEL: + case V150_1_SSE_MOIP_RIC_V23_MINITEL: res = "V.23 Minitel"; break; - case V150_1_SSE_RIC_V18_TEXT_TELEPHONE: + case V150_1_SSE_MOIP_RIC_V18_TEXT_TELEPHONE: res = "Text telephone"; break; - case V150_1_SSE_RIC_V18_DTMF_TEXT_RELAY: + case V150_1_SSE_MOIP_RIC_V18_DTMF_TEXT_RELAY: res = "Text relay"; break; - case V150_1_SSE_RIC_CTM: + case V150_1_SSE_MOIP_RIC_CTM: res = "CTM"; break; } @@ -597,23 +251,23 @@ SPAN_DECLARE(const char *) v150_1_sse_ric_to_str(int ric) } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(const char *) v150_1_sse_timeout_reason_to_str(int ric) +SPAN_DECLARE(const char *) v150_1_sse_timeout_reason_to_str(int reason) { const char *res; res = "unknown"; - switch (ric) + switch (reason) { - case V150_1_SSE_RIC_INFO_TIMEOUT_NULL: + case V150_1_SSE_MOIP_RIC_INFO_TIMEOUT_NULL: res = "NULL"; break; - case V150_1_SSE_RIC_INFO_TIMEOUT_CALL_DISCRIMINATION_TIMEOUT: + case V150_1_SSE_MOIP_RIC_INFO_TIMEOUT_CALL_DISCRIMINATION_TIMEOUT: res = "Call discrimination timeout"; break; - case V150_1_SSE_RIC_INFO_TIMEOUT_IP_TLP: + case V150_1_SSE_MOIP_RIC_INFO_TIMEOUT_IP_TLP: res = "IP-TLP"; break; - case V150_1_SSE_RIC_INFO_TIMEOUT_SSE_EXPLICIT_ACK_TIMEOUT: + case V150_1_SSE_MOIP_RIC_INFO_TIMEOUT_SSE_EXPLICIT_ACK_TIMEOUT: res = "TSSE explicit acknowledgement timeout"; break; } @@ -622,36 +276,41 @@ SPAN_DECLARE(const char *) v150_1_sse_timeout_reason_to_str(int ric) } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(const char *) v150_1_sse_cleardown_reason_to_str(int ric) +SPAN_DECLARE(const char *) v150_1_sse_cleardown_reason_to_str(int reason) { const char *res; res = "unknown"; - switch (ric) + switch (reason) { - case V150_1_SSE_RIC_INFO_CLEARDOWN_UNKNOWN: + case V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_UNKNOWN: res = "Unknown/unspecified"; break; - case V150_1_SSE_RIC_INFO_CLEARDOWN_PHYSICAL_LAYER_RELEASE: - res = "Physical Layer Release"; // (i.e. data pump release)"; + case V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_PHYSICAL_LAYER_RELEASE: + /* Data pump release */ + res = "Physical Layer Release"; break; - case V150_1_SSE_RIC_INFO_CLEARDOWN_LINK_LAYER_DISCONNECT: - res = "Link Layer Disconnect"; // (i.e. receiving a V.42 DISC frame)"; + case V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_LINK_LAYER_DISCONNECT: + /* Received a V.42 DISC frame */ + res = "Link Layer Disconnect"; break; - case V150_1_SSE_RIC_INFO_CLEARDOWN_COMPRESSION_DISCONNECT: + case V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_COMPRESSION_DISCONNECT: res = "Data compression disconnect"; break; - case V150_1_SSE_RIC_INFO_CLEARDOWN_ABORT: - res = "Abort"; // (i.e. termination due to Abort procedure as specified in SDL)"; + case V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_ABORT: + /* Termination due to Abort procedure as specified in SDL */ + res = "Abort"; break; - case V150_1_SSE_RIC_INFO_CLEARDOWN_ON_HOOK: - res = "On-hook"; // (i.e. when gateway receives On-hook signal from an end-point device)"; + case V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_ON_HOOK: + /* When gateway receives On-hook signal from an end-point device */ + res = "On-hook"; break; - case V150_1_SSE_RIC_INFO_CLEARDOWN_NETWORK_LAYER_TERMINATION: + case V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_NETWORK_LAYER_TERMINATION: res = "Network layer termination"; break; - case V150_1_SSE_RIC_INFO_CLEARDOWN_ADMINISTRATIVE: - res = "Administrative"; // (i.e., operator action at gateway)"; + case V150_1_SSE_MOIP_RIC_INFO_CLEARDOWN_ADMINISTRATIVE: + /* Operator action at gateway */ + res = "Administrative"; break; } /*endswitch*/ @@ -659,12 +318,48 @@ SPAN_DECLARE(const char *) v150_1_sse_cleardown_reason_to_str(int ric) } /*- End of function --------------------------------------------------------*/ -static int update_timer(v150_1_sse_state_t *s) +SPAN_DECLARE(const char *) v150_1_sse_status_to_str(int status) +{ + const char *res; + + res = "unknown"; + switch (status) + { + case V150_1_SSE_STATUS_V8_CM_RECEIVED: + res = "V.8 CM received"; + break; + case V150_1_SSE_STATUS_V8_JM_RECEIVED: + res = "V.8 JM received"; + break; + case V150_1_SSE_STATUS_AA_RECEIVED: + res = "V.32 AA received"; + break; + case V150_1_SSE_STATUS_V8_CM_RECEIVED_FAX: + res = "Fax V.8 CM received"; + break; + case V150_1_SSE_STATUS_V8_JM_RECEIVED_FAX: + res = "Fax V.8 JM received"; + break; + case V150_1_SSE_STATUS_AA_RECEIVED_FAX: + res = "Fax AA received"; + break; + case V150_1_SSE_STATUS_CLEARDOWN: + res = "cleardown"; + break; + } + /*endif*/ + return res; +} +/*- End of function --------------------------------------------------------*/ + +static int update_timer(v150_1_state_t *s) { span_timestamp_t shortest; int shortest_is; + v150_1_sse_state_t *sse; - if (s->immediate_timer) + sse = &s->sse; + if (sse->immediate_timer) { shortest = 1; shortest_is = 4; @@ -675,33 +370,33 @@ static int update_timer(v150_1_sse_state_t *s) shortest = ~0; shortest_is = 0; - if (s->ack_timer_t0 && s->ack_timer_t0 < shortest) + if (sse->ack_timer_t0 && sse->ack_timer_t0 < shortest) { - shortest = s->ack_timer_t0; + shortest = sse->ack_timer_t0; shortest_is = 0; } /*endif*/ - if (s->ack_timer_t1 && s->ack_timer_t1 < shortest) + if (sse->ack_timer_t1 && sse->ack_timer_t1 < shortest) { - shortest = s->ack_timer_t1; + shortest = sse->ack_timer_t1; shortest_is = 1; } /*endif*/ - if (s->repetition_timer && s->repetition_timer < shortest) + if (sse->repetition_timer && sse->repetition_timer < shortest) { - shortest = s->repetition_timer; + shortest = sse->repetition_timer; shortest_is = 2; } /*endif*/ - if (s->recovery_timer_t1 && s->recovery_timer_t1 < shortest) + if (sse->recovery_timer_t1 && sse->recovery_timer_t1 < shortest) { - shortest = s->recovery_timer_t1; + shortest = sse->recovery_timer_t1; shortest_is = 3; } /*endif*/ - if (s->recovery_timer_t2 && s->recovery_timer_t2 < shortest) + if (sse->recovery_timer_t2 && sse->recovery_timer_t2 < shortest) { - shortest = s->recovery_timer_t2; + shortest = sse->recovery_timer_t2; shortest_is = 4; } /*endif*/ @@ -713,74 +408,72 @@ static int update_timer(v150_1_sse_state_t *s) } /*endif*/ span_log(&s->logging, SPAN_LOG_FLOW, "Update timer to %lu (%d)\n", shortest, shortest_is); - s->latest_timer = shortest; - if (s->timer_handler) - s->timer_handler(s->timer_user_data, s->latest_timer); - /*endif*/ + sse->latest_timer = shortest; + update_sse_timer(s, sse->latest_timer); return 0; } /*- End of function --------------------------------------------------------*/ -static void log_v8_ric_info(v150_1_sse_state_t *s, int ric_info) +static void log_v8_ric_info(v150_1_state_t *s, int ric_info) { - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_PCM_MODE)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_PCM_MODE)) span_log(&s->logging, SPAN_LOG_FLOW, " PCM mode\n"); /*endif*/ - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_V34_DUPLEX)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_V34_DUPLEX)) span_log(&s->logging, SPAN_LOG_FLOW, " V.34 duplex\n"); /*endif*/ - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_V34_HALF_DUPLEX)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_V34_HALF_DUPLEX)) span_log(&s->logging, SPAN_LOG_FLOW, " V.34 half duplex\n"); /*endif*/ - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_V32BIS)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_V32BIS)) span_log(&s->logging, SPAN_LOG_FLOW, " V.32/V32.bis\n"); /*endif*/ - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_V22BIS)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_V22BIS)) span_log(&s->logging, SPAN_LOG_FLOW, " V.22/V22.bis\n"); /*endif*/ - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_V17)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_V17)) span_log(&s->logging, SPAN_LOG_FLOW, " V.17\n"); /*endif*/ - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_V29)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_V29)) span_log(&s->logging, SPAN_LOG_FLOW, " V.29 half-duplex\n"); /*endif*/ - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_V27TER)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_V27TER)) span_log(&s->logging, SPAN_LOG_FLOW, " V.27ter\n"); /*endif*/ - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_V26TER)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_V26TER)) span_log(&s->logging, SPAN_LOG_FLOW, " V.26ter\n"); /*endif*/ - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_V26BIS)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_V26BIS)) span_log(&s->logging, SPAN_LOG_FLOW, " V.26bis\n"); /*endif*/ - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_V23_DUPLEX)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_V23_DUPLEX)) span_log(&s->logging, SPAN_LOG_FLOW, " V.23 duplex\n"); /*endif*/ - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_V23_HALF_DUPLEX)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_V23_HALF_DUPLEX)) span_log(&s->logging, SPAN_LOG_FLOW, " V.23 half-duplex\n"); /*endif*/ - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_V21)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_V21)) span_log(&s->logging, SPAN_LOG_FLOW, " V.21\n"); /*endif*/ - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_V90_V92_ANALOGUE)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_V90_V92_ANALOGUE)) span_log(&s->logging, SPAN_LOG_FLOW, " V.90/V.92 analogue\n"); /*endif*/ - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_V90_V92_DIGITAL)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_V90_V92_DIGITAL)) span_log(&s->logging, SPAN_LOG_FLOW, " V.90/V.92 digital\n"); /*endif*/ - if ((ric_info & V150_1_SSE_RIC_INFO_V8_CM_V91)) + if ((ric_info & V150_1_SSE_MOIP_RIC_INFO_V8_CM_V91)) span_log(&s->logging, SPAN_LOG_FLOW, " V.91\n"); /*endif*/ } /*- End of function --------------------------------------------------------*/ -static int rx_initial_audio_packet(v150_1_sse_state_t *s, const uint8_t pkt[], int len) +static int rx_initial_audio_packet(v150_1_state_t *s, const uint8_t pkt[], int len) { - if (s->rmt_mode != V150_1_SSE_MEDIA_STATE_INITIAL_AUDIO) + if (s->remote_media_state != V150_1_MEDIA_STATE_INITIAL_AUDIO) { /* Even if we don't support audio, C.5.3.2 says we need to make this our local state */ - s->lcl_mode = V150_1_SSE_MEDIA_STATE_INITIAL_AUDIO; - s->rmt_mode = V150_1_SSE_MEDIA_STATE_INITIAL_AUDIO; + s->local_media_state = V150_1_MEDIA_STATE_INITIAL_AUDIO; + s->remote_media_state = V150_1_MEDIA_STATE_INITIAL_AUDIO; } else { @@ -790,14 +483,14 @@ static int rx_initial_audio_packet(v150_1_sse_state_t *s, const uint8_t pkt[], i } /*- End of function --------------------------------------------------------*/ -static int rx_voice_band_data_packet(v150_1_sse_state_t *s, const uint8_t pkt[], int len) +static int rx_voice_band_data_packet(v150_1_state_t *s, const uint8_t pkt[], int len) { - if (s->rmt_mode != V150_1_SSE_MEDIA_STATE_VOICE_BAND_DATA) + if (s->remote_media_state != V150_1_MEDIA_STATE_VOICE_BAND_DATA) { /* Whether we change to VBD or plain audio is our choice. C.5.3.2. */ - //s->lcl_mode = V150_1_SSE_MEDIA_STATE_INITIAL_AUDIO; - s->lcl_mode = V150_1_SSE_MEDIA_STATE_VOICE_BAND_DATA; - s->rmt_mode = V150_1_SSE_MEDIA_STATE_VOICE_BAND_DATA; + //s->local_media_state = V150_1_MEDIA_STATE_INITIAL_AUDIO; + s->local_media_state = V150_1_MEDIA_STATE_VOICE_BAND_DATA; + s->remote_media_state = V150_1_MEDIA_STATE_VOICE_BAND_DATA; } else { @@ -807,7 +500,7 @@ static int rx_voice_band_data_packet(v150_1_sse_state_t *s, const uint8_t pkt[], } /*- End of function --------------------------------------------------------*/ -static int rx_modem_relay_packet(v150_1_sse_state_t *s, const uint8_t pkt[], int len) +static int rx_modem_relay_packet(v150_1_state_t *s, const uint8_t pkt[], int len) { int res; int ric; @@ -820,15 +513,24 @@ static int rx_modem_relay_packet(v150_1_sse_state_t *s, const uint8_t pkt[], int SPAN_LOG_FLOW, "%sReason %s - 0x%x\n", ((pkt[0] >> 1) & 0x01) ? "Force response. " : "", - v150_1_sse_ric_to_str(ric), + v150_1_sse_moip_ric_to_str(ric), ric_info); - if (s->rmt_mode != V150_1_SSE_MEDIA_STATE_MODEM_RELAY) + if (s->remote_media_state != V150_1_MEDIA_STATE_MODEM_RELAY) { /* Whether we change to modem relay, VBD or plain audio is our choice. C.5.3.2. */ - //s->lcl_mode = V150_1_SSE_MEDIA_STATE_INITIAL_AUDIO; - //s->lcl_mode = V150_1_SSE_MEDIA_STATE_VOICE_BAND_DATA; - s->lcl_mode = V150_1_SSE_MEDIA_STATE_MODEM_RELAY; - s->rmt_mode = V150_1_SSE_MEDIA_STATE_MODEM_RELAY; + if (s->cdscselect == V150_1_CDSCSELECT_VBD_SELECT + || + s->cdscselect == V150_1_CDSCSELECT_MIXED) + { + s->local_media_state = V150_1_MEDIA_STATE_VOICE_BAND_DATA; + s->remote_media_state = V150_1_MEDIA_STATE_VOICE_BAND_DATA; + } + else + { + s->local_media_state = V150_1_MEDIA_STATE_MODEM_RELAY; + s->remote_media_state = V150_1_MEDIA_STATE_MODEM_RELAY; + } + /*endif*/ } else { @@ -836,71 +538,65 @@ static int rx_modem_relay_packet(v150_1_sse_state_t *s, const uint8_t pkt[], int /*endif*/ switch (ric) { - case V150_1_SSE_RIC_V8_CM: + case V150_1_SSE_MOIP_RIC_V8_CM: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.8 (CM) detection\n"); log_v8_ric_info(s, ric_info); /* We need to respond with a P' */ - v150_1_sse_tx_modem_relay_packet(s, 0, V150_1_SSE_RIC_P_STATE_TRANSITION, 0); - if (s->status_handler) - res = s->status_handler(s->status_user_data, V150_1_SSE_STATUS_V8_CM_RECEIVED); - /*endif*/ + v150_1_sse_tx_modem_relay_packet(s, 0, V150_1_SSE_MOIP_RIC_P_STATE_TRANSITION, 0); + res = sse_status_handler(s, V150_1_SSE_STATUS_V8_CM_RECEIVED); break; - case V150_1_SSE_RIC_V8_JM: + case V150_1_SSE_MOIP_RIC_V8_JM: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.8 (JM) detection\n"); log_v8_ric_info(s, ric_info); - if (s->status_handler) - res = s->status_handler(s->status_user_data, V150_1_SSE_STATUS_V8_JM_RECEIVED); - /*endif*/ + res = sse_status_handler(s, V150_1_SSE_STATUS_V8_JM_RECEIVED); break; - case V150_1_SSE_RIC_V32BIS_AA: + case V150_1_SSE_MOIP_RIC_V32BIS_AA: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.32bis detection\n"); /* We need to respond with a P' */ - v150_1_sse_tx_modem_relay_packet(s, 0, V150_1_SSE_RIC_P_STATE_TRANSITION, 0); - if (s->status_handler) - res = s->status_handler(s->status_user_data, V150_1_SSE_STATUS_AA_RECEIVED); - /*endif*/ + v150_1_sse_tx_modem_relay_packet(s, 0, V150_1_SSE_MOIP_RIC_P_STATE_TRANSITION, 0); + res = sse_status_handler(s, V150_1_SSE_STATUS_AA_RECEIVED); break; - case V150_1_SSE_RIC_V32BIS_AC: + case V150_1_SSE_MOIP_RIC_V32BIS_AC: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.32bis detection\n"); break; - case V150_1_SSE_RIC_V22BIS_USB1: + case V150_1_SSE_MOIP_RIC_V22BIS_USB1: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.22bis detection\n"); break; - case V150_1_SSE_RIC_V22BIS_SB1: + case V150_1_SSE_MOIP_RIC_V22BIS_SB1: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.22bis detection\n"); break; - case V150_1_SSE_RIC_V22BIS_S1: + case V150_1_SSE_MOIP_RIC_V22BIS_S1: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.22bis detection\n"); break; - case V150_1_SSE_RIC_V21_CH2: + case V150_1_SSE_MOIP_RIC_V21_CH2: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.21 detection\n"); break; - case V150_1_SSE_RIC_V21_CH1: + case V150_1_SSE_MOIP_RIC_V21_CH1: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.21 detection\n"); break; - case V150_1_SSE_RIC_V23_HIGH_CHANNEL: + case V150_1_SSE_MOIP_RIC_V23_HIGH_CHANNEL: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.23 detection\n"); break; - case V150_1_SSE_RIC_V23_LOW_CHANNEL: + case V150_1_SSE_MOIP_RIC_V23_LOW_CHANNEL: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.23 detection\n"); break; - case V150_1_SSE_RIC_TONE_2225HZ: + case V150_1_SSE_MOIP_RIC_TONE_2225HZ: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on 2225Hz tone detection\n"); break; - case V150_1_SSE_RIC_V21_CH2_HDLC_FLAGS: + case V150_1_SSE_MOIP_RIC_V21_CH2_HDLC_FLAGS: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.21 flags detection\n"); break; - case V150_1_SSE_RIC_INDETERMINATE_SIGNAL: + case V150_1_SSE_MOIP_RIC_INDETERMINATE_SIGNAL: break; - case V150_1_SSE_RIC_SILENCE: + case V150_1_SSE_MOIP_RIC_SILENCE: break; - case V150_1_SSE_RIC_CNG: + case V150_1_SSE_MOIP_RIC_CNG: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on CNG detection\n"); break; - case V150_1_SSE_RIC_VOICE: + case V150_1_SSE_MOIP_RIC_VOICE: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on voice detection\n"); break; - case V150_1_SSE_RIC_TIMEOUT: + case V150_1_SSE_MOIP_RIC_TIMEOUT: span_log(&s->logging, SPAN_LOG_FLOW, "Timeout %d - %s - 0x%x\n", @@ -908,64 +604,62 @@ static int rx_modem_relay_packet(v150_1_sse_state_t *s, const uint8_t pkt[], int v150_1_sse_timeout_reason_to_str(ric_info >> 8), ric_info & 0xFF); break; - case V150_1_SSE_RIC_P_STATE_TRANSITION: + case V150_1_SSE_MOIP_RIC_P_STATE_TRANSITION: span_log(&s->logging, SPAN_LOG_FLOW, "P' received\n"); break; - case V150_1_SSE_RIC_CLEARDOWN: + case V150_1_SSE_MOIP_RIC_CLEARDOWN: span_log(&s->logging, SPAN_LOG_FLOW, "Cleardown %d - %s\n", (ric_info >> 8), v150_1_sse_cleardown_reason_to_str(ric_info >> 8)); - if (s->status_handler) - res = s->status_handler(s->status_user_data, V150_1_SSE_STATUS_CLEARDOWN); - /*endif*/ + res = sse_status_handler(s, V150_1_SSE_STATUS_CLEARDOWN); break; - case V150_1_SSE_RIC_ANS_CED: + case V150_1_SSE_MOIP_RIC_ANS_CED: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on ANS/CED detection\n"); break; - case V150_1_SSE_RIC_ANSAM: + case V150_1_SSE_MOIP_RIC_ANSAM: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on ANSam detection\n"); break; - case V150_1_SSE_RIC_ANS_PR: + case V150_1_SSE_MOIP_RIC_ANS_PR: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on /ANS detection\n"); break; - case V150_1_SSE_RIC_ANSAM_PR: + case V150_1_SSE_MOIP_RIC_ANSAM_PR: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on /ANSam detection\n"); break; - case V150_1_SSE_RIC_V92_QC1A: + case V150_1_SSE_MOIP_RIC_V92_QC1A: break; - case V150_1_SSE_RIC_V92_QC1D: + case V150_1_SSE_MOIP_RIC_V92_QC1D: break; - case V150_1_SSE_RIC_V92_QC2A: + case V150_1_SSE_MOIP_RIC_V92_QC2A: break; - case V150_1_SSE_RIC_V92_QC2D: + case V150_1_SSE_MOIP_RIC_V92_QC2D: break; - case V150_1_SSE_RIC_V8BIS_CRE: + case V150_1_SSE_MOIP_RIC_V8BIS_CRE: break; - case V150_1_SSE_RIC_V8BIS_CRD: + case V150_1_SSE_MOIP_RIC_V8BIS_CRD: break; - case V150_1_SSE_RIC_TIA825A_45_45BPS: + case V150_1_SSE_MOIP_RIC_TIA825A_45_45BPS: break; - case V150_1_SSE_RIC_TIA825A_50BPS: + case V150_1_SSE_MOIP_RIC_TIA825A_50BPS: break; - case V150_1_SSE_RIC_EDT: + case V150_1_SSE_MOIP_RIC_EDT: break; - case V150_1_SSE_RIC_BELL103: + case V150_1_SSE_MOIP_RIC_BELL103: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on Bell103 detection\n"); break; - case V150_1_SSE_RIC_V21_TEXT_TELEPHONE: + case V150_1_SSE_MOIP_RIC_V21_TEXT_TELEPHONE: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.21 text telephone detection\n"); break; - case V150_1_SSE_RIC_V23_MINITEL: + case V150_1_SSE_MOIP_RIC_V23_MINITEL: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.21 minitel detection\n"); break; - case V150_1_SSE_RIC_V18_TEXT_TELEPHONE: + case V150_1_SSE_MOIP_RIC_V18_TEXT_TELEPHONE: break; - case V150_1_SSE_RIC_V18_DTMF_TEXT_RELAY: + case V150_1_SSE_MOIP_RIC_V18_DTMF_TEXT_RELAY: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on DTMF text relay detection\n"); break; - case V150_1_SSE_RIC_CTM: + case V150_1_SSE_MOIP_RIC_CTM: break; } /*endswitch*/ @@ -973,7 +667,7 @@ static int rx_modem_relay_packet(v150_1_sse_state_t *s, const uint8_t pkt[], int } /*- End of function --------------------------------------------------------*/ -static int rx_fax_relay_packet(v150_1_sse_state_t *s, const uint8_t pkt[], int len) +static int rx_fax_relay_packet(v150_1_state_t *s, const uint8_t pkt[], int len) { int res; int ric; @@ -984,17 +678,17 @@ static int rx_fax_relay_packet(v150_1_sse_state_t *s, const uint8_t pkt[], int l ric_info = get_net_unaligned_uint16(pkt + 2); span_log(&s->logging, SPAN_LOG_FLOW, - "%sReason %s - 0x%x\n", + "SSE %sReason %s - 0x%x\n", ((pkt[0] >> 1) & 0x01) ? "Force response. " : "", - v150_1_sse_ric_to_str(ric), + v150_1_sse_moip_ric_to_str(ric), ric_info); - if (s->rmt_mode != V150_1_SSE_MEDIA_STATE_FAX_RELAY) + if (s->remote_media_state != V150_1_MEDIA_STATE_FAX_RELAY) { /* Whether we change to FAX relay, VBD or plain audio is our choice. C.5.3.2. */ - //s->lcl_mode = V150_1_SSE_MEDIA_STATE_INITIAL_AUDIO; - //s->lcl_mode = V150_1_SSE_MEDIA_STATE_VOICE_BAND_DATA; - s->lcl_mode = V150_1_SSE_MEDIA_STATE_FAX_RELAY; - s->rmt_mode = V150_1_SSE_MEDIA_STATE_FAX_RELAY; + //s->local_media_state = V150_1_MEDIA_STATE_INITIAL_AUDIO; + //s->local_media_state = V150_1_MEDIA_STATE_VOICE_BAND_DATA; + s->local_media_state = V150_1_MEDIA_STATE_FAX_RELAY; + s->remote_media_state = V150_1_MEDIA_STATE_FAX_RELAY; } else { @@ -1002,66 +696,62 @@ static int rx_fax_relay_packet(v150_1_sse_state_t *s, const uint8_t pkt[], int l /*endif*/ switch (ric) { - case V150_1_SSE_RIC_V8_CM: + case V150_1_SSE_MOIP_RIC_V8_CM: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.8 detection\n"); /* We need to respond with a P' */ - v150_1_sse_tx_fax_relay_packet(s, 0, V150_1_SSE_RIC_P_STATE_TRANSITION, 0); - if (s->status_handler) - res = s->status_handler(s->status_user_data, V150_1_SSE_STATUS_V8_CM_RECEIVED_FAX); - /*endif*/ + v150_1_sse_tx_fax_relay_packet(s, 0, V150_1_SSE_MOIP_RIC_P_STATE_TRANSITION, 0); + res = sse_status_handler(s, V150_1_SSE_STATUS_V8_CM_RECEIVED_FAX); break; - case V150_1_SSE_RIC_V8_JM: + case V150_1_SSE_MOIP_RIC_V8_JM: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.8 detection\n"); break; - case V150_1_SSE_RIC_V32BIS_AA: + case V150_1_SSE_MOIP_RIC_V32BIS_AA: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.32bis detection\n"); /* We need to respond with a P' */ - v150_1_sse_tx_fax_relay_packet(s, 0, V150_1_SSE_RIC_P_STATE_TRANSITION, 0); - if (s->status_handler) - res = s->status_handler(s->status_user_data, V150_1_SSE_STATUS_AA_RECEIVED_FAX); - /*endif*/ + v150_1_sse_tx_fax_relay_packet(s, 0, V150_1_SSE_MOIP_RIC_P_STATE_TRANSITION, 0); + res = sse_status_handler(s, V150_1_SSE_STATUS_AA_RECEIVED_FAX); break; - case V150_1_SSE_RIC_V32BIS_AC: + case V150_1_SSE_MOIP_RIC_V32BIS_AC: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.32bis detection\n"); break; - case V150_1_SSE_RIC_V22BIS_USB1: + case V150_1_SSE_MOIP_RIC_V22BIS_USB1: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.22bis detection\n"); break; - case V150_1_SSE_RIC_V22BIS_SB1: + case V150_1_SSE_MOIP_RIC_V22BIS_SB1: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.22bis detection\n"); break; - case V150_1_SSE_RIC_V22BIS_S1: + case V150_1_SSE_MOIP_RIC_V22BIS_S1: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.22bis detection\n"); break; - case V150_1_SSE_RIC_V21_CH2: + case V150_1_SSE_MOIP_RIC_V21_CH2: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.21 detection\n"); break; - case V150_1_SSE_RIC_V21_CH1: + case V150_1_SSE_MOIP_RIC_V21_CH1: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.21 detection\n"); break; - case V150_1_SSE_RIC_V23_HIGH_CHANNEL: + case V150_1_SSE_MOIP_RIC_V23_HIGH_CHANNEL: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.23 detection\n"); break; - case V150_1_SSE_RIC_V23_LOW_CHANNEL: + case V150_1_SSE_MOIP_RIC_V23_LOW_CHANNEL: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.23 detection\n"); break; - case V150_1_SSE_RIC_TONE_2225HZ: + case V150_1_SSE_MOIP_RIC_TONE_2225HZ: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on 2225Hz tone detection\n"); break; - case V150_1_SSE_RIC_V21_CH2_HDLC_FLAGS: + case V150_1_SSE_MOIP_RIC_V21_CH2_HDLC_FLAGS: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.21 flags detection\n"); break; - case V150_1_SSE_RIC_INDETERMINATE_SIGNAL: + case V150_1_SSE_MOIP_RIC_INDETERMINATE_SIGNAL: break; - case V150_1_SSE_RIC_SILENCE: + case V150_1_SSE_MOIP_RIC_SILENCE: break; - case V150_1_SSE_RIC_CNG: + case V150_1_SSE_MOIP_RIC_CNG: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on CNG detection\n"); break; - case V150_1_SSE_RIC_VOICE: + case V150_1_SSE_MOIP_RIC_VOICE: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on voice detection\n"); break; - case V150_1_SSE_RIC_TIMEOUT: + case V150_1_SSE_MOIP_RIC_TIMEOUT: span_log(&s->logging, SPAN_LOG_FLOW, "Timeout %d - %s - 0x%x\n", @@ -1069,64 +759,62 @@ static int rx_fax_relay_packet(v150_1_sse_state_t *s, const uint8_t pkt[], int l v150_1_sse_timeout_reason_to_str(ric_info >> 8), ric_info & 0xFF); break; - case V150_1_SSE_RIC_P_STATE_TRANSITION: + case V150_1_SSE_MOIP_RIC_P_STATE_TRANSITION: span_log(&s->logging, SPAN_LOG_FLOW, "P' received\n"); break; - case V150_1_SSE_RIC_CLEARDOWN: + case V150_1_SSE_MOIP_RIC_CLEARDOWN: span_log(&s->logging, SPAN_LOG_FLOW, "Cleardown %d - %s\n", (ric_info >> 8), v150_1_sse_cleardown_reason_to_str(ric_info >> 8)); - if (s->status_handler) - res = s->status_handler(s->status_user_data, V150_1_SSE_STATUS_CLEARDOWN); - /*endif*/ + res = sse_status_handler(s, V150_1_SSE_STATUS_CLEARDOWN); break; - case V150_1_SSE_RIC_ANS_CED: + case V150_1_SSE_MOIP_RIC_ANS_CED: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on ANS/CED detection\n"); break; - case V150_1_SSE_RIC_ANSAM: + case V150_1_SSE_MOIP_RIC_ANSAM: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on ANSam detection\n"); break; - case V150_1_SSE_RIC_ANS_PR: + case V150_1_SSE_MOIP_RIC_ANS_PR: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on /ANS detection\n"); break; - case V150_1_SSE_RIC_ANSAM_PR: + case V150_1_SSE_MOIP_RIC_ANSAM_PR: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on /ANSam detection\n"); break; - case V150_1_SSE_RIC_V92_QC1A: + case V150_1_SSE_MOIP_RIC_V92_QC1A: break; - case V150_1_SSE_RIC_V92_QC1D: + case V150_1_SSE_MOIP_RIC_V92_QC1D: break; - case V150_1_SSE_RIC_V92_QC2A: + case V150_1_SSE_MOIP_RIC_V92_QC2A: break; - case V150_1_SSE_RIC_V92_QC2D: + case V150_1_SSE_MOIP_RIC_V92_QC2D: break; - case V150_1_SSE_RIC_V8BIS_CRE: + case V150_1_SSE_MOIP_RIC_V8BIS_CRE: break; - case V150_1_SSE_RIC_V8BIS_CRD: + case V150_1_SSE_MOIP_RIC_V8BIS_CRD: break; - case V150_1_SSE_RIC_TIA825A_45_45BPS: + case V150_1_SSE_MOIP_RIC_TIA825A_45_45BPS: break; - case V150_1_SSE_RIC_TIA825A_50BPS: + case V150_1_SSE_MOIP_RIC_TIA825A_50BPS: break; - case V150_1_SSE_RIC_EDT: + case V150_1_SSE_MOIP_RIC_EDT: break; - case V150_1_SSE_RIC_BELL103: + case V150_1_SSE_MOIP_RIC_BELL103: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on Bell103 detection\n"); break; - case V150_1_SSE_RIC_V21_TEXT_TELEPHONE: + case V150_1_SSE_MOIP_RIC_V21_TEXT_TELEPHONE: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.21 text telephone detection\n"); break; - case V150_1_SSE_RIC_V23_MINITEL: + case V150_1_SSE_MOIP_RIC_V23_MINITEL: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.23 minitel detection\n"); break; - case V150_1_SSE_RIC_V18_TEXT_TELEPHONE: + case V150_1_SSE_MOIP_RIC_V18_TEXT_TELEPHONE: break; - case V150_1_SSE_RIC_V18_DTMF_TEXT_RELAY: + case V150_1_SSE_MOIP_RIC_V18_DTMF_TEXT_RELAY: span_log(&s->logging, SPAN_LOG_FLOW, "Switch on DTMF text relay detection\n"); break; - case V150_1_SSE_RIC_CTM: + case V150_1_SSE_MOIP_RIC_CTM: break; } /*endswitch*/ @@ -1134,40 +822,108 @@ static int rx_fax_relay_packet(v150_1_sse_state_t *s, const uint8_t pkt[], int l } /*- End of function --------------------------------------------------------*/ -static int rx_text_relay_packet(v150_1_sse_state_t *s, const uint8_t pkt[], int len) +static int rx_text_relay_packet(v150_1_state_t *s, const uint8_t pkt[], int len) { - if (s->rmt_mode != V150_1_SSE_MEDIA_STATE_TEXT_RELAY) + int ric; + int ric_info; + + ric = pkt[1]; + ric_info = get_net_unaligned_uint16(pkt + 2); + span_log(&s->logging, + SPAN_LOG_FLOW, + "SSE %sReason %s - 0x%x\n", + ((pkt[0] >> 1) & 0x01) ? "Force response. " : "", + v150_1_sse_moip_ric_to_str(ric), + ric_info); + if (s->remote_media_state != V150_1_MEDIA_STATE_TEXT_RELAY) { /* Whether we change to text relay, VBD or plain audio is our choice. C.5.3.2. */ - //s->lcl_mode = V150_1_SSE_MEDIA_STATE_INITIAL_AUDIO; - //s->lcl_mode = V150_1_SSE_MEDIA_STATE_VOICE_BAND_DATA; - s->lcl_mode = V150_1_SSE_MEDIA_STATE_TEXT_RELAY; - s->rmt_mode = V150_1_SSE_MEDIA_STATE_TEXT_RELAY; + //s->local_media_state = V150_1_MEDIA_STATE_INITIAL_AUDIO; + //s->local_media_state = V150_1_MEDIA_STATE_VOICE_BAND_DATA; + s->local_media_state = V150_1_MEDIA_STATE_TEXT_RELAY; + s->remote_media_state = V150_1_MEDIA_STATE_TEXT_RELAY; } else { } /*endif*/ + switch (ric) + { + case V150_1_SSE_MOIP_RIC_TIMEOUT: + span_log(&s->logging, + SPAN_LOG_FLOW, + "Timeout %d - %s - 0x%x\n", + (ric_info >> 8), + v150_1_sse_timeout_reason_to_str(ric_info >> 8), + ric_info & 0xFF); + break; + case V150_1_SSE_MOIP_RIC_TIA825A_45_45BPS: + break; + case V150_1_SSE_MOIP_RIC_TIA825A_50BPS: + break; + case V150_1_SSE_MOIP_RIC_EDT: + break; + case V150_1_SSE_MOIP_RIC_BELL103: + span_log(&s->logging, SPAN_LOG_FLOW, "Switch on Bell103 detection\n"); + break; + case V150_1_SSE_MOIP_RIC_V21_TEXT_TELEPHONE: + span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.21 text telephone detection\n"); + break; + case V150_1_SSE_MOIP_RIC_V23_MINITEL: + span_log(&s->logging, SPAN_LOG_FLOW, "Switch on V.23 minitel detection\n"); + break; + case V150_1_SSE_MOIP_RIC_V18_TEXT_TELEPHONE: + break; + case V150_1_SSE_MOIP_RIC_V18_DTMF_TEXT_RELAY: + span_log(&s->logging, SPAN_LOG_FLOW, "Switch on DTMF text relay detection\n"); + break; + case V150_1_SSE_MOIP_RIC_CTM: + break; + } + /*endswitch*/ return 0; } /*- End of function --------------------------------------------------------*/ -static int rx_text_probe_packet(v150_1_sse_state_t *s, const uint8_t pkt[], int len) +static int rx_text_probe_packet(v150_1_state_t *s, const uint8_t pkt[], int len) { - if (s->rmt_mode != V150_1_SSE_MEDIA_STATE_TEXT_RELAY) + int ric; + int ric_info; + + ric = pkt[1]; + ric_info = get_net_unaligned_uint16(pkt + 2); + span_log(&s->logging, + SPAN_LOG_FLOW, + "SSE %sReason %s - 0x%x\n", + ((pkt[0] >> 1) & 0x01) ? "Force response. " : "", + v150_1_sse_moip_ric_to_str(ric), + ric_info); + if (s->remote_media_state != V150_1_MEDIA_STATE_TEXT_RELAY) { - s->lcl_mode = V150_1_SSE_MEDIA_STATE_TEXT_RELAY; - s->rmt_mode = V150_1_SSE_MEDIA_STATE_TEXT_RELAY; + s->local_media_state = V150_1_MEDIA_STATE_TEXT_RELAY; + s->remote_media_state = V150_1_MEDIA_STATE_TEXT_RELAY; } else { } /*endif*/ + switch (ric) + { + case V150_1_SSE_MOIP_RIC_TIMEOUT: + span_log(&s->logging, + SPAN_LOG_FLOW, + "Timeout %d - %s - 0x%x\n", + (ric_info >> 8), + v150_1_sse_timeout_reason_to_str(ric_info >> 8), + ric_info & 0xFF); + break; + } + /*endswitch*/ return 0; } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(int) v150_1_sse_rx_packet(v150_1_sse_state_t *s, +SPAN_DECLARE(int) v150_1_rx_sse_packet(v150_1_state_t *s, uint16_t seq_no, uint32_t timestamp, const uint8_t pkt[], @@ -1178,8 +934,11 @@ SPAN_DECLARE(int) v150_1_sse_rx_packet(v150_1_sse_state_t *s, int f; int x; int ext_len; + v150_1_sse_state_t *sse; + sse = &s->sse; span_log(&s->logging, SPAN_LOG_FLOW, "Rx message - %d bytes\n", len); + if (len < 4) return -1; /*endif*/ @@ -1191,7 +950,7 @@ SPAN_DECLARE(int) v150_1_sse_rx_packet(v150_1_sse_state_t *s, then the endpoint ignores the received message else - set the values of rmt_mode and rmt_ack to the values in the message + set the values of remote_media_state and remote_ack to the values in the message if the message contained a new value for the remote endpoint's mode or the message's must respond flag is set to TRUE @@ -1201,17 +960,21 @@ SPAN_DECLARE(int) v150_1_sse_rx_packet(v150_1_sse_state_t *s, */ res = 0; - if (s->previous_rx_timestamp != timestamp) + /* V.150.1 C.4.1 says act on the first received copy of an SSE message. Expect + the sequence number to increase, but the timestamp should remain the same for + redundant repeats. */ + if (sse->previous_rx_timestamp == timestamp) { - /* V.150.1 C.4.1 says act on the first received copy of an SSE message. Expect - the sequence number to increase, but the timestamp should remain the same for - redundant repeats. */ - s->previous_rx_timestamp = timestamp; + span_log(&s->logging, SPAN_LOG_FLOW, "Repeat SSE timestamp %d\n", timestamp); + } + else + { + sse->previous_rx_timestamp = timestamp; event = (pkt[0] >> 2) & 0x3F; f = (pkt[0] >> 1) & 0x01; x = pkt[0] & 0x01; - span_log(&s->logging, SPAN_LOG_FLOW, "Rx event %s\n", v150_1_sse_media_state_to_str(event)); + span_log(&s->logging, SPAN_LOG_FLOW, "Rx SSE event %s\n", v150_1_media_state_to_str(event)); if (x) { if (len >= 6) @@ -1220,7 +983,7 @@ SPAN_DECLARE(int) v150_1_sse_rx_packet(v150_1_sse_state_t *s, ext_len = get_net_unaligned_uint16(&pkt[4]) & 0x7FF; if (ext_len >= 1) { - s->rmt_ack = pkt[6] & 0x3F; + s->remote_ack = pkt[6] & 0x3F; } /*endif*/ } @@ -1233,24 +996,26 @@ SPAN_DECLARE(int) v150_1_sse_rx_packet(v150_1_sse_state_t *s, /*endif*/ } /*endif*/ + /* TODO event needs to map properly */ + v150_1_state_machine(s, event, pkt, len); switch (event) { - case V150_1_SSE_MEDIA_STATE_INITIAL_AUDIO: + case V150_1_MEDIA_STATE_INITIAL_AUDIO: res = rx_initial_audio_packet(s, pkt, len); break; - case V150_1_SSE_MEDIA_STATE_VOICE_BAND_DATA: + case V150_1_MEDIA_STATE_VOICE_BAND_DATA: res = rx_voice_band_data_packet(s, pkt, len); break; - case V150_1_SSE_MEDIA_STATE_MODEM_RELAY: + case V150_1_MEDIA_STATE_MODEM_RELAY: res = rx_modem_relay_packet(s, pkt, len); break; - case V150_1_SSE_MEDIA_STATE_FAX_RELAY: + case V150_1_MEDIA_STATE_FAX_RELAY: res = rx_fax_relay_packet(s, pkt, len); break; - case V150_1_SSE_MEDIA_STATE_TEXT_RELAY: + case V150_1_MEDIA_STATE_TEXT_RELAY: res = rx_text_relay_packet(s, pkt, len); break; - case V150_1_SSE_MEDIA_STATE_TEXT_PROBE: + case V150_1_MEDIA_STATE_TEXT_PROBE: res = rx_text_probe_packet(s, pkt, len); break; default: @@ -1259,50 +1024,44 @@ SPAN_DECLARE(int) v150_1_sse_rx_packet(v150_1_sse_state_t *s, break; } /*endswitch*/ - s->rmt_mode = event; + s->remote_media_state = event; } /*endif*/ return res; } /*- End of function --------------------------------------------------------*/ -static int send_packet(v150_1_sse_state_t *s, uint8_t *pkt, int len) +static int send_packet(v150_1_state_t *s, uint8_t *pkt, int len) { span_timestamp_t now; + v150_1_sse_state_t *sse; - if (s->tx_packet_handler) - s->tx_packet_handler(s->tx_packet_user_data, false, pkt, len); + sse = &s->sse; + if (sse->tx_packet_handler) + sse->tx_packet_handler(sse->tx_packet_user_data, false, pkt, len); /*endif*/ - switch (s->reliability_method) + switch (sse->reliability_method) { case V150_1_SSE_RELIABILITY_BY_REPETITION: - if (s->timer_handler) - { - memcpy(s->last_tx_pkt, pkt, len); - s->last_tx_len = len; - now = s->timer_handler(s->timer_user_data, ~0); - s->repetition_timer = now + s->repetition_interval; - s->repetition_counter = s->repetition_count; - update_timer(s); - } - /*endif*/ + memcpy(sse->last_tx_pkt, pkt, len); + sse->last_tx_len = len; + now = update_sse_timer(s, ~0); + sse->repetition_timer = now + sse->repetition_interval; + sse->repetition_counter = sse->repetition_count; + update_timer(s); break; case V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK: - if (s->timer_handler) - { - /* V.150.1/C.4.3.2 */ - /* Save a copy of the message for retransmission */ - /* TODO: add lcl_mode and rmt_mode to the message */ - memcpy(s->last_tx_pkt, pkt, len); - s->last_tx_len = len; - now = s->timer_handler(s->timer_user_data, ~0); - s->ack_counter_n0 = s->ack_n0count; - s->ack_timer_t0 = now + s->ack_t0interval; - s->ack_timer_t1 = now + s->ack_t1interval; - s->force_response = false; - update_timer(s); - } - /*endif*/ + /* V.150.1/C.4.3.2 */ + /* Save a copy of the message for retransmission */ + /* TODO: add local_media_state and remote_media_state to the message */ + memcpy(sse->last_tx_pkt, pkt, len); + sse->last_tx_len = len; + now = update_sse_timer(s, ~0); + sse->ack_counter_n0 = sse->ack_n0count; + sse->ack_timer_t0 = now + sse->ack_t0interval; + sse->ack_timer_t1 = now + sse->ack_t1interval; + sse->force_response = false; + update_timer(s); break; } /*endswitch*/ @@ -1310,42 +1069,126 @@ static int send_packet(v150_1_sse_state_t *s, uint8_t *pkt, int len) } /*- End of function --------------------------------------------------------*/ -static int v150_1_sse_tx_initial_audio_packet(v150_1_sse_state_t *s) +static int v150_1_sse_tx_initial_audio_packet(v150_1_state_t *s, int x, int ric, int ricinfo) { + uint8_t pkt[256]; + int len; + uint8_t f; + v150_1_sse_state_t *sse; + + sse = &s->sse; + f = 0; + /* If we are using explicit acknowledgements, both the F and X bits need to be set */ + if (sse->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) + { + f |= 0x01; + if (sse->force_response) + f |= 0x02; + /*endif*/ + } + /*endif*/ + span_log(&s->logging, SPAN_LOG_FLOW, "Sending %s\n", v150_1_sse_moip_ric_to_str(ric)); + pkt[0] = f | (V150_1_MEDIA_STATE_INITIAL_AUDIO << 2); + pkt[1] = ric; + put_net_unaligned_uint16(&pkt[2], ricinfo); + len = 4; + switch (ric) + { + case V150_1_SSE_MOIP_RIC_CLEARDOWN: + /* We may need to add more information as an extension. Note that V.150.1 originally made + the SSE message lengths variable in a way that can't really work. The only message this + affected was cleardown. Corrigendum 2 changed the extra bytes to an extension field, so + all messages are 4 bytes long until the extension bit it used to stretch them. */ + break; + } + /*endswitch*/ + if (sse->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) + { + /* The length of the extension field */ + put_net_unaligned_uint16(&pkt[len], 1); + len += 2; + /* The actual content of the field */ + pkt[len++] = s->remote_media_state; + } + /*endif*/ + send_packet(s, pkt, len); return 0; } /*- End of function --------------------------------------------------------*/ -static int v150_1_sse_tx_voice_band_data_packet(v150_1_sse_state_t *s) +static int v150_1_sse_tx_voice_band_data_packet(v150_1_state_t *s, int x, int ric, int ricinfo) { + uint8_t pkt[256]; + int len; + uint8_t f; + v150_1_sse_state_t *sse; + + sse = &s->sse; + f = 0; + /* If we are using explicit acknowledgements, both the F and X bits need to be set */ + if (sse->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) + { + f |= 0x01; + if (sse->force_response) + f |= 0x02; + /*endif*/ + } + /*endif*/ + span_log(&s->logging, SPAN_LOG_FLOW, "Sending %s\n", v150_1_sse_moip_ric_to_str(ric)); + pkt[0] = f | (V150_1_MEDIA_STATE_VOICE_BAND_DATA << 2); + pkt[1] = ric; + put_net_unaligned_uint16(&pkt[2], ricinfo); + len = 4; + switch (ric) + { + case V150_1_SSE_MOIP_RIC_CLEARDOWN: + /* We may need to add more information as an extension. Note that V.150.1 originally made + the SSE message lengths variable in a way that can't really work. The only message this + affected was cleardown. Corrigendum 2 changed the extra bytes to an extension field, so + all messages are 4 bytes long until the extension bit it used to stretch them. */ + break; + } + /*endswitch*/ + if (sse->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) + { + /* The length of the extension field */ + put_net_unaligned_uint16(&pkt[len], 1); + len += 2; + /* The actual content of the field */ + pkt[len++] = s->remote_media_state; + } + /*endif*/ + send_packet(s, pkt, len); return 0; } /*- End of function --------------------------------------------------------*/ -static int v150_1_sse_tx_modem_relay_packet(v150_1_sse_state_t *s, int x, int ric, int ricinfo) +static int v150_1_sse_tx_modem_relay_packet(v150_1_state_t *s, int x, int ric, int ricinfo) { uint8_t pkt[256]; int len; uint8_t f; + v150_1_sse_state_t *sse; + sse = &s->sse; f = 0; /* If we are using explicit acknowledgements, both the F and X bits need to be set */ - if (s->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) + if (sse->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) { f |= 0x01; - if (s->force_response) + if (sse->force_response) f |= 0x02; /*endif*/ } /*endif*/ - span_log(&s->logging, SPAN_LOG_FLOW, "Sending %s\n", v150_1_sse_ric_to_str(ric)); - pkt[0] = f | (V150_1_SSE_MEDIA_STATE_MODEM_RELAY << 2); + span_log(&s->logging, SPAN_LOG_FLOW, "Sending %s\n", v150_1_sse_moip_ric_to_str(ric)); + pkt[0] = f | (V150_1_MEDIA_STATE_MODEM_RELAY << 2); pkt[1] = ric; put_net_unaligned_uint16(&pkt[2], ricinfo); len = 4; switch (ric) { - case V150_1_SSE_RIC_CLEARDOWN: + case V150_1_SSE_MOIP_RIC_CLEARDOWN: /* We may need to add more information as an extension. Note that V.150.1 originally made the SSE message lengths variable in a way that can't really work. The only message this affected was cleardown. Corrigendum 2 changed the extra bytes to an extension field, so @@ -1353,13 +1196,13 @@ static int v150_1_sse_tx_modem_relay_packet(v150_1_sse_state_t *s, int x, int ri break; } /*endswitch*/ - if (s->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) + if (sse->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) { /* The length of the extension field */ put_net_unaligned_uint16(&pkt[len], 1); len += 2; /* The actual content of the field */ - pkt[len++] = s->rmt_mode; + pkt[len++] = s->remote_media_state; } /*endif*/ send_packet(s, pkt, len); @@ -1367,32 +1210,33 @@ static int v150_1_sse_tx_modem_relay_packet(v150_1_sse_state_t *s, int x, int ri } /*- End of function --------------------------------------------------------*/ -static int v150_1_sse_tx_fax_relay_packet(v150_1_sse_state_t *s, int x, int ric, int ricinfo) +static int v150_1_sse_tx_fax_relay_packet(v150_1_state_t *s, int x, int ric, int ricinfo) { - int res; uint8_t pkt[256]; int len; uint8_t f; + v150_1_sse_state_t *sse; + sse = &s->sse; f = 0; /* If we are using explicit acknowledgements, both the F and X bits need to be set */ - if (s->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) + if (sse->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) { f |= 0x01; - if (s->force_response) + if (sse->force_response) f |= 0x02; /*endif*/ } /*endif*/ - pkt[0] = (V150_1_SSE_MEDIA_STATE_FAX_RELAY << 2) | f; + pkt[0] = (V150_1_MEDIA_STATE_FAX_RELAY << 2) | f; pkt[1] = ric; put_net_unaligned_uint16(&pkt[2], ricinfo); len = 4; - if (s->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) + if (sse->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) { put_net_unaligned_uint16(&pkt[len], 1); len += 2; - pkt[len++] = s->rmt_mode; + pkt[len++] = s->remote_media_state; } /*endif*/ send_packet(s, pkt, len); @@ -1400,44 +1244,100 @@ static int v150_1_sse_tx_fax_relay_packet(v150_1_sse_state_t *s, int x, int ric, } /*- End of function --------------------------------------------------------*/ -static int v150_1_sse_tx_text_relay_packet(v150_1_sse_state_t *s) +static int v150_1_sse_tx_text_relay_packet(v150_1_state_t *s, int x, int ric, int ricinfo) { + uint8_t pkt[256]; + int len; + uint8_t f; + v150_1_sse_state_t *sse; + + sse = &s->sse; + f = 0; + /* If we are using explicit acknowledgements, both the F and X bits need to be set */ + if (sse->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) + { + f |= 0x01; + if (sse->force_response) + f |= 0x02; + /*endif*/ + } + /*endif*/ + pkt[0] = (V150_1_MEDIA_STATE_TEXT_RELAY << 2) | f; + pkt[1] = ric; + put_net_unaligned_uint16(&pkt[2], ricinfo); + len = 4; + if (sse->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) + { + put_net_unaligned_uint16(&pkt[len], 1); + len += 2; + pkt[len++] = s->remote_media_state; + } + /*endif*/ + send_packet(s, pkt, len); return 0; } /*- End of function --------------------------------------------------------*/ -static int v150_1_sse_tx_text_probe_packet(v150_1_sse_state_t *s) +static int v150_1_sse_tx_text_probe_packet(v150_1_state_t *s, int x, int ric, int ricinfo) { + uint8_t pkt[256]; + int len; + uint8_t f; + v150_1_sse_state_t *sse; + + sse = &s->sse; + f = 0; + /* If we are using explicit acknowledgements, both the F and X bits need to be set */ + if (sse->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) + { + f |= 0x01; + if (sse->force_response) + f |= 0x02; + /*endif*/ + } + /*endif*/ + pkt[0] = (V150_1_MEDIA_STATE_TEXT_PROBE << 2) | f; + pkt[1] = ric; + put_net_unaligned_uint16(&pkt[2], ricinfo); + len = 4; + if (sse->reliability_method == V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK) + { + put_net_unaligned_uint16(&pkt[len], 1); + len += 2; + pkt[len++] = s->remote_media_state; + } + /*endif*/ + send_packet(s, pkt, len); return 0; } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(int) v150_1_sse_tx_packet(v150_1_sse_state_t *s, int event, int ric, int ricinfo) +SPAN_DECLARE(int) v150_1_tx_sse_packet(v150_1_state_t *s, int event, int ric, int ricinfo) { int res; int x; x = 0; - span_log(&s->logging, SPAN_LOG_FLOW, "Tx event %s\n", v150_1_sse_media_state_to_str(event)); + span_log(&s->logging, SPAN_LOG_FLOW, "Tx event %s\n", v150_1_media_state_to_str(event)); switch (event) { - case V150_1_SSE_MEDIA_STATE_INITIAL_AUDIO: - res = v150_1_sse_tx_initial_audio_packet(s); + case V150_1_MEDIA_STATE_INITIAL_AUDIO: + res = v150_1_sse_tx_initial_audio_packet(s, x, ric, ricinfo); break; - case V150_1_SSE_MEDIA_STATE_VOICE_BAND_DATA: - res = v150_1_sse_tx_voice_band_data_packet(s); + case V150_1_MEDIA_STATE_VOICE_BAND_DATA: + res = v150_1_sse_tx_voice_band_data_packet(s, x, ric, ricinfo); break; - case V150_1_SSE_MEDIA_STATE_MODEM_RELAY: + case V150_1_MEDIA_STATE_MODEM_RELAY: res = v150_1_sse_tx_modem_relay_packet(s, x, ric, ricinfo); break; - case V150_1_SSE_MEDIA_STATE_FAX_RELAY: + case V150_1_MEDIA_STATE_FAX_RELAY: res = v150_1_sse_tx_fax_relay_packet(s, x, ric, ricinfo); break; - case V150_1_SSE_MEDIA_STATE_TEXT_RELAY: - res = v150_1_sse_tx_text_relay_packet(s); + case V150_1_MEDIA_STATE_TEXT_RELAY: + res = v150_1_sse_tx_text_relay_packet(s, x, ric, ricinfo); break; - case V150_1_SSE_MEDIA_STATE_TEXT_PROBE: - res = v150_1_sse_tx_text_probe_packet(s); + case V150_1_MEDIA_STATE_TEXT_PROBE: + res = v150_1_sse_tx_text_probe_packet(s, x, ric, ricinfo); break; default: span_log(&s->logging, SPAN_LOG_FLOW, "Unexpected SSE event %d\n", event); @@ -1445,97 +1345,98 @@ SPAN_DECLARE(int) v150_1_sse_tx_packet(v150_1_sse_state_t *s, int event, int ric break; } /*endswitch*/ - s->lcl_mode = event; + s->local_media_state = event; return res; } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(int) v150_1_sse_timer_expired(v150_1_sse_state_t *s, span_timestamp_t now) +SPAN_DECLARE(int) v150_1_sse_timer_expired(v150_1_state_t *s, span_timestamp_t now) { - span_log(&s->logging, SPAN_LOG_FLOW, "Timer expired at %lu\n", now); + v150_1_sse_state_t *sse; + + sse = &s->sse; + span_log(&s->logging, SPAN_LOG_FLOW, "SSE timer expired at %lu\n", now); - if (now < s->latest_timer) + if (now < sse->latest_timer) { - span_log(&s->logging, SPAN_LOG_FLOW, "Timer returned %luus early\n", s->latest_timer - now); + span_log(&s->logging, SPAN_LOG_FLOW, "SSE timer returned %luus early\n", sse->latest_timer - now); /* Request the same timeout point again. */ - if (s->timer_handler) - s->timer_handler(s->timer_user_data, s->latest_timer); - /*endif*/ + update_sse_timer(s, sse->latest_timer); return 0; } /*endif*/ - if (s->immediate_timer) + if (sse->immediate_timer) { - s->immediate_timer = false; + sse->immediate_timer = false; /* TODO: */ } /*endif*/ - if (s->ack_timer_t0 != 0 && s->ack_timer_t0 <= now) + if (sse->ack_timer_t0 != 0 && sse->ack_timer_t0 <= now) { - span_log(&s->logging, SPAN_LOG_FLOW, "T0 expired\n"); + span_log(&s->logging, SPAN_LOG_FLOW, "SSE T0 expired\n"); /* V.150.1/C.4.3.2 */ - if (s->ack_counter_n0 > 0 && s->lcl_mode != s->rmt_ack) + if (sse->ack_counter_n0 > 0 && s->local_media_state != s->remote_ack) { - span_log(&s->logging, SPAN_LOG_FLOW, "Resend (%d)\n", s->ack_counter_n0); + span_log(&s->logging, SPAN_LOG_FLOW, "SSE resend (%d)\n", sse->ack_counter_n0); /* TODO: The must respond flag is set to TRUE if the value of timer t1 is zero. */ - if (s->tx_packet_handler) - s->tx_packet_handler(s->tx_packet_user_data, true, s->last_tx_pkt, s->last_tx_len); + if (sse->tx_packet_handler) + sse->tx_packet_handler(sse->tx_packet_user_data, true, sse->last_tx_pkt, sse->last_tx_len); /*endif*/ - s->ack_counter_n0--; - s->ack_timer_t0 = now + s->ack_t0interval; + sse->ack_counter_n0--; + sse->ack_timer_t0 = now + sse->ack_t0interval; /* T1 is not touched at this time */ update_timer(s); } /*endif*/ } /*endif*/ - if (s->ack_timer_t1 != 0 && s->ack_timer_t1 <= now) + if (sse->ack_timer_t1 != 0 && sse->ack_timer_t1 <= now) { - span_log(&s->logging, SPAN_LOG_FLOW, "T1 expired\n"); + span_log(&s->logging, SPAN_LOG_FLOW, "SSE T1 expired\n"); /* V.150.1/C.4.3.2 */ - if (s->ack_counter_n0 == 0 && s->lcl_mode != s->rmt_ack) + if (sse->ack_counter_n0 == 0 && s->local_media_state != s->remote_ack) { - span_log(&s->logging, SPAN_LOG_FLOW, "Resend (%d)\n", s->ack_counter_n0); + span_log(&s->logging, SPAN_LOG_FLOW, "SSE resend (%d)\n", sse->ack_counter_n0); /* TODO: The must respond flag is set to TRUE */ - if (s->tx_packet_handler) - s->tx_packet_handler(s->tx_packet_user_data, true, s->last_tx_pkt, s->last_tx_len); + if (sse->tx_packet_handler) + sse->tx_packet_handler(sse->tx_packet_user_data, true, sse->last_tx_pkt, sse->last_tx_len); /*endif*/ /* counter N0 is not touched at this time */ /* T0 is not touched at this time */ - s->ack_timer_t1 = now + s->ack_t1interval; + sse->ack_timer_t1 = now + sse->ack_t1interval; update_timer(s); } /*endif*/ } /*endif*/ - if (s->repetition_timer != 0 && s->repetition_timer <= now) + if (sse->repetition_timer != 0 && sse->repetition_timer <= now) { /* Handle reliability by simple repetition timer */ - span_log(&s->logging, SPAN_LOG_FLOW, "Repetition timer expired\n"); - if (s->repetition_counter > 1) + span_log(&s->logging, SPAN_LOG_FLOW, "SSE repetition timer expired\n"); + if (sse->repetition_counter > 1) { - s->repetition_timer += s->repetition_interval; + sse->repetition_timer += sse->repetition_interval; update_timer(s); } else { - s->repetition_timer = 0; + sse->repetition_timer = 0; } /*endif*/ - --s->repetition_counter; - if (s->tx_packet_handler) - s->tx_packet_handler(s->tx_packet_user_data, true, s->last_tx_pkt, s->last_tx_len); + --sse->repetition_counter; + if (sse->tx_packet_handler) + sse->tx_packet_handler(sse->tx_packet_user_data, true, sse->last_tx_pkt, sse->last_tx_len); /*endif*/ } /*endif*/ - if (s->recovery_timer_t1 != 0 && s->recovery_timer_t1 <= now) + if (sse->recovery_timer_t1 != 0 && sse->recovery_timer_t1 <= now) { } /*endif*/ - if (s->recovery_timer_t2 != 0 && s->recovery_timer_t2 <= now) + if (sse->recovery_timer_t2 != 0 && sse->recovery_timer_t2 <= now) { } /*endif*/ @@ -1543,19 +1444,22 @@ SPAN_DECLARE(int) v150_1_sse_timer_expired(v150_1_sse_state_t *s, span_timestamp } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(int) v150_1_sse_set_reliability_method(v150_1_sse_state_t *s, +SPAN_DECLARE(int) v150_1_set_sse_reliability_method(v150_1_state_t *s, enum v150_1_sse_reliability_option_e method, int parm1, int parm2, int parm3) { + v150_1_sse_state_t *sse; + + sse = &s->sse; /* Select one of the reliability methods from V.150.1 C.4 */ switch (method) { case V150_1_SSE_RELIABILITY_NONE: break; case V150_1_SSE_RELIABILITY_BY_REPETITION: - if (parm1 < 2 || parm1 > 10) + if (parm1 < 2 || parm1 > 10) return -1; /*endif*/ if (parm2 < 10000 || parm2 > 1000000) @@ -1563,13 +1467,13 @@ SPAN_DECLARE(int) v150_1_sse_set_reliability_method(v150_1_sse_state_t *s, /*endif*/ /* The actual number of repeats is one less than the total number of transmissions */ - s->repetition_count = parm1 - 1; - s->repetition_interval = parm2; + sse->repetition_count = parm1 - 1; + sse->repetition_interval = parm2; break; case V150_1_SSE_RELIABILITY_BY_RFC2198: break; case V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK: - if (parm1 < 2 || parm1 > 10) + if (parm1 < 2 || parm1 > 10) return -1; /*endif*/ if (parm2 < 10000 || parm2 > 1000000) @@ -1578,65 +1482,44 @@ SPAN_DECLARE(int) v150_1_sse_set_reliability_method(v150_1_sse_state_t *s, if (parm3 < 10000 || parm3 > 1000000) return -1; /*endif*/ - s->ack_n0count = parm1; - s->ack_t0interval = parm2; - s->ack_t1interval = parm3; + sse->ack_n0count = parm1; + sse->ack_t0interval = parm2; + sse->ack_t1interval = parm3; break; default: return -1; } /*endswitch*/ - s->reliability_method = method; + sse->reliability_method = method; return 0; } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(logging_state_t *) v150_1_sse_get_logging_state(v150_1_sse_state_t *s) +void v150_1_sse_init(v150_1_state_t *s, + v150_1_sse_tx_packet_handler_t tx_packet_handler, + void *tx_packet_user_data) { - return &s->logging; -} -/*- End of function --------------------------------------------------------*/ + v150_1_sse_state_t *sse; -SPAN_DECLARE(v150_1_sse_state_t *) v150_1_sse_init(v150_1_sse_state_t *s, - v150_1_sse_packet_handler_t packet_handler, - void *packet_user_data, - v150_1_sse_status_handler_t status_handler, - void *status_user_data, - v150_1_sse_timer_handler_t timer_handler, - void *timer_user_data) -{ - if (packet_handler == NULL) - return NULL; - /*endif*/ - if (s == NULL) - { - if ((s = (v150_1_sse_state_t *) malloc(sizeof(*s))) == NULL) - return NULL; - /*endif*/ - } - /*endif*/ - memset(s, 0, sizeof(*s)); - - span_log_init(&s->logging, SPAN_LOG_NONE, NULL); - span_log_set_protocol(&s->logging, "V.150.1 SSE"); + sse = &s->sse; - s->reliability_method = V150_1_SSE_RELIABILITY_NONE; + sse->reliability_method = V150_1_SSE_RELIABILITY_NONE; /* Set default values for the reliability by redundancy parameters */ /* V.150.1 C.4.1 */ /* The actual number of repeats is one less than the total number of transmissions */ - s->repetition_count = V150_1_SSE_DEFAULT_REPETITIONS - 1; - s->repetition_interval = V150_1_SSE_DEFAULT_REPETITION_INTERVAL; + sse->repetition_count = V150_1_SSE_DEFAULT_REPETITIONS - 1; + sse->repetition_interval = V150_1_SSE_DEFAULT_REPETITION_INTERVAL; /* Set default values for the explicit acknowledgement parameters */ /* V.150.1 C.4.3.1 */ - s->ack_n0count = V150_1_SSE_DEFAULT_ACK_N0; - s->ack_t0interval = V150_1_SSE_DEFAULT_ACK_T0; - s->ack_t1interval = V150_1_SSE_DEFAULT_ACK_T1; + sse->ack_n0count = V150_1_SSE_DEFAULT_ACK_N0; + sse->ack_t0interval = V150_1_SSE_DEFAULT_ACK_T0; + sse->ack_t1interval = V150_1_SSE_DEFAULT_ACK_T1; - s->recovery_n = V150_1_SSE_DEFAULT_RECOVERY_N; - s->recovery_t1 = V150_1_SSE_DEFAULT_RECOVERY_T1; - s->recovery_t2 = V150_1_SSE_DEFAULT_RECOVERY_T2; + sse->recovery_n = V150_1_SSE_DEFAULT_RECOVERY_N; + sse->recovery_t1 = V150_1_SSE_DEFAULT_RECOVERY_T1; + sse->recovery_t2 = V150_1_SSE_DEFAULT_RECOVERY_T2; /* V.150.1 C.4.3.1 */ /* Let p be the probability that a packet sent by one MoIP node through the packet @@ -1647,26 +1530,16 @@ SPAN_DECLARE(v150_1_sse_state_t *) v150_1_sse_init(v150_1_sse_state_t *s, Let rtd be the round trip delay through the packet network between the two nodes Let owd be the one way delay through the packet network from one node to the other (i.e. rtd/2) */ - //s->n0count = floor(log(1 - q)/log(1 - p)); - //s->t0interval = max(0, ((rtd/2) - t)/(n0count - 1)); - //s->t1interval = 1.5*rtd; - - s->explicit_ack_enabled = false; - - /* V.150.1 C.5.3 */ - s->lcl_mode = V150_1_SSE_MEDIA_STATE_INITIAL_AUDIO; - s->rmt_mode = V150_1_SSE_MEDIA_STATE_INITIAL_AUDIO; + //sse->n0count = floor(log(1 - q)/log(1 - p)); + //sse->t0interval = max(0, ((rtd/2) - t)/(n0count - 1)); + //sse->t1interval = 1.5*rtd; - s->previous_rx_timestamp = 0xFFFFFFFF; + sse->explicit_ack_enabled = false; - s->tx_packet_handler = packet_handler; - s->tx_packet_user_data = packet_user_data; - s->status_handler = status_handler; - s->status_user_data = status_user_data; - s->timer_handler = timer_handler; - s->timer_user_data = timer_user_data; + sse->previous_rx_timestamp = 0xFFFFFFFF; - return s; + sse->tx_packet_handler = tx_packet_handler; + sse->tx_packet_user_data = tx_packet_user_data; } /*- End of function --------------------------------------------------------*/ /*- End of file ------------------------------------------------------------*/ diff --git a/src/v18.c b/src/v18.c index 0425cfb2..1023482a 100644 --- a/src/v18.c +++ b/src/v18.c @@ -174,22 +174,22 @@ When answering the DCE should prepare to detect: DTMF tones */ +#define GOERTZEL_SAMPLES_PER_BLOCK 102 + #if defined(SPANDSP_USE_FIXED_POINTx) /* The fixed point version scales the 16 bit signal down by 7 bits, so the Goertzels will fit in a 32 bit word */ -#define FP_SCALE(x) ((int16_t) (x/128.0 + ((x >= 0.0) ? 0.5 : -0.5))) -#define TONE_TO_TOTAL_ENERGY 83.868f /* -0.85dB [GOERTZEL_SAMPLES_PER_BLOCK*10^(-0.85/10.0)] */ +#define FP_SCALE(x) ((int16_t) (x/128.0 + ((x >= 0.0) ? 0.5 : -0.5))) +static const float tone_to_total_energy = GOERTZEL_SAMPLES_PER_BLOCK*db_to_power_ratio(-0.85f); #else -#define FP_SCALE(x) (x) -#define TONE_TO_TOTAL_ENERGY 83.868f /* -0.85dB [GOERTZEL_SAMPLES_PER_BLOCK*10^(-0.85/10.0)] */ +#define FP_SCALE(x) (x) +static const float tone_to_total_energy = GOERTZEL_SAMPLES_PER_BLOCK*db_to_power_ratio(-0.85f); #endif -#define GOERTZEL_SAMPLES_PER_BLOCK 102 - static void v18_set_modem(v18_state_t *s, int mode); static goertzel_descriptor_t tone_set_desc[GOERTZEL_TONE_SET_ENTRIES]; static bool goertzel_descriptors_inited = false; -static float tone_set_frequency[GOERTZEL_TONE_SET_ENTRIES] = +static const float tone_set_frequency[GOERTZEL_TONE_SET_ENTRIES] = { 390.0f, // V.23 low channel 980.0f, @@ -201,7 +201,7 @@ static float tone_set_frequency[GOERTZEL_TONE_SET_ENTRIES] = 1800.0f, 2225.0f // Bell 103 answer tone }; -static span_sample_timer_t tone_set_target_duration[GOERTZEL_TONE_SET_ENTRIES] = +static const span_sample_timer_t tone_set_target_duration[GOERTZEL_TONE_SET_ENTRIES] = { milliseconds_to_samples(3000), /* 390Hz */ milliseconds_to_samples(1500), /* 980Hz */ @@ -214,7 +214,7 @@ static span_sample_timer_t tone_set_target_duration[GOERTZEL_TONE_SET_ENTRIES] = milliseconds_to_samples(460) /* 2225Hz */ }; -static bool tone_set_enabled[2][GOERTZEL_TONE_SET_ENTRIES] = +static const bool tone_set_enabled[2][GOERTZEL_TONE_SET_ENTRIES] = { { true, /* 390Hz */ @@ -1586,7 +1586,7 @@ static int caller_tone_scan(v18_state_t *s, const int16_t amp[], int samples) /* Fraction of total energy test */ if (max_energy < s->threshold || - max_energy <= TONE_TO_TOTAL_ENERGY*s->energy) + max_energy <= tone_to_total_energy*s->energy) { tone_is = 0; } @@ -1727,7 +1727,7 @@ static int answerer_tone_scan(v18_state_t *s, const int16_t amp[], int samples) /* Fraction of total energy test */ if (max_energy < s->threshold || - max_energy <= TONE_TO_TOTAL_ENERGY*s->energy) + max_energy <= tone_to_total_energy*s->energy) { tone_is = 0; } @@ -2036,7 +2036,7 @@ static void init_v18_descriptors(void) } /*- End of function --------------------------------------------------------*/ -SPAN_DECLARE(int) v18_set_stored_message(v18_state_t *s, uint8_t *msg) +SPAN_DECLARE(int) v18_set_stored_message(v18_state_t *s, const char *msg) { strncpy(s->stored_message, msg, 80); return 0; diff --git a/tests/Makefile.am b/tests/Makefile.am index 5b8f17a8..42d783cf 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -48,10 +48,10 @@ EXTRA_DIST = fax_tests.sh \ msvc/v22bis_tests.2012.vcxproj.filters \ msvc/v29_tests.2012.vcxproj \ msvc/v29_tests.2012.vcxproj.filters \ - msvc/v80_tests.2012.vcxproj \ - msvc/v80_tests.2012.vcxproj.filters \ msvc/v8_tests.2012.vcxproj \ msvc/v8_tests.2012.vcxproj.filters \ + msvc/v80_tests.2012.vcxproj \ + msvc/v80_tests.2012.vcxproj.filters \ msvc/vector_float_tests.2012.vcxproj \ msvc/vector_float_tests.2012.vcxproj.filters \ msvc/vector_int_tests.2012.vcxproj \ @@ -153,7 +153,6 @@ noinst_PROGRAMS = ademco_contactid_tests \ tone_detect_tests \ tone_generate_tests \ tsb85_tests \ - v150_1_sse_tests \ v150_1_tests \ v17_tests \ v18_tests \ @@ -347,7 +346,7 @@ sprt_decode_SOURCES = sprt_decode.c pcap_parse.c sprt_decode_LDADD = -L$(top_builddir)/spandsp-sim -lspandsp-sim $(BASE_LIBS) sprt_tests_SOURCES = sprt_tests.c socket_dgram_harness.c pseudo_terminals.c -sprt_tests_LDADD = -L$(top_builddir)/spandsp-sim -lspandsp-sim $(BASE_LIBS) -luv +sprt_tests_LDADD = -L$(top_builddir)/spandsp-sim -lspandsp-sim $(BASE_LIBS) super_tone_rx_tests_SOURCES = super_tone_rx_tests.c super_tone_rx_tests_LDADD = -L$(top_builddir)/spandsp-sim -lspandsp-sim $(BASE_LIBS) @@ -409,12 +408,9 @@ tone_generate_tests_LDADD = -L$(top_builddir)/spandsp-sim -lspandsp-sim $(BASE_L tsb85_tests_SOURCES = tsb85_tests.c fax_utils.c fax_tester.c tsb85_tests_LDADD = -L$(top_builddir)/spandsp-sim -lspandsp-sim $(BASE_LIBS) -v150_1_tests_SOURCES = v150_1_tests.c +v150_1_tests_SOURCES = v150_1_tests.c socket_dgram_harness.c pseudo_terminals.c v150_1_tests_LDADD = -L$(top_builddir)/spandsp-sim -lspandsp-sim $(BASE_LIBS) -v150_1_sse_tests_SOURCES = v150_1_sse_tests.c socket_dgram_harness.c pseudo_terminals.c -v150_1_sse_tests_LDADD = -L$(top_builddir)/spandsp-sim -lspandsp-sim $(BASE_LIBS) - v17_tests_SOURCES = v17_tests.c line_model_monitor.cpp modem_monitor.cpp v17_tests_LDADD = -L$(top_builddir)/spandsp-sim -lspandsp-sim $(BASE_LIBS) diff --git a/tests/ademco_contactid_tests.c b/tests/ademco_contactid_tests.c index 4071999d..1904a916 100644 --- a/tests/ademco_contactid_tests.c +++ b/tests/ademco_contactid_tests.c @@ -98,6 +98,7 @@ static int mitel_cm7291_side_2_and_bellcore_tests(void) if ((sender = ademco_contactid_sender_init(NULL, talkoff_tx_callback, NULL)) == NULL) return -1; + /*endif*/ logging = ademco_contactid_sender_get_logging_state(sender); span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); span_log_set_tag(logging, "Ademco-tx"); @@ -118,22 +119,27 @@ static int mitel_cm7291_side_2_and_bellcore_tests(void) printf(" Cannot open speech file '%s'\n", bellcore_files[j]); return -1; } + /*endif*/ while ((frames = sf_readf_short(inhandle, amp, SAMPLE_RATE))) { ademco_contactid_sender_rx(sender, amp, frames); } + /*endwhile*/ if (sf_close_telephony(inhandle)) { printf(" Cannot close speech file '%s'\n", bellcore_files[j]); return -1; } + /*endif*/ printf(" File %d gave %d false hits.\n", j + 1, 0); } + /*endfor*/ if (tx_callback_reported) { printf(" Failed\n"); return -1; } + /*endif*/ printf(" Passed\n"); ademco_contactid_sender_free(sender); return 0; @@ -154,6 +160,7 @@ static void rx_callback(void *user_data, const ademco_contactid_report_t *report printf("Report mismatch\n"); exit(2); } + /*endif*/ rx_callback_reported = true; } /*- End of function --------------------------------------------------------*/ @@ -176,12 +183,14 @@ static void tx_callback(void *user_data, int tone, int level, int duration) ademco_contactid_sender_put(sender, &reports[reports_entry]); else sending_complete = true; + /*endif*/ break; case 0: /* Sending failed after retries */ sending_complete = true; break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -205,9 +214,11 @@ static int end_to_end_tests(void) fprintf(stderr, " Cannot open audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ if ((receiver = ademco_contactid_receiver_init(NULL, rx_callback, NULL)) == NULL) return -1; + /*endif*/ ademco_contactid_receiver_set_realtime_callback(receiver, rx_callback, receiver); logging = ademco_contactid_receiver_get_logging_state(receiver); @@ -216,6 +227,7 @@ static int end_to_end_tests(void) if ((sender = ademco_contactid_sender_init(NULL, tx_callback, NULL)) == NULL) return -1; + /*endif*/ ademco_contactid_sender_set_realtime_callback(sender, tx_callback, sender); logging = ademco_contactid_sender_get_logging_state(sender); span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); @@ -232,8 +244,10 @@ static int end_to_end_tests(void) samples = ademco_contactid_sender_tx(sender, amp, SAMPLES_PER_CHUNK); for (j = samples; j < SAMPLES_PER_CHUNK; j++) amp[j] = 0; + /*endfor*/ for (j = 0; j < SAMPLES_PER_CHUNK; j++) sndfile_buf[2*j] = amp[j]; + /*endfor*/ /* There is no point in impairing this signal. It is just DTMF tones, which will work as wel as the DTMF detector beign used. */ ademco_contactid_receiver_rx(receiver, amp, SAMPLES_PER_CHUNK); @@ -241,6 +255,7 @@ static int end_to_end_tests(void) samples = ademco_contactid_receiver_tx(receiver, amp, SAMPLES_PER_CHUNK); for (j = samples; j < SAMPLES_PER_CHUNK; j++) amp[j] = 0; + /*endfor*/ /* We add AWGN and codec impairments to the signal, to stress the tone detector. */ codec_munge(munge, amp, SAMPLES_PER_CHUNK); @@ -250,23 +265,27 @@ static int end_to_end_tests(void) /* Add noise to the tones */ amp[j] += awgn(&noise_source); } + /*endfor*/ codec_munge(munge, amp, SAMPLES_PER_CHUNK); ademco_contactid_sender_rx(sender, amp, SAMPLES_PER_CHUNK); sf_writef_short(outhandle, sndfile_buf, SAMPLES_PER_CHUNK); } + /*endfor*/ codec_munge_free(munge); if (!rx_callback_reported) { fprintf(stderr, " Report not received\n"); return -1; } + /*endif*/ if (sf_close_telephony(outhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME); return -1; } + /*endif*/ printf(" Passed\n"); ademco_contactid_sender_free(sender); ademco_contactid_receiver_free(receiver); @@ -287,12 +306,14 @@ static int encode_decode_tests(void) if ((receiver = ademco_contactid_receiver_init(NULL, NULL, NULL)) == NULL) return 2; + /*endif*/ logging = ademco_contactid_receiver_get_logging_state(receiver); span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); span_log_set_tag(logging, "Ademco-rx"); if ((sender = ademco_contactid_sender_init(NULL, NULL, NULL)) == NULL) return 2; + /*endif*/ logging = ademco_contactid_sender_get_logging_state(sender); span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); span_log_set_tag(logging, "Ademco-tx"); @@ -304,12 +325,14 @@ static int encode_decode_tests(void) printf("Bad encode message\n"); return -1; } + /*endif*/ printf("'%s'\n", buf); if (decode_msg(&result, buf)) { printf("Bad decode message\n"); return -1; } + /*endif*/ ademco_contactid_receiver_log_msg(receiver, &result); printf("\n"); if (memcmp(&reports[i], &result, sizeof(result))) @@ -317,13 +340,16 @@ static int encode_decode_tests(void) printf("Received message does not match the one sent\n"); return -1; } + /*endif*/ } + /*endfor*/ if (encode_msg(buf, &reports[5]) >= 0) { printf("Incorrectly good message\n"); return -1; } + /*endif*/ printf("'%s'\n", buf); printf("\n"); printf(" Passed\n"); @@ -357,31 +383,37 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ if (decode_test_file) { decode_file(decode_test_file); return 0; } + /*endif*/ if (encode_decode_tests()) { printf("Tests failed\n"); return 2; } + /*endif*/ if (mitel_cm7291_side_2_and_bellcore_tests()) { printf("Tests failed\n"); return 2; } + /*endif*/ if (end_to_end_tests()) { printf("Tests failed\n"); return 2; } + /*endif*/ printf("Tests passed\n"); return 0; diff --git a/tests/adsi_tests.c b/tests/adsi_tests.c index 500bbf08..de23c26b 100644 --- a/tests/adsi_tests.c +++ b/tests/adsi_tests.c @@ -93,6 +93,7 @@ static int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) case ADSI_STANDARD_CLASS: if (cycle > 3) cycle = 0; + /*endif*/ switch (cycle) { case 0: @@ -124,10 +125,12 @@ static int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) len = adsi_add_field(s, msg, len, 0, (uint8_t *) "6095551212", 10); break; } + /*endswitch*/ break; case ADSI_STANDARD_CLIP: if (cycle > 4) cycle = 0; + /*endif*/ switch (cycle) { case 0: @@ -160,10 +163,12 @@ static int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) len = adsi_add_field(s, msg, len, CLIP_NUM_MSG, (uint8_t *) "\x03", 1); break; } + /*endswitch*/ break; case ADSI_STANDARD_ACLIP: if (cycle > 0) cycle = 0; + /*endif*/ switch (cycle) { case 0: @@ -175,6 +180,7 @@ static int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) len = adsi_add_field(s, msg, len, ACLIP_CALLER_NAME, (uint8_t *) "Chan Dai Man", 15); break; } + /*endswitch*/ break; case ADSI_STANDARD_JCLIP: len = adsi_add_field(s, msg, -1, JCLIP_MDMF_CALLERID, NULL, 0); @@ -186,6 +192,7 @@ static int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) case ADSI_STANDARD_CLIP_DTMF: if (cycle > 4) cycle = 0; + /*endif*/ switch (cycle) { case 0: @@ -213,12 +220,14 @@ static int adsi_create_message(adsi_tx_state_t *s, uint8_t *msg) len = adsi_add_field(s, msg, len, CLIP_DTMF_HASH_UNSPECIFIED, (uint8_t *) "12345678", 8); break; } + /*endswitch*/ break; case ADSI_STANDARD_TDD: t = "The quick Brown Fox Jumps Over The Lazy dog 0123456789!@#$%^&*()"; len = adsi_add_field(s, msg, -1, 0, (uint8_t *) t, strlen(t)); break; } + /*endswitch*/ cycle++; return len; } @@ -241,7 +250,9 @@ static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) printf("%02x ", msg[i]); if ((i & 0xF) == 0xF) printf("\n"); + /*endif*/ } + /*endfor*/ printf("\n"); l = -1; message_type = -1; @@ -291,6 +302,7 @@ static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) printf("Caller's name absent: 'O' or 'P'"); break; } + /*endswitch*/ break; case CLASS_SDMF_MSG_WAITING: break; @@ -301,8 +313,10 @@ static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) printf("Message waiting/not waiting"); break; } + /*endswitch*/ break; } + /*endswitch*/ break; case ADSI_STANDARD_CLIP: switch (message_type) @@ -364,8 +378,10 @@ static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) printf("Service information"); break; } + /*endswitch*/ break; } + /*endswitch*/ break; case ADSI_STANDARD_ACLIP: switch (message_type) @@ -400,8 +416,10 @@ static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) printf("Caller's name absent: 'O' or 'P'"); break; } + /*endswitch*/ break; } + /*endswitch*/ break; case ADSI_STANDARD_JCLIP: switch (message_type) @@ -425,8 +443,10 @@ static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) printf("Caller's number absent: 'C', 'O', 'P' or 'S'"); break; } + /*endswitch*/ break; } + /*endswitch*/ break; case ADSI_STANDARD_CLIP_DTMF: switch (message_type) @@ -444,6 +464,7 @@ static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) printf("Unspecified"); break; } + /*endswitch*/ break; case CLIP_DTMF_C_TERMINATED: switch (field_type) @@ -458,8 +479,10 @@ static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) printf("Caller's number absent"); break; } + /*endswitch*/ break; } + /*endswitch*/ break; case ADSI_STANDARD_TDD: if (basic_testing) @@ -472,9 +495,12 @@ static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) printf("String error\n"); exit(2); } + /*endif*/ } + /*endif*/ break; } + /*endswitch*/ } else { @@ -501,6 +527,7 @@ static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) printf("Unknown"); break; } + /*endswitch*/ break; case ADSI_STANDARD_CLIP: switch (message_type) @@ -521,6 +548,7 @@ static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) printf("Unknown"); break; } + /*endswitch*/ break; case ADSI_STANDARD_ACLIP: switch (message_type) @@ -535,6 +563,7 @@ static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) printf("Unknown"); break; } + /*endswitch*/ break; case ADSI_STANDARD_JCLIP: switch (message_type) @@ -546,6 +575,7 @@ static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) printf("Unknown"); break; } + /*endswitch*/ break; case ADSI_STANDARD_CLIP_DTMF: switch (message_type) @@ -560,14 +590,18 @@ static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) printf("Unknown"); break; } + /*endswitch*/ break; case ADSI_STANDARD_TDD: printf("Unknown"); break; } + /*endswitch*/ } + /*endif*/ printf("\n"); } + /*endif*/ } while (l > 0); if (l < -1) @@ -576,6 +610,7 @@ static void put_adsi_msg(void *user_data, const uint8_t *msg, int len) printf("Bad message contents\n"); exit(2); } + /*endif*/ printf("\n"); } /*- End of function --------------------------------------------------------*/ @@ -603,11 +638,15 @@ static void tdd_character_set_tests(void) yy = adsi_decode_baudot(rx_adsi, (xx >> 5) & 0x1F); if (yy) printf("%c", yy); + /*endif*/ } + /*endif*/ yy = adsi_decode_baudot(rx_adsi, xx & 0x1F); if (yy) printf("%c", yy); + /*endif*/ } + /*endwhile*/ adsi_tx_free(tx_adsi); adsi_rx_free(rx_adsi); printf("\n"); @@ -630,6 +669,7 @@ static void basic_tests(int standard) tx_adsi = adsi_tx_init(NULL, standard); if (short_preamble) adsi_tx_set_preamble(tx_adsi, 50, 20, 5, -1); + /*endif*/ rx_adsi = adsi_rx_init(NULL, standard, put_adsi_msg, NULL); /* Fake an OK condition for the first message test */ @@ -641,6 +681,7 @@ static void basic_tests(int standard) { if ((len = adsi_tx(tx_adsi, amp, BLOCK_LEN)) == 0) push = 10; + /*endif*/ } else { @@ -653,11 +694,14 @@ static void basic_tests(int standard) printf("No message received %s (%d)\n", adsi_standard_to_str(standard), i); exit(2); } + /*endif*/ good_message_received = false; adsi_msg_len = adsi_create_message(tx_adsi, adsi_msg); adsi_msg_len = adsi_tx_put_message(tx_adsi, adsi_msg, adsi_msg_len); } + /*endif*/ } + /*endif*/ if (len < BLOCK_LEN) { memset(&[len], 0, sizeof(int16_t)*(BLOCK_LEN - len)); @@ -673,9 +717,12 @@ static void basic_tests(int standard) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } + /*endif*/ adsi_rx(rx_adsi, amp, len); } + /*endfor*/ adsi_rx_free(rx_adsi); adsi_tx_free(tx_adsi); basic_testing = false; @@ -702,22 +749,27 @@ static void mitel_cm7291_side_2_and_bellcore_tests(int standard) printf(" Cannot open speech file '%s'\n", bellcore_files[j]); exit(2); } + /*endif*/ while ((frames = sf_readf_short(inhandle, amp, BLOCK_LEN))) { adsi_rx(rx_adsi, amp, frames); } + /*endwhile*/ if (sf_close_telephony(inhandle)) { printf(" Cannot close speech file '%s'\n", bellcore_files[j]); exit(2); } + /*endif*/ } + /*endfor*/ adsi_rx_free(rx_adsi); if (j > 470) { printf(" Failed\n"); exit(2); } + /*endif*/ printf(" Passed\n"); } /*- End of function --------------------------------------------------------*/ @@ -772,6 +824,7 @@ int main(int argc, char *argv[]) test_standard = ADSI_STANDARD_TDD; else test_standard = atoi(optarg); + /*endif*/ break; case 't': enable_basic_tests = false; @@ -782,7 +835,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ outhandle = NULL; tdd_character_set_tests(); @@ -795,10 +850,12 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ if (test_standard < 0) current_standard = ADSI_STANDARD_CLASS; else current_standard = test_standard; + /*endif*/ rx_adsi = adsi_rx_init(NULL, current_standard, put_adsi_msg, NULL); @@ -810,13 +867,16 @@ int main(int argc, char *argv[]) len = sf_readf_short(inhandle, amp, BLOCK_LEN); if (len == 0) break; + /*endif*/ adsi_rx(rx_adsi, amp, len); } + /*endfor*/ if (sf_close_telephony(inhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ adsi_rx_free(rx_adsi); } else @@ -828,7 +888,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot create audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ /* Go through all the standards */ /* This assumes standard 0 is NULL, and TDD is the last in the list */ if (test_standard < 0) @@ -841,13 +903,17 @@ int main(int argc, char *argv[]) first_standard = last_standard = test_standard; } + /*endif*/ for (current_standard = first_standard; current_standard <= last_standard; current_standard++) { if (enable_basic_tests) basic_tests(current_standard); + /*endif*/ if (enable_talkoff_tests) mitel_cm7291_side_2_and_bellcore_tests(current_standard); + /*endif*/ } + /*endfor*/ if (log_audio) { if (sf_close_telephony(outhandle)) @@ -855,9 +921,12 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ printf("Tests passed.\n"); } + /*endif*/ return 0; } diff --git a/tests/at_interpreter_tests.c b/tests/at_interpreter_tests.c index d771afec..a74c0409 100644 --- a/tests/at_interpreter_tests.c +++ b/tests/at_interpreter_tests.c @@ -446,8 +446,10 @@ static int at_send_hdlc(at_state_t *s, uint8_t *t, int len) { if (*t == DLE) buf[j++] = DLE; + /*endif*/ buf[j++] = *t++; } + /*endfor*/ buf[j++] = DLE; buf[j++] = ETX; at_rx(s, (char *) buf, j); @@ -473,7 +475,9 @@ static int general_test(at_state_t *s) printf("Received: '%s'\n", response_buf); return -1; } + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -543,6 +547,7 @@ static int at_tx_handler(void *user_data, const uint8_t *buf, size_t len) response_buf[response_buf_ptr++] = buf[i]; putchar(buf[i]); } + /*endfor*/ response_buf[response_buf_ptr] = '\0'; return 0; @@ -558,11 +563,13 @@ int main(int argc, char *argv[]) fprintf(stderr, "Cannot start the AT interpreter\n"); exit(2); } + /*endif*/ if (general_test(at_state)) { printf("Tests failed.\n"); exit(2); } + /*endif*/ printf("Tests passed.\n"); at_free(at_state); return 0; diff --git a/tests/awgn_tests.c b/tests/awgn_tests.c index 09e7884e..9dfd2e8e 100644 --- a/tests/awgn_tests.c +++ b/tests/awgn_tests.c @@ -40,7 +40,7 @@ #include "spandsp.h" #if !defined(M_PI) -# define M_PI 3.14159265358979323846 /* pi */ +#define M_PI 3.14159265358979323846 /* pi */ #endif #define OUT_FILE_NAME "awgn.wav" @@ -63,13 +63,15 @@ int main(int argc, char *argv[]) double error; int bins[65536]; awgn_state_t *noise_source; + power_meter_t meter; - /* Generate noise at several RMS levels between -50dBm and 0dBm. Noise is + /* Generate noise at several RMS levels between -50dBm0 and 0dBm0. Noise is generated for a large number of samples (1,000,000), and the RMS value of the noise is calculated along the way. If the resulting level is close to the requested RMS level, at least the scaling of the noise - should be Ok. At high level some clipping may distort the result a + should be OK. At high level some clipping may distort the result a little. */ + power_meter_init(&meter, 10); for (j = -50; j <= 0; j += 5) { clip_high = 0; @@ -80,6 +82,7 @@ int main(int argc, char *argv[]) printf("Failed to allocate AWGN source\n"); exit(2); } + /*endif*/ total_samples = 1000000; for (i = 0; i < total_samples; i++) { @@ -88,8 +91,11 @@ int main(int argc, char *argv[]) clip_high++; else if (value == -32768) clip_low++; + /*endif*/ + power_meter_update(&meter, value); total += ((double) value)*((double) value); } + /*endfor*/ error = 100.0*(1.0 - sqrt(total/total_samples)/noise_source->rms); printf("RMS = %.3f (expected %d) %.2f%% error [clipped samples %d+%d]\n", 10.0*log10((total/total_samples)/(32768.0*32768.0) + 1.0e-10) + DBM0_MAX_POWER, @@ -97,14 +103,18 @@ int main(int argc, char *argv[]) error, clip_low, clip_high); + printf("Power meter says %fdBOv/%fdBm0\n", power_meter_current_dbov(&meter), power_meter_current_dbm0(&meter)); + /* We don't check the result at 0dBm0, as there will definitely be a lot of error due to clipping */ if (j < 0 && fabs(error) > 0.2) { printf("Test failed.\n"); exit(2); } + /*endif*/ awgn_free(noise_source); } + /*endfor*/ /* Now look at the statistical spread of the results, by collecting data in bins from a large number of samples. Use a fairly high noise level, but low enough to avoid significant clipping. Use the Gaussian model to @@ -117,6 +127,7 @@ int main(int argc, char *argv[]) printf("Failed to allocate AWGN source\n"); exit(2); } + /*endif*/ total_samples = 10000000; for (i = 0; i < total_samples; i++) { @@ -125,8 +136,10 @@ int main(int argc, char *argv[]) clip_high++; else if (value == -32768) clip_low++; + /*endif*/ bins[value + 32768]++; } + /*endfor*/ o = noise_source->rms; for (i = 0; i < 65536 - 10; i++) { @@ -138,11 +151,13 @@ int main(int argc, char *argv[]) x = 0; for (j = 0; j < 10; j++) x += bins[i + j]; + /*endfor*/ x /= 10.0; x /= total_samples; /* Now send it out for graphing. */ printf("%6d %.7f %.7f\n", i - 32768, x, p); } + /*endfor*/ awgn_free(noise_source); printf("Tests passed.\n"); return 0; diff --git a/tests/bell_mf_rx_tests.c b/tests/bell_mf_rx_tests.c index 3160c6d7..d5144a23 100644 --- a/tests/bell_mf_rx_tests.c +++ b/tests/bell_mf_rx_tests.c @@ -149,6 +149,7 @@ static void my_mf_gen_init(float low_fudge, 0, false); } + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -166,8 +167,10 @@ static int my_mf_generate(int16_t amp[], const char *digits) tone_gen_init(&tone, &my_mf_digit_tones[cp - bell_mf_tone_codes]); len += tone_gen(&tone, amp + len, 9999); } + /*endif*/ digits++; } + /*endwhile*/ return len; } /*- End of function --------------------------------------------------------*/ @@ -186,6 +189,7 @@ static void digit_delivery(void *data, const char *digits, int len) callback_ok = false; return; } + /*endif*/ callback_ok = true; t = s + callback_roll; seg = 15 - callback_roll; @@ -193,15 +197,18 @@ static void digit_delivery(void *data, const char *digits, int len) { if (i + seg > len) seg = len - i; + /*endif*/ if (memcmp(digits + i, t, seg)) { callback_ok = false; printf("Fail at %d %d\n", i, seg); break; } + /*endif*/ t = s; callback_roll = (callback_roll + seg)%15; } + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -255,8 +262,11 @@ static int test_tone_set(void) printf(" Failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ } + /*endwhile*/ printf(" Passed\n"); /* Test 3: Recognition bandwidth and channel centre frequency check. @@ -302,6 +312,7 @@ static int test_tone_set(void) bell_mf_rx(mf_state, amp, len); nplus += bell_mf_rx_get(mf_state, buf, 128); } + /*endfor*/ for (nminus = 0, i = -1; i >= -60; i--) { my_mf_gen_init((float) i/1000.0, -17, 0.0, -17, 68, 68); @@ -310,6 +321,7 @@ static int test_tone_set(void) bell_mf_rx(mf_state, amp, len); nminus += bell_mf_rx_get(mf_state, buf, 128); } + /*endfor*/ rrb = (float) (nplus + nminus)/10.0; rcfo = (float) (nplus - nminus)/10.0; printf(" %c (low) rrb = %5.2f%%, rcfo = %5.2f%%, max -ve = %5.2f, max +ve = %5.2f\n", @@ -324,6 +336,7 @@ static int test_tone_set(void) printf(" Failed\n"); exit(2); } + /*endif*/ for (nplus = 0, i = 1; i <= 60; i++) { @@ -333,6 +346,7 @@ static int test_tone_set(void) bell_mf_rx(mf_state, amp, len); nplus += bell_mf_rx_get(mf_state, buf, 128); } + /*endfor*/ for (nminus = 0, i = -1; i >= -60; i--) { my_mf_gen_init(0.0, -17, (float) i/1000.0, -17, 68, 68); @@ -341,6 +355,7 @@ static int test_tone_set(void) bell_mf_rx(mf_state, amp, len); nminus += bell_mf_rx_get(mf_state, buf, 128); } + /*endfor*/ rrb = (float) (nplus + nminus)/10.0; rcfo = (float) (nplus - nminus)/10.0; printf(" %c (high) rrb = %5.2f%%, rcfo = %5.2f%%, max -ve = %5.2f, max +ve = %5.2f\n", @@ -354,8 +369,10 @@ static int test_tone_set(void) printf(" Failed\n"); exit(2); } + /*endif*/ j++; } + /*endwhile*/ printf(" Passed\n"); /* Test 4: Acceptable amplitude ratio (twist). @@ -378,12 +395,14 @@ static int test_tone_set(void) bell_mf_rx(mf_state, amp, len); nplus += bell_mf_rx_get(mf_state, buf, 128); } + /*endfor*/ printf(" %c normal twist = %.2fdB\n", digit[0], (float) nplus/10.0); if (nplus < 60) { printf(" Failed\n"); exit(2); } + /*endif*/ for (nminus = 0, i = -50; i >= -250; i--) { my_mf_gen_init(0.0, i/10, 0.0, -5, 68, 68); @@ -393,13 +412,16 @@ static int test_tone_set(void) bell_mf_rx(mf_state, amp, len); nminus += bell_mf_rx_get(mf_state, buf, 128); } + /*endfor*/ printf(" %c reverse twist = %.2fdB\n", digit[0], (float) nminus/10.0); if (nminus < 60) { printf(" Failed\n"); exit(2); } + /*endif*/ } + /*endwhile*/ printf(" Passed\n"); /* Test 5: Dynamic range @@ -419,26 +441,34 @@ static int test_tone_set(void) bell_mf_rx(mf_state, amp, len); if (bell_mf_rx_get(mf_state, buf, 128) != 15) break; + /*endif*/ if (strcmp(buf, ALL_POSSIBLE_DIGITS) != 0) break; + /*endif*/ } + /*endfor*/ if (j == 100) { if (nplus == -1000) nplus = i; + /*endif*/ } else { if (nplus != -1000 && nminus == -1000) nminus = i; + /*endif*/ } + /*endif*/ } + /*endfor*/ printf(" Dynamic range = %ddB to %ddB\n", nplus, nminus - 1); if (nplus > -22 || nminus <= -3) { printf(" Failed\n"); exit(2); } + /*endif*/ printf(" Passed\n"); /* Test 6: Guard time @@ -460,18 +490,24 @@ static int test_tone_set(void) bell_mf_rx(mf_state, amp, len); if (bell_mf_rx_get(mf_state, buf, 128) != 15) break; + /*endif*/ if (strcmp(buf, ALL_POSSIBLE_DIGITS) != 0) break; + /*endif*/ } + /*endfor*/ if (j == 500) break; + /*endif*/ } + /*endfor*/ printf(" Guard time = %dms\n", i); if (i > 61) { printf(" Failed\n"); exit(2); } + /*endif*/ printf(" Passed\n"); /* Test 7: Acceptable signal to noise ratio @@ -492,18 +528,24 @@ static int test_tone_set(void) bell_mf_rx(mf_state, amp, len); if (bell_mf_rx_get(mf_state, buf, 128) != 15) break; + /*endif*/ if (strcmp(buf, ALL_POSSIBLE_DIGITS) != 0) break; + /*endif*/ } + /*endfor*/ if (j == 500) break; + /*endif*/ } + /*endfor*/ printf(" Acceptable S/N ratio is %ddB\n", -3 - i); if (-3 - i > 26) { printf(" Failed\n"); exit(2); } + /*endif*/ bell_mf_rx_free(mf_state); printf(" Passed\n"); @@ -524,15 +566,19 @@ static int test_tone_set(void) len = 0; for (j = 0; j < i; j++) len += my_mf_generate(amp + len, ALL_POSSIBLE_DIGITS); + /*endfor*/ bell_mf_rx(mf_state, amp, len); if (!callback_ok) break; + /*endif*/ } + /*endfor*/ if (!callback_ok) { printf(" Failed\n"); exit(2); } + /*endif*/ bell_mf_rx_free(mf_state); printf(" Passed\n"); return 0; @@ -547,10 +593,12 @@ static void digit_delivery_decode(void *data, const char *digits, int len) { return; } + /*endif*/ for (i = 0; i < len; i++) { printf("Digit '%c'\n", digits[i]); } + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -569,12 +617,14 @@ static void decode_test(const char *test_file) fprintf(stderr, " Cannot open audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ while ((samples = sf_readf_short(inhandle, amp, SAMPLES_PER_CHUNK)) > 0) { codec_munge(munge, amp, samples); bell_mf_rx(mf_state, amp, samples); } + /*endwhile*/ } /*- End of function --------------------------------------------------------*/ @@ -597,7 +647,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ munge = codec_munge_init(MUNGE_CODEC_ULAW, 0); if (decode_test_file) { @@ -610,6 +662,7 @@ int main(int argc, char *argv[]) duration = time (NULL) - now; printf("Tests passed in %lds\n", duration); } + /*endif*/ codec_munge_free(munge); return 0; } diff --git a/tests/bell_mf_tx_tests.c b/tests/bell_mf_tx_tests.c index 6c88f985..75ec6e0a 100644 --- a/tests/bell_mf_tx_tests.c +++ b/tests/bell_mf_tx_tests.c @@ -62,6 +62,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ gen = bell_mf_tx_init(NULL); len = bell_mf_tx(gen, amp, 16384); @@ -69,21 +70,25 @@ int main(int argc, char *argv[]) sf_writef_short(outhandle, amp, len); if (bell_mf_tx_put(gen, "123", -1)) printf("Ooops\n"); + /*endif*/ len = bell_mf_tx(gen, amp, 16384); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); if (bell_mf_tx_put(gen, "456", -1)) printf("Ooops\n"); + /*endif*/ len = bell_mf_tx(gen, amp, 160); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); if (bell_mf_tx_put(gen, "789", -1)) printf("Ooops\n"); + /*endif*/ len = bell_mf_tx(gen, amp, 160); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); if (bell_mf_tx_put(gen, "*#", -1)) printf("Ooops\n"); + /*endif*/ len = bell_mf_tx(gen, amp, 160); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); @@ -94,6 +99,7 @@ int main(int argc, char *argv[]) printf("Generated %d samples\n", len); if (len > 0) sf_writef_short(outhandle, amp, len); + /*endif*/ if (add_digits) { if (bell_mf_tx_put(gen, "1234567890", -1)) @@ -101,7 +107,9 @@ int main(int argc, char *argv[]) printf("Digit buffer full\n"); add_digits = 0; } + /*endif*/ } + /*endif*/ } while (len > 0); @@ -111,26 +119,31 @@ int main(int argc, char *argv[]) sf_writef_short(outhandle, amp, len); if (bell_mf_tx_put(gen, "123", -1)) printf("Ooops\n"); + /*endif*/ len = bell_mf_tx(gen, amp, 16384); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); if (bell_mf_tx_put(gen, "456", -1)) printf("Ooops\n"); + /*endif*/ len = bell_mf_tx(gen, amp, 160); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); if (bell_mf_tx_put(gen, "789", -1)) printf("Ooops\n"); + /*endif*/ len = bell_mf_tx(gen, amp, 160); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); if (bell_mf_tx_put(gen, "0*#", -1)) printf("Ooops\n"); + /*endif*/ len = bell_mf_tx(gen, amp, 160); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); if (bell_mf_tx_put(gen, "ABC", -1)) printf("Ooops\n"); + /*endif*/ len = bell_mf_tx(gen, amp, 160); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); @@ -141,6 +154,7 @@ int main(int argc, char *argv[]) printf("Generated %d samples\n", len); if (len > 0) sf_writef_short(outhandle, amp, len); + /*endif*/ if (add_digits) { if (bell_mf_tx_put(gen, "1234567890", -1)) @@ -148,7 +162,9 @@ int main(int argc, char *argv[]) printf("Digit buffer full\n"); add_digits = 0; } + /*endif*/ } + /*endif*/ } while (len > 0); @@ -157,6 +173,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME); exit (2); } + /*endif*/ bell_mf_tx_free(gen); return 0; diff --git a/tests/bert_tests.c b/tests/bert_tests.c index 214815d6..d2bbda06 100644 --- a/tests/bert_tests.c +++ b/tests/bert_tests.c @@ -65,6 +65,7 @@ static void reporter(void *user_data, int reason, bert_results_t *results) printf("%d bits, %d bad bits, %d resyncs", results->total_bits, results->bad_bits, results->resyncs); break; } + /*endswitch*/ printf("\r"); } /*- End of function --------------------------------------------------------*/ @@ -90,6 +91,7 @@ int main(int argc, char *argv[]) bit = bert_get_bit(tx_bert); bert_put_bit(rx_bert, bit); } + /*endfor*/ bert_result(rx_bert, &bert_results); printf("Zeros: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits); if (bert_results.bad_bits || bert_results.total_bits != 950) @@ -97,6 +99,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ bert_free(tx_bert); bert_free(rx_bert); @@ -107,6 +110,7 @@ int main(int argc, char *argv[]) bit = bert_get_bit(tx_bert); bert_put_bit(rx_bert, bit); } + /*endfor*/ bert_result(rx_bert, &bert_results); printf("Ones: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits); if (bert_results.bad_bits || bert_results.total_bits != 950) @@ -114,6 +118,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ bert_free(tx_bert); bert_free(rx_bert); @@ -124,6 +129,7 @@ int main(int argc, char *argv[]) bit = bert_get_bit(tx_bert); bert_put_bit(rx_bert, bit); } + /*endfor*/ bert_result(rx_bert, &bert_results); printf("1 to 7: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits); if (bert_results.bad_bits || bert_results.total_bits != 950) @@ -131,6 +137,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ bert_free(tx_bert); bert_free(rx_bert); @@ -141,6 +148,7 @@ int main(int argc, char *argv[]) bit = bert_get_bit(tx_bert); bert_put_bit(rx_bert, bit); } + /*endfor*/ bert_result(rx_bert, &bert_results); printf("1 to 3: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits); if (bert_results.bad_bits || bert_results.total_bits != 950) @@ -148,6 +156,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ bert_free(tx_bert); bert_free(rx_bert); @@ -158,6 +167,7 @@ int main(int argc, char *argv[]) bit = bert_get_bit(tx_bert); bert_put_bit(rx_bert, bit); } + /*endfor*/ bert_result(rx_bert, &bert_results); printf("1 to 1: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits); if (bert_results.bad_bits || bert_results.total_bits != 950) @@ -165,6 +175,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ bert_free(tx_bert); bert_free(rx_bert); @@ -175,6 +186,7 @@ int main(int argc, char *argv[]) bit = bert_get_bit(tx_bert); bert_put_bit(rx_bert, bit); } + /*endfor*/ bert_result(rx_bert, &bert_results); printf("3 to 1: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits); if (bert_results.bad_bits || bert_results.total_bits != 950) @@ -182,6 +194,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ bert_free(tx_bert); bert_free(rx_bert); @@ -192,6 +205,7 @@ int main(int argc, char *argv[]) bit = bert_get_bit(tx_bert); bert_put_bit(rx_bert, bit); } + /*endfor*/ bert_result(rx_bert, &bert_results); printf("7 to 1: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits); if (bert_results.bad_bits || bert_results.total_bits != 950) @@ -199,6 +213,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ bert_free(tx_bert); bert_free(rx_bert); @@ -206,6 +221,7 @@ int main(int argc, char *argv[]) rx_bert = bert_init(NULL, 0, BERT_PATTERN_ITU_O153_9, 300, 20); for (i = 0; i < 0x200; i++) test[i] = 0; + /*endfor*/ max_zeros = 0; zeros = 0; for (i = 0; i < 511*2; i++) @@ -215,21 +231,25 @@ int main(int argc, char *argv[]) { if (zeros > max_zeros) max_zeros = zeros; + /*endif*/ zeros = 0; } else { zeros++; } + /*endif*/ bert_put_bit(rx_bert, bit); test[tx_bert->tx.reg]++; } + /*endfor*/ failed = false; if (test[0] != 0) { printf("XXX %d %d\n", 0, test[0]); failed = true; } + /*endif*/ for (i = 1; i < 0x200; i++) { if (test[i] != 2) @@ -237,7 +257,9 @@ int main(int argc, char *argv[]) printf("XXX %d %d\n", i, test[i]); failed = true; } + /*endif*/ } + /*endfor*/ bert_result(rx_bert, &bert_results); printf("O.153(9): Bad bits %d/%d, max zeros %d\n", bert_results.bad_bits, bert_results.total_bits, max_zeros); if (bert_results.bad_bits || bert_results.total_bits != 986 || failed) @@ -245,6 +267,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ bert_free(tx_bert); bert_free(rx_bert); @@ -252,6 +275,7 @@ int main(int argc, char *argv[]) rx_bert = bert_init(NULL, 0, BERT_PATTERN_ITU_O152_11, 300, 20); for (i = 0; i < 0x800; i++) test[i] = 0; + /*endfor*/ max_zeros = 0; zeros = 0; for (i = 0; i < 2047*2; i++) @@ -261,21 +285,25 @@ int main(int argc, char *argv[]) { if (zeros > max_zeros) max_zeros = zeros; + /*endif*/ zeros = 0; } else { zeros++; } + /*endif*/ bert_put_bit(rx_bert, bit); test[tx_bert->tx.reg]++; } + /*endfor*/ failed = false; if (test[0] != 0) { printf("XXX %d %d\n", 0, test[0]); failed = true; } + /*endif*/ for (i = 1; i < 0x800; i++) { if (test[i] != 2) @@ -283,7 +311,9 @@ int main(int argc, char *argv[]) printf("XXX %d %d\n", i, test[i]); failed = true; } + /*endif*/ } + /*endfor*/ bert_result(rx_bert, &bert_results); printf("O.152(11): Bad bits %d/%d, max zeros %d\n", bert_results.bad_bits, bert_results.total_bits, max_zeros); if (bert_results.bad_bits || bert_results.total_bits != 4052 || failed) @@ -291,6 +321,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ bert_free(tx_bert); bert_free(rx_bert); @@ -298,6 +329,7 @@ int main(int argc, char *argv[]) rx_bert = bert_init(NULL, 0, BERT_PATTERN_ITU_O151_15, 300, 20); for (i = 0; i < 0x8000; i++) test[i] = 0; + /*endfor*/ max_zeros = 0; zeros = 0; for (i = 0; i < 32767*2; i++) @@ -307,21 +339,25 @@ int main(int argc, char *argv[]) { if (zeros > max_zeros) max_zeros = zeros; + /*endif*/ zeros = 0; } else { zeros++; } + /*endif*/ bert_put_bit(rx_bert, bit); test[tx_bert->tx.reg]++; } + /*endfor*/ failed = false; if (test[0] != 0) { printf("XXX %d %d\n", 0, test[0]); failed = true; } + /*endif*/ for (i = 1; i < 0x8000; i++) { if (test[i] != 2) @@ -329,7 +365,9 @@ int main(int argc, char *argv[]) printf("XXX %d %d\n", i, test[i]); failed = true; } + /*endif*/ } + /*endfor*/ bert_result(rx_bert, &bert_results); printf("O.151(15): Bad bits %d/%d, max zeros %d\n", bert_results.bad_bits, bert_results.total_bits, max_zeros); if (bert_results.bad_bits || bert_results.total_bits != 65480 || failed) @@ -337,6 +375,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ bert_free(tx_bert); bert_free(rx_bert); @@ -344,6 +383,7 @@ int main(int argc, char *argv[]) rx_bert = bert_init(NULL, 0, BERT_PATTERN_ITU_O151_20, 300, 20); for (i = 0; i < 0x100000; i++) test[i] = 0; + /*endfor*/ max_zeros = 0; zeros = 0; for (i = 0; i < 1048575*2; i++) @@ -359,20 +399,25 @@ int main(int argc, char *argv[]) { zeros++; } + /*endif*/ bert_put_bit(rx_bert, bit); test[tx_bert->tx.reg]++; } + /*endfor*/ failed = false; if (test[0] != 0) { printf("XXX %d %d\n", 0, test[0]); failed = true; } + /*endif*/ for (i = 1; i < 0x100000; i++) { if (test[i] != 2) printf("XXX %d %d\n", i, test[i]); + /*endif*/ } + /*endfor*/ bert_result(rx_bert, &bert_results); printf("O.151(20): Bad bits %d/%d, max zeros %d\n", bert_results.bad_bits, bert_results.total_bits, max_zeros); if (bert_results.bad_bits || bert_results.total_bits != 2097066 || failed) @@ -380,6 +425,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ bert_free(tx_bert); bert_free(rx_bert); @@ -387,6 +433,7 @@ int main(int argc, char *argv[]) rx_bert = bert_init(NULL, 0, BERT_PATTERN_ITU_O151_23, 300, 20); for (i = 0; i < 0x800000; i++) test[i] = 0; + /*endfor*/ max_zeros = 0; zeros = 0; for (i = 0; i < 8388607*2; i++) @@ -396,26 +443,32 @@ int main(int argc, char *argv[]) { if (zeros > max_zeros) max_zeros = zeros; + /*endif*/ zeros = 0; } else { zeros++; } + /*endif*/ bert_put_bit(rx_bert, bit); test[tx_bert->tx.reg]++; } + /*endfor*/ failed = false; if (test[0] != 0) { printf("XXX %d %d\n", 0, test[0]); failed = true; } + /*endif*/ for (i = 1; i < 0x800000; i++) { if (test[i] != 2) printf("XXX %d %d\n", i, test[i]); + /*endif*/ } + /*endfor*/ bert_result(rx_bert, &bert_results); printf("O.151(23): Bad bits %d/%d, max zeros %d\n", bert_results.bad_bits, bert_results.total_bits, max_zeros); if (bert_results.bad_bits || bert_results.total_bits != 16777136 || failed) @@ -423,6 +476,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ bert_free(tx_bert); bert_free(rx_bert); @@ -433,6 +487,7 @@ int main(int argc, char *argv[]) bit = bert_get_bit(tx_bert); bert_put_bit(rx_bert, bit); } + /*endfor*/ bert_result(rx_bert, &bert_results); printf("QBF: Bad bits %d/%d\n", bert_results.bad_bits, bert_results.total_bits); if (bert_results.bad_bits || bert_results.total_bits != 100000) @@ -440,6 +495,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ bert_free(tx_bert); bert_free(rx_bert); @@ -462,17 +518,22 @@ int main(int argc, char *argv[]) printf("Tests failed\n"); exit(2); } + /*endif*/ break; //bert = bert_init(NULL, 15000000, BERT_PATTERN_ITU_O152_11, 300, 20); //bert_set_report(bert, 100000, reporter, (intptr_t) 0); //continue; } + /*endif*/ if ((my_rand() & 0x3FFFF) == 0) bit ^= 1; + /*endif*/ //if ((my_rand() & 0xFFF) == 0) // bert_put_bit(bert, bit); + /*endif*/ bert_put_bit(bert, bit); } + /*endfor*/ bert_free(bert); printf("Tests passed.\n"); diff --git a/tests/bit_operations_tests.c b/tests/bit_operations_tests.c index bee247e6..f28addcb 100644 --- a/tests/bit_operations_tests.c +++ b/tests/bit_operations_tests.c @@ -52,11 +52,14 @@ static __inline__ int top_bit_dumb(unsigned int data) if (data == 0) return -1; + /*endif*/ for (i = 31; i >= 0; i--) { if ((data & (1U << i))) return i; + /*endif*/ } + /*endfor*/ return -1; } /*- End of function --------------------------------------------------------*/ @@ -67,11 +70,14 @@ static __inline__ int bottom_bit_dumb(unsigned int data) if (data == 0) return -1; + /*endif*/ for (i = 0; i < 32; i++) { if ((data & (1U << i))) return i; + /*endif*/ } + /*endfor*/ return -1; } /*- End of function --------------------------------------------------------*/ @@ -87,6 +93,7 @@ static __inline__ uint8_t bit_reverse8_dumb(uint8_t data) result = (result << 1) | (data & 1); data >>= 1; } + /*endfor*/ return result; } /*- End of function --------------------------------------------------------*/ @@ -102,6 +109,7 @@ static __inline__ uint32_t bit_reverse_4bytes_dumb(uint32_t data) result = (result << 1) | (data & 0x01010101); data >>= 1; } + /*endfor*/ return result; } /*- End of function --------------------------------------------------------*/ @@ -117,6 +125,7 @@ static __inline__ uint16_t bit_reverse16_dumb(uint16_t data) result = (result << 1) | (data & 1); data >>= 1; } + /*endfor*/ return result; } /*- End of function --------------------------------------------------------*/ @@ -132,6 +141,7 @@ static __inline__ uint32_t bit_reverse32_dumb(uint32_t data) result = (result << 1) | (data & 1); data >>= 1; } + /*endfor*/ return result; } /*- End of function --------------------------------------------------------*/ @@ -146,6 +156,7 @@ static __inline__ int parity8_dumb(uint8_t x) y ^= (x & 1); x >>= 1; } + /*endfor*/ return y; } /*- End of function --------------------------------------------------------*/ @@ -160,8 +171,10 @@ static __inline__ int one_bits32_dumb(uint32_t x) { if (x & 1) bits++; + /*endif*/ x >>= 1; } + /*endfor*/ return bits; } /*- End of function --------------------------------------------------------*/ @@ -186,6 +199,7 @@ int main(int argc, char *argv[]) printf("Test failed: top bit mismatch 0x%" PRIx32 " -> %u %u\n", x, ax, bx); exit(2); } + /*endif*/ ax = bottom_bit_dumb(x); bx = bottom_bit(x); if (ax != bx) @@ -193,8 +207,10 @@ int main(int argc, char *argv[]) printf("Test failed: bottom bit mismatch 0x%" PRIx32 " -> %u %u\n", x, ax, bx); exit(2); } + /*endif*/ x = rand(); } + /*endfor*/ for (i = 0; i < 256; i++) { ax = bit_reverse8_dumb(i); @@ -204,9 +220,12 @@ int main(int argc, char *argv[]) printf("Test failed: bit reverse 8 - %02x %02x %02x\n", i, ax, bx); exit(2); } + /*endif*/ } + /*endfor*/ for (i = 0; i < 1000000; i++) from[i] = rand(); + /*endfor*/ bit_reverse(to, from, 1000000); for (i = 0; i < 1000000; i++) { @@ -215,7 +234,9 @@ int main(int argc, char *argv[]) printf("Test failed: bit reverse - at %d, %02x %02x %02x\n", i, from[i], bit_reverse8(from[i]), to[i]); exit(2); } + /*endif*/ } + /*endfor*/ for (i = 0; i < 256; i++) { x = i | (((i + 1) & 0xFF) << 8) | (((i + 2) & 0xFF) << 16) | (((i + 3) & 0xFF) << 24); @@ -226,7 +247,9 @@ int main(int argc, char *argv[]) printf("Test failed: bit reverse 4 bytes - %" PRIx32 " %" PRIx32 " %" PRIx32 "\n", x, ax32, bx32); exit(2); } + /*endif*/ } + /*endfor*/ for (i = 0; i < 65536; i++) { ax16 = bit_reverse16_dumb(i); @@ -236,7 +259,9 @@ int main(int argc, char *argv[]) printf("Test failed: bit reverse 16 - %x %x %x\n", i, ax16, bx16); exit(2); } + /*endif*/ } + /*endfor*/ for (i = 0; i < 0x7FFFFF00; i += 127) { ax32 = bit_reverse32_dumb(i); @@ -246,7 +271,9 @@ int main(int argc, char *argv[]) printf("Test failed: bit reverse 32 - %d %" PRIx32 " %" PRIx32 "\n", i, ax32, bx32); exit(2); } + /*endif*/ } + /*endfor*/ for (i = 0; i < 256; i++) { @@ -257,7 +284,9 @@ int main(int argc, char *argv[]) printf("Test failed: parity 8 - %x %x %x\n", i, ax, bx); exit(2); } + /*endif*/ } + /*endfor*/ for (i = -1; i < 32; i++) { @@ -267,13 +296,16 @@ int main(int argc, char *argv[]) printf("Test failed: most significant one 32 - %x %" PRIx32 " %x\n", i, ax32, (1 << i)); exit(2); } + /*endif*/ ax32 = least_significant_one32(1U << i); if (ax32 != (1U << i)) { printf("Test failed: least significant one 32 - %x %" PRIx32 " %x\n", i, ax32, (1 << i)); exit(2); } + /*endif*/ } + /*endfor*/ for (i = 0x80000000; i < 0x800FFFFF; i++) { @@ -284,7 +316,9 @@ int main(int argc, char *argv[]) printf("Test failed: one bits - %d, %x %x\n", i, ax, bx); exit(2); } + /*endif*/ } + /*endfor*/ printf("Tests passed.\n"); return 0; diff --git a/tests/bitstream_tests.c b/tests/bitstream_tests.c index 3e7b441a..a7df01a3 100644 --- a/tests/bitstream_tests.c +++ b/tests/bitstream_tests.c @@ -114,14 +114,17 @@ int main(int argc, char *argv[]) bitstream_put(s, &w, i*PATTERN, i + 1); total_bits += (i + 1); } + /*endfor*/ bitstream_flush(s, &w); printf("%d bits written\n", total_bits); for (cc = buffer; cc < w; cc++) printf("%02X ", *cc); + /*endfor*/ printf("\n"); for (cc = right; cc < right + sizeof(right); cc++) printf("%02X ", *cc); + /*endfor*/ printf("\n"); if ((w - buffer) != sizeof(right) || memcmp(buffer, right, sizeof(right))) @@ -129,6 +132,7 @@ int main(int argc, char *argv[]) printf("Test failed\n"); exit(2); } + /*endif*/ s = bitstream_init(&state, true); r = buffer; @@ -141,7 +145,9 @@ int main(int argc, char *argv[]) printf("Test failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ s = bitstream_init(&state, false); w = buffer; @@ -151,14 +157,17 @@ int main(int argc, char *argv[]) bitstream_put(s, &w, PATTERN*i, i + 1); total_bits += (i + 1); } + /*endfor*/ bitstream_flush(s, &w); printf("%d bits written\n", total_bits); for (cc = buffer; cc < w; cc++) printf("%02X ", *cc); + /*endfor*/ printf("\n"); for (cc = left; cc < left + sizeof(left); cc++) printf("%02X ", *cc); + /*endfor*/ printf("\n"); if ((w - buffer) != sizeof(left) || memcmp(buffer, left, sizeof(left))) @@ -166,6 +175,7 @@ int main(int argc, char *argv[]) printf("Test failed\n"); exit(2); } + /*endif*/ s = bitstream_init(&state, false); r = buffer; @@ -178,7 +188,9 @@ int main(int argc, char *argv[]) printf("Test failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ printf("Tests passed.\n"); return 0; diff --git a/tests/complex_vector_float_tests.c b/tests/complex_vector_float_tests.c index e32ac075..8c2c1e33 100644 --- a/tests/complex_vector_float_tests.c +++ b/tests/complex_vector_float_tests.c @@ -62,10 +62,12 @@ static int test_cvec_mulf(void) y[i].re = rand(); y[i].im = rand(); } + /*endfor*/ cvec_mulf(za, x, y, 99); cvec_mulf_dumb(zb, x, y, 99); for (i = 0; i < 99; i++) printf("(%f,%f) (%f,%f) (%f,%f)\n", za[i].re, za[i].im, x[i].re, x[i].im, y[i].re, y[i].im); + /*endfor*/ for (i = 0; i < 99; i++) { ratio.re = za[i].re/zb[i].re; @@ -78,7 +80,9 @@ static int test_cvec_mulf(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -95,6 +99,7 @@ static complexf_t cvec_dot_prodf_dumb(const complexf_t x[], const complexf_t y[] z1 = complex_mulf(&x[i], &y[i]); z = complex_addf(&z, &z1); } + /*endfor*/ return z; } /*- End of function --------------------------------------------------------*/ @@ -115,6 +120,7 @@ static int test_cvec_dot_prodf(void) y[i].re = rand(); y[i].im = rand(); } + /*endfor*/ for (i = 1; i < 99; i++) { zsa = cvec_dot_prodf(x, y, i); @@ -129,7 +135,9 @@ static int test_cvec_dot_prodf(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/complex_vector_int_tests.c b/tests/complex_vector_int_tests.c index 57fa7a6a..dda219b3 100644 --- a/tests/complex_vector_int_tests.c +++ b/tests/complex_vector_int_tests.c @@ -45,6 +45,7 @@ static complexi32_t cvec_dot_prodi16_dumb(const complexi16_t x[], const complexi z.re += ((int32_t) x[i].re*(int32_t) y[i].re - (int32_t) x[i].im*(int32_t) y[i].im); z.im += ((int32_t) x[i].re*(int32_t) y[i].im + (int32_t) x[i].im*(int32_t) y[i].re); } + /*endfor*/ return z; } /*- End of function --------------------------------------------------------*/ @@ -64,6 +65,7 @@ static int test_cvec_dot_prodi16(void) y[i].re = rand(); y[i].im = rand(); } + /*endfor*/ for (i = 1; i < 99; i++) { @@ -74,7 +76,9 @@ static int test_cvec_dot_prodi16(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -99,6 +103,7 @@ static int test_cvec_circular_dot_prodi16(void) y[i].re = rand(); y[i].im = rand(); } + /*endfor*/ len = 95; for (pos = 0; pos < len; pos++) @@ -111,13 +116,16 @@ static int test_cvec_circular_dot_prodi16(void) zb.re += ((int32_t) x[j].re*(int32_t) y[i].re - (int32_t) x[j].im*(int32_t) y[i].im); zb.im += ((int32_t) x[j].re*(int32_t) y[i].im + (int32_t) x[j].im*(int32_t) y[i].re); } + /*endfor*/ if (za.re != zb.re || za.im != zb.im) { printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/data_modems_tests.c b/tests/data_modems_tests.c index e156f2d3..20eecf84 100644 --- a/tests/data_modems_tests.c +++ b/tests/data_modems_tests.c @@ -118,6 +118,7 @@ static void reporter(void *user_data, int reason, bert_results_t *results) fprintf(stderr, "%d: BERT report reason %d\n", channel, reason); break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -131,6 +132,7 @@ static void put_msg(void *user_data, const uint8_t msg[], int len) { if (len < 0) printf("Status %s\n", signal_status_to_str(len)); + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -164,7 +166,9 @@ static int modem_tests(int use_gui, int log_audio, int test_sending) fprintf(stderr, " Cannot create audio file '%s'\n", OUTPUT_WAVE_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ in_handle = NULL; if (decode_test_file) @@ -174,7 +178,9 @@ static int modem_tests(int use_gui, int log_audio, int test_sending) fprintf(stderr, " Cannot create audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ } + /*endif*/ memset(silence, 0, sizeof(silence)); memset(mdm_amp, 0, sizeof(mdm_amp)); @@ -199,15 +205,18 @@ static int modem_tests(int use_gui, int log_audio, int test_sending) fprintf(stderr, " Cannot start the data modem\n"); exit(2); } + /*endif*/ logging = data_modems_get_logging_state(data_modems_state[i]); span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME); span_log_set_tag(logging, "Modem"); calling_party = false; } + /*endfor*/ #if defined(ENABLE_GUI) if (use_gui) start_media_monitor(); + /*endif*/ #endif while (!done) { @@ -222,22 +231,30 @@ static int modem_tests(int use_gui, int log_audio, int test_sending) vec_zeroi16(mdm_amp + mdm_len, SAMPLES_PER_CHUNK - mdm_len); mdm_len = SAMPLES_PER_CHUNK; } + /*endif*/ if (log_audio) { for (k = 0; k < mdm_len; k++) out_amp[2*k + i] = mdm_amp[k]; + /*endfor*/ } + /*endif*/ if (data_modems_rx(data_modems_state[i ^ 1], mdm_amp, mdm_len)) break; + /*endif*/ } + /*endif*/ if (log_audio) { outframes = sf_writef_short(wave_handle, out_amp, SAMPLES_PER_CHUNK); if (outframes != SAMPLES_PER_CHUNK) break; + /*endif*/ } + /*endif*/ } + /*endif*/ if (decode_test_file) { @@ -246,7 +263,9 @@ static int modem_tests(int use_gui, int log_audio, int test_sending) fprintf(stderr, " Cannot close audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ } + /*endif*/ if (log_audio) { if (sf_close_telephony(wave_handle)) @@ -254,13 +273,16 @@ static int modem_tests(int use_gui, int log_audio, int test_sending) fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_WAVE_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ if (!done || !sequence_terminated) { printf("Tests failed\n"); return 2; } + /*endif*/ return 0; } @@ -306,7 +328,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ modem_tests(use_gui, log_audio, test_sending); printf("Tests passed\n"); diff --git a/tests/dc_restore_tests.c b/tests/dc_restore_tests.c index 0150aa02..f2805ee1 100644 --- a/tests/dc_restore_tests.c +++ b/tests/dc_restore_tests.c @@ -38,7 +38,7 @@ #include "spandsp.h" -int main (int argc, char *argv[]) +int main(int argc, char *argv[]) { awgn_state_t *noise_source; dc_restore_state_t dc_state; @@ -64,7 +64,9 @@ int main (int argc, char *argv[]) dc_restore_estimate(&dc_state), dc_offset); } + /*endif*/ } + /*endfor*/ /* We should have settled by now. Look at the variation we get */ min = 99999; max = -99999; @@ -75,15 +77,19 @@ int main (int argc, char *argv[]) estimate = dc_restore_estimate(&dc_state); if (estimate < min) min = estimate; + /*endif*/ if (estimate > max) max = estimate; + /*endif*/ } + /*endfor*/ printf("Spread of DC estimate for an offset of %d was %d to %d\n", dc_offset, min, max); if (min < dc_offset - 50 || max > dc_offset + 50) { printf("Test failed.\n"); exit(2); } + /*endif*/ awgn_free(noise_source); printf("Test passed.\n"); return 0; diff --git a/tests/dds_tests.c b/tests/dds_tests.c index 27095b61..ff5193ab 100644 --- a/tests/dds_tests.c +++ b/tests/dds_tests.c @@ -73,10 +73,11 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot create audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ phase = 0; - printf("Test with 123.456789Hz.\n"); + printf("Test with 123.456789Hz at -10dBm0.\n"); phase_inc = dds_phase_rate(123.456789f); scale = dds_scaling_dbm0(-10.0f); for (i = 0; i < SAMPLES_PER_CHUNK; i++) @@ -84,32 +85,37 @@ int main(int argc, char *argv[]) buf[i] = alaw_to_linear(linear_to_alaw((dds(&phase, phase_inc)*scale) >> 15)); power_meter_update(&meter, buf[i]); } + /*endfor*/ outframes = sf_writef_short(outhandle, buf, SAMPLES_PER_CHUNK); if (outframes != SAMPLES_PER_CHUNK) { fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ printf("Level is %fdBOv/%fdBm0\n", power_meter_current_dbov(&meter), power_meter_current_dbm0(&meter)); if (fabs(power_meter_current_dbm0(&meter) + 10.0f) > 0.1f) { printf("Test failed.\n"); exit(2); } + /*endif*/ - printf("Test with 12.3456789Hz.\n"); + printf("Test with 12.3456789Hz at full scale.\n"); phase_inc = dds_phase_rate(12.3456789f); for (i = 0; i < SAMPLES_PER_CHUNK; i++) { buf[i] = alaw_to_linear(linear_to_alaw(dds(&phase, phase_inc))); power_meter_update(&meter, buf[i]); } + /*endfor*/ outframes = sf_writef_short(outhandle, buf, SAMPLES_PER_CHUNK); if (outframes != SAMPLES_PER_CHUNK) { fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ printf("Level is %fdBOv/%fdBm0\n", power_meter_current_dbov(&meter), power_meter_current_dbm0(&meter)); /* Use a wider tolerance for this very low frequency - the power meter will ripple */ if (fabs(power_meter_current_dbov(&meter) + 3.02f) > 0.2f) @@ -117,8 +123,9 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ - printf("Test with 2345.6789Hz.\n"); + printf("Test with 2345.6789Hz at -10dBov.\n"); phase_inc = dds_phase_rate(2345.6789f); scale = dds_scaling_dbov(-10.0f); for (i = 0; i < SAMPLES_PER_CHUNK; i++) @@ -126,44 +133,51 @@ int main(int argc, char *argv[]) buf[i] = alaw_to_linear(linear_to_alaw((dds(&phase, phase_inc)*scale) >> 15)); power_meter_update(&meter, buf[i]); } + /*endfor*/ outframes = sf_writef_short(outhandle, buf, SAMPLES_PER_CHUNK); if (outframes != SAMPLES_PER_CHUNK) { fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ printf("Level is %fdBOv/%fdBm0\n", power_meter_current_dbov(&meter), power_meter_current_dbm0(&meter)); if (fabs(power_meter_current_dbov(&meter) + 10.0f) > 0.1f) { printf("Test failed.\n"); exit(2); } + /*endif*/ - printf("Test with 3456.789Hz.\n"); + printf("Test with 3456.789Hz at full scale.\n"); phase_inc = dds_phase_rate(3456.789f); for (i = 0; i < SAMPLES_PER_CHUNK; i++) { buf[i] = alaw_to_linear(linear_to_alaw(dds(&phase, phase_inc))); power_meter_update(&meter, buf[i]); } + /*endfor*/ outframes = sf_writef_short(outhandle, buf, SAMPLES_PER_CHUNK); if (outframes != SAMPLES_PER_CHUNK) { fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ printf("Level is %fdBOv/%fdBm0\n", power_meter_current_dbov(&meter), power_meter_current_dbm0(&meter)); if (fabs(power_meter_current_dbov(&meter) + 3.02f) > 0.05f) { printf("Test failed.\n"); exit(2); } + /*endif*/ if (sf_close_telephony(outhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ printf("Complex DDS tests,\n"); if ((outhandle = sf_open_telephony_write(OUTPUT_FILE_NAME_COMPLEX, 2)) == NULL) @@ -171,7 +185,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot create audio file '%s'\n", OUTPUT_FILE_NAME_COMPLEX); exit(2); } + /*endif*/ + printf("Test with 123.456789Hz at -7dBm0/-13.22dBov.\n"); power_meter_init(&meter_i, 7); power_meter_init(&meter_q, 7); @@ -183,32 +199,36 @@ int main(int argc, char *argv[]) buf[2*i] = camp.re*10000.0f; buf[2*i + 1] = camp.im*10000.0f; power_meter_update(&meter_i, buf[2*i]); - power_meter_update(&meter_q, buf[2*i]); + power_meter_update(&meter_q, buf[2*i + 1]); } + /*endfor*/ outframes = sf_writef_short(outhandle, buf, SAMPLES_PER_CHUNK); if (outframes != SAMPLES_PER_CHUNK) { fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ printf("Level is %fdBOv/%fdBm0, %fdBOv/%fdBm0\n", power_meter_current_dbov(&meter_i), power_meter_current_dbm0(&meter_i), power_meter_current_dbov(&meter_q), power_meter_current_dbm0(&meter_q)); - if (fabs(power_meter_current_dbov(&meter_i) + 13.42f) > 0.05f + if (fabs(power_meter_current_dbov(&meter_i) + 13.42f) > 0.2f || - fabs(power_meter_current_dbov(&meter_q) + 13.42f) > 0.05f) + fabs(power_meter_current_dbov(&meter_q) + 13.42f) > 0.2f) { printf("Test failed.\n"); exit(2); } + /*endif*/ if (sf_close_telephony(outhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME_COMPLEX); exit(2); } + /*endif*/ printf("Tests passed.\n"); return 0; diff --git a/tests/dtmf_rx_tests.c b/tests/dtmf_rx_tests.c index d0fa87a3..ccb1fb33 100644 --- a/tests/dtmf_rx_tests.c +++ b/tests/dtmf_rx_tests.c @@ -187,7 +187,9 @@ static void my_dtmf_gen_init(float low_fudge, 0, false); } + /*endfor*/ } + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -206,8 +208,10 @@ static int my_dtmf_generate(int16_t amp[], const char *digits) tone_gen_init(&tone, &my_dtmf_digit_tones[cp - dtmf_positions]); len += tone_gen(&tone, amp + len, 1000); } + /*endif*/ digits++; } + /*endwhile*/ return len; } /*- End of function --------------------------------------------------------*/ @@ -228,20 +232,24 @@ static void digit_delivery(void *data, const char *digits, int len) { if (i + seg > len) seg = len - i; + /*endif*/ if (memcmp(digits + i, t, seg)) { callback_ok = false; printf("Fail at %d %d\n", i, seg); break; } + /*endif*/ t = s; callback_roll = (callback_roll + seg)%16; } + /*endfor*/ } else { callback_ok = false; } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -269,7 +277,9 @@ static void digit_status(void *data, int signal, int level, int delay) printf("Failed for signal %s length %d at %d\n", (callback_roll & 1) ? "on" : "off", len, step); callback_ok = false; } + /*endif*/ } + /*endif*/ if (callback_roll & 1) { if (signal != 0) @@ -277,6 +287,7 @@ static void digit_status(void *data, int signal, int level, int delay) printf("Failed for signal 0x%X instead of 0\n", signal); callback_ok = false; } + /*endif*/ } else { @@ -285,19 +296,24 @@ static void digit_status(void *data, int signal, int level, int delay) printf("Failed for signal 0x%X instead of 0x%X\n", signal, s[callback_roll >> 1]); callback_ok = false; } - if (level < DEFAULT_DTMF_TX_LEVEL + 3 - 1 || level > DEFAULT_DTMF_TX_LEVEL + 3 + 1) + /*endif*/ + if (level < DEFAULT_DTMF_TX_LEVEL - 1 || level > DEFAULT_DTMF_TX_LEVEL + 1) { - printf("Failed for level %d instead of %d\n", level, DEFAULT_DTMF_TX_LEVEL + 3); + printf("Failed for level %d instead of %d\n", level, DEFAULT_DTMF_TX_LEVEL); callback_ok = false; } + /*endif*/ } + /*endif*/ if (++callback_roll >= 32) callback_roll = 0; + /*endif*/ } else { callback_ok = false; } + /*endif*/ last_step = step; } /*- End of function --------------------------------------------------------*/ @@ -323,6 +339,7 @@ static void mitel_cm7291_side_1_tests(void) dtmf_state = dtmf_rx_init(NULL, NULL, NULL); if (use_dialtone_filter || max_forward_twist >= 0.0f || max_reverse_twist >= 0.0f) dtmf_rx_parms(dtmf_state, use_dialtone_filter, max_forward_twist, max_reverse_twist, -99.0f); + /*endif*/ logging = dtmf_rx_get_logging_state(dtmf_state); span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); span_log_set_tag(logging, "DTMF-rx"); @@ -359,8 +376,11 @@ static void mitel_cm7291_side_1_tests(void) printf(" Failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ } + /*endwhile*/ printf(" Passed\n"); /* Test 3: Recognition bandwidth and channel centre frequency check. @@ -405,6 +425,7 @@ static void mitel_cm7291_side_1_tests(void) dtmf_rx(dtmf_state, amp, len); nplus += dtmf_rx_get(dtmf_state, buf, 128); } + /*endfor*/ for (nminus = 0, i = -1; i >= -60; i--) { my_dtmf_gen_init((float) i/1000.0f, -17, 0.0f, -17, 50, 50); @@ -413,6 +434,7 @@ static void mitel_cm7291_side_1_tests(void) dtmf_rx(dtmf_state, amp, len); nminus += dtmf_rx_get(dtmf_state, buf, 128); } + /*endfor*/ rrb = (float) (nplus + nminus)/10.0f; rcfo = (float) (nplus - nminus)/10.0f; printf(" %c (low) rrb = %5.2f%%, rcfo = %5.2f%%, max -ve = %5.2f, max +ve = %5.2f\n", @@ -426,6 +448,7 @@ static void mitel_cm7291_side_1_tests(void) printf(" Failed\n"); exit(2); } + /*endif*/ for (nplus = 0, i = 1; i <= 60; i++) { @@ -435,6 +458,7 @@ static void mitel_cm7291_side_1_tests(void) dtmf_rx(dtmf_state, amp, len); nplus += dtmf_rx_get(dtmf_state, buf, 128); } + /*endfor*/ for (nminus = 0, i = -1; i >= -60; i--) { my_dtmf_gen_init(0.0f, -17, (float) i/1000.0f, -17, 50, 50); @@ -443,6 +467,7 @@ static void mitel_cm7291_side_1_tests(void) dtmf_rx(dtmf_state, amp, len); nminus += dtmf_rx_get(dtmf_state, buf, 128); } + /*endfor*/ rrb = (float) (nplus + nminus)/10.0f; rcfo = (float) (nplus - nminus)/10.0f; printf(" %c (high) rrb = %5.2f%%, rcfo = %5.2f%%, max -ve = %5.2f, max +ve = %5.2f\n", @@ -456,7 +481,9 @@ static void mitel_cm7291_side_1_tests(void) printf(" Failed\n"); exit(2); } + /*endif*/ } + /*endwhile*/ printf(" Passed\n"); /* Test 4: Acceptable amplitude ratio (twist). @@ -497,12 +524,14 @@ static void mitel_cm7291_side_1_tests(void) dtmf_rx(dtmf_state, amp, len); nplus += dtmf_rx_get(dtmf_state, buf, 128); } + /*endfor*/ printf(" %c normal twist = %.2fdB\n", digit[0], (float) nplus/10.0); if (nplus < 80) { printf(" Failed\n"); exit(2); } + /*endif*/ for (nminus = 0, i = -30; i >= -230; i--) { my_dtmf_gen_init(0.0f, i/10, 0.0f, -3, 50, 50); @@ -512,13 +541,16 @@ static void mitel_cm7291_side_1_tests(void) dtmf_rx(dtmf_state, amp, len); nminus += dtmf_rx_get(dtmf_state, buf, 128); } + /*endfor*/ printf(" %c reverse twist = %.2fdB\n", digit[0], (float) nminus/10.0); if (nminus < 40) { printf(" Failed\n"); exit(2); } + /*endif*/ } + /*endwhile*/ printf(" Passed\n"); /* Test 5: Dynamic range @@ -540,6 +572,7 @@ static void mitel_cm7291_side_1_tests(void) dtmf_rx(dtmf_state, amp, len); nplus += dtmf_rx_get(dtmf_state, buf, 128); } + /*endfor*/ printf(" Dynamic range = %ddB\n", nplus); /* We ought to set some pass/fail condition, even if Mitel did not. If we don't, regression testing is weakened. */ @@ -548,6 +581,7 @@ static void mitel_cm7291_side_1_tests(void) printf(" Failed\n"); exit(2); } + /*endif*/ printf(" Passed\n"); /* Test 6: Guard time @@ -569,6 +603,7 @@ static void mitel_cm7291_side_1_tests(void) dtmf_rx(dtmf_state, amp, len); nplus += dtmf_rx_get(dtmf_state, buf, 128); } + /*endfor*/ printf(" Guard time = %dms\n", (500 - nplus)/10); printf(" Passed\n"); @@ -597,22 +632,27 @@ static void mitel_cm7291_side_1_tests(void) // TODO: Clip for (sample = 0; sample < len; sample++) amp[sample] = sat_add16(amp[sample], awgn(&noise_source)); + /*endfor*/ codec_munge(munge, amp, len); dtmf_rx(dtmf_state, amp, len); if (dtmf_rx_get(dtmf_state, buf, 128) != 1) break; + /*endif*/ } if (i == 1000) break; + /*endif*/ } + /*endfor*/ printf(" Acceptable S/N ratio is %ddB\n", -4 - j); if (-4 - j > 26) { printf(" Failed\n"); exit(2); } + /*endif*/ dtmf_rx_free(dtmf_state); printf(" Passed\n"); } @@ -634,6 +674,7 @@ static void mitel_cm7291_side_2_and_bellcore_tests(void) dtmf_state = dtmf_rx_init(NULL, NULL, NULL); if (use_dialtone_filter || max_forward_twist >= 0.0f || max_reverse_twist >= 0.0f) dtmf_rx_parms(dtmf_state, use_dialtone_filter, max_forward_twist, max_reverse_twist, -99.0f); + /*endif*/ logging = dtmf_rx_get_logging_state(dtmf_state); span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); span_log_set_tag(logging, "DTMF-rx"); @@ -653,6 +694,7 @@ static void mitel_cm7291_side_2_and_bellcore_tests(void) printf(" Cannot open speech file '%s'\n", bellcore_files[j]); exit(2); } + /*endif*/ hits = 0; while ((frames = sf_readf_short(inhandle, amp, SAMPLE_RATE))) { @@ -662,16 +704,21 @@ static void mitel_cm7291_side_2_and_bellcore_tests(void) { for (i = 0; i < len; i++) hit_types[(int) buf[i]]++; + /*endfor*/ hits += len; } + /*endif*/ } + /*endwhile*/ if (sf_close_telephony(inhandle)) { printf(" Cannot close speech file '%s'\n", bellcore_files[j]); exit(2); } + /*endif*/ printf(" File %d gave %d false hits.\n", j + 1, hits); } + /*endfor*/ for (i = 0, j = 0; i < 256; i++) { if (hit_types[i]) @@ -679,13 +726,16 @@ static void mitel_cm7291_side_2_and_bellcore_tests(void) printf(" Digit %c had %d false hits.\n", i, hit_types[i]); j += hit_types[i]; } + /*endif*/ } + /*endfor*/ printf(" %d false hits in total.\n", j); if (j > 470) { printf(" Failed\n"); exit(2); } + /*endif*/ printf(" Passed\n"); dtmf_rx_free(dtmf_state); } @@ -706,6 +756,7 @@ static void dial_tone_tolerance_tests(void) dtmf_state = dtmf_rx_init(NULL, NULL, NULL); if (use_dialtone_filter || max_forward_twist >= 0.0f || max_reverse_twist >= 0.0f) dtmf_rx_parms(dtmf_state, use_dialtone_filter, max_forward_twist, max_reverse_twist, -99.0f); + /*endif*/ logging = dtmf_rx_get_logging_state(dtmf_state); span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); span_log_set_tag(logging, "DTMF-rx"); @@ -725,15 +776,20 @@ static void dial_tone_tolerance_tests(void) for (sample = 0; sample < len; sample++) amp[sample] = sat_add16(amp[sample], amp2[sample]); + /*endfor*/ codec_munge(munge, amp, len); dtmf_rx(dtmf_state, amp, len); if (dtmf_rx_get(dtmf_state, buf, 128) != strlen(ALL_POSSIBLE_DIGITS)) break; + /*endif*/ } + /*endfor*/ if (i != 10) break; + /*endif*/ } + /*endfor*/ printf(" Acceptable signal to dial tone ratio is %ddB\n", -15 - j); if ((use_dialtone_filter && (-15 - j) > -12) || @@ -742,6 +798,7 @@ static void dial_tone_tolerance_tests(void) printf(" Failed\n"); exit(2); } + /*endif*/ printf(" Passed\n"); dtmf_rx_free(dtmf_state); } @@ -764,6 +821,7 @@ static void callback_function_tests(void) dtmf_state = dtmf_rx_init(NULL, digit_delivery, (void *) 0x12345678); if (use_dialtone_filter || max_forward_twist >= 0.0f || max_reverse_twist >= 0.0f) dtmf_rx_parms(dtmf_state, use_dialtone_filter, max_forward_twist, max_reverse_twist, -99.0f); + /*endif*/ logging = dtmf_rx_get_logging_state(dtmf_state); span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); span_log_set_tag(logging, "DTMF-rx"); @@ -774,15 +832,19 @@ static void callback_function_tests(void) len = 0; for (j = 0; j < i; j++) len += my_dtmf_generate(amp + len, ALL_POSSIBLE_DIGITS); + /*endfor*/ dtmf_rx(dtmf_state, amp, len); if (!callback_hit || !callback_ok) break; + /*endif*/ } + /*endfor*/ if (!callback_hit || !callback_ok) { printf(" Failed\n"); exit(2); } + /*endif*/ printf(" Passed\n"); /* Test the realtime callback mode for reporting detected digits */ @@ -794,6 +856,7 @@ static void callback_function_tests(void) dtmf_rx_set_realtime_callback(dtmf_state, digit_status, (void *) 0x12345678); if (use_dialtone_filter || max_forward_twist >= 0.0f || max_reverse_twist >= 0.0f) dtmf_rx_parms(dtmf_state, use_dialtone_filter, max_forward_twist, max_reverse_twist, -99.0f); + /*endif*/ logging = dtmf_rx_get_logging_state(dtmf_state); span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); span_log_set_tag(logging, "DTMF-rx"); @@ -805,21 +868,27 @@ static void callback_function_tests(void) len = 0; for (j = 0; j < i; j++) len += my_dtmf_generate(amp + len, ALL_POSSIBLE_DIGITS); + /*endfor*/ for (sample = 0, j = SAMPLES_PER_CHUNK; sample < len; sample += SAMPLES_PER_CHUNK, j = ((len - sample) >= SAMPLES_PER_CHUNK) ? SAMPLES_PER_CHUNK : (len - sample)) { dtmf_rx(dtmf_state, &[sample], j); if (!callback_ok) break; + /*endif*/ step += j; } + /*endfor*/ if (!callback_hit || !callback_ok) break; + /*endif*/ } + /*endfor*/ if (!callback_hit || !callback_ok) { printf(" Failed\n"); exit(2); } + /*endif*/ dtmf_rx_free(dtmf_state); } /*- End of function --------------------------------------------------------*/ @@ -838,6 +907,7 @@ static void decode_test(const char *test_file) dtmf_state = dtmf_rx_init(NULL, NULL, NULL); if (use_dialtone_filter || max_forward_twist >= 0.0f || max_reverse_twist >= 0.0f) dtmf_rx_parms(dtmf_state, use_dialtone_filter, max_forward_twist, max_reverse_twist, -99.0f); + /*endif*/ logging = dtmf_rx_get_logging_state(dtmf_state); span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); span_log_set_tag(logging, "DTMF-rx"); @@ -849,6 +919,7 @@ static void decode_test(const char *test_file) fprintf(stderr, " Cannot open audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ total = 0; while ((samples = sf_readf_short(inhandle, amp, SAMPLES_PER_CHUNK)) > 0) @@ -858,8 +929,10 @@ static void decode_test(const char *test_file) //printf("Status 0x%X\n", dtmf_rx_status(dtmf_state)); if ((actual = dtmf_rx_get(dtmf_state, buf, 128)) > 0) printf("Received '%s'\n", buf); + /*endif*/ total += actual; } + /*endwhile*/ printf("%d digits received\n", total); } /*- End of function --------------------------------------------------------*/ @@ -900,7 +973,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ munge = codec_munge_init(channel_codec, 0); if (decode_test_file) @@ -918,6 +993,7 @@ int main(int argc, char *argv[]) duration = time(NULL) - now; printf("Tests passed in %ds\n", duration); } + /*endif*/ codec_munge_free(munge); return 0; diff --git a/tests/dtmf_tx_tests.c b/tests/dtmf_tx_tests.c index 1d0ad291..3b60cfe7 100644 --- a/tests/dtmf_tx_tests.c +++ b/tests/dtmf_tx_tests.c @@ -62,6 +62,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ gen = dtmf_tx_init(NULL, NULL, NULL); len = dtmf_tx(gen, amp, 16384); @@ -72,6 +73,7 @@ int main(int argc, char *argv[]) printf("Ooops\n"); exit(2); } + /*endif*/ len = dtmf_tx(gen, amp, 16384); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); @@ -80,6 +82,7 @@ int main(int argc, char *argv[]) printf("Ooops\n"); exit(2); } + /*endif*/ len = dtmf_tx(gen, amp, 160); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); @@ -88,6 +91,7 @@ int main(int argc, char *argv[]) printf("Ooops\n"); exit(2); } + /*endif*/ len = dtmf_tx(gen, amp, 160); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); @@ -96,6 +100,7 @@ int main(int argc, char *argv[]) printf("Ooops\n"); exit(2); } + /*endif*/ len = dtmf_tx(gen, amp, 160); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); @@ -106,6 +111,7 @@ int main(int argc, char *argv[]) printf("Generated %d samples\n", len); if (len > 0) sf_writef_short(outhandle, amp, len); + /*endif*/ if (add_digits) { if (dtmf_tx_put(gen, "1234567890", -1)) @@ -113,7 +119,9 @@ int main(int argc, char *argv[]) printf("Digit buffer full\n"); add_digits = 0; } + /*endif*/ } + /*endif*/ } while (len > 0); @@ -126,6 +134,7 @@ int main(int argc, char *argv[]) printf("Ooops\n"); exit(2); } + /*endif*/ len = dtmf_tx(gen, amp, 16384); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); @@ -134,6 +143,7 @@ int main(int argc, char *argv[]) printf("Ooops\n"); exit(2); } + /*endif*/ len = dtmf_tx(gen, amp, 160); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); @@ -142,6 +152,7 @@ int main(int argc, char *argv[]) printf("Ooops\n"); exit(2); } + /*endif*/ len = dtmf_tx(gen, amp, 160); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); @@ -150,6 +161,7 @@ int main(int argc, char *argv[]) printf("Ooops\n"); exit(2); } + /*endif*/ len = dtmf_tx(gen, amp, 160); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); @@ -158,6 +170,7 @@ int main(int argc, char *argv[]) printf("Ooops\n"); exit(2); } + /*endif*/ len = dtmf_tx(gen, amp, 160); printf("Generated %d samples\n", len); sf_writef_short(outhandle, amp, len); @@ -171,12 +184,14 @@ int main(int argc, char *argv[]) printf("Ooops\n"); exit(2); } + /*endif*/ do { len = dtmf_tx(gen, amp, 160); printf("Generated %d samples\n", len); if (len > 0) sf_writef_short(outhandle, amp, len); + /*endif*/ } while (len > 0); printf("Restore normal levels and timing\n"); @@ -187,6 +202,7 @@ int main(int argc, char *argv[]) printf("Ooops\n"); exit(2); } + /*endif*/ add_digits = true; do @@ -195,6 +211,7 @@ int main(int argc, char *argv[]) printf("Generated %d samples\n", len); if (len > 0) sf_writef_short(outhandle, amp, len); + /*endif*/ if (add_digits) { if (dtmf_tx_put(gen, "1234567890", -1)) @@ -202,7 +219,9 @@ int main(int argc, char *argv[]) printf("Digit buffer full\n"); add_digits = false; } + /*endif*/ } + /*endif*/ } while (len > 0); @@ -211,6 +230,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ dtmf_tx_free(gen); return 0; diff --git a/tests/echo_monitor.cpp b/tests/echo_monitor.cpp index ecea0f6b..c85e1e07 100644 --- a/tests/echo_monitor.cpp +++ b/tests/echo_monitor.cpp @@ -106,6 +106,7 @@ int echo_can_monitor_can_update(const int16_t *coeffs, int len) if (s->can_re) delete s->can_re; + /*endif*/ s->canvas_can->current(s->canvas_can); i = 0; @@ -117,9 +118,12 @@ int echo_can_monitor_can_update(const int16_t *coeffs, int len) s->can_re_plot[2*i + 1] = coeffs[i]; if (min > coeffs[i]) min = coeffs[i]; + /*endif*/ if (max < coeffs[i]) max = coeffs[i]; + /*endif*/ } + /*endfor*/ s->can_y->maximum((max == min) ? max + 0.2 : max); s->can_y->minimum(min); s->can_re = new Ca_Line(len, s->can_re_plot, 0, 0, FL_BLUE, CA_NO_POINT); @@ -128,6 +132,7 @@ int echo_can_monitor_can_update(const int16_t *coeffs, int len) skip = 0; Fl::check(); } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -140,6 +145,7 @@ int echo_can_monitor_line_model_update(const int32_t *coeffs, int len) if (s->line_model_re) delete s->line_model_re; + /*endif*/ s->canvas_line_model->current(s->canvas_line_model); i = 0; @@ -151,9 +157,12 @@ int echo_can_monitor_line_model_update(const int32_t *coeffs, int len) s->line_model_re_plot[2*i + 1] = coeffs[i]; if (min > coeffs[i]) min = coeffs[i]; + /*endif*/ if (max < coeffs[i]) max = coeffs[i]; + /*endif*/ } + /*endfor*/ s->line_model_y->maximum((max == min) ? max + 0.2 : max); s->line_model_y->minimum(min); s->line_model_re = new Ca_Line(len, s->line_model_re_plot, 0, 0, FL_BLUE, CA_NO_POINT); @@ -162,6 +171,7 @@ int echo_can_monitor_line_model_update(const int32_t *coeffs, int len) skip = 0; Fl::check(); } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -173,47 +183,61 @@ int echo_can_monitor_line_spectrum_update(const int16_t amp[], int len) for (i = 0; i < len; i++) s->audio_meter->sample(amp[i]/32768.0); + /*endfor*/ if (s->in_ptr + len < 512) { /* Just add this fragment to the buffer. */ for (i = 0; i < len; i++) + { #if defined(HAVE_FFTW3_H) s->in[s->in_ptr + i][0] = amp[i]; #else s->in[s->in_ptr + i].re = amp[i]; #endif + } + /*endfor*/ s->in_ptr += len; return 0; } + /*endif*/ if (len >= 512) { /* We have enough for a whole block. Use the last 512 samples we have. */ x = len - 512; for (i = 0; i < 512; i++) + { #if defined(HAVE_FFTW3_H) s->in[i][0] = amp[x + i]; #else s->in[i].re = amp[x + i]; #endif + } + /*endfor*/ } else { /* We want the last 512 samples. */ x = 512 - len; for (i = 0; i < x; i++) + { #if defined(HAVE_FFTW3_H) s->in[i][0] = s->in[s->in_ptr - x + i][0]; #else s->in[i].re = s->in[s->in_ptr - x + i].re; #endif + } + /*endfor*/ for (i = x; i < 512; i++) + { #if defined(HAVE_FFTW3_H) s->in[i][0] = amp[i - x]; #else s->in[i].re = amp[i - x]; #endif + } + /*endfor*/ } s->in_ptr = 0; #if defined(HAVE_FFTW3_H) @@ -223,6 +247,7 @@ int echo_can_monitor_line_spectrum_update(const int16_t amp[], int len) #endif if (s->spec_re) delete s->spec_re; + /*endif*/ s->canvas_spec->current(s->canvas_spec); for (i = 0; i < 512; i++) { @@ -233,6 +258,7 @@ int echo_can_monitor_line_spectrum_update(const int16_t amp[], int len) s->spec_re_plot[2*i + 1] = 10.0*log10((s->out[i].re*s->out[i].re + s->out[i].im*s->out[i].im)/(256.0*32768*256.0*32768) + 1.0e-10) + 3.14; #endif } + /*endif*/ s->spec_re = new Ca_Line(512, s->spec_re_plot, 0, 0, FL_BLUE, CA_NO_POINT); Fl::check(); return 0; @@ -401,6 +427,7 @@ int start_echo_can_monitor(int len) s->in[i][0] = 0.0; s->in[i][1] = 0.0; } + /*endfor*/ #else s->p = fftw_create_plan(1024, FFTW_BACKWARD, FFTW_ESTIMATE); for (i = 0; i < 1024; i++) @@ -408,6 +435,7 @@ int start_echo_can_monitor(int len) s->in[i].re = 0.0; s->in[i].im = 0.0; } + /*endfor*/ #endif s->in_ptr = 0; diff --git a/tests/echo_tests.c b/tests/echo_tests.c index fbca40f6..0005296e 100644 --- a/tests/echo_tests.c +++ b/tests/echo_tests.c @@ -169,8 +169,10 @@ static void dump_ec_state(echo_can_state_t *ctx) if ((f = fopen("echo_tests_state.txt", "wt")) == NULL) return; + /*endif*/ for (i = 0; i < TEST_EC_TAPS; i++) fprintf(f, "%f\n", (float) ctx->fir_taps16[0][i]/(1 << 15)); + /*endifor*/ fclose(f); } /*- End of function --------------------------------------------------------*/ @@ -188,8 +190,10 @@ static inline void put_residue(int16_t amp) fprintf(stderr, " Error writing residue sound\n"); exit(2); } + /*endif*/ residue_cur = 0; } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -203,6 +207,7 @@ static void signal_load(signal_source_t *sig, const char *name) fprintf(stderr, " Error reading sound file '%s'\n", sig->name); exit(2); } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -213,6 +218,7 @@ static void signal_free(signal_source_t *sig) fprintf(stderr, " Cannot close sound file '%s'\n", sig->name); exit(2); } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -230,6 +236,7 @@ static int16_t signal_amp(signal_source_t *sig) tx = sig->signal[sig->cur++]*sig->gain; if (sig->cur >= sig->max) sig->cur = 0; + /*endif*/ return tx; } /*- End of function --------------------------------------------------------*/ @@ -248,11 +255,13 @@ static level_measurement_device_t *level_measurement_device_create(int type) sizeof(level_measurement_bp_coeffs)/sizeof(float)); for (i = 0; i < 35*8; i++) dev->history[i] = 0.0f; + /*endfor*/ dev->pos = 0; dev->factor = expf(-1.0f/((float) SAMPLE_RATE*0.035f)); dev->power = 0; dev->type = type; } + /*endif*/ return dev; } /*- End of function --------------------------------------------------------*/ @@ -264,6 +273,7 @@ static void level_measurement_device_reset(level_measurement_device_t *dev) for (i = 0; i < 35*8; i++) dev->history[i] = 0.0f; + /*endfor*/ dev->pos = 0; dev->power = 0; dev->peak = 0.0f; @@ -321,11 +331,14 @@ static float level_measurement_device(level_measurement_device_t *dev, int16_t a dev->history[dev->pos++] = signal; signal = sqrtf(dev->power/(35.8f*8.0f)); } + /*endif*/ if (signal <= 0.0f) return -99.0f; + /*endif*/ power = DBM0_MAX_POWER + 20.0f*log10f(signal/32767.0f + 1.0e-10f); if (power > dev->peak) dev->peak = power; + /*endif*/ return power; } /*- End of function --------------------------------------------------------*/ @@ -364,6 +377,7 @@ static void print_results(void) { if (!quiet) printf("test model ERL time Max Rin Max Rout Max Sgen Max Sin Max Sout\n"); + /*endif*/ printf("%-4s %-1d %-5.1f%6.2fs%9.2f%9.2f%9.2f%9.2f%9.2f\n", test_name, chan_model.model_no, @@ -422,6 +436,7 @@ static int channel_model_create(channel_model_state_t *chan, int model, float er if (model < 0 || model >= (int) (sizeof(line_model_sizes)/sizeof(line_model_sizes[0]))) return -1; + /*endif*/ fir32_create(&chan->impulse, line_models[model], line_model_sizes[model]); chan->gain = 32768.0f*powf(10.0f, erl/20.0f)*ki[model]; chan->munging_codec = codec; @@ -450,6 +465,7 @@ static int16_t channel_model(channel_model_state_t *chan, int16_t rout, int16_t sgen = ulaw_to_linear(linear_to_ulaw(sgen)); break; } + /*endswitch*/ /* The local tx signal will usually have gone through codec munging before it reached the line's analogue area, where the echo occurs. */ @@ -462,6 +478,7 @@ static int16_t channel_model(channel_model_state_t *chan, int16_t rout, int16_t rout = ulaw_to_linear(linear_to_ulaw(rout)); break; } + /*endswitch*/ /* Now we need to model the echo. We only model a single analogue segment, as per the G.168 spec. However, there will generally be near end and far end analogue/echoey segments in the real world, unless an end is purely digital. */ @@ -479,6 +496,7 @@ static int16_t channel_model(channel_model_state_t *chan, int16_t rout, int16_t sin = ulaw_to_linear(linear_to_ulaw(sin)); break; } + /*endswitch*/ return sin; } /*- End of function --------------------------------------------------------*/ @@ -597,12 +615,16 @@ static void run_test(echo_can_state_t *ctx, int16_t (*tx_source)(void), int16_t fprintf(stderr, " Error writing result sound\n"); exit(2); } + /*endif*/ result_cur = 0; } + /*endif*/ } + /*endfor*/ #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[0], TEST_EC_TAPS); + /*endif*/ #endif if (result_cur >= 0) { @@ -612,8 +634,10 @@ static void run_test(echo_can_state_t *ctx, int16_t (*tx_source)(void), int16_t fprintf(stderr, " Error writing result sound\n"); exit(2); } + /*endif*/ result_cur = 0; } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -672,16 +696,20 @@ static int perform_test_sanity(void) fprintf(stderr, " Error reading far sound\n"); exit(2); } + /*endif*/ if (far_max == 0) break; + /*endif*/ far_cur = 0; } + /*endif*/ far_tx = far_sound[far_cur++]; } else { far_tx = 0; } + /*endif*/ #else //far_sound[0] = 0; far_tx = 0; @@ -698,9 +726,12 @@ static int perform_test_sanity(void) { for (j = 0; j < ctx->taps; j++) coeffs[coeff_index][j] = ctx->fir_taps32[j]; + /*endfor*/ coeff_index++; } + /*endif*/ } + /*endif*/ #endif result_sound[result_cur++] = tx; result_sound[result_cur++] = rx; @@ -728,9 +759,12 @@ static int perform_test_sanity(void) fprintf(stderr, " Error writing result sound\n"); exit(2); } + /*endif*/ result_cur = 0; } + /*endif*/ } + /*endfor*/ if (result_cur > 0) { outframes = sf_writef_short(result_handle, result_sound, result_cur/RESULT_CHANNELS); @@ -739,14 +773,18 @@ static int perform_test_sanity(void) fprintf(stderr, " Error writing result sound\n"); exit(2); } + /*endif*/ } + /*endif*/ #if defined(XYZZY) for (j = 0; j < ctx->taps; j++) { for (i = 0; i < coeff_index; i++) fprintf(stderr, "%d ", coeffs[i][j]); + /*endfor*/ fprintf(stderr, "\n"); } + /*endfor*/ #endif echo_can_free(ctx); @@ -779,6 +817,7 @@ static int perform_test_2a(void) printf("Test failed\n"); else printf("Test passed\n"); + /*endif*/ /* Test 2A (b) - Reconvergence test with NLP enabled */ @@ -788,6 +827,7 @@ static int perform_test_2a(void) fprintf(stderr, " Failed to create line model\n"); exit(2); } + /*endif*/ signal_restart(&local_css, 0.0f); run_test(ctx, local_css_signal, silence, 1000); level_measurements_reset_peaks(); @@ -797,6 +837,7 @@ static int perform_test_2a(void) printf("Test failed\n"); else printf("Test passed\n"); + /*endif*/ echo_can_free(ctx); return 0; @@ -840,6 +881,7 @@ static int perform_test_2b(void) fprintf(stderr, " Failed to create line model\n"); exit(2); } + /*endif*/ run_test(ctx, local_css_signal, silence, 1000); level_measurements_reset_peaks(); run_test(ctx, local_css_signal, silence, 9000); @@ -851,6 +893,7 @@ static int perform_test_2b(void) printf("Test failed\n"); else printf("Test passed\n"); + /*endif*/ echo_can_free(ctx); return 0; @@ -886,6 +929,7 @@ static int perform_test_2ca(void) printf("Test failed\n"); else printf("Test passed\n"); + /*endif*/ echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); echo_can_free(ctx); @@ -924,6 +968,7 @@ static int perform_test_3a(void) printf("Test failed\n"); else printf("Test passed\n"); + /*endif*/ echo_can_adaption_mode(ctx, ECHO_CAN_USE_ADAPTION); echo_can_free(ctx); @@ -1157,6 +1202,7 @@ static int perform_test_6(void) clean = echo_can_update(ctx, tx, rx); put_residue(clean); } + /*endfor*/ #if defined(ENABLE_GUI) if (use_gui) { @@ -1164,12 +1210,16 @@ static int perform_test_6(void) echo_can_monitor_update_display(); usleep(100000); } + /*endif*/ #endif } + /*endfor*/ } + /*endfor*/ #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[0], TEST_EC_TAPS); + /*endif*/ #endif echo_can_free(ctx); return 0; @@ -1218,6 +1268,7 @@ static int perform_test_7(void) clean = echo_can_update(ctx, tx, rx); put_residue(clean); } + /*endfor*/ #if defined(ENABLE_GUI) if (use_gui) { @@ -1225,11 +1276,14 @@ static int perform_test_7(void) echo_can_monitor_update_display(); usleep(100000); } + /*endif*/ #endif } + /*endfor*/ #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_can_update(ctx->fir_taps16[0], TEST_EC_TAPS); + /*endif*/ #endif echo_can_free(ctx); return 0; @@ -1458,14 +1512,18 @@ static int match_test_name(const char *name) tests[i].func(); return 0; } + /*endif*/ } + /*endfor*/ printf("Unknown test name '%s' specified. The known test names are ", name); for (i = 0; tests[i].name; i++) { printf("%s", tests[i].name); if (tests[i + 1].name) printf(", "); + /*endif*/ } + /*endfor*/ printf("\n"); return -1; } @@ -1503,6 +1561,7 @@ static void simulate_ec(char *argv[], int two_channel_file, int mode) rxtxfile = sf_open_telephony_read(argv[0], 2); ecfile = sf_open_telephony_write(argv[1], 1); } + /*endif*/ ctx = echo_can_init(TEST_EC_TAPS, 0); echo_can_adaption_mode(ctx, mode); @@ -1515,6 +1574,7 @@ static void simulate_ec(char *argv[], int two_channel_file, int mode) fprintf(stderr, " Error reading tx sound file\n"); exit(2); } + /*endif*/ rin = buf[0]; sin = buf[1]; nrx = ntx; @@ -1531,7 +1591,9 @@ static void simulate_ec(char *argv[], int two_channel_file, int mode) fprintf(stderr, " Error reading rx sound file\n"); exit(2); } + /*endif*/ } + /*endif*/ rout = echo_can_hpf_tx(ctx, rin); sout = echo_can_update(ctx, rout, sin); @@ -1540,6 +1602,7 @@ static void simulate_ec(char *argv[], int two_channel_file, int mode) fprintf(stderr, " Error writing ec sound file\n"); exit(2); } + /*endif*/ level_measurements_update(rin, sin, rout, sout, 0); write_log_files(rin, sin); #if defined(ENABLE_GUI) @@ -1561,6 +1624,7 @@ static void simulate_ec(char *argv[], int two_channel_file, int mode) sf_close_telephony(txfile); sf_close_telephony(rxfile); } + /*endif*/ sf_close_telephony(ecfile); } /*- End of function --------------------------------------------------------*/ @@ -1634,13 +1698,16 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ argc -= optind; argv += optind; #if defined(ENABLE_GUI) if (use_gui) start_echo_can_monitor(TEST_EC_TAPS); + /*endif*/ #endif if (simulate) { @@ -1651,6 +1718,7 @@ int main(int argc, char *argv[]) printf("not enough arguments for a simulation\n"); exit(2); } + /*endif*/ mode = ECHO_CAN_USE_NLP; mode |= ((cng) ? ECHO_CAN_USE_CNG : ECHO_CAN_USE_CLIP); if (hpf) @@ -1658,6 +1726,7 @@ int main(int argc, char *argv[]) mode |= ECHO_CAN_USE_TX_HPF; mode |= ECHO_CAN_USE_RX_HPF; } + /*endif*/ simulate_ec(argv, two_channel_file, mode); } else @@ -1666,6 +1735,7 @@ int main(int argc, char *argv[]) #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_line_model_update(chan_model.impulse.coeffs, chan_model.impulse.taps); + /*endif*/ #endif signal_load(&local_css, "sound_c1_8k.wav"); signal_load(&far_css, "sound_c3_8k.wav"); @@ -1687,6 +1757,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Failed to open result file\n"); exit(2); } + /*endif*/ result_cur = 0; level_measurements_create(0); for (i = 0; i < argc; i++) @@ -1696,15 +1767,19 @@ int main(int argc, char *argv[]) fprintf(stderr, " Failed to create line model\n"); exit(2); } + /*endif*/ match_test_name(argv[i]); } + /*endfor*/ if (sf_close_telephony(result_handle)) { fprintf(stderr, " Cannot close speech file '%s'\n", "result_sound.wav"); exit(2); } + /*endif*/ printf("Run time %lds\n", time(NULL) - now); } + /*endif*/ signal_free(&local_css); signal_free(&far_css); if (sf_close_telephony(residue_handle)) @@ -1712,10 +1787,13 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close speech file '%s'\n", RESIDUE_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ #if defined(ENABLE_GUI) if (use_gui) echo_can_monitor_wait_to_end(); + /*endif*/ #endif printf("Tests passed.\n"); diff --git a/tests/fax_decode.c b/tests/fax_decode.c index 85aeea2c..e209df0a 100644 --- a/tests/fax_decode.c +++ b/tests/fax_decode.c @@ -147,9 +147,7 @@ static void print_frame(const char *io, const uint8_t *fr, int frlen) const char *model; if (frlen == 0) - { return; - } /*endif*/ fprintf(stderr, "%s %s:", io, t30_frametype(fr[2])); for (i = 2; i < frlen; i++) diff --git a/tests/fax_tester.c b/tests/fax_tester.c index 514255cc..0c24bbd4 100644 --- a/tests/fax_tester.c +++ b/tests/fax_tester.c @@ -166,6 +166,7 @@ static void timer_update(faxtester_state_t *s, int len) printf("Test failed\n"); exit(2); } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -195,6 +196,7 @@ static int faxtester_phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote ident incorrect! - expected '%s'\n", ch, s->expected_rx_info.ident); status = T30_ERR_IDENT_UNACCEPTABLE; } + /*endif*/ } else { @@ -203,7 +205,9 @@ static int faxtester_phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote ident missing!\n", ch); status = T30_ERR_IDENT_UNACCEPTABLE; } + /*endif*/ } + /*endif*/ if ((u = t30_get_rx_sub_address(s->far_t30))) { printf("%c: Phase B: remote sub-address '%s'\n", ch, u); @@ -212,6 +216,7 @@ static int faxtester_phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote sub-address incorrect! - expected '%s'\n", ch, s->expected_rx_info.sub_address); status = T30_ERR_SUB_UNACCEPTABLE; } + /*endif*/ } else { @@ -220,7 +225,9 @@ static int faxtester_phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote sub-address missing!\n", ch); status = T30_ERR_SUB_UNACCEPTABLE; } + /*endif*/ } + /*endif*/ if ((u = t30_get_rx_polled_sub_address(s->far_t30))) { printf("%c: Phase B: remote polled sub-address '%s'\n", ch, u); @@ -229,6 +236,7 @@ static int faxtester_phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote polled sub-address incorrect! - expected '%s'\n", ch, s->expected_rx_info.polled_sub_address); status = T30_ERR_PSA_UNACCEPTABLE; } + /*endif*/ } else { @@ -237,7 +245,9 @@ static int faxtester_phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote polled sub-address missing!\n", ch); status = T30_ERR_PSA_UNACCEPTABLE; } + /*endif*/ } + /*endif*/ if ((u = t30_get_rx_selective_polling_address(s->far_t30))) { printf("%c: Phase B: remote selective polling address '%s'\n", ch, u); @@ -246,6 +256,7 @@ static int faxtester_phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote selective polling address incorrect! - expected '%s'\n", ch, s->expected_rx_info.selective_polling_address); status = T30_ERR_SEP_UNACCEPTABLE; } + /*endif*/ } else { @@ -254,7 +265,9 @@ static int faxtester_phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote selective polling address missing!\n", ch); status = T30_ERR_SEP_UNACCEPTABLE; } + /*endif*/ } + /*endif*/ if ((u = t30_get_rx_sender_ident(s->far_t30))) { printf("%c: Phase B: remote sender ident '%s'\n", ch, u); @@ -263,6 +276,7 @@ static int faxtester_phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote sender ident incorrect! - expected '%s'\n", ch, s->expected_rx_info.sender_ident); status = T30_ERR_SID_UNACCEPTABLE; } + /*endif*/ } else { @@ -271,7 +285,9 @@ static int faxtester_phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote sender ident missing!\n", ch); status = T30_ERR_SID_UNACCEPTABLE; } + /*endif*/ } + /*endif*/ if ((u = t30_get_rx_password(s->far_t30))) { printf("%c: Phase B: remote password '%s'\n", ch, u); @@ -280,6 +296,7 @@ static int faxtester_phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote password incorrect! - expected '%s'\n", ch, s->expected_rx_info.password); status = T30_ERR_PWD_UNACCEPTABLE; } + /*endif*/ } else { @@ -288,7 +305,9 @@ static int faxtester_phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote password missing!\n", ch); status = T30_ERR_PWD_UNACCEPTABLE; } + /*endif*/ } + /*endif*/ printf("%c: Phase B handler on channel %c - (0x%X) %s\n", ch, ch, result, t30_frametype(result)); return status; } @@ -312,6 +331,7 @@ static int faxtester_phase_d_handler(void *user_data, int result) if (s->use_receiver_not_ready) t30_set_receiver_not_ready(s->far_t30, 3); + /*endif*/ if (s->test_local_interrupt) { @@ -334,8 +354,11 @@ static int faxtester_phase_d_handler(void *user_data, int result) case T30_PIN: break; } + /*endswitch*/ } + /*endif*/ } + /*endif*/ return T30_ERR_OK; } /*- End of function --------------------------------------------------------*/ @@ -361,10 +384,7 @@ static void t30_real_time_frame_handler(void *user_data, const uint8_t *msg, int len) { - if (msg == NULL) - { - } - else + if (msg) { fprintf(stderr, "T.30: Real time frame handler - %s, %s, length = %d\n", @@ -372,6 +392,7 @@ static void t30_real_time_frame_handler(void *user_data, t30_frametype(msg[2]), len); } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -391,6 +412,7 @@ static int faxtester_document_handler(void *user_data, int event) s->next_tx_file[0] = '\0'; return true; } + /*endif*/ return false; } /*- End of function --------------------------------------------------------*/ @@ -426,14 +448,18 @@ static void faxtester_real_time_frame_handler(faxtester_state_t *s, printf("Test failed\n"); exit(2); } + /*endif*/ } + /*endif*/ if (msg[1] == s->awaited[1]) { while (faxtester_next_step(s) == 0) ; /*endwhile*/ } + /*endif*/ } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -448,6 +474,7 @@ void faxtester_send_hdlc_msg(faxtester_state_t *s, const uint8_t *msg, int len, hdlc_tx_frame(&s->modems.hdlc_tx, msg, len); if (!crc_ok) hdlc_tx_corrupt_frame(&s->modems.hdlc_tx); + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -471,9 +498,11 @@ static void hdlc_underflow_handler(void *user_data) hdlc_tx_frame(&s->modems.hdlc_tx, buf, 4 + s->ecm_frame_size); if (s->corrupt_crc >= 0 && s->corrupt_crc == s->image_ptr/s->ecm_frame_size) hdlc_tx_corrupt_frame(&s->modems.hdlc_tx); + /*endif*/ s->image_ptr += s->ecm_frame_size; return; } + /*endif*/ /* The actual image is over. We are sending the final RCP frames. */ if (s->image_bit_ptr > 2) { @@ -484,9 +513,11 @@ static void hdlc_underflow_handler(void *user_data) hdlc_tx_frame(&s->modems.hdlc_tx, buf, 3); return; } + /*endif*/ /* All done. */ s->image_buffer = NULL; } + /*endif*/ front_end_step_complete(s); } /*- End of function --------------------------------------------------------*/ @@ -503,6 +534,7 @@ static void modem_tx_status(void *user_data, int status) front_end_step_complete(s); break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -528,9 +560,11 @@ static void tone_detected(void *user_data, int tone, int level, int delay) "Tone was on for %fs\n", (float) (s->timer - s->tone_on_time)/SAMPLE_RATE + 0.55); } + /*endif*/ s->tone_state = tone; if (tone == MODEM_CONNECT_TONES_NONE) front_end_step_complete(s); + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -547,9 +581,11 @@ static int non_ecm_get_bit(void *user_data) s->image_buffer = NULL; return SIG_STATUS_END_OF_DATA; } + /*endif*/ s->image_bit_ptr = 8; s->image_ptr++; } + /*endif*/ s->image_bit_ptr--; bit = (s->image_buffer[s->image_ptr] >> (7 - s->image_bit_ptr)) & 0x01; //printf("Rx bit - %d\n", bit); @@ -562,6 +598,7 @@ static void faxtester_set_ecm_image_buffer(faxtester_state_t *s, int block, int s->image_ptr = 256*frame_size*block; if (s->image_len > s->image_ptr + 256*frame_size) s->image_len = s->image_ptr + 256*frame_size; + /*endif*/ s->ecm_frame_size = frame_size; s->image_bit_ptr = 8; @@ -598,6 +635,7 @@ static void non_ecm_rx_status(void *user_data, int status) s->modems.rx_trained = false; break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -608,6 +646,7 @@ static void non_ecm_put_bit(void *user_data, int bit) non_ecm_rx_status(user_data, bit); return; } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -634,6 +673,7 @@ static void hdlc_rx_status(void *user_data, int status) s->modems.rx_trained = false; break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -646,6 +686,7 @@ static void hdlc_accept(void *user_data, const uint8_t *msg, int len, int ok) hdlc_rx_status(user_data, len); return; } + /*endif*/ s = (faxtester_state_t *) user_data; faxtester_real_time_frame_handler(s, true, msg, len); } @@ -657,8 +698,10 @@ int faxtester_rx(faxtester_state_t *s, int16_t *amp, int len) for (i = 0; i < len; i++) amp[i] = dc_restore(&s->modems.dc_restore, amp[i]); + /*endfor*/ if (s->modems.rx_handler) s->modems.rx_handler(s->modems.rx_user_data, amp, len); + /*endif*/ timer_update(s, len); if (s->wait_for_silence) { @@ -667,7 +710,9 @@ int faxtester_rx(faxtester_state_t *s, int16_t *amp, int len) s->wait_for_silence = false; front_end_step_complete(s); } + /*endif*/ } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -691,9 +736,12 @@ int faxtester_tx(faxtester_state_t *s, int16_t *amp, int max_len) memset(amp + len, 0, (max_len - len)*sizeof(int16_t)); len = max_len; } + /*endif*/ break; } + /*endif*/ } + /*endwhile*/ } else { @@ -703,7 +751,9 @@ int faxtester_tx(faxtester_state_t *s, int16_t *amp, int max_len) memset(amp, 0, max_len*sizeof(int16_t)); len = max_len; } + /*endif*/ } + /*endif*/ return len; } /*- End of function --------------------------------------------------------*/ @@ -724,9 +774,11 @@ void faxtester_set_rx_type(void *user_data, int type, int bit_rate, int short_tr span_log(&s->logging, SPAN_LOG_FLOW, "Set rx type %s (%d)\n", t30_modem_to_str(type), type); if (s->current_rx_type == type) return; + /*endif*/ s->current_rx_type = type; if (use_hdlc) hdlc_rx_init(&t->hdlc_rx, false, false, HDLC_FRAMING_OK_THRESHOLD, hdlc_accept, s); + /*endif*/ switch (type) { case T30_MODEM_CED: @@ -757,6 +809,7 @@ void faxtester_set_rx_type(void *user_data, int type, int bit_rate, int short_tr fax_modems_set_rx_handler(t, (span_rx_handler_t) &span_dummy_rx, s, NULL, s); break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -770,7 +823,7 @@ void faxtester_set_tx_type(void *user_data, int type, int bit_rate, int short_tr s = (faxtester_state_t *) user_data; t = &s->modems; - span_log(&s->logging, SPAN_LOG_FLOW, "Set rx type %s (%d)\n", t30_modem_to_str(type), type); + span_log(&s->logging, SPAN_LOG_FLOW, "Set tx type %s (%d)\n", t30_modem_to_str(type), type); if (use_hdlc) { get_bit_func = (span_get_bit_func_t) hdlc_tx_get_bit; @@ -786,6 +839,7 @@ void faxtester_set_tx_type(void *user_data, int type, int bit_rate, int short_tr { if (type == T30_MODEM_PAUSE) silence_gen_alter(&t->silence_gen, milliseconds_to_samples(short_train)); + /*endif*/ return; } /*endif*/ @@ -1030,6 +1084,7 @@ static void fax_prepare(faxtester_state_t *s) fax_set_tep_mode(s->far_fax, true); } /*endif*/ + t30_set_retransmit_capable(s->far_t30, false); #if 0 t30_set_tx_ident(s->far_t30, "1234567890"); t30_set_tx_sub_address(s->far_t30, "Sub-address"); diff --git a/tests/fax_tests.c b/tests/fax_tests.c index b16743a9..15fcfba6 100644 --- a/tests/fax_tests.c +++ b/tests/fax_tests.c @@ -203,6 +203,7 @@ static int phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote ident incorrect! - expected '%s'\n", ch, info->ident); status = T30_ERR_IDENT_UNACCEPTABLE; } + /*endif*/ } else { @@ -211,7 +212,9 @@ static int phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote ident missing!\n", ch); status = T30_ERR_IDENT_UNACCEPTABLE; } + /*endif*/ } + /*endif*/ if ((u = t30_get_rx_sub_address(s))) { printf("%c: Phase B: remote sub-address '%s'\n", ch, u); @@ -220,6 +223,7 @@ static int phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote sub-address incorrect! - expected '%s'\n", ch, info->sub_address); status = T30_ERR_SUB_UNACCEPTABLE; } + /*endif*/ } else { @@ -228,7 +232,9 @@ static int phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote sub-address missing!\n", ch); status = T30_ERR_SUB_UNACCEPTABLE; } + /*endif*/ } + /*endif*/ if ((u = t30_get_rx_polled_sub_address(s))) { printf("%c: Phase B: remote polled sub-address '%s'\n", ch, u); @@ -237,6 +243,7 @@ static int phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote polled sub-address incorrect! - expected '%s'\n", ch, info->polled_sub_address); status = T30_ERR_PSA_UNACCEPTABLE; } + /*endif*/ } else { @@ -245,7 +252,9 @@ static int phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote polled sub-address missing!\n", ch); status = T30_ERR_PSA_UNACCEPTABLE; } + /*endif*/ } + /*endif*/ if ((u = t30_get_rx_selective_polling_address(s))) { printf("%c: Phase B: remote selective polling address '%s'\n", ch, u); @@ -254,6 +263,7 @@ static int phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote selective polling address incorrect! - expected '%s'\n", ch, info->selective_polling_address); status = T30_ERR_SEP_UNACCEPTABLE; } + /*endif*/ } else { @@ -262,7 +272,9 @@ static int phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote selective polling address missing!\n", ch); status = T30_ERR_SEP_UNACCEPTABLE; } + /*endif*/ } + /*endif*/ if ((u = t30_get_rx_sender_ident(s))) { printf("%c: Phase B: remote sender ident '%s'\n", ch, u); @@ -271,6 +283,7 @@ static int phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote sender ident incorrect! - expected '%s'\n", ch, info->sender_ident); status = T30_ERR_SID_UNACCEPTABLE; } + /*endif*/ } else { @@ -279,7 +292,9 @@ static int phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote sender ident missing!\n", ch); status = T30_ERR_SID_UNACCEPTABLE; } + /*endif*/ } + /*endif*/ if ((u = t30_get_rx_password(s))) { printf("%c: Phase B: remote password '%s'\n", ch, u); @@ -288,6 +303,7 @@ static int phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote password incorrect! - expected '%s'\n", ch, info->password); status = T30_ERR_PWD_UNACCEPTABLE; } + /*endif*/ } else { @@ -296,7 +312,9 @@ static int phase_b_handler(void *user_data, int result) printf("%c: Phase B: remote password missing!\n", ch); status = T30_ERR_PWD_UNACCEPTABLE; } + /*endif*/ } + /*endif*/ if ((len = t30_get_rx_nsf(s, &v))) { printf("%c: Phase B: NSF %d bytes\n", ch, len); @@ -304,6 +322,7 @@ static int phase_b_handler(void *user_data, int result) { printf("%c: Phase B: remote NSF incorrect! - expected %u bytes\n", ch, (unsigned int) info->nsf_len); } + /*endif*/ } else { @@ -311,7 +330,9 @@ static int phase_b_handler(void *user_data, int result) { printf("%c: Phase B: remote NSF missing! - expected %u bytes\n", ch, (unsigned int) info->nsf_len); } + /*endif*/ } + /*endif*/ if ((len = t30_get_rx_nsc(s, &v))) { printf("%c: Phase B: NSC %d bytes\n", ch, len); @@ -319,6 +340,7 @@ static int phase_b_handler(void *user_data, int result) { printf("%c: Phase B: remote NSC incorrect! - expected %u bytes\n", ch, (unsigned int) info->nsc_len); } + /*endif*/ } else { @@ -326,7 +348,9 @@ static int phase_b_handler(void *user_data, int result) { printf("%c: Phase B: remote NSC missing! - expected %u bytes\n", ch, (unsigned int) info->nsc_len); } + /*endif*/ } + /*endif*/ if ((len = t30_get_rx_nss(s, &v))) { printf("%c: Phase B: NSS %d bytes\n", ch, len); @@ -334,6 +358,7 @@ static int phase_b_handler(void *user_data, int result) { printf("%c: Phase B: remote NSS incorrect! - expected %u bytes\n", ch, (unsigned int) info->nss_len); } + /*endif*/ } else { @@ -341,7 +366,9 @@ static int phase_b_handler(void *user_data, int result) { printf("%c: Phase B: remote NSS missing! - expected %u bytes\n", ch, (unsigned int) info->nsf_len); } + /*endif*/ } + /*endif*/ return status; } @@ -365,6 +392,7 @@ static int phase_d_handler(void *user_data, int result) if (use_receiver_not_ready) t30_set_receiver_not_ready(s, 3); + /*endif*/ if (test_local_interrupt) { @@ -387,8 +415,11 @@ static int phase_d_handler(void *user_data, int result) case T30_PIN: break; } + /*endswitch*/ } + /*endif*/ } + /*endif*/ return T30_ERR_OK; } /*- End of function --------------------------------------------------------*/ @@ -486,8 +517,10 @@ static int tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t if (g1050_put(chain[chan].path.g1050_path, buf, len, chain[chan].t38_subst_seq, when) < 0) printf("Lost packet %d\n", chain[chan].t38_subst_seq); + /*endif*/ chain[chan].t38_subst_seq = (chain[chan].t38_subst_seq + 1) & 0xFFFF; } + /*endfor*/ } else { @@ -497,8 +530,11 @@ static int tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t { if (g1050_put(chain[chan].path.g1050_path, buf, len, s->tx_seq_no, when) < 0) printf("Lost packet %d\n", s->tx_seq_no); + /*endif*/ } + /*endfor*/ } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -534,9 +570,11 @@ static void t33_tests(void) { if (type == T33_NONE) break; + /*endif*/ printf("Bad sub-address field\n"); exit(2); } + /*endif*/ switch (type) { case T33_SST: @@ -548,13 +586,17 @@ static void t33_tests(void) t33_sub_address_add_field(new_t33, num, type); break; } + /*endswitch*/ } + /*endfor*/ if (strcmp((const char *) pkts[n], (const char *) new_t33)) { printf("Re-encode mismatch '%s' '%s'\n", pkts[n], new_t33); exit(2); } + /*endif*/ } + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -742,6 +784,7 @@ int main(int argc, char *argv[]) { if (optarg[i] != '-' && optarg[i] != '\0') continue; + /*endif*/ j = optarg[i]; optarg[i] = '\0'; if (strcmp(&optarg[k], "FAX") == 0) @@ -777,10 +820,13 @@ int main(int argc, char *argv[]) fprintf(stderr, "Unknown FAX path element %s\n", &optarg[k]); exit(2); } + /*endif*/ k = i + 1; if (j == '\0') break; + /*endif*/ } + /*endfor*/ #if 0 if ((chain[0].node_type == AUDIO_FAX && chain[chain_elements - 1].node_type != AUDIO_FAX) || @@ -789,6 +835,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Invalid FAX path\n"); exit(2); } + /*endif*/ #endif break; case 'P': @@ -826,6 +873,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Unknown T.38 transport mode\n"); exit(2); } + /*endif*/ break; case 'v': t38_version = atoi(optarg); @@ -845,17 +893,21 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ if (code_to_look_up >= 0) { printf("Result code %d is %s\n", code_to_look_up, t30_completion_code_to_str(code_to_look_up)); exit(0); } + /*endif*/ printf("Using T.38 version %d\n", t38_version); if (use_ecm) printf("Using ECM\n"); + /*endif*/ wave_handle = NULL; if (log_audio) @@ -865,7 +917,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot create audio file '%s'\n", OUTPUT_WAVE_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ memset(silence, 0, sizeof(silence)); srand48(0x1234567); @@ -894,6 +948,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot start FAX instance\n"); exit(2); } + /*endif*/ chain[i].t30_state = fax_get_t30_state(chain[i].node.fax_state); logging = fax_get_logging_state(chain[i].node.fax_state); @@ -921,6 +976,7 @@ int main(int argc, char *argv[]) signal_scaling = powf(10.0f, signal_level/20.0f); printf("Signal scaling %f\n", signal_scaling); } + /*endif*/ break; case T38_FAX: if ((chain[i].node.t38_state = t38_terminal_init(NULL, (i == 0), tx_packet_handler, (void *) (intptr_t) i)) == NULL) @@ -928,6 +984,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot start the T.38 terminal instance\n"); exit(2); } + /*endif*/ chain[i].t30_state = t38_terminal_get_t30_state(chain[i].node.t38_state); chain[i].t38_core_state = t38_terminal_get_t38_core_state(chain[i].node.t38_state); @@ -961,7 +1018,9 @@ int main(int argc, char *argv[]) chain[i].t38_peer = i + 1; break; } + /*endswitch*/ } + /*endif*/ break; case T31_AUDIO_FAX: break; @@ -974,6 +1033,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot start FAX tester instance\n"); exit(2); } + /*endif*/ logging = faxtester_get_logging_state(chain[i].node.faxtester_state); span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME); span_log_set_tag(logging, chain[i].tag); @@ -999,7 +1059,9 @@ int main(int argc, char *argv[]) chain[i].t38_peer = i + 1; break; } + /*endswitch*/ } + /*endif*/ chain[i].awgn_state = NULL; signal_scaling = 1.0f; @@ -1009,6 +1071,7 @@ int main(int argc, char *argv[]) signal_scaling = powf(10.0f, signal_level/20.0f); printf("Signal scaling %f\n", signal_scaling); } + /*endif*/ break; case REPLAY_AUDIO_FAX: if ((chain[i].node.wave_handle = sf_open_telephony_read(replay_file_name, 1)) == NULL) @@ -1016,7 +1079,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", replay_file_name); exit(2); } - + /*endif*/ chain[i].path.audio_in_buf = &chain[i + ((i == 0) ? 1 : -1)].audio_buf[0]; chain[i].path.audio_out_buf = &chain[i].audio_buf[0]; break; @@ -1026,6 +1089,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot start T.38 gateway instance\n"); exit(2); } + /*endif*/ chain[i].t38_core_state = t38_gateway_get_t38_core_state(chain[i].node.t38_gateway_state); logging = t38_gateway_get_logging_state(chain[i].node.t38_gateway_state); @@ -1067,7 +1131,9 @@ int main(int argc, char *argv[]) chain[i].path.audio_in_buf = &chain[i - 1].audio_buf[0]; break; } + /*endswitch*/ } + /*endif*/ chain[i].path.audio_out_buf = &chain[i].audio_buf[0]; @@ -1079,13 +1145,16 @@ int main(int argc, char *argv[]) signal_scaling = powf(10.0f, signal_level/20.0f); printf("Signal scaling %f\n", signal_scaling); } + /*endif*/ } if ((chain[i].path.g1050_path = g1050_init(g1050_model_no, g1050_speed_pattern_no, 100, 33)) == NULL) { fprintf(stderr, " Failed to start IP network path model\n"); exit(2); } + /*endif*/ } + /*endfor*/ for (i = 0; i < chain_elements; i++) { @@ -1113,13 +1182,14 @@ int main(int argc, char *argv[]) t30_set_tx_page_header_info(chain[i].t30_state, page_header_info); if (page_header_tz) t30_set_tx_page_header_tz(chain[i].t30_state, page_header_tz); - + /*endif*/ if (i != 0) { t30_set_tx_nsf(chain[i].t30_state, (const uint8_t *) "\x50\x00\x00\x00Spandsp\x00", 12); chain[chain[i].peer].expected_rx_info.nsf = (uint8_t *) "\x50\x00\x00\x00Spandsp\x00"; chain[chain[i].peer].expected_rx_info.nsf_len = 12; } + /*endif*/ t30_set_supported_modems(chain[i].t30_state, supported_modems); t30_set_supported_t30_features(chain[i].t30_state, @@ -1190,6 +1260,7 @@ int main(int argc, char *argv[]) | T4_RESOLUTION_200_100); break; } + /*endswitch*/ if (colour_enabled) { t30_set_supported_colour_resolutions(chain[i].t30_state, @@ -1204,6 +1275,7 @@ int main(int argc, char *argv[]) { t30_set_supported_colour_resolutions(chain[i].t30_state, 0); } + /*endif*/ if (t37_like_output) { t30_set_supported_output_compressions(chain[i].t30_state, @@ -1218,6 +1290,7 @@ int main(int argc, char *argv[]) T4_COMPRESSION_T6 | T4_COMPRESSION_JPEG); } + /*endif*/ t30_set_ecm_capability(chain[i].t30_state, use_ecm); t30_set_supported_compressions(chain[i].t30_state, @@ -1241,6 +1314,7 @@ int main(int argc, char *argv[]) | 0); t30_set_minimum_scan_line_time(chain[i].t30_state, scan_line_time); } + /*endif*/ switch (chain[i].node_type) { @@ -1265,9 +1339,12 @@ int main(int argc, char *argv[]) t38_terminal_set_tep_mode(chain[i].node.t38_state, false); break; } + /*endswitch*/ break; } + /*endswitch*/ } + /*endfor*/ for (i = 0; i < chain_elements; i++) { @@ -1279,6 +1356,7 @@ int main(int argc, char *argv[]) chain[i].node.faxtester_state->far_fax = chain[chain[i].peer].node.fax_state; else chain[i].node.faxtester_state->far_t38 = chain[chain[i].peer].node.t38_state; + /*endif*/ chain[i].node.faxtester_state->far_t30 = chain[chain[i].peer].t30_state; chain[i].node.faxtester_state->far_tag = chain[i].peer + 'A'; @@ -1291,11 +1369,15 @@ int main(int argc, char *argv[]) case PASSTHROUGH: if (chain[i - 1].path.audio_in_buf == &chain[i].audio_buf[0]) chain[i - 1].path.audio_in_buf = &chain[i + 1].audio_buf[0]; + /*endif*/ if (chain[i + 1].path.audio_in_buf == &chain[i].audio_buf[0]) chain[i + 1].path.audio_in_buf = &chain[i - 1].audio_buf[0]; + /*endif*/ break; } + /*endswitch*/ } + /*endfor*/ switch (chain[chain_elements - 1].node_type) { @@ -1304,8 +1386,10 @@ int main(int argc, char *argv[]) k = (use_polled_mode) ? (chain_elements - 1) : 0; if (chain[k].t30_state) t30_set_tx_file(chain[k].t30_state, input_tiff_file_name, start_page, end_page); + /*endif*/ break; } + /*endswitch*/ switch (chain[0].node_type) { case AUDIO_FAX: @@ -1313,8 +1397,10 @@ int main(int argc, char *argv[]) k = (use_polled_mode) ? 0 : (chain_elements - 1); if (chain[k].t30_state) t30_set_rx_file(chain[k].t30_state, output_tiff_file_name, -1); + /*endif*/ break; } + /*endswitch*/ #if defined(ENABLE_GUI) if (use_gui) @@ -1355,13 +1441,16 @@ int main(int argc, char *argv[]) k = (i == 0) ? 0 : 2; for (j = 0; j < chain[i].path.audio_in_buf->len; j++) audio_log[4*j + k] = chain[i].path.audio_in_buf->amp[j]; + /*endfor*/ } + /*endif*/ fax_rx(chain[i].node.fax_state, chain[i].path.audio_in_buf->amp, chain[i].path.audio_in_buf->len); if (!t30_call_active(chain[i].t30_state)) { chain[i].completed = true; continue; } + /*endif*/ chain[i].path.audio_out_buf->len = fax_tx(chain[i].node.fax_state, chain[i].path.audio_out_buf->amp, SAMPLES_PER_CHUNK); if (!use_transmit_on_idle) @@ -1374,24 +1463,32 @@ int main(int argc, char *argv[]) vec_zeroi16(&chain[i].path.audio_out_buf->amp[chain[i].path.audio_out_buf->len], SAMPLES_PER_CHUNK - chain[i].path.audio_out_buf->len); chain[i].path.audio_out_buf->len = SAMPLES_PER_CHUNK; } + /*endif*/ } + /*endif*/ if (chain[i].awgn_state) { for (j = 0; j < chain[i].path.audio_out_buf->len; j++) chain[i].path.audio_out_buf->amp[j] = ((int16_t) (chain[i].path.audio_out_buf->amp[j]*signal_scaling)) + awgn(chain[i].awgn_state); + /*endfor*/ } + /*endif*/ if (log_audio) { k = (i == 0) ? 1 : 3; for (j = 0; j < chain[i].path.audio_out_buf->len; j++) audio_log[4*j + k] = chain[i].path.audio_out_buf->amp[j]; + /*endfor*/ } + /*endif*/ if (feedback_audio) { for (j = 0; j < chain[i].path.audio_out_buf->len; j++) chain[i].path.audio_out_buf->amp[j] += t38_amp_hist_a[hist_ptr][j] >> 1; + /*endfor*/ memcpy(t38_amp_hist_a[hist_ptr], chain[i].path.audio_out_buf->amp, sizeof(int16_t)*SAMPLES_PER_CHUNK); } + /*endif*/ break; case T38_FAX: /* Update timing */ @@ -1409,9 +1506,11 @@ int main(int argc, char *argv[]) #if defined(ENABLE_GUI) if (use_gui) media_monitor_rx(seq_no, tx_when, rx_when); + /*endif*/ #endif t38_core_rx_ifp_packet(chain[chain[i].t38_peer].t38_core_state, msg, msg_len, seq_no); } + /*endwhile*/ break; case TSB85_AUDIO_FAX: /* Update timing */ @@ -1429,17 +1528,22 @@ int main(int argc, char *argv[]) k = (i == 0) ? 0 : 2; for (j = 0; j < chain[i].path.audio_in_buf->len; j++) audio_log[4*j + k] = chain[i].path.audio_in_buf->amp[j]; + /*endfor*/ } + /*endif*/ faxtester_rx(chain[i].node.faxtester_state, chain[i].path.audio_in_buf->amp, chain[i].path.audio_in_buf->len); chain[i].path.audio_out_buf->len = faxtester_tx(chain[i].node.faxtester_state, chain[i].path.audio_out_buf->amp, SAMPLES_PER_CHUNK); if (chain[i].path.audio_out_buf->len == 0) break; + /*endif*/ if (log_audio) { k = (i == 0) ? 1 : 3; for (j = 0; j < chain[i].path.audio_out_buf->len; j++) audio_log[4*j + k] = chain[i].path.audio_out_buf->amp[j]; + /*endfor*/ } + /*endif*/ if (chain[i].node.faxtester_state->test_for_call_clear && !chain[i].node.faxtester_state->far_end_cleared_call) { chain[i].node.faxtester_state->call_clear_timer += chain[i].path.audio_out_buf->len; @@ -1456,6 +1560,7 @@ int main(int argc, char *argv[]) printf("Test failed\n"); exit(2); } + /*endif*/ span_log(faxtester_get_logging_state(chain[i].node.faxtester_state), SPAN_LOG_FLOW, "Clear time OK\n"); chain[i].node.faxtester_state->far_end_cleared_call = true; chain[i].node.faxtester_state->test_for_call_clear = false; @@ -1471,6 +1576,7 @@ int main(int argc, char *argv[]) chain[i].path.audio_out_buf->len = sf_readf_short(chain[i].node.wave_handle, chain[i].path.audio_out_buf->amp, SAMPLES_PER_CHUNK); if (chain[i].path.audio_out_buf->len == 0) break; + /*endif*/ break; case AUDIO_TO_T38_GATEWAY: /* Update timing */ @@ -1490,13 +1596,15 @@ int main(int argc, char *argv[]) drop_frame = drop_frame_rate; if (t38_gateway_rx_fillin(chain[i].node.t38_gateway_state, SAMPLES_PER_CHUNK)) break; + /*endif*/ } else { if (t38_gateway_rx(chain[i].node.t38_gateway_state, chain[i].path.audio_in_buf->amp, chain[i].path.audio_in_buf->len)) break; + /*endif*/ } - + /*endif*/ chain[i].path.audio_out_buf->len = t38_gateway_tx(chain[i].node.t38_gateway_state, chain[i].path.audio_out_buf->amp, SAMPLES_PER_CHUNK); if (!use_transmit_on_idle) { @@ -1505,50 +1613,64 @@ int main(int argc, char *argv[]) vec_zeroi16(&chain[i].path.audio_out_buf->amp[chain[i].path.audio_out_buf->len], SAMPLES_PER_CHUNK - chain[i].path.audio_out_buf->len); chain[i].path.audio_out_buf->len = SAMPLES_PER_CHUNK; } + /*endif*/ } + /*endif*/ if (feedback_audio) { for (j = 0; j < chain[i].path.audio_out_buf->len; j++) chain[i].path.audio_out_buf->amp[j] += t38_amp_hist_a[hist_ptr][j] >> 1; + /*endfor*/ vec_movei16(t38_amp_hist_a[hist_ptr], chain[i].path.audio_out_buf->amp, SAMPLES_PER_CHUNK); } - + /*endif*/ #if 0 if (log_audio) { k = (i == 0) ? 1 : 3; for (j = 0; j < chain[i].path.audio_out_buf->len; j++) audio_log[4*j + k] = chain[i].path.audio_out_buf->amp[j]; + /*endfor*/ } + /*endif*/ #endif while ((msg_len = g1050_get(chain[i].path.g1050_path, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0) { #if defined(ENABLE_GUI) if (use_gui) media_monitor_rx(seq_no, tx_when, rx_when); + /*endif*/ #endif t38_core_rx_ifp_packet(chain[chain[i].t38_peer].t38_core_state, msg, msg_len, seq_no); } + /*endwhile*/ break; } + /*endfor*/ } + /*endfor*/ if (log_audio) { outframes = sf_writef_short(wave_handle, audio_log, SAMPLES_PER_CHUNK); if (outframes != SAMPLES_PER_CHUNK) break; + /*endif*/ } + /*endif*/ when += (float) SAMPLES_PER_CHUNK/(float) SAMPLE_RATE; if (chain[0].completed && chain[chain_elements - 1].completed) break; + /*endif*/ #if defined(ENABLE_GUI) if (use_gui) media_monitor_update_display(); + /*endif*/ #endif if (++hist_ptr > 3) hist_ptr = 0; + /*endif*/ } for (i = 0; i < chain_elements; i++) @@ -1564,7 +1686,9 @@ int main(int argc, char *argv[]) (t38_stats.error_correcting_mode) ? "ECM" : "non-ECM"); break; } + /*endswitch*/ } + /*endfor*/ if (log_audio) { if (sf_close_telephony(wave_handle)) @@ -1572,35 +1696,45 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_WAVE_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ /* Check how many pages should have been transferred */ expected_pages = get_tiff_total_pages(input_tiff_file_name); if (end_page >= 0 && expected_pages > end_page + 1) expected_pages = end_page + 1; + /*endif*/ if (start_page >= 0) expected_pages -= start_page; + /*endif*/ /* Check how many pages were transferred */ for (j = 0; j < 2; j++) { i = (j == 0) ? 0 : (chain_elements - 1); if (!chain[i].phase_e_reached) break; + /*endif*/ if (!chain[i].succeeded) break; + /*endif*/ t30_get_transfer_statistics(chain[i].t30_state, &t30_stats); if ((!use_polled_mode && i != 0) || (use_polled_mode && i == 0)) { if (t30_stats.pages_tx != 0 || t30_stats.pages_rx != expected_pages) break; + /*endif*/ } else { if (t30_stats.pages_tx != expected_pages || t30_stats.pages_rx != 0) break; + /*endif*/ } + /*endif*/ } + /*endfor*/ for (i = 0; i < chain_elements; i++) { switch (chain[i].node_type) @@ -1621,23 +1755,28 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", replay_file_name); exit(2); } + /*endif*/ chain[i].node.wave_handle = NULL; break; case AUDIO_TO_T38_GATEWAY: t38_gateway_free(chain[i].node.t38_gateway_state); break; } + /*endswitch*/ if (chain[i].path.g1050_path) { g1050_free(chain[i].path.g1050_path); chain[i].path.g1050_path = NULL; } + /*endif*/ } + /*endfor*/ if (j < 2) { printf("Tests failed\n"); exit(2); } + /*endif*/ t33_tests(); printf("Tests passed\n"); return 0; diff --git a/tests/fax_utils.c b/tests/fax_utils.c index 7491d862..3869dc25 100644 --- a/tests/fax_utils.c +++ b/tests/fax_utils.c @@ -44,16 +44,22 @@ void fax_log_tx_parameters(t30_state_t *s, const char *tag) if ((u = t30_get_tx_ident(s))) printf("%s: Local ident '%s'\n", tag, u); + /*endif*/ if ((u = t30_get_tx_sub_address(s))) printf("%s: Local sub-address '%s'\n", tag, u); + /*endif*/ if ((u = t30_get_tx_polled_sub_address(s))) printf("%s: Local polled sub-address '%s'\n", tag, u); + /*endif*/ if ((u = t30_get_tx_selective_polling_address(s))) printf("%s: Local selective polling address '%s'\n", tag, u); + /*endif*/ if ((u = t30_get_tx_sender_ident(s))) printf("%s: Local sender ident '%s'\n", tag, u); + /*endif*/ if ((u = t30_get_tx_password(s))) printf("%s: Local password '%s'\n", tag, u); + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -63,22 +69,31 @@ void fax_log_rx_parameters(t30_state_t *s, const char *tag) if ((u = t30_get_rx_ident(s))) printf("%s: Remote ident '%s'\n", tag, u); + /*endif*/ if ((u = t30_get_rx_sub_address(s))) printf("%s: Remote sub-address '%s'\n", tag, u); + /*endif*/ if ((u = t30_get_rx_polled_sub_address(s))) printf("%s: Remote polled sub-address '%s'\n", tag, u); + /*endif*/ if ((u = t30_get_rx_selective_polling_address(s))) printf("%s: Remote selective polling address '%s'\n", tag, u); + /*endif*/ if ((u = t30_get_rx_sender_ident(s))) printf("%s: Remote sender ident '%s'\n", tag, u); + /*endif*/ if ((u = t30_get_rx_password(s))) printf("%s: Remote password '%s'\n", tag, u); + /*endif*/ if ((u = t30_get_rx_country(s))) printf("%s: Remote was made in '%s'\n", tag, u); + /*endif*/ if ((u = t30_get_rx_vendor(s))) printf("%s: Remote was made by '%s'\n", tag, u); + /*endif*/ if ((u = t30_get_rx_model(s))) printf("%s: Remote is model '%s'\n", tag, u); + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -123,12 +138,14 @@ int get_tiff_total_pages(const char *file) if ((tiff_file = TIFFOpen(file, "r")) == NULL) return -1; + /*endif*/ /* Each page *should* contain the total number of pages, but can this be trusted? Some files say 0. Actually searching for the last page is more reliable. */ max = 0; while (TIFFSetDirectory(tiff_file, (tdir_t) max)) max++; + /*endwhile*/ TIFFClose(tiff_file); return max; } diff --git a/tests/g1050_tests.c b/tests/g1050_tests.c index 397a2c62..0c849230 100644 --- a/tests/g1050_tests.c +++ b/tests/g1050_tests.c @@ -111,6 +111,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Bad model ID '%s'\n", optarg); exit(2); } + /*endif*/ break; case 's': speed_pattern_no = atoi(optarg); @@ -119,6 +120,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Bad link speed pattern %s\n", optarg); exit(2); } + /*endif*/ break; case 't': simulation_time = atoi(optarg); @@ -128,7 +130,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ argc -= optind; argv += optind; @@ -137,6 +141,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Can't open %s\n", "g1050_tests.txt"); return 2; } + /*endif*/ packets_per_sec = 1000/PACKET_INTERVAL; num_packets = packets_per_sec*simulation_time; @@ -145,8 +150,10 @@ int main(int argc, char *argv[]) fprintf(stderr, "Can't allocate the data buffers\n"); return 2; } + /*endif*/ for (i = 0; i < num_packets; i++) packet_arrival_times[i] = 0.0; + /*endfor*/ /* If we don't initialise this random number generator it gives endless zeros on some systems. */ /* Use a fixed seed to produce identical results in successive runs of the simulation, for debug purposes. */ @@ -157,6 +164,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Failed to start the G.1050 model\n"); exit(2); } + /*endif*/ g1050_dump_parms(model_no, speed_pattern_no); #if defined(ENABLE_GUI) @@ -166,6 +174,7 @@ int main(int argc, char *argv[]) for (i = 0; i < 256; i++) put_pkt[i] = i; + /*endfor*/ put_pkt_len = 256; get_pkt_len = -1; get_seq_no = -1; @@ -180,9 +189,11 @@ int main(int argc, char *argv[]) { if ((len = g1050_put(s, put_pkt, put_pkt_len, i, (double) i*0.001*PACKET_INTERVAL)) > 0) packets_really_put++; + /*endif*/ packets_put++; if (i == 5) g1050_queue_dump(s); + /*endif*/ if (i >= 5) { do @@ -199,18 +210,24 @@ int main(int argc, char *argv[]) oos_packets_got++; else if (get_seq_no > highest_seq_no_got + 1) missing_packets_got += (get_seq_no - highest_seq_no_got - 1); + /*endif*/ if (get_seq_no > highest_seq_no_got) highest_seq_no_got = get_seq_no; + /*endif*/ fprintf(out_file, "%d, %.3f, %.8f\n", get_seq_no, get_seq_no*0.001*PACKET_INTERVAL, get_arrival_time); } + /*endif*/ } while (get_pkt_len >= 0); } + /*endif*/ #if defined(ENABLE_GUI) if (use_gui) media_monitor_update_display(); + /*endif*/ #endif } + /*endfor*/ /* Clear out anything remaining in the queue, by jumping forwards in time */ do { @@ -220,6 +237,7 @@ int main(int argc, char *argv[]) packets_got++; fprintf(out_file, "%d, %.3f, %.8f\n", get_seq_no, get_seq_no*0.001*PACKET_INTERVAL, get_arrival_time); } + /*endif*/ } while (get_pkt_len >= 0); @@ -232,6 +250,7 @@ int main(int argc, char *argv[]) printf("%d packets queued, but only %d received\n", packets_really_put, packets_got); exit(2); } + /*endif*/ printf("%.3f%% of packets lost\n", 100.0*(packets_put - packets_really_put)/packets_put); g1050_free(s); free(packet_arrival_times); diff --git a/tests/g168_tests.c b/tests/g168_tests.c index 6eb9d7b4..2d036471 100644 --- a/tests/g168_tests.c +++ b/tests/g168_tests.c @@ -61,6 +61,7 @@ static void signal_load(signal_source_t *sig, const char *name) fprintf(stderr, " Error reading sound file '%s'\n", sig->name); exit(2); } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -71,6 +72,7 @@ static void signal_free(signal_source_t *sig) fprintf(stderr, " Cannot close sound file '%s'\n", sig->name); exit(2); } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -88,6 +90,7 @@ static int16_t signal_amp(signal_source_t *sig) tx = sig->signal[sig->cur++]*sig->gain; if (sig->cur >= sig->max) sig->cur = 0; + /*endif*/ return tx; } /*- End of function --------------------------------------------------------*/ @@ -160,6 +163,7 @@ int main(int argc, char *argv[]) tone_gen(&tone_state, amp, 8000); for (i = 0; i < 10; i++) power[i] = 0.0f; + /*endfor*/ for (i = 0; i < 800; i++) { signal = fir32(&line_model_d2, amp[i]); @@ -183,6 +187,7 @@ int main(int argc, char *argv[]) signal = amp[i]; power[9] += ((signal*signal - power[9])/32.0f); } + /*endfor*/ printf("%d %f %f %f %f %f %f %f %f %f %f\n", f, sqrt(power[0])*LINE_MODEL_D2_GAIN, @@ -196,9 +201,11 @@ int main(int argc, char *argv[]) sqrt(power[8]), sqrt(power[9])); } + /*endfor*/ awgn_init_dbm0(&noise_source, 1234567, -20.0f); for (i = 0; i < 10; i++) power[i] = 0.0f; + /*endfor*/ signal_restart(&local_css, 0.0f); signal_restart(&far_css, 0.0f); for (i = 0; i < SAMPLE_RATE; i++) @@ -226,8 +233,10 @@ int main(int argc, char *argv[]) signal = value; power[9] += ((signal*signal - power[9])/32.0f); } + /*endfor*/ for (i = 0; i < 10; i++) power[i] = 0.0f; + /*endfor*/ for (i = 0; i < SAMPLE_RATE; i++) { value = signal_amp(&local_css); @@ -253,6 +262,7 @@ int main(int argc, char *argv[]) signal = value; power[9] += ((signal*signal - power[9])/32.0f); } + /*endfor*/ printf("%d %f %f %f %f %f %f %f %f %f %f\n", 0, sqrt(power[0])*LINE_MODEL_D2_GAIN, @@ -304,9 +314,11 @@ int main(int argc, char *argv[]) for (i = 0; i < (int) (sizeof(css_c1)/sizeof(css_c1[0])); i++) printf("%d\n", css_c1[i]); + /*endfor*/ printf("\n"); for (i = 0; i < (int) (sizeof(css_c1)/sizeof(css_c3[0])); i++) printf("%d\n", css_c3[i]); + /*endfor*/ signal_free(&local_css); signal_free(&far_css); fir32_free(&line_model_d2); diff --git a/tests/g711_tests.c b/tests/g711_tests.c index 9efb8eba..a549b299 100644 --- a/tests/g711_tests.c +++ b/tests/g711_tests.c @@ -84,7 +84,9 @@ static void compliance_tests(int log_audio) fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ printf("Conversion accuracy tests.\n"); alaw_failures = 0; @@ -105,8 +107,10 @@ static void compliance_tests(int log_audio) printf("A-law: Excessive error at %d (%d)\n", pre, post); alaw_failures++; } + /*endif*/ if (tmp > worst_alaw) worst_alaw = tmp; + /*endif*/ } else { @@ -116,9 +120,12 @@ static void compliance_tests(int log_audio) printf("A-law: Excessive error at %d (%d)\n", pre, post); alaw_failures++; } + /*endif*/ } + /*endif*/ amp[i] = post; } + /*endfor*/ if (log_audio) { outframes = sf_writef_short(outhandle, amp, 65536); @@ -127,6 +134,7 @@ static void compliance_tests(int log_audio) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } for (i = 0; i < 65536; i++) { @@ -140,8 +148,10 @@ static void compliance_tests(int log_audio) printf("u-law: Excessive error at %d (%d)\n", pre, post); ulaw_failures++; } + /*endif*/ if (tmp > worst_ulaw) worst_ulaw = tmp; + /*endif*/ } else { @@ -151,9 +161,12 @@ static void compliance_tests(int log_audio) printf("u-law: Excessive error at %d (%d)\n", pre, post); ulaw_failures++; } + /*endif*/ } + /*endif*/ amp[i] = post; } + /*endfor*/ if (log_audio) { outframes = sf_writef_short(outhandle, amp, 65536); @@ -162,8 +175,11 @@ static void compliance_tests(int log_audio) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } + /*endif*/ } + /*endfor*/ printf("Worst A-law error (ignoring small values) %f%%\n", worst_alaw*100.0); printf("Worst u-law error (ignoring small values) %f%%\n", worst_ulaw*100.0); if (alaw_failures || ulaw_failures) @@ -173,6 +189,7 @@ static void compliance_tests(int log_audio) printf("Tests failed\n"); exit(2); } + /*endif*/ printf("Cyclic conversion repeatability tests.\n"); /* Find what happens to every possible linear value after a round trip. */ @@ -189,6 +206,7 @@ static void compliance_tests(int log_audio) printf("Tests failed\n"); exit(2); } + /*endif*/ /* Make a round trip */ post = ulaw_to_linear(linear_to_ulaw(pre)); /* A second round trip should cause no further change */ @@ -199,7 +217,9 @@ static void compliance_tests(int log_audio) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ printf("Reference power level tests.\n"); power_meter_init(&power_meter, 7); @@ -209,6 +229,7 @@ static void compliance_tests(int log_audio) amp[i] = ulaw_to_linear(ulaw_1khz_sine[i & 7]); power_meter_update(&power_meter, amp[i]); } + /*endfor*/ printf("Reference u-law 1kHz tone is %fdBm0\n", power_meter_current_dbm0(&power_meter)); if (log_audio) { @@ -218,18 +239,22 @@ static void compliance_tests(int log_audio) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } + /*endif*/ if (0.1f < fabs(power_meter_current_dbm0(&power_meter))) { printf("Test failed.\n"); exit(2); } + /*endif*/ for (i = 0; i < 8000; i++) { amp[i] = alaw_to_linear(alaw_1khz_sine[i & 7]); power_meter_update(&power_meter, amp[i]); } + /*endfor*/ printf("Reference A-law 1kHz tone is %fdBm0\n", power_meter_current_dbm0(&power_meter)); if (log_audio) { @@ -239,12 +264,15 @@ static void compliance_tests(int log_audio) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } + /*endif*/ if (0.1f < fabs(power_meter_current_dbm0(&power_meter))) { printf("Test failed.\n"); exit(2); } + /*endif*/ /* Check the transcoding functions. */ printf("Testing transcoding A-law -> u-law -> A-law\n"); @@ -258,8 +286,11 @@ static void compliance_tests(int log_audio) printf("Test failed\n"); exit(2); } + /*endif*/ } + /*endif*/ } + /*endfor*/ printf("Testing transcoding u-law -> A-law -> u-law\n"); for (i = 0; i < 256; i++) @@ -272,8 +303,11 @@ static void compliance_tests(int log_audio) printf("Test failed\n"); exit(2); } + /*endif*/ } + /*endif*/ } + /*endfor*/ enc_state = g711_init(NULL, G711_ALAW); transcode = g711_init(NULL, G711_ALAW); @@ -282,6 +316,7 @@ static void compliance_tests(int log_audio) len = 65536; for (i = 0; i < len; i++) amp[i] = i - 32768; + /*endfor*/ len = g711_encode(enc_state, alaw_data, amp, len); len = g711_transcode(transcode, ulaw_data, alaw_data, len); len = g711_decode(dec_state, amp, ulaw_data, len); @@ -291,6 +326,7 @@ static void compliance_tests(int log_audio) printf("Test failed\n"); exit(2); } + /*endif*/ for (i = 0; i < len; i++) { pre = i - 32768; @@ -303,6 +339,7 @@ static void compliance_tests(int log_audio) printf("Block: Excessive error at %d (%d)\n", pre, post); exit(2); } + /*endif*/ } else { @@ -312,8 +349,11 @@ static void compliance_tests(int log_audio) printf("Block: Excessive error at %d (%d)\n", pre, post); exit(2); } + /*endif*/ } + /*endif*/ } + /*endfor*/ g711_free(enc_state); g711_free(transcode); g711_free(dec_state); @@ -325,7 +365,9 @@ static void compliance_tests(int log_audio) fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ printf("Tests passed.\n"); } @@ -388,7 +430,9 @@ int main(int argc, char *argv[]) //usage(); exit(2); } + /*endswitch*/ } + /*endwhile*/ if (basic_tests) { @@ -401,14 +445,17 @@ int main(int argc, char *argv[]) decode = encode = true; } + /*endif*/ if (in_file == NULL) { in_file = (encode) ? IN_FILE_NAME : ENCODED_FILE_NAME; } + /*endif*/ if (out_file == NULL) { out_file = (decode) ? OUT_FILE_NAME : ENCODED_FILE_NAME; } + /*endif*/ inhandle = NULL; outhandle = NULL; file = -1; @@ -421,6 +468,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", in_file); exit(2); } + /*endif*/ enc_state = g711_init(NULL, law); } else @@ -430,6 +478,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Failed to open '%s'\n", in_file); exit(2); } + /*endif*/ } if (decode) { @@ -438,6 +487,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot create audio file '%s'\n", out_file); exit(2); } + /*endif*/ dec_state = g711_init(NULL, law); } else @@ -447,7 +497,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Failed to open '%s'\n", out_file); exit(2); } + /*endif*/ } + /*endif*/ for (;;) { if (encode) @@ -455,6 +507,7 @@ int main(int argc, char *argv[]) samples = sf_readf_short(inhandle, indata, BLOCK_LEN); if (samples <= 0) break; + /*endif*/ len2 = g711_encode(enc_state, g711data, indata, samples); } else @@ -462,7 +515,9 @@ int main(int argc, char *argv[]) len2 = read(file, g711data, BLOCK_LEN); if (len2 <= 0) break; + /*endif*/ } + /*endif*/ if (decode) { len3 = g711_decode(dec_state, outdata, g711data, len2); @@ -472,14 +527,18 @@ int main(int argc, char *argv[]) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } else { len3 = write(file, g711data, len2); if (len3 <= 0) break; + /*endif*/ } + /*endif*/ } + /*endfor*/ if (encode) { if (sf_close_telephony(inhandle)) @@ -487,11 +546,13 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", IN_FILE_NAME); exit(2); } + /*endif*/ } else { close(file); } + /*endif*/ if (decode) { if (sf_close_telephony(outhandle)) @@ -499,13 +560,16 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ } else { close(file); } + /*endif*/ printf("'%s' translated to '%s' using %s.\n", in_file, out_file, (law == G711_ALAW) ? "A-law" : "u-law"); } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/g722_tests.c b/tests/g722_tests.c index 9e513123..d69dd6db 100644 --- a/tests/g722_tests.c +++ b/tests/g722_tests.c @@ -157,13 +157,17 @@ static int hex_get(char *s) x = *s++ - 0x30; if (x > 9) x -= 0x07; + /*endif*/ if (x > 15) x -= 0x20; + /*endif*/ if (x < 0 || x > 15) return -1; + /*endif*/ value <<= 4; value |= x; } + /*endfor*/ return value; } /*- End of function --------------------------------------------------------*/ @@ -179,6 +183,7 @@ static int get_vector(FILE *file, uint16_t vec[]) { if (buf[0] == '/' && buf[1] == '*') continue; + /*endif*/ s = buf; i = 0; while ((value = hex_get(s)) >= 0) @@ -186,8 +191,10 @@ static int get_vector(FILE *file, uint16_t vec[]) vec[i++] = value; s += 4; } + /*endwhile*/ return i; } + /*endwhile*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -203,9 +210,11 @@ static int get_test_vector(const char *file, uint16_t buf[], int max_len) fprintf(stderr, " Failed to open '%s'\n", file); exit(2); } + /*endif*/ octets = 0; while ((i = get_vector(infile, buf + octets)) > 0) octets += i; + /*endwhile*/ fclose(infile); return octets; } @@ -244,18 +253,23 @@ static void itu_compliance_tests(void) printf("Test data length mismatch\n"); exit(2); } + /*endif*/ /* Process the input data */ /* Skip the reset stuff at each end of the data */ for (i = 0; i < len_data; i++) { if ((itu_data[i] & 1) == 0) break; + /*endif*/ } + /*endfor*/ for (j = i; j < len_data; j++) { if ((itu_data[j] & 1)) break; + /*endif*/ } + /*endfor*/ len = j - i; enc_state = g722_encode_init(NULL, 64000, 0); enc_state->itu_test_mode = true; @@ -270,16 +284,20 @@ static void itu_compliance_tests(void) printf(">>> %6d %4x %4x\n", k, compressed[k] & 0xFF, itu_ref[k + i] & 0xFFFF); j++; } + /*endif*/ } + /*endfor*/ printf("%d bad samples, out of %d/%d samples\n", j, len, len_data); if (j) { printf("Test failed\n"); exit(2); } + /*endif*/ printf("Test passed\n"); g722_encode_free(enc_state); } + /*endfor*/ #endif #if 1 /* ITU G.722 decode tests, using configuration 2. The QMF is bypassed */ @@ -308,21 +326,27 @@ static void itu_compliance_tests(void) printf("Test data length mismatch\n"); exit(2); } + /*endif*/ /* Process the input data */ /* Skip the reset stuff at each end of the data */ for (i = 0; i < len_data; i++) { if ((itu_data[i] & 1) == 0) break; + /*endif*/ } + /*endfor*/ for (j = i; j < len_data; j++) { if ((itu_data[j] & 1)) break; + /*endif*/ } + /*endfor*/ len = j - i; for (k = 0; k < len; k++) compressed[k] = itu_data[k + i] >> ((mode == 3) ? 10 : (mode == 2) ? 9 : 8); + /*endfor*/ dec_state = g722_decode_init(NULL, (mode == 3) ? 48000 : (mode == 2) ? 56000 : 64000, 0); dec_state->itu_test_mode = true; @@ -339,17 +363,22 @@ static void itu_compliance_tests(void) printf(">>> %6d %4x %4x %4x %4x\n", k >> 1, decompressed[k] & 0xFFFF, decompressed[k + 1] & 0xFFFF, itu_ref[(k >> 1) + i] & 0xFFFF, itu_ref_upper[(k >> 1) + i] & 0xFFFF); j++; } + /*endif*/ } + /*endfor*/ printf("%d bad samples, out of %d/%d samples\n", j, len, len_data); if (j) { printf("Test failed\n"); exit(2); } + /*endif*/ printf("Test passed\n"); g722_decode_free(dec_state); } + /*endfor*/ } + /*endfor*/ #endif printf("Tests passed.\n"); } @@ -384,11 +413,13 @@ static void signal_to_distortion_tests(void) memset(original, 0, len*sizeof(original[0])); for (i = 0; i < len; i++) in_level = power_meter_update(in_meter, original[i]); + /*endfor*/ len2 = g722_encode(enc_state, compressed, original, len); len3 = g722_decode(dec_state, decompressed, compressed, len2); out_level = 0; for (i = 0; i < len3; i++) out_level = power_meter_update(out_meter, decompressed[i]); + /*endfor*/ printf("Silence produces %d at the output\n", out_level); /* Now a swept tone test */ @@ -398,10 +429,12 @@ static void signal_to_distortion_tests(void) len = swept_tone(swept, original, 1024); for (i = 0; i < len; i++) in_level = power_meter_update(in_meter, original[i]); + /*endfor*/ len2 = g722_encode(enc_state, compressed, original, len); len3 = g722_decode(dec_state, decompressed, compressed, len2); for (i = 0; i < len3; i++) out_level = power_meter_update(out_meter, decompressed[i]); + /*endfor*/ printf("%10d, %10d, %f\n", in_level, out_level, (float) out_level/in_level); } while (len > 0); @@ -463,6 +496,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Invalid bit rate selected. Only 48000, 56000 and 64000 are valid.\n"); exit(2); } + /*endif*/ itutests = false; break; case 'd': @@ -482,9 +516,11 @@ int main(int argc, char *argv[]) fprintf(stderr, "Invalid incoming sample rate. Only 8000 and 16000 are valid.\n"); exit(2); } + /*endif*/ eight_k_in = (i == 8000); if (eight_k_in) in_file = EIGHTK_IN_FILE_NAME; + /*endif*/ break; case 'l': out_file = optarg; @@ -496,6 +532,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Invalid outgoing sample rate. Only 8000 and 16000 are valid.\n"); exit(2); } + /*endif*/ eight_k_out = (i == 8000); break; case 't': @@ -506,7 +543,9 @@ int main(int argc, char *argv[]) //usage(); exit(2); } + /*endswitch*/ } + /*endwhile*/ if (itutests) { @@ -523,6 +562,7 @@ int main(int argc, char *argv[]) decode = encode = true; } + /*endif*/ if (in_file == NULL) { if (encode) @@ -531,16 +571,20 @@ int main(int argc, char *argv[]) in_file = EIGHTK_IN_FILE_NAME; else in_file = IN_FILE_NAME; + /*endif*/ } else { in_file = ENCODED_FILE_NAME; } + /*endif*/ } + /*endif*/ if (out_file == NULL) { out_file = (decode) ? OUT_FILE_NAME : ENCODED_FILE_NAME; } + /*endif*/ inhandle = NULL; outhandle = NULL; file = -1; @@ -553,16 +597,19 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", in_file); exit(2); } + /*endif*/ if (info.samplerate != SAMPLE_RATE) { fprintf(stderr, " Unexpected sample rate %d in audio file '%s'\n", info.samplerate, in_file); exit(2); } + /*endif*/ if (info.channels != 1) { fprintf(stderr, " Unexpected number of channels in audio file '%s'\n", in_file); exit(2); } + /*endif*/ enc_state = g722_encode_init(NULL, bit_rate, G722_PACKED | G722_SAMPLE_RATE_8000); } else @@ -572,18 +619,22 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", in_file); exit(2); } + /*endif*/ if (info.samplerate != G722_SAMPLE_RATE) { fprintf(stderr, " Unexpected sample rate %d in audio file '%s'\n", info.samplerate, in_file); exit(2); } + /*endif*/ if (info.channels != 1) { fprintf(stderr, " Unexpected number of channels in audio file '%s'\n", in_file); exit(2); } + /*endif*/ enc_state = g722_encode_init(NULL, bit_rate, G722_PACKED); } + /*endif*/ } else { @@ -592,7 +643,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Failed to open '%s'\n", in_file); exit(2); } + /*endif*/ } + /*endif*/ dec_state = NULL; if (decode) { @@ -608,10 +661,12 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot create audio file '%s'\n", out_file); exit(2); } + /*endif*/ if (eight_k_out) dec_state = g722_decode_init(NULL, bit_rate, G722_PACKED | G722_SAMPLE_RATE_8000); else dec_state = g722_decode_init(NULL, bit_rate, G722_PACKED); + /*endif*/ } else { @@ -620,7 +675,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Failed to open '%s'\n", out_file); exit(2); } + /*endif*/ } + /*endif*/ for (;;) { if (encode) @@ -628,11 +685,14 @@ int main(int argc, char *argv[]) samples = sf_readf_short(inhandle, indata, BLOCK_LEN); if (samples <= 0) break; + /*endif*/ if (tone_test) { for (i = 0; i < samples; i++) indata[i] = dds_modf(&tone_phase, tone_phase_rate, tone_level, 0); + /*endfor*/ } + /*endif*/ len2 = g722_encode(enc_state, adpcmdata, indata, samples); } else @@ -640,7 +700,9 @@ int main(int argc, char *argv[]) len2 = read(file, adpcmdata, BLOCK_LEN); if (len2 <= 0) break; + /*endif*/ } + /*endif*/ if (decode) { len3 = g722_decode(dec_state, outdata, adpcmdata, len2); @@ -650,14 +712,18 @@ int main(int argc, char *argv[]) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } else { len3 = write(file, adpcmdata, len2); if (len3 <= 0) break; + /*endif*/ } + /*endif*/ } + /*endfor*/ if (encode) { if (sf_close(inhandle)) @@ -665,12 +731,14 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", IN_FILE_NAME); exit(2); } + /*endif*/ g722_encode_free(enc_state); } else { close(file); } + /*endif*/ if (decode) { if (sf_close(outhandle)) @@ -678,12 +746,14 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ g722_decode_free(dec_state); } else { close(file); } + /*endif*/ printf("'%s' translated to '%s' at %dbps.\n", in_file, out_file, bit_rate); } return 0; diff --git a/tests/g726_tests.c b/tests/g726_tests.c index 45f64c22..678ccb7d 100644 --- a/tests/g726_tests.c +++ b/tests/g726_tests.c @@ -1004,13 +1004,17 @@ static int hex_get(char *s) x = *s++ - 0x30; if (x > 9) x -= 0x07; + /*endif*/ if (x > 15) x -= 0x20; + /*endif*/ if (x < 0 || x > 15) return -1; + /*endif*/ value <<= 4; value |= x; } + /*endfor*/ return value; } /*- End of function --------------------------------------------------------*/ @@ -1031,8 +1035,10 @@ static int get_vector(FILE *file, uint8_t vec[]) vec[i++] = value; s += 2; } + /*endwhile*/ return i; } + /*endwhile*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -1049,9 +1055,11 @@ static int get_test_vector(const char *file, uint8_t buf[], int max_len) fprintf(stderr, " Failed to open '%s'\n", file); exit(2); } + /*endif*/ octets = 0; while ((i = get_vector(infile, buf + octets)) > 0) octets += i; + /*endwhile*/ fclose(infile); /* The last octet is a sumcheck, so the real data octets are one less than the total we have */ @@ -1059,11 +1067,13 @@ static int get_test_vector(const char *file, uint8_t buf[], int max_len) /* Test the checksum */ for (sum = i = 0; i < octets; i++) sum += buf[i]; + /*endfor*/ if (sum%255 != (int) buf[i]) { fprintf(stderr, " Sumcheck failed in '%s' - %x %x\n", file, sum%255, buf[i]); exit(2); } + /*endif*/ return octets; } /*- End of function --------------------------------------------------------*/ @@ -1111,11 +1121,13 @@ static void itu_compliance_tests(void) { conditioning_samples = 0; } + /*endif*/ samples = get_test_vector(itu_test_sets[test].pcm_file, xlaw + conditioning_samples, MAX_TEST_VECTOR_LEN); memcpy(itudata, xlaw, samples + conditioning_samples); printf("Test %d: Compressing %d samples at %dbps\n", test, samples, itu_test_sets[test].rate); len2 = g726_encode(&enc_state, adpcmdata, itudata, conditioning_samples + samples); } + /*endif*/ /* Test the decode side */ g726_init(&dec_state, itu_test_sets[test].rate, itu_test_sets[test].decompression_law, G726_PACKING_NONE); if (itu_test_sets[test].conditioning_adpcm_file[0]) @@ -1127,6 +1139,7 @@ static void itu_compliance_tests(void) { conditioning_adpcm = 0; } + /*endif*/ adpcm = get_test_vector(itu_test_sets[test].adpcm_file, unpacked + conditioning_adpcm, MAX_TEST_VECTOR_LEN); if (itu_test_sets[test].compression_law != G726_ENCODING_NONE) { @@ -1141,12 +1154,15 @@ static void itu_compliance_tests(void) bad_samples++; printf("Test %d: Compressed mismatch %d %x %x\n", test, i, adpcmdata[i], unpacked[i]); } + /*endif*/ } + /*endfor*/ if (bad_samples > 0) { printf("Test failed\n"); exit(2); } + /*endif*/ printf("Test passed\n"); } else @@ -1154,7 +1170,9 @@ static void itu_compliance_tests(void) printf("Test %d: Length mismatch - ref = %d, processed = %d\n", test, conditioning_adpcm + adpcm, len2); exit(2); } + /*endif*/ } + /*endif*/ len3 = g726_decode(&dec_state, outdata, unpacked, conditioning_adpcm + adpcm); @@ -1172,12 +1190,15 @@ static void itu_compliance_tests(void) bad_samples++; printf("Test %d: Decompressed mismatch %d %x %x\n", test, i, itu_ref[i], ((uint8_t *) outdata)[i + conditioning_adpcm]); } + /*endif*/ } + /*endfor*/ if (bad_samples > 0) { printf("Test failed\n"); exit(2); } + /*endif*/ printf("Test passed\n"); } else @@ -1185,7 +1206,9 @@ static void itu_compliance_tests(void) printf("Test %d: Length mismatch - ref = %d, processed = %d\n", test, samples, len3 - conditioning_adpcm); exit(2); } + /*endif*/ } + /*endfor*/ printf("Tests passed.\n"); } @@ -1219,6 +1242,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Invalid bit rate selected. Only 16000, 24000, 32000 and 40000 are valid.\n"); exit(2); } + /*endif*/ itutests = false; break; case 'L': @@ -1231,7 +1255,9 @@ int main(int argc, char *argv[]) //usage(); exit(2); } + /*endswitch*/ } + /*endwhile*/ if (itutests) { @@ -1244,11 +1270,13 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", IN_FILE_NAME); exit(2); } + /*endif*/ if ((outhandle = sf_open_telephony_write(OUT_FILE_NAME, 1)) == NULL) { fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ printf("ADPCM packing is %d\n", packing); enc_state = g726_init(NULL, bit_rate, G726_ENCODING_LINEAR, packing); @@ -1260,20 +1288,24 @@ int main(int argc, char *argv[]) frames = g726_decode(dec_state, amp, adpcmdata, adpcm); sf_writef_short(outhandle, amp, frames); } + /*endwhile*/ if (sf_close_telephony(inhandle)) { printf(" Cannot close audio file '%s'\n", IN_FILE_NAME); exit(2); } + /*endif*/ if (sf_close_telephony(outhandle)) { printf(" Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ printf("'%s' transcoded to '%s' at %dbps.\n", IN_FILE_NAME, OUT_FILE_NAME, bit_rate); g726_free(enc_state); g726_free(dec_state); } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/gsm0610_tests.c b/tests/gsm0610_tests.c index 06177fd9..07392004 100644 --- a/tests/gsm0610_tests.c +++ b/tests/gsm0610_tests.c @@ -162,11 +162,13 @@ static int get_test_vector(int full, int disk, const char *name) fprintf(stderr, "Cannot open %s\n", buf); exit(2); } + /*endif*/ len = read(in, in_vector, 1000000); close(in); len /= sizeof(int16_t); vector_len = len; } + /*endif*/ sprintf(buf, "%s%c/%s.out", TESTDATA_DIR, 'L', name); if ((in = open(buf, O_RDONLY)) < 0) @@ -174,6 +176,7 @@ static int get_test_vector(int full, int disk, const char *name) fprintf(stderr, "Cannot open %s\n", buf); exit(2); } + /*endif*/ len = read(in, ref_out_vector, 1000000); close(in); len /= sizeof(int16_t); @@ -184,11 +187,13 @@ static int get_test_vector(int full, int disk, const char *name) fprintf(stderr, "Input and reference vector lengths do not match - %d %d\n", vector_len, len); exit(2); } + /*endif*/ } else { vector_len = len; } + /*endif*/ sprintf(buf, "%s%c/%s.cod", TESTDATA_DIR, 'L', name); if ((in = open(buf, O_RDONLY)) < 0) @@ -196,6 +201,7 @@ static int get_test_vector(int full, int disk, const char *name) fprintf(stderr, "Cannot open %s\n", buf); exit(2); } + /*endif*/ len = read(in, code_vector_buf, 1000000); close(in); len /= sizeof(int16_t); @@ -204,11 +210,13 @@ static int get_test_vector(int full, int disk, const char *name) ref_code_vector[i] = code_vector_buf[i]; decoder_code_vector[i] = code_vector_buf[i]; } + /*endfor*/ if (len*BLOCK_LEN != vector_len*76) { fprintf(stderr, "Input and code vector lengths do not match - %d %d\n", vector_len, len); exit(2); } + /*endif*/ return len; } @@ -232,6 +240,7 @@ static int get_law_test_vector(int full, int law, const char *name) fprintf(stderr, "Cannot open %s\n", buf); exit(2); } + /*endif*/ len = read(in, law_in_vector, 1000000); close(in); vector_len = len; @@ -247,12 +256,15 @@ static int get_law_test_vector(int full, int law, const char *name) len /= sizeof(int16_t); for (i = 0; i < len; i++) ref_code_vector[i] = code_vector_buf[i]; + /*endfor*/ if (len*BLOCK_LEN != vector_len*76) { fprintf(stderr, "Input and code vector lengths do not match - %d %d\n", vector_len, len); exit(2); } + /*endif*/ } + /*endif*/ sprintf(buf, "%s%c/%s-%c.out", TESTDATA_DIR, law_uc, name, law_uc); if ((in = open(buf, O_RDONLY)) < 0) @@ -260,6 +272,7 @@ static int get_law_test_vector(int full, int law, const char *name) fprintf(stderr, "Cannot open %s\n", buf); exit(2); } + /*endif*/ len = read(in, ref_law_out_vector, 1000000); close(in); if (full) @@ -269,11 +282,13 @@ static int get_law_test_vector(int full, int law, const char *name) fprintf(stderr, "Input and reference vector lengths do not match - %d %d\n", vector_len, len); exit(2); } + /*endif*/ } else { vector_len = len; } + /*endif*/ sprintf(buf, "%s%c/%s.cod", TESTDATA_DIR, 'L', name); if ((in = open(buf, O_RDONLY)) < 0) @@ -281,11 +296,13 @@ static int get_law_test_vector(int full, int law, const char *name) fprintf(stderr, "Cannot open %s\n", buf); exit(2); } + /*endif*/ len = read(in, code_vector_buf, 1000000); close(in); len /= sizeof(int16_t); for (i = 0; i < len; i++) decoder_code_vector[i] = code_vector_buf[i]; + /*endfor*/ return len; } @@ -310,6 +327,7 @@ static int perform_linear_test(int full, int disk, const char *name) fprintf(stderr, " Cannot create encoder\n"); exit(2); } + /*endif*/ xxx = gsm0610_encode(gsm0610_enc_state, code_vector, in_vector, vector_len); printf("Check code vector of length %d\n", xxx); @@ -320,21 +338,26 @@ static int perform_linear_test(int full, int disk, const char *name) printf("%8d/%3d: %6d %6d\n", i/76, i%76, code_vector[i], ref_code_vector[i]); mismatches++; } + /*endif*/ } + /*endfor*/ gsm0610_free(gsm0610_enc_state); if (mismatches) { printf("Test failed: %d of %d samples mismatch\n", mismatches, xxx); exit(2); } + /*endif*/ printf("Test passed\n"); } + /*endif*/ if ((gsm0610_dec_state = gsm0610_init(NULL, GSM0610_PACKING_NONE)) == NULL) { fprintf(stderr, " Cannot create decoder\n"); exit(2); } + /*endif*/ xxx = gsm0610_decode(gsm0610_dec_state, out_vector, decoder_code_vector, vector_len); printf("Check output vector of length %d\n", vector_len); for (i = 0, mismatches = 0; i < vector_len; i++) @@ -344,12 +367,15 @@ static int perform_linear_test(int full, int disk, const char *name) printf("%8d: %6d %6d\n", i, out_vector[i], ref_out_vector[i]); mismatches++; } + /*endif*/ } + /*endfor*/ if (mismatches) { printf("Test failed: %d of %d samples mismatch\n", mismatches, vector_len); exit(2); } + /*endif*/ gsm0610_free(gsm0610_dec_state); printf("Test passed\n"); return 0; @@ -368,6 +394,7 @@ static int perform_law_test(int full, int law, const char *name) printf("Performing A-law test '%s'\n", name); else printf("Performing u-law test '%s'\n", name); + /*endif*/ get_law_test_vector(full, law, name); @@ -378,16 +405,20 @@ static int perform_law_test(int full, int law, const char *name) fprintf(stderr, " Cannot create encoder\n"); exit(2); } + /*endif*/ if (law == 'a') { for (i = 0; i < vector_len; i++) in_vector[i] = alaw_to_linear(law_in_vector[i]); + /*endfor*/ } else { for (i = 0; i < vector_len; i++) in_vector[i] = ulaw_to_linear(law_in_vector[i]); + /*endfor*/ } + /*endif*/ xxx = gsm0610_encode(gsm0610_enc_state, code_vector, in_vector, vector_len); printf("Check code vector of length %d\n", xxx); @@ -398,12 +429,15 @@ static int perform_law_test(int full, int law, const char *name) printf("%8d/%3d: %6d %6d %6d\n", i/76, i%76, code_vector[i], ref_code_vector[i], decoder_code_vector[i]); mismatches++; } + /*endif*/ } + /*endfor*/ if (mismatches) { printf("Test failed: %d of %d samples mismatch\n", mismatches, xxx); exit(2); } + /*endif*/ printf("Test passed\n"); gsm0610_free(gsm0610_enc_state); } @@ -413,17 +447,21 @@ static int perform_law_test(int full, int law, const char *name) fprintf(stderr, " Cannot create decoder\n"); exit(2); } + /*endif*/ xxx = gsm0610_decode(gsm0610_dec_state, out_vector, decoder_code_vector, vector_len); if (law == 'a') { for (i = 0; i < vector_len; i++) law_out_vector[i] = linear_to_alaw(out_vector[i]); + /*endfor*/ } else { for (i = 0; i < vector_len; i++) law_out_vector[i] = linear_to_ulaw(out_vector[i]); + /*endfor*/ } + /*endif*/ printf("Check output vector of length %d\n", vector_len); for (i = 0, mismatches = 0; i < vector_len; i++) { @@ -432,12 +470,15 @@ static int perform_law_test(int full, int law, const char *name) printf("%8d: %6d %6d\n", i, law_out_vector[i], ref_law_out_vector[i]); mismatches++; } + /*endif*/ } + /*endfor*/ if (mismatches) { printf("Test failed: %d of %d samples mismatch\n", mismatches, vector_len); exit(2); } + /*endif*/ gsm0610_free(gsm0610_dec_state); printf("Test passed\n"); return 0; @@ -482,6 +523,7 @@ static int perform_pack_unpack_test(void) { for (i = 0; i < 65; i++) a[i] = rand(); + /*endfor*/ repack_gsm0610_wav49_to_voip(b, a); repack_gsm0610_voip_to_wav49(c, b); if (memcmp(a, c, 65)) @@ -489,9 +531,11 @@ static int perform_pack_unpack_test(void) printf("Test failed: data mismatch\n"); exit(2); } + /*endif*/ for (i = 0; i < 66; i++) a[i] = rand(); + /*endfor*/ /* Insert the magic code */ a[0] = (a[0] & 0xF) | 0xD0; a[33] = (a[33] & 0xF) | 0xD0; @@ -504,7 +548,9 @@ static int perform_pack_unpack_test(void) printf("Test failed: data mismatch\n"); exit(2); } + /*endif*/ } + /*endfor*/ printf("Test passed\n"); return 0; } @@ -565,7 +611,9 @@ int main(int argc, char *argv[]) //usage(); exit(2); } + /*endswitch*/ } + /*endwhile*/ if (etsitests) { @@ -578,23 +626,27 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", IN_FILE_NAME); exit(2); } + /*endif*/ if ((outhandle = sf_open_telephony_write(OUT_FILE_NAME, 1)) == NULL) { fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ if ((gsm0610_enc_state = gsm0610_init(NULL, packing)) == NULL) { fprintf(stderr, " Cannot create encoder\n"); exit(2); } + /*endif*/ if ((gsm0610_dec_state = gsm0610_init(NULL, packing)) == NULL) { fprintf(stderr, " Cannot create decoder\n"); exit(2); } + /*endif*/ while ((frames = sf_readf_short(inhandle, pre_amp, 2*BLOCK_LEN))) { @@ -602,20 +654,24 @@ int main(int argc, char *argv[]) gsm0610_decode(gsm0610_dec_state, post_amp, gsm0610_data, bytes); sf_writef_short(outhandle, post_amp, frames); } + /*endwhile*/ if (sf_close_telephony(inhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", IN_FILE_NAME); exit(2); } + /*endif*/ if (sf_close_telephony(outhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ gsm0610_free(gsm0610_enc_state); gsm0610_free(gsm0610_dec_state); } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/ima_adpcm_tests.c b/tests/ima_adpcm_tests.c index 46645f09..af8d6194 100644 --- a/tests/ima_adpcm_tests.c +++ b/tests/ima_adpcm_tests.c @@ -117,31 +117,37 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ if ((inhandle = sf_open_telephony_read(in_file_name, 1)) == NULL) { fprintf(stderr, " Cannot open audio file '%s'\n", in_file_name); exit(2); } + /*endif*/ if ((outhandle = sf_open_telephony_write(OUT_FILE_NAME, 1)) == NULL) { fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ if ((ima_enc_state = ima_adpcm_init(NULL, variant, enc_chunk_size)) == NULL) { fprintf(stderr, " Cannot create encoder\n"); exit(2); } + /*endif*/ if ((ima_dec_state = ima_adpcm_init(NULL, variant, enc_chunk_size)) == NULL) { fprintf(stderr, " Cannot create decoder\n"); exit(2); } + /*endif*/ hist_in = 0; hist_out = 0; @@ -157,6 +163,7 @@ int main(int argc, char *argv[]) ima_bytes = ima_adpcm_encode(ima_enc_state, ima_data, pre_amp, frames); if (log_encoded_data) write(1, ima_data, ima_bytes); + /*endif*/ total_compressed_bytes += ima_bytes; dec_frames = ima_adpcm_decode(ima_dec_state, post_amp, ima_data, ima_bytes); total_post_samples += dec_frames; @@ -165,28 +172,35 @@ int main(int argc, char *argv[]) history[hist_in++] = pre_amp[i]; if (hist_in >= HIST_LEN) hist_in = 0; + /*endif*/ pre_energy += (double) pre_amp[i] * (double) pre_amp[i]; } + /*endfor*/ for (i = 0; i < dec_frames; i++) { post_energy += (double) post_amp[i] * (double) post_amp[i]; xx = post_amp[i] - history[hist_out++]; if (hist_out >= HIST_LEN) hist_out = 0; + /*endif*/ diff_energy += (double) xx * (double) xx; } + /*endfor*/ sf_writef_short(outhandle, post_amp, dec_frames); } + /*endwhile*/ if (sf_close_telephony(inhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", in_file_name); exit(2); } + /*endif*/ if (sf_close_telephony(outhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ ima_adpcm_free(ima_enc_state); ima_adpcm_free(ima_dec_state); @@ -203,6 +217,7 @@ int main(int argc, char *argv[]) printf("Tests failed.\n"); exit(2); } + /*endif*/ printf("Tests passed.\n"); return 0; diff --git a/tests/image_translate_tests.c b/tests/image_translate_tests.c index 9ec0691f..c317f248 100644 --- a/tests/image_translate_tests.c +++ b/tests/image_translate_tests.c @@ -68,6 +68,7 @@ static void display_row(int row, int width, uint8_t buf[]) test_pixel = (buf[i >> 3] >> (7 - (i & 7))) & 0x01; printf("%c", (test_pixel) ? ' ' : '@'); } + /*endfor*/ printf("\n"); } /*- End of function --------------------------------------------------------*/ @@ -95,7 +96,9 @@ static void create_undithered_50_by_50(image_descriptor_t *im, uint8_t buf[], in { for (j = 0; j < im->width; j++) image8[im->width*i + j] = ((i + j)*655) >> 8; + /*endfor*/ } + /*endfor*/ break; case 2: samples_per_pixel = 1; @@ -104,7 +107,9 @@ static void create_undithered_50_by_50(image_descriptor_t *im, uint8_t buf[], in { for (j = 0; j < im->width; j++) image16[im->width*i + j] = (i + j)*655; + /*endfor*/ } + /*endfor*/ break; case 3: samples_per_pixel = 3; @@ -123,7 +128,9 @@ static void create_undithered_50_by_50(image_descriptor_t *im, uint8_t buf[], in image8[samples_per_pixel*(im->width*i + j) + 2] = saturateu8((((i + j)*655U)*47900U) >> 22); #endif } + /*endfor*/ } + /*endfor*/ break; case 4: samples_per_pixel = 4; @@ -144,7 +151,9 @@ static void create_undithered_50_by_50(image_descriptor_t *im, uint8_t buf[], in image8[samples_per_pixel*(im->width*i + j) + 3] = 0; #endif } + /*endfor*/ } + /*endfor*/ break; case 6: samples_per_pixel = 3; @@ -163,7 +172,9 @@ static void create_undithered_50_by_50(image_descriptor_t *im, uint8_t buf[], in image16[samples_per_pixel*(im->width*i + j) + 2] = saturateu16((((i + j)*655U)*47900U) >> 14); #endif } + /*endfor*/ } + /*endfor*/ break; case 8: samples_per_pixel = 4; @@ -184,9 +195,12 @@ static void create_undithered_50_by_50(image_descriptor_t *im, uint8_t buf[], in image16[samples_per_pixel*(im->width*i + j) + 3] = 0; #endif } + /*endfor*/ } + /*endfor*/ break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -257,7 +271,9 @@ static int test_dithered_50_by_50(int row, int width, uint8_t buf[]) test_pixel = (buf[i >> 3] >> (7 - (i & 7))) & 0x01; if (ref_pixel != test_pixel) match = -1; + /*endif*/ } + /*endfor*/ return match; } /*- End of function --------------------------------------------------------*/ @@ -269,6 +285,7 @@ static int row_read(void *user_data, uint8_t buf[], size_t len) im = (image_descriptor_t *) user_data; if (im->current_row >= im->length) return 0; + /*endif*/ memcpy(buf, &im->image[im->current_row*im->width*im->bytes_per_pixel], len); im->current_row++; return len; @@ -288,6 +305,7 @@ static void get_bilevel_image(image_translate_state_t *s, int compare) printf("Image finished early - %d %d\n", len, (s->output_width + 7)/8); exit(2); } + /*endif*/ display_row(i, s->output_width, row_buf); if (compare) { @@ -296,13 +314,17 @@ static void get_bilevel_image(image_translate_state_t *s, int compare) printf("Dithered image mismatch at row %d\n", i); //exit(2); } + /*endif*/ } + /*endif*/ } + /*endfor*/ if ((len = image_translate_row(s, row_buf, (s->output_width + 7)/8)) != 0) { printf("Image finished late - %d %d\n", len, (s->output_width + 7)/8); exit(2); } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -320,6 +342,7 @@ static void get_gray8_image(image_translate_state_t *s, int compare) printf("Image finished early - %d %d\n", len, s->output_width); exit(2); } + /*endif*/ if (compare) { for (j = 0; j < 50; j++) @@ -329,14 +352,19 @@ static void get_gray8_image(image_translate_state_t *s, int compare) printf("Image mismatch - %dx%d - %d %d\n", j, i, ((i + j)*655) >> 8, row_buf[j]); //exit(2); } + /*endif*/ } + /*endfor*/ } + /*endif*/ } + /*endfor*/ if ((len = image_translate_row(s, row_buf, s->output_width)) != 0) { printf("Image finished late - %d %d\n", len, s->output_width); exit(2); } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -354,6 +382,7 @@ static void get_gray16_image(image_translate_state_t *s, int compare) printf("Image finished early - %d %d\n", len, 2*s->output_width); exit(2); } + /*endif*/ if (compare) { for (j = 0; j < s->output_width; j++) @@ -363,14 +392,19 @@ static void get_gray16_image(image_translate_state_t *s, int compare) printf("Image mismatch - %dx%d - %d %d\n", j, i, (i + j)*655, row_buf[j]); //exit(2); } + /*endif*/ } + /*endfor*/ } + /*endif*/ } + /*endfor*/ if ((len = image_translate_row(s, (uint8_t *) row_buf, 2*s->output_width)) != 0) { printf("Image finished late - %d %d\n", len, 2*s->output_width); exit(2); } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -393,6 +427,7 @@ static void get_colour8_image(image_translate_state_t *s, int compare) printf("Image finished early - %d %d\n", len, samples_per_pixel*s->output_width); exit(2); } + /*endif*/ if (compare) { for (j = 0; j < s->output_width; j++) @@ -418,14 +453,19 @@ static void get_colour8_image(image_translate_state_t *s, int compare) row_buf[samples_per_pixel*j + 0], row_buf[samples_per_pixel*j + 1], row_buf[samples_per_pixel*j + 2]); //exit(2); } + /*endif*/ } + /*endfor*/ } + /*endif*/ } + /*endfor*/ if ((len = image_translate_row(s, row_buf, samples_per_pixel*s->output_width)) != 0) { printf("Image finished late - %d %d\n", len, samples_per_pixel*s->output_width); exit(2); } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -448,6 +488,7 @@ static void get_colour16_image(image_translate_state_t *s, int compare) printf("Image finished early - %d %d\n", len, 2*samples_per_pixel*s->output_width); exit(2); } + /*endif*/ if (compare) { for (j = 0; j < s->output_width; j++) @@ -473,14 +514,19 @@ static void get_colour16_image(image_translate_state_t *s, int compare) row_buf[samples_per_pixel*j + 0], row_buf[samples_per_pixel*j + 1], row_buf[samples_per_pixel*j + 2]); //exit(2); } + /*endif*/ } + /*endfor*/ } + /*endif*/ } + /*endfor*/ if ((len = image_translate_row(s, (uint8_t *) row_buf, 2*samples_per_pixel*s->output_width)) != 0) { printf("Image finished late - %d %d\n", len, 2*samples_per_pixel*s->output_width); exit(2); } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -675,16 +721,20 @@ static void lenna_tests(int output_width, int output_length_scaling, const char printf("Dithering Lenna from colour to bi-level test\n"); else printf("Processing Lenna test\n"); + /*endif*/ if ((in_file = TIFFOpen(INPUT_TIFF_FILE_NAME, "r")) == NULL) return; + /*endif*/ image_width = 0; TIFFGetField(in_file, TIFFTAG_IMAGEWIDTH, &image_width); if (image_width <= 0) return; + /*endif*/ image_length = 0; TIFFGetField(in_file, TIFFTAG_IMAGELENGTH, &image_length); if (image_length <= 0) return; + /*endif*/ x_resolution = 200.0; TIFFGetField(in_file, TIFFTAG_XRESOLUTION, &x_resolution); y_resolution = 200.0; @@ -698,18 +748,22 @@ static void lenna_tests(int output_width, int output_length_scaling, const char printf("Original image is %d x %d, %.2f x %.2f resolution, %d bits per sample, %d samples per pixel\n", image_width, image_length, x_resolution, y_resolution, bits_per_sample, samples_per_pixel); if ((image = malloc(image_width*image_length*samples_per_pixel)) == NULL) return; + /*endif*/ for (total = 0, i = 0; i < 1000; i++) { len = TIFFReadEncodedStrip(in_file, i, &image[total], image_width*image_length*samples_per_pixel - total); if (len <= 0) break; + /*endif*/ total += len; if (total == image_width*image_length*samples_per_pixel) { printf("Done\n"); break; } + /*endif*/ } + /*endfor*/ printf("Input image size %d %d\n", total, image_width*image_length*samples_per_pixel); TIFFClose(in_file); @@ -717,6 +771,7 @@ static void lenna_tests(int output_width, int output_length_scaling, const char output_length = (double) image_length*output_length_scaling*output_width/image_width; else output_length = -1; + /*endif*/ im.image = image; im.width = image_width; @@ -746,9 +801,11 @@ static void lenna_tests(int output_width, int output_length_scaling, const char output_length = image_translate_get_output_length(s); break; } + /*endswitch*/ if ((out_file = TIFFOpen(file, "w")) == NULL) return; + /*endif*/ TIFFSetField(out_file, TIFFTAG_IMAGEWIDTH, output_width); TIFFSetField(out_file, TIFFTAG_IMAGELENGTH, output_length); TIFFSetField(out_file, TIFFTAG_RESOLUTIONUNIT, res_unit); @@ -767,8 +824,10 @@ static void lenna_tests(int output_width, int output_length_scaling, const char TIFFSetField(out_file, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); break; } + /*endswitch*/ if (output_length_scaling > 0) y_resolution *= output_length_scaling; + /*endif*/ TIFFSetField(out_file, TIFFTAG_XRESOLUTION, x_resolution); TIFFSetField(out_file, TIFFTAG_YRESOLUTION, y_resolution); TIFFSetField(out_file, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); @@ -783,31 +842,38 @@ static void lenna_tests(int output_width, int output_length_scaling, const char case -2: if ((image2 = malloc(output_width*output_length*3)) == NULL) return; + /*endif*/ memset(image2, 0, output_width*output_length*3); n = 0; for (i = 0; i < output_length; i++) n += image_translate_row(s2, &image2[n], output_width*3); + /*endfor*/ TIFFWriteEncodedStrip(out_file, 0, image2, n); break; case -1: if ((image2 = malloc(output_width*output_length*3)) == NULL) return; + /*endif*/ memset(image2, 0, output_width*output_length*3); n = 0; for (i = 0; i < output_length; i++) n += image_translate_row(s, &image2[n], output_width*3); + /*endfor*/ TIFFWriteEncodedStrip(out_file, 0, image2, n); break; default: if ((image2 = malloc(output_width*output_length/8)) == NULL) return; + /*endif*/ memset(image2, 0, output_width*output_length/8); n = 0; for (i = 0; i < output_length; i++) n += image_translate_row(s, &image2[n], output_width/8); + /*endfor*/ TIFFWriteEncodedStrip(out_file, 0, image2, n); break; } + /*endswitch*/ TIFFWriteDirectory(out_file); TIFFClose(out_file); image_translate_free(s); diff --git a/tests/line_model_monitor.cpp b/tests/line_model_monitor.cpp index 0d305935..7b849201 100644 --- a/tests/line_model_monitor.cpp +++ b/tests/line_model_monitor.cpp @@ -106,6 +106,7 @@ int line_model_monitor_can_update(const float *coeffs, int len) if (s->can_re) delete s->can_re; + /*endif*/ s->canvas_can->current(s->canvas_can); i = 0; @@ -117,9 +118,12 @@ int line_model_monitor_can_update(const float *coeffs, int len) s->can_re_plot[2*i + 1] = coeffs[i]; if (min > coeffs[i]) min = coeffs[i]; + /*endif*/ if (max < coeffs[i]) max = coeffs[i]; + /*endif*/ } + /*endfor*/ s->can_y->maximum((max == min) ? max + 0.2 : max); s->can_y->minimum(min); s->can_re = new Ca_Line(len, s->can_re_plot, 0, 0, FL_BLUE, CA_NO_POINT); @@ -128,6 +132,7 @@ int line_model_monitor_can_update(const float *coeffs, int len) skip = 0; Fl::check(); } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -140,6 +145,7 @@ int line_model_monitor_line_model_update(const float *coeffs, int len) if (s->line_model_re) delete s->line_model_re; + /*endif*/ s->canvas_line_model->current(s->canvas_line_model); i = 0; @@ -151,9 +157,12 @@ int line_model_monitor_line_model_update(const float *coeffs, int len) s->line_model_re_plot[2*i + 1] = coeffs[i]; if (min > coeffs[i]) min = coeffs[i]; + /*endif*/ if (max < coeffs[i]) max = coeffs[i]; + /*endif*/ } + /*endfor*/ s->line_model_y->maximum((max == min) ? max + 0.2 : max); s->line_model_y->minimum(min); s->line_model_re = new Ca_Line(len, s->line_model_re_plot, 0, 0, FL_BLUE, CA_NO_POINT); @@ -162,6 +171,7 @@ int line_model_monitor_line_model_update(const float *coeffs, int len) skip = 0; Fl::check(); } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -173,47 +183,61 @@ int line_model_monitor_line_spectrum_update(const int16_t amp[], int len) for (i = 0; i < len; i++) s->audio_meter->sample(amp[i]/32768.0); + /*endfor*/ if (s->in_ptr + len < 512) { /* Just add this fragment to the buffer. */ for (i = 0; i < len; i++) + { #if defined(HAVE_FFTW3_H) s->in[s->in_ptr + i][0] = amp[i]; #else s->in[s->in_ptr + i].re = amp[i]; #endif + } + /*endif*/ s->in_ptr += len; return 0; } + /*endif*/ if (len >= 512) { /* We have enough for a whole block. Use the last 512 samples we have. */ x = len - 512; for (i = 0; i < 512; i++) + { #if defined(HAVE_FFTW3_H) s->in[i][0] = amp[x + i]; #else s->in[i].re = amp[x + i]; #endif + } + /*endfor*/ } else { /* We want the last 512 samples. */ x = 512 - len; for (i = 0; i < x; i++) + { #if defined(HAVE_FFTW3_H) s->in[i][0] = s->in[s->in_ptr - x + i][0]; #else s->in[i].re = s->in[s->in_ptr - x + i].re; #endif + } + /*endfor*/ for (i = x; i < 512; i++) + { #if defined(HAVE_FFTW3_H) s->in[i][0] = amp[i - x]; #else s->in[i].re = amp[i - x]; #endif + } + /*endfor*/ } s->in_ptr = 0; #if defined(HAVE_FFTW3_H) @@ -223,6 +247,7 @@ int line_model_monitor_line_spectrum_update(const int16_t amp[], int len) #endif if (s->spec_re) delete s->spec_re; + /*endif*/ s->canvas_spec->current(s->canvas_spec); for (i = 0; i < 512; i++) { @@ -233,6 +258,7 @@ int line_model_monitor_line_spectrum_update(const int16_t amp[], int len) s->spec_re_plot[2*i + 1] = 10.0*log10((s->out[i].re*s->out[i].re + s->out[i].im*s->out[i].im)/(256.0*32768*256.0*32768) + 1.0e-10) + 3.14; #endif } + /*endfor*/ s->spec_re = new Ca_Line(512, s->spec_re_plot, 0, 0, FL_BLUE, CA_NO_POINT); Fl::check(); return 0; @@ -402,6 +428,7 @@ int start_line_model_monitor(int len) s->in[i][0] = 0.0; s->in[i][1] = 0.0; } + /*endfor*/ #else s->p = fftw_create_plan(1024, FFTW_BACKWARD, FFTW_ESTIMATE); for (i = 0; i < 1024; i++) @@ -409,6 +436,7 @@ int start_line_model_monitor(int len) s->in[i].re = 0.0; s->in[i].im = 0.0; } + /*endfor*/ #endif s->in_ptr = 0; diff --git a/tests/line_model_tests.c b/tests/line_model_tests.c index b44f9771..155be208 100644 --- a/tests/line_model_tests.c +++ b/tests/line_model_tests.c @@ -79,6 +79,7 @@ static void complexify_tests(void) fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_COMPLEXIFY); exit(2); } + /*endif*/ awgn_init_dbm0(&noise1, 1234567, -10.0f); s = complexify_init(); for (i = 0; i < 20000; i++) @@ -88,6 +89,7 @@ static void complexify_tests(void) out[2*i] = cc.re; out[2*i + 1] = cc.im; } + /*endfor*/ awgn_release(&noise1); complexify_free(s); outframes = sf_writef_short(outhandle, out, 20000); @@ -96,11 +98,13 @@ static void complexify_tests(void) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ if (sf_close_telephony(outhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_COMPLEXIFY); exit(2); } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -123,6 +127,7 @@ static void test_one_way_model(int line_model_no, int speech_test) fprintf(stderr, " Failed to create line model\n"); exit(2); } + /*endif*/ awgn_init_dbm0(&noise1, 1234567, -10.0f); @@ -133,16 +138,19 @@ static void test_one_way_model(int line_model_no, int speech_test) fprintf(stderr, " Cannot open audio file '%s'\n", IN_FILE_NAME1); exit(2); } + /*endif*/ } else { inhandle1 = NULL; } + /*endif*/ if ((outhandle = sf_open_telephony_write(OUT_FILE_NAME1, 1)) == NULL) { fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME1); exit(2); } + /*endif*/ for (i = 0; i < 10000; i++) { if (speech_test) @@ -155,8 +163,10 @@ static void test_one_way_model(int line_model_no, int speech_test) { for (j = 0; j < BLOCK_LEN; j++) input1[j] = awgn(&noise1); + /*endfor*/ samples = BLOCK_LEN; } + /*endif*/ for (j = 0; j < samples; j++) { one_way_line_model(model, @@ -165,13 +175,16 @@ static void test_one_way_model(int line_model_no, int speech_test) 1); amp[j] = output1[j]; } + /*endfor*/ outframes = sf_writef_short(outhandle, amp, samples); if (outframes != samples) { fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } + /*endfor*/ if (speech_test) { if (sf_close_telephony(inhandle1)) @@ -179,6 +192,7 @@ static void test_one_way_model(int line_model_no, int speech_test) fprintf(stderr, " Cannot close audio file '%s'\n", IN_FILE_NAME1); exit(2); } + /*endif*/ } if (sf_close_telephony(outhandle)) { @@ -221,6 +235,7 @@ static void test_both_ways_model(int line_model_no, int speech_test) fprintf(stderr, " Failed to create line model\n"); exit(2); } + /*endif*/ awgn_init_dbm0(&noise1, 1234567, -10.0f); awgn_init_dbm0(&noise2, 1234567, -10.0f); @@ -232,22 +247,26 @@ static void test_both_ways_model(int line_model_no, int speech_test) fprintf(stderr, " Cannot open audio file '%s'\n", IN_FILE_NAME1); exit(2); } + /*endif*/ if ((inhandle2 = sf_open_telephony_read(IN_FILE_NAME2, 1)) == NULL) { fprintf(stderr, " Cannot open audio file '%s'\n", IN_FILE_NAME2); exit(2); } + /*endif*/ } else { inhandle1 = inhandle2 = NULL; } + /*endif*/ if ((outhandle = sf_open_telephony_write(OUT_FILE_NAME2, 2)) == NULL) { fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME2); exit(2); } + /*endif*/ for (i = 0; i < 10000; i++) { if (speech_test) @@ -255,9 +274,11 @@ static void test_both_ways_model(int line_model_no, int speech_test) samples = sf_readf_short(inhandle1, input1, BLOCK_LEN); if (samples == 0) break; + /*endif*/ samples = sf_readf_short(inhandle2, input2, samples); if (samples == 0) break; + /*endif*/ } else { @@ -266,8 +287,10 @@ static void test_both_ways_model(int line_model_no, int speech_test) input1[j] = awgn(&noise1); input2[j] = awgn(&noise2); } + /*endfor*/ samples = BLOCK_LEN; } + /*endif*/ for (j = 0; j < samples; j++) { both_ways_line_model(model, @@ -279,13 +302,16 @@ static void test_both_ways_model(int line_model_no, int speech_test) amp[2*j] = output1[j]; amp[2*j + 1] = output2[j]; } + /*endfor*/ outframes = sf_writef_short(outhandle, amp, samples); if (outframes != samples) { fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } + /*endfor*/ if (speech_test) { if (sf_close_telephony(inhandle1)) @@ -293,17 +319,21 @@ static void test_both_ways_model(int line_model_no, int speech_test) fprintf(stderr, " Cannot close audio file '%s'\n", IN_FILE_NAME1); exit(2); } + /*endif*/ if (sf_close_telephony(inhandle2)) { fprintf(stderr, " Cannot close audio file '%s'\n", IN_FILE_NAME2); exit(2); } + /*endif*/ } + /*endif*/ if (sf_close_telephony(outhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME2); exit(2); } + /*endif*/ both_ways_line_model_free(model); } /*- End of function --------------------------------------------------------*/ @@ -326,11 +356,13 @@ static void test_line_filter(int line_model_no) s = swept_tone_init(NULL, 200.0f, 3900.0f, -10.0f, 120*SAMPLE_RATE, 0); for (j = 0; j < 129; j++) filter[j] = 0.0f; + /*endfor*/ ptr = 0; for (;;) { if ((len = swept_tone(s, buf, BLOCK_LEN)) <= 0) break; + /*endif*/ sumin = 0.0; sumout = 0.0; for (i = 0; i < len; i++) @@ -340,6 +372,7 @@ static void test_line_filter(int line_model_no) filter[p] = buf[i]; if (++p == 129) p = 0; + /*endif*/ ptr = p; /* Apply the filter */ @@ -349,7 +382,9 @@ static void test_line_filter(int line_model_no) out += line_models[line_model_no][128 - j]*filter[p]; if (++p >= 129) p = 0; + /*endif*/ } + /*endfor*/ sumin += buf[i]*buf[i]; sumout += out*out; } @@ -392,7 +427,9 @@ int main(int argc, char *argv[]) //usage(); exit(2); } + /*endswitch*/ } + /*endwhile*/ complexify_tests(); test_one_way_model(line_model_no, speech_test); test_both_ways_model(line_model_no, speech_test); diff --git a/tests/logging_tests.c b/tests/logging_tests.c index 2ba4bac9..9587dc1a 100644 --- a/tests/logging_tests.c +++ b/tests/logging_tests.c @@ -75,13 +75,16 @@ static void message_handler(void *user_data, int level, const char *text) if (ref[msg_step][0] == '\0') return; + /*endif*/ if (strcmp(ref[msg_step], text)) { printf(">>>: %s", ref[msg_step]); tests_failed = true; } + /*endif*/ if (ref[++msg_step][0] == '\0') msg_done = true; + /*endif*/ printf("MSG: %s", text); } /*- End of function --------------------------------------------------------*/ @@ -94,8 +97,10 @@ static void message_handler2(void *user_data, int level, const char *text) printf(">>>: %s", text + 23); tests_failed = true; } + /*endif*/ if (++msg2_step == 10) msg2_done = true; + /*endif*/ printf("MSG: %s", text); } /*- End of function --------------------------------------------------------*/ @@ -113,12 +118,14 @@ int main(int argc, char *argv[]) fprintf(stderr, "Failed to initialise log.\n"); exit(2); } + /*endif*/ /* Try it */ span_log_set_level(log, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW); if (span_log(log, SPAN_LOG_FLOW, "Logging to fprintf, as simple as %d %d %d\n", 1, 2, 3)) fprintf(stderr, "Logged.\n"); else fprintf(stderr, "Not logged.\n"); + /*endif*/ /* Now set a custom log handler */ span_log_set_message_handler(log, &message_handler, NULL); @@ -130,16 +137,21 @@ int main(int argc, char *argv[]) fprintf(stderr, "Logged.\n"); else fprintf(stderr, "Not logged.\n"); + /*endif*/ + span_log_set_level(log, SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW); if (span_log(log, SPAN_LOG_FLOW, "Log with protocol %d %d %d\n", 1, 2, 3)) fprintf(stderr, "Logged.\n"); else fprintf(stderr, "Not logged.\n"); + /*endif*/ + span_log_set_level(log, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_FLOW); if (span_log(log, SPAN_LOG_ERROR, "Log with severity log %d %d %d\n", 1, 2, 3)) fprintf(stderr, "Logged.\n"); else fprintf(stderr, "Not logged.\n"); + /*endif*/ span_log_set_level(log, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW); span_log_set_tag(log, "NewTag"); @@ -147,24 +159,29 @@ int main(int argc, char *argv[]) fprintf(stderr, "Logged.\n"); else fprintf(stderr, "Not logged.\n"); + /*endif*/ span_log_set_protocol(log, "Protocol"); if (span_log(log, SPAN_LOG_FLOW, "Log with protocol %d %d %d\n", 1, 2, 3)) fprintf(stderr, "Logged.\n"); else fprintf(stderr, "Not logged.\n"); + /*endif*/ /* Test logging of buffer contents */ for (i = 0; i < 1000; i++) buf[i] = i; + /*endfor*/ if (span_log_buf(log, SPAN_LOG_FLOW, "Buf", buf, 10)) fprintf(stderr, "Logged.\n"); else fprintf(stderr, "Not logged.\n"); + /*endif*/ if (span_log_buf(log, SPAN_LOG_FLOW, "Buf", buf, 1000)) fprintf(stderr, "Logged.\n"); else fprintf(stderr, "Not logged.\n"); + /*endif*/ /* Test the correct severities will be logged */ for (i = 0; i < 10; i++) @@ -173,9 +190,12 @@ int main(int argc, char *argv[]) { if (i != 6) tests_failed = true; + /*endif*/ break; } + /*endif*/ } + /*endfor*/ /* Check timestamping by samples */ span_log_set_level(log, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_FLOW | SPAN_LOG_SHOW_SAMPLE_TIME); @@ -184,6 +204,7 @@ int main(int argc, char *argv[]) span_log(log, SPAN_LOG_FLOW, "Time tagged log %d %d %d\n", 1, 2, 3); span_log_bump_samples(log, 441*2); } + /*endfor*/ /* Check timestamping by current date and time */ span_log_set_message_handler(log, &message_handler2, NULL); @@ -195,11 +216,13 @@ int main(int argc, char *argv[]) delay.tv_nsec = 20000000; nanosleep(&delay, NULL); } + /*endfor*/ if (tests_failed || !msg_done) { printf("Tests failed - %d %d.\n", tests_failed, msg_done); return 2; } + /*endif*/ span_log_set_message_handler(log, &message_handler, NULL); diff --git a/tests/media_monitor.cpp b/tests/media_monitor.cpp index be983e64..a2089d8b 100644 --- a/tests/media_monitor.cpp +++ b/tests/media_monitor.cpp @@ -88,6 +88,7 @@ void media_monitor_rx(int seq_no, double departure_time, double arrival_time) if (s->received_delays) delete s->received_delays; + /*endif*/ s->canvas_received->current(s->canvas_received); fdiff = (arrival_time - departure_time)*1000.0; @@ -96,27 +97,32 @@ void media_monitor_rx(int seq_no, double departure_time, double arrival_time) diff = 0; else if (diff > 1999) diff = 1999; + /*endif*/ s->received_delays_plot[2*diff + 1]++; if (s->received_delays_plot[2*diff + 1] > s->received_delays_plot_max) { s->received_delays_plot_max = s->received_delays_plot[2*diff + 1]; s->received_y->maximum(s->received_delays_plot_max); } + /*endif*/ if (diff > s->max_diff) { s->max_diff = diff; s->received_x->maximum((double) s->max_diff); } + /*endif*/ if (diff < s->min_diff) { s->min_diff = diff - 1; s->received_x->minimum((double) s->min_diff); } + /*endif*/ s->received_delays = new Ca_Line(2000, s->received_delays_plot, 0, 0, FL_BLUE, CA_NO_POINT); if (s->sent_re) delete s->sent_re; + /*endif*/ s->canvas_sent->current(s->canvas_sent); @@ -124,7 +130,9 @@ void media_monitor_rx(int seq_no, double departure_time, double arrival_time) { for (i = s->highest_seq_no_seen + 1; i < seq_no; i++) s->sent_re_plot[2*(i%500) + 1] = 0.0; + /*endfor*/ } + /*endif*/ s->sent_re_plot[2*(seq_no%500) + 1] = fdiff; if (fdiff > s->sent_re_plot_max) @@ -132,21 +140,25 @@ void media_monitor_rx(int seq_no, double departure_time, double arrival_time) s->sent_re_plot_max = fdiff; s->sent_y->maximum(s->sent_re_plot_max); } + /*endif*/ if (fdiff < s->sent_re_plot_min) { s->sent_re_plot_min = fdiff - 1.0; s->sent_y->minimum(s->sent_re_plot_min); } + /*endif*/ s->sent_re = new Ca_Line(500, s->sent_re_plot, 0, 0, FL_BLUE, CA_NO_POINT); if (seq_no > s->highest_seq_no_seen) s->highest_seq_no_seen = seq_no; + /*endif*/ if (++skip >= 100) { skip = 0; Fl::check(); } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -252,6 +264,7 @@ int start_media_monitor(void) for (i = 0; i < 2000; i++) s->received_delays_plot[2*i] = i; + /*endfor*/ s->received_delays_plot_max = 0.0; s->min_diff = 2000; s->max_diff = 0; @@ -261,6 +274,7 @@ int start_media_monitor(void) for (i = 0; i < 500; i++) s->sent_re_plot[2*i] = i; + /*endfor*/ s->sent_re_plot_min = 99999.0; s->sent_re_plot_max = 0.0; s->sent_re = NULL; diff --git a/tests/noise_tests.c b/tests/noise_tests.c index 0c7ee99b..f6ae3864 100644 --- a/tests/noise_tests.c +++ b/tests/noise_tests.c @@ -73,6 +73,7 @@ int main (int argc, char *argv[]) fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ for (quality = 7; quality <= 20; quality += (20 - 7)) { @@ -97,8 +98,10 @@ int main (int argc, char *argv[]) clip_high++; else if (value == -32768) clip_low++; + /*endif*/ total += ((double) value)*((double) value); } + /*endfor*/ printf ("RMS = %.3f (expected %d) %.2f%% error [clipped samples %d+%d]\n", 10.0*log10((total/total_samples)/(32768.0*32768.0) + 1.0e-10), level, @@ -110,8 +113,11 @@ int main (int argc, char *argv[]) printf("Test failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ } + /*endfor*/ /* Now look at the statistical spread of the results, by collecting data in bins from a large number of samples. Use a fairly high noise level, but @@ -132,8 +138,10 @@ int main (int argc, char *argv[]) clip_high++; else if (value == -32768) clip_low++; + /*endif*/ bins[value + 32768]++; } + /*endfor*/ /* Find the RMS power level to expect */ o = pow(10.0, level/20.0)*(32768.0*0.70711); for (i = 0; i < 65536 - 10; i++) @@ -146,25 +154,31 @@ int main (int argc, char *argv[]) x = 0; for (j = 0; j < 10; j++) x += bins[i + j]; + /*endfor*/ x /= 10.0; x /= total_samples; /* Now send it out for graphing. */ if (p > 0.0000001) printf("%6d %.7f %.7f\n", i - 32768, x, p); + /*endif*/ } + /*endfor*/ printf("Generating AWGN at -15dBOv to file\n"); for (j = 0; j < 50; j++) { for (i = 0; i < 1024; i++) amp[i] = noise(&noise_source); + /*endfor*/ outframes = sf_writef_short(outhandle, amp, 1024); if (outframes != 1024) { fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } + /*endfor*/ /* Generate Hoth noise at several RMS levels between -50dBm and 0dBm. Noise is generated for a large number of samples (1,000,000), and the RMS value @@ -188,8 +202,10 @@ int main (int argc, char *argv[]) clip_high++; else if (value == -32768) clip_low++; + /*endif*/ total += ((double) value)*((double) value); } + /*endfor*/ printf ("RMS = %.3f (expected %d) %.2f%% error [clipped samples %d+%d]\n", 10.0*log10((total/total_samples)/(32768.0*32768.0) + 1.0e-10), level, @@ -201,7 +217,9 @@ int main (int argc, char *argv[]) printf("Test failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ quality = 7; printf("Generating Hoth noise at -15dBOv to file\n"); @@ -211,19 +229,23 @@ int main (int argc, char *argv[]) { for (i = 0; i < 1024; i++) amp[i] = noise(&noise_source); + /*endfor*/ outframes = sf_writef_short(outhandle, amp, 1024); if (outframes != 1024) { fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } + /*endfor*/ if (sf_close_telephony(outhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ printf("Tests passed.\n"); return 0; diff --git a/tests/oki_adpcm_tests.c b/tests/oki_adpcm_tests.c index a9eef7e1..ce4ceebd 100644 --- a/tests/oki_adpcm_tests.c +++ b/tests/oki_adpcm_tests.c @@ -116,7 +116,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ encoded_fd = -1; inhandle = NULL; @@ -128,6 +130,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open encoded file '%s'\n", encoded_file_name); exit(2); } + /*endif*/ } else { @@ -136,34 +139,41 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", in_file_name); exit(2); } + /*endif*/ if ((oki_enc_state = oki_adpcm_init(NULL, bit_rate)) == NULL) { fprintf(stderr, " Cannot create encoder\n"); exit(2); } + /*endif*/ } + /*endif*/ if ((outhandle = sf_open_telephony_write(OUT_FILE_NAME, 1)) == NULL) { fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ if ((oki_dec_state = oki_adpcm_init(NULL, bit_rate)) == NULL) { fprintf(stderr, " Cannot create decoder\n"); exit(2); } + /*endif*/ if ((oki_dec_state2 = oki_adpcm_init(NULL, bit_rate)) == NULL) { fprintf(stderr, " Cannot create decoder\n"); exit(2); } + /*endif*/ hist_in = 0; if (bit_rate == 32000) hist_out = 0; else hist_out = HIST_LEN - 27; + /*endif*/ memset(history, 0, sizeof(history)); pre_energy = 0.0; post_energy = 0.0; @@ -185,10 +195,13 @@ int main(int argc, char *argv[]) xx = post_amp[i] - history[hist_out++]; if (hist_out >= HIST_LEN) hist_out = 0; + /*endif*/ diff_energy += (double) xx * (double) xx; } + /*endfor*/ sf_writef_short(outhandle, post_amp, dec_frames); } + /*endwhile*/ close(encoded_fd); } else @@ -204,6 +217,7 @@ int main(int argc, char *argv[]) oki_bytes = oki_adpcm_encode(oki_enc_state, oki_data, pre_amp, frames); if (log_encoded_data) write(1, oki_data, oki_bytes); + /*endif*/ total_compressed_bytes += oki_bytes; /* Look for a condition which is defined as something which should cause a reset of the decoder (48 samples of 0, 8, 0, 8, etc.), and verify that it really does. Use @@ -215,10 +229,12 @@ int main(int argc, char *argv[]) successive_08_bytes++; else successive_08_bytes = 0; + /*endif*/ if (oki_data[i] == 0x80) successive_80_bytes++; else successive_80_bytes = 0; + /*endif*/ if (successive_08_bytes == 24 || successive_80_bytes == 24) { if (oki_dec_state2->step_index != 0) @@ -226,8 +242,11 @@ int main(int argc, char *argv[]) fprintf(stderr, "Decoder reset failure\n"); exit(2); } + /*endif*/ } + /*endif*/ } + /*endfor*/ dec_frames = oki_adpcm_decode(oki_dec_state, post_amp, oki_data, oki_bytes); total_post_samples += dec_frames; for (i = 0; i < frames; i++) @@ -235,19 +254,24 @@ int main(int argc, char *argv[]) history[hist_in++] = pre_amp[i]; if (hist_in >= HIST_LEN) hist_in = 0; + /*endif*/ pre_energy += (double) pre_amp[i] * (double) pre_amp[i]; } + /*endfor*/ for (i = 0; i < dec_frames; i++) { post_energy += (double) post_amp[i] * (double) post_amp[i]; xx = post_amp[i] - history[hist_out++]; if (hist_out >= HIST_LEN) hist_out = 0; + /*endif*/ diff_energy += (double) xx * (double) xx; //post_amp[i] = xx; } + /*endfor*/ sf_writef_short(outhandle, post_amp, dec_frames); } + /*endwhile*/ printf("Pre samples: %d\n", total_pre_samples); printf("Compressed bytes: %d\n", total_compressed_bytes); printf("Post samples: %d\n", total_post_samples); @@ -263,6 +287,7 @@ int main(int argc, char *argv[]) printf("Tests failed.\n"); exit(2); } + /*endif*/ } else { @@ -273,7 +298,9 @@ int main(int argc, char *argv[]) printf("Tests failed.\n"); exit(2); } + /*endif*/ } + /*endif*/ oki_adpcm_free(oki_enc_state); if (sf_close_telephony(inhandle)) @@ -281,7 +308,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", in_file_name); exit(2); } + /*endif*/ } + /*endif*/ oki_adpcm_free(oki_dec_state); oki_adpcm_free(oki_dec_state2); if (sf_close_telephony(outhandle)) @@ -289,6 +318,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ printf("Tests passed.\n"); return 0; diff --git a/tests/playout_tests.c b/tests/playout_tests.c index a5180eaf..868f11b4 100644 --- a/tests/playout_tests.c +++ b/tests/playout_tests.c @@ -77,11 +77,13 @@ static void dynamic_buffer_tests(void) fprintf(stderr, " Failed to open audio file '%s'\n", INPUT_FILE_NAME); exit(2); } + /*endif*/ if ((outhandle = sf_open_telephony_write(OUTPUT_FILE_NAME, 1)) == NULL) { fprintf(stderr, " Failed to create audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ near_far_time_offset = 54321; time_stamp = 12345; @@ -89,9 +91,11 @@ static void dynamic_buffer_tests(void) next_scheduled_receive = 0; for (i = 0; i < BLOCK_LEN; i++) fill[i] = 32767; + /*endfor*/ if ((s = playout_init(2*BLOCK_LEN, 15*BLOCK_LEN)) == NULL) return; + /*endif*/ plc_init(&plc); time_scale_init(&ts, SAMPLE_RATE, 1.0); for (i = 0; i < 1000000; i++) @@ -102,6 +106,7 @@ static void dynamic_buffer_tests(void) inframes = sf_readf_short(inhandle, amp, BLOCK_LEN); if (inframes < BLOCK_LEN) break; + /*endif*/ ret = playout_put(s, amp, PLAYOUT_TYPE_SPEECH, @@ -121,6 +126,7 @@ static void dynamic_buffer_tests(void) printf("<< Eh?\n"); break; } + /*endswitch*/ #endif rng = rand() & 0xFF; if (i < 100000) @@ -131,9 +137,11 @@ static void dynamic_buffer_tests(void) rng = (rng*rng) >> 5; else if (i < 400000) rng = (rng*rng) >> 7; + /*endif*/ time_stamp += BLOCK_LEN; next_actual_receive = time_stamp + near_far_time_offset + rng; } + /*endif*/ if (i >= next_scheduled_receive) { do @@ -141,6 +149,7 @@ static void dynamic_buffer_tests(void) ret = playout_get(s, &frame, next_scheduled_receive); if (ret == PLAYOUT_DROP) printf(">> Drop %d\n", next_scheduled_receive); + /*endif*/ } while (ret == PLAYOUT_DROP); switch (ret) @@ -155,12 +164,14 @@ printf("len = %d\n", len); buf[2*j] = out[j]; buf[2*j + 1] = 10*playout_current_length(s); } + /*endfor*/ outframes = sf_writef_short(outhandle, buf, len); if (outframes != len) { fprintf(stderr, " Error writing out sound\n"); exit(2); } + /*endif*/ free(frame.data); next_scheduled_receive += BLOCK_LEN; break; @@ -176,12 +187,14 @@ printf("len = %d\n", len); buf[2*j] = out[j]; buf[2*j + 1] = 10*playout_current_length(s); } + /*endfor*/ outframes = sf_writef_short(outhandle, buf, len); if (outframes != len) { fprintf(stderr, " Error writing out sound\n"); exit(2); } + /*endif*/ next_scheduled_receive += BLOCK_LEN; break; case PLAYOUT_DROP: @@ -203,6 +216,7 @@ printf("len = %d\n", len); printf(">> Eh? %d\n", next_scheduled_receive); break; } + /*endswitch*/ } } if (sf_close_telephony(inhandle)) @@ -210,17 +224,20 @@ printf("len = %d\n", len); fprintf(stderr, " Cannot close audio file '%s'\n", INPUT_FILE_NAME); exit(2); } + /*endif*/ if (sf_close_telephony(outhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ printf("%10" PRId32 " %10" PRId32 " %10d\n", s->state_just_in_time, s->state_late, playout_current_length(s)); /* Clear everything from the queue */ while ((p = playout_get_unconditional(s))) /*free(p->data)*/; + /*endif*/ /* Now free the context itself */ playout_free(s); } @@ -252,6 +269,7 @@ static void static_buffer_tests(void) if ((s = playout_init(2*BLOCK_LEN, 2*BLOCK_LEN)) == NULL) return; + /*endif*/ for (i = 0; i < 1000000; i++) { if (i >= next_actual_receive) @@ -274,12 +292,14 @@ static void static_buffer_tests(void) printf("<< Eh?\n"); break; } + /*endswitch*/ next_scheduled_send += BLOCK_LEN; ret = rand() & 0xFF; ret = (ret*ret) >> 7; transit_time = 320 + ret; next_actual_receive = next_scheduled_send + transit_time; } + /*endif*/ if (i >= next_scheduled_receive) { do @@ -316,11 +336,15 @@ static void static_buffer_tests(void) printf(">> Eh?\n"); break; } + /*endswitch*/ } + /*endif*/ } + /*endfor*/ /* Clear everything from the queue */ while ((p = playout_get_unconditional(s))) /*free(p->data)*/; + /*endwhile*/ /* Now free the context itself */ playout_free(s); } diff --git a/tests/plc_tests.c b/tests/plc_tests.c index 78e645d3..613695b4 100644 --- a/tests/plc_tests.c +++ b/tests/plc_tests.c @@ -103,7 +103,9 @@ int main(int argc, char *argv[]) tone = atoi(optarg); break; } + /*endswitch*/ } + /*endwhile*/ phase_rate = 0; inhandle = NULL; if (tone < 0) @@ -113,16 +115,19 @@ int main(int argc, char *argv[]) fprintf(stderr, " Failed to open audio file '%s'\n", INPUT_FILE_NAME); exit(2); } + /*endif*/ } else { phase_rate = dds_phase_ratef((float) tone); } + /*endif*/ if ((outhandle = sf_open_telephony_write(OUTPUT_FILE_NAME, 1)) == NULL) { fprintf(stderr, " Failed to open audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ plc_init(&plc); lost_blocks = 0; for (block_no = 0; ; block_no++) @@ -132,21 +137,26 @@ int main(int argc, char *argv[]) inframes = sf_readf_short(inhandle, amp, block_len); if (inframes != block_len) break; + /*endif*/ } else { if (block_no > 10000) break; + /*endif*/ for (i = 0; i < block_len; i++) amp[i] = (int16_t) dds_modf(&phase_acc, phase_rate, 10000.0, 0); + /*endfor*/ inframes = block_len; } + /*endif*/ dropit = rand()/(RAND_MAX/100); if (dropit > loss_rate) { plc_rx(&plc, amp, inframes); if (block_real) memset(amp, 0, sizeof(int16_t)*inframes); + /*endif*/ } else { @@ -154,14 +164,18 @@ int main(int argc, char *argv[]) plc_fillin(&plc, amp, inframes); if (block_synthetic) memset(amp, 0, sizeof(int16_t)*inframes); + /*endif*/ } + /*endif*/ outframes = sf_writef_short(outhandle, amp, inframes); if (outframes != inframes) { fprintf(stderr, " Error writing out sound\n"); exit(2); } + /*endif*/ } + /*endfor*/ printf("Dropped %d of %d blocks\n", lost_blocks, block_no); if (tone < 0) { @@ -170,12 +184,15 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", INPUT_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ if (sf_close_telephony(outhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/power_meter_tests.c b/tests/power_meter_tests.c index 59287b7d..8d2f51ab 100644 --- a/tests/power_meter_tests.c +++ b/tests/power_meter_tests.c @@ -74,6 +74,7 @@ static int power_surge_detector_tests(void) fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ sig = power_surge_detector_init(NULL, -50.0f, 5.0f); prev_signal_present = false; @@ -95,6 +96,7 @@ static int power_surge_detector_tests(void) amp[i] = awgn(awgnx); if (i < 4000) amp[i] += dds_mod(&phase_acc, phase_rate, phase_scale, 0); + /*endif*/ signal_level = power_surge_detector(sig, amp[i]); signal_present = (signal_level != 0); @@ -105,27 +107,36 @@ static int power_surge_detector_tests(void) { if (ok == 0 && i >= 0 && i < 25) ok = 1; + /*endif*/ if (extremes[0] > i) extremes[0] = i; + /*endif*/ if (extremes[1] < i) extremes[1] = i; + /*endif*/ printf("On at %f (%fdBm0)\n", (sample + i)/8000.0, signal_power); } else { if (ok == 1 && i >= 4000 + 0 && i < 4000 + 35) ok = 2; + /*endif*/ if (extremes[2] > i) extremes[2] = i; + /*endif*/ if (extremes[3] < i) extremes[3] = i; + /*endif*/ printf("Off at %f (%fdBm0)\n", (sample + i)/8000.0, signal_power); } + /*endif*/ prev_signal_present = signal_present; } + /*endif*/ amp_out[2*i] = amp[i]; amp_out[2*i + 1] = signal_present*5000; } + /*endfor*/ sf_writef_short(outhandle, amp_out, 8000); if (ok != 2 || @@ -140,12 +151,15 @@ static int power_surge_detector_tests(void) printf(" Surge not detected correctly (%d)\n", ok); exit(2); } + /*endif*/ } + /*endfor*/ if (sf_close_telephony(outhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ printf("Min on %d, max on %d, min off %d, max off %d\n", extremes[0], extremes[1], extremes[2], extremes[3]); power_surge_detector_free(sig); awgn_free(awgnx); @@ -173,12 +187,14 @@ static int power_surge_detector_file_test(const char *file) fprintf(stderr, " Cannot open audio file '%s'\n", file); exit(2); } + /*endif*/ if ((outhandle = sf_open_telephony_write(OUT_FILE_NAME, 1)) == NULL) { fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ sig = power_surge_detector_init(NULL, -50.0f, 6.0f); prev_signal_present = false; @@ -196,24 +212,30 @@ static int power_surge_detector_file_test(const char *file) printf("On at %f (%fdBm0)\n", (sample + i)/8000.0, signal_power); else printf("Off at %f (%fdBm0)\n", (sample + i)/8000.0, signal_power); + /*endif*/ prev_signal_present = signal_present; } + /*endif*/ amp_out[2*i] = amp[i]; amp_out[2*i + 1] = signal_present*5000; } + /*endfor*/ sf_writef_short(outhandle, amp_out, inframes); sample += inframes; } + /*endwhile*/ if (sf_close_telephony(inhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", file); exit(2); } + /*endif*/ if (sf_close_telephony(outhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -242,6 +264,7 @@ static int power_meter_tests(void) level = power_meter_update(&meter, amp[i]); //printf("%12d %fdBm0 %fdBov\n", level, power_meter_current_dbm0(&meter), power_meter_current_dbov(&meter)); } + /*endfor*/ printf("Level: expected %" PRId32 "/%" PRId32 ", got %" PRId32 "\n", power_meter_level_dbov(-10.0f), power_meter_level_dbm0(-10.0f + DBM0_MAX_POWER), level); printf("Power: expected %fdBm0, got %fdBm0\n", -10.0f + DBM0_MAX_POWER, power_meter_current_dbm0(&meter)); printf("Power: expected %fdBOv, got %fdBOv\n", -10.0f, power_meter_current_dbov(&meter)); @@ -252,16 +275,19 @@ static int power_meter_tests(void) printf("Test failed (level)\n"); exit(2); } + /*endif*/ if (0.1f < fabsf(power_meter_current_dbm0(&meter) + 10.0f - DBM0_MAX_POWER)) { printf("Test failed (dBm0)\n"); exit(2); } + /*endif*/ if (0.1f < fabsf(power_meter_current_dbov(&meter) + 10.0)) { printf("Test failed (dBOv)\n"); exit(2); } + /*endif*/ printf("Testing with a sine wave tone 10dB from maximum\n"); tone_gen_descriptor_init(&tone_desc, @@ -281,6 +307,7 @@ static int power_meter_tests(void) level = power_meter_update(&meter, amp[i]); //printf("%12d %fdBm0 %fdBov\n", level, power_meter_current_dbm0(&meter), power_meter_current_dbov(&meter)); } + /*endfor*/ printf("Level: expected %" PRId32 "/%" PRId32 ", got %" PRId32 "\n", power_meter_level_dbov(-10.0f), power_meter_level_dbm0(-10.0f + DBM0_MAX_POWER), level); printf("Power: expected %fdBm0, got %fdBm0\n", -10.0f + DBM0_MAX_POWER, power_meter_current_dbm0(&meter)); printf("Power: expected %fdBOv, got %fdBOv\n", -10.0f, power_meter_current_dbov(&meter)); @@ -291,26 +318,31 @@ static int power_meter_tests(void) printf("Test failed (level)\n"); exit(2); } + /*endif*/ if (0.2f < fabsf(power_meter_current_dbm0(&meter) + 10.0f - DBM0_MAX_POWER)) { printf("Test failed (dBm0)\n"); exit(2); } + /*endif*/ if (0.2f < fabsf(power_meter_current_dbov(&meter) + 10.0)) { printf("Test failed (dBOv)\n"); exit(2); } + /*endif*/ printf("Testing with AWGN 10dB from maximum\n"); awgn_init_dbov(&noise_source, idum, -10.0f); for (i = 0; i < 1000; i++) amp[i] = awgn(&noise_source); + /*endfor*/ for (i = 0; i < 1000; i++) { level = power_meter_update(&meter, amp[i]); //printf("%12d %fdBm0 %fdBov\n", level, power_meter_current_dbm0(&meter), power_meter_current_dbov(&meter)); } + /*endfor*/ printf("Level: expected %" PRId32 "/%" PRId32 ", got %" PRId32 "\n", power_meter_level_dbov(-10.0f), power_meter_level_dbm0(-10.0f + DBM0_MAX_POWER), level); printf("Power: expected %fdBm0, got %fdBm0\n", -10.0f + DBM0_MAX_POWER, power_meter_current_dbm0(&meter)); printf("Power: expected %fdBOv, got %fdBOv\n", -10.0f, power_meter_current_dbov(&meter)); @@ -321,16 +353,19 @@ static int power_meter_tests(void) printf("Test failed (level)\n"); exit(2); } + /*endif*/ if (0.2f < fabsf(power_meter_current_dbm0(&meter) + 10.0f - DBM0_MAX_POWER)) { printf("Test failed (dBm0)\n"); exit(2); } + /*endif*/ if (0.2f < fabsf(power_meter_current_dbov(&meter) + 10.0f)) { printf("Test failed (dBOv)\n"); exit(2); } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -358,17 +393,21 @@ int main(int argc, char *argv[]) //usage(); exit(2); } + /*endswitch*/ } + /*endwhile*/ if (basic_tests) { power_meter_tests(); power_surge_detector_tests(); } + /*endif*/ if (decode) { power_surge_detector_file_test(in_file); } + /*endif*/ printf("Tests passed\n"); return 0; } diff --git a/tests/r2_mf_rx_tests.c b/tests/r2_mf_rx_tests.c index 33556771..6d525de7 100644 --- a/tests/r2_mf_rx_tests.c +++ b/tests/r2_mf_rx_tests.c @@ -164,6 +164,7 @@ static void my_mf_gen_init(float low_fudge, tone = &r2_mf_fwd_tones[i]; else tone = &r2_mf_back_tones[i]; + /*endif*/ tone_gen_descriptor_init(&my_mf_digit_tones[i], tone->f1*(1.0 + low_fudge), low_level, @@ -175,6 +176,7 @@ static void my_mf_gen_init(float low_fudge, 0, false); } + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -191,6 +193,7 @@ static int my_mf_generate(int16_t amp[], char digit) len += tone_gen(tone, amp + len, 9999); tone_gen_free(tone); } + /*endif*/ return len; } /*- End of function --------------------------------------------------------*/ @@ -204,18 +207,22 @@ static void digit_delivery(void *data, int digit, int level, int delay) callback_ok = false; return; } + /*endif*/ if ((callback_roll & 1)) ch = 0; else ch = r2_mf_tone_codes[callback_roll >> 1]; + /*endif*/ if (ch == digit) callback_ok = true; else callback_ok = false; + /*endif*/ if (r2_mf_tone_codes[callback_roll >> 1]) callback_roll++; else callback_ok = false; + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -268,8 +275,11 @@ static int test_a_tone_set(int fwd) printf(" Failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ } + /*endwhile*/ printf(" Passed\n"); /* Test 3: Recognition bandwidth and channel centre frequency check. @@ -314,7 +324,9 @@ static int test_a_tone_set(int fwd) r2_mf_rx(mf_state, amp, len); if (r2_mf_rx_get(mf_state) == digit) nplus++; + /*endif*/ } + /*endfor*/ for (nminus = 0, i = -1; i >= -60; i--) { my_mf_gen_init((float) i/1000.0, -17, 0.0, -17, 68, fwd); @@ -323,7 +335,9 @@ static int test_a_tone_set(int fwd) r2_mf_rx(mf_state, amp, len); if (r2_mf_rx_get(mf_state) == digit) nminus++; + /*endif*/ } + /*endfor*/ rrb = (float) (nplus + nminus)/10.0; rcfo = (float) (nplus - nminus)/10.0; printf(" %c (low) rrb = %5.2f%%, rcfo = %5.2f%%, max -ve = %5.2f, max +ve = %5.2f\n", @@ -338,6 +352,7 @@ static int test_a_tone_set(int fwd) printf(" Failed\n"); exit(2); } + /*endif*/ for (nplus = 0, i = 1; i <= 60; i++) { @@ -347,7 +362,9 @@ static int test_a_tone_set(int fwd) r2_mf_rx(mf_state, amp, len); if (r2_mf_rx_get(mf_state) == digit) nplus++; + /*endif*/ } + /*endfor*/ for (nminus = 0, i = -1; i >= -60; i--) { my_mf_gen_init(0.0, -17, (float) i/1000.0, -17, 68, fwd); @@ -356,7 +373,9 @@ static int test_a_tone_set(int fwd) r2_mf_rx(mf_state, amp, len); if (r2_mf_rx_get(mf_state) == digit) nminus++; + /*endif*/ } + /*endfor*/ rrb = (float) (nplus + nminus)/10.0; rcfo = (float) (nplus - nminus)/10.0; printf(" %c (high) rrb = %5.2f%%, rcfo = %5.2f%%, max -ve = %5.2f, max +ve = %5.2f\n", @@ -370,8 +389,10 @@ static int test_a_tone_set(int fwd) printf(" Failed\n"); exit(2); } + /*endif*/ j++; } + /*endwhile*/ printf(" Passed\n"); /* Test 4: Acceptable amplitude ratio (twist). @@ -393,13 +414,16 @@ static int test_a_tone_set(int fwd) r2_mf_rx(mf_state, amp, len); if (r2_mf_rx_get(mf_state) == digit) nplus++; + /*endif*/ } + /*endfor*/ printf(" %c normal twist = %.2fdB\n", digit, (float) nplus/10.0); if (nplus < 70) { printf(" Failed\n"); exit(2); } + /*endif*/ for (nminus = 0, i = -50; i >= -250; i--) { my_mf_gen_init(0.0, i/10, 0.0, -5, 68, fwd); @@ -409,14 +433,18 @@ static int test_a_tone_set(int fwd) r2_mf_rx(mf_state, amp, len); if (r2_mf_rx_get(mf_state) == digit) nminus++; + /*endif*/ } + /*endfor*/ printf(" %c reverse twist = %.2fdB\n", digit, (float) nminus/10.0); if (nminus < 70) { printf(" Failed\n"); exit(2); } + /*endif*/ } + /*endwhile*/ printf(" Passed\n"); /* Test 5: Dynamic range @@ -439,27 +467,36 @@ static int test_a_tone_set(int fwd) r2_mf_rx(mf_state, amp, len); if (r2_mf_rx_get(mf_state) != digit) break; + /*endif*/ } + /*endfor*/ if (j < 100) break; + /*endif*/ } + /*endwhile*/ if (j == 100) { if (nplus == -1000) nplus = i; + /*endif*/ } else { if (nplus != -1000 && nminus == -1000) nminus = i; + /*endif*/ } + /*endif*/ } + /*endfor*/ printf(" Dynamic range = %ddB to %ddB\n", nplus, nminus - 1); if (nplus > -35 || nminus <= -5) { printf(" Failed\n"); exit(2); } + /*endif*/ printf(" Passed\n"); /* Test 6: Guard time @@ -482,19 +519,26 @@ static int test_a_tone_set(int fwd) r2_mf_rx(mf_state, amp, len); if (r2_mf_rx_get(mf_state) != digit) break; + /*endif*/ } + /*endfor*/ if (j < 500) break; + /*endif*/ } + /*endwhile*/ if (j == 500) break; + /*endif*/ } + /*endfor*/ printf(" Guard time = %dms\n", i); if (i > 61) { printf(" Failed\n"); exit(2); } + /*endif*/ printf(" Passed\n"); /* Test 7: Acceptable signal to noise ratio @@ -515,24 +559,32 @@ static int test_a_tone_set(int fwd) len = my_mf_generate(amp, digit); for (sample = 0; sample < len; sample++) amp[sample] = sat_add16(amp[sample], awgn(noise_source)); + /*endfor*/ codec_munge(munge, amp, len); r2_mf_rx(mf_state, amp, len); if (r2_mf_rx_get(mf_state) != digit) break; + /*endif*/ } + /*endfor*/ awgn_free(noise_source); if (j < 500) break; + /*endif*/ } + /*endwhile*/ if (j == 500) break; + /*endif*/ } + /*endfor*/ printf(" Acceptable S/N ratio is %ddB\n", -3 - i); if (-3 - i > 26) { printf(" Failed\n"); exit(2); } + /*endif*/ printf(" Passed\n"); printf("Test 8: Callback digit delivery mode.\n"); @@ -554,15 +606,18 @@ static int test_a_tone_set(int fwd) memset(amp, '\0', len*sizeof(int16_t)); for (sample = 0; sample < len; sample++) amp[sample] = sat_add16(amp[sample], awgn(noise_source)); + /*endfor*/ codec_munge(munge, amp, len); r2_mf_rx(mf_state, amp, len); } + /*endwhile*/ awgn_free(noise_source); if (!callback_ok) { printf(" Failed\n"); exit(2); } + /*endif*/ printf(" Passed\n"); r2_mf_rx_free(mf_state); @@ -583,6 +638,7 @@ static void digit_delivery_fwd(void *data, int digit, int level, int delay) callback_ok = false; return; } + /*endif*/ printf("FWD '%c' %d %d\n", (digit == 0) ? '-' : digit, level, delay); } /*- End of function --------------------------------------------------------*/ @@ -594,6 +650,7 @@ static void digit_delivery_bwd(void *data, int digit, int level, int delay) callback_ok = false; return; } + /*endif*/ printf("BWD '%c' %d %d\n", (digit == 0) ? '-' : digit, level, delay); } /*- End of function --------------------------------------------------------*/ @@ -615,6 +672,7 @@ static void decode_test(const char *test_file) fprintf(stderr, " Cannot open audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ while ((samples = sf_readf_short(inhandle, amp, SAMPLES_PER_CHUNK)) > 0) { @@ -622,6 +680,7 @@ static void decode_test(const char *test_file) r2_mf_rx(mf_fwd_state, amp, samples); r2_mf_rx(mf_bwd_state, amp, samples); } + /*endwhile*/ } /*- End of function --------------------------------------------------------*/ @@ -644,7 +703,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ munge = codec_munge_init(MUNGE_CODEC_ALAW, 0); if (decode_test_file) { @@ -660,6 +721,7 @@ int main(int argc, char *argv[]) duration = time(NULL) - now; printf("Tests passed in %lds\n", duration); } + /*endif*/ codec_munge_free(munge); return 0; } diff --git a/tests/r2_mf_tx_tests.c b/tests/r2_mf_tx_tests.c index 0348f799..7c76103c 100644 --- a/tests/r2_mf_tx_tests.c +++ b/tests/r2_mf_tx_tests.c @@ -63,6 +63,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ r2_mf_tx_init(&gen, false); for (digit = 0; digits[digit]; digit++) @@ -72,12 +73,15 @@ int main(int argc, char *argv[]) printf("Generated %d samples of %c\n", len, digits[digit]); if (len > 0) sf_writef_short(outhandle, amp, len); + /*endif*/ r2_mf_tx_put(&gen, 0); len = r2_mf_tx(&gen, amp, 1000); printf("Generated %d samples\n", len); if (len > 0) sf_writef_short(outhandle, amp, len); + /*endif*/ } + /*endfor*/ r2_mf_tx_init(&gen, true); for (digit = 0; digits[digit]; digit++) @@ -87,18 +91,22 @@ int main(int argc, char *argv[]) printf("Generated %d samples of %c\n", len, digits[digit]); if (len > 0) sf_writef_short(outhandle, amp, len); + /*endif*/ r2_mf_tx_put(&gen, 0); len = r2_mf_tx(&gen, amp, 1000); printf("Generated %d samples\n", len); if (len > 0) sf_writef_short(outhandle, amp, len); + /*endif*/ } + /*endfor*/ if (sf_close_telephony(outhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME); exit (2); } + /*endif*/ return 0; } diff --git a/tests/rfc2198_sim_tests.c b/tests/rfc2198_sim_tests.c index fe210a25..491041f0 100644 --- a/tests/rfc2198_sim_tests.c +++ b/tests/rfc2198_sim_tests.c @@ -113,6 +113,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Bad model ID '%s'\n", optarg); exit(2); } + /*endif*/ break; case 's': speed_pattern_no = atoi(optarg); @@ -121,6 +122,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Bad link speed pattern %s\n", optarg); exit(2); } + /*endif*/ break; case 't': simulation_time = atoi(optarg); @@ -130,7 +132,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ argc -= optind; argv += optind; @@ -139,6 +143,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Can't open %s\n", "rfc2198_sim_tests.txt"); return 2; } + /*endif*/ packets_per_sec = 1000/PACKET_INTERVAL; num_packets = packets_per_sec*simulation_time; @@ -147,8 +152,10 @@ int main(int argc, char *argv[]) fprintf(stderr, "Can't allocate the data buffers\n"); return 2; } + /*endif*/ for (i = 0; i < num_packets; i++) packet_arrival_times[i] = 0.0; + /*endfor*/ /* If we don't initialise this random number generator it gives endless zeros on some systems. */ /* Use a fixed seed to produce identical results in successive runs of the simulation, for debug purposes. */ @@ -159,6 +166,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Failed to start the G.1050 model\n"); exit(2); } + /*endif*/ //rfc2198_sim_dump_parms(model_no, speed_pattern_no); #if defined(ENABLE_GUI) @@ -168,6 +176,7 @@ int main(int argc, char *argv[]) for (i = 0; i < 256; i++) put_pkt[i] = i; + /*endfor*/ put_pkt_len = 256; get_pkt_len = -1; get_seq_no = -1; @@ -182,6 +191,7 @@ int main(int argc, char *argv[]) { if ((len = rfc2198_sim_put(s, put_pkt, put_pkt_len, i, (double) i*0.001*PACKET_INTERVAL)) > 0) packets_really_put++; + /*endif*/ packets_put++; #if 0 if (i == 5) @@ -203,18 +213,24 @@ int main(int argc, char *argv[]) oos_packets_got++; else if (get_seq_no > highest_seq_no_got + 1) missing_packets_got += (get_seq_no - highest_seq_no_got - 1); + /*endif*/ if (get_seq_no > highest_seq_no_got) highest_seq_no_got = get_seq_no; + /*endif*/ fprintf(out_file, "%d, %.3f, %.8f\n", get_seq_no, get_seq_no*0.001*PACKET_INTERVAL, get_arrival_time); } + /*endif*/ } while (get_pkt_len >= 0); } + /*endif*/ #if defined(ENABLE_GUI) if (use_gui) media_monitor_update_display(); + /*endif*/ #endif } + /*endfor*/ /* Clear out anything remaining in the queue, by jumping forwards in time */ do { @@ -224,6 +240,7 @@ int main(int argc, char *argv[]) packets_got++; fprintf(out_file, "%d, %.3f, %.8f\n", get_seq_no, get_seq_no*0.001*PACKET_INTERVAL, get_arrival_time); } + /*endif*/ } while (get_pkt_len >= 0); diff --git a/tests/saturated_tests.c b/tests/saturated_tests.c index 67666ced..957814a1 100644 --- a/tests/saturated_tests.c +++ b/tests/saturated_tests.c @@ -60,6 +60,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 15 bit saturation\n"); if (saturate15(10000) != 10000 || @@ -76,6 +77,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 16 bit unsigned saturation\n"); if (saturateu16(10000) != 10000 || @@ -88,6 +90,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 8 bit unsigned saturation\n"); if (saturateu8(100) != 100 || @@ -100,6 +103,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 16 bit saturation from float\n"); if (fsaturatef(10000.0f) != 10000 || @@ -116,6 +120,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 16 bit saturation from double\n"); if (fsaturate(10000.0) != 10000 || @@ -132,6 +137,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 16 bit fast saturation from float\n"); if (ffastsaturatef(10000.0f) != 10000 || @@ -148,6 +154,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 16 bit fast saturation from double\n"); if (ffastsaturate(10000.0) != 10000 || @@ -164,6 +171,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 16 bit float saturation from float\n"); if (ffsaturatef(10000.0f) != 10000.0f || @@ -180,6 +188,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 16 bit double saturation from double\n"); if (ffsaturate(10000.0) != 10000.0 || @@ -196,6 +205,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 16 bit add\n"); if (sat_add16(10000, 10000) != 20000 || @@ -216,6 +226,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 32 bit add\n"); if (sat_add32(10000, 10000) != 20000 || @@ -232,6 +243,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 16 bit subtract\n"); if (sat_sub16(10000, 10000) != 0 || @@ -252,6 +264,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 32 bit subtract\n"); if (sat_sub32(10000, 10000) != 0 || @@ -268,6 +281,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 16 x 16 => 16 bit multiply\n"); if (sat_mul16(100, 100) != 0 || @@ -284,6 +298,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 16 x 16 => 32 bit multiply\n"); if (sat_mul32_16(100, 100) != 20000 || @@ -300,6 +315,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 32 + 16 x 16 => 32 bit MAC\n"); if (sat_mac32_16(123, 100, 100) != 123 + 20000 || @@ -316,6 +332,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 32 - 16 x 16 => 32 bit MSU\n"); if (sat_msu32_16(123, 100, 100) != 123 - 20000 || @@ -332,6 +349,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Testing 16 bit absolute\n"); if (sat_abs16(10000) != 10000 || @@ -344,6 +362,7 @@ int main(int argc, char *argv[]) printf("Test failed.\n"); exit(2); } + /*endif*/ printf("Tests passed.\n"); return 0; } diff --git a/tests/schedule_tests.c b/tests/schedule_tests.c index e3aca335..3c8c6678 100644 --- a/tests/schedule_tests.c +++ b/tests/schedule_tests.c @@ -57,6 +57,7 @@ static void callback1(span_sched_state_t *s, void *user_data) printf("Callback occured at the wrong time.\n"); exit(2); } + /*endif*/ id = span_schedule_event(s, 500000, callback1, NULL); when1 = when + 500000; when = span_schedule_next(s); @@ -76,6 +77,7 @@ static void callback2(span_sched_state_t *s, void *user_data) printf("Callback occured at the wrong time.\n"); exit(2); } + /*endif*/ when2 = when + 550000; when = span_schedule_next(s); printf("2: Event %d, earliest is %" PRId64 "\n", id, when); @@ -97,12 +99,14 @@ int main(int argc, char *argv[]) for (i = 0; i < 100000000; i += 20000) span_schedule_update(&sched, 20000); + /*endfor*/ when = span_schedule_time(&sched); if ((when1 - when) < 0 || (when1 - when) > 500000 || (when2 - when) < 0 || (when2 - when) > 550000) { printf("Callback failed to occur.\n"); exit(2); } + /*endif*/ span_schedule_release(&sched); printf("Tests passed.\n"); diff --git a/tests/sig_tone_tests.c b/tests/sig_tone_tests.c index 290e7873..d13eed8f 100644 --- a/tests/sig_tone_tests.c +++ b/tests/sig_tone_tests.c @@ -93,6 +93,7 @@ static void plot_frequency_response(void) { exit(2); } + /*endif*/ fprintf(gnucmd, "set autoscale\n"); fprintf(gnucmd, "unset log\n"); @@ -111,6 +112,7 @@ static void plot_frequency_response(void) { exit(2); } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -194,6 +196,7 @@ static void tx_handler(void *user_data, int what, int level, int duration) time = pattern_2_tones[tx_section][0]; tone = pattern_2_tones[tx_section][1]; } + /*endif*/ if (time) { printf("Tx: [%04x] %s %s for %d samples (%dms)\n", @@ -209,6 +212,7 @@ static void tx_handler(void *user_data, int what, int level, int duration) { printf("End of sequence\n"); } + /*endif*/ } /*endif*/ } @@ -228,6 +232,7 @@ static void rx_handler(void *user_data, int what, int level, int duration) printf(" %s", (x) ? "on " : "off"); if (x == tone_1_present) exit(2); + /*endif*/ tone_1_present = x; } else @@ -235,6 +240,7 @@ static void rx_handler(void *user_data, int what, int level, int duration) printf(" ---"); if (x != tone_1_present) exit(2); + /*endif*/ } /*endif*/ x = what & SIG_TONE_2_PRESENT; @@ -243,12 +249,14 @@ static void rx_handler(void *user_data, int what, int level, int duration) printf(" %s", (x) ? "on " : "off"); if (x == tone_2_present) exit(2); + /*endif*/ tone_2_present = x; } else { if (x != tone_2_present) exit(2); + /*endif*/ printf(" ---"); } /*endif*/ @@ -318,6 +326,7 @@ static void map_frequency_response(sig_tone_rx_state_t *s, template_t template[] /*endif*/ if (freq > template[template_entry].freq) template_entry++; + /*endif*/ } /*endfor*/ swept_tone_free(swept); @@ -425,6 +434,7 @@ static void level_and_ratio_tests(sig_tone_rx_state_t *s, double pitch[2]) tone = dds_mod(&phase[0], phase_rate[0], gain, 0); if (phase_rate[1]) tone += dds_mod(&phase[1], phase_rate[1], gain, 0); + /*endif*/ power_meter_update(&noise_meter, noise); power_meter_update(&tone_meter, tone); amp[i] = noise + tone; @@ -437,6 +447,7 @@ static void level_and_ratio_tests(sig_tone_rx_state_t *s, double pitch[2]) printf("Measured tone = %.2fdBm0, noise = %.2fdBm0\n", power_meter_current_dbm0(&tone_meter), power_meter_current_dbm0(&noise_meter)); if (rx_handler_callbacks != 1) printf("Callbacks = %d\n", rx_handler_callbacks); + /*endif*/ } /*endif*/ tone_level += 1.0f; @@ -535,7 +546,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ for (type = 1; type <= 3; type++) { @@ -549,6 +562,7 @@ int main(int argc, char *argv[]) template[i].min_level = 0.0; template[i].max_level = 0.0; } + /*endfor*/ fc[0] = fc[1] = 0.0; switch (type) @@ -650,6 +664,7 @@ int main(int argc, char *argv[]) sequence_tests(&tx_state, &rx_state, munge); if (munge) codec_munge_free(munge); + /*endif*/ } /*endfor*/ diff --git a/tests/sprt_decode.c b/tests/sprt_decode.c index 83ee9b72..35fb7e1b 100644 --- a/tests/sprt_decode.c +++ b/tests/sprt_decode.c @@ -71,21 +71,6 @@ static span_timestamp_t sprt_timer_handler(void *user_data, span_timestamp_t tim } /*- End of function --------------------------------------------------------*/ -static int sprt_rx_packet_handler(void *user_data, int chan, int seq_no, const uint8_t msg[], int len) -{ - int i; - - printf("%d %s\n", chan, sprt_transmission_channel_to_str(chan)); - printf("%5d %3d >>> ", seq_no, len); - for (i = 0; i < len; i++) - printf("%02X ", msg[i]); - /*endfor*/ - printf("\n"); - v150_1_process_rx_msg(v150_1, chan, seq_no, msg, len); - return 0; -} -/*- End of function --------------------------------------------------------*/ - static int sprt_tx_packet_handler(void *user_data, const uint8_t msg[], int len) { int i; @@ -124,18 +109,6 @@ static int v150_1_octet_stream_handler(void *user_data, const uint8_t msg[], int } /*- End of function --------------------------------------------------------*/ -static int v150_1_rx_packet_handler(void *user_data, int seq_no, const uint8_t msg[], int len) -{ - return 0; -} -/*- End of function --------------------------------------------------------*/ - -static int v150_1_tx_packet_handler(void *user_data, int seq_no, const uint8_t msg[], int len) -{ - return 0; -} -/*- End of function --------------------------------------------------------*/ - static int timing_update(void *user_data, struct timeval *ts) { current_time = ts->tv_sec*1000000LL + ts->tv_usec; @@ -347,12 +320,36 @@ static int process_packet(void *user_data, const uint8_t *pkt, int len, bool for if (sprt == NULL) { - sprt = sprt_init(NULL, 0, 120, 120, NULL, sprt_tx_packet_handler, NULL, sprt_rx_packet_handler, NULL, sprt_timer_handler, NULL, NULL, NULL); + sprt = sprt_init(NULL, + 0, + 120, + 120, + NULL, + sprt_tx_packet_handler, + NULL, + NULL, + NULL, + sprt_timer_handler, + NULL, + NULL, + NULL); } /*endif*/ if (v150_1 == NULL) { - v150_1 = v150_1_init(NULL, v150_1_tx_packet_handler, NULL, v150_1_octet_stream_handler, NULL, v150_1_status_report_handler, NULL); + v150_1 = v150_1_init(NULL, + sprt_tx_packet_handler, + NULL, + 120, + 120, + NULL, + NULL, + NULL, + NULL, + v150_1_octet_stream_handler, + NULL, + v150_1_status_report_handler, + NULL); } /*endif*/ diff --git a/tests/sprt_tests.c b/tests/sprt_tests.c index 8f5fec01..4d06d29c 100644 --- a/tests/sprt_tests.c +++ b/tests/sprt_tests.c @@ -64,7 +64,7 @@ int max_payloads[SPRT_CHANNELS]; int pace_no = 0; span_timestamp_t pace_timer = 0; -span_timestamp_t app_timer = 0; +span_timestamp_t sprt_timer = 0; bool send_messages = false; @@ -326,15 +326,15 @@ static void timer_callback(void *user_data) pace_timer += 20000; } /*endif*/ - if (app_timer && now >= app_timer) + if (sprt_timer && now >= sprt_timer) { fprintf(stderr, "SPRT timer expired at %lu\n", now); - app_timer = 0; + sprt_timer = 0; sprt_timer_expired((sprt_state_t *) user_data, now); } /*endif*/ - if (app_timer && app_timer < pace_timer) - socket_dgram_harness_timer = app_timer; + if (sprt_timer && sprt_timer < pace_timer) + socket_dgram_harness_timer = sprt_timer; else socket_dgram_harness_timer = pace_timer; /*endif*/ @@ -349,7 +349,7 @@ static span_timestamp_t timer_handler(void *user_data, span_timestamp_t timeout) if (timeout == 0) { fprintf(stderr, "SPRT timer stopped at %lu\n", now); - app_timer = 0; + sprt_timer = 0; socket_dgram_harness_timer = pace_timer; } else if (timeout == ~0) @@ -363,8 +363,8 @@ static span_timestamp_t timer_handler(void *user_data, span_timestamp_t timeout) if (timeout < now) timeout = now; /*endif*/ - app_timer = timeout; - if (app_timer < pace_timer) + sprt_timer = timeout; + if (sprt_timer < pace_timer) socket_dgram_harness_timer = timeout; /*endif*/ } @@ -404,7 +404,7 @@ static int sprt_tests(bool calling_party) rx_callback, tx_callback, timer_callback, - sprt_state)) == NULL) + NULL)) == NULL) { fprintf(stderr, " Cannot start the socket harness\n"); exit(2); @@ -429,12 +429,13 @@ static int sprt_tests(bool calling_party) exit(2); } /*endif*/ - socket_dgram_harness_set_user_data(dgram_state, sprt_state); for (i = SPRT_TCID_MIN; i <= SPRT_TCID_MAX; i++) max_payloads[i] = sprt_get_far_tc_payload_bytes(sprt_state, i); /*endfor*/ + socket_dgram_harness_set_user_data(dgram_state, sprt_state); + logging = sprt_get_logging_state(sprt_state); span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_DATE); span_log_set_tag(logging, (calling_party) ? "C" : "A"); diff --git a/tests/super_tone_rx_tests.c b/tests/super_tone_rx_tests.c index 492d2906..3d0ccc6d 100644 --- a/tests/super_tone_rx_tests.c +++ b/tests/super_tone_rx_tests.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include #include @@ -53,11 +54,13 @@ #include #endif +#if defined(HAVE_LIBXML_XMLMEMORY_H) && defined(HAVE_LIBXML_PARSER_H) && defined(HAVE_LIBXML_XINCLUDE_H) +#define HAVE_LIBXML2 1 +#endif + #include "spandsp.h" #include "spandsp-sim.h" -#define IN_FILE_NAME "super_tone.wav" - #define MITEL_DIR "../test-data/mitel/" #define BELLCORE_DIR "../test-data/bellcore/" @@ -437,14 +440,16 @@ static int detection_range_tests(super_tone_rx_state_t *super) int16_t amp[SAMPLES_PER_CHUNK]; int i; int j; - uint32_t phase; - int32_t phase_inc; + uint32_t phase[2]; + int32_t phase_inc[2]; int scale; printf("Detection range tests\n"); super_tone_rx_tone_callback(super, wakeup, (void *) "test"); - phase = 0; - phase_inc = dds_phase_rate(440.0f); + phase[0] = 0; + phase_inc[0] = dds_phase_rate(350.0f); + phase[1] = 0; + phase_inc[1] = dds_phase_rate(440.0f); for (level = -80; level < 0; level++) { printf("Testing at %ddBm0\n", level); @@ -452,7 +457,10 @@ static int detection_range_tests(super_tone_rx_state_t *super) for (j = 0; j < 100; j++) { for (i = 0; i < SAMPLES_PER_CHUNK; i++) - amp[i] = (dds(&phase, phase_inc)*scale) >> 15; + { + amp[i] = (dds(&phase[0], phase_inc[0])*scale) >> 15; + amp[i] += (dds(&phase[1], phase_inc[1])*scale) >> 15; + } /*endfor*/ super_tone_rx(super, amp, SAMPLES_PER_CHUNK); } @@ -506,12 +514,31 @@ static int file_decode_tests(super_tone_rx_state_t *super, const char *file_name int main(int argc, char *argv[]) { - const char *file_name; + char *decode_test_file; super_tone_rx_state_t *super; super_tone_rx_descriptor_t desc; + int opt; + + decode_test_file = NULL; + while ((opt = getopt(argc, argv, "d:")) != -1) + { + switch (opt) + { + case 'd': + decode_test_file = optarg; + break; + default: + //usage(); + exit(2); + break; + } + /*endswitch*/ + } + /*endwhile*/ super_tone_rx_make_descriptor(&desc); #if defined(HAVE_LIBXML2) + printf("Loading tone set %s\n", (argc > 1) ? argv[1] : "hk"); get_tone_set(&desc, "../spandsp/global-tones.xml", (argc > 1) ? argv[1] : "hk"); #endif super_tone_rx_fill_descriptor(&desc); @@ -525,8 +552,11 @@ int main(int argc, char *argv[]) detection_range_tests(super); - file_name = IN_FILE_NAME; - file_decode_tests(super, file_name); + if (decode_test_file) + { + file_decode_tests(super, decode_test_file); + } + /*endif*/ talk_off_tests(super); diff --git a/tests/super_tone_tx_tests.c b/tests/super_tone_tx_tests.c index 68d65a7d..777bbf64 100644 --- a/tests/super_tone_tx_tests.c +++ b/tests/super_tone_tx_tests.c @@ -54,6 +54,10 @@ #include #endif +#if defined(HAVE_LIBXML_XMLMEMORY_H) && defined(HAVE_LIBXML_PARSER_H) && defined(HAVE_LIBXML_XINCLUDE_H) +#define HAVE_LIBXML2 1 +#endif + #include "spandsp.h" #include "spandsp-sim.h" @@ -83,6 +87,7 @@ static void play_tones(super_tone_tx_state_t *tone, int max_samples) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ total_length += len; } while (len > 0 && --i > 0); @@ -125,38 +130,46 @@ static int parse_tone(super_tone_tx_step_t **tree, xmlDocPtr doc, xmlNsPtr ns, x printf("Frequency=%.2f+%.2f [%.2f%%]", f1, f2, f_tol); xmlFree(x); } + /*endif*/ if ((x = xmlGetProp(cur, (const xmlChar *) "level"))) { if (sscanf((char *) x, "%f+%f", &l1, &l2) < 2) l2 = l1; + /*endif*/ printf("Level=%.2f+%.2f", l1, l2); xmlFree(x); } + /*endif*/ if ((x = xmlGetProp(cur, (const xmlChar *) "length"))) { sscanf((char *) x, "%f [%f%%]", &length, &length_tol); printf("Length=%.2f [%.2f%%]", length, length_tol); xmlFree(x); } + /*endif*/ if ((x = xmlGetProp(cur, (const xmlChar *) "recognition-length"))) { printf("Recognition length='%s'", x); xmlFree(x); } + /*endif*/ if ((x = xmlGetProp(cur, (const xmlChar *) "cycles"))) { if (strcasecmp((char *) x, "endless") == 0) cycles = 0; else cycles = atoi((char *) x); + /*endif*/ printf("Cycles=%d ", cycles); xmlFree(x); } + /*endif*/ if ((x = xmlGetProp(cur, (const xmlChar *) "recorded-announcement"))) { printf("Recorded announcement='%s'", x); xmlFree(x); } + /*endif*/ printf("\n"); treep = super_tone_tx_make_step(NULL, f1, @@ -288,6 +301,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ #if defined(HAVE_LIBXML2) get_tone_set("../spandsp/global-tones.xml", (argc > 1) ? argv[1] : "hk"); #endif @@ -296,6 +310,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ printf("Done\n"); return 0; } diff --git a/tests/swept_tone_tests.c b/tests/swept_tone_tests.c index 8fef1322..35b5ecab 100644 --- a/tests/swept_tone_tests.c +++ b/tests/swept_tone_tests.c @@ -60,6 +60,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot create audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ printf("Test with swept tone.\n"); s = swept_tone_init(NULL, 200.0f, 3900.0f, -10.0f, 60*SAMPLE_RATE, true); @@ -68,12 +69,14 @@ int main(int argc, char *argv[]) len = swept_tone(s, buf, BLOCK_LEN); for (i = 0; i < len; i++) power_meter_update(&meter, buf[i]); + /*endfor*/ outframes = sf_writef_short(outhandle, buf, len); if (outframes != len) { fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ #if 0 printf("Current freq %.1fHz, Level is %fdBOv/%fdBm0\n", swept_tone_current_frequency(s), @@ -85,12 +88,14 @@ int main(int argc, char *argv[]) power_meter_current_dbm0(&meter)); #endif } + /*endfor*/ if (sf_close_telephony(outhandle)) { fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ swept_tone_free(s); diff --git a/tests/t31_pseudo_terminal_tests.c b/tests/t31_pseudo_terminal_tests.c index fcd5146a..9def0a42 100644 --- a/tests/t31_pseudo_terminal_tests.c +++ b/tests/t31_pseudo_terminal_tests.c @@ -167,6 +167,7 @@ printf("\n"); assert(o.hEvent); if (!WriteFile(modem->master_fd, buf, (DWORD) len, &res, &o)) GetOverlappedResult(modem->master_fd, &o, &res, true); + /*endif*/ CloseHandle(o.hEvent); #else res = write(pty->master_fd, buf, len); @@ -184,8 +185,10 @@ printf("\n"); printf("Unable to flush pty slave buffer: %s\n", strerror(errno)); else printf("Successfully flushed pty buffer\n"); + /*endif*/ #endif } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -269,7 +272,9 @@ static int t38_tx_packet_handler(t38_core_state_t *s, void *user_data, const uin { if (g1050_put(path_a_to_b, buf, len, s->tx_seq_no, when) < 0) printf("Lost packet %d\n", s->tx_seq_no); + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -285,7 +290,9 @@ static int t31_tx_packet_handler(t38_core_state_t *s, void *user_data, const uin { if (g1050_put(path_b_to_a, buf, len, s->tx_seq_no, when) < 0) printf("Lost packet %d\n", s->tx_seq_no); + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -329,13 +336,17 @@ static int modem_wait_sock(pseudo_terminal_state_t *pty, int ms, modem_poll_t fl dwWait = WaitForMultipleObjects(2, arHandles, false, INFINITE); if (dwWait == WAIT_OBJECT_0 + 1 && !pty->block_read) ret = MODEM_POLL_READ; + /*endif*/ } + /*endif*/ } else { if (!pty->block_read) ret = MODEM_POLL_READ; + /*endif*/ } + /*endif*/ CloseHandle (o.hEvent); return ret; @@ -352,10 +363,13 @@ static int modem_wait_sock(int sock, uint32_t ms, modem_poll_t flags) if ((flags & MODEM_POLL_READ)) pfds[0].events |= POLLIN; + /*endif*/ if ((flags & MODEM_POLL_WRITE)) pfds[0].events |= POLLOUT; + /*endif*/ if ((flags & MODEM_POLL_ERROR)) pfds[0].events |= POLLERR; + /*endif*/ s = poll(pfds, (pty->block_read) ? 0 : 1, ms); @@ -368,11 +382,15 @@ static int modem_wait_sock(int sock, uint32_t ms, modem_poll_t flags) { if ((pfds[0].revents & POLLIN)) ret |= MODEM_POLL_READ; + /*endif*/ if ((pfds[0].revents & POLLOUT)) ret |= MODEM_POLL_WRITE; + /*endif*/ if ((pfds[0].revents & POLLERR)) ret |= MODEM_POLL_ERROR; + /*endif*/ } + /*endif*/ return ret; @@ -429,7 +447,9 @@ static int t30_tests(int t38_mode, int use_ecm, int use_gui, int log_audio, int fprintf(stderr, " Cannot create audio file '%s'\n", OUTPUT_WAVE_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ in_handle = NULL; if (decode_test_file) @@ -439,7 +459,9 @@ static int t30_tests(int t38_mode, int use_ecm, int use_gui, int log_audio, int fprintf(stderr, " Cannot create audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ } + /*endif*/ srand48(0x1234567); if ((path_a_to_b = g1050_init(g1050_model_no, g1050_speed_pattern_no, 100, 33)) == NULL) @@ -447,11 +469,13 @@ static int t30_tests(int t38_mode, int use_ecm, int use_gui, int log_audio, int fprintf(stderr, "Failed to start IP network path model\n"); exit(2); } + /*endif*/ if ((path_b_to_a = g1050_init(g1050_model_no, g1050_speed_pattern_no, 100, 33)) == NULL) { fprintf(stderr, "Failed to start IP network path model\n"); exit(2); } + /*endif*/ t38_state = NULL; fax_state = NULL; @@ -464,6 +488,7 @@ static int t30_tests(int t38_mode, int use_ecm, int use_gui, int log_audio, int fprintf(stderr, "Cannot start the T.38 channel\n"); exit(2); } + /*endif*/ t30 = t38_terminal_get_t30_state(t38_state); } else @@ -471,6 +496,7 @@ static int t30_tests(int t38_mode, int use_ecm, int use_gui, int log_audio, int fax_state = fax_init(NULL, false); t30 = fax_get_t30_state(fax_state); } + /*endif*/ t30_set_rx_file(t30, OUTPUT_FILE_NAME, -1); countdown = 0; } @@ -483,6 +509,7 @@ static int t30_tests(int t38_mode, int use_ecm, int use_gui, int log_audio, int fprintf(stderr, "Cannot start the T.38 channel\n"); exit(2); } + /*endif*/ t30 = t38_terminal_get_t30_state(t38_state); } else @@ -490,9 +517,11 @@ static int t30_tests(int t38_mode, int use_ecm, int use_gui, int log_audio, int fax_state = fax_init(NULL, true); t30 = fax_get_t30_state(fax_state); } + /*endif*/ t30_set_tx_file(t30, INPUT_FILE_NAME, -1, -1); countdown = 250; } + /*endif*/ t30_set_ecm_capability(t30, use_ecm); @@ -503,6 +532,7 @@ static int t30_tests(int t38_mode, int use_ecm, int use_gui, int log_audio, int t38_terminal_set_config(t38_state, without_pacing); t38_terminal_set_tep_mode(t38_state, use_tep); } + /*endif*/ t30_set_tx_ident(t30, "11111111"); t30_set_supported_modems(t30, T30_SUPPORT_V27TER | T30_SUPPORT_V29 | T30_SUPPORT_V17); @@ -515,6 +545,7 @@ static int t30_tests(int t38_mode, int use_ecm, int use_gui, int log_audio, int logging = t38_terminal_get_logging_state(t38_state); else logging = t30_get_logging_state(t30); + /*endif*/ span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME); span_log_set_tag(logging, (t38_mode) ? "T.38" : "FAX"); @@ -535,6 +566,7 @@ static int t30_tests(int t38_mode, int use_ecm, int use_gui, int log_audio, int span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME); span_log_set_tag(logging, "FAX"); } + /*endif*/ memset(silence, 0, sizeof(silence)); memset(t30_amp, 0, sizeof(t30_amp)); @@ -545,6 +577,7 @@ static int t30_tests(int t38_mode, int use_ecm, int use_gui, int log_audio, int fprintf(stderr, " Cannot start the T.31 modem\n"); exit(2); } + /*endif*/ at_state = t31_get_at_state(t31_state); logging = t31_get_logging_state(t31_state); @@ -565,6 +598,7 @@ static int t30_tests(int t38_mode, int use_ecm, int use_gui, int log_audio, int t31_set_mode(t31_state, true); t38_set_t38_version(t38_core, t38_version); } + /*endif*/ at_reset_call_info(at_state); at_set_call_info(at_state, "DATE", "1231"); @@ -596,6 +630,7 @@ static int t30_tests(int t38_mode, int use_ecm, int use_gui, int log_audio, int t31_call_event(t31_state, AT_CALL_EVENT_ALERTING); countdown = 250; } + /*endif*/ } else if (answered == 1) { @@ -603,7 +638,9 @@ printf("ZZZ\n"); answered = 2; t31_call_event(t31_state, AT_CALL_EVENT_ANSWERED); } + /*endif*/ } + /*endif*/ ret = modem_wait_sock(pty[0].master_fd, 20, MODEM_POLL_READ); if ((ret & MODEM_POLL_READ)) @@ -619,6 +656,7 @@ printf("ZZZ\n"); assert(o.hEvent); if (!ReadFile(pty[0].master_fd, buf, avail, &read_bytes, &o)) GetOverlappedResult(pty[0].master_fd, &o, &read_bytes, true); + /*endif*/ CloseHandle (o.hEvent); if ((len = read_bytes)) #else @@ -633,7 +671,9 @@ for (i = 0; i < len; i++) printf("\n"); t31_at_rx(t31_state, buf, len); } + /*endif*/ } + /*endif*/ if (answered == 2) { @@ -648,6 +688,7 @@ printf("\n"); t38_core = t31_get_t38_core_state(t31_state); t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no); } + /*endwhile*/ while ((msg_len = g1050_get(path_b_to_a, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0) { #if defined(ENABLE_GUI) @@ -657,9 +698,11 @@ printf("\n"); t38_core = t38_terminal_get_t38_core_state(t38_state); t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no); } + /*endwhile*/ #if defined(ENABLE_GUI) if (use_gui) media_monitor_update_display(); + /*endif*/ #endif /* Bump the G.1050 models along */ when += (float) SAMPLES_PER_CHUNK/(float) SAMPLE_RATE; @@ -683,37 +726,48 @@ printf("\n"); memset(t30_amp + t30_len, 0, sizeof(int16_t)*(SAMPLES_PER_CHUNK - t30_len)); t30_len = SAMPLES_PER_CHUNK; } + /*endif*/ if (log_audio) { for (k = 0; k < t30_len; k++) out_amp[2*k] = t30_amp[k]; + /*endfor*/ } + /*endif*/ if (t31_rx(t31_state, t30_amp, t30_len)) break; + /*endif*/ t31_len = t31_tx(t31_state, t31_amp, SAMPLES_PER_CHUNK); if (t31_len < SAMPLES_PER_CHUNK) { memset(t31_amp + t31_len, 0, sizeof(int16_t)*(SAMPLES_PER_CHUNK - t31_len)); t31_len = SAMPLES_PER_CHUNK; } + /*endif*/ if (log_audio) { for (k = 0; k < t31_len; k++) out_amp[2*k + 1] = t31_amp[k]; + /*endfor*/ } + /*endif*/ if (fax_rx(fax_state, t31_amp, SAMPLES_PER_CHUNK)) break; + /*endif*/ if (log_audio) { outframes = sf_writef_short(wave_handle, out_amp, SAMPLES_PER_CHUNK); if (outframes != SAMPLES_PER_CHUNK) break; + /*endif*/ } + /*endif*/ /* Bump things along on the FAX machine side */ span_log_bump_samples(fax_get_logging_state(fax_state), SAMPLES_PER_CHUNK); } + /*endif*/ /* Bump things along on the FAX machine side */ span_log_bump_samples(t30_get_logging_state(t30), SAMPLES_PER_CHUNK); @@ -723,10 +777,13 @@ printf("\n"); span_log_bump_samples(t31_get_logging_state(t31_state), SAMPLES_PER_CHUNK); span_log_bump_samples(at_get_logging_state(t31_get_at_state(t31_state)), SAMPLES_PER_CHUNK); } + /*endif*/ } + /*endwhile*/ if (t38_mode) t38_terminal_release(t38_state); + /*endif*/ if (decode_test_file) { @@ -735,7 +792,9 @@ printf("\n"); fprintf(stderr, " Cannot close audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ } + /*endif*/ if (log_audio) { if (sf_close_telephony(wave_handle)) @@ -743,13 +802,16 @@ printf("\n"); fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_WAVE_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ if (!done) { printf("Tests failed\n"); return 2; } + /*endif*/ return 0; } @@ -815,14 +877,18 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ if (pseudo_terminal_init(&pty[0])) printf("Failure\n"); + /*endif*/ t30_tests(t38_mode, use_ecm, use_gui, log_audio, test_sending, g1050_model_no, g1050_speed_pattern_no); if (pseudo_terminal_release(&pty[0])) printf("Failure\n"); + /*endif*/ printf("Tests passed\n"); return 0; } diff --git a/tests/t31_tests.c b/tests/t31_tests.c index beff7f9c..23866a1a 100644 --- a/tests/t31_tests.c +++ b/tests/t31_tests.c @@ -399,35 +399,46 @@ static int at_tx_handler(void *user_data, const uint8_t *buf, size_t len) test_seq_ptr++; if (fax_test_seq[test_seq_ptr].command == NULL && fax_test_seq[test_seq_ptr].command == NULL) sequence_terminated = true; + /*endif*/ if (fax_test_seq[test_seq_ptr].command) kick = true; + /*endif*/ break; } + /*endif*/ dled = false; } else { if (buf[i] == DLE) dled = true; + /*endif*/ } + /*endif*/ } + /*endfor*/ i++; if (i >= len) return 0; + /*endif*/ } + /*endif*/ for ( ; i < len; i++) { response_buf[response_buf_ptr++] = buf[i]; putchar(buf[i]); } + /*endfor*/ response_buf[response_buf_ptr] = '\0'; printf("Expected "); for (i = 0; i < response_buf_ptr; i++) printf("%02x ", fax_test_seq[test_seq_ptr].response[i] & 0xFF); + /*endfor*/ printf("\n"); printf("Response "); for (i = 0; i < response_buf_ptr; i++) printf("%02x ", response_buf[i] & 0xFF); + /*endfor*/ printf("\n"); printf("Match %d against %d\n", response_buf_ptr, fax_test_seq[test_seq_ptr].len_response); if (response_buf_ptr >= fax_test_seq[test_seq_ptr].len_response @@ -438,13 +449,16 @@ static int at_tx_handler(void *user_data, const uint8_t *buf, size_t len) test_seq_ptr++; if (fax_test_seq[test_seq_ptr].command == NULL && fax_test_seq[test_seq_ptr].command == NULL) sequence_terminated = true; + /*endif*/ response_buf_ptr = 0; response_buf[response_buf_ptr] = '\0'; if (fax_test_seq[test_seq_ptr].command) kick = true; else dled = false; + /*endif*/ } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -460,7 +474,9 @@ static int t38_tx_packet_handler(t38_core_state_t *s, void *user_data, const uin { if (g1050_put(path_a_to_b, buf, len, s->tx_seq_no, when) < 0) printf("Lost packet %d\n", s->tx_seq_no); + /*endfor*/ } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -476,7 +492,9 @@ static int t31_tx_packet_handler(t38_core_state_t *s, void *user_data, const uin { if (g1050_put(path_b_to_a, buf, len, s->tx_seq_no, when) < 0) printf("Lost packet %d\n", s->tx_seq_no); + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -527,7 +545,9 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, fprintf(stderr, " Cannot create audio file '%s'\n", OUTPUT_WAVE_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ in_handle = NULL; if (decode_test_file) @@ -537,7 +557,9 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, fprintf(stderr, " Cannot create audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ } + /*endif*/ srand48(0x1234567); if ((path_a_to_b = g1050_init(g1050_model_no, g1050_speed_pattern_no, 100, 33)) == NULL) @@ -545,11 +567,13 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, fprintf(stderr, "Failed to start IP network path model\n"); exit(2); } + /*endif*/ if ((path_b_to_a = g1050_init(g1050_model_no, g1050_speed_pattern_no, 100, 33)) == NULL) { fprintf(stderr, "Failed to start IP network path model\n"); exit(2); } + /*endif*/ t38_state = NULL; fax_state = NULL; @@ -562,6 +586,7 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, fprintf(stderr, "Cannot start the T.38 channel\n"); exit(2); } + /*endif*/ t30 = t38_terminal_get_t30_state(t38_state); } else @@ -569,6 +594,7 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, fax_state = fax_init(NULL, false); t30 = fax_get_t30_state(fax_state); } + /*endif*/ t30_set_rx_file(t30, OUTPUT_FILE_NAME, -1); fax_test_seq = fax_send_test_seq; countdown = 0; @@ -582,6 +608,7 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, fprintf(stderr, "Cannot start the T.38 channel\n"); exit(2); } + /*endif*/ t30 = t38_terminal_get_t30_state(t38_state); } else @@ -589,10 +616,12 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, fax_state = fax_init(NULL, true); t30 = fax_get_t30_state(fax_state); } + /*endif*/ t30_set_tx_file(t30, INPUT_FILE_NAME, -1, -1); fax_test_seq = fax_receive_test_seq; countdown = 250; } + /*endif*/ if (t38_mode) { @@ -601,6 +630,7 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, t38_terminal_set_config(t38_state, without_pacing); t38_terminal_set_tep_mode(t38_state, use_tep); } + /*endif*/ t30_set_tx_ident(t30, "11111111"); t30_set_supported_modems(t30, T30_SUPPORT_V27TER | T30_SUPPORT_V29 | T30_SUPPORT_V17); @@ -613,6 +643,7 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, logging = t38_terminal_get_logging_state(t38_state); else logging = t30_get_logging_state(t30); + /*endif*/ span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME); span_log_set_tag(logging, (t38_mode) ? "T.38" : "FAX"); @@ -632,6 +663,7 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME); span_log_set_tag(logging, "FAX"); } + /*endif*/ memset(silence, 0, sizeof(silence)); memset(t30_amp, 0, sizeof(t30_amp)); @@ -642,6 +674,7 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, fprintf(stderr, " Cannot start the T.31 modem\n"); exit(2); } + /*endif*/ logging = t31_get_logging_state(t31_state); span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME); span_log_set_tag(logging, "T.31"); @@ -660,6 +693,7 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, t31_set_mode(t31_state, true); t38_set_t38_version(t38_core, t38_version); } + /*endif*/ fast_send = false; fast_send_tcf = true; @@ -668,6 +702,7 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, #if defined(ENABLE_GUI) if (use_gui) start_media_monitor(); + /*endif*/ #endif while (!done) { @@ -684,7 +719,9 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, t31_call_event(t31_state, AT_CALL_EVENT_ALERTING); countdown = 250; } + /*endif*/ } + /*endif*/ if (kick) { @@ -697,6 +734,7 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, printf("%s\n", fax_test_seq[test_seq_ptr].command); t31_at_rx(t31_state, fax_test_seq[test_seq_ptr].command, fax_test_seq[test_seq_ptr].len_command); } + /*endif*/ } else { @@ -714,8 +752,11 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, fast_send_tcf = false; fast_blocks = 100; } + /*endif*/ } + /*endif*/ } + /*endif*/ if (fast_send) { /* Send fast modem data */ @@ -729,6 +770,7 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, fast_buf[34] = DLE; fast_buf[35] = ETX; } + /*endif*/ } else { @@ -744,6 +786,7 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, fast_buf[i + 2] = 0xB2; fast_buf[i + 3] = 0x01; } + /*endfor*/ } else { @@ -754,15 +797,20 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, fast_buf[i + 1] = 0x08; fast_buf[i + 2] = 0x80; } + /*endfor*/ /* Tell the modem this is the end of the image data. */ fast_buf[34] = DLE; fast_buf[35] = ETX; } + /*endif*/ } + /*endif*/ t31_at_rx(t31_state, (char *) fast_buf, 36); if (--fast_blocks == 0) fast_send = false; + /*endif*/ } + /*endif*/ if (t38_mode) { @@ -775,6 +823,7 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, t38_core = t31_get_t38_core_state(t31_state); t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no); } + /*endwhile*/ while ((msg_len = g1050_get(path_b_to_a, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0) { #if defined(ENABLE_GUI) @@ -784,9 +833,11 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, t38_core = t38_terminal_get_t38_core_state(t38_state); t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no); } + /*endwhile*/ #if defined(ENABLE_GUI) if (use_gui) media_monitor_update_display(); + /*endif*/ #endif /* Bump the G.1050 models along */ when += (float) SAMPLES_PER_CHUNK/(float) SAMPLE_RATE; @@ -810,37 +861,48 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, memset(t30_amp + t30_len, 0, sizeof(int16_t)*(SAMPLES_PER_CHUNK - t30_len)); t30_len = SAMPLES_PER_CHUNK; } + /*endif*/ if (log_audio) { for (k = 0; k < t30_len; k++) out_amp[2*k] = t30_amp[k]; + /*endfor*/ } + /*endif*/ if (t31_rx(t31_state, t30_amp, t30_len)) break; + /*endif*/ t31_len = t31_tx(t31_state, t31_amp, SAMPLES_PER_CHUNK); if (t31_len < SAMPLES_PER_CHUNK) { memset(t31_amp + t31_len, 0, sizeof(int16_t)*(SAMPLES_PER_CHUNK - t31_len)); t31_len = SAMPLES_PER_CHUNK; } + /*endif*/ if (log_audio) { for (k = 0; k < t31_len; k++) out_amp[2*k + 1] = t31_amp[k]; + /*endfor*/ } + /*endif*/ if (fax_rx(fax_state, t31_amp, SAMPLES_PER_CHUNK)) break; + /*endif*/ if (log_audio) { outframes = sf_writef_short(wave_handle, out_amp, SAMPLES_PER_CHUNK); if (outframes != SAMPLES_PER_CHUNK) break; + /*endif*/ } + /*endif*/ /* Bump things along on the FAX machine side */ span_log_bump_samples(fax_get_logging_state(fax_state), SAMPLES_PER_CHUNK); } + /*endif*/ /* Bump things along on the FAX machine side */ span_log_bump_samples(t30_get_logging_state(t30), SAMPLES_PER_CHUNK); @@ -851,6 +913,7 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, span_log_bump_samples(t31_get_logging_state(t31_state), SAMPLES_PER_CHUNK); span_log_bump_samples(at_get_logging_state(t31_get_at_state(t31_state)), SAMPLES_PER_CHUNK); } + /*endwhile*/ g1050_free(path_a_to_b); g1050_free(path_b_to_a); @@ -858,6 +921,7 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, t38_terminal_free(t38_state); else fax_free(fax_state); + /*endif*/ t31_free(t31_state); if (decode_test_file) @@ -867,7 +931,9 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, fprintf(stderr, " Cannot close audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ } + /*endif*/ if (log_audio) { if (sf_close_telephony(wave_handle)) @@ -875,13 +941,16 @@ static int t30_tests(int t38_mode, int use_gui, int log_audio, int test_sending, fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_WAVE_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ if (!done || !sequence_terminated) { printf("Tests failed\n"); return -1; } + /*endif*/ return 0; } @@ -942,10 +1011,13 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ if (t30_tests(t38_mode, use_gui, log_audio, test_sending, g1050_model_no, g1050_speed_pattern_no) < 0) return 2; + /*endif*/ printf("Tests passed\n"); return 0; } diff --git a/tests/t35_tests.c b/tests/t35_tests.c index b65e3018..c7a8f85a 100644 --- a/tests/t35_tests.c +++ b/tests/t35_tests.c @@ -67,7 +67,9 @@ int main(int argc, char *argv[]) t35_real_country_code(i, 0), (real_country) ? real_country : "???"); } + /*endif*/ } + /*endfor*/ printf("\nSweep through all the possible vendors within each country\n"); for (i = 0; i < 256; i++) @@ -88,12 +90,17 @@ int main(int argc, char *argv[]) printf("%s\n", real_country); else printf("???\n"); + /*endif*/ first_hit = false; } + /*endif*/ printf(" 0x%02x 0x%02x 0x%02x '%s'\n", msg[0], msg[1], msg[2], vendor); } + /*endif*/ } + /*endfor*/ } + /*endfor*/ printf("\nTry a decode of a full NSF string\n"); t35_decode((uint8_t *) "\x00\x00\x0E\x00\x00\x00\x96\x0F\x01\x02\x00\x10\x05\x02\x95\xC8\x08\x01\x49\x02\x41\x53\x54\x47", diff --git a/tests/t38_core_tests.c b/tests/t38_core_tests.c index 21c131bf..6fa169da 100644 --- a/tests/t38_core_tests.c +++ b/tests/t38_core_tests.c @@ -106,6 +106,7 @@ static int rx_indicator_handler(t38_core_state_t *s, void *user_data, int indica ok_indicator_packets++; else bad_indicator_packets++; + /*endif*/ //printf("Hit indicator %d\n", indicator); return 0; } @@ -117,6 +118,7 @@ static int rx_data_handler(t38_core_state_t *s, void *user_data, int data_type, ok_data_packets++; else bad_data_packets++; + /*endif*/ msg_list_ptr2 += 2; //printf("Hit data %d, field %d\n", data_type, field_type); return 0; @@ -131,6 +133,7 @@ static int tx_packet_handler(t38_core_state_t *s, void *user_data, const uint8_t span_log(t38_core_get_logging_state(s), SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count); if (t38_core_rx_ifp_packet(t, buf, len, seq_no) < 0) succeeded = false; + /*endif*/ seq_no++; return 0; } @@ -170,7 +173,9 @@ static int encode_decode_tests(t38_core_state_t *a, t38_core_state_t *b) msg_list_ptr--; break; } + /*endif*/ } + /*endfor*/ /* Try all the data types, as single field messages with no data */ for (i = 0; i < 100; i++) @@ -185,10 +190,14 @@ static int encode_decode_tests(t38_core_state_t *a, t38_core_state_t *b) msg_list_ptr -= 2; break; } + /*endif*/ } + /*endfor*/ if (j == 0) break; + /*endif*/ } + /*endfor*/ /* Try all the data types and field types, as single field messages with data */ for (i = 0; i < 100; i++) @@ -203,10 +212,14 @@ static int encode_decode_tests(t38_core_state_t *a, t38_core_state_t *b) msg_list_ptr -= 2; break; } + /*endif*/ } + /*endfor*/ if (j == 0) break; + /*endif*/ } + /*endfor*/ /* Try all the data types and field types, as multi-field messages, but with 0 fields */ for (i = 0; i < 100; i++) @@ -216,10 +229,13 @@ static int encode_decode_tests(t38_core_state_t *a, t38_core_state_t *b) skip = 1; if (t38_core_send_data_multi_field(a, i, field, 0, T38_PACKET_CATEGORY_CONTROL_DATA) < 0) break; + /*endif*/ } if (j == 0) break; + /*endif*/ } + /*endfor*/ /* Try all the data types and field types, as multi-field messages */ for (i = 0; i < 100; i++) @@ -246,10 +262,14 @@ static int encode_decode_tests(t38_core_state_t *a, t38_core_state_t *b) msg_list_ptr -= 4; break; } + /*endif*/ } + /*endfor*/ if (j == 0) break; + /*endif*/ } + /*endfor*/ printf("Indicator packets: OK = %d, bad = %d\n", ok_indicator_packets, bad_indicator_packets); printf("Data packets: OK = %d, bad = %d\n", ok_data_packets, bad_data_packets); @@ -262,11 +282,13 @@ static int encode_decode_tests(t38_core_state_t *a, t38_core_state_t *b) printf("Tests failed\n"); return -1; } + /*endif*/ if (ok_data_packets != 288 || bad_data_packets != 0) { printf("Tests failed\n"); return -1; } + /*endif*/ } else { @@ -275,17 +297,21 @@ static int encode_decode_tests(t38_core_state_t *a, t38_core_state_t *b) printf("Tests failed\n"); return -1; } + /*endif*/ if (ok_data_packets != 720 || bad_data_packets != 0) { printf("Tests failed\n"); return -1; } + /*endif*/ } + /*endif*/ if (missing_packets > 0) { printf("Tests failed\n"); return -1; } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -315,7 +341,9 @@ static int encode_then_decode_tests(t38_core_state_t *a, t38_core_state_t *b) msg_list_ptr--; break; } + /*endif*/ } + /*endfor*/ /* Try all the data types, as single field messages with no data */ for (i = 0; i < 100; i++) @@ -330,10 +358,14 @@ static int encode_then_decode_tests(t38_core_state_t *a, t38_core_state_t *b) msg_list_ptr -= 2; break; } + /*endif*/ } + /*endfor*/ if (j == 0) break; + /*endif*/ } + /*endfor*/ /* Try all the data types and field types, as single field messages with data */ for (i = 0; i < 100; i++) @@ -348,10 +380,13 @@ static int encode_then_decode_tests(t38_core_state_t *a, t38_core_state_t *b) msg_list_ptr -= 2; break; } + /*endif*/ } if (j == 0) break; + /*endif*/ } + /*endfor*/ /* Try all the data types and field types, as multi-field messages, but with 0 fields */ for (i = 0; i < 100; i++) @@ -361,10 +396,13 @@ static int encode_then_decode_tests(t38_core_state_t *a, t38_core_state_t *b) skip = 1; if (t38_core_send_data_multi_field(a, i, field, 0, T38_PACKET_CATEGORY_CONTROL_DATA) < 0) break; + /*endif*/ } if (j == 0) break; + /*endif*/ } + /*endfor*/ /* Try all the data types and field types, as multi-field messages */ for (i = 0; i < 100; i++) @@ -391,18 +429,24 @@ static int encode_then_decode_tests(t38_core_state_t *a, t38_core_state_t *b) msg_list_ptr -= 4; break; } + /*endif*/ } + /*endfor*/ if (j == 0) break; + /*endif*/ } + /*endfor*/ /* Now split up the big concatented block of IFP packets. */ for (i = 0, seq_no = 0; i < concat_len; i += len) { if ((len = t38_core_rx_ifp_stream(b, &concat[i], concat_len - i, seq_no)) < 0) succeeded = false; + /*endif*/ seq_no++; } + /*endif*/ printf("Indicator packets: OK = %d, bad = %d\n", ok_indicator_packets, bad_indicator_packets); printf("Data packets: OK = %d, bad = %d\n", ok_data_packets, bad_data_packets); @@ -415,11 +459,13 @@ static int encode_then_decode_tests(t38_core_state_t *a, t38_core_state_t *b) printf("Tests failed\n"); return -1; } + /*endif*/ if (ok_data_packets != 288 || bad_data_packets != 0) { printf("Tests failed\n"); return -1; } + /*endif*/ } else { @@ -428,17 +474,21 @@ static int encode_then_decode_tests(t38_core_state_t *a, t38_core_state_t *b) printf("Tests failed\n"); return -1; } + /*endif*/ if (ok_data_packets != 720 || bad_data_packets != 0) { printf("Tests failed\n"); return -1; } + /*endif*/ } + /*endif*/ if (missing_packets > 0) { printf("Tests failed\n"); return -1; } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -461,10 +511,13 @@ static int attack_tests(t38_core_state_t *s, int packets) { for (j = 0; j < len; j++) buf[j] = (rand() >> 16) & 0xFF; + /*endfor*/ t38_core_rx_ifp_packet(s, buf, len, seq_no); seq_no = (seq_no + 1) & 0xFFFF; } + /*endfor*/ } + /*endfor*/ return 0; } @@ -492,7 +545,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ /* Tests in UDP type mode, for UDPTL and RTP */ for (t38_version = 0; t38_version < 2; t38_version++) @@ -512,6 +567,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Cannot start the T.38 core\n"); exit(2); } + /*endif*/ if ((t38_core_b = t38_core_init(&t38_core_bx, rx_indicator_handler, rx_data_handler, @@ -523,6 +579,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Cannot start the T.38 core\n"); exit(2); } + /*endif*/ t38_set_t38_version(t38_core_a, t38_version); t38_set_t38_version(t38_core_b, t38_version); @@ -538,6 +595,7 @@ int main(int argc, char *argv[]) printf("Encode/decode tests failed\n"); exit(2); } + /*endif*/ if ((t38_core_a = t38_core_init(&t38_core_ax, rx_indicator_attack_handler, @@ -550,6 +608,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Cannot start the T.38 core\n"); exit(2); } + /*endif*/ t38_set_t38_version(t38_core_a, t38_version); @@ -561,7 +620,9 @@ int main(int argc, char *argv[]) printf("Attack tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ /* Tests in TCP without TPKT mode, like T.38 version 0 */ for (t38_version = 0; t38_version < 2; t38_version++) @@ -582,6 +643,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Cannot start the T.38 core\n"); exit(2); } + /*endif*/ if ((t38_core_b = t38_core_init(&t38_core_bx, rx_indicator_handler, rx_data_handler, @@ -593,6 +655,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Cannot start the T.38 core\n"); exit(2); } + /*endif*/ t38_set_t38_version(t38_core_a, t38_version); t38_set_t38_version(t38_core_b, t38_version); @@ -614,6 +677,7 @@ int main(int argc, char *argv[]) printf("Encode then decode tests failed\n"); exit(2); } + /*endif*/ if ((t38_core_a = t38_core_init(&t38_core_ax, rx_indicator_attack_handler, @@ -626,6 +690,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Cannot start the T.38 core\n"); exit(2); } + /*endif*/ t38_set_t38_version(t38_core_a, t38_version); @@ -641,7 +706,9 @@ int main(int argc, char *argv[]) printf("Attack tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ /* Tests in TCP with TPKT mode, like T.38 versions >0 */ for (t38_version = 0; t38_version < 2; t38_version++) @@ -662,6 +729,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Cannot start the T.38 core\n"); exit(2); } + /*endif*/ if ((t38_core_b = t38_core_init(&t38_core_bx, rx_indicator_handler, rx_data_handler, @@ -673,6 +741,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Cannot start the T.38 core\n"); exit(2); } + /*endif*/ t38_set_t38_version(t38_core_a, t38_version); t38_set_t38_version(t38_core_b, t38_version); @@ -694,6 +763,7 @@ int main(int argc, char *argv[]) printf("Encode then decode tests failed\n"); exit(2); } + /*endif*/ if ((t38_core_a = t38_core_init(&t38_core_ax, rx_indicator_attack_handler, @@ -706,6 +776,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Cannot start the T.38 core\n"); exit(2); } + /*endif*/ t38_set_t38_version(t38_core_a, t38_version); t38_set_pace_transmission(t38_core_a, false); @@ -720,13 +791,16 @@ int main(int argc, char *argv[]) printf("Attack tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ if (!succeeded) { printf("Tests failed\n"); exit(2); } + /*endif*/ printf("Tests passed\n"); return 0; } diff --git a/tests/t38_non_ecm_buffer_tests.c b/tests/t38_non_ecm_buffer_tests.c index 4ed2bcf7..0c22bacf 100644 --- a/tests/t38_non_ecm_buffer_tests.c +++ b/tests/t38_non_ecm_buffer_tests.c @@ -86,13 +86,16 @@ static int xxx(t38_non_ecm_buffer_state_t *s, logging_state_t *l, int log_bits, bit = t38_non_ecm_buffer_get_bit((void *) s); if (log_bits) printf("Rx bit %d - %d\n", bit_no, bit); + /*endif*/ if (bit != expected) { printf("Tests failed - %d %d %d\n", bit_no, bit, expected); exit(2); } + /*endif*/ bit_no++; } + /*endfor*/ } else { @@ -102,10 +105,12 @@ static int xxx(t38_non_ecm_buffer_state_t *s, logging_state_t *l, int log_bits, bit = t38_non_ecm_buffer_get_bit((void *) s); if (log_bits) printf("Rx bit %d - %d\n", bit_no, bit); + /*endif*/ if (j < 0) { if (bit == 1) j = 18*8 - 5; + /*endif*/ } else { @@ -115,15 +120,21 @@ static int xxx(t38_non_ecm_buffer_state_t *s, logging_state_t *l, int log_bits, printf("Tests failed - %d %d %d\n", bit_no, bit, expected); exit(2); } + /*endif*/ j++; if (j >= 18*8) j = 0; + /*endif*/ } + /*endif*/ bit_no++; if (j == 17*8) return 0; + /*endif*/ } + /*endfor*/ } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -151,18 +162,22 @@ int main(int argc, char *argv[]) printf(" We should get ones here\n"); for (i = 0; i < 17; i++) xxx(&buffer, &logging, log_bits, i, 1); + /*endfor*/ printf(" We should change to zeros here\n"); xxx(&buffer, &logging, log_bits, i, 0); for (i = 0; i < 17; i++) xxx(&buffer, &logging, log_bits, i, 0); + /*endfor*/ printf(" We should get the first row here\n"); xxx(&buffer, &logging, log_bits, i, -1); for (i = 0; i < 17; i++) xxx(&buffer, &logging, log_bits, i, 0); + /*endfor*/ printf(" We should get the second row here\n"); xxx(&buffer, &logging, log_bits, i, -1); for (i = 0; i < 17; i++) xxx(&buffer, &logging, log_bits, i, 0); + /*endfor*/ printf(" We should get the third row here\n"); xxx(&buffer, &logging, log_bits, i, -1); printf(" Done\n"); @@ -189,6 +204,7 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n, bit); + /*endif*/ n++; if (bit == SIG_STATUS_END_OF_DATA) { @@ -197,8 +213,10 @@ int main(int argc, char *argv[]) printf("Tests failed\n"); exit(2); } + /*endif*/ break; } + /*endif*/ if (n >= 18 && n <= 96) { if (bit == (n & 1)) @@ -206,6 +224,7 @@ int main(int argc, char *argv[]) printf("Tests failed\n"); exit(2); } + /*endif*/ } else if (n >= 178 && n <= 256) { @@ -214,6 +233,7 @@ int main(int argc, char *argv[]) printf("Tests failed\n"); exit(2); } + /*endif*/ } else if (n == 139 || n == 300) { @@ -222,6 +242,7 @@ int main(int argc, char *argv[]) printf("Tests failed\n"); exit(2); } + /*endif*/ } else { @@ -230,8 +251,11 @@ int main(int argc, char *argv[]) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endif*/ } + /*endfor*/ t38_non_ecm_buffer_report_input_status(&buffer, &logging); t38_non_ecm_buffer_report_output_status(&buffer, &logging); t38_non_ecm_buffer_release(&buffer); @@ -255,6 +279,7 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n, bit); + /*endif*/ n++; if (bit == SIG_STATUS_END_OF_DATA) { @@ -263,8 +288,10 @@ int main(int argc, char *argv[]) printf("Tests failed\n"); exit(2); } + /*endif*/ break; } + /*endif*/ if (n >= 18 && n <= 96) { if (bit == (n & 1)) @@ -272,6 +299,7 @@ int main(int argc, char *argv[]) printf("Tests failed\n"); exit(2); } + /*endif*/ } else if (n >= 834 && n <= 912) { @@ -280,6 +308,7 @@ int main(int argc, char *argv[]) printf("Tests failed\n"); exit(2); } + /*endif*/ } else if (n == 429 || n == 1238) { @@ -288,6 +317,7 @@ int main(int argc, char *argv[]) printf("Tests failed\n"); exit(2); } + /*endif*/ } else { @@ -296,8 +326,11 @@ int main(int argc, char *argv[]) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endif*/ } + /*endfor*/ t38_non_ecm_buffer_report_input_status(&buffer, &logging); t38_non_ecm_buffer_report_output_status(&buffer, &logging); t38_non_ecm_buffer_release(&buffer); @@ -311,12 +344,15 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if (bit != 1) { printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ printf(" Initial ones OK\n"); /* Now put some zeros into the buffer, but no EOL. We should continue getting ones out. */ @@ -327,12 +363,15 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if (bit != 1) { printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ printf(" Continuing initial ones OK\n"); /* Now add a one, to make an EOL. We should see the zeros come out. */ buf[0] = 0x01; @@ -342,12 +381,15 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if (bit != 0) { printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ printf(" First EOL caused zeros to output OK\n"); /* Now add another line. We should see the first line come out. This means just the 23rd bit from now will be a one. */ @@ -359,12 +401,15 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if ((i == 23 && bit == 0) || (i != 23 && bit != 0)) { printf("Tests failed (%d)\n", i); exit(2); } + /*endif*/ } + /*endfor*/ printf(" Second EOL caused the first row to output OK\n"); /* Now inject an RTC - 6 EOLs */ memset(buf, 0, sizeof(buf)); @@ -375,6 +420,7 @@ int main(int argc, char *argv[]) buf[i + 1] = 0x10; buf[i + 2] = 0x01; } + /*endfor*/ /* T.4 2D style */ buf[25 + 0] = 0x00; buf[25 + 1] = 0x18; @@ -393,6 +439,7 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if (i == 7 || i == 400 + 11 + 0*12 @@ -436,6 +483,7 @@ int main(int argc, char *argv[]) printf("Tests failed (%d)\n", i); exit(2); } + /*endif*/ } else { @@ -444,8 +492,11 @@ int main(int argc, char *argv[]) printf("Tests failed (%d)\n", i); exit(2); } + /*endif*/ } + /*endif*/ } + /*endfor*/ printf(" RTC output OK\n"); t38_non_ecm_buffer_report_input_status(&buffer, &logging); t38_non_ecm_buffer_report_output_status(&buffer, &logging); @@ -465,12 +516,15 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if (bit != 1) { printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ printf(" Initial ones OK\n"); /* Now add a one, to make an EOL. We should see the zeros come out. */ buf[0] = 0x01; @@ -480,12 +534,15 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if (bit != 0) { printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ printf(" First EOL caused zeros to output OK\n"); /* Now add another line. We should see the first line come out. This means just the 23rd bit from now will be a one. */ @@ -497,12 +554,15 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if ((i == 23 && bit == 0) || (i != 23 && bit != 0)) { printf("Tests failed (%d)\n", i); exit(2); } + /*endif*/ } + /*endfor*/ printf(" Second EOL caused the first row to output OK\n"); /* Now inject an RTC - 6 EOLs */ memset(buf, 0, sizeof(buf)); @@ -513,6 +573,7 @@ int main(int argc, char *argv[]) buf[i + 1] = 0x10; buf[i + 2] = 0x01; } + /*endif*/ /* T.4 2D style */ buf[25 + 0] = 0x00; buf[25 + 1] = 0x18; @@ -531,6 +592,7 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if (i == 7 || i == 400 + 11 + 0*12 @@ -574,6 +636,7 @@ int main(int argc, char *argv[]) printf("Tests failed (%d)\n", i); exit(2); } + /*endif*/ } else { @@ -582,8 +645,11 @@ int main(int argc, char *argv[]) printf("Tests failed (%d)\n", i); exit(2); } + /*endif*/ } + /*endif*/ } + /*endfor*/ printf(" RTC output OK\n"); t38_non_ecm_buffer_report_input_status(&buffer, &logging); t38_non_ecm_buffer_report_output_status(&buffer, &logging); @@ -598,12 +664,15 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if (bit != 1) { printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ printf(" Initial ones from an empty TCF buffer OK\n"); /* Now send some TCF through, and see that it comes out */ memset(buf, 0x00, sizeof(buf)); @@ -614,22 +683,27 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if (bit != 0) { printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ printf(" Passthrough of TCF OK\n"); /* Check the right number of bits was buffered */ bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if (bit != SIG_STATUS_END_OF_DATA) { printf("Tests failed\n"); exit(2); } + /*endif*/ printf(" End of data seen OK\n"); t38_non_ecm_buffer_report_input_status(&buffer, &logging); t38_non_ecm_buffer_report_output_status(&buffer, &logging); @@ -644,12 +718,15 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if (bit != 1) { printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ printf(" Initial ones from an empty TCF buffer OK\n"); /* Now send some initial ones, and see that we continue to get all ones @@ -661,12 +738,15 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if (bit != 1) { printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ printf(" Sustaining ones OK\n"); /* Now send some initial ones, and some TCF through, and see that only @@ -682,22 +762,27 @@ int main(int argc, char *argv[]) bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if ((i < 4 && bit == 0) || (i >= 4 && bit != 0)) { printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ printf(" Passthrough of TCF OK\n"); /* Check the right number of bits was buffered */ bit = t38_non_ecm_buffer_get_bit((void *) &buffer); if (log_bits) printf("Rx bit %d - %d\n", n++, bit); + /*endif*/ if (bit != SIG_STATUS_END_OF_DATA) { printf("Tests failed\n"); exit(2); } + /*endif*/ printf(" End of data seen OK\n"); t38_non_ecm_buffer_report_input_status(&buffer, &logging); t38_non_ecm_buffer_report_output_status(&buffer, &logging); diff --git a/tests/t42_tests.c b/tests/t42_tests.c index 03f0e403..19b7167d 100644 --- a/tests/t42_tests.c +++ b/tests/t42_tests.c @@ -92,8 +92,11 @@ static int t85_row_write_handler(void *user_data, const uint8_t buf[], size_t le data5[data5_ptr + 3*(8*i + j)] |= bit_mask; else data5[data5_ptr + 3*(8*i + j)] &= ~bit_mask; + /*endif*/ } + /*endfor*/ } + /*endfor*/ data5_ptr += 3*8*len; write_row++; return 0; @@ -106,6 +109,7 @@ static int t85_comment_handler(void *user_data, const uint8_t buf[], size_t len) printf("Comment (%lu): %s\n", (unsigned long int) len, buf); else printf("Comment (%lu): ---\n", (unsigned long int) len); + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -172,11 +176,13 @@ int main(int argc, char *argv[]) printf("Unable to open '%s'!\n", source_file); return 1; } + /*endif*/ if (TIFFSetDirectory(tif, (tdir_t) 0) < 0) { printf("Unable to set directory '%s'!\n", source_file); return 1; } + /*endif*/ w = 0; TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &w); @@ -212,6 +218,7 @@ int main(int argc, char *argv[]) colour_map[3*i + 2] = (map_b[i] >> 8) & 0xFF; printf("Map %3d - %5d %5d %5d\n", i, colour_map[3*i], colour_map[3*i + 1], colour_map[3*i + 2]); } + /*endfor*/ #else /* Sweep the colormap in the order that seems to work for l04x_02x.tif */ for (i = 0; i < (1 << bits_per_pixel); i++) @@ -220,6 +227,7 @@ int main(int argc, char *argv[]) colour_map[256 + i] = (map_a[i] >> 8) & 0xFF; colour_map[2*256 + i] = (map_b[i] >> 8) & 0xFF; } + /*endfor*/ #endif lab_params_t lab; @@ -229,11 +237,13 @@ int main(int argc, char *argv[]) lab_to_srgb(&lab, colour_map, colour_map, 256); for (i = 0; i < (1 << bits_per_pixel); i++) printf("Map %3d - %5d %5d %5d\n", i, colour_map[3*i], colour_map[3*i + 1], colour_map[3*i + 2]); + /*endfor*/ } else { printf("There is no colour map\n"); } + /*endif*/ process_raw = false; printf("Compression is "); switch (compression) @@ -268,6 +278,7 @@ int main(int argc, char *argv[]) printf("Unexpected compression %d\n", compression); break; } + /*endswitch*/ outsize = 0; if (process_raw) @@ -284,14 +295,17 @@ int main(int argc, char *argv[]) printf("JPEG tables %u\n", jpeg_table_len); printf("YYY %d - %x %x %x %x\n", jpeg_table_len, jpeg_table[0], jpeg_table[1], jpeg_table[2], jpeg_table[3]); } + /*endif*/ for (i = 0, total_image_len = 0; i < nstrips; i++) total_image_len += TIFFRawStripSize(tif, i); + /*endfor*/ if ((data = malloc(total_image_len)) == NULL) { printf("Failed to allocate buffer\n"); exit(2); } + /*endif*/ for (i = 0, total_len = 0; i < nstrips; i++, total_len += len) { if ((len = TIFFReadRawStrip(tif, i, &data[total_len], total_image_len - total_len)) < 0) @@ -299,12 +313,16 @@ int main(int argc, char *argv[]) printf("TIFF read error.\n"); return -1; } + /*endif*/ } + /*endfor*/ if (jpeg_table_len > 0) memcpy(data, jpeg_table, jpeg_table_len - 2); + /*endif*/ if (total_len != total_image_len) printf("Size mismatch %ld %ld\n", (long int) total_len, (long int) total_image_len); + /*endif*/ off = total_len; switch (compression) { @@ -316,11 +334,13 @@ int main(int argc, char *argv[]) printf("T.85 image %ld bytes\n", (long int) total_len); for (i = 0; i < 16; i++) printf("0x%02x\n", data[i]); + /*endif*/ t85_decode_init(&t85_dec, t85_row_write_handler, NULL); t85_decode_set_comment_handler(&t85_dec, 1000, t85_comment_handler, NULL); result = t85_decode_put(&t85_dec, data, total_len); if (result == T4_DECODE_MORE_DATA) result = t85_decode_put(&t85_dec, NULL, 0); + /*endif*/ len = t85_decode_get_compressed_image_size(&t85_dec); printf("Compressed image is %d bytes, %d rows\n", len/8, write_row); t85_decode_release(&t85_dec); @@ -353,8 +373,11 @@ int main(int argc, char *argv[]) { break; } + /*endif*/ } + /*endfor*/ } + /*endif*/ bit_mask = 0x80; t85_decode_init(&t85_dec, t85_row_write_handler, NULL); @@ -378,11 +401,13 @@ int main(int argc, char *argv[]) len = t85_decode_get_compressed_image_size(&t85_dec); printf("Compressed image is %d bytes, %d rows\n", len/8, write_row); } + /*endfor*/ if (result == T4_DECODE_MORE_DATA) { printf("More\n"); result = t85_decode_put(&t85_dec, NULL, 0); } + /*endif*/ len = t85_decode_get_compressed_image_size(&t85_dec); printf("Compressed image is %d bytes, %d rows\n", len/8, write_row); t85_decode_release(&t85_dec); @@ -395,12 +420,14 @@ int main(int argc, char *argv[]) data5[j + 1] = colour_map[3*i + 1]; data5[j + 2] = colour_map[3*i + 2]; } + /*endfor*/ if ((tif = TIFFOpen(OUT_FILE_NAME, "w")) == NULL) { printf("Unable to open '%s'!\n", OUT_FILE_NAME); return 1; } + /*endif*/ TIFFSetField(tif, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE); TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, w); // libtiff requires IMAGELENGTH to be set before SAMPLESPERPIXEL, @@ -426,12 +453,14 @@ int main(int argc, char *argv[]) { TIFFWriteScanline(tif, data5 + off, i, 0); } + /*endfor*/ TIFFWriteDirectory(tif); TIFFClose(tif); return 0; case COMPRESSION_JPEG: break; } + /*endswitch*/ } else { @@ -453,8 +482,10 @@ int main(int argc, char *argv[]) { if (TIFFReadScanline(tif, data + off, row, 0) < 0) return 1; + /*endif*/ off += bytes_per_row; } + /*endfor*/ printf("total %u, off %ld\n", totdata, (long int) off); /* We now have the image in memory in RGB form */ @@ -493,18 +524,22 @@ int main(int argc, char *argv[]) set_lab_gamut(&lab_param, 0, 100, -85, 85, -75, 125, false); break; } + /*endswitch*/ //if (!t42_srgb_to_itulab_jpeg(logging, &lab_param, (tdata_t) &outptr, &outsize, data, off, w, h, 3)) { printf("Failed to convert to ITULAB\n"); return 1; } + /*endif*/ end = rdtscll(); printf("Duration %" PRIu64 "\n", end - start); free(data); data = (uint8_t *) outptr; off = outsize; } + /*endif*/ } + /*endif*/ TIFFClose(tif); printf("XXX - image is %d by %d, %ld bytes\n", w, h, (long int) off); @@ -516,6 +551,7 @@ int main(int argc, char *argv[]) printf("Unable to open '%s'!\n", OUT_FILE_NAME); return 1; } + /*endif*/ TIFFSetField(tif, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE); TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, w); /* libtiff requires IMAGELENGTH to be set before SAMPLESPERPIXEL, @@ -548,6 +584,7 @@ int main(int argc, char *argv[]) #endif if (YCbCrSubsampleHoriz || YCbCrSubsampleVert) TIFFSetField(tif, TIFFTAG_YCBCRSUBSAMPLING, YCbCrSubsampleHoriz, YCbCrSubsampleVert); + /*endif*/ bytes_per_row = (bits_per_pixel + 7)/8; bytes_per_row *= w*samples_per_pixel; totdata = h*bytes_per_row; @@ -567,6 +604,7 @@ int main(int argc, char *argv[]) printf("Failed to convert from ITULAB\n"); return 1; } + /*endif*/ free(data); #else if ((data2 = malloc(totdata)) == NULL) @@ -574,12 +612,14 @@ int main(int argc, char *argv[]) printf("Failed to allocate buffer\n"); exit(2); } + /*endif*/ start = rdtscll(); //if (!t42_itulab_jpeg_to_srgb(logging, &lab_param, data2, &off, data, off, &w, &h, &samples_per_pixel)) { printf("Failed to convert from ITULAB\n"); return 1; } + /*endif*/ end = rdtscll(); printf("Duration %" PRIu64 "\n", end - start); free(data); @@ -591,8 +631,10 @@ int main(int argc, char *argv[]) { if (TIFFWriteScanline(tif, data2 + off, row, 0) < 0) return 1; + /*endif*/ off += bytes_per_row; } + /*endfor*/ #endif free(data2); } @@ -607,13 +649,16 @@ int main(int argc, char *argv[]) #endif if (YCbCrSubsampleHoriz || YCbCrSubsampleVert) TIFFSetField(tif, TIFFTAG_YCBCRSUBSAMPLING, YCbCrSubsampleHoriz, YCbCrSubsampleVert); + /*endif*/ if (TIFFWriteRawStrip(tif, 0, (tdata_t) data, off) == -1) { printf("Write error to TIFF file\n"); return 1; } + /*endif*/ free(data); } + /*endif*/ TIFFWriteDirectory(tif); TIFFClose(tif); printf("Done!\n"); diff --git a/tests/t43_tests.c b/tests/t43_tests.c index 8c61f41b..c6e7bc97 100644 --- a/tests/t43_tests.c +++ b/tests/t43_tests.c @@ -152,6 +152,7 @@ static int t85_comment_handler(void *user_data, const uint8_t buf[], size_t len) printf("Comment (%lu): %s\n", (unsigned long int) len, buf); else printf("Comment (%lu): ---\n", (unsigned long int) len); + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -231,6 +232,7 @@ int write_file(meta_t *meta, int page, const uint8_t buf[]) { if (TIFFWriteRawStrip(tif, 0, (tdata_t) buf, meta->compressed_image_len) < 0) printf("Error writing TIFF strip.\n"); + /*endif*/ } else { @@ -254,16 +256,20 @@ int write_file(meta_t *meta, int page, const uint8_t buf[]) { if (out_buf) free(out_buf); + /*endif*/ return -1; } + /*endif*/ out_buf = out_buf2; } + /*endif*/ chunk_len = t85_encode_get(&t85, &out_buf[out_len], 50000); out_len += chunk_len; } while (chunk_len > 0); if (TIFFWriteRawStrip(tif, 0, out_buf, out_len) < 0) printf("Error writing TIFF strip.\n"); + /*endif*/ t85_encode_release(&t85); free(out_buf); break; @@ -283,16 +289,20 @@ int write_file(meta_t *meta, int page, const uint8_t buf[]) { if (out_buf) free(out_buf); + /*endif*/ return -1; } + /*endif*/ out_buf = out_buf2; } + /*endif*/ chunk_len = t43_encode_get(&t43, &out_buf[out_len], 50000); out_len += chunk_len; } while (chunk_len > 0); if (TIFFWriteRawStrip(tif, 0, out_buf, out_len) < 0) printf("Error writing TIFF strip.\n"); + /*endif*/ t43_encode_release(&t43); free(out_buf); break; @@ -302,13 +312,18 @@ int write_file(meta_t *meta, int page, const uint8_t buf[]) { if (TIFFWriteScanline(tif, (tdata_t) &buf[off], i, 0) < 0) printf("Error writing TIFF scan line.\n"); + /*endif*/ } + /*endfor*/ break; } + /*endswitch*/ } + /*endif*/ if (!TIFFWriteDirectory(tif)) printf("Failed to write directory.\n"); + /*endif*/ #if defined(SPANDSP_SUPPORT_TIFF_FX) && defined(HAVE_TIF_DIR_H) if (!TIFFCreateCustomDirectory(tif, &tiff_fx_field_array)) @@ -325,11 +340,15 @@ int write_file(meta_t *meta, int page, const uint8_t buf[]) if (!TIFFSetDirectory(tif, (tdir_t) page)) printf("Failed to set directory.\n"); + /*endif*/ if (!TIFFSetField(tif, TIFFTAG_GLOBALPARAMETERSIFD, diroff)) printf("Failed to set global parameters IFD.\n"); + /*endif*/ if (!TIFFWriteDirectory(tif)) printf("Failed to write directory.\n"); + /*endif*/ } + /*endif*/ #endif return 0; } @@ -372,6 +391,7 @@ int read_file(meta_t *meta, int page) printf("Unable to set TIFF directory %d!\n", page); return -1; } + /*endif*/ meta->image_width = 0; TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &meta->image_width); meta->image_length = 0; @@ -419,6 +439,7 @@ int read_file(meta_t *meta, int page) meta->bmax = 0.0f; break; } + /*endswitch*/ #if defined(SPANDSP_SUPPORT_TIFF_FX) && defined(HAVE_TIF_DIR_H) if (TIFFGetField(tif, TIFFTAG_DECODE, &parm16, &fl_parms)) { @@ -430,6 +451,7 @@ int read_file(meta_t *meta, int page) meta->bmax = fl_parms[5]; printf("Got decode tag %f %f %f %f %f %f\n", meta->lmin, meta->lmax, meta->amin, meta->amax, meta->bmin, meta->bmax); } + /*endif*/ #endif #if defined(SPANDSP_SUPPORT_TIFF_FX) && defined(HAVE_TIF_DIR_H) @@ -445,38 +467,51 @@ int read_file(meta_t *meta, int page) { if (TIFFGetField(tif, TIFFTAG_PROFILETYPE, &parm32)) printf(" Profile type %u\n", parm32); + /*endif*/ if (TIFFGetField(tif, TIFFTAG_FAXPROFILE, &parm8)) printf(" FAX profile %s (%u)\n", tiff_fx_fax_profiles[parm8], parm8); + /*endif*/ if (TIFFGetField(tif, TIFFTAG_CODINGMETHODS, &parm32)) printf(" Coding methods 0x%x\n", parm32); + /*endif*/ if (TIFFGetField(tif, TIFFTAG_VERSIONYEAR, &u)) { memcpy(uu, u, 4); uu[4] = '\0'; printf(" Version year \"%s\"\n", uu); } + /*endif*/ if (TIFFGetField(tif, TIFFTAG_MODENUMBER, &parm8)) printf(" Mode number %u\n", parm8); + /*endif*/ } + /*endif*/ TIFFSetDirectory(tif, (tdir_t) page); } + /*endif*/ if (TIFFGetField(tif, TIFFTAG_PROFILETYPE, &parm32)) printf("Profile type %u\n", parm32); + /*endif*/ if (TIFFGetField(tif, TIFFTAG_FAXPROFILE, &parm8)) printf("FAX profile %s (%u)\n", tiff_fx_fax_profiles[parm8], parm8); + /*endif*/ if (TIFFGetField(tif, TIFFTAG_CODINGMETHODS, &parm32)) printf("Coding methods 0x%x\n", parm32); + /*endif*/ if (TIFFGetField(tif, TIFFTAG_VERSIONYEAR, &u)) { memcpy(uu, u, 4); uu[4] = '\0'; printf("Version year \"%s\"\n", uu); } + /*endif*/ if (TIFFGetField(tif, TIFFTAG_MODENUMBER, &parm8)) printf("Mode number %u\n", parm8); + /*endif*/ if (TIFFGetField(tif, TIFFTAG_T82OPTIONS, &parm32)) printf("T.82 options 0x%x\n", parm32); + /*endif*/ #endif map_L = NULL; @@ -497,6 +532,7 @@ int read_file(meta_t *meta, int page) meta->colour_map[3*i + 2] = (map_b[i] >> 8) & 0xFF; printf("Map %3d - %5d %5d %5d\n", i, meta->colour_map[3*i], meta->colour_map[3*i + 1], meta->colour_map[3*i + 2]); } + /*endfor*/ #else /* Sweep the colormap in the order that seems to work for l04x_02x.tif */ for (i = 0; i < entries; i++) @@ -505,6 +541,7 @@ int read_file(meta_t *meta, int page) meta->colour_map[256 + i] = (map_a[i] >> 8) & 0xFF; meta->colour_map[2*256 + i] = (map_b[i] >> 8) & 0xFF; } + /*endfor*/ #endif /* The default luminant is D50 */ set_lab_illuminant(&lab_param, 96.422f, 100.000f, 82.521f); @@ -512,8 +549,11 @@ int read_file(meta_t *meta, int page) lab_to_srgb(&lab, meta->colour_map, meta->colour_map, 256); for (i = 0; i < entries; i++) printf("Map %3d - %5d %5d %5d\n", i, meta->colour_map[3*i], meta->colour_map[3*i + 1], meta->colour_map[3*i + 2]); + /*endfor*/ } + /*endif*/ } + /*endif*/ meta->tif = tif; return 0; } @@ -533,8 +573,10 @@ int read_compressed_image(meta_t *meta, uint8_t **buf) { total_len += TIFFRawStripSize(meta->tif, i); } + /*endfor*/ if ((data = malloc(total_len)) == NULL) return -1; + /*endif*/ for (i = 0, read_len = 0; i < num_strips; i++, read_len += len) { if ((len = TIFFReadRawStrip(meta->tif, i, &data[read_len], total_len - read_len)) < 0) @@ -543,7 +585,9 @@ int read_compressed_image(meta_t *meta, uint8_t **buf) free(data); return -1; } + /*endif*/ } + /*endfor*/ *buf = data; return total_len; } @@ -594,6 +638,7 @@ int read_decompressed_image(meta_t *meta, uint8_t **buf) printf("Failed to allocated image buffer\n"); return -1; } + /*endif*/ total_raw = read_compressed_image(meta, &raw_buf); t85_decode_init(&t85, row_write_handler, &pack); t85_decode_set_comment_handler(&t85, 1000, t85_comment_handler, NULL); @@ -606,6 +651,7 @@ int read_decompressed_image(meta_t *meta, uint8_t **buf) result = t85_decode_put(&t85, raw_buf, total_raw); if (result == T4_DECODE_MORE_DATA) result = t85_decode_put(&t85, NULL, 0); + /*endif*/ total_data = t85_decode_get_compressed_image_size(&t85); printf("Compressed image is %d/%d bytes, %d rows\n", total_raw, total_data/8, write_row); t85_decode_release(&t85); @@ -616,10 +662,11 @@ int read_decompressed_image(meta_t *meta, uint8_t **buf) total_data = meta->image_length*bytes_per_row; printf("Total decompressed data %d, %d per row\n", total_data, bytes_per_row); -total_data *= 8; + total_data *= 8; /* Read the image into memory. */ if ((image_buf = malloc(total_data)) == NULL) printf("Failed to allocated image buffer\n"); + /*endif*/ total_raw = read_compressed_image(meta, &raw_buf); t43_decode_init(&t43, row_write_handler, &pack); @@ -633,6 +680,7 @@ total_data *= 8; result = t43_decode_put(&t43, raw_buf, total_raw); if (result == T4_DECODE_MORE_DATA) result = t43_decode_put(&t43, NULL, 0); + /*endif*/ t43_decode_release(&t43); free(raw_buf); @@ -653,7 +701,7 @@ total_data *= 8; /* Read the image into memory. */ if ((image_buf = malloc(total_data)) == NULL) printf("Failed to allocated image buffer\n"); - + /*endif*/ #if 0 jpeg_table_len = 0; if (TIFFGetField(meta->tif, TIFFTAG_JPEGTABLES, &jpeg_table_len, &jpeg_table)) @@ -668,6 +716,7 @@ for (ii = 0; ii < jpeg_table_len; ii++) printf("\n"); } } + /*endif*/ #endif total_raw = read_compressed_image(meta, &raw_buf); //if (!t42_itulab_jpeg_to_srgb(&logging2, &lab_param, (tdata_t) image_buf, &off, raw_buf, total_raw, &w, &h, &samples_per_pixel)) @@ -676,12 +725,14 @@ printf("\n"); free(image_buf); return -1; } + /*endif*/ meta->photometric = PHOTOMETRIC_RGB; #if 0 total_len = 0; if (jpeg_table_len > 0) total_len += jpeg_table_len - 4; + /*endif*/ printf("nstrips %d\n", nstrips); data2 = NULL; @@ -690,17 +741,20 @@ printf("nstrips %d\n", nstrips); total_len = 0; if (jpeg_table_len > 0) total_len += jpeg_table_len - 4; + /*endif*/ if ((len = TIFFReadRawStrip(tif, i, &data[total_len], total_image_len - total_len)) < 0) { printf("TIFF read error.\n"); free(image_buf); return -1; } + /*endif*/ if (jpeg_table_len > 0) { memcpy(data, jpeg_table, jpeg_table_len - 2); printf("%02x %02x %02x %02x\n", data[total_len], data[total_len + 1], data[total_len + 2], data[total_len + 3]); } + /*endif*/ totdata = meta->image_width*3000*meta->samples_per_pixel; data2 = realloc(data2, totdata); off = total_len; @@ -710,15 +764,20 @@ printf("%02x %02x %02x %02x\n", data[total_len], data[total_len + 1], data[total free(image_buf); return -1; } + /*endif*/ } + /*endfor*/ if (data2) free(data2); + /*endif*/ //exit(2); if (jpeg_table_len > 0) memcpy(data, jpeg_table, jpeg_table_len - 2); + /*endif*/ if (total_len != total_image_len) printf("Size mismatch %d %d\n", (int) total_len, (int) total_image_len); + /*endif*/ { int ii; @@ -747,6 +806,7 @@ printf("\n"); /* Read the image into memory. */ if ((image_buf = malloc(total_data)) == NULL) printf("Failed to allocated image buffer\n"); + /*endif*/ for (y = 0; y < meta->image_length; y += meta->tile_length) { @@ -758,19 +818,26 @@ printf("\n"); yyy = meta->tile_length; if (y + meta->tile_length > meta->image_length) yyy = meta->image_length - y; + /*endif*/ xxx = meta->tile_width; if (x + meta->tile_width > meta->image_width) xxx = meta->image_width - x; + /*endif*/ for (yy = 0; yy < yyy; yy++) { for (xx = 0; xx < xxx; xx++) { for (j = 0; j < meta->samples_per_pixel; j++) image_buf[meta->samples_per_pixel*((y + yy)*meta->image_width + x + xx) + j] = data[meta->samples_per_pixel*(yy*meta->tile_width + xx) + j]; + /*endfor*/ } + /*endfor*/ } + /*endfor*/ } + /*endfor*/ } + /*endfor*/ break; case PLANARCONFIG_SEPARATE: bytes_per_row = TIFFScanlineSize(meta->tif); @@ -780,6 +847,7 @@ printf("\n"); /* Read the image into memory. */ if ((image_buf = malloc(total_data)) == NULL) printf("Failed to allocated image buffer\n"); + /*endif*/ for (j = 0; j < meta->samples_per_pixel; j++) { @@ -793,21 +861,29 @@ printf("\n"); yyy = meta->tile_length; if (y + meta->tile_length > meta->image_length) yyy = meta->image_length - y; + /*endif*/ xxx = meta->tile_width; if (x + meta->tile_width > meta->image_width) xxx = meta->image_width - x; + /*endif*/ for (yy = 0; yy < yyy; yy++) { for (xx = 0; xx < xxx; xx++) { image_buf[meta->samples_per_pixel*((y + yy)*meta->image_width + x + xx) + j] = data[yy*meta->tile_width + xx]; } + /*endfor*/ } + /*endfor*/ } + /*endfor*/ } + /*endfor*/ } + /*endfor*/ break; } + /*endswitch*/ } else { @@ -822,6 +898,7 @@ printf("\n"); /* Read the image into memory. */ if ((image_buf = malloc(total_data)) == NULL) printf("Failed to allocated image buffer\n"); + /*endif*/ for (y = 0; y < meta->image_length; y++) { @@ -830,7 +907,9 @@ printf("\n"); free(image_buf); return -1; } + /*endif*/ } + /*endfor*/ break; case PLANARCONFIG_SEPARATE: bytes_per_row = TIFFScanlineSize(meta->tif); @@ -840,6 +919,7 @@ printf("\n"); /* Read the image into memory. */ if ((image_buf = malloc(total_data)) == NULL) printf("Failed to allocated image buffer\n"); + /*endif*/ for (j = 0; j < meta->samples_per_pixel; j++) { @@ -852,13 +932,19 @@ printf("\n"); free(image_buf); return -1; } + /*endif*/ for (x = 0; x < meta->image_width; x++) image_buf[meta->samples_per_pixel*(y*bytes_per_row + x) + j] = data[x]; + /*endfor*/ } + /*endfor*/ } + /*endfor*/ break; } + /*endswitch*/ } + /*endif*/ break; } /* Normalise bi-level images, so they are always in PHOTOMETRIC_MINISWHITE form */ @@ -868,9 +954,12 @@ printf("\n"); { for (i = 0; i < total_data; i++) image_buf[i] = ~image_buf[i]; + /*endfor*/ meta->photometric = PHOTOMETRIC_MINISWHITE; } + /*endif*/ } + /*endif*/ *buf = image_buf; return total_data; @@ -909,7 +998,7 @@ int main(int argc, char *argv[]) source_file = (argc > 1) ? argv[1] : IN_FILE_NAME; printf("Processing '%s'\n", source_file); destination_file = OUT_FILE_NAME; - output_compression = (argc > 2) ? atoi(argv[2]) : COMPRESSION_CCITT_T6; + output_compression = (argc > 2) ? atoi(argv[2]) : COMPRESSION_CCITT_T6; #if defined(SPANDSP_SUPPORT_TIFF_FX) && defined(HAVE_TIF_DIR_H) TIFF_FX_init(); @@ -920,12 +1009,14 @@ int main(int argc, char *argv[]) printf("Unable to open '%s'!\n", source_file); return 1; } + /*endif*/ if ((meta.tif = TIFFOpen(destination_file, "w")) == NULL) { printf("Unable to open '%s'!\n", destination_file); return 1; } + /*endif*/ span_log_init(&logging2, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_FLOW, "lab"); /* The default luminant is D50 */ @@ -942,6 +1033,7 @@ int main(int argc, char *argv[]) TIFFClose(meta.tif); exit(2); } + /*endif*/ tif = in_meta.tif; @@ -954,6 +1046,7 @@ int main(int argc, char *argv[]) { /* It looks like we need to decompress and recompress the image */ } + /*endif*/ printf("Width %d, height %d, bits %d, samples %d\n", in_meta.image_width, in_meta.image_length, in_meta.bits_per_sample, in_meta.samples_per_pixel); @@ -999,8 +1092,10 @@ int main(int argc, char *argv[]) { if ((outptr = malloc(in_meta.image_width*in_meta.image_length)) == NULL) printf("Failed to allocate buffer\n"); + /*endif*/ for (i = 0; i < in_meta.image_width*in_meta.image_length; i++) outptr[i] = data[2*i]; + /*endfor*/ free(data); data = (uint8_t *) outptr; } @@ -1014,6 +1109,7 @@ int main(int argc, char *argv[]) number of bytes. */ if ((outptr = malloc(in_meta.image_width*in_meta.image_length)) == NULL) printf("Failed to allocate buffer\n"); + /*endif*/ bitstream = 0; bits = 0; j = 0; @@ -1024,12 +1120,15 @@ int main(int argc, char *argv[]) bitstream = (bitstream << 8) | data[j++]; bits += 8; } + /*endwhile*/ outptr[i] = bitstream >> (bits - 8); bits -= in_meta.bits_per_sample; } + /*endfor*/ free(data); data = (uint8_t *) outptr; } + /*endif*/ off = in_meta.samples_per_pixel*in_meta.image_width*in_meta.image_length; /* We have finished acquiring the image. Now we need to push it out */ @@ -1046,6 +1145,7 @@ int main(int argc, char *argv[]) write_file(&meta, page_no, data); } + /*endif*/ break; case 3: printf("Photometric is %d\n", in_meta.photometric); @@ -1058,6 +1158,7 @@ int main(int argc, char *argv[]) /* We are already in the ITULAB color space */ if ((outptr = malloc(totdata)) == NULL) printf("Failed to allocate buffer\n"); + /*endif*/ lab_to_srgb(&lab_param, (tdata_t) outptr, data, totdata/3); free(data); data = (uint8_t *) outptr; @@ -1097,12 +1198,14 @@ int main(int argc, char *argv[]) printf("Pack %d to %d\n", totdata, in_meta.samples_per_pixel*in_meta.image_width*in_meta.image_length); if ((outptr = malloc(in_meta.samples_per_pixel*in_meta.image_width*in_meta.image_length)) == NULL) printf("Failed to allocate buffer\n"); + /*endif*/ for (i = 0; i < in_meta.image_width*in_meta.image_length; i++) { outptr[in_meta.samples_per_pixel*i + 0] = (data[in_meta.samples_per_pixel*2*i + 1] << 4) | (data[in_meta.samples_per_pixel*2*i + 0] >> 4); outptr[in_meta.samples_per_pixel*i + 1] = (data[in_meta.samples_per_pixel*2*i + 3] << 4) | (data[in_meta.samples_per_pixel*2*i + 2] >> 4); outptr[in_meta.samples_per_pixel*i + 2] = (data[in_meta.samples_per_pixel*2*i + 5] << 4) | (data[in_meta.samples_per_pixel*2*i + 4] >> 4); } + /*endfor*/ free(data); data = (uint8_t *) outptr; off = in_meta.samples_per_pixel*in_meta.image_width*in_meta.image_length; @@ -1118,6 +1221,7 @@ int main(int argc, char *argv[]) printf("Pack %d to %d\n", totdata, in_meta.samples_per_pixel*in_meta.image_width*in_meta.image_length); if ((outptr = malloc(in_meta.samples_per_pixel*in_meta.image_width*in_meta.image_length)) == NULL) printf("Failed to allocate buffer\n"); + /*endif*/ bitstream = 0; bits = 0; j = 0; @@ -1130,17 +1234,22 @@ int main(int argc, char *argv[]) bitstream = (bitstream << 8) | data[j++]; bits += 8; } + /*endwhile*/ outptr[in_meta.samples_per_pixel*i + k] = bitstream >> (bits - 8); bits -= in_meta.bits_per_sample; } + /*endfor*/ } + /*endfor*/ free(data); data = (uint8_t *) outptr; off = in_meta.samples_per_pixel*in_meta.image_width*in_meta.image_length; in_meta.bits_per_sample = 8; } + /*endif*/ break; } + /*endswitch*/ #if 0 /* The default luminant is D50 */ set_lab_illuminant(&lab_param, 96.422f, 100.000f, 82.521f); @@ -1150,6 +1259,7 @@ int main(int argc, char *argv[]) printf("Failed to convert to ITULAB (B).\n"); return 1; } + /*endif*/ end = rdtscll(); printf("Duration %" PRIu64 "\n", end - start); free(data); @@ -1168,6 +1278,7 @@ int main(int argc, char *argv[]) meta.compression = COMPRESSION_JPEG; meta.photometric = PHOTOMETRIC_RGB; } + /*endif*/ write_file(&meta, page_no, data); break; case 4: @@ -1184,6 +1295,7 @@ int main(int argc, char *argv[]) printf("Failed to convert to ITULAB (C).\n"); return 1; } + /*endif*/ #else outsize = 0; #endif @@ -1213,21 +1325,27 @@ int main(int argc, char *argv[]) k = data[(y*in_meta.image_width + x)*4 + 0] + data[(y*in_meta.image_width + x)*4 + 3]; if (k > 255) k = 255; + /*endif*/ data[(y*in_meta.image_width + x)*3 + 0] = 255 - k; k = data[(y*in_meta.image_width + x)*4 + 1] + data[(y*in_meta.image_width + x)*4 + 3]; if (k > 255) k = 255; + /*endif*/ data[(y*in_meta.image_width + x)*3 + 1] = 255 - k; k = data[(y*in_meta.image_width + x)*4 + 2] + data[(y*in_meta.image_width + x)*4 + 3]; if (k > 255) k = 255; + /*endif*/ data[(y*in_meta.image_width + x)*3 + 2] = 255 - k; } + /*endfor*/ } + /*endfor*/ off = 3*in_meta.image_width*in_meta.image_length; in_meta.bits_per_sample = 8; break; } + /*endswitch*/ /* The default luminant is D50 */ set_lab_illuminant(&lab_param, 96.422f, 100.000f, 82.521f); @@ -1237,11 +1355,13 @@ int main(int argc, char *argv[]) printf("Failed to convert to ITULAB (D).\n"); return 1; } + /*endif*/ end = rdtscll(); printf("Duration %" PRIu64 "\n", end - start); off = outsize; in_meta.bits_per_sample = 8; } + /*endif*/ meta.pre_compressed = false; meta.image_width = in_meta.image_width; meta.image_length = in_meta.image_length; @@ -1256,9 +1376,9 @@ int main(int argc, char *argv[]) write_file(&meta, page_no, data); break; } + /*endswitch*/ } - - + /*endfor*/ printf("XXX - image is %d by %d, %d bytes\n", in_meta.image_width, in_meta.image_length, (int) off); @@ -1293,6 +1413,7 @@ int main(int argc, char *argv[]) printf("Unable to open '%s'!\n", destination_file); return 1; } + /*endif*/ TIFFSetField(tif, TIFFTAG_SUBFILETYPE, FILETYPE_PAGE); TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, meta.image_width); /* libtiff requires IMAGELENGTH to be set before SAMPLESPERPIXEL, @@ -1328,6 +1449,7 @@ int main(int argc, char *argv[]) printf("Write error to TIFF file\n"); return 1; } + /*endif*/ free(data); } else @@ -1348,6 +1470,7 @@ int main(int argc, char *argv[]) printf("Failed to convert from ITULAB (A).\n"); return 1; } + /*endif*/ end = rdtscll(); printf("Duration %" PRIu64 "\n", end - start); printf("Compressed length %d (%p)\n", totdata, data2); @@ -1356,6 +1479,7 @@ int main(int argc, char *argv[]) printf("Failed to convert from ITULAB (B).\n"); return 1; } + /*endif*/ free(data); data = data2; #elif 1 @@ -1364,6 +1488,7 @@ int main(int argc, char *argv[]) printf("Failed to allocate buffer\n"); exit(2); } + /*endif*/ start = rdtscll(); //if (!t42_itulab_jpeg_to_srgb(&logging2, &lab_param, data2, &off, data, off, &meta.image_width, &meta.image_length, &meta.samples_per_pixel)) { @@ -1376,19 +1501,24 @@ int main(int argc, char *argv[]) data = data2; #endif } + /*endif*/ off = 0; bytes_per_row = ((meta.bits_per_sample + 7)/8)*meta.image_width*meta.samples_per_pixel; for (row = 0; row < meta.image_length; row++) { if (TIFFWriteScanline(tif, &data[off], row, 0) < 0) return 1; + /*endif*/ off += bytes_per_row; } + /*endfor*/ free(data); } + /*endif*/ if (!TIFFWriteDirectory(tif)) printf("Failed to write directory.\n"); + /*endif*/ #if defined(SPANDSP_SUPPORT_TIFF_FX) && defined(HAVE_TIF_DIR_H) if (!TIFFCreateCustomDirectory(tif, &tiff_fx_field_array)) @@ -1402,14 +1532,19 @@ int main(int argc, char *argv[]) diroff = 0; if (!TIFFWriteCustomDirectory(tif, &diroff)) printf("Failed to write custom directory.\n"); + /*endif*/ if (!TIFFSetDirectory(tif, (tdir_t) page_no)) printf("Failed to set directory.\n"); + /*endif*/ if (!TIFFSetField(tif, TIFFTAG_GLOBALPARAMETERSIFD, diroff)) printf("Failed to set global parameters IFD.\n"); + /*endif*/ if (!TIFFWriteDirectory(tif)) printf("Failed to write directory.\n"); + /*endif*/ } + /*endif*/ #endif TIFFClose(tif); printf("Done!\n"); diff --git a/tests/t4_t6_tests.c b/tests/t4_t6_tests.c index 476f7375..d4ff8de9 100644 --- a/tests/t4_t6_tests.c +++ b/tests/t4_t6_tests.c @@ -110,9 +110,12 @@ static void dump_image_as_xxx(const uint8_t buf[], int bytes_per_row, int len) { for (k = 0; k < 8; k++) printf((buf[i*bytes_per_row + j] & (0x80 >> k)) ? "X" : " "); + /*endfor*/ } + /*endfor*/ printf("\n"); } + /*endfor*/ } /*- End of function --------------------------------------------------------*/ #endif @@ -130,6 +133,7 @@ static int row_read_handler(void *user_data, uint8_t buf[], size_t len) row = 0; return 0; } + /*endif*/ s = t4_t6_test_patterns[row++]; memset(buf, 0, len); for (i = 0; i < len; i++) @@ -138,10 +142,14 @@ static int row_read_handler(void *user_data, uint8_t buf[], size_t len) { if (*s++ != ' ') buf[i] |= (0x80 >> j); + /*endif*/ } + /*endfor*/ } + /*endfor*/ if (*s) printf("Oops - '%c' at end of row %d\n", *s, row); + /*endif*/ return len; } /*- End of function --------------------------------------------------------*/ @@ -158,9 +166,11 @@ static int row_write_handler(void *user_data, const uint8_t buf[], size_t len) //printf("Row %d\n", row); if (len == 0) return 0; + /*endif*/ s = t4_t6_test_patterns[row++]; if (row >= TEST_ROWS) row = 0; + /*endif*/ memset(ref, 0, len); for (i = 0; i < len; i++) { @@ -168,15 +178,20 @@ static int row_write_handler(void *user_data, const uint8_t buf[], size_t len) { if (*s++ != ' ') ref[i] |= (0x80 >> j); + /*endif*/ } + /*endfor*/ } + /*endfor*/ if (*s) printf("Oops - '%c' at end of row %d\n", *s, row); + /*endif*/ if (memcmp(buf, ref, len)) { printf("Test failed at row %d\n", row); exit(2); } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -209,6 +224,7 @@ static int detect_page_end(int bit, int page_ended) expected_eols = (page_ended == T4_COMPRESSION_T6) ? 2 : 6; return 0; } + /*endif*/ /* Monitor whether the EOLs are there in the correct amount */ if (bit == 0) @@ -226,11 +242,14 @@ static int detect_page_end(int bit, int page_ended) consecutive_eols++; else consecutive_eols = 0; + /*endif*/ consecutive_zeros = 0; consecutive_ones = 0; } + /*endif*/ if (max_consecutive_eols < consecutive_eols) max_consecutive_eols = consecutive_eols; + /*endif*/ } else if (bit == SIG_STATUS_END_OF_DATA) { @@ -241,10 +260,12 @@ static int detect_page_end(int bit, int page_ended) printf("Only %d EOLs (should be %d)\n", max_consecutive_eols, expected_eols); return 2; } + /*endif*/ consecutive_zeros = 0; consecutive_eols = 0; max_consecutive_eols = 0; } + /*endif*/ if (!page_ended) { /* We might need to push a few bits to get the receiver to report the @@ -254,10 +275,13 @@ static int detect_page_end(int bit, int page_ended) printf("Receiver missed the end of page mark\n"); return 2; } + /*endif*/ return 0; } + /*endif*/ return 1; } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -299,6 +323,7 @@ int main(int argc, char *argv[]) block_size = atoi(optarg); if (block_size > 1024) block_size = 1024; + /*endif*/ break; case 'c': if (strcmp(optarg, "T41D") == 0) @@ -316,6 +341,7 @@ int main(int argc, char *argv[]) compression = T4_COMPRESSION_T6; compression_step = -1; } + /*endif*/ break; case 'm': min_row_bits = atoi(optarg); @@ -325,7 +351,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ end_of_page = false; #if 1 @@ -336,6 +364,7 @@ int main(int argc, char *argv[]) printf("Failed to init T.4/T.6 encoder\n"); exit(2); } + /*endif*/ span_log_set_level(t4_t6_encode_get_logging_state(send_state), SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW); t4_t6_encode_set_min_bits_per_row(send_state, min_row_bits); t4_t6_encode_set_max_2d_rows_per_1d_row(send_state, 2); @@ -346,12 +375,14 @@ int main(int argc, char *argv[]) printf("Failed to init T.4/T.6 decoder\n"); exit(2); } + /*endif*/ span_log_set_level(t4_t6_decode_get_logging_state(receive_state), SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW); /* Now send and receive the test data with all compression modes. */ /* If we are stepping around the compression schemes, reset to the start of the sequence. */ if (compression_step > 0) compression_step = 0; + /*endif*/ for (;;) { end_marks = 0; @@ -360,14 +391,18 @@ int main(int argc, char *argv[]) compression = compression_sequence[compression_step++]; if (compression < 0) break; + /*endif*/ } + /*endif*/ t4_t6_encode_set_encoding(send_state, compression); t4_t6_decode_set_encoding(receive_state, compression); if (t4_t6_encode_restart(send_state, 1728, -1)) break; + /*endif*/ if (t4_t6_decode_restart(receive_state, 1728)) break; + /*endif*/ detect_page_end(-1000000, compression); switch (block_size) { @@ -383,11 +418,15 @@ int main(int argc, char *argv[]) printf("Test failed\n"); exit(2); } + /*endif*/ break; } + /*endif*/ if (!end_of_page) end_of_page = t4_t6_decode_put_bit(receive_state, bit & 1); + /*endif*/ } + /*endfor*/ break; default: do @@ -401,17 +440,22 @@ int main(int argc, char *argv[]) tests_failed++; break; } + /*endif*/ chunk_buf[0] = 0xFF; len = 1; } + /*endif*/ end_of_page = t4_t6_decode_put(receive_state, chunk_buf, len); } while (!end_of_page); break; } + /*endswitch*/ if (compression_step < 0) break; + /*endif*/ } + /*endfor*/ t4_t6_encode_free(send_state); t4_t6_decode_free(receive_state); #endif diff --git a/tests/t4_tests.c b/tests/t4_tests.c index 451ecd9a..d551f9e1 100644 --- a/tests/t4_tests.c +++ b/tests/t4_tests.c @@ -414,6 +414,12 @@ int main(int argc, char *argv[]) t4_rx_start_page(receive_state); last_pkt_no = 0; file = fopen(decode_file_name, "r"); + if (file == NULL) + { + printf("file %s not found\n", decode_file_name); + exit(2); + } + /*endif*/ while (fgets(buf, 1024, file)) { if (sscanf(buf, "HDLC: FCD: 06 %x", &pkt_no) == 1) diff --git a/tests/t81_t82_arith_coding_tests.c b/tests/t81_t82_arith_coding_tests.c index 7df59567..1e7ab895 100644 --- a/tests/t81_t82_arith_coding_tests.c +++ b/tests/t81_t82_arith_coding_tests.c @@ -60,6 +60,7 @@ static void write_byte(void *user_data, int byte) { if (msg_len < MSG_SIZE) msg[msg_len++] = byte; + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -103,6 +104,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Failed to allocate arithmetic encoder!\n"); exit(2); } + /*endif*/ msg_len = 0; for (i = 0; i < 16; i++) { @@ -112,21 +114,26 @@ int main(int argc, char *argv[]) (cx_7_1[i] >> (15 - j)) & 1, (pix_7_1[i] >> (15 - j)) & 1); } + /*endfor*/ } + /*endfor*/ t81_t82_arith_encode_flush(se); if (msg_len != SDE_7_1_LEN || memcmp(msg, sde_7_1, SDE_7_1_LEN)) { printf("Encoded data: "); for (i = 0; i < msg_len; i++) printf("%02X", msg[i]); + /*endfor*/ printf("\n"); printf("Expected data: "); for (i = 0; i < SDE_7_1_LEN; i++) printf("%02X", sde_7_1[i]); + /*endfor*/ printf("\n"); printf("Test failed\n"); exit(2); } + /*endif*/ printf("Test passed\n"); printf("Arithmetic decoder tests from ITU-T T.82/7.1\n"); @@ -137,6 +144,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Failed to allocate arithmetic decoder!\n"); exit(2); } + /*endif*/ pp = sde_7_1; sd->pscd_ptr = pp; sd->pscd_end = pp + 1; @@ -149,11 +157,13 @@ int main(int argc, char *argv[]) pix = t81_t82_arith_decode(sd, (cx_7_1[i] >> (15 - j)) & 1); if ((pix >= 0 || sd->pscd_end >= sde_7_1 + SDE_7_1_FULL_LEN)) break; + /*endif*/ pp++; if (sd->pscd_ptr != pp - 1) sd->pscd_ptr = pp; sd->pscd_end = pp + 1; } + /*endfor*/ if (pix < 0) { printf("Bad pixel %d, byte %" PRIdPTR ".\n\n", @@ -162,6 +172,7 @@ int main(int argc, char *argv[]) test_failed = true; break; } + /*endif*/ if (pix != ((pix_7_1[i] >> (15 - j)) & 1)) { printf("Bad PIX (%d) at pixel %d.\n\n", @@ -170,19 +181,24 @@ int main(int argc, char *argv[]) test_failed = true; break; } + /*endif*/ } + /*endfor*/ } + /*endfor*/ if (sd->pscd_ptr != sd->pscd_end - 2) { printf("%" PRIdPTR " bytes left after decoder finished.\n\n", sd->pscd_end - sd->pscd_ptr - 2); test_failed = true; } + /*endif*/ if (test_failed) { printf("Test failed\n"); exit(2); } + /*endif*/ printf("Test passed\n"); printf("Decoding chunk by chunk...\n"); @@ -203,6 +219,7 @@ int main(int argc, char *argv[]) test_failed = true; break; } + /*endif*/ if (pix != ((pix_7_1[i] >> (15 - j)) & 1)) { printf("Bad PIX (%d) at pixel %d.\n\n", @@ -211,19 +228,24 @@ int main(int argc, char *argv[]) test_failed = true; break; } + /*endif*/ } + /*endfor*/ } + /*endfor*/ if (sd->pscd_ptr != sd->pscd_end - 2) { printf("%" PRIdPTR " bytes left after decoder finished.\n\n", sd->pscd_end - sd->pscd_ptr - 2); test_failed = true; } + /*endif*/ if (test_failed) { printf("Test failed\n"); exit(2); } + /*endif*/ printf("Test passed\n"); t81_t82_arith_encode_free(se); t81_t82_arith_decode_free(sd); diff --git a/tests/t85_tests.c b/tests/t85_tests.c index 338fe30c..436dfcaf 100644 --- a/tests/t85_tests.c +++ b/tests/t85_tests.c @@ -75,6 +75,7 @@ static int row_read_handler(void *user_data, uint8_t buf[], size_t len) clip_to_row = 0; return 0; } + /*endif*/ read_row++; return len; } @@ -98,6 +99,7 @@ static int comment_handler(void *user_data, const uint8_t buf[], size_t len) printf("Comment (%lu): %s\n", (unsigned long int) len, buf); else printf("Comment (%lu): ---\n", (unsigned long int) len); + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -138,17 +140,24 @@ static void create_test_image(uint8_t *pic) { repeat[j & 7] = 0; } + /*endif*/ } else { if (repeat[j & 7]) *p |= 1 << (7 - (j & 7)); + /*endif*/ } + /*endif*/ } + /*endif*/ if ((j & 7) == 7) ++p; + /*endif*/ } + /*endfor*/ } + /*endfor*/ /* Verify the test image has been generated OK, by checking the number of set pixels */ sum = 0; @@ -156,12 +165,15 @@ static void create_test_image(uint8_t *pic) { for (j = 0; j < 8; j++) sum += ((pic[i] >> j) & 1); + /*endfor*/ } + /*endfor*/ if (sum != 861965) { printf("WARNING: Test image has %" PRIu32 " foreground pixels. There should be 861965.\n", sum); } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -210,12 +222,14 @@ static int test_cycle(const char *test_id, t85_enc = t85_encode_init(NULL, width, height, row_read_handler, NULL); clip_to_row = 0; } + /*endif*/ read_row = 0; t85_encode_set_options(t85_enc, l0, mx, options); /* A comment inserted here should always succeed. The later one, inserted some way down the image, will only succeed if a new chunk is started afterwards. */ if (comment) t85_encode_comment(t85_enc, comment, strlen((const char *) comment) + 1); + /*endif*/ testbuf_len = 0; max_len = 100; @@ -225,9 +239,12 @@ static int test_cycle(const char *test_id, max_len = 100; if (testbuf_len + 100 > TESTBUF_SIZE) max_len = TESTBUF_SIZE - testbuf_len; + /*endif*/ if (comment && testbuf_len == 1000) t85_encode_comment(t85_enc, comment, strlen((const char *) comment) + 1); + /*endif*/ } + /*endwhile*/ printf("Encoded BIE has %lu bytes\n", (unsigned long int) testbuf_len); if (correct_length > 0) { @@ -237,8 +254,10 @@ static int test_cycle(const char *test_id, printf("Test failed\n"); exit(2); } + /*endif*/ printf("Test passed\n"); } + /*endif*/ cnt_a = t85_encode_get_compressed_image_size(t85_enc); t85_encode_free(t85_enc); @@ -249,13 +268,16 @@ static int test_cycle(const char *test_id, fprintf(stderr, "Out of memory!\n"); exit(2); } + /*endif*/ t85_dec = t85_decode_init(NULL, row_write_handler, decoded_image); if (comment && comment[0] != 'X') t85_decode_set_comment_handler(t85_dec, 1000, comment_handler, NULL); + /*endif*/ write_row = 0; result = t85_decode_put(t85_dec, testbuf, testbuf_len); if (result == T4_DECODE_MORE_DATA) result = t85_decode_put(t85_dec, NULL, 0); + /*endif*/ cnt_b = t85_decode_get_compressed_image_size(t85_dec); if (cnt_a != cnt_b || cnt_a != testbuf_len*8 || result != T4_DECODE_OK) { @@ -268,12 +290,14 @@ static int test_cycle(const char *test_id, printf("Test failed\n"); exit(2); } + /*endif*/ if (memcmp(decoded_image, image, image_size)) { printf("Image mismatch\n"); printf("Test failed\n"); exit(2); } + /*endif*/ free(decoded_image); t85_decode_free(t85_dec); printf("Test passed\n"); @@ -284,9 +308,11 @@ static int test_cycle(const char *test_id, fprintf(stderr, "Out of memory!\n"); exit(2); } + /*endif*/ t85_dec = t85_decode_init(NULL, row_write_handler, decoded_image); if (comment && comment[0] != 'X') t85_decode_set_comment_handler(t85_dec, 1000, comment_handler, NULL); + /*endif*/ write_row = 0; result = T4_DECODE_MORE_DATA; for (l = 0; l < testbuf_len; l++) @@ -297,9 +323,12 @@ static int test_cycle(const char *test_id, l++; break; } + /*endif*/ } + /*endfor*/ if (result == T4_DECODE_MORE_DATA) result = t85_decode_put(t85_dec, NULL, 0); + /*endif*/ if (l != testbuf_len || result != T4_DECODE_OK) { printf("Decode result %d\n", result); @@ -310,12 +339,14 @@ static int test_cycle(const char *test_id, printf("Test failed\n"); exit(2); } + /*endif*/ if (memcmp(decoded_image, image, image_size)) { printf("Image mismatch\n"); printf("Test failed\n"); exit(2); } + /*endif*/ free(decoded_image); t85_decode_free(t85_dec); printf("Test passed\n"); diff --git a/tests/time_scale_tests.c b/tests/time_scale_tests.c index 4e902c2e..9280219a 100644 --- a/tests/time_scale_tests.c +++ b/tests/time_scale_tests.c @@ -95,18 +95,23 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ + memset(&info, 0, sizeof(info)); if ((inhandle = sf_open(in_file_name, SFM_READ, &info)) == NULL) { printf(" Cannot open audio file '%s'\n", in_file_name); exit(2); } + /*endif*/ if (info.channels != 1) { printf(" Unexpected number of channels in audio file '%s'\n", in_file_name); exit(2); } + /*endif*/ sample_rate = info.samplerate; memset(&info, 0, sizeof(info)); @@ -122,12 +127,14 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ if ((time_scale_init(&state, (int) sample_rate, rate)) == NULL) { fprintf(stderr, " Cannot start the time scaler\n"); exit(2); } + /*endif*/ max = time_scale_max_output_len(&state, BLOCK_LEN); printf("Rate is %f, longest output block is %d\n", rate, max); count = 0; @@ -143,6 +150,7 @@ int main(int argc, char *argv[]) printf("Tests failed\n"); exit(2); } + /*endif*/ samples_out += new_frames; out_frames = sf_writef_short(outhandle, out, new_frames); if (out_frames != new_frames) @@ -150,6 +158,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ if (sweep_rate && ++count > 100) { if (rate > 0.5f) @@ -161,9 +170,12 @@ int main(int argc, char *argv[]) max = time_scale_max_output_len(&state, BLOCK_LEN); printf("Rate is %f, longest output block is %d\n", rate, max); } + /*endif*/ count = 0; } + /*endif*/ } + /*endwhile*/ new_frames = time_scale_flush(&state, out); if (new_frames > max) { @@ -171,6 +183,7 @@ int main(int argc, char *argv[]) printf("Tests failed\n"); exit(2); } + /*endif*/ samples_out += new_frames; out_frames = sf_writef_short(outhandle, out, new_frames); if (out_frames != new_frames) @@ -178,6 +191,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ time_scale_release(&state); if ((int) (rate*samples_in) < samples_out - 1 || (int) (rate*samples_in) > samples_out + 1) { @@ -185,16 +199,19 @@ int main(int argc, char *argv[]) printf("Tests failed\n"); exit(2); } + /*endif*/ if (sf_close(inhandle)) { printf(" Cannot close audio file '%s'\n", in_file_name); exit(2); } + /*endif*/ if (sf_close(outhandle)) { printf(" Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/tone_detect_tests.c b/tests/tone_detect_tests.c index 016e0096..476d283a 100644 --- a/tests/tone_detect_tests.c +++ b/tests/tone_detect_tests.c @@ -80,6 +80,7 @@ static int periodogram_tests(void) printf("Test failed\n"); return -1; } + /*endif*/ pg_scale = periodogram_generate_phase_offset(&phase_offset, FREQ1, DEC_SAMPLE_RATE, PG_WINDOW); scale1 = dds_scaling_dbm0f(-6.0f); scale2 = dds_scaling_dbm0f(-6.0f); @@ -103,12 +104,14 @@ static int periodogram_tests(void) camp[j].re += awgn(noise_source_re); camp[j].im += awgn(noise_source_im); } + /*endfor*/ result = periodogram(coeffs, camp, PG_WINDOW); level = sqrtf(result.re*result.re + result.im*result.im); freq_error = periodogram_freq_error(&phase_offset, pg_scale, &last_result, &result); last_result = result; if (i == 0) continue; + /*endif*/ printf("Signal level = %.5f, freq error = %.5f\n", level, freq_error); if (level < scale1*0.8f || level > scale1*1.2f) @@ -116,15 +119,19 @@ static int periodogram_tests(void) printf("Test failed - %ddBm0 of noise, signal is %f (%f)\n", k, level, scale1); return -1; } + /*endif*/ if (freq_error < -10.0f || freq_error > 10.0f) { printf("Test failed - %ddBm0 of noise, %fHz error\n", k, freq_error); return -1; } + /*endif*/ } + /*endfor*/ awgn_free(noise_source_re); awgn_free(noise_source_im); } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -133,6 +140,7 @@ int main(int argc, char *argv[]) { if (periodogram_tests()) exit(2); + /*endif*/ printf("Tests passed\n"); return 0; } diff --git a/tests/tone_generate_tests.c b/tests/tone_generate_tests.c index f90f2b47..c83bc8b1 100644 --- a/tests/tone_generate_tests.c +++ b/tests/tone_generate_tests.c @@ -59,6 +59,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", OUTPUT_FILE_NAME); exit(2); } + /*endif*/ /* Try a tone pair */ tone_gen_descriptor_init(&tone_desc, @@ -78,8 +79,10 @@ int main(int argc, char *argv[]) printf("Generated %d samples\n", len); if (len <= 0) break; + /*endif*/ sf_writef_short(outhandle, amp, len); } + /*endfor*/ tone_gen_release(&tone_state); /* Try a different tone pair */ @@ -100,8 +103,10 @@ int main(int argc, char *argv[]) printf("Generated %d samples\n", len); if (len <= 0) break; + /*endif*/ sf_writef_short(outhandle, amp, len); } + /*endfor*/ tone_gen_release(&tone_state); /* Try a different tone pair */ @@ -122,8 +127,10 @@ int main(int argc, char *argv[]) printf("Generated %d samples\n", len); if (len <= 0) break; + /*endif*/ sf_writef_short(outhandle, amp, len); } + /*endfor*/ tone_gen_release(&tone_state); /* Try a single tone */ @@ -144,8 +151,10 @@ int main(int argc, char *argv[]) printf("Generated %d samples\n", len); if (len <= 0) break; + /*endif*/ sf_writef_short(outhandle, amp, len); } + /*endfor*/ tone_gen_release(&tone_state); /* Try a single non-repeating tone */ @@ -166,8 +175,10 @@ int main(int argc, char *argv[]) printf("Generated %d samples\n", len); if (len <= 0) break; + /*endif*/ sf_writef_short(outhandle, amp, len); } + /*endfor*/ tone_gen_release(&tone_state); /* Try a single non-repeating tone at 0dBm0 */ @@ -188,8 +199,10 @@ int main(int argc, char *argv[]) printf("Generated %d samples\n", len); if (len <= 0) break; + /*endif*/ sf_writef_short(outhandle, amp, len); } + /*endfor*/ tone_gen_release(&tone_state); /* Try an AM modulated tone at a modest modulation level (25%) */ @@ -210,8 +223,10 @@ int main(int argc, char *argv[]) printf("Generated %d samples\n", len); if (len <= 0) break; + /*endif*/ sf_writef_short(outhandle, amp, len); } + /*endfor*/ tone_gen_release(&tone_state); /* Try an AM modulated tone at maximum modulation level (100%) */ @@ -232,8 +247,10 @@ int main(int argc, char *argv[]) printf("Generated %d samples\n", len); if (len <= 0) break; + /*endif*/ sf_writef_short(outhandle, amp, len); } + /*endfor*/ tone_gen_release(&tone_state); if (sf_close_telephony(outhandle)) @@ -241,6 +258,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME); exit (2); } + /*endif*/ return 0; } diff --git a/tests/tsb85_tests.c b/tests/tsb85_tests.c index 5b199491..69ba9575 100644 --- a/tests/tsb85_tests.c +++ b/tests/tsb85_tests.c @@ -106,12 +106,14 @@ static void exchange(faxtester_state_t *s) s->far_fax = fax_init(NULL, false); s->far_t30 = fax_get_t30_state(s->far_fax); + s->far_tag = 'A'; if (s->far_fax) logging = fax_get_logging_state(s->far_fax); else logging = t38_terminal_get_logging_state(s->far_t38); + /*endif*/ span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW); span_log_set_tag(logging, "A"); @@ -182,6 +184,7 @@ static void exchange(faxtester_state_t *s) printf("Test failed\n"); exit(2); } + /*endif*/ span_log(faxtester_get_logging_state(s), SPAN_LOG_FLOW, "Clear time OK\n"); s->far_end_cleared_call = true; s->test_for_call_clear = false; @@ -237,11 +240,14 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ argc -= optind; argv += optind; if (argc > 0) test_name = argv[0]; + /*endif*/ if ((state = faxtester_init(NULL, xml_file_name, test_name)) == NULL) { @@ -249,6 +255,7 @@ int main(int argc, char *argv[]) printf("Test failed\n"); exit(2); } + /*endif*/ logging = faxtester_get_logging_state(state); span_log_set_level(logging, SPAN_LOG_SHOW_SEVERITY | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME | SPAN_LOG_FLOW); span_log_set_tag(logging, "B"); diff --git a/tests/tsb85_tests.sh b/tests/tsb85_tests.sh index d29be6a2..2003f181 100755 --- a/tests/tsb85_tests.sh +++ b/tests/tsb85_tests.sh @@ -28,8 +28,7 @@ run_tsb85_test() fi } -#for TEST in MRGN01 MRGN02 MRGN03 MRGN04 MRGN05 MRGN06a MRGN06b MRGN07 MRGN08 -for TEST in MRGN01 MRGN02 MRGN04 MRGN06a MRGN06b MRGN07 MRGN08 +for TEST in MRGN01 MRGN02 MRGN03 MRGN04 MRGN05 MRGN06a MRGN06b MRGN07 MRGN08 do run_tsb85_test done @@ -39,20 +38,17 @@ do run_tsb85_test done -#for TEST in ORGC01 ORGC02 ORGC03 -for TEST in ORGC01 ORGC02 +for TEST in ORGC01 ORGC02 ORGC03 do run_tsb85_test done -#for TEST in OREN01 OREN02 OREN03 OREN04 OREN05 OREN06 OREN07 OREN08 OREN09 OREN10 -for TEST in OREN01 OREN02 OREN03 OREN04 OREN05 OREN06 OREN07 OREN08 OREN09 +for TEST in OREN01 OREN02 OREN03 OREN04 OREN05 OREN06 OREN07 OREN08 OREN09 OREN10 do run_tsb85_test done -#for TEST in MRGX01 MRGX02 MRGX03 MRGX04 MRGX05 MRGX06 MRGX07 MRGX08 -for TEST in MRGX02 MRGX03 MRGX04 MRGX05 MRGX06 MRGX07 MRGX08 +for TEST in MRGX01 MRGX02 MRGX03 MRGX04 MRGX05 MRGX06 MRGX07 MRGX08 do run_tsb85_test done @@ -67,8 +63,7 @@ do run_tsb85_test done -#for TEST in MTGN01 MTGN02 MTGN03 MTGN04 MTGN05 MTGN06 MTGN07 MTGN08 MTGN09 MTGN10 -for TEST in MTGN02 MTGN03 MTGN04 MTGN05 MTGN06 MTGN07 MTGN08 MTGN09 MTGN10 +for TEST in MTGN01 MTGN02 MTGN03 MTGN04 MTGN05 MTGN06 MTGN07 MTGN08 MTGN09 MTGN10 do run_tsb85_test done @@ -78,8 +73,7 @@ do run_tsb85_test done -#for TEST in MTGN21 MTGN22 MTGN23 MTGN24 MTGN25 MTGN26 MTGN27 MTGN28 -for TEST in MTGN21 MTGN22 MTGN23 MTGN24 MTGN25 MTGN26 MTGN27 +for TEST in MTGN21 MTGN22 MTGN23 MTGN24 MTGN25 MTGN26 MTGN27 MTGN28 do run_tsb85_test done @@ -94,13 +88,12 @@ do run_tsb85_test done -#for TEST in OTGC10 OTGC11 -#do -# run_tsb85_test -#done +for TEST in OTGC10 OTGC11 +do + run_tsb85_test +done -#for TEST in OTEN01 OTEN02 OTEN03 OTEN04 OTEN05 OTEN06 -for TEST in OTEN03 OTEN04 OTEN05 +for TEST in OTEN01 OTEN02 OTEN03 OTEN04 OTEN05 OTEN06 do run_tsb85_test done diff --git a/tests/v150_1_sse_tests.c b/tests/v150_1_sse_tests.c index a659ce13..d179e48c 100644 --- a/tests/v150_1_sse_tests.c +++ b/tests/v150_1_sse_tests.c @@ -61,12 +61,12 @@ typedef struct uint32_t ssrc; } rtp_t; -rtp_t rtp; +rtp_t tx_sse_rtp; #define PACKET_TYPE 118 socket_dgram_harness_state_t *dgram_state; -v150_1_sse_state_t *v150_1_sse_state; +v150_1_state_t *v150_1_state; int pace_no = 0; @@ -87,7 +87,9 @@ static int rtp_fill(rtp_t *rtp, uint8_t *buf, int max_len, int pt, const uint8_t put_net_unaligned_uint32(&buf[4], rtp->time_stamp); put_net_unaligned_uint32(&buf[8], rtp->ssrc); memcpy(&buf[12], signal, signal_len); - rtp->seq_no++; + if (advance) + rtp->seq_no++; + /*endif*/ rtp->time_stamp += advance; return 12 + signal_len; } @@ -155,15 +157,7 @@ static void rx_callback(void *user_data, const uint8_t buf[], int len) signal_len = rtp_extract(&rtp, signal, 160, buf, len); if (rtp.pt == PACKET_TYPE) { - if (rtp.seq_no != seq - 1) - { - v150_1_sse_rx_packet((v150_1_sse_state_t *) user_data, rtp.seq_no, rtp.time_stamp, signal, signal_len); - } - else - { - fprintf(stderr, "Repeat packet\n"); - } - /*endif*/ + v150_1_sse_rx_packet((v150_1_state_t *) user_data, rtp.seq_no, rtp.time_stamp, signal, signal_len); } /*endif*/ seq = rtp.seq_no + 1; @@ -175,7 +169,7 @@ static int tx_callback(void *user_data, uint8_t buff[], int len) { int res; - res = v150_1_sse_tx_packet((v150_1_sse_state_t *) user_data, V150_1_SSE_MEDIA_STATE_MODEM_RELAY, V150_1_SSE_RIC_V32BIS_AA, 0); + res = v150_1_sse_tx_packet((v150_1_state_t *) user_data, V150_1_MEDIA_STATE_MODEM_RELAY, V150_1_SSE_RIC_V32BIS_AA, 0); return res; } /*- End of function --------------------------------------------------------*/ @@ -196,7 +190,7 @@ static int tx_packet_handler(void *user_data, bool repeat, const uint8_t pkt[], /*endfor*/ fprintf(stderr, "\n"); - len2 = rtp_fill(&rtp, buf, 256, PACKET_TYPE, pkt, len, (repeat) ? 0 : 160); + len2 = rtp_fill(&tx_sse_rtp, buf, 256, PACKET_TYPE, pkt, len, (repeat) ? 0 : 160); s = (socket_dgram_harness_state_t *) user_data; /* We need a packet loss mechanism here */ @@ -228,12 +222,6 @@ static int tx_packet_handler(void *user_data, bool repeat, const uint8_t pkt[], } /*- End of function --------------------------------------------------------*/ -static int status_handler(void *user_data, int status) -{ - return 0; -} -/*- End of function --------------------------------------------------------*/ - static void paced_operations(void) { //fprintf(stderr, "Pace at %lu\n", now_us()); @@ -241,7 +229,7 @@ static void paced_operations(void) if (send_messages && (pace_no & 0x3F) == 0) { fprintf(stderr, "Sending paced message\n"); - if (v150_1_sse_tx_packet(v150_1_sse_state, V150_1_SSE_MEDIA_STATE_MODEM_RELAY, V150_1_SSE_RIC_V32BIS_AA, 0) != 0) + if (v150_1_sse_tx_packet(v150_1_state, V150_1_MEDIA_STATE_MODEM_RELAY, V150_1_SSE_RIC_V32BIS_AA, 0) != 0) fprintf(stderr, "ERROR: Failed to send message\n"); /*endif*/ @@ -271,7 +259,7 @@ static void timer_callback(void *user_data) { //fprintf(stderr, "V.150.1 SSE timer expired at %lu\n", now); app_timer = 0; - v150_1_sse_timer_expired((v150_1_sse_state_t *) user_data, now); + v150_1_sse_timer_expired((v150_1_state_t *) user_data, now); } /*endif*/ if (app_timer && app_timer < pace_timer) @@ -282,45 +270,13 @@ static void timer_callback(void *user_data) } /*- End of function --------------------------------------------------------*/ -static span_timestamp_t timer_handler(void *user_data, span_timestamp_t timeout) -{ - span_timestamp_t now; - - now = now_us(); - if (timeout == 0) - { - fprintf(stderr, "V.150_1 SSE timer stopped at %lu\n", now); - app_timer = 0; - //socket_dgram_harness_timer = pace_timer; - } - else if (timeout == ~0) - { - fprintf(stderr, "V.150_1 SSE get the time %lu\n", now); - /* Just return the current time */ - } - else - { - fprintf(stderr, "V.150_1 SSE timer set to %lu at %lu\n", timeout, now); - if (timeout < now) - timeout = now; - /*endif*/ - app_timer = timeout; - //if (app_timer < pace_timer) - // socket_dgram_harness_timer = timeout; - /*endif*/ - } - /*endif*/ - return now; -} -/*- End of function --------------------------------------------------------*/ - static int v150_1_sse_tests(bool calling_party) { logging_state_t *logging; send_messages = true; //calling_party; - memset(&rtp, 0, sizeof(rtp)); + memset(&tx_sse_rtp, 0, sizeof(tx_sse_rtp)); if ((dgram_state = socket_dgram_harness_init(NULL, (calling_party) ? "/tmp/sse_socket_a" : "/tmp/sse_socket_b", @@ -334,32 +290,28 @@ static int v150_1_sse_tests(bool calling_party) rx_callback, tx_callback, timer_callback, - v150_1_sse_state)) == NULL) + v150_1_state)) == NULL) { fprintf(stderr, " Cannot start the socket harness\n"); exit(2); } /*endif*/ - if ((v150_1_sse_state = v150_1_sse_init(NULL, - tx_packet_handler, - dgram_state, - status_handler, - dgram_state, - timer_handler, - dgram_state)) == NULL) + if ((v150_1_state = v150_1_sse_init(NULL, + tx_packet_handler, + dgram_state)) == NULL) { fprintf(stderr, " Cannot start V.150.1 SSE\n"); exit(2); } /*endif*/ - socket_dgram_harness_set_user_data(dgram_state, v150_1_sse_state); + socket_dgram_harness_set_user_data(dgram_state, v150_1_state); - logging = v150_1_sse_get_logging_state(v150_1_sse_state); + logging = v150_1_get_logging_state(v150_1_state); span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_DATE); span_log_set_tag(logging, (calling_party) ? "C" : "A"); - v150_1_sse_set_reliability_method(v150_1_sse_state, V150_1_SSE_RELIABILITY_BY_REPETITION, 3, 20000, 0); + v150_1_sse_set_reliability_method(v150_1_state, V150_1_SSE_RELIABILITY_BY_REPETITION, 3, 20000, 0); //v150_1_sse_set_reliability_method(v150_1_sse_state, // V150_1_SSE_RELIABILITY_BY_EXPLICIT_ACK, // V150_1_SSE_DEFAULT_N0, diff --git a/tests/v150_1_tests.c b/tests/v150_1_tests.c index c625d65e..c8a665a7 100644 --- a/tests/v150_1_tests.c +++ b/tests/v150_1_tests.c @@ -37,50 +37,242 @@ #include #include #include -#include -#include +#include +#include +#include +#include +#include #include "spandsp.h" +#include "spandsp-sim.h" -v150_1_state_t *v150_1[2]; +#include "pseudo_terminals.h" +#include "socket_dgram_harness.h" + +#define SSE_PACKET_TYPE 118 +#define SPRT_PACKET_TYPE 120 + +typedef struct +{ + uint8_t v; + uint8_t p; + uint8_t x; + uint8_t cc; + uint8_t m; + uint8_t pt; + uint16_t seq_no; + uint32_t time_stamp; + uint32_t ssrc; +} rtp_t; + +int rtp_time_stamp = 0; + +rtp_t rtp; +v150_1_state_t *v150_1; +socket_dgram_harness_state_t *dgram_state; + +int max_payloads[SPRT_CHANNELS]; + +int pace_no = 0; + +bool send_messages = false; +bool calling_party = false; + +span_timestamp_t pace_timer = 0; +span_timestamp_t v150_1_timer = 0; + +/* Crude RTP routines */ + +static int rtp_init(rtp_t *rtp, uint32_t time_stamp, uint32_t ssrc) +{ + rtp->v = 2; + rtp->p = 0; + rtp->x = 0; + rtp->cc = 0; + rtp->m = 0; + rtp->seq_no = rand(); + rtp->time_stamp = time_stamp; + rtp->ssrc = ssrc; + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int rtp_fill(rtp_t *rtp, uint8_t *buf, int max_len, int pt, const uint8_t *signal, int signal_len, uint32_t advance) +{ + rtp->time_stamp += advance; + buf[0] = ((rtp->v & 0x03) << 6) | ((rtp->p & 0x01) << 5) | ((rtp->x & 0x01) << 4) | (rtp->cc & 0x0F); + buf[1] = ((rtp->m & 0x01) << 7) | pt; + put_net_unaligned_uint16(&buf[2], rtp->seq_no); + put_net_unaligned_uint32(&buf[4], rtp->time_stamp); + put_net_unaligned_uint32(&buf[8], rtp->ssrc); + memcpy(&buf[12], signal, signal_len); + rtp->seq_no++; + return 12 + signal_len; +} +/*- End of function --------------------------------------------------------*/ + +static int rtp_extract(rtp_t *rtp, uint8_t *signal, int max_len, const uint8_t *buf, int len) +{ + rtp->v = (buf[0] >> 6) & 0x03; + rtp->p = (buf[0] >> 5) & 0x01; + rtp->x = (buf[0] >> 4) & 0x01; + rtp->cc = buf[0] & 0x0F; + rtp->m = (buf[1] >> 7) & 0x01; + rtp->pt = buf[1] & 0x7F; + rtp->seq_no = get_net_unaligned_uint16(&buf[2]); + rtp->time_stamp = get_net_unaligned_uint32(&buf[4]); + rtp->ssrc = get_net_unaligned_uint32(&buf[8]); + if (signal) + memcpy(signal, &buf[12], len - 12); + /*endif*/ + return len - 12; +} +/*- End of function --------------------------------------------------------*/ + +static void terminal_callback(void *user_data, const uint8_t msg[], int len) +{ + int i; + + fprintf(stderr, "terminal callback %d\n", len); + for (i = 0; i < len; i++) + { + fprintf(stderr, "0x%x ", msg[i]); + } + fprintf(stderr, "\n"); + /* TODO: connect AT input to SPRT */ +} +/*- End of function --------------------------------------------------------*/ + +static int termios_callback(void *user_data, struct termios *termios) +{ + //data_modems_state_t *s; + + //s = (data_modems_state_t *) user_data; + fprintf(stderr, "termios callback\n"); + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static void hangup_callback(void *user_data, int status) +{ +} +/*- End of function --------------------------------------------------------*/ + +static int terminal_free_space_callback(void *user_data) +{ + return 42; +} +/*- End of function --------------------------------------------------------*/ + +static void dgram_rx_callback(void *user_data, const uint8_t buf[], int len) +{ + int pt; + rtp_t rtp; + int signal_len; + uint8_t signal[160]; + v150_1_state_t *s; + + s = (v150_1_state_t *) user_data; + if (len > 1) + { + pt = buf[1] & 0x7F; + fprintf(stderr, "Packet type %d\n", pt); + if ((buf[0] & 0xC0) == 0x80) + { + /* This looks like RTP */ + fprintf(stderr, "Looks RTPish\n"); + signal_len = rtp_extract(&rtp, signal, 160, buf, len); + if (rtp.pt == SSE_PACKET_TYPE) + { + v150_1_rx_sse_packet(s, rtp.seq_no, rtp.time_stamp, signal, signal_len); + } + /*endif*/ + rtp_time_stamp = rtp.time_stamp + 160; + } + else + { + /* Could be SPRT */ + fprintf(stderr, "Looks SPRTish\n"); + if (pt == SPRT_PACKET_TYPE) + { + sprt_rx_packet(&s->sprt, buf, len); + } + /*endif*/ + } + /*endif*/ + } + /*endif*/ +} +/*- End of function --------------------------------------------------------*/ + +static int tx_callback(void *user_data, uint8_t buff[], int len) +{ + return 0; +} +/*- End of function --------------------------------------------------------*/ static int v150_1_status_report_handler(void *user_data, v150_1_status_t *report) { - printf("V.150.1 status report received\n"); + fprintf(stderr, "V.150.1 status report received\n"); switch (report->reason) { - case V150_1_STATUS_REASON_STATE_CHANGED: - printf("Connection state changed to %s\n", v150_1_state_to_str(report->state_change.state)); - if (report->state_change.state == V150_1_STATE_IDLE) - printf(" Cleardown reason %s\n", v150_1_cleardown_reason_to_str(report->state_change.cleardown_reason)); - /*endif*/ + case V150_1_STATUS_REASON_MEDIA_STATE_CHANGED: + fprintf(stderr, + "Media state changed to %s %s\n", + v150_1_media_state_to_str(report->media_state_change.local_state), + v150_1_media_state_to_str(report->media_state_change.remote_state)); + break; + case V150_1_STATUS_REASON_CONNECTION_STATE_CHANGED: + fprintf(stderr, "Connection state changed to %s\n", v150_1_state_to_str(report->connection_state_change.state)); + switch (report->connection_state_change.state) + { + case V150_1_STATE_IDLE: + fprintf(stderr, " Cleardown reason %s\n", v150_1_cleardown_reason_to_str(report->connection_state_change.cleardown_reason)); + break; + case V150_1_STATE_INITED: + if (calling_party) + v150_1_tx_init(v150_1); + else + v150_1_tx_jm_info(v150_1); + /*endif*/ + break; + } + /*endswitch*/ + break; + case V150_1_STATUS_REASON_CONNECTION_STATE_PHYSUP: + fprintf(stderr, "Physup received\n"); + v150_1_tx_mr_event(v150_1, V150_1_MR_EVENT_ID_PHYSUP); + break; + case V150_1_STATUS_REASON_CONNECTION_STATE_CONNECTED: + fprintf(stderr, "Connected received\n"); + v150_1_tx_connect(v150_1); break; case V150_1_STATUS_REASON_DATA_FORMAT_CHANGED: - printf("Data format changed\n"); - printf(" Format is %d data bits, %d stop bits, %s parity\n", + fprintf(stderr, "Data format changed\n"); + fprintf(stderr, " Format is %d data bits, %d stop bits, %s parity\n", report->data_format_change.bits, report->data_format_change.stop_bits, v150_1_parity_to_str(report->data_format_change.parity_code)); break; case V150_1_STATUS_REASON_BREAK_RECEIVED: - printf("Break received\n"); - printf(" Break source %s\n", v150_1_break_source_to_str(report->break_received.source)); - printf(" Break type %s\n", v150_1_break_type_to_str(report->break_received.type)); - printf(" Break duration %d ms\n", report->break_received.duration); + fprintf(stderr, "Break received\n"); + fprintf(stderr, " Break source %s\n", v150_1_break_source_to_str(report->break_received.source)); + fprintf(stderr, " Break type %s\n", v150_1_break_type_to_str(report->break_received.type)); + fprintf(stderr, " Break duration %d ms\n", report->break_received.duration); break; case V150_1_STATUS_REASON_RATE_RETRAIN_RECEIVED: - printf("Retrain received\n"); + fprintf(stderr, "Retrain received\n"); break; case V150_1_STATUS_REASON_RATE_RENEGOTIATION_RECEIVED: - printf("Rate renegotiation received\n"); + fprintf(stderr, "Rate renegotiation received\n"); break; case V150_1_STATUS_REASON_BUSY_CHANGED: - printf("Busy status change received\n"); - printf("Near side now %sbusy\n", (report->busy_change.local_busy) ? "" : "not "); - printf("Far side now %sbusy\n", (report->busy_change.far_busy) ? "" : "not "); + fprintf(stderr, "Busy status change received\n"); + fprintf(stderr, "Near side now %sbusy\n", (report->busy_change.local_busy) ? "" : "not "); + fprintf(stderr, "Far side now %sbusy\n", (report->busy_change.far_busy) ? "" : "not "); break; default: - printf("Unknown status report reason %d received\n", report->reason); + fprintf(stderr, "Unknown status report reason %d received\n", report->reason); break; } /*endif*/ @@ -88,212 +280,247 @@ static int v150_1_status_report_handler(void *user_data, v150_1_status_t *report } /*- End of function --------------------------------------------------------*/ -static int v150_1_octet_stream_handler(void *user_data, const uint8_t msg[], int len, int fill) +static int v150_1_data_stream_handler(void *user_data, const uint8_t msg[], int len, int fill) { int i; if (fill > 0) - printf("%d missing characters\n", fill); + fprintf(stderr, "%d missing characters\n", fill); /*endif*/ - printf(">>>"); + fprintf(stderr, ">>>"); for (i = 0; i < len; i++) { - printf(" %02x", msg[i]); + fprintf(stderr, " %02x", msg[i]); } /*endfor*/ - printf("<<<\n"); + fprintf(stderr, "<<<\n"); return 0; } /*- End of function --------------------------------------------------------*/ /* Get a packet from one side, and pass it to the other */ -static int v150_1_tx_packet_handler(void *user_data, int chan, const uint8_t msg[], int len) +static int sprt_tx_packet_handler(void *user_data, const uint8_t pkt[], int len) { - int i; - int which; + socket_dgram_harness_state_t *s; + int sent_len; - which = (intptr_t) user_data; - printf("Tx (%d) ", which); + s = (socket_dgram_harness_state_t *) user_data; + /* We need a packet loss mechanism here */ + if ((rand() % 20) != 0) + { + fprintf(stderr, "Pass\n"); + if ((sent_len = sendto(s->net_fd, pkt, len, 0, (struct sockaddr *) &s->far_addr, s->far_addr_len)) < 0) + { + if (errno != EAGAIN) + { + fprintf(stderr, "Error: Net write: %s\n", strerror(errno)); + return -1; + } + /*endif*/ + /* TODO: */ + } + /*endif*/ + if (sent_len != len) + fprintf(stderr, "Net write = %d\n", sent_len); + /*endif*/ + } + else + { + fprintf(stderr, "Block\n"); + } + /*endif*/ + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int sse_tx_packet_handler(void *user_data, bool repeat, const uint8_t *pkt, int len) +{ + int i; + socket_dgram_harness_state_t *s; + int sent_len; + uint8_t buf[256]; + int len2; + + fprintf(stderr, "Tx message"); for (i = 0; i < len; i++) - printf("%02x ", msg[i]); + fprintf(stderr, " %02x", pkt[i]); /*endfor*/ - printf("\n"); + fprintf(stderr, "\n"); + + len2 = rtp_fill(&rtp, buf, 256, SSE_PACKET_TYPE, pkt, len, (repeat) ? 0 : 160); - v150_1_process_rx_msg(v150_1[which ^ 1], chan, 0, msg, len); + s = (socket_dgram_harness_state_t *) user_data; + /* We need a packet loss mechanism here */ + if ((sent_len = sendto(s->net_fd, buf, len2, 0, (struct sockaddr *) &s->far_addr, s->far_addr_len)) < 0) + { + if (errno != EAGAIN) + { + fprintf(stderr, "Error: Net write: %s\n", strerror(errno)); + return -1; + } + /*endif*/ + /* TODO: */ + } + /*endif*/ + if (sent_len != len) + fprintf(stderr, "Net write = %d\n", sent_len); + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ -int main(int argc, char *argv[]) +static void paced_operations(void) { - logging_state_t *logging; - uint8_t buf[256]; - int msg_id_priorities[10]; int i; - int max; - - v150_1[0] = v150_1_init(NULL, - v150_1_tx_packet_handler, - (void *) (intptr_t) 0, - v150_1_octet_stream_handler, - (void *) (intptr_t) 0, - v150_1_status_report_handler, - (void *) (intptr_t) 0); - - v150_1[1] = v150_1_init(NULL, - v150_1_tx_packet_handler, - (void *) (intptr_t) 1, - v150_1_octet_stream_handler, - (void *) (intptr_t) 1, - v150_1_status_report_handler, - (void *) (intptr_t) 1); - - logging = v150_1_get_logging_state(v150_1[0]); - span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_DATE); - logging = v150_1_get_logging_state(v150_1[1]); - span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_DATE); - - v150_1_set_info_stream_tx_mode(v150_1[0], SPRT_TCID_RELIABLE_SEQUENCED, V150_1_MSGID_I_OCTET_CS); - v150_1_set_info_stream_tx_mode(v150_1[1], SPRT_TCID_RELIABLE_SEQUENCED, V150_1_MSGID_I_OCTET_CS); - - msg_id_priorities[0] = V150_1_MSGID_I_OCTET; - msg_id_priorities[1] = V150_1_MSGID_I_OCTET_CS; - msg_id_priorities[2] = -1; - v150_1_set_info_stream_msg_priorities(v150_1[0], msg_id_priorities); - v150_1_set_info_stream_msg_priorities(v150_1[1], msg_id_priorities); + uint8_t buf[256]; - v150_1_tx_null(v150_1[0]); - v150_1_tx_null(v150_1[1]); + fprintf(stderr, "Pace at %lu\n", now_us()); - v150_1_tx_init(v150_1[0]); - v150_1_tx_init(v150_1[1]); + pace_no++; - v150_1_set_modulation(v150_1[0], V150_1_SELMOD_V34); - v150_1_set_compression_direction(v150_1[0], V150_1_COMPRESS_NEITHER_WAY); - v150_1_set_compression(v150_1[0], V150_1_COMPRESSION_NONE); - v150_1_set_compression_parameters(v150_1[0], - 512, - 512, - 6, - 6, - 0, - 0); - v150_1_set_error_correction(v150_1[0], V150_1_ERROR_CORRECTION_NONE); - v150_1_set_tx_symbol_rate(v150_1[0], true, V150_1_SYMBOL_RATE_3429); - v150_1_set_rx_symbol_rate(v150_1[0], true, V150_1_SYMBOL_RATE_3429); - v150_1_set_tx_data_signalling_rate(v150_1[0], 33600); - v150_1_set_rx_data_signalling_rate(v150_1[0], 33600); - - v150_1_set_modulation(v150_1[1], V150_1_SELMOD_V34); - v150_1_set_compression_direction(v150_1[1], V150_1_COMPRESS_NEITHER_WAY); - v150_1_set_compression(v150_1[1], V150_1_COMPRESSION_NONE); - v150_1_set_compression_parameters(v150_1[1], - 512, - 512, - 6, - 6, - 0, - 0); - v150_1_set_error_correction(v150_1[1], V150_1_ERROR_CORRECTION_NONE); - v150_1_set_tx_symbol_rate(v150_1[1], true, V150_1_SYMBOL_RATE_3429); - v150_1_set_rx_symbol_rate(v150_1[1], true, V150_1_SYMBOL_RATE_3429); - v150_1_set_tx_data_signalling_rate(v150_1[1], 33600); - v150_1_set_rx_data_signalling_rate(v150_1[1], 33600); - - v150_1_tx_jm_info(v150_1[0]); - v150_1_tx_jm_info(v150_1[1]); - v150_1_tx_mr_event(v150_1[0], V150_1_MR_EVENT_ID_PHYSUP); - v150_1_tx_mr_event(v150_1[1], V150_1_MR_EVENT_ID_PHYSUP); - v150_1_tx_connect(v150_1[0]); - v150_1_tx_connect(v150_1[1]); - - v150_1_tx_xid_xchg(v150_1[0]); - v150_1_tx_start_jm(v150_1[0]); - v150_1_tx_prof_xchg(v150_1[0]); - - if (v150_1_tx_info_stream(v150_1[0], (const uint8_t *) "Test side 0", 11) < 0) - printf("Failed to send good message\n"); + if (pace_no == 50) + { + if (!calling_party) + { + if (v150_1_tx_sse_packet(v150_1, V150_1_MEDIA_STATE_MODEM_RELAY, V150_1_SSE_MOIP_RIC_V32BIS_AA, 0) != 0) + fprintf(stderr, "ERROR: Failed to send message\n"); + /*endif*/ + } + /*endif*/ + } /*endif*/ - if (v150_1_tx_info_stream(v150_1[1], (const uint8_t *) "Test side 1", 11) < 0) - printf("Failed to send good message\n"); +#if 0 + if (pace_no == 50) + { + if (!calling_party) + v150_1_tx_init(v150_1); + /*endif*/ + } /*endif*/ - - max = v150_1_get_local_tc_payload_bytes(v150_1[0], SPRT_TCID_RELIABLE_SEQUENCED); - printf("Max payload bytes is %d\n", max); - - for (i = 0; i < 256; i++) - buf[i] = i; - /*endfor*/ - if (v150_1_tx_info_stream(v150_1[0], buf, 129) < 0) - printf("Failed to send good message\n"); + if (pace_no == 500) + { + if (!calling_party) + { + v150_1_tx_mr_event(v150_1, V150_1_MR_EVENT_ID_PHYSUP); + v150_1_tx_connect(v150_1); + } + /*endif*/ + } /*endif*/ - for (i = 0; i < 256; i++) - buf[i] = 255 - i; - /*endfor*/ - if (v150_1_tx_info_stream(v150_1[1], buf, 129) < 0) - printf("Failed to send good message\n"); +#if 0 + else + { + for (i = 0; i < 256; i++) + buf[i] = i; + /*endfor*/ + if (v150_1_tx_info_stream(v150_1, buf, 42) < 0) + fprintf(stderr, "Failed to send good message\n"); + /*endif*/ + } +#endif +#endif /*endif*/ +} +/*- End of function --------------------------------------------------------*/ - if (v150_1_set_local_tc_payload_bytes(v150_1[0], SPRT_TCID_RELIABLE_SEQUENCED, 200) < 0) - printf("Failed to set new max payload bytes\n"); - /*endif*/ - if (v150_1_set_local_tc_payload_bytes(v150_1[1], SPRT_TCID_RELIABLE_SEQUENCED, 200) < 0) - printf("Failed to set new max payload bytes\n"); - /*endif*/ +static void timer_callback(void *user_data) +{ + span_timestamp_t now; + span_timestamp_t cand; - for (i = 0; i < 256; i++) - buf[i] = i; - /*endfor*/ - if (v150_1_tx_info_stream(v150_1[0], buf, 197) < 0) - printf("Failed to send good message\n"); + now = now_us(); + if (pace_timer && now >= pace_timer) + { + fprintf(stderr, "Pace timer expired at %lu\n", now); + paced_operations(); + pace_timer += 20000; + } /*endif*/ - for (i = 0; i < 256; i++) - buf[i] = 255 - i; - /*endfor*/ - if (v150_1_tx_info_stream(v150_1[1], buf, 198) >= 0) - printf("Able to send bad length message\n"); + if (v150_1_timer && now >= v150_1_timer) + { + fprintf(stderr, "V150.1 timer expired at %lu\n", now); + v150_1_timer = 0; + v150_1_timer_expired(v150_1, now); + } /*endif*/ - - if (v150_1_set_local_tc_payload_bytes(v150_1[0], SPRT_TCID_RELIABLE_SEQUENCED, 256) < 0) - printf("Failed to set new max payload bytes\n"); + cand = ~0; + if (v150_1_timer && v150_1_timer < cand) + cand = v150_1_timer; /*endif*/ - if (v150_1_set_local_tc_payload_bytes(v150_1[1], SPRT_TCID_RELIABLE_SEQUENCED, 257) >= 0) - printf("Able to set bad new max payload bytes\n"); + if (pace_timer && pace_timer < cand) + cand = pace_timer; /*endif*/ + socket_dgram_harness_timer = cand; +} +/*- End of function --------------------------------------------------------*/ - if (v150_1_set_local_tc_payload_bytes(v150_1[0], SPRT_TCID_RELIABLE_SEQUENCED, 132) < 0) - printf("Failed to set new max payload bytes\n"); - /*endif*/ - if (v150_1_set_local_tc_payload_bytes(v150_1[1], SPRT_TCID_RELIABLE_SEQUENCED, 132) >= 0) - printf("Able to set bad new max payload bytes\n"); - /*endif*/ +static span_timestamp_t v150_1_timer_handler(void *user_data, span_timestamp_t timeout) +{ + span_timestamp_t now; - for (i = 0; i < 256; i++) - buf[i] = i; - /*endfor*/ - if (v150_1_tx_info_stream(v150_1[0], buf, 129) < 0) - printf("Failed to send byte stream\n"); - /*endif*/ - for (i = 0; i < 256; i++) - buf[i] = 255 - i; - /*endfor*/ - if (v150_1_tx_info_stream(v150_1[1], buf, 129) < 0) - printf("Failed to send byte stream\n"); + now = now_us(); + if (timeout == 0) + { + fprintf(stderr, "V.150.1 timer stopped at %lu\n", now); + v150_1_timer = 0; + socket_dgram_harness_timer = pace_timer; + } + else if (timeout == ~0) + { + fprintf(stderr, "V.150.1 get the time %lu\n", now); + /* Just return the current time */ + } + else + { + fprintf(stderr, "V.150.1 timer set to %lu at %lu\n", timeout, now); + if (timeout < now) + timeout = now; + /*endif*/ + v150_1_timer = timeout; + if (pace_timer == 0 || pace_timer > v150_1_timer) + socket_dgram_harness_timer = v150_1_timer; + else + socket_dgram_harness_timer = pace_timer; + /*endif*/ + } /*endif*/ + return now; +} +/*- End of function --------------------------------------------------------*/ - v150_1_tx_break(v150_1[0], V150_1_BREAK_SOURCE_V42_LAPM, V150_1_BREAK_TYPE_DESTRUCTIVE_EXPEDITED, 1230); - v150_1_tx_break_ack(v150_1[1]); - - v150_1_tx_cleardown(v150_1[0], V150_1_CLEARDOWN_REASON_LINK_LAYER_DISCONNECT); - - v150_1_tx_cleardown(v150_1[1], V150_1_CLEARDOWN_REASON_LINK_LAYER_DISCONNECT); - +static int message_decode_tests(void) +{ + uint8_t buf[256]; + int len; + + /* The following INIT message should say: + Preferred non-error controlled Rx channel: USC + Preferred error controlled Rx channel: USC + XID profile exchange not supported + Asymmetric data types not supported + I_RAW-CHAR supported + I_RAW-BIT not supported + I_FRAME not supported + I_OCTET (no DLCI) supported + I_CHAR-STAT not supported + I_CHAR-DYN not supported + I_OCTET-CS supported + I_CHAR-STAT-CS not supported + I_CHAR-DYN-CS not supported + */ + printf("INIT test\n"); buf[0] = 0x01; buf[1] = 0x40; buf[2] = 0x80; - v150_1_process_rx_msg(v150_1[0], SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, 0, buf, 3); - + v150_1_test_rx_sprt_msg(v150_1, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, 0, buf, 3); + + /* The following MR-EVENT message + Selected modulation V.32 + Tx data signalling rate 9600 + Rx data signalling rate 9600 + */ + printf("MR-EVENT test\n"); buf[0] = 0x08; buf[1] = 0x03; buf[2] = 0x00; @@ -304,8 +531,26 @@ int main(int argc, char *argv[]) buf[7] = 0x80; buf[8] = 0x00; buf[9] = 0x00; - v150_1_process_rx_msg(v150_1[0], SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, 1, buf, 10); - + v150_1_test_rx_sprt_msg(v150_1, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, 1, buf, 10); + + /* The following CONNECT message should say: + Modulation V.32 + Compression direction Neither way + Compression None + Error correction None + Tx data rate 9600 + Rx data rate 9600 + I_RAW-CHAR available + I_RAW-BIT not available + I_FRAME not available + I_OCTET not available + I_CHAR-STAT not available + I_CHAR-DYN not available + I_OCTET-CS available + I_CHAR-STAT-CS not available + I_CHAR-DYN-CS not available + */ + printf("CONNECT test\n"); buf[0] = 0x05; buf[1] = 0x18; buf[2] = 0x00; @@ -315,14 +560,336 @@ int main(int argc, char *argv[]) buf[6] = 0x80; buf[7] = 0x02; buf[8] = 0x00; - v150_1_process_rx_msg(v150_1[0], SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, 2, buf, 9); + v150_1_test_rx_sprt_msg(v150_1, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, 2, buf, 9); + + printf("I_OCTET-CS sending \"TEST\" test\n"); + buf[0] = 0x16; + buf[1] = 0x00; + buf[2] = 0x00; + buf[3] = 0x54; + buf[4] = 0x45; + buf[5] = 0x53; + buf[6] = 0x54; + v150_1_test_rx_sprt_msg(v150_1, SPRT_TCID_RELIABLE_SEQUENCED, 0, buf, 7); + + printf("I_OCTET-CS sending \"TEST\" test\n"); + buf[0] = 0x16; + buf[1] = 0x00; + buf[2] = 0x00; + buf[3] = 0x54; + buf[4] = 0x45; + buf[5] = 0x53; + buf[6] = 0x54; + v150_1_test_rx_sprt_msg(v150_1, SPRT_TCID_UNRELIABLE_SEQUENCED, 0, buf, 7); + printf("CLEARDOWN test\n"); buf[0] = 0x09; buf[1] = 0x05; buf[2] = 0x01; buf[3] = 0x02; - v150_1_process_rx_msg(v150_1[0], SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, 2, buf, 4); + v150_1_test_rx_sprt_msg(v150_1, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, 3, buf, 4); + + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int message_encode_tests(void) +{ + uint8_t buf[256]; + int i; + + v150_1_tx_null(v150_1); + + /* The following INIT message should say: + Preferred non-error controlled Rx channel: USC + Preferred error controlled Rx channel: USC + XID profile exchange not supported + Asymmetric data types not supported + I_RAW-CHAR supported + I_RAW-BIT not supported + I_FRAME not supported + I_OCTET (no DLCI) supported + I_CHAR-STAT not supported + I_CHAR-DYN not supported + I_OCTET-CS supported + I_CHAR-STAT-CS not supported + I_CHAR-DYN-CS not supported + */ + printf("INIT test\n"); + buf[0] = 0x01; + buf[1] = 0x40; + buf[2] = 0x80; + v150_1_test_rx_sprt_msg(v150_1, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, 0, buf, 3); + + v150_1_tx_init(v150_1); + + v150_1_tx_jm_info(v150_1); + /* The following MR-EVENT message + Selected modulation V.32 + Tx data signalling rate 9600 + Rx data signalling rate 9600 + */ + printf("MR-EVENT test\n"); + buf[0] = 0x08; + buf[1] = 0x03; + buf[2] = 0x00; + buf[3] = 0x18; + buf[4] = 0x25; + buf[5] = 0x80; + buf[6] = 0x25; + buf[7] = 0x80; + buf[8] = 0x00; + buf[9] = 0x00; + v150_1_test_rx_sprt_msg(v150_1, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, 1, buf, 10); + + v150_1_tx_mr_event(v150_1, V150_1_MR_EVENT_ID_PHYSUP); + + /* The following CONNECT message should say: + Modulation V.32 + Compression direction Neither way + Compression None + Error correction None + Tx data rate 9600 + Rx data rate 9600 + I_RAW-CHAR available + I_RAW-BIT not available + I_FRAME not available + I_OCTET not available + I_CHAR-STAT not available + I_CHAR-DYN not available + I_OCTET-CS available + I_CHAR-STAT-CS not available + I_CHAR-DYN-CS not available + */ + printf("CONNECT test\n"); + buf[0] = 0x05; + buf[1] = 0x18; + buf[2] = 0x00; + buf[3] = 0x25; + buf[4] = 0x80; + buf[5] = 0x25; + buf[6] = 0x80; + buf[7] = 0x02; + buf[8] = 0x00; + v150_1_test_rx_sprt_msg(v150_1, SPRT_TCID_EXPEDITED_RELIABLE_SEQUENCED, 2, buf, 9); + + v150_1_tx_connect(v150_1); + + //v150_1_tx_xid_xchg(v150_1); + //v150_1_tx_start_jm(v150_1); + //v150_1_tx_prof_xchg(v150_1); + + if (v150_1_tx_info_stream(v150_1, (const uint8_t *) "Test side 0", 11) < 0) + fprintf(stderr, "Failed to send good message\n"); + /*endif*/ + + for (i = 0; i < 256; i++) + buf[i] = i; + /*endfor*/ + if (v150_1_tx_info_stream(v150_1, buf, 129) < 0) + fprintf(stderr, "Failed to send good message\n"); + /*endif*/ + + for (i = 0; i < 256; i++) + buf[i] = 255 - i; + /*endfor*/ + if (v150_1_tx_info_stream(v150_1, buf, 129) < 0) + fprintf(stderr, "Failed to send good message\n"); + /*endif*/ + + for (i = 0; i < 256; i++) + buf[i] = 255 - i; + /*endfor*/ + if (v150_1_tx_info_stream(v150_1, buf, 198) >= 0) + fprintf(stderr, "Able to send bad length message\n"); + /*endif*/ + + for (i = 0; i < 256; i++) + buf[i] = i; + /*endfor*/ + if (v150_1_tx_info_stream(v150_1, buf, 129) < 0) + fprintf(stderr, "Failed to send byte stream\n"); + /*endif*/ + + v150_1_tx_break(v150_1, V150_1_BREAK_SOURCE_V42_LAPM, V150_1_BREAK_TYPE_DESTRUCTIVE_EXPEDITED, 1230); + v150_1_tx_break_ack(v150_1); + v150_1_tx_cleardown(v150_1, V150_1_CLEARDOWN_REASON_LINK_LAYER_DISCONNECT); + + v150_1_tx_cleardown(v150_1, V150_1_CLEARDOWN_REASON_LINK_LAYER_DISCONNECT); + + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int state_machine_tests(void) +{ + //v150_1_state_machine(v150_1, V150_1_SIGNAL_ANS, NULL, 0); + //v150_1_state_machine(v150_1, V150_1_SIGNAL_ANS, NULL, 0); + v150_1_state_machine(v150_1, V150_1_SIGNAL_CM, NULL, 0); + v150_1_state_machine(v150_1, V150_1_SIGNAL_MODEM_RELAY, NULL, 0); + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int dynamic_tests(void) +{ + socket_dgram_harness_timer = + pace_timer = now_us() + 20000; + socket_dgram_harness_run(dgram_state); + return 0; +} +/*- End of function --------------------------------------------------------*/ + +static int v150_1_tests(void) +{ + logging_state_t *logging; + int msg_id_priorities[10]; + int i; + int max; + + if ((dgram_state = socket_dgram_harness_init(NULL, + (calling_party) ? "/tmp/v150_1_socket_a" : "/tmp/v150_1_socket_b", + (calling_party) ? "/tmp/v150_1_socket_b" : "/tmp/v150_1_socket_a", + (calling_party) ? "C" : "A", + calling_party, + terminal_callback, + termios_callback, + hangup_callback, + terminal_free_space_callback, + dgram_rx_callback, + tx_callback, + timer_callback, + NULL)) == NULL) + { + fprintf(stderr, " Cannot start the socket harness\n"); + exit(2); + } + /*endif*/ + + if ((v150_1 = v150_1_init(NULL, + sprt_tx_packet_handler, + (void *) dgram_state, + 120, + 120, + sse_tx_packet_handler, + (void *) dgram_state, + v150_1_timer_handler, + NULL, + v150_1_data_stream_handler, + NULL, + v150_1_status_report_handler, + NULL)) == NULL) + { + fprintf(stderr, " Cannot start V.150.1\n"); + exit(2); + } + /*endif*/ + + logging = sprt_get_logging_state(&v150_1->sprt); + span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_DATE); + span_log_set_tag(logging, (calling_party) ? "C" : "A"); + + logging = v150_1_get_logging_state(v150_1); + span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_PROTOCOL | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_DATE); + span_log_set_tag(logging, (calling_party) ? "C" : "A"); + + v150_1_set_info_stream_tx_mode(v150_1, SPRT_TCID_RELIABLE_SEQUENCED, V150_1_MSGID_I_OCTET_CS); + + msg_id_priorities[0] = V150_1_MSGID_I_OCTET_CS; + msg_id_priorities[1] = V150_1_MSGID_I_OCTET; + msg_id_priorities[2] = -1; + v150_1_set_info_stream_msg_priorities(v150_1, msg_id_priorities); + + v150_1_set_modulation(v150_1, V150_1_SELMOD_V34); + v150_1_set_compression_direction(v150_1, V150_1_COMPRESS_NEITHER_WAY); + v150_1_set_compression(v150_1, V150_1_COMPRESSION_NONE); + v150_1_set_compression_parameters(v150_1, + 512, + 512, + 6, + 6, + 0, + 0); + v150_1_set_error_correction(v150_1, V150_1_ERROR_CORRECTION_NONE); + v150_1_set_tx_symbol_rate(v150_1, true, V150_1_SYMBOL_RATE_3429); + v150_1_set_rx_symbol_rate(v150_1, true, V150_1_SYMBOL_RATE_3429); + v150_1_set_tx_data_signalling_rate(v150_1, 33600); + v150_1_set_rx_data_signalling_rate(v150_1, 33600); + + v150_1_set_sse_reliability_method(v150_1, + V150_1_SSE_RELIABILITY_BY_REPETITION, + 3, + 100000, + 0); + + v150_1_set_near_cdscselect(v150_1, V150_1_CDSCSELECT_AUDIO_RFC4733); + v150_1_set_far_cdscselect(v150_1, V150_1_CDSCSELECT_MIXED); + + for (i = SPRT_TCID_MIN; i <= SPRT_TCID_MAX; i++) + { + max_payloads[i] = sprt_get_far_tc_payload_bytes(&v150_1->sprt, i); + fprintf(stderr, "Max payload %d is %d\n", i, max_payloads[i]); + } + /*endfor*/ + + socket_dgram_harness_set_user_data(dgram_state, v150_1); + + if (v150_1_set_local_tc_payload_bytes(v150_1, SPRT_TCID_RELIABLE_SEQUENCED, 256) < 0) + fprintf(stderr, "Failed to set new max payload bytes\n"); + /*endif*/ + if (v150_1_set_local_tc_payload_bytes(v150_1, SPRT_TCID_RELIABLE_SEQUENCED, 257) >= 0) + fprintf(stderr, "Able to set bad new max payload bytes\n"); + /*endif*/ + if (v150_1_set_local_tc_payload_bytes(v150_1, SPRT_TCID_RELIABLE_SEQUENCED, 132) < 0) + fprintf(stderr, "Failed to set new max payload bytes\n"); + /*endif*/ + if (v150_1_set_local_tc_payload_bytes(v150_1, SPRT_TCID_RELIABLE_SEQUENCED, 131) >= 0) + fprintf(stderr, "Able to set bad new max payload bytes\n"); + /*endif*/ + + max = v150_1_get_local_tc_payload_bytes(v150_1, SPRT_TCID_RELIABLE_SEQUENCED); + fprintf(stderr, "Max payload bytes is %d\n", max); + + rtp_init(&rtp, 0, 0x12345678); + + //message_decode_tests(); + message_encode_tests(); + //state_machine_tests(); + //dynamic_tests(); + + return 0; +} +/*- End of function --------------------------------------------------------*/ + +int main(int argc, char *argv[]) +{ + int opt; + + calling_party = false; + while ((opt = getopt(argc, argv, "ac")) != -1) + { + switch (opt) + { + case 'a': + calling_party = false; + break; + case 'c': + calling_party = true; + break; + default: + //usage(); + exit(2); + break; + } + /*endswitch*/ + } + /*endwhile*/ + + if (v150_1_tests()) + exit(2); + /*endif*/ + fprintf(stderr, "Tests passed\n"); return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/v17_tests.c b/tests/v17_tests.c index 27437212..17c7fcb8 100644 --- a/tests/v17_tests.c +++ b/tests/v17_tests.c @@ -109,6 +109,7 @@ static void reporter(void *user_data, int reason, bert_results_t *results) fprintf(stderr, "BERT report %s\n", bert_event_to_str(reason)); break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -133,14 +134,19 @@ static void v17_rx_status(void *user_data, int status) { printf("Equalizer:\n"); for (i = 0; i < len; i++) + { #if defined(SPANDSP_USE_FIXED_POINT) printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/V17_CONSTELLATION_SCALING_FACTOR, coeffs[i].im/V17_CONSTELLATION_SCALING_FACTOR); #else printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif + } + /*endfor*/ } + /*endif*/ break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -151,11 +157,13 @@ static void v17putbit(void *user_data, int bit) v17_rx_status(user_data, bit); return; } + /*endif*/ if (decode_test_file) printf("Rx bit %d - %d\n", rx_bits++, bit); else bert_put_bit(&bert, bit); + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -208,6 +216,7 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex qam_monitor_update_carrier_tracking(qam_monitor, v17_rx_carrier_frequency(rx)); qam_monitor_update_symbol_tracking(qam_monitor, v17_rx_symbol_timing_correction(rx)); } + /*endif*/ #endif printf("%8d [%8.4f, %8.4f] [%8.4f, %8.4f] %2x %8.4f %8.4f %9.4f %7.3f %7.4f\n", symbol_no, @@ -242,11 +251,15 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex qam_monitor_update_equalizer(qam_monitor, coeffs, len); #endif } + /*endif*/ #endif } + /*endif*/ update_interval = 100; } + /*endif*/ } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -283,11 +296,13 @@ static void sigfpe_handler(int sig_num, siginfo_t *info, void *data) fprintf(stderr, "subscript out of range at %p\n", info->si_addr); break; } + /*endswitch*/ break; default: fprintf(stderr, "Unexpected signal %d\n", sig_num); break; } + /*endswitch*/ exit(2); } /*- End of function --------------------------------------------------------*/ @@ -362,6 +377,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Invalid bit rate specified\n"); exit(2); } + /*endif*/ break; case 'B': bits_per_test = atoi(optarg); @@ -403,7 +419,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ inhandle = NULL; outhandle = NULL; @@ -418,7 +436,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ if (decode_test_file) { @@ -429,6 +449,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ } else { @@ -453,11 +474,13 @@ int main(int argc, char *argv[]) fprintf(stderr, " Failed to create line model\n"); exit(2); } + /*endif*/ one_way_line_model_set_dc(line_model, 0.0f); #if defined(ADD_MAINS_INTERFERENCE) one_way_line_model_set_mains_pickup(line_model, 50, -40.0f); #endif } + /*endif*/ rx = v17_rx_init(NULL, test_bps, v17putbit, NULL); logging = v17_rx_get_logging_state(rx); @@ -475,7 +498,9 @@ int main(int argc, char *argv[]) start_line_model_monitor(129); line_model_monitor_line_model_update(line_model->near_filter, line_model->near_filter_len); } + /*endif*/ } + /*endif*/ #endif memset(&latest_results, 0, sizeof(latest_results)); @@ -487,9 +512,11 @@ int main(int argc, char *argv[]) #if defined(ENABLE_GUI) if (use_gui) qam_monitor_update_audio_level(qam_monitor, amp, samples); + /*endif*/ #endif if (samples == 0) break; + /*endif*/ } else { @@ -523,6 +550,7 @@ int main(int argc, char *argv[]) { break; } + /*endif*/ memset(&latest_results, 0, sizeof(latest_results)); #if defined(SPANDSP_EXPOSE_INTERNAL_STRUCTURES) signal_level--; @@ -541,7 +569,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Failed to create line model\n"); exit(2); } + /*endif*/ } + /*endif*/ if (log_audio) { outframes = sf_writef_short(outhandle, gen_amp, samples); @@ -550,12 +580,16 @@ int main(int argc, char *argv[]) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } + /*endif*/ one_way_line_model(line_model, amp, gen_amp, samples); } + /*endif*/ #if defined(ENABLE_GUI) if (use_gui && !decode_test_file) line_model_monitor_line_spectrum_update(amp, samples); + /*endif*/ #endif v17_rx(rx, amp, samples); } @@ -572,15 +606,19 @@ int main(int argc, char *argv[]) printf("Tests failed.\n"); exit(2); } + /*endif*/ printf("Tests passed.\n"); } + /*endif*/ v17_rx_free(rx); if (tx) v17_tx_free(tx); + /*endif*/ #if defined(ENABLE_GUI) if (use_gui) qam_wait_to_end(qam_monitor); + /*endif*/ #endif if (decode_test_file) { @@ -589,7 +627,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ } + /*endif*/ if (log_audio) { if (sf_close_telephony(outhandle)) @@ -597,7 +637,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/v22bis_tests.c b/tests/v22bis_tests.c index 0a29ca6d..8f56314d 100644 --- a/tests/v22bis_tests.c +++ b/tests/v22bis_tests.c @@ -106,6 +106,7 @@ static void reporter(void *user_data, int reason, bert_results_t *results) bert_event_to_str(reason)); break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -133,14 +134,19 @@ static void v22bis_rx_status(void *user_data, int status) { printf("Equalizer:\n"); for (i = 0; i < len; i++) + { #if defined(SPANDSP_USE_FIXED_POINT) printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/V22BIS_CONSTELLATION_SCALING_FACTOR, coeffs[i].im/V22BIS_CONSTELLATION_SCALING_FACTOR); #else printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif + } + /*endif*/ } + /*endif*/ break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -153,12 +159,14 @@ static void v22bis_putbit(void *user_data, int bit) v22bis_rx_status(user_data, bit); return; } + /*endif*/ s = (endpoint_t *) user_data; if (decode_test_file) printf("Rx bit %p-%d - %d\n", user_data, rx_bits++, bit); else bert_put_bit(&s->bert_rx, bit); + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -205,6 +213,7 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex qam_monitor_update_carrier_tracking(s->qam_monitor, v22bis_rx_carrier_frequency(s->v22bis)); qam_monitor_update_symbol_tracking(s->qam_monitor, v22bis_rx_symbol_timing_correction(s->v22bis)); } + /*endif*/ #endif fpower = (constel_point.re - target_point.re)*(constel_point.re - target_point.re) + (constel_point.im - target_point.im)*(constel_point.im - target_point.im); @@ -229,12 +238,15 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex { printf("Equalizer A:\n"); for (i = 0; i < len; i++) + { #if defined(SPANDSP_USE_FIXED_POINT) printf("%3d (%15.5f, %15.5f)\n", i, coeffs[i].re/V22BIS_CONSTELLATION_SCALING_FACTOR, coeffs[i].im/V22BIS_CONSTELLATION_SCALING_FACTOR); #else printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif #if defined(ENABLE_GUI) + } + /*endfor*/ if (use_gui) { #if defined(SPANDSP_USE_FIXED_POINT) @@ -243,9 +255,12 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex qam_monitor_update_equalizer(s->qam_monitor, coeffs, len); #endif } + /*endif*/ #endif } + /*endif*/ } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -293,6 +308,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Invalid bit rate specified\n"); exit(2); } + /*endif*/ break; case 'B': bits_per_test = atoi(optarg); @@ -334,7 +350,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ inhandle = NULL; if (decode_test_file) { @@ -344,7 +362,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ } + /*endif*/ outhandle = NULL; if (log_audio) @@ -354,7 +374,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ memset(endpoint, 0, sizeof(endpoint)); for (i = 0; i < 2; i++) @@ -372,6 +394,7 @@ int main(int argc, char *argv[]) bert_init(&endpoint[i].bert_rx, bits_per_test, BERT_PATTERN_ITU_O152_11, test_bps, 20); bert_set_report(&endpoint[i].bert_rx, 10000, reporter, &endpoint[i]); } + /*endfor*/ #if defined(ENABLE_GUI) if (use_gui) @@ -379,6 +402,7 @@ int main(int argc, char *argv[]) endpoint[0].qam_monitor = qam_monitor_init(6.0f, V22BIS_CONSTELLATION_SCALING_FACTOR, "Calling modem"); endpoint[1].qam_monitor = qam_monitor_init(6.0f, V22BIS_CONSTELLATION_SCALING_FACTOR, "Answering modem"); } + /*endif*/ #endif if ((model = both_ways_line_model_init(line_model_no, (float) noise_level, @@ -394,6 +418,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Failed to create line model\n"); exit(2); } + /*endif*/ samples = 0; for (;;) { @@ -416,7 +441,9 @@ int main(int argc, char *argv[]) printf("Restarting on zero output\n"); v22bis_restart(endpoint[i].v22bis, test_bps); } + /*endif*/ } + /*endfor*/ #if 1 both_ways_line_model(model, @@ -434,16 +461,21 @@ int main(int argc, char *argv[]) samples2 = sf_readf_short(inhandle, model_amp[0], samples); if (samples2 != samples) break; + /*endif*/ } + /*endif*/ for (i = 0; i < 2; i++) { span_log_bump_samples(&endpoint[i].v22bis->logging, samples); v22bis_rx(endpoint[i ^ 1].v22bis, model_amp[i], samples); for (j = 0; j < samples; j++) out_amp[2*j + i] = model_amp[i][j]; + /*endfor*/ for ( ; j < BLOCK_LEN; j++) out_amp[2*j + i] = 0; + /*endfor*/ } + /*endfor*/ if (log_audio) { @@ -453,12 +485,16 @@ int main(int argc, char *argv[]) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } + /*endif*/ } + /*endfor*/ both_ways_line_model_free(model); #if defined(ENABLE_GUI) if (use_gui) qam_wait_to_end(endpoint[0].qam_monitor); + /*endif*/ #endif if (decode_test_file) { @@ -467,7 +503,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ } + /*endif*/ if (log_audio) { if (sf_close_telephony(outhandle)) @@ -475,7 +513,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/v27ter_tests.c b/tests/v27ter_tests.c index edac945a..14b06f88 100644 --- a/tests/v27ter_tests.c +++ b/tests/v27ter_tests.c @@ -105,6 +105,7 @@ static void reporter(void *user_data, int reason, bert_results_t *results) fprintf(stderr, "BERT report %s\n", bert_event_to_str(reason)); break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -133,9 +134,12 @@ static void v27ter_rx_status(void *user_data, int status) #else printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif + /*endfor*/ } + /*endif*/ break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -146,11 +150,13 @@ static void v27terputbit(void *user_data, int bit) v27ter_rx_status(user_data, bit); return; } + /*endif*/ if (decode_test_file) printf("Rx bit %d - %d\n", rx_bits++, bit); else bert_put_bit(&bert, bit); + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -231,6 +237,7 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex #else printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif + /*endfor*/ #if defined(ENABLE_GUI) if (use_gui) { @@ -240,10 +247,13 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex qam_monitor_update_equalizer(qam_monitor, coeffs, len); #endif } + /*endif*/ #endif } + /*endif*/ update_interval = 100; } + /*endif*/ } else { @@ -257,6 +267,7 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex #else printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif + /*endfor*/ #if defined(ENABLE_GUI) if (use_gui) { @@ -266,9 +277,12 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex qam_monitor_update_equalizer(qam_monitor, coeffs, len); #endif } + /*endif*/ #endif } + /*endif*/ } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -305,11 +319,13 @@ static void sigfpe_handler(int sig_num, siginfo_t *info, void *data) fprintf(stderr, "subscript out of range at %p\n", info->si_addr); break; } + /*endswitch*/ break; default: fprintf(stderr, "Unexpected signal %d\n", sig_num); break; } + /*endswitch*/ exit(2); } /*- End of function --------------------------------------------------------*/ @@ -376,6 +392,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Invalid bit rate specified\n"); exit(2); } + /*endif*/ break; case 'B': bits_per_test = atoi(optarg); @@ -417,7 +434,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ inhandle = NULL; outhandle = NULL; @@ -432,7 +451,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ if (decode_test_file) { @@ -443,6 +464,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ } else { @@ -465,7 +487,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Failed to create line model\n"); exit(2); } + /*endif*/ } + /*endif*/ rx = v27ter_rx_init(NULL, test_bps, v27terputbit, NULL); logging = v27ter_rx_get_logging_state(rx); @@ -483,7 +507,9 @@ int main(int argc, char *argv[]) start_line_model_monitor(129); line_model_monitor_line_model_update(line_model->near_filter, line_model->near_filter_len); } + /*endif*/ } + /*endif*/ #endif memset(&latest_results, 0, sizeof(latest_results)); @@ -498,6 +524,7 @@ int main(int argc, char *argv[]) #endif if (samples == 0) break; + /*endif*/ } else { @@ -505,6 +532,7 @@ int main(int argc, char *argv[]) #if defined(ENABLE_GUI) if (use_gui) qam_monitor_update_audio_level(qam_monitor, gen_amp, samples); + /*endif*/ #endif if (samples == 0) { @@ -533,6 +561,7 @@ int main(int argc, char *argv[]) { break; } + /*endif*/ memset(&latest_results, 0, sizeof(latest_results)); signal_level--; v27ter_tx_restart(tx, test_bps, tep); @@ -546,7 +575,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Failed to create line model\n"); exit(2); } + /*endif*/ } + /*endif*/ if (log_audio) { @@ -556,15 +587,20 @@ int main(int argc, char *argv[]) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } + /*endif*/ one_way_line_model(line_model, amp, gen_amp, samples); } + /*endif*/ #if defined(ENABLE_GUI) if (use_gui && !decode_test_file) line_model_monitor_line_spectrum_update(amp, samples); + /*endif*/ #endif v27ter_rx(rx, amp, samples); } + /*endfor*/ if (!decode_test_file) { bert_result(&bert, &bert_results); @@ -578,12 +614,15 @@ int main(int argc, char *argv[]) printf("Tests failed.\n"); exit(2); } + /*endif*/ printf("Tests passed.\n"); } + /*endif*/ v27ter_rx_free(rx); if (tx) v27ter_tx_free(tx); + /*endif*/ bert_release(&bert); #if defined(ENABLE_GUI) if (use_gui) @@ -596,7 +635,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ } + /*endif*/ if (log_audio) { if (sf_close_telephony(outhandle)) @@ -604,7 +645,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/v29_tests.c b/tests/v29_tests.c index ba5639e0..390663f3 100644 --- a/tests/v29_tests.c +++ b/tests/v29_tests.c @@ -104,6 +104,7 @@ static void reporter(void *user_data, int reason, bert_results_t *results) fprintf(stderr, "BERT report %s\n", bert_event_to_str(reason)); break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -133,9 +134,12 @@ static void v29_rx_status(void *user_data, int status) #else printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif + /*endfor*/ } + /*endif*/ break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -146,11 +150,13 @@ static void v29putbit(void *user_data, int bit) v29_rx_status(user_data, bit); return; } + /*endif*/ if (decode_test_file) printf("Rx bit %d - %d\n", rx_bits++, bit); else bert_put_bit(&bert, bit); + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -230,6 +236,7 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif #if defined(ENABLE_GUI) + /*endfor*/ if (use_gui) { #if defined(SPANDSP_USE_FIXED_POINT) @@ -238,11 +245,15 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex qam_monitor_update_equalizer(qam_monitor, coeffs, len); #endif } + /*endif*/ #endif } + /*endif*/ update_interval = 100; } + /*endif*/ } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -279,11 +290,13 @@ static void sigfpe_handler(int sig_num, siginfo_t *info, void *data) fprintf(stderr, "subscript out of range at %p\n", info->si_addr); break; } + /*endswitch*/ break; default: fprintf(stderr, "Unexpected signal %d\n", sig_num); break; } + /*endswitch*/ exit(2); } /*- End of function --------------------------------------------------------*/ @@ -391,7 +404,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ inhandle = NULL; outhandle = NULL; @@ -406,7 +421,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ if (decode_test_file) { @@ -417,6 +434,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot open audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ } else { @@ -441,7 +459,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Failed to create line model\n"); exit(2); } + /*endif*/ } + /*endif*/ rx = v29_rx_init(NULL, test_bps, v29putbit, NULL); logging = v29_rx_get_logging_state(rx); @@ -464,7 +484,9 @@ int main(int argc, char *argv[]) start_line_model_monitor(129); line_model_monitor_line_model_update(line_model->near_filter, line_model->near_filter_len); } + /*endif*/ } + /*endif*/ #endif memset(&latest_results, 0, sizeof(latest_results)); @@ -479,6 +501,7 @@ int main(int argc, char *argv[]) #endif if (samples == 0) break; + /*endif*/ } else { @@ -510,6 +533,7 @@ int main(int argc, char *argv[]) { break; } + /*endif*/ memset(&latest_results, 0, sizeof(latest_results)); signal_level--; v29_tx_restart(tx, test_bps, tep); @@ -526,7 +550,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Failed to create line model\n"); exit(2); } + /*endif*/ } + /*endif*/ if (log_audio) { outframes = sf_writef_short(outhandle, gen_amp, samples); @@ -535,15 +561,20 @@ int main(int argc, char *argv[]) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } + /*endif*/ one_way_line_model(line_model, amp, gen_amp, samples); } + /*endif*/ #if defined(ENABLE_GUI) if (use_gui && !decode_test_file) line_model_monitor_line_spectrum_update(amp, samples); + /*endif*/ #endif v29_rx(rx, amp, samples); } + /*endfor*/ if (!decode_test_file) { bert_result(&bert, &bert_results); @@ -557,12 +588,15 @@ int main(int argc, char *argv[]) printf("Tests failed.\n"); exit(2); } + /*endif*/ printf("Tests passed.\n"); } + /*endif*/ v29_rx_free(rx); if (tx) v29_tx_free(tx); + /*endif*/ bert_release(&bert); #if defined(ENABLE_GUI) if (use_gui) @@ -575,6 +609,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", decode_test_file); exit(2); } + /*endif*/ } if (log_audio) { @@ -583,7 +618,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/v32bis_tests.c b/tests/v32bis_tests.c index 56e2a727..d4f7ae2b 100644 --- a/tests/v32bis_tests.c +++ b/tests/v32bis_tests.c @@ -105,6 +105,7 @@ static void reporter(void *user_data, int reason, bert_results_t *results) fprintf(stderr, "%p - BERT report %s\n", user_data, bert_event_to_str(reason)); break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -132,8 +133,10 @@ static void v32bis_rx_status(void *user_data, int status) #else printf("%p: %3d (%15.5f, %15.5f) -> %15.5f\n", user_data, i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif + /*endfor*/ break; } + /*endswitch*/ } /*- End of function --------------------------------------------------------*/ @@ -144,6 +147,7 @@ static void v32bis_putbit(void *user_data, int bit) v32bis_rx_status(user_data, bit); return; } + /*endif*/ if (decode_test_file) { @@ -155,7 +159,9 @@ static void v32bis_putbit(void *user_data, int bit) bert_put_bit(&caller_bert, bit); else bert_put_bit(&answerer_bert, bit); + /*endif*/ } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -163,6 +169,7 @@ static int v32bis_getbit(void *user_data) { if (user_data == (void *) &caller) return bert_get_bit(&caller_bert); + /*endif*/ return bert_get_bit(&answerer_bert); } /*- End of function --------------------------------------------------------*/ @@ -202,6 +209,7 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex qam_monitor_update_carrier_tracking(s->qam_monitor, v32bis_rx_carrier_frequency(s->s)); qam_monitor_update_symbol_tracking(s->qam_monitor, v32bis_rx_symbol_timing_correction(s->s)); } + /*endif*/ #endif printf("%8d [%8.4f, %8.4f] [%8.4f, %8.4f] %2x %8.4f %8.4f %9.4f %7.3f %7.4f\n", s->symbol_no, @@ -229,6 +237,7 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex #else printf("%3d (%15.5f, %15.5f) -> %15.5f\n", i, coeffs[i].re, coeffs[i].im, powerf(&coeffs[i])); #endif + /*endfor*/ #if defined(ENABLE_GUI) if (use_gui) { @@ -238,6 +247,7 @@ static void qam_report(void *user_data, const complexf_t *constel, const complex qam_monitor_update_equalizer(s->qam_monitor, coeffs, len); #endif } + /*endif*/ #endif } } @@ -294,6 +304,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Invalid bit rate specified\n"); exit(2); } + /*endif*/ break; case 'B': bits_per_test = atoi(optarg); @@ -329,7 +340,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ outhandle = NULL; if (log_audio) @@ -339,7 +352,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot create audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ v32bis_init(&caller, test_bps, true, v32bis_getbit, &caller, v32bis_putbit, &caller); v32bis_tx_power(&caller, signal_level); @@ -373,6 +388,7 @@ int main(int argc, char *argv[]) qam_caller.qam_monitor = qam_monitor_init(10.0f, V32BIS_CONSTELLATION_SCALING_FACTOR, "Calling modem"); qam_answerer.qam_monitor = qam_monitor_init(10.0f, V32BIS_CONSTELLATION_SCALING_FACTOR, "Answering modem"); } + /*endif*/ #endif bert_init(&caller_bert, bits_per_test, BERT_PATTERN_ITU_O152_11, test_bps, 20); bert_set_report(&caller_bert, 10000, reporter, &caller); @@ -392,6 +408,7 @@ int main(int argc, char *argv[]) fprintf(stderr, " Failed to create line model\n"); exit(2); } + /*endif*/ for (;;) { samples = v32bis_tx(&caller, caller_amp, BLOCK_LEN); @@ -408,11 +425,13 @@ int main(int argc, char *argv[]) bert_init(&answerer_bert, bits_per_test, BERT_PATTERN_ITU_O152_11, test_bps, 20); bert_set_report(&answerer_bert, 10000, reporter, &answerer); } + /*endif*/ samples = v32bis_tx(&answerer, answerer_amp, BLOCK_LEN); #if defined(ENABLE_GUI) if (use_gui) qam_monitor_update_audio_level(qam_answerer.qam_monitor, answerer_amp, samples); + /*endif*/ #endif if (samples == 0) { @@ -423,6 +442,7 @@ int main(int argc, char *argv[]) bert_init(&answerer_bert, bits_per_test, BERT_PATTERN_ITU_O152_11, test_bps, 20); bert_set_report(&answerer_bert, 10000, reporter, &answerer); } + /*endif*/ both_ways_line_model(model, caller_model_amp, caller_amp, @@ -432,14 +452,18 @@ int main(int argc, char *argv[]) v32bis_rx(&answerer, caller_model_amp, samples); for (i = 0; i < samples; i++) out_amp[2*i] = caller_model_amp[i]; + /*endfor*/ for ( ; i < BLOCK_LEN; i++) out_amp[2*i] = 0; + /*endfor*/ v32bis_rx(&caller, answerer_model_amp, samples); for (i = 0; i < samples; i++) out_amp[2*i + 1] = answerer_model_amp[i]; + /*endfor*/ for ( ; i < BLOCK_LEN; i++) out_amp[2*i + 1] = 0; + /*endfor*/ if (log_audio) { @@ -449,8 +473,11 @@ int main(int argc, char *argv[]) fprintf(stderr, " Error writing audio file\n"); exit(2); } + /*endif*/ } + /*endif*/ } + /*endfor*/ if (!decode_test_file) { bert_result(&answerer_bert, &bert_results); @@ -465,9 +492,11 @@ int main(int argc, char *argv[]) printf("Tests failed.\n"); exit(2); } + /*endif*/ printf("Tests passed.\n"); } + /*endif*/ v32bis_free(&caller); v32bis_free(&answerer); if (log_audio) @@ -477,7 +506,9 @@ int main(int argc, char *argv[]) fprintf(stderr, " Cannot close audio file '%s'\n", OUT_FILE_NAME); exit(2); } + /*endif*/ } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/v34_tests.c b/tests/v34_tests.c index 927f439f..75df1930 100644 --- a/tests/v34_tests.c +++ b/tests/v34_tests.c @@ -486,6 +486,7 @@ static void v34_mapping_frame_tests(int test_baud_rate, int test_bps, bool duple { printf("Bits %d %d\n", bits[2*j], bits[2*j + 1]); } + /*endfor*/ #endif v34_put_mapping_frame(&v34_caller.rx, bits); } diff --git a/tests/v42_tests.c b/tests/v42_tests.c index 727b5a8b..abb8d57b 100644 --- a/tests/v42_tests.c +++ b/tests/v42_tests.c @@ -63,6 +63,7 @@ static void v42_status(void *user_data, int status) printf("%p: Status is '%s' (%d)\n", s, signal_status_to_str(status), status); else printf("%p: Status is '%s' (%d)\n", s, lapm_status_to_str(status), status); + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -79,6 +80,7 @@ static int v42_get_frames(void *user_data, uint8_t msg[], int len) v42_status(user_data, len); return 0; } + /*endif*/ s = (v42_state_t *) user_data; x = (s == caller) ? 1 : 2; if (variable_length) @@ -92,8 +94,10 @@ static int v42_get_frames(void *user_data, uint8_t msg[], int len) { k = len; } + /*endif*/ for (i = 0; i < k; i++) msg[i] = tx_next[x]++; + /*endfor*/ return k; } /*- End of function --------------------------------------------------------*/ @@ -111,6 +115,7 @@ static void v42_put_frames(void *user_data, const uint8_t msg[], int len) v42_status(user_data, len); return; } + /*endif*/ s = (v42_state_t *) user_data; x = (s == caller) ? 1 : 2; for (i = 0; i < len; i++) @@ -120,8 +125,10 @@ static void v42_put_frames(void *user_data, const uint8_t msg[], int len) printf("%p: Mismatch 0x%02X 0x%02X\n", user_data, msg[i], rx_next[x] & 0xFF); exit(2); } + /*endif*/ rx_next[x]++; } + /*endfor*/ printf("%p: Got frame len %d\n", user_data, len); printf("%p: %d Far end busy status %d\n", user_data, count, v42_get_far_busy_status(s)); if (s == caller) @@ -131,12 +138,15 @@ static void v42_put_frames(void *user_data, const uint8_t msg[], int len) v42_set_local_busy_status(s, true); xxx = 1; } + /*endif*/ } else { if (xxx && ++count == 45) v42_set_local_busy_status(caller, false); + /*endif*/ } + /*endif*/ } /*- End of function --------------------------------------------------------*/ @@ -167,7 +177,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ caller = v42_init(&callerx, true, true, v42_get_frames, v42_put_frames, (void *) &callerx); answerer = v42_init(&answererx, false, true, v42_get_frames, v42_put_frames, (void *) &answererx); @@ -186,12 +198,15 @@ int main(int argc, char *argv[]) bit = v42_tx_bit(caller); if (insert_caller_bit_errors && i%insert_caller_bit_errors == 0) bit ^= 1; + /*endif*/ v42_rx_bit(answerer, bit); bit = v42_tx_bit(answerer); if (insert_answerer_bit_errors && i%insert_answerer_bit_errors == 0) bit ^= 1; + /*endif*/ v42_rx_bit(caller, bit); } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/v42bis_tests.c b/tests/v42bis_tests.c index 253cbcb4..d3ebe0b6 100644 --- a/tests/v42bis_tests.c +++ b/tests/v42bis_tests.c @@ -60,6 +60,7 @@ static void frame_handler(void *user_data, const uint8_t *buf, int len) if ((ret = write((intptr_t) user_data, buf, len)) != len) fprintf(stderr, "Write error %d/%d\n", ret, errno); + /*endif*/ out_octets_to_date += len; } @@ -69,6 +70,7 @@ static void data_handler(void *user_data, const uint8_t *buf, int len) if ((ret = write((intptr_t) user_data, buf, len)) != len) fprintf(stderr, "Write error %d/%d\n", ret, errno); + /*endif*/ out_octets_to_date += len; } @@ -115,7 +117,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ argc -= optind; argv += optind; if (argc < 1) @@ -123,6 +127,7 @@ int main(int argc, char *argv[]) fprintf(stderr, "Usage: %s [-c] [-d] [-s] []\n", argv0); exit(2); } + /*endif*/ if (do_compression) { original_file = argv[0]; @@ -133,6 +138,7 @@ int main(int argc, char *argv[]) original_file = NULL; compressed_file = argv[0]; } + /*endif*/ decompressed_file = (argc > 1) ? argv[1] : DECOMPRESSED_FILE_NAME; if (do_compression) { @@ -142,11 +148,13 @@ int main(int argc, char *argv[]) fprintf(stderr, "Error opening file '%s'.\n", original_file); exit(2); } + /*endif*/ if ((v42bis_fd = open(compressed_file, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) { fprintf(stderr, "Error opening file '%s'.\n", compressed_file); exit(2); } + /*endif*/ time(&now); state_a = v42bis_init(NULL, 3, 512, 6, frame_handler, (void *) (intptr_t) v42bis_fd, 512, data_handler, NULL, 512); @@ -167,23 +175,29 @@ int main(int argc, char *argv[]) fprintf(stderr, "Bad return code from compression\n"); exit(2); } + /*endif*/ v42bis_compress_flush(state_a); seg += stutter_time; stutter_time = rand() & 0x3FF; } + /*endwhile*/ } + /*endif*/ if (v42bis_compress(state_a, buf + seg, len - seg)) { fprintf(stderr, "Bad return code from compression\n"); exit(2); } + /*endif*/ in_octets_to_date += len; } + /*endwhile*/ v42bis_compress_flush(state_a); printf("%d bytes compressed to %d bytes in %lds\n", in_octets_to_date, out_octets_to_date, time(NULL) - now); close(in_fd); close(v42bis_fd); } + /*endif*/ if (do_decompression) { @@ -193,11 +207,13 @@ int main(int argc, char *argv[]) fprintf(stderr, "Error opening file '%s'.\n", compressed_file); exit(2); } + /*endif*/ if ((out_fd = open(decompressed_file, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) { fprintf(stderr, "Error opening file '%s'.\n", decompressed_file); exit(2); } + /*endif*/ time(&now); state_b = v42bis_init(NULL, 3, 512, 6, frame_handler, (void *) (intptr_t) v42bis_fd, 512, data_handler, (void *) (intptr_t) out_fd, 512); @@ -212,13 +228,16 @@ int main(int argc, char *argv[]) fprintf(stderr, "Bad return code from decompression\n"); exit(2); } + /*endif*/ in_octets_to_date += len; } + /*endwhile*/ v42bis_decompress_flush(state_b); printf("%d bytes decompressed to %d bytes in %lds\n", in_octets_to_date, out_octets_to_date, time(NULL) - now); close(v42bis_fd); close(out_fd); } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/v8_tests.c b/tests/v8_tests.c index b341ff31..c95ddff0 100644 --- a/tests/v8_tests.c +++ b/tests/v8_tests.c @@ -936,7 +936,9 @@ int main(int argc, char *argv[]) exit(2); break; } + /*endswitch*/ } + /*endwhile*/ if (decode_test_file) { diff --git a/tests/vector_float_tests.c b/tests/vector_float_tests.c index 0d391c88..ab47a81a 100644 --- a/tests/vector_float_tests.c +++ b/tests/vector_float_tests.c @@ -40,6 +40,7 @@ static void vec_copyf_dumb(float z[], const float x[], int n) for (i = 0; i < n; i++) z[i] = x[i]; + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -57,6 +58,7 @@ static int test_vec_copyf(void) za[i] = -0.5f; zb[i] = -0.5f; } + /*endfor*/ vec_copyf_dumb(za + 3, x + 1, 0); vec_copyf(zb + 3, x + 1, 0); for (i = 0; i < 99; i++) @@ -67,7 +69,9 @@ static int test_vec_copyf(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ vec_copyf_dumb(za + 3, x + 1, 1); vec_copyf(zb + 3, x + 1, 1); for (i = 0; i < 99; i++) @@ -78,7 +82,9 @@ static int test_vec_copyf(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ vec_copyf_dumb(za + 3, x + 1, 29); vec_copyf(zb + 3, x + 1, 29); for (i = 0; i < 99; i++) @@ -89,7 +95,9 @@ static int test_vec_copyf(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -100,6 +108,7 @@ static void vec_negatef_dumb(float z[], const float x[], int n) for (i = 0; i < n; i++) z[i] = -x[i]; + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -117,6 +126,7 @@ static int test_vec_negatef(void) za[i] = -0.5f; zb[i] = -0.5f; } + /*endfor*/ vec_negatef_dumb(za + 3, x + 1, 0); vec_negatef(zb + 3, x + 1, 0); for (i = 0; i < 99; i++) @@ -127,7 +137,9 @@ static int test_vec_negatef(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ vec_negatef_dumb(za + 3, x + 1, 1); vec_negatef(zb + 3, x + 1, 1); for (i = 0; i < 99; i++) @@ -138,7 +150,9 @@ static int test_vec_negatef(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ vec_negatef_dumb(za + 3, x + 1, 29); vec_negatef(zb + 3, x + 1, 29); for (i = 0; i < 99; i++) @@ -149,7 +163,9 @@ static int test_vec_negatef(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -160,6 +176,7 @@ static void vec_zerof_dumb(float z[], int n) for (i = 0; i < n; i++) z[i] = 0.0f; + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -175,6 +192,7 @@ static int test_vec_zerof(void) za[i] = -1.0f; zb[i] = -1.0f; } + /*endfor*/ vec_zerof_dumb(za + 3, 0); vec_zerof(zb + 3, 0); for (i = 0; i < 99; i++) @@ -185,7 +203,9 @@ static int test_vec_zerof(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ vec_zerof_dumb(za + 3, 1); vec_zerof(zb + 3, 1); for (i = 0; i < 99; i++) @@ -196,7 +216,9 @@ static int test_vec_zerof(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ vec_zerof_dumb(za + 3, 29); vec_zerof(zb + 3, 29); for (i = 0; i < 99; i++) @@ -207,7 +229,9 @@ static int test_vec_zerof(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -218,6 +242,7 @@ static void vec_setf_dumb(float z[], float x, int n) for (i = 0; i < n; i++) z[i] = x; + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -233,6 +258,7 @@ static int test_vec_setf(void) za[i] = -1.0f; zb[i] = -1.0f; } + /*endfor*/ vec_setf_dumb(za + 3, 42.0f, 0); vec_setf(zb + 3, 42.0f, 0); for (i = 0; i < 99; i++) @@ -243,7 +269,9 @@ static int test_vec_setf(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ vec_setf_dumb(za + 3, 42.0f, 1); vec_setf(zb + 3, 42.0f, 1); for (i = 0; i < 99; i++) @@ -254,7 +282,9 @@ static int test_vec_setf(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ vec_setf_dumb(za + 3, 42.0f, 29); vec_setf(zb + 3, 42.0f, 29); for (i = 0; i < 99; i++) @@ -265,7 +295,9 @@ static int test_vec_setf(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -278,6 +310,7 @@ static double vec_dot_prod_dumb(const double x[], const double y[], int n) z = 0.0; for (i = 0; i < n; i++) z += x[i]*y[i]; + /*endfor*/ return z; } /*- End of function --------------------------------------------------------*/ @@ -297,6 +330,7 @@ static int test_vec_dot_prod(void) x[i] = rand(); y[i] = rand(); } + /*endfor*/ for (i = 1; i < 99; i++) { zsa = vec_dot_prod(x, y, i); @@ -308,7 +342,9 @@ static int test_vec_dot_prod(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -321,6 +357,7 @@ static float vec_dot_prodf_dumb(const float x[], const float y[], int n) z = 0.0; for (i = 0; i < n; i++) z += x[i]*y[i]; + /*endfor*/ return z; } /*- End of function --------------------------------------------------------*/ @@ -340,6 +377,7 @@ static int test_vec_dot_prodf(void) x[i] = rand(); y[i] = rand(); } + /*endfor*/ for (i = 1; i < 99; i++) { zsa = vec_dot_prodf(x, y, i); @@ -351,7 +389,9 @@ static int test_vec_dot_prodf(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -362,6 +402,7 @@ static void vec_addf_dumb(float z[], const float x[], const float y[], int n) for (i = 0; i < n; i++) z[i] = x[i] + y[i]; + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -381,6 +422,7 @@ static int test_vec_addf(void) x[i] = rand(); y[i] = rand(); } + /*endfor*/ for (i = 1; i < 90; i++) { /* Force address misalignment, to check this works OK */ @@ -395,8 +437,11 @@ static int test_vec_addf(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -407,6 +452,7 @@ static void vec_subf_dumb(float z[], const float x[], const float y[], int n) for (i = 0; i < n; i++) z[i] = x[i] - y[i]; + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -426,6 +472,7 @@ static int test_vec_subf(void) x[i] = rand(); y[i] = rand(); } + /*endfor*/ for (i = 1; i < 90; i++) { /* Force address misalignment, to check this works OK */ @@ -440,8 +487,11 @@ static int test_vec_subf(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -452,6 +502,7 @@ static void vec_mulf_dumb(float z[], const float x[], const float y[], int n) for (i = 0; i < n; i++) z[i] = x[i]*y[i]; + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -471,6 +522,7 @@ static int test_vec_mulf(void) x[i] = rand(); y[i] = rand(); } + /*endfor*/ for (i = 1; i < 90; i++) { /* Force address misalignment, to check this works OK */ @@ -485,8 +537,11 @@ static int test_vec_mulf(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -502,6 +557,7 @@ static void vec_lmsf_dumb(const float x[], float y[], int n, float error) /* Leak a little to tame uncontrolled wandering */ y[i] = y[i]*LMS_LEAK_RATE + x[i]*error; } + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -521,6 +577,7 @@ static int test_vec_lmsf(void) ya[i] = yb[i] = rand(); } + /*endfor*/ for (i = 1; i < 99; i++) { vec_lmsf(x, ya, i, 0.1f); @@ -534,8 +591,11 @@ static int test_vec_lmsf(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -546,6 +606,7 @@ static void vec_scaledxy_addf_dumb(float z[], const float x[], float x_scale, co for (i = 0; i < n; i++) z[i] = x[i]*x_scale + y[i]*y_scale; + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -565,6 +626,7 @@ static int test_vec_scaledxy_addf(void) x[i] = rand(); y[i] = rand(); } + /*endfor*/ for (i = 1; i < 99; i++) { vec_scaledxy_addf(za, x, 2.5f, y, 1.5f, i); @@ -578,8 +640,11 @@ static int test_vec_scaledxy_addf(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -590,6 +655,7 @@ static void vec_scaledy_addf_dumb(float z[], const float x[], const float y[], f for (i = 0; i < n; i++) z[i] = x[i] + y[i]*y_scale; + /*endfor*/ } /*- End of function --------------------------------------------------------*/ @@ -609,6 +675,7 @@ static int test_vec_scaledy_addf(void) x[i] = rand(); y[i] = rand(); } + /*endfor*/ for (i = 1; i < 99; i++) { vec_scaledy_addf(za, x, y, 1.5f, i); @@ -622,8 +689,11 @@ static int test_vec_scaledy_addf(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ diff --git a/tests/vector_int_tests.c b/tests/vector_int_tests.c index 0ac0c642..52cfedb2 100644 --- a/tests/vector_int_tests.c +++ b/tests/vector_int_tests.c @@ -42,6 +42,7 @@ static int32_t vec_dot_prodi16_dumb(const int16_t x[], const int16_t y[], int n) z = 0; for (i = 0; i < n; i++) z += (int32_t) x[i]*(int32_t) y[i]; + /*endfor*/ return z; } /*- End of function --------------------------------------------------------*/ @@ -59,6 +60,7 @@ static int test_vec_dot_prodi16(void) x[i] = rand(); y[i] = rand(); } + /*endfor*/ for (i = 1; i < 99; i++) { @@ -69,7 +71,9 @@ static int test_vec_dot_prodi16(void) printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -100,6 +104,7 @@ static int32_t vec_min_maxi16_dumb(const int16_t x[], int n, int16_t out[]) z = abs(min); if (z > max) return z; + /*endif*/ return max; } /*- End of function --------------------------------------------------------*/ @@ -115,6 +120,7 @@ static int test_vec_min_maxi16(void) for (i = 0; i < 99; i++) x[i] = rand(); + /*endfor*/ x[42] = -32768; za = vec_min_maxi16_dumb(x, 99, outa); @@ -128,6 +134,7 @@ static int test_vec_min_maxi16(void) printf("Tests failed\n"); exit(2); } + /*endif*/ return 0; } /*- End of function --------------------------------------------------------*/ @@ -150,6 +157,7 @@ static int test_vec_circular_dot_prodi16(void) x[i] = rand(); y[i] = rand(); } + /*endfor*/ len = 95; for (pos = 0; pos < len; pos++) @@ -161,13 +169,16 @@ static int test_vec_circular_dot_prodi16(void) j = (pos + i) % len; zb += (int32_t) x[j]*(int32_t) y[i]; } + /*endfor*/ if (za != zb) { printf("Tests failed\n"); exit(2); } + /*endif*/ } + /*endfor*/ return 0; } /*- End of function --------------------------------------------------------*/