]> git.sesse.net Git - vlc/blobdiff - modules/misc/notify/telepathy.c
telepathy: avoid flooding the bus when playing some special inputs.
[vlc] / modules / misc / notify / telepathy.c
index 885bbe7fad353a24abd65598800899ad8d81239b..6d093adf6dea0770a891888ffdd4e6ee966f32a3 100644 (file)
  *****************************************************************************/
 struct intf_sys_t
 {
-    char *psz_format;
+    char            *psz_format;
     DBusConnection  *p_conn;
+    int             i_id;
+    int             i_item-changes;
 };
 
 /*****************************************************************************
@@ -57,9 +59,9 @@ static int SendToTelepathy( intf_thread_t *, const char * );
 #define FORMAT_DEFAULT "$a - $t"
 #define FORMAT_TEXT N_("Title format string")
 #define FORMAT_LONGTEXT N_("Format of the string to send to Telepathy." \
-"Defaults to \"Artist - Title\" ($a - $t)." \
+"Defaults to \"Artist - Title\" ($a - $t). " \
 "You can use the following substitutions: " \
-"$a Artist, $b Album, $c, Copyright, $d Description, $e Encoder, $g Genre, " \
+"$a Artist, $b Album, $c Copyright, $d Description, $e Encoder, $g Genre, " \
 "$l Language, $n number, $p Now Playing, $r Rating, $s Subtitles language, " \
 "$t Title, $u URL, $A Date, $B Bitrate, $C Chapter, $D Duration, $F URI, " \
 "$I Video Title, $L Time Remaining, $N Name, $O Audio language, $P Position, " \
@@ -98,13 +100,13 @@ static int Open( vlc_object_t *p_this )
     }
     msg_Dbg( p_intf, "using format: %s", p_intf->p_sys->psz_format );
 
+    p_intf->p_sys->i_id = -1;
+
     p_playlist = pl_Yield( p_intf );
     var_AddCallback( p_playlist, "item-change", ItemChange, p_intf );
     var_AddCallback( p_playlist, "playlist-current", ItemChange, p_intf );
     pl_Release( p_intf );
 
-    dbus_threads_init_default();
-
     dbus_error_init( &error );
 
     /* connect to the session bus */
@@ -156,6 +158,25 @@ static int ItemChange( vlc_object_t *p_this, const char *psz_var,
     intf_thread_t *p_intf = (intf_thread_t *)param;
     char *psz_buf = NULL;
     input_thread_t *p_input;
+
+    /* Don't update Telepathy presence each time an item has been preparsed */
+    if( !strncmp( "playlist-current", psz_var, 16 ) )
+    { /* stores the current input item id */
+        p_intf->p_sys->i_id = newval.i_int;
+        p_intf->p_sys->i_item-changes = 0;
+    }
+    else
+    {
+        if( newval.i_int != p_intf->p_sys->i_id ) /* "item-change" */
+            return VLC_SUCCESS;
+        /* some variable bitrate inputs call "item-change callbacks each time
+         * their length is updated, that is several times per second. */
+        if( p_intf->p_sys->i_item-changes > 5 )
+            return VLC_SUCCESS;
+        p_intf->p_sys->i_item-changes++;
+    }
+
+
     playlist_t *p_playlist = pl_Yield( p_this );
 
     p_input = p_playlist->p_input;
@@ -218,7 +239,7 @@ static int SendToTelepathy( intf_thread_t *p_intf, const char *psz_msg )
         return VLC_ENOMEM;
 
     p_reply = dbus_connection_send_with_reply_and_block( p_conn, p_msg,
-        1000, &error );
+        50, &error ); /* blocks 50ms maximum */
 
     dbus_message_unref( p_msg );
     if( p_reply == NULL )