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 
54 int av1_encode_strategy(AV1_COMP *const cpi, size_t *const size,
55  uint8_t *const dest, unsigned int *frame_flags,
56  int64_t *const time_stamp, int64_t *const time_end,
57  const aom_rational64_t *const timestamp_ratio,
58  int flush);
59 
61 // Set individual buffer update flags based on frame reference type.
62 // force_refresh_all is used when we have a KEY_FRAME or S_FRAME. It forces all
63 // refresh_*_frame flags to be set, because we refresh all buffers in this case.
64 void av1_configure_buffer_updates(
65  AV1_COMP *const cpi, RefreshFrameFlagsInfo *const refresh_frame_flags,
66  const FRAME_UPDATE_TYPE type, const FRAME_TYPE frame_type,
67  int force_refresh_all);
68 
69 int av1_get_refresh_frame_flags(const AV1_COMP *const cpi,
70  const EncodeFrameParams *const frame_params,
71  FRAME_UPDATE_TYPE frame_update_type,
72  const RefBufferStack *const ref_buffer_stack);
73 
74 int av1_get_refresh_ref_frame_map(int refresh_frame_flags);
75 
76 void av1_update_ref_frame_map(AV1_COMP *cpi,
77  FRAME_UPDATE_TYPE frame_update_type,
78  FRAME_TYPE frame_type, int show_existing_frame,
79  int ref_map_index,
80  RefBufferStack *ref_buffer_stack);
81 
82 void av1_get_ref_frames(AV1_COMP *const cpi, RefBufferStack *ref_buffer_stack);
83 
84 int is_forced_keyframe_pending(struct lookahead_ctx *lookahead,
85  const int up_to_index,
86  const COMPRESSOR_STAGE compressor_stage);
88 #ifdef __cplusplus
89 } // extern "C"
90 #endif
91 
92 #endif // AOM_AV1_ENCODER_ENCODE_STRATEGY_H_
SPEED_FEATURES::rt_sf
REAL_TIME_SPEED_FEATURES rt_sf
Definition: speed_features.h:1184
encoder.h
Declares top-level encoder structures and functions.
FeatureFlags::interp_filter
InterpFilter interp_filter
Definition: av1_common_int.h:383
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:1876
AV1_COMP::ext_flags
ExternalFlags ext_flags
Definition: encoder.h:2246
EncodeFrameParams::ref_frame_flags
int ref_frame_flags
Definition: encoder.h:2756
AV1Common::number_spatial_layers
unsigned int number_spatial_layers
Definition: av1_common_int.h:1029
AV1Common::number_temporal_layers
unsigned int number_temporal_layers
Definition: av1_common_int.h:1019
GF_GROUP
Data related to the current GF/ARF group and the individual frames within the group.
Definition: firstpass.h:171
RefreshFrameFlagsInfo
Refresh frame flags for different type of frames.
Definition: encoder.h:1767
AOM_EFLAG_SET_S_FRAME
#define AOM_EFLAG_SET_S_FRAME
Enable s frame mode.
Definition: aomcx.h:158
ExternalFlags::use_error_resilient
bool use_error_resilient
Definition: encoder.h:1916
ExternalFlags::refresh_frame
ExtRefreshFrameFlagsInfo refresh_frame
Definition: encoder.h:1895
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:2171
FeatureFlags::error_resilient_mode
bool error_resilient_mode
Definition: av1_common_int.h:376
AlgoCfg::enable_tpl_model
bool enable_tpl_model
Definition: encoder.h:753
AV1Common::tiles
CommonTileParams tiles
Definition: av1_common_int.h:969
AV1_COMP::use_svc
int use_svc
Definition: encoder.h:2632
AV1_COMP::sf
SPEED_FEATURES sf
Definition: encoder.h:2314
ExternalFlags::use_s_frame
bool use_s_frame
Definition: encoder.h:1921
AV1_COMP::td
ThreadData td
Definition: encoder.h:2110
AV1_COMP::gf_frame_index
unsigned char gf_frame_index
Definition: encoder.h:2362
av1_lookahead_pop
struct lookahead_entry * av1_lookahead_pop(struct lookahead_ctx *ctx, int drain, COMPRESSOR_STAGE stage)
Get the next source buffer to encode.
KeyFrameCfg::fwd_kf_enabled
bool fwd_kf_enabled
Definition: encoder.h:414
AV1_COMP::compressor_stage
COMPRESSOR_STAGE compressor_stage
Definition: encoder.h:2645
ExternalFlags::use_primary_ref_none
bool use_primary_ref_none
Definition: encoder.h:1927
AlgoCfg::arnr_max_frames
int arnr_max_frames
Definition: encoder.h:735
ExtRefreshFrameFlagsInfo::golden_frame
bool golden_frame
Definition: encoder.h:1873
ExternalFlags::ref_frame_flags
int ref_frame_flags
Definition: encoder.h:1890
ExtRefreshFrameFlagsInfo::alt2_ref_frame
bool alt2_ref_frame
Definition: encoder.h:1875
AV1_COMP::twopass
TWO_PASS twopass
Definition: encoder.h:2352
AOM_CODEC_OK
@ AOM_CODEC_OK
Operation completed without error.
Definition: aom_codec.h:157
AV1EncoderConfig::kf_cfg
KeyFrameCfg kf_cfg
Definition: encoder.h:822
FeatureFlags::allow_ref_frame_mvs
bool allow_ref_frame_mvs
Definition: av1_common_int.h:357
RefreshFrameFlagsInfo::golden_frame
bool golden_frame
Definition: encoder.h:1768
AOM_EFLAG_FORCE_KF
#define AOM_EFLAG_FORCE_KF
Force this frame to be a keyframe.
Definition: aom_encoder.h:359
aom_codec.h
Describes the codec algorithm interface to applications.
AV1EncoderConfig
Main encoder configuration data structure.
Definition: encoder.h:805
AV1_COMP::fb_of_context_type
int fb_of_context_type[REF_FRAMES]
Definition: encoder.h:2241
AV1Common::cur_frame
RefCntBuffer * cur_frame
Definition: av1_common_int.h:809
ExternalFlags::refresh_frame_context
bool refresh_frame_context
Definition: encoder.h:1900
AOM_CODEC_ERROR
@ AOM_CODEC_ERROR
Unspecified error.
Definition: aom_codec.h:160
AV1_COMP::gf_group
GF_GROUP gf_group
Definition: encoder.h:2357
AV1_COMP
Top level encoder structure.
Definition: encoder.h:2095
EncodeFrameParams::remapped_ref_idx
int remapped_ref_idx[REF_FRAMES]
Definition: encoder.h:2761
TimeStamps
Frame time stamps.
Definition: encoder.h:2020
AV1Common::height
int height
Definition: av1_common_int.h:749
AV1_COMP::droppable
int droppable
Definition: encoder.h:2438
SVC
The stucture of SVC.
Definition: svc_layercontext.h:91
av1_get_second_pass_params
void av1_get_second_pass_params(struct AV1_COMP *cpi, struct EncodeFrameParams *const frame_params, const EncodeFrameInput *const frame_input, unsigned int frame_flags)
Main per frame entry point for second pass of two pass encode.
Definition: pass2_strategy.c:3505
AV1_COMP::unscaled_source
YV12_BUFFER_CONFIG * unscaled_source
Definition: encoder.h:2176
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:3389
TimeStamps::prev_ts_end
int64_t prev_ts_end
Definition: encoder.h:2028
AOM_EFLAG_ERROR_RESILIENT
#define AOM_EFLAG_ERROR_RESILIENT
Enable error resilient frame.
Definition: aomcx.h:152
RateControlCfg::mode
enum aom_rc_mode mode
Definition: encoder.h:514
EncodeFrameParams::frame_type
FRAME_TYPE frame_type
Definition: encoder.h:2734
AV1_PRIMARY::lookahead
struct lookahead_ctx * lookahead
Definition: encoder.h:2071
AV1_COMP::common
AV1_COMMON common
Definition: encoder.h:2138
EncodeFrameParams::error_resilient_mode
int error_resilient_mode
Definition: encoder.h:2730
FeatureFlags::refresh_frame_context
REFRESH_FRAME_CONTEXT_MODE refresh_frame_context
Definition: av1_common_int.h:397
AV1Common::superres_upscaled_width
int superres_upscaled_width
Definition: av1_common_int.h:772
AV1_COMP::tpl_data
TplParams tpl_data
Definition: encoder.h:2202
ExtRefreshFrameFlagsInfo::last_frame
bool last_frame
Definition: encoder.h:1872
AV1Common::show_existing_frame
int show_existing_frame
Definition: av1_common_int.h:877
CommonQuantParams::using_qmatrix
bool using_qmatrix
Definition: av1_common_int.h:669
encode_strategy.h
Declares frame encoding functions.
av1_twopass_postencode_update
void av1_twopass_postencode_update(struct AV1_COMP *cpi)
Adjustments to two pass and rate control after each frame.
Definition: pass2_strategy.c:3865
AV1Common::film_grain_params
aom_film_grain_t film_grain_params
Definition: av1_common_int.h:937
RATE_CONTROL::frames_till_gf_update_due
int frames_till_gf_update_due
Definition: ratectrl.h:189
AV1Common::frame_presentation_time
uint32_t frame_presentation_time
Definition: av1_common_int.h:798
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:2551
AV1_COMP::film_grain_table
aom_film_grain_table_t * film_grain_table
Definition: encoder.h:2528
av1_lookahead_pop_sz
int av1_lookahead_pop_sz(struct lookahead_ctx *ctx, COMPRESSOR_STAGE stage)
Get pop_sz value.
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 flush)
Implement high-level encode strategy.
Definition: encode_strategy.c:1085
RefreshFrameFlagsInfo::bwd_ref_frame
bool bwd_ref_frame
Definition: encoder.h:1769
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:3053
AV1_COMP::refresh_frame
RefreshFrameFlagsInfo refresh_frame
Definition: encoder.h:2233
av1_tpl_setup_stats
int av1_tpl_setup_stats(struct AV1_COMP *cpi, int gop_eval, const struct EncodeFrameParams *const frame_params, const struct EncodeFrameInput *const frame_input)
Implements temporal dependency modelling for a GOP (GF/ARF group) and selects between 16 and 32 frame...
AV1_COMP::ref_buffer_stack
RefBufferStack ref_buffer_stack
Definition: encoder.h:2372
AOM_CODEC_MEM_ERROR
@ AOM_CODEC_MEM_ERROR
Memory operation failed.
Definition: aom_codec.h:163
AV1_COMP::alt_ref_buffer
YV12_BUFFER_CONFIG alt_ref_buffer
Definition: encoder.h:2378
AV1EncoderConfig::pass
enum aom_enc_pass pass
Definition: encoder.h:930
AV1_COMP::show_existing_alt_ref
int show_existing_alt_ref
Definition: encoder.h:2383
EncodeFrameParams::speed
int speed
Definition: encoder.h:2772
AV1Common::show_frame
int show_frame
Definition: av1_common_int.h:862
CommonTileParams::large_scale
unsigned int large_scale
Definition: av1_common_int.h:464
TimeStamps::prev_ts_start
int64_t prev_ts_start
Definition: encoder.h:2024
SPEED_FEATURES::tpl_sf
TPL_SPEED_FEATURES tpl_sf
Definition: speed_features.h:1129
RefreshFrameFlagsInfo::alt_ref_frame
bool alt_ref_frame
Definition: encoder.h:1770
AV1Common::quant_params
CommonQuantParams quant_params
Definition: av1_common_int.h:899
yv12_buffer_config
YV12 frame buffer data structure.
Definition: yv12config.h:38
av1_save_layer_context
void av1_save_layer_context(AV1_COMP *const cpi)
Save the layer context after encoding the frame.
Definition: svc_layercontext.c:213
AV1_COMP::time_stamps
TimeStamps time_stamps
Definition: encoder.h:2289
AV1_COMP::no_show_fwd_kf
int no_show_fwd_kf
Definition: encoder.h:2148
aom_encoder.h
Describes the encoder algorithm interface to applications.
ExternalFlags
Flags signalled by the external interface at frame level.
Definition: encoder.h:1886
AV1_COMP::rc
RATE_CONTROL rc
Definition: encoder.h:2294
AV1Common
Top level common structure used by both encoder and decoder.
Definition: av1_common_int.h:723
ExternalFlags::use_ref_frame_mvs
bool use_ref_frame_mvs
Definition: encoder.h:1911
AV1_COMP::unfiltered_source
YV12_BUFFER_CONFIG * unfiltered_source
Definition: encoder.h:2197
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:169
AV1EncoderConfig::algo_cfg
AlgoCfg algo_cfg
Definition: encoder.h:817
AV1_COMP::scaled_source
YV12_BUFFER_CONFIG scaled_source
Definition: encoder.h:2181
EncodeFrameInput
Input frames and last input frame.
Definition: encoder.h:2714
AV1_COMP::framerate
double framerate
Definition: encoder.h:2299
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:2726
AV1_COMP::ppi
AV1_PRIMARY * ppi
Definition: encoder.h:2099
macroblockd
Variables related to current coding block.
Definition: blockd.h:568
KeyFrameCfg::enable_keyframe_filtering
int enable_keyframe_filtering
Definition: encoder.h:391
AV1Common::superres_upscaled_height
int superres_upscaled_height
Definition: av1_common_int.h:773
ExternalFlags::refresh_frame_context_pending
bool refresh_frame_context_pending
Definition: encoder.h:1906
macroblock::e_mbd
MACROBLOCKD e_mbd
Decoder's view of current coding block.
Definition: block.h:864
ExtRefreshFrameFlagsInfo::bwd_ref_frame
bool bwd_ref_frame
Definition: encoder.h:1874
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:419
AV1Common::width
int width
Definition: av1_common_int.h:748
AV1_COMP::oxcf
AV1EncoderConfig oxcf
Definition: encoder.h:2143
AV1Common::seq_params
SequenceHeader seq_params
Definition: av1_common_int.h:953
TimeStamps::first_ts_start
int64_t first_ts_start
Definition: encoder.h:2032
ExtRefreshFrameFlagsInfo
Frame refresh flags set by the external interface.
Definition: encoder.h:1871
av1_temporal_filter
int av1_temporal_filter(struct AV1_COMP *cpi, const int filter_frame_lookahead_idx, FRAME_UPDATE_TYPE update_type, int is_forward_keyframe, int *show_existing_arf)
Performs temporal filtering if needed on a source frame. For example to create a filtered alternate r...
AV1EncoderConfig::rc_cfg
RateControlCfg rc_cfg
Definition: encoder.h:827
ExtRefreshFrameFlagsInfo::update_pending
bool update_pending
Definition: encoder.h:1880
AV1Common::showable_frame
int showable_frame
Definition: av1_common_int.h:870
AV1Common::current_frame
CurrentFrame current_frame
Definition: av1_common_int.h:727
AV1Common::features
FeatureFlags features
Definition: av1_common_int.h:882
EncodeFrameParams::refresh_frame
RefreshFrameFlagsInfo refresh_frame
Definition: encoder.h:2767
AV1_COMP::source
YV12_BUFFER_CONFIG * source
Definition: encoder.h:2161
AV1Common::mi_params
CommonModeInfoParams mi_params
Definition: av1_common_int.h:887
EncodeFrameParams::show_frame
int show_frame
Definition: encoder.h:2744
macroblock
Encoder's parameters related to the current coding block.
Definition: block.h:846
TplParams::skip_tpl_setup_stats
int skip_tpl_setup_stats
Definition: tpl_model.h:203
AV1Common::remapped_ref_idx
int remapped_ref_idx[REF_FRAMES]
Definition: av1_common_int.h:831
RATE_CONTROL::frames_to_key
int frames_to_key
Definition: ratectrl.h:223
KeyFrameCfg::key_freq_max
int key_freq_max
Definition: encoder.h:386
AV1_COMP::svc
SVC svc
Definition: encoder.h:2636