now goes back to main frame when connection is terminated

This commit is contained in:
Diego Waxemberg 2014-10-21 01:02:04 -04:00
parent 127c53e341
commit a359aee36c
8 changed files with 71 additions and 46 deletions

View File

@ -10,9 +10,15 @@
#import "VideoDecoderRenderer.h" #import "VideoDecoderRenderer.h"
#import "StreamConfiguration.h" #import "StreamConfiguration.h"
@protocol ConTermCallback <NSObject>
- (void) connectionTerminated;
@end
@interface Connection : NSOperation <NSStreamDelegate> @interface Connection : NSOperation <NSStreamDelegate>
-(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer; -(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer connectionTerminatedCallback:(id<ConTermCallback>)callback;
-(void) main; -(void) main;
@end @end

View File

@ -15,15 +15,16 @@
#include "opus.h" #include "opus.h"
@implementation Connection { @implementation Connection {
IP_ADDRESS host; IP_ADDRESS _host;
STREAM_CONFIGURATION streamConfig; STREAM_CONFIGURATION _streamConfig;
CONNECTION_LISTENER_CALLBACKS clCallbacks; CONNECTION_LISTENER_CALLBACKS _clCallbacks;
DECODER_RENDERER_CALLBACKS drCallbacks; DECODER_RENDERER_CALLBACKS _drCallbacks;
AUDIO_RENDERER_CALLBACKS arCallbacks; AUDIO_RENDERER_CALLBACKS _arCallbacks;
} }
static OpusDecoder *opusDecoder; static OpusDecoder *opusDecoder;
static id<ConTermCallback> _callback;
#define PCM_BUFFER_SIZE 1024 #define PCM_BUFFER_SIZE 1024
#define OUTPUT_BUS 0 #define OUTPUT_BUS 0
@ -181,6 +182,8 @@ void ClConnectionStarted(void)
void ClConnectionTerminated(long errorCode) void ClConnectionTerminated(long errorCode)
{ {
NSLog(@"ConnectionTerminated: %ld", errorCode); NSLog(@"ConnectionTerminated: %ld", errorCode);
[_callback connectionTerminated];
NSLog(@"Tried calling callback");
} }
void ClDisplayMessage(char* message) void ClDisplayMessage(char* message)
@ -193,42 +196,42 @@ void ClDisplayTransientMessage(char* message)
NSLog(@"DisplayTransientMessage: %s", message); NSLog(@"DisplayTransientMessage: %s", message);
} }
-(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer -(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer connectionTerminatedCallback:(id<ConTermCallback>)callback
{ {
self = [super init]; self = [super init];
host = config.hostAddr; _host = config.hostAddr;
renderer = myRenderer; 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; memcpy(_streamConfig.remoteInputAesKey, [config.riKey bytes], [config.riKey length]);
streamConfig.height = config.height; memset(_streamConfig.remoteInputAesIv, 0, 16);
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);
int riKeyId = htonl(config.riKeyId); int riKeyId = htonl(config.riKeyId);
memcpy(streamConfig.remoteInputAesIv, &riKeyId, sizeof(riKeyId)); memcpy(_streamConfig.remoteInputAesIv, &riKeyId, sizeof(riKeyId));
drCallbacks.setup = DrSetup; _drCallbacks.setup = DrSetup;
drCallbacks.start = DrStart; _drCallbacks.start = DrStart;
drCallbacks.stop = DrStop; _drCallbacks.stop = DrStop;
drCallbacks.release = DrRelease; _drCallbacks.release = DrRelease;
drCallbacks.submitDecodeUnit = DrSubmitDecodeUnit; _drCallbacks.submitDecodeUnit = DrSubmitDecodeUnit;
arCallbacks.init = ArInit; _arCallbacks.init = ArInit;
arCallbacks.start = ArStart; _arCallbacks.start = ArStart;
arCallbacks.stop = ArStop; _arCallbacks.stop = ArStop;
arCallbacks.release = ArRelease; _arCallbacks.release = ArRelease;
arCallbacks.decodeAndPlaySample = ArDecodeAndPlaySample; _arCallbacks.decodeAndPlaySample = ArDecodeAndPlaySample;
clCallbacks.stageStarting = ClStageStarting; _clCallbacks.stageStarting = ClStageStarting;
clCallbacks.stageComplete = ClStageComplete; _clCallbacks.stageComplete = ClStageComplete;
clCallbacks.stageFailed = ClStageFailed; _clCallbacks.stageFailed = ClStageFailed;
clCallbacks.connectionStarted = ClConnectionStarted; _clCallbacks.connectionStarted = ClConnectionStarted;
clCallbacks.connectionTerminated = ClConnectionTerminated; _clCallbacks.connectionTerminated = ClConnectionTerminated;
clCallbacks.displayMessage = ClDisplayMessage; _clCallbacks.displayMessage = ClDisplayMessage;
clCallbacks.displayTransientMessage = ClDisplayTransientMessage; _clCallbacks.displayTransientMessage = ClDisplayTransientMessage;
// Configure the audio session for our app // Configure the audio session for our app
NSError *audioSessionError = nil; NSError *audioSessionError = nil;
@ -388,7 +391,7 @@ static OSStatus playbackCallback(void *inRefCon,
-(void) main -(void) main
{ {
LiStartConnection(host, &streamConfig, &clCallbacks, &drCallbacks, &arCallbacks, NULL, 0); LiStartConnection(_host, &_streamConfig, &_clCallbacks, &_drCallbacks, &_arCallbacks, NULL, 0);
} }

View File

@ -6,8 +6,10 @@
// Copyright (c) 2014 Diego Waxemberg. All rights reserved. // Copyright (c) 2014 Diego Waxemberg. All rights reserved.
// //
#import "Connection.h"
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
@interface StreamFrameViewController : UIViewController @interface StreamFrameViewController : UIViewController <ConTermCallback>
@end @end

View File

@ -8,7 +8,6 @@
#import "StreamFrameViewController.h" #import "StreamFrameViewController.h"
#import "MainFrameViewController.h" #import "MainFrameViewController.h"
#import "Connection.h"
#import "VideoDecoderRenderer.h" #import "VideoDecoderRenderer.h"
#import "StreamManager.h" #import "StreamManager.h"
#import "ControllerSupport.h" #import "ControllerSupport.h"
@ -29,11 +28,20 @@
_controllerSupport = [[ControllerSupport alloc] init]; _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]; NSOperationQueue* opQueue = [[NSOperationQueue alloc] init];
[opQueue addOperation:streamMan]; [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 - (void)didReceiveMemoryWarning
{ {
[super didReceiveMemoryWarning]; [super didReceiveMemoryWarning];

View File

@ -8,9 +8,9 @@
#import <Foundation/Foundation.h> #import <Foundation/Foundation.h>
#import "StreamConfiguration.h" #import "StreamConfiguration.h"
#import "Connection.h"
@interface StreamManager : NSOperation @interface StreamManager : NSOperation
- (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view; - (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view connectionTerminatedCallback:(id<ConTermCallback>)callback;
@end @end

View File

@ -10,17 +10,18 @@
#import "CryptoManager.h" #import "CryptoManager.h"
#import "HttpManager.h" #import "HttpManager.h"
#import "Utils.h" #import "Utils.h"
#import "Connection.h"
@implementation StreamManager { @implementation StreamManager {
StreamConfiguration* _config; StreamConfiguration* _config;
UIView* _renderView; UIView* _renderView;
id<ConTermCallback> _callback;
} }
- (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view { - (id) initWithConfig:(StreamConfiguration*)config renderView:(UIView*)view connectionTerminatedCallback:(id<ConTermCallback>)callback {
self = [super init]; self = [super init];
_config = config; _config = config;
_renderView = view; _renderView = view;
_callback = callback;
_config.riKey = [Utils randomBytes:16]; _config.riKey = [Utils randomBytes:16];
_config.riKeyId = arc4random(); _config.riKeyId = arc4random();
_config.bitRate = 10000; _config.bitRate = 10000;
@ -48,8 +49,7 @@
} }
VideoDecoderRenderer* renderer = [[VideoDecoderRenderer alloc]initWithView:_renderView]; 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]; NSOperationQueue* opQueue = [[NSOperationQueue alloc] init];
[opQueue addOperation:conn]; [opQueue addOperation:conn];
} }

View File

@ -71,7 +71,7 @@
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="ZYl-Xu-QyD" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="ZYl-Xu-QyD" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects> </objects>
<point key="canvasLocation" x="179" y="-318"/> <point key="canvasLocation" x="-375" y="-162"/>
</scene> </scene>
<!--Stream Frame View Controller--> <!--Stream Frame View Controller-->
<scene sceneID="RuD-qk-7nb"> <scene sceneID="RuD-qk-7nb">
@ -91,6 +91,9 @@
<nil key="simulatedBottomBarMetrics"/> <nil key="simulatedBottomBarMetrics"/>
<simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/> <simulatedOrientationMetrics key="simulatedOrientationMetrics" orientation="landscapeRight"/>
<simulatedScreenMetrics key="simulatedDestinationMetrics"/> <simulatedScreenMetrics key="simulatedDestinationMetrics"/>
<connections>
<segue destination="wb7-af-jn8" kind="modal" identifier="returnToMainFrame" id="Ryr-0y-o43"/>
</connections>
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="hON-k2-Efa" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="hON-k2-Efa" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects> </objects>

View File

@ -108,6 +108,9 @@
<nil key="simulatedStatusBarMetrics"/> <nil key="simulatedStatusBarMetrics"/>
<nil key="simulatedTopBarMetrics"/> <nil key="simulatedTopBarMetrics"/>
<nil key="simulatedBottomBarMetrics"/> <nil key="simulatedBottomBarMetrics"/>
<connections>
<segue destination="dgh-JZ-Q7z" kind="modal" identifier="returnToMainFrame" id="djB-MF-L5D"/>
</connections>
</viewController> </viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="pqv-jd-33O" userLabel="First Responder" sceneMemberID="firstResponder"/> <placeholder placeholderIdentifier="IBFirstResponder" id="pqv-jd-33O" userLabel="First Responder" sceneMemberID="firstResponder"/>
</objects> </objects>