From 5a32d3bfc004476754bd09ae3180a1aed86fcfc0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Cartegnie?= <fcvlcdev@free.fr>
Date: Mon, 2 Dec 2024 18:14:45 +0700
Subject: [PATCH] input: add stats-min-report-interval instead of fixed rate

Aiming at tests using reporting events in realtime.
Allows finer reporting, or per sample, instead of fixed interval.
---
 src/input/input.c   | 4 +++-
 src/libvlc-module.c | 7 +++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/input/input.c b/src/input/input.c
index 7f32eaa22ce7..58242179b752 100644
--- a/src/input/input.c
+++ b/src/input/input.c
@@ -625,6 +625,8 @@ static void MainLoopStatistics( input_thread_t *p_input )
 static void MainLoop( input_thread_t *p_input, bool b_interactive )
 {
     vlc_tick_t i_intf_update = 0;
+    vlc_tick_t i_inf_update_delay =
+        VLC_TICK_FROM_MS(var_InheritInteger( p_input, "stats-min-report-interval" ));
     vlc_tick_t i_last_seek_mdate = 0;
 
     if( b_interactive && var_InheritBool( p_input, "start-paused" ) )
@@ -697,7 +699,7 @@ static void MainLoop( input_thread_t *p_input, bool b_interactive )
             if( now >= i_intf_update )
             {
                 MainLoopStatistics( p_input );
-                i_intf_update = now + VLC_TICK_FROM_MS(250);
+                i_intf_update = now + i_inf_update_delay;
             }
         }
 
diff --git a/src/libvlc-module.c b/src/libvlc-module.c
index 832eddd722fa..7b24b8f4c647 100644
--- a/src/libvlc-module.c
+++ b/src/libvlc-module.c
@@ -1119,6 +1119,10 @@ static const char* const ppsz_restore_playback_desc[] = {
 #define STATS_LONGTEXT N_( \
      "Collect miscellaneous local statistics about the playing media.")
 
+#define STATSFREQ_TEXT N_("Statistics collection frequency")
+#define STATSFREQ_LONGTEXT N_( \
+     "Collection frequency of the statistics in ms.")
+
 #define ONEINSTANCE_TEXT N_("Allow only one running instance")
 #define ONEINSTANCE_LONGTEXT N_( \
     "Allowing only one running instance of VLC can sometimes be useful, " \
@@ -2227,6 +2231,9 @@ vlc_module_begin ()
               INTERACTION_LONGTEXT )
 
     add_bool ( "stats", true, STATS_TEXT, STATS_LONGTEXT )
+    add_integer( "stats-min-report-interval", 250,
+                        STATSFREQ_TEXT, STATSFREQ_LONGTEXT );
+        change_integer_range( 0, INT32_MAX )
 
     set_subcategory( SUBCAT_INTERFACE_MAIN )
     add_module_cat("intf", SUBCAT_INTERFACE_MAIN, NULL,
-- 
GitLab