From a359aee36c16b8068e6525929aff96c77f12983c Mon Sep 17 00:00:00 2001 From: Diego Waxemberg Date: Tue, 21 Oct 2014 01:02:04 -0400 Subject: [PATCH] now goes back to main frame when connection is terminated --- Limelight/Connection.h | 8 ++- Limelight/Connection.m | 73 ++++++++++++++------------- Limelight/StreamFrameViewController.h | 4 +- Limelight/StreamFrameViewController.m | 12 ++++- Limelight/StreamManager.h | 4 +- Limelight/StreamManager.m | 8 +-- MainFrame-iPad.storyboard | 5 +- MainFrame-iPhone.storyboard | 3 ++ 8 files changed, 71 insertions(+), 46 deletions(-) diff --git a/Limelight/Connection.h b/Limelight/Connection.h index 502ce42..d897186 100644 --- a/Limelight/Connection.h +++ b/Limelight/Connection.h @@ -10,9 +10,15 @@ #import "VideoDecoderRenderer.h" #import "StreamConfiguration.h" +@protocol ConTermCallback + +- (void) connectionTerminated; + +@end + @interface Connection : NSOperation --(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer; +-(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer connectionTerminatedCallback:(id)callback; -(void) main; @end diff --git a/Limelight/Connection.m b/Limelight/Connection.m index 1f27fcf..5b22960 100644 --- a/Limelight/Connection.m +++ b/Limelight/Connection.m @@ -15,15 +15,16 @@ #include "opus.h" @implementation Connection { - IP_ADDRESS host; - STREAM_CONFIGURATION streamConfig; - CONNECTION_LISTENER_CALLBACKS clCallbacks; - DECODER_RENDERER_CALLBACKS drCallbacks; - AUDIO_RENDERER_CALLBACKS arCallbacks; + IP_ADDRESS _host; + STREAM_CONFIGURATION _streamConfig; + CONNECTION_LISTENER_CALLBACKS _clCallbacks; + DECODER_RENDERER_CALLBACKS _drCallbacks; + AUDIO_RENDERER_CALLBACKS _arCallbacks; + } static OpusDecoder *opusDecoder; - +static id _callback; #define PCM_BUFFER_SIZE 1024 #define OUTPUT_BUS 0 @@ -181,6 +182,8 @@ void ClConnectionStarted(void) void ClConnectionTerminated(long errorCode) { NSLog(@"ConnectionTerminated: %ld", errorCode); + [_callback connectionTerminated]; + NSLog(@"Tried calling callback"); } void ClDisplayMessage(char* message) @@ -193,42 +196,42 @@ void ClDisplayTransientMessage(char* message) NSLog(@"DisplayTransientMessage: %s", message); } --(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer +-(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer connectionTerminatedCallback:(id)callback { self = [super init]; - host = config.hostAddr; + _host = config.hostAddr; renderer = myRenderer; + _callback = callback; + _streamConfig.width = config.width; + _streamConfig.height = config.height; + _streamConfig.fps = config.frameRate; + _streamConfig.bitrate = config.bitRate; + _streamConfig.packetSize = 1024; - streamConfig.width = config.width; - streamConfig.height = config.height; - streamConfig.fps = config.frameRate; - streamConfig.bitrate = config.bitRate; - streamConfig.packetSize = 1024; - - memcpy(streamConfig.remoteInputAesKey, [config.riKey bytes], [config.riKey length]); - memset(streamConfig.remoteInputAesIv, 0, 16); + memcpy(_streamConfig.remoteInputAesKey, [config.riKey bytes], [config.riKey length]); + memset(_streamConfig.remoteInputAesIv, 0, 16); int riKeyId = htonl(config.riKeyId); - memcpy(streamConfig.remoteInputAesIv, &riKeyId, sizeof(riKeyId)); + memcpy(_streamConfig.remoteInputAesIv, &riKeyId, sizeof(riKeyId)); - drCallbacks.setup = DrSetup; - drCallbacks.start = DrStart; - drCallbacks.stop = DrStop; - drCallbacks.release = DrRelease; - drCallbacks.submitDecodeUnit = DrSubmitDecodeUnit; + _drCallbacks.setup = DrSetup; + _drCallbacks.start = DrStart; + _drCallbacks.stop = DrStop; + _drCallbacks.release = DrRelease; + _drCallbacks.submitDecodeUnit = DrSubmitDecodeUnit; - arCallbacks.init = ArInit; - arCallbacks.start = ArStart; - arCallbacks.stop = ArStop; - arCallbacks.release = ArRelease; - arCallbacks.decodeAndPlaySample = ArDecodeAndPlaySample; + _arCallbacks.init = ArInit; + _arCallbacks.start = ArStart; + _arCallbacks.stop = ArStop; + _arCallbacks.release = ArRelease; + _arCallbacks.decodeAndPlaySample = ArDecodeAndPlaySample; - clCallbacks.stageStarting = ClStageStarting; - clCallbacks.stageComplete = ClStageComplete; - clCallbacks.stageFailed = ClStageFailed; - clCallbacks.connectionStarted = ClConnectionStarted; - clCallbacks.connectionTerminated = ClConnectionTerminated; - clCallbacks.displayMessage = ClDisplayMessage; - clCallbacks.displayTransientMessage = ClDisplayTransientMessage; + _clCallbacks.stageStarting = ClStageStarting; + _clCallbacks.stageComplete = ClStageComplete; + _clCallbacks.stageFailed = ClStageFailed; + _clCallbacks.connectionStarted = ClConnectionStarted; + _clCallbacks.connectionTerminated = ClConnectionTerminated; + _clCallbacks.displayMessage = ClDisplayMessage; + _clCallbacks.displayTransientMessage = ClDisplayTransientMessage; // Configure the audio session for our app NSError *audioSessionError = nil; @@ -388,7 +391,7 @@ static OSStatus playbackCallback(void *inRefCon, -(void) main { - LiStartConnection(host, &streamConfig, &clCallbacks, &drCallbacks, &arCallbacks, NULL, 0); + LiStartConnection(_host, &_streamConfig, &_clCallbacks, &_drCallbacks, &_arCallbacks, NULL, 0); } diff --git a/Limelight/StreamFrameViewController.h b/Limelight/StreamFrameViewController.h index 94fea5e..adbcd29 100644 --- a/Limelight/StreamFrameViewController.h +++ b/Limelight/StreamFrameViewController.h @@ -6,8 +6,10 @@ // Copyright (c) 2014 Diego Waxemberg. All rights reserved. // +#import "Connection.h" + #import -@interface StreamFrameViewController : UIViewController +@interface StreamFrameViewController : UIViewController @end diff --git a/Limelight/StreamFrameViewController.m b/Limelight/StreamFrameViewController.m index 8514e3f..26ae694 100644 --- a/Limelight/StreamFrameViewController.m +++ b/Limelight/StreamFrameViewController.m @@ -8,7 +8,6 @@ #import "StreamFrameViewController.h" #import "MainFrameViewController.h" -#import "Connection.h" #import "VideoDecoderRenderer.h" #import "StreamManager.h" #import "ControllerSupport.h" @@ -29,11 +28,20 @@ _controllerSupport = [[ControllerSupport alloc] init]; - StreamManager* streamMan = [[StreamManager alloc] initWithConfig:[MainFrameViewController getStreamConfiguration] renderView:self.view]; + StreamManager* streamMan = [[StreamManager alloc] initWithConfig:[MainFrameViewController getStreamConfiguration] renderView:self.view connectionTerminatedCallback:self]; NSOperationQueue* opQueue = [[NSOperationQueue alloc] init]; [opQueue addOperation:streamMan]; } +- (void)connectionTerminated { + NSLog(@"StreamFrame - Connection Terminated"); + UIAlertController* conTermAlert = [UIAlertController alertControllerWithTitle:@"Connection Terminated" message:@"The connection terminated unexpectedly" preferredStyle:UIAlertControllerStyleAlert]; + [conTermAlert addAction:[UIAlertAction actionWithTitle:@"Ok" style:UIAlertActionStyleDestructive handler:^(UIAlertAction* action){ + [self performSegueWithIdentifier:@"returnToMainFrame" sender:self]; + }]]; + [self presentViewController:conTermAlert animated:YES completion:nil]; +} + - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; diff --git a/Limelight/StreamManager.h b/Limelight/StreamManager.h index a08aa57..1a3565f 100644 --- a/Limelight/StreamManager.h +++ b/Limelight/StreamManager.h @@ -8,9 +8,9 @@ #import #import "StreamConfiguration.h" +#import "Connection.h" @interface StreamManager : NSOperation -- (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view; - +- (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view connectionTerminatedCallback:(id)callback; @end diff --git a/Limelight/StreamManager.m b/Limelight/StreamManager.m index afaec5c..be9aad5 100644 --- a/Limelight/StreamManager.m +++ b/Limelight/StreamManager.m @@ -10,17 +10,18 @@ #import "CryptoManager.h" #import "HttpManager.h" #import "Utils.h" -#import "Connection.h" @implementation StreamManager { StreamConfiguration* _config; UIView* _renderView; + id _callback; } -- (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view { +- (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view connectionTerminatedCallback:(id)callback { self = [super init]; _config = config; _renderView = view; + _callback = callback; _config.riKey = [Utils randomBytes:16]; _config.riKeyId = arc4random(); _config.bitRate = 10000; @@ -48,8 +49,7 @@ } VideoDecoderRenderer* renderer = [[VideoDecoderRenderer alloc]initWithView:_renderView]; - Connection* conn = [[Connection alloc] initWithConfig:_config renderer:renderer]; - + Connection* conn = [[Connection alloc] initWithConfig:_config renderer:renderer connectionTerminatedCallback:_callback]; NSOperationQueue* opQueue = [[NSOperationQueue alloc] init]; [opQueue addOperation:conn]; } diff --git a/MainFrame-iPad.storyboard b/MainFrame-iPad.storyboard index cbe41c1..da64e55 100644 --- a/MainFrame-iPad.storyboard +++ b/MainFrame-iPad.storyboard @@ -71,7 +71,7 @@ - + @@ -91,6 +91,9 @@ + + + diff --git a/MainFrame-iPhone.storyboard b/MainFrame-iPhone.storyboard index e1c21c1..8d7030a 100644 --- a/MainFrame-iPhone.storyboard +++ b/MainFrame-iPhone.storyboard @@ -108,6 +108,9 @@ + + +