2023-02-28 01:15:26 +00:00
|
|
|
// 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
|
2020-02-14 06:30:46 +00:00
|
|
|
|
|
|
|
#pragma once
|
2020-04-02 15:02:01 +00:00
|
|
|
#include "common.hpp"
|
2022-05-28 18:01:12 +00:00
|
|
|
#include "obs/obs-source.hpp"
|
2020-07-12 16:41:50 +00:00
|
|
|
#include "util/util-event.hpp"
|
2020-02-14 06:30:46 +00:00
|
|
|
|
2021-06-08 02:36:30 +00:00
|
|
|
namespace streamfx::obs {
|
2020-02-14 06:30:46 +00:00
|
|
|
template<typename T>
|
|
|
|
class signal_handler_base {
|
|
|
|
protected:
|
|
|
|
std::string _signal;
|
|
|
|
|
|
|
|
public:
|
2021-06-08 02:18:02 +00:00
|
|
|
streamfx::util::event<T, calldata*> event;
|
2020-02-14 06:30:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
class signal_handler : public signal_handler_base<T> {
|
|
|
|
public:
|
2022-07-21 11:09:10 +00:00
|
|
|
signal_handler(std::string_view signal, T keepalive) {}
|
|
|
|
virtual ~signal_handler() = default;
|
2020-02-14 06:30:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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
|
2022-08-27 11:17:47 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
auto p = reinterpret_cast<signal_handler<std::shared_ptr<obs_source_t>>*>(ptr);
|
|
|
|
p->event(p->_keepalive, cd);
|
|
|
|
} catch (...) {
|
|
|
|
}
|
2020-02-14 06:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2022-07-21 11:09:10 +00:00
|
|
|
signal_handler(std::string_view signal, std::shared_ptr<obs_source_t> keepalive) : _keepalive(keepalive)
|
2020-02-14 06:30:46 +00:00
|
|
|
{
|
|
|
|
_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 {
|
2022-05-28 18:01:12 +00:00
|
|
|
::streamfx::obs::source _keepalive;
|
2020-02-14 06:30:46 +00:00
|
|
|
|
|
|
|
static void handle_audio(void* ptr, obs_source_t*, const struct audio_data* audio_data, bool muted) noexcept
|
2022-08-27 11:17:47 +00:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
auto p = reinterpret_cast<audio_signal_handler*>(ptr);
|
|
|
|
p->event(p->_keepalive, audio_data, muted);
|
|
|
|
} catch (...) {
|
|
|
|
}
|
2020-02-14 06:30:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2022-05-28 18:01:12 +00:00
|
|
|
audio_signal_handler(::streamfx::obs::source const& keepalive) : _keepalive(keepalive), event()
|
2020-02-14 06:30:46 +00:00
|
|
|
{
|
2022-05-28 18:01:12 +00:00
|
|
|
obs_source_add_audio_capture_callback(_keepalive, handle_audio, this);
|
2020-02-14 06:30:46 +00:00
|
|
|
}
|
|
|
|
virtual ~audio_signal_handler()
|
|
|
|
{
|
|
|
|
event.clear();
|
2022-05-28 18:01:12 +00:00
|
|
|
obs_source_remove_audio_capture_callback(_keepalive, handle_audio, this);
|
2020-02-14 06:30:46 +00:00
|
|
|
}
|
|
|
|
|
2022-05-28 18:01:12 +00:00
|
|
|
streamfx::util::event<::streamfx::obs::source, const struct audio_data*, bool> event;
|
2020-02-14 06:30:46 +00:00
|
|
|
};
|
|
|
|
|
2021-06-08 02:36:30 +00:00
|
|
|
} // namespace streamfx::obs
|