Gazebo Common

API Reference

4.7.0
HWEncoder Class Reference

Representation of a GPU video encoder and its configuration. More...

#include <HWEncoder.hh>

Public Member Functions

 HWEncoder (FlagSet< HWEncoderType > _allowedHwEncoders, const std::string &_hwAccelDevice, std::optional< bool > _useHwSurface)
 Set up the HW encoder configurator. More...
 
virtual ~HWEncoder ()
 
void ConfigHWAccel (AVCodecContext *_encoderContext)
 Configure hardware acceleration. Should be called after the codec context parameters have been set, but before calling avcodec_open2(). More...
 
AVCodec * FindEncoder (AVCodecID _codecId)
 
HWEncoderType GetEncoderType () const
 Returns the type of encoder that is currently being used. The value will be NONE until ConfigHWAccel() successfully finishes. More...
 
AVFrame * GetFrameForEncoder (AVFrame *_inFrame)
 Get a pointer to the frame that contains the encoder input. This mainly serves for uploading the frame to GPU buffer if requested. More...
 

Detailed Description

Representation of a GPU video encoder and its configuration.

Note
This class is intentionally hidden as it provides highly customized behavior tailored just for the use with VideoEncoder.

Constructor & Destructor Documentation

◆ HWEncoder()

HWEncoder ( FlagSet< HWEncoderType >  _allowedHwEncoders,
const std::string _hwAccelDevice,
std::optional< bool >  _useHwSurface 
)

Set up the HW encoder configurator.

Parameters
[in]_allowedHwEncodersHW encoders to try.
[in]_hwAccelDeviceOptional name of the device that should be used. It doesn't affect unrelated HW encoders, but if the name is a match for an encoder, it will limit its search to only this device. However, if another encoder is tried earlier and succeeds, it will return with its default device.
[in]_useHwSurface.If set, specifies whether the HW encoder should explicitly upload frames to the GPU, or whether that is left for the internals of the codec. If the value is unset, a HW-specific default is used that was experimentally found to be faster.

◆ ~HWEncoder()

virtual ~HWEncoder ( )
virtual

Member Function Documentation

◆ ConfigHWAccel()

void ConfigHWAccel ( AVCodecContext *  _encoderContext)

Configure hardware acceleration. Should be called after the codec context parameters have been set, but before calling avcodec_open2().

Parameters
[in]_encoderContextContext of the encoder for which hardware acceleration should be set up.
Note
If the configuration fails, the codec will be left configured for software encoding and an error will be written to ignerr describing what failed.

◆ FindEncoder()

AVCodec* FindEncoder ( AVCodecID  _codecId)

Find a suitable encoder, preferring HW encoders.

Parameters
[in]_codecIdID of the codec we seek the encoder for.
Returns
Name of the encoder to be used.
Note
The class expects that the returned encoder will be passed to ConfigHWAccel, and no other.

◆ GetEncoderType()

HWEncoderType GetEncoderType ( ) const

Returns the type of encoder that is currently being used. The value will be NONE until ConfigHWAccel() successfully finishes.

◆ GetFrameForEncoder()

AVFrame* GetFrameForEncoder ( AVFrame *  _inFrame)

Get a pointer to the frame that contains the encoder input. This mainly serves for uploading the frame to GPU buffer if requested.

Parameters
[in]_inFrameThe input frame to be encoded (in CPU buffer).
Returns
Pointer to either this->avOutFrame or this->avOutHwFrame.
Note
If GPU buffers are used, this function uploads the frame from the CPU buffer to the GPU before returning.

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