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

Owner of an AVHWDeviceContext. More...

#include <hwcontext.h>

Public Member Functions

bool isValid () const noexcept
 Whether the wrapper holds a device.
DeviceType type () const noexcept
 The type of the device.
AVHWDeviceContext * raw () const noexcept
 The underlying FFmpeg context.
AVBufferRef * bufferRef () const noexcept
 The reference-counted buffer that owns the context.

Static Public Member Functions

static DeviceContext create (DeviceType type, const char *device=nullptr, const Dictionary &options={}, OptionalErrorCode ec=throws())
 Create and open a hardware device.
static DeviceContext create (DeviceType type, const std::string &device, const Dictionary &options={}, OptionalErrorCode ec=throws())
 Create and open a hardware device from a std::string selector.
static DeviceContext derive (const DeviceContext &source, DeviceType type, const Dictionary &options={}, OptionalErrorCode ec=throws())
 Create a device derived from an existing one.
static DeviceContext wrap (AVBufferRef *ref) noexcept
 Take a reference to an existing AVBufferRef.

Friends

class FramesContext

Detailed Description

The context is reference counted with AVBufferRef. Copying the wrapper only adds a reference. Use raw() or bufferRef() to pass the context to FFmpeg.

Examples
api2-hw-decode.cpp, api2-hw-encode.cpp, api2-hw-probe.cpp, api2-hw-scale.cpp, and api2-hw-transcode.cpp.

Member Function Documentation

◆ bufferRef()

AVBufferRef * av::hw::DeviceContext::bufferRef ( ) const
noexcept
Returns
the raw buffer reference, or nullptr for an invalid wrapper
Note
Borrowed by the wrapper. Pass it to FFmpeg APIs that take an AVBufferRef* without unreffing it afterwards.

◆ create() [1/2]

DeviceContext av::hw::DeviceContext::create ( DeviceType type,
const char * device = nullptr,
const Dictionary & options = {},
OptionalErrorCode ec = throws() )
static
Parameters
typethe device type to create
devicebackend-specific selector: a path for VAAPI/DRM, an index for CUDA, an adapter name for D3D11VA, or nullptr for the default device
optionsbackend-specific options passed to FFmpeg
echolder for the error code; throws() raises av::Exception
Returns
a valid context, or an invalid one when the device cannot be created
Note
This overload borrows device; it must outlive the call. Use the std::string overload when the selector is a temporary.
Examples
api2-hw-decode.cpp, api2-hw-encode.cpp, api2-hw-probe.cpp, api2-hw-scale.cpp, and api2-hw-transcode.cpp.

◆ create() [2/2]

DeviceContext av::hw::DeviceContext::create ( DeviceType type,
const std::string & device,
const Dictionary & options = {},
OptionalErrorCode ec = throws() )
static
Parameters
typethe device type to create
devicebackend-specific selector; may be empty for the default
optionsbackend-specific options passed to FFmpeg
echolder for the error code
Returns
a valid context, or an invalid one when the device cannot be created

◆ derive()

DeviceContext av::hw::DeviceContext::derive ( const DeviceContext & source,
DeviceType type,
const Dictionary & options = {},
OptionalErrorCode ec = throws() )
static

A typical use is an OpenCL device on top of a VAAPI device, so both APIs share the same frames. Do not derive a QSV device: the libmfx path can crash.

Parameters
sourcethe device to derive from; must be valid
typethe type of the derived device
optionsbackend-specific options
echolder for the error code
Returns
a valid derived device, or an invalid one on failure

◆ isValid()

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

◆ raw()

AVHWDeviceContext * av::hw::DeviceContext::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.

◆ type()

DeviceType av::hw::DeviceContext::type ( ) const
noexcept
Returns
the device type, or "none" for an invalid wrapper

◆ wrap()

DeviceContext av::hw::DeviceContext::wrap ( AVBufferRef * ref)
staticnoexcept

The reference count is incremented, so the caller keeps ownership of its pointer and must still unref it. Never free a pointer that was passed here and then keep using the returned context.

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: