1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//! Playing media: playback sessions and range reads.
//!
//! `StartPlayback` (an RPC) plans the item and returns a
//! [`PlaybackHandle`]. The client then reads the file in ranges, each on its
//! own [`crate::streams::bi::RESOURCE`] stream, wrapped with the playback
//! revision in [`crate::resource::ResourceRequest`]. These media structs
//! describe the request and SDK result; the resource header announces the
//! raw body length. Several reads may be in flight at once. End of file is
//! `offset + sent == size`; a read at or past the end has `sent = 0`.
use std::fmt;
use serde::{Deserialize, Serialize};
use crate::messages::{Error, SessionId};
/// The largest range one read returns. A reply shorter than asked is
/// normal: the client asks again from where it stopped.
pub const MAX_READ: u64 = 16 << 20;
/// A playback session on the server: one planned file, bound to the
/// session and endpoint that started it. Opaque to the client.
#[derive(Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(transparent)]
pub struct PlaybackHandle(pub String);
impl fmt::Debug for PlaybackHandle {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Not a credential on its own (it is bound to a session and an
// endpoint), but there is no reason to log it.
f.write_str("PlaybackHandle(<redacted>)")
}
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MediaRead {
pub session: SessionId,
pub handle: PlaybackHandle,
pub offset: u64,
/// Capped at [`MAX_READ`].
pub length: u64,
/// The encode this read is for: byte offsets mean nothing
/// across a restart. 0 for direct play and a playback's first encode.
pub epoch: u32,
/// An HLS segment to read in, 0 being the init segment; `None`
/// reads the file itself (direct play) or the progressive output.
#[serde(deserialize_with = "spoolframe_types::required::option")]
pub segment: Option<u32>,
/// For HLS, the variant the segment is of: a ladder's rung,
/// as `v{n}/` in its playlist. 0 for one encode, and for anything
/// that is not a segment.
pub variant: u32,
}
/// What follows on the stream. Every field is required.
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct MediaReadReply {
/// How many bytes follow this frame.
pub sent: u64,
/// The size of the whole file, or of what an encode has written so
/// far (see `complete`).
pub size: u64,
/// `size` is final: always for direct play, once the encode has ended
/// for a converted playback. The end is `complete` and `offset + sent
/// == size`.
pub complete: bool,
/// The encode the bytes are from.
pub epoch: u32,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum MediaReadResponse {
Ok(MediaReadReply),
Err(Error),
}