Hermes
0.7.0
Linux game streaming host
Toggle main menu visibility
Loading...
Searching...
No Matches
nvenc_base.h
Go to the documentation of this file.
1
5
#pragma once
6
7
// lib includes
8
#include <ffnvcodec/nvEncodeAPI.h>
9
10
// local includes
11
#include "
nvenc_colorspace.h
"
12
#include "
nvenc_config.h
"
13
#include "
nvenc_encoded_frame.h
"
14
#include "
src/logging.h
"
15
#include "
src/video.h
"
16
20
namespace
nvenc
{
21
26
class
nvenc_base
{
27
public
:
31
explicit
nvenc_base
(NV_ENC_DEVICE_TYPE device_type);
32
virtual
~nvenc_base
();
33
34
nvenc_base
(
const
nvenc_base
&) =
delete
;
35
nvenc_base
&operator=(
const
nvenc_base
&) =
delete
;
36
45
bool
create_encoder
(
const
nvenc_config
&config,
const
video::config_t
&client_config,
const
nvenc_colorspace_t
&colorspace, NV_ENC_BUFFER_FORMAT buffer_format);
46
51
void
destroy_encoder
();
52
61
nvenc_encoded_frame
encode_frame
(uint64_t frame_index,
bool
force_idr);
62
70
bool
invalidate_ref_frames
(uint64_t first_frame, uint64_t last_frame);
71
72
protected
:
78
virtual
bool
init_library
() = 0;
79
86
virtual
bool
create_and_register_input_buffer
() = 0;
87
93
virtual
bool
synchronize_input_buffer
() {
94
return
true
;
95
}
96
103
virtual
bool
wait_for_async_event
(uint32_t timeout_ms) {
104
return
false
;
105
}
106
107
bool
nvenc_failed(NVENCSTATUS status);
108
117
uint32_t
min_struct_version
(uint32_t version, uint32_t v11_struct_version = 0, uint32_t v12_struct_version = 0);
118
119
const
NV_ENC_DEVICE_TYPE device_type;
120
121
void
*encoder =
nullptr
;
122
123
struct
{
124
uint32_t width = 0;
125
uint32_t height = 0;
126
NV_ENC_BUFFER_FORMAT buffer_format = NV_ENC_BUFFER_FORMAT_UNDEFINED;
127
uint32_t ref_frames_in_dpb = 0;
128
bool
rfi =
false
;
129
} encoder_params;
130
131
std::string last_nvenc_error_string;
132
133
// Derived classes set these variables
134
void
*
device
=
nullptr
;
136
std::shared_ptr<NV_ENCODE_API_FUNCTION_LIST>
nvenc
;
138
NV_ENC_REGISTERED_PTR
registered_input_buffer
=
nullptr
;
140
void
*
async_event_handle
=
nullptr
;
142
143
private
:
144
NV_ENC_OUTPUT_PTR output_bitstream =
nullptr
;
145
uint32_t minimum_api_version = 0;
146
147
struct
{
148
uint64_t last_encoded_frame_index = 0;
149
bool
rfi_needs_confirmation =
false
;
150
std::pair<uint64_t, uint64_t> last_rfi_range;
151
logging::min_max_avg_periodic_logger<double>
frame_size_logger = {debug,
"NvEnc: encoded frame sizes in kB"
,
""
};
152
} encoder_state;
153
};
154
155
}
// namespace nvenc
logging::min_max_avg_periodic_logger
A helper class for tracking and logging numerical values across a period of time.
Definition
logging.h:102
nvenc::nvenc_base::invalidate_ref_frames
bool invalidate_ref_frames(uint64_t first_frame, uint64_t last_frame)
Perform reference frame invalidation (RFI) procedure.
Definition
nvenc_base.cpp:574
nvenc::nvenc_base::encode_frame
nvenc_encoded_frame encode_frame(uint64_t frame_index, bool force_idr)
Encode the next frame using platform-specific input surface.
Definition
nvenc_base.cpp:490
nvenc::nvenc_base::registered_input_buffer
NV_ENC_REGISTERED_PTR registered_input_buffer
Definition
nvenc_base.h:138
nvenc::nvenc_base::create_encoder
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.
Definition
nvenc_base.cpp:100
nvenc::nvenc_base::create_and_register_input_buffer
virtual bool create_and_register_input_buffer()=0
Required. Used for creating outside-facing input surface, registering this surface with nvenc->nvEncR...
nvenc::nvenc_base::min_struct_version
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.
Definition
nvenc_base.cpp:666
nvenc::nvenc_base::wait_for_async_event
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_even...
Definition
nvenc_base.h:103
nvenc::nvenc_base::async_event_handle
void * async_event_handle
Definition
nvenc_base.h:140
nvenc::nvenc_base::destroy_encoder
void destroy_encoder()
Destroy the encoder. Derived classes classes call it in the destructor.
Definition
nvenc_base.cpp:459
nvenc::nvenc_base::device
void * device
Definition
nvenc_base.h:134
nvenc::nvenc_base::init_library
virtual bool init_library()=0
Required. Used for loading NvEnc library and setting nvenc variable with NvEncodeAPICreateInstance()....
nvenc::nvenc_base::nvenc_base
nvenc_base(NV_ENC_DEVICE_TYPE device_type)
Definition
nvenc_base.cpp:92
nvenc::nvenc_base::synchronize_input_buffer
virtual bool synchronize_input_buffer()
Optional. Override if you must perform additional operations on the registered input surface in the b...
Definition
nvenc_base.h:93
logging.h
Declarations for logging related functions.
nvenc
Standalone NVENC encoder.
Definition
nvenc_base.cpp:90
nvenc_colorspace.h
Declarations for NVENC YUV colorspace.
nvenc_config.h
Declarations for NVENC encoder configuration.
nvenc_encoded_frame.h
Declarations for NVENC encoded frame.
nvenc::nvenc_colorspace_t
YUV colorspace and color range.
Definition
nvenc_colorspace.h:15
nvenc::nvenc_config
NVENC encoder configuration.
Definition
nvenc_config.h:18
nvenc::nvenc_encoded_frame
Encoded frame.
Definition
nvenc_encoded_frame.h:16
video::config_t
Definition
video.h:37
video.h
Declarations for video.
src
nvenc
nvenc_base.h
Generated by
1.18.0