Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable UI if plugin is not available #144

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 31 additions & 5 deletions src/audio-capture-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,41 @@
#include "audio-capture-helper.hpp"
#include "format-conversion.hpp"

AUDIOCLIENT_ACTIVATION_PARAMS AudioCaptureHelper::GetParams()
bool system_supported = false;
bool AudioCaptureHelper::TestPluginAvailable()
{
auto mode = PROCESS_LOOPBACK_MODE_INCLUDE_TARGET_PROCESS_TREE;
try {
auto params = AudioCaptureHelper::GetParams(
GetCurrentProcessId(), PROCESS_LOOPBACK_MODE_INCLUDE_TARGET_PROCESS_TREE);
auto propvariant = AudioCaptureHelper::GetPropvariant(&params);

wil::com_ptr<IActivateAudioInterfaceAsyncOperation> async_op;
CompletionHandler completion_handler;

THROW_IF_FAILED(ActivateAudioInterfaceAsync(VIRTUAL_AUDIO_DEVICE_PROCESS_LOOPBACK,
__uuidof(IAudioClient), &propvariant,
&completion_handler, &async_op));

completion_handler.event_finished.wait();
THROW_IF_FAILED(completion_handler.activate_hr);

info("Plugin can be used");
return true;

} catch (wil::ResultException e) {
warn("Plugin is unavailable because of OS limit");
return false;
}
}

AUDIOCLIENT_ACTIVATION_PARAMS AudioCaptureHelper::GetParams(DWORD process_id,
PROCESS_LOOPBACK_MODE mode)
{
return {
.ActivationType = AUDIOCLIENT_ACTIVATION_TYPE_PROCESS_LOOPBACK,
.ProcessLoopbackParams =
{
.TargetProcessId = pid,
.TargetProcessId = process_id,
.ProcessLoopbackMode = mode,
},
};
Expand All @@ -42,7 +68,7 @@ AudioCaptureHelper::GetPropvariant(AUDIOCLIENT_ACTIVATION_PARAMS *params)

void AudioCaptureHelper::InitClient()
{
auto params = GetParams();
auto params = GetParams(pid, PROCESS_LOOPBACK_MODE_INCLUDE_TARGET_PROCESS_TREE);
auto propvariant = GetPropvariant(&params);

wil::com_ptr<IActivateAudioInterfaceAsyncOperation> async_op;
Expand Down Expand Up @@ -178,4 +204,4 @@ AudioCaptureHelper::~AudioCaptureHelper()

events[HelperEvents::Shutdown].SetEvent();
capture_thread.join();
}
}
7 changes: 5 additions & 2 deletions src/audio-capture-helper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ class AudioCaptureHelper {
std::array<wil::unique_event, HelperEvents::Count> events;
std::thread capture_thread;

AUDIOCLIENT_ACTIVATION_PARAMS GetParams();
PROPVARIANT GetPropvariant(AUDIOCLIENT_ACTIVATION_PARAMS *params);
static AUDIOCLIENT_ACTIVATION_PARAMS GetParams(DWORD process_id,
PROCESS_LOOPBACK_MODE mode);
static PROPVARIANT GetPropvariant(AUDIOCLIENT_ACTIVATION_PARAMS *params);

void InitClient();
void InitCapture();
Expand All @@ -82,6 +83,8 @@ class AudioCaptureHelper {
void CaptureSafe();

public:
static bool TestPluginAvailable();

DWORD GetPid() { return pid; }

AudioCaptureHelper(Mixer *mixer, WAVEFORMATEX format, DWORD pid);
Expand Down
10 changes: 10 additions & 0 deletions src/audio-capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "audio-capture.hpp"
#include "audio-capture-helper-manager.hpp"

extern bool system_supported;

AudioCaptureHelperManager helper_manager;

void AudioCapture::StartCapture(const std::set<DWORD> &new_pids)
Expand Down Expand Up @@ -513,6 +515,14 @@ static obs_properties_t *audio_capture_properties(void *data)
obs_properties_add_group(ps, SETTING_ACTIVE_SESSION_GROUP, TEXT_ACTIVE_SESSION_GROUP,
OBS_GROUP_NORMAL, active_session_group);

if (!system_supported) {
obs_property_t *el = obs_properties_first(ps);
while (el != nullptr) {
obs_property_set_enabled(el, false);
obs_property_next(&el);
}
}

return ps;
}

Expand Down
4 changes: 3 additions & 1 deletion src/plugin.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
#include <obs-module.h>

#include "audio-capture-helper.hpp"
#include "common.hpp"
#include "plugin-macros.generated.hpp"

OBS_DECLARE_MODULE()
OBS_MODULE_USE_DEFAULT_LOCALE("win-capture-audio", "en-GB")

extern struct obs_source_info audio_capture_info;
extern bool system_supported;

bool obs_module_load(void)
{
blog(LOG_INFO, "[win-capture-audio] Version %s (%s)", PLUGIN_VERSION, GIT_HASH);
system_supported = AudioCaptureHelper::TestPluginAvailable();
obs_register_source(&audio_capture_info);
return true;
}
Expand Down