• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_
40 typedef enum
41 {
42     INIT_DONE, HEADER_DONE, FIRST_FRAME_DONE,
43 }CODEC_STATE_T;
44 
45 
46 
47 typedef struct _codec_t codec_t;
48 
49 /** Structure to hold format conversion context */
50 typedef 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  */
62 typedef 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  */
100 typedef 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 
124 typedef enum
125 {
126     CMD_PROCESS,
127     CMD_FMTCONV,
128 }JOBQ_CMD_T;
129 
130 /**
131  * Structure to represent a processing job entry
132  */
133 typedef 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  */
169 typedef 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 
217 typedef 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 
315 typedef 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 
464 typedef 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 
533 typedef 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 
693 typedef 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  */
786 typedef 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      * SEI parameters
1166      */
1167     sei_params_t s_sei_params;
1168 }parse_ctxt_t;
1169 
1170 /**
1171  * Pixel processing thread context
1172  */
1173 
1174 typedef struct
1175 {
1176     /* Pointer to codec context
1177      *
1178      */
1179     codec_t *ps_codec;
1180 
1181     /**
1182      * CTB's x position within a picture in raster scan in CTB units
1183      */
1184     WORD32 i4_ctb_x;
1185 
1186     /**
1187      * CTB's y position within a picture in raster scan in CTB units
1188      */
1189 
1190     WORD32 i4_ctb_y;
1191 
1192     /**
1193      * CTB's x position within a Tile in raster scan in CTB units
1194      */
1195     WORD32 i4_ctb_tile_x;
1196 
1197     /**
1198      * CTB's y position within a Tile in raster scan in CTB units
1199      */
1200 
1201     WORD32 i4_ctb_tile_y;
1202 
1203     /**
1204      * CTB's x position within a Slice in raster scan in CTB units
1205      */
1206     WORD32 i4_ctb_slice_x;
1207 
1208     /**
1209      * CTB's y position within a Slice in raster scan in CTB units
1210      */
1211 
1212     WORD32 i4_ctb_slice_y;
1213 
1214     /**
1215      * Current tile being processed
1216      */
1217     tile_t *ps_tile;
1218 
1219     /**
1220      * Current slice idx - Used in multi-core cases to store slice index for
1221      * each ctb for sao filtering.
1222      */
1223     WORD32 i4_cur_slice_idx;
1224 
1225     /**
1226      * Current tile idx - Used in multi-core cases to store tile index for
1227      * each ctb for sao filtering.
1228      */
1229     WORD32 i4_cur_tile_idx;
1230     /**
1231      * Pointer to current PPS
1232      */
1233     pps_t *ps_pps;
1234 
1235     /**
1236      * Pointer to current SPS
1237      */
1238     sps_t *ps_sps;
1239 
1240     /**
1241      * Pointer to current slice header structure
1242      */
1243     slice_header_t *ps_slice_hdr;
1244 
1245     /**
1246      * Error code during parse stage
1247      */
1248     WORD32 i4_error_code;
1249 
1250     /**
1251      * Signal that pic_init is called first time
1252      */
1253     WORD32 i4_first_pic_init;
1254 
1255     /**
1256      * Pointer frame level TU subblock coeff data
1257      */
1258     void *pv_pic_tu_coeff_data;
1259 
1260     /**
1261      * Pointer to TU subblock coeff data and number of subblocks and scan idx
1262      * Incremented each time a coded subblock is processed
1263      *
1264      */
1265     void *pv_tu_coeff_data;
1266 
1267     /**
1268      * Current TU structure - set to CTB tu_t pointer at the start of CTB processing and incremented
1269      * for every TU
1270      */
1271     tu_t *ps_tu;
1272 
1273     /**
1274      * Current ctb's TU map
1275      */
1276     UWORD8 *pu1_tu_map;
1277 
1278     /**
1279      * Current PU structure - set to CTB pu_t pointer at the start of CTB processing and incremented
1280      * for every TU
1281      */
1282     pu_t *ps_pu;
1283 
1284     /**
1285      * Points to an array of TU indices which is used to identify
1286      * start index of tu_t in ps_pic_tu and also to identify number of
1287      * TUs in the current CTB by subtracting current idx from next CTB's
1288      * TU idx
1289      */
1290     UWORD32 *pu4_pic_tu_idx;
1291 
1292     /**
1293      * Points to an array of PU indices which is used to identify
1294      * start index of pu_t in ps_pic_pu and also to identify number of
1295      * PUs in the current CTB by subtracting current idx from next CTB's
1296      * PU idx
1297      */
1298     UWORD32 *pu4_pic_pu_idx;
1299 
1300     /**
1301      * Pointer to tu_map for the current frame being parsed
1302      */
1303     UWORD8 *pu1_pic_tu_map;
1304 
1305     /**
1306       * Pointer to pu_map for the current frame being parsed
1307       * where MVs and Intra pred modes will be updated
1308       */
1309     UWORD8 *pu1_pic_pu_map;
1310 
1311     /**
1312      * Pointer to frame level pu_t for the current frame being parsed
1313      * where MVs and Intra pred modes will be updated
1314      */
1315     pu_t *ps_pic_pu;
1316 
1317     /** PU Index map per CTB. The indices in this map are w.r.t picture pu array and not
1318      * w.r.t CTB pu array.
1319      * This will be used during mv prediction and since neighbours will have different CTB pu map
1320      * it will be easier if they all have indices w.r.t picture level PU array rather than CTB level
1321      * PU array.
1322      * pu1_pic_pu_map is map w.r.t CTB's pu_t array
1323      */
1324     UWORD32 *pu4_pic_pu_idx_map;
1325 
1326     /**
1327      * PU Index of top 4x4 neighbors stored for an entire row
1328      */
1329     UWORD32 *pu4_pic_pu_idx_top;
1330 
1331     /**
1332      * PU Index of left 4x4 neighbors stored for 64 pixels
1333      */
1334     UWORD32 *pu4_pic_pu_idx_left;
1335 
1336     /**
1337      * Holds top left PU index at CTB level - top left gets overwritten
1338      * by left CTB while updating top array. Before updating top at CTB
1339      * level required top-left index is backed up in the following
1340      */
1341     UWORD32 u4_ctb_top_left_pu_idx;
1342 
1343     /**
1344      * Pointer to frame level tu_t for the current frame being parsed
1345      * where transform unit related info will be updated
1346      */
1347     tu_t *ps_pic_tu;
1348 
1349 
1350     /**
1351     * Current PU structure - set to CTB pu_map pointer at the start of CTB parsing
1352     */
1353     UWORD8 *pu1_pu_map;
1354 
1355     /** Current MV Bank's buffer ID */
1356     WORD32 i4_cur_mv_bank_buf_id;
1357 
1358     /**
1359      * Current pictures intra mode map at 8x8 level
1360      */
1361     UWORD8 *pu1_pic_intra_flag;
1362 
1363     /**
1364      * Current pictures loop filter flag map at 8x8 level
1365      */
1366     UWORD8 *pu1_pic_no_loop_filter_flag;
1367 
1368     /**
1369      * Void pointer to process job context
1370      */
1371 
1372     void *pv_proc_jobq;
1373 
1374     /**
1375      * Number of CTBs to be processed in the current Job
1376      */
1377     WORD32 i4_ctb_cnt;
1378     /**
1379      * ID for the current context - Used for debugging
1380      */
1381     WORD32 i4_id;
1382 
1383     /**
1384      * Flag to indicate if parsing status has to be checked
1385      * Needed when parsing and processing are done in different threads
1386      */
1387     WORD32 i4_check_parse_status;
1388 
1389     /**
1390      * Flag to indicate if processing status of top row CTBs has to be checked
1391      * Needed when processing of different rows is done in different threads
1392      */
1393     WORD32 i4_check_proc_status;
1394 
1395     /**
1396      * Holds Intra dequantization matrices
1397      */
1398     WORD16 *api2_dequant_intra_matrix[4];
1399 
1400     /**
1401      * Holds Inter dequantization matrices
1402      */
1403     WORD16 *api2_dequant_inter_matrix[4];
1404 
1405 
1406     /**
1407      * Temporary buffer 1 - Used as a scratch in inter_pred_ctb()
1408      */
1409     WORD16 *pi2_inter_pred_tmp_buf1;
1410 
1411     /**
1412      * Temporary buffer 2 - Used as a scratch in inter_pred_ctb()
1413      */
1414     WORD16 *pi2_inter_pred_tmp_buf2;
1415 
1416     /**
1417      * Temporary buffer 3 - Used as a scratch in inter_pred_ctb()
1418      */
1419     WORD16 *pi2_inter_pred_tmp_buf3;
1420 
1421     /**
1422      * The above temporary buffers' stride
1423      */
1424     WORD32 i4_inter_pred_tmp_buf_strd;
1425     /**
1426      * Picture stride
1427      * Used as prediction stride, destination stride while computing inverse transform
1428      */
1429     WORD32 i4_pic_strd;
1430 
1431     /**
1432      * Picture qp offset for U
1433      */
1434     WORD8 i1_pic_cb_qp_offset;
1435 
1436     /**
1437      * Slice qp offset for U
1438      */
1439     WORD32 i1_slice_cb_qp_offset;
1440 
1441     /**
1442      * Picture qp offset for V
1443      */
1444     WORD8 i1_pic_cr_qp_offset;
1445 
1446     /**
1447      * Slice qp offset for V
1448      */
1449     WORD32 i1_slice_cr_qp_offset;
1450 
1451     /** Pointer to current picture buffer structure */
1452     pic_buf_t *ps_cur_pic;
1453 
1454     /** Current pic_buf's picture buffer id */
1455     WORD32 i4_cur_pic_buf_id;
1456 
1457     /** Pointer to 0th luma pixel in current pic */
1458     UWORD8 *pu1_cur_pic_luma;
1459 
1460     /** Pointer to 0th chroma pixel in current pic */
1461     UWORD8 *pu1_cur_pic_chroma;
1462 
1463     /** Intermediate buffer to be used during inverse transform */
1464     WORD16 *pi2_itrans_intrmd_buf;
1465 
1466     /** Buffer to hold output of inverse scan */
1467     WORD16 *pi2_invscan_out;
1468 
1469     /**
1470      *  Top availability for current CTB level
1471      */
1472     UWORD8 u1_top_ctb_avail;
1473 
1474     /**
1475      *  Top right availability for current CTB level
1476      */
1477     UWORD8 u1_top_rt_ctb_avail;
1478     /**
1479      *  Top left availability for current CTB level
1480      */
1481     UWORD8 u1_top_lt_ctb_avail;
1482     /**
1483      *  left availability for current CTB level
1484      */
1485     UWORD8 u1_left_ctb_avail;
1486     /**
1487      *  TU count in current CTB
1488      */
1489     WORD32 i4_ctb_tu_cnt;
1490 
1491     /**
1492      *  Recon pointer to current CTB luma
1493      */
1494     UWORD8 *pu1_cur_ctb_luma;
1495     /**
1496      *  Recon pointer to current CTB chroma
1497      */
1498     UWORD8 *pu1_cur_ctb_chroma;
1499 
1500     /**
1501      *  PU count in current CTB
1502      */
1503     WORD32 i4_ctb_pu_cnt;
1504 
1505     /**
1506      *  PU count in current CTB
1507      */
1508     WORD32 i4_ctb_start_pu_idx;
1509 
1510     /* Pointer to a structure describing output display buffer */
1511     ivd_out_bufdesc_t *ps_out_buffer;
1512 
1513     /** Flag to indicate if ps_proc was intialized at least once in a frame.
1514      * This is needed to handle cases where a core starts to handle format conversion jobs directly
1515      */
1516     WORD32 i4_init_done;
1517 
1518     /**
1519      * Pointer to the structure that contains BS and QP frame level arrays
1520      */
1521     bs_ctxt_t s_bs_ctxt;
1522 
1523     /**
1524      * Pointer to the structure that contains deblock context
1525      */
1526     deblk_ctxt_t s_deblk_ctxt;
1527 
1528     /**
1529      * Pointer to the structure that contains sao context
1530      */
1531     sao_ctxt_t s_sao_ctxt;
1532 
1533     /**
1534      * Points to the array of slice indices which is used to identify the independent
1535      * slice to which each CTB in a frame belongs.
1536      */
1537     UWORD16 *pu1_slice_idx;
1538 
1539     /**
1540      * Points to the array of slice indices which is used to identify the slice
1541      *  to which each CTB in a frame belongs.
1542      */
1543     UWORD16 *pu1_tile_idx;
1544     /**
1545      * Variable to store the next ctb count to compute pu idx
1546      */
1547     WORD32 i4_next_pu_ctb_cnt;
1548 
1549     /**
1550      * Variable to store the next ctb count to compute tu idx
1551      */
1552     WORD32 i4_next_tu_ctb_cnt;
1553     /**
1554      * Number of ctb's to process in one loop
1555      */
1556     WORD32 i4_nctb;
1557 }process_ctxt_t;
1558 
1559 typedef void (*pf_inter_pred)(void *,
1560                               void *,
1561                               WORD32,
1562                               WORD32,
1563                               WORD8 *,
1564                               WORD32,
1565                               WORD32);
1566 
1567 
1568 typedef void (*pf_intra_pred)(UWORD8 *pu1_ref,
1569                               WORD32 src_strd,
1570                               UWORD8 *pu1_dst,
1571                               WORD32 dst_strd,
1572                               WORD32 nt,
1573                               WORD32 mode);
1574 
1575 typedef void (*pf_itrans_recon)(WORD16 *pi2_src,
1576                                 WORD16 *pi2_tmp,
1577                                 UWORD8 *pu1_pred,
1578                                 UWORD8 *pu1_dst,
1579                                 WORD32 src_strd,
1580                                 WORD32 pred_strd,
1581                                 WORD32 dst_strd,
1582                                 WORD32 zero_cols,
1583                                 WORD32 zero_rows);
1584 
1585 typedef void (*pf_recon)(WORD16 *pi2_src,
1586                          UWORD8 *pu1_pred,
1587                          UWORD8 *pu1_dst,
1588                          WORD32 src_strd,
1589                          WORD32 pred_strd,
1590                          WORD32 dst_strd,
1591                          WORD32 zero_cols);
1592 
1593 typedef void (*pf_itrans_recon_dc)(UWORD8 *pu1_pred,
1594                                    UWORD8 *pu1_dst,
1595                                    WORD32 pred_strd,
1596                                    WORD32 dst_strd,
1597                                    WORD32 log2_trans_size,
1598                                    WORD16 i2_coeff_value);
1599 
1600 
1601 typedef void (*pf_sao_luma)(UWORD8 *,
1602                             WORD32,
1603                             UWORD8 *,
1604                             UWORD8 *,
1605                             UWORD8 *,
1606                             UWORD8 *,
1607                             UWORD8 *,
1608                             UWORD8 *,
1609                             WORD8 *,
1610                             WORD32,
1611                             WORD32);
1612 
1613 typedef void (*pf_sao_chroma)(UWORD8 *,
1614                               WORD32,
1615                               UWORD8 *,
1616                               UWORD8 *,
1617                               UWORD8 *,
1618                               UWORD8 *,
1619                               UWORD8 *,
1620                               UWORD8 *,
1621                               WORD8 *,
1622                               WORD8 *,
1623                               WORD32,
1624                               WORD32);
1625 
1626 /**
1627  * Codec context
1628  */
1629 
1630 struct _codec_t
1631 {
1632     /**
1633      * Width : pic_width_in_luma_samples
1634      */
1635     WORD32 i4_wd;
1636 
1637     /**
1638      * Height : pic_height_in_luma_samples
1639      */
1640     WORD32 i4_ht;
1641 
1642     /**
1643      * Display width after cropping
1644      */
1645     WORD32 i4_disp_wd;
1646 
1647     /**
1648      * Display height after cropping
1649      */
1650     WORD32 i4_disp_ht;
1651 
1652     /**
1653      * Display stride
1654      */
1655     WORD32 i4_disp_strd;
1656 
1657     /**
1658      * Stride of reference buffers.
1659      * For shared mode even display buffer will use the same stride
1660      */
1661     WORD32 i4_strd;
1662 
1663     /**
1664      * Number of cores to be used
1665      */
1666     WORD32 i4_num_cores;
1667 
1668     /**
1669      * RASL output flag
1670      */
1671     WORD32 i4_rasl_output_flag;
1672 
1673     /**
1674      * 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
1675      * For example, it is set, if an EOS (end of stream) NAL is received
1676      */
1677     WORD32 i4_cra_as_first_pic;
1678 
1679     /**
1680      * Pictures that are are degraded
1681      * 0 : No degrade
1682      * 1 : Only on non-reference frames
1683      * 2 : Use interval specified by u4_nondegrade_interval
1684      * 3 : All non-key frames
1685      * 4 : All frames
1686      */
1687     WORD32                                     i4_degrade_pics;
1688 
1689     /**
1690      * Interval for pictures which are completely decoded without any degradation
1691      */
1692     WORD32                                     i4_nondegrade_interval;
1693 
1694     /**
1695      * bit position (lsb is zero): Type of degradation
1696      * 0 : Disable SAO
1697      * 1 : Disable deblocking
1698      * 2 : Faster inter prediction filters
1699      * 3 : Fastest inter prediction filters
1700      */
1701     WORD32                                     i4_degrade_type;
1702 
1703     /** Degrade pic count, Used to maintain the interval between non-degraded pics
1704      *
1705      */
1706     WORD32  i4_degrade_pic_cnt;
1707 
1708     /**
1709      * Total number of display buffers to be used
1710      * In case of shared mode, this will be number of reference frames
1711      */
1712     WORD32 i4_num_disp_bufs;
1713 
1714     /**
1715      * Flag to enable shared display buffer mode
1716      */
1717     WORD32 i4_share_disp_buf;
1718 
1719     /**
1720      * Chroma format of display buffers.
1721      In shared mode only 420SP_UV and 420SP_VU are supported
1722      */
1723     IV_COLOR_FORMAT_T e_chroma_fmt;
1724 
1725     /**
1726      * Chroma format of reference buffers.
1727      * In non-shared mode it will be 420SP_UV
1728      * In shared mode only 420SP_UV and 420SP_VU are supported
1729      */
1730     IV_COLOR_FORMAT_T e_ref_chroma_fmt;
1731 
1732     /**
1733      * Frame skip mode
1734      */
1735     IVD_FRAME_SKIP_MODE_T e_pic_skip_mode;
1736 
1737     /**
1738      * Display or decode order dump of output
1739      */
1740     IVD_DISPLAY_FRAME_OUT_MODE_T e_pic_out_order;
1741 
1742     /**
1743      * Coding type of the picture that is decoded
1744      */
1745     IV_PICTURE_CODING_TYPE_T e_dec_pic_type;
1746 
1747     /**
1748      * Flag to signal if a frame was decoded in this call
1749      */
1750     WORD32 i4_pic_decoded;
1751 
1752     /**
1753      * Flag to signal if picture data is present in the current input bitstream
1754      */
1755     WORD32 i4_pic_present;
1756 
1757     /**
1758      * Flag to disable deblocking of a frame
1759      */
1760     WORD32 i4_disable_deblk_pic;
1761 
1762     /**
1763      * Flag to disable sao of a frame
1764      */
1765     WORD32 i4_disable_sao_pic;
1766 
1767     /**
1768      * Flag to use full pel MC
1769      */
1770     WORD32 i4_fullpel_inter_pred;
1771     /**
1772      * Flush mode
1773      */
1774     WORD32 i4_flush_mode;
1775 
1776     /**
1777      * Decode header mode
1778      */
1779     WORD32 i4_header_mode;
1780 
1781     /**
1782      * Header in slice mode
1783      */
1784     WORD32 i4_header_in_slice_mode;
1785 
1786     /**
1787      * Flag to signal sps done
1788      */
1789     WORD32 i4_sps_done;
1790 
1791     /**
1792      * Flag to signal pps done
1793      */
1794     WORD32 i4_pps_done;
1795 
1796     /**
1797      * To signal successful completion of init
1798      */
1799     WORD32 i4_init_done;
1800 
1801     /**
1802      * To signal that at least one picture was decoded
1803      */
1804     WORD32 i4_first_pic_done;
1805 
1806     /**
1807      * To signal error in slice
1808      */
1809     WORD32 i4_slice_error;
1810 
1811     /**
1812      * Reset flag - Codec is reset if this flag is set
1813      */
1814     WORD32 i4_reset_flag;
1815 
1816     /**
1817      * Number of pictures decoded till now
1818      */
1819     UWORD32 u4_pic_cnt;
1820 
1821     /**
1822      * Number of pictures displayed till now
1823      */
1824     UWORD32 u4_disp_cnt;
1825 
1826     /**
1827      * Current error code
1828      */
1829     WORD32 i4_error_code;
1830 
1831     /**
1832      * Pointer to input bitstream. This is incremented everytime a NAL is processed
1833      */
1834     UWORD8 *pu1_inp_bitsbuf;
1835 
1836     /**
1837      * Offset to first byte after the start code in current NAL
1838      */
1839     WORD32 i4_nal_ofst;
1840 
1841     /**
1842      * Length of the NAL unit including the emulation bytes
1843      */
1844     WORD32 i4_nal_len;
1845 
1846     /**
1847      * Number of emulation prevention bytes present in the current NAL
1848      */
1849     WORD32 i4_num_emln_bytes;
1850 
1851     /**
1852      * Number of bytes remaining in the input bitstream
1853      */
1854     /**
1855      * Decremented everytime a NAL is processed
1856      */
1857     WORD32 i4_bytes_remaining;
1858 
1859     /**
1860      * Pointer to bitstream after emulation prevention
1861      */
1862     UWORD8 *pu1_bitsbuf;
1863 
1864     /**
1865      * Pointer to static bitstream after emulation prevention
1866      * This is a fixed size buffer used initially till SPS is decoded
1867      */
1868     UWORD8 *pu1_bitsbuf_static;
1869 
1870     /**
1871      * Pointer to dynamic bitstream after emulation prevention
1872      * This is allocated after SPS is done, based on width and height
1873      */
1874     UWORD8 *pu1_bitsbuf_dynamic;
1875 
1876     /**
1877      * Size of intermediate bitstream buffer
1878      */
1879     UWORD32 u4_bitsbuf_size;
1880 
1881     /**
1882      * Size of intermediate static bitstream buffer
1883      */
1884     UWORD32 u4_bitsbuf_size_static;
1885 
1886     /**
1887      * Size of intermediate dynamic bitstream buffer
1888      */
1889     UWORD32 u4_bitsbuf_size_dynamic;
1890 
1891     /**
1892      * Pointer to hold TU data for a set of CTBs or a picture
1893      */
1894     void *pv_tu_data;
1895 
1896     /**
1897      * Process Job queue buffer base
1898      */
1899     void *pv_proc_jobq_buf;
1900 
1901     /**
1902      * Process Job Queue mem tab size
1903      */
1904     WORD32 i4_proc_jobq_buf_size;
1905 
1906     /** Parse status: one byte per CTB */
1907     UWORD8 *pu1_parse_map;
1908 
1909     /** Process status: one byte per CTB */
1910     UWORD8 *pu1_proc_map;
1911     /**
1912      * Current pictures intra mode map at 8x8 level
1913      */
1914     UWORD8 *pu1_pic_intra_flag;
1915 
1916     /**
1917      * No LPF buffer base
1918      */
1919     UWORD8 *pu1_pic_no_loop_filter_flag_base;
1920 
1921     /**
1922      * Current pictures loop filter flag map at 8x8 level
1923      */
1924     UWORD8 *pu1_pic_no_loop_filter_flag;
1925     /**
1926      * MV Bank buffer manager
1927      */
1928     void *pv_mv_buf_mgr;
1929 
1930     /**
1931      * Pointer to MV Buf structure array
1932      */
1933     void *ps_mv_buf;
1934 
1935     /** Holds the number of mv_buf_t structures allocated */
1936     WORD32 i4_max_dpb_size;
1937 
1938     /**
1939      * Base address for Motion Vector bank buffer
1940      */
1941     void *pv_mv_bank_buf_base;
1942 
1943     /**
1944      * MV Bank size allocated
1945      */
1946     WORD32 i4_total_mv_bank_size;
1947 
1948     /**
1949      * Picture buffer manager
1950      */
1951     void *pv_pic_buf_mgr;
1952 
1953     /**
1954      * Pointer to Pic Buf structure array
1955      */
1956     void *ps_pic_buf;
1957 
1958     /**
1959      * Base address for Picture buffer
1960      */
1961     void *pv_pic_buf_base;
1962 
1963     /**
1964      * Total pic buffer size allocated
1965      */
1966     WORD32 i4_total_pic_buf_size;
1967 
1968     /**
1969      * Current chroma buffer base - used for shared mode with 420p output
1970      */
1971     UWORD8 *pu1_cur_chroma_ref_buf;
1972 
1973     /**
1974      * Picture buffer manager
1975      */
1976     void *pv_disp_buf_mgr;
1977 
1978     /**
1979      * Current display buffer's buffer ID
1980      */
1981     WORD32 i4_disp_buf_id;
1982 
1983     /**
1984      * Current display buffer
1985      */
1986     pic_buf_t *ps_disp_buf;
1987 
1988     /**
1989      * Pointer to dpb manager structure
1990      */
1991     void *pv_dpb_mgr;
1992 
1993     /**
1994      * Scaling matrices for each PPS
1995      */
1996     WORD16 *pi2_scaling_mat;
1997 
1998     /**
1999      * Array containing Tile information for each PPS
2000      */
2001     tile_t *ps_tile;
2002 
2003     /**
2004      * Timestamp associated with the current display output
2005      */
2006     UWORD32 u4_ts;
2007 
2008     /**
2009      * Pointer to base of Video parameter set structure array
2010      */
2011     vps_t *ps_vps_base;
2012 
2013     /**
2014      * Pointer to base of Sequence parameter set structure array
2015      */
2016     sps_t *ps_sps_base;
2017 
2018     /**
2019      * Pointer to base of Picture parameter set structure array
2020      */
2021     pps_t *ps_pps_base;
2022 
2023     /**
2024      * Pointer to base of slice header structure array
2025      */
2026     slice_header_t *ps_slice_hdr_base;
2027     /**
2028      * Pointer to base of entry point offsets in a frame
2029      */
2030     WORD32 *pi4_entry_ofst;
2031 
2032     /**
2033      * Current offset in pi4_entry_ofst
2034      */
2035     WORD32 i4_cur_entry_ofst;
2036 
2037     /**
2038      *  Parsing context
2039      */
2040     parse_ctxt_t s_parse;
2041 
2042 #ifdef KEEP_THREADS_ACTIVE
2043     /**
2044      * Condition variable to signal process start
2045      */
2046     void *apv_proc_start_condition[MAX_PROCESS_THREADS];
2047 
2048     /**
2049      * Mutex used to keep the functions thread-safe
2050      */
2051     void *apv_proc_start_mutex[MAX_PROCESS_THREADS];
2052 
2053     /**
2054      * Process state start- One for each thread
2055      */
2056     WORD32 ai4_process_start[MAX_PROCESS_THREADS];
2057 
2058     /**
2059      * Condition variable to signal process done
2060      */
2061     void *apv_proc_done_condition[MAX_PROCESS_THREADS];
2062 
2063     /**
2064      * Mutex used to keep the functions thread-safe
2065      */
2066     void *apv_proc_done_mutex[MAX_PROCESS_THREADS];
2067 
2068     /**
2069      * Process state end- One for each thread
2070      */
2071     WORD32 ai4_process_done[MAX_PROCESS_THREADS];
2072 
2073     /**
2074      * Flag to signal processing thread to exit
2075      */
2076     WORD32 i4_break_threads;
2077 #endif
2078 
2079     /**
2080      * Processing context - One for each processing thread
2081      */
2082     process_ctxt_t as_process[MAX_PROCESS_THREADS];
2083 
2084     /**
2085      * Thread handle for each of the processing threads
2086      */
2087     void *apv_process_thread_handle[MAX_PROCESS_THREADS];
2088 
2089     /**
2090      * Thread created flag for each of the processing threads
2091      */
2092     WORD32 ai4_process_thread_created[MAX_PROCESS_THREADS];
2093 
2094     /**
2095      * Void pointer to process job context
2096      */
2097     void *pv_proc_jobq;
2098 
2099     /* Number of CTBs processed together for better instruction cache handling */
2100     WORD32 i4_proc_nctb;
2101 
2102     /**
2103      * Previous POC lsb
2104      */
2105     WORD32 i4_prev_poc_lsb;
2106 
2107     /**
2108      * Previous POC msb
2109      */
2110     WORD32 i4_prev_poc_msb;
2111 
2112     /**
2113      * Max POC lsb that has arrived till now
2114      */
2115     WORD32 i4_max_prev_poc_lsb;
2116 
2117     /** Context for format conversion */
2118     fmt_conv_t s_fmt_conv;
2119 
2120     /** Pointer to a structure describing output display buffer */
2121     ivd_out_bufdesc_t *ps_out_buffer;
2122     /**
2123      * Variable to store the next ctb count to compute pu idx
2124      */
2125     WORD32 i4_next_pu_ctb_cnt;
2126 
2127     /**
2128      * Variable to store the next ctb count to compute tu idx
2129      */
2130     WORD32 i4_next_tu_ctb_cnt;
2131 
2132     /**  Active SPS id - mainly to be used during codec initializations in shared mode */
2133     WORD32 i4_sps_id;
2134 
2135     /**  Number of ctbs to be decoded in one process call */
2136     UWORD32 u4_nctb;
2137 
2138     /** Flag to enable scheduling of format conversion jobs ahead of processing jobs */
2139     UWORD32 u4_enable_fmt_conv_ahead;
2140 
2141     /** Mask used to change MVs to full pel when configured to run in reduced complexity mode */
2142     WORD32 i4_mv_frac_mask;
2143 
2144     /** Memory holding tile indices */
2145     UWORD8 *pu1_tile_idx_base;
2146 
2147     /** Callback for aligned allocation */
2148     void *(*pf_aligned_alloc)(void *pv_mem_ctxt, WORD32 alignment, WORD32 size);
2149 
2150     /** Callback for aligned free */
2151     void (*pf_aligned_free)(void *pv_mem_ctxt, void *pv_buf);
2152 
2153     /** Memory context passed from application */
2154     void *pv_mem_ctxt;
2155 
2156     /** Base address of reference buffrers allocated */
2157     UWORD8 *pu1_ref_pic_buf_base;
2158 
2159     /** Flag to indicate if dynamic buffers are allocated */
2160     UWORD32 u4_allocate_dynamic_done;
2161 
2162     /** Flag to signal display order */
2163     IVD_DISPLAY_FRAME_OUT_MODE_T  e_frm_out_mode;
2164 
2165     /**  Funtion pointers for inter_pred leaf level functions */
2166     pf_inter_pred apf_inter_pred[22];
2167 
2168     /**  Funtion pointers for inter_pred_luma leaf level functions */
2169     pf_intra_pred apf_intra_pred_luma[11];
2170 
2171     /**  Funtion pointers for inter_pred_chroma leaf level functions */
2172     pf_intra_pred apf_intra_pred_chroma[11];
2173 
2174     /**  Funtion pointers for itrans_recon leaf level functions */
2175     pf_itrans_recon apf_itrans_recon[8];
2176 
2177     /**  Funtion pointers for recon leaf level functions */
2178     pf_recon apf_recon[8];
2179 
2180     /**  Funtion pointers for itrans_recon_dc leaf level functions */
2181     pf_itrans_recon_dc apf_itrans_recon_dc[2];
2182 
2183     /**  Funtion pointers for sao_luma leaf level functions */
2184     pf_sao_luma apf_sao_luma[4];
2185 
2186     /**  Funtion pointers for sao_chroma leaf level functions */
2187     pf_sao_chroma apf_sao_chroma[4];
2188 
2189     /**  Funtion pointers for all the leaf level functions */
2190     func_selector_t s_func_selector;
2191     /**  Processor architecture */
2192     IVD_ARCH_T e_processor_arch;
2193     /**  Processor soc */
2194     IVD_SOC_T e_processor_soc;
2195 
2196     /** Display buffer array - for shared mode */
2197     ivd_out_bufdesc_t s_disp_buffer[IVD_VIDDEC_MAX_IO_BUFFERS];
2198 
2199     /** Number of active display buffers - for shared mode */
2200     WORD32  i4_share_disp_buf_cnt;
2201 };
2202 
2203 #endif /* _IHEVCD_STRUCTS_H_ */
2204