From 1f7b8595aef1c7cc161f052a8cfb0a5a258ad888 Mon Sep 17 00:00:00 2001 From: Pascal Massimino Date: Wed, 25 Jan 2012 08:31:20 -0800 Subject: [PATCH] re-organize the error-handling in the main loop a bit Change-Id: Id74298131df9c33a86b989e15c11ffb6d04960d8 --- src/enc/frame.c | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/enc/frame.c b/src/enc/frame.c index 27fd8bec..3c7b09d6 100644 --- a/src/enc/frame.c +++ b/src/enc/frame.c @@ -801,26 +801,27 @@ int VP8EncLoop(VP8Encoder* const enc) { ok = VP8IteratorProgress(&it, 20); } while (ok && VP8IteratorNext(&it, it.yuv_out_)); - if (ok) { - VP8AdjustFilterStrength(&it); - } - - // Finalize the partitions - for (p = 0; p < enc->num_parts_; ++p) { - VP8BitWriterFinish(enc->parts_ + p); - ok &= !enc->parts_[p].error_; - } - // and byte counters - if (enc->pic_->stats) { - for (i = 0; i <= 2; ++i) { - for (s = 0; s < NUM_MB_SEGMENTS; ++s) { - enc->residual_bytes_[i][s] = (int)((it.bit_count_[s][i] + 7) >> 3); - } + if (ok) { // Finalize the partitions, check for extra errors. + for (p = 0; p < enc->num_parts_; ++p) { + VP8BitWriterFinish(enc->parts_ + p); + ok &= !enc->parts_[p].error_; } } - if (!ok) { // need to do some memory cleanup + + if (ok) { // All good. Finish up. + if (enc->pic_->stats) { // finalize byte counters... + for (i = 0; i <= 2; ++i) { + for (s = 0; s < NUM_MB_SEGMENTS; ++s) { + enc->residual_bytes_[i][s] = (int)((it.bit_count_[s][i] + 7) >> 3); + } + } + } + VP8AdjustFilterStrength(&it); // ...and store filter stats. + } else { + // Something bad happened -> need to do some memory cleanup. VP8EncFreeBitWriters(enc); } + return ok; }