xref: /aosp_15_r20/external/libavc/encoder/svc/isvce_encode_header.c (revision 495ae853bb871d1e5a258cb02c2cc13cde8ddb9a)
1*495ae853SAndroid Build Coastguard Worker /******************************************************************************
2*495ae853SAndroid Build Coastguard Worker  *
3*495ae853SAndroid Build Coastguard Worker  * Copyright (C) 2022 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 *  isvce_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 *  - isvce_generate_sps()
34*495ae853SAndroid Build Coastguard Worker *  - isvce_generate_pps()
35*495ae853SAndroid Build Coastguard Worker *  - isvce_generate_slice_header()
36*495ae853SAndroid Build Coastguard Worker *  - isvce_populate_sps()
37*495ae853SAndroid Build Coastguard Worker *  - isvce_populate_pps()
38*495ae853SAndroid Build Coastguard Worker *  - isvce_populate_slice_header()
39*495ae853SAndroid Build Coastguard Worker *
40*495ae853SAndroid Build Coastguard Worker *******************************************************************************
41*495ae853SAndroid Build Coastguard Worker */
42*495ae853SAndroid Build Coastguard Worker 
43*495ae853SAndroid Build Coastguard Worker #include "ih264_typedefs.h"
44*495ae853SAndroid Build Coastguard Worker #include "ih264_debug.h"
45*495ae853SAndroid Build Coastguard Worker 
46*495ae853SAndroid Build Coastguard Worker /* Dependencies of ih264e_bitstream.h */
47*495ae853SAndroid Build Coastguard Worker #include "ih264e_error.h"
48*495ae853SAndroid Build Coastguard Worker 
49*495ae853SAndroid Build Coastguard Worker #include "ih264e_bitstream.h"
50*495ae853SAndroid Build Coastguard Worker 
51*495ae853SAndroid Build Coastguard Worker #include "isvce_encode_header.h"
52*495ae853SAndroid Build Coastguard Worker #include "isvce_utils.h"
53*495ae853SAndroid Build Coastguard Worker 
isvce_generate_nal_unit_header(bitstrm_t * ps_bitstrm,WORD32 nal_unit_type,WORD32 nal_ref_idc)54*495ae853SAndroid Build Coastguard Worker static FORCEINLINE IH264E_ERROR_T isvce_generate_nal_unit_header(bitstrm_t *ps_bitstrm,
55*495ae853SAndroid Build Coastguard Worker                                                                  WORD32 nal_unit_type,
56*495ae853SAndroid Build Coastguard Worker                                                                  WORD32 nal_ref_idc)
57*495ae853SAndroid Build Coastguard Worker {
58*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
59*495ae853SAndroid Build Coastguard Worker 
60*495ae853SAndroid Build Coastguard Worker     if(!((nal_unit_type > 0) && (nal_unit_type < 32)))
61*495ae853SAndroid Build Coastguard Worker     {
62*495ae853SAndroid Build Coastguard Worker         return IH264E_FAIL;
63*495ae853SAndroid Build Coastguard Worker     }
64*495ae853SAndroid Build Coastguard Worker 
65*495ae853SAndroid Build Coastguard Worker     /* forbidden_zero_bit + nal_ref_idc + nal_unit_type */
66*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ((nal_ref_idc << 5) + nal_unit_type),
67*495ae853SAndroid Build Coastguard Worker              (1 + 2 + 5), /*1 forbidden zero bit + 2 nal_ref_idc + 5 nal_unit_type */
68*495ae853SAndroid Build Coastguard Worker              return_status, "nal_unit_header");
69*495ae853SAndroid Build Coastguard Worker 
70*495ae853SAndroid Build Coastguard Worker     return return_status;
71*495ae853SAndroid Build Coastguard Worker }
72*495ae853SAndroid Build Coastguard Worker 
73*495ae853SAndroid Build Coastguard Worker /**
74*495ae853SAndroid Build Coastguard Worker ******************************************************************************
75*495ae853SAndroid Build Coastguard Worker *
76*495ae853SAndroid Build Coastguard Worker * @brief Generates SPS (Sequence Parameter Set)
77*495ae853SAndroid Build Coastguard Worker *
78*495ae853SAndroid Build Coastguard Worker * @par   Description
79*495ae853SAndroid Build Coastguard Worker *  This function generates Sequence Parameter Set header as per the spec
80*495ae853SAndroid Build Coastguard Worker *
81*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_bitstrm
82*495ae853SAndroid Build Coastguard Worker *  pointer to bitstream context (handle)
83*495ae853SAndroid Build Coastguard Worker *
84*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_sps
85*495ae853SAndroid Build Coastguard Worker *  pointer to structure containing SPS data
86*495ae853SAndroid Build Coastguard Worker *
87*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_vui
88*495ae853SAndroid Build Coastguard Worker *  pointer to structure containing VUI data
89*495ae853SAndroid Build Coastguard Worker *
90*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
91*495ae853SAndroid Build Coastguard Worker *
92*495ae853SAndroid Build Coastguard Worker ******************************************************************************
93*495ae853SAndroid Build Coastguard Worker */
isvce_generate_sps(bitstrm_t * ps_bitstrm,sps_t * ps_sps,NAL_UNIT_TYPE_T nal_type)94*495ae853SAndroid Build Coastguard Worker WORD32 isvce_generate_sps(bitstrm_t *ps_bitstrm, sps_t *ps_sps, NAL_UNIT_TYPE_T nal_type)
95*495ae853SAndroid Build Coastguard Worker {
96*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
97*495ae853SAndroid Build Coastguard Worker     WORD32 i;
98*495ae853SAndroid Build Coastguard Worker     WORD8 i1_nal_ref_idc = 3;
99*495ae853SAndroid Build Coastguard Worker     vui_t *ps_vui = &ps_sps->s_vui_parameters;
100*495ae853SAndroid Build Coastguard Worker 
101*495ae853SAndroid Build Coastguard Worker     /* Insert Start Code */
102*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
103*495ae853SAndroid Build Coastguard Worker     if(return_status != IH264E_SUCCESS)
104*495ae853SAndroid Build Coastguard Worker     {
105*495ae853SAndroid Build Coastguard Worker         return return_status;
106*495ae853SAndroid Build Coastguard Worker     }
107*495ae853SAndroid Build Coastguard Worker     /* Insert Nal Unit Header */
108*495ae853SAndroid Build Coastguard Worker     return_status = isvce_generate_nal_unit_header(ps_bitstrm, nal_type, i1_nal_ref_idc);
109*495ae853SAndroid Build Coastguard Worker     if(return_status != IH264E_SUCCESS)
110*495ae853SAndroid Build Coastguard Worker     {
111*495ae853SAndroid Build Coastguard Worker         return return_status;
112*495ae853SAndroid Build Coastguard Worker     }
113*495ae853SAndroid Build Coastguard Worker 
114*495ae853SAndroid Build Coastguard Worker     /* profile_idc */
115*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->u1_profile_idc, 8, return_status, "profile_idc");
116*495ae853SAndroid Build Coastguard Worker 
117*495ae853SAndroid Build Coastguard Worker     /* constrained_set_flags */
118*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->u1_constraint_set0_flag, 1, return_status,
119*495ae853SAndroid Build Coastguard Worker              "constrained_set0_flag");
120*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->u1_constraint_set1_flag, 1, return_status,
121*495ae853SAndroid Build Coastguard Worker              "constrained_set1_flag");
122*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->u1_constraint_set2_flag, 1, return_status,
123*495ae853SAndroid Build Coastguard Worker              "constrained_set2_flag");
124*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->u1_constraint_set3_flag, 1, return_status,
125*495ae853SAndroid Build Coastguard Worker              "constrained_set3_flag");
126*495ae853SAndroid Build Coastguard Worker 
127*495ae853SAndroid Build Coastguard Worker     /* reserved_zero_four_bits */
128*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, 0, 4, return_status, "reserved_zero_four_bits");
129*495ae853SAndroid Build Coastguard Worker 
130*495ae853SAndroid Build Coastguard Worker     /* level_idc */
131*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->u1_level_idc, 8, return_status, "level_idc");
132*495ae853SAndroid Build Coastguard Worker 
133*495ae853SAndroid Build Coastguard Worker     /* seq_parameter_set_id */
134*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_sps->u1_sps_id, return_status, "seq_parameter_set_id");
135*495ae853SAndroid Build Coastguard Worker 
136*495ae853SAndroid Build Coastguard Worker     if((ps_sps->u1_profile_idc == IH264_SCALABLE_BASELINE) ||
137*495ae853SAndroid Build Coastguard Worker        (ps_sps->u1_profile_idc >= IH264_PROFILE_HIGH))
138*495ae853SAndroid Build Coastguard Worker     {
139*495ae853SAndroid Build Coastguard Worker         /* chroma_format_idc */
140*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_sps->u1_chroma_format_idc, return_status, "chroma_format_idc");
141*495ae853SAndroid Build Coastguard Worker 
142*495ae853SAndroid Build Coastguard Worker         if(ps_sps->u1_chroma_format_idc == CHROMA_FMT_IDC_YUV444)
143*495ae853SAndroid Build Coastguard Worker         {
144*495ae853SAndroid Build Coastguard Worker             /* i1_residual_colour_transform_flag */
145*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_sps->i1_residual_colour_transform_flag, 1, return_status,
146*495ae853SAndroid Build Coastguard Worker                      "i1_residual_colour_transform_flag");
147*495ae853SAndroid Build Coastguard Worker         }
148*495ae853SAndroid Build Coastguard Worker 
149*495ae853SAndroid Build Coastguard Worker         /* bit_depth_luma_minus8 */
150*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, (ps_sps->i1_bit_depth_luma - 8), return_status,
151*495ae853SAndroid Build Coastguard Worker                      "bit_depth_luma_minus8");
152*495ae853SAndroid Build Coastguard Worker 
153*495ae853SAndroid Build Coastguard Worker         /* bit_depth_chroma_minus8 */
154*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, (ps_sps->i1_bit_depth_chroma - 8), return_status,
155*495ae853SAndroid Build Coastguard Worker                      "bit_depth_chroma_minus8");
156*495ae853SAndroid Build Coastguard Worker 
157*495ae853SAndroid Build Coastguard Worker         /* qpprime_y_zero_transform_bypass_flag */
158*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_sps->i1_qpprime_y_zero_transform_bypass_flag, 1, return_status,
159*495ae853SAndroid Build Coastguard Worker                  "qpprime_y_zero_transform_bypass_flag");
160*495ae853SAndroid Build Coastguard Worker 
161*495ae853SAndroid Build Coastguard Worker         /* seq_scaling_matrix_present_flag */
162*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_sps->i1_seq_scaling_matrix_present_flag, 1, return_status,
163*495ae853SAndroid Build Coastguard Worker                  "seq_scaling_matrix_present_flag");
164*495ae853SAndroid Build Coastguard Worker 
165*495ae853SAndroid Build Coastguard Worker         /* seq_scaling_list */
166*495ae853SAndroid Build Coastguard Worker         if(ps_sps->i1_seq_scaling_matrix_present_flag)
167*495ae853SAndroid Build Coastguard Worker         {
168*495ae853SAndroid Build Coastguard Worker             /* TODO_LATER: Will be enabled once scaling list support is added */
169*495ae853SAndroid Build Coastguard Worker         }
170*495ae853SAndroid Build Coastguard Worker     }
171*495ae853SAndroid Build Coastguard Worker 
172*495ae853SAndroid Build Coastguard Worker     /* log2_max_frame_num_minus4 */
173*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, (ps_sps->i1_log2_max_frame_num - 4), return_status,
174*495ae853SAndroid Build Coastguard Worker                  "log2_max_frame_num_minus4");
175*495ae853SAndroid Build Coastguard Worker 
176*495ae853SAndroid Build Coastguard Worker     /* pic_order_cnt_type */
177*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_sps->i1_pic_order_cnt_type, return_status, "pic_order_cnt_type");
178*495ae853SAndroid Build Coastguard Worker 
179*495ae853SAndroid Build Coastguard Worker     if(ps_sps->i1_pic_order_cnt_type == 0)
180*495ae853SAndroid Build Coastguard Worker     {
181*495ae853SAndroid Build Coastguard Worker         /* log2_max_pic_order_cnt_lsb_minus4 */
182*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, (ps_sps->i1_log2_max_pic_order_cnt_lsb - 4), return_status,
183*495ae853SAndroid Build Coastguard Worker                      "log2_max_pic_order_cnt_lsb_minus4");
184*495ae853SAndroid Build Coastguard Worker     }
185*495ae853SAndroid Build Coastguard Worker     else if(ps_sps->i1_pic_order_cnt_type == 1)
186*495ae853SAndroid Build Coastguard Worker     {
187*495ae853SAndroid Build Coastguard Worker         /* delta_pic_order_always_zero_flag */
188*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_sps->i1_delta_pic_order_always_zero_flag, 1, return_status,
189*495ae853SAndroid Build Coastguard Worker                  "delta_pic_order_always_zero_flag");
190*495ae853SAndroid Build Coastguard Worker 
191*495ae853SAndroid Build Coastguard Worker         /* offset_for_non_ref_pic */
192*495ae853SAndroid Build Coastguard Worker         PUT_BITS_SEV(ps_bitstrm, ps_sps->i4_offset_for_non_ref_pic, return_status,
193*495ae853SAndroid Build Coastguard Worker                      "offset_for_non_ref_pic");
194*495ae853SAndroid Build Coastguard Worker 
195*495ae853SAndroid Build Coastguard Worker         /* offset_for_top_to_bottom_field */
196*495ae853SAndroid Build Coastguard Worker         PUT_BITS_SEV(ps_bitstrm, ps_sps->i4_offset_for_top_to_bottom_field, return_status,
197*495ae853SAndroid Build Coastguard Worker                      "offset_for_top_to_bottom_field");
198*495ae853SAndroid Build Coastguard Worker 
199*495ae853SAndroid Build Coastguard Worker         /* num_ref_frames_in_pic_order_cnt_cycle */
200*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_sps->u1_num_ref_frames_in_pic_order_cnt_cycle, return_status,
201*495ae853SAndroid Build Coastguard Worker                      "num_ref_frames_in_pic_order_cnt_cycle");
202*495ae853SAndroid Build Coastguard Worker 
203*495ae853SAndroid Build Coastguard Worker         /* Offset for ref frame */
204*495ae853SAndroid Build Coastguard Worker         for(i = 0; i < ps_sps->u1_num_ref_frames_in_pic_order_cnt_cycle; i++)
205*495ae853SAndroid Build Coastguard Worker         {
206*495ae853SAndroid Build Coastguard Worker             /* offset_for_ref_frame */
207*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_sps->ai4_offset_for_ref_frame[i], return_status,
208*495ae853SAndroid Build Coastguard Worker                          "offset_for_ref_frame");
209*495ae853SAndroid Build Coastguard Worker         }
210*495ae853SAndroid Build Coastguard Worker     }
211*495ae853SAndroid Build Coastguard Worker 
212*495ae853SAndroid Build Coastguard Worker     /* num_ref_frames */
213*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_sps->u1_max_num_ref_frames, return_status, "num_ref_frames");
214*495ae853SAndroid Build Coastguard Worker 
215*495ae853SAndroid Build Coastguard Worker     /* gaps_in_frame_num_value_allowed_flag */
216*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->i1_gaps_in_frame_num_value_allowed_flag, 1, return_status,
217*495ae853SAndroid Build Coastguard Worker              "gaps_in_frame_num_value_allowed_flag");
218*495ae853SAndroid Build Coastguard Worker 
219*495ae853SAndroid Build Coastguard Worker     /* pic_width_in_mbs_minus1 */
220*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_sps->i2_pic_width_in_mbs_minus1, return_status,
221*495ae853SAndroid Build Coastguard Worker                  "pic_width_in_mbs_minus1");
222*495ae853SAndroid Build Coastguard Worker 
223*495ae853SAndroid Build Coastguard Worker     /* pic_height_in_map_units_minus1 */
224*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_sps->i2_pic_height_in_map_units_minus1, return_status,
225*495ae853SAndroid Build Coastguard Worker                  "pic_height_in_map_units_minus1");
226*495ae853SAndroid Build Coastguard Worker 
227*495ae853SAndroid Build Coastguard Worker     /* frame_mbs_only_flag */
228*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->i1_frame_mbs_only_flag, 1, return_status, "frame_mbs_only_flag");
229*495ae853SAndroid Build Coastguard Worker 
230*495ae853SAndroid Build Coastguard Worker     if(!ps_sps->i1_frame_mbs_only_flag)
231*495ae853SAndroid Build Coastguard Worker     {
232*495ae853SAndroid Build Coastguard Worker         /* mb_adaptive_frame_field_flag */
233*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_sps->i1_mb_adaptive_frame_field_flag, 1, return_status,
234*495ae853SAndroid Build Coastguard Worker                  "mb_adaptive_frame_field_flag");
235*495ae853SAndroid Build Coastguard Worker     }
236*495ae853SAndroid Build Coastguard Worker 
237*495ae853SAndroid Build Coastguard Worker     /* direct_8x8_inference_flag */
238*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->i1_direct_8x8_inference_flag, 1, return_status,
239*495ae853SAndroid Build Coastguard Worker              "direct_8x8_inference_flag");
240*495ae853SAndroid Build Coastguard Worker 
241*495ae853SAndroid Build Coastguard Worker     /* frame_cropping_flag */
242*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->i1_frame_cropping_flag, 1, return_status, "frame_cropping_flag");
243*495ae853SAndroid Build Coastguard Worker 
244*495ae853SAndroid Build Coastguard Worker     if(ps_sps->i1_frame_cropping_flag)
245*495ae853SAndroid Build Coastguard Worker     {
246*495ae853SAndroid Build Coastguard Worker         /* frame_crop_left_offset */
247*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_sps->i2_frame_crop_left_offset, return_status,
248*495ae853SAndroid Build Coastguard Worker                      "frame_crop_left_offset");
249*495ae853SAndroid Build Coastguard Worker 
250*495ae853SAndroid Build Coastguard Worker         /* frame_crop_right_offset */
251*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_sps->i2_frame_crop_right_offset, return_status,
252*495ae853SAndroid Build Coastguard Worker                      "frame_crop_right_offset");
253*495ae853SAndroid Build Coastguard Worker 
254*495ae853SAndroid Build Coastguard Worker         /* frame_crop_top_offset */
255*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_sps->i2_frame_crop_top_offset, return_status,
256*495ae853SAndroid Build Coastguard Worker                      "frame_crop_top_offset");
257*495ae853SAndroid Build Coastguard Worker 
258*495ae853SAndroid Build Coastguard Worker         /* frame_crop_bottom_offset */
259*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_sps->i2_frame_crop_bottom_offset, return_status,
260*495ae853SAndroid Build Coastguard Worker                      "frame_crop_bottom_offset");
261*495ae853SAndroid Build Coastguard Worker     }
262*495ae853SAndroid Build Coastguard Worker 
263*495ae853SAndroid Build Coastguard Worker     /* vui_parameters_present_flag */
264*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sps->i1_vui_parameters_present_flag, 1, return_status,
265*495ae853SAndroid Build Coastguard Worker              "vui_parameters_present_flag");
266*495ae853SAndroid Build Coastguard Worker 
267*495ae853SAndroid Build Coastguard Worker     if(ps_sps->i1_vui_parameters_present_flag)
268*495ae853SAndroid Build Coastguard Worker     {
269*495ae853SAndroid Build Coastguard Worker         /* Add vui parameters to the bitstream */;
270*495ae853SAndroid Build Coastguard Worker         return_status = ih264e_generate_vui(ps_bitstrm, ps_vui);
271*495ae853SAndroid Build Coastguard Worker         if(return_status != IH264E_SUCCESS)
272*495ae853SAndroid Build Coastguard Worker         {
273*495ae853SAndroid Build Coastguard Worker             return return_status;
274*495ae853SAndroid Build Coastguard Worker         }
275*495ae853SAndroid Build Coastguard Worker     }
276*495ae853SAndroid Build Coastguard Worker 
277*495ae853SAndroid Build Coastguard Worker     if(nal_type != NAL_SUBSET_SPS)
278*495ae853SAndroid Build Coastguard Worker     {
279*495ae853SAndroid Build Coastguard Worker         /* rbsp trailing bits */
280*495ae853SAndroid Build Coastguard Worker         return_status = ih264e_put_rbsp_trailing_bits(ps_bitstrm);
281*495ae853SAndroid Build Coastguard Worker     }
282*495ae853SAndroid Build Coastguard Worker 
283*495ae853SAndroid Build Coastguard Worker     return return_status;
284*495ae853SAndroid Build Coastguard Worker }
285*495ae853SAndroid Build Coastguard Worker 
286*495ae853SAndroid Build Coastguard Worker /**
287*495ae853SAndroid Build Coastguard Worker ******************************************************************************
288*495ae853SAndroid Build Coastguard Worker *
289*495ae853SAndroid Build Coastguard Worker * @brief Generates PPS (Picture Parameter Set)
290*495ae853SAndroid Build Coastguard Worker *
291*495ae853SAndroid Build Coastguard Worker * @par   Description
292*495ae853SAndroid Build Coastguard Worker *  Generate Picture Parameter Set as per Section 7.3.2.2
293*495ae853SAndroid Build Coastguard Worker *
294*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_bitstrm
295*495ae853SAndroid Build Coastguard Worker *  pointer to bitstream context (handle)
296*495ae853SAndroid Build Coastguard Worker *
297*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_pps
298*495ae853SAndroid Build Coastguard Worker *  pointer to structure containing PPS data
299*495ae853SAndroid Build Coastguard Worker *
300*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
301*495ae853SAndroid Build Coastguard Worker *
302*495ae853SAndroid Build Coastguard Worker ******************************************************************************
303*495ae853SAndroid Build Coastguard Worker */
isvce_generate_pps(bitstrm_t * ps_bitstrm,pps_t * ps_pps,sps_t * ps_sps)304*495ae853SAndroid Build Coastguard Worker WORD32 isvce_generate_pps(bitstrm_t *ps_bitstrm, pps_t *ps_pps, sps_t *ps_sps)
305*495ae853SAndroid Build Coastguard Worker {
306*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
307*495ae853SAndroid Build Coastguard Worker 
308*495ae853SAndroid Build Coastguard Worker     /* Insert the NAL start code */
309*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
310*495ae853SAndroid Build Coastguard Worker     if(return_status != IH264E_SUCCESS)
311*495ae853SAndroid Build Coastguard Worker     {
312*495ae853SAndroid Build Coastguard Worker         return return_status;
313*495ae853SAndroid Build Coastguard Worker     }
314*495ae853SAndroid Build Coastguard Worker 
315*495ae853SAndroid Build Coastguard Worker     /* Insert Nal Unit Header */
316*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, NAL_PPS_FIRST_BYTE, 8, return_status, "pps_header");
317*495ae853SAndroid Build Coastguard Worker 
318*495ae853SAndroid Build Coastguard Worker     /* pic_parameter_set_id */
319*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_pps->u1_pps_id, return_status, "pic_parameter_set_id");
320*495ae853SAndroid Build Coastguard Worker 
321*495ae853SAndroid Build Coastguard Worker     /* seq_parameter_set_id */
322*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_pps->u1_sps_id, return_status, "seq_parameter_set_id");
323*495ae853SAndroid Build Coastguard Worker 
324*495ae853SAndroid Build Coastguard Worker     /* Entropy coding : 0-VLC; 1 - CABAC */
325*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_pps->u1_entropy_coding_mode_flag, 1, return_status,
326*495ae853SAndroid Build Coastguard Worker              "Entropy coding : 0-VLC; 1 - CABAC");
327*495ae853SAndroid Build Coastguard Worker 
328*495ae853SAndroid Build Coastguard Worker     /* Pic order present flag */
329*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_pps->u1_pic_order_present_flag, 1, return_status,
330*495ae853SAndroid Build Coastguard Worker              "Pic order present flag");
331*495ae853SAndroid Build Coastguard Worker 
332*495ae853SAndroid Build Coastguard Worker     /* Number of slice groups */
333*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_pps->u1_num_slice_groups - 1, return_status,
334*495ae853SAndroid Build Coastguard Worker                  "Number of slice groups");
335*495ae853SAndroid Build Coastguard Worker 
336*495ae853SAndroid Build Coastguard Worker     if(ps_pps->u1_num_slice_groups > 1)
337*495ae853SAndroid Build Coastguard Worker     {
338*495ae853SAndroid Build Coastguard Worker         /* TODO_LATER: Currently the number of slice groups minus 1 is 0.
339*495ae853SAndroid Build Coastguard Worker          * If this is not the case, we have to add Slice group map type to the bit
340*495ae853SAndroid Build Coastguard Worker          * stream*/
341*495ae853SAndroid Build Coastguard Worker     }
342*495ae853SAndroid Build Coastguard Worker 
343*495ae853SAndroid Build Coastguard Worker     /* num_ref_idx_l0_default_active_minus1 */
344*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_pps->i1_num_ref_idx_l0_default_active - 1, return_status,
345*495ae853SAndroid Build Coastguard Worker                  "num_ref_idx_l0_default_active_minus1");
346*495ae853SAndroid Build Coastguard Worker 
347*495ae853SAndroid Build Coastguard Worker     /* num_ref_idx_l1_default_active_minus1 */
348*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_pps->i1_num_ref_idx_l1_default_active - 1, return_status,
349*495ae853SAndroid Build Coastguard Worker                  "num_ref_idx_l1_default_active_minus1");
350*495ae853SAndroid Build Coastguard Worker 
351*495ae853SAndroid Build Coastguard Worker     /* weighted_pred_flag */
352*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_pps->i1_weighted_pred_flag, 1, return_status, "weighted_pred_flag");
353*495ae853SAndroid Build Coastguard Worker 
354*495ae853SAndroid Build Coastguard Worker     /* weighted_bipred_flag */
355*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_pps->i1_weighted_bipred_idc, 2, return_status, "weighted_bipred_idc");
356*495ae853SAndroid Build Coastguard Worker 
357*495ae853SAndroid Build Coastguard Worker     /* pic_init_qp_minus26 */
358*495ae853SAndroid Build Coastguard Worker     PUT_BITS_SEV(ps_bitstrm, ps_pps->i1_pic_init_qp - 26, return_status, "pic_init_qp_minus26");
359*495ae853SAndroid Build Coastguard Worker 
360*495ae853SAndroid Build Coastguard Worker     /* pic_init_qs_minus26 */
361*495ae853SAndroid Build Coastguard Worker     PUT_BITS_SEV(ps_bitstrm, ps_pps->i1_pic_init_qs - 26, return_status, "pic_init_qs_minus26");
362*495ae853SAndroid Build Coastguard Worker 
363*495ae853SAndroid Build Coastguard Worker     /* chroma_qp_index_offset */
364*495ae853SAndroid Build Coastguard Worker     PUT_BITS_SEV(ps_bitstrm, ps_pps->i1_chroma_qp_index_offset, return_status,
365*495ae853SAndroid Build Coastguard Worker                  "chroma_qp_index_offset");
366*495ae853SAndroid Build Coastguard Worker 
367*495ae853SAndroid Build Coastguard Worker     /* deblocking_filter_control_present_flag */
368*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_pps->i1_deblocking_filter_control_present_flag, 1, return_status,
369*495ae853SAndroid Build Coastguard Worker              "deblocking_filter_control_present_flag");
370*495ae853SAndroid Build Coastguard Worker 
371*495ae853SAndroid Build Coastguard Worker     /* constrained_intra_pred_flag */
372*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_pps->i1_constrained_intra_pred_flag, 1, return_status,
373*495ae853SAndroid Build Coastguard Worker              "constrained_intra_pred_flag");
374*495ae853SAndroid Build Coastguard Worker 
375*495ae853SAndroid Build Coastguard Worker     /*redundant_pic_cnt_present_flag */
376*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_pps->i1_redundant_pic_cnt_present_flag, 1, return_status,
377*495ae853SAndroid Build Coastguard Worker              "redundant_pic_cnt_present_flag");
378*495ae853SAndroid Build Coastguard Worker 
379*495ae853SAndroid Build Coastguard Worker     if(ps_sps->u1_profile_idc >= IH264_PROFILE_HIGH)
380*495ae853SAndroid Build Coastguard Worker     {
381*495ae853SAndroid Build Coastguard Worker         /* transform_8x8_mode_flag */
382*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_pps->i1_transform_8x8_mode_flag, 1, return_status,
383*495ae853SAndroid Build Coastguard Worker                  "transform_8x8_mode_flag");
384*495ae853SAndroid Build Coastguard Worker 
385*495ae853SAndroid Build Coastguard Worker         /* pic_scaling_matrix_present_flag */
386*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_pps->i1_pic_scaling_matrix_present_flag, 1, return_status,
387*495ae853SAndroid Build Coastguard Worker                  "pic_scaling_matrix_present_flag");
388*495ae853SAndroid Build Coastguard Worker 
389*495ae853SAndroid Build Coastguard Worker         if(ps_pps->i1_pic_scaling_matrix_present_flag)
390*495ae853SAndroid Build Coastguard Worker         {
391*495ae853SAndroid Build Coastguard Worker             /* TODO_LATER: Will be enabled once scaling list support is added */
392*495ae853SAndroid Build Coastguard Worker         }
393*495ae853SAndroid Build Coastguard Worker 
394*495ae853SAndroid Build Coastguard Worker         /* Second chroma QP offset */
395*495ae853SAndroid Build Coastguard Worker         PUT_BITS_SEV(ps_bitstrm, ps_pps->i1_second_chroma_qp_index_offset, return_status,
396*495ae853SAndroid Build Coastguard Worker                      "Second chroma QP offset");
397*495ae853SAndroid Build Coastguard Worker     }
398*495ae853SAndroid Build Coastguard Worker 
399*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_rbsp_trailing_bits(ps_bitstrm);
400*495ae853SAndroid Build Coastguard Worker 
401*495ae853SAndroid Build Coastguard Worker     return return_status;
402*495ae853SAndroid Build Coastguard Worker }
403*495ae853SAndroid Build Coastguard Worker 
404*495ae853SAndroid Build Coastguard Worker /**
405*495ae853SAndroid Build Coastguard Worker ******************************************************************************
406*495ae853SAndroid Build Coastguard Worker *
407*495ae853SAndroid Build Coastguard Worker * @brief Generates Slice Header
408*495ae853SAndroid Build Coastguard Worker *
409*495ae853SAndroid Build Coastguard Worker * @par   Description
410*495ae853SAndroid Build Coastguard Worker *  Generate Slice Header as per Section 7.3.5.1
411*495ae853SAndroid Build Coastguard Worker *
412*495ae853SAndroid Build Coastguard Worker * @param[inout]   ps_bitstrm
413*495ae853SAndroid Build Coastguard Worker *  pointer to bitstream context for generating slice header
414*495ae853SAndroid Build Coastguard Worker *
415*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_slice_hdr
416*495ae853SAndroid Build Coastguard Worker *  pointer to slice header params
417*495ae853SAndroid Build Coastguard Worker *
418*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_pps
419*495ae853SAndroid Build Coastguard Worker *  pointer to pps params referred by slice
420*495ae853SAndroid Build Coastguard Worker *
421*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_sps
422*495ae853SAndroid Build Coastguard Worker *  pointer to sps params referred by slice
423*495ae853SAndroid Build Coastguard Worker *
424*495ae853SAndroid Build Coastguard Worker * @param[out]   ps_dup_bit_strm_ent_offset
425*495ae853SAndroid Build Coastguard Worker *  Bitstream struct to store bitstream state
426*495ae853SAndroid Build Coastguard Worker *
427*495ae853SAndroid Build Coastguard Worker * @param[out]   pu4_first_slice_start_offset
428*495ae853SAndroid Build Coastguard Worker *  first slice offset is returned
429*495ae853SAndroid Build Coastguard Worker *
430*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
431*495ae853SAndroid Build Coastguard Worker *
432*495ae853SAndroid Build Coastguard Worker ******************************************************************************
433*495ae853SAndroid Build Coastguard Worker */
isvce_generate_slice_header(bitstrm_t * ps_bitstrm,slice_header_t * ps_slice_hdr,pps_t * ps_pps,sps_t * ps_sps,UWORD8 u1_idr_flag)434*495ae853SAndroid Build Coastguard Worker WORD32 isvce_generate_slice_header(bitstrm_t *ps_bitstrm, slice_header_t *ps_slice_hdr,
435*495ae853SAndroid Build Coastguard Worker                                    pps_t *ps_pps, sps_t *ps_sps, UWORD8 u1_idr_flag)
436*495ae853SAndroid Build Coastguard Worker {
437*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
438*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_slice_type;
439*495ae853SAndroid Build Coastguard Worker 
440*495ae853SAndroid Build Coastguard Worker     /* Insert start code */
441*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
442*495ae853SAndroid Build Coastguard Worker     if(return_status != IH264E_SUCCESS)
443*495ae853SAndroid Build Coastguard Worker     {
444*495ae853SAndroid Build Coastguard Worker         return return_status;
445*495ae853SAndroid Build Coastguard Worker     }
446*495ae853SAndroid Build Coastguard Worker     /* Insert Nal Unit Header */
447*495ae853SAndroid Build Coastguard Worker     return_status = isvce_generate_nal_unit_header(ps_bitstrm, ps_slice_hdr->i1_nal_unit_type,
448*495ae853SAndroid Build Coastguard Worker                                                    ps_slice_hdr->i1_nal_unit_idc);
449*495ae853SAndroid Build Coastguard Worker     if(return_status != IH264E_SUCCESS)
450*495ae853SAndroid Build Coastguard Worker     {
451*495ae853SAndroid Build Coastguard Worker         return return_status;
452*495ae853SAndroid Build Coastguard Worker     }
453*495ae853SAndroid Build Coastguard Worker     /* first_mb_in_slice */
454*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u2_first_mb_in_slice, return_status,
455*495ae853SAndroid Build Coastguard Worker                  "first_mb_in_slice");
456*495ae853SAndroid Build Coastguard Worker 
457*495ae853SAndroid Build Coastguard Worker     /* slice_type */
458*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u1_slice_type, return_status, "slice_type");
459*495ae853SAndroid Build Coastguard Worker 
460*495ae853SAndroid Build Coastguard Worker     /* pic_parameter_set_id */
461*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u1_pps_id, return_status, "pic_parameter_set_id");
462*495ae853SAndroid Build Coastguard Worker 
463*495ae853SAndroid Build Coastguard Worker     /* frame_num */
464*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_slice_hdr->i4_frame_num, ps_sps->i1_log2_max_frame_num, return_status,
465*495ae853SAndroid Build Coastguard Worker              "frame_num");
466*495ae853SAndroid Build Coastguard Worker 
467*495ae853SAndroid Build Coastguard Worker     if(!ps_sps->i1_frame_mbs_only_flag)
468*495ae853SAndroid Build Coastguard Worker     {
469*495ae853SAndroid Build Coastguard Worker         /* field_pic_flag */
470*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_slice_hdr->i1_field_pic_flag, 1, return_status, "field_pic_flag");
471*495ae853SAndroid Build Coastguard Worker 
472*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->i1_field_pic_flag)
473*495ae853SAndroid Build Coastguard Worker         {
474*495ae853SAndroid Build Coastguard Worker             /* bottom_field_flag */
475*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_hdr->i1_bottom_field_flag, 1, return_status,
476*495ae853SAndroid Build Coastguard Worker                      "bottom_field_flag");
477*495ae853SAndroid Build Coastguard Worker         }
478*495ae853SAndroid Build Coastguard Worker     }
479*495ae853SAndroid Build Coastguard Worker 
480*495ae853SAndroid Build Coastguard Worker     if(u1_idr_flag == 1)
481*495ae853SAndroid Build Coastguard Worker     {
482*495ae853SAndroid Build Coastguard Worker         /* u2_idr_pic_id */
483*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u2_idr_pic_id, return_status, "idr_pic_id");
484*495ae853SAndroid Build Coastguard Worker     }
485*495ae853SAndroid Build Coastguard Worker 
486*495ae853SAndroid Build Coastguard Worker     if(ps_sps->i1_pic_order_cnt_type == 0)
487*495ae853SAndroid Build Coastguard Worker     {
488*495ae853SAndroid Build Coastguard Worker         /* pic_order_cnt_lsb */
489*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_slice_hdr->i4_pic_order_cnt_lsb,
490*495ae853SAndroid Build Coastguard Worker                  ps_sps->i1_log2_max_pic_order_cnt_lsb, return_status, "pic_order_cnt_lsb");
491*495ae853SAndroid Build Coastguard Worker 
492*495ae853SAndroid Build Coastguard Worker         if(ps_pps->u1_pic_order_present_flag && !ps_slice_hdr->i1_field_pic_flag)
493*495ae853SAndroid Build Coastguard Worker         {
494*495ae853SAndroid Build Coastguard Worker             /* delta_pic_order_cnt_bottom */
495*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->i4_delta_pic_order_cnt_bottom, return_status,
496*495ae853SAndroid Build Coastguard Worker                          "delta_pic_order_cnt_bottom");
497*495ae853SAndroid Build Coastguard Worker         }
498*495ae853SAndroid Build Coastguard Worker     }
499*495ae853SAndroid Build Coastguard Worker 
500*495ae853SAndroid Build Coastguard Worker     if(ps_sps->i1_pic_order_cnt_type == 1 && !ps_sps->i1_delta_pic_order_always_zero_flag)
501*495ae853SAndroid Build Coastguard Worker     {
502*495ae853SAndroid Build Coastguard Worker         /* delta_pic_order_cnt[0] */
503*495ae853SAndroid Build Coastguard Worker         PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->ai4_delta_pic_order_cnt[0], return_status,
504*495ae853SAndroid Build Coastguard Worker                      "delta_pic_order_cnt[0]");
505*495ae853SAndroid Build Coastguard Worker 
506*495ae853SAndroid Build Coastguard Worker         if(ps_pps->u1_pic_order_present_flag && !ps_slice_hdr->i1_field_pic_flag)
507*495ae853SAndroid Build Coastguard Worker         {
508*495ae853SAndroid Build Coastguard Worker             /* delta_pic_order_cnt[1] */
509*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->ai4_delta_pic_order_cnt[1], return_status,
510*495ae853SAndroid Build Coastguard Worker                          "delta_pic_order_cnt[1]");
511*495ae853SAndroid Build Coastguard Worker         }
512*495ae853SAndroid Build Coastguard Worker     }
513*495ae853SAndroid Build Coastguard Worker 
514*495ae853SAndroid Build Coastguard Worker     if(ps_pps->i1_redundant_pic_cnt_present_flag)
515*495ae853SAndroid Build Coastguard Worker     {
516*495ae853SAndroid Build Coastguard Worker         /* redundant_pic_cnt */
517*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u1_redundant_pic_cnt, return_status,
518*495ae853SAndroid Build Coastguard Worker                      "redundant_pic_cnt");
519*495ae853SAndroid Build Coastguard Worker     }
520*495ae853SAndroid Build Coastguard Worker 
521*495ae853SAndroid Build Coastguard Worker     u1_slice_type = ps_slice_hdr->u1_slice_type % EPSLICE;
522*495ae853SAndroid Build Coastguard Worker 
523*495ae853SAndroid Build Coastguard Worker     if(u1_slice_type == BSLICE)
524*495ae853SAndroid Build Coastguard Worker     {
525*495ae853SAndroid Build Coastguard Worker         /* direct_spatial_mv_pred_flag */
526*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_direct_spatial_mv_pred_flag, 1, return_status,
527*495ae853SAndroid Build Coastguard Worker                  "direct_spatial_mv_pred_flag");
528*495ae853SAndroid Build Coastguard Worker     }
529*495ae853SAndroid Build Coastguard Worker 
530*495ae853SAndroid Build Coastguard Worker     if(u1_slice_type == PSLICE || u1_slice_type == SPSLICE || u1_slice_type == BSLICE)
531*495ae853SAndroid Build Coastguard Worker     {
532*495ae853SAndroid Build Coastguard Worker         /* num_ref_idx_active_override_flag */
533*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_num_ref_idx_active_override_flag, 1, return_status,
534*495ae853SAndroid Build Coastguard Worker                  "num_ref_idx_active_override_flag");
535*495ae853SAndroid Build Coastguard Worker 
536*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->u1_num_ref_idx_active_override_flag)
537*495ae853SAndroid Build Coastguard Worker         {
538*495ae853SAndroid Build Coastguard Worker             /* num_ref_idx_l0_active_minus1 */
539*495ae853SAndroid Build Coastguard Worker             PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->i1_num_ref_idx_l0_active - 1, return_status,
540*495ae853SAndroid Build Coastguard Worker                          "num_ref_idx_l0_active_minus1");
541*495ae853SAndroid Build Coastguard Worker 
542*495ae853SAndroid Build Coastguard Worker             if(u1_slice_type == BSLICE)
543*495ae853SAndroid Build Coastguard Worker             {
544*495ae853SAndroid Build Coastguard Worker                 /* num_ref_idx_l1_active_minus1 */
545*495ae853SAndroid Build Coastguard Worker                 PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->i1_num_ref_idx_l1_active - 1, return_status,
546*495ae853SAndroid Build Coastguard Worker                              "num_ref_idx_l1_active_minus1");
547*495ae853SAndroid Build Coastguard Worker             }
548*495ae853SAndroid Build Coastguard Worker         }
549*495ae853SAndroid Build Coastguard Worker     }
550*495ae853SAndroid Build Coastguard Worker 
551*495ae853SAndroid Build Coastguard Worker     /* ref_pic_list_modification */
552*495ae853SAndroid Build Coastguard Worker     if((u1_slice_type != ISLICE) && (u1_slice_type != SISLICE))
553*495ae853SAndroid Build Coastguard Worker     {
554*495ae853SAndroid Build Coastguard Worker         /* ref_pic_list_modification_flag_l0 */
555*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l0, 1,
556*495ae853SAndroid Build Coastguard Worker                  return_status, "ref_pic_list_modification_flag_l0");
557*495ae853SAndroid Build Coastguard Worker 
558*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l0)
559*495ae853SAndroid Build Coastguard Worker         {
560*495ae853SAndroid Build Coastguard Worker             UWORD8 i = 0;
561*495ae853SAndroid Build Coastguard Worker 
562*495ae853SAndroid Build Coastguard Worker             WORD8 *pi1_modification_of_pic_nums_idc_l0 =
563*495ae853SAndroid Build Coastguard Worker                 ps_slice_hdr->s_rplm.i1_modification_of_pic_nums_idc_l0;
564*495ae853SAndroid Build Coastguard Worker             UWORD32 *pu4_abs_diff_pic_num_minus1_l0 =
565*495ae853SAndroid Build Coastguard Worker                 ps_slice_hdr->s_rplm.u4_abs_diff_pic_num_minus1_l0;
566*495ae853SAndroid Build Coastguard Worker             UWORD8 *pu1_long_term_pic_num_l0 = ps_slice_hdr->s_rplm.u1_long_term_pic_num_l0;
567*495ae853SAndroid Build Coastguard Worker 
568*495ae853SAndroid Build Coastguard Worker             do
569*495ae853SAndroid Build Coastguard Worker             {
570*495ae853SAndroid Build Coastguard Worker                 /* modification_of_pic_nums_idc */
571*495ae853SAndroid Build Coastguard Worker                 PUT_BITS_UEV(ps_bitstrm, pi1_modification_of_pic_nums_idc_l0[i], return_status,
572*495ae853SAndroid Build Coastguard Worker                              "modification_of_pic_nums_idc");
573*495ae853SAndroid Build Coastguard Worker 
574*495ae853SAndroid Build Coastguard Worker                 if((0 == pi1_modification_of_pic_nums_idc_l0[i]) ||
575*495ae853SAndroid Build Coastguard Worker                    (1 == pi1_modification_of_pic_nums_idc_l0[i]))
576*495ae853SAndroid Build Coastguard Worker                 {
577*495ae853SAndroid Build Coastguard Worker                     /* abs_diff_pic_num_minus1 */
578*495ae853SAndroid Build Coastguard Worker                     PUT_BITS_UEV(ps_bitstrm, pu4_abs_diff_pic_num_minus1_l0[0], return_status,
579*495ae853SAndroid Build Coastguard Worker                                  "abs_diff_pic_num_minus1");
580*495ae853SAndroid Build Coastguard Worker 
581*495ae853SAndroid Build Coastguard Worker                     pu4_abs_diff_pic_num_minus1_l0++;
582*495ae853SAndroid Build Coastguard Worker                 }
583*495ae853SAndroid Build Coastguard Worker                 else if(2 == pi1_modification_of_pic_nums_idc_l0[i])
584*495ae853SAndroid Build Coastguard Worker                 {
585*495ae853SAndroid Build Coastguard Worker                     /* long_term_pic_num */
586*495ae853SAndroid Build Coastguard Worker                     PUT_BITS_UEV(ps_bitstrm, pu1_long_term_pic_num_l0[0], return_status,
587*495ae853SAndroid Build Coastguard Worker                                  "abs_diff_pic_num_minus1");
588*495ae853SAndroid Build Coastguard Worker 
589*495ae853SAndroid Build Coastguard Worker                     pu1_long_term_pic_num_l0++;
590*495ae853SAndroid Build Coastguard Worker                 }
591*495ae853SAndroid Build Coastguard Worker             } while(pi1_modification_of_pic_nums_idc_l0[i++] != 3);
592*495ae853SAndroid Build Coastguard Worker         }
593*495ae853SAndroid Build Coastguard Worker     }
594*495ae853SAndroid Build Coastguard Worker 
595*495ae853SAndroid Build Coastguard Worker     if(u1_slice_type == BSLICE)
596*495ae853SAndroid Build Coastguard Worker     {
597*495ae853SAndroid Build Coastguard Worker         /* ref_pic_list_modification_flag_l1 */
598*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l1, 1,
599*495ae853SAndroid Build Coastguard Worker                  return_status, "ref_pic_list_modification_flag_l1");
600*495ae853SAndroid Build Coastguard Worker 
601*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l1)
602*495ae853SAndroid Build Coastguard Worker         {
603*495ae853SAndroid Build Coastguard Worker             UWORD8 i = 0;
604*495ae853SAndroid Build Coastguard Worker 
605*495ae853SAndroid Build Coastguard Worker             WORD8 *pi1_modification_of_pic_nums_idc_l1 =
606*495ae853SAndroid Build Coastguard Worker                 ps_slice_hdr->s_rplm.i1_modification_of_pic_nums_idc_l1;
607*495ae853SAndroid Build Coastguard Worker             UWORD32 *pu4_abs_diff_pic_num_minus1_l1 =
608*495ae853SAndroid Build Coastguard Worker                 ps_slice_hdr->s_rplm.u4_abs_diff_pic_num_minus1_l1;
609*495ae853SAndroid Build Coastguard Worker             UWORD8 *pu1_long_term_pic_num_l1 = ps_slice_hdr->s_rplm.u1_long_term_pic_num_l1;
610*495ae853SAndroid Build Coastguard Worker 
611*495ae853SAndroid Build Coastguard Worker             do
612*495ae853SAndroid Build Coastguard Worker             {
613*495ae853SAndroid Build Coastguard Worker                 /* modification_of_pic_nums_idc */
614*495ae853SAndroid Build Coastguard Worker                 PUT_BITS_UEV(ps_bitstrm, pi1_modification_of_pic_nums_idc_l1[i], return_status,
615*495ae853SAndroid Build Coastguard Worker                              "modification_of_pic_nums_idc");
616*495ae853SAndroid Build Coastguard Worker 
617*495ae853SAndroid Build Coastguard Worker                 if((0 == pi1_modification_of_pic_nums_idc_l1[i]) ||
618*495ae853SAndroid Build Coastguard Worker                    (1 == pi1_modification_of_pic_nums_idc_l1[i]))
619*495ae853SAndroid Build Coastguard Worker                 {
620*495ae853SAndroid Build Coastguard Worker                     /* abs_diff_pic_num_minus1 */
621*495ae853SAndroid Build Coastguard Worker                     PUT_BITS_UEV(ps_bitstrm, pu4_abs_diff_pic_num_minus1_l1[0], return_status,
622*495ae853SAndroid Build Coastguard Worker                                  "abs_diff_pic_num_minus1");
623*495ae853SAndroid Build Coastguard Worker 
624*495ae853SAndroid Build Coastguard Worker                     pu4_abs_diff_pic_num_minus1_l1++;
625*495ae853SAndroid Build Coastguard Worker                 }
626*495ae853SAndroid Build Coastguard Worker                 else if(2 == pi1_modification_of_pic_nums_idc_l1[i])
627*495ae853SAndroid Build Coastguard Worker                 {
628*495ae853SAndroid Build Coastguard Worker                     /* long_term_pic_num */
629*495ae853SAndroid Build Coastguard Worker                     PUT_BITS_UEV(ps_bitstrm, pu1_long_term_pic_num_l1[0], return_status,
630*495ae853SAndroid Build Coastguard Worker                                  "abs_diff_pic_num_minus1");
631*495ae853SAndroid Build Coastguard Worker 
632*495ae853SAndroid Build Coastguard Worker                     pu1_long_term_pic_num_l1++;
633*495ae853SAndroid Build Coastguard Worker                 }
634*495ae853SAndroid Build Coastguard Worker             } while(pi1_modification_of_pic_nums_idc_l1[i++] != 3);
635*495ae853SAndroid Build Coastguard Worker         }
636*495ae853SAndroid Build Coastguard Worker     }
637*495ae853SAndroid Build Coastguard Worker 
638*495ae853SAndroid Build Coastguard Worker     if((ps_pps->i1_weighted_pred_flag && u1_slice_type == PSLICE) ||
639*495ae853SAndroid Build Coastguard Worker        (u1_slice_type == BSLICE && ps_pps->i1_weighted_bipred_idc == 1))
640*495ae853SAndroid Build Coastguard Worker     {
641*495ae853SAndroid Build Coastguard Worker         /* TODO_LATER: Currently there is no support for weighted prediction.
642*495ae853SAndroid Build Coastguard Worker          This needs to be updated when the support is added */
643*495ae853SAndroid Build Coastguard Worker     }
644*495ae853SAndroid Build Coastguard Worker 
645*495ae853SAndroid Build Coastguard Worker     if(ps_slice_hdr->i1_nal_unit_idc != 0)
646*495ae853SAndroid Build Coastguard Worker     {
647*495ae853SAndroid Build Coastguard Worker         if(u1_idr_flag == 1)
648*495ae853SAndroid Build Coastguard Worker         {
649*495ae853SAndroid Build Coastguard Worker             /* no_output_of_prior_pics_flag  */
650*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_no_output_of_prior_pics_flag, 1, return_status,
651*495ae853SAndroid Build Coastguard Worker                      "no_output_of_prior_pics_flag ");
652*495ae853SAndroid Build Coastguard Worker 
653*495ae853SAndroid Build Coastguard Worker             /* long_term_reference_flag  */
654*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_long_term_reference_flag, 1, return_status,
655*495ae853SAndroid Build Coastguard Worker                      "long_term_reference_flag ");
656*495ae853SAndroid Build Coastguard Worker         }
657*495ae853SAndroid Build Coastguard Worker         else
658*495ae853SAndroid Build Coastguard Worker         {
659*495ae853SAndroid Build Coastguard Worker             /* adaptive_ref_pic_marking_mode_flag  */
660*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_adaptive_ref_pic_marking_mode_flag, 1,
661*495ae853SAndroid Build Coastguard Worker                      return_status, "adaptive_ref_pic_marking_mode_flag ");
662*495ae853SAndroid Build Coastguard Worker 
663*495ae853SAndroid Build Coastguard Worker             if(ps_slice_hdr->u1_adaptive_ref_pic_marking_mode_flag)
664*495ae853SAndroid Build Coastguard Worker             {
665*495ae853SAndroid Build Coastguard Worker                 /* TODO: if the reference picture marking mode is adaptive
666*495ae853SAndroid Build Coastguard Worker                  add these fields in the bit-stream */
667*495ae853SAndroid Build Coastguard Worker             }
668*495ae853SAndroid Build Coastguard Worker         }
669*495ae853SAndroid Build Coastguard Worker     }
670*495ae853SAndroid Build Coastguard Worker 
671*495ae853SAndroid Build Coastguard Worker     if(ps_slice_hdr->u1_entropy_coding_mode_flag && u1_slice_type != ISLICE &&
672*495ae853SAndroid Build Coastguard Worker        u1_slice_type != SISLICE)
673*495ae853SAndroid Build Coastguard Worker     {
674*495ae853SAndroid Build Coastguard Worker         /* cabac_init_idc */
675*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->i1_cabac_init_idc, return_status, "cabac_init_idc");
676*495ae853SAndroid Build Coastguard Worker     }
677*495ae853SAndroid Build Coastguard Worker 
678*495ae853SAndroid Build Coastguard Worker     /* slice_qp_delta */
679*495ae853SAndroid Build Coastguard Worker     PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->i1_slice_qp - ps_pps->i1_pic_init_qp, return_status,
680*495ae853SAndroid Build Coastguard Worker                  "slice_qp_delta");
681*495ae853SAndroid Build Coastguard Worker 
682*495ae853SAndroid Build Coastguard Worker     if(ps_slice_hdr->u1_slice_type == SPSLICE || ps_slice_hdr->u1_slice_type == SISLICE)
683*495ae853SAndroid Build Coastguard Worker     {
684*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->u1_slice_type == SPSLICE)
685*495ae853SAndroid Build Coastguard Worker         {
686*495ae853SAndroid Build Coastguard Worker             /* sp_for_switch_flag */
687*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_sp_for_switch_flag, 1, return_status,
688*495ae853SAndroid Build Coastguard Worker                      "sp_for_switch_flag");
689*495ae853SAndroid Build Coastguard Worker         }
690*495ae853SAndroid Build Coastguard Worker         /* slice_qs_delta */
691*495ae853SAndroid Build Coastguard Worker         PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->u1_slice_qs - ps_pps->i1_pic_init_qs, return_status,
692*495ae853SAndroid Build Coastguard Worker                      "slice_qs_delta");
693*495ae853SAndroid Build Coastguard Worker     }
694*495ae853SAndroid Build Coastguard Worker 
695*495ae853SAndroid Build Coastguard Worker     if(ps_pps->i1_deblocking_filter_control_present_flag)
696*495ae853SAndroid Build Coastguard Worker     {
697*495ae853SAndroid Build Coastguard Worker         /* disable_deblocking_filter_idc */
698*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u1_disable_deblocking_filter_idc, return_status,
699*495ae853SAndroid Build Coastguard Worker                      "disable_deblocking_filter_idc");
700*495ae853SAndroid Build Coastguard Worker 
701*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->u1_disable_deblocking_filter_idc != 1)
702*495ae853SAndroid Build Coastguard Worker         {
703*495ae853SAndroid Build Coastguard Worker             /* slice_alpha_c0_offset_div2 */
704*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->i1_slice_alpha_c0_offset_div2, return_status,
705*495ae853SAndroid Build Coastguard Worker                          "slice_alpha_c0_offset_div2");
706*495ae853SAndroid Build Coastguard Worker 
707*495ae853SAndroid Build Coastguard Worker             /* slice_beta_offset_div2 */
708*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->i1_slice_beta_offset_div2, return_status,
709*495ae853SAndroid Build Coastguard Worker                          "slice_beta_offset_div2");
710*495ae853SAndroid Build Coastguard Worker         }
711*495ae853SAndroid Build Coastguard Worker     }
712*495ae853SAndroid Build Coastguard Worker 
713*495ae853SAndroid Build Coastguard Worker     if(ps_slice_hdr->u1_num_slice_groups_minus1 > 0 && ps_pps->u1_slice_group_map_type >= 3 &&
714*495ae853SAndroid Build Coastguard Worker        ps_pps->u1_slice_group_map_type <= 5)
715*495ae853SAndroid Build Coastguard Worker     {
716*495ae853SAndroid Build Coastguard Worker         /* slice_group_change_cycle */
717*495ae853SAndroid Build Coastguard Worker         /* TODO_LATER: Currently the number of slice groups minus 1 is 0.
718*495ae853SAndroid Build Coastguard Worker          * If this is not the case, we have to add Slice group map type to the bit
719*495ae853SAndroid Build Coastguard Worker          * stream */
720*495ae853SAndroid Build Coastguard Worker     }
721*495ae853SAndroid Build Coastguard Worker 
722*495ae853SAndroid Build Coastguard Worker     return return_status;
723*495ae853SAndroid Build Coastguard Worker }
724*495ae853SAndroid Build Coastguard Worker 
725*495ae853SAndroid Build Coastguard Worker /**
726*495ae853SAndroid Build Coastguard Worker ******************************************************************************
727*495ae853SAndroid Build Coastguard Worker *
728*495ae853SAndroid Build Coastguard Worker * @brief Populates VUI structure
729*495ae853SAndroid Build Coastguard Worker *
730*495ae853SAndroid Build Coastguard Worker * @par   Description
731*495ae853SAndroid Build Coastguard Worker *  Populates VUI structure for its use in header generation
732*495ae853SAndroid Build Coastguard Worker *
733*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_codec
734*495ae853SAndroid Build Coastguard Worker *  pointer to encoder context
735*495ae853SAndroid Build Coastguard Worker *
736*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
737*495ae853SAndroid Build Coastguard Worker *
738*495ae853SAndroid Build Coastguard Worker ******************************************************************************
739*495ae853SAndroid Build Coastguard Worker */
isvce_populate_vui(isvce_codec_t * ps_codec,sps_t * ps_sps)740*495ae853SAndroid Build Coastguard Worker static IH264E_ERROR_T isvce_populate_vui(isvce_codec_t *ps_codec, sps_t *ps_sps)
741*495ae853SAndroid Build Coastguard Worker {
742*495ae853SAndroid Build Coastguard Worker     vui_t *ps_vui = &ps_sps->s_vui_parameters;
743*495ae853SAndroid Build Coastguard Worker 
744*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_nal_hrd_parameters_present_flag = 0;
745*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_vcl_hrd_parameters_present_flag = 0;
746*495ae853SAndroid Build Coastguard Worker 
747*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_bitstream_restriction_flag = 1;
748*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_motion_vectors_over_pic_boundaries_flag = 1;
749*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_max_bytes_per_pic_denom = 0;
750*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_max_bits_per_mb_denom = 0;
751*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_log2_max_mv_length_horizontal = 16;
752*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_log2_max_mv_length_vertical = 16;
753*495ae853SAndroid Build Coastguard Worker 
754*495ae853SAndroid Build Coastguard Worker     if(ps_codec->s_cfg.u4_num_bframes == 0)
755*495ae853SAndroid Build Coastguard Worker     {
756*495ae853SAndroid Build Coastguard Worker         ps_vui->u1_num_reorder_frames = 0;
757*495ae853SAndroid Build Coastguard Worker     }
758*495ae853SAndroid Build Coastguard Worker     else
759*495ae853SAndroid Build Coastguard Worker     {
760*495ae853SAndroid Build Coastguard Worker         ps_vui->u1_num_reorder_frames = 1;
761*495ae853SAndroid Build Coastguard Worker     }
762*495ae853SAndroid Build Coastguard Worker 
763*495ae853SAndroid Build Coastguard Worker     ps_vui->u1_max_dec_frame_buffering = ps_sps->u1_max_num_ref_frames;
764*495ae853SAndroid Build Coastguard Worker 
765*495ae853SAndroid Build Coastguard Worker     return 0;
766*495ae853SAndroid Build Coastguard Worker }
767*495ae853SAndroid Build Coastguard Worker 
768*495ae853SAndroid Build Coastguard Worker /**
769*495ae853SAndroid Build Coastguard Worker ******************************************************************************
770*495ae853SAndroid Build Coastguard Worker *
771*495ae853SAndroid Build Coastguard Worker * @brief Populates sps structure
772*495ae853SAndroid Build Coastguard Worker *
773*495ae853SAndroid Build Coastguard Worker * @par   Description
774*495ae853SAndroid Build Coastguard Worker *  Populates sps structure for its use in header generation
775*495ae853SAndroid Build Coastguard Worker *
776*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_codec
777*495ae853SAndroid Build Coastguard Worker *  pointer to encoder context
778*495ae853SAndroid Build Coastguard Worker *
779*495ae853SAndroid Build Coastguard Worker * @param[out]  ps_sps
780*495ae853SAndroid Build Coastguard Worker *  pointer to sps params that needs to be populated
781*495ae853SAndroid Build Coastguard Worker *
782*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
783*495ae853SAndroid Build Coastguard Worker *
784*495ae853SAndroid Build Coastguard Worker ******************************************************************************
785*495ae853SAndroid Build Coastguard Worker */
isvce_populate_sps(isvce_codec_t * ps_codec,sps_t * ps_sps,UWORD8 u1_sps_id,UWORD8 u1_profile_idc,isvce_inp_buf_t * ps_inp_buf,UWORD8 u1_spatial_layer_id)786*495ae853SAndroid Build Coastguard Worker IH264E_ERROR_T isvce_populate_sps(isvce_codec_t *ps_codec, sps_t *ps_sps, UWORD8 u1_sps_id,
787*495ae853SAndroid Build Coastguard Worker                                   UWORD8 u1_profile_idc, isvce_inp_buf_t *ps_inp_buf,
788*495ae853SAndroid Build Coastguard Worker                                   UWORD8 u1_spatial_layer_id)
789*495ae853SAndroid Build Coastguard Worker {
790*495ae853SAndroid Build Coastguard Worker     /* active config parameters */
791*495ae853SAndroid Build Coastguard Worker     isvce_cfg_params_t *ps_cfg = &(ps_codec->s_cfg);
792*495ae853SAndroid Build Coastguard Worker 
793*495ae853SAndroid Build Coastguard Worker     //    /* level */
794*495ae853SAndroid Build Coastguard Worker     //    IH264_LEVEL_T   level_idc;
795*495ae853SAndroid Build Coastguard Worker 
796*495ae853SAndroid Build Coastguard Worker     /* error_status */
797*495ae853SAndroid Build Coastguard Worker     IH264E_ERROR_T i4_err_code = IH264E_FAIL;
798*495ae853SAndroid Build Coastguard Worker 
799*495ae853SAndroid Build Coastguard Worker     /* profile */
800*495ae853SAndroid Build Coastguard Worker     /*
801*495ae853SAndroid Build Coastguard Worker      * Baseline profile supports, 8 bits per sample, 4:2:0 format, CAVLC.
802*495ae853SAndroid Build Coastguard Worker      * B frames are not allowed. Further, Flexible mb ordering, Redundant slices,
803*495ae853SAndroid Build Coastguard Worker      * Arbitrary slice ordering are supported. The constrained baseline profile is
804*495ae853SAndroid Build Coastguard Worker      * baseline profile minus ASO, FMO and redundant slices. To the constrained
805*495ae853SAndroid Build Coastguard Worker      * baseline profile if we add support for B slices, support for encoding
806*495ae853SAndroid Build Coastguard Worker      * interlaced frames, support for weighted prediction and introduce CABAC
807*495ae853SAndroid Build Coastguard Worker      * entropy coding then we have Main Profile.
808*495ae853SAndroid Build Coastguard Worker      */
809*495ae853SAndroid Build Coastguard Worker     ps_sps->u1_profile_idc = u1_profile_idc;
810*495ae853SAndroid Build Coastguard Worker 
811*495ae853SAndroid Build Coastguard Worker     /* level */
812*495ae853SAndroid Build Coastguard Worker     ps_sps->u1_level_idc = MAX(
813*495ae853SAndroid Build Coastguard Worker         ps_cfg->u4_max_level, (UWORD32) ih264e_get_min_level(ps_cfg->u4_max_wd, ps_cfg->u4_max_ht));
814*495ae853SAndroid Build Coastguard Worker 
815*495ae853SAndroid Build Coastguard Worker     /* constrained flags */
816*495ae853SAndroid Build Coastguard Worker     /*
817*495ae853SAndroid Build Coastguard Worker      * baseline profile automatically implies set 0 flag
818*495ae853SAndroid Build Coastguard Worker      */
819*495ae853SAndroid Build Coastguard Worker     ps_sps->u1_constraint_set0_flag = (ps_sps->u1_profile_idc == IH264_PROFILE_BASELINE);
820*495ae853SAndroid Build Coastguard Worker     /*
821*495ae853SAndroid Build Coastguard Worker      * main profile automatically implies set 1 flag
822*495ae853SAndroid Build Coastguard Worker      * Although the encoder says it supports Baseline profile it actually supports
823*495ae853SAndroid Build Coastguard Worker      * constrained baseline profile as ASO, FMO and redundant slices are not
824*495ae853SAndroid Build Coastguard Worker      * supported
825*495ae853SAndroid Build Coastguard Worker      */
826*495ae853SAndroid Build Coastguard Worker     ps_sps->u1_constraint_set1_flag = (ps_sps->u1_profile_idc <= IH264_PROFILE_MAIN);
827*495ae853SAndroid Build Coastguard Worker     /*
828*495ae853SAndroid Build Coastguard Worker      * extended profile is not supported
829*495ae853SAndroid Build Coastguard Worker      */
830*495ae853SAndroid Build Coastguard Worker     ps_sps->u1_constraint_set2_flag = 0x00;
831*495ae853SAndroid Build Coastguard Worker     /*
832*495ae853SAndroid Build Coastguard Worker      * level 1b or level 11
833*495ae853SAndroid Build Coastguard Worker      */
834*495ae853SAndroid Build Coastguard Worker     if(ps_sps->u1_level_idc == IH264_LEVEL_1B)
835*495ae853SAndroid Build Coastguard Worker     {
836*495ae853SAndroid Build Coastguard Worker         ps_sps->u1_constraint_set3_flag = 0;
837*495ae853SAndroid Build Coastguard Worker         ps_sps->u1_level_idc = IH264_LEVEL_11;
838*495ae853SAndroid Build Coastguard Worker     }
839*495ae853SAndroid Build Coastguard Worker     else
840*495ae853SAndroid Build Coastguard Worker     {
841*495ae853SAndroid Build Coastguard Worker         ps_sps->u1_constraint_set3_flag = 0;
842*495ae853SAndroid Build Coastguard Worker     }
843*495ae853SAndroid Build Coastguard Worker 
844*495ae853SAndroid Build Coastguard Worker     /* active sps id */
845*495ae853SAndroid Build Coastguard Worker     ps_sps->u1_sps_id = u1_sps_id;
846*495ae853SAndroid Build Coastguard Worker 
847*495ae853SAndroid Build Coastguard Worker     if((ps_sps->u1_profile_idc == IH264_SCALABLE_BASELINE) ||
848*495ae853SAndroid Build Coastguard Worker        (ps_sps->u1_profile_idc >= IH264_PROFILE_HIGH))
849*495ae853SAndroid Build Coastguard Worker     {
850*495ae853SAndroid Build Coastguard Worker         /* chroma format idc */
851*495ae853SAndroid Build Coastguard Worker         ps_sps->u1_chroma_format_idc = CHROMA_FMT_IDC_YUV420;
852*495ae853SAndroid Build Coastguard Worker 
853*495ae853SAndroid Build Coastguard Worker         /* residual_colour_transform_flag */
854*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_residual_colour_transform_flag = 0;
855*495ae853SAndroid Build Coastguard Worker 
856*495ae853SAndroid Build Coastguard Worker         /* luma bit depth 8 */
857*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_bit_depth_luma = 8;
858*495ae853SAndroid Build Coastguard Worker 
859*495ae853SAndroid Build Coastguard Worker         /* chroma bit depth 8 */
860*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_bit_depth_chroma = 8;
861*495ae853SAndroid Build Coastguard Worker 
862*495ae853SAndroid Build Coastguard Worker         /* qpprime_y_zero_transform_bypass_flag */
863*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_qpprime_y_zero_transform_bypass_flag = 0;
864*495ae853SAndroid Build Coastguard Worker 
865*495ae853SAndroid Build Coastguard Worker         /* seq_scaling_matrix_present_flag */
866*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_seq_scaling_matrix_present_flag = 0;
867*495ae853SAndroid Build Coastguard Worker 
868*495ae853SAndroid Build Coastguard Worker         if(ps_sps->i1_seq_scaling_matrix_present_flag)
869*495ae853SAndroid Build Coastguard Worker         {
870*495ae853SAndroid Build Coastguard Worker             /* TODO_LATER: Will be enabled once scaling list support is added */
871*495ae853SAndroid Build Coastguard Worker         }
872*495ae853SAndroid Build Coastguard Worker     }
873*495ae853SAndroid Build Coastguard Worker 
874*495ae853SAndroid Build Coastguard Worker     /* log2_max_frame_num_minus4 */
875*495ae853SAndroid Build Coastguard Worker     ps_sps->i1_log2_max_frame_num = LOG2_MAX_FRAME_NUM_MINUS4 + 4;
876*495ae853SAndroid Build Coastguard Worker 
877*495ae853SAndroid Build Coastguard Worker     /* pic_order_cnt_type */
878*495ae853SAndroid Build Coastguard Worker     ps_sps->i1_pic_order_cnt_type = 2;
879*495ae853SAndroid Build Coastguard Worker 
880*495ae853SAndroid Build Coastguard Worker     if(ps_codec->i4_non_ref_frames_in_stream)
881*495ae853SAndroid Build Coastguard Worker     {
882*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_pic_order_cnt_type = 0;
883*495ae853SAndroid Build Coastguard Worker     }
884*495ae853SAndroid Build Coastguard Worker 
885*495ae853SAndroid Build Coastguard Worker     /* log2_max_pic_order_cnt_lsb_minus4 */
886*495ae853SAndroid Build Coastguard Worker     ps_sps->i1_log2_max_pic_order_cnt_lsb = 8;
887*495ae853SAndroid Build Coastguard Worker 
888*495ae853SAndroid Build Coastguard Worker     /* TODO : add support for other poc types */
889*495ae853SAndroid Build Coastguard Worker     if(ps_sps->i1_pic_order_cnt_type == 0)
890*495ae853SAndroid Build Coastguard Worker     {
891*495ae853SAndroid Build Coastguard Worker     }
892*495ae853SAndroid Build Coastguard Worker     else if(ps_sps->i1_pic_order_cnt_type == 1)
893*495ae853SAndroid Build Coastguard Worker     {
894*495ae853SAndroid Build Coastguard Worker     }
895*495ae853SAndroid Build Coastguard Worker 
896*495ae853SAndroid Build Coastguard Worker     ps_sps->u1_max_num_ref_frames = ps_codec->i4_max_num_reference_frames;
897*495ae853SAndroid Build Coastguard Worker 
898*495ae853SAndroid Build Coastguard Worker     /* gaps_in_frame_num_value_allowed_flag */
899*495ae853SAndroid Build Coastguard Worker     ps_sps->i1_gaps_in_frame_num_value_allowed_flag = 0;
900*495ae853SAndroid Build Coastguard Worker 
901*495ae853SAndroid Build Coastguard Worker     /* pic width in mb - 1 */
902*495ae853SAndroid Build Coastguard Worker     ps_sps->i2_pic_width_in_mbs_minus1 =
903*495ae853SAndroid Build Coastguard Worker         (ps_inp_buf->as_layer_yuv_buf_props[u1_spatial_layer_id].u4_width >> 4) - 1;
904*495ae853SAndroid Build Coastguard Worker 
905*495ae853SAndroid Build Coastguard Worker     /* pic height in mb - 1 */
906*495ae853SAndroid Build Coastguard Worker     ps_sps->i2_pic_height_in_map_units_minus1 =
907*495ae853SAndroid Build Coastguard Worker         (ps_inp_buf->as_layer_yuv_buf_props[u1_spatial_layer_id].u4_height >> 4) - 1;
908*495ae853SAndroid Build Coastguard Worker 
909*495ae853SAndroid Build Coastguard Worker     /* frame_mbs_only_flag, no support for interlace encoding */
910*495ae853SAndroid Build Coastguard Worker     ps_sps->i1_frame_mbs_only_flag = 1;
911*495ae853SAndroid Build Coastguard Worker 
912*495ae853SAndroid Build Coastguard Worker     /* mb_adaptive_frame_field_flag */
913*495ae853SAndroid Build Coastguard Worker     if(ps_sps->i1_frame_mbs_only_flag == 0)
914*495ae853SAndroid Build Coastguard Worker     {
915*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_mb_adaptive_frame_field_flag = 0;
916*495ae853SAndroid Build Coastguard Worker     }
917*495ae853SAndroid Build Coastguard Worker 
918*495ae853SAndroid Build Coastguard Worker     /* direct_8x8_inference_flag */
919*495ae853SAndroid Build Coastguard Worker     if(ps_sps->u1_level_idc < IH264_LEVEL_30)
920*495ae853SAndroid Build Coastguard Worker     {
921*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_direct_8x8_inference_flag = 0;
922*495ae853SAndroid Build Coastguard Worker     }
923*495ae853SAndroid Build Coastguard Worker     else
924*495ae853SAndroid Build Coastguard Worker     {
925*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_direct_8x8_inference_flag = 1;
926*495ae853SAndroid Build Coastguard Worker     }
927*495ae853SAndroid Build Coastguard Worker 
928*495ae853SAndroid Build Coastguard Worker     /* cropping params */
929*495ae853SAndroid Build Coastguard Worker     /*NOTE : Cropping values depend on the chroma format
930*495ae853SAndroid Build Coastguard Worker      * For our case ,decoder interprets the cropping values as 2*num pixels
931*495ae853SAndroid Build Coastguard Worker      * Hence the difference in the disp width and width must be halved before
932*495ae853SAndroid Build Coastguard Worker      * sending to get the expected results
933*495ae853SAndroid Build Coastguard Worker      */
934*495ae853SAndroid Build Coastguard Worker     ps_sps->i1_frame_cropping_flag = 0;
935*495ae853SAndroid Build Coastguard Worker     ps_sps->i2_frame_crop_left_offset = 0;
936*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;
937*495ae853SAndroid Build Coastguard Worker     ps_sps->i2_frame_crop_top_offset = 0;
938*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;
939*495ae853SAndroid Build Coastguard Worker 
940*495ae853SAndroid Build Coastguard Worker     if(ps_sps->i2_frame_crop_left_offset || ps_sps->i2_frame_crop_right_offset ||
941*495ae853SAndroid Build Coastguard Worker        ps_sps->i2_frame_crop_top_offset || ps_sps->i2_frame_crop_bottom_offset)
942*495ae853SAndroid Build Coastguard Worker     {
943*495ae853SAndroid Build Coastguard Worker         ps_sps->i1_frame_cropping_flag = 1;
944*495ae853SAndroid Build Coastguard Worker     }
945*495ae853SAndroid Build Coastguard Worker 
946*495ae853SAndroid Build Coastguard Worker     /* vui params */
947*495ae853SAndroid Build Coastguard Worker     ps_sps->i1_vui_parameters_present_flag = !(ps_cfg->u4_disable_vui);
948*495ae853SAndroid Build Coastguard Worker 
949*495ae853SAndroid Build Coastguard Worker     if(!ps_sps->i1_vui_parameters_present_flag)
950*495ae853SAndroid Build Coastguard Worker     {
951*495ae853SAndroid Build Coastguard Worker         /* populate vui params */
952*495ae853SAndroid Build Coastguard Worker         isvce_populate_vui(ps_codec, ps_sps);
953*495ae853SAndroid Build Coastguard Worker     }
954*495ae853SAndroid Build Coastguard Worker     else
955*495ae853SAndroid Build Coastguard Worker     {
956*495ae853SAndroid Build Coastguard Worker         ps_sps->s_vui_parameters = ps_cfg->s_vui;
957*495ae853SAndroid Build Coastguard Worker     }
958*495ae853SAndroid Build Coastguard Worker 
959*495ae853SAndroid Build Coastguard Worker     return i4_err_code;
960*495ae853SAndroid Build Coastguard Worker }
961*495ae853SAndroid Build Coastguard Worker 
962*495ae853SAndroid Build Coastguard Worker /**
963*495ae853SAndroid Build Coastguard Worker ******************************************************************************
964*495ae853SAndroid Build Coastguard Worker *
965*495ae853SAndroid Build Coastguard Worker * @brief Populates pps structure
966*495ae853SAndroid Build Coastguard Worker *
967*495ae853SAndroid Build Coastguard Worker * @par   Description
968*495ae853SAndroid Build Coastguard Worker *  Populates pps structure for its use in header generation
969*495ae853SAndroid Build Coastguard Worker *
970*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_codec
971*495ae853SAndroid Build Coastguard Worker *  pointer to encoder context
972*495ae853SAndroid Build Coastguard Worker *
973*495ae853SAndroid Build Coastguard Worker * @param[out]  ps_pps
974*495ae853SAndroid Build Coastguard Worker *  pointer to pps params that needs to be populated
975*495ae853SAndroid Build Coastguard Worker *
976*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
977*495ae853SAndroid Build Coastguard Worker *
978*495ae853SAndroid Build Coastguard Worker ******************************************************************************
979*495ae853SAndroid Build Coastguard Worker */
isvce_populate_pps(isvce_codec_t * ps_codec,pps_t * ps_pps,UWORD8 u1_sps_id,UWORD8 u1_pps_id,UWORD8 u1_spatial_layer_id)980*495ae853SAndroid Build Coastguard Worker IH264E_ERROR_T isvce_populate_pps(isvce_codec_t *ps_codec, pps_t *ps_pps, UWORD8 u1_sps_id,
981*495ae853SAndroid Build Coastguard Worker                                   UWORD8 u1_pps_id, UWORD8 u1_spatial_layer_id)
982*495ae853SAndroid Build Coastguard Worker {
983*495ae853SAndroid Build Coastguard Worker     /* seq_parameter_set_id */
984*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_sps_id = u1_sps_id;
985*495ae853SAndroid Build Coastguard Worker 
986*495ae853SAndroid Build Coastguard Worker     /* pic_parameter_set_id */
987*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_pps_id = u1_pps_id;
988*495ae853SAndroid Build Coastguard Worker 
989*495ae853SAndroid Build Coastguard Worker     /* entropy_coding_mode */
990*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_entropy_coding_mode_flag =
991*495ae853SAndroid Build Coastguard Worker         ((ps_codec->s_cfg.s_svc_params.u1_num_spatial_layers > 1) && (0 == u1_spatial_layer_id))
992*495ae853SAndroid Build Coastguard Worker             ? CAVLC
993*495ae853SAndroid Build Coastguard Worker             : ps_codec->s_cfg.u4_entropy_coding_mode;
994*495ae853SAndroid Build Coastguard Worker 
995*495ae853SAndroid Build Coastguard Worker     /* pic_order_present_flag is unset if we don't have feilds */
996*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_pic_order_present_flag = 0;
997*495ae853SAndroid Build Coastguard Worker 
998*495ae853SAndroid Build Coastguard Worker     /* Currently number of slice groups supported are 1 */
999*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_num_slice_groups = 1;
1000*495ae853SAndroid Build Coastguard Worker 
1001*495ae853SAndroid Build Coastguard Worker     if(ps_pps->u1_num_slice_groups - 1)
1002*495ae853SAndroid Build Coastguard Worker     {
1003*495ae853SAndroid Build Coastguard Worker         /* TODO_LATER: Currently the number of slice groups minus 1 is 0.
1004*495ae853SAndroid Build Coastguard Worker          * If this is not the case, we have to add Slice group map type to the bit
1005*495ae853SAndroid Build Coastguard Worker          * stream*/
1006*495ae853SAndroid Build Coastguard Worker     }
1007*495ae853SAndroid Build Coastguard Worker 
1008*495ae853SAndroid Build Coastguard Worker     /* number of reference frames for list 0 */
1009*495ae853SAndroid Build Coastguard Worker     /* FIXME : fix this hard coded value */
1010*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_num_ref_idx_l0_default_active = 1;
1011*495ae853SAndroid Build Coastguard Worker 
1012*495ae853SAndroid Build Coastguard Worker     /* number of reference frames for list 1 */
1013*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_num_ref_idx_l1_default_active = 1;
1014*495ae853SAndroid Build Coastguard Worker 
1015*495ae853SAndroid Build Coastguard Worker     /* weighted prediction for now is disabled */
1016*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_weighted_pred_flag = 0;
1017*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_weighted_bipred_idc = 0;
1018*495ae853SAndroid Build Coastguard Worker 
1019*495ae853SAndroid Build Coastguard Worker     /* The intent is to not signal qp from pps. Rather send the same in slice
1020*495ae853SAndroid Build Coastguard Worker      * headers */
1021*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_pic_init_qp = 0;
1022*495ae853SAndroid Build Coastguard Worker 
1023*495ae853SAndroid Build Coastguard Worker     /* The intent is to not signal qp from pps. Rather send the same in slice
1024*495ae853SAndroid Build Coastguard Worker      * headers */
1025*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_pic_init_qs = 0;
1026*495ae853SAndroid Build Coastguard Worker 
1027*495ae853SAndroid Build Coastguard Worker     /* The intent is to not signal qp from pps. Rather send the same in slice
1028*495ae853SAndroid Build Coastguard Worker      * headers */
1029*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_chroma_qp_index_offset = 0;
1030*495ae853SAndroid Build Coastguard Worker 
1031*495ae853SAndroid Build Coastguard Worker     /* deblocking filter flags present in slice header */
1032*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_deblocking_filter_control_present_flag = 1;
1033*495ae853SAndroid Build Coastguard Worker 
1034*495ae853SAndroid Build Coastguard Worker     /* constrained intra prediction */
1035*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_constrained_intra_pred_flag =
1036*495ae853SAndroid Build Coastguard Worker         ps_codec->au4_constrained_intra_pred[u1_spatial_layer_id];
1037*495ae853SAndroid Build Coastguard Worker 
1038*495ae853SAndroid Build Coastguard Worker     /* sending redundant slices is not supported for now */
1039*495ae853SAndroid Build Coastguard Worker     ps_pps->i1_redundant_pic_cnt_present_flag = 0;
1040*495ae853SAndroid Build Coastguard Worker 
1041*495ae853SAndroid Build Coastguard Worker     ps_pps->u1_slice_group_map_type = 0;
1042*495ae853SAndroid Build Coastguard Worker 
1043*495ae853SAndroid Build Coastguard Worker     return IH264E_SUCCESS;
1044*495ae853SAndroid Build Coastguard Worker }
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 * @brief Populates slice header structure
1050*495ae853SAndroid Build Coastguard Worker *
1051*495ae853SAndroid Build Coastguard Worker * @par   Description
1052*495ae853SAndroid Build Coastguard Worker *  Populates slice header structure for its use in header generation
1053*495ae853SAndroid Build Coastguard Worker *
1054*495ae853SAndroid Build Coastguard Worker * @param[in]  ps_proc
1055*495ae853SAndroid Build Coastguard Worker *  pointer to proc context
1056*495ae853SAndroid Build Coastguard Worker *
1057*495ae853SAndroid Build Coastguard Worker * @param[out]  ps_slice_hdr
1058*495ae853SAndroid Build Coastguard Worker *  pointer to slice header structure that needs to be populated
1059*495ae853SAndroid Build Coastguard Worker *
1060*495ae853SAndroid Build Coastguard Worker * @param[in]  ps_pps
1061*495ae853SAndroid Build Coastguard Worker *  pointer to pps params structure referred by the slice
1062*495ae853SAndroid Build Coastguard Worker *
1063*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_sps
1064*495ae853SAndroid Build Coastguard Worker *  pointer to sps params referred by the pps
1065*495ae853SAndroid Build Coastguard Worker *
1066*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
1067*495ae853SAndroid Build Coastguard Worker *
1068*495ae853SAndroid Build Coastguard Worker ******************************************************************************
1069*495ae853SAndroid Build Coastguard Worker */
isvce_populate_slice_header(isvce_process_ctxt_t * ps_proc,slice_header_t * ps_slice_hdr,pps_t * ps_pps,sps_t * ps_sps,UWORD8 u1_is_idr)1070*495ae853SAndroid Build Coastguard Worker WORD32 isvce_populate_slice_header(isvce_process_ctxt_t *ps_proc, slice_header_t *ps_slice_hdr,
1071*495ae853SAndroid Build Coastguard Worker                                    pps_t *ps_pps, sps_t *ps_sps, UWORD8 u1_is_idr)
1072*495ae853SAndroid Build Coastguard Worker {
1073*495ae853SAndroid Build Coastguard Worker     /* entropy context */
1074*495ae853SAndroid Build Coastguard Worker     isvce_entropy_ctxt_t *ps_entropy = &ps_proc->s_entropy;
1075*495ae853SAndroid Build Coastguard Worker 
1076*495ae853SAndroid Build Coastguard Worker     isvce_codec_t *ps_codec = ps_proc->ps_codec;
1077*495ae853SAndroid Build Coastguard Worker 
1078*495ae853SAndroid Build Coastguard Worker     if(ps_codec->u4_is_curr_frm_ref)
1079*495ae853SAndroid Build Coastguard Worker     {
1080*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->i1_nal_unit_idc = 3;
1081*495ae853SAndroid Build Coastguard Worker     }
1082*495ae853SAndroid Build Coastguard Worker     else
1083*495ae853SAndroid Build Coastguard Worker     {
1084*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->i1_nal_unit_idc = 0;
1085*495ae853SAndroid Build Coastguard Worker     }
1086*495ae853SAndroid Build Coastguard Worker 
1087*495ae853SAndroid Build Coastguard Worker     /* start mb address */
1088*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->u2_first_mb_in_slice = ps_entropy->i4_mb_start_add;
1089*495ae853SAndroid Build Coastguard Worker 
1090*495ae853SAndroid Build Coastguard Worker     /* slice type */
1091*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->u1_slice_type = ps_proc->i4_slice_type;
1092*495ae853SAndroid Build Coastguard Worker 
1093*495ae853SAndroid Build Coastguard Worker     /* pic_parameter_set_id */
1094*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->u1_pps_id = ps_pps->u1_pps_id;
1095*495ae853SAndroid Build Coastguard Worker 
1096*495ae853SAndroid Build Coastguard Worker     /* Separate color plane flag is 0,
1097*495ae853SAndroid Build Coastguard Worker      * hence the syntax element color_plane_id not included */
1098*495ae853SAndroid Build Coastguard Worker 
1099*495ae853SAndroid Build Coastguard Worker     /* frame num */
1100*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->i4_frame_num = ps_proc->i4_frame_num;
1101*495ae853SAndroid Build Coastguard Worker 
1102*495ae853SAndroid Build Coastguard Worker     /* frame_mbs_only_flag, no support for interlace encoding */
1103*495ae853SAndroid Build Coastguard Worker     if(!ps_sps->i1_frame_mbs_only_flag)
1104*495ae853SAndroid Build Coastguard Worker     {
1105*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->i1_field_pic_flag = 0;
1106*495ae853SAndroid Build Coastguard Worker 
1107*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->i1_field_pic_flag)
1108*495ae853SAndroid Build Coastguard Worker         {
1109*495ae853SAndroid Build Coastguard Worker             ps_slice_hdr->i1_bottom_field_flag = 0;
1110*495ae853SAndroid Build Coastguard Worker         }
1111*495ae853SAndroid Build Coastguard Worker     }
1112*495ae853SAndroid Build Coastguard Worker 
1113*495ae853SAndroid Build Coastguard Worker     /* idr pic id */
1114*495ae853SAndroid Build Coastguard Worker     if(u1_is_idr)
1115*495ae853SAndroid Build Coastguard Worker     {
1116*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->u2_idr_pic_id = ps_proc->u4_idr_pic_id;
1117*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->i1_nal_unit_type = NAL_SLICE_IDR;
1118*495ae853SAndroid Build Coastguard Worker     }
1119*495ae853SAndroid Build Coastguard Worker     else
1120*495ae853SAndroid Build Coastguard Worker     {
1121*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->i1_nal_unit_type = NAL_SLICE_NON_IDR;
1122*495ae853SAndroid Build Coastguard Worker     }
1123*495ae853SAndroid Build Coastguard Worker 
1124*495ae853SAndroid Build Coastguard Worker     if(ps_proc->u1_spatial_layer_id > 0)
1125*495ae853SAndroid Build Coastguard Worker     {
1126*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->i1_nal_unit_type = NAL_CODED_SLICE_EXTENSION;
1127*495ae853SAndroid Build Coastguard Worker     }
1128*495ae853SAndroid Build Coastguard Worker 
1129*495ae853SAndroid Build Coastguard Worker     if(ps_sps->i1_pic_order_cnt_type == 0)
1130*495ae853SAndroid Build Coastguard Worker     {
1131*495ae853SAndroid Build Coastguard Worker         WORD32 i4_poc;
1132*495ae853SAndroid Build Coastguard Worker         i4_poc = ps_codec->i4_poc;
1133*495ae853SAndroid Build Coastguard Worker         i4_poc %= (1 << ps_sps->i1_log2_max_pic_order_cnt_lsb);
1134*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->i4_pic_order_cnt_lsb = i4_poc;
1135*495ae853SAndroid Build Coastguard Worker     }
1136*495ae853SAndroid Build Coastguard Worker     /* TODO add support for poc type 1 */
1137*495ae853SAndroid Build Coastguard Worker     else if(ps_sps->i1_pic_order_cnt_type == 1)
1138*495ae853SAndroid Build Coastguard Worker     {
1139*495ae853SAndroid Build Coastguard Worker     }
1140*495ae853SAndroid Build Coastguard Worker 
1141*495ae853SAndroid Build Coastguard Worker     /*
1142*495ae853SAndroid Build Coastguard Worker      * redundant slices are not currently supported.
1143*495ae853SAndroid Build Coastguard Worker      * Hence the syntax element redundant slice cnt is not initialized
1144*495ae853SAndroid Build Coastguard Worker      */
1145*495ae853SAndroid Build Coastguard Worker     if(ps_pps->i1_redundant_pic_cnt_present_flag)
1146*495ae853SAndroid Build Coastguard Worker     {
1147*495ae853SAndroid Build Coastguard Worker     }
1148*495ae853SAndroid Build Coastguard Worker 
1149*495ae853SAndroid Build Coastguard Worker     /* direct spatial mv pred flag */
1150*495ae853SAndroid Build Coastguard Worker     if(ps_proc->i4_slice_type == BSLICE)
1151*495ae853SAndroid Build Coastguard Worker     {
1152*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->u1_direct_spatial_mv_pred_flag = 1;
1153*495ae853SAndroid Build Coastguard Worker     }
1154*495ae853SAndroid Build Coastguard Worker 
1155*495ae853SAndroid Build Coastguard Worker     if(ps_proc->i4_slice_type == PSLICE || ps_proc->i4_slice_type == SPSLICE ||
1156*495ae853SAndroid Build Coastguard Worker        ps_proc->i4_slice_type == BSLICE)
1157*495ae853SAndroid Build Coastguard Worker     {
1158*495ae853SAndroid Build Coastguard Worker         /* num_ref_idx_active_override_flag */
1159*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->u1_num_ref_idx_active_override_flag = 0;
1160*495ae853SAndroid Build Coastguard Worker 
1161*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->u1_num_ref_idx_active_override_flag)
1162*495ae853SAndroid Build Coastguard Worker         {
1163*495ae853SAndroid Build Coastguard Worker             /* num_ref_idx_l0_active_minus1 */
1164*495ae853SAndroid Build Coastguard Worker 
1165*495ae853SAndroid Build Coastguard Worker             if(ps_proc->i4_slice_type == BSLICE)
1166*495ae853SAndroid Build Coastguard Worker             {
1167*495ae853SAndroid Build Coastguard Worker                 /* num_ref_idx_l1_active_minus1 */
1168*495ae853SAndroid Build Coastguard Worker             }
1169*495ae853SAndroid Build Coastguard Worker         }
1170*495ae853SAndroid Build Coastguard Worker     }
1171*495ae853SAndroid Build Coastguard Worker 
1172*495ae853SAndroid Build Coastguard Worker     /* ref_pic_list_modification */
1173*495ae853SAndroid Build Coastguard Worker     if((ps_proc->i4_slice_type != ISLICE) && (ps_proc->i4_slice_type != SISLICE))
1174*495ae853SAndroid Build Coastguard Worker     {
1175*495ae853SAndroid Build Coastguard Worker         /* ref_pic_list_modification_flag_l0 */
1176*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l0 = 1;
1177*495ae853SAndroid Build Coastguard Worker 
1178*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l0)
1179*495ae853SAndroid Build Coastguard Worker         {
1180*495ae853SAndroid Build Coastguard Worker             ps_slice_hdr->s_rplm.i1_modification_of_pic_nums_idc_l0[0] = 0;
1181*495ae853SAndroid Build Coastguard Worker             ps_slice_hdr->s_rplm.i1_modification_of_pic_nums_idc_l0[1] = 3;
1182*495ae853SAndroid Build Coastguard Worker 
1183*495ae853SAndroid Build Coastguard Worker             if((ps_codec->i4_frame_num - ps_proc->aps_ref_pic[L0]->i4_frame_num) < 1)
1184*495ae853SAndroid Build Coastguard Worker             {
1185*495ae853SAndroid Build Coastguard Worker                 return IH264E_FAIL;
1186*495ae853SAndroid Build Coastguard Worker             }
1187*495ae853SAndroid Build Coastguard Worker 
1188*495ae853SAndroid Build Coastguard Worker             ps_slice_hdr->s_rplm.u4_abs_diff_pic_num_minus1_l0[0] =
1189*495ae853SAndroid Build Coastguard Worker                 ps_codec->i4_frame_num - ps_proc->aps_ref_pic[L0]->i4_frame_num - 1;
1190*495ae853SAndroid Build Coastguard Worker         }
1191*495ae853SAndroid Build Coastguard Worker     }
1192*495ae853SAndroid Build Coastguard Worker 
1193*495ae853SAndroid Build Coastguard Worker     if(ps_proc->i4_slice_type == BSLICE)
1194*495ae853SAndroid Build Coastguard Worker     {
1195*495ae853SAndroid Build Coastguard Worker         /* ref_pic_list_modification_flag_l1 */
1196*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l1 = 0;
1197*495ae853SAndroid Build Coastguard Worker 
1198*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l1)
1199*495ae853SAndroid Build Coastguard Worker         {
1200*495ae853SAndroid Build Coastguard Worker         }
1201*495ae853SAndroid Build Coastguard Worker     }
1202*495ae853SAndroid Build Coastguard Worker 
1203*495ae853SAndroid Build Coastguard Worker     /* Currently we do not support weighted pred */
1204*495ae853SAndroid Build Coastguard Worker     /* ps_slice_hdr->u1_weighted_bipred_idc = 0; */
1205*495ae853SAndroid Build Coastguard Worker 
1206*495ae853SAndroid Build Coastguard Worker     if((ps_pps->i1_weighted_pred_flag &&
1207*495ae853SAndroid Build Coastguard Worker         (ps_proc->i4_slice_type == PSLICE || ps_proc->i4_slice_type == SPSLICE)) ||
1208*495ae853SAndroid Build Coastguard Worker        (ps_proc->i4_slice_type == BSLICE && ps_pps->i1_weighted_bipred_idc == 1))
1209*495ae853SAndroid Build Coastguard Worker     {
1210*495ae853SAndroid Build Coastguard Worker         /* TODO_LATER: Currently there is no support for weighted prediction.
1211*495ae853SAndroid Build Coastguard Worker              This needs to be updated when the support is added */
1212*495ae853SAndroid Build Coastguard Worker     }
1213*495ae853SAndroid Build Coastguard Worker 
1214*495ae853SAndroid Build Coastguard Worker     if(ps_slice_hdr->i1_nal_unit_idc != 0)
1215*495ae853SAndroid Build Coastguard Worker     {
1216*495ae853SAndroid Build Coastguard Worker         if(u1_is_idr)
1217*495ae853SAndroid Build Coastguard Worker         {
1218*495ae853SAndroid Build Coastguard Worker             /* no_output_of_prior_pics_flag  */
1219*495ae853SAndroid Build Coastguard Worker             ps_slice_hdr->u1_no_output_of_prior_pics_flag = 0;
1220*495ae853SAndroid Build Coastguard Worker 
1221*495ae853SAndroid Build Coastguard Worker             /* long_term_reference_flag  */
1222*495ae853SAndroid Build Coastguard Worker             ps_slice_hdr->u1_long_term_reference_flag = 0;
1223*495ae853SAndroid Build Coastguard Worker         }
1224*495ae853SAndroid Build Coastguard Worker         else
1225*495ae853SAndroid Build Coastguard Worker         {
1226*495ae853SAndroid Build Coastguard Worker             /* adaptive_ref_pic_marking_mode_flag  */
1227*495ae853SAndroid Build Coastguard Worker             ps_slice_hdr->u1_adaptive_ref_pic_marking_mode_flag = 0;
1228*495ae853SAndroid Build Coastguard Worker 
1229*495ae853SAndroid Build Coastguard Worker             if(ps_slice_hdr->u1_adaptive_ref_pic_marking_mode_flag)
1230*495ae853SAndroid Build Coastguard Worker             {
1231*495ae853SAndroid Build Coastguard Worker                 /* TODO: if the reference picture marking mode is adaptive
1232*495ae853SAndroid Build Coastguard Worker                      add these fields in the bit-stream */
1233*495ae853SAndroid Build Coastguard Worker             }
1234*495ae853SAndroid Build Coastguard Worker         }
1235*495ae853SAndroid Build Coastguard Worker     }
1236*495ae853SAndroid Build Coastguard Worker 
1237*495ae853SAndroid Build Coastguard Worker     /* entropy coding mode flag */
1238*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->u1_entropy_coding_mode_flag = ps_entropy->u1_entropy_coding_mode_flag;
1239*495ae853SAndroid Build Coastguard Worker 
1240*495ae853SAndroid Build Coastguard Worker     if(ps_slice_hdr->u1_entropy_coding_mode_flag && ps_proc->i4_slice_type != ISLICE &&
1241*495ae853SAndroid Build Coastguard Worker        ps_proc->i4_slice_type != SISLICE)
1242*495ae853SAndroid Build Coastguard Worker     {
1243*495ae853SAndroid Build Coastguard Worker         /* cabac_init_idc */
1244*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->i1_cabac_init_idc = CABAC_INIT_IDC;
1245*495ae853SAndroid Build Coastguard Worker     }
1246*495ae853SAndroid Build Coastguard Worker 
1247*495ae853SAndroid Build Coastguard Worker     /* slice qp */
1248*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->i1_slice_qp = ps_proc->u1_frame_qp;
1249*495ae853SAndroid Build Coastguard Worker 
1250*495ae853SAndroid Build Coastguard Worker     if(ps_proc->i4_slice_type == SPSLICE || ps_proc->i4_slice_type == SISLICE)
1251*495ae853SAndroid Build Coastguard Worker     {
1252*495ae853SAndroid Build Coastguard Worker         if(ps_proc->i4_slice_type == SPSLICE)
1253*495ae853SAndroid Build Coastguard Worker         {
1254*495ae853SAndroid Build Coastguard Worker             /* sp_for_switch_flag */
1255*495ae853SAndroid Build Coastguard Worker         }
1256*495ae853SAndroid Build Coastguard Worker         /* slice_qs_delta */
1257*495ae853SAndroid Build Coastguard Worker     }
1258*495ae853SAndroid Build Coastguard Worker 
1259*495ae853SAndroid Build Coastguard Worker     if(ps_pps->i1_deblocking_filter_control_present_flag)
1260*495ae853SAndroid Build Coastguard Worker     {
1261*495ae853SAndroid Build Coastguard Worker         /* disable_deblocking_filter_idc */
1262*495ae853SAndroid Build Coastguard Worker         ps_slice_hdr->u1_disable_deblocking_filter_idc = ps_proc->u4_disable_deblock_level;
1263*495ae853SAndroid Build Coastguard Worker 
1264*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->u1_disable_deblocking_filter_idc != 1)
1265*495ae853SAndroid Build Coastguard Worker         {
1266*495ae853SAndroid Build Coastguard Worker             /* slice_alpha_c0_offset_div2 */
1267*495ae853SAndroid Build Coastguard Worker             ps_slice_hdr->i1_slice_alpha_c0_offset_div2 = 0;
1268*495ae853SAndroid Build Coastguard Worker 
1269*495ae853SAndroid Build Coastguard Worker             /* slice_beta_offset_div2 */
1270*495ae853SAndroid Build Coastguard Worker             ps_slice_hdr->i1_slice_beta_offset_div2 = 0;
1271*495ae853SAndroid Build Coastguard Worker         }
1272*495ae853SAndroid Build Coastguard Worker     }
1273*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->u1_num_slice_groups_minus1 = 0;
1274*495ae853SAndroid Build Coastguard Worker     if(ps_slice_hdr->u1_num_slice_groups_minus1 > 0 && ps_pps->u1_slice_group_map_type >= 3 &&
1275*495ae853SAndroid Build Coastguard Worker        ps_pps->u1_slice_group_map_type <= 5)
1276*495ae853SAndroid Build Coastguard Worker     {
1277*495ae853SAndroid Build Coastguard Worker         /* slice_group_change_cycle */
1278*495ae853SAndroid Build Coastguard Worker         /* TODO_LATER: Currently the number of slice groups minus 1 is 0.
1279*495ae853SAndroid Build Coastguard Worker          * If this is not the case, we have to add Slice group map type to the bit
1280*495ae853SAndroid Build Coastguard Worker          * stream */
1281*495ae853SAndroid Build Coastguard Worker     }
1282*495ae853SAndroid Build Coastguard Worker 
1283*495ae853SAndroid Build Coastguard Worker     ps_slice_hdr->i1_cabac_init_idc = CABAC_INIT_IDC;
1284*495ae853SAndroid Build Coastguard Worker 
1285*495ae853SAndroid Build Coastguard Worker     return IH264E_SUCCESS;
1286*495ae853SAndroid Build Coastguard Worker }
1287*495ae853SAndroid Build Coastguard Worker 
1288*495ae853SAndroid Build Coastguard Worker /**
1289*495ae853SAndroid Build Coastguard Worker ******************************************************************************
1290*495ae853SAndroid Build Coastguard Worker *
1291*495ae853SAndroid Build Coastguard Worker * @brief Populates svc_nalu_ext structure
1292*495ae853SAndroid Build Coastguard Worker *
1293*495ae853SAndroid Build Coastguard Worker * @par   Description
1294*495ae853SAndroid Build Coastguard Worker *  Populates svc_nalu_ext structure for its use in header generation
1295*495ae853SAndroid Build Coastguard Worker *
1296*495ae853SAndroid Build Coastguard Worker * @param[in]  ps_proc
1297*495ae853SAndroid Build Coastguard Worker *  pointer to proc context
1298*495ae853SAndroid Build Coastguard Worker *
1299*495ae853SAndroid Build Coastguard Worker * @param[out]  ps_slice_hdr
1300*495ae853SAndroid Build Coastguard Worker *  pointer to slice header structure that needs to be populated
1301*495ae853SAndroid Build Coastguard Worker *
1302*495ae853SAndroid Build Coastguard Worker * @param[in]  ps_pps
1303*495ae853SAndroid Build Coastguard Worker *  pointer to pps params structure referred by the slice
1304*495ae853SAndroid Build Coastguard Worker *
1305*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_sps
1306*495ae853SAndroid Build Coastguard Worker *  pointer to sps params referred by the pps
1307*495ae853SAndroid Build Coastguard Worker *
1308*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
1309*495ae853SAndroid Build Coastguard Worker *
1310*495ae853SAndroid Build Coastguard Worker ******************************************************************************
1311*495ae853SAndroid Build Coastguard Worker */
isvce_populate_svc_nalu_extension(isvce_process_ctxt_t * ps_proc,svc_nalu_ext_t * ps_svc_nalu_ext,NAL_UNIT_TYPE_T nalu_type,UWORD8 u1_idr_flag)1312*495ae853SAndroid Build Coastguard Worker WORD32 isvce_populate_svc_nalu_extension(isvce_process_ctxt_t *ps_proc,
1313*495ae853SAndroid Build Coastguard Worker                                          svc_nalu_ext_t *ps_svc_nalu_ext, NAL_UNIT_TYPE_T nalu_type,
1314*495ae853SAndroid Build Coastguard Worker                                          UWORD8 u1_idr_flag)
1315*495ae853SAndroid Build Coastguard Worker {
1316*495ae853SAndroid Build Coastguard Worker     isvce_codec_t *ps_codec = ps_proc->ps_codec;
1317*495ae853SAndroid Build Coastguard Worker 
1318*495ae853SAndroid Build Coastguard Worker     ps_svc_nalu_ext->u1_idr_flag = u1_idr_flag;
1319*495ae853SAndroid Build Coastguard Worker 
1320*495ae853SAndroid Build Coastguard Worker     ps_svc_nalu_ext->u1_priority_id = 0;
1321*495ae853SAndroid Build Coastguard Worker 
1322*495ae853SAndroid Build Coastguard Worker     ps_svc_nalu_ext->u1_no_inter_layer_pred_flag = ((nalu_type == NAL_PREFIX) ? 1 : 0);
1323*495ae853SAndroid Build Coastguard Worker 
1324*495ae853SAndroid Build Coastguard Worker     ps_svc_nalu_ext->u1_dependency_id =
1325*495ae853SAndroid Build Coastguard Worker         ((nalu_type == NAL_PREFIX) ? 0 : ps_proc->u1_spatial_layer_id);
1326*495ae853SAndroid Build Coastguard Worker 
1327*495ae853SAndroid Build Coastguard Worker     ps_svc_nalu_ext->u1_temporal_id = ps_proc->ps_cur_pic->i1_temporal_id;
1328*495ae853SAndroid Build Coastguard Worker 
1329*495ae853SAndroid Build Coastguard Worker     ps_svc_nalu_ext->u1_quality_id = 0;
1330*495ae853SAndroid Build Coastguard Worker 
1331*495ae853SAndroid Build Coastguard Worker     ps_svc_nalu_ext->u1_use_ref_base_pic_flag = 0;
1332*495ae853SAndroid Build Coastguard Worker 
1333*495ae853SAndroid Build Coastguard Worker     ps_svc_nalu_ext->u1_discardable_flag = 0;
1334*495ae853SAndroid Build Coastguard Worker 
1335*495ae853SAndroid Build Coastguard Worker     ps_svc_nalu_ext->u1_output_flag = 1;
1336*495ae853SAndroid Build Coastguard Worker 
1337*495ae853SAndroid Build Coastguard Worker     ps_svc_nalu_ext->u1_reserved_three_2bits = 3;
1338*495ae853SAndroid Build Coastguard Worker 
1339*495ae853SAndroid Build Coastguard Worker     ps_svc_nalu_ext->s_nalu_header.u1_nal_ref_idc = ps_codec->u4_is_curr_frm_ref ? 3 : 0;
1340*495ae853SAndroid Build Coastguard Worker 
1341*495ae853SAndroid Build Coastguard Worker     ps_svc_nalu_ext->s_nalu_header.u1_nal_unit_type = nalu_type;
1342*495ae853SAndroid Build Coastguard Worker 
1343*495ae853SAndroid Build Coastguard Worker     return IH264E_SUCCESS;
1344*495ae853SAndroid Build Coastguard Worker }
1345*495ae853SAndroid Build Coastguard Worker 
isvce_populate_subset_sps(isvce_codec_t * ps_codec,subset_sps_t * ps_subset_sps,UWORD8 u1_sps_id,isvce_inp_buf_t * ps_inp_buf,UWORD8 u1_spatial_layer_id)1346*495ae853SAndroid Build Coastguard Worker WORD32 isvce_populate_subset_sps(isvce_codec_t *ps_codec, subset_sps_t *ps_subset_sps,
1347*495ae853SAndroid Build Coastguard Worker                                  UWORD8 u1_sps_id, isvce_inp_buf_t *ps_inp_buf,
1348*495ae853SAndroid Build Coastguard Worker                                  UWORD8 u1_spatial_layer_id)
1349*495ae853SAndroid Build Coastguard Worker {
1350*495ae853SAndroid Build Coastguard Worker     sps_t *ps_sps = &ps_subset_sps->s_sps;
1351*495ae853SAndroid Build Coastguard Worker 
1352*495ae853SAndroid Build Coastguard Worker     isvce_populate_sps(ps_codec, ps_sps, u1_sps_id, IH264_SCALABLE_BASELINE, ps_inp_buf,
1353*495ae853SAndroid Build Coastguard Worker                        u1_spatial_layer_id);
1354*495ae853SAndroid Build Coastguard Worker 
1355*495ae853SAndroid Build Coastguard Worker     ps_subset_sps->s_sps_svc_ext.u1_inter_layer_deblocking_filter_control_present_flag = 1;
1356*495ae853SAndroid Build Coastguard Worker 
1357*495ae853SAndroid Build Coastguard Worker     ps_subset_sps->s_sps_svc_ext.i1_slice_header_restriction_flag = 1;
1358*495ae853SAndroid Build Coastguard Worker 
1359*495ae853SAndroid Build Coastguard Worker     ps_subset_sps->s_sps_svc_ext.u1_extended_spatial_scalability_idc = 0;
1360*495ae853SAndroid Build Coastguard Worker 
1361*495ae853SAndroid Build Coastguard Worker     ps_subset_sps->s_sps_svc_ext.i1_seq_tcoeff_level_prediction_flag = 0;
1362*495ae853SAndroid Build Coastguard Worker 
1363*495ae853SAndroid Build Coastguard Worker     ps_subset_sps->i1_svc_vui_parameters_present_flag = 0;
1364*495ae853SAndroid Build Coastguard Worker 
1365*495ae853SAndroid Build Coastguard Worker     ps_subset_sps->i1_additional_extension2_flag = 0;
1366*495ae853SAndroid Build Coastguard Worker 
1367*495ae853SAndroid Build Coastguard Worker     ps_subset_sps->s_sps_svc_ext.u1_chroma_phase_x_plus1 = 1;
1368*495ae853SAndroid Build Coastguard Worker 
1369*495ae853SAndroid Build Coastguard Worker     ps_subset_sps->s_sps_svc_ext.u1_chroma_phase_y_plus1 = 1;
1370*495ae853SAndroid Build Coastguard Worker 
1371*495ae853SAndroid Build Coastguard Worker     ps_subset_sps->s_sps_svc_ext.i1_adaptive_tcoeff_level_prediction_flag = 0;
1372*495ae853SAndroid Build Coastguard Worker 
1373*495ae853SAndroid Build Coastguard Worker     return IH264E_SUCCESS;
1374*495ae853SAndroid Build Coastguard Worker }
1375*495ae853SAndroid Build Coastguard Worker 
isvce_populate_svc_slice(isvce_process_ctxt_t * ps_proc,svc_slice_header_t * ps_svc_slice_hdr,pps_t * ps_pps,subset_sps_t * ps_subset_sps,svc_nalu_ext_t * ps_svc_nalu_ext)1376*495ae853SAndroid Build Coastguard Worker WORD32 isvce_populate_svc_slice(isvce_process_ctxt_t *ps_proc, svc_slice_header_t *ps_svc_slice_hdr,
1377*495ae853SAndroid Build Coastguard Worker                                 pps_t *ps_pps, subset_sps_t *ps_subset_sps,
1378*495ae853SAndroid Build Coastguard Worker                                 svc_nalu_ext_t *ps_svc_nalu_ext)
1379*495ae853SAndroid Build Coastguard Worker {
1380*495ae853SAndroid Build Coastguard Worker     WORD32 i4_return_status;
1381*495ae853SAndroid Build Coastguard Worker 
1382*495ae853SAndroid Build Coastguard Worker     i4_return_status =
1383*495ae853SAndroid Build Coastguard Worker         isvce_populate_slice_header(ps_proc, &ps_svc_slice_hdr->s_slice_header, ps_pps,
1384*495ae853SAndroid Build Coastguard Worker                                     &ps_subset_sps->s_sps, ps_svc_nalu_ext->u1_idr_flag);
1385*495ae853SAndroid Build Coastguard Worker 
1386*495ae853SAndroid Build Coastguard Worker     if(IH264E_SUCCESS != i4_return_status)
1387*495ae853SAndroid Build Coastguard Worker     {
1388*495ae853SAndroid Build Coastguard Worker         return IH264E_FAIL;
1389*495ae853SAndroid Build Coastguard Worker     }
1390*495ae853SAndroid Build Coastguard Worker 
1391*495ae853SAndroid Build Coastguard Worker     ps_svc_slice_hdr->i1_slice_skip_flag = 0;
1392*495ae853SAndroid Build Coastguard Worker     ps_svc_slice_hdr->i1_adaptive_residual_prediction_flag = ENABLE_RESIDUAL_PREDICTION;
1393*495ae853SAndroid Build Coastguard Worker     ps_svc_slice_hdr->i1_default_residual_prediction_flag = 0;
1394*495ae853SAndroid Build Coastguard Worker     ps_svc_slice_hdr->i1_adaptive_base_mode_flag = ENABLE_ILP_MV || ENABLE_IBL_MODE;
1395*495ae853SAndroid Build Coastguard Worker     ps_svc_slice_hdr->i1_default_base_mode_flag = 0;
1396*495ae853SAndroid Build Coastguard Worker     ps_svc_slice_hdr->i1_tcoeff_level_prediction_flag = 0;
1397*495ae853SAndroid Build Coastguard Worker     ps_svc_slice_hdr->i1_constrained_intra_resampling_flag = 0;
1398*495ae853SAndroid Build Coastguard Worker     ps_svc_slice_hdr->i1_adaptive_motion_prediction_flag = USE_ILP_MV_AS_MVP;
1399*495ae853SAndroid Build Coastguard Worker     ps_svc_slice_hdr->i1_default_motion_prediction_flag = 0;
1400*495ae853SAndroid Build Coastguard Worker     ps_svc_slice_hdr->u4_disable_inter_layer_deblocking_filter_idc =
1401*495ae853SAndroid Build Coastguard Worker         !ENABLE_INTRA_BASE_DEBLOCK || ps_proc->u4_disable_deblock_level;
1402*495ae853SAndroid Build Coastguard Worker 
1403*495ae853SAndroid Build Coastguard Worker     if(ps_svc_slice_hdr->u4_disable_inter_layer_deblocking_filter_idc != 1)
1404*495ae853SAndroid Build Coastguard Worker     {
1405*495ae853SAndroid Build Coastguard Worker         /* slice_alpha_c0_offset_div2 */
1406*495ae853SAndroid Build Coastguard Worker         ps_svc_slice_hdr->i4_inter_layer_slice_alpha_c0_offset_div2 = 0;
1407*495ae853SAndroid Build Coastguard Worker 
1408*495ae853SAndroid Build Coastguard Worker         /* slice_beta_offset_div2 */
1409*495ae853SAndroid Build Coastguard Worker         ps_svc_slice_hdr->i4_inter_layer_slice_beta_offset_div2 = 0;
1410*495ae853SAndroid Build Coastguard Worker     }
1411*495ae853SAndroid Build Coastguard Worker 
1412*495ae853SAndroid Build Coastguard Worker     if((ps_svc_nalu_ext->u1_quality_id == 0) && (ps_svc_nalu_ext->u1_no_inter_layer_pred_flag == 0))
1413*495ae853SAndroid Build Coastguard Worker     {
1414*495ae853SAndroid Build Coastguard Worker         ps_svc_slice_hdr->u4_ref_layer_dq_id = (ps_proc->u1_spatial_layer_id - 1) << 4;
1415*495ae853SAndroid Build Coastguard Worker     }
1416*495ae853SAndroid Build Coastguard Worker 
1417*495ae853SAndroid Build Coastguard Worker     return IH264E_SUCCESS;
1418*495ae853SAndroid Build Coastguard Worker }
1419*495ae853SAndroid Build Coastguard Worker 
1420*495ae853SAndroid Build Coastguard Worker /**
1421*495ae853SAndroid Build Coastguard Worker ******************************************************************************
1422*495ae853SAndroid Build Coastguard Worker *
1423*495ae853SAndroid Build Coastguard Worker * @brief Signals prefix_nal_unit_rbsp
1424*495ae853SAndroid Build Coastguard Worker *
1425*495ae853SAndroid Build Coastguard Worker * @par   Description
1426*495ae853SAndroid Build Coastguard Worker *  prefix_nal_unit_rbsp as per Section G.7.3.2.12
1427*495ae853SAndroid Build Coastguard Worker *
1428*495ae853SAndroid Build Coastguard Worker * @param[inout]   ps_bitstrm
1429*495ae853SAndroid Build Coastguard Worker *  pointer to bitstream context for generating slice header
1430*495ae853SAndroid Build Coastguard Worker *
1431*495ae853SAndroid Build Coastguard Worker * @param[in]    svc_nalu_ext
1432*495ae853SAndroid Build Coastguard Worker *  pointer to svc NAL unit structure
1433*495ae853SAndroid Build Coastguard Worker *
1434*495ae853SAndroid Build Coastguard Worker * @param[in]    ps_slice_header
1435*495ae853SAndroid Build Coastguard Worker *  pointer to slice header
1436*495ae853SAndroid Build Coastguard Worker *
1437*495ae853SAndroid Build Coastguard Worker * @return      success or failure error code
1438*495ae853SAndroid Build Coastguard Worker *
1439*495ae853SAndroid Build Coastguard Worker ******************************************************************************
1440*495ae853SAndroid Build Coastguard Worker */
isvce_generate_prefix_nal(bitstrm_t * ps_bitstrm,svc_nalu_ext_t * ps_svc_nalu_ext,slice_header_t * ps_slice_header,UWORD8 u1_max_num_ref_frames,UWORD8 u1_num_spatial_layers)1441*495ae853SAndroid Build Coastguard Worker WORD32 isvce_generate_prefix_nal(bitstrm_t *ps_bitstrm, svc_nalu_ext_t *ps_svc_nalu_ext,
1442*495ae853SAndroid Build Coastguard Worker                                  slice_header_t *ps_slice_header, UWORD8 u1_max_num_ref_frames,
1443*495ae853SAndroid Build Coastguard Worker                                  UWORD8 u1_num_spatial_layers)
1444*495ae853SAndroid Build Coastguard Worker {
1445*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
1446*495ae853SAndroid Build Coastguard Worker 
1447*495ae853SAndroid Build Coastguard Worker     WORD32 i4_store_ref_base_pic_flag = 0;
1448*495ae853SAndroid Build Coastguard Worker     WORD32 i4_additional_prefix_nal_unit_extension_flag = 0;
1449*495ae853SAndroid Build Coastguard Worker 
1450*495ae853SAndroid Build Coastguard Worker     if(ps_svc_nalu_ext->u1_dependency_id == (u1_num_spatial_layers - 1))
1451*495ae853SAndroid Build Coastguard Worker     {
1452*495ae853SAndroid Build Coastguard Worker         i4_store_ref_base_pic_flag = 1;
1453*495ae853SAndroid Build Coastguard Worker         if(u1_max_num_ref_frames < 2)
1454*495ae853SAndroid Build Coastguard Worker         {
1455*495ae853SAndroid Build Coastguard Worker             i4_store_ref_base_pic_flag = 0;
1456*495ae853SAndroid Build Coastguard Worker         }
1457*495ae853SAndroid Build Coastguard Worker     }
1458*495ae853SAndroid Build Coastguard Worker 
1459*495ae853SAndroid Build Coastguard Worker     /* store_ref_base_pic_flag */
1460*495ae853SAndroid Build Coastguard Worker     if(ps_svc_nalu_ext->s_nalu_header.u1_nal_ref_idc != 0)
1461*495ae853SAndroid Build Coastguard Worker     {
1462*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, i4_store_ref_base_pic_flag, 1, return_status,
1463*495ae853SAndroid Build Coastguard Worker                  "store_ref_base_pic_flag");
1464*495ae853SAndroid Build Coastguard Worker 
1465*495ae853SAndroid Build Coastguard Worker         if((ps_svc_nalu_ext->u1_use_ref_base_pic_flag || i4_store_ref_base_pic_flag) &&
1466*495ae853SAndroid Build Coastguard Worker            !ps_svc_nalu_ext->u1_idr_flag)
1467*495ae853SAndroid Build Coastguard Worker         {
1468*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_header->u1_adaptive_ref_pic_marking_mode_flag, 1,
1469*495ae853SAndroid Build Coastguard Worker                      return_status, "DPRM: adaptive_ref_base_pic_marking_mode_flag");
1470*495ae853SAndroid Build Coastguard Worker         }
1471*495ae853SAndroid Build Coastguard Worker 
1472*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, i4_additional_prefix_nal_unit_extension_flag, 1, return_status,
1473*495ae853SAndroid Build Coastguard Worker                  "additional_prefix_nal_unit_extension_flag");
1474*495ae853SAndroid Build Coastguard Worker     }
1475*495ae853SAndroid Build Coastguard Worker 
1476*495ae853SAndroid Build Coastguard Worker     /* rbsp trailing bits */
1477*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_rbsp_trailing_bits(ps_bitstrm);
1478*495ae853SAndroid Build Coastguard Worker 
1479*495ae853SAndroid Build Coastguard Worker     return return_status;
1480*495ae853SAndroid Build Coastguard Worker }
1481*495ae853SAndroid Build Coastguard Worker 
isvce_generate_slice_header_svc(bitstrm_t * ps_bitstrm,pps_t * ps_pps,svc_nalu_ext_t * ps_svc_nalu_ext,svc_slice_header_t * ps_svc_slice_hdr,subset_sps_t * ps_subset_sps)1482*495ae853SAndroid Build Coastguard Worker WORD32 isvce_generate_slice_header_svc(bitstrm_t *ps_bitstrm, pps_t *ps_pps,
1483*495ae853SAndroid Build Coastguard Worker                                        svc_nalu_ext_t *ps_svc_nalu_ext,
1484*495ae853SAndroid Build Coastguard Worker                                        svc_slice_header_t *ps_svc_slice_hdr,
1485*495ae853SAndroid Build Coastguard Worker                                        subset_sps_t *ps_subset_sps)
1486*495ae853SAndroid Build Coastguard Worker {
1487*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
1488*495ae853SAndroid Build Coastguard Worker 
1489*495ae853SAndroid Build Coastguard Worker     UWORD8 u1_slice_type;
1490*495ae853SAndroid Build Coastguard Worker     sps_t *ps_sps = &ps_subset_sps->s_sps;
1491*495ae853SAndroid Build Coastguard Worker     slice_header_t *ps_slice_hdr = &ps_svc_slice_hdr->s_slice_header;
1492*495ae853SAndroid Build Coastguard Worker 
1493*495ae853SAndroid Build Coastguard Worker     /* first_mb_in_slice */
1494*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u2_first_mb_in_slice, return_status,
1495*495ae853SAndroid Build Coastguard Worker                  "SH: first_mb_in_slice");
1496*495ae853SAndroid Build Coastguard Worker 
1497*495ae853SAndroid Build Coastguard Worker     /* slice_type */
1498*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u1_slice_type, return_status, "SH: slice_type");
1499*495ae853SAndroid Build Coastguard Worker 
1500*495ae853SAndroid Build Coastguard Worker     /* pic_parameter_set_id */
1501*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u1_pps_id, return_status, "SH: pic_parameter_set_id");
1502*495ae853SAndroid Build Coastguard Worker 
1503*495ae853SAndroid Build Coastguard Worker     /* frame_num */
1504*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_slice_hdr->i4_frame_num, ps_sps->i1_log2_max_frame_num, return_status,
1505*495ae853SAndroid Build Coastguard Worker              "SH: frame_num");
1506*495ae853SAndroid Build Coastguard Worker 
1507*495ae853SAndroid Build Coastguard Worker     if(!ps_sps->i1_frame_mbs_only_flag)
1508*495ae853SAndroid Build Coastguard Worker     {
1509*495ae853SAndroid Build Coastguard Worker         /* field_pic_flag */
1510*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_slice_hdr->i1_field_pic_flag, 1, return_status,
1511*495ae853SAndroid Build Coastguard Worker                  "SH: field_pic_flag");
1512*495ae853SAndroid Build Coastguard Worker 
1513*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->i1_field_pic_flag)
1514*495ae853SAndroid Build Coastguard Worker         {
1515*495ae853SAndroid Build Coastguard Worker             /* bottom_field_flag */
1516*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_hdr->i1_bottom_field_flag, 1, return_status,
1517*495ae853SAndroid Build Coastguard Worker                      "SH: bottom_field_flag");
1518*495ae853SAndroid Build Coastguard Worker         }
1519*495ae853SAndroid Build Coastguard Worker     }
1520*495ae853SAndroid Build Coastguard Worker 
1521*495ae853SAndroid Build Coastguard Worker     if(ps_svc_nalu_ext->u1_idr_flag == 1)
1522*495ae853SAndroid Build Coastguard Worker     {
1523*495ae853SAndroid Build Coastguard Worker         /* u2_idr_pic_id */
1524*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u2_idr_pic_id, return_status, "SH: idr_pic_id");
1525*495ae853SAndroid Build Coastguard Worker     }
1526*495ae853SAndroid Build Coastguard Worker 
1527*495ae853SAndroid Build Coastguard Worker     if(ps_sps->i1_pic_order_cnt_type == 0)
1528*495ae853SAndroid Build Coastguard Worker     {
1529*495ae853SAndroid Build Coastguard Worker         /* pic_order_cnt_lsb */
1530*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_slice_hdr->i4_pic_order_cnt_lsb,
1531*495ae853SAndroid Build Coastguard Worker                  ps_sps->i1_log2_max_pic_order_cnt_lsb, return_status, "SH: pic_order_cnt_lsb");
1532*495ae853SAndroid Build Coastguard Worker 
1533*495ae853SAndroid Build Coastguard Worker         if(ps_pps->u1_pic_order_present_flag && !ps_slice_hdr->i1_field_pic_flag)
1534*495ae853SAndroid Build Coastguard Worker         {
1535*495ae853SAndroid Build Coastguard Worker             /* delta_pic_order_cnt_bottom */
1536*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->i4_delta_pic_order_cnt_bottom, return_status,
1537*495ae853SAndroid Build Coastguard Worker                          "SH: delta_pic_order_cnt_bottom");
1538*495ae853SAndroid Build Coastguard Worker         }
1539*495ae853SAndroid Build Coastguard Worker     }
1540*495ae853SAndroid Build Coastguard Worker 
1541*495ae853SAndroid Build Coastguard Worker     if(ps_sps->i1_pic_order_cnt_type == 1 && !ps_sps->i1_delta_pic_order_always_zero_flag)
1542*495ae853SAndroid Build Coastguard Worker     {
1543*495ae853SAndroid Build Coastguard Worker         /* delta_pic_order_cnt[0] */
1544*495ae853SAndroid Build Coastguard Worker         PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->ai4_delta_pic_order_cnt[0], return_status,
1545*495ae853SAndroid Build Coastguard Worker                      "SH: delta_pic_order_cnt[0]");
1546*495ae853SAndroid Build Coastguard Worker 
1547*495ae853SAndroid Build Coastguard Worker         if(ps_pps->u1_pic_order_present_flag && !ps_slice_hdr->i1_field_pic_flag)
1548*495ae853SAndroid Build Coastguard Worker         {
1549*495ae853SAndroid Build Coastguard Worker             /* delta_pic_order_cnt[1] */
1550*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->ai4_delta_pic_order_cnt[1], return_status,
1551*495ae853SAndroid Build Coastguard Worker                          "SH: delta_pic_order_cnt[1]");
1552*495ae853SAndroid Build Coastguard Worker         }
1553*495ae853SAndroid Build Coastguard Worker     }
1554*495ae853SAndroid Build Coastguard Worker 
1555*495ae853SAndroid Build Coastguard Worker     if(ps_pps->i1_redundant_pic_cnt_present_flag)
1556*495ae853SAndroid Build Coastguard Worker     {
1557*495ae853SAndroid Build Coastguard Worker         /* redundant_pic_cnt */
1558*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u1_redundant_pic_cnt, return_status,
1559*495ae853SAndroid Build Coastguard Worker                      "SH: redundant_pic_cnt");
1560*495ae853SAndroid Build Coastguard Worker     }
1561*495ae853SAndroid Build Coastguard Worker 
1562*495ae853SAndroid Build Coastguard Worker     u1_slice_type = ps_slice_hdr->u1_slice_type % EPSLICE;
1563*495ae853SAndroid Build Coastguard Worker 
1564*495ae853SAndroid Build Coastguard Worker     if(ps_svc_nalu_ext->u1_quality_id == 0)
1565*495ae853SAndroid Build Coastguard Worker     {
1566*495ae853SAndroid Build Coastguard Worker         if(u1_slice_type == BSLICE)
1567*495ae853SAndroid Build Coastguard Worker         {
1568*495ae853SAndroid Build Coastguard Worker             /* direct_spatial_mv_pred_flag */
1569*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_direct_spatial_mv_pred_flag, 1, return_status,
1570*495ae853SAndroid Build Coastguard Worker                      "SH: direct_spatial_mv_pred_flag");
1571*495ae853SAndroid Build Coastguard Worker         }
1572*495ae853SAndroid Build Coastguard Worker 
1573*495ae853SAndroid Build Coastguard Worker         if(u1_slice_type == PSLICE || u1_slice_type == BSLICE)
1574*495ae853SAndroid Build Coastguard Worker         {
1575*495ae853SAndroid Build Coastguard Worker             /* num_ref_idx_active_override_flag */
1576*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_num_ref_idx_active_override_flag, 1,
1577*495ae853SAndroid Build Coastguard Worker                      return_status, "SH: num_ref_idx_active_override_flag");
1578*495ae853SAndroid Build Coastguard Worker 
1579*495ae853SAndroid Build Coastguard Worker             if(ps_slice_hdr->u1_num_ref_idx_active_override_flag)
1580*495ae853SAndroid Build Coastguard Worker             {
1581*495ae853SAndroid Build Coastguard Worker                 /* num_ref_idx_l0_active_minus1 */
1582*495ae853SAndroid Build Coastguard Worker                 PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->i1_num_ref_idx_l0_active - 1, return_status,
1583*495ae853SAndroid Build Coastguard Worker                              "SH: num_ref_idx_l0_active_minus1");
1584*495ae853SAndroid Build Coastguard Worker 
1585*495ae853SAndroid Build Coastguard Worker                 if(u1_slice_type == BSLICE)
1586*495ae853SAndroid Build Coastguard Worker                 {
1587*495ae853SAndroid Build Coastguard Worker                     /* num_ref_idx_l1_active_minus1 */
1588*495ae853SAndroid Build Coastguard Worker                     PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->i1_num_ref_idx_l1_active - 1,
1589*495ae853SAndroid Build Coastguard Worker                                  return_status, "SH: num_ref_idx_l1_active_minus1");
1590*495ae853SAndroid Build Coastguard Worker                 }
1591*495ae853SAndroid Build Coastguard Worker             }
1592*495ae853SAndroid Build Coastguard Worker         }
1593*495ae853SAndroid Build Coastguard Worker 
1594*495ae853SAndroid Build Coastguard Worker         /* ref_pic_list_modification */
1595*495ae853SAndroid Build Coastguard Worker         if((u1_slice_type != ISLICE) && (u1_slice_type != SISLICE))
1596*495ae853SAndroid Build Coastguard Worker         {
1597*495ae853SAndroid Build Coastguard Worker             /* ref_pic_list_modification_flag_l0 */
1598*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l0, 1,
1599*495ae853SAndroid Build Coastguard Worker                      return_status, "RPLR: ref_pic_list_reordering_flag");
1600*495ae853SAndroid Build Coastguard Worker 
1601*495ae853SAndroid Build Coastguard Worker             if(ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l0)
1602*495ae853SAndroid Build Coastguard Worker             {
1603*495ae853SAndroid Build Coastguard Worker                 UWORD8 i = 0;
1604*495ae853SAndroid Build Coastguard Worker 
1605*495ae853SAndroid Build Coastguard Worker                 WORD8 *pi1_modification_of_pic_nums_idc_l0 =
1606*495ae853SAndroid Build Coastguard Worker                     ps_slice_hdr->s_rplm.i1_modification_of_pic_nums_idc_l0;
1607*495ae853SAndroid Build Coastguard Worker                 UWORD32 *pu4_abs_diff_pic_num_minus1_l0 =
1608*495ae853SAndroid Build Coastguard Worker                     ps_slice_hdr->s_rplm.u4_abs_diff_pic_num_minus1_l0;
1609*495ae853SAndroid Build Coastguard Worker                 UWORD8 *pu1_long_term_pic_num_l0 = ps_slice_hdr->s_rplm.u1_long_term_pic_num_l0;
1610*495ae853SAndroid Build Coastguard Worker 
1611*495ae853SAndroid Build Coastguard Worker                 do
1612*495ae853SAndroid Build Coastguard Worker                 {
1613*495ae853SAndroid Build Coastguard Worker                     /* modification_of_pic_nums_idc */
1614*495ae853SAndroid Build Coastguard Worker                     PUT_BITS_UEV(ps_bitstrm, pi1_modification_of_pic_nums_idc_l0[i], return_status,
1615*495ae853SAndroid Build Coastguard Worker                                  "RPLR: reordering_of_pic_nums_idc");
1616*495ae853SAndroid Build Coastguard Worker 
1617*495ae853SAndroid Build Coastguard Worker                     if((0 == pi1_modification_of_pic_nums_idc_l0[i]) ||
1618*495ae853SAndroid Build Coastguard Worker                        (1 == pi1_modification_of_pic_nums_idc_l0[i]))
1619*495ae853SAndroid Build Coastguard Worker                     {
1620*495ae853SAndroid Build Coastguard Worker                         /* abs_diff_pic_num_minus1 */
1621*495ae853SAndroid Build Coastguard Worker                         PUT_BITS_UEV(ps_bitstrm, pu4_abs_diff_pic_num_minus1_l0[0], return_status,
1622*495ae853SAndroid Build Coastguard Worker                                      "RPLR: abs_diff_pic_num_minus1");
1623*495ae853SAndroid Build Coastguard Worker 
1624*495ae853SAndroid Build Coastguard Worker                         pu4_abs_diff_pic_num_minus1_l0++;
1625*495ae853SAndroid Build Coastguard Worker                     }
1626*495ae853SAndroid Build Coastguard Worker                     else if(2 == pi1_modification_of_pic_nums_idc_l0[i])
1627*495ae853SAndroid Build Coastguard Worker                     {
1628*495ae853SAndroid Build Coastguard Worker                         /* long_term_pic_num */
1629*495ae853SAndroid Build Coastguard Worker                         PUT_BITS_UEV(ps_bitstrm, pu1_long_term_pic_num_l0[0], return_status,
1630*495ae853SAndroid Build Coastguard Worker                                      "RPLR: long_term_pic_num");
1631*495ae853SAndroid Build Coastguard Worker 
1632*495ae853SAndroid Build Coastguard Worker                         pu1_long_term_pic_num_l0++;
1633*495ae853SAndroid Build Coastguard Worker                     }
1634*495ae853SAndroid Build Coastguard Worker                 } while(pi1_modification_of_pic_nums_idc_l0[i++] != 3);
1635*495ae853SAndroid Build Coastguard Worker             }
1636*495ae853SAndroid Build Coastguard Worker         }
1637*495ae853SAndroid Build Coastguard Worker 
1638*495ae853SAndroid Build Coastguard Worker         if(u1_slice_type == BSLICE)
1639*495ae853SAndroid Build Coastguard Worker         {
1640*495ae853SAndroid Build Coastguard Worker             /* ref_pic_list_modification_flag_l1 */
1641*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l1, 1,
1642*495ae853SAndroid Build Coastguard Worker                      return_status, "SH: ref_pic_list_modification_flag_l1");
1643*495ae853SAndroid Build Coastguard Worker 
1644*495ae853SAndroid Build Coastguard Worker             if(ps_slice_hdr->s_rplm.i1_ref_pic_list_modification_flag_l1)
1645*495ae853SAndroid Build Coastguard Worker             {
1646*495ae853SAndroid Build Coastguard Worker                 UWORD8 i = 0;
1647*495ae853SAndroid Build Coastguard Worker 
1648*495ae853SAndroid Build Coastguard Worker                 WORD8 *pi1_modification_of_pic_nums_idc_l1 =
1649*495ae853SAndroid Build Coastguard Worker                     ps_slice_hdr->s_rplm.i1_modification_of_pic_nums_idc_l1;
1650*495ae853SAndroid Build Coastguard Worker                 UWORD32 *pu4_abs_diff_pic_num_minus1_l1 =
1651*495ae853SAndroid Build Coastguard Worker                     ps_slice_hdr->s_rplm.u4_abs_diff_pic_num_minus1_l1;
1652*495ae853SAndroid Build Coastguard Worker                 UWORD8 *pu1_long_term_pic_num_l1 = ps_slice_hdr->s_rplm.u1_long_term_pic_num_l1;
1653*495ae853SAndroid Build Coastguard Worker 
1654*495ae853SAndroid Build Coastguard Worker                 do
1655*495ae853SAndroid Build Coastguard Worker                 {
1656*495ae853SAndroid Build Coastguard Worker                     /* modification_of_pic_nums_idc */
1657*495ae853SAndroid Build Coastguard Worker                     PUT_BITS_UEV(ps_bitstrm, pi1_modification_of_pic_nums_idc_l1[i], return_status,
1658*495ae853SAndroid Build Coastguard Worker                                  "SH: modification_of_pic_nums_idc");
1659*495ae853SAndroid Build Coastguard Worker 
1660*495ae853SAndroid Build Coastguard Worker                     if((0 == pi1_modification_of_pic_nums_idc_l1[i]) ||
1661*495ae853SAndroid Build Coastguard Worker                        (1 == pi1_modification_of_pic_nums_idc_l1[i]))
1662*495ae853SAndroid Build Coastguard Worker                     {
1663*495ae853SAndroid Build Coastguard Worker                         /* abs_diff_pic_num_minus1 */
1664*495ae853SAndroid Build Coastguard Worker                         PUT_BITS_UEV(ps_bitstrm, pu4_abs_diff_pic_num_minus1_l1[0], return_status,
1665*495ae853SAndroid Build Coastguard Worker                                      "SH: abs_diff_pic_num_minus1");
1666*495ae853SAndroid Build Coastguard Worker 
1667*495ae853SAndroid Build Coastguard Worker                         pu4_abs_diff_pic_num_minus1_l1++;
1668*495ae853SAndroid Build Coastguard Worker                     }
1669*495ae853SAndroid Build Coastguard Worker                     else if(2 == pi1_modification_of_pic_nums_idc_l1[i])
1670*495ae853SAndroid Build Coastguard Worker                     {
1671*495ae853SAndroid Build Coastguard Worker                         /* long_term_pic_num */
1672*495ae853SAndroid Build Coastguard Worker                         PUT_BITS_UEV(ps_bitstrm, pu1_long_term_pic_num_l1[0], return_status,
1673*495ae853SAndroid Build Coastguard Worker                                      "SH: abs_diff_pic_num_minus1");
1674*495ae853SAndroid Build Coastguard Worker 
1675*495ae853SAndroid Build Coastguard Worker                         pu1_long_term_pic_num_l1++;
1676*495ae853SAndroid Build Coastguard Worker                     }
1677*495ae853SAndroid Build Coastguard Worker                 } while(pi1_modification_of_pic_nums_idc_l1[i++] != 3);
1678*495ae853SAndroid Build Coastguard Worker             }
1679*495ae853SAndroid Build Coastguard Worker         }
1680*495ae853SAndroid Build Coastguard Worker 
1681*495ae853SAndroid Build Coastguard Worker         if((ps_pps->i1_weighted_pred_flag && u1_slice_type == PSLICE) ||
1682*495ae853SAndroid Build Coastguard Worker            (u1_slice_type == BSLICE && ps_pps->i1_weighted_bipred_idc == 1))
1683*495ae853SAndroid Build Coastguard Worker         {
1684*495ae853SAndroid Build Coastguard Worker             /* TODO_LATER: Currently there is no support for weighted prediction.
1685*495ae853SAndroid Build Coastguard Worker              This needs to be updated when the support is added */
1686*495ae853SAndroid Build Coastguard Worker         }
1687*495ae853SAndroid Build Coastguard Worker 
1688*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->i1_nal_unit_idc != 0)
1689*495ae853SAndroid Build Coastguard Worker         {
1690*495ae853SAndroid Build Coastguard Worker             if(ps_svc_nalu_ext->u1_idr_flag)
1691*495ae853SAndroid Build Coastguard Worker             {
1692*495ae853SAndroid Build Coastguard Worker                 /* no_output_of_prior_pics_flag  */
1693*495ae853SAndroid Build Coastguard Worker                 PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_no_output_of_prior_pics_flag, 1,
1694*495ae853SAndroid Build Coastguard Worker                          return_status, "DRPM: no_output_of_prior_pics_flag ");
1695*495ae853SAndroid Build Coastguard Worker 
1696*495ae853SAndroid Build Coastguard Worker                 /* long_term_reference_flag  */
1697*495ae853SAndroid Build Coastguard Worker                 PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_long_term_reference_flag, 1, return_status,
1698*495ae853SAndroid Build Coastguard Worker                          "DRPM: long_term_reference_flag ");
1699*495ae853SAndroid Build Coastguard Worker             }
1700*495ae853SAndroid Build Coastguard Worker             else
1701*495ae853SAndroid Build Coastguard Worker             {
1702*495ae853SAndroid Build Coastguard Worker                 /* adaptive_ref_pic_marking_mode_flag  */
1703*495ae853SAndroid Build Coastguard Worker                 PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_adaptive_ref_pic_marking_mode_flag, 1,
1704*495ae853SAndroid Build Coastguard Worker                          return_status, "DPRM: adaptive_ref_pic_marking_mode_flag ");
1705*495ae853SAndroid Build Coastguard Worker 
1706*495ae853SAndroid Build Coastguard Worker                 if(ps_slice_hdr->u1_adaptive_ref_pic_marking_mode_flag)
1707*495ae853SAndroid Build Coastguard Worker                 {
1708*495ae853SAndroid Build Coastguard Worker                     /* TODO: if the reference picture marking mode is adaptive
1709*495ae853SAndroid Build Coastguard Worker                      add these fields in the bit-stream */
1710*495ae853SAndroid Build Coastguard Worker                 }
1711*495ae853SAndroid Build Coastguard Worker             }
1712*495ae853SAndroid Build Coastguard Worker             if(ps_subset_sps->s_sps_svc_ext.i1_slice_header_restriction_flag == 0)
1713*495ae853SAndroid Build Coastguard Worker             {
1714*495ae853SAndroid Build Coastguard Worker                 WORD32 i4_store_ref_base_pic_flag = 0;
1715*495ae853SAndroid Build Coastguard Worker 
1716*495ae853SAndroid Build Coastguard Worker                 if(ps_sps->u1_max_num_ref_frames >= 2)
1717*495ae853SAndroid Build Coastguard Worker                 {
1718*495ae853SAndroid Build Coastguard Worker                     i4_store_ref_base_pic_flag = 1;
1719*495ae853SAndroid Build Coastguard Worker                 }
1720*495ae853SAndroid Build Coastguard Worker 
1721*495ae853SAndroid Build Coastguard Worker                 /* store_ref_base_pic_flag */
1722*495ae853SAndroid Build Coastguard Worker                 PUT_BITS(ps_bitstrm, i4_store_ref_base_pic_flag, 1, return_status,
1723*495ae853SAndroid Build Coastguard Worker                          "SH: store_ref_base_pic_flag");
1724*495ae853SAndroid Build Coastguard Worker 
1725*495ae853SAndroid Build Coastguard Worker                 if((ps_svc_nalu_ext->u1_use_ref_base_pic_flag || i4_store_ref_base_pic_flag) &&
1726*495ae853SAndroid Build Coastguard Worker                    (!ps_svc_nalu_ext->u1_idr_flag))
1727*495ae853SAndroid Build Coastguard Worker                 {
1728*495ae853SAndroid Build Coastguard Worker                     PUT_BITS(ps_bitstrm, ps_slice_hdr->u1_adaptive_ref_pic_marking_mode_flag, 1,
1729*495ae853SAndroid Build Coastguard Worker                              return_status, "SH: adaptive_ref_base_pic_marking_mode_flag");
1730*495ae853SAndroid Build Coastguard Worker                 }
1731*495ae853SAndroid Build Coastguard Worker             }
1732*495ae853SAndroid Build Coastguard Worker         }
1733*495ae853SAndroid Build Coastguard Worker     }
1734*495ae853SAndroid Build Coastguard Worker 
1735*495ae853SAndroid Build Coastguard Worker     if(ps_slice_hdr->u1_entropy_coding_mode_flag && u1_slice_type != ISLICE)
1736*495ae853SAndroid Build Coastguard Worker     {
1737*495ae853SAndroid Build Coastguard Worker         /* cabac_init_idc */
1738*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->i1_cabac_init_idc, return_status,
1739*495ae853SAndroid Build Coastguard Worker                      "SH: cabac_init_idc");
1740*495ae853SAndroid Build Coastguard Worker     }
1741*495ae853SAndroid Build Coastguard Worker 
1742*495ae853SAndroid Build Coastguard Worker     /* slice_qp_delta */
1743*495ae853SAndroid Build Coastguard Worker     PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->i1_slice_qp - ps_pps->i1_pic_init_qp, return_status,
1744*495ae853SAndroid Build Coastguard Worker                  "SH: slice_qp_delta");
1745*495ae853SAndroid Build Coastguard Worker 
1746*495ae853SAndroid Build Coastguard Worker     if(ps_pps->i1_deblocking_filter_control_present_flag)
1747*495ae853SAndroid Build Coastguard Worker     {
1748*495ae853SAndroid Build Coastguard Worker         /* disable_deblocking_filter_idc */
1749*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_slice_hdr->u1_disable_deblocking_filter_idc, return_status,
1750*495ae853SAndroid Build Coastguard Worker                      "SH: disable_deblocking_filter_idc");
1751*495ae853SAndroid Build Coastguard Worker 
1752*495ae853SAndroid Build Coastguard Worker         if(ps_slice_hdr->u1_disable_deblocking_filter_idc != 1)
1753*495ae853SAndroid Build Coastguard Worker         {
1754*495ae853SAndroid Build Coastguard Worker             /* slice_alpha_c0_offset_div2 */
1755*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->i1_slice_alpha_c0_offset_div2, return_status,
1756*495ae853SAndroid Build Coastguard Worker                          "SH: slice_alpha_c0_offset_div2");
1757*495ae853SAndroid Build Coastguard Worker 
1758*495ae853SAndroid Build Coastguard Worker             /* slice_beta_offset_div2 */
1759*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_slice_hdr->i1_slice_beta_offset_div2, return_status,
1760*495ae853SAndroid Build Coastguard Worker                          "SH: slice_beta_offset_div2");
1761*495ae853SAndroid Build Coastguard Worker         }
1762*495ae853SAndroid Build Coastguard Worker     }
1763*495ae853SAndroid Build Coastguard Worker 
1764*495ae853SAndroid Build Coastguard Worker     if(ps_slice_hdr->u1_num_slice_groups_minus1 > 0 && ps_pps->u1_slice_group_map_type >= 3 &&
1765*495ae853SAndroid Build Coastguard Worker        ps_pps->u1_slice_group_map_type <= 5)
1766*495ae853SAndroid Build Coastguard Worker     {
1767*495ae853SAndroid Build Coastguard Worker         /* slice_group_change_cycle */
1768*495ae853SAndroid Build Coastguard Worker         /* TODO_LATER: Currently the number of slice groups minus 1 is 0.
1769*495ae853SAndroid Build Coastguard Worker          * If this is not the case, we have to add Slice group map type to the bit
1770*495ae853SAndroid Build Coastguard Worker          * stream */
1771*495ae853SAndroid Build Coastguard Worker     }
1772*495ae853SAndroid Build Coastguard Worker 
1773*495ae853SAndroid Build Coastguard Worker     if((ps_svc_nalu_ext->u1_no_inter_layer_pred_flag == 0) && (ps_svc_nalu_ext->u1_quality_id == 0))
1774*495ae853SAndroid Build Coastguard Worker     {
1775*495ae853SAndroid Build Coastguard Worker         PUT_BITS_UEV(ps_bitstrm, ps_svc_slice_hdr->u4_ref_layer_dq_id, return_status,
1776*495ae853SAndroid Build Coastguard Worker                      "SH: ref_layer_dq_id");
1777*495ae853SAndroid Build Coastguard Worker         if(ps_subset_sps->s_sps_svc_ext.u1_inter_layer_deblocking_filter_control_present_flag)
1778*495ae853SAndroid Build Coastguard Worker         {
1779*495ae853SAndroid Build Coastguard Worker             PUT_BITS_UEV(ps_bitstrm, ps_svc_slice_hdr->u4_disable_inter_layer_deblocking_filter_idc,
1780*495ae853SAndroid Build Coastguard Worker                          return_status, "SH: disable_inter_layer_deblocking_filter_idc");
1781*495ae853SAndroid Build Coastguard Worker             if(ps_svc_slice_hdr->u4_disable_inter_layer_deblocking_filter_idc != 1)
1782*495ae853SAndroid Build Coastguard Worker             {
1783*495ae853SAndroid Build Coastguard Worker                 PUT_BITS_SEV(ps_bitstrm,
1784*495ae853SAndroid Build Coastguard Worker                              ps_svc_slice_hdr->i4_inter_layer_slice_alpha_c0_offset_div2,
1785*495ae853SAndroid Build Coastguard Worker                              return_status, "SH: inter_layer_slice_alpha_c0_offset_div2");
1786*495ae853SAndroid Build Coastguard Worker                 PUT_BITS_SEV(ps_bitstrm, ps_svc_slice_hdr->i4_inter_layer_slice_beta_offset_div2,
1787*495ae853SAndroid Build Coastguard Worker                              return_status, "SH: inter_layer_slice_beta_offset_div2");
1788*495ae853SAndroid Build Coastguard Worker             }
1789*495ae853SAndroid Build Coastguard Worker         }
1790*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_svc_slice_hdr->i1_constrained_intra_resampling_flag, 1,
1791*495ae853SAndroid Build Coastguard Worker                  return_status, "SH: constrained_intra_resampling_flag");
1792*495ae853SAndroid Build Coastguard Worker         if(ps_subset_sps->s_sps_svc_ext.u1_extended_spatial_scalability_idc == 2)
1793*495ae853SAndroid Build Coastguard Worker         {
1794*495ae853SAndroid Build Coastguard Worker             if(ps_sps->u1_chroma_format_idc > 0)
1795*495ae853SAndroid Build Coastguard Worker             {
1796*495ae853SAndroid Build Coastguard Worker                 PUT_BITS(ps_bitstrm, ps_svc_slice_hdr->i1_ref_layer_chroma_phase_x_plus1_flag, 1,
1797*495ae853SAndroid Build Coastguard Worker                          return_status, "SH: ref_layer_chroma_phase_x_plus1_flag");
1798*495ae853SAndroid Build Coastguard Worker                 PUT_BITS(ps_bitstrm, ps_svc_slice_hdr->i1_ref_layer_chroma_phase_y_plus1, 2,
1799*495ae853SAndroid Build Coastguard Worker                          return_status, "SH: ref_layer_chroma_phase_y_plus1");
1800*495ae853SAndroid Build Coastguard Worker             }
1801*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_svc_slice_hdr->i4_scaled_ref_layer_left, return_status,
1802*495ae853SAndroid Build Coastguard Worker                          "SH: scaled_ref_layer_left_offset");
1803*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_svc_slice_hdr->i4_scaled_ref_layer_top, return_status,
1804*495ae853SAndroid Build Coastguard Worker                          "SH: scaled_ref_layer_top_offset");
1805*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_svc_slice_hdr->i4_scaled_ref_layer_right, return_status,
1806*495ae853SAndroid Build Coastguard Worker                          "SH: scaled_ref_layer_right_offset");
1807*495ae853SAndroid Build Coastguard Worker             PUT_BITS_SEV(ps_bitstrm, ps_svc_slice_hdr->i4_scaled_ref_layer_bottom, return_status,
1808*495ae853SAndroid Build Coastguard Worker                          "SH: scaled_ref_layer_bottom_offset");
1809*495ae853SAndroid Build Coastguard Worker         }
1810*495ae853SAndroid Build Coastguard Worker     }
1811*495ae853SAndroid Build Coastguard Worker 
1812*495ae853SAndroid Build Coastguard Worker     if(!ps_svc_nalu_ext->u1_no_inter_layer_pred_flag)
1813*495ae853SAndroid Build Coastguard Worker     {
1814*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_svc_slice_hdr->i1_slice_skip_flag, 1, return_status,
1815*495ae853SAndroid Build Coastguard Worker                  "SH: slice_skip_flag");
1816*495ae853SAndroid Build Coastguard Worker         if(ps_svc_slice_hdr->i1_slice_skip_flag)
1817*495ae853SAndroid Build Coastguard Worker         {
1818*495ae853SAndroid Build Coastguard Worker             PUT_BITS_UEV(ps_bitstrm, ps_svc_slice_hdr->u4_num_mbs_in_slice_minus1, return_status,
1819*495ae853SAndroid Build Coastguard Worker                          "SH: num_mbs_in_slice_minus1");
1820*495ae853SAndroid Build Coastguard Worker         }
1821*495ae853SAndroid Build Coastguard Worker         else
1822*495ae853SAndroid Build Coastguard Worker         {
1823*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_svc_slice_hdr->i1_adaptive_base_mode_flag, 1, return_status,
1824*495ae853SAndroid Build Coastguard Worker                      "SH: adaptive_base_mode_flag");
1825*495ae853SAndroid Build Coastguard Worker             if(!ps_svc_slice_hdr->i1_adaptive_base_mode_flag)
1826*495ae853SAndroid Build Coastguard Worker                 PUT_BITS(ps_bitstrm, ps_svc_slice_hdr->i1_default_base_mode_flag, 1, return_status,
1827*495ae853SAndroid Build Coastguard Worker                          "SH: default_base_mode_flag");
1828*495ae853SAndroid Build Coastguard Worker 
1829*495ae853SAndroid Build Coastguard Worker             if(!ps_svc_slice_hdr->i1_default_base_mode_flag)
1830*495ae853SAndroid Build Coastguard Worker             {
1831*495ae853SAndroid Build Coastguard Worker                 PUT_BITS(ps_bitstrm, ps_svc_slice_hdr->i1_adaptive_motion_prediction_flag, 1,
1832*495ae853SAndroid Build Coastguard Worker                          return_status, "SH: adaptive_motion_prediction_flag");
1833*495ae853SAndroid Build Coastguard Worker                 if(!ps_svc_slice_hdr->i1_adaptive_motion_prediction_flag)
1834*495ae853SAndroid Build Coastguard Worker                     PUT_BITS(ps_bitstrm, ps_svc_slice_hdr->i1_default_motion_prediction_flag, 1,
1835*495ae853SAndroid Build Coastguard Worker                              return_status, "SH: default_motion_prediction_flag");
1836*495ae853SAndroid Build Coastguard Worker             }
1837*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_svc_slice_hdr->i1_adaptive_residual_prediction_flag, 1,
1838*495ae853SAndroid Build Coastguard Worker                      return_status, "SH: adaptive_residual_prediction_flag");
1839*495ae853SAndroid Build Coastguard Worker             if(!ps_svc_slice_hdr->i1_adaptive_residual_prediction_flag)
1840*495ae853SAndroid Build Coastguard Worker                 PUT_BITS(ps_bitstrm, ps_svc_slice_hdr->i1_default_residual_prediction_flag, 1,
1841*495ae853SAndroid Build Coastguard Worker                          return_status, "SH: default_residual_prediction_flag");
1842*495ae853SAndroid Build Coastguard Worker         }
1843*495ae853SAndroid Build Coastguard Worker 
1844*495ae853SAndroid Build Coastguard Worker         if(ps_subset_sps->s_sps_svc_ext.i1_adaptive_tcoeff_level_prediction_flag)
1845*495ae853SAndroid Build Coastguard Worker         {
1846*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_svc_slice_hdr->i1_tcoeff_level_prediction_flag, 1,
1847*495ae853SAndroid Build Coastguard Worker                      return_status, "SH: tcoeff_level_prediction_flag");
1848*495ae853SAndroid Build Coastguard Worker         }
1849*495ae853SAndroid Build Coastguard Worker     }
1850*495ae853SAndroid Build Coastguard Worker 
1851*495ae853SAndroid Build Coastguard Worker     if(!ps_subset_sps->s_sps_svc_ext.i1_slice_header_restriction_flag &&
1852*495ae853SAndroid Build Coastguard Worker        !ps_svc_slice_hdr->i1_slice_skip_flag)
1853*495ae853SAndroid Build Coastguard Worker     {
1854*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_svc_slice_hdr->u4_scan_idx_start, 4, return_status,
1855*495ae853SAndroid Build Coastguard Worker                  "SH: scan_idx_start");
1856*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_svc_slice_hdr->u4_scan_idx_end, 4, return_status,
1857*495ae853SAndroid Build Coastguard Worker                  "SH: scan_idx_end");
1858*495ae853SAndroid Build Coastguard Worker     }
1859*495ae853SAndroid Build Coastguard Worker 
1860*495ae853SAndroid Build Coastguard Worker     return return_status;
1861*495ae853SAndroid Build Coastguard Worker }
1862*495ae853SAndroid Build Coastguard Worker 
isvce_seq_parameter_set_svc_extension(bitstrm_t * ps_bitstrm,subset_sps_t * ps_sub_sps,UWORD8 u1_chroma_format_idc)1863*495ae853SAndroid Build Coastguard Worker WORD32 isvce_seq_parameter_set_svc_extension(bitstrm_t *ps_bitstrm, subset_sps_t *ps_sub_sps,
1864*495ae853SAndroid Build Coastguard Worker                                              UWORD8 u1_chroma_format_idc)
1865*495ae853SAndroid Build Coastguard Worker {
1866*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
1867*495ae853SAndroid Build Coastguard Worker 
1868*495ae853SAndroid Build Coastguard Worker     /* inter_layer_deblocking_filter_control_present_flag */
1869*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm,
1870*495ae853SAndroid Build Coastguard Worker              ps_sub_sps->s_sps_svc_ext.u1_inter_layer_deblocking_filter_control_present_flag, 1,
1871*495ae853SAndroid Build Coastguard Worker              return_status, "SPS: inter_layer_deblocking_filter_control_present_flag");
1872*495ae853SAndroid Build Coastguard Worker 
1873*495ae853SAndroid Build Coastguard Worker     /* extended_spatial_scalability */
1874*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sub_sps->s_sps_svc_ext.u1_extended_spatial_scalability_idc, 2,
1875*495ae853SAndroid Build Coastguard Worker              return_status, "SPS: extended_spatial_scalability");
1876*495ae853SAndroid Build Coastguard Worker 
1877*495ae853SAndroid Build Coastguard Worker     if(u1_chroma_format_idc == 1 || u1_chroma_format_idc == 2)
1878*495ae853SAndroid Build Coastguard Worker     {
1879*495ae853SAndroid Build Coastguard Worker         /* chroma_phase_x_plus1_flag */
1880*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_sub_sps->s_sps_svc_ext.u1_chroma_phase_x_plus1, 1, return_status,
1881*495ae853SAndroid Build Coastguard Worker                  "SPS: chroma_phase_x_plus1_flag");
1882*495ae853SAndroid Build Coastguard Worker     }
1883*495ae853SAndroid Build Coastguard Worker 
1884*495ae853SAndroid Build Coastguard Worker     if(u1_chroma_format_idc == 1)
1885*495ae853SAndroid Build Coastguard Worker     {
1886*495ae853SAndroid Build Coastguard Worker         /* chroma_phase_y_plus1 */
1887*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_sub_sps->s_sps_svc_ext.u1_chroma_phase_y_plus1, 2, return_status,
1888*495ae853SAndroid Build Coastguard Worker                  "SPS: chroma_phase_y_plus1");
1889*495ae853SAndroid Build Coastguard Worker     }
1890*495ae853SAndroid Build Coastguard Worker 
1891*495ae853SAndroid Build Coastguard Worker     if(ps_sub_sps->s_sps_svc_ext.u1_extended_spatial_scalability_idc == 1)
1892*495ae853SAndroid Build Coastguard Worker     {
1893*495ae853SAndroid Build Coastguard Worker         if(u1_chroma_format_idc > 0)
1894*495ae853SAndroid Build Coastguard Worker         {
1895*495ae853SAndroid Build Coastguard Worker             /* seq_ref_layer_chroma_phase_x_plus1_flag */
1896*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm,
1897*495ae853SAndroid Build Coastguard Worker                      ps_sub_sps->s_sps_svc_ext.u1_seq_ref_layer_chroma_phase_x_plus1_flag, 1,
1898*495ae853SAndroid Build Coastguard Worker                      return_status, "SPS: seq_ref_layer_chroma_phase_x_plus1_flag");
1899*495ae853SAndroid Build Coastguard Worker 
1900*495ae853SAndroid Build Coastguard Worker             /* seq_ref_layer_chroma_phase_y_plus1 */
1901*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_sub_sps->s_sps_svc_ext.u1_seq_ref_layer_chroma_phase_y_plus1, 2,
1902*495ae853SAndroid Build Coastguard Worker                      return_status, "SPS: seq_ref_layer_chroma_phase_y_plus1");
1903*495ae853SAndroid Build Coastguard Worker         }
1904*495ae853SAndroid Build Coastguard Worker         /* seq_scaled_ref_layer_left_offset */
1905*495ae853SAndroid Build Coastguard Worker         PUT_BITS_SEV(ps_bitstrm, ps_sub_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_left_offset,
1906*495ae853SAndroid Build Coastguard Worker                      return_status, "SPS: seq_scaled_ref_layer_left_offset");
1907*495ae853SAndroid Build Coastguard Worker 
1908*495ae853SAndroid Build Coastguard Worker         /* seq_scaled_ref_layer_top_offset */
1909*495ae853SAndroid Build Coastguard Worker         PUT_BITS_SEV(ps_bitstrm, ps_sub_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_top_offset,
1910*495ae853SAndroid Build Coastguard Worker                      return_status, "SPS: seq_scaled_ref_layer_top_offset");
1911*495ae853SAndroid Build Coastguard Worker 
1912*495ae853SAndroid Build Coastguard Worker         /* seq_scaled_ref_layer_right_offset */
1913*495ae853SAndroid Build Coastguard Worker         PUT_BITS_SEV(ps_bitstrm, ps_sub_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_right_offset,
1914*495ae853SAndroid Build Coastguard Worker                      return_status, "SPS: seq_scaled_ref_layer_right_offset");
1915*495ae853SAndroid Build Coastguard Worker 
1916*495ae853SAndroid Build Coastguard Worker         /* seq_scaled_ref_layer_bottom_offset */
1917*495ae853SAndroid Build Coastguard Worker         PUT_BITS_SEV(ps_bitstrm, ps_sub_sps->s_sps_svc_ext.i4_seq_scaled_ref_layer_bottom_offset,
1918*495ae853SAndroid Build Coastguard Worker                      return_status, "SPS: seq_scaled_ref_layer_bottom_offset");
1919*495ae853SAndroid Build Coastguard Worker     }
1920*495ae853SAndroid Build Coastguard Worker 
1921*495ae853SAndroid Build Coastguard Worker     /* seq_tcoeff_level_prediction_flag */
1922*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sub_sps->s_sps_svc_ext.i1_seq_tcoeff_level_prediction_flag, 1,
1923*495ae853SAndroid Build Coastguard Worker              return_status, "SPS: seq_tcoeff_level_prediction_flag");
1924*495ae853SAndroid Build Coastguard Worker 
1925*495ae853SAndroid Build Coastguard Worker     if(ps_sub_sps->s_sps_svc_ext.i1_seq_tcoeff_level_prediction_flag)
1926*495ae853SAndroid Build Coastguard Worker     {
1927*495ae853SAndroid Build Coastguard Worker         /* adaptive_tcoeff_level_prediction_flag */
1928*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_sub_sps->s_sps_svc_ext.i1_adaptive_tcoeff_level_prediction_flag, 1,
1929*495ae853SAndroid Build Coastguard Worker                  return_status, "SPS: adaptive_tcoeff_level_prediction_flag");
1930*495ae853SAndroid Build Coastguard Worker     }
1931*495ae853SAndroid Build Coastguard Worker 
1932*495ae853SAndroid Build Coastguard Worker     /* slice_header_restriction_flag */
1933*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_sub_sps->s_sps_svc_ext.i1_slice_header_restriction_flag, 1,
1934*495ae853SAndroid Build Coastguard Worker              return_status, "SPS: slice_header_restriction_flag");
1935*495ae853SAndroid Build Coastguard Worker 
1936*495ae853SAndroid Build Coastguard Worker     return return_status;
1937*495ae853SAndroid Build Coastguard Worker }
1938*495ae853SAndroid Build Coastguard Worker 
isvce_svc_vui_parameters_extension(bitstrm_t * ps_bitstrm,svc_vui_ext_t * ps_svc_vui)1939*495ae853SAndroid Build Coastguard Worker WORD32 isvce_svc_vui_parameters_extension(bitstrm_t *ps_bitstrm, svc_vui_ext_t *ps_svc_vui)
1940*495ae853SAndroid Build Coastguard Worker {
1941*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
1942*495ae853SAndroid Build Coastguard Worker     UWORD32 i;
1943*495ae853SAndroid Build Coastguard Worker 
1944*495ae853SAndroid Build Coastguard Worker     PUT_BITS_UEV(ps_bitstrm, ps_svc_vui->u4_vui_ext_num_entries_minus1, return_status,
1945*495ae853SAndroid Build Coastguard Worker                  "num_layers_minus1");
1946*495ae853SAndroid Build Coastguard Worker 
1947*495ae853SAndroid Build Coastguard Worker     for(i = 0; i < ps_svc_vui->u4_vui_ext_num_entries_minus1; i++)
1948*495ae853SAndroid Build Coastguard Worker     {
1949*495ae853SAndroid Build Coastguard Worker         /* dependency_id */
1950*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_svc_vui->u1_vui_ext_dependency_id[i], 3, return_status,
1951*495ae853SAndroid Build Coastguard Worker                  "dependency_id");
1952*495ae853SAndroid Build Coastguard Worker 
1953*495ae853SAndroid Build Coastguard Worker         /* quality_id */
1954*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_svc_vui->u1_vui_ext_quality_id[i], 4, return_status, "quality_id");
1955*495ae853SAndroid Build Coastguard Worker 
1956*495ae853SAndroid Build Coastguard Worker         /* temporal_id */
1957*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_svc_vui->u1_vui_ext_temporal_id[i], 3, return_status,
1958*495ae853SAndroid Build Coastguard Worker                  "temporal_id");
1959*495ae853SAndroid Build Coastguard Worker 
1960*495ae853SAndroid Build Coastguard Worker         /* timing_info_present_flag */
1961*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_svc_vui->u1_vui_ext_timing_info_present_flag[i], 1, return_status,
1962*495ae853SAndroid Build Coastguard Worker                  "timing_info_present_flag");
1963*495ae853SAndroid Build Coastguard Worker 
1964*495ae853SAndroid Build Coastguard Worker         if(ps_svc_vui->u1_vui_ext_timing_info_present_flag[i])
1965*495ae853SAndroid Build Coastguard Worker         {
1966*495ae853SAndroid Build Coastguard Worker             /* num_units_in_tick */
1967*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_svc_vui->u4_vui_ext_num_units_in_tick[i], 32, return_status,
1968*495ae853SAndroid Build Coastguard Worker                      "num_units_in_tick");
1969*495ae853SAndroid Build Coastguard Worker 
1970*495ae853SAndroid Build Coastguard Worker             /* time_scale */
1971*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_svc_vui->u4_vui_ext_time_scale[i], 32, return_status,
1972*495ae853SAndroid Build Coastguard Worker                      "time_scale");
1973*495ae853SAndroid Build Coastguard Worker 
1974*495ae853SAndroid Build Coastguard Worker             /* fixed_frame_rate_flag */
1975*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_svc_vui->u1_vui_ext_fixed_frame_rate_flag[i], 1, return_status,
1976*495ae853SAndroid Build Coastguard Worker                      "fixed_frame_rate_flag");
1977*495ae853SAndroid Build Coastguard Worker         }
1978*495ae853SAndroid Build Coastguard Worker 
1979*495ae853SAndroid Build Coastguard Worker         /* nal_hrd_parameters_present_flag */
1980*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_svc_vui->u1_vui_ext_nal_hrd_params_present_flag[i], 1,
1981*495ae853SAndroid Build Coastguard Worker                  return_status, "nal_hrd_parameters_present_flag");
1982*495ae853SAndroid Build Coastguard Worker 
1983*495ae853SAndroid Build Coastguard Worker         if(ps_svc_vui->u1_vui_ext_nal_hrd_params_present_flag[i])
1984*495ae853SAndroid Build Coastguard Worker         {
1985*495ae853SAndroid Build Coastguard Worker         }
1986*495ae853SAndroid Build Coastguard Worker 
1987*495ae853SAndroid Build Coastguard Worker         /* nal_hrd_parameters_present_flag */
1988*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_svc_vui->u1_vui_ext_vcl_hrd_params_present_flag[i], 1,
1989*495ae853SAndroid Build Coastguard Worker                  return_status, "vcl_hrd_parameters_present_flag");
1990*495ae853SAndroid Build Coastguard Worker 
1991*495ae853SAndroid Build Coastguard Worker         if(ps_svc_vui->u1_vui_ext_vcl_hrd_params_present_flag[i])
1992*495ae853SAndroid Build Coastguard Worker         {
1993*495ae853SAndroid Build Coastguard Worker         }
1994*495ae853SAndroid Build Coastguard Worker 
1995*495ae853SAndroid Build Coastguard Worker         if(ps_svc_vui->u1_vui_ext_nal_hrd_params_present_flag[i] ||
1996*495ae853SAndroid Build Coastguard Worker            ps_svc_vui->u1_vui_ext_vcl_hrd_params_present_flag[i])
1997*495ae853SAndroid Build Coastguard Worker         {
1998*495ae853SAndroid Build Coastguard Worker             /* low_delay_hrd_flag */
1999*495ae853SAndroid Build Coastguard Worker             PUT_BITS(ps_bitstrm, ps_svc_vui->u1_vui_ext_low_delay_hrd_flag[i], 1, return_status,
2000*495ae853SAndroid Build Coastguard Worker                      "low_delay_hrd_flag");
2001*495ae853SAndroid Build Coastguard Worker         }
2002*495ae853SAndroid Build Coastguard Worker 
2003*495ae853SAndroid Build Coastguard Worker         /* pic_struct_present_flag */
2004*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_svc_vui->u1_vui_ext_pic_struct_present_flag[i], 1, return_status,
2005*495ae853SAndroid Build Coastguard Worker                  "pic_struct_present_flag");
2006*495ae853SAndroid Build Coastguard Worker     }
2007*495ae853SAndroid Build Coastguard Worker 
2008*495ae853SAndroid Build Coastguard Worker     return return_status;
2009*495ae853SAndroid Build Coastguard Worker }
2010*495ae853SAndroid Build Coastguard Worker 
isvce_generate_subset_sps(bitstrm_t * ps_bitstrm,subset_sps_t * ps_subset_sps)2011*495ae853SAndroid Build Coastguard Worker WORD32 isvce_generate_subset_sps(bitstrm_t *ps_bitstrm, subset_sps_t *ps_subset_sps)
2012*495ae853SAndroid Build Coastguard Worker {
2013*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
2014*495ae853SAndroid Build Coastguard Worker     sps_t *ps_sps = &ps_subset_sps->s_sps;
2015*495ae853SAndroid Build Coastguard Worker     return_status = isvce_generate_sps(ps_bitstrm, &ps_subset_sps->s_sps, NAL_SUBSET_SPS);
2016*495ae853SAndroid Build Coastguard Worker 
2017*495ae853SAndroid Build Coastguard Worker     /* generate subset sps */
2018*495ae853SAndroid Build Coastguard Worker     if(ps_sps->u1_profile_idc == IH264_SCALABLE_BASELINE ||
2019*495ae853SAndroid Build Coastguard Worker        ps_sps->u1_profile_idc == IH264_SCALABLE_HIGH_PROFILE)
2020*495ae853SAndroid Build Coastguard Worker     {
2021*495ae853SAndroid Build Coastguard Worker         isvce_seq_parameter_set_svc_extension(ps_bitstrm, ps_subset_sps,
2022*495ae853SAndroid Build Coastguard Worker                                               ps_sps->u1_chroma_format_idc);
2023*495ae853SAndroid Build Coastguard Worker 
2024*495ae853SAndroid Build Coastguard Worker         /* svc_vui_parameters_present_flag */
2025*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_subset_sps->i1_svc_vui_parameters_present_flag, 1, return_status,
2026*495ae853SAndroid Build Coastguard Worker                  "SPS: svc_vui_parameters_present_flag");
2027*495ae853SAndroid Build Coastguard Worker 
2028*495ae853SAndroid Build Coastguard Worker         if(ps_subset_sps->i1_svc_vui_parameters_present_flag == 1)
2029*495ae853SAndroid Build Coastguard Worker         {
2030*495ae853SAndroid Build Coastguard Worker             svc_vui_ext_t *ps_svc_vui = NULL;
2031*495ae853SAndroid Build Coastguard Worker             isvce_svc_vui_parameters_extension(ps_bitstrm, ps_svc_vui);
2032*495ae853SAndroid Build Coastguard Worker         }
2033*495ae853SAndroid Build Coastguard Worker 
2034*495ae853SAndroid Build Coastguard Worker         /* additional_extension2_flag */
2035*495ae853SAndroid Build Coastguard Worker         PUT_BITS(ps_bitstrm, ps_subset_sps->i1_additional_extension2_flag, 1, return_status,
2036*495ae853SAndroid Build Coastguard Worker                  "SPS: additional_extension2_flag");
2037*495ae853SAndroid Build Coastguard Worker     }
2038*495ae853SAndroid Build Coastguard Worker 
2039*495ae853SAndroid Build Coastguard Worker     /* rbsp trailing bits */
2040*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_rbsp_trailing_bits(ps_bitstrm);
2041*495ae853SAndroid Build Coastguard Worker 
2042*495ae853SAndroid Build Coastguard Worker     return return_status;
2043*495ae853SAndroid Build Coastguard Worker }
2044*495ae853SAndroid Build Coastguard Worker /**
2045*495ae853SAndroid Build Coastguard Worker ******************************************************************************
2046*495ae853SAndroid Build Coastguard Worker *
2047*495ae853SAndroid Build Coastguard Worker * @brief Generates svc_nalu_ext
2048*495ae853SAndroid Build Coastguard Worker *
2049*495ae853SAndroid Build Coastguard Worker * @par   Description
2050*495ae853SAndroid Build Coastguard Worker *  Generate svc_nalu_ext as per Section G.7.3.1.1
2051*495ae853SAndroid Build Coastguard Worker *
2052*495ae853SAndroid Build Coastguard Worker * @param[inout]   ps_bitstrm
2053*495ae853SAndroid Build Coastguard Worker *  pointer to bitstream context for generating slice header
2054*495ae853SAndroid Build Coastguard Worker *
2055*495ae853SAndroid Build Coastguard Worker * @param[in]   ps_svc_nalu_ext
2056*495ae853SAndroid Build Coastguard Worker *  pointer to svc_nalu_ext struct
2057*495ae853SAndroid Build Coastguard Worker *
2058*495ae853SAndroid Build Coastguard Worker * @return    success or failure error code
2059*495ae853SAndroid Build Coastguard Worker *
2060*495ae853SAndroid Build Coastguard Worker ******************************************************************************
2061*495ae853SAndroid Build Coastguard Worker */
isvce_generate_svc_nalu_extension(bitstrm_t * ps_bitstrm,svc_nalu_ext_t * ps_svc_nalu_ext,UWORD8 u1_nalu_id)2062*495ae853SAndroid Build Coastguard Worker WORD32 isvce_generate_svc_nalu_extension(bitstrm_t *ps_bitstrm, svc_nalu_ext_t *ps_svc_nalu_ext,
2063*495ae853SAndroid Build Coastguard Worker                                          UWORD8 u1_nalu_id)
2064*495ae853SAndroid Build Coastguard Worker {
2065*495ae853SAndroid Build Coastguard Worker     WORD32 return_status = IH264E_SUCCESS;
2066*495ae853SAndroid Build Coastguard Worker 
2067*495ae853SAndroid Build Coastguard Worker     /* Insert start code */
2068*495ae853SAndroid Build Coastguard Worker     return_status = ih264e_put_nal_start_code_prefix(ps_bitstrm, 1);
2069*495ae853SAndroid Build Coastguard Worker 
2070*495ae853SAndroid Build Coastguard Worker     if(return_status != IH264E_SUCCESS)
2071*495ae853SAndroid Build Coastguard Worker     {
2072*495ae853SAndroid Build Coastguard Worker         return return_status;
2073*495ae853SAndroid Build Coastguard Worker     }
2074*495ae853SAndroid Build Coastguard Worker 
2075*495ae853SAndroid Build Coastguard Worker     /* Insert Nal Unit Header */
2076*495ae853SAndroid Build Coastguard Worker     return_status = isvce_generate_nal_unit_header(ps_bitstrm, u1_nalu_id, 3);
2077*495ae853SAndroid Build Coastguard Worker 
2078*495ae853SAndroid Build Coastguard Worker     if(return_status != IH264E_SUCCESS)
2079*495ae853SAndroid Build Coastguard Worker     {
2080*495ae853SAndroid Build Coastguard Worker         return return_status;
2081*495ae853SAndroid Build Coastguard Worker     }
2082*495ae853SAndroid Build Coastguard Worker 
2083*495ae853SAndroid Build Coastguard Worker     /* reserved_one_bit */
2084*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, 1, 1, return_status, "NAL unit header: reserved_one_bit");
2085*495ae853SAndroid Build Coastguard Worker 
2086*495ae853SAndroid Build Coastguard Worker     /* idr_flag */
2087*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_svc_nalu_ext->u1_idr_flag, 1, return_status,
2088*495ae853SAndroid Build Coastguard Worker              "NAL unit header: idr_flag");
2089*495ae853SAndroid Build Coastguard Worker 
2090*495ae853SAndroid Build Coastguard Worker     /* priority_id */
2091*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_svc_nalu_ext->u1_priority_id, 6, return_status,
2092*495ae853SAndroid Build Coastguard Worker              "NAL unit header: priority_id");
2093*495ae853SAndroid Build Coastguard Worker 
2094*495ae853SAndroid Build Coastguard Worker     /* no_inter_layer_pred_flag */
2095*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_svc_nalu_ext->u1_no_inter_layer_pred_flag, 1, return_status,
2096*495ae853SAndroid Build Coastguard Worker              "NAL unit header: no_inter_layer_pred_flag");
2097*495ae853SAndroid Build Coastguard Worker 
2098*495ae853SAndroid Build Coastguard Worker     /* dependency_id */
2099*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_svc_nalu_ext->u1_dependency_id, 3, return_status,
2100*495ae853SAndroid Build Coastguard Worker              "NAL unit header: dependency_id");
2101*495ae853SAndroid Build Coastguard Worker 
2102*495ae853SAndroid Build Coastguard Worker     /* quality_id */
2103*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_svc_nalu_ext->u1_quality_id, 4, return_status,
2104*495ae853SAndroid Build Coastguard Worker              "NAL unit header: quality_id");
2105*495ae853SAndroid Build Coastguard Worker 
2106*495ae853SAndroid Build Coastguard Worker     /* temporal_id */
2107*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_svc_nalu_ext->u1_temporal_id, 3, return_status,
2108*495ae853SAndroid Build Coastguard Worker              "NAL unit header: temporal_id");
2109*495ae853SAndroid Build Coastguard Worker 
2110*495ae853SAndroid Build Coastguard Worker     /* use_ref_base_pic_flag */
2111*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_svc_nalu_ext->u1_use_ref_base_pic_flag, 1, return_status,
2112*495ae853SAndroid Build Coastguard Worker              "NAL unit header: use_ref_base_pic_flag");
2113*495ae853SAndroid Build Coastguard Worker 
2114*495ae853SAndroid Build Coastguard Worker     /* discardable_flag */
2115*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_svc_nalu_ext->u1_discardable_flag, 1, return_status,
2116*495ae853SAndroid Build Coastguard Worker              "NAL unit header: discardable_flag");
2117*495ae853SAndroid Build Coastguard Worker 
2118*495ae853SAndroid Build Coastguard Worker     /* output_flag */
2119*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_svc_nalu_ext->u1_output_flag, 1, return_status,
2120*495ae853SAndroid Build Coastguard Worker              "NAL unit header: output_flag");
2121*495ae853SAndroid Build Coastguard Worker 
2122*495ae853SAndroid Build Coastguard Worker     /* reserved_three_2bits */
2123*495ae853SAndroid Build Coastguard Worker     PUT_BITS(ps_bitstrm, ps_svc_nalu_ext->u1_reserved_three_2bits, 2, return_status,
2124*495ae853SAndroid Build Coastguard Worker              "NAL unit header: reserved_three_2bits");
2125*495ae853SAndroid Build Coastguard Worker 
2126*495ae853SAndroid Build Coastguard Worker     return return_status;
2127*495ae853SAndroid Build Coastguard Worker }
2128