Lines Matching refs:bs

41 static void bitstream_start(bitstream *bs)  in bitstream_start()  argument
43 bs->max_size_in_dword = BITSTREAM_ALLOCATE_STEPPING; in bitstream_start()
44 bs->buffer = (unsigned int*)calloc(bs->max_size_in_dword * sizeof(int), 1); in bitstream_start()
45 bs->bit_offset = 0; in bitstream_start()
48 static void bitstream_end(bitstream *bs) in bitstream_end() argument
50 int pos = (bs->bit_offset >> 5); in bitstream_end()
51 int bit_offset = (bs->bit_offset & 0x1f); in bitstream_end()
55 bs->buffer[pos] = va_swap32((bs->buffer[pos] << bit_left)); in bitstream_end()
59 static void bitstream_put_ui(bitstream *bs, unsigned int val, int size_in_bits) in bitstream_put_ui() argument
61 int pos = (bs->bit_offset >> 5); in bitstream_put_ui()
62 int bit_offset = (bs->bit_offset & 0x1f); in bitstream_put_ui()
68 bs->bit_offset += size_in_bits; in bitstream_put_ui()
71 bs->buffer[pos] = (bs->buffer[pos] << size_in_bits | val); in bitstream_put_ui()
74 bs->buffer[pos] = (bs->buffer[pos] << bit_left) | (val >> size_in_bits); in bitstream_put_ui()
75 bs->buffer[pos] = va_swap32(bs->buffer[pos]); in bitstream_put_ui()
77 if (pos + 1 == bs->max_size_in_dword) { in bitstream_put_ui()
78 bs->max_size_in_dword += BITSTREAM_ALLOCATE_STEPPING; in bitstream_put_ui()
79bs->buffer = (unsigned int*)realloc(bs->buffer, bs->max_size_in_dword * sizeof(unsigned int)); in bitstream_put_ui()
80 if (bs->buffer == NULL) in bitstream_put_ui()
84 bs->buffer[pos + 1] = val; in bitstream_put_ui()
88 static void bitstream_put_ue(bitstream *bs, unsigned int val) in bitstream_put_ue() argument
98 bitstream_put_ui(bs, 0, size_in_bits - 1); // leading zero in bitstream_put_ue()
99 bitstream_put_ui(bs, val, size_in_bits); in bitstream_put_ue()
102 static void bitstream_put_se(bitstream *bs, int val) in bitstream_put_se() argument
111 bitstream_put_ue(bs, new_val); in bitstream_put_se()
114 static void bitstream_byte_aligning(bitstream *bs, int bit) in bitstream_byte_aligning() argument
116 int bit_offset = (bs->bit_offset & 0x7); in bitstream_byte_aligning()
130 bitstream_put_ui(bs, new_val, bit_left); in bitstream_byte_aligning()
133 static void rbsp_trailing_bits(bitstream *bs) in rbsp_trailing_bits() argument
135 bitstream_put_ui(bs, 1, 1); in rbsp_trailing_bits()
136 bitstream_byte_aligning(bs, 0); in rbsp_trailing_bits()
139 static void nal_start_code_prefix(bitstream *bs) in nal_start_code_prefix() argument
141 bitstream_put_ui(bs, 0x00000001, 32); in nal_start_code_prefix()
144 static void nal_header(bitstream *bs, int nal_ref_idc, int nal_unit_type) in nal_header() argument
146 bitstream_put_ui(bs, 0, 1); /* forbidden_zero_bit: 0 */ in nal_header()
147 bitstream_put_ui(bs, nal_ref_idc, 2); in nal_header()
148 bitstream_put_ui(bs, nal_unit_type, 5); in nal_header()
173 static void sps_rbsp(bitstream *bs, VAProfile profile, int frame_bit_rate, VAEncSequenceParameterBu… in sps_rbsp() argument
190 bitstream_put_ui(bs, profile_idc, 8); /* profile_idc */ in sps_rbsp()
191 …bitstream_put_ui(bs, !!(constraint_set_flag & 1), 1); /* constraint_set0_f… in sps_rbsp()
192 …bitstream_put_ui(bs, !!(constraint_set_flag & 2), 1); /* constraint_set1_f… in sps_rbsp()
193 …bitstream_put_ui(bs, !!(constraint_set_flag & 4), 1); /* constraint_set2_f… in sps_rbsp()
194 …bitstream_put_ui(bs, !!(constraint_set_flag & 8), 1); /* constraint_set3_f… in sps_rbsp()
195 bitstream_put_ui(bs, 0, 4); /* reserved_zero_4bits */ in sps_rbsp()
196 bitstream_put_ui(bs, seq_param->level_idc, 8); /* level_idc */ in sps_rbsp()
197 bitstream_put_ue(bs, seq_param->seq_parameter_set_id); /* seq_parameter_set_id */ in sps_rbsp()
200 bitstream_put_ue(bs, 1); /* chroma_format_idc = 1, 4:2:0 */ in sps_rbsp()
201 bitstream_put_ue(bs, 0); /* bit_depth_luma_minus8 */ in sps_rbsp()
202 bitstream_put_ue(bs, 0); /* bit_depth_chroma_minus8 */ in sps_rbsp()
203 bitstream_put_ui(bs, 0, 1); /* qpprime_y_zero_transform_bypass_flag */ in sps_rbsp()
204 bitstream_put_ui(bs, 0, 1); /* seq_scaling_matrix_present_flag */ in sps_rbsp()
207 …bitstream_put_ue(bs, seq_param->seq_fields.bits.log2_max_frame_num_minus4); /* log2_max_frame_num_… in sps_rbsp()
208 …bitstream_put_ue(bs, seq_param->seq_fields.bits.pic_order_cnt_type); /* pic_order_cnt_type … in sps_rbsp()
211 …bitstream_put_ue(bs, seq_param->seq_fields.bits.log2_max_pic_order_cnt_lsb_minus4); /* log2_ma… in sps_rbsp()
216 bitstream_put_ue(bs, seq_param->max_num_ref_frames); /* num_ref_frames */ in sps_rbsp()
217 …bitstream_put_ui(bs, 0, 1); /* gaps_in_frame_num_value_allowed_fla… in sps_rbsp()
219 bitstream_put_ue(bs, seq_param->picture_width_in_mbs - 1); /* pic_width_in_mbs_minus1 */ in sps_rbsp()
220 bitstream_put_ue(bs, seq_param->picture_height_in_mbs - 1); /* pic_height_in_map_units_minus1 */ in sps_rbsp()
221 …bitstream_put_ui(bs, seq_param->seq_fields.bits.frame_mbs_only_flag, 1); /* frame_mbs_only_flag… in sps_rbsp()
227 …bitstream_put_ui(bs, seq_param->seq_fields.bits.direct_8x8_inference_flag, 1); /* direct_8x8_… in sps_rbsp()
228 bitstream_put_ui(bs, seq_param->frame_cropping_flag, 1); /* frame_cropping_flag */ in sps_rbsp()
231 bitstream_put_ue(bs, seq_param->frame_crop_left_offset); /* frame_crop_left_offset */ in sps_rbsp()
232 … bitstream_put_ue(bs, seq_param->frame_crop_right_offset); /* frame_crop_right_offset */ in sps_rbsp()
233 bitstream_put_ue(bs, seq_param->frame_crop_top_offset); /* frame_crop_top_offset */ in sps_rbsp()
234 … bitstream_put_ue(bs, seq_param->frame_crop_bottom_offset); /* frame_crop_bottom_offset */ in sps_rbsp()
238 bitstream_put_ui(bs, 0, 1); /* vui_parameters_present_flag */ in sps_rbsp()
240 bitstream_put_ui(bs, 1, 1); /* vui_parameters_present_flag */ in sps_rbsp()
241 bitstream_put_ui(bs, 0, 1); /* aspect_ratio_info_present_flag */ in sps_rbsp()
242 bitstream_put_ui(bs, 0, 1); /* overscan_info_present_flag */ in sps_rbsp()
243 bitstream_put_ui(bs, 0, 1); /* video_signal_type_present_flag */ in sps_rbsp()
244 bitstream_put_ui(bs, 0, 1); /* chroma_loc_info_present_flag */ in sps_rbsp()
245 bitstream_put_ui(bs, 1, 1); /* timing_info_present_flag */ in sps_rbsp()
247 bitstream_put_ui(bs, 15, 32); in sps_rbsp()
248 bitstream_put_ui(bs, 900, 32); in sps_rbsp()
249 bitstream_put_ui(bs, 1, 1); in sps_rbsp()
251 bitstream_put_ui(bs, 1, 1); /* nal_hrd_parameters_present_flag */ in sps_rbsp()
254 bitstream_put_ue(bs, 0); /* cpb_cnt_minus1 */ in sps_rbsp()
255 bitstream_put_ui(bs, 4, 4); /* bit_rate_scale */ in sps_rbsp()
256 bitstream_put_ui(bs, 6, 4); /* cpb_size_scale */ in sps_rbsp()
258 bitstream_put_ue(bs, frame_bit_rate - 1); /* bit_rate_value_minus1[0] */ in sps_rbsp()
259 bitstream_put_ue(bs, frame_bit_rate*8 - 1); /* cpb_size_value_minus1[0] */ in sps_rbsp()
260 bitstream_put_ui(bs, 1, 1); /* cbr_flag[0] */ in sps_rbsp()
262 bitstream_put_ui(bs, 23, 5); /* initial_cpb_removal_delay_length_minus1 */ in sps_rbsp()
263 bitstream_put_ui(bs, 23, 5); /* cpb_removal_delay_length_minus1 */ in sps_rbsp()
264 bitstream_put_ui(bs, 23, 5); /* dpb_output_delay_length_minus1 */ in sps_rbsp()
265 bitstream_put_ui(bs, 23, 5); /* time_offset_length */ in sps_rbsp()
267 bitstream_put_ui(bs, 0, 1); /* vcl_hrd_parameters_present_flag */ in sps_rbsp()
268 bitstream_put_ui(bs, 0, 1); /* low_delay_hrd_flag */ in sps_rbsp()
270 bitstream_put_ui(bs, 0, 1); /* pic_struct_present_flag */ in sps_rbsp()
271 bitstream_put_ui(bs, 0, 1); /* bitstream_restriction_flag */ in sps_rbsp()
274 rbsp_trailing_bits(bs); /* rbsp_trailing_bits */ in sps_rbsp()
277 static void pps_rbsp(bitstream *bs, VAEncPictureParameterBufferH264 *pic_param) in pps_rbsp() argument
280 bitstream_put_ue(bs, pic_param->pic_parameter_set_id); /* pic_parameter_set_id */ in pps_rbsp()
281 bitstream_put_ue(bs, pic_param->seq_parameter_set_id); /* seq_parameter_set_id */ in pps_rbsp()
283 …bitstream_put_ui(bs, pic_param->pic_fields.bits.entropy_coding_mode_flag, 1); /* entropy_coding_m… in pps_rbsp()
285 bitstream_put_ui(bs, 0, 1); /* pic_order_present_flag: 0 */ in pps_rbsp()
287 bitstream_put_ue(bs, 0); /* num_slice_groups_minus1 */ in pps_rbsp()
289 …bitstream_put_ue(bs, pic_param->num_ref_idx_l0_active_minus1); /* num_ref_idx_l0_active_minus… in pps_rbsp()
290 …bitstream_put_ue(bs, pic_param->num_ref_idx_l1_active_minus1); /* num_ref_idx_l1_active_minus… in pps_rbsp()
292 …bitstream_put_ui(bs, pic_param->pic_fields.bits.weighted_pred_flag, 1); /* weighted_pred_flag:… in pps_rbsp()
293 …bitstream_put_ui(bs, pic_param->pic_fields.bits.weighted_bipred_idc, 2); /* weighted_bipred_idc: 0… in pps_rbsp()
295 bitstream_put_se(bs, pic_param->pic_init_qp - 26); /* pic_init_qp_minus26 */ in pps_rbsp()
296 bitstream_put_se(bs, 0); /* pic_init_qs_minus26 */ in pps_rbsp()
297 bitstream_put_se(bs, 0); /* chroma_qp_index_offset */ in pps_rbsp()
299 …bitstream_put_ui(bs, pic_param->pic_fields.bits.deblocking_filter_control_present_flag, 1); /* deb… in pps_rbsp()
300 bitstream_put_ui(bs, 0, 1); /* constrained_intra_pred_flag */ in pps_rbsp()
301 bitstream_put_ui(bs, 0, 1); /* redundant_pic_cnt_present_flag */ in pps_rbsp()
304 …bitstream_put_ui(bs, pic_param->pic_fields.bits.transform_8x8_mode_flag, 1); /*transform_8x8_mo… in pps_rbsp()
305 bitstream_put_ui(bs, 0, 1); /* pic_scaling_matrix_present_flag */ in pps_rbsp()
306 …bitstream_put_se(bs, pic_param->second_chroma_qp_index_offset ); /*second_chroma_qp_index_offse… in pps_rbsp()
308 rbsp_trailing_bits(bs); in pps_rbsp()
313 bitstream bs; in build_packed_seq_buffer() local
315 bitstream_start(&bs); in build_packed_seq_buffer()
316 nal_start_code_prefix(&bs); in build_packed_seq_buffer()
317 nal_header(&bs, NAL_REF_IDC_HIGH, NAL_SPS); in build_packed_seq_buffer()
318 sps_rbsp(&bs, profile, seq_param->bits_per_second, seq_param); in build_packed_seq_buffer()
319 bitstream_end(&bs); in build_packed_seq_buffer()
321 *header_buffer = (unsigned char *)bs.buffer; in build_packed_seq_buffer()
322 return bs.bit_offset; in build_packed_seq_buffer()
327 bitstream bs; in build_packed_pic_buffer() local
329 bitstream_start(&bs); in build_packed_pic_buffer()
330 nal_start_code_prefix(&bs); in build_packed_pic_buffer()
331 nal_header(&bs, NAL_REF_IDC_HIGH, NAL_PPS); in build_packed_pic_buffer()
332 pps_rbsp(&bs, pic_param); in build_packed_pic_buffer()
333 bitstream_end(&bs); in build_packed_pic_buffer()
335 *header_buffer = (unsigned char *)bs.buffer; in build_packed_pic_buffer()
336 return bs.bit_offset; in build_packed_pic_buffer()