Esempio n. 1
0
int
h264_decode_seq_parameter_set(elementary_stream_t *st, bitstream_t *bs)
{
  int profile_idc, level_idc, poc_type;
  unsigned int sps_id, tmp, i, width, height;
  int cbpsize = -1;
  h264_private_t *p;

  if((p = st->es_priv) == NULL)
    p = st->es_priv = calloc(1, sizeof(h264_private_t));

  profile_idc= read_bits(bs, 8);
  read_bits1(bs);   //constraint_set0_flag
  read_bits1(bs);   //constraint_set1_flag
  read_bits1(bs);   //constraint_set2_flag
  read_bits1(bs);   //constraint_set3_flag
  read_bits(bs, 4); // reserved
  level_idc= read_bits(bs, 8);
  sps_id= read_golomb_ue(bs);


  i = 0;
  while(h264_lev2cpbsize[i][0] != -1) {
    if(h264_lev2cpbsize[i][0] >= level_idc) {
      cbpsize = h264_lev2cpbsize[i][1];
      break;
    }
    i++;
  }
  if(cbpsize < 0)
    return -1;

  p->sps[sps_id].cbpsize = cbpsize * 125; /* Convert from kbit to bytes */


  if(profile_idc >= 100){ //high profile
    if(read_golomb_ue(bs) == 3) //chroma_format_idc
      read_bits1(bs);  //residual_color_transform_flag
    read_golomb_ue(bs);  //bit_depth_luma_minus8
    read_golomb_ue(bs);  //bit_depth_chroma_minus8
    read_bits1(bs);

    if(read_bits1(bs)) {
      /* Scaling matrices */
      decode_scaling_list(bs, 16);
      decode_scaling_list(bs, 16);
      decode_scaling_list(bs, 16);
      decode_scaling_list(bs, 16);
      decode_scaling_list(bs, 16);
      decode_scaling_list(bs, 16);

      decode_scaling_list(bs, 64);
      decode_scaling_list(bs, 64);

    }
  }

  p->sps[sps_id].max_frame_num_bits = read_golomb_ue(bs) + 4;
  poc_type= read_golomb_ue(bs);
 
  if(poc_type == 0){ //FIXME #define
    read_golomb_ue(bs);
  } else if(poc_type == 1){//FIXME #define
    read_bits1(bs);
    read_golomb_se(bs);
    read_golomb_se(bs);
    tmp = read_golomb_ue(bs); /* poc_cycle_length */
    for(i = 0; i < tmp; i++)
      read_golomb_se(bs);

  }else if(poc_type != 2){
    /* Illegal poc */
    return -1;
  }

  tmp = read_golomb_ue(bs);

  read_bits1(bs);

  width = read_golomb_ue(bs) + 1; /* mb width */
  height = read_golomb_ue(bs) + 1; /* mb height */

  p->sps[sps_id].width = width * 16;
  p->sps[sps_id].height = height * 16;

  p->sps[sps_id].mbs_only_flag = read_bits1(bs);
  if(!p->sps[sps_id].mbs_only_flag)
    p->sps[sps_id].aff = read_bits1(bs);

  read_bits1(bs);

  /* CROP */
  if(read_bits1(bs)){
    tmp = read_golomb_ue(bs);
    tmp = read_golomb_ue(bs);
    tmp = read_golomb_ue(bs);
    tmp = read_golomb_ue(bs);
  }

  if(read_bits1(bs)) {
    decode_vui(p, bs, sps_id);
    return 0;
  } else {
    return -1;
  }
}
Esempio n. 2
0
int
h264_decode_seq_parameter_set(elementary_stream_t *st, bitstream_t *bs)
{
  uint32_t profile_idc, level_idc, poc_type;
  uint32_t sps_id, tmp, i, width, height;
  uint32_t cbpsize, mbs_only_flag, aff;
  uint32_t max_frame_num_bits;
  uint32_t crop_left, crop_right, crop_top, crop_bottom;
  h264_private_t *p;
  h264_sps_t *sps;

  if ((p = st->es_priv) == NULL) {
    p = st->es_priv = calloc(1, sizeof(h264_private_t));
    p->start = dispatch_clock;
  }

  profile_idc = read_bits(bs, 8);
  skip_bits1(bs);   //constraint_set0_flag
  skip_bits1(bs);   //constraint_set1_flag
  skip_bits1(bs);   //constraint_set2_flag
  skip_bits1(bs);   //constraint_set3_flag
  skip_bits(bs, 4); // reserved
  level_idc = read_bits(bs, 8);

  sps_id = read_golomb_ue(bs);
  if(sps_id >= MAX_SPS_COUNT)
    return -1;
  sps = &p->sps[sps_id];

  i = 0;
  cbpsize = -1;
  while (h264_lev2cpbsize[i][0] != -1) {
    if (h264_lev2cpbsize[i][0] >= level_idc) {
      cbpsize = h264_lev2cpbsize[i][1];
      break;
    }
    i++;
  }
  if (cbpsize == -1)
    return -1;

  if (profile_idc >= 100){ //high profile
    tmp = read_golomb_ue(bs);
    if (tmp == 3)          //chroma_format_idc
      read_bits1(bs);      //residual_color_transform_flag
    read_golomb_ue(bs);    //bit_depth_luma_minus8
    read_golomb_ue(bs);    //bit_depth_chroma_minus8
    read_bits1(bs);        //transform_bypass

    if(read_bits1(bs)) {
      /* Scaling matrices */
      decode_scaling_list(bs, 16);
      decode_scaling_list(bs, 16);
      decode_scaling_list(bs, 16);
      decode_scaling_list(bs, 16);
      decode_scaling_list(bs, 16);
      decode_scaling_list(bs, 16);

      decode_scaling_list(bs, 64);
      decode_scaling_list(bs, 64);

    }
  }

  max_frame_num_bits = read_golomb_ue(bs) + 4;
  poc_type = read_golomb_ue(bs); // pic_order_cnt_type

  if(poc_type == 0){
    read_golomb_ue(bs);
  } else if(poc_type == 1){
    skip_bits1(bs);
    read_golomb_se(bs);
    read_golomb_se(bs);
    tmp = read_golomb_ue(bs); /* poc_cycle_length */
    for(i = 0; i < tmp; i++)
      read_golomb_se(bs);

  }else if(poc_type != 2){
    /* Illegal poc */
    return -1;
  }

  tmp = read_golomb_ue(bs);

  read_bits1(bs);

  width  = read_golomb_ue(bs) + 1; /* mb width */
  height = read_golomb_ue(bs) + 1; /* mb height */

  mbs_only_flag = read_bits1(bs);
  aff = 0;
  if(!mbs_only_flag)
    aff = read_bits1(bs);

  read_bits1(bs);

  /* CROP */
  crop_left = crop_right = crop_top = crop_bottom = 0;
  if (read_bits1(bs)){
    crop_left   = read_golomb_ue(bs) * 2;
    crop_right  = read_golomb_ue(bs) * 2;
    crop_top    = read_golomb_ue(bs) * 2;
    crop_bottom = read_golomb_ue(bs) * 2;
  }

  if (read_bits1(bs)) /* vui present */
    if (decode_vui(sps, bs))
      return -1;

  sps->max_frame_num_bits = max_frame_num_bits;
  sps->mbs_only_flag = mbs_only_flag;
  sps->aff = aff;
  sps->cbpsize = cbpsize * 125; /* Convert from kbit to bytes */
  sps->width   = width  * 16 - crop_left - crop_right;
  sps->height  = height * 16 - crop_top  - crop_bottom;
  sps->valid   = 1;

  return 0;
}