From 6d000814d576f571931d4b3efa3354d27b0e0ff7 Mon Sep 17 00:00:00 2001 From: Luis Nafarrate Date: Tue, 23 Jul 2019 14:53:17 -0500 Subject: [PATCH 1/9] Adding new properties 'pixel', 'density' and 'scale' in 'SDLVideoStreamingCapability'. --- SmartDeviceLink/SDLRPCParameterNames.h | 3 ++ SmartDeviceLink/SDLRPCParameterNames.m | 3 ++ SmartDeviceLink/SDLVideoStreamingCapability.h | 23 ++++++++++++++- SmartDeviceLink/SDLVideoStreamingCapability.m | 29 ++++++++++++++++++- 4 files changed, 56 insertions(+), 2 deletions(-) diff --git a/SmartDeviceLink/SDLRPCParameterNames.h b/SmartDeviceLink/SDLRPCParameterNames.h index 6e346e357..a27b3c792 100644 --- a/SmartDeviceLink/SDLRPCParameterNames.h +++ b/SmartDeviceLink/SDLRPCParameterNames.h @@ -135,6 +135,7 @@ extern SDLRPCParameterName const SDLRPCParameterNameDestinationETA; extern SDLRPCParameterName const SDLRPCParameterNameDetails; extern SDLRPCParameterName const SDLRPCParameterNameDeviceInfo; extern SDLRPCParameterName const SDLRPCParameterNameDeviceStatus; +extern SDLRPCParameterName const SDLRPCParameterNameDiagonalScreenSize; extern SDLRPCParameterName const SDLRPCParameterNameDialNumberEnabled; extern SDLRPCParameterName const SDLRPCParameterNameDIDLocation; extern SDLRPCParameterName const SDLRPCParameterNameDIDResult; @@ -434,6 +435,7 @@ extern SDLRPCParameterName const SDLRPCParameterNamePhoneCall; extern SDLRPCParameterName const SDLRPCParameterNamePhoneCapability; extern SDLRPCParameterName const SDLRPCParameterNamePhoneNumber; extern SDLRPCParameterName const SDLRPCParameterNamePhoneRoaming; +extern SDLRPCParameterName const SDLRPCParameterNamePixelPerInch; extern SDLRPCParameterName const SDLRPCParameterNamePlaylistName; extern SDLRPCParameterName const SDLRPCParameterNamePlayTone; extern SDLRPCParameterName const SDLRPCParameterNamePosition; @@ -505,6 +507,7 @@ extern SDLRPCParameterName const SDLRPCParameterNameRPM; extern SDLRPCParameterName const SDLRPCParameterNameRadioText; extern SDLRPCParameterName const SDLRPCParameterNameSamplingRate; extern SDLRPCParameterName const SDLRPCParameterNameSatellites; +extern SDLRPCParameterName const SDLRPCParameterNameScale; extern SDLRPCParameterName const SDLRPCParameterNameScreenParams; extern SDLRPCParameterName const SDLRPCParameterNameScrollableMessageBody; extern SDLRPCParameterName const SDLRPCParameterNameSDLVersion; diff --git a/SmartDeviceLink/SDLRPCParameterNames.m b/SmartDeviceLink/SDLRPCParameterNames.m index 0aae8440d..e23693ef2 100644 --- a/SmartDeviceLink/SDLRPCParameterNames.m +++ b/SmartDeviceLink/SDLRPCParameterNames.m @@ -133,6 +133,7 @@ SDLRPCParameterName const SDLRPCParameterNameDeviceInfo = @"deviceInfo"; SDLRPCParameterName const SDLRPCParameterNameDeviceStatus = @"deviceStatus"; SDLRPCParameterName const SDLRPCParameterNameDetails = @"details"; +SDLRPCParameterName const SDLRPCParameterNameDiagonalScreenSize = @"diagonalScreenSize"; SDLRPCParameterName const SDLRPCParameterNameDialNumberEnabled = @"dialNumberEnabled"; SDLRPCParameterName const SDLRPCParameterNameDIDLocation = @"didLocation"; SDLRPCParameterName const SDLRPCParameterNameDIDResult = @"didResult"; @@ -428,6 +429,7 @@ SDLRPCParameterName const SDLRPCParameterNamePhoneCapability = @"phoneCapability"; SDLRPCParameterName const SDLRPCParameterNamePhoneNumber = @"phoneNumber"; SDLRPCParameterName const SDLRPCParameterNamePhoneRoaming = @"phoneRoaming"; +SDLRPCParameterName const SDLRPCParameterNamePixelPerInch = @"pixelPerInch"; SDLRPCParameterName const SDLRPCParameterNamePrimaryColor = @"primaryColor"; SDLRPCParameterName const SDLRPCParameterNamePlaylistName = @"playlistName"; SDLRPCParameterName const SDLRPCParameterNamePlayTone = @"playTone"; @@ -500,6 +502,7 @@ SDLRPCParameterName const SDLRPCParameterNameRadioText = @"RT"; SDLRPCParameterName const SDLRPCParameterNameSamplingRate = @"samplingRate"; SDLRPCParameterName const SDLRPCParameterNameSatellites = @"satellites"; +SDLRPCParameterName const SDLRPCParameterNameScale = @"scale"; SDLRPCParameterName const SDLRPCParameterNameScreenParams = @"screenParams"; SDLRPCParameterName const SDLRPCParameterNameScrollableMessageBody = @"scrollableMessageBody"; SDLRPCParameterName const SDLRPCParameterNameSDLVersion = @"sdlVersion"; diff --git a/SmartDeviceLink/SDLVideoStreamingCapability.h b/SmartDeviceLink/SDLVideoStreamingCapability.h index c15c73a8f..be25baa7f 100644 --- a/SmartDeviceLink/SDLVideoStreamingCapability.h +++ b/SmartDeviceLink/SDLVideoStreamingCapability.h @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN */ @interface SDLVideoStreamingCapability : SDLRPCStruct -- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray *)supportedFormats hapticDataSupported:(BOOL)hapticDataSupported; +- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray *)supportedFormats hapticDataSupported:(BOOL)hapticDataSupported diagonalScreenSize:(float)diagonalScreenSize pixelPerInch:(float)pixelPerInch scale:(float)scale; /** The preferred resolution of a video stream for decoding and rendering on HMI @@ -48,6 +48,27 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nullable, strong, nonatomic) NSNumber *hapticSpatialDataSupported; +/** + The diagonal screen size in inches. + + Optional + */ +@property (nullable, strong, nonatomic) NSNumber *diagonalScreenSize; + +/** + PPI is the diagonal resolution in pixels divided by the diagonal screen size in inches. + + Optional + */ +@property (nullable, strong, nonatomic) NSNumber *pixelPerInch; + +/** + The scaling factor the app should use to change the size of the projecting view. + + Optional + */ +@property (nullable, strong, nonatomic) NSNumber *scale; + @end NS_ASSUME_NONNULL_END diff --git a/SmartDeviceLink/SDLVideoStreamingCapability.m b/SmartDeviceLink/SDLVideoStreamingCapability.m index 8f2d0d630..0c50b817e 100644 --- a/SmartDeviceLink/SDLVideoStreamingCapability.m +++ b/SmartDeviceLink/SDLVideoStreamingCapability.m @@ -17,7 +17,7 @@ @implementation SDLVideoStreamingCapability -- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray *)supportedFormats hapticDataSupported:(BOOL)hapticDataSupported { +- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray *)supportedFormats hapticDataSupported:(BOOL)hapticDataSupported diagonalScreenSize:(float)diagonalScreenSize pixelPerInch:(float)pixelPerInch scale:(float)scale { self = [self init]; if (!self) { return self; @@ -27,6 +27,9 @@ - (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)prefe self.preferredResolution = preferredResolution; self.supportedFormats = supportedFormats; self.hapticSpatialDataSupported = @(hapticDataSupported); + self.diagonalScreenSize = @(diagonalScreenSize); + self.pixelPerInch = @(pixelPerInch); + self.scale = @(scale); return self; } @@ -63,6 +66,30 @@ - (void)setHapticSpatialDataSupported:(nullable NSNumber *)hapticSpatia return [self.store sdl_objectForName:SDLRPCParameterNameHapticSpatialDataSupported ofClass:NSNumber.class error:nil]; } +- (void)setDiagonalScreenSize:(nullable NSNumber *)diagonalScreenSize { + [self.store sdl_setObject:diagonalScreenSize forName:SDLRPCParameterNameDiagonalScreenSize]; +} + +- (nullable NSNumber *)diagonalScreenSize { + return [self.store sdl_objectForName:SDLRPCParameterNameDiagonalScreenSize ofClass:NSNumber.class error:nil]; +} + +- (void)setPixelPerInch:(nullable NSNumber *)pixelPerInch { + [self.store sdl_setObject:pixelPerInch forName:SDLRPCParameterNamePixelPerInch]; +} + +- (nullable NSNumber *)pixelPerInch { + return [self.store sdl_objectForName:SDLRPCParameterNamePixelPerInch ofClass:NSNumber.class error:nil]; +} + +- (void)setScale:(nullable NSNumber *)scale { + [self.store sdl_setObject:scale forName:SDLRPCParameterNameScale]; +} + +- (nullable NSNumber *)scale { + return [self.store sdl_objectForName:SDLRPCParameterNameScale ofClass:NSNumber.class error:nil]; +} + @end NS_ASSUME_NONNULL_END From addae68202d0b72d363e5664b4109eef7ba6a056 Mon Sep 17 00:00:00 2001 From: Luis Nafarrate Date: Tue, 23 Jul 2019 15:09:14 -0500 Subject: [PATCH 2/9] Accessing SDLVideoStreamingCapability from SDLCarWindow, to apply changes in the view controller's size to the accepted video resolution divided by the scale. --- SmartDeviceLink/SDLCarWindow.m | 14 +++++++++----- .../SDLStreamingVideoLifecycleManager.h | 2 ++ .../SDLStreamingVideoLifecycleManager.m | 3 +++ 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/SmartDeviceLink/SDLCarWindow.m b/SmartDeviceLink/SDLCarWindow.m index 5e2e02557..25046545a 100755 --- a/SmartDeviceLink/SDLCarWindow.m +++ b/SmartDeviceLink/SDLCarWindow.m @@ -21,6 +21,7 @@ #import "SDLStreamingMediaConfiguration.h" #import "SDLStreamingVideoLifecycleManager.h" #import "SDLStreamingMediaManagerConstants.h" +#import "SDLVideoStreamingCapability.h" NS_ASSUME_NONNULL_BEGIN @@ -71,7 +72,7 @@ - (void)syncFrame { return; } - CGRect bounds = self.rootViewController.view.bounds; + CGRect bounds = CGRectMake(0, 0, self.streamManager.screenSize.width, self.streamManager.screenSize.height); UIGraphicsBeginImageContextWithOptions(bounds.size, YES, 1.0f); switch (self.renderingType) { @@ -120,10 +121,13 @@ - (void)sdl_didReceiveVideoStreamStarted:(NSNotification *)notification { dispatch_async(dispatch_get_main_queue(), ^{ // If the video stream has started, we want to resize the streamingViewController to the size from the RegisterAppInterface - self.rootViewController.view.frame = CGRectMake(0, 0, self.streamManager.screenSize.width, self.streamManager.screenSize.height); - self.rootViewController.view.bounds = self.rootViewController.view.frame; - - SDLLogD(@"Video stream started, setting CarWindow frame to: %@", NSStringFromCGRect(self.rootViewController.view.bounds)); + float scale = self.streamManager.videoStreamingCapability.scale.floatValue; + if (scale > 0) { + self.rootViewController.view.frame = CGRectMake(0, 0, self.streamManager.screenSize.width / scale, self.streamManager.screenSize.height / scale); + self.rootViewController.view.bounds = self.rootViewController.view.frame; + + SDLLogD(@"Video stream started, setting CarWindow frame to: %@", NSStringFromCGRect(self.rootViewController.view.bounds)); + } }); } diff --git a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.h b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.h index 1d1350469..b44edef04 100644 --- a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.h +++ b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.h @@ -22,6 +22,7 @@ @class SDLStateMachine; @class SDLStreamingMediaConfiguration; @class SDLTouchManager; +@class SDLVideoStreamingCapability; @protocol SDLConnectionManagerType; @protocol SDLFocusableItemLocatorType; @@ -35,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN @property (strong, nonatomic, readonly) SDLStateMachine *videoStreamStateMachine; @property (strong, nonatomic, readonly) SDLVideoStreamManagerState *currentVideoStreamState; +@property (strong, nonatomic, readonly) SDLVideoStreamingCapability *videoStreamingCapability; @property (strong, nonatomic, readonly) SDLStateMachine *appStateMachine; @property (strong, nonatomic, readonly) SDLAppState *currentAppState; diff --git a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m index f483866ec..bd190f598 100644 --- a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m +++ b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m @@ -58,6 +58,8 @@ @interface SDLStreamingVideoLifecycleManager() @property (assign, nonatomic, readonly, getter=isAppStateVideoStreamCapable) BOOL appStateVideoStreamCapable; @property (assign, nonatomic, readonly, getter=isHmiStateVideoStreamCapable) BOOL hmiStateVideoStreamCapable; +@property (strong, nonatomic, readwrite) SDLVideoStreamingCapability *videoStreamingCapability; + @property (strong, nonatomic, readwrite) SDLStateMachine *videoStreamStateMachine; @property (strong, nonatomic, readwrite) SDLStateMachine *appStateMachine; @@ -707,6 +709,7 @@ - (void)sdl_requestVideoCapabilities:(SDLVideoCapabilityResponseHandler)response } SDLVideoStreamingCapability *videoCapability = ((SDLGetSystemCapabilityResponse *)response).systemCapability.videoStreamingCapability; + self.videoStreamingCapability = videoCapability; SDLLogD(@"Video capabilities response received: %@", videoCapability); responseHandler(videoCapability); }]; From a115a48af32b1dc91746cd96fe80d87375f10985 Mon Sep 17 00:00:00 2001 From: Luis Nafarrate Date: Wed, 24 Jul 2019 19:42:28 -0500 Subject: [PATCH 3/9] Calculating the correct coordinates by dividing the incoming coords with the scale. --- .../SDLStreamingVideoLifecycleManager.m | 1 + SmartDeviceLink/SDLTouchManager.h | 6 ++++++ SmartDeviceLink/SDLTouchManager.m | 17 ++++++++++++++++- 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m index bd190f598..205ab8fab 100644 --- a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m +++ b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m @@ -710,6 +710,7 @@ - (void)sdl_requestVideoCapabilities:(SDLVideoCapabilityResponseHandler)response SDLVideoStreamingCapability *videoCapability = ((SDLGetSystemCapabilityResponse *)response).systemCapability.videoStreamingCapability; self.videoStreamingCapability = videoCapability; + self.touchManager.videoStreamingCapability = videoCapability; SDLLogD(@"Video capabilities response received: %@", videoCapability); responseHandler(videoCapability); }]; diff --git a/SmartDeviceLink/SDLTouchManager.h b/SmartDeviceLink/SDLTouchManager.h index 185aae174..58b4254ca 100644 --- a/SmartDeviceLink/SDLTouchManager.h +++ b/SmartDeviceLink/SDLTouchManager.h @@ -14,6 +14,7 @@ @protocol SDLTouchManagerDelegate; @class SDLTouch; +@class SDLVideoStreamingCapability; NS_ASSUME_NONNULL_BEGIN @@ -78,6 +79,11 @@ typedef void(^SDLTouchEventHandler)(SDLTouch *touch, SDLTouchType type); */ @property (nonatomic, assign, getter=isTouchEnabled) BOOL touchEnabled; +/** + Provides all video streaming capabilities defined in the HMI. + */ +@property (strong, nonatomic) SDLVideoStreamingCapability *videoStreamingCapability; + /** * @abstract * Cancels pending touch event timers that may be in progress. diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index 9a66d81e4..1affc03b3 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -22,6 +22,7 @@ #import "SDLTouchCoord.h" #import "SDLTouchEvent.h" #import "SDLTouchManagerDelegate.h" +#import "SDLVideoStreamingCapability.h" NS_ASSUME_NONNULL_BEGIN @@ -180,7 +181,8 @@ - (void)sdl_onTouchEvent:(SDLRPCNotificationNotification *)notification { return; } - SDLOnTouchEvent* onTouchEvent = (SDLOnTouchEvent*)notification.notification; + SDLOnTouchEvent *onTouchEvent = (SDLOnTouchEvent *)notification.notification; + onTouchEvent = [self applyScaleToEventCoordinates:onTouchEvent]; SDLTouchType touchType = onTouchEvent.type; [onTouchEvent.event enumerateObjectsUsingBlock:^(SDLTouchEvent *touchEvent, NSUInteger idx, BOOL *stop) { @@ -208,6 +210,19 @@ - (void)sdl_onTouchEvent:(SDLRPCNotificationNotification *)notification { }]; } +- (SDLOnTouchEvent *)applyScaleToEventCoordinates:(SDLOnTouchEvent *)onTouchEvent { + float scale = self.videoStreamingCapability.scale.floatValue; + if (scale > 0) { + for (SDLTouchEvent *touchEvent in onTouchEvent.event) { + for (SDLTouchCoord *coord in touchEvent.coord) { + coord.x = @(coord.x.floatValue / scale); + coord.y = @(coord.y.floatValue / scale); + } + } + } + return onTouchEvent; +} + #pragma mark - Private /** * Handles a BEGIN touch event sent by Core From 4e5b88ca3278731f6798911665b4c19519c5e349 Mon Sep 17 00:00:00 2001 From: Luis Nafarrate Date: Wed, 24 Jul 2019 21:38:30 -0500 Subject: [PATCH 4/9] Fixing tests for new changes in implementation for 'Pixel density and Scale' proposal. --- .../DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m | 9 ++++++++- .../RPCSpecs/StructSpecs/SDLSystemCapabilitySpec.m | 7 +++++-- .../StructSpecs/SDLVideoStreamingCapabilitySpec.m | 5 ++++- 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m index 872f5eb72..dff1c33bd 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m @@ -446,6 +446,9 @@ __block void (^sendNotificationForHMILevel)(SDLHMILevel hmiLevel, SDLVideoStream __block int32_t maxBitrate = 0; __block NSArray *testFormats = nil; __block BOOL testHapticsSupported = NO; + __block float diagonalScreenSize = 0.0; + __block float pixelPerInch = 0.0; + __block float scale = 0.0; beforeEach(^{ SDLGetSystemCapabilityResponse *response = [[SDLGetSystemCapabilityResponse alloc] init]; @@ -457,7 +460,11 @@ __block void (^sendNotificationForHMILevel)(SDLHMILevel hmiLevel, SDLVideoStream maxBitrate = 12345; testFormats = @[[[SDLVideoStreamingFormat alloc] initWithCodec:SDLVideoStreamingCodecH265 protocol:SDLVideoStreamingProtocolRTMP], [[SDLVideoStreamingFormat alloc] initWithCodec:SDLVideoStreamingCodecH264 protocol:SDLVideoStreamingProtocolRTP]]; testHapticsSupported = YES; - response.systemCapability.videoStreamingCapability = [[SDLVideoStreamingCapability alloc] initWithPreferredResolution:resolution maxBitrate:maxBitrate supportedFormats:testFormats hapticDataSupported:testHapticsSupported]; + diagonalScreenSize = 22.0; + pixelPerInch = 96.0; + scale = 1.0; + + response.systemCapability.videoStreamingCapability = [[SDLVideoStreamingCapability alloc] initWithPreferredResolution:resolution maxBitrate:maxBitrate supportedFormats:testFormats hapticDataSupported:testHapticsSupported diagonalScreenSize:diagonalScreenSize pixelPerInch:pixelPerInch scale:scale]; [testConnectionManager respondToLastRequestWithResponse:response]; }); diff --git a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLSystemCapabilitySpec.m b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLSystemCapabilitySpec.m index ea41d0163..1f16945c9 100755 --- a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLSystemCapabilitySpec.m +++ b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLSystemCapabilitySpec.m @@ -33,7 +33,7 @@ testNavigationCapability = [[SDLNavigationCapability alloc] initWithSendLocation:YES waypoints:NO]; testPhoneCapability = [[SDLPhoneCapability alloc] initWithDialNumber:YES]; testRemoteControlCapabilities = [[SDLRemoteControlCapabilities alloc] initWithClimateControlCapabilities:nil radioControlCapabilities:nil buttonCapabilities:nil seatControlCapabilities:nil audioControlCapabilities:nil hmiSettingsControlCapabilities:nil lightControlCapabilities:nil]; - testVideoStreamingCapability = [[SDLVideoStreamingCapability alloc] initWithPreferredResolution:[[SDLImageResolution alloc] initWithWidth:50 height:50] maxBitrate:5 supportedFormats:@[] hapticDataSupported:false]; + testVideoStreamingCapability = [[SDLVideoStreamingCapability alloc] initWithPreferredResolution:[[SDLImageResolution alloc] initWithWidth:50 height:50] maxBitrate:5 supportedFormats:@[] hapticDataSupported:false diagonalScreenSize:22.0 pixelPerInch:96.0 scale:1.0]; }); it(@"Should set and get correctly", ^ { @@ -128,6 +128,9 @@ int32_t maxBitrate = 100; NSNumber *hapticDataSupported = @YES; + float diagonalScreenSize = 22.0; + float pixelPerInch = 96.0; + float scale = 1.0; SDLVideoStreamingFormat *format1 = [[SDLVideoStreamingFormat alloc] init]; format1.codec = SDLVideoStreamingCodecH264; @@ -139,7 +142,7 @@ NSArray *formatArray = @[format1, format2]; - SDLVideoStreamingCapability *testVidStruct = [[SDLVideoStreamingCapability alloc] initWithPreferredResolution:resolution maxBitrate:maxBitrate supportedFormats:formatArray hapticDataSupported:hapticDataSupported]; + SDLVideoStreamingCapability *testVidStruct = [[SDLVideoStreamingCapability alloc] initWithPreferredResolution:resolution maxBitrate:maxBitrate supportedFormats:formatArray hapticDataSupported:hapticDataSupported diagonalScreenSize:diagonalScreenSize pixelPerInch:pixelPerInch scale:scale]; SDLSystemCapability *testStruct = [[SDLSystemCapability alloc] initWithVideoStreamingCapability:testVidStruct]; expect(testStruct.systemCapabilityType).to(equal(SDLSystemCapabilityTypeVideoStreaming)); diff --git a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLVideoStreamingCapabilitySpec.m b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLVideoStreamingCapabilitySpec.m index 7c83fe99b..0223e23cd 100644 --- a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLVideoStreamingCapabilitySpec.m +++ b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLVideoStreamingCapabilitySpec.m @@ -69,6 +69,9 @@ int32_t maxBitrate = 100; NSNumber *hapticDataSupported = @YES; + float diagonalScreenSize = 22.0; + float pixelPerInch = 96.0; + float scale = 1.0; SDLVideoStreamingFormat *format1 = [[SDLVideoStreamingFormat alloc] init]; format1.codec = SDLVideoStreamingCodecH264; @@ -80,7 +83,7 @@ NSArray *formatArray = @[format1, format2]; - SDLVideoStreamingCapability *testStruct = [[SDLVideoStreamingCapability alloc] initWithPreferredResolution:resolution maxBitrate:maxBitrate supportedFormats:formatArray hapticDataSupported:hapticDataSupported]; + SDLVideoStreamingCapability *testStruct = [[SDLVideoStreamingCapability alloc] initWithPreferredResolution:resolution maxBitrate:maxBitrate supportedFormats:formatArray hapticDataSupported:hapticDataSupported diagonalScreenSize:diagonalScreenSize pixelPerInch:pixelPerInch scale:scale]; expect(testStruct.preferredResolution).to(equal(resolution)); expect(testStruct.maxBitrate).to(equal(maxBitrate)); From 6f46e1e1a694b6853b9649f839fd7487e97cd590 Mon Sep 17 00:00:00 2001 From: Luis Nafarrate Date: Thu, 25 Jul 2019 00:45:06 -0500 Subject: [PATCH 5/9] Adding Unit Tests for Pixel density and Scale proposal. --- .../SDLStreamingVideoLifecycleManagerSpec.m | 6 +++ .../SDLVideoStreamingCapabilitySpec.m | 3 ++ .../Touches/SDLTouchManagerSpec.m | 54 ++++++++++++++++--- 3 files changed, 57 insertions(+), 6 deletions(-) diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m index dff1c33bd..29ab96ee0 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m @@ -491,6 +491,12 @@ __block void (^sendNotificationForHMILevel)(SDLHMILevel hmiLevel, SDLVideoStream expect(preferredResolution.resolutionHeight).to(equal(@69)); expect(preferredResolution.resolutionWidth).to(equal(@42)); }); + + it(@"should have correct video streaming capability values", ^{ + expect(streamingLifecycleManager.videoStreamingCapability.diagonalScreenSize).to(equal(22.0)); + expect(streamingLifecycleManager.videoStreamingCapability.pixelPerInch).to(equal(96.0)); + expect(streamingLifecycleManager.videoStreamingCapability.scale).to(equal(1.0)); + }); }); }); }); diff --git a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLVideoStreamingCapabilitySpec.m b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLVideoStreamingCapabilitySpec.m index 0223e23cd..82bd0791d 100644 --- a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLVideoStreamingCapabilitySpec.m +++ b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLVideoStreamingCapabilitySpec.m @@ -89,6 +89,9 @@ expect(testStruct.maxBitrate).to(equal(maxBitrate)); expect(testStruct.supportedFormats).to(equal(formatArray)); expect(testStruct.hapticSpatialDataSupported).to(equal(hapticDataSupported)); + expect(testStruct.diagonalScreenSize).to(equal(diagonalScreenSize)); + expect(testStruct.pixelPerInch).to(equal(pixelPerInch)); + expect(testStruct.scale).to(equal(scale)); }); }); diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m index 25fad6316..46c108fa5 100644 --- a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m @@ -23,6 +23,8 @@ #import "SDLTouchManagerDelegate.h" #import "SDLTouchType.h" #import "SDLTouch.h" +#import "SDLVideoStreamingCapability.h" +#import "SDLImageResolution.h" @interface SDLTouchManager () @@ -214,6 +216,7 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent describe(@"When receiving a tap gesture", ^{ __block SDLTouchCoord* firstTouchCoord; + __block SDLTouchCoord* firstTouchCoordEnd; __block NSUInteger firstTouchTimeStamp; __block SDLOnTouchEvent* firstOnTouchEventStart; __block SDLOnTouchEvent* firstOnTouchEventEnd; @@ -223,19 +226,24 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent firstTouchCoord.x = @(controlPoint.x); firstTouchCoord.y = @(controlPoint.y); firstTouchTimeStamp = [[NSDate date] timeIntervalSince1970] * 1000.0; + + firstTouchCoordEnd = firstTouchCoord.copy; - SDLTouchEvent* touchEvent = [[SDLTouchEvent alloc] init]; - touchEvent.touchEventId = @0; - touchEvent.coord = [NSArray arrayWithObject:firstTouchCoord]; - touchEvent.timeStamp = [NSArray arrayWithObject:@(firstTouchTimeStamp)]; + SDLTouchEvent *touchEventStart = [[SDLTouchEvent alloc] init]; + touchEventStart.touchEventId = @0; + touchEventStart.coord = [NSArray arrayWithObject:firstTouchCoord]; + touchEventStart.timeStamp = [NSArray arrayWithObject:@(firstTouchTimeStamp)]; + + SDLTouchEvent *touchEventEnd = touchEventStart.copy; + touchEventEnd.coord = [NSArray arrayWithObject:firstTouchCoordEnd]; firstOnTouchEventStart = [[SDLOnTouchEvent alloc] init]; firstOnTouchEventStart.type = SDLTouchTypeBegin; - firstOnTouchEventStart.event = [NSArray arrayWithObject:touchEvent]; + firstOnTouchEventStart.event = [NSArray arrayWithObject:touchEventStart]; firstOnTouchEventEnd = [[SDLOnTouchEvent alloc] init]; firstOnTouchEventEnd.type = SDLTouchTypeEnd; - firstOnTouchEventEnd.event = [NSArray arrayWithObject:touchEvent]; + firstOnTouchEventEnd.event = [NSArray arrayWithObject:touchEventEnd]; }); describe(@"when receiving a single tap", ^{ @@ -256,6 +264,40 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent expectedDidCallSingleTap = YES; expectedNumTimesHandlerCalled = 2; }); + + it(@"should correctly use scale = 1.5 to calculate coordinates", ^{ + singleTapTests = ^(NSInvocation* invocation) { + CGPoint point; + [invocation getArgument:&point atIndex:4]; + controlPoint = CGPointMake(66.666664123535156, 133.33332824707031); + expect(@(CGPointEqualToPoint(point, controlPoint))).to(beTruthy()); + }; + + touchManager.videoStreamingCapability = [[SDLVideoStreamingCapability alloc] initWithPreferredResolution:[[SDLImageResolution alloc] initWithWidth:50 height:50] maxBitrate:5 supportedFormats:@[] hapticDataSupported:false diagonalScreenSize:22.0 pixelPerInch:96.0 scale:1.5]; + + performTouchEvent(touchManager, firstOnTouchEventStart); + performTouchEvent(touchManager, firstOnTouchEventEnd); + + expectedDidCallSingleTap = YES; + expectedNumTimesHandlerCalled = 2; + }); + + it(@"should correctly use scale = 0.75 to calculate coordinates", ^{ + singleTapTests = ^(NSInvocation* invocation) { + CGPoint point; + [invocation getArgument:&point atIndex:4]; + controlPoint = CGPointMake(133.33332824707031, 266.66665649414063); + expect(@(CGPointEqualToPoint(point, controlPoint))).to(beTruthy()); + }; + + touchManager.videoStreamingCapability = [[SDLVideoStreamingCapability alloc] initWithPreferredResolution:[[SDLImageResolution alloc] initWithWidth:50 height:50] maxBitrate:5 supportedFormats:@[] hapticDataSupported:false diagonalScreenSize:22.0 pixelPerInch:96.0 scale:0.75]; + + performTouchEvent(touchManager, firstOnTouchEventStart); + performTouchEvent(touchManager, firstOnTouchEventEnd); + + expectedDidCallSingleTap = YES; + expectedNumTimesHandlerCalled = 2; + }); }); describe(@"when receiving a single tap with small movement", ^{ From 05ed747a7a58c388c6f12e8226d387710d7524fa Mon Sep 17 00:00:00 2001 From: Luis Nafarrate Date: Thu, 25 Jul 2019 01:59:46 -0500 Subject: [PATCH 6/9] Fixing unit tests. --- .../UtilitiesSpecs/Touches/SDLTouchManagerSpec.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m index c1c9d8897..60c43adec 100644 --- a/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m +++ b/SmartDeviceLinkTests/UtilitiesSpecs/Touches/SDLTouchManagerSpec.m @@ -351,6 +351,10 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent expectedDidCallSingleTap = YES; expectedNumTimesHandlerCalled = 2; }); + + afterEach(^{ + touchManager.videoStreamingCapability.scale = @(1.0); + }); }); describe(@"when receiving a single tap with small movement", ^{ @@ -397,10 +401,6 @@ __block void (^performTouchEvent)(SDLTouchManager* touchManager, SDLOnTouchEvent expectedDidCallSingleTap = YES; expectedNumTimesHandlerCalled = 3; - - expect(didCallSingleTap).withTimeout((touchManager.tapTimeThreshold + additionalWaitTime)).toEventually(expectedDidCallSingleTap ? beTrue() : beFalse()); - - expect(numTimesHandlerCalled).to(equal(@(expectedNumTimesHandlerCalled))); }); }); From fcf51e38d7060d0f61c607e8a0c123cf3ff6cdc2 Mon Sep 17 00:00:00 2001 From: Luis Nafarrate Date: Mon, 5 Aug 2019 13:47:25 -0500 Subject: [PATCH 7/9] Addressing comment in PR to copy OnTouchEvent before modification. --- SmartDeviceLink/SDLTouchManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index 09175ff54..27e080849 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -186,7 +186,7 @@ - (void)sdl_onTouchEvent:(SDLRPCNotificationNotification *)notification { } SDLOnTouchEvent *onTouchEvent = (SDLOnTouchEvent *)notification.notification; - onTouchEvent = [self applyScaleToEventCoordinates:onTouchEvent]; + onTouchEvent = [self applyScaleToEventCoordinates:onTouchEvent.copy]; SDLTouchType touchType = onTouchEvent.type; [onTouchEvent.event enumerateObjectsUsingBlock:^(SDLTouchEvent *touchEvent, NSUInteger idx, BOOL *stop) { From 31d9165dadceb2d27bcc711c02d29788948e59c2 Mon Sep 17 00:00:00 2001 From: Luis Nafarrate Date: Fri, 9 Aug 2019 14:53:44 -0500 Subject: [PATCH 8/9] Fixing video frame dimensions, applying scale. Now video frame and video streaming source match size. --- SmartDeviceLink/SDLCarWindow.m | 16 ++++++++++++---- .../SDLStreamingVideoLifecycleManager.m | 4 +++- 2 files changed, 15 insertions(+), 5 deletions(-) mode change 100755 => 100644 SmartDeviceLink/SDLCarWindow.m diff --git a/SmartDeviceLink/SDLCarWindow.m b/SmartDeviceLink/SDLCarWindow.m old mode 100755 new mode 100644 index 25046545a..ab194e75b --- a/SmartDeviceLink/SDLCarWindow.m +++ b/SmartDeviceLink/SDLCarWindow.m @@ -72,7 +72,7 @@ - (void)syncFrame { return; } - CGRect bounds = CGRectMake(0, 0, self.streamManager.screenSize.width, self.streamManager.screenSize.height); + CGRect bounds = self.getScaledScreenSizeFrame; UIGraphicsBeginImageContextWithOptions(bounds.size, YES, 1.0f); switch (self.renderingType) { @@ -121,9 +121,8 @@ - (void)sdl_didReceiveVideoStreamStarted:(NSNotification *)notification { dispatch_async(dispatch_get_main_queue(), ^{ // If the video stream has started, we want to resize the streamingViewController to the size from the RegisterAppInterface - float scale = self.streamManager.videoStreamingCapability.scale.floatValue; - if (scale > 0) { - self.rootViewController.view.frame = CGRectMake(0, 0, self.streamManager.screenSize.width / scale, self.streamManager.screenSize.height / scale); + if (self.scale > 0) { + self.rootViewController.view.frame = self.getScaledScreenSizeFrame; self.rootViewController.view.bounds = self.rootViewController.view.frame; SDLLogD(@"Video stream started, setting CarWindow frame to: %@", NSStringFromCGRect(self.rootViewController.view.bounds)); @@ -131,6 +130,15 @@ - (void)sdl_didReceiveVideoStreamStarted:(NSNotification *)notification { }); } +- (CGRect)getScaledScreenSizeFrame { + float scale = self.streamManager.videoStreamingCapability.scale.floatValue; + return CGRectMake(0, 0, self.streamManager.screenSize.width / scale, self.streamManager.screenSize.height / scale); +} + +- (float)scale { + return self.streamManager.videoStreamingCapability.scale.floatValue; +} + - (void)sdl_didReceiveVideoStreamStopped:(NSNotification *)notification { self.videoStreamStarted = false; diff --git a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m index c106a4b9c..7f363dd81 100644 --- a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m +++ b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m @@ -395,7 +395,9 @@ - (void)didEnterStateVideoStreamReady { NSAssert(self.videoFormat != nil, @"No video format is known, but it must be if we got a protocol start service response"); SDLLogD(@"Attempting to create video encoder"); - self.videoEncoder = [[SDLH264VideoEncoder alloc] initWithProtocol:self.videoFormat.protocol dimensions:self.screenSize ssrc:self.ssrc properties:self.videoEncoderSettings delegate:self error:&error]; + float scale = self.videoStreamingCapability.scale.floatValue; + CGSize scaledScreenSize = CGSizeMake(self.screenSize.width / scale, self.screenSize.height / scale); + self.videoEncoder = [[SDLH264VideoEncoder alloc] initWithProtocol:self.videoFormat.protocol dimensions:scaledScreenSize ssrc:self.ssrc properties:self.videoEncoderSettings delegate:self error:&error]; if (error || self.videoEncoder == nil) { SDLLogE(@"Could not create a video encoder: %@", error); From 4cd321e415f8ff2bd2964b15ea471ebad8b211f4 Mon Sep 17 00:00:00 2001 From: Luis Nafarrate Date: Mon, 26 Aug 2019 20:25:51 -0500 Subject: [PATCH 9/9] Addressing comments in PR. --- SmartDeviceLink/SDLCarWindow.m | 18 +++++-------- .../SDLStreamingVideoLifecycleManager.h | 2 +- .../SDLStreamingVideoLifecycleManager.m | 2 +- SmartDeviceLink/SDLTouchManager.h | 2 +- SmartDeviceLink/SDLTouchManager.m | 13 ++++++--- SmartDeviceLink/SDLVideoStreamingCapability.h | 7 ++++- SmartDeviceLink/SDLVideoStreamingCapability.m | 16 +++++++++-- .../SDLStreamingVideoLifecycleManagerSpec.m | 27 ++++++++----------- .../SDLVideoStreamingCapabilitySpec.m | 11 +++++++- 9 files changed, 60 insertions(+), 38 deletions(-) diff --git a/SmartDeviceLink/SDLCarWindow.m b/SmartDeviceLink/SDLCarWindow.m index ab194e75b..bc96f2c8f 100644 --- a/SmartDeviceLink/SDLCarWindow.m +++ b/SmartDeviceLink/SDLCarWindow.m @@ -72,7 +72,7 @@ - (void)syncFrame { return; } - CGRect bounds = self.getScaledScreenSizeFrame; + CGRect bounds = self.sdl_getScaledScreenSizeFrame; UIGraphicsBeginImageContextWithOptions(bounds.size, YES, 1.0f); switch (self.renderingType) { @@ -121,24 +121,18 @@ - (void)sdl_didReceiveVideoStreamStarted:(NSNotification *)notification { dispatch_async(dispatch_get_main_queue(), ^{ // If the video stream has started, we want to resize the streamingViewController to the size from the RegisterAppInterface - if (self.scale > 0) { - self.rootViewController.view.frame = self.getScaledScreenSizeFrame; - self.rootViewController.view.bounds = self.rootViewController.view.frame; - - SDLLogD(@"Video stream started, setting CarWindow frame to: %@", NSStringFromCGRect(self.rootViewController.view.bounds)); - } + self.rootViewController.view.frame = self.sdl_getScaledScreenSizeFrame; + self.rootViewController.view.bounds = self.rootViewController.view.frame; + + SDLLogD(@"Video stream started, setting CarWindow frame to: %@", NSStringFromCGRect(self.rootViewController.view.bounds)); }); } -- (CGRect)getScaledScreenSizeFrame { +- (CGRect)sdl_getScaledScreenSizeFrame { float scale = self.streamManager.videoStreamingCapability.scale.floatValue; return CGRectMake(0, 0, self.streamManager.screenSize.width / scale, self.streamManager.screenSize.height / scale); } -- (float)scale { - return self.streamManager.videoStreamingCapability.scale.floatValue; -} - - (void)sdl_didReceiveVideoStreamStopped:(NSNotification *)notification { self.videoStreamStarted = false; diff --git a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.h b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.h index c42ffccf3..2b7a47ff3 100644 --- a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.h +++ b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.h @@ -36,7 +36,7 @@ NS_ASSUME_NONNULL_BEGIN @property (strong, nonatomic, readonly) SDLStateMachine *videoStreamStateMachine; @property (strong, nonatomic, readonly) SDLVideoStreamManagerState *currentVideoStreamState; -@property (strong, nonatomic, readonly) SDLVideoStreamingCapability *videoStreamingCapability; +@property (nullable, strong, nonatomic, readonly) SDLVideoStreamingCapability *videoStreamingCapability; @property (strong, nonatomic, readonly) SDLStateMachine *appStateMachine; @property (strong, nonatomic, readonly) SDLAppState *currentAppState; diff --git a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m index 7f363dd81..c1530fbb5 100644 --- a/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m +++ b/SmartDeviceLink/SDLStreamingVideoLifecycleManager.m @@ -58,7 +58,7 @@ @interface SDLStreamingVideoLifecycleManager() @property (assign, nonatomic, readonly, getter=isAppStateVideoStreamCapable) BOOL appStateVideoStreamCapable; @property (assign, nonatomic, readonly, getter=isHmiStateVideoStreamCapable) BOOL hmiStateVideoStreamCapable; -@property (strong, nonatomic, readwrite) SDLVideoStreamingCapability *videoStreamingCapability; +@property (nullable, strong, nonatomic, readwrite) SDLVideoStreamingCapability *videoStreamingCapability; @property (strong, nonatomic, readwrite) SDLStateMachine *videoStreamStateMachine; @property (strong, nonatomic, readwrite) SDLStateMachine *appStateMachine; diff --git a/SmartDeviceLink/SDLTouchManager.h b/SmartDeviceLink/SDLTouchManager.h index 58b4254ca..9e01a8b0c 100644 --- a/SmartDeviceLink/SDLTouchManager.h +++ b/SmartDeviceLink/SDLTouchManager.h @@ -82,7 +82,7 @@ typedef void(^SDLTouchEventHandler)(SDLTouch *touch, SDLTouchType type); /** Provides all video streaming capabilities defined in the HMI. */ -@property (strong, nonatomic) SDLVideoStreamingCapability *videoStreamingCapability; +@property (nullable, strong, nonatomic) SDLVideoStreamingCapability *videoStreamingCapability; /** * @abstract diff --git a/SmartDeviceLink/SDLTouchManager.m b/SmartDeviceLink/SDLTouchManager.m index 27e080849..7f2ca8593 100644 --- a/SmartDeviceLink/SDLTouchManager.m +++ b/SmartDeviceLink/SDLTouchManager.m @@ -186,7 +186,7 @@ - (void)sdl_onTouchEvent:(SDLRPCNotificationNotification *)notification { } SDLOnTouchEvent *onTouchEvent = (SDLOnTouchEvent *)notification.notification; - onTouchEvent = [self applyScaleToEventCoordinates:onTouchEvent.copy]; + onTouchEvent = [self sdl_applyScaleToEventCoordinates:onTouchEvent.copy]; SDLTouchType touchType = onTouchEvent.type; [onTouchEvent.event enumerateObjectsUsingBlock:^(SDLTouchEvent *touchEvent, NSUInteger idx, BOOL *stop) { @@ -214,9 +214,16 @@ - (void)sdl_onTouchEvent:(SDLRPCNotificationNotification *)notification { }]; } -- (SDLOnTouchEvent *)applyScaleToEventCoordinates:(SDLOnTouchEvent *)onTouchEvent { +/** + * Modifies the existing coordinates of the SDLOnTouchEvent, based on the received 'scale' value. + + * This will match the coordinates to the scaled resolution of the video. + + * @param onTouchEvent A SDLOnTouchEvent with coordinates. + */ +- (SDLOnTouchEvent *)sdl_applyScaleToEventCoordinates:(SDLOnTouchEvent *)onTouchEvent { float scale = self.videoStreamingCapability.scale.floatValue; - if (scale > 0) { + if (scale > 1) { for (SDLTouchEvent *touchEvent in onTouchEvent.event) { for (SDLTouchCoord *coord in touchEvent.coord) { coord.x = @(coord.x.floatValue / scale); diff --git a/SmartDeviceLink/SDLVideoStreamingCapability.h b/SmartDeviceLink/SDLVideoStreamingCapability.h index be25baa7f..bd3da80ea 100644 --- a/SmartDeviceLink/SDLVideoStreamingCapability.h +++ b/SmartDeviceLink/SDLVideoStreamingCapability.h @@ -18,7 +18,12 @@ NS_ASSUME_NONNULL_BEGIN */ @interface SDLVideoStreamingCapability : SDLRPCStruct -- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray *)supportedFormats hapticDataSupported:(BOOL)hapticDataSupported diagonalScreenSize:(float)diagonalScreenSize pixelPerInch:(float)pixelPerInch scale:(float)scale; +- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray *)supportedFormats hapticDataSupported:(BOOL)hapticDataSupported __deprecated_msg("Use initWithPreferredResolution:maxBitrate:supportedFormats:hapticDataSupported:diagonalScreenSize:pixelPerInch:scale: instead");; + +/** + Contains information about this system's video streaming capabilities + */ +- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray *)supportedFormats hapticDataSupported:(BOOL)hapticDataSupported diagonalScreenSize:(float)diagonalScreenSize pixelPerInch:(float)pixelPerInch scale:(float)scale; /** The preferred resolution of a video stream for decoding and rendering on HMI diff --git a/SmartDeviceLink/SDLVideoStreamingCapability.m b/SmartDeviceLink/SDLVideoStreamingCapability.m index 0c50b817e..c24f698bd 100644 --- a/SmartDeviceLink/SDLVideoStreamingCapability.m +++ b/SmartDeviceLink/SDLVideoStreamingCapability.m @@ -17,7 +17,11 @@ @implementation SDLVideoStreamingCapability -- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray *)supportedFormats hapticDataSupported:(BOOL)hapticDataSupported diagonalScreenSize:(float)diagonalScreenSize pixelPerInch:(float)pixelPerInch scale:(float)scale { +- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray *)supportedFormats hapticDataSupported:(BOOL)hapticDataSupported { + return [self initWithPreferredResolution:preferredResolution maxBitrate:maxBitrate supportedFormats:supportedFormats hapticDataSupported:hapticDataSupported diagonalScreenSize:0 pixelPerInch:0 scale:SDLVideoStreamingCapability.sdl_DefaultScale.floatValue]; +} + +- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray *)supportedFormats hapticDataSupported:(BOOL)hapticDataSupported diagonalScreenSize:(float)diagonalScreenSize pixelPerInch:(float)pixelPerInch scale:(float)scale { self = [self init]; if (!self) { return self; @@ -87,7 +91,15 @@ - (void)setScale:(nullable NSNumber *)scale { } - (nullable NSNumber *)scale { - return [self.store sdl_objectForName:SDLRPCParameterNameScale ofClass:NSNumber.class error:nil]; + NSNumber *scale = [self.store sdl_objectForName:SDLRPCParameterNameScale ofClass:NSNumber.class error:nil]; + if (scale != nil) { + return scale; + } + return SDLVideoStreamingCapability.sdl_DefaultScale; +} + ++ (NSNumber *)sdl_DefaultScale { + return @1.0; } @end diff --git a/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m b/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m index 93439e3df..24c2b0935 100644 --- a/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m +++ b/SmartDeviceLinkTests/DevAPISpecs/SDLStreamingVideoLifecycleManagerSpec.m @@ -40,6 +40,7 @@ @interface SDLStreamingVideoLifecycleManager () @property (copy, nonatomic, readonly) NSString *appName; @property (copy, nonatomic, readonly) NSString *videoStreamBackgroundString; +@property (strong, nonatomic, readwrite) SDLVideoStreamingCapability *videoStreamingCapability; @end QuickSpecBegin(SDLStreamingVideoLifecycleManagerSpec) @@ -411,6 +412,14 @@ __block void (^sendNotificationForHMILevel)(SDLHMILevel hmiLevel, SDLVideoStream }); describe(@"sending a video capabilities request", ^{ + __block SDLImageResolution *resolution = [[SDLImageResolution alloc] initWithWidth:42 height:69]; + __block int32_t maxBitrate = 12345; + __block NSArray *testFormats = @[[[SDLVideoStreamingFormat alloc] initWithCodec:SDLVideoStreamingCodecH265 protocol:SDLVideoStreamingProtocolRTMP], [[SDLVideoStreamingFormat alloc] initWithCodec:SDLVideoStreamingCodecH264 protocol:SDLVideoStreamingProtocolRTP]]; + __block BOOL testHapticsSupported = YES; + __block float diagonalScreenSize = 22.0; + __block float pixelPerInch = 96.0; + __block float scale = 1.0; + beforeEach(^{ [streamingLifecycleManager.videoStreamStateMachine setToState:SDLVideoStreamManagerStateStarting fromOldState:nil callEnterTransition:YES]; }); @@ -443,27 +452,11 @@ __block void (^sendNotificationForHMILevel)(SDLHMILevel hmiLevel, SDLVideoStream }); context(@"and receiving a response", ^{ - __block SDLImageResolution *resolution = nil; - __block int32_t maxBitrate = 0; - __block NSArray *testFormats = nil; - __block BOOL testHapticsSupported = NO; - __block float diagonalScreenSize = 0.0; - __block float pixelPerInch = 0.0; - __block float scale = 0.0; - beforeEach(^{ SDLGetSystemCapabilityResponse *response = [[SDLGetSystemCapabilityResponse alloc] init]; response.success = @YES; response.systemCapability = [[SDLSystemCapability alloc] init]; response.systemCapability.systemCapabilityType = SDLSystemCapabilityTypeVideoStreaming; - - resolution = [[SDLImageResolution alloc] initWithWidth:42 height:69]; - maxBitrate = 12345; - testFormats = @[[[SDLVideoStreamingFormat alloc] initWithCodec:SDLVideoStreamingCodecH265 protocol:SDLVideoStreamingProtocolRTMP], [[SDLVideoStreamingFormat alloc] initWithCodec:SDLVideoStreamingCodecH264 protocol:SDLVideoStreamingProtocolRTP]]; - testHapticsSupported = YES; - diagonalScreenSize = 22.0; - pixelPerInch = 96.0; - scale = 1.0; response.systemCapability.videoStreamingCapability = [[SDLVideoStreamingCapability alloc] initWithPreferredResolution:resolution maxBitrate:maxBitrate supportedFormats:testFormats hapticDataSupported:testHapticsSupported diagonalScreenSize:diagonalScreenSize pixelPerInch:pixelPerInch scale:scale]; [testConnectionManager respondToLastRequestWithResponse:response]; @@ -520,6 +513,8 @@ __block void (^sendNotificationForHMILevel)(SDLHMILevel hmiLevel, SDLVideoStream testVideoHeader.frameData = SDLFrameInfoStartServiceACK; testVideoHeader.encrypted = YES; testVideoHeader.serviceType = SDLServiceTypeVideo; + + streamingLifecycleManager.videoStreamingCapability = [[SDLVideoStreamingCapability alloc] initWithPreferredResolution:resolution maxBitrate:maxBitrate supportedFormats:testFormats hapticDataSupported:testHapticsSupported diagonalScreenSize:diagonalScreenSize pixelPerInch:pixelPerInch scale:scale]; }); context(@"with data", ^{ diff --git a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLVideoStreamingCapabilitySpec.m b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLVideoStreamingCapabilitySpec.m index 82bd0791d..f202548c6 100644 --- a/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLVideoStreamingCapabilitySpec.m +++ b/SmartDeviceLinkTests/RPCSpecs/StructSpecs/SDLVideoStreamingCapabilitySpec.m @@ -28,6 +28,9 @@ NSNumber *maxBitrate = @100; NSNumber *hapticDataSupported = @NO; + NSNumber *diagonalScreenSize = @22; + NSNumber *pixelPerInch = @96; + NSNumber *scale = @1; SDLVideoStreamingFormat *format1 = [[SDLVideoStreamingFormat alloc] init]; format1.codec = SDLVideoStreamingCodecH264; @@ -42,7 +45,10 @@ NSMutableDictionary* dict = [@{SDLRPCParameterNamePreferredResolution: resolution, SDLRPCParameterNameMaxBitrate: maxBitrate, SDLRPCParameterNameSupportedFormats: formatArray, - SDLRPCParameterNameHapticSpatialDataSupported: hapticDataSupported} mutableCopy]; + SDLRPCParameterNameHapticSpatialDataSupported: hapticDataSupported, + SDLRPCParameterNameDiagonalScreenSize: diagonalScreenSize, + SDLRPCParameterNamePixelPerInch: pixelPerInch, + SDLRPCParameterNameScale: scale} mutableCopy]; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" SDLVideoStreamingCapability* testStruct = [[SDLVideoStreamingCapability alloc] initWithDictionary:dict]; @@ -60,6 +66,9 @@ expect(testStruct.preferredResolution).to(beNil()); expect(testStruct.maxBitrate).to(beNil()); expect(testStruct.supportedFormats).to(beNil()); + expect(testStruct.diagonalScreenSize).to(beNil()); + expect(testStruct.pixelPerInch).to(beNil()); + expect(testStruct.scale).to(equal(1)); }); it(@"Should initialize correctly with initWithVideoStreaming:maxBitrate:suportedFormats", ^ {