Line data Source code
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 AV1_ENCODER_AQ_CYCLICREFRESH_H_
13 : #define 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 segmentation map, and related quantities: cyclic refresh map,
58 : // refresh sb_index, and target number of blocks to be refreshed.
59 : void av1_cyclic_refresh_update__map(struct AV1_COMP *const cpi);
60 :
61 : // Update the actual number of blocks that were applied the segment delta q.
62 : void av1_cyclic_refresh_postencode(struct AV1_COMP *const cpi);
63 :
64 : // Set golden frame update interval, for 1 pass CBR mode.
65 : void av1_cyclic_refresh_set_golden_update(struct AV1_COMP *const cpi);
66 :
67 : // Check if we should not update golden reference, based on past refresh stats.
68 : void av1_cyclic_refresh_check_golden_update(struct AV1_COMP *const cpi);
69 :
70 : // Set/update global/frame level refresh parameters.
71 : void av1_cyclic_refresh_update_parameters(struct AV1_COMP *const cpi);
72 :
73 : // Setup cyclic background refresh: set delta q and segmentation map.
74 : void av1_cyclic_refresh_setup(struct AV1_COMP *const cpi);
75 :
76 : int av1_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr);
77 :
78 : void av1_cyclic_refresh_reset_resize(struct AV1_COMP *const cpi);
79 :
80 0 : static INLINE int cyclic_refresh_segment_id_boosted(int segment_id) {
81 0 : return segment_id == CR_SEGMENT_ID_BOOST1 ||
82 : segment_id == CR_SEGMENT_ID_BOOST2;
83 : }
84 :
85 0 : static INLINE int cyclic_refresh_segment_id(int segment_id) {
86 0 : if (segment_id == CR_SEGMENT_ID_BOOST1)
87 0 : return CR_SEGMENT_ID_BOOST1;
88 0 : else if (segment_id == CR_SEGMENT_ID_BOOST2)
89 0 : return CR_SEGMENT_ID_BOOST2;
90 : else
91 0 : return CR_SEGMENT_ID_BASE;
92 : }
93 :
94 : #ifdef __cplusplus
95 : } // extern "C"
96 : #endif
97 :
98 : #endif // AV1_ENCODER_AQ_CYCLICREFRESH_H_
|