Hermes 0.7.0
Linux game streaming host
Loading...
Searching...
No Matches
nvenc::nvenc_base Class Referenceabstract

Abstract platform-agnostic base of standalone NVENC encoder. Derived classes perform platform-specific operations. More...

#include <src/nvenc/nvenc_base.h>

Public Member Functions

 nvenc_base (NV_ENC_DEVICE_TYPE device_type)
 nvenc_base (const nvenc_base &)=delete
nvenc_base & operator= (const nvenc_base &)=delete
bool create_encoder (const nvenc_config &config, const video::config_t &client_config, const nvenc_colorspace_t &colorspace, NV_ENC_BUFFER_FORMAT buffer_format)
 Create the encoder.
void destroy_encoder ()
 Destroy the encoder. Derived classes classes call it in the destructor.
nvenc_encoded_frame encode_frame (uint64_t frame_index, bool force_idr)
 Encode the next frame using platform-specific input surface.
bool invalidate_ref_frames (uint64_t first_frame, uint64_t last_frame)
 Perform reference frame invalidation (RFI) procedure.

Protected Member Functions

virtual bool init_library ()=0
 Required. Used for loading NvEnc library and setting nvenc variable with NvEncodeAPICreateInstance(). Called during create_encoder() if nvenc variable is not initialized.
virtual bool create_and_register_input_buffer ()=0
 Required. Used for creating outside-facing input surface, registering this surface with nvenc->nvEncRegisterResource() and setting registered_input_buffer variable. Called during create_encoder().
virtual bool synchronize_input_buffer ()
 Optional. Override if you must perform additional operations on the registered input surface in the beginning of encode_frame(). Typically used for interop copy.
virtual bool wait_for_async_event (uint32_t timeout_ms)
 Optional. Override if you want to create encoder in async mode. In this case must also set async_event_handle variable.
bool nvenc_failed (NVENCSTATUS status)
uint32_t min_struct_version (uint32_t version, uint32_t v11_struct_version=0, uint32_t v12_struct_version=0)
 This function returns the corresponding struct version for the minimum API required by the codec.

Protected Attributes

const NV_ENC_DEVICE_TYPE device_type
void * encoder = nullptr
struct nvenc::nvenc_base:: { ... }  encoder_params
std::string last_nvenc_error_string
void * device = nullptr
std::shared_ptr< NV_ENCODE_API_FUNCTION_LIST > nvenc
NV_ENC_REGISTERED_PTR registered_input_buffer = nullptr
void * async_event_handle = nullptr

Detailed Description

Abstract platform-agnostic base of standalone NVENC encoder. Derived classes perform platform-specific operations.

Definition at line 26 of file nvenc_base.h.

Constructor & Destructor Documentation

◆ nvenc_base()

nvenc::nvenc_base::nvenc_base ( NV_ENC_DEVICE_TYPE device_type)
explicit
Parameters
device_typeUnderlying device type used by derived class.

Definition at line 92 of file nvenc_base.cpp.

◆ ~nvenc_base()

nvenc::nvenc_base::~nvenc_base ( )
virtual

Definition at line 96 of file nvenc_base.cpp.

Member Function Documentation

◆ create_and_register_input_buffer()

virtual bool nvenc::nvenc_base::create_and_register_input_buffer ( )
protectedpure virtual

Required. Used for creating outside-facing input surface, registering this surface with nvenc->nvEncRegisterResource() and setting registered_input_buffer variable. Called during create_encoder().

Returns
true on success, false on error

◆ create_encoder()

bool nvenc::nvenc_base::create_encoder ( const nvenc_config & config,
const video::config_t & client_config,
const nvenc_colorspace_t & colorspace,
NV_ENC_BUFFER_FORMAT buffer_format )

Create the encoder.

Parameters
configNVENC encoder configuration.
client_configStream configuration requested by the client.
colorspaceYUV colorspace.
buffer_formatPlatform-agnostic input surface format.
Returns
true on success, false on error

Definition at line 100 of file nvenc_base.cpp.

◆ destroy_encoder()

void nvenc::nvenc_base::destroy_encoder ( )

Destroy the encoder. Derived classes classes call it in the destructor.

Definition at line 459 of file nvenc_base.cpp.

◆ encode_frame()

nvenc_encoded_frame nvenc::nvenc_base::encode_frame ( uint64_t frame_index,
bool force_idr )

Encode the next frame using platform-specific input surface.

Parameters
frame_indexFrame index that uniquely identifies the frame. Afterwards serves as parameter for invalidate_ref_frames(). No restrictions on the first frame index, but later frame indexes must be subsequent.
force_idrWhether to encode frame as forced IDR.
Returns
Encoded frame.

Definition at line 490 of file nvenc_base.cpp.

◆ init_library()

virtual bool nvenc::nvenc_base::init_library ( )
protectedpure virtual

Required. Used for loading NvEnc library and setting nvenc variable with NvEncodeAPICreateInstance(). Called during create_encoder() if nvenc variable is not initialized.

Returns
true on success, false on error

◆ invalidate_ref_frames()

bool nvenc::nvenc_base::invalidate_ref_frames ( uint64_t first_frame,
uint64_t last_frame )

Perform reference frame invalidation (RFI) procedure.

Parameters
first_frameFirst frame index of the invalidation range.
last_frameLast frame index of the invalidation range.
Returns
true on success, false on error. After error next frame must be encoded with force_idr = true.

Definition at line 574 of file nvenc_base.cpp.

◆ min_struct_version()

uint32_t nvenc::nvenc_base::min_struct_version ( uint32_t version,
uint32_t v11_struct_version = 0,
uint32_t v12_struct_version = 0 )
protected

This function returns the corresponding struct version for the minimum API required by the codec.

Reducing the struct versions maximizes driver compatibility by avoiding needless API breaks.

Parameters
versionThe raw structure version from NVENCAPI_STRUCT_VERSION().
v11_struct_versionOptionally specifies the struct version to use with v11 SDK major versions.
v12_struct_versionOptionally specifies the struct version to use with v12 SDK major versions.
Returns
A suitable struct version for the active codec.

Definition at line 666 of file nvenc_base.cpp.

◆ nvenc_failed()

bool nvenc::nvenc_base::nvenc_failed ( NVENCSTATUS status)
protected

Definition at line 612 of file nvenc_base.cpp.

◆ synchronize_input_buffer()

virtual bool nvenc::nvenc_base::synchronize_input_buffer ( )
inlineprotectedvirtual

Optional. Override if you must perform additional operations on the registered input surface in the beginning of encode_frame(). Typically used for interop copy.

Returns
true on success, false on error

Definition at line 93 of file nvenc_base.h.

◆ wait_for_async_event()

virtual bool nvenc::nvenc_base::wait_for_async_event ( uint32_t timeout_ms)
inlineprotectedvirtual

Optional. Override if you want to create encoder in async mode. In this case must also set async_event_handle variable.

Parameters
timeout_msWait timeout in milliseconds
Returns
true on success, false on timeout or error

Definition at line 103 of file nvenc_base.h.

Member Data Documentation

◆ async_event_handle

void* nvenc::nvenc_base::async_event_handle = nullptr
protected

(optional) Platform-specific handle of event object event. Can be set in constructor or init_library(), must override wait_for_async_event().

Definition at line 140 of file nvenc_base.h.

◆ device

void* nvenc::nvenc_base::device = nullptr
protected

Platform-specific handle of encoding device. Should be set in constructor or init_library().

Definition at line 134 of file nvenc_base.h.

◆ device_type

const NV_ENC_DEVICE_TYPE nvenc::nvenc_base::device_type
protected

Definition at line 119 of file nvenc_base.h.

◆ encoder

void* nvenc::nvenc_base::encoder = nullptr
protected

Definition at line 121 of file nvenc_base.h.

◆ last_nvenc_error_string

std::string nvenc::nvenc_base::last_nvenc_error_string
protected

Definition at line 131 of file nvenc_base.h.

◆ nvenc

std::shared_ptr<NV_ENCODE_API_FUNCTION_LIST> nvenc::nvenc_base::nvenc
protected

Function pointers list produced by NvEncodeAPICreateInstance(). Should be set in init_library().

Definition at line 136 of file nvenc_base.h.

◆ registered_input_buffer

NV_ENC_REGISTERED_PTR nvenc::nvenc_base::registered_input_buffer = nullptr
protected

Platform-specific input surface registered with NvEncRegisterResource(). Should be set in create_and_register_input_buffer().

Definition at line 138 of file nvenc_base.h.


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