Blob Blame History Raw
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jonathon Jongsma <jjongsma@redhat.com>
Date: Fri, 30 May 2014 13:45:02 -0500
Subject: [PATCH] Fix assert in mjpeg_encoder_adjust_params_to_bit_rate()

If mjpeg_encoder_reset_quality() is called with the same quality as currently
set, it will not reset last_enc_size but not reset num_recent_enc_frames,
violating some assumptions in _adjust_params_to_bit_rate(). To avoid aborting
the server, simply return early from this function.

Resolves: rhbz#1070028
(cherry picked from commit 284cca2a5ebc98257275585083321a7100fb89b3)
---
 server/mjpeg_encoder.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/server/mjpeg_encoder.c b/server/mjpeg_encoder.c
index 04b244e..223fe64 100644
--- a/server/mjpeg_encoder.c
+++ b/server/mjpeg_encoder.c
@@ -624,7 +624,10 @@ static void mjpeg_encoder_adjust_params_to_bit_rate(MJpegEncoder *encoder)
         return;
     }
 
-    spice_assert(rate_control->num_recent_enc_frames);
+    if (!rate_control->num_recent_enc_frames) {
+        spice_debug("No recent encoded frames");
+        return;
+    }
 
     if (rate_control->num_recent_enc_frames < MJPEG_AVERAGE_SIZE_WINDOW &&
         rate_control->num_recent_enc_frames < rate_control->fps) {