diff options
author | Liong Sauw Ming <ming@teluu.com> | 2010-08-27 06:46:29 +0000 |
---|---|---|
committer | Liong Sauw Ming <ming@teluu.com> | 2010-08-27 06:46:29 +0000 |
commit | a5c285d7fd046c862ef2ba11cd8bef71786db939 (patch) | |
tree | 13247c6735d6bb8f6a4b6d5253b39dd8a4b0e6a3 /pjsip-apps/src/ipjsua | |
parent | 41b2998504157f24d6b991d372e77addbed55030 (diff) |
Closed ticket #1107: iOS4 background feature
* pjlib:
* add support for activesock TCP to work in background mode.
* add feature in ioqueue to recreate closed UDP sockets.
* pjsip-apps:
* ipjsua: add support for iPhone OS 4 background mode
* ipjsystest: add support for iPhone OS 4 background mode
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@3299 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip-apps/src/ipjsua')
-rw-r--r-- | pjsip-apps/src/ipjsua/Classes/ipjsuaAppDelegate.m | 76 | ||||
-rw-r--r-- | pjsip-apps/src/ipjsua/ipjsua-Info.plist | 5 | ||||
-rw-r--r-- | pjsip-apps/src/ipjsua/ipjsua.xcodeproj/project.pbxproj | 10 |
3 files changed, 82 insertions, 9 deletions
diff --git a/pjsip-apps/src/ipjsua/Classes/ipjsuaAppDelegate.m b/pjsip-apps/src/ipjsua/Classes/ipjsuaAppDelegate.m index 8a1b2f1a..6edb33d9 100644 --- a/pjsip-apps/src/ipjsua/Classes/ipjsuaAppDelegate.m +++ b/pjsip-apps/src/ipjsua/Classes/ipjsuaAppDelegate.m @@ -7,6 +7,7 @@ // #import <pjlib.h> +#import <pjsua.h> #import "ipjsuaAppDelegate.h" extern pj_log_func *log_cb; @@ -18,14 +19,15 @@ extern pj_log_func *log_cb; @synthesize cfgView; /* Sleep interval duration */ -#define SLEEP_INTERVAL 0.5 +#define SLEEP_INTERVAL 0.5 /* Determine whether we should print the messages in the debugger * console as well */ -#define DEBUGGER_PRINT 1 +#define DEBUGGER_PRINT 1 /* Whether we should show pj log messages in the text area */ -#define SHOW_LOG 1 -#define PATH_LENGTH PJ_MAXPATH +#define SHOW_LOG 1 +#define PATH_LENGTH PJ_MAXPATH +#define KEEP_ALIVE_INTERVAL 600 extern pj_bool_t app_restart; @@ -34,13 +36,17 @@ char *argv[] = {"", "--config-file", argv_buf}; ipjsuaAppDelegate *app; -bool app_running; -bool thread_quit; +bool app_running; +bool thread_quit; NSMutableString *mstr; +pj_thread_desc a_thread_desc; +pj_thread_t *a_thread; +pjsua_call_id ccall_id; pj_status_t app_init(int argc, char *argv[]); pj_status_t app_main(void); pj_status_t app_destroy(void); +void keepAliveFunction(int timeout); void showMsg(const char *format, ...) { @@ -50,7 +56,7 @@ void showMsg(const char *format, ...) va_start(arg, format); NSString *str = [[NSString alloc] initWithFormat:[NSString stringWithFormat:@"%s", format] arguments: arg]; #if DEBUGGER_PRINT - NSLog(str); + NSLog(@"%@", str); #endif va_end(arg); @@ -92,6 +98,62 @@ void showLog(int level, const char *data, int len) showMsg("%s", data); } +pj_bool_t showNotification(pjsua_call_id call_id) +{ +#ifdef __IPHONE_4_0 + ccall_id = call_id; + + // Create a new notification + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + UILocalNotification* alert = [[[UILocalNotification alloc] init] autorelease]; + if (alert) + { + alert.repeatInterval = 0; + alert.alertBody = @"Incoming call received..."; + alert.alertAction = @"Answer"; + + [[UIApplication sharedApplication] presentLocalNotificationNow:alert]; + } + + [pool release]; + + return PJ_FALSE; +#else + return PJ_TRUE; +#endif +} + +- (void)answer_call { + if (!pj_thread_is_registered()) + { + pj_thread_register("ipjsua", a_thread_desc, &a_thread); + } + pjsua_call_answer(ccall_id, 200, NULL, NULL); +} + +#ifdef __IPHONE_4_0 +- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification { + [app performSelectorOnMainThread:@selector(answer_call) withObject:nil waitUntilDone:YES]; +} + +- (void)keepAlive { + if (!pj_thread_is_registered()) + { + pj_thread_register("ipjsua", a_thread_desc, &a_thread); + } + keepAliveFunction(KEEP_ALIVE_INTERVAL); +} + +- (void)applicationDidEnterBackground:(UIApplication *)application +{ + [app performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES]; + [application setKeepAliveTimeout:KEEP_ALIVE_INTERVAL handler: ^{ + [app performSelectorOnMainThread:@selector(keepAlive) withObject:nil waitUntilDone:YES]; + }]; +} + +#endif + - (void)start_app { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; /* Wait until the view is ready */ diff --git a/pjsip-apps/src/ipjsua/ipjsua-Info.plist b/pjsip-apps/src/ipjsua/ipjsua-Info.plist index 5cc34c72..e552e111 100644 --- a/pjsip-apps/src/ipjsua/ipjsua-Info.plist +++ b/pjsip-apps/src/ipjsua/ipjsua-Info.plist @@ -28,5 +28,10 @@ <string>MainWindow</string> <key>UIInterfaceOrientation</key> <string>UIInterfaceOrientationLandscapeRight</string> + <key>UIBackgroundModes</key> + <array> + <string>audio</string> + <string>voip</string> + </array> </dict> </plist> diff --git a/pjsip-apps/src/ipjsua/ipjsua.xcodeproj/project.pbxproj b/pjsip-apps/src/ipjsua/ipjsua.xcodeproj/project.pbxproj index 3ed07534..727d0c24 100644 --- a/pjsip-apps/src/ipjsua/ipjsua.xcodeproj/project.pbxproj +++ b/pjsip-apps/src/ipjsua/ipjsua.xcodeproj/project.pbxproj @@ -15,6 +15,7 @@ 282CCBFE0DB6C98000C4EA27 /* SecondView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 282CCBFD0DB6C98000C4EA27 /* SecondView.xib */; }; 288765080DF74369002DB57D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 288765070DF74369002DB57D /* CoreGraphics.framework */; }; 28AD73880D9D96C1002E5188 /* MainWindow.xib in Resources */ = {isa = PBXBuildFile; fileRef = 28AD73870D9D96C1002E5188 /* MainWindow.xib */; }; + 3A0D789F121E324E009D5030 /* CFNetwork.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3A0D789E121E324E009D5030 /* CFNetwork.framework */; }; 3AE9099D11587BB900FAEAA5 /* AudioToolbox.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AE9099C11587BB900FAEAA5 /* AudioToolbox.framework */; }; 3AE90A2D1158B52500FAEAA5 /* pjsua_app.c in Sources */ = {isa = PBXBuildFile; fileRef = 3AE90A2C1158B52500FAEAA5 /* pjsua_app.c */; }; 3AE90A6A1158C6B400FAEAA5 /* libgsmcodec-arm-apple-darwin9.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3AE90A691158C6B400FAEAA5 /* libgsmcodec-arm-apple-darwin9.a */; }; @@ -53,6 +54,7 @@ 28A0AB4B0D9B1048005BE974 /* ipjsua_Prefix.pch */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ipjsua_Prefix.pch; sourceTree = "<group>"; }; 28AD73870D9D96C1002E5188 /* MainWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainWindow.xib; sourceTree = "<group>"; }; 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; }; + 3A0D789E121E324E009D5030 /* CFNetwork.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CFNetwork.framework; path = System/Library/Frameworks/CFNetwork.framework; sourceTree = SDKROOT; }; 3AE9099C11587BB900FAEAA5 /* AudioToolbox.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AudioToolbox.framework; path = System/Library/Frameworks/AudioToolbox.framework; sourceTree = SDKROOT; }; 3AE90A2C1158B52500FAEAA5 /* pjsua_app.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = pjsua_app.c; path = ../pjsua/pjsua_app.c; sourceTree = SOURCE_ROOT; }; 3AE90A691158C6B400FAEAA5 /* libgsmcodec-arm-apple-darwin9.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = "libgsmcodec-arm-apple-darwin9.a"; path = "../../../third_party/lib/libgsmcodec-arm-apple-darwin9.a"; sourceTree = SOURCE_ROOT; }; @@ -109,6 +111,7 @@ 3AE90EBA115F7BCE00FAEAA5 /* libpjsdp-arm-apple-darwin9.a in Frameworks */, 3AE90EBB115F7BCE00FAEAA5 /* libspeex-arm-apple-darwin9.a in Frameworks */, 3AE90EBC115F7BCE00FAEAA5 /* libsrtp-arm-apple-darwin9.a in Frameworks */, + 3A0D789F121E324E009D5030 /* CFNetwork.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -180,6 +183,7 @@ 1D30AB110D05D00D00671497 /* Foundation.framework */, 288765070DF74369002DB57D /* CoreGraphics.framework */, 3AE9099C11587BB900FAEAA5 /* AudioToolbox.framework */, + 3A0D789E121E324E009D5030 /* CFNetwork.framework */, ); name = Frameworks; sourceTree = "<group>"; @@ -347,8 +351,9 @@ ../../../pjsip/lib, ../../../third_party/lib, ); + OTHER_CFLAGS = ""; PREBINDING = NO; - SDKROOT = iphoneos3.1.2; + SDKROOT = iphoneos4.0; }; name = Debug; }; @@ -376,8 +381,9 @@ ../../../pjsip/lib, ../../../third_party/lib, ); + OTHER_CFLAGS = ""; PREBINDING = NO; - SDKROOT = iphoneos3.1.2; + SDKROOT = iphoneos4.0; }; name = Release; }; |