2014-08-31 13:13:46 -04:00
//
// StreamFrameViewController . m
// Limelight - iOS
//
// Created by Diego Waxemberg on 1 / 18 / 14.
// Copyright ( c ) 2014 Diego Waxemberg . All rights reserved .
//
# import "StreamFrameViewController.h"
# import "MainFrameViewController.h"
2014-10-18 22:43:52 -04:00
# import "VideoDecoderRenderer.h"
2014-10-20 19:20:50 -04:00
# import "StreamManager.h"
2014-10-20 21:13:13 -04:00
# import "ControllerSupport.h"
2014-12-28 21:42:18 -05:00
# import "StreamView.h"
2014-08-31 13:13:46 -04:00
# include < sys / socket . h >
# include < netinet / in . h >
# include < arpa / inet . h >
2014-10-20 21:13:13 -04:00
@ implementation StreamFrameViewController {
ControllerSupport * _controllerSupport ;
2014-10-21 01:54:31 -04:00
StreamManager * _streamMan ;
2014-10-20 21:13:13 -04:00
}
2014-08-31 13:13:46 -04:00
- ( void ) viewDidLoad
{
[ super viewDidLoad ] ;
2014-10-21 17:18:30 -04:00
2014-10-29 00:47:51 -04:00
[ self . navigationController setNavigationBarHidden : YES animated : YES ] ;
2014-10-21 17:18:30 -04:00
[ self . stageLabel setText : @ "Starting App" ] ;
2014-10-26 02:15:53 -04:00
[ self . stageLabel sizeToFit ] ;
2014-11-27 00:02:18 -05:00
self . stageLabel . center = CGPointMake ( self . view . frame . size . width / 2 , self . view . frame . size . height / 2 ) ;
2014-11-27 16:23:06 -05:00
self . spinner . center = CGPointMake ( self . view . frame . size . width / 2 , self . view . frame . size . height / 2 - self . stageLabel . frame . size . height - self . spinner . frame . size . height ) ;
2014-08-31 13:13:46 -04:00
[ UIApplication sharedApplication ] . idleTimerDisabled = YES ;
2014-10-19 00:09:47 -04:00
2014-10-20 21:13:13 -04:00
_controllerSupport = [ [ ControllerSupport alloc ] init ] ;
2014-10-21 14:54:10 -04:00
_streamMan = [ [ StreamManager alloc ] initWithConfig : [ MainFrameViewController getStreamConfiguration ]
renderView : self . view
connectionCallbacks : self ] ;
2014-08-31 13:13:46 -04:00
NSOperationQueue * opQueue = [ [ NSOperationQueue alloc ] init ] ;
2014-10-21 01:54:31 -04:00
[ opQueue addOperation : _streamMan ] ;
[ [ NSNotificationCenter defaultCenter ] addObserver : self
selector : @ selector ( applicationWillResignActive : )
name : UIApplicationWillResignActiveNotification
object : nil ] ;
}
2014-10-29 00:47:51 -04:00
- ( void ) returnToMainFrame {
[ self . navigationController popToRootViewControllerAnimated : YES ] ;
}
2014-10-21 01:54:31 -04:00
- ( void ) applicationWillResignActive : ( NSNotification * ) notification {
[ _streamMan stopStream ] ;
2014-10-29 00:47:51 -04:00
[ self returnToMainFrame ] ;
2014-08-31 13:13:46 -04:00
}
2015-01-09 15:22:12 -05:00
- ( void ) edgeSwiped {
[ _streamMan stopStream ] ;
[ self returnToMainFrame ] ;
}
2014-10-21 14:54:10 -04:00
- ( void ) connectionStarted {
2014-12-28 21:40:44 -05:00
NSLog ( @ "Connection started" ) ;
2014-10-21 17:18:30 -04:00
dispatch_async ( dispatch_get _main _queue ( ) , ^ {
[ self . spinner stopAnimating ] ;
[ self . stageLabel setText : @ "Waiting for first frame..." ] ;
2014-10-26 02:15:53 -04:00
[ self . stageLabel sizeToFit ] ;
2015-01-09 16:14:50 -05:00
[ ( StreamView * ) self . view setupOnScreenControls : _controllerSupport ] ;
2015-01-09 15:22:12 -05:00
UIScreenEdgePanGestureRecognizer * swipeGesture = [ [ UIScreenEdgePanGestureRecognizer alloc ] initWithTarget : self action : @ selector ( edgeSwiped ) ] ;
swipeGesture . edges = UIRectEdgeLeft ;
if ( swipeGesture = = nil ) {
NSLog ( @ "An error occured trying to create UIScreenEdgePanGestureRecognizer" ) ;
} else {
[ self . view addGestureRecognizer : swipeGesture ] ;
}
2014-10-21 17:18:30 -04:00
} ) ;
2014-10-21 14:54:10 -04:00
}
- ( void ) connectionTerminated : ( long ) errorCode {
printf ( "Connection terminated: %ld\n" , errorCode ) ;
2015-01-09 01:35:40 -05:00
UIAlertController * conTermAlert = [ UIAlertController alertControllerWithTitle : @ "Connection Terminated" message : @ "The connection was terminated" preferredStyle : UIAlertControllerStyleAlert ] ;
2014-10-21 01:02:04 -04:00
[ conTermAlert addAction : [ UIAlertAction actionWithTitle : @ "Ok" style : UIAlertActionStyleDestructive handler : ^ ( UIAlertAction * action ) {
2014-10-29 00:47:51 -04:00
[ self returnToMainFrame ] ;
2014-10-21 01:02:04 -04:00
} ] ] ;
[ self presentViewController : conTermAlert animated : YES completion : nil ] ;
2014-10-21 01:54:31 -04:00
[ _streamMan stopStream ] ;
2014-10-21 01:02:04 -04:00
}
2014-10-21 14:54:10 -04:00
- ( void ) stageStarting : ( char * ) stageName {
printf ( "Starting %s\n" , stageName ) ;
2014-10-21 17:18:30 -04:00
dispatch_async ( dispatch_get _main _queue ( ) , ^ {
NSString * lowerCase = [ NSString stringWithFormat : @ "%s in progress..." , stageName ] ;
NSString * titleCase = [ [ [ lowerCase substringToIndex : 1 ] uppercaseString ] stringByAppendingString : [ lowerCase substringFromIndex : 1 ] ] ;
[ self . stageLabel setText : titleCase ] ;
2014-10-26 02:15:53 -04:00
[ self . stageLabel sizeToFit ] ;
self . stageLabel . center = CGPointMake ( self . view . frame . size . width / 2 , self . stageLabel . center . y ) ;
2014-10-21 17:18:30 -04:00
} ) ;
2014-10-21 14:54:10 -04:00
}
- ( void ) stageComplete : ( char * ) stageName {
}
- ( void ) stageFailed : ( char * ) stageName withError : ( long ) errorCode {
UIAlertController * alert = [ UIAlertController alertControllerWithTitle : @ "Connection Failed"
message : [ NSString stringWithFormat : @ "%s failed with error %ld" ,
2014-10-21 17:18:30 -04:00
stageName , errorCode ]
2014-10-21 14:54:10 -04:00
preferredStyle : UIAlertControllerStyleAlert ] ;
[ alert addAction : [ UIAlertAction actionWithTitle : @ "Ok" style : UIAlertActionStyleDestructive handler : ^ ( UIAlertAction * action ) {
2014-10-29 00:47:51 -04:00
[ self returnToMainFrame ] ;
2014-10-21 14:54:10 -04:00
} ] ] ;
[ self presentViewController : alert animated : YES completion : nil ] ;
}
2014-10-23 23:41:07 -04:00
- ( void ) launchFailed : ( NSString * ) message {
2014-10-21 15:54:19 -04:00
UIAlertController * alert = [ UIAlertController alertControllerWithTitle : @ "Connection Failed"
2014-10-23 23:41:07 -04:00
message : message
2014-10-21 15:54:19 -04:00
preferredStyle : UIAlertControllerStyleAlert ] ;
[ alert addAction : [ UIAlertAction actionWithTitle : @ "Ok" style : UIAlertActionStyleDestructive handler : ^ ( UIAlertAction * action ) {
2014-10-29 00:47:51 -04:00
[ self returnToMainFrame ] ;
2014-10-21 15:54:19 -04:00
} ] ] ;
[ self presentViewController : alert animated : YES completion : nil ] ;
2014-10-21 14:54:10 -04:00
}
- ( void ) displayMessage : ( char * ) message {
printf ( "Display message: %s\n" , message ) ;
}
- ( void ) displayTransientMessage : ( char * ) message {
printf ( "Display transient message: %s\n" , message ) ;
}
2014-08-31 13:13:46 -04:00
- ( void ) didReceiveMemoryWarning
{
[ super didReceiveMemoryWarning ] ;
// Dispose of any resources that can be recreated .
}
2014-10-20 21:39:40 -04:00
- ( BOOL ) shouldAutorotate {
return YES ;
}
2014-08-31 13:13:46 -04:00
@ end