screencapturekit/output/mod.rs
1//! Frame buffer and pixel access
2//!
3//! This module provides types for accessing captured frame data at the pixel level.
4//! All buffer types now use `std::io::Cursor` for data access, providing standard
5//! `Read` and `Seek` traits for maximum compatibility.
6//!
7//! ## Main Types
8//!
9//! - [`CVPixelBuffer`] - Pixel buffer containing frame data
10//! - [`IOSurface`] - IOSurface-backed buffer for zero-copy access
11//! - [`PixelBufferLockGuard`] - RAII guard for locked pixel buffer access
12//! - [`IOSurfaceLockGuard`] - RAII guard for locked `IOSurface` access
13//! - [`PixelBufferCursorExt`] - Extension trait for pixel-specific cursor operations
14//!
15//! ## Examples
16//!
17//! ### Basic Usage with Cursor
18//!
19//! ```no_run
20//! use std::io::{Read, Seek, SeekFrom};
21//! use screencapturekit::output::{CVImageBufferLockExt, PixelBufferLockFlags, PixelBufferCursorExt};
22//!
23//! # fn example(sample: screencapturekit::cm::CMSampleBuffer) -> Result<(), Box<dyn std::error::Error>> {
24//! if let Some(pixel_buffer) = sample.get_image_buffer() {
25//! let guard = pixel_buffer.lock(PixelBufferLockFlags::ReadOnly)?;
26//!
27//! // Get a standard io::Cursor
28//! let mut cursor = guard.cursor();
29//!
30//! // Read pixels using standard Read trait
31//! let mut pixel = [0u8; 4];
32//! cursor.read_exact(&mut pixel)?;
33//!
34//! // Or use the extension trait for pixel operations
35//! cursor.seek(SeekFrom::Start(0))?;
36//! let pixel = cursor.read_pixel()?;
37//!
38//! // Seek to specific coordinates
39//! cursor.seek_to_pixel(50, 50, guard.bytes_per_row())?;
40//! }
41//! # Ok(())
42//! # }
43//! ```
44//!
45//! ### Direct Slice Access
46//!
47//! ```no_run
48//! use screencapturekit::output::{CVImageBufferLockExt, PixelBufferLockFlags};
49//!
50//! # fn example(sample: screencapturekit::cm::CMSampleBuffer) -> Result<(), Box<dyn std::error::Error>> {
51//! if let Some(pixel_buffer) = sample.get_image_buffer() {
52//! let guard = pixel_buffer.lock(PixelBufferLockFlags::ReadOnly)?;
53//!
54//! // Direct slice access (no cursor overhead)
55//! let data = guard.as_slice();
56//! println!("Frame size: {} bytes", data.len());
57//!
58//! // Access specific rows
59//! if let Some(row) = guard.row(100) {
60//! println!("Row 100 has {} bytes", row.len());
61//! }
62//! }
63//! # Ok(())
64//! # }
65//! ```
66
67pub mod iosurface;
68pub mod pixel_buffer;
69
70pub use crate::cm::{CMSampleBuffer, CMTime, CVPixelBuffer};
71pub use iosurface::{CVPixelBufferIOSurface, IOSurface, IOSurfaceLockGuard, IOSurfaceLockOptions};
72pub use pixel_buffer::{
73 CVImageBufferLockExt, PixelBufferCursorExt, PixelBufferLockFlags, PixelBufferLockGuard,
74};