make -pass option work with token buffers

-pass 2 can be useful sometimes. More passes usually don't help more.
This change is a step toward being able to re-code the whole picture
with varying parameter (when token buffer is used).

Change-Id: Ia2538e2069a53c080e2ad248c18a1e04623a9304
This commit is contained in:
skal 2013-09-03 23:37:42 +02:00
parent 733a7faae4
commit cfb56b1707

View File

@ -835,7 +835,7 @@ static int PostLoopFinalize(VP8EncIterator* const it, int ok) {
} }
if (ok) { // All good. Finish up. if (ok) { // All good. Finish up.
if (enc->pic_->stats) { // finalize byte counters... if (enc->pic_->stats != NULL) { // finalize byte counters...
int i, s; int i, s;
for (i = 0; i <= 2; ++i) { for (i = 0; i <= 2; ++i) {
for (s = 0; s < NUM_MB_SEGMENTS; ++s) { for (s = 0; s < NUM_MB_SEGMENTS; ++s) {
@ -908,15 +908,14 @@ int VP8EncLoop(VP8Encoder* const enc) {
int VP8EncTokenLoop(VP8Encoder* const enc) { int VP8EncTokenLoop(VP8Encoder* const enc) {
int ok; int ok;
// Roughly refresh the proba height times per pass // Roughly refresh the proba eight times per pass
int max_count = (enc->mb_w_ * enc->mb_h_) >> 3; int max_count = (enc->mb_w_ * enc->mb_h_) >> 3;
int cnt; int num_pass_left = enc->config_->pass;
VP8EncIterator it; VP8EncIterator it;
VP8Proba* const proba = &enc->proba_; VP8Proba* const proba = &enc->proba_;
const VP8RDLevel rd_opt = enc->rd_opt_level_; const VP8RDLevel rd_opt = enc->rd_opt_level_;
if (max_count < MIN_COUNT) max_count = MIN_COUNT; if (max_count < MIN_COUNT) max_count = MIN_COUNT;
cnt = max_count;
assert(enc->num_parts_ == 1); assert(enc->num_parts_ == 1);
assert(enc->use_tokens_); assert(enc->use_tokens_);
@ -929,8 +928,13 @@ int VP8EncTokenLoop(VP8Encoder* const enc) {
ok = PreLoopInitialize(enc); ok = PreLoopInitialize(enc);
if (!ok) return 0; if (!ok) return 0;
while (ok && num_pass_left-- > 0) {
int cnt = max_count;
VP8IteratorInit(enc, &it); VP8IteratorInit(enc, &it);
VP8InitFilter(&it); if (num_pass_left == 0) {
VP8InitFilter(&it); // don't collect stats until last pass (too costly)
}
VP8TBufferClear(&enc->tokens_);
do { do {
VP8ModeScore info; VP8ModeScore info;
VP8IteratorImport(&it); VP8IteratorImport(&it);
@ -946,20 +950,20 @@ int VP8EncTokenLoop(VP8Encoder* const enc) {
VP8EncCodeLayerBlock(&it); VP8EncCodeLayerBlock(&it);
} }
#endif #endif
if (num_pass_left == 0) {
StoreSideInfo(&it); StoreSideInfo(&it);
VP8StoreFilterStats(&it); VP8StoreFilterStats(&it);
VP8IteratorExport(&it); VP8IteratorExport(&it);
ok = VP8IteratorProgress(&it, 20); ok = VP8IteratorProgress(&it, 20);
}
} while (ok && VP8IteratorNext(&it, it.yuv_out_)); } while (ok && VP8IteratorNext(&it, it.yuv_out_));
}
ok = ok && WebPReportProgress(enc->pic_, enc->percent_ + 20, &enc->percent_); ok = ok && WebPReportProgress(enc->pic_, enc->percent_ + 20, &enc->percent_);
if (ok) { if (ok) {
FinalizeTokenProbas(proba); FinalizeTokenProbas(proba);
ok = VP8EmitTokens(&enc->tokens_, enc->parts_ + 0, ok = VP8EmitTokens(&enc->tokens_, enc->parts_ + 0,
(const uint8_t*)proba->coeffs_, 1); (const uint8_t*)proba->coeffs_, 1);
} }
return PostLoopFinalize(&it, ok); return PostLoopFinalize(&it, ok);
} }