]> granicus.if.org Git - libvpx/blob - vp9/encoder/vp9_aq_cyclicrefresh.h
Merge "[svc] Make size of empty frame to be 16x16 all the time"
[libvpx] / vp9 / encoder / vp9_aq_cyclicrefresh.h
1 /*
2  *  Copyright (c) 2014 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10
11
12 #ifndef VP9_ENCODER_VP9_AQ_CYCLICREFRESH_H_
13 #define VP9_ENCODER_VP9_AQ_CYCLICREFRESH_H_
14
15 #include "vp9/common/vp9_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 // Boost factor for rate target ratio, for segment CR_SEGMENT_ID_BOOST2.
31 #define CR_BOOST2_FAC 1.7
32
33 struct VP9_COMP;
34
35 struct CYCLIC_REFRESH;
36 typedef struct CYCLIC_REFRESH CYCLIC_REFRESH;
37
38 CYCLIC_REFRESH *vp9_cyclic_refresh_alloc(int mi_rows, int mi_cols);
39
40 void vp9_cyclic_refresh_free(CYCLIC_REFRESH *cr);
41
42 // Estimate the bits, incorporating the delta-q from segment 1, after encoding
43 // the frame.
44 int vp9_cyclic_refresh_estimate_bits_at_q(const struct VP9_COMP *cpi,
45                                           double correction_factor);
46
47 // Estimate the bits per mb, for a given q = i and a corresponding delta-q
48 // (for segment 1), prior to encoding the frame.
49 int vp9_cyclic_refresh_rc_bits_per_mb(const struct VP9_COMP *cpi, int i,
50                                       double correction_factor);
51
52 // Prior to coding a given prediction block, of size bsize at (mi_row, mi_col),
53 // check if we should reset the segment_id, and update the cyclic_refresh map
54 // and segmentation map.
55 void vp9_cyclic_refresh_update_segment(struct VP9_COMP *const cpi,
56                                        MB_MODE_INFO *const mbmi,
57                                        int mi_row, int mi_col, BLOCK_SIZE bsize,
58                                        int64_t rate, int64_t dist, int skip);
59
60 // Update the segmentation map, and related quantities: cyclic refresh map,
61 // refresh sb_index, and target number of blocks to be refreshed.
62 void vp9_cyclic_refresh_update__map(struct VP9_COMP *const cpi);
63
64 // Update the actual number of blocks that were applied the segment delta q.
65 void vp9_cyclic_refresh_postencode(struct VP9_COMP *const cpi);
66
67 // Set golden frame update interval, for non-svc 1 pass CBR mode.
68 void vp9_cyclic_refresh_set_golden_update(struct VP9_COMP *const cpi);
69
70 // Check if we should not update golden reference, based on past refresh stats.
71 void vp9_cyclic_refresh_check_golden_update(struct VP9_COMP *const cpi);
72
73 // Set/update global/frame level refresh parameters.
74 void vp9_cyclic_refresh_update_parameters(struct VP9_COMP *const cpi);
75
76 // Setup cyclic background refresh: set delta q and segmentation map.
77 void vp9_cyclic_refresh_setup(struct VP9_COMP *const cpi);
78
79 int vp9_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr);
80
81 static INLINE int cyclic_refresh_segment_id_boosted(int segment_id) {
82   return segment_id == CR_SEGMENT_ID_BOOST1 ||
83          segment_id == CR_SEGMENT_ID_BOOST2;
84 }
85
86 static INLINE int cyclic_refresh_segment_id(int segment_id) {
87   if (segment_id == CR_SEGMENT_ID_BOOST1)
88     return CR_SEGMENT_ID_BOOST1;
89   else if (segment_id == CR_SEGMENT_ID_BOOST2)
90     return CR_SEGMENT_ID_BOOST2;
91   else
92     return CR_SEGMENT_ID_BASE;
93 }
94
95 #ifdef __cplusplus
96 }  // extern "C"
97 #endif
98
99 #endif  // VP9_ENCODER_VP9_AQ_CYCLICREFRESH_H_