Pjsua 2 Doc
Pjsua 2 Doc
PJSUA2 Documentation
Release 1.0-alpha
http://slidepdf.com/reader/full/pjsua2doc 1/271
8/10/2019 PJSUA2Doc
http://slidepdf.com/reader/full/pjsua2doc 2/271
8/10/2019 PJSUA2Doc
CONTENTS
1 Introduction 3
1.1 Getting Started with PJSIP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2 PJSIP Info and Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
5 Accounts 41
5.1 Subclassing the Account class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
5.2 Creating Userless Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
5.3 Creating Account . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
5.4 Account Configurations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
5.5 Account Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
5.6 Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6 Media 69
6.1 The Audio Conference Bridge . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
6.2 Audio Device Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
6.3 Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
http://slidepdf.com/reader/full/pjsua2doc 3/271
8/10/2019 PJSUA2Doc
7 Calls 91
7.1 Subclassing the Call Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
7.2 Making Outgoing Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
7.3 Receiving Incoming Calls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
7.4 Call Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
7.5 Call Disconnection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
7.6 Working with Call’s Audio Media . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
7.7 Call Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
7.8 Instant Messaging(IM) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
7.9 Class Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
9 PJSUA2 Sample
9.1 Sample Applications
Apps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
129
9.2 Miscellaneous . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
ii
http://slidepdf.com/reader/full/pjsua2doc 4/271
8/10/2019 PJSUA2Doc
Contents:
CONTENTS 1
http://slidepdf.com/reader/full/pjsua2doc 5/271
8/10/2019 PJSUA2Doc
2 CONTENTS
http://slidepdf.com/reader/full/pjsua2doc 6/271
8/10/2019 PJSUA2Doc
CHAPTER
ONE
INTRODUCTION
This documentation is intended for developers looking to develop Session Initiation Protocol (SIP) based client appli-
cation. Some knowledge on SIP is definitely required, and of course some programming experience. Prior knowledge
of PJSUA C API is not needed, although it will probably help.
PJSIP libraries provide multi-level APIs to do SIP calls, presence, and instant messaging, as well as handling media
and NAT traversal. PJSUA2 API is the highest API from PJSIP, on top of PJSUA-LIB API. PJSUA-LIB API itself
is a library that unifies SIP, audio/video media, NAT traversal, and client media application best practices into a high
level, integrated, and easy to use API. The next chapter will guide you on selecting which API level to use depending
on your requirements.
This documentation can be viewed online, or alternatively you can download the PDF format for offline viewing.
Check PJSIP Datasheet to make sure that it has the features that you require.
To start using PJSIP, the Getting Started Guide contains instructions to acquire and build PJSIP on various platforms
that we support.
To get other relevant info and documentations about PJSIP, you can visit:
• PJSIP General Wiki is the home for all documentation
• PJSIP FAQ
• PJSIP Reference Manual - please see Reference Manual section
http://slidepdf.com/reader/full/pjsua2doc 7/271
8/10/2019 PJSUA2Doc
4 Chapter 1. Introduction
http://slidepdf.com/reader/full/pjsua2doc 8/271
8/10/2019 PJSUA2Doc
CHAPTER
TWO
2.1.1 Preparation
• Essential: Familiarise yourself with SIP. You don’t need to be an expert, but SIP knowledge is essential.
• Check out our features in Datasheet. Other features may be provided by our community.
• All PJSIP documentation is indexed in our Trac site.
2.1.2 Development
Essential: set your editor to use 8 characters tab size in order to see PJSIP source correctly.
Detailed below is the PJSIP coding style. You don’t need to follow it unless you are submitting patches to PJSIP:
• Indentation uses tabs and spaces. Tab size is 8 characters, indentation 4.
• All public API in header file must be documented in Doxygen format.
• Apart from that, we mostly just use K & R style, which is the only correct style anyway.
2.1.4 Deployment
• Essential: Logging is essential when troubleshooting any problems. The application MUST be equipped with
logging capability. Enable PJSIP log at level 5.
Platform selection is usually driven by business motives. The selection will affect all aspects of development, and here
we will cover considerations for each platforms that we support.
http://slidepdf.com/reader/full/pjsua2doc 9/271
8/10/2019 PJSUA2Doc
Windows is supported from Windows 2000 up to the recent Windows 8 and beyond. All features are expected to work.
64bit support was added recently. Development is based on Visual Studio. Considerations for this platform include:
1. Because Visual Studio file format keeps changing on every release, we decided to support the lowest denomina-
tor, namely Visual Studio 2005. Unfortunately the project upgrade procedure fails on Visual Studio 2010, and
we don’t have any solution for that. VS 2008 and VS 2012 onwards should work.
2.2.2 MacOS X
All features except video are expected to work (video is coming soon!). Considerations for iOS:
1. You need to use TCP transport for SIP for the background feature to work
2. IP change (for example when user is changing access point) is a feature frequently asked by developers and you
can find the documentation here: http://trac.pjsip.org/repos/wiki/IPAddressChange
3. There are some specific issues for iOS 7 and beyond, please see http://trac.pjsip.org/repos/ticket/1697
4. If SSL is needed, you need to compile OpenSSL for iOS
2.2.5 Android
All features except video are expected to work (video is coming soon!). Considerations for Android:
1. You can only use PJSUA2 Java binding for this target.
2. It has been reported that Android audio device is not so good in general, so some audio tuning may be needed.
Echo cancellation also needs to be checked.
3. This is also a new platform for us.
2.2.6 Symbian
Symbian has been supported for a long time. In general all features (excluding video) are expected to work, but we’re
not going to do Symbian specific development anymore. Other considerations for Symbian:
http://slidepdf.com/reader/full/pjsua2doc 10/271
8/10/2019 PJSUA2Doc
1. The MDA audio is not very good (it has high latency), so normally you’d want to use Audio Proxy Server
(APS) or VoIP Audio Service (VAS) for the audio device, which we support. Using these audio backends will
also provide us with high quality echo cancellation as well as low bitrate codecs such as AMR-NB, G.729, and
iLBC. But VAS and APS requires purchase of Nokia development certificate to sign the app, and also since APS
and VAS only run on specific device type, you need to package the app carefully and manage the deployment to
cover various device types.
2.2.7 BlackBerry 10
BlackBerry 10 (BB10) is supported since PJSIP version 2.2. As this is a relatively new platform for us, we are currently
listening to developer’s feedback regarding the port. But so far it seems to be working well. Some considerations for
BB10 platform include:
1. IP change (for example when user is changing access point) is a feature frequently asked by developers and you
can find the documentation here: http://trac.pjsip.org/repos/wiki/IPAddressChange
This is the old Windows Mobile platform that is based on WinCE. This platform has been supported for a long time.
We expect all features except video to work, but there may be some errors every now and then because this target is
not actively maintained. No new development will be done for this platform.
Other considerations for Windows Mobile platform are:
1. The quality of audio device on WM varies a lot, and this affects audio latency. Audio latency could go as high
as hundreds of millisecond on bad hardware.
2. Echo cancellation could be a problem. We can only use basic echo suppressor due to hardware limitation, and
combined with bad quality of audio device, it may cause ineffective echo cancellation. This could be mitigated
by setting the audio level to low.
In general embedded Linux support is similar to Linux and we find no problems with it. We found some specific
considerations for embedded Linux as follows:
1. The performance of the audio device is probably the one with most issues, as some development boards does
not have a decent sound device. Typically there is high audio jitter (or burst) and latency. This will affect end
to end audio latency and also the performance of the echo canceller. Also we found that ALSA generally works
better than OSS, so if you can have ALSA up and running that will be better. Use our native ALSA backend
audio device instead of PortAudio since it is simpler and lighter.
http://slidepdf.com/reader/full/pjsua2doc 11/271
8/10/2019 PJSUA2Doc
This is not part of our officially supported OS platforms, but users have run PJSIP on QNX and BlackBerry 10 is based
on QNX too. Since QNX provides Posix API, and maybe by using the settings found in the configure-bb10 script,
PJSIP should be able to run on it, but you need to develop PJMEDIA sound device wrapper for your audio device.
Other than this, we don’t have enough experience to comment on the platform.
Community members, including myself, have occasionally run PJSIP on other Unix OSes such as Solaris, FreeBSD,
and OpenBSD. We expect PJSIP to run on these platforms (maybe with a little kick).
It is possible to port PJSIP to other embedded OS or even directly to device without OS and people have done so. In
general, the closer resemblance the new OS to existing supported OS, the easier the porting job will be. The good
thing is, PJSIP has been made to be very very portable, and system dependent features are localized in PJLIB and
PJMEDIA audio device, so the effort is more quantifiable. Once you are able to successfully run pjlib-test , you are
more or less there with your porting effort. Other than that, if you really want to port PJSIP to new platform, you
probably already know what you’re doing.
At the lowest level we have the individual PJSIP C libraries, which consist of PJSIP, PJMEDIA, and PJNATH, with
PJLIB-UTIL and PJLIB as support libraries. This level provides the most flexibility, but it’s also the hardest to use.
The only reason you’d want to use this level is if:
1. You only need the individual library (say, PJNATH)
2. You need to be very very tight in footprint (say when things need to be measured in Kilobytes instead of
Megabytes)
3. You are not developing a SIP client
Use the corresponding PJSIP, PJMEDIA, PJNATH manuals from http://trac.pjsip.org/repos/ for information on how to
use the libraries. If you use PJSIP, the PJSIP Developer’s Guide (PDF) from that page provides in-depth information
about PJSIP library.
Next up is PJSUA-LIB API that combines all those libraries into a high level, integrated client user agent library
written in C. This is the library that most PJSIP users use, and the highest level abstraction before pjsua2 was created.
Motivations for using PJSUA-LIB library includes:
1. Developing client application (PJSUA-LIB is optimized for developing client app)
2. Better efficiency than higher level API
http://slidepdf.com/reader/full/pjsua2doc 12/271
8/10/2019 PJSUA2Doc
pjsua2 is a new, objected oriented, C++ API created on top of PJSUA-LIB. The API is different than PJSUA-LIB,
but it should be even easier to use and it should have better documentation too (such as this book). The pjsua2 API
removes most cruxes typically associated with PJSIP, such as the pool and pj_str_t, and add new features such as
object persistence so you can save your configs to a file, for example. All data structures are rewritten for more clarity.
A C++ application can use pjsua2 natively, while at the same time still has access to the lower level objects if it needs
to. This means that the C++ application should not lose any information from using the C++ abstraction, compared to
if it is using PJSUA-LIB directly. The C++ application also should not lose the ability to extend the library. It would
still be able to register a custom PJSIP module, pjmedia_port, pjmedia_transport, and so on.
Benefits of using pjsua2 C++ API include:
1. Cleaner object oriented API
2. Uniform API for higher level language such as Java and Python
3. Persistence API
4. The ability to access PJSUA-LIB and lower level libraries when needed (including the ability to extend the
libraries, for example creating custom PJSIP module, pjmedia_port, pjmedia_transport, etc.)
Some considerations on PJSUA2 C++ API are:
1. Instead of returning error, the API uses exception for error reporting
2. It uses standard C++ library (STL)
3. The performance penalty due to the API abstraction should be negligible on typical modern device
The PJSUA2 API is also available for non-native code via SWIG binding. Configurations for Java and Python are
provided with the distribution. Thanks to SWIG, other language bindings may be generated relatively easily.
The pjsua2
access API for and
PJSUA-LIB non-native code is C
the underlying effectively the same
libraries from as pjsua2
the scripting C++ API.
language, However,
hence you areunlike C++,
limited you cannot
to what pjsua2
provides.
You can use this API if native application development is not available in target platform (such as Android), or if you
prefer to develop with non-native code instead of C/C++.
TBD.
If you support iOS devices in your service, you need to use TCP, because only TCP will work on iOS device when it
is in background mode. This means your infrastructure needs to support TCP.
http://slidepdf.com/reader/full/pjsua2doc 13/271
8/10/2019 PJSUA2Doc
2.5.1 Latency
TBD.
TBD.
http://slidepdf.com/reader/full/pjsua2doc 14/271
8/10/2019 PJSUA2Doc
CHAPTER
THREE
PJSUA2 is an object-oriented abstraction above PJSUA API. It provides high level API for constructing Session
Initiation Protocol (SIP) multimedia user agent applications (a.k.a Voice over IP/VoIP softphones). It wraps together
the signaling, media, and NAT traversal functionality into easy to use call control API, account management, buddy
list management, presence, and instant messaging, along with multimedia features such as local conferencing, file
streaming, local playback, and voice recording, and powerful NAT traversal techniques utilizing STUN, TURN, and
ICE.
PJSUA2 is implemented on top of PJSUA-LIB API. The SIP and media features and object modelling follows what
PJSUA-LIB provides (for example, we still have accounts, call, buddy, and so on), but the API to access them is
different. These features will be described later in this chapter. PJSUA2 is a C++ library, which you can find under
pjsip directory in the PJSIP distribution. The C++ library can be used by native C++ applications directly. But
PJSUA2 is not just a C++ library. From the beginning, it has been designed to be accessible from high level non-
native languages such as Java and Python. This is achieved by SWIG binding. And thanks to SWIG, binding to other
languages can be added relatively easily in the future.
PJSUA2 API declaration can be found in pjsip/include/pjsua2 while the source codes are located in
pjsip/src/pjsua2. It will be automatically built when you compile PJSIP.
3.1.1 Endpoint
This is the main class of PJSUA2. You need to instantiate one and exactly one of this class, and from the instance you
can then initialize and start the library.
3.1.2 Account
An account specifies the identity of the person (or endpoint) on one side of SIP conversation. At least one account
instance needs to be created before anything else, and from the account instance you can start making/receiving calls
as well as adding buddies.
3.1.3 Media
This is an abstract base class that represents a media element which is capable to either produce media or
takes media. It is then subclassed into AudioMedia, which is then subclassed into concrete classes such as
AudioMediaPlayer and AudioMediaRecorder.
11
http://slidepdf.com/reader/full/pjsua2doc 15/271
8/10/2019 PJSUA2Doc
3.1.4 Call
This class represents an ongoing call (or speaking technically, an INVITE session) and can be used to manipulate it,
such as to answer the call, hangup the call, put the call on hold, transfer the call, etc.
3.1.5 Buddy
This class represents a remote buddy (a person, or a SIP endpoint). You can subscribe to presence status of a buddy to
know whether the buddy is online/offline/etc., and you can send and receive instant messages to/from the buddy.
With the methods of the main classes above, you will be able to invoke various operations to the object quite easily. But
how can we get events/notifications from these classes? Each of the main classes above (except Media) will get their
events in the callback methods. So to handle these events, just derive a class from the corresponding class (Endpoint,
Call, Account, or Buddy) and implement/override the relevant method (depending on which event you want to handle).
More will be explained in later sections.
We use exceptions as means to report error, as this would make the program flows more naturally. Operations which
yield error will raise Error exception. If you prefer to display the error in more structured manner, the Error class has
several members to explain the error, such as the operation name that raised the error, the error code, and the error
message itself.
3.2.4 Threading
For platforms that require polling, the PJSUA2 module provides its own worker thread to poll PJSIP, so it is not
necessary to instantiate own your polling thread. Having said that the application should be prepared to have the
callbacks called by different thread than the main thread. The PJSUA2 module itself is thread safe.
Often though, especially if you use PJSUA2 with high level languages such as Python, it is required to disable PJSUA2
internal worker threads by setting EpConfig.uaConfig.threadCnt to 0, because the high level environment doesn’t like
to be called by external thread (such as PJSIP’s worker thread).
http://slidepdf.com/reader/full/pjsua2doc 16/271
8/10/2019 PJSUA2Doc
Garbage collection (GC) exists in Java and Python (and other languages, but we don’t support those for now), and
there are some problems with it when it comes to PJSUA2 usage:
• it delays the destruction of objects (including PJSUA2 objects), causing the code in object’s destructor to be
executed out of order
• the GC operation may run on different thread not previously registered to PJLIB, causing assertion
Due to problems above, application ‘’‘MUST immediately destroy PJSUA2 objects using object’s delete() method (in
Java)’‘’, instead of relying on the GC to clean up the object.
For example, to delete an Account, it’s NOT enough to just let it go out of scope. Application MUST delete it manually
like this (in Java):
acc.delete();
PJSUA2 includes PersistentObject class to provide functionality to read/write data from/to a document (string or
file). The data can be simple data types such as boolean, number, string, and string arrays, or a user defined object.
Currently the implementation supports reading and writing from/to JSON document ([http://tools.ietf.org/html/rfc4627
RFC 4627]), but the framework allows application to extend the API to support other document formats.
As such, classes which inherit from PersistentObject, such as EpConfig (endpoint configuration), AccountConfig
(account configuration), and BuddyConfig (buddy configuration) can be loaded/saved from/to a file. Heres an example
to save a config to a file:
EpConfig epCfg;
JsonDocument jDoc;
epCfg.uaConfig.maxCalls = 61;
epCfg.uaConfig.userAgent = "Just JSON Test";
jDoc.writeObject(epCfg);
jDoc.saveFile("jsontest.js");
To load from the file:
EpConfig epCfg;
JsonDocument jDoc;
jDoc.loadFile("jsontest.js");
jDoc.readObject(epCfg);
The PJSUA2 C++ library will be built by default by PJSIP build system. Standard C++ library is required.
The SWIG modules for Python and Java are built by invoking make and make install manually from
pjsip-apps/src/swig directory. The make install will install the Python SWIG module to user’s
site-packages directory.
http://slidepdf.com/reader/full/pjsua2doc 17/271
8/10/2019 PJSUA2Doc
3.4.1 Requirements
1. SWIG
2. JDK.
3. Python, version 2.7 or above is required. For Linux/UNIX, you will also need Python developent
package (called python-devel (e.g. on Fedora) or python2.7-dev (e.g. on Ubuntu)). For Windows,
you will need MinGW and Python SDK such as ActivePython-2.7.5 from ActiveState.
To test the installation, simply run python and import pjsua2 module:
$ python
> import pjsua2
> ^Z
int main()
{
Endpoint ep;
ep.libCreate();
// Initialize endpoint
EpConfig ep_cfg;
ep.libInit( ep_cfg );
http://slidepdf.com/reader/full/pjsua2doc 18/271
8/10/2019 PJSUA2Doc
ep.transportCreate(PJSIP_TRANSPORT_UDP, tcfg);
} catch (Error &err) {
std::cout << err.info() << std::endl;
return 1;
}
// Configure an AccountConfig
AccountConfig acfg;
acfg.idUri = "sip:test@pjsip.org";
acfg.regConfig.registrarUri = "sip:pjsip.org";
AuthCredInfo cred("digest", "*", "test", 0, "secret");
acfg.sipConfig.authCreds.push_back( cred );
acfg = pj.AccountConfig();
http://slidepdf.com/reader/full/pjsua2doc 19/271
8/10/2019 PJSUA2Doc
acfg.idUri = "sip:test@pjsip.org";
acfg.regConfig.registrarUri = "sip:pjsip.org";
cred = pj.AuthCredInfo("digest", "*", "test", 0, "pwtest");
acfg.sipConfig.authCreds.append( cred );
# Create the account
acc = Account();
acc.create(acfg);
# Here we don’t have anything else to do..
time.sleep(10);
#
# main()
#
if __name__ == "__main__":
pjsua2_test()
http://slidepdf.com/reader/full/pjsua2doc 20/271
8/10/2019 PJSUA2Doc
acfg.getRegConfig().setRegistrarUri("sip:pjsip.org");
AuthCredInfo cred = new AuthCredInfo("digest", "*", "test", 0, "secret");
acfg.getSipConfig().getAuthCreds().add( cred );
// Create the account
MyAccount acc = new MyAccount();
acc.create(acfg);
// Here we don’t have anything else to do..
Thread.sleep(10000);
/ * Explicitly delete the account.
* This is to avoid GC to delete the endpoint first before deleting
* the account.
*/
acc.delete();
} catch (Exception e) {
System.out.println(e);
return;
}
}
}
http://slidepdf.com/reader/full/pjsua2doc 21/271
8/10/2019 PJSUA2Doc
http://slidepdf.com/reader/full/pjsua2doc 22/271
8/10/2019 PJSUA2Doc
CHAPTER
FOUR
ENDPOINT
The Endpoint class is a singleton class, and application MUST create one and at most one of this class instance before
it can do anything else, and similarly, once this class is destroyed, application must NOT call any library API. This
class is the core class of PJSUA2, and it provides the following functions:
• Starting up and shutting down
• Customization of configurations, such as core UA (User Agent) SIP configuration, media configuration, and
logging configuration
This chapter will describe the functions above.
To use the Endpoint class, normally application does not need to subclass it unless:
• application wants to implement/override Endpoints callback methods to get the events such as transport state
change or NAT detection completion, or
• application schedules a timer using Endpoint.utilTimerSchedule() API. In this case, application needs to imple-
ment the onTimer() callback to get the notification when the timer expires.
Once the endpoint is instantiated, you can retrieve the Endpoint instance using Endpoint.instance() static method.
The libCreate() method will raise exception if error occurs, so we need to trap the exception using try/catch clause as
above.
19
http://slidepdf.com/reader/full/pjsua2doc 23/271
8/10/2019 PJSUA2Doc
The EpConfig class provides endpoint configuration which allows the customization of the following settings:
• UAConfig, to specify core SIP user agent settings.
• MediaConfig, to specify various media global settings
• LogConfig, to customize logging settings.
Note that some settings can be further specified on per account basis, in the AccountConfig.
To customize the settings, create instance of EpConfig class and specify them during the endpoint initialization (will
be explained more later), for example:
EpConfig ep_cfg;
ep_cfg.logConfig.level = 5;
ep_cfg.uaConfig.maxCalls = 4;
ep_cfg.mediaConfig.sndClockRate = 16000;
try {
EpConfig ep_cfg;
// Specify customization of settings in ep_cfg
ep->libInit(ep_cfg);
} catch(Error& err) {
cout << "Initialization error: " << err.info() << endl;
}
The snippet above initializes the library with the default settings.
Application needs to create one or more transports before it can send or receive SIP messages:
try {
TransportConfig tcfg;
tcfg.port = 5060;
TransportId tid = ep->transportCreate(PJSIP_TRANSPORT_UDP, tcfg);
} catch(Error& err) {
cout << "Transport creation error: " << err.info() << endl;
}
The transportCreate() method returns the newly created Transport ID and it takes the transport type and TransportCon-
fig object to customize the transport settings like bound address and listening port number. Without this, by default
the transport will be bound to INADDR_ANY and any available port.
There is no real use of the Transport ID, except to create userless account (with Account.create(), as will be explained
later), and perhaps to display the list of transports to user if the application wants it.
Now we’re ready to start the library. We need to start the library to finalize the initialization phase, e.g. to complete
the initial STUN address resolution, initialize/start the sound device, etc. To start the library, call libStart() method:
20 Chapter 4. Endpoint
http://slidepdf.com/reader/full/pjsua2doc 24/271
8/10/2019 PJSUA2Doc
try {
ep->libStart();
} catch(Error& err) {
cout << "Startup error: " << err.info() << endl;
}
Once the application exits, the library needs to be shutdown so that resources can be released back to the operating
system. Although this can be done by deleting the Endpoint instance, which will internally call libDestroy(), it is
better to call it manually because on Java or Python there are problems with garbage collection as explained earlier:
ep->libDestroy();
delete ep;
class pj::Endpoint
Endpoint()
Default constructor.
~Endpoint()
Virtual destructor.
Version libVersion()
void libCreate()
http://slidepdf.com/reader/full/pjsua2doc 25/271
8/10/2019 PJSUA2Doc
pjsua_state libGetState()
void libStart()
Call this function after all initialization is done, so that the library can do additional
checking set up.
Application may call this function any time after init().
void libStopWorkerThreads()
int libHandleEvents(unsigned msec_timeout)
Poll pjsua for events, and if necessary block the caller thread for the specified maxi-
mum interval (in miliseconds).
Application doesn’t normally need to call this function if it has configured worker
thread (thread_cnt field) in pjsua_config structure, because polling then will be done
by these worker threads instead.
If EpConfig::UaConfig::mainThreadOnly is enabled and this function is called from
the main thread (by default the main thread is thread that calls libCreate()), this func-
tion will also scan and run any pending jobs in the list.
22 Chapter 4. Endpoint
http://slidepdf.com/reader/full/pjsua2doc 26/271
8/10/2019 PJSUA2Doc
Return
The number of events that have been handled during the poll. Negative value
indicates error, and application can retrieve the error as (status = -return_value).
Parameters
• msec_timeout - Maximum time to wait, in miliseconds.
void libDestroy(unsigned prmFlags = 0)
Destroy pjsua.
Application is recommended to perform graceful shutdown before calling this func-
tion (such as unregister the account from the SIP server, terminate presense subscrip-
tion, and hangup active calls), however, this function will do all of these if it finds
there are active sessions that need to be terminated. This function will block for few
seconds to wait for replies from remote.
Application.may safely call this function more than once if it doesn’t keep track of
it’s state.
Parameters
• prmFlags - Combination of pjsua_destroy_flag enumeration.
string utilStrError(pj_status_t prmErr)
void utilLogWrite(int prmLevel, const string & prmSender, const string & prmMsg)
void utilLogWrite( LogEntry & e)
http://slidepdf.com/reader/full/pjsua2doc 27/271
8/10/2019 PJSUA2Doc
Parameters
• prmUri - The URL string.
void utilTimerCancel(Token prmToken)
24 Chapter 4. Endpoint
http://slidepdf.com/reader/full/pjsua2doc 28/271
8/10/2019 PJSUA2Doc
Parameters
• prmToken - The timer token, which was returned from previous utilTimer-
Schedule() call.
IntVector utilSslGetAvailableCiphers()
void natDetectType(void)
pj_stun_nat_type natGetType()
Auxiliary function to resolve and contact each of the STUN server entries (sequen-
tially) to find which is usable.
The libInit() must have been called before calling this function.
http://slidepdf.com/reader/full/pjsua2doc 29/271
8/10/2019 PJSUA2Doc
See
natCancelCheckStunServers()
Parameters
• prmServers - Array of STUN servers to try. The endpoint will try to resolve
and contact each of the STUN server entry until it finds one that is usable.
Each entry may be a domain name, host name, IP address, and it may contain
an optional port number. For example:
• prmWait - Specify if the function should block until it gets the result. In
this case, the function will block while the resolution is being done, and the
callback will be called before this function returns.
• prmUserData - Arbitrary user data to be passed back to application in the
callback.
Create and start a new SIP transport according to the specified settings.
Return
The transport ID.
Parameters
• type - Transport type.
• cfg - Transport configuration.
IntVector transportEnum()
Return
Array of transport IDs.
26 Chapter 4. Endpoint
http://slidepdf.com/reader/full/pjsua2doc 30/271
8/10/2019 PJSUA2Doc
TransportInfo transportGetInfo(TransportId id)
Parameters
• id - Transport ID.
• enabled - Enable or disable the transport.
void transportClose(TransportId id)
Parameters
• id - Transport ID.
void hangupAllCalls(void)
void mediaAdd( AudioMedia & media)
void mediaRemove( AudioMedia & media)
http://slidepdf.com/reader/full/pjsua2doc 31/271
8/10/2019 PJSUA2Doc
unsigned mediaMaxPorts()
unsigned mediaActivePorts()
const AudioMediaVector & mediaEnumPorts()
AudDevManager & audDevManager()
const CodecInfoVector & codecEnum()
28 Chapter 4. Endpoint
http://slidepdf.com/reader/full/pjsua2doc 32/271
8/10/2019 PJSUA2Doc
Callback when the Endpoint has finished performing NAT type detection that is ini-
tiated with natDetectType().
Parameters
• prm - Callback parameters containing the detection result.
void onNatCheckStunServersComplete(const OnNatCheckStunServersCompleteParam &
prm)
http://slidepdf.com/reader/full/pjsua2doc 33/271
8/10/2019 PJSUA2Doc
Callback when the Endpoint has finished performing STUN server checking that is
initiated with natCheckStunServers().
Parameters
• prm - Callback parameters.
void onTransportState(const OnTransportStateParam & prm)
This callback can be used by application to override the account to be used to handle
an incoming message.
Initially, the account to be used will be calculated automatically by the library. This
initial account will be used if application does not implement this callback, or appli-
cation sets an invalid account upon returning from this callback.
Note that currently the incoming messages requiring account assignment are INVITE,
MESSAGE, SUBSCRIBE, and unsolicited NOTIFY. This callback may be called
before the callback of the SIP event itself, i.e: incoming call, pager, subscription, or
unsolicited-event.
Parameters
• prm - Callback parameters.
Public Static Functions
Endpoint & instance()
Endpoint
struct pj::EpConfig
#include <endpoint.hpp>
30 Chapter 4. Endpoint
http://slidepdf.com/reader/full/pjsua2doc 34/271
8/10/2019 PJSUA2Doc
Endpoint configuration.
Public Functions
void readObject(const ContainerNode & node)
Read this object from a container.
Parameters
• node - Container to write values from.
void writeObject(ContainerNode & node)
UaConfig uaConfig
UA config.
LogConfig logConfig
Logging config.
MediaConfig medConfig
Media config.
Media
struct pj::MediaConfig
#include <endpoint.hpp>
This structure describes media configuration, which will be specified when calling Lib::init().
Public Functions
MediaConfig()
Default constructor initialises with default values.
pjsua_media_config toPj()
Export.
http://slidepdf.com/reader/full/pjsua2doc 35/271
8/10/2019 PJSUA2Doc
void writeObject(ContainerNode & node)
conference bridge. Specifying lower ptime will normally reduce the latency.
Default value: PJSUA_DEFAULT_AUDIO_FRAME_PTIME
unsigned maxMediaPorts
Specify maximum number of media ports to be created in the conference bridge.
Since all media terminate in the bridge (calls, file player, file recorder, etc), the value
must be large enough to support all of them. However, the larger the value, the more
computations are performed.
Default value: PJSUA_MAX_CONF_PORTS
bool hasIoqueue
Specify whether the media manager should manage its own ioqueue for the
RTP/RTCP sockets.
If yes, ioqueue will be created and at least one worker thread will be created too. If
no, the RTP/RTCP sockets will share the same ioqueue as SIP sockets, and no worker
thread is needed.
Normally application would say yes here, unless it wants to run everything from a
single thread.
unsigned threadCnt
32 Chapter 4. Endpoint
http://slidepdf.com/reader/full/pjsua2doc 36/271
8/10/2019 PJSUA2Doc
unsigned ilbcMode
iLBC mode (20 or 30).
Default: 30 (PJSUA_DEFAULT_ILBC_MODE)
unsigned txDropPct
Percentage of RTP packet to drop in TX direction (to simulate packet lost).
Default: 0
unsigned rxDropPct
Percentage of RTP packet to drop in RX direction (to simulate packet lost).
Default: 0
unsigned ecOptions
Echo canceller options (see pjmedia_echo_create())
Default: 0.
unsigned ecTailLen
Echo canceller tail length, in miliseconds.
Setting this to zero will disable echo cancellation.
Default: PJSUA_DEFAULT_EC_TAIL_LEN
unsigned sndRecLatency
http://slidepdf.com/reader/full/pjsua2doc 37/271
8/10/2019 PJSUA2Doc
Default: PJ_TRUE
Logging
struct pj::LogConfig
#include <endpoint.hpp>
LogConfig()
pjsua_logging_config toPj()
34 Chapter 4. Endpoint
http://slidepdf.com/reader/full/pjsua2doc 38/271
8/10/2019 PJSUA2Doc
Generate pjsua_logging_config.
void writeObject(ContainerNode & node)
unsigned decor
Log decoration.
string filename
Optional log filename if app wishes the library to write to log file.
unsigned fileFlags
Additional flags to be given to pj_file_open() when opening the log file.
By default, the flag is PJ_O_WRONLY. Application may set PJ_O_APPEND here so
that logs are appended to existing file instead of overwriting it.
Default is 0.
LogWriter * writer
Custom log writer, if required.
This instance will be destroyed by the endpoint when the endpoint is destroyed.
class pj::LogWriter
http://slidepdf.com/reader/full/pjsua2doc 39/271
8/10/2019 PJSUA2Doc
~LogWriter()
Destructor.
struct pj::LogEntry
#include <endpoint.hpp>
User Agent
struct pj::UaConfig
#include <endpoint.hpp>
36 Chapter 4. Endpoint
http://slidepdf.com/reader/full/pjsua2doc 40/271
8/10/2019 PJSUA2Doc
pjsua_config toPj()
Export to pjsua_config.
void writeObject(ContainerNode & node)
unsigned maxCalls
Maximum calls to support (default: 4).
The value specified here must be smaller than the compile time maximum settings
PJSUA_MAX_CALLS, which by default is 32. To increase this limit, the library
must be recompiled with new PJSUA_MAX_CALLS value.
unsigned threadCnt
Number of worker threads.
Normally application will want to have at least one worker thread, unless when it
wants to poll the library periodically, which in this case the worker thread can be set
to zero.
bool mainThreadOnly
When this flag is non-zero, all callbacks that come from thread other than main thread
will be posted to the main thread and to be executed by Endpoint::libHandleEvents()
function.
This includes the logging callback. Note that this will only work if threadCnt is set to
zero and Endpoint::libHandleEvents() is performed by main thread. By default, the
main thread is set from the thread that invoke Endpoint::libCreate()
Default: false
StringVector nameserver
Array of nameservers to be used by the SIP resolver subsystem.
The order of the name server specifies the priority (first name server will be used first,
unless it is not reachable).
string userAgent
http://slidepdf.com/reader/full/pjsua2doc 41/271
8/10/2019 PJSUA2Doc
The library will try to resolve and contact each of the STUN server entry until it finds
one that is usable. Each entry may be a domain name, host name, IP address, and it
may contain an optional port number. For example:
When nameserver is configured in the pjsua_config.nameserver field, if entry is not
an IP address, it will be resolved with DNS SRV resolution first, and it will fallback
to use DNS A resolution if this fails. Port number may be specified even if the entry
is a domain name, in case the DNS SRV resolution should fallback to a non-standard
port.
When nameserver is not configured, entries will be resolved with pj_gethostbyname()
if it’s not an IP address. Port number may be specified if the server is not listening in
standard STUN port.
bool stunIgnoreFailure
This specifies if the library startup should ignore failure with the STUN servers.
If this is set to PJ_FALSE, the library will refuse to start if it fails to resolve or contact
any of the STUN servers.
Default: TRUE
int natTypeInSdp
Support for adding and parsing NAT type in the SDP to assist troubleshooting.
The valid values are:
Default: 1
bool mwiUnsolicitedEnabled
Handle unsolicited NOTIFY requests containing message waiting indication (MWI)
info.
Unsolicited MWI is incoming NOTIFY requests which are not requested by client
with SUBSCRIBE request.
If this is enabled, the library will respond 200/OK to the NOTIFY request and forward
the request to Endpoint::onMwiInfo() callback.
See also AccountMwiConfig.enabled .
Default: PJ_TRUE
38 Chapter 4. Endpoint
http://slidepdf.com/reader/full/pjsua2doc 42/271
8/10/2019 PJSUA2Doc
pj_status_t status
Status of the detection process.
If this value is not PJ_SUCCESS, the detection has failed and nat_type field will
contain PJ_STUN_NAT_TYPE_UNKNOWN.
string reason
The text describing the status, if the status is not PJ_SUCCESS.
pj_stun_nat_type natType
This contains the NAT type as detected by the detection procedure.
This value is only valid when the status is PJ_SUCCESS.
string natTypeName
Text describing that NAT type.
struct pj::OnNatCheckStunServersCompleteParam
#include <endpoint.hpp>
Argument to Endpoint::onNatCheckStunServersComplete() callback.
Public Members
Token userData
Arbitrary user data that was passed to Endpoint::natCheckStunServers() function.
pj_status_t status
This will contain PJ_SUCCESS if at least one usable STUN server is found, other-
wise it will contain the last error code during the operation.
string name
The server name that yields successful result.
This will only contain value if status is successful.
SocketAddress addr
The server IP address and port in “IP:port” format.
This will only contain value if status is successful.
struct pj::OnTimerParam
#include <endpoint.hpp>
Token userData
Arbitrary user data that was passed to Endpoint::utilTimerSchedule() function.
unsigned msecDelay
The interval of this timer, in miliseconds.
http://slidepdf.com/reader/full/pjsua2doc 43/271
8/10/2019 PJSUA2Doc
struct pj::OnTransportStateParam
#include <endpoint.hpp>
TransportHandle hnd
struct pj::OnSelectAccountParam
#include <endpoint.hpp>
4.7.4 Other
struct pj::PendingJob
Public Functions
void execute(bool is_pending)
Perform the job.
~PendingJob()
Virtual destructor.
40 Chapter 4. Endpoint
http://slidepdf.com/reader/full/pjsua2doc 44/271
8/10/2019 PJSUA2Doc
CHAPTER
FIVE
ACCOUNTS
Accounts provide identity (or identities) of the user who is currently using the application. An account has one SIP
Uniform Resource Identifier (URI) associated with it. In SIP terms, this URI acts as Address of Record (AOR) of the
person and is used as the From header in outgoing requests.
Account may or may not have client registration associated with it. An account is also associated with route set and
some authentication credentials, which are used when sending SIP request messages using the account. An account
also has presence status, which will be reported to remote peer when they subscribe to the account’s presence, or which
is published to a presence server if presence publication is enabled for the account.
At least one account MUST be created in the application, since any outgoing requests require an account context. If no
user association is required, application can create a userless account by calling Account.create(). A userless account
identifies local endpoint instead of a particular user, and it corresponds to a particular transport ID.
Also one account must be set as the default account, which will be used as the account identity when pjsua fails to
match incoming request with any accounts using the stricter matching rules.
To use the Account class, normally application SHOULD create its own subclass, in order to receive notifications for
the account. For example:
41
http://slidepdf.com/reader/full/pjsua2doc 45/271
8/10/2019 PJSUA2Doc
In its subclass, application can implement the account callbacks, which is basically used to process events related to
A userless account identifies a particular SIP endpoint rather than a particular user. Some other SIP softphones may
call this peer-to-peer mode, which means that we are calling another computer via its address rather than calling a
particular user ID. For example, we might identify ourselves as “sip:192.168.0.15” (a userless account) rather than,
say, “sip:alice@pjsip.org”.
In the lower layer PJSUA-LIB API, a userless account is associated with a SIP transport, and is created with
pjsua_acc_add_local() API. This concept has been deprecated in PJSUA2, and rather, a userless account
is a “normal” account with a userless ID URI (e.g. “sip:192.168.0.15”) and without registration. Thus creating a
userless account is exactly the same as creating “normal” account.
We need to configure AccountConfig and call Account.create() to create the account. At the very minimum, pjsua only
requires the account’s ID, which is an URI to identify the account (or in SIP terms, it’s called Address of Record/AOR).
Here’s a snippet:
AccountConfig acc_cfg;
acc_cfg.idUri = "sip:test1@pjsip.org";
The account created above doesn’t do anything except to provide identity in the “From:” header for outgoing requests.
The account will not register to SIP server or anything.
42 Chapter 5. Accounts
http://slidepdf.com/reader/full/pjsua2doc 46/271
8/10/2019 PJSUA2Doc
Typically you will want the account to authenticate and register to your SIP server so that you can receive incoming
calls. To do that you will need to configure some more settings in your AccountConfig, something like this:
AccountConfig acc_cfg;
acc_cfg.idUri = "sip:test1@pjsip.org";
acc_cfg.regConfig.registrarUri = "sip:pjsip.org";
acc_cfg.sipConfig.authCreds.push_back( AuthCredInfo("digest", "*", "test1", 0, "secret1") );
There are many more settings that can be specified in AccountConfig, like:
• AccountRegConfig, to specify registration settings, such as registrar server and retry interval.
• AccountSipConfig, to specify SIP settings, such as credential information and proxy server.
• AccountCallConfig, to specify call settings, such as whether reliable provisional response (SIP 100rel) is re-
quired.
• AccountPresConfig, to specify presence settings, such as whether presence publication (PUBLISH) is enabled.
• AccountMwiConfig, to specify MWI (Message Waiting Indication) settings.
• AccountNatConfig, to specify NAT settings, such as whether STUN or ICE is used.
• AccountMediaConfig, to specify media settings, such as Secure RTP (SRTP) related settings.
• AccountVideoConfig, to specify video settings, such as default capture and render device.
Please see AccountConfig reference documentation for more info.
5.6.1 Account
class pj::Account
http://slidepdf.com/reader/full/pjsua2doc 47/271
8/10/2019 PJSUA2Doc
Account .
Public Functions
Account()
Constructor.
~Account()
Destructor.
Note that if the account is deleted, it will also delete the corresponding account in the
PJSUA-LIB.
Parameters
• cfg - New account config to be applied to the account.
bool isValid()
void setDefault()
Set this as default account to be used when incoming and outgoing requests don’t
match any accounts.
Return
PJ_SUCCESS on success.
44 Chapter 5. Accounts
http://slidepdf.com/reader/full/pjsua2doc 48/271
8/10/2019 PJSUA2Doc
bool isDefault()
Return
True if this is the default account.
int getId()
AccountInfo getInfo()
void setRegistration(bool renew)
Application normally only needs to call this function if it wants to manually update
the registration or to unregister from the server.
Parameters
• renew - If False, this will start unregistration process.
void setTransport(TransportId tp_id)
http://slidepdf.com/reader/full/pjsua2doc 49/271
8/10/2019 PJSUA2Doc
void presNotify(const PresNotifyParam & prm)
Send NOTIFY to inform account presence status or to terminate server side presence
subscription.
If application wants to reject the incoming request, it should set the param PresNoti-
fyParam.state to PJSIP_EVSUB_STATE_TERMINATED.
Parameters
• prm - The sending NOTIFY parameter.
const BuddyVector & enumBuddies()
void addBuddy( Buddy * buddy)
46 Chapter 5. Accounts
http://slidepdf.com/reader/full/pjsua2doc 50/271
8/10/2019 PJSUA2Doc
void removeBuddy( Buddy * buddy)
void onRegState(OnRegStateParam & prm)
Parameters
• prm - Callback parameter.
http://slidepdf.com/reader/full/pjsua2doc 51/271
8/10/2019 PJSUA2Doc
Notify application about the delivery status of outgoing pager/instant message (i.e.
MESSAGE) request.
Parameters
• prm - Callback parameter.
48 Chapter 5. Accounts
http://slidepdf.com/reader/full/pjsua2doc 52/271
8/10/2019 PJSUA2Doc
5.6.2 AccountInfo
struct pj::AccountInfo
#include <account.hpp>
Account information.
http://slidepdf.com/reader/full/pjsua2doc 53/271
8/10/2019 PJSUA2Doc
AccountConfig
struct pj::AccountConfig
#include <account.hpp>
Account configuration.
Public Functions
AccountConfig()
Default constructor will initialize with default values.
This will return a temporary pjsua_acc_config instance, which contents are only valid
as long as this AccountConfig structure remains valid AND no modifications are done
to it AND no further toPj() function call is made.
Any call to toPj() function will invalidate the content of temporary pjsua_acc_config
that was returned by the previous call.
void writeObject(ContainerNode & node)
50 Chapter 5. Accounts
http://slidepdf.com/reader/full/pjsua2doc 54/271
8/10/2019 PJSUA2Doc
string idUri
The Address of Record or AOR, that is full SIP URL that identifies the account.
The value can take name address or URL format, and will look something like
“sip:account@serviceprovider”.
This field is mandatory.
AccountRegConfig regConfig
Registration settings.
AccountSipConfig sipConfig
SIP settings.
AccountCallConfig callConfig
Call settings.
AccountPresConfig presConfig
Presence settings.
AccountMwiConfig mwiConfig
MWI (Message Waiting Indication) settings.
AccountNatConfig natConfig
NAT settings.
AccountMediaConfig mediaConfig
Media settings (applicable for both audio and video).
AccountVideoConfig videoConfig
Video settings.
AccoutRegConfig
struct pj::AccountRegConfig
#include <account.hpp>
Account registration config.
This will be specified in AccountConfig.
Public Functions
void readObject(const ContainerNode & node)
Read this object from a container node.
Parameters
• node - Container to read values from.
void writeObject(ContainerNode & node)
http://slidepdf.com/reader/full/pjsua2doc 55/271
8/10/2019 PJSUA2Doc
Parameters
• node - Container to write values to.
Public Members
string registrarUri
This is the URL to be put in the request URI for the registration, and will look some-
thing like “sip:serviceprovider”.
This field should be specified if registration is desired. If the value is empty, no
account registration will be performed.
bool registerOnAdd
Specify whether the account should register as soon as it is added to the UA.
Application can set this to PJ_FALSE and control the registration manually with pj-
sua_acc_set_registration().
Default: True
SipHeaderVector headers
The optional custom SIP headers to be put in the registration request.
unsigned timeoutSec
Optional interval for registration, in seconds.
If the value is zero, default interval will be used (PJSUA_REG_INTERVAL, 300
seconds).
unsigned retryIntervalSec
Specify interval of auto registration retry upon registration failure (including caused
by transport problem), in second.
Set to 0 to disable auto re-registration. Note that if the registration retry occurs be-
cause of transport failure, the first retry will be done after firstRetryIntervalSec sec-
onds instead. Also note that the interval will be randomized slightly by approximately
+/- ten seconds to avoid all clients re-registering at the same time.
See also firstRetryIntervalSec setting.
Default: PJSUA_REG_RETRY_INTERVAL
unsigned firstRetryIntervalSec
This specifies the interval for the first registration retry.
The registration retry is explained in retryIntervalSec. Note that the value here will
also be randomized by +/- ten seconds.
Default: 0
unsigned delayBeforeRefreshSec
Specify the number of seconds to refresh the client registration before the registration
expires.
Default: PJSIP_REGISTER_CLIENT_DELAY_BEFORE_REFRESH, 5 seconds
bool dropCallsOnFail
52 Chapter 5. Accounts
http://slidepdf.com/reader/full/pjsua2doc 56/271
8/10/2019 PJSUA2Doc
Specify whether calls of the configured account should be dropped after registration
failure and an attempt of re-registration has also failed.
Default: FALSE (disabled)
unsigned unregWaitSec
Specify the maximum time to wait for unregistration requests to complete during
library shutdown sequence.
Default: PJSUA_UNREG_TIMEOUT
unsigned proxyUse
Specify how the registration uses the outbound and account proxy settings.
This controls if and what Route headers will appear in the REGIS-
TER request of this account. The value is bitmask combination of PJ-
SUA_REG_USE_OUTBOUND_PROXY and PJSUA_REG_USE_ACC_PROXY
bits. If the value is set to 0, the REGISTER request will not use any proxy (i.e. it
will not have any Route headers).
Default: 3 (PJSUA_REG_USE_OUTBOUND_PROXY | PJ-
SUA_REG_USE_ACC_PROXY)
AccountSipConfig
struct pj::AccountSipConfig
#include <account.hpp>
void writeObject(ContainerNode & node)
http://slidepdf.com/reader/full/pjsua2doc 57/271
8/10/2019 PJSUA2Doc
specified, for example when the requests are expected to be challenged by the proxies
in the route set.
StringVector proxies
Array of proxy servers to visit for outgoing requests.
Each of the entry is translated into one Route URI.
string contactForced
Optional URI to be put as Contact for this account.
It is recommended that this field is left empty, so that the value will be calculated
automatically based on the transport address.
string contactParams
Additional parameters that will be appended in the Contact header for this account.
This will affect the Contact header in all SIP messages sent on behalf of this ac-
count, including but not limited to REGISTER, INVITE, and SUBCRIBE requests
or responses.
The parameters should be preceeded by semicolon, and all strings must be properly
escaped. Example: ”;my-param=X;another-param=Hi%20there”
string contactUriParams
Additional URI parameters that will be appended in the Contact URI for this account.
This will affect the Contact URI in all SIP messages sent on behalf of this account,
including but not limited to REGISTER, INVITE, and SUBCRIBE requests or re-
sponses.
The parameters should be preceeded by semicolon, and all strings must be properly
escaped. Example: ”;my-param=X;another-param=Hi%20there”
bool authInitialEmpty
If this flag is set, the authentication client framework will send an empty Authoriza-
tion header in each initial request.
Default is no.
string authInitialAlgorithm
Specify the algorithm to use when empty Authorization header is to be sent for each
initial request (see above)
TransportId transportId
Optionally bind this account to specific transport.
This normally is not a good idea, as account should be able to send requests using
any available transports according to the destination. But some application may want
to have explicit control over the transport to use, so in that case it can set this field.
Default: -1 (PJSUA_INVALID_ID)
See
Account::setTransport()
54 Chapter 5. Accounts
http://slidepdf.com/reader/full/pjsua2doc 58/271
8/10/2019 PJSUA2Doc
AccountCallConfig
struct pj::AccountCallConfig
#include <account.hpp>
void writeObject(ContainerNode & node)
pjsua_call_hold_type holdType
Specify how to offer call hold to remote peer.
Please see the documentation on pjsua_call_hold_type for more info.
Default: PJSUA_CALL_HOLD_TYPE_DEFAULT
pjsua_100rel_use prackUse
Specify how support for reliable provisional response (100rel/ PRACK) should be
used for all sessions in this account.
See the documentation of pjsua_100rel_use enumeration for more info.
Default: PJSUA_100REL_NOT_USED
pjsua_sip_timer_use timerUse
Specify the usage of Session Timers for all sessions.
See the pjsua_sip_timer_use for possible values.
Default: PJSUA_SIP_TIMER_OPTIONAL
unsigned timerMinSESec
Specify minimum Session Timer expiration period, in seconds.
Must not be lower than 90. Default is 90.
unsigned timerSessExpiresSec
Specify Session Timer expiration period, in seconds.
Must not be lower than timerMinSE. Default is 1800.
http://slidepdf.com/reader/full/pjsua2doc 59/271
8/10/2019 PJSUA2Doc
AccountPresConfig
struct pj::AccountPresConfig
#include <account.hpp>
Account presence config.
void writeObject(ContainerNode & node)
SipHeaderVector headers
The optional custom SIP headers to be put in the presence subscription request.
bool publishEnabled
If this flag is set, the presence information of this account will be PUBLISH-ed to the
server where the account belongs.
Default: PJ_FALSE
bool publishQueue
Specify whether the client publication session should queue the PUBLISH request
should there be another PUBLISH transaction still pending.
If this is set to false, the client will return error on the PUBLISH request if there is
another PUBLISH transaction still in progress.
Default: PJSIP_PUBLISHC_QUEUE_REQUEST (TRUE)
unsigned publishShutdownWaitMsec
Maximum timesending
process, before to wait for unpublication transaction(s) to complete during shutdown
unregistration.
The library tries to wait for the unpublication (un-PUBLISH) to complete before
sending REGISTER request to unregister the account, during library shutdown pro-
cess. If the value is set too short, it is possible that the unregistration is sent before
unpublication completes, causing unpublication request to fail.
Value is in milliseconds.
Default: PJSUA_UNPUBLISH_MAX_WAIT_TIME_MSEC (2000)
56 Chapter 5. Accounts
http://slidepdf.com/reader/full/pjsua2doc 60/271
8/10/2019 PJSUA2Doc
string pidfTupleId
Optional PIDF tuple ID for outgoing PUBLISH and NOTIFY.
If this value is not specified, a random string will be used.
AccountMwiConfig
struct pj::AccountMwiConfig
#include <account.hpp>
Parameters
• node - Container to read values from.
void writeObject(ContainerNode & node)
bool enabled
Subscribe to message waiting indication events (RFC 3842).
See also UaConfig.mwiUnsolicitedEnabled setting.
Default: FALSE
unsigned expirationSec
Specify the default expiration time (in seconds) for Message Waiting Indication (RFC
3842) event subscription.
This must not be zero.
Default: PJSIP_MWI_DEFAULT_EXPIRES (3600)
AccountNatConfig
struct pj::AccountNatConfig
#include <account.hpp>
http://slidepdf.com/reader/full/pjsua2doc 61/271
8/10/2019 PJSUA2Doc
void writeObject(ContainerNode & node)
Public Members
pjsua_stun_use sipStunUse
Control the use of STUN for the SIP signaling.
Default: PJSUA_STUN_USE_DEFAULT
pjsua_stun_use mediaStunUse
Control the use of STUN for the media transports.
Default: PJSUA_STUN_USE_DEFAULT
bool iceEnabled
Enable ICE for the media transport.
Default: False
int iceMaxHostCands
Set the maximum number of ICE host candidates.
Default: -1 (maximum not set)
bool iceAggressiveNomination
Specify whether to use aggressive nomination.
Default: True
unsigned iceNominatedCheckDelayMsec
For controlling agent if it uses regular nomination, specify the delay to perform nom-
inated check (connectivity check with USE-CANDIDATE attribute) after all compo-
nents have a valid pair.
Default value is PJ_ICE_NOMINATED_CHECK_DELAY.
int iceWaitNominationTimeoutMsec
58 Chapter 5. Accounts
http://slidepdf.com/reader/full/pjsua2doc 62/271
8/10/2019 PJSUA2Doc
For a controlled agent, specify how long it wants to wait (in milliseconds) for the
controlling agent to complete sending connectivity check with nominated flag set
to true for all components after the controlled agent has found that all connectivity
checks in its checklist have been completed and there is at least one successful (but
not nominated) check for every component.
Default value for this option is ICE_CONTROLLED_AGENT_WAIT_NOMINATION_TIMEOUT.
Specify -1 to disable this timer.
bool iceNoRtcp
Disable RTCP component.
Default: False
bool iceAlwaysUpdate
Always send re-INVITE/UPDATE after ICE negotiation regardless of whether the
default ICE transport address is changed or not.
When this is set to False, re-INVITE/UPDATE will be sent only when the default
ICE transport address is changed.
Default: yes
bool turnEnabled
Enable TURN candidate in ICE.
string turnServer
Specify TURN domain name or host name, in in “DOMAIN:PORT” or
“HOST:PORT” format.
pj_turn_tp_type turnConnType
Specify the connection type to be used to the TURN server.
Valid values are PJ_TURN_TP_UDP or PJ_TURN_TP_TCP.
Default: PJ_TURN_TP_UDP
string turnUserName
Specify the username to authenticate with the TURN server.
int turnPasswordType
Specify the type of password.
Currently this must be zero to indicate plain-text password will be used in the pass-
word.
string turnPassword
Specify the password to authenticate with the TURN server.
int contactRewriteUse
This option is used to update the transport address and the Contact header of REGIS-
TER request.
When this option is enabled, the library will keep track of the public IP address from
the response of REGISTER request. Once it detects that the address has changed,
it will unregister current Contact, update the Contact with transport address learned
from Via header, and register a new Contact to the registrar. This will also update the
public name of UDP transport if STUN is configured.
http://slidepdf.com/reader/full/pjsua2doc 63/271
8/10/2019 PJSUA2Doc
int sipOutboundUse
Control the use of SIP outbound feature.
SIP outbound is described in RFC 5626 to enable proxies or registrar to send inbound
requests back to UA using the same connection initiated by the UA for its registration.
This feature is highly useful in NAT-ed deployemtns, hence it is enabled by default.
Note: currently SIP outbound can only be used with TCP and TLS transports. If UDP
is used for the registration, the SIP outbound feature will be silently ignored for the
account.
Default: TRUE
string sipOutboundInstanceId
Specify SIP outbound (RFC 5626) instance ID to be used by this account.
If empty, an instance ID will be generated based on the hostname of this agent. If
application specifies this parameter, the value will look like “<urn:uuid:00000000-
0000-1000-8000-AABBCCDDEEFF>” without the double-quotes.
Default: empty
string sipOutboundRegId
60 Chapter 5. Accounts
http://slidepdf.com/reader/full/pjsua2doc 64/271
8/10/2019 PJSUA2Doc
AccountMediaConfig
struct pj::AccountMediaConfig
#include <account.hpp>
Parameters
• node - Container to read values from.
void writeObject(ContainerNode & node)
TransportConfig transportConfig
Media transport (RTP) configuration.
bool lockCodecEnabled
If remote sends SDP answer containing more than one format or codec in the media
line, send re-INVITE or UPDATE with just one codec to lock which codec to use.
Default: True (Yes).
bool streamKaEnabled
http://slidepdf.com/reader/full/pjsua2doc 65/271
8/10/2019 PJSUA2Doc
Specify whether stream keep-alive and NAT hole punching with non-codec-VAD
mechanism (see PJMEDIA_STREAM_ENABLE_KA) is enabled for this account.
Default: False
pjmedia_srtp_use srtpUse
Specify whether secure media transport should be used for this account.
Valid values are PJMEDIA_SRTP_DISABLED, PJMEDIA_SRTP_OPTIONAL, and
PJMEDIA_SRTP_MANDATORY.
Default: PJSUA_DEFAULT_USE_SRTP
int srtpSecureSignaling
Specify whether SRTP requires secure signaling to be used.
This option is only used when use_srtp option above is non-zero.
Valid values are: 0: SRTP does not require secure signaling 1: SRTP requires secure
transport such as TLS 2: SRTP requires secure end-to-end transport (SIPS)
Default: PJSUA_DEFAULT_SRTP_SECURE_SIGNALING
pjsua_ipv6_use ipv6Use
Specify whether IPv6 should be used on media.
Default is not used.
AccountVideoConfig
struct pj::AccountVideoConfig
#include <account.hpp>
void writeObject(ContainerNode & node)
62 Chapter 5. Accounts
http://slidepdf.com/reader/full/pjsua2doc 66/271
8/10/2019 PJSUA2Doc
http://slidepdf.com/reader/full/pjsua2doc 67/271
8/10/2019 PJSUA2Doc
struct pj::OnIncomingCallParam
#include <account.hpp>
struct pj::OnRegStartedParam
#include <account.hpp>
struct pj::OnRegStateParam
#include <account.hpp>
struct pj::OnIncomingSubscribeParam
#include <account.hpp>
64 Chapter 5. Accounts
http://slidepdf.com/reader/full/pjsua2doc 68/271
8/10/2019 PJSUA2Doc
If application delays the acceptance of the request, it will need to specify this object
when calling Account::presNotify().
string fromUri
Sender URI.
SipRxData rdata
The incoming message.
pjsip_status_code code
The status code to respond to the request.
The default value is 200. Application may set this to other final status code to accept
or reject the request.
string reason
The reason phrase to respond to the request.
SipTxOption txOption
Additional data to be sent with the response, if any.
struct pj::OnInstantMessageParam
#include <account.hpp>
http://slidepdf.com/reader/full/pjsua2doc 69/271
8/10/2019 PJSUA2Doc
struct pj::OnInstantMessageStatusParam
#include <account.hpp>
Token userData
Token or a user data that was associated with the pager transmission.
string toUri
Destination URI.
string msgBody
The message body.
pjsip_status_code code
The SIP status code of the transaction.
string reason
The reason phrase of the transaction.
SipRxData rdata
struct pj::OnTypingIndicationParam
#include <account.hpp>
struct pj::OnMwiInfoParam
#include <account.hpp>
66 Chapter 5. Accounts
http://slidepdf.com/reader/full/pjsua2doc 70/271
8/10/2019 PJSUA2Doc
SipRxData rdata
The whole message buffer.
struct pj::PresNotifyParam
#include <account.hpp>
void * srvPres
5.6.5 Other
class pj::FindBuddyMatch
http://slidepdf.com/reader/full/pjsua2doc 71/271
8/10/2019 PJSUA2Doc
~FindBuddyMatch()
Destructor.
68 Chapter 5. Accounts
http://slidepdf.com/reader/full/pjsua2doc 72/271
8/10/2019 PJSUA2Doc
CHAPTER
SIX
MEDIA
Media objects are objects that are capable to either produce media or takes media.
An important subclass of Media is AudioMedia which represents audio media. There are several type of audio media
objects supported in PJSUA2:
• Capture device’s AudioMedia, to capture audio from the sound device.
• Playback device’s AudioMedia, to play audio to the sound device.
• Call’s AudioMedia, to transmit and receive audio to/from remote person.
• AudioMediaPlayer, to play WAV file(s).
• AudioMediaRecorder, to record audio to a WAV file.
More media objects may be added in the future.
The conference bridge provides a simple but yet powerful concept to manage audio flow between the audio medias.
The principle is very simple, that is you connect audio source to audio destination, and the bridge will make the audio
flows from the source to destination, and that’s it. If more than one sources are transmitting to the same destination,
then the audio from the sources will be mixed. If one source is transmitting to more than one destinations, the bridge
will take care of duplicating the audio from the source to the multiple destinations. The bridge will even take care
medias with different clock rates and ptime.
In PJSUA2, all audio media objects are plugged-in to the central conference bridge for easier manipulation. At
first, a plugged-in audio media will not be connected to anything, so media will not flow from/to any objects. An
audio media source can start/stop the transmission to a destination by using the API AudioMedia.startTransmit() /
AudioMedia.stopTransmit().
An audio media object plugged-in to the conference bridge will be given a port ID number that identifies the object in
the bridge. Application can use the API AudioMedia.getPortId() to retrieve the port ID. Normally, application should
not need to worry about the conference bridge and its port ID (as all will be taken care of by the Media class) unless
To playback the WAV file to the sound device, just start the transmission of the WAV playback object to the sound
device’s playback media:
69
http://slidepdf.com/reader/full/pjsua2doc 73/271
8/10/2019 PJSUA2Doc
AudioMediaPlayer player;
AudioMedia& play_med = Endpoint::instance().audDevManager().getPlaybackDevMedia();
try {
player.createPlayer("file.wav");
player.startTransmit(play_med);
} catch(Error& err) {
}
By default, the WAV file will be played in a loop. To disable the loop, specify PJMEDIA_FILE_NO_LOOP when
creating the player:
player.createPlayer("file.wav", PJMEDIA_FILE_NO_LOOP);
Without looping, silence will be played once the playback has reached the end of the WAV file.
Once you’re done with the playback, just stop the transmission to stop the playback:
try {
player.stopTransmit(play_med);
} catch(Error& err) {
}
Resuming the transmission after the playback is stopped will resume playback from the last play position. Use
player.setPos() to set playback position to a desired location.
Or if you want to record the audio from the sound device to the WAV file, simply do this:
AudioMediaRecorder recorder;
AudioMedia& cap_med = Endpoint::instance().audDevManager().getCaptureDevMedia();
try {
recorder.createRecorder("file.wav");
cap_med.startTransmit(recorder);
} catch(Error& err) {
}
And the media will flow from the sound device to the WAV record file. As usual, to stop or pause recording, just stop
the transmission:
try {
cap_med.stopTransmit(recorder);
} catch(Error& err) {
}
Note that stopping the transmission to the WAV recorder as above does not close the WAV file, and you can resume
recording by connecting a source to the WAV recorder again. You cannot playback the recorded WAV file before you
close it. To close the WAV recorder, simply delete it:
delete recorder;
A useful test to check whether the local sound device (capture and playback device) is working properly is by trans-
mitting the audio from the capture device directly to the playback device (i.e. local loopback). You can do this by:
70 Chapter 6. Media
http://slidepdf.com/reader/full/pjsua2doc 74/271
8/10/2019 PJSUA2Doc
cap_med.startTransmit(play_med);
If you want, you can loop the audio of an audio media object to itself (i.e. the audio received from the object will be
transmitted to itself). You can loop-back audio from any objects, as long as the object has bidirectional media. That
means you can loop the call’s audio media, so that audio received from the remote person will be transmitted back to
her/him. But you can’t loop the WAV player or recorder since these objects can only play or record and not both.
A single call can have more than one media (for example, audio and video). Application can retrieve the audio media
by using the API Call.getMedia(). Then for a normal call, we would want to establish bidirectional audio with the
remote person, which can be done easily by connecting the sound device and the call audio media and vice versa:
CallInfo ci = call.getInfo();
AudioMedia *aud_med = NULL;
if (aud_med) {
// This will connect the sound device/mic to the call audio media
cap_med.startTransmit(*aud_med);
// And this will connect the call audio media to the sound device/speaker
aud_med->startTransmit(play_med);
}
Suppose we want to talk with two remote parties at the same time. Since we already have bidirectional media connec-
tion with one party, we just need to add bidirectional connection with the other party using the code below:
AudioMedia *aud_med2 = (AudioMedia *)call2.getMedia(aud_idx);
if (aud_med2) {
cap_med->startTransmit(*aud_med2);
aud_med2->startTransmit(play_med);
}
Now we can talk to both parties at the same time, and we will hear audio from either party. But at this stage, the remote
parties can’t talk or hear each other (i.e. we’re not in full conference mode yet).
To enable both parties talk to each other, just establish bidirectional media between them:
http://slidepdf.com/reader/full/pjsua2doc 75/271
8/10/2019 PJSUA2Doc
aud_med->startTransmit(*aud_med2);
aud_med2->startTransmit(*aud_med);
Now the three parties (us and both remote parties) will be able to talk to each other.
cap_med.startTransmit(recorder);
aud_med->startTransmit(recorder);
aud_med2->startTransmit(recorder);
Classes
class pj::Media
Media.
Public Functions
~Media()
Virtual destructor.
pjmedia_type getType()
class pj::AudioMedia
Audio Media.
Public Functions
ConfPortInfo getPortInfo()
72 Chapter 6. Media
http://slidepdf.com/reader/full/pjsua2doc 76/271
8/10/2019 PJSUA2Doc
int getPortId()
void adjustRxLevel(float level)
Adjust the signal level to be transmitted from the bridge to this media port by making
it louder or quieter.
Parameters
• level - Signal level adjustment. Value 1.0 means no level adjustment, while
value 0 means to mute the port.
void adjustTxLevel(float level)
Adjust the signal level to be received from this media port (to the bridge) by making
it louder or quieter.
Parameters
• level - Signal level adjustment. Value 1.0 means no level adjustment, while
value 0 means to mute the port.
unsigned getRxLevel()
http://slidepdf.com/reader/full/pjsua2doc 77/271
8/10/2019 PJSUA2Doc
unsigned getTxLevel()
~AudioMedia()
Virtual Destructor.
Public Static Functions
ConfPortInfo getPortInfoFromId(int port_id)
Get information from specific port id.
AudioMedia * typecastFromMedia( Media * media)
class pj::AudioMediaPlayer
Audio Media Player.
Public Functions
AudioMediaPlayer()
Constructor.
Create a file player, and automatically add this player to the conference bridge.
Parameters
74 Chapter 6. Media
http://slidepdf.com/reader/full/pjsua2doc 78/271
8/10/2019 PJSUA2Doc
• file_name - The filename to be played. Currently only WAV files are sup-
ported, and the WAV file MUST be formatted as 16bit PCM mono/single chan-
nel (any clock rate is supported).
• options - Optional option flag. Application may specify PJME-
DIA_FILE_NO_LOOP to prevent playback loop.
void createPlaylist(const StringVector & file_names, const string & label = “”, unsigned
options = 0)
Create a file playlist media port, and automatically add the port to the conference
bridge.
Parameters
• file_names - Array of file names to be added to the play list. Note that the
files must have the same clock rate, number of channels, and number of bits
per sample.
• label - Optional label to be set for the media port.
• options - Optional option flag. Application may specify PJME-
DIA_FILE_NO_LOOP to prevent looping.
void setPos(pj_uint32_t samples)
~AudioMediaPlayer()
Virtual destructor.
Public Static Functions
class pj::AudioMediaRecorder
http://slidepdf.com/reader/full/pjsua2doc 79/271
8/10/2019 PJSUA2Doc
Audio Media Recorder.
Public Functions
AudioMediaRecorder()
Constructor.
Create a file recorder, and automatically connect this recorder to the conference
bridge.
The recorder currently supports recording WAV file. The type of the recorder to use
is determined by the extension of the file (e.g. ”.wav”).
Parameters
• file_name - Output file name. The function will determine the default for-
mat to be used based on the file extension. Currently ”.wav” is supported on
all platforms.
• enc_type - Optionally specify the type of encoder to be used to compress
the media, if the file can support different encodings. This value must be zero
for now.
• max_size - Maximum file size. Specify zero or -1 to remove size limitation.
This value must be zero or -1 for now.
• options - Optional options, which can be used to specify the recording
file format. Supported options are PJMEDIA_FILE_WRITE_PCM, PJME-
DIA_FILE_WRITE_ALAW, and PJMEDIA_FILE_WRITE_ULAW. Default
is zero or PJMEDIA_FILE_WRITE_PCM.
~AudioMediaRecorder()
Virtual destructor.
Public Static Functions
AudioMediaRecorder * typecastFromAudioMedia( AudioMedia * media)
76 Chapter 6. Media
http://slidepdf.com/reader/full/pjsua2doc 80/271
8/10/2019 PJSUA2Doc
struct pj::MediaFormat
#include <media.hpp>
This structure contains all the information needed to completely describe a media.
Public Members
pj_uint32_t id
The format id that specifies the audio sample or video pixel format.
Some well known formats ids are declared in pjmedia_format_id enumeration.
See
pjmedia_format_id
pjmedia_type type
The top-most type of the media, as an information.
struct pj::MediaFormatAudio
#include <media.hpp>
pjmedia_format toPj()
Export to pjmedia_format.
Public Members
unsigned clockRate
Audio clock rate in samples or Hz.
unsigned channelCount
Number of channels.
unsigned frameTimeUsec
Frame interval, in microseconds.
unsigned bitsPerSample
Number of bits per sample.
pj_uint32_t avgBps
Average bitrate.
pj_uint32_t maxBps
http://slidepdf.com/reader/full/pjsua2doc 81/271
8/10/2019 PJSUA2Doc
Maximum bitrate.
struct pj::MediaFormatVideo
#include <media.hpp>
int fpsDenum
Frames per second denumerator.
pj_uint32_t avgBps
Average bitrate.
pj_uint32_t maxBps
Maximum bitrate.
struct pj::ConfPortInfo
#include <media.hpp>
This structure descibes information about a particular media port that has been registered into the confer-
ence bridge.
Public Functions
void fromPj(const pjsua_conf_port_info & port_info)
Construct from pjsua_conf_port_info.
Public Members
int portId
Conference port number.
string name
Port name.
MediaFormatAudio format
Media audio format information.
float txLevelAdj
78 Chapter 6. Media
http://slidepdf.com/reader/full/pjsua2doc 82/271
8/10/2019 PJSUA2Doc
Tx level adjustment.
Value 1.0 means no adjustment, value 0 means the port is muted, value 2.0 means the
level is amplified two times.
float rxLevelAdj
Rx level adjustment.
Value 1.0 means no adjustment, value 0 means the port is muted, value 2.0 means the
level is amplified two times.
IntVector listeners
Array of listeners (in other words, ports where this port is transmitting to.
Device Manager
class pj::AudDevManager
int getCaptureDev()
Get currently active capture sound devices.
If sound devices has not been created, it is possible that the function returns -1 as
device IDs.
Return
Device ID of the capture device.
AudioMedia & getCaptureDevMedia()
int getPlaybackDev()
AudioMedia & getPlaybackDevMedia()
http://slidepdf.com/reader/full/pjsua2doc 83/271
8/10/2019 PJSUA2Doc
void setCaptureDev(int capture_dev)
const AudioDevInfoVector & enumDev()
void setNullDev()
MediaPort * setNoDev()
Disconnect the main conference bridge from any sound devices, and let application
connect the bridge to it’s own sound device/master port.
Return
The port interface of the conference bridge, so that application can connect this
to it’s own sound device or master port.
80 Chapter 6. Media
http://slidepdf.com/reader/full/pjsua2doc 84/271
8/10/2019 PJSUA2Doc
unsigned getEcTail()
bool sndIsActive()
The sound device may be inactive if the application has set the auto close feature to
non-zero (the sndAutoCloseTime setting in MediaConfig), or if null sound device or
no sound device has been configured via the setNoDev() function.
void refreshDevs()
unsigned getDevCount()
http://slidepdf.com/reader/full/pjsua2doc 85/271
8/10/2019 PJSUA2Doc
string capName(pjmedia_aud_dev_cap cap)
This will configure audio format capability (other than PCM) to the sound device
being used.
If sound device is currently active, the method will forward the setting to the sound
device instance to be applied immediately, if it supports it.
82 Chapter 6. Media
http://slidepdf.com/reader/full/pjsua2doc 86/271
8/10/2019 PJSUA2Doc
MediaFormatAudio getExtFormat()
Get the audio format capability (other than PCM) of the sound device being used.
If sound device is currently active, the method will forward the request to the sound
device. If sound device is currently inactive, and if application had previously set the
setting and mark the setting as kept, then that setting will be returned. Otherwise, this
method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_EXT_FORMAT capability in AudioDevInfo.caps flags,
otherwise Error will be thrown.
Return
The audio format.
This will configure audio input latency control or query capability to the sound device
being used.
If sound device is currently active, the method will forward the setting to the sound
device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_INPUT_LATENCY capability in AudioDevInfo.caps
flags, otherwise Error will be thrown.
Note that in case the setting is kept for future use, it will be applied to any devices,
unsigned getInputLatency()
Get the audio input latency control or query capability of the sound device being used.
If sound device is currently active, the method will forward the request to the sound
device. If sound device is currently inactive, and if application had previously set the
setting and mark the setting as kept, then that setting will be returned. Otherwise, this
method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_INPUT_LATENCY capability in AudioDevInfo.caps
flags, otherwise Error will be thrown.
Return
The audio input latency.
http://slidepdf.com/reader/full/pjsua2doc 87/271
8/10/2019 PJSUA2Doc
This will configure audio output latency control or query capability to the sound
device being used.
If sound device is currently active, the method will forward the setting to the sound
device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_OUTPUT_LATENCY capability in AudioDevInfo.caps
flags, otherwise Error will be thrown.
Note that in case the setting is kept for future use, it will be applied to any devices,
even when application has changed the sound device to be used.
Parameters
• latency_msec - The output latency.
• keep - Specify whether the setting is to be kept for future use.
unsigned getOutputLatency()
Get the audio output latency control or query capability of the sound device being
used.
If sound device is currently active, the method will forward the request to the sound
device. If sound device is currently inactive, and if application had previously set the
setting and mark the setting as kept, then that setting will be returned. Otherwise, this
method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_OUTPUT_LATENCY capability in AudioDevInfo.caps
flags, otherwise Error will be thrown.
Return
The audio output latency.
This will configure audio input volume level capability to the sound device being
used.
If sound device is currently active, the method will forward the setting to the sound
device instance to be applied immediately, if it supports it.
84 Chapter 6. Media
http://slidepdf.com/reader/full/pjsua2doc 88/271
8/10/2019 PJSUA2Doc
unsigned getInputVolume()
Get the audio input volume level capability of the sound device being used.
If sound device is currently active, the method will forward the request to the sound
device. If sound device is currently inactive, and if application had previously set the
setting and mark the setting as kept, then that setting will be returned. Otherwise, this
method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING capability in AudioDev-
Info.caps flags, otherwise Error will be thrown. *
Return
The audio input volume level, in percent.
This will configure audio output volume level capability to the sound device being
used.
If sound device is currently active, the method will forward the setting to the sound
device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING capability in AudioDev-
Info.caps flags, otherwise Error will be thrown.
Note that in case the setting is kept for future use, it will be applied to any devices,
unsigned getOutputVolume()
Get the audio output volume level capability of the sound device being used.
If sound device is currently active, the method will forward the request to the sound
device. If sound device is currently inactive, and if application had previously set the
setting and mark the setting as kept, then that setting will be returned. Otherwise, this
method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING capability in AudioDev-
Info.caps flags, otherwise Error will be thrown.
Return
The audio output volume level, in percent.
http://slidepdf.com/reader/full/pjsua2doc 89/271
8/10/2019 PJSUA2Doc
unsigned getInputSignal()
Get the audio input signal level capability of the sound device being used.
If sound device is currently active, the method will forward the request to the sound
device. If sound device is currently inactive, and if application had previously set the
setting and mark the setting as kept, then that setting will be returned. Otherwise, this
method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_INPUT_SIGNAL_METER capability in AudioDevInfo.caps
flags, otherwise Error will be thrown.
Return
The audio input signal level, in percent.
unsigned getOutputSignal()
Get the audio output signal level capability of the sound device being used.
If sound device is currently active, the method will forward the request to the sound
device. If sound device is currently inactive, and if application had previously set the
setting and mark the setting as kept, then that setting will be returned. Otherwise, this
method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_OUTPUT_SIGNAL_METER capability in AudioDev-
Info.caps flags, otherwise Error will be thrown.
Return
The audio output signal level, in percent.
This will configure audio input route capability to the sound device being used.
If sound device is currently active, the method will forward the setting to the sound
device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_INPUT_ROUTE capability in AudioDevInfo.caps flags,
otherwise Error will be thrown.
Note that in case the setting is kept for future use, it will be applied to any devices,
even when application has changed the sound device to be used.
Parameters
• route - The audio input route.
• keep - Specify whether the setting is to be kept for future use.
pjmedia_aud_dev_route getInputRoute()
86 Chapter 6. Media
http://slidepdf.com/reader/full/pjsua2doc 90/271
8/10/2019 PJSUA2Doc
Get the audio input route capability of the sound device being used.
If sound device is currently active, the method will forward the request to the sound
device. If sound device is currently inactive, and if application had previously set the
setting and mark the setting as kept, then that setting will be returned. Otherwise, this
method will raise error.
This will configure audio output route capability to the sound device being used.
If sound device is currently active, the method will forward the setting to the sound
device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_OUTPUT_ROUTE capability in AudioDevInfo.caps
flags, otherwise Error will be thrown.
Note that in case the setting is kept for future use, it will be applied to any devices,
even when application has changed the sound device to be used.
Parameters
• route - The audio output route.
• keep - Specify whether the setting is to be kept for future use.
pjmedia_aud_dev_route getOutputRoute()
Get the audio output route capability of the sound device being used.
If sound device is currently active, the method will forward the request to the sound
device. If sound device is currently inactive, and if application had previously set the
setting and mark the setting as kept, then that setting will be returned. Otherwise, this
method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_OUTPUT_ROUTE capability in AudioDevInfo.caps
flags, otherwise Error will be thrown.
Return
The audio output route.
This will configure audio voice activity detection capability to the sound device being
used.
http://slidepdf.com/reader/full/pjsua2doc 91/271
8/10/2019 PJSUA2Doc
If sound device is currently active, the method will forward the setting to the sound
device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_VAD capa-
bility in AudioDevInfo.caps flags, otherwise Error will be thrown.
Note that in case the setting is kept for future use, it will be applied to any devices,
even when application has changed the sound device to be used.
Parameters
• enable - Enable/disable voice activity detection feature. Set true to enable.
• keep - Specify whether the setting is to be kept for future use.
bool getVad()
Get the audio voice activity detection capability of the sound device being used.
If sound device is currently active, the method will forward the request to the sound
device. If sound device is currently inactive, and if application had previously set the
setting and mark the setting as kept, then that setting will be returned. Otherwise, this
method will raise error.
This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_VAD capa-
bility in AudioDevInfo.caps flags, otherwise Error will be thrown.
Return
The audio voice activity detection feature.
This will configure audio comfort noise generation capability to the sound device
being used.
If sound device is currently active, the method will forward the setting to the sound
device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_CNG capa-
bility in AudioDevInfo.caps flags, otherwise Error will be thrown.
Note that in case the setting is kept for future use, it will be applied to any devices,
even when application has changed the sound device to be used.
Parameters
• enable - Enable/disable comfort noise generation feature. Set true to enable.
bool getCng()
Get the audio comfort noise generation capability of the sound device being used.
If sound device is currently active, the method will forward the request to the sound
device. If sound device is currently inactive, and if application had previously set the
88 Chapter 6. Media
http://slidepdf.com/reader/full/pjsua2doc 92/271
8/10/2019 PJSUA2Doc
setting and mark the setting as kept, then that setting will be returned. Otherwise, this
method will raise error.
This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_CNG capa-
bility in AudioDevInfo.caps flags, otherwise Error will be thrown.
Return
The audio comfort noise generation feature.
This will configure audio packet loss concealment capability to the sound device
being used.
If sound device is currently active, the method will forward the setting to the sound
device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_PLC capa-
bility in AudioDevInfo.caps flags, otherwise Error will be thrown.
Note that in case the setting is kept for future use, it will be applied to any devices,
even when application has changed the sound device to be used.
Parameters
• enable - Enable/disable packet loss concealment feature. Set true to enable.
• keep - Specify whether the setting is to be kept for future use.
bool getPlc()
Get the audio packet loss concealment capability of the sound device being used.
If sound device is currently active, the method will forward the request to the sound
device. If sound device is currently inactive, and if application had previously set the
setting and mark the setting as kept, then that setting will be returned. Otherwise, this
method will raise error.
This method is only valid if the device has PJMEDIA_AUD_DEV_CAP_PLC capa-
bility in AudioDevInfo.caps flags, otherwise Error will be thrown.
Return
The audio packet loss concealment feature.
Device Info
struct pj::AudioDevInfo
#include <media.hpp>
http://slidepdf.com/reader/full/pjsua2doc 93/271
8/10/2019 PJSUA2Doc
~AudioDevInfo()
Destructor.
Public Members
string name
The device name.
unsigned inputCount
Maximum number of input channels supported by this device.
If the value is zero, the device does not support input operation (i.e. it is a playback
only device).
unsigned outputCount
Maximum number of output channels supported by this device.
If the value is zero, the device does not support output operation (i.e. it is an input
only device).
unsigned defaultSamplesPerSec
Default sampling rate.
string driver
The underlying driver name.
unsigned caps
Device capabilities, as bitmask combination of pjmedia_aud_dev_cap.
unsigned routes
Supported audio device routes, as bitmask combination of pjmedia_aud_dev_route.
The value may be zero if the device does not support audio routing.
MediaFormatVector extFmt
Array of supported extended audio formats.
90 Chapter 6. Media
http://slidepdf.com/reader/full/pjsua2doc 94/271
8/10/2019 PJSUA2Doc
CHAPTER
SEVEN
CALLS
To use the Call class, normally application SHOULD create its own subclass, such as:
class MyCall : public Call
{
public:
MyCall(Account &acc, int call_id = PJSUA_INVALID_ID)
: Call(acc, call_id)
{ }
~MyCall()
{ }
In its subclass, application can implement the call callbacks, which is basically used to process events related to the
call, such as call state change or incoming call transfer request.
Making outgoing call is simple, just invoke makeCall() method of the Call object. Assuming you have the Account
object as acc variable and destination URI string in dest_uri, you can initiate outgoing call with the snippet below:
Call *call = new MyCall(*acc);
CallOpParam prm(true); // Use default call settings
try {
call->makeCall(dest_uri, prm);
} catch(Error& err) {
cout << err.info() << endl;
}
91
http://slidepdf.com/reader/full/pjsua2doc 95/271
8/10/2019 PJSUA2Doc
The snippet above creates a Call object and initiates outgoing call to dest_uri using the default call settings. Subsequent
operations to the call can use the method in the call instance, and events to the call will be reported to the callback.
More on the callback will be explained a bit later.
Incoming calls are reported as onIncomingCall() of the Account class. You must derive a class from the Account class
to handle incoming calls.
Below is a sample code of the callback implementation:
void MyAccount::onIncomingCall(OnIncomingCallParam &iprm)
{
Call *call = new MyCall(*this, iprm.callId);
CallOpParam prm;
prm.statusCode = PJSIP_SC_OK;
call->answer(prm);
}
For incoming calls, the call instance is created in the callback function as shown above. Application should make sure
to store the call instance during the lifetime of the call (that is until the call is disconnected).
All call properties such as state, media state, remote peer information, etc. are stored as CallInfo class, which can be
retrieved from the call object with using getInfo() method of the Call.
Call disconnection event is a special event since once the callback that reports this event returns, the call is no longer
valid and any operations invoked to the call object will raise error exception. Thus, it is recommended to delete the
call object inside the callback.
The call disconnection is reported in onCallState() method of Call and it can be detected as follows:
You can only operate with the call’s audio media (e.g. connecting the call to the sound device in the conference bridge)
when the call’s audio media is ready (or active). The changes to the call’s media state is reported in onCallMediaState()
callback, and if the calls audio media is ready (or active) the function Call.getMedia() will return a valid audio media.
Below is a sample code to connect the call to the sound device when the media is active:
92 Chapter 7. Calls
http://slidepdf.com/reader/full/pjsua2doc 96/271
8/10/2019 PJSUA2Doc
When the audio media becomes inactive (for example when the call is put on hold), there is no need to stop the audio
media’s transmission to/from the sound device since the call’s audio media will be removed automatically from the
conference bridge when it’s no longer valid, and this will automatically remove all connections to/from the call.
You can invoke operations to the Call object, such as hanging up, putting the call on hold, sending re-INVITE, etc.
Please see the reference documentation of Call for more info.
You can send IM within a call using Call.sendInstantMessage(). The transmission status of outgoing instant messages
is reported in Call.onInstantMessageStatus() callback method.
In addition to sending instant messages, you can also send typing indication using Call.sendTypingIndication().
Incoming IM and typing indication received within a call will be reported in the callback functions
Call.onInstantMessage() and Call.onTypingIndication().
Alternatively, you can send IM and typing indication outside a call by using Buddy.sendInstantMessage() and
Buddy.sendTypingIndication(). For more information, please see Presence documentation.
7.9.1 Call
class pj::Call
Call.
Public Functions
http://slidepdf.com/reader/full/pjsua2doc 97/271
8/10/2019 PJSUA2Doc
~Call()
Destructor.
CallInfo getInfo()
bool isActive()
Check if this call has active INVITE session and the INVITE session has not been
disconnected.
Return
True if call is active.
int getId()
bool hasMedia()
Media * getMedia(unsigned med_idx)
Return
The media or NULL if invalid or inactive.
Parameters
• med_idx - Media index.
94 Chapter 7. Calls
http://slidepdf.com/reader/full/pjsua2doc 98/271
8/10/2019 PJSUA2Doc
void setUserData(Token user_data)
Token getUserData()
Get user data attached to the call, which has been previously set with setUserData().
Return
The user data.
pj_stun_nat_type getRemNatType()
http://slidepdf.com/reader/full/pjsua2doc 99/271
8/10/2019 PJSUA2Doc
void answer(const CallOpParam & prm)
Hangup call by using method that is appropriate according to the call state.
This function is different than answering the call with 3xx-6xx response (with an-
swer()), in that this function will hangup the call regardless of the state and role of
the call, while answer() only works with incoming calls on EARLY state.
Parameters
• prm.statusCode - Optional status code to be sent when we’re rejecting
incoming call. If the value is zero, “603/Decline” will be sent.
• prm.reason - Optional reason phrase to be sent when we’re rejecting in-
coming call. If empty, default text will be used.
• prm.txOption - Optional list of headers etc to be added to outgoing re-
quest/response message.
96 Chapter 7. Calls
http://slidepdf.com/reader/full/pjsua2doc 100/271
8/10/2019 PJSUA2Doc
This will send re-INVITE with the appropriate SDP to inform remote that the call
is being put on hold. The final status of the request itself will be reported on the
onCallMediaState() callback, which inform the application that the media state of the
call has changed.
Parameters
void reinvite(const CallOpParam & prm)
void update(const CallOpParam & prm)
unchanged.
• prm.txOption - Optional message components to be sent with the request.
http://slidepdf.com/reader/full/pjsua2doc 101/271
8/10/2019 PJSUA2Doc
• cmd - Redirection operation to be applied to the current target. The semantic of
this argument is similar to the description in the onCallRedirected() callback,
except that the PJSIP_REDIRECT_PENDING is not accepted here.
98 Chapter 7. Calls
http://slidepdf.com/reader/full/pjsua2doc 102/271
8/10/2019 PJSUA2Doc
Parameters
• with_media - True to include media information too.
• indent - Spaces for left indentation.
int vidGetStreamIdx()
Get the media stream index of the default video stream in the call.
Typically this will just retrieve the stream index of the first activated video stream in
the call. If none is active, it will return the first inactive video stream.
http://slidepdf.com/reader/full/pjsua2doc 103/271
8/10/2019 PJSUA2Doc
Return
The media stream index or -1 if no video stream is present in the call.
Determine if video stream for the specified call is currently running (i.e.
has been created, started, and not being paused) for the specified direction.
Return
True if stream is currently running for the specified direction.
Parameters
• med_idx - Media stream index, or -1 to specify default video media.
• dir - The direction to be checked.
Add, remove, modify, and/or manipulate video media stream for the specified call.
This may trigger a re-INVITE or UPDATE to be sent for the call.
Parameters
• op - The video stream operation to be performed, possible values are pj-
sua_call_vid_strm_op.
• param - The parameters for the video stream operation (see CallVidSet-
StreamParam).
StreamStat getStreamStat(unsigned med_idx)
http://slidepdf.com/reader/full/pjsua2doc 104/271
8/10/2019 PJSUA2Doc
Internal function (callled by Endpoint ( to process update to call medias when call
media state changes.
Parameters
http://slidepdf.com/reader/full/pjsua2doc 105/271
8/10/2019 PJSUA2Doc
Normal application would need to implement this callback, e.g. to connect the call’s
media to sound device. When ICE is used, this callback will also be called to report
ICE negotiation failure.
Parameters
• prm - Callback parameter.
Notify application when a call has just created a local SDP (for initial or subsequent
SDP offer/answer).
Application can implement this callback to modify the SDP, before it is being sent
and/or negotiated with remote SDP, for example to apply per account/call basis
codecs priority or to add custom/proprietary SDP attributes.
Parameters
• prm - Callback parameter.
Notify application when media session is created and before it is registered to the
conference bridge.
Application may return different media port if it has added media processing port to
the stream. This media port then will be added to the conference bridge instead.
Parameters
• prm - Callback parameter.
Notify application when media session has been unregistered from the conference
bridge and about to be destroyed.
Parameters
• prm - Callback parameter.
http://slidepdf.com/reader/full/pjsua2doc 106/271
8/10/2019 PJSUA2Doc
Notify application that an existing call has been replaced with a new call.
This happens when PJSUA-API receives incoming INVITE request with Replaces
header.
After this callback is called, normally PJSUA-API will disconnect this call and es-
tablish a new call newCallId .
Parameters
• prm - Callback parameter.
Notify application when call has received new offer from remote (i.e.
re-INVITE/UPDATE with SDP is received). Application can decide to accept/reject
the offer by setting the code (default is 200). If the offer is accepted, application
can update the call setting to be applied in the answer. When this callback is not
implemented, the default behavior is to accept the offer using current call setting.
Parameters
http://slidepdf.com/reader/full/pjsua2doc 107/271
8/10/2019 PJSUA2Doc
This callback is called when the call is about to resend the INVITE request to the
specified target, following the previously received redirection response.
Application may accept the redirection to the specified target, reject this target only
and make the session continue to try the next target in the list if such target exists, stop
the whole redirection process altogether and cause the session to be disconnected, or
defer the decision to ask for user confirmation.
This callback is optional, the default behavior is to NOT follow the redirection re-
sponse.
Return
Action to be performed for the target. Set this parameter to one of the value
below:
Parameters
• prm - Callback parameter.
http://slidepdf.com/reader/full/pjsua2doc 108/271
8/10/2019 PJSUA2Doc
7.9.2 Settings
struct pj::CallSetting
#include <call.hpp>
Call settings.
Public Functions
CallSetting(pj_bool_t useDefaultValues = false)
Default constructor initializes with empty or default values.
http://slidepdf.com/reader/full/pjsua2doc 109/271
8/10/2019 PJSUA2Doc
bool isEmpty()
pjsua_call_setting toPj()
Convert to pjsip.
Public Members
unsigned flag
Bitmask of pjsua_call_flag constants.
Default: PJSUA_CALL_INCLUDE_DISABLED_MEDIA
unsigned reqKeyframeMethod
This flag controls what methods to request keyframe are allowed on the call.
Value is bitmask of pjsua_vid_req_keyframe_method.
Default: PJSUA_VID_REQ_KEYFRAME_SIP_INFO | PJ-
SUA_VID_REQ_KEYFRAME_RTCP_PLI
unsigned audioCount
Number of simultaneous active audio streams for this call.
Setting this to zero will disable audio in this call.
Default: 1
unsigned videoCount
Number of simultaneous active video streams for this call.
Setting this to zero will disable video in this call.
Default: 1 (if video feature is enabled, otherwise it is zero)
Call information.
Application can query the call information by calling Call::getInfo().
Public Functions
http://slidepdf.com/reader/full/pjsua2doc 110/271
8/10/2019 PJSUA2Doc
Call identification.
pjsip_role_e role
Initial call role (UAC == caller)
pjsua_acc_id accId
The account ID where this call belongs.
string localUri
Local URI.
string localContact
Local Contact.
string remoteUri
Remote URI.
string remoteContact
Remote contact.
string callIdString
Dialog Call-ID string.
CallSetting setting
Call setting.
pjsip_inv_state state
Call state.
string stateText
Text describing the state.
pjsip_status_code lastStatusCode
Last status code heard, which can be used as cause code.
string lastReason
The reason phrase describing the last status.
CallMediaInfoVector media
Array of active media information.
CallMediaInfoVector provMedia
Array of provisional media information.
This contains the media info in the provisioning state, that is when the media session
is being created/updated (SDP offer/answer is on progress).
TimeVal connectDuration
http://slidepdf.com/reader/full/pjsua2doc 111/271
8/10/2019 PJSUA2Doc
struct pj::CallMediaInfo
#include <call.hpp>
Call media information.
Public Functions
CallMediaInfo()
Default constructor.
unsigned index
Media index in SDP.
pjmedia_type type
Media type.
pjmedia_dir dir
Media direction.
pjsua_call_media_status status
Call media status.
int audioConfSlot
The conference port number for the call.
Only valid if the media type is audio.
pjsua_vid_win_id videoIncomingWindowId
The window id for incoming video, if any, or PJSUA_INVALID_ID.
Only valid if the media type is video.
pjmedia_vid_dev_index videoCapDev
http://slidepdf.com/reader/full/pjsua2doc 112/271
8/10/2019 PJSUA2Doc
struct pj::StreamInfo
#include <call.hpp>
Media stream info.
Public Functions
void fromPj(const pjsua_stream_info & info)
Convert from pjsip.
Public Members
pjmedia_type type
Media type of this stream.
pjmedia_tp_proto proto
Transport protocol (RTP/AVP, etc.)
pjmedia_dir dir
Media direction.
SocketAddress remoteRtpAddress
unsigned txPt
Outgoing codec payload type.
unsigned rxPt
Incoming codec payload type.
string codecName
Codec name.
unsigned codecClockRate
Codec clock rate.
CodecParam codecParam
Optional codec param.
struct pj::StreamStat
#include <call.hpp>
Media stream statistic.
Public Functions
http://slidepdf.com/reader/full/pjsua2doc 113/271
8/10/2019 PJSUA2Doc
RtcpStat rtcp
RTCP statistic.
JbufState jbuf
Jitter buffer statistic.
struct pj::JbufState
#include <call.hpp>
unsigned frameSize
Individual frame size, in bytes.
unsigned minPrefetch
Minimum allowed prefetch, in frms.
unsigned maxPrefetch
Maximum allowed prefetch, in frms.
unsigned burst
Current burst level, in frames.
unsigned prefetch
Current prefetch value, in frames.
unsigned size
Current buffer size, in frames.
unsigned avgDelayMsec
Average delay, in ms.
unsigned minDelayMsec
Minimum delay, in ms.
unsigned maxDelayMsec
Maximum delay, in ms.
unsigned devDelayMsec
Standard deviation of delay, in ms.
unsigned avgBurst
http://slidepdf.com/reader/full/pjsua2doc 114/271
8/10/2019 PJSUA2Doc
struct pj::RtcpStat
#include <call.hpp>
TimeVal start
Time when session was created.
RtcpStreamStat txStat
http://slidepdf.com/reader/full/pjsua2doc 115/271
8/10/2019 PJSUA2Doc
struct pj::RtcpStreamStat
#include <call.hpp>
TimeVal update
Time of last update.
unsigned updateCount
Number of updates (to calculate avg)
unsigned pkt
struct pj::RtcpStreamStat::@0 lossType
Types of loss detected.
MathStat jitterUsec
Jitter statistics.
struct pj::MathStat
#include <call.hpp>
http://slidepdf.com/reader/full/pjsua2doc 116/271
8/10/2019 PJSUA2Doc
int min
minimum value
int last
last value
int mean
mean
struct pj::MediaTransportInfo
#include <call.hpp>
http://slidepdf.com/reader/full/pjsua2doc 117/271
8/10/2019 PJSUA2Doc
struct pj::OnCallStateParam
#include <call.hpp>
SipEvent e
struct pj::OnCallTsxStateParam
#include <call.hpp>
struct pj::OnCallMediaStateParam
#include <call.hpp>
struct pj::OnCallSdpCreatedParam
#include <call.hpp>
struct pj::OnStreamCreatedParam
#include <call.hpp>
http://slidepdf.com/reader/full/pjsua2doc 118/271
8/10/2019 PJSUA2Doc
unsigned streamIdx
Stream index in the media session.
MediaPort pPort
On input, it specifies the media port of the stream.
Application may modify this pointer to point to different media port to be registered
to the conference bridge.
struct pj::OnStreamDestroyedParam
#include <call.hpp>
Media stream.
unsigned streamIdx
Stream index in the media session.
struct pj::OnDtmfDigitParam
#include <call.hpp>
struct pj::OnCallTransferRequestParam
#include <call.hpp>
http://slidepdf.com/reader/full/pjsua2doc 119/271
8/10/2019 PJSUA2Doc
struct pj::OnCallTransferStatusParam
#include <call.hpp>
pjsip_status_code statusCode
Status progress of the transfer request.
string reason
Status progress reason.
bool finalNotify
If true, no further notification will be reported.
The statusCode specified in this callback is the final status.
bool cont
struct pj::OnCallReplaceRequestParam
#include <call.hpp>
struct pj::OnCallReplacedParam
#include <call.hpp>
http://slidepdf.com/reader/full/pjsua2doc 120/271
8/10/2019 PJSUA2Doc
struct pj::OnCallRxOfferParam
#include <call.hpp>
SdpSession offer
struct pj::OnCallRedirectedParam
#include <call.hpp>
string targetUri
The current target to be tried.
SipEvent e
The event that caused this callback to be called.
This could be the receipt of 3xx response, or 4xx/5xx response received for the IN-
VITE sent to subsequent targets, or empty (e.type == PJSIP_EVENT_UNKNOWN)
if this callback is called from within Call::processRedirect() context.
struct pj::OnCallMediaEventParam
#include <call.hpp>
struct pj::OnCallMediaTransportStateParam
#include <call.hpp>
http://slidepdf.com/reader/full/pjsua2doc 121/271
8/10/2019 PJSUA2Doc
pjsua_med_tp_st state
The media transport state.
pj_status_t status
The last error code related to the media transport state.
int sipErrorCode
Optional SIP error code.
struct pj::OnCreateMediaTransportParam
#include <call.hpp>
unsigned mediaIdx
The media index in the SDP for which this media transport will be used.
MediaTransport mediaTp
The media transport which otherwise will be used by the call has this callback not
been implemented.
Application can change this to its own instance of media transport to be used by the
call.
unsigned flags
Bitmask from pjsua_create_media_transport_flag.
struct pj::CallOpParam
#include <call.hpp>
http://slidepdf.com/reader/full/pjsua2doc 122/271
8/10/2019 PJSUA2Doc
pjsip_status_code statusCode
Status code.
string reason
Reason phrase.
unsigned options
Options.
SipTxOption txOption
struct pj::CallSendRequestParam
#include <call.hpp>
string method
SIP method of the request.
SipTxOption txOption
struct pj::CallVidSetStreamParam
#include <call.hpp>
Public Members
int medIdx
Specify the media stream index.
This can be set to -1 to denote the default video stream in the call, which is the first
active video stream or any first video stream if none is active.
This field is valid for all video stream operations, except PJ-
SUA_CALL_VID_STRM_ADD.
http://slidepdf.com/reader/full/pjsua2doc 123/271
8/10/2019 PJSUA2Doc
Default: -1 (first active video stream, or any first video stream if none is active)
pjmedia_dir dir
Specify the media stream direction.
This field is valid for the following video stream operations: PJ-
SUA_CALL_VID_STRM_ADD and PJSUA_CALL_VID_STRM_CHANGE_DIR.
Default: PJMEDIA_DIR_ENCODING_DECODING
pjmedia_vid_dev_index capDev
Specify the video capture device ID.
This can be set to PJMEDIA_VID_DEFAULT_CAPTURE_DEV to specify the de-
fault capture device as configured in the account.
This field is valid for the following video stream op-
erations: PJSUA_CALL_VID_STRM_ADD and PJ-
SUA_CALL_VID_STRM_CHANGE_CAP_DEV.
Default: PJMEDIA_VID_DEFAULT_CAPTURE_DEV.
7.9.5 Other
struct pj::MediaEvent
#include <call.hpp>
http://slidepdf.com/reader/full/pjsua2doc 124/271
8/10/2019 PJSUA2Doc
struct pj::MediaFmtChangedEvent
#include <call.hpp>
unsigned newWidth
The new width.
unsigned newHeight
The new height.
struct pj::SdpSession
#include <call.hpp>
struct pj::RtcpSdes
#include <call.hpp>
http://slidepdf.com/reader/full/pjsua2doc 125/271
8/10/2019 PJSUA2Doc
http://slidepdf.com/reader/full/pjsua2doc 126/271
8/10/2019 PJSUA2Doc
CHAPTER
EIGHT
BUDDY (PRESENCE)
Presence feature in PJSUA2 centers around Buddy class. This class represents a remote buddy (a person, or a SIP
endpoint).
To use the Buddy class, normally application SHOULD create its own subclass, such as:
In its subclass, application can implement the buddy callback to get the notifications on buddy state change.
To subscribe to buddy’s presence status, you need to add a buddy object and subscribe to buddy’s presence status. The
snippet below shows a sample code to achieve these:
BuddyConfig cfg;
cfg.uri = "sip:alice@example.com";
MyBuddy buddy;
try {
buddy.create(*acc, cfg);
buddy.subscribePresence(true);
} catch(Error& err) {
}
Then you can get the buddy’s presence state change inside the onBuddyState() callback:
void MyBuddy::onBuddyState()
{
BuddyInfo bi = getInfo();
cout << "Buddy " << bi.uri << " i s " << bi.presStatus.statusText << endl;
}
123
http://slidepdf.com/reader/full/pjsua2doc 127/271
8/10/2019 PJSUA2Doc
By default, incoming presence subscription to an account will be accepted automatically. You will probably want to
change this behavior, for example only to automatically accept subscription if it comes from one of the buddy in the
buddy list, and for anything else prompt the user if he/she wants to accept the request.
This can be done by overriding the onIncomingSubscribe() method of the Account class. Please see the documentation
of this method for more info.
To change account’s presence status, you can use the function Account.setOnlineStatus() to set basic account’s pres-
ence status (i.e. available or not available) and optionally, some extended information (e.g. busy, away, on the phone,
etc), such as:
try {
PresenceStatus ps;
ps.status = PJSUA_BUDDY_STATUS_ONLINE;
// Optional, set the activity and some note
ps.activity = PJRPID_ACTIVITY_BUSY;
ps.note = "On the phone";
acc->setOnlineStatus(ps);
} catch(Error& err) {
}
When the presence status is changed, the account will publish the new status to all of its presence subscriber, either
with PUBLISH request or NOTIFY request, or both, depending on account configuration.
You can send IM using Buddy.sendInstantMessage(). The transmission status of outgoing instant messages is reported
in Account.onInstantMessageStatus() callback method of Account class.
In addition to sending instant messages, you can also send typing indication to remote buddy using
Buddy.sendTypingIndication().
Incoming IM and typing indication received not within the scope of a call will be reported in the callback functions
Account.onInstantMessage() and Account.onTypingIndication().
Alternatively, you can send IM and typing indication within a call by using Call.sendInstantMessage() and
Call.sendTypingIndication(). For more information, please see Call documentation.
8.6.1 Buddy
class pj::Buddy
Buddy.
Public Functions
http://slidepdf.com/reader/full/pjsua2doc 128/271
8/10/2019 PJSUA2Doc
Buddy()
Constructor.
~Buddy()
Destructor.
Note that if the Buddy instance is deleted, it will also delete the corresponding buddy
in the PJSUA-LIB.
bool isValid()
BuddyInfo getInfo()
void subscribePresence(bool subscribe)
void updatePresence(void)
http://slidepdf.com/reader/full/pjsua2doc 129/271
8/10/2019 PJSUA2Doc
Send instant messaging outside dialog, using this buddy’s specified account for route
set and authentication.
Parameters
void onBuddyState()
8.6.2 Status
struct pj::PresenceStatus
#include <presence.hpp>
Public Functions
PresenceStatus()
Constructor.
Public Members
pjsua_buddy_status status
Buddy‘s online status.
http://slidepdf.com/reader/full/pjsua2doc 130/271
8/10/2019 PJSUA2Doc
string statusText
Text to describe buddy’s online status.
pjrpid_activity activity
Activity type.
string note
Optional text describing the person/element.
string rpidId
Optional RPID ID string.
8.6.3 Info
struct pj::BuddyInfo
#include <presence.hpp>
This structure describes buddy info, which can be retrieved by via Buddy::getInfo().
Public Functions
void fromPj(const pjsua_buddy_info & pbi)
Import from pjsip structure.
Public Members
string uri
The full URI of the buddy, as specified in the configuration.
string contact
Buddy‘s Contact, only available when presence subscription has been established to
the buddy.
bool presMonitorEnabled
Flag to indicate that we should monitor the presence information for this buddy (nor-
mally yes, unless explicitly disabled).
pjsip_evsub_state subState
If presMonitorEnabled is true, this specifies the last state of the presence subscription.
If presence subscription session is currently active, the value will be
PJSIP_EVSUB_STATE_ACTIVE. If presence subscription request has been re-
jected, the value will be PJSIP_EVSUB_STATE_TERMINATED, and the termina-
tion reason will be specified in subTermReason.
string subStateName
String representation of subscription state.
pjsip_status_code subTermCode
Specifies the last presence subscription termination code.
This would return the last status of the SUBSCRIBE request. If the subscription is
terminated with NOTIFY by the server, this value will be set to 200, and subscription
termination reason will be given in the subTermReason field.
http://slidepdf.com/reader/full/pjsua2doc 131/271
8/10/2019 PJSUA2Doc
string subTermReason
Specifies the last presence subscription termination reason.
If presence subscription is currently active, the value will be empty.
PresenceStatus presStatus
Presence status.
8.6.4 Config
struct pj::BuddyConfig
#include <presence.hpp>
This structure describes buddy configuration when adding a buddy to the buddy list with Buddy::create().
Public Functions
void readObject(const ContainerNode & node)
void writeObject(ContainerNode & node)
Public Members
string uri
Buddy URL or name address.
bool subscribe
Specify whether presence subscription should start immediately.
http://slidepdf.com/reader/full/pjsua2doc 132/271
8/10/2019 PJSUA2Doc
CHAPTER
NINE
9.1.1 C++
This is a rather complete Python GUI sample apps, located in pjsip-apps/src/pygui. It requires Python 2.7
and above, and the Python SWIG module of course. To use the application, simply run:
python application.py
9.1.3 Android
9.1.4 Java
There is a Hello World type of application located in pjsip-apps/src/swig/java. This requires the Java
SWIG module. After building the SWIG module, run make test from this directory to run the app.
9.2 Miscellaneous
9.2.1 How to
129
http://slidepdf.com/reader/full/pjsua2doc 133/271
8/10/2019 PJSUA2Doc
http://slidepdf.com/reader/full/pjsua2doc 134/271
8/10/2019 PJSUA2Doc
CHAPTER
TEN
MEDIA QUALITY
If you experience any problem with the audio quality, you may want to try the steps below:
1. Follow the guide: Test the sound device using pjsystest.
2. Identify the sound problem and troubleshoot it using the steps described in: Checking for sound problems.
It is probably easier to do the testing using lower level API such as PJSUA since we already have a built-in pjsua
sample app located in pjsip-apps/bin to do the testing. However, you can also do the testing in your application using
PJSUA2 API such as local audio loopback, recording to WAV file as explained in the Media chapter previously.
2. Check local video preview using PJSUA API as described in Video Users Guide-Video Preview API.
3. Since video requires a larger bandwidth, we need to check for network impairments as described in Checking
Network Impairments. The document is for troubleshooting audio problem but it applies for video as well.
4. Check the CPU utilization. If the CPU utilization is too high, you can try a different (less CPU-intensive)
video codec or reduce the resolution/fps. A general guide on how to reduce CPU utilization can be found here:
FAQ-CPU utilization.
131
http://slidepdf.com/reader/full/pjsua2doc 135/271
8/10/2019 PJSUA2Doc
http://slidepdf.com/reader/full/pjsua2doc 136/271
8/10/2019 PJSUA2Doc
CHAPTER
ELEVEN
NETWORK PROBLEMS
Please see the wiki Handling IP Address Change. Note that the guide is written using PJSUA API as a reference.
133
http://slidepdf.com/reader/full/pjsua2doc 137/271
8/10/2019 PJSUA2Doc
http://slidepdf.com/reader/full/pjsua2doc 138/271
8/10/2019 PJSUA2Doc
CHAPTER
TWELVE
12.1 endpoint.hpp
135
http://slidepdf.com/reader/full/pjsua2doc 139/271
8/10/2019 PJSUA2Doc
Token userData
Arbitrary user data that was passed to Endpoint::utilTimerSchedule() func-
tion.
unsigned msecDelay
The interval of this timer, in miliseconds.
class OnTransportStateParam
Parameter of Endpoint::onTransportState() callback.
Public Members
TransportHandle hnd
UaConfig()
Default constructor to initialize with default values.
http://slidepdf.com/reader/full/pjsua2doc 140/271
8/10/2019 PJSUA2Doc
pjsua_config toPj()
Export to pjsua_config.
void writeObject(ContainerNode & node)
unsigned maxCalls
Maximum calls to support (default: 4).
The value specified here must be smaller than the compile time maximum
settings PJSUA_MAX_CALLS, which by default is 32. To increase this
limit, the library must be recompiled with new PJSUA_MAX_CALLS value.
unsigned threadCnt
Number of worker threads.
Normally application will want to have at least one worker thread, unless
when it wants to poll the library periodically, which in this case the worker
thread can be set to zero.
bool mainThreadOnly
When this flag is non-zero, all callbacks that come from thread other than
main thread will be posted to the main thread and to be executed by End-
point::libHandleEvents() function.
This includes the logging callback. Note that this will only work if thread-
Cnt is set to zero and Endpoint::libHandleEvents() is performed by main
thread. By default, the main thread is set from the thread that invoke End-
point::libCreate()
Default: false
StringVector nameserver
http://slidepdf.com/reader/full/pjsua2doc 141/271
8/10/2019 PJSUA2Doc
int natTypeInSdp
Support for adding and parsing NAT type in the SDP to assist troubleshoot-
ing.
The valid values are:
Default: 1
bool mwiUnsolicitedEnabled
Handle unsolicited NOTIFY requests containing message waiting indication
(MWI) info.
Unsolicited MWI is incoming NOTIFY requests which are not requested by
client with SUBSCRIBE request.
If this is enabled, the library will respond 200/OK to the NOTIFY request
and forward the request to Endpoint::onMwiInfo() callback.
See also AccountMwiConfig.enabled .
Default: PJ_TRUE
class LogEntry
http://slidepdf.com/reader/full/pjsua2doc 142/271
8/10/2019 PJSUA2Doc
string msg
The log message.
long threadId
ID of current thread.
string threadName
The name of the thread that writes this log.
class LogWriter
Interface for writing log messages.
Applications can inherit this class and supply it in the LogConfig structure to implement custom
log writing facility.
Public Functions
~LogWriter()
Destructor.
LogConfig()
Default constructor initialises with default values.
pjsua_logging_config toPj()
Generate pjsua_logging_config.
http://slidepdf.com/reader/full/pjsua2doc 143/271
8/10/2019 PJSUA2Doc
Parameters
• node - Container to write values from.
void writeObject(ContainerNode & node)
Value 5 is reasonable.
unsigned consoleLevel
Verbosity level for console.
Value 4 is reasonable.
unsigned decor
Log decoration.
string filename
Optional log filename if app wishes the library to write to log file.
unsigned fileFlags
Additional flags to be given to pj_file_open() when opening the log file.
By default, the flag is PJ_O_WRONLY. Application may set
PJ_O_APPEND here so that logs are appended to existing file instead
of overwriting it.
Default is 0.
LogWriter * writer
class MediaConfig
This structure describes media configuration, which will be specified when calling Lib::init().
Public Functions
MediaConfig()
Default constructor initialises with default values.
http://slidepdf.com/reader/full/pjsua2doc 144/271
8/10/2019 PJSUA2Doc
pjsua_media_config toPj()
Export.
void writeObject(ContainerNode & node)
unsigned clockRate
Clock rate to be applied to the conference bridge.
If value is zero, default clock rate will be used (PJ-
SUA_DEFAULT_CLOCK_RATE, which by default is 16KHz).
unsigned sndClockRate
Clock rate to be applied when opening the sound device.
If value is zero, conference bridge clock rate will be used.
unsigned channelCount
Channel count be applied when opening the sound device and conference
bridge.
unsigned audioFramePtime
Specify audio frame ptime.
The value here will affect the samples per frame of both the sound device
and the conference bridge. Specifying lower ptime will normally reduce the
latency.
Default value: PJSUA_DEFAULT_AUDIO_FRAME_PTIME
unsigned maxMediaPorts
http://slidepdf.com/reader/full/pjsua2doc 145/271
8/10/2019 PJSUA2Doc
http://slidepdf.com/reader/full/pjsua2doc 146/271
8/10/2019 PJSUA2Doc
bool vidPreviewEnableNative
Specify whether built-in/native preview should be used if available.
In some systems, video input devices have built-in capability to show pre-
view window of the device. Using this built-in preview is preferable as it
consumes less CPU power. If built-in preview is not available, the library
will perform software rendering of the input. If this field is set to PJ_FALSE,
software preview will always be used.
Default: PJ_TRUE
http://slidepdf.com/reader/full/pjsua2doc 147/271
8/10/2019 PJSUA2Doc
class EpConfig
Endpoint configuration.
Public Functions
void readObject(const ContainerNode & node)
void writeObject(ContainerNode & node)
Public Members
UaConfig uaConfig
UA config.
LogConfig logConfig
Logging config.
MediaConfig medConfig
Media config.
class PendingJob
Public Functions
void execute(bool is_pending)
Perform the job.
~PendingJob()
Virtual destructor.
class Endpoint
~Endpoint()
http://slidepdf.com/reader/full/pjsua2doc 148/271
8/10/2019 PJSUA2Doc
Virtual destructor.
Version libVersion()
void libCreate()
pjsua_state libGetState()
void libStart()
Call this function after all initialization is done, so that the library can do
additional checking set up.
Application may call this function any time after init().
http://slidepdf.com/reader/full/pjsua2doc 149/271
8/10/2019 PJSUA2Doc
void libStopWorkerThreads()
int libHandleEvents(unsigned msec_timeout)
Poll pjsua for events, and if necessary block the caller thread for the specified
maximum interval (in miliseconds).
Application doesn’t normally need to call this function if it has configured
worker thread (thread_cnt field) in pjsua_config structure, because polling
then will be done by these worker threads instead.
If EpConfig::UaConfig::mainThreadOnly is enabled and this function is
called from the main thread (by default the main thread is thread that calls
libCreate() ), this function will also scan and run any pending jobs in the list.
Return
The number of events that have been handled during the poll. Negative
value indicates error, and application can retrieve the error as (status =
-return_value).
Parameters
• msec_timeout - Maximum time to wait, in miliseconds.
void libDestroy(unsigned prmFlags = 0)
Destroy pjsua.
Application is recommended to perform graceful shutdown before calling
this function (such as unregister the account from the SIP server, terminate
presense subscription, and hangup active calls), however, this function will
do all of these if it finds there are active sessions that need to be terminated.
This function will block for few seconds to wait for replies from remote.
Application.may safely call this function more than once if it doesn’t keep
track of it’s state.
Parameters
• prmFlags - Combination of pjsua_destroy_flag enumeration.
void utilLogWrite(int prmLevel, const string & prmSender, const string & prmMsg)
http://slidepdf.com/reader/full/pjsua2doc 150/271
8/10/2019 PJSUA2Doc
void utilLogWrite( LogEntry & e)
Parameters
• prmUri - The URL string.
pjsua_verify_sip_url()
Parameters
• prmUri - The URL string.
http://slidepdf.com/reader/full/pjsua2doc 151/271
8/10/2019 PJSUA2Doc
void utilTimerCancel(Token prmToken)
Parameters
• prmToken - The timer token, which was returned from previous util-
TimerSchedule() call.
IntVector utilSslGetAvailableCiphers()
void natDetectType(void)
http://slidepdf.com/reader/full/pjsua2doc 152/271
8/10/2019 PJSUA2Doc
pj_stun_nat_type natGetType()
Auxiliary function to resolve and contact each of the STUN server entries
(sequentially) to find which is usable.
The libInit() must have been called before calling this function.
See
natCancelCheckStunServers()
Parameters
• prmServers - Array of STUN servers to try. The endpoint will try to
resolve and contact each of the STUN server entry until it finds one that
is usable. Each entry may be a domain name, host name, IP address,
and it may contain an optional port number. For example:
• prmWait - Specify if the function should block until it gets the result.
In this case, the function will block while the resolution is being done,
and the callback will be called before this function returns.
http://slidepdf.com/reader/full/pjsua2doc 153/271
8/10/2019 PJSUA2Doc
Create and start a new SIP transport according to the specified settings.
Return
The transport ID.
Parameters
IntVector transportEnum()
TransportInfo transportGetInfo(TransportId id)
void transportClose(TransportId id)
http://slidepdf.com/reader/full/pjsua2doc 154/271
8/10/2019 PJSUA2Doc
The system will wait until all transactions are closed while preventing new
users from using the transport, and will close the transport when its usage
count reaches zero.
Parameters
• id - Transport ID.
void hangupAllCalls(void)
Parameters
• media - media to be added.
void mediaRemove( AudioMedia & media)
unsigned mediaMaxPorts()
unsigned mediaActivePorts()
http://slidepdf.com/reader/full/pjsua2doc 155/271
8/10/2019 PJSUA2Doc
const AudioMediaVector & mediaEnumPorts()
AudDevManager & audDevManager()
const CodecInfoVector & codecEnum()
http://slidepdf.com/reader/full/pjsua2doc 156/271
8/10/2019 PJSUA2Doc
Callback when the Endpoint has finished performing NAT type detection that
is initiated with natDetectType().
Parameters
• prm - Callback parameters containing the detection result.
void onNatCheckStunServersComplete(const
OnNatCheckStunServersCompleteParam & prm)
void onTimer(const OnTimerParam & prm)
http://slidepdf.com/reader/full/pjsua2doc 157/271
8/10/2019 PJSUA2Doc
void performPendingJobs()
void clearCodecInfoList()
Private Members
LogWriter * writer
AudioMediaVector mediaList
AudDevManager audioDevMgr
CodecInfoVector codecInfoList
bool mainThreadOnly
void * mainThread
unsigned pendingJobSize
std::list< PendingJob * > pendingJobs
http://slidepdf.com/reader/full/pjsua2doc 158/271
8/10/2019 PJSUA2Doc
http://slidepdf.com/reader/full/pjsua2doc 159/271
8/10/2019 PJSUA2Doc
void on_buddy_state(pjsua_buddy_id buddy_id)
void on_call_media_state(pjsua_call_id call_id)
http://slidepdf.com/reader/full/pjsua2doc 160/271
8/10/2019 PJSUA2Doc
http://slidepdf.com/reader/full/pjsua2doc 161/271
8/10/2019 PJSUA2Doc
Endpoint * instance_
12.2 account.hpp
http://slidepdf.com/reader/full/pjsua2doc 162/271
8/10/2019 PJSUA2Doc
class AccountRegConfig
Account registration config.
This will be specified in AccountConfig.
Public Functions
void writeObject(ContainerNode & node)
string registrarUri
This is the URL to be put in the request URI for the registration, and will
look something like “sip:serviceprovider”.
unsigned timeoutSec
Optional interval for registration, in seconds.
If the value is zero, default interval will be used (PJSUA_REG_INTERVAL,
300 seconds).
unsigned retryIntervalSec
http://slidepdf.com/reader/full/pjsua2doc 163/271
8/10/2019 PJSUA2Doc
http://slidepdf.com/reader/full/pjsua2doc 164/271
8/10/2019 PJSUA2Doc
void writeObject(ContainerNode & node)
AuthCredInfoVector authCreds
Array of credentials.
If registration is desired, normally there should be at least one credential
specified, to successfully authenticate against the service provider. More
credentials can be specified, for example when the requests are expected to
be challenged by the proxies in the route set.
StringVector proxies
Array of proxy servers to visit for outgoing requests.
Each of the entry is translated into one Route URI.
string contactForced
Optional URI to be put as Contact for this account.
It is recommended that this field is left empty, so that the value will be cal-
culated automatically based on the transport address.
string contactParams
Additional parameters that will be appended in the Contact header for this
account.
This will affect the Contact header in all SIP messages sent on behalf of this
account, including but not limited to REGISTER, INVITE, and SUBCRIBE
requests or responses.
The parameters should be preceeded by semicolon, and all strings must be
properly escaped. Example: ”;my-param=X;another-param=Hi%20there”
string contactUriParams
Additional URI parameters that will be appended in the Contact URI for this
account.
This will affect the Contact URI in all SIP messages sent on behalf of this
account, including but not limited to REGISTER, INVITE, and SUBCRIBE
requests or responses.
The parameters should be preceeded by semicolon, and all strings must be
properly escaped. Example: ”;my-param=X;another-param=Hi%20there”
bool authInitialEmpty
http://slidepdf.com/reader/full/pjsua2doc 165/271
8/10/2019 PJSUA2Doc
If this flag is set, the authentication client framework will send an empty
Authorization header in each initial request.
Default is no.
string authInitialAlgorithm
Specify the algorithm to use when empty Authorization header is to be sent
for each initial request (see above)
TransportId transportId
void writeObject(ContainerNode & node)
http://slidepdf.com/reader/full/pjsua2doc 166/271
8/10/2019 PJSUA2Doc
Default: PJSUA_100REL_NOT_USED
pjsua_sip_timer_use timerUse
Specify the usage of Session Timers for all sessions.
See the pjsua_sip_timer_use for possible values.
Default: PJSUA_SIP_TIMER_OPTIONAL
unsigned timerMinSESec
Specify minimum Session Timer expiration period, in seconds.
Must not be lower than 90. Default is 90.
unsigned timerSessExpiresSec
Specify Session Timer expiration period, in seconds.
Must not be lower than timerMinSE. Default is 1800.
class AccountPresConfig
Account presence config.
This will be specified in AccountConfig.
Public Functions
void writeObject(ContainerNode & node)
The optional custom SIP headers to be put in the presence subscription re-
quest.
bool publishEnabled
If this flag is set, the presence information of this account will be PUBLISH-
ed to the server where the account belongs.
Default: PJ_FALSE
bool publishQueue
Specify whether the client publication session should queue the PUBLISH
request should there be another PUBLISH transaction still pending.
If this is set to false, the client will return error on the PUBLISH request if
there is another PUBLISH transaction still in progress.
http://slidepdf.com/reader/full/pjsua2doc 167/271
8/10/2019 PJSUA2Doc
void writeObject(ContainerNode & node)
bool enabled
Subscribe to message waiting indication events (RFC 3842).
See also UaConfig.mwiUnsolicitedEnabled setting.
Default: FALSE
unsigned expirationSec
Specify the default expiration time (in seconds) for Message Waiting Indica-
tion (RFC 3842) event subscription.
This must not be zero.
Default: PJSIP_MWI_DEFAULT_EXPIRES (3600)
http://slidepdf.com/reader/full/pjsua2doc 168/271
8/10/2019 PJSUA2Doc
class AccountNatConfig
void writeObject(ContainerNode & node)
pjsua_stun_use sipStunUse
Control the use of STUN for the SIP signaling.
Default: PJSUA_STUN_USE_DEFAULT
pjsua_stun_use mediaStunUse
Control the use of STUN for the media transports.
Default: PJSUA_STUN_USE_DEFAULT
bool iceEnabled
Enable ICE for the media transport.
Default: False
int iceMaxHostCands
Set the maximum number of ICE host candidates.
Default: -1 (maximum not set)
bool iceAggressiveNomination
Specify whether to use aggressive nomination.
Default: True
unsigned iceNominatedCheckDelayMsec
For controlling agent if it uses regular nomination, specify the delay to
perform nominated check (connectivity check with USE-CANDIDATE at-
tribute) after all components have a valid pair.
Default value is PJ_ICE_NOMINATED_CHECK_DELAY.
int iceWaitNominationTimeoutMsec
http://slidepdf.com/reader/full/pjsua2doc 169/271
8/10/2019 PJSUA2Doc
For a controlled agent, specify how long it wants to wait (in milliseconds) for
the controlling agent to complete sending connectivity check with nominated
flag set to true for all components after the controlled agent has found that
all connectivity checks in its checklist have been completed and there is at
least one successful (but not nominated) check for every component.
Default value for this option is ICE_CONTROLLED_AGENT_WAIT_NOMINATION_TIMEOUT.
Specify -1 to disable this timer.
bool iceNoRtcp
Disable RTCP component.
Default: False
bool iceAlwaysUpdate
Always send re-INVITE/UPDATE after ICE negotiation regardless of
whether the default ICE transport address is changed or not.
When this is set to False, re-INVITE/UPDATE will be sent only when the
default ICE transport address is changed.
Default: yes
bool turnEnabled
Enable TURN candidate in ICE.
string turnServer
Specify TURN domain name or host name, in in “DOMAIN:PORT” or
“HOST:PORT” format.
pj_turn_tp_type turnConnType
Specify the connection type to be used to the TURN server.
Valid values are PJ_TURN_TP_UDP or PJ_TURN_TP_TCP.
Default: PJ_TURN_TP_UDP
string turnUserName
Specify the username to authenticate with the TURN server.
int turnPasswordType
Specify the type of password.
Currently this must be zero to indicate plain-text password will be used in
the password.
string turnPassword
Specify the password to authenticate with the TURN server.
int contactRewriteUse
This option is used to update the transport address and the Contact header of
REGISTER request.
When this option is enabled, the library will keep track of the public IP ad-
dress from the response of REGISTER request. Once it detects that the ad-
dress has changed, it will unregister current Contact, update the Contact with
transport address learned from Via header, and register a new Contact to the
http://slidepdf.com/reader/full/pjsua2doc 170/271
8/10/2019 PJSUA2Doc
registrar. This will also update the public name of UDP transport if STUN is
configured.
See also contactRewriteMethod field.
Default: TRUE
int contactRewriteMethod
Specify how Contact update will be done with the registration, if contac-
tRewriteEnabled is enabled.
be used. If TRUE, and when STUN and ICE are disabled, then the IP address
found in registration response will be used.
Default: PJ_FALSE (no)
int sipOutboundUse
Control the use of SIP outbound feature.
SIP outbound is described in RFC 5626 to enable proxies or registrar to send
inbound requests back to UA using the same connection initiated by the UA
for its registration. This feature is highly useful in NAT-ed deployemtns,
hence it is enabled by default.
Note: currently SIP outbound can only be used with TCP and TLS transports.
If UDP is used for the registration, the SIP outbound feature will be silently
ignored for the account.
Default: TRUE
string sipOutboundInstanceId
Specify SIP outbound (RFC 5626) instance ID to be used by this account.
If empty, an instance ID will be generated based on the hostname of
this agent. If application specifies this parameter, the value will look
http://slidepdf.com/reader/full/pjsua2doc 171/271
8/10/2019 PJSUA2Doc
string udpKaData
Specify the data to be transmitted as keep-alive packets.
Default: CR-LF
class AccountMediaConfig
void writeObject(ContainerNode & node)
http://slidepdf.com/reader/full/pjsua2doc 172/271
8/10/2019 PJSUA2Doc
void writeObject(ContainerNode & node)
http://slidepdf.com/reader/full/pjsua2doc 173/271
8/10/2019 PJSUA2Doc
unsigned rateControlBandwidth
Upstream/outgoing bandwidth.
If this is set to zero, the video stream will use codec maximum bitrate setting.
Default: 0 (follow codec maximum bitrate).
class AccountConfig
http://slidepdf.com/reader/full/pjsua2doc 174/271
8/10/2019 PJSUA2Doc
Account configuration.
Public Functions
AccountConfig()
Default constructor will initialize with default values.
void writeObject(ContainerNode & node)
int priority
Account priority, which is used to control the order of matching incom-
ing/outgoing requests.
The higher the number means the higher the priority is, and the account will
be matched first.
string idUri
The Address of Record or AOR, that is full SIP URL that identifies the ac-
count.
The value can take name address or URL format, and will look something
like “sip:account@serviceprovider”.
This field is mandatory.
http://slidepdf.com/reader/full/pjsua2doc 175/271
8/10/2019 PJSUA2Doc
AccountRegConfig regConfig
Registration settings.
AccountSipConfig sipConfig
SIP settings.
AccountCallConfig callConfig
Call settings.
AccountPresConfig presConfig
Presence settings.
AccountMwiConfig mwiConfig
MWI (Message Waiting Indication) settings.
AccountNatConfig natConfig
NAT settings.
AccountMediaConfig mediaConfig
Media settings (applicable for both audio and video).
AccountVideoConfig videoConfig
Video settings.
class AccountInfo
Account information.
Application can query the account information by calling Account::getInfo().
Public Functions
void fromPj(const pjsua_acc_info & pai)
http://slidepdf.com/reader/full/pjsua2doc 176/271
8/10/2019 PJSUA2Doc
pjsip_status_code regStatus
Last registration status code.
If status code is zero, the account is currently not registered. Any other value
indicates the SIP status code of the registration.
string regStatusText
String describing the registration status.
pj_status_t regLastErr
Last registration error code.
When the status field contains a SIP status code that indicates a registration
failure, last registration error code contains the error code that causes the
failure. In any other case, its value is zero.
bool onlineStatus
Presence online status for this account.
string onlineStatusText
Presence online status text.
class OnIncomingCallParam
class OnRegStartedParam
This structure contains parameters for onRegStarted() account callback.
Public Members
bool renew
True for registration and False for unregistration.
class OnRegStateParam
http://slidepdf.com/reader/full/pjsua2doc 177/271
8/10/2019 PJSUA2Doc
class OnInstantMessageParam
Parameters for onInstantMessage() account callback.
Public Members
string fromUri
Sender From URI.
string toUri
To URI of the request.
string contactUri
Contact URI of the sender.
string contentType
MIME type of the message body.
string msgBody
The message body.
SipRxData rdata
The whole message.
http://slidepdf.com/reader/full/pjsua2doc 178/271
8/10/2019 PJSUA2Doc
class OnInstantMessageStatusParam
Parameters for onInstantMessageStatus() account callback.
Public Members
Token userData
Token or a user data that was associated with the pager transmission.
string toUri
Destination URI.
string msgBody
The message body.
pjsip_status_code code
The SIP status code of the transaction.
string reason
The reason phrase of the transaction.
SipRxData rdata
The incoming response that causes this callback to be called.
If the transaction fails because of time out or transport error, the content will
be empty.
class OnTypingIndicationParam
Parameters for onTypingIndication() account callback.
Public Members
string fromUri
Sender/From URI.
string toUri
To URI.
string contactUri
The Contact URI.
bool isTyping
Boolean to indicate if sender is typing.
SipRxData rdata
The whole message buffer.
class OnMwiInfoParam
Parameters for onMwiInfo() account callback.
Public Members
pjsip_evsub_state state
MWI subscription state.
SipRxData rdata
http://slidepdf.com/reader/full/pjsua2doc 179/271
8/10/2019 PJSUA2Doc
void * srvPres
Server presence subscription instance.
pjsip_evsub_state state
Server presence subscription state to set.
string stateStr
Optionally specify the state string name, if state is not “active”, “pending”,
or “terminated”.
string reason
If the new state is PJSIP_EVSUB_STATE_TERMINATED, optionally spec-
ify the termination reason.
bool withBody
If the new state is PJSIP_EVSUB_STATE_TERMINATED, this specifies
whether the NOTIFY request should contain message body containing ac-
count’s presence information.
SipTxOption txOption
Optional list of headers to be sent with the NOTIFY request.
class FindBuddyMatch
Wrapper class for Buddy matching algo.
Default algo is a simple substring lookup of search-token in the Buddy URIs, with case sensi-
tive. Application can implement its own matching algo by overriding this class and specifying
its instance in Account::findBuddy().
Public Functions
bool match(const string & token, const Buddy & buddy)
Default algo implementation.
~FindBuddyMatch()
Destructor.
class Account
Account .
Public Functions
Account()
Constructor.
http://slidepdf.com/reader/full/pjsua2doc 180/271
8/10/2019 PJSUA2Doc
~Account()
Destructor.
Note that if the account is deleted, it will also delete the corresponding ac-
count in the PJSUA-LIB.
bool isValid()
void setDefault()
Set this as default account to be used when incoming and outgoing requests
don’t match any accounts.
Return
PJ_SUCCESS on success.
bool isDefault()
http://slidepdf.com/reader/full/pjsua2doc 181/271
8/10/2019 PJSUA2Doc
Return
True if this is the default account.
int getId()
AccountInfo getInfo()
void setRegistration(bool renew)
void setTransport(TransportId tp_id)
http://slidepdf.com/reader/full/pjsua2doc 182/271
8/10/2019 PJSUA2Doc
Parameters
• tp_id - The transport ID.
void presNotify(const PresNotifyParam & prm)
const BuddyVector & enumBuddies()
void addBuddy( Buddy * buddy)
void removeBuddy( Buddy * buddy)
http://slidepdf.com/reader/full/pjsua2doc 183/271
8/10/2019 PJSUA2Doc
void onRegState(OnRegStateParam & prm)
http://slidepdf.com/reader/full/pjsua2doc 184/271
8/10/2019 PJSUA2Doc
Account * lookup(int acc_id)
Get the Account class for the specified account Id.
Return
The Account instance or NULL if not found.
Parameters
• acc_id - The account ID to lookup
Private Members
pjsua_acc_id id
http://slidepdf.com/reader/full/pjsua2doc 185/271
8/10/2019 PJSUA2Doc
string tmpReason
BuddyVector buddyList
Friends
friend class Endpoint
12.3 media.hpp
This structure contains all the information needed to completely describe a media.
Public Members
pj_uint32_t id
The format id that specifies the audio sample or video pixel format.
http://slidepdf.com/reader/full/pjsua2doc 186/271
8/10/2019 PJSUA2Doc
pjmedia_format toPj()
Export to pjmedia_format.
Public Members
unsigned clockRate
Audio clock rate in samples or Hz.
unsigned channelCount
Number of channels.
unsigned frameTimeUsec
Frame interval, in microseconds.
unsigned bitsPerSample
Number of bits per sample.
pj_uint32_t avgBps
Average bitrate.
pj_uint32_t maxBps
Maximum bitrate.
class MediaFormatVideo
int fpsDenum
Frames per second denumerator.
pj_uint32_t avgBps
Average bitrate.
pj_uint32_t maxBps
Maximum bitrate.
http://slidepdf.com/reader/full/pjsua2doc 187/271
8/10/2019 PJSUA2Doc
class ConfPortInfo
This structure descibes information about a particular media port that has been registered into
the conference bridge.
Public Functions
int portId
Conference port number.
string name
Port name.
MediaFormatAudio format
Media audio format information.
float txLevelAdj
Tx level adjustment.
Value 1.0 means no adjustment, value 0 means the port is muted, value 2.0
means the level is amplified two times.
float rxLevelAdj
Rx level adjustment.
Value 1.0 means no adjustment, value 0 means the port is muted, value 2.0
means the level is amplified two times.
IntVector listeners
Array of listeners (in other words, ports where this port is transmitting to.
class Media
Media.
Public Functions
~Media()
Virtual destructor.
pjmedia_type getType()
Media(pjmedia_type med_type)
Constructor.
http://slidepdf.com/reader/full/pjsua2doc 188/271
8/10/2019 PJSUA2Doc
Private Members
pjmedia_type type
Media type.
class AudioMedia
Audio Media.
Public Functions
ConfPortInfo getPortInfo()
int getPortId()
void adjustRxLevel(float level)
Adjust the signal level to be transmitted from the bridge to this media port
by making it louder or quieter.
Parameters
• level - Signal level adjustment. Value 1.0 means no level adjustment,
while value 0 means to mute the port.
http://slidepdf.com/reader/full/pjsua2doc 189/271
8/10/2019 PJSUA2Doc
void adjustTxLevel(float level)
Adjust the signal level to be received from this media port (to the bridge) by
making it louder or quieter.
Parameters
• level - Signal level adjustment. Value 1.0 means no level adjustment,
while value 0 means to mute the port.
unsigned getRxLevel()
unsigned getTxLevel()
~AudioMedia()
Virtual Destructor.
AudioMedia * typecastFromMedia( Media * media)
AudioMedia()
Default Constructor.
http://slidepdf.com/reader/full/pjsua2doc 190/271
8/10/2019 PJSUA2Doc
void registerMediaPort( MediaPort port)
void unregisterMediaPort()
Private Members
pj_caching_pool mediaCachingPool
pj_pool_t * mediaPool
class AudioMediaPlayer
Audio Media Player.
Public Functions
AudioMediaPlayer()
Constructor.
Create a file player, and automatically add this player to the conference
bridge.
Parameters
• file_name - The filename to be played. Currently only WAV files
are supported, and the WAV file MUST be formatted as 16bit PCM
mono/single channel (any clock rate is supported).
• options - Optional option flag. Application may specify PJME-
DIA_FILE_NO_LOOP to prevent playback loop.
http://slidepdf.com/reader/full/pjsua2doc 191/271
8/10/2019 PJSUA2Doc
Create a file playlist media port, and automatically add the port to the con-
ference bridge.
Parameters
• file_names - Array of file names to be added to the play list. Note
that the files must have the same clock rate, number of channels, and
number of bits per sample.
• label - Optional label to be set for the media port.
• options - Optional option flag. Application may specify PJME-
DIA_FILE_NO_LOOP to prevent looping.
void setPos(pj_uint32_t samples)
~AudioMediaPlayer()
Virtual destructor.
Public Static Functions
Audio Media Recorder.
Public Functions
AudioMediaRecorder()
http://slidepdf.com/reader/full/pjsua2doc 192/271
8/10/2019 PJSUA2Doc
Constructor.
Create a file recorder, and automatically connect this recorder to the confer-
ence bridge.
The recorder currently supports recording WAV file. The type of the recorder
to use is determined by the extension of the file (e.g. ”.wav”).
Parameters
• file_name - Output file name. The function will determine the de-
fault format to be used based on the file extension. Currently ”.wav” is
supported on all platforms.
• enc_type - Optionally specify the type of encoder to be used to com-
press the media, if the file can support different encodings. This value
must be zero for now.
• max_size - Maximum file size. Specify zero or -1 to remove size
limitation. This value must be zero or -1 for now.
• options - Optional options, which can be used to spec-
ify the recording file format. Supported options are PJME-
DIA_FILE_WRITE_PCM, PJMEDIA_FILE_WRITE_ALAW,
and PJMEDIA_FILE_WRITE_ULAW. Default is zero or PJME-
DIA_FILE_WRITE_PCM.
~AudioMediaRecorder()
Virtual destructor.
Public Static Functions
http://slidepdf.com/reader/full/pjsua2doc 193/271
8/10/2019 PJSUA2Doc
~AudioDevInfo()
Destructor.
Public Members
string name
The device name.
unsigned inputCount
Maximum number of input channels supported by this device.
If the value is zero, the device does not support input operation (i.e. it is a
playback only device).
unsigned outputCount
Maximum number of output channels supported by this device.
If the value is zero, the device does not support output operation (i.e. it is an
input only device).
unsigned defaultSamplesPerSec
Default sampling rate.
string driver
class AudDevManager
Audio device manager.
Public Functions
int getCaptureDev()
Get currently active capture sound devices.
If sound devices has not been created, it is possible that the function returns
-1 as device IDs.
http://slidepdf.com/reader/full/pjsua2doc 194/271
8/10/2019 PJSUA2Doc
Return
Device ID of the capture device.
AudioMedia & getCaptureDevMedia()
int getPlaybackDev()
AudioMedia & getPlaybackDevMedia()
void setCaptureDev(int capture_dev)
void setPlaybackDev(int playback_dev)
http://slidepdf.com/reader/full/pjsua2doc 195/271
8/10/2019 PJSUA2Doc
const AudioDevInfoVector & enumDev()
void setNullDev()
MediaPort * setNoDev()
Disconnect the main conference bridge from any sound devices, and let ap-
plication connect the bridge to it’s own sound device/master port.
Return
The port interface of the conference bridge, so that application can connect
this to it’s own sound device or master port.
unsigned getEcTail()
http://slidepdf.com/reader/full/pjsua2doc 196/271
8/10/2019 PJSUA2Doc
bool sndIsActive()
void refreshDevs()
unsigned getDevCount()
http://slidepdf.com/reader/full/pjsua2doc 197/271
8/10/2019 PJSUA2Doc
Return
The device ID. If the device is not found, Error will be thrown.
Parameters
• drv_name - The driver name.
string capName(pjmedia_aud_dev_cap cap)
This will configure audio format capability (other than PCM) to the sound
device being used.
If sound device is currently active, the method will forward the setting to the
sound device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_EXT_FORMAT capability in AudioDevInfo.caps
flags, otherwise Error will be thrown.
Note that in case the setting is kept for future use, it will be applied to any
devices, even when application has changed the sound device to be used.
Parameters
• format - The audio format.
• keep - Specify whether the setting is to be kept for future use.
MediaFormatAudio getExtFormat()
Get the audio format capability (other than PCM) of the sound device being
used.
If sound device is currently active, the method will forward the request to the
sound device. If sound device is currently inactive, and if application had
previously set the setting and mark the setting as kept, then that setting will
be returned. Otherwise, this method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_EXT_FORMAT capability in AudioDevInfo.caps
flags, otherwise Error will be thrown.
http://slidepdf.com/reader/full/pjsua2doc 198/271
8/10/2019 PJSUA2Doc
Return
The audio format.
This will configure audio input latency control or query capability to the
sound device being used.
If sound device is currently active, the method will forward the setting to the
sound device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_INPUT_LATENCY capability in AudioDev-
Info.caps flags, otherwise Error will be thrown.
Note that in case the setting is kept for future use, it will be applied to any
devices, even when application has changed the sound device to be used.
Parameters
• latency_msec - The input latency.
• keep - Specify whether the setting is to be kept for future use.
unsigned getInputLatency()
Get the audio input latency control or query capability of the sound device
being used.
If sound device is currently active, the method will forward the request to the
sound device. If sound device is currently inactive, and if application had
previously set the setting and mark the setting as kept, then that setting will
be returned. Otherwise, this method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_INPUT_LATENCY capability in AudioDev-
Info.caps flags, otherwise Error will be thrown.
Return
The audio input latency.
This will configure audio output latency control or query capability to the
sound device being used.
If sound device is currently active, the method will forward the setting to the
sound device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_OUTPUT_LATENCY capability in AudioDev-
Info.caps flags, otherwise Error will be thrown.
http://slidepdf.com/reader/full/pjsua2doc 199/271
8/10/2019 PJSUA2Doc
Note that in case the setting is kept for future use, it will be applied to any
devices, even when application has changed the sound device to be used.
Parameters
• latency_msec - The output latency.
• keep - Specify whether the setting is to be kept for future use.
unsigned getOutputLatency()
Get the audio output latency control or query capability of the sound device
being used.
If sound device is currently active, the method will forward the request to the
sound device. If sound device is currently inactive, and if application had
previously set the setting and mark the setting as kept, then that setting will
be returned. Otherwise, this method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_OUTPUT_LATENCY capability in AudioDev-
Info.caps flags, otherwise Error will be thrown.
Return
The audio output latency.
This will configure audio input volume level capability to the sound device
being used.
If sound device is currently active, the method will forward the setting to the
sound device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_INPUT_VOLUME_SETTING capability in
AudioDevInfo.caps flags, otherwise Error will be thrown.
Note that in case the setting is kept for future use, it will be applied to any
devices, even when application has changed the sound device to be used.
Parameters
• volume - The input volume level, in percent.
• keep - Specify whether the setting is to be kept for future use.
unsigned getInputVolume()
Get the audio input volume level capability of the sound device being used.
If sound device is currently active, the method will forward the request to the
sound device. If sound device is currently inactive, and if application had
previously set the setting and mark the setting as kept, then that setting will
be returned. Otherwise, this method will raise error.
http://slidepdf.com/reader/full/pjsua2doc 200/271
8/10/2019 PJSUA2Doc
Return
The audio input volume level, in percent.
This will configure audio output volume level capability to the sound device
being used.
If sound device is currently active, the method will forward the setting to the
sound device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING capability in
AudioDevInfo.caps flags, otherwise Error will be thrown.
Note that in case the setting is kept for future use, it will be applied to any
devices, even when application has changed the sound device to be used.
Parameters
• volume - The output volume level, in percent.
• keep - Specify whether the setting is to be kept for future use.
unsigned getOutputVolume()
Get the audio output volume level capability of the sound device being used.
If sound device is currently active, the method will forward the request to the
sound device. If sound device is currently inactive, and if application had
previously set the setting and mark the setting as kept, then that setting will
be returned. Otherwise, this method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_OUTPUT_VOLUME_SETTING capability in
AudioDevInfo.caps flags, otherwise Error will be thrown.
Return
The audio output volume level, in percent.
unsigned getInputSignal()
Get the audio input signal level capability of the sound device being used.
If sound device is currently active, the method will forward the request to the
sound device. If sound device is currently inactive, and if application had
previously set the setting and mark the setting as kept, then that setting will
be returned. Otherwise, this method will raise error.
http://slidepdf.com/reader/full/pjsua2doc 201/271
8/10/2019 PJSUA2Doc
Return
The audio input signal level, in percent.
unsigned getOutputSignal()
Get the audio output signal level capability of the sound device being used.
If sound device is currently active, the method will forward the request to the
sound device. If sound device is currently inactive, and if application had
previously set the setting and mark the setting as kept, then that setting will
be returned. Otherwise, this method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_OUTPUT_SIGNAL_METER capability in
AudioDevInfo.caps flags, otherwise Error will be thrown.
Return
The audio output signal level, in percent.
This will configure audio input route capability to the sound device being
used.
If sound device is currently active, the method will forward the setting to the
sound device instance to be applied immediately, if it supports it.
pjmedia_aud_dev_route getInputRoute()
Get the audio input route capability of the sound device being used.
If sound device is currently active, the method will forward the request to the
sound device. If sound device is currently inactive, and if application had
previously set the setting and mark the setting as kept, then that setting will
be returned. Otherwise, this method will raise error.
http://slidepdf.com/reader/full/pjsua2doc 202/271
8/10/2019 PJSUA2Doc
This will configure audio output route capability to the sound device being
used.
If sound device is currently active, the method will forward the setting to the
sound device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_OUTPUT_ROUTE capability in AudioDev-
Info.caps flags, otherwise Error will be thrown.
Note that in case the setting is kept for future use, it will be applied to any
devices, even when application has changed the sound device to be used.
Parameters
• route - The audio output route.
• keep - Specify whether the setting is to be kept for future use.
pjmedia_aud_dev_route getOutputRoute()
Get the audio output route capability of the sound device being used.
If sound device is currently active, the method will forward the request to the
sound device. If sound device is currently inactive, and if application had
previously set the setting and mark the setting as kept, then that setting will
be returned. Otherwise, this method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_OUTPUT_ROUTE capability in AudioDev-
Info.caps flags, otherwise Error will be thrown.
Return
The audio output route.
This will configure audio voice activity detection capability to the sound
device being used.
If sound device is currently active, the method will forward the setting to the
sound device instance to be applied immediately, if it supports it.
http://slidepdf.com/reader/full/pjsua2doc 203/271
8/10/2019 PJSUA2Doc
Parameters
• enable - Enable/disable voice activity detection feature. Set true to
enable.
• keep - Specify whether the setting is to be kept for future use.
bool getVad()
Get the audio voice activity detection capability of the sound device being
used.
If sound device is currently active, the method will forward the request to the
sound device. If sound device is currently inactive, and if application had
previously set the setting and mark the setting as kept, then that setting will
be returned. Otherwise, this method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_VAD capability in AudioDevInfo.caps flags,
otherwise Error will be thrown.
Return
The audio voice activity detection feature.
This will configure audio comfort noise generation capability to the sound
device being used.
If sound device is currently active, the method will forward the setting to the
sound device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_CNG capability in AudioDevInfo.caps flags,
otherwise Error will be thrown.
Note that in case the setting is kept for future use, it will be applied to any
devices, even when application has changed the sound device to be used.
Parameters
• enable - Enable/disable comfort noise generation feature. Set true to
enable.
• keep - Specify whether the setting is to be kept for future use.
bool getCng()
http://slidepdf.com/reader/full/pjsua2doc 204/271
8/10/2019 PJSUA2Doc
Get the audio comfort noise generation capability of the sound device being
used.
If sound device is currently active, the method will forward the request to the
sound device. If sound device is currently inactive, and if application had
previously set the setting and mark the setting as kept, then that setting will
be returned. Otherwise, this method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_CNG capability in AudioDevInfo.caps flags,
otherwise Error will be thrown.
Return
The audio comfort noise generation feature.
This will configure audio packet loss concealment capability to the sound
device being used.
If sound device is currently active, the method will forward the setting to the
sound device instance to be applied immediately, if it supports it.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_PLC capability in AudioDevInfo.caps flags,
otherwise Error will be thrown.
Note that in case the setting is kept for future use, it will be applied to any
devices, even when application has changed the sound device to be used.
Parameters
• enable - Enable/disable packet loss concealment feature. Set true to
enable.
• keep - Specify whether the setting is to be kept for future use.
bool getPlc()
Get the audio packet loss concealment capability of the sound device being
used.
If sound device is currently active, the method will forward the request to the
sound device. If sound device is currently inactive, and if application had
previously set the setting and mark the setting as kept, then that setting will
be returned. Otherwise, this method will raise error.
This method is only valid if the device has PJME-
DIA_AUD_DEV_CAP_PLC capability in AudioDevInfo.caps flags,
otherwise Error will be thrown.
Return
The audio packet loss concealment feature.
Private Functions
AudDevManager()
http://slidepdf.com/reader/full/pjsua2doc 205/271
8/10/2019 PJSUA2Doc
Constructor.
~AudDevManager()
Destructor.
void clearAudioDevList()
int getActiveDev(bool is_capture)
Private Members
AudioDevInfoVector audioDevList
AudioMedia * devMedia
Friends
friend class Endpoint
class CodecInfo
http://slidepdf.com/reader/full/pjsua2doc 206/271
8/10/2019 PJSUA2Doc
12.4 call.hpp
int n
number of samples
int max
maximum value
int min
minimum value
int last
last value
int mean
mean
class RtcpStreamStat
http://slidepdf.com/reader/full/pjsua2doc 207/271
8/10/2019 PJSUA2Doc
Public Members
TimeVal update
Time of last update.
unsigned updateCount
Number of updates (to calculate avg)
unsigned pkt
Total number of packets.
unsigned bytes
Total number of payload/bytes.
unsigned discard
Total number of discarded packets.
unsigned loss
Total number of packets lost.
unsigned reorder
Total number of out of order packets.
unsigned dup
Total number of duplicates packets.
MathStat lossPeriodUsec
Loss period statistics.
unsigned burst
Burst/sequential packet lost detected.
unsigned random
Random packet lost detected.
struct pj::RtcpStreamStat::@0 lossType
Types of loss detected.
MathStat jitterUsec
Jitter statistics.
class RtcpSdes
RTCP SDES structure.
Public Functions
void fromPj(const pjmedia_rtcp_sdes & prm)
Convert from pjsip.
http://slidepdf.com/reader/full/pjsua2doc 208/271
8/10/2019 PJSUA2Doc
Public Members
string cname
RTCP SDES type CNAME.
string name
TimeVal start
Time when session was created.
RtcpStreamStat txStat
Encoder stream statistics.
RtcpStreamStat rxStat
Decoder stream statistics.
MathStat rttUsec
Round trip delay statistic.
pj_uint32_t rtpTxLastTs
Last TX RTP timestamp.
pj_uint16_t rtpTxLastSeq
Last TX RTP sequence.
MathStat rxIpdvUsec
Statistics of IP packet delay variation in receiving direction.
It is only used when PJMEDIA_RTCP_STAT_HAS_IPDV is set to non-zero.
http://slidepdf.com/reader/full/pjsua2doc 209/271
8/10/2019 PJSUA2Doc
MathStat rxRawJitterUsec
Statistic of raw jitter in receiving direction.
It is only used when PJMEDIA_RTCP_STAT_HAS_RAW_JITTER is set to
non-zero.
RtcpSdes peerSdes
Peer SDES.
class JbufState
unsigned devDelayMsec
Standard deviation of delay, in ms.
unsigned avgBurst
Average burst, in frames.
unsigned lost
Number of lost frames.
http://slidepdf.com/reader/full/pjsua2doc 210/271
8/10/2019 PJSUA2Doc
unsigned discard
Number of discarded frames.
unsigned empty
Number of empty on GET events.
class SdpSession
This structure describes SDP session description.
It corresponds to the pjmedia_sdp_session structure.
Public Functions
unsigned newWidth
The new width.
unsigned newHeight
The new height.
class MediaEvent
This structure describes a media event.
It corresponds to the pjmedia_event structure.
Public Functions
GenericData ptr
Pointer to storage to user event data, if it’s outside this struct.
http://slidepdf.com/reader/full/pjsua2doc 211/271
8/10/2019 PJSUA2Doc
union pj::MediaEvent::@1 data
Additional data/parameters about the event.
The type of data will be specific to the event type being reported.
void * pjMediaEvent
Public Functions
bool isEmpty()
pjsua_call_setting toPj()
Convert to pjsip.
Public Members
http://slidepdf.com/reader/full/pjsua2doc 212/271
8/10/2019 PJSUA2Doc
unsigned flag
Bitmask of pjsua_call_flag constants.
Default: PJSUA_CALL_INCLUDE_DISABLED_MEDIA
unsigned reqKeyframeMethod
This flag controls what methods to request keyframe are allowed on the call.
Value is bitmask of pjsua_vid_req_keyframe_method.
Default: PJSUA_VID_REQ_KEYFRAME_SIP_INFO | PJ-
SUA_VID_REQ_KEYFRAME_RTCP_PLI
unsigned audioCount
Number of simultaneous active audio streams for this call.
Setting this to zero will disable audio in this call.
Default: 1
unsigned videoCount
Call media information.
Public Functions
CallMediaInfo()
Default constructor.
int audioConfSlot
The conference port number for the call.
Only valid if the media type is audio.
http://slidepdf.com/reader/full/pjsua2doc 213/271
8/10/2019 PJSUA2Doc
pjsua_vid_win_id videoIncomingWindowId
The window id for incoming video, if any, or PJSUA_INVALID_ID.
Only valid if the media type is video.
pjmedia_vid_dev_index videoCapDev
Call information.
Application can query the call information by calling Call::getInfo().
Public Functions
void fromPj(const pjsua_call_info & pci)
Convert from pjsip.
Public Members
pjsua_call_id id
Call identification.
pjsip_role_e role
Initial call role (UAC == caller)
pjsua_acc_id accId
The account ID where this call belongs.
string localUri
Local URI.
string localContact
Local Contact.
string remoteUri
Remote URI.
string remoteContact
Remote contact.
string callIdString
Dialog Call-ID string.
CallSetting setting
Call setting.
pjsip_inv_state state
Call state.
string stateText
Text describing the state.
http://slidepdf.com/reader/full/pjsua2doc 214/271
8/10/2019 PJSUA2Doc
pjsip_status_code lastStatusCode
Last status code heard, which can be used as cause code.
string lastReason
The reason phrase describing the last status.
CallMediaInfoVector media
Array of active media information.
CallMediaInfoVector provMedia
Public Functions
void fromPj(const pjsua_stream_info & info)
Convert from pjsip.
Public Members
pjmedia_type type
Media type of this stream.
pjmedia_tp_proto proto
Transport protocol (RTP/AVP, etc.)
pjmedia_dir dir
Media direction.
SocketAddress remoteRtpAddress
Remote RTP address.
SocketAddress remoteRtcpAddress
Optional remote RTCP address.
http://slidepdf.com/reader/full/pjsua2doc 215/271
8/10/2019 PJSUA2Doc
unsigned txPt
Outgoing codec payload type.
unsigned rxPt
Incoming codec payload type.
string codecName
Codec name.
unsigned codecClockRate
Codec clock rate.
CodecParam codecParam
Optional codec param.
class StreamStat
Media stream statistic.
Public Functions
void fromPj(const pjsua_stream_stat & prm)
Convert from pjsip.
Public Members
RtcpStat rtcp
RTCP statistic.
JbufState jbuf
SipEvent e
Event which causes the call state to change.
class OnCallTsxStateParam
This structure contains parameters for Call::onCallTsxState() callback.
Public Members
SipEvent e
Transaction event that caused the state change.
class OnCallMediaStateParam
This structure contains parameters for Call::onCallMediaState() callback.
class OnCallSdpCreatedParam
SdpSession sdp
http://slidepdf.com/reader/full/pjsua2doc 216/271
8/10/2019 PJSUA2Doc
Media stream.
unsigned streamIdx
Stream index in the media session.
MediaPort pPort
On input, it specifies the media port of the stream.
Application may modify this pointer to point to different media port to be
registered to the conference bridge.
class OnStreamDestroyedParam
MediaStream stream
Media stream.
unsigned streamIdx
Stream index in the media session.
class OnDtmfDigitParam
http://slidepdf.com/reader/full/pjsua2doc 217/271
8/10/2019 PJSUA2Doc
class OnCallTransferStatusParam
This structure contains parameters for Call::onCallTransferStatus() callback.
Public Members
pjsip_status_code statusCode
class OnCallReplaceRequestParam
This structure contains parameters for Call::onCallReplaceRequest() callback.
Public Members
SipRxData rdata
SdpSession offer
The new offer received.
pjsip_status_code statusCode
http://slidepdf.com/reader/full/pjsua2doc 218/271
8/10/2019 PJSUA2Doc
The current call setting, application can update this setting for answering the
offer.
class OnCallRedirectedParam
string targetUri
The current target to be tried.
SipEvent e
The event that caused this callback to be called.
This could be the receipt of 3xx response, or 4xx/5xx response re-
ceived for the INVITE sent to subsequent targets, or empty (e.type
== PJSIP_EVENT_UNKNOWN) if this callback is called from within
Call::processRedirect() context.
class OnCallMediaEventParam
This structure contains parameters for Call::onCallMediaEvent() callback.
Public Members
unsigned medIdx
The media stream index.
MediaEvent ev
http://slidepdf.com/reader/full/pjsua2doc 219/271
8/10/2019 PJSUA2Doc
unsigned mediaIdx
The media index in the SDP for which this media transport will be used.
MediaTransport mediaTp
The media transport which otherwise will be used by the call has this call-
back not been implemented.
Application can change this to its own instance of media transport to be used
by the call.
unsigned flags
Bitmask from pjsua_create_media_transport_flag.
class CallOpParam
This structure contains parameters for Call::answer(), Call::hangup(), Call::reinvite(),
Call::update(), Call::xfer(), Call::xferReplaces(), Call::setHold().
Public Functions
CallSetting opt
The call setting.
pjsip_status_code statusCode
Status code.
string reason
Reason phrase.
unsigned options
Options.
SipTxOption txOption
List of headers etc to be added to outgoing response message.
Note that this message data will be persistent in all next answers/responses
for this INVITE request.
class CallSendRequestParam
This structure contains parameters for Call::sendRequest()
Public Functions
CallSendRequestParam()
Default constructor initializes with zero/empty values.
Public Members
string method
SIP method of the request.
http://slidepdf.com/reader/full/pjsua2doc 220/271
8/10/2019 PJSUA2Doc
SipTxOption txOption
Message body and/or list of headers etc to be included in outgoing request.
class CallVidSetStreamParam
This structure contains parameters for Call::vidSetStream()
Public Functions
CallVidSetStreamParam()
Default constructor.
Public Members
int medIdx
Specify the media stream index.
This can be set to -1 to denote the default video stream in the call, which is
the first active video stream or any first video stream if none is active.
This field is valid for all video stream operations, except PJ-
SUA_CALL_VID_STRM_ADD.
Default: -1 (first active video stream, or any first video stream if none is
active)
pjmedia_dir dir
Specify the media stream direction.
This field is valid for the following video stream op-
erations: PJSUA_CALL_VID_STRM_ADD and PJ-
SUA_CALL_VID_STRM_CHANGE_DIR.
Default: PJMEDIA_DIR_ENCODING_DECODING
pjmedia_vid_dev_index capDev
Call.
Public Functions
Call( Account & acc, int call_id = PJSUA_INVALID_ID)
Constructor.
~Call()
Destructor.
http://slidepdf.com/reader/full/pjsua2doc 221/271
8/10/2019 PJSUA2Doc
CallInfo getInfo()
bool isActive()
Check if this call has active INVITE session and the INVITE session has not
been disconnected.
Return
True if call is active.
int getId()
bool hasMedia()
True if yes.
Media * getMedia(unsigned med_idx)
http://slidepdf.com/reader/full/pjsua2doc 222/271
8/10/2019 PJSUA2Doc
Return
PJSIP_DIALOG_CAP_SUPPORTED if the specified capability is explic-
itly supported, see pjsip_dialog_cap_status for more info.
Parameters
• htype - The header type (pjsip_hdr_e) to be checked, which value may
be:
• hname - If htype specifies PJSIP_H_OTHER, then the header name
must be supplied in this argument. Otherwise the value must be set to
empty string (“”).
• token - The capability token to check. For example, if htype is
PJSIP_H_ALLOW, then token specifies the method names; if htype is
PJSIP_H_SUPPORTED, then token specifies the extension names such
as “100rel”.
void setUserData(Token user_data)
Token getUserData()
Get user data attached to the call, which has been previously set with se-
tUserData().
Return
The user data.
pj_stun_nat_type getRemNatType()
http://slidepdf.com/reader/full/pjsua2doc 223/271
8/10/2019 PJSUA2Doc
See
Endpoint::natGetType(), natTypeInSdp
Hangup call by using method that is appropriate according to the call state.
This function is different than answering the call with 3xx-6xx response
(with answer()), in that this function will hangup the call regardless of the
state and role of the call, while answer() only works with incoming calls on
EARLY state.
Parameters
• prm.statusCode - Optional status code to be sent when we’re re-
jecting incoming call. If the value is zero, “603/Decline” will be sent.
• prm.reason - Optional reason phrase to be sent when we’re rejecting
incoming call. If empty, default text will be used.
http://slidepdf.com/reader/full/pjsua2doc 224/271
8/10/2019 PJSUA2Doc
void update(const CallOpParam & prm)
http://slidepdf.com/reader/full/pjsua2doc 225/271
8/10/2019 PJSUA2Doc
Parameters
• dest_call - The call to be replaced.
• prm.options - Application may specify PJ-
SUA_XFER_NO_REQUIRE_REPLACES to suppress the inclusion
of “Require: replaces” in the outgoing INVITE request created by the
REFER request.
• prm.txOption - Optional message components to be sent with the
request.
http://slidepdf.com/reader/full/pjsua2doc 226/271
8/10/2019 PJSUA2Doc
http://slidepdf.com/reader/full/pjsua2doc 227/271
8/10/2019 PJSUA2Doc
Return
Call dump and media statistics string.
Parameters
• with_media - True to include media information too.
int vidGetStreamIdx()
Get the media stream index of the default video stream in the call.
Typically this will just retrieve the stream index of the first activated video
stream in the call. If none is active, it will return the first inactive video
stream.
Return
The media stream index or -1 if no video stream is present in the call.
Determine if video stream for the specified call is currently running (i.e.
has been created, started, and not being paused) for the specified direction.
Return
True if stream is currently running for the specified direction.
Parameters
• med_idx - Media stream index, or -1 to specify default video media.
• dir - The direction to be checked.
Add, remove, modify, and/or manipulate video media stream for the speci-
fied call.
This may trigger a re-INVITE or UPDATE to be sent for the call.
Parameters
http://slidepdf.com/reader/full/pjsua2doc 228/271
8/10/2019 PJSUA2Doc
Parameters
• prm - Callback parameter.
http://slidepdf.com/reader/full/pjsua2doc 229/271
8/10/2019 PJSUA2Doc
Notify application when a call has just created a local SDP (for initial or
subsequent SDP offer/answer).
Application can implement this callback to modify the SDP, before it is be-
ing sent and/or negotiated with remote SDP, for example to apply per ac-
count/call basis codecs priority or to add custom/proprietary SDP attributes.
Parameters
• prm - Callback parameter.
http://slidepdf.com/reader/full/pjsua2doc 230/271
8/10/2019 PJSUA2Doc
Notify application when media session has been unregistered from the con-
ference bridge and about to be destroyed.
Parameters
• prm - Callback parameter.
Application can monitor the status of the call transfer request, for example
to decide whether to terminate existing call.
Parameters
• prm - Callback parameter.
Notify application that an existing call has been replaced with a new call.
http://slidepdf.com/reader/full/pjsua2doc 231/271
8/10/2019 PJSUA2Doc
This happens when PJSUA-API receives incoming INVITE request with Re-
places header.
After this callback is called, normally PJSUA-API will disconnect this call
and establish a new call newCallId .
Parameters
• prm - Callback parameter.
Notify application when call has received new offer from remote (i.e.
re-INVITE/UPDATE with SDP is received). Application can decide to ac-
cept/reject the offer by setting the code (default is 200). If the offer is ac-
cepted, application can update the call setting to be applied in the answer.
When this callback is not implemented, the default behavior is to accept the
offer using current call setting.
Parameters
• prm - Callback parameter.
Parameters
• prm - Callback parameter.
This callback is called when the call is about to resend the INVITE request to
the specified target, following the previously received redirection response.
http://slidepdf.com/reader/full/pjsua2doc 232/271
8/10/2019 PJSUA2Doc
Application may accept the redirection to the specified target, reject this tar-
get only and make the session continue to try the next target in the list if such
target exists, stop the whole redirection process altogether and cause the ses-
sion to be disconnected, or defer the decision to ask for user confirmation.
This callback is optional, the default behavior is to NOT follow the redirec-
tion response.
Return
Action to be performed for the target. Set this parameter to one of the
value below:
Parameters
• prm - Callback parameter.
http://slidepdf.com/reader/full/pjsua2doc 233/271
8/10/2019 PJSUA2Doc
pjsua_call_id id
Token userData
12.5 presence.hpp
PresenceStatus()
Constructor.
Public Members
pjsua_buddy_status status
http://slidepdf.com/reader/full/pjsua2doc 234/271
8/10/2019 PJSUA2Doc
This structure describes buddy configuration when adding a buddy to the buddy list with
Buddy::create().
Public Functions
void writeObject(ContainerNode & node)
bool subscribe
Specify whether presence subscription should start immediately.
class BuddyInfo
This structure describes buddy info, which can be retrieved by via Buddy::getInfo().
Public Functions
void fromPj(const pjsua_buddy_info & pbi)
Import from pjsip structure.
Public Members
string uri
The full URI of the buddy, as specified in the configuration.
string contact
Buddy‘s Contact, only available when presence subscription has been estab-
lished to the buddy.
bool presMonitorEnabled
Flag to indicate that we should monitor the presence information for this
buddy (normally yes, unless explicitly disabled).
pjsip_evsub_state subState
http://slidepdf.com/reader/full/pjsua2doc 235/271
8/10/2019 PJSUA2Doc
If presMonitorEnabled is true, this specifies the last state of the presence
subscription.
If presence subscription session is currently active, the value will be
PJSIP_EVSUB_STATE_ACTIVE. If presence subscription request has been
rejected, the value will be PJSIP_EVSUB_STATE_TERMINATED, and the
termination reason will be specified in subTermReason.
string subStateName
String representation of subscription state.
pjsip_status_code subTermCode
Specifies the last presence subscription termination code.
This would return the last status of the SUBSCRIBE request. If the sub-
scription is terminated with NOTIFY by the server, this value will be set to
200, and subscription termination reason will be given in the subTermReason
field.
string subTermReason
Public Functions
Buddy()
Constructor.
~Buddy()
Destructor.
Note that if the Buddy instance is deleted, it will also delete the correspond-
ing buddy in the PJSUA-LIB.
bool isValid()
http://slidepdf.com/reader/full/pjsua2doc 236/271
8/10/2019 PJSUA2Doc
BuddyInfo getInfo()
void subscribePresence(bool subscribe)
void updatePresence(void)
scription immediately, and in this case it can use this function to accomplish
this.
Note that the buddy’s presence subscription will only be initiated if presence
monitoring is enabled for the buddy. See subscribePresence() for more info.
Also if presence subscription for the buddy is already active, this function
will not do anything.
Once the presence subscription is activated successfully for the buddy, appli-
cation will be notified about the buddy’s presence status in the onBuddyS-
tate() callback.
Send instant messaging outside dialog, using this buddy’s specified account
for route set and authentication.
Parameters
• prm - Sending instant message parameter.
http://slidepdf.com/reader/full/pjsua2doc 237/271
8/10/2019 PJSUA2Doc
void onBuddyState()
12.6 persistent.hpp
void writeObject(ContainerNode & node)
http://slidepdf.com/reader/full/pjsua2doc 238/271
8/10/2019 PJSUA2Doc
Document is read and written serially, hence the order of reading must be the same as the order
of writing. The PersistentDocument class provides API to read and write to the root node, but
for more flexible operations application can use the ContainerNode methods instead. Indeed
the read and write API in PersistentDocument is just a shorthand which calls the relevant
methods in the ContainerNode. As a tip, normally application only uses the readObject() and
writeObject() methods declared here to read/write top level objects, and use the macros that
string saveString()
ContainerNode & getRootContainer()
http://slidepdf.com/reader/full/pjsua2doc 239/271
8/10/2019 PJSUA2Doc
bool hasUnread()
string unreadName()
Read an integer value from the document and return the value.
This will throw Error if the current element is not a number. The read posi-
tion will be advanced to the next element.
Return
The value.
Parameters
• name - If specified, then the function will check if the name of the next
element matches the specified name and throw Error if it doesn’t match.
Read a float value from the document and return the value.
This will throw Error if the current element is not a number. The read posi-
tion will be advanced to the next element.
Return
The value.
Parameters
• name - If specified, then the function will check if the name of the next
element matches the specified name and throw Error if it doesn’t match.
http://slidepdf.com/reader/full/pjsua2doc 240/271
8/10/2019 PJSUA2Doc
Read a boolean value from the container and return the value.
This will throw Error if the current element is not a boolean. The read posi-
tion will be advanced to the next element.
Return
The value.
Parameters
• name - If specified, then the function will check if the name of the next
element matches the specified name and throw Error if it doesn’t match.
Read a string value from the container and return the value.
This will throw Error if the current element is not a string. The read position
will be advanced to the next element.
Return
The value.
Parameters
• name - If specified, then the function will check if the name of the next
element matches the specified name and throw Error if it doesn’t match.
This will throw Error if the current element is not a string array. The read
position will be advanced to the next element.
Return
The value.
Parameters
• name - If specified, then the function will check if the name of the next
element matches the specified name and throw Error if it doesn’t match.
http://slidepdf.com/reader/full/pjsua2doc 241/271
8/10/2019 PJSUA2Doc
Return
Container object.
Parameters
• name - If specified, then the function will check if the name of the next
element matches the specified name and throw Error if it doesn’t match.
Parameters
• name - The name for the value in the container.
• num - The value to be written.
http://slidepdf.com/reader/full/pjsua2doc 242/271
8/10/2019 PJSUA2Doc
Create and write an empty Object node that can be used as parent for subse-
quent write operations.
Return
A sub-container.
Parameters
• name - The name for the new container in the container.
Create and write an empty array node that can be used as parent for subse-
quent write operations.
Return
A sub-container.
http://slidepdf.com/reader/full/pjsua2doc 243/271
8/10/2019 PJSUA2Doc
Parameters
• name - The name for the array.
class container_node_internal_data
Internal data for ContainerNode.
inheritance, some methods will be made pure virtual and must be implemented by the actual
class. However, doing so will require dynamic instantiation of the ContainerNode class, which
means we will need to pass around the class as pointer, for example as the return value of
readContainer() and writeNewContainer() methods. Then we will need to establish who needs
or how to delete these objects, or use shared pointer mechanism, each of which is considered
too inconvenient or complicated for the purpose.
So hence we use C style “inheritance”, where the methods are declared in container_node_op
and the data in container_node_internal_data structures. An implementation of ContainerN-
ode class will need to set up these members with values that makes sense to itself. The methods
in container_node_op contains the pointer to the actual implementation of the operation, which
would be specific according to the format of the document. The methods in this ContainerNode
class are just thin wrappers which call the implementation in the container_node_op structure.
Public Functions
bool hasUnread()
Determine if there is unread element.
If yes, then app can use one of the readXxx() functions to read it.
string unreadName()
http://slidepdf.com/reader/full/pjsua2doc 244/271
8/10/2019 PJSUA2Doc
Read an integer value from the document and return the value.
This will throw Error if the current element is not a number. The read posi-
tion will be advanced to the next element.
Return
The value.
Parameters
• name - If specified, then the function will check if the name of the next
element matches the specified name and throw Error if it doesn’t match.
Read a number value from the document and return the value.
This will throw Error if the current element is not a number. The read posi-
tion will be advanced to the next element.
Return
The value.
Parameters
• name - If specified, then the function will check if the name of the next
element matches the specified name and throw Error if it doesn’t match.
Read a boolean value from the container and return the value.
This will throw Error if the current element is not a boolean. The read posi-
tion will be advanced to the next element.
Return
The value.
Parameters
• name - If specified, then the function will check if the name of the next
element matches the specified name and throw Error if it doesn’t match.
Read a string value from the container and return the value.
This will throw Error if the current element is not a string. The read position
will be advanced to the next element.
http://slidepdf.com/reader/full/pjsua2doc 245/271
8/10/2019 PJSUA2Doc
Return
The value.
Parameters
• name - If specified, then the function will check if the name of the next
element matches the specified name and throw Error if it doesn’t match.
• name - If specified, then the function will check if the name of the next
element matches the specified name and throw Error if it doesn’t match.
http://slidepdf.com/reader/full/pjsua2doc 246/271
8/10/2019 PJSUA2Doc
This will throw Error if the current element is not an array. The read position
will be advanced to the next element.
Return
Container object.
Parameters
• name - If specified, then the function will check if the name of the next
element matches the specified name and throw Error if it doesn’t match.
http://slidepdf.com/reader/full/pjsua2doc 247/271
8/10/2019 PJSUA2Doc
Create and write an empty Object node that can be used as parent for subse-
quent write operations.
Return
A sub-container.
Parameters
• name - The name for the new container in the container.
Create and write an empty array node that can be used as parent for subse-
quent write operations.
Return
A sub-container.
Parameters
• name - The name for the array.
Public Members
container_node_op * op
Method table.
container_node_internal_data data
Internal data.
12.7 json.hpp
namespace pj
http://slidepdf.com/reader/full/pjsua2doc 248/271
8/10/2019 PJSUA2Doc
JsonDocument()
Default constructor.
~JsonDocument()
Destructor.
string saveString()
ContainerNode & getRootContainer()
pj_json_elem * allocElement()
http://slidepdf.com/reader/full/pjsua2doc 249/271
8/10/2019 PJSUA2Doc
pj_pool_t * getPool()
void initRoot()
Private Members
pj_caching_pool cp
ContainerNode rootNode
pj_json_elem * root
pj_pool_t * pool
12.8 siptypes.hpp
namespace pj
PJSUA2 API is inside pj namespace.
Typedefs
typedef std::vector< SipHeader > SipHeaderVector
Array of strings.
typedef std::vector< SipMultipartPart > SipMultipartPartVector
Array of multipart parts.
class AuthCredInfo
Credential information.
Credential contains information to authenticate against a service.
Public Functions
AuthCredInfo()
Default constructor.
AuthCredInfo(const string & scheme, const string & realm, const string &
user_name, const int data_type, const string data)
http://slidepdf.com/reader/full/pjsua2doc 250/271
8/10/2019 PJSUA2Doc
void writeObject(ContainerNode & node)
http://slidepdf.com/reader/full/pjsua2doc 251/271
8/10/2019 PJSUA2Doc
TlsConfig()
Default constructor initialises with default values.
pjsip_tls_setting toPj()
Convert to pjsip.
void writeObject(ContainerNode & node)
string CaListFile
Certificate of Authority (CA) list file.
string certFile
Public endpoint certificate file, which will be used as client- side certificate
for outgoing TLS connection, and server-side certificate for incoming TLS
connection.
string privKeyFile
Optional private key of the endpoint certificate to be used.
string password
Password to open private key.
pjsip_ssl_method method
TLS protocol method from pjsip_ssl_method.
Default is PJSIP_SSL_UNSPECIFIED_METHOD (0), which in turn
will use PJSIP_SSL_DEFAULT_METHOD, which default value is
PJSIP_TLSV1_METHOD.
IntVector ciphers
http://slidepdf.com/reader/full/pjsua2doc 252/271
8/10/2019 PJSUA2Doc
This is a lower level operation than setting the qosType field and may not be
supported on all platforms.
By default all settings in this structure are disabled.
bool qosIgnoreError
Specify if the transport should ignore any errors when setting the QoS traffic
type/parameters.
Default: PJ_TRUE
http://slidepdf.com/reader/full/pjsua2doc 253/271
8/10/2019 PJSUA2Doc
class TransportConfig
Parameters to create a transport instance.
Public Functions
TransportConfig()
pjsua_transport_config toPj()
Convert to pjsip.
void writeObject(ContainerNode & node)
http://slidepdf.com/reader/full/pjsua2doc 254/271
8/10/2019 PJSUA2Doc
Note: this option can be used for both UDP and TCP as well!
string boundAddress
Optional address where the socket should be bound to.
This option SHOULD only be used to selectively bind the socket to particular
interface (instead of 0.0.0.0), and SHOULD NOT be used to set the published
address of a transport (the public_addr field should be used for that purpose).
Note that unlike public_addr field, the address (or hostname) here MUST
correspond to the actual interface address in the host, since this address will
be specified as bind() argument.
TlsConfig tlsConfig
http://slidepdf.com/reader/full/pjsua2doc 255/271
8/10/2019 PJSUA2Doc
SipRxData()
Default constructor.
string info
A short info string describing the request, which normally contains the re-
quest method and its CSeq.
string wholeMsg
The whole message data as a string, containing both the header section and
message body section.
SocketAddress srcAddress
Source address of the message.
void * pjRxData
Pointer to original pjsip_rx_data.
Only valid when the struct is constructed from PJSIP’s pjsip_rx_data.
class SipTxData
http://slidepdf.com/reader/full/pjsua2doc 256/271
8/10/2019 PJSUA2Doc
SipTxData()
Default constructor.
string info
A short info string describing the request, which normally contains the re-
quest method and its CSeq.
string wholeMsg
The whole message data as a string, containing both the header section and
message body section.
SocketAddress dstAddress
Destination address of the message.
void * pjTxData
Pointer to original pjsip_tx_data.
Only valid when the struct is constructed from PJSIP’s pjsip_tx_data.
class SipTransaction
This structure describes SIP transaction object.
It corresponds to the pjsip_transaction structure in PJSIP library.
Public Functions
SipTransaction()
Default constructor.
string method
The method.
int statusCode
Last status code seen.
string statusText
Last reason phrase.
http://slidepdf.com/reader/full/pjsua2doc 257/271
8/10/2019 PJSUA2Doc
pjsip_tsx_state_e state
State.
SipTxData lastTx
Msg kept for retrans.
void * pjTransaction
pjsip_transaction.
class TimerEvent
The timer.
pj_status_t status
The transaction.
pjsip_tsx_state_e prevState
Previous state.
pjsip_event_id_e type
Type of event source:
class TxMsgEvent
SipTxData tdata
http://slidepdf.com/reader/full/pjsua2doc 258/271
8/10/2019 PJSUA2Doc
SipTxData tdata
The transmit data.
SipTransaction tsx
The transaction.
class RxMsgEvent
This structure describes message arrival event.
Public Members
SipRxData rdata
GenericData user1
User data 1.
GenericData user2
User data 2.
GenericData user3
User data 3.
GenericData user4
User data 4.
class SipEvent
This structure describe event descriptor to fully identify a SIP event.
It corresponds to the pjsip_event structure in PJSIP library.
Public Functions
SipEvent()
Default constructor.
http://slidepdf.com/reader/full/pjsua2doc 259/271
8/10/2019 PJSUA2Doc
User event.
struct pj::SipEvent::@3 body
The event body, which fields depends on the event type.
void * pjEvent
Pointer to its original pjsip_event.
Only valid when the struct is constructed from PJSIP’s pjsip_event.
class SipMediaType
Public Functions
void fromPj(const pjsip_media_type & prm)
Construct from PJSIP’s pjsip_media_type.
pjsip_media_type toPj()
Media type.
string subType
Media subtype.
class SipHeader
http://slidepdf.com/reader/full/pjsua2doc 260/271
8/10/2019 PJSUA2Doc
void fromPj(const pjsip_hdr *)
Initiaize from PJSIP header.
pjsip_generic_string_hdr & toPj()
string hName
Header name.
string hValue
Header value.
Private Members
pjsip_generic_string_hdr pjHdr
pjsip_multipart_part & toPj()
SipHeaderVector headers
Optional headers to be put in this multipart part.
SipMediaType contentType
class SipTxOption
http://slidepdf.com/reader/full/pjsua2doc 261/271
8/10/2019 PJSUA2Doc
SipHeaderVector headers
Additional message headers to be included in the outgoing message.
string contentType
MIME type of the message body, if application specifies the messageBody
in this structure.
string msgBody
Optional message body to be added to the message, only when the message
doesn’t have a body.
SipMediaType multipartContentType
http://slidepdf.com/reader/full/pjsua2doc 262/271
8/10/2019 PJSUA2Doc
This structure contains parameters for sending instance message methods, e.g:
Buddy::sendInstantMessage(), Call:sendInstantMessage().
Public Functions
SendInstantMessageParam()
Default constructor initializes with zero/empty values.
Public Members
string contentType
MIME type.
Default is “text/plain”.
string content
The message content.
SipTxOption txOption
List of headers etc to be included in outgoing request.
Token userData
User data, which will be given back when the IM callback is called.
class SendTypingIndicationParam
This structure contains parameters for sending typing indication methods, e.g:
Buddy::sendTypingIndication(), Call:sendTypingIndication().
Public Functions
SendTypingIndicationParam ()
Default constructor initializes with zero/empty values.
Public Members
bool isTyping
True to indicate to remote that local person is currently typing an IM.
SipTxOption txOption
List of headers etc to be included in outgoing request.
12.9 types.hpp
http://slidepdf.com/reader/full/pjsua2doc 263/271
8/10/2019 PJSUA2Doc
PJSUA2_RAISE_ERROR2(status, op)
Raise Error exception.
PJSUA2_RAISE_ERROR3(status, op, txt)
Raise Error exception.
PJSUA2_CHECK_RAISE_ERROR2(status, op)
Raise Error exception if the expression fails.
PJSUA2_CHECK_RAISE_ERROR(status)
Raise Error exception if the status fails.
PJSUA2_CHECK_EXPR(expr)
Raise Error exception if the expression fails.
namespace pj
PJSUA2 API is inside pj namespace.
Typedefs
typedef std::vector< std::string > StringVector
Array of strings.
typedef std::vector< int > IntVector
Array of integers.
typedef void * Token
Type of token, i.e.
arbitrary application user data
typedef string SocketAddress
Anonymous enum
Constants.
Values:
http://slidepdf.com/reader/full/pjsua2doc 264/271
8/10/2019 PJSUA2Doc
Public Functions
string info(bool multi_line = false)
Build error string.
Error()
Default constructor.
Error(pj_status_t prm_status, const string & prm_title, const string & prm_reason,
const string & prm_src_file, int prm_src_line)
Version information.
Public Members
int major
Major number.
int minor
Minor number.
int rev
http://slidepdf.com/reader/full/pjsua2doc 265/271
8/10/2019 PJSUA2Doc
string full
The full version info (e.g.
“2.1.0-svn”)
unsigned numeric
PJLIB version number as three bytes with the following format: 0xMMI-
IRR00, where MM: major number, II: minor number, RR: revision number,
00: always zero for now.
class TimeVal
Representation of time value.
Public Functions
void fromPj(const pj_time_val & prm)
Convert from pjsip.
Public Members
long sec
The seconds part of the time.
long msec
The miliseconds fraction of the time.
12.10 config.hpp
PJSUA2 Base Agent Operation.
Defines
PJSUA2_ERROR_HAS_EXTRA_INFO
Specify if the Error exception info should contain operation and source file information.
http://slidepdf.com/reader/full/pjsua2doc 266/271
8/10/2019 PJSUA2Doc
CHAPTER
THIRTEEN
13.1 Requirements
2. The easiest way to install all the tools is with Python Package Index (PyPI). Just run this and it will install
Sphinx, Breathe, and all the required tools if they are not installed:
3. Otherwise if PyPI is not available, consult Sphinx and Breathe sites for installation instructions and you may
need to install these manually:
• Sphinx
• Breathe
• docutils
• Pygments
The main source of the documentation is currently the ‘’‘Trac’‘’ pages at https://trac.pjsip.org/repos/wiki/pjsip-
doc/index. The copies in SVN are just copies for backup.
To render the documentation as HTML in _build/html directory:
$ cd $PJDIR/doc/pjsip-book
$ python fetch_trac.py
$ make
$ make latexpdf
Quick sample:
263
http://slidepdf.com/reader/full/pjsua2doc 267/271
8/10/2019 PJSUA2Doc
.. code-block:: c++
For that links to work, we need to display the link target declaration (a class or method)
somewhere in the doc, like this:
.. doxygenclass::
:path: xml pj::AudioMediaPlayer
:members:
.. doxygenfunction:: pj::AudioMediaPlayer::createPlayer()
:path: xml
:no-link:
Audio Media Player.
Public Functions
http://slidepdf.com/reader/full/pjsua2doc 268/271
8/10/2019 PJSUA2Doc
AudioMediaPlayer()
Constructor.
Create a file player, and automatically add this player to the conference
bridge.
Parameters
• file_name - The filename to be played. Currently only WAV files
are supported, and the WAV file MUST be formatted as 16bit PCM
mono/single channel (any clock rate is supported).
• options - Optional option flag. Application may specify PJME-
DIA_FILE_NO_LOOP to prevent playback loop.
Create a file playlist media port, and automatically add the port to the con-
ference bridge.
Parameters
• file_names - Array of file names to be added to the play list. Note
that the files must have the same clock rate, number of channels, and
number of bits per sample.
• label - Optional label to be set for the media port.
• options - Optional option flag. Application may specify PJME-
DIA_FILE_NO_LOOP to prevent looping.
void setPos(pj_uint32_t samples)
~AudioMediaPlayer()
Virtual destructor.
Public Static Functions
http://slidepdf.com/reader/full/pjsua2doc 269/271
8/10/2019 PJSUA2Doc
http://slidepdf.com/reader/full/pjsua2doc 270/271
8/10/2019 PJSUA2Doc
CHAPTER
FOURTEEN
http://slidepdf.com/reader/full/pjsua2doc 271/271