[artoolkit-commits] artoolkit/lib/SRC/VideoMacOSX video.c,1.5,1.6
Optical marker tracking and overlay for augmented reality.
Brought to you by:
philip_lamb
From: Philip L. <phi...@us...> - 2005-03-16 04:42:16
|
Update of /cvsroot/artoolkit/artoolkit/lib/SRC/VideoMacOSX In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31869 Modified Files: video.c Log Message: Mac OS X video driver: Check QuickTime version. Index: video.c =================================================================== RCS file: /cvsroot/artoolkit/artoolkit/lib/SRC/VideoMacOSX/video.c,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** video.c 10 Mar 2005 04:00:38 -0000 1.5 --- video.c 16 Mar 2005 04:42:06 -0000 1.6 *************** *** 15,21 **** * Returns aligned data in ARGB pixel format. * 1.2.0 2004-04-28 PRL Now one thread per video source. Versions of QuickTime ! * prior to 6.4 are NOT thread safe, and if using a non-thread ! * safe version, you should comment out AR_VIDEO_HAVE_THREADSAFE_QUICKTIME ! * so serialise access when there is more than one thread. * 1.2.1 2004-06-28 PRL Support for 2vuy and yuvs pixel formats. * 1.3.0 2004-07-13 PRL Code from Daniel Heckenberg to directly access vDig. --- 15,20 ---- * Returns aligned data in ARGB pixel format. * 1.2.0 2004-04-28 PRL Now one thread per video source. Versions of QuickTime ! * prior to 6.4 are NOT thread safe, and with these earlier ! * versions, QuickTime toolbox access will be serialised. * 1.2.1 2004-06-28 PRL Support for 2vuy and yuvs pixel formats. * 1.3.0 2004-07-13 PRL Code from Daniel Heckenberg to directly access vDig. *************** *** 23,28 **** * specification at runtime, with default determined at compile time. * 1.4.0 2005-03-08 PRL Video input settings now saved and restored. * - * TODO: Check version of Quicktime available at runtime. */ /* --- 22,29 ---- * specification at runtime, with default determined at compile time. * 1.4.0 2005-03-08 PRL Video input settings now saved and restored. + * 1.4.1 2005-03-15 PRL QuickTime 6.4 or newer is now required by default. In order + * to allow earlier versions, AR_VIDEO_SUPPORT_OLD_QUICKTIME must + * be uncommented at compile time. * */ /* *************** *** 91,95 **** #define AR_VIDEO_DEBUG_BUFFERCOPY // Uncomment to have ar2VideoGetImage() return a copy of video pixel data. ! #define AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Uncomment to trust QuickTime's thread-safety, QuickTime 6.4 and later are thread-safe. #define AR_VIDEO_IDLE_INTERVAL_MILLISECONDS_MIN 20L --- 92,96 ---- #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_IDLE_INTERVAL_MILLISECONDS_MIN 20L *************** *** 172,178 **** static AR2VideoParamT *gVid = NULL; static unsigned int gVidCount = 0; ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME static pthread_mutex_t gVidQuickTimeMutex; ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME #pragma mark - --- 173,179 ---- static AR2VideoParamT *gVid = NULL; static unsigned int gVidCount = 0; ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME static pthread_mutex_t gVidQuickTimeMutex; ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME #pragma mark - *************** *** 974,982 **** vid = (AR2VideoParamT *)arg; ar2VideoInternalUnlock(&(vid->bufMutex)); // A cancelled thread shouldn't leave mutexes locked. ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME ! ar2VideoInternalUnlock(&gVidQuickTimeMutex); ! #else ExitMoviesOnThread(); ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME } --- 975,983 ---- vid = (AR2VideoParamT *)arg; ar2VideoInternalUnlock(&(vid->bufMutex)); // A cancelled thread shouldn't leave mutexes locked. ! #ifndef AR_VIDEO_SUPPORT_OLD_QUICKTIME ExitMoviesOnThread(); ! #else ! ar2VideoInternalUnlock(&gVidQuickTimeMutex); ! #endif // !AR_VIDEO_SUPPORT_OLD_QUICKTIME } *************** *** 988,996 **** static void *ar2VideoInternalThread(void *arg) { ! #ifdef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME OSErr err_o; #else int weLocked = 0; ! #endif // AR_VIDEO_HAVE_THREADSAFE_QUICKTIME AR2VideoParamT *vid; int keepAlive = 1; --- 989,997 ---- static void *ar2VideoInternalThread(void *arg) { ! #ifndef AR_VIDEO_SUPPORT_OLD_QUICKTIME OSErr err_o; #else int weLocked = 0; ! #endif // !AR_VIDEO_SUPPORT_OLD_QUICKTIME AR2VideoParamT *vid; int keepAlive = 1; *************** *** 1010,1014 **** ! #ifdef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Signal to QuickTime that this is a separate thread. if ((err_o = EnterMoviesOnThread(0)) != noErr) { --- 1011,1015 ---- ! #ifndef AR_VIDEO_SUPPORT_OLD_QUICKTIME // Signal to QuickTime that this is a separate thread. if ((err_o = EnterMoviesOnThread(0)) != noErr) { *************** *** 1016,1020 **** return (NULL); } ! #endif // AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Register our cleanup function, with arg as arg. --- 1017,1021 ---- return (NULL); } ! #endif // !AR_VIDEO_SUPPORT_OLD_QUICKTIME // Register our cleanup function, with arg as arg. *************** *** 1041,1045 **** ts.tv_sec += 1; } ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Get a lock to access QuickTime (for SGIdle()), but only if more than one thread is running. if (gVidCount > 1) { --- 1042,1046 ---- 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. if (gVidCount > 1) { *************** *** 1051,1055 **** weLocked = 1; } ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME if ((err = vdgIdle(vid->pVdg, &isUpdated)) != noErr) { --- 1052,1056 ---- weLocked = 1; } ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME if ((err = vdgIdle(vid->pVdg, &isUpdated)) != noErr) { *************** *** 1069,1073 **** } ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // vdgIdle() is done, unlock our hold on QuickTime if we locked it. if (weLocked) { --- 1070,1074 ---- } ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME // vdgIdle() is done, unlock our hold on QuickTime if we locked it. if (weLocked) { *************** *** 1079,1083 **** weLocked = 0; } ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME if (isUpdated) { --- 1080,1084 ---- weLocked = 0; } ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME if (isUpdated) { *************** *** 1170,1173 **** --- 1171,1175 ---- { static int initF = 0; + long qtVersion = 0L; int width = 0; int height = 0; *************** *** 1180,1186 **** AR2VideoParamT *vid = NULL; char *a, line[256]; ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME int weLocked = 0; ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME OSType pixFormat = (OSType)0; long bytesPerPixel; --- 1182,1188 ---- AR2VideoParamT *vid = NULL; char *a, line[256]; ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME int weLocked = 0; ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME OSType pixFormat = (OSType)0; long bytesPerPixel; *************** *** 1288,1291 **** --- 1290,1310 ---- // If there are no active grabbers, init the QuickTime access mutex. if (gVidCount == 0) { + + if ((err_s = Gestalt(gestaltQuickTimeVersion, &qtVersion)) != noErr) { + fprintf(stderr,"ar2VideoOpen(): QuickTime not installed (%d).\n", err_s); + return (NULL); + } + + #ifndef AR_VIDEO_SUPPORT_OLD_QUICKTIME + if ((qtVersion >> 16) < 0x640) { + fprintf(stderr,"ar2VideoOpen(): QuickTime version 6.4 or newer is required by this program.\n");; + return (NULL); + } + #else + if ((qtVersion >> 16) < 0x400) { + fprintf(stderr,"ar2VideoOpen(): QuickTime version 4.0 or newer is required by this program.\n");; + return (NULL); + } + #endif // !AR_VIDEO_SUPPORT_OLD_QUICKTIME // Initialise QuickTime (a.k.a. Movie Toolbox). *************** *** 1295,1299 **** } ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // If there are no active grabbers, init the QuickTime access mutex. if ((err_i = pthread_mutex_init(&gVidQuickTimeMutex, NULL)) != 0) { --- 1314,1318 ---- } ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME // If there are no active grabbers, init the QuickTime access mutex. if ((err_i = pthread_mutex_init(&gVidQuickTimeMutex, NULL)) != 0) { *************** *** 1301,1308 **** return (NULL); } ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME } ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Get a hold on the QuickTime toolbox. // Need to unlock this mutex before returning, so any errors should goto bail; --- 1320,1327 ---- return (NULL); } ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME } ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME // Get a hold on the QuickTime toolbox. // Need to unlock this mutex before returning, so any errors should goto bail; *************** *** 1314,1318 **** weLocked = 1; } ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME gVidCount++; --- 1333,1337 ---- weLocked = 1; } ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME gVidCount++; *************** *** 1490,1494 **** gVidCount--; out: ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Release our hold on the QuickTime toolbox. if (weLocked) { --- 1509,1513 ---- gVidCount--; out: ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME // Release our hold on the QuickTime toolbox. if (weLocked) { *************** *** 1498,1502 **** } } ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME return (vid); --- 1517,1521 ---- } } ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME return (vid); *************** *** 1506,1514 **** { int err_i; ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME int weLocked = 0; ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Get a hold on the QuickTime toolbox. if (gVidCount > 1) { --- 1525,1533 ---- { int err_i; ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME int weLocked = 0; ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME // Get a hold on the QuickTime toolbox. if (gVidCount > 1) { *************** *** 1518,1522 **** weLocked = 1; } ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Destroy the condition variable. --- 1537,1541 ---- weLocked = 1; } ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME // Destroy the condition variable. *************** *** 1562,1566 **** vdgReleaseAndDealloc(vid->pVdg); ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Release our hold on the QuickTime toolbox. if (weLocked) { --- 1581,1585 ---- vdgReleaseAndDealloc(vid->pVdg); ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME // Release our hold on the QuickTime toolbox. if (weLocked) { *************** *** 1569,1573 **** } } ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Count one less grabber running. --- 1588,1592 ---- } } ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME // Count one less grabber running. *************** *** 1577,1586 **** // If we're the last to close, clean up after everybody. if (!gVidCount) { ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Destroy the mutex. if ((err_i = pthread_mutex_destroy(&gVidQuickTimeMutex)) != 0) { fprintf(stderr, "ar2VideoClose(): Error %d destroying mutex (for QuickTime).\n", err_i); } ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Probably a good idea to close down QuickTime. --- 1596,1605 ---- // If we're the last to close, clean up after everybody. if (!gVidCount) { ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME // Destroy the mutex. if ((err_i = pthread_mutex_destroy(&gVidQuickTimeMutex)) != 0) { fprintf(stderr, "ar2VideoClose(): Error %d destroying mutex (for QuickTime).\n", err_i); } ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME // Probably a good idea to close down QuickTime. *************** *** 1595,1603 **** ComponentResult err; int err_i = 0; ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME int weLocked = 0; ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Get a hold on the QuickTime toolbox. if (gVidCount > 1) { --- 1614,1622 ---- ComponentResult err; int err_i = 0; ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME int weLocked = 0; ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME // Get a hold on the QuickTime toolbox. if (gVidCount > 1) { *************** *** 1608,1612 **** weLocked = 1; } ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME vid->status = 0; --- 1627,1631 ---- weLocked = 1; } ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME vid->status = 0; *************** *** 1617,1621 **** } ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Release our hold on the QuickTime toolbox. if (weLocked) { --- 1636,1640 ---- } ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME // Release our hold on the QuickTime toolbox. if (weLocked) { *************** *** 1625,1629 **** } } ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME if (err_i == 0) { --- 1644,1648 ---- } } ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME if (err_i == 0) { *************** *** 1647,1653 **** { int err_i = 0; ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME int weLocked = 0; ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME void *exit_status_p; // Pointer to return value from thread, will be filled in by pthread_join(). ComponentResult err = noErr; --- 1666,1672 ---- { int err_i = 0; ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME int weLocked = 0; ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME void *exit_status_p; // Pointer to return value from thread, will be filled in by pthread_join(). ComponentResult err = noErr; *************** *** 1672,1676 **** if (vid->pVdg) { ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Get a hold on the QuickTime toolbox. if (gVidCount > 1) { --- 1691,1695 ---- if (vid->pVdg) { ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME // Get a hold on the QuickTime toolbox. if (gVidCount > 1) { *************** *** 1681,1685 **** weLocked = 1; } ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME if ((err = vdgStopGrabbing(vid->pVdg)) != noErr) { --- 1700,1704 ---- weLocked = 1; } ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME if ((err = vdgStopGrabbing(vid->pVdg)) != noErr) { *************** *** 1688,1692 **** } ! #ifndef AR_VIDEO_HAVE_THREADSAFE_QUICKTIME // Release our hold on the QuickTime toolbox. if (weLocked) { --- 1707,1711 ---- } ! #ifdef AR_VIDEO_SUPPORT_OLD_QUICKTIME // Release our hold on the QuickTime toolbox. if (weLocked) { *************** *** 1696,1700 **** } } ! #endif // !AR_VIDEO_HAVE_THREADSAFE_QUICKTIME } --- 1715,1719 ---- } } ! #endif // AR_VIDEO_SUPPORT_OLD_QUICKTIME } |