From 9a062b8ea60425f1f69303cac555a05e8aa46b3e Mon Sep 17 00:00:00 2001 From: Urvang Joshi Date: Fri, 23 Jan 2015 10:48:59 -0800 Subject: [PATCH] AnimEncoder: Bugfix for kmin = 1 and kmax = 2. SanitizeEncoderOptions() was changing kmin to 2 too, which resulted in a bad state with kmin == kmax. Change-Id: Ie7273f1949bac469e7e6c8efbc98b154caf6de0f --- src/mux/anim_encode.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/mux/anim_encode.c b/src/mux/anim_encode.c index e7b92ac7..49cd24c6 100644 --- a/src/mux/anim_encode.c +++ b/src/mux/anim_encode.c @@ -122,14 +122,17 @@ static void SanitizeEncoderOptions(WebPAnimEncoderOptions* const enc_options) { fprintf(stderr, "WARNING: Setting kmin = %d, so that kmin < kmax.\n", (int)enc_options->kmin); } - } else if (enc_options->kmin < (enc_options->kmax / 2 + 1)) { - // This ensures that enc.keyframe + kmin >= kmax is always true. So, we - // can flush all the frames in the 'count_since_key_frame == kmax' case. - enc_options->kmin = (enc_options->kmax / 2 + 1); - if (print_warning) { - fprintf(stderr, - "WARNING: Setting kmin = %d, so that kmin >= kmax / 2 + 1.\n", - (int)enc_options->kmin); + } else { + const size_t kmin_limit = enc_options->kmax / 2 + 1; + if (enc_options->kmin < kmin_limit && kmin_limit < enc_options->kmax) { + // This ensures that enc.keyframe + kmin >= kmax is always true. So, we + // can flush all the frames in the 'count_since_key_frame == kmax' case. + enc_options->kmin = kmin_limit; + if (print_warning) { + fprintf(stderr, + "WARNING: Setting kmin = %d, so that kmin >= kmax / 2 + 1.\n", + (int)enc_options->kmin); + } } } // Limit the max number of frames that are allocated. @@ -141,6 +144,7 @@ static void SanitizeEncoderOptions(WebPAnimEncoderOptions* const enc_options) { (int)enc_options->kmin, MAX_CACHED_FRAMES); } } + assert(enc_options->kmin <= enc_options->kmax); } #undef MAX_CACHED_FRAMES