[artoolkit-commits] artoolkit/lib/SRC/VideoMacOSX video.c,1.12,1.13
Optical marker tracking and overlay for augmented reality.
Brought to you by:
philip_lamb
From: Philip L. <phi...@us...> - 2005-12-08 18:54:55
|
Update of /cvsroot/artoolkit/artoolkit/lib/SRC/VideoMacOSX In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29207 Modified Files: video.c Log Message: Change locking requirement in arVideoGetImage, other minor fixes. Index: video.c =================================================================== RCS file: /cvsroot/artoolkit/artoolkit/lib/SRC/VideoMacOSX/video.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** video.c 30 Aug 2005 20:46:42 -0000 1.12 --- video.c 8 Dec 2005 18:54:45 -0000 1.13 *************** *** 83,86 **** --- 83,87 ---- #include <pthread.h> #include <sys/time.h> + #include <unistd.h> // usleep() #include <AR/config.h> #include <AR/ar.h> *************** *** 94,97 **** --- 95,99 ---- #define AR_VIDEO_DEBUG_BUFFERCOPY // Uncomment to have ar2VideoGetImage() return a copy of video pixel data. //#define AR_VIDEO_SUPPORT_OLD_QUICKTIME // Uncomment to allow use of non-thread safe QuickTime (pre-6.4). + //#define AR_VIDEO_DEBUG_FIX_DUAL_PROCESSOR_RACE #define AR_VIDEO_IDLE_INTERVAL_MILLISECONDS_MIN 20L *************** *** 263,267 **** if ((err = SGNewChannel(seqGrab, VideoMediaType, psgchanVideo))) { ! fprintf(stderr, "MakeSequenceGrabChannel(): SGNewChannel err=%ld\n", err); goto endFunc; } --- 265,273 ---- if ((err = SGNewChannel(seqGrab, VideoMediaType, psgchanVideo))) { ! if (err == couldntGetRequiredComponent) { ! printf("ERROR: No camera connected. Please connect a camera and re-try.\n"); ! } else { ! fprintf(stderr, "MakeSequenceGrabChannel(): SGNewChannel err=%ld\n", err); ! } goto endFunc; } *************** *** 333,337 **** if ((err = MakeSequenceGrabChannel(pVdg->seqGrab, &pVdg->sgchanVideo))) { ! fprintf(stderr, "MakeSequenceGrabChannel err=%d.\n", err); free(pVdg); return (NULL); --- 339,343 ---- if ((err = MakeSequenceGrabChannel(pVdg->seqGrab, &pVdg->sgchanVideo))) { ! if (err != couldntGetRequiredComponent) fprintf(stderr, "MakeSequenceGrabChannel err=%d.\n", err); free(pVdg); return (NULL); *************** *** 1026,1036 **** while (keepAlive && vdgIsGrabbing(vid->pVdg)) { gettimeofday(&tv, NULL); ts.tv_sec = tv.tv_sec; ! ts.tv_nsec = tv.tv_usec * 1000 + vid->milliSecPerTimer * 1E6; ! if (ts.tv_nsec >= 1E9) { ! ts.tv_nsec -= 1E9; ts.tv_sec += 1; } #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME // Get a lock to access QuickTime (for SGIdle()), but only if more than one thread is running. --- 1032,1044 ---- while (keepAlive && vdgIsGrabbing(vid->pVdg)) { + #ifndef AR_VIDEO_DEBUG_FIX_DUAL_PROCESSOR_RACE gettimeofday(&tv, NULL); ts.tv_sec = tv.tv_sec; ! ts.tv_nsec = tv.tv_usec * 1000 + vid->milliSecPerTimer * 1000000; ! if (ts.tv_nsec >= 1000000000) { ! ts.tv_nsec -= 1000000000; ts.tv_sec += 1; } + #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. *************** *** 1110,1114 **** vid->status |= AR_VIDEO_STATUS_BIT_READY; } ! err_i = pthread_cond_timedwait(&(vid->condition), &(vid->bufMutex), &ts); if (err_i != 0 && err_i != ETIMEDOUT) { --- 1118,1122 ---- 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); if (err_i != 0 && err_i != ETIMEDOUT) { *************** *** 1117,1120 **** --- 1125,1137 ---- break; } + #else + ar2VideoInternalUnlock(&(vid->bufMutex)); + usleep(vid->milliSecPerTimer * 1000); + if (!ar2VideoInternalLock(&(vid->bufMutex))) { + fprintf(stderr, "ar2VideoInternalThread(): Unable to lock mutex, exiting.\n"); + keepAlive = 0; + break; + } + #endif // AR_VIDEO_DEBUG_FIX_DUAL_PROCESSOR_RACE pthread_testcancel(); *************** *** 1339,1353 **** if(!(vid->pVdg = vdgAllocAndInit(grabber))) { ! fprintf(stderr, "ar2VideoOpen(): vdgAllocAndInit err=%ld\n", err); goto out1; } if (err = vdgRequestSettings(vid->pVdg, showDialog, gVidCount)) { ! fprintf(stderr, "ar2VideoOpen(): vdgRequestSettings err=%ld\n", err); goto out2; } if (err = vdgPreflightGrabbing(vid->pVdg)) { ! fprintf(stderr, "ar2VideoOpen(): vdgPreflightGrabbing err=%ld\n", err); goto out2; } --- 1356,1370 ---- if(!(vid->pVdg = vdgAllocAndInit(grabber))) { ! fprintf(stderr, "ar2VideoOpen(): vdgAllocAndInit returned error.\n"); goto out1; } if (err = vdgRequestSettings(vid->pVdg, showDialog, gVidCount)) { ! fprintf(stderr, "ar2VideoOpen(): vdgRequestSettings err=%ld.\n", err); goto out2; } if (err = vdgPreflightGrabbing(vid->pVdg)) { ! fprintf(stderr, "ar2VideoOpen(): vdgPreflightGrabbing err=%ld.\n", err); goto out2; } *************** *** 1359,1363 **** &vid->frameRate, &vid->bytesPerSecond)) { ! fprintf(stderr, "ar2VideoOpen(): vdgGetDataRate err=%ld\n", err); //goto out2; } --- 1376,1380 ---- &vid->frameRate, &vid->bytesPerSecond)) { ! fprintf(stderr, "ar2VideoOpen(): vdgGetDataRate err=%ld.\n", err); //goto out2; } *************** *** 1389,1393 **** // Report video size and compression type. ! fprintf(stdout, "Video cType is %c%c%c%c, size is %dx%d.\n", (char)(((*(vid->vdImageDesc))->cType >> 24) & 0xFF), (char)(((*(vid->vdImageDesc))->cType >> 16) & 0xFF), --- 1406,1410 ---- // Report video size and compression type. ! printf("Video cType is %c%c%c%c, size is %dx%d.\n", (char)(((*(vid->vdImageDesc))->cType >> 24) & 0xFF), (char)(((*(vid->vdImageDesc))->cType >> 16) & 0xFF), *************** *** 1746,1755 **** ARUint8 *pix = NULL; - // Need lock to guarantee this thread exclusive access to vid. - if (!ar2VideoInternalLock(&(vid->bufMutex))) { - fprintf(stderr, "ar2VideoGetImage(): Unable to lock mutex.\n"); - return (NULL); - } - // ar2VideoGetImage() used to block waiting for a frame. // This locked the OpenGL frame rate to the camera frame rate. --- 1763,1766 ---- *************** *** 1758,1761 **** --- 1769,1778 ---- 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); *************** *** 1783,1792 **** vid->status &= ~AR_VIDEO_STATUS_BIT_READY; // Clear ready bit. } - if (!ar2VideoInternalUnlock(&(vid->bufMutex))) { - fprintf(stderr, "ar2VideoGetImage(): Unable to unlock mutex.\n"); - return (NULL); - } return (pix); } --- 1800,1810 ---- vid->status &= ~AR_VIDEO_STATUS_BIT_READY; // Clear ready bit. + + if (!ar2VideoInternalUnlock(&(vid->bufMutex))) { + fprintf(stderr, "ar2VideoGetImage(): Unable to unlock mutex.\n"); + return (NULL); + } } return (pix); } |