12 #ifndef ROC_PIPELINE_RECEIVER_SESSION_ROUTER_H_
13 #define ROC_PIPELINE_RECEIVER_SESSION_ROUTER_H_
136 enum { PreallocatedRoutes = 4, PreallocatedSources = 8 };
149 : core::RefCounted<SourceNode, core::PoolAllocation>(pool)
150 , parent_route(route)
151 , source_id(source_id) {
169 return source_id1 == source_id2;
175 struct AddressNode : core::HashmapNode<> {
180 const address::SocketAddr& key() {
182 return route().source_addr;
185 static core::hashsum_t key_hash(
const address::SocketAddr& source_addr) {
189 static bool key_equal(
const address::SocketAddr& source_addr1,
190 const address::SocketAddr& source_addr2) {
191 return source_addr1 == source_addr2;
197 struct CnameNode : core::HashmapNode<> {
204 return route().cname;
211 static bool key_equal(
const char* cname1,
const char* cname2) {
212 return strcmp(cname1, cname2) == 0;
218 struct SessionNode : core::HashmapNode<> {
223 const core::SharedPtr<ReceiverSession>& key() {
225 return route().session;
228 static core::hashsum_t key_hash(
const core::SharedPtr<ReceiverSession>& session) {
232 static bool key_equal(
const core::SharedPtr<ReceiverSession>& session1,
233 const core::SharedPtr<ReceiverSession>& session2) {
234 return session1 == session2;
250 struct Route : core::RefCounted<Route, core::PoolAllocation>, core::ListNode<> {
253 core::SharedPtr<ReceiverSession> session;
257 address::SocketAddr source_addr;
261 char cname[rtcp::MaxCnameLen + 1];
266 bool has_main_source_id;
270 core::List<SourceNode> source_nodes;
271 AddressNode address_node;
272 CnameNode cname_node;
273 SessionNode session_node;
275 Route(core::IPool& pool)
277 , has_main_source_id(false)
278 , main_source_id(0) {
287 const address::SocketAddr& source_addr,
289 const core::SharedPtr<ReceiverSession>& session);
290 void remove_route_(core::SharedPtr<Route> route);
291 void remove_all_routes_();
292 status::StatusCode move_route_session_(Route& from, Route& to);
293 void collect_route_(Route& route);
296 core::SlabPool<Route, PreallocatedRoutes> route_pool_;
297 core::SlabPool<SourceNode, PreallocatedSources> source_node_pool_;
301 core::List<Route> route_list_;
305 core::Hashmap<SourceNode, PreallocatedRoutes, core::NoOwnership> source_route_map_;
306 core::Hashmap<AddressNode, PreallocatedRoutes, core::NoOwnership> address_route_map_;
307 core::Hashmap<CnameNode, PreallocatedRoutes, core::NoOwnership> cname_route_map_;
308 core::Hashmap<SessionNode, PreallocatedRoutes, core::NoOwnership> session_route_map_;
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Base class for Hashmap element.
Base class for List element.
Base class for non-copyable objects.
PoolAllocation(IPool &pool)
Initialize.
Base class for object with reference counter.
Shared ownership intrusive pointer.
void unlink_source(packet::stream_source_t source_id)
Unlink source id from session.
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.
ROC_ATTR_NODISCARD status::StatusCode link_source(packet::stream_source_t source_id, const char *cname)
Link source id with unique CNAME.
size_t num_routes()
Get number of know routes.
core::SharedPtr< ReceiverSession > find_by_address(const address::SocketAddr &source_addr)
Find registered session by source address of sender's stream.
void remove_session(const core::SharedPtr< ReceiverSession > &session)
Unregister session from router.
bool has_session(const core::SharedPtr< ReceiverSession > &session)
Check if there is a route for given session.
~ReceiverSessionRouter()
Deinitialize.
core::SharedPtr< ReceiverSession > find_by_source(packet::stream_source_t source_id)
Find registered session by source id of sender's stream.
ReceiverSessionRouter(core::IArena &arena)
Initialize.
Intrusive doubly-linked list.
#define ROC_CONTAINER_OF(ptr, type, member)
Cast a member of a structure out to the containing structure.
hashsum_t hashsum_int(int16_t)
Compute hash of 16-bit integer.
hashsum_t hashsum_str(const char *str)
Compute hash of zero-terminated string.
hashsum_t hashsum_mem(const void *data, size_t size)
Compute hash of byte range.
size_t hashsum_t
Hash type.
uint32_t stream_source_t
Packet stream identifier.
Receiver session pipeline.
Various units used in packets.