Home | History | Annotate | Download | only in encoder
      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 "av1/common/blockd.h"
     16 #include "av1/encoder/block.h"
     17 
     18 #ifdef __cplusplus
     19 extern "C" {
     20 #endif
     21 
     22 struct AV1_COMP;
     23 struct AV1Common;
     24 struct ThreadData;
     25 
     26 enum {
     27   // Search all the partition types in this plane.
     28   SEARCH_FULL_PLANE = 0,
     29   // Only search none_partition coding block.
     30   NONE_PARTITION_PLANE = 1,
     31   // Search all the partition types in this plane except split.
     32   SEARCH_SAME_PLANE = 2,
     33   // Skip search partition on this plane. Go split directly.
     34   SPLIT_PLANE = 3,
     35 } UENUM1BYTE(CB_TREE_SEARCH);
     36 
     37 // Structure to hold snapshot of coding context during the mode picking process
     38 typedef struct {
     39   MB_MODE_INFO mic;
     40   MB_MODE_INFO_EXT mbmi_ext;
     41   int64_t dist;
     42   int64_t rdcost;
     43   uint8_t *color_index_map[2];
     44   uint8_t *blk_skip;
     45 
     46   tran_low_t *coeff[MAX_MB_PLANE];
     47   tran_low_t *qcoeff[MAX_MB_PLANE];
     48   tran_low_t *dqcoeff[MAX_MB_PLANE];
     49   uint16_t *eobs[MAX_MB_PLANE];
     50   uint8_t *txb_entropy_ctx[MAX_MB_PLANE];
     51 
     52   int num_4x4_blk;
     53   int skip;
     54   // For current partition, only if all Y, U, and V transform blocks'
     55   // coefficients are quantized to 0, skippable is set to 1.
     56   int skippable;
     57   int best_mode_index;
     58   int hybrid_pred_diff;
     59   int comp_pred_diff;
     60   int single_pred_diff;
     61 
     62   // TODO(jingning) Use RD_COST struct here instead. This involves a boarder
     63   // scope of refactoring.
     64   int rate;
     65 
     66   int rd_mode_is_ready;  // Flag to indicate whether rd pick mode decision has
     67                          // been made.
     68 
     69   // motion vector cache for adaptive motion search control in partition
     70   // search loop
     71   MV pred_mv[REF_FRAMES];
     72   InterpFilter pred_interp_filter;
     73   PARTITION_TYPE partition;
     74 } PICK_MODE_CONTEXT;
     75 
     76 typedef struct {
     77   int64_t rdcost;
     78   int64_t sub_block_rdcost[4];
     79   int valid;
     80   int split;
     81   int sub_block_split[4];
     82   int sub_block_skip[4];
     83   int skip;
     84 } PC_TREE_STATS;
     85 
     86 typedef struct PC_TREE {
     87   PARTITION_TYPE partitioning;
     88   BLOCK_SIZE block_size;
     89   PICK_MODE_CONTEXT none;
     90   PICK_MODE_CONTEXT horizontal[2];
     91   PICK_MODE_CONTEXT vertical[2];
     92   PICK_MODE_CONTEXT horizontala[3];
     93   PICK_MODE_CONTEXT horizontalb[3];
     94   PICK_MODE_CONTEXT verticala[3];
     95   PICK_MODE_CONTEXT verticalb[3];
     96   PICK_MODE_CONTEXT horizontal4[4];
     97   PICK_MODE_CONTEXT vertical4[4];
     98   struct PC_TREE *split[4];
     99   PC_TREE_STATS pc_tree_stats;
    100   CB_TREE_SEARCH cb_search_range;
    101   int index;
    102   MV mv_ref_fulls[REF_FRAMES];
    103 } PC_TREE;
    104 
    105 void av1_setup_pc_tree(struct AV1Common *cm, struct ThreadData *td);
    106 void av1_free_pc_tree(struct ThreadData *td, const int num_planes);
    107 void av1_copy_tree_context(PICK_MODE_CONTEXT *dst_ctx,
    108                            PICK_MODE_CONTEXT *src_ctx);
    109 
    110 #ifdef __cplusplus
    111 }  // extern "C"
    112 #endif
    113 
    114 #endif  // AOM_AV1_ENCODER_CONTEXT_TREE_H_
    115