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

📄 video.cpp

📁 This code is based on mpeg_play, available from: http://bmrc.berkeley.edu/frame/research/mpeg/
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  vid_stream->mb_width = (vid_stream->h_size + 15) / 16;  vid_stream->mb_height = (vid_stream->v_size + 15) / 16;#ifndef DISABLE_DITHER  /* If dither type is MBORDERED allocate ditherFlags. */  if (ditherType == MBORDERED_DITHER) {    vid_stream->ditherFlags =         (char *) malloc(vid_stream->mb_width*vid_stream->mb_height);  }#endif  /* Parse of aspect ratio code. */  get_bits4(data);  vid_stream->aspect_ratio = (unsigned char) data;  /* Parse off picture rate code. */  get_bits4(data);  vid_stream->picture_rate = (unsigned char) data;  /* Parse off bit rate. */  get_bits18(data);  vid_stream->bit_rate = data;  /* Flush marker bit. */  flush_bits(1);  /* Parse off vbv buffer size. */  get_bits10(data);  vid_stream->vbv_buffer_size = data;#ifdef not_def  /* Lets not bother with this.  Only increases memory image */  if (data*1024>vid_stream->max_buf_length) {    unsigned int *newbuf;    int sz=1024*data+1;    /* If they actually want a bigger buffer than we default to,       let them have it! (if we can) */    newbuf = (unsigned int *) realloc(vid_stream->buf_start, (unsigned int) 4*sz);    if (newbuf!=(unsigned int *)NULL) {      vid_stream->max_buf_length=sz;      vid_stream->buffer=          (vid_stream->buffer-vid_stream->buf_start)+newbuf;      vid_stream->buf_start=newbuf;    }}#endif  /* Parse off contrained parameter flag. */  get_bits1(data);  if (data) {    vid_stream->const_param_flag = TRUE;  } else    vid_stream->const_param_flag = FALSE;  /*   * If intra_quant_matrix_flag set, parse off intra quant matrix values.   */  get_bits1(data);  if (data) {    for (i = 0; i < 64; i++) {      get_bits8(data);      vid_stream->intra_quant_matrix[zigzag[i][1]][zigzag[i][0]] =        (unsigned char) data;    }  }  /*   * If non intra quant matrix flag set, parse off non intra quant matrix   * values.   */  get_bits1(data);  if (data) {    for (i = 0; i < 64; i++) {      get_bits8(data);      vid_stream->non_intra_quant_matrix[zigzag[i][1]][zigzag[i][0]] =        (unsigned char) data;    }  }  /* Adjust noise base matrix according to non_intra matrix */  for( i = 0; i < 8; i++ )    for( j = 0; j < 8; j++ )      vid_stream->noise_base_matrix[i][j] = (short) vid_stream->non_intra_quant_matrix[i][j];    j_rev_dct((short *) vid_stream->noise_base_matrix);    for( i = 0; i < 8; i++ )    for( j = 0; j < 8; j++ )      vid_stream->noise_base_matrix[i][j] *= vid_stream->noise_base_matrix[i][j];  /* Go to next start code. */  next_start_code(vid_stream);  /*   * If next start code is extension start code, parse off extension data.   */  if (next_bits(32, EXT_START_CODE, vid_stream)) {    flush_bits32;    if (vid_stream->ext_data != NULL) {      free(vid_stream->ext_data);      vid_stream->ext_data = NULL;    }    vid_stream->ext_data = get_ext_data(vid_stream);  }  /* If next start code is user start code, parse off user data. */  if (next_bits(32, USER_START_CODE, vid_stream)) {    flush_bits32;    if (vid_stream->user_data != NULL) {      free(vid_stream->user_data);      vid_stream->user_data = NULL;    }    vid_stream->user_data = get_ext_data(vid_stream);  }  return PARSE_OK;}/* *-------------------------------------------------------------- * * ParseGOP -- * *      Parses of group of pictures header from bit stream *      associated with vid_stream. * * Results: *      Values in gop header placed into video stream structure. * * Side effects: *      Bit stream irreversibly parsed. * *-------------------------------------------------------------- */static int ParseGOP( VidStream* vid_stream ){  unsigned int data;  /* Flush group of pictures start code. */  flush_bits32;  /* Parse off drop frame flag. */  get_bits1(data);  if (data) {    vid_stream->group.drop_flag = TRUE;  } else    vid_stream->group.drop_flag = FALSE;  /* Parse off hour component of time code. */  get_bits5(data);  vid_stream->group.tc_hours = data;  /* Parse off minute component of time code. */  get_bits6(data);  vid_stream->group.tc_minutes = data;  /* Flush marker bit. */  flush_bits(1);  /* Parse off second component of time code. */  get_bits6(data);  vid_stream->group.tc_seconds = data;  /* Parse off picture count component of time code. */  get_bits6(data);  vid_stream->group.tc_pictures = data;  /* Parse off closed gop and broken link flags. */  get_bits2(data);  if (data > 1) {    vid_stream->group.closed_gop = TRUE;    if (data > 2) {      vid_stream->group.broken_link = TRUE;    } else      vid_stream->group.broken_link = FALSE;  } else {    vid_stream->group.closed_gop = FALSE;    if (data) {      vid_stream->group.broken_link = TRUE;    } else      vid_stream->group.broken_link = FALSE;  }  /* Goto next start code. */  next_start_code(vid_stream);  /* If next start code is extension data, parse off extension data. */  if (next_bits(32, EXT_START_CODE, vid_stream)) {    flush_bits32;    if (vid_stream->group.ext_data != NULL) {      free(vid_stream->group.ext_data);      vid_stream->group.ext_data = NULL;    }    vid_stream->group.ext_data = get_ext_data(vid_stream);  }  /* If next start code is user data, parse off user data. */  if (next_bits(32, USER_START_CODE,vid_stream)) {    flush_bits32;    if (vid_stream->group.user_data != NULL) {      free(vid_stream->group.user_data);      vid_stream->group.user_data = NULL;    }    vid_stream->group.user_data = get_ext_data(vid_stream);  }  return PARSE_OK;}/* *-------------------------------------------------------------- * * ParsePicture -- * *      Parses picture header. Marks picture to be presented *      at particular time given a time stamp. * * Results: *      Values from picture header put into video stream structure. * * Side effects: *      Bit stream irreversibly parsed. * *-------------------------------------------------------------- */static int ParsePicture( VidStream* vid_stream, TimeStamp time_stamp ){  unsigned int data;  int i;  /* Flush header start code. */  flush_bits32;  /* This happens if there is a picture code before a sequence start */  if (vid_stream->ring[0] == NULL) {    printf("Warning: picture block before sequence header block\n");    return SKIP_PICTURE;  }  /* Parse off temporal reference. */  get_bits10(data);  vid_stream->picture.temp_ref = data;  /* Parse of picture type. */  get_bits3(data);  vid_stream->picture.code_type = data;  if ((vid_stream->picture.code_type == B_TYPE) &&      ((vid_stream->future == NULL) ||       ((vid_stream->past == NULL) && !(vid_stream->group.closed_gop))))    /* According to 2-D.5.1 (p D-18) this is ok, if the refereneces are OK */    return SKIP_PICTURE;  if ((vid_stream->picture.code_type == P_TYPE) && (vid_stream->future == NULL))    return SKIP_PICTURE;#ifdef ANALYSIS  StartTime();  stat_a[0].frametype = vid_stream->picture.code_type;  stat_a[0].number = 1;  stat_a[0].totsize = 45;  pictureSizeCount = bitCountRead();#endif  /* Parse off vbv buffer delay value. */  get_bits16(data);  vid_stream->picture.vbv_delay = data;  /* If P or B type frame... */  if ((vid_stream->picture.code_type == P_TYPE) ||       (vid_stream->picture.code_type == B_TYPE)) {    /* Parse off forward vector full pixel flag. */    get_bits1(data);    if (data) {      vid_stream->picture.full_pel_forw_vector = TRUE;    } else {      vid_stream->picture.full_pel_forw_vector = FALSE;    }    /* Parse of forw_r_code. */    get_bits3(data);    /* Decode forw_r_code into forw_r_size and forw_f. */    vid_stream->picture.forw_r_size = data - 1;    vid_stream->picture.forw_f = (1 << vid_stream->picture.forw_r_size);  }  /* If B type frame... */  if (vid_stream->picture.code_type == B_TYPE) {    /* Parse off back vector full pixel flag. */    get_bits1(data);    if (data)      vid_stream->picture.full_pel_back_vector = TRUE;    else      vid_stream->picture.full_pel_back_vector = FALSE;    /* Parse off back_r_code. */    get_bits3(data);    /* Decode back_r_code into back_r_size and back_f. */    vid_stream->picture.back_r_size = data - 1;    vid_stream->picture.back_f = (1 << vid_stream->picture.back_r_size);  }  /* Get extra bit picture info. */  if (vid_stream->picture.extra_info != NULL) {    free(vid_stream->picture.extra_info);    vid_stream->picture.extra_info = NULL;  }  vid_stream->picture.extra_info = get_extra_bit_info(vid_stream);  /* Goto next start code. */  next_start_code(vid_stream);  /* If start code is extension start code, parse off extension data. */  if (next_bits(32, EXT_START_CODE, vid_stream)) {    flush_bits32;    if (vid_stream->picture.ext_data != NULL) {      free(vid_stream->picture.ext_data);      vid_stream->picture.ext_data = NULL;    }    vid_stream->picture.ext_data = get_ext_data(vid_stream);  }  /* If start code is user start code, parse off user data. */  if (next_bits(32, USER_START_CODE, vid_stream)) {    flush_bits32;    if (vid_stream->picture.user_data != NULL) {      free(vid_stream->picture.user_data);      vid_stream->picture.user_data = NULL;    }    vid_stream->picture.user_data = get_ext_data(vid_stream);  }  /* Find a pict image structure in ring buffer not currently locked. */  i = 0;  while (vid_stream->ring[i]->locked != 0) {    if (++i >= RING_BUF_SIZE) {      perror("Fatal error. Ring buffer full.");      exit(1);    }  }  /* Set current pict image structure to the one just found in ring. */  vid_stream->current = vid_stream->ring[i];  /* Set time stamp. */  vid_stream->current->show_time = time_stamp;  /* Reset past macroblock address field. */  vid_stream->mblock.past_mb_addr = -1;#ifdef USE_ATI  int back, forw, current;  back = forw = -1;  current = i;  /* Look for indexes of future and past frames */  for(i = 0; i < RING_BUF_SIZE; i++)  {    if(vid_stream->future == vid_stream->ring[i]) forw = i;    if(vid_stream->past == vid_stream->ring[i]) back = i;  }  /* Start decoding a new frame */  switch(vid_stream->picture.code_type)  {    case B_TYPE:      vhar128_newdecode(vid_stream->ati_handle, forw, back, current);    break;    case P_TYPE:      vhar128_newdecode(vid_stream->ati_handle, -1, forw, current);    break;    case I_TYPE:      vhar128_newdecode(vid_stream->ati_handle, -1, -1, current);    break;  }#endif  return PARSE_OK;}/* *-------------------------------------------------------------- * * ParseSlice -- * *      Parses off slice header. * * Results: *      Values found in slice header put into video stream structure. * * Side effects: *      Bit stream irreversibly parsed. * *-------------------------------------------------------------- */static int ParseSlice( VidStream* vid_stream ){  unsigned int data;  /* Flush slice start code. */  flush_bits(24);  /* Parse off slice vertical position. */  get_bits8(data);  vid_stream->slice.vert_pos = data;  /* Parse off quantization scale. */  get_bits5(data);  vid_stream->slice.quant_scale = data;  /* Parse off extra bit slice info. */  if (vid_stream->slice.extra_info != NULL) {    free(vid_stream->slice.extra_info);    vid_stream->slice.extra_info = NULL;  }

⌨️ 快捷键说明

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