Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
context.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/context.h
10 //! @brief Node context.
11 
12 #ifndef ROC_NODE_CONTEXT_H_
13 #define ROC_NODE_CONTEXT_H_
14 
15 #include "roc_audio/sample.h"
17 #include "roc_core/atomic.h"
18 #include "roc_core/iarena.h"
19 #include "roc_core/ref_counted.h"
20 #include "roc_core/slab_pool.h"
21 #include "roc_ctl/control_loop.h"
22 #include "roc_netio/network_loop.h"
24 #include "roc_rtp/encoding_map.h"
25 
26 namespace roc {
27 namespace node {
28 
29 //! Node context config.
30 struct ContextConfig {
31  //! Maximum size in bytes of a network packet.
33 
34  //! Maximum size in bytes of an audio frame.
36 
38  : max_packet_size(2048)
39  , max_frame_size(4096) {
40  }
41 };
42 
43 //! Node context.
44 class Context : public core::RefCounted<Context, core::ManualAllocation> {
45 public:
46  //! Initialize.
47  explicit Context(const ContextConfig& config, core::IArena& arena);
48 
49  //! Deinitialize.
51 
52  //! Check if successfully constructed.
53  bool is_valid();
54 
55  //! Get arena.
57 
58  //! Get packet pool.
60 
61  //! Get packet buffer pool.
63 
64  //! Get frame buffer pool.
66 
67  //! Get encoding map.
69 
70  //! Get network event loop.
72 
73  //! Get control event loop.
75 
76 private:
77  core::IArena& arena_;
78 
79  core::SlabPool<packet::Packet> packet_pool_;
80  core::SlabPool<core::Buffer> packet_buffer_pool_;
81  core::SlabPool<core::Buffer> frame_buffer_pool_;
82 
83  rtp::EncodingMap encoding_map_;
84 
85  netio::NetworkLoop network_loop_;
86  ctl::ControlLoop control_loop_;
87 };
88 
89 } // namespace node
90 } // namespace roc
91 
92 #endif // ROC_NODE_CONTEXT_H_
Allocation policies.
Atomic.
Memory arena interface.
Definition: iarena.h:23
Memory pool interface.
Definition: ipool.h:23
Base class for object with reference counter.
Definition: ref_counted.h:40
Memory pool.
Definition: slab_pool.h:72
Control loop thread.
Definition: control_loop.h:33
Network event loop thread.
Definition: network_loop.h:52
Node context.
Definition: context.h:44
ctl::ControlLoop & control_loop()
Get control event loop.
core::IPool & packet_pool()
Get packet pool.
core::IArena & arena()
Get arena.
bool is_valid()
Check if successfully constructed.
core::IPool & packet_buffer_pool()
Get packet buffer pool.
rtp::EncodingMap & encoding_map()
Get encoding map.
netio::NetworkLoop & network_loop()
Get network event loop.
~Context()
Deinitialize.
Context(const ContextConfig &config, core::IArena &arena)
Initialize.
core::IPool & frame_buffer_pool()
Get frame buffer pool.
RTP encoding map. Thread-safe. Returned encodings are immutable and can be safely used from any threa...
Definition: encoding_map.h:33
Control loop thread.
RTP encoding map.
Memory arena interface.
Root namespace.
Network event loop thread.
Packet factory.
Base class for object with reference counter.
Audio sample.
Memory pool.
Node context config.
Definition: context.h:30
size_t max_frame_size
Maximum size in bytes of an audio frame.
Definition: context.h:35
size_t max_packet_size
Maximum size in bytes of a network packet.
Definition: context.h:32