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

Common interface of video frames and audio samples. More...

#include <frame.h>

Inheritance diagram for av::FrameCommon:

Classes

struct  wrap_data
 Wrap data and take owning. More...
struct  wrap_data_static
 Wrap static data, do not owning and free. More...

Public Member Functions

 FrameCommon ()
 Create an invalid frame.
 FrameCommon (const AVFrame *frame)
 Copy the frame metadata into a new wrapper.
 FrameCommon (const FrameCommon &other)
 Copy constructor: references the same buffer.
 FrameCommon (FrameCommon &&other)
 Move constructor.
bool isReferenced () const
 Whether the frame data is reference counted.
int refCount () const
 Number of references to the frame buffer.
AVFrame * makeRef () const
 Create an independent reference to the frame.
Timestamp pts () const
 Presentation timestamp.
attribute_deprecated void setPts (int64_t pts, Rational ptsTimeBase)
 Set the timestamp and its time base at once.
void setPts (const Timestamp &ts)
 Set the timestamp.
const Rational & timeBase () const
 Time base of the frame.
void setTimeBase (const Rational &value)
 Set the time base.
int streamIndex () const
 Index of the stream the frame belongs to.
void setStreamIndex (int streamIndex)
 Set the stream index.
void setComplete (bool isComplete)
 Mark the frame as complete or incomplete.
bool isComplete () const
 Whether the frame is marked complete.
bool isValid () const
 Whether the wrapper holds a frame.
 operator bool () const
 Whether the wrapper holds a frame.
bool isHwFrame () const
 Whether the frame lives in device memory.
uint8_t * data (size_t plane=0)
 Pointer to one image or audio plane.
const uint8_t * data (size_t plane=0) const
 Pointer to one plane, read-only.
size_t size (size_t plane) const
 Size of one plane.
size_t size () const
 Total size of all planes.
void dump () const
 Print the frame layout through the FFmpeg log system.
void operator= (const FrameCommon &)=delete
 Assignment is deleted: derived classes implement it to avoid slicing.
void swap (FrameCommon &other)
 Exchange the contents of two frames.
const FrameSideData sideData (AVFrameSideDataType type) const
 Get packet side data of the given type.
FrameSideData sideData (AVFrameSideDataType type)
 Mutable access to the side data of the given type.
std::size_t sideDataCount () const noexcept
 Return count of the side data elements.
FrameSideData sideDataIndex (std::size_t index) noexcept
 Get side data element by index.
ArrayView< AVFrameSideData *, FrameSideData, std::size_t > sideData () noexcept
 Observe all packet side data via iterators.
ArrayView< const AVFrameSideData *, FrameSideData, std::size_t > sideData () const noexcept
 Read-only iteration over all side data entries.
void sideDataRemove (AVFrameSideDataType type) noexcept
 Remove and free all side data instances of the given type.
FrameSideData addSideData (AVFrameSideDataType type, std::span< const uint8_t > data, OptionalErrorCode ec=throws())
 Add side data of the given type into packet.
FrameSideData addSideData (AVFrameSideDataType type, std::span< uint8_t > data, wrap_data, OptionalErrorCode ec=throws())
 Add side data of the given type into packet.
FrameSideData addSideData (AVFrameSideDataType type, std::span< uint8_t > data, wrap_data_static, OptionalErrorCode ec=throws())
 Add side data of the given type into packet.
FrameSideData addSideData (AVFrameSideDataType type, BufferRef buf, OptionalErrorCode ec=throws())
 Add side data of the given type into packet.
FrameSideData allocateSideData (AVFrameSideDataType type, std::size_t size, OptionalErrorCode ec=throws())
 Allocate storage for the packet side data of the given type and return reference to it.
Public Member Functions inherited from FFWrapperPtr< AVFrame >
 FFWrapperPtr ()=default
 Create an empty wrapper; isNull() is true.
const AVFrame * raw () const
 Read access to the wrapped object.
void reset (AVFrame *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.

Protected Member Functions

void copyInfoFrom (const FrameCommon &other)
 Copy the avcpp bookkeeping (time base, stream index, completeness).
void clone (FrameCommon &dst, size_t align=1) const
 Make a deep copy of the frame data into another frame object.

Protected Attributes

Rational m_timeBase {}
 Time base of the timestamps in this frame.
int m_streamIndex {-1}
 Index of the stream the frame belongs to; -1 when unset.
bool m_isComplete {false}
 Completeness flag, set through setComplete().
Protected Attributes inherited from FFWrapperPtr< AVFrame >
AVFrame * m_raw
 The wrapped pointer; owned by the derived class, not by this template.

Detailed Description

Owns an AVFrame and adds the avcpp bookkeeping that FFmpeg keeps outside it: the time base, the stream index and a completeness flag. Derived classes are expected to implement assignment through assignOperator()/moveOperator(); direct assignment is deleted here to make slicing impossible.

Reference counting follows AVPacket/AVFrame semantics: a copy of the wrapper references the same frame buffer, and clone() is the way to get an independent copy.

Constructor & Destructor Documentation

◆ FrameCommon() [1/3]

av::FrameCommon::FrameCommon ( const AVFrame * frame)

The data itself is referenced, not copied.

Parameters
framethe frame to reference

◆ FrameCommon() [2/3]

av::FrameCommon::FrameCommon ( const FrameCommon & other)
Parameters
otherthe wrapper to copy

◆ FrameCommon() [3/3]

av::FrameCommon::FrameCommon ( FrameCommon && other)
Parameters
otherthe wrapper to move from; left invalid

Member Function Documentation

◆ addSideData() [1/4]

FrameSideData av::FrameCommon::addSideData ( AVFrameSideDataType type,
BufferRef buf,
OptionalErrorCode ec = throws() )

Setup via buffer reference view. Nested API does not reference buffer so it must be done with the caller code.

Parameters
type
buf
ec
Returns
a view of the added entry

◆ addSideData() [2/4]

FrameSideData av::FrameCommon::addSideData ( AVFrameSideDataType type,
std::span< const uint8_t > data,
OptionalErrorCode ec = throws() )

Data will be cloned.

Parameters
type
data
ec
Returns
a view of the added entry

◆ addSideData() [3/4]

FrameSideData av::FrameCommon::addSideData ( AVFrameSideDataType type,
std::span< uint8_t > data,
wrap_data ,
OptionalErrorCode ec = throws() )

Data will be wrapped and owner-shipping taken. Data must be allocated via av_malloc()/av::malloc() family functions.

Parameters
type
data
ec
Returns
a view of the added entry

◆ addSideData() [4/4]

FrameSideData av::FrameCommon::addSideData ( AVFrameSideDataType type,
std::span< uint8_t > data,
wrap_data_static ,
OptionalErrorCode ec = throws() )

Data will be wrapped without copying and null deleter will be provided. So data maybe any static data.

Parameters
type
data
ec
Returns
a view of the added entry

◆ allocateSideData()

FrameSideData av::FrameCommon::allocateSideData ( AVFrameSideDataType type,
std::size_t size,
OptionalErrorCode ec = throws() )

Data owned by the packet.

Parameters
type
size
ec
Returns

◆ clone()

void av::FrameCommon::clone ( FrameCommon & dst,
size_t align = 1 ) const
protected
Parameters
dstthe frame that receives the copy
alignalignment in bytes for the allocated planes

◆ copyInfoFrom()

void av::FrameCommon::copyInfoFrom ( const FrameCommon & other)
protected
Parameters
otherthe frame to copy from

◆ data() [1/2]

uint8_t * av::FrameCommon::data ( size_t plane = 0)
Parameters
planezero-based plane index; audio uses one plane per channel for planar formats
Returns
the plane pointer, or nullptr when it is absent
Note
Borrowed. The pointer is valid while the frame's buffer lives.

◆ data() [2/2]

const uint8_t * av::FrameCommon::data ( size_t plane = 0) const
Parameters
planezero-based plane index
Returns
the plane pointer, or nullptr when it is absent

◆ isComplete()

bool av::FrameCommon::isComplete ( ) const
Returns
the completeness flag; settable with setComplete()

◆ isHwFrame()

bool av::FrameCommon::isHwFrame ( ) const
Returns
true when hw_frames_ctx is set, which means data[] is not directly readable

◆ isReferenced()

bool av::FrameCommon::isReferenced ( ) const

◆ isValid()

bool av::FrameCommon::isValid ( ) const
Returns
true when the underlying AVFrame exists
Examples
api2-hw-decode.cpp, and api2-hw-scale.cpp.

◆ makeRef()

AVFrame * av::FrameCommon::makeRef ( ) const
Returns
a new AVFrame that shares the buffer and must be freed by the caller, or nullptr when the frame is invalid

◆ operator bool()

av::FrameCommon::operator bool ( ) const
Returns
true when the underlying AVFrame exists

◆ pts()

◆ refCount()

int av::FrameCommon::refCount ( ) const
Returns
the reference count, or zero when the frame is not referenced
Examples
api2-decode-audio.cpp, api2-decode-encode-audio.cpp, api2-decode-filter-encode.cpp, api2-decode-overlay-encode.cpp, and api2-decode-rasample-audio.cpp.

◆ setComplete()

void av::FrameCommon::setComplete ( bool isComplete)
Parameters
isCompletetrue when the frame holds all the data it should

◆ setPts() [1/2]

void av::FrameCommon::setPts ( const Timestamp & ts)
Parameters
tsthe timestamp; its time base is stored with the frame

◆ setPts() [2/2]

attribute_deprecated void av::FrameCommon::setPts ( int64_t pts,
Rational ptsTimeBase )
Deprecated
Pass a Timestamp instead, so the time base travels with the value and cannot be lost.
Parameters
ptstimestamp in ptsTimeBase units
ptsTimeBasetime base of the timestamp
Examples
api2-hw-scale.cpp.

◆ setStreamIndex()

void av::FrameCommon::setStreamIndex ( int streamIndex)
Parameters
streamIndexindex of the stream in the container
Examples
api2-decode-encode-audio.cpp, api2-decode-overlay-encode.cpp, and api2-hw-scale.cpp.

◆ setTimeBase()

void av::FrameCommon::setTimeBase ( const Rational & value)
Parameters
valuetimestamp units per second; set it before the frame is passed to another component
Examples
api2-decode-encode-audio.cpp, api2-decode-filter-encode.cpp, api2-decode-overlay-encode.cpp, and api2-hw-scale.cpp.

◆ sideData() [1/4]

ArrayView< const AVFrameSideData *, FrameSideData, std::size_t > av::FrameCommon::sideData ( ) const
noexcept
Returns
a non-owning range valid while the frame is alive

◆ sideData() [2/4]

ArrayView< AVFrameSideData *, FrameSideData, std::size_t > av::FrameCommon::sideData ( )
noexcept

Applicable for range-based for and std::range:xxx algos.

Returns

◆ sideData() [3/4]

FrameSideData av::FrameCommon::sideData ( AVFrameSideDataType type)
Parameters
typethe AV_FRAME_DATA_* value to look for
Returns
a view of the entry, empty when the frame has none

◆ sideData() [4/4]

const FrameSideData av::FrameCommon::sideData ( AVFrameSideDataType type) const

Empty buffer means no data.

Parameters
type
Returns

◆ sideDataCount()

std::size_t av::FrameCommon::sideDataCount ( ) const
noexcept
Returns

◆ sideDataIndex()

FrameSideData av::FrameCommon::sideDataIndex ( std::size_t index)
noexcept
Parameters
index
Returns

◆ sideDataRemove()

void av::FrameCommon::sideDataRemove ( AVFrameSideDataType type)
noexcept
Parameters
type

◆ size() [1/2]

size_t av::FrameCommon::size ( ) const
Returns
the sum of the plane sizes in bytes

◆ size() [2/2]

size_t av::FrameCommon::size ( size_t plane) const
Parameters
planezero-based plane index
Returns
the size in bytes
Examples
api2-decode-filter-encode.cpp, and api2-decode-overlay-encode.cpp.

◆ streamIndex()

int av::FrameCommon::streamIndex ( ) const
Returns
the index, or -1 when it has not been set

◆ swap()

void av::FrameCommon::swap ( FrameCommon & other)
Parameters
otherthe frame to swap with

◆ timeBase()

const Rational & av::FrameCommon::timeBase ( ) const

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