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; }
133 SDL_CAMERA_POSITION_UNKNOWN;
136 SDL_CAMERA_POSITION_FRONT_FACING;
139 SDL_CAMERA_POSITION_BACK_FACING;
164 : m_resource(resource)
226 : m_resource(SDL_OpenCamera(instance_id, spec))
236 std::swap(m_resource, other.m_resource);
247 m_resource =
nullptr;
255 constexpr bool operator==(std::nullptr_t _)
const {
return !m_resource; }
258 constexpr explicit operator bool()
const {
return !!m_resource; }
498 return SDL_GetCameraDriver(index);
517 return SDL_GetCurrentCameraDriver();
535 auto data = SDL_GetCameras(&count);
574 auto data = SDL_GetCameraSupportedFormats(instance_id, &count);
593 return SDL_GetCameraName(instance_id);
615 return SDL_GetCameraPosition(instance_id);
665 return Camera(instance_id, spec);
701 return SDL_GetCameraPermissionState(camera);
742 return {
CheckError(SDL_GetCameraProperties(camera))};
773 if (
CameraSpec spec; SDL_GetCameraFormat(camera, &spec))
return spec;
823 Uint64* timestampNS =
nullptr)
861 SDL_ReleaseCameraFrame(camera, frame);
The opaque structure used to identify an opened SDL camera.
Definition: SDL3pp_camera.h:149
constexpr Camera()=default
Default ctor.
Camera & operator=(Camera other)
Assignment operator.
Definition: SDL3pp_camera.h:234
constexpr CameraRaw get() const
Retrieves underlying CameraRaw.
Definition: SDL3pp_camera.h:241
constexpr CameraRaw release()
Retrieves underlying CameraRaw and clear this.
Definition: SDL3pp_camera.h:244
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:172
constexpr Camera(const CameraRaw resource)
Constructs from CameraParam.
Definition: SDL3pp_camera.h:163
Camera(CameraID instance_id, OptionalRef< const CameraSpec > spec={})
Open a video recording device (a "camera").
Definition: SDL3pp_camera.h:225
~Camera()
Destructor.
Definition: SDL3pp_camera.h:231
constexpr bool operator==(std::nullptr_t _) const
Comparison.
Definition: SDL3pp_camera.h:255
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:201
static constexpr Surface Borrow(SurfaceParam resource)
Safely borrows the from SurfaceParam.
Definition: SDL3pp_surface.h:378
Surface AcquireCameraFrame(CameraParam camera, Uint64 *timestampNS=nullptr)
Acquire a frame.
Definition: SDL3pp_camera.h:822
constexpr CameraPosition CAMERA_POSITION_FRONT_FACING
CAMERA_POSITION_FRONT_FACING.
Definition: SDL3pp_camera.h:135
PropertiesRef GetCameraProperties(CameraParam camera)
Get the properties associated with an opened camera.
Definition: SDL3pp_camera.h:740
Surface AcquireFrame(Uint64 *timestampNS=nullptr)
Acquire a frame.
Definition: SDL3pp_camera.h:828
CameraID GetCameraID(CameraParam camera)
Get the instance ID of an opened camera.
Definition: SDL3pp_camera.h:722
void CloseCamera(CameraRaw camera)
Use this function to shut down camera processing and close the camera device.
Definition: SDL3pp_camera.h:881
int GetCameraPermissionState(CameraParam camera)
Query if camera access has been approved by the user.
Definition: SDL3pp_camera.h:699
constexpr CameraPosition CAMERA_POSITION_UNKNOWN
CAMERA_POSITION_UNKNOWN.
Definition: SDL3pp_camera.h:132
void Close()
Use this function to shut down camera processing and close the camera device.
Definition: SDL3pp_camera.h:883
constexpr CameraPosition CAMERA_POSITION_BACK_FACING
CAMERA_POSITION_BACK_FACING.
Definition: SDL3pp_camera.h:138
void ReleaseCameraFrame(CameraParam camera, SurfaceParam frame)
Release a frame of video acquired from a camera.
Definition: SDL3pp_camera.h:859
Camera OpenCamera(CameraID instance_id, OptionalRef< const CameraSpec > spec={})
Open a video recording device (a "camera").
Definition: SDL3pp_camera.h:662
int GetNumCameraDrivers()
Use this function to get the number of built-in camera drivers.
Definition: SDL3pp_camera.h:472
OwnArray< CameraID > GetCameras()
Get a list of currently connected camera devices.
Definition: SDL3pp_camera.h:532
SDL_CameraPosition CameraPosition
The position of camera in relation to system device.
Definition: SDL3pp_camera.h:130
SDL_CameraSpec CameraSpec
The details of an output format for a camera device.
Definition: SDL3pp_camera.h:121
OwnArray< CameraSpec * > GetCameraSupportedFormats(CameraID instance_id)
Get the list of native formats/sizes a camera supports.
Definition: SDL3pp_camera.h:571
SDL_Camera * CameraRaw
Alias to raw representation for Camera.
Definition: SDL3pp_camera.h:64
const char * GetCameraDriver(int index)
Use this function to get the name of a built in camera driver.
Definition: SDL3pp_camera.h:496
PropertiesRef GetProperties()
Get the properties associated with an opened camera.
Definition: SDL3pp_camera.h:745
const char * GetCameraName(CameraID instance_id)
Get the human-readable device name for a camera.
Definition: SDL3pp_camera.h:591
std::optional< CameraSpec > GetCameraFormat(CameraParam camera)
Get the spec that a camera is using when generating images.
Definition: SDL3pp_camera.h:771
int GetPermissionState()
Query if camera access has been approved by the user.
Definition: SDL3pp_camera.h:704
CameraID GetID()
Get the instance ID of an opened camera.
Definition: SDL3pp_camera.h:727
std::optional< CameraSpec > GetFormat()
Get the spec that a camera is using when generating images.
Definition: SDL3pp_camera.h:777
const char * GetCurrentCameraDriver()
Get the name of the current camera driver.
Definition: SDL3pp_camera.h:515
void ReleaseFrame(SurfaceParam frame)
Release a frame of video acquired from a camera.
Definition: SDL3pp_camera.h:864
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:108
CameraPosition GetCameraPosition(CameraID instance_id)
Get the position of the camera in relation to the system.
Definition: SDL3pp_camera.h:613
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(CameraRaw value)
Constructs from CameraRaw.
Definition: SDL3pp_camera.h:75
constexpr CameraParam(std::nullptr_t _=nullptr)
Constructs null/invalid.
Definition: SDL3pp_camera.h:81
CameraRaw value
parameter's CameraRaw
Definition: SDL3pp_camera.h:72
Semi-safe reference for Camera.
Definition: SDL3pp_camera.h:428
~CameraRef()
Destructor.
Definition: SDL3pp_camera.h:448
CameraRef(const CameraRef &other)
Copy constructor.
Definition: SDL3pp_camera.h:442
CameraRef(CameraParam resource)
Constructs from CameraParam.
Definition: SDL3pp_camera.h:436
Semi-safe reference for Properties.
Definition: SDL3pp_properties.h:701
Safely wrap Surface for non owning parameters.
Definition: SDL3pp_surface.h:46