Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
roc::pipeline::ReceiverSessionRouter Class Reference

Receiver session router. More...

#include <receiver_session_router.h>

Inheritance diagram for roc::pipeline::ReceiverSessionRouter:
Collaboration diagram for roc::pipeline::ReceiverSessionRouter:

Public Member Functions

 ReceiverSessionRouter (core::IArena &arena)
 Initialize. More...
 
 ~ReceiverSessionRouter ()
 Deinitialize. More...
 
size_t num_routes ()
 Get number of know routes. More...
 
core::SharedPtr< ReceiverSessionfind_by_source (packet::stream_source_t source_id)
 Find registered session by source id of sender's stream. More...
 
core::SharedPtr< ReceiverSessionfind_by_address (const address::SocketAddr &source_addr)
 Find registered session by source address of sender's stream. More...
 
bool has_session (const core::SharedPtr< ReceiverSession > &session)
 Check if there is a route for given session. More...
 
ROC_ATTR_NODISCARD status::StatusCode add_session (const core::SharedPtr< ReceiverSession > &session, packet::stream_source_t source_id, const address::SocketAddr &source_addr)
 Register session in router. More...
 
void remove_session (const core::SharedPtr< ReceiverSession > &session)
 Unregister session from router. More...
 
ROC_ATTR_NODISCARD status::StatusCode link_source (packet::stream_source_t source_id, const char *cname)
 Link source id with unique CNAME. More...
 
void unlink_source (packet::stream_source_t source_id)
 Unlink source id from session. More...
 

Detailed Description

Receiver session router.

Helps routing packets to sessions within session group.

Session group corresponds to all sessions handled by one receiver slot - a set of related complementary endpoints, e.g. one endpoint for audio, one for repair, and one for control packets.

For each remote sender, receiver creates a session inside session group. All audio, repair, and control packets from same sender are then routed to same session.

Session management is implemented in ReceiverSessionGroup, and algorithm for selecting session for a packet is implemented in ReceiverSessionRouter (this class).

Session router provides two methods to select session:

  • By source id.

    Sender can assign unique source id (SSRC) to each stream (audio, repair), and then transmit RTCP SDES packet that associate all sender's SSRCs with the same unique (randomly generated) CNAME string.

    Session router will remember that these SSRCs are related and will route packets from those streams to same session.

  • By source address.

    As a fallback for the case when RTCP is not used, session router will assume that packets with same source address belong to the same session.

    To make it work, sender should ensure that it sends all streams (audio, repair) from the same socket, and that there are no proxies or retranslators that combine multiple senders on the same socket.

Definition at line 67 of file receiver_session_router.h.

Constructor & Destructor Documentation

◆ ReceiverSessionRouter()

roc::pipeline::ReceiverSessionRouter::ReceiverSessionRouter ( core::IArena arena)

Initialize.

◆ ~ReceiverSessionRouter()

roc::pipeline::ReceiverSessionRouter::~ReceiverSessionRouter ( )

Deinitialize.

Member Function Documentation

◆ add_session()

ROC_ATTR_NODISCARD status::StatusCode roc::pipeline::ReceiverSessionRouter::add_session ( const core::SharedPtr< ReceiverSession > &  session,
packet::stream_source_t  source_id,
const address::SocketAddr source_addr 
)

Register session in router.

Remarks
  • session defines session where to route packets.
  • source_id defines SSRC of stream which will be routed to the session. Additional streams may be associated with same session via link_source() call.
  • source_addr defines source address which will be routed to the session. If other streams share the same source address, they will be routed to it.

◆ find_by_address()

core::SharedPtr<ReceiverSession> roc::pipeline::ReceiverSessionRouter::find_by_address ( const address::SocketAddr source_addr)

Find registered session by source address of sender's stream.

Remarks
Sender can use one source address for all its streams. Session router will remember this address and map it to sender's session.
Note
To make it work, sender's source address should be provided to add_session(), and all sender's streams should have the same source address.

◆ find_by_source()

core::SharedPtr<ReceiverSession> roc::pipeline::ReceiverSessionRouter::find_by_source ( packet::stream_source_t  source_id)

Find registered session by source id of sender's stream.

Remarks
Sender can have multiple streams, each with its own SSRC. Session router will remember all those SSRCs and map them to sender's session.
Note
To make it work, one of the SSRCs should be explicitly mapped to a session using add_session(), and the rest of SSRCs should be linked together using link_source() with same CNAME. The order of these calls does not matter.

◆ has_session()

bool roc::pipeline::ReceiverSessionRouter::has_session ( const core::SharedPtr< ReceiverSession > &  session)

Check if there is a route for given session.

Remarks
Will return false after session was removed via remove_session() or unlink_source().

◆ link_source()

ROC_ATTR_NODISCARD status::StatusCode roc::pipeline::ReceiverSessionRouter::link_source ( packet::stream_source_t  source_id,
const char *  cname 
)

Link source id with unique CNAME.

Remarks
Remembers what SSRCs are linked together by sharing the same CNAME. If/when one of the linked SSRCs is associated with a session using add_session(), all linked SSRCs become being routed to that session.

◆ num_routes()

size_t roc::pipeline::ReceiverSessionRouter::num_routes ( )

Get number of know routes.

◆ remove_session()

void roc::pipeline::ReceiverSessionRouter::remove_session ( const core::SharedPtr< ReceiverSession > &  session)

Unregister session from router.

Remarks
All associated SSRCs, CNAMEs, and addresses are removed.

◆ unlink_source()

void roc::pipeline::ReceiverSessionRouter::unlink_source ( packet::stream_source_t  source_id)

Unlink source id from session.

Remarks
Removes association of SSRC with session and CNAME. If this was the last SSRC, the whole route is removed.

The documentation for this class was generated from the following file: