Module camera

Source
Expand description

Check if a camera is available, request access to it and open a PipeWire remote stream.

§Examples

use ashpd::desktop::camera::Camera;

pub async fn run() -> ashpd::Result<()> {
    let camera = Camera::new().await?;
    if camera.is_present().await? {
        camera.request_access().await?;
        let remote_fd = camera.open_pipe_wire_remote().await?;
        // pass the remote fd to GStreamer for example
    }
    Ok(())
}

An example on how to connect with Pipewire can be found here. Although the example’s primary focus is screen casting, stream connection logic remains the same – with one accessibility change:

let stream = pw::stream::Stream::new(
   &core,
   "video-test",
   properties! {
       *pw::keys::MEDIA_TYPE => "Video",
       *pw::keys::MEDIA_CATEGORY => "Capture",
       *pw::keys::MEDIA_ROLE => "Screen", // <-- make this 'Camera'
   },
)?;

Structs§

Camera
The interface lets sandboxed applications access camera devices, such as web cams.
Stream
A PipeWire camera stream returned by pipewire_streams.

Functions§

pipewire_streamspipewire
A helper to get a list of PipeWire streams to use with the camera file descriptor returned by Camera::open_pipe_wire_remote.
requestpipewire
Request access to the camera and return a file descriptor and a list of the available streams, one per camera.