obs-StreamFX/source/obs/obs-source-tracker.hpp
Michael Fabian 'Xaymar' Dirks 5a3954ae0e project: Fix License, License headers and Copyright information
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.
2023-04-05 18:59:08 +02:00

67 lines
2.3 KiB
C++

// AUTOGENERATED COPYRIGHT HEADER START
// Copyright (C) 2019-2023 Michael Fabian 'Xaymar' Dirks <info@xaymar.com>
// AUTOGENERATED COPYRIGHT HEADER END
#pragma once
#include "common.hpp"
#include "obs/obs-weak-source.hpp"
#include "warning-disable.hpp"
#include <functional>
#include <map>
#include <mutex>
#include "warning-enable.hpp"
namespace streamfx::obs {
class source_tracker {
std::map<std::string, ::streamfx::obs::weak_source> _sources;
std::mutex _mutex;
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.
typedef std::function<bool(std::string, ::streamfx::obs::source)> enumerate_cb_t;
// 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.
typedef std::function<bool(std::string, ::streamfx::obs::source)> filter_cb_t;
protected:
source_tracker();
public:
~source_tracker();
//! 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);
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);
public:
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;
public: // Singleton
static std::shared_ptr<streamfx::obs::source_tracker> get();
};
} // namespace streamfx::obs