# HG changeset patch # User Yoshiki Yazawa # Date 1232784302 -32400 # Node ID 47b3caeb47c5793894cd28efbc30c3f82d6e79e6 # Parent c0280cf3ca84f6f76297341505a635062e687d15 improved frequent update avoidance. diff -r c0280cf3ca84 -r 47b3caeb47c5 pidgin-audacious.c --- 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(¤t); - 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(¤t); 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); diff -r c0280cf3ca84 -r 47b3caeb47c5 pidgin-audacious.h --- 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