1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
//! Source of [bento4](https://github.com/axiomatic-systems/Bento4) and logic to build it.
//! See this [file](https://github.com/clitic/vsd/blob/main/mp4decrypt/build.rs) for example usage.

pub use cc;

use std::{env, path::PathBuf};

pub fn version() -> String {
    "1.6.0-640".to_owned()
}

pub fn includes() -> Vec<PathBuf> {
    let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    vec![
        root.join("Bento4/Source/C++/Core"),
        root.join("Bento4/Source/C++/Codecs"),
        root.join("Bento4/Source/C++/Crypto"),
        root.join("Bento4/Source/C++/MetaData"),
    ]
}

pub fn build() {
    let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
    println!(
        "cargo:rerun-if-changed={}",
        root.join("Bento4").to_string_lossy()
    );

    cc::Build::new()
        .cpp(true)
        .warnings(false)
        .extra_warnings(false)
        .includes(includes())
        .files([
            root.join("Bento4/Source/C++/Codecs/Ap4Ac3Parser.cpp"),
            root.join("Bento4/Source/C++/Codecs/Ap4Ac4Parser.cpp"),
            root.join("Bento4/Source/C++/Codecs/Ap4AdtsParser.cpp"),
            root.join("Bento4/Source/C++/Codecs/Ap4AvcParser.cpp"),
            root.join("Bento4/Source/C++/Codecs/Ap4BitStream.cpp"),
            root.join("Bento4/Source/C++/Codecs/Ap4Eac3Parser.cpp"),
            root.join("Bento4/Source/C++/Codecs/Ap4HevcParser.cpp"),
            root.join("Bento4/Source/C++/Codecs/Ap4Mp4AudioInfo.cpp"),
            root.join("Bento4/Source/C++/Codecs/Ap4NalParser.cpp"),
        ])
        .files([
            root.join("Bento4/Source/C++/Core/Ap4.cpp"),
            root.join("Bento4/Source/C++/Core/Ap48bdlAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Ac4Utils.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4AinfAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Atom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4AtomFactory.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4AtomSampleTable.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Av1cAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4AvccAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4BlocAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4ByteStream.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Co64Atom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Command.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4CommandFactory.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4CommonEncryption.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4ContainerAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4CttsAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Dac3Atom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Dac4Atom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4DataBuffer.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Debug.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Dec3Atom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4DecoderConfigDescriptor.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4DecoderSpecificInfoDescriptor.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Descriptor.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4DescriptorFactory.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4DrefAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4DvccAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4ElstAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4EsDescriptor.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4EsdsAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Expandable.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4File.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4FileCopier.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4FileWriter.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4FragmentSampleTable.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4FrmaAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4FtypAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4GrpiAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4HdlrAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4HintTrackReader.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4HmhdAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4HvccAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4IkmsAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4IodsAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Ipmp.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4IproAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4IsfmAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4IsltAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4IsmaCryp.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4LinearReader.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Marlin.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4MdhdAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4MehdAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4MfhdAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4MfroAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4MoovAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Movie.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4MovieFragment.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Mpeg2Ts.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4MvhdAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4NmhdAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4ObjectDescriptor.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4OdafAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4OddaAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4OdheAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4OhdrAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4OmaDcf.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4PdinAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Piff.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Processor.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Protection.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4PsshAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Results.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4RtpAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4RtpHint.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SaioAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SaizAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Sample.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SampleDescription.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SampleEntry.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SampleSource.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SampleTable.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SbgpAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SchmAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SdpAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SegmentBuilder.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SencAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SgpdAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SidxAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SLConfigDescriptor.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SmhdAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4StcoAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SthdAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4String.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4StscAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4StsdAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4StssAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4StszAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SttsAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Stz2Atom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4SyntheticSampleTable.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4TencAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4TfdtAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4TfhdAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4TfraAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4TimsAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4TkhdAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Track.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4TrakAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4TrefTypeAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4TrexAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4TrunAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4UrlAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4Utils.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4UuidAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4VmhdAtom.cpp"),
            root.join("Bento4/Source/C++/Core/Ap4VpccAtom.cpp"),
        ])
        .files([
            root.join("Bento4/Source/C++/Crypto/Ap4AesBlockCipher.cpp"),
            root.join("Bento4/Source/C++/Crypto/Ap4Hmac.cpp"),
            root.join("Bento4/Source/C++/Crypto/Ap4KeyWrap.cpp"),
            root.join("Bento4/Source/C++/Crypto/Ap4StreamCipher.cpp"),
        ])
        .file(root.join("Bento4/Source/C++/MetaData/Ap4MetaData.cpp"))
        .file(root.join("Bento4/Source/C++/System/StdC/Ap4StdCFileByteStream.cpp"))
        .file(
            if env::var("CARGO_CFG_TARGET_OS")
                .expect("CARGO_CFG_TARGET_OS env variable not set by cargo?")
                == "windows"
            {
                root.join("Bento4/Source/C++/System/Win32/Ap4Win32Random.cpp")
            } else {
                root.join("Bento4/Source/C++/System/Posix/Ap4PosixRandom.cpp")
            },
        )
        .out_dir(
            env::var("OUT_DIR")
                .map(|x| PathBuf::from(x).join("bento4"))
                .expect("OUT_DIR env variable not set by cargo?"),
        )
        .compile("ap4");
}