Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions Limelight/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@
- (NSURL*) getStoreURL;

@end

#if !TARGET_OS_TV
// Required by iOS 27: apps built with the current SDK must use the scene lifecycle
@interface SceneDelegate : UIResponder <UIWindowSceneDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
#endif
39 changes: 39 additions & 0 deletions Limelight/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,42 @@ - (NSURL*) getStoreURL {
}

@end

#if !TARGET_OS_TV
@implementation SceneDelegate

- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions {
if (![scene isKindOfClass:[UIWindowScene class]]) {
return;
}

AppDelegate* appDelegate = (AppDelegate*)UIApplication.sharedApplication.delegate;

// Shortcut used to launch the app (previously in the launch options)
UIApplicationShortcutItem* shortcut = connectionOptions.shortcutItem;
if (shortcut != nil) {
appDelegate.pcUuidToLoad = (NSString*)[shortcut.userInfo objectForKey:@"UUID"];
}

// Same storyboards as UIMainStoryboardFile / UIMainStoryboardFile~ipad
NSString* storyboardName = UIDevice.currentDevice.userInterfaceIdiom == UIUserInterfaceIdiomPad ? @"iPad" : @"iPhone";
UIStoryboard* storyboard = [UIStoryboard storyboardWithName:storyboardName bundle:nil];

self.window = [[UIWindow alloc] initWithWindowScene:(UIWindowScene*)scene];
self.window.rootViewController = [storyboard instantiateInitialViewController];
appDelegate.window = self.window;
[self.window makeKeyAndVisible];
}

- (void)windowScene:(UIWindowScene *)windowScene performActionForShortcutItem:(UIApplicationShortcutItem *)shortcutItem completionHandler:(void (^)(BOOL succeeded))completionHandler {
[(AppDelegate*)UIApplication.sharedApplication.delegate application:UIApplication.sharedApplication
performActionForShortcutItem:shortcutItem
completionHandler:completionHandler];
}

- (void)sceneDidEnterBackground:(UIScene *)scene {
[(AppDelegate*)UIApplication.sharedApplication.delegate saveContext];
}

@end
#endif
21 changes: 17 additions & 4 deletions Limelight/Limelight-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,27 @@
</array>
<key>NSLocalNetworkUsageDescription</key>
<string>Moonlight uses the local network to connect to your gaming PC for streaming.</string>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>SceneDelegate</string>
</dict>
</array>
</dict>
</dict>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UILaunchStoryboardName</key>
<string>Launch Screen</string>
<key>UIMainStoryboardFile</key>
<string>iPhone</string>
<key>UIMainStoryboardFile~ipad</key>
<string>iPad</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand Down
2 changes: 2 additions & 0 deletions Limelight/Stream/StreamManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

- (void) stopStream;

- (void) updateRendererLayout;

- (NSString*) getStatsOverlayText;

@end
8 changes: 8 additions & 0 deletions Limelight/Stream/StreamManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ @implementation StreamManager {
UIView* _renderView;
id<ConnectionCallbacks> _callbacks;
Connection* _connection;
VideoDecoderRenderer* _renderer;
}

- (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view connectionCallbacks:(id<ConnectionCallbacks>)callbacks {
Expand Down Expand Up @@ -100,12 +101,19 @@ - (void)main {
// Initializing the renderer must be done on the main thread
dispatch_async(dispatch_get_main_queue(), ^{
VideoDecoderRenderer* renderer = [[VideoDecoderRenderer alloc] initWithView:self->_renderView callbacks:self->_callbacks streamAspectRatio:(float)self->_config.width / (float)self->_config.height useFramePacing:self->_config.useFramePacing];
self->_renderer = renderer;
self->_connection = [[Connection alloc] initWithConfig:self->_config renderer:renderer connectionCallbacks:self->_callbacks];
NSOperationQueue* opQueue = [[NSOperationQueue alloc] init];
[opQueue addOperation:self->_connection];
});
}

// Must be called on the main thread
- (void) updateRendererLayout
{
[_renderer updateDisplayLayerLayout];
}

- (void) stopStream
{
[_connection terminate];
Expand Down
1 change: 1 addition & 0 deletions Limelight/Stream/VideoDecoderRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- (void)start;
- (void)stop;
- (void)setHdrMode:(BOOL)enabled;
- (void)updateDisplayLayerLayout;

- (int)submitDecodeBuffer:(unsigned char *)data length:(int)length bufferType:(int)bufferType decodeUnit:(PDECODE_UNIT)du;

Expand Down
30 changes: 24 additions & 6 deletions Limelight/Stream/VideoDecoderRenderer.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,8 @@ @implementation VideoDecoderRenderer {
BOOL framePacing;
}

- (void)reinitializeDisplayLayer
- (void)layoutDisplayLayer
{
CALayer *oldLayer = displayLayer;

displayLayer = [[AVSampleBufferDisplayLayer alloc] init];
displayLayer.backgroundColor = [UIColor blackColor].CGColor;

// Ensure the AVSampleBufferDisplayLayer is sized to preserve the aspect ratio
// of the video stream. We used to use AVLayerVideoGravityResizeAspect, but that
// respects the PAR encoded in the SPS which causes our computed video-relative
Expand All @@ -57,6 +52,29 @@ - (void)reinitializeDisplayLayer
}
displayLayer.position = CGPointMake(CGRectGetMidX(_view.bounds), CGRectGetMidY(_view.bounds));
displayLayer.bounds = CGRectMake(0, 0, videoSize.width, videoSize.height);
}

// Called when the view size changes (e.g. folding or unfolding iPhone Duo)
- (void)updateDisplayLayerLayout
{
if (displayLayer == nil) {
return;
}

[CATransaction begin];
[CATransaction setDisableActions:YES];
[self layoutDisplayLayer];
[CATransaction commit];
}

- (void)reinitializeDisplayLayer
{
CALayer *oldLayer = displayLayer;

displayLayer = [[AVSampleBufferDisplayLayer alloc] init];
displayLayer.backgroundColor = [UIColor blackColor].CGColor;

[self layoutDisplayLayer];
displayLayer.videoGravity = AVLayerVideoGravityResize;

// Hide the layer until we get an IDR frame. This ensures we
Expand Down
32 changes: 30 additions & 2 deletions Limelight/ViewControllers/StreamFrameViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ @implementation StreamFrameViewController {
UILabel *_tipLabel;
UIActivityIndicatorView *_spinner;
StreamView *_streamView;
CGSize _lastLayoutSize;
UIScrollView *_scrollView;
BOOL _userIsInteracting;
CGSize _keyboardSize;
Expand Down Expand Up @@ -107,7 +108,8 @@ - (void)viewDidLoad
_controllerSupport = [[ControllerSupport alloc] initWithConfig:self.streamConfig delegate:self];
_inactivityTimer = nil;

_streamView = [[StreamView alloc] initWithFrame:self.view.frame];
_streamView = [[StreamView alloc] initWithFrame:self.view.bounds];
_streamView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[_streamView setupStreamView:_controllerSupport interactionDelegate:self config:self.streamConfig];

#if TARGET_OS_TV
Expand Down Expand Up @@ -188,7 +190,8 @@ - (void)viewDidLoad

// Only enable scroll and zoom in absolute touch mode
if (_settings.absoluteTouchMode) {
_scrollView = [[UIScrollView alloc] initWithFrame:self.view.frame];
_scrollView = [[UIScrollView alloc] initWithFrame:self.view.bounds];
_scrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
#if !TARGET_OS_TV
[_scrollView.panGestureRecognizer setMinimumNumberOfTouches:2];
#endif
Expand All @@ -215,6 +218,31 @@ - (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
return _streamView;
}

// The window can change size during a stream, for example when folding or
// unfolding iPhone Duo. Keep the stream view and video layer filling it.
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];

CGSize size = self.view.bounds.size;
if (CGSizeEqualToSize(size, _lastLayoutSize)) {
return;
}
_lastLayoutSize = size;

if (_scrollView != nil) {
// Reset any zoom so the stream view can match the new size
[_scrollView setZoomScale:1.0f animated:NO];
_streamView.frame = _scrollView.bounds;
_scrollView.contentSize = _scrollView.bounds.size;
}

_stageLabel.center = CGPointMake(size.width / 2, _stageLabel.center.y);
_spinner.center = CGPointMake(size.width / 2, _spinner.center.y);
_tipLabel.center = CGPointMake(size.width / 2, _tipLabel.center.y);

[_streamMan updateRendererLayout];
}

- (void)willMoveToParentViewController:(UIViewController *)parent {
// Only cleanup when we're being destroyed
if (parent == nil) {
Expand Down