 |
AOMedia AV1 Codec
|
12 #ifndef AOM_AV1_ENCODER_TEMPORAL_FILTER_H_
13 #define AOM_AV1_ENCODER_TEMPORAL_FILTER_H_
31 #define TF_BLOCK_SIZE BLOCK_32X32
34 #define TF_WINDOW_LENGTH 5
40 #define TF_WEIGHT_SCALE 1000
44 #define TF_WINDOW_BLOCK_BALANCE_WEIGHT 5
50 #define TF_Q_DECAY_THRESHOLD 20
54 #define TF_SEARCH_ERROR_NORM_WEIGHT 20
60 #define TF_STRENGTH_THRESHOLD 4
69 #define TF_SEARCH_DISTANCE_THRESHOLD 0.1
77 #define TF_QINDEX_CUTOFF 128
79 #define NOISE_ESTIMATION_EDGE_THRESHOLD 50
115 int compute_frame_diff;
119 struct scale_factors sf;
123 double noise_levels[MAX_MB_PLANE];
151 #define TF_INFO_BUF_COUNT 2
233 FRAME_DIFF *frame_diff);
250 } TemporalFilterData;
254 #if CONFIG_MULTITHREAD
256 pthread_mutex_t *mutex_;
257 #endif // CONFIG_MULTITHREAD
260 } AV1TemporalFilterSync;
278 const int edge_thresh);
320 const int filter_frame_lookahead_idx,
321 int gf_frame_index, FRAME_DIFF *frame_diff,
339 const FRAME_DIFF *frame_diff,
int q_index,
344 int av1_get_q(
const struct AV1_COMP *cpi);
353 static AOM_INLINE
bool tf_alloc_and_reset_data(TemporalFilterData *tf_data,
355 int is_high_bitdepth) {
356 tf_data->tmp_mbmi = (
MB_MODE_INFO *)malloc(
sizeof(*tf_data->tmp_mbmi));
357 memset(tf_data->tmp_mbmi, 0,
sizeof(*tf_data->tmp_mbmi));
359 (uint32_t *)aom_memalign(16, num_pels *
sizeof(*tf_data->accum));
361 (uint16_t *)aom_memalign(16, num_pels *
sizeof(*tf_data->count));
362 memset(&tf_data->diff, 0,
sizeof(tf_data->diff));
363 if (is_high_bitdepth)
364 tf_data->pred = CONVERT_TO_BYTEPTR(
365 aom_memalign(32, num_pels * 2 *
sizeof(*tf_data->pred)));
368 (uint8_t *)aom_memalign(32, num_pels *
sizeof(*tf_data->pred));
369 if (!(tf_data->accum && tf_data->count && tf_data->pred)) {
370 aom_free(tf_data->accum);
371 aom_free(tf_data->count);
372 aom_free(tf_data->pred);
385 static AOM_INLINE
void tf_setup_macroblockd(
MACROBLOCKD *mbd,
386 TemporalFilterData *tf_data,
387 const struct scale_factors *scale) {
390 mbd->
mi = &tf_data->tmp_mbmi;
400 static AOM_INLINE
void tf_dealloc_data(TemporalFilterData *tf_data,
401 int is_high_bitdepth) {
402 if (is_high_bitdepth)
403 tf_data->pred = (uint8_t *)CONVERT_TO_SHORTPTR(tf_data->pred);
404 free(tf_data->tmp_mbmi);
405 aom_free(tf_data->accum);
406 aom_free(tf_data->count);
407 aom_free(tf_data->pred);
420 uint8_t **input_buffer,
int num_planes) {
421 for (
int i = 0; i < num_planes; i++) {
422 input_buffer[i] = mbd->
plane[i].pre[0].buf;
424 *input_mbmi = mbd->
mi;
436 uint8_t **input_buffer,
int num_planes) {
437 for (
int i = 0; i < num_planes; i++) {
438 mbd->
plane[i].pre[0].buf = input_buffer[i];
440 mbd->
mi = input_mbmi;
448 #endif // AOM_AV1_ENCODER_TEMPORAL_FILTER_H_
int q_factor
Definition: temporal_filter.h:143
Declares top-level encoder structures and functions.
Parameters related to temporal filtering.
Definition: temporal_filter.h:93
The stucture of acummulated frame stats in the first pass.
Definition: firstpass.h:41
void av1_apply_temporal_filter_c(const YV12_BUFFER_CONFIG *frame_to_filter, const MACROBLOCKD *mbd, const BLOCK_SIZE block_size, const int mb_row, const int mb_col, const int num_planes, const double *noise_levels, const MV *subblock_mvs, const int *subblock_mses, const int q_factor, const int filter_strength, const uint8_t *pred, uint32_t *accum, uint16_t *count)
Applies temporal filtering. NOTE that there are various optimised versions of this function called wh...
Definition: temporal_filter.c:556
int byte_alignment
Definition: av1_common_int.h:416
int mb_rows
Definition: temporal_filter.h:131
struct macroblock_plane plane[3]
Each of the encoding plane.
Definition: block.h:823
Data related to the current GF/ARF group and the individual frames within the group.
Definition: firstpass.h:344
const struct scale_factors * block_ref_scale_factors[2]
Definition: blockd.h:694
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.
#define AOM_PLANE_Y
Definition: aom_image.h:208
Encoder parameters related to multi-threading.
Definition: encoder.h:1593
int arf_q
Definition: ratectrl.h:323
#define AOM_PLANE_U
Definition: aom_image.h:209
TWO_PASS twopass
Definition: encoder.h:2525
YV12_BUFFER_CONFIG tf_buf[2]
Definition: temporal_filter.h:167
SPEED_FEATURES sf
Definition: encoder.h:2881
ThreadData td
Definition: encoder.h:2679
unsigned char gf_frame_index
Definition: encoder.h:2912
COMPRESSOR_STAGE compressor_stage
Definition: encoder.h:3168
int filter_frame_idx
Definition: temporal_filter.h:111
int arnr_max_frames
Definition: encoder.h:830
struct aom_internal_error_info * error
Definition: av1_common_int.h:758
bool cur_frame_force_integer_mv
Definition: av1_common_int.h:371
GF_GROUP gf_group
Definition: encoder.h:2495
int bd
Definition: blockd.h:815
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...
int avg_frame_qindex[FRAME_TYPES]
Definition: ratectrl.h:356
TWO_PASS_FRAME twopass_frame
Definition: encoder.h:3323
Main encoder configuration data structure.
Definition: encoder.h:909
int num_workers
Definition: encoder.h:1597
MultiThreadInfo mt_info
Definition: encoder.h:3042
int num_frames
Definition: temporal_filter.h:101
int compute_frame_diff
Definition: temporal_filter.h:115
Top level encoder structure.
Definition: encoder.h:2664
int height
Definition: av1_common_int.h:776
void av1_tf_do_filtering_row(AV1_COMP *cpi, ThreadData *td, int mb_row)
Does temporal filter for a given macroblock row.
Definition: temporal_filter.c:787
int is_highbitdepth
Definition: temporal_filter.h:139
search_site_config search_site_cfg[SS_CFG_TOTAL][NUM_DISTINCT_SEARCH_METHODS]
Definition: encoder.h:2014
int num_pels
Definition: temporal_filter.h:127
SequenceHeader * seq_params
Definition: av1_common_int.h:976
static void tf_setup_filtering_buffer(AV1_COMP *cpi, int filter_frame_lookahead_idx, int gf_frame_index)
Setups the frame buffer for temporal filtering. This fuction determines how many frames will be used ...
Definition: temporal_filter.c:954
struct lookahead_ctx * lookahead
Definition: encoder.h:2467
AV1_COMMON common
Definition: encoder.h:2707
YV12_BUFFER_CONFIG * output_frame
Definition: temporal_filter.h:106
int mb_cols
Definition: temporal_filter.h:135
MotionVectorSearchParams mv_search_params
Definition: encoder.h:2886
Temporal filter info for a gop.
Definition: temporal_filter.h:156
int tf_buf_valid[2]
Definition: temporal_filter.h:191
static void tf_motion_search(AV1_COMP *cpi, MACROBLOCK *mb, const YV12_BUFFER_CONFIG *frame_to_filter, const YV12_BUFFER_CONFIG *ref_frame, const BLOCK_SIZE block_size, const int mb_row, const int mb_col, MV *ref_mv, MV *subblock_mvs, int *subblock_mses)
Does motion search for blocks in temporal filtering. This is the first step for temporal filtering....
Definition: temporal_filter.c:86
@ AOM_CODEC_MEM_ERROR
Memory operation failed.
Definition: aom_codec.h:163
FullMvLimits mv_limits
Limit for the range of motion vectors.
Definition: block.h:1193
int num_frames_used_in_tf
Definition: speed_features.h:437
PRIMARY_RATE_CONTROL p_rc
Definition: encoder.h:2530
MOTION_MODE motion_mode
The motion mode used by the inter prediction.
Definition: blockd.h:250
FRAME_DIFF frame_diff[2]
Definition: temporal_filter.h:179
TemporalFilterCtx tf_ctx
Definition: encoder.h:2787
HIGH_LEVEL_SPEED_FEATURES hl_sf
Definition: speed_features.h:1532
fractional_mv_step_fp * find_fractional_mv_step
Definition: encoder.h:2007
int tf_buf_display_index_offset[2]
Definition: temporal_filter.h:187
int tf_buf_gf_index[2]
Definition: temporal_filter.h:183
YV12 frame buffer data structure.
Definition: yv12config.h:39
struct buf_2d src
A buffer containing the source frame.
Definition: block.h:113
RATE_CONTROL rc
Definition: encoder.h:2861
Top level common structure used by both encoder and decoder.
Definition: av1_common_int.h:750
static void tf_build_predictor(const YV12_BUFFER_CONFIG *ref_frame, const MACROBLOCKD *mbd, const BLOCK_SIZE block_size, const int mb_row, const int mb_col, const int num_planes, const struct scale_factors *scale, const MV *subblock_mvs, uint8_t *pred)
Builds predictor for blocks in temporal filtering. This is the second step for temporal filtering,...
Definition: temporal_filter.c:327
int arnr_strength
Definition: encoder.h:835
AlgoCfg algo_cfg
Definition: encoder.h:921
static void tf_do_filtering(AV1_COMP *cpi)
Does temporal filter for a given frame.
Definition: temporal_filter.c:919
struct aom_internal_error_info * error_info
Definition: blockd.h:845
struct lookahead_entry * av1_lookahead_peek(struct lookahead_ctx *ctx, int index, COMPRESSOR_STAGE stage)
Get a future source buffer to encode.
AV1_PRIMARY * ppi
Definition: encoder.h:2668
Stores the prediction/txfm mode of the current coding block.
Definition: blockd.h:222
@ PRUNE_MESH_SEARCH_LVL_1
Definition: speed_features.h:361
YV12_BUFFER_CONFIG tf_buf_second_arf
Definition: temporal_filter.h:175
Variables related to current coding block.
Definition: blockd.h:577
MACROBLOCKD e_mbd
Decoder's view of current coding block.
Definition: block.h:831
unsigned int av1_lookahead_depth(struct lookahead_ctx *ctx, COMPRESSOR_STAGE stage)
Get the number of frames currently in the lookahead queue.
double noise_levels[MAX_MB_PLANE]
Definition: temporal_filter.h:123
int is_temporal_filter_on
Definition: temporal_filter.h:162
int width
Definition: av1_common_int.h:775
AV1EncoderConfig oxcf
Definition: encoder.h:2712
aom_variance_fn_ptr_t fn_ptr[BLOCK_SIZES_ALL]
Definition: encoder.h:2572
MV_SPEED_FEATURES mv_sf
Definition: speed_features.h:1557
struct scale_factors sf
Definition: temporal_filter.h:119
struct macroblockd_plane plane[3]
Definition: blockd.h:613
enum aom_bit_depth aom_bit_depth_t
Bit depth for codecThis enumeration determines the bit depth of the codec.
static void tf_normalize_filtered_frame(const MACROBLOCKD *mbd, const BLOCK_SIZE block_size, const int mb_row, const int mb_col, const int num_planes, const uint32_t *accum, const uint16_t *count, YV12_BUFFER_CONFIG *result_buffer)
Normalizes the accumulated filtering result to produce the filtered frame.
Definition: temporal_filter.c:739
FeatureFlags features
Definition: av1_common_int.h:905
YV12_BUFFER_CONFIG * frames[MAX_LAG_BUFFERS]
Definition: temporal_filter.h:97
FRAME_INFO frame_info
Definition: encoder.h:2940
CommonModeInfoParams mi_params
Definition: av1_common_int.h:910
Encoder's parameters related to the current coding block.
Definition: block.h:813
int av1_gop_check_forward_keyframe(const GF_GROUP *gf_group, int gf_frame_index)
Check whether a frame in the GOP is a forward key frame.
MB_MODE_INFO ** mi
Definition: blockd.h:624
int frames_to_key
Definition: ratectrl.h:185