Skip to content

Commit

Permalink
Addressing comments in PR.
Browse files Browse the repository at this point in the history
  • Loading branch information
lnafarrateluxoft committed Aug 27, 2019
1 parent 505ca7f commit 4cd321e
Show file tree
Hide file tree
Showing 9 changed files with 60 additions and 38 deletions.
18 changes: 6 additions & 12 deletions SmartDeviceLink/SDLCarWindow.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion SmartDeviceLink/SDLStreamingVideoLifecycleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion SmartDeviceLink/SDLStreamingVideoLifecycleManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ @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 (nullable, strong, nonatomic, readwrite) SDLVideoStreamingCapability *videoStreamingCapability;

@property (strong, nonatomic, readwrite) SDLStateMachine *videoStreamStateMachine;
@property (strong, nonatomic, readwrite) SDLStateMachine *appStateMachine;
Expand Down
2 changes: 1 addition & 1 deletion SmartDeviceLink/SDLTouchManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions SmartDeviceLink/SDLTouchManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion SmartDeviceLink/SDLVideoStreamingCapability.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ NS_ASSUME_NONNULL_BEGIN
*/
@interface SDLVideoStreamingCapability : SDLRPCStruct

- (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;
- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray<SDLVideoStreamingFormat *> *)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<SDLVideoStreamingFormat *> *)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
Expand Down
16 changes: 14 additions & 2 deletions SmartDeviceLink/SDLVideoStreamingCapability.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

@implementation SDLVideoStreamingCapability

- (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 {
- (instancetype)initWithPreferredResolution:(nullable SDLImageResolution *)preferredResolution maxBitrate:(int32_t)maxBitrate supportedFormats:(nullable NSArray<SDLVideoStreamingFormat *> *)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<SDLVideoStreamingFormat *> *)supportedFormats hapticDataSupported:(BOOL)hapticDataSupported diagonalScreenSize:(float)diagonalScreenSize pixelPerInch:(float)pixelPerInch scale:(float)scale {
self = [self init];
if (!self) {
return self;
Expand Down Expand Up @@ -87,7 +91,15 @@ - (void)setScale:(nullable NSNumber<SDLFloat> *)scale {
}

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

+ (NSNumber<SDLFloat> *)sdl_DefaultScale {
return @1.0;
}

@end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<SDLVideoStreamingFormat *> *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];
});
Expand Down Expand Up @@ -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<SDLVideoStreamingFormat *> *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];
Expand Down Expand Up @@ -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", ^{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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];
Expand All @@ -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", ^ {
Expand Down

0 comments on commit 4cd321e

Please sign in to comment.