[gnome-remote-desktop] rdp-gfx-surface: Add API to notify new round trip time



commit cb7804cd8204110b944279d791a383c61c30e7a0
Author: Pascal Nowack <Pascal Nowack gmx de>
Date:   Fri May 21 07:50:11 2021 +0200

    rdp-gfx-surface: Add API to notify new round trip time
    
    Extend the throttling mechanism by also considering the round trip
    time.
    The higher the round trip time, the higher the activate threshold for
    the throttling mechanism.
    This ensures that even on high latencies (up to 500ms everything works
    fine), gnome-remote-desktop will still be able to provide a smooth
    experience.
    The frame latency will still be delayed. This obviously cannot be
    changed, but the experience will stay smooth regarding any frame
    updates with both slow and fast clients.

 src/grd-rdp-gfx-surface.c | 32 ++++++++++++++++++++++++++++++++
 src/grd-rdp-gfx-surface.h |  3 +++
 2 files changed, 35 insertions(+)
---
diff --git a/src/grd-rdp-gfx-surface.c b/src/grd-rdp-gfx-surface.c
index f1b5532..e05f44c 100644
--- a/src/grd-rdp-gfx-surface.c
+++ b/src/grd-rdp-gfx-surface.c
@@ -52,6 +52,8 @@ struct _GrdRdpGfxSurface
 
   GrdRdpGfxFrameLog *frame_log;
 
+  int64_t nw_auto_last_rtt_us;
+
   ThrottlingState throttling_state;
   /* Throttling triggers on >= activate_throttling_th */
   uint32_t activate_throttling_th;
@@ -85,6 +87,23 @@ grd_rdp_gfx_surface_get_rdp_surface (GrdRdpGfxSurface *gfx_surface)
   return gfx_surface->rdp_surface;
 }
 
+static uint32_t
+get_activate_throttling_th_from_rtt (GrdRdpGfxSurface *gfx_surface,
+                                     int64_t           rtt_us)
+{
+  GrdRdpSurface *rdp_surface = gfx_surface->rdp_surface;
+  int64_t refresh_rate = rdp_surface->refresh_rate;
+  uint32_t activate_throttling_th;
+  uint32_t delayed_frames;
+
+  delayed_frames = rtt_us * refresh_rate / G_USEC_PER_SEC;
+
+  activate_throttling_th = MAX (2, MIN (delayed_frames + 2, refresh_rate));
+  g_assert (activate_throttling_th > gfx_surface->deactivate_throttling_th);
+
+  return activate_throttling_th;
+}
+
 void
 grd_rdp_gfx_surface_unack_frame (GrdRdpGfxSurface *gfx_surface,
                                  uint32_t          frame_id,
@@ -104,6 +123,9 @@ grd_rdp_gfx_surface_unack_frame (GrdRdpGfxSurface *gfx_surface,
   switch (gfx_surface->throttling_state)
     {
     case THROTTLING_STATE_INACTIVE:
+      gfx_surface->activate_throttling_th = get_activate_throttling_th_from_rtt (
+        gfx_surface, gfx_surface->nw_auto_last_rtt_us);
+
       if (n_unacked_frames >= gfx_surface->activate_throttling_th)
         {
           gfx_surface->throttling_state = THROTTLING_STATE_ACTIVE;
@@ -170,6 +192,9 @@ reevaluate_encoding_suspension_state (GrdRdpGfxSurface *gfx_surface)
   switch (gfx_surface->throttling_state)
     {
     case THROTTLING_STATE_INACTIVE:
+      gfx_surface->activate_throttling_th = get_activate_throttling_th_from_rtt (
+        gfx_surface, gfx_surface->nw_auto_last_rtt_us);
+
       if (n_unacked_frames >= gfx_surface->activate_throttling_th)
         {
           gfx_surface->throttling_state = THROTTLING_STATE_ACTIVE;
@@ -212,6 +237,13 @@ grd_rdp_gfx_surface_clear_all_unacked_frames (GrdRdpGfxSurface *gfx_surface)
     g_source_set_ready_time (gfx_surface->pending_encode_source, 0);
 }
 
+void
+grd_rdp_gfx_surface_notify_new_round_trip_time (GrdRdpGfxSurface *gfx_surface,
+                                                int64_t           round_trip_time_us)
+{
+  gfx_surface->nw_auto_last_rtt_us = round_trip_time_us;
+}
+
 static gboolean
 maybe_encode_pending_frame (gpointer user_data)
 {
diff --git a/src/grd-rdp-gfx-surface.h b/src/grd-rdp-gfx-surface.h
index 856e5e0..a2b57a2 100644
--- a/src/grd-rdp-gfx-surface.h
+++ b/src/grd-rdp-gfx-surface.h
@@ -57,4 +57,7 @@ void grd_rdp_gfx_surface_unack_last_acked_frame (GrdRdpGfxSurface *gfx_surface,
 
 void grd_rdp_gfx_surface_clear_all_unacked_frames (GrdRdpGfxSurface *gfx_surface);
 
+void grd_rdp_gfx_surface_notify_new_round_trip_time (GrdRdpGfxSurface *gfx_surface,
+                                                     int64_t           round_trip_time_us);
+
 #endif /* GRD_RDP_GFX_SURFACE_H */


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