Skip to content

Reflow API

Scott Godin edited this page Mar 5, 2021 · 1 revision

Table of Contents

Flow Manager APIs

Flow Manager Object

An application should create one instance of the FlowManager object. Once an application determines that an audio media stream is needed it uses the following API call on the FlowManager object to create a MediaStream object.

  MediaStream* createMediaStream(MediaStreamHandler& mediaStreamHandler,
                                 const StunTuple& localBinding, 
                                 bool rtcpEnabled = true,
                                 Flow::NatTraversalMode natTraversalMode = Flow::NoNatTraversal,
                                 const char* natTraversalServerHostname = 0, 
                                 unsigned short natTraversalServerPort = 0, 
                                 const char* stunUsername = 0,
                                 const char* stunPassword = 0);

Possible NatTraversalModes are:

  • NoNatTraveral - just send media to/from localBinding
  • StunBindDiscovery - send STUN bind request to stun server specified and fire an event when discovered reflexive mapping is retrieved
  • TurnUdpAllocation - send a TURN allocation request via UDP to the turn server specified and fire an event when the allocation is complete and allocated address is known
  • TurnTcpAllocation - send a TURN allocation request via TCP to the turn server specified and fire an event when the allocation is complete and allocated address is known - this allows us to tunnel media via TCP to the TURN server which is relayed via UDP to the peer
  • TurnTlsAllocation - send a TURN allocation request via TLS to the turn server specified and fire an event when the allocation is complete and allocated address is known - this allows us to tunnel media via TCP to the TURN server which is relayed via UDP to the peer

MediaStream Handler

MediaStreamHandler class passed in will receive event notifications:

  • virtual void onMediaStreamReady(const StunTuple& rtpTuple, const StunTuple& rtcpTuple) = 0;
  • virtual void onMediaStreamError(unsigned int errorCode) = 0;

MediaStream Object

Each created Media Stream consists of one or two flows, depending on whether RTCP is enabled or not. The Flow objects can be obtained from the MediaStream via the following MediaStream API's:

  • Flow* getRtpFlow();
  • Flow* getRtcpFlow();



Flow Object

Each Flow can then be used to send/receive media after the onMediaStreamReady callback has been received. The following Flow API's are available:

  /// Returns a socket descriptor that can be used in a select call
  /// WARNING - this descriptor should not be used for any other purpose
  /// - do NOT set socket options, or send, receive from this descriptor,
  /// instead use the Flow api's
  unsigned int getSelectSocketDescriptor(); 
  unsigned int getSocketDescriptor(); // returns the real socket descriptor - can be used to 
                                    // correlate callbacks
 
  /// Turn Send Methods
  void send(const char* buffer, unsigned int size);
  void sendTo(const asio::ip::address& address, unsigned short port, const char* buffer, 
              unsigned int size); 
 
  /// Receive Methods
  asio::error_code receive(char* buffer, unsigned int& size, unsigned int timeout, 
                           asio::ip::address* sourceAddress=0, unsigned short* sourcePort=0);
  asio::error_code receiveFrom(const asio::ip::address& address, unsigned short port, 
                               char* buffer, unsigned int& size, unsigned int timeout);
  
  /// Used to set where this flow should be sending to
  void setActiveDestination(const char* address, unsigned short port); 
 
  const StunTuple& getLocalTuple();
  StunTuple getSessionTuple(); // returns either local, reflexive, or relay tuple depending 
                               // on NatTraversalMode
  StunTuple getRelayTuple();
  StunTuple getReflexiveTuple();

Using SRTP support in FlowManager

DTLS-SRTP Support

FlowManager::initializeDtlsFactory must be called during application initialization by passing in an AOR to use in the automatically generated client certificate that may be used with dtls-srtp.

The following API's on the Flow object are then used to control dtls-srtp:

  /// This method should be called when remote fingerprint is discovered
  /// via SDP negotiation.  After this is called only dtls-srtp connections
  /// with a matching fingerprint will be maintained.
  void setRemoteSDPFingerprint(const resip::Data& fingerprint);

SDES SRTP Support

If using SDES srtp key negotiation, then the following two API's on the MediaStream object are used in order to initialize the SRTP sessions before sending or receiving on the RTP or RTCP flows.

   bool createOutboundSRTPSession(SrtpCryptoSuite cryptoSuite, const char* key, unsigned int keyLen);
   bool createInboundSRTPSession(SrtpCryptoSuite cryptoSuite, const char* key, unsigned int keyLen);
Clone this wiki locally