Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
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_peer/context.h
10//! @brief Peer context.
11
12#ifndef ROC_PEER_CONTEXT_H_
13#define ROC_PEER_CONTEXT_H_
14
15#include "roc_audio/sample.h"
16#include "roc_core/atomic.h"
18#include "roc_core/iallocator.h"
22
23namespace roc {
24namespace peer {
25
26//! Peer context config.
28 //! Maximum size in bytes of a network packet.
30
31 //! Maximum size in bytes of an audio frame.
33
34 //! Enable memory poisoning.
36
38 : max_packet_size(2048)
39 , max_frame_size(4096)
40 , poisoning(false) {
41 }
42};
43
44//! Peer context.
45class Context : public core::NonCopyable<> {
46public:
47 //! Initialize.
49
50 //! Deinitialize.
52
53 //! Check if successfully constructed.
54 bool valid();
55
56 //! Increment context reference counter.
57 void incref();
58
59 //! Decrement context reference counter.
60 void decref();
61
62 //! Check if context is still in use.
63 bool is_used();
64
65 //! Get allocator.
67
68 //! Get packet factory.
70
71 //! Get byte buffer factory.
73
74 //! Get sample buffer factory.
76
77 //! Get network event loop.
79
80 //! Get control event loop.
82
83private:
84 core::IAllocator& allocator_;
85
86 packet::PacketFactory packet_factory_;
87 core::BufferFactory<uint8_t> byte_buffer_factory_;
88 core::BufferFactory<audio::sample_t> sample_buffer_factory_;
89
90 netio::NetworkLoop network_loop_;
91 ctl::ControlLoop control_loop_;
92
93 core::Atomic<int> ref_counter_;
94};
95
96} // namespace peer
97} // namespace roc
98
99#endif // ROC_PEER_CONTEXT_H_
Atomic.
Buffer factory.
Atomic integer. Provides sequential consistency. For a fine-grained memory order control,...
Definition: atomic.h:26
Memory allocator interface.
Definition: iallocator.h:23
Base class for non-copyable objects.
Definition: noncopyable.h:23
Control loop thread.
Definition: control_loop.h:32
Network event loop thread.
Definition: network_loop.h:52
Peer context.
Definition: context.h:45
void decref()
Decrement context reference counter.
ctl::ControlLoop & control_loop()
Get control event loop.
core::BufferFactory< audio::sample_t > & sample_buffer_factory()
Get sample buffer factory.
Context(const ContextConfig &config, core::IAllocator &allocator)
Initialize.
bool valid()
Check if successfully constructed.
bool is_used()
Check if context is still in use.
~Context()
Deinitialize.
void incref()
Increment context reference counter.
core::IAllocator & allocator()
Get allocator.
netio::NetworkLoop & network_loop()
Get network event loop.
packet::PacketFactory & packet_factory()
Get packet factory.
core::BufferFactory< uint8_t > & byte_buffer_factory()
Get byte buffer factory.
Control loop thread.
Memory allocator interface.
Root namespace.
Network event loop thread.
Packet factory.
Audio sample.
Peer context config.
Definition: context.h:27
size_t max_frame_size
Maximum size in bytes of an audio frame.
Definition: context.h:32
bool poisoning
Enable memory poisoning.
Definition: context.h:35
size_t max_packet_size
Maximum size in bytes of a network packet.
Definition: context.h:29