Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Loading...
Searching...
No Matches
frame_factory.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024 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_audio/frame_factory.h
10//! @brief Frame factory.
11
12#ifndef ROC_AUDIO_FRAME_FACTORY_H_
13#define ROC_AUDIO_FRAME_FACTORY_H_
14
15#include "roc_audio/frame.h"
16#include "roc_audio/sample.h"
17#include "roc_core/buffer.h"
18#include "roc_core/iarena.h"
19#include "roc_core/ipool.h"
21#include "roc_core/optional.h"
22#include "roc_core/slab_pool.h"
23#include "roc_core/slice.h"
24
25namespace roc {
26namespace audio {
27
28//! Frame factory.
29//!
30//! Allows allocating frames and frame buffers (byte buffers of appropriate size
31//! that should be attached to frame to hold payload).
32//!
33//! Serves several purposes:
34//! - implements convenient and type-safe wrapper on top of memory pools
35//! - combines two related pools (frame pool and buffer pool) in one class
36//! - detaches pipeline logic from memory management interface, so that it can
37//! change independently without affecting every pipeline element
39public:
40 //! Initialize with default pools.
41 //! @p buffer_size defines number of bytes in frame buffer.
42 FrameFactory(core::IArena& arena, size_t buffer_size);
43
44 //! Initialize with custom pools.
45 //! @p buffer_pool is a pool of core::Buffer objects.
47
48 //! Get number of bytes in byte buffer.
49 size_t byte_buffer_size() const;
50
51 //! Allocate byte buffer.
53
54 //! Get number of samples in raw sample buffer.
55 size_t raw_buffer_size() const;
56
57 //! Allocate raw sample buffer.
59
60private:
61 // used if factory is created with default pools
63
64 core::IPool* buffer_pool_;
65 size_t buffer_size_;
66};
67
68} // namespace audio
69} // namespace roc
70
71#endif // ROC_AUDIO_FRAME_FACTORY_H_
Buffer.
core::Slice< sample_t > new_raw_buffer()
Allocate raw sample buffer.
core::Slice< uint8_t > new_byte_buffer()
Allocate byte buffer.
FrameFactory(core::IArena &arena, size_t buffer_size)
Initialize with default pools. buffer_size defines number of bytes in frame buffer.
size_t raw_buffer_size() const
Get number of samples in raw sample buffer.
size_t byte_buffer_size() const
Get number of bytes in byte buffer.
FrameFactory(core::IPool &buffer_pool)
Initialize with custom pools. buffer_pool is a pool of core::Buffer objects.
Memory arena interface.
Definition iarena.h:23
Memory pool interface.
Definition ipool.h:23
Base class for non-copyable objects.
Definition noncopyable.h:23
Optionally constructed object.
Definition optional.h:25
Audio frame.
Memory arena interface.
Memory pool interface.
Root namespace.
Non-copyable object.
Optionally constructed object.
Audio sample.
Memory pool.
Slice.