avcpp 3.2.1
Wrapper for the FFmpeg that simplify usage from C++ projects.
Loading...
Searching...
No Matches
hwcontext.h File Reference

Hardware devices, hardware frames and hardware codec configuration.

#include <cstddef>
#include <iterator>
#include <memory>
#include <optional>
#include <string>
#include <system_error>
#include <vector>
#include "avcompat.h"
#include "averror.h"
#include "buffer.h"
#include "codec.h"
#include "dictionary.h"
#include "pixelformat.h"
#include <libavutil/hwcontext.h>

Go to the source code of this file.

Classes

class  av::hw::DeviceType
 Wrapper for AVHWDeviceType. More...
class  av::hw::DeviceContext
 Owner of an AVHWDeviceContext. More...
class  av::hw::FramesContext
 Owner of an AVHWFramesContext. More...
class  av::hw::RangeView< T >
 Non-owning view over a contiguous array. More...
class  av::hw::DeviceTypeRange
 Non-owning iterator over AVHWDeviceType values. More...
class  av::hw::DeviceTypeRange::iterator
 Forward iterator over the device types FFmpeg was built with. More...
struct  av::hw::DeviceProbe
 Result of probing one device type: whether it could be created, and why not. More...
class  av::hw::DeviceProbeRange
 Lazy range that probes every compiled device type. More...
class  av::hw::DeviceProbeRange::iterator
 Forward iterator that creates and destroys one device per step. More...
class  av::hw::PixelFormatRange
 Non-owning view over a null-terminated AVPixelFormat array. More...
class  av::hw::PixelFormatRange::iterator
 Forward iterator over a null-terminated AVPixelFormat array. More...
class  av::hw::PixelFormatList
 Owner of an AVPixelFormat array allocated by FFmpeg. More...
class  av::hw::FrameConstraints
 Owner of AVHWFramesConstraints. More...
class  av::hw::CodecConfigRange
 Non-owning iterator over AVCodecHWConfig entries of a codec. More...
class  av::hw::CodecConfigRange::iterator
 Forward iterator over the hardware configurations of a codec. More...
class  av::hw::CodecRange
 Non-owning range over codecs found with av_codec_iterate(). More...
class  av::hw::CodecRange::iterator
 Forward iterator over the codecs FFmpeg was built with. More...

Namespaces

namespace  av
 Root namespace of the library.

Enumerations

enum class  av::hw::EncodingMode { Auto , Frames , Device }
 How an encoder receives hardware frames. More...

Functions

DeviceTypeRange av::hw::allDeviceTypes () noexcept
 All hardware device types compiled into FFmpeg.
DeviceProbeRange av::hw::probeDevices (const char *device=nullptr)
 Probe every compiled device type with a borrowed selector.
DeviceProbeRange av::hw::probeDevices (const std::string &device)
 Probe every compiled device type, keeping a copy of the selector.
bool av::hw::isDeviceAvailable (DeviceType type, const char *device=nullptr)
 Check whether one device type can be created.
bool av::hw::isDeviceAvailable (DeviceType type, const std::string &device)
 Check whether one device type can be created.
FrameConstraints av::hw::frameConstraints (const DeviceContext &device, OptionalErrorCode ec=throws())
 Query hardware frames constraints for a device.
CodecConfigRange av::hw::codecConfigs (const Codec &codec) noexcept
 All hardware configurations of a codec.
std::optional< AVCodecHWConfig > av::hw::findCodecConfig (const Codec &codec, DeviceType type, int methodsMask=AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX|AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX)
 The first hardware configuration that matches a device type.
CodecRange av::hw::findDecoders (AVCodecID id, DeviceType type) noexcept
 All decoders for a codec identifier that support a device type.
CodecRange av::hw::findEncoders (AVCodecID id, DeviceType type) noexcept
 All encoders for a codec identifier that support a device type.
Codec av::hw::findDecoder (AVCodecID id, DeviceType type) noexcept
 The first decoder for a codec identifier that supports a device type.
Codec av::hw::findEncoder (AVCodecID id, DeviceType type) noexcept
 The first encoder for a codec identifier that supports a device type.
PixelFormat av::hw::hwPixelFormat (DeviceType type) noexcept
 Hardware pixel format used by a device type.

Enumeration Type Documentation

◆ EncodingMode

enum class av::hw::EncodingMode
strong
Enumerator
Auto 

Prefer a hardware frames context, fall back to a device context.

Frames 

Use AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX only.

Device 

Use AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX only.

Function Documentation

◆ allDeviceTypes()

DeviceTypeRange av::hw::allDeviceTypes ( )
noexcept

This lists compiled backends, not present hardware. Use probeDevices() or isDeviceAvailable() to check whether a device can actually be created.

Returns
a non-owning range over the compiled types
Examples
api2-hw-probe.cpp.

◆ codecConfigs()

CodecConfigRange av::hw::codecConfigs ( const Codec & codec)
noexcept
Parameters
codecthe codec to inspect
Returns
a non-owning range over the configurations FFmpeg reports
Examples
api2-hw-probe.cpp.

◆ findCodecConfig()

std::optional< AVCodecHWConfig > av::hw::findCodecConfig ( const Codec & codec,
DeviceType type,
int methodsMask = AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX|AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX )
Parameters
codecthe codec to inspect
typethe device type to match
methodsMaskconfiguration methods to accept; by default both the device-context and the frames-context methods qualify
Returns
the matching entry, or std::nullopt when the codec cannot use this device type with the accepted methods

◆ findDecoder()

Codec av::hw::findDecoder ( AVCodecID id,
DeviceType type )
noexcept
Parameters
idthe codec identifier
typethe device type the decoder must support
Returns
a valid codec, or an invalid one when nothing matches
Examples
api2-hw-decode.cpp, api2-hw-probe.cpp, api2-hw-scale.cpp, and api2-hw-transcode.cpp.

◆ findDecoders()

CodecRange av::hw::findDecoders ( AVCodecID id,
DeviceType type )
noexcept

The search covers every codec with the identifier, which matters for QSV: the generic h264 decoder cannot use QSV, h264_qsv can.

Parameters
idthe codec identifier
typethe device type the decoder must support
Returns
a lazy, non-owning range

◆ findEncoder()

Codec av::hw::findEncoder ( AVCodecID id,
DeviceType type )
noexcept
Parameters
idthe codec identifier
typethe device type the encoder must support
Returns
a valid codec, or an invalid one when nothing matches
Examples
api2-hw-encode.cpp, api2-hw-probe.cpp, api2-hw-scale.cpp, and api2-hw-transcode.cpp.

◆ findEncoders()

CodecRange av::hw::findEncoders ( AVCodecID id,
DeviceType type )
noexcept
Parameters
idthe codec identifier
typethe device type the encoder must support
Returns
a lazy, non-owning range

◆ frameConstraints()

FrameConstraints av::hw::frameConstraints ( const DeviceContext & device,
OptionalErrorCode ec = throws() )

The returned object owns the FFmpeg constraints; hwFormats() and swFormats() are non-owning views into it.

Parameters
devicethe device to query
echolder for the error code
Returns
an owning value; check isValid() before reading it

◆ hwPixelFormat()

PixelFormat av::hw::hwPixelFormat ( DeviceType type)
noexcept

The lookup is name based, so the function does not depend on enum values that may be missing in older FFmpeg versions.

Parameters
typethe device type
Returns
the surface format, for example AV_PIX_FMT_VAAPI, or AV_PIX_FMT_NONE when the type is unknown

◆ isDeviceAvailable() [1/2]

bool av::hw::isDeviceAvailable ( DeviceType type,
const char * device = nullptr )
Parameters
typethe device type to probe
devicebackend-specific selector; nullptr asks for the default
Returns
true when FFmpeg managed to create a device; the temporary device is destroyed before the call returns

◆ isDeviceAvailable() [2/2]

bool av::hw::isDeviceAvailable ( DeviceType type,
const std::string & device )
Parameters
typethe device type to probe
devicebackend-specific selector
Returns
true when FFmpeg managed to create a device

◆ probeDevices() [1/2]

DeviceProbeRange av::hw::probeDevices ( const char * device = nullptr)

Each step creates a device and destroys it immediately, which is the only reliable availability check: FFmpeg lists compiled backends, not hardware.

Parameters
devicebackend-specific selector, for example "/dev/dri/renderD128" or "1"; nullptr asks for the default device
Returns
a lazy range of results; the selector must outlive the range
Examples
api2-hw-probe.cpp.

◆ probeDevices() [2/2]

DeviceProbeRange av::hw::probeDevices ( const std::string & device)
Parameters
devicebackend-specific selector; a copy is stored in the range
Returns
a lazy range of results