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 implement the onTimer() callback to get the notification when the timer expires.

Instantiating the Endpoint

Before anything else, you must instantiate the Endpoint class:

Endpoint *ep = new Endpoint;

Once the endpoint is instantiated, you can retrieve the Endpoint instance using Endpoint.instance() static method.

Creating the Library

Create the library by calling its libCreate() method:

try {
    ep->libCreate();
} catch(Error& err) {
    cout << "Startup error: " << err.info() << endl;
}

The libCreate() method will raise exception if error occurs, so we need to trap the exception using try/catch clause as above.

Initializing the Library and Configuring the Settings

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;

Next, you can initialize the library by calling libInit():

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.

Creating One or More Transports

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 TransportConfig 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.

Starting the Library

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:

try {
    ep->libStart();
} catch(Error& err) {
    cout << "Startup error: " << err.info() << endl;
}

Shutting Down the Library

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 Reference

The Endpoint

class Endpoint

Endpoint represents an instance of pjsua library. There can only be one instance of pjsua library in an application, hence this class is a singleton.

Public Functions

Endpoint()

Default constructor

virtual ~Endpoint()

Virtual destructor

Version libVersion() const

Get library version.

void libCreate()

Instantiate pjsua application. Application must call this function before calling any other functions, to make sure that the underlying libraries are properly initialized. Once this function has returned success, application must call libDestroy() before quitting.

pjsua_state libGetState() const

Get library state.

Return

library state.

void libInit(const EpConfig &prmEpConfig)

Initialize pjsua with the specified settings. All the settings are optional, and the default values will be used when the config is not specified.

Note that create() MUST be called before calling this function.

Parameters

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 libRegisterThread(const string &name)

Register a thread that was created by external or native API to the library. Note that each time this function is called, it will allocate some memory to store the thread description, which will only be freed when the library is destroyed.

Parameters
  • name: The optional name to be assigned to the thread.

bool libIsThreadRegistered()

Check if this thread has been registered to the library. Note that this function is only applicable for library main & worker threads and external/native threads registered using libRegisterThread().

void libStopWorkerThreads()

Stop all worker threads.

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.

string utilStrError(pj_status_t prmErr)

Retrieve the error string for the specified status code.

Parameters
  • prmErr: The error code.

void utilLogWrite(int prmLevel, const string &prmSender, const string &prmMsg)

Write a log message.

Parameters
  • prmLevel: Log verbosity level (1-5)

  • prmSender: The log sender.

  • prmMsg: The log message.

void utilLogWrite(LogEntry &e)

Write a log entry. Application must implement its own custom LogWriter and this function will then call the LogWriter::write() method. Note that this function does not call PJSIP’s internal logging functionality. For that, you should use utilLogWrite(prmLevel, prmSender, prmMsg) above.

Parameters
  • e: The log entry.

pj_status_t utilVerifySipUri(const string &prmUri)

This is a utility function to verify that valid SIP url is given. If the URL is a valid SIP/SIPS scheme, PJ_SUCCESS will be returned.

Return

PJ_SUCCESS on success, or the appropriate error code.

See

utilVerifyUri()

Parameters
  • prmUri: The URL string.

pj_status_t utilVerifyUri(const string &prmUri)

This is a utility function to verify that valid URI is given. Unlike utilVerifySipUri(), this function will return PJ_SUCCESS if tel: URI is given.

Return

PJ_SUCCESS on success, or the appropriate error code.

See

pjsua_verify_sip_url()

Parameters
  • prmUri: The URL string.

Token utilTimerSchedule(unsigned prmMsecDelay, Token prmUserData)

Schedule a timer with the specified interval and user data. When the interval elapsed, onTimer() callback will be called. Note that the callback may be executed by different thread, depending on whether worker thread is enabled or not.

Return

Token to identify the timer, which could be given to utilTimerCancel().

Parameters
  • prmMsecDelay: The time interval in msec.

  • prmUserData: Arbitrary user data, to be given back to application in the callback.

void utilTimerCancel(Token prmToken)

Cancel previously scheduled timer with the specified timer token.

Parameters

void utilAddPendingJob(PendingJob *job)

Utility to register a pending job to be executed by main thread. If EpConfig::UaConfig::mainThreadOnly is false, the job will be executed immediately.

Parameters
  • job: The job class.

IntVector utilSslGetAvailableCiphers()

Get cipher list supported by SSL/TLS backend.

void natDetectType(void)

This is a utility function to detect NAT type in front of this endpoint. Once invoked successfully, this function will complete asynchronously and report the result in onNatDetectionComplete().

After NAT has been detected and the callback is called, application can get the detected NAT type by calling natGetType(). Application can also perform NAT detection by calling natDetectType() again at later time.

Note that STUN must be enabled to run this function successfully.

pj_stun_nat_type natGetType()

Get the NAT type as detected by natDetectType() function. This function will only return useful NAT type after natDetectType() has completed successfully and onNatDetectionComplete() callback has been called.

Exception: if this function is called while detection is in progress, PJ_EPENDING exception will be raised.

void natUpdateStunServers(const StringVector &prmServers, bool prmWait)

Update the STUN servers list. The libInit() must have been called before calling this function.

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:

    • ”pjsip.org” (domain name)

    • ”sip.pjsip.org” (host name)

    • ”pjsip.org:33478” (domain name and a non- standard port number)

    • ”10.0.0.1:3478” (IP address and port number)

  • 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 onNatCheckStunServersComplete() will be called before this function returns.

void natCheckStunServers(const StringVector &prmServers, bool prmWait, Token prmUserData)

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:

    • ”pjsip.org” (domain name)

    • ”sip.pjsip.org” (host name)

    • ”pjsip.org:33478” (domain name and a non- standard port number)

    • ”10.0.0.1:3478” (IP address and port number)

  • 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.

void natCancelCheckStunServers(Token token, bool notify_cb = false)

Cancel pending STUN resolution which match the specified token.

Exception: PJ_ENOTFOUND if there is no matching one, or other error.

Parameters
  • token: The token to match. This token was given to natCheckStunServers()

  • notify_cb: Boolean to control whether the callback should be called for cancelled resolutions. When the callback is called, the status in the result will be set as PJ_ECANCELLED.

TransportId transportCreate(pjsip_transport_type_e type, const TransportConfig &cfg)

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()

Enumerate all transports currently created in the system. This function will return all transport IDs, and application may then call transportGetInfo() function to retrieve detailed information about the transport.

Return

Array of transport IDs.

TransportInfo transportGetInfo(TransportId id)

Get information about transport.

Return

Transport info.

Parameters
  • id: Transport ID.

void transportSetEnable(TransportId id, bool enabled)

Disable a transport or re-enable it. By default transport is always enabled after it is created. Disabling a transport does not necessarily close the socket, it will only discard incoming messages and prevent the transport from being used to send outgoing messages.

Parameters
  • id: Transport ID.

  • enabled: Enable or disable the transport.

void transportClose(TransportId id)

Close the transport. 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 transportShutdown(TransportHandle tp)

Start graceful shutdown procedure for this transport handle. After graceful shutdown has been initiated, no new reference can be obtained for the transport. However, existing objects that currently uses the transport may still use this transport to send and receive packets. After all objects release their reference to this transport, the transport will be destroyed immediately.

Note: application normally uses this API after obtaining the handle from onTransportState() callback.

Parameters
  • tp: The transport.

void hangupAllCalls(void)

Terminate all calls. This will initiate call hangup for all currently active calls.

void mediaAdd(AudioMedia &media)

Add media to the media list.

Parameters
  • media: media to be added.

void mediaRemove(AudioMedia &media)

Remove media from the media list.

Parameters
  • media: media to be removed.

bool mediaExists(const AudioMedia &media) const

Check if media has been added to the media list.

Return

True if media has been added, false otherwise.

Parameters
  • media: media to be check.

unsigned mediaMaxPorts() const

Get maximum number of media port.

Return

Maximum number of media port in the conference bridge.

unsigned mediaActivePorts() const

Get current number of active media port in the bridge.

Return

The number of active media port.

const AudioMediaVector &mediaEnumPorts() const

Warning: deprecated, use mediaEnumPorts2() instead. This function is not safe in multithreaded environment.

Enumerate all media port.

Return

The list of media port.

AudioMediaVector2 mediaEnumPorts2() const

Enumerate all audio media port.

Return

The list of audio media port.

VideoMediaVector mediaEnumVidPorts() const

Enumerate all video media port.

Return

The list of video media port.

AudDevManager &audDevManager()

Get the instance of Audio Device Manager.

Return

The Audio Device Manager.

VidDevManager &vidDevManager()

Get the instance of Video Device Manager.

Return

The Video Device Manager.

const CodecInfoVector &codecEnum()

Warning: deprecated, use codecEnum2() instead. This function is not safe in multithreaded environment.

Enum all supported codecs in the system.

Return

Array of codec info.

CodecInfoVector2 codecEnum2() const

Enum all supported codecs in the system.

Return

Array of codec info.

void codecSetPriority(const string &codec_id, pj_uint8_t priority)

Change codec priority.

Parameters
  • codec_id: Codec ID, which is a string that uniquely identify the codec (such as “speex/8000”).

  • priority: Codec priority, 0-255, where zero means to disable the codec.

CodecParam codecGetParam(const string &codec_id) const

Get codec parameters.

Return

Codec parameters. If codec is not found, Error will be thrown.

Parameters
  • codec_id: Codec ID.

void codecSetParam(const string &codec_id, const CodecParam param)

Set codec parameters.

Parameters
  • codec_id: Codec ID.

  • param: Codec parameter to set. Set to NULL to reset codec parameter to library default settings.

const CodecInfoVector &videoCodecEnum()

Warning: deprecated, use videoCodecEnum2() instead. This function is not safe in multithreaded environment.

Enum all supported video codecs in the system.

Return

Array of video codec info.

CodecInfoVector2 videoCodecEnum2() const

Enum all supported video codecs in the system.

Return

Array of video codec info.

void videoCodecSetPriority(const string &codec_id, pj_uint8_t priority)

Change video codec priority.

Parameters
  • codec_id: Codec ID, which is a string that uniquely identify the codec (such as “H263/90000”). Please see pjsua manual or pjmedia codec reference for details.

  • priority: Codec priority, 0-255, where zero means to disable the codec.

VidCodecParam getVideoCodecParam(const string &codec_id) const

Get video codec parameters.

Return

Codec parameters. If codec is not found, Error will be thrown.

Parameters
  • codec_id: Codec ID.

void setVideoCodecParam(const string &codec_id, const VidCodecParam &param)

Set video codec parameters.

Parameters
  • codec_id: Codec ID.

  • param: Codec parameter to set.

void resetVideoCodecParam(const string &codec_id)

Reset video codec parameters to library default settings.

Parameters
  • codec_id: Codec ID.

StringVector srtpCryptoEnum()

Enumerate all SRTP crypto-suite names.

Return

The list of SRTP crypto-suite name.

void handleIpChange(const IpChangeParam &param)

Inform the stack that IP address change event was detected. The stack will:

  1. Restart the listener (this step is configurable via IpChangeParam.restartListener).

  2. Shutdown the transport used by account registration (this step is configurable via AccountConfig.ipChangeConfig.shutdownTp).

  3. Update contact URI by sending re-Registration (this step is configurable via a\ AccountConfig.natConfig.contactRewriteUse and a\ AccountConfig.natConfig.contactRewriteMethod)

  4. Hangup active calls (this step is configurable via a\ AccountConfig.ipChangeConfig.hangupCalls) or continue the call by sending re-INVITE (configurable via AccountConfig.ipChangeConfig.reinviteFlags).

Return

PJ_SUCCESS on success, other on error.

Parameters
  • param: The IP change parameter, have a look at #IpChangeParam.

virtual void onNatDetectionComplete(const OnNatDetectionCompleteParam &prm)

Callback when the Endpoint has finished performing NAT type detection that is initiated with natDetectType().

Parameters
  • prm: Callback parameters containing the detection result.

virtual void onNatCheckStunServersComplete(const OnNatCheckStunServersCompleteParam &prm)

Callback when the Endpoint has finished performing STUN server checking that is initiated when calling libInit(), or by calling natCheckStunServers() or natUpdateStunServers().

Parameters
  • prm: Callback parameters.

virtual void onTransportState(const OnTransportStateParam &prm)

This callback is called when transport state has changed.

Parameters
  • prm: Callback parameters.

virtual void onTimer(const OnTimerParam &prm)

Callback when a timer has fired. The timer was scheduled by utilTimerSchedule().

Parameters
  • prm: Callback parameters.

virtual void onSelectAccount(OnSelectAccountParam &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 application 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.

virtual void onIpChangeProgress(OnIpChangeProgressParam &prm)

Calling handleIpChange() may involve different operation. This callback is called to report the progress of each enabled operation.

Parameters
  • prm: Callback parameters.

virtual void onMediaEvent(OnMediaEventParam &prm)

Notification about media events such as video notifications. This callback will most likely be called from media threads, thus application must not perform heavy processing in this callback. If application needs to perform more complex tasks to handle the event, it should post the task to another thread.

Parameters
  • prm: Callback parameter.

Public Static Functions

static Endpoint &instance()

Retrieve the singleton instance of the endpoint

Endpoint Configurations

Endpoint

struct EpConfig : public pj::PersistentObject

Endpoint configuration

Public Functions

virtual void readObject(const ContainerNode &node)

Read this object from a container.

Parameters
  • node: Container to write values from.

virtual void writeObject(ContainerNode &node) const

Write this object to a container.

Parameters
  • node: Container to write values to.

Public Members

UaConfig uaConfig

UA config

LogConfig logConfig

Logging config

MediaConfig medConfig

Media config

Media

struct MediaConfig : public pj::PersistentObject

This structure describes media configuration, which will be specified when calling Lib::init().

Public Functions

MediaConfig()

Default constructor initialises with default values

void fromPj(const pjsua_media_config &mc)

Construct from pjsua_media_config.

pjsua_media_config toPj() const

Export

virtual void readObject(const ContainerNode &node)

Read this object from a container.

Parameters
  • node: Container to write values from.

virtual void writeObject(ContainerNode &node) const

Write this object to a container.

Parameters
  • node: Container to write values to.

Public Members

unsigned clockRate

Clock rate to be applied to the conference bridge. If value is zero, default clock rate will be used (PJSUA_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

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

Specify the number of worker threads to handle incoming RTP packets. A value of one is recommended for most applications.

unsigned quality

Media quality, 0-10, according to this table: 5-10: resampling use large filter, 3-4: resampling use small filter, 1-2: resampling use linear. The media quality also sets speex codec quality/complexity to the number.

Default: 5 (PJSUA_DEFAULT_CODEC_QUALITY).

unsigned ptime

Specify default codec ptime.

Default: 0 (codec specific)

bool noVad

Disable VAD?

Default: 0 (no (meaning VAD is enabled))

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()). Specify PJMEDIA_ECHO_USE_SW_ECHO here if application wishes to use software echo canceller instead of device EC.

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

Audio capture buffer length, in milliseconds.

Default: PJMEDIA_SND_DEFAULT_REC_LATENCY

unsigned sndPlayLatency

Audio playback buffer length, in milliseconds.

Default: PJMEDIA_SND_DEFAULT_PLAY_LATENCY

int jbInit

Jitter buffer initial prefetch delay in msec. The value must be between jb_min_pre and jb_max_pre below.

Default: -1 (to use default stream settings, currently 150 msec)

int jbMinPre

Jitter buffer minimum prefetch delay in msec.

Default: -1 (to use default stream settings, currently 60 msec)

int jbMaxPre

Jitter buffer maximum prefetch delay in msec.

Default: -1 (to use default stream settings, currently 240 msec)

int jbMax

Set maximum delay that can be accomodated by the jitter buffer msec.

Default: -1 (to use default stream settings, currently 360 msec)

int sndAutoCloseTime

Specify idle time of sound device before it is automatically closed, in seconds. Use value -1 to disable the auto-close feature of sound device

Default : 1

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 preview 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

Logging

struct LogConfig : public pj::PersistentObject

Logging configuration, which can be (optionally) specified when calling Lib::init().

Public Functions

LogConfig()

Default constructor initialises with default values

void fromPj(const pjsua_logging_config &lc)

Construct from pjsua_logging_config

pjsua_logging_config toPj() const

Generate pjsua_logging_config.

virtual void readObject(const ContainerNode &node)

Read this object from a container.

Parameters
  • node: Container to write values from.

virtual void writeObject(ContainerNode &node) const

Write this object to a container.

Parameters
  • node: Container to write values to.

Public Members

unsigned msgLogging

Log incoming and outgoing SIP message? Yes!

unsigned level

Input verbosity level. 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

Custom log writer, if required. This instance will be destroyed by the endpoint when the endpoint is destroyed.

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

virtual ~LogWriter()

Destructor

virtual void write(const LogEntry &entry) = 0

Write a log entry.

struct LogEntry

Data containing log entry to be written by the LogWriter.

Public Members

int level

Log verbosity level of this message

string msg

The log message

long threadId

ID of current thread

string threadName

The name of the thread that writes this log

User Agent

struct UaConfig : public pj::PersistentObject

SIP User Agent related settings.

Public Functions

UaConfig()

Default constructor to initialize with default values.

void fromPj(const pjsua_config &ua_cfg)

Construct from pjsua_config.

pjsua_config toPj() const

Export to pjsua_config

virtual void readObject(const ContainerNode &node)

Read this object from a container.

Parameters
  • node: Container to write values from.

virtual void writeObject(ContainerNode &node) const

Write this object to a container.

Parameters
  • node: Container to write values to.

Public Members

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).

StringVector outboundProxies

Specify the URL of outbound proxies to visit for all outgoing requests. The outbound proxies will be used for all accounts, and it will be used to build the route set for outgoing requests. The final route set for outgoing requests will consists of the outbound proxies and the proxy configured in the account.

string userAgent

Optional user agent string (default empty). If it’s empty, no User-Agent header will be sent with outgoing requests.

StringVector stunServer

Array of STUN servers to try. 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:

  • ”pjsip.org” (domain name)

  • ”sip.pjsip.org” (host name)

  • ”pjsip.org:33478” (domain name and a non-standard port number)

  • ”10.0.0.1:3478” (IP address and port number)

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 stunTryIpv6

This specifies if the library should try to do an IPv6 resolution of the STUN servers if the IPv4 resolution fails. It can be useful in an IPv6-only environment, including on NAT64.

Default: FALSE

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:

  • 0: no information will be added in SDP, and parsing is disabled.

  • 1: only the NAT type number is added.

  • 2: add both NAT type number and name.

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

Callback Parameters

struct OnNatDetectionCompleteParam

Argument to Endpoint::onNatDetectionComplete() callback.

Public Members

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 OnNatCheckStunServersCompleteParam

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, otherwise 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 OnTimerParam

Parameter of Endpoint::onTimer() callback.

Public Members

Token userData

Arbitrary user data that was passed to Endpoint::utilTimerSchedule() function.

unsigned msecDelay

The interval of this timer, in miliseconds.

struct OnTransportStateParam

Parameter of Endpoint::onTransportState() callback.

Public Members

TransportHandle hnd

The transport handle.

string type

The transport type.

pjsip_transport_state state

Transport current state.

pj_status_t lastError

The last error code related to the transport state.

TlsInfo tlsInfo

TLS transport info, only used if transport type is TLS. Use TlsInfo.isEmpty() to check if this info is available.

struct OnSelectAccountParam

Parameter of Endpoint::onSelectAccount() callback.

Public Members

SipRxData rdata

The incoming request.

int accountIndex

The account index to be used to handle the request. Upon entry, this will be filled by the account index chosen by the library. Application may change it to another value to use another account.

Other

struct PendingJob

Public Functions

virtual void execute(bool is_pending) = 0

Perform the job

virtual ~PendingJob()

Virtual destructor