• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright (C) 2018 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *****************************************************************************
18  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19 */
20 /*!
21 ******************************************************************************
22 * \file ihevce_decomp_pre_intra_structs.h
23 *
24 * \brief
25 *    This file contains strcutures of pre_enc_loop pass
26 *
27 * \date
28 *    18/09/2012
29 *
30 * \author
31 *    Ittiam
32 *
33 ******************************************************************************
34 */
35 
36 #ifndef _IHEVCE_DECOMP_PRE_INTRA_STRUCTS_H_
37 #define _IHEVCE_DECOMP_PRE_INTRA_STRUCTS_H_
38 
39 /*****************************************************************************/
40 /* Constant Macros                                                           */
41 /*****************************************************************************/
42 
43 /*For decomposition of every row we need some extra rows above n below that row*/
44 #define NUM_EXTRA_ROWS_REQ 3
45 
46 /*Macros for pre intra early decisions*/
47 #define NUM_MODES 35
48 #define SAD_NOT_VALID 0xFFFFF
49 
50 #define SET_T_AVAILABLE(x) (x = x | (1 << 8))
51 #define SET_L_AVAILABLE(x) (x = x | (1 << 7))
52 #define SET_TL_AVAILABLE(x) (x = x | (1 << 16))
53 #define SET_TR_AVAILABLE(x) (x = x | (1 << 12))
54 #define SET_BL_AVAILABLE(x) (x = x | (1 << 3))
55 #define SET_ALL_AVAILABLE(x) (x = (1 << 8) + (1 << 7) + (1 << 16) + (1 << 12) + (1 << 3))
56 
57 #define SET_T_UNAVAILABLE(x) (x = x & ~((WORD32)1 << 8))
58 #define SET_L_UNAVAILABLE(x) (x = x & ~((WORD32)1 << 7))
59 #define SET_TL_UNAVAILABLE(x) (x = x & ~((WORD32)1 << 16))
60 #define SET_TR_UNAVAILABLE(x) (x = x & ~((WORD32)1 << 12))
61 #define SET_BL_UNAVAILABLE(x) (x = x & ~((WORD32)1 << 3))
62 #define SET_ALL_UNAVAILABLE(x) (x = 0)
63 
64 #define CHECK_T_AVAILABLE(x) ((x & (1 << 8)) >> 8)
65 #define CHECK_L_AVAILABLE(x) ((x & (1 << 7)) >> 7)
66 #define CHECK_TL_AVAILABLE(x) ((x & (1 << 16)) >> 16)
67 #define CHECK_TR_AVAILABLE(x) ((x & (1 << 12)) >> 12)
68 #define CHECK_BL_AVAILABLE(x) ((x & (1 << 3)) >> 3)
69 
70 /*  q format for lamba used in the encoder                                   */
71 #define LAMBDA_Q_SHIFT 8
72 
73 /*****************************************************************************/
74 /* Enums                                                                     */
75 /*****************************************************************************/
76 typedef enum
77 {
78     DECOMP_PRE_INTRA_CTXT = 0,
79     DECOMP_PRE_INTRA_THRDS_CTXT,
80     DECOMP_PRE_INTRA_ED_CTXT,
81 
82     /* should always be the last entry */
83     NUM_DECOMP_PRE_INTRA_MEM_RECS
84 } DECOMP_PRE_INTRA_MEM_TABS_T;
85 
86 /*****************************************************************************/
87 /* Structure                                                                 */
88 /*****************************************************************************/
89 
90 /**
91 ******************************************************************************
92  *  @brief  Context for  early intra or inter decision
93 ******************************************************************************
94  */
95 typedef struct
96 {
97     /** lambda for cost calculation */
98     WORD32 lambda;
99 
100     /*pic type*/
101     WORD32 i4_slice_type;
102 
103     /**
104      * Until what level, intra is evaluated.
105      * 0 - 8
106      * 1 - 4
107      * 2 - 2
108      * 3 - 4
109      */
110     WORD32 level;
111 
112     /*Pointer to 4x4 blocks of entire frame */
113     ihevce_ed_blk_t *ps_ed_pic;
114 
115     /*Pointer to present 4x4 block */
116     ihevce_ed_blk_t *ps_ed;
117 
118     /*Pointer to ctb level data of entire frame */
119     ihevce_ed_ctb_l1_t *ps_ed_ctb_l1_pic;
120 
121     /*Pointer to ctb level data of current ctb */
122     ihevce_ed_ctb_l1_t *ps_ed_ctb_l1;
123 
124     WORD32 left_ctb_intra_modes[20];
125 
126     WORD32 sad[64 * NUM_MODES];
127 
128     /*Sum of best SATDs at L1*/
129     LWORD64 i8_sum_best_satd;
130 
131     /*Sum of best SATDs at L1*/
132     LWORD64 i8_sum_sq_best_satd;
133 
134     /** Encoder quality preset : See IHEVCE_QUALITY_CONFIG_T for presets */
135     WORD32 i4_quality_preset;
136 
137     /*following are the changes for reducing the stack memory used by this module. Local variables are copied to context memory */
138 
139     /** Neighbour flags. Used as local variable in pre_intra_process_row function. Shouldnt be used by other functions */
140     WORD32 ai4_nbr_flags[64];
141 
142     /** reference data for four 4x4 blocks. This is used as local variable in ed_calc_8x8_blk */
143     UWORD8 au1_ref_full_ctb[4][18];
144 
145     /** reference data for 8x8 block. This is used as local variable in ed_calc_8x8_blk */
146     UWORD8 au1_ref_8x8[1][33];
147 
148     /** mode bits costs array. This is used as local variable in ed_calc_8x8_blk */
149     UWORD16 au2_mode_bits_cost_full_ctb[4][NUM_MODES];
150 
151     /** reference data for 4x4 block for incomplete ctb proc. Variable local to ed_calc_incomplete_ctb*/
152     UWORD8 au1_ref_ic_ctb[18];
153 
154     /** top intra modes for incomplete ctb proc. Variable local to ed_calc_incomplete_ctb*/
155     WORD32 ai4_top_intra_modes_ic_ctb[20];
156 
157     /** mode bits cost for incomplete ctb proc. Variable local to ed_calc_incomplete_ctb*/
158     UWORD16 au2_mode_bits_cost_ic_ctb[NUM_MODES];
159 
160     /** Pointer to structure containing function pointers of common*/
161     func_selector_t *ps_func_selector;
162 
163 } ihevce_ed_ctxt_t;  //early decision
164 
165 typedef struct
166 {
167     /** Actual Width of this layer */
168     WORD32 i4_actual_wd;
169 
170     /** Actual height of this layer */
171     WORD32 i4_actual_ht;
172 
173     /** Padded width of this layer */
174     WORD32 i4_padded_wd;
175 
176     /** Padded height of this layer */
177     WORD32 i4_padded_ht;
178 
179     /** input pointer. */
180     UWORD8 *pu1_inp;
181 
182     /** stride of input buffer */
183     WORD32 i4_inp_stride;
184 
185     /** Decomposition block height size */
186     WORD32 i4_decomp_blk_ht;
187 
188     /** Decomposition block width size */
189     WORD32 i4_decomp_blk_wd;
190 
191     /** Number of blocks in a row */
192     WORD32 i4_num_col_blks;
193 
194     /** Number of rows in a layer */
195     WORD32 i4_num_row_blks;
196     WORD32 ai4_curr_row_no[MAX_NUM_CTB_ROWS_FRM];
197 
198     WORD32 i4_num_rows_processed;
199 } decomp_layer_ctxt_t;
200 
201 typedef struct
202 {
203     /* Number of layers */
204     WORD32 i4_num_layers;
205 
206     /** Handles for all layers. Entry 0 refers to L0 , 3 refers to L3 */
207     decomp_layer_ctxt_t as_layers[MAX_NUM_HME_LAYERS];
208 
209     /** Array for working memory of the thread */
210     UWORD8 au1_wkg_mem[((MAX_CTB_SIZE >> 1) * (MAX_CTB_SIZE + 2 * NUM_EXTRA_ROWS_REQ))];
211 
212     /** Pointer for working memory of the thread */
213     UWORD8 *pu1_wkg_mem;
214 
215     /** Encoder quality preset : See IHEVCE_QUALITY_CONFIG_T for presets */
216     WORD32 i4_quality_preset;
217 
218     /** ed_ctxt pointer. This memory is re-used across layers now */
219     ihevce_ed_ctxt_t *ps_ed_ctxt;
220 
221     ihevce_ed_blk_t *ps_layer1_buf;
222     ihevce_ed_blk_t *ps_layer2_buf;
223     ihevce_ed_ctb_l1_t *ps_ed_ctb_l1;
224 
225     /** to store the L0 8x8 cur SATD */
226     ihevce_8x8_L0_satd_t *ps_layer0_cur_satd;
227 
228     /** to store the L0 8x8 cur mean*/
229     ihevce_8x8_L0_mean_t *ps_layer0_cur_mean;
230 
231     WORD32 i4_slice_type;
232     WORD32 i4_codec_level;
233     WORD32 ai4_lambda[MAX_NUM_HME_LAYERS];
234 
235     /* pointer to the structure ps_ctb_analyse in pre_enc_me_ctxt_t */
236     ctb_analyse_t *ps_ctb_analyse;
237 
238     WORD32 i4_enable_noise_detection;
239 
240     ihevce_ipe_optimised_function_list_t s_ipe_optimised_function_list;
241 
242     ihevce_cmn_opt_func_t s_cmn_opt_func;
243 
244 } ihevce_decomp_pre_intra_ctxt_t;
245 
246 /**
247 ******************************************************************************
248  *  @brief  Encode loop master context structure
249 ******************************************************************************
250 */
251 typedef struct
252 {
253     /** Array of encode loop structure */
254     ihevce_decomp_pre_intra_ctxt_t *aps_decomp_pre_intra_thrd_ctxt[MAX_NUM_FRM_PROC_THRDS_PRE_ENC];
255 
256     /** Number of processing threads created run time */
257     WORD32 i4_num_proc_thrds;
258 
259 } ihevce_decomp_pre_intra_master_ctxt_t;
260 
261 /*****************************************************************************/
262 /* Extern Variable Declarations                                              */
263 /*****************************************************************************/
264 
265 /*****************************************************************************/
266 /* Extern Function Declarations                                              */
267 /*****************************************************************************/
268 
269 #endif /* _IHEVCE_ENC_LOOP_STRUCTS_H_ */
270