libfreemkv/lib.rs
1//! libfreemkv -- Open source optical drive library for 4K UHD / Blu-ray / DVD.
2//!
3//! Handles drive access, disc structure parsing, AACS decryption, and raw
4//! sector reading. 206 bundled drive profiles. No external files needed.
5//!
6//! # Quick Start
7//!
8//! ```no_run
9//! use libfreemkv::{Drive, Disc, ScanOptions, find_drive};
10//!
11//! let mut drive = find_drive().expect("no optical drive found");
12//! drive.wait_ready().unwrap();
13//! drive.init().unwrap();
14//! let disc = Disc::scan(&mut drive, &ScanOptions::default()).unwrap();
15//!
16//! for title in &disc.titles {
17//! println!("{} -- {} streams", title.duration_display(), title.streams.len());
18//! }
19//!
20//! // Stream via PES pipeline
21//! let opts = libfreemkv::InputOptions::default();
22//! let mut input = libfreemkv::input("disc://", &opts).unwrap();
23//! let title = input.info().clone();
24//! let mut output = libfreemkv::output("mkv://Movie.mkv", &title).unwrap();
25//! while let Ok(Some(frame)) = input.read() {
26//! output.write(&frame).unwrap();
27//! }
28//! output.finish().unwrap();
29//! ```
30//!
31//! # Architecture
32//!
33//! ```text
34//! Drive -- open, identify, unlock, read sectors
35//! ├── ScsiTransport -- SG_IO (Linux), IOKit (macOS)
36//! ├── DriveProfile -- per-drive unlock parameters (206 bundled)
37//! ├── DriveId -- INQUIRY + GET_CONFIG identification
38//! └── Platform
39//! └── Mt1959 -- MediaTek unlock/read (Renesas planned)
40//!
41//! Disc -- scan titles, streams, AACS state
42//! ├── UDF reader -- Blu-ray UDF 2.50 with metadata partitions
43//! ├── MPLS parser -- playlists → titles + clips + STN streams
44//! ├── CLPI parser -- clip info → EP map → sector extents
45//! ├── JAR parser -- BD-J audio track labels
46//! └── AACS -- encryption: key resolution + content decrypt
47//! ├── aacs -- KEYDB, VUK, MKB, unit decrypt
48//! └── handshake -- SCSI auth, ECDH, bus key
49//! ```
50//!
51//! # AACS Encryption
52//!
53//! Disc scanning automatically detects and handles AACS encryption.
54//! If a KEYDB.cfg is available (via `ScanOptions` or standard paths),
55//! the library resolves keys and decrypts content transparently.
56//!
57//! Supports AACS 1.0 (Blu-ray) and AACS 2.0 (UHD, with fallback).
58//!
59//! # Error Codes
60//!
61//! All errors are structured with numeric codes. No user-facing English
62//! text -- applications format their own messages.
63//!
64//! | Range | Category |
65//! |-------|----------|
66//! | E1xxx | Device errors (not found, permission) |
67//! | E2xxx | Profile errors (unsupported drive) |
68//! | E3xxx | Unlock errors (failed, signature) |
69//! | E4xxx | SCSI errors (command failed, timeout) |
70//! | E5xxx | I/O errors |
71//! | E6xxx | Disc format errors |
72//! | E7xxx | AACS errors |
73
74pub mod aacs;
75pub(crate) mod clpi;
76pub mod css;
77pub mod decrypt;
78pub mod disc;
79pub mod drive;
80pub mod error;
81pub mod event;
82pub(crate) mod identity;
83pub(crate) mod ifo;
84pub mod keydb;
85pub(crate) mod labels;
86pub(crate) mod mpls;
87pub mod mux;
88pub mod pes;
89pub(crate) mod platform;
90pub mod profile;
91pub mod scsi;
92pub mod sector;
93pub(crate) mod speed;
94pub(crate) mod udf;
95
96pub use drive::capture::{
97 capture_drive_data, mask_bytes, mask_string, CapturedFeature, DriveCapture,
98};
99pub use drive::{find_drive, find_drives, Drive, DriveStatus};
100pub use error::{Error, Result};
101pub use event::{Event, EventKind};
102pub use identity::DriveId;
103pub use profile::DriveProfile;
104// Platform trait is pub(crate) -- callers use Drive, not Platform directly
105pub use decrypt::{decrypt_sectors, DecryptKeys};
106pub use disc::{
107 AacsState, AudioChannels, AudioStream, Clip, Codec, ColorSpace, ContentFormat, Disc,
108 DiscFormat, DiscTitle, Extent, FrameRate, HdrFormat, KeySource, Resolution, SampleRate,
109 ScanOptions, Stream, SubtitleStream, VideoStream,
110};
111pub use mux::DiscStream;
112pub use mux::M2tsStream;
113pub use mux::MkvStream;
114pub use mux::NetworkStream;
115pub use mux::NullStream;
116pub use mux::StdioStream;
117pub use mux::{input, output, parse_url, InputOptions, StreamUrl};
118pub use scsi::ScsiTransport;
119pub use sector::SectorReader;
120pub use speed::DriveSpeed;
121pub use udf::{read_filesystem, UdfFs};