smooth_runtime/client/action.rs
1//! What the engine asks its host to fetch, and how a host reports a failed fetch.
2
3use url::Url;
4
5/// Identifies one outstanding fetch; echoed back in `on_*` calls.
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
7pub struct RequestId(pub u64);
8
9/// Identifies a selected stream by its position in the session's stream order,
10/// stable for the session. Track `n + 1` carries stream `n`'s samples.
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
12pub struct StreamId(pub usize);
13
14/// One GET the host must perform.
15#[derive(Debug, Clone, PartialEq, Eq)]
16#[non_exhaustive]
17pub enum Action {
18 /// GET the client manifest (MS-SSTR §2.2.2).
19 FetchManifest {
20 /// The id to echo back.
21 id: RequestId,
22 /// Absolute manifest URL.
23 url: Url,
24 },
25 /// GET one fragment (MS-SSTR §2.2.4).
26 FetchFragment {
27 /// The id to echo back.
28 id: RequestId,
29 /// The stream the fragment belongs to.
30 stream: StreamId,
31 /// Fragment start time, in the stream's timescale.
32 start: u64,
33 /// Fragment duration, in the stream's timescale.
34 duration: u64,
35 /// Absolute fragment URL.
36 url: Url,
37 },
38}
39
40/// A fetch that produced no usable body.
41#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
42pub struct FetchFailure {
43 /// The HTTP status when the server answered with a non-success one; `None`
44 /// for a transport error or a timeout.
45 pub status: Option<u16>,
46 /// The wait the server asked for with `Retry-After` (RFC 9110 §10.2.3), in
47 /// microseconds; `0` when it asked for none. The retry waits at least this
48 /// long, never less than the configured backoff.
49 pub retry_after_us: u64,
50}
51
52impl FetchFailure {
53 /// The HTTP statuses that say a resource is not (yet) there.
54 pub(crate) fn is_not_found(self) -> bool {
55 matches!(self.status, Some(NOT_FOUND | GONE))
56 }
57}
58
59pub(crate) const NOT_FOUND: u16 = 404;
60pub(crate) const GONE: u16 = 410;