Cleanup av1_get_compressed_data()
In preparation for moving much of av1_get_compressed_data() to
av1_encode_strategy() I am performing refactoring and trying to reduce
its length.
* Move buf_8bit_valid clearing to assign_cur_frame_new_fb()
* Move aom_clear_system_state() to adjust_frame_rate() where it is
required
* Make the fact that show_existing_frame only works in pass2 explicit
* Clear cm->show_existing_frame if show_existing_frame is disallowed
* Combine redundant *size = 0;
This forms part of wider restructuring and refactoring in order to
achieve a clean API separation at the entry to the low-level encoder.
BUG=aomedia:2244
Change-Id: Id53edda8f945b2d5f19c4df1f4c9e101579b2522
diff --git a/av1/common/onyxc_int.h b/av1/common/onyxc_int.h
index acdb9ad..f6e6259 100644
--- a/av1/common/onyxc_int.h
+++ b/av1/common/onyxc_int.h
@@ -642,6 +642,7 @@
if (new_fb_idx == INVALID_IDX) return NULL;
cm->cur_frame = &cm->buffer_pool->frame_bufs[new_fb_idx];
+ cm->cur_frame->buf.buf_8bit_valid = 0;
return cm->cur_frame;
}
diff --git a/av1/encoder/encoder.c b/av1/encoder/encoder.c
index 2c1e098..eeb6a6a 100644
--- a/av1/encoder/encoder.c
+++ b/av1/encoder/encoder.c
@@ -5817,6 +5817,9 @@
int64_t this_duration;
int step = 0;
+ // Clear down mmx registers
+ aom_clear_system_state();
+
if (source->ts_start == cpi->first_time_stamp_ever) {
this_duration = source->ts_end - source->ts_start;
step = 1;
@@ -6793,6 +6796,7 @@
#endif
cm->showable_frame = 0;
+ *size = 0;
aom_usec_timer_start(&cmptimer);
set_high_precision_mv(cpi, ALTREF_HIGH_PRECISION_MV, 0);
@@ -6811,15 +6815,13 @@
cpi->no_show_kf = 0;
cm->reset_decoder_state = 0;
- if (oxcf->pass == 2 && cm->show_existing_frame && allow_show_existing(cpi)) {
+ cm->show_existing_frame &= allow_show_existing(cpi);
+ if (cm->show_existing_frame) {
// Manage the source buffer and flush out the source frame that has been
// coded already; Also get prepared for PSNR calculation if needed.
struct lookahead_entry *const source =
av1_lookahead_pop(cpi->lookahead, flush);
- if (source == NULL) {
- *size = 0;
- return -1;
- }
+ if (source == NULL) return -1;
av1_apply_encoding_flags(cpi, source->flags);
cpi->source = &source->img;
// TODO(zoeliu): To track down to determine whether it's needed to adjust
@@ -6832,12 +6834,6 @@
if (assign_cur_frame_new_fb(cm) == NULL) return -1;
- // Clear down mmx registers
- aom_clear_system_state();
-
- // Start with a 0 size frame.
- *size = 0;
-
// We need to update the gf_group for show_existing overlay frame
if (cpi->rc.is_src_frame_alt_ref) av1_rc_get_second_pass_params(cpi);
@@ -6850,9 +6846,6 @@
compute_internal_stats(cpi, (int)(*size));
#endif // CONFIG_INTERNAL_STATS
- // Clear down mmx registers
- aom_clear_system_state();
-
cm->show_existing_frame = 0;
return 0;
}
@@ -6862,9 +6855,7 @@
struct lookahead_entry *const source =
choose_frame_source(cpi, &temporal_filtered, &flush, &last_source);
- if (source == NULL) {
- // If no source has been found, we can't encode a frame.
- *size = 0;
+ if (source == NULL) { // If no source was found, we can't encode a frame.
if (flush && oxcf->pass == 1 && !cpi->twopass.first_pass_done) {
av1_end_first_pass(cpi); /* get last stats packet */
cpi->twopass.first_pass_done = 1;
@@ -6891,9 +6882,6 @@
cpi->last_end_time_stamp_seen = source->ts_start;
}
- // Clear down mmx registers
- aom_clear_system_state();
-
// adjust frame rates based on timestamps given
if (cm->show_frame) adjust_frame_rate(cpi, source);
@@ -6903,8 +6891,6 @@
cm->cur_frame->frame_rf_level =
cpi->twopass.gf_group.rf_level[cpi->twopass.gf_group.index];
- cm->cur_frame->buf.buf_8bit_valid = 0;
-
if (cpi->film_grain_table) {
cm->seq_params.film_grain_params_present = aom_film_grain_table_lookup(
cpi->film_grain_table, *time_stamp, *time_end, 0 /* =erase */,
@@ -6918,9 +6904,6 @@
if (pts64 < 0 || pts64 > UINT32_MAX) return AOM_CODEC_ERROR;
cpi->common.frame_presentation_time = (uint32_t)pts64;
- // Start with a 0 size frame.
- *size = 0;
-
cpi->frame_flags = *frame_flags;
if (oxcf->pass == 2) {