2014-03-14 22:35:47 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 The WebM project authors. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2014-03-21 22:31:53 +01:00
|
|
|
#ifndef VP9_ENCODER_VP9_AQ_CYCLICREFRESH_H_
|
|
|
|
#define VP9_ENCODER_VP9_AQ_CYCLICREFRESH_H_
|
2014-03-14 22:35:47 +01:00
|
|
|
|
2015-09-08 20:45:15 +02:00
|
|
|
#include "vpx/vpx_integer.h"
|
2014-03-21 00:42:13 +01:00
|
|
|
#include "vp9/common/vp9_blockd.h"
|
2014-03-14 22:35:47 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-01-28 20:34:24 +01:00
|
|
|
// The segment ids used in cyclic refresh: from base (no boost) to increasing
|
|
|
|
// boost (higher delta-qp).
|
|
|
|
#define CR_SEGMENT_ID_BASE 0
|
|
|
|
#define CR_SEGMENT_ID_BOOST1 1
|
|
|
|
#define CR_SEGMENT_ID_BOOST2 2
|
|
|
|
|
|
|
|
// Maximum rate target ratio for setting segment delta-qp.
|
|
|
|
#define CR_MAX_RATE_TARGET_RATIO 4.0
|
|
|
|
|
2015-09-08 20:45:15 +02:00
|
|
|
struct CYCLIC_REFRESH {
|
|
|
|
// Percentage of blocks per frame that are targeted as candidates
|
|
|
|
// for cyclic refresh.
|
|
|
|
int percent_refresh;
|
|
|
|
// Maximum q-delta as percentage of base q.
|
|
|
|
int max_qdelta_perc;
|
|
|
|
// Superblock starting index for cycling through the frame.
|
|
|
|
int sb_index;
|
|
|
|
// Controls how long block will need to wait to be refreshed again, in
|
|
|
|
// excess of the cycle time, i.e., in the case of all zero motion, block
|
|
|
|
// will be refreshed every (100/percent_refresh + time_for_refresh) frames.
|
|
|
|
int time_for_refresh;
|
|
|
|
// Target number of (8x8) blocks that are set for delta-q.
|
|
|
|
int target_num_seg_blocks;
|
|
|
|
// Actual number of (8x8) blocks that were applied delta-q.
|
|
|
|
int actual_num_seg1_blocks;
|
|
|
|
int actual_num_seg2_blocks;
|
|
|
|
// RD mult. parameters for segment 1.
|
|
|
|
int rdmult;
|
|
|
|
// Cyclic refresh map.
|
|
|
|
signed char *map;
|
|
|
|
// Map of the last q a block was coded at.
|
|
|
|
uint8_t *last_coded_q_map;
|
|
|
|
// Thresholds applied to the projected rate/distortion of the coding block,
|
|
|
|
// when deciding whether block should be refreshed.
|
|
|
|
int64_t thresh_rate_sb;
|
|
|
|
int64_t thresh_dist_sb;
|
|
|
|
// Threshold applied to the motion vector (in units of 1/8 pel) of the
|
|
|
|
// coding block, when deciding whether block should be refreshed.
|
|
|
|
int16_t motion_thresh;
|
|
|
|
// Rate target ratio to set q delta.
|
|
|
|
double rate_ratio_qdelta;
|
|
|
|
// Boost factor for rate target ratio, for segment CR_SEGMENT_ID_BOOST2.
|
|
|
|
int rate_boost_fac;
|
|
|
|
double low_content_avg;
|
|
|
|
int qindex_delta[3];
|
|
|
|
};
|
|
|
|
|
2014-03-21 00:42:13 +01:00
|
|
|
struct VP9_COMP;
|
2014-03-14 22:35:47 +01:00
|
|
|
|
2014-03-26 19:00:35 +01:00
|
|
|
typedef struct CYCLIC_REFRESH CYCLIC_REFRESH;
|
|
|
|
|
|
|
|
CYCLIC_REFRESH *vp9_cyclic_refresh_alloc(int mi_rows, int mi_cols);
|
|
|
|
|
|
|
|
void vp9_cyclic_refresh_free(CYCLIC_REFRESH *cr);
|
|
|
|
|
2014-04-03 03:37:04 +02:00
|
|
|
// Estimate the bits, incorporating the delta-q from segment 1, after encoding
|
|
|
|
// the frame.
|
|
|
|
int vp9_cyclic_refresh_estimate_bits_at_q(const struct VP9_COMP *cpi,
|
|
|
|
double correction_factor);
|
|
|
|
|
|
|
|
// Estimate the bits per mb, for a given q = i and a corresponding delta-q
|
|
|
|
// (for segment 1), prior to encoding the frame.
|
|
|
|
int vp9_cyclic_refresh_rc_bits_per_mb(const struct VP9_COMP *cpi, int i,
|
|
|
|
double correction_factor);
|
|
|
|
|
2014-03-14 22:35:47 +01:00
|
|
|
// Prior to coding a given prediction block, of size bsize at (mi_row, mi_col),
|
|
|
|
// check if we should reset the segment_id, and update the cyclic_refresh map
|
|
|
|
// and segmentation map.
|
2014-03-26 19:00:35 +01:00
|
|
|
void vp9_cyclic_refresh_update_segment(struct VP9_COMP *const cpi,
|
|
|
|
MB_MODE_INFO *const mbmi,
|
2015-01-22 01:09:13 +01:00
|
|
|
int mi_row, int mi_col, BLOCK_SIZE bsize,
|
2015-03-10 23:16:10 +01:00
|
|
|
int64_t rate, int64_t dist, int skip);
|
2014-03-14 22:35:47 +01:00
|
|
|
|
2014-04-03 03:37:04 +02:00
|
|
|
// Update the segmentation map, and related quantities: cyclic refresh map,
|
|
|
|
// refresh sb_index, and target number of blocks to be refreshed.
|
|
|
|
void vp9_cyclic_refresh_update__map(struct VP9_COMP *const cpi);
|
|
|
|
|
|
|
|
// Update the actual number of blocks that were applied the segment delta q.
|
2015-03-06 02:26:52 +01:00
|
|
|
void vp9_cyclic_refresh_postencode(struct VP9_COMP *const cpi);
|
|
|
|
|
|
|
|
// Set golden frame update interval, for non-svc 1 pass CBR mode.
|
2015-03-12 00:11:35 +01:00
|
|
|
void vp9_cyclic_refresh_set_golden_update(struct VP9_COMP *const cpi);
|
2015-03-06 02:26:52 +01:00
|
|
|
|
|
|
|
// Check if we should not update golden reference, based on past refresh stats.
|
|
|
|
void vp9_cyclic_refresh_check_golden_update(struct VP9_COMP *const cpi);
|
2014-04-03 03:37:04 +02:00
|
|
|
|
2014-12-03 19:19:54 +01:00
|
|
|
// Set/update global/frame level refresh parameters.
|
|
|
|
void vp9_cyclic_refresh_update_parameters(struct VP9_COMP *const cpi);
|
|
|
|
|
2014-03-14 22:35:47 +01:00
|
|
|
// Setup cyclic background refresh: set delta q and segmentation map.
|
2014-03-26 19:00:35 +01:00
|
|
|
void vp9_cyclic_refresh_setup(struct VP9_COMP *const cpi);
|
|
|
|
|
|
|
|
int vp9_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr);
|
2014-03-14 22:35:47 +01:00
|
|
|
|
2015-06-08 19:03:51 +02:00
|
|
|
void vp9_cyclic_refresh_reset_resize(struct VP9_COMP *const cpi);
|
|
|
|
|
2015-03-11 00:08:17 +01:00
|
|
|
static INLINE int cyclic_refresh_segment_id_boosted(int segment_id) {
|
|
|
|
return segment_id == CR_SEGMENT_ID_BOOST1 ||
|
|
|
|
segment_id == CR_SEGMENT_ID_BOOST2;
|
|
|
|
}
|
|
|
|
|
2015-03-10 23:16:10 +01:00
|
|
|
static INLINE int cyclic_refresh_segment_id(int segment_id) {
|
|
|
|
if (segment_id == CR_SEGMENT_ID_BOOST1)
|
|
|
|
return CR_SEGMENT_ID_BOOST1;
|
|
|
|
else if (segment_id == CR_SEGMENT_ID_BOOST2)
|
|
|
|
return CR_SEGMENT_ID_BOOST2;
|
|
|
|
else
|
|
|
|
return CR_SEGMENT_ID_BASE;
|
|
|
|
}
|
|
|
|
|
2014-03-14 22:35:47 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
} // extern "C"
|
|
|
|
#endif
|
|
|
|
|
2014-03-21 22:31:53 +01:00
|
|
|
#endif // VP9_ENCODER_VP9_AQ_CYCLICREFRESH_H_
|