AOMedia AV1 Codec
High-level Algorithm
Collaboration diagram for High-level Algorithm:

Modules

 Speed vs Quality Trade Off
 
 Source Frame Processing
 
 Rate Control
 
 Temporal Dependency Modelling
 
 Two Pass Mode
 
 The Look-Ahead Buffer
 
 Golden Frame Group
 

Functions

int av1_pack_bitstream (struct AV1_COMP *const cpi, uint8_t *dst, size_t *size, int *const largest_tile_id)
 Pack the bitstream for one frame.
 
int av1_encode_strategy (AV1_COMP *const cpi, size_t *const size, uint8_t *const dest, unsigned int *frame_flags, int64_t *const time_stamp, int64_t *const time_end, const aom_rational64_t *const timestamp_ratio, int *const pop_lookahead, int flush)
 Implement high-level encode strategy. More...
 
static void encode_frame_internal (AV1_COMP *cpi)
 Encoder setup(only for the current frame), encoding, and recontruction for a single frame.
 
void av1_encode_frame (AV1_COMP *cpi)
 Setup reference frame buffers and encode a frame. More...
 
static void cdef_restoration_frame (AV1_COMP *cpi, AV1_COMMON *cm, MACROBLOCKD *xd, int use_restoration, int use_cdef)
 Select and apply cdef filters and switchable restoration filters.
 
static void loopfilter_frame (AV1_COMP *cpi, AV1_COMMON *cm)
 Select and apply in-loop deblocking filters, cdef filters, and restoration filters.
 
static int encode_without_recode (AV1_COMP *cpi)
 Encode a frame without the recode loop, usually used in one-pass encoding and realtime coding. More...
 
static int encode_with_recode_loop (AV1_COMP *cpi, size_t *size, uint8_t *dest)
 Recode loop for encoding one frame. the purpose of encoding one frame for multiple times can be approaching a target bitrate or adjusting the usage of global motions. More...
 
static int encode_with_recode_loop_and_filter (AV1_COMP *cpi, size_t *size, uint8_t *dest, int64_t *sse, int64_t *rate, int *largest_tile_id)
 Recode loop or a single loop for encoding one frame, followed by in-loop deblocking filters, CDEF filters, and restoration filters. More...
 
static int encode_frame_to_data_rate (AV1_COMP *cpi, size_t *size, uint8_t *dest)
 Run the final pass encoding for 1-pass/2-pass encoding mode, and pack the bitstream. More...
 
int av1_receive_raw_frame (AV1_COMP *cpi, aom_enc_frame_flags_t frame_flags, YV12_BUFFER_CONFIG *sd, int64_t time_stamp, int64_t end_time_stamp)
 Obtain the raw frame data. More...
 
int av1_get_compressed_data (AV1_COMP *cpi, AV1_COMP_DATA *const cpi_data)
 Encode a frame. More...
 
int av1_encode (AV1_COMP *const cpi, uint8_t *const dest, const EncodeFrameInput *const frame_input, const EncodeFrameParams *const frame_params, EncodeFrameResults *const frame_results)
 Run 1-pass/2-pass encoding.
 

Detailed Description

This module describes sequence level/frame level algorithm in AV1. More details will be added.

Function Documentation

◆ av1_encode_strategy()

int av1_encode_strategy ( AV1_COMP *const  cpi,
size_t *const  size,
uint8_t *const  dest,
unsigned int *  frame_flags,
int64_t *const  time_stamp,
int64_t *const  time_end,
const aom_rational64_t *const  timestamp_ratio,
int *const  pop_lookahead,
int  flush 
)

Implement high-level encode strategy.

This function will implement high-level encode strategy, choosing frame type, frame placement, etc. It populates an EncodeFrameParams struct with the results of these decisions and then encodes the frame. The caller should use the output parameters *time_stamp and *time_end only when this function returns AOM_CODEC_OK.

Parameters
[in]cpiTop-level encoder structure
[in]sizeBitstream size
[in]destBitstream output
[in]frame_flagsFlags to decide how to encoding the frame
[out]time_stampTime stamp of the frame
[out]time_endTime end
[in]timestamp_ratioTime base
[in]pop_lookaheadDecide to pop the source frame from queue
[in]flushDecide to encode one frame or the rest of frames
Returns
Returns a value to indicate if the encoding is done successfully.
Return values
AOM_CODEC_OK
-1
AOM_CODEC_ERROR

References AOM_CODEC_ERROR, AOM_CODEC_OK, AOM_EFLAG_FORCE_KF, AOM_Q, AOM_RC_FIRST_PASS, AOM_RC_THIRD_PASS, av1_cyclic_refresh_update_parameters(), av1_encode(), av1_get_one_pass_rt_params(), av1_get_second_pass_params(), av1_lookahead_depth(), av1_lookahead_peek(), av1_lookahead_pop_sz(), av1_set_reference_structure_one_pass_rt(), AV1_COMP::common, AV1_COMP::compressor_stage, RateControlCfg::cq_level, AV1Common::cur_frame, AV1Common::current_frame, AV1Common::error, AV1_COMP::ext_flags, AV1Common::film_grain_params, AV1_COMP::film_grain_table, TimeStamps::first_ts_start, AV1Common::frame_presentation_time, EncodeFrameParams::frame_type, AV1_COMP::framerate, AV1_COMP::gf_frame_index, AV1_PRIMARY::gf_group, has_no_stats_stage(), KeyFrameCfg::key_freq_max, AV1EncoderConfig::kf_cfg, AV1_PRIMARY::lookahead, AV1Common::mi_params, RateControlCfg::mode, AV1_PRIMARY::mv_stats, AV1_COMP::mv_stats, AV1_PRIMARY::number_spatial_layers, AV1_PRIMARY::number_temporal_layers, AV1_COMP::orig_source, AV1_COMP::oxcf, AV1_PRIMARY::p_rc, AV1EncoderConfig::pass, AV1_COMP::ppi, TimeStamps::prev_ts_end, AV1Common::quant_params, PRIMARY_RATE_CONTROL::rate_correction_factors, AV1_COMP::rc, AV1EncoderConfig::rc_cfg, ExternalFlags::ref_frame_flags, EncodeFrameParams::ref_frame_flags, AV1Common::ref_frame_map, ExternalFlags::refresh_frame, AV1_COMP::refresh_frame, EncodeFrameParams::refresh_frame, AV1Common::remapped_ref_idx, EncodeFrameParams::remapped_ref_idx, SPEED_FEATURES::rt_sf, AV1_COMP::second_pass_log_stream, AV1Common::seq_params, AV1_COMP::sf, AV1_PRIMARY::show_existing_alt_ref, EncodeFrameParams::show_frame, AV1_COMP::skip_tpl_setup_stats, AV1_COMP::source, EncodeFrameParams::speed, AV1_COMP::svc, AV1_COMP::td, AV1_COMP::time_stamps, AV1_PRIMARY::tpl_data, TplParams::tpl_stats_pool, AV1_PRIMARY::twopass, AV1_COMP::twopass_frame, AV1_COMP::unfiltered_source, ExtRefreshFrameFlagsInfo::update_pending, and CommonQuantParams::using_qmatrix.

Referenced by av1_get_compressed_data().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ av1_encode_frame()

◆ encode_without_recode()

static int encode_without_recode ( AV1_COMP cpi)
static

Encode a frame without the recode loop, usually used in one-pass encoding and realtime coding.

Parameters
[in]cpiTop-level encoder structure
Returns
Returns a value to indicate if the encoding is done successfully.
Return values
AOM_CODEC_OK
AOM_CODEC_ERROR

References AV1_COMP::common, AV1Common::current_frame, SVC::downsample_filter_phase, SVC::downsample_filter_type, RefreshFrameInfo::golden_frame, AV1Common::height, SPEED_FEATURES::inter_sf, AV1_COMP::oxcf, SPEED_FEATURES::part_sf, AV1_COMP::ppi, AV1_COMP::refresh_frame, AV1_COMP::sf, AV1_COMP::svc, AV1_COMP::unscaled_source, AV1_PRIMARY::use_svc, and AV1Common::width.

Referenced by encode_with_recode_loop_and_filter().

◆ encode_with_recode_loop()

static int encode_with_recode_loop ( AV1_COMP cpi,
size_t *  size,
uint8_t *  dest 
)
static

Recode loop for encoding one frame. the purpose of encoding one frame for multiple times can be approaching a target bitrate or adjusting the usage of global motions.

Parameters
[in]cpiTop-level encoder structure
[in]sizeBitstream size
[in]destBitstream output
Returns
Returns a value to indicate if the encoding is done successfully.
Return values
AOM_CODEC_OK
-1
AOM_CODEC_ERROR

References AOM_SUPERRES_NONE, AV1_COMP::common, AV1Common::current_frame, HIGH_LEVEL_SPEED_FEATURES::disable_extra_sc_testing, AV1_COMP::gm_info, SPEED_FEATURES::hl_sf, InterpSearchFlags::interp_filter_search_mask, AV1_COMP::interp_search_flags, SPEED_FEATURES::interp_sf, RateControlCfg::min_cr, AV1_COMP::oxcf, SPEED_FEATURES::part_sf, AV1_COMP::rc, AV1EncoderConfig::rc_cfg, HIGH_LEVEL_SPEED_FEATURES::recode_loop, AV1_COMP::sf, AV1_COMP::source, AV1_COMP::superres_mode, and AV1Common::superres_scale_denominator.

Referenced by encode_with_recode_loop_and_filter().

◆ encode_with_recode_loop_and_filter()

static int encode_with_recode_loop_and_filter ( AV1_COMP cpi,
size_t *  size,
uint8_t *  dest,
int64_t *  sse,
int64_t *  rate,
int *  largest_tile_id 
)
static

◆ encode_frame_to_data_rate()

static int encode_frame_to_data_rate ( AV1_COMP cpi,
size_t *  size,
uint8_t *  dest 
)
static

Run the final pass encoding for 1-pass/2-pass encoding mode, and pack the bitstream.

Parameters
[in]cpiTop-level encoder structure
[in]sizeBitstream size
[in]destBitstream output
Returns
Returns a value to indicate if the encoding is done successfully.
Return values
AOM_CODEC_OK
AOM_CODEC_ERROR

References FeatureFlags::allow_ref_frame_mvs, FeatureFlags::allow_screen_content_tools, FeatureFlags::allow_warped_motion, AOM_CBR, AOM_CODEC_ERROR, AOM_CODEC_OK, AOM_RC_THIRD_PASS, av1_pack_bitstream(), RATE_CONTROL::coefficient_size, AV1_COMP::common, AV1Common::cur_frame, FeatureFlags::cur_frame_force_integer_mv, AV1Common::current_frame, AV1_COMP::existing_fb_idx_to_show, AV1Common::features, AV1_COMP::force_intpel_info, AV1_COMP::frame_index_set, AV1_COMP::gf_frame_index, AV1_PRIMARY::gf_group, has_no_stats_stage(), AV1Common::height, AV1_COMP::is_dropped_frame, CommonTileParams::large_scale, AV1_COMP::last_frame_type, AV1_COMP::last_show_frame_buf, AV1Common::lf, RateControlCfg::mode, AV1_COMP::num_tg, AV1_COMP::oxcf, AV1EncoderConfig::pass, AV1_COMP::ppi, AV1_COMP::rc, AV1EncoderConfig::rc_cfg, AV1Common::ref_frame_id, SPEED_FEATURES::rt_sf, AV1Common::seg, AV1Common::seq_params, AV1_COMP::sf, AV1Common::show_frame, CommonTileParams::single_tile_decoding, AV1_COMP::source, RateControlCfg::target_bandwidth, AV1Common::tiles, AV1_COMP::unscaled_last_source, and AV1Common::width.

Referenced by av1_encode().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ av1_receive_raw_frame()

int av1_receive_raw_frame ( AV1_COMP cpi,
aom_enc_frame_flags_t  frame_flags,
YV12_BUFFER_CONFIG sd,
int64_t  time_stamp,
int64_t  end_time_stamp 
)

Obtain the raw frame data.

This function receives the raw frame data from input.

Parameters
[in]cpiTop-level encoder structure
[in]frame_flagsFlags to decide how to encoding the frame
[in]sdContain raw frame data
[in]time_stampTime stamp of the frame
[in]end_time_stampEnd time stamp
Returns
Returns a value to indicate if the frame data is received successfully.
Note
The caller can assume that a copy of this frame is made and not just a copy of the pointer.

References AV1_COMP::common, AV1_COMP::oxcf, and AV1Common::seq_params.

◆ av1_get_compressed_data()

int av1_get_compressed_data ( AV1_COMP cpi,
AV1_COMP_DATA *const  cpi_data 
)

Encode a frame.

This function encodes the raw frame data, and outputs the frame bit stream to the designated buffer. The caller should use the output parameters cpi_data->ts_frame_start and cpi_data->ts_frame_end only when this function returns AOM_CODEC_OK.

Parameters
[in]cpiTop-level encoder structure
[in,out]cpi_dataData corresponding to a frame encode
Returns
Returns a value to indicate if the encoding is done successfully.
Return values
AOM_CODEC_OK
-1No frame encoded; more input is required.
AOM_CODEC_ERROR

References AOM_CODEC_ERROR, AOM_CODEC_OK, av1_encode_strategy(), av1_one_pass_cbr_svc_start_layer(), AV1_COMP::available_bs_size, CommonQuantParams::base_qindex, AV1_COMP::common, AV1_COMP::compressor_stage, AV1_COMP::counts, AV1Common::current_frame, AV1_COMP_DATA::cx_data, AV1_COMP_DATA::cx_data_sz, AV1Common::error, AV1Common::features, AV1_COMP_DATA::flush, AV1_COMP_DATA::frame_size, AV1_COMP::gf_frame_index, AV1_PRIMARY::gf_group, AV1_COMP::is_dropped_frame, AV1_COMP_DATA::lib_flags, AV1_PRIMARY::number_spatial_layers, AV1_COMP::oxcf, AV1EncoderConfig::pass, AV1_COMP_DATA::pop_lookahead, AV1_COMP::ppi, AV1Common::quant_params, FeatureFlags::refresh_frame_context, AV1Common::seq_params, AV1Common::show_existing_frame, AV1Common::show_frame, AV1Common::showable_frame, AV1_COMP::td, AV1_COMP_DATA::timestamp_ratio, AV1_COMP_DATA::ts_frame_end, AV1_COMP_DATA::ts_frame_start, and AV1_PRIMARY::use_svc.

Here is the call graph for this function: