Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
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"
17#include "roc_core/ipool.h"
20#include "roc_core/shared_ptr.h"
21#include "roc_core/stddefs.h"
22
23namespace roc {
24namespace core {
25
26class Buffer;
27
28//! Buffer smart pointer.
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.
40class Buffer : public RefCounted<Buffer, PoolAllocation> {
41public:
42 //! Initialize empty buffer.
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
60private:
61 const size_t size_;
62 AlignMax data_[];
63};
64
65} // namespace core
66} // namespace roc
67
68#endif // ROC_CORE_BUFFER_H_
Alignment operations.
Allocation policies.
Fixed-size dynamically-allocated byte buffer.
Definition buffer.h:40
size_t size() const
Get buffer size in bytes.
Definition buffer.h:46
uint8_t * data()
Get buffer data.
Definition buffer.h:51
Buffer(IPool &buffer_pool, size_t buffer_size)
Initialize empty buffer.
static Buffer * container_of(void *data)
Get pointer to buffer from the pointer to its data.
Definition buffer.h:56
Memory pool interface.
Definition ipool.h:23
Base class for object with reference counter.
Definition ref_counted.h:40
Shared ownership intrusive pointer.
Definition shared_ptr.h:32
Memory pool interface.
Helper macros.
#define ROC_CONTAINER_OF(ptr, type, member)
Cast a member of a structure out to the containing structure.
SharedPtr< Buffer > BufferPtr
Buffer smart pointer.
Definition buffer.h:29
Root namespace.
Base class for object with reference counter.
Shared ownership intrusive pointer.
Commonly used types and functions.
Maximum aligned data unit.
Definition align_ops.h:21