Skip to main content

Writing New VoIP Application

Writing new VoIP application using sk400vop is straightforward due to availability of high-level API. This is in contrast to other commercial and open-source solutions that export low-level APIs and require a whole lot of signaling knowledge onbehalf of application developer.

sk400vop demo code can be used as template for writing new application for Windows and Linux platforms. For others, the same pattern can befollowed. The following section describes the demo application step-by-step.

Including header files

Some basic header files have to be included in the main source file (andall other application level source files):

#include"common.h"

#include"ippapi.h"

Initializing the callbacks and registry information

Before initializing the signaling component, the configuration structure hasto be populated with callbacks and registry information. The example code populates all three types of callback structures:

/\*Init callback interfaces and pass on to signaling \*/

ippconf.sigCB.eventHandler = uiEventCallback;

ippconf.mediaCB.mediaContextCreate = (MEDIA\_CONTEXT\_CREATE\_CB) mediaContextCreate;

ippconf.mediaCB.mediaContextDestroy = (MEDIA\_CONTEXT\_DESTROY\_CB) mediaContextDestroy;

ippconf.mediaCB.mediaSetFormat = (MEDIA\_SET\_FORMAT\_CB) mediaSetFormat;

ippconf.mediaCB.mediaDecodeAndRender = (MEDIA\_DECODE\_AND\_RENDER\_CB) mediaDecodeAndRender;

ippconf.mediaCB.mediaCaptureAndEncode = (MEDIA\_CAPTURE\_AND\_ENCODE\_CB) mediaCaptureAndEncode;

ippconf.netCB.socketCreate= (SOCK\_CREATE\_CB) socket;

ippconf.netCB.socketClose = (SOCK\_CLOSE\_CB) closesocket;

ippconf.netCB.socketBind = (SOCK\_BIND\_CB) bind;

ippconf.netCB.socketSendTo= (SOCK\_SENDTO\_CB) sendto;

ippconf.netCB.socketReceiveFrom= (SOCK\_RECEIVEFROM\_CB) recvfrom;

ippconf.netCB.socketIoctl = (SOCK\_IOCTL\_CB) ioctlsocket;

ippconf.netCB.inetPToN = (INET\_PTON\_CB) inet\_pton;

ippconf.netCB.inetNToP = (INET\_NTOP\_CB) inet\_ntop;

ippconf.netCB.netMatchSubnet = (NET\_MATCH\_SUBNET\_CB) netMatchSubnet;

ippconf.netCB.netGetLocalAddr = (NET\_GET\_LOCAL\_ADDR\_CB) netGetLocalAddr;

ippconf.netCB.netGetMappedAddr = (NET\_GET\_MAPPED\_ADDR\_CB) netGetMappedAddr;

ippconf.netCB.netResolveHost = (NET\_RESOLVE\_HOST\_CB) netResolveHost;

Referringto the example, following code initializes a SIP registry:

ippconf.sipPortUDP = 5060;

ippconf.numRegistries = 1;

/\*First registry - SIP \*/

ippconf.registryInfo\[0\].protocol= SIG\_PROTO\_SIP;

strcpy(ippconf.registryInfo\[0\].username,"101");

strcpy(ippconf.registryInfo\[0\].password,"101");

strcpy(ippconf.registryInfo\[0\].context,"");

strcpy(ippconf.registryInfo\[0\].servername,"192.168.1.100");

ippconf.registryInfo\[0\].serverport= ntohs(5060);

ippconf.registryInfo\[0\].regRefreshTime= 0;

ippconf.registryInfo\[0\].status= REG\_PENDING;

Initializing signaling

Signaling module can now be initializing by invoking API call with initialized configuration structure as first parameter and required signaling protocols bitmap as second parameter:

/* Initialize signaling */

err= ippInitMessaging(&ippconf, SIG\_PROTO\_SIP);

Adding supported codecs

Supported media codecs should be added in order of preference. In the examplecode, ALAW is added first and thus is the preferred codec when negotiating codecs:

/* Add supported codecs in order of preference */

ippAddCodec(MT_AUDIO,PT_ALAW, 8000, 1, EN_ALAW);

ippAddCodec(MT_AUDIO,PT_ULAW, 8000, 1, EN_ULAW);

Registering with server

Following API call is necessary to specify preferred registry refresh interval(in seconds). This is a blocking call and will return only when all registrations have completed with failure/success:

printf("Registering with server...");

ippRegister(3600);

Startingsignaling

After all the initialization steps, signaling can be started. Following call starts signaling. This call never returns and thus should becalled from a separate dedicated thread in a multi-threaded environment or should be the last call in OS-less environment:

printf("Starting signalling...\\r\\n");

ippStartMessaging();