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#[derive(Clone, Debug)]
15pub struct Frame {
16 /// Presentation timestamp of the first sample.
17 pub timestamp: Timestamp,
18 /// The samples, in the layout the producer or consumer was built with.
19 pub data: Bytes,
20 /// Whether the packet these samples came out of coded audio, or none at all.
21 /// Set on the way out of [`decode`](crate::decode) and ignored on the way
22 /// into [`encode`](crate::encode), which classifies what it encodes rather
23 /// than what it was told.
24 pub activity: Activity,
25}
26
27impl Frame {
28 /// PCM shown at `timestamp`, classified [`Activity::Active`].
29 pub fn new(data: Bytes, timestamp: Timestamp) -> Self {
30 Self {
31 timestamp,
32 data,
33 activity: Activity::Active,
34 }
35 }
36}