SDL_syscamera.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2024 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "../SDL_internal.h"
  19. #ifndef SDL_syscamera_h_
  20. #define SDL_syscamera_h_
  21. #include "../SDL_list.h"
  22. #define DEBUG_CAMERA 1
  23. // The SDL camera driver
  24. typedef struct SDL_CameraDevice SDL_CameraDevice;
  25. // Define the SDL camera driver structure
  26. struct SDL_CameraDevice
  27. {
  28. // The device's current camera specification
  29. SDL_CameraSpec spec;
  30. // Device name
  31. char *dev_name;
  32. // Current state flags
  33. SDL_AtomicInt shutdown;
  34. SDL_AtomicInt enabled;
  35. SDL_bool is_spec_set;
  36. // A mutex for locking the queue buffers
  37. SDL_Mutex *device_lock;
  38. SDL_Mutex *acquiring_lock;
  39. // A thread to feed the camera device
  40. SDL_Thread *thread;
  41. SDL_ThreadID threadid;
  42. // Queued buffers (if app not using callback).
  43. SDL_ListNode *buffer_queue;
  44. // Data private to this driver
  45. struct SDL_PrivateCameraData *hidden;
  46. };
  47. typedef struct SDL_CameraDriverImpl
  48. {
  49. void (*DetectDevices)(void);
  50. int (*OpenDevice)(SDL_CameraDevice *_this);
  51. void (*CloseDevice)(SDL_CameraDevice *_this);
  52. int (*InitDevice)(SDL_CameraDevice *_this);
  53. int (*GetDeviceSpec)(SDL_CameraDevice *_this, SDL_CameraSpec *spec);
  54. int (*StartCamera)(SDL_CameraDevice *_this);
  55. int (*StopCamera)(SDL_CameraDevice *_this);
  56. int (*AcquireFrame)(SDL_CameraDevice *_this, SDL_CameraFrame *frame);
  57. int (*ReleaseFrame)(SDL_CameraDevice *_this, SDL_CameraFrame *frame);
  58. int (*GetNumFormats)(SDL_CameraDevice *_this);
  59. int (*GetFormat)(SDL_CameraDevice *_this, int index, Uint32 *format);
  60. int (*GetNumFrameSizes)(SDL_CameraDevice *_this, Uint32 format);
  61. int (*GetFrameSize)(SDL_CameraDevice *_this, Uint32 format, int index, int *width, int *height);
  62. int (*GetDeviceName)(SDL_CameraDeviceID instance_id, char *buf, int size);
  63. SDL_CameraDeviceID *(*GetDevices)(int *count);
  64. void (*Deinitialize)(void);
  65. } SDL_CameraDriverImpl;
  66. typedef struct SDL_CameraDriver
  67. {
  68. const char *name; // The name of this camera driver
  69. const char *desc; // The description of this camera driver
  70. SDL_CameraDriverImpl impl; // the backend's interface
  71. } SDL_CameraDriver;
  72. typedef struct CameraBootStrap
  73. {
  74. const char *name;
  75. const char *desc;
  76. SDL_bool (*init)(SDL_CameraDriverImpl *impl);
  77. SDL_bool demand_only; // if SDL_TRUE: request explicitly, or it won't be available.
  78. } CameraBootStrap;
  79. // Not all of these are available in a given build. Use #ifdefs, etc.
  80. extern CameraBootStrap DUMMYCAMERA_bootstrap;
  81. extern CameraBootStrap V4L2_bootstrap;
  82. extern CameraBootStrap COREMEDIA_bootstrap;
  83. extern CameraBootStrap ANDROIDCAMERA_bootstrap;
  84. #endif // SDL_syscamera_h_