mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-06-16 21:50:57 +00:00
Refactor new macOS code to reduce #ifs, increase shared code, and fix warnings
This commit is contained in:
@@ -98,7 +98,6 @@ int ArInit(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig, v
|
||||
audioLock = [[NSLock alloc] init];
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
|
||||
// Configure the audio session for our app
|
||||
NSError *audioSessionError = nil;
|
||||
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
|
||||
@@ -108,8 +107,8 @@ int ArInit(int audioConfiguration, POPUS_MULTISTREAM_CONFIGURATION opusConfig, v
|
||||
[audioSession setPreferredOutputNumberOfChannels:opusConfig->channelCount error:&audioSessionError];
|
||||
[audioSession setPreferredIOBufferDuration:0.005 error:&audioSessionError];
|
||||
[audioSession setActive: YES error: &audioSessionError];
|
||||
|
||||
#endif
|
||||
|
||||
OSStatus status;
|
||||
|
||||
AudioComponentDescription audioDesc;
|
||||
@@ -355,7 +354,7 @@ void ClLogMessage(const char* format, ...)
|
||||
#else
|
||||
if (@available(macOS 10.13, *)) {
|
||||
if (VTIsHardwareDecodeSupported(kCMVideoCodecType_HEVC) || _streamConfig.streamingRemotely != 0)
|
||||
_streamConfig.supportsHevc = true;
|
||||
_streamConfig.supportsHevc = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
@@ -12,11 +12,7 @@
|
||||
|
||||
@interface StreamManager : NSOperation
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
- (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view connectionCallbacks:(id<ConnectionCallbacks>)callback;
|
||||
#else
|
||||
- (id) initWithConfig:(StreamConfiguration*)config renderView:(NSView*)view connectionCallbacks:(id<ConnectionCallbacks>)callback;
|
||||
#endif
|
||||
- (id) initWithConfig:(StreamConfiguration*)config renderView:(OSView*)view connectionCallbacks:(id<ConnectionCallbacks>)callback;
|
||||
|
||||
- (void) stopStream;
|
||||
|
||||
|
||||
@@ -11,10 +11,6 @@
|
||||
#import "HttpManager.h"
|
||||
#import "Utils.h"
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
#import "OnScreenControls.h"
|
||||
#endif
|
||||
|
||||
#import "StreamView.h"
|
||||
#import "ServerInfoResponse.h"
|
||||
#import "HttpResponse.h"
|
||||
@@ -24,17 +20,12 @@
|
||||
@implementation StreamManager {
|
||||
StreamConfiguration* _config;
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
UIView* _renderView;
|
||||
#else
|
||||
NSView* _renderView;
|
||||
#endif
|
||||
OSView* _renderView;
|
||||
id<ConnectionCallbacks> _callbacks;
|
||||
Connection* _connection;
|
||||
}
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
- (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view connectionCallbacks:(id<ConnectionCallbacks>)callbacks {
|
||||
- (id) initWithConfig:(StreamConfiguration*)config renderView:(OSView*)view connectionCallbacks:(id<ConnectionCallbacks>)callbacks {
|
||||
self = [super init];
|
||||
_config = config;
|
||||
_renderView = view;
|
||||
@@ -43,17 +34,6 @@
|
||||
_config.riKeyId = arc4random();
|
||||
return self;
|
||||
}
|
||||
#else
|
||||
- (id) initWithConfig:(StreamConfiguration*)config renderView:(NSView*)view connectionCallbacks:(id<ConnectionCallbacks>)callbacks {
|
||||
self = [super init];
|
||||
_config = config;
|
||||
_renderView = view;
|
||||
_callbacks = callbacks;
|
||||
_config.riKey = [Utils randomBytes:16];
|
||||
_config.riKeyId = arc4random();
|
||||
return self;
|
||||
}
|
||||
#endif
|
||||
|
||||
- (void)main {
|
||||
[CryptoManager generateKeyPairUsingSSl];
|
||||
|
||||
@@ -11,11 +11,8 @@
|
||||
@import AVFoundation;
|
||||
|
||||
@interface VideoDecoderRenderer : NSObject
|
||||
#if TARGET_OS_IPHONE
|
||||
- (id)initWithView:(UIView*)view;
|
||||
#else
|
||||
- (id)initWithView:(NSView*)view;
|
||||
#endif
|
||||
|
||||
- (id)initWithView:(OSView*)view;
|
||||
|
||||
- (void)setupWithVideoFormat:(int)videoFormat;
|
||||
|
||||
|
||||
@@ -11,11 +11,7 @@
|
||||
#include "Limelight.h"
|
||||
|
||||
@implementation VideoDecoderRenderer {
|
||||
#if TARGET_OS_IPHONE
|
||||
UIView *_view;
|
||||
#else
|
||||
NSView *_view;
|
||||
#endif
|
||||
OSView *_view;
|
||||
|
||||
AVSampleBufferDisplayLayer* displayLayer;
|
||||
Boolean waitingForSps, waitingForPps, waitingForVps;
|
||||
@@ -31,11 +27,7 @@
|
||||
|
||||
displayLayer = [[AVSampleBufferDisplayLayer alloc] init];
|
||||
displayLayer.bounds = _view.bounds;
|
||||
#if TARGET_OS_IPHONE
|
||||
displayLayer.backgroundColor = [UIColor blackColor].CGColor;
|
||||
#else
|
||||
displayLayer.backgroundColor = [NSColor blackColor].CGColor;
|
||||
#endif
|
||||
displayLayer.backgroundColor = [OSColor blackColor].CGColor;
|
||||
|
||||
displayLayer.position = CGPointMake(CGRectGetMidX(_view.bounds), CGRectGetMidY(_view.bounds));
|
||||
displayLayer.videoGravity = AVLayerVideoGravityResizeAspect;
|
||||
@@ -61,8 +53,8 @@
|
||||
formatDesc = nil;
|
||||
}
|
||||
}
|
||||
#if TARGET_OS_IPHONE
|
||||
- (id)initWithView:(UIView*)view
|
||||
|
||||
- (id)initWithView:(OSView*)view
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
@@ -72,20 +64,6 @@
|
||||
|
||||
return self;
|
||||
}
|
||||
#else
|
||||
- (id)initWithView:(NSView*)view
|
||||
{
|
||||
self = [super init];
|
||||
|
||||
_view = view;
|
||||
|
||||
[self reinitializeDisplayLayer];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
- (void)setupWithVideoFormat:(int)videoFormat
|
||||
{
|
||||
@@ -248,20 +226,9 @@
|
||||
|
||||
#if TARGET_OS_IPHONE
|
||||
if (@available(iOS 11.0, *)) {
|
||||
status = CMVideoFormatDescriptionCreateFromHEVCParameterSets(kCFAllocatorDefault,
|
||||
3, /* count of parameter sets */
|
||||
parameterSetPointers,
|
||||
parameterSetSizes,
|
||||
NAL_LENGTH_PREFIX_SIZE,
|
||||
nil,
|
||||
&formatDesc);
|
||||
} else {
|
||||
// This means Moonlight-common-c decided to give us an HEVC stream
|
||||
// even though we said we couldn't support it. All we can do is abort().
|
||||
abort();
|
||||
}
|
||||
#else
|
||||
if (@available(macOS 10.13, *)) {
|
||||
#endif
|
||||
status = CMVideoFormatDescriptionCreateFromHEVCParameterSets(kCFAllocatorDefault,
|
||||
3, /* count of parameter sets */
|
||||
parameterSetPointers,
|
||||
@@ -274,7 +241,6 @@
|
||||
// even though we said we couldn't support it. All we can do is abort().
|
||||
abort();
|
||||
}
|
||||
#endif
|
||||
|
||||
if (status != noErr) {
|
||||
Log(LOG_E, @"Failed to create HEVC format description: %d", (int)status);
|
||||
|
||||
Reference in New Issue
Block a user