mirror of
https://github.com/thinkonmay/sunshine-sdk.git
synced 2026-01-14 20:04:54 +00:00
58 lines
1.4 KiB
C++
58 lines
1.4 KiB
C++
/**
|
|
* @file src/nvenc/nvenc_d3d11.cpp
|
|
* @brief Definitions for abstract Direct3D11 NVENC encoder.
|
|
*/
|
|
// local includes
|
|
#include "src/logging.h"
|
|
|
|
#ifdef _WIN32
|
|
#include "nvenc_d3d11.h"
|
|
|
|
namespace nvenc {
|
|
|
|
nvenc_d3d11::~nvenc_d3d11() {
|
|
if (dll) {
|
|
FreeLibrary(dll);
|
|
dll = NULL;
|
|
}
|
|
}
|
|
|
|
bool nvenc_d3d11::init_library() {
|
|
if (dll) {
|
|
return true;
|
|
}
|
|
|
|
#ifdef _WIN64
|
|
constexpr auto dll_name = "nvEncodeAPI64.dll";
|
|
#else
|
|
constexpr auto dll_name = "nvEncodeAPI.dll";
|
|
#endif
|
|
|
|
if ((dll = LoadLibraryEx(dll_name, NULL, LOAD_LIBRARY_SEARCH_SYSTEM32))) {
|
|
if (auto create_instance = (decltype(NvEncodeAPICreateInstance) *) GetProcAddress(dll, "NvEncodeAPICreateInstance")) {
|
|
auto new_nvenc = std::make_unique<NV_ENCODE_API_FUNCTION_LIST>();
|
|
new_nvenc->version = min_struct_version(NV_ENCODE_API_FUNCTION_LIST_VER);
|
|
if (nvenc_failed(create_instance(new_nvenc.get()))) {
|
|
BOOST_LOG(error) << "NvEnc: NvEncodeAPICreateInstance() failed: " << last_nvenc_error_string;
|
|
} else {
|
|
nvenc = std::move(new_nvenc);
|
|
return true;
|
|
}
|
|
} else {
|
|
BOOST_LOG(error) << "NvEnc: No NvEncodeAPICreateInstance() in " << dll_name;
|
|
}
|
|
} else {
|
|
BOOST_LOG(debug) << "NvEnc: Couldn't load NvEnc library " << dll_name;
|
|
}
|
|
|
|
if (dll) {
|
|
FreeLibrary(dll);
|
|
dll = NULL;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
} // namespace nvenc
|
|
#endif
|