Refactor new macOS code to reduce #ifs, increase shared code, and fix warnings

This commit is contained in:
Cameron Gutman
2018-03-27 00:34:38 -07:00
parent 6cc165b589
commit e8832ed746
22 changed files with 73 additions and 293 deletions
+2 -3
View File
@@ -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
+1 -5
View File
@@ -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;
+2 -22
View File
@@ -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];
+2 -5
View File
@@ -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;
+5 -39
View File
@@ -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);