Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
Toggle main menu visibility
Loading...
Searching...
No Matches
buffer.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2017 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_core/buffer.h
10
//! @brief Buffer.
11
12
#ifndef ROC_CORE_BUFFER_H_
13
#define ROC_CORE_BUFFER_H_
14
15
#include "
roc_core/align_ops.h
"
16
#include "
roc_core/allocation_policy.h
"
17
#include "
roc_core/ipool.h
"
18
#include "
roc_core/macro_helpers.h
"
19
#include "
roc_core/ref_counted.h
"
20
#include "
roc_core/shared_ptr.h
"
21
#include "
roc_core/stddefs.h
"
22
23
namespace
roc
{
24
namespace
core
{
25
26
class
Buffer
;
27
28
//! Buffer smart pointer.
29
typedef
SharedPtr<Buffer>
BufferPtr
;
30
31
//! Fixed-size dynamically-allocated byte buffer.
32
//!
33
//! @remarks
34
//! Buffer size is fixed, but determined at runtime, not compile time.
35
//! It is defined by the pool that allocates the buffer.
36
//! User typically works with buffers via Slice, which holds a shared pointer
37
//! to buffer and points to a variable-size subset of its memory.
38
//!
39
//! @see BufferFactory, Slice.
40
class
Buffer
:
public
RefCounted
<Buffer, PoolAllocation> {
41
public
:
42
//! Initialize empty buffer.
43
Buffer
(
IPool
& buffer_pool,
size_t
buffer_size);
44
45
//! Get buffer size in bytes.
46
size_t
size
()
const
{
47
return
size_;
48
}
49
50
//! Get buffer data.
51
uint8_t*
data
() {
52
return
(uint8_t*)data_;
53
}
54
55
//! Get pointer to buffer from the pointer to its data.
56
static
Buffer
*
container_of
(
void
*
data
) {
57
return
ROC_CONTAINER_OF
(
data
,
Buffer
, data_);
58
}
59
60
private
:
61
const
size_t
size_;
62
AlignMax
data_[];
63
};
64
65
}
// namespace core
66
}
// namespace roc
67
68
#endif
// ROC_CORE_BUFFER_H_
align_ops.h
Alignment operations.
allocation_policy.h
Allocation policies.
roc::core::Buffer
Fixed-size dynamically-allocated byte buffer.
Definition
buffer.h:40
roc::core::Buffer::size
size_t size() const
Get buffer size in bytes.
Definition
buffer.h:46
roc::core::Buffer::data
uint8_t * data()
Get buffer data.
Definition
buffer.h:51
roc::core::Buffer::Buffer
Buffer(IPool &buffer_pool, size_t buffer_size)
Initialize empty buffer.
roc::core::Buffer::container_of
static Buffer * container_of(void *data)
Get pointer to buffer from the pointer to its data.
Definition
buffer.h:56
roc::core::IPool
Memory pool interface.
Definition
ipool.h:23
roc::core::RefCounted< Buffer, PoolAllocation >::RefCounted
RefCounted()
Definition
ref_counted.h:43
roc::core::SharedPtr
Shared ownership intrusive pointer.
Definition
shared_ptr.h:32
ipool.h
Memory pool interface.
macro_helpers.h
Helper macros.
ROC_CONTAINER_OF
#define ROC_CONTAINER_OF(ptr, type, member)
Cast a member of a structure out to the containing structure.
Definition
macro_helpers.h:37
roc::core
General-purpose building blocks and platform abstraction layer.
roc::core::BufferPtr
SharedPtr< Buffer > BufferPtr
Buffer smart pointer.
Definition
buffer.h:29
roc
Root namespace.
ref_counted.h
Base class for object with reference counter.
shared_ptr.h
Shared ownership intrusive pointer.
stddefs.h
Commonly used types and functions.
roc::core::AlignMax
Maximum aligned data unit.
Definition
align_ops.h:21
roc_core
buffer.h
Generated by
1.17.0