[GnomeMeeting-devel-list] small bug in stats_drawing_area



Hi,

there is a small bug in the stats drawing area.

In endpoint.cpp:
---
if (gm_conf_get_int (USER_INTERFACE_KEY "main_window/control_panel_section") 
== 0)
gm_main_window_update_stats (main_window,
...
---

So the stats get only updated if the widget is visible. Unfortunately not only 
the visible stats is affected, but also the ringbuffer with the transfer 
speeds. To see the effect, during a call switch away from statistics pane, 
wait some seconds, and switch back - there will be a peak in the graph, as 
the data transfered during this time will be accumulated.

To fix this, the appeded fix does the following:
1) call gm_main_window_update_stats unconditionally
2) check for GTK_WIDGET_REALIZED() in the graph widget
3) check for GTK_WIDGET_REALIZED() when setting the labels in the statistics 
pane

Additionally, the patch cleans up stats_drawing_area.c a little bit:
1) adjust the ringbuffer size in the allocation to the size used in the rest 
of the code (100 -> 50)
2) optimize the calculation for the maximum transfer speed
3) put the calculation of the grid segments into the size_allocate function

Everything open for discussion ...

The patch has been tested with 1.2.1, but I have prepared versions for 1.2.1 
and OPAL_BRANCH. The first patch is for both Branches, the second comes in 
two versions.

Greetings,

Stefan

-- 
Stefan Brüns  /  Kastanienweg 6 - Zimmer 1206  /  52074 Aachen
mailto:lurch gmx li  http://www.kawo1.rwth-aachen.de/~lurchi/
   phone: +49 241 169-4206     mobile: +49 160 3797725
diff -dru gnomemeeting-1.2.1/lib/stats_drawing_area.c gnomemeeting_new/lib/stats_drawing_area.c
--- gnomemeeting-1.2.1/lib/stats_drawing_area.c	2004-08-20 17:43:00.000000000 +0200
+++ gnomemeeting_new/lib/stats_drawing_area.c	2005-04-05 23:41:15.198517212 +0200
@@ -51,16 +51,18 @@
   GdkGC *gc;
   GdkColormap *colormap;
   GdkColor colors [6];
+  GdkSegment* grid;
+  int numGridLines;
 
   int last_audio_octets_received;
   int last_video_octets_received;
   int last_audio_octets_transmitted;
   int last_video_octets_transmitted;
 
-  float transmitted_audio_speeds[100];
-  float received_audio_speeds[100];
-  float transmitted_video_speeds[100];
-  float received_video_speeds[100];
+  float transmitted_audio_speeds[50];
+  float received_audio_speeds[50];
+  float transmitted_video_speeds[50];
+  float received_video_speeds[50];
   int position;
 };
 
@@ -91,6 +93,12 @@
 static gboolean stats_drawing_area_exposed_cb (GtkWidget *,
 					       GdkEventExpose *,
 					       gpointer);
+/* DESCRIPTION  :
+ * PRE          :
+ */
+static void stats_drawing_area_size_allocate (GtkWidget *,
+					      GtkAllocation *);
+
 
 
 /* helper functions' implementation */
@@ -145,6 +153,9 @@
   self->pango_layout = pango_layout_new (self->pango_context);
   self->gc = NULL;
 
+  self->grid = NULL;
+  self->numGridLines = 0;
+
   g_signal_connect (G_OBJECT (self), "expose_event",
 		    G_CALLBACK (stats_drawing_area_exposed_cb), 
 		    NULL);
@@ -156,8 +167,10 @@
 stats_drawing_area_class_init (StatsDrawingAreaClass *klass)
 {
   GObjectClass *gobject_klass = G_OBJECT_CLASS (klass);
+  GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
 
   gobject_klass->finalize = stats_drawing_area_finalize;
+  widget_class->size_allocate = stats_drawing_area_size_allocate;
 }
 
 static void
@@ -173,7 +186,7 @@
   self->last_video_octets_transmitted = 0;
 
   self->position = 0;
-  for (i = 0; i < 100; i++) {
+  for (i = 0; i < 50; i++) {
     self->transmitted_audio_speeds[i] = (float)0;
     self->received_audio_speeds[i] = (float)0;
     self->transmitted_video_speeds[i] = (float)0;
@@ -189,12 +202,8 @@
 {
   StatsDrawingArea *self = NULL;
   
-  GdkSegment s [50];
-
   gchar *pango_text = NULL;
   
-  int x = 0;
-  int y = 0;
   int cpt = 0;
   int pos = 0;
   GdkPoint points [50];
@@ -202,11 +211,8 @@
   int allocation_height = 0;
   float height_step = 0;
 
-  float max_transmitted_video = 1;
-  float max_transmitted_audio = 1;
-  float max_received_video = 1;
-  float max_received_audio = 1;
-  gboolean success [256];
+  float max_speed = 1;
+  gboolean success [6];
 
   g_return_val_if_fail (IS_STATS_DRAWING_AREA (widget), FALSE);
 
@@ -223,10 +229,7 @@
   allocation_height = GTK_WIDGET (widget)->allocation.height;
 
   width_step = (int) GTK_WIDGET (widget)->allocation.width / 40;
-  height_step = allocation_height;
 
-  x = width_step;
-  
   gdk_gc_set_foreground (self->gc, &self->colors [0]);
   gdk_draw_rectangle (widget->window,
 		      self->gc,
@@ -238,57 +241,24 @@
   gdk_gc_set_line_attributes (self->gc, 1, GDK_LINE_SOLID, 
 			      GDK_CAP_ROUND, GDK_JOIN_BEVEL);
   
-  while ( y < allocation_height
-	  && cpt < 50) {
-
-    s [cpt].x1 = 0;
-    s [cpt].x2 = widget->allocation.width;
-    s [cpt].y1 = y;
-    s [cpt].y2 = y;
-      
-    y = y + 21;
-    cpt++;
-  }
- 
-  gdk_draw_segments (GDK_DRAWABLE (widget->window), self->gc, s, cpt);
-
-  cpt = 0;
-  while (x < widget->allocation.width && cpt < 50) {
-
-    s [cpt].x1 = x;
-    s [cpt].x2 = x;
-    s [cpt].y1 = 0;
-    s [cpt].y2 = widget->allocation.height;
-      
-    x = x + 21;
-    cpt++;
-  }
- 
-  gdk_draw_segments (GDK_DRAWABLE (widget->window), self->gc, s, cpt);
+  gdk_draw_segments (GDK_DRAWABLE (widget->window), self->gc, self->grid, self->numGridLines);
   gdk_window_set_background (widget->window, &self->colors [0]);
 
 
   /* Compute the height_step */
   for (cpt = 0 ; cpt < 50 ; cpt++) {
     
-    if (self->transmitted_audio_speeds [cpt] > max_transmitted_audio)
-      max_transmitted_audio = self->transmitted_audio_speeds [cpt];
-    if (self->received_audio_speeds [cpt] > max_received_audio)
-      max_received_audio = self->received_audio_speeds [cpt];
-    if (self->transmitted_video_speeds [cpt] > max_transmitted_video)
-      max_transmitted_video = self->transmitted_video_speeds [cpt];
-    if (self->received_video_speeds [cpt] > max_received_video)
-      max_received_video = self->received_video_speeds [cpt];    
+    if (self->transmitted_audio_speeds [cpt] > max_speed)
+      max_speed = self->transmitted_audio_speeds [cpt];
+    if (self->received_audio_speeds [cpt] > max_speed)
+      max_speed = self->received_audio_speeds [cpt];
+    if (self->transmitted_video_speeds [cpt] > max_speed)
+      max_speed = self->transmitted_video_speeds [cpt];
+    if (self->received_video_speeds [cpt] > max_speed)
+      max_speed = self->received_video_speeds [cpt];    
   }
-  if (max_received_video > allocation_height / height_step)
-    height_step = allocation_height / max_received_video;
-  if (max_received_audio > allocation_height / height_step)
-    height_step = allocation_height / max_received_audio;
-  if (max_transmitted_video > allocation_height / height_step)
-    height_step = allocation_height /  max_transmitted_video;
-  if (max_transmitted_audio > allocation_height / height_step)
-    height_step = allocation_height / max_transmitted_audio;
-  
+  height_step = allocation_height / max_speed;
+ 
   gdk_gc_set_line_attributes (self->gc, 2, GDK_LINE_SOLID, 
 			      GDK_CAP_ROUND, GDK_JOIN_BEVEL);
   
@@ -369,13 +339,65 @@
   gdk_draw_layout_with_colors (GDK_DRAWABLE (widget->window),
 			       self->gc, 5, 2,
 			       self->pango_layout,
-			       &self->colors [5], &self->colors [0]);
+			       &self->colors [5], 0);
   g_free (pango_text);
 
   return TRUE;
 }
 
 
+static void
+stats_drawing_area_size_allocate (GtkWidget *widget,
+				  GtkAllocation *allocation)
+{
+  StatsDrawingArea *self = NULL;
+  int y = 0;
+  int x = 0;
+  int cpt = 0;
+
+  g_return_if_fail (widget != NULL);
+  g_return_if_fail (IS_STATS_DRAWING_AREA (widget));
+  g_return_if_fail (allocation != NULL);
+
+  self = STATS_DRAWING_AREA (widget);
+
+  widget->allocation = *allocation;
+  if (GTK_WIDGET_REALIZED (widget)) {
+    gdk_window_move_resize (widget->window,
+			    allocation->x, allocation->y,
+			    allocation->width, allocation->height);
+  }
+
+  /* Calculate Grid Segments */
+  self->numGridLines = ((20+allocation->height) / 21) + ((20+allocation->width) / 21);
+  GdkSegment* s = (GdkSegment*) malloc(self->numGridLines * sizeof(GdkSegment));
+  free(self->grid);
+  self->grid = s;
+
+  while ( y < allocation->height) {
+
+    s [cpt].x1 = 0;
+    s [cpt].x2 = allocation->width;
+    s [cpt].y1 = y;
+    s [cpt].y2 = y;
+      
+    y = y + 21;
+    cpt++;
+  }
+ 
+  while (x < allocation->width) {
+
+    s [cpt].x1 = x;
+    s [cpt].x2 = x;
+    s [cpt].y1 = 0;
+    s [cpt].y2 = allocation->height;
+      
+    x = x + 21;
+    cpt++;
+  }
+}
+
+
 /* implementation of the external api */
 
 
@@ -444,16 +466,6 @@
 
   self = STATS_DRAWING_AREA (widget);
 
-  /* sets things right at startup */
-  if (self->last_audio_octets_transmitted == 0 && self->position == 0)
-    self->last_audio_octets_transmitted = new_audio_octets_transmitted;
-  if (self->last_audio_octets_received == 0 && self->position == 0)
-    self->last_audio_octets_received = new_audio_octets_received;
-  if (self->last_video_octets_transmitted == 0 && self->position == 0)
-    self->last_video_octets_transmitted = new_video_octets_transmitted;
-  if (self->last_video_octets_received == 0 && self->position == 0)
-    self->last_video_octets_received = new_video_octets_received;
-
   /* compute speeds */
   received_audio_speed = (float) (new_audio_octets_received - self->last_audio_octets_received)/ 1024;
   transmitted_audio_speed = (float) (new_audio_octets_transmitted - self->last_audio_octets_transmitted)/ 1024;
@@ -476,5 +488,6 @@
   self->last_video_octets_transmitted = new_video_octets_transmitted;
   self->last_video_octets_received = new_video_octets_received;
 
-  gtk_widget_queue_draw (GTK_WIDGET (self));
+  if (GTK_WIDGET_REALIZED (self))
+	  gtk_widget_queue_draw (GTK_WIDGET (self));
 }
diff -dru gnomemeeting-1.2.1/src/endpoint.cpp gnomemeeting_new/src/endpoint.cpp
--- gnomemeeting-1.2.1/src/endpoint.cpp	2005-02-14 09:25:24.000000000 +0100
+++ gnomemeeting_new/src/endpoint.cpp	2005-04-05 23:17:52.227255186 +0200
@@ -2126,9 +2126,7 @@
   gdk_threads_enter ();
   gm_main_window_flash_message (main_window, msg);
 
-  if (gm_conf_get_int (USER_INTERFACE_KEY "main_window/control_panel_section") 
-      == 0)
-    gm_main_window_update_stats (main_window,
+  gm_main_window_update_stats (main_window,
 			     lost_packets_per,
 			     late_packets_per,
 			     (int) rtt,
diff -dru gnomemeeting-1.2.1/src/main_window.cpp gnomemeeting_new/src/main_window.cpp
--- gnomemeeting-1.2.1/src/main_window.cpp	2005-01-28 12:18:16.000000000 +0100
+++ gnomemeeting_new/src/main_window.cpp	2005-04-05 21:28:23.186557388 +0200
@@ -4074,9 +4074,13 @@
 
   g_return_if_fail (mw != NULL);
 
-  stats_msg =  g_strdup_printf (_("Lost packets: %.1f %%\nLate packets: %.1f %%\nRound-trip delay: %d ms\nJitter buffer: %d ms"), lost, late, rtt, jitter);
-  gtk_label_set_text (GTK_LABEL (mw->stats_label), stats_msg);
-  g_free (stats_msg);
+  if (GTK_WIDGET_REALIZED (mw->stats_label)) {
+
+    stats_msg =  g_strdup_printf (_("Lost packets: %.1f %%\nLate packets: %.1f %%\nRound-trip delay: %d ms\nJitter buffer: %d ms"), lost, late, rtt, jitter);
+    gtk_label_set_text (GTK_LABEL (mw->stats_label), stats_msg);
+    g_free (stats_msg);
+  }
+
 
   stats_drawing_area_new_data (mw->stats_drawing_area,
 			       new_video_octets_received,
diff -dru gnomemeeting-1.2.1/src/endpoint.cpp gnomemeeting_new/src/endpoint.cpp
--- gnomemeeting-1.2.1/src/endpoint.cpp	2005-02-14 09:25:24.000000000 +0100
+++ gnomemeeting_new/src/endpoint.cpp	2005-04-05 23:17:52.227255186 +0200
@@ -2126,9 +2126,7 @@
   gdk_threads_enter ();
   gm_main_window_flash_message (main_window, msg);
 
-  if (gm_conf_get_int (USER_INTERFACE_KEY "main_window/control_panel_section") 
-      == 0)
-    gm_main_window_update_stats (main_window,
+  gm_main_window_update_stats (main_window,
 				lost_packets_per,
 				late_packets_per,
 				out_of_order_packets_per,
diff -dru gnomemeeting-1.2.1/src/main_window.cpp gnomemeeting_new/src/main_window.cpp
--- gnomemeeting-1.2.1/src/main_window.cpp	2005-01-28 12:18:16.000000000 +0100
+++ gnomemeeting_new/src/main_window.cpp	2005-04-05 21:28:23.186557388 +0200
@@ -4074,9 +4074,13 @@
 
   g_return_if_fail (mw != NULL);
 
-  stats_msg =  g_strdup_printf (_("Lost packets: %.1f %%\nLate packets: %.1f %%\nOut of order packets: %.1f %%\nJitter buffer: %d ms"), lost, late, out_of_order, jitter);
-  gtk_label_set_text (GTK_LABEL (mw->stats_label), stats_msg);
-  g_free (stats_msg);
+  if (GTK_WIDGET_REALIZED (mw->stats_label)) {
+
+    stats_msg =  g_strdup_printf (_("Lost packets: %.1f %%\nLate packets: %.1f %%\nOut of order packets: %.1f %%\nJitter buffer: %d ms"), lost, late, out_of_order, jitter);
+    gtk_label_set_text (GTK_LABEL (mw->stats_label), stats_msg);
+    g_free (stats_msg);
+  }
+
 
   stats_drawing_area_new_data (mw->stats_drawing_area,
 			       new_video_octets_received,

Attachment: pgpBKNnxgGRuL.pgp
Description: PGP signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]