diff --git a/Limelight/Computer.h b/Limelight/Computer.h index 17fec12..40ea8d5 100644 --- a/Limelight/Computer.h +++ b/Limelight/Computer.h @@ -14,5 +14,6 @@ @property BOOL paired; - (id) initWithHost:(NSNetService*)host; +- (int) resolveHost; @end diff --git a/Limelight/Computer.m b/Limelight/Computer.m index 2d03366..199a11d 100644 --- a/Limelight/Computer.m +++ b/Limelight/Computer.m @@ -8,6 +8,10 @@ #import "Computer.h" +#include +#include +#include + @implementation Computer - (id) initWithHost:(NSNetService *)host { @@ -19,4 +23,29 @@ return self; } +- (int) resolveHost +{ + struct hostent *hostent; + + if (inet_addr([self.hostName UTF8String]) != INADDR_NONE) + { + // Already an IP address + return inet_addr([self.hostName UTF8String]); + } + else + { + hostent = gethostbyname([self.hostName UTF8String]); + if (hostent != NULL) + { + char* ipstr = inet_ntoa(*(struct in_addr*)hostent->h_addr_list[0]); + NSLog(@"Resolved %@ -> %s", self.hostName, ipstr); + return inet_addr(ipstr); + } + else + { + NSLog(@"Failed to resolve host: %d", h_errno); + return -1; + } + } +} @end diff --git a/Limelight/MDNSManager.h b/Limelight/MDNSManager.h index b3cb988..1f13d98 100644 --- a/Limelight/MDNSManager.h +++ b/Limelight/MDNSManager.h @@ -20,7 +20,6 @@ - (id) initWithCallback:(id) callback; - (void) searchForHosts; -- (NSArray*) getFoundHosts; @end diff --git a/Limelight/MainFrameViewController.h b/Limelight/MainFrameViewController.h index 514d776..45309e3 100644 --- a/Limelight/MainFrameViewController.h +++ b/Limelight/MainFrameViewController.h @@ -18,7 +18,7 @@ @property (strong, nonatomic) NSArray* streamConfigVals; @property (strong, nonatomic) NSArray* hostPickerVals; -+ (const char*)getHostAddr; +- (int) getHostAddr; - (void) segueIntoStream; @end diff --git a/Limelight/MainFrameViewController.m b/Limelight/MainFrameViewController.m index e691254..dde7d9e 100644 --- a/Limelight/MainFrameViewController.m +++ b/Limelight/MainFrameViewController.m @@ -12,14 +12,17 @@ #import "CryptoManager.h" #import "HttpManager.h" #import "PairManager.h" +#import "Connection.h" +#import "VideoDecoderRenderer.h" -@implementation MainFrameViewController -NSString* hostAddr; -MDNSManager* mDNSManager; +@implementation MainFrameViewController { + NSOperationQueue* _opQueue; + MDNSManager* _mDNSManager; + Computer* _selectedHost; +} -+ (const char*)getHostAddr -{ - return [hostAddr UTF8String]; +- (int)getHostAddr { + return [_selectedHost resolveHost]; } - (void)PairButton:(UIButton *)sender @@ -29,17 +32,16 @@ MDNSManager* mDNSManager; NSString* uniqueId = [CryptoManager getUniqueID]; NSData* cert = [CryptoManager readCertFromFile]; - HttpManager* hMan = [[HttpManager alloc] initWithHost:hostAddr uniqueId:uniqueId deviceName:@"roth" cert:cert]; + HttpManager* hMan = [[HttpManager alloc] initWithHost:_selectedHost.hostName uniqueId:uniqueId deviceName:@"roth" cert:cert]; PairManager* pMan = [[PairManager alloc] initWithManager:hMan andCert:cert]; - - NSOperationQueue* opQueue = [[NSOperationQueue alloc] init]; - [opQueue addOperation:pMan]; + + [_opQueue addOperation:pMan]; } - (void)StreamButton:(UIButton *)sender { NSLog(@"Stream Button Pressed!"); - [ConnectionHandler streamWithHost:hostAddr viewController:self]; + [self segueIntoStream]; } - (void) segueIntoStream { @@ -59,11 +61,8 @@ MDNSManager* mDNSManager; - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { - self.hostPickerVals = [mDNSManager getFoundHosts]; - - [self.HostPicker reloadAllComponents]; if (pickerView == self.HostPicker) { - hostAddr = ((Computer*)([self.hostPickerVals objectAtIndex:[self.HostPicker selectedRowInComponent:0]])).hostName; + _selectedHost = (Computer*)([self.hostPickerVals objectAtIndex:[self.HostPicker selectedRowInComponent:0]]); } //TODO: figure out how to save this info!! @@ -95,13 +94,15 @@ MDNSManager* mDNSManager; self.hostPickerVals = [[NSArray alloc] init]; - mDNSManager = [[MDNSManager alloc] initWithCallback:self]; - [mDNSManager searchForHosts]; + _mDNSManager = [[MDNSManager alloc] initWithCallback:self]; + [_mDNSManager searchForHosts]; + _opQueue = [[NSOperationQueue alloc] init]; } - (void)updateHosts:(NSArray *)hosts { self.hostPickerVals = hosts; [self.HostPicker reloadAllComponents]; + _selectedHost = (Computer*)([self.hostPickerVals objectAtIndex:[self.HostPicker selectedRowInComponent:0]]); } - (void)didReceiveMemoryWarning diff --git a/Limelight/StreamFrameViewController.m b/Limelight/StreamFrameViewController.m index 986871f..67b12f2 100644 --- a/Limelight/StreamFrameViewController.m +++ b/Limelight/StreamFrameViewController.m @@ -20,7 +20,13 @@ @end -@implementation StreamFrameViewController +@implementation StreamFrameViewController { + int _host; +} + +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + _host = [sender getHostAddr]; +} - (void)viewDidLoad { @@ -30,7 +36,7 @@ VideoDecoderRenderer* renderer = [[VideoDecoderRenderer alloc]initWithView:self.view]; - Connection* conn = [[Connection alloc] initWithHost:inet_addr([[ConnectionHandler resolveHost:[NSString stringWithUTF8String:[MainFrameViewController getHostAddr]]] UTF8String]) width:1280 height:720 + Connection* conn = [[Connection alloc] initWithHost:_host width:1280 height:720 renderer: renderer]; NSOperationQueue* opQueue = [[NSOperationQueue alloc] init];