| 1 | /**************************************************************************/ | 
|---|
| 2 | /*  camera_server.h                                                       */ | 
|---|
| 3 | /**************************************************************************/ | 
|---|
| 4 | /*                         This file is part of:                          */ | 
|---|
| 5 | /*                             GODOT ENGINE                               */ | 
|---|
| 6 | /*                        https://godotengine.org                         */ | 
|---|
| 7 | /**************************************************************************/ | 
|---|
| 8 | /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ | 
|---|
| 9 | /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur.                  */ | 
|---|
| 10 | /*                                                                        */ | 
|---|
| 11 | /* Permission is hereby granted, free of charge, to any person obtaining  */ | 
|---|
| 12 | /* a copy of this software and associated documentation files (the        */ | 
|---|
| 13 | /* "Software"), to deal in the Software without restriction, including    */ | 
|---|
| 14 | /* without limitation the rights to use, copy, modify, merge, publish,    */ | 
|---|
| 15 | /* distribute, sublicense, and/or sell copies of the Software, and to     */ | 
|---|
| 16 | /* permit persons to whom the Software is furnished to do so, subject to  */ | 
|---|
| 17 | /* the following conditions:                                              */ | 
|---|
| 18 | /*                                                                        */ | 
|---|
| 19 | /* The above copyright notice and this permission notice shall be         */ | 
|---|
| 20 | /* included in all copies or substantial portions of the Software.        */ | 
|---|
| 21 | /*                                                                        */ | 
|---|
| 22 | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,        */ | 
|---|
| 23 | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF     */ | 
|---|
| 24 | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ | 
|---|
| 25 | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY   */ | 
|---|
| 26 | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,   */ | 
|---|
| 27 | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE      */ | 
|---|
| 28 | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                 */ | 
|---|
| 29 | /**************************************************************************/ | 
|---|
| 30 |  | 
|---|
| 31 | #ifndef CAMERA_SERVER_H | 
|---|
| 32 | #define CAMERA_SERVER_H | 
|---|
| 33 |  | 
|---|
| 34 | #include "core/object/class_db.h" | 
|---|
| 35 | #include "core/object/ref_counted.h" | 
|---|
| 36 | #include "core/os/thread_safe.h" | 
|---|
| 37 | #include "core/templates/rid.h" | 
|---|
| 38 | #include "core/variant/variant.h" | 
|---|
| 39 |  | 
|---|
| 40 | /** | 
|---|
| 41 | The camera server is a singleton object that gives access to the various | 
|---|
| 42 | camera feeds that can be used as the background for our environment. | 
|---|
| 43 | **/ | 
|---|
| 44 |  | 
|---|
| 45 | class CameraFeed; | 
|---|
| 46 | template <typename T> | 
|---|
| 47 | class TypedArray; | 
|---|
| 48 |  | 
|---|
| 49 | class CameraServer : public Object { | 
|---|
| 50 | GDCLASS(CameraServer, Object); | 
|---|
| 51 | _THREAD_SAFE_CLASS_ | 
|---|
| 52 |  | 
|---|
| 53 | public: | 
|---|
| 54 | enum FeedImage { | 
|---|
| 55 | FEED_RGBA_IMAGE = 0, | 
|---|
| 56 | FEED_YCBCR_IMAGE = 0, | 
|---|
| 57 | FEED_Y_IMAGE = 0, | 
|---|
| 58 | FEED_CBCR_IMAGE = 1, | 
|---|
| 59 | FEED_IMAGES = 2 | 
|---|
| 60 | }; | 
|---|
| 61 |  | 
|---|
| 62 | typedef CameraServer *(*CreateFunc)(); | 
|---|
| 63 |  | 
|---|
| 64 | private: | 
|---|
| 65 | protected: | 
|---|
| 66 | static CreateFunc create_func; | 
|---|
| 67 |  | 
|---|
| 68 | Vector<Ref<CameraFeed>> feeds; | 
|---|
| 69 |  | 
|---|
| 70 | static CameraServer *singleton; | 
|---|
| 71 |  | 
|---|
| 72 | static void _bind_methods(); | 
|---|
| 73 |  | 
|---|
| 74 | template <class T> | 
|---|
| 75 | static CameraServer *_create_builtin() { | 
|---|
| 76 | return memnew(T); | 
|---|
| 77 | } | 
|---|
| 78 |  | 
|---|
| 79 | public: | 
|---|
| 80 | static CameraServer *get_singleton(); | 
|---|
| 81 |  | 
|---|
| 82 | template <class T> | 
|---|
| 83 | static void make_default() { | 
|---|
| 84 | create_func = _create_builtin<T>; | 
|---|
| 85 | } | 
|---|
| 86 |  | 
|---|
| 87 | static CameraServer *create() { | 
|---|
| 88 | CameraServer *server = create_func ? create_func() : memnew(CameraServer); | 
|---|
| 89 | return server; | 
|---|
| 90 | }; | 
|---|
| 91 |  | 
|---|
| 92 | // Right now we identify our feed by it's ID when it's used in the background. | 
|---|
| 93 | // May see if we can change this to purely relying on CameraFeed objects or by name. | 
|---|
| 94 | int get_free_id(); | 
|---|
| 95 | int get_feed_index(int p_id); | 
|---|
| 96 | Ref<CameraFeed> get_feed_by_id(int p_id); | 
|---|
| 97 |  | 
|---|
| 98 | // Add and remove feeds. | 
|---|
| 99 | void add_feed(const Ref<CameraFeed> &p_feed); | 
|---|
| 100 | void remove_feed(const Ref<CameraFeed> &p_feed); | 
|---|
| 101 |  | 
|---|
| 102 | // Get our feeds. | 
|---|
| 103 | Ref<CameraFeed> get_feed(int p_index); | 
|---|
| 104 | int get_feed_count(); | 
|---|
| 105 | TypedArray<CameraFeed> get_feeds(); | 
|---|
| 106 |  | 
|---|
| 107 | // Intended for use with custom CameraServer implementation. | 
|---|
| 108 | RID feed_texture(int p_id, FeedImage p_texture); | 
|---|
| 109 |  | 
|---|
| 110 | CameraServer(); | 
|---|
| 111 | ~CameraServer(); | 
|---|
| 112 | }; | 
|---|
| 113 |  | 
|---|
| 114 | VARIANT_ENUM_CAST(CameraServer::FeedImage); | 
|---|
| 115 |  | 
|---|
| 116 | #endif // CAMERA_SERVER_H | 
|---|
| 117 |  | 
|---|