forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

io.rs50 lines, 1.4 KiBHistoryRawDownload
1//! The source a reader reads from.
2
3use std::io::{Read, Seek};
4
5/// Anything a reader can be built over: seekable, readable, and movable to the
6/// thread that will do the reading.
7pub trait MediaSource: Read + Seek + Send {}
8
9impl<T: Read + Seek + Send> MediaSource for T {}
10
11/// Options a stream is built with; nothing here has any.
12#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
13pub struct MediaSourceStreamOptions {
14 /// Buffer size a caller would like. This shim buffers in the demuxers
15 /// themselves, so it is advisory.
16 pub buffer_len: usize,
17}
18
19/// A source with a buffer in front of it.
20pub struct MediaSourceStream {
21 inner: Box<dyn MediaSource>,
22}
23
24impl MediaSourceStream {
25 /// Wrap a source.
26 pub fn new(
27 source: Box<dyn MediaSource>,
28 _options: MediaSourceStreamOptions,
29 ) -> MediaSourceStream {
30 MediaSourceStream { inner: source }
31 }
32
33 /// Take the source back out, which is how a reader in this family is
34 /// handed the file it will read.
35 pub fn into_inner(self) -> Box<dyn MediaSource> {
36 self.inner
37 }
38}
39
40impl Read for MediaSourceStream {
41 fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
42 self.inner.read(buf)
43 }
44}
45
46impl Seek for MediaSourceStream {
47 fn seek(&mut self, pos: std::io::SeekFrom) -> std::io::Result<u64> {
48 self.inner.seek(pos)
49 }
50}