camera_server.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. #pragma once
  31. #include "core/object/class_db.h"
  32. #include "core/object/ref_counted.h"
  33. #include "core/os/thread_safe.h"
  34. #include "core/templates/rid.h"
  35. #include "core/variant/variant.h"
  36. /**
  37. The camera server is a singleton object that gives access to the various
  38. camera feeds that can be used as the background for our environment.
  39. **/
  40. class CameraFeed;
  41. template <typename T>
  42. class TypedArray;
  43. class CameraServer : public Object {
  44. GDCLASS(CameraServer, Object);
  45. _THREAD_SAFE_CLASS_
  46. public:
  47. enum FeedImage {
  48. FEED_RGBA_IMAGE = 0,
  49. FEED_YCBCR_IMAGE = 0,
  50. FEED_Y_IMAGE = 0,
  51. FEED_CBCR_IMAGE = 1,
  52. FEED_IMAGES = 2
  53. };
  54. typedef CameraServer *(*CreateFunc)();
  55. private:
  56. protected:
  57. static CreateFunc create_func;
  58. bool monitoring_feeds = false;
  59. Vector<Ref<CameraFeed>> feeds;
  60. static CameraServer *singleton;
  61. static void _bind_methods();
  62. template <typename T>
  63. static CameraServer *_create_builtin() {
  64. return memnew(T);
  65. }
  66. public:
  67. static CameraServer *get_singleton();
  68. template <typename T>
  69. static void make_default() {
  70. create_func = _create_builtin<T>;
  71. }
  72. static CameraServer *create() {
  73. CameraServer *server = create_func ? create_func() : memnew(CameraServer);
  74. return server;
  75. }
  76. virtual void set_monitoring_feeds(bool p_monitoring_feeds);
  77. _FORCE_INLINE_ bool is_monitoring_feeds() const { return monitoring_feeds; }
  78. // Right now we identify our feed by it's ID when it's used in the background.
  79. // May see if we can change this to purely relying on CameraFeed objects or by name.
  80. int get_free_id();
  81. int get_feed_index(int p_id);
  82. Ref<CameraFeed> get_feed_by_id(int p_id);
  83. // Add and remove feeds.
  84. void add_feed(const Ref<CameraFeed> &p_feed);
  85. void remove_feed(const Ref<CameraFeed> &p_feed);
  86. // Get our feeds.
  87. Ref<CameraFeed> get_feed(int p_index);
  88. int get_feed_count();
  89. TypedArray<CameraFeed> get_feeds();
  90. // Intended for use with custom CameraServer implementation.
  91. RID feed_texture(int p_id, FeedImage p_texture);
  92. CameraServer();
  93. ~CameraServer();
  94. };
  95. VARIANT_ENUM_CAST(CameraServer::FeedImage);