tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

av1_temporal_denoiser.h (4736B)


      1 /*
      2 * Copyright (c) 2020, 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_AV1_TEMPORAL_DENOISER_H_
     13 #define AOM_AV1_ENCODER_AV1_TEMPORAL_DENOISER_H_
     14 
     15 #include "av1/encoder/block.h"
     16 #include "aom_scale/yv12config.h"
     17 
     18 #ifdef __cplusplus
     19 extern "C" {
     20 #endif
     21 
     22 #define MOTION_MAGNITUDE_THRESHOLD (8 * 3)
     23 
     24 // Denoiser is used in non svc real-time mode which does not use alt-ref, so no
     25 // need to allocate for it, and hence we need MAX_REF_FRAME - 1
     26 #define NONSVC_REF_FRAMES REF_FRAMES - 1
     27 
     28 // Number of frame buffers when SVC is used. [0] for current denoised buffer and
     29 // [1..8] for REF_FRAMES
     30 #define SVC_REF_FRAMES 9
     31 
     32 typedef enum av1_denoiser_decision {
     33  COPY_BLOCK,
     34  FILTER_BLOCK,
     35  FILTER_ZEROMV_BLOCK
     36 } AV1_DENOISER_DECISION;
     37 
     38 typedef enum av1_denoiser_level {
     39  kDenLowLow,
     40  kDenLow,
     41  kDenMedium,
     42  kDenHigh
     43 } AV1_DENOISER_LEVEL;
     44 
     45 typedef struct av1_denoiser {
     46  YV12_BUFFER_CONFIG *running_avg_y;
     47  YV12_BUFFER_CONFIG *mc_running_avg_y;
     48  YV12_BUFFER_CONFIG last_source;
     49  int frame_buffer_initialized;
     50  int reset;
     51  int num_ref_frames;
     52  int num_layers;
     53  unsigned int current_denoiser_frame;
     54  AV1_DENOISER_LEVEL denoising_level;
     55  AV1_DENOISER_LEVEL prev_denoising_level;
     56 } AV1_DENOISER;
     57 
     58 typedef struct {
     59  int64_t zero_last_cost_orig;
     60  unsigned int *ref_frame_cost;
     61  int_mv (*frame_mv)[REF_FRAMES];
     62  int reuse_inter_pred;
     63  TX_SIZE best_tx_size;
     64  PREDICTION_MODE best_mode;
     65  MV_REFERENCE_FRAME best_ref_frame;
     66  int_interpfilters best_pred_filter;
     67  uint8_t best_mode_skip_txfm;
     68 } AV1_PICKMODE_CTX_DEN;
     69 
     70 struct AV1_COMP;
     71 struct SVC;
     72 struct RTC_REF;
     73 
     74 void av1_denoiser_update_frame_info(
     75    AV1_DENOISER *denoiser, YV12_BUFFER_CONFIG src, struct RTC_REF *rtc_ref,
     76    struct SVC *svc, FRAME_TYPE frame_type, int refresh_alt_ref_frame,
     77    int refresh_golden_frame, int refresh_last_frame, int alt_fb_idx,
     78    int gld_fb_idx, int lst_fb_idx, int resized,
     79    int svc_refresh_denoiser_buffers, int second_spatial_layer);
     80 
     81 void av1_denoiser_denoise(struct AV1_COMP *cpi, MACROBLOCK *mb, int mi_row,
     82                          int mi_col, BLOCK_SIZE bs, PICK_MODE_CONTEXT *ctx,
     83                          AV1_DENOISER_DECISION *denoiser_decision,
     84                          int use_gf_temporal_ref);
     85 
     86 void av1_denoiser_reset_frame_stats(PICK_MODE_CONTEXT *ctx);
     87 
     88 void av1_denoiser_update_frame_stats(MB_MODE_INFO *mi, int64_t sse,
     89                                     PREDICTION_MODE mode,
     90                                     PICK_MODE_CONTEXT *ctx);
     91 
     92 int av1_denoiser_realloc_svc(AV1_COMMON *cm, AV1_DENOISER *denoiser,
     93                             struct RTC_REF *rtc, struct SVC *svc,
     94                             int svc_buf_shift, int refresh_alt,
     95                             int refresh_gld, int refresh_lst, int alt_fb_idx,
     96                             int gld_fb_idx, int lst_fb_idx);
     97 
     98 int av1_denoiser_alloc(AV1_COMMON *cm, struct SVC *svc, AV1_DENOISER *denoiser,
     99                       int use_svc, int noise_sen, int width, int height,
    100                       int ssx, int ssy, int use_highbitdepth, int border);
    101 
    102 #if CONFIG_AV1_TEMPORAL_DENOISING
    103 // This function is used by both c and sse2 denoiser implementations.
    104 // Define it as a static function within the scope where av1_denoiser.h
    105 // is referenced.
    106 static inline int total_adj_strong_thresh(BLOCK_SIZE bs,
    107                                          int increase_denoising) {
    108  return (1 << num_pels_log2_lookup[bs]) * (increase_denoising ? 3 : 2);
    109 }
    110 #endif
    111 
    112 void av1_denoiser_free(AV1_DENOISER *denoiser);
    113 
    114 void av1_denoiser_set_noise_level(struct AV1_COMP *const cpi, int noise_level);
    115 
    116 void av1_denoiser_reset_on_first_frame(struct AV1_COMP *const cpi);
    117 
    118 int64_t av1_scale_part_thresh(int64_t threshold, AV1_DENOISER_LEVEL noise_level,
    119                              CONTENT_STATE_SB content_state,
    120                              int temporal_layer_id);
    121 
    122 int64_t av1_scale_acskip_thresh(int64_t threshold,
    123                                AV1_DENOISER_LEVEL noise_level, int abs_sumdiff,
    124                                int temporal_layer_id);
    125 
    126 void av1_denoiser_update_ref_frame(struct AV1_COMP *const cpi);
    127 
    128 void aom_write_yuv_frame(FILE *yuv_file, YV12_BUFFER_CONFIG *s);
    129 
    130 #ifdef __cplusplus
    131 }  // extern "C"
    132 #endif
    133 
    134 #endif  // AOM_AV1_ENCODER_AV1_TEMPORAL_DENOISER_H_