AOMedia AV1 Codec: Cyclic Refresh

| AOMedia AV1 Codec

Cyclic Refresh
Encoder Algorithm

## Data Structures
struct | CYCLIC_REFRESH
| The stucture of CYCLIC_REFRESH. More...

## Functions
int | av1_cyclic_refresh_estimate_bits_at_q (const struct AV1_COMP *cpi, double correction_factor)
| Estimate the bits, incorporating the delta-q from the segments.
int | av1_cyclic_refresh_rc_bits_per_mb (const struct AV1_COMP *cpi, int i, double correction_factor)
| Estimate the bits per mb, for given q = i and delta-q.
void | av1_cyclic_reset_segment_skip (const struct AV1_COMP *cpi, MACROBLOCK *const x, int mi_row, int mi_col, BLOCK_SIZE bsize, RUN_TYPE dry_run)
| Update segment_id for blocks are skipped.
void | av1_cyclic_refresh_update_segment (const struct AV1_COMP *cpi, MACROBLOCK *const x, int mi_row, int mi_col, BLOCK_SIZE bsize, int64_t rate, int64_t dist, int skip, RUN_TYPE dry_run)
| Update segment_id for block based on mode selected.
void | av1_init_cyclic_refresh_counters (MACROBLOCK *const x)
| Initialize counters used for cyclic refresh.
void | av1_accumulate_cyclic_refresh_counters (CYCLIC_REFRESH *const cyclic_refresh, const MACROBLOCK *const x)
| Accumulate cyclic refresh counters.
void | av1_cyclic_refresh_set_golden_update (struct AV1_COMP *const cpi)
| Set golden frame update interval nased on cyclic refresh.
void | av1_cyclic_refresh_update_parameters (struct AV1_COMP *const cpi)
| Set the global/frame level parameters for cyclic refresh.
void | av1_cyclic_refresh_setup (struct AV1_COMP *const cpi)
| Setup the cyclic background refresh.

## Detailed Description

This module describes the cyclic refresh (aq-mode=3) in AV1. More details will be added.

## Function Documentation

## ◆ av1_cyclic_refresh_estimate_bits_at_q()

int av1_cyclic_refresh_estimate_bits_at_q | ( | const struct AV1_COMP * | cpi,
|  | double | correction_factor )

Estimate the bits, incorporating the delta-q from the segments.

For the just encoded frame, estimate the bits, incorporating the delta-q from non-base segment(s). Note this function is called in the postencode (called from rc_update_rate_correction_factors()).

Parameters

  [in] | cpi | Top level encoder structure
  [in] | correction_factor | rate correction factor

Returns
  Return the estimated bits at given q.

Referenced by av1_rc_update_rate_correction_factors().

## ◆ av1_cyclic_refresh_rc_bits_per_mb()

int av1_cyclic_refresh_rc_bits_per_mb | ( | const struct AV1_COMP * | cpi,
|  | int | i,
|  | double | correction_factor )

Estimate the bits per mb, for given q = i and delta-q.

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.

Parameters

  [in] | cpi | Top level encoder structure
  [in] | i | q index
  [in] | correction_factor | rate correction factor

Returns
  Return the estimated bits for q = i and delta-q (segment 1).

## ◆ av1_cyclic_reset_segment_skip()

void av1_cyclic_reset_segment_skip | ( | const struct AV1_COMP * | cpi,
|  | MACROBLOCK *const | x,
|  | int | mi_row,
|  | int | mi_col,
|  | BLOCK_SIZE | bsize,
|  | RUN_TYPE | dry_run )

Update segment_id for blocks are skipped.

After encoding a given prediction block, of size bsize at (mi_row, mi_col), check if we should reset the segment_id based on skip_txfm, and update the cyclic_refresh map and segmentation counters.

Parameters

  [in] | cpi | Top level encoder structure
  [in] | x | Pointer to MACROBLOCK structure
  [in] | mi_row | Row coordinate of the block in a step size of MI_SIZE
  [in] | mi_col | Col coordinate of the block in a step size of MI_SIZE
  [in] | bsize | Block size
  [in] | dry_run | A code indicating whether it is part of the final pass for reconstructing the superblock

Remarks
  Update the `mbmi->segment_id`, the `cpi->cyclic_refresh` and the `cm->cpi->enc_seg.map`.

## ◆ av1_cyclic_refresh_update_segment()

void av1_cyclic_refresh_update_segment | ( | const struct AV1_COMP * | cpi,
|  | MACROBLOCK *const | x,
|  | int | mi_row,
|  | int | mi_col,
|  | BLOCK_SIZE | bsize,
|  | int64_t | rate,
|  | int64_t | dist,
|  | int | skip,
|  | RUN_TYPE | dry_run )

Update segment_id for block based on mode selected.

Prior to coding a given prediction block, of size bsize at (mi_row, mi_col), check if we should reset the segment_id (based on mode/motion/skip selected for that block) and update the cyclic_refresh map and segmentation map.

Parameters

  [in] | cpi | Top level encoder structure
  [in] | x | Pointer to MACROBLOCK structure
  [in] | mi_row | Row coordinate of the block in a step size of MI_SIZE
  [in] | mi_col | Col coordinate of the block in a step size of MI_SIZE
  [in] | bsize | Block size
  [in] | rate | Projected block rate from pickmode
  [in] | dist | Projected block dist from pickmode
  [in] | skip | Skip flag set from picmode
  [in] | dry_run | A code indicating whether it is part of the final pass for reconstructing the superblock

Remarks
  Update the `mbmi->segment_id`, the `cpi->cyclic_refresh` and the `cm->cpi->enc_seg.map`.

## ◆ av1_init_cyclic_refresh_counters()

void av1_init_cyclic_refresh_counters | ( | MACROBLOCK *const | x | ) |

Initialize counters used for cyclic refresh.

Initializes cyclic refresh counters actual_num_seg1_blocks and actual_num_seg2_blocks.

Parameters

  [in] | x | Pointer to MACROBLOCK structure

Remarks
  Update the `x->actual_num_seg1_blocks` and the `x->actual_num_seg2_blocks`.

## ◆ av1_accumulate_cyclic_refresh_counters()

void av1_accumulate_cyclic_refresh_counters | ( | CYCLIC_REFRESH *const | cyclic_refresh,
|  | const MACROBLOCK *const | x )

Accumulate cyclic refresh counters.

Accumulates cyclic refresh counters actual_num_seg1_blocks and actual_num_seg2_blocks from MACROBLOCK strcture to CYCLIC_REFRESH strcture.

Parameters

  [in] | Cyclic Refresh | Pointer to CYCLIC_REFRESH structure
  [in] | x | Pointer to MACROBLOCK structure

Remarks
  Update the `cyclic_refresh->actual_num_seg1_blocks` and the `cyclic_refresh->actual_num_seg2_blocks`.

## ◆ av1_cyclic_refresh_set_golden_update()

void av1_cyclic_refresh_set_golden_update | ( | struct AV1_COMP *const | cpi | ) |

Set golden frame update interval nased on cyclic refresh.

Parameters

  [in] | cpi | Top level encoder structure

Remarks
  Returns the interval in `cpi->rc.baseline_gf_interval`.

## ◆ av1_cyclic_refresh_update_parameters()

void av1_cyclic_refresh_update_parameters | ( | struct AV1_COMP *const | cpi | ) |

Set the global/frame level parameters for cyclic refresh.

First call to the cyclic refresh, before encoding the frame. Sets the flag on whether cyclic refresh should be applied, sets the amount/percent of refresh, and the amount of boost applied to the two segments (set by rate_ratio_qdelta and rate_boost_fac).

Parameters

  [in] | cpi | Top level encoder structure

Remarks
  Updates the `cpi->cyclic_refresh` with the settings.

Referenced by av1_encode_strategy().

## ◆ av1_cyclic_refresh_setup()

void av1_cyclic_refresh_setup | ( | struct AV1_COMP *const | cpi | ) |

Setup the cyclic background refresh.

Set the delta q for the segment(s), and set the segmentation map.

Parameters

  [in] | cpi | Top level encoder structure

Remarks
  Updates the `cpi->cyclic_refresh` with the cyclic refresh parameters and the `cm->seg` with the segmentation data.

Referenced by encode_without_recode().