tor-browser

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

context_tree.h (4679B)


      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_CONTEXT_TREE_H_
     13 #define AOM_AV1_ENCODER_CONTEXT_TREE_H_
     14 
     15 #include "config/aom_config.h"
     16 
     17 #include "av1/common/blockd.h"
     18 #include "av1/encoder/block.h"
     19 #include "av1/encoder/speed_features.h"
     20 
     21 #ifdef __cplusplus
     22 extern "C" {
     23 #endif
     24 
     25 struct AV1_PRIMARY;
     26 struct AV1_COMP;
     27 struct AV1Common;
     28 struct ThreadData;
     29 
     30 typedef struct {
     31  tran_low_t *coeff_buf[MAX_MB_PLANE];
     32  tran_low_t *qcoeff_buf[MAX_MB_PLANE];
     33  tran_low_t *dqcoeff_buf[MAX_MB_PLANE];
     34 } PC_TREE_SHARED_BUFFERS;
     35 
     36 // Structure to hold snapshot of coding context during the mode picking process
     37 typedef struct PICK_MODE_CONTEXT {
     38  MB_MODE_INFO mic;
     39  MB_MODE_INFO_EXT_FRAME mbmi_ext_best;
     40  uint8_t *color_index_map[2];
     41  uint8_t *blk_skip;
     42 
     43  tran_low_t *coeff[MAX_MB_PLANE];
     44  tran_low_t *qcoeff[MAX_MB_PLANE];
     45  tran_low_t *dqcoeff[MAX_MB_PLANE];
     46  uint16_t *eobs[MAX_MB_PLANE];
     47  uint8_t *txb_entropy_ctx[MAX_MB_PLANE];
     48  uint8_t *tx_type_map;
     49 
     50  int num_4x4_blk;
     51  // For current partition, only if all Y, U, and V transform blocks'
     52  // coefficients are quantized to 0, skippable is set to 1.
     53  int skippable;
     54 #if CONFIG_INTERNAL_STATS
     55  THR_MODES best_mode_index;
     56 #endif  // CONFIG_INTERNAL_STATS
     57  RD_STATS rd_stats;
     58 
     59  int rd_mode_is_ready;  // Flag to indicate whether rd pick mode decision has
     60                         // been made.
     61 #if CONFIG_AV1_TEMPORAL_DENOISING
     62  int64_t newmv_sse;
     63  int64_t zeromv_sse;
     64  int64_t zeromv_lastref_sse;
     65  PREDICTION_MODE best_sse_inter_mode;
     66  int_mv best_sse_mv;
     67  MV_REFERENCE_FRAME best_reference_frame;
     68  MV_REFERENCE_FRAME best_zeromv_reference_frame;
     69  int sb_skip_denoising;
     70 #endif
     71 } PICK_MODE_CONTEXT;
     72 
     73 typedef struct PC_TREE {
     74  PARTITION_TYPE partitioning;
     75  BLOCK_SIZE block_size;
     76  PICK_MODE_CONTEXT *none;
     77  PICK_MODE_CONTEXT *horizontal[2];
     78  PICK_MODE_CONTEXT *vertical[2];
     79 #if !CONFIG_REALTIME_ONLY
     80  PICK_MODE_CONTEXT *horizontala[3];
     81  PICK_MODE_CONTEXT *horizontalb[3];
     82  PICK_MODE_CONTEXT *verticala[3];
     83  PICK_MODE_CONTEXT *verticalb[3];
     84  PICK_MODE_CONTEXT *horizontal4[4];
     85  PICK_MODE_CONTEXT *vertical4[4];
     86 #endif
     87  struct PC_TREE *split[4];
     88  int index;
     89 } PC_TREE;
     90 
     91 typedef struct SIMPLE_MOTION_DATA_TREE {
     92  BLOCK_SIZE block_size;
     93  PARTITION_TYPE partitioning;
     94  struct SIMPLE_MOTION_DATA_TREE *split[4];
     95 
     96  // Simple motion search_features
     97  FULLPEL_MV start_mvs[REF_FRAMES];
     98  unsigned int sms_none_feat[2];
     99  unsigned int sms_rect_feat[8];
    100  int sms_none_valid;
    101  int sms_rect_valid;
    102 } SIMPLE_MOTION_DATA_TREE;
    103 
    104 void av1_setup_shared_coeff_buffer(const SequenceHeader *const seq_params,
    105                                   PC_TREE_SHARED_BUFFERS *shared_bufs,
    106                                   struct aom_internal_error_info *error);
    107 void av1_free_shared_coeff_buffer(PC_TREE_SHARED_BUFFERS *shared_bufs);
    108 
    109 PC_TREE *av1_alloc_pc_tree_node(BLOCK_SIZE bsize);
    110 void av1_free_pc_tree_recursive(PC_TREE *tree, int num_planes, int keep_best,
    111                                int keep_none,
    112                                PARTITION_SEARCH_TYPE partition_search_type);
    113 
    114 PICK_MODE_CONTEXT *av1_alloc_pmc(const struct AV1_COMP *const cpi,
    115                                 BLOCK_SIZE bsize,
    116                                 PC_TREE_SHARED_BUFFERS *shared_bufs);
    117 void av1_reset_pmc(PICK_MODE_CONTEXT *ctx);
    118 void av1_free_pmc(PICK_MODE_CONTEXT *ctx, int num_planes);
    119 void av1_copy_tree_context(PICK_MODE_CONTEXT *dst_ctx,
    120                           PICK_MODE_CONTEXT *src_ctx);
    121 
    122 static const BLOCK_SIZE square[MAX_SB_SIZE_LOG2 - 1] = {
    123  BLOCK_4X4, BLOCK_8X8, BLOCK_16X16, BLOCK_32X32, BLOCK_64X64, BLOCK_128X128,
    124 };
    125 
    126 static inline int av1_get_pc_tree_nodes(const int is_sb_size_128,
    127                                        int stat_generation_stage) {
    128  const int tree_nodes_inc = is_sb_size_128 ? 1024 : 0;
    129  const int tree_nodes =
    130      stat_generation_stage ? 1 : (tree_nodes_inc + 256 + 64 + 16 + 4 + 1);
    131  return tree_nodes;
    132 }
    133 
    134 // Returns 0 on success, -1 on memory allocation failure.
    135 int av1_setup_sms_tree(struct AV1_COMP *const cpi, struct ThreadData *td);
    136 void av1_free_sms_tree(struct ThreadData *td);
    137 
    138 #ifdef __cplusplus
    139 }  // extern "C"
    140 #endif
    141 
    142 #endif  // AOM_AV1_ENCODER_CONTEXT_TREE_H_