• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2017, 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_ENCODETXB_H_
13 #define AOM_AV1_ENCODER_ENCODETXB_H_
14 
15 #include "config/aom_config.h"
16 
17 #include "av1/common/av1_common_int.h"
18 #include "av1/common/blockd.h"
19 #include "av1/common/txb_common.h"
20 #include "av1/encoder/block.h"
21 #include "av1/encoder/encoder.h"
22 #include "aom_dsp/bitwriter.h"
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 #define TXB_SKIP_CTX_MASK 15
28 #define DC_SIGN_CTX_SHIFT 4
29 #define DC_SIGN_CTX_MASK 3
30 
31 typedef struct TxbInfo {
32   tran_low_t *qcoeff;
33   uint8_t *levels;  // absolute values and clamped to 255.
34   tran_low_t *dqcoeff;
35   const tran_low_t *tcoeff;
36   const int16_t *dequant;
37   int shift;
38   TX_SIZE tx_size;
39   TX_SIZE txs_ctx;
40   TX_TYPE tx_type;
41   int bwl;
42   int width;
43   int height;
44   int eob;
45   int seg_eob;
46   const SCAN_ORDER *scan_order;
47   TXB_CTX *txb_ctx;
48   int64_t rdmult;
49   const qm_val_t *iqmatrix;
50   int tx_type_cost;
51 } TxbInfo;
52 
53 void av1_alloc_txb_buf(AV1_COMP *cpi);
54 void av1_free_txb_buf(AV1_COMP *cpi);
55 int av1_cost_coeffs_txb(const MACROBLOCK *x, const int plane, const int block,
56                         const TX_SIZE tx_size, const TX_TYPE tx_type,
57                         const TXB_CTX *const txb_ctx, int reduced_tx_set_used);
58 int av1_cost_coeffs_txb_laplacian(const MACROBLOCK *x, const int plane,
59                                   const int block, const TX_SIZE tx_size,
60                                   const TX_TYPE tx_type,
61                                   const TXB_CTX *const txb_ctx,
62                                   const int reduced_tx_set_used,
63                                   const int adjust_eob);
64 int av1_cost_coeffs_txb_estimate(const MACROBLOCK *x, const int plane,
65                                  const int block, const TX_SIZE tx_size,
66                                  const TX_TYPE tx_type);
67 void av1_write_coeffs_txb(const AV1_COMMON *const cm, MACROBLOCK *const x,
68                           aom_writer *w, int blk_row, int blk_col, int plane,
69                           int block, TX_SIZE tx_size);
70 void av1_write_coeffs_mb(const AV1_COMMON *const cm, MACROBLOCK *x,
71                          aom_writer *w, BLOCK_SIZE bsize);
72 int av1_get_txb_entropy_context(const tran_low_t *qcoeff,
73                                 const SCAN_ORDER *scan_order, int eob);
74 void av1_update_txb_context(const AV1_COMP *cpi, ThreadData *td,
75                             RUN_TYPE dry_run, BLOCK_SIZE bsize,
76                             uint8_t allow_update_cdf);
77 void av1_update_and_record_txb_context(int plane, int block, int blk_row,
78                                        int blk_col, BLOCK_SIZE plane_bsize,
79                                        TX_SIZE tx_size, void *arg);
80 #if CONFIG_HTB_TRELLIS
81 void hbt_destroy();
82 #endif  // CONFIG_HTB_TRELLIS
83 int av1_optimize_txb_new(const struct AV1_COMP *cpi, MACROBLOCK *x, int plane,
84                          int block, TX_SIZE tx_size, TX_TYPE tx_type,
85                          const TXB_CTX *const txb_ctx, int *rate_cost,
86                          int sharpness, int fast_mode);
87 
88 CB_COEFF_BUFFER *av1_get_cb_coeff_buffer(const struct AV1_COMP *cpi, int mi_row,
89                                          int mi_col);
90 
91 // These numbers are empirically obtained.
92 static const int plane_rd_mult[REF_TYPES][PLANE_TYPES] = {
93   { 17, 13 },
94   { 16, 10 },
95 };
96 
97 #ifdef __cplusplus
98 }
99 #endif
100 
101 #endif  // AOM_AV1_ENCODER_ENCODETXB_H_
102