Ring Daemon 16.0.0
|
Provides an abstraction layer to the hardware acceleration APIs in FFmpeg. More...
#include <accel.h>
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< VideoFrame > | transfer (const VideoFrame &frame) |
Transfers a frame to/from the GPU memory. | |
~HardwareAccel () | |
Dereferences hardware contexts. | |
Static Public Member Functions | |
static std::list< HardwareAccel > | getCompatibleAccel (AVCodecID id, int width, int height, CodecType type) |
static std::unique_ptr< VideoFrame > | transferToMainMemory (const VideoFrame &frame, AVPixelFormat desiredFormat) |
Transfers hardware frame to main memory. | |
Provides an abstraction layer to the hardware acceleration APIs in FFmpeg.
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.
jami::video::HardwareAccel::~HardwareAccel | ( | ) |
Dereferences hardware contexts.
Definition at line 134 of file accel.cpp.
References av_buffer_unref().
|
inline |
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().
|
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().
|
inline |
|
inline |
Name of the hardware layer/API being used.
Definition at line 88 of file accel.h.
Referenced by jami::video::getFormatCb().
|
inline |
int jami::video::HardwareAccel::initAPI | ( | bool | linkable, |
AVBufferRef * | framesCtx | ||
) |
Definition at line 406 of file accel.cpp.
References jami::emitSignal(), getCodecName(), and linkHardware().
|
inline |
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().
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().
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.
frame | Hardware frame when decoding, software 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().
|
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.
frame | Refrerence to the decoded hardware frame. |
desiredFormat | Software pixel format that the hardware outputs. |
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().