1 /******************************************************************************
2  *
3  * Copyright (C) 2015 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 #ifndef __IMPEG2D_STRUCTS_H__
21 #define __IMPEG2D_STRUCTS_H__
22 
23 typedef enum
24 {
25     CMD_PROCESS,
26     CMD_FMTCONV,
27 }e_jobq_cmd_t;
28 
29 /**
30  * Structure to represent a processing job entry
31  */
32 typedef struct
33 {
34     /**
35      * Command
36      * Currently: PROCESS, FMTCONV are the only two jobs
37      */
38     WORD32 i4_cmd;
39 
40     /**
41      * MB y of the starting MB
42      */
43     WORD16 i2_start_mb_y;
44 
45     /**
46      * MB y of the last MB
47      */
48 
49     WORD16 i2_end_mb_y;
50 
51     /**
52      * Bitstream offset for the current job
53      */
54     WORD32 i4_bistream_ofst;
55 
56 }job_t;
57 
58 typedef struct
59 {
60     /* Params of the reference buffer used as input to MC */
61     UWORD32 u4_src_wd;
62     UWORD32 u4_src_offset;
63 
64     /* Params of the buffer where MC output will be written */
65     UWORD32 u4_dst_wd_res_buf;
66     UWORD32 u4_dst_wd_cur_frm;
67     UWORD32 u4_dst_offset_res_buf;
68     UWORD32 u4_dst_offset_cur_frm;
69 
70     /* Operation Parameters */
71     UWORD32 u4_rows;
72     UWORD32 u4_cols;
73     UWORD32 u4_mode;
74 }comp_mc_params_t;
75 
76 typedef struct
77 {
78     yuv_buf_t        s_ref;
79     comp_mc_params_t s_luma;
80     comp_mc_params_t s_chroma;
81 }mb_mc_params_t;
82 
83 struct _dec_mb_params_t;
84 
85 typedef UWORD8 pf_inv_quant_t (WORD16 *blk,
86                                 UWORD8 *weighting_matrix,
87                                 UWORD8 quant_scale,
88                                 WORD32 intra_flag,
89                                 WORD32 i4_num_coeffs,
90                                 WORD16 *pi2_coeffs,
91                                 UWORD8 *pu1_pos,
92                                 const UWORD8   *scan,
93                                 UWORD16 *u2_def_dc_pred,
94                                 UWORD16 u2_intra_dc_precision);
95 
96 typedef IMPEG2D_ERROR_CODES_T  pf_vld_inv_quant_t  (void  *dec,
97                              WORD16       *out_addr,
98                              const UWORD8 *scan,
99                              UWORD16      intra_flag,
100                              UWORD16      colr_comp,
101                              UWORD16      d_picture);
102 
103 typedef void  pf_mc_t(void *, UWORD8 *, UWORD32 , UWORD8 *, UWORD32 ,
104                  UWORD32 , UWORD32  );
105 
106 typedef struct dec_state_struct_t
107 {
108     WORD16          ai2_vld_buf[NUM_PELS_IN_BLOCK];
109     WORD16          ai2_idct_stg1[NUM_PELS_IN_BLOCK];
110 
111 
112     UWORD8          au1_intra_quant_matrix[NUM_PELS_IN_BLOCK];
113     UWORD8          au1_inter_quant_matrix[NUM_PELS_IN_BLOCK];
114 
115     IMPEG2D_ERROR_CODES_T (*pf_decode_slice)(struct dec_state_struct_t *);
116 
117     pf_vld_inv_quant_t *pf_vld_inv_quant;
118 
119     pf_idct_recon_t *pf_idct_recon[4];
120 
121     pf_mc_t         *pf_mc[4];
122     pf_interpred_t  *pf_fullx_halfy_8x8;
123     pf_interpred_t  *pf_halfx_fully_8x8;
124     pf_interpred_t  *pf_halfx_halfy_8x8;
125     pf_interpred_t  *pf_fullx_fully_8x8;
126 
127 
128     pf_interpolate_t *pf_interpolate;
129     pf_copy_mb_t     *pf_copy_mb;
130 
131     pf_memset0_one_16bit_buf_t *pf_memset_16bit_8x8_linear_block;
132     pf_memset_8bit_t    *pf_memset_8bit_8x8_block;
133     pf_copy_yuv420p_buf_t *pf_copy_yuv420p_buf;
134     pf_fmt_conv_yuv420p_to_yuv422ile_t *pf_fmt_conv_yuv420p_to_yuv422ile;
135     pf_fmt_conv_yuv420p_to_yuv420sp_t  *pf_fmt_conv_yuv420p_to_yuv420sp_uv;
136     pf_fmt_conv_yuv420p_to_yuv420sp_t  *pf_fmt_conv_yuv420p_to_yuv420sp_vu;
137 
138     stream_t         s_bit_stream;
139 /* @ */
140 
141     UWORD16         u2_is_mpeg2; /* 0 if stream is MPEG1 1 otherwise */
142     UWORD16         u2_frame_width;  /* Width of the frame */
143     UWORD16         u2_frame_height; /* Height of the frame */
144     UWORD16         u2_picture_width;
145     UWORD16         u2_horizontal_size;
146     UWORD16         u2_vertical_size;
147     UWORD16         u2_create_max_width;
148     UWORD16         u2_create_max_height;
149     UWORD16         u2_reinit_max_width;
150     UWORD16         u2_reinit_max_height;
151     UWORD16         u2_header_done;
152     UWORD16         u2_decode_header;
153 
154     UWORD16         u2_mb_x;
155     UWORD16         u2_mb_y;
156     UWORD16         u2_num_horiz_mb;
157     UWORD16         u2_num_vert_mb;
158     UWORD16         u2_num_flds_decoded;
159     void            *pv_pic_buf_mg;
160 
161     UWORD32         u4_frm_buf_stride; /* for display Buffer */
162 
163     UWORD16         u2_field_dct;
164     UWORD16         u2_read_dct_type;
165 
166     UWORD16         u2_read_motion_type;
167     UWORD16         u2_motion_type;
168 
169     const UWORD16   *pu2_mb_type;
170     UWORD16         u2_fld_pic;
171     UWORD16         u2_frm_pic;
172 
173     yuv_buf_t       s_cur_frm_buf;
174 
175     UWORD16         u2_fld_parity;
176     UWORD16         u2_def_dc_pred[MAX_COLR_COMPS];
177 
178     /* Variables related to Motion Vector predictors */
179 
180     WORD16          ai2_pred_mv[2][2][2];
181     e_pred_direction_t   e_mb_pred;
182     UWORD16         au2_fcode_data[2];
183 
184     /* Variables related to reference pictures */
185     yuv_buf_t       as_recent_fld[2][2];
186 
187     UWORD8          u1_quant_scale;
188     UWORD16         u2_num_mbs_left;
189     UWORD16         u2_first_mb;
190     UWORD16         u2_num_skipped_mbs;
191 
192     UWORD8          *pu1_inv_scan_matrix;
193 
194     UWORD16         u2_progressive_sequence;
195     e_pic_type_t         e_pic_type;
196 
197     UWORD16         u2_full_pel_forw_vector;
198     UWORD16         u2_forw_f_code;
199     UWORD16         u2_full_pel_back_vector;
200     UWORD16         u2_back_f_code;
201 
202     WORD16          ai2_mv[2][2][2]; /* Motion vectors */
203 
204     /* Bitstream code present in Picture coding extension */
205     UWORD16         au2_f_code[2][2];
206     UWORD16         u2_intra_dc_precision;
207     UWORD16         u2_picture_structure;
208     UWORD16         u2_top_field_first;
209     UWORD16         u2_frame_pred_frame_dct;
210     UWORD16         u2_concealment_motion_vectors;
211     UWORD16         u2_q_scale_type;
212     UWORD16         u2_intra_vlc_format;
213     UWORD16         u2_alternate_scan;
214     UWORD16         u2_repeat_first_field;
215     UWORD16         u2_progressive_frame;
216 
217 
218     /* Bitstream code related to frame rate of the bitstream */
219     UWORD16         u2_frame_rate_code;
220     UWORD16         u2_frame_rate_extension_n;
221     UWORD16         u2_frame_rate_extension_d;
222     UWORD16         u2_framePeriod;   /* Frame period in milli seconds */
223 
224     /* Members related to display dimensions of bitstream */
225     /* The size values may not be returned right now. But they are read */
226     /* and can be returned if there is a requirement.                   */
227     UWORD16         u2_display_horizontal_size;
228     UWORD16         u2_display_vertical_size;
229     UWORD16         u2_aspect_ratio_info;
230 
231     /* Members related to motion compensation */
232     yuv_buf_t       s_mc_fw_buf;
233     yuv_buf_t       s_mc_bk_buf;
234     yuv_buf_t       s_mc_buf;
235     mb_mc_params_t  as_mb_mc_params[2][2];
236     yuv_buf_t       as_ref_buf[2][2];
237     e_mb_type_t       s_mb_type;
238 
239     yuv_buf_t       s_dest_buf;
240 
241     /* Variable to handle intra MB */
242     UWORD16         u2_prev_intra_mb;
243     UWORD16         u2_coded_mb;
244 
245     /* Bidirect function pointers */
246     const struct _dec_mb_params_t *ps_func_bi_direct;
247 
248     /* Forw or Back function pointers */
249     const struct _dec_mb_params_t *ps_func_forw_or_back;
250 
251 
252     /* CBP of the current MB        */
253     UWORD16         u2_cbp;
254     void            *pv_video_scratch;
255 
256 
257     /* For global error handling */
258     void            *pv_stack_cntxt;
259 
260 /* @ */
261     WORD32          i4_chromaFormat;
262     UWORD32         u4_xdmBufID;
263     UWORD32         u4_num_mem_records;
264     /* For holding memRecords */
265     void            *pv_memTab;
266 
267     UWORD8          u1_flushfrm;
268     UWORD8          u1_flushcnt;
269     iv_yuv_buf_t    as_frame_buf[MAX_FRAME_BUFFER];
270     iv_yuv_buf_t    ps_yuv_buf;
271 
272     ivd_get_display_frame_op_t  s_disp_op;
273 
274 
275     UWORD32         u4_non_zero_cols;
276     UWORD32         u4_non_zero_rows;
277 
278     UWORD32         u4_num_frames_decoded;
279 
280     /* Adding error code variable to signal benign errors. */
281     UWORD32         u4_error_code;
282 
283     WORD32          i4_num_cores;
284 
285     UWORD8          u1_first_frame_done;
286 
287     void            *pv_codec_thread_handle;
288     void            *ps_dec_state_multi_core;
289     UWORD32         u4_inp_ts;
290     pic_buf_t       *ps_cur_pic;
291     pic_buf_t       *ps_disp_pic;
292     pic_buf_t       *aps_ref_pics[2];
293 
294     WORD32          i4_disp_buf_id;
295     WORD32          i4_cur_buf_id;
296     iv_yuv_buf_t    *ps_disp_frm_buf;
297 
298     UWORD32         u4_share_disp_buf;
299     void            *pv_pic_buf_base;
300 
301     disp_mgr_t      s_disp_mgr;
302     UWORD8          *pu1_chroma_ref_buf[BUF_MGR_MAX_CNT];
303     ivd_out_bufdesc_t as_disp_buffers[BUF_MGR_MAX_CNT];
304 
305     /* Flag to signal last coeff in a 8x8 block is one
306     after mismatch contol */
307     WORD32          i4_last_value_one;
308 
309     WORD32          i4_start_mb_y;
310     WORD32          i4_end_mb_y;
311 
312     /**
313      * Job queue buffer base
314      */
315     void            *pv_jobq_buf;
316 
317     /**
318      * Job Queue mem tab size
319      */
320     WORD32          i4_jobq_buf_size;
321 
322     /**
323      * Job Queue context
324      */
325     void            *pv_jobq;
326 
327     /* Pointer to input bitstream */
328     UWORD8          *pu1_inp_bits_buf;
329 
330     /* Number of bytes in the input bitstream */
331     UWORD32         u4_num_inp_bytes;
332 
333     /* Bytes consumed */
334     WORD32          i4_bytes_consumed;
335 
336     IVD_ARCH_T      e_processor_arch;
337 
338     IVD_SOC_T       e_processor_soc;
339 
340     WORD32          i4_frame_decoded;
341 
342 }dec_state_t;
343 
344 
345 
346 
347 typedef void (*func_decmb_params)(dec_state_t *);
348 typedef void  (*mc_funcs)(dec_state_t *);
349 typedef struct _dec_mb_params_t
350 {
351     func_decmb_params    pf_func_mb_params;
352     e_mb_type_t            s_mb_type;
353     mc_funcs             pf_mc;
354 }dec_mb_params_t;
355 
356 
357 
358 #define MAX_THREADS     4
359 
360 
361 #define MAX_MB_ROWS     (MAX_HEIGHT / 16) // number of rows for 1080p
362 
363 typedef struct _dec_state_multi_core
364 {
365     // contains the decoder state of decoder for each thread
366     dec_state_t *ps_dec_state[MAX_THREADS];
367     UWORD32     au4_thread_launched[MAX_THREADS];
368     // number of rows: first thread will populate the row offsets and update
369     // row_offset_cnt. Other threads should pick up offset from this thread
370     // and start decoding
371     UWORD32     au4_row_offset[MAX_MB_ROWS];
372     volatile    UWORD32 u4_row_offset_cnt;
373 }dec_state_multi_core_t;
374 
375 
376 
377 #endif /* #ifndef __IMPEG2D_STRUCTS_H__ */
378