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 Unknown = 0,
13 LeadingWithDependency = 1,
15 NotLeading = 2,
17 LeadingWithoutDependency = 3,
19}
20
21#[repr(u8)]
22pub enum SampleDependsOn {
23 Unknown = 0,
25 DependsOn = 1,
27 DoesntDependOn = 2,
29 Reserved = 3,
30}
31
32#[repr(u8)]
33pub enum SampleIsDependedOn {
34 Unknown = 0,
36 DependedOn = 1,
38 NotDependedOn = 2,
40 Reserved = 3,
41}
42
43#[repr(u8)]
44pub enum SampleHasRedundancy {
45 Unknown = 0,
47 Redundant = 1,
49 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}