2023-02-28 01:15:26 +00:00
|
|
|
// AUTOGENERATED COPYRIGHT HEADER START
|
|
|
|
// Copyright (C) 2019-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
|
|
|
|
// AUTOGENERATED COPYRIGHT HEADER END
|
2019-01-27 21:43:49 +00:00
|
|
|
|
|
|
|
#pragma once
|
2020-04-02 15:02:01 +00:00
|
|
|
#include "common.hpp"
|
2023-02-16 04:33:33 +00:00
|
|
|
#include "obs/obs-weak-source.hpp"
|
2022-08-29 10:29:44 +00:00
|
|
|
|
|
|
|
#include "warning-disable.hpp"
|
2019-01-27 21:43:49 +00:00
|
|
|
#include <functional>
|
|
|
|
#include <map>
|
2020-07-26 16:38:49 +00:00
|
|
|
#include <mutex>
|
2022-08-29 10:29:44 +00:00
|
|
|
#include "warning-enable.hpp"
|
2019-01-27 21:43:49 +00:00
|
|
|
|
2021-06-08 02:36:30 +00:00
|
|
|
namespace streamfx::obs {
|
2019-01-27 21:43:49 +00:00
|
|
|
class source_tracker {
|
2023-02-16 04:33:33 +00:00
|
|
|
std::map<std::string, ::streamfx::obs::weak_source> _sources;
|
|
|
|
std::mutex _mutex;
|
2019-01-27 21:43:49 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
// Callback function for enumerating sources.
|
|
|
|
//
|
|
|
|
// @param std::string Name of the Source
|
|
|
|
// @param obs_source_t* Source
|
|
|
|
// @return true to abort enumeration, false to keep going.
|
2023-02-16 04:33:33 +00:00
|
|
|
typedef std::function<bool(std::string, ::streamfx::obs::source)> enumerate_cb_t;
|
2019-01-27 21:43:49 +00:00
|
|
|
|
|
|
|
// Filter function for enumerating sources.
|
|
|
|
//
|
|
|
|
// @param std::string Name of the Source
|
|
|
|
// @param obs_source_t* Source
|
|
|
|
// @return true to skip, false to pass along.
|
2023-02-16 04:33:33 +00:00
|
|
|
typedef std::function<bool(std::string, ::streamfx::obs::source)> filter_cb_t;
|
2019-01-27 21:43:49 +00:00
|
|
|
|
2022-05-10 20:52:35 +00:00
|
|
|
protected:
|
|
|
|
source_tracker();
|
|
|
|
|
|
|
|
public:
|
|
|
|
~source_tracker();
|
|
|
|
|
2019-01-27 21:43:49 +00:00
|
|
|
//! Enumerate all tracked sources
|
|
|
|
//
|
|
|
|
// @param enumerate_cb The function called for each tracked source.
|
|
|
|
// @param filter_cb Filter function to narrow down results.
|
|
|
|
void enumerate(enumerate_cb_t enumerate_cb, filter_cb_t filter_cb = nullptr);
|
|
|
|
|
2023-02-16 04:33:33 +00:00
|
|
|
protected:
|
|
|
|
void insert_source(obs_source_t* source);
|
|
|
|
void remove_source(obs_source_t* source);
|
|
|
|
void rename_source(std::string_view old_name, std::string_view new_name, obs_source_t* source);
|
|
|
|
|
2019-01-27 21:43:49 +00:00
|
|
|
public:
|
2023-02-16 04:33:33 +00:00
|
|
|
static bool filter_sources(std::string name, ::streamfx::obs::source source);
|
|
|
|
static bool filter_audio_sources(std::string name, ::streamfx::obs::source source);
|
|
|
|
static bool filter_video_sources(std::string name, ::streamfx::obs::source source);
|
|
|
|
static bool filter_transitions(std::string name, ::streamfx::obs::source source);
|
|
|
|
static bool filter_scenes(std::string name, ::streamfx::obs::source source);
|
|
|
|
|
|
|
|
private:
|
|
|
|
static void source_create_handler(void* ptr, calldata_t* data) noexcept;
|
|
|
|
static void source_destroy_handler(void* ptr, calldata_t* data) noexcept;
|
|
|
|
static void source_rename_handler(void* ptr, calldata_t* data) noexcept;
|
2022-05-10 20:52:35 +00:00
|
|
|
|
|
|
|
public: // Singleton
|
|
|
|
static std::shared_ptr<streamfx::obs::source_tracker> get();
|
2019-01-27 21:43:49 +00:00
|
|
|
};
|
2021-06-08 02:36:30 +00:00
|
|
|
} // namespace streamfx::obs
|