[Spice-devel,6/7] server: Add time constants to go with spice_get_monotonic_time_ms()

Submitted by Francois Gouget on Dec. 11, 2015, 11:22 a.m.

Details

Message ID alpine.DEB.2.20.1512111215550.1593@amboise
State New
Headers show
Series "Series without cover letter" ( rev: 1 ) in Spice

Not browsing as part of any series.

Commit Message

Francois Gouget Dec. 11, 2015, 11:22 a.m.
They clarify the time unit being used and simplify calculations.

Signed-off-by: Francois Gouget <fgouget@codeweavers.com>
---
 server/inputs-channel.c | 3 ++-
 server/main-channel.c   | 6 +++---
 server/mjpeg-encoder.c  | 8 ++++----
 server/red-channel.c    | 4 ++--
 server/reds-private.h   | 2 +-
 server/stream.h         | 2 +-
 server/utils.h          | 2 ++
 7 files changed, 15 insertions(+), 12 deletions(-)

Patch hide | download patch | download mbox

diff --git a/server/inputs-channel.c b/server/inputs-channel.c
index 74aa30d..60474e1 100644
--- a/server/inputs-channel.c
+++ b/server/inputs-channel.c
@@ -42,6 +42,7 @@ 
 #include "main-channel.h"
 #include "inputs-channel.h"
 #include "migration-protocol.h"
+#include "utils.h"
 
 // TODO: RECEIVE_BUF_SIZE used to be the same for inputs_channel and main_channel
 // since it was defined once in reds.c which contained both.
@@ -111,7 +112,7 @@  static SpiceTimer *key_modifiers_timer;
 
 static InputsChannel *g_inputs_channel = NULL;
 
-#define KEY_MODIFIERS_TTL (1000 * 2) /*2sec*/
+#define KEY_MODIFIERS_TTL (MS_PER_SECOND * 2)
 
 #define SCROLL_LOCK_SCAN_CODE 0x46
 #define NUM_LOCK_SCAN_CODE 0x45
diff --git a/server/main-channel.c b/server/main-channel.c
index 6cd2e59..c509616 100644
--- a/server/main-channel.c
+++ b/server/main-channel.c
@@ -53,9 +53,9 @@ 
 #define NET_TEST_WARMUP_BYTES 0
 #define NET_TEST_BYTES (1024 * 250)
 
-#define PING_INTERVAL (1000 * 10)
+#define PING_INTERVAL (MS_PER_SECOND * 10)
 
-#define CLIENT_CONNECTIVITY_TIMEOUT (30*1000) // 30 seconds
+#define CLIENT_CONNECTIVITY_TIMEOUT (MS_PER_SECOND * 30)
 
 static uint8_t zero_page[ZERO_BUF_SIZE] = {0};
 
@@ -1050,7 +1050,7 @@  static void do_ping_client(MainChannelClient *mcc,
         main_channel_client_push_ping(mcc, 0);
     } else if (!strcmp(opt, "on")) {
         if (has_interval && interval > 0) {
-            mcc->ping_interval = interval * 1000;
+            mcc->ping_interval = interval * MS_PER_SECOND;
         }
         core->timer_start(mcc->ping_timer, mcc->ping_interval);
     } else if (!strcmp(opt, "off")) {
diff --git a/server/mjpeg-encoder.c b/server/mjpeg-encoder.c
index 5da498d..1e83a02 100644
--- a/server/mjpeg-encoder.c
+++ b/server/mjpeg-encoder.c
@@ -59,7 +59,7 @@  static const int mjpeg_quality_samples[MJPEG_QUALITY_SAMPLE_NUM] = {20, 30, 40,
  * avoid interrupting the playback when there are temporary
  * incidents of instability (with respect to server and client drops)
  */
-#define MJPEG_MAX_CLIENT_PLAYBACK_DELAY 5000 // 5 sec
+#define MJPEG_MAX_CLIENT_PLAYBACK_DELAY (MS_PER_SECOND * 5)
 
 /*
  * The stream starts after lossless frames were sent to the client,
@@ -663,11 +663,11 @@  static void mjpeg_encoder_adjust_fps(MJpegEncoder *encoder, uint64_t now)
 
     if (!rate_control->during_quality_eval &&
         adjusted_fps_time_passed > MJPEG_ADJUST_FPS_TIMEOUT &&
-        adjusted_fps_time_passed > 1000 / rate_control->adjusted_fps) {
+        adjusted_fps_time_passed > MS_PER_SECOND / rate_control->adjusted_fps) {
         double avg_fps;
         double fps_ratio;
 
-        avg_fps = ((double)rate_control->adjusted_fps_num_frames*1000) /
+        avg_fps = ((double)rate_control->adjusted_fps_num_frames * MS_PER_SECOND) /
                   adjusted_fps_time_passed;
         spice_debug("#frames-adjust=%"PRIu64" #adjust-time=%"PRIu64" avg-fps=%.2f",
                     rate_control->adjusted_fps_num_frames, adjusted_fps_time_passed, avg_fps);
@@ -1165,7 +1165,7 @@  static uint32_t get_min_required_playback_delay(uint64_t frame_enc_size,
     if (!frame_enc_size || !byte_rate) {
         return latency;
     }
-    one_frame_time = (frame_enc_size*1000)/byte_rate;
+    one_frame_time = (frame_enc_size * MS_PER_SECOND) / byte_rate;
 
     min_delay = MIN(one_frame_time*2 + latency, MJPEG_MAX_CLIENT_PLAYBACK_DELAY);
     return min_delay;
diff --git a/server/red-channel.c b/server/red-channel.c
index cdaa7ae..9f79c8e 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -50,8 +50,8 @@  typedef struct EmptyMsgPipeItem {
     int msg;
 } EmptyMsgPipeItem;
 
-#define PING_TEST_TIMEOUT_MS 15000
-#define PING_TEST_IDLE_NET_TIMEOUT_MS 100
+#define PING_TEST_TIMEOUT_MS (MS_PER_SECOND * 15)
+#define PING_TEST_IDLE_NET_TIMEOUT_MS (MS_PER_SECOND / 10)
 
 #define CHANNEL_BLOCKED_SLEEP_DURATION 10000 //micro
 
diff --git a/server/reds-private.h b/server/reds-private.h
index 5afde30..38ec9d6 100644
--- a/server/reds-private.h
+++ b/server/reds-private.h
@@ -20,7 +20,7 @@ 
 
 #include <spice/protocol.h>
 
-#define MIGRATE_TIMEOUT (1000 * 10) /* 10sec */
+#define MIGRATE_TIMEOUT (MS_PER_SECOND * 10)
 #define MM_TIME_DELTA 400 /*ms*/
 
 typedef struct TicketAuthentication {
diff --git a/server/stream.h b/server/stream.h
index 348a753..65bb60b 100644
--- a/server/stream.h
+++ b/server/stream.h
@@ -36,7 +36,7 @@ 
 #define RED_STREAM_CHANNEL_CAPACITY 0.8
 /* the client's stream report frequency is the minimum of the 2 values below */
 #define RED_STREAM_CLIENT_REPORT_WINDOW 5 // #frames
-#define RED_STREAM_CLIENT_REPORT_TIMEOUT 1000 // milliseconds
+#define RED_STREAM_CLIENT_REPORT_TIMEOUT MS_PER_SECOND
 #define RED_STREAM_DEFAULT_HIGH_START_BIT_RATE (10 * 1024 * 1024) // 10Mbps
 #define RED_STREAM_DEFAULT_LOW_START_BIT_RATE (2.5 * 1024 * 1024) // 2.5Mbps
 #define MAX_FPS 30
diff --git a/server/utils.h b/server/utils.h
index cf6b224..755133b 100644
--- a/server/utils.h
+++ b/server/utils.h
@@ -62,6 +62,8 @@  static inline red_time_t spice_get_monotonic_time_ns(void)
     return NS_PER_SECOND * time.tv_sec + time.tv_nsec;
 }
 
+#define MS_PER_SECOND 1000
+
 static inline red_time_t spice_get_monotonic_time_ms(void)
 {
     return g_get_monotonic_time() / 1000;

Comments

On Fri, Dec 11, 2015 at 12:22:31PM +0100, Francois Gouget wrote:
> diff --git a/server/utils.h b/server/utils.h
> index cf6b224..755133b 100644
> --- a/server/utils.h
> +++ b/server/utils.h
> @@ -62,6 +62,8 @@ static inline red_time_t spice_get_monotonic_time_ns(void)
>      return NS_PER_SECOND * time.tv_sec + time.tv_nsec;
>  }
>  
> +#define MS_PER_SECOND 1000

Same comment about naming as in the other patch, looks good to me
otherwise.

Christophe