pub struct Frame {
pub timestamp: Timestamp,
pub payload: Bytes,
}Expand description
A media frame with a timestamp and codec-specific payload.
Frames are the fundamental unit of media data in hang. Each frame contains:
- A timestamp when they should be rendered.
- A codec-specific payload.
Fields§
§timestamp: TimestampThe presentation timestamp for this frame.
This indicates when the frame should be displayed relative to the start of the stream or some other reference point. This is NOT a wall clock time.
payload: BytesThe encoded media data for this frame.
The format depends on the codec being used (H.264, AV1, Opus, etc.). The debug implementation shows only the payload length for brevity.
Implementations§
Source§impl Frame
impl Frame
Sourcepub fn encode(&self, buf: &mut impl BufMut) -> Result<(), Error>
pub fn encode(&self, buf: &mut impl BufMut) -> Result<(), Error>
Encode the frame: varint timestamp prefix followed by the raw codec payload.
The timestamp is normalized to TIMESCALE (microseconds) so peers using a
different source scale (e.g. nanoseconds from MKV) can decode without knowing
the producer’s internal scale. Inverse of Self::decode.
Sourcepub fn decode(buf: impl Buf) -> Result<Self, Error>
pub fn decode(buf: impl Buf) -> Result<Self, Error>
Decode a frame from raw bytes (varint timestamp prefix + payload).
Attaches TIMESCALE (microseconds) to the decoded timestamp, matching what
Self::encode writes. Inverse of Self::encode.
Sourcepub fn write_to(&self, group: &mut Producer) -> Result<(), Error>
pub fn write_to(&self, group: &mut Producer) -> Result<(), Error>
Write the frame to group as a single moq-lite frame, in the Self::encode format.
Prefer this over Self::encode when writing to a group: it stamps the moq-net frame
timestamp so moq-lite-05 and later can delta-encode it on the wire independently of the
container-level prefix.