⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.cpp

📁 完整的RTP RTSP代码库
💻 CPP
📖 第 1 页 / 共 3 页
字号:
  }  printf("   additional extension flag: %u\n", bs->GetBits(1));}      void h264_parse_pic_parameter_set (h264_decode_t *dec, CBitstream *bs){  uint32_t num_slice_groups, temp, iGroup;    printf("   pic_parameter_set_id: %u\n", h264_ue(bs));    printf("   seq_parameter_set_id: %u\n", h264_ue(bs));    printf("   entropy_coding_mode_flag: %u\n", bs->GetBits(1));    dec->pic_order_present_flag = bs->GetBits(1);    printf("   pic_order_present_flag: %u\n", dec->pic_order_present_flag);    num_slice_groups = h264_ue(bs);    printf("   num_slice_groups_minus1: %u\n", num_slice_groups);    if (num_slice_groups > 0) {      temp = h264_ue(bs);      printf("    slice_group_map_type: %u\n", temp);      if (temp == 0) {	for (iGroup = 0; iGroup <= num_slice_groups; iGroup++) {	  printf("     run_length_minus1[%u]: %u\n", iGroup, h264_ue(bs));	}      } else if (temp == 2) {	for (iGroup = 0; iGroup < num_slice_groups; iGroup++) {	  printf("     top_left[%u]: %u\n", iGroup, h264_ue(bs));	  printf("     bottom_right[%u]: %u\n", iGroup, h264_ue(bs));	}      } else if (temp < 6) { // 3, 4, 5	printf("     slice_group_change_direction_flag: %u\n", bs->GetBits(1));	printf("     slice_group_change_rate_minus1: %u\n", h264_ue(bs));      } else if (temp == 6) {	temp = h264_ue(bs);	printf("     pic_size_in_map_units_minus1: %u\n", temp);	uint32_t bits = calc_ceil_log2(num_slice_groups + 1);	printf("     bits - %u\n", bits);	for (iGroup = 0; iGroup <= temp; iGroup++) {	  printf("      slice_group_id[%u]: %u\n", iGroup, bs->GetBits(bits));	}      }    }    printf("   num_ref_idx_l0_active_minus1: %u\n", h264_ue(bs));    printf("   num_ref_idx_l1_active_minus1: %u\n", h264_ue(bs));    printf("   weighted_pred_flag: %u\n", bs->GetBits(1));    printf("   weighted_bipred_idc: %u\n", bs->GetBits(2));    printf("   pic_init_qp_minus26: %d\n", h264_se(bs));    printf("   pic_init_qs_minus26: %d\n", h264_se(bs));    printf("   chroma_qp_index_offset: %d\n", h264_se(bs));    printf("   deblocking_filter_control_present_flag: %u\n", bs->GetBits(1));    printf("   constrained_intra_pred_flag: %u\n", bs->GetBits(1));    printf("   redundant_pic_cnt_present_flag: %u\n", bs->GetBits(1));    int bits = bs->bits_remain();    if (bits == 0) return;    if (bits <= 8) {      uint8_t trail_check = bs->PeekBits(bits);      if (trail_check == trailing_bits[bits]) return;    }    // we have the extensions    uint8_t transform_8x8_mode_flag = bs->GetBits(1);    printf("   transform_8x8_mode_flag: %u\n", transform_8x8_mode_flag);    temp = bs->GetBits(1);    printf("   pic_scaling_matrix_present_flag: %u\n", temp);    if (temp) {      uint max_count = 6 + (2 * transform_8x8_mode_flag);      for (uint ix = 0; ix < max_count; ix++) {	temp = bs->GetBits(1);	printf("   Pic Scaling List[%u] Present Flag: %u\n", ix, temp); 	if (temp) {	  scaling_list(ix, ix < 6 ? 16 : 64, bs);	}      }    }    printf("   second_chroma_qp_index_offset: %u\n", h264_se(bs));}static const char *sei[19] = {  "buffering_period",  "pic_timing",   "pan_scan_rect",   "filler_payload",  "user_data_registered_itu_t_t35",  "user_data_unregistered",  "recovery_point",  "dec_ref_pic_marking_repetition",  "spare_pic",  "scene_info",  "sub_seq_info",  "sub_seq-layer_characteristics",  "full_frame_freeze",  "full_frame_freeze_release",  "full_frame_snapshot",  "progressive_refinement_segment_start",  "progressive_refinement_segment_end",  "motioned_constrained_slice_group_set",};static void h264_parse_sei (h264_decode_t *dec, CBitstream *bs){  uint32_t payload_type;  uint32_t payload_size, count;  uint32_t read_val;  const char *sei_type;  char *buffer = NULL;  uint8_t *payload_buffer = NULL;  uint32_t bufsize = 0;  bool is_printable;  uint32_t temp;  while (bs->bits_remain() >= 16) {    payload_type = 0;    while ((read_val = bs->GetBits(8)) == 0xff) {      payload_type += 255;    }    payload_type += read_val;    payload_size = 0;    while ((read_val = bs->GetBits(8)) == 0xff) {      payload_size += 255;    }    payload_size += read_val;    sei_type = payload_type <= 18 ? sei[payload_type] : "unknown value";    printf("   payload_type: %u %s\n", payload_type, sei_type);    printf("   payload_size: %u", payload_size);    if (payload_size + 1 > bufsize) {      buffer = (char *)realloc(buffer, payload_size + 1);      payload_buffer = (uint8_t *)realloc(payload_buffer, payload_size + 1);      bufsize = payload_size + 1;    }    uint ix = 0;    count = payload_size;    if (payload_size > 8) {      printf("\n   ");    }    is_printable = true;    while (count > 0) {      uint8_t bits = bs->GetBits(8);      payload_buffer[ix] = bits;      if (isprint(bits)) {	buffer[ix++] = bits;      } else {	buffer[ix++] = '.';	is_printable = false;      }      printf(" 0x%x", bits);      if ((ix % 8) == 0) printf("\n   ");      count--;    }    printf("\n");    if (is_printable || payload_type == 4 || payload_type == 5) {      buffer[ix] = '\0';      printf("    string is \"%s\"\n", buffer);    }    try {      CBitstream payload_bs;      payload_bs.init(payload_buffer, payload_size * 8);      switch (payload_type) {      case 0: // buffering period	printf("    seq_parameter_set_id: %u\n", h264_ue(&payload_bs));	if (dec->NalHrdBpPresentFlag) {	  for (ix = 0; ix <= dec->cpb_cnt_minus1; ix++) {	    printf("    initial_cpb_removal_delay[%u]: %u\n", 		   ix, 		   payload_bs.GetBits(dec->initial_cpb_removal_delay_length_minus1 + 1));	    printf("    initial_cpb_removal_delay_offset[%u]: %u\n", 		   ix, 		   payload_bs.GetBits(dec->initial_cpb_removal_delay_length_minus1 + 1));	  }	    	}	if (dec->VclHrdBpPresentFlag) {	  for (ix = 0; ix <= dec->cpb_cnt_minus1; ix++) {	    printf("    initial_cpb_removal_delay[%u]: %u\n", 		   ix, 		   payload_bs.GetBits(dec->initial_cpb_removal_delay_length_minus1 + 1));	    printf("    initial_cpb_removal_delay_offset[%u]: %u\n", 		   ix, 		   payload_bs.GetBits(dec->initial_cpb_removal_delay_length_minus1 + 1));	  }	}	break;      case 1: // picture timing	if (dec->CpbDpbDelaysPresentFlag) {	  printf("    cpb_removal_delay: %u\n", 		 payload_bs.GetBits(dec->cpb_removal_delay_length_minus1 + 1));	  printf("    dpb_output_delay: %u\n", 		 payload_bs.GetBits(dec->dpb_output_delay_length_minus1 + 1));	}	if (dec->pic_struct_present_flag) {	  temp = payload_bs.GetBits(4);	  printf("    pict_struct: %u\n", temp);	  uint NumClockTS = 0;	  if (temp < 3) NumClockTS = 1;	  else if (temp < 5 || temp == 7) NumClockTS = 2;	  else if (temp < 9) NumClockTS = 3;	  for (ix = 0; ix < NumClockTS; ix++) {	    temp = payload_bs.GetBits(1);	    printf("    clock_timestamp_flag[%u]: %u\n", ix, temp);	    if (temp) {	      printf("     ct_type: %u\n", payload_bs.GetBits(2));	      printf("     nuit_field_base_flag: %u\n", payload_bs.GetBits(1));	      printf("     counting_type: %u\n", payload_bs.GetBits(5));	      temp = payload_bs.GetBits(1);	      printf("     full_timestamp_flag: %u\n", temp);	      printf("     discontinuity_flag: %u\n", payload_bs.GetBits(1));	      printf("     cnt_dropped_flag: %u\n", payload_bs.GetBits(1));	      printf("     n_frame: %u\n", payload_bs.GetBits(8));	      if (temp) {		printf("     seconds_value: %u\n", payload_bs.GetBits(6));		printf("     minutes_value: %u\n", payload_bs.GetBits(6));		printf("     hours_value: %u\n", payload_bs.GetBits(5));	      } else {		temp = payload_bs.GetBits(1);		printf("     seconds_flag: %u\n", temp);		if (temp) {		  printf("     seconds_value: %u\n", payload_bs.GetBits(6));		  temp = payload_bs.GetBits(1);		  printf("     minutes_flag: %u\n", temp);		  if (temp) {		    printf("     minutes_value: %u\n", payload_bs.GetBits(6));		    temp = payload_bs.GetBits(1);		    printf("     hours_flag: %u\n", temp);		    if (temp) {		      printf("     hours_value: %u\n", payload_bs.GetBits(5));		    }		  }		}	      }	      if (dec->time_offset_length > 0) {		printf("     time_offset: %d\n", 		       payload_bs.GetBits(dec->time_offset_length));	      }	    }	  }	}	break;      case 2: //pan scan rectangle	printf("    pan_scan_rect_id: %u\n", h264_ue(&payload_bs));	temp = payload_bs.GetBits(1);	printf("    pan_scan_rect_cancel_flag: %u\n", temp);	if (!temp) {	  temp = h264_ue(&payload_bs);	  printf("     pan_scan_cnd_minus1: %u\n", temp);	  for (ix = 0; ix <= temp; ix++) {	    printf("      pan_scan_rect_left_offset[%u]: %u\n", 		   ix,h264_se(&payload_bs));	    printf("      pan_scan_rect_right_offset[%u]: %u\n", 		   ix,h264_se(&payload_bs));	    printf("      pan_scan_rect_top_offset[%u]: %u\n", 		   ix,h264_se(&payload_bs));	    printf("      pan_scan_rect_bottom_offset[%u]: %u\n", 		   ix,h264_se(&payload_bs));	  }	  printf("      pan_scan_rect_repitition_period: %u\n", 		 h264_ue(&payload_bs));	}	break;      case 6: // recover point	printf("    recovery_frame_cnt: %u\n", h264_ue(&payload_bs));	printf("    exact_match_flag: %u\n", payload_bs.GetBits(1));	printf("    broken_link_flag: %u\n", payload_bs.GetBits(1));	printf("    changing_slice_group_idc: %u\n",  payload_bs.GetBits(2));	break;      case 7: // decoded reference picture marking repetition	printf("    original_idr_flag: %u\n", payload_bs.GetBits(1));	printf("    original_frame_num: %u\n", h264_ue(&payload_bs));	if (!dec->frame_mbs_only_flag) {	  temp = payload_bs.GetBits(1);	  printf("    original_field_pic_flag: %u\n", temp);	  if (temp) {	    printf("     original_bottom_field_flag: %u\n", 		   payload_bs.GetBits(1));	  }	}	break;      case 8: { // spare pic 	uint32_t spare_field_flag;	printf("    target_frame_num: %u\n", h264_ue(&payload_bs));	spare_field_flag = payload_bs.GetBits(1);	printf("    spare_field_flag: %u\n", spare_field_flag);	if (spare_field_flag) 	  printf("     target_bottom_field_flag: %u\n", payload_bs.GetBits(1));	temp = h264_ue(&payload_bs);	printf("    num_spare_pics_minus1: %u\n", temp);#if 0	for (ix = 0; ix <= temp; ix++) {	  printf("    delta_spare_frame_num[%u]: %u\n", ix, h264_ue(&payload_bs));	  if (spare_field_flag) {	    printf("    spare_bottom_field_flag[%u]: %u\n", 		   ix, payload_bs.GetBits(1));	  }	  uint32_t spare_area_idc = h264_ue(&payload_bs);	  printf("    spare_area_idc[%u]: %u", ix, spare_area_idc);	  if (spare_area_idc == 1) {	  }	}#endif	break;      }      case 9: // scene information	temp = payload_bs.GetBits(1);	printf("    scene_info_present_flag: %u\n", temp);	if (temp) {	  printf("     scene_id: %u\n", h264_ue(&payload_bs));	  temp = h264_ue(&payload_bs);	  printf("     scene_transition_type: %u\n", temp);	  if (temp > 3) {	    printf("      second_scene_id: %u\n", h264_ue(&payload_bs));	  }	}	break;	      }          } catch (BitstreamErr_t err) {      printf("\nERROR reading bitstream %s\n\n", err == BITSTREAM_PAST_END ?	     "read past payload end" : "too many bits requested");    }  }  CHECK_AND_FREE(buffer);}uint32_t h264_find_next_start_code (uint8_t *pBuf, 				    uint32_t bufLen){  uint32_t val;  uint32_t offset;  offset = 0;  if (pBuf[0] == 0 && pBuf[1] == 0 && pBuf[2] == 0 && pBuf[3] == 1) {    pBuf += 4;    offset = 4;  } else if (pBuf[0] == 0 && pBuf[1] == 0 && pBuf[2] == 1) {    pBuf += 3;    offset = 3;  }  val = 0xffffffff;  while (offset < bufLen - 3) {    val <<= 8;    val |= *pBuf++;    offset++;    if (val == H264_START_CODE) {      return offset - 4;    }    if ((val & 0x00ffffff) == H264_START_CODE) {      return offset - 3;    }  }  return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -