mirror of
https://gitlab.uni-freiburg.de/opensourcevdi/spice-gtk
synced 2026-02-03 03:55:15 +00:00
spice-gtk: Use time comparisons that still work after wraparound
The mm timer is a millisecond timer that wraps around after ~49 days. All comparisons that look like a<b will fail once this happens. Instead, use signed ((int)(a-b)<0), which may fail if there is more than 25 days between a and b (should not be happening under normal conditions), but is robust to the timer wrapping around. Signed-off-by: Christophe de Dinechin <dinechin@redhat.com> Acked-by: Christophe Fergeau <cfergeau@redhat.com>
This commit is contained in:
parent
dbe27cb7f9
commit
0bedcab1fc
@ -166,7 +166,7 @@ static void schedule_frame(SpiceGstDecoder *decoder)
|
||||
break;
|
||||
}
|
||||
|
||||
if (now < gstframe->frame->mm_time) {
|
||||
if (spice_mmtime_diff(now, gstframe->frame->mm_time) < 0) {
|
||||
decoder->timer_id = g_timeout_add(gstframe->frame->mm_time - now,
|
||||
display_frame, decoder);
|
||||
} else if (g_queue_get_length(decoder->display_queue) == 1) {
|
||||
@ -511,7 +511,7 @@ static gboolean spice_gst_decoder_queue_frame(VideoDecoder *video_decoder,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (frame->mm_time < decoder->last_mm_time) {
|
||||
if (spice_mmtime_diff(frame->mm_time, decoder->last_mm_time) < 0) {
|
||||
SPICE_DEBUG("new-frame-time < last-frame-time (%u < %u):"
|
||||
" resetting stream",
|
||||
frame->mm_time, decoder->last_mm_time);
|
||||
|
||||
@ -201,7 +201,7 @@ static void mjpeg_decoder_schedule(MJpegDecoder *decoder)
|
||||
decoder->cur_frame = NULL;
|
||||
do {
|
||||
if (frame) {
|
||||
if (time <= frame->mm_time) {
|
||||
if (spice_mmtime_diff(time, frame->mm_time) <= 0) {
|
||||
guint32 d = frame->mm_time - time;
|
||||
decoder->cur_frame = frame;
|
||||
decoder->timer_id = g_timeout_add(d, mjpeg_decoder_decode_frame, decoder);
|
||||
@ -251,7 +251,7 @@ static gboolean mjpeg_decoder_queue_frame(VideoDecoder *video_decoder,
|
||||
|
||||
last_frame = g_queue_peek_tail(decoder->msgq);
|
||||
if (last_frame) {
|
||||
if (frame->mm_time < last_frame->mm_time) {
|
||||
if (spice_mmtime_diff(frame->mm_time, last_frame->mm_time) < 0) {
|
||||
/* This should really not happen */
|
||||
SPICE_DEBUG("new-frame-time < last-frame-time (%u < %u):"
|
||||
" resetting stream",
|
||||
|
||||
@ -1366,7 +1366,7 @@ static void display_update_stream_report(SpiceDisplayChannel *channel, uint32_t
|
||||
}
|
||||
|
||||
if (st->report_num_frames >= st->report_max_window ||
|
||||
now - st->report_start_time >= st->report_timeout ||
|
||||
spice_mmtime_diff(now - st->report_start_time, st->report_timeout) >= 0 ||
|
||||
st->report_drops_seq_len >= STREAM_REPORT_DROP_SEQ_LEN_LIMIT) {
|
||||
SpiceMsgcDisplayStreamReport report;
|
||||
SpiceSession *session = spice_channel_get_session(SPICE_CHANNEL(channel));
|
||||
|
||||
@ -313,7 +313,7 @@ static void playback_handle_data(SpiceChannel *channel, SpiceMsgIn *in)
|
||||
packet->time, packet->data, packet->data_size);
|
||||
#endif
|
||||
|
||||
if (c->last_time > packet->time)
|
||||
if (spice_mmtime_diff(c->last_time, packet->time) > 0)
|
||||
g_warn_if_reached();
|
||||
|
||||
c->last_time = packet->time;
|
||||
|
||||
@ -43,6 +43,8 @@ G_BEGIN_DECLS
|
||||
#define CHANNEL_DEBUG(channel, fmt, ...) \
|
||||
SPICE_DEBUG("%s: " fmt, SPICE_CHANNEL(channel)->priv->name, ## __VA_ARGS__)
|
||||
|
||||
#define spice_mmtime_diff(t1, t2) ((int32_t) ((t1)-(t2)))
|
||||
|
||||
struct _SpiceMsgOut {
|
||||
int refcount;
|
||||
SpiceChannel *channel;
|
||||
|
||||
@ -2336,8 +2336,8 @@ void spice_session_set_mm_time(SpiceSession *session, guint32 time)
|
||||
s->mm_time = time;
|
||||
s->mm_time_at_clock = g_get_monotonic_time();
|
||||
SPICE_DEBUG("set mm time: %u", spice_session_get_mm_time(session));
|
||||
if (time > old_time + MM_TIME_DIFF_RESET_THRESH ||
|
||||
time < old_time) {
|
||||
if (spice_mmtime_diff(time, old_time + MM_TIME_DIFF_RESET_THRESH) > 0 ||
|
||||
spice_mmtime_diff(time, old_time) < 0) {
|
||||
SPICE_DEBUG("%s: mm-time-reset, old %u, new %u", __FUNCTION__, old_time, s->mm_time);
|
||||
g_coroutine_signal_emit(session, signals[SPICE_SESSION_MM_TIME_RESET], 0);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user