Skip to content

Commit

Permalink
obs-filter: Fix loading of NVIDIA Audio Effects SDK
Browse files Browse the repository at this point in the history
The NVIDIA Audio Effects SDK currently interferes with the Video
Effects SDK by not releasing a CUDA context.
Till this is fixed upstream, we do it manually. This also requires
 an SDK update to 1.1.0.5 for NVIDIA Audio Effects SDK.

Signed-off-by: pkv <pkv@obsproject.com>
  • Loading branch information
pkviet committed Jul 24, 2022
1 parent cc2030e commit 048090a
Showing 1 changed file with 48 additions and 3 deletions.
51 changes: 48 additions & 3 deletions plugins/obs-filters/noise-suppress-filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,12 @@ static void *nvafx_initialize(void *data)
ng->sample_rate = NVAFX_SAMPLE_RATE;

for (size_t i = 0; i < ng->channels; i++) {
CUcontext old = {0};
CUcontext curr = {0};

if (cuCtxGetCurrent(&old) != CUDA_SUCCESS)
goto failure;

err = NvAFX_CreateEffect(NVAFX_EFFECT_DENOISER,
&ng->handle[i]);
if (err != NVAFX_STATUS_SUCCESS) {
Expand All @@ -247,6 +253,14 @@ static void *nvafx_initialize(void *data)
err);
goto failure;
}
if (cuCtxGetCurrent(&curr) != CUDA_SUCCESS)
goto failure;

if (curr != old) {

cuCtxPopCurrent(NULL);
}

err = NvAFX_SetU32(ng->handle[i],
NVAFX_PARAM_DENOISER_SAMPLE_RATE,
ng->sample_rate);
Expand Down Expand Up @@ -559,10 +573,35 @@ bool load_nvafx(void)
LOAD_SYM(cuCtxPopCurrent);
LOAD_SYM(cuInit);
#undef LOAD_SYM

NvAFX_Status err;
CUresult cudaerr;

NvAFX_Handle h = NULL;

cudaerr = cuInit(0);
if (cudaerr != CUDA_SUCCESS) {
goto cuda_errors;
}
CUcontext old = {0};
CUcontext curr = {0};
cudaerr = cuCtxGetCurrent(&old);
if (cudaerr != CUDA_SUCCESS) {
goto cuda_errors;
}

err = NvAFX_CreateEffect(NVAFX_EFFECT_DENOISER, &h);
cudaerr = cuCtxGetCurrent(&curr);
if (cudaerr != CUDA_SUCCESS) {
goto cuda_errors;
}

if (curr != old) {
cudaerr = cuCtxPopCurrent(NULL);
if (cudaerr != CUDA_SUCCESS)
goto cuda_errors;
}

if (err != NVAFX_STATUS_SUCCESS) {
if (err == NVAFX_STATUS_GPU_UNSUPPORTED) {
blog(LOG_INFO,
Expand All @@ -577,14 +616,20 @@ bool load_nvafx(void)

err = NvAFX_DestroyEffect(h);
if (err != NVAFX_STATUS_SUCCESS) {
blog(LOG_ERROR, "NvAFX_DestroyEffect() failed, error %i", err);
blog(LOG_ERROR,
"[noise suppress]: NVIDIA RTX AUDIO FX disabled, error %i",
err);
goto unload_everything;
}

nvafx_loaded = true;
blog(LOG_INFO, "[noise suppress]: NVIDIA RTX AUDIO FX enabled");
return true;

cuda_errors:
blog(LOG_ERROR,
"[noise suppress]: NVIDIA RTX AUDIO FX disabled, CUDA error %i",
cudaerr);
unload_everything:
release_lib();
#endif
Expand All @@ -594,17 +639,17 @@ bool load_nvafx(void)
#pragma warning(pop)
#endif

#ifdef LIBNVAFX_ENABLED
void unload_nvafx(void)
{
#ifdef LIBNVAFX_ENABLED
release_lib();

if (nvafx_initializer_mutex_initialized) {
pthread_mutex_destroy(&nvafx_initializer_mutex);
nvafx_initializer_mutex_initialized = false;
}
#endif
}
#endif

static void *noise_suppress_create(obs_data_t *settings, obs_source_t *filter)
{
Expand Down

0 comments on commit 048090a

Please sign in to comment.