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

Owner of an AVHWFramesContext. More...

#include <hwcontext.h>

Public Member Functions

bool isValid () const noexcept
 Whether the wrapper holds a pool.
DeviceContext device () const noexcept
 The device this pool belongs to.
PixelFormat format () const noexcept
 The hardware format of the surfaces in the pool.
PixelFormat swFormat () const noexcept
 The system-memory format used to transfer frames into and out of the pool.
int width () const noexcept
 Surface width.
int height () const noexcept
 Surface height.
PixelFormatList transferFormats (AVHWFrameTransferDirection direction, OptionalErrorCode ec=throws()) const
 Formats that frames can be transferred to or from this pool.
AVHWFramesContext * raw () const noexcept
 The underlying FFmpeg frames context.
AVBufferRef * bufferRef () const noexcept
 The reference-counted buffer that owns the frames context.

Static Public Member Functions

static FramesContext create (const DeviceContext &device, PixelFormat format, PixelFormat swFormat, int width, int height, int initialPoolSize=0, OptionalErrorCode ec=throws())
 Create and initialize a hardware frames context (a pool of surfaces).
static FramesContext wrap (AVBufferRef *ref) noexcept
 Take a reference to an existing AVHWFrameContext buffer.

Detailed Description

Member Function Documentation

◆ bufferRef()

AVBufferRef * av::hw::FramesContext::bufferRef ( ) const
noexcept
Returns
the raw buffer reference, or nullptr for an invalid wrapper
Note
Borrowed by the wrapper. This is the pointer to pass to AVCodecContext::hw_frames_ctx.

◆ create()

FramesContext av::hw::FramesContext::create ( const DeviceContext & device,
PixelFormat format,
PixelFormat swFormat,
int width,
int height,
int initialPoolSize = 0,
OptionalErrorCode ec = throws() )
static
Parameters
devicethe device the surfaces live on
formatthe hardware surface format, usually hwPixelFormat(device.type())
swFormatthe format used when a frame is transferred to system memory; AV_PIX_FMT_NONE lets FFmpeg choose
widthframe width in pixels
heightframe height in pixels
initialPoolSizenumber of surfaces; zero lets FFmpeg choose
echolder for the error code
Returns
a valid pool, or an invalid one on failure
Note
FFmpeg 4.x QSV requires a fixed pool size; avcpp uses 20 surfaces in that case. Check FrameConstraints::swFormats() before choosing swFormat: not every device supports NV12.

◆ device()

DeviceContext av::hw::FramesContext::device ( ) const
noexcept
Returns
a copy of the owning device wrapper, obtained from device_ref

◆ format()

PixelFormat av::hw::FramesContext::format ( ) const
noexcept
Returns
the surface format, for example AV_PIX_FMT_VAAPI

◆ height()

int av::hw::FramesContext::height ( ) const
noexcept
Returns
the height in pixels

◆ isValid()

bool av::hw::FramesContext::isValid ( ) const
noexcept
Returns
true when the underlying context is present
Examples
api2-hw-encode.cpp, and api2-hw-scale.cpp.

◆ raw()

AVHWFramesContext * av::hw::FramesContext::raw ( ) const
noexcept
Returns
the raw pointer, or nullptr for an invalid wrapper
Note
Borrowed. Do not free it and do not keep it after the wrapper dies.

◆ swFormat()

PixelFormat av::hw::FramesContext::swFormat ( ) const
noexcept
Returns
the software format, for example AV_PIX_FMT_NV12
Examples
api2-hw-encode.cpp, and api2-hw-scale.cpp.

◆ transferFormats()

PixelFormatList av::hw::FramesContext::transferFormats ( AVHWFrameTransferDirection direction,
OptionalErrorCode ec = throws() ) const
Parameters
directionAV_HWFRAME_TRANSFER_DIRECTION_TO for uploads into the pool, AV_HWFRAME_TRANSFER_DIRECTION_FROM for downloads
echolder for the error code
Returns
an owning list of formats; the list is empty when the device does not report any
Note
The returned object owns the array FFmpeg allocated. Its range() view is only valid while the list is alive.

◆ width()

int av::hw::FramesContext::width ( ) const
noexcept
Returns
the width in pixels

◆ wrap()

FramesContext av::hw::FramesContext::wrap ( AVBufferRef * ref)
staticnoexcept
Parameters
refthe buffer to reference; may be null
Returns
a wrapper that owns one reference, invalid when ref is null

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