1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12 #ifndef AOM_AV1_ENCODER_AQ_CYCLICREFRESH_H_
13 #define AOM_AV1_ENCODER_AQ_CYCLICREFRESH_H_
14
15 #include "av1/common/blockd.h"
16
17 #ifdef __cplusplus
18 extern "C" {
19 #endif
20
21 // The segment ids used in cyclic refresh: from base (no boost) to increasing
22 // boost (higher delta-qp).
23 #define CR_SEGMENT_ID_BASE 0
24 #define CR_SEGMENT_ID_BOOST1 1
25 #define CR_SEGMENT_ID_BOOST2 2
26
27 // Maximum rate target ratio for setting segment delta-qp.
28 #define CR_MAX_RATE_TARGET_RATIO 4.0
29
30 struct AV1_COMP;
31
32 struct CYCLIC_REFRESH;
33 typedef struct CYCLIC_REFRESH CYCLIC_REFRESH;
34
35 CYCLIC_REFRESH *av1_cyclic_refresh_alloc(int mi_rows, int mi_cols);
36
37 void av1_cyclic_refresh_free(CYCLIC_REFRESH *cr);
38
39 // Estimate the bits, incorporating the delta-q from segment 1, after encoding
40 // the frame.
41 int av1_cyclic_refresh_estimate_bits_at_q(const struct AV1_COMP *cpi,
42 double correction_factor);
43
44 // Estimate the bits per mb, for a given q = i and a corresponding delta-q
45 // (for segment 1), prior to encoding the frame.
46 int av1_cyclic_refresh_rc_bits_per_mb(const struct AV1_COMP *cpi, int i,
47 double correction_factor);
48
49 // Prior to coding a given prediction block, of size bsize at (mi_row, mi_col),
50 // check if we should reset the segment_id, and update the cyclic_refresh map
51 // and segmentation map.
52 void av1_cyclic_refresh_update_segment(const struct AV1_COMP *cpi,
53 MB_MODE_INFO *const mbmi, int mi_row,
54 int mi_col, BLOCK_SIZE bsize,
55 int64_t rate, int64_t dist, int skip);
56
57 // Update the actual number of blocks that were applied the segment delta q.
58 void av1_cyclic_refresh_postencode(struct AV1_COMP *const cpi);
59
60 // Set golden frame update interval, for 1 pass CBR mode.
61 void av1_cyclic_refresh_set_golden_update(struct AV1_COMP *const cpi);
62
63 // Set/update global/frame level refresh parameters.
64 void av1_cyclic_refresh_update_parameters(struct AV1_COMP *const cpi);
65
66 // Setup cyclic background refresh: set delta q and segmentation map.
67 void av1_cyclic_refresh_setup(struct AV1_COMP *const cpi);
68
69 int av1_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr);
70
71 void av1_cyclic_refresh_reset_resize(struct AV1_COMP *const cpi);
72
cyclic_refresh_segment_id_boosted(int segment_id)73 static INLINE int cyclic_refresh_segment_id_boosted(int segment_id) {
74 return segment_id == CR_SEGMENT_ID_BOOST1 ||
75 segment_id == CR_SEGMENT_ID_BOOST2;
76 }
77
cyclic_refresh_segment_id(int segment_id)78 static INLINE int cyclic_refresh_segment_id(int segment_id) {
79 if (segment_id == CR_SEGMENT_ID_BOOST1)
80 return CR_SEGMENT_ID_BOOST1;
81 else if (segment_id == CR_SEGMENT_ID_BOOST2)
82 return CR_SEGMENT_ID_BOOST2;
83 else
84 return CR_SEGMENT_ID_BASE;
85 }
86
87 #ifdef __cplusplus
88 } // extern "C"
89 #endif
90
91 #endif // AOM_AV1_ENCODER_AQ_CYCLICREFRESH_H_
92