forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

packet.rs44 lines, 1.2 KiBHistoryRawDownload
1//! One packet of coded bytes.
2
3use crate::units::{Duration, Timestamp};
4
5/// A packet as a reader hands it out.
6#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct Packet {
8 /// Track this packet belongs to.
9 pub track_id: u32,
10 /// Presentation timestamp, in the track's own time base.
11 pub pts: Timestamp,
12 /// How long it plays for.
13 pub dur: Duration,
14 /// The coded bytes.
15 pub data: Box<[u8]>,
16 /// The container's own end-of-packet position, in the track's time base,
17 /// when it states one — an Ogg page's granule above all, which is the
18 /// only way a Vorbis (or FLAC-in-Ogg) stream's true, un-rounded length
19 /// ever reaches the decoder: the codec's own bitstream never states it.
20 pub granule: Option<i64>,
21}
22
23impl Packet {
24 /// A packet over `data`.
25 pub fn new(track_id: u32, pts: Timestamp, dur: Duration, data: &[u8]) -> Packet {
26 Packet {
27 track_id,
28 pts,
29 dur,
30 data: data.to_vec().into_boxed_slice(),
31 granule: None,
32 }
33 }
34
35 /// The presentation timestamp.
36 pub fn pts(&self) -> Timestamp {
37 self.pts
38 }
39
40 /// The coded bytes.
41 pub fn buf(&self) -> &[u8] {
42 &self.data
43 }
44}