CAF: Filling SDP Structures

From TBwiki
(Difference between revisions)
Jump to: navigation, search
Line 29: Line 29:
 
    
 
    
 
       '''strSdpText = SdpProfile.str_sdp_text;'''
 
       '''strSdpText = SdpProfile.str_sdp_text;'''
  '''if( !strSdpText.EndsWith( "\r\n" ) )'''
+
  '''if( !strSdpText.EndsWith( "\r\n" ) )'''
  '''{'''
+
  '''{'''
  '''      strSdpText.Append( "\r\n" );'''
+
  '''      strSdpText.Append( "\r\n" );'''
  '''}'''
+
  '''}'''
 
+
  '''/* Fill media capabilities */'''
+
  '''/* Fill media capabilities */'''
  '''Result = TBXMediaLibSdpParse'''
+
  '''Result = TBXMediaLibSdpParse'''
  '''('''
+
  '''('''
 
  '''    (PTBX_CHAR)strSdpText.c_str(),'''
 
  '''    (PTBX_CHAR)strSdpText.c_str(),'''
 
  '''    &SdpInfo,'''
 
  '''    &SdpInfo,'''
 
  '''    TBX_MEDIA_SDP_PARSE_OPTION_DEFAULT'''
 
  '''    TBX_MEDIA_SDP_PARSE_OPTION_DEFAULT'''
  ''');'''
+
  ''');'''
 
   
 
   
  '''// SdpInfo is now filled with the info from the text SDP'''
+
  '''// SdpInfo is now filled with the info from the text SDP'''
 
  }
 
  }
  

Revision as of 13:25, 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 )
 }
Personal tools