Skip to main content

CameraCapture

Struct CameraCapture 

Source
pub struct CameraCapture { /* private fields */ }
Expand description

Stateful camera capture session over SDL’s camera backend.

poll acquires the newest queued frame, uploads it into an owned RGBA8 texture, and returns it as a VideoFrame; the SDL surface is released immediately, so no ring-slot release contract exists on this route. The returned frame’s presentation timestamp is the camera’s hardware capture timestamp in microseconds and its duration follows the negotiated frame rate.

Implementations§

Source§

impl CameraCapture

Source

pub fn open(runtime: &Runtime, config: &CameraCaptureConfig) -> Result<Self>

Open the selected camera and negotiate the closest supported format.

The session requests RGBA32 output so no pixel conversion happens outside SDL. On platforms with a camera permission gate the camera opens before approval; poll reports ErrorKind::MissingCapability when the user denies access and None while approval is pending.

§Errors

Returns an error for a zero extent, when no camera device matches device_index, or when SDL cannot open or describe the device.

Source

pub fn poll(&mut self) -> Result<Option<VideoFrame>>

Acquire and upload the newest queued camera frame.

Returns Ok(None) when the camera has not produced another frame yet — this is also the steady state while a platform permission request is pending. Callers drive this in their own pacing loop; poll never blocks.

§Errors

Returns an error after close, when camera access was denied, for an unexpected frame layout, or when the texture upload fails.

Source

pub fn close(&mut self)

Close the session and release the camera.

Frames already returned remain owned by their callers; SDL surfaces are released eagerly at poll time so nothing is deferred to close.

Source

pub const fn is_streaming(&self) -> bool

Return whether the session still owns an open camera.

Source

pub const fn width(&self) -> u32

Return the negotiated frame width in pixels.

Source

pub const fn height(&self) -> u32

Return the negotiated frame height in pixels.

Source

pub fn frame_rate(&self) -> f64

Return the negotiated frame rate, or 0.0 when the device reported none.

Trait Implementations§

Source§

impl Drop for CameraCapture

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for CameraCapture

§

impl !Send for CameraCapture

§

impl !Sync for CameraCapture

§

impl !UnwindSafe for CameraCapture

§

impl Forget for CameraCapture

§

impl Freeze for CameraCapture
where *const RcInner<RefCell<RuntimeState>> is !null: Freeze, PhantomData<RcInner<RefCell<RuntimeState>>>: Freeze, PhantomData<*mut ()>: Freeze, *const SDL_Camera is !null: Freeze,

§

impl Move for CameraCapture

§

impl Unpin for CameraCapture
where Rc<RefCell<RuntimeState>>: Unpin, *mut (): Unpin, *const SDL_Camera is !null: Unpin,

§

impl UnsafeUnpin for CameraCapture
where *const RcInner<RefCell<RuntimeState>> is !null: UnsafeUnpin, PhantomData<RcInner<RefCell<RuntimeState>>>: UnsafeUnpin, PhantomData<*mut ()>: UnsafeUnpin, *const SDL_Camera is !null: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.