From 1f33caa3b3445df1e8107ca2b2af53073d8c282d Mon Sep 17 00:00:00 2001 From: Tom Butterworth Date: Tue, 15 Aug 2017 13:40:20 +0100 Subject: [PATCH] Throttle calls to EdsOpenSession Together with 09acf9bfd1470f745265cd122471ace25a17c795 this fixes #8 --- Camera Live/SyPCanonDSLR.h | 1 + Camera Live/SyPCanonDSLR.m | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/Camera Live/SyPCanonDSLR.h b/Camera Live/SyPCanonDSLR.h index eb06e36..1f2330e 100644 --- a/Camera Live/SyPCanonDSLR.h +++ b/Camera Live/SyPCanonDSLR.h @@ -50,5 +50,6 @@ SyPCanonEVFImageBuffer *_nextImage; SyPImageBuffer *_pendingImage; NSError *_pendingError; + NSTimeInterval _lastSession; } @end diff --git a/Camera Live/SyPCanonDSLR.m b/Camera Live/SyPCanonDSLR.m index 320612e..2509e73 100644 --- a/Camera Live/SyPCanonDSLR.m +++ b/Camera Live/SyPCanonDSLR.m @@ -464,7 +464,14 @@ - (NSError *)startSessionOnQueue if (OSAtomicCompareAndSwapPtrBarrier(NULL, self, (void **)&mSession)) { _hasSession = YES; + // Throttle sessions or the EdsOpenSession call never returns + NSTimeInterval since = [NSDate timeIntervalSinceReferenceDate] - _lastSession; + if (since < 0.5) + { + usleep((0.5 - since) * USEC_PER_SEC); + } EdsError result = EdsOpenSession(_camera); + _lastSession = [NSDate timeIntervalSinceReferenceDate]; error = [SyPCanonDSLR errorForEDSError:result]; } else