sdl3_sys/generated/
camera.rs

1//! Video capture for the SDL library.
2//!
3//! This API lets apps read input from video sources, like webcams. Camera
4//! devices can be enumerated, queried, and opened. Once opened, it will
5//! provide [`SDL_Surface`] objects as new frames of video come in. These surfaces
6//! can be uploaded to an [`SDL_Texture`] or processed as pixels in memory.
7//!
8//! Several platforms will alert the user if an app tries to access a camera,
9//! and some will present a UI asking the user if your application should be
10//! allowed to obtain images at all, which they can deny. A successfully opened
11//! camera will not provide images until permission is granted. Applications,
12//! after opening a camera device, can see if they were granted access by
13//! either polling with the [`SDL_GetCameraPermissionState()`] function, or waiting
14//! for an [`SDL_EVENT_CAMERA_DEVICE_APPROVED`] or [`SDL_EVENT_CAMERA_DEVICE_DENIED`]
15//! event. Platforms that don't have any user approval process will report
16//! approval immediately.
17//!
18//! Note that SDL cameras only provide video as individual frames; they will
19//! not provide full-motion video encoded in a movie file format, although an
20//! app is free to encode the acquired frames into any format it likes. It also
21//! does not provide audio from the camera hardware through this API; not only
22//! do many webcams not have microphones at all, many people--from streamers to
23//! people on Zoom calls--will want to use a separate microphone regardless of
24//! the camera. In any case, recorded audio will be available through SDL's
25//! audio API no matter what hardware provides the microphone.
26//!
27//! ## Camera gotchas
28//!
29//! Consumer-level camera hardware tends to take a little while to warm up,
30//! once the device has been opened. Generally most camera apps have some sort
31//! of UI to take a picture (a button to snap a pic while a preview is showing,
32//! some sort of multi-second countdown for the user to pose, like a photo
33//! booth), which puts control in the users' hands, or they are intended to
34//! stay on for long times (Pokemon Go, etc).
35//!
36//! It's not uncommon that a newly-opened camera will provide a couple of
37//! completely black frames, maybe followed by some under-exposed images. If
38//! taking a single frame automatically, or recording video from a camera's
39//! input without the user initiating it from a preview, it could be wise to
40//! drop the first several frames (if not the first several _seconds_ worth of
41//! frames!) before using images from a camera.
42
43use super::stdinc::*;
44
45use super::error::*;
46
47use super::pixels::*;
48
49use super::properties::*;
50
51use super::surface::*;
52
53/// This is a unique ID for a camera device for the time it is connected to the
54/// system, and is never reused for the lifetime of the application.
55///
56/// If the device is disconnected and reconnected, it will get a new ID.
57///
58/// The value 0 is an invalid ID.
59///
60/// ## Availability
61/// This datatype is available since SDL 3.2.0.
62///
63/// ## See also
64/// - [`SDL_GetCameras`]
65#[repr(transparent)]
66#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
67#[cfg_attr(feature = "debug-impls", derive(Debug))]
68pub struct SDL_CameraID(pub Uint32);
69
70impl ::core::cmp::PartialEq<Uint32> for SDL_CameraID {
71    #[inline(always)]
72    fn eq(&self, other: &Uint32) -> bool {
73        &self.0 == other
74    }
75}
76
77impl ::core::cmp::PartialEq<SDL_CameraID> for Uint32 {
78    #[inline(always)]
79    fn eq(&self, other: &SDL_CameraID) -> bool {
80        self == &other.0
81    }
82}
83
84impl From<SDL_CameraID> for Uint32 {
85    #[inline(always)]
86    fn from(value: SDL_CameraID) -> Self {
87        value.0
88    }
89}
90
91#[cfg(feature = "metadata")]
92impl sdl3_sys::metadata::GroupMetadata for SDL_CameraID {
93    const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
94        &crate::metadata::camera::METADATA_SDL_CameraID;
95}
96
97/// The details of an output format for a camera device.
98///
99/// Cameras often support multiple formats; each one will be encapsulated in
100/// this struct.
101///
102/// ## Availability
103/// This struct is available since SDL 3.2.0.
104///
105/// ## See also
106/// - [`SDL_GetCameraSupportedFormats`]
107/// - [`SDL_GetCameraFormat`]
108#[repr(C)]
109#[derive(Clone, Copy, Default, PartialEq, Eq, Hash)]
110#[cfg_attr(feature = "debug-impls", derive(Debug))]
111pub struct SDL_CameraSpec {
112    /// Frame format
113    pub format: SDL_PixelFormat,
114    /// Frame colorspace
115    pub colorspace: SDL_Colorspace,
116    /// Frame width
117    pub width: ::core::ffi::c_int,
118    /// Frame height
119    pub height: ::core::ffi::c_int,
120    /// Frame rate numerator ((num / denom) == FPS, (denom / num) == duration in seconds)
121    pub framerate_numerator: ::core::ffi::c_int,
122    /// Frame rate denominator ((num / denom) == FPS, (denom / num) == duration in seconds)
123    pub framerate_denominator: ::core::ffi::c_int,
124}
125
126/// The position of camera in relation to system device.
127///
128/// ## Availability
129/// This enum is available since SDL 3.2.0.
130///
131/// ## See also
132/// - [`SDL_GetCameraPosition`]
133///
134/// ## Known values (`sdl3-sys`)
135/// | Associated constant | Global constant | Description |
136/// | ------------------- | --------------- | ----------- |
137/// | [`UNKNOWN`](SDL_CameraPosition::UNKNOWN) | [`SDL_CAMERA_POSITION_UNKNOWN`] | |
138/// | [`FRONT_FACING`](SDL_CameraPosition::FRONT_FACING) | [`SDL_CAMERA_POSITION_FRONT_FACING`] | |
139/// | [`BACK_FACING`](SDL_CameraPosition::BACK_FACING) | [`SDL_CAMERA_POSITION_BACK_FACING`] | |
140#[repr(transparent)]
141#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
142pub struct SDL_CameraPosition(pub ::core::ffi::c_int);
143
144impl ::core::cmp::PartialEq<::core::ffi::c_int> for SDL_CameraPosition {
145    #[inline(always)]
146    fn eq(&self, other: &::core::ffi::c_int) -> bool {
147        &self.0 == other
148    }
149}
150
151impl ::core::cmp::PartialEq<SDL_CameraPosition> for ::core::ffi::c_int {
152    #[inline(always)]
153    fn eq(&self, other: &SDL_CameraPosition) -> bool {
154        self == &other.0
155    }
156}
157
158impl From<SDL_CameraPosition> for ::core::ffi::c_int {
159    #[inline(always)]
160    fn from(value: SDL_CameraPosition) -> Self {
161        value.0
162    }
163}
164
165#[cfg(feature = "debug-impls")]
166impl ::core::fmt::Debug for SDL_CameraPosition {
167    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
168        #[allow(unreachable_patterns)]
169        f.write_str(match *self {
170            Self::UNKNOWN => "SDL_CAMERA_POSITION_UNKNOWN",
171            Self::FRONT_FACING => "SDL_CAMERA_POSITION_FRONT_FACING",
172            Self::BACK_FACING => "SDL_CAMERA_POSITION_BACK_FACING",
173
174            _ => return write!(f, "SDL_CameraPosition({})", self.0),
175        })
176    }
177}
178
179impl SDL_CameraPosition {
180    pub const UNKNOWN: Self = Self((0 as ::core::ffi::c_int));
181    pub const FRONT_FACING: Self = Self((1 as ::core::ffi::c_int));
182    pub const BACK_FACING: Self = Self((2 as ::core::ffi::c_int));
183}
184
185pub const SDL_CAMERA_POSITION_UNKNOWN: SDL_CameraPosition = SDL_CameraPosition::UNKNOWN;
186pub const SDL_CAMERA_POSITION_FRONT_FACING: SDL_CameraPosition = SDL_CameraPosition::FRONT_FACING;
187pub const SDL_CAMERA_POSITION_BACK_FACING: SDL_CameraPosition = SDL_CameraPosition::BACK_FACING;
188
189#[cfg(feature = "metadata")]
190impl sdl3_sys::metadata::GroupMetadata for SDL_CameraPosition {
191    const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
192        &crate::metadata::camera::METADATA_SDL_CameraPosition;
193}
194
195/// The current state of a request for camera access.
196///
197/// ## Availability
198/// This enum is available since SDL 3.4.0.
199///
200/// ## See also
201/// - [`SDL_GetCameraPermissionState`]
202///
203/// ## Known values (`sdl3-sys`)
204/// | Associated constant | Global constant | Description |
205/// | ------------------- | --------------- | ----------- |
206/// | [`DENIED`](SDL_CameraPermissionState::DENIED) | [`SDL_CAMERA_PERMISSION_STATE_DENIED`] | |
207/// | [`PENDING`](SDL_CameraPermissionState::PENDING) | [`SDL_CAMERA_PERMISSION_STATE_PENDING`] | |
208/// | [`APPROVED`](SDL_CameraPermissionState::APPROVED) | [`SDL_CAMERA_PERMISSION_STATE_APPROVED`] | |
209#[repr(transparent)]
210#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
211pub struct SDL_CameraPermissionState(pub ::core::ffi::c_int);
212
213impl ::core::cmp::PartialEq<::core::ffi::c_int> for SDL_CameraPermissionState {
214    #[inline(always)]
215    fn eq(&self, other: &::core::ffi::c_int) -> bool {
216        &self.0 == other
217    }
218}
219
220impl ::core::cmp::PartialEq<SDL_CameraPermissionState> for ::core::ffi::c_int {
221    #[inline(always)]
222    fn eq(&self, other: &SDL_CameraPermissionState) -> bool {
223        self == &other.0
224    }
225}
226
227impl From<SDL_CameraPermissionState> for ::core::ffi::c_int {
228    #[inline(always)]
229    fn from(value: SDL_CameraPermissionState) -> Self {
230        value.0
231    }
232}
233
234#[cfg(feature = "debug-impls")]
235impl ::core::fmt::Debug for SDL_CameraPermissionState {
236    fn fmt(&self, f: &mut ::core::fmt::Formatter<'_>) -> ::core::fmt::Result {
237        #[allow(unreachable_patterns)]
238        f.write_str(match *self {
239            Self::DENIED => "SDL_CAMERA_PERMISSION_STATE_DENIED",
240            Self::PENDING => "SDL_CAMERA_PERMISSION_STATE_PENDING",
241            Self::APPROVED => "SDL_CAMERA_PERMISSION_STATE_APPROVED",
242
243            _ => return write!(f, "SDL_CameraPermissionState({})", self.0),
244        })
245    }
246}
247
248impl SDL_CameraPermissionState {
249    pub const DENIED: Self = Self((-1_i32 as ::core::ffi::c_int));
250    pub const PENDING: Self = Self((0_i32 as ::core::ffi::c_int));
251    pub const APPROVED: Self = Self((1_i32 as ::core::ffi::c_int));
252}
253
254pub const SDL_CAMERA_PERMISSION_STATE_DENIED: SDL_CameraPermissionState =
255    SDL_CameraPermissionState::DENIED;
256pub const SDL_CAMERA_PERMISSION_STATE_PENDING: SDL_CameraPermissionState =
257    SDL_CameraPermissionState::PENDING;
258pub const SDL_CAMERA_PERMISSION_STATE_APPROVED: SDL_CameraPermissionState =
259    SDL_CameraPermissionState::APPROVED;
260
261#[cfg(feature = "metadata")]
262impl sdl3_sys::metadata::GroupMetadata for SDL_CameraPermissionState {
263    const GROUP_METADATA: &'static sdl3_sys::metadata::Group =
264        &crate::metadata::camera::METADATA_SDL_CameraPermissionState;
265}
266
267unsafe extern "C" {
268    /// Use this function to get the number of built-in camera drivers.
269    ///
270    /// This function returns a hardcoded number. This never returns a negative
271    /// value; if there are no drivers compiled into this build of SDL, this
272    /// function returns zero. The presence of a driver in this list does not mean
273    /// it will function, it just means SDL is capable of interacting with that
274    /// interface. For example, a build of SDL might have v4l2 support, but if
275    /// there's no kernel support available, SDL's v4l2 driver would fail if used.
276    ///
277    /// By default, SDL tries all drivers, in its preferred order, until one is
278    /// found to be usable.
279    ///
280    /// ## Return value
281    /// Returns the number of built-in camera drivers.
282    ///
283    /// ## Thread safety
284    /// It is safe to call this function from any thread.
285    ///
286    /// ## Availability
287    /// This function is available since SDL 3.2.0.
288    ///
289    /// ## See also
290    /// - [`SDL_GetCameraDriver`]
291    pub fn SDL_GetNumCameraDrivers() -> ::core::ffi::c_int;
292}
293
294unsafe extern "C" {
295    /// Use this function to get the name of a built in camera driver.
296    ///
297    /// The list of camera drivers is given in the order that they are normally
298    /// initialized by default; the drivers that seem more reasonable to choose
299    /// first (as far as the SDL developers believe) are earlier in the list.
300    ///
301    /// The names of drivers are all simple, low-ASCII identifiers, like "v4l2",
302    /// "coremedia" or "android". These never have Unicode characters, and are not
303    /// meant to be proper names.
304    ///
305    /// ## Parameters
306    /// - `index`: the index of the camera driver; the value ranges from 0 to
307    ///   [`SDL_GetNumCameraDrivers()`] - 1.
308    ///
309    /// ## Return value
310    /// Returns the name of the camera driver at the requested index, or NULL if
311    ///   an invalid index was specified.
312    ///
313    /// ## Thread safety
314    /// It is safe to call this function from any thread.
315    ///
316    /// ## Availability
317    /// This function is available since SDL 3.2.0.
318    ///
319    /// ## See also
320    /// - [`SDL_GetNumCameraDrivers`]
321    pub fn SDL_GetCameraDriver(index: ::core::ffi::c_int) -> *const ::core::ffi::c_char;
322}
323
324unsafe extern "C" {
325    /// Get the name of the current camera driver.
326    ///
327    /// The names of drivers are all simple, low-ASCII identifiers, like "v4l2",
328    /// "coremedia" or "android". These never have Unicode characters, and are not
329    /// meant to be proper names.
330    ///
331    /// ## Return value
332    /// Returns the name of the current camera driver or NULL if no driver has
333    ///   been initialized.
334    ///
335    /// ## Thread safety
336    /// It is safe to call this function from any thread.
337    ///
338    /// ## Availability
339    /// This function is available since SDL 3.2.0.
340    pub fn SDL_GetCurrentCameraDriver() -> *const ::core::ffi::c_char;
341}
342
343unsafe extern "C" {
344    /// Get a list of currently connected camera devices.
345    ///
346    /// ## Parameters
347    /// - `count`: a pointer filled in with the number of cameras returned, may
348    ///   be NULL.
349    ///
350    /// ## Return value
351    /// Returns a 0 terminated array of camera instance IDs or NULL on failure;
352    ///   call [`SDL_GetError()`] for more information. This should be freed
353    ///   with [`SDL_free()`] when it is no longer needed.
354    ///
355    /// ## Thread safety
356    /// It is safe to call this function from any thread.
357    ///
358    /// ## Availability
359    /// This function is available since SDL 3.2.0.
360    ///
361    /// ## See also
362    /// - [`SDL_OpenCamera`]
363    pub fn SDL_GetCameras(count: *mut ::core::ffi::c_int) -> *mut SDL_CameraID;
364}
365
366unsafe extern "C" {
367    /// Get the list of native formats/sizes a camera supports.
368    ///
369    /// This returns a list of all formats and frame sizes that a specific camera
370    /// can offer. This is useful if your app can accept a variety of image formats
371    /// and sizes and so want to find the optimal spec that doesn't require
372    /// conversion.
373    ///
374    /// This function isn't strictly required; if you call [`SDL_OpenCamera`] with a
375    /// NULL spec, SDL will choose a native format for you, and if you instead
376    /// specify a desired format, it will transparently convert to the requested
377    /// format on your behalf.
378    ///
379    /// If `count` is not NULL, it will be filled with the number of elements in
380    /// the returned array.
381    ///
382    /// Note that it's legal for a camera to supply an empty list. This is what
383    /// will happen on Emscripten builds, since that platform won't tell _anything_
384    /// about available cameras until you've opened one, and won't even tell if
385    /// there _is_ a camera until the user has given you permission to check
386    /// through a scary warning popup.
387    ///
388    /// ## Parameters
389    /// - `instance_id`: the camera device instance ID.
390    /// - `count`: a pointer filled in with the number of elements in the list,
391    ///   may be NULL.
392    ///
393    /// ## Return value
394    /// Returns a NULL terminated array of pointers to [`SDL_CameraSpec`] or NULL on
395    ///   failure; call [`SDL_GetError()`] for more information. This is a
396    ///   single allocation that should be freed with [`SDL_free()`] when it is
397    ///   no longer needed.
398    ///
399    /// ## Thread safety
400    /// It is safe to call this function from any thread.
401    ///
402    /// ## Availability
403    /// This function is available since SDL 3.2.0.
404    ///
405    /// ## See also
406    /// - [`SDL_GetCameras`]
407    /// - [`SDL_OpenCamera`]
408    pub fn SDL_GetCameraSupportedFormats(
409        instance_id: SDL_CameraID,
410        count: *mut ::core::ffi::c_int,
411    ) -> *mut *mut SDL_CameraSpec;
412}
413
414unsafe extern "C" {
415    /// Get the human-readable device name for a camera.
416    ///
417    /// ## Parameters
418    /// - `instance_id`: the camera device instance ID.
419    ///
420    /// ## Return value
421    /// Returns a human-readable device name or NULL on failure; call
422    ///   [`SDL_GetError()`] for more information.
423    ///
424    /// ## Thread safety
425    /// It is safe to call this function from any thread.
426    ///
427    /// ## Availability
428    /// This function is available since SDL 3.2.0.
429    ///
430    /// ## See also
431    /// - [`SDL_GetCameras`]
432    pub fn SDL_GetCameraName(instance_id: SDL_CameraID) -> *const ::core::ffi::c_char;
433}
434
435unsafe extern "C" {
436    /// Get the position of the camera in relation to the system.
437    ///
438    /// Most platforms will report UNKNOWN, but mobile devices, like phones, can
439    /// often make a distinction between cameras on the front of the device (that
440    /// points towards the user, for taking "selfies") and cameras on the back (for
441    /// filming in the direction the user is facing).
442    ///
443    /// ## Parameters
444    /// - `instance_id`: the camera device instance ID.
445    ///
446    /// ## Return value
447    /// Returns the position of the camera on the system hardware.
448    ///
449    /// ## Thread safety
450    /// It is safe to call this function from any thread.
451    ///
452    /// ## Availability
453    /// This function is available since SDL 3.2.0.
454    ///
455    /// ## See also
456    /// - [`SDL_GetCameras`]
457    pub fn SDL_GetCameraPosition(instance_id: SDL_CameraID) -> SDL_CameraPosition;
458}
459
460unsafe extern "C" {
461    /// Open a video recording device (a "camera").
462    ///
463    /// You can open the device with any reasonable spec, and if the hardware can't
464    /// directly support it, it will convert data seamlessly to the requested
465    /// format. This might incur overhead, including scaling of image data.
466    ///
467    /// If you would rather accept whatever format the device offers, you can pass
468    /// a NULL spec here and it will choose one for you (and you can use
469    /// SDL_Surface's conversion/scaling functions directly if necessary).
470    ///
471    /// You can call [`SDL_GetCameraFormat()`] to get the actual data format if passing
472    /// a NULL spec here. You can see the exact specs a device can support without
473    /// conversion with [`SDL_GetCameraSupportedFormats()`].
474    ///
475    /// SDL will not attempt to emulate framerate; it will try to set the hardware
476    /// to the rate closest to the requested speed, but it won't attempt to limit
477    /// or duplicate frames artificially; call [`SDL_GetCameraFormat()`] to see the
478    /// actual framerate of the opened the device, and check your timestamps if
479    /// this is crucial to your app!
480    ///
481    /// Note that the camera is not usable until the user approves its use! On some
482    /// platforms, the operating system will prompt the user to permit access to
483    /// the camera, and they can choose Yes or No at that point. Until they do, the
484    /// camera will not be usable. The app should either wait for an
485    /// [`SDL_EVENT_CAMERA_DEVICE_APPROVED`] (or [`SDL_EVENT_CAMERA_DEVICE_DENIED`]) event,
486    /// or poll [`SDL_GetCameraPermissionState()`] occasionally until it returns
487    /// non-zero. On platforms that don't require explicit user approval (and
488    /// perhaps in places where the user previously permitted access), the approval
489    /// event might come immediately, but it might come seconds, minutes, or hours
490    /// later!
491    ///
492    /// ## Parameters
493    /// - `instance_id`: the camera device instance ID.
494    /// - `spec`: the desired format for data the device will provide. Can be
495    ///   NULL.
496    ///
497    /// ## Return value
498    /// Returns an [`SDL_Camera`] object or NULL on failure; call [`SDL_GetError()`] for
499    ///   more information.
500    ///
501    /// ## Thread safety
502    /// It is safe to call this function from any thread.
503    ///
504    /// ## Availability
505    /// This function is available since SDL 3.2.0.
506    ///
507    /// ## See also
508    /// - [`SDL_GetCameras`]
509    /// - [`SDL_GetCameraFormat`]
510    pub fn SDL_OpenCamera(
511        instance_id: SDL_CameraID,
512        spec: *const SDL_CameraSpec,
513    ) -> *mut SDL_Camera;
514}
515
516unsafe extern "C" {
517    /// Query if camera access has been approved by the user.
518    ///
519    /// Cameras will not function between when the device is opened by the app and
520    /// when the user permits access to the hardware. On some platforms, this
521    /// presents as a popup dialog where the user has to explicitly approve access;
522    /// on others the approval might be implicit and not alert the user at all.
523    ///
524    /// This function can be used to check the status of that approval. It will
525    /// return [`SDL_CAMERA_PERMISSION_STATE_PENDING`] if waiting for user response,
526    /// [`SDL_CAMERA_PERMISSION_STATE_APPROVED`] if the camera is approved for use, and
527    /// [`SDL_CAMERA_PERMISSION_STATE_DENIED`] if the user denied access.
528    ///
529    /// Instead of polling with this function, you can wait for a
530    /// [`SDL_EVENT_CAMERA_DEVICE_APPROVED`] (or [`SDL_EVENT_CAMERA_DEVICE_DENIED`]) event
531    /// in the standard SDL event loop, which is guaranteed to be sent once when
532    /// permission to use the camera is decided.
533    ///
534    /// If a camera is declined, there's nothing to be done but call
535    /// [`SDL_CloseCamera()`] to dispose of it.
536    ///
537    /// ## Parameters
538    /// - `camera`: the opened camera device to query.
539    ///
540    /// ## Return value
541    /// Returns an [`SDL_CameraPermissionState`] value indicating if access is
542    ///   granted, or [`SDL_CAMERA_PERMISSION_STATE_PENDING`] if the decision
543    ///   is still pending.
544    ///
545    /// ## Thread safety
546    /// It is safe to call this function from any thread.
547    ///
548    /// ## Availability
549    /// This function is available since SDL 3.2.0.
550    ///
551    /// ## See also
552    /// - [`SDL_OpenCamera`]
553    /// - [`SDL_CloseCamera`]
554    pub fn SDL_GetCameraPermissionState(camera: *mut SDL_Camera) -> SDL_CameraPermissionState;
555}
556
557unsafe extern "C" {
558    /// Get the instance ID of an opened camera.
559    ///
560    /// ## Parameters
561    /// - `camera`: an [`SDL_Camera`] to query.
562    ///
563    /// ## Return value
564    /// Returns the instance ID of the specified camera on success or 0 on
565    ///   failure; call [`SDL_GetError()`] for more information.
566    ///
567    /// ## Thread safety
568    /// It is safe to call this function from any thread.
569    ///
570    /// ## Availability
571    /// This function is available since SDL 3.2.0.
572    ///
573    /// ## See also
574    /// - [`SDL_OpenCamera`]
575    pub fn SDL_GetCameraID(camera: *mut SDL_Camera) -> SDL_CameraID;
576}
577
578unsafe extern "C" {
579    /// Get the properties associated with an opened camera.
580    ///
581    /// ## Parameters
582    /// - `camera`: the [`SDL_Camera`] obtained from [`SDL_OpenCamera()`].
583    ///
584    /// ## Return value
585    /// Returns a valid property ID on success or 0 on failure; call
586    ///   [`SDL_GetError()`] for more information.
587    ///
588    /// ## Thread safety
589    /// It is safe to call this function from any thread.
590    ///
591    /// ## Availability
592    /// This function is available since SDL 3.2.0.
593    pub fn SDL_GetCameraProperties(camera: *mut SDL_Camera) -> SDL_PropertiesID;
594}
595
596unsafe extern "C" {
597    /// Get the spec that a camera is using when generating images.
598    ///
599    /// Note that this might not be the native format of the hardware, as SDL might
600    /// be converting to this format behind the scenes.
601    ///
602    /// If the system is waiting for the user to approve access to the camera, as
603    /// some platforms require, this will return false, but this isn't necessarily
604    /// a fatal error; you should either wait for an
605    /// [`SDL_EVENT_CAMERA_DEVICE_APPROVED`] (or [`SDL_EVENT_CAMERA_DEVICE_DENIED`]) event,
606    /// or poll [`SDL_GetCameraPermissionState()`] occasionally until it returns
607    /// non-zero.
608    ///
609    /// ## Parameters
610    /// - `camera`: opened camera device.
611    /// - `spec`: the [`SDL_CameraSpec`] to be initialized by this function.
612    ///
613    /// ## Return value
614    /// Returns true on success or false on failure; call [`SDL_GetError()`] for more
615    ///   information.
616    ///
617    /// ## Thread safety
618    /// It is safe to call this function from any thread.
619    ///
620    /// ## Availability
621    /// This function is available since SDL 3.2.0.
622    ///
623    /// ## See also
624    /// - [`SDL_OpenCamera`]
625    pub fn SDL_GetCameraFormat(
626        camera: *mut SDL_Camera,
627        spec: *mut SDL_CameraSpec,
628    ) -> ::core::primitive::bool;
629}
630
631unsafe extern "C" {
632    /// Acquire a frame.
633    ///
634    /// The frame is a memory pointer to the image data, whose size and format are
635    /// given by the spec requested when opening the device.
636    ///
637    /// This is a non blocking API. If there is a frame available, a non-NULL
638    /// surface is returned, and timestampNS will be filled with a non-zero value.
639    ///
640    /// Note that an error case can also return NULL, but a NULL by itself is
641    /// normal and just signifies that a new frame is not yet available. Note that
642    /// even if a camera device fails outright (a USB camera is unplugged while in
643    /// use, etc), SDL will send an event separately to notify the app, but
644    /// continue to provide blank frames at ongoing intervals until
645    /// [`SDL_CloseCamera()`] is called, so real failure here is almost always an out
646    /// of memory condition.
647    ///
648    /// After use, the frame should be released with [`SDL_ReleaseCameraFrame()`]. If
649    /// you don't do this, the system may stop providing more video!
650    ///
651    /// Do not call [`SDL_DestroySurface()`] on the returned surface! It must be given
652    /// back to the camera subsystem with SDL_ReleaseCameraFrame!
653    ///
654    /// If the system is waiting for the user to approve access to the camera, as
655    /// some platforms require, this will return NULL (no frames available); you
656    /// should either wait for an [`SDL_EVENT_CAMERA_DEVICE_APPROVED`] (or
657    /// [`SDL_EVENT_CAMERA_DEVICE_DENIED`]) event, or poll
658    /// [`SDL_GetCameraPermissionState()`] occasionally until it returns non-zero.
659    ///
660    /// ## Parameters
661    /// - `camera`: opened camera device.
662    /// - `timestampNS`: a pointer filled in with the frame's timestamp, or 0 on
663    ///   error. Can be NULL.
664    ///
665    /// ## Return value
666    /// Returns a new frame of video on success, NULL if none is currently
667    ///   available.
668    ///
669    /// ## Thread safety
670    /// It is safe to call this function from any thread.
671    ///
672    /// ## Availability
673    /// This function is available since SDL 3.2.0.
674    ///
675    /// ## See also
676    /// - [`SDL_ReleaseCameraFrame`]
677    pub fn SDL_AcquireCameraFrame(
678        camera: *mut SDL_Camera,
679        timestampNS: *mut Uint64,
680    ) -> *mut SDL_Surface;
681}
682
683unsafe extern "C" {
684    /// Release a frame of video acquired from a camera.
685    ///
686    /// Let the back-end re-use the internal buffer for camera.
687    ///
688    /// This function _must_ be called only on surface objects returned by
689    /// [`SDL_AcquireCameraFrame()`]. This function should be called as quickly as
690    /// possible after acquisition, as SDL keeps a small FIFO queue of surfaces for
691    /// video frames; if surfaces aren't released in a timely manner, SDL may drop
692    /// upcoming video frames from the camera.
693    ///
694    /// If the app needs to keep the surface for a significant time, they should
695    /// make a copy of it and release the original.
696    ///
697    /// The app should not use the surface again after calling this function;
698    /// assume the surface is freed and the pointer is invalid.
699    ///
700    /// ## Parameters
701    /// - `camera`: opened camera device.
702    /// - `frame`: the video frame surface to release.
703    ///
704    /// ## Thread safety
705    /// It is safe to call this function from any thread.
706    ///
707    /// ## Availability
708    /// This function is available since SDL 3.2.0.
709    ///
710    /// ## See also
711    /// - [`SDL_AcquireCameraFrame`]
712    pub fn SDL_ReleaseCameraFrame(camera: *mut SDL_Camera, frame: *mut SDL_Surface);
713}
714
715unsafe extern "C" {
716    /// Use this function to shut down camera processing and close the camera
717    /// device.
718    ///
719    /// ## Parameters
720    /// - `camera`: opened camera device.
721    ///
722    /// ## Thread safety
723    /// It is safe to call this function from any thread, but no
724    ///   thread may reference `device` once this function is called.
725    ///
726    /// ## Availability
727    /// This function is available since SDL 3.2.0.
728    ///
729    /// ## See also
730    /// - [`SDL_OpenCamera`]
731    pub fn SDL_CloseCamera(camera: *mut SDL_Camera);
732}
733
734/// The opaque structure used to identify an opened SDL camera.
735///
736/// ## Availability
737/// This struct is available since SDL 3.2.0.
738#[repr(C)]
739pub struct SDL_Camera {
740    _opaque: [::core::primitive::u8; 0],
741}
742
743#[cfg(doc)]
744use crate::everything::*;