@@ -2059,10 +2059,11 @@ fn read_tkhd<T: Read>(src: &mut BMFFBox<T>) -> Result<TrackHeaderBox> {
2059
2059
}
2060
2060
2061
2061
/// Parse a elst box.
2062
+ /// See ISO 14496-12:2015 § 8.6.6
2062
2063
fn read_elst < T : Read > ( src : & mut BMFFBox < T > ) -> Result < EditListBox > {
2063
2064
let ( version, _) = read_fullbox_extra ( src) ?;
2064
2065
let edit_count = be_u32_with_limit ( src) ?;
2065
- let mut edits = TryVec :: new ( ) ;
2066
+ let mut edits = TryVec :: with_capacity ( edit_count . to_usize ( ) ) ? ;
2066
2067
for _ in 0 ..edit_count {
2067
2068
let ( segment_duration, media_time) = match version {
2068
2069
1 => {
@@ -2134,10 +2135,11 @@ fn read_mdhd<T: Read>(src: &mut BMFFBox<T>) -> Result<MediaHeaderBox> {
2134
2135
}
2135
2136
2136
2137
/// Parse a stco box.
2138
+ /// See ISO 14496-12:2015 § 8.7.5
2137
2139
fn read_stco < T : Read > ( src : & mut BMFFBox < T > ) -> Result < ChunkOffsetBox > {
2138
2140
let ( _, _) = read_fullbox_extra ( src) ?;
2139
2141
let offset_count = be_u32_with_limit ( src) ?;
2140
- let mut offsets = TryVec :: new ( ) ;
2142
+ let mut offsets = TryVec :: with_capacity ( offset_count . to_usize ( ) ) ? ;
2141
2143
for _ in 0 ..offset_count {
2142
2144
offsets. push ( be_u32 ( src) ?. into ( ) ) ?;
2143
2145
}
@@ -2149,10 +2151,11 @@ fn read_stco<T: Read>(src: &mut BMFFBox<T>) -> Result<ChunkOffsetBox> {
2149
2151
}
2150
2152
2151
2153
/// Parse a co64 box.
2154
+ /// See ISO 14496-12:2015 § 8.7.5
2152
2155
fn read_co64 < T : Read > ( src : & mut BMFFBox < T > ) -> Result < ChunkOffsetBox > {
2153
2156
let ( _, _) = read_fullbox_extra ( src) ?;
2154
2157
let offset_count = be_u32_with_limit ( src) ?;
2155
- let mut offsets = TryVec :: new ( ) ;
2158
+ let mut offsets = TryVec :: with_capacity ( offset_count . to_usize ( ) ) ? ;
2156
2159
for _ in 0 ..offset_count {
2157
2160
offsets. push ( be_u64 ( src) ?) ?;
2158
2161
}
@@ -2164,10 +2167,11 @@ fn read_co64<T: Read>(src: &mut BMFFBox<T>) -> Result<ChunkOffsetBox> {
2164
2167
}
2165
2168
2166
2169
/// Parse a stss box.
2170
+ /// See ISO 14496-12:2015 § 8.6.2
2167
2171
fn read_stss < T : Read > ( src : & mut BMFFBox < T > ) -> Result < SyncSampleBox > {
2168
2172
let ( _, _) = read_fullbox_extra ( src) ?;
2169
2173
let sample_count = be_u32_with_limit ( src) ?;
2170
- let mut samples = TryVec :: new ( ) ;
2174
+ let mut samples = TryVec :: with_capacity ( sample_count . to_usize ( ) ) ? ;
2171
2175
for _ in 0 ..sample_count {
2172
2176
samples. push ( be_u32 ( src) ?) ?;
2173
2177
}
@@ -2179,10 +2183,11 @@ fn read_stss<T: Read>(src: &mut BMFFBox<T>) -> Result<SyncSampleBox> {
2179
2183
}
2180
2184
2181
2185
/// Parse a stsc box.
2186
+ /// See ISO 14496-12:2015 § 8.7.4
2182
2187
fn read_stsc < T : Read > ( src : & mut BMFFBox < T > ) -> Result < SampleToChunkBox > {
2183
2188
let ( _, _) = read_fullbox_extra ( src) ?;
2184
2189
let sample_count = be_u32_with_limit ( src) ?;
2185
- let mut samples = TryVec :: new ( ) ;
2190
+ let mut samples = TryVec :: with_capacity ( sample_count . to_usize ( ) ) ? ;
2186
2191
for _ in 0 ..sample_count {
2187
2192
let first_chunk = be_u32 ( src) ?;
2188
2193
let samples_per_chunk = be_u32_with_limit ( src) ?;
@@ -2200,16 +2205,23 @@ fn read_stsc<T: Read>(src: &mut BMFFBox<T>) -> Result<SampleToChunkBox> {
2200
2205
Ok ( SampleToChunkBox { samples } )
2201
2206
}
2202
2207
2208
+ /// Parse a Composition Time to Sample Box
2209
+ /// See ISO 14496-12:2015 § 8.6.1.3
2203
2210
fn read_ctts < T : Read > ( src : & mut BMFFBox < T > ) -> Result < CompositionOffsetBox > {
2204
2211
let ( version, _) = read_fullbox_extra ( src) ?;
2205
2212
2206
- let counts = u64 :: from ( be_u32_with_limit ( src) ?) ;
2213
+ let counts = be_u32_with_limit ( src) ?;
2207
2214
2208
- if src. bytes_left ( ) < counts. checked_mul ( 8 ) . expect ( "counts -> bytes overflow" ) {
2215
+ if src. bytes_left ( )
2216
+ < counts
2217
+ . checked_mul ( 8 )
2218
+ . expect ( "counts -> bytes overflow" )
2219
+ . into ( )
2220
+ {
2209
2221
return Err ( Error :: InvalidData ( "insufficient data in 'ctts' box" ) ) ;
2210
2222
}
2211
2223
2212
- let mut offsets = TryVec :: new ( ) ;
2224
+ let mut offsets = TryVec :: with_capacity ( counts . to_usize ( ) ) ? ;
2213
2225
for _ in 0 ..counts {
2214
2226
let ( sample_count, time_offset) = match version {
2215
2227
// According to spec, Version0 shoule be used when version == 0;
@@ -2236,12 +2248,14 @@ fn read_ctts<T: Read>(src: &mut BMFFBox<T>) -> Result<CompositionOffsetBox> {
2236
2248
}
2237
2249
2238
2250
/// Parse a stsz box.
2251
+ /// See ISO 14496-12:2015 § 8.7.3.2
2239
2252
fn read_stsz < T : Read > ( src : & mut BMFFBox < T > ) -> Result < SampleSizeBox > {
2240
2253
let ( _, _) = read_fullbox_extra ( src) ?;
2241
2254
let sample_size = be_u32 ( src) ?;
2242
2255
let sample_count = be_u32_with_limit ( src) ?;
2243
2256
let mut sample_sizes = TryVec :: new ( ) ;
2244
2257
if sample_size == 0 {
2258
+ sample_sizes. reserve ( sample_count. to_usize ( ) ) ?;
2245
2259
for _ in 0 ..sample_count {
2246
2260
sample_sizes. push ( be_u32 ( src) ?) ?;
2247
2261
}
@@ -2257,10 +2271,11 @@ fn read_stsz<T: Read>(src: &mut BMFFBox<T>) -> Result<SampleSizeBox> {
2257
2271
}
2258
2272
2259
2273
/// Parse a stts box.
2274
+ /// See ISO 14496-12:2015 § 8.6.1.2
2260
2275
fn read_stts < T : Read > ( src : & mut BMFFBox < T > ) -> Result < TimeToSampleBox > {
2261
2276
let ( _, _) = read_fullbox_extra ( src) ?;
2262
2277
let sample_count = be_u32_with_limit ( src) ?;
2263
- let mut samples = TryVec :: new ( ) ;
2278
+ let mut samples = TryVec :: with_capacity ( sample_count . to_usize ( ) ) ? ;
2264
2279
for _ in 0 ..sample_count {
2265
2280
let sample_count = be_u32_with_limit ( src) ?;
2266
2281
let sample_delta = be_u32 ( src) ?;
@@ -2715,6 +2730,7 @@ fn read_esds<T: Read>(src: &mut BMFFBox<T>) -> Result<ES_Descriptor> {
2715
2730
}
2716
2731
2717
2732
/// Parse `FLACSpecificBox`.
2733
+ /// See https://github.com/xiph/flac/blob/master/doc/isoflac.txt § 3.3.2
2718
2734
fn read_dfla < T : Read > ( src : & mut BMFFBox < T > ) -> Result < FLACSpecificBox > {
2719
2735
let ( version, flags) = read_fullbox_extra ( src) ?;
2720
2736
if version != 0 {
0 commit comments