/**************************************************************************/1/* camera_server.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/object/class_db.h"33#include "core/object/ref_counted.h"34#include "core/os/thread_safe.h"35#include "core/templates/rid.h"36#include "core/variant/variant.h"3738/**39The camera server is a singleton object that gives access to the various40camera feeds that can be used as the background for our environment.41**/4243class CameraFeed;44template <typename T>45class TypedArray;4647class CameraServer : public Object {48GDCLASS(CameraServer, Object);49_THREAD_SAFE_CLASS_5051public:52enum FeedImage {53FEED_RGBA_IMAGE = 0,54FEED_YCBCR_IMAGE = 0,55FEED_Y_IMAGE = 0,56FEED_CBCR_IMAGE = 1,57FEED_IMAGES = 258};5960typedef CameraServer *(*CreateFunc)();61static inline constexpr const char feeds_updated_signal_name[] = "camera_feeds_updated";6263private:64protected:65static CreateFunc create_func;6667bool monitoring_feeds = false;68Vector<Ref<CameraFeed>> feeds;6970static CameraServer *singleton;7172static void _bind_methods();7374template <typename T>75static CameraServer *_create_builtin() {76return memnew(T);77}7879public:80static CameraServer *get_singleton();8182template <typename T>83static void make_default() {84create_func = _create_builtin<T>;85}8687static CameraServer *create() {88CameraServer *server = create_func ? create_func() : memnew(CameraServer);89return server;90}9192virtual void set_monitoring_feeds(bool p_monitoring_feeds);93_FORCE_INLINE_ bool is_monitoring_feeds() const { return monitoring_feeds; }9495// Right now we identify our feed by it's ID when it's used in the background.96// May see if we can change this to purely relying on CameraFeed objects or by name.97int get_free_id();98int get_feed_index(int p_id);99Ref<CameraFeed> get_feed_by_id(int p_id);100101// Add and remove feeds.102void add_feed(const Ref<CameraFeed> &p_feed);103void remove_feed(const Ref<CameraFeed> &p_feed);104105// Get our feeds.106Ref<CameraFeed> get_feed(int p_index);107int get_feed_count();108TypedArray<CameraFeed> get_feeds();109110// Intended for use with custom CameraServer implementation.111RID feed_texture(int p_id, FeedImage p_texture);112113CameraServer();114~CameraServer();115};116117VARIANT_ENUM_CAST(CameraServer::FeedImage);118119120