网络电话pjsip Getting Started: Building for Apple iPhone, iPad and iPod Touch

技术支持留言:Http://www.lcpower.cn

Getting Started: Building for Apple iPhone, iPad and iPod Touch



  1. Features
  2. Requirements
  3. Build Preparation
  4. Building PJSIP
  5. Simulator
  6. OpenSSL Suport
  7. Common problems
    1. Unable to accept incoming call in background mode (iOS4)
    2. Audio session management issue (iOS7)
    3. Audio issue (no audio) (iOS7)
    4. Supporting multiple architectures (armv6, armv7, armv7s, and so on)
    5. Unable to support Bluetooth input
    6. Problem with interruption (by a phone call or an alarm), headset plug/unplug, or Bluetooth input
    7. Sound not working in the simulator
    8. List of Issues
  8. Other iPhone Projects


Apple iOS target is supported by PJSIP version 1.7 and later.

Features

Some of the features of the iPhone port:

  • it has a native CoreAudio based audio device, which supports the following features:
    • the built-in/device's echo canceller
    • output volume setting
    • change input route to bluetooth input
    • change output route
    • input latency setting
    • output latency setting
  • supports for the built-in iLBC codec
  • Note: video (from 2.x) is not yet supported on iOS.

Requirements

  • iOS SDK, part of Xcode. Apple iPad is supported starting with iPhone SDK 3.2 onwards.

Build Preparation

  1. Get the source code, if you haven't already.
  2. Set your config_site.h to the following: #define PJ_CONFIG_IPHONE 1
  3. #include <pj/config_site_sample.h>

  4. This will activate iPhone specific settings in the config_site_sample.h.

Building PJSIP

Just run:

$ cd /path/to/your/pjsip/dir

$ ./configure-iphone

$ make dep && make clean && make

For iPhone 5, use armv7s architecture:

$ cd /path/to/your/pjsip/dir

$ ARCH='-arch armv7s' ./configure-iphone

$ make dep && make clean && make

Open ipjsua.xcodeproj using Xcode in pjproject/pjsip-apps/src/pjsua/ios and build the project. You will see telnet instructions on the device's screen. Telnet to this address to operate the application. SeePJSUA CLI Manual for commands available. (For release 2.1 and below, ipjsua is located inpjproject/pjsip-apps/src/ipjsua and does not have CLI telnet feature).

Notes:

  • the ./configure-iphone is a wrapper that calls the standard./configure script with settings suitable for iPhone target.
  • the latest iPhone SDK version will be selected by default. You may change this by settingIPHONESDK environment variable to the desired SDK path. For ipjsua, select Project-Edit Project Settings-Base SDK and Targets-ipjsua-Get Info-Base SDK to change the SDK version.
  • you may pass standard ./configure options to this script too.
  • for more info, run ./configure-iphone --help
  • other customizations are similar to what is explained in Building with GNU page.

Simulator

To configure the build system for the iPhone simulator:

export DEVPATH=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer

ARCH="-arch i386" CFLAGS="-O2 -m32 -miphoneos-version-min=4.0" LDFLAGS="-O2 -m32 -miphoneos-version-min=4.0" ./configure-iphone

make dep && make clean && make

Note that the exact paths may vary according to your SDK version.

OpenSSL Suport

Follow the instructions below to enable TLS transport by using OpenSSL:

  1. Build and install OpenSSL-1.0.0 for iPhone by following these instructions or OpenSSL-0.9.8o with these instructions.
  2. Specify OpenSSL location when running configure-iphone, for example (with Bash):export OPENSSL=${HOME}/openssl/openssl_arm
  3. export CFLAGS="-O2 -Wno-unused-label -I${OPENSSL}/include"
  4. export LDFLAGS="-L${OPENSSL}/lib"
  5. ./configure-iphone

  6. And check that OpenSSL is detected by the configure script: ...
  7. checking for OpenSSL installations..
  8. checking openssl/ssl.h usability... yes
  9. checking openssl/ssl.h presence... no
  10. aconfigure: WARNING: openssl/ssl.h: accepted by the compiler, rejected by the preprocessor!
  11. aconfigure: WARNING: openssl/ssl.h: proceeding with the compiler's result
  12. checking for openssl/ssl.h... yes
  13. checking for ERR_load_BIO_strings in -lcrypto... yes
  14. checking for SSL_library_init in -lssl... yes
  15. OpenSSL library found, SSL support enabled
  16. ...
  17. Build the libraries: make dep && make
  18. In XCode project setting of your application (for example, ipjsua), addlibssl.a and libcrypto.a from OpenSSL ARM directory to the project's Libraries:
    1. In Group & Files pane, expand ipjsua, then right clickLibraries, and select Add -> Existing Files....
    2. Find libssl.a and libcrypto.a from OpenSSL ARM directory (for example,${HOME}/openssl/openssl_arm) and add them to the project.
  19. Build the app

Common problems

Unable to accept incoming call in background mode (iOS4)

If while in the background, ipjsua (or your application) is unable to detect if there is an incoming call and display the local notification:

  1. Note that background feature only works with TCP.
  2. Make sure that voip is included in the required background modes (UIBackgroundModes) in the application’s Info.plist file.
  3. Make sure that the TCP socket is successfully wrapped with CFReadStreamRef (check if there is a message: "Failed to configure TCP transport for VoIP usage").
  4. Check whether you can accept the incoming call by bringing the app to the foreground. If yes, make sure that the incoming call request comes from the wrapped TCP socket (check the log for the INVITE request).

Note: these steps do not troubleshoot audio problems.

Audio session management issue (iOS7)

Since the deprecation of C-interface Audio Session API in iOS 7 SDK, PJSIP now uses AVAudioSession to set audio session category (toPlayAndRecord?) and activate/deactivate audio session. Application will need to do its own audio session management to handle input/output route and notifications (interruption, media server reset, etc). Please refer toApple's official doc on Audio Session Programming Guide and our ticket#1697.

Audio issue (no audio) (iOS7)

There are a few reports that the audio is not working on iOS 7 (so far it's only reported to happen in iPhone 5) after getting the following error:

iPhone mediaserverd[45] <Error>: 10:53:59.986 ERROR:     [0x240b000] 740: _vp: initialize hw input: fs mismatched! REF=0.000000Hz, MIC=44100.000000Hz

iPhone mediaserverd[45] <Error>: Resampler2 bad sample rate(s) :        0.00    16000.00

One solution is to set the sound device's clock rate to 44100 Hz as to avoid resampling.

Supporting multiple architectures (armv6, armv7, armv7s, and so on)

You need to compile separately for each architecture. If your iPhone SDK hasllvm-gcc compiler (which is the supported compiler starting iOS SDK 5) orclang, then you need to set ARCH environment variable to the desired architecture before runningconfigure-iphone, for example:

export ARCH = "-arch armv6"

Then you need to combine the resulting libraries using the lipo command. For example:

lipo -arch armv6 lib/armv6/libpjlib.a -arch armv7 lib/armv7/libpjlib.a -create -output lib/libpjlib.a

Unable to support Bluetooth input

Since Bluetooth input support is only available for iOS 3.1 or later, you need to specifically specify that your deployment target is iOS 3.1 or above. You can do this either inuser.mak:

export CFLAGS += -D__IPHONE_OS_VERSION_MIN_REQUIRED=30100

or in config_site.h:

#define __IPHONE_OS_VERSION_MIN_REQUIRED 30100

You need to recompile PJSIP after this.

Problem with interruption (by a phone call or an alarm), headset plug/unplug, or Bluetooth input

For devices running iOS 4.0 or later, you need to enable your application to respond to remote-control events. This allows PJSIP to properly receive and process the above events. You can do this by adding the following code in your application:

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

For more details, please refer to Apple's doc on Remote Control of Multimedia.

Sound not working in the simulator

Go to System Preferences > Sound > Sound Effects and then uncheck and recheck "Play user interface sound effects". If it still doesn't work, you can try some other suggestionshere.

List of Issues


#1113

iPhone: Echo cancellation may not work on iOS using SDK 4.x

#1115

iPhone: Long delay when calling AudioConverterNew() causing timeout in acquiring pjsua lock (thanks Bogdan Krakowski the report)

#1130

Incoming TCP connection on iPhone iOS4 BG mode would fail over and over with EAGAIN error (thanks Bogdan Krakowski for the report)

#1172

Crash in coreaudio_dev (iPhone OS) when there is no call during a GSM interruption

#1174

Fix crash in coreaudio_dev's interruptionListener (iPhone OS) and support for multiple interrupted streams (thanks to Seth Hinze for the patch)

#1194

iPhone: Fix problems with echo cancellation and Bluetooth input (SDK 4.x)

#1225

iPhone: UDP socket send error after waking up from background mode (thanks Joe Meade for the report)

#1226

iPhone (info only): No audio in calls if app is woken up from background mode without network connectivity (thanks Joe Meade for the report)

#1228

Long delay in iPhone initialization (thanks Guy Zelkha for the report)

#1231

Crash in iPhone iOS when trying to make a call after the application is left running for days (thanks Alejandro Orellana for the report)

#1245

Assertion may be raised if iPhone app woken up to perform registration and the server is down (thanks Alejandro Orellana for the report)

#1246

Use CFHost API for pj_getaddrinfo() on iPhone OS

#1324

Build correctness on non-video platforms (Symbian, iPhone, Windows Mobile)

#1335

Fixes assertion when interruptionListener is called from an unregistered thread on iPhone OS (thanks to Ilya Kalinin for the patch)

#1342

Disable local host resolution on iPhone OS

#1597

Handle socket failure in STUN resolution when coming back from iPhone/iOS background mode


Other iPhone Projects

Also have a look at these PJSIP iPhone ports by pjsip users:

Attachments

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
pjsip是一个开源的SIP协议栈,可以用于实现基于SIP协议的电话呼叫。以下是一个简单的pjsip电话呼叫的示例代码: ```c #include <pjsua-lib/pjsua.h> int main() { pj_status_t status; pj_caching_pool cp; pj_pool_t *pool; pjsua_config cfg; pjsua_logging_config log_cfg; pjmedia_transport_config media_cfg; pjmedia_transport *media_transport; pjsua_acc_id acc_id; pjsua_call_id call_id; pj_str_t uri = pj_str("sip:[email protected]"); // Initialize pjsua status = pj_init(); pj_caching_pool_init(&cp, NULL, 0); pool = pj_pool_create(&cp.factory, "pjsua", 4000, 4000, NULL); pjsua_config_default(&cfg); cfg.cb.on_incoming_call = NULL; cfg.cb.on_call_media_state = NULL; cfg.cb.on_call_state = NULL; cfg.cb.on_reg_state = NULL; pjsua_logging_config_default(&log_cfg); log_cfg.console_level = 4; log_cfg.level = 4; status = pjsua_init(&cfg, &log_cfg, NULL); pjsua_transport_config cfg_transport; pjsua_transport_config_default(&cfg_transport); cfg_transport.port = 5060; status = pjsua_transport_create(PJSIP_TRANSPORT_UDP, &cfg_transport, NULL); pjsua_start(); // Register with SIP server pjsua_acc_config acc_cfg; pjsua_acc_config_default(&acc_cfg); acc_cfg.id = pj_str("sip:[email protected]"); acc_cfg.reg_uri = pj_str("sip:domain.com"); acc_cfg.cred_count = 1; acc_cfg.cred_info[0].realm = pj_str("domain.com"); acc_cfg.cred_info[0].scheme = pj_str("digest"); acc_cfg.cred_info[0].username = pj_str("username"); acc_cfg.cred_info[0].data_type = PJSIP_CRED_DATA_PLAIN_PASSWD; acc_cfg.cred_info[0].data = pj_str("password"); status = pjsua_acc_add(&acc_cfg, PJ_TRUE, &acc_id); // Make outgoing call pjsua_call_setting call_setting; pjsua_call_setting_default(&call_setting); status = pjsua_call_make_call(acc_id, &uri, &call_setting, NULL, NULL, &call_id); // Destroy pjsua pjsua_destroy(); pj_pool_release(pool); pj_caching_pool_destroy(&cp); return 0; } ``` 这段代码首先初始化了pjsua,然后注册到SIP服务器,最后发起一个呼叫。具体的调用过程可以参考pjsip官方文档。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值