2015-08-06 05:00:31 +03:00
|
|
|
/*
|
2016-09-02 22:04:54 +03:00
|
|
|
* Copyright (c) 2016, Alliance for Open Media. All rights reserved
|
2015-08-06 05:00:31 +03:00
|
|
|
*
|
2016-09-02 22:04:54 +03:00
|
|
|
* This source code is subject to the terms of the BSD 2 Clause License and
|
|
|
|
* the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
|
|
|
|
* was not distributed with this source code in the LICENSE file, you can
|
|
|
|
* obtain it at www.aomedia.org/license/software. If the Alliance for Open
|
|
|
|
* Media Patent License 1.0 was not distributed with this source code in the
|
|
|
|
* PATENTS file, you can obtain it at www.aomedia.org/license/patent.
|
2015-08-06 05:00:31 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <limits.h>
|
|
|
|
#include <math.h>
|
|
|
|
|
2016-08-23 02:08:15 +03:00
|
|
|
#include "av1/common/seg_common.h"
|
|
|
|
#include "av1/encoder/aq_cyclicrefresh.h"
|
|
|
|
#include "av1/encoder/ratectrl.h"
|
|
|
|
#include "av1/encoder/segmentation.h"
|
2016-08-31 00:01:10 +03:00
|
|
|
#include "aom_dsp/aom_dsp_common.h"
|
2016-08-23 02:08:15 +03:00
|
|
|
#include "aom_ports/system_state.h"
|
2015-08-06 05:00:31 +03: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];
|
|
|
|
};
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
CYCLIC_REFRESH *av1_cyclic_refresh_alloc(int mi_rows, int mi_cols) {
|
2015-08-06 05:00:31 +03:00
|
|
|
size_t last_coded_q_map_size;
|
2016-08-31 00:01:10 +03:00
|
|
|
CYCLIC_REFRESH *const cr = aom_calloc(1, sizeof(*cr));
|
2016-08-12 06:13:14 +03:00
|
|
|
if (cr == NULL) return NULL;
|
2015-08-06 05:00:31 +03:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
cr->map = aom_calloc(mi_rows * mi_cols, sizeof(*cr->map));
|
2015-08-06 05:00:31 +03:00
|
|
|
if (cr->map == NULL) {
|
2016-08-31 00:01:10 +03:00
|
|
|
av1_cyclic_refresh_free(cr);
|
2015-08-06 05:00:31 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
last_coded_q_map_size = mi_rows * mi_cols * sizeof(*cr->last_coded_q_map);
|
2016-08-31 00:01:10 +03:00
|
|
|
cr->last_coded_q_map = aom_malloc(last_coded_q_map_size);
|
2015-08-06 05:00:31 +03:00
|
|
|
if (cr->last_coded_q_map == NULL) {
|
2016-08-31 00:01:10 +03:00
|
|
|
av1_cyclic_refresh_free(cr);
|
2015-08-06 05:00:31 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
assert(MAXQ <= 255);
|
|
|
|
memset(cr->last_coded_q_map, MAXQ, last_coded_q_map_size);
|
|
|
|
|
|
|
|
return cr;
|
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
void av1_cyclic_refresh_free(CYCLIC_REFRESH *cr) {
|
|
|
|
aom_free(cr->map);
|
|
|
|
aom_free(cr->last_coded_q_map);
|
|
|
|
aom_free(cr);
|
2015-08-06 05:00:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check if we should turn off cyclic refresh based on bitrate condition.
|
2016-08-31 00:01:10 +03:00
|
|
|
static int apply_cyclic_refresh_bitrate(const AV1_COMMON *cm,
|
2015-08-06 05:00:31 +03:00
|
|
|
const RATE_CONTROL *rc) {
|
|
|
|
// Turn off cyclic refresh if bits available per frame is not sufficiently
|
|
|
|
// larger than bit cost of segmentation. Segment map bit cost should scale
|
|
|
|
// with number of seg blocks, so compare available bits to number of blocks.
|
|
|
|
// Average bits available per frame = avg_frame_bandwidth
|
|
|
|
// Number of (8x8) blocks in frame = mi_rows * mi_cols;
|
|
|
|
const float factor = 0.25;
|
2016-08-12 06:13:14 +03:00
|
|
|
const int number_blocks = cm->mi_rows * cm->mi_cols;
|
2015-08-06 05:00:31 +03:00
|
|
|
// The condition below corresponds to turning off at target bitrates:
|
|
|
|
// (at 30fps), ~12kbps for CIF, 36kbps for VGA, 100kps for HD/720p.
|
|
|
|
// Also turn off at very small frame sizes, to avoid too large fraction of
|
|
|
|
// superblocks to be refreshed per frame. Threshold below is less than QCIF.
|
|
|
|
if (rc->avg_frame_bandwidth < factor * number_blocks ||
|
|
|
|
number_blocks / 64 < 5)
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check if this coding block, of size bsize, should be considered for refresh
|
|
|
|
// (lower-qp coding). Decision can be based on various factors, such as
|
|
|
|
// size of the coding block (i.e., below min_block size rejected), coding
|
|
|
|
// mode, and rate/distortion.
|
|
|
|
static int candidate_refresh_aq(const CYCLIC_REFRESH *cr,
|
2016-08-12 06:13:14 +03:00
|
|
|
const MB_MODE_INFO *mbmi, int64_t rate,
|
|
|
|
int64_t dist, int bsize) {
|
2015-08-06 05:00:31 +03:00
|
|
|
MV mv = mbmi->mv[0].as_mv;
|
|
|
|
// Reject the block for lower-qp coding if projected distortion
|
|
|
|
// is above the threshold, and any of the following is true:
|
|
|
|
// 1) mode uses large mv
|
|
|
|
// 2) mode is an intra-mode
|
|
|
|
// Otherwise accept for refresh.
|
|
|
|
if (dist > cr->thresh_dist_sb &&
|
|
|
|
(mv.row > cr->motion_thresh || mv.row < -cr->motion_thresh ||
|
|
|
|
mv.col > cr->motion_thresh || mv.col < -cr->motion_thresh ||
|
|
|
|
!is_inter_block(mbmi)))
|
|
|
|
return CR_SEGMENT_ID_BASE;
|
2016-08-12 06:13:14 +03:00
|
|
|
else if (bsize >= BLOCK_16X16 && rate < cr->thresh_rate_sb &&
|
|
|
|
is_inter_block(mbmi) && mbmi->mv[0].as_int == 0 &&
|
|
|
|
cr->rate_boost_fac > 10)
|
2015-08-06 05:00:31 +03:00
|
|
|
// More aggressive delta-q for bigger blocks with zero motion.
|
|
|
|
return CR_SEGMENT_ID_BOOST2;
|
|
|
|
else
|
|
|
|
return CR_SEGMENT_ID_BOOST1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Compute delta-q for the segment.
|
2016-08-31 00:01:10 +03:00
|
|
|
static int compute_deltaq(const AV1_COMP *cpi, int q, double rate_factor) {
|
2015-08-06 05:00:31 +03:00
|
|
|
const CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
|
|
|
|
const RATE_CONTROL *const rc = &cpi->rc;
|
2016-08-31 00:01:10 +03:00
|
|
|
int deltaq = av1_compute_qdelta_by_rate(rc, cpi->common.frame_type, q,
|
|
|
|
rate_factor, cpi->common.bit_depth);
|
2015-08-06 05:00:31 +03:00
|
|
|
if ((-deltaq) > cr->max_qdelta_perc * q / 100) {
|
|
|
|
deltaq = -cr->max_qdelta_perc * q / 100;
|
|
|
|
}
|
|
|
|
return deltaq;
|
|
|
|
}
|
|
|
|
|
|
|
|
// For the just encoded frame, estimate the bits, incorporating the delta-q
|
|
|
|
// from non-base segment. For now ignore effect of multiple segments
|
|
|
|
// (with different delta-q). Note this function is called in the postencode
|
|
|
|
// (called from rc_update_rate_correction_factors()).
|
2016-08-31 00:01:10 +03:00
|
|
|
int av1_cyclic_refresh_estimate_bits_at_q(const AV1_COMP *cpi,
|
|
|
|
double correction_factor) {
|
|
|
|
const AV1_COMMON *const cm = &cpi->common;
|
2015-08-06 05:00:31 +03:00
|
|
|
const CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
|
|
|
|
int estimated_bits;
|
|
|
|
int mbs = cm->MBs;
|
|
|
|
int num8x8bl = mbs << 2;
|
|
|
|
// Weight for non-base segments: use actual number of blocks refreshed in
|
|
|
|
// previous/just encoded frame. Note number of blocks here is in 8x8 units.
|
|
|
|
double weight_segment1 = (double)cr->actual_num_seg1_blocks / num8x8bl;
|
|
|
|
double weight_segment2 = (double)cr->actual_num_seg2_blocks / num8x8bl;
|
|
|
|
// Take segment weighted average for estimated bits.
|
2016-08-12 06:13:14 +03:00
|
|
|
estimated_bits =
|
|
|
|
(int)((1.0 - weight_segment1 - weight_segment2) *
|
2016-08-31 00:01:10 +03:00
|
|
|
av1_estimate_bits_at_q(cm->frame_type, cm->base_qindex, mbs,
|
|
|
|
correction_factor, cm->bit_depth) +
|
2016-08-12 06:13:14 +03:00
|
|
|
weight_segment1 *
|
2016-08-31 00:01:10 +03:00
|
|
|
av1_estimate_bits_at_q(cm->frame_type,
|
|
|
|
cm->base_qindex + cr->qindex_delta[1],
|
|
|
|
mbs, correction_factor, cm->bit_depth) +
|
2016-08-12 06:13:14 +03:00
|
|
|
weight_segment2 *
|
2016-08-31 00:01:10 +03:00
|
|
|
av1_estimate_bits_at_q(cm->frame_type,
|
|
|
|
cm->base_qindex + cr->qindex_delta[2],
|
|
|
|
mbs, correction_factor, cm->bit_depth));
|
2015-08-06 05:00:31 +03:00
|
|
|
return estimated_bits;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Prior to encoding the frame, estimate the bits per mb, for a given q = i and
|
|
|
|
// a corresponding delta-q (for segment 1). This function is called in the
|
|
|
|
// rc_regulate_q() to set the base qp index.
|
|
|
|
// Note: the segment map is set to either 0/CR_SEGMENT_ID_BASE (no refresh) or
|
|
|
|
// to 1/CR_SEGMENT_ID_BOOST1 (refresh) for each superblock, prior to encoding.
|
2016-08-31 00:01:10 +03:00
|
|
|
int av1_cyclic_refresh_rc_bits_per_mb(const AV1_COMP *cpi, int i,
|
|
|
|
double correction_factor) {
|
|
|
|
const AV1_COMMON *const cm = &cpi->common;
|
2015-08-06 05:00:31 +03:00
|
|
|
CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
|
|
|
|
int bits_per_mb;
|
|
|
|
int num8x8bl = cm->MBs << 2;
|
|
|
|
// Weight for segment prior to encoding: take the average of the target
|
|
|
|
// number for the frame to be encoded and the actual from the previous frame.
|
2016-08-12 06:13:14 +03:00
|
|
|
double weight_segment =
|
|
|
|
(double)((cr->target_num_seg_blocks + cr->actual_num_seg1_blocks +
|
|
|
|
cr->actual_num_seg2_blocks) >>
|
|
|
|
1) /
|
2015-08-06 05:00:31 +03:00
|
|
|
num8x8bl;
|
|
|
|
// Compute delta-q corresponding to qindex i.
|
|
|
|
int deltaq = compute_deltaq(cpi, i, cr->rate_ratio_qdelta);
|
|
|
|
// Take segment weighted average for bits per mb.
|
2016-08-31 00:01:10 +03:00
|
|
|
bits_per_mb = (int)((1.0 - weight_segment) *
|
|
|
|
av1_rc_bits_per_mb(cm->frame_type, i,
|
|
|
|
correction_factor, cm->bit_depth) +
|
|
|
|
weight_segment *
|
|
|
|
av1_rc_bits_per_mb(cm->frame_type, i + deltaq,
|
|
|
|
correction_factor, cm->bit_depth));
|
2015-08-06 05:00:31 +03:00
|
|
|
return bits_per_mb;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2016-10-14 03:27:51 +03:00
|
|
|
void av1_cyclic_refresh_update_segment(const AV1_COMP *cpi,
|
2016-08-31 00:01:10 +03:00
|
|
|
MB_MODE_INFO *const mbmi, int mi_row,
|
|
|
|
int mi_col, BLOCK_SIZE bsize,
|
|
|
|
int64_t rate, int64_t dist, int skip) {
|
|
|
|
const AV1_COMMON *const cm = &cpi->common;
|
2015-08-06 05:00:31 +03:00
|
|
|
CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
|
2016-12-07 01:48:09 +03:00
|
|
|
const int bw = mi_size_wide[bsize];
|
|
|
|
const int bh = mi_size_high[bsize];
|
2016-08-31 00:01:10 +03:00
|
|
|
const int xmis = AOMMIN(cm->mi_cols - mi_col, bw);
|
|
|
|
const int ymis = AOMMIN(cm->mi_rows - mi_row, bh);
|
2015-08-06 05:00:31 +03:00
|
|
|
const int block_index = mi_row * cm->mi_cols + mi_col;
|
2016-08-12 06:13:14 +03:00
|
|
|
const int refresh_this_block =
|
|
|
|
candidate_refresh_aq(cr, mbmi, rate, dist, bsize);
|
2015-08-06 05:00:31 +03:00
|
|
|
// Default is to not update the refresh map.
|
|
|
|
int new_map_value = cr->map[block_index];
|
2016-08-12 06:13:14 +03:00
|
|
|
int x = 0;
|
|
|
|
int y = 0;
|
2015-08-06 05:00:31 +03:00
|
|
|
|
|
|
|
// If this block is labeled for refresh, check if we should reset the
|
|
|
|
// segment_id.
|
|
|
|
if (cyclic_refresh_segment_id_boosted(mbmi->segment_id)) {
|
|
|
|
mbmi->segment_id = refresh_this_block;
|
|
|
|
// Reset segment_id if will be skipped.
|
2016-08-12 06:13:14 +03:00
|
|
|
if (skip) mbmi->segment_id = CR_SEGMENT_ID_BASE;
|
2015-08-06 05:00:31 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update the cyclic refresh map, to be used for setting segmentation map
|
|
|
|
// for the next frame. If the block will be refreshed this frame, mark it
|
|
|
|
// as clean. The magnitude of the -ve influences how long before we consider
|
|
|
|
// it for refresh again.
|
|
|
|
if (cyclic_refresh_segment_id_boosted(mbmi->segment_id)) {
|
|
|
|
new_map_value = -cr->time_for_refresh;
|
|
|
|
} else if (refresh_this_block) {
|
|
|
|
// Else if it is accepted as candidate for refresh, and has not already
|
|
|
|
// been refreshed (marked as 1) then mark it as a candidate for cleanup
|
|
|
|
// for future time (marked as 0), otherwise don't update it.
|
2016-08-12 06:13:14 +03:00
|
|
|
if (cr->map[block_index] == 1) new_map_value = 0;
|
2015-08-06 05:00:31 +03:00
|
|
|
} else {
|
|
|
|
// Leave it marked as block that is not candidate for refresh.
|
|
|
|
new_map_value = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update entries in the cyclic refresh map with new_map_value, and
|
|
|
|
// copy mbmi->segment_id into global segmentation map.
|
|
|
|
for (y = 0; y < ymis; y++)
|
|
|
|
for (x = 0; x < xmis; x++) {
|
|
|
|
int map_offset = block_index + y * cm->mi_cols + x;
|
|
|
|
cr->map[map_offset] = new_map_value;
|
|
|
|
cpi->segmentation_map[map_offset] = mbmi->segment_id;
|
|
|
|
// Inter skip blocks were clearly not coded at the current qindex, so
|
|
|
|
// don't update the map for them. For cases where motion is non-zero or
|
|
|
|
// the reference frame isn't the previous frame, the previous value in
|
|
|
|
// the map for this spatial location is not entirely correct.
|
2016-03-11 02:11:31 +03:00
|
|
|
if ((!is_inter_block(mbmi) || !skip) &&
|
|
|
|
mbmi->segment_id <= CR_SEGMENT_ID_BOOST2) {
|
2015-08-06 05:00:31 +03:00
|
|
|
cr->last_coded_q_map[map_offset] = clamp(
|
|
|
|
cm->base_qindex + cr->qindex_delta[mbmi->segment_id], 0, MAXQ);
|
2016-03-11 02:11:31 +03:00
|
|
|
} else if (is_inter_block(mbmi) && skip &&
|
|
|
|
mbmi->segment_id <= CR_SEGMENT_ID_BOOST2) {
|
|
|
|
cr->last_coded_q_map[map_offset] =
|
2016-08-31 00:01:10 +03:00
|
|
|
AOMMIN(clamp(cm->base_qindex + cr->qindex_delta[mbmi->segment_id],
|
2016-03-11 02:11:31 +03:00
|
|
|
0, MAXQ),
|
|
|
|
cr->last_coded_q_map[map_offset]);
|
|
|
|
}
|
2015-08-06 05:00:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the actual number of blocks that were applied the segment delta q.
|
2016-08-31 00:01:10 +03:00
|
|
|
void av1_cyclic_refresh_postencode(AV1_COMP *const cpi) {
|
|
|
|
AV1_COMMON *const cm = &cpi->common;
|
2015-08-06 05:00:31 +03:00
|
|
|
CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
|
|
|
|
unsigned char *const seg_map = cpi->segmentation_map;
|
|
|
|
int mi_row, mi_col;
|
|
|
|
cr->actual_num_seg1_blocks = 0;
|
|
|
|
cr->actual_num_seg2_blocks = 0;
|
|
|
|
for (mi_row = 0; mi_row < cm->mi_rows; mi_row++)
|
|
|
|
for (mi_col = 0; mi_col < cm->mi_cols; mi_col++) {
|
2016-08-12 06:13:14 +03:00
|
|
|
if (cyclic_refresh_segment_id(seg_map[mi_row * cm->mi_cols + mi_col]) ==
|
|
|
|
CR_SEGMENT_ID_BOOST1)
|
2015-08-06 05:00:31 +03:00
|
|
|
cr->actual_num_seg1_blocks++;
|
|
|
|
else if (cyclic_refresh_segment_id(
|
2016-08-12 06:13:14 +03:00
|
|
|
seg_map[mi_row * cm->mi_cols + mi_col]) ==
|
|
|
|
CR_SEGMENT_ID_BOOST2)
|
2015-08-06 05:00:31 +03:00
|
|
|
cr->actual_num_seg2_blocks++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-28 01:11:38 +03:00
|
|
|
// Set golden frame update interval, for 1 pass CBR mode.
|
2016-08-31 00:01:10 +03:00
|
|
|
void av1_cyclic_refresh_set_golden_update(AV1_COMP *const cpi) {
|
2015-08-06 05:00:31 +03:00
|
|
|
RATE_CONTROL *const rc = &cpi->rc;
|
|
|
|
CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
|
|
|
|
// Set minimum gf_interval for GF update to a multiple (== 2) of refresh
|
|
|
|
// period. Depending on past encoding stats, GF flag may be reset and update
|
|
|
|
// may not occur until next baseline_gf_interval.
|
|
|
|
if (cr->percent_refresh > 0)
|
|
|
|
rc->baseline_gf_interval = 4 * (100 / cr->percent_refresh);
|
|
|
|
else
|
|
|
|
rc->baseline_gf_interval = 40;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update some encoding stats (from the just encoded frame). If this frame's
|
|
|
|
// background has high motion, refresh the golden frame. Otherwise, if the
|
|
|
|
// golden reference is to be updated check if we should NOT update the golden
|
|
|
|
// ref.
|
2016-08-31 00:01:10 +03:00
|
|
|
void av1_cyclic_refresh_check_golden_update(AV1_COMP *const cpi) {
|
|
|
|
AV1_COMMON *const cm = &cpi->common;
|
2015-08-06 05:00:31 +03:00
|
|
|
CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
|
|
|
|
int mi_row, mi_col;
|
|
|
|
double fraction_low = 0.0;
|
|
|
|
int low_content_frame = 0;
|
|
|
|
|
2016-06-14 15:12:45 +03:00
|
|
|
MODE_INFO **mi;
|
2015-08-06 05:00:31 +03:00
|
|
|
RATE_CONTROL *const rc = &cpi->rc;
|
|
|
|
const int rows = cm->mi_rows, cols = cm->mi_cols;
|
|
|
|
int cnt1 = 0, cnt2 = 0;
|
|
|
|
int force_gf_refresh = 0;
|
|
|
|
|
|
|
|
for (mi_row = 0; mi_row < rows; mi_row++) {
|
2016-06-14 15:12:45 +03:00
|
|
|
mi = cm->mi_grid_visible + mi_row * cm->mi_stride;
|
|
|
|
|
2015-08-06 05:00:31 +03:00
|
|
|
for (mi_col = 0; mi_col < cols; mi_col++) {
|
2016-08-12 06:13:14 +03:00
|
|
|
int16_t abs_mvr = mi[0]->mbmi.mv[0].as_mv.row >= 0
|
|
|
|
? mi[0]->mbmi.mv[0].as_mv.row
|
|
|
|
: -1 * mi[0]->mbmi.mv[0].as_mv.row;
|
|
|
|
int16_t abs_mvc = mi[0]->mbmi.mv[0].as_mv.col >= 0
|
|
|
|
? mi[0]->mbmi.mv[0].as_mv.col
|
|
|
|
: -1 * mi[0]->mbmi.mv[0].as_mv.col;
|
2015-08-06 05:00:31 +03:00
|
|
|
|
|
|
|
// Calculate the motion of the background.
|
|
|
|
if (abs_mvr <= 16 && abs_mvc <= 16) {
|
|
|
|
cnt1++;
|
2016-08-12 06:13:14 +03:00
|
|
|
if (abs_mvr == 0 && abs_mvc == 0) cnt2++;
|
2015-08-06 05:00:31 +03:00
|
|
|
}
|
|
|
|
mi++;
|
|
|
|
|
|
|
|
// Accumulate low_content_frame.
|
2016-08-12 06:13:14 +03:00
|
|
|
if (cr->map[mi_row * cols + mi_col] < 1) low_content_frame++;
|
2015-08-06 05:00:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// For video conference clips, if the background has high motion in current
|
|
|
|
// frame because of the camera movement, set this frame as the golden frame.
|
|
|
|
// Use 70% and 5% as the thresholds for golden frame refreshing.
|
2017-05-23 09:15:05 +03:00
|
|
|
if (cnt1 * 10 > (70 * rows * cols) && cnt2 * 20 < cnt1) {
|
2016-08-31 00:01:10 +03:00
|
|
|
av1_cyclic_refresh_set_golden_update(cpi);
|
2015-08-06 05:00:31 +03:00
|
|
|
rc->frames_till_gf_update_due = rc->baseline_gf_interval;
|
|
|
|
|
|
|
|
if (rc->frames_till_gf_update_due > rc->frames_to_key)
|
|
|
|
rc->frames_till_gf_update_due = rc->frames_to_key;
|
|
|
|
cpi->refresh_golden_frame = 1;
|
|
|
|
force_gf_refresh = 1;
|
|
|
|
}
|
|
|
|
|
2016-08-12 06:13:14 +03:00
|
|
|
fraction_low = (double)low_content_frame / (rows * cols);
|
2015-08-06 05:00:31 +03:00
|
|
|
// Update average.
|
|
|
|
cr->low_content_avg = (fraction_low + 3 * cr->low_content_avg) / 4;
|
|
|
|
if (!force_gf_refresh && cpi->refresh_golden_frame == 1) {
|
|
|
|
// Don't update golden reference if the amount of low_content for the
|
|
|
|
// current encoded frame is small, or if the recursive average of the
|
|
|
|
// low_content over the update interval window falls below threshold.
|
|
|
|
if (fraction_low < 0.8 || cr->low_content_avg < 0.7)
|
|
|
|
cpi->refresh_golden_frame = 0;
|
|
|
|
// Reset for next internal.
|
|
|
|
cr->low_content_avg = fraction_low;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update the segmentation map, and related quantities: cyclic refresh map,
|
|
|
|
// refresh sb_index, and target number of blocks to be refreshed.
|
|
|
|
// The map is set to either 0/CR_SEGMENT_ID_BASE (no refresh) or to
|
|
|
|
// 1/CR_SEGMENT_ID_BOOST1 (refresh) for each superblock.
|
|
|
|
// Blocks labeled as BOOST1 may later get set to BOOST2 (during the
|
|
|
|
// encoding of the superblock).
|
2016-08-31 00:01:10 +03:00
|
|
|
static void cyclic_refresh_update_map(AV1_COMP *const cpi) {
|
|
|
|
AV1_COMMON *const cm = &cpi->common;
|
2015-08-06 05:00:31 +03:00
|
|
|
CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
|
|
|
|
unsigned char *const seg_map = cpi->segmentation_map;
|
|
|
|
int i, block_count, bl_index, sb_rows, sb_cols, sbs_in_frame;
|
|
|
|
int xmis, ymis, x, y;
|
|
|
|
memset(seg_map, CR_SEGMENT_ID_BASE, cm->mi_rows * cm->mi_cols);
|
Make superblock size variable at the frame level.
The uncompressed frame header contains a bit to signal whether the
frame is encoded using 64x64 or 128x128 superblocks. This can vary
between any 2 frames.
vpxenc gained the --sb-size={64,128,dynamic} option, which allows the
configuration of the superblock size used (default is dynamic). 64/128
will force the encoder to always use the specified superblock size.
Dynamic would enable the encoder to choose the sb size for each
frame, but this is not implemented yet (dynamic does the same as 128
for now).
Constraints on tile sizes depend on the superblock size, the following
is a summary of the current bitstream syntax and semantics:
If both --enable-ext-tile is OFF and --enable-ext-partition is OFF:
The tile coding in this case is the same as VP9. In particular,
tiles have a minimum width of 256 pixels and a maximum width of
4096 pixels. The tile width must be multiples of 64 pixels
(except for the rightmost tile column). There can be a maximum
of 64 tile columns and 4 tile rows.
If --enable-ext-tile is OFF and --enable-ext-partition is ON:
Same constraints as above, except that tile width must be
multiples of 128 pixels (except for the rightmost tile column).
There is no change in the bitstream syntax used for coding the tile
configuration if --enable-ext-tile is OFF.
If --enable-ext-tile is ON and --enable-ext-partition is ON:
This is the new large scale tile coding configuration. The
minimum/maximum tile width and height are 64/4096 pixels. Tile
width and height must be multiples of 64 pixels. The uncompressed
header contains two 6 bit fields that hold the tile width/heigh
in units of 64 pixels. The maximum number of tile rows/columns
is only limited by the maximum frame size of 65536x65536 pixels
that can be coded in the bitstream. This yields a maximum of
1024x1024 tile rows and columns (of 64x64 tiles in a 65536x65536
frame).
If both --enable-ext-tile is ON and --enable-ext-partition is ON:
Same applies as above, except that in the bitstream the 2 fields
containing the tile width/height are in units of the superblock
size, and the superblock size itself is also coded in the bitstream.
If the uncompressed header signals the use of 64x64 superblocks,
then the tile width/height fields are 6 bits wide and are in units
of 64 pixels. If the uncompressed header signals the use of 128x128
superblocks, then the tile width/height fields are 5 bits wide and
are in units of 128 pixels.
The above is a summary of the bitstream. The user interface to vpxenc
(and the equivalent encoder API) behaves a follows:
If --enable-ext-tile is OFF:
No change in the user interface. --tile-columns and --tile-rows
specify the base 2 logarithm of the desired number of tile columns
and tile rows. The actual number of tile rows and tile columns,
and the particular tile width and tile height are computed by the
codec ensuring all of the above constraints are respected.
If --enable-ext-tile is ON, but --enable-ext-partition is OFF:
No change in the user interface. --tile-columns and --tile-rows
specify the WIDTH and HEIGHT of the tiles in unit of 64 pixels.
The valid values are in the range [1, 64] (which corresponds to
[64, 4096] pixels in increments of 64.
If both --enable-ext-tile is ON and --enable-ext-partition is ON:
If --sb-size=64 (default):
The user interface is the same as in the previous point.
--tile-columns and --tile-rows specify tile WIDTH and HEIGHT,
in units of 64 pixels, in the range [1, 64] (which corresponds
to [64, 4096] pixels in increments of 64).
If --sb-size=128 or --sb-size=dynamic:
--tile-columns and --tile-rows specify tile WIDTH and HEIGHT,
in units of 128 pixels in the range [1, 32] (which corresponds
to [128, 4096] pixels in increments of 128).
Change-Id: Idc9beee1ad12ff1634e83671985d14c680f9179a
2016-03-24 16:56:05 +03:00
|
|
|
sb_cols = (cm->mi_cols + cm->mib_size - 1) / cm->mib_size;
|
|
|
|
sb_rows = (cm->mi_rows + cm->mib_size - 1) / cm->mib_size;
|
2015-08-06 05:00:31 +03:00
|
|
|
sbs_in_frame = sb_cols * sb_rows;
|
|
|
|
// Number of target blocks to get the q delta (segment 1).
|
|
|
|
block_count = cr->percent_refresh * cm->mi_rows * cm->mi_cols / 100;
|
|
|
|
// Set the segmentation map: cycle through the superblocks, starting at
|
|
|
|
// cr->mb_index, and stopping when either block_count blocks have been found
|
|
|
|
// to be refreshed, or we have passed through whole frame.
|
|
|
|
assert(cr->sb_index < sbs_in_frame);
|
|
|
|
i = cr->sb_index;
|
|
|
|
cr->target_num_seg_blocks = 0;
|
|
|
|
do {
|
|
|
|
int sum_map = 0;
|
|
|
|
// Get the mi_row/mi_col corresponding to superblock index i.
|
|
|
|
int sb_row_index = (i / sb_cols);
|
|
|
|
int sb_col_index = i - sb_row_index * sb_cols;
|
Make superblock size variable at the frame level.
The uncompressed frame header contains a bit to signal whether the
frame is encoded using 64x64 or 128x128 superblocks. This can vary
between any 2 frames.
vpxenc gained the --sb-size={64,128,dynamic} option, which allows the
configuration of the superblock size used (default is dynamic). 64/128
will force the encoder to always use the specified superblock size.
Dynamic would enable the encoder to choose the sb size for each
frame, but this is not implemented yet (dynamic does the same as 128
for now).
Constraints on tile sizes depend on the superblock size, the following
is a summary of the current bitstream syntax and semantics:
If both --enable-ext-tile is OFF and --enable-ext-partition is OFF:
The tile coding in this case is the same as VP9. In particular,
tiles have a minimum width of 256 pixels and a maximum width of
4096 pixels. The tile width must be multiples of 64 pixels
(except for the rightmost tile column). There can be a maximum
of 64 tile columns and 4 tile rows.
If --enable-ext-tile is OFF and --enable-ext-partition is ON:
Same constraints as above, except that tile width must be
multiples of 128 pixels (except for the rightmost tile column).
There is no change in the bitstream syntax used for coding the tile
configuration if --enable-ext-tile is OFF.
If --enable-ext-tile is ON and --enable-ext-partition is ON:
This is the new large scale tile coding configuration. The
minimum/maximum tile width and height are 64/4096 pixels. Tile
width and height must be multiples of 64 pixels. The uncompressed
header contains two 6 bit fields that hold the tile width/heigh
in units of 64 pixels. The maximum number of tile rows/columns
is only limited by the maximum frame size of 65536x65536 pixels
that can be coded in the bitstream. This yields a maximum of
1024x1024 tile rows and columns (of 64x64 tiles in a 65536x65536
frame).
If both --enable-ext-tile is ON and --enable-ext-partition is ON:
Same applies as above, except that in the bitstream the 2 fields
containing the tile width/height are in units of the superblock
size, and the superblock size itself is also coded in the bitstream.
If the uncompressed header signals the use of 64x64 superblocks,
then the tile width/height fields are 6 bits wide and are in units
of 64 pixels. If the uncompressed header signals the use of 128x128
superblocks, then the tile width/height fields are 5 bits wide and
are in units of 128 pixels.
The above is a summary of the bitstream. The user interface to vpxenc
(and the equivalent encoder API) behaves a follows:
If --enable-ext-tile is OFF:
No change in the user interface. --tile-columns and --tile-rows
specify the base 2 logarithm of the desired number of tile columns
and tile rows. The actual number of tile rows and tile columns,
and the particular tile width and tile height are computed by the
codec ensuring all of the above constraints are respected.
If --enable-ext-tile is ON, but --enable-ext-partition is OFF:
No change in the user interface. --tile-columns and --tile-rows
specify the WIDTH and HEIGHT of the tiles in unit of 64 pixels.
The valid values are in the range [1, 64] (which corresponds to
[64, 4096] pixels in increments of 64.
If both --enable-ext-tile is ON and --enable-ext-partition is ON:
If --sb-size=64 (default):
The user interface is the same as in the previous point.
--tile-columns and --tile-rows specify tile WIDTH and HEIGHT,
in units of 64 pixels, in the range [1, 64] (which corresponds
to [64, 4096] pixels in increments of 64).
If --sb-size=128 or --sb-size=dynamic:
--tile-columns and --tile-rows specify tile WIDTH and HEIGHT,
in units of 128 pixels in the range [1, 32] (which corresponds
to [128, 4096] pixels in increments of 128).
Change-Id: Idc9beee1ad12ff1634e83671985d14c680f9179a
2016-03-24 16:56:05 +03:00
|
|
|
int mi_row = sb_row_index * cm->mib_size;
|
|
|
|
int mi_col = sb_col_index * cm->mib_size;
|
2015-08-06 05:00:31 +03:00
|
|
|
int qindex_thresh =
|
2016-08-31 00:01:10 +03:00
|
|
|
cpi->oxcf.content == AOM_CONTENT_SCREEN
|
|
|
|
? av1_get_qindex(&cm->seg, CR_SEGMENT_ID_BOOST2, cm->base_qindex)
|
2015-08-06 05:00:31 +03:00
|
|
|
: 0;
|
|
|
|
assert(mi_row >= 0 && mi_row < cm->mi_rows);
|
|
|
|
assert(mi_col >= 0 && mi_col < cm->mi_cols);
|
|
|
|
bl_index = mi_row * cm->mi_cols + mi_col;
|
Make superblock size variable at the frame level.
The uncompressed frame header contains a bit to signal whether the
frame is encoded using 64x64 or 128x128 superblocks. This can vary
between any 2 frames.
vpxenc gained the --sb-size={64,128,dynamic} option, which allows the
configuration of the superblock size used (default is dynamic). 64/128
will force the encoder to always use the specified superblock size.
Dynamic would enable the encoder to choose the sb size for each
frame, but this is not implemented yet (dynamic does the same as 128
for now).
Constraints on tile sizes depend on the superblock size, the following
is a summary of the current bitstream syntax and semantics:
If both --enable-ext-tile is OFF and --enable-ext-partition is OFF:
The tile coding in this case is the same as VP9. In particular,
tiles have a minimum width of 256 pixels and a maximum width of
4096 pixels. The tile width must be multiples of 64 pixels
(except for the rightmost tile column). There can be a maximum
of 64 tile columns and 4 tile rows.
If --enable-ext-tile is OFF and --enable-ext-partition is ON:
Same constraints as above, except that tile width must be
multiples of 128 pixels (except for the rightmost tile column).
There is no change in the bitstream syntax used for coding the tile
configuration if --enable-ext-tile is OFF.
If --enable-ext-tile is ON and --enable-ext-partition is ON:
This is the new large scale tile coding configuration. The
minimum/maximum tile width and height are 64/4096 pixels. Tile
width and height must be multiples of 64 pixels. The uncompressed
header contains two 6 bit fields that hold the tile width/heigh
in units of 64 pixels. The maximum number of tile rows/columns
is only limited by the maximum frame size of 65536x65536 pixels
that can be coded in the bitstream. This yields a maximum of
1024x1024 tile rows and columns (of 64x64 tiles in a 65536x65536
frame).
If both --enable-ext-tile is ON and --enable-ext-partition is ON:
Same applies as above, except that in the bitstream the 2 fields
containing the tile width/height are in units of the superblock
size, and the superblock size itself is also coded in the bitstream.
If the uncompressed header signals the use of 64x64 superblocks,
then the tile width/height fields are 6 bits wide and are in units
of 64 pixels. If the uncompressed header signals the use of 128x128
superblocks, then the tile width/height fields are 5 bits wide and
are in units of 128 pixels.
The above is a summary of the bitstream. The user interface to vpxenc
(and the equivalent encoder API) behaves a follows:
If --enable-ext-tile is OFF:
No change in the user interface. --tile-columns and --tile-rows
specify the base 2 logarithm of the desired number of tile columns
and tile rows. The actual number of tile rows and tile columns,
and the particular tile width and tile height are computed by the
codec ensuring all of the above constraints are respected.
If --enable-ext-tile is ON, but --enable-ext-partition is OFF:
No change in the user interface. --tile-columns and --tile-rows
specify the WIDTH and HEIGHT of the tiles in unit of 64 pixels.
The valid values are in the range [1, 64] (which corresponds to
[64, 4096] pixels in increments of 64.
If both --enable-ext-tile is ON and --enable-ext-partition is ON:
If --sb-size=64 (default):
The user interface is the same as in the previous point.
--tile-columns and --tile-rows specify tile WIDTH and HEIGHT,
in units of 64 pixels, in the range [1, 64] (which corresponds
to [64, 4096] pixels in increments of 64).
If --sb-size=128 or --sb-size=dynamic:
--tile-columns and --tile-rows specify tile WIDTH and HEIGHT,
in units of 128 pixels in the range [1, 32] (which corresponds
to [128, 4096] pixels in increments of 128).
Change-Id: Idc9beee1ad12ff1634e83671985d14c680f9179a
2016-03-24 16:56:05 +03:00
|
|
|
// Loop through all MI blocks in superblock and update map.
|
2016-08-31 00:01:10 +03:00
|
|
|
xmis = AOMMIN(cm->mi_cols - mi_col, cm->mib_size);
|
|
|
|
ymis = AOMMIN(cm->mi_rows - mi_row, cm->mib_size);
|
2015-08-06 05:00:31 +03:00
|
|
|
for (y = 0; y < ymis; y++) {
|
|
|
|
for (x = 0; x < xmis; x++) {
|
|
|
|
const int bl_index2 = bl_index + y * cm->mi_cols + x;
|
|
|
|
// If the block is as a candidate for clean up then mark it
|
|
|
|
// for possible boost/refresh (segment 1). The segment id may get
|
|
|
|
// reset to 0 later if block gets coded anything other than ZEROMV.
|
|
|
|
if (cr->map[bl_index2] == 0) {
|
2016-08-12 06:13:14 +03:00
|
|
|
if (cr->last_coded_q_map[bl_index2] > qindex_thresh) sum_map++;
|
2015-08-06 05:00:31 +03:00
|
|
|
} else if (cr->map[bl_index2] < 0) {
|
|
|
|
cr->map[bl_index2]++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Enforce constant segment over superblock.
|
|
|
|
// If segment is at least half of superblock, set to 1.
|
|
|
|
if (sum_map >= xmis * ymis / 2) {
|
|
|
|
for (y = 0; y < ymis; y++)
|
|
|
|
for (x = 0; x < xmis; x++) {
|
|
|
|
seg_map[bl_index + y * cm->mi_cols + x] = CR_SEGMENT_ID_BOOST1;
|
|
|
|
}
|
|
|
|
cr->target_num_seg_blocks += xmis * ymis;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
if (i == sbs_in_frame) {
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
} while (cr->target_num_seg_blocks < block_count && i != cr->sb_index);
|
|
|
|
cr->sb_index = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set cyclic refresh parameters.
|
2016-08-31 00:01:10 +03:00
|
|
|
void av1_cyclic_refresh_update_parameters(AV1_COMP *const cpi) {
|
2015-08-06 05:00:31 +03:00
|
|
|
const RATE_CONTROL *const rc = &cpi->rc;
|
2016-08-31 00:01:10 +03:00
|
|
|
const AV1_COMMON *const cm = &cpi->common;
|
2015-08-06 05:00:31 +03:00
|
|
|
CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
|
|
|
|
cr->percent_refresh = 10;
|
|
|
|
cr->max_qdelta_perc = 50;
|
|
|
|
cr->time_for_refresh = 0;
|
|
|
|
// Use larger delta-qp (increase rate_ratio_qdelta) for first few (~4)
|
|
|
|
// periods of the refresh cycle, after a key frame.
|
2016-08-12 06:13:14 +03:00
|
|
|
if (rc->frames_since_key < 4 * cr->percent_refresh)
|
2015-08-06 05:00:31 +03:00
|
|
|
cr->rate_ratio_qdelta = 3.0;
|
|
|
|
else
|
|
|
|
cr->rate_ratio_qdelta = 2.0;
|
|
|
|
// Adjust some parameters for low resolutions at low bitrates.
|
2016-08-12 06:13:14 +03:00
|
|
|
if (cm->width <= 352 && cm->height <= 288 && rc->avg_frame_bandwidth < 3400) {
|
2015-08-06 05:00:31 +03:00
|
|
|
cr->motion_thresh = 4;
|
|
|
|
cr->rate_boost_fac = 10;
|
|
|
|
} else {
|
|
|
|
cr->motion_thresh = 32;
|
|
|
|
cr->rate_boost_fac = 17;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Setup cyclic background refresh: set delta q and segmentation map.
|
2016-08-31 00:01:10 +03:00
|
|
|
void av1_cyclic_refresh_setup(AV1_COMP *const cpi) {
|
|
|
|
AV1_COMMON *const cm = &cpi->common;
|
2015-08-06 05:00:31 +03:00
|
|
|
const RATE_CONTROL *const rc = &cpi->rc;
|
|
|
|
CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
|
|
|
|
struct segmentation *const seg = &cm->seg;
|
2016-08-12 06:13:14 +03:00
|
|
|
const int apply_cyclic_refresh = apply_cyclic_refresh_bitrate(cm, rc);
|
|
|
|
if (cm->current_video_frame == 0) cr->low_content_avg = 0.0;
|
2015-08-06 05:00:31 +03:00
|
|
|
// Don't apply refresh on key frame or enhancement layer frames.
|
2015-08-28 01:11:38 +03:00
|
|
|
if (!apply_cyclic_refresh || cm->frame_type == KEY_FRAME) {
|
2015-08-06 05:00:31 +03:00
|
|
|
// Set segmentation map to 0 and disable.
|
|
|
|
unsigned char *const seg_map = cpi->segmentation_map;
|
|
|
|
memset(seg_map, 0, cm->mi_rows * cm->mi_cols);
|
2016-08-31 00:01:10 +03:00
|
|
|
av1_disable_segmentation(&cm->seg);
|
2015-08-06 05:00:31 +03:00
|
|
|
if (cm->frame_type == KEY_FRAME) {
|
|
|
|
memset(cr->last_coded_q_map, MAXQ,
|
|
|
|
cm->mi_rows * cm->mi_cols * sizeof(*cr->last_coded_q_map));
|
|
|
|
cr->sb_index = 0;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
int qindex_delta = 0;
|
|
|
|
int qindex2;
|
2016-08-31 00:01:10 +03:00
|
|
|
const double q = av1_convert_qindex_to_q(cm->base_qindex, cm->bit_depth);
|
|
|
|
aom_clear_system_state();
|
2015-08-06 05:00:31 +03:00
|
|
|
// Set rate threshold to some multiple (set to 2 for now) of the target
|
|
|
|
// rate (target is given by sb64_target_rate and scaled by 256).
|
|
|
|
cr->thresh_rate_sb = ((int64_t)(rc->sb64_target_rate) << 8) << 2;
|
|
|
|
// Distortion threshold, quadratic in Q, scale factor to be adjusted.
|
|
|
|
// q will not exceed 457, so (q * q) is within 32bit; see:
|
2016-08-31 00:01:10 +03:00
|
|
|
// av1_convert_qindex_to_q(), av1_ac_quant(), ac_qlookup*[].
|
2015-08-06 05:00:31 +03:00
|
|
|
cr->thresh_dist_sb = ((int64_t)(q * q)) << 2;
|
|
|
|
|
|
|
|
// Set up segmentation.
|
|
|
|
// Clear down the segment map.
|
2016-08-31 00:01:10 +03:00
|
|
|
av1_enable_segmentation(&cm->seg);
|
|
|
|
av1_clearall_segfeatures(seg);
|
2015-08-06 05:00:31 +03:00
|
|
|
// Select delta coding method.
|
|
|
|
seg->abs_delta = SEGMENT_DELTADATA;
|
|
|
|
|
|
|
|
// Note: setting temporal_update has no effect, as the seg-map coding method
|
2016-08-12 06:13:14 +03:00
|
|
|
// (temporal or spatial) is determined in
|
2016-08-31 00:01:10 +03:00
|
|
|
// av1_choose_segmap_coding_method(),
|
2015-08-06 05:00:31 +03:00
|
|
|
// based on the coding cost of each method. For error_resilient mode on the
|
|
|
|
// last_frame_seg_map is set to 0, so if temporal coding is used, it is
|
|
|
|
// relative to 0 previous map.
|
|
|
|
// seg->temporal_update = 0;
|
|
|
|
|
|
|
|
// Segment BASE "Q" feature is disabled so it defaults to the baseline Q.
|
2016-08-31 00:01:10 +03:00
|
|
|
av1_disable_segfeature(seg, CR_SEGMENT_ID_BASE, SEG_LVL_ALT_Q);
|
2015-08-06 05:00:31 +03:00
|
|
|
// Use segment BOOST1 for in-frame Q adjustment.
|
2016-08-31 00:01:10 +03:00
|
|
|
av1_enable_segfeature(seg, CR_SEGMENT_ID_BOOST1, SEG_LVL_ALT_Q);
|
2015-08-06 05:00:31 +03:00
|
|
|
// Use segment BOOST2 for more aggressive in-frame Q adjustment.
|
2016-08-31 00:01:10 +03:00
|
|
|
av1_enable_segfeature(seg, CR_SEGMENT_ID_BOOST2, SEG_LVL_ALT_Q);
|
2015-08-06 05:00:31 +03:00
|
|
|
|
|
|
|
// Set the q delta for segment BOOST1.
|
|
|
|
qindex_delta = compute_deltaq(cpi, cm->base_qindex, cr->rate_ratio_qdelta);
|
|
|
|
cr->qindex_delta[1] = qindex_delta;
|
|
|
|
|
|
|
|
// Compute rd-mult for segment BOOST1.
|
|
|
|
qindex2 = clamp(cm->base_qindex + cm->y_dc_delta_q + qindex_delta, 0, MAXQ);
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
cr->rdmult = av1_compute_rd_mult(cpi, qindex2);
|
2015-08-06 05:00:31 +03:00
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
av1_set_segdata(seg, CR_SEGMENT_ID_BOOST1, SEG_LVL_ALT_Q, qindex_delta);
|
2015-08-06 05:00:31 +03:00
|
|
|
|
|
|
|
// Set a more aggressive (higher) q delta for segment BOOST2.
|
|
|
|
qindex_delta = compute_deltaq(
|
2015-08-18 04:19:22 +03:00
|
|
|
cpi, cm->base_qindex,
|
2016-08-31 00:01:10 +03:00
|
|
|
AOMMIN(CR_MAX_RATE_TARGET_RATIO,
|
2015-08-18 04:19:22 +03:00
|
|
|
0.1 * cr->rate_boost_fac * cr->rate_ratio_qdelta));
|
2015-08-06 05:00:31 +03:00
|
|
|
cr->qindex_delta[2] = qindex_delta;
|
2016-08-31 00:01:10 +03:00
|
|
|
av1_set_segdata(seg, CR_SEGMENT_ID_BOOST2, SEG_LVL_ALT_Q, qindex_delta);
|
2015-08-06 05:00:31 +03:00
|
|
|
|
|
|
|
// Update the segmentation and refresh map.
|
|
|
|
cyclic_refresh_update_map(cpi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
int av1_cyclic_refresh_get_rdmult(const CYCLIC_REFRESH *cr) {
|
2015-08-06 05:00:31 +03:00
|
|
|
return cr->rdmult;
|
|
|
|
}
|
|
|
|
|
2016-08-31 00:01:10 +03:00
|
|
|
void av1_cyclic_refresh_reset_resize(AV1_COMP *const cpi) {
|
|
|
|
const AV1_COMMON *const cm = &cpi->common;
|
2015-08-06 05:00:31 +03:00
|
|
|
CYCLIC_REFRESH *const cr = cpi->cyclic_refresh;
|
|
|
|
memset(cr->map, 0, cm->mi_rows * cm->mi_cols);
|
|
|
|
cr->sb_index = 0;
|
|
|
|
cpi->refresh_golden_frame = 1;
|
|
|
|
}
|