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"
113 SDL_CAMERA_POSITION_UNKNOWN;
116 SDL_CAMERA_POSITION_FRONT_FACING;
119 SDL_CAMERA_POSITION_BACK_FACING;
121#if SDL_VERSION_ATLEAST(3, 4, 0)
133 SDL_CAMERA_PERMISSION_STATE_DENIED;
136 SDL_CAMERA_PERMISSION_STATE_PENDING;
139 SDL_CAMERA_PERMISSION_STATE_APPROVED;
468 , m_lock(std::move(other.m_lock))
502 std::swap(m_lock, other.m_lock);
582 return SDL_GetCameraDriver(index);
601 return SDL_GetCurrentCameraDriver();
619 auto data = SDL_GetCameras(&count);
658 auto data = SDL_GetCameraSupportedFormats(instance_id, &count);
677 return SDL_GetCameraName(instance_id);
699 return SDL_GetCameraPosition(instance_id);
749 return Camera(instance_id, spec);
753 :
Camera(SDL_OpenCamera(instance_id, spec))
791 return SDL_GetCameraPermissionState(camera);
832 return {
CheckError(SDL_GetCameraProperties(camera))};
863 if (
CameraSpec spec; SDL_GetCameraFormat(camera, &spec))
return spec;
913 Uint64* timestampNS =
nullptr)
927 if (!*
this) m_lock.release();
958 SDL_ReleaseCameraFrame(camera, frame);
964 std::move(lock).reset();
Camera Frame.
Definition SDL3pp_camera.h:415
CameraFrame & operator=(CameraFrame &&other) noexcept
Assignment operator.
Definition SDL3pp_camera.h:500
CameraFrame(CameraFrame &&other) noexcept
Move constructor.
Definition SDL3pp_camera.h:466
CameraFrame(const CameraFrame &other)=delete
Copy constructor.
CameraRef resource() const
Get the reference to locked resource.
Definition SDL3pp_camera.h:532
~CameraFrame()
Release a frame of video acquired from a camera.
Definition SDL3pp_camera.h:495
Optional-like shim for references.
Definition SDL3pp_optionalRef.h:20
Base class for SDL memory allocated array wrap.
Definition SDL3pp_ownPtr.h:44
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:53
constexpr RawPointer release() noexcept
Definition SDL3pp_resource.h:56
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
#define SDL_assert_paranoid(condition)
An assertion test that is performed only when built with paranoid settings.
Definition SDL3pp_assert.h:383
void ReleaseCameraFrame(CameraRef camera, SurfaceRef frame)
Release a frame of video acquired from a camera.
Definition SDL3pp_camera.h:956
CameraPermissionState GetPermissionState()
Query if camera access has been approved by the user.
Definition SDL3pp_camera.h:794
std::optional< CameraSpec > GetCameraFormat(CameraRef camera)
Get the spec that a camera is using when generating images.
Definition SDL3pp_camera.h:861
CameraFrame AcquireFrame(Uint64 *timestampNS=nullptr)
Acquire a frame.
Definition SDL3pp_camera.h:918
constexpr CameraPosition CAMERA_POSITION_FRONT_FACING
CAMERA_POSITION_FRONT_FACING.
Definition SDL3pp_camera.h:115
constexpr CameraPermissionState CAMERA_PERMISSION_STATE_APPROVED
CAMERA_PERMISSION_STATE_APPROVED.
Definition SDL3pp_camera.h:138
Surface AcquireCameraFrame(CameraRef camera, Uint64 *timestampNS=nullptr)
Acquire a frame.
Definition SDL3pp_camera.h:912
constexpr CameraPermissionState CAMERA_PERMISSION_STATE_PENDING
CAMERA_PERMISSION_STATE_PENDING.
Definition SDL3pp_camera.h:135
SDL_Camera * CameraRaw
Alias to raw representation for Camera.
Definition SDL3pp_camera.h:64
void CloseCamera(CameraRaw camera)
Use this function to shut down camera processing and close the camera device.
Definition SDL3pp_camera.h:986
PropertiesRef GetCameraProperties(CameraRef camera)
Get the properties associated with an opened camera.
Definition SDL3pp_camera.h:830
constexpr CameraPosition CAMERA_POSITION_UNKNOWN
CAMERA_POSITION_UNKNOWN.
Definition SDL3pp_camera.h:112
void Close()
Use this function to shut down camera processing and close the camera device.
Definition SDL3pp_camera.h:988
constexpr CameraPosition CAMERA_POSITION_BACK_FACING
CAMERA_POSITION_BACK_FACING.
Definition SDL3pp_camera.h:118
void ReleaseFrame(CameraFrame &&lock)
Release a frame of video acquired from a camera.
Definition SDL3pp_camera.h:961
CameraPermissionState GetCameraPermissionState(CameraRef camera)
Query if camera access has been approved by the user.
Definition SDL3pp_camera.h:789
Camera OpenCamera(CameraID instance_id, OptionalRef< const CameraSpec > spec={})
Open a video recording device (a "camera").
Definition SDL3pp_camera.h:746
int GetNumCameraDrivers()
Use this function to get the number of built-in camera drivers.
Definition SDL3pp_camera.h:556
constexpr CameraPermissionState CAMERA_PERMISSION_STATE_DENIED
CAMERA_PERMISSION_STATE_DENIED.
Definition SDL3pp_camera.h:132
OwnArray< CameraID > GetCameras()
Get a list of currently connected camera devices.
Definition SDL3pp_camera.h:616
SDL_CameraPosition CameraPosition
The position of camera in relation to system device.
Definition SDL3pp_camera.h:110
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:88
OwnArray< CameraSpec * > GetCameraSupportedFormats(CameraID instance_id)
Get the list of native formats/sizes a camera supports.
Definition SDL3pp_camera.h:655
ResourceRef< Camera > CameraRef
Reference for Camera.
Definition SDL3pp_camera.h:71
CameraID GetCameraID(CameraRef camera)
Get the instance ID of an opened camera.
Definition SDL3pp_camera.h:812
CameraFrame(CameraRef resource, Uint64 *timestampNS=nullptr)
Acquire a frame.
Definition SDL3pp_camera.h:923
const char * GetCameraDriver(int index)
Use this function to get the name of a built in camera driver.
Definition SDL3pp_camera.h:580
PropertiesRef GetProperties()
Get the properties associated with an opened camera.
Definition SDL3pp_camera.h:835
const char * GetCameraName(CameraID instance_id)
Get the human-readable device name for a camera.
Definition SDL3pp_camera.h:675
void reset()
Release a frame of video acquired from a camera.
Definition SDL3pp_camera.h:967
CameraID GetID()
Get the instance ID of an opened camera.
Definition SDL3pp_camera.h:817
std::optional< CameraSpec > GetFormat()
Get the spec that a camera is using when generating images.
Definition SDL3pp_camera.h:867
SDL_CameraPermissionState CameraPermissionState
The current state of a request for camera access.
Definition SDL3pp_camera.h:130
const char * GetCurrentCameraDriver()
Get the name of the current camera driver.
Definition SDL3pp_camera.h:599
CameraPosition GetCameraPosition(CameraID instance_id)
Get the position of the camera in relation to the system.
Definition SDL3pp_camera.h:697
SDL_CameraSpec CameraSpec
The details of an output format for a camera device.
Definition SDL3pp_camera.h:101
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
ResourceRef< Properties > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:54
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition SDL3pp_stdinc.h:320
ResourceRef< Surface > SurfaceRef
Reference for Surface.
Definition SDL3pp_surface.h:54
Main include header for the SDL3pp library.
The opaque structure used to identify an opened SDL camera.
Definition SDL3pp_camera.h:161
constexpr Camera(const Camera &other)=delete
Copy constructor.
constexpr ResourceBase(RawPointer resource)
Constructs from resource pointer.
Definition SDL3pp_resource.h:29
constexpr Camera(CameraRaw resource) noexcept
Constructs from raw Camera.
Definition SDL3pp_camera.h:171
constexpr Camera(Camera &&other) noexcept
Move constructor.
Definition SDL3pp_camera.h:180
constexpr Camera & operator=(Camera &&other) noexcept
Assignment operator.
Definition SDL3pp_camera.h:239
Camera & operator=(const Camera &other)=delete
Assignment operator.
~Camera()
Destructor.
Definition SDL3pp_camera.h:236
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:156
A collection of pixels used in software blitting.
Definition SDL3pp_surface.h:172
constexpr Surface(SurfaceRaw resource) noexcept
Constructs from raw Surface.
Definition SDL3pp_surface.h:182
static Surface Borrow(SurfaceRaw resource)
Safely borrows the from SurfaceRaw.
Definition SDL3pp_surface.h:340