2 * Copyright (c) 2014 The WebM project authors. All Rights Reserved.
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.
12 #ifndef VP10_ENCODER_AQ_CYCLICREFRESH_H_
13 #define VP10_ENCODER_AQ_CYCLICREFRESH_H_
15 #include "vp10/common/blockd.h"
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
27 // Maximum rate target ratio for setting segment delta-qp.
28 #define CR_MAX_RATE_TARGET_RATIO 4.0
32 struct CYCLIC_REFRESH;
33 typedef struct CYCLIC_REFRESH CYCLIC_REFRESH;
35 CYCLIC_REFRESH *vp10_cyclic_refresh_alloc(int mi_rows, int mi_cols);
37 void vp10_cyclic_refresh_free(CYCLIC_REFRESH *cr);
39 // Estimate the bits, incorporating the delta-q from segment 1, after encoding
41 int vp10_cyclic_refresh_estimate_bits_at_q(const struct VP10_COMP *cpi,
42 double correction_factor);
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 vp10_cyclic_refresh_rc_bits_per_mb(const struct VP10_COMP *cpi, int i,
47 double correction_factor);
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 vp10_cyclic_refresh_update_segment(struct VP10_COMP *const cpi,
53 MB_MODE_INFO *const mbmi,
54 int mi_row, int mi_col, BLOCK_SIZE bsize,
55 int64_t rate, int64_t dist, int skip);
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 vp10_cyclic_refresh_update__map(struct VP10_COMP *const cpi);
61 // Update the actual number of blocks that were applied the segment delta q.
62 void vp10_cyclic_refresh_postencode(struct VP10_COMP *const cpi);
64 // Set golden frame update interval, for non-svc 1 pass CBR mode.
65 void vp10_cyclic_refresh_set_golden_update(struct VP10_COMP *const cpi);
67 // Check if we should not update golden reference, based on past refresh stats.
68 void vp10_cyclic_refresh_check_golden_update(struct VP10_COMP *const cpi);
70 // Set/update global/frame level refresh parameters.
71 void vp10_cyclic_refresh_update_parameters(struct VP10_COMP *const cpi);
73 // Setup cyclic background refresh: set delta q and segmentation map.
74 void vp10_cyclic_refresh_setup(struct VP10_COMP *const cpi);
76 int vp10_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr);
78 void vp10_cyclic_refresh_reset_resize(struct VP10_COMP *const cpi);
80 static INLINE int cyclic_refresh_segment_id_boosted(int segment_id) {
81 return segment_id == CR_SEGMENT_ID_BOOST1 ||
82 segment_id == CR_SEGMENT_ID_BOOST2;
85 static INLINE int cyclic_refresh_segment_id(int segment_id) {
86 if (segment_id == CR_SEGMENT_ID_BOOST1)
87 return CR_SEGMENT_ID_BOOST1;
88 else if (segment_id == CR_SEGMENT_ID_BOOST2)
89 return CR_SEGMENT_ID_BOOST2;
91 return CR_SEGMENT_ID_BASE;
98 #endif // VP10_ENCODER_AQ_CYCLICREFRESH_H_