📄 video.c
字号:
(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(void){ 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(void){ return bitCount;}static voidStartTime(void){ stat_a[0].tottime = ReadSysClock();}static voidEndTime(void){ stat_a[0].tottime = ReadSysClock() - stat_a[0].tottime;}/*#endif*/double realTimeStart;doubleReadSysClock(void){ struct timeval tv; (void) gettimeofday(&tv, (struct timezone *)NULL); return (tv.tv_sec + tv.tv_usec / 1000000.0);}voidPrintTimeInfo(void){ double spent; spent = ReadSysClock() - realTimeStart; if (!quietFlag) { printf("\nReal Time Spent (After Initializations): %f secs.\n", spent); printf("Avg. Frames/Sec: %f\n", ((double) totNumFrames) / spent); }}#endif/* *-------------------------------------------------------------- * * 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(int bufLength){ int i, j; VidStream *new; static 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 (bufLength < 4) return NULL; /* Make buffer length multiple of 4. */ bufLength = (bufLength + 3) >> 2; /* Allocate memory for new structure. */ new = (VidStream *) mxCalloc(1,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[j][i] = default_intra_matrix[i * 8 + j]; } } /* 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; } else if (i >= 255) { cropTbl[i + MAX_NEG_CROP] = 255; } else { cropTbl[i + MAX_NEG_CROP] = i; } } /* Initialize non intra quantization matrix. */ for (i = 0; i < 8; i++) { for (j = 0; j < 8; j++) { new->non_intra_quant_matrix[j][i] = 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 *) mxCalloc(bufLength, sizeof(unsigned int)); /* * Set max_buf_length to one less than actual length to deal with messy * data without proper seq. end codes. */ new->max_buf_length = bufLength - 1; /* Initialize bitstream i/o fields. */ new->bit_offset = 0; new->buf_length = 0; new->buffer = new->buf_start; /* Return structure. */ return new;}/* *-------------------------------------------------------------- * * DestroyVidStream -- * * Deallocates a VidStream structure. * * Results: * None. * * Side effects: * None. * *-------------------------------------------------------------- */voidDestroyVidStream(VidStream *astream){ int i; if (astream->ext_data != NULL) mxFree(astream->ext_data); if (astream->user_data != NULL) mxFree(astream->user_data); if (astream->group.ext_data != NULL) mxFree(astream->group.ext_data); if (astream->group.user_data != NULL) mxFree(astream->group.user_data); if (astream->picture.extra_info != NULL) mxFree(astream->picture.extra_info); if (astream->picture.ext_data != NULL) mxFree(astream->picture.ext_data); if (astream->picture.user_data != NULL) mxFree(astream->picture.user_data); if (astream->slice.extra_info != NULL) mxFree(astream->slice.extra_info); if (astream->buf_start != NULL) mxFree(astream->buf_start); for (i = 0; i < RING_BUF_SIZE; i++) { if (astream->ring[i] != NULL) { DestroyPictImage(astream->ring[i]); astream->ring[i] = NULL; } } mxFree(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(unsigned int width, unsigned int height){ PictImage *new; /* Allocate memory space for new structure. */ new = (PictImage *) mxCalloc(1, sizeof(PictImage)); /* Allocate memory for image spaces. *//*#ifdef SH_MEM new->ximage = NULL; if (shmemFlag) { Visual *fc_visual; int depth; Visual *FindFullColorVisual(); if (ditherType == Twox2_DITHER) { new->ximage = XShmCreateImage(display, None, 8, ZPixmap, NULL, &(new->shminfo), width * 2, height * 2); } else if (ditherType == FULL_COLOR_DITHER) { fc_visual = FindFullColorVisual(display, &depth); new->ximage = XShmCreateImage(display, fc_visual, depth, ZPixmap, NULL, &(new->shminfo), width, height); } else if (ditherType == MONO_DITHER || ditherType == MONO_THRESHOLD) { new->ximage = XShmCreateImage(display, None, 1, XYBitmap, NULL, &(new->shminfo), width, height); } else { new->ximage = XShmCreateImage(display, None, 8, ZPixmap, NULL, &(new->shminfo), width, height); } * If no go, then revert to normal Xlib calls. * if (new->ximage == NULL) { shmemFlag = 0; if (!quietFlag) { fprintf(stderr, "Shared memory error, disabling.\n"); fprintf(stderr, "Ximage error.\n"); } goto shmemerror; } * Success here, continue. * new->shminfo.shmid = shmget(IPC_PRIVATE, (new->ximage->bytes_per_line * new->ximage->height), IPC_CREAT | 0777); if (new->shminfo.shmid < 0) { XDestroyImage(new->ximage); new->ximage = NULL; shmemFlag = 0; if (!quietFlag) { fprintf(stderr, "Shared memory error, disabling.\n"); fprintf(stderr, "Seg. id. error.\n"); } goto shmemerror; } new->shminfo.shmaddr = (char *) shmat(new->shminfo.shmid, 0, 0); if (new->shminfo.shmaddr == ((char *) -1)) { XDestroyImage(new->ximage); new->ximage = NULL; shmemFlag = 0; if (!quietFlag) { fprintf(stderr, "Shared memory error, disabling.\n"); fprintf(stderr, "Address error.\n"); } goto shmemerror; } new->ximage->data = new->shminfo.shmaddr; new->display = (unsigned char *) new->ximage->data; new->shminfo.readOnly = False; XShmAttach(display, &(new->shminfo)); XSync(display, False); if (gXErrorFlag) { * Ultimate failure here. * XDestroyImage(new->ximage); new->ximage = NULL; shmemFlag = 0; if (!quietFlag) { fprintf(stderr, "Shared memory error, disabling.\n"); } gXErrorFlag = 0; goto shmemerror; } else { shmctl(new->shminfo.shmid, IPC_RMID, 0); } if (!quietFlag) { fprintf(stderr, "Sharing memory.\n"); } } else#endif*/ {shmemerror: if ((ditherType == Twox2_DITHER) || (ditherType == FULL_COLOR_DITHER)) { new->display = (unsigned char *) mxCalloc(width * height * 4, sizeof(char)); } else { new->display = (unsigned char *) mxCalloc(width * height, sizeof(char)); } } new->luminance = (unsigned char *) mxCalloc(width * height, sizeof(char)); new->Cr = (unsigned char *) mxCalloc(width * height / 4, sizeof(char)); new->Cb = (unsigned char *) mxCalloc(width * height / 4, sizeof(char)); /* Reset locked flag. */ new->locked = 0; /* Return pointer to new structure. */ return new;}/* *-------------------------------------------------------------- * * DestroyPictImage -- * * Deallocates a PictImage structure. * * Results: * None. * * Side effects: * None. * *-------------------------------------------------------------- */voidDestroyPictImage(PictImage *apictimage){ if (apictimage->luminance != NULL) { mxFree(apictimage->luminance); } if (apictimage->Cr != NULL) { mxFree(apictimage->Cr); } if (apictimage->Cb != NULL) { mxFree(apictimage->Cb); }/*#ifdef SH_MEM if (apictimage->ximage != NULL) { XShmDetach(display, &(apictimage->shminfo)); XDestroyImage(apictimage->ximage); shmdt(apictimage->shminfo.shmaddr); apictimage->ximage = NULL; apictimage->display = NULL; }#endif*/ if (apictimage->display != NULL) { mxFree(apictimage->display); } mxFree(apictimage);}/* *-------------------------------------------------------------- * * mpegVidRsrc -- *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -