Skip to main content

moq_audio/
frame.rs

1use bytes::Bytes;
2use moq_net::Timestamp;
3
4use crate::Activity;
5
6/// One unit of raw PCM crossing the codec boundary: what
7/// [`encode::Producer::write`](crate::encode::Producer::write) takes and what
8/// [`decode::Consumer::read`](crate::decode::Consumer::read) returns.
9///
10/// Just a payload, a presentation timestamp, and whether the packet these
11/// samples came from coded any audio. PCM layout (format / sample rate / channel count)
12/// is fixed by the producer or consumer at construction time, never per frame,
13/// so callers can't accidentally drift the format mid-stream.
14///
15/// `#[non_exhaustive]`: construct input with [`Frame::new`] so the record can
16/// gain metadata without breaking callers.
17#[derive(Clone, Debug)]
18#[non_exhaustive]
19pub struct Frame {
20	/// Presentation timestamp of the first sample.
21	pub timestamp: Timestamp,
22	/// The samples, in the layout the producer or consumer was built with.
23	pub data: Bytes,
24	/// Whether the packet these samples came out of coded audio, or none at all.
25	/// Set on the way out of [`decode`](crate::decode) and ignored on the way
26	/// into [`encode`](crate::encode), which classifies what it encodes rather
27	/// than what it was told.
28	pub activity: Activity,
29}
30
31impl Frame {
32	/// PCM shown at `timestamp`, classified [`Activity::Active`].
33	pub fn new(data: Bytes, timestamp: Timestamp) -> Self {
34		Self {
35			timestamp,
36			data,
37			activity: Activity::Active,
38		}
39	}
40}