From: Frédéric Devernay Date: Tue, 2 Jul 2013 16:08:12 +0000 (+0200) Subject: allow QtKit capture in secondary threads X-Git-Tag: accepted/tizen/ivi/20140515.103456~1^2~664^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b524e275c1db2f09f2a3a5f6ccc7ad6fc5d4bc2a;p=profile%2Fivi%2Fopencv.git allow QtKit capture in secondary threads [NSRunLoop currentRunLoop] is not the same as in the main thread. see https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/F oundation/Classes/nsrunloop_Class/Reference/Reference.html "If no input sources or timers are attached to the run loop, this method exits immediately" The old code caused grabFrame() to return immediately if the capture was not done in the main thread. This code works correctly, even in secondary threads, provided that all capture functions are called in the *same* thread --- diff --git a/modules/highgui/src/cap_qtkit.mm b/modules/highgui/src/cap_qtkit.mm index c7afffa..207f01b 100644 --- a/modules/highgui/src/cap_qtkit.mm +++ b/modules/highgui/src/cap_qtkit.mm @@ -277,11 +277,8 @@ bool CvCaptureCAM::grabFrame(double timeOut) { double sleepTime = 0.005; double total = 0; - NSDate *loopUntil = [NSDate dateWithTimeIntervalSinceNow:sleepTime]; - while (![capture updateImage] && (total += sleepTime)<=timeOut && - [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode - beforeDate:loopUntil]) - loopUntil = [NSDate dateWithTimeIntervalSinceNow:sleepTime]; + while (![capture updateImage] && (total += sleepTime)<=timeOut) + usleep((int)(sleepTime*1000)); [localpool drain];