xref: /aosp_15_r20/external/libavc/decoder/ih264d_parse_headers.c (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
1*495ae853SAndroid Build Coastguard Worker /******************************************************************************
2*495ae853SAndroid Build Coastguard Worker  *
3*495ae853SAndroid Build Coastguard Worker  * Copyright (C) 2015 The Android Open Source Project
4*495ae853SAndroid Build Coastguard Worker  *
5*495ae853SAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
6*495ae853SAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
7*495ae853SAndroid Build Coastguard Worker  * You may obtain a copy of the License at:
8*495ae853SAndroid Build Coastguard Worker  *
9*495ae853SAndroid Build Coastguard Worker  * http://www.apache.org/licenses/LICENSE-2.0
10*495ae853SAndroid Build Coastguard Worker  *
11*495ae853SAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
12*495ae853SAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
13*495ae853SAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*495ae853SAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
15*495ae853SAndroid Build Coastguard Worker  * limitations under the License.
16*495ae853SAndroid Build Coastguard Worker  *
17*495ae853SAndroid Build Coastguard Worker  *****************************************************************************
18*495ae853SAndroid Build Coastguard Worker  * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19*495ae853SAndroid Build Coastguard Worker */
20*495ae853SAndroid Build Coastguard Worker /*!
21*495ae853SAndroid Build Coastguard Worker  **************************************************************************
22*495ae853SAndroid Build Coastguard Worker  * \file ih264d_parse_headers.c
23*495ae853SAndroid Build Coastguard Worker  *
24*495ae853SAndroid Build Coastguard Worker  * \brief
25*495ae853SAndroid Build Coastguard Worker  *    Contains High level syntax[above slice] parsing routines
26*495ae853SAndroid Build Coastguard Worker  *
27*495ae853SAndroid Build Coastguard Worker  * \date
28*495ae853SAndroid Build Coastguard Worker  *    19/12/2002
29*495ae853SAndroid Build Coastguard Worker  *
30*495ae853SAndroid Build Coastguard Worker  * \author  AI
31*495ae853SAndroid Build Coastguard Worker  **************************************************************************
32*495ae853SAndroid Build Coastguard Worker  */
33*495ae853SAndroid Build Coastguard Worker #include <string.h>
34*495ae853SAndroid Build Coastguard Worker 
35*495ae853SAndroid Build Coastguard Worker #include "ih264_typedefs.h"
36*495ae853SAndroid Build Coastguard Worker #include "ih264_macros.h"
37*495ae853SAndroid Build Coastguard Worker #include "ih264_platform_macros.h"
38*495ae853SAndroid Build Coastguard Worker #include "ih264_defs.h"
39*495ae853SAndroid Build Coastguard Worker #include "ih264d_bitstrm.h"
40*495ae853SAndroid Build Coastguard Worker #include "ih264d_structs.h"
41*495ae853SAndroid Build Coastguard Worker #include "ih264d_parse_cavlc.h"
42*495ae853SAndroid Build Coastguard Worker #include "ih264d_defs.h"
43*495ae853SAndroid Build Coastguard Worker #include "ih264d_defs.h"
44*495ae853SAndroid Build Coastguard Worker #include "ih264d_defs.h"
45*495ae853SAndroid Build Coastguard Worker #include "ih264d_parse_slice.h"
46*495ae853SAndroid Build Coastguard Worker #include "ih264d_tables.h"
47*495ae853SAndroid Build Coastguard Worker #include "ih264d_utils.h"
48*495ae853SAndroid Build Coastguard Worker #include "ih264d_nal.h"
49*495ae853SAndroid Build Coastguard Worker #include "ih264d_deblocking.h"
50*495ae853SAndroid Build Coastguard Worker 
51*495ae853SAndroid Build Coastguard Worker #include "ih264d_mem_request.h"
52*495ae853SAndroid Build Coastguard Worker #include "ih264d_debug.h"
53*495ae853SAndroid Build Coastguard Worker #include "ih264d_error_handler.h"
54*495ae853SAndroid Build Coastguard Worker #include "ih264d_mb_utils.h"
55*495ae853SAndroid Build Coastguard Worker #include "ih264d_sei.h"
56*495ae853SAndroid Build Coastguard Worker #include "ih264d_vui.h"
57*495ae853SAndroid Build Coastguard Worker #include "ih264d_thread_parse_decode.h"
58*495ae853SAndroid Build Coastguard Worker #include "ih264d_thread_compute_bs.h"
59*495ae853SAndroid Build Coastguard Worker #include "ih264d_quant_scaling.h"
60*495ae853SAndroid Build Coastguard Worker #include "ih264d_defs.h"
61*495ae853SAndroid Build Coastguard Worker #include "ivd.h"
62*495ae853SAndroid Build Coastguard Worker #include "ih264d.h"
63*495ae853SAndroid Build Coastguard Worker 
64*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
65*495ae853SAndroid Build Coastguard Worker /*                                                                           */
66*495ae853SAndroid Build Coastguard Worker /*  Function Name : ih264d_get_pre_sei_params                                */
67*495ae853SAndroid Build Coastguard Worker /*                                                                           */
68*495ae853SAndroid Build Coastguard Worker /*  Description   : Gets valid pre-sei params in decoder struct from parse   */
69*495ae853SAndroid Build Coastguard Worker /*                  struct.                                                  */
70*495ae853SAndroid Build Coastguard Worker /*  Inputs        : u1_nal_unit_type slice type                              */
71*495ae853SAndroid Build Coastguard Worker /*                  ps_dec    Decoder parameters                             */
72*495ae853SAndroid Build Coastguard Worker /*  Globals       : None                                                     */
73*495ae853SAndroid Build Coastguard Worker /*  Outputs       : None                                                     */
74*495ae853SAndroid Build Coastguard Worker /*  Returns       : None                                                     */
75*495ae853SAndroid Build Coastguard Worker /*                                                                           */
76*495ae853SAndroid Build Coastguard Worker /*  Issues        : None                                                     */
77*495ae853SAndroid Build Coastguard Worker /*                                                                           */
78*495ae853SAndroid Build Coastguard Worker /*  Revision History:                                                        */
79*495ae853SAndroid Build Coastguard Worker /*                                                                           */
80*495ae853SAndroid Build Coastguard Worker /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
81*495ae853SAndroid Build Coastguard Worker /*                                          Draft                            */
82*495ae853SAndroid Build Coastguard Worker /*                                                                           */
83*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
84*495ae853SAndroid Build Coastguard Worker 
ih264d_get_pre_sei_params(dec_struct_t * ps_dec,UWORD8 u1_nal_unit_type)85*495ae853SAndroid Build Coastguard Worker void ih264d_get_pre_sei_params(dec_struct_t *ps_dec, UWORD8 u1_nal_unit_type)
86*495ae853SAndroid Build Coastguard Worker {
87*495ae853SAndroid Build Coastguard Worker     if((NULL != ps_dec->ps_sei) &&
88*495ae853SAndroid Build Coastguard Worker         ((0 == ps_dec->ps_sei->s_sei_ccv_params.u1_ccv_cancel_flag) &&
89*495ae853SAndroid Build Coastguard Worker         (0 == ps_dec->ps_sei->s_sei_ccv_params.u1_ccv_persistence_flag)))
90*495ae853SAndroid Build Coastguard Worker     {
91*495ae853SAndroid Build Coastguard Worker         ps_dec->ps_sei->u1_sei_ccv_params_present_flag = 0;
92*495ae853SAndroid Build Coastguard Worker         memset(&ps_dec->ps_sei->s_sei_ccv_params, 0, sizeof(sei_ccv_params_t));
93*495ae853SAndroid Build Coastguard Worker     }
94*495ae853SAndroid Build Coastguard Worker 
95*495ae853SAndroid Build Coastguard Worker     if((NULL != ps_dec->ps_cur_sps) &&
96*495ae853SAndroid Build Coastguard Worker         ((1 == ps_dec->ps_cur_sps->u1_vui_parameters_present_flag) &&
97*495ae853SAndroid Build Coastguard Worker         ((2 != ps_dec->ps_cur_sps->s_vui.u1_colour_primaries) &&
98*495ae853SAndroid Build Coastguard Worker         (2 != ps_dec->ps_cur_sps->s_vui.u1_matrix_coeffs) &&
99*495ae853SAndroid Build Coastguard Worker         (2 != ps_dec->ps_cur_sps->s_vui.u1_tfr_chars) &&
100*495ae853SAndroid Build Coastguard Worker         (4 != ps_dec->ps_cur_sps->s_vui.u1_tfr_chars) &&
101*495ae853SAndroid Build Coastguard Worker         (5 != ps_dec->ps_cur_sps->s_vui.u1_tfr_chars))))
102*495ae853SAndroid Build Coastguard Worker     {
103*495ae853SAndroid Build Coastguard Worker         if((1 == ps_dec->ps_sei_parse->u1_sei_ccv_params_present_flag) ||
104*495ae853SAndroid Build Coastguard Worker             (IDR_SLICE_NAL == u1_nal_unit_type))
105*495ae853SAndroid Build Coastguard Worker         {
106*495ae853SAndroid Build Coastguard Worker             ps_dec->ps_sei->u1_sei_ccv_params_present_flag =
107*495ae853SAndroid Build Coastguard Worker                         ps_dec->ps_sei_parse->u1_sei_ccv_params_present_flag;
108*495ae853SAndroid Build Coastguard Worker             ps_dec->ps_sei->s_sei_ccv_params = ps_dec->ps_sei_parse->s_sei_ccv_params;
109*495ae853SAndroid Build Coastguard Worker         }
110*495ae853SAndroid Build Coastguard Worker     }
111*495ae853SAndroid Build Coastguard Worker     else
112*495ae853SAndroid Build Coastguard Worker     {
113*495ae853SAndroid Build Coastguard Worker         ps_dec->ps_sei->u1_sei_ccv_params_present_flag = 0;
114*495ae853SAndroid Build Coastguard Worker         memset(&ps_dec->ps_sei->s_sei_ccv_params, 0, sizeof(sei_ccv_params_t));
115*495ae853SAndroid Build Coastguard Worker     }
116*495ae853SAndroid Build Coastguard Worker 
117*495ae853SAndroid Build Coastguard Worker     if(IDR_SLICE_NAL == u1_nal_unit_type)
118*495ae853SAndroid Build Coastguard Worker     {
119*495ae853SAndroid Build Coastguard Worker         ps_dec->ps_sei->u1_sei_mdcv_params_present_flag =
120*495ae853SAndroid Build Coastguard Worker                         ps_dec->ps_sei_parse->u1_sei_mdcv_params_present_flag;
121*495ae853SAndroid Build Coastguard Worker         ps_dec->ps_sei->s_sei_mdcv_params = ps_dec->ps_sei_parse->s_sei_mdcv_params;
122*495ae853SAndroid Build Coastguard Worker         ps_dec->ps_sei->u1_sei_cll_params_present_flag =
123*495ae853SAndroid Build Coastguard Worker                         ps_dec->ps_sei_parse->u1_sei_cll_params_present_flag;
124*495ae853SAndroid Build Coastguard Worker         ps_dec->ps_sei->s_sei_cll_params = ps_dec->ps_sei_parse->s_sei_cll_params;
125*495ae853SAndroid Build Coastguard Worker         ps_dec->ps_sei->u1_sei_ave_params_present_flag =
126*495ae853SAndroid Build Coastguard Worker                         ps_dec->ps_sei_parse->u1_sei_ave_params_present_flag;
127*495ae853SAndroid Build Coastguard Worker         ps_dec->ps_sei->s_sei_ave_params = ps_dec->ps_sei_parse->s_sei_ave_params;
128*495ae853SAndroid Build Coastguard Worker         ps_dec->ps_sei->u1_sei_sii_params_present_flag =
129*495ae853SAndroid Build Coastguard Worker             ps_dec->ps_sei_parse->u1_sei_sii_params_present_flag;
130*495ae853SAndroid Build Coastguard Worker         ps_dec->ps_sei->s_sei_sii_params = ps_dec->ps_sei_parse->s_sei_sii_params;
131*495ae853SAndroid Build Coastguard Worker     }
132*495ae853SAndroid Build Coastguard Worker 
133*495ae853SAndroid Build Coastguard Worker     if(NULL != ps_dec->ps_sei)
134*495ae853SAndroid Build Coastguard Worker     {
135*495ae853SAndroid Build Coastguard Worker         ps_dec->ps_sei->u1_sei_fgc_params_present_flag =
136*495ae853SAndroid Build Coastguard Worker             ps_dec->ps_sei_parse->u1_sei_fgc_params_present_flag;
137*495ae853SAndroid Build Coastguard Worker         ps_dec->ps_sei->s_sei_fgc_params = ps_dec->ps_sei_parse->s_sei_fgc_params;
138*495ae853SAndroid Build Coastguard Worker     }
139*495ae853SAndroid Build Coastguard Worker 
140*495ae853SAndroid Build Coastguard Worker     ps_dec->ps_sei_parse->u1_sei_mdcv_params_present_flag = 0;
141*495ae853SAndroid Build Coastguard Worker     memset(&ps_dec->ps_sei_parse->s_sei_mdcv_params, 0, sizeof(sei_mdcv_params_t));
142*495ae853SAndroid Build Coastguard Worker     ps_dec->ps_sei_parse->u1_sei_cll_params_present_flag = 0;
143*495ae853SAndroid Build Coastguard Worker     memset(&ps_dec->ps_sei_parse->s_sei_cll_params, 0, sizeof(sei_cll_params_t));
144*495ae853SAndroid Build Coastguard Worker     ps_dec->ps_sei_parse->u1_sei_ave_params_present_flag = 0;
145*495ae853SAndroid Build Coastguard Worker     memset(&ps_dec->ps_sei_parse->s_sei_ave_params, 0, sizeof(sei_ave_params_t));
146*495ae853SAndroid Build Coastguard Worker     ps_dec->ps_sei_parse->u1_sei_ccv_params_present_flag = 0;
147*495ae853SAndroid Build Coastguard Worker     memset(&ps_dec->ps_sei_parse->s_sei_ccv_params, 0, sizeof(sei_ccv_params_t));
148*495ae853SAndroid Build Coastguard Worker     ps_dec->ps_sei_parse->u1_sei_sii_params_present_flag = 0;
149*495ae853SAndroid Build Coastguard Worker     memset(&ps_dec->ps_sei_parse->s_sei_sii_params, 0, sizeof(sei_sii_params_t));
150*495ae853SAndroid Build Coastguard Worker }
151*495ae853SAndroid Build Coastguard Worker 
152*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
153*495ae853SAndroid Build Coastguard Worker /*                                                                           */
154*495ae853SAndroid Build Coastguard Worker /*  Function Name : ih264d_parse_slice_partition                                     */
155*495ae853SAndroid Build Coastguard Worker /*                                                                           */
156*495ae853SAndroid Build Coastguard Worker /*  Description   : This function is intended to parse and decode slice part */
157*495ae853SAndroid Build Coastguard Worker /*                  itions. Currently it's not implemented. Decoder will     */
158*495ae853SAndroid Build Coastguard Worker /*                  print a message, skips this NAL and continues            */
159*495ae853SAndroid Build Coastguard Worker /*  Inputs        : ps_dec    Decoder parameters                             */
160*495ae853SAndroid Build Coastguard Worker /*                  ps_bitstrm    Bitstream                                */
161*495ae853SAndroid Build Coastguard Worker /*  Globals       : None                                                     */
162*495ae853SAndroid Build Coastguard Worker /*  Processing    : This functionality needs to be implemented               */
163*495ae853SAndroid Build Coastguard Worker /*  Outputs       : None                                                     */
164*495ae853SAndroid Build Coastguard Worker /*  Returns       : None                                                     */
165*495ae853SAndroid Build Coastguard Worker /*                                                                           */
166*495ae853SAndroid Build Coastguard Worker /*  Issues        : Not implemented                                          */
167*495ae853SAndroid Build Coastguard Worker /*                                                                           */
168*495ae853SAndroid Build Coastguard Worker /*  Revision History:                                                        */
169*495ae853SAndroid Build Coastguard Worker /*                                                                           */
170*495ae853SAndroid Build Coastguard Worker /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
171*495ae853SAndroid Build Coastguard Worker /*         06 05 2002   NS              Draft                                */
172*495ae853SAndroid Build Coastguard Worker /*                                                                           */
173*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
174*495ae853SAndroid Build Coastguard Worker 
ih264d_parse_slice_partition(dec_struct_t * ps_dec,dec_bit_stream_t * ps_bitstrm)175*495ae853SAndroid Build Coastguard Worker WORD32 ih264d_parse_slice_partition(dec_struct_t * ps_dec,
176*495ae853SAndroid Build Coastguard Worker                                     dec_bit_stream_t * ps_bitstrm)
177*495ae853SAndroid Build Coastguard Worker {
178*495ae853SAndroid Build Coastguard Worker     H264_DEC_DEBUG_PRINT("\nSlice partition not supported");
179*495ae853SAndroid Build Coastguard Worker     UNUSED(ps_dec);
180*495ae853SAndroid Build Coastguard Worker     UNUSED(ps_bitstrm);
181*495ae853SAndroid Build Coastguard Worker     return (0);
182*495ae853SAndroid Build Coastguard Worker }
183*495ae853SAndroid Build Coastguard Worker 
184*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
185*495ae853SAndroid Build Coastguard Worker /*                                                                           */
186*495ae853SAndroid Build Coastguard Worker /*  Function Name : ih264d_parse_sei                                                */
187*495ae853SAndroid Build Coastguard Worker /*                                                                           */
188*495ae853SAndroid Build Coastguard Worker /*  Description   : This function is intended to parse and decode SEI        */
189*495ae853SAndroid Build Coastguard Worker /*                  Currently it's not implemented. Decoder will print a     */
190*495ae853SAndroid Build Coastguard Worker /*                  message, skips this NAL and continues                    */
191*495ae853SAndroid Build Coastguard Worker /*  Inputs        : ps_dec    Decoder parameters                       */
192*495ae853SAndroid Build Coastguard Worker /*                  ps_bitstrm    Bitstream                                */
193*495ae853SAndroid Build Coastguard Worker /*  Globals       : None                                                     */
194*495ae853SAndroid Build Coastguard Worker /*  Processing    : This functionality needs to be implemented               */
195*495ae853SAndroid Build Coastguard Worker /*  Outputs       : None                                                     */
196*495ae853SAndroid Build Coastguard Worker /*  Returns       : None                                                     */
197*495ae853SAndroid Build Coastguard Worker /*                                                                           */
198*495ae853SAndroid Build Coastguard Worker /*  Issues        : Not implemented                                          */
199*495ae853SAndroid Build Coastguard Worker /*                                                                           */
200*495ae853SAndroid Build Coastguard Worker /*  Revision History:                                                        */
201*495ae853SAndroid Build Coastguard Worker /*                                                                           */
202*495ae853SAndroid Build Coastguard Worker /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
203*495ae853SAndroid Build Coastguard Worker /*         06 05 2002   NS              Draft                                */
204*495ae853SAndroid Build Coastguard Worker /*                                                                           */
205*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
ih264d_parse_sei(dec_struct_t * ps_dec,dec_bit_stream_t * ps_bitstrm)206*495ae853SAndroid Build Coastguard Worker WORD32 ih264d_parse_sei(dec_struct_t * ps_dec, dec_bit_stream_t * ps_bitstrm)
207*495ae853SAndroid Build Coastguard Worker {
208*495ae853SAndroid Build Coastguard Worker     UNUSED(ps_dec);
209*495ae853SAndroid Build Coastguard Worker     UNUSED(ps_bitstrm);
210*495ae853SAndroid Build Coastguard Worker     return (0);
211*495ae853SAndroid Build Coastguard Worker }
212*495ae853SAndroid Build Coastguard Worker 
213*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
214*495ae853SAndroid Build Coastguard Worker /*                                                                           */
215*495ae853SAndroid Build Coastguard Worker /*  Function Name : ih264d_parse_filler_data                                          */
216*495ae853SAndroid Build Coastguard Worker /*                                                                           */
217*495ae853SAndroid Build Coastguard Worker /*  Description   : This function is intended to parse and decode filler     */
218*495ae853SAndroid Build Coastguard Worker /*                  data NAL. Currently it's not implemented. Decoder will   */
219*495ae853SAndroid Build Coastguard Worker /*                  print a message, skips this NAL and continues            */
220*495ae853SAndroid Build Coastguard Worker /*  Inputs        : ps_dec    Decoder parameters                       */
221*495ae853SAndroid Build Coastguard Worker /*                  ps_bitstrm    Bitstream                                */
222*495ae853SAndroid Build Coastguard Worker /*  Globals       : None                                                     */
223*495ae853SAndroid Build Coastguard Worker /*  Processing    : This functionality needs to be implemented               */
224*495ae853SAndroid Build Coastguard Worker /*  Outputs       : None                                                     */
225*495ae853SAndroid Build Coastguard Worker /*  Returns       : None                                                     */
226*495ae853SAndroid Build Coastguard Worker /*                                                                           */
227*495ae853SAndroid Build Coastguard Worker /*  Issues        : Not implemented                                          */
228*495ae853SAndroid Build Coastguard Worker /*                                                                           */
229*495ae853SAndroid Build Coastguard Worker /*  Revision History:                                                        */
230*495ae853SAndroid Build Coastguard Worker /*                                                                           */
231*495ae853SAndroid Build Coastguard Worker /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
232*495ae853SAndroid Build Coastguard Worker /*         06 05 2002   NS              Draft                                */
233*495ae853SAndroid Build Coastguard Worker /*                                                                           */
234*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
ih264d_parse_filler_data(dec_struct_t * ps_dec,dec_bit_stream_t * ps_bitstrm)235*495ae853SAndroid Build Coastguard Worker WORD32 ih264d_parse_filler_data(dec_struct_t * ps_dec,
236*495ae853SAndroid Build Coastguard Worker                                 dec_bit_stream_t * ps_bitstrm)
237*495ae853SAndroid Build Coastguard Worker {
238*495ae853SAndroid Build Coastguard Worker     UNUSED(ps_dec);
239*495ae853SAndroid Build Coastguard Worker     UNUSED(ps_bitstrm);
240*495ae853SAndroid Build Coastguard Worker     return (0);
241*495ae853SAndroid Build Coastguard Worker }
242*495ae853SAndroid Build Coastguard Worker 
243*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
244*495ae853SAndroid Build Coastguard Worker /*                                                                           */
245*495ae853SAndroid Build Coastguard Worker /*  Function Name : ih264d_parse_end_of_stream                                        */
246*495ae853SAndroid Build Coastguard Worker /*                                                                           */
247*495ae853SAndroid Build Coastguard Worker /*  Description   : This function is intended to parse and decode end of     */
248*495ae853SAndroid Build Coastguard Worker /*                  sequence. Currently it's not implemented. Decoder will   */
249*495ae853SAndroid Build Coastguard Worker /*                  print a message, skips this NAL and continues            */
250*495ae853SAndroid Build Coastguard Worker /*  Inputs        : ps_dec    Decoder parameters                       */
251*495ae853SAndroid Build Coastguard Worker /*  Globals       : None                                                     */
252*495ae853SAndroid Build Coastguard Worker /*  Processing    : This functionality needs to be implemented               */
253*495ae853SAndroid Build Coastguard Worker /*  Outputs       : None                                                     */
254*495ae853SAndroid Build Coastguard Worker /*  Returns       : None                                                     */
255*495ae853SAndroid Build Coastguard Worker /*                                                                           */
256*495ae853SAndroid Build Coastguard Worker /*  Issues        : Not implemented                                          */
257*495ae853SAndroid Build Coastguard Worker /*                                                                           */
258*495ae853SAndroid Build Coastguard Worker /*  Revision History:                                                        */
259*495ae853SAndroid Build Coastguard Worker /*                                                                           */
260*495ae853SAndroid Build Coastguard Worker /*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
261*495ae853SAndroid Build Coastguard Worker /*         06 05 2002   NS              Draft                                */
262*495ae853SAndroid Build Coastguard Worker /*                                                                           */
263*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
ih264d_parse_end_of_stream(dec_struct_t * ps_dec)264*495ae853SAndroid Build Coastguard Worker void ih264d_parse_end_of_stream(dec_struct_t * ps_dec)
265*495ae853SAndroid Build Coastguard Worker {
266*495ae853SAndroid Build Coastguard Worker     UNUSED(ps_dec);
267*495ae853SAndroid Build Coastguard Worker     return;
268*495ae853SAndroid Build Coastguard Worker }
269*495ae853SAndroid Build Coastguard Worker 
270*495ae853SAndroid Build Coastguard Worker /*!
271*495ae853SAndroid Build Coastguard Worker  **************************************************************************
272*495ae853SAndroid Build Coastguard Worker  * \if Function name : ih264d_parse_pps \endif
273*495ae853SAndroid Build Coastguard Worker  *
274*495ae853SAndroid Build Coastguard Worker  * \brief
275*495ae853SAndroid Build Coastguard Worker  *    Decodes Picture Parameter set
276*495ae853SAndroid Build Coastguard Worker  *
277*495ae853SAndroid Build Coastguard Worker  * \return
278*495ae853SAndroid Build Coastguard Worker  *    0 on Success and Error code otherwise
279*495ae853SAndroid Build Coastguard Worker  **************************************************************************
280*495ae853SAndroid Build Coastguard Worker  */
ih264d_parse_pps(dec_struct_t * ps_dec,dec_bit_stream_t * ps_bitstrm)281*495ae853SAndroid Build Coastguard Worker WORD32 ih264d_parse_pps(dec_struct_t * ps_dec, dec_bit_stream_t * ps_bitstrm)
282*495ae853SAndroid Build Coastguard Worker {
283*495ae853SAndroid Build Coastguard Worker     UWORD8 uc_temp;
284*495ae853SAndroid Build Coastguard Worker     dec_seq_params_t * ps_sps = NULL;
285*495ae853SAndroid Build Coastguard Worker     dec_pic_params_t * ps_pps = NULL;
286*495ae853SAndroid Build Coastguard Worker     UWORD32 *pu4_bitstrm_buf = ps_dec->ps_bitstrm->pu4_buffer;
287*495ae853SAndroid Build Coastguard Worker     UWORD32 *pu4_bitstrm_ofst = &ps_dec->ps_bitstrm->u4_ofst;
288*495ae853SAndroid Build Coastguard Worker 
289*495ae853SAndroid Build Coastguard Worker     /* Variables used for error resilience checks */
290*495ae853SAndroid Build Coastguard Worker     UWORD64 u8_temp;
291*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_temp;
292*495ae853SAndroid Build Coastguard Worker     WORD32 i_temp;
293*495ae853SAndroid Build Coastguard Worker 
294*495ae853SAndroid Build Coastguard Worker     /* For High profile related syntax elements */
295*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_more_data_flag;
296*495ae853SAndroid Build Coastguard Worker     WORD32 i4_i;
297*495ae853SAndroid Build Coastguard Worker 
298*495ae853SAndroid Build Coastguard Worker     if(!(ps_dec->i4_header_decoded & 1))
299*495ae853SAndroid Build Coastguard Worker         return ERROR_INV_SPS_PPS_T;
300*495ae853SAndroid Build Coastguard Worker 
301*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
302*495ae853SAndroid Build Coastguard Worker     /* Decode pic_parameter_set_id and find corresponding pic params      */
303*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
304*495ae853SAndroid Build Coastguard Worker     u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
305*495ae853SAndroid Build Coastguard Worker     if(u4_temp & MASK_ERR_PIC_SET_ID)
306*495ae853SAndroid Build Coastguard Worker         return ERROR_INV_SPS_PPS_T;
307*495ae853SAndroid Build Coastguard Worker     ps_pps = ps_dec->pv_scratch_sps_pps;
308*495ae853SAndroid Build Coastguard Worker     *ps_pps = ps_dec->ps_pps[u4_temp];
309*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_pic_parameter_set_id = (WORD8)u4_temp;
310*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("PPS: pic_parameter_set_id",ps_pps->u1_pic_parameter_set_id);
311*495ae853SAndroid Build Coastguard Worker 
312*495ae853SAndroid Build Coastguard Worker     /************************************************/
313*495ae853SAndroid Build Coastguard Worker     /* initilization of High profile syntax element */
314*495ae853SAndroid Build Coastguard Worker     /************************************************/
315*495ae853SAndroid Build Coastguard Worker     ps_pps->i4_transform_8x8_mode_flag = 0;
316*495ae853SAndroid Build Coastguard Worker     ps_pps->i4_pic_scaling_matrix_present_flag = 0;
317*495ae853SAndroid Build Coastguard Worker 
318*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
319*495ae853SAndroid Build Coastguard Worker     /* Decode seq_parameter_set_id and map it to a seq_parameter_set      */
320*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
321*495ae853SAndroid Build Coastguard Worker     u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
322*495ae853SAndroid Build Coastguard Worker     if(u4_temp & MASK_ERR_SEQ_SET_ID)
323*495ae853SAndroid Build Coastguard Worker         return ERROR_INV_SPS_PPS_T;
324*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("PPS: seq_parameter_set_id",u4_temp);
325*495ae853SAndroid Build Coastguard Worker     ps_sps = &ps_dec->ps_sps[u4_temp];
326*495ae853SAndroid Build Coastguard Worker 
327*495ae853SAndroid Build Coastguard Worker     if(FALSE == ps_sps->u1_is_valid)
328*495ae853SAndroid Build Coastguard Worker         return ERROR_INV_SPS_PPS_T;
329*495ae853SAndroid Build Coastguard Worker     ps_pps->ps_sps = ps_sps;
330*495ae853SAndroid Build Coastguard Worker 
331*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
332*495ae853SAndroid Build Coastguard Worker     /* Decode entropy_coding_mode                                         */
333*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
334*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_entropy_coding_mode = ih264d_get_bit_h264(ps_bitstrm);
335*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("PPS: entropy_coding_mode_flag",ps_pps->u1_entropy_coding_mode);
336*495ae853SAndroid Build Coastguard Worker 
337*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_pic_order_present_flag = ih264d_get_bit_h264(ps_bitstrm);
338*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("PPS: pic_order_present_flag",ps_pps->u1_pic_order_present_flag);
339*495ae853SAndroid Build Coastguard Worker 
340*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
341*495ae853SAndroid Build Coastguard Worker     /* Decode num_slice_groups_minus1                                     */
342*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
343*495ae853SAndroid Build Coastguard Worker     u8_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf) + (UWORD64)1;
344*495ae853SAndroid Build Coastguard Worker     if(u8_temp != 1)
345*495ae853SAndroid Build Coastguard Worker     {
346*495ae853SAndroid Build Coastguard Worker         return ERROR_FEATURE_UNAVAIL;
347*495ae853SAndroid Build Coastguard Worker     }
348*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_num_slice_groups = u8_temp;
349*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("PPS: num_slice_groups_minus1",ps_pps->u1_num_slice_groups -1);
350*495ae853SAndroid Build Coastguard Worker 
351*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
352*495ae853SAndroid Build Coastguard Worker     /* Other parameter set values                                         */
353*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
354*495ae853SAndroid Build Coastguard Worker     u8_temp = (UWORD64)1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
355*495ae853SAndroid Build Coastguard Worker     if(u8_temp > H264_MAX_REF_IDX)
356*495ae853SAndroid Build Coastguard Worker         return ERROR_REF_IDX;
357*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_num_ref_idx_lx_active[0] = u8_temp;
358*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("PPS: num_ref_idx_l0_active_minus1",
359*495ae853SAndroid Build Coastguard Worker                     ps_pps->u1_num_ref_idx_lx_active[0] - 1);
360*495ae853SAndroid Build Coastguard Worker 
361*495ae853SAndroid Build Coastguard Worker     u8_temp = (UWORD64)1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
362*495ae853SAndroid Build Coastguard Worker     if(u8_temp > H264_MAX_REF_IDX)
363*495ae853SAndroid Build Coastguard Worker         return ERROR_REF_IDX;
364*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_num_ref_idx_lx_active[1] = u8_temp;
365*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("PPS: num_ref_idx_l1_active_minus1",
366*495ae853SAndroid Build Coastguard Worker                     ps_pps->u1_num_ref_idx_lx_active[1] - 1);
367*495ae853SAndroid Build Coastguard Worker 
368*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_wted_pred_flag = ih264d_get_bit_h264(ps_bitstrm);
369*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("PPS: weighted prediction u4_flag",ps_pps->u1_wted_pred_flag);
370*495ae853SAndroid Build Coastguard Worker     uc_temp = ih264d_get_bits_h264(ps_bitstrm, 2);
371*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("PPS: weighted_bipred_idc",uc_temp);
372*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_wted_bipred_idc = uc_temp;
373*495ae853SAndroid Build Coastguard Worker 
374*495ae853SAndroid Build Coastguard Worker     if(ps_pps->u1_wted_bipred_idc > MAX_WEIGHT_BIPRED_IDC)
375*495ae853SAndroid Build Coastguard Worker         return ERROR_INV_SPS_PPS_T;
376*495ae853SAndroid Build Coastguard Worker     {
377*495ae853SAndroid Build Coastguard Worker         WORD64 i8_temp;
378*495ae853SAndroid Build Coastguard Worker         i8_temp = (WORD64)26 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
379*495ae853SAndroid Build Coastguard Worker 
380*495ae853SAndroid Build Coastguard Worker         if((i8_temp < MIN_H264_QP) || (i8_temp > MAX_H264_QP))
381*495ae853SAndroid Build Coastguard Worker             return ERROR_INV_RANGE_QP_T;
382*495ae853SAndroid Build Coastguard Worker 
383*495ae853SAndroid Build Coastguard Worker         ps_pps->u1_pic_init_qp = i8_temp;
384*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("PPS: pic_init_qp_minus26",ps_pps->u1_pic_init_qp - 26);
385*495ae853SAndroid Build Coastguard Worker 
386*495ae853SAndroid Build Coastguard Worker         i8_temp = (WORD64)26 + ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
387*495ae853SAndroid Build Coastguard Worker 
388*495ae853SAndroid Build Coastguard Worker         if((i8_temp < MIN_H264_QP) || (i8_temp > MAX_H264_QP))
389*495ae853SAndroid Build Coastguard Worker             return ERROR_INV_RANGE_QP_T;
390*495ae853SAndroid Build Coastguard Worker 
391*495ae853SAndroid Build Coastguard Worker         ps_pps->u1_pic_init_qs = i8_temp;
392*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("PPS: pic_init_qs_minus26",ps_pps->u1_pic_init_qs - 26);
393*495ae853SAndroid Build Coastguard Worker     }
394*495ae853SAndroid Build Coastguard Worker 
395*495ae853SAndroid Build Coastguard Worker     i_temp = ih264d_sev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
396*495ae853SAndroid Build Coastguard Worker     if((i_temp < -12) || (i_temp > 12))
397*495ae853SAndroid Build Coastguard Worker         return ERROR_INV_RANGE_QP_T;
398*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_chroma_qp_index_offset = i_temp;
399*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("PPS: chroma_qp_index_offset",ps_pps->i1_chroma_qp_index_offset);
400*495ae853SAndroid Build Coastguard Worker 
401*495ae853SAndroid Build Coastguard Worker     /***************************************************************************/
402*495ae853SAndroid Build Coastguard Worker     /* initialize second_chroma_qp_index_offset to i1_chroma_qp_index_offset if */
403*495ae853SAndroid Build Coastguard Worker     /* second_chroma_qp_index_offset is not present in bit-ps_bitstrm              */
404*495ae853SAndroid Build Coastguard Worker     /***************************************************************************/
405*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_second_chroma_qp_index_offset =
406*495ae853SAndroid Build Coastguard Worker                     ps_pps->i1_chroma_qp_index_offset;
407*495ae853SAndroid Build Coastguard Worker 
408*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_deblocking_filter_parameters_present_flag = ih264d_get_bit_h264(
409*495ae853SAndroid Build Coastguard Worker                     ps_bitstrm);
410*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("PPS: deblocking_filter_control_present_flag",
411*495ae853SAndroid Build Coastguard Worker                     ps_pps->u1_deblocking_filter_parameters_present_flag);
412*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_constrained_intra_pred_flag = ih264d_get_bit_h264(ps_bitstrm);
413*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("PPS: constrained_intra_pred_flag",
414*495ae853SAndroid Build Coastguard Worker                     ps_pps->u1_constrained_intra_pred_flag);
415*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_redundant_pic_cnt_present_flag = ih264d_get_bit_h264(ps_bitstrm);
416*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("PPS: redundant_pic_cnt_present_flag",
417*495ae853SAndroid Build Coastguard Worker                     ps_pps->u1_redundant_pic_cnt_present_flag);
418*495ae853SAndroid Build Coastguard Worker 
419*495ae853SAndroid Build Coastguard Worker     /* High profile related syntax elements */
420*495ae853SAndroid Build Coastguard Worker     u1_more_data_flag = MORE_RBSP_DATA(ps_bitstrm);
421*495ae853SAndroid Build Coastguard Worker     if(u1_more_data_flag && (ps_pps->ps_sps->u1_profile_idc == HIGH_PROFILE_IDC))
422*495ae853SAndroid Build Coastguard Worker     {
423*495ae853SAndroid Build Coastguard Worker         /* read transform_8x8_mode_flag  */
424*495ae853SAndroid Build Coastguard Worker         ps_pps->i4_transform_8x8_mode_flag = (WORD32)ih264d_get_bit_h264(
425*495ae853SAndroid Build Coastguard Worker                         ps_bitstrm);
426*495ae853SAndroid Build Coastguard Worker 
427*495ae853SAndroid Build Coastguard Worker         /* read pic_scaling_matrix_present_flag */
428*495ae853SAndroid Build Coastguard Worker         ps_pps->i4_pic_scaling_matrix_present_flag =
429*495ae853SAndroid Build Coastguard Worker                         (WORD32)ih264d_get_bit_h264(ps_bitstrm);
430*495ae853SAndroid Build Coastguard Worker 
431*495ae853SAndroid Build Coastguard Worker         if(ps_pps->i4_pic_scaling_matrix_present_flag)
432*495ae853SAndroid Build Coastguard Worker         {
433*495ae853SAndroid Build Coastguard Worker             /* read the scaling matrices */
434*495ae853SAndroid Build Coastguard Worker             for(i4_i = 0; i4_i < (6 + (ps_pps->i4_transform_8x8_mode_flag << 1)); i4_i++)
435*495ae853SAndroid Build Coastguard Worker             {
436*495ae853SAndroid Build Coastguard Worker                 ps_pps->u1_pic_scaling_list_present_flag[i4_i] =
437*495ae853SAndroid Build Coastguard Worker                                 ih264d_get_bit_h264(ps_bitstrm);
438*495ae853SAndroid Build Coastguard Worker 
439*495ae853SAndroid Build Coastguard Worker                 if(ps_pps->u1_pic_scaling_list_present_flag[i4_i])
440*495ae853SAndroid Build Coastguard Worker                 {
441*495ae853SAndroid Build Coastguard Worker                     WORD32 ret;
442*495ae853SAndroid Build Coastguard Worker                     if(i4_i < 6)
443*495ae853SAndroid Build Coastguard Worker                     {
444*495ae853SAndroid Build Coastguard Worker                         ret = ih264d_scaling_list(
445*495ae853SAndroid Build Coastguard Worker                                         ps_pps->i2_pic_scalinglist4x4[i4_i],
446*495ae853SAndroid Build Coastguard Worker                                         16,
447*495ae853SAndroid Build Coastguard Worker                                         &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i],
448*495ae853SAndroid Build Coastguard Worker                                         ps_bitstrm);
449*495ae853SAndroid Build Coastguard Worker                     }
450*495ae853SAndroid Build Coastguard Worker                     else
451*495ae853SAndroid Build Coastguard Worker                     {
452*495ae853SAndroid Build Coastguard Worker                         ret = ih264d_scaling_list(
453*495ae853SAndroid Build Coastguard Worker                                         ps_pps->i2_pic_scalinglist8x8[i4_i - 6],
454*495ae853SAndroid Build Coastguard Worker                                         64,
455*495ae853SAndroid Build Coastguard Worker                                         &ps_pps->u1_pic_use_default_scaling_matrix_flag[i4_i],
456*495ae853SAndroid Build Coastguard Worker                                         ps_bitstrm);
457*495ae853SAndroid Build Coastguard Worker                     }
458*495ae853SAndroid Build Coastguard Worker 
459*495ae853SAndroid Build Coastguard Worker                     if(ret != OK)
460*495ae853SAndroid Build Coastguard Worker                     {
461*495ae853SAndroid Build Coastguard Worker                         return ret;
462*495ae853SAndroid Build Coastguard Worker                     }
463*495ae853SAndroid Build Coastguard Worker                 }
464*495ae853SAndroid Build Coastguard Worker             }
465*495ae853SAndroid Build Coastguard Worker         }
466*495ae853SAndroid Build Coastguard Worker 
467*495ae853SAndroid Build Coastguard Worker         /* read second_chroma_qp_index_offset syntax element */
468*495ae853SAndroid Build Coastguard Worker         i_temp = ih264d_sev(
469*495ae853SAndroid Build Coastguard Worker                         pu4_bitstrm_ofst, pu4_bitstrm_buf);
470*495ae853SAndroid Build Coastguard Worker 
471*495ae853SAndroid Build Coastguard Worker         if((i_temp < -12) || (i_temp > 12))
472*495ae853SAndroid Build Coastguard Worker             return ERROR_INV_RANGE_QP_T;
473*495ae853SAndroid Build Coastguard Worker 
474*495ae853SAndroid Build Coastguard Worker         ps_pps->i1_second_chroma_qp_index_offset = i_temp;
475*495ae853SAndroid Build Coastguard Worker     }
476*495ae853SAndroid Build Coastguard Worker 
477*495ae853SAndroid Build Coastguard Worker     /* In case bitstream read has exceeded the filled size, then
478*495ae853SAndroid Build Coastguard Worker        return an error */
479*495ae853SAndroid Build Coastguard Worker     if(EXCEED_OFFSET(ps_bitstrm))
480*495ae853SAndroid Build Coastguard Worker     {
481*495ae853SAndroid Build Coastguard Worker         return ERROR_INV_SPS_PPS_T;
482*495ae853SAndroid Build Coastguard Worker     }
483*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_is_valid = TRUE;
484*495ae853SAndroid Build Coastguard Worker     ps_dec->ps_pps[ps_pps->u1_pic_parameter_set_id] = *ps_pps;
485*495ae853SAndroid Build Coastguard Worker     return OK;
486*495ae853SAndroid Build Coastguard Worker }
487*495ae853SAndroid Build Coastguard Worker 
488*495ae853SAndroid Build Coastguard Worker /*!
489*495ae853SAndroid Build Coastguard Worker  **************************************************************************
490*495ae853SAndroid Build Coastguard Worker  * \if Function name : ih264d_parse_sps \endif
491*495ae853SAndroid Build Coastguard Worker  *
492*495ae853SAndroid Build Coastguard Worker  * \brief
493*495ae853SAndroid Build Coastguard Worker  *    Decodes Sequence parameter set from the bitstream
494*495ae853SAndroid Build Coastguard Worker  *
495*495ae853SAndroid Build Coastguard Worker  * \return
496*495ae853SAndroid Build Coastguard Worker  *    0 on Success and Error code otherwise
497*495ae853SAndroid Build Coastguard Worker  **************************************************************************
498*495ae853SAndroid Build Coastguard Worker  */
ih264d_correct_level_idc(UWORD32 u4_level_idc,UWORD32 u4_total_mbs)499*495ae853SAndroid Build Coastguard Worker UWORD32 ih264d_correct_level_idc(UWORD32 u4_level_idc, UWORD32 u4_total_mbs)
500*495ae853SAndroid Build Coastguard Worker {
501*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_max_mbs_allowed;
502*495ae853SAndroid Build Coastguard Worker 
503*495ae853SAndroid Build Coastguard Worker     switch(u4_level_idc)
504*495ae853SAndroid Build Coastguard Worker     {
505*495ae853SAndroid Build Coastguard Worker         case H264_LEVEL_1_0:
506*495ae853SAndroid Build Coastguard Worker             u4_max_mbs_allowed = MAX_MBS_LEVEL_10;
507*495ae853SAndroid Build Coastguard Worker             break;
508*495ae853SAndroid Build Coastguard Worker         case H264_LEVEL_1_1:
509*495ae853SAndroid Build Coastguard Worker             u4_max_mbs_allowed = MAX_MBS_LEVEL_11;
510*495ae853SAndroid Build Coastguard Worker             break;
511*495ae853SAndroid Build Coastguard Worker         case H264_LEVEL_1_2:
512*495ae853SAndroid Build Coastguard Worker             u4_max_mbs_allowed = MAX_MBS_LEVEL_12;
513*495ae853SAndroid Build Coastguard Worker             break;
514*495ae853SAndroid Build Coastguard Worker         case H264_LEVEL_1_3:
515*495ae853SAndroid Build Coastguard Worker             u4_max_mbs_allowed = MAX_MBS_LEVEL_13;
516*495ae853SAndroid Build Coastguard Worker             break;
517*495ae853SAndroid Build Coastguard Worker         case H264_LEVEL_2_0:
518*495ae853SAndroid Build Coastguard Worker             u4_max_mbs_allowed = MAX_MBS_LEVEL_20;
519*495ae853SAndroid Build Coastguard Worker             break;
520*495ae853SAndroid Build Coastguard Worker         case H264_LEVEL_2_1:
521*495ae853SAndroid Build Coastguard Worker             u4_max_mbs_allowed = MAX_MBS_LEVEL_21;
522*495ae853SAndroid Build Coastguard Worker             break;
523*495ae853SAndroid Build Coastguard Worker         case H264_LEVEL_2_2:
524*495ae853SAndroid Build Coastguard Worker             u4_max_mbs_allowed = MAX_MBS_LEVEL_22;
525*495ae853SAndroid Build Coastguard Worker             break;
526*495ae853SAndroid Build Coastguard Worker         case H264_LEVEL_3_0:
527*495ae853SAndroid Build Coastguard Worker             u4_max_mbs_allowed = MAX_MBS_LEVEL_30;
528*495ae853SAndroid Build Coastguard Worker             break;
529*495ae853SAndroid Build Coastguard Worker         case H264_LEVEL_3_1:
530*495ae853SAndroid Build Coastguard Worker             u4_max_mbs_allowed = MAX_MBS_LEVEL_31;
531*495ae853SAndroid Build Coastguard Worker             break;
532*495ae853SAndroid Build Coastguard Worker         case H264_LEVEL_3_2:
533*495ae853SAndroid Build Coastguard Worker             u4_max_mbs_allowed = MAX_MBS_LEVEL_32;
534*495ae853SAndroid Build Coastguard Worker             break;
535*495ae853SAndroid Build Coastguard Worker         case H264_LEVEL_4_0:
536*495ae853SAndroid Build Coastguard Worker             u4_max_mbs_allowed = MAX_MBS_LEVEL_40;
537*495ae853SAndroid Build Coastguard Worker             break;
538*495ae853SAndroid Build Coastguard Worker         case H264_LEVEL_4_1:
539*495ae853SAndroid Build Coastguard Worker             u4_max_mbs_allowed = MAX_MBS_LEVEL_41;
540*495ae853SAndroid Build Coastguard Worker             break;
541*495ae853SAndroid Build Coastguard Worker         case H264_LEVEL_4_2:
542*495ae853SAndroid Build Coastguard Worker             u4_max_mbs_allowed = MAX_MBS_LEVEL_42;
543*495ae853SAndroid Build Coastguard Worker             break;
544*495ae853SAndroid Build Coastguard Worker         case H264_LEVEL_5_0:
545*495ae853SAndroid Build Coastguard Worker             u4_max_mbs_allowed = MAX_MBS_LEVEL_50;
546*495ae853SAndroid Build Coastguard Worker             break;
547*495ae853SAndroid Build Coastguard Worker         case H264_LEVEL_5_1:
548*495ae853SAndroid Build Coastguard Worker         default:
549*495ae853SAndroid Build Coastguard Worker             u4_max_mbs_allowed = MAX_MBS_LEVEL_51;
550*495ae853SAndroid Build Coastguard Worker             break;
551*495ae853SAndroid Build Coastguard Worker 
552*495ae853SAndroid Build Coastguard Worker     }
553*495ae853SAndroid Build Coastguard Worker 
554*495ae853SAndroid Build Coastguard Worker     /*correct of the level is incorrect*/
555*495ae853SAndroid Build Coastguard Worker     if(u4_total_mbs > u4_max_mbs_allowed)
556*495ae853SAndroid Build Coastguard Worker     {
557*495ae853SAndroid Build Coastguard Worker         if(u4_total_mbs > MAX_MBS_LEVEL_50)
558*495ae853SAndroid Build Coastguard Worker             u4_level_idc = H264_LEVEL_5_1;
559*495ae853SAndroid Build Coastguard Worker         else if(u4_total_mbs > MAX_MBS_LEVEL_42)
560*495ae853SAndroid Build Coastguard Worker             u4_level_idc = H264_LEVEL_5_0;
561*495ae853SAndroid Build Coastguard Worker         else if(u4_total_mbs > MAX_MBS_LEVEL_41)
562*495ae853SAndroid Build Coastguard Worker             u4_level_idc = H264_LEVEL_4_2;
563*495ae853SAndroid Build Coastguard Worker         else if(u4_total_mbs > MAX_MBS_LEVEL_40)
564*495ae853SAndroid Build Coastguard Worker             u4_level_idc = H264_LEVEL_4_1;
565*495ae853SAndroid Build Coastguard Worker         else if(u4_total_mbs > MAX_MBS_LEVEL_32)
566*495ae853SAndroid Build Coastguard Worker             u4_level_idc = H264_LEVEL_4_0;
567*495ae853SAndroid Build Coastguard Worker         else if(u4_total_mbs > MAX_MBS_LEVEL_31)
568*495ae853SAndroid Build Coastguard Worker             u4_level_idc = H264_LEVEL_3_2;
569*495ae853SAndroid Build Coastguard Worker         else if(u4_total_mbs > MAX_MBS_LEVEL_30)
570*495ae853SAndroid Build Coastguard Worker             u4_level_idc = H264_LEVEL_3_1;
571*495ae853SAndroid Build Coastguard Worker         else if(u4_total_mbs > MAX_MBS_LEVEL_21)
572*495ae853SAndroid Build Coastguard Worker             u4_level_idc = H264_LEVEL_3_0;
573*495ae853SAndroid Build Coastguard Worker         else if(u4_total_mbs > MAX_MBS_LEVEL_20)
574*495ae853SAndroid Build Coastguard Worker             u4_level_idc = H264_LEVEL_2_1;
575*495ae853SAndroid Build Coastguard Worker         else if(u4_total_mbs > MAX_MBS_LEVEL_10)
576*495ae853SAndroid Build Coastguard Worker             u4_level_idc = H264_LEVEL_2_0;
577*495ae853SAndroid Build Coastguard Worker     }
578*495ae853SAndroid Build Coastguard Worker 
579*495ae853SAndroid Build Coastguard Worker     return (u4_level_idc);
580*495ae853SAndroid Build Coastguard Worker 
581*495ae853SAndroid Build Coastguard Worker }
ih264d_parse_sps(dec_struct_t * ps_dec,dec_bit_stream_t * ps_bitstrm)582*495ae853SAndroid Build Coastguard Worker WORD32 ih264d_parse_sps(dec_struct_t *ps_dec, dec_bit_stream_t *ps_bitstrm)
583*495ae853SAndroid Build Coastguard Worker {
584*495ae853SAndroid Build Coastguard Worker     UWORD8 i;
585*495ae853SAndroid Build Coastguard Worker     dec_seq_params_t *ps_seq = NULL;
586*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_profile_idc, u1_level_idc, u1_seq_parameter_set_id, u1_mb_aff_flag = 0;
587*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_max_frm_num;
588*495ae853SAndroid Build Coastguard Worker     UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
589*495ae853SAndroid Build Coastguard Worker     UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
590*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_frm, uc_constraint_set0_flag, uc_constraint_set1_flag;
591*495ae853SAndroid Build Coastguard Worker     WORD32 i4_cropped_ht, i4_cropped_wd;
592*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_temp;
593*495ae853SAndroid Build Coastguard Worker     UWORD64 u8_temp;
594*495ae853SAndroid Build Coastguard Worker     UWORD32 u4_pic_height_in_map_units, u4_pic_width_in_mbs;
595*495ae853SAndroid Build Coastguard Worker     UWORD32 u2_pic_wd = 0;
596*495ae853SAndroid Build Coastguard Worker     UWORD32 u2_pic_ht = 0;
597*495ae853SAndroid Build Coastguard Worker     UWORD32 u2_frm_wd_y = 0;
598*495ae853SAndroid Build Coastguard Worker     UWORD32 u2_frm_ht_y = 0;
599*495ae853SAndroid Build Coastguard Worker     UWORD32 u2_frm_wd_uv = 0;
600*495ae853SAndroid Build Coastguard Worker     UWORD32 u2_frm_ht_uv = 0;
601*495ae853SAndroid Build Coastguard Worker     UWORD32 u2_crop_offset_y = 0;
602*495ae853SAndroid Build Coastguard Worker     UWORD32 u2_crop_offset_uv = 0;
603*495ae853SAndroid Build Coastguard Worker     WORD32 ret;
604*495ae853SAndroid Build Coastguard Worker     WORD32 num_reorder_frames;
605*495ae853SAndroid Build Coastguard Worker     /* High profile related syntax element */
606*495ae853SAndroid Build Coastguard Worker     WORD32 i4_i;
607*495ae853SAndroid Build Coastguard Worker     /* G050 */
608*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_frame_cropping_flag, u1_frame_cropping_rect_left_ofst,
609*495ae853SAndroid Build Coastguard Worker                     u1_frame_cropping_rect_right_ofst,
610*495ae853SAndroid Build Coastguard Worker                     u1_frame_cropping_rect_top_ofst,
611*495ae853SAndroid Build Coastguard Worker                     u1_frame_cropping_rect_bottom_ofst;
612*495ae853SAndroid Build Coastguard Worker     /* G050 */
613*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
614*495ae853SAndroid Build Coastguard Worker     /* Decode seq_parameter_set_id and profile and level values           */
615*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
616*495ae853SAndroid Build Coastguard Worker     SWITCHONTRACE;
617*495ae853SAndroid Build Coastguard Worker     u1_profile_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
618*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("SPS: profile_idc",u1_profile_idc);
619*495ae853SAndroid Build Coastguard Worker 
620*495ae853SAndroid Build Coastguard Worker     /* G050 */
621*495ae853SAndroid Build Coastguard Worker     uc_constraint_set0_flag = ih264d_get_bit_h264(ps_bitstrm);
622*495ae853SAndroid Build Coastguard Worker     uc_constraint_set1_flag = ih264d_get_bit_h264(ps_bitstrm);
623*495ae853SAndroid Build Coastguard Worker     ih264d_get_bit_h264(ps_bitstrm);
624*495ae853SAndroid Build Coastguard Worker 
625*495ae853SAndroid Build Coastguard Worker     /*****************************************************/
626*495ae853SAndroid Build Coastguard Worker     /* Read 5 bits for uc_constraint_set3_flag (1 bit)   */
627*495ae853SAndroid Build Coastguard Worker     /* and reserved_zero_4bits (4 bits) - Sushant        */
628*495ae853SAndroid Build Coastguard Worker     /*****************************************************/
629*495ae853SAndroid Build Coastguard Worker     ih264d_get_bits_h264(ps_bitstrm, 5);
630*495ae853SAndroid Build Coastguard Worker     /* G050 */
631*495ae853SAndroid Build Coastguard Worker 
632*495ae853SAndroid Build Coastguard Worker     /* Check whether particular profile is suported or not */
633*495ae853SAndroid Build Coastguard Worker     /* Check whether particular profile is suported or not */
634*495ae853SAndroid Build Coastguard Worker     if((u1_profile_idc != MAIN_PROFILE_IDC) &&
635*495ae853SAndroid Build Coastguard Worker 
636*495ae853SAndroid Build Coastguard Worker     (u1_profile_idc != BASE_PROFILE_IDC) &&
637*495ae853SAndroid Build Coastguard Worker 
638*495ae853SAndroid Build Coastguard Worker     (u1_profile_idc != HIGH_PROFILE_IDC)
639*495ae853SAndroid Build Coastguard Worker 
640*495ae853SAndroid Build Coastguard Worker     )
641*495ae853SAndroid Build Coastguard Worker     {
642*495ae853SAndroid Build Coastguard Worker 
643*495ae853SAndroid Build Coastguard Worker         /* Apart from Baseline, main and high profile,
644*495ae853SAndroid Build Coastguard Worker          * only extended profile is supported provided
645*495ae853SAndroid Build Coastguard Worker          * uc_constraint_set0_flag or uc_constraint_set1_flag are set to 1
646*495ae853SAndroid Build Coastguard Worker          */
647*495ae853SAndroid Build Coastguard Worker         if((u1_profile_idc != EXTENDED_PROFILE_IDC) ||
648*495ae853SAndroid Build Coastguard Worker            ((uc_constraint_set1_flag != 1) && (uc_constraint_set0_flag != 1)))
649*495ae853SAndroid Build Coastguard Worker         {
650*495ae853SAndroid Build Coastguard Worker             return (ERROR_FEATURE_UNAVAIL);
651*495ae853SAndroid Build Coastguard Worker         }
652*495ae853SAndroid Build Coastguard Worker     }
653*495ae853SAndroid Build Coastguard Worker 
654*495ae853SAndroid Build Coastguard Worker     u1_level_idc = ih264d_get_bits_h264(ps_bitstrm, 8);
655*495ae853SAndroid Build Coastguard Worker 
656*495ae853SAndroid Build Coastguard Worker 
657*495ae853SAndroid Build Coastguard Worker 
658*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("SPS: u4_level_idc",u1_level_idc);
659*495ae853SAndroid Build Coastguard Worker 
660*495ae853SAndroid Build Coastguard Worker     u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
661*495ae853SAndroid Build Coastguard Worker     if(u4_temp & MASK_ERR_SEQ_SET_ID)
662*495ae853SAndroid Build Coastguard Worker         return ERROR_INV_SPS_PPS_T;
663*495ae853SAndroid Build Coastguard Worker     u1_seq_parameter_set_id = u4_temp;
664*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("SPS: seq_parameter_set_id",
665*495ae853SAndroid Build Coastguard Worker                     u1_seq_parameter_set_id);
666*495ae853SAndroid Build Coastguard Worker 
667*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
668*495ae853SAndroid Build Coastguard Worker     /* Find an seq param entry in seqparam array of decStruct             */
669*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
670*495ae853SAndroid Build Coastguard Worker 
671*495ae853SAndroid Build Coastguard Worker     ps_seq = ps_dec->pv_scratch_sps_pps;
672*495ae853SAndroid Build Coastguard Worker     memset(ps_seq, 0, sizeof(dec_seq_params_t));
673*495ae853SAndroid Build Coastguard Worker 
674*495ae853SAndroid Build Coastguard Worker     if(ps_dec->i4_header_decoded & 1)
675*495ae853SAndroid Build Coastguard Worker     {
676*495ae853SAndroid Build Coastguard Worker         *ps_seq = *ps_dec->ps_cur_sps;
677*495ae853SAndroid Build Coastguard Worker     }
678*495ae853SAndroid Build Coastguard Worker 
679*495ae853SAndroid Build Coastguard Worker 
680*495ae853SAndroid Build Coastguard Worker     if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_profile_idc != u1_profile_idc))
681*495ae853SAndroid Build Coastguard Worker     {
682*495ae853SAndroid Build Coastguard Worker         ps_dec->u1_res_changed = 1;
683*495ae853SAndroid Build Coastguard Worker         return IVD_RES_CHANGED;
684*495ae853SAndroid Build Coastguard Worker     }
685*495ae853SAndroid Build Coastguard Worker 
686*495ae853SAndroid Build Coastguard Worker     if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_level_idc != u1_level_idc))
687*495ae853SAndroid Build Coastguard Worker     {
688*495ae853SAndroid Build Coastguard Worker         ps_dec->u1_res_changed = 1;
689*495ae853SAndroid Build Coastguard Worker         return IVD_RES_CHANGED;
690*495ae853SAndroid Build Coastguard Worker     }
691*495ae853SAndroid Build Coastguard Worker 
692*495ae853SAndroid Build Coastguard Worker     ps_seq->u1_profile_idc = u1_profile_idc;
693*495ae853SAndroid Build Coastguard Worker     ps_seq->u1_level_idc = u1_level_idc;
694*495ae853SAndroid Build Coastguard Worker     ps_seq->u1_seq_parameter_set_id = u1_seq_parameter_set_id;
695*495ae853SAndroid Build Coastguard Worker 
696*495ae853SAndroid Build Coastguard Worker     /*******************************************************************/
697*495ae853SAndroid Build Coastguard Worker     /* Initializations for high profile - Sushant                      */
698*495ae853SAndroid Build Coastguard Worker     /*******************************************************************/
699*495ae853SAndroid Build Coastguard Worker     ps_seq->i4_chroma_format_idc = 1;
700*495ae853SAndroid Build Coastguard Worker     ps_seq->i4_bit_depth_luma_minus8 = 0;
701*495ae853SAndroid Build Coastguard Worker     ps_seq->i4_bit_depth_chroma_minus8 = 0;
702*495ae853SAndroid Build Coastguard Worker     ps_seq->i4_qpprime_y_zero_transform_bypass_flag = 0;
703*495ae853SAndroid Build Coastguard Worker     ps_seq->i4_seq_scaling_matrix_present_flag = 0;
704*495ae853SAndroid Build Coastguard Worker     if(u1_profile_idc == HIGH_PROFILE_IDC)
705*495ae853SAndroid Build Coastguard Worker     {
706*495ae853SAndroid Build Coastguard Worker 
707*495ae853SAndroid Build Coastguard Worker         /* reading chroma_format_idc   */
708*495ae853SAndroid Build Coastguard Worker         ps_seq->i4_chroma_format_idc = ih264d_uev(pu4_bitstrm_ofst,
709*495ae853SAndroid Build Coastguard Worker                                                   pu4_bitstrm_buf);
710*495ae853SAndroid Build Coastguard Worker 
711*495ae853SAndroid Build Coastguard Worker         /* Monochrome is not supported */
712*495ae853SAndroid Build Coastguard Worker         if(ps_seq->i4_chroma_format_idc != 1)
713*495ae853SAndroid Build Coastguard Worker         {
714*495ae853SAndroid Build Coastguard Worker             return ERROR_FEATURE_UNAVAIL;
715*495ae853SAndroid Build Coastguard Worker         }
716*495ae853SAndroid Build Coastguard Worker 
717*495ae853SAndroid Build Coastguard Worker         /* reading bit_depth_luma_minus8   */
718*495ae853SAndroid Build Coastguard Worker         ps_seq->i4_bit_depth_luma_minus8 = ih264d_uev(pu4_bitstrm_ofst,
719*495ae853SAndroid Build Coastguard Worker                                                       pu4_bitstrm_buf);
720*495ae853SAndroid Build Coastguard Worker 
721*495ae853SAndroid Build Coastguard Worker         if(ps_seq->i4_bit_depth_luma_minus8 != 0)
722*495ae853SAndroid Build Coastguard Worker         {
723*495ae853SAndroid Build Coastguard Worker             return ERROR_FEATURE_UNAVAIL;
724*495ae853SAndroid Build Coastguard Worker         }
725*495ae853SAndroid Build Coastguard Worker 
726*495ae853SAndroid Build Coastguard Worker         /* reading bit_depth_chroma_minus8   */
727*495ae853SAndroid Build Coastguard Worker         ps_seq->i4_bit_depth_chroma_minus8 = ih264d_uev(pu4_bitstrm_ofst,
728*495ae853SAndroid Build Coastguard Worker                                                         pu4_bitstrm_buf);
729*495ae853SAndroid Build Coastguard Worker 
730*495ae853SAndroid Build Coastguard Worker         if(ps_seq->i4_bit_depth_chroma_minus8 != 0)
731*495ae853SAndroid Build Coastguard Worker         {
732*495ae853SAndroid Build Coastguard Worker             return ERROR_FEATURE_UNAVAIL;
733*495ae853SAndroid Build Coastguard Worker         }
734*495ae853SAndroid Build Coastguard Worker 
735*495ae853SAndroid Build Coastguard Worker         /* reading qpprime_y_zero_transform_bypass_flag   */
736*495ae853SAndroid Build Coastguard Worker         ps_seq->i4_qpprime_y_zero_transform_bypass_flag =
737*495ae853SAndroid Build Coastguard Worker                         (WORD32)ih264d_get_bit_h264(ps_bitstrm);
738*495ae853SAndroid Build Coastguard Worker 
739*495ae853SAndroid Build Coastguard Worker         if(ps_seq->i4_qpprime_y_zero_transform_bypass_flag != 0)
740*495ae853SAndroid Build Coastguard Worker         {
741*495ae853SAndroid Build Coastguard Worker             return ERROR_INV_SPS_PPS_T;
742*495ae853SAndroid Build Coastguard Worker         }
743*495ae853SAndroid Build Coastguard Worker 
744*495ae853SAndroid Build Coastguard Worker         /* reading seq_scaling_matrix_present_flag   */
745*495ae853SAndroid Build Coastguard Worker         ps_seq->i4_seq_scaling_matrix_present_flag =
746*495ae853SAndroid Build Coastguard Worker                         (WORD32)ih264d_get_bit_h264(ps_bitstrm);
747*495ae853SAndroid Build Coastguard Worker 
748*495ae853SAndroid Build Coastguard Worker         if(ps_seq->i4_seq_scaling_matrix_present_flag)
749*495ae853SAndroid Build Coastguard Worker         {
750*495ae853SAndroid Build Coastguard Worker             for(i4_i = 0; i4_i < 8; i4_i++)
751*495ae853SAndroid Build Coastguard Worker             {
752*495ae853SAndroid Build Coastguard Worker                 ps_seq->u1_seq_scaling_list_present_flag[i4_i] =
753*495ae853SAndroid Build Coastguard Worker                                 ih264d_get_bit_h264(ps_bitstrm);
754*495ae853SAndroid Build Coastguard Worker 
755*495ae853SAndroid Build Coastguard Worker                 /* initialize u1_use_default_scaling_matrix_flag[i4_i] to zero */
756*495ae853SAndroid Build Coastguard Worker                 /* before calling scaling list                             */
757*495ae853SAndroid Build Coastguard Worker                 ps_seq->u1_use_default_scaling_matrix_flag[i4_i] = 0;
758*495ae853SAndroid Build Coastguard Worker 
759*495ae853SAndroid Build Coastguard Worker                 if(ps_seq->u1_seq_scaling_list_present_flag[i4_i])
760*495ae853SAndroid Build Coastguard Worker                 {
761*495ae853SAndroid Build Coastguard Worker                     if(i4_i < 6)
762*495ae853SAndroid Build Coastguard Worker                     {
763*495ae853SAndroid Build Coastguard Worker                         ret = ih264d_scaling_list(
764*495ae853SAndroid Build Coastguard Worker                                         ps_seq->i2_scalinglist4x4[i4_i],
765*495ae853SAndroid Build Coastguard Worker                                         16,
766*495ae853SAndroid Build Coastguard Worker                                         &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
767*495ae853SAndroid Build Coastguard Worker                                         ps_bitstrm);
768*495ae853SAndroid Build Coastguard Worker                     }
769*495ae853SAndroid Build Coastguard Worker                     else
770*495ae853SAndroid Build Coastguard Worker                     {
771*495ae853SAndroid Build Coastguard Worker                         ret = ih264d_scaling_list(
772*495ae853SAndroid Build Coastguard Worker                                         ps_seq->i2_scalinglist8x8[i4_i - 6],
773*495ae853SAndroid Build Coastguard Worker                                         64,
774*495ae853SAndroid Build Coastguard Worker                                         &ps_seq->u1_use_default_scaling_matrix_flag[i4_i],
775*495ae853SAndroid Build Coastguard Worker                                         ps_bitstrm);
776*495ae853SAndroid Build Coastguard Worker                     }
777*495ae853SAndroid Build Coastguard Worker                     if(ret != OK)
778*495ae853SAndroid Build Coastguard Worker                     {
779*495ae853SAndroid Build Coastguard Worker                         return ret;
780*495ae853SAndroid Build Coastguard Worker                     }
781*495ae853SAndroid Build Coastguard Worker                 }
782*495ae853SAndroid Build Coastguard Worker             }
783*495ae853SAndroid Build Coastguard Worker         }
784*495ae853SAndroid Build Coastguard Worker     }
785*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
786*495ae853SAndroid Build Coastguard Worker     /* Decode MaxFrameNum                                                 */
787*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
788*495ae853SAndroid Build Coastguard Worker     u8_temp = (UWORD64)4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
789*495ae853SAndroid Build Coastguard Worker     if(u8_temp > MAX_BITS_IN_FRAME_NUM)
790*495ae853SAndroid Build Coastguard Worker     {
791*495ae853SAndroid Build Coastguard Worker         return ERROR_INV_SPS_PPS_T;
792*495ae853SAndroid Build Coastguard Worker     }
793*495ae853SAndroid Build Coastguard Worker     ps_seq->u1_bits_in_frm_num = u8_temp;
794*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("SPS: log2_max_frame_num_minus4",
795*495ae853SAndroid Build Coastguard Worker                     (ps_seq->u1_bits_in_frm_num - 4));
796*495ae853SAndroid Build Coastguard Worker 
797*495ae853SAndroid Build Coastguard Worker     u4_max_frm_num = (1 << (ps_seq->u1_bits_in_frm_num));
798*495ae853SAndroid Build Coastguard Worker     ps_seq->u2_u4_max_pic_num_minus1 = u4_max_frm_num - 1;
799*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
800*495ae853SAndroid Build Coastguard Worker     /* Decode picture order count and related values                      */
801*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
802*495ae853SAndroid Build Coastguard Worker     u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
803*495ae853SAndroid Build Coastguard Worker 
804*495ae853SAndroid Build Coastguard Worker     if(u4_temp > MAX_PIC_ORDER_CNT_TYPE)
805*495ae853SAndroid Build Coastguard Worker     {
806*495ae853SAndroid Build Coastguard Worker         return ERROR_INV_POC_TYPE_T;
807*495ae853SAndroid Build Coastguard Worker     }
808*495ae853SAndroid Build Coastguard Worker     ps_seq->u1_pic_order_cnt_type = u4_temp;
809*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("SPS: pic_order_cnt_type",ps_seq->u1_pic_order_cnt_type);
810*495ae853SAndroid Build Coastguard Worker 
811*495ae853SAndroid Build Coastguard Worker     ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = 1;
812*495ae853SAndroid Build Coastguard Worker     if(ps_seq->u1_pic_order_cnt_type == 0)
813*495ae853SAndroid Build Coastguard Worker     {
814*495ae853SAndroid Build Coastguard Worker         u8_temp = (UWORD64)4 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
815*495ae853SAndroid Build Coastguard Worker         if(u8_temp > MAX_BITS_IN_POC_LSB)
816*495ae853SAndroid Build Coastguard Worker         {
817*495ae853SAndroid Build Coastguard Worker             return ERROR_INV_SPS_PPS_T;
818*495ae853SAndroid Build Coastguard Worker         }
819*495ae853SAndroid Build Coastguard Worker         ps_seq->u1_log2_max_pic_order_cnt_lsb_minus = u8_temp;
820*495ae853SAndroid Build Coastguard Worker         ps_seq->i4_max_pic_order_cntLsb = (1 << u8_temp);
821*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("SPS: log2_max_pic_order_cnt_lsb_minus4",(u8_temp - 4));
822*495ae853SAndroid Build Coastguard Worker     }
823*495ae853SAndroid Build Coastguard Worker     else if(ps_seq->u1_pic_order_cnt_type == 1)
824*495ae853SAndroid Build Coastguard Worker     {
825*495ae853SAndroid Build Coastguard Worker         ps_seq->u1_delta_pic_order_always_zero_flag = ih264d_get_bit_h264(
826*495ae853SAndroid Build Coastguard Worker                         ps_bitstrm);
827*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("SPS: delta_pic_order_always_zero_flag",
828*495ae853SAndroid Build Coastguard Worker                         ps_seq->u1_delta_pic_order_always_zero_flag);
829*495ae853SAndroid Build Coastguard Worker 
830*495ae853SAndroid Build Coastguard Worker         ps_seq->i4_ofst_for_non_ref_pic = ih264d_sev(pu4_bitstrm_ofst,
831*495ae853SAndroid Build Coastguard Worker                                                      pu4_bitstrm_buf);
832*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("SPS: offset_for_non_ref_pic",
833*495ae853SAndroid Build Coastguard Worker                         ps_seq->i4_ofst_for_non_ref_pic);
834*495ae853SAndroid Build Coastguard Worker 
835*495ae853SAndroid Build Coastguard Worker         ps_seq->i4_ofst_for_top_to_bottom_field = ih264d_sev(
836*495ae853SAndroid Build Coastguard Worker                         pu4_bitstrm_ofst, pu4_bitstrm_buf);
837*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("SPS: offset_for_top_to_bottom_field",
838*495ae853SAndroid Build Coastguard Worker                         ps_seq->i4_ofst_for_top_to_bottom_field);
839*495ae853SAndroid Build Coastguard Worker 
840*495ae853SAndroid Build Coastguard Worker         u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
841*495ae853SAndroid Build Coastguard Worker         if(u4_temp > 255)
842*495ae853SAndroid Build Coastguard Worker             return ERROR_INV_SPS_PPS_T;
843*495ae853SAndroid Build Coastguard Worker         ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle = u4_temp;
844*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("SPS: num_ref_frames_in_pic_order_cnt_cycle",
845*495ae853SAndroid Build Coastguard Worker                         ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle);
846*495ae853SAndroid Build Coastguard Worker 
847*495ae853SAndroid Build Coastguard Worker         for(i = 0; i < ps_seq->u1_num_ref_frames_in_pic_order_cnt_cycle; i++)
848*495ae853SAndroid Build Coastguard Worker         {
849*495ae853SAndroid Build Coastguard Worker             ps_seq->i4_ofst_for_ref_frame[i] = ih264d_sev(
850*495ae853SAndroid Build Coastguard Worker                             pu4_bitstrm_ofst, pu4_bitstrm_buf);
851*495ae853SAndroid Build Coastguard Worker             COPYTHECONTEXT("SPS: offset_for_ref_frame",
852*495ae853SAndroid Build Coastguard Worker                             ps_seq->i4_ofst_for_ref_frame[i]);
853*495ae853SAndroid Build Coastguard Worker         }
854*495ae853SAndroid Build Coastguard Worker     }
855*495ae853SAndroid Build Coastguard Worker 
856*495ae853SAndroid Build Coastguard Worker     u4_temp = ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
857*495ae853SAndroid Build Coastguard Worker 
858*495ae853SAndroid Build Coastguard Worker     if((u4_temp > H264_MAX_REF_PICS))
859*495ae853SAndroid Build Coastguard Worker     {
860*495ae853SAndroid Build Coastguard Worker         return ERROR_NUM_REF;
861*495ae853SAndroid Build Coastguard Worker     }
862*495ae853SAndroid Build Coastguard Worker 
863*495ae853SAndroid Build Coastguard Worker     /* Compare with older num_ref_frames is header is already once */
864*495ae853SAndroid Build Coastguard Worker     if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_num_ref_frames != u4_temp))
865*495ae853SAndroid Build Coastguard Worker     {
866*495ae853SAndroid Build Coastguard Worker         ps_dec->u1_res_changed = 1;
867*495ae853SAndroid Build Coastguard Worker         return IVD_RES_CHANGED;
868*495ae853SAndroid Build Coastguard Worker     }
869*495ae853SAndroid Build Coastguard Worker 
870*495ae853SAndroid Build Coastguard Worker     ps_seq->u1_num_ref_frames = u4_temp;
871*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("SPS: num_ref_frames",ps_seq->u1_num_ref_frames);
872*495ae853SAndroid Build Coastguard Worker 
873*495ae853SAndroid Build Coastguard Worker     ps_seq->u1_gaps_in_frame_num_value_allowed_flag = ih264d_get_bit_h264(
874*495ae853SAndroid Build Coastguard Worker                     ps_bitstrm);
875*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("SPS: gaps_in_frame_num_value_allowed_flag",
876*495ae853SAndroid Build Coastguard Worker                     ps_seq->u1_gaps_in_frame_num_value_allowed_flag);
877*495ae853SAndroid Build Coastguard Worker 
878*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
879*495ae853SAndroid Build Coastguard Worker     /* Decode FrameWidth and FrameHeight and related values               */
880*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
881*495ae853SAndroid Build Coastguard Worker     u8_temp = (UWORD64)1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
882*495ae853SAndroid Build Coastguard Worker     /* Check  for unsupported resolutions*/
883*495ae853SAndroid Build Coastguard Worker     if(u8_temp > (H264_MAX_FRAME_WIDTH >> 4))
884*495ae853SAndroid Build Coastguard Worker     {
885*495ae853SAndroid Build Coastguard Worker         return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
886*495ae853SAndroid Build Coastguard Worker     }
887*495ae853SAndroid Build Coastguard Worker     u4_pic_width_in_mbs = u8_temp;
888*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("SPS: pic_width_in_mbs_minus1",
889*495ae853SAndroid Build Coastguard Worker                    u4_pic_width_in_mbs - 1);
890*495ae853SAndroid Build Coastguard Worker 
891*495ae853SAndroid Build Coastguard Worker     u8_temp = (UWORD64)1 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
892*495ae853SAndroid Build Coastguard Worker     if (u8_temp > (H264_MAX_FRAME_HEIGHT >> 4))
893*495ae853SAndroid Build Coastguard Worker     {
894*495ae853SAndroid Build Coastguard Worker         return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
895*495ae853SAndroid Build Coastguard Worker     }
896*495ae853SAndroid Build Coastguard Worker     u4_pic_height_in_map_units = u8_temp;
897*495ae853SAndroid Build Coastguard Worker 
898*495ae853SAndroid Build Coastguard Worker     ps_seq->u2_frm_wd_in_mbs = u4_pic_width_in_mbs;
899*495ae853SAndroid Build Coastguard Worker     ps_seq->u2_frm_ht_in_mbs = u4_pic_height_in_map_units;
900*495ae853SAndroid Build Coastguard Worker 
901*495ae853SAndroid Build Coastguard Worker     u2_pic_wd = (u4_pic_width_in_mbs << 4);
902*495ae853SAndroid Build Coastguard Worker     u2_pic_ht = (u4_pic_height_in_map_units << 4);
903*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
904*495ae853SAndroid Build Coastguard Worker     /* Get the value of MaxMbAddress and Number of bits needed for it     */
905*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
906*495ae853SAndroid Build Coastguard Worker     ps_seq->u2_max_mb_addr = (ps_seq->u2_frm_wd_in_mbs
907*495ae853SAndroid Build Coastguard Worker                     * ps_seq->u2_frm_ht_in_mbs) - 1;
908*495ae853SAndroid Build Coastguard Worker 
909*495ae853SAndroid Build Coastguard Worker     ps_seq->u2_total_num_of_mbs = ps_seq->u2_max_mb_addr + 1;
910*495ae853SAndroid Build Coastguard Worker 
911*495ae853SAndroid Build Coastguard Worker     ps_seq->u1_level_idc = ih264d_correct_level_idc(
912*495ae853SAndroid Build Coastguard Worker                     u1_level_idc, ps_seq->u2_total_num_of_mbs);
913*495ae853SAndroid Build Coastguard Worker 
914*495ae853SAndroid Build Coastguard Worker     u1_frm = ih264d_get_bit_h264(ps_bitstrm);
915*495ae853SAndroid Build Coastguard Worker     if((ps_dec->i4_header_decoded & 1) && (ps_seq->u1_frame_mbs_only_flag != u1_frm))
916*495ae853SAndroid Build Coastguard Worker     {
917*495ae853SAndroid Build Coastguard Worker         ps_dec->u1_res_changed = 1;
918*495ae853SAndroid Build Coastguard Worker         return IVD_RES_CHANGED;
919*495ae853SAndroid Build Coastguard Worker     }
920*495ae853SAndroid Build Coastguard Worker 
921*495ae853SAndroid Build Coastguard Worker     ps_seq->u1_frame_mbs_only_flag = u1_frm;
922*495ae853SAndroid Build Coastguard Worker 
923*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("SPS: frame_mbs_only_flag", u1_frm);
924*495ae853SAndroid Build Coastguard Worker 
925*495ae853SAndroid Build Coastguard Worker     if(!u1_frm)
926*495ae853SAndroid Build Coastguard Worker         u1_mb_aff_flag = ih264d_get_bit_h264(ps_bitstrm);
927*495ae853SAndroid Build Coastguard Worker 
928*495ae853SAndroid Build Coastguard Worker     if((ps_dec->i4_header_decoded & 1)
929*495ae853SAndroid Build Coastguard Worker                     && (ps_seq->u1_mb_aff_flag != u1_mb_aff_flag))
930*495ae853SAndroid Build Coastguard Worker     {
931*495ae853SAndroid Build Coastguard Worker         ps_dec->u1_res_changed = 1;
932*495ae853SAndroid Build Coastguard Worker         return IVD_RES_CHANGED;
933*495ae853SAndroid Build Coastguard Worker     }
934*495ae853SAndroid Build Coastguard Worker 
935*495ae853SAndroid Build Coastguard Worker     if(!u1_frm)
936*495ae853SAndroid Build Coastguard Worker     {
937*495ae853SAndroid Build Coastguard Worker         u2_pic_ht <<= 1;
938*495ae853SAndroid Build Coastguard Worker         ps_seq->u1_mb_aff_flag = u1_mb_aff_flag;
939*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("SPS: mb_adaptive_frame_field_flag",
940*495ae853SAndroid Build Coastguard Worker                         ps_seq->u1_mb_aff_flag);
941*495ae853SAndroid Build Coastguard Worker 
942*495ae853SAndroid Build Coastguard Worker     }
943*495ae853SAndroid Build Coastguard Worker     else
944*495ae853SAndroid Build Coastguard Worker         ps_seq->u1_mb_aff_flag = 0;
945*495ae853SAndroid Build Coastguard Worker 
946*495ae853SAndroid Build Coastguard Worker     ps_seq->u1_direct_8x8_inference_flag = ih264d_get_bit_h264(ps_bitstrm);
947*495ae853SAndroid Build Coastguard Worker 
948*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("SPS: direct_8x8_inference_flag",
949*495ae853SAndroid Build Coastguard Worker                     ps_seq->u1_direct_8x8_inference_flag);
950*495ae853SAndroid Build Coastguard Worker 
951*495ae853SAndroid Build Coastguard Worker     /* G050 */
952*495ae853SAndroid Build Coastguard Worker     u1_frame_cropping_flag = ih264d_get_bit_h264(ps_bitstrm);
953*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("SPS: frame_cropping_flag",u1_frame_cropping_flag);
954*495ae853SAndroid Build Coastguard Worker 
955*495ae853SAndroid Build Coastguard Worker     if(u1_frame_cropping_flag)
956*495ae853SAndroid Build Coastguard Worker     {
957*495ae853SAndroid Build Coastguard Worker         u1_frame_cropping_rect_left_ofst = ih264d_uev(pu4_bitstrm_ofst,
958*495ae853SAndroid Build Coastguard Worker                                                       pu4_bitstrm_buf);
959*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("SPS: frame_cropping_rect_left_offset",
960*495ae853SAndroid Build Coastguard Worker                         u1_frame_cropping_rect_left_ofst);
961*495ae853SAndroid Build Coastguard Worker         u1_frame_cropping_rect_right_ofst = ih264d_uev(pu4_bitstrm_ofst,
962*495ae853SAndroid Build Coastguard Worker                                                        pu4_bitstrm_buf);
963*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("SPS: frame_cropping_rect_right_offset",
964*495ae853SAndroid Build Coastguard Worker                         u1_frame_cropping_rect_right_ofst);
965*495ae853SAndroid Build Coastguard Worker         u1_frame_cropping_rect_top_ofst = ih264d_uev(pu4_bitstrm_ofst,
966*495ae853SAndroid Build Coastguard Worker                                                      pu4_bitstrm_buf);
967*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("SPS: frame_cropping_rect_top_offset",
968*495ae853SAndroid Build Coastguard Worker                         u1_frame_cropping_rect_top_ofst);
969*495ae853SAndroid Build Coastguard Worker         u1_frame_cropping_rect_bottom_ofst = ih264d_uev(pu4_bitstrm_ofst,
970*495ae853SAndroid Build Coastguard Worker                                                         pu4_bitstrm_buf);
971*495ae853SAndroid Build Coastguard Worker         COPYTHECONTEXT("SPS: frame_cropping_rect_bottom_offset",
972*495ae853SAndroid Build Coastguard Worker                         u1_frame_cropping_rect_bottom_ofst);
973*495ae853SAndroid Build Coastguard Worker     }
974*495ae853SAndroid Build Coastguard Worker     /* G050 */
975*495ae853SAndroid Build Coastguard Worker 
976*495ae853SAndroid Build Coastguard Worker     ps_seq->u1_vui_parameters_present_flag = ih264d_get_bit_h264(ps_bitstrm);
977*495ae853SAndroid Build Coastguard Worker     COPYTHECONTEXT("SPS: vui_parameters_present_flag",
978*495ae853SAndroid Build Coastguard Worker                     ps_seq->u1_vui_parameters_present_flag);
979*495ae853SAndroid Build Coastguard Worker 
980*495ae853SAndroid Build Coastguard Worker     u2_frm_wd_y = u2_pic_wd + (UWORD8)(PAD_LEN_Y_H << 1);
981*495ae853SAndroid Build Coastguard Worker     if(1 == ps_dec->u4_share_disp_buf)
982*495ae853SAndroid Build Coastguard Worker     {
983*495ae853SAndroid Build Coastguard Worker         if(ps_dec->u4_app_disp_width > u2_frm_wd_y)
984*495ae853SAndroid Build Coastguard Worker             u2_frm_wd_y = ps_dec->u4_app_disp_width;
985*495ae853SAndroid Build Coastguard Worker     }
986*495ae853SAndroid Build Coastguard Worker 
987*495ae853SAndroid Build Coastguard Worker     u2_frm_ht_y = u2_pic_ht + (UWORD8)(PAD_LEN_Y_V << 2);
988*495ae853SAndroid Build Coastguard Worker     u2_frm_wd_uv = u2_pic_wd + (UWORD8)(PAD_LEN_UV_H << 2);
989*495ae853SAndroid Build Coastguard Worker     u2_frm_wd_uv = MAX(u2_frm_wd_uv, u2_frm_wd_y);
990*495ae853SAndroid Build Coastguard Worker 
991*495ae853SAndroid Build Coastguard Worker     u2_frm_ht_uv = (u2_pic_ht >> 1) + (UWORD8)(PAD_LEN_UV_V << 2);
992*495ae853SAndroid Build Coastguard Worker     u2_frm_ht_uv = MAX(u2_frm_ht_uv, (u2_frm_ht_y >> 1));
993*495ae853SAndroid Build Coastguard Worker 
994*495ae853SAndroid Build Coastguard Worker 
995*495ae853SAndroid Build Coastguard Worker     /* Calculate display picture width, height and start u4_ofst from YUV420 */
996*495ae853SAndroid Build Coastguard Worker     /* pictute buffers as per cropping information parsed above             */
997*495ae853SAndroid Build Coastguard Worker     {
998*495ae853SAndroid Build Coastguard Worker         UWORD16 u2_rgt_ofst = 0;
999*495ae853SAndroid Build Coastguard Worker         UWORD16 u2_lft_ofst = 0;
1000*495ae853SAndroid Build Coastguard Worker         UWORD16 u2_top_ofst = 0;
1001*495ae853SAndroid Build Coastguard Worker         UWORD16 u2_btm_ofst = 0;
1002*495ae853SAndroid Build Coastguard Worker         UWORD8 u1_frm_mbs_flag;
1003*495ae853SAndroid Build Coastguard Worker         UWORD8 u1_vert_mult_factor;
1004*495ae853SAndroid Build Coastguard Worker 
1005*495ae853SAndroid Build Coastguard Worker         if(u1_frame_cropping_flag)
1006*495ae853SAndroid Build Coastguard Worker         {
1007*495ae853SAndroid Build Coastguard Worker             /* Calculate right and left u4_ofst for cropped picture           */
1008*495ae853SAndroid Build Coastguard Worker             u2_rgt_ofst = u1_frame_cropping_rect_right_ofst << 1;
1009*495ae853SAndroid Build Coastguard Worker             u2_lft_ofst = u1_frame_cropping_rect_left_ofst << 1;
1010*495ae853SAndroid Build Coastguard Worker 
1011*495ae853SAndroid Build Coastguard Worker             /* Know frame MBs only u4_flag                                      */
1012*495ae853SAndroid Build Coastguard Worker             u1_frm_mbs_flag = (1 == ps_seq->u1_frame_mbs_only_flag);
1013*495ae853SAndroid Build Coastguard Worker 
1014*495ae853SAndroid Build Coastguard Worker             /* Simplify the vertical u4_ofst calculation from field/frame     */
1015*495ae853SAndroid Build Coastguard Worker             u1_vert_mult_factor = (2 - u1_frm_mbs_flag);
1016*495ae853SAndroid Build Coastguard Worker 
1017*495ae853SAndroid Build Coastguard Worker             /* Calculate bottom and top u4_ofst for cropped  picture          */
1018*495ae853SAndroid Build Coastguard Worker             u2_btm_ofst = (u1_frame_cropping_rect_bottom_ofst
1019*495ae853SAndroid Build Coastguard Worker                             << u1_vert_mult_factor);
1020*495ae853SAndroid Build Coastguard Worker             u2_top_ofst = (u1_frame_cropping_rect_top_ofst
1021*495ae853SAndroid Build Coastguard Worker                             << u1_vert_mult_factor);
1022*495ae853SAndroid Build Coastguard Worker         }
1023*495ae853SAndroid Build Coastguard Worker 
1024*495ae853SAndroid Build Coastguard Worker         /* Calculate u4_ofst from start of YUV 420 picture buffer to start of*/
1025*495ae853SAndroid Build Coastguard Worker         /* cropped picture buffer                                           */
1026*495ae853SAndroid Build Coastguard Worker         u2_crop_offset_y = (u2_frm_wd_y * u2_top_ofst) + (u2_lft_ofst);
1027*495ae853SAndroid Build Coastguard Worker         u2_crop_offset_uv = (u2_frm_wd_uv * (u2_top_ofst >> 1))
1028*495ae853SAndroid Build Coastguard Worker                         + (u2_lft_ofst >> 1) * YUV420SP_FACTOR;
1029*495ae853SAndroid Build Coastguard Worker         /* Calculate the display picture width and height based on crop      */
1030*495ae853SAndroid Build Coastguard Worker         /* information                                                       */
1031*495ae853SAndroid Build Coastguard Worker         i4_cropped_ht = (WORD32)u2_pic_ht - (WORD32)(u2_btm_ofst + u2_top_ofst);
1032*495ae853SAndroid Build Coastguard Worker         i4_cropped_wd = (WORD32)u2_pic_wd - (WORD32)(u2_rgt_ofst + u2_lft_ofst);
1033*495ae853SAndroid Build Coastguard Worker 
1034*495ae853SAndroid Build Coastguard Worker         if((i4_cropped_ht < MB_SIZE) || (i4_cropped_wd < MB_SIZE))
1035*495ae853SAndroid Build Coastguard Worker         {
1036*495ae853SAndroid Build Coastguard Worker             return ERROR_INV_SPS_PPS_T;
1037*495ae853SAndroid Build Coastguard Worker         }
1038*495ae853SAndroid Build Coastguard Worker 
1039*495ae853SAndroid Build Coastguard Worker         if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_pic_wd != u2_pic_wd))
1040*495ae853SAndroid Build Coastguard Worker         {
1041*495ae853SAndroid Build Coastguard Worker             ps_dec->u1_res_changed = 1;
1042*495ae853SAndroid Build Coastguard Worker             return IVD_RES_CHANGED;
1043*495ae853SAndroid Build Coastguard Worker         }
1044*495ae853SAndroid Build Coastguard Worker 
1045*495ae853SAndroid Build Coastguard Worker         if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_disp_width != i4_cropped_wd))
1046*495ae853SAndroid Build Coastguard Worker         {
1047*495ae853SAndroid Build Coastguard Worker             ps_dec->u1_res_changed = 1;
1048*495ae853SAndroid Build Coastguard Worker             return IVD_RES_CHANGED;
1049*495ae853SAndroid Build Coastguard Worker         }
1050*495ae853SAndroid Build Coastguard Worker 
1051*495ae853SAndroid Build Coastguard Worker         if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_pic_ht != u2_pic_ht))
1052*495ae853SAndroid Build Coastguard Worker         {
1053*495ae853SAndroid Build Coastguard Worker             ps_dec->u1_res_changed = 1;
1054*495ae853SAndroid Build Coastguard Worker             return IVD_RES_CHANGED;
1055*495ae853SAndroid Build Coastguard Worker         }
1056*495ae853SAndroid Build Coastguard Worker 
1057*495ae853SAndroid Build Coastguard Worker         if((ps_dec->i4_header_decoded & 1) && (ps_dec->u2_disp_height != i4_cropped_ht))
1058*495ae853SAndroid Build Coastguard Worker         {
1059*495ae853SAndroid Build Coastguard Worker             ps_dec->u1_res_changed = 1;
1060*495ae853SAndroid Build Coastguard Worker             return IVD_RES_CHANGED;
1061*495ae853SAndroid Build Coastguard Worker         }
1062*495ae853SAndroid Build Coastguard Worker 
1063*495ae853SAndroid Build Coastguard Worker         /* Check again for unsupported resolutions with updated values*/
1064*495ae853SAndroid Build Coastguard Worker         if((u2_pic_wd > H264_MAX_FRAME_WIDTH) || (u2_pic_ht > H264_MAX_FRAME_HEIGHT)
1065*495ae853SAndroid Build Coastguard Worker                 || (u2_pic_wd < H264_MIN_FRAME_WIDTH) || (u2_pic_ht < H264_MIN_FRAME_HEIGHT)
1066*495ae853SAndroid Build Coastguard Worker                 || (u2_pic_wd * (UWORD32)u2_pic_ht > H264_MAX_FRAME_SIZE))
1067*495ae853SAndroid Build Coastguard Worker         {
1068*495ae853SAndroid Build Coastguard Worker             return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1069*495ae853SAndroid Build Coastguard Worker         }
1070*495ae853SAndroid Build Coastguard Worker 
1071*495ae853SAndroid Build Coastguard Worker         /* If MBAff is enabled, decoder support is limited to streams with
1072*495ae853SAndroid Build Coastguard Worker          * width less than half of H264_MAX_FRAME_WIDTH.
1073*495ae853SAndroid Build Coastguard Worker          * In case of MBAff decoder processes two rows at a time
1074*495ae853SAndroid Build Coastguard Worker          */
1075*495ae853SAndroid Build Coastguard Worker         if((u2_pic_wd << ps_seq->u1_mb_aff_flag) > H264_MAX_FRAME_WIDTH)
1076*495ae853SAndroid Build Coastguard Worker         {
1077*495ae853SAndroid Build Coastguard Worker             return IVD_STREAM_WIDTH_HEIGHT_NOT_SUPPORTED;
1078*495ae853SAndroid Build Coastguard Worker         }
1079*495ae853SAndroid Build Coastguard Worker 
1080*495ae853SAndroid Build Coastguard Worker     }
1081*495ae853SAndroid Build Coastguard Worker 
1082*495ae853SAndroid Build Coastguard Worker     /* Backup num_reorder_frames if header is already decoded */
1083*495ae853SAndroid Build Coastguard Worker     if((ps_dec->i4_header_decoded & 1) &&
1084*495ae853SAndroid Build Coastguard Worker                     (1 == ps_seq->u1_vui_parameters_present_flag) &&
1085*495ae853SAndroid Build Coastguard Worker                     (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
1086*495ae853SAndroid Build Coastguard Worker     {
1087*495ae853SAndroid Build Coastguard Worker         num_reorder_frames =  (WORD32)ps_seq->s_vui.u4_num_reorder_frames;
1088*495ae853SAndroid Build Coastguard Worker     }
1089*495ae853SAndroid Build Coastguard Worker     else
1090*495ae853SAndroid Build Coastguard Worker     {
1091*495ae853SAndroid Build Coastguard Worker         num_reorder_frames = -1;
1092*495ae853SAndroid Build Coastguard Worker     }
1093*495ae853SAndroid Build Coastguard Worker     if(1 == ps_seq->u1_vui_parameters_present_flag)
1094*495ae853SAndroid Build Coastguard Worker     {
1095*495ae853SAndroid Build Coastguard Worker         ret = ih264d_parse_vui_parametres(&ps_seq->s_vui, ps_bitstrm);
1096*495ae853SAndroid Build Coastguard Worker         if(ret != OK)
1097*495ae853SAndroid Build Coastguard Worker             return ret;
1098*495ae853SAndroid Build Coastguard Worker 
1099*495ae853SAndroid Build Coastguard Worker         if (ps_dec->pu1_bits_buf_dynamic != NULL) {
1100*495ae853SAndroid Build Coastguard Worker             vui_t *ps_vui = &ps_seq->s_vui;
1101*495ae853SAndroid Build Coastguard Worker             dec_seq_params_t *ps_sps_old = ps_dec->ps_sps;
1102*495ae853SAndroid Build Coastguard Worker             vui_t *ps_vui_old = &ps_sps_old->s_vui;
1103*495ae853SAndroid Build Coastguard Worker 
1104*495ae853SAndroid Build Coastguard Worker             if (ps_vui->u1_video_full_range_flag != ps_vui_old->u1_video_full_range_flag ||
1105*495ae853SAndroid Build Coastguard Worker                 ps_vui->u1_colour_primaries != ps_vui_old->u1_colour_primaries ||
1106*495ae853SAndroid Build Coastguard Worker                 ps_vui->u1_tfr_chars != ps_vui_old->u1_tfr_chars ||
1107*495ae853SAndroid Build Coastguard Worker                 ps_vui->u1_matrix_coeffs != ps_vui_old->u1_matrix_coeffs) {
1108*495ae853SAndroid Build Coastguard Worker                 ps_dec->u1_res_changed = 1;
1109*495ae853SAndroid Build Coastguard Worker                 return IVD_RES_CHANGED;
1110*495ae853SAndroid Build Coastguard Worker             }
1111*495ae853SAndroid Build Coastguard Worker         }
1112*495ae853SAndroid Build Coastguard Worker     }
1113*495ae853SAndroid Build Coastguard Worker 
1114*495ae853SAndroid Build Coastguard Worker     /* Compare older num_reorder_frames with the new one if header is already decoded */
1115*495ae853SAndroid Build Coastguard Worker     if((ps_dec->i4_header_decoded & 1) &&
1116*495ae853SAndroid Build Coastguard Worker                     (-1 != num_reorder_frames) &&
1117*495ae853SAndroid Build Coastguard Worker                     (1 == ps_seq->u1_vui_parameters_present_flag) &&
1118*495ae853SAndroid Build Coastguard Worker                     (1 == ps_seq->s_vui.u1_bitstream_restriction_flag) &&
1119*495ae853SAndroid Build Coastguard Worker                     ((WORD32)ps_seq->s_vui.u4_num_reorder_frames != num_reorder_frames))
1120*495ae853SAndroid Build Coastguard Worker     {
1121*495ae853SAndroid Build Coastguard Worker         ps_dec->u1_res_changed = 1;
1122*495ae853SAndroid Build Coastguard Worker         return IVD_RES_CHANGED;
1123*495ae853SAndroid Build Coastguard Worker     }
1124*495ae853SAndroid Build Coastguard Worker 
1125*495ae853SAndroid Build Coastguard Worker     /* In case bitstream read has exceeded the filled size, then
1126*495ae853SAndroid Build Coastguard Worker      return an error */
1127*495ae853SAndroid Build Coastguard Worker     if (EXCEED_OFFSET(ps_bitstrm))
1128*495ae853SAndroid Build Coastguard Worker     {
1129*495ae853SAndroid Build Coastguard Worker         return ERROR_INV_SPS_PPS_T;
1130*495ae853SAndroid Build Coastguard Worker     }
1131*495ae853SAndroid Build Coastguard Worker 
1132*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
1133*495ae853SAndroid Build Coastguard Worker     /* All initializations to ps_dec are beyond this point                */
1134*495ae853SAndroid Build Coastguard Worker     /*--------------------------------------------------------------------*/
1135*495ae853SAndroid Build Coastguard Worker     {
1136*495ae853SAndroid Build Coastguard Worker         WORD32 reorder_depth = ih264d_get_dpb_size(ps_seq);
1137*495ae853SAndroid Build Coastguard Worker         if((1 == ps_seq->u1_vui_parameters_present_flag) &&
1138*495ae853SAndroid Build Coastguard Worker            (1 == ps_seq->s_vui.u1_bitstream_restriction_flag))
1139*495ae853SAndroid Build Coastguard Worker         {
1140*495ae853SAndroid Build Coastguard Worker             reorder_depth = ps_seq->s_vui.u4_num_reorder_frames + 1;
1141*495ae853SAndroid Build Coastguard Worker         }
1142*495ae853SAndroid Build Coastguard Worker 
1143*495ae853SAndroid Build Coastguard Worker         if (reorder_depth > H264_MAX_REF_PICS)
1144*495ae853SAndroid Build Coastguard Worker         {
1145*495ae853SAndroid Build Coastguard Worker             return ERROR_INV_SPS_PPS_T;
1146*495ae853SAndroid Build Coastguard Worker         }
1147*495ae853SAndroid Build Coastguard Worker 
1148*495ae853SAndroid Build Coastguard Worker         if(ps_seq->u1_frame_mbs_only_flag != 1)
1149*495ae853SAndroid Build Coastguard Worker             reorder_depth *= 2;
1150*495ae853SAndroid Build Coastguard Worker         ps_dec->i4_reorder_depth = reorder_depth + DISPLAY_LATENCY;
1151*495ae853SAndroid Build Coastguard Worker     }
1152*495ae853SAndroid Build Coastguard Worker     ps_dec->u2_disp_height = i4_cropped_ht;
1153*495ae853SAndroid Build Coastguard Worker     ps_dec->u2_disp_width = i4_cropped_wd;
1154*495ae853SAndroid Build Coastguard Worker 
1155*495ae853SAndroid Build Coastguard Worker     ps_dec->u2_pic_wd = u2_pic_wd;
1156*495ae853SAndroid Build Coastguard Worker     ps_dec->u2_pic_ht = u2_pic_ht;
1157*495ae853SAndroid Build Coastguard Worker     ps_dec->u4_total_mbs = ps_seq->u2_total_num_of_mbs << (1 - ps_seq->u1_frame_mbs_only_flag);
1158*495ae853SAndroid Build Coastguard Worker 
1159*495ae853SAndroid Build Coastguard Worker     /* Determining the Width and Height of Frame from that of Picture */
1160*495ae853SAndroid Build Coastguard Worker     ps_dec->u2_frm_wd_y = u2_frm_wd_y;
1161*495ae853SAndroid Build Coastguard Worker     ps_dec->u2_frm_ht_y = u2_frm_ht_y;
1162*495ae853SAndroid Build Coastguard Worker 
1163*495ae853SAndroid Build Coastguard Worker     ps_dec->u2_frm_wd_uv = u2_frm_wd_uv;
1164*495ae853SAndroid Build Coastguard Worker     ps_dec->u2_frm_ht_uv = u2_frm_ht_uv;
1165*495ae853SAndroid Build Coastguard Worker     ps_dec->s_pad_mgr.u1_pad_len_y_v = (UWORD8)(PAD_LEN_Y_V << (1 - u1_frm));
1166*495ae853SAndroid Build Coastguard Worker     ps_dec->s_pad_mgr.u1_pad_len_cr_v = (UWORD8)(PAD_LEN_UV_V << (1 - u1_frm));
1167*495ae853SAndroid Build Coastguard Worker 
1168*495ae853SAndroid Build Coastguard Worker     ps_dec->u2_frm_wd_in_mbs = ps_seq->u2_frm_wd_in_mbs;
1169*495ae853SAndroid Build Coastguard Worker     ps_dec->u2_frm_ht_in_mbs = ps_seq->u2_frm_ht_in_mbs;
1170*495ae853SAndroid Build Coastguard Worker 
1171*495ae853SAndroid Build Coastguard Worker     ps_dec->u2_crop_offset_y = u2_crop_offset_y;
1172*495ae853SAndroid Build Coastguard Worker     ps_dec->u2_crop_offset_uv = u2_crop_offset_uv;
1173*495ae853SAndroid Build Coastguard Worker 
1174*495ae853SAndroid Build Coastguard Worker     ps_seq->u1_is_valid = TRUE;
1175*495ae853SAndroid Build Coastguard Worker     ps_dec->ps_sps[u1_seq_parameter_set_id] = *ps_seq;
1176*495ae853SAndroid Build Coastguard Worker     ps_dec->ps_cur_sps = &ps_dec->ps_sps[u1_seq_parameter_set_id];
1177*495ae853SAndroid Build Coastguard Worker 
1178*495ae853SAndroid Build Coastguard Worker     return OK;
1179*495ae853SAndroid Build Coastguard Worker }
1180*495ae853SAndroid Build Coastguard Worker 
1181*495ae853SAndroid Build Coastguard Worker /*!
1182*495ae853SAndroid Build Coastguard Worker  **************************************************************************
1183*495ae853SAndroid Build Coastguard Worker  * \if Function name : ih264d_parse_end_of_sequence \endif
1184*495ae853SAndroid Build Coastguard Worker  *
1185*495ae853SAndroid Build Coastguard Worker  * \brief
1186*495ae853SAndroid Build Coastguard Worker  *    Decodes End of Sequence.
1187*495ae853SAndroid Build Coastguard Worker  *
1188*495ae853SAndroid Build Coastguard Worker  * \param ps_bitstrm   : Pointer to bit ps_bitstrm containing the NAL unit
1189*495ae853SAndroid Build Coastguard Worker  *
1190*495ae853SAndroid Build Coastguard Worker  * \return
1191*495ae853SAndroid Build Coastguard Worker  *    0 on Success and error code otherwise
1192*495ae853SAndroid Build Coastguard Worker  **************************************************************************
1193*495ae853SAndroid Build Coastguard Worker  */
ih264d_parse_end_of_sequence(dec_struct_t * ps_dec)1194*495ae853SAndroid Build Coastguard Worker WORD32 ih264d_parse_end_of_sequence(dec_struct_t * ps_dec)
1195*495ae853SAndroid Build Coastguard Worker {
1196*495ae853SAndroid Build Coastguard Worker     WORD32 ret;
1197*495ae853SAndroid Build Coastguard Worker 
1198*495ae853SAndroid Build Coastguard Worker     ret = ih264d_end_of_pic_processing(ps_dec);
1199*495ae853SAndroid Build Coastguard Worker     return ret;
1200*495ae853SAndroid Build Coastguard Worker }
1201*495ae853SAndroid Build Coastguard Worker 
1202*495ae853SAndroid Build Coastguard Worker /*!
1203*495ae853SAndroid Build Coastguard Worker  **************************************************************************
1204*495ae853SAndroid Build Coastguard Worker  * \if Function name : AcessUnitDelimiterRbsp \endif
1205*495ae853SAndroid Build Coastguard Worker  *
1206*495ae853SAndroid Build Coastguard Worker  * \brief
1207*495ae853SAndroid Build Coastguard Worker  *    Decodes AcessUnitDelimiterRbsp.
1208*495ae853SAndroid Build Coastguard Worker  *
1209*495ae853SAndroid Build Coastguard Worker  * \param ps_bitstrm   : Pointer to bit ps_bitstrm containing the NAL unit
1210*495ae853SAndroid Build Coastguard Worker  *
1211*495ae853SAndroid Build Coastguard Worker  * \return
1212*495ae853SAndroid Build Coastguard Worker  *    0 on Success and error code otherwise
1213*495ae853SAndroid Build Coastguard Worker  **************************************************************************
1214*495ae853SAndroid Build Coastguard Worker  */
1215*495ae853SAndroid Build Coastguard Worker 
ih264d_access_unit_delimiter_rbsp(dec_struct_t * ps_dec)1216*495ae853SAndroid Build Coastguard Worker WORD32 ih264d_access_unit_delimiter_rbsp(dec_struct_t * ps_dec)
1217*495ae853SAndroid Build Coastguard Worker {
1218*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_primary_pic_type;
1219*495ae853SAndroid Build Coastguard Worker     u1_primary_pic_type = ih264d_get_bits_h264(ps_dec->ps_bitstrm, 3);
1220*495ae853SAndroid Build Coastguard Worker     switch(u1_primary_pic_type)
1221*495ae853SAndroid Build Coastguard Worker     {
1222*495ae853SAndroid Build Coastguard Worker         case I_PIC:
1223*495ae853SAndroid Build Coastguard Worker         case SI_PIC:
1224*495ae853SAndroid Build Coastguard Worker         case ISI_PIC:
1225*495ae853SAndroid Build Coastguard Worker             ps_dec->ps_dec_err_status->u1_pic_aud_i = PIC_TYPE_I;
1226*495ae853SAndroid Build Coastguard Worker             break;
1227*495ae853SAndroid Build Coastguard Worker         default:
1228*495ae853SAndroid Build Coastguard Worker             ps_dec->ps_dec_err_status->u1_pic_aud_i = PIC_TYPE_UNKNOWN;
1229*495ae853SAndroid Build Coastguard Worker     }
1230*495ae853SAndroid Build Coastguard Worker     return (0);
1231*495ae853SAndroid Build Coastguard Worker }
1232*495ae853SAndroid Build Coastguard Worker /*!
1233*495ae853SAndroid Build Coastguard Worker  **************************************************************************
1234*495ae853SAndroid Build Coastguard Worker  * \if Function name : ih264d_parse_nal_unit \endif
1235*495ae853SAndroid Build Coastguard Worker  *
1236*495ae853SAndroid Build Coastguard Worker  * \brief
1237*495ae853SAndroid Build Coastguard Worker  *    Decodes NAL unit
1238*495ae853SAndroid Build Coastguard Worker  *
1239*495ae853SAndroid Build Coastguard Worker  * \return
1240*495ae853SAndroid Build Coastguard Worker  *    0 on Success and error code otherwise
1241*495ae853SAndroid Build Coastguard Worker  **************************************************************************
1242*495ae853SAndroid Build Coastguard Worker  */
1243*495ae853SAndroid Build Coastguard Worker 
ih264d_parse_nal_unit(iv_obj_t * dec_hdl,ivd_video_decode_op_t * ps_dec_op,UWORD8 * pu1_buf,UWORD32 u4_length)1244*495ae853SAndroid Build Coastguard Worker WORD32 ih264d_parse_nal_unit(iv_obj_t *dec_hdl,
1245*495ae853SAndroid Build Coastguard Worker                           ivd_video_decode_op_t *ps_dec_op,
1246*495ae853SAndroid Build Coastguard Worker                           UWORD8 *pu1_buf,
1247*495ae853SAndroid Build Coastguard Worker                           UWORD32 u4_length)
1248*495ae853SAndroid Build Coastguard Worker {
1249*495ae853SAndroid Build Coastguard Worker 
1250*495ae853SAndroid Build Coastguard Worker     dec_bit_stream_t *ps_bitstrm;
1251*495ae853SAndroid Build Coastguard Worker 
1252*495ae853SAndroid Build Coastguard Worker 
1253*495ae853SAndroid Build Coastguard Worker     dec_struct_t *ps_dec = (dec_struct_t *)dec_hdl->pv_codec_handle;
1254*495ae853SAndroid Build Coastguard Worker     ivd_video_decode_ip_t *ps_dec_in =
1255*495ae853SAndroid Build Coastguard Worker                     (ivd_video_decode_ip_t *)ps_dec->pv_dec_in;
1256*495ae853SAndroid Build Coastguard Worker     dec_slice_params_t * ps_cur_slice = ps_dec->ps_cur_slice;
1257*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_first_byte, u1_nal_ref_idc;
1258*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_nal_unit_type;
1259*495ae853SAndroid Build Coastguard Worker     WORD32 i_status = OK;
1260*495ae853SAndroid Build Coastguard Worker     ps_bitstrm = ps_dec->ps_bitstrm;
1261*495ae853SAndroid Build Coastguard Worker 
1262*495ae853SAndroid Build Coastguard Worker     if(pu1_buf)
1263*495ae853SAndroid Build Coastguard Worker     {
1264*495ae853SAndroid Build Coastguard Worker         if(u4_length)
1265*495ae853SAndroid Build Coastguard Worker         {
1266*495ae853SAndroid Build Coastguard Worker             ps_dec_op->u4_frame_decoded_flag = 0;
1267*495ae853SAndroid Build Coastguard Worker             ih264d_process_nal_unit(ps_dec->ps_bitstrm, pu1_buf,
1268*495ae853SAndroid Build Coastguard Worker                                     u4_length);
1269*495ae853SAndroid Build Coastguard Worker 
1270*495ae853SAndroid Build Coastguard Worker             SWITCHOFFTRACE;
1271*495ae853SAndroid Build Coastguard Worker             u1_first_byte = ih264d_get_bits_h264(ps_bitstrm, 8);
1272*495ae853SAndroid Build Coastguard Worker 
1273*495ae853SAndroid Build Coastguard Worker             if(NAL_FORBIDDEN_BIT(u1_first_byte))
1274*495ae853SAndroid Build Coastguard Worker             {
1275*495ae853SAndroid Build Coastguard Worker                 H264_DEC_DEBUG_PRINT("\nForbidden bit set in Nal Unit, Let's try\n");
1276*495ae853SAndroid Build Coastguard Worker             }
1277*495ae853SAndroid Build Coastguard Worker             u1_nal_unit_type = NAL_UNIT_TYPE(u1_first_byte);
1278*495ae853SAndroid Build Coastguard Worker             // if any other nal unit other than slice nal is encountered in between a
1279*495ae853SAndroid Build Coastguard Worker             // frame break out of loop without consuming header
1280*495ae853SAndroid Build Coastguard Worker             if ((ps_dec->u4_slice_start_code_found == 1)
1281*495ae853SAndroid Build Coastguard Worker                     && (ps_dec->u1_pic_decode_done != 1)
1282*495ae853SAndroid Build Coastguard Worker                     && (u1_nal_unit_type > IDR_SLICE_NAL))
1283*495ae853SAndroid Build Coastguard Worker             {
1284*495ae853SAndroid Build Coastguard Worker                 return ERROR_INCOMPLETE_FRAME;
1285*495ae853SAndroid Build Coastguard Worker             }
1286*495ae853SAndroid Build Coastguard Worker             ps_dec->u1_nal_unit_type = u1_nal_unit_type;
1287*495ae853SAndroid Build Coastguard Worker             u1_nal_ref_idc = (UWORD8)(NAL_REF_IDC(u1_first_byte));
1288*495ae853SAndroid Build Coastguard Worker             //Skip all NALUs if SPS and PPS are not decoded
1289*495ae853SAndroid Build Coastguard Worker             switch(u1_nal_unit_type)
1290*495ae853SAndroid Build Coastguard Worker             {
1291*495ae853SAndroid Build Coastguard Worker                 case SLICE_DATA_PARTITION_A_NAL:
1292*495ae853SAndroid Build Coastguard Worker                 case SLICE_DATA_PARTITION_B_NAL:
1293*495ae853SAndroid Build Coastguard Worker                 case SLICE_DATA_PARTITION_C_NAL:
1294*495ae853SAndroid Build Coastguard Worker                     if(!ps_dec->i4_decode_header)
1295*495ae853SAndroid Build Coastguard Worker                         ih264d_parse_slice_partition(ps_dec, ps_bitstrm);
1296*495ae853SAndroid Build Coastguard Worker 
1297*495ae853SAndroid Build Coastguard Worker                     break;
1298*495ae853SAndroid Build Coastguard Worker 
1299*495ae853SAndroid Build Coastguard Worker                 case IDR_SLICE_NAL:
1300*495ae853SAndroid Build Coastguard Worker                 case SLICE_NAL:
1301*495ae853SAndroid Build Coastguard Worker 
1302*495ae853SAndroid Build Coastguard Worker                     /* ! */
1303*495ae853SAndroid Build Coastguard Worker                     DEBUG_THREADS_PRINTF("Decoding  a slice NAL\n");
1304*495ae853SAndroid Build Coastguard Worker                     if(!ps_dec->i4_decode_header)
1305*495ae853SAndroid Build Coastguard Worker                     {
1306*495ae853SAndroid Build Coastguard Worker                         if(ps_dec->i4_header_decoded == 3)
1307*495ae853SAndroid Build Coastguard Worker                         {
1308*495ae853SAndroid Build Coastguard Worker                             ih264d_get_pre_sei_params(ps_dec, u1_nal_unit_type);
1309*495ae853SAndroid Build Coastguard Worker                             /* ! */
1310*495ae853SAndroid Build Coastguard Worker                             ps_dec->u4_slice_start_code_found = 1;
1311*495ae853SAndroid Build Coastguard Worker 
1312*495ae853SAndroid Build Coastguard Worker                             ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1313*495ae853SAndroid Build Coastguard Worker 
1314*495ae853SAndroid Build Coastguard Worker                             i_status = ih264d_parse_decode_slice(
1315*495ae853SAndroid Build Coastguard Worker                                             (UWORD8)(u1_nal_unit_type
1316*495ae853SAndroid Build Coastguard Worker                                                             == IDR_SLICE_NAL),
1317*495ae853SAndroid Build Coastguard Worker                                             u1_nal_ref_idc, ps_dec);
1318*495ae853SAndroid Build Coastguard Worker 
1319*495ae853SAndroid Build Coastguard Worker                             if(i_status != OK)
1320*495ae853SAndroid Build Coastguard Worker                             {
1321*495ae853SAndroid Build Coastguard Worker                                 return i_status;
1322*495ae853SAndroid Build Coastguard Worker                             }
1323*495ae853SAndroid Build Coastguard Worker                         }
1324*495ae853SAndroid Build Coastguard Worker                         else
1325*495ae853SAndroid Build Coastguard Worker                         {
1326*495ae853SAndroid Build Coastguard Worker                             H264_DEC_DEBUG_PRINT(
1327*495ae853SAndroid Build Coastguard Worker                                             "\nSlice NAL Supplied but no header has been supplied\n");
1328*495ae853SAndroid Build Coastguard Worker                         }
1329*495ae853SAndroid Build Coastguard Worker                     }
1330*495ae853SAndroid Build Coastguard Worker                     break;
1331*495ae853SAndroid Build Coastguard Worker 
1332*495ae853SAndroid Build Coastguard Worker                 case SEI_NAL:
1333*495ae853SAndroid Build Coastguard Worker                     if(!ps_dec->i4_decode_header)
1334*495ae853SAndroid Build Coastguard Worker                     {
1335*495ae853SAndroid Build Coastguard Worker                         ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1336*495ae853SAndroid Build Coastguard Worker                         i_status = ih264d_parse_sei_message(ps_dec, ps_bitstrm);
1337*495ae853SAndroid Build Coastguard Worker                         if(i_status != OK)
1338*495ae853SAndroid Build Coastguard Worker                             return i_status;
1339*495ae853SAndroid Build Coastguard Worker                         ih264d_parse_sei(ps_dec, ps_bitstrm);
1340*495ae853SAndroid Build Coastguard Worker                     }
1341*495ae853SAndroid Build Coastguard Worker                     break;
1342*495ae853SAndroid Build Coastguard Worker                 case SEQ_PARAM_NAL:
1343*495ae853SAndroid Build Coastguard Worker                     /* ! */
1344*495ae853SAndroid Build Coastguard Worker                     ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1345*495ae853SAndroid Build Coastguard Worker                     i_status = ih264d_parse_sps(ps_dec, ps_bitstrm);
1346*495ae853SAndroid Build Coastguard Worker                     ps_dec->u4_sps_cnt_in_process++;
1347*495ae853SAndroid Build Coastguard Worker                     /*If a resolution change happens within a process call, due to multiple sps
1348*495ae853SAndroid Build Coastguard Worker                      * we will not support it.
1349*495ae853SAndroid Build Coastguard Worker                      */
1350*495ae853SAndroid Build Coastguard Worker                     if((ps_dec->u4_sps_cnt_in_process > 1 ) &&
1351*495ae853SAndroid Build Coastguard Worker                                     (i_status == IVD_RES_CHANGED))
1352*495ae853SAndroid Build Coastguard Worker                     {
1353*495ae853SAndroid Build Coastguard Worker                         i_status = ERROR_INV_SPS_PPS_T;
1354*495ae853SAndroid Build Coastguard Worker                         ps_dec->u1_res_changed = 0;
1355*495ae853SAndroid Build Coastguard Worker                     }
1356*495ae853SAndroid Build Coastguard Worker                     if(i_status == ERROR_INV_SPS_PPS_T)
1357*495ae853SAndroid Build Coastguard Worker                         return i_status;
1358*495ae853SAndroid Build Coastguard Worker                     if(!i_status)
1359*495ae853SAndroid Build Coastguard Worker                         ps_dec->i4_header_decoded |= 0x1;
1360*495ae853SAndroid Build Coastguard Worker                     break;
1361*495ae853SAndroid Build Coastguard Worker 
1362*495ae853SAndroid Build Coastguard Worker                 case PIC_PARAM_NAL:
1363*495ae853SAndroid Build Coastguard Worker                     /* ! */
1364*495ae853SAndroid Build Coastguard Worker                     ih264d_rbsp_to_sodb(ps_dec->ps_bitstrm);
1365*495ae853SAndroid Build Coastguard Worker                     i_status = ih264d_parse_pps(ps_dec, ps_bitstrm);
1366*495ae853SAndroid Build Coastguard Worker                     if(i_status == ERROR_INV_SPS_PPS_T)
1367*495ae853SAndroid Build Coastguard Worker                         return i_status;
1368*495ae853SAndroid Build Coastguard Worker                     if(!i_status)
1369*495ae853SAndroid Build Coastguard Worker                         ps_dec->i4_header_decoded |= 0x2;
1370*495ae853SAndroid Build Coastguard Worker                     break;
1371*495ae853SAndroid Build Coastguard Worker                 case ACCESS_UNIT_DELIMITER_RBSP:
1372*495ae853SAndroid Build Coastguard Worker                     if(!ps_dec->i4_decode_header)
1373*495ae853SAndroid Build Coastguard Worker                     {
1374*495ae853SAndroid Build Coastguard Worker                         ih264d_access_unit_delimiter_rbsp(ps_dec);
1375*495ae853SAndroid Build Coastguard Worker                     }
1376*495ae853SAndroid Build Coastguard Worker                     break;
1377*495ae853SAndroid Build Coastguard Worker                     //Let us ignore the END_OF_SEQ_RBSP NAL and decode even after this NAL
1378*495ae853SAndroid Build Coastguard Worker                 case END_OF_STREAM_RBSP:
1379*495ae853SAndroid Build Coastguard Worker                     if(!ps_dec->i4_decode_header)
1380*495ae853SAndroid Build Coastguard Worker                     {
1381*495ae853SAndroid Build Coastguard Worker                         ih264d_parse_end_of_stream(ps_dec);
1382*495ae853SAndroid Build Coastguard Worker                     }
1383*495ae853SAndroid Build Coastguard Worker                     break;
1384*495ae853SAndroid Build Coastguard Worker                 case FILLER_DATA_NAL:
1385*495ae853SAndroid Build Coastguard Worker                     if(!ps_dec->i4_decode_header)
1386*495ae853SAndroid Build Coastguard Worker                     {
1387*495ae853SAndroid Build Coastguard Worker                         ih264d_parse_filler_data(ps_dec, ps_bitstrm);
1388*495ae853SAndroid Build Coastguard Worker                     }
1389*495ae853SAndroid Build Coastguard Worker                     break;
1390*495ae853SAndroid Build Coastguard Worker                 default:
1391*495ae853SAndroid Build Coastguard Worker                     H264_DEC_DEBUG_PRINT("\nUnknown NAL type %d\n", u1_nal_unit_type);
1392*495ae853SAndroid Build Coastguard Worker                     break;
1393*495ae853SAndroid Build Coastguard Worker             }
1394*495ae853SAndroid Build Coastguard Worker 
1395*495ae853SAndroid Build Coastguard Worker         }
1396*495ae853SAndroid Build Coastguard Worker 
1397*495ae853SAndroid Build Coastguard Worker     }
1398*495ae853SAndroid Build Coastguard Worker 
1399*495ae853SAndroid Build Coastguard Worker     return i_status;
1400*495ae853SAndroid Build Coastguard Worker 
1401*495ae853SAndroid Build Coastguard Worker }
1402