93static uint32_t parse_me(uint32_t ChromaArrayType, uint32_t pred_mode,
const uint8_t *data,
size_t &bit)
95 uint32_t codeNum = parse_ue(data, bit);
97 if(ChromaArrayType == 1 || ChromaArrayType == 2){
98 if(pred_mode == Intra_4x4 || pred_mode == Intra_8x8){
99 uint8_t a[] = {47, 31, 15, 0, 23, 27, 29, 30, 7, 11, 13, 14, 39, 43, 45, 46, 16, 3, 5, 10, 12, 19, 21, 26, 28, 35, 37, 42, 44, 1, 2, 4, 8, 17, 18, 20, 24, 6, 9, 22, 25, 32, 33, 34, 36, 40, 38, 41};
103 assert(pred_mode != Intra_4x4 && pred_mode != Intra_8x8 && pred_mode != Intra_16x16);
104 uint8_t b[] = {0, 16, 1, 2, 4, 8, 32, 3, 5, 10, 12, 15, 47, 7, 11, 13, 14, 6, 9, 31, 35, 37, 42, 44, 33, 34, 36, 40, 39, 43, 45, 46, 17, 18, 20, 24, 19, 21, 26, 28, 23, 27, 29, 30, 22, 25, 38, 41};
108 else if(ChromaArrayType == 0 || ChromaArrayType == 3){
109 if(pred_mode == Intra_4x4 || pred_mode == Intra_8x8){
110 uint8_t a[] = {15, 0, 7, 11, 13, 14, 3, 5, 10, 12, 1, 2, 4, 8, 6, 9};
114 assert(pred_mode != Intra_4x4 && pred_mode != Intra_8x8 && pred_mode != Intra_16x16);
115 uint8_t b[] = {0, 1, 2, 4, 8, 3, 5, 10, 12, 15, 7, 11, 13, 14, 6, 9};
143 uint32_t PicWidthInMbs = seq_set.pic_width_in_mbs_minus1 + 1;
144 uint32_t PicHeightInMapUnits = seq_set.pic_height_in_map_units_minus1 + 1;
145 uint32_t FrameHeightInMbs = ( 2 - seq_set.frame_mbs_only_flag ) * PicHeightInMapUnits;
146 uint32_t PicHeightInMbs = FrameHeightInMbs / ( 1 + layer.field_pic_flag );
147 uint32_t PicSizeInMbs = PicWidthInMbs * PicHeightInMbs;
148 uint32_t PicSizeInMapUnits = PicWidthInMbs * PicHeightInMapUnits;
150 uint32_t MbaffFrameFlag = (seq_set.mb_adaptive_frame_field_flag && !layer.field_pic_flag);
152 uint32_t *mapUnitToSliceGroupMap =
new uint32_t[PicSizeInMbs];
153 if(pic_set.slice_group_map_type == 0){
156 for(uint32_t iGroup=0; iGroup<=pic_set.num_slice_groups_minus1 && i<PicSizeInMapUnits; i += pic_set.run_length_minus1[iGroup++]+1){
157 for(uint32_t j=0; j<=pic_set.run_length_minus1[iGroup] && i+j<PicSizeInMapUnits; j++){
158 mapUnitToSliceGroupMap[i+j] = iGroup;
161 }
while( i < PicSizeInMapUnits );
167 uint32_t *MbToSliceGroupMap =
new uint32_t[PicSizeInMbs];
169 for(uint32_t i=0; i<PicSizeInMbs-1; i++){
170 if(seq_set.frame_mbs_only_flag == 1 || layer.field_pic_flag == 1)
171 MbToSliceGroupMap[i] = mapUnitToSliceGroupMap[i];
172 else if(MbaffFrameFlag == 1)
173 MbToSliceGroupMap[i] = mapUnitToSliceGroupMap[i/2];
175 MbToSliceGroupMap[i] = mapUnitToSliceGroupMap[(i/(2*PicWidthInMbs)) * PicWidthInMbs + (i%PicWidthInMbs)];
178 uint32_t n = CurrMbAddr;
180 while(i < PicSizeInMbs && MbToSliceGroupMap[i] != MbToSliceGroupMap[n]) i++;
181 delete [] mapUnitToSliceGroupMap;
182 delete [] MbToSliceGroupMap;
186static uint32_t CodedBlockPatternLumaTab(uint32_t coded_block_pattern, uint32_t slice_type, uint32_t mb_type)
188 if(slice_type == 2 || slice_type == 7){
189 if(mb_type == I_NxN)
return coded_block_pattern % 16;
190 if(mb_type >= I_16x16_0_0_0 && mb_type <= I_16x16_3_2_0)
return 0;
191 if(mb_type >= I_16x16_0_0_1 && mb_type <= I_16x16_3_2_1)
return 15;
193 else if(slice_type == 4 || slice_type == 9){
194 if(mb_type == SI)
return coded_block_pattern % 16;
196 if(mb_type == I_NxN)
return coded_block_pattern % 16;
197 if(mb_type >= I_16x16_0_0_0 && mb_type <= I_16x16_3_2_0)
return 0;
198 if(mb_type >= I_16x16_0_0_1 && mb_type <= I_16x16_3_2_1)
return 15;
200 else if(slice_type == 0 || slice_type == 5){
201 assert(mb_type >= 5);
203 if(mb_type == I_NxN)
return coded_block_pattern % 16;
204 if(mb_type >= I_16x16_0_0_0 && mb_type <= I_16x16_3_2_0)
return 0;
205 if(mb_type >= I_16x16_0_0_1 && mb_type <= I_16x16_3_2_1)
return 15;
207 else if(slice_type == 1 || slice_type == 6){
208 assert(mb_type >= 23);
209 mb_type = mb_type-23;
210 if(mb_type == I_NxN)
return coded_block_pattern % 16;
211 if(mb_type >= I_16x16_0_0_0 && mb_type <= I_16x16_3_2_0)
return 0;
212 if(mb_type >= I_16x16_0_0_1 && mb_type <= I_16x16_3_2_1)
return 15;
217static uint32_t CodedBlockPatternChromaTab(uint32_t coded_block_pattern, uint32_t slice_type, uint32_t mb_type)
219 if(slice_type == 2 || slice_type == 7){
220 if(mb_type == I_NxN)
return coded_block_pattern / 16;
221 if(mb_type >= I_16x16_0_0_0 && mb_type <= I_16x16_3_0_0)
return 0;
222 if(mb_type >= I_16x16_0_1_0 && mb_type <= I_16x16_3_1_0)
return 1;
223 if(mb_type >= I_16x16_0_2_0 && mb_type <= I_16x16_3_2_0)
return 2;
224 if(mb_type >= I_16x16_0_0_1 && mb_type <= I_16x16_3_0_1)
return 0;
225 if(mb_type >= I_16x16_0_1_1 && mb_type <= I_16x16_3_1_1)
return 1;
226 if(mb_type >= I_16x16_0_2_1 && mb_type <= I_16x16_3_2_1)
return 2;
228 else if(slice_type == 4 || slice_type == 9){
229 if(mb_type == SI)
return coded_block_pattern / 16;
231 if(mb_type == I_NxN)
return coded_block_pattern / 16;
232 if(mb_type >= I_16x16_0_0_0 && mb_type <= I_16x16_3_0_0)
return 0;
233 if(mb_type >= I_16x16_0_1_0 && mb_type <= I_16x16_3_1_0)
return 1;
234 if(mb_type >= I_16x16_0_2_0 && mb_type <= I_16x16_3_2_0)
return 2;
235 if(mb_type >= I_16x16_0_0_1 && mb_type <= I_16x16_3_0_1)
return 0;
236 if(mb_type >= I_16x16_0_1_1 && mb_type <= I_16x16_3_1_1)
return 1;
237 if(mb_type >= I_16x16_0_2_1 && mb_type <= I_16x16_3_2_1)
return 2;
239 else if(slice_type == 0 || slice_type == 5){
240 assert(mb_type >= 5);
242 if(mb_type == I_NxN)
return coded_block_pattern / 16;
243 if(mb_type >= I_16x16_0_0_0 && mb_type <= I_16x16_3_0_0)
return 0;
244 if(mb_type >= I_16x16_0_1_0 && mb_type <= I_16x16_3_1_0)
return 1;
245 if(mb_type >= I_16x16_0_2_0 && mb_type <= I_16x16_3_2_0)
return 2;
246 if(mb_type >= I_16x16_0_0_1 && mb_type <= I_16x16_3_0_1)
return 0;
247 if(mb_type >= I_16x16_0_1_1 && mb_type <= I_16x16_3_1_1)
return 1;
248 if(mb_type >= I_16x16_0_2_1 && mb_type <= I_16x16_3_2_1)
return 2;
250 else if(slice_type == 1 || slice_type == 6){
251 assert(mb_type >= 23);
252 mb_type = mb_type-23;
253 if(mb_type == I_NxN)
return coded_block_pattern / 16;
254 if(mb_type >= I_16x16_0_0_0 && mb_type <= I_16x16_3_0_0)
return 0;
255 if(mb_type >= I_16x16_0_1_0 && mb_type <= I_16x16_3_1_0)
return 1;
256 if(mb_type >= I_16x16_0_2_0 && mb_type <= I_16x16_3_2_0)
return 2;
257 if(mb_type >= I_16x16_0_0_1 && mb_type <= I_16x16_3_0_1)
return 0;
258 if(mb_type >= I_16x16_0_1_1 && mb_type <= I_16x16_3_1_1)
return 1;
259 if(mb_type >= I_16x16_0_2_1 && mb_type <= I_16x16_3_2_1)
return 2;
265static uint32_t MbPartPredMode(uint32_t slice_type, uint32_t transform_size_8x8_flag, uint32_t mb_type, uint32_t n)
267 if(slice_type == 2 || slice_type == 7){
268 if(mb_type == I_NxN && transform_size_8x8_flag == 0)
return Intra_4x4;
269 if(mb_type == I_NxN && transform_size_8x8_flag == 1)
return Intra_8x8;
270 if(mb_type >= I_16x16_0_0_0 && mb_type <= I_16x16_3_2_1)
return Intra_16x16;
272 else if(slice_type == 4 || slice_type == 9){
273 if(mb_type == SI)
return Intra_4x4;
275 if(mb_type == I_NxN && transform_size_8x8_flag == 0)
return Intra_4x4;
276 if(mb_type == I_NxN && transform_size_8x8_flag == 1)
return Intra_8x8;
277 if(mb_type >= I_16x16_0_0_0 && mb_type <= I_16x16_3_2_1)
return Intra_16x16;
279 else if(slice_type == 0 || slice_type == 5){
281 if(mb_type == P_L0_16x16)
return Pred_L0;
282 if(mb_type == P_L0_L0_16x8)
return Pred_L0;
283 if(mb_type == P_L0_L0_8x16)
return Pred_L0;
285 if(mb_type == I_NxN && transform_size_8x8_flag == 0)
return Intra_4x4;
286 if(mb_type == I_NxN && transform_size_8x8_flag == 1)
return Intra_8x8;
287 if(mb_type >= I_16x16_0_0_0 && mb_type <= I_16x16_3_2_1)
return Intra_16x16;
289 else if(slice_type == 1 || slice_type == 6){
291 if(mb_type == B_Direct_16x16)
return Direct;
292 if(mb_type == B_L0_16x16)
return Pred_L0;
293 if(mb_type == B_L1_16x16)
return Pred_L1;
294 if(mb_type == B_Bi_16x16)
return BiPred;
295 if(mb_type == B_l0_L0_16x8)
return Pred_L0;
296 if(mb_type == B_l0_L0_8x16)
return Pred_L0;
297 if(mb_type == B_L1_L1_16x8)
return Pred_L1;
298 if(mb_type == B_L1_L1_8x16)
return Pred_L1;
299 if(mb_type == B_L0_L1_16x8)
return Pred_L0;
300 if(mb_type == B_L0_L1_8x16)
return Pred_L0;
301 if(mb_type == B_L1_L0_16x8)
return Pred_L1;
302 if(mb_type == B_L1_L0_8x16)
return Pred_L1;
303 if(mb_type == B_L0_Bi_16x8)
return Pred_L0;
304 if(mb_type == B_L0_Bi_8x16)
return Pred_L0;
305 if(mb_type == B_L1_Bi_16x8)
return Pred_L1;
306 if(mb_type == B_L1_Bi_8x16)
return Pred_L1;
307 if(mb_type == B_Bi_L0_16x8)
return BiPred;
308 if(mb_type == B_Bi_L0_8x16)
return BiPred;
309 if(mb_type == B_Bi_L1_16x8)
return BiPred;
310 if(mb_type == B_Bi_L1_8x16)
return BiPred;
311 if(mb_type == B_Bi_Bi_16x8)
return BiPred;
312 if(mb_type == B_Bi_Bi_8x16)
return BiPred;
316 if(mb_type == B_l0_L0_16x8)
return Pred_L0;
317 if(mb_type == B_l0_L0_8x16)
return Pred_L0;
318 if(mb_type == B_L1_L1_16x8)
return Pred_L1;
319 if(mb_type == B_L1_L1_8x16)
return Pred_L1;
320 if(mb_type == B_L0_L1_16x8)
return Pred_L1;
321 if(mb_type == B_L0_L1_8x16)
return Pred_L1;
322 if(mb_type == B_L1_L0_16x8)
return Pred_L0;
323 if(mb_type == B_L1_L0_8x16)
return Pred_L0;
324 if(mb_type == B_L0_Bi_16x8)
return BiPred;
325 if(mb_type == B_L0_Bi_8x16)
return BiPred;
326 if(mb_type == B_L1_Bi_16x8)
return BiPred;
327 if(mb_type == B_L1_Bi_8x16)
return BiPred;
328 if(mb_type == B_Bi_L0_16x8)
return Pred_L0;
329 if(mb_type == B_Bi_L0_8x16)
return Pred_L0;
330 if(mb_type == B_Bi_L1_16x8)
return Pred_L1;
331 if(mb_type == B_Bi_L1_8x16)
return Pred_L1;
332 if(mb_type == B_Bi_Bi_16x8)
return BiPred;
333 if(mb_type == B_Bi_Bi_8x16)
return BiPred;
335 mb_type = mb_type-23;
336 if(mb_type == I_NxN && transform_size_8x8_flag == 0)
return Intra_4x4;
337 if(mb_type == I_NxN && transform_size_8x8_flag == 1)
return Intra_8x8;
338 if(mb_type >= I_16x16_0_0_0 && mb_type <= I_16x16_3_2_1)
return Intra_16x16;
344static uint32_t NumMbPart(uint32_t )
351static void rbsp_trailing_bits(
const uint8_t *data,
size_t &bit)
353 uint32_t rbsp_stop_one_bit = parse_u(1, data, bit);
354 assert(rbsp_stop_one_bit == 0x1);
356 uint32_t rbsp_alignment_zero_bit = parse_u(1, data, bit);
357 assert(rbsp_alignment_zero_bit == 0x0);
361static void rbsp_slice_trailing_bits(
const uint8_t *data,
size_t &bit)
363 rbsp_trailing_bits(data, bit);
374static void residual_block(uint32_t *coeffLevel, uint32_t startIdx, uint32_t endIdx, uint32_t maxNumCoeff,
const uint8_t *data,
size_t &bit)
377 for(uint32_t i=0; i<maxNumCoeff; i++)
429 uint32_t TotalCoeff = 0;
430 assert(TotalCoeff <= maxNumCoeff);
431 uint32_t TrailingOnes = 0;
434 int32_t levelVal[16];
435 uint32_t suffixLength;
436 if(TotalCoeff > 10 && TrailingOnes<3)
440 for(uint32_t i=0; i<TotalCoeff; i++){
441 if(i < TrailingOnes){
442 uint32_t trailing_ones_sign_flag = parse_u(1, data, bit);
443 levelVal[i] = 1-2*trailing_ones_sign_flag;
446 int32_t level_prefix = 0;
449 int32_t levelCode = (std::min(15, level_prefix)<<suffixLength);
450 if(suffixLength > 0 || level_prefix >= 14){
451 uint32_t levelSuffixSize;
452 if(level_prefix == 14 && suffixLength == 0)
454 else if(level_prefix >= 15)
455 levelSuffixSize = level_prefix - 3;
457 levelSuffixSize = suffixLength;
458 uint32_t level_suffix;
460 level_suffix= parse_u(levelSuffixSize, data, bit);
463 levelCode += level_suffix;
465 if(level_prefix >= 15 && suffixLength == 0)
467 if(level_prefix >= 16)
468 levelCode += (1<<(level_prefix-3))-4096;
469 if(i == TrailingOnes && TrailingOnes < 3)
472 levelVal[i] = (levelCode +2)>>1;
474 levelVal[i] = (-levelCode-1)>>1;
475 if(suffixLength == 0)
477 if(std::abs(levelVal[i]) > (3<<(suffixLength-1)) && suffixLength < 6)
482 if(TotalCoeff<endIdx-startIdx+1){
483 uint32_t total_zeros = 0;
485 zerosLeft = total_zeros;
490 for(uint32_t i=0; i<TotalCoeff-1; i++){
492 uint32_t run_before = 0;
494 runVal[i] = run_before;
499 zerosLeft = zerosLeft - runVal[i];
501 runVal[TotalCoeff-1] = zerosLeft;
502 int32_t coeffNum = -1;
503 for(int32_t i=TotalCoeff-1; i>=0; i--){
504 coeffNum += runVal[i] + 1;
505 coeffLevel[startIdx + coeffNum] = levelVal[i];
512static void slice_layer_without_partitioning_rbsp(
H264ParseData &parse, uint8_t *data,
size_t,
bool IdrPicFlag)
514 const NALheader &nal_header(parse.nal_header);
522 layer.IdrPicFlag = IdrPicFlag;
525 layer.first_mb_in_slice = parse_ue(data, bit);
526 layer.slice_type = parse_ue(data, bit);
527 layer.pic_parameter_set_id = parse_ue(data, bit);
528 assert(layer.pic_parameter_set_id == 0);
530 if(seq_set.separate_colour_plane_flag == 1)
531 layer.colour_plane_id = parse_u(2, data, bit);
532 layer.frame_num = parse_u(seq_set.log2_max_frame_num_minus4+4, data, bit);
533 if(!seq_set.frame_mbs_only_flag){
534 layer.field_pic_flag = parse_u(1, data, bit);
535 if(layer.field_pic_flag)
536 layer.bottom_field_flag = parse_u(1, data, bit);
539 layer.idr_pic_id = parse_ue(data, bit);
540 if(seq_set.pic_order_cnt_type == 0){
541 layer.pic_order_cnt_lsb = parse_u(seq_set.log2_max_pic_order_cnt_lsb_minus4+4, data, bit);
542 if(pic_set.bottom_field_pic_order_in_frame_present_flag && !layer.field_pic_flag)
543 layer.delta_pic_order_cnt_bottom = parse_se(data, bit);
545 if(seq_set.pic_order_cnt_type == 1 && !seq_set.delta_pic_order_always_zero_flag){
546 layer.delta_pic_order_cnt[0] = parse_se(data, bit);
547 if(pic_set.bottom_field_pic_order_in_frame_present_flag && !layer.field_pic_flag)
548 layer.delta_pic_order_cnt[1] = parse_se(data, bit);
550 if(pic_set.redundant_pic_cnt_present_flag)
551 layer.redundant_pic_cnt = parse_ue(data, bit);
552 if(layer.slice_type == 1 || layer.slice_type == 6)
553 layer.direct_spatial_mv_pred_flag = parse_u(1, data, bit);
554 if(layer.slice_type == 0 || layer.slice_type == 3 || layer.slice_type == 1 ||
555 layer.slice_type == 5 || layer.slice_type == 8 || layer.slice_type == 6){
556 layer.num_ref_idx_active_override_flag = parse_u(1, data, bit);
557 if(layer.num_ref_idx_active_override_flag){
558 layer.num_ref_idx_l0_active_minus1 = parse_ue(data, bit);
559 if(layer.slice_type == 1 || layer.slice_type == 6)
560 layer.num_ref_idx_l1_active_minus1 = parse_ue(data, bit);
563 if(nal_header.nal_unit_type == 20 || nal_header.nal_unit_type == 21)
567 if(layer.slice_type%5 != 2 && layer.slice_type%5 != 4){
568 uint32_t ref_pic_list_modification_flagl0 = parse_u(1, data, bit);
569 if(ref_pic_list_modification_flagl0){
573 if(layer.slice_type%5 == 1){
574 uint32_t ref_pic_list_modification_flag_l1 = parse_u(1, data, bit);
575 if(ref_pic_list_modification_flag_l1){
580 if((pic_set.weighted_pred_flag && (layer.slice_type == 0 || layer.slice_type == 3 || layer.slice_type == 5 || layer.slice_type == 8)) ||
581 (pic_set.weighted_bipred_idc == 1 && (layer.slice_type == 1 || layer.slice_type == 6))){
583 layer.luma_log2_weight_denom = parse_ue(data, bit);
585 uint32_t ChromaArrayType;
586 if(seq_set.separate_colour_plane_flag == 0)
587 ChromaArrayType = seq_set.chroma_format_idc;
591 if(ChromaArrayType != 0)
592 layer.chroma_log2_weight_denom = parse_ue(data, bit);
593 for(uint32_t i=0; i<layer.num_ref_idx_l0_active_minus1; i++){
596 if(layer.slice_type%5 == 1){
600 if(nal_header.nal_ref_idc != 0){
602 if(layer.IdrPicFlag){
604 parse_u(1, data, bit);
606 parse_u(1, data, bit);
609 uint32_t adaptive_ref_pic_marking_mode_flag = parse_u(1, data, bit);
610 if(adaptive_ref_pic_marking_mode_flag){
615 if(pic_set.entropy_coding_mode_flag && !(layer.slice_type == 2 || layer.slice_type == 7) && !(layer.slice_type == 4 || layer.slice_type == 9))
616 layer.cabac_init_idc = parse_ue(data, bit);
617 layer.slice_qp_delta = parse_se(data, bit);
618 if(layer.slice_type == 3 || layer.slice_type == 4 ||
619 layer.slice_type == 8 || layer.slice_type == 9){
620 if(layer.slice_type == 3 || layer.slice_type == 8)
621 layer.sp_for_switch_flag = parse_u(1, data, bit);
622 layer.slice_qs_delta = parse_se(data, bit);
624 if(pic_set.deblocking_filter_control_present_flag){
625 layer.disable_deblocking_filter_idc = parse_ue(data, bit);
626 if(layer.disable_deblocking_filter_idc != 1){
627 layer.slice_alpha_c0_offset_div2 = parse_se(data, bit);
628 layer.slice_beta_offset_div2 = parse_se(data, bit);
631 if(pic_set.num_slice_groups_minus1 > 0 &&
632 pic_set.slice_group_map_type >= 3 && pic_set.slice_group_map_type <= 5){
873 param.cpb_cnt_minus1 = parse_ue(data, bit);
874 assert(param.cpb_cnt_minus1+1 < 32);
875 param.bit_rate_scale = parse_u(4, data, bit);
876 param.cpb_size_scale = parse_u(4, data, bit);
877 for(
size_t SchedSelIdx=0; SchedSelIdx<=param.cpb_cnt_minus1; SchedSelIdx++){
878 param.bit_rate_calue_minus1[SchedSelIdx] = parse_ue(data, bit);
879 param.cpb_size_value_minus1[SchedSelIdx] = parse_ue(data, bit);
880 param.cbr_flag[SchedSelIdx] = parse_u(1, data, bit);
882 param.initial_cpb_removal_delay_length_minus1 = parse_u(5, data, bit);
883 param.cpb_removal_delay_length_minus1 = parse_u(5, data, bit);
884 param.cpb_output_delay_length_minus1 = parse_u(5, data, bit);
885 param.time_offset_length = parse_u(5, data, bit);
888static void seq_parameter_set_rbsp(
H264ParseData &parse,
const uint8_t *data,
size_t size)
892 for(uint32_t i=0; i<size; i++){
893 if(i%8 == 0) printf(
"\n");
894 printf(
"0x%02x ", data[i]);
902 set.profile_idc = parse_u(8, data, bit);
903 set.constraint_set0_flag = parse_u(1, data, bit);
904 set.constraint_set1_flag = parse_u(1, data, bit);
905 set.constraint_set2_flag = parse_u(1, data, bit);
906 set.constraint_set3_flag = parse_u(1, data, bit);
907 set.constraint_set3_flag;
908 set.constraint_set4_flag = parse_u(1, data, bit);
909 set.constraint_set5_flag = parse_u(1, data, bit);
910 uint32_t reserved_zero_2bits = parse_u(2, data, bit);
911 assert(reserved_zero_2bits == 0);
912 set.level_idc = parse_u(8, data, bit);
914 set.seq_parameter_set_id = parse_ue(data, bit);
915 if(set.profile_idc == 100 || set.profile_idc == 110 ||
916 set.profile_idc == 122 || set.profile_idc == 244 || set.profile_idc == 44 ||
917 set.profile_idc == 83 || set.profile_idc == 86 || set.profile_idc == 118 ||
918 set.profile_idc == 128 || set.profile_idc == 138 || set.profile_idc == 139 ||
919 set.profile_idc == 134 || set.profile_idc == 135){
920 set.chroma_format_idc = parse_ue(data, bit);
921 if(set.chroma_format_idc == 3)
922 set.separate_colour_plane_flag = parse_u(1, data, bit);
923 set.bit_depth_luma_minus8 = parse_ue(data, bit);
924 set.bit_depth_chroma_minus8 = parse_ue(data, bit);
925 set.qpprime_y_zero_transform_bypass_flag = parse_u(1, data, bit);
926 set.seq_scaling_matrix_present_flag = parse_u(1, data, bit);
927 if(set.seq_scaling_matrix_present_flag){
942 set.chroma_format_idc = 1;
944 set.log2_max_frame_num_minus4 = parse_ue(data, bit);
945 set.pic_order_cnt_type = parse_ue(data, bit);
946 if(set.pic_order_cnt_type == 0)
947 set.log2_max_pic_order_cnt_lsb_minus4 = parse_ue(data, bit);
948 else if(set.pic_order_cnt_type == 1){
949 set.delta_pic_order_always_zero_flag = parse_u(1, data, bit);
950 set.offset_for_non_ref_pic = parse_se(data, bit);
951 set.offset_for_top_to_bottom_field = parse_se(data, bit);
952 set.num_ref_frames_in_pic_order_cnt_cycle = parse_ue(data, bit);
953 assert(set.num_ref_frames_in_pic_order_cnt_cycle <=
sizeof(set.offset_for_ref_frame)/
sizeof(set.offset_for_ref_frame[0]));
954 for(uint32_t i=0; i<set.num_ref_frames_in_pic_order_cnt_cycle; i++)
955 set.offset_for_ref_frame[i] = parse_se(data, bit);
957 set.num_ref_frames = parse_ue(data, bit);
958 set.gaps_in_frame_num_value_allowed_flag = parse_u(1, data, bit);
959 set.pic_width_in_mbs_minus1 = parse_ue(data, bit);
960 set.pic_height_in_map_units_minus1 = parse_ue(data, bit);
961 set.frame_mbs_only_flag = parse_u(1, data, bit);
963 if(!set.frame_mbs_only_flag)
964 set.mb_adaptive_frame_field_flag = parse_u(1, data, bit);
965 set.direct_8x8_inference_flag = parse_u(1, data, bit);
966 set.frame_cropping_flag = parse_u(1, data, bit);
967 if(set.frame_cropping_flag){
968 set.frame_crop_left_offset = parse_ue(data, bit);
969 set.frame_crop_right_offset = parse_ue(data, bit);
970 set.frame_crop_top_offset = parse_ue(data, bit);
971 set.frame_crop_bottom_offset = parse_ue(data, bit);
975 set.vui_parameters_present_flag = parse_u(1, data, bit);
976 if(set.vui_parameters_present_flag){
979 vui.aspect_ratio_info_present = parse_u(1, data, bit);
980 if(vui.aspect_ratio_info_present){
981 uint32_t aspect_ratio_idc = parse_u(8, data, bit);
982 uint32_t aspect_ratio_width[255] = {
983 1, 12, 10, 16, 40, 24, 20, 32, 80, 18, 15, 64, 160, 4, 3, 2
985 uint32_t aspect_ratio_height[255] = {
986 1, 11, 11, 11, 33, 11, 11, 11, 33, 11, 11, 33, 99, 3, 2, 1
988 if(aspect_ratio_idc == 255){
989 vui.sar_width = parse_u(16, data, bit);
990 vui.sar_height = parse_u(16, data, bit);
993 assert(aspect_ratio_idc<=16);
994 vui.sar_width = aspect_ratio_width[aspect_ratio_idc];
995 vui.sar_height = aspect_ratio_height[aspect_ratio_idc];
999 vui.overscan_info_present_flag = parse_u(1, data, bit);
1000 if(vui.overscan_info_present_flag){
1001 vui.overscan_appropriate_flag = parse_u(1, data, bit);
1004 vui.video_signal_type_present_flag = parse_u(1, data, bit);
1005 if(vui.video_signal_type_present_flag){
1006 vui.video_format = parse_u(3, data, bit);
1007 vui.video_full_range_flag = parse_u(1, data, bit);
1008 vui.colour_description_present_flag = parse_u(1, data, bit);
1009 if(vui.colour_description_present_flag){
1010 vui.colour_primaries = parse_u(8, data, bit);
1011 vui.transfer_characteristics = parse_u(8, data, bit);
1012 vui.matrix_coefficients = parse_u(8, data, bit);
1016 vui.chroma_loc_info_present_flag = parse_u(1, data, bit);
1017 if(vui.chroma_loc_info_present_flag){
1018 vui.chroma_sample_loc_type_top_field = parse_ue(data, bit);
1019 vui.chroma_sample_loc_type_bottom_field = parse_ue(data, bit);
1022 vui.timing_info_present_flag = parse_u(1, data, bit);
1023 if(vui.timing_info_present_flag){
1024 vui.num_units_in_tick = parse_u(32, data, bit);
1025 vui.time_scale = parse_u(32, data, bit);
1026 vui.fixed_frame_rate_flag = parse_u(1, data, bit);
1029 vui.nal_hrd_parameters_present_flag = parse_u(1, data, bit);
1030 if(vui.nal_hrd_parameters_present_flag){
1031 hrd_parameters(parse, parse.vui.nal_hrd_parameters, data, bit);
1034 vui.vcl_hrd_parameters_present_flag = parse_u(1, data, bit);
1035 if(vui.vcl_hrd_parameters_present_flag){
1036 hrd_parameters(parse, parse.vui.vcl_hrd_parameters, data, bit);
1039 if(vui.nal_hrd_parameters_present_flag || vui.vcl_hrd_parameters_present_flag){
1040 vui.low_delay_hrd_flag = parse_u(1, data, bit);
1043 vui.pic_struct_present_flag = parse_u(1, data, bit);
1045 vui.bitstream_restriction_flag = parse_u(1, data, bit);
1046 if(vui.bitstream_restriction_flag){
1047 vui.motion_vectors_over_pic_bondaries_flag = parse_u(1, data, bit);
1048 vui.max_bytes_per_pic_denom = parse_ue(data, bit);
1049 vui.max_bits_per_pic_denom = parse_ue(data, bit);
1050 if(bit/8 >= size)
return;
1051 vui.log2_max_mv_length_horizontal = parse_ue(data, bit, size);
1052 if(bit/8 >= size)
return;
1053 vui.log2_max_mv_length_vertical = parse_ue(data, bit, size);
1054 if(bit/8 >= size)
return;
1055 vui.max_num_reorder_frames = parse_ue(data, bit, size);
1056 if(bit/8 >= size)
return;
1057 vui.max_dec_frame_buffering = parse_ue(data, bit, size);
1060 if(bit/8 == size)
return;
1061 rbsp_trailing_bits(data, bit);
1064static void pic_parameter_set_rbsp(
H264ParseData &parse,
const uint8_t *data,
size_t size)
1070 set.pic_parameter_set_id = parse_ue(data, bit);
1071 set.seq_parameter_set_id = parse_ue(data, bit);
1072 set.entropy_coding_mode_flag = parse_u(1, data, bit);
1074 set.bottom_field_pic_order_in_frame_present_flag = parse_u(1, data, bit);
1075 set.num_slice_groups_minus1 = parse_ue(data, bit);
1077 if(set.num_slice_groups_minus1 > 0){
1078 set.slice_group_map_type = parse_ue(data, bit);
1079 if(set.slice_group_map_type == 0){
1080 for(uint32_t iGroup = 0; iGroup <= set.num_slice_groups_minus1; iGroup++){
1081 parse_ue(data, bit);
1085 else if(set.slice_group_map_type == 2){
1086 for(uint32_t iGroup = 0; iGroup <= set.num_slice_groups_minus1; iGroup++){
1087 parse_ue(data, bit);
1088 parse_ue(data, bit);
1093 else if(set.slice_group_map_type == 3 ||
1094 set.slice_group_map_type == 4 ||
1095 set.slice_group_map_type == 5){
1097 parse_u(1, data, bit);
1099 parse_ue(data, bit);
1101 else if(set.slice_group_map_type == 6){
1102 uint32_t pic_size_in_map_units_minus1 = parse_ue(data, bit);
1103 for(uint32_t i=0; i<=pic_size_in_map_units_minus1; i++){
1109 set.num_ref_idx_l0_default_active_minus1 = parse_ue(data, bit);
1110 set.num_ref_idx_l1_default_active_minus1 = parse_ue(data, bit);
1111 set.weighted_pred_flag = parse_u(1, data, bit);
1113 set.weighted_bipred_idc = parse_u(2, data, bit);
1115 set.pic_init_qp_minus26 = parse_se(data, bit);
1116 set.pic_init_sp_minus26 = parse_se(data, bit);
1117 set.chroma_qp_index_offset = parse_se(data, bit);
1118 set.deblocking_filter_control_present_flag = parse_u(1, data, bit);
1119 set.constrained_intra_pred_flag = parse_u(1, data, bit);
1120 set.redundant_pic_cnt_present_flag = parse_u(1, data, bit);
1123 if(more_rbsp_data(data, size, bit)){
1124 set.transform_8x8_mode_flag = parse_u(1, data, bit);
1125 set.pic_scaling_matrix_present_flag = parse_u(1, data, bit);
1126 if(set.pic_scaling_matrix_present_flag){
1137 set.second_chroma_qp_index_offset = parse_se(data, bit);
1139 rbsp_trailing_bits(data, bit);
1142static void buffering_period(
H264ParseData &parse,
const uint8_t *data,
size_t &bit, uint32_t)
1144 uint32_t NalHrdBpPresentFlag = parse.vui.nal_hrd_parameters_present_flag;
1145 uint32_t VclHrdBpPresentFlag = parse.vui.vcl_hrd_parameters_present_flag;
1147 uint32_t seq_parameter_set_id =
1148 parse_ue(data, bit);
1149 printf(
" - seq_parameter_set_id %u\n", seq_parameter_set_id);
1150 if(NalHrdBpPresentFlag){
1151 uint32_t initial_cpb_removal_delay[32];
1152 uint32_t initial_cpb_removal_delay_offset[32];
1153 for(
size_t SchedSelIdx=0; SchedSelIdx<=parse.vui.nal_hrd_parameters.cpb_cnt_minus1; SchedSelIdx++){
1154 uint32_t v = parse.vui.nal_hrd_parameters.initial_cpb_removal_delay_length_minus1+1;
1155 initial_cpb_removal_delay[SchedSelIdx] = parse_u(v, data, bit);
1156 initial_cpb_removal_delay_offset[SchedSelIdx] = parse_u(v, data, bit);
1157 printf(
" - initial_cpb_removal_delay[%zu] %u\n", SchedSelIdx, initial_cpb_removal_delay[SchedSelIdx]);
1158 printf(
" - initial_cpb_removal_delay_offset[%zu] %u\n", SchedSelIdx, initial_cpb_removal_delay_offset[SchedSelIdx]);
1162 if(VclHrdBpPresentFlag){
1163 uint32_t initial_cpb_removal_delay[32];
1164 uint32_t initial_cpb_removal_delay_offset[32];
1165 for(
size_t SchedSelIdx=0; SchedSelIdx<=parse.vui.vcl_hrd_parameters.cpb_cnt_minus1; SchedSelIdx++){
1166 uint32_t v = parse.vui.vcl_hrd_parameters.initial_cpb_removal_delay_length_minus1;
1167 initial_cpb_removal_delay[SchedSelIdx] = parse_u(v, data, bit);
1168 initial_cpb_removal_delay_offset[SchedSelIdx] = parse_u(v, data, bit);
1169 printf(
" - initial_cpb_removal_delay[%zu] %u\n", SchedSelIdx, initial_cpb_removal_delay[SchedSelIdx]);
1170 printf(
" - initial_cpb_removal_delay_offset[%zu] %u\n", SchedSelIdx, initial_cpb_removal_delay_offset[SchedSelIdx]);
1175static void pic_timing(
H264ParseData &parse,
const uint8_t *data,
size_t &bit, uint32_t)
1177 uint32_t CpbDpbDelaysPresentFlag = parse.vui.nal_hrd_parameters_present_flag | parse.vui.vcl_hrd_parameters_present_flag;
1179 HrdParameters &hrd(parse.vui.nal_hrd_parameters_present_flag ? parse.vui.nal_hrd_parameters : parse.vui.vcl_hrd_parameters);
1181 if(CpbDpbDelaysPresentFlag){
1182 uint32_t cpb_removal_delay = parse_u(hrd.cpb_removal_delay_length_minus1+1, data, bit);
1183 uint32_t cpb_output_delay = parse_u(hrd.cpb_output_delay_length_minus1+1, data, bit);
1184 printf(
" - cpb_removal_delay %u\n", cpb_removal_delay);
1185 printf(
" - cpb_output_delay %u\n", cpb_output_delay);
1187 if(parse.vui.pic_struct_present_flag){
1188 uint32_t pic_struct = parse_u(4, data, bit);
1189 printf(
" - pic_struct %u\n", pic_struct);
1191 uint32_t NumClockTS = 1;
1192 assert(pic_struct <= 8);
1214 printf(
" - NumClockTS %u\n", NumClockTS);
1216 uint32_t clock_timestamp_flag[3];
1217 for(
size_t i=0; i<NumClockTS; i++){
1218 clock_timestamp_flag[i] = parse_u(1, data, bit);
1219 printf(
" - clock_timestamp_flag[%zu] %u\n", i, clock_timestamp_flag[i]);
1220 if(clock_timestamp_flag[i]){
1221 uint32_t ct_type = parse_u(2, data, bit);
1222 printf(
" - ct_type %u\n", ct_type);
1223 uint32_t nuit_field_based_flag = parse_u(1, data, bit);
1224 printf(
" - nuit_field_based_flag %u\n", nuit_field_based_flag);
1225 uint32_t counting_type = parse_u(5, data, bit);
1226 printf(
" - counting_type %u\n", counting_type);
1227 uint32_t full_timestamp_flag = parse_u(1, data, bit);
1228 printf(
" - full_timestamp_flag %u\n", full_timestamp_flag);
1229 uint32_t discontinuity_flag = parse_u(1, data, bit);
1230 printf(
" - discontinuity_flag %u\n", discontinuity_flag);
1231 uint32_t cnt_dropped_flag = parse_u(1, data, bit);
1232 printf(
" - cnt_dropped_flag %u\n", cnt_dropped_flag);
1233 uint32_t n_frames = parse_u(5, data, bit);
1234 printf(
" - n_frames %u\n", n_frames);
1235 if(full_timestamp_flag){
1236 uint32_t seconds_value = parse_u(6, data, bit);
1237 uint32_t minutes_value = parse_u(6, data, bit);
1238 uint32_t hours_value = parse_u(5, data, bit);
1239 printf(
" - seconds_value %u\n", seconds_value);
1240 printf(
" - minutes_value %u\n", minutes_value);
1241 printf(
" - hours_value %u\n", hours_value);
1244 uint32_t seconds_flag = parse_u(1, data, bit);
1245 printf(
" - seconds_flag %u\n", seconds_flag);
1247 uint32_t seconds_value = parse_u(6, data, bit);
1248 uint32_t minutes_flag = parse_u(1, data, bit);
1249 printf(
" - seconds_value %u\n", seconds_value);
1250 printf(
" - minutes_flag %u\n", minutes_flag);
1252 uint32_t minutes_value = parse_u(6, data, bit);
1253 uint32_t hours_flag = parse_u(1, data, bit);
1254 printf(
" - minutes_value %u\n", minutes_value);
1255 printf(
" - hours_flag %u\n", hours_flag);
1257 uint32_t hours_value = parse_u(5, data, bit);
1258 printf(
" - hours_value %u\n", hours_value);
1263 uint32_t v = hrd.time_offset_length;
1265 int32_t time_offset = parse_i(v, data, bit);
1266 printf(
" - time_offset %i\n", time_offset);
1273static void filler_payload(
H264ParseData&,
const uint8_t *data,
size_t &bit, uint32_t payloadSize)
1275 for(
size_t k=0; k<payloadSize; k++){
1276 uint32_t ff_byte = parse_f(8, data, bit);
1277 assert(ff_byte == 0xff);
1281static void recovery_point(
H264ParseData&,
const uint8_t *data,
size_t &bit, uint32_t)
1283 uint32_t recovery_frame_cnt =
1284 parse_ue(data, bit);
1285 uint32_t exact_match_flag =
1286 parse_u(1, data, bit);
1287 uint32_t broken_link_flag =
1288 parse_u(1, data, bit);
1289 uint32_t changing_slice_group_idc =
1290 parse_u(2, data, bit);
1292 printf(
"recovery_frame_cnt %u\n", recovery_frame_cnt);
1293 printf(
"exact_match_flag %u\n", exact_match_flag);
1294 printf(
"broken_link_flag %u\n", broken_link_flag);
1295 printf(
"changing_slice_group_idc %u\n", changing_slice_group_idc);
1302static void reserverd_sei_message(
H264ParseData&,
const uint8_t* ,
size_t &bit, uint32_t payloadSize)
1304 bit += 8*payloadSize;
1309static bool byte_aligned(
size_t &bit)
1314static void sei_payload(
H264ParseData ¶se,
const uint8_t *data,
size_t &bit, uint32_t payloadType, uint32_t payloadSize)
1316 printf(
"SEI payloadType %u\n", payloadType);
1317 if(payloadType == 0){
1318 buffering_period(parase, data, bit, payloadSize);
1320 else if(payloadType == 1){
1321 pic_timing(parase, data, bit, payloadSize);
1323 else if(payloadType == 3){
1324 filler_payload(parase, data, bit, payloadSize);
1326 else if(payloadType == 6){
1327 recovery_point(parase, data, bit, payloadSize);
1333 reserverd_sei_message(parase, data, bit, payloadSize);
1335 if(!byte_aligned(bit)){
1336 uint32_t bit_equal_to_one = parse_u(1, data, bit);
1337 assert(bit_equal_to_one == 1);
1338 while(!byte_aligned(bit)){
1339 uint32_t bit_equal_to_zero = parse_u(1, data, bit);
1340 assert(bit_equal_to_zero == 0);
1345static void sei_message(
H264ParseData &parse,
const uint8_t *data,
size_t,
size_t &bit)
1347 uint32_t payloadType = 0;
1348 while(next_bits(8, data, bit) == 0xff){
1349 uint32_t ff_byte = parse_f(8, data, bit);
1350 assert(ff_byte == 0xff);
1353 uint32_t last_payload_type_byte = parse_u(8, data, bit);
1354 payloadType += last_payload_type_byte;
1355 uint32_t payloadSize = 0;
1356 while(next_bits(8, data, bit) == 0xff){
1357 uint32_t ff_byte = parse_f(8, data, bit);
1358 assert(ff_byte == 0xff);
1361 uint32_t last_payload_size_byte = parse_u(8, data, bit);
1362 payloadSize += last_payload_size_byte;
1363 sei_payload(parse, data, bit, payloadType, payloadSize);
1366static void sei_rbsp(
H264ParseData &parse,
const uint8_t *data,
size_t size)
1370 sei_message(parse, data, size, bit);
1371 }
while(more_rbsp_data(data, size, bit));
1372 rbsp_trailing_bits(data, bit);
1375static void access_unit_delimiter_rbsp(
H264ParseData&,
const uint8_t *data,
size_t)
1379 parse_u(3, data, bit);
1380 rbsp_trailing_bits(data, bit);
1383static void end_of_seq_rbsp(
H264ParseData&,
const uint8_t* ,
size_t)
1388static void end_of_stream_rbsp(
H264ParseData&,
const uint8_t* ,
size_t)
1393static void filler_data_rbsp(
H264ParseData&,
const uint8_t *data,
size_t size)
1396 for(; data[i]==0xff && i<size; i++)
1397 assert(data[i] == 0xff);
1399 rbsp_trailing_bits(data, bit);
1402static void prefix_nal_unit_rbsp(
H264ParseData&,
const uint8_t* ,
size_t)
1409static void seq_parameter_set_extension_rbsp(
H264ParseData&,
const uint8_t* ,
size_t)
1414void Cogs::Core::seq_parameter_set_nalu(
H264ParseData &parse,
const uint8_t *data,
size_t size)
1417 size_t rbsp_size = size;
1418 uint32_t NumBytesInRBSP = 0;
1419 uint8_t *rbsp =
new uint8_t[rbsp_size];
1425 header.forbidden_zero_bit = parse_f(1, data, bit);
1426 assert(header.forbidden_zero_bit == 0);
1427 header.nal_ref_idc = parse_u(2, data, bit);
1428 header.nal_unit_type = parse_u(5, data, bit);
1429 assert(header.nal_unit_type == 7);
1433 if(i+2 < j && data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x03){
1434 rbsp[NumBytesInRBSP++] = data[i++];
1435 rbsp[NumBytesInRBSP++] = data[i++];
1439 rbsp[NumBytesInRBSP++] = data[i++];
1441 assert(NumBytesInRBSP <= rbsp_size);
1444 seq_parameter_set_rbsp(parse, rbsp, NumBytesInRBSP);
1449void Cogs::Core::pic_parameter_set_nalu(
H264ParseData &parse,
const uint8_t *data,
size_t size)
1452 size_t rbsp_size = size;
1453 uint32_t NumBytesInRBSP = 0;
1454 uint8_t *rbsp =
new uint8_t[rbsp_size];
1460 header.forbidden_zero_bit = parse_f(1, data, bit);
1461 assert(header.forbidden_zero_bit == 0);
1462 header.nal_ref_idc = parse_u(2, data, bit);
1463 header.nal_unit_type = parse_u(5, data, bit);
1464 assert(header.nal_unit_type == 8);
1468 if(i+2 < j && data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x03){
1469 rbsp[NumBytesInRBSP++] = data[i++];
1470 rbsp[NumBytesInRBSP++] = data[i++];
1474 rbsp[NumBytesInRBSP++] = data[i++];
1476 assert(NumBytesInRBSP <= rbsp_size);
1479 pic_parameter_set_rbsp(parse, rbsp, NumBytesInRBSP);
1484void Cogs::Core::byte_stream_nal_unit(
H264ParseData &parse,
const uint8_t *data,
size_t size)
1488 for(uint32_t i=0; i<size; i++){
1489 if(i%8 == 0) printf(
"\n");
1490 printf(
"0x%02x ", data[i]);
1498 while(!(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x00 && data[i+3] == 0x01) &&
1499 !(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x01)){
1500 assert(data[i] == 0x00);
1506 if(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x00 && data[i+3] == 0x01){
1510 assert(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x01);
1515 size_t bit = (i++)*8;
1517 header.forbidden_zero_bit = parse_f(1, data, bit);
1518 assert(header.forbidden_zero_bit == 0);
1519 header.nal_ref_idc = parse_u(2, data, bit);
1520 header.nal_unit_type = parse_u(5, data, bit);
1523 if(header.nal_unit_type == 14 || header.nal_unit_type == 20 || header.nal_unit_type == 21){
1529 while(!(data[j+0] == 0x00 && data[j+1] == 0x00 && data[j+2] == 0x00 && data[j+3] == 0x01) &&
1530 !(data[j+0] == 0x00 && data[j+1] == 0x00 && data[j+2] == 0x01) &&
1534 size_t rbsp_size = j-i;
1536 uint32_t NumBytesInRBSP = 0;
1537 uint8_t *rbsp =
new uint8_t[rbsp_size];
1539 if(i+2 < j && data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x03){
1540 rbsp[NumBytesInRBSP++] = data[i++];
1541 rbsp[NumBytesInRBSP++] = data[i++];
1545 rbsp[NumBytesInRBSP++] = data[i++];
1547 assert(NumBytesInRBSP <= rbsp_size);
1551 switch(header.nal_unit_type){
1561 sei_rbsp(parse, rbsp, NumBytesInRBSP);
1564 seq_parameter_set_rbsp(parse, rbsp, NumBytesInRBSP);
1567 pic_parameter_set_rbsp(parse, rbsp, NumBytesInRBSP);
1570 access_unit_delimiter_rbsp(parse, rbsp, NumBytesInRBSP);
1573 end_of_seq_rbsp(parse, rbsp, NumBytesInRBSP);
1576 end_of_stream_rbsp(parse, rbsp, NumBytesInRBSP);
1579 filler_data_rbsp(parse, rbsp, NumBytesInRBSP);
1582 seq_parameter_set_extension_rbsp(parse, rbsp, NumBytesInRBSP);
1585 prefix_nal_unit_rbsp(parse, rbsp, NumBytesInRBSP);
1594 if(i == size)
break;
1599void Cogs::Core::extract_spspps(
const uint8_t *data,
size_t size, std::string &sps, std::string &pps)
1603 while(!(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x00 && data[i+3] == 0x01) &&
1604 !(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x01)){
1605 assert(data[i] == 0x00);
1611 if(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x00 && data[i+3] == 0x01){
1615 assert(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x01);
1623 header.forbidden_zero_bit = parse_f(1, data, bit);
1624 assert(header.forbidden_zero_bit == 0);
1625 header.nal_ref_idc = parse_u(2, data, bit);
1626 header.nal_unit_type = parse_u(5, data, bit);
1630 while(!(data[j+0] == 0x00 && data[j+1] == 0x00 && data[j+2] == 0x00 && data[j+3] == 0x01) &&
1631 !(data[j+0] == 0x00 && data[j+1] == 0x00 && data[j+2] == 0x01) &&
1635 size_t rbsp_size = j-i;
1637 if(header.nal_unit_type == 7 || header.nal_unit_type == 8){
1638 switch(header.nal_unit_type){
1640 sps = std::string((
char*)&data[i], rbsp_size);
1646 pps = std::string((
char*)&data[i], rbsp_size);
1658bool Cogs::Core::extract_nalu_header(
NALheader &header,
const uint8_t *data,
size_t size)
1661 if(i+3 >= size)
return false;
1663 while(!(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x00 && data[i+3] == 0x01) &&
1664 !(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x01)){
1665 if(data[i] != 0x00)
return false;
1667 if(i+3 >= size)
return false;
1671 if(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x00 && data[i+3] == 0x01){
1674 else if(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x01){
1683 header.forbidden_zero_bit = parse_f(1, data, bit);
1684 if(header.forbidden_zero_bit != 0)
return false;
1685 header.nal_ref_idc = parse_u(2, data, bit);
1686 header.nal_unit_type = parse_u(5, data, bit);
1690size_t Cogs::Core::find_next_frame(
const uint8_t *data,
size_t size)
1692 if(size < 4)
return size;
1695 while(!(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x00 && data[i+3] == 0x01) &&
1696 !(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x01)){
1697 assert(data[i] == 0x00);
1702 if(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x00 && data[i+3] == 0x01){
1706 assert(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x01);
1713 while(!(data[j+0] == 0x00 && data[j+1] == 0x00 && data[j+2] == 0x00 && data[j+3] == 0x01) &&
1714 !(data[j+0] == 0x00 && data[j+1] == 0x00 && data[j+2] == 0x01) &&
1724 if(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x00 && data[i+3] == 0x01){
1728 assert(data[i+0] == 0x00 && data[i+1] == 0x00 && data[i+2] == 0x01);
1736 header.forbidden_zero_bit = parse_f(1, data, bit);
1737 assert(header.forbidden_zero_bit == 0);
1738 header.nal_ref_idc = parse_u(2, data, bit);
1739 header.nal_unit_type = parse_u(5, data, bit);
1741 if(header.nal_unit_type <= 5 || header.nal_unit_type >= 19)
1746 while(!(data[j+0] == 0x00 && data[j+1] == 0x00 && data[j+2] == 0x00 && data[j+3] == 0x01) &&
1747 !(data[j+0] == 0x00 && data[j+1] == 0x00 && data[j+2] == 0x01) &&
1753 if(i == size)
break;
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....