void H264or5VideoStreamParser::analyze_hrd_parameters(BitVector& bv) {
  DEBUG_TAB;
  unsigned cpb_cnt_minus1 = bv.get_expGolomb();
  DEBUG_PRINT(cpb_cnt_minus1);
  unsigned bit_rate_scale = bv.getBits(4);
  DEBUG_PRINT(bit_rate_scale);
  unsigned cpb_size_scale = bv.getBits(4);
  DEBUG_PRINT(cpb_size_scale);
  for (unsigned SchedSelIdx = 0; SchedSelIdx <= cpb_cnt_minus1; ++SchedSelIdx) {
    DEBUG_TAB;
    DEBUG_PRINT(SchedSelIdx);
    unsigned bit_rate_value_minus1 = bv.get_expGolomb();
    DEBUG_PRINT(bit_rate_value_minus1);
    unsigned cpb_size_value_minus1 = bv.get_expGolomb();
    DEBUG_PRINT(cpb_size_value_minus1);
    Boolean cbr_flag = bv.get1BitBoolean();
    DEBUG_PRINT(cbr_flag);
  }
  unsigned initial_cpb_removal_delay_length_minus1 = bv.getBits(5);
  DEBUG_PRINT(initial_cpb_removal_delay_length_minus1);
  cpb_removal_delay_length_minus1 = bv.getBits(5);
  DEBUG_PRINT(cpb_removal_delay_length_minus1);
  dpb_output_delay_length_minus1 = bv.getBits(5);
  DEBUG_PRINT(dpb_output_delay_length_minus1);
  unsigned time_offset_length = bv.getBits(5);
  DEBUG_PRINT(time_offset_length);
}
void H264or5VideoStreamParser::profile_tier_level(BitVector& bv, unsigned max_sub_layers_minus1) {
  bv.skipBits(96);

  unsigned i;
  Boolean sub_layer_profile_present_flag[7], sub_layer_level_present_flag[7];
  for (i = 0; i < max_sub_layers_minus1; ++i) {
    sub_layer_profile_present_flag[i] = bv.get1BitBoolean();
    sub_layer_level_present_flag[i] = bv.get1BitBoolean();
  }
  if (max_sub_layers_minus1 > 0) {
    bv.skipBits(2*(8-max_sub_layers_minus1)); // reserved_zero_2bits
  }
  for (i = 0; i < max_sub_layers_minus1; ++i) {
    if (sub_layer_profile_present_flag[i]) {
      bv.skipBits(88);
    }
    if (sub_layer_level_present_flag[i]) {
      bv.skipBits(8); // sub_layer_level_idc[i]
    }
  }
}
void H264or5VideoStreamParser
::analyze_vui_parameters(BitVector& bv,
			 unsigned& num_units_in_tick, unsigned& time_scale) {
  Boolean aspect_ratio_info_present_flag = bv.get1BitBoolean();
  DEBUG_PRINT(aspect_ratio_info_present_flag);
  if (aspect_ratio_info_present_flag) {
    DEBUG_TAB;
    unsigned aspect_ratio_idc = bv.getBits(8);
    DEBUG_PRINT(aspect_ratio_idc);
    if (aspect_ratio_idc == 255/*Extended_SAR*/) {
      bv.skipBits(32); // sar_width; sar_height
    }
  }
  Boolean overscan_info_present_flag = bv.get1BitBoolean();
  DEBUG_PRINT(overscan_info_present_flag);
  if (overscan_info_present_flag) {
    bv.skipBits(1); // overscan_appropriate_flag
  }
  Boolean video_signal_type_present_flag = bv.get1BitBoolean();
  DEBUG_PRINT(video_signal_type_present_flag);
  if (video_signal_type_present_flag) {
    DEBUG_TAB;
    bv.skipBits(4); // video_format; video_full_range_flag
    Boolean colour_description_present_flag = bv.get1BitBoolean();
    DEBUG_PRINT(colour_description_present_flag);
    if (colour_description_present_flag) {
      bv.skipBits(24); // colour_primaries; transfer_characteristics; matrix_coefficients
    }
  }
  Boolean chroma_loc_info_present_flag = bv.get1BitBoolean();
  DEBUG_PRINT(chroma_loc_info_present_flag);
  if (chroma_loc_info_present_flag) {
    (void)bv.get_expGolomb(); // chroma_sample_loc_type_top_field
    (void)bv.get_expGolomb(); // chroma_sample_loc_type_bottom_field
  }
  if (fHNumber == 265) {
    bv.skipBits(3); // neutral_chroma_indication_flag, field_seq_flag, frame_field_info_present_flag
    Boolean default_display_window_flag = bv.get1BitBoolean();
    DEBUG_PRINT(default_display_window_flag);
    if (default_display_window_flag) {
      (void)bv.get_expGolomb(); // def_disp_win_left_offset
      (void)bv.get_expGolomb(); // def_disp_win_right_offset
      (void)bv.get_expGolomb(); // def_disp_win_top_offset
      (void)bv.get_expGolomb(); // def_disp_win_bottom_offset
    }
  }
  Boolean timing_info_present_flag = bv.get1BitBoolean();
  DEBUG_PRINT(timing_info_present_flag);
  if (timing_info_present_flag) {
    DEBUG_TAB;
    num_units_in_tick = bv.getBits(32);
    DEBUG_PRINT(num_units_in_tick);
    time_scale = bv.getBits(32);
    DEBUG_PRINT(time_scale);
    if (fHNumber == 264) {
      Boolean fixed_frame_rate_flag = bv.get1BitBoolean();
      DEBUG_PRINT(fixed_frame_rate_flag);
    } else { // 265
      Boolean vui_poc_proportional_to_timing_flag = bv.get1BitBoolean();
      DEBUG_PRINT(vui_poc_proportional_to_timing_flag);
      if (vui_poc_proportional_to_timing_flag) {
	unsigned vui_num_ticks_poc_diff_one_minus1 = bv.get_expGolomb();
	DEBUG_PRINT(vui_num_ticks_poc_diff_one_minus1);
      }
    }
  }
}
void H264or5VideoStreamParser
::analyze_vui_parameters(BitVector& bv,
			 unsigned& num_units_in_tick, unsigned& time_scale) {
  Boolean aspect_ratio_info_present_flag = bv.get1BitBoolean();
  DEBUG_PRINT(aspect_ratio_info_present_flag);
  if (aspect_ratio_info_present_flag) {
    DEBUG_TAB;
    unsigned aspect_ratio_idc = bv.getBits(8);
    DEBUG_PRINT(aspect_ratio_idc);
    if (aspect_ratio_idc == 255/*Extended_SAR*/) {
      bv.skipBits(32); // sar_width; sar_height
    }
  }
  Boolean overscan_info_present_flag = bv.get1BitBoolean();
  DEBUG_PRINT(overscan_info_present_flag);
  if (overscan_info_present_flag) {
    bv.skipBits(1); // overscan_appropriate_flag
  }
  Boolean video_signal_type_present_flag = bv.get1BitBoolean();
  DEBUG_PRINT(video_signal_type_present_flag);
  if (video_signal_type_present_flag) {
    DEBUG_TAB;
    bv.skipBits(4); // video_format; video_full_range_flag
    Boolean colour_description_present_flag = bv.get1BitBoolean();
    DEBUG_PRINT(colour_description_present_flag);
    if (colour_description_present_flag) {
      bv.skipBits(24); // colour_primaries; transfer_characteristics; matrix_coefficients
    }
  }
  Boolean chroma_loc_info_present_flag = bv.get1BitBoolean();
  DEBUG_PRINT(chroma_loc_info_present_flag);
  if (chroma_loc_info_present_flag) {
    (void)bv.get_expGolomb(); // chroma_sample_loc_type_top_field
    (void)bv.get_expGolomb(); // chroma_sample_loc_type_bottom_field
  }
  if (fHNumber == 265) {
    bv.skipBits(2); // neutral_chroma_indication_flag, field_seq_flag
    Boolean frame_field_info_present_flag = bv.get1BitBoolean();
    DEBUG_PRINT(frame_field_info_present_flag);
    pic_struct_present_flag = frame_field_info_present_flag; // hack to make H.265 like H.264
    Boolean default_display_window_flag = bv.get1BitBoolean();
    DEBUG_PRINT(default_display_window_flag);
    if (default_display_window_flag) {
      (void)bv.get_expGolomb(); // def_disp_win_left_offset
      (void)bv.get_expGolomb(); // def_disp_win_right_offset
      (void)bv.get_expGolomb(); // def_disp_win_top_offset
      (void)bv.get_expGolomb(); // def_disp_win_bottom_offset
    }
  }
  Boolean timing_info_present_flag = bv.get1BitBoolean();
  DEBUG_PRINT(timing_info_present_flag);
  if (timing_info_present_flag) {
    DEBUG_TAB;
    num_units_in_tick = bv.getBits(32);
    DEBUG_PRINT(num_units_in_tick);
    time_scale = bv.getBits(32);
    DEBUG_PRINT(time_scale);
    if (fHNumber == 264) {
      Boolean fixed_frame_rate_flag = bv.get1BitBoolean();
      DEBUG_PRINT(fixed_frame_rate_flag);
    } else { // 265
      Boolean vui_poc_proportional_to_timing_flag = bv.get1BitBoolean();
      DEBUG_PRINT(vui_poc_proportional_to_timing_flag);
      if (vui_poc_proportional_to_timing_flag) {
	unsigned vui_num_ticks_poc_diff_one_minus1 = bv.get_expGolomb();
	DEBUG_PRINT(vui_num_ticks_poc_diff_one_minus1);
      }
      return; // For H.265, don't bother parsing any more of this #####
    }
  }
  // The following is H.264 only: #####
  Boolean nal_hrd_parameters_present_flag = bv.get1BitBoolean();
  DEBUG_PRINT(nal_hrd_parameters_present_flag);
  if (nal_hrd_parameters_present_flag) analyze_hrd_parameters(bv);
  Boolean vcl_hrd_parameters_present_flag = bv.get1BitBoolean();
  DEBUG_PRINT(vcl_hrd_parameters_present_flag);
  if (vcl_hrd_parameters_present_flag) analyze_hrd_parameters(bv);
  CpbDpbDelaysPresentFlag = nal_hrd_parameters_present_flag || vcl_hrd_parameters_present_flag;
  if (CpbDpbDelaysPresentFlag) {
    bv.skipBits(1); // low_delay_hrd_flag
  }
  pic_struct_present_flag = bv.get1BitBoolean();
  DEBUG_PRINT(pic_struct_present_flag);
}