scuffle_mp4/
boxes.rs

1//! ISO base media file format boxes for MP4.
2//!
3//! ISO/IEC 14496-14 - 6
4
5use isobmff::boxes::{AudioSampleEntry, SampleEntry, VisualSampleEntry};
6use isobmff::{FullBoxHeader, IsoBox};
7use scuffle_bytes_util::BytesCow;
8use scuffle_bytes_util::zero_copy::U24Be;
9
10use crate::object_description::ESDescriptor;
11
12/// Object Descriptor Box
13///
14/// ISO/IEC 14496-14 - 6.2
15#[derive(IsoBox, Debug, PartialEq, Eq)]
16#[iso_box(box_type = b"iods")]
17pub struct ObjectDescriptorBox<'a> {
18    /// The full header of the box
19    pub header: FullBoxHeader,
20    /// The object descriptor contained in this box.
21    ///
22    /// Defined in ISO/IEC 14496-1.
23    pub od: BytesCow<'a>,
24}
25
26// TODO: Mpeg4MediaHeaderBox ISO/IEC 14496-14 - 6.6
27
28/// MP4 visual sample description box
29///
30/// ISO/IEC 14496-14 - 6.7
31#[derive(IsoBox, Debug, PartialEq, Eq)]
32#[iso_box(box_type = b"mp4v")]
33pub struct MP4VisualSampleEntry<'a> {
34    /// The visual sample entry fields that this box inherits.
35    pub sample_entry: VisualSampleEntry,
36    /// The ES Descriptor for this stream.
37    #[iso_box(nested_box)]
38    pub es: ESDBox<'a>,
39}
40
41/// MP4 audio sample description box
42///
43/// ISO/IEC 14496-14 - 6.7
44#[derive(IsoBox, Debug, PartialEq, Eq)]
45#[iso_box(box_type = b"mp4a")]
46pub struct MP4AudioSampleEntry<'a> {
47    /// The audio sample entry fields that this box inherits.
48    pub sample_entry: AudioSampleEntry,
49    /// The ES Descriptor for this stream.
50    #[iso_box(nested_box)]
51    pub es: ESDBox<'a>,
52}
53
54/// Mpeg sample description box
55///
56/// ISO/IEC 14496-14 - 6.7
57#[derive(IsoBox, Debug, PartialEq, Eq)]
58#[iso_box(box_type = b"mp4s")]
59pub struct MpegSampleEntry<'a> {
60    /// The sample entry fields that this box inherits.
61    pub sample_entry: SampleEntry,
62    /// The ES Descriptor for this stream.
63    #[iso_box(nested_box)]
64    pub es: ESDBox<'a>,
65}
66
67/// MP4 audio enhancement sample description box
68///
69/// ISO/IEC 14496-14 - 6.7
70#[derive(IsoBox, Debug, PartialEq, Eq)]
71#[iso_box(box_type = b"m4ae")]
72pub struct MP4AudioEnhancementSampleEntry<'a> {
73    /// The audio sample entry fields that this box inherits.
74    pub sample_entry: AudioSampleEntry,
75    /// The ES Descriptor for this stream.
76    #[iso_box(nested_box)]
77    pub es: ESDBox<'a>,
78}
79
80/// Elementary Stream Descriptor Box
81///
82/// ISO/IEC 14496-14 - 6.7
83#[derive(IsoBox, Debug, PartialEq, Eq)]
84#[iso_box(box_type = b"esds")]
85pub struct ESDBox<'a> {
86    /// The full header of the box
87    pub header: FullBoxHeader,
88    /// The ES Descriptor for this stream.
89    ///
90    /// Defined in ISO/IEC 14496-1.
91    pub es: ESDescriptor<'a>,
92}
93
94impl<'a> ESDBox<'a> {
95    /// Creates a new ESDBox with the given ES descriptor.
96    pub fn new(es: ESDescriptor<'a>) -> Self {
97        Self {
98            header: FullBoxHeader {
99                version: 0,
100                flags: U24Be(0),
101            },
102            es,
103        }
104    }
105}