[Spice-commits] 2 commits - server/dcc.h server/inputs-channel.c server/main-channel.c server/mjpeg-encoder.c server/red-channel.c server/reds-private.h server/red-worker.c server/red-worker.h server/stream.c server/stream.h server/utils.h

Frediano Ziglio fziglio at kemper.freedesktop.org
Mon Dec 14 03:26:51 PST 2015


 server/dcc.h            |    2 +-
 server/inputs-channel.c |    3 ++-
 server/main-channel.c   |    6 +++---
 server/mjpeg-encoder.c  |   18 +++++++++---------
 server/red-channel.c    |   12 +++++-------
 server/red-worker.c     |    2 +-
 server/red-worker.h     |    2 +-
 server/reds-private.h   |    2 +-
 server/stream.c         |    4 ++--
 server/stream.h         |   10 +++++-----
 server/utils.h          |    7 ++++++-
 11 files changed, 36 insertions(+), 32 deletions(-)

New commits:
commit 8bddb1444e34e7de85bf6e7832814c211c5f94e4
Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Mon Dec 14 11:24:05 2015 +0000

    server: Add time constants to go with spice_get_monotonic_time_ms()
    
    They clarify the time unit being used and simplify calculations.
    
    Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/inputs-channel.c b/server/inputs-channel.c
index 74aa30d..ba97f0f 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 (MSEC_PER_SEC * 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..eb894b0 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 (MSEC_PER_SEC * 10)
 
-#define CLIENT_CONNECTIVITY_TIMEOUT (30*1000) // 30 seconds
+#define CLIENT_CONNECTIVITY_TIMEOUT (MSEC_PER_SEC * 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 * MSEC_PER_SEC;
         }
         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 2a040f5..3bd1a04 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 (MSEC_PER_SEC * 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 > MSEC_PER_SEC / 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 * MSEC_PER_SEC) /
                   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 * MSEC_PER_SEC) / 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 f10810e..ba906c6 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 (MSEC_PER_SEC * 15)
+#define PING_TEST_IDLE_NET_TIMEOUT_MS (MSEC_PER_SEC / 10)
 
 #define CHANNEL_BLOCKED_SLEEP_DURATION 10000 //micro
 
diff --git a/server/reds-private.h b/server/reds-private.h
index 5afde30..2df4ca4 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 (MSEC_PER_SEC * 10)
 #define MM_TIME_DELTA 400 /*ms*/
 
 typedef struct TicketAuthentication {
diff --git a/server/stream.h b/server/stream.h
index 7b63402..a3e84ed 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 MSEC_PER_SEC
 #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 b85b104..00631f8 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 NSEC_PER_SEC * time.tv_sec + time.tv_nsec;
 }
 
+#define MSEC_PER_SEC 1000
+
 static inline red_time_t spice_get_monotonic_time_ms(void)
 {
     return g_get_monotonic_time() / 1000;
commit 5c9fb9a0f3be945e19f4cdeb86a7732ae218888c
Author: Francois Gouget <fgouget at codeweavers.com>
Date:   Mon Dec 14 11:23:33 2015 +0000

    server: Add time constants to go with spice_get_monotonic_time_ns()
    
    They clarify the time unit being used, reduce the need for casts and
    simplify calculations.
    
    Signed-off-by: Francois Gouget <fgouget at codeweavers.com>
    Acked-by: Christophe Fergeau <cfergeau at redhat.com>

diff --git a/server/dcc.h b/server/dcc.h
index 9d88b90..2a12226 100644
--- a/server/dcc.h
+++ b/server/dcc.h
@@ -31,7 +31,7 @@
 #define PALETTE_CACHE_HASH_KEY(id) ((id) & PALETTE_CACHE_HASH_MASK)
 #define CLIENT_PALETTE_CACHE_SIZE 128
 
-#define DISPLAY_CLIENT_MIGRATE_DATA_TIMEOUT 10000000000ULL //nano, 10 sec
+#define DISPLAY_CLIENT_MIGRATE_DATA_TIMEOUT (NSEC_PER_SEC * 10)
 #define DISPLAY_CLIENT_RETRY_INTERVAL 10000 //micro
 
 /* Each drawable can refer to at most 3 images: src, brush and mask */
diff --git a/server/mjpeg-encoder.c b/server/mjpeg-encoder.c
index 9c51f7b..2a040f5 100644
--- a/server/mjpeg-encoder.c
+++ b/server/mjpeg-encoder.c
@@ -68,7 +68,7 @@ static const int mjpeg_quality_samples[MJPEG_QUALITY_SAMPLE_NUM] = {20, 30, 40,
  * are not necessarily related to mis-estimation of the bit rate, and we would
  * like to wait till the stream stabilizes.
  */
-#define MJPEG_WARMUP_TIME 3000000000LL // 3 sec
+#define MJPEG_WARMUP_TIME (NSEC_PER_SEC * 3)
 
 enum {
     MJPEG_QUALITY_EVAL_TYPE_SET,
@@ -659,7 +659,7 @@ static void mjpeg_encoder_adjust_fps(MJpegEncoder *encoder, uint64_t now)
 
     spice_assert(rate_control_is_active(encoder));
 
-    adjusted_fps_time_passed = (now - rate_control->adjusted_fps_start_time) / 1000 / 1000;
+    adjusted_fps_time_passed = (now - rate_control->adjusted_fps_start_time) / NSEC_PER_MILLISEC;
 
     if (!rate_control->during_quality_eval &&
         adjusted_fps_time_passed > MJPEG_ADJUST_FPS_TIMEOUT &&
@@ -724,7 +724,7 @@ static int mjpeg_encoder_start_frame(MJpegEncoder *encoder,
         mjpeg_encoder_adjust_fps(encoder, now);
         interval = (now - rate_control->bit_rate_info.last_frame_time);
 
-        if (interval < (1000*1000*1000) / rate_control->adjusted_fps) {
+        if (interval < NSEC_PER_SEC / rate_control->adjusted_fps) {
             return MJPEG_ENCODER_FRAME_DROP;
         }
 
@@ -1009,7 +1009,7 @@ static void mjpeg_encoder_decrease_bit_rate(MJpegEncoder *encoder)
         double duration_sec;
 
         duration_sec = (bit_rate_info->last_frame_time - bit_rate_info->change_start_time);
-        duration_sec /= (1000.0 * 1000.0 * 1000.0);
+        duration_sec /= NSEC_PER_SEC;
         measured_byte_rate = bit_rate_info->sum_enc_size / duration_sec;
         measured_fps = bit_rate_info->num_enc_frames / duration_sec;
         decrease_size = bit_rate_info->sum_enc_size / bit_rate_info->num_enc_frames;
@@ -1078,7 +1078,7 @@ static void mjpeg_encoder_increase_bit_rate(MJpegEncoder *encoder)
         double duration_sec;
 
         duration_sec = (bit_rate_info->last_frame_time - bit_rate_info->change_start_time);
-        duration_sec /= (1000.0 * 1000.0 * 1000.0);
+        duration_sec /= NSEC_PER_SEC;
         measured_byte_rate = bit_rate_info->sum_enc_size / duration_sec;
         measured_fps = bit_rate_info->num_enc_frames / duration_sec;
         avg_frame_size = bit_rate_info->sum_enc_size / bit_rate_info->num_enc_frames;
diff --git a/server/red-channel.c b/server/red-channel.c
index 361f1a5..f10810e 100644
--- a/server/red-channel.c
+++ b/server/red-channel.c
@@ -1370,7 +1370,7 @@ int red_channel_client_get_roundtrip_ms(RedChannelClient *rcc)
     if (rcc->latency_monitor.roundtrip < 0) {
         return rcc->latency_monitor.roundtrip;
     }
-    return rcc->latency_monitor.roundtrip / 1000 / 1000;
+    return rcc->latency_monitor.roundtrip / NSEC_PER_MILLISEC;
 }
 
 static void red_channel_client_init_outgoing_messages_window(RedChannelClient *rcc)
@@ -1432,9 +1432,7 @@ static void red_channel_client_restart_ping_timer(RedChannelClient *rcc)
 {
     uint64_t passed, timeout;
 
-    passed = spice_get_monotonic_time_ns();
-    passed = passed - rcc->latency_monitor.last_pong_time;
-    passed /= 1000*1000;
+    passed = (spice_get_monotonic_time_ns() - rcc->latency_monitor.last_pong_time) / NSEC_PER_MILLISEC;
     timeout = PING_TEST_IDLE_NET_TIMEOUT_MS;
     if (passed  < PING_TEST_TIMEOUT_MS) {
         timeout += PING_TEST_TIMEOUT_MS - passed;
@@ -1511,7 +1509,7 @@ static void red_channel_client_handle_pong(RedChannelClient *rcc, SpiceMsgPing *
     if (rcc->latency_monitor.roundtrip < 0 ||
         now - ping->timestamp < rcc->latency_monitor.roundtrip) {
         rcc->latency_monitor.roundtrip = now - ping->timestamp;
-        spice_debug("update roundtrip %.2f(ms)", rcc->latency_monitor.roundtrip/1000.0/1000.0);
+        spice_debug("update roundtrip %.2f(ms)", ((double)rcc->latency_monitor.roundtrip)/NSEC_PER_MILLISEC);
     }
 
     rcc->latency_monitor.last_pong_time = now;
diff --git a/server/red-worker.c b/server/red-worker.c
index f0de17e..dfaf4ba 100644
--- a/server/red-worker.c
+++ b/server/red-worker.c
@@ -330,7 +330,7 @@ static int red_process_display(RedWorker *worker, uint32_t max_pipe_size, int *r
         n++;
         if ((worker->display_channel &&
              red_channel_all_blocked(&worker->display_channel->common.base))
-            || spice_get_monotonic_time_ns() - start > 10 * 1000 * 1000) {
+            || spice_get_monotonic_time_ns() - start > NSEC_PER_SEC / 100) {
             worker->event_timeout = 0;
             return n;
         }
diff --git a/server/red-worker.h b/server/red-worker.h
index e6ad8cf..1f0cd99 100644
--- a/server/red-worker.h
+++ b/server/red-worker.h
@@ -33,7 +33,7 @@ typedef struct CommonChannelClient {
 } CommonChannelClient;
 
 #define COMMON_CHANNEL_CLIENT(Client) ((CommonChannelClient*)(Client))
-#define COMMON_CLIENT_TIMEOUT 30000000000ULL //nano
+#define COMMON_CLIENT_TIMEOUT (NSEC_PER_SEC * 30)
 
 #define CHANNEL_RECEIVE_BUF_SIZE 1024
 typedef struct CommonChannel {
diff --git a/server/stream.c b/server/stream.c
index ae70296..811f7d3 100644
--- a/server/stream.c
+++ b/server/stream.c
@@ -430,8 +430,8 @@ static void display_channel_create_stream(DisplayChannel *display, Drawable *dra
      * the nearest integer, for instance 24 for 23.976.
      */
     uint64_t duration = drawable->creation_time - drawable->first_frame_time;
-    if (duration > (uint64_t)drawable->frames_count * 1000 * 1000 * 1000 / MAX_FPS) {
-        stream->input_fps = ((uint64_t)drawable->frames_count * 1000 * 1000 * 1000 + duration / 2) / duration;
+    if (duration > NSEC_PER_SEC * drawable->frames_count / MAX_FPS) {
+        stream->input_fps = (NSEC_PER_SEC * drawable->frames_count + duration / 2) / duration;
     } else {
         stream->input_fps = MAX_FPS;
     }
diff --git a/server/stream.h b/server/stream.h
index e20c8de..7b63402 100644
--- a/server/stream.h
+++ b/server/stream.h
@@ -25,14 +25,14 @@
 #include "red-channel.h"
 #include "image-cache.h"
 
-#define RED_STREAM_DETACTION_MAX_DELTA ((1000 * 1000 * 1000) / 5) // 1/5 sec
-#define RED_STREAM_CONTINUS_MAX_DELTA (1000 * 1000 * 1000)
-#define RED_STREAM_TIMEOUT (1000 * 1000 * 1000)
+#define RED_STREAM_DETACTION_MAX_DELTA (NSEC_PER_SEC / 5)
+#define RED_STREAM_CONTINUS_MAX_DELTA NSEC_PER_SEC
+#define RED_STREAM_TIMEOUT NSEC_PER_SEC
 #define RED_STREAM_FRAMES_START_CONDITION 20
 #define RED_STREAM_GRADUAL_FRAMES_START_CONDITION 0.2
 #define RED_STREAM_FRAMES_RESET_CONDITION 100
 #define RED_STREAM_MIN_SIZE (96 * 96)
-#define RED_STREAM_INPUT_FPS_TIMEOUT ((uint64_t)5 * 1000 * 1000 * 1000) // 5 sec
+#define RED_STREAM_INPUT_FPS_TIMEOUT (NSEC_PER_SEC * 5)
 #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
diff --git a/server/utils.h b/server/utils.h
index 3aa5be0..b85b104 100644
--- a/server/utils.h
+++ b/server/utils.h
@@ -50,13 +50,16 @@ static inline int test_bit(int index, uint32_t val)
 
 typedef int64_t red_time_t;
 
+#define NSEC_PER_SEC      1000000000LL
+#define NSEC_PER_MILLISEC 1000000LL
+
 /* FIXME: consider g_get_monotonic_time (), but in microseconds */
 static inline red_time_t spice_get_monotonic_time_ns(void)
 {
     struct timespec time;
 
     clock_gettime(CLOCK_MONOTONIC, &time);
-    return (red_time_t) time.tv_sec * (1000 * 1000 * 1000) + time.tv_nsec;
+    return NSEC_PER_SEC * time.tv_sec + time.tv_nsec;
 }
 
 static inline red_time_t spice_get_monotonic_time_ms(void)


More information about the Spice-commits mailing list