Debian Codegraph @

tests/t38_gateway_to_terminal_tests.c

raw symbols SCIP
1 /*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * t38_gateway_to_terminal_tests.c - Joint tests for the T.38 FoIP terminal and gateway modules.
5 *
6 * Written by Steve Underwood <[email protected]>
7 *
8 * Copyright (C) 2005, 2006 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2, as
14 * published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26 /*! \file */
27
28 /*! \page t38_gateway_to_terminal_tests_page T.38 mixed gateway and termination tests
29 \section t38_gateway_to_terminal_tests_page_sec_1 What does it do?
30 These tests exercise the path
31
32 FAX machine -> T.38 gateway -> T.38 termination
33 */
34
35 /* Enable the following definition to enable direct probing into the FAX structures */
36 //#define WITH_SPANDSP_INTERNALS
37
38 #if defined(HAVE_CONFIG_H)
39 #include <config.h>
40 #endif
41
42 #if defined(HAVE_FL_FL_H) && defined(HAVE_FL_FL_CARTESIAN_H) && defined(HAVE_FL_FL_AUDIO_METER_H)
43 #define ENABLE_GUI
44 #endif
45
46 #include <stdlib.h>
47 #include <stdio.h>
48 #include <fcntl.h>
49 #include <string.h>
50 #include <assert.h>
51 #include <errno.h>
52 #include <sndfile.h>
53 #if !defined(_WIN32)
54 #include <unistd.h>
55 #endif
56
57 //#if defined(WITH_SPANDSP_INTERNALS)
58 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES
59 //#endif
60
61 #include "spandsp.h"
62 #include "spandsp-sim.h"
63
64 #if defined(ENABLE_GUI)
65 #include "media_monitor.h"
66 #endif
67 #include "fax_utils.h"
68
69 #define SAMPLES_PER_CHUNK 160
70
71 #define INPUT_FILE_NAME "../test-data/itu/fax/itutests.tif"
72 #define OUTPUT_FILE_NAME "t38.tif"
73 #define OUTPUT_FILE_NAME_WAVE "t38_gateway_to_terminal.wav"
74
75 fax_state_t *fax_state_a;
76 t38_gateway_state_t *t38_state_a;
77 t38_terminal_state_t *t38_state_b;
78
79 g1050_state_t *path_a_to_b;
80 g1050_state_t *path_b_to_a;
81
82 double when = 0.0;
83
84 int done[2] = {FALSE, FALSE};
85 int succeeded[2] = {FALSE, FALSE};
86
87 int simulate_incrementing_repeats = FALSE;
88
89 int t38_version;
90 int use_ecm;
91 int use_tep;
92 int use_transmit_on_idle;
93 int supported_modems;
94 int use_gui;
95 int g1050_model_no;
96 int g1050_speed_pattern_no;
97
98 static int phase_b_handler(t30_state_t *s, void *user_data, int result)
99 {
100 int i;
101 char tag[20];
102
103 i = (int) (intptr_t) user_data;
104 snprintf(tag, sizeof(tag), "%c: Phase B", i);
105 printf("%c: Phase B handler on channel %c - (0x%X) %s\n", i, i, result, t30_frametype(result));
106 fax_log_rx_parameters(s, tag);
107 return T30_ERR_OK;
108 }
109 /*- End of function --------------------------------------------------------*/
110
111 static int phase_d_handler(t30_state_t *s, void *user_data, int result)
112 {
113 int i;
114 char tag[20];
115
116 i = (int) (intptr_t) user_data;
117 snprintf(tag, sizeof(tag), "%c: Phase D", i);
118 printf("%c: Phase D handler on channel %c - (0x%X) %s\n", i, i, result, t30_frametype(result));
119 fax_log_page_transfer_statistics(s, tag);
120 fax_log_tx_parameters(s, tag);
121 fax_log_rx_parameters(s, tag);
122 return T30_ERR_OK;
123 }
124 /*- End of function --------------------------------------------------------*/
125
126 static void phase_e_handler(t30_state_t *s, void *user_data, int result)
127 {
128 int i;
129 t30_stats_t t;
130 char tag[20];
131
132 i = (int) (intptr_t) user_data;
133 snprintf(tag, sizeof(tag), "%c: Phase E", i);
134 printf("%c: Phase E handler on channel %c - (%d) %s\n", i, i, result, t30_completion_code_to_str(result));
135 fax_log_final_transfer_statistics(s, tag);
136 fax_log_tx_parameters(s, tag);
137 fax_log_rx_parameters(s, tag);
138 t30_get_transfer_statistics(s, &t);
139 succeeded[i - 'A'] = (result == T30_ERR_OK) && (t.pages_tx == 12 || t.pages_rx == 12);
140 done[i - 'A'] = TRUE;
141 }
142 /*- End of function --------------------------------------------------------*/
143
144 static int tx_packet_handler_a(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
145 {
146 int i;
147 static int subst_seq = 0;
148
149 /* This routine queues messages between two instances of T.38 processing */
150 if (simulate_incrementing_repeats)
151 {
152 for (i = 0; i < count; i++)
153 {
154 span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d\n", subst_seq, len);
155
156 g1050_put(path_a_to_b, buf, len, subst_seq, when);
157 subst_seq = (subst_seq + 1) & 0xFFFF;
158 }
159 }
160 else
161 {
162 span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count);
163
164 for (i = 0; i < count; i++)
165 g1050_put(path_a_to_b, buf, len, s->tx_seq_no, when);
166 }
167 return 0;
168 }
169 /*- End of function --------------------------------------------------------*/
170
171 static int tx_packet_handler_b(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count)
172 {
173 int i;
174 static int subst_seq = 0;
175
176 /* This routine queues messages between two instances of T.38 processing */
177 if (simulate_incrementing_repeats)
178 {
179 for (i = 0; i < count; i++)
180 {
181 span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d\n", subst_seq, len);
182
183 g1050_put(path_b_to_a, buf, len, subst_seq, when);
184 subst_seq = (subst_seq + 1) & 0xFFFF;
185 }
186 }
187 else
188 {
189 span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count);
190
191 for (i = 0; i < count; i++)
192 g1050_put(path_b_to_a, buf, len, s->tx_seq_no, when);
193 }
194 return 0;
195 }
196 /*- End of function --------------------------------------------------------*/
197
198 static int decode_test(const char *decode_test_file)
199 {
200 int16_t t38_amp_a[SAMPLES_PER_CHUNK];
201 int16_t t30_amp_a[SAMPLES_PER_CHUNK];
202 SNDFILE *wave_handle;
203 t30_state_t *t30;
204 t38_core_state_t *t38_core;
205 logging_state_t *logging;
206 int t38_len_a;
207 int t30_len_a;
208 int msg_len;
209 uint8_t msg[1024];
210 int seq_no;
211 double tx_when;
212 double rx_when;
213
214 printf("Decode test data file '%s'\n", decode_test_file);
215
216 if ((wave_handle = sf_open_telephony_read(decode_test_file, 1)) == NULL)
217 {
218 fprintf(stderr, " Cannot open audio file '%s'\n", decode_test_file);
219 exit(2);
220 }
221
222 srand48(0x1234567);
223 if ((path_a_to_b = g1050_init(g1050_model_no, g1050_speed_pattern_no, 100, 33)) == NULL)
224 {
225 fprintf(stderr, "Failed to start IP network path model\n");
226 exit(2);
227 }
228 if ((path_b_to_a = g1050_init(g1050_model_no, g1050_speed_pattern_no, 100, 33)) == NULL)
229 {
230 fprintf(stderr, "Failed to start IP network path model\n");
231 exit(2);
232 }
233
234 memset(t30_amp_a, 0, sizeof(t30_amp_a));
235
236 if ((t38_state_a = t38_gateway_init(NULL, tx_packet_handler_a, t38_state_b)) == NULL)
237 {
238 fprintf(stderr, "Cannot start the T.38 channel\n");
239 exit(2);
240 }
241 t38_core = t38_gateway_get_t38_core_state(t38_state_a);
242 t38_gateway_set_transmit_on_idle(t38_state_a, use_transmit_on_idle);
243 t38_set_t38_version(t38_core, t38_version);
244 t38_gateway_set_ecm_capability(t38_state_a, use_ecm);
245
246 logging = t38_gateway_get_logging_state(t38_state_a);
247 span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
248 span_log_set_tag(logging, "T.38-A");
249
250 logging = t38_core_get_logging_state(t38_core);
251 span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
252 span_log_set_tag(logging, "T.38-A");
253
254 logging = &t38_state_a->audio.modems.fast_modems.v17_rx.logging;
255 span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
256 span_log_set_tag(logging, "V.17-A");
257
258 memset(t38_amp_a, 0, sizeof(t38_amp_a));
259
260 if ((t38_state_b = t38_terminal_init(NULL, FALSE, tx_packet_handler_b, t38_state_a)) == NULL)
261 {
262 fprintf(stderr, "Cannot start the T.38 channel\n");
263 exit(2);
264 }
265 t30 = t38_terminal_get_t30_state(t38_state_b);
266 t38_core = t38_terminal_get_t38_core_state(t38_state_b);
267 t38_set_t38_version(t38_core, t38_version);
268
269 logging = t38_terminal_get_logging_state(t38_state_b);
270 span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
271 span_log_set_tag(logging, "T.38-B");
272
273 logging = t38_core_get_logging_state(t38_core);
274 span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
275 span_log_set_tag(logging, "T.38-B");
276
277 logging = t30_get_logging_state(t30);
278 span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
279 span_log_set_tag(logging, "T.38-B");
280
281 t30_set_supported_modems(t30, supported_modems);
282 t30_set_tx_ident(t30, "22222222");
283 t30_set_rx_file(t30, OUTPUT_FILE_NAME, -1);
284 t30_set_phase_b_handler(t30, phase_b_handler, (void *) (intptr_t) 'B');
285 t30_set_phase_d_handler(t30, phase_d_handler, (void *) (intptr_t) 'B');
286 t30_set_phase_e_handler(t30, phase_e_handler, (void *) (intptr_t) 'B');
287 t30_set_ecm_capability(t30, use_ecm);
288 if (use_ecm)
289 t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
290
291 #if defined(ENABLE_GUI)
292 if (use_gui)
293 start_media_monitor();
294 #endif
295 for (;;)
296 {
297 t30_len_a = sf_readf_short(wave_handle, t30_amp_a, SAMPLES_PER_CHUNK);
298
299 logging = t38_gateway_get_logging_state(t38_state_a);
300 span_log_bump_samples(logging, t30_len_a);
301 t38_core = t38_gateway_get_t38_core_state(t38_state_a);
302 logging = t38_core_get_logging_state(t38_core);
303 span_log_bump_samples(logging, t30_len_a);
304 logging = &t38_state_a->audio.modems.fast_modems.v17_rx.logging;
305 span_log_bump_samples(logging, t30_len_a);
306
307 logging = t38_terminal_get_logging_state(t38_state_b);
308 span_log_bump_samples(logging, t30_len_a);
309 t38_core = t38_terminal_get_t38_core_state(t38_state_b);
310 logging = t38_core_get_logging_state(t38_core);
311 span_log_bump_samples(logging, t30_len_a);
312
313 t30 = t38_terminal_get_t30_state(t38_state_b);
314 logging = t30_get_logging_state(t30);
315 span_log_bump_samples(logging, t30_len_a);
316
317 t38_terminal_send_timeout(t38_state_b, t30_len_a);
318
319 if (t38_gateway_rx(t38_state_a, t30_amp_a, t30_len_a))
320 break;
321
322 t38_len_a = t38_gateway_tx(t38_state_a, t38_amp_a, t30_len_a);
323 if (!use_transmit_on_idle)
324 {
325 if (t38_len_a < SAMPLES_PER_CHUNK)
326 {
327 memset(t38_amp_a + t38_len_a, 0, sizeof(int16_t)*(t30_len_a - t38_len_a));
328 t38_len_a = t30_len_a;
329 }
330 }
331
332 when += (float) t30_len_a/(float) SAMPLE_RATE;
333
334 while ((msg_len = g1050_get(path_a_to_b, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0)
335 {
336 #if defined(ENABLE_GUI)
337 if (use_gui)
338 media_monitor_rx(seq_no, tx_when, rx_when);
339 #endif
340 t38_core = t38_terminal_get_t38_core_state(t38_state_b);
341 t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no);
342 }
343 while ((msg_len = g1050_get(path_b_to_a, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0)
344 {
345 #if defined(ENABLE_GUI)
346 if (use_gui)
347 media_monitor_rx(seq_no, tx_when, rx_when);
348 #endif
349 t38_core = t38_gateway_get_t38_core_state(t38_state_a);
350 t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no);
351 }
352
353 if (done[0] && done[1])
354 break;
355 #if defined(ENABLE_GUI)
356 if (use_gui)
357 media_monitor_update_display();
358 #endif
359 }
360 t38_gateway_release(t38_state_a);
361 t38_terminal_release(t38_state_b);
362 if (sf_close(wave_handle) != 0)
363 {
364 fprintf(stderr, " Cannot close audio file '%s'\n", decode_test_file);
365 exit(2);
366 }
367 return 0;
368 }
369 /*- End of function --------------------------------------------------------*/
370
371 int main(int argc, char *argv[])
372 {
373 int16_t t38_amp_a[SAMPLES_PER_CHUNK];
374 int16_t t30_amp_a[SAMPLES_PER_CHUNK];
375 int16_t out_amp[2*SAMPLES_PER_CHUNK];
376 int t38_len_a;
377 int t30_len_a;
378 int msg_len;
379 uint8_t msg[1024];
380 int log_audio;
381 int outframes;
382 int feedback_audio;
383 SNDFILE *wave_handle;
384 const char *input_file_name;
385 int i;
386 int seq_no;
387 double tx_when;
388 double rx_when;
389 int opt;
390 t30_state_t *t30;
391 t38_core_state_t *t38_core;
392 logging_state_t *logging;
393 char *decode_test_file;
394
395 log_audio = FALSE;
396 t38_version = 1;
397 use_ecm = FALSE;
398 input_file_name = INPUT_FILE_NAME;
399 simulate_incrementing_repeats = FALSE;
400 g1050_model_no = 0;
401 g1050_speed_pattern_no = 1;
402 use_gui = FALSE;
403 use_tep = FALSE;
404 feedback_audio = FALSE;
405 use_transmit_on_idle = TRUE;
406 supported_modems = T30_SUPPORT_V27TER | T30_SUPPORT_V29 | T30_SUPPORT_V17;
407 decode_test_file = NULL;
408 while ((opt = getopt(argc, argv, "d:efgi:Ilm:M:s:tv:")) != -1)
409 {
410 switch (opt)
411 {
412 case 'd':
413 decode_test_file = optarg;
414 break;
415 case 'e':
416 use_ecm = TRUE;
417 break;
418 case 'f':
419 feedback_audio = TRUE;
420 break;
421 case 'g':
422 #if defined(ENABLE_GUI)
423 use_gui = TRUE;
424 #else
425 fprintf(stderr, "Graphical monitoring not available\n");
426 exit(2);
427 #endif
428 break;
429 case 'i':
430 input_file_name = optarg;
431 break;
432 case 'I':
433 simulate_incrementing_repeats = TRUE;
434 break;
435 case 'l':
436 log_audio = TRUE;
437 break;
438 case 'm':
439 supported_modems = atoi(optarg);
440 break;
441 case 'M':
442 g1050_model_no = optarg[0] - 'A' + 1;
443 break;
444 case 's':
445 g1050_speed_pattern_no = atoi(optarg);
446 break;
447 case 't':
448 use_tep = TRUE;
449 break;
450 case 'v':
451 t38_version = atoi(optarg);
452 break;
453 default:
454 //usage();
455 exit(2);
456 break;
457 }
458 }
459
460 printf("Using T.38 version %d\n", t38_version);
461 if (use_ecm)
462 printf("Using ECM\n");
463
464 if (decode_test_file)
465 {
466 decode_test(decode_test_file);
467 return 0;
468 }
469
470 wave_handle = NULL;
471 if (log_audio)
472 {
473 if ((wave_handle = sf_open_telephony_write(OUTPUT_FILE_NAME_WAVE, 2)) == NULL)
474 {
475 fprintf(stderr, " Cannot create audio file '%s'\n", OUTPUT_FILE_NAME_WAVE);
476 exit(2);
477 }
478 }
479
480 srand48(0x1234567);
481 if ((path_a_to_b = g1050_init(g1050_model_no, g1050_speed_pattern_no, 100, 33)) == NULL)
482 {
483 fprintf(stderr, "Failed to start IP network path model\n");
484 exit(2);
485 }
486 if ((path_b_to_a = g1050_init(g1050_model_no, g1050_speed_pattern_no, 100, 33)) == NULL)
487 {
488 fprintf(stderr, "Failed to start IP network path model\n");
489 exit(2);
490 }
491
492 if ((fax_state_a = fax_init(NULL, TRUE)) == NULL)
493 {
494 fprintf(stderr, "Cannot start FAX\n");
495 exit(2);
496 }
497 t30 = fax_get_t30_state(fax_state_a);
498 fax_set_transmit_on_idle(fax_state_a, use_transmit_on_idle);
499 fax_set_tep_mode(fax_state_a, use_tep);
500 t30_set_supported_modems(t30, supported_modems);
501 t30_set_tx_ident(t30, "11111111");
502 t30_set_tx_nsf(t30, (const uint8_t *) "\x50\x00\x00\x00Spandsp\x00", 12);
503 t30_set_tx_file(t30, input_file_name, -1, -1);
504 t30_set_phase_b_handler(t30, phase_b_handler, (void *) (intptr_t) 'A');
505 t30_set_phase_d_handler(t30, phase_d_handler, (void *) (intptr_t) 'A');
506 t30_set_phase_e_handler(t30, phase_e_handler, (void *) (intptr_t) 'A');
507 t30_set_ecm_capability(t30, use_ecm);
508 if (use_ecm)
509 t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
510
511 logging = fax_get_logging_state(fax_state_a);
512 span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
513 span_log_set_tag(logging, "FAX-A ");
514
515 logging = t30_get_logging_state(t30);
516 span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
517 span_log_set_tag(logging, "FAX-A ");
518
519 memset(t30_amp_a, 0, sizeof(t30_amp_a));
520
521 if ((t38_state_a = t38_gateway_init(NULL, tx_packet_handler_a, t38_state_b)) == NULL)
522 {
523 fprintf(stderr, "Cannot start the T.38 channel\n");
524 exit(2);
525 }
526 t38_core = t38_gateway_get_t38_core_state(t38_state_a);
527 t38_gateway_set_transmit_on_idle(t38_state_a, use_transmit_on_idle);
528 t38_set_t38_version(t38_core, t38_version);
529 t38_gateway_set_ecm_capability(t38_state_a, use_ecm);
530
531 logging = t38_gateway_get_logging_state(t38_state_a);
532 span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
533 span_log_set_tag(logging, "T.38-A");
534
535 logging = t38_core_get_logging_state(t38_core);
536 span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
537 span_log_set_tag(logging, "T.38-A");
538
539 logging = &t38_state_a->audio.modems.fast_modems.v17_rx.logging;
540 span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
541 span_log_set_tag(logging, "V.17-A");
542
543 memset(t38_amp_a, 0, sizeof(t38_amp_a));
544
545 if ((t38_state_b = t38_terminal_init(NULL, FALSE, tx_packet_handler_b, t38_state_a)) == NULL)
546 {
547 fprintf(stderr, "Cannot start the T.38 channel\n");
548 exit(2);
549 }
550 t30 = t38_terminal_get_t30_state(t38_state_b);
551 t38_core = t38_terminal_get_t38_core_state(t38_state_b);
552 t38_set_t38_version(t38_core, t38_version);
553
554 logging = t38_terminal_get_logging_state(t38_state_b);
555 span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
556 span_log_set_tag(logging, "T.38-B");
557
558 logging = t38_core_get_logging_state(t38_core);
559 span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
560 span_log_set_tag(logging, "T.38-B");
561
562 logging = t30_get_logging_state(t30);
563 span_log_set_level(logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME);
564 span_log_set_tag(logging, "T.38-B");
565
566 t30_set_supported_modems(t30, supported_modems);
567 t30_set_tx_ident(t30, "22222222");
568 t30_set_rx_file(t30, OUTPUT_FILE_NAME, -1);
569 t30_set_phase_b_handler(t30, phase_b_handler, (void *) (intptr_t) 'B');
570 t30_set_phase_d_handler(t30, phase_d_handler, (void *) (intptr_t) 'B');
571 t30_set_phase_e_handler(t30, phase_e_handler, (void *) (intptr_t) 'B');
572 t30_set_ecm_capability(t30, use_ecm);
573 if (use_ecm)
574 t30_set_supported_compressions(t30, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION);
575
576 #if defined(ENABLE_GUI)
577 if (use_gui)
578 start_media_monitor();
579 #endif
580 for (;;)
581 {
582 logging = fax_get_logging_state(fax_state_a);
583 span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
584 t30 = fax_get_t30_state(fax_state_a);
585 logging = t30_get_logging_state(t30);
586 span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
587
588 logging = t38_gateway_get_logging_state(t38_state_a);
589 span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
590 t38_core = t38_gateway_get_t38_core_state(t38_state_a);
591 logging = t38_core_get_logging_state(t38_core);
592 span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
593 logging = &t38_state_a->audio.modems.fast_modems.v17_rx.logging;
594 span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
595
596 logging = t38_terminal_get_logging_state(t38_state_b);
597 span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
598 t38_core = t38_terminal_get_t38_core_state(t38_state_b);
599 logging = t38_core_get_logging_state(t38_core);
600 span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
601 t30 = t38_terminal_get_t30_state(t38_state_b);
602 logging = t30_get_logging_state(t30);
603 span_log_bump_samples(logging, SAMPLES_PER_CHUNK);
604 memset(out_amp, 0, sizeof(out_amp));
605
606 t38_terminal_send_timeout(t38_state_b, SAMPLES_PER_CHUNK);
607
608 t30_len_a = fax_tx(fax_state_a, t30_amp_a, SAMPLES_PER_CHUNK);
609 if (!use_transmit_on_idle)
610 {
611 /* The receive side always expects a full block of samples, but the
612 transmit side may not be sending any when it doesn't need to. We
613 may need to pad with some silence. */
614 if (t30_len_a < SAMPLES_PER_CHUNK)
615 {
616 memset(t30_amp_a + t30_len_a, 0, sizeof(int16_t)*(SAMPLES_PER_CHUNK - t30_len_a));
617 t30_len_a = SAMPLES_PER_CHUNK;
618 }
619 }
620 if (log_audio)
621 {
622 for (i = 0; i < t30_len_a; i++)
623 out_amp[2*i] = t30_amp_a[i];
624 }
625 if (feedback_audio)
626 {
627 for (i = 0; i < t30_len_a; i++)
628 t30_amp_a[i] += t38_amp_a[i] >> 1;
629 }
630 if (t38_gateway_rx(t38_state_a, t30_amp_a, t30_len_a))
631 break;
632
633 t38_len_a = t38_gateway_tx(t38_state_a, t38_amp_a, SAMPLES_PER_CHUNK);
634 if (!use_transmit_on_idle)
635 {
636 if (t38_len_a < SAMPLES_PER_CHUNK)
637 {
638 memset(t38_amp_a + t38_len_a, 0, sizeof(int16_t)*(SAMPLES_PER_CHUNK - t38_len_a));
639 t38_len_a = SAMPLES_PER_CHUNK;
640 }
641 }
642 if (log_audio)
643 {
644 for (i = 0; i < t38_len_a; i++)
645 out_amp[2*i + 1] = t38_amp_a[i];
646 }
647 if (fax_rx(fax_state_a, t38_amp_a, SAMPLES_PER_CHUNK))
648 break;
649
650 when += (float) SAMPLES_PER_CHUNK/(float) SAMPLE_RATE;
651
652 while ((msg_len = g1050_get(path_a_to_b, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0)
653 {
654 #if defined(ENABLE_GUI)
655 if (use_gui)
656 media_monitor_rx(seq_no, tx_when, rx_when);
657 #endif
658 t38_core = t38_terminal_get_t38_core_state(t38_state_b);
659 t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no);
660 }
661 while ((msg_len = g1050_get(path_b_to_a, msg, 1024, when, &seq_no, &tx_when, &rx_when)) >= 0)
662 {
663 #if defined(ENABLE_GUI)
664 if (use_gui)
665 media_monitor_rx(seq_no, tx_when, rx_when);
666 #endif
667 t38_core = t38_gateway_get_t38_core_state(t38_state_a);
668 t38_core_rx_ifp_packet(t38_core, msg, msg_len, seq_no);
669 }
670 if (log_audio)
671 {
672 outframes = sf_writef_short(wave_handle, out_amp, SAMPLES_PER_CHUNK);
673 if (outframes != SAMPLES_PER_CHUNK)
674 break;
675 }
676
677 if (done[0] && done[1])
678 break;
679 #if defined(ENABLE_GUI)
680 if (use_gui)
681 media_monitor_update_display();
682 #endif
683 }
684 fax_release(fax_state_a);
685 t38_gateway_release(t38_state_a);
686 t38_terminal_release(t38_state_b);
687 if (log_audio)
688 {
689 if (sf_close(wave_handle) != 0)
690 {
691 fprintf(stderr, " Cannot close audio file '%s'\n", OUTPUT_FILE_NAME_WAVE);
692 exit(2);
693 }
694 }
695 if (!succeeded[0] || !succeeded[1])
696 {
697 printf("Tests failed\n");
698 exit(2);
699 }
700 printf("Tests passed\n");
701 return 0;
702 }
703 /*- End of function --------------------------------------------------------*/
704 /*- End of file ------------------------------------------------------------*/