Merge remote-tracking branch 'moonlight-stream/master'

This commit is contained in:
Mimiste
2016-04-16 18:56:02 +02:00
17 changed files with 437 additions and 75 deletions

View File

@@ -1,23 +0,0 @@
//
// Controller.h
// Moonlight
//
// Created by Diego Waxemberg on 2/1/15.
// Copyright (c) 2015 Moonlight Stream. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface Controller : NSObject
@property (nonatomic) int playerIndex;
@property (nonatomic) int lastButtonFlags;
@property (nonatomic) int emulatingButtonFlags;
@property (nonatomic) char lastLeftTrigger;
@property (nonatomic) char lastRightTrigger;
@property (nonatomic) short lastLeftStickX;
@property (nonatomic) short lastLeftStickY;
@property (nonatomic) short lastRightStickX;
@property (nonatomic) short lastRightStickY;
@end

View File

@@ -1,15 +0,0 @@
//
// Controller.m
// Moonlight
//
// Created by Diego Waxemberg on 2/1/15.
// Copyright (c) 2015 Moonlight Stream. All rights reserved.
//
#import "Controller.h"
@implementation Controller
@synthesize playerIndex;
@synthesize lastButtonFlags, emulatingButtonFlags, lastLeftTrigger, lastRightTrigger;
@synthesize lastLeftStickX, lastLeftStickY, lastRightStickX, lastRightStickY;
@end

View File

@@ -0,0 +1,26 @@
//
// Controller.swift
// Moonlight
//
// Created by David Aghassi on 4/11/16.
// Copyright © 2016 Moonlight Stream. All rights reserved.
//
import Foundation
@objc
/**
Defines a controller layout
*/
class Controller: NSObject {
// Swift requires initial properties
var playerIndex: CInt = 0 // Controller number (e.g. 1, 2 ,3 etc)
var lastButtonFlags: CInt = 0
var emulatingButtonFlags: CInt = 0
var lastLeftTrigger: CChar = 0 // Last left trigger pressed
var lastRightTrigger: CChar = 0 // Last right trigger pressed
var lastLeftStickX: CShort = 0 // Last X direction the left joystick went
var lastLeftStickY: CShort = 0 // Last Y direction the left joystick went
var lastRightStickX: CShort = 0 // Last X direction the right joystick went
var lastRightStickY: CShort = 0 // Last Y direction the right joystick went
}

View File

@@ -7,7 +7,10 @@
//
#import <Foundation/Foundation.h>
#import "Controller.h"
// Swift
#import "Moonlight-Swift.h"
@class Controller;
@class OnScreenControls;

View File

@@ -8,9 +8,12 @@
#import "ControllerSupport.h"
#import "OnScreenControls.h"
#import "Controller.h"
#include "Limelight.h"
// Swift
#import "Moonlight-Swift.h"
@class Controller;
@import GameController;
@implementation ControllerSupport {

View File

@@ -0,0 +1,4 @@
//
// Use this file to import your target's public headers that you would like to expose to Swift.
//

View File

@@ -8,9 +8,12 @@
#import "OnScreenControls.h"
#import "ControllerSupport.h"
#import "Controller.h"
//#import "Controller.h"
#include "Limelight.h"
#import "Moonlight-Swift.h"
@class Controller;
#define UPDATE_BUTTON(x, y) (buttonFlags = \
(y) ? (buttonFlags | (x)) : (buttonFlags & ~(x)))

View File

@@ -27,7 +27,6 @@
-(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer connectionCallbacks:(id<ConnectionCallbacks>)callbacks serverMajorVersion:(int)serverMajorVersion;
-(void) terminate;
-(void) terminateInternal;
-(void) main;
@end

View File

@@ -23,6 +23,7 @@
int _serverMajorVersion;
}
static NSLock* initLock;
static OpusDecoder *opusDecoder;
static id<ConnectionCallbacks> _callbacks;
@@ -261,26 +262,28 @@ void ClDisplayTransientMessage(char* message)
[_callbacks displayTransientMessage: message];
}
-(void) terminateInternal
{
// We dispatch this async to get out because this can be invoked
// on a thread inside common and we don't want to deadlock
dispatch_async(dispatch_get_main_queue(), ^{
// This is safe to call even before LiStartConnection
LiStopConnection();
});
}
-(void) terminate
{
// We're guaranteed to not be on a moonlight-common thread
// here so it's safe to call stop directly
LiStopConnection();
// We dispatch this async to get out because this can be invoked
// on a thread inside common and we don't want to deadlock. It also avoids
// blocking on the caller's thread waiting to acquire initLock.
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[initLock lock];
LiStopConnection();
[initLock unlock];
});
}
-(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer connectionCallbacks:(id<ConnectionCallbacks>)callbacks serverMajorVersion:(int)serverMajorVersion
{
self = [super init];
// Use a lock to ensure that only one thread is initializing
// or deinitializing a connection at a time.
if (initLock == nil) {
initLock = [[NSLock alloc] init];
}
_host = [config.host cStringUsingEncoding:NSUTF8StringEncoding];
renderer = myRenderer;
_callbacks = callbacks;
@@ -403,12 +406,14 @@ static OSStatus playbackCallback(void *inRefCon,
-(void) main
{
[initLock lock];
LiStartConnection(_host,
&_streamConfig,
&_clCallbacks,
&_drCallbacks,
&_arCallbacks,
NULL, 0, _serverMajorVersion);
[initLock unlock];
}
@end

View File

@@ -14,6 +14,5 @@
- (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view connectionCallbacks:(id<ConnectionCallbacks>)callback;
- (void) stopStream;
- (void) stopStreamInternal;
@end

View File

@@ -91,20 +91,11 @@
[opQueue addOperation:_connection];
}
// This should NEVER be called from within a thread
// owned by moonlight-common
- (void) stopStream
{
[_connection terminate];
}
// This should only be called from within a thread
// owned by moonlight-common
- (void) stopStreamInternal
{
[_connection terminateInternal];
}
- (BOOL) launchApp:(HttpManager*)hMan {
HttpResponse* launchResp = [[HttpResponse alloc] init];
[hMan executeRequestSynchronously:[HttpRequest requestForResponse:launchResp withUrlRequest:

View File

@@ -84,7 +84,7 @@
[self presentViewController:conTermAlert animated:YES completion:nil];
});
[_streamMan stopStreamInternal];
[_streamMan stopStream];
}
- (void) stageStarting:(char*)stageName {
@@ -115,7 +115,7 @@
[self presentViewController:alert animated:YES completion:nil];
});
[_streamMan stopStreamInternal];
[_streamMan stopStream];
}
- (void) launchFailed:(NSString*)message {