AOMedia AV1 Codec
encode_strategy.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
15 #ifndef AOM_AV1_ENCODER_ENCODE_STRATEGY_H_
16 #define AOM_AV1_ENCODER_ENCODE_STRATEGY_H_
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #include <stdint.h>
23 
24 #include "aom/aom_encoder.h"
25 
26 #include "av1/encoder/encoder.h"
27 #include "av1/encoder/firstpass.h"
28 
55 int av1_encode_strategy(AV1_COMP *const cpi, size_t *const size,
56  uint8_t *const dest, unsigned int *frame_flags,
57  int64_t *const time_stamp, int64_t *const time_end,
58  const aom_rational64_t *const timestamp_ratio,
59  int *const pop_lookahead, int flush);
60 
62 // Set individual buffer update flags based on frame reference type.
63 // force_refresh_all is used when we have a KEY_FRAME or S_FRAME. It forces all
64 // refresh_*_frame flags to be set, because we refresh all buffers in this case.
65 void av1_configure_buffer_updates(AV1_COMP *const cpi,
66  RefreshFrameInfo *const refresh_frame,
67  const FRAME_UPDATE_TYPE type,
68  const REFBUF_STATE refbuf_state,
69  int force_refresh_all);
70 
71 int av1_get_refresh_frame_flags(
72  const AV1_COMP *const cpi, const EncodeFrameParams *const frame_params,
73  FRAME_UPDATE_TYPE frame_update_type, int gf_index, int cur_disp_order,
74  RefFrameMapPair ref_frame_map_pairs[REF_FRAMES]);
75 
76 int av1_get_refresh_ref_frame_map(int refresh_frame_flags);
77 
88 void av1_get_ref_frames(RefFrameMapPair ref_frame_map_pairs[REF_FRAMES],
89  int cur_frame_disp,
90 #if CONFIG_FRAME_PARALLEL_ENCODE_2
91  const AV1_COMP *cpi, int gf_index,
92  int is_parallel_encode,
93 #endif // CONFIG_FRAME_PARALLEL_ENCODE_2
94  int remapped_ref_idx[REF_FRAMES]);
95 
96 int is_forced_keyframe_pending(struct lookahead_ctx *lookahead,
97  const int up_to_index,
98  const COMPRESSOR_STAGE compressor_stage);
99 
100 static AOM_INLINE int is_frame_droppable(
101  const SVC *const svc,
102  const ExtRefreshFrameFlagsInfo *const ext_refresh_frame_flags) {
103  // Droppable frame is only used by external refresh flags. VoD setting won't
104  // trigger its use case.
105  if (svc->set_ref_frame_config)
106  return svc->non_reference_frame;
107  else if (ext_refresh_frame_flags->update_pending)
108  return !(ext_refresh_frame_flags->alt_ref_frame ||
109  ext_refresh_frame_flags->alt2_ref_frame ||
110  ext_refresh_frame_flags->bwd_ref_frame ||
111  ext_refresh_frame_flags->golden_frame ||
112  ext_refresh_frame_flags->last_frame);
113  else
114  return 0;
115 }
116 
117 static AOM_INLINE int get_current_frame_ref_type(const AV1_COMP *const cpi) {
118  // We choose the reference "type" of this frame from the flags which indicate
119  // which reference frames will be refreshed by it. More than one of these
120  // flags may be set, so the order here implies an order of precedence. This is
121  // just used to choose the primary_ref_frame (as the most recent reference
122  // buffer of the same reference-type as the current frame).
123 
124  switch (cpi->ppi->gf_group.layer_depth[cpi->gf_frame_index]) {
125  case 0: return 0;
126  case 1: return 1;
127  case MAX_ARF_LAYERS:
128  case MAX_ARF_LAYERS + 1: return 4;
129  default: return 7;
130  }
131 }
132 
133 #if CONFIG_FRAME_PARALLEL_ENCODE
134 #if CONFIG_FRAME_PARALLEL_ENCODE_2
135 int av1_calc_refresh_idx_for_intnl_arf(
136  AV1_COMP *cpi, RefFrameMapPair ref_frame_map_pairs[REF_FRAMES],
137  int gf_index);
138 #endif // CONFIG_FRAME_PARALLEL_ENCODE_2
139 #endif // CONFIG_FRAME_PARALLEL_ENCODE
140 
141 #ifdef __cplusplus
142 } // extern "C"
143 #endif
144 
145 #endif // AOM_AV1_ENCODER_ENCODE_STRATEGY_H_
SPEED_FEATURES::rt_sf
REAL_TIME_SPEED_FEATURES rt_sf
Definition: speed_features.h:1597
encoder.h
Declares top-level encoder structures and functions.
FeatureFlags::interp_filter
InterpFilter interp_filter
Definition: av1_common_int.h:407
av1_rc_pick_q_and_bounds
int av1_rc_pick_q_and_bounds(const struct AV1_COMP *cpi, int width, int height, int gf_index, int *bottom_index, int *top_index)
Picks q and q bounds given the rate control parameters in cpi->rc.
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.
ExtRefreshFrameFlagsInfo::alt_ref_frame
bool alt_ref_frame
Definition: encoder.h:2134
AOM_RC_SECOND_PASS
@ AOM_RC_SECOND_PASS
Definition: aom_encoder.h:178
AV1_COMP::ext_flags
ExternalFlags ext_flags
Definition: encoder.h:2813
EncodeFrameParams::ref_frame_flags
int ref_frame_flags
Definition: encoder.h:3386
GF_GROUP
Data related to the current GF/ARF group and the individual frames within the group.
Definition: firstpass.h:344
av1_check_show_filtered_frame
int av1_check_show_filtered_frame(const YV12_BUFFER_CONFIG *frame, const FRAME_DIFF *frame_diff, int q_index, aom_bit_depth_t bit_depth)
Check whether a filtered frame can be show directly.
av1_get_second_pass_params
void av1_get_second_pass_params(struct AV1_COMP *cpi, struct EncodeFrameParams *const frame_params, unsigned int frame_flags)
Main per frame entry point for second pass of two pass encode.
Definition: pass2_strategy.c:3622
AOM_EFLAG_SET_S_FRAME
#define AOM_EFLAG_SET_S_FRAME
Enable s frame mode.
Definition: aomcx.h:159
ExternalFlags::use_error_resilient
bool use_error_resilient
Definition: encoder.h:2174
ExternalFlags::refresh_frame
ExtRefreshFrameFlagsInfo refresh_frame
Definition: encoder.h:2153
RefreshFrameInfo::alt_ref_frame
bool alt_ref_frame
Definition: encoder.h:2028
av1_set_reference_structure_one_pass_rt
void av1_set_reference_structure_one_pass_rt(AV1_COMP *cpi, int gf_update)
Setup the reference prediction structure for 1 pass real-time.
Definition: ratectrl.c:2587
FeatureFlags::error_resilient_mode
bool error_resilient_mode
Definition: av1_common_int.h:400
AlgoCfg::enable_tpl_model
bool enable_tpl_model
Definition: encoder.h:848
av1_gop_is_second_arf
int av1_gop_is_second_arf(const GF_GROUP *gf_group, int gf_frame_index)
Check whether a frame in the GOP is the second arf.
AV1Common::tiles
CommonTileParams tiles
Definition: av1_common_int.h:992
AV1_PRIMARY::twopass
TWO_PASS twopass
Definition: encoder.h:2525
AV1_COMP::sf
SPEED_FEATURES sf
Definition: encoder.h:2881
AV1_PRIMARY::number_spatial_layers
unsigned int number_spatial_layers
Definition: encoder.h:2560
ExternalFlags::use_s_frame
bool use_s_frame
Definition: encoder.h:2179
AV1_COMP::td
ThreadData td
Definition: encoder.h:2679
AV1_COMP::gf_frame_index
unsigned char gf_frame_index
Definition: encoder.h:2912
AV1_COMP::compressor_stage
COMPRESSOR_STAGE compressor_stage
Definition: encoder.h:3168
ExternalFlags::use_primary_ref_none
bool use_primary_ref_none
Definition: encoder.h:2185
ExtRefreshFrameFlagsInfo::golden_frame
bool golden_frame
Definition: encoder.h:2131
ExternalFlags::ref_frame_flags
int ref_frame_flags
Definition: encoder.h:2148
ExtRefreshFrameFlagsInfo::alt2_ref_frame
bool alt2_ref_frame
Definition: encoder.h:2133
AV1Common::error
struct aom_internal_error_info * error
Definition: av1_common_int.h:758
AV1_PRIMARY::gf_group
GF_GROUP gf_group
Definition: encoder.h:2495
AOM_CODEC_OK
@ AOM_CODEC_OK
Operation completed without error.
Definition: aom_codec.h:157
AV1EncoderConfig::kf_cfg
KeyFrameCfg kf_cfg
Definition: encoder.h:926
FeatureFlags::allow_ref_frame_mvs
bool allow_ref_frame_mvs
Definition: av1_common_int.h:381
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.
Definition: encode_strategy.c:1166
av1_temporal_filter
void av1_temporal_filter(struct AV1_COMP *cpi, const int filter_frame_lookahead_idx, int gf_frame_index, FRAME_DIFF *frame_diff, YV12_BUFFER_CONFIG *output_frame)
Performs temporal filtering if needed on a source frame. For example to create a filtered alternate r...
TplParams
Params related to temporal dependency model.
Definition: tpl_model.h:142
AOM_EFLAG_FORCE_KF
#define AOM_EFLAG_FORCE_KF
Force this frame to be a keyframe.
Definition: aom_encoder.h:378
aom_codec.h
Describes the codec algorithm interface to applications.
AV1_COMP::twopass_frame
TWO_PASS_FRAME twopass_frame
Definition: encoder.h:3323
AV1EncoderConfig
Main encoder configuration data structure.
Definition: encoder.h:909
AOM_RC_FIRST_PASS
@ AOM_RC_FIRST_PASS
Definition: aom_encoder.h:177
AV1Common::cur_frame
RefCntBuffer * cur_frame
Definition: av1_common_int.h:832
AV1_PRIMARY::number_temporal_layers
unsigned int number_temporal_layers
Definition: encoder.h:2555
ExternalFlags::refresh_frame_context
bool refresh_frame_context
Definition: encoder.h:2158
AOM_CODEC_ERROR
@ AOM_CODEC_ERROR
Unspecified error.
Definition: aom_codec.h:160
AV1_COMP
Top level encoder structure.
Definition: encoder.h:2664
EncodeFrameParams::remapped_ref_idx
int remapped_ref_idx[REF_FRAMES]
Definition: encoder.h:3391
TimeStamps
Frame time stamps.
Definition: encoder.h:2280
AV1Common::height
int height
Definition: av1_common_int.h:776
AV1_COMP::droppable
int droppable
Definition: encoder.h:2935
AV1_PRIMARY::tpl_data
TplParams tpl_data
Definition: encoder.h:2583
SVC
The stucture of SVC.
Definition: svc_layercontext.h:87
AV1_COMP::unscaled_source
YV12_BUFFER_CONFIG * unscaled_source
Definition: encoder.h:2740
av1_encode
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.
Definition: encoder.c:3678
TimeStamps::prev_ts_end
int64_t prev_ts_end
Definition: encoder.h:2288
AOM_EFLAG_ERROR_RESILIENT
#define AOM_EFLAG_ERROR_RESILIENT
Enable error resilient frame.
Definition: aomcx.h:153
RateControlCfg::mode
enum aom_rc_mode mode
Definition: encoder.h:604
EncodeFrameParams::frame_type
FRAME_TYPE frame_type
Definition: encoder.h:3364
RefreshFrameInfo
Refresh frame flags for different type of frames.
Definition: encoder.h:2025
AV1_PRIMARY::tf_info
TEMPORAL_FILTER_INFO tf_info
Definition: encoder.h:2535
AV1Common::seq_params
SequenceHeader * seq_params
Definition: av1_common_int.h:976
AV1_PRIMARY::lookahead
struct lookahead_ctx * lookahead
Definition: encoder.h:2467
AV1_PRIMARY::mv_stats
MV_STATS mv_stats
Definition: encoder.h:2588
TplParams::tpl_stats_pool
TplDepStats * tpl_stats_pool[MAX_LAG_BUFFERS]
Definition: tpl_model.h:170
AV1_COMP::common
AV1_COMMON common
Definition: encoder.h:2707
EncodeFrameParams::error_resilient_mode
int error_resilient_mode
Definition: encoder.h:3360
FeatureFlags::refresh_frame_context
REFRESH_FRAME_CONTEXT_MODE refresh_frame_context
Definition: av1_common_int.h:421
AV1Common::superres_upscaled_width
int superres_upscaled_width
Definition: av1_common_int.h:799
RateControlCfg::cq_level
int cq_level
Definition: encoder.h:599
ExtRefreshFrameFlagsInfo::last_frame
bool last_frame
Definition: encoder.h:2130
RefreshFrameInfo::golden_frame
bool golden_frame
Definition: encoder.h:2026
CommonQuantParams::using_qmatrix
bool using_qmatrix
Definition: av1_common_int.h:696
encode_strategy.h
Declares frame encoding functions.
av1_tpl_setup_stats
int av1_tpl_setup_stats(struct AV1_COMP *cpi, int gop_eval, const struct EncodeFrameParams *const frame_params)
Implements temporal dependency modelling for a GOP (GF/ARF group) and selects between 16 and 32 frame...
AV1Common::film_grain_params
aom_film_grain_t film_grain_params
Definition: av1_common_int.h:960
AV1Common::frame_presentation_time
uint32_t frame_presentation_time
Definition: av1_common_int.h:821
av1_get_one_pass_rt_params
void av1_get_one_pass_rt_params(AV1_COMP *cpi, EncodeFrameParams *const frame_params, unsigned int frame_flags)
Setup the rate control parameters for 1 pass real-time mode.
Definition: ratectrl.c:3021
AV1_COMP::film_grain_table
aom_film_grain_table_t * film_grain_table
Definition: encoder.h:3069
av1_lookahead_pop_sz
int av1_lookahead_pop_sz(struct lookahead_ctx *ctx, COMPRESSOR_STAGE stage)
Get pop_sz value.
has_no_stats_stage
static int has_no_stats_stage(const AV1_COMP *const cpi)
Check if the current stage has statistics.
Definition: encoder.h:3761
AOM_CODEC_MEM_ERROR
@ AOM_CODEC_MEM_ERROR
Memory operation failed.
Definition: aom_codec.h:163
AV1EncoderConfig::pass
enum aom_enc_pass pass
Definition: encoder.h:1034
AV1_PRIMARY::p_rc
PRIMARY_RATE_CONTROL p_rc
Definition: encoder.h:2530
AV1_COMP::second_pass_log_stream
FILE * second_pass_log_stream
Definition: encoder.h:3333
EncodeFrameParams::speed
int speed
Definition: encoder.h:3402
AV1Common::show_frame
int show_frame
Definition: av1_common_int.h:885
SPEED_FEATURES::hl_sf
HIGH_LEVEL_SPEED_FEATURES hl_sf
Definition: speed_features.h:1532
CommonTileParams::large_scale
unsigned int large_scale
Definition: av1_common_int.h:488
AV1_PRIMARY::show_existing_alt_ref
int show_existing_alt_ref
Definition: encoder.h:2490
TimeStamps::prev_ts_start
int64_t prev_ts_start
Definition: encoder.h:2284
SPEED_FEATURES::tpl_sf
TPL_SPEED_FEATURES tpl_sf
Definition: speed_features.h:1542
AV1Common::quant_params
CommonQuantParams quant_params
Definition: av1_common_int.h:922
AV1_PRIMARY::use_svc
int use_svc
Definition: encoder.h:2545
yv12_buffer_config
YV12 frame buffer data structure.
Definition: yv12config.h:39
AV1_COMP::orig_source
YV12_BUFFER_CONFIG orig_source
Definition: encoder.h:2767
AV1_COMP::time_stamps
TimeStamps time_stamps
Definition: encoder.h:2856
aom_encoder.h
Describes the encoder algorithm interface to applications.
ExternalFlags
Flags signalled by the external interface at frame level.
Definition: encoder.h:2144
AV1_COMP::rc
RATE_CONTROL rc
Definition: encoder.h:2861
AV1Common
Top level common structure used by both encoder and decoder.
Definition: av1_common_int.h:750
ExternalFlags::use_ref_frame_mvs
bool use_ref_frame_mvs
Definition: encoder.h:2169
AV1_COMP::new_framerate
double new_framerate
Definition: encoder.h:3032
AV1_COMP::unfiltered_source
YV12_BUFFER_CONFIG * unfiltered_source
Definition: encoder.h:2761
av1_svc_primary_ref_frame
int av1_svc_primary_ref_frame(const struct AV1_COMP *const cpi)
Get primary reference frame for current layer.
AOM_Q
@ AOM_Q
Definition: aom_encoder.h:188
AV1EncoderConfig::algo_cfg
AlgoCfg algo_cfg
Definition: encoder.h:921
AV1_COMP::scaled_source
YV12_BUFFER_CONFIG scaled_source
Definition: encoder.h:2745
RefreshFrameInfo::bwd_ref_frame
bool bwd_ref_frame
Definition: encoder.h:2027
AV1_COMP::refresh_frame
RefreshFrameInfo refresh_frame
Definition: encoder.h:2808
EncodeFrameInput
Input frames and last input frame.
Definition: encoder.h:3344
AV1_COMP::mv_stats
MV_STATS mv_stats
Definition: encoder.h:3237
AV1_COMP::skip_tpl_setup_stats
int skip_tpl_setup_stats
Definition: encoder.h:2772
AV1_COMP::framerate
double framerate
Definition: encoder.h:2866
av1_lookahead_peek
struct lookahead_entry * av1_lookahead_peek(struct lookahead_ctx *ctx, int index, COMPRESSOR_STAGE stage)
Get a future source buffer to encode.
EncodeFrameParams
contains per-frame encoding parameters decided upon by av1_encode_strategy() and passed down to av1_e...
Definition: encoder.h:3356
HIGH_LEVEL_SPEED_FEATURES::second_alt_ref_filtering
int second_alt_ref_filtering
Definition: speed_features.h:431
AV1Common::ref_frame_map
RefCntBuffer * ref_frame_map[REF_FRAMES]
Definition: av1_common_int.h:878
AV1_COMP::ppi
AV1_PRIMARY * ppi
Definition: encoder.h:2668
TEMPORAL_FILTER_INFO::tf_buf_second_arf
YV12_BUFFER_CONFIG tf_buf_second_arf
Definition: temporal_filter.h:175
macroblockd
Variables related to current coding block.
Definition: blockd.h:577
KeyFrameCfg::enable_keyframe_filtering
int enable_keyframe_filtering
Definition: encoder.h:476
AV1Common::superres_upscaled_height
int superres_upscaled_height
Definition: av1_common_int.h:800
ExternalFlags::refresh_frame_context_pending
bool refresh_frame_context_pending
Definition: encoder.h:2164
macroblock::e_mbd
MACROBLOCKD e_mbd
Decoder's view of current coding block.
Definition: block.h:831
ExtRefreshFrameFlagsInfo::bwd_ref_frame
bool bwd_ref_frame
Definition: encoder.h:2132
av1_lookahead_depth
unsigned int av1_lookahead_depth(struct lookahead_ctx *ctx, COMPRESSOR_STAGE stage)
Get the number of frames currently in the lookahead queue.
KeyFrameCfg::enable_sframe
bool enable_sframe
Definition: encoder.h:509
AV1_PRIMARY::fb_of_context_type
int fb_of_context_type[REF_FRAMES]
Definition: encoder.h:2640
AV1Common::width
int width
Definition: av1_common_int.h:775
AV1_COMP::oxcf
AV1EncoderConfig oxcf
Definition: encoder.h:2712
EncodeFrameParams::refresh_frame
RefreshFrameInfo refresh_frame
Definition: encoder.h:3397
TimeStamps::first_ts_start
int64_t first_ts_start
Definition: encoder.h:2292
ExtRefreshFrameFlagsInfo
Frame refresh flags set by the external interface.
Definition: encoder.h:2129
AV1EncoderConfig::rc_cfg
RateControlCfg rc_cfg
Definition: encoder.h:931
PRIMARY_RATE_CONTROL::rate_correction_factors
double rate_correction_factors[RATE_FACTOR_LEVELS]
Definition: ratectrl.h:485
ExtRefreshFrameFlagsInfo::update_pending
bool update_pending
Definition: encoder.h:2138
AV1Common::showable_frame
int showable_frame
Definition: av1_common_int.h:893
AV1Common::current_frame
CurrentFrame current_frame
Definition: av1_common_int.h:754
AV1Common::features
FeatureFlags features
Definition: av1_common_int.h:905
AV1_COMP::source
YV12_BUFFER_CONFIG * source
Definition: encoder.h:2725
AV1Common::mi_params
CommonModeInfoParams mi_params
Definition: av1_common_int.h:910
EncodeFrameParams::show_frame
int show_frame
Definition: encoder.h:3374
macroblock
Encoder's parameters related to the current coding block.
Definition: block.h:813
AV1Common::remapped_ref_idx
int remapped_ref_idx[REF_FRAMES]
Definition: av1_common_int.h:854
RATE_CONTROL::frames_to_key
int frames_to_key
Definition: ratectrl.h:185
KeyFrameCfg::key_freq_max
int key_freq_max
Definition: encoder.h:471
AOM_RC_THIRD_PASS
@ AOM_RC_THIRD_PASS
Definition: aom_encoder.h:179
AV1_COMP::svc
SVC svc
Definition: encoder.h:3163