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

Conversation

lnafarrateluxoft
Copy link
Contributor

@lnafarrateluxoft lnafarrateluxoft commented Jul 25, 2019

Fixes #1007

This PR is ready for review.

Risk

This PR makes minor API changes.

Testing Plan

Unit tests added for:

  • SDLStreamingVideoLifecycleManagerSpec
  • SDLVideoStreamingCapabilitySpec
  • SDLTouchManagerSpec

Functional testing can be done by editing the preferred resolution,
and scale in HMI and testing that the captured view has the proper size and touches are reported
correctly and with the correct coordinates while clicking on the HMI interface.
Also the Automatic Haptic Rect sent to HMI should have the propper size according to the scale value set.

Summary

The main change is related to changing the size of the view captured.
This is done by adding a new scale parameter in the video
streaming capability and by dividing the preferred resolution from the
HMI and the scale.

Also touch coordinates need some changes to match in the HMI with the new resolution, I had to divide the coordinates with the new scale value.

CLA

@lnafarrateluxoft lnafarrateluxoft force-pushed the feature/0179_pixel_density_and_scale branch from 428b300 to e4a8547 Compare July 25, 2019 06:30
@NicoleYarroch NicoleYarroch added enhancement proposal Accepted SDL Evolution Proposal labels Jul 25, 2019
@NicoleYarroch NicoleYarroch added this to In progress in v6.4 via automation Jul 25, 2019
@NicoleYarroch NicoleYarroch added this to the 6.4.0 milestone Jul 25, 2019
@lnafarrateluxoft
Copy link
Contributor Author

@joeljfischer please review.

@joeljfischer joeljfischer changed the title [SDL 0179]Pixel density and Scale Implement SDL 0179 - Pixel density and Scale Jul 29, 2019
@theresalech
Copy link
Contributor

@kshala-ford can you please confirm if you have reviewed and approved this PR? Thank you!

Copy link
Contributor

@kshala-ford kshala-ford left a comment

Choose a reason for hiding this comment

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

I left a comment regarding the OnTouchEvent scaling. Other than that it looks good. I was missing code/tests regarding the hit tester (see https://github.com/smartdevicelink/sdl_ios/blob/master/SmartDeviceLink/SDLTouchManager.m#L89). This is using the focusable item tester here https://github.com/smartdevicelink/sdl_ios/blob/master/SmartDeviceLink/SDLFocusableItemLocator.h

Can you explain if the hit tester is covered by updating the touch event notifications?

SmartDeviceLink/SDLTouchManager.m Show resolved Hide resolved
v6.4 automation moved this from In progress to Review in progress Aug 2, 2019
@NicoleYarroch NicoleYarroch self-requested a review August 6, 2019 12:38
Copy link
Contributor

@NicoleYarroch NicoleYarroch left a comment

Choose a reason for hiding this comment

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

I left some comments on the code. When I run the all of the test cases all at once (Product > Test), 19 test case s fail. However, when I run the classes where the test cases fail individually, all the class test cases succeed. I tried to debug the test cases but I'm not sure exactly what is happening. I would recommend commenting out the changes you made and adding them back in one-by-one.

SmartDeviceLink/SDLVideoStreamingCapability.h Outdated Show resolved Hide resolved
SmartDeviceLink/SDLCarWindow.m Outdated Show resolved Hide resolved
SmartDeviceLink/SDLCarWindow.m Show resolved Hide resolved
SmartDeviceLink/SDLCarWindow.m Outdated Show resolved Hide resolved
SmartDeviceLink/SDLTouchManager.m Outdated Show resolved Hide resolved
@@ -23,6 +23,8 @@
#import "SDLTouchManagerDelegate.h"
#import "SDLTouchType.h"
#import "SDLTouch.h"
#import "SDLVideoStreamingCapability.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

When I run all the test cases at once, I get 14 failing test cases in this class, but when I run just the test cases in this class they all pass. I'm baffled as to why this is happening. Maybe the new scale parameter is messing things up?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did noticed that some of the tests are faulty, but at the end they pass.

Copy link
Contributor

@yLeonid yLeonid Sep 13, 2019

Choose a reason for hiding this comment

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

The main problem there is that:

  1. SDLTouchManager is recreated on every test.
  2. SDLTouchManager subscribes for notifications in its -init* method (which is not the best solution by itself but it works)
  3. SDLTouchManager never unsubscribes from notifications.
  4. A few instances of SDLTouchManager receive notifications and handle them "properly"
  5. Tests fail due to wrong event number

Hotfix in SDLTouchManagerSpec.m:

        if (touchManager) {
            //FIXIT: SDLTouchManager must unsubscribe from notifications
            [[NSNotificationCenter defaultCenter] removeObserver:touchManager];
            touchManager = nil;
        }

SmartDeviceLink/SDLTouchManager.h Outdated Show resolved Hide resolved
@lnafarrateluxoft
Copy link
Contributor Author

@NicoleYarroch Done. All your comments have been addressed in a new commit.

@lnafarrateluxoft lnafarrateluxoft force-pushed the feature/0179_pixel_density_and_scale branch from 699d4db to 4cd321e Compare August 27, 2019 12:52
Copy link
Contributor

@NicoleYarroch NicoleYarroch left a comment

Choose a reason for hiding this comment

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

Left some comments on the implementation and the tests.

if (scale != nil) {
return scale;
}
return SDLVideoStreamingCapability.sdl_DefaultScale;
Copy link
Contributor

Choose a reason for hiding this comment

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

I see what you are trying to do here, but a custom getter should not be created in this class. The SDL convention is for this to return the value set by Core. In the future we might need to know if scale is null or if it has been set by Core and we wouldn't be able to get this information with the current setup. I added another comment to the SDLStreamingVideoLifecycleManager with an idea of how to best reuse the code.

@@ -35,6 +36,7 @@ NS_ASSUME_NONNULL_BEGIN

@property (strong, nonatomic, readonly) SDLStateMachine *videoStreamStateMachine;
@property (strong, nonatomic, readonly) SDLVideoStreamManagerState *currentVideoStreamState;
@property (nullable, strong, nonatomic, readonly) SDLVideoStreamingCapability *videoStreamingCapability;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason you want to makevideoStreamingCapability public? Iit doesn't appear to be used by another class. If developers want to get the videoStreamingCapability they can use the SDLSystemCapabilityManager.

@@ -58,6 +58,8 @@ @interface SDLStreamingVideoLifecycleManager() <SDLVideoEncoderDelegate>
@property (assign, nonatomic, readonly, getter=isAppStateVideoStreamCapable) BOOL appStateVideoStreamCapable;
@property (assign, nonatomic, readonly, getter=isHmiStateVideoStreamCapable) BOOL hmiStateVideoStreamCapable;

@property (nullable, strong, nonatomic, readwrite) SDLVideoStreamingCapability *videoStreamingCapability;
Copy link
Contributor

Choose a reason for hiding this comment

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

This my idea of how to best prevent duplicate code for the scale value.

  1. In the SDLStreamingVideoLifecycleManager create a custom sdl_scale getter to return videoStreamingCapability.scale or 1 if the scale value does not exists.
  2. Add another init to SDLTouchManger that takes a scale value in addition to the hitTester. In the SDLStreamingVideoLifecycleManager class set sdl_scale for the scale value in the touch manager init. Then later, when we get the videoStreamingCapability from core, the actual scale value can be set in the touch manager class.
  3. Do the same thing for SDLCarWindow. Add another init to SDLCarWindow that takes a scale value in addition to the streamManager and configuration. In the SDLStreamingVideoLifecycleManager class set sdl_scale for the scale value in the car window init. Then later, when we get the videoStreamingCapability from core, the actual scale value can be set in the car window class.

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:
yLeonid@91b30ce

@@ -42,7 +45,10 @@
NSMutableDictionary* dict = [@{SDLRPCParameterNamePreferredResolution: resolution,
SDLRPCParameterNameMaxBitrate: maxBitrate,
SDLRPCParameterNameSupportedFormats: formatArray,
SDLRPCParameterNameHapticSpatialDataSupported: hapticDataSupported} mutableCopy];
SDLRPCParameterNameHapticSpatialDataSupported: hapticDataSupported,
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 checks for the new values added to the dictionary to this test case:

expect(testStruct.diagonalScreenSize).to(equal(diagonalScreenSize));
expect(testStruct.pixelPerInch).to(equal(pixelPerInch));
expect(testStruct.scale).to(equal(scale));

@@ -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));
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be expect(testStruct.scale).to(beNil());

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -80,12 +92,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

@@ -40,6 +40,7 @@
@interface SDLStreamingVideoLifecycleManager ()
@property (copy, nonatomic, readonly) NSString *appName;
@property (copy, nonatomic, readonly) NSString *videoStreamBackgroundString;
@property (strong, nonatomic, readwrite) SDLVideoStreamingCapability *videoStreamingCapability;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should match what is in the class being tested (missing the nullable)

@property (nullable, strong, nonatomic, readwrite) SDLVideoStreamingCapability *videoStreamingCapability;

Copy link
Contributor

Choose a reason for hiding this comment

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

Implemented in (line 43):
lnafarrateluxoft@c8a9e5e

@@ -40,6 +40,7 @@
@interface SDLStreamingVideoLifecycleManager ()
Copy link
Contributor

Choose a reason for hiding this comment

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

The tests in this class are crashing due to the videoStreamingCapability not yet being set in the SDLCarWindow class. In the sdl_getScaledScreenSizeFrame of the SDLCarWindow class it is dividing by a scale of 0. This would be solved by setting a default scale value in the init of SDLCarWindow

Copy link
Contributor

Choose a reason for hiding this comment

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

@@ -184,7 +185,8 @@ - (void)sdl_onTouchEvent:(SDLRPCNotificationNotification *)notification {
return;
}

SDLOnTouchEvent* onTouchEvent = (SDLOnTouchEvent*)notification.notification;
SDLOnTouchEvent *onTouchEvent = (SDLOnTouchEvent *)notification.notification;
onTouchEvent = [self sdl_applyScaleToEventCoordinates:onTouchEvent.copy];
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think copy is working as expected here which is why the TouchManager test cases are breaking when I run all the tests. Maybe copyWithZone: has a bug?

@theresalech
Copy link
Contributor

@lnafarrateluxoft can you please let us know when you anticipate this PR being ready for re-review? Thank you!

SDLLogD(@"Video stream started, setting CarWindow frame to: %@", NSStringFromCGRect(self.rootViewController.view.bounds));
});
}

- (CGRect)sdl_getScaledScreenSizeFrame {
Copy link
Contributor

@yLeonid yLeonid Sep 11, 2019

Choose a reason for hiding this comment

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

Misleading method name:

  1. We can use a property name without the prefix get
    - (CGRect)sdl_scaledScreenSizeFrame {}
  2. If we really want to use the prefix get then the method must look like this:
- (void)sdl_getScaledScreenSizeFrame:(CGRect * outRect) {
    if (outRect) {
       *outRect = <the rect value>;
    }
}

(See Apple Objective-C guideline)

@yLeonid
Copy link
Contributor

yLeonid commented Sep 13, 2019

Travis tests had no chance to pass or even to get executed:
See Travis Job log:
error: SDK "iphonesimulator11.0" cannot be located.
BUT: exited with 0. <<== zero here means success but in fact tests were not even launched.

https://travis-ci.org/smartdevicelink/sdl_ios/builds/577331329?utm_source=github_status&utm_medium=notification

yLeonid added a commit to yLeonid/sdl_ios that referenced this pull request Sep 13, 2019
yLeonid added a commit to yLeonid/sdl_ios that referenced this pull request Sep 14, 2019
yLeonid added a commit to yLeonid/sdl_ios that referenced this pull request Sep 14, 2019
@dboltovskyi
Copy link

@NicoleYarroch Please review updates related to your comments

@NicoleYarroch
Copy link
Contributor

Closing this PR in favor of PR #1401

v6.4 automation moved this from Review in progress to Done Sep 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal Accepted SDL Evolution Proposal
Projects
No open projects
v6.4
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

7 participants