avcpp 3.1.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
Loading...
Searching...
No Matches
buffer.h
Go to the documentation of this file.
1#pragma once
2
9
10#include "avcpp/averror.h"
11#include "ffmpeg.h"
12
13#if AVCPP_CXX_STANDARD >= 20
14#include <span>
15#endif // AVCPP_CXX_STANDARD >= 20
16
17namespace av {
18
19namespace buffer {
23void null_deleter(void* /*opaque*/, uint8_t* /*data*/);
24} // ::buffer
25
26class BufferRef;
27
31class BufferRefView : public FFWrapperPtr<AVBufferRef>
32{
33public:
34 using FFWrapperPtr<AVBufferRef>::FFWrapperPtr;
35
39 BufferRefView() = default;
40
52 explicit BufferRefView(const BufferRef& ref);
53
62 AVBufferRef* makeRef(iam_sure_what_i_do_tag) const noexcept;
63
69
75 BufferRef clone(int flags = 0) const noexcept;
76
81 int refCount() const noexcept;
86 bool isWritable() const noexcept;
87
92 std::size_t size() const noexcept;
97 const uint8_t* data() const noexcept;
102 const uint8_t* constData() const noexcept;
109 uint8_t* data(OptionalErrorCode ec = throws());
110
111#if AVCPP_CXX_STANDARD >= 20
116 std::span<const uint8_t> span() const noexcept;
121 std::span<const uint8_t> constSpan() const noexcept;
128#endif
129};
130
131
135class BufferRef : public BufferRefView
136{
137 //using FFWrapperPtr<AVBufferRef>::FFWrapperPtr;
139
140public:
144 BufferRef() = default;
145
155 BufferRef(std::size_t size, bool keepUninit = true) noexcept;
156
174 BufferRef(uint8_t *data, size_t size, void (*free)(void *opaque, uint8_t *data), void *opaque, int flags = 0) noexcept;
175
187 BufferRef(const uint8_t *data, size_t size, void (*free)(void *opaque, uint8_t *data), void *opaque, int flags = 0) noexcept;
188
198 BufferRef(const uint8_t *data, size_t size, int flags = 0) noexcept;
199
200#if AVCPP_CXX_STANDARD >= 20
210 BufferRef(std::span<uint8_t> data, void (*free)(void *opaque, uint8_t *data), void *opaque, int flags = 0) noexcept;
211
218 explicit BufferRef(std::span<const uint8_t> data, int flags = 0) noexcept;
219#endif // AVCPP_CXX_STANDARD
220
226 BufferRef(const BufferRef& other) noexcept;
232 BufferRef(BufferRef&& other) noexcept;
233
237 ~BufferRef() noexcept;
238
248 BufferRef& operator=(const BufferRef& other) noexcept;
254 BufferRef& operator=(BufferRef&& other) noexcept;
255
262 static BufferRef wrap(const AVBufferRef *buf, int flags = 0) noexcept;
274 static BufferRef wrap(AVBufferRef *buf) noexcept;
280 static BufferRef ref(const AVBufferRef *buf) noexcept;
281
282 using BufferRefView::ref;
283
289 AVBufferRef* release() noexcept;
290
294 void reset() noexcept;
295
306 void resize(std::size_t size, OptionalErrorCode ec = throws());
307
312 void swap(BufferRef &other) noexcept;
313};
314
315} // ::av
Error codes, error categories and the OptionalErrorCode convention.
void null_deleter(void *, uint8_t *)
Buffer deleter that do nothing.
BufferRefView()=default
Construct null buffer.
int refCount() const noexcept
Report current reference counter of the buffer.
std::size_t size() const noexcept
Nested buffer size.
BufferRef ref()
Create reference to the view data, refCount() will be increased.
AVBufferRef * makeRef(iam_sure_what_i_do_tag) const noexcept
Make an reference of the exsting buffer.
bool isWritable() const noexcept
Report writable flag.
const uint8_t * data() const noexcept
Pointer to the data block start.
BufferRefView(const BufferRef &ref)
View an owning buffer, read-only.
std::span< const uint8_t > constSpan() const noexcept
Force request const span.
std::span< const uint8_t > span() const noexcept
Span interface to obtain nested buffer data.
const uint8_t * constData() const noexcept
Force request const data.
BufferRefView(BufferRef &ref)
View an owning buffer.
BufferRef clone(int flags=0) const noexcept
Make deep copy of the existing buffer.
Light weight wrapper for the FFmpeg AVBufferRef functionality.
Definition buffer.h:136
static BufferRef wrap(const AVBufferRef *buf, int flags=0) noexcept
Wrap constant raw buffer reference.
BufferRef(BufferRef &&other) noexcept
Just move owning of the nested AVBufferRef pointer into new instance.
BufferRef()=default
Construct null buffer.
void makeWritable(OptionalErrorCode ec=throws())
Make buffer writable.
~BufferRef() noexcept
Unref nested AVBufferRef.
BufferRef(std::size_t size, bool keepUninit=true) noexcept
Allocate referenced buffer with given size.
void resize(std::size_t size, OptionalErrorCode ec=throws())
Resize given buffer.
static BufferRef ref(const AVBufferRef *buf) noexcept
Reference non-const buffer reference and wrap it.
void swap(BufferRef &other) noexcept
Swap nested data with other.
BufferRef(const BufferRef &other) noexcept
Make a buffer reference.
void reset() noexcept
Force to unref nested data.
AVBufferRef * release() noexcept
Release owning of the buffer and return existing raw AVBufferRef.
BufferRef(std::span< uint8_t > data, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags=0) noexcept
Same to BufferRef(data, size, free, opaque, flags) but pass data via std::span() interface.
Carries the caller's choice between exceptions and error codes.
Definition averror.h:96
FFmpeg types re-exported for the public API and small value wrappers.
Root namespace of the library.
Definition audioresampler.h:19
OptionalErrorCode throws()
Helper to construct null OptionalErrorCode object.
Definition averror.h:310
STL namespace.
Tag to confirm usage of the Low Level functionality.
Definition buffer.h:57