oxideav_source/lib.rs
1//! Source registry shim — `oxideav_core::SourceRegistry` plus the
2//! built-in `file://`, `mem://`, `data:`, and `concat:` drivers and a
3//! prefetching `BufferedSource` wrapper.
4//!
5//! `SourceRegistry`, the typed source traits ([`BytesSource`],
6//! [`PacketSource`], [`FrameSource`]), and the [`SourceOutput`] enum
7//! live in `oxideav-core`. This crate retains the concrete drivers and
8//! the `BufferedSource` helper that `oxideav-http` and the player rely
9//! on; it also exposes a [`with_defaults`] free function that
10//! pre-populates a registry with the bundled drivers, matching the
11//! historical surface.
12//!
13//! ```no_run
14//! let reg = oxideav_source::with_defaults();
15//! let _input = reg.open("/tmp/video.mp4").unwrap();
16//! ```
17//!
18//! ## Schemes
19//!
20//! - **`file://<path>`** and bare paths — local filesystem. Default
21//! opener is unscoped; install a [`FileScope`] via
22//! [`FileScope::register_into`] to restrict by directory allow-list.
23//! - **`mem://<id>`** — process-global in-memory buffer; register a
24//! payload with [`mem::put`].
25//! - **`data:[<mediatype>][;base64],<bytes>`** — RFC 2397 inline byte
26//! literals; payload is decoded directly from the URI with no
27//! filesystem access.
28//! - **`concat:<a>|<b>|…`** — concatenate several `file://` segments into
29//! one seekable byte stream (de-facto `concat:` shape; no on-wire
30//! spec).
31//! - **`slice:<offset>+<length>!<inner-uri>`** — URI-level windowed view
32//! over an inner `file://` / `mem://` / `data:` / `slice:` source.
33//! Pipelines can address a byte-range sub-stream without first
34//! materialising the inner source.
35
36pub use oxideav_core::{
37 BytesSource, FrameSource, PacketSource, ReadSeek, SourceOutput, SourceRegistry,
38};
39
40mod buffered;
41mod concat;
42pub mod data;
43mod file;
44pub mod mem;
45mod scope;
46mod slice;
47mod sub;
48mod uri;
49
50pub use buffered::{
51 BufferedSource, BufferedSourceBuilder, DEFAULT_BLOCK, DEFAULT_LOOKBACK_DEN,
52 DEFAULT_LOOKBACK_NUM, DEFAULT_PREFETCH_TIMEOUT,
53};
54pub use concat::open_concat;
55pub use data::{open_data, parse as parse_data_uri, DataUri};
56pub use file::open_file;
57pub use mem::open_mem;
58pub use scope::{open_file_scoped, FileScope};
59pub use slice::open_slice;
60pub use sub::{stream_len, SubSource};
61
62/// Build a [`SourceRegistry`] pre-populated with the built-in `file`,
63/// `mem`, `data`, `concat`, and `slice` drivers. Bare paths (without a
64/// scheme) dispatch to the `file` driver via the registry's fall-back
65/// behaviour.
66pub fn with_defaults() -> SourceRegistry {
67 let mut r = SourceRegistry::new();
68 r.register_bytes("file", open_file);
69 r.register_bytes("mem", open_mem);
70 r.register_bytes("data", open_data);
71 r.register_bytes("concat", open_concat);
72 r.register_bytes("slice", open_slice);
73 r
74}
75
76/// Install the bundled source drivers (`file://`, bare paths, `mem://`,
77/// `data:`, `concat:`, `slice:`) into the given runtime context.
78/// Idempotent — replacing any prior registration of those schemes.
79pub fn register(ctx: &mut oxideav_core::RuntimeContext) {
80 ctx.sources.register_bytes("file", open_file);
81 ctx.sources.register_bytes("mem", open_mem);
82 ctx.sources.register_bytes("data", open_data);
83 ctx.sources.register_bytes("concat", open_concat);
84 ctx.sources.register_bytes("slice", open_slice);
85}
86
87oxideav_core::register!("source", register);