CAF: Filling SDP Structures

From TBwiki
(Difference between revisions)
Jump to: navigation, search
(Created page with 'ferwferfre')
 
Line 1: Line 1:
ferwferfre
+
Here is an example of how you can build and fill 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 )
 +
  }

Revision as of 08:09, 21 October 2009

Here is an example of how you can build and fill 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