/* * Copyright (c) 1997 by * PARALLAX GRAPHICS, INCORPORATED, Santa Clara, California. * All rights reserved * * This software is furnished on an as-is basis, and may be used and copied * only with the inclusion of the above copyright notice. * * The information in this software is subject to change without notice. * No committment is made as to the usability or reliability of this * software. * * Parallax Graphics, Inc. * 2500 Condensa Street * Santa Clara, California 95051 * Author: Scott Schmitz * * Adapted from SUN makemovie, not saving anything */ /* Program: jpegtime Usage: jpegtime [options] [options]: -wWidth (in pixels) Height is automatic -qQfactor [25-1000] 25 = 20:1 compression Example: jpegtime -w320 -q50 This will record at with a width of 320 pixels (height is automatic) at about a 45:1 compression Description: This program allows the user to "rate" their system, experimenting with different capture sizes and compression ratios to determine the frames per second and the capture bandwidth available at each level. */ #include #include #include #include #include #include #include #include #include #include #include /* required for gettimeofday */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* function prototypes */ void print_help(void); void FindRate(int); struct timeval later, now; main(argc,argv) int argc; char **argv; { int depth; Display *disp; Window win; int screen, width=640, height=480, i=1; int winMask; /* Window attribute mask. */ XPlxCImage *cImage; GC gc; static unsigned char *qTable; /* Q Table to load to CCube chip */ static int qTableSize; /* Size of Q Table. */ XVisualInfo *vInfo; XSetWindowAttributes attr; static int mask=ExposureMask; /* Window event mask. */ XEvent winEvent; plx_signal *plxSignal=NULL; /* Video signal structure. */ int playbackRate=20; /* Movie playback rate, default to 20 fps, */ /* this is conservative. */ int QFactor=50; int end = 30; /* Number of frames to capture. */ int seconds = 10; /* Default to 10 seconds of recording */ long int us_per_frame; /* micro seconds per frame */ long int ms_per_frame; int frame = 0; char *window_name="fastgrab"; XTextProperty windowname; int nextFrameTime; int thisFrameTime; int framesizing; if (argc<1) /* Forgot to specify a filename? */ { /* Print help message */ print_help(); exit(1); } i = 1; while(i < argc && argv[i][0] == '-') /* Decode option list (options begin with */ /* a '-' */ { switch(argv[i][1]) { case 'w': /* set the width (height is automatic) */ { width = atoi(argv[i]+2); height = (int)((double)(480.0/640.0) * (double) width); printf("width = %d, height = %d (pixels).\n", width, height); } /* end of case 'w' */ break; case 'q': /* set the qfactor */ { QFactor = atoi(argv[i]+2); if(QFactor < 25 || QFactor > 1000) { QFactor = 50; printf("qfactor must be between 25 and 1000. "); } printf("qfactor = %d\n", QFactor); } /* end of case 'q' */ break; } /* end of switch statement */ i++; /* increment the argument pointer */ } /* end of while */ us_per_frame = (long int)((1.0 / (float)playbackRate) * 1000000); ms_per_frame = us_per_frame / 1000; disp=XOpenDisplay(getenv("DISPLAY")); screen=(int)XDefaultScreen(disp); vInfo = XPlxGetVideoVisual(screen, disp); /* Try to get a visual appropriate for showing live video */ depth = vInfo->depth; winMask=CWBackPixel|CWColormap|CWBorderPixel; /* Setup window attribute mask. */ attr.colormap=XCreateColormap(disp, /* Create colormap according to visual. */ XRootWindow(disp,screen), vInfo->visual,AllocNone); attr.background_pixel=BlackPixel(disp,screen); /* Set background color to black. */ attr.border_pixel=WhitePixel(disp,screen); /* Set boarder color to white. */ win=XCreateWindow(disp,RootWindow(disp,screen), /* Create window for frame grab. */ 0,0,width,height,0,depth,InputOutput, /* Window size is set to 640 x 480. */ vInfo->visual,winMask,&attr); XStringListToTextProperty(&window_name, 1, &windowname); XSetWMProperties(disp, win, &windowname, &windowname, argv, argc, NULL, NULL, NULL); gc=XCreateGC(disp, win, 0, 0); /* Create window gc. */ qTableSize=MakeQTables(QFactor, &qTable); /* Create Q Table according to QFactor. */ XPlxPutTable(disp,win,gc,(char*)qTable,qTableSize,0); /* Load QTable to chip for compression. */ XPlxVideoInputSelect(disp,win,gc, PLX_INPUT_0, PLX_NTSC, PLX_COMP, /* NTSC */ /* PLX_INPUT_0, PLX_PAL, PLX_COMP, /* PAL */ PLX_RGB24); /* Select video input type & channel. */ plxSignal=(plx_signal*)XPlxQueryVideo(disp, /* Detect for video signal at input. */ win,gc); while (!plxSignal->sync_ok) { printf("Sync Absent - Hook up an input source\n"); XPlxSleep(500000); plxSignal=(plx_signal*)XPlxQueryVideo(disp, win, gc); } XPlxVideoTag(disp,win,gc,PLX_VIDEO); /* Setup up window tag to display video */ XSelectInput(disp,win,mask); /* Setup up window event mask. */ XMapWindow(disp,win); /* Map window to display. */ XNextEvent(disp,&winEvent); XPlxVideoSqueezeLive(disp,win,gc,0,plxSignal->b, 640, 480, 0,0,width,height); /* Display live video. NTSC */ /* 768, 575, 0,0,width,height); /* Display live video. PAL */ gettimeofday(&now, NULL); while(1) { cImage=XPlxGetCImage(disp,win, gc,0,0, width, height, width, height); /* Grab and compress image from window. */ frame++; framesizing += cImage->size; if(frame % 100 == 0) /* calculate rate every 100 frames */ { FindRate(framesizing); framesizing = 0; /* reset size for next calculation */ } /* insert your processing code here */ XPlxDestroyCImage(cImage); /* free up storage */ } } void print_help(void) { printf("usage: jpegtime [-options]\n"); printf(" -options:\n"); printf(" -qQfactor\n"); printf(" -wWidth (Height is automatic)\n"); return; } void FindRate(int sizes) { char buf[32]; float d,e; int i,j; float bps; gettimeofday(&later,NULL); i = later.tv_sec * 1000000 + later.tv_usec; j = now.tv_sec * 1000000 + now.tv_usec; i = i - j; e = ((float) i) / 100.0; d = 1000000.0 / e; printf("Captured %d bytes in %1.1f seconds\n",sizes,(float)i/1000000); bps = ((sizes * 8) / ((float)i)); printf("Current Rate : %1.1f fps bandwidth = %1.4f Mbits/sec\n", d,bps); gettimeofday(&now,NULL); }