avcpp 3.1.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
Loading...
Searching...
No Matches
av::BufferRef Class Reference

Light weight wrapper for the FFmpeg AVBufferRef functionality.

#include <buffer.h>

Inheritance diagram for av::BufferRef:

Public Member Functions

 BufferRef ()=default
 Construct null buffer.
 BufferRef (std::size_t size, bool keepUninit=true) noexcept
 Allocate referenced buffer with given size.
 BufferRef (uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags=0) noexcept
 Wrap existing data buffer and take ownershipping.
 BufferRef (const uint8_t *data, size_t size, void(*free)(void *opaque, uint8_t *data), void *opaque, int flags=0) noexcept
 Same previous one, but forces AV_BUFFER_FLAG_READONLY.
 BufferRef (const uint8_t *data, size_t size, int flags=0) noexcept
 Clone exsiting data buffer and wrap it.
 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.
 BufferRef (std::span< const uint8_t > data, int flags=0) noexcept
 Same to BufferRef(data, size, flags) but pass data via std::span() interface.
 BufferRef (const BufferRef &other) noexcept
 Make a buffer reference.
 BufferRef (BufferRef &&other) noexcept
 Just move owning of the nested AVBufferRef pointer into new instance.
 ~BufferRef () noexcept
 Unref nested AVBufferRef.
BufferRef & operator= (const BufferRef &other) noexcept
 Make a buffer reference.
BufferRef & operator= (BufferRef &&other) noexcept
 Move owning of the nested AVBufferRef from other to the this instance.
AVBufferRef * release () noexcept
 Release owning of the buffer and return existing raw AVBufferRef.
void reset () noexcept
 Force to unref nested data.
void makeWritable (OptionalErrorCode ec=throws())
 Make buffer writable.
void resize (std::size_t size, OptionalErrorCode ec=throws())
 Resize given buffer.
void swap (BufferRef &other) noexcept
 Swap nested data with other.
BufferRef ref ()
 Create reference to the view data, refCount() will be increased.
Public Member Functions inherited from av::BufferRefView
 BufferRefView ()=default
 Construct null buffer.
 BufferRefView (BufferRef &ref)
 View an owning buffer.
 BufferRefView (const BufferRef &ref)
 View an owning buffer, read-only.
AVBufferRef * makeRef (iam_sure_what_i_do_tag) const noexcept
 Make an reference of the exsting buffer.
BufferRef ref ()
 Create reference to the view data, refCount() will be increased.
BufferRef clone (int flags=0) const noexcept
 Make deep copy of the existing buffer.
int refCount () const noexcept
 Report current reference counter of the buffer.
bool isWritable () const noexcept
 Report writable flag.
std::size_t size () const noexcept
 Nested buffer size.
const uint8_t * data () const noexcept
 Pointer to the data block start.
const uint8_t * constData () const noexcept
 Force request const data.
uint8_t * data (OptionalErrorCode ec=throws())
 Pointer to the data block start.
std::span< const uint8_t > span () const noexcept
 Span interface to obtain nested buffer data.
std::span< const uint8_t > constSpan () const noexcept
 Force request const span.
std::span< uint8_t > span (OptionalErrorCode ec=throws())
 Span interface to obtain nested buffer data.
Public Member Functions inherited from FFWrapperPtr< AVBufferRef >
 FFWrapperPtr ()=default
 Create an empty wrapper; isNull() is true.
const AVBufferRef * raw () const
 Read access to the wrapped object.
void reset (AVBufferRef *raw=nullptr)
 Replace the stored pointer.
bool isNull () const
 Whether the wrapper is empty.
void _log (int level, const char *fmt) const
 Log through the FFmpeg log system, using this wrapper as the context.

Static Public Member Functions

static BufferRef wrap (const AVBufferRef *buf, int flags=0) noexcept
 Wrap constant raw buffer reference.
static BufferRef wrap (AVBufferRef *buf) noexcept
 Wrap non-constant raw buffer reference.
static BufferRef ref (const AVBufferRef *buf) noexcept
 Reference non-const buffer reference and wrap it.

Additional Inherited Members

Protected Attributes inherited from FFWrapperPtr< AVBufferRef >
AVBufferRef * m_raw
 The wrapped pointer; owned by the derived class, not by this template.

Constructor & Destructor Documentation

◆ BufferRef() [1/8]

av::BufferRef::BufferRef ( std::size_t size,
bool keepUninit = true )
noexcept

If keepUninit point into true data in the buffer kept uninitialized. otherwise it initializes with zeroes.

refCount() will return 1 after this function.

Parameters
sizerequested size of the buffer
keepUninittrue to kept buffer with garbage and zeroing it otherwise.

◆ BufferRef() [2/8]

av::BufferRef::BufferRef ( uint8_t * data,
size_t size,
void(* free )(void *opaque, uint8_t *data),
void * opaque,
int flags = 0 )
noexcept

Data kept uncopied.

If data allocated with custom allocators other then av_malloc/av_realloc/av::alloc/av::memdup families, free function must be provided.

Also, it can be used to wrap static buffers with av::buffer::null_deleter()

refCount() will return 1 after this function.

Parameters
datadata buffer to wrap, owning taken.
sizesize of the data buffer.
freedeleter for the data, maybe nullptr if data buffer was allocated with av_malloc/av_realloc/av::alloc/av::memdup function familiy.
opaqueoptional argnument for the deleter, may be null
flagsAV_BUFFER_FLAG_* flags

◆ BufferRef() [3/8]

av::BufferRef::BufferRef ( const uint8_t * data,
size_t size,
void(* free )(void *opaque, uint8_t *data),
void * opaque,
int flags = 0 )
noexcept

Data still uncopied until makeWritable() call.

Can be used to wrap static constant data with av::buffer::null_deleter.

Parameters
datadata buffer to wrap, not copied
sizesize of the data buffer
freedeleter for the data; receives the opaque pointer and the data
opaqueoptional argument for the deleter, may be null
flagsAV_BUFFER_FLAG_* flags

◆ BufferRef() [4/8]

av::BufferRef::BufferRef ( const uint8_t * data,
size_t size,
int flags = 0 )
noexcept

Data copied into new storage and owning taken.

refCount() will return 1 after this function.

Parameters
datadata buffer with payload
sizedata buffer size
flagsAV_BUFFER_FLAG_*

◆ BufferRef() [5/8]

av::BufferRef::BufferRef ( std::span< uint8_t > data,
void(* free )(void *opaque, uint8_t *data),
void * opaque,
int flags = 0 )
noexcept

Span must be pointed into start of the allocated block.

Parameters
datadata block reference with size
freedeleter, may be nullptr
opaqueextra data passed into deleter, maybe nullptr
flagsAV_BUFFER_FLAG_*

◆ BufferRef() [6/8]

av::BufferRef::BufferRef ( std::span< const uint8_t > data,
int flags = 0 )
explicitnoexcept

Span may point to any location of the allocated memory block.

Parameters
datadata block reference with size
flagsAV_BUFFER_FLAG_*

◆ BufferRef() [7/8]

av::BufferRef::BufferRef ( const BufferRef & other)
noexcept

refCount() will return values increased by 1 for both new and old instances. Actual data will be kept uncopied. Newly created buffer may be invalid if the allocating for the reference block fails.

Parameters
other

◆ BufferRef() [8/8]

av::BufferRef::BufferRef ( BufferRef && other)
noexcept

refCount() kept untouched. other buffer does not controll nested AVBufferRef anymore;

Parameters
other

◆ ~BufferRef()

av::BufferRef::~BufferRef ( )
noexcept

If the refCount() == 1 data will be deleted too.

Member Function Documentation

◆ makeWritable()

void av::BufferRef::makeWritable ( OptionalErrorCode ec = throws())

Look into notice of the av_buffer_make_writable() for data coping details.

Parameters
ec

◆ operator=() [1/2]

BufferRef & av::BufferRef::operator= ( BufferRef && other)
noexcept

Existing data will be unreferenced.

Parameters
other
Returns

◆ operator=() [2/2]

BufferRef & av::BufferRef::operator= ( const BufferRef & other)
noexcept

Existing data will be unreferenced. refCount() will return value increased by 1 for both this and other instances. Value must be same.

Buffer state may be invalid, if control block allocation will be fail durting copying.

Parameters
other
Returns

◆ ref() [1/2]

◆ ref() [2/2]

BufferRef av::BufferRef::ref ( const AVBufferRef * buf)
staticnoexcept

Owning of the new ference will be taken. Data kept uncopying.

Parameters
bufraw buffer to reference
Returns
wrapped buffer reference. It may be invalid if allocation fails.

◆ release()

AVBufferRef * av::BufferRef::release ( )
noexcept

Useful to move owning without referencing into nested low-level code.

Returns

◆ resize()

void av::BufferRef::resize ( std::size_t size,
OptionalErrorCode ec = throws() )

Look into of the av_buffer_realloc() for allocation details.

Parameters
sizenew buffer size
ec

◆ swap()

void av::BufferRef::swap ( BufferRef & other)
noexcept
Parameters
other

◆ wrap() [1/2]

BufferRef av::BufferRef::wrap ( AVBufferRef * buf)
staticnoexcept

Owning taken, but original buffer will not be referenced.

Possible usage:

BufferRef buf = BufferRef::wrap(av_buffer_ref(raw_buffer))
static BufferRef wrap(const AVBufferRef *buf, int flags=0) noexcept
Wrap constant raw buffer reference.
BufferRef()=default
Construct null buffer.
Parameters
bufbuffer to wrap
Returns
wrapped buffer reference. It may be invalid if allocation fails.

◆ wrap() [2/2]

BufferRef av::BufferRef::wrap ( const AVBufferRef * buf,
int flags = 0 )
staticnoexcept

Data will be cloned into new buffer.

Parameters
bufbuffer to wrap
flagsAV_BUFFER_FLAG_*
Returns
wrapped buffer reference. It may be invalid if allocation fails.

The documentation for this class was generated from the following file: