creek_core/read/
mod.rs

1mod data;
2mod decoder;
3mod read_stream;
4mod server;
5
6pub mod error;
7
8pub use data::{DataBlock, ReadData};
9pub use decoder::Decoder;
10pub use error::{FatalReadError, ReadError};
11pub use read_stream::{ReadDiskStream, SeekMode};
12
13use data::{DataBlockCache, HeapData};
14use server::ReadServer;
15
16pub(crate) enum ServerToClientMsg<D: Decoder> {
17    ReadIntoBlockRes {
18        block_index: usize,
19        block: DataBlock<D::T>,
20        wanted_start_frame: usize,
21    },
22    CacheRes {
23        cache_index: usize,
24        cache: DataBlockCache<D::T>,
25        wanted_start_frame: usize,
26    },
27    FatalError(D::FatalError),
28}
29
30pub(crate) enum ClientToServerMsg<D: Decoder> {
31    ReadIntoBlock {
32        block_index: usize,
33        block: Option<DataBlock<D::T>>,
34        start_frame: usize,
35    },
36    DisposeBlock {
37        block: DataBlock<D::T>,
38    },
39    SeekTo {
40        frame: usize,
41    },
42    Cache {
43        cache_index: usize,
44        cache: Option<DataBlockCache<D::T>>,
45        start_frame: usize,
46    },
47    DisposeCache {
48        cache: DataBlockCache<D::T>,
49    },
50}
51
52/// Options for a read stream.
53#[derive(Debug, Clone, Copy)]
54pub struct ReadStreamOptions<D: Decoder> {
55    /// The number of prefetch blocks in a cache block. This will cause a cache to be
56    /// used whenever the stream is seeked to a frame in the range:
57    ///
58    /// `[cache_start, cache_start + (num_cache_blocks * block_size))`
59    ///
60    /// If this is 0, then the cache is only used when seeked to exactly `cache_start`.
61    pub num_cache_blocks: usize,
62
63    /// The maximum number of caches that can be active in this stream. Keep in mind each
64    /// cache uses some memory (but memory is only allocated when the cache is created).
65    ///
66    /// The default is `1`.
67    pub num_caches: usize,
68
69    /// Any additional decoder-specific options.
70    pub additional_opts: D::AdditionalOpts,
71
72    /// The number of prefetch blocks to store ahead of the cache block. This must be
73    /// sufficiently large to ensure enough to time to fill the buffer in the worst
74    /// case latency scenario.
75    ///
76    /// This should be left alone unless you know what you are doing.
77    pub num_look_ahead_blocks: usize,
78
79    /// The number of frames in a prefetch block.
80    ///
81    /// This should be left alone unless you know what you are doing.
82    pub block_size: usize,
83
84    /// The size of the realtime ring buffer that sends data to and from the stream the the
85    /// internal IO server. This must be sufficiently large enough to avoid stalling the channels.
86    ///
87    /// Set this to `None` to automatically find a generous size based on the other read options.
88    /// This should be left as `None` unless you know what you are doing.
89    ///
90    /// The default is `None`.
91    pub server_msg_channel_size: Option<usize>,
92}
93
94impl<D: Decoder> Default for ReadStreamOptions<D> {
95    fn default() -> Self {
96        ReadStreamOptions {
97            block_size: D::DEFAULT_BLOCK_SIZE,
98            num_cache_blocks: D::DEFAULT_NUM_CACHE_BLOCKS,
99            additional_opts: Default::default(),
100            num_look_ahead_blocks: D::DEFAULT_NUM_LOOK_AHEAD_BLOCKS,
101            num_caches: 1,
102            server_msg_channel_size: None,
103        }
104    }
105}