BLOG | DOCUMENTATION | TRAC

Home --> Documentations --> PJSIP Reference

#include <endpoint.hpp>

Public Member Functions

 Endpoint ()
 
virtual ~Endpoint ()
 
Version libVersion () const
 
void libCreate () PJSUA2_THROW(Error)
 
pjsua_state libGetState () const
 
void libInit (const EpConfig &prmEpConfig) PJSUA2_THROW(Error)
 
void libStart () PJSUA2_THROW(Error)
 
void libRegisterThread (const string &name) PJSUA2_THROW(Error)
 
bool libIsThreadRegistered ()
 
void libStopWorkerThreads ()
 
int libHandleEvents (unsigned msec_timeout)
 
void libDestroy (unsigned prmFlags=0) PJSUA2_THROW(Error)
 
string utilStrError (pj_status_t prmErr)
 
void utilLogWrite (int prmLevel, const string &prmSender, const string &prmMsg)
 
void utilLogWrite (LogEntry &e)
 
pj_status_t utilVerifySipUri (const string &prmUri)
 
pj_status_t utilVerifyUri (const string &prmUri)
 
Token utilTimerSchedule (unsigned prmMsecDelay, Token prmUserData) PJSUA2_THROW(Error)
 
void utilTimerCancel (Token prmToken)
 
void utilAddPendingJob (PendingJob *job)
 
IntVector utilSslGetAvailableCiphers () PJSUA2_THROW(Error)
 
void natDetectType (void) PJSUA2_THROW(Error)
 
pj_stun_nat_type natGetType () PJSUA2_THROW(Error)
 
void natUpdateStunServers (const StringVector &prmServers, bool prmWait) PJSUA2_THROW(Error)
 
void natCheckStunServers (const StringVector &prmServers, bool prmWait, Token prmUserData) PJSUA2_THROW(Error)
 
void natCancelCheckStunServers (Token token, bool notify_cb=false) PJSUA2_THROW(Error)
 
TransportId transportCreate (pjsip_transport_type_e type, const TransportConfig &cfg) PJSUA2_THROW(Error)
 
IntVector transportEnum () PJSUA2_THROW(Error)
 
TransportInfo transportGetInfo (TransportId id) PJSUA2_THROW(Error)
 
void transportSetEnable (TransportId id, bool enabled) PJSUA2_THROW(Error)
 
void transportClose (TransportId id) PJSUA2_THROW(Error)
 
void transportShutdown (TransportHandle tp) PJSUA2_THROW(Error)
 
void hangupAllCalls (void)
 
void mediaAdd (AudioMedia &media)
 
void mediaRemove (AudioMedia &media)
 
bool mediaExists (const AudioMedia &media) const
 
unsigned mediaMaxPorts () const
 
unsigned mediaActivePorts () const
 
const AudioMediaVectormediaEnumPorts () const PJSUA2_THROW(Error)
 
AudioMediaVector2 mediaEnumPorts2 () const PJSUA2_THROW(Error)
 
VideoMediaVector mediaEnumVidPorts () const PJSUA2_THROW(Error)
 
AudDevManageraudDevManager ()
 
VidDevManagervidDevManager ()
 
const CodecInfoVectorcodecEnum () PJSUA2_THROW(Error)
 
CodecInfoVector2 codecEnum2 () const PJSUA2_THROW(Error)
 
void codecSetPriority (const string &codec_id, pj_uint8_t priority) PJSUA2_THROW(Error)
 
CodecParam codecGetParam (const string &codec_id) const PJSUA2_THROW(Error)
 
void codecSetParam (const string &codec_id, const CodecParam param) PJSUA2_THROW(Error)
 
const CodecInfoVectorvideoCodecEnum () PJSUA2_THROW(Error)
 
CodecInfoVector2 videoCodecEnum2 () const PJSUA2_THROW(Error)
 
void videoCodecSetPriority (const string &codec_id, pj_uint8_t priority) PJSUA2_THROW(Error)
 
VidCodecParam getVideoCodecParam (const string &codec_id) const PJSUA2_THROW(Error)
 
void setVideoCodecParam (const string &codec_id, const VidCodecParam &param) PJSUA2_THROW(Error)
 
void resetVideoCodecParam (const string &codec_id) PJSUA2_THROW(Error)
 
StringVector srtpCryptoEnum () PJSUA2_THROW(Error)
 
void handleIpChange (const IpChangeParam &param) PJSUA2_THROW(Error)
 
virtual void onNatDetectionComplete (const OnNatDetectionCompleteParam &prm)
 
virtual void onNatCheckStunServersComplete (const OnNatCheckStunServersCompleteParam &prm)
 
virtual void onTransportState (const OnTransportStateParam &prm)
 
virtual void onTimer (const OnTimerParam &prm)
 
virtual void onSelectAccount (OnSelectAccountParam &prm)
 
virtual void onIpChangeProgress (OnIpChangeProgressParam &prm)
 
virtual void onMediaEvent (OnMediaEventParam &prm)
 

Static Public Member Functions

static Endpointinstance () PJSUA2_THROW(Error)
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ Endpoint()

pj::Endpoint::Endpoint ( )

Default constructor

◆ ~Endpoint()

virtual pj::Endpoint::~Endpoint ( )
virtual

Virtual destructor

Member Function Documentation

◆ instance()

static Endpoint& pj::Endpoint::instance ( )
static

Retrieve the singleton instance of the endpoint

◆ libVersion()

Version pj::Endpoint::libVersion ( ) const

Get library version.

◆ libCreate()

void pj::Endpoint::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.

◆ libGetState()

pjsua_state pj::Endpoint::libGetState ( ) const

Get library state.

Returns
library state.

◆ libInit()

void pj::Endpoint::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
prmEpConfigEndpoint configurations

◆ libStart()

void pj::Endpoint::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().

◆ libRegisterThread()

void pj::Endpoint::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
nameThe optional name to be assigned to the thread.

◆ libIsThreadRegistered()

bool pj::Endpoint::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().

◆ libStopWorkerThreads()

void pj::Endpoint::libStopWorkerThreads ( )

Stop all worker threads.

◆ libHandleEvents()

int pj::Endpoint::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.

Parameters
msec_timeoutMaximum time to wait, in miliseconds.
Returns
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).

◆ libDestroy()

void pj::Endpoint::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
prmFlagsCombination of pjsua_destroy_flag enumeration.

◆ utilStrError()

string pj::Endpoint::utilStrError ( pj_status_t  prmErr)

Retrieve the error string for the specified status code.

Parameters
prmErrThe error code.

◆ utilLogWrite() [1/2]

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

Write a log message.

Parameters
prmLevelLog verbosity level (1-5)
prmSenderThe log sender.
prmMsgThe log message.

◆ utilLogWrite() [2/2]

void pj::Endpoint::utilLogWrite ( LogEntry e)

Write a log entry.

Parameters
eThe log entry.

◆ utilVerifySipUri()

pj_status_t pj::Endpoint::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.

Parameters
prmUriThe URL string.
Returns
PJ_SUCCESS on success, or the appropriate error code.
See also
utilVerifyUri()

◆ utilVerifyUri()

pj_status_t pj::Endpoint::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.

Parameters
prmUriThe URL string.
Returns
PJ_SUCCESS on success, or the appropriate error code.
See also
pjsua_verify_sip_url()

◆ utilTimerSchedule()

Token pj::Endpoint::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.

Parameters
prmMsecDelayThe time interval in msec.
prmUserDataArbitrary user data, to be given back to application in the callback.
Returns
Token to identify the timer, which could be given to utilTimerCancel().

◆ utilTimerCancel()

void pj::Endpoint::utilTimerCancel ( Token  prmToken)

Cancel previously scheduled timer with the specified timer token.

Parameters
prmTokenThe timer token, which was returned from previous utilTimerSchedule() call.

◆ utilAddPendingJob()

void pj::Endpoint::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
jobThe job class.

◆ utilSslGetAvailableCiphers()

IntVector pj::Endpoint::utilSslGetAvailableCiphers ( )

Get cipher list supported by SSL/TLS backend.

◆ natDetectType()

void pj::Endpoint::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.

◆ natGetType()

pj_stun_nat_type pj::Endpoint::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.

◆ natUpdateStunServers()

void pj::Endpoint::natUpdateStunServers ( const StringVector prmServers,
bool  prmWait 
)

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

Parameters
prmServersArray 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)
prmWaitSpecify 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.

◆ natCheckStunServers()

void pj::Endpoint::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.

Parameters
prmServersArray 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)
prmWaitSpecify 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.
prmUserDataArbitrary user data to be passed back to application in the callback.
See also
natCancelCheckStunServers()

◆ natCancelCheckStunServers()

void pj::Endpoint::natCancelCheckStunServers ( Token  token,
bool  notify_cb = false 
)

Cancel pending STUN resolution which match the specified token.

Parameters
tokenThe token to match. This token was given to natCheckStunServers()
notify_cbBoolean 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.

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

◆ transportCreate()

TransportId pj::Endpoint::transportCreate ( pjsip_transport_type_e  type,
const TransportConfig cfg 
)

Create and start a new SIP transport according to the specified settings.

Parameters
typeTransport type.
cfgTransport configuration.
Returns
The transport ID.

◆ transportEnum()

IntVector pj::Endpoint::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.

Returns
Array of transport IDs.

◆ transportGetInfo()

TransportInfo pj::Endpoint::transportGetInfo ( TransportId  id)

Get information about transport.

Parameters
idTransport ID.
Returns
Transport info.

◆ transportSetEnable()

void pj::Endpoint::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
idTransport ID.
enabledEnable or disable the transport.

◆ transportClose()

void pj::Endpoint::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
idTransport ID.

◆ transportShutdown()

void pj::Endpoint::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
tpThe transport.

◆ hangupAllCalls()

void pj::Endpoint::hangupAllCalls ( void  )

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

◆ mediaAdd()

void pj::Endpoint::mediaAdd ( AudioMedia media)

Add media to the media list.

Parameters
mediamedia to be added.

◆ mediaRemove()

void pj::Endpoint::mediaRemove ( AudioMedia media)

Remove media from the media list.

Parameters
mediamedia to be removed.

◆ mediaExists()

bool pj::Endpoint::mediaExists ( const AudioMedia media) const

Check if media has been added to the media list.

Parameters
mediamedia to be check.
Returns
True if media has been added, false otherwise.

◆ mediaMaxPorts()

unsigned pj::Endpoint::mediaMaxPorts ( ) const

Get maximum number of media port.

Returns
Maximum number of media port in the conference bridge.

◆ mediaActivePorts()

unsigned pj::Endpoint::mediaActivePorts ( ) const

Get current number of active media port in the bridge.

Returns
The number of active media port.

◆ mediaEnumPorts()

const AudioMediaVector& pj::Endpoint::mediaEnumPorts ( ) const

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

Enumerate all media port.

Returns
The list of media port.

◆ mediaEnumPorts2()

AudioMediaVector2 pj::Endpoint::mediaEnumPorts2 ( ) const

Enumerate all audio media port.

Returns
The list of audio media port.

◆ mediaEnumVidPorts()

VideoMediaVector pj::Endpoint::mediaEnumVidPorts ( ) const

Enumerate all video media port.

Returns
The list of video media port.

◆ audDevManager()

AudDevManager& pj::Endpoint::audDevManager ( )

Get the instance of Audio Device Manager.

Returns
The Audio Device Manager.

◆ vidDevManager()

VidDevManager& pj::Endpoint::vidDevManager ( )

Get the instance of Video Device Manager.

Returns
The Video Device Manager.

◆ codecEnum()

const CodecInfoVector& pj::Endpoint::codecEnum ( )

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

Enum all supported codecs in the system.

Returns
Array of codec info.

◆ codecEnum2()

CodecInfoVector2 pj::Endpoint::codecEnum2 ( ) const

Enum all supported codecs in the system.

Returns
Array of codec info.

◆ codecSetPriority()

void pj::Endpoint::codecSetPriority ( const string &  codec_id,
pj_uint8_t  priority 
)

Change codec priority.

Parameters
codec_idCodec ID, which is a string that uniquely identify the codec (such as "speex/8000").
priorityCodec priority, 0-255, where zero means to disable the codec.

◆ codecGetParam()

CodecParam pj::Endpoint::codecGetParam ( const string &  codec_id) const

Get codec parameters.

Parameters
codec_idCodec ID.
Returns
Codec parameters. If codec is not found, Error will be thrown.

◆ codecSetParam()

void pj::Endpoint::codecSetParam ( const string &  codec_id,
const CodecParam  param 
)

Set codec parameters.

Parameters
codec_idCodec ID.
paramCodec parameter to set. Set to NULL to reset codec parameter to library default settings.

◆ videoCodecEnum()

const CodecInfoVector& pj::Endpoint::videoCodecEnum ( )

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

Enum all supported video codecs in the system.

Returns
Array of video codec info.

◆ videoCodecEnum2()

CodecInfoVector2 pj::Endpoint::videoCodecEnum2 ( ) const

Enum all supported video codecs in the system.

Returns
Array of video codec info.

◆ videoCodecSetPriority()

void pj::Endpoint::videoCodecSetPriority ( const string &  codec_id,
pj_uint8_t  priority 
)

Change video codec priority.

Parameters
codec_idCodec ID, which is a string that uniquely identify the codec (such as "H263/90000"). Please see pjsua manual or pjmedia codec reference for details.
priorityCodec priority, 0-255, where zero means to disable the codec.

◆ getVideoCodecParam()

VidCodecParam pj::Endpoint::getVideoCodecParam ( const string &  codec_id) const

Get video codec parameters.

Parameters
codec_idCodec ID.
Returns
Codec parameters. If codec is not found, Error will be thrown.

◆ setVideoCodecParam()

void pj::Endpoint::setVideoCodecParam ( const string &  codec_id,
const VidCodecParam param 
)

Set video codec parameters.

Parameters
codec_idCodec ID.
paramCodec parameter to set.

◆ resetVideoCodecParam()

void pj::Endpoint::resetVideoCodecParam ( const string &  codec_id)

Reset video codec parameters to library default settings.

Parameters
codec_idCodec ID.

◆ srtpCryptoEnum()

StringVector pj::Endpoint::srtpCryptoEnum ( )

Enumerate all SRTP crypto-suite names.

Returns
The list of SRTP crypto-suite name.

◆ handleIpChange()

void pj::Endpoint::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).
Parameters
paramThe IP change parameter, have a look at #IpChangeParam.
Returns
PJ_SUCCESS on success, other on error.

◆ onNatDetectionComplete()

virtual void pj::Endpoint::onNatDetectionComplete ( const OnNatDetectionCompleteParam prm)
inlinevirtual

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

Parameters
prmCallback parameters containing the detection result.

References PJ_UNUSED_ARG.

◆ onNatCheckStunServersComplete()

virtual void pj::Endpoint::onNatCheckStunServersComplete ( const OnNatCheckStunServersCompleteParam prm)
inlinevirtual

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

Parameters
prmCallback parameters.

References PJ_UNUSED_ARG.

◆ onTransportState()

virtual void pj::Endpoint::onTransportState ( const OnTransportStateParam prm)
inlinevirtual

This callback is called when transport state has changed.

Parameters
prmCallback parameters.

References PJ_UNUSED_ARG.

◆ onTimer()

virtual void pj::Endpoint::onTimer ( const OnTimerParam prm)
inlinevirtual

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

Parameters
prmCallback parameters.

References PJ_UNUSED_ARG.

◆ onSelectAccount()

virtual void pj::Endpoint::onSelectAccount ( OnSelectAccountParam prm)
inlinevirtual

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
prmCallback parameters.

References PJ_UNUSED_ARG.

◆ onIpChangeProgress()

virtual void pj::Endpoint::onIpChangeProgress ( OnIpChangeProgressParam prm)
inlinevirtual

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

Parameters
prmCallback parameters.

References PJ_UNUSED_ARG.

◆ onMediaEvent()

virtual void pj::Endpoint::onMediaEvent ( OnMediaEventParam prm)
inlinevirtual

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
prmCallback parameter.

References flags, info, PJ_UNUSED_ARG, pj::OnNatDetectionCompleteParam::reason, pj::OnNatDetectionCompleteParam::status, and user_data.


The documentation for this class was generated from the following file:

 


PJSIP Open Source, high performance, small footprint, and very very portable SIP stack
Copyright (C) 2006-2008 Teluu Inc.