The following example shows how to receive a VOIP call using Virtual Media Processing channels. To receive a VOIP call one needs to create a VMP channel and configure some codecs on that VMP channel. The VMP channel is then specified in the CCaccept() parameters when accepting the inbound call. The datafeeds from the VOX and VMP channels can then be connected in full duplex to allow voice prompts to be played or recorded over the VOIP call..
$include "aculab.inc"
main
int port,chan,vmp_chan,vox_chan,module_id;
int state,x,last_state;
var DNIS:50;
// Hard code these for this simple test..
port=0;
chan=1;
vox_chan=1;
module_id=0;
// Create a VMP port on DSP module 0
vmp_chan=SMcreateVMP(module_id);
if(vmp_chan < 0)
errlog("Could not open VMP channel: err=",vmp_chan);
stop;
endif
// Set G711 ALAW codec at element 0 in array of accepted codecs.
SMsetcodec(vmp_chan,0,G711_ALAW);
// Create full duplex connection between the VMP and the VOX datafeeds in advance..
SMfeedlisten(vox_chan,TYPE_VOX,vmp_chan,TYPE_VMP);
SMfeedlisten(vmp_chan,TYPE_VMP,vox_chan,TYPE_VOX);
// Now go wait for inbound IP call..
CCenablein(port,chan);
CCuse(port,chan); // cause jump to onsignal on disconnect
last_state=-1;
while(1)
// wait forever for a change in state
x=CCwait(port,chan,WAIT_FOREVER,&state,last_state);
last_state=state;
if(state eq CS_INCOMING_CALL_DET)
CCalerting(port,chan); // Send INCOMING RINGING.
CCgetparm(port,chan,CP_DESTINATION_ADDR,&DNIS);
applog("INCOMING CALL: DNIS=" & DNIS);
else if(state eq CS_WAIT_FOR_ACCEPT)
// We must set the VMP channel in the accept parameters for VOIP
CCclrparms(port,chan,PARM_TYPE_ACCEPT);
CCsetparm(port,chan,PARM_TYPE_ACCEPT,CP_IPTEL_VMPRXID,vmp_chan);
CCsetparm(port,chan,PARM_TYPE_ACCEPT,CP_IPTEL_VMPTXID,vmp_chan);
CCsetparm(port,chan,PARM_TYPE_ACCEPT,CP_IPTEL_CODECS,vmp_chan);
CCaccept(port,chan);
break;
endif endif
endwhile
//Now loop playing file /recording file/playing recording/getting DTMF...
//only hangup signal will interrupt this..
while(1)
SMplay(vox_line,"demo.vox");
x=SMplaytone(vox_line,19,100); // play a short beep
SMrecord(vox_line,"test.vox",10,5); // Record a short message
SMplay(vox_line,"test.vox"); // playback the recording
SMwaittones(vox_line,4,50,50); // wait for some DTMF
input=SMgettones(vox_line); // Retrieve the digits..
applog("Got input=",input); // display the digits..
endwhile
endmain
onsignal
applog("We are in ONSIGNAL!!!! Hangup signal was received..");
CCdisconnect(port,chan,LC_NORMAL);
# Now go wait for call to go idle
if(last_state <> CS_IDLE)
while(1)
# wait for idle
applog("In onsig CCwaiting for CS_IDLE");
x=CCwait(port,chan,10,&state,last_state);
applog("CCwait returned x=",x," state=",state);
if(state eq 0)
applog("port=" & port & " chan=" & chan & " Incoming went to IDLE");
break;
endif
sleep(1);
endwhile
endif
CCrelease(port,chan);
// Restart the program to receive another call..
restart;
endonsignal