#include "vid.h" #include #include #include /*#include */ #include //#include "vidin.h" //#include "jd_time.h" /* Report errors */ void error_exit(void) { vlPerror("vidin"); exit(1); } VidInfo *vidInit() { VLControlValue val; /* Get a VidInfo structure */ VidInfo *info; info = (VidInfo *) malloc(sizeof(VidInfo)); /* Connect to the daemon */ if (!(info->svr = vlOpenVideo(""))) error_exit(); /* Set up a drain node in memory */ info->drn = vlGetNode(info->svr, VL_DRN, VL_MEM, VL_ANY); /* Set up a source node on any video source */ info->src = vlGetNode(info->svr, VL_SRC, VL_VIDEO, VL_ANY); /* Create a path using the first device that will support it */ info->path = vlCreatePath(info->svr, VL_ANY, info->src, info->drn); /* Set up the hardware for and define the usage of the path */ if ((vlSetupPaths(info->svr, (VLPathList)&info->path, 1, VL_SHARE, VL_SHARE)) < 0) error_exit(); /* Set the packing to RGB */ val.intVal = VL_PACKING_RGB_8; vlSetControl(info->svr, info->path, info->drn, VL_PACKING, &val); /* Set the video size */ val.xyVal.x = 640; val.xyVal.y = 480; vlSetControl(info->svr, info->path, info->drn, VL_SIZE, &val); /* Create a VLBuffer and begin transfer */ vidCreateBuffer(info); return info; } void vidQuit(VidInfo *info) { vidDeleteBuffer(info); vlDestroyPath(info->svr, info->path); vlCloseVideo(info->svr); } /*************************************************************************** * V I D I N L A T E S T ***************************************************************************/ char *vidInLatest(VidInfo *info, int *sequence) { VLInfoPtr vlinfo; vlinfo = vlGetLatestValid(info->svr, info->buffer); while (!vlinfo) { sginap(0); /* wait */ vlinfo = vlGetLatestValid(info->svr, info->buffer); } ; /* if required return sequence number */ if (sequence!=NULL) { *sequence = vlGetDMediaInfo(info->svr, info->buffer, vlinfo)->sequence; } /* Free up a previous buffer, vidCreateBuffer uses one */ /* up so that it is safe to do this. By freeing one here */ /* we save the user of this routine from calling vlPutFree() */ vlPutFree(info->svr, info->buffer); /* Get a pointer to the frame */ return (char *)vlGetActiveRegion(info->svr, info->buffer, vlinfo); } /*************************************************************************** * V I D I N ***************************************************************************/ char *vidIn(VidInfo *info, int *sequence) { VLInfoPtr vlinfo; vlinfo = vlGetNextValid(info->svr, info->buffer); while (!vlinfo) { sginap(0); /* wait */ vlinfo = vlGetNextValid(info->svr, info->buffer); } ; /* if required return sequence number */ if (sequence!=NULL) { *sequence = vlGetDMediaInfo(info->svr, info->buffer, vlinfo)->sequence; } /* Free up a previous buffer, vidCreateBuffer uses one */ /* up so that it is safe to do this. By freeing one here */ /* we save the user of this routine from calling vlPutFree() */ vlPutFree(info->svr, info->buffer); /* Get a pointer to the frame */ return (char *)vlGetActiveRegion(info->svr, info->buffer, vlinfo); } int vidBuffersPending(VidInfo *info) { VLInfoPtr vlinfo; int count=0; vlinfo = vlGetNextValid(info->svr, info->buffer); while (vlinfo) { count++; vlPutFree(info->svr, info->buffer); vlinfo = vlGetNextValid(info->svr, info->buffer); } ; return count; } void vidSetCapType(VidInfo *info, int captype) { VLControlValue val; val.intVal=captype; vidDeleteBuffer(info); vlSetControl(info->svr, info->path, info->drn, VL_CAP_TYPE, &val); vidCreateBuffer(info); } void vidSetPacking(VidInfo *info, int packing) { VLControlValue val; val.intVal=packing; vidDeleteBuffer(info); vlSetControl(info->svr, info->path, info->drn, VL_PACKING, &val); vidCreateBuffer(info); } void vidSetZoom(VidInfo *info, int num, int den) { VLControlValue val; val.fractVal.numerator=num; val.fractVal.denominator=den; vidDeleteBuffer(info); vlSetControl(info->svr, info->path, info->drn, VL_ZOOM, &val); vidCreateBuffer(info); } void vidSetRate(VidInfo *info, int rate) { VLControlValue val; val.fractVal.numerator=rate; val.fractVal.denominator=1; vidDeleteBuffer(info); vlSetControl(info->svr, info->path, info->drn, VL_RATE, &val); vidCreateBuffer(info); } void vidGetXYSize(VidInfo *info, long *x, long *y) { VLControlValue val; /* Get the video size */ vlGetControl(info->svr, info->path, info->drn, VL_SIZE, &val); *x = val.xyVal.x; *y = val.xyVal.y; } void vidSetXYSize(VidInfo *info, int x, int y) { VLControlValue val; /* delete old buffer since we are changing size */ vidDeleteBuffer(info); /* Set the video size */ val.xyVal.x = x; val.xyVal.y = y; vlSetControl(info->svr, info->path, info->drn, VL_SIZE, &val); /* Create a new buffer */ vidCreateBuffer(info); } void vidDeleteBuffer(VidInfo *info) { /* End the data transfer */ vlEndTransfer(info->svr, info->path); /* Deregister and deallocate old buffer */ vlDeregisterBuffer(info->svr, info->path, info->drn, info->buffer); vlDestroyBuffer(info->svr, info->buffer); } void vidCreateBuffer(VidInfo *info) { VLInfoPtr vlinfo; /* Create and register a buffer for 1 frame */ info->buffer = vlCreateBuffer(info->svr, info->path, info->drn, 5); if (info->buffer == NULL) error_exit(); vlRegisterBuffer(info->svr, info->path, info->drn, info->buffer); /* Begin the data transfer */ if (vlBeginTransfer(info->svr, info->path, 0, NULL)) error_exit(); /* Get one frame, and then dont release */ vlinfo = vlGetNextValid(info->svr, info->buffer); while (!vlinfo) { sginap(1); /* wait */ vlinfo = vlGetNextValid(info->svr, info->buffer); } ; }