diff options
author | Joel Fischer <joeljfischer@gmail.com> | 2017-12-13 10:25:47 -0500 |
---|---|---|
committer | Joel Fischer <joeljfischer@gmail.com> | 2017-12-13 10:25:47 -0500 |
commit | 07a1c1b78a294a2e540bac75a9c74bdb415127a9 (patch) | |
tree | d6d4db9ebe6ff6b0aa652861e512a5032b7907bb | |
parent | 3fbd44329340096fab684b3f97971c883b707039 (diff) | |
download | sdl_ios-07a1c1b78a294a2e540bac75a9c74bdb415127a9.tar.gz |
Remove carwindow `sendFrame` dispatch as it’s already on the main thread
-rwxr-xr-x | SmartDeviceLink/SDLCarWindow.m | 74 |
1 files changed, 36 insertions, 38 deletions
diff --git a/SmartDeviceLink/SDLCarWindow.m b/SmartDeviceLink/SDLCarWindow.m index 4752c7ca4..a5db14ae8 100755 --- a/SmartDeviceLink/SDLCarWindow.m +++ b/SmartDeviceLink/SDLCarWindow.m @@ -60,49 +60,47 @@ NS_ASSUME_NONNULL_BEGIN } - (void)sdl_sendFrame:(CADisplayLink *)displayLink { - dispatch_async(dispatch_get_main_queue(), ^{ - if (!self.streamManager.isVideoConnected || self.streamManager.isVideoStreamingPaused) { - return; - } - - if (self.sameFrameCounter == 30 && ((displayLink.timestamp - self.lastMd5HashTimestamp) <= 0.1)) { - SDLLogD(@"Paused CarWindow, no frame changes in over a second"); - return; - } + if (!self.streamManager.isVideoConnected || self.streamManager.isVideoStreamingPaused) { + return; + } + + if (self.sameFrameCounter == 30 && ((displayLink.timestamp - self.lastMd5HashTimestamp) <= 0.1)) { + SDLLogD(@"Paused CarWindow, no frame changes in over a second"); + return; + } + + if (self.isLockScreenMoving) { + SDLLogD(@"Paused CarWindow, lock screen moving"); + return; + } - if (self.isLockScreenMoving) { - SDLLogD(@"Paused CarWindow, lock screen moving"); + self.lastMd5HashTimestamp = displayLink.timestamp; + + CGRect bounds = self.rootViewController.view.bounds; + + UIGraphicsBeginImageContextWithOptions(bounds.size, YES, 1.0f); + [self.rootViewController.view drawViewHierarchyInRect:bounds afterScreenUpdates:YES]; + UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); + UIGraphicsEndImageContext(); + + CGImageRef imageRef = screenshot.CGImage; + + // We use MD5 Hashes to determine if we are sending the same frame over and over. If so, we will only send 30. + NSString *currentMd5Hash = [self.class sdl_md5HashForImageRef:imageRef]; + if ([currentMd5Hash isEqualToString:self.previousMd5Hash]) { + if (self.sameFrameCounter == 30) { return; } - - self.lastMd5HashTimestamp = displayLink.timestamp; - - CGRect bounds = self.rootViewController.view.bounds; - - UIGraphicsBeginImageContextWithOptions(bounds.size, YES, 1.0f); - [self.rootViewController.view drawViewHierarchyInRect:bounds afterScreenUpdates:YES]; - UIImage *screenshot = UIGraphicsGetImageFromCurrentImageContext(); - UIGraphicsEndImageContext(); - - CGImageRef imageRef = screenshot.CGImage; - - // We use MD5 Hashes to determine if we are sending the same frame over and over. If so, we will only send 30. - NSString *currentMd5Hash = [self.class sdl_md5HashForImageRef:imageRef]; - if ([currentMd5Hash isEqualToString:self.previousMd5Hash]) { - if (self.sameFrameCounter == 30) { - return; - } - self.sameFrameCounter++; - } else { - self.sameFrameCounter = 0; - } + self.sameFrameCounter++; + } else { + self.sameFrameCounter = 0; + } - self.previousMd5Hash = currentMd5Hash; + self.previousMd5Hash = currentMd5Hash; - CVPixelBufferRef pixelBuffer = [self.class sdl_pixelBufferForImageRef:imageRef usingPool:self.streamManager.pixelBufferPool]; - [self.streamManager sendVideoData:pixelBuffer]; - CVPixelBufferRelease(pixelBuffer); - }); + CVPixelBufferRef pixelBuffer = [self.class sdl_pixelBufferForImageRef:imageRef usingPool:self.streamManager.pixelBufferPool]; + [self.streamManager sendVideoData:pixelBuffer]; + CVPixelBufferRelease(pixelBuffer); } #pragma mark - SDLNavigationLockScreenManager Notifications |