avcpp  2.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
buffer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "avcpp/averror.h"
4 #include "ffmpeg.h"
5 
6 #if AVCPP_CXX_STANDARD >= 20
7 #include <span>
8 #endif // AVCPP_CXX_STANDARD >= 20
9 
10 namespace av {
11 
12 namespace buffer {
16 void null_deleter(void* /*opaque*/, uint8_t* /*data*/);
17 } // ::buffer
18 
19 class BufferRef;
20 
24 class BufferRefView : public FFWrapperPtr<AVBufferRef>
25 {
26 public:
28 
32  BufferRefView() = default;
33 
34  explicit BufferRefView(BufferRef& ref);
35  explicit BufferRefView(const BufferRef& ref);
36 
45  AVBufferRef* makeRef(iam_sure_what_i_do_tag) const noexcept;
46 
51  BufferRef ref();
52 
58  BufferRef clone(int flags = 0) const noexcept;
59 
64  int refCount() const noexcept;
69  bool isWritable() const noexcept;
70 
75  std::size_t size() const noexcept;
80  const uint8_t* data() const noexcept;
85  const uint8_t* constData() const noexcept;
92  uint8_t* data(OptionalErrorCode ec = throws());
93 
94 #if AVCPP_CXX_STANDARD >= 20
99  std::span<const uint8_t> span() const noexcept;
104  std::span<const uint8_t> constSpan() const noexcept;
110  std::span<uint8_t> span(OptionalErrorCode ec = throws());
111 #endif
112 };
113 
114 
118 class BufferRef : public BufferRefView
119 {
120  //using FFWrapperPtr<AVBufferRef>::FFWrapperPtr;
122 
123 public:
127  BufferRef() = default;
128 
138  BufferRef(std::size_t size, bool keepUninit = true) noexcept;
139 
157  BufferRef(uint8_t *data, size_t size, void (*free)(void *opaque, uint8_t *data), void *opaque, int flags = 0) noexcept;
158 
169  BufferRef(const uint8_t *data, size_t size, void (*free)(void *opaque, uint8_t *data), void *opaque, int flags = 0) noexcept;
170 
180  BufferRef(const uint8_t *data, size_t size, int flags = 0) noexcept;
181 
182 #if AVCPP_CXX_STANDARD
192  BufferRef(std::span<uint8_t> data, void (*free)(void *opaque, uint8_t *data), void *opaque, int flags = 0) noexcept;
193 
200  explicit BufferRef(std::span<const uint8_t> data, int flags = 0) noexcept;
201 #endif // AVCPP_CXX_STANDARD
202 
208  BufferRef(const BufferRef& other) noexcept;
214  BufferRef(BufferRef&& other) noexcept;
215 
219  ~BufferRef() noexcept;
220 
230  BufferRef& operator=(const BufferRef& other) noexcept;
236  BufferRef& operator=(BufferRef&& other) noexcept;
237 
244  static BufferRef wrap(const AVBufferRef *buf, int flags = 0) noexcept;
256  static BufferRef wrap(AVBufferRef *buf) noexcept;
262  static BufferRef ref(const AVBufferRef *buf) noexcept;
263 
264  using BufferRefView::ref;
265 
271  AVBufferRef* release() noexcept;
272 
276  void reset() noexcept;
277 
288  void resize(std::size_t size, OptionalErrorCode ec = throws());
289 
294  void swap(BufferRef &other) noexcept;
295 };
296 
297 } // ::av
Non-owning view for the nested AVBufferRef.
Definition: buffer.h:25
BufferRefView()=default
Construct null buffer.
int refCount() const noexcept
Report current reference counter of the buffer.
Definition: buffer.cpp:58
std::size_t size() const noexcept
Nested buffer size.
Definition: buffer.cpp:63
BufferRef ref()
Create reference to the view data, refCount() will be increased.
Definition: buffer.cpp:39
AVBufferRef * makeRef(iam_sure_what_i_do_tag) const noexcept
Make an reference of the exsting buffer.
Definition: buffer.cpp:35
bool isWritable() const noexcept
Report writable flag.
Definition: buffer.cpp:53
const uint8_t * data() const noexcept
Pointer to the data block start.
Definition: buffer.cpp:68
const uint8_t * constData() const noexcept
Force request const data.
Definition: buffer.cpp:73
BufferRef clone(int flags=0) const noexcept
Make deep copy of the existing buffer.
Definition: buffer.cpp:46
Light weight wrapper for the FFmpeg AVBufferRef functionality.
Definition: buffer.h:119
BufferRef ref()
Create reference to the view data, refCount() will be increased.
Definition: buffer.cpp:39
BufferRef()=default
Construct null buffer.
void makeWritable(OptionalErrorCode ec=throws())
Make buffer writable.
Definition: buffer.cpp:211
~BufferRef() noexcept
Unref nested AVBufferRef.
Definition: buffer.cpp:170
void resize(std::size_t size, OptionalErrorCode ec=throws())
Resize given buffer.
Definition: buffer.cpp:224
void swap(BufferRef &other) noexcept
Swap nested data with other.
Definition: buffer.cpp:237
static BufferRef wrap(const AVBufferRef *buf, int flags=0) noexcept
Wrap constant raw buffer reference.
Definition: buffer.cpp:182
void reset() noexcept
Force to unref nested data.
Definition: buffer.cpp:202
AVBufferRef * release() noexcept
Release owning of the buffer and return existing raw AVBufferRef.
Definition: buffer.cpp:197
Definition: averror.h:66
void null_deleter(void *, uint8_t *)
Buffer deleter that do nothing.
Definition: buffer.cpp:15
Definition: audioresampler.cpp:8
OptionalErrorCode throws()
Helper to construct null OptionalErrorCode object.
Definition: averror.h:181
Definition: averror.h:230
Definition: ffmpeg.h:22
Tag to confirm usage of the Low Level functionality.
Definition: buffer.h:40