joining stream works

This commit is contained in:
Diego Waxemberg
2014-10-20 11:31:40 -04:00
parent f909371a90
commit 44a7494823
6 changed files with 57 additions and 21 deletions
+1
View File
@@ -14,5 +14,6 @@
@property BOOL paired; @property BOOL paired;
- (id) initWithHost:(NSNetService*)host; - (id) initWithHost:(NSNetService*)host;
- (int) resolveHost;
@end @end
+29
View File
@@ -8,6 +8,10 @@
#import "Computer.h" #import "Computer.h"
#include <arpa/inet.h>
#include <netinet/in.h>
#include <netdb.h>
@implementation Computer @implementation Computer
- (id) initWithHost:(NSNetService *)host { - (id) initWithHost:(NSNetService *)host {
@@ -19,4 +23,29 @@
return self; 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 @end
-1
View File
@@ -20,7 +20,6 @@
- (id) initWithCallback:(id<MDNSCallback>) callback; - (id) initWithCallback:(id<MDNSCallback>) callback;
- (void) searchForHosts; - (void) searchForHosts;
- (NSArray*) getFoundHosts;
@end @end
+1 -1
View File
@@ -18,7 +18,7 @@
@property (strong, nonatomic) NSArray* streamConfigVals; @property (strong, nonatomic) NSArray* streamConfigVals;
@property (strong, nonatomic) NSArray* hostPickerVals; @property (strong, nonatomic) NSArray* hostPickerVals;
+ (const char*)getHostAddr; - (int) getHostAddr;
- (void) segueIntoStream; - (void) segueIntoStream;
@end @end
+18 -17
View File
@@ -12,14 +12,17 @@
#import "CryptoManager.h" #import "CryptoManager.h"
#import "HttpManager.h" #import "HttpManager.h"
#import "PairManager.h" #import "PairManager.h"
#import "Connection.h"
#import "VideoDecoderRenderer.h"
@implementation MainFrameViewController @implementation MainFrameViewController {
NSString* hostAddr; NSOperationQueue* _opQueue;
MDNSManager* mDNSManager; MDNSManager* _mDNSManager;
Computer* _selectedHost;
}
+ (const char*)getHostAddr - (int)getHostAddr {
{ return [_selectedHost resolveHost];
return [hostAddr UTF8String];
} }
- (void)PairButton:(UIButton *)sender - (void)PairButton:(UIButton *)sender
@@ -29,17 +32,16 @@ MDNSManager* mDNSManager;
NSString* uniqueId = [CryptoManager getUniqueID]; NSString* uniqueId = [CryptoManager getUniqueID];
NSData* cert = [CryptoManager readCertFromFile]; 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]; PairManager* pMan = [[PairManager alloc] initWithManager:hMan andCert:cert];
NSOperationQueue* opQueue = [[NSOperationQueue alloc] init]; [_opQueue addOperation:pMan];
[opQueue addOperation:pMan];
} }
- (void)StreamButton:(UIButton *)sender - (void)StreamButton:(UIButton *)sender
{ {
NSLog(@"Stream Button Pressed!"); NSLog(@"Stream Button Pressed!");
[ConnectionHandler streamWithHost:hostAddr viewController:self]; [self segueIntoStream];
} }
- (void) segueIntoStream { - (void) segueIntoStream {
@@ -59,11 +61,8 @@ MDNSManager* mDNSManager;
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{ {
self.hostPickerVals = [mDNSManager getFoundHosts];
[self.HostPicker reloadAllComponents];
if (pickerView == self.HostPicker) { 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!! //TODO: figure out how to save this info!!
@@ -95,13 +94,15 @@ MDNSManager* mDNSManager;
self.hostPickerVals = [[NSArray alloc] init]; self.hostPickerVals = [[NSArray alloc] init];
mDNSManager = [[MDNSManager alloc] initWithCallback:self]; _mDNSManager = [[MDNSManager alloc] initWithCallback:self];
[mDNSManager searchForHosts]; [_mDNSManager searchForHosts];
_opQueue = [[NSOperationQueue alloc] init];
} }
- (void)updateHosts:(NSArray *)hosts { - (void)updateHosts:(NSArray *)hosts {
self.hostPickerVals = hosts; self.hostPickerVals = hosts;
[self.HostPicker reloadAllComponents]; [self.HostPicker reloadAllComponents];
_selectedHost = (Computer*)([self.hostPickerVals objectAtIndex:[self.HostPicker selectedRowInComponent:0]]);
} }
- (void)didReceiveMemoryWarning - (void)didReceiveMemoryWarning
+8 -2
View File
@@ -20,7 +20,13 @@
@end @end
@implementation StreamFrameViewController @implementation StreamFrameViewController {
int _host;
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
_host = [sender getHostAddr];
}
- (void)viewDidLoad - (void)viewDidLoad
{ {
@@ -30,7 +36,7 @@
VideoDecoderRenderer* renderer = [[VideoDecoderRenderer alloc]initWithView:self.view]; 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]; renderer: renderer];
NSOperationQueue* opQueue = [[NSOperationQueue alloc] init]; NSOperationQueue* opQueue = [[NSOperationQueue alloc] init];