From 7f7770a42c5f7fc7bf4ef067f6d6103b22a0baaa Mon Sep 17 00:00:00 2001 From: hbouhadji Date: Sun, 6 Feb 2022 19:04:18 -0600 Subject: [PATCH] Added support for native stream resolution --- .../ViewControllers/SWRevealViewController.m | 4 +- .../ViewControllers/SettingsViewController.m | 61 ++++++++++++++++--- iPad.storyboard | 25 ++++---- iPhone.storyboard | 25 ++++---- 4 files changed, 82 insertions(+), 33 deletions(-) diff --git a/Limelight/ViewControllers/SWRevealViewController.m b/Limelight/ViewControllers/SWRevealViewController.m index c5e6b1c..bf64803 100755 --- a/Limelight/ViewControllers/SWRevealViewController.m +++ b/Limelight/ViewControllers/SWRevealViewController.m @@ -626,10 +626,10 @@ const int FrontViewPositionNone = 0xff; _frontViewPosition = FrontViewPositionLeft; _rearViewPosition = FrontViewPositionLeft; _rightViewPosition = FrontViewPositionLeft; - _rearViewRevealWidth = 260.0f; + _rearViewRevealWidth = 510.0f; _rearViewRevealOverdraw = 60.0f; _rearViewRevealDisplacement = 40.0f; - _rightViewRevealWidth = 260.0f; + _rightViewRevealWidth = 510.0f; _rightViewRevealOverdraw = 60.0f; _rightViewRevealDisplacement = 40.0f; _bounceBackOnOverdraw = YES; diff --git a/Limelight/ViewControllers/SettingsViewController.m b/Limelight/ViewControllers/SettingsViewController.m index 1ce5e99..b93ddee 100644 --- a/Limelight/ViewControllers/SettingsViewController.m +++ b/Limelight/ViewControllers/SettingsViewController.m @@ -146,10 +146,17 @@ static const int bitrateTable[] = { resolution = 2; break; case 2160: - resolution = 3; + resolution = 4; break; } - + // because switch case doesn't work with "expression" + if ([currentSettings.height integerValue] == [self getMainScreenHeight]) { + resolution = 3; + } + + NSString *newTitle = [NSString stringWithFormat:@"%dx%d", (int) self.getMainScreenWidth, (int) self.getMainScreenHeight]; + [self.resolutionSelector setTitle:newTitle forSegmentAtIndex:3]; + // Only show the 120 FPS option if we have a > 60-ish Hz display bool enable120Fps = false; if (@available(iOS 10.3, tvOS 10.3, *)) { @@ -165,11 +172,11 @@ static const int bitrateTable[] = { // they support HEVC decoding (A9 or later). if (@available(iOS 11.0, tvOS 11.0, *)) { if (!VTIsHardwareDecodeSupported(kCMVideoCodecType_HEVC)) { - [self.resolutionSelector removeSegmentAtIndex:3 animated:NO]; + [self.resolutionSelector removeSegmentAtIndex:4 animated:NO]; } } else { - [self.resolutionSelector removeSegmentAtIndex:3 animated:NO]; + [self.resolutionSelector removeSegmentAtIndex:4 animated:NO]; } // Disable the HEVC selector if HEVC is not supported by the hardware @@ -281,14 +288,54 @@ static const int bitrateTable[] = { } } +- (UIEdgeInsets) getSafeAreaInsets { + if (@available(iOS 11.0, *)) { + return UIApplication.sharedApplication.keyWindow.safeAreaInsets; + } else { + // todo: find a way to calculate the safe area for previous version + return UIEdgeInsetsMake(0, 0, 0, 0); + } +} + +- (NSInteger) getMainScreenHeight { + CGFloat scale = UIScreen.mainScreen.scale; + UIEdgeInsets insets = [self getSafeAreaInsets]; + CGFloat top = insets.top; + CGFloat bottom = insets.bottom; + CGFloat height = UIScreen.mainScreen.bounds.size.height; + + return scale * (height - top - bottom); +} + +- (NSInteger) getMainScreenWidth { + CGFloat scale = UIScreen.mainScreen.scale; + UIEdgeInsets insets = [self getSafeAreaInsets]; + CGFloat left = insets.left; + CGFloat right = insets.right; + CGFloat width = UIScreen.mainScreen.bounds.size.width; + + return scale * (width - left - right); +} + - (NSInteger) getChosenStreamHeight { - const int resolutionTable[] = { 360, 720, 1080, 2160 }; + const int mainScreenHeight = (int)[self getMainScreenHeight]; + const int resolutionTable[] = { 360, 720, 1080, mainScreenHeight, 2160 }; + return resolutionTable[[self.resolutionSelector selectedSegmentIndex]]; } - (NSInteger) getChosenStreamWidth { - // Assumes fixed 16:9 aspect ratio - return ([self getChosenStreamHeight] * 16) / 9; + const NSInteger choosenHeight = [self getChosenStreamHeight]; + switch (choosenHeight) { + case 360: + case 720: + case 1080: + case 2160: + // Assumes fixed 16:9 aspect ratio + return choosenHeight * 16 / 9; + default: + return [self getMainScreenWidth]; + } } - (void) saveSettings { diff --git a/iPad.storyboard b/iPad.storyboard index 14eb2af..2c51427 100644 --- a/iPad.storyboard +++ b/iPad.storyboard @@ -71,12 +71,13 @@ - + + @@ -91,7 +92,7 @@ - + @@ -110,7 +111,7 @@ - + @@ -122,7 +123,7 @@ - + @@ -140,7 +141,7 @@ - + @@ -159,7 +160,7 @@ - + @@ -176,7 +177,7 @@ - + @@ -193,7 +194,7 @@ - + @@ -210,7 +211,7 @@ - + @@ -227,7 +228,7 @@ - + @@ -244,7 +245,7 @@ - + @@ -261,7 +262,7 @@ - + diff --git a/iPhone.storyboard b/iPhone.storyboard index 684af9b..2fb71ff 100644 --- a/iPhone.storyboard +++ b/iPhone.storyboard @@ -93,12 +93,13 @@ - + + @@ -112,7 +113,7 @@ - + @@ -130,7 +131,7 @@ - + @@ -142,7 +143,7 @@ - + @@ -159,7 +160,7 @@ - + @@ -178,7 +179,7 @@ - + @@ -195,7 +196,7 @@ - + @@ -212,7 +213,7 @@ - + @@ -229,7 +230,7 @@ - + @@ -246,7 +247,7 @@ - + @@ -263,7 +264,7 @@ - + @@ -280,7 +281,7 @@ - +