Sunshine0.0.5917
Sunshine 0.0.5917
Self-hosted game stream host for Moonlight.
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>

Inheritance diagram for nvenc::nvenc_base:
Collaboration diagram for nvenc::nvenc_base:

Public Member Functions

bool create_encoder (const ::nvenc::nvenc_config &config, const video::config_t &client_config, const video::sunshine_colorspace_t &colorspace, platf::pix_fmt_e buffer_format) override
 Create the encoder.
void destroy_encoder () override
 Destroy the encoder. Derived classes classes call it in the destructor.
::nvenc::nvenc_encoded_frame encode_frame (uint64_t frame_index, bool force_idr) override
 Encode the next frame using platform-specific input surface.
bool invalidate_ref_frames (uint64_t first_frame, uint64_t last_frame) override
 Perform reference frame invalidation (RFI) procedure.
 nvenc_base (const nvenc_base &)=delete
 nvenc_base (NV_ENC_DEVICE_TYPE device_type)
nvenc_base & operator= (const nvenc_base &)=delete
 ~nvenc_base () override
 Destroy the encoder wrapper; callers release the encoder session with destroy_encoder().
Public Member Functions inherited from nvenc::nvenc_encoder
virtual nvenc_encoded_frame encode_frame (std::uint64_t frame_index, bool force_idr)=0
 Encode the next frame using the platform-specific input surface.
virtual bool invalidate_ref_frames (std::uint64_t first_frame, std::uint64_t last_frame)=0
 Invalidate reference frames in the requested range.
virtual ~nvenc_encoder ()=default
 Destroy the SDK-neutral encoder interface.

Protected Member Functions

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 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.
bool nvenc_failed (NVENCSTATUS status)
 Check whether an NVENC API status represents failure.
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.

Protected Attributes

completion_event_t * async_event_handle = nullptr
std::variant< ID3D11Device *, CUctx_st * > device {static_cast<ID3D11Device *>(nullptr)}
 Native D3D11 device or CUDA context, set by the derived backend.
const NV_ENC_DEVICE_TYPE device_type
 NVENC device backend used by this encoder instance.
encoder_session_t * encoder = nullptr
 Opaque NVENC encoder session handle returned by the driver.
struct nvenc::nvenc_base:: { ... }  encoder_params
 Current encoder dimensions, pixel format, and reference-frame settings.
std::string last_nvenc_error_string
 Last NVENC error string.
std::shared_ptr< NV_ENCODE_API_FUNCTION_LIST > nvenc
NV_ENC_REGISTERED_PTR registered_input_buffer = nullptr

Detailed Description

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

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.

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::nvenc_config & config,
const video::config_t & client_config,
const video::sunshine_colorspace_t & colorspace,
platf::pix_fmt_e buffer_format )
overridevirtual

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

Implements nvenc::nvenc_encoder.

◆ destroy_encoder()

void nvenc::nvenc_base::destroy_encoder ( )
overridevirtual

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

Implements nvenc::nvenc_encoder.

◆ encode_frame()

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

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.

◆ 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

Implemented in nvenc::nvenc_d3d11.

◆ invalidate_ref_frames()

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

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.

◆ nvenc_failed()

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

Check whether an NVENC API status represents failure.

Parameters
statusNative status code returned by the platform API.
Returns
True when the status is an NVENC error code.

◆ 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

◆ 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

Reimplemented in nvenc::nvenc_d3d11.

Member Data Documentation

◆ async_event_handle

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

(optional) Native event registered for encode completion. Can be set in constructor or init_library(), must override wait_for_async_event().

◆ 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().

◆ 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().


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