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

📄 video.c

📁 MPEG2 PLAYER in linux
💻 C
📖 第 1 页 / 共 5 页
字号:
  supertot = stat_a[1].totsize + stat_a[2].totsize + stat_a[3].totsize;  supernum = stat_a[1].number + stat_a[2].number + stat_a[3].number;  supertime = stat_a[1].tottime + stat_a[2].tottime + stat_a[3].tottime;  printf("Total Number of Frames: %d\n", supernum);  printf("Avg Frame Size: %d bytes %d bits\n",	 supertot / (8 * supernum), (supertot / supernum) % 8);  printf("Total Time Decoding: %g secs.\n", supertime);  printf("Avg Decoding Time/Frame: %g secs.\n", supertime / ((double) supernum));  printf("Avg Decoding Frames/Sec: %g secs.\n", ((double) supernum) / supertime);  printf("\n");  printf("Cache Hits/Miss\n");  for (i = 0; i < 8; i++) {    printf("%.6d/%.6d\t%.6d/%.6d\t%.6d/%.6d\t%.6d/%.6d\n",	   cacheHit[i][0], cacheMiss[i][0], cacheHit[i][1], cacheMiss[i][1],	   cacheHit[i][2], cacheMiss[i][2], cacheHit[i][3], cacheMiss[i][3]);    printf("%.6d/%.6d\t%.6d/%.6d\t%.6d/%.6d\t%.6d/%.6d\n",	   cacheHit[i][4], cacheMiss[i][4], cacheHit[i][5], cacheMiss[i][5],	   cacheHit[i][6], cacheMiss[i][6], cacheHit[i][7], cacheMiss[i][7]);  }}static voidCollectStats(){  int i, j;  i = stat_a[0].frametype;  stat_a[i].totsize += stat_a[0].totsize;  stat_a[i].number += stat_a[0].number;  stat_a[i].i_mbsize += stat_a[0].i_mbsize;  stat_a[i].p_mbsize += stat_a[0].p_mbsize;  stat_a[i].b_mbsize += stat_a[0].b_mbsize;  stat_a[i].bi_mbsize += stat_a[0].bi_mbsize;  stat_a[i].i_mbnum += stat_a[0].i_mbnum;  stat_a[i].p_mbnum += stat_a[0].p_mbnum;  stat_a[i].b_mbnum += stat_a[0].b_mbnum;  stat_a[i].bi_mbnum += stat_a[0].bi_mbnum;  for (j = 0; j < 64; j++) {    stat_a[i].i_mbcbp[j] += stat_a[0].i_mbcbp[j];    stat_a[i].p_mbcbp[j] += stat_a[0].p_mbcbp[j];    stat_a[i].b_mbcbp[j] += stat_a[0].b_mbcbp[j];    stat_a[i].bi_mbcbp[j] += stat_a[0].bi_mbcbp[j];    stat_a[i].i_mbcoeff[j] += stat_a[0].i_mbcoeff[j];    stat_a[i].p_mbcoeff[j] += stat_a[0].p_mbcoeff[j];    stat_a[i].b_mbcoeff[j] += stat_a[0].b_mbcoeff[j];    stat_a[i].bi_mbcoeff[j] += stat_a[0].bi_mbcoeff[j];  }  stat_a[i].tottime += stat_a[0].tottime;  init_stat_struct(&(stat_a[0]));}static unsigned intbitCountRead(){  return bitCount;}static voidStartTime(){  stat_a[0].tottime = ReadSysClock();}static voidEndTime(){  stat_a[0].tottime = ReadSysClock() - stat_a[0].tottime;}#endif/* *-------------------------------------------------------------- * * ReadSysClock -- * *	Computes the current time according to the system clock. * * Results: *  The current time according to the system clock. * * Side effects: *      None. * *-------------------------------------------------------------- */doubleReadSysClock(){  struct timeval tv;  (void) gettimeofday(&tv, (struct timezone *)NULL);  return (tv.tv_sec + tv.tv_usec / 1000000.0);}/* *-------------------------------------------------------------- * * PrintTimeInfo -- * *	Displays statistics regarding the video playback time. * * Results: *  Outputs time statistics to the screen. * * Side effects: *      None. * *-------------------------------------------------------------- */voidPrintTimeInfo(vid_stream)  VidStream *vid_stream;{  double spent;#ifndef NOCONTROLS  if (ControlShow != CTRLBAR_NONE)    spent = StopWatch(STOPWATCH_STOP);  else      spent = ReadSysClock() - vid_stream->realTimeStart;#else  spent = ReadSysClock() - vid_stream->realTimeStart;#endif  if (!quietFlag) {    printf("\nReal Time Spent (After Initializations): %f secs.\n", spent);    printf("Avg. Frames/Sec: %f\n",	   ((double) vid_stream->totNumFrames) / spent);  }}/* *-------------------------------------------------------------- * * InitCrop -- * *      Initializes cropTbl - this was taken from newVidStream so *      that it wasn't done for each new video stream * * Results: *	None * * Side effects: *      cropTbl will be initialized * *-------------------------------------------------------------- */voidInitCrop(){  int i;  /* Initialize crop table. */  for (i = (-MAX_NEG_CROP); i < NUM_CROP_ENTRIES - MAX_NEG_CROP; i++) {    if (i <= 0) {      cropTbl[i + MAX_NEG_CROP] = 0;#ifdef TWELVE_BITS	} else if (i >= 2047) {      cropTbl[i + MAX_NEG_CROP] = 2047;#endif    } else if (i >= 255) {      cropTbl[i + MAX_NEG_CROP] = 255;    } else {      cropTbl[i + MAX_NEG_CROP] = i;    }  }}/* *-------------------------------------------------------------- * * NewVidStream -- * *	Allocates and initializes a VidStream structure. Takes *      as parameter requested size for buffer length. * * Results: *	A pointer to the new VidStream structure. * * Side effects: *      None. * *-------------------------------------------------------------- */VidStream *NewVidStream(buffer_len)  unsigned int buffer_len;{  int i, j;  VidStream *new;  static const unsigned char default_intra_matrix[64] = {    8, 16, 19, 22, 26, 27, 29, 34,    16, 16, 22, 24, 27, 29, 34, 37,    19, 22, 26, 27, 29, 34, 34, 38,    22, 22, 26, 27, 29, 34, 37, 40,    22, 26, 27, 29, 32, 35, 40, 48,    26, 27, 29, 32, 35, 40, 48, 58,    26, 27, 29, 34, 38, 46, 56, 69,  27, 29, 35, 38, 46, 56, 69, 83};  /* Check for legal buffer length. */  if (buffer_len < 4)    return NULL;  /* Make buffer length multiple of 4. */  buffer_len = (buffer_len + 3) >> 2;  /* Allocate memory for new structure. */  new = (VidStream *) malloc(sizeof(VidStream));  /* Initialize pointers to extension and user data. */  new->group.ext_data = new->group.user_data =    new->picture.extra_info = new->picture.user_data =    new->picture.ext_data = new->slice.extra_info =    new->ext_data = new->user_data = NULL;  /* Copy default intra matrix. */  for (i = 0; i < 8; i++) {    for (j = 0; j < 8; j++) {      new->intra_quant_matrix[i][j] = default_intra_matrix[i * 8 + j];    }  }  /* Initialize non intra quantization matrix. */  for (i = 0; i < 8; i++) {    for (j = 0; j < 8; j++) {      new->non_intra_quant_matrix[i][j] = 16;    }  }  /* Initialize pointers to image spaces. */  new->current = new->past = new->future = NULL;  for (i = 0; i < RING_BUF_SIZE; i++) {    new->ring[i] = NULL;  }  /* Create buffer. */    new->buf_start = (unsigned int *) malloc(buffer_len * 4);  /*   * Set max_buf_length to one less than actual length to deal with messy   * data without proper seq. end codes.   */  new->max_buf_length = buffer_len - 1;  /* Initialize bitstream i/o fields. */  new->bit_offset = 0;  new->buf_length = 0;  new->buffer = new->buf_start;  /* Initialize fields that used to be global */  new->film_has_ended = FALSE;  new->filename = NULL;  new->totNumFrames = 0;  new->ditherFlags = NULL;  new->EOF_flag = FALSE;  /* Return structure. */  return new;}/* *-------------------------------------------------------------- * * ResetVidStream -- * *	Re-initializes a VidStream structure. Takes *      as parameter a pointer to the VidStream to reset. * * Results: *	None. * * Side effects: *      None. * *-------------------------------------------------------------- */voidResetVidStream(vid)  VidStream *vid;{  int i;  /* Initialize pointers to image spaces. */  vid->current = vid->past = vid->future = NULL;  /* Initialize rings */  for (i = 0; i < RING_BUF_SIZE; i++)    vid->ring[i]->locked = 0;  /* Unlock */  /* Initialize bitstream i/o fields. */  vid->bit_offset = vid->buf_length = 0;  vid->buffer = vid->buf_start;  vid->curBits = 0;  /* We are at the beginning of the film, so film has not ended */  vid->film_has_ended = FALSE;  /* Initialize start time */  vid->realTimeStart = ReadSysClock();  /* Reset number of frames to zero */  vid->totNumFrames=0;  /* Reset EOF_flag to 0 */  vid->EOF_flag = 0;}/* *-------------------------------------------------------------- * * DestroyVidStream -- * *	Deallocates a VidStream structure. * * Results: *      None. * * Side effects: *	None. * *-------------------------------------------------------------- */voidDestroyVidStream(astream, xinfo)  VidStream *astream;  XInfo *xinfo;{  int i;  if (astream->ext_data != NULL)    free(astream->ext_data);  if (astream->user_data != NULL)    free(astream->user_data);  if (astream->group.ext_data != NULL)    free(astream->group.ext_data);  if (astream->group.user_data != NULL)    free(astream->group.user_data);  if (astream->picture.extra_info != NULL)    free(astream->picture.extra_info);  if (astream->picture.ext_data != NULL)    free(astream->picture.ext_data);  if (astream->picture.user_data != NULL)    free(astream->picture.user_data);  if (astream->slice.extra_info != NULL)    free(astream->slice.extra_info);  if (astream->buf_start != NULL)    free(astream->buf_start);  for (i = 0; i < RING_BUF_SIZE; i++) {    if (astream->ring[i] != NULL) {      DestroyPictImage(astream->ring[i], xinfo);      astream->ring[i] = NULL;    }  }  if (astream->ditherFlags !=NULL)    free(astream->ditherFlags);  free((char *) astream);}/* *-------------------------------------------------------------- * * NewPictImage -- * *	Allocates and initializes a PictImage structure. *      The width and height of the image space are passed in *      as parameters. * * Results: *	A pointer to the new PictImage structure. * * Side effects: *	None. * *-------------------------------------------------------------- */PictImage *NewPictImage(vid_stream,xinfo)  VidStream *vid_stream;  XInfo *xinfo;{  PictImage *new;  int ditherType=vid_stream->ditherType;  unsigned int width=vid_stream->mb_width * 16;  unsigned int height=vid_stream->mb_height * 16;#ifdef SH_MEM  Display *display=xinfo->display;#endif  /* Allocate memory space for new structure. */  new = (PictImage *) malloc(sizeof(PictImage));  /* Allocate memory for image spaces. */#ifdef SH_MEM  new->ximage = NULL;    if (shmemFlag) {    Visual *fc_visual;    int depth;    /*     * factor is 1 or 2     */    int factor = 1 + IS_2x2_DITHER(ditherType);    Visual *FindFullColorVisual();    #ifndef DISABLE_DITHER    if (ditherType == FULL_COLOR_DITHER || ditherType == FULL_COLOR2_DITHER) {#endif      fc_visual = FindFullColorVisual(display, &depth);      new->ximage = XShmCreateImage(display, fc_visual, (unsigned int) depth,				    ZPixmap,				    NULL, &(new->shminfo), width * factor,				    height * factor);#ifndef DISABLE_DITHER    } else if (ditherType == FULL_COLOR2_DITHER) {      fc_visual = FindFullColorVisual(display, &depth);      new->ximage = XShmCreateImage(display, fc_visual, (unsigned int) depth,				   ZPixmap,				    NULL, &(new->shminfo), width*2, height*2);    } else if (ditherType == MONO_DITHER || ditherType == MONO_THRESHOLD) {      new->ximage = XShmCreateImage(display, None, 1, XYBitmap,				    NULL, &(new->shminfo), width * factor,				    height * factor);    } else {      new->ximage = XShmCreateImage(display, None, xinfo->depth, ZPixmap, NULL,				    &(new->shminfo), width * factor,				    height * factor);    }#endif    /* If no go, then revert to normal Xlib calls. */        if (new->ximage == NULL) {

⌨️ 快捷键说明

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