Mercurial > hg > audiostuff
comparison spandsp-0.0.6pre17/tests/media_monitor.cpp @ 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 * media_monitor.cpp - Display IP streaming media status, using the FLTK toolkit. | |
| 5 * | |
| 6 * Written by Steve Underwood <steveu@coppice.org> | |
| 7 * | |
| 8 * Copyright (C) 2007 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: media_monitor.cpp,v 1.5 2008/09/08 16:10:41 steveu Exp $ | |
| 26 */ | |
| 27 | |
| 28 #ifdef HAVE_CONFIG_H | |
| 29 #include "config.h" | |
| 30 #endif | |
| 31 | |
| 32 #if defined(HAVE_FL_FL_H) && defined(HAVE_FL_FL_CARTESIAN_H) | |
| 33 | |
| 34 #define __STDC_LIMIT_MACROS | |
| 35 | |
| 36 #include <inttypes.h> | |
| 37 #include <stdio.h> | |
| 38 #include <math.h> | |
| 39 #include <stdlib.h> | |
| 40 #include <string.h> | |
| 41 #include <unistd.h> | |
| 42 #include <sys/select.h> | |
| 43 | |
| 44 #include <FL/Fl.H> | |
| 45 #include <FL/Fl_Overlay_Window.H> | |
| 46 #include <FL/Fl_Light_Button.H> | |
| 47 #include <FL/Fl_Cartesian.H> | |
| 48 #include <FL/fl_draw.H> | |
| 49 | |
| 50 #include "spandsp.h" | |
| 51 #include "media_monitor.h" | |
| 52 | |
| 53 struct line_model_monitor_s | |
| 54 { | |
| 55 Fl_Double_Window *w; | |
| 56 | |
| 57 Fl_Group *c_right; | |
| 58 Fl_Group *c_sent; | |
| 59 Fl_Group *c_received; | |
| 60 | |
| 61 Ca_Canvas *canvas_sent; | |
| 62 Ca_X_Axis *sent_x; | |
| 63 Ca_Y_Axis *sent_y; | |
| 64 Ca_Line *sent_re; | |
| 65 double sent_re_plot[1000]; | |
| 66 double sent_re_plot_min; | |
| 67 double sent_re_plot_max; | |
| 68 | |
| 69 Ca_Canvas *canvas_received; | |
| 70 Ca_X_Axis *received_x; | |
| 71 Ca_Y_Axis *received_y; | |
| 72 Ca_Line *received_delays; | |
| 73 double received_delays_plot[4000]; | |
| 74 double received_delays_plot_max; | |
| 75 int min_diff; | |
| 76 int max_diff; | |
| 77 | |
| 78 int highest_seq_no_seen; | |
| 79 }; | |
| 80 | |
| 81 static int skip = 0; | |
| 82 static struct line_model_monitor_s media; | |
| 83 static struct line_model_monitor_s *s = &media; | |
| 84 | |
| 85 void media_monitor_rx(int seq_no, double departure_time, double arrival_time) | |
| 86 { | |
| 87 double fdiff; | |
| 88 int diff; | |
| 89 int i; | |
| 90 | |
| 91 if (s->received_delays) | |
| 92 delete s->received_delays; | |
| 93 | |
| 94 s->canvas_received->current(s->canvas_received); | |
| 95 fdiff = (arrival_time - departure_time)*1000.0; | |
| 96 diff = (int) fdiff; | |
| 97 if (diff < 0) | |
| 98 diff = 0; | |
| 99 else if (diff > 1999) | |
| 100 diff = 1999; | |
| 101 s->received_delays_plot[2*diff + 1]++; | |
| 102 if (s->received_delays_plot[2*diff + 1] > s->received_delays_plot_max) | |
| 103 { | |
| 104 s->received_delays_plot_max = s->received_delays_plot[2*diff + 1]; | |
| 105 s->received_y->maximum(s->received_delays_plot_max); | |
| 106 } | |
| 107 if (diff > s->max_diff) | |
| 108 { | |
| 109 s->max_diff = diff; | |
| 110 s->received_x->maximum((double) s->max_diff); | |
| 111 } | |
| 112 if (diff < s->min_diff) | |
| 113 { | |
| 114 s->min_diff = diff - 1; | |
| 115 s->received_x->minimum((double) s->min_diff); | |
| 116 } | |
| 117 | |
| 118 s->received_delays = new Ca_Line(2000, s->received_delays_plot, 0, 0, FL_BLUE, CA_NO_POINT); | |
| 119 | |
| 120 if (s->sent_re) | |
| 121 delete s->sent_re; | |
| 122 | |
| 123 s->canvas_sent->current(s->canvas_sent); | |
| 124 | |
| 125 if (seq_no > s->highest_seq_no_seen + 1) | |
| 126 { | |
| 127 for (i = s->highest_seq_no_seen + 1; i < seq_no; i++) | |
| 128 s->sent_re_plot[2*(i%500) + 1] = 0.0; | |
| 129 } | |
| 130 s->sent_re_plot[2*(seq_no%500) + 1] = fdiff; | |
| 131 | |
| 132 if (fdiff > s->sent_re_plot_max) | |
| 133 { | |
| 134 s->sent_re_plot_max = fdiff; | |
| 135 s->sent_y->maximum(s->sent_re_plot_max); | |
| 136 } | |
| 137 if (fdiff < s->sent_re_plot_min) | |
| 138 { | |
| 139 s->sent_re_plot_min = fdiff - 1.0; | |
| 140 s->sent_y->minimum(s->sent_re_plot_min); | |
| 141 } | |
| 142 s->sent_re = new Ca_Line(500, s->sent_re_plot, 0, 0, FL_BLUE, CA_NO_POINT); | |
| 143 | |
| 144 if (seq_no > s->highest_seq_no_seen) | |
| 145 s->highest_seq_no_seen = seq_no; | |
| 146 | |
| 147 if (++skip >= 100) | |
| 148 { | |
| 149 skip = 0; | |
| 150 Fl::check(); | |
| 151 } | |
| 152 } | |
| 153 /*- End of function --------------------------------------------------------*/ | |
| 154 | |
| 155 int start_media_monitor(void) | |
| 156 { | |
| 157 char buf[132 + 1]; | |
| 158 float x; | |
| 159 float y; | |
| 160 int i; | |
| 161 int len; | |
| 162 | |
| 163 len = 128; | |
| 164 | |
| 165 s->w = new Fl_Double_Window(465, 400, "IP streaming media monitor"); | |
| 166 | |
| 167 s->c_right = new Fl_Group(0, 0, 465, 405); | |
| 168 | |
| 169 s->c_sent = new Fl_Group(0, 0, 465, 200); | |
| 170 s->c_sent->box(FL_DOWN_BOX); | |
| 171 s->c_sent->align(FL_ALIGN_TOP | FL_ALIGN_INSIDE); | |
| 172 s->c_sent->current(); | |
| 173 | |
| 174 s->canvas_sent = new Ca_Canvas(110, 35, 300, 100, "Packet delays"); | |
| 175 s->canvas_sent->box(FL_PLASTIC_DOWN_BOX); | |
| 176 s->canvas_sent->color(7); | |
| 177 s->canvas_sent->align(FL_ALIGN_TOP); | |
| 178 Fl_Group::current()->resizable(s->canvas_sent); | |
| 179 s->canvas_sent->border(15); | |
| 180 | |
| 181 s->sent_x = new Ca_X_Axis(115, 135, 290, 30, "Packet"); | |
| 182 s->sent_x->align(FL_ALIGN_BOTTOM); | |
| 183 s->sent_x->minimum(0.0); | |
| 184 s->sent_x->maximum(500.0); | |
| 185 s->sent_x->label_format("%g"); | |
| 186 s->sent_x->minor_grid_color(fl_gray_ramp(20)); | |
| 187 s->sent_x->major_grid_color(fl_gray_ramp(15)); | |
| 188 s->sent_x->label_grid_color(fl_gray_ramp(10)); | |
| 189 s->sent_x->grid_visible(CA_LABEL_GRID | CA_ALWAYS_VISIBLE); | |
| 190 s->sent_x->minor_grid_style(FL_DOT); | |
| 191 s->sent_x->major_step(5); | |
| 192 s->sent_x->label_step(1); | |
| 193 s->sent_x->axis_align(CA_BOTTOM | CA_LINE); | |
| 194 s->sent_x->axis_color(FL_BLACK); | |
| 195 s->sent_x->current(); | |
| 196 | |
| 197 s->sent_y = new Ca_Y_Axis(60, 40, 50, 90, "Delay\n(ms)"); | |
| 198 s->sent_y->align(FL_ALIGN_LEFT); | |
| 199 s->sent_y->minimum(0.0); | |
| 200 s->sent_y->maximum(2000.0); | |
| 201 s->sent_y->minor_grid_color(fl_gray_ramp(20)); | |
| 202 s->sent_y->major_grid_color(fl_gray_ramp(15)); | |
| 203 s->sent_y->label_grid_color(fl_gray_ramp(10)); | |
| 204 s->sent_y->grid_visible(CA_LABEL_GRID | CA_ALWAYS_VISIBLE); | |
| 205 s->sent_y->minor_grid_style(FL_DOT); | |
| 206 s->sent_y->major_step(5); | |
| 207 s->sent_y->label_step(1); | |
| 208 s->sent_y->axis_color(FL_BLACK); | |
| 209 s->sent_y->current(); | |
| 210 | |
| 211 s->c_sent->end(); | |
| 212 | |
| 213 s->c_received = new Fl_Group(0, 200, 465, 200); | |
| 214 s->c_received->box(FL_DOWN_BOX); | |
| 215 s->c_received->align(FL_ALIGN_TOP | FL_ALIGN_INSIDE); | |
| 216 s->c_received->current(); | |
| 217 | |
| 218 s->canvas_received = new Ca_Canvas(110, 235, 300, 100, "Delay spread"); | |
| 219 s->canvas_received->box(FL_PLASTIC_DOWN_BOX); | |
| 220 s->canvas_received->color(7); | |
| 221 s->canvas_received->align(FL_ALIGN_TOP); | |
| 222 Fl_Group::current()->resizable(s->canvas_received); | |
| 223 s->canvas_received->border(15); | |
| 224 | |
| 225 s->received_x = new Ca_X_Axis(115, 335, 290, 30, "Delay (ms)"); | |
| 226 s->received_x->align(FL_ALIGN_BOTTOM); | |
| 227 s->received_x->minimum(0.0); | |
| 228 s->received_x->maximum(2000.0); | |
| 229 s->received_x->label_format("%g"); | |
| 230 s->received_x->minor_grid_color(fl_gray_ramp(20)); | |
| 231 s->received_x->major_grid_color(fl_gray_ramp(15)); | |
| 232 s->received_x->label_grid_color(fl_gray_ramp(10)); | |
| 233 s->received_x->grid_visible(CA_LABEL_GRID | CA_ALWAYS_VISIBLE); | |
| 234 s->received_x->minor_grid_style(FL_DOT); | |
| 235 s->received_x->major_step(5); | |
| 236 s->received_x->label_step(1); | |
| 237 s->received_x->axis_align(CA_BOTTOM | CA_LINE); | |
| 238 s->received_x->axis_color(FL_BLACK); | |
| 239 s->received_x->current(); | |
| 240 | |
| 241 s->received_y = new Ca_Y_Axis(60, 240, 50, 90, "Freq"); | |
| 242 s->received_y->align(FL_ALIGN_LEFT); | |
| 243 s->received_y->minimum(0.0); | |
| 244 s->received_y->maximum(50.0); | |
| 245 s->received_y->minor_grid_color(fl_gray_ramp(20)); | |
| 246 s->received_y->major_grid_color(fl_gray_ramp(15)); | |
| 247 s->received_y->label_grid_color(fl_gray_ramp(10)); | |
| 248 s->received_y->grid_visible(CA_LABEL_GRID | CA_ALWAYS_VISIBLE); | |
| 249 s->received_y->minor_grid_style(FL_DOT); | |
| 250 s->received_y->major_step(5); | |
| 251 s->received_y->label_step(1); | |
| 252 s->received_y->axis_color(FL_BLACK); | |
| 253 s->received_y->current(); | |
| 254 | |
| 255 for (i = 0; i < 2000; i++) | |
| 256 s->received_delays_plot[2*i] = i; | |
| 257 s->received_delays_plot_max = 0.0; | |
| 258 s->min_diff = 2000; | |
| 259 s->max_diff = 0; | |
| 260 | |
| 261 s->received_delays = NULL; | |
| 262 s->highest_seq_no_seen = -1; | |
| 263 | |
| 264 for (i = 0; i < 500; i++) | |
| 265 s->sent_re_plot[2*i] = i; | |
| 266 s->sent_re_plot_min = 99999.0; | |
| 267 s->sent_re_plot_max = 0.0; | |
| 268 s->sent_re = NULL; | |
| 269 | |
| 270 s->c_received->end(); | |
| 271 | |
| 272 s->c_right->end(); | |
| 273 | |
| 274 Fl_Group::current()->resizable(s->c_right); | |
| 275 s->w->end(); | |
| 276 s->w->show(); | |
| 277 | |
| 278 Fl::check(); | |
| 279 return 0; | |
| 280 } | |
| 281 /*- End of function --------------------------------------------------------*/ | |
| 282 | |
| 283 void media_monitor_wait_to_end(void) | |
| 284 { | |
| 285 fd_set rfds; | |
| 286 int res; | |
| 287 struct timeval tv; | |
| 288 | |
| 289 fprintf(stderr, "Processing complete. Press the <enter> key to end\n"); | |
| 290 do | |
| 291 { | |
| 292 usleep(100000); | |
| 293 Fl::check(); | |
| 294 FD_ZERO(&rfds); | |
| 295 FD_SET(0, &rfds); | |
| 296 tv.tv_usec = 100000; | |
| 297 tv.tv_sec = 0; | |
| 298 res = select(1, &rfds, NULL, NULL, &tv); | |
| 299 } | |
| 300 while (res <= 0); | |
| 301 } | |
| 302 /*- End of function --------------------------------------------------------*/ | |
| 303 | |
| 304 void media_monitor_update_display(void) | |
| 305 { | |
| 306 Fl::check(); | |
| 307 Fl::check(); | |
| 308 Fl::check(); | |
| 309 Fl::check(); | |
| 310 Fl::check(); | |
| 311 Fl::check(); | |
| 312 Fl::check(); | |
| 313 Fl::check(); | |
| 314 Fl::check(); | |
| 315 Fl::check(); | |
| 316 Fl::check(); | |
| 317 Fl::check(); | |
| 318 } | |
| 319 /*- End of function --------------------------------------------------------*/ | |
| 320 #endif | |
| 321 /*- End of file ------------------------------------------------------------*/ |
