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"
116 SDL_CAMERA_POSITION_UNKNOWN;
119 SDL_CAMERA_POSITION_FRONT_FACING;
122 SDL_CAMERA_POSITION_BACK_FACING;
124#if SDL_VERSION_ATLEAST(3, 4, 0)
136 SDL_CAMERA_PERMISSION_STATE_DENIED;
139 SDL_CAMERA_PERMISSION_STATE_PENDING;
142 SDL_CAMERA_PERMISSION_STATE_APPROVED;
339 using CameraBase::CameraBase;
471 , m_lock(std::move(other.m_lock))
505 std::swap(m_lock, other.m_lock);
585 return SDL_GetCameraDriver(index);
604 return SDL_GetCurrentCameraDriver();
622 auto data = SDL_GetCameras(&count);
661 auto data = SDL_GetCameraSupportedFormats(instance_id, &count);
680 return SDL_GetCameraName(instance_id);
702 return SDL_GetCameraPosition(instance_id);
752 return Camera(instance_id, spec);
756 :
Camera(SDL_OpenCamera(instance_id, spec))
794 return SDL_GetCameraPermissionState(camera);
835 return {
CheckError(SDL_GetCameraProperties(camera))};
866 if (
CameraSpec spec; SDL_GetCameraFormat(camera, &spec))
return spec;
916 Uint64* timestampNS =
nullptr)
930 if (!*
this) m_lock.release();
961 SDL_ReleaseCameraFrame(camera, frame);
967 std::move(lock).reset();
Camera Frame.
Definition SDL3pp_camera.h:418
CameraFrame & operator=(CameraFrame &&other) noexcept
Assignment operator.
Definition SDL3pp_camera.h:503
CameraFrame(CameraFrame &&other) noexcept
Move constructor.
Definition SDL3pp_camera.h:469
CameraFrame(const CameraFrame &other)=delete
Copy constructor.
CameraRef resource() const
Get the reference to locked resource.
Definition SDL3pp_camera.h:535
~CameraFrame()
Release a frame of video acquired from a camera.
Definition SDL3pp_camera.h:498
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 release() noexcept
Definition SDL3pp_resource.h:57
friend constexpr void swap(ResourceBaseT &lhs, ResourceBaseT &rhs) noexcept
Definition SDL3pp_resource.h:65
constexpr RawPointer get() const noexcept
Definition SDL3pp_resource.h:54
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
#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:959
CameraID GetID()
Get the instance ID of an opened camera.
Definition SDL3pp_camera.h:820
std::optional< CameraSpec > GetCameraFormat(CameraRef camera)
Get the spec that a camera is using when generating images.
Definition SDL3pp_camera.h:864
void ReleaseFrame(CameraFrame &&lock)
Release a frame of video acquired from a camera.
Definition SDL3pp_camera.h:964
constexpr CameraPosition CAMERA_POSITION_FRONT_FACING
CAMERA_POSITION_FRONT_FACING.
Definition SDL3pp_camera.h:118
constexpr CameraPermissionState CAMERA_PERMISSION_STATE_APPROVED
CAMERA_PERMISSION_STATE_APPROVED.
Definition SDL3pp_camera.h:141
Surface AcquireCameraFrame(CameraRef camera, Uint64 *timestampNS=nullptr)
Acquire a frame.
Definition SDL3pp_camera.h:915
constexpr CameraPermissionState CAMERA_PERMISSION_STATE_PENDING
CAMERA_PERMISSION_STATE_PENDING.
Definition SDL3pp_camera.h:138
SDL_Camera * CameraRaw
Alias to raw representation for Camera.
Definition SDL3pp_camera.h:67
void CloseCamera(CameraRaw camera)
Use this function to shut down camera processing and close the camera device.
Definition SDL3pp_camera.h:989
PropertiesRef GetCameraProperties(CameraRef camera)
Get the properties associated with an opened camera.
Definition SDL3pp_camera.h:833
constexpr CameraPosition CAMERA_POSITION_UNKNOWN
CAMERA_POSITION_UNKNOWN.
Definition SDL3pp_camera.h:115
ResourceRefT< CameraBase > CameraRef
Reference for Camera.
Definition SDL3pp_camera.h:74
constexpr CameraPosition CAMERA_POSITION_BACK_FACING
CAMERA_POSITION_BACK_FACING.
Definition SDL3pp_camera.h:121
CameraPermissionState GetCameraPermissionState(CameraRef camera)
Query if camera access has been approved by the user.
Definition SDL3pp_camera.h:792
Camera OpenCamera(CameraID instance_id, OptionalRef< const CameraSpec > spec={})
Open a video recording device (a "camera").
Definition SDL3pp_camera.h:749
int GetNumCameraDrivers()
Use this function to get the number of built-in camera drivers.
Definition SDL3pp_camera.h:559
constexpr CameraPermissionState CAMERA_PERMISSION_STATE_DENIED
CAMERA_PERMISSION_STATE_DENIED.
Definition SDL3pp_camera.h:135
OwnArray< CameraID > GetCameras()
Get a list of currently connected camera devices.
Definition SDL3pp_camera.h:619
SDL_CameraPosition CameraPosition
The position of camera in relation to system device.
Definition SDL3pp_camera.h:113
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:91
CameraPermissionState GetPermissionState()
Query if camera access has been approved by the user.
Definition SDL3pp_camera.h:797
PropertiesRef GetProperties()
Get the properties associated with an opened camera.
Definition SDL3pp_camera.h:838
OwnArray< CameraSpec * > GetCameraSupportedFormats(CameraID instance_id)
Get the list of native formats/sizes a camera supports.
Definition SDL3pp_camera.h:658
void Close()
Use this function to shut down camera processing and close the camera device.
Definition SDL3pp_camera.h:991
CameraFrame AcquireFrame(Uint64 *timestampNS=nullptr)
Acquire a frame.
Definition SDL3pp_camera.h:921
CameraID GetCameraID(CameraRef camera)
Get the instance ID of an opened camera.
Definition SDL3pp_camera.h:815
CameraFrame(CameraRef resource, Uint64 *timestampNS=nullptr)
Acquire a frame.
Definition SDL3pp_camera.h:926
const char * GetCameraDriver(int index)
Use this function to get the name of a built in camera driver.
Definition SDL3pp_camera.h:583
const char * GetCameraName(CameraID instance_id)
Get the human-readable device name for a camera.
Definition SDL3pp_camera.h:678
std::optional< CameraSpec > GetFormat()
Get the spec that a camera is using when generating images.
Definition SDL3pp_camera.h:870
void reset()
Release a frame of video acquired from a camera.
Definition SDL3pp_camera.h:970
SDL_CameraPermissionState CameraPermissionState
The current state of a request for camera access.
Definition SDL3pp_camera.h:133
const char * GetCurrentCameraDriver()
Get the name of the current camera driver.
Definition SDL3pp_camera.h:602
CameraPosition GetCameraPosition(CameraID instance_id)
Get the position of the camera in relation to the system.
Definition SDL3pp_camera.h:700
SDL_CameraSpec CameraSpec
The details of an output format for a camera device.
Definition SDL3pp_camera.h:104
constexpr void CheckError(bool result)
Check and throw if returned value from SDL is an error.
Definition SDL3pp_error.h:199
ResourceRefT< PropertiesBase > PropertiesRef
Reference for Properties.
Definition SDL3pp_properties.h:53
::Uint64 Uint64
An unsigned 64-bit integer type.
Definition SDL3pp_stdinc.h:326
ResourceRefT< SurfaceBase > SurfaceRef
Reference for Surface.
Definition SDL3pp_surface.h:57
Main include header for the SDL3pp library.
Base class to Camera.
Definition SDL3pp_camera.h:162
constexpr ResourceBaseT()=default
Default constructor, creates null/invalid resource.
The opaque structure used to identify an opened SDL camera.
Definition SDL3pp_camera.h:338
constexpr Camera(CameraRaw resource) noexcept
Constructs from raw Camera.
Definition SDL3pp_camera.h:348
constexpr Camera(Camera &&other) noexcept
Move constructor.
Definition SDL3pp_camera.h:354
constexpr Camera & operator=(Camera &&other) noexcept
Assignment operator.
Definition SDL3pp_camera.h:409
~Camera()
Destructor.
Definition SDL3pp_camera.h:406
A non-owning reference wrapper for a given resource.
Definition SDL3pp_resource.h:93
A collection of pixels used in software blitting.
Definition SDL3pp_surface.h:1677
static Surface borrow(SurfaceRaw resource)
Safely borrows the from SurfaceRaw.
Definition SDL3pp_surface.h:1844
constexpr Surface(SurfaceRaw resource) noexcept
Constructs from raw Surface.
Definition SDL3pp_surface.h:1687