Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement SDL 0179 - Pixel density and Scale #1360

Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions SmartDeviceLink/SDLCarWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "SDLStreamingMediaConfiguration.h"
#import "SDLStreamingVideoLifecycleManager.h"
#import "SDLStreamingMediaManagerConstants.h"
#import "SDLVideoStreamingCapability.h"

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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));
}
});
}

Expand Down
3 changes: 3 additions & 0 deletions SmartDeviceLink/SDLRPCParameterNames.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,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;
Expand Down Expand Up @@ -438,6 +439,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;
Expand Down Expand Up @@ -509,6 +511,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;
Expand Down
3 changes: 3 additions & 0 deletions SmartDeviceLink/SDLRPCParameterNames.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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";
Expand Down Expand Up @@ -432,6 +433,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";
Expand Down Expand Up @@ -504,6 +506,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";
Expand Down
2 changes: 2 additions & 0 deletions SmartDeviceLink/SDLStreamingVideoLifecycleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
@class SDLStateMachine;
@class SDLStreamingMediaConfiguration;
@class SDLTouchManager;
@class SDLVideoStreamingCapability;

@protocol SDLConnectionManagerType;
@protocol SDLFocusableItemLocatorType;
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions SmartDeviceLink/SDLStreamingVideoLifecycleManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ @interface SDLStreamingVideoLifecycleManager() <SDLVideoEncoderDelegate>
@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;

Expand Down Expand Up @@ -707,6 +709,8 @@ - (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);
}];
Expand Down
6 changes: 6 additions & 0 deletions SmartDeviceLink/SDLTouchManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
@protocol SDLTouchManagerDelegate;

@class SDLTouch;
@class SDLVideoStreamingCapability;

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -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;
lnafarrateluxoft marked this conversation as resolved.
Show resolved Hide resolved

/**
* @abstract
* Cancels pending touch event timers that may be in progress.
Expand Down
17 changes: 16 additions & 1 deletion SmartDeviceLink/SDLTouchManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#import "SDLTouchCoord.h"
#import "SDLTouchEvent.h"
#import "SDLTouchManagerDelegate.h"
#import "SDLVideoStreamingCapability.h"


NS_ASSUME_NONNULL_BEGIN
Expand Down Expand Up @@ -184,7 +185,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) {
Expand Down Expand Up @@ -212,6 +214,19 @@ - (void)sdl_onTouchEvent:(SDLRPCNotificationNotification *)notification {
}];
}

- (SDLOnTouchEvent *)applyScaleToEventCoordinates:(SDLOnTouchEvent *)onTouchEvent {
lnafarrateluxoft marked this conversation as resolved.
Show resolved Hide resolved
float scale = self.videoStreamingCapability.scale.floatValue;
if (scale > 0) {
lnafarrateluxoft marked this conversation as resolved.
Show resolved Hide resolved
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;
}

lnafarrateluxoft marked this conversation as resolved.
Show resolved Hide resolved
#pragma mark - Private
/**
* Handles a BEGIN touch event sent by Core
Expand Down
23 changes: 22 additions & 1 deletion SmartDeviceLink/SDLVideoStreamingCapability.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface SDLVideoStreamingCapability : SDLRPCStruct

- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray<SDLVideoStreamingFormat *> *)supportedFormats hapticDataSupported:(BOOL)hapticDataSupported;
- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray<SDLVideoStreamingFormat *> *)supportedFormats hapticDataSupported:(BOOL)hapticDataSupported diagonalScreenSize:(float)diagonalScreenSize pixelPerInch:(float)pixelPerInch scale:(float)scale;
lnafarrateluxoft marked this conversation as resolved.
Show resolved Hide resolved

/**
The preferred resolution of a video stream for decoding and rendering on HMI
Expand Down Expand Up @@ -48,6 +48,27 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nullable, strong, nonatomic) NSNumber<SDLBool> *hapticSpatialDataSupported;

/**
The diagonal screen size in inches.

Optional
*/
@property (nullable, strong, nonatomic) NSNumber<SDLFloat> *diagonalScreenSize;

/**
PPI is the diagonal resolution in pixels divided by the diagonal screen size in inches.

Optional
*/
@property (nullable, strong, nonatomic) NSNumber<SDLFloat> *pixelPerInch;

/**
The scaling factor the app should use to change the size of the projecting view.

Optional
*/
@property (nullable, strong, nonatomic) NSNumber<SDLFloat> *scale;

@end

NS_ASSUME_NONNULL_END
29 changes: 28 additions & 1 deletion SmartDeviceLink/SDLVideoStreamingCapability.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

@implementation SDLVideoStreamingCapability

- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray<SDLVideoStreamingFormat *> *)supportedFormats hapticDataSupported:(BOOL)hapticDataSupported {
- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray<SDLVideoStreamingFormat *> *)supportedFormats hapticDataSupported:(BOOL)hapticDataSupported diagonalScreenSize:(float)diagonalScreenSize pixelPerInch:(float)pixelPerInch scale:(float)scale {
self = [self init];
if (!self) {
return self;
Expand All @@ -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;
}
Expand Down Expand Up @@ -63,6 +66,30 @@ - (void)setHapticSpatialDataSupported:(nullable NSNumber<SDLBool> *)hapticSpatia
return [self.store sdl_objectForName:SDLRPCParameterNameHapticSpatialDataSupported ofClass:NSNumber.class error:nil];
}

- (void)setDiagonalScreenSize:(nullable NSNumber<SDLFloat> *)diagonalScreenSize {
[self.store sdl_setObject:diagonalScreenSize forName:SDLRPCParameterNameDiagonalScreenSize];
}

- (nullable NSNumber<SDLFloat> *)diagonalScreenSize {
return [self.store sdl_objectForName:SDLRPCParameterNameDiagonalScreenSize ofClass:NSNumber.class error:nil];
}

- (void)setPixelPerInch:(nullable NSNumber<SDLFloat> *)pixelPerInch {
[self.store sdl_setObject:pixelPerInch forName:SDLRPCParameterNamePixelPerInch];
}

- (nullable NSNumber<SDLFloat> *)pixelPerInch {
return [self.store sdl_objectForName:SDLRPCParameterNamePixelPerInch ofClass:NSNumber.class error:nil];
}

- (void)setScale:(nullable NSNumber<SDLFloat> *)scale {
[self.store sdl_setObject:scale forName:SDLRPCParameterNameScale];
}

- (nullable NSNumber<SDLFloat> *)scale {
return [self.store sdl_objectForName:SDLRPCParameterNameScale ofClass:NSNumber.class error:nil];
}

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ __block void (^sendNotificationForHMILevel)(SDLHMILevel hmiLevel, SDLVideoStream
__block int32_t maxBitrate = 0;
__block NSArray<SDLVideoStreamingFormat *> *testFormats = nil;
__block BOOL testHapticsSupported = NO;
__block float diagonalScreenSize = 0.0;
lnafarrateluxoft marked this conversation as resolved.
Show resolved Hide resolved
__block float pixelPerInch = 0.0;
__block float scale = 0.0;

beforeEach(^{
SDLGetSystemCapabilityResponse *response = [[SDLGetSystemCapabilityResponse alloc] init];
Expand All @@ -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];
});

Expand All @@ -484,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));
});
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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", ^ {
Expand Down Expand Up @@ -128,6 +128,9 @@

int32_t maxBitrate = 100;
BOOL hapticDataSupported = YES;
float diagonalScreenSize = 22.0;
float pixelPerInch = 96.0;
float scale = 1.0;

SDLVideoStreamingFormat *format1 = [[SDLVideoStreamingFormat alloc] init];
format1.codec = SDLVideoStreamingCodecH264;
Expand All @@ -139,7 +142,7 @@

NSArray<SDLVideoStreamingFormat *> *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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@

int32_t maxBitrate = 100;
NSNumber *hapticDataSupported = @YES;
float diagonalScreenSize = 22.0;
float pixelPerInch = 96.0;
float scale = 1.0;
lnafarrateluxoft marked this conversation as resolved.
Show resolved Hide resolved

SDLVideoStreamingFormat *format1 = [[SDLVideoStreamingFormat alloc] init];
format1.codec = SDLVideoStreamingCodecH264;
Expand All @@ -80,12 +83,15 @@

NSArray<SDLVideoStreamingFormat *> *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];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add another test case so you have one test case for the new init and another test case for the deprecated init. The SDLMediaServiceDataSpec has an example of how to suppress warnings when testing a deprecated init.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented here (lines 109-140)
lnafarrateluxoft@c8a9e5e


expect(testStruct.preferredResolution).to(equal(resolution));
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));
});

});
Expand Down
Loading