diff --git a/Classes/LinphoneAppDelegate.h b/Classes/LinphoneAppDelegate.h index cf01f937c..f13b8cb84 100644 --- a/Classes/LinphoneAppDelegate.h +++ b/Classes/LinphoneAppDelegate.h @@ -44,6 +44,10 @@ CTCallCenter* callCenter; } +- (void) loadDefaultSettings:(NSDictionary *) appDefaults; +-(void) setupUI; +-(void) setupGSMInteraction; + @property (nonatomic, retain) IBOutlet UIWindow *window; @property (nonatomic, retain) IBOutlet UITabBarController* myTabBarController; @property (nonatomic, retain) ABPeoplePickerNavigationController* myPeoplePickerController; diff --git a/Classes/LinphoneAppDelegate.m b/Classes/LinphoneAppDelegate.m index 8cbd45e2c..6e6653dbc 100644 --- a/Classes/LinphoneAppDelegate.m +++ b/Classes/LinphoneAppDelegate.m @@ -125,7 +125,7 @@ int __aeabi_idiv(int a, int b) { } } -- (void) loadDefaultSettings { +- (void) loadDefaultSettings:(NSDictionary *) appDefaults { NSString *settingsBundle = [[NSBundle mainBundle] pathForResource:@"Settings" ofType:@"bundle"]; if(!settingsBundle) { @@ -149,33 +149,15 @@ int __aeabi_idiv(int a, int b) { [defaultsToRegister setObject:[prefSpecification objectForKey:@"DefaultValue"] forKey:key]; } } - - NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys: - @"NO", @"enable_first_login_view_preference", // -#ifdef HAVE_AMR - @"YES",@"amr_8k_preference", // enable amr by default if compiled with -#endif -#ifdef HAVE_G729 - @"YES",@"g729_preference", // enable amr by default if compiled with -#endif - @"NO",@"debugenable_preference", - //@"+33",@"countrycode_preference", - nil]; - + [defaultsToRegister addEntriesFromDictionary:appDefaults]; [[NSUserDefaults standardUserDefaults] registerDefaults:defaultsToRegister]; [defaultsToRegister release]; [[NSUserDefaults standardUserDefaults] synchronize]; - } -- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ - - /* - *Custumization - */ - [self loadDefaultSettings]; - //as defined in PhoneMainView.xib +-(void) setupUI { + //as defined in PhoneMainView.xib //dialer myPhoneViewController = (PhoneViewController*) [myTabBarController.viewControllers objectAtIndex: DIALER_TAB_INDEX]; myPhoneViewController.myTabBarController = myTabBarController; @@ -217,17 +199,44 @@ int __aeabi_idiv(int a, int b) { [window makeKeyAndVisible]; [[LinphoneManager instance] setCallDelegate:myPhoneViewController]; - [[LinphoneManager instance] startLibLinphone]; - - [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound]; +} +-(void) setupGSMInteraction { callCenter = [[CTCallCenter alloc] init]; callCenter.callEventHandler = ^(CTCall* call) { // post on main thread [self performSelectorOnMainThread:@selector(handleGSMCallInteration:) withObject:callCenter waitUntilDone:YES]; - }; + }; +} + +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ + NSDictionary *appDefaults = [NSDictionary dictionaryWithObjectsAndKeys: + @"NO", @"enable_first_login_view_preference", // +#ifdef HAVE_AMR + @"YES",@"amr_8k_preference", // enable amr by default if compiled with +#endif +#ifdef HAVE_G729 + @"YES",@"g729_preference", // enable amr by default if compiled with +#endif + //@"+33",@"countrycode_preference", + nil]; + + /* explicitely instanciate LinphoneManager */ + LinphoneManager* lm = [[LinphoneManager alloc] init]; + assert(lm == [LinphoneManager instance]); + + [self loadDefaultSettings: appDefaults]; + + [self setupUI]; + + [[LinphoneManager instance] startLibLinphone]; + + [[UIApplication sharedApplication] registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound]; + + [self setupGSMInteraction]; + return YES; } diff --git a/Classes/LinphoneUI/LinphoneManager.h b/Classes/LinphoneUI/LinphoneManager.h index d31962ddb..f68b7739f 100644 --- a/Classes/LinphoneUI/LinphoneManager.h +++ b/Classes/LinphoneUI/LinphoneManager.h @@ -36,10 +36,16 @@ typedef struct _CallContext { bool_t cameraIsEnabled; } CallContext; +struct NetworkReachabilityContext { + bool_t testWifi, testWWan; + void (*networkStateChanged) (Connectivity newConnectivity); +}; + + @interface LinphoneManager : NSObject { -@private - SCNetworkReachabilityContext proxyReachabilityContext; +@protected SCNetworkReachabilityRef proxyReachability; +@private NSTimer* mIterateTimer; id mLogView; bool isbackgroundModeEnabled; @@ -76,6 +82,7 @@ typedef struct _CallContext { -(UIImage*) getImageFromAddressBook:(NSString*) number; -(BOOL) reconfigureLinphoneIfNeeded:(NSDictionary *)oldSettings; +-(void) setupNetworkReachabilityCallback: (const char*) nodeName withContext:(SCNetworkReachabilityContext*) ctx; @property (nonatomic, retain) id callDelegate; @property (nonatomic, retain) id registrationDelegate; @@ -84,4 +91,3 @@ typedef struct _CallContext { @property (readonly) const char* backCamId; @end - diff --git a/Classes/LinphoneUI/LinphoneManager.m b/Classes/LinphoneUI/LinphoneManager.m index ca1b5ac2c..a1a7dc7d5 100644 --- a/Classes/LinphoneUI/LinphoneManager.m +++ b/Classes/LinphoneUI/LinphoneManager.m @@ -57,14 +57,16 @@ extern void libmsbcg729_init(); @synthesize backCamId; -(id) init { + assert (!theLinphoneManager); if ((self= [super init])) { mFastAddressBook = [[FastAddressBook alloc] init]; + theLinphoneManager = self; } return self; } +(LinphoneManager*) instance { if (theLinphoneManager==nil) { - theLinphoneManager = [[LinphoneManager alloc] init]; + [[LinphoneManager alloc] init]; } return theLinphoneManager; } @@ -413,16 +415,21 @@ static LinphoneCoreVTable linphonec_vtable = { CFWriteStreamClose (writeStream); } -void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void * info) { +void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReachabilityFlags flags, void* nilCtx) { ms_message("Network connection flag [%x]",flags); - LinphoneManager* lLinphoneMgr = (LinphoneManager*)info; + LinphoneManager* lLinphoneMgr = [LinphoneManager instance]; if ([LinphoneManager getLc] != nil) { + struct NetworkReachabilityContext* ctx = nilCtx ? ((struct NetworkReachabilityContext*)nilCtx) : 0; if ((flags == 0) | (flags & (kSCNetworkReachabilityFlagsConnectionRequired |kSCNetworkReachabilityFlagsConnectionOnTraffic))) { [[LinphoneManager instance] kickOffNetworkConnection]; linphone_core_set_network_reachable([LinphoneManager getLc],false); - ((LinphoneManager*)info).connectivity = none; + lLinphoneMgr.connectivity = none; } else { - Connectivity newConnectivity = flags & kSCNetworkReachabilityFlagsIsWWAN ? wwan:wifi; + Connectivity newConnectivity; + if (!ctx || ctx->testWWan) + newConnectivity = flags & kSCNetworkReachabilityFlagsIsWWAN ? wwan:wifi; + else + newConnectivity = wifi; if (lLinphoneMgr.connectivity == none) { linphone_core_set_network_reachable([LinphoneManager getLc],true); } else if (lLinphoneMgr.connectivity != newConnectivity) { @@ -433,7 +440,9 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach lLinphoneMgr.connectivity=newConnectivity; ms_message("new network connectivity of type [%s]",(newConnectivity==wifi?"wifi":"wwan")); } - + if (ctx && ctx->networkStateChanged) { + (*ctx->networkStateChanged)(lLinphoneMgr.connectivity); + } } } @@ -649,7 +658,7 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach } bool enableSrtp = [[NSUserDefaults standardUserDefaults] boolForKey:@"enable_srtp_preference"]; linphone_core_set_media_encryption(theLinphoneCore, enableSrtp?LinphoneMediaEncryptionSRTP:LinphoneMediaEncryptionZRTP); - + NSString* stun_server = [[NSUserDefaults standardUserDefaults] stringForKey:@"stun_preference"]; if ([stun_server length]>0){ linphone_core_set_stun_server(theLinphoneCore,[stun_server cStringUsingEncoding:[NSString defaultCStringEncoding]]); @@ -707,7 +716,8 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach linphone_core_destroy(theLinphoneCore); theLinphoneCore = nil; SCNetworkReachabilityUnscheduleFromRunLoop(proxyReachability, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); - CFRelease(proxyReachability); + if (proxyReachability) + CFRelease(proxyReachability); proxyReachability=nil; } @@ -762,7 +772,6 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach [self destroyLibLinphone]; return NO; } - } @@ -772,7 +781,30 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach } - +-(void) setupNetworkReachabilityCallback: (const char*) nodeName withContext:(SCNetworkReachabilityContext*) ctx { + if (proxyReachability) { + ms_message("Cancel old network reachability check"); + SCNetworkReachabilityUnscheduleFromRunLoop(proxyReachability, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); + CFRelease(proxyReachability); + proxyReachability = nil; + } + + proxyReachability = SCNetworkReachabilityCreateWithName(nil, nodeName); + + //initial state is network off should be done as soon as possible + SCNetworkReachabilityFlags flags; + if (!SCNetworkReachabilityGetFlags(proxyReachability, &flags)) { + ms_error("Cannot get reachability flags"); + }; + networkReachabilityCallBack(proxyReachability, flags, ctx ? ctx->info : 0); + + if (!SCNetworkReachabilitySetCallback(proxyReachability, (SCNetworkReachabilityCallBack)networkReachabilityCallBack, ctx)){ + ms_error("Cannot register reachability cb"); + }; + if(!SCNetworkReachabilityScheduleWithRunLoop(proxyReachability, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)){ + ms_error("Cannot register schedule reachability cb"); + }; +} /************* @@ -824,22 +856,8 @@ void networkReachabilityCallBack(SCNetworkReachabilityRef target, SCNetworkReach linphone_core_set_zrtp_secrets_file(theLinphoneCore, [zrtpSecretsFileName cStringUsingEncoding:[NSString defaultCStringEncoding]]); - proxyReachability=SCNetworkReachabilityCreateWithName(nil, "linphone.org"); - proxyReachabilityContext.info=self; - //initial state is network off should be done as soon as possible - SCNetworkReachabilityFlags flags; - if (!SCNetworkReachabilityGetFlags(proxyReachability, &flags)) { - ms_error("Cannot get reachability flags"); - }; - networkReachabilityCallBack(proxyReachability,flags,self); + [self setupNetworkReachabilityCallback: "linphone.org" withContext:nil]; - if (!SCNetworkReachabilitySetCallback(proxyReachability, (SCNetworkReachabilityCallBack)networkReachabilityCallBack,&proxyReachabilityContext)){ - ms_error("Cannot register reachability cb"); - }; - if(!SCNetworkReachabilityScheduleWithRunLoop(proxyReachability, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode)){ - ms_error("Cannot register schedule reachability cb"); - }; - [self reconfigureLinphoneIfNeeded:nil]; // start scheduler diff --git a/README b/README index 4f0900f9d..096cfdadb 100644 --- a/README +++ b/README @@ -36,19 +36,24 @@ BUILDING THE SDK * GPL third parties versus non GPL third parties -This sdk can be generated in 2 flavors. Firt is with GPL third parties, it means liblinphone includes GPL third parties like FFMPEG or x264. -If you choose this flavor, your final application must comply with GPL in any case. This is the default mode. + This sdk can be generated in 2 flavors. Firt is with GPL third parties, it means liblinphone includes GPL third parties like FFMPEG or x264. + If you choose this flavor, your final application must comply with GPL in any case. This is the default mode. -To generate the liblinphone multi arch sdk in GPL mode, do: + To generate the liblinphone multi arch sdk in GPL mode, do: $ cd submodules/build $ make all -ALTERNATIVELY, you can force liblinphone to use only non GPL code except for liblinphone, mediastremer2, ortp, exosip, osip. -If you choose this flavor, your final application is still subject to GPL except if you have a commercial license for liblinphone, mediastremer2, ortp, exosip, osip. + ALTERNATIVELY, you can force liblinphone to use only non GPL code except for liblinphone, mediastremer2, ortp, exosip, osip. + If you choose this flavor, your final application is still subject to GPL except if you have a commercial license for liblinphone, mediastremer2, ortp, exosip, osip. -To generate the liblinphone multi arch sdkin non GPL mode, do: + To generate the liblinphone multi arch sdkin non GPL mode, do: $ cd submodules/build $ make all enable_gpl_third_parties=no + + * ZRTP support + + You can enable ZRTP support in GPL mode only, by adding "enable_zrtp=yes" to the make command, for example: + $ make all enable_gpl_third_parties=yes enable_zrtp=yes The resulting sdk is in liblinphone-sdk/ directory. diff --git a/submodules/build/Makefile b/submodules/build/Makefile index 311aaa4fd..aa1fa2c70 100644 --- a/submodules/build/Makefile +++ b/submodules/build/Makefile @@ -20,6 +20,7 @@ # ############################################################################ enable_gpl_third_parties=yes +enable_zrtp=no .NOTPARALLEL all: build warning ifeq ($(enable_gpl_third_parties),yes) @@ -39,12 +40,18 @@ warning: @echo "*****linphone SDK without GPL code ******" @echo "*****************************************************************" @echo "*****************************************************************" + ifeq($(enable_zrtp),yes) + @echo "ZRTP is not available in non-gpl build." + enable_zrtp=no + endif endif +LINPHONE_OPTIONS="enable_gpl_third_parties=$(enable_gpl_third_parties) enable_zrtp=$(enable_zrtp)" + build: - make -f builder-iphone-os.mk all enable_gpl_third_parties=$(enable_gpl_third_parties) \ - && make -f builder-iphone-simulator.mk all enable_gpl_third_parties=$(enable_gpl_third_parties)\ - && make -f builder-iphone-os.mk host=armv7-apple-darwin all enable_gpl_third_parties=$(enable_gpl_third_parties)\ + make -f builder-iphone-os.mk all $(LINPHONE_OPTIONS) \ + && make -f builder-iphone-simulator.mk all $(LINPHONE_OPTIONS) \ + && make -f builder-iphone-os.mk host=armv7-apple-darwin all $(LINPHONE_OPTIONS) \ && make -f builder-iphone-os.mk delivery-sdk ipa: build diff --git a/submodules/build/builder-iphone-os.mk b/submodules/build/builder-iphone-os.mk index e89de143d..20797a9f4 100644 --- a/submodules/build/builder-iphone-os.mk +++ b/submodules/build/builder-iphone-os.mk @@ -38,6 +38,12 @@ linphone_configure_controls= \ --disable-tests \ --with-srtp=$(prefix) +ifeq ($(enable_zrtp),yes) + linphone_configure_controls+= --enable-zrtp +else + linphone_configure_controls+= --disable-zrtp +endif + #path BUILDER_SRC_DIR?=$(shell pwd)/../ BUILDER_BUILD_DIR?=$(shell pwd)/../build-$(host) @@ -60,11 +66,11 @@ $(LINPHONE_BUILD_DIR)/disable_gpl_third_parties: cd $(LINPHONE_BUILD_DIR) && rm -f Makefile && rm -f oRTP/Makefile && rm -f mediastreamer2/Makefile ifeq ($(enable_gpl_third_parties),yes) -linphone_configure_controls+= --enable-ffmpeg --enable-zrtp +linphone_configure_controls+= --enable-ffmpeg detect_gpl_mode_switch: $(LINPHONE_BUILD_DIR)/enable_gpl_third_parties else -linphone_configure_controls+= --disable-ffmpeg --disable-zrtp +linphone_configure_controls+= --disable-ffmpeg detect_gpl_mode_switch: $(LINPHONE_BUILD_DIR)/disable_gpl_third_parties endif