Skip to main content

FormatDescriptor

Struct FormatDescriptor 

Source
pub struct FormatDescriptor {
    pub pixel_format: PixelFormat,
    pub size: Size,
    /* private fields */
}
Expand description

Describes a supported camera format.

Fields§

§pixel_format: PixelFormat§size: Size

Implementations§

Source§

impl FormatDescriptor

Source

pub fn frame_rate_ranges(&self) -> &[FrameRateRange]

The frame rate ranges supported by this format.

Examples found in repository?
examples/capture.rs (line 49)
9fn main() {
10    #[cfg(target_os = "macos")]
11    {
12        use camera_stream::platform::macos::device::MacosCameraManager;
13
14        let manager = MacosCameraManager::default();
15
16        // Discover devices
17        let devices: Vec<_> = manager
18            .discover_devices()
19            .expect("failed to discover devices")
20            .collect();
21        println!("Found {} camera(s):", devices.len());
22        for (i, dev) in devices.iter().enumerate() {
23            println!("  [{}] {} (id: {})", i, dev.name(), dev.id());
24        }
25
26        if devices.is_empty() {
27            println!("No cameras found.");
28            return;
29        }
30
31        // Use default device
32        let device = manager
33            .default_device()
34            .expect("failed to get default device")
35            .expect("no default camera");
36
37        println!("\nUsing: {} ({})", device.name(), device.id());
38
39        // Print supported formats
40        let formats: Vec<_> = device.supported_formats().expect("failed to get formats").collect();
41        println!("\nSupported formats ({} total):", formats.len());
42        for (i, f) in formats.iter().take(10).enumerate() {
43            println!(
44                "  [{}] {:?} {}x{} ({} frame rate range(s))",
45                i,
46                f.pixel_format,
47                f.size.width,
48                f.size.height,
49                f.frame_rate_ranges().len(),
50            );
51            for rr in f.frame_rate_ranges() {
52                println!("       {:.1}-{:.1} fps", rr.min.as_f64(), rr.max.as_f64(),);
53            }
54        }
55        if formats.len() > 10 {
56            println!("  ... and {} more", formats.len() - 10);
57        }
58
59        // Pick first format or a reasonable default
60        let config =
61            if let Some(f) = formats.first() {
62                let rate = f.frame_rate_ranges().first().map(|r| r.max).unwrap_or(
63                    camera_stream::Ratio {
64                        numerator: 30000,
65                        denominator: 1000,
66                    },
67                );
68                camera_stream::StreamConfig {
69                    pixel_format: f.pixel_format,
70                    size: f.size,
71                    frame_rate: rate,
72                }
73            } else {
74                println!("No supported formats found.");
75                return;
76            };
77
78        println!(
79            "\nOpening with {:?} {}x{} @ {:.1} fps",
80            config.pixel_format,
81            config.size.width,
82            config.size.height,
83            config.frame_rate.as_f64(),
84        );
85
86        let mut stream = device.open(&config).expect("failed to open stream");
87
88        let frame_count = Arc::new(AtomicU64::new(0));
89        let count_clone = frame_count.clone();
90        let target_frames: u64 = 60;
91
92        stream
93            .start(move |frame| {
94                let n = count_clone.fetch_add(1, Ordering::Relaxed) + 1;
95                let planes = frame.planes();
96                let total_bytes: usize = planes.iter().map(|p| p.data.len()).sum();
97                println!(
98                    "Frame {}: {:?} {}x{} ts={:.3}s planes={} bytes={}",
99                    n,
100                    frame.pixel_format(),
101                    frame.size().width,
102                    frame.size().height,
103                    frame.timestamp().as_secs_f64(),
104                    planes.len(),
105                    total_bytes,
106                );
107            })
108            .expect("failed to start stream");
109
110        // Wait until we've captured enough frames
111        loop {
112            std::thread::sleep(Duration::from_millis(100));
113            if frame_count.load(Ordering::Relaxed) >= target_frames {
114                break;
115            }
116        }
117
118        stream.stop().expect("failed to stop stream");
119        println!(
120            "\nDone. Captured {} frames.",
121            frame_count.load(Ordering::Relaxed)
122        );
123    }
124
125    #[cfg(not(target_os = "macos"))]
126    {
127        println!("This example only works on macOS.");
128    }
129}

Trait Implementations§

Source§

impl Clone for FormatDescriptor

Source§

fn clone(&self) -> FormatDescriptor

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FormatDescriptor

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for FormatDescriptor

Source§

fn eq(&self, other: &FormatDescriptor) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for FormatDescriptor

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

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