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