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

📄 video.cpp

📁 This code is based on mpeg_play, available from: http://bmrc.berkeley.edu/frame/research/mpeg/
💻 CPP
📖 第 1 页 / 共 5 页
字号:
               stat_a[i].p_mbcoeff[j + 7]);      }    }    if (stat_a[i].b_mbnum > 0) {      printf("\tB Macro Block Stats:\n");      printf("\t%d B Macroblocks\n", stat_a[i].b_mbnum);      printf("\tAvg. Size: %d bytes + %d bits\n",             stat_a[i].b_mbsize / (8 * stat_a[i].b_mbnum),             (stat_a[i].b_mbsize * stat_a[i].b_mbnum) % 8);      printf("\t\tCoded Block Pattern Histogram:\n");      for (j = 0; j < 64; j += 8) {        printf("\t%.6d %.6d %.6d %.6d %.6d %.6d %.6d %.6d\n", stat_a[i].b_mbcbp[j],               stat_a[i].b_mbcbp[j + 1], stat_a[i].b_mbcbp[j + 2], stat_a[i].b_mbcbp[j + 3],               stat_a[i].b_mbcbp[j + 4], stat_a[i].b_mbcbp[j + 5], stat_a[i].b_mbcbp[j + 6],               stat_a[i].b_mbcbp[j + 7]);      }      printf("\n\t\tNumber of Coefficients/Block Histogram:\n");      for (j = 0; j < 64; j += 8) {        printf("\t%.6d %.6d %.6d %.6d %.6d %.6d %.6d %.6d\n", stat_a[i].b_mbcoeff[j],               stat_a[i].b_mbcoeff[j + 1], stat_a[i].b_mbcoeff[j + 2],               stat_a[i].b_mbcoeff[j + 3], stat_a[i].b_mbcoeff[j + 4],               stat_a[i].b_mbcoeff[j + 5], stat_a[i].b_mbcoeff[j + 6],               stat_a[i].b_mbcoeff[j + 7]);      }    }    if (stat_a[i].bi_mbnum > 0) {      printf("\tBi Macro Block Stats:\n");      printf("\t%d Bi Macroblocks\n", stat_a[i].bi_mbnum);      printf("\tAvg. Size: %d bytes + %d bits\n",             stat_a[i].bi_mbsize / (8 * stat_a[i].bi_mbnum),             (stat_a[i].bi_mbsize * stat_a[i].bi_mbnum) % 8);      printf("\t\tCoded Block Pattern Histogram:\n");      for (j = 0; j < 64; j += 8) {        printf("\t%.6d %.6d %.6d %.6d %.6d %.6d %.6d %.6d\n", stat_a[i].bi_mbcbp[j],               stat_a[i].bi_mbcbp[j + 1], stat_a[i].bi_mbcbp[j + 2], stat_a[i].bi_mbcbp[j + 3],               stat_a[i].bi_mbcbp[j + 4], stat_a[i].bi_mbcbp[j + 5], stat_a[i].bi_mbcbp[j + 6],               stat_a[i].bi_mbcbp[j + 7]);      }      printf("\n\t\tNumber of Coefficients/Block Histogram:\n");      for (j = 0; j < 64; j += 8) {        printf("\t%.6d %.6d %.6d %.6d %.6d %.6d %.6d %.6d\n", stat_a[i].bi_mbcoeff[j],               stat_a[i].bi_mbcoeff[j + 1], stat_a[i].bi_mbcoeff[j + 2],               stat_a[i].bi_mbcoeff[j + 3], stat_a[i].bi_mbcoeff[j + 4],               stat_a[i].bi_mbcoeff[j + 5], stat_a[i].bi_mbcoeff[j + 6],               stat_a[i].bi_mbcoeff[j + 7]);      }    }    printf("\nAvg. Time to Decode: %f secs.\n",           (stat_a[i].tottime / ((double) stat_a[i].number)));    printf("\n");    printf("*************************\n\n");  }  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(){    return(SDL_GetTicks()/1000.0);}/* *-------------------------------------------------------------- * * 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(){#ifdef USE_CROP_TABLE  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;    }  }#endif /* USE_CROP_TABLE */}/* *-------------------------------------------------------------- * * 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( unsigned int buffer_len ){    int i, j;    VidStream* vs;    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 vs structure. */    vs = (VidStream *) malloc(sizeof(VidStream));    memset( vs, 0, (sizeof *vs) );    /* Initialize pointers to extension and user data. */    vs->group.ext_data = vs->group.user_data =    vs->picture.extra_info = vs->picture.user_data =    vs->picture.ext_data = vs->slice.extra_info =    vs->ext_data = vs->user_data = NULL;    /* Copy default intra matrix. */    for( i = 0; i < 8; i++ )    {        for( j = 0; j < 8; j++ )        {            vs->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++ )        {            vs->non_intra_quant_matrix[i][j] = 16;        }    }        /* Initialize noise base matrix */    for( i = 0; i < 8; i++ )        for( j = 0; j < 8; j++ )            vs->noise_base_matrix[i][j] = (short) vs->non_intra_quant_matrix[i][j];    j_rev_dct((short *) vs->noise_base_matrix);    for( i = 0; i < 8; i++ )        for( j = 0; j < 8; j++ )	  vs->noise_base_matrix[i][j] *= vs->noise_base_matrix[i][j];    /* Initialize pointers to image spaces. */    vs->current = vs->past = vs->future = NULL;    for( i = 0; i < RING_BUF_SIZE; i++ )    {        vs->ring[i] = NULL;    }    /* Create buffer. */    vs->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.    */    vs->max_buf_length = buffer_len - 1;    /* Initialize fields that used to be global */    vs->ditherFlags = NULL;    vs->rate_deal = -1;    /* Reset everything for start of display */    ResetVidStream(vs);#ifdef USE_ATI    /* Initialize Rage128 hardware */    vs->ati_handle = vhar128_new();#endif    /* Return structure. */    return vs;}/* *-------------------------------------------------------------- * * ResetVidStream -- * *    Re-initializes a VidStream structure. Takes *      as parameter a pointer to the VidStream to reset. * * Results: *    None. * * Side effects: *    None. * *-------------------------------------------------------------- */void ResetVidStream( 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++) {    if ( vid->ring[i] )      vid->ring[i]->locked = 0;  /* Unlock */  }  /* Initialize bitstream i/o fields. */  vid->bit_offset = 0;  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;  /* Reset number of frames to zero */  vid->totNumFrames=0;#ifdef CALCULATE_FPS  for ( i=0; i<FPS_WINDOW; ++i )    vid->frame_time[i] = 0.0;  vid->timestamp_index = 0;#endif  /* Fields added by KR for synchronization */  vid->_skipFrame = 0;  vid->_skipCount = 0;  vid->_jumpFrame = -1;  vid->realTimeStart = 0;  /* Reset EOF_flag to 0 */  vid->EOF_flag = FALSE;  vid->current_frame=0;  vid->need_frameadjust=false;}/* *-------------------------------------------------------------- * * DestroyVidStream -- * *    Deallocates a VidStream structure. * * Results: *    None. * * Side effects: *    None. * *-------------------------------------------------------------- */void DestroyVidStream( VidStream* astream ){    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, astream->ring[i] );            astream->ring[i] = NULL;        }    }    if( astream->ditherFlags != NULL )        free( astream->ditherFlags );#ifdef USE_ATI    vhar128_close(astream->ati_handle);#endif#ifdef USE_ATI    vhar128_delete();#endif    free( (char*) astream );}/* *-------------------------------------------------------------- * * NewPictImage -- * *    Allocates and initializes a PictImage structure. *      The width and height of the image space are passed in *      as parameters. * * Results:

⌨️ 快捷键说明

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