<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 17 Jul 2017, at 13:49, Christophe Fergeau <<a href="mailto:cfergeau@redhat.com" class="">cfergeau@redhat.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">On Mon, Jul 17, 2017 at 11:44:04AM +0200, Christophe de Dinechin wrote:</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">From: Christophe de Dinechin <<a href="mailto:dinechin@redhat.com" class="">dinechin@redhat.com</a>><br class=""><br class="">The mm timer is a millisecond timer that wraps around after ~49 days.<br class="">All comparisons that look like a<b will fail once this happens.<br class="">Instead, use signed ((int)(a-b)<0), which may fail if there is more than<br class="">25 days between a and b (should not be happening under normal conditions),<br class="">but is robust to the timer wrapping around.<br class=""><br class="">Signed-off-by: Christophe de Dinechin <<a href="mailto:dinechin@redhat.com" class="">dinechin@redhat.com</a>><br class="">---<br class="">src/channel-display-gst.c | 4 ++--<br class="">src/channel-display-mjpeg.c | 4 ++--<br class="">src/channel-display.c | 2 +-<br class="">src/channel-playback.c | 2 +-<br class="">src/spice-channel-priv.h | 2 ++<br class="">src/spice-session.c | 4 ++--<br class="">6 files changed, 10 insertions(+), 8 deletions(-)<br class=""><br class="">diff --git a/src/channel-display-gst.c b/src/channel-display-gst.c<br class="">index adcd6ef..3f51361 100644<br class="">--- a/src/channel-display-gst.c<br class="">+++ b/src/channel-display-gst.c<br class="">@@ -166,7 +166,7 @@ static void schedule_frame(SpiceGstDecoder *decoder)<br class=""> break;<br class=""> }<br class=""><br class="">- if (now < gstframe->frame->mm_time) {<br class="">+ if (spice_mmtime_diff(now, gstframe->frame->mm_time) < 0) {<br class=""> decoder->timer_id = g_timeout_add(gstframe->frame->mm_time - now,<br class=""> display_frame, decoder);<br class=""> } else if (g_queue_get_length(decoder->display_queue) == 1) {<br class="">@@ -511,7 +511,7 @@ static gboolean spice_gst_decoder_queue_frame(VideoDecoder *video_decoder,<br class=""> return TRUE;<br class=""> }<br class=""><br class="">- if (frame->mm_time < decoder->last_mm_time) {<br class="">+ if (spice_mmtime_diff(frame->mm_time, decoder->last_mm_time) < 0) {<br class=""> SPICE_DEBUG("new-frame-time < last-frame-time (%u < %u):"<br class=""> " resetting stream",<br class=""> frame->mm_time, decoder->last_mm_time);<br class="">diff --git a/src/channel-display-mjpeg.c b/src/channel-display-mjpeg.c<br class="">index ee33b01..3ba098c 100644<br class="">--- a/src/channel-display-mjpeg.c<br class="">+++ b/src/channel-display-mjpeg.c<br class="">@@ -201,7 +201,7 @@ static void mjpeg_decoder_schedule(MJpegDecoder *decoder)<br class=""> decoder->cur_frame = NULL;<br class=""> do {<br class=""> if (frame) {<br class="">- if (time <= frame->mm_time) {<br class="">+ if (spice_mmtime_diff(time, frame->mm_time) <= 0) {<br class=""> guint32 d = frame->mm_time - time;<br class=""> decoder->cur_frame = frame;<br class=""> decoder->timer_id = g_timeout_add(d, mjpeg_decoder_decode_frame, decoder);<br class="">@@ -251,7 +251,7 @@ static gboolean mjpeg_decoder_queue_frame(VideoDecoder *video_decoder,<br class=""><br class=""> last_frame = g_queue_peek_tail(decoder->msgq);<br class=""> if (last_frame) {<br class="">- if (frame->mm_time < last_frame->mm_time) {<br class="">+ if (spice_mmtime_diff(frame->mm_time, last_frame->mm_time) < 0) {<br class=""> /* This should really not happen */<br class=""> SPICE_DEBUG("new-frame-time < last-frame-time (%u < %u):"<br class=""> " resetting stream",<br class="">diff --git a/src/channel-display.c b/src/channel-display.c<br class="">index 3c98d79..06ed18a 100644<br class="">--- a/src/channel-display.c<br class="">+++ b/src/channel-display.c<br class="">@@ -1366,7 +1366,7 @@ static void display_update_stream_report(SpiceDisplayChannel *channel, uint32_t<br class=""> }<br class=""><br class=""> if (st->report_num_frames >= st->report_max_window ||<br class="">- now - st->report_start_time >= st->report_timeout ||<br class="">+ spice_mmtime_diff(now - st->report_start_time, st->report_timeout) >= 0 ||<br class=""> st->report_drops_seq_len >= STREAM_REPORT_DROP_SEQ_LEN_LIMIT) {<br class=""> SpiceMsgcDisplayStreamReport report;<br class=""> SpiceSession *session = spice_channel_get_session(SPICE_CHANNEL(channel));<br class="">diff --git a/src/channel-playback.c b/src/channel-playback.c<br class="">index ca14b96..afc9059 100644<br class="">--- a/src/channel-playback.c<br class="">+++ b/src/channel-playback.c<br class="">@@ -313,7 +313,7 @@ static void playback_handle_data(SpiceChannel *channel, SpiceMsgIn *in)<br class=""> packet->time, packet->data, packet->data_size);<br class="">#endif<br class=""><br class="">- if (c->last_time > packet->time)<br class="">+ if (spice_mmtime_diff(c->last_time, packet->time) > 0)<br class=""> g_warn_if_reached();<br class=""><br class=""> c->last_time = packet->time;<br class="">diff --git a/src/spice-channel-priv.h b/src/spice-channel-priv.h<br class="">index 7288920..20d3495 100644<br class="">--- a/src/spice-channel-priv.h<br class="">+++ b/src/spice-channel-priv.h<br class="">@@ -43,6 +43,8 @@ G_BEGIN_DECLS<br class="">#define CHANNEL_DEBUG(channel, fmt, ...) \<br class=""> SPICE_DEBUG("%s: " fmt, SPICE_CHANNEL(channel)->priv->name, ## __VA_ARGS__)<br class=""><br class="">+#define spice_mmtime_diff(now, time) ((int32_t) ((now)-(time)))<br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Nit: I think the 'now' and 'time' naming here could be misleading, what</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">about just "mmtime0" and "mmtime1" for example?</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div class=""><br class=""></div><div class="">Well, that was to match the typical usage where ‘now’ would be the current time, and ‘time’ would be some other reference time. To me, that’s more readable that way. But YMMV…</div><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Acked-by: Christophe Fergeau <</span><a href="mailto:cfergeau@redhat.com" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px;" class="">cfergeau@redhat.com</a><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">></span></div></blockquote></div><br class=""></div></body></html>