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"
19 #include "roc_core/iarena.h"
20 #include "roc_core/ref_counted.h"
21 #include "roc_ctl/control_loop.h"
22 #include "roc_netio/network_loop.h"
24 #include "roc_rtp/format_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 factory.
60 
61  //! Get byte buffer factory.
63 
64  //! Get sample buffer factory.
66 
67  //! Get format map.
69 
70  //! Get network event loop.
72 
73  //! Get control event loop.
75 
76 private:
77  core::IArena& arena_;
78 
79  packet::PacketFactory packet_factory_;
80  core::BufferFactory<uint8_t> byte_buffer_factory_;
81  core::BufferFactory<audio::sample_t> sample_buffer_factory_;
82 
83  rtp::FormatMap format_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.
Buffer factory.
Memory arena interface.
Definition: iarena.h:23
Base class for object with reference counter.
Definition: ref_counted.h:40
Control loop thread.
Definition: control_loop.h:33
Network event loop thread.
Definition: network_loop.h:53
Node context.
Definition: context.h:44
core::BufferFactory< audio::sample_t > & sample_buffer_factory()
Get sample buffer factory.
ctl::ControlLoop & control_loop()
Get control event loop.
core::IArena & arena()
Get arena.
bool is_valid()
Check if successfully constructed.
core::BufferFactory< uint8_t > & byte_buffer_factory()
Get byte buffer factory.
netio::NetworkLoop & network_loop()
Get network event loop.
~Context()
Deinitialize.
Context(const ContextConfig &config, core::IArena &arena)
Initialize.
rtp::FormatMap & format_map()
Get format map.
packet::PacketFactory & packet_factory()
Get packet factory.
RTP payload format map. Thread-safe. Returned formats are immutable and can be safely used from any t...
Definition: format_map.h:33
Control loop thread.
RTP payload format map.
Memory arena interface.
Root namespace.
Network event loop thread.
Packet factory.
Base class for object with reference counter.
Audio sample.
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