1#ifndef SDL3PP_CAMERA_H_
2#define SDL3PP_CAMERA_H_
4#include <SDL3/SDL_camera.h>
5#include "SDL3pp_error.h"
6#include "SDL3pp_pixels.h"
7#include "SDL3pp_properties.h"
8#include "SDL3pp_stdinc.h"
9#include "SDL3pp_surface.h"
87 constexpr explicit operator bool()
const {
return !!
value; }
136 SDL_CAMERA_POSITION_UNKNOWN;
139 SDL_CAMERA_POSITION_FRONT_FACING;
142 SDL_CAMERA_POSITION_BACK_FACING;
144#if SDL_VERSION_ATLEAST(3, 4, 0)
156 SDL_CAMERA_PERMISSION_STATE_DENIED;
159 SDL_CAMERA_PERMISSION_STATE_PENDING;
162 SDL_CAMERA_PERMISSION_STATE_APPROVED;
189 constexpr Camera(std::nullptr_t =
nullptr) noexcept
202 : m_resource(resource)
266 : m_resource(SDL_OpenCamera(instance_id, spec))
276 std::swap(m_resource, other.m_resource);
292 m_resource =
nullptr;
300 constexpr explicit operator bool() const noexcept {
return !!m_resource; }
303 constexpr operator CameraParam() const noexcept {
return {m_resource}; }
561 , m_lock(other.m_lock)
596 std::swap(m_lock, other.m_lock);
601 constexpr operator bool()
const
603 return bool(m_lock) && Surface::operator bool();
689 return SDL_GetCameraDriver(index);
708 return SDL_GetCurrentCameraDriver();
726 auto data = SDL_GetCameras(&count);
765 auto data = SDL_GetCameraSupportedFormats(instance_id, &count);
784 return SDL_GetCameraName(instance_id);
806 return SDL_GetCameraPosition(instance_id);
856 return Camera(instance_id, spec);
893 return SDL_GetCameraPermissionState(camera);
934 return {
CheckError(SDL_GetCameraProperties(camera))};
965 if (
CameraSpec spec; SDL_GetCameraFormat(camera, &spec))
return spec;
1015 Uint64* timestampNS =
nullptr)
1027 , m_lock(std::move(resource))
1060 SDL_ReleaseCameraFrame(camera, frame);
1071 if (!m_lock)
return;
Camera Frame.
Definition: SDL3pp_camera.h:508
CameraFrame & operator=(CameraFrame &&other) noexcept
Assignment operator.
Definition: SDL3pp_camera.h:594
void release()
Releases the lock without unlocking.
Definition: SDL3pp_camera.h:635
CameraFrame(const CameraFrame &other)=delete
Copy constructor.
CameraRef get()
Get the reference to locked resource.
Definition: SDL3pp_camera.h:632
~CameraFrame()
Release a frame of video acquired from a camera.
Definition: SDL3pp_camera.h:589
constexpr CameraFrame(CameraFrame &&other) noexcept
Move constructor.
Definition: SDL3pp_camera.h:559
The opaque structure used to identify an opened SDL camera.
Definition: SDL3pp_camera.h:184
constexpr Camera(const Camera &other) noexcept=default
Copy constructor.
constexpr Camera & operator=(const Camera &other) noexcept=default
Assignment operator.
constexpr auto operator<=>(const Camera &other) const noexcept=default
Comparison.
constexpr CameraRaw get() const noexcept
Retrieves underlying CameraRaw.
Definition: SDL3pp_camera.h:286
constexpr CameraRaw release() noexcept
Retrieves underlying CameraRaw and clear this.
Definition: SDL3pp_camera.h:289
constexpr Camera(const CameraRaw resource) noexcept
Constructs from CameraParam.
Definition: SDL3pp_camera.h:201
Camera(CameraID instance_id, OptionalRef< const CameraSpec > spec={})
Open a video recording device (a "camera").
Definition: SDL3pp_camera.h:265
constexpr Camera(Camera &&other) noexcept
Move constructor.
Definition: SDL3pp_camera.h:212
constexpr Camera & operator=(Camera &&other) noexcept
Assignment operator.
Definition: SDL3pp_camera.h:274
~Camera()
Destructor.
Definition: SDL3pp_camera.h:271
constexpr Camera(std::nullptr_t=nullptr) noexcept
Default ctor.
Definition: SDL3pp_camera.h:189
Optional-like shim for references.
Definition: SDL3pp_optionalRef.h:20
Base class for SDL memory allocated array wrap.
Definition: SDL3pp_ownPtr.h:44
A collection of pixels used in software blitting.
Definition: SDL3pp_surface.h:227
constexpr SurfaceRaw release() noexcept
Retrieves underlying SurfaceRaw and clear this.
Definition: SDL3pp_surface.h:536
static constexpr Surface Borrow(SurfaceParam resource)
Safely borrows the from SurfaceParam.
Definition: SDL3pp_surface.h:411
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition: SDL3pp_assert.h:383
Surface AcquireCameraFrame(CameraParam camera, Uint64 *timestampNS=nullptr)
Acquire a frame.
Definition: SDL3pp_camera.h:1014
CameraPermissionState GetPermissionState()
Query if camera access has been approved by the user.
Definition: SDL3pp_camera.h:896
CameraFrame AcquireFrame(Uint64 *timestampNS=nullptr)
Acquire a frame.
Definition: SDL3pp_camera.h:1020
constexpr CameraPosition CAMERA_POSITION_FRONT_FACING
CAMERA_POSITION_FRONT_FACING.
Definition: SDL3pp_camera.h:138
constexpr CameraPermissionState CAMERA_PERMISSION_STATE_APPROVED
CAMERA_PERMISSION_STATE_APPROVED.
Definition: SDL3pp_camera.h:161
SDL_CameraPermissionState CameraPermissionState
The current state of a request for camera access.
Definition: SDL3pp_camera.h:153
constexpr CameraPermissionState CAMERA_PERMISSION_STATE_PENDING
CAMERA_PERMISSION_STATE_PENDING.
Definition: SDL3pp_camera.h:158
PropertiesRef GetCameraProperties(CameraParam camera)
Get the properties associated with an opened camera.
Definition: SDL3pp_camera.h:932
CameraID GetCameraID(CameraParam camera)
Get the instance ID of an opened camera.
Definition: SDL3pp_camera.h:914
void CloseCamera(CameraRaw camera)
Use this function to shut down camera processing and close the camera device.
Definition: SDL3pp_camera.h:1088
CameraPermissionState GetCameraPermissionState(CameraParam camera)
Query if camera access has been approved by the user.
Definition: SDL3pp_camera.h:891
constexpr CameraPosition CAMERA_POSITION_UNKNOWN
CAMERA_POSITION_UNKNOWN.
Definition: SDL3pp_camera.h:135
void Close()
Use this function to shut down camera processing and close the camera device.
Definition: SDL3pp_camera.h:1090
constexpr CameraPosition CAMERA_POSITION_BACK_FACING
CAMERA_POSITION_BACK_FACING.
Definition: SDL3pp_camera.h:141
void ReleaseFrame(CameraFrame &&lock)
Release a frame of video acquired from a camera.
Definition: SDL3pp_camera.h:1063
void ReleaseCameraFrame(CameraParam camera, SurfaceParam frame)
Release a frame of video acquired from a camera.
Definition: SDL3pp_camera.h:1058
Camera OpenCamera(CameraID instance_id, OptionalRef< const CameraSpec > spec={})
Open a video recording device (a "camera").
Definition: SDL3pp_camera.h:853
int GetNumCameraDrivers()
Use this function to get the number of built-in camera drivers.
Definition: SDL3pp_camera.h:663
constexpr CameraPermissionState CAMERA_PERMISSION_STATE_DENIED
CAMERA_PERMISSION_STATE_DENIED.
Definition: SDL3pp_camera.h:155
OwnArray< CameraID > GetCameras()
Get a list of currently connected camera devices.
Definition: SDL3pp_camera.h:723
SDL_CameraPosition CameraPosition
The position of camera in relation to system device.
Definition: SDL3pp_camera.h:133
SDL_CameraSpec CameraSpec
The details of an output format for a camera device.
Definition: SDL3pp_camera.h:124
OwnArray< CameraSpec * > GetCameraSupportedFormats(CameraID instance_id)
Get the list of native formats/sizes a camera supports.
Definition: SDL3pp_camera.h:762
SDL_Camera * CameraRaw
Alias to raw representation for Camera.
Definition: SDL3pp_camera.h:64
CameraFrame(CameraRef resource, Uint64 *timestampNS=nullptr)
Acquire a frame.
Definition: SDL3pp_camera.h:1025
const char * GetCameraDriver(int index)
Use this function to get the name of a built in camera driver.
Definition: SDL3pp_camera.h:687
PropertiesRef GetProperties()
Get the properties associated with an opened camera.
Definition: SDL3pp_camera.h:937
const char * GetCameraName(CameraID instance_id)
Get the human-readable device name for a camera.
Definition: SDL3pp_camera.h:782
std::optional< CameraSpec > GetCameraFormat(CameraParam camera)
Get the spec that a camera is using when generating images.
Definition: SDL3pp_camera.h:963
void reset()
Release a frame of video acquired from a camera.
Definition: SDL3pp_camera.h:1069
CameraID GetID()
Get the instance ID of an opened camera.
Definition: SDL3pp_camera.h:919
std::optional< CameraSpec > GetFormat()
Get the spec that a camera is using when generating images.
Definition: SDL3pp_camera.h:969
const char * GetCurrentCameraDriver()
Get the name of the current camera driver.
Definition: SDL3pp_camera.h:706
SDL_CameraID CameraID
This is a unique ID for a camera device for the time it is connected to the system,...
Definition: SDL3pp_camera.h:111
CameraPosition GetCameraPosition(CameraID instance_id)
Get the position of the camera in relation to the system.
Definition: SDL3pp_camera.h:804
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:197
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition: SDL3pp_stdinc.h:371
Main include header for the SDL3pp library.
Safely wrap Camera for non owning parameters.
Definition: SDL3pp_camera.h:71
constexpr auto operator<=>(const CameraParam &other) const =default
Comparison.
constexpr CameraParam(std::nullptr_t=nullptr)
Constructs null/invalid.
Definition: SDL3pp_camera.h:81
constexpr CameraParam(CameraRaw value)
Constructs from CameraRaw.
Definition: SDL3pp_camera.h:75
CameraRaw value
parameter's CameraRaw
Definition: SDL3pp_camera.h:72
Semi-safe reference for Camera.
Definition: SDL3pp_camera.h:472
~CameraRef()
Destructor.
Definition: SDL3pp_camera.h:503
constexpr CameraRef(const CameraRef &other) noexcept=default
Copy constructor.
CameraRef(CameraRaw resource) noexcept
Constructs from CameraParam.
Definition: SDL3pp_camera.h:494
CameraRef(CameraParam resource) noexcept
Constructs from CameraParam.
Definition: SDL3pp_camera.h:482
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:716
Safely wrap Surface for non owning parameters.
Definition: SDL3pp_surface.h:53