bool AndroidVideoSource::open() { ARController::logv("Opening Android Video Source."); if (deviceState != DEVICE_CLOSED) { ARController::logv("Error: device is already open."); return false; } // On Android, ARVideo doesn't actually provide the frames, but it is needed to handle // fetching of the camera parameters. Note that if the current working directory // isn't already the directory where the camera parametere cache should be created, // then the videoconfiguration should include the option 'cachedir="/path/to/cache"'. gVid = ar2VideoOpen(videoConfiguration); if (!gVid) { ARController::logv("arVideoOpen unable to open connection to camera."); return false; } //ARController::logv("Opened connection to camera."); pixelFormat = ar2VideoGetPixelFormat(gVid); if (pixelFormat == AR_PIXEL_FORMAT_INVALID) { ARController::logv("AndroidVideoSource::getVideoReadyAndroid: Error: No pixel format set.\n"); goto bail; } deviceState = DEVICE_OPEN; return true; bail: ar2VideoClose(gVid); gVid = NULL; return false; }
int arVideoOpen( char *config ) { if( vid != NULL ) { printf("Device has been opened!!\n"); return -1; } vid = ar2VideoOpen( config ); if( vid == NULL ) return -1; return 0; }
static int setupMovie(const char *path) { char *movieVconf; int len; int xsize, ysize; AR_PIXEL_FORMAT pixFormat; // Construct the vconf string. arMalloc(movieVconf, char, 2048); // 2Kb for URL. sprintf(movieVconf, "-device=QUICKTIME -movie=\""); // Make sure we're using the QuickTime video input. len = (int)strlen(movieVconf); strncat(movieVconf + len, path, 2048 - len - 1); len = (int)strlen(movieVconf); strncat(movieVconf + len, "\" -loop -pause", 2048 - len - 1); // Start the movie paused. It will be unpaused in mainLoop(). // Open the movie. gMovieVideo = ar2VideoOpen(movieVconf); free(movieVconf); if (!gMovieVideo) { ARLOGe("setupMovie(): Unable to open movie.\n"); return (FALSE); } // Find the size of the movie. if (ar2VideoGetSize(gMovieVideo, &xsize, &ysize) < 0) return (FALSE); // Get the pixel format of the movie. pixFormat = ar2VideoGetPixelFormat(gMovieVideo); if (pixFormat == AR_PIXEL_FORMAT_INVALID) { ARLOGe("setupMovie(): Movie is using unsupported pixel format.\n"); return (FALSE); } // Set up an ARParam object for the movie input. arParamClear(&gMovieCparam, xsize, ysize, AR_DIST_FUNCTION_VERSION_DEFAULT); // For convenience, we will use gsub_lite to draw the actual pixels. Set it up now. gMovieArglSettings = arglSetupForCurrentContext(&gMovieCparam, pixFormat); arglDistortionCompensationSet(gMovieArglSettings, 0); return (TRUE); }
bool ARToolKitVideoSource::open() { ARController::logv(AR_LOG_LEVEL_INFO, "Opening ARToolKit video using configuration '%s'.", videoConfiguration); if (deviceState != DEVICE_CLOSED) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrapper::ARToolKitVideoSource::open(): error: device is already open, exiting returning false"); return false; } // Open the video path if (!(gVid = ar2VideoOpenAsync(videoConfiguration, openCallback, (void *)this))) { if (!(gVid = ar2VideoOpen(videoConfiguration))) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrapper::ARToolKitVideoSource::open(): arVideoOpen unable to open connection to camera using configuration '%s', exiting returning false", videoConfiguration); return false; } deviceState = DEVICE_OPEN; return this->open2(); } deviceState = DEVICE_OPEN; return true; }
JNIEXPORT jboolean JNICALL JNIFUNCTION_NATIVE(nativeStart(JNIEnv * env, jobject object)) { LOGD("nativeStart\n"); g_Vid = ar2VideoOpen(""); if (!g_Vid) { LOGE("Error: ar2VideoOpen.\n"); return (false); } // Since most NFT init can't be completed until the video frame size is known, // and NFT surface loading depends on NFT init, all that will be deferred. // Also, VirtualEnvironment init depends on having an OpenGL context, and so that also // forces us to defer VirtualEnvironment init. // ARGL init depends on both these things, which forces us to defer it until the // main frame loop. return (true); }
int CWebCam::SetupWebCam(const char *cparam_names, char *vconfs) { int xsize, ysize; ARParam wparam; if((ARTVideo = ar2VideoOpen(vconfs)) == 0) return(0); if(ar2VideoInqSize(ARTVideo, &xsize, &ysize) < 0) return(0); if(arParamLoad(cparam_names, 1, &wparam) < 0) return(0); arParamChangeSize(&wparam, xsize, ysize, &ARTCparam); arInitCparam(&ARTCparam); arParamDisp(&ARTCparam); ARTThreshhold = 100; arglCameraFrustumRH(&ARTCparam, VIEW_DISTANCE_MIN, VIEW_DISTANCE_MAX, projectionMat); if(ar2VideoCapStart(ARTVideo) != 0) return(0); ar2VideoCapNext(ARTVideo); return(1); }
static void init(int argc, char *argv[]) { char *vconfL = NULL; char *vconfR = NULL; char *cparaL = NULL; char *cparaR = NULL; char cparaLDefault[] = "Data/cparaL.dat"; char cparaRDefault[] = "Data/cparaR.dat"; ARParam wparam; ARGViewport viewport; int i, j; int gotTwoPartOption; int screenWidth, screenHeight, screenMargin; double wscalef, hscalef, scalef; chessboardCornerNumX = 0; chessboardCornerNumY = 0; calibImageNum = 0; patternWidth = 0.0f; i = 1; // argv[0] is name of app, so start at 1. while (i < argc) { gotTwoPartOption = FALSE; // Look for two-part options first. if ((i + 1) < argc) { if (strcmp(argv[i], "--vconfL") == 0) { i++; vconfL = argv[i]; gotTwoPartOption = TRUE; } else if (strcmp(argv[i], "--vconfR") == 0) { i++; vconfR = argv[i]; gotTwoPartOption = TRUE; } else if (strcmp(argv[i], "--cparaL") == 0) { i++; cparaL = argv[i]; gotTwoPartOption = TRUE; } else if (strcmp(argv[i], "--cparaR") == 0) { i++; cparaR = argv[i]; gotTwoPartOption = TRUE; } } if (!gotTwoPartOption) { // Look for single-part options. if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-help") == 0 || strcmp(argv[i], "-h") == 0) { usage(argv[0]); } else if (strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-version") == 0 || strcmp(argv[i], "-v") == 0) { ARLOG("%s version %s\n", argv[0], AR_HEADER_VERSION_STRING); exit(0); } else if( strncmp(argv[i], "-cornerx=", 9) == 0 ) { if( sscanf(&(argv[i][9]), "%d", &chessboardCornerNumX) != 1 ) usage(argv[0]); if( chessboardCornerNumX <= 0 ) usage(argv[0]); } else if( strncmp(argv[i], "-cornery=", 9) == 0 ) { if( sscanf(&(argv[i][9]), "%d", &chessboardCornerNumY) != 1 ) usage(argv[0]); if( chessboardCornerNumY <= 0 ) usage(argv[0]); } else if( strncmp(argv[i], "-imagenum=", 10) == 0 ) { if( sscanf(&(argv[i][10]), "%d", &calibImageNum) != 1 ) usage(argv[0]); if( calibImageNum <= 0 ) usage(argv[0]); } else if( strncmp(argv[i], "-pattwidth=", 11) == 0 ) { if( sscanf(&(argv[i][11]), "%f", &patternWidth) != 1 ) usage(argv[0]); if( patternWidth <= 0 ) usage(argv[0]); } else if( strncmp(argv[i], "-cparaL=", 8) == 0 ) { cparaL = &(argv[i][8]); } else if( strncmp(argv[i], "-cparaR=", 8) == 0 ) { cparaR = &(argv[i][8]); } else { ARLOGe("Error: invalid command line argument '%s'.\n", argv[i]); usage(argv[0]); } } i++; } if( chessboardCornerNumX == 0 ) chessboardCornerNumX = CHESSBOARD_CORNER_NUM_X; if( chessboardCornerNumY == 0 ) chessboardCornerNumY = CHESSBOARD_CORNER_NUM_Y; if( calibImageNum == 0 ) calibImageNum = CALIB_IMAGE_NUM; if( patternWidth == 0.0f ) patternWidth = (float)CHESSBOARD_PATTERN_WIDTH; if (!cparaL) cparaL = cparaLDefault; if (!cparaR) cparaR = cparaRDefault; ARLOG("CHESSBOARD_CORNER_NUM_X = %d\n", chessboardCornerNumX); ARLOG("CHESSBOARD_CORNER_NUM_Y = %d\n", chessboardCornerNumY); ARLOG("CHESSBOARD_PATTERN_WIDTH = %f\n", patternWidth); ARLOG("CALIB_IMAGE_NUM = %d\n", calibImageNum); ARLOG("Video parameter Left : %s\n", vconfL); ARLOG("Video parameter Right: %s\n", vconfR); ARLOG("Camera parameter Left : %s\n", cparaL); ARLOG("Camera parameter Right: %s\n", cparaR); if( (vidL=ar2VideoOpen(vconfL)) == NULL ) { ARLOGe("Cannot found the first camera.\n"); exit(0); } if( (vidR=ar2VideoOpen(vconfR)) == NULL ) { ARLOGe("Cannot found the second camera.\n"); exit(0); } if( ar2VideoGetSize(vidL, &xsizeL, &ysizeL) < 0 ) exit(0); if( ar2VideoGetSize(vidR, &xsizeR, &ysizeR) < 0 ) exit(0); if( (pixFormatL=ar2VideoGetPixelFormat(vidL)) < 0 ) exit(0); if( (pixFormatR=ar2VideoGetPixelFormat(vidR)) < 0 ) exit(0); ARLOG("Image size for the left camera = (%d,%d)\n", xsizeL, ysizeL); ARLOG("Image size for the right camera = (%d,%d)\n", xsizeR, ysizeR); if( arParamLoad(cparaL, 1, &wparam) < 0 ) { ARLOGe("Camera parameter load error !! %s\n", cparaL); exit(0); } arParamChangeSize( &wparam, xsizeL, ysizeL, ¶mL ); ARLOG("*** Camera Parameter for the left camera ***\n"); arParamDisp( ¶mL ); if( arParamLoad(cparaR, 1, &wparam) < 0 ) { ARLOGe("Camera parameter load error !! %s\n", cparaR); exit(0); } arParamChangeSize( &wparam, xsizeR, ysizeR, ¶mR ); ARLOG("*** Camera Parameter for the right camera ***\n"); arParamDisp( ¶mR ); screenWidth = glutGet(GLUT_SCREEN_WIDTH); screenHeight = glutGet(GLUT_SCREEN_HEIGHT); if (screenWidth > 0 && screenHeight > 0) { screenMargin = (int)(MAX(screenWidth, screenHeight) * SCREEN_SIZE_MARGIN); if ((screenWidth - screenMargin) < (xsizeL + xsizeR) || (screenHeight - screenMargin) < MAX(ysizeL, ysizeR)) { wscalef = (double)(screenWidth - screenMargin) / (double)(xsizeL + xsizeR); hscalef = (double)(screenHeight - screenMargin) / (double)MAX(ysizeL, ysizeR); scalef = MIN(wscalef, hscalef); ARLOG("Scaling %dx%d window by %0.3f to fit onto %dx%d screen (with %2.0f%% margin).\n", xsizeL + xsizeR, MAX(ysizeL, ysizeR), scalef, screenWidth, screenHeight, SCREEN_SIZE_MARGIN*100.0); } else { scalef = 1.0; } } else { scalef = 1.0; } /* open the graphics window */ if( argCreateWindow((int)((xsizeL + xsizeR)*scalef), (int)(MAX(ysizeL, ysizeR)*scalef)) < 0 ) { ARLOGe("Error: argCreateWindow.\n"); exit(0); } viewport.sx = 0; viewport.sy = 0; viewport.xsize = (int)(xsizeL*scalef); viewport.ysize = (int)(ysizeL*scalef); if( (vpL=argCreateViewport(&viewport)) == NULL ) { ARLOGe("Error: argCreateViewport.\n"); exit(0); } viewport.sx = (int)(xsizeL*scalef); viewport.sy = 0; viewport.xsize = (int)(xsizeR*scalef); viewport.ysize = (int)(ysizeR*scalef); if( (vpR=argCreateViewport(&viewport)) == NULL ) { ARLOGe("Error: argCreateViewport.\n"); exit(0); } argViewportSetPixFormat( vpL, pixFormatL ); argViewportSetPixFormat( vpR, pixFormatR ); argViewportSetCparam( vpL, ¶mL ); argViewportSetCparam( vpR, ¶mR ); argViewportSetDispMethod( vpL, AR_GL_DISP_METHOD_TEXTURE_MAPPING_FRAME ); argViewportSetDispMethod( vpR, AR_GL_DISP_METHOD_TEXTURE_MAPPING_FRAME ); argViewportSetDispMode(vpL, AR_GL_DISP_MODE_FIT_TO_VIEWPORT_KEEP_ASPECT_RATIO); argViewportSetDispMode(vpR, AR_GL_DISP_MODE_FIT_TO_VIEWPORT_KEEP_ASPECT_RATIO); calibImageL = cvCreateImage( cvSize(xsizeL, ysizeL), IPL_DEPTH_8U, 1); calibImageR = cvCreateImage( cvSize(xsizeR, ysizeR), IPL_DEPTH_8U, 1); arMalloc(cornersL, CvPoint2D32f, chessboardCornerNumX*chessboardCornerNumY); arMalloc(cornersR, CvPoint2D32f, chessboardCornerNumX*chessboardCornerNumY); arMalloc(worldCoord, ICP3DCoordT, chessboardCornerNumX*chessboardCornerNumY); for( i = 0; i < chessboardCornerNumX; i++ ) { for( j = 0; j < chessboardCornerNumY; j++ ) { worldCoord[i*chessboardCornerNumY+j].x = patternWidth*i; worldCoord[i*chessboardCornerNumY+j].y = patternWidth*j; worldCoord[i*chessboardCornerNumY+j].z = 0.0; } } arMalloc(calibData, ICPCalibDataT, calibImageNum); for( i = 0; i < calibImageNum; i++ ) { arMalloc(calibData[i].screenCoordL, ICP2DCoordT, chessboardCornerNumX*chessboardCornerNumY); arMalloc(calibData[i].screenCoordR, ICP2DCoordT, chessboardCornerNumX*chessboardCornerNumY); calibData[i].worldCoordL = worldCoord; calibData[i].worldCoordR = worldCoord; calibData[i].numL = chessboardCornerNumX*chessboardCornerNumY; calibData[i].numR = chessboardCornerNumX*chessboardCornerNumY; } return; }
bool ARToolKitVideoSource::open() { ARController::logv(AR_LOG_LEVEL_DEBUG, "ARWrap::ARToolKitVideoSource::open(): called, opening ARToolKit video"); if (deviceState != DEVICE_CLOSED) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): error: device is already open, exiting returning false"); return false; } // Open the video path gVid = ar2VideoOpen(videoConfiguration); if (!gVid) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): arVideoOpen unable to open connection to camera using configuration '%s', exiting returning false", videoConfiguration); return false; } ARController::logv(AR_LOG_LEVEL_DEBUG, "ARWrap::ARToolKitVideoSource::open(): Opened connection to camera using configuration '%s'", videoConfiguration); deviceState = DEVICE_OPEN; // Find the size of the video if (ar2VideoGetSize(gVid, &videoWidth, &videoHeight) < 0) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): Error: unable to get video size, calling close(), exiting returning false"); this->close(); return false; } // Get the format in which the camera is returning pixels pixelFormat = ar2VideoGetPixelFormat(gVid); if (pixelFormat < 0 ) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): Error: unable to get pixel format, calling close(), exiting returning false"); this->close(); return false; } ARController::logv(AR_LOG_LEVEL_DEBUG, "ARWrap::ARToolKitVideoSource::open(): Video %dx%d@%dBpp (%s)", videoWidth, videoHeight, arUtilGetPixelSize(pixelFormat), arUtilGetPixelFormatName(pixelFormat)); #ifndef _WINRT // Translate pixel format into OpenGL texture intformat, format, and type. switch (pixelFormat) { case AR_PIXEL_FORMAT_RGBA: glPixIntFormat = GL_RGBA; glPixFormat = GL_RGBA; glPixType = GL_UNSIGNED_BYTE; break; case AR_PIXEL_FORMAT_RGB: glPixIntFormat = GL_RGB; glPixFormat = GL_RGB; glPixType = GL_UNSIGNED_BYTE; break; case AR_PIXEL_FORMAT_BGRA: glPixIntFormat = GL_RGBA; glPixFormat = GL_BGRA; glPixType = GL_UNSIGNED_BYTE; break; case AR_PIXEL_FORMAT_ABGR: glPixIntFormat = GL_RGBA; glPixFormat = GL_ABGR_EXT; glPixType = GL_UNSIGNED_BYTE; break; case AR_PIXEL_FORMAT_ARGB: glPixIntFormat = GL_RGBA; glPixFormat = GL_BGRA; #ifdef AR_BIG_ENDIAN glPixType = GL_UNSIGNED_INT_8_8_8_8_REV; #else glPixType = GL_UNSIGNED_INT_8_8_8_8; #endif break; case AR_PIXEL_FORMAT_BGR: glPixIntFormat = GL_RGB; glPixFormat = GL_BGR; glPixType = GL_UNSIGNED_BYTE; break; case AR_PIXEL_FORMAT_MONO: case AR_PIXEL_FORMAT_420v: case AR_PIXEL_FORMAT_420f: case AR_PIXEL_FORMAT_NV21: glPixIntFormat = GL_LUMINANCE; glPixFormat = GL_LUMINANCE; glPixType = GL_UNSIGNED_BYTE; break; case AR_PIXEL_FORMAT_RGB_565: glPixIntFormat = GL_RGB; glPixFormat = GL_RGB; glPixType = GL_UNSIGNED_SHORT_5_6_5; break; case AR_PIXEL_FORMAT_RGBA_5551: glPixIntFormat = GL_RGBA; glPixFormat = GL_RGBA; glPixType = GL_UNSIGNED_SHORT_5_5_5_1; break; case AR_PIXEL_FORMAT_RGBA_4444: glPixIntFormat = GL_RGBA; glPixFormat = GL_RGBA; glPixType = GL_UNSIGNED_SHORT_4_4_4_4; break; default: ARController::logv("Error: Unsupported pixel format.\n"); this->close(); return false; break; } #endif // !_WINRT #if TARGET_PLATFORM_IOS // Tell arVideo what the typical focal distance will be. Note that this does NOT // change the actual focus, but on devices with non-fixed focus, it lets arVideo // choose a better set of camera parameters. ar2VideoSetParami(gVid, AR_VIDEO_PARAM_IOS_FOCUS, AR_VIDEO_IOS_FOCUS_0_3M); // Default is 0.3 metres. See <AR/sys/videoiPhone.h> for allowable values. #endif // Load the camera parameters, resize for the window and init. ARParam cparam; // Prefer internal camera parameters. if (ar2VideoGetCParam(gVid, &cparam) == 0) { ARController::logv(AR_LOG_LEVEL_DEBUG, "ARWrap::ARToolKitVideoSource::open(): Using internal camera parameters."); } else { const char cparam_name_default[] = "camera_para.dat"; // Default name for the camera parameters. if (cameraParamBuffer) { if (arParamLoadFromBuffer(cameraParamBuffer, cameraParamBufferLen, &cparam) < 0) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): error-failed to load camera parameters from buffer, calling close(), exiting returning false"); this->close(); return false; } else { ARController::logv(AR_LOG_LEVEL_DEBUG, "ARWrap::ARToolKitVideoSource::open(): Camera parameters loaded from buffer"); } } else { if (arParamLoad((cameraParam ? cameraParam : cparam_name_default), 1, &cparam) < 0) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): error-failed to load camera parameters %s, calling close(), exiting returning false", (cameraParam ? cameraParam : cparam_name_default)); this->close(); return false; } else { ARController::logv(AR_LOG_LEVEL_DEBUG, "ARWrap::ARToolKitVideoSource::open():Camera parameters loaded from %s", (cameraParam ? cameraParam : cparam_name_default)); } } } if (cparam.xsize != videoWidth || cparam.ysize != videoHeight) { #ifdef DEBUG ARController::logv(AR_LOG_LEVEL_ERROR, "*** Camera Parameter resized from %d, %d. ***\n", cparam.xsize, cparam.ysize); #endif arParamChangeSize(&cparam, videoWidth, videoHeight, &cparam); } if (!(cparamLT = arParamLTCreate(&cparam, AR_PARAM_LT_DEFAULT_OFFSET))) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): error-failed to create camera parameters lookup table, calling close(), exiting returning false"); this->close(); return false; } int err = ar2VideoCapStart(gVid); if (err != 0) { if (err == -2) { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): error starting video-device unavailable \"%d,\" setting ARW_ERROR_DEVICE_UNAVAILABLE error state", err); setError(ARW_ERROR_DEVICE_UNAVAILABLE); } else { ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): error \"%d\" starting video capture", err); } ARController::logv(AR_LOG_LEVEL_ERROR, "ARWrap::ARToolKitVideoSource::open(): calling close(), exiting returning false"); this->close(); return false; } deviceState = DEVICE_RUNNING; ARController::logv(AR_LOG_LEVEL_DEBUG, "ARWrap::ARToolKitVideoSource::open(): exiting returning true, deviceState = DEVICE_RUNNING, video capture started"); return true; }
/* CHECKED TODO * PsychAROpenVideoCaptureDevice() -- Create a video capture object. * * This function tries to open and initialize a connection to a camera * and returns the associated captureHandle for it. * * slotid = Number of slot in vidcapRecordBANK[] array to use for this camera. * win = Pointer to window record of associated onscreen window. * deviceIndex = Index of the grabber device. (Currently ignored) * capturehandle = handle to the new capture object. * capturerectangle = If non-NULL a ptr to a PsychRectangle which contains the ROI for capture. * reqdepth = Number of layers for captured output textures. (0=Don't care, 1=LUMINANCE8, 2=LUMINANCE8_ALPHA8, 3=RGB8, 4=RGBA8) * num_dmabuffers = Number of buffers in the ringbuffer queue (e.g., DMA buffers) - This is OS specific. Zero = Don't care. * allow_lowperf_fallback = If set to 1 then PTB can use a slower, low-performance fallback path to get nasty devices working. * targetmoviefilename and recordingflags are currently ignored, they would refer to video harddics recording capabilities. */ psych_bool PsychAROpenVideoCaptureDevice(int slotid, PsychWindowRecordType *win, int deviceIndex, int* capturehandle, double* capturerectangle, int reqdepth, int num_dmabuffers, int allow_lowperf_fallback, char* targetmoviefilename, unsigned int recordingflags) { PsychVidcapRecordType *capdev = NULL; int w, h; char msgerr[10000]; char config[1000]; char tmpstr[1000]; config[0] = 0; tmpstr[0] = 0; // Default camera config: #if PSYCH_SYSTEM == PSYCH_WINDOWS //strcat(config, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><dsvl_input><camera show_format_dialog=\"false\" friendly_name=\"\"><pixel_format><RGB32 flip_h=\"false\" flip_v=\"true\"/></pixel_format></camera></dsvl_input>"); // Prefix: strcat(config, "<?xml version=\"1.0\" encoding=\"UTF-8\"?><dsvl_input><camera show_format_dialog=\"false\" "); // Specific deviceIndex requested, instead of auto-select? if (deviceIndex >= 1 && deviceIndex <= 3) { // Fetch optional moviename parameter as name spec string: if (targetmoviefilename == NULL) PsychErrorExitMsg(PsychError_user, "You set 'deviceIndex' to a value of 1, 2 or 3, but didn't provide the required device name string in the 'moviename' argument! Aborted."); switch(deviceIndex) { case 1: sprintf(tmpstr, "friendly_name=\"%s\" ", targetmoviefilename); break; case 2: sprintf(tmpstr, "device_name=\"%s\" ", targetmoviefilename); break; case 3: sprintf(tmpstr, "ieee1394id=\"%s\" ", targetmoviefilename); break; } strcat(config, tmpstr); } else { // Default device index: Just pass through as default device: strcat(config, "friendly_name=\"\" "); } #endif #if PSYCH_SYSTEM == PSYCH_OSX char *defaultcamconfig = ""; #endif #if PSYCH_SYSTEM == PSYCH_LINUX char *defaultcamconfig = "-dev=/dev/video0 -channel=0 -palette=YUV420P -width=320 -height=240"; #endif // Init capturehandle to none: *capturehandle = -1; if (firsttime) { // First time invocation: #if PSYCH_SYSTEM == PSYCH_WINDOWS // On Windows, we need to delay-load the libARvideo.dll DLL. This loading // and linking will automatically happen downstream. However, if delay loading // would fail, we would end up with a crash! For that reason, we try here to // load the DLL, just to probe if the real load/link/bind op later on will // likely succeed. If the following LoadLibrary() call fails and returns NULL, // then we know we would end up crashing. Therefore we'll output some helpful // error-message instead: if (NULL == LoadLibrary("libARvideo.dll")) { // Failed: printf("\n\nPTB-ERROR: Tried to startup video capture engine type 2 (ARVideo). This didn't work,\n"); printf("PTB-ERROR: because one of the required helper DLL libraries failed to load. Probably because they\n"); printf("PTB-ERROR: could not be found or could not be accessed (e.g., due to permission problems).\n\n"); printf("PTB-ERROR: Please read the online help by typing 'help ARVideoCapture' for troubleshooting instructions.\n\n"); PsychErrorExitMsg(PsychError_user, "Unable to start Videocapture engine ARVideo due to DLL loading problems. Aborted."); } #endif firsttime = FALSE; } // Slot 'slotid' will contain the record for our new capture object: // Initialize new record: vidcapRecordBANK[slotid].valid = 1; // Retrieve device record for slotid: capdev = PsychGetARVidcapRecord(slotid); capdev->camera = NULL; capdev->grabber_active = 0; capdev->scratchbuffer = NULL; // ROI rectangle specified? if (capturerectangle) { // Extract wanted width and height: w = (int) PsychGetWidthFromRect(capturerectangle); h = (int) PsychGetHeightFromRect(capturerectangle); #if PSYCH_SYSTEM == PSYCH_OSX sprintf(tmpstr, " -width=%i -height=%i", w, h); #endif #if PSYCH_SYSTEM == PSYCH_WINDOWS sprintf(tmpstr, " frame_width=\"%i\" frame_height=\"%i\" ", w, h); #endif #if PSYCH_SYSTEM == PSYCH_LINUX // TODO #endif strcat(config, tmpstr); } if (num_dmabuffers > 0) { #if PSYCH_SYSTEM == PSYCH_WINDOWS // Get framerate from num_dmabuffers argument: sprintf(tmpstr, " frame_rate=\"%i\" ", num_dmabuffers); strcat(config, tmpstr); #endif } #if PSYCH_SYSTEM == PSYCH_OSX // Disable setup dialog: strcat(config, " -nodialog"); // Specific deviceIndex requested, instead of auto-select? if (deviceIndex > 0) { sprintf(tmpstr, " -grabber=%i", deviceIndex + 1); strcat(config, tmpstr); } else { deviceIndex = 0; } switch (reqdepth) { case 2: // A no-go: Instead we use 1 channel luminance8: if (PsychPrefStateGet_Verbosity()>1) printf("PTB-WARNING: Video capture engine doesn't support requested Luminance+Alpha format. Will revert to pure Luminance instead...\n"); case 1: reqdepth = 1; sprintf(tmpstr, " -pixelformat=40"); break; case 3: reqdepth = 3; sprintf(tmpstr, " -pixelformat=24"); break; case 5: reqdepth = 4; sprintf(tmpstr, ""); break; case 4: case 0: reqdepth = 4; sprintf(tmpstr, " -pixelformat=ARGB"); break; default: // Unknown format: PsychErrorExitMsg(PsychError_user, "You requested an invalid image depths (not one of 0, 1, 2, 3 or 4). Aborted."); } strcat(config, tmpstr); #endif #if PSYCH_SYSTEM == PSYCH_WINDOWS if (reqdepth == 4 || reqdepth == 0) { // Default is RGB32 bit: reqdepth = 4; sprintf(tmpstr, "><pixel_format><RGB32 flip_h=\"false\" flip_v=\"true\"/></pixel_format></camera></dsvl_input>"); } else { // Only other supported format is RGB24 bit: switch (reqdepth) { case 1: if (PsychPrefStateGet_Verbosity()>1) printf("PTB-WARNING: Video capture engine doesn't support requested Luminance format. Will revert to RGB color instead...\n"); break; case 2: // A no-go: Instead we use 1 channel luminance8: if (PsychPrefStateGet_Verbosity()>1) printf("PTB-WARNING: Video capture engine doesn't support requested Luminance+Alpha format. Will revert to RGB color instead...\n"); break; case 3: break; default: // Unknown format: PsychErrorExitMsg(PsychError_user, "You requested an invalid image depths (not one of 0, 1, 2, 3 or 4). Aborted."); } reqdepth = 3; sprintf(tmpstr, "><pixel_format><RGB24 flip_h=\"false\" flip_v=\"true\"/></pixel_format></camera></dsvl_input>"); } strcat(config, tmpstr); if (deviceIndex == 4) { // Fetch optional moviename parameter as override configuration string: if (targetmoviefilename == NULL) PsychErrorExitMsg(PsychError_user, "You set 'deviceIndex' to a value of 4, but didn't provide the required override configuration string in the 'moviename' argument! Aborted."); // Reset config string: config[0] = 0; // And load the moviename argument as override string: strcat(config, targetmoviefilename); } // End of MS-Windows specific setup. #endif #if PSYCH_SYSTEM == PSYCH_LINUX // Specific deviceIndex requested, instead of auto-select? if (deviceIndex!=-1) { sprintf(tmpstr, " -dev=/dev/video%i", deviceIndex); strcat(config, tmpstr); } else { deviceIndex = 0; } reqdepth = 3; #endif // Requested output texture pixel depth in layers: capdev->reqpixeldepth = reqdepth; capdev->pixeldepth = reqdepth * 8; // Number of DMA ringbuffers to use in DMA capture mode: If no number provided (==0), set it to 8 buffers... #if PSYCH_SYSTEM == PSYCH_OSX if (num_dmabuffers == 1) { // Use single-buffering instead of triple buffering: strcat(config, " -singlebuffer"); } else { num_dmabuffers = 3; } capdev->num_dmabuffers = num_dmabuffers; #else capdev->num_dmabuffers = num_dmabuffers; #endif if (PsychPrefStateGet_Verbosity()>4) printf("PTB-INFO: Final configuration string passed to ARVideo library is:\n%s\n", config); // Prepare error message in case its needed below: sprintf(msgerr, "PTB-ERROR: Opening the %i. camera (deviceIndex=%i) failed!\n", deviceIndex + 1, deviceIndex); // Try to open and initialize camera according to given settings: capdev->camera = ar2VideoOpen(config); // Error abort if camera init failed: if(capdev->camera == NULL) { // Error abort here: capdev->valid = 0; PsychErrorExitMsg(PsychError_user, msgerr); } // Our camera should be ready: Assign final handle. *capturehandle = slotid; // Increase counter of open capture devices: numCaptureRecords++; // Set zero framerate: capdev->fps = 0; // Set image size: ar2VideoInqSize(capdev->camera, &(capdev->width), &(capdev->height)); // Create capture ROI corresponding to width and height of video image: PsychMakeRect(capdev->roirect, 0, 0, capdev->width, capdev->height); // Reset framecounter: capdev->nrframes = 0; capdev->grabber_active = 0; printf("PTB-INFO: Camera successfully opened...\n"); return(TRUE); }