ff_sys/io_traits.rs
1//! The Rust side of a custom `AVIOContext`: what a caller may hand FFmpeg as a
2//! byte source or sink.
3//!
4//! Both traits are blanket-implemented, so a caller passes a plain
5//! `std::io::Cursor`, `File`, or anything else meeting the bounds; they exist
6//! only so the boxed form has a name to be stored under.
7//!
8//! `Seek` is required rather than optional. FFmpeg accepts a null seek callback,
9//! but a demuxer that cannot seek behaves differently enough (probing, and the
10//! containers it can open at all) that supporting it is its own piece of work.
11//!
12//! `Send` is required because [`InputFormatContext`](crate::InputFormatContext)
13//! and [`OutputFormatContext`](crate::OutputFormatContext) are `Send`: the source
14//! travels with the context it is attached to.
15
16use std::io::{Read, Seek, Write};
17
18/// A byte source FFmpeg can demux from.
19pub trait IoSource: Read + Seek + Send {}
20
21impl<T: Read + Seek + Send> IoSource for T {}
22
23/// A byte sink FFmpeg can mux into.
24pub trait IoSink: Write + Seek + Send {}
25
26impl<T: Write + Seek + Send> IoSink for T {}