Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/tests/rfc2198_sim_tests.c @ 4:26cd8f1ef0b1
import spandsp-0.0.6pre17
| author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
|---|---|
| date | Fri, 25 Jun 2010 15:50:58 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 3:c6c5a16ce2f2 | 4:26cd8f1ef0b1 |
|---|---|
| 1 /* | |
| 2 * SpanDSP - a series of DSP components for telephony | |
| 3 * | |
| 4 * rfc2198_sim_tests.c - Tests for the G.1050/TIA-921 model | |
| 5 * with redundant transmission in the | |
| 6 * style of UDPTL or RFC2198.. | |
| 7 * | |
| 8 * Written by Steve Underwood <steveu@coppice.org> | |
| 9 * | |
| 10 * Copyright (C) 2007 Steve Underwood | |
| 11 * | |
| 12 * All rights reserved. | |
| 13 * | |
| 14 * This program is free software; you can redistribute it and/or modify | |
| 15 * it under the terms of the GNU General Public License version 2, as | |
| 16 * published by the Free Software Foundation. | |
| 17 * | |
| 18 * This program is distributed in the hope that it will be useful, | |
| 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 21 * GNU General Public License for more details. | |
| 22 * | |
| 23 * You should have received a copy of the GNU General Public License | |
| 24 * along with this program; if not, write to the Free Software | |
| 25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
| 26 * | |
| 27 * $Id: rfc2198_sim_tests.c,v 1.7 2009/05/30 15:23:14 steveu Exp $ | |
| 28 */ | |
| 29 | |
| 30 #if defined(HAVE_CONFIG_H) | |
| 31 #include "config.h" | |
| 32 #endif | |
| 33 | |
| 34 #if defined(HAVE_FL_FL_H) && defined(HAVE_FL_FL_CARTESIAN_H) && defined(HAVE_FL_FL_AUDIO_METER_H) | |
| 35 #define ENABLE_GUI | |
| 36 #endif | |
| 37 | |
| 38 #include <stdlib.h> | |
| 39 #include <stdio.h> | |
| 40 #include <fcntl.h> | |
| 41 #include <unistd.h> | |
| 42 #include <string.h> | |
| 43 #include <time.h> | |
| 44 #include <sndfile.h> | |
| 45 #if defined(HAVE_MATH_H) | |
| 46 #define GEN_CONST | |
| 47 #endif | |
| 48 | |
| 49 //#if defined(WITH_SPANDSP_INTERNALS) | |
| 50 #define SPANDSP_EXPOSE_INTERNAL_STRUCTURES | |
| 51 //#endif | |
| 52 | |
| 53 #include "spandsp.h" | |
| 54 #include "spandsp-sim.h" | |
| 55 | |
| 56 #if defined(ENABLE_GUI) | |
| 57 #include "media_monitor.h" | |
| 58 #endif | |
| 59 | |
| 60 #define PACKET_SIZE 256 | |
| 61 #define PACKET_INTERVAL 20 | |
| 62 #define SIMULATION_TIME 300 | |
| 63 | |
| 64 #define MODEL_NO 8 | |
| 65 #define SPEED_PATTERN_NO 133 | |
| 66 | |
| 67 int main(int argc, char *argv[]) | |
| 68 { | |
| 69 rfc2198_sim_state_t *s; | |
| 70 double *packet_arrival_times; | |
| 71 int packets_per_sec; | |
| 72 int num_packets; | |
| 73 int model_no; | |
| 74 int speed_pattern_no; | |
| 75 int use_gui; | |
| 76 int simulation_time; | |
| 77 int i; | |
| 78 int len; | |
| 79 uint8_t put_pkt[256]; | |
| 80 uint8_t get_pkt[256]; | |
| 81 int put_pkt_len; | |
| 82 int get_pkt_len; | |
| 83 int get_seq_no; | |
| 84 double get_departure_time; | |
| 85 double get_arrival_time; | |
| 86 int packets_put; | |
| 87 int packets_really_put; | |
| 88 int packets_got; | |
| 89 int oos_packets_got; | |
| 90 int missing_packets_got; | |
| 91 int highest_seq_no_got; | |
| 92 int opt; | |
| 93 FILE *out_file; | |
| 94 | |
| 95 model_no = MODEL_NO; | |
| 96 speed_pattern_no = SPEED_PATTERN_NO; | |
| 97 simulation_time = SIMULATION_TIME; | |
| 98 use_gui = FALSE; | |
| 99 while ((opt = getopt(argc, argv, "gm:s:t:")) != -1) | |
| 100 { | |
| 101 switch (opt) | |
| 102 { | |
| 103 case 'g': | |
| 104 #if defined(ENABLE_GUI) | |
| 105 use_gui = TRUE; | |
| 106 #else | |
| 107 fprintf(stderr, "Graphical monitoring not available\n"); | |
| 108 exit(2); | |
| 109 #endif | |
| 110 break; | |
| 111 case 'm': | |
| 112 model_no = optarg[0] - 'A' + 1; | |
| 113 if (model_no < 0 || model_no > 8) | |
| 114 { | |
| 115 fprintf(stderr, "Bad model ID '%s'\n", optarg); | |
| 116 exit(2); | |
| 117 } | |
| 118 break; | |
| 119 case 's': | |
| 120 speed_pattern_no = atoi(optarg); | |
| 121 if (speed_pattern_no < 1 || speed_pattern_no > 133) | |
| 122 { | |
| 123 fprintf(stderr, "Bad link speed pattern %s\n", optarg); | |
| 124 exit(2); | |
| 125 } | |
| 126 break; | |
| 127 case 't': | |
| 128 simulation_time = atoi(optarg); | |
| 129 break; | |
| 130 default: | |
| 131 //usage(); | |
| 132 exit(2); | |
| 133 break; | |
| 134 } | |
| 135 } | |
| 136 argc -= optind; | |
| 137 argv += optind; | |
| 138 | |
| 139 if ((out_file = fopen("rfc2198_sim_tests.txt", "w")) == NULL) | |
| 140 { | |
| 141 fprintf(stderr, "Can't open %s\n", "rfc2198_sim_tests.txt"); | |
| 142 return 2; | |
| 143 } | |
| 144 packets_per_sec = 1000/PACKET_INTERVAL; | |
| 145 num_packets = packets_per_sec*simulation_time; | |
| 146 | |
| 147 if ((packet_arrival_times = calloc(num_packets, sizeof(double))) == NULL) | |
| 148 { | |
| 149 fprintf(stderr, "Can't allocate the data buffers\n"); | |
| 150 return 2; | |
| 151 } | |
| 152 for (i = 0; i < num_packets; i++) | |
| 153 packet_arrival_times[i] = 0.0; | |
| 154 | |
| 155 /* If we don't initialise this random number generator it gives endless zeros on some systems. */ | |
| 156 /* Use a fixed seed to produce identical results in successive runs of the simulation, for debug purposes. */ | |
| 157 srand48(0x1234567); | |
| 158 | |
| 159 if ((s = rfc2198_sim_init(model_no, speed_pattern_no, PACKET_SIZE, packets_per_sec, 3)) == NULL) | |
| 160 { | |
| 161 fprintf(stderr, "Failed to start the G.1050 model\n"); | |
| 162 exit(2); | |
| 163 } | |
| 164 //rfc2198_sim_dump_parms(model_no, speed_pattern_no); | |
| 165 | |
| 166 #if defined(ENABLE_GUI) | |
| 167 if (use_gui) | |
| 168 start_media_monitor(); | |
| 169 #endif | |
| 170 | |
| 171 for (i = 0; i < 256; i++) | |
| 172 put_pkt[i] = i; | |
| 173 put_pkt_len = 256; | |
| 174 get_pkt_len = -1; | |
| 175 get_seq_no = -1; | |
| 176 get_arrival_time = -1; | |
| 177 packets_put = 0; | |
| 178 packets_really_put = 0; | |
| 179 packets_got = 0; | |
| 180 oos_packets_got = 0; | |
| 181 missing_packets_got = 0; | |
| 182 highest_seq_no_got = -1; | |
| 183 for (i = 0; i < num_packets; i++) | |
| 184 { | |
| 185 if ((len = rfc2198_sim_put(s, put_pkt, put_pkt_len, i, (double) i*0.001*PACKET_INTERVAL)) > 0) | |
| 186 packets_really_put++; | |
| 187 packets_put++; | |
| 188 #if 0 | |
| 189 if (i == 5) | |
| 190 rfc2198_sim_queue_dump(s); | |
| 191 #endif | |
| 192 if (i >= 5) | |
| 193 { | |
| 194 do | |
| 195 { | |
| 196 get_pkt_len = rfc2198_sim_get(s, get_pkt, 256, (double) i*0.001*PACKET_INTERVAL, &get_seq_no, &get_departure_time, &get_arrival_time); | |
| 197 if (get_pkt_len >= 0) | |
| 198 { | |
| 199 #if defined(ENABLE_GUI) | |
| 200 if (use_gui) | |
| 201 media_monitor_rx(get_seq_no, get_departure_time, get_arrival_time); | |
| 202 #endif | |
| 203 packets_got++; | |
| 204 if (get_seq_no < highest_seq_no_got) | |
| 205 oos_packets_got++; | |
| 206 else if (get_seq_no > highest_seq_no_got + 1) | |
| 207 missing_packets_got += (get_seq_no - highest_seq_no_got - 1); | |
| 208 if (get_seq_no > highest_seq_no_got) | |
| 209 highest_seq_no_got = get_seq_no; | |
| 210 fprintf(out_file, "%d, %.3f, %.8f\n", get_seq_no, get_seq_no*0.001*PACKET_INTERVAL, get_arrival_time); | |
| 211 } | |
| 212 } | |
| 213 while (get_pkt_len >= 0); | |
| 214 } | |
| 215 #if defined(ENABLE_GUI) | |
| 216 if (use_gui) | |
| 217 media_monitor_update_display(); | |
| 218 #endif | |
| 219 } | |
| 220 /* Clear out anything remaining in the queue, by jumping forwards in time */ | |
| 221 do | |
| 222 { | |
| 223 get_pkt_len = rfc2198_sim_get(s, get_pkt, 256, (double) i*0.001*PACKET_INTERVAL + 5.0, &get_seq_no, &get_departure_time, &get_arrival_time); | |
| 224 if (get_pkt_len >= 0) | |
| 225 { | |
| 226 packets_got++; | |
| 227 fprintf(out_file, "%d, %.3f, %.8f\n", get_seq_no, get_seq_no*0.001*PACKET_INTERVAL, get_arrival_time); | |
| 228 } | |
| 229 } | |
| 230 while (get_pkt_len >= 0); | |
| 231 | |
| 232 fclose(out_file); | |
| 233 | |
| 234 printf("Put %d packets. Really put %d packets. Got %d packets.\n", packets_put, packets_really_put, packets_got); | |
| 235 printf("%d OOS packets, %d missing packets\n", oos_packets_got, missing_packets_got - oos_packets_got); | |
| 236 printf("%d packets queued, %d received\n", packets_really_put, packets_got); | |
| 237 printf("%.3f%% of packets lost before redundancy\n", 100.0*(packets_put - packets_really_put)/packets_put); | |
| 238 printf("%.3f%% of packets lost after redundancy\n", 100.0*(packets_put - packets_got)/packets_put); | |
| 239 return 0; | |
| 240 } | |
| 241 /*- End of function --------------------------------------------------------*/ | |
| 242 /*- End of file ------------------------------------------------------------*/ |
