[gnome-remote-desktop] rdp/nw-auto: Fix initial ping source not being created



commit 351893fac77dea21a44fc44508ba2eefe1d1af4a
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Mon May 16 17:42:22 2022 +0200

    rdp/nw-auto: Fix initial ping source not being created
    
    Currently, gnome-remote-desktop does not create the initial GSource to
    emit pings, unless ping interval changes to low due to inactivity on
    the screen.
    As a result, stutters can appear.
    
    To fix this issue, introduce a new ping internal with the name "NONE".
    This new interval represents the absence of the ping source.
    When the client emits the SuppressOutput PDU, where
    gnome-remote-desktop stops emitting pings, also reset the ping
    interval.

 src/grd-rdp-network-autodetection.c | 34 ++++++++++++++++++++++------------
 1 file changed, 22 insertions(+), 12 deletions(-)
---
diff --git a/src/grd-rdp-network-autodetection.c b/src/grd-rdp-network-autodetection.c
index 74161426..15c06cfc 100644
--- a/src/grd-rdp-network-autodetection.c
+++ b/src/grd-rdp-network-autodetection.c
@@ -31,6 +31,7 @@
 
 typedef enum _PingInterval
 {
+  PING_INTERVAL_NONE,
   PING_INTERVAL_HIGH,
   PING_INTERVAL_LOW,
 } PingInterval;
@@ -104,6 +105,16 @@ is_active_high_nec_rtt_consumer (GrdRdpNetworkAutodetection    *network_autodete
   return FALSE;
 }
 
+static gboolean
+has_active_high_nec_rtt_consumers (GrdRdpNetworkAutodetection *network_autodetection)
+{
+  if (is_active_high_nec_rtt_consumer (network_autodetection,
+                                       GRD_RDP_NW_AUTODETECT_RTT_CONSUMER_RDPGFX))
+    return TRUE;
+
+  return FALSE;
+}
+
 static uint16_t
 get_next_free_sequence_number (GrdRdpNetworkAutodetection *network_autodetection)
 {
@@ -146,30 +157,26 @@ emit_ping (gpointer user_data)
 static void
 update_ping_source (GrdRdpNetworkAutodetection *network_autodetection)
 {
-  GrdRdpNwAutodetectRTTConsumer active_high_nec_rtt_consumers;
   PingInterval new_ping_interval_type;
   uint32_t ping_interval_ms;
 
-  active_high_nec_rtt_consumers = GRD_RDP_NW_AUTODETECT_RTT_CONSUMER_NONE;
-  if (is_active_high_nec_rtt_consumer (
-        network_autodetection, GRD_RDP_NW_AUTODETECT_RTT_CONSUMER_RDPGFX))
-    active_high_nec_rtt_consumers |= GRD_RDP_NW_AUTODETECT_RTT_CONSUMER_RDPGFX;
-
-  if (active_high_nec_rtt_consumers)
+  if (network_autodetection->rtt_consumers == GRD_RDP_NW_AUTODETECT_RTT_CONSUMER_NONE)
+    new_ping_interval_type = PING_INTERVAL_NONE;
+  else if (has_active_high_nec_rtt_consumers (network_autodetection))
     new_ping_interval_type = PING_INTERVAL_HIGH;
   else
     new_ping_interval_type = PING_INTERVAL_LOW;
 
-  if ((network_autodetection->rtt_consumers == GRD_RDP_NW_AUTODETECT_RTT_CONSUMER_NONE ||
-       network_autodetection->ping_interval != new_ping_interval_type) &&
+  if (network_autodetection->ping_interval != new_ping_interval_type &&
       network_autodetection->ping_source)
     {
       g_source_destroy (network_autodetection->ping_source);
       g_clear_pointer (&network_autodetection->ping_source, g_source_unref);
     }
 
-  if (network_autodetection->rtt_consumers == GRD_RDP_NW_AUTODETECT_RTT_CONSUMER_NONE ||
-      network_autodetection->ping_interval == new_ping_interval_type)
+  network_autodetection->ping_interval = new_ping_interval_type;
+
+  if (network_autodetection->ping_interval == PING_INTERVAL_NONE)
     return;
 
   g_assert (!network_autodetection->ping_source);
@@ -177,6 +184,8 @@ update_ping_source (GrdRdpNetworkAutodetection *network_autodetection)
 
   switch (new_ping_interval_type)
     {
+    case PING_INTERVAL_NONE:
+      g_assert_not_reached ();
     case PING_INTERVAL_HIGH:
       ping_interval_ms = PING_INTERVAL_HIGH_MS;
       break;
@@ -189,7 +198,6 @@ update_ping_source (GrdRdpNetworkAutodetection *network_autodetection)
   g_source_set_callback (network_autodetection->ping_source, emit_ping,
                          network_autodetection, NULL);
   g_source_attach (network_autodetection->ping_source, NULL);
-  network_autodetection->ping_interval = new_ping_interval_type;
 }
 
 void
@@ -430,6 +438,8 @@ grd_rdp_network_autodetection_finalize (GObject *object)
 static void
 grd_rdp_network_autodetection_init (GrdRdpNetworkAutodetection *network_autodetection)
 {
+  network_autodetection->ping_interval = PING_INTERVAL_NONE;
+
   network_autodetection->sequences = g_hash_table_new (NULL, NULL);
   network_autodetection->pings = g_queue_new ();
   network_autodetection->round_trip_times = g_queue_new ();


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