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
This commit is contained in:
hui su 2016-08-30 11:38:44 -07:00
parent 85cd5d061c
commit 29fedbf58b

View File

@ -1190,16 +1190,20 @@ static int CacheFrame(WebPAnimEncoder* const enc,
enc->prev_candidate_undecided_ = 0; enc->prev_candidate_undecided_ = 0;
} else { } else {
int64_t curr_delta; int64_t curr_delta;
FrameRect prev_rect_key, prev_rect_sub;
// Add this as a frame rectangle to enc. // Add this as a frame rectangle to enc.
error_code = SetFrame(enc, config, 0, encoded_frame, &frame_skipped); error_code = SetFrame(enc, config, 0, encoded_frame, &frame_skipped);
if (error_code != VP8_ENC_OK) goto End; if (error_code != VP8_ENC_OK) goto End;
if (frame_skipped) goto Skip; if (frame_skipped) goto Skip;
prev_rect_sub = enc->prev_rect_;
// Add this as a key-frame to enc, too. // Add this as a key-frame to enc, too.
error_code = SetFrame(enc, config, 1, encoded_frame, &frame_skipped); error_code = SetFrame(enc, config, 1, encoded_frame, &frame_skipped);
if (error_code != VP8_ENC_OK) goto End; if (error_code != VP8_ENC_OK) goto End;
assert(frame_skipped == 0); // Key-frame cannot be an empty rectangle. assert(frame_skipped == 0); // Key-frame cannot be an empty rectangle.
prev_rect_key = enc->prev_rect_;
// Analyze size difference of the two variants. // Analyze size difference of the two variants.
curr_delta = KeyFramePenalty(encoded_frame); curr_delta = KeyFramePenalty(encoded_frame);
@ -1210,11 +1214,13 @@ static int CacheFrame(WebPAnimEncoder* const enc,
old_keyframe->is_key_frame_ = 0; old_keyframe->is_key_frame_ = 0;
} }
encoded_frame->is_key_frame_ = 1; encoded_frame->is_key_frame_ = 1;
enc->prev_candidate_undecided_ = 1;
enc->keyframe_ = (int)position; enc->keyframe_ = (int)position;
enc->best_delta_ = curr_delta; enc->best_delta_ = curr_delta;
enc->flush_count_ = enc->count_ - 1; // We can flush previous frames. enc->flush_count_ = enc->count_ - 1; // We can flush previous frames.
} else { } else {
encoded_frame->is_key_frame_ = 0; encoded_frame->is_key_frame_ = 0;
enc->prev_candidate_undecided_ = 0;
} }
// Note: We need '>=' below because when kmin and kmax are both zero, // Note: We need '>=' below because when kmin and kmax are both zero,
// count_since_key_frame will always be > kmax. // count_since_key_frame will always be > kmax.
@ -1224,7 +1230,10 @@ static int CacheFrame(WebPAnimEncoder* const enc,
enc->keyframe_ = KEYFRAME_NONE; enc->keyframe_ = KEYFRAME_NONE;
enc->best_delta_ = DELTA_INFINITY; 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;
}
} }
} }