2017-12-14 07:06:09 +00:00
|
|
|
/*
|
|
|
|
* Modern effects for a modern Streamer
|
|
|
|
* Copyright (C) 2017 Michael Fabian Dirks
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-04-02 15:02:01 +00:00
|
|
|
#include "common.hpp"
|
2018-11-07 13:11:38 +00:00
|
|
|
#include <condition_variable>
|
|
|
|
#include <mutex>
|
2019-04-03 00:58:54 +00:00
|
|
|
#include <queue>
|
2018-11-07 13:11:38 +00:00
|
|
|
#include <thread>
|
|
|
|
#include <vector>
|
2019-02-11 02:54:16 +00:00
|
|
|
#include "gfx/gfx-source-texture.hpp"
|
|
|
|
#include "obs/gs/gs-rendertarget.hpp"
|
|
|
|
#include "obs/gs/gs-sampler.hpp"
|
2020-02-14 06:55:18 +00:00
|
|
|
#include "obs/obs-signal-handler.hpp"
|
2019-10-15 11:34:47 +00:00
|
|
|
#include "obs/obs-source-factory.hpp"
|
2019-02-11 02:54:16 +00:00
|
|
|
#include "obs/obs-source.hpp"
|
2020-02-14 06:55:18 +00:00
|
|
|
#include "obs/obs-tools.hpp"
|
2017-12-14 07:06:09 +00:00
|
|
|
|
2020-04-05 16:52:06 +00:00
|
|
|
namespace streamfx::source::mirror {
|
2020-01-13 21:40:15 +00:00
|
|
|
struct mirror_audio_data {
|
2020-03-03 01:17:26 +00:00
|
|
|
mirror_audio_data(const audio_data*, speaker_layout);
|
|
|
|
|
2020-08-10 01:29:05 +00:00
|
|
|
obs_source_audio osa;
|
|
|
|
std::vector<std::vector<uint8_t>> data;
|
2020-01-13 21:40:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class mirror_instance : public obs::source_instance {
|
2020-02-14 06:55:18 +00:00
|
|
|
// Source
|
|
|
|
std::shared_ptr<obs_source_t> _source;
|
|
|
|
std::shared_ptr<obs::tools::child_source> _source_child;
|
|
|
|
std::shared_ptr<obs::source_signal_handler> _signal_rename;
|
|
|
|
std::shared_ptr<obs::audio_signal_handler> _signal_audio;
|
2020-03-21 08:13:31 +00:00
|
|
|
std::pair<uint32_t, uint32_t> _source_size;
|
2020-01-13 21:40:15 +00:00
|
|
|
|
|
|
|
// Audio
|
2020-03-20 22:59:42 +00:00
|
|
|
bool _audio_enabled;
|
|
|
|
speaker_layout _audio_layout;
|
|
|
|
std::mutex _audio_queue_lock;
|
|
|
|
std::queue<mirror_audio_data> _audio_queue;
|
2020-01-13 21:40:15 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
mirror_instance(obs_data_t* settings, obs_source_t* self);
|
|
|
|
virtual ~mirror_instance();
|
|
|
|
|
2020-08-10 01:29:05 +00:00
|
|
|
virtual uint32_t get_width() override;
|
|
|
|
virtual uint32_t get_height() override;
|
2020-01-13 21:40:15 +00:00
|
|
|
|
|
|
|
virtual void load(obs_data_t*) override;
|
2020-08-10 01:29:05 +00:00
|
|
|
virtual void migrate(obs_data_t*, uint64_t) override;
|
2020-04-05 04:02:03 +00:00
|
|
|
virtual void update(obs_data_t*) override;
|
2020-01-13 21:40:15 +00:00
|
|
|
virtual void save(obs_data_t*) override;
|
|
|
|
|
2020-04-24 01:54:30 +00:00
|
|
|
virtual void video_tick(float_t) override;
|
2020-01-13 21:40:15 +00:00
|
|
|
virtual void video_render(gs_effect_t*) override;
|
|
|
|
|
|
|
|
virtual void enum_active_sources(obs_source_enum_proc_t, void*) override;
|
|
|
|
virtual void enum_all_sources(obs_source_enum_proc_t, void*) override;
|
|
|
|
|
2020-02-14 06:55:18 +00:00
|
|
|
private:
|
|
|
|
void acquire(std::string source_name);
|
|
|
|
void release();
|
|
|
|
|
|
|
|
void on_rename(std::shared_ptr<obs_source_t>, calldata*);
|
|
|
|
void on_audio(std::shared_ptr<obs_source_t>, const struct audio_data*, bool);
|
2020-03-03 01:17:26 +00:00
|
|
|
|
|
|
|
void audio_output(std::shared_ptr<void> data);
|
2020-01-13 21:40:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class mirror_factory : public obs::source_factory<source::mirror::mirror_factory, source::mirror::mirror_instance> {
|
|
|
|
public:
|
|
|
|
mirror_factory();
|
|
|
|
virtual ~mirror_factory() override;
|
|
|
|
|
|
|
|
virtual const char* get_name() override;
|
|
|
|
|
|
|
|
virtual void get_defaults2(obs_data_t* data) override;
|
|
|
|
|
|
|
|
virtual obs_properties_t* get_properties2(source::mirror::mirror_instance* data) override;
|
2020-04-05 16:52:06 +00:00
|
|
|
|
2021-04-16 23:43:30 +00:00
|
|
|
#ifdef ENABLE_FRONTEND
|
|
|
|
static bool on_manual_open(obs_properties_t* props, obs_property_t* property, void* data);
|
|
|
|
#endif
|
|
|
|
|
2020-04-05 16:52:06 +00:00
|
|
|
public: // Singleton
|
|
|
|
static void initialize();
|
|
|
|
|
|
|
|
static void finalize();
|
|
|
|
|
|
|
|
static std::shared_ptr<mirror_factory> get();
|
2020-01-13 21:40:15 +00:00
|
|
|
};
|
2020-04-05 16:52:06 +00:00
|
|
|
} // namespace streamfx::source::mirror
|