[artoolkit-commits] artoolkit/lib/SRC/VideoMacOSX video.c, 1.23, 1.24
Optical marker tracking and overlay for augmented reality.
Brought to you by:
philip_lamb
From: Philip L. <phi...@us...> - 2007-01-18 22:50:53
|
Update of /cvsroot/artoolkit/artoolkit/lib/SRC/VideoMacOSX In directory sc8-pr-cvs11.sourceforge.net:/tmp/cvs-serv9843 Modified Files: video.c Log Message: Optimise Mac video handling in ARvideo and ARgsub_lite. Index: video.c =================================================================== RCS file: /cvsroot/artoolkit/artoolkit/lib/SRC/VideoMacOSX/video.c,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** video.c 3 Oct 2006 21:35:52 -0000 1.23 --- video.c 18 Jan 2007 22:50:46 -0000 1.24 *************** *** 1037,1040 **** --- 1037,1041 ---- } #endif // AR_VIDEO_DEBUG_FIX_DUAL_PROCESSOR_RACE + #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME // Get a lock to access QuickTime (for SGIdle()), but only if more than one thread is running. *************** *** 1057,1064 **** // from the VDig. fprintf(stderr, "vdgIdle err=%ld.\n", err); - // ... to fix this we could simply call SGStop and SGStartRecord again - // calling stop allows the SG to release and re-prepare for grabbing - // hopefully fixing any problems, this is obviously a very relaxed - // approach. keepAlive = 0; break; --- 1058,1061 ---- *************** *** 1130,1137 **** //vid->lastTime = time; } ! // Mark status to indicate we have a frame available. vid->status |= AR_VIDEO_STATUS_BIT_READY; } #ifndef AR_VIDEO_DEBUG_FIX_DUAL_PROCESSOR_RACE err_i = pthread_cond_timedwait(&(vid->condition), &(vid->bufMutex), &ts); --- 1127,1143 ---- //vid->lastTime = time; } ! // Now copy the frame (if double-buffering). ! if (vid->bufCopyFlag) { ! if (vid->status & AR_VIDEO_STATUS_BIT_BUFFER) { ! memcpy((void *)(vid->bufPixelsCopy2), (void *)(vid->bufPixels), vid->bufSize); ! } else { ! memcpy((void *)(vid->bufPixelsCopy1), (void *)(vid->bufPixels), vid->bufSize); ! } ! } // Mark status to indicate we have a frame available. vid->status |= AR_VIDEO_STATUS_BIT_READY; } + + // All done. Wewease Wodger! #ifndef AR_VIDEO_DEBUG_FIX_DUAL_PROCESSOR_RACE err_i = pthread_cond_timedwait(&(vid->condition), &(vid->bufMutex), &ts); *************** *** 1238,1241 **** --- 1244,1249 ---- printf(" -flipv\n"); printf(" Flip camera image vertically.\n"); + printf(" -singlebuffer\n"); + printf(" Use single buffering of captured video instead of triple-buffering.\n"); printf("\n"); *************** *** 1246,1250 **** AR2VideoParamT *ar2VideoOpen(char *config_in) { - static int initF = 0; long qtVersion = 0L; int width = 0; --- 1254,1257 ---- *************** *** 1254,1257 **** --- 1261,1265 ---- int showDialog = 1; int standardDialog = 0; + int singleBuffer = 0; int flipH = 0, flipV = 0; OSErr err_s = noErr; *************** *** 1265,1270 **** OSType pixFormat = (OSType)0; long bytesPerPixel; - CGrafPtr theSavedPort; - GDHandle theSavedDevice; long cpuType; --- 1273,1276 ---- *************** *** 1275,1286 **** if (envconf && envconf[0]) { config = envconf; ! printf ("Using config string from environment [%s].\n", envconf); } else { config = NULL; ! printf ("No video config string supplied, using defaults.\n"); } } else { config = config_in; ! printf ("Using supplied video config string [%s].\n", config_in); } --- 1281,1292 ---- if (envconf && envconf[0]) { config = envconf; ! printf ("Using video config from environment \"%s\".\n", envconf); } else { config = NULL; ! printf ("Using default video config.\n"); } } else { config = config_in; ! printf ("Using supplied video config \"%s\".\n", config_in); } *************** *** 1319,1322 **** --- 1325,1330 ---- } else if (strncmp(a, "-flipv", 6) == 0) { flipV = 1; + } else if (strncmp(a, "-singlebuffer", 13) == 0) { + singleBuffer = 1; } else { err_i = 1; *************** *** 1380,1389 **** } - // Once only, initialize for Carbon. - if (initF == 0) { - InitCursor(); - initF = 1; - } - // If there are no active grabbers, init QuickTime. if (gVidCount == 0) { --- 1388,1391 ---- *************** *** 1444,1447 **** --- 1446,1450 ---- //vid->timeScale = 0; vid->grabber = grabber; + vid->bufCopyFlag = !singleBuffer; // Find out if we are running on an Intel Mac. *************** *** 1451,1457 **** } if (cpuType == gestaltCPUPentium) { ! // We are running on an Intel-based Mac. ! vid->bufCopyFlag = 0; //Hack: don't do buffercopy on Intel Macs. ! printf("Detected Intel CPU.\n"); } else { int native = is_pid_native(0); --- 1454,1459 ---- } if (cpuType == gestaltCPUPentium) { ! // We are running native on an Intel-based Mac. ! //printf("Detected Intel CPU.\n"); } else { int native = is_pid_native(0); *************** *** 1459,1467 **** if (native == 0) { // We're running under Rosetta. - vid->bufCopyFlag = 0; printf("Detected Intel CPU, but running PowerPC code under Rosetta.\n"); } else { ! // Error if < 0, or native if 1. ! vid->bufCopyFlag = 1; } } --- 1461,1469 ---- if (native == 0) { // We're running under Rosetta. printf("Detected Intel CPU, but running PowerPC code under Rosetta.\n"); + } else if (native == 1) { + //printf("Detected PowerPC CPU.\n"); } else { ! // Error. } } *************** *** 1590,1594 **** // we can't decompress into an unlocked PixMap, // and open the default sequence grabber. - // TODO: Allow user to configure sequence grabber. err_i = (int)LockPixels(GetGWorldPixMap(vid->pGWorld)); if (!err_i) { --- 1592,1595 ---- *************** *** 1598,1608 **** // Erase to black. ! #if 0 QDBeginCGContext(vid->pGWorld, &ctx); ! CGContextSetRGBFillColor(ctx, 1, 1, 1, 1); CGContextFillRect(ctx, CGRectMake(0, 0, (vid->theRect).left - (vid->theRect).right, (vid->theRect).top - (vid->theRect).bottom)); CGContextFlush(ctx); QDEndCGContext (vid->pGWorld, &ctx); #else GetGWorld(&theSavedPort, &theSavedDevice); SetGWorld(vid->pGWorld, NULL); --- 1599,1612 ---- // Erase to black. ! #if 1 ! CGContextRef ctx; QDBeginCGContext(vid->pGWorld, &ctx); ! CGContextSetRGBFillColor(ctx, 0, 0, 0, 1); CGContextFillRect(ctx, CGRectMake(0, 0, (vid->theRect).left - (vid->theRect).right, (vid->theRect).top - (vid->theRect).bottom)); CGContextFlush(ctx); QDEndCGContext (vid->pGWorld, &ctx); #else + CGrafPtr theSavedPort; + GDHandle theSavedDevice; GetGWorld(&theSavedPort, &theSavedDevice); SetGWorld(vid->pGWorld, NULL); *************** *** 1908,1917 **** if (vid->status & AR_VIDEO_STATUS_BIT_READY) { - // Need lock to guarantee this thread exclusive access to vid. - if (!ar2VideoInternalLock(&(vid->bufMutex))) { - fprintf(stderr, "ar2VideoGetImage(): Unable to lock mutex.\n"); - return (NULL); - } - //fprintf(stderr, "For vid @ %p got frame %ld.\n", vid, vid->frameCount); --- 1912,1915 ---- *************** *** 1925,1928 **** --- 1923,1931 ---- // various bits of the toolkit to cope. if (vid->bufCopyFlag) { + // Need lock to guarantee this thread exclusive access to vid. + if (!ar2VideoInternalLock(&(vid->bufMutex))) { + fprintf(stderr, "ar2VideoGetImage(): Unable to lock mutex.\n"); + return (NULL); + } if (vid->status & AR_VIDEO_STATUS_BIT_BUFFER) { memcpy((void *)(vid->bufPixelsCopy2), (void *)(vid->bufPixels), vid->bufSize); *************** *** 1934,1937 **** --- 1937,1944 ---- vid->status |= AR_VIDEO_STATUS_BIT_BUFFER; // Set buffer bit. } + if (!ar2VideoInternalUnlock(&(vid->bufMutex))) { + fprintf(stderr, "ar2VideoGetImage(): Unable to unlock mutex.\n"); + return (NULL); + } } else { pix = vid->bufPixels; *************** *** 1940,1947 **** vid->status &= ~AR_VIDEO_STATUS_BIT_READY; // Clear ready bit. - if (!ar2VideoInternalUnlock(&(vid->bufMutex))) { - fprintf(stderr, "ar2VideoGetImage(): Unable to unlock mutex.\n"); - return (NULL); - } } --- 1947,1950 ---- |