• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, 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 
12 #ifndef AOM_AV1_ENCODER_TEMPORAL_FILTER_H_
13 #define AOM_AV1_ENCODER_TEMPORAL_FILTER_H_
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 // TODO(any): These two variables are only used in avx2, sse2, sse4
20 // implementations, where the block size is still hard coded. This should be
21 // fixed to align with the c implementation.
22 #define BH 32
23 #define BW 32
24 
25 // Block size used in temporal filtering.
26 #define TF_BLOCK_SIZE BLOCK_32X32
27 
28 // Window size for YUV temporal filtering.
29 // This is particually used for function `av1_apply_temporal_filter_yuv()`.
30 #define TF_YUV_FILTER_WINDOW_LENGTH 3
31 // A scale factor used in YUV temporal filtering for weight adjustment.
32 #define TF_YUV_FILTER_WEIGHT_SCALE 3
33 
34 #define TF_ENABLE_PLANEWISE_STRATEGY 1
35 // Window size for plane-wise temporal filtering.
36 // This is particually used for function `av1_apply_temporal_filter_planewise()`
37 #define TF_PLANEWISE_FILTER_WINDOW_LENGTH 5
38 // A scale factor used in plane-wise temporal filtering to raise the filter
39 // weight from `double` with range [0, 1] to `int` with range [0, 1000].
40 #define TF_PLANEWISE_FILTER_WEIGHT_SCALE 1000
41 
42 #define NOISE_ESTIMATION_EDGE_THRESHOLD 50
43 // Estimates noise level from a given frame using a single plane (Y, U, or V).
44 // This is an adaptation of the mehtod in the following paper:
45 // Shen-Chuan Tai, Shih-Ming Yang, "A fast method for image noise
46 // estimation using Laplacian operator and adaptive edge detection",
47 // Proc. 3rd International Symposium on Communications, Control and
48 // Signal Processing, 2008, St Julians, Malta.
49 // Inputs:
50 //   frame: Pointer to the frame to estimate noise level from.
51 //   plane: Index of the plane used for noise estimation. Commonly, 0 for
52 //          Y-plane, 1 for U-plane, and 2 for V-plane.
53 //   bit_depth: Actual bit-depth instead of the encoding bit-depth of the frame.
54 // Returns:
55 //   The estimated noise, or -1.0 if there are too few smooth pixels.
56 double av1_estimate_noise_from_single_plane(const YV12_BUFFER_CONFIG *frame,
57                                             const int plane,
58                                             const int bit_depth);
59 
60 #define TF_QINDEX 128  // Q-index used in temporal filtering.
61 #define TF_NUM_FILTERING_FRAMES_FOR_KEY_FRAME 7
62 // Performs temporal filtering if needed.
63 // NOTE: In this function, the lookahead index is different from the 0-based
64 // real index. For example, if we want to filter the first frame in the
65 // pre-fetched buffer `cpi->lookahead`, the lookahead index will be -1 instead
66 // of 0. More concretely, 0 indicates the first LOOKAHEAD frame, which is the
67 // second frame in the pre-fetched buffer. Another example: if we want to filter
68 // the 17-th frame, which is an ARF, the lookahead index is 15 instead of 16.
69 // Futhermore, negative number is used for key frame in one-pass mode, where key
70 // frame is filtered with the frames before it instead of after it. For example,
71 // -15 means to filter the 17-th frame, which is a key frame in one-pass mode.
72 // Inputs:
73 //   cpi: Pointer to the composed information of input video.
74 //   filter_frame_lookahead_idx: The index of the to-filter frame in the
75 //                               lookahead buffer `cpi->lookahead`.
76 //   show_existing_arf: Whether to show existing ARF. This field will be updated
77 //                      in this function.
78 // Returns:
79 //   Whether temporal filtering is successfully done.
80 int av1_temporal_filter(AV1_COMP *cpi, const int filter_frame_lookahead_idx,
81                         int *show_existing_arf);
82 
83 #ifdef __cplusplus
84 }  // extern "C"
85 #endif
86 
87 #endif  // AOM_AV1_ENCODER_TEMPORAL_FILTER_H_
88