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 "StreamConfiguration.h"
@protocol ConTermCallback <NSObject>
- (void) connectionTerminated;
@end
@interface Connection : NSOperation <NSStreamDelegate>
-(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer;
-(id) initWithConfig:(StreamConfiguration*)config renderer:(VideoDecoderRenderer*)myRenderer connectionTerminatedCallback:(id<ConTermCallback>)callback;
-(void) main;
@end

View File

@ -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<ConTermCallback> _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<ConTermCallback>)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);
}

View File

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

View File

@ -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];

View File

@ -8,9 +8,9 @@
#import <Foundation/Foundation.h>
#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<ConTermCallback>)callback;
@end

View File

@ -10,17 +10,18 @@
#import "CryptoManager.h"
#import "HttpManager.h"
#import "Utils.h"
#import "Connection.h"
@implementation StreamManager {
StreamConfiguration* _config;
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];
_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];
}

View File

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

View File

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