[vlc-commits] dbus: don't spam dbus events

Thomas Guillem git at videolan.org
Fri Feb 9 19:57:27 CET 2018


vlc/vlc-3.0 | branch: master | Thomas Guillem <thomas at gllm.fr> | Thu Feb  8 16:32:25 2018 +0100| [95b79bda2fcf55860f57dc17e1d4500f63f0433b] | committer: Thomas Guillem

dbus: don't spam dbus events

Wait 100ms before sending new events and drop identical events.

This fixes global Desktop freeze (happening on Gnome Shell with Debian stable)
when playing some files that update metadatas too much. This can also happen
when the playlist fail to open a lot of files in a row.

(cherry picked from commit 9c146272d089e36ce79730adc36fe611495fd926)
Signed-off-by: Thomas Guillem <thomas at gllm.fr>

> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=95b79bda2fcf55860f57dc17e1d4500f63f0433b
---

 modules/control/dbus/dbus.c | 42 ++++++++++++++++++++++++++++++++++++------
 1 file changed, 36 insertions(+), 6 deletions(-)

diff --git a/modules/control/dbus/dbus.c b/modules/control/dbus/dbus.c
index 0e353785dd..77923daa02 100644
--- a/modules/control/dbus/dbus.c
+++ b/modules/control/dbus/dbus.c
@@ -75,6 +75,7 @@
 #define DBUS_INSTANCE_ID_PREFIX "instance"
 
 #define SEEK_THRESHOLD 1000 /* µsec */
+#define EVENTS_DELAY INT64_C(100000) /* 100 ms */
 
 /*****************************************************************************
  * Local prototypes.
@@ -768,6 +769,8 @@ static void *Run( void *data )
 
     int canc = vlc_savecancel();
 
+    mtime_t events_last_date = VLC_TS_INVALID;
+    int events_poll_timeout = -1;
     for( ;; )
     {
         vlc_mutex_lock( &p_sys->lock );
@@ -783,6 +786,8 @@ static void *Run( void *data )
 
         /* thread cancellation is allowed while the main loop sleeps */
         vlc_restorecancel( canc );
+        if( timeout == -1 )
+            timeout = events_poll_timeout;
 
         while (poll(fds, i_fds, timeout) == -1)
         {
@@ -822,18 +827,43 @@ static void *Run( void *data )
 
         /* Get the list of events to process */
         size_t i_events = vlc_array_count( &p_sys->events );
-        callback_info_t* p_info[i_events ? i_events : 1];
-        for( size_t i = 0; i < i_events; i++ )
+        callback_info_t** pp_info = NULL;
+
+        if( i_events > 0 )
         {
-            p_info[i] = vlc_array_item_at_index( &p_sys->events, i );
+            mtime_t now = mdate();
+            if( now - events_last_date > EVENTS_DELAY )
+            {
+                /* Send events every EVENTS_DELAY */
+                events_last_date = now;
+                events_poll_timeout = -1;
+
+                pp_info = vlc_alloc( i_events, sizeof(*pp_info) );
+                if( pp_info )
+                {
+                    for( size_t i = 0; i < i_events; i++ )
+                        pp_info[i] = vlc_array_item_at_index( &p_sys->events, i );
+                    vlc_array_clear( &p_sys->events );
+                }
+            }
+            else if( events_poll_timeout == -1 )
+            {
+                /* Request poll to wake up in order to send these events after
+                 * some delay */
+                events_poll_timeout = ( EVENTS_DELAY - ( now - events_last_date ) ) / 1000;
+            }
         }
-
-        vlc_array_clear( &p_sys->events );
+        else /* No events: clear timeout */
+            events_poll_timeout = -1;
 
         /* now we can release the lock and process what's pending */
         vlc_mutex_unlock( &p_intf->p_sys->lock );
 
-        ProcessEvents( p_intf, p_info, i_events );
+        if( pp_info )
+        {
+            ProcessEvents( p_intf, pp_info, i_events );
+            free( pp_info );
+        }
         ProcessWatches( p_intf, p_watches, i_watches, fds, i_fds );
 
         DispatchDBusMessages( p_intf );



More information about the vlc-commits mailing list