1/******************************************************************************
2*
3* Copyright (C) 2012 Ittiam Systems Pvt Ltd, Bangalore
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
19/**
20 *******************************************************************************
21 * @file
22 *  ihevcd_structs.h
23 *
24 * @brief
25 *  Structure definitions used in the decoder
26 *
27 * @author
28 *  Harish
29 *
30 * @par List of Functions:
31 *
32 * @remarks
33 *  None
34 *
35 *******************************************************************************
36 */
37
38#ifndef _IHEVCD_STRUCTS_H_
39#define _IHEVCD_STRUCTS_H_
40typedef enum
41{
42    INIT_DONE, HEADER_DONE, FIRST_FRAME_DONE,
43}CODEC_STATE_T;
44
45
46
47typedef struct _codec_t codec_t;
48
49/** Structure to hold format conversion context */
50typedef struct
51{
52    /** Current row for which format conversion should be done */
53    WORD32 i4_cur_row;
54
55    /** Number of rows for which format conversion should be done */
56    WORD32 i4_num_rows;
57}fmt_conv_t;
58
59/**
60 * Bitstream structure
61 */
62typedef struct
63{
64    /**
65     * Bitstream buffer base pointer
66     */
67    UWORD8 *pu1_buf_base;
68
69    /**
70     * Bitstream bit offset in current word. Value between 0 and 31
71     */
72    UWORD32 u4_bit_ofst;
73
74    /**
75     * Current bitstream buffer pointer
76     */
77    UWORD32 *pu4_buf;
78
79    /**
80     * Current word
81     */
82    UWORD32 u4_cur_word;
83
84    /**
85     * Next word
86     */
87    UWORD32 u4_nxt_word;
88
89    /**
90     * Max address for bitstream
91     */
92    UWORD8 *pu1_buf_max;
93}bitstrm_t;
94
95/**
96******************************************************************************
97 *  @brief      Cabac context for decoder
98******************************************************************************
99 */
100typedef struct cab_ctxt
101{
102    /*********************************************************************/
103    /*  CABAC ENGINE related fields                                      */
104    /*********************************************************************/
105    /** cabac interval range  R */
106    UWORD32  u4_range;
107
108    /** cabac interval offset O  */
109    UWORD32  u4_ofst;
110
111    /*********************************************************************/
112    /*  CABAC context models                                             */
113    /*********************************************************************/
114    /** All Context models stored in pscked form pState[bits6-1] | MPS[bit0] */
115    UWORD8  au1_ctxt_models[IHEVC_CAB_CTXT_END];
116
117    /** Context models memorized after decoding 2nd CTB in a row to be used
118     * during entropy sync cases
119     */
120    UWORD8 au1_ctxt_models_sync[IHEVC_CAB_CTXT_END];
121
122}cab_ctxt_t;
123
124typedef enum
125{
126    CMD_PROCESS,
127    CMD_FMTCONV,
128}JOBQ_CMD_T;
129
130/**
131 * Structure to represent a processing job entry
132 */
133typedef struct
134{
135    /**
136     * Command
137     * Currently: PROCESS, FMTCONV are the only two jobs
138     */
139    WORD32 i4_cmd;
140    /**
141     * CTB x of the starting CTB
142     */
143    WORD16 i2_ctb_x;
144
145    /**
146     * CTB y of the starting CTB
147     */
148
149    WORD16 i2_ctb_y;
150
151    /**
152     * Number of CTBs that need to be processed in this job
153     */
154    WORD16 i2_ctb_cnt;
155
156    /**
157     *  Slice index for the current CTB
158     */
159    WORD16 i2_slice_idx;
160
161    /**
162     * TU coefficient data offset for the current job
163     */
164    WORD32 i4_tu_coeff_data_ofst;
165}proc_job_t;
166/**
167 * Structure to represent a MV Bank buffer
168 */
169typedef struct
170{
171    /**
172     *  Pointer to hold PU index for each CTB in a picture
173     */
174    UWORD32 *pu4_pic_pu_idx;
175
176    /**
177     * Pointer to hold pu_t for each PU in a picture
178     */
179    pu_t *ps_pic_pu;
180
181    /**
182     * Pointer to hold PU map for each CTB in a picture
183     */
184    UWORD8 *pu1_pic_pu_map;
185
186    /**
187     * Pointer to hold the Slice map
188     */
189    UWORD16 *pu1_pic_slice_map;
190
191    /**
192     * Absolute POC for the current MV Bank
193     */
194    WORD32 i4_abs_poc;
195
196    /**
197     * Absolute POCs of reference List 0 for all slices in the frame from which this frame is reconstructed
198     */
199    WORD32 ai4_l0_collocated_poc[MAX_SLICE_HDR_CNT][MAX_DPB_SIZE];
200
201    /**
202     * Flag to indicate Long Term reference for POCs of reference List 0 for all slices in the frame from which this frame is reconstructed
203     */
204    WORD8 ai1_l0_collocated_poc_lt[MAX_SLICE_HDR_CNT][MAX_DPB_SIZE];
205
206    /**
207     * Absolute POCs of reference List 1 for all slices in the frame from which this frame is reconstructed
208     */
209    WORD32 ai4_l1_collocated_poc[MAX_SLICE_HDR_CNT][MAX_DPB_SIZE];
210    /**
211     * Flag to indicate Long Term reference for POCs of reference List 1 for all slices in the frame from which this frame is reconstructed
212     */
213    WORD8 ai1_l1_collocated_poc_lt[MAX_SLICE_HDR_CNT][MAX_DPB_SIZE];
214
215}mv_buf_t;
216
217typedef struct
218{
219    /**
220     * Pointer to current PPS
221     */
222    pps_t *ps_pps;
223
224    /**
225     * Pointer to current SPS
226     */
227    sps_t *ps_sps;
228
229    /**
230     * Pointer to current slice header structure
231     */
232    slice_header_t *ps_slice_hdr;
233
234    /**
235     * CTB's x position within a picture in raster scan in CTB units
236     */
237    WORD32 i4_ctb_x;
238
239    /**
240     * CTB's y position within a picture in raster scan in CTB units
241     */
242
243    WORD32 i4_ctb_y;
244
245    /**
246     * Current PU structure - set to CTB pu_t pointer at the start of CTB processing and incremented
247     * for every TU
248     */
249    pu_t *ps_pu;
250
251    /**
252     * Pointer to frame level pu_t for the current frame being parsed
253     * where MVs and Intra pred modes will be updated
254     */
255    pu_t *ps_pic_pu;
256
257    /**
258     * Store the current tile's information. This is needed for the computation of mvs.
259     */
260    tile_t *ps_tile;
261
262    /**
263     * Points to an array of PU indices which is used to identify
264     * start index of pu_t in ps_pic_pu and also to identify number of
265     * PUs in the current CTB by subtracting current idx from next CTB's
266     * PU idx
267     */
268    UWORD32 *pu4_pic_pu_idx;
269
270    /** PU Index map per CTB. The indices in this map are w.r.t picture pu array and not
271     * w.r.t CTB pu array.
272     * This will be used during mv prediction and since neighbours will have different CTB pu map
273     * it will be easier if they all have indices w.r.t picture level PU array rather than CTB level
274     * PU array.
275     * pu1_pic_pu_map is map w.r.t CTB's pu_t array
276     */
277    UWORD32 *pu4_pic_pu_idx_map;
278
279    /**
280      * Pointer to pu_map for the current frame being parsed
281      * where MVs and Intra pred modes will be updated
282      */
283    UWORD8 *pu1_pic_pu_map;
284
285    /**
286     *  PU count in current CTB
287     */
288    WORD32 i4_ctb_pu_cnt;
289
290    /**
291     *  PU count in current CTB
292     */
293    WORD32 i4_ctb_start_pu_idx;
294
295    /**
296     *  Top availability for current CTB level
297     */
298    UWORD8 u1_top_ctb_avail;
299
300    /**
301     *  Top right availability for current CTB level
302     */
303    UWORD8 u1_top_rt_ctb_avail;
304    /**
305     *  Top left availability for current CTB level
306     */
307    UWORD8 u1_top_lt_ctb_avail;
308    /**
309     *  left availability for current CTB level
310     */
311    UWORD8 u1_left_ctb_avail;
312
313}mv_ctxt_t;
314
315typedef struct
316{
317    /**
318     * Pointer to current PPS
319     */
320    pps_t *ps_pps;
321
322    /**
323     * Pointer to current SPS
324     */
325    sps_t *ps_sps;
326
327    /*
328     * Pointer to codec context
329     */
330    codec_t *ps_codec;
331
332    /**
333     * Index of the current Tile being parsed
334     */
335    tile_t *ps_tile;
336
337    /**
338     * Pointer to the current slice header
339     */
340    slice_header_t *ps_slice_hdr;
341
342    /**
343     *  TU count in current CTB
344     */
345    WORD32 i4_ctb_tu_cnt;
346
347    /**
348     * CTB's x position within a picture in raster scan in CTB units
349     */
350    WORD32 i4_ctb_x;
351
352    /**
353     * CTB's y position within a picture in raster scan in CTB units
354     */
355
356    WORD32 i4_ctb_y;
357
358    /**
359     * CTB's x position within a Tile in raster scan in CTB units
360     */
361    WORD32 i4_ctb_tile_x;
362
363    /**
364     * CTB's y position within a Tile in raster scan in CTB units
365     */
366
367    WORD32 i4_ctb_tile_y;
368
369    /**
370     * CTB's x position within a Slice in raster scan in CTB units
371     */
372    WORD32 i4_ctb_slice_x;
373
374    /**
375     * CTB's y position within a Slice in raster scan in CTB units
376     */
377
378    WORD32 i4_ctb_slice_y;
379
380    /* Two bits per edge.
381    Stored in format. BS[15] | BS[14] | .. |BS[0]*/
382    UWORD32 *pu4_pic_vert_bs;
383
384    /**
385     * Horizontal Boundary strength
386     */
387
388    /* Two bits per edge.
389    Stored in format. BS[15] | BS[14] | .. |BS[0]*/
390    UWORD32 *pu4_pic_horz_bs;
391
392    /**
393     * Flags to indicate if QP is constant through out a CTB - 1 bit for each CTB
394     * The bits are packed from LSB to MSB
395     * To get the flag corresponding to CTB with (ctb_x, ctb_y), use
396     *      pu4_qp_const_in_ctb[(ctb_x + pic_wd_in_ctb * ctb_y) >> 3] & (1 << ((ctb_x + pic_wd_in_ctb * ctb_y) & 7))
397     */
398    UWORD8 *pu1_pic_qp_const_in_ctb;
399
400    /**
401     *  Qp array stored for each 8x8 pixels
402     */
403    UWORD8  *pu1_pic_qp;
404
405    /**
406     * Current TU structure - set to CTB tu_t pointer at the start of CTB processing and incremented
407     * for every TU
408     */
409    tu_t *ps_tu;
410
411    /**
412     * Points to an array of TU indices which is used to identify
413     * start index of tu_t in ps_pic_tu and also to identify number of
414     * TUs in the current CTB by subtracting current idx from next CTB's
415     * TU idx
416     */
417    UWORD32 *pu4_pic_tu_idx;
418
419    /**
420     * Points to an array of PU indices which is used to identify
421     * start index of pu_t in ps_pic_pu and also to identify number of
422     * PUs in the current CTB by subtracting current idx from next CTB's
423     * PU idx
424     */
425    UWORD32 *pu4_pic_pu_idx;
426
427    /**
428     * Current PU structure - set to CTB pu_t pointer at the start of CTB processing and incremented
429     * for every TU
430     */
431    pu_t *ps_pu;
432
433    /**
434     * Pointer to frame level pu_t for the current frame being parsed
435     * where MVs and Intra pred modes will be updated
436     */
437    pu_t *ps_pic_pu;
438
439    /** PU Index map per CTB. The indices in this map are w.r.t picture pu array and not
440     * w.r.t CTB pu array.
441     * This will be used during mv prediction and since neighbours will have different CTB pu map
442     * it will be easier if they all have indices w.r.t picture level PU array rather than CTB level
443     * PU array.
444     * pu1_pic_pu_map is map w.r.t CTB's pu_t array
445     */
446    UWORD32 *pu4_pic_pu_idx_map;
447
448    /**
449     * Variable to store the next ctb count to compute pu idx
450     */
451    WORD32 i4_next_pu_ctb_cnt;
452
453    /**
454     * Variable to store the next ctb count to compute tu idx
455     */
456    WORD32 i4_next_tu_ctb_cnt;
457    /**
458     * Points to the array of slice indices which is used to identify the slice
459     *  to which each CTB in a frame belongs.
460     */
461    UWORD16 *pu1_slice_idx;
462}bs_ctxt_t;
463
464typedef struct
465{
466    /**
467     * Pointer to current PPS
468     */
469    pps_t *ps_pps;
470
471    /**
472     * Pointer to current SPS
473     */
474    sps_t *ps_sps;
475
476    /*
477     * Pointer to codec context
478     */
479    codec_t *ps_codec;
480
481    /**
482     * Pointer to current slice header structure
483     */
484    slice_header_t *ps_slice_hdr;
485
486    /**
487     * Pointer to the structure that contains BS and QP frame level arrays
488     */
489    bs_ctxt_t s_bs_ctxt;
490
491    /**
492     * CTB's x position within a picture in raster scan in CTB units
493     */
494    WORD32 i4_ctb_x;
495
496    /**
497     * CTB's y position within a picture in raster scan in CTB units
498     */
499
500    WORD32 i4_ctb_y;
501
502    /**
503     * Current pictures loop filter flag map at 8x8 level
504     */
505    UWORD8 *pu1_pic_no_loop_filter_flag;
506
507    /**
508     * Current CTB's no_loop_filter_flags
509     * each element corresponds to one row - including the left CTB's last 8x8
510     */
511    UWORD16 au2_ctb_no_loop_filter_flag[9];
512
513    /*
514     * Pointer to 0th luma pixel in current pic
515     */
516    UWORD8 *pu1_cur_pic_luma;
517
518    /*
519     * Pointer to 0th chroma pixel in current pic
520     */
521    UWORD8 *pu1_cur_pic_chroma;
522
523    /* Points to the array of slice indices which is used to identify the slice
524    *  to which each CTB in a frame belongs.
525    */
526    UWORD16 *pu1_slice_idx;
527
528    /* Specifies if the chroma format is yuv420sp_vu */
529    WORD32 is_chroma_yuv420sp_vu;
530
531}deblk_ctxt_t;
532
533typedef struct
534{
535    /**
536     * Pointer to current PPS
537     */
538    pps_t *ps_pps;
539
540    /**
541     * Pointer to current SPS
542     */
543    sps_t *ps_sps;
544
545    /* Pointer to codec context
546     *
547     */
548    codec_t *ps_codec;
549
550    /**
551     * Pointer to base slice header structure
552     */
553    slice_header_t *ps_slice_hdr_base;
554
555    /**
556     * Pointer to current slice header structure
557     */
558    slice_header_t *ps_slice_hdr;
559
560    /**
561     * Pointer to current tile structure
562     */
563    tile_t *ps_tile;
564    /**
565     * CTB's x position within a picture in raster scan in CTB units
566     */
567    WORD32 i4_ctb_x;
568
569    /**
570     * CTB's y position within a picture in raster scan in CTB units
571     */
572
573    WORD32 i4_ctb_y;
574
575    /**
576     * Current pictures loop filter flag map at 8x8 level
577     */
578    UWORD8 *pu1_pic_no_loop_filter_flag;
579
580    /*
581     * Pointer to 0th luma pixel in current pic
582     */
583    UWORD8 *pu1_cur_pic_luma;
584
585    /*
586     * Pointer to 0th chroma pixel in current pic
587     */
588    UWORD8 *pu1_cur_pic_chroma;
589
590    /**
591     * Pointer to frame level sao_t for the current frame being parsed
592     */
593    sao_t *ps_pic_sao;
594
595    /**
596     * Temporary buffer needed during SAO processing
597     */
598    UWORD8 *pu1_tmp_buf_luma;
599
600    /**
601     * Temporary buffer needed during SAO processing
602     */
603    UWORD8 *pu1_tmp_buf_chroma;
604
605    /**
606     * Left column of luma pixels - used by SAO
607     */
608    UWORD8 *pu1_sao_src_left_luma;
609
610    /**
611     * Top row of luma pixels - used by SAO
612     */
613    UWORD8 *pu1_sao_src_top_luma;
614
615    /**
616     * Left column of chroma pixels(interleaved) - used by SAO
617     */
618    UWORD8 *pu1_sao_src_left_chroma;
619
620    /**
621     * Top row of chroma pixels(interleaved) - used by SAO
622     */
623    UWORD8 *pu1_sao_src_top_chroma;
624
625    /**
626     * Top-left luma pixel - used by SAO (for the top CTB row)
627     */
628    UWORD8 *pu1_sao_src_luma_top_left_ctb;
629
630    /**
631     * Top-left chroma pixel(interleaved) - used by SAO (for the top CTB row)
632     */
633    UWORD8 *pu1_sao_src_chroma_top_left_ctb;
634
635    /**
636     * Top-left luma pixel - used by SAO (for the current  CTB row)
637     */
638    UWORD8 *pu1_sao_src_top_left_luma_curr_ctb;
639
640    /**
641     * Top-left chroma pixel(interleaved) - used by SAO (for the current CTB row)
642     */
643    UWORD8 *pu1_sao_src_top_left_chroma_curr_ctb;
644
645    /**
646     * Top-right luma pixel - used by SAO (for the top CTB row)
647     */
648    UWORD8 *pu1_sao_src_top_left_luma_top_right;
649
650    /**
651     * Top-right chroma pixel(interleaved) - used by SAO (for the top CTB row)
652     */
653    UWORD8 *pu1_sao_src_top_left_chroma_top_right;
654
655    /**
656     * Bottom-left luma pixel - used by SAO
657     */
658    UWORD8 u1_sao_src_top_left_luma_bot_left;
659    /**
660     *  Pointer to array that stores bottom left luma pixel per row(interleaved) - used by SAO
661     */
662    UWORD8 *pu1_sao_src_top_left_luma_bot_left;
663
664    /**
665     * Bottom left chroma pixel(interleaved) - used by SAO
666     */
667    UWORD8 au1_sao_src_top_left_chroma_bot_left[2];
668    /**
669     *  Pointer to array that stores bottom left chroma pixel per row(interleaved) - used by SAO
670     */
671    UWORD8 *pu1_sao_src_top_left_chroma_bot_left;
672
673    /*
674     * Slice counter in a picture.
675     */
676    UWORD32 i4_cur_slice_idx;
677    /**
678     * Points to the array of slice indices which is used to identify the slice
679     *  to which each CTB in a frame belongs.
680     */
681    UWORD16 *pu1_slice_idx;
682    /**
683     * Points to the array of tile indices which is used to identify the slice
684     *  to which each CTB in a frame belongs.
685     */
686    UWORD16 *pu1_tile_idx;
687
688    /* Specifies if the chroma format is yuv420sp_vu */
689    WORD32 is_chroma_yuv420sp_vu;
690
691}sao_ctxt_t;
692
693typedef struct
694{
695    /** Log2 CU's size */
696    WORD32 i4_log2_cb_size;
697
698    /** CU's x position */
699    WORD32 i4_pos_x;
700
701    /** CU's y position */
702    WORD32 i4_pos_y;
703    /**
704     * Transquant Bypass enable flag at CU level - To be replicated at TU level
705     */
706    WORD32 i4_cu_transquant_bypass;
707    /**
708     * Prediction mode
709     */
710    WORD32 i4_pred_mode;
711
712    /**
713     * Partition mode
714     */
715    WORD32 i4_part_mode;
716
717    /**
718     * Intra luma pred mode for current CU. In case of PART2Nx2N
719     * the first value is replicated to avoid checks later
720     */
721    WORD32 ai4_intra_luma_pred_mode[4];
722
723    /**
724     * Previous intra luma pred flag used for intra pred mode computation
725     */
726    WORD32 ai4_prev_intra_luma_pred_flag[4];
727
728    /**
729     * mpm index used in intra prediction mode computation
730     */
731    WORD32 ai4_mpm_idx[4];
732    /**
733     * Remaining intra pred mode
734     */
735    WORD32 ai4_rem_intra_luma_pred_mode[4];
736    /**
737     * Chroma pred mode index to be used to compute intra pred mode for chroma
738     */
739    WORD32 i4_intra_chroma_pred_mode_idx;
740    /**
741     * Maximum transform depth
742     */
743    WORD32 i4_max_trafo_depth;
744
745    /**
746     *  Luma CBF for current TU
747     */
748    UWORD8 i1_cbf_luma;
749
750    /**
751     * Cb CBF
752     */
753    UWORD8 ai1_cbf_cb[MAX_TRAFO_DEPTH];
754
755    /**
756     * Cr CBF
757     */
758    UWORD8 ai1_cbf_cr[MAX_TRAFO_DEPTH];
759
760    /**
761     * Intra split flag
762     */
763    WORD32 i4_intra_split_flag;
764
765    /**
766     * Current QP
767     */
768    WORD32 i4_qp;
769
770    /**
771     * Number of TUs in CU parsed before a change in QP is signaled
772     */
773    WORD32 i4_tu_cnt;
774
775    /**
776     * Cu QP delta
777     */
778    WORD32 i4_cu_qp_delta;
779
780}parse_cu_t;
781/**
782 * Structure contains few common state variables such as CTB positions, current SPS, PPS ids etc which are to be
783 * used in the parsing thread. By keeping it a different structure it is being explicitly signalled that these
784 * variables are specific to Parsing threads context and other threads should not update these elements
785 */
786typedef struct
787{
788    /**
789     * CTB's x position within a picture in raster scan in CTB units
790     */
791    WORD32 i4_ctb_x;
792
793    /**
794     * CTB's y position within a picture in raster scan in CTB units
795     */
796
797    WORD32 i4_ctb_y;
798
799    /**
800     * CTB's x position within a Tile in raster scan in CTB units
801     */
802    WORD32 i4_ctb_tile_x;
803
804    /**
805     * CTB's y position within a Tile in raster scan in CTB units
806     */
807
808    WORD32 i4_ctb_tile_y;
809
810    /**
811     * CTB's x position within a Slice in raster scan in CTB units
812     */
813    WORD32 i4_ctb_slice_x;
814
815    /**
816     * CTB's y position within a Slice in raster scan in CTB units
817     */
818
819    WORD32 i4_ctb_slice_y;
820
821    /**
822     * Index of the current Tile being parsed
823     */
824    tile_t *ps_tile;
825
826    /**
827     * Current slice idx - Used in multi-core cases to ensure slice header is
828     * preserved till the last CB of the slice is decoded
829     */
830    WORD32 i4_cur_slice_idx;
831    /**
832     * Current slice idx - Used in multi-core cases to ensure slice header is
833     * preserved till the last CB of the slice is decoded
834     */
835    WORD32 i4_cur_independent_slice_idx;
836
837    /**
838     * Current slice idx - Used in multi-core cases to ensure slice header is
839     * preserved till the last CB of the slice is decoded
840     */
841    WORD32 i4_cur_tile_idx;
842
843    /**
844     * Pointer to current PPS
845     */
846    pps_t *ps_pps;
847
848    /**
849     * Pointer to current SPS
850     */
851    sps_t *ps_sps;
852
853    /**
854     * Signal that pic_init is called first time
855     */
856    WORD32 i4_first_pic_init;
857
858    /**
859     * Flag to indicate if CU QP delta is coded.
860     * By default it is set to 0 at the beginning of coding quad tree
861     */
862    WORD32 i4_is_cu_qp_delta_coded;
863
864    /**
865     * CU Qp delta
866     * By default it is set to 0 at the beginning of coding quad tree
867     */
868    WORD32 i4_cu_qp_delta;
869
870    /**
871     * Bitstream structure
872     */
873    bitstrm_t s_bitstrm;
874
875    /**
876     * Pointer frame level TU subblock coeff data
877     */
878    void *pv_pic_tu_coeff_data;
879
880    /**
881     * Pointer to TU subblock coeff data and number of coded subblocks and scan idx
882     * Incremented each time a coded subblock is parsed
883     *
884     */
885    void *pv_tu_coeff_data;
886
887    /**
888     * Current TU structure - set to CTB tu_t pointer at the start of CTB parsing and incremented
889     * for every TU
890     */
891    tu_t *ps_tu;
892
893    /**
894     * Current ctb's TU map
895     */
896    UWORD8 *pu1_tu_map;
897
898    /**
899     * Current PU structure - set to CTB pu_t pointer at the start of CTB parsing and incremented
900     * for every TU
901     */
902    pu_t *ps_pu;
903
904    /**
905     * Points to the array of slice indices which is used to identify the independent slice
906     *  to which each CTB in a frame belongs.
907     */
908    UWORD16 *pu1_slice_idx;
909
910    /**
911     * Current PU index in a frame
912     */
913    WORD32 i4_pic_pu_idx;
914
915    /**
916     * Current TU index in a frame
917     */
918    WORD32 i4_pic_tu_idx;
919
920    /**
921     * Current PU structure - set to CTB pu_map pointer at the start of CTB parsing
922     */
923    UWORD8 *pu1_pu_map;
924
925    /**
926     * Current QP
927     */
928    WORD32 u4_qp;
929
930    /**
931     * Current Group's QP
932     */
933    WORD32 u4_qpg;
934
935    /**
936     * Number of PCM blocks in current CTB - Needed only during parsing
937     * If needed during recon then move it to ctb_t
938     */
939    WORD32 i4_ctb_num_pcm_blks;
940
941    /**
942     * PCM flag for the current CU
943     */
944    WORD32 i4_cu_pcm_flag;
945
946    /**
947     * CU related information to be used to populate tu_t and pu_t during
948     * pred unit and transform tree parsing.
949     */
950    parse_cu_t s_cu;
951
952    /**
953     * Pointer to pu_map for the current frame being parsed
954     */
955    UWORD8 *pu1_pic_pu_map;
956
957    /**
958     * Pointer to frame level pu_t for the current frame being parsed
959     * where MVs and Intra pred modes will be updated
960     */
961    pu_t *ps_pic_pu;
962
963    /**
964     * Pointer to tu_map for the current frame being parsed
965     */
966    UWORD8 *pu1_pic_tu_map;
967
968    /**
969     * Pointer to frame level tu_t for the current frame being parsed
970     * where transform unit related info will be updated
971     */
972    tu_t *ps_pic_tu;
973
974    /**
975     * Points to an array of TU indices which is used to identify
976     * start index of tu_t in ps_pic_tu and also to identify number of
977     * TUs in the current CTB by subtracting current idx from next CTB's
978     * TU idx
979     */
980    UWORD32 *pu4_pic_tu_idx;
981
982    /**
983     * Points to an array of PU indices which is used to identify
984     * start index of pu_t in ps_pic_pu and also to identify number of
985     * PUs in the current CTB by subtracting current idx from next CTB's
986     * PU idx
987     */
988    UWORD32 *pu4_pic_pu_idx;
989
990
991    /**
992     * Current pictures intra mode map at 8x8 level
993     */
994    UWORD8 *pu1_pic_intra_flag;
995
996    /**
997     * Current pictures loop filter flag map at 8x8 level
998     */
999    UWORD8 *pu1_pic_no_loop_filter_flag;
1000
1001    /**
1002     * Array to hold one row (top) of skip_flag flag stored at (8x8) level
1003     * 1 bit per (8x8)
1004     * read and written as a UWORD32
1005     * LSB gives skip_flag for 0th 8x8 and MSB gives skip_flag for 31st 8x8 and so on
1006     * This is independent of CTB size or minCU size
1007     * Packed format requires extra calculations in extracting required bits but makes it easier
1008     * to store skip data for larger sizes such as 32 x 32 where 4 bits need to be set instead of
1009     * 4 bytes or for 64 x 64 where 8 bits need to be set instead of 8 bytes.
1010     */
1011    UWORD32 *pu4_skip_cu_top;
1012
1013    /**
1014     * Array to hold one 64 pixel column (left) of skip_flag flag stored at (8x8) level
1015     * 1 bit per (8x8)
1016     * read and written as a UWORD32
1017     * LSB gives skip_flag for 0th 8x8 and MSB gives skip for 31st 8x8 and so on
1018     * This is independent of CTB size and allocated to store data for 64 pixels, of
1019     * this only first ctb_size number of bits (starting from MSB) will have valid data
1020     * This is also independent of min CU size and data is stored at 8x8 level.
1021     * Since only 8 bits are needed to represent left 64 pixels at 8x8 level, this is not an array
1022     */
1023    UWORD32 u4_skip_cu_left;
1024
1025    /**
1026     * Array to hold one row (top) of coding_tree_depth stored at (8x8) level
1027     * 2 bits per (8x8) pixels
1028     * read and written as a WORD32
1029     * 2 LSBits give coding_tree_depth for 0th 8x8 and 2 MSBits give coding_tree_depth for 15th 8x8 and so on
1030     * This is independent of CTB size or minCU size
1031     */
1032    UWORD32 *pu4_ct_depth_top;
1033
1034    /**
1035     * Array to hold one 64 pixel column (left) of coding_tree_depth stored at (8x8) level
1036     * 2 bits per (8x8) pixels
1037     * read and written as a WORD32
1038     * 2 LSBits give coding_tree_depth for 0th 8x8 and 2 MSBits give coding_tree_depth for 15th 8x8 and so on
1039     * This is independent of CTB size and allocated to store data for 64 pixels, of
1040     * this only first ctb_size * 2 number of bits (starting from MSB) will have valid data
1041     * This is also independent of min CU size and data is stored at 8x8 level.
1042     * Since only 16 bits are needed to represent left 64 pixels at 8x8 level, this is not an array
1043     */
1044    UWORD32 u4_ct_depth_left;
1045
1046    /**
1047     * Array to hold top (one row) luma_intra_pred_mode stored at (4x4) level for a CTB
1048     * 8 bits per (4x4) pixels
1049     * read and written as a UWORD8
1050     * This is independent of CTB size or minCU size
1051     * This is independent of CTB size and allocated to store data for 64 pixels i.e. 64 bits is the size
1052     * Note this data is used only within a CTB, There is no inter CTB dependencies for this
1053     */
1054    UWORD8 *pu1_luma_intra_pred_mode_top;
1055
1056    /**
1057     * Array to hold  left (one column) luma_intra_pred_mode stored at (4x4) level for a CTB
1058     * 8 bits per (4x4) pixels
1059     * read and written as a UWORD8
1060     * This is independent of CTB size and allocated to store data for 64 pixels i.e. 64 bits is the size
1061     * This is also independent of min CU size and data is stored at 8x8 level.
1062     * This is used for prediction of next CTB within a row in a slice or tile
1063     */
1064    UWORD8 *pu1_luma_intra_pred_mode_left;
1065
1066
1067    /**
1068     * Pointer to base of Video parameter set structure array
1069     */
1070    vps_t *ps_vps_base;
1071
1072    /**
1073     * Pointer to base of Sequence parameter set structure array
1074     */
1075    sps_t *ps_sps_base;
1076
1077    /**
1078     * Pointer to base of Picture parameter set structure array
1079     */
1080    pps_t *ps_pps_base;
1081
1082    /**
1083     * Pointer to base of slice header structure array
1084     */
1085    slice_header_t *ps_slice_hdr_base;
1086
1087    /**
1088     * Pointer to current slice header structure
1089     */
1090    slice_header_t *ps_slice_hdr;
1091
1092
1093    /**
1094     * Error code during parse stage
1095     */
1096    WORD32 i4_error_code;
1097
1098    /**
1099     * Void pointer to process job context
1100     */
1101    void *pv_proc_jobq;
1102
1103    /* Cabac context */
1104    cab_ctxt_t s_cabac;
1105
1106    /* Current Coding tree depth */
1107    WORD32 i4_ct_depth;
1108
1109    /** Flag to signal end of frame */
1110    WORD32 i4_end_of_frame;
1111
1112    /**
1113     * Index of the next CTB parsed
1114     */
1115    WORD32 i4_next_ctb_indx;
1116
1117    /**
1118     * Pointer to the structure that contains BS and QP frame level arrays
1119     */
1120    bs_ctxt_t s_bs_ctxt;
1121
1122    /**
1123     * Pointer to the structure that contains deblock context
1124     */
1125    deblk_ctxt_t s_deblk_ctxt;
1126
1127    /**
1128     * Pointer to the structure that contains sao context
1129     */
1130    sao_ctxt_t s_sao_ctxt;
1131
1132    /**
1133     * QP Array for the current CTB
1134     * Used in QP prediction
1135     */
1136    WORD8 ai1_8x8_cu_qp[MAX_CU_IN_CTB];
1137
1138
1139    /**
1140     * Pointer to frame level sao_t for the current frame being parsed
1141     */
1142    sao_t *ps_pic_sao;
1143
1144    /**
1145     * Abs POC count of the frame
1146     */
1147    WORD32 i4_abs_pic_order_cnt;
1148
1149    /**
1150     * Pointer points to mv_buffer of current frame
1151     */
1152    mv_buf_t *ps_cur_mv_buf;
1153
1154    /**
1155     * Variable to store the next ctb count to compute pu idx
1156     */
1157    WORD32 i4_next_pu_ctb_cnt;
1158
1159    /**
1160     * Variable to store the next ctb count to compute tu idx
1161     */
1162    WORD32 i4_next_tu_ctb_cnt;
1163
1164
1165}parse_ctxt_t;
1166
1167/**
1168 * Pixel processing thread context
1169 */
1170
1171typedef struct
1172{
1173    /* Pointer to codec context
1174     *
1175     */
1176    codec_t *ps_codec;
1177
1178    /**
1179     * CTB's x position within a picture in raster scan in CTB units
1180     */
1181    WORD32 i4_ctb_x;
1182
1183    /**
1184     * CTB's y position within a picture in raster scan in CTB units
1185     */
1186
1187    WORD32 i4_ctb_y;
1188
1189    /**
1190     * CTB's x position within a Tile in raster scan in CTB units
1191     */
1192    WORD32 i4_ctb_tile_x;
1193
1194    /**
1195     * CTB's y position within a Tile in raster scan in CTB units
1196     */
1197
1198    WORD32 i4_ctb_tile_y;
1199
1200    /**
1201     * CTB's x position within a Slice in raster scan in CTB units
1202     */
1203    WORD32 i4_ctb_slice_x;
1204
1205    /**
1206     * CTB's y position within a Slice in raster scan in CTB units
1207     */
1208
1209    WORD32 i4_ctb_slice_y;
1210
1211    /**
1212     * Current tile being processed
1213     */
1214    tile_t *ps_tile;
1215
1216    /**
1217     * Current slice idx - Used in multi-core cases to store slice index for
1218     * each ctb for sao filtering.
1219     */
1220    WORD32 i4_cur_slice_idx;
1221
1222    /**
1223     * Current tile idx - Used in multi-core cases to store tile index for
1224     * each ctb for sao filtering.
1225     */
1226    WORD32 i4_cur_tile_idx;
1227    /**
1228     * Pointer to current PPS
1229     */
1230    pps_t *ps_pps;
1231
1232    /**
1233     * Pointer to current SPS
1234     */
1235    sps_t *ps_sps;
1236
1237    /**
1238     * Pointer to current slice header structure
1239     */
1240    slice_header_t *ps_slice_hdr;
1241
1242    /**
1243     * Error code during parse stage
1244     */
1245    WORD32 i4_error_code;
1246
1247    /**
1248     * Signal that pic_init is called first time
1249     */
1250    WORD32 i4_first_pic_init;
1251
1252    /**
1253     * Pointer frame level TU subblock coeff data
1254     */
1255    void *pv_pic_tu_coeff_data;
1256
1257    /**
1258     * Pointer to TU subblock coeff data and number of subblocks and scan idx
1259     * Incremented each time a coded subblock is processed
1260     *
1261     */
1262    void *pv_tu_coeff_data;
1263
1264    /**
1265     * Current TU structure - set to CTB tu_t pointer at the start of CTB processing and incremented
1266     * for every TU
1267     */
1268    tu_t *ps_tu;
1269
1270    /**
1271     * Current ctb's TU map
1272     */
1273    UWORD8 *pu1_tu_map;
1274
1275    /**
1276     * Current PU structure - set to CTB pu_t pointer at the start of CTB processing and incremented
1277     * for every TU
1278     */
1279    pu_t *ps_pu;
1280
1281    /**
1282     * Points to an array of TU indices which is used to identify
1283     * start index of tu_t in ps_pic_tu and also to identify number of
1284     * TUs in the current CTB by subtracting current idx from next CTB's
1285     * TU idx
1286     */
1287    UWORD32 *pu4_pic_tu_idx;
1288
1289    /**
1290     * Points to an array of PU indices which is used to identify
1291     * start index of pu_t in ps_pic_pu and also to identify number of
1292     * PUs in the current CTB by subtracting current idx from next CTB's
1293     * PU idx
1294     */
1295    UWORD32 *pu4_pic_pu_idx;
1296
1297    /**
1298     * Pointer to tu_map for the current frame being parsed
1299     */
1300    UWORD8 *pu1_pic_tu_map;
1301
1302    /**
1303      * Pointer to pu_map for the current frame being parsed
1304      * where MVs and Intra pred modes will be updated
1305      */
1306    UWORD8 *pu1_pic_pu_map;
1307
1308    /**
1309     * Pointer to frame level pu_t for the current frame being parsed
1310     * where MVs and Intra pred modes will be updated
1311     */
1312    pu_t *ps_pic_pu;
1313
1314    /** PU Index map per CTB. The indices in this map are w.r.t picture pu array and not
1315     * w.r.t CTB pu array.
1316     * This will be used during mv prediction and since neighbours will have different CTB pu map
1317     * it will be easier if they all have indices w.r.t picture level PU array rather than CTB level
1318     * PU array.
1319     * pu1_pic_pu_map is map w.r.t CTB's pu_t array
1320     */
1321    UWORD32 *pu4_pic_pu_idx_map;
1322
1323    /**
1324     * PU Index of top 4x4 neighbors stored for an entire row
1325     */
1326    UWORD32 *pu4_pic_pu_idx_top;
1327
1328    /**
1329     * PU Index of left 4x4 neighbors stored for 64 pixels
1330     */
1331    UWORD32 *pu4_pic_pu_idx_left;
1332
1333    /**
1334     * Holds top left PU index at CTB level - top left gets overwritten
1335     * by left CTB while updating top array. Before updating top at CTB
1336     * level required top-left index is backed up in the following
1337     */
1338    UWORD32 u4_ctb_top_left_pu_idx;
1339
1340    /**
1341     * Pointer to frame level tu_t for the current frame being parsed
1342     * where transform unit related info will be updated
1343     */
1344    tu_t *ps_pic_tu;
1345
1346
1347    /**
1348    * Current PU structure - set to CTB pu_map pointer at the start of CTB parsing
1349    */
1350    UWORD8 *pu1_pu_map;
1351
1352    /** Current MV Bank's buffer ID */
1353    WORD32 i4_cur_mv_bank_buf_id;
1354
1355    /**
1356     * Current pictures intra mode map at 8x8 level
1357     */
1358    UWORD8 *pu1_pic_intra_flag;
1359
1360    /**
1361     * Current pictures loop filter flag map at 8x8 level
1362     */
1363    UWORD8 *pu1_pic_no_loop_filter_flag;
1364
1365    /**
1366     * Void pointer to process job context
1367     */
1368
1369    void *pv_proc_jobq;
1370
1371    /**
1372     * Number of CTBs to be processed in the current Job
1373     */
1374    WORD32 i4_ctb_cnt;
1375    /**
1376     * ID for the current context - Used for debugging
1377     */
1378    WORD32 i4_id;
1379
1380    /**
1381     * Flag to indicate if parsing status has to be checked
1382     * Needed when parsing and processing are done in different threads
1383     */
1384    WORD32 i4_check_parse_status;
1385
1386    /**
1387     * Flag to indicate if processing status of top row CTBs has to be checked
1388     * Needed when processing of different rows is done in different threads
1389     */
1390    WORD32 i4_check_proc_status;
1391
1392    /**
1393     * Holds Intra dequantization matrices
1394     */
1395    WORD16 *api2_dequant_intra_matrix[4];
1396
1397    /**
1398     * Holds Inter dequantization matrices
1399     */
1400    WORD16 *api2_dequant_inter_matrix[4];
1401
1402
1403    /**
1404     * Temporary buffer 1 - Used as a scratch in inter_pred_ctb()
1405     */
1406    WORD16 *pi2_inter_pred_tmp_buf1;
1407
1408    /**
1409     * Temporary buffer 2 - Used as a scratch in inter_pred_ctb()
1410     */
1411    WORD16 *pi2_inter_pred_tmp_buf2;
1412
1413    /**
1414     * Temporary buffer 3 - Used as a scratch in inter_pred_ctb()
1415     */
1416    WORD16 *pi2_inter_pred_tmp_buf3;
1417
1418    /**
1419     * The above temporary buffers' stride
1420     */
1421    WORD32 i4_inter_pred_tmp_buf_strd;
1422    /**
1423     * Picture stride
1424     * Used as prediction stride, destination stride while computing inverse transform
1425     */
1426    WORD32 i4_pic_strd;
1427
1428    /**
1429     * Picture qp offset for U
1430     */
1431    WORD8 i1_pic_cb_qp_offset;
1432
1433    /**
1434     * Slice qp offset for U
1435     */
1436    WORD32 i1_slice_cb_qp_offset;
1437
1438    /**
1439     * Picture qp offset for V
1440     */
1441    WORD8 i1_pic_cr_qp_offset;
1442
1443    /**
1444     * Slice qp offset for V
1445     */
1446    WORD32 i1_slice_cr_qp_offset;
1447
1448    /** Pointer to current picture buffer structure */
1449    pic_buf_t *ps_cur_pic;
1450
1451    /** Current pic_buf's picture buffer id */
1452    WORD32 i4_cur_pic_buf_id;
1453
1454    /** Pointer to 0th luma pixel in current pic */
1455    UWORD8 *pu1_cur_pic_luma;
1456
1457    /** Pointer to 0th chroma pixel in current pic */
1458    UWORD8 *pu1_cur_pic_chroma;
1459
1460    /** Intermediate buffer to be used during inverse transform */
1461    WORD16 *pi2_itrans_intrmd_buf;
1462
1463    /** Buffer to hold output of inverse scan */
1464    WORD16 *pi2_invscan_out;
1465
1466    /**
1467     *  Top availability for current CTB level
1468     */
1469    UWORD8 u1_top_ctb_avail;
1470
1471    /**
1472     *  Top right availability for current CTB level
1473     */
1474    UWORD8 u1_top_rt_ctb_avail;
1475    /**
1476     *  Top left availability for current CTB level
1477     */
1478    UWORD8 u1_top_lt_ctb_avail;
1479    /**
1480     *  left availability for current CTB level
1481     */
1482    UWORD8 u1_left_ctb_avail;
1483    /**
1484     *  TU count in current CTB
1485     */
1486    WORD32 i4_ctb_tu_cnt;
1487
1488    /**
1489     *  Recon pointer to current CTB luma
1490     */
1491    UWORD8 *pu1_cur_ctb_luma;
1492    /**
1493     *  Recon pointer to current CTB chroma
1494     */
1495    UWORD8 *pu1_cur_ctb_chroma;
1496
1497    /**
1498     *  PU count in current CTB
1499     */
1500    WORD32 i4_ctb_pu_cnt;
1501
1502    /**
1503     *  PU count in current CTB
1504     */
1505    WORD32 i4_ctb_start_pu_idx;
1506
1507    /* Pointer to a structure describing output display buffer */
1508    ivd_out_bufdesc_t *ps_out_buffer;
1509
1510    /** Flag to indicate if ps_proc was intialized at least once in a frame.
1511     * This is needed to handle cases where a core starts to handle format conversion jobs directly
1512     */
1513    WORD32 i4_init_done;
1514
1515    /**
1516     * Pointer to the structure that contains BS and QP frame level arrays
1517     */
1518    bs_ctxt_t s_bs_ctxt;
1519
1520    /**
1521     * Pointer to the structure that contains deblock context
1522     */
1523    deblk_ctxt_t s_deblk_ctxt;
1524
1525    /**
1526     * Pointer to the structure that contains sao context
1527     */
1528    sao_ctxt_t s_sao_ctxt;
1529
1530    /**
1531     * Points to the array of slice indices which is used to identify the independent
1532     * slice to which each CTB in a frame belongs.
1533     */
1534    UWORD16 *pu1_slice_idx;
1535
1536    /**
1537     * Points to the array of slice indices which is used to identify the slice
1538     *  to which each CTB in a frame belongs.
1539     */
1540    UWORD16 *pu1_tile_idx;
1541    /**
1542     * Variable to store the next ctb count to compute pu idx
1543     */
1544    WORD32 i4_next_pu_ctb_cnt;
1545
1546    /**
1547     * Variable to store the next ctb count to compute tu idx
1548     */
1549    WORD32 i4_next_tu_ctb_cnt;
1550    /**
1551     * Number of ctb's to process in one loop
1552     */
1553    WORD32 i4_nctb;
1554}process_ctxt_t;
1555
1556typedef void (*pf_inter_pred)(void *,
1557                              void *,
1558                              WORD32,
1559                              WORD32,
1560                              WORD8 *,
1561                              WORD32,
1562                              WORD32);
1563
1564
1565typedef void (*pf_intra_pred)(UWORD8 *pu1_ref,
1566                              WORD32 src_strd,
1567                              UWORD8 *pu1_dst,
1568                              WORD32 dst_strd,
1569                              WORD32 nt,
1570                              WORD32 mode);
1571
1572typedef void (*pf_itrans_recon)(WORD16 *pi2_src,
1573                                WORD16 *pi2_tmp,
1574                                UWORD8 *pu1_pred,
1575                                UWORD8 *pu1_dst,
1576                                WORD32 src_strd,
1577                                WORD32 pred_strd,
1578                                WORD32 dst_strd,
1579                                WORD32 zero_cols,
1580                                WORD32 zero_rows);
1581
1582typedef void (*pf_recon)(WORD16 *pi2_src,
1583                         UWORD8 *pu1_pred,
1584                         UWORD8 *pu1_dst,
1585                         WORD32 src_strd,
1586                         WORD32 pred_strd,
1587                         WORD32 dst_strd,
1588                         WORD32 zero_cols);
1589
1590typedef void (*pf_itrans_recon_dc)(UWORD8 *pu1_pred,
1591                                   UWORD8 *pu1_dst,
1592                                   WORD32 pred_strd,
1593                                   WORD32 dst_strd,
1594                                   WORD32 log2_trans_size,
1595                                   WORD16 i2_coeff_value);
1596
1597
1598typedef void (*pf_sao_luma)(UWORD8 *,
1599                            WORD32,
1600                            UWORD8 *,
1601                            UWORD8 *,
1602                            UWORD8 *,
1603                            UWORD8 *,
1604                            UWORD8 *,
1605                            UWORD8 *,
1606                            WORD8 *,
1607                            WORD32,
1608                            WORD32);
1609
1610typedef void (*pf_sao_chroma)(UWORD8 *,
1611                              WORD32,
1612                              UWORD8 *,
1613                              UWORD8 *,
1614                              UWORD8 *,
1615                              UWORD8 *,
1616                              UWORD8 *,
1617                              UWORD8 *,
1618                              WORD8 *,
1619                              WORD8 *,
1620                              WORD32,
1621                              WORD32);
1622
1623/**
1624 * Codec context
1625 */
1626
1627struct _codec_t
1628{
1629    /**
1630     * Width : pic_width_in_luma_samples
1631     */
1632    WORD32 i4_wd;
1633
1634    /**
1635     * Height : pic_height_in_luma_samples
1636     */
1637    WORD32 i4_ht;
1638
1639    /**
1640     * Display width after cropping
1641     */
1642    WORD32 i4_disp_wd;
1643
1644    /**
1645     * Display height after cropping
1646     */
1647    WORD32 i4_disp_ht;
1648
1649    /**
1650     * Display stride
1651     */
1652    WORD32 i4_disp_strd;
1653
1654    /**
1655     * Stride of reference buffers.
1656     * For shared mode even display buffer will use the same stride
1657     */
1658    WORD32 i4_strd;
1659
1660    /**
1661     * Number of cores to be used
1662     */
1663    WORD32 i4_num_cores;
1664
1665    /**
1666     * RASL output flag
1667     */
1668    WORD32 i4_rasl_output_flag;
1669
1670    /**
1671     * This flag is set if the next picture received is a CRA and has to be treated as a first pic in the video sequence
1672     * For example, it is set, if an EOS (end of stream) NAL is received
1673     */
1674    WORD32 i4_cra_as_first_pic;
1675
1676    /**
1677     * Pictures that are are degraded
1678     * 0 : No degrade
1679     * 1 : Only on non-reference frames
1680     * 2 : Use interval specified by u4_nondegrade_interval
1681     * 3 : All non-key frames
1682     * 4 : All frames
1683     */
1684    WORD32                                     i4_degrade_pics;
1685
1686    /**
1687     * Interval for pictures which are completely decoded without any degradation
1688     */
1689    WORD32                                     i4_nondegrade_interval;
1690
1691    /**
1692     * bit position (lsb is zero): Type of degradation
1693     * 0 : Disable SAO
1694     * 1 : Disable deblocking
1695     * 2 : Faster inter prediction filters
1696     * 3 : Fastest inter prediction filters
1697     */
1698    WORD32                                     i4_degrade_type;
1699
1700    /** Degrade pic count, Used to maintain the interval between non-degraded pics
1701     *
1702     */
1703    WORD32  i4_degrade_pic_cnt;
1704
1705    /**
1706     * Total number of display buffers to be used
1707     * In case of shared mode, this will be number of reference frames
1708     */
1709    WORD32 i4_num_disp_bufs;
1710
1711    /**
1712     * Flag to enable shared display buffer mode
1713     */
1714    WORD32 i4_share_disp_buf;
1715
1716    /**
1717     * Chroma format of display buffers.
1718     In shared mode only 420SP_UV and 420SP_VU are supported
1719     */
1720    IV_COLOR_FORMAT_T e_chroma_fmt;
1721
1722    /**
1723     * Chroma format of reference buffers.
1724     * In non-shared mode it will be 420SP_UV
1725     * In shared mode only 420SP_UV and 420SP_VU are supported
1726     */
1727    IV_COLOR_FORMAT_T e_ref_chroma_fmt;
1728
1729    /**
1730     * Frame skip mode
1731     */
1732    IVD_FRAME_SKIP_MODE_T e_pic_skip_mode;
1733
1734    /**
1735     * Display or decode order dump of output
1736     */
1737    IVD_DISPLAY_FRAME_OUT_MODE_T e_pic_out_order;
1738
1739    /**
1740     * Coding type of the picture that is decoded
1741     */
1742    IV_PICTURE_CODING_TYPE_T e_dec_pic_type;
1743
1744    /**
1745     * Flag to signal if a frame was decoded in this call
1746     */
1747    WORD32 i4_pic_decoded;
1748
1749    /**
1750     * Flag to signal if picture data is present in the current input bitstream
1751     */
1752    WORD32 i4_pic_present;
1753
1754    /**
1755     * Flag to disable deblocking of a frame
1756     */
1757    WORD32 i4_disable_deblk_pic;
1758
1759    /**
1760     * Flag to disable sao of a frame
1761     */
1762    WORD32 i4_disable_sao_pic;
1763
1764    /**
1765     * Flag to use full pel MC
1766     */
1767    WORD32 i4_fullpel_inter_pred;
1768    /**
1769     * Flush mode
1770     */
1771    WORD32 i4_flush_mode;
1772
1773    /**
1774     * Decode header mode
1775     */
1776    WORD32 i4_header_mode;
1777
1778    /**
1779     * Header in slice mode
1780     */
1781    WORD32 i4_header_in_slice_mode;
1782
1783    /**
1784     * Flag to signal sps done
1785     */
1786    WORD32 i4_sps_done;
1787
1788    /**
1789     * Flag to signal pps done
1790     */
1791    WORD32 i4_pps_done;
1792
1793    /**
1794     * To signal successful completion of init
1795     */
1796    WORD32 i4_init_done;
1797
1798    /**
1799     * To signal that at least one picture was decoded
1800     */
1801    WORD32 i4_first_pic_done;
1802
1803    /**
1804     * To signal error in slice
1805     */
1806    WORD32 i4_slice_error;
1807
1808    /**
1809     * Reset flag - Codec is reset if this flag is set
1810     */
1811    WORD32 i4_reset_flag;
1812
1813    /**
1814     * Number of pictures decoded till now
1815     */
1816    UWORD32 u4_pic_cnt;
1817
1818    /**
1819     * Number of pictures displayed till now
1820     */
1821    UWORD32 u4_disp_cnt;
1822
1823    /**
1824     * Current error code
1825     */
1826    WORD32 i4_error_code;
1827
1828    /**
1829     * Pointer to input bitstream. This is incremented everytime a NAL is processed
1830     */
1831    UWORD8 *pu1_inp_bitsbuf;
1832
1833    /**
1834     * Offset to first byte after the start code in current NAL
1835     */
1836    WORD32 i4_nal_ofst;
1837
1838    /**
1839     * Length of the NAL unit including the emulation bytes
1840     */
1841    WORD32 i4_nal_len;
1842
1843    /**
1844     * Number of emulation prevention bytes present in the current NAL
1845     */
1846    WORD32 i4_num_emln_bytes;
1847
1848    /**
1849     * Number of bytes remaining in the input bitstream
1850     */
1851    /**
1852     * Decremented everytime a NAL is processed
1853     */
1854    WORD32 i4_bytes_remaining;
1855
1856    /**
1857     * Pointer to bitstream after emulation prevention
1858     */
1859    UWORD8 *pu1_bitsbuf;
1860
1861    /**
1862     * Pointer to static bitstream after emulation prevention
1863     * This is a fixed size buffer used initially till SPS is decoded
1864     */
1865    UWORD8 *pu1_bitsbuf_static;
1866
1867    /**
1868     * Pointer to dynamic bitstream after emulation prevention
1869     * This is allocated after SPS is done, based on width and height
1870     */
1871    UWORD8 *pu1_bitsbuf_dynamic;
1872
1873    /**
1874     * Size of intermediate bitstream buffer
1875     */
1876    UWORD32 u4_bitsbuf_size;
1877
1878    /**
1879     * Size of intermediate static bitstream buffer
1880     */
1881    UWORD32 u4_bitsbuf_size_static;
1882
1883    /**
1884     * Size of intermediate dynamic bitstream buffer
1885     */
1886    UWORD32 u4_bitsbuf_size_dynamic;
1887
1888    /**
1889     * Pointer to hold TU data for a set of CTBs or a picture
1890     */
1891    void *pv_tu_data;
1892
1893    /**
1894     * Process Job queue buffer base
1895     */
1896    void *pv_proc_jobq_buf;
1897
1898    /**
1899     * Process Job Queue mem tab size
1900     */
1901    WORD32 i4_proc_jobq_buf_size;
1902
1903    /** Parse status: one byte per CTB */
1904    UWORD8 *pu1_parse_map;
1905
1906    /** Process status: one byte per CTB */
1907    UWORD8 *pu1_proc_map;
1908    /**
1909     * Current pictures intra mode map at 8x8 level
1910     */
1911    UWORD8 *pu1_pic_intra_flag;
1912
1913    /**
1914     * No LPF buffer base
1915     */
1916    UWORD8 *pu1_pic_no_loop_filter_flag_base;
1917
1918    /**
1919     * Current pictures loop filter flag map at 8x8 level
1920     */
1921    UWORD8 *pu1_pic_no_loop_filter_flag;
1922    /**
1923     * MV Bank buffer manager
1924     */
1925    void *pv_mv_buf_mgr;
1926
1927    /**
1928     * Pointer to MV Buf structure array
1929     */
1930    void *ps_mv_buf;
1931
1932    /** Holds the number of mv_buf_t structures allocated */
1933    WORD32 i4_max_dpb_size;
1934
1935    /**
1936     * Base address for Motion Vector bank buffer
1937     */
1938    void *pv_mv_bank_buf_base;
1939
1940    /**
1941     * MV Bank size allocated
1942     */
1943    WORD32 i4_total_mv_bank_size;
1944
1945    /**
1946     * Picture buffer manager
1947     */
1948    void *pv_pic_buf_mgr;
1949
1950    /**
1951     * Pointer to Pic Buf structure array
1952     */
1953    void *ps_pic_buf;
1954
1955    /**
1956     * Base address for Picture buffer
1957     */
1958    void *pv_pic_buf_base;
1959
1960    /**
1961     * Total pic buffer size allocated
1962     */
1963    WORD32 i4_total_pic_buf_size;
1964
1965    /**
1966     * Current chroma buffer base - used for shared mode with 420p output
1967     */
1968    UWORD8 *pu1_cur_chroma_ref_buf;
1969
1970    /**
1971     * Picture buffer manager
1972     */
1973    void *pv_disp_buf_mgr;
1974
1975    /**
1976     * Current display buffer's buffer ID
1977     */
1978    WORD32 i4_disp_buf_id;
1979
1980    /**
1981     * Current display buffer
1982     */
1983    pic_buf_t *ps_disp_buf;
1984
1985    /**
1986     * Pointer to dpb manager structure
1987     */
1988    void *pv_dpb_mgr;
1989
1990    /**
1991     * Scaling matrices for each PPS
1992     */
1993    WORD16 *pi2_scaling_mat;
1994
1995    /**
1996     * Array containing Tile information for each PPS
1997     */
1998    tile_t *ps_tile;
1999
2000    /**
2001     * Timestamp associated with the current display output
2002     */
2003    UWORD32 u4_ts;
2004
2005    /**
2006     * Pointer to base of Video parameter set structure array
2007     */
2008    vps_t *ps_vps_base;
2009
2010    /**
2011     * Pointer to base of Sequence parameter set structure array
2012     */
2013    sps_t *ps_sps_base;
2014
2015    /**
2016     * Pointer to base of Picture parameter set structure array
2017     */
2018    pps_t *ps_pps_base;
2019
2020    /**
2021     * Pointer to base of slice header structure array
2022     */
2023    slice_header_t *ps_slice_hdr_base;
2024    /**
2025     * Pointer to base of entry point offsets in a frame
2026     */
2027    WORD32 *pi4_entry_ofst;
2028
2029    /**
2030     * Current offset in pi4_entry_ofst
2031     */
2032    WORD32 i4_cur_entry_ofst;
2033
2034    /**
2035     *  Parsing context
2036     */
2037    parse_ctxt_t s_parse;
2038
2039    /**
2040     * Processing context - One for each processing thread
2041     */
2042    process_ctxt_t as_process[MAX_PROCESS_THREADS];
2043
2044    /**
2045     * Thread handle for each of the processing threads
2046     */
2047    void *apv_process_thread_handle[MAX_PROCESS_THREADS];
2048
2049    /**
2050     * Thread created flag for each of the processing threads
2051     */
2052    WORD32 ai4_process_thread_created[MAX_PROCESS_THREADS];
2053
2054    /**
2055     * Void pointer to process job context
2056     */
2057    void *pv_proc_jobq;
2058
2059    /* Number of CTBs processed together for better instruction cache handling */
2060    WORD32 i4_proc_nctb;
2061
2062    /**
2063     * Previous POC lsb
2064     */
2065    WORD32 i4_prev_poc_lsb;
2066
2067    /**
2068     * Previous POC msb
2069     */
2070    WORD32 i4_prev_poc_msb;
2071
2072    /**
2073     * Max POC lsb that has arrived till now
2074     */
2075    WORD32 i4_max_prev_poc_lsb;
2076
2077    /** Context for format conversion */
2078    fmt_conv_t s_fmt_conv;
2079
2080    /** Pointer to a structure describing output display buffer */
2081    ivd_out_bufdesc_t *ps_out_buffer;
2082    /**
2083     * Variable to store the next ctb count to compute pu idx
2084     */
2085    WORD32 i4_next_pu_ctb_cnt;
2086
2087    /**
2088     * Variable to store the next ctb count to compute tu idx
2089     */
2090    WORD32 i4_next_tu_ctb_cnt;
2091
2092    /**  Active SPS id - mainly to be used during codec initializations in shared mode */
2093    WORD32 i4_sps_id;
2094
2095    /**  Number of ctbs to be decoded in one process call */
2096    UWORD32 u4_nctb;
2097
2098    /** Flag to enable scheduling of format conversion jobs ahead of processing jobs */
2099    UWORD32 u4_enable_fmt_conv_ahead;
2100
2101    /** Mask used to change MVs to full pel when configured to run in reduced complexity mode */
2102    WORD32 i4_mv_frac_mask;
2103
2104    /** Memory holding tile indices */
2105    UWORD8 *pu1_tile_idx_base;
2106
2107    /** Callback for aligned allocation */
2108    void *(*pf_aligned_alloc)(void *pv_mem_ctxt, WORD32 alignment, WORD32 size);
2109
2110    /** Callback for aligned free */
2111    void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
2112
2113    /** Memory context passed from application */
2114    void *pv_mem_ctxt;
2115
2116    /** Base address of reference buffrers allocated */
2117    UWORD8 *pu1_ref_pic_buf_base;
2118
2119    /** Flag to indicate if dynamic buffers are allocated */
2120    UWORD32 u4_allocate_dynamic_done;
2121
2122    /** Flag to signal display order */
2123    IVD_DISPLAY_FRAME_OUT_MODE_T  e_frm_out_mode;
2124
2125    /**  Funtion pointers for inter_pred leaf level functions */
2126    pf_inter_pred apf_inter_pred[22];
2127
2128    /**  Funtion pointers for inter_pred_luma leaf level functions */
2129    pf_intra_pred apf_intra_pred_luma[11];
2130
2131    /**  Funtion pointers for inter_pred_chroma leaf level functions */
2132    pf_intra_pred apf_intra_pred_chroma[11];
2133
2134    /**  Funtion pointers for itrans_recon leaf level functions */
2135    pf_itrans_recon apf_itrans_recon[8];
2136
2137    /**  Funtion pointers for recon leaf level functions */
2138    pf_recon apf_recon[8];
2139
2140    /**  Funtion pointers for itrans_recon_dc leaf level functions */
2141    pf_itrans_recon_dc apf_itrans_recon_dc[2];
2142
2143    /**  Funtion pointers for sao_luma leaf level functions */
2144    pf_sao_luma apf_sao_luma[4];
2145
2146    /**  Funtion pointers for sao_chroma leaf level functions */
2147    pf_sao_chroma apf_sao_chroma[4];
2148
2149    /**  Funtion pointers for all the leaf level functions */
2150    func_selector_t s_func_selector;
2151    /**  Processor architecture */
2152    IVD_ARCH_T e_processor_arch;
2153    /**  Processor soc */
2154    IVD_SOC_T e_processor_soc;
2155
2156    /** Display buffer array - for shared mode */
2157    ivd_out_bufdesc_t s_disp_buffer[IVD_VIDDEC_MAX_IO_BUFFERS];
2158
2159    /** Number of active display buffers - for shared mode */
2160    WORD32  i4_share_disp_buf_cnt;
2161};
2162
2163#endif /* _IHEVCD_STRUCTS_H_ */
2164