avcpp  2.0
Wrapper for the FFmpeg that simplify usage from C++ projects.
Public Member Functions | Static Public Member Functions | List of all members
av::BufferRef Class Reference

Light weight wrapper for the FFmpeg AVBufferRef functionality. More...

#include <buffer.h>

Inheritance diagram for av::BufferRef:
Inheritance graph
[legend]
Collaboration diagram for av::BufferRef:
Collaboration graph
[legend]

Public Member Functions

 BufferRef ()=default
 Construct null buffer. More...
 
 BufferRef (std::size_t size, bool keepUninit=true) noexcept
 Allocate referenced buffer with given size. More...
 
 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. More...
 
 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. More...
 
 BufferRef (const uint8_t *data, size_t size, int flags=0) noexcept
 Clone exsiting data buffer and wrap it. More...
 
 BufferRef (const BufferRef &other) noexcept
 Make a buffer reference. More...
 
 BufferRef (BufferRef &&other) noexcept
 Just move owning of the nested AVBufferRef pointer into new instance. More...
 
 ~BufferRef () noexcept
 Unref nested AVBufferRef. More...
 
BufferRefoperator= (const BufferRef &other) noexcept
 Make a buffer reference. More...
 
BufferRefoperator= (BufferRef &&other) noexcept
 Move owning of the nested AVBufferRef from other to the this instance. More...
 
AVBufferRef * release () noexcept
 Release owning of the buffer and return existing raw AVBufferRef. More...
 
void reset () noexcept
 Force to unref nested data. More...
 
void makeWritable (OptionalErrorCode ec=throws())
 Make buffer writable. More...
 
void resize (std::size_t size, OptionalErrorCode ec=throws())
 Resize given buffer. More...
 
void swap (BufferRef &other) noexcept
 Swap nested data with other. More...
 
BufferRef ref ()
 Create reference to the view data, refCount() will be increased. More...
 
- Public Member Functions inherited from av::BufferRefView
 BufferRefView ()=default
 Construct null buffer. More...
 
 BufferRefView (BufferRef &ref)
 
 BufferRefView (const BufferRef &ref)
 
AVBufferRef * makeRef (iam_sure_what_i_do_tag) const noexcept
 Make an reference of the exsting buffer. More...
 
BufferRef ref ()
 Create reference to the view data, refCount() will be increased. More...
 
BufferRef clone (int flags=0) const noexcept
 Make deep copy of the existing buffer. More...
 
int refCount () const noexcept
 Report current reference counter of the buffer. More...
 
bool isWritable () const noexcept
 Report writable flag. More...
 
std::size_t size () const noexcept
 Nested buffer size. More...
 
const uint8_t * data () const noexcept
 Pointer to the data block start. More...
 
const uint8_t * constData () const noexcept
 Force request const data. More...
 
uint8_t * data (OptionalErrorCode ec=throws())
 Pointer to the data block start. More...
 
- Public Member Functions inherited from FFWrapperPtr< AVBufferRef >
 FFWrapperPtr ()=default
 
 FFWrapperPtr (AVBufferRef *raw)
 
const AVBufferRef * raw () const
 
AVBufferRef * raw ()
 
void reset (AVBufferRef *raw=nullptr)
 
bool isNull () const
 
void _log (int level, const char *fmt) const
 
void _log (int level, const char *fmt, const Args &... args) const
 

Static Public Member Functions

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

Additional Inherited Members

- Protected Attributes inherited from FFWrapperPtr< AVBufferRef >
AVBufferRef * m_raw
 

Detailed Description

Light weight wrapper for the FFmpeg AVBufferRef functionality.

Constructor & Destructor Documentation

◆ BufferRef() [1/7]

av::BufferRef::BufferRef ( )
default

Construct null buffer.

◆ BufferRef() [2/7]

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

Allocate referenced buffer with given size.

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() [3/7]

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

Wrap existing data buffer and take ownershipping.

Data kept uncopied.

If data allocated with custom allocators other then av_malloc/av_realloc/av::alloc/avmemdup 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/avmemdup function familiy.
opaqueoptional argnument for the deleter, may be null
flagsAV_BUFFER_FLAG_* flags

◆ BufferRef() [4/7]

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

Same previous one, but forces AV_BUFFER_FLAG_READONLY.

Data still uncopied until makeWritable() call.

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

Parameters
data
size
opaque
flags

◆ BufferRef() [5/7]

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

Clone exsiting data buffer and wrap it.

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() [6/7]

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

Make a buffer reference.

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() [7/7]

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

Just move owning of the nested AVBufferRef pointer into new instance.

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

Parameters
other

◆ ~BufferRef()

av::BufferRef::~BufferRef ( )
noexcept

Unref nested AVBufferRef.

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

Member Function Documentation

◆ makeWritable()

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

Make buffer writable.

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

Move owning of the nested AVBufferRef from other to the this instance.

Existing data will be unreferenced.

Parameters
other
Returns

◆ operator=() [2/2]

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

Make a buffer reference.

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]

BufferRef av::BufferRefView::ref

Create reference to the view data, refCount() will be increased.

Returns

◆ ref() [2/2]

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

Reference non-const buffer reference and wrap it.

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

Release owning of the buffer and return existing raw AVBufferRef.

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

Returns

◆ reset()

void av::BufferRef::reset ( )
noexcept

Force to unref nested data.

◆ resize()

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

Resize given buffer.

Look into of the av_buffer_realloc() for allocation details.

Parameters
sizenew buffer size
ec

◆ swap()

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

Swap nested data with other.

Parameters
other

◆ wrap() [1/2]

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

Wrap non-constant raw buffer reference.

Owning taken, but original buffer will not be referenced.

Possible usage:

BufferRef buf = BufferRef::wrap(av_buffer_ref(raw_buffer))
BufferRef()=default
Construct null buffer.
static BufferRef wrap(const AVBufferRef *buf, int flags=0) noexcept
Wrap constant raw buffer reference.
Definition: buffer.cpp:182
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

Wrap constant raw buffer reference.

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 files: