/src/aom/av1/encoder/hash_motion.h
Line | Count | Source |
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_HASH_MOTION_H_ |
13 | | #define AOM_AV1_ENCODER_HASH_MOTION_H_ |
14 | | |
15 | | #include <stdbool.h> |
16 | | |
17 | | #include "aom/aom_integer.h" |
18 | | #include "aom_scale/yv12config.h" |
19 | | #include "av1/encoder/hash.h" |
20 | | #ifdef __cplusplus |
21 | | extern "C" { |
22 | | #endif |
23 | | |
24 | | // Block size used for force_integer_mv decisions |
25 | 0 | #define FORCE_INT_MV_DECISION_BLOCK_SIZE 8 |
26 | | |
27 | | // store a block's hash info. |
28 | | // x and y are the position from the top left of the picture |
29 | | // hash_value2 is used to store the second hash value |
30 | | typedef struct _block_hash { |
31 | | int16_t x; |
32 | | int16_t y; |
33 | | uint32_t hash_value2; |
34 | | } block_hash; |
35 | | |
36 | | // The rectangle of the frame, in luma pixels, that a hash table takes its |
37 | | // blocks from. The end values are exclusive. |
38 | | typedef struct { |
39 | | int x_start; |
40 | | int y_start; |
41 | | int x_end; |
42 | | int y_end; |
43 | | } IntraBCHashRegion; |
44 | | |
45 | | // The most tables built for a frame, to keep the memory down. Frames with more |
46 | | // tiles than this let neighboring tiles share a table. |
47 | 0 | #define MAX_INTRABC_HASH_TABLES 16 |
48 | | |
49 | | // A table keeps its buffers from frame to frame. cpi->td.mb owns it and frees |
50 | | // it with the encoder. The encoder threads build the tables before the tiles |
51 | | // are encoded, one table at a time per thread. After that they only read them |
52 | | // through the tile_tables pointer in their own MACROBLOCK, so a table must not |
53 | | // change while the tiles are encoded. |
54 | | typedef struct _hash_table { |
55 | | // For each block size from 4x4 to 128x128, the number of entries in each |
56 | | // bucket and the index of the first one. Each array has 1 << 16 elements, |
57 | | // one for each bucket. NULL for the sizes not built. |
58 | | uint16_t *bucket_count[6]; |
59 | | uint32_t *bucket_start[6]; |
60 | | // The entries of each block size, stored bucket after bucket, and how many |
61 | | // entries each array has room for. |
62 | | block_hash *block_hashes[6]; |
63 | | uint32_t block_hashes_size[6]; |
64 | | } hash_table; |
65 | | |
66 | | struct intrabc_hash_info; |
67 | | |
68 | | typedef struct intrabc_hash_info { |
69 | | // buffer for hash value calculation of a block |
70 | | // used only in av1_get_block_hash_value() |
71 | | // [two buffers used ping-pong] |
72 | | // buffers are AOM_BUFFER_SIZE_FOR_BLOCK_HASH elements long |
73 | | uint32_t *hash_value_buffer[2]; |
74 | | // The tables in raster order, table_cols x table_rows of them. Each one |
75 | | // covers a rectangle of tile_cols_per_table x tile_rows_per_table tiles. |
76 | | // Every tile has its own table unless the frame has more than |
77 | | // MAX_INTRABC_HASH_TABLES tiles. |
78 | | hash_table *tile_tables; |
79 | | int num_tile_tables; |
80 | | int table_cols; |
81 | | int table_rows; |
82 | | int tile_cols_per_table; |
83 | | int tile_rows_per_table; |
84 | | // Hash values of every position of the frame, only needed while the tables |
85 | | // are built. The first buffer holds the 8x8 hashes. The second one holds the |
86 | | // 4x4 hashes when the 4x4 table is built, and the two are used alternately |
87 | | // for the sizes above 8x8. It is NULL when neither is needed. Both cover |
88 | | // the luma size of the source frame they were allocated for, |
89 | | // frame_hash_width x frame_hash_height. Both sizes are 0 when the buffers |
90 | | // are freed. |
91 | | uint32_t *frame_hash_buffer[2]; |
92 | | int frame_hash_width; |
93 | | int frame_hash_height; |
94 | | |
95 | | CRC32C crc_calculator; |
96 | | int crc_initialized; |
97 | | } IntraBCHashInfo; |
98 | | |
99 | | // Returns the index of the table that covers the given tile. |
100 | | static inline int av1_intrabc_hash_table_idx( |
101 | 0 | const IntraBCHashInfo *intra_bc_hash_info, int tile_row, int tile_col) { |
102 | 0 | return tile_row / intra_bc_hash_info->tile_rows_per_table * |
103 | 0 | intra_bc_hash_info->table_cols + |
104 | 0 | tile_col / intra_bc_hash_info->tile_cols_per_table; |
105 | 0 | } Unexecuted instantiation: av1_quantize.c:av1_intrabc_hash_table_idx Unexecuted instantiation: encodetxb.c:av1_intrabc_hash_table_idx Unexecuted instantiation: pickrst.c:av1_intrabc_hash_table_idx Unexecuted instantiation: rd.c:av1_intrabc_hash_table_idx Unexecuted instantiation: rdopt.c:av1_intrabc_hash_table_idx Unexecuted instantiation: temporal_filter.c:av1_intrabc_hash_table_idx Unexecuted instantiation: tokenize.c:av1_intrabc_hash_table_idx Unexecuted instantiation: tpl_model.c:av1_intrabc_hash_table_idx Unexecuted instantiation: tx_search.c:av1_intrabc_hash_table_idx Unexecuted instantiation: txb_rdopt.c:av1_intrabc_hash_table_idx Unexecuted instantiation: intra_mode_search.c:av1_intrabc_hash_table_idx Unexecuted instantiation: var_based_part.c:av1_intrabc_hash_table_idx Unexecuted instantiation: av1_noise_estimate.c:av1_intrabc_hash_table_idx Unexecuted instantiation: intra_mode_search_sse2.c:av1_intrabc_hash_table_idx Unexecuted instantiation: temporal_filter_sse2.c:av1_intrabc_hash_table_idx Unexecuted instantiation: highbd_temporal_filter_sse2.c:av1_intrabc_hash_table_idx Unexecuted instantiation: rdopt_sse4.c:av1_intrabc_hash_table_idx Unexecuted instantiation: pickrst_sse4.c:av1_intrabc_hash_table_idx Unexecuted instantiation: rdopt_avx2.c:av1_intrabc_hash_table_idx Unexecuted instantiation: temporal_filter_avx2.c:av1_intrabc_hash_table_idx Unexecuted instantiation: pickrst_avx2.c:av1_intrabc_hash_table_idx Unexecuted instantiation: highbd_temporal_filter_avx2.c:av1_intrabc_hash_table_idx Unexecuted instantiation: bitstream.c:av1_intrabc_hash_table_idx Unexecuted instantiation: compound_type.c:av1_intrabc_hash_table_idx Unexecuted instantiation: encodeframe.c:av1_intrabc_hash_table_idx Unexecuted instantiation: encodeframe_utils.c:av1_intrabc_hash_table_idx Unexecuted instantiation: encodemb.c:av1_intrabc_hash_table_idx Unexecuted instantiation: encodemv.c:av1_intrabc_hash_table_idx Unexecuted instantiation: encode_strategy.c:av1_intrabc_hash_table_idx Unexecuted instantiation: encoder.c:av1_intrabc_hash_table_idx Unexecuted instantiation: encoder_utils.c:av1_intrabc_hash_table_idx Unexecuted instantiation: ethread.c:av1_intrabc_hash_table_idx Unexecuted instantiation: firstpass.c:av1_intrabc_hash_table_idx Unexecuted instantiation: global_motion_facade.c:av1_intrabc_hash_table_idx Unexecuted instantiation: gop_structure.c:av1_intrabc_hash_table_idx Unexecuted instantiation: hash_motion.c:av1_intrabc_hash_table_idx Unexecuted instantiation: interp_search.c:av1_intrabc_hash_table_idx Unexecuted instantiation: level.c:av1_intrabc_hash_table_idx Unexecuted instantiation: lookahead.c:av1_intrabc_hash_table_idx Unexecuted instantiation: mcomp.c:av1_intrabc_hash_table_idx Unexecuted instantiation: motion_search_facade.c:av1_intrabc_hash_table_idx Unexecuted instantiation: mv_prec.c:av1_intrabc_hash_table_idx Unexecuted instantiation: palette.c:av1_intrabc_hash_table_idx Unexecuted instantiation: partition_search.c:av1_intrabc_hash_table_idx Unexecuted instantiation: partition_strategy.c:av1_intrabc_hash_table_idx Unexecuted instantiation: pass2_strategy.c:av1_intrabc_hash_table_idx Unexecuted instantiation: pickcdef.c:av1_intrabc_hash_table_idx Unexecuted instantiation: picklpf.c:av1_intrabc_hash_table_idx Unexecuted instantiation: ratectrl.c:av1_intrabc_hash_table_idx Unexecuted instantiation: nonrd_pickmode.c:av1_intrabc_hash_table_idx Unexecuted instantiation: nonrd_opt.c:av1_intrabc_hash_table_idx Unexecuted instantiation: segmentation.c:av1_intrabc_hash_table_idx Unexecuted instantiation: speed_features.c:av1_intrabc_hash_table_idx Unexecuted instantiation: superres_scale.c:av1_intrabc_hash_table_idx Unexecuted instantiation: svc_layercontext.c:av1_intrabc_hash_table_idx Unexecuted instantiation: aq_complexity.c:av1_intrabc_hash_table_idx Unexecuted instantiation: aq_cyclicrefresh.c:av1_intrabc_hash_table_idx Unexecuted instantiation: aq_variance.c:av1_intrabc_hash_table_idx Unexecuted instantiation: allintra_vis.c:av1_intrabc_hash_table_idx Unexecuted instantiation: context_tree.c:av1_intrabc_hash_table_idx Unexecuted instantiation: global_motion.c:av1_intrabc_hash_table_idx Unexecuted instantiation: av1_cx_iface.c:av1_intrabc_hash_table_idx |
106 | | |
107 | | void av1_hash_table_init(IntraBCHashInfo *intra_bc_hash_info); |
108 | | // Makes num_tables empty tables. Their buffers are kept for the next frame |
109 | | // while the number of tables stays the same. |
110 | | bool av1_hash_tables_create(IntraBCHashInfo *intra_bc_hash_info, |
111 | | int num_tables); |
112 | | // Frees the tables and the frame hash buffers. |
113 | | void av1_hash_tables_destroy(IntraBCHashInfo *intra_bc_hash_info); |
114 | | int32_t av1_hash_table_count(const hash_table *p_hash_table, |
115 | | uint32_t hash_value); |
116 | | // Returns the first of the av1_hash_table_count() entries for hash_value. |
117 | | const block_hash *av1_hash_get_first_block_hash(const hash_table *p_hash_table, |
118 | | uint32_t hash_value); |
119 | | // These fill the hash values of the blocks that lie inside region. The stride |
120 | | // parameters give the distance in values between rows of the hash buffers. |
121 | | // av1_generate_block_8x8_hash_value() hashes the picture into hash_8x8, and |
122 | | // into hash_4x4 too unless it is NULL. It returns false if it runs out of |
123 | | // memory. |
124 | | bool av1_generate_block_8x8_hash_value(IntraBCHashInfo *intrabc_hash_info, |
125 | | const YV12_BUFFER_CONFIG *picture, |
126 | | const IntraBCHashRegion *region, |
127 | | uint32_t *hash_4x4, uint32_t *hash_8x8, |
128 | | int pic_block_hash_stride); |
129 | | // Hashes block_size blocks from the block_size / 2 hashes in src. |
130 | | void av1_generate_block_hash_value(IntraBCHashInfo *intra_bc_hash_info, |
131 | | const IntraBCHashRegion *region, |
132 | | int block_size, |
133 | | const uint32_t *src_pic_block_hash, |
134 | | uint32_t *dst_pic_block_hash, |
135 | | int pic_block_hash_stride); |
136 | | bool av1_add_to_hash_map_by_row_with_precal_data( |
137 | | hash_table *p_hash_table, const uint32_t *pic_hash, int pic_hash_stride, |
138 | | const IntraBCHashRegion *region, int block_size); |
139 | | |
140 | | // check whether the block starts from (x_start, y_start) with the size of |
141 | | // block_size x block_size has the same color in all rows |
142 | | int av1_hash_is_horizontal_perfect(const YV12_BUFFER_CONFIG *picture, |
143 | | int block_size, int x_start, int y_start); |
144 | | // check whether the block starts from (x_start, y_start) with the size of |
145 | | // block_size x block_size has the same color in all columns |
146 | | int av1_hash_is_vertical_perfect(const YV12_BUFFER_CONFIG *picture, |
147 | | int block_size, int x_start, int y_start); |
148 | | |
149 | | void av1_get_block_hash_value(IntraBCHashInfo *intra_bc_hash_info, |
150 | | const uint8_t *y_src, int stride, int block_size, |
151 | | uint32_t *hash_value1, uint32_t *hash_value2, |
152 | | int use_highbitdepth); |
153 | | |
154 | | #ifdef __cplusplus |
155 | | } // extern "C" |
156 | | #endif |
157 | | |
158 | | #endif // AOM_AV1_ENCODER_HASH_MOTION_H_ |