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"
88 constexpr explicit operator bool()
const {
return !!
value; }
134 SDL_CAMERA_POSITION_UNKNOWN;
137 SDL_CAMERA_POSITION_FRONT_FACING;
140 SDL_CAMERA_POSITION_BACK_FACING;
165 : m_resource(resource)
228 : m_resource(SDL_OpenCamera(instance_id, spec))
238 std::swap(m_resource, other.m_resource);
249 m_resource =
nullptr;
257 constexpr bool operator==(std::nullptr_t _)
const {
return !m_resource; }
260 constexpr explicit operator bool()
const {
return !!m_resource; }
502 return SDL_GetCameraDriver(index);
521 return SDL_GetCurrentCameraDriver();
541 auto data = SDL_GetCameras(&count);
585 return SDL_GetCameraSupportedFormats(instance_id, count);
603 return SDL_GetCameraName(instance_id);
625 return SDL_GetCameraPosition(instance_id);
676 return Camera(instance_id, spec);
712 return SDL_GetCameraPermissionState(camera);
753 return {
CheckError(SDL_GetCameraProperties(camera))};
785 if (
CameraSpec spec; SDL_GetCameraFormat(camera, &spec))
return spec;
836 Uint64* timestampNS =
nullptr)
874 SDL_ReleaseCameraFrame(camera, frame);
The opaque structure used to identify an opened SDL camera.
Definition: SDL3pp_camera.h:150
constexpr Camera()=default
Default ctor.
Camera & operator=(Camera other)
Assignment operator.
Definition: SDL3pp_camera.h:236
constexpr CameraRaw get() const
Retrieves underlying CameraRaw.
Definition: SDL3pp_camera.h:243
constexpr CameraRaw release()
Retrieves underlying CameraRaw and clear this.
Definition: SDL3pp_camera.h:246
constexpr auto operator<=>(const Camera &other) const =default
Comparison.
constexpr Camera(const Camera &other)=delete
Copy constructor.
constexpr Camera(Camera &&other)
Move constructor.
Definition: SDL3pp_camera.h:173
constexpr Camera(const CameraRaw resource)
Constructs from CameraParam.
Definition: SDL3pp_camera.h:164
Camera(CameraID instance_id, OptionalRef< const CameraSpec > spec={})
Open a video recording device (a "camera").
Definition: SDL3pp_camera.h:227
~Camera()
Destructor.
Definition: SDL3pp_camera.h:233
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_camera.h:257
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:195
static constexpr Surface Borrow(SurfaceParam resource)
Safely borrows the from SurfaceParam.
Definition: SDL3pp_surface.h:374
Surface AcquireCameraFrame(CameraParam camera, Uint64 *timestampNS=nullptr)
Acquire a frame.
Definition: SDL3pp_camera.h:835
constexpr CameraPosition CAMERA_POSITION_FRONT_FACING
CAMERA_POSITION_FRONT_FACING.
Definition: SDL3pp_camera.h:136
PropertiesRef GetCameraProperties(CameraParam camera)
Get the properties associated with an opened camera.
Definition: SDL3pp_camera.h:751
Surface AcquireFrame(Uint64 *timestampNS=nullptr)
Acquire a frame.
Definition: SDL3pp_camera.h:841
CameraID GetCameraID(CameraParam camera)
Get the instance ID of an opened camera.
Definition: SDL3pp_camera.h:733
void CloseCamera(CameraRaw camera)
Use this function to shut down camera processing and close the camera device.
Definition: SDL3pp_camera.h:895
int GetCameraPermissionState(CameraParam camera)
Query if camera access has been approved by the user.
Definition: SDL3pp_camera.h:710
constexpr CameraPosition CAMERA_POSITION_UNKNOWN
CAMERA_POSITION_UNKNOWN.
Definition: SDL3pp_camera.h:133
void Close()
Use this function to shut down camera processing and close the camera device.
Definition: SDL3pp_camera.h:897
constexpr CameraPosition CAMERA_POSITION_BACK_FACING
CAMERA_POSITION_BACK_FACING.
Definition: SDL3pp_camera.h:139
void ReleaseCameraFrame(CameraParam camera, SurfaceParam frame)
Release a frame of video acquired from a camera.
Definition: SDL3pp_camera.h:872
Camera OpenCamera(CameraID instance_id, OptionalRef< const CameraSpec > spec={})
Open a video recording device (a "camera").
Definition: SDL3pp_camera.h:673
int GetNumCameraDrivers()
Use this function to get the number of built-in camera drivers.
Definition: SDL3pp_camera.h:476
OwnArray< CameraID > GetCameras()
Get a list of currently connected camera devices.
Definition: SDL3pp_camera.h:538
SDL_CameraPosition CameraPosition
The position of camera in relation to system device.
Definition: SDL3pp_camera.h:131
SDL_CameraSpec CameraSpec
The details of an output format for a camera device.
Definition: SDL3pp_camera.h:122
SDL_Camera * CameraRaw
Alias to raw representation for Camera.
Definition: SDL3pp_camera.h:65
SDL_CameraSpec ** GetCameraSupportedFormats(CameraID instance_id, int *count)
Get the list of native formats/sizes a camera supports.
Definition: SDL3pp_camera.h:582
const char * GetCameraDriver(int index)
Use this function to get the name of a built in camera driver.
Definition: SDL3pp_camera.h:500
PropertiesRef GetProperties()
Get the properties associated with an opened camera.
Definition: SDL3pp_camera.h:756
const char * GetCameraName(CameraID instance_id)
Get the human-readable device name for a camera.
Definition: SDL3pp_camera.h:601
std::optional< CameraSpec > GetCameraFormat(CameraParam camera)
Get the spec that a camera is using when generating images.
Definition: SDL3pp_camera.h:783
int GetPermissionState()
Query if camera access has been approved by the user.
Definition: SDL3pp_camera.h:715
CameraID GetID()
Get the instance ID of an opened camera.
Definition: SDL3pp_camera.h:738
std::optional< CameraSpec > GetFormat()
Get the spec that a camera is using when generating images.
Definition: SDL3pp_camera.h:789
const char * GetCurrentCameraDriver()
Get the name of the current camera driver.
Definition: SDL3pp_camera.h:519
void ReleaseFrame(SurfaceParam frame)
Release a frame of video acquired from a camera.
Definition: SDL3pp_camera.h:877
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:109
CameraPosition GetCameraPosition(CameraID instance_id)
Get the position of the camera in relation to the system.
Definition: SDL3pp_camera.h:623
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition: SDL3pp_error.h:198
Uint64 Uint64
An unsigned 64-bit integer type.
Definition: SDL3pp_stdinc.h:363
Main include header for the SDL3pp library.
Safely wrap Camera for non owning parameters.
Definition: SDL3pp_camera.h:72
constexpr auto operator<=>(const CameraParam &other) const =default
Comparison.
constexpr CameraParam(CameraRaw value)
Constructs from CameraRaw.
Definition: SDL3pp_camera.h:76
constexpr CameraParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_camera.h:82
CameraRaw value
parameter's CameraRaw
Definition: SDL3pp_camera.h:73
Semi-safe reference for Camera.
Definition: SDL3pp_camera.h:432
~CameraRef()
Destructor.
Definition: SDL3pp_camera.h:452
CameraRef(const CameraRef &other)
Copy constructor.
Definition: SDL3pp_camera.h:446
CameraRef(CameraParam resource)
Constructs from CameraParam.
Definition: SDL3pp_camera.h:440
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:569
Safely wrap Surface for non owning parameters.
Definition: SDL3pp_surface.h:46