pub struct GstreamerVideoCapture {
child: Child,
stdout: ChildStdout,
width: u32,
height: u32,
framerate: f64,
next_index: u64,
raw_buffer: Vec<u8>,
}Expand description
Streaming video capture wrapping a gst-launch-1.0 child process.
Fields§
§child: Child§stdout: ChildStdout§width: u32§height: u32§framerate: f64§next_index: u64§raw_buffer: Vec<u8>Pre-allocated scratch buffer for the raw bytes of one frame.
Implementations§
Source§impl GstreamerVideoCapture
impl GstreamerVideoCapture
Sourcepub fn from_default_camera(
width: u32,
height: u32,
framerate: u32,
) -> Result<Self, Error>
pub fn from_default_camera( width: u32, height: u32, framerate: u32, ) -> Result<Self, Error>
Build a capture from the default OS camera via gst’s
autovideosrc (M-CAM.0 / AUT-254).
On macOS autovideosrc routes to avfvideosrc; on Linux
v4l2src; on Windows mfvideosrc. Caller picks the output
dimensions + framerate — gst’s videoconvert step resizes /
converts whatever the camera natively produces.
**macOS gotcha:** `avfvideosrc` requires
`NSCameraUsageDescription` in the bundled app's Info.plist.
Without it the gst pipeline fails with a misleading "device
busy" error AND the OS permission prompt never shows. See
`crates/app/tauri.conf.json` for the project's declaration.§Errors
Error::InvalidFormatif any dimension is zero.Error::Spawnifgst-launch-1.0isn’t onPATH.Error::NoStdoutif the child’s stdout pipe is missing (shouldn’t happen — we request it explicitly).
Cross-OS behaviour: on a host without a default camera the
pipeline spawns but next_frame returns
Error::EndOfStream as soon as the OS denies access /
reports no device. Integration tests should call
default_camera_available first and skip cleanly.
Sourcepub fn from_camera(
camera_id: &str,
width: u32,
height: u32,
framerate: u32,
) -> Result<Self, Error>
pub fn from_camera( camera_id: &str, width: u32, height: u32, framerate: u32, ) -> Result<Self, Error>
Build a capture pinned to a specific camera resolved by its
stable id (M-CAM.4). Re-probes list_cameras() at call time to
turn camera_id into the OS-native source element + props
(avfvideosrc device-index=N on macOS, mfvideosrc device-path=... on Windows, v4l2src device=... on Linux).
If the camera is in the enumeration but the parser couldn’t
extract a gst_source for it (unusual — would indicate a
gst-device-monitor output format the parser didn’t recognise),
falls back to autovideosrc with a tracing::warn so the user
still sees some camera. The picker just won’t be honored.
§Errors
Error::InvalidFormatif any dimension is zero.Error::CameraNotFoundif no enumerated camera matchescamera_id(typical: the camera was unplugged betweenlist_cameras()andfrom_camera()).Error::Spawnifgst-launch-1.0isn’t onPATH.Error::NoStdoutif the child’s stdout pipe is missing.
Sourcepub fn test_source(
width: u32,
height: u32,
framerate: u32,
) -> Result<Self, Error>
pub fn test_source( width: u32, height: u32, framerate: u32, ) -> Result<Self, Error>
Build a capture from videotestsrc at the given dimensions +
framerate. The default videotestsrc pattern is the SMPTE
colorbars — useful for visual smoke checks because every frame
is visually distinct (animated subpattern).
Sourcepub fn dimensions(&self) -> (u32, u32)
pub fn dimensions(&self) -> (u32, u32)
Width × height the captured frames will carry.
Sourcepub fn frames_emitted(&self) -> u64
pub fn frames_emitted(&self) -> u64
Cumulative frames emitted across next_frame calls.
Sourcepub fn next_frame(&mut self) -> Result<VideoFrame, Error>
pub fn next_frame(&mut self) -> Result<VideoFrame, Error>
Read one BGRA frame. PTS is computed from the frame index and the captured framerate.
§Errors
Error::Ioon read failures.Error::EndOfStreamif the pipeline ends mid-frame.