Use sub-frame statistics for adaptive scan order update
Skip the last SB row counting for per frame adaptive scan order.
This allows enough time window for HW decoder to process the
scan order update for next frame decoding.
Change-Id: I8a3b48fe452c68c921d55dc76cc787f0a8e00e29
diff --git a/av1/common/scan.c b/av1/common/scan.c
index 7f33a18..9a32bb5 100644
--- a/av1/common/scan.c
+++ b/av1/common/scan.c
@@ -5505,9 +5505,16 @@
}
}
-void av1_update_scan_count_facade(AV1_COMMON *cm, FRAME_COUNTS *counts,
- TX_SIZE tx_size, TX_TYPE tx_type,
- const tran_low_t *dqcoeffs, int max_scan) {
+void av1_update_scan_count_facade(AV1_COMMON *cm, int mi_row,
+ FRAME_COUNTS *counts, TX_SIZE tx_size,
+ TX_TYPE tx_type, const tran_low_t *dqcoeffs,
+ int max_scan) {
+#if SUB_FRAME_COUNT
+ if (((mi_row >> 5) << 5) + 32 >= cm->mi_rows) return;
+#else
+ (void)mi_row;
+#endif
+
if (cm->use_adapt_scan && do_adapt_scan(tx_size, tx_type) && max_scan) {
#if SUB_REGION_COUNT
if (counts->txb_count[tx_size][tx_type] >= UINT8_MAX) return;
diff --git a/av1/common/scan.h b/av1/common/scan.h
index d9a5255..0ee68f8 100644
--- a/av1/common/scan.h
+++ b/av1/common/scan.h
@@ -34,11 +34,13 @@
#define CACHE_SCAN_PROB 0
#define REDUCED_SET 1
#define SUB_REGION_COUNT 1
+#define SUB_FRAME_COUNT 1
#define USE_TOPOLOGICAL_SORT 0
#define USE_LIMIT_SCAN_DISTANCE 0
-void av1_update_scan_count_facade(AV1_COMMON *cm, FRAME_COUNTS *counts,
- TX_SIZE tx_size, TX_TYPE tx_type,
- const tran_low_t *dqcoeffs, int max_scan);
+void av1_update_scan_count_facade(AV1_COMMON *cm, int mi_row,
+ FRAME_COUNTS *counts, TX_SIZE tx_size,
+ TX_TYPE tx_type, const tran_low_t *dqcoeffs,
+ int max_scan);
// embed r + c and coeff_idx info with nonzero probabilities. When sorting the
// nonzero probabilities, if there is a tie, the coefficient with smaller r + c
diff --git a/av1/decoder/decodetxb.c b/av1/decoder/decodetxb.c
index 398d085..d154ff7 100644
--- a/av1/decoder/decodetxb.c
+++ b/av1/decoder/decodetxb.c
@@ -406,9 +406,11 @@
#if CONFIG_ADAPT_SCAN
PLANE_TYPE plane_type = get_plane_type(plane);
TX_TYPE tx_type = av1_get_tx_type(plane_type, xd, row, col, block, tx_size);
+ const int mi_row = -xd->mb_to_top_edge >> (3 + MI_SIZE_LOG2);
+
if (xd->counts && *eob > 0)
- av1_update_scan_count_facade(cm, xd->counts, tx_size, tx_type, pd->dqcoeff,
- *eob);
+ av1_update_scan_count_facade(cm, mi_row, xd->counts, tx_size, tx_type,
+ pd->dqcoeff, *eob);
#endif
av1_set_contexts(xd, pd, plane, tx_size, cul_level, col, row);
return cul_level;
diff --git a/av1/decoder/detokenize.c b/av1/decoder/detokenize.c
index 92e54e4..4b24e13 100644
--- a/av1/decoder/detokenize.c
+++ b/av1/decoder/detokenize.c
@@ -372,9 +372,11 @@
ctx, sc->scan, sc->neighbors, max_scan_line, r);
av1_set_contexts(xd, pd, plane, tx_size, eob > 0, x, y);
#if CONFIG_ADAPT_SCAN
+ const int mi_row = -xd->mb_to_top_edge >> (3 + MI_SIZE_LOG2);
+
if (xd->counts)
- av1_update_scan_count_facade(cm, xd->counts, tx_size, tx_type, pd->dqcoeff,
- eob);
+ av1_update_scan_count_facade(cm, mi_row, xd->counts, tx_size, tx_type,
+ pd->dqcoeff, eob);
#else
(void)cm;
#endif
diff --git a/av1/encoder/encodetxb.c b/av1/encoder/encodetxb.c
index e0d25bd..cbdc9f6 100644
--- a/av1/encoder/encodetxb.c
+++ b/av1/encoder/encodetxb.c
@@ -2402,8 +2402,9 @@
// av1_update_scan_count_facade(). The update behavior should be the same
// because av1_update_scan_count_facade() only cares if coefficients are zero
// or not.
- av1_update_scan_count_facade((AV1_COMMON *)cm, td->counts, tx_size, tx_type,
- qcoeff, eob);
+ const int mi_row = -xd->mb_to_top_edge >> (3 + MI_SIZE_LOG2);
+ av1_update_scan_count_facade((AV1_COMMON *)cm, mi_row, td->counts, tx_size,
+ tx_type, qcoeff, eob);
#endif
}
diff --git a/av1/encoder/tokenize.c b/av1/encoder/tokenize.c
index 94cd9a9..b8a8f5e 100644
--- a/av1/encoder/tokenize.c
+++ b/av1/encoder/tokenize.c
@@ -513,8 +513,9 @@
// av1_update_scan_count_facade(). The update behavior should be the same
// because av1_update_scan_count_facade() only cares if coefficients are zero
// or not.
- av1_update_scan_count_facade((AV1_COMMON *)cm, td->counts, tx_size, tx_type,
- qcoeff, c);
+ const int mi_row = -xd->mb_to_top_edge >> (3 + MI_SIZE_LOG2);
+ av1_update_scan_count_facade((AV1_COMMON *)cm, mi_row, td->counts, tx_size,
+ tx_type, qcoeff, c);
#endif
av1_set_contexts(xd, pd, plane, tx_size, c > 0, blk_col, blk_row);