changeset 26:47b3caeb47c5

improved frequent update avoidance.
author Yoshiki Yazawa <yaz@honeyplanet.jp>
date Sat, 24 Jan 2009 17:05:02 +0900
parents c0280cf3ca84
children 1d6975f2b5b3
files pidgin-audacious.c pidgin-audacious.h
diffstat 2 files changed, 16 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/pidgin-audacious.c	Sat Jan 24 14:57:20 2009 +0900
+++ b/pidgin-audacious.c	Sat Jan 24 17:05:02 2009 +0900
@@ -215,6 +215,8 @@
 
     song_info = format_song_info(tuple);
 
+    aud_debug("track_signal_hook %s\n", song_info);
+
     aud_process(song_info);
     free_song_tuple(tuple);
     g_free(song_info);
@@ -227,29 +229,20 @@
 track_signal_cb(DBusGProxy *player_proxy, GHashTable *table, gpointer data)
 {
     GTimeVal current;
-    gulong interval;
+    guint mil_interval;
     song_tuple *tuple = get_song_tuple(table);
 
     g_get_current_time(&current);
 
-    if(current.tv_sec > latest.tv_sec) {
-        interval = current.tv_sec - latest.tv_sec;
-
-        if(interval < MINIMAL_INTERVAL) {
-            g_timeout_add_seconds(MINIMAL_INTERVAL - interval,
-                                  track_signal_hook, (gpointer)tuple);
-
-            latest.tv_sec = current.tv_sec + MINIMAL_INTERVAL - interval;
-        }
-        else {
-            track_signal_hook((gpointer)tuple);
-            latest.tv_sec = current.tv_sec;
-        }
+    if(current.tv_sec >= latest.tv_sec) {
+        track_signal_hook((gpointer)tuple);
+        latest.tv_sec = current.tv_sec;
     }
-    else {
-        latest.tv_sec = latest.tv_sec + MINIMAL_INTERVAL;
-        g_timeout_add_seconds(latest.tv_sec - current.tv_sec,
-                              track_signal_hook, (gpointer)tuple);
+    else { /* current < lataset */
+        g_time_val_add(&latest, 200000); /* 0.2sec ahead */
+        mil_interval = (latest.tv_sec - current.tv_sec) * 1000
+            + (latest.tv_usec - current.tv_usec) / 1000;
+        g_timeout_add(mil_interval, track_signal_hook, (gpointer)tuple);
     }
 }
 
@@ -257,9 +250,7 @@
 static gboolean
 status_signal_hook(gpointer data)
 {
-    gboolean stopped = !is_app_playing();
-
-    if(stopped) {
+    if(!is_app_playing()) {
         /* clear status/user info */
         aud_process(NULL);
         /* clear current song */
@@ -278,6 +269,9 @@
 
 	aud_debug("StatusChange %d\n", status);
 
+    if(status != STOPPED)
+        return;
+
     g_get_current_time(&current);
 
     if(current.tv_sec > latest.tv_sec) {
@@ -294,9 +288,6 @@
         }
     }
     else { /* current < latest */
-        /* latest.tv_sec = latest.tv_sec + MINIMAL_INTERVAL; */
-        /* g_timeout_add_seconds(latest.tv_sec - current.tv_sec, */
-        /*                       status_signal_hook, NULL); */
         latest.tv_sec = latest.tv_sec + MINIMAL_INTERVAL;
         g_timeout_add_seconds(latest.tv_sec - current.tv_sec,
                               status_signal_hook, NULL);
--- a/pidgin-audacious.h	Sat Jan 24 14:57:20 2009 +0900
+++ b/pidgin-audacious.h	Sat Jan 24 17:05:02 2009 +0900
@@ -40,7 +40,7 @@
 
 /* constants */
 #define DBUS_TIMEOUT 1000
-#define MINIMAL_INTERVAL 8
+#define MINIMAL_INTERVAL 12
 #define PLAYING 0
 #define PAUSED  1
 #define STOPPED 2