Skip to main content

camera/
lib.rs

1//! Async cross-platform camera capture with owned sessions and immutable frames.
2#![warn(missing_docs)]
3//!
4//! ```no_run
5//! use camera::{CameraSystem, CaptureProfile, DeviceSelector};
6//! # async fn capture()->camera::CameraResult<()> {
7//! let system=CameraSystem::new();
8//! let mut capture=system.capture(DeviceSelector::Default)
9//!     .profile(CaptureProfile::Preview)
10//!     .resolution(1280,720)
11//!     .start().await?;
12//! let frame=capture.next_frame().await?;
13//! println!("{} native bytes, {:?}",frame.bytes().len(),frame.layout());
14//! capture.close().await?;
15//! # Ok(()) }
16//! ```
17#[cfg(feature = "runtime-tokio")]
18mod api;
19#[cfg(feature = "runtime-tokio")]
20#[allow(dead_code)]
21mod backends;
22#[cfg(feature = "blocking")]
23pub mod blocking;
24mod contract;
25#[cfg(feature = "runtime-tokio")]
26mod controls;
27#[cfg(feature = "convert-rgb")]
28mod conversion;
29mod error;
30#[cfg(feature = "runtime-tokio")]
31#[cfg_attr(not(feature = "custom-backend"), allow(dead_code))]
32mod extension;
33mod format;
34#[cfg(feature = "runtime-tokio")]
35mod frame;
36#[cfg(feature = "decode-mjpeg")]
37mod mjpeg;
38#[cfg(all(
39    unix,
40    any(
41        all(
42            feature = "backend-uvc",
43            any(target_os = "linux", target_os = "macos", target_os = "android")
44        ),
45        test
46    )
47))]
48mod owned_fd;
49#[allow(dead_code)]
50mod pixels;
51#[cfg(feature = "runtime-tokio")]
52#[allow(dead_code)]
53mod traits;
54// Native adapters keep a small internal compatibility vocabulary.
55#[allow(dead_code)]
56mod types;
57#[allow(dead_code)]
58mod utils;
59
60#[cfg(feature = "runtime-tokio")]
61pub use api::{
62    CameraSystem, Capture, CaptureBuilder, Device, EventReceiver, Session, SessionEvent,
63    SessionState, StateWatcher, SystemBuilder,
64};
65#[cfg(feature = "runtime-tokio")]
66pub(crate) use backends::BackendType;
67pub use contract::*;
68#[cfg(feature = "runtime-tokio")]
69pub use controls::{
70    ControlDescriptor, ControlId, ControlMode, ControlOutcome, ControlRange, ControlReadback,
71    ControlUnit, ControlValue, Exposure, Focus, Kelvin, WhiteBalance,
72};
73#[cfg(feature = "convert-rgb")]
74pub use conversion::{selected_conversion_path, ConversionRequest, RgbConverter};
75pub use error::{CameraError, CameraErrorKind, RecoveryHint};
76#[cfg(all(feature = "runtime-tokio", feature = "custom-backend"))]
77pub use extension::{
78    BackendDevice, BackendDeviceInfo, BackendProvider, FrameSink, WritableFrameLease,
79};
80pub use format::{
81    ClockDomain, ColorInfo, ColorMatrix, ColorPrimaries, ColorRange, FrameLayout, FrameRate,
82    MemoryBudget, Orientation, OverflowPolicy, PixelFormat, PlaneLayout, ReconnectPolicy,
83    SourceTimestamp, TransferFunction,
84};
85pub(crate) use format::{DeliveryPolicy, OutputFormat, SelectionPolicy, StreamRequest};
86#[cfg(feature = "runtime-tokio")]
87#[cfg(not(feature = "benchmark-internals"))]
88pub(crate) use frame::FrameHub;
89#[cfg(feature = "runtime-tokio")]
90#[cfg(feature = "benchmark-internals")]
91#[doc(hidden)]
92pub use frame::FrameHub;
93#[cfg(feature = "runtime-tokio")]
94pub use frame::{CapturedFrame, Frame, FrameKey, FrameMetrics, FrameReceiver, RgbView};
95#[cfg(feature = "runtime-tokio")]
96pub use traits::StreamStats;
97#[cfg(feature = "runtime-tokio")]
98pub(crate) use traits::{CameraControl, CameraManager, StreamingCamera};
99/// Result type returned by all core camera operations.
100pub type CameraResult<T> = std::result::Result<T, CameraError>;
101pub(crate) use types::{CameraConfig, VideoFormat};
102#[cfg(feature = "runtime-tokio")]
103pub(crate) use types::{
104    CameraControlRange, CameraControlType, CameraControlValue, CameraDeviceInfo,
105};
106#[cfg(test)]
107#[cfg(feature = "runtime-tokio")]
108mod api_regressions_tests;
109#[cfg(feature = "runtime-tokio")]
110mod device_watch;
111#[cfg(test)]
112#[cfg(feature = "runtime-tokio")]
113mod shared_frames_tests;
114#[cfg(feature = "runtime-tokio")]
115pub use device_watch::{DeviceSnapshot, DeviceWatcher};
116
117#[cfg(test)]
118#[cfg(feature = "runtime-tokio")]
119mod yuv_planes_tests;