Mercurial > hg > audiostuff
comparison spandsp-0.0.3/spandsp-0.0.3/tests/t38_terminal_tests.c @ 5:f762bf195c4b
import spandsp-0.0.3
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 25 Jun 2010 16:00:21 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
4:26cd8f1ef0b1 | 5:f762bf195c4b |
---|---|
1 /* | |
2 * SpanDSP - a series of DSP components for telephony | |
3 * | |
4 * t38_terminal_tests.c - Tests for the T.38 FoIP terminal module. | |
5 * | |
6 * Written by Steve Underwood <steveu@coppice.org> | |
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 * $Id: t38_terminal_tests.c,v 1.32 2006/12/09 04:56:20 steveu Exp $ | |
26 */ | |
27 | |
28 /*! \file */ | |
29 | |
30 /*! \page t38_terminal_tests_page T.38 termination tests | |
31 \section t38_terminal_tests_page_sec_1 What does it do? | |
32 These tests exercise the path | |
33 | |
34 T.38 termination <-> T.38 termination | |
35 */ | |
36 | |
37 #ifdef HAVE_CONFIG_H | |
38 #include <config.h> | |
39 #endif | |
40 | |
41 #include <inttypes.h> | |
42 #include <stdlib.h> | |
43 #include <stdio.h> | |
44 #include <fcntl.h> | |
45 #include <string.h> | |
46 #if defined(HAVE_TGMATH_H) | |
47 #include <tgmath.h> | |
48 #endif | |
49 #if defined(HAVE_MATH_H) | |
50 #include <math.h> | |
51 #endif | |
52 #include <assert.h> | |
53 #include <errno.h> | |
54 #include <sys/socket.h> | |
55 #include <netinet/in.h> | |
56 #include <netinet/tcp.h> | |
57 #define __USE_MISC | |
58 #include <arpa/inet.h> | |
59 #include <sys/select.h> | |
60 #include <sys/time.h> | |
61 #include <tiffio.h> | |
62 | |
63 #include "spandsp.h" | |
64 | |
65 #include "ip_network_model.h" | |
66 | |
67 #define SAMPLES_PER_CHUNK 160 | |
68 | |
69 #define INPUT_FILE_NAME "../itutests/fax/itutests.tif" | |
70 #define OUTPUT_FILE_NAME "t38.tif" | |
71 | |
72 t38_terminal_state_t t38_state_a; | |
73 t38_terminal_state_t t38_state_b; | |
74 | |
75 ip_network_model_state_t *path_a_to_b; | |
76 ip_network_model_state_t *path_b_to_a; | |
77 | |
78 int done[2] = {FALSE, FALSE}; | |
79 int succeeded[2] = {FALSE, FALSE}; | |
80 | |
81 static void phase_b_handler(t30_state_t *s, void *user_data, int result) | |
82 { | |
83 int i; | |
84 | |
85 i = (int) (intptr_t) user_data; | |
86 printf("%c: Phase B handler on channel %c - (0x%X) %s\n", i, i, result, t30_frametype(result)); | |
87 } | |
88 /*- End of function --------------------------------------------------------*/ | |
89 | |
90 static void phase_d_handler(t30_state_t *s, void *user_data, int result) | |
91 { | |
92 int i; | |
93 t30_stats_t t; | |
94 char ident[21]; | |
95 | |
96 i = (int) (intptr_t) user_data; | |
97 printf("%c: Phase D handler on channel %c - (0x%X) %s\n", i, i, result, t30_frametype(result)); | |
98 t30_get_transfer_statistics(s, &t); | |
99 printf("%c: Phase D: bit rate %d\n", i, t.bit_rate); | |
100 printf("%c: Phase D: ECM %s\n", i, (t.error_correcting_mode) ? "on" : "off"); | |
101 printf("%c: Phase D: pages transferred %d\n", i, t.pages_transferred); | |
102 printf("%c: Phase D: image size %d x %d\n", i, t.width, t.length); | |
103 printf("%c: Phase D: image resolution %d x %d\n", i, t.x_resolution, t.y_resolution); | |
104 printf("%c: Phase D: bad rows %d\n", i, t.bad_rows); | |
105 printf("%c: Phase D: longest bad row run %d\n", i, t.longest_bad_row_run); | |
106 printf("%c: Phase D: coding method %s\n", i, t4_encoding_to_str(t.encoding)); | |
107 printf("%c: Phase D: image size %d\n", i, t.image_size); | |
108 t30_get_local_ident(s, ident); | |
109 printf("%c: Phase D: local ident '%s'\n", i, ident); | |
110 t30_get_far_ident(s, ident); | |
111 printf("%c: Phase D: remote ident '%s'\n", i, ident); | |
112 } | |
113 /*- End of function --------------------------------------------------------*/ | |
114 | |
115 static void phase_e_handler(t30_state_t *s, void *user_data, int result) | |
116 { | |
117 int i; | |
118 t30_stats_t t; | |
119 char ident[21]; | |
120 | |
121 i = (int) (intptr_t) user_data; | |
122 printf("%c: Phase E handler on channel %c - (%d) %s\n", i, i, result, t30_completion_code_to_str(result)); | |
123 t30_get_transfer_statistics(s, &t); | |
124 printf("%c: Phase E: bit rate %d\n", i, t.bit_rate); | |
125 printf("%c: Phase E: ECM %s\n", i, (t.error_correcting_mode) ? "on" : "off"); | |
126 printf("%c: Phase E: pages transferred %d\n", i, t.pages_transferred); | |
127 printf("%c: Phase E: image size %d x %d\n", i, t.width, t.length); | |
128 printf("%c: Phase E: image resolution %d x %d\n", i, t.x_resolution, t.y_resolution); | |
129 printf("%c: Phase E: bad rows %d\n", i, t.bad_rows); | |
130 printf("%c: Phase E: longest bad row run %d\n", i, t.longest_bad_row_run); | |
131 printf("%c: Phase E: coding method %s\n", i, t4_encoding_to_str(t.encoding)); | |
132 printf("%c: Phase E: image size %d bytes\n", i, t.image_size); | |
133 t30_get_local_ident(s, ident); | |
134 printf("%c: Phase E: local ident '%s'\n", i, ident); | |
135 t30_get_far_ident(s, ident); | |
136 printf("%c: Phase E: remote ident '%s'\n", i, ident); | |
137 succeeded[i - 'A'] = (result == T30_ERR_OK) && (t.pages_transferred == 12); | |
138 //done[i - 'A'] = TRUE; | |
139 } | |
140 /*- End of function --------------------------------------------------------*/ | |
141 | |
142 static int tx_packet_handler_a(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count) | |
143 { | |
144 t38_terminal_state_t *t; | |
145 | |
146 /* This routine queues messages between two instances of T.38 processing */ | |
147 t = (t38_terminal_state_t *) user_data; | |
148 span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count); | |
149 | |
150 ip_network_model_send(path_a_to_b, s->tx_seq_no, count, buf, len); | |
151 return 0; | |
152 } | |
153 /*- End of function --------------------------------------------------------*/ | |
154 | |
155 static int tx_packet_handler_b(t38_core_state_t *s, void *user_data, const uint8_t *buf, int len, int count) | |
156 { | |
157 t38_terminal_state_t *t; | |
158 | |
159 /* This routine queues messages between two instances of T.38 processing */ | |
160 t = (t38_terminal_state_t *) user_data; | |
161 span_log(&s->logging, SPAN_LOG_FLOW, "Send seq %d, len %d, count %d\n", s->tx_seq_no, len, count); | |
162 | |
163 ip_network_model_send(path_b_to_a, s->tx_seq_no, count, buf, len); | |
164 return 0; | |
165 } | |
166 /*- End of function --------------------------------------------------------*/ | |
167 | |
168 int main(int argc, char *argv[]) | |
169 { | |
170 int msg_len; | |
171 uint8_t msg[1024]; | |
172 int t38_version; | |
173 int i; | |
174 int seq_no; | |
175 int use_ecm; | |
176 const char *input_file_name; | |
177 | |
178 t38_version = 1; | |
179 input_file_name = INPUT_FILE_NAME; | |
180 use_ecm = FALSE; | |
181 for (i = 1; i < argc; i++) | |
182 { | |
183 if (strcmp(argv[i], "-e") == 0) | |
184 { | |
185 use_ecm = TRUE; | |
186 continue; | |
187 } | |
188 if (strcmp(argv[i], "-v") == 0) | |
189 { | |
190 i++; | |
191 t38_version = atoi(argv[i]); | |
192 continue; | |
193 } | |
194 if (strcmp(argv[i], "-i") == 0) | |
195 { | |
196 i++; | |
197 input_file_name = argv[i]; | |
198 continue; | |
199 } | |
200 } | |
201 | |
202 printf("Using T.38 version %d\n", t38_version); | |
203 if (use_ecm) | |
204 printf("Using ECM\n"); | |
205 | |
206 if ((path_a_to_b = ip_network_model_init(800, 2000, 0)) == NULL) | |
207 { | |
208 fprintf(stderr, "Failed to start IP network path model\n"); | |
209 exit(2); | |
210 } | |
211 if ((path_b_to_a = ip_network_model_init(800, 2000, 0)) == NULL) | |
212 { | |
213 fprintf(stderr, "Failed to start IP network path model\n"); | |
214 exit(2); | |
215 } | |
216 | |
217 if (t38_terminal_init(&t38_state_a, TRUE, tx_packet_handler_a, &t38_state_b) == NULL) | |
218 { | |
219 fprintf(stderr, "Cannot start the T.38 channel\n"); | |
220 exit(2); | |
221 } | |
222 t38_set_t38_version(&t38_state_a.t38, t38_version); | |
223 span_log_set_level(&t38_state_a.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME); | |
224 span_log_set_tag(&t38_state_a.logging, "T.38-A"); | |
225 span_log_set_level(&t38_state_a.t38.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME); | |
226 span_log_set_tag(&t38_state_a.t38.logging, "T.38-A"); | |
227 span_log_set_level(&t38_state_a.t30_state.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME); | |
228 span_log_set_tag(&t38_state_a.t30_state.logging, "T.38-A"); | |
229 | |
230 t30_set_local_ident(&t38_state_a.t30_state, "11111111"); | |
231 t30_set_tx_file(&t38_state_a.t30_state, input_file_name, -1, -1); | |
232 t30_set_phase_b_handler(&t38_state_a.t30_state, phase_b_handler, (void *) (intptr_t) 'A'); | |
233 t30_set_phase_d_handler(&t38_state_a.t30_state, phase_d_handler, (void *) (intptr_t) 'A'); | |
234 t30_set_phase_e_handler(&t38_state_a.t30_state, phase_e_handler, (void *) (intptr_t) 'A'); | |
235 t30_set_ecm_capability(&t38_state_a.t30_state, use_ecm); | |
236 if (use_ecm) | |
237 t30_set_supported_compressions(&t38_state_a.t30_state, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION); | |
238 | |
239 if (t38_terminal_init(&t38_state_b, FALSE, tx_packet_handler_b, &t38_state_a) == NULL) | |
240 { | |
241 fprintf(stderr, "Cannot start the T.38 channel\n"); | |
242 exit(2); | |
243 } | |
244 t38_set_t38_version(&t38_state_b.t38, t38_version); | |
245 span_log_set_level(&t38_state_b.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME); | |
246 span_log_set_tag(&t38_state_b.logging, "T.38-B"); | |
247 span_log_set_level(&t38_state_b.t38.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME); | |
248 span_log_set_tag(&t38_state_b.t38.logging, "T.38-B"); | |
249 span_log_set_level(&t38_state_b.t30_state.logging, SPAN_LOG_DEBUG | SPAN_LOG_SHOW_TAG | SPAN_LOG_SHOW_SAMPLE_TIME); | |
250 span_log_set_tag(&t38_state_b.t30_state.logging, "T.38-B"); | |
251 | |
252 t30_set_local_ident(&t38_state_b.t30_state, "22222222"); | |
253 t30_set_rx_file(&t38_state_b.t30_state, OUTPUT_FILE_NAME, -1); | |
254 t30_set_phase_b_handler(&t38_state_b.t30_state, phase_b_handler, (void *) (intptr_t) 'B'); | |
255 t30_set_phase_d_handler(&t38_state_b.t30_state, phase_d_handler, (void *) (intptr_t) 'B'); | |
256 t30_set_phase_e_handler(&t38_state_b.t30_state, phase_e_handler, (void *) (intptr_t) 'B'); | |
257 t30_set_ecm_capability(&t38_state_b.t30_state, use_ecm); | |
258 if (use_ecm) | |
259 t30_set_supported_compressions(&t38_state_b.t30_state, T30_SUPPORT_T4_1D_COMPRESSION | T30_SUPPORT_T4_2D_COMPRESSION | T30_SUPPORT_T6_COMPRESSION); | |
260 | |
261 for (;;) | |
262 { | |
263 span_log_bump_samples(&t38_state_a.logging, SAMPLES_PER_CHUNK); | |
264 span_log_bump_samples(&t38_state_a.t38.logging, SAMPLES_PER_CHUNK); | |
265 span_log_bump_samples(&t38_state_a.t30_state.logging, SAMPLES_PER_CHUNK); | |
266 span_log_bump_samples(&t38_state_b.logging, SAMPLES_PER_CHUNK); | |
267 span_log_bump_samples(&t38_state_b.t38.logging, SAMPLES_PER_CHUNK); | |
268 span_log_bump_samples(&t38_state_b.t30_state.logging, SAMPLES_PER_CHUNK); | |
269 | |
270 done[0] = t38_terminal_send_timeout(&t38_state_a, SAMPLES_PER_CHUNK); | |
271 done[1] = t38_terminal_send_timeout(&t38_state_b, SAMPLES_PER_CHUNK); | |
272 | |
273 while ((msg_len = ip_network_model_get(path_a_to_b, SAMPLES_PER_CHUNK, msg, 1024, &seq_no)) >= 0) | |
274 t38_core_rx_ifp_packet(&t38_state_b.t38, seq_no, msg, msg_len); | |
275 while ((msg_len = ip_network_model_get(path_b_to_a, SAMPLES_PER_CHUNK, msg, 1024, &seq_no)) >= 0) | |
276 t38_core_rx_ifp_packet(&t38_state_a.t38, seq_no, msg, msg_len); | |
277 | |
278 if (done[0] && done[1]) | |
279 break; | |
280 } | |
281 if (!succeeded[0] || !succeeded[1]) | |
282 { | |
283 printf("Tests failed\n"); | |
284 exit(2); | |
285 } | |
286 printf("Tests passed\n"); | |
287 return 0; | |
288 } | |
289 /*- End of function --------------------------------------------------------*/ | |
290 /*- End of file ------------------------------------------------------------*/ |