Skip to main content

moq_video/encode/
encoded.rs

1//! [`Encoded`]: one encoded access unit on its way to a track.
2
3use bytes::Bytes;
4use moq_net::Timestamp;
5
6/// One encoded video frame: a whole access unit in the codec's wire framing
7/// (Annex-B with in-band parameter sets), plus the presentation time of the raw
8/// [`Frame`](crate::Frame) it came from.
9///
10/// Named for what it holds rather than mirroring [`Frame`](crate::Frame), so the
11/// two never read alike at a call site that handles both.
12///
13/// The encoder carries the timestamp through the codec rather than leaving the
14/// caller to guess one at publish time, so a backend that buffers a frame or
15/// drains a tail on [`Encoder::flush`](super::Encoder::flush) still stamps
16/// each access unit with the time of the picture it encoded.
17#[derive(Clone, Debug)]
18#[non_exhaustive]
19pub struct Encoded {
20	/// Presentation timestamp, from the raw frame this was encoded from.
21	pub timestamp: Timestamp,
22	/// The access unit, in the framing the matching catalog importer expects.
23	pub payload: Bytes,
24	/// Whether this access unit is a keyframe, one a decoder can start from.
25	///
26	/// Set on every keyframe, whether [`Encoder::cut`](super::Encoder::cut) forced
27	/// it or the encoder placed it on its own [`Config::join`](super::Config::join) cadence.
28	pub keyframe: bool,
29}
30
31impl Encoded {
32	/// An encoded access unit shown at `timestamp`, and whether it is a keyframe.
33	pub fn new(timestamp: Timestamp, payload: Bytes, keyframe: bool) -> Self {
34		Self {
35			timestamp,
36			payload,
37			keyframe,
38		}
39	}
40}