mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-27 13:53:01 +00:00
5a3954ae0e
Fixes several files incorrectly stated a different license from the actual project, as well as the copyright headers included in all files. This change has no effect on the licensing terms, it should clear up a bit of confusion by contributors. Plus the files get a bit smaller, and we have less duplicated information across the entire project. Overall the project is GPLv2 if not built with Qt, and GPLv3 if it is built with Qt. There are no parts licensed under a different license, all have been adapted from other compatible licenses into GPLv2 or GPLv3.
85 lines
2.4 KiB
C++
85 lines
2.4 KiB
C++
// AUTOGENERATED COPYRIGHT HEADER START
|
|
// Copyright (C) 2020-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
// Copyright (C) 2022 lainon <GermanAizek@yandex.ru>
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
|
|
|
#pragma once
|
|
#include "common.hpp"
|
|
#include "obs/obs-source.hpp"
|
|
#include "util/util-event.hpp"
|
|
|
|
namespace streamfx::obs {
|
|
template<typename T>
|
|
class signal_handler_base {
|
|
protected:
|
|
std::string _signal;
|
|
|
|
public:
|
|
streamfx::util::event<T, calldata*> event;
|
|
};
|
|
|
|
template<typename T>
|
|
class signal_handler : public signal_handler_base<T> {
|
|
public:
|
|
signal_handler(std::string_view signal, T keepalive) {}
|
|
virtual ~signal_handler() = default;
|
|
};
|
|
|
|
template<>
|
|
class signal_handler<std::shared_ptr<obs_source_t>> : public signal_handler_base<std::shared_ptr<obs_source_t>> {
|
|
std::shared_ptr<obs_source_t> _keepalive;
|
|
|
|
static void handle_signal(void* ptr, calldata* cd) noexcept
|
|
{
|
|
try {
|
|
auto p = reinterpret_cast<signal_handler<std::shared_ptr<obs_source_t>>*>(ptr);
|
|
p->event(p->_keepalive, cd);
|
|
} catch (...) {
|
|
}
|
|
}
|
|
|
|
public:
|
|
signal_handler(std::string_view signal, std::shared_ptr<obs_source_t> keepalive) : _keepalive(keepalive)
|
|
{
|
|
_signal = signal;
|
|
signal_handler_t* sh = obs_source_get_signal_handler(_keepalive.get());
|
|
signal_handler_connect(sh, _signal.c_str(), handle_signal, this);
|
|
}
|
|
virtual ~signal_handler()
|
|
{
|
|
event.clear();
|
|
signal_handler_t* sh = obs_source_get_signal_handler(_keepalive.get());
|
|
signal_handler_disconnect(sh, _signal.c_str(), handle_signal, this);
|
|
}
|
|
};
|
|
|
|
typedef signal_handler<std::shared_ptr<obs_source_t>> source_signal_handler;
|
|
|
|
// Audio Capture is also here, as it could be considered a signal.
|
|
class audio_signal_handler {
|
|
::streamfx::obs::source _keepalive;
|
|
|
|
static void handle_audio(void* ptr, obs_source_t*, const struct audio_data* audio_data, bool muted) noexcept
|
|
{
|
|
try {
|
|
auto p = reinterpret_cast<audio_signal_handler*>(ptr);
|
|
p->event(p->_keepalive, audio_data, muted);
|
|
} catch (...) {
|
|
}
|
|
}
|
|
|
|
public:
|
|
audio_signal_handler(::streamfx::obs::source const& keepalive) : _keepalive(keepalive), event()
|
|
{
|
|
obs_source_add_audio_capture_callback(_keepalive, handle_audio, this);
|
|
}
|
|
virtual ~audio_signal_handler()
|
|
{
|
|
event.clear();
|
|
obs_source_remove_audio_capture_callback(_keepalive, handle_audio, this);
|
|
}
|
|
|
|
streamfx::util::event<::streamfx::obs::source, const struct audio_data*, bool> event;
|
|
};
|
|
|
|
} // namespace streamfx::obs
|