Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
receiver.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2020 Roc Streaming authors
3 *
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 */
8
9//! @file roc_node/receiver.h
10//! @brief Receiver node.
11
12#ifndef ROC_NODE_RECEIVER_H_
13#define ROC_NODE_RECEIVER_H_
14
18#include "roc_core/attributes.h"
19#include "roc_core/hashmap.h"
20#include "roc_core/mutex.h"
22#include "roc_core/slab_pool.h"
23#include "roc_core/stddefs.h"
25#include "roc_node/context.h"
26#include "roc_node/node.h"
29
30namespace roc {
31namespace node {
32
33//! Receiver node.
35public:
36 //! Slot index.
37 typedef uint64_t slot_index_t;
38
39 //! Initialize.
41
42 //! Deinitialize.
44
45 //! Check if successfully constructed.
46 bool is_valid();
47
48 //! Set interface config.
51 const netio::UdpConfig& config);
52
53 //! Bind to local endpoint.
56
57 //! Remove slot.
59
60 //! Callback for slot metrics.
61 typedef void (*slot_metrics_func_t)(const pipeline::ReceiverSlotMetrics& slot_metrics,
62 void* slot_arg);
63
64 //! Callback for participant metrics.
65 typedef void (*party_metrics_func_t)(
66 const pipeline::ReceiverParticipantMetrics& party_metrics,
67 size_t party_index,
68 void* party_arg);
69
70 //! Get metrics.
72 slot_metrics_func_t slot_metrics_func,
73 void* slot_metrics_arg,
74 party_metrics_func_t party_metrics_func,
75 size_t* party_metrics_size,
76 void* party_metrics_arg);
77
78 //! Check if there are broken slots.
79 bool has_broken();
80
81 //! Get receiver source.
83
84private:
85 struct Port {
86 netio::UdpConfig config;
88
89 Port()
90 : handle(NULL) {
91 }
92 };
93
94 struct Slot : core::RefCounted<Slot, core::PoolAllocation>, core::HashmapNode<> {
95 const slot_index_t index;
97 Port ports[address::Iface_Max];
98 bool broken;
99
100 Slot(core::IPool& pool,
101 slot_index_t index,
103 : core::RefCounted<Slot, core::PoolAllocation>(pool)
104 , index(index)
105 , handle(handle)
106 , broken(false) {
107 }
108
109 slot_index_t key() const {
110 return index;
111 }
112
113 static core::hashsum_t key_hash(slot_index_t index) {
114 return core::hashsum_int(index);
115 }
116
117 static bool key_equal(slot_index_t index1, slot_index_t index2) {
118 return index1 == index2;
119 }
120 };
121
122 bool check_compatibility_(address::Interface iface, const address::EndpointUri& uri);
123 void update_compatibility_(address::Interface iface, const address::EndpointUri& uri);
124
125 core::SharedPtr<Slot> get_slot_(slot_index_t slot_index, bool auto_create);
126 void cleanup_slot_(Slot& slot);
127 void break_slot_(Slot& slot);
128
129 virtual void schedule_task_processing(pipeline::PipelineLoop&,
130 core::nanoseconds_t delay);
131 virtual void cancel_task_processing(pipeline::PipelineLoop&);
132
133 core::Mutex mutex_;
134
135 pipeline::ReceiverLoop pipeline_;
136 ctl::ControlLoop::Tasks::PipelineProcessing processing_task_;
137
138 core::SlabPool<Slot> slot_pool_;
139 core::Hashmap<Slot> slot_map_;
140
141 bool used_interfaces_[address::Iface_Max];
142 address::Protocol used_protocols_[address::Iface_Max];
143
144 pipeline::ReceiverSlotMetrics slot_metrics_;
145 core::Array<pipeline::ReceiverParticipantMetrics, 8> party_metrics_;
146
147 bool valid_;
148};
149
150} // namespace node
151} // namespace roc
152
153#endif // ROC_NODE_RECEIVER_H_
Compiler attributes.
#define ROC_ATTR_NODISCARD
Emit warning if function result is not checked.
Definition attributes.h:31
Network endpoint URI.
Base class for Hashmap element.
Memory pool interface.
Definition ipool.h:23
PoolAllocation(IPool &pool)
Initialize.
IPool & pool() const
Get pool.
Base class for object with reference counter.
Definition ref_counted.h:40
struct PortHandle * PortHandle
Opaque port handle.
Node context.
Definition context.h:44
Base class for nodes.
Definition node.h:23
Context & context()
All nodes hold reference to context.
Receiver node.
Definition receiver.h:34
bool configure(slot_index_t slot_index, address::Interface iface, const netio::UdpConfig &config)
Set interface config.
bool has_broken()
Check if there are broken slots.
sndio::ISource & source()
Get receiver source.
bool unlink(slot_index_t slot_index)
Remove slot.
uint64_t slot_index_t
Slot index.
Definition receiver.h:37
void(* slot_metrics_func_t)(const pipeline::ReceiverSlotMetrics &slot_metrics, void *slot_arg)
Callback for slot metrics.
Definition receiver.h:61
Receiver(Context &context, const pipeline::ReceiverSourceConfig &pipeline_config)
Initialize.
bool bind(slot_index_t slot_index, address::Interface iface, address::EndpointUri &uri)
Bind to local endpoint.
~Receiver()
Deinitialize.
void(* party_metrics_func_t)(const pipeline::ReceiverParticipantMetrics &party_metrics, size_t party_index, void *party_arg)
Callback for participant metrics.
Definition receiver.h:65
bool is_valid()
Check if successfully constructed.
bool get_metrics(slot_index_t slot_index, slot_metrics_func_t slot_metrics_func, void *slot_metrics_arg, party_metrics_func_t party_metrics_func, size_t *party_metrics_size, void *party_metrics_arg)
Get metrics.
Pipeline task scheduler interface. PipelineLoop uses this interface to schedule asynchronous work....
struct SlotHandle * SlotHandle
Opaque slot handle.
struct SlotHandle * SlotHandle
Opaque slot handle.
Definition sender_loop.h:47
Source interface.
Definition isource.h:23
Node context.
Control loop thread.
Network endpoint URI.
Intrusive hash table.
Interface ID.
Pipeline task scheduler interface.
Mutex.
Interface
Interface ID.
Definition interface.h:19
@ Iface_Max
Number of interfaces.
Definition interface.h:36
Protocol
Protocol ID.
Definition protocol.h:19
hashsum_t hashsum_int(int16_t)
Compute hash of 16-bit integer.
int64_t nanoseconds_t
Nanoseconds.
Definition time.h:58
size_t hashsum_t
Hash type.
Definition hashsum.h:21
Root namespace.
Base class for nodes.
Protocol ID.
Receiver pipeline loop.
Base class for object with reference counter.
Memory pool.
Commonly used types and functions.
UDP port parameters.
Definition udp_port.h:32
Receiver-side metrics specific to one participant (remote sender).
Definition metrics.h:54
Receiver-side metrics of the whole slot.
Definition metrics.h:66
Parameters of receiver session.
Definition config.h:184