From a5c285d7fd046c862ef2ba11cd8bef71786db939 Mon Sep 17 00:00:00 2001 From: Liong Sauw Ming Date: Fri, 27 Aug 2010 06:46:29 +0000 Subject: 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 --- pjsip-apps/src/ipjsua/Classes/ipjsuaAppDelegate.m | 76 ++++++++++++++++++++-- pjsip-apps/src/ipjsua/ipjsua-Info.plist | 5 ++ .../src/ipjsua/ipjsua.xcodeproj/project.pbxproj | 10 ++- pjsip-apps/src/ipjsystest/ipjsystest-Info.plist | 4 ++ .../ipjsystest.xcodeproj/project.pbxproj | 4 +- pjsip-apps/src/pjsua/gui.h | 1 + pjsip-apps/src/pjsua/pjsua_app.c | 28 +++++++- 7 files changed, 114 insertions(+), 14 deletions(-) (limited to 'pjsip-apps') 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 +#import #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 @@ MainWindow UIInterfaceOrientation UIInterfaceOrientationLandscapeRight + UIBackgroundModes + + audio + voip + 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 = ""; }; 28AD73870D9D96C1002E5188 /* MainWindow.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = MainWindow.xib; sourceTree = ""; }; 29B97316FDCFA39411CA2CEA /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 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 = ""; @@ -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; }; diff --git a/pjsip-apps/src/ipjsystest/ipjsystest-Info.plist b/pjsip-apps/src/ipjsystest/ipjsystest-Info.plist index f718cf68..e15a90b4 100644 --- a/pjsip-apps/src/ipjsystest/ipjsystest-Info.plist +++ b/pjsip-apps/src/ipjsystest/ipjsystest-Info.plist @@ -26,5 +26,9 @@ NSMainNibFile MainWindow + UIBackgroundModes + + audio + diff --git a/pjsip-apps/src/ipjsystest/ipjsystest.xcodeproj/project.pbxproj b/pjsip-apps/src/ipjsystest/ipjsystest.xcodeproj/project.pbxproj index 510d11af..7fb2ff1f 100755 --- a/pjsip-apps/src/ipjsystest/ipjsystest.xcodeproj/project.pbxproj +++ b/pjsip-apps/src/ipjsystest/ipjsystest.xcodeproj/project.pbxproj @@ -366,7 +366,7 @@ ../../../third_party/lib, ); PREBINDING = NO; - SDKROOT = iphoneos3.1.2; + SDKROOT = iphoneos4.0; }; name = Debug; }; @@ -394,7 +394,7 @@ ../../../third_party/lib, ); PREBINDING = NO; - SDKROOT = iphoneos3.1.2; + SDKROOT = iphoneos4.0; }; name = Release; }; diff --git a/pjsip-apps/src/pjsua/gui.h b/pjsip-apps/src/pjsua/gui.h index 6a321bf2..8e622253 100644 --- a/pjsip-apps/src/pjsua/gui.h +++ b/pjsip-apps/src/pjsua/gui.h @@ -29,6 +29,7 @@ PJ_BEGIN_DECL void showMsg(const char *format, ...); char * getInput(char *s, int n, FILE *stream); +pj_bool_t showNotification(pjsua_call_id call_id); #endif diff --git a/pjsip-apps/src/pjsua/pjsua_app.c b/pjsip-apps/src/pjsua/pjsua_app.c index f51a30cd..9da513d7 100644 --- a/pjsip-apps/src/pjsua/pjsua_app.c +++ b/pjsip-apps/src/pjsua/pjsua_app.c @@ -158,6 +158,23 @@ pj_log_func *log_cb = NULL; * Configuration manipulation */ +#if (defined(PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT) && \ + PJ_IPHONE_OS_HAS_MULTITASKING_SUPPORT!=0) || \ + defined(__IPHONE_4_0) +void keepAliveFunction(int timeout) +{ + int i; + for (i=0; i<(int)pjsua_acc_get_count(); ++i) { + if (!pjsua_acc_is_valid(i)) + continue; + + if (app_config.acc_cfg[i].reg_timeout < timeout) + app_config.acc_cfg[i].reg_timeout = timeout; + pjsua_acc_set_registration(i, PJ_TRUE); + } +} +#endif + /* Show usage */ static void usage(void) { @@ -2456,12 +2473,17 @@ static void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsua_call_get_info(call_id, &call_info); - /* Start ringback */ - ring_start(call_id); - if (current_call==PJSUA_INVALID_ID) current_call = call_id; +#ifdef USE_GUI + if (!showNotification(call_id)) + return; +#endif + + /* Start ringback */ + ring_start(call_id); + if (app_config.auto_answer > 0) { pjsua_call_answer(call_id, app_config.auto_answer, NULL, NULL); } -- cgit v1.2.3