1/******************************************************************************
2 *
3 * Copyright (C) 2015 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *****************************************************************************
18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19*/
20
21/**
22 *******************************************************************************
23 * @file
24 *  ih264_structs.h
25 *
26 * @brief
27 *  Structure definitions used in the code
28 *
29 * @author
30 *  Ittiam
31 *
32 * @par List of Functions:
33 *
34 * @remarks
35 *  None
36 *
37 *******************************************************************************
38 */
39
40#ifndef _IH264_STRUCTS_H_
41#define _IH264_STRUCTS_H_
42
43/** MB Type info for Intra MBs */
44typedef struct
45{
46    UWORD32             u4_num_mbpart;
47    MBPART_PREDMODE_T   e_mbpart_predmode;
48    MBMODES_I16x16      e_intra_predmode;
49    UWORD32             u4_cpb_chroma;
50    UWORD32             u4_cpb_luma;
51}intra_mbtype_info_t;
52
53/** MB Type info for Inter MBs */
54typedef struct
55{
56    UWORD32                 u4_num_mbpart;
57    MBPART_PREDMODE_T       e_mbpart_predmode_0;
58    MBPART_PREDMODE_T       e_mbpart_predmode_1;
59    UWORD32                 u4_mbpart_wd;
60    UWORD32                 u4_mbpart_ht;
61}inter_mbtype_info_t;
62
63
64/** Sub MB Type info for Inter MBs */
65typedef struct
66{
67    UWORD32                 u4_num_mbpart;
68    MBPART_PREDMODE_T       e_mbpart_predmode;
69    UWORD32                 u4_mbpart_wd;
70    UWORD32                 u4_mbpart_ht;
71}submbtype_info_t;
72
73/**
74 * Picture buffer
75 */
76typedef struct
77{
78    UWORD8* pu1_luma;
79    UWORD8* pu1_chroma;
80
81    WORD32 i4_abs_poc;
82    WORD32 i4_poc_lsb;
83
84
85    /** Lower 32 bit of time stamp */
86    UWORD32 u4_timestamp_low;
87
88    /** Upper 32 bit of time stamp */
89    UWORD32 u4_timestamp_high;
90
91    WORD32 i4_used_as_ref;
92
93    /**
94     * frame_num in the slice header
95     */
96    WORD32 i4_frame_num;
97
98    /**
99     * Long-term frame idx
100     * TODO: store in frame_num
101     */
102    WORD32 i4_long_term_frame_idx;
103
104    /*
105     *  0: Top Field
106     *  1: Bottom Field
107     */
108    WORD8   i1_field_type;
109
110    /**
111     * buffer ID from frame buffer manager
112     */
113    WORD32 i4_buf_id;
114
115} pic_buf_t;
116
117
118/**
119 * Reference List
120 */
121typedef struct
122{
123    void *pv_pic_buf;
124
125    void *pv_mv_buf;
126
127} ref_list_t;
128
129
130/**
131 * Motion vector
132 */
133typedef struct
134{
135    /**
136     * Horizontal Motion Vector
137     */
138    WORD16 i2_mvx;
139
140    /**
141     * Vertical Motion Vector
142     */
143    WORD16 i2_mvy;
144} mv_t;
145
146/*****************************************************************************/
147/* Following results in packed 48 bit structure. If mv_t included            */
148/*  ref_pic_buf_id, then 8 bits will be wasted for each mv for aligning.     */
149/*  Also using mv_t as elements directly instead of a pointer to l0 and l1   */
150/*  mvs. Since pointer takes 4 bytes and MV itself is 4 bytes. It does not   */
151/*  really help using pointers.                                              */
152/*****************************************************************************/
153
154/**
155 * PU Motion Vector info
156 */
157typedef struct
158{
159    /**
160     *  L0 Motion Vector
161     */
162    mv_t s_l0_mv;
163
164    /**
165     *  L1 Motion Vector
166     */
167    mv_t s_l1_mv;
168
169    /**
170     *  L0 Ref index
171     */
172    WORD8   i1_l0_ref_idx;
173
174    /**
175     *  L1 Ref index
176     */
177    WORD8   i1_l1_ref_idx;
178
179    /**
180     *  L0 Ref Pic Buf ID
181     */
182    WORD8 i1_l0_ref_pic_buf_id;
183
184    /**
185     *  L1 Ref Pic Buf ID
186     */
187    WORD8 i1_l1_ref_pic_buf_id;
188
189} pu_mv_t;
190
191/**
192 * PU information
193 */
194typedef struct
195{
196
197    /**
198     *  Motion Vectors
199     */
200    pu_mv_t     s_mv;
201
202    /**
203     *  PU X position in terms of min PU (4x4) units
204     */
205    UWORD32     b2_pos_x        : 2;
206
207    /**
208     *  PU Y position in terms of min PU (4x4) units
209     */
210    UWORD32     b2_pos_y        : 2;
211
212    /**
213     *  PU width in pixels = (b2_wd + 1) << 2
214     */
215    UWORD32     b2_wd           : 2;
216
217    /**
218     *  PU height in pixels = (b2_ht + 1) << 2
219     */
220    UWORD32     b2_ht           : 2;
221
222    /**
223     *  Intra or Inter flag for each partition - 0 or 1
224     */
225    UWORD32     b1_intra_flag   : 1;
226
227    /**
228     *  PRED_L0, PRED_L1, PRED_BI
229     */
230    UWORD32     b2_pred_mode    : 2;
231
232} pu_t;
233
234
235/**
236 * MB information to be stored for entire frame
237 */
238typedef struct
239{
240    /**
241     * Transform sizes 0: 4x4, 1: 8x8,
242     */
243    UWORD32     b1_trans_size : 1;
244
245    /**
246     * CBP - 4 bits for Y, 1 for U and 1 for V
247     */
248    UWORD32     b6_cbp: 6;
249
250    /**
251     * Intra pred sizes  0: 4x4, 1: 8x8, 2: 16x16
252     */
253    UWORD32     b2_intra_pred_size : 2;
254
255    /**
256     * Flag to signal if the current MB is IPCM
257     */
258    UWORD32     b1_ipcm : 1;
259
260}mb_t;
261
262/*****************************************************************************/
263/* Info from last TU row of MB is stored in a row level neighbour buffer    */
264/* , which will be used for Boundary Strength computation                    */
265/*****************************************************************************/
266/**
267 *  MB neighbor info
268 */
269typedef struct
270{
271    /**
272     *  Slice index of the mb
273     */
274    UWORD16 u2_slice_idx;
275
276    /*************************************************************************/
277    /* CBF of bottom TU row (replicated in 4 pixel boundary)                 */
278    /* MSB contains CBF of first TU in the last row and LSB contains CBF     */
279    /* of last TU in the last row                                            */
280    /*************************************************************************/
281    /**
282     * CBF of bottom TU row
283     */
284    UWORD16 u2_packed_cbf;
285
286    /*************************************************************************/
287    /* QP of bottom TU row (replicated at 8 pixel boundary (Since QP can     */
288    /* not change at less than min CU granularity)                           */
289    /*************************************************************************/
290    /**
291     * QP of bottom TU row
292     */
293    UWORD8 u1_qp;
294
295} mb_top_ny_info_t;
296
297/**
298 *  MB level context
299 */
300typedef struct _mb_ctxt_t
301{
302    /*************************************************************************/
303    /* Tile boundary can be detected by looking at tile start x and tile     */
304    /* start y.  And based on the tile, slice and frame boundary the         */
305    /* following will be initialized.                                        */
306    /*************************************************************************/
307    /**
308     *  Pointer to left MB
309     */
310    /*  If not available, this will be set to NULL   */
311    struct _mb_ctxt_t *ps_mb_left;
312
313    /**
314     *  Pointer to top-left MB
315     */
316    /* If not available, this will be set to NULL   */
317    mb_top_ny_info_t *ps_mb_ny_topleft;
318
319    /**
320     *  Pointer to top MB
321     */
322    /* If not available, this will be set to NULL  */
323    mb_top_ny_info_t *ps_mb_ny_top;
324
325    /**
326     *  Pointer to top-right MB
327     */
328    /* If not available, this will be set to NULL */
329    mb_top_ny_info_t *ps_mb_ny_topright;
330
331    /*************************************************************************/
332    /* Pointer to PU data.                                                   */
333    /* This points to a MV Bank stored at frame level. Though this           */
334    /* pointer can be derived by reading offset at frame level, it is        */
335    /* stored here for faster access. Can be removed if storage of MB       */
336    /* structure is critical                                                 */
337    /*************************************************************************/
338    /**
339     * Pointer to PU data
340     */
341    pu_t *ps_pu;
342
343    /*************************************************************************/
344    /* Pointer to a PU map stored at frame level,                            */
345    /* Though this pointer can be derived by multiplying MB address with    */
346    /* number of minTUs in a MB, it is stored here for faster access.       */
347    /* Can be removed if storage of MB structure is critical                */
348    /*************************************************************************/
349    /**
350     * Pointer to a PU map stored at frame level
351     */
352    UWORD8 *pu1_pu_map;
353
354    /**
355     *  Number of TUs filled in as_tu
356     */
357    /*************************************************************************/
358    /* Having the first entry as 32 bit data, helps in keeping each of       */
359    /* the structures aligned to 32 bits at MB level                        */
360    /*************************************************************************/
361    WORD32 i4_tu_cnt;
362
363    /**
364     *  Pointer to transform coeff data
365     */
366    /*************************************************************************/
367    /* Following format is repeated for every coded TU                       */
368    /* Luma Block                                                            */
369    /* num_coeffs      : 16 bits                                             */
370    /* zero_cols       : 8 bits ( 1 bit per 4 columns)                       */
371    /* sig_coeff_map   : ((TU Size * TU Size) + 31) >> 5 number of WORD32s   */
372    /* coeff_data      : Non zero coefficients                               */
373    /* Cb Block (only for last TU in 4x4 case else for every luma TU)        */
374    /* num_coeffs      : 16 bits                                             */
375    /* zero_cols       : 8 bits ( 1 bit per 4 columns)                       */
376    /* sig_coeff_map   : ((TU Size * TU Size) + 31) >> 5 number of WORD32s   */
377    /* coeff_data      : Non zero coefficients                               */
378    /* Cr Block (only for last TU in 4x4 case else for every luma TU)        */
379    /* num_coeffs      : 16 bits                                             */
380    /* zero_cols       : 8 bits ( 1 bit per 4 columns)                       */
381    /* sig_coeff_map   : ((TU Size * TU Size) + 31) >> 5 number of WORD32s   */
382    /* coeff_data      : Non zero coefficients                               */
383    /*************************************************************************/
384    void            *pv_coeff_data;
385
386    /**
387     *  Slice to which the MB belongs to
388     */
389    WORD32 i4_slice_idx;
390
391    /**
392     *  MB column position
393     */
394    WORD32 i4_pos_x;
395
396    /**
397     *  MB row position
398     */
399    WORD32 i4_pos_y;
400
401    /**
402     *  Number of PUs filled in ps_pu
403     */
404    WORD32 i4_pu_cnt;
405
406    /**
407     *  Index of current PU being processed in ps_pu
408     */
409    /*  Scratch variable set to 0 at the start of any PU processing function */
410    WORD32 i4_pu_idx;
411
412    /**
413     * Vertical Boundary strength
414     */
415    /* Two bits per edge.
416    Stored in format. BS[15] | BS[14] | .. |BS[0]*/
417    UWORD32 *pu4_vert_bs;
418
419    /**
420     * Horizontal Boundary strength
421     */
422
423    /* Two bits per edge.
424    Stored in format. BS[15] | BS[14] | .. |BS[0]*/
425    UWORD32 *pu4_horz_bs;
426
427    /**
428     *  Qp array stored for each 8x8 pixels
429     */
430    UWORD8 *pu1_qp;
431
432    /**
433     *  Pointer to current frame's pu_t array
434     */
435    pu_t *ps_frm_pu;
436
437    /**
438     * Pointer to current frame's pu_t index array, which stores starting index
439     * of pu_t for every MB
440     */
441    UWORD32 *pu4_frm_pu_idx;
442
443    /**
444     *  Pointer to current frame's pu map array
445     */
446    UWORD8 *pu1_frm_pu_map;
447
448    /*************************************************************************/
449    /* Need to add encoder specific elements for identifying the order of    */
450    /* coding for CU, TU and PU if any                                       */
451    /*************************************************************************/
452} mb_ctxt_t;
453
454/*************************************************************************/
455/* The following describes how each of the CU cases are handled          */
456/*************************************************************************/
457
458/*************************************************************************/
459/* For SKIP MB                                                           */
460/* One Inter PU with appropriate MV                                      */
461/* One TU which says CBP is zero and size is 16x16                       */
462/*************************************************************************/
463
464/*************************************************************************/
465/* For Inter MB                                                          */
466/* M Inter PU with appropriate MVs (M between 1 to 4)                    */
467/* Number of TUs derived based on transform size                         */
468/*************************************************************************/
469
470/*************************************************************************/
471/* For Intra MB                                                          */
472/* Number of TUs derived based on transform size                         */
473/* N Intra Modes are signaled along with coeff data at the start        */
474/*************************************************************************/
475
476/*************************************************************************/
477/* For Intra PCM MB                                                      */
478/* One TU which says ipcm is 1                                           */
479/*************************************************************************/
480
481
482
483/**
484 * Structure to hold quantization parameters of an mb
485 */
486typedef struct
487{
488
489    /*
490     * mb qp
491     */
492    UWORD8 u1_mb_qp;
493
494    /*
495     * mb qp / 6
496     */
497    UWORD8 u1_qp_div;
498
499    /*
500     * mb qp mod 6
501     */
502    UWORD8 u1_qp_rem;
503
504    /*
505     * QP bits
506     */
507    UWORD8  u1_qbits;
508
509    /*
510     * forward scale matrix
511     */
512    const UWORD16 *pu2_scale_mat;
513
514    /*
515     * threshold matrix for quantization
516     */
517    UWORD16 *pu2_thres_mat;
518
519    /*
520     * Threshold to compare the sad with
521     */
522    UWORD16 *pu2_sad_thrsh;
523
524    /*
525     * qp dependent rounding constant
526     */
527    UWORD32 u4_dead_zone;
528
529    /*
530     *  inverse scale matrix
531     */
532    const UWORD16 *pu2_iscale_mat;
533
534    /*
535     * Weight matrix in iquant
536     */
537    UWORD16 *pu2_weigh_mat;
538
539}quant_params_t;
540
541/**
542 * Structure to hold Profile tier level info for a given layer
543 */
544
545typedef struct
546{
547    /**
548     *  NAL unit type
549     */
550    WORD8 i1_nal_unit_type;
551
552    /**
553     * NAL ref idc
554     */
555    WORD8 i1_nal_ref_idc;
556
557
558} nal_header_t;
559
560/**
561 * HRD parameters Info
562 */
563typedef struct
564{
565    /**
566     * Specifies the number of alternative CPB specifications in the
567     * bitstream
568     */
569    UWORD8 u1_cpb_cnt_minus1;
570
571    /**
572    * (together with bit_rate_value_minus1) specifies the
573    * maximum input bit rate of the i-th CPB
574    */
575    UWORD32 u4_bit_rate_scale;
576
577    /**
578    * (together with cpb_size_du_value_minus1) specifies
579    * CPB size of the i-th CPB when the CPB operates
580    * at the access unit level
581    */
582    UWORD32 u4_cpb_size_scale;
583
584    /**
585     *  (together with bit_rate_scale) specifies the
586     *  maximum input bit rate for the i-th CPB
587     */
588    UWORD32 au4_bit_rate_value_minus1[32];
589    /**
590     *  together with cpb_size_scale to specify the
591     *  CPB size when the CPB operates at the access unit level.
592     */
593    UWORD32 au4_cpb_size_value_minus1[32];
594
595    /**
596     * if 1, specifies that the HSS operates in a constant bit rate (CBR) mode
597     * if 0, specifies that the HSS operates in a intermittent bit rate (CBR) mode
598     */
599    UWORD8  au1_cbr_flag[32];
600
601
602    /**
603    * specifies the length, in bits for initial cpb delay (nal/vcl)syntax in bp sei
604    */
605    UWORD8  u1_initial_cpb_removal_delay_length_minus1;
606
607    /**
608    * specifies the length, in bits for the cpb delay syntax in pt_sei
609    */
610    UWORD8  u1_cpb_removal_delay_length_minus1;
611
612    /**
613    * specifies the length, in bits, of the pic_dpb_output_delay syntax element in the pt SEI message
614    */
615    UWORD8  u1_dpb_output_delay_length_minus1;
616
617    /**
618     * Specifies length of the time offset parameter
619     */
620    UWORD8  u1_time_offset_length;
621
622}hrd_params_t;
623
624
625/**
626 * Structure to hold VUI parameters Info
627 */
628typedef struct
629{
630    /**
631    *  indicates the presence of aspect_ratio
632    */
633    UWORD8 u1_aspect_ratio_info_present_flag;
634
635    /**
636    *  specifies the aspect ratio of the luma samples
637    */
638    UWORD8 u1_aspect_ratio_idc;
639
640    /**
641    *  width of the luma samples. user dependent
642    */
643    UWORD16 u2_sar_width;
644
645    /**
646    *  Height of the luma samples. user dependent
647    */
648    UWORD16 u2_sar_height;
649
650    /**
651    * if 1, specifies that the overscan_appropriate_flag is present
652    * if 0, the preferred display method for the video signal is unspecified
653    */
654    UWORD8 u1_overscan_info_present_flag;
655
656    /**
657    * if 1,indicates that the cropped decoded pictures output
658    * are suitable for display using overscan
659    */
660    UWORD8 u1_overscan_appropriate_flag;
661
662    /**
663    * if 1 specifies that video_format, video_full_range_flag and
664    * colour_description_present_flag are present
665    */
666    UWORD8 u1_video_signal_type_present_flag;
667
668    /**
669    * pal, secam, ntsc, ...
670    */
671    UWORD8 u1_video_format;
672
673    /**
674    * indicates the black level and range of the luma and chroma signals
675    */
676    UWORD8 u1_video_full_range_flag;
677
678    /**
679    * if 1,to 1 specifies that colour_primaries, transfer_characteristics
680    * and matrix_coefficients are present
681    */
682    UWORD8 u1_colour_description_present_flag;
683
684    /**
685    * indicates the chromaticity coordinates of the source primaries
686    */
687    UWORD8 u1_colour_primaries;
688
689    /**
690    * indicates the opto-electronic transfer characteristic of the source picture
691    */
692    UWORD8 u1_transfer_characteristics;
693
694    /**
695    * the matrix coefficients used in deriving luma and chroma signals
696    * from the green, blue, and red primaries
697    */
698    UWORD8 u1_matrix_coefficients;
699
700    /**
701    * if 1, specifies that chroma_sample_loc_type_top_field and
702    * chroma_sample_loc_type_bottom_field are present
703    */
704    UWORD8 u1_chroma_loc_info_present_flag;
705
706    /**
707    * location of chroma samples
708    */
709    UWORD8 u1_chroma_sample_loc_type_top_field;
710
711    UWORD8 u1_chroma_sample_loc_type_bottom_field;
712
713    /**
714    *   Indicates the presence of the
715    *   num_units_in_ticks, time_scale flag
716    */
717    UWORD8 u1_vui_timing_info_present_flag;
718
719    /**
720    *   Number of units that
721    *   correspond to one increment of the
722    *   clock. Indicates the  resolution
723    */
724    UWORD32 u4_vui_num_units_in_tick;
725
726    /**
727    *   The number of time units that pass in one second
728    */
729    UWORD32 u4_vui_time_scale;
730
731    /**
732     *   Flag indicating that time difference between two frames is a constant
733     */
734    UWORD8 u1_fixed_frame_rate_flag;
735
736    /**
737     *   Indicates the presence of NAL HRD parameters
738     */
739    UWORD8 u1_nal_hrd_parameters_present_flag;
740
741    /**
742     *   NAL level HRD parameters
743     */
744    hrd_params_t s_nal_hrd_parameters;
745
746    /**
747     *   Indicates the presence of VCL HRD parameters
748     */
749    UWORD8 u1_vcl_hrd_parameters_present_flag;
750
751    /**
752     *   VCL level HRD parameters
753     */
754    hrd_params_t s_vcl_hrd_parameters;
755
756    /**
757     *  Specifies the HRD operational mode
758     */
759    UWORD8 u1_low_delay_hrd_flag;
760
761    /**
762     * Indicates presence of SEI messages which include pic_struct syntax element
763     */
764    UWORD8 u1_pic_struct_present_flag;
765
766    /**
767    * 1, specifies that the following cvs bitstream restriction parameters are present
768    */
769    UWORD8 u1_bitstream_restriction_flag;
770
771    /**
772    * if 0, indicates that no pel outside the pic boundaries and
773    * no sub-pels derived using pels outside the pic boundaries is used for inter prediction
774    */
775    UWORD8 u1_motion_vectors_over_pic_boundaries_flag;
776
777    /**
778    * Indicates a number of bytes not exceeded by the sum of the sizes of the VCL NAL units
779    * associated with any coded picture
780    */
781    UWORD8 u1_max_bytes_per_pic_denom;
782
783    /**
784    *  Indicates an upper bound for the number of bits of coding_unit() data
785    */
786    UWORD8 u1_max_bits_per_mb_denom;
787
788    /**
789    * Indicate the maximum absolute value of a decoded horizontal MV component
790    * in quarter-pel luma units
791    */
792    UWORD8 u1_log2_max_mv_length_horizontal;
793
794    /**
795    * Indicate the maximum absolute value of a decoded vertical MV component
796    * in quarter-pel luma units
797    */
798    UWORD8 u1_log2_max_mv_length_vertical;
799
800    /**
801     *  Max number of frames that are not synchronized in display and decode order
802     */
803    UWORD8 u1_num_reorder_frames;
804
805    /**
806     * specifies required size of the HRD DPB in units of frame buffers.
807     */
808     UWORD8 u1_max_dec_frame_buffering;
809
810} vui_t;
811
812
813/**
814 * Structure to hold SPS info
815 */
816typedef struct
817{
818    /**
819     *  profile_idc
820     */
821    UWORD8 u1_profile_idc;
822
823    /** constraint_set0_flag */
824    UWORD8 u1_constraint_set0_flag;
825
826    /** constraint_set1_flag */
827    UWORD8 u1_constraint_set1_flag;
828
829    /** constraint_set2_flag */
830    UWORD8 u1_constraint_set2_flag;
831
832    /** constraint_set3_flag */
833    UWORD8 u1_constraint_set3_flag;
834
835    /**
836     *  level_idc
837     */
838    UWORD8 u1_level_idc;
839
840    /**
841     *  seq_parameter_set_id
842     */
843    UWORD8 u1_sps_id;
844
845
846    /**
847     *  chroma_format_idc
848     */
849    UWORD8 u1_chroma_format_idc;
850
851    /**
852     *  residual_colour_transform_flag
853     */
854    WORD8 i1_residual_colour_transform_flag;
855
856    /**
857     *  bit_depth_luma_minus8
858     */
859    WORD8 i1_bit_depth_luma;
860
861    /**
862     *  bit_depth_chroma_minus8
863     */
864    WORD8 i1_bit_depth_chroma;
865
866    /**
867     *  qpprime_y_zero_transform_bypass_flag
868     */
869    WORD8 i1_qpprime_y_zero_transform_bypass_flag;
870
871    /**
872     *  seq_scaling_matrix_present_flag
873     */
874    WORD8 i1_seq_scaling_matrix_present_flag;
875
876    /**
877     *  seq_scaling_list_present_flag
878     */
879    WORD8 ai1_seq_scaling_list_present_flag[8];
880
881    /**
882     *  log2_max_frame_num_minus4
883     */
884    WORD8 i1_log2_max_frame_num;
885
886    /**
887     *  MaxFrameNum in the standard
888     *  1 << i1_log2_max_frame_num
889     */
890    WORD32 i4_max_frame_num;
891
892    /**
893     *  pic_order_cnt_type
894     */
895    WORD8 i1_pic_order_cnt_type;
896
897    /**
898     *  log2_max_pic_order_cnt_lsb_minus4
899     */
900    WORD8 i1_log2_max_pic_order_cnt_lsb;
901
902    /**
903     * MaxPicOrderCntLsb in the standard.
904     * 1 << log2_max_pic_order_cnt_lsb_minus4
905     */
906    WORD32 i4_max_pic_order_cnt_lsb;
907
908    /**
909     *  delta_pic_order_always_zero_flag
910     */
911    WORD8 i1_delta_pic_order_always_zero_flag;
912
913    /**
914     *  offset_for_non_ref_pic
915     */
916    WORD32 i4_offset_for_non_ref_pic;
917
918    /**
919     *  offset_for_top_to_bottom_field
920     */
921    WORD32 i4_offset_for_top_to_bottom_field;
922
923    /**
924     *  num_ref_frames_in_pic_order_cnt_cycle
925     */
926    UWORD8 u1_num_ref_frames_in_pic_order_cnt_cycle;
927
928    /**
929     * Offset_for_ref_frame
930     */
931    WORD32 ai4_offset_for_ref_frame[256];
932
933    /**
934     *  max_num_ref_frames
935     */
936    UWORD8 u1_max_num_ref_frames;
937
938    /**
939     *  gaps_in_frame_num_value_allowed_flag
940     */
941    WORD8 i1_gaps_in_frame_num_value_allowed_flag;
942
943    /**
944     *  pic_width_in_mbs_minus1
945     */
946    WORD16 i2_pic_width_in_mbs_minus1;
947
948    /**
949     *  pic_height_in_map_units_minus1
950     */
951    WORD16 i2_pic_height_in_map_units_minus1;
952
953    /**
954     *  frame_mbs_only_flag
955     */
956    WORD8 i1_frame_mbs_only_flag;
957
958    /**
959     *  mb_adaptive_frame_field_flag
960     */
961    WORD8 i1_mb_adaptive_frame_field_flag;
962
963    /**
964     *  direct_8x8_inference_flag
965     */
966    WORD8 i1_direct_8x8_inference_flag;
967
968    /**
969     *  frame_cropping_flag
970     */
971    WORD8 i1_frame_cropping_flag;
972
973    /**
974     *  frame_crop_left_offset
975     */
976    WORD16 i2_frame_crop_left_offset;
977
978    /**
979     *  frame_crop_right_offset
980     */
981    WORD16 i2_frame_crop_right_offset;
982
983    /**
984     *  frame_crop_top_offset
985     */
986    WORD16 i2_frame_crop_top_offset;
987
988    /**
989     *  frame_crop_bottom_offset
990     */
991    WORD16 i2_frame_crop_bottom_offset;
992
993    /**
994     *  vui_parameters_present_flag
995     */
996    WORD8 i1_vui_parameters_present_flag;
997
998    /**
999     * vui_parameters_Structure_info
1000     */
1001    vui_t s_vui_parameters;
1002
1003    /**
1004     * Flag to give status of SPS structure
1005     */
1006    WORD8 i1_sps_valid;
1007
1008    /**
1009     * Coded Picture width
1010     */
1011    WORD32 i2_pic_wd;
1012
1013    /**
1014     * Coded Picture height
1015     */
1016    WORD32 i2_pic_ht;
1017
1018    /**
1019     *  Picture width in MB units
1020     */
1021
1022    WORD16 i2_pic_wd_in_mb;
1023
1024    /**
1025     *  Picture height in MB units
1026     */
1027
1028    WORD16 i2_pic_ht_in_mb;
1029
1030    /**
1031     * useDefaultScalingMatrixFlag
1032     */
1033    WORD8 ai1_use_default_scaling_matrix_flag[8];
1034
1035    /**
1036     * 4x4 Scaling lists after inverse zig zag scan
1037     */
1038    UWORD16 au2_4x4_weight_scale[6][16];
1039
1040    /**
1041     * 4x4 Scaling lists after inverse zig zag scan
1042     */
1043    UWORD16 au2_8x8_weight_scale[2][64];
1044
1045} sps_t;
1046
1047
1048/**
1049 * Structure to hold PPS info
1050 */
1051typedef struct
1052{
1053    /**
1054     *  pic_parameter_set_id
1055     */
1056    UWORD8 u1_pps_id;
1057
1058    /**
1059     *  seq_parameter_set_id
1060     */
1061    UWORD8 u1_sps_id;
1062
1063    /**
1064     *   Entropy coding : 0-VLC; 1 - CABAC
1065     */
1066    UWORD8 u1_entropy_coding_mode_flag;
1067
1068    /*
1069     * Pic order present flag
1070     */
1071    UWORD8 u1_pic_order_present_flag;
1072
1073    /*
1074     * Number of slice groups
1075     */
1076    UWORD8 u1_num_slice_groups;
1077
1078    /*
1079     * Slice group map type
1080     */
1081    UWORD8 u1_slice_group_map_type;
1082
1083    /*
1084     * Maximum reference picture index in the reference list 0 : range [0 - 31]
1085     */
1086    WORD8 i1_num_ref_idx_l0_default_active;
1087
1088    /*
1089     * Maximum reference picture index in the reference list 1 : range [0 - 31]
1090     */
1091    WORD8 i1_num_ref_idx_l1_default_active;
1092
1093    /**
1094     *  weighted_pred_flag
1095     */
1096    WORD8 i1_weighted_pred_flag;
1097
1098    /**
1099     *  weighted_bipred_flag
1100     */
1101    WORD8 i1_weighted_bipred_idc;
1102
1103    /**
1104     *  pic_init_qp_minus26
1105     */
1106    WORD8 i1_pic_init_qp;
1107
1108    /**
1109     *  pic_init_qs_minus26
1110     */
1111    WORD8 i1_pic_init_qs;
1112
1113    /*
1114     * Chroma QP offset w.r.t QPY {-12,12}
1115     */
1116    WORD8  i1_chroma_qp_index_offset;
1117
1118    /**
1119     *  deblocking_filter_control_present_flag
1120     */
1121    WORD8 i1_deblocking_filter_control_present_flag;
1122
1123    /**
1124     *  constrained_intra_pred_flag
1125     */
1126    WORD8 i1_constrained_intra_pred_flag;
1127
1128    /**
1129     *  redundant_pic_cnt_present_flag
1130     */
1131    WORD8 i1_redundant_pic_cnt_present_flag;
1132
1133    /**
1134     *  transform_8x8_mode_flag
1135     */
1136    WORD8 i1_transform_8x8_mode_flag;
1137
1138    /**
1139     *  pic_scaling_matrix_present_flag
1140     */
1141    WORD8 i1_pic_scaling_matrix_present_flag;
1142
1143    /*
1144     *  Second chroma QP offset
1145     */
1146    WORD8  i1_second_chroma_qp_index_offset;
1147
1148
1149    /**
1150     * useDefaultScalingMatrixFlag
1151     */
1152    WORD8 ai1_use_default_scaling_matrix_flag[8];
1153
1154    /**
1155     * 4x4 Scaling lists after inverse zig zag scan
1156     */
1157    UWORD16 au2_4x4_weight_scale[6][16];
1158
1159    /**
1160     * 4x4 Scaling lists after inverse zig zag scan
1161     */
1162    UWORD16 au2_8x8_weight_scale[2][64];
1163
1164
1165    /**
1166     *  pic_scaling_list_present_flag
1167     */
1168    WORD8 ai1_pic_scaling_list_present_flag[8];
1169
1170    /**
1171     * Flag to give status of PPS structure
1172     */
1173    WORD8   i1_pps_valid;
1174
1175
1176} pps_t;
1177
1178/**
1179 * MMCO commands and params.
1180 */
1181typedef struct
1182{
1183    /* memory management control operation command */
1184    UWORD8 u1_memory_management_control_operation;
1185
1186    /*
1187     * Contains difference of pic nums of short-term pic/frame
1188     * 1. To signal it as "unused for reference" if mmco = 1
1189     * 2. To signal it as "used for long-term reference" if mmco = 3
1190     */
1191    UWORD32 u4_difference_of_pic_nums_minus1;
1192
1193    /* Long-term pic num to be set as "unused for reference" */
1194    UWORD8 u1_long_term_pic_num;
1195
1196    /*
1197     * Assign a long-term idx to a picture as follows
1198     * 1. Assign to a short-term pic if mmco = 3
1199     * 2. Assign to the current pic if mmco = 6
1200     */
1201    UWORD8 u1_long_term_frame_idx;
1202
1203    /*
1204     * The max long-term idx. The long-term pics having idx above
1205     * are set as "unused for reference
1206     */
1207    UWORD8 u1_max_long_term_frame_idx_plus1;
1208
1209}mmco_prms_t;
1210
1211/**
1212 * Structure to hold Reference picture list modification info
1213 */
1214typedef struct
1215{
1216    /* ref_pic_list_modification_flag_l0 */
1217    WORD8 i1_ref_pic_list_modification_flag_l0;
1218
1219    /* Modification required in list0 */
1220    WORD8 i1_modification_of_pic_nums_idc_l0[MAX_MODICATION_IDC];
1221
1222    /*
1223     * The absolute difference between the picture number of
1224     * the picture being moved to the current index in
1225     * list0 and the picture number prediction value
1226     */
1227    UWORD32 u4_abs_diff_pic_num_minus1_l0[MAX_MODICATION_IDC];
1228
1229    /*
1230     * The long-term picture number of the picture being moved
1231     * to the current index in list0
1232     */
1233    UWORD8 u1_long_term_pic_num_l0[MAX_MODICATION_IDC];
1234
1235    /* ref_pic_list_modification_flag_l1 */
1236    WORD8 i1_ref_pic_list_modification_flag_l1;
1237
1238    /* Modification required in list1 */
1239    WORD8 i1_modification_of_pic_nums_idc_l1[MAX_MODICATION_IDC];
1240
1241    /*
1242     * The absolute difference between the picture number of
1243     * the picture being moved to the current index in
1244     * list1 and the picture number prediction value
1245     */
1246    UWORD32 u4_abs_diff_pic_num_minus1_l1[MAX_MODICATION_IDC];
1247
1248    /*
1249     * The long-term picture number of the picture being moved
1250     * to the current index in list1
1251     */
1252   UWORD8 u1_long_term_pic_num_l1[MAX_MODICATION_IDC];
1253}rplm_t;
1254
1255/**
1256 * Structure to hold Slice Header info
1257 */
1258typedef struct
1259{
1260
1261    /*
1262     *  nal_unit_type
1263     */
1264    WORD8  i1_nal_unit_type;
1265
1266    /*
1267     *  nal_unit_idc
1268     */
1269    WORD8  i1_nal_unit_idc;
1270
1271    /*
1272     *  first_mb_in_slice
1273     */
1274    UWORD16   u2_first_mb_in_slice;
1275
1276    /*
1277     *  slice_type
1278     */
1279    UWORD8   u1_slice_type;
1280
1281    /*
1282     *  pic_parameter_set_id
1283     */
1284    UWORD8   u1_pps_id;
1285
1286    /*
1287     *  frame_num
1288     */
1289    WORD32 i4_frame_num;
1290
1291    /*
1292     *  field_pic_flag
1293     */
1294    WORD8   i1_field_pic_flag;
1295
1296    /*
1297     *  bottom_field_flag
1298     */
1299    WORD8   i1_bottom_field_flag;
1300
1301    /*
1302     *  second_field
1303     */
1304    WORD8   i1_second_field_flag;
1305
1306    /*
1307     *  idr_pic_id
1308     */
1309    UWORD16 u2_idr_pic_id ;
1310
1311    /*
1312     *  pic_order_cnt_lsb
1313     */
1314    UWORD16 i4_pic_order_cnt_lsb;
1315
1316    /*
1317     *  delta_pic_order_cnt_bottom
1318     */
1319    WORD32  i4_delta_pic_order_cnt_bottom;
1320
1321    /*
1322     *  delta_pic_order_cnt
1323     */
1324    WORD32   ai4_delta_pic_order_cnt[2];
1325
1326    /*
1327     *  redundant_pic_cnt
1328     */
1329    UWORD8   u1_redundant_pic_cnt;
1330
1331    /*
1332     *  direct_spatial_mv_pred_flag
1333     */
1334    UWORD8   u1_direct_spatial_mv_pred_flag;
1335
1336    /*
1337     *  num_ref_idx_active_override_flag
1338     */
1339    UWORD8   u1_num_ref_idx_active_override_flag;
1340
1341    /*
1342     *  num_ref_idx_l0_active
1343     */
1344    WORD8   i1_num_ref_idx_l0_active;
1345
1346    /*
1347     *  num_ref_idx_l1_active_minus1
1348     */
1349    WORD8   i1_num_ref_idx_l1_active;
1350
1351    /*
1352     * ref_pic_list_reordering_flag_l0
1353     */
1354    UWORD8  u1_ref_idx_reordering_flag_l0;
1355
1356    /*
1357     * ref_pic_list_reordering_flag_l1
1358     */
1359    UWORD8  u1_ref_idx_reordering_flag_l1;
1360
1361    /**
1362     *  Reference prediction list modification
1363     */
1364    rplm_t s_rplm;
1365
1366    /**
1367     * L0 Reference pic lists
1368     */
1369    ref_list_t as_ref_pic_list0[MAX_DPB_SIZE];
1370
1371    /**
1372     * L1 Reference pic lists
1373     */
1374    ref_list_t as_ref_pic_list1[MAX_DPB_SIZE];
1375
1376    /*
1377     * no_output_of_prior_pics_flag
1378     */
1379    UWORD8   u1_no_output_of_prior_pics_flag;
1380
1381    /*
1382     * long_term_reference_flag
1383     */
1384    UWORD8   u1_long_term_reference_flag;
1385
1386    /*
1387     * adaptive_ref_pic_marking_mode_flag
1388     */
1389    UWORD8   u1_adaptive_ref_pic_marking_mode_flag;
1390
1391    /*
1392     * Array to structures to store mmco commands
1393     * and parameters.
1394     */
1395    mmco_prms_t as_mmco_prms[MAX_MMCO_COMMANDS];
1396
1397    /*
1398     *  entropy_coding_mode_flag
1399     */
1400    WORD8   u1_entropy_coding_mode_flag;
1401
1402    /*
1403     *  cabac_init_idc
1404     */
1405    WORD8   i1_cabac_init_idc;
1406
1407    /*
1408     *  i1_slice_qp
1409     */
1410    WORD8   i1_slice_qp;
1411
1412    /*
1413     *  sp_for_switch_flag
1414     */
1415    UWORD8   u1_sp_for_switch_flag;
1416
1417    /*
1418     *  slice_qs_delta
1419     */
1420    UWORD8   u1_slice_qs;
1421
1422    /*
1423     *  disable_deblocking_filter_idc
1424     */
1425    WORD8   u1_disable_deblocking_filter_idc;
1426
1427    /*
1428     *  slice_alpha_c0_offset_div2
1429     */
1430    WORD8   i1_slice_alpha_c0_offset_div2;
1431
1432    /*
1433     *  slice_beta_offset_div2
1434     */
1435    WORD8   i1_slice_beta_offset_div2;
1436
1437    /*
1438     *  num_slice_groups_minus1
1439     */
1440    WORD8   u1_num_slice_groups_minus1;
1441
1442    /*
1443     *  slice_group_change_cycle
1444     */
1445    WORD8   u1_slice_group_change_cycle;
1446
1447    /**
1448     * Start MB X
1449     */
1450    UWORD16 i2_mb_x;
1451
1452    /**
1453     * Start MB Y
1454     */
1455    UWORD16 i2_mb_y;
1456
1457    /**
1458     * Absolute POC. Contains minimum of top and bottom POC.
1459     */
1460    WORD32 i4_abs_pic_order_cnt;
1461
1462    /**
1463     *  Absolute top POC. Contains top poc for frame or top
1464     *  field. Invalid for bottom field.
1465     */
1466    WORD32 i4_abs_top_pic_order_cnt;
1467
1468    /**
1469     *  Absolute top POC. Contains bottom poc for frame or bottom
1470     *  field. Invalid for top field.
1471     */
1472    WORD32 i4_abs_bottom_pic_order_cnt;
1473
1474    /** Flag signaling if the current slice is ref slice */
1475    UWORD8 i1_nal_ref_idc;
1476
1477    /** Flag to indicate if the current slice is MBAFF Frame */
1478    UWORD8 u1_mbaff_frame_flag;
1479
1480    /** luma_log2_weight_denom */
1481    UWORD8 u1_luma_log2_weight_denom;
1482
1483    /** chroma_log2_weight_denom */
1484    UWORD8 u1_chroma_log2_weight_denom;
1485
1486    /** luma_weight_l0_flag */
1487    UWORD8 au1_luma_weight_l0_flag[MAX_DPB_SIZE];
1488
1489    /** luma_weight_l0 : (-128, 127 )is the range of weights
1490     * when weighted pred is enabled, 128 is default value */
1491    WORD16 ai2_luma_weight_l0[MAX_DPB_SIZE];
1492
1493    /** luma_offset_l0 : (-128, 127 )is the range of offset
1494     * when weighted pred is enabled, 0 is default value */
1495    WORD8 ai1_luma_offset_l0[MAX_DPB_SIZE];
1496
1497    /** chroma_weight_l0_flag */
1498    UWORD8 au1_chroma_weight_l0_flag[MAX_DPB_SIZE];
1499
1500    /** chroma_weight_l0 : (-128, 127 )is the range of weights
1501     * when weighted pred is enabled, 128 is default value*/
1502    WORD16 ai2_chroma_weight_l0[MAX_DPB_SIZE][2];
1503
1504    /** chroma_offset_l0 : (-128, 127 )is the range of offset
1505     * when weighted pred is enabled, 0 is default value*/
1506    WORD8 ai1_chroma_offset_l0[MAX_DPB_SIZE][2];
1507
1508    /** luma_weight_l0_flag */
1509    UWORD8 au1_luma_weight_l1_flag[MAX_DPB_SIZE];
1510
1511    /** luma_weight_l1 : (-128, 127 )is the range of weights
1512     * when weighted pred is enabled, 128 is default value */
1513    WORD16 ai2_luma_weight_l1[MAX_DPB_SIZE];
1514
1515    /** luma_offset_l1 : (-128, 127 )is the range of offset
1516     * when weighted pred is enabled, 0 is default value */
1517    WORD8 ai1_luma_offset_l1[MAX_DPB_SIZE];
1518
1519    /** chroma_weight_l1_flag */
1520    UWORD8 au1_chroma_weight_l1_flag[MAX_DPB_SIZE];
1521
1522    /** chroma_weight_l1 : (-128, 127 )is the range of weights
1523     * when weighted pred is enabled, 128 is default value */
1524    WORD16 ai2_chroma_weight_l1[MAX_DPB_SIZE][2];
1525
1526    /** chroma_offset_l1 :(-128, 127 )is the range of offset
1527     * when weighted pred is enabled, 0 is default value */
1528    WORD8 ai1_chroma_offset_l1[MAX_DPB_SIZE][2];
1529}slice_header_t;
1530
1531
1532/*****************************************************************************/
1533/* The following can be used to type cast coefficient data that is stored    */
1534/*  per subblock. Note that though i2_level is shown as an array that        */
1535/*  holds 16 coefficients, only the first few entries will be valid. Next    */
1536/*  subblocks data starts after the valid number of coefficients. Number     */
1537/*  of non-zero coefficients will be derived using number of non-zero bits   */
1538/*  in sig coeff map                                                         */
1539/*****************************************************************************/
1540
1541/**
1542 * Structure to hold coefficient info for a 2x2 chroma DC transform
1543 */
1544typedef struct
1545{
1546    /**
1547     * significant coefficient map
1548     */
1549    UWORD8 u1_sig_coeff_map;
1550
1551    /**
1552     * sub block position
1553     */
1554    UWORD8 u1_subblk_pos;
1555
1556    /**
1557     * holds coefficients
1558     */
1559    WORD16  ai2_level[2 * 2];
1560}tu_sblk2x2_coeff_data_t;
1561
1562/**
1563 * Structure to hold coefficient info for a 4x4 transform
1564 */
1565typedef struct
1566{
1567    /**
1568     * significant coefficient map
1569     */
1570    UWORD16 u2_sig_coeff_map;
1571
1572    /**
1573     * sub block position
1574     */
1575    UWORD16 u2_subblk_pos;
1576
1577    /**
1578     * holds coefficients
1579     */
1580    WORD16  ai2_level[SUBBLK_COEFF_CNT];
1581}tu_sblk4x4_coeff_data_t;
1582
1583/**
1584 * Structure to hold coefficient info for a 8x8 transform
1585 */
1586typedef struct
1587{
1588
1589    /**
1590     * significant coefficient map
1591     */
1592    UWORD32 au4_sig_coeff_map[2];
1593
1594    /**
1595     * sub block position
1596     */
1597    UWORD16 u2_subblk_pos;
1598
1599    /**
1600     * holds coefficients
1601     */
1602    WORD16  ai2_level[TRANS_SIZE_8 * TRANS_SIZE_8];
1603}tu_blk8x8_coeff_data_t;
1604
1605
1606/**
1607 * Structure to hold coefficient info for a 16x16 IPCM MB
1608 */
1609typedef struct
1610{
1611    /**
1612     * holds coefficients
1613     */
1614    UWORD8  au1_level[MB_SIZE * MB_SIZE * 3 / 2];
1615}tu_ipcm_coeff_data_t;
1616
1617
1618typedef struct
1619{
1620    /**
1621     * Transform sizes 0: 4x4, 1: 8x8,
1622     */
1623    UWORD32     b1_trans_size : 1;
1624
1625    /**
1626     * Flag to signal if the current MB is IPCM
1627     */
1628    UWORD32     b1_ipcm : 1;
1629
1630    /**
1631     * Intra pred sizes  0: 4x4, 1: 8x8, 2: 16x16
1632     */
1633    UWORD32     b2_intra_pred_size : 2;
1634
1635    /**
1636     * Chroma intra mode
1637     */
1638    UWORD32     b2_intra_chroma_pred_mode: 2;
1639
1640    /**
1641     * Number of coded subblocks in the current MB, for which
1642     * tu data is sent. Maximum of 27 subblocks in the following
1643     * order.
1644     * 1 4x4 luma DC(for intra16x16),
1645     * 16 4x4 luma,
1646     * 2 2x2 chroma DC,
1647     * 8 4x4 chroma,
1648     */
1649    WORD32      b5_num_coded_sblks: 5;
1650
1651    /**
1652     * Flag to signal if 4x4 subblock for DC values (in INTRA 16x16 MB)
1653     * is coded
1654     */
1655    UWORD32     b1_luma_dc_coded: 1;
1656
1657    /**
1658     * Flag to signal if 4x4 subblock for DC values (in INTRA 16x16 MB)
1659     * is coded
1660     */
1661    UWORD32     b1_chroma_dc_coded: 1;
1662
1663    /**
1664     * CSBP - 16 bits, 1 bit for each 4x4
1665     * for intra16x16 mb_type only ac coefficients are
1666     */
1667    UWORD32     b16_luma_csbp: 16;
1668
1669    /**
1670     * CSBP - 16 bits, 1 bit for each 4x4
1671     * for intra16x16 mb_type only ac coefficients are
1672     */
1673    UWORD32     b8_chroma_csbp: 8;
1674
1675    /**
1676     * Luma Intra pred modes,
1677     * Based on intra pred size either 16, 4 or 1 entry will be
1678     * populated below.
1679     */
1680    UWORD8     au1_luma_intra_modes[16];
1681
1682}intra_mb_t;
1683
1684
1685typedef struct
1686{
1687    /**
1688     * Transform sizes 0: 4x4, 1: 8x8,
1689     */
1690    UWORD8     b1_trans_size : 1;
1691
1692
1693    /**
1694     * Skip flag
1695     */
1696    UWORD8     b1_skip : 1;
1697
1698
1699    /**
1700     * Number of coded subblocks in the current MB, for which
1701     * tu data is sent. Maximum of 26 subblocks in the following
1702     * order.
1703     * 16 4x4 luma,
1704     * 2 2x2 chroma DC,
1705     * 8 4x4 chroma,
1706     */
1707    WORD32      b5_num_coded_sblks: 5;
1708
1709    /**
1710     * CSBP - 16 bits, 1 bit for each 4x4
1711     * for intra16x16 mb_type only ac coefficients are
1712     */
1713    UWORD32     b16_luma_csbp: 16;
1714
1715    /**
1716     * CSBP - 16 bits, 1 bit for each 4x4
1717     * for intra16x16 mb_type only ac coefficients are
1718     */
1719    UWORD32     b16_chroma_csbp: 8;
1720}inter_mb_t;
1721
1722#endif /* _IH264_STRUCTS_H_ */
1723