From 29fedbf58b9c0d7641e9e42505199ed5ad295325 Mon Sep 17 00:00:00 2001 From: hui su Date: Tue, 30 Aug 2016 11:38:44 -0700 Subject: [PATCH] Anim_encoder: correctly handle enc->prev_candidate_undecided_ Set enc->prev_candidate_undecided_ as 0 when a frame is not chosen as a possible keyframe, so that the dispose method can be dispose-to-background. Change-Id: If2899f5dbc06fb53705fb8240072ab6440a6de12 --- src/mux/anim_encode.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/mux/anim_encode.c b/src/mux/anim_encode.c index aaac3821..8b65a952 100644 --- a/src/mux/anim_encode.c +++ b/src/mux/anim_encode.c @@ -1190,16 +1190,20 @@ static int CacheFrame(WebPAnimEncoder* const enc, enc->prev_candidate_undecided_ = 0; } else { int64_t curr_delta; + FrameRect prev_rect_key, prev_rect_sub; // Add this as a frame rectangle to enc. error_code = SetFrame(enc, config, 0, encoded_frame, &frame_skipped); if (error_code != VP8_ENC_OK) goto End; if (frame_skipped) goto Skip; + prev_rect_sub = enc->prev_rect_; + // Add this as a key-frame to enc, too. error_code = SetFrame(enc, config, 1, encoded_frame, &frame_skipped); if (error_code != VP8_ENC_OK) goto End; assert(frame_skipped == 0); // Key-frame cannot be an empty rectangle. + prev_rect_key = enc->prev_rect_; // Analyze size difference of the two variants. curr_delta = KeyFramePenalty(encoded_frame); @@ -1210,11 +1214,13 @@ static int CacheFrame(WebPAnimEncoder* const enc, old_keyframe->is_key_frame_ = 0; } encoded_frame->is_key_frame_ = 1; + enc->prev_candidate_undecided_ = 1; enc->keyframe_ = (int)position; enc->best_delta_ = curr_delta; enc->flush_count_ = enc->count_ - 1; // We can flush previous frames. } else { encoded_frame->is_key_frame_ = 0; + enc->prev_candidate_undecided_ = 0; } // Note: We need '>=' below because when kmin and kmax are both zero, // count_since_key_frame will always be > kmax. @@ -1224,7 +1230,10 @@ static int CacheFrame(WebPAnimEncoder* const enc, enc->keyframe_ = KEYFRAME_NONE; enc->best_delta_ = DELTA_INFINITY; } - enc->prev_candidate_undecided_ = 1; + if (!enc->prev_candidate_undecided_) { + enc->prev_rect_ = + encoded_frame->is_key_frame_ ? prev_rect_key : prev_rect_sub; + } } }