From a6eca26cda56244612083511c4db48cbd24a19f0 Mon Sep 17 00:00:00 2001 From: Jehan Monnier Date: Wed, 24 Nov 2010 10:16:52 +0100 Subject: [PATCH] better handle non background mode --- Classes/linphoneAppDelegate.h | 1 + Classes/linphoneAppDelegate.m | 158 +++++++++--------- linphone.xcodeproj/project.pbxproj | 51 ++++-- .../liblinphone.xcodeproj/project.pbxproj | 13 +- submodules/linphone | 2 +- 5 files changed, 136 insertions(+), 89 deletions(-) diff --git a/Classes/linphoneAppDelegate.h b/Classes/linphoneAppDelegate.h index bc41e5c2c..540d4a2f0 100644 --- a/Classes/linphoneAppDelegate.h +++ b/Classes/linphoneAppDelegate.h @@ -54,6 +54,7 @@ SCNetworkReachabilityContext proxyReachabilityContext; SCNetworkReachabilityRef proxyReachability; CFReadStreamRef mReadStream; + NSTimer* mIterateTimer; } diff --git a/Classes/linphoneAppDelegate.m b/Classes/linphoneAppDelegate.m index c7f248967..7d1bf1993 100644 --- a/Classes/linphoneAppDelegate.m +++ b/Classes/linphoneAppDelegate.m @@ -122,7 +122,7 @@ LinphoneCoreVTable linphonec_vtable = { - (void)applicationDidEnterBackground:(UIApplication *)application { -//#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000 + //#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000 struct addrinfo hints; struct addrinfo *res=NULL; @@ -133,85 +133,79 @@ LinphoneCoreVTable linphonec_vtable = { int sipsock = linphone_core_get_sip_socket(myLinphoneCore); linphone_core_get_default_proxy(myLinphoneCore, &proxyCfg); - if (backgroundSupported && proxyCfg) { + if (isbackgroundModeEnabled && proxyCfg) { + //register + linphone_core_set_network_reachable(myLinphoneCore,false); + linphone_core_iterate(myLinphoneCore); + linphone_core_set_network_reachable(myLinphoneCore,true); - - if (isbackgroundModeEnabled) { - //register - linphone_core_set_network_reachable(myLinphoneCore,false); + int i=0; + while (!linphone_proxy_config_is_registered(proxyCfg) && i++<40 ) { linphone_core_iterate(myLinphoneCore); - linphone_core_set_network_reachable(myLinphoneCore,true); + usleep(100000); + } + if ([[UIApplication sharedApplication] setKeepAliveTimeout:600/*(NSTimeInterval)linphone_proxy_config_get_expires(proxyCfg)*/ + handler:^{ + ms_warning("keepalive handler"); + //kick up network cnx, just in case + linphone_core_set_network_reachable(myLinphoneCore,false); + linphone_core_iterate(myLinphoneCore); + [self kickOffNetworkConnection]; + linphone_core_set_network_reachable(myLinphoneCore,true); + linphone_core_iterate(myLinphoneCore); + } + ]) { - int i=0; - while (!linphone_proxy_config_is_registered(proxyCfg) && i++<40 ) { - linphone_core_iterate(myLinphoneCore); - usleep(100000); + + ms_warning("keepalive handler succesfully registered"); + } else { + ms_warning("keepalive handler cannot be registered"); + } + LCSipTransports transportValue; + if (linphone_core_get_sip_transports(myLinphoneCore, &transportValue)) { + ms_error("cannot get current transport"); + } + + if (mReadStream == nil && transportValue.udp_port>0) { //only for udp + const char *port; + addr=linphone_address_new(linphone_proxy_config_get_addr(proxyCfg)); + memset(&hints,0,sizeof(hints)); + hints.ai_family=linphone_core_ipv6_enabled(myLinphoneCore) ? AF_INET6 : AF_INET; + port=linphone_address_get_port(addr); + if (port==NULL) port="5060"; + err=getaddrinfo(linphone_address_get_domain(addr),port,&hints,&res); + if (err!=0){ + ms_error("getaddrinfo() failed for %s: %s",linphone_address_get_domain(addr),gai_strerror(err)); + linphone_address_destroy(addr); + return; } - if ([[UIApplication sharedApplication] setKeepAliveTimeout:600/*(NSTimeInterval)linphone_proxy_config_get_expires(proxyCfg)*/ - handler:^{ - ms_warning("keepalive handler"); - //kick up network cnx, just in case - linphone_core_set_network_reachable(myLinphoneCore,false); - linphone_core_iterate(myLinphoneCore); - [self kickOffNetworkConnection]; - linphone_core_set_network_reachable(myLinphoneCore,true); - linphone_core_iterate(myLinphoneCore); - } - ]) { - - - ms_warning("keepalive handler succesfully registered"); - } else { - ms_warning("keepalive handler cannot be registered"); + err=connect(sipsock,res->ai_addr,res->ai_addrlen); + if (err==-1){ + ms_error("Connect failed: %s",strerror(errno)); } - LCSipTransports transportValue; - if (linphone_core_get_sip_transports(myLinphoneCore, &transportValue)) { - ms_error("cannot get current transport"); + freeaddrinfo(res); + + CFStreamCreatePairWithSocket(NULL, (CFSocketNativeHandle)sipsock, &mReadStream,nil); + + if (!CFReadStreamSetProperty(mReadStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP)) { + ms_error("cannot set service type to voip for read stream"); } - if (mReadStream == nil && transportValue.udp_port>0) { //only for udp - const char *port; - addr=linphone_address_new(linphone_proxy_config_get_addr(proxyCfg)); - memset(&hints,0,sizeof(hints)); - hints.ai_family=linphone_core_ipv6_enabled(myLinphoneCore) ? AF_INET6 : AF_INET; - port=linphone_address_get_port(addr); - if (port==NULL) port="5060"; - err=getaddrinfo(linphone_address_get_domain(addr),port,&hints,&res); - if (err!=0){ - ms_error("getaddrinfo() failed for %s: %s",linphone_address_get_domain(addr),gai_strerror(err)); - linphone_address_destroy(addr); - return; - } - err=connect(sipsock,res->ai_addr,res->ai_addrlen); - if (err==-1){ - ms_error("Connect failed: %s",strerror(errno)); - } - freeaddrinfo(res); - - CFStreamCreatePairWithSocket(NULL, (CFSocketNativeHandle)sipsock, &mReadStream,nil); - - if (!CFReadStreamSetProperty(mReadStream, kCFStreamNetworkServiceType, kCFStreamNetworkServiceTypeVoIP)) { - ms_error("cannot set service type to voip for read stream"); - } - - - if (!CFReadStreamOpen(mReadStream)) { - ms_error("cannot open read stream"); - } - } - } - else { - //only unregister - //register - linphone_proxy_config_edit(proxyCfg); //force unregister - linphone_core_iterate(myLinphoneCore); - ms_warning("Entering lite bg mode"); + + if (!CFReadStreamOpen(mReadStream)) { + ms_error("cannot open read stream"); + } } } - -//#endif - + else { + ms_warning("Entering lite bg mode"); + [self applicationWillTerminate:nil]; } + + + //#endif + +} - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ @@ -279,8 +273,9 @@ LinphoneCoreVTable linphonec_vtable = { } + -(void) kickOffNetworkConnection { - signal(SIGPIPE,SIG_IGN); + ms_message("waiking up network connection"); CFWriteStreamRef writeStream; CFStreamCreatePairWithSocketToHost(NULL, (CFStringRef)@"linphone.org", 15000, nil, &writeStream); CFWriteStreamOpen (writeStream); @@ -291,6 +286,14 @@ LinphoneCoreVTable linphonec_vtable = { } - (void)applicationDidBecomeActive:(UIApplication *)application { + if (myLinphoneCore == nil) { + //back from standby and background mode is disabled + [self startlibLinphone]; + + [myCallHistoryTableViewController setLinphoneCore: myLinphoneCore]; + + [myPhoneViewController setLinphoneCore: myLinphoneCore]; + } if (isStarted) { ms_message("becomming active, make sure we are registered"); [self doRegister]; @@ -316,7 +319,9 @@ LinphoneCoreVTable linphonec_vtable = { } - (void)applicationWillTerminate:(UIApplication *)application { + [mIterateTimer invalidate]; linphone_core_destroy(myLinphoneCore); + myLinphoneCore = nil; } - (void)dealloc { @@ -338,6 +343,7 @@ extern void libmsilbc_init(); NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *confiFileName = [[paths objectAtIndex:0] stringByAppendingString:@"/.linphonerc"]; ; + signal(SIGPIPE, SIG_IGN); //log management isDebug = [[NSUserDefaults standardUserDefaults] boolForKey:@"debugenable_preference"]; if (isDebug) { @@ -366,11 +372,11 @@ extern void libmsilbc_init(); // start scheduler - [NSTimer scheduledTimerWithTimeInterval:0.1 - target:self - selector:@selector(iterate) - userInfo:nil - repeats:YES]; + mIterateTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 + target:self + selector:@selector(iterate) + userInfo:nil + repeats:YES]; //init audio session AVAudioSession *audioSession = [AVAudioSession sharedInstance]; BOOL bAudioInputAvailable= [audioSession inputIsAvailable]; diff --git a/linphone.xcodeproj/project.pbxproj b/linphone.xcodeproj/project.pbxproj index c25c20f3e..3b8c619fe 100755 --- a/linphone.xcodeproj/project.pbxproj +++ b/linphone.xcodeproj/project.pbxproj @@ -49,7 +49,6 @@ 228697C411AC29B800E9E0CA /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 228697C311AC29B800E9E0CA /* CFNetwork.framework */; }; 22A10F3A11F8960300373793 /* libmediastreamer.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 220FAD2B10765B400068D98F /* libmediastreamer.a */; }; 22A10F3B11F8960300373793 /* libortp.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 220FAD2C10765B400068D98F /* libortp.a */; }; - 22A805C3124D021E005E4D90 /* liblinphone.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 220FAD2A10765B400068D98F /* liblinphone.a */; }; 22B5EFA310CE50BD00777D97 /* AddressBookUI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22B5EFA210CE50BD00777D97 /* AddressBookUI.framework */; }; 22B5EFE510CE5E5800777D97 /* ContactPickerDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 22B5EFE410CE5E5800777D97 /* ContactPickerDelegate.m */; }; 22B5F03510CE6B2F00777D97 /* AddressBook.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 22B5F03410CE6B2F00777D97 /* AddressBook.framework */; }; @@ -75,6 +74,18 @@ }; /* End PBXContainerItemProxy section */ +/* Begin PBXCopyFilesBuildPhase section */ + 2247673A129C3B9C002B94B4 /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 11; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ 1D30AB110D05D00D00671497 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 1D3623240D0F684500981E51 /* linphoneAppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = linphoneAppDelegate.h; sourceTree = ""; }; @@ -191,7 +202,6 @@ 220FACEB107654FC0068D98F /* speex_types.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = speex_types.h; sourceTree = ""; }; 220FAD2810765B400068D98F /* libeXosip2.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libeXosip2.a; path = "liblinphone-sdk/apple-darwin/lib/libeXosip2.a"; sourceTree = ""; }; 220FAD2910765B400068D98F /* libgsm.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libgsm.a; path = "liblinphone-sdk/apple-darwin/lib/libgsm.a"; sourceTree = ""; }; - 220FAD2A10765B400068D98F /* liblinphone.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = liblinphone.a; path = "liblinphone-sdk/apple-darwin/lib/liblinphone.a"; sourceTree = ""; }; 220FAD2B10765B400068D98F /* libmediastreamer.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libmediastreamer.a; path = "liblinphone-sdk/apple-darwin/lib/libmediastreamer.a"; sourceTree = ""; }; 220FAD2C10765B400068D98F /* libortp.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libortp.a; path = "liblinphone-sdk/apple-darwin/lib/libortp.a"; sourceTree = ""; }; 220FAD2D10765B400068D98F /* libosip2.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libosip2.a; path = "liblinphone-sdk/apple-darwin/lib/libosip2.a"; sourceTree = ""; }; @@ -281,7 +291,6 @@ 228697C411AC29B800E9E0CA /* CFNetwork.framework in Frameworks */, 22A10F3A11F8960300373793 /* libmediastreamer.a in Frameworks */, 22A10F3B11F8960300373793 /* libortp.a in Frameworks */, - 22A805C3124D021E005E4D90 /* liblinphone.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -524,7 +533,6 @@ 223148E31178A08200637D6A /* libilbc.a */, 220FAD2810765B400068D98F /* libeXosip2.a */, 220FAD2910765B400068D98F /* libgsm.a */, - 220FAD2A10765B400068D98F /* liblinphone.a */, 220FAD2B10765B400068D98F /* libmediastreamer.a */, 220FAD2C10765B400068D98F /* libortp.a */, 220FAD2D10765B400068D98F /* libosip2.a */, @@ -612,6 +620,7 @@ 1D60588D0D05DD3D006BFB54 /* Resources */, 1D60588E0D05DD3D006BFB54 /* Sources */, 1D60588F0D05DD3D006BFB54 /* Frameworks */, + 2247673A129C3B9C002B94B4 /* CopyFiles */, ); buildRules = ( ); @@ -629,7 +638,14 @@ isa = PBXProject; buildConfigurationList = C01FCF4E08A954540054247B /* Build configuration list for PBXProject "linphone" */; compatibilityVersion = "Xcode 3.1"; + developmentRegion = English; hasScannedForEncodings = 1; + knownRegions = ( + English, + Japanese, + French, + German, + ); mainGroup = 29B97314FDCFA39411CA2CEA /* CustomTemplate */; projectDirPath = ""; projectReferences = ( @@ -717,6 +733,7 @@ ALWAYS_SEARCH_USER_PATHS = NO; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; + FRAMEWORK_SEARCH_PATHS = ""; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PRECOMPILE_PREFIX_HEADER = YES; @@ -745,9 +762,13 @@ "\"$(SRCROOT)/submodules/build/$(CONFIGURATION)-iphonesimulator\"", "$(inherited)", ); + OTHER_LDFLAGS = ( + "-l", + linphone, + ); PRODUCT_NAME = linphone; "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; - SDKROOT = iphoneos4.0; + SDKROOT = iphoneos; STANDARD_C_PLUS_PLUS_LIBRARY_TYPE = dynamic; }; name = Debug; @@ -757,6 +778,7 @@ buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; COPY_PHASE_STRIP = YES; + FRAMEWORK_SEARCH_PATHS = ""; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = linphone_Prefix.pch; GCC_PREPROCESSOR_DEFINITIONS = IN_LINPHONE; @@ -783,8 +805,12 @@ "\"$(SRCROOT)/submodules/build/$(CONFIGURATION)-iphonesimulator\"", "$(inherited)", ); + OTHER_LDFLAGS = ( + "-l", + linphone, + ); PRODUCT_NAME = linphone; - SDKROOT = iphoneos4.0; + SDKROOT = iphoneos; }; name = Release; }; @@ -802,7 +828,7 @@ LINK_WITH_STANDARD_LIBRARIES = YES; PREBINDING = NO; "PROVISIONING_PROFILE[sdk=iphoneos*]" = "09801E17-63DB-47FD-A203-166EDD1E55A1"; - SDKROOT = iphoneos4.0; + SDKROOT = iphoneos; }; name = Distribution; }; @@ -813,6 +839,7 @@ CODE_SIGN_ENTITLEMENTS = untitled.plist; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; COPY_PHASE_STRIP = NO; + FRAMEWORK_SEARCH_PATHS = ""; GCC_DYNAMIC_NO_PIC = NO; GCC_OPTIMIZATION_LEVEL = 0; GCC_PRECOMPILE_PREFIX_HEADER = YES; @@ -841,9 +868,13 @@ "\"$(SRCROOT)/submodules/build/$(CONFIGURATION)-iphonesimulator\"", "$(inherited)", ); + OTHER_LDFLAGS = ( + "-l", + linphone, + ); PRODUCT_NAME = linphone; "PROVISIONING_PROFILE[sdk=iphoneos*]" = ""; - SDKROOT = iphoneos4.0; + SDKROOT = iphoneos; STANDARD_C_PLUS_PLUS_LIBRARY_TYPE = dynamic; }; name = Distribution; @@ -861,7 +892,7 @@ LIBRARY_SEARCH_PATHS = ""; LINK_WITH_STANDARD_LIBRARIES = YES; PREBINDING = NO; - SDKROOT = iphoneos4.0; + SDKROOT = iphoneos; }; name = Debug; }; @@ -875,7 +906,7 @@ GCC_WARN_UNUSED_VARIABLE = YES; IPHONEOS_DEPLOYMENT_TARGET = 3.1; PREBINDING = NO; - SDKROOT = iphoneos4.0; + SDKROOT = iphoneos; }; name = Release; }; diff --git a/submodules/liblinphone.xcodeproj/project.pbxproj b/submodules/liblinphone.xcodeproj/project.pbxproj index c12a69aee..fa8842be2 100644 --- a/submodules/liblinphone.xcodeproj/project.pbxproj +++ b/submodules/liblinphone.xcodeproj/project.pbxproj @@ -801,7 +801,14 @@ isa = PBXProject; buildConfigurationList = 1DEB922208733DC00010E9CD /* Build configuration list for PBXProject "liblinphone" */; compatibilityVersion = "Xcode 3.1"; + developmentRegion = English; hasScannedForEncodings = 1; + knownRegions = ( + English, + Japanese, + French, + German, + ); mainGroup = 0867D691FE84028FC02AAC07 /* liblinphone */; productRefGroup = 034768DFFF38A50411DB9C8B /* Products */; projectDirPath = ""; @@ -955,6 +962,7 @@ "POSIXTIMER_INTERVAL=10000", IN_LINPHONE, __MACIOUNIT_ENABLED__, + HAVE_EXOSIP_GET_SOCKET, ); GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; @@ -969,7 +977,7 @@ ); OTHER_LDFLAGS = "-ObjC"; PREBINDING = NO; - SDKROOT = iphoneos4.0; + SDKROOT = iphoneos; }; name = Debug; }; @@ -993,6 +1001,7 @@ "POSIXTIMER_INTERVAL=10000", IN_LINPHONE, __MACIOUNIT_ENABLED__, + HAVE_EXOSIP_GET_SOCKET, ); GCC_WARN_ABOUT_RETURN_TYPE = YES; GCC_WARN_UNUSED_VARIABLE = YES; @@ -1007,7 +1016,7 @@ ); OTHER_LDFLAGS = "-ObjC"; PREBINDING = NO; - SDKROOT = iphoneos4.0; + SDKROOT = iphoneos; }; name = Release; }; diff --git a/submodules/linphone b/submodules/linphone index b6535cd6d..3bf340a4b 160000 --- a/submodules/linphone +++ b/submodules/linphone @@ -1 +1 @@ -Subproject commit b6535cd6deb7d821c52ac31ea534cf5529ab8e5d +Subproject commit 3bf340a4b8f30d016ad3bff4737a9a3d3e954b1f