summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fischer <joeljfischer@gmail.com>2017-12-15 16:00:29 -0500
committerJoel Fischer <joeljfischer@gmail.com>2017-12-15 16:00:29 -0500
commit43a7be38b49b8e9f2e6003460e817344c5e77b45 (patch)
treeb788fab896da084969c38359a82ac6759fc7f846
parente6717aa5a27b81ff1aeb07736ff25d90693cc23c (diff)
downloadsdl_ios-43a7be38b49b8e9f2e6003460e817344c5e77b45.tar.gz
Streaming Media Manager now strictly manages framerate
* CarWindow CADisplayLink migrated to SMM. The frame sync is passed to TouchManager and CarWindow. * Added BOOL to SMMConfig to configure whether to wait for screen updates in CarWindow before drawing. * TouchManager now syncs panning and pinching to framerate by default and passes back panning and pinching delegates before the frame updates. * TouchManager adds a new BOOL to disable new behavior and enable old behavior. * Fix tests
-rwxr-xr-xSmartDeviceLink/SDLCarWindow.h6
-rwxr-xr-xSmartDeviceLink/SDLCarWindow.m24
-rw-r--r--SmartDeviceLink/SDLStreamingMediaConfiguration.h6
-rw-r--r--SmartDeviceLink/SDLStreamingMediaConfiguration.m1
-rw-r--r--SmartDeviceLink/SDLStreamingMediaLifecycleManager.m30
-rw-r--r--SmartDeviceLink/SDLTouchManager.h12
-rw-r--r--SmartDeviceLink/SDLTouchManager.m77
-rw-r--r--SmartDeviceLinkTests/RPCSpecs/PayloadSpecs/SDLRPCPayloadSpec.m2
-rw-r--r--SmartDeviceLinkTests/SDLStreamingMediaLifecycleManagerSpec.m3
-rw-r--r--SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m36
10 files changed, 138 insertions, 59 deletions
diff --git a/SmartDeviceLink/SDLCarWindow.h b/SmartDeviceLink/SDLCarWindow.h
index 28964d70e..b372f0b42 100755
--- a/SmartDeviceLink/SDLCarWindow.h
+++ b/SmartDeviceLink/SDLCarWindow.h
@@ -20,16 +20,18 @@ NS_ASSUME_NONNULL_BEGIN
Initialize the CarWindow automatic streamer.
@param streamManager The stream manager to use for retrieving head unit dimension details and forwarding video frame data
- @param framesPerSecond The number of frames per second CarWindow should attempt to generate
+ @param drawsAfterScreenUpdates Whether or not it should wait until a screen update to draw.
@return An instance of this class
*/
-- (instancetype)initWithStreamManager:(SDLStreamingMediaLifecycleManager *)streamManager targetFramerate:(NSUInteger)framesPerSecond;
+- (instancetype)initWithStreamManager:(SDLStreamingMediaLifecycleManager *)streamManager drawsAfterScreenUpdates:(BOOL)drawsAfterScreenUpdates;
/**
* View Controller that will be streamed.
*/
@property (strong, nonatomic, nullable) UIViewController *rootViewController;
+- (void)syncFrame;
+
@end
NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/SDLCarWindow.m b/SmartDeviceLink/SDLCarWindow.m
index 79c1111bc..3af046876 100755
--- a/SmartDeviceLink/SDLCarWindow.m
+++ b/SmartDeviceLink/SDLCarWindow.m
@@ -26,6 +26,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (strong, nonatomic, nullable) CADisplayLink *displayLink;
@property (assign, nonatomic) NSUInteger targetFramerate;
+@property (assign, nonatomic) BOOL drawsAfterScreenUpdates;
@property (weak, nonatomic, nullable) SDLStreamingMediaLifecycleManager *streamManager;
@@ -35,14 +36,12 @@ NS_ASSUME_NONNULL_BEGIN
@implementation SDLCarWindow
-- (instancetype)initWithStreamManager:(SDLStreamingMediaLifecycleManager *)streamManager targetFramerate:(NSUInteger)framesPerSecond {
+- (instancetype)initWithStreamManager:(SDLStreamingMediaLifecycleManager *)streamManager drawsAfterScreenUpdates:(BOOL)drawsAfterScreenUpdates {
self = [super init];
if (!self) { return nil; }
- SDLLogD(@"Initializing Car Window automatic streaming with framerate: %lu", (unsigned long)framesPerSecond);
-
_streamManager = streamManager;
- _targetFramerate = framesPerSecond;
+ _drawsAfterScreenUpdates = drawsAfterScreenUpdates;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_didReceiveVideoStreamStarted:) name:SDLVideoStreamDidStartNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_didReceiveVideoStreamStopped:) name:SDLVideoStreamDidStopNotification object:nil];
@@ -56,7 +55,7 @@ NS_ASSUME_NONNULL_BEGIN
return self;
}
-- (void)sdl_sendFrame:(CADisplayLink *)displayLink {
+- (void)syncFrame {
if (!self.streamManager.isVideoConnected || self.streamManager.isVideoStreamingPaused) {
return;
}
@@ -69,7 +68,7 @@ NS_ASSUME_NONNULL_BEGIN
CGRect bounds = self.rootViewController.view.bounds;
UIGraphicsBeginImageContextWithOptions(bounds.size, YES, 1.0f);
- [self.rootViewController.view drawViewHierarchyInRect:bounds afterScreenUpdates:YES];
+ [self.rootViewController.view drawViewHierarchyInRect:bounds afterScreenUpdates:self.drawsAfterScreenUpdates];
UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
@@ -96,24 +95,11 @@ NS_ASSUME_NONNULL_BEGIN
self.rootViewController.view.bounds = self.rootViewController.view.frame;
SDLLogD(@"Video stream started, setting CarWindow frame to: %@", NSStringFromCGRect(self.rootViewController.view.bounds));
-
- // And start up the displayLink
- self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(sdl_sendFrame:)];
- if (SDL_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10")) {
- self.displayLink.preferredFramesPerSecond = (NSInteger)self.targetFramerate;
- } else {
- self.displayLink.frameInterval = (60 / self.targetFramerate);
- }
- [self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
});
}
- (void)sdl_didReceiveVideoStreamStopped:(NSNotification *)notification {
dispatch_async(dispatch_get_main_queue(), ^{
- // If the video stream has stopped, we want to resize the streamingViewController to the ordinary size
- self.displayLink.paused = YES;
- [self.displayLink invalidate];
-
// And also reset the streamingViewController's frame, because we are about to show it.
self.rootViewController.view.frame = [UIScreen mainScreen].bounds;
SDLLogD(@"Video stream ended, setting view controller frame back: %@", NSStringFromCGRect(self.rootViewController.view.frame));
diff --git a/SmartDeviceLink/SDLStreamingMediaConfiguration.h b/SmartDeviceLink/SDLStreamingMediaConfiguration.h
index 4f7d04cdf..e4001009e 100644
--- a/SmartDeviceLink/SDLStreamingMediaConfiguration.h
+++ b/SmartDeviceLink/SDLStreamingMediaConfiguration.h
@@ -29,7 +29,6 @@ NS_ASSUME_NONNULL_BEGIN
@property (assign, nonatomic) SDLStreamingEncryptionFlag maximumDesiredEncryption;
/**
- * Properties to use for applications that utilitze the video encoder for streaming. See VTCompressionProperties.h for more details. For example, you can set kVTCompressionPropertyKey_ExpectedFrameRate to set your framerate. Setting the framerate this way will also set the framerate if you use CarWindow automatic streaming.
* Properties to use for applications that utilize the video encoder for streaming. See VTCompressionProperties.h for more details. For example, you can set kVTCompressionPropertyKey_ExpectedFrameRate to set your framerate. Setting the framerate this way will also set the framerate if you use CarWindow automatic streaming.
*
* Other properties you may want to try adjusting include kVTCompressionPropertyKey_AverageBitRate and kVTCompressionPropertyKey_DataRateLimits.
@@ -66,6 +65,11 @@ NS_ASSUME_NONNULL_BEGIN
@property (strong, nonatomic, nullable) UIViewController *rootViewController;
/**
+ Declares if CarWindow will wait until after the screen updates to draw. Defaults to YES.
+ */
+@property (assign, nonatomic) BOOL carWindowDrawsAfterScreenUpdates;
+
+/**
Create an insecure video streaming configuration. No security managers will be provided and the encryption flag will be set to None. If you'd like custom video encoder settings, you can set the property manually.
@return The configuration
diff --git a/SmartDeviceLink/SDLStreamingMediaConfiguration.m b/SmartDeviceLink/SDLStreamingMediaConfiguration.m
index 14240cfc4..4bd582e2c 100644
--- a/SmartDeviceLink/SDLStreamingMediaConfiguration.m
+++ b/SmartDeviceLink/SDLStreamingMediaConfiguration.m
@@ -38,6 +38,7 @@ NS_ASSUME_NONNULL_BEGIN
_customVideoEncoderSettings = videoSettings;
_dataSource = dataSource;
_rootViewController = rootViewController;
+ _carWindowDrawsAfterScreenUpdates = YES;
return self;
}
diff --git a/SmartDeviceLink/SDLStreamingMediaLifecycleManager.m b/SmartDeviceLink/SDLStreamingMediaLifecycleManager.m
index 5e47a04c0..c8cdc125f 100644
--- a/SmartDeviceLink/SDLStreamingMediaLifecycleManager.m
+++ b/SmartDeviceLink/SDLStreamingMediaLifecycleManager.m
@@ -89,6 +89,8 @@ typedef void(^SDLVideoCapabilityResponseHandler)(SDLVideoStreamingCapability *_N
@property (assign, nonatomic) CV_NULLABLE CVPixelBufferRef backgroundingPixelBuffer;
+@property (strong, nonatomic, nullable) CADisplayLink *displayLink;
+
@property (assign, nonatomic) CMTime lastPresentationTimestamp;
@end
@@ -112,11 +114,12 @@ typedef void(^SDLVideoCapabilityResponseHandler)(SDLVideoStreamingCapability *_N
if (configuration.rootViewController != nil) {
if (@available(iOS 9.0, *)) {
+ SDLLogD(@"Initializing focusable item locator");
_focusableItemManager = [[SDLFocusableItemLocator alloc] initWithViewController:configuration.rootViewController connectionManager:_connectionManager];
}
- NSUInteger framerate = ((NSNumber *)_videoEncoderSettings[(__bridge NSString *)kVTCompressionPropertyKey_ExpectedFrameRate]).unsignedIntegerValue;
- _carWindow = [[SDLCarWindow alloc] initWithStreamManager:self targetFramerate:framerate];
+ SDLLogD(@"Initializing CarWindow");
+ _carWindow = [[SDLCarWindow alloc] initWithStreamManager:self drawsAfterScreenUpdates:configuration.carWindowDrawsAfterScreenUpdates];
_carWindow.rootViewController = configuration.rootViewController;
}
@@ -316,6 +319,9 @@ typedef void(^SDLVideoCapabilityResponseHandler)(SDLVideoStreamingCapability *_N
_videoEncoder = nil;
}
+ self.displayLink.paused = YES;
+ [self.displayLink invalidate];
+
[[NSNotificationCenter defaultCenter] postNotificationName:SDLVideoStreamDidStopNotification object:nil];
if (self.shouldRestartVideoStream) {
@@ -397,6 +403,19 @@ typedef void(^SDLVideoCapabilityResponseHandler)(SDLVideoStreamingCapability *_N
}
[[NSNotificationCenter defaultCenter] postNotificationName:SDLVideoStreamDidStartNotification object:nil];
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ // And start up the displayLink
+ NSInteger targetFramerate = ((NSNumber *)self.videoEncoderSettings[(__bridge NSString *)kVTCompressionPropertyKey_ExpectedFrameRate]).integerValue;
+ SDLLogD(@"Initializing CADisplayLink with framerate: %ld", (long)targetFramerate);
+ self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(sdl_displayLinkFired:)];
+ if (SDL_SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"10")) {
+ self.displayLink.preferredFramesPerSecond = targetFramerate;
+ } else {
+ self.displayLink.frameInterval = (60 / targetFramerate);
+ }
+ [self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
+ });
}
- (void)didEnterStateVideoStreamShuttingDown {
@@ -705,6 +724,13 @@ typedef void(^SDLVideoCapabilityResponseHandler)(SDLVideoStreamingCapability *_N
}
}
+- (void)sdl_displayLinkFired:(CADisplayLink *)displayLink {
+ SDLLogV(@"DisplayLink frame fired, duration: %f, last frame timestamp: %f, target timestamp: %f", displayLink.duration, displayLink.timestamp, displayLink.targetTimestamp);
+
+ [self.touchManager syncFrame];
+ [self.carWindow syncFrame];
+}
+
- (void)sdl_sendBackgroundFrames {
SDLLogV(@"Attempting to send background frames");
if (!self.backgroundingPixelBuffer) {
diff --git a/SmartDeviceLink/SDLTouchManager.h b/SmartDeviceLink/SDLTouchManager.h
index f67ca882f..89c46f084 100644
--- a/SmartDeviceLink/SDLTouchManager.h
+++ b/SmartDeviceLink/SDLTouchManager.h
@@ -55,7 +55,12 @@ typedef void(^SDLTouchEventHandler)(SDLTouch *touch, SDLTouchType type);
* @remark
* Default is 0.05 seconds.
*/
-@property (nonatomic, assign) CGFloat movementTimeThreshold;
+@property (nonatomic, assign) CGFloat movementTimeThreshold __deprecated_msg("This is now unused, the movement time threshold is now synced to the framerate automatically");
+
+/**
+ If set to YES, the display link syncing will be ignored and `movementTimeThreshold` will be used.
+ */
+@property (assign, nonatomic) BOOL disableSyncedPanning;
/**
* @abstract
@@ -84,6 +89,11 @@ typedef void(^SDLTouchEventHandler)(SDLTouch *touch, SDLTouchType type);
*/
- (instancetype)initWithHitTester:(nullable id<SDLFocusableItemHitTester>)hitTester;
+/**
+ Called by SDLStreamingMediaManager in sync with the streaming framerate. This helps to moderate panning gestures by allowing the UI to be modified in time with the framerate.
+ */
+- (void)syncFrame;
+
@end
NS_ASSUME_NONNULL_END
diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m
index 4c9417961..c92015aac 100644
--- a/SmartDeviceLink/SDLTouchManager.m
+++ b/SmartDeviceLink/SDLTouchManager.m
@@ -82,6 +82,16 @@ static NSUInteger const MaximumNumberOfTouches = 2;
*/
@property (nonatomic, weak, nullable) id<SDLFocusableItemHitTester> hitTester;
+/**
+ The last panning touch we received
+ */
+@property (nonatomic) CGPoint lastStoredTouchLocation;
+
+/**
+ The last panning touch that we notified the developer about
+ */
+@property (nonatomic) CGPoint lastNotifiedTouchLocation;
+
@end
@implementation SDLTouchManager
@@ -97,6 +107,7 @@ static NSUInteger const MaximumNumberOfTouches = 2;
_tapTimeThreshold = 0.4f;
_tapDistanceThreshold = 50.0f;
_touchEnabled = YES;
+ _disableSyncedPanning = NO;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(sdl_onTouchEvent:) name:SDLDidReceiveTouchEventNotification object:nil];
@@ -108,6 +119,45 @@ static NSUInteger const MaximumNumberOfTouches = 2;
[self sdl_cancelSingleTapTimer];
}
+- (void)syncFrame {
+ if (!self.isTouchEnabled || (!self.touchEventHandler && !self.touchEventDelegate)) {
+ return;
+ }
+
+ if (self.performingTouchType == SDLPerformingTouchTypePanningTouch) {
+ CGPoint storedTouchLocation = self.lastStoredTouchLocation;
+ CGPoint notifiedTouchLocation = self.lastNotifiedTouchLocation;
+
+ if (CGPointEqualToPoint(storedTouchLocation, CGPointZero) ||
+ CGPointEqualToPoint(notifiedTouchLocation, CGPointZero) ||
+ CGPointEqualToPoint(storedTouchLocation, notifiedTouchLocation)) {
+ return;
+ }
+
+ if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:didReceivePanningFromPoint:toPoint:)]) {
+ [self.touchEventDelegate touchManager:self
+ didReceivePanningFromPoint:notifiedTouchLocation
+ toPoint:storedTouchLocation];
+
+ self.lastNotifiedTouchLocation = storedTouchLocation;
+ }
+ } else if (self.performingTouchType == SDLPerformingTouchTypeMultiTouch) {
+ if (self.previousPinchDistance == self.currentPinchGesture.distance) {
+ return;
+ }
+
+ if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:didReceivePinchAtCenterPoint:withScale:)]) {
+ CGFloat scale = self.currentPinchGesture.distance / self.previousPinchDistance;
+ [self.touchEventDelegate touchManager:self
+ didReceivePinchAtCenterPoint:self.currentPinchGesture.center
+ withScale:scale];
+ }
+
+ self.previousPinchDistance = self.currentPinchGesture.distance;
+
+ }
+}
+
#pragma mark - SDLDidReceiveTouchEventNotification
/**
@@ -178,9 +228,13 @@ static NSUInteger const MaximumNumberOfTouches = 2;
* @param touch Gesture information
*/
- (void)sdl_handleTouchMoved:(SDLTouch *)touch {
- if ((touch.timeStamp - self.previousTouch.timeStamp) <= (self.movementTimeThreshold * NSEC_PER_USEC)) {
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ if (self.disableSyncedPanning &&
+ ((touch.timeStamp - self.previousTouch.timeStamp) <= (self.movementTimeThreshold * NSEC_PER_USEC))) {
return; // no-op
}
+#pragma clang diagnostic pop
switch (self.performingTouchType) {
case SDLPerformingTouchTypeMultiTouch: {
@@ -193,16 +247,14 @@ static NSUInteger const MaximumNumberOfTouches = 2;
} break;
}
- if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:didReceivePinchAtCenterPoint:withScale:)]) {
- CGFloat scale = self.currentPinchGesture.distance / self.previousPinchDistance;
- [self.touchEventDelegate touchManager:self
- didReceivePinchAtCenterPoint:self.currentPinchGesture.center
- withScale:scale];
+ if (self.disableSyncedPanning) {
+ [self syncFrame];
}
-
- self.previousPinchDistance = self.currentPinchGesture.distance;
} break;
case SDLPerformingTouchTypeSingleTouch: {
+ self.lastNotifiedTouchLocation = touch.location;
+ self.lastStoredTouchLocation = touch.location;
+
_performingTouchType = SDLPerformingTouchTypePanningTouch;
if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:panningDidStartInView:atPoint:)]) {
UIView *hitView = (self.hitTester != nil) ? [self.hitTester viewForPoint:touch.location] : nil;
@@ -210,11 +262,10 @@ static NSUInteger const MaximumNumberOfTouches = 2;
}
} break;
case SDLPerformingTouchTypePanningTouch: {
- if ([self.touchEventDelegate respondsToSelector:@selector(touchManager:didReceivePanningFromPoint:toPoint:)]) {
- [self.touchEventDelegate touchManager:self
- didReceivePanningFromPoint:self.previousTouch.location
- toPoint:touch.location];
+ if (self.disableSyncedPanning) {
+ [self syncFrame];
}
+ self.lastStoredTouchLocation = touch.location;
} break;
case SDLPerformingTouchTypeNone: break;
}
@@ -316,6 +367,8 @@ static NSUInteger const MaximumNumberOfTouches = 2;
_performingTouchType = SDLPerformingTouchTypeNone;
}
+#pragma mark - Helpers
+
/**
* Saves the pinch touch gesture to the correct finger
*
diff --git a/SmartDeviceLinkTests/RPCSpecs/PayloadSpecs/SDLRPCPayloadSpec.m b/SmartDeviceLinkTests/RPCSpecs/PayloadSpecs/SDLRPCPayloadSpec.m
index f0632eb87..cde24a77a 100644
--- a/SmartDeviceLinkTests/RPCSpecs/PayloadSpecs/SDLRPCPayloadSpec.m
+++ b/SmartDeviceLinkTests/RPCSpecs/PayloadSpecs/SDLRPCPayloadSpec.m
@@ -19,7 +19,7 @@ __block NSDictionary* dict = @{SDLNameResponse:
@{SDLNameParameters:@{},
SDLNameOperationName:SDLNameDeleteCommand}};
-NSData* (^testData)() = ^NSData* {
+NSData* (^testData)(void) = ^NSData* {
NSData* jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:0];
NSData* binaryData = [NSData dataWithBytes:"PrimitiveString" length:strlen("PrimitiveString")];
diff --git a/SmartDeviceLinkTests/SDLStreamingMediaLifecycleManagerSpec.m b/SmartDeviceLinkTests/SDLStreamingMediaLifecycleManagerSpec.m
index 877c65b42..616454d97 100644
--- a/SmartDeviceLinkTests/SDLStreamingMediaLifecycleManagerSpec.m
+++ b/SmartDeviceLinkTests/SDLStreamingMediaLifecycleManagerSpec.m
@@ -7,6 +7,7 @@
#import <Nimble/Nimble.h>
#import <OCMock/OCMock.h>
+#import "SDLCarWindowViewController.h"
#import "SDLConnectionManagerType.h"
#import "SDLControlFramePayloadAudioStartServiceAck.h"
#import "SDLControlFramePayloadConstants.h"
@@ -46,7 +47,7 @@ QuickSpecBegin(SDLStreamingMediaLifecycleManagerSpec)
describe(@"the streaming media manager", ^{
__block SDLStreamingMediaLifecycleManager *streamingLifecycleManager = nil;
__block SDLStreamingMediaConfiguration *testConfiguration = [SDLStreamingMediaConfiguration insecureConfiguration];
- __block UIViewController *testViewController = [[UIViewController alloc] init];
+ __block SDLCarWindowViewController *testViewController = [[SDLCarWindowViewController alloc] init];
__block SDLFakeStreamingManagerDataSource *testDataSource = [[SDLFakeStreamingManagerDataSource alloc] init];
__block NSString *someBackgroundTitleString = nil;
__block TestConnectionManager *testConnectionManager = nil;
diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m
index 43a2f6fab..86204073c 100644
--- a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m
+++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m
@@ -44,7 +44,6 @@ describe(@"SDLTouchManager Tests", ^{
expect(touchManager.touchEventDelegate).to(beNil());
expect(@(touchManager.tapDistanceThreshold)).to(equal(@50));
expect(@(touchManager.tapTimeThreshold)).to(beCloseTo(@0.4).within(0.0001));
- expect(@(touchManager.movementTimeThreshold)).to(beCloseTo(@0.05).within(0.0001));
expect(@(touchManager.isTouchEnabled)).to(beTruthy());
});
});
@@ -441,8 +440,7 @@ describe(@"SDLTouchManager Tests", ^{
SDLTouchCoord* panStartTouchCoord = [[SDLTouchCoord alloc] init];
panStartTouchCoord.x = @(panStartPoint.x);
panStartTouchCoord.y = @(panStartPoint.y);
- double movementTimeThresholdOffset = (touchManager.movementTimeThreshold + .01) * 1000;
- NSUInteger panStartTimeStamp = ([[NSDate date] timeIntervalSince1970] * 1000) + movementTimeThresholdOffset;
+ NSUInteger panStartTimeStamp = ([[NSDate date] timeIntervalSince1970] * 1000);
SDLTouchEvent* panStartTouchEvent = [[SDLTouchEvent alloc] init];
panStartTouchEvent.coord = [NSArray arrayWithObject:panStartTouchCoord];
panStartTouchEvent.timeStamp = [NSArray arrayWithObject:@(panStartTimeStamp)];
@@ -455,7 +453,7 @@ describe(@"SDLTouchManager Tests", ^{
SDLTouchCoord* panMoveTouchCoord = [[SDLTouchCoord alloc] init];
panMoveTouchCoord.x = @(panMovePoint.x);
panMoveTouchCoord.y = @(panMovePoint.y);
- NSUInteger panMoveTimeStamp = panStartTimeStamp + movementTimeThresholdOffset;
+ NSUInteger panMoveTimeStamp = panStartTimeStamp;
SDLTouchEvent* panMoveTouchEvent = [[SDLTouchEvent alloc] init];
panMoveTouchEvent.coord = [NSArray arrayWithObject:panMoveTouchCoord];
panMoveTouchEvent.timeStamp = [NSArray arrayWithObject:@(panMoveTimeStamp)];
@@ -468,10 +466,9 @@ describe(@"SDLTouchManager Tests", ^{
SDLTouchCoord* panSecondMoveTouchCoord = [[SDLTouchCoord alloc] init];
panSecondMoveTouchCoord.x = @(panSecondMovePoint.x);
panSecondMoveTouchCoord.y = @(panSecondMovePoint.y);
- NSUInteger panSecondMoveTimeStamp = panMoveTimeStamp + movementTimeThresholdOffset;
SDLTouchEvent* panSecondMoveTouchEvent = [[SDLTouchEvent alloc] init];
panSecondMoveTouchEvent.coord = [NSArray arrayWithObject:panSecondMoveTouchCoord];
- panSecondMoveTouchEvent.timeStamp = [NSArray arrayWithObject:@(panSecondMoveTimeStamp)];
+ panSecondMoveTouchEvent.timeStamp = [NSArray arrayWithObject:@(panMoveTimeStamp)];
panSecondMoveOnTouchEvent = [[SDLOnTouchEvent alloc] init];
panSecondMoveOnTouchEvent.event = [NSArray arrayWithObject:panSecondMoveTouchEvent];
panSecondMoveOnTouchEvent.type = SDLTouchTypeMove;
@@ -481,10 +478,9 @@ describe(@"SDLTouchManager Tests", ^{
SDLTouchCoord* panEndTouchCoord = [[SDLTouchCoord alloc] init];
panEndTouchCoord.x = @(panEndPoint.x);
panEndTouchCoord.y = @(panEndPoint.y);
- NSUInteger panEndTimeStamp = panSecondMoveTimeStamp + movementTimeThresholdOffset;
SDLTouchEvent* panEndTouchEvent = [[SDLTouchEvent alloc] init];
panEndTouchEvent.coord = [NSArray arrayWithObject:panEndTouchCoord];
- panEndTouchEvent.timeStamp = [NSArray arrayWithObject:@(panEndTimeStamp)];
+ panEndTouchEvent.timeStamp = [NSArray arrayWithObject:@(panMoveTimeStamp)];
panEndOnTouchEvent = [[SDLOnTouchEvent alloc] init];
panEndOnTouchEvent.event = [NSArray arrayWithObject:panEndTouchEvent];
panEndOnTouchEvent.type = SDLTouchTypeEnd;
@@ -494,10 +490,9 @@ describe(@"SDLTouchManager Tests", ^{
SDLTouchCoord* panCancelAfterMoveTouchCoord = [[SDLTouchCoord alloc] init];
panCancelAfterMoveTouchCoord.x = @(panCancelPointAfterMove.x);
panCancelAfterMoveTouchCoord.y = @(panCancelPointAfterMove.y);
- NSUInteger panCancelAfterMoveTimeStamp = panMoveTimeStamp + movementTimeThresholdOffset;
SDLTouchEvent* panCancelAfterMoveTouchEvent = [[SDLTouchEvent alloc] init];
panCancelAfterMoveTouchEvent.coord = [NSArray arrayWithObject:panCancelAfterMoveTouchCoord];
- panCancelAfterMoveTouchEvent.timeStamp = [NSArray arrayWithObject:@(panCancelAfterMoveTimeStamp)];
+ panCancelAfterMoveTouchEvent.timeStamp = [NSArray arrayWithObject:@(panMoveTimeStamp)];
panCancelAfterMoveOnTouchEvent = [[SDLOnTouchEvent alloc] init];
panCancelAfterMoveOnTouchEvent.event = [NSArray arrayWithObject:panCancelAfterMoveTouchEvent];
panCancelAfterMoveOnTouchEvent.type = SDLTouchTypeCancel;
@@ -507,10 +502,9 @@ describe(@"SDLTouchManager Tests", ^{
SDLTouchCoord* panCancelAfterSecondMoveTouchCoord = [[SDLTouchCoord alloc] init];
panCancelAfterSecondMoveTouchCoord.x = @(panCancelPointAfterSecondMove.x);
panCancelAfterSecondMoveTouchCoord.y = @(panCancelPointAfterSecondMove.y);
- NSUInteger panCancelAfterSecondMoveTimeStamp = panEndTimeStamp;
SDLTouchEvent* panCancelAfterSecondMoveTouchEvent = [[SDLTouchEvent alloc] init];
panCancelAfterSecondMoveTouchEvent.coord = [NSArray arrayWithObject:panCancelAfterSecondMoveTouchCoord];
- panCancelAfterSecondMoveTouchEvent.timeStamp = [NSArray arrayWithObject:@(panCancelAfterSecondMoveTimeStamp)];
+ panCancelAfterSecondMoveTouchEvent.timeStamp = [NSArray arrayWithObject:@(panMoveTimeStamp)];
panCancelAfterSecondMoveOnTouchEvent = [[SDLOnTouchEvent alloc] init];
panCancelAfterSecondMoveOnTouchEvent.event = [NSArray arrayWithObject:panCancelAfterSecondMoveTouchEvent];
panCancelAfterSecondMoveOnTouchEvent.type = SDLTouchTypeCancel;
@@ -553,7 +547,9 @@ describe(@"SDLTouchManager Tests", ^{
performTouchEvent(touchManager, panStartOnTouchEvent);
performTouchEvent(touchManager, panMoveOnTouchEvent);
+ [touchManager syncFrame];
performTouchEvent(touchManager, panSecondMoveOnTouchEvent);
+ [touchManager syncFrame];
performTouchEvent(touchManager, panEndOnTouchEvent);
expectedDidCallBeginPan = YES;
@@ -632,7 +628,9 @@ describe(@"SDLTouchManager Tests", ^{
performTouchEvent(touchManager, panStartOnTouchEvent);
performTouchEvent(touchManager, panMoveOnTouchEvent);
+ [touchManager syncFrame];
performTouchEvent(touchManager, panSecondMoveOnTouchEvent);
+ [touchManager syncFrame];
performTouchEvent(touchManager, panCancelAfterMoveOnTouchEvent);
expectedDidCallBeginPan = YES;
@@ -707,11 +705,10 @@ describe(@"SDLTouchManager Tests", ^{
SDLTouchCoord* secondFingerMoveTouchCoord = [[SDLTouchCoord alloc] init];
secondFingerMoveTouchCoord.x = @(secondFingerTouchCoord.x.floatValue - 50);
secondFingerMoveTouchCoord.y = @(secondFingerTouchCoord.y.floatValue - 40);
- NSUInteger secondFingerMoveTimeStamp = secondFingerTimeStamp + ((touchManager.movementTimeThreshold + 0.1) * 1000);
SDLTouchEvent* secondFingerMoveTouchEvent = [[SDLTouchEvent alloc] init];
secondFingerMoveTouchEvent.touchEventId = @1;
secondFingerMoveTouchEvent.coord = [NSArray arrayWithObject:secondFingerMoveTouchCoord];
- secondFingerMoveTouchEvent.timeStamp = [NSArray arrayWithObject:@(secondFingerMoveTimeStamp)];
+ secondFingerMoveTouchEvent.timeStamp = [NSArray arrayWithObject:@(secondFingerTimeStamp)];
pinchMoveSecondFingerOnTouchEvent = [[SDLOnTouchEvent alloc] init];
pinchMoveSecondFingerOnTouchEvent.event = [NSArray arrayWithObject:secondFingerMoveTouchEvent];
pinchMoveSecondFingerOnTouchEvent.type = SDLTouchTypeMove;
@@ -723,11 +720,10 @@ describe(@"SDLTouchManager Tests", ^{
// Second finger end
SDLTouchCoord* secondFingerEndTouchCoord = secondFingerMoveTouchCoord;
- NSUInteger secondFingerEndTimeStamp = secondFingerMoveTimeStamp + ((touchManager.movementTimeThreshold + 0.1) * 1000);
SDLTouchEvent* secondFingerEndTouchEvent = [[SDLTouchEvent alloc] init];
secondFingerEndTouchEvent.touchEventId = @1;
secondFingerEndTouchEvent.coord = [NSArray arrayWithObject:secondFingerEndTouchCoord];
- secondFingerEndTouchEvent.timeStamp = [NSArray arrayWithObject:@(secondFingerEndTimeStamp)];
+ secondFingerEndTouchEvent.timeStamp = [NSArray arrayWithObject:@(secondFingerTimeStamp)];
pinchEndSecondFingerOnTouchEvent = [[SDLOnTouchEvent alloc] init];
pinchEndSecondFingerOnTouchEvent.event = [NSArray arrayWithObject:secondFingerEndTouchEvent];
pinchEndSecondFingerOnTouchEvent.type = SDLTouchTypeEnd;
@@ -735,11 +731,10 @@ describe(@"SDLTouchManager Tests", ^{
// First finger cancel
SDLTouchCoord* firstFingerCanceledTouchCoord = secondFingerMoveTouchCoord;
- NSUInteger firstFingerCanceledTimeStamp = secondFingerMoveTimeStamp + ((touchManager.movementTimeThreshold + 0.1) * 1000);
SDLTouchEvent* firstFingerCanceledTouchEvent = [[SDLTouchEvent alloc] init];
firstFingerCanceledTouchEvent.touchEventId = @0;
firstFingerCanceledTouchEvent.coord = [NSArray arrayWithObject:firstFingerCanceledTouchCoord];
- firstFingerCanceledTouchEvent.timeStamp = [NSArray arrayWithObject:@(firstFingerCanceledTimeStamp)];
+ firstFingerCanceledTouchEvent.timeStamp = [NSArray arrayWithObject:@(secondFingerTimeStamp)];
pinchCancelFirstFingerOnTouchEvent = [[SDLOnTouchEvent alloc] init];
pinchCancelFirstFingerOnTouchEvent.event = [NSArray arrayWithObject:firstFingerCanceledTouchEvent];
pinchCancelFirstFingerOnTouchEvent.type = SDLTouchTypeCancel;
@@ -747,11 +742,10 @@ describe(@"SDLTouchManager Tests", ^{
// Second finger cancel
SDLTouchCoord* secondFingerCanceledTouchCoord = secondFingerMoveTouchCoord;
- NSUInteger secondFingerCanceledTimeStamp = firstFingerTimeStamp + ((touchManager.movementTimeThreshold + 0.1) * 1000);
SDLTouchEvent* secondFingerCanceledTouchEvent = [[SDLTouchEvent alloc] init];
secondFingerCanceledTouchEvent.touchEventId = @1;
secondFingerCanceledTouchEvent.coord = [NSArray arrayWithObject:secondFingerCanceledTouchCoord];
- secondFingerCanceledTouchEvent.timeStamp = [NSArray arrayWithObject:@(secondFingerCanceledTimeStamp)];
+ secondFingerCanceledTouchEvent.timeStamp = [NSArray arrayWithObject:@(firstFingerTimeStamp)];
pinchCancelSecondFingerOnTouchEvent = [[SDLOnTouchEvent alloc] init];
pinchCancelSecondFingerOnTouchEvent.event = [NSArray arrayWithObject:secondFingerCanceledTouchEvent];
pinchCancelSecondFingerOnTouchEvent.type = SDLTouchTypeCancel;
@@ -799,6 +793,7 @@ describe(@"SDLTouchManager Tests", ^{
performTouchEvent(touchManager, pinchStartFirstFingerOnTouchEvent);
performTouchEvent(touchManager, pinchStartSecondFingerOnTouchEvent);
performTouchEvent(touchManager, pinchMoveSecondFingerOnTouchEvent);
+ [touchManager syncFrame];
performTouchEvent(touchManager, pinchEndSecondFingerOnTouchEvent);
expectedDidCallBeginPinch = YES;
@@ -879,6 +874,7 @@ describe(@"SDLTouchManager Tests", ^{
performTouchEvent(touchManager, pinchStartFirstFingerOnTouchEvent);
performTouchEvent(touchManager, pinchStartSecondFingerOnTouchEvent);
performTouchEvent(touchManager, pinchMoveSecondFingerOnTouchEvent);
+ [touchManager syncFrame];
performTouchEvent(touchManager, pinchCancelSecondFingerOnTouchEvent);
expectedDidCallBeginPinch = YES;