obs-ffmpeg: Show encoder name when logging jim-nvenc

This commit is contained in:
jp9000 2019-03-28 16:37:49 -07:00
parent 81354a9903
commit 5d83e1aec4
3 changed files with 43 additions and 27 deletions

View File

@ -7,6 +7,21 @@ static pthread_mutex_t init_mutex = PTHREAD_MUTEX_INITIALIZER;
NV_ENCODE_API_FUNCTION_LIST nv = {NV_ENCODE_API_FUNCTION_LIST_VER}; NV_ENCODE_API_FUNCTION_LIST nv = {NV_ENCODE_API_FUNCTION_LIST_VER};
NV_CREATE_INSTANCE_FUNC nv_create_instance = NULL; NV_CREATE_INSTANCE_FUNC nv_create_instance = NULL;
#define error(format, ...) \
blog(LOG_ERROR, "[jim-nvenc] " format, ##__VA_ARGS__)
static inline bool nv_failed(NVENCSTATUS err, const char *func, const char *call)
{
if (err == NV_ENC_SUCCESS)
return false;
error("%s: %s failed: %d (%s)", func, call, (int)err,
nv_error_name(err));
return true;
}
#define NV_FAILED(x) nv_failed(x, __FUNCTION__, #x)
bool load_nvenc_lib(void) bool load_nvenc_lib(void)
{ {
if (sizeof(void*) == 8) { if (sizeof(void*) == 8) {

View File

@ -12,6 +12,15 @@
#define EXTRA_BUFFERS 5 #define EXTRA_BUFFERS 5
#define do_log(level, format, ...) \
blog(level, "[jim-nvenc: '%s'] " format, \
obs_encoder_get_name(enc->encoder), ##__VA_ARGS__)
#define error(format, ...) do_log(LOG_ERROR, format, ##__VA_ARGS__)
#define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
#define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)
#define error_hr(msg) \ #define error_hr(msg) \
error("%s: %s: 0x%08lX", __FUNCTION__, msg, (uint32_t)hr); error("%s: %s: 0x%08lX", __FUNCTION__, msg, (uint32_t)hr);
@ -73,6 +82,19 @@ struct nv_bitstream {
HANDLE event; HANDLE event;
}; };
static inline bool nv_failed(struct nvenc_data *enc, NVENCSTATUS err,
const char *func, const char *call)
{
if (err == NV_ENC_SUCCESS)
return false;
error("%s: %s failed: %d (%s)", func, call, (int)err,
nv_error_name(err));
return true;
}
#define NV_FAILED(x) nv_failed(enc, x, __FUNCTION__, #x)
static bool nv_bitstream_init(struct nvenc_data *enc, struct nv_bitstream *bs) static bool nv_bitstream_init(struct nvenc_data *enc, struct nv_bitstream *bs)
{ {
NV_ENC_CREATE_BITSTREAM_BUFFER buf = {NV_ENC_CREATE_BITSTREAM_BUFFER_VER}; NV_ENC_CREATE_BITSTREAM_BUFFER buf = {NV_ENC_CREATE_BITSTREAM_BUFFER_VER};
@ -227,7 +249,7 @@ static bool nvenc_update(void *data, obs_data_t *settings)
return true; return true;
} }
static HANDLE get_lib(const char *lib) static HANDLE get_lib(struct nvenc_data *enc, const char *lib)
{ {
HMODULE mod = GetModuleHandleA(lib); HMODULE mod = GetModuleHandleA(lib);
if (mod) if (mod)
@ -243,8 +265,8 @@ typedef HRESULT (WINAPI *CREATEDXGIFACTORY1PROC)(REFIID, void **);
static bool init_d3d11(struct nvenc_data *enc, obs_data_t *settings) static bool init_d3d11(struct nvenc_data *enc, obs_data_t *settings)
{ {
HMODULE dxgi = get_lib("DXGI.dll"); HMODULE dxgi = get_lib(enc, "DXGI.dll");
HMODULE d3d11 = get_lib("D3D11.dll"); HMODULE d3d11 = get_lib(enc, "D3D11.dll");
CREATEDXGIFACTORY1PROC create_dxgi; CREATEDXGIFACTORY1PROC create_dxgi;
PFN_D3D11_CREATE_DEVICE create_device; PFN_D3D11_CREATE_DEVICE create_device;
IDXGIFactory1 *factory; IDXGIFactory1 *factory;
@ -375,7 +397,7 @@ static bool init_encoder(struct nvenc_data *enc, obs_data_t *settings)
err = nv.nvEncGetEncodePresetConfig(enc->session, err = nv.nvEncGetEncodePresetConfig(enc->session,
NV_ENC_CODEC_H264_GUID, nv_preset, &preset_config); NV_ENC_CODEC_H264_GUID, nv_preset, &preset_config);
if (nv_failed(err, __FUNCTION__, "nvEncGetEncodePresetConfig")) { if (nv_failed(enc, err, __FUNCTION__, "nvEncGetEncodePresetConfig")) {
return false; return false;
} }
@ -741,7 +763,7 @@ static bool get_encoded_packet(struct nvenc_data *enc, bool finalize)
if (nvtex->mapped_res) { if (nvtex->mapped_res) {
NVENCSTATUS err; NVENCSTATUS err;
err = nv.nvEncUnmapInputResource(s, nvtex->mapped_res); err = nv.nvEncUnmapInputResource(s, nvtex->mapped_res);
if (nv_failed(err, __FUNCTION__, "unmap")) { if (nv_failed(enc, err, __FUNCTION__, "unmap")) {
return false; return false;
} }
nvtex->mapped_res = NULL; nvtex->mapped_res = NULL;
@ -834,7 +856,7 @@ static bool nvenc_encode_tex(void *data, uint32_t handle, int64_t pts,
err = nv.nvEncEncodePicture(enc->session, &params); err = nv.nvEncEncodePicture(enc->session, &params);
if (err != NV_ENC_SUCCESS && err != NV_ENC_ERR_NEED_MORE_INPUT) { if (err != NV_ENC_SUCCESS && err != NV_ENC_ERR_NEED_MORE_INPUT) {
nv_failed(err, __FUNCTION__, "nvEncEncodePicture"); nv_failed(enc, err, __FUNCTION__, "nvEncEncodePicture");
return false; return false;
} }

View File

@ -6,30 +6,9 @@
#include <obs-module.h> #include <obs-module.h>
#include "nvEncodeAPI.h" #include "nvEncodeAPI.h"
#define do_log(level, format, ...) \
blog(level, "[jim-nvenc] " format, ##__VA_ARGS__)
#define error(format, ...) do_log(LOG_ERROR, format, ##__VA_ARGS__)
#define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
#define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
#define debug(format, ...) do_log(LOG_DEBUG, format, ##__VA_ARGS__)
typedef NVENCSTATUS (NVENCAPI *NV_CREATE_INSTANCE_FUNC)(NV_ENCODE_API_FUNCTION_LIST*); typedef NVENCSTATUS (NVENCAPI *NV_CREATE_INSTANCE_FUNC)(NV_ENCODE_API_FUNCTION_LIST*);
extern const char *nv_error_name(NVENCSTATUS err); extern const char *nv_error_name(NVENCSTATUS err);
extern NV_ENCODE_API_FUNCTION_LIST nv; extern NV_ENCODE_API_FUNCTION_LIST nv;
extern NV_CREATE_INSTANCE_FUNC nv_create_instance; extern NV_CREATE_INSTANCE_FUNC nv_create_instance;
extern bool init_nvenc(void); extern bool init_nvenc(void);
static inline bool nv_failed(NVENCSTATUS err, const char *func,
const char *call)
{
if (err == NV_ENC_SUCCESS)
return false;
error("%s: %s failed: %d (%s)", func, call, (int)err,
nv_error_name(err));
return true;
}
#define NV_FAILED(x) nv_failed(x, __FUNCTION__, #x)