xref: /aosp_15_r20/external/libavc/encoder/ih264e_encode_header.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 *******************************************************************************
23*495ae853SAndroid Build Coastguard Worker * @file
24*495ae853SAndroid Build Coastguard Worker *  ih264e_encode_header.c
25*495ae853SAndroid Build Coastguard Worker *
26*495ae853SAndroid Build Coastguard Worker * @brief
27*495ae853SAndroid Build Coastguard Worker *  This file contains function definitions related to header encoding.
28*495ae853SAndroid Build Coastguard Worker *
29*495ae853SAndroid Build Coastguard Worker * @author
30*495ae853SAndroid Build Coastguard Worker *  ittiam
31*495ae853SAndroid Build Coastguard Worker *
32*495ae853SAndroid Build Coastguard Worker * @par List of Functions:
33*495ae853SAndroid Build Coastguard Worker *  - ih264e_generate_nal_unit_header
34*495ae853SAndroid Build Coastguard Worker *  - ih264e_generate_vui
35*495ae853SAndroid Build Coastguard Worker *  - ih264e_generate_aud
36*495ae853SAndroid Build Coastguard Worker *  - ih264e_generate_sps
37*495ae853SAndroid Build Coastguard Worker *  - ih264e_generate_pps
38*495ae853SAndroid Build Coastguard Worker *  - ih264e_generate_slice_header
39*495ae853SAndroid Build Coastguard Worker *  - ih264e_populate_vui
40*495ae853SAndroid Build Coastguard Worker *  - ih264e_populate_sps
41*495ae853SAndroid Build Coastguard Worker *  - ih264e_populate_pps
42*495ae853SAndroid Build Coastguard Worker *  - ih264e_populate_slice_header
43*495ae853SAndroid Build Coastguard Worker *  - ih264e_add_filler_nal_unit
44*495ae853SAndroid Build Coastguard Worker *
45*495ae853SAndroid Build Coastguard Worker * @remarks
46*495ae853SAndroid Build Coastguard Worker *  none
47*495ae853SAndroid Build Coastguard Worker *
48*495ae853SAndroid Build Coastguard Worker *******************************************************************************
49*495ae853SAndroid Build Coastguard Worker */
50*495ae853SAndroid Build Coastguard Worker 
51*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
52*495ae853SAndroid Build Coastguard Worker /* File Includes                                                             */
53*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
54*495ae853SAndroid Build Coastguard Worker 
55*495ae853SAndroid Build Coastguard Worker /* System Include Files */
56*495ae853SAndroid Build Coastguard Worker #include <stdio.h>
57*495ae853SAndroid Build Coastguard Worker #include <stddef.h>
58*495ae853SAndroid Build Coastguard Worker #include <stdlib.h>
59*495ae853SAndroid Build Coastguard Worker #include <string.h>
60*495ae853SAndroid Build Coastguard Worker #include <assert.h>
61*495ae853SAndroid Build Coastguard Worker 
62*495ae853SAndroid Build Coastguard Worker /* User Include Files */
63*495ae853SAndroid Build Coastguard Worker #include "ih264e_config.h"
64*495ae853SAndroid Build Coastguard Worker #include "ih264_typedefs.h"
65*495ae853SAndroid Build Coastguard Worker #include "iv2.h"
66*495ae853SAndroid Build Coastguard Worker #include "ive2.h"
67*495ae853SAndroid Build Coastguard Worker #include "ithread.h"
68*495ae853SAndroid Build Coastguard Worker 
69*495ae853SAndroid Build Coastguard Worker #include "ih264_debug.h"
70*495ae853SAndroid Build Coastguard Worker #include "ih264_macros.h"
71*495ae853SAndroid Build Coastguard Worker #include "ih264_error.h"
72*495ae853SAndroid Build Coastguard Worker #include "ih264_defs.h"
73*495ae853SAndroid Build Coastguard Worker #include "ih264_mem_fns.h"
74*495ae853SAndroid Build Coastguard Worker #include "ih264_padding.h"
75*495ae853SAndroid Build Coastguard Worker #include "ih264_structs.h"
76*495ae853SAndroid Build Coastguard Worker #include "ih264_trans_quant_itrans_iquant.h"
77*495ae853SAndroid Build Coastguard Worker #include "ih264_inter_pred_filters.h"
78*495ae853SAndroid Build Coastguard Worker #include "ih264_intra_pred_filters.h"
79*495ae853SAndroid Build Coastguard Worker #include "ih264_deblk_edge_filters.h"
80*495ae853SAndroid Build Coastguard Worker #include "ih264_common_tables.h"
81*495ae853SAndroid Build Coastguard Worker #include "ih264_cabac_tables.h"
82*495ae853SAndroid Build Coastguard Worker 
83*495ae853SAndroid Build Coastguard Worker #include "ime_defs.h"
84*495ae853SAndroid Build Coastguard Worker #include "ime_distortion_metrics.h"
85*495ae853SAndroid Build Coastguard Worker #include "ime_structs.h"
86*495ae853SAndroid Build Coastguard Worker 
87*495ae853SAndroid Build Coastguard Worker #include "irc_cntrl_param.h"
88*495ae853SAndroid Build Coastguard Worker #include "irc_frame_info_collector.h"
89*495ae853SAndroid Build Coastguard Worker 
90*495ae853SAndroid Build Coastguard Worker #include "ih264e.h"
91*495ae853SAndroid Build Coastguard Worker #include "ih264e_error.h"
92*495ae853SAndroid Build Coastguard Worker #include "ih264e_defs.h"
93*495ae853SAndroid Build Coastguard Worker #include "ih264e_rate_control.h"
94*495ae853SAndroid Build Coastguard Worker #include "ih264e_bitstream.h"
95*495ae853SAndroid Build Coastguard Worker #include "ih264e_cabac_structs.h"
96*495ae853SAndroid Build Coastguard Worker #include "ih264e_structs.h"
97*495ae853SAndroid Build Coastguard Worker #include "ih264e_utils.h"
98*495ae853SAndroid Build Coastguard Worker #include "ih264e_sei.h"
99*495ae853SAndroid Build Coastguard Worker #include "ih264e_encode_header.h"
100*495ae853SAndroid Build Coastguard Worker #include "ih264e_trace.h"
101*495ae853SAndroid Build Coastguard Worker 
102*495ae853SAndroid Build Coastguard Worker 
103*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
104*495ae853SAndroid Build Coastguard Worker /* Function Definitions                                                      */
105*495ae853SAndroid Build Coastguard Worker /*****************************************************************************/
106*495ae853SAndroid Build Coastguard Worker 
107*495ae853SAndroid Build Coastguard Worker /**
108*495ae853SAndroid Build Coastguard Worker ******************************************************************************
109*495ae853SAndroid Build Coastguard Worker *
110*495ae853SAndroid Build Coastguard Worker * @brief Generate nal unit header in the stream as per section 7.4.1
111*495ae853SAndroid Build Coastguard Worker *
112*495ae853SAndroid Build Coastguard Worker * @par   Description
113*495ae853SAndroid Build Coastguard Worker *  Inserts Nal unit header syntax as per section 7.4.1
114*495ae853SAndroid Build Coastguard Worker *
115*495ae853SAndroid Build Coastguard Worker * @param[inout]   ps_bitstrm
116*495ae853SAndroid Build Coastguard Worker *  pointer to bitstream context (handle)
117*495ae853SAndroid Build Coastguard Worker *
118*495ae853SAndroid Build Coastguard Worker * @param[in]   nal_unit_type
119*495ae853SAndroid Build Coastguard Worker *  nal type to be inserted
120*495ae853SAndroid Build Coastguard Worker *
121*495ae853SAndroid Build Coastguard Worker * @param[in]   nal_ref_idc
122*495ae853SAndroid Build Coastguard Worker *  nal ref idc to be inserted
123*495ae853SAndroid Build Coastguard Worker *
124*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
125*495ae853SAndroid Build Coastguard Worker *
126*495ae853SAndroid Build Coastguard Worker ******************************************************************************
127*495ae853SAndroid Build Coastguard Worker */
ih264e_generate_nal_unit_header(bitstrm_t * ps_bitstrm,WORD32 nal_unit_type,WORD32 nal_ref_idc)128*495ae853SAndroid Build Coastguard Worker static WORD32 ih264e_generate_nal_unit_header(bitstrm_t *ps_bitstrm,
129*495ae853SAndroid Build Coastguard Worker                                               WORD32 nal_unit_type,
130*495ae853SAndroid Build Coastguard Worker                                               WORD32 nal_ref_idc)
131*495ae853SAndroid Build Coastguard Worker {
132*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
133*495ae853SAndroid Build Coastguard Worker 
134*495ae853SAndroid Build Coastguard Worker     /* sanity checks */
135*495ae853SAndroid Build Coastguard Worker     ASSERT((nal_unit_type > 0) && (nal_unit_type < 32));
136*495ae853SAndroid Build Coastguard Worker 
137*495ae853SAndroid Build Coastguard Worker     /* forbidden_zero_bit + nal_ref_idc + nal_unit_type */
138*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm,
139*495ae853SAndroid Build Coastguard Worker              ((nal_ref_idc << 5) + nal_unit_type),
140*495ae853SAndroid Build Coastguard Worker              (1+2+5), /*1 forbidden zero bit + 2 nal_ref_idc + 5 nal_unit_type */
141*495ae853SAndroid Build Coastguard Worker              return_status,
142*495ae853SAndroid Build Coastguard Worker              "nal_unit_header");
143*495ae853SAndroid Build Coastguard Worker 
144*495ae853SAndroid Build Coastguard Worker     return(return_status);
145*495ae853SAndroid Build Coastguard Worker }
146*495ae853SAndroid Build Coastguard Worker /**
147*495ae853SAndroid Build Coastguard Worker ******************************************************************************
148*495ae853SAndroid Build Coastguard Worker *
149*495ae853SAndroid Build Coastguard Worker * @brief Generates VUI (Video usability information)
150*495ae853SAndroid Build Coastguard Worker *
151*495ae853SAndroid Build Coastguard Worker * @par   Description
152*495ae853SAndroid Build Coastguard Worker *  This function generates VUI header as per the spec
153*495ae853SAndroid Build Coastguard Worker *
154*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_bitstrm
155*495ae853SAndroid Build Coastguard Worker *  pointer to bitstream context (handle)
156*495ae853SAndroid Build Coastguard Worker *
157*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_vui
158*495ae853SAndroid Build Coastguard Worker *  pointer to structure containing VUI data
159*495ae853SAndroid Build Coastguard Worker 
160*495ae853SAndroid Build Coastguard Worker *
161*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
162*495ae853SAndroid Build Coastguard Worker *
163*495ae853SAndroid Build Coastguard Worker ******************************************************************************
164*495ae853SAndroid Build Coastguard Worker */
ih264e_generate_vui(bitstrm_t * ps_bitstrm,vui_t * ps_vui)165*495ae853SAndroid Build Coastguard Worker WORD32 ih264e_generate_vui(bitstrm_t *ps_bitstrm, vui_t *ps_vui)
166*495ae853SAndroid Build Coastguard Worker {
167*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
168*495ae853SAndroid Build Coastguard Worker 
169*495ae853SAndroid Build Coastguard Worker     /* aspect_ratio_info_present_flag */
170*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_vui->u1_aspect_ratio_info_present_flag, 1,
171*495ae853SAndroid Build Coastguard Worker              return_status, "aspect_ratio_info_present_flag");
172*495ae853SAndroid Build Coastguard Worker 
173*495ae853SAndroid Build Coastguard Worker     if(ps_vui->u1_aspect_ratio_info_present_flag)
174*495ae853SAndroid Build Coastguard Worker     { /* aspect_ratio_idc */
175*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_vui->u1_aspect_ratio_idc, 8, return_status,
176*495ae853SAndroid Build Coastguard Worker                  "aspect_ratio_idc");
177*495ae853SAndroid Build Coastguard Worker         if(255 == ps_vui->u1_aspect_ratio_idc) /* Extended_SAR */
178*495ae853SAndroid Build Coastguard Worker         { /* sar_width */
179*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_vui->u2_sar_width, 16, return_status,
180*495ae853SAndroid Build Coastguard Worker                      "sar_width");
181*495ae853SAndroid Build Coastguard Worker             /* sar_height */
182*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_vui->u2_sar_height, 16, return_status,
183*495ae853SAndroid Build Coastguard Worker                      "sar_height");
184*495ae853SAndroid Build Coastguard Worker         }
185*495ae853SAndroid Build Coastguard Worker 
186*495ae853SAndroid Build Coastguard Worker     }
187*495ae853SAndroid Build Coastguard Worker     /* overscan_info_present_flag */
188*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_vui->u1_overscan_info_present_flag, 1,
189*495ae853SAndroid Build Coastguard Worker              return_status, "overscan_info_present_flag");
190*495ae853SAndroid Build Coastguard Worker 
191*495ae853SAndroid Build Coastguard Worker     if(ps_vui->u1_overscan_info_present_flag)
192*495ae853SAndroid Build Coastguard Worker     {
193*495ae853SAndroid Build Coastguard Worker         /* overscan_appropriate_flag */
194*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_vui->u1_overscan_appropriate_flag, 1,
195*495ae853SAndroid Build Coastguard Worker                  return_status, "overscan_appropriate_flag");
196*495ae853SAndroid Build Coastguard Worker 
197*495ae853SAndroid Build Coastguard Worker     }
198*495ae853SAndroid Build Coastguard Worker     /* video_signal_type_present_flag */
199*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_vui->u1_video_signal_type_present_flag, 1,
200*495ae853SAndroid Build Coastguard Worker              return_status, "video_signal_type_present_flag");
201*495ae853SAndroid Build Coastguard Worker 
202*495ae853SAndroid Build Coastguard Worker     if(ps_vui->u1_video_signal_type_present_flag)
203*495ae853SAndroid Build Coastguard Worker     { /* video_format */
204*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_vui->u1_video_format, 3, return_status,
205*495ae853SAndroid Build Coastguard Worker                  "video_format");
206*495ae853SAndroid Build Coastguard Worker 
207*495ae853SAndroid Build Coastguard Worker         /* video_full_range_flag */
208*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_vui->u1_video_full_range_flag, 1, return_status,
209*495ae853SAndroid Build Coastguard Worker                  "video_full_range_flag");
210*495ae853SAndroid Build Coastguard Worker 
211*495ae853SAndroid Build Coastguard Worker         /* colour_description_present_flag */
212*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_vui->u1_colour_description_present_flag, 1,
213*495ae853SAndroid Build Coastguard Worker                  return_status, "colour_description_present_flag");
214*495ae853SAndroid Build Coastguard Worker 
215*495ae853SAndroid Build Coastguard Worker         if(ps_vui->u1_colour_description_present_flag)
216*495ae853SAndroid Build Coastguard Worker         {
217*495ae853SAndroid Build Coastguard Worker             /* colour_primaries */
218*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_vui->u1_colour_primaries, 8, return_status,
219*495ae853SAndroid Build Coastguard Worker                      "colour_primaries");
220*495ae853SAndroid Build Coastguard Worker 
221*495ae853SAndroid Build Coastguard Worker             /* transfer_characteristics */
222*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_vui->u1_transfer_characteristics, 8,
223*495ae853SAndroid Build Coastguard Worker                      return_status, "transfer_characteristics");
224*495ae853SAndroid Build Coastguard Worker 
225*495ae853SAndroid Build Coastguard Worker             /* matrix_coefficients */
226*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_vui->u1_matrix_coefficients, 8,
227*495ae853SAndroid Build Coastguard Worker                      return_status, "matrix_coefficients");
228*495ae853SAndroid Build Coastguard Worker         }
229*495ae853SAndroid Build Coastguard Worker 
230*495ae853SAndroid Build Coastguard Worker     }
231*495ae853SAndroid Build Coastguard Worker 
232*495ae853SAndroid Build Coastguard Worker     /* chroma_loc_info_present_flag */
233*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_vui->u1_chroma_loc_info_present_flag, 1,
234*495ae853SAndroid Build Coastguard Worker              return_status, "chroma_loc_info_present_flag");
235*495ae853SAndroid Build Coastguard Worker 
236*495ae853SAndroid Build Coastguard Worker     if(ps_vui->u1_chroma_loc_info_present_flag)
237*495ae853SAndroid Build Coastguard Worker     {
238*495ae853SAndroid Build Coastguard Worker         /* chroma_sample_loc_type_top_field */
239*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_vui->u1_chroma_sample_loc_type_top_field,
240*495ae853SAndroid Build Coastguard Worker                      return_status, "chroma_sample_loc_type_top_field");
241*495ae853SAndroid Build Coastguard Worker 
242*495ae853SAndroid Build Coastguard Worker         /* chroma_sample_loc_type_bottom_field */
243*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_vui->u1_chroma_sample_loc_type_bottom_field,
244*495ae853SAndroid Build Coastguard Worker                      return_status, "chroma_sample_loc_type_bottom_field");
245*495ae853SAndroid Build Coastguard Worker     }
246*495ae853SAndroid Build Coastguard Worker 
247*495ae853SAndroid Build Coastguard Worker     /* timing_info_present_flag */
248*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_vui->u1_vui_timing_info_present_flag, 1,
249*495ae853SAndroid Build Coastguard Worker              return_status, "timing_info_present_flag");
250*495ae853SAndroid Build Coastguard Worker 
251*495ae853SAndroid Build Coastguard Worker     if(ps_vui->u1_vui_timing_info_present_flag)
252*495ae853SAndroid Build Coastguard Worker     {
253*495ae853SAndroid Build Coastguard Worker         /* num_units_in_tick */
254*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_vui->u4_vui_num_units_in_tick, 32,
255*495ae853SAndroid Build Coastguard Worker                  return_status, "num_units_in_tick");
256*495ae853SAndroid Build Coastguard Worker 
257*495ae853SAndroid Build Coastguard Worker         /* time_scale */
258*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_vui->u4_vui_time_scale, 32, return_status,
259*495ae853SAndroid Build Coastguard Worker                  "time_scale");
260*495ae853SAndroid Build Coastguard Worker 
261*495ae853SAndroid Build Coastguard Worker         /* fixed_frame_rate_flag */
262*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_vui->u1_fixed_frame_rate_flag, 1, return_status,
263*495ae853SAndroid Build Coastguard Worker                  "fixed_frame_rate_flag");
264*495ae853SAndroid Build Coastguard Worker 
265*495ae853SAndroid Build Coastguard Worker     }
266*495ae853SAndroid Build Coastguard Worker 
267*495ae853SAndroid Build Coastguard Worker     /* nal_hrd_parameters_present_flag */
268*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_vui->u1_nal_hrd_parameters_present_flag, 1,
269*495ae853SAndroid Build Coastguard Worker              return_status, "nal_hrd_parameters_present_flag");
270*495ae853SAndroid Build Coastguard Worker 
271*495ae853SAndroid Build Coastguard Worker     if(ps_vui->u1_nal_hrd_parameters_present_flag)
272*495ae853SAndroid Build Coastguard Worker     {
273*495ae853SAndroid Build Coastguard Worker         hrd_params_t * ps_hrd_params = &ps_vui->s_nal_hrd_parameters;
274*495ae853SAndroid Build Coastguard Worker         WORD32 i;
275*495ae853SAndroid Build Coastguard Worker         /* cpb_cnt_minus1 */
276*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_hrd_params->u1_cpb_cnt_minus1,
277*495ae853SAndroid Build Coastguard Worker                      return_status, "cpb_cnt_minus1");
278*495ae853SAndroid Build Coastguard Worker 
279*495ae853SAndroid Build Coastguard Worker         /* bit_rate_scale */
280*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_hrd_params->u4_bit_rate_scale, 4, return_status,
281*495ae853SAndroid Build Coastguard Worker                  "bit_rate_scale");
282*495ae853SAndroid Build Coastguard Worker 
283*495ae853SAndroid Build Coastguard Worker         /* cpb_size_scale */
284*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_hrd_params->u4_cpb_size_scale, 4, return_status,
285*495ae853SAndroid Build Coastguard Worker                  "cpb_size_scale");
286*495ae853SAndroid Build Coastguard Worker         for(i = 0; i < ps_hrd_params->u1_cpb_cnt_minus1; i++)
287*495ae853SAndroid Build Coastguard Worker         {
288*495ae853SAndroid Build Coastguard Worker             /* bit_rate_value_minus1[SchedSelIdx] */
289*495ae853SAndroid Build Coastguard Worker             PUT_BITS_UEV(ps_bitstrm,
290*495ae853SAndroid Build Coastguard Worker                          ps_hrd_params->au4_bit_rate_value_minus1[i],
291*495ae853SAndroid Build Coastguard Worker                          return_status, "bit_rate_value_minus1[SchedSelIdx]");
292*495ae853SAndroid Build Coastguard Worker 
293*495ae853SAndroid Build Coastguard Worker             /* cpb_size_value_minus1[SchedSelIdx] */
294*495ae853SAndroid Build Coastguard Worker             PUT_BITS_UEV(ps_bitstrm,
295*495ae853SAndroid Build Coastguard Worker                          ps_hrd_params->au4_cpb_size_value_minus1[i],
296*495ae853SAndroid Build Coastguard Worker                          return_status, "cpb_size_value_minus1[SchedSelIdx]");
297*495ae853SAndroid Build Coastguard Worker 
298*495ae853SAndroid Build Coastguard Worker             /* cbr_flag[SchedSelIdx] */
299*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_hrd_params->au1_cbr_flag[i], 1,
300*495ae853SAndroid Build Coastguard Worker                      return_status, "cbr_flag[SchedSelIdx]");
301*495ae853SAndroid Build Coastguard Worker         }
302*495ae853SAndroid Build Coastguard Worker 
303*495ae853SAndroid Build Coastguard Worker         /* initial_cpb_removal_delay_length_minus1 */
304*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm,
305*495ae853SAndroid Build Coastguard Worker                  ps_hrd_params->u1_initial_cpb_removal_delay_length_minus1, 5,
306*495ae853SAndroid Build Coastguard Worker                  return_status, "initial_cpb_removal_delay_length_minus1");
307*495ae853SAndroid Build Coastguard Worker 
308*495ae853SAndroid Build Coastguard Worker         /* cpb_removal_delay_length_minus1 */
309*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_hrd_params->u1_cpb_removal_delay_length_minus1,
310*495ae853SAndroid Build Coastguard Worker                  5, return_status, "cpb_removal_delay_length_minus1");
311*495ae853SAndroid Build Coastguard Worker 
312*495ae853SAndroid Build Coastguard Worker         /* dpb_output_delay_length_minus1 */
313*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_hrd_params->u1_dpb_output_delay_length_minus1,
314*495ae853SAndroid Build Coastguard Worker                  5, return_status, "dpb_output_delay_length_minus1");
315*495ae853SAndroid Build Coastguard Worker 
316*495ae853SAndroid Build Coastguard Worker         /* time_offset_length */
317*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_hrd_params->u1_time_offset_length, 5,
318*495ae853SAndroid Build Coastguard Worker                  return_status, "time_offset_length");
319*495ae853SAndroid Build Coastguard Worker     }
320*495ae853SAndroid Build Coastguard Worker 
321*495ae853SAndroid Build Coastguard Worker     /* vcl_hrd_parameters_present_flag */
322*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_vui->u1_vcl_hrd_parameters_present_flag, 1,
323*495ae853SAndroid Build Coastguard Worker              return_status, "vcl_hrd_parameters_present_flag");
324*495ae853SAndroid Build Coastguard Worker 
325*495ae853SAndroid Build Coastguard Worker     if(ps_vui->u1_vcl_hrd_parameters_present_flag)
326*495ae853SAndroid Build Coastguard Worker     {
327*495ae853SAndroid Build Coastguard Worker         hrd_params_t * ps_hrd_params = &ps_vui->s_vcl_hrd_parameters;
328*495ae853SAndroid Build Coastguard Worker         WORD32 i;
329*495ae853SAndroid Build Coastguard Worker         /* cpb_cnt_minus1 */
330*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_hrd_params->u1_cpb_cnt_minus1,
331*495ae853SAndroid Build Coastguard Worker                      return_status, "cpb_cnt_minus1");
332*495ae853SAndroid Build Coastguard Worker 
333*495ae853SAndroid Build Coastguard Worker         /* bit_rate_scale */
334*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_hrd_params->u4_bit_rate_scale, 4, return_status,
335*495ae853SAndroid Build Coastguard Worker                  "bit_rate_scale");
336*495ae853SAndroid Build Coastguard Worker 
337*495ae853SAndroid Build Coastguard Worker         /* cpb_size_scale */
338*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_hrd_params->u4_cpb_size_scale, 4, return_status,
339*495ae853SAndroid Build Coastguard Worker                  "cpb_size_scale");
340*495ae853SAndroid Build Coastguard Worker         for(i = 0; i < ps_hrd_params->u1_cpb_cnt_minus1; i++)
341*495ae853SAndroid Build Coastguard Worker         {
342*495ae853SAndroid Build Coastguard Worker             /* bit_rate_value_minus1[SchedSelIdx] */
343*495ae853SAndroid Build Coastguard Worker             PUT_BITS_UEV(ps_bitstrm,
344*495ae853SAndroid Build Coastguard Worker                          ps_hrd_params->au4_bit_rate_value_minus1[i],
345*495ae853SAndroid Build Coastguard Worker                          return_status, "bit_rate_value_minus1[SchedSelIdx]");
346*495ae853SAndroid Build Coastguard Worker 
347*495ae853SAndroid Build Coastguard Worker             /* cpb_size_value_minus1[SchedSelIdx] */
348*495ae853SAndroid Build Coastguard Worker             PUT_BITS_UEV(ps_bitstrm,
349*495ae853SAndroid Build Coastguard Worker                          ps_hrd_params->au4_cpb_size_value_minus1[i],
350*495ae853SAndroid Build Coastguard Worker                          return_status, "cpb_size_value_minus1[SchedSelIdx]");
351*495ae853SAndroid Build Coastguard Worker 
352*495ae853SAndroid Build Coastguard Worker             /* cbr_flag[SchedSelIdx] */
353*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_hrd_params->au1_cbr_flag[i], 1,
354*495ae853SAndroid Build Coastguard Worker                      return_status, "cbr_flag[SchedSelIdx]");
355*495ae853SAndroid Build Coastguard Worker         }
356*495ae853SAndroid Build Coastguard Worker 
357*495ae853SAndroid Build Coastguard Worker         /* initial_cpb_removal_delay_length_minus1 */
358*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm,
359*495ae853SAndroid Build Coastguard Worker                  ps_hrd_params->u1_initial_cpb_removal_delay_length_minus1, 5,
360*495ae853SAndroid Build Coastguard Worker                  return_status, "initial_cpb_removal_delay_length_minus1");
361*495ae853SAndroid Build Coastguard Worker 
362*495ae853SAndroid Build Coastguard Worker         /* cpb_removal_delay_length_minus1 */
363*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_hrd_params->u1_cpb_removal_delay_length_minus1,
364*495ae853SAndroid Build Coastguard Worker                  5, return_status, "cpb_removal_delay_length_minus1");
365*495ae853SAndroid Build Coastguard Worker 
366*495ae853SAndroid Build Coastguard Worker         /* dpb_output_delay_length_minus1 */
367*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_hrd_params->u1_dpb_output_delay_length_minus1,
368*495ae853SAndroid Build Coastguard Worker                  5, return_status, "dpb_output_delay_length_minus1");
369*495ae853SAndroid Build Coastguard Worker 
370*495ae853SAndroid Build Coastguard Worker         /* time_offset_length */
371*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_hrd_params->u1_time_offset_length, 5,
372*495ae853SAndroid Build Coastguard Worker                  return_status, "time_offset_length");
373*495ae853SAndroid Build Coastguard Worker     }
374*495ae853SAndroid Build Coastguard Worker 
375*495ae853SAndroid Build Coastguard Worker     if(ps_vui->u1_nal_hrd_parameters_present_flag
376*495ae853SAndroid Build Coastguard Worker                     || ps_vui->u1_vcl_hrd_parameters_present_flag)
377*495ae853SAndroid Build Coastguard Worker     {
378*495ae853SAndroid Build Coastguard Worker         /* low_delay_hrd_flag */
379*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_vui->u1_low_delay_hrd_flag, 1, return_status,
380*495ae853SAndroid Build Coastguard Worker                  "low_delay_hrd_flag");
381*495ae853SAndroid Build Coastguard Worker     }
382*495ae853SAndroid Build Coastguard Worker     /* pic_struct_present_flag */
383*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_vui->u1_pic_struct_present_flag, 1, return_status,
384*495ae853SAndroid Build Coastguard Worker              "pic_struct_present_flag");
385*495ae853SAndroid Build Coastguard Worker 
386*495ae853SAndroid Build Coastguard Worker     /* bitstream_restriction_flag */
387*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_vui->u1_bitstream_restriction_flag, 1,
388*495ae853SAndroid Build Coastguard Worker              return_status, "bitstream_restriction_flag");
389*495ae853SAndroid Build Coastguard Worker 
390*495ae853SAndroid Build Coastguard Worker     if(ps_vui->u1_bitstream_restriction_flag == 1)
391*495ae853SAndroid Build Coastguard Worker     {
392*495ae853SAndroid Build Coastguard Worker         /* motion_vectors_over_pic_boundaries_flag */
393*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_vui->u1_motion_vectors_over_pic_boundaries_flag,
394*495ae853SAndroid Build Coastguard Worker                  1, return_status, "motion_vectors_over_pic_boundaries_flag");
395*495ae853SAndroid Build Coastguard Worker 
396*495ae853SAndroid Build Coastguard Worker         /* max_bytes_per_pic_denom */
397*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_vui->u1_max_bytes_per_pic_denom,
398*495ae853SAndroid Build Coastguard Worker                      return_status, "max_bytes_per_pic_denom");
399*495ae853SAndroid Build Coastguard Worker 
400*495ae853SAndroid Build Coastguard Worker         /* max_bits_per_mb_denom */
401*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_vui->u1_max_bits_per_mb_denom,
402*495ae853SAndroid Build Coastguard Worker                      return_status, "max_bits_per_mb_denom");
403*495ae853SAndroid Build Coastguard Worker 
404*495ae853SAndroid Build Coastguard Worker         /* log2_max_mv_length_horizontal */
405*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_vui->u1_log2_max_mv_length_horizontal,
406*495ae853SAndroid Build Coastguard Worker                      return_status, "log2_max_mv_length_horizontal");
407*495ae853SAndroid Build Coastguard Worker 
408*495ae853SAndroid Build Coastguard Worker         /* log2_max_mv_length_vertical */
409*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_vui->u1_log2_max_mv_length_vertical,
410*495ae853SAndroid Build Coastguard Worker                      return_status, "log2_max_mv_length_vertical");
411*495ae853SAndroid Build Coastguard Worker 
412*495ae853SAndroid Build Coastguard Worker         /* max_num_reorder_frames */
413*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_vui->u1_num_reorder_frames, return_status,
414*495ae853SAndroid Build Coastguard Worker                      "max_num_reorder_frames");
415*495ae853SAndroid Build Coastguard Worker 
416*495ae853SAndroid Build Coastguard Worker         /* max_dec_frame_buffering */
417*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_vui->u1_max_dec_frame_buffering,
418*495ae853SAndroid Build Coastguard Worker                      return_status, "max_dec_frame_buffering");
419*495ae853SAndroid Build Coastguard Worker     }
420*495ae853SAndroid Build Coastguard Worker 
421*495ae853SAndroid Build Coastguard Worker     return return_status;
422*495ae853SAndroid Build Coastguard Worker }
423*495ae853SAndroid Build Coastguard Worker 
424*495ae853SAndroid Build Coastguard Worker /**
425*495ae853SAndroid Build Coastguard Worker ******************************************************************************
426*495ae853SAndroid Build Coastguard Worker *
427*495ae853SAndroid Build Coastguard Worker * @brief Generates SPS (Sequence Parameter Set)
428*495ae853SAndroid Build Coastguard Worker *
429*495ae853SAndroid Build Coastguard Worker * @par   Description
430*495ae853SAndroid Build Coastguard Worker *  This function generates Sequence Parameter Set header as per the spec
431*495ae853SAndroid Build Coastguard Worker *
432*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_bitstrm
433*495ae853SAndroid Build Coastguard Worker *  pointer to bitstream context (handle)
434*495ae853SAndroid Build Coastguard Worker *
435*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_sps
436*495ae853SAndroid Build Coastguard Worker *  pointer to structure containing SPS data
437*495ae853SAndroid Build Coastguard Worker *
438*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_vui
439*495ae853SAndroid Build Coastguard Worker *  pointer to structure containing VUI data
440*495ae853SAndroid Build Coastguard Worker *
441*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
442*495ae853SAndroid Build Coastguard Worker *
443*495ae853SAndroid Build Coastguard Worker ******************************************************************************
444*495ae853SAndroid Build Coastguard Worker */
ih264e_generate_sps(bitstrm_t * ps_bitstrm,sps_t * ps_sps,vui_t * ps_vui)445*495ae853SAndroid Build Coastguard Worker WORD32 ih264e_generate_sps(bitstrm_t *ps_bitstrm, sps_t *ps_sps, vui_t *ps_vui)
446*495ae853SAndroid Build Coastguard Worker {
447*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
448*495ae853SAndroid Build Coastguard Worker     WORD32 i;
449*495ae853SAndroid Build Coastguard Worker     WORD8  i1_nal_unit_type = 7;
450*495ae853SAndroid Build Coastguard Worker     WORD8  i1_nal_ref_idc = 3;
451*495ae853SAndroid Build Coastguard Worker 
452*495ae853SAndroid Build Coastguard Worker     /* Insert Start Code */
453*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
454*495ae853SAndroid Build Coastguard Worker     if(return_status != IH264E_SUCCESS)
455*495ae853SAndroid Build Coastguard Worker     {
456*495ae853SAndroid Build Coastguard Worker         return return_status;
457*495ae853SAndroid Build Coastguard Worker     }
458*495ae853SAndroid Build Coastguard Worker     /* Insert Nal Unit Header */
459*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_generate_nal_unit_header(ps_bitstrm, i1_nal_unit_type, i1_nal_ref_idc);
460*495ae853SAndroid Build Coastguard Worker     if(return_status != IH264E_SUCCESS)
461*495ae853SAndroid Build Coastguard Worker     {
462*495ae853SAndroid Build Coastguard Worker         return return_status;
463*495ae853SAndroid Build Coastguard Worker     }
464*495ae853SAndroid Build Coastguard Worker     /* profile_idc */
465*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->u1_profile_idc, 8, return_status, "profile_idc");
466*495ae853SAndroid Build Coastguard Worker 
467*495ae853SAndroid Build Coastguard Worker     /* constrained_set_flags */
468*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->u1_constraint_set0_flag, 1, return_status, "constrained_set0_flag");
469*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->u1_constraint_set1_flag, 1, return_status, "constrained_set1_flag");
470*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->u1_constraint_set2_flag, 1, return_status, "constrained_set2_flag");
471*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->u1_constraint_set3_flag, 1, return_status, "constrained_set3_flag");
472*495ae853SAndroid Build Coastguard Worker 
473*495ae853SAndroid Build Coastguard Worker     /* reserved_zero_four_bits */
474*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, 0, 4, return_status, "reserved_zero_four_bits");
475*495ae853SAndroid Build Coastguard Worker 
476*495ae853SAndroid Build Coastguard Worker     /* level_idc */
477*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->u1_level_idc, 8, return_status, "level_idc");
478*495ae853SAndroid Build Coastguard Worker 
479*495ae853SAndroid Build Coastguard Worker     /* seq_parameter_set_id */
480*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_sps->u1_sps_id, return_status, "seq_parameter_set_id");
481*495ae853SAndroid Build Coastguard Worker 
482*495ae853SAndroid Build Coastguard Worker     if (ps_sps->u1_profile_idc >= IH264_PROFILE_HIGH)
483*495ae853SAndroid Build Coastguard Worker     {
484*495ae853SAndroid Build Coastguard Worker         /* chroma_format_idc */
485*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_sps->u1_chroma_format_idc, return_status, "chroma_format_idc");
486*495ae853SAndroid Build Coastguard Worker 
487*495ae853SAndroid Build Coastguard Worker         if (ps_sps->u1_chroma_format_idc == CHROMA_FMT_IDC_YUV444)
488*495ae853SAndroid Build Coastguard Worker         {
489*495ae853SAndroid Build Coastguard Worker             /* i1_residual_colour_transform_flag */
490*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_sps->i1_residual_colour_transform_flag, 1, return_status, "i1_residual_colour_transform_flag");
491*495ae853SAndroid Build Coastguard Worker         }
492*495ae853SAndroid Build Coastguard Worker 
493*495ae853SAndroid Build Coastguard Worker         /* bit_depth_luma_minus8 */
494*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, (ps_sps->i1_bit_depth_luma - 8), return_status, "bit_depth_luma_minus8");
495*495ae853SAndroid Build Coastguard Worker 
496*495ae853SAndroid Build Coastguard Worker         /* bit_depth_chroma_minus8 */
497*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, (ps_sps->i1_bit_depth_chroma - 8), return_status, "bit_depth_chroma_minus8");
498*495ae853SAndroid Build Coastguard Worker 
499*495ae853SAndroid Build Coastguard Worker         /* qpprime_y_zero_transform_bypass_flag */
500*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_sps->i1_qpprime_y_zero_transform_bypass_flag, 1, return_status, "qpprime_y_zero_transform_bypass_flag");
501*495ae853SAndroid Build Coastguard Worker 
502*495ae853SAndroid Build Coastguard Worker         /* seq_scaling_matrix_present_flag */
503*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_sps->i1_seq_scaling_matrix_present_flag, 1, return_status, "seq_scaling_matrix_present_flag");
504*495ae853SAndroid Build Coastguard Worker 
505*495ae853SAndroid Build Coastguard Worker         /* seq_scaling_list */
506*495ae853SAndroid Build Coastguard Worker         if (ps_sps->i1_seq_scaling_matrix_present_flag)
507*495ae853SAndroid Build Coastguard Worker         {
508*495ae853SAndroid Build Coastguard Worker             /* TODO_LATER: Will be enabled once scaling list support is added */
509*495ae853SAndroid Build Coastguard Worker         }
510*495ae853SAndroid Build Coastguard Worker     }
511*495ae853SAndroid Build Coastguard Worker 
512*495ae853SAndroid Build Coastguard Worker     /* log2_max_frame_num_minus4 */
513*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, (ps_sps->i1_log2_max_frame_num - 4), return_status, "log2_max_frame_num_minus4");
514*495ae853SAndroid Build Coastguard Worker 
515*495ae853SAndroid Build Coastguard Worker     /* pic_order_cnt_type */
516*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_sps->i1_pic_order_cnt_type, return_status, "pic_order_cnt_type");
517*495ae853SAndroid Build Coastguard Worker 
518*495ae853SAndroid Build Coastguard Worker     if (ps_sps->i1_pic_order_cnt_type == 0)
519*495ae853SAndroid Build Coastguard Worker     {
520*495ae853SAndroid Build Coastguard Worker         /* log2_max_pic_order_cnt_lsb_minus4 */
521*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, (ps_sps->i1_log2_max_pic_order_cnt_lsb - 4), return_status, "log2_max_pic_order_cnt_lsb_minus4");
522*495ae853SAndroid Build Coastguard Worker     }
523*495ae853SAndroid Build Coastguard Worker     else if (ps_sps->i1_pic_order_cnt_type == 1)
524*495ae853SAndroid Build Coastguard Worker     {
525*495ae853SAndroid Build Coastguard Worker         /* delta_pic_order_always_zero_flag */
526*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_sps->i1_delta_pic_order_always_zero_flag, 1, return_status, "delta_pic_order_always_zero_flag");
527*495ae853SAndroid Build Coastguard Worker 
528*495ae853SAndroid Build Coastguard Worker         /* offset_for_non_ref_pic */
529*495ae853SAndroid Build Coastguard Worker         PUT_BITS_SEV(ps_bitstrm, ps_sps->i4_offset_for_non_ref_pic, return_status, "offset_for_non_ref_pic");
530*495ae853SAndroid Build Coastguard Worker 
531*495ae853SAndroid Build Coastguard Worker         /* offset_for_top_to_bottom_field */
532*495ae853SAndroid Build Coastguard Worker         PUT_BITS_SEV(ps_bitstrm, ps_sps->i4_offset_for_top_to_bottom_field, return_status, "offset_for_top_to_bottom_field");
533*495ae853SAndroid Build Coastguard Worker 
534*495ae853SAndroid Build Coastguard Worker         /* num_ref_frames_in_pic_order_cnt_cycle */
535*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_sps->u1_num_ref_frames_in_pic_order_cnt_cycle, return_status, "num_ref_frames_in_pic_order_cnt_cycle");
536*495ae853SAndroid Build Coastguard Worker 
537*495ae853SAndroid Build Coastguard Worker         /* Offset for ref frame */
538*495ae853SAndroid Build Coastguard Worker         for (i=0; i<ps_sps->u1_num_ref_frames_in_pic_order_cnt_cycle; i++)
539*495ae853SAndroid Build Coastguard Worker         {
540*495ae853SAndroid Build Coastguard Worker             /* offset_for_ref_frame */
541*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_sps->ai4_offset_for_ref_frame[i], return_status, "offset_for_ref_frame");
542*495ae853SAndroid Build Coastguard Worker         }
543*495ae853SAndroid Build Coastguard Worker     }
544*495ae853SAndroid Build Coastguard Worker 
545*495ae853SAndroid Build Coastguard Worker     /* num_ref_frames */
546*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_sps->u1_max_num_ref_frames, return_status, "num_ref_frames");
547*495ae853SAndroid Build Coastguard Worker 
548*495ae853SAndroid Build Coastguard Worker     /* gaps_in_frame_num_value_allowed_flag */
549*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->i1_gaps_in_frame_num_value_allowed_flag, 1, return_status, "gaps_in_frame_num_value_allowed_flag");
550*495ae853SAndroid Build Coastguard Worker 
551*495ae853SAndroid Build Coastguard Worker     /* pic_width_in_mbs_minus1 */
552*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_sps->i2_pic_width_in_mbs_minus1, return_status, "pic_width_in_mbs_minus1");
553*495ae853SAndroid Build Coastguard Worker 
554*495ae853SAndroid Build Coastguard Worker     /* pic_height_in_map_units_minus1 */
555*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_sps->i2_pic_height_in_map_units_minus1, return_status, "pic_height_in_map_units_minus1");
556*495ae853SAndroid Build Coastguard Worker 
557*495ae853SAndroid Build Coastguard Worker     /* frame_mbs_only_flag */
558*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->i1_frame_mbs_only_flag, 1, return_status, "frame_mbs_only_flag");
559*495ae853SAndroid Build Coastguard Worker 
560*495ae853SAndroid Build Coastguard Worker     if (!ps_sps->i1_frame_mbs_only_flag)
561*495ae853SAndroid Build Coastguard Worker     {
562*495ae853SAndroid Build Coastguard Worker         /* mb_adaptive_frame_field_flag */
563*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_sps->i1_mb_adaptive_frame_field_flag, 1, return_status, "mb_adaptive_frame_field_flag");
564*495ae853SAndroid Build Coastguard Worker     }
565*495ae853SAndroid Build Coastguard Worker 
566*495ae853SAndroid Build Coastguard Worker     /* direct_8x8_inference_flag */
567*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->i1_direct_8x8_inference_flag, 1, return_status, "direct_8x8_inference_flag");
568*495ae853SAndroid Build Coastguard Worker 
569*495ae853SAndroid Build Coastguard Worker     /* frame_cropping_flag */
570*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->i1_frame_cropping_flag, 1, return_status, "frame_cropping_flag");
571*495ae853SAndroid Build Coastguard Worker 
572*495ae853SAndroid Build Coastguard Worker     if (ps_sps->i1_frame_cropping_flag)
573*495ae853SAndroid Build Coastguard Worker     {
574*495ae853SAndroid Build Coastguard Worker         /* frame_crop_left_offset */
575*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_sps->i2_frame_crop_left_offset, return_status, "frame_crop_left_offset");
576*495ae853SAndroid Build Coastguard Worker 
577*495ae853SAndroid Build Coastguard Worker         /* frame_crop_right_offset */
578*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_sps->i2_frame_crop_right_offset, return_status, "frame_crop_right_offset");
579*495ae853SAndroid Build Coastguard Worker 
580*495ae853SAndroid Build Coastguard Worker         /* frame_crop_top_offset */
581*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_sps->i2_frame_crop_top_offset, return_status, "frame_crop_top_offset");
582*495ae853SAndroid Build Coastguard Worker 
583*495ae853SAndroid Build Coastguard Worker         /* frame_crop_bottom_offset */
584*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_sps->i2_frame_crop_bottom_offset, return_status, "frame_crop_bottom_offset");
585*495ae853SAndroid Build Coastguard Worker     }
586*495ae853SAndroid Build Coastguard Worker 
587*495ae853SAndroid Build Coastguard Worker     /* vui_parameters_present_flag */
588*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->i1_vui_parameters_present_flag, 1, return_status, "vui_parameters_present_flag");
589*495ae853SAndroid Build Coastguard Worker 
590*495ae853SAndroid Build Coastguard Worker     if (ps_sps->i1_vui_parameters_present_flag)
591*495ae853SAndroid Build Coastguard Worker     {
592*495ae853SAndroid Build Coastguard Worker         /* Add vui parameters to the bitstream */;
593*495ae853SAndroid Build Coastguard Worker         return_status = ih264e_generate_vui(ps_bitstrm, ps_vui);
594*495ae853SAndroid Build Coastguard Worker         if(return_status != IH264E_SUCCESS)
595*495ae853SAndroid Build Coastguard Worker         {
596*495ae853SAndroid Build Coastguard Worker             return return_status;
597*495ae853SAndroid Build Coastguard Worker         }
598*495ae853SAndroid Build Coastguard Worker     }
599*495ae853SAndroid Build Coastguard Worker 
600*495ae853SAndroid Build Coastguard Worker     /* rbsp trailing bits */
601*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_rbsp_trailing_bits(ps_bitstrm);
602*495ae853SAndroid Build Coastguard Worker 
603*495ae853SAndroid Build Coastguard Worker     return return_status;
604*495ae853SAndroid Build Coastguard Worker }
605*495ae853SAndroid Build Coastguard Worker 
606*495ae853SAndroid Build Coastguard Worker /**
607*495ae853SAndroid Build Coastguard Worker ******************************************************************************
608*495ae853SAndroid Build Coastguard Worker *
609*495ae853SAndroid Build Coastguard Worker * @brief Generates PPS (Picture Parameter Set)
610*495ae853SAndroid Build Coastguard Worker *
611*495ae853SAndroid Build Coastguard Worker * @par   Description
612*495ae853SAndroid Build Coastguard Worker *  Generate Picture Parameter Set as per Section 7.3.2.2
613*495ae853SAndroid Build Coastguard Worker *
614*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_bitstrm
615*495ae853SAndroid Build Coastguard Worker *  pointer to bitstream context (handle)
616*495ae853SAndroid Build Coastguard Worker *
617*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_pps
618*495ae853SAndroid Build Coastguard Worker *  pointer to structure containing PPS data
619*495ae853SAndroid Build Coastguard Worker *
620*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
621*495ae853SAndroid Build Coastguard Worker *
622*495ae853SAndroid Build Coastguard Worker ******************************************************************************
623*495ae853SAndroid Build Coastguard Worker */
ih264e_generate_pps(bitstrm_t * ps_bitstrm,pps_t * ps_pps,sps_t * ps_sps)624*495ae853SAndroid Build Coastguard Worker WORD32 ih264e_generate_pps(bitstrm_t *ps_bitstrm, pps_t *ps_pps, sps_t *ps_sps)
625*495ae853SAndroid Build Coastguard Worker {
626*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
627*495ae853SAndroid Build Coastguard Worker 
628*495ae853SAndroid Build Coastguard Worker     /* Insert the NAL start code */
629*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
630*495ae853SAndroid Build Coastguard Worker     if(return_status != IH264E_SUCCESS)
631*495ae853SAndroid Build Coastguard Worker     {
632*495ae853SAndroid Build Coastguard Worker         return return_status;
633*495ae853SAndroid Build Coastguard Worker     }
634*495ae853SAndroid Build Coastguard Worker 
635*495ae853SAndroid Build Coastguard Worker     /* Insert Nal Unit Header */
636*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, NAL_PPS_FIRST_BYTE, 8, return_status, "pps_header");
637*495ae853SAndroid Build Coastguard Worker 
638*495ae853SAndroid Build Coastguard Worker     /* pic_parameter_set_id */
639*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_pps->u1_pps_id, return_status, "pic_parameter_set_id");
640*495ae853SAndroid Build Coastguard Worker 
641*495ae853SAndroid Build Coastguard Worker     /* seq_parameter_set_id */
642*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_pps->u1_sps_id, return_status, "seq_parameter_set_id");
643*495ae853SAndroid Build Coastguard Worker 
644*495ae853SAndroid Build Coastguard Worker     /* Entropy coding : 0-VLC; 1 - CABAC */
645*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_pps->u1_entropy_coding_mode_flag, 1, return_status, "Entropy coding : 0-VLC; 1 - CABAC");
646*495ae853SAndroid Build Coastguard Worker 
647*495ae853SAndroid Build Coastguard Worker     /* Pic order present flag */
648*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_pps->u1_pic_order_present_flag, 1, return_status, "Pic order present flag");
649*495ae853SAndroid Build Coastguard Worker 
650*495ae853SAndroid Build Coastguard Worker     /* Number of slice groups */
651*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_pps->u1_num_slice_groups - 1, return_status, "Number of slice groups");
652*495ae853SAndroid Build Coastguard Worker 
653*495ae853SAndroid Build Coastguard Worker     if (ps_pps->u1_num_slice_groups > 1)
654*495ae853SAndroid Build Coastguard Worker     {
655*495ae853SAndroid Build Coastguard Worker         /* TODO_LATER: Currently the number of slice groups minus 1 is 0.
656*495ae853SAndroid Build Coastguard Worker          * If this is not the case, we have to add Slice group map type to the bit stream*/
657*495ae853SAndroid Build Coastguard Worker     }
658*495ae853SAndroid Build Coastguard Worker 
659*495ae853SAndroid Build Coastguard Worker     /* num_ref_idx_l0_default_active_minus1 */
660*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_pps->i1_num_ref_idx_l0_default_active - 1, return_status, "num_ref_idx_l0_default_active_minus1");
661*495ae853SAndroid Build Coastguard Worker 
662*495ae853SAndroid Build Coastguard Worker     /* num_ref_idx_l1_default_active_minus1 */
663*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_pps->i1_num_ref_idx_l1_default_active - 1, return_status, "num_ref_idx_l1_default_active_minus1");
664*495ae853SAndroid Build Coastguard Worker 
665*495ae853SAndroid Build Coastguard Worker     /* weighted_pred_flag */
666*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_pps->i1_weighted_pred_flag, 1, return_status, "weighted_pred_flag");
667*495ae853SAndroid Build Coastguard Worker 
668*495ae853SAndroid Build Coastguard Worker     /* weighted_bipred_flag */
669*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_pps->i1_weighted_bipred_idc, 2, return_status, "weighted_bipred_idc");
670*495ae853SAndroid Build Coastguard Worker 
671*495ae853SAndroid Build Coastguard Worker     /* pic_init_qp_minus26 */
672*495ae853SAndroid Build Coastguard Worker     PUT_BITS_SEV(ps_bitstrm, ps_pps->i1_pic_init_qp - 26, return_status, "pic_init_qp_minus26");
673*495ae853SAndroid Build Coastguard Worker 
674*495ae853SAndroid Build Coastguard Worker     /* pic_init_qs_minus26 */
675*495ae853SAndroid Build Coastguard Worker     PUT_BITS_SEV(ps_bitstrm, ps_pps->i1_pic_init_qs - 26, return_status, "pic_init_qs_minus26");
676*495ae853SAndroid Build Coastguard Worker 
677*495ae853SAndroid Build Coastguard Worker     /* chroma_qp_index_offset */
678*495ae853SAndroid Build Coastguard Worker     PUT_BITS_SEV(ps_bitstrm, ps_pps->i1_chroma_qp_index_offset, return_status, "chroma_qp_index_offset");
679*495ae853SAndroid Build Coastguard Worker 
680*495ae853SAndroid Build Coastguard Worker     /* deblocking_filter_control_present_flag */
681*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_pps->i1_deblocking_filter_control_present_flag, 1, return_status, "deblocking_filter_control_present_flag");
682*495ae853SAndroid Build Coastguard Worker 
683*495ae853SAndroid Build Coastguard Worker     /* constrained_intra_pred_flag */
684*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_pps->i1_constrained_intra_pred_flag, 1, return_status, "constrained_intra_pred_flag");
685*495ae853SAndroid Build Coastguard Worker 
686*495ae853SAndroid Build Coastguard Worker     /*redundant_pic_cnt_present_flag */
687*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_pps->i1_redundant_pic_cnt_present_flag, 1, return_status, "redundant_pic_cnt_present_flag");
688*495ae853SAndroid Build Coastguard Worker 
689*495ae853SAndroid Build Coastguard Worker     if (ps_sps->u1_profile_idc >= IH264_PROFILE_HIGH)
690*495ae853SAndroid Build Coastguard Worker     {
691*495ae853SAndroid Build Coastguard Worker         /* transform_8x8_mode_flag */
692*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_pps->i1_transform_8x8_mode_flag, 1, return_status, "transform_8x8_mode_flag");
693*495ae853SAndroid Build Coastguard Worker 
694*495ae853SAndroid Build Coastguard Worker         /* pic_scaling_matrix_present_flag */
695*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_pps->i1_pic_scaling_matrix_present_flag, 1, return_status, "pic_scaling_matrix_present_flag");
696*495ae853SAndroid Build Coastguard Worker 
697*495ae853SAndroid Build Coastguard Worker         if(ps_pps->i1_pic_scaling_matrix_present_flag)
698*495ae853SAndroid Build Coastguard Worker         {
699*495ae853SAndroid Build Coastguard Worker             /* TODO_LATER: Will be enabled once scaling list support is added */
700*495ae853SAndroid Build Coastguard Worker         }
701*495ae853SAndroid Build Coastguard Worker 
702*495ae853SAndroid Build Coastguard Worker         /* Second chroma QP offset */
703*495ae853SAndroid Build Coastguard Worker         PUT_BITS_SEV(ps_bitstrm, ps_pps->i1_second_chroma_qp_index_offset, return_status, "Second chroma QP offset");
704*495ae853SAndroid Build Coastguard Worker     }
705*495ae853SAndroid Build Coastguard Worker 
706*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_rbsp_trailing_bits(ps_bitstrm);
707*495ae853SAndroid Build Coastguard Worker 
708*495ae853SAndroid Build Coastguard Worker     return return_status;
709*495ae853SAndroid Build Coastguard Worker }
710*495ae853SAndroid Build Coastguard Worker 
711*495ae853SAndroid Build Coastguard Worker /**
712*495ae853SAndroid Build Coastguard Worker ******************************************************************************
713*495ae853SAndroid Build Coastguard Worker *
714*495ae853SAndroid Build Coastguard Worker * @brief Generates SEI (Supplemental Enhancement Information)
715*495ae853SAndroid Build Coastguard Worker *
716*495ae853SAndroid Build Coastguard Worker * @par   Description
717*495ae853SAndroid Build Coastguard Worker *  This function generates Supplemental Enhancement Information header as per the spec
718*495ae853SAndroid Build Coastguard Worker *
719*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_bitstrm
720*495ae853SAndroid Build Coastguard Worker *  pointer to bitstream context (handle)
721*495ae853SAndroid Build Coastguard Worker *
722*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_sei
723*495ae853SAndroid Build Coastguard Worker *  pointer to structure containing SEI data
724*495ae853SAndroid Build Coastguard Worker *
725*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
726*495ae853SAndroid Build Coastguard Worker *
727*495ae853SAndroid Build Coastguard Worker ******************************************************************************
728*495ae853SAndroid Build Coastguard Worker */
ih264e_generate_sei(bitstrm_t * ps_bitstrm,sei_params_t * ps_sei,UWORD32 u4_insert_per_idr)729*495ae853SAndroid Build Coastguard Worker IH264E_ERROR_T ih264e_generate_sei(bitstrm_t *ps_bitstrm, sei_params_t *ps_sei,
730*495ae853SAndroid Build Coastguard Worker                                                         UWORD32 u4_insert_per_idr)
731*495ae853SAndroid Build Coastguard Worker {
732*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
733*495ae853SAndroid Build Coastguard Worker     WORD8  i1_nal_unit_type = NAL_SEI;
734*495ae853SAndroid Build Coastguard Worker     WORD8  i1_nal_ref_idc = 0;
735*495ae853SAndroid Build Coastguard Worker 
736*495ae853SAndroid Build Coastguard Worker     /* Insert Start Code */
737*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
738*495ae853SAndroid Build Coastguard Worker     if(return_status != IH264E_SUCCESS)
739*495ae853SAndroid Build Coastguard Worker     {
740*495ae853SAndroid Build Coastguard Worker         return return_status;
741*495ae853SAndroid Build Coastguard Worker     }
742*495ae853SAndroid Build Coastguard Worker 
743*495ae853SAndroid Build Coastguard Worker     /* Insert Nal Unit Header */
744*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_generate_nal_unit_header(ps_bitstrm,
745*495ae853SAndroid Build Coastguard Worker                                                     i1_nal_unit_type, i1_nal_ref_idc);
746*495ae853SAndroid Build Coastguard Worker     if(return_status != IH264E_SUCCESS)
747*495ae853SAndroid Build Coastguard Worker     {
748*495ae853SAndroid Build Coastguard Worker         return return_status;
749*495ae853SAndroid Build Coastguard Worker     }
750*495ae853SAndroid Build Coastguard Worker     /* Mastering Display Color SEI */
751*495ae853SAndroid Build Coastguard Worker     if(1 == ps_sei->u1_sei_mdcv_params_present_flag && u4_insert_per_idr)
752*495ae853SAndroid Build Coastguard Worker     {
753*495ae853SAndroid Build Coastguard Worker         return_status = ih264e_put_sei_msg(IH264_SEI_MASTERING_DISP_COL_VOL,
754*495ae853SAndroid Build Coastguard Worker                                             ps_sei, ps_bitstrm);
755*495ae853SAndroid Build Coastguard Worker         if(return_status != IH264E_SUCCESS)
756*495ae853SAndroid Build Coastguard Worker         {
757*495ae853SAndroid Build Coastguard Worker             return return_status;
758*495ae853SAndroid Build Coastguard Worker         }
759*495ae853SAndroid Build Coastguard Worker     }
760*495ae853SAndroid Build Coastguard Worker 
761*495ae853SAndroid Build Coastguard Worker     /* Content Light Level Information*/
762*495ae853SAndroid Build Coastguard Worker     if(1 == ps_sei->u1_sei_cll_params_present_flag && u4_insert_per_idr)
763*495ae853SAndroid Build Coastguard Worker     {
764*495ae853SAndroid Build Coastguard Worker         return_status = ih264e_put_sei_msg(IH264_SEI_CONTENT_LIGHT_LEVEL_DATA,
765*495ae853SAndroid Build Coastguard Worker                                             ps_sei, ps_bitstrm);
766*495ae853SAndroid Build Coastguard Worker         if(return_status != IH264E_SUCCESS)
767*495ae853SAndroid Build Coastguard Worker         {
768*495ae853SAndroid Build Coastguard Worker             return return_status;
769*495ae853SAndroid Build Coastguard Worker         }
770*495ae853SAndroid Build Coastguard Worker     }
771*495ae853SAndroid Build Coastguard Worker 
772*495ae853SAndroid Build Coastguard Worker     /* Ambient viewing environment SEI */
773*495ae853SAndroid Build Coastguard Worker     if(1 == ps_sei->u1_sei_ave_params_present_flag && u4_insert_per_idr)
774*495ae853SAndroid Build Coastguard Worker     {
775*495ae853SAndroid Build Coastguard Worker         return_status = ih264e_put_sei_msg(IH264_SEI_AMBIENT_VIEWING_ENVIRONMENT,
776*495ae853SAndroid Build Coastguard Worker                                             ps_sei, ps_bitstrm);
777*495ae853SAndroid Build Coastguard Worker         if(return_status != IH264E_SUCCESS)
778*495ae853SAndroid Build Coastguard Worker         {
779*495ae853SAndroid Build Coastguard Worker             return return_status;
780*495ae853SAndroid Build Coastguard Worker         }
781*495ae853SAndroid Build Coastguard Worker     }
782*495ae853SAndroid Build Coastguard Worker 
783*495ae853SAndroid Build Coastguard Worker     /* Content color volume Information*/
784*495ae853SAndroid Build Coastguard Worker     if(1 == ps_sei->u1_sei_ccv_params_present_flag)
785*495ae853SAndroid Build Coastguard Worker     {
786*495ae853SAndroid Build Coastguard Worker         return_status = ih264e_put_sei_msg(IH264_SEI_CONTENT_COLOR_VOLUME,
787*495ae853SAndroid Build Coastguard Worker                                             ps_sei, ps_bitstrm);
788*495ae853SAndroid Build Coastguard Worker         if(return_status != IH264E_SUCCESS)
789*495ae853SAndroid Build Coastguard Worker         {
790*495ae853SAndroid Build Coastguard Worker             return return_status;
791*495ae853SAndroid Build Coastguard Worker         }
792*495ae853SAndroid Build Coastguard Worker     }
793*495ae853SAndroid Build Coastguard Worker 
794*495ae853SAndroid Build Coastguard Worker     /* Shutter Interval Information*/
795*495ae853SAndroid Build Coastguard Worker     if(1 == ps_sei->u1_sei_sii_params_present_flag)
796*495ae853SAndroid Build Coastguard Worker     {
797*495ae853SAndroid Build Coastguard Worker         return_status = ih264e_put_sei_msg(IH264_SEI_SHUTTER_INTERVAL_INFO, ps_sei, ps_bitstrm);
798*495ae853SAndroid Build Coastguard Worker         if(return_status != IH264E_SUCCESS)
799*495ae853SAndroid Build Coastguard Worker         {
800*495ae853SAndroid Build Coastguard Worker             return return_status;
801*495ae853SAndroid Build Coastguard Worker         }
802*495ae853SAndroid Build Coastguard Worker     }
803*495ae853SAndroid Build Coastguard Worker 
804*495ae853SAndroid Build Coastguard Worker     /* rbsp trailing bits */
805*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_rbsp_trailing_bits(ps_bitstrm);
806*495ae853SAndroid Build Coastguard Worker 
807*495ae853SAndroid Build Coastguard Worker     return return_status;
808*495ae853SAndroid Build Coastguard Worker }
809*495ae853SAndroid Build Coastguard Worker 
810*495ae853SAndroid Build Coastguard Worker /**
811*495ae853SAndroid Build Coastguard Worker ******************************************************************************
812*495ae853SAndroid Build Coastguard Worker *
813*495ae853SAndroid Build Coastguard Worker * @brief Generates Slice Header
814*495ae853SAndroid Build Coastguard Worker *
815*495ae853SAndroid Build Coastguard Worker * @par   Description
816*495ae853SAndroid Build Coastguard Worker *  Generate Slice Header as per Section 7.3.5.1
817*495ae853SAndroid Build Coastguard Worker *
818*495ae853SAndroid Build Coastguard Worker * @param[inout]   ps_bitstrm
819*495ae853SAndroid Build Coastguard Worker *  pointer to bitstream context for generating slice header
820*495ae853SAndroid Build Coastguard Worker *
821*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_slice_hdr
822*495ae853SAndroid Build Coastguard Worker *  pointer to slice header params
823*495ae853SAndroid Build Coastguard Worker *
824*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_pps
825*495ae853SAndroid Build Coastguard Worker *  pointer to pps params referred by slice
826*495ae853SAndroid Build Coastguard Worker *
827*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_sps
828*495ae853SAndroid Build Coastguard Worker *  pointer to sps params referred by slice
829*495ae853SAndroid Build Coastguard Worker *
830*495ae853SAndroid Build Coastguard Worker * @param[out]   ps_dup_bit_strm_ent_offset
831*495ae853SAndroid Build Coastguard Worker *  Bitstream struct to store bitstream state
832*495ae853SAndroid Build Coastguard Worker *
833*495ae853SAndroid Build Coastguard Worker * @param[out]   pu4_first_slice_start_offset
834*495ae853SAndroid Build Coastguard Worker *  first slice offset is returned
835*495ae853SAndroid Build Coastguard Worker *
836*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
837*495ae853SAndroid Build Coastguard Worker *
838*495ae853SAndroid Build Coastguard Worker ******************************************************************************
839*495ae853SAndroid Build Coastguard Worker */
ih264e_generate_slice_header(bitstrm_t * ps_bitstrm,slice_header_t * ps_slice_hdr,pps_t * ps_pps,sps_t * ps_sps)840*495ae853SAndroid Build Coastguard Worker WORD32 ih264e_generate_slice_header(bitstrm_t *ps_bitstrm,
841*495ae853SAndroid Build Coastguard Worker                                     slice_header_t *ps_slice_hdr,
842*495ae853SAndroid Build Coastguard Worker                                     pps_t *ps_pps,
843*495ae853SAndroid Build Coastguard Worker                                     sps_t *ps_sps)
844*495ae853SAndroid Build Coastguard Worker {
845*495ae853SAndroid Build Coastguard Worker 
846*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
847*495ae853SAndroid Build Coastguard Worker 
848*495ae853SAndroid Build Coastguard Worker     /* Insert start code */
849*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
850*495ae853SAndroid Build Coastguard Worker     if(return_status != IH264E_SUCCESS)
851*495ae853SAndroid Build Coastguard Worker     {
852*495ae853SAndroid Build Coastguard Worker         return return_status;
853*495ae853SAndroid Build Coastguard Worker     }
854*495ae853SAndroid Build Coastguard Worker     /* Insert Nal Unit Header */
855*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_generate_nal_unit_header(ps_bitstrm, ps_slice_hdr->i1_nal_unit_type, ps_slice_hdr->i1_nal_unit_idc);
856*495ae853SAndroid Build Coastguard Worker     if(return_status != IH264E_SUCCESS)
857*495ae853SAndroid Build Coastguard Worker     {
858*495ae853SAndroid Build Coastguard Worker         return return_status;
859*495ae853SAndroid Build Coastguard Worker     }
860*495ae853SAndroid Build Coastguard Worker     /* first_mb_in_slice */
861*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u2_first_mb_in_slice, return_status, "first_mb_in_slice");
862*495ae853SAndroid Build Coastguard Worker 
863*495ae853SAndroid Build Coastguard Worker     /* slice_type */
864*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u1_slice_type, return_status, "slice_type");
865*495ae853SAndroid Build Coastguard Worker 
866*495ae853SAndroid Build Coastguard Worker     /* pic_parameter_set_id */
867*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u1_pps_id, return_status, "pic_parameter_set_id");
868*495ae853SAndroid Build Coastguard Worker 
869*495ae853SAndroid Build Coastguard Worker     /* frame_num */
870*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_slice_hdr->i4_frame_num, ps_sps->i1_log2_max_frame_num, return_status, "frame_num");
871*495ae853SAndroid Build Coastguard Worker 
872*495ae853SAndroid Build Coastguard Worker     if (!ps_sps->i1_frame_mbs_only_flag)
873*495ae853SAndroid Build Coastguard Worker     {
874*495ae853SAndroid Build Coastguard Worker         /* field_pic_flag */
875*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_slice_hdr->i1_field_pic_flag, 1, return_status, "field_pic_flag");
876*495ae853SAndroid Build Coastguard Worker 
877*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->i1_field_pic_flag)
878*495ae853SAndroid Build Coastguard Worker         {
879*495ae853SAndroid Build Coastguard Worker             /* bottom_field_flag */
880*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_hdr->i1_bottom_field_flag, 1, return_status, "bottom_field_flag");
881*495ae853SAndroid Build Coastguard Worker         }
882*495ae853SAndroid Build Coastguard Worker     }
883*495ae853SAndroid Build Coastguard Worker 
884*495ae853SAndroid Build Coastguard Worker     if (ps_slice_hdr->i1_nal_unit_type == 5)
885*495ae853SAndroid Build Coastguard Worker     {
886*495ae853SAndroid Build Coastguard Worker         /* u2_idr_pic_id */
887*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u2_idr_pic_id, return_status, "u2_idr_pic_id");
888*495ae853SAndroid Build Coastguard Worker     }
889*495ae853SAndroid Build Coastguard Worker 
890*495ae853SAndroid Build Coastguard Worker     if (ps_sps->i1_pic_order_cnt_type == 0)
891*495ae853SAndroid Build Coastguard Worker     {
892*495ae853SAndroid Build Coastguard Worker         /* pic_order_cnt_lsb */
893*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_slice_hdr->i4_pic_order_cnt_lsb, ps_sps->i1_log2_max_pic_order_cnt_lsb, return_status, "pic_order_cnt_lsb");
894*495ae853SAndroid Build Coastguard Worker 
895*495ae853SAndroid Build Coastguard Worker         if(ps_pps->u1_pic_order_present_flag && !ps_slice_hdr->i1_field_pic_flag)
896*495ae853SAndroid Build Coastguard Worker         {
897*495ae853SAndroid Build Coastguard Worker             /* delta_pic_order_cnt_bottom */
898*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->i4_delta_pic_order_cnt_bottom, return_status, "delta_pic_order_cnt_bottom");
899*495ae853SAndroid Build Coastguard Worker         }
900*495ae853SAndroid Build Coastguard Worker     }
901*495ae853SAndroid Build Coastguard Worker 
902*495ae853SAndroid Build Coastguard Worker     if (ps_sps->i1_pic_order_cnt_type == 1 && !ps_sps->i1_delta_pic_order_always_zero_flag)
903*495ae853SAndroid Build Coastguard Worker     {
904*495ae853SAndroid Build Coastguard Worker         /* delta_pic_order_cnt[0] */
905*495ae853SAndroid Build Coastguard Worker         PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->ai4_delta_pic_order_cnt[0], return_status, "delta_pic_order_cnt[0]");
906*495ae853SAndroid Build Coastguard Worker 
907*495ae853SAndroid Build Coastguard Worker         if (ps_pps->u1_pic_order_present_flag && !ps_slice_hdr->i1_field_pic_flag)
908*495ae853SAndroid Build Coastguard Worker         {
909*495ae853SAndroid Build Coastguard Worker             /* delta_pic_order_cnt[1] */
910*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->ai4_delta_pic_order_cnt[1], return_status, "delta_pic_order_cnt[1]");
911*495ae853SAndroid Build Coastguard Worker         }
912*495ae853SAndroid Build Coastguard Worker     }
913*495ae853SAndroid Build Coastguard Worker 
914*495ae853SAndroid Build Coastguard Worker     if (ps_pps->i1_redundant_pic_cnt_present_flag)
915*495ae853SAndroid Build Coastguard Worker     {
916*495ae853SAndroid Build Coastguard Worker         /* redundant_pic_cnt */
917*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u1_redundant_pic_cnt, return_status, "redundant_pic_cnt");
918*495ae853SAndroid Build Coastguard Worker     }
919*495ae853SAndroid Build Coastguard Worker 
920*495ae853SAndroid Build Coastguard Worker     if (ps_slice_hdr->u1_slice_type == BSLICE)
921*495ae853SAndroid Build Coastguard Worker     {
922*495ae853SAndroid Build Coastguard Worker         /* direct_spatial_mv_pred_flag */
923*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_direct_spatial_mv_pred_flag, 1, return_status, "direct_spatial_mv_pred_flag");
924*495ae853SAndroid Build Coastguard Worker     }
925*495ae853SAndroid Build Coastguard Worker 
926*495ae853SAndroid Build Coastguard Worker     if (ps_slice_hdr->u1_slice_type == PSLICE || ps_slice_hdr->u1_slice_type == SPSLICE || ps_slice_hdr->u1_slice_type == BSLICE)
927*495ae853SAndroid Build Coastguard Worker     {
928*495ae853SAndroid Build Coastguard Worker         /* num_ref_idx_active_override_flag */
929*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_num_ref_idx_active_override_flag, 1, return_status, "num_ref_idx_active_override_flag");
930*495ae853SAndroid Build Coastguard Worker 
931*495ae853SAndroid Build Coastguard Worker         if (ps_slice_hdr->u1_num_ref_idx_active_override_flag)
932*495ae853SAndroid Build Coastguard Worker         {
933*495ae853SAndroid Build Coastguard Worker             /* num_ref_idx_l0_active_minus1 */
934*495ae853SAndroid Build Coastguard Worker             PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->i1_num_ref_idx_l0_active - 1, return_status, "num_ref_idx_l0_active_minus1");
935*495ae853SAndroid Build Coastguard Worker 
936*495ae853SAndroid Build Coastguard Worker             if (ps_slice_hdr->u1_slice_type == BSLICE)
937*495ae853SAndroid Build Coastguard Worker             {
938*495ae853SAndroid Build Coastguard Worker                 /* num_ref_idx_l1_active_minus1 */
939*495ae853SAndroid Build Coastguard Worker                 PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->i1_num_ref_idx_l1_active - 1, return_status, "num_ref_idx_l1_active_minus1");
940*495ae853SAndroid Build Coastguard Worker             }
941*495ae853SAndroid Build Coastguard Worker         }
942*495ae853SAndroid Build Coastguard Worker     }
943*495ae853SAndroid Build Coastguard Worker 
944*495ae853SAndroid Build Coastguard Worker     /* ref_idx_reordering */
945*495ae853SAndroid Build Coastguard Worker     /* TODO: ref_idx_reordering */
946*495ae853SAndroid Build Coastguard Worker     if ((ps_slice_hdr->u1_slice_type != ISLICE) && (ps_slice_hdr->u1_slice_type != SISLICE))
947*495ae853SAndroid Build Coastguard Worker     {
948*495ae853SAndroid Build Coastguard Worker         /* ref_pic_list_reordering_flag_l0 */
949*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_ref_idx_reordering_flag_l0, 1, return_status, "ref_pic_list_reordering_flag_l0");
950*495ae853SAndroid Build Coastguard Worker 
951*495ae853SAndroid Build Coastguard Worker         if (ps_slice_hdr->u1_ref_idx_reordering_flag_l0)
952*495ae853SAndroid Build Coastguard Worker         {
953*495ae853SAndroid Build Coastguard Worker 
954*495ae853SAndroid Build Coastguard Worker         }
955*495ae853SAndroid Build Coastguard Worker     }
956*495ae853SAndroid Build Coastguard Worker 
957*495ae853SAndroid Build Coastguard Worker     if (ps_slice_hdr->u1_slice_type == BSLICE)
958*495ae853SAndroid Build Coastguard Worker     {
959*495ae853SAndroid Build Coastguard Worker         /* ref_pic_list_reordering_flag_l1 */
960*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_ref_idx_reordering_flag_l1, 1, return_status, "ref_pic_list_reordering_flag_l1");
961*495ae853SAndroid Build Coastguard Worker 
962*495ae853SAndroid Build Coastguard Worker         if (ps_slice_hdr->u1_ref_idx_reordering_flag_l1)
963*495ae853SAndroid Build Coastguard Worker         {
964*495ae853SAndroid Build Coastguard Worker 
965*495ae853SAndroid Build Coastguard Worker         }
966*495ae853SAndroid Build Coastguard Worker     }
967*495ae853SAndroid Build Coastguard Worker 
968*495ae853SAndroid Build Coastguard Worker     if ((ps_pps->i1_weighted_pred_flag &&
969*495ae853SAndroid Build Coastguard Worker                     (ps_slice_hdr->u1_slice_type == PSLICE || ps_slice_hdr->u1_slice_type == SPSLICE)) ||
970*495ae853SAndroid Build Coastguard Worker                     (ps_slice_hdr->u1_slice_type == BSLICE && ps_pps->i1_weighted_bipred_idc == 1))
971*495ae853SAndroid Build Coastguard Worker     {
972*495ae853SAndroid Build Coastguard Worker         /* TODO_LATER: Currently there is no support for weighted prediction.
973*495ae853SAndroid Build Coastguard Worker          This needs to be updated when the support is added */
974*495ae853SAndroid Build Coastguard Worker     }
975*495ae853SAndroid Build Coastguard Worker 
976*495ae853SAndroid Build Coastguard Worker     if (ps_slice_hdr->i1_nal_unit_idc != 0)
977*495ae853SAndroid Build Coastguard Worker     {
978*495ae853SAndroid Build Coastguard Worker         if (ps_slice_hdr->i1_nal_unit_type == 5)
979*495ae853SAndroid Build Coastguard Worker         {
980*495ae853SAndroid Build Coastguard Worker             /* no_output_of_prior_pics_flag  */
981*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_no_output_of_prior_pics_flag , 1, return_status, "no_output_of_prior_pics_flag ");
982*495ae853SAndroid Build Coastguard Worker 
983*495ae853SAndroid Build Coastguard Worker             /* long_term_reference_flag  */
984*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_long_term_reference_flag , 1, return_status, "long_term_reference_flag ");
985*495ae853SAndroid Build Coastguard Worker         }
986*495ae853SAndroid Build Coastguard Worker         else
987*495ae853SAndroid Build Coastguard Worker         {
988*495ae853SAndroid Build Coastguard Worker             /* adaptive_ref_pic_marking_mode_flag  */
989*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_adaptive_ref_pic_marking_mode_flag , 1, return_status, "adaptive_ref_pic_marking_mode_flag ");
990*495ae853SAndroid Build Coastguard Worker 
991*495ae853SAndroid Build Coastguard Worker             if (ps_slice_hdr->u1_adaptive_ref_pic_marking_mode_flag)
992*495ae853SAndroid Build Coastguard Worker             {
993*495ae853SAndroid Build Coastguard Worker                 /* TODO: if the reference picture marking mode is adaptive
994*495ae853SAndroid Build Coastguard Worker                  add these fields in the bit-stream */
995*495ae853SAndroid Build Coastguard Worker             }
996*495ae853SAndroid Build Coastguard Worker         }
997*495ae853SAndroid Build Coastguard Worker     }
998*495ae853SAndroid Build Coastguard Worker 
999*495ae853SAndroid Build Coastguard Worker     if (ps_slice_hdr->u1_entropy_coding_mode_flag && ps_slice_hdr->u1_slice_type != ISLICE &&
1000*495ae853SAndroid Build Coastguard Worker                     ps_slice_hdr->u1_slice_type != SISLICE)
1001*495ae853SAndroid Build Coastguard Worker     {
1002*495ae853SAndroid Build Coastguard Worker         /* cabac_init_idc */
1003*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->i1_cabac_init_idc, return_status, "cabac_init_idc");
1004*495ae853SAndroid Build Coastguard Worker     }
1005*495ae853SAndroid Build Coastguard Worker 
1006*495ae853SAndroid Build Coastguard Worker     /* slice_qp_delta */
1007*495ae853SAndroid Build Coastguard Worker     PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->i1_slice_qp - ps_pps->i1_pic_init_qp, return_status, "slice_qp_delta");
1008*495ae853SAndroid Build Coastguard Worker 
1009*495ae853SAndroid Build Coastguard Worker     if (ps_slice_hdr->u1_slice_type == SPSLICE || ps_slice_hdr->u1_slice_type == SISLICE)
1010*495ae853SAndroid Build Coastguard Worker     {
1011*495ae853SAndroid Build Coastguard Worker         if (ps_slice_hdr->u1_slice_type == SPSLICE)
1012*495ae853SAndroid Build Coastguard Worker         {
1013*495ae853SAndroid Build Coastguard Worker             /* sp_for_switch_flag */
1014*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_sp_for_switch_flag , 1, return_status, "sp_for_switch_flag");
1015*495ae853SAndroid Build Coastguard Worker         }
1016*495ae853SAndroid Build Coastguard Worker         /* slice_qs_delta */
1017*495ae853SAndroid Build Coastguard Worker         PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->u1_slice_qs - ps_pps->i1_pic_init_qs, return_status, "slice_qs_delta");
1018*495ae853SAndroid Build Coastguard Worker     }
1019*495ae853SAndroid Build Coastguard Worker 
1020*495ae853SAndroid Build Coastguard Worker     if (ps_pps->i1_deblocking_filter_control_present_flag)
1021*495ae853SAndroid Build Coastguard Worker     {
1022*495ae853SAndroid Build Coastguard Worker         /* disable_deblocking_filter_idc */
1023*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u1_disable_deblocking_filter_idc, return_status, "disable_deblocking_filter_idc");
1024*495ae853SAndroid Build Coastguard Worker 
1025*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->u1_disable_deblocking_filter_idc != 1)
1026*495ae853SAndroid Build Coastguard Worker         {
1027*495ae853SAndroid Build Coastguard Worker             /* slice_alpha_c0_offset_div2 */
1028*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->i1_slice_alpha_c0_offset_div2, return_status, "slice_alpha_c0_offset_div2");
1029*495ae853SAndroid Build Coastguard Worker 
1030*495ae853SAndroid Build Coastguard Worker             /* slice_beta_offset_div2 */
1031*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->i1_slice_beta_offset_div2, return_status, "slice_beta_offset_div2");
1032*495ae853SAndroid Build Coastguard Worker         }
1033*495ae853SAndroid Build Coastguard Worker     }
1034*495ae853SAndroid Build Coastguard Worker 
1035*495ae853SAndroid Build Coastguard Worker     if (ps_slice_hdr->u1_num_slice_groups_minus1 > 0 &&
1036*495ae853SAndroid Build Coastguard Worker                     ps_pps->u1_slice_group_map_type >= 3 &&
1037*495ae853SAndroid Build Coastguard Worker                     ps_pps->u1_slice_group_map_type <= 5)
1038*495ae853SAndroid Build Coastguard Worker     {
1039*495ae853SAndroid Build Coastguard Worker         /* slice_group_change_cycle */
1040*495ae853SAndroid Build Coastguard Worker         /* TODO_LATER: Currently the number of slice groups minus 1 is 0.
1041*495ae853SAndroid Build Coastguard Worker          * If this is not the case, we have to add Slice group map type to the bit stream */
1042*495ae853SAndroid Build Coastguard Worker     }
1043*495ae853SAndroid Build Coastguard Worker 
1044*495ae853SAndroid Build Coastguard Worker     return return_status;
1045*495ae853SAndroid Build Coastguard Worker }
1046*495ae853SAndroid Build Coastguard Worker 
1047*495ae853SAndroid Build Coastguard Worker /**
1048*495ae853SAndroid Build Coastguard Worker ******************************************************************************
1049*495ae853SAndroid Build Coastguard Worker *
1050*495ae853SAndroid Build Coastguard Worker * @brief Populates VUI structure
1051*495ae853SAndroid Build Coastguard Worker *
1052*495ae853SAndroid Build Coastguard Worker * @par   Description
1053*495ae853SAndroid Build Coastguard Worker *  Populates VUI structure for its use in header generation
1054*495ae853SAndroid Build Coastguard Worker *
1055*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_codec
1056*495ae853SAndroid Build Coastguard Worker *  pointer to encoder context
1057*495ae853SAndroid Build Coastguard Worker *
1058*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
1059*495ae853SAndroid Build Coastguard Worker *
1060*495ae853SAndroid Build Coastguard Worker ******************************************************************************
1061*495ae853SAndroid Build Coastguard Worker */
ih264e_populate_vui(codec_t * ps_codec)1062*495ae853SAndroid Build Coastguard Worker IH264E_ERROR_T ih264e_populate_vui(codec_t *ps_codec)
1063*495ae853SAndroid Build Coastguard Worker {
1064*495ae853SAndroid Build Coastguard Worker     /* vui params */
1065*495ae853SAndroid Build Coastguard Worker     vui_t *ps_vui = &ps_codec->s_cfg.s_vui;
1066*495ae853SAndroid Build Coastguard Worker 
1067*495ae853SAndroid Build Coastguard Worker     /* active sps params */
1068*495ae853SAndroid Build Coastguard Worker     sps_t *ps_sps = ps_codec->ps_sps_base + ps_codec->i4_sps_id;
1069*495ae853SAndroid Build Coastguard Worker 
1070*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_nal_hrd_parameters_present_flag = 0;
1071*495ae853SAndroid Build Coastguard Worker 
1072*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_vcl_hrd_parameters_present_flag = 0;
1073*495ae853SAndroid Build Coastguard Worker 
1074*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_bitstream_restriction_flag = 1;
1075*495ae853SAndroid Build Coastguard Worker 
1076*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_motion_vectors_over_pic_boundaries_flag = 1;
1077*495ae853SAndroid Build Coastguard Worker 
1078*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_max_bytes_per_pic_denom = 0;
1079*495ae853SAndroid Build Coastguard Worker 
1080*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_max_bits_per_mb_denom = 0;
1081*495ae853SAndroid Build Coastguard Worker 
1082*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_log2_max_mv_length_horizontal = 16;
1083*495ae853SAndroid Build Coastguard Worker 
1084*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_log2_max_mv_length_vertical = 16;
1085*495ae853SAndroid Build Coastguard Worker 
1086*495ae853SAndroid Build Coastguard Worker     if (ps_codec->s_cfg.u4_num_bframes == 0)
1087*495ae853SAndroid Build Coastguard Worker     {
1088*495ae853SAndroid Build Coastguard Worker         ps_vui->u1_num_reorder_frames = 0;
1089*495ae853SAndroid Build Coastguard Worker     }
1090*495ae853SAndroid Build Coastguard Worker     else
1091*495ae853SAndroid Build Coastguard Worker     {
1092*495ae853SAndroid Build Coastguard Worker         ps_vui->u1_num_reorder_frames = 1;
1093*495ae853SAndroid Build Coastguard Worker     }
1094*495ae853SAndroid Build Coastguard Worker 
1095*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_max_dec_frame_buffering = ps_sps->u1_max_num_ref_frames;
1096*495ae853SAndroid Build Coastguard Worker 
1097*495ae853SAndroid Build Coastguard Worker     return IH264E_SUCCESS;
1098*495ae853SAndroid Build Coastguard Worker }
1099*495ae853SAndroid Build Coastguard Worker 
1100*495ae853SAndroid Build Coastguard Worker /**
1101*495ae853SAndroid Build Coastguard Worker ******************************************************************************
1102*495ae853SAndroid Build Coastguard Worker *
1103*495ae853SAndroid Build Coastguard Worker * @brief Populates sps structure
1104*495ae853SAndroid Build Coastguard Worker *
1105*495ae853SAndroid Build Coastguard Worker * @par   Description
1106*495ae853SAndroid Build Coastguard Worker *  Populates sps structure for its use in header generation
1107*495ae853SAndroid Build Coastguard Worker *
1108*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_codec
1109*495ae853SAndroid Build Coastguard Worker *  pointer to encoder context
1110*495ae853SAndroid Build Coastguard Worker *
1111*495ae853SAndroid Build Coastguard Worker * @param[out]  ps_sps
1112*495ae853SAndroid Build Coastguard Worker *  pointer to sps params that needs to be populated
1113*495ae853SAndroid Build Coastguard Worker *
1114*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
1115*495ae853SAndroid Build Coastguard Worker *
1116*495ae853SAndroid Build Coastguard Worker ******************************************************************************
1117*495ae853SAndroid Build Coastguard Worker */
ih264e_populate_sps(codec_t * ps_codec,sps_t * ps_sps)1118*495ae853SAndroid Build Coastguard Worker IH264E_ERROR_T ih264e_populate_sps(codec_t *ps_codec, sps_t *ps_sps)
1119*495ae853SAndroid Build Coastguard Worker {
1120*495ae853SAndroid Build Coastguard Worker     /* active config parameters */
1121*495ae853SAndroid Build Coastguard Worker     cfg_params_t    *ps_cfg = &(ps_codec->s_cfg);
1122*495ae853SAndroid Build Coastguard Worker 
1123*495ae853SAndroid Build Coastguard Worker //    /* level */
1124*495ae853SAndroid Build Coastguard Worker //    IH264_LEVEL_T   level_idc;
1125*495ae853SAndroid Build Coastguard Worker 
1126*495ae853SAndroid Build Coastguard Worker     /* error_status */
1127*495ae853SAndroid Build Coastguard Worker     IH264E_ERROR_T i4_err_code = IH264E_FAIL;
1128*495ae853SAndroid Build Coastguard Worker 
1129*495ae853SAndroid Build Coastguard Worker     /* profile */
1130*495ae853SAndroid Build Coastguard Worker     /*
1131*495ae853SAndroid Build Coastguard Worker      * Baseline profile supports, 8 bits per sample, 4:2:0 format, CAVLC.
1132*495ae853SAndroid Build Coastguard Worker      * B frames are not allowed. Further, Flexible mb ordering, Redundant slices, Arbitrary slice ordering are supported.
1133*495ae853SAndroid Build Coastguard Worker      * The constrained baseline profile is baseline profile minus ASO, FMO and redundant slices.
1134*495ae853SAndroid Build Coastguard Worker      * To the constrained baseline profile if we add support for B slices, support for encoding interlaced frames,
1135*495ae853SAndroid Build Coastguard Worker      * support for weighted prediction and introduce CABAC entropy coding then we have Main Profile.
1136*495ae853SAndroid Build Coastguard Worker      */
1137*495ae853SAndroid Build Coastguard Worker     if ((ps_cfg->u4_num_bframes) || (ps_cfg->e_content_type != IV_PROGRESSIVE) ||
1138*495ae853SAndroid Build Coastguard Worker         (ps_cfg->u4_entropy_coding_mode == CABAC) || (ps_cfg->u4_weighted_prediction))
1139*495ae853SAndroid Build Coastguard Worker     {
1140*495ae853SAndroid Build Coastguard Worker         ps_sps->u1_profile_idc = IH264_PROFILE_MAIN;
1141*495ae853SAndroid Build Coastguard Worker     }
1142*495ae853SAndroid Build Coastguard Worker     else
1143*495ae853SAndroid Build Coastguard Worker     {
1144*495ae853SAndroid Build Coastguard Worker         ps_sps->u1_profile_idc = IH264_PROFILE_BASELINE;
1145*495ae853SAndroid Build Coastguard Worker     }
1146*495ae853SAndroid Build Coastguard Worker 
1147*495ae853SAndroid Build Coastguard Worker     /* level */
1148*495ae853SAndroid Build Coastguard Worker     ps_sps->u1_level_idc = MAX(ps_cfg->u4_max_level,
1149*495ae853SAndroid Build Coastguard Worker                                (UWORD32)ih264e_get_min_level(ps_cfg->u4_max_wd, ps_cfg->u4_max_ht));
1150*495ae853SAndroid Build Coastguard Worker 
1151*495ae853SAndroid Build Coastguard Worker     /* constrained flags */
1152*495ae853SAndroid Build Coastguard Worker     /*
1153*495ae853SAndroid Build Coastguard Worker      * baseline profile automatically implies set 0 flag
1154*495ae853SAndroid Build Coastguard Worker      */
1155*495ae853SAndroid Build Coastguard Worker     ps_sps->u1_constraint_set0_flag = (ps_sps->u1_profile_idc == IH264_PROFILE_BASELINE);
1156*495ae853SAndroid Build Coastguard Worker     /*
1157*495ae853SAndroid Build Coastguard Worker      * main profile automatically implies set 1 flag
1158*495ae853SAndroid Build Coastguard Worker      * Although the encoder says it supports Baseline profile it actually supports constrained
1159*495ae853SAndroid Build Coastguard Worker      * baseline profile as ASO, FMO and redundant slices are not supported
1160*495ae853SAndroid Build Coastguard Worker      */
1161*495ae853SAndroid Build Coastguard Worker     ps_sps->u1_constraint_set1_flag = (ps_sps->u1_profile_idc <= IH264_PROFILE_MAIN);
1162*495ae853SAndroid Build Coastguard Worker     /*
1163*495ae853SAndroid Build Coastguard Worker      * extended profile is not supported
1164*495ae853SAndroid Build Coastguard Worker      */
1165*495ae853SAndroid Build Coastguard Worker     ps_sps->u1_constraint_set2_flag = 0x00;
1166*495ae853SAndroid Build Coastguard Worker     /*
1167*495ae853SAndroid Build Coastguard Worker      * level 1b or level 11
1168*495ae853SAndroid Build Coastguard Worker      */
1169*495ae853SAndroid Build Coastguard Worker     if (ps_sps->u1_level_idc == IH264_LEVEL_1B)
1170*495ae853SAndroid Build Coastguard Worker     {
1171*495ae853SAndroid Build Coastguard Worker         ps_sps->u1_constraint_set3_flag = 0;
1172*495ae853SAndroid Build Coastguard Worker         ps_sps->u1_level_idc = IH264_LEVEL_11;
1173*495ae853SAndroid Build Coastguard Worker     }
1174*495ae853SAndroid Build Coastguard Worker     else
1175*495ae853SAndroid Build Coastguard Worker     {
1176*495ae853SAndroid Build Coastguard Worker         ps_sps->u1_constraint_set3_flag = 0;
1177*495ae853SAndroid Build Coastguard Worker     }
1178*495ae853SAndroid Build Coastguard Worker 
1179*495ae853SAndroid Build Coastguard Worker     /* active sps id */
1180*495ae853SAndroid Build Coastguard Worker     ps_sps->u1_sps_id = ps_codec->i4_sps_id;
1181*495ae853SAndroid Build Coastguard Worker 
1182*495ae853SAndroid Build Coastguard Worker     if (ps_sps->u1_profile_idc >= IH264_PROFILE_HIGH)
1183*495ae853SAndroid Build Coastguard Worker     {
1184*495ae853SAndroid Build Coastguard Worker         /* chroma format idc */
1185*495ae853SAndroid Build Coastguard Worker         ps_sps->u1_chroma_format_idc = CHROMA_FMT_IDC_YUV420;
1186*495ae853SAndroid Build Coastguard Worker 
1187*495ae853SAndroid Build Coastguard Worker         /* residual_colour_transform_flag */
1188*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_residual_colour_transform_flag = 0;
1189*495ae853SAndroid Build Coastguard Worker 
1190*495ae853SAndroid Build Coastguard Worker         /* luma bit depth 8 */
1191*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_bit_depth_luma = 8;
1192*495ae853SAndroid Build Coastguard Worker 
1193*495ae853SAndroid Build Coastguard Worker         /* chroma bit depth 8 */
1194*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_bit_depth_chroma = 8;
1195*495ae853SAndroid Build Coastguard Worker 
1196*495ae853SAndroid Build Coastguard Worker         /* qpprime_y_zero_transform_bypass_flag */
1197*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_qpprime_y_zero_transform_bypass_flag = 0;
1198*495ae853SAndroid Build Coastguard Worker 
1199*495ae853SAndroid Build Coastguard Worker         /* seq_scaling_matrix_present_flag */
1200*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_seq_scaling_matrix_present_flag = 0;
1201*495ae853SAndroid Build Coastguard Worker 
1202*495ae853SAndroid Build Coastguard Worker         if (ps_sps->i1_seq_scaling_matrix_present_flag)
1203*495ae853SAndroid Build Coastguard Worker         {
1204*495ae853SAndroid Build Coastguard Worker             /* TODO_LATER: Will be enabled once scaling list support is added */
1205*495ae853SAndroid Build Coastguard Worker         }
1206*495ae853SAndroid Build Coastguard Worker     }
1207*495ae853SAndroid Build Coastguard Worker 
1208*495ae853SAndroid Build Coastguard Worker     /* log2_max_frame_num_minus4 */
1209*495ae853SAndroid Build Coastguard Worker     ps_sps->i1_log2_max_frame_num = 16;
1210*495ae853SAndroid Build Coastguard Worker 
1211*495ae853SAndroid Build Coastguard Worker     /* pic_order_cnt_type */
1212*495ae853SAndroid Build Coastguard Worker     ps_sps->i1_pic_order_cnt_type = 2;
1213*495ae853SAndroid Build Coastguard Worker 
1214*495ae853SAndroid Build Coastguard Worker     if (ps_codec->i4_non_ref_frames_in_stream)
1215*495ae853SAndroid Build Coastguard Worker     {
1216*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_pic_order_cnt_type = 0;
1217*495ae853SAndroid Build Coastguard Worker     }
1218*495ae853SAndroid Build Coastguard Worker 
1219*495ae853SAndroid Build Coastguard Worker     /* log2_max_pic_order_cnt_lsb_minus4 */
1220*495ae853SAndroid Build Coastguard Worker     ps_sps->i1_log2_max_pic_order_cnt_lsb = 8;
1221*495ae853SAndroid Build Coastguard Worker 
1222*495ae853SAndroid Build Coastguard Worker     /* TODO : add support for other poc types */
1223*495ae853SAndroid Build Coastguard Worker     if (ps_sps->i1_pic_order_cnt_type == 0)
1224*495ae853SAndroid Build Coastguard Worker     {
1225*495ae853SAndroid Build Coastguard Worker 
1226*495ae853SAndroid Build Coastguard Worker     }
1227*495ae853SAndroid Build Coastguard Worker     else if (ps_sps->i1_pic_order_cnt_type == 1)
1228*495ae853SAndroid Build Coastguard Worker     {
1229*495ae853SAndroid Build Coastguard Worker 
1230*495ae853SAndroid Build Coastguard Worker     }
1231*495ae853SAndroid Build Coastguard Worker 
1232*495ae853SAndroid Build Coastguard Worker     /* num_ref_frames */
1233*495ae853SAndroid Build Coastguard Worker     /* TODO : Should we have a flexible num ref frames */
1234*495ae853SAndroid Build Coastguard Worker     if (ps_codec->s_cfg.u4_num_bframes > 0)
1235*495ae853SAndroid Build Coastguard Worker     {
1236*495ae853SAndroid Build Coastguard Worker         ps_sps->u1_max_num_ref_frames = 2;
1237*495ae853SAndroid Build Coastguard Worker     }
1238*495ae853SAndroid Build Coastguard Worker     else
1239*495ae853SAndroid Build Coastguard Worker     {
1240*495ae853SAndroid Build Coastguard Worker         ps_sps->u1_max_num_ref_frames = 1;
1241*495ae853SAndroid Build Coastguard Worker     }
1242*495ae853SAndroid Build Coastguard Worker 
1243*495ae853SAndroid Build Coastguard Worker     /* gaps_in_frame_num_value_allowed_flag */
1244*495ae853SAndroid Build Coastguard Worker     ps_sps->i1_gaps_in_frame_num_value_allowed_flag = 0;
1245*495ae853SAndroid Build Coastguard Worker 
1246*495ae853SAndroid Build Coastguard Worker     /* pic width in mb - 1 */
1247*495ae853SAndroid Build Coastguard Worker     ps_sps->i2_pic_width_in_mbs_minus1 = ps_cfg->i4_wd_mbs - 1;
1248*495ae853SAndroid Build Coastguard Worker 
1249*495ae853SAndroid Build Coastguard Worker     /* pic height in mb - 1 */
1250*495ae853SAndroid Build Coastguard Worker     ps_sps->i2_pic_height_in_map_units_minus1 = ps_cfg->i4_ht_mbs - 1;;
1251*495ae853SAndroid Build Coastguard Worker 
1252*495ae853SAndroid Build Coastguard Worker     /* frame_mbs_only_flag, no support for interlace encoding */
1253*495ae853SAndroid Build Coastguard Worker     ps_sps->i1_frame_mbs_only_flag = 1;
1254*495ae853SAndroid Build Coastguard Worker 
1255*495ae853SAndroid Build Coastguard Worker     /* mb_adaptive_frame_field_flag */
1256*495ae853SAndroid Build Coastguard Worker     if (ps_sps->i1_frame_mbs_only_flag == 0)
1257*495ae853SAndroid Build Coastguard Worker     {
1258*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_mb_adaptive_frame_field_flag = 0;
1259*495ae853SAndroid Build Coastguard Worker     }
1260*495ae853SAndroid Build Coastguard Worker 
1261*495ae853SAndroid Build Coastguard Worker     /* direct_8x8_inference_flag */
1262*495ae853SAndroid Build Coastguard Worker     if (ps_sps->u1_level_idc < IH264_LEVEL_30)
1263*495ae853SAndroid Build Coastguard Worker     {
1264*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_direct_8x8_inference_flag = 0;
1265*495ae853SAndroid Build Coastguard Worker     }
1266*495ae853SAndroid Build Coastguard Worker     else
1267*495ae853SAndroid Build Coastguard Worker     {
1268*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_direct_8x8_inference_flag = 1;
1269*495ae853SAndroid Build Coastguard Worker     }
1270*495ae853SAndroid Build Coastguard Worker 
1271*495ae853SAndroid Build Coastguard Worker 
1272*495ae853SAndroid Build Coastguard Worker     /* cropping params */
1273*495ae853SAndroid Build Coastguard Worker     /*NOTE : Cropping values depend on the chroma format
1274*495ae853SAndroid Build Coastguard Worker      * For our case ,decoder interprets the cropping values as 2*num pixels
1275*495ae853SAndroid Build Coastguard Worker      * Hence the difference in the disp width and width must be halved before sending
1276*495ae853SAndroid Build Coastguard Worker      * to get the expected results
1277*495ae853SAndroid Build Coastguard Worker      */
1278*495ae853SAndroid Build Coastguard Worker     ps_sps->i1_frame_cropping_flag      = 0;
1279*495ae853SAndroid Build Coastguard Worker     ps_sps->i2_frame_crop_left_offset   = 0;
1280*495ae853SAndroid Build Coastguard Worker     ps_sps->i2_frame_crop_right_offset  = (ps_codec->s_cfg.u4_wd - ps_codec->s_cfg.u4_disp_wd)>>1;
1281*495ae853SAndroid Build Coastguard Worker     ps_sps->i2_frame_crop_top_offset    = 0;
1282*495ae853SAndroid Build Coastguard Worker     ps_sps->i2_frame_crop_bottom_offset = (ps_codec->s_cfg.u4_ht - ps_codec->s_cfg.u4_disp_ht)>>1;
1283*495ae853SAndroid Build Coastguard Worker 
1284*495ae853SAndroid Build Coastguard Worker     if (ps_sps->i2_frame_crop_left_offset    ||
1285*495ae853SAndroid Build Coastguard Worker                     ps_sps->i2_frame_crop_right_offset   ||
1286*495ae853SAndroid Build Coastguard Worker                     ps_sps->i2_frame_crop_top_offset     ||
1287*495ae853SAndroid Build Coastguard Worker                     ps_sps->i2_frame_crop_bottom_offset)
1288*495ae853SAndroid Build Coastguard Worker     {
1289*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_frame_cropping_flag      = 1;
1290*495ae853SAndroid Build Coastguard Worker     }
1291*495ae853SAndroid Build Coastguard Worker 
1292*495ae853SAndroid Build Coastguard Worker     /* vui params */
1293*495ae853SAndroid Build Coastguard Worker     ps_sps->i1_vui_parameters_present_flag = 1;
1294*495ae853SAndroid Build Coastguard Worker 
1295*495ae853SAndroid Build Coastguard Worker     if (ps_sps->i1_vui_parameters_present_flag)
1296*495ae853SAndroid Build Coastguard Worker     {
1297*495ae853SAndroid Build Coastguard Worker         /* populate vui params */
1298*495ae853SAndroid Build Coastguard Worker         ih264e_populate_vui(ps_codec);
1299*495ae853SAndroid Build Coastguard Worker     }
1300*495ae853SAndroid Build Coastguard Worker 
1301*495ae853SAndroid Build Coastguard Worker     return i4_err_code;
1302*495ae853SAndroid Build Coastguard Worker }
1303*495ae853SAndroid Build Coastguard Worker 
1304*495ae853SAndroid Build Coastguard Worker /**
1305*495ae853SAndroid Build Coastguard Worker ******************************************************************************
1306*495ae853SAndroid Build Coastguard Worker *
1307*495ae853SAndroid Build Coastguard Worker * @brief Populates pps structure
1308*495ae853SAndroid Build Coastguard Worker *
1309*495ae853SAndroid Build Coastguard Worker * @par   Description
1310*495ae853SAndroid Build Coastguard Worker *  Populates pps structure for its use in header generation
1311*495ae853SAndroid Build Coastguard Worker *
1312*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_codec
1313*495ae853SAndroid Build Coastguard Worker *  pointer to encoder context
1314*495ae853SAndroid Build Coastguard Worker *
1315*495ae853SAndroid Build Coastguard Worker * @param[out]  ps_pps
1316*495ae853SAndroid Build Coastguard Worker *  pointer to pps params that needs to be populated
1317*495ae853SAndroid Build Coastguard Worker *
1318*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
1319*495ae853SAndroid Build Coastguard Worker *
1320*495ae853SAndroid Build Coastguard Worker ******************************************************************************
1321*495ae853SAndroid Build Coastguard Worker */
ih264e_populate_pps(codec_t * ps_codec,pps_t * ps_pps)1322*495ae853SAndroid Build Coastguard Worker IH264E_ERROR_T ih264e_populate_pps(codec_t *ps_codec, pps_t *ps_pps)
1323*495ae853SAndroid Build Coastguard Worker {
1324*495ae853SAndroid Build Coastguard Worker     /* active config parameters */
1325*495ae853SAndroid Build Coastguard Worker     cfg_params_t    *ps_cfg = &(ps_codec->s_cfg);
1326*495ae853SAndroid Build Coastguard Worker 
1327*495ae853SAndroid Build Coastguard Worker     /* seq_parameter_set_id */
1328*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_sps_id = ps_codec->i4_sps_id;
1329*495ae853SAndroid Build Coastguard Worker 
1330*495ae853SAndroid Build Coastguard Worker     /* pic_parameter_set_id */
1331*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_pps_id = ps_codec->i4_pps_id;
1332*495ae853SAndroid Build Coastguard Worker 
1333*495ae853SAndroid Build Coastguard Worker     /* entropy_coding_mode */
1334*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_entropy_coding_mode_flag = ps_cfg->u4_entropy_coding_mode;
1335*495ae853SAndroid Build Coastguard Worker 
1336*495ae853SAndroid Build Coastguard Worker     /* pic_order_present_flag is unset if we don't have feilds */
1337*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_pic_order_present_flag = 0;
1338*495ae853SAndroid Build Coastguard Worker 
1339*495ae853SAndroid Build Coastguard Worker     /* Currently number of slice groups supported are 1 */
1340*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_num_slice_groups = 1;
1341*495ae853SAndroid Build Coastguard Worker 
1342*495ae853SAndroid Build Coastguard Worker     if (ps_pps->u1_num_slice_groups - 1)
1343*495ae853SAndroid Build Coastguard Worker     {
1344*495ae853SAndroid Build Coastguard Worker         /* TODO_LATER: Currently the number of slice groups minus 1 is 0.
1345*495ae853SAndroid Build Coastguard Worker          * If this is not the case, we have to add Slice group map type to the bit stream*/
1346*495ae853SAndroid Build Coastguard Worker     }
1347*495ae853SAndroid Build Coastguard Worker 
1348*495ae853SAndroid Build Coastguard Worker     /* number of reference frames for list 0 */
1349*495ae853SAndroid Build Coastguard Worker     /* FIXME : fix this hard coded value */
1350*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_num_ref_idx_l0_default_active = 1;
1351*495ae853SAndroid Build Coastguard Worker 
1352*495ae853SAndroid Build Coastguard Worker     /* number of reference frames for list 1 */
1353*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_num_ref_idx_l1_default_active = 1;
1354*495ae853SAndroid Build Coastguard Worker 
1355*495ae853SAndroid Build Coastguard Worker     /* weighted prediction for now is disabled */
1356*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_weighted_pred_flag = 0;
1357*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_weighted_bipred_idc = 0;
1358*495ae853SAndroid Build Coastguard Worker 
1359*495ae853SAndroid Build Coastguard Worker     /* The intent is to not signal qp from pps. Rather send the same in slice headers */
1360*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_pic_init_qp = 0;
1361*495ae853SAndroid Build Coastguard Worker 
1362*495ae853SAndroid Build Coastguard Worker     /* The intent is to not signal qp from pps. Rather send the same in slice headers */
1363*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_pic_init_qs = 0;
1364*495ae853SAndroid Build Coastguard Worker 
1365*495ae853SAndroid Build Coastguard Worker     /* The intent is to not signal qp from pps. Rather send the same in slice headers */
1366*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_chroma_qp_index_offset = 0;
1367*495ae853SAndroid Build Coastguard Worker 
1368*495ae853SAndroid Build Coastguard Worker     /* deblocking filter flags present in slice header */
1369*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_deblocking_filter_control_present_flag = 1;
1370*495ae853SAndroid Build Coastguard Worker 
1371*495ae853SAndroid Build Coastguard Worker     /* constrained intra prediction */
1372*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_constrained_intra_pred_flag = ps_cfg->u4_constrained_intra_pred;
1373*495ae853SAndroid Build Coastguard Worker 
1374*495ae853SAndroid Build Coastguard Worker     /* sending redundant slices is not supported for now */
1375*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_redundant_pic_cnt_present_flag = 0;
1376*495ae853SAndroid Build Coastguard Worker 
1377*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_slice_group_map_type = 0;
1378*495ae853SAndroid Build Coastguard Worker 
1379*495ae853SAndroid Build Coastguard Worker     return IH264E_SUCCESS;
1380*495ae853SAndroid Build Coastguard Worker }
1381*495ae853SAndroid Build Coastguard Worker 
1382*495ae853SAndroid Build Coastguard Worker /**
1383*495ae853SAndroid Build Coastguard Worker ******************************************************************************
1384*495ae853SAndroid Build Coastguard Worker *
1385*495ae853SAndroid Build Coastguard Worker * @brief Populates slice header structure
1386*495ae853SAndroid Build Coastguard Worker *
1387*495ae853SAndroid Build Coastguard Worker * @par   Description
1388*495ae853SAndroid Build Coastguard Worker *  Populates slice header structure for its use in header generation
1389*495ae853SAndroid Build Coastguard Worker *
1390*495ae853SAndroid Build Coastguard Worker * @param[in]  ps_proc
1391*495ae853SAndroid Build Coastguard Worker *  pointer to proc context
1392*495ae853SAndroid Build Coastguard Worker *
1393*495ae853SAndroid Build Coastguard Worker * @param[out]  ps_slice_hdr
1394*495ae853SAndroid Build Coastguard Worker *  pointer to slice header structure that needs to be populated
1395*495ae853SAndroid Build Coastguard Worker *
1396*495ae853SAndroid Build Coastguard Worker * @param[in]  ps_pps
1397*495ae853SAndroid Build Coastguard Worker *  pointer to pps params structure referred by the slice
1398*495ae853SAndroid Build Coastguard Worker *
1399*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_sps
1400*495ae853SAndroid Build Coastguard Worker *  pointer to sps params referred by the pps
1401*495ae853SAndroid Build Coastguard Worker *
1402*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
1403*495ae853SAndroid Build Coastguard Worker *
1404*495ae853SAndroid Build Coastguard Worker ******************************************************************************
1405*495ae853SAndroid Build Coastguard Worker */
ih264e_populate_slice_header(process_ctxt_t * ps_proc,slice_header_t * ps_slice_hdr,pps_t * ps_pps,sps_t * ps_sps)1406*495ae853SAndroid Build Coastguard Worker WORD32 ih264e_populate_slice_header(process_ctxt_t *ps_proc,
1407*495ae853SAndroid Build Coastguard Worker                                     slice_header_t *ps_slice_hdr,
1408*495ae853SAndroid Build Coastguard Worker                                     pps_t *ps_pps,
1409*495ae853SAndroid Build Coastguard Worker                                     sps_t *ps_sps)
1410*495ae853SAndroid Build Coastguard Worker {
1411*495ae853SAndroid Build Coastguard Worker     /* entropy context */
1412*495ae853SAndroid Build Coastguard Worker     entropy_ctxt_t *ps_entropy = &ps_proc->s_entropy;
1413*495ae853SAndroid Build Coastguard Worker 
1414*495ae853SAndroid Build Coastguard Worker     codec_t *ps_codec = ps_proc->ps_codec;
1415*495ae853SAndroid Build Coastguard Worker 
1416*495ae853SAndroid Build Coastguard Worker     if (ps_proc->ps_codec->u4_is_curr_frm_ref)
1417*495ae853SAndroid Build Coastguard Worker     {
1418*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->i1_nal_unit_idc = 3;
1419*495ae853SAndroid Build Coastguard Worker     }
1420*495ae853SAndroid Build Coastguard Worker     else
1421*495ae853SAndroid Build Coastguard Worker     {
1422*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->i1_nal_unit_idc = 0;
1423*495ae853SAndroid Build Coastguard Worker     }
1424*495ae853SAndroid Build Coastguard Worker 
1425*495ae853SAndroid Build Coastguard Worker     /* start mb address */
1426*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->u2_first_mb_in_slice = ps_entropy->i4_mb_start_add;
1427*495ae853SAndroid Build Coastguard Worker 
1428*495ae853SAndroid Build Coastguard Worker     /* slice type */
1429*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->u1_slice_type = ps_proc->i4_slice_type;
1430*495ae853SAndroid Build Coastguard Worker 
1431*495ae853SAndroid Build Coastguard Worker     /* pic_parameter_set_id */
1432*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->u1_pps_id = ps_pps->u1_pps_id;
1433*495ae853SAndroid Build Coastguard Worker 
1434*495ae853SAndroid Build Coastguard Worker     /* Separate color plane flag is 0,
1435*495ae853SAndroid Build Coastguard Worker      * hence the syntax element color_plane_id not included */
1436*495ae853SAndroid Build Coastguard Worker 
1437*495ae853SAndroid Build Coastguard Worker     /* frame num */
1438*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->i4_frame_num = ps_proc->i4_frame_num;
1439*495ae853SAndroid Build Coastguard Worker 
1440*495ae853SAndroid Build Coastguard Worker     /* frame_mbs_only_flag, no support for interlace encoding */
1441*495ae853SAndroid Build Coastguard Worker     if (!ps_sps->i1_frame_mbs_only_flag)
1442*495ae853SAndroid Build Coastguard Worker     {
1443*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->i1_field_pic_flag = 0;
1444*495ae853SAndroid Build Coastguard Worker 
1445*495ae853SAndroid Build Coastguard Worker         if (ps_slice_hdr->i1_field_pic_flag)
1446*495ae853SAndroid Build Coastguard Worker         {
1447*495ae853SAndroid Build Coastguard Worker             ps_slice_hdr->i1_bottom_field_flag = 0;
1448*495ae853SAndroid Build Coastguard Worker         }
1449*495ae853SAndroid Build Coastguard Worker     }
1450*495ae853SAndroid Build Coastguard Worker 
1451*495ae853SAndroid Build Coastguard Worker     /* idr pic id */
1452*495ae853SAndroid Build Coastguard Worker     if (ps_proc->u4_is_idr)
1453*495ae853SAndroid Build Coastguard Worker     {
1454*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->u2_idr_pic_id = ps_proc->u4_idr_pic_id;
1455*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->i1_nal_unit_type = 5;
1456*495ae853SAndroid Build Coastguard Worker     }
1457*495ae853SAndroid Build Coastguard Worker     else
1458*495ae853SAndroid Build Coastguard Worker     {
1459*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->i1_nal_unit_type = 1;
1460*495ae853SAndroid Build Coastguard Worker     }
1461*495ae853SAndroid Build Coastguard Worker 
1462*495ae853SAndroid Build Coastguard Worker     if (ps_sps->i1_pic_order_cnt_type == 0)
1463*495ae853SAndroid Build Coastguard Worker     {
1464*495ae853SAndroid Build Coastguard Worker 
1465*495ae853SAndroid Build Coastguard Worker         WORD32 i4_poc;
1466*495ae853SAndroid Build Coastguard Worker         i4_poc = ps_codec->i4_poc;
1467*495ae853SAndroid Build Coastguard Worker         i4_poc %= (1 << ps_sps->i1_log2_max_pic_order_cnt_lsb);
1468*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->i4_pic_order_cnt_lsb = i4_poc;
1469*495ae853SAndroid Build Coastguard Worker     }
1470*495ae853SAndroid Build Coastguard Worker     /* TODO add support for poc type 1 */
1471*495ae853SAndroid Build Coastguard Worker     else if (ps_sps->i1_pic_order_cnt_type == 1)
1472*495ae853SAndroid Build Coastguard Worker     {
1473*495ae853SAndroid Build Coastguard Worker 
1474*495ae853SAndroid Build Coastguard Worker     }
1475*495ae853SAndroid Build Coastguard Worker 
1476*495ae853SAndroid Build Coastguard Worker 
1477*495ae853SAndroid Build Coastguard Worker     /*
1478*495ae853SAndroid Build Coastguard Worker      * redundant slices are not currently supported.
1479*495ae853SAndroid Build Coastguard Worker      * Hence the syntax element redundant slice cnt is not initialized
1480*495ae853SAndroid Build Coastguard Worker      */
1481*495ae853SAndroid Build Coastguard Worker     if (ps_pps->i1_redundant_pic_cnt_present_flag)
1482*495ae853SAndroid Build Coastguard Worker     {
1483*495ae853SAndroid Build Coastguard Worker 
1484*495ae853SAndroid Build Coastguard Worker     }
1485*495ae853SAndroid Build Coastguard Worker 
1486*495ae853SAndroid Build Coastguard Worker     /* direct spatial mv pred flag */
1487*495ae853SAndroid Build Coastguard Worker     if (ps_proc->i4_slice_type == BSLICE)
1488*495ae853SAndroid Build Coastguard Worker     {
1489*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->u1_direct_spatial_mv_pred_flag = 1;
1490*495ae853SAndroid Build Coastguard Worker     }
1491*495ae853SAndroid Build Coastguard Worker 
1492*495ae853SAndroid Build Coastguard Worker     if (ps_proc->i4_slice_type == PSLICE || ps_proc->i4_slice_type == SPSLICE || ps_proc->i4_slice_type == BSLICE)
1493*495ae853SAndroid Build Coastguard Worker     {
1494*495ae853SAndroid Build Coastguard Worker         /* num_ref_idx_active_override_flag */
1495*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->u1_num_ref_idx_active_override_flag = 0;
1496*495ae853SAndroid Build Coastguard Worker 
1497*495ae853SAndroid Build Coastguard Worker         if (ps_slice_hdr->u1_num_ref_idx_active_override_flag)
1498*495ae853SAndroid Build Coastguard Worker         {
1499*495ae853SAndroid Build Coastguard Worker             /* num_ref_idx_l0_active_minus1 */
1500*495ae853SAndroid Build Coastguard Worker 
1501*495ae853SAndroid Build Coastguard Worker             if (ps_proc->i4_slice_type == BSLICE)
1502*495ae853SAndroid Build Coastguard Worker             {
1503*495ae853SAndroid Build Coastguard Worker                 /* num_ref_idx_l1_active_minus1 */
1504*495ae853SAndroid Build Coastguard Worker 
1505*495ae853SAndroid Build Coastguard Worker             }
1506*495ae853SAndroid Build Coastguard Worker         }
1507*495ae853SAndroid Build Coastguard Worker     }
1508*495ae853SAndroid Build Coastguard Worker 
1509*495ae853SAndroid Build Coastguard Worker     /* ref_idx_reordering */
1510*495ae853SAndroid Build Coastguard Worker     /* TODO: ref_idx_reordering */
1511*495ae853SAndroid Build Coastguard Worker     if ((ps_proc->i4_slice_type != ISLICE) && (ps_proc->i4_slice_type != SISLICE))
1512*495ae853SAndroid Build Coastguard Worker     {
1513*495ae853SAndroid Build Coastguard Worker         /* ref_pic_list_reordering_flag_l0 */
1514*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->u1_ref_idx_reordering_flag_l0 = 0;
1515*495ae853SAndroid Build Coastguard Worker 
1516*495ae853SAndroid Build Coastguard Worker         if (ps_slice_hdr->u1_ref_idx_reordering_flag_l0)
1517*495ae853SAndroid Build Coastguard Worker         {
1518*495ae853SAndroid Build Coastguard Worker 
1519*495ae853SAndroid Build Coastguard Worker         }
1520*495ae853SAndroid Build Coastguard Worker 
1521*495ae853SAndroid Build Coastguard Worker         /* ref_pic_list_reordering_flag_l1 */
1522*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->u1_ref_idx_reordering_flag_l1 = 0;
1523*495ae853SAndroid Build Coastguard Worker 
1524*495ae853SAndroid Build Coastguard Worker         if (ps_slice_hdr->u1_ref_idx_reordering_flag_l1)
1525*495ae853SAndroid Build Coastguard Worker         {
1526*495ae853SAndroid Build Coastguard Worker 
1527*495ae853SAndroid Build Coastguard Worker         }
1528*495ae853SAndroid Build Coastguard Worker     }
1529*495ae853SAndroid Build Coastguard Worker 
1530*495ae853SAndroid Build Coastguard Worker 
1531*495ae853SAndroid Build Coastguard Worker     /* Currently we do not support weighted pred */
1532*495ae853SAndroid Build Coastguard Worker     /* ps_slice_hdr->u1_weighted_bipred_idc = 0; */
1533*495ae853SAndroid Build Coastguard Worker 
1534*495ae853SAndroid Build Coastguard Worker     if ((ps_pps->i1_weighted_pred_flag &&
1535*495ae853SAndroid Build Coastguard Worker                     (ps_proc->i4_slice_type == PSLICE || ps_proc->i4_slice_type == SPSLICE)) ||
1536*495ae853SAndroid Build Coastguard Worker                     (ps_proc->i4_slice_type == BSLICE && ps_pps->i1_weighted_bipred_idc == 1))
1537*495ae853SAndroid Build Coastguard Worker     {
1538*495ae853SAndroid Build Coastguard Worker         /* TODO_LATER: Currently there is no support for weighted prediction.
1539*495ae853SAndroid Build Coastguard Worker              This needs to be updated when the support is added */
1540*495ae853SAndroid Build Coastguard Worker     }
1541*495ae853SAndroid Build Coastguard Worker 
1542*495ae853SAndroid Build Coastguard Worker     if (ps_slice_hdr->i1_nal_unit_idc != 0)
1543*495ae853SAndroid Build Coastguard Worker     {
1544*495ae853SAndroid Build Coastguard Worker         if (ps_slice_hdr->i1_nal_unit_type == 5)
1545*495ae853SAndroid Build Coastguard Worker         {
1546*495ae853SAndroid Build Coastguard Worker             /* no_output_of_prior_pics_flag  */
1547*495ae853SAndroid Build Coastguard Worker             ps_slice_hdr->u1_no_output_of_prior_pics_flag = 0;
1548*495ae853SAndroid Build Coastguard Worker 
1549*495ae853SAndroid Build Coastguard Worker             /* long_term_reference_flag  */
1550*495ae853SAndroid Build Coastguard Worker             ps_slice_hdr->u1_long_term_reference_flag = 0;
1551*495ae853SAndroid Build Coastguard Worker         }
1552*495ae853SAndroid Build Coastguard Worker         else
1553*495ae853SAndroid Build Coastguard Worker         {
1554*495ae853SAndroid Build Coastguard Worker             /* adaptive_ref_pic_marking_mode_flag  */
1555*495ae853SAndroid Build Coastguard Worker             ps_slice_hdr->u1_adaptive_ref_pic_marking_mode_flag = 0;
1556*495ae853SAndroid Build Coastguard Worker 
1557*495ae853SAndroid Build Coastguard Worker             if (ps_slice_hdr->u1_adaptive_ref_pic_marking_mode_flag)
1558*495ae853SAndroid Build Coastguard Worker             {
1559*495ae853SAndroid Build Coastguard Worker                 /* TODO: if the reference picture marking mode is adaptive
1560*495ae853SAndroid Build Coastguard Worker                      add these fields in the bit-stream */
1561*495ae853SAndroid Build Coastguard Worker             }
1562*495ae853SAndroid Build Coastguard Worker         }
1563*495ae853SAndroid Build Coastguard Worker     }
1564*495ae853SAndroid Build Coastguard Worker 
1565*495ae853SAndroid Build Coastguard Worker     /* entropy coding mode flag */
1566*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->u1_entropy_coding_mode_flag = ps_entropy->u1_entropy_coding_mode_flag;
1567*495ae853SAndroid Build Coastguard Worker 
1568*495ae853SAndroid Build Coastguard Worker     if (ps_slice_hdr->u1_entropy_coding_mode_flag && ps_proc->i4_slice_type != ISLICE &&
1569*495ae853SAndroid Build Coastguard Worker                     ps_proc->i4_slice_type != SISLICE)
1570*495ae853SAndroid Build Coastguard Worker     {
1571*495ae853SAndroid Build Coastguard Worker         /* cabac_init_idc */
1572*495ae853SAndroid Build Coastguard Worker     }
1573*495ae853SAndroid Build Coastguard Worker 
1574*495ae853SAndroid Build Coastguard Worker     /* slice qp */
1575*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->i1_slice_qp = ps_proc->u4_frame_qp;
1576*495ae853SAndroid Build Coastguard Worker 
1577*495ae853SAndroid Build Coastguard Worker     if (ps_proc->i4_slice_type == SPSLICE || ps_proc->i4_slice_type == SISLICE)
1578*495ae853SAndroid Build Coastguard Worker     {
1579*495ae853SAndroid Build Coastguard Worker         if (ps_proc->i4_slice_type == SPSLICE)
1580*495ae853SAndroid Build Coastguard Worker         {
1581*495ae853SAndroid Build Coastguard Worker             /* sp_for_switch_flag */
1582*495ae853SAndroid Build Coastguard Worker         }
1583*495ae853SAndroid Build Coastguard Worker         /* slice_qs_delta */
1584*495ae853SAndroid Build Coastguard Worker     }
1585*495ae853SAndroid Build Coastguard Worker 
1586*495ae853SAndroid Build Coastguard Worker     if (ps_pps->i1_deblocking_filter_control_present_flag)
1587*495ae853SAndroid Build Coastguard Worker     {
1588*495ae853SAndroid Build Coastguard Worker         /* disable_deblocking_filter_idc */
1589*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->u1_disable_deblocking_filter_idc = ps_proc->u4_disable_deblock_level;
1590*495ae853SAndroid Build Coastguard Worker 
1591*495ae853SAndroid Build Coastguard Worker         if (ps_slice_hdr->u1_disable_deblocking_filter_idc != 1)
1592*495ae853SAndroid Build Coastguard Worker         {
1593*495ae853SAndroid Build Coastguard Worker             /* slice_alpha_c0_offset_div2 */
1594*495ae853SAndroid Build Coastguard Worker             ps_slice_hdr->i1_slice_alpha_c0_offset_div2 = 0;
1595*495ae853SAndroid Build Coastguard Worker 
1596*495ae853SAndroid Build Coastguard Worker             /* slice_beta_offset_div2 */
1597*495ae853SAndroid Build Coastguard Worker             ps_slice_hdr->i1_slice_beta_offset_div2 = 0;
1598*495ae853SAndroid Build Coastguard Worker         }
1599*495ae853SAndroid Build Coastguard Worker     }
1600*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->u1_num_slice_groups_minus1 = 0;
1601*495ae853SAndroid Build Coastguard Worker     if(ps_slice_hdr->u1_num_slice_groups_minus1 > 0 &&
1602*495ae853SAndroid Build Coastguard Worker         ps_pps->u1_slice_group_map_type >= 3 &&
1603*495ae853SAndroid Build Coastguard Worker         ps_pps->u1_slice_group_map_type <= 5)
1604*495ae853SAndroid Build Coastguard Worker     {
1605*495ae853SAndroid Build Coastguard Worker         /* slice_group_change_cycle */
1606*495ae853SAndroid Build Coastguard Worker         /* TODO_LATER: Currently the number of slice groups minus 1 is 0.
1607*495ae853SAndroid Build Coastguard Worker          * If this is not the case, we have to add Slice group map type to the bit stream */
1608*495ae853SAndroid Build Coastguard Worker     }
1609*495ae853SAndroid Build Coastguard Worker 
1610*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->i1_cabac_init_idc = CABAC_INIT_IDC;
1611*495ae853SAndroid Build Coastguard Worker 
1612*495ae853SAndroid Build Coastguard Worker     return IH264E_SUCCESS;
1613*495ae853SAndroid Build Coastguard Worker }
1614*495ae853SAndroid Build Coastguard Worker 
1615*495ae853SAndroid Build Coastguard Worker /**
1616*495ae853SAndroid Build Coastguard Worker ******************************************************************************
1617*495ae853SAndroid Build Coastguard Worker *
1618*495ae853SAndroid Build Coastguard Worker * @brief inserts FILLER Nal Unit.
1619*495ae853SAndroid Build Coastguard Worker *
1620*495ae853SAndroid Build Coastguard Worker * @par   Description
1621*495ae853SAndroid Build Coastguard Worker *  In constant bit rate rc mode, when the bits generated by the codec is
1622*495ae853SAndroid Build Coastguard Worker *  underflowing the target bit rate, the encoder library inserts filler nal unit.
1623*495ae853SAndroid Build Coastguard Worker *
1624*495ae853SAndroid Build Coastguard Worker * @param[in]    ps_bitstrm
1625*495ae853SAndroid Build Coastguard Worker *  pointer to bitstream context (handle)
1626*495ae853SAndroid Build Coastguard Worker *
1627*495ae853SAndroid Build Coastguard Worker * @param[in]    insert_fill_bytes
1628*495ae853SAndroid Build Coastguard Worker *  Number of fill bytes to be inserted
1629*495ae853SAndroid Build Coastguard Worker *
1630*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
1631*495ae853SAndroid Build Coastguard Worker *
1632*495ae853SAndroid Build Coastguard Worker ******************************************************************************
1633*495ae853SAndroid Build Coastguard Worker */
ih264e_add_filler_nal_unit(bitstrm_t * ps_bitstrm,WORD32 insert_fill_bytes)1634*495ae853SAndroid Build Coastguard Worker IH264E_ERROR_T ih264e_add_filler_nal_unit(bitstrm_t *ps_bitstrm,
1635*495ae853SAndroid Build Coastguard Worker                                           WORD32 insert_fill_bytes)
1636*495ae853SAndroid Build Coastguard Worker {
1637*495ae853SAndroid Build Coastguard Worker     WORD32  i4_num_words_to_fill, i4_words_filled;
1638*495ae853SAndroid Build Coastguard Worker 
1639*495ae853SAndroid Build Coastguard Worker     IH264E_ERROR_T return_status = IH264E_SUCCESS;
1640*495ae853SAndroid Build Coastguard Worker 
1641*495ae853SAndroid Build Coastguard Worker     /* Insert the NAL start code */
1642*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
1643*495ae853SAndroid Build Coastguard Worker     if(return_status != IH264E_SUCCESS)
1644*495ae853SAndroid Build Coastguard Worker     {
1645*495ae853SAndroid Build Coastguard Worker         return return_status;
1646*495ae853SAndroid Build Coastguard Worker     }
1647*495ae853SAndroid Build Coastguard Worker 
1648*495ae853SAndroid Build Coastguard Worker     if (ps_bitstrm->u4_strm_buf_offset + insert_fill_bytes >= ps_bitstrm->u4_max_strm_size)
1649*495ae853SAndroid Build Coastguard Worker     {
1650*495ae853SAndroid Build Coastguard Worker         return (IH264E_BITSTREAM_BUFFER_OVERFLOW);
1651*495ae853SAndroid Build Coastguard Worker     }
1652*495ae853SAndroid Build Coastguard Worker 
1653*495ae853SAndroid Build Coastguard Worker     /* Insert Nal Unit Header */
1654*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, NAL_FILLER_FIRST_BYTE, 8, return_status, "filler_header");
1655*495ae853SAndroid Build Coastguard Worker 
1656*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, 0xFFFFFF, 24, return_status, "fill bytes");
1657*495ae853SAndroid Build Coastguard Worker 
1658*495ae853SAndroid Build Coastguard Worker     /* Initializing Variables                           */
1659*495ae853SAndroid Build Coastguard Worker     i4_words_filled    = 1;
1660*495ae853SAndroid Build Coastguard Worker 
1661*495ae853SAndroid Build Coastguard Worker     /****************************************************/
1662*495ae853SAndroid Build Coastguard Worker     /* Flooring the number of bytes for be stuffed to   */
1663*495ae853SAndroid Build Coastguard Worker     /* WORD unit                                        */
1664*495ae853SAndroid Build Coastguard Worker     /****************************************************/
1665*495ae853SAndroid Build Coastguard Worker     i4_num_words_to_fill = (insert_fill_bytes >> 2);
1666*495ae853SAndroid Build Coastguard Worker 
1667*495ae853SAndroid Build Coastguard Worker     /****************************************************/
1668*495ae853SAndroid Build Coastguard Worker     /* Reducing already 4 bytes filled. In case stuffing*/
1669*495ae853SAndroid Build Coastguard Worker     /* is <= 4 bytes, we are actually not stuffing      */
1670*495ae853SAndroid Build Coastguard Worker     /* anything                                         */
1671*495ae853SAndroid Build Coastguard Worker     /****************************************************/
1672*495ae853SAndroid Build Coastguard Worker     i4_num_words_to_fill -= i4_words_filled;
1673*495ae853SAndroid Build Coastguard Worker 
1674*495ae853SAndroid Build Coastguard Worker     while (i4_num_words_to_fill > 0)
1675*495ae853SAndroid Build Coastguard Worker     {
1676*495ae853SAndroid Build Coastguard Worker         /* Insert Nal Unit Header */
1677*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, 0xFFFFFFFF, 32, return_status, "fill bytes");
1678*495ae853SAndroid Build Coastguard Worker 
1679*495ae853SAndroid Build Coastguard Worker         i4_num_words_to_fill-- ;
1680*495ae853SAndroid Build Coastguard Worker     }
1681*495ae853SAndroid Build Coastguard Worker 
1682*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_rbsp_trailing_bits(ps_bitstrm);
1683*495ae853SAndroid Build Coastguard Worker 
1684*495ae853SAndroid Build Coastguard Worker     return return_status;
1685*495ae853SAndroid Build Coastguard Worker }
1686*495ae853SAndroid Build Coastguard Worker 
1687