camera_server.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ifndef CAMERA_SERVER_H
  31. #define CAMERA_SERVER_H
  32. #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"
  37. /**
  38. The camera server is a singleton object that gives access to the various
  39. camera feeds that can be used as the background for our environment.
  40. **/
  41. class CameraFeed;
  42. template <typename T>
  43. class TypedArray;
  44. class CameraServer : public Object {
  45. GDCLASS(CameraServer, Object);
  46. _THREAD_SAFE_CLASS_
  47. public:
  48. enum FeedImage {
  49. FEED_RGBA_IMAGE = 0,
  50. FEED_YCBCR_IMAGE = 0,
  51. FEED_Y_IMAGE = 0,
  52. FEED_CBCR_IMAGE = 1,
  53. FEED_IMAGES = 2
  54. };
  55. typedef CameraServer *(*CreateFunc)();
  56. private:
  57. protected:
  58. static CreateFunc create_func;
  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. // Right now we identify our feed by it's ID when it's used in the background.
  77. // May see if we can change this to purely relying on CameraFeed objects or by name.
  78. int get_free_id();
  79. int get_feed_index(int p_id);
  80. Ref<CameraFeed> get_feed_by_id(int p_id);
  81. // Add and remove feeds.
  82. void add_feed(const Ref<CameraFeed> &p_feed);
  83. void remove_feed(const Ref<CameraFeed> &p_feed);
  84. // Get our feeds.
  85. Ref<CameraFeed> get_feed(int p_index);
  86. int get_feed_count();
  87. TypedArray<CameraFeed> get_feeds();
  88. // Intended for use with custom CameraServer implementation.
  89. RID feed_texture(int p_id, FeedImage p_texture);
  90. CameraServer();
  91. ~CameraServer();
  92. };
  93. VARIANT_ENUM_CAST(CameraServer::FeedImage);
  94. #endif // CAMERA_SERVER_H