Skip to content

Commit

Permalink
allow QtKit capture in secondary threads
Browse files Browse the repository at this point in the history
[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
  • Loading branch information
devernay committed Jul 2, 2013
1 parent 6bf8f47 commit b524e27
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions modules/highgui/src/cap_qtkit.mm
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,8 @@ - (IplImage*)getOutput;
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];

Expand Down

0 comments on commit b524e27

Please sign in to comment.