async_mp4/mp4box/
trex.rs

1use std::hash::{Hash, Hasher};
2use bitregions::bitregions;
3use crate::bytes_write::{Mp4Writable, WriteMp4};
4use async_trait::async_trait;
5use crate::bytes_read::{Mp4Readable, ReadMp4};
6use crate::error::MP4Error;
7use crate::full_box;
8
9#[repr(u8)]
10pub enum IsLeading {
11    /// the	leading	nature of this sample is unknown
12    Unknown = 0,
13    /// this sample is a leading sample that has a dependency before the referenced I‐picture (and is therefore	not	decodable)
14    LeadingWithDependency = 1,
15    /// this sample is not a leading sample
16    NotLeading = 2,
17    /// this sample is a leading sample that has no dependency before the referenced I‐picture (and is therefore decodable);
18    LeadingWithoutDependency = 3,
19}
20
21#[repr(u8)]
22pub enum SampleDependsOn {
23    /// the	dependency	of	this	sample	is	unknown
24    Unknown = 0,
25    /// 	 this	sample	does	depend	on	others	(not	an	I	picture)
26    DependsOn = 1,
27    ///	 this	sample	does	not	depend	on	others	(I	picture)
28    DoesntDependOn = 2,
29    Reserved = 3,
30}
31
32#[repr(u8)]
33pub enum SampleIsDependedOn {
34    /// the	dependency	of	other	samples	on	this	sample	is	unknown
35    Unknown = 0,
36    ///other	samples	may	depend	on	this	one	(not	disposable)
37    DependedOn = 1,
38    ///no	other	sample	depends	on	this	one	(disposable)
39    NotDependedOn = 2,
40    Reserved = 3,
41}
42
43#[repr(u8)]
44pub enum SampleHasRedundancy {
45    ///	 it	is	unknown	whether	there	is	redundant	coding	in	this	sample
46    Unknown = 0,
47    ///	 there	is	redundant	coding	in	this	sample
48    Redundant = 1,
49    ///	 there	is	no	redundant	coding	in	this	sample
50    NotRedundant = 2,
51    Reserved = 3,
52}
53
54bitregions! {
55    pub SampleFlags u32 {
56        IS_LEADING:                     0b0000000000000000__0_000_00_00_00_11_0000,
57        SAMPLE_DEPENDS_ON:              0b0000000000000000__0_000_00_00_11_00_0000,
58        SAMPLE_IS_DEPENDED_ON:          0b0000000000000000__0_000_00_11_00_00_0000,
59        SAMPLE_HAS_REDUNDANCY:          0b0000000000000000__0_000_11_00_00_00_0000,
60        SAMPLE_PADDING_VALUE:           0b0000000000000000__0_111_00_00_00_00_0000,
61        SAMPLE_IS_NON_SYNC_SAMPLE:      0b0000000000000000__1_000_00_00_00_00_0000,
62        SAMPLE_DEGRADATION_PRIORITY:    0b1111111111111111__0_000_00_00_00_00_0000,
63    }
64}
65
66impl Mp4Writable for SampleFlags {
67    fn byte_size(&self) -> usize {
68        self.0.byte_size()
69    }
70
71    fn write<W: WriteMp4>(&self, writer: &mut W) -> Result<usize, MP4Error> {
72        self.0.write(writer)
73    }
74}
75
76#[async_trait]
77impl Mp4Readable for SampleFlags {
78    async fn read<R: ReadMp4>(reader: &mut R) -> Result<Self, MP4Error> {
79        Ok(Self(reader.read().await?))
80    }
81}
82
83impl Eq for SampleFlags {}
84impl Hash for SampleFlags {
85    fn hash<H: Hasher>(&self, state: &mut H) {
86        self.0.hash(state)
87    }
88}
89
90full_box! {
91    box (b"trex", Trex, TrexBox, u32)
92    data {
93        track_id: u32,
94        default_sample_description_index: u32,
95        default_sample_duration: u32,
96        default_sample_size: u32,
97        default_sample_flags: SampleFlags,
98    }
99}