CAF: Leg Creation Samples
Contents |
Creating a Standalone Outgoing Call
First you must build the outgoing leg attribute:
PTRCTBCMC_CALL_LEG_ATTRIBUTE ptrOutgoingLegAttribute; ptrOutgoingLegAttribute = tbnew CTBCMC_CALL_LEG_ATTRIBUTE(); ptrOutgoingLegAttribute->GetCalledNumber() = "123-4567"; ptrOutgoingLegAttribute->GetCallingNumber() = "987-6543"; ptrOutgoingLegAttribute->GetNetworkAccessPoint() = "NAP_SS7_MONTREAL";
Once you have all your parameters set, you can now create the outgoing call leg like this:
PTRCTBCAFCallLeg ptrOutgoingCallLeg = CreateOutgoingCallLeg(ptrOutgoingLegAttribute);
The function CreateOutgoingCallLeg() will do all the work to create the leg and will return it. You have now an active outgoing call leg.
Bridging an Incoming Call (manual method)
TODO ADD SAMPLE CODE
Bridging an Incoming Call (using CTBCAFBridge )
TODO ADD SAMPLE CODE
Creating a Media-only Leg
You must first create a media only leg attribute:
PTRCTBCMC_MEDIA_ONLY_LEG_ATTRIBUTE ptrLegAttribute; ptrLegAttribute = tbnew CTBCMC_MEDIA_ONLY_LEG_ATTRIBUTE(); ptrLegAttribute->GetNetworkAccessPoint() = "NAP_SS7_MONTREAL"; pMediaDesc = ptrLegAttribute->GetProfile()->MediaDescription; pMediaDesc->Type = TBCMC_MEDIA_TYPE_AUDIO; pMediaDesc->Transport = TBCMC_MEDIA_TRANSPORT_TDM or TBCMC_MEDIA_TRANSPORT_IP;
Depending on which type of NAP your using, some parameters must be set. If you are using the NAP_MEDIA_TDM:
pMediaDesc->Settings.TdmAudio.Type = TBCMC_MEDIA_SETTINGS_TYPE_TDM_AUDIO; pMediaDesc->Settings.TdmAudio.un8Timeslot = 5; Strncpy ( pMediaDesc->Settings.TdmAudio.szTrunkName, "TRUNK_TORONTO_1", sizeof(pMediaDesc->Settings.TdmAudio.szTrunkName) );
If you are using the NAP_MEDIA_VOIP:
TBX_RESULT Result; TBX_SDP_INFO SdpInfo; pMediaDesc->Settings.PacketAudio.Type = TBCMC_MEDIA_SETTINGS_TYPE_PACKET_AUDIO; // Set Local SDP Result = BuildSdpInfo("", 0, SdpInfo); // No IP specified, Toolpack will choose one TBCAF_EXIT_ON_ERROR( Result, "BuildSdpInfo failed." ); ptrLegAttribute->SetLocalSDP(&SdpInfo); // Set Peer SDP Result = BuildSdpInfo("10.0.0.15", 5000, SdpInfo); // Using peer IP address and port TBCAF_EXIT_ON_ERROR( Result, "BuildSdpInfo failed." ); ptrLegAttribute->SetPeerSDP(&SdpInfo);
Here is the implementation of BuildSdpInfo:
TBX_RESULT CTBS2GWSimpleMediaCall::BuildSdpInfo ( IN PTBX_CHAR in_pszIp, IN TBX_UINT32 in_un32Port, OUT TBX_SDP_INFO& out_SdpInfo ) { TBCAF_MUTEX_GET_SCOPE_BEGIN( &mMutex ) PTBX_MEDIA_CAPABILITY pCap; PTBX_SDP_MEDIA_CONNECTION pConn; PTBX_MEDIA_CAPABILITY_DESCRIPTION pMediaDesc; /*--------------------------------------------------------------------------------------------------------------------------- | Code section *--------------------------------------------------------------------------------------------------------------------------*/ CAFCODE( CTBS2GWSimpleMediaCall::BuildSdpInfo ) { memset(&out_SdpInfo, 0, sizeof(out_SdpInfo)); // Set capabilities pCap = &( out_SdpInfo.Capabilities.aMediaCap[ out_SdpInfo.Capabilities.un8NbMediaCapabilities ] ); { /* Reserve this capability in aMediaCap */ out_SdpInfo.Capabilities.un8NbMediaCapabilities++; pCap->Encoding.MediaType = TBX_MEDIA_TYPE_AUDIO_PCMU; pCap->Direction = TBX_MEDIA_DIRECTION_RX_TX_SAME; pCap->Transport.Type = TBX_MEDIA_TRANSPORT_TYPE_RTP; pCap->Transport.Rtp.PayloadType = TBX_MEDIA_PAYLOAD_TYPE_PCMU; pCap->Transport.Rtp.un16MaxAudioFramesPerPacket = 160; pCap->Transport.Rtp.un16PacketDurationMs = 20;
} pCap = &( out_SdpInfo.Capabilities.aMediaCap[ out_SdpInfo.Capabilities.un8NbMediaCapabilities ] ); { /* Reserve this capability in aMediaCap */ out_SdpInfo.Capabilities.un8NbMediaCapabilities++;
pCap->Encoding.MediaType = TBX_MEDIA_TYPE_AUDIO_PCMA; pCap->Direction = TBX_MEDIA_DIRECTION_RX_TX_SAME;
pCap->Transport.Type = TB X_MEDIA_TRANSPORT_TYPE_RTP;
pCap->Transport.Rtp.PayloadType = TBX_MEDIA_PAYLOAD_TYPE_PCMA; pCap->Transport.Rtp.un16MaxAudioFramesPerPacket = 160; pCap->Transport.Rtp.un16PacketDurationMs = 40; } out_SdpInfo.Capabilities.un8NbCapabilityGroups = 1; out_SdpInfo.Capabilities.aCapGroups[0].un8NbSimultaneousCap = 1; pMediaDesc = &( out_SdpInfo.Capabilities.aCapGroups[0].aSimultaneousCap[ 0 ] ); pMediaDesc->un8NbPorts = in_un32Port ? 1 : 0; pMediaDesc->un16UdpPort = in_un32Port; pMediaDesc->un8ConnectionIdx = 0; pMediaDesc->un8NbChoices = 2; pMediaDesc->aMediaCapChoices[0] = 0; pMediaDesc->aMediaCapChoices[1] = 1; // Set connection info pConn = &out_SdpInfo.aConnections[out_SdpInfo.un8NbConnections]; pConn->un32NumAddr = 0; /* Not used, not multicast */ pConn->un16Ttl = 0; /* Not used, not multicast */ pConn->IPDescriptionType = (TBX_UINT8)TBX_SDP_MEDIA_IP_DESCRIPTION_TYPE_IPV4_ADDRESS; Strncpy ( pConn->szIp, in_pszIp, sizeof( pConn->szIp ) ); out_SdpInfo.un8NbConnections++; TBX_EXIT_SUCCESS( TBX_RESULT_OK ); } /*--------------------------------------------------------------------------------------------------------------------------- | Exception handling section *--------------------------------------------------------------------------------------------------------------------------*/ CAF_EXCEPTION_HANDLING /*--------------------------------------------------------------------------------------------------------------------------- | Error handling section *--------------------------------------------------------------------------------------------------------------------------*/ CAF_ERROR_HANDLING( CAF_VERBOSE )
{ }
/*--------------------------------------------------------------------------------------------------------------------------- | Cleanup section *--------------------------------------------------------------------------------------------------------------------------*/ CAF_CLEANUP { }
RETURN;
TBCAF_MUTEX_GET_SCOPE_END( &mMutex ) }