~ubuntu-branches/ubuntu/trusty/iaxmodem/trusty-proposed

« back to all changes in this revision

Viewing changes to lib/spandsp/tests/t4_tests.c

  • Committer: Bazaar Package Importer
  • Author(s): Julien BLACHE
  • Date: 2007-05-15 09:43:53 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20070515094353-bpr27hxvt6taxugb
Tags: 0.3.0~dfsg-1
* New upstream release.
  + Now supports V.17 reception; see changelog for details.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 * along with this program; if not, write to the Free Software
23
23
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24
24
 *
25
 
 * $Id: t4_tests.c,v 1.34 2006/11/23 15:48:09 steveu Exp $
 
25
 * $Id: t4_tests.c,v 1.36 2007/03/27 13:04:01 steveu Exp $
26
26
 */
27
27
 
28
28
/*! \file */
75
75
    int add_page_headers;
76
76
    int min_row_bits;
77
77
    int restart_pages;
 
78
    int block_size;
78
79
    char buf[512];
 
80
    uint8_t block[1024];
79
81
    t4_stats_t stats;
80
82
    const char *in_file_name;
81
83
 
82
 
    i = 1;
83
84
    decode_test = FALSE;
84
85
    compression = -1;
85
86
    add_page_headers = FALSE;
86
87
    restart_pages = FALSE;
87
88
    in_file_name = IN_FILE_NAME;
88
89
    min_row_bits = 0;
89
 
    while (i < argc)
 
90
    block_size = 0;
 
91
    for (i = 1;  i < argc;  i++)
90
92
    {
 
93
        if (strcmp(argv[i], "-b") == 0)
 
94
        {
 
95
            block_size = atoi(argv[++i]);
 
96
            if (block_size > 1024)
 
97
                block_size = 1024;
 
98
            continue;
 
99
        }
91
100
        if (strcmp(argv[i], "-d") == 0)
 
101
        {
92
102
            decode_test = TRUE;
93
 
        else if (strcmp(argv[i], "-1") == 0)
 
103
            continue;
 
104
        }
 
105
        if (strcmp(argv[i], "-1") == 0)
 
106
        {
94
107
            compression = T4_COMPRESSION_ITU_T4_1D;
95
 
        else if (strcmp(argv[i], "-2") == 0)
 
108
            continue;
 
109
        }
 
110
        if (strcmp(argv[i], "-2") == 0)
 
111
        {
96
112
            compression = T4_COMPRESSION_ITU_T4_2D;
97
 
        else if (strcmp(argv[i], "-6") == 0)
 
113
            continue;
 
114
        }
 
115
        if (strcmp(argv[i], "-6") == 0)
 
116
        {
98
117
            compression = T4_COMPRESSION_ITU_T6;
99
 
        else if (strcmp(argv[i], "-h") == 0)
 
118
            continue;
 
119
        }
 
120
        if (strcmp(argv[i], "-h") == 0)
 
121
        {
100
122
            add_page_headers = TRUE;
101
 
        else if (strcmp(argv[i], "-r") == 0)
 
123
            continue;
 
124
        }
 
125
        if (strcmp(argv[i], "-r") == 0)
 
126
        {
102
127
            restart_pages = TRUE;
103
 
        else if (strcmp(argv[i], "-i") == 0)
 
128
            continue;
 
129
        }
 
130
        if (strcmp(argv[i], "-i") == 0)
 
131
        {
104
132
            in_file_name = argv[++i];
105
 
        else if (strcmp(argv[i], "-m") == 0)
 
133
            continue;
 
134
        }
 
135
        if (strcmp(argv[i], "-m") == 0)
 
136
        {
106
137
            min_row_bits = atoi(argv[++i]);
107
 
        i++;
 
138
            continue;
 
139
        }
108
140
    }
109
141
    /* Create a send and a receive end */
110
142
    memset(&send_state, 0, sizeof(send_state));
111
143
    memset(&receive_state, 0, sizeof(receive_state));
112
144
 
 
145
    end_of_page = FALSE;
113
146
    if (decode_test)
114
147
    {
115
148
        if (compression < 0)
229
262
                    break;
230
263
            }
231
264
            t4_rx_start_page(&receive_state);
232
 
            do
 
265
            if (block_size == 0)
233
266
            {
234
 
                bit = t4_tx_get_bit(&send_state);
 
267
                do
 
268
                {
 
269
                    bit = t4_tx_get_bit(&send_state);
235
270
#if 0
236
 
                if (--next_hit <= 0)
237
 
                {
238
 
                    do
239
 
                        next_hit = rand() & 0x3FF;
240
 
                    while (next_hit < 20);
241
 
                    bit ^= (rand() & 1);
242
 
                }
 
271
                    if (--next_hit <= 0)
 
272
                    {
 
273
                        do
 
274
                            next_hit = rand() & 0x3FF;
 
275
                        while (next_hit < 20);
 
276
                        bit ^= (rand() & 1);
 
277
                    }
243
278
#endif
244
 
                if (bit == PUTBIT_END_OF_DATA)
245
 
                {
246
 
                    /* T.6 data does not contain an image termination sequence.
247
 
                       T.4 1D and 2D do, and should locate that sequence. */
248
 
                    if (compression == T4_COMPRESSION_ITU_T6)
249
 
                        break;
250
 
                    if (++end_marks > 50)
251
 
                    {
252
 
                        printf("Receiver missed the end of page mark\n");
253
 
                        exit(2);
254
 
                    }
255
 
                }
256
 
                end_of_page = t4_rx_put_bit(&receive_state, bit & 1);
257
 
            }
258
 
            while (!end_of_page);
 
279
                    if (bit == PUTBIT_END_OF_DATA)
 
280
                    {
 
281
                        /* T.6 data does not contain an image termination sequence.
 
282
                           T.4 1D and 2D do, and should locate that sequence. */
 
283
                        if (compression == T4_COMPRESSION_ITU_T6)
 
284
                            break;
 
285
                        if (++end_marks > 50)
 
286
                        {
 
287
                            printf("Receiver missed the end of page mark\n");
 
288
                            exit(2);
 
289
                        }
 
290
                    }
 
291
                    end_of_page = t4_rx_put_bit(&receive_state, bit & 1);
 
292
                }
 
293
                while (!end_of_page);
 
294
            }
 
295
            else if (block_size == 1)
 
296
            {
 
297
                do
 
298
                {
 
299
                    bit = t4_tx_get_byte(&send_state);
 
300
                    if ((bit & 0x100))
 
301
                    {
 
302
                        /* T.6 data does not contain an image termination sequence.
 
303
                           T.4 1D and 2D do, and should locate that sequence. */
 
304
                        if (compression == T4_COMPRESSION_ITU_T6)
 
305
                            break;
 
306
                        if (++end_marks > 50)
 
307
                        {
 
308
                            printf("Receiver missed the end of page mark\n");
 
309
                            exit(2);
 
310
                        }
 
311
                    }
 
312
                    end_of_page = t4_rx_put_byte(&receive_state, bit & 0xFF);
 
313
                }
 
314
                while (!end_of_page);
 
315
            }
 
316
            else
 
317
            {
 
318
                do
 
319
                {
 
320
                    bit = t4_tx_get_chunk(&send_state, block, block_size);
 
321
                    if (bit > 0)
 
322
                        end_of_page = t4_rx_put_chunk(&receive_state, block, bit);
 
323
                    if (bit < block_size)
 
324
                    {
 
325
                        /* T.6 data does not contain an image termination sequence.
 
326
                           T.4 1D and 2D do, and should locate that sequence. */
 
327
                        if (compression == T4_COMPRESSION_ITU_T6)
 
328
                            break;
 
329
                        if (++end_marks > 50)
 
330
                        {
 
331
                            printf("Receiver missed the end of page mark\n");
 
332
                            exit(2);
 
333
                        }
 
334
                    }
 
335
                }
 
336
                while (!end_of_page);
 
337
            }
259
338
            t4_get_transfer_statistics(&receive_state, &stats);
260
339
            printf("Pages = %d\n", stats.pages_transferred);
261
340
            printf("Image size = %d x %d\n", stats.width, stats.length);