Ring Daemon 16.0.0
Loading...
Searching...
No Matches
jami::video::HardwareAccel Class Reference

Provides an abstraction layer to the hardware acceleration APIs in FFmpeg. More...

#include <accel.h>

Collaboration diagram for jami::video::HardwareAccel:
Collaboration graph

Public Member Functions

bool dynBitrate ()
 
AVCodecID getCodecId () const
 Codec that is being accelerated.
 
std::string getCodecName () const
 Gets the name of the codec.
 
AVPixelFormat getFormat () const
 Hardware format.
 
const std::string & getName () const
 Name of the hardware layer/API being used.
 
AVPixelFormat getSoftwareFormat () const
 Software format.
 
 HardwareAccel (AVCodecID id, const std::string &name, AVHWDeviceType hwType, AVPixelFormat format, AVPixelFormat swFormat, CodecType type, bool dynBitrate)
 Constructs a HardwareAccel object.
 
int initAPI (bool linkable, AVBufferRef *framesCtx)
 
bool isLinked () const
 If hardware decoder can feed hardware encoder directly.
 
bool linkHardware (AVBufferRef *framesCtx)
 Links this HardwareAccel's frames context with the passed in context.
 
void setDetails (AVCodecContext *codecCtx)
 Set some extra details in the codec context.
 
std::unique_ptr< VideoFrametransfer (const VideoFrame &frame)
 Transfers a frame to/from the GPU memory.
 
 ~HardwareAccel ()
 Dereferences hardware contexts.
 

Static Public Member Functions

static std::list< HardwareAccelgetCompatibleAccel (AVCodecID id, int width, int height, CodecType type)
 
static std::unique_ptr< VideoFrametransferToMainMemory (const VideoFrame &frame, AVPixelFormat desiredFormat)
 Transfers hardware frame to main memory.
 

Detailed Description

Provides an abstraction layer to the hardware acceleration APIs in FFmpeg.

Definition at line 44 of file accel.h.

Constructor & Destructor Documentation

◆ HardwareAccel()

jami::video::HardwareAccel::HardwareAccel ( AVCodecID  id,
const std::string &  name,
AVHWDeviceType  hwType,
AVPixelFormat  format,
AVPixelFormat  swFormat,
CodecType  type,
bool  dynBitrate 
)

Constructs a HardwareAccel object.

Made public so std::unique_ptr can access it. Should not be called.

Definition at line 118 of file accel.cpp.

◆ ~HardwareAccel()

jami::video::HardwareAccel::~HardwareAccel ( )

Dereferences hardware contexts.

Definition at line 134 of file accel.cpp.

References av_buffer_unref().

Here is the call graph for this function:

Member Function Documentation

◆ dynBitrate()

bool jami::video::HardwareAccel::dynBitrate ( )
inline

Definition at line 156 of file accel.h.

◆ getCodecId()

AVCodecID jami::video::HardwareAccel::getCodecId ( ) const
inline

Codec that is being accelerated.

Definition at line 83 of file accel.h.

◆ getCodecName()

std::string jami::video::HardwareAccel::getCodecName ( ) const

Gets the name of the codec.

Decoding: avcodec_get_name(id_) Encoding: avcodec_get_name(id_) + '_' + name_

Definition at line 246 of file accel.cpp.

References jami::CODEC_DECODER, jami::CODEC_ENCODER, and jami::emitSignal().

Referenced by initAPI(), and linkHardware().

Here is the call graph for this function:

◆ getCompatibleAccel()

std::list< HardwareAccel > jami::video::HardwareAccel::getCompatibleAccel ( AVCodecID  id,
int  width,
int  height,
CodecType  type 
)
static

Definition at line 424 of file accel.cpp.

References jami::video::apiListDec, jami::video::apiListEnc, jami::CODEC_ENCODER, and jami::emitSignal().

Referenced by jami::MediaEncoder::testH265Accel().

Here is the call graph for this function:

◆ getFormat()

AVPixelFormat jami::video::HardwareAccel::getFormat ( ) const
inline

Hardware format.

Definition at line 93 of file accel.h.

◆ getName()

const std::string & jami::video::HardwareAccel::getName ( ) const
inline

Name of the hardware layer/API being used.

Definition at line 88 of file accel.h.

Referenced by jami::video::getFormatCb().

◆ getSoftwareFormat()

AVPixelFormat jami::video::HardwareAccel::getSoftwareFormat ( ) const
inline

Software format.

For encoding it is the format expected by the hardware. For decoding it is the format output by the hardware.

Definition at line 101 of file accel.h.

◆ initAPI()

int jami::video::HardwareAccel::initAPI ( bool  linkable,
AVBufferRef framesCtx 
)

Definition at line 406 of file accel.cpp.

References jami::emitSignal(), getCodecName(), and linkHardware().

Here is the call graph for this function:

◆ isLinked()

bool jami::video::HardwareAccel::isLinked ( ) const
inline

If hardware decoder can feed hardware encoder directly.

Returns whether or not the decoder is linked to an encoder or vice-versa. Being linked means an encoder can directly use the decoder's hardware frame, without first transferring it to main memory.

Definition at line 118 of file accel.h.

◆ linkHardware()

bool jami::video::HardwareAccel::linkHardware ( AVBufferRef framesCtx)

Links this HardwareAccel's frames context with the passed in context.

This serves to skip transferring a decoded frame back to main memory before encoding.

Definition at line 350 of file accel.cpp.

References av_buffer_unref(), jami::emitSignal(), getCodecName(), and JAMI_DBG.

Referenced by initAPI().

Here is the call graph for this function:

◆ setDetails()

void jami::video::HardwareAccel::setDetails ( AVCodecContext codecCtx)

Set some extra details in the codec context.

Should be called after a successful setup (setupDecoder or setupEncoder). For decoding, sets the hw_device_ctx and get_format callback. If the decoder has a frames context, mark as linked. For encoding, sets hw_device_ctx and hw_frames_ctx, and may set some hardware codec options.

Definition at line 307 of file accel.cpp.

References jami::CODEC_DECODER, jami::CODEC_ENCODER, jami::emitSignal(), and jami::video::getFormatCb().

Here is the call graph for this function:

◆ transfer()

std::unique_ptr< VideoFrame > jami::video::HardwareAccel::transfer ( const VideoFrame frame)

Transfers a frame to/from the GPU memory.

Transfers a hardware decoded frame back to main memory. Should be called after the frame is decoded using avcodec_send_packet/avcodec_receive_frame or before the frame is encoded using avcodec_send_frame/avcodec_receive_packet.

Parameters
frameHardware frame when decoding, software frame when encoding.
Returns
Software frame when decoding, hardware frame when encoding.

Definition at line 257 of file accel.cpp.

References jami::CODEC_DECODER, jami::CODEC_ENCODER, jami::emitSignal(), jami::libav_utils::getError(), JAMI_ERR, and transferToMainMemory().

Here is the call graph for this function:

◆ transferToMainMemory()

std::unique_ptr< VideoFrame > jami::video::HardwareAccel::transferToMainMemory ( const VideoFrame frame,
AVPixelFormat  desiredFormat 
)
static

Transfers hardware frame to main memory.

Transfers a hardware decoded frame back to main memory. Should be called after the frame is decoded using avcodec_send_packet/avcodec_receive_frame.

If @frame is software, this is a no-op.

Parameters
frameRefrerence to the decoded hardware frame.
desiredFormatSoftware pixel format that the hardware outputs.
Returns
Software frame.

Definition at line 372 of file accel.cpp.

References av_frame_new_side_data_from_buf(), and jami::emitSignal().

Referenced by transfer(), jami::MediaRecorder::StreamObserver::update(), and jami::video::VideoMixer::update().

Here is the call graph for this function:

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