CAF: Filling SDP Structures
From TBwiki
(Difference between revisions)
(→Filling a TBX_SDP_INFO structure from a formatted text:) |
m |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
− | There are two ways to fill a TBX_SDP_INFO structure. | + | There are two ways to fill a TBX_SDP_INFO structure. |
− | ===Filling a TBX_SDP_INFO structure from a | + | === Filling a TBX_SDP_INFO structure from a text SDP: === |
TBX_RESULT CallBridgingSampleLoadConfig_DB | TBX_RESULT CallBridgingSampleLoadConfig_DB | ||
Line 12: | Line 12: | ||
CTBCAFOam_sdp_profiles_db_acc AccessSdpProfiles; | CTBCAFOam_sdp_profiles_db_acc AccessSdpProfiles; | ||
PITBCAFDb pCfgDb; | PITBCAFDb pCfgDb; | ||
− | std::vector | + | std::vector<CTBCAFOam_sdp_profiles> SdpProfiles; |
CTBCAFOam_sdp_profiles SdpProfile; | CTBCAFOam_sdp_profiles SdpProfile; | ||
TBX_SDP_INFO SdpInfo; | TBX_SDP_INFO SdpInfo; | ||
CTBCAFString strSdpText; | CTBCAFString strSdpText; | ||
− | pCfgDb = in_pContext- | + | pCfgDb = in_pContext->pCppCtx->pCfgDb; |
Result = AccessSdpProfiles.Init(pCfgDb); | Result = AccessSdpProfiles.Init(pCfgDb); | ||
Line 28: | Line 28: | ||
SdpProfile = SdpProfiles[0]; | SdpProfile = SdpProfiles[0]; | ||
− | strSdpText = SdpProfile.str_sdp_text; | + | '''strSdpText = SdpProfile.str_sdp_text;''' |
− | + | '''if( !strSdpText.EndsWith( "\r\n" ) )''' | |
− | + | '''{''' | |
− | + | ''' strSdpText.Append( "\r\n" );''' | |
− | + | '''}''' | |
− | + | ||
− | + | '''/* Fill media capabilities */''' | |
− | + | '''Result = TBXMediaLibSdpParse''' | |
− | + | '''(''' | |
− | + | ''' (PTBX_CHAR)strSdpText.c_str(),''' | |
− | + | ''' &SdpInfo,''' | |
− | + | ''' TBX_MEDIA_SDP_PARSE_OPTION_DEFAULT''' | |
− | + | ''');''' | |
− | + | ||
+ | '''// SdpInfo is now filled with the info from the text SDP''' | ||
+ | } | ||
− | ===Filling a TBX_SDP_INFO structure manually:=== | + | === Filling a TBX_SDP_INFO structure manually: === |
TBX_RESULT CTBS2GWSimpleMediaCall::BuildSdpInfo | TBX_RESULT CTBS2GWSimpleMediaCall::BuildSdpInfo | ||
Line 49: | Line 51: | ||
IN PTBX_CHAR in_pszIp, | IN PTBX_CHAR in_pszIp, | ||
IN TBX_UINT32 in_un32Port, | IN TBX_UINT32 in_un32Port, | ||
− | OUT TBX_SDP_INFO& out_SdpInfo | + | OUT TBX_SDP_INFO& out_SdpInfo |
) | ) | ||
{ | { | ||
− | TBCAF_MUTEX_GET_SCOPE_BEGIN( &mMutex ) | + | TBCAF_MUTEX_GET_SCOPE_BEGIN( &mMutex ) |
PTBX_MEDIA_CAPABILITY pCap; | PTBX_MEDIA_CAPABILITY pCap; | ||
PTBX_SDP_MEDIA_CONNECTION pConn; | PTBX_SDP_MEDIA_CONNECTION pConn; | ||
Line 61: | Line 63: | ||
CAFCODE( CTBS2GWSimpleMediaCall::BuildSdpInfo ) | CAFCODE( CTBS2GWSimpleMediaCall::BuildSdpInfo ) | ||
{ | { | ||
− | memset(&out_SdpInfo, 0, sizeof(out_SdpInfo)); | + | memset(&out_SdpInfo, 0, sizeof(out_SdpInfo)); |
// Set capabilities | // Set capabilities | ||
− | pCap = &( out_SdpInfo.Capabilities.aMediaCap[ out_SdpInfo.Capabilities.un8NbMediaCapabilities ] ); | + | pCap = &( out_SdpInfo.Capabilities.aMediaCap[ out_SdpInfo.Capabilities.un8NbMediaCapabilities ] ); |
{ | { | ||
/* Reserve this capability in aMediaCap */ | /* Reserve this capability in aMediaCap */ | ||
out_SdpInfo.Capabilities.un8NbMediaCapabilities++; | out_SdpInfo.Capabilities.un8NbMediaCapabilities++; | ||
− | pCap- | + | pCap->Encoding.MediaType = TBX_MEDIA_TYPE_AUDIO_PCMU; |
− | pCap- | + | pCap->Direction = TBX_MEDIA_DIRECTION_RX_TX_SAME; |
− | pCap- | + | pCap->Transport.Type = TBX_MEDIA_TRANSPORT_TYPE_RTP; |
− | pCap- | + | pCap->Transport.Rtp.PayloadType = TBX_MEDIA_PAYLOAD_TYPE_PCMU; |
− | pCap- | + | pCap->Transport.Rtp.un16MaxAudioFramesPerPacket = 160; |
− | pCap- | + | pCap->Transport.Rtp.un16PacketDurationMs = 20; |
} | } | ||
− | pCap = &( out_SdpInfo.Capabilities.aMediaCap[ out_SdpInfo.Capabilities.un8NbMediaCapabilities ] ); | + | pCap = &( out_SdpInfo.Capabilities.aMediaCap[ out_SdpInfo.Capabilities.un8NbMediaCapabilities ] ); |
{ | { | ||
/* Reserve this capability in aMediaCap */ | /* Reserve this capability in aMediaCap */ | ||
out_SdpInfo.Capabilities.un8NbMediaCapabilities++; | out_SdpInfo.Capabilities.un8NbMediaCapabilities++; | ||
− | pCap- | + | pCap->Encoding.MediaType = TBX_MEDIA_TYPE_AUDIO_PCMA; |
− | pCap- | + | pCap->Direction = TBX_MEDIA_DIRECTION_RX_TX_SAME; |
− | pCap- | + | pCap->Transport.Type = TBX_MEDIA_TRANSPORT_TYPE_RTP; |
− | pCap- | + | pCap->Transport.Rtp.PayloadType = TBX_MEDIA_PAYLOAD_TYPE_PCMA; |
− | pCap- | + | pCap->Transport.Rtp.un16MaxAudioFramesPerPacket = 160; |
− | pCap- | + | pCap->Transport.Rtp.un16PacketDurationMs = 40; |
} | } | ||
out_SdpInfo.Capabilities.un8NbCapabilityGroups = 1; | out_SdpInfo.Capabilities.un8NbCapabilityGroups = 1; | ||
out_SdpInfo.Capabilities.aCapGroups[0].un8NbSimultaneousCap = 1; | out_SdpInfo.Capabilities.aCapGroups[0].un8NbSimultaneousCap = 1; | ||
− | pMediaDesc = &( out_SdpInfo.Capabilities.aCapGroups[0].aSimultaneousCap[ 0 ] ); | + | pMediaDesc = &( out_SdpInfo.Capabilities.aCapGroups[0].aSimultaneousCap[ 0 ] ); |
− | pMediaDesc- | + | pMediaDesc->un8NbPorts = in_un32Port ? 1 : 0; |
− | pMediaDesc- | + | pMediaDesc->un16UdpPort = in_un32Port; |
− | pMediaDesc- | + | pMediaDesc->un8ConnectionIdx = 0; |
− | pMediaDesc- | + | pMediaDesc->un8NbChoices = 2; |
− | pMediaDesc- | + | pMediaDesc->aMediaCapChoices[0] = 0; |
− | pMediaDesc- | + | pMediaDesc->aMediaCapChoices[1] = 1; |
// Set connection info | // Set connection info | ||
− | pConn = &out_SdpInfo.aConnections[out_SdpInfo.un8NbConnections]; | + | pConn = &out_SdpInfo.aConnections[out_SdpInfo.un8NbConnections]; |
− | pConn- | + | pConn->un32NumAddr = 0; /* Not used, not multicast */ |
− | pConn- | + | pConn->un16Ttl = 0; /* Not used, not multicast */ |
− | pConn- | + | pConn->IPDescriptionType = (TBX_UINT8)TBX_SDP_MEDIA_IP_DESCRIPTION_TYPE_IPV4_ADDRESS; |
Strncpy | Strncpy | ||
( | ( | ||
− | pConn- | + | pConn->szIp, |
in_pszIp, | in_pszIp, | ||
− | sizeof( pConn- | + | sizeof( pConn->szIp ) |
); | ); | ||
out_SdpInfo.un8NbConnections++; | out_SdpInfo.un8NbConnections++; | ||
Line 134: | Line 136: | ||
RETURN; | RETURN; | ||
− | TBCAF_MUTEX_GET_SCOPE_END( &mMutex ) | + | TBCAF_MUTEX_GET_SCOPE_END( &mMutex ) |
} | } | ||
− | + | [[Category:CAF]] | |
− | + | ||
− | [[ | + |
Latest revision as of 13:26, 5 March 2010
There are two ways to fill a TBX_SDP_INFO structure.
Filling a TBX_SDP_INFO structure from a text SDP:
TBX_RESULT CallBridgingSampleLoadConfig_DB ( IN PCALL_BRIDGING_SAMPLE_CONTEXT in_pContext, OUT PCALL_BRIDGING_SAMPLE_DYNAMIC_CONFIG out_pDynamicConfig, OUT TBX_CHAR out_szResult[ TBCAF_DB_FULL_PATH_NAME_MAX ] ) { CTBCAFOam_sdp_profiles_db_acc AccessSdpProfiles; PITBCAFDb pCfgDb; std::vector<CTBCAFOam_sdp_profiles> SdpProfiles; CTBCAFOam_sdp_profiles SdpProfile; TBX_SDP_INFO SdpInfo; CTBCAFString strSdpText; pCfgDb = in_pContext->pCppCtx->pCfgDb; Result = AccessSdpProfiles.Init(pCfgDb); if (TBX_RESULT_FAILURE(Result)) { TBX_EXIT_ERROR (Result, 0, "Cannot init AccessSdpProfiles" ); } SdpProfiles = AccessSdpProfiles.GetAllBy_profile_id( 1 ); SdpProfile = SdpProfiles[0]; strSdpText = SdpProfile.str_sdp_text; if( !strSdpText.EndsWith( "\r\n" ) ) { strSdpText.Append( "\r\n" ); } /* Fill media capabilities */ Result = TBXMediaLibSdpParse ( (PTBX_CHAR)strSdpText.c_str(), &SdpInfo, TBX_MEDIA_SDP_PARSE_OPTION_DEFAULT ); // SdpInfo is now filled with the info from the text SDP }
Filling a TBX_SDP_INFO structure manually:
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 = TBX_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 ) }