@@ -299,19 +299,14 @@ impl Feature {
299
299
match self {
300
300
Self :: Auxc
301
301
| Self :: Av1c
302
+ | Self :: Avis
302
303
| Self :: Colr
303
304
| Self :: Imir
304
305
| Self :: Irot
305
306
| Self :: Ispe
306
307
| Self :: Pasp
307
308
| Self :: Pixi => true ,
308
- Self :: A1lx
309
- | Self :: A1op
310
- | Self :: Clap
311
- | Self :: Grid
312
- | Self :: Ipro
313
- | Self :: Lsel
314
- | Self :: Avis => false ,
309
+ Self :: A1lx | Self :: A1op | Self :: Clap | Self :: Grid | Self :: Ipro | Self :: Lsel => false ,
315
310
}
316
311
}
317
312
}
@@ -1100,6 +1095,29 @@ pub enum SampleEntry {
1100
1095
Unknown ,
1101
1096
}
1102
1097
1098
+ #[ derive( Debug ) ]
1099
+ pub struct TrackReferenceBox {
1100
+ pub references : TryVec < TrackReferenceEntry > ,
1101
+ }
1102
+
1103
+ impl TrackReferenceBox {
1104
+ pub fn has_auxl_reference ( & self , track_id : u32 ) -> bool {
1105
+ self . references . iter ( ) . any ( |entry| match entry {
1106
+ TrackReferenceEntry :: Auxiliary ( aux_entry) => aux_entry. track_ids . contains ( & track_id) ,
1107
+ } )
1108
+ }
1109
+ }
1110
+
1111
+ #[ derive( Debug ) ]
1112
+ pub enum TrackReferenceEntry {
1113
+ Auxiliary ( TrackReference ) ,
1114
+ }
1115
+
1116
+ #[ derive( Debug ) ]
1117
+ pub struct TrackReference {
1118
+ pub track_ids : TryVec < u32 > ,
1119
+ }
1120
+
1103
1121
/// An Elementary Stream Descriptor
1104
1122
/// See MPEG-4 Systems (ISO 14496-1:2010) § 7.2.6.5
1105
1123
#[ allow( non_camel_case_types) ]
@@ -1550,7 +1568,7 @@ impl AvifItem {
1550
1568
}
1551
1569
}
1552
1570
1553
- #[ derive( Debug ) ]
1571
+ #[ derive( Default , Debug ) ]
1554
1572
pub struct AvifContext {
1555
1573
/// Level of deviation from the specification before failing the parse
1556
1574
strictness : ParseStrictness ,
@@ -1574,13 +1592,17 @@ pub struct AvifContext {
1574
1592
/// Should probably only ever be [`AVIF_BRAND`] or [`AVIS_BRAND`], but other values
1575
1593
/// are legal as long as one of the two is the `compatible_brand` list.
1576
1594
pub major_brand : FourCC ,
1577
- /// True if a `moov` box is present
1578
- pub has_sequence : bool ,
1595
+ /// Information on the sequence contained in the image, or None if not present
1596
+ pub sequence : Option < MediaContext > ,
1579
1597
/// A collection of unsupported features encountered during the parse
1580
1598
pub unsupported_features : UnsupportedFeatures ,
1581
1599
}
1582
1600
1583
1601
impl AvifContext {
1602
+ pub fn primary_item_is_present ( & self ) -> bool {
1603
+ self . primary_item . is_some ( )
1604
+ }
1605
+
1584
1606
pub fn primary_item_coded_data ( & self ) -> Option < & [ u8 ] > {
1585
1607
self . primary_item
1586
1608
. as_ref ( )
@@ -1593,6 +1615,10 @@ impl AvifContext {
1593
1615
. map ( |item| self . image_bits_per_channel ( item. id ) )
1594
1616
}
1595
1617
1618
+ pub fn alpha_item_is_present ( & self ) -> bool {
1619
+ self . alpha_item . is_some ( )
1620
+ }
1621
+
1596
1622
pub fn alpha_item_coded_data ( & self ) -> Option < & [ u8 ] > {
1597
1623
self . alpha_item
1598
1624
. as_ref ( )
@@ -2122,6 +2148,8 @@ enum Extent {
2122
2148
pub enum TrackType {
2123
2149
Audio ,
2124
2150
Video ,
2151
+ Picture ,
2152
+ AuxiliaryVideo ,
2125
2153
Metadata ,
2126
2154
Unknown ,
2127
2155
}
@@ -2142,6 +2170,12 @@ pub enum ParseStrictness {
2142
2170
Strict , // Error on "should" directives
2143
2171
}
2144
2172
2173
+ impl Default for ParseStrictness {
2174
+ fn default ( ) -> Self {
2175
+ ParseStrictness :: Normal
2176
+ }
2177
+ }
2178
+
2145
2179
fn fail_with_status_if ( violation : bool , status : Status ) -> Result < ( ) > {
2146
2180
let error = Error :: from ( status) ;
2147
2181
if violation {
@@ -2227,6 +2261,7 @@ pub struct Track {
2227
2261
pub stco : Option < ChunkOffsetBox > , // It is for stco or co64.
2228
2262
pub stss : Option < SyncSampleBox > ,
2229
2263
pub ctts : Option < CompositionOffsetBox > ,
2264
+ pub tref : Option < TrackReferenceBox > ,
2230
2265
}
2231
2266
2232
2267
impl Track {
@@ -2496,10 +2531,6 @@ pub fn read_avif<T: Read>(f: &mut T, strictness: ParseStrictness) -> Result<Avif
2496
2531
return Status :: FtypNotFirst . into ( ) ;
2497
2532
} ;
2498
2533
2499
- if major_brand == AVIS_BRAND {
2500
- unsupported_features. insert ( Feature :: Avis ) ;
2501
- }
2502
-
2503
2534
let mut meta = None ;
2504
2535
let mut image_sequence = None ;
2505
2536
let mut media_storage = TryVec :: new ( ) ;
@@ -2776,7 +2807,7 @@ pub fn read_avif<T: Read>(f: &mut T, strictness: ParseStrictness) -> Result<Avif
2776
2807
premultiplied_alpha,
2777
2808
item_properties,
2778
2809
major_brand,
2779
- has_sequence : image_sequence. is_some ( ) ,
2810
+ sequence : image_sequence,
2780
2811
unsupported_features,
2781
2812
} )
2782
2813
}
@@ -4346,6 +4377,7 @@ fn read_trak<T: Read>(f: &mut BMFFBox<T>, track: &mut Track) -> Result<()> {
4346
4377
}
4347
4378
BoxType :: EditBox => read_edts ( & mut b, track) ?,
4348
4379
BoxType :: MediaBox => read_mdia ( & mut b, track) ?,
4380
+ BoxType :: TrackReferenceBox => track. tref = Some ( read_tref ( & mut b) ?) ,
4349
4381
_ => skip_box_content ( & mut b) ?,
4350
4382
} ;
4351
4383
check_parser_state ! ( b. content) ;
@@ -4430,6 +4462,8 @@ fn read_mdia<T: Read>(f: &mut BMFFBox<T>, track: &mut Track) -> Result<()> {
4430
4462
4431
4463
match hdlr. handler_type . value . as_ref ( ) {
4432
4464
b"vide" => track. track_type = TrackType :: Video ,
4465
+ b"pict" => track. track_type = TrackType :: Picture ,
4466
+ b"auxv" => track. track_type = TrackType :: AuxiliaryVideo ,
4433
4467
b"soun" => track. track_type = TrackType :: Audio ,
4434
4468
b"meta" => track. track_type = TrackType :: Metadata ,
4435
4469
_ => ( ) ,
@@ -4444,6 +4478,32 @@ fn read_mdia<T: Read>(f: &mut BMFFBox<T>, track: &mut Track) -> Result<()> {
4444
4478
Ok ( ( ) )
4445
4479
}
4446
4480
4481
+ fn read_tref < T : Read > ( f : & mut BMFFBox < T > ) -> Result < TrackReferenceBox > {
4482
+ // Will likely only see trefs with one auxl
4483
+ let mut references = TryVec :: with_capacity ( 1 ) ?;
4484
+ let mut iter = f. box_iter ( ) ;
4485
+ while let Some ( mut b) = iter. next_box ( ) ? {
4486
+ match b. head . name {
4487
+ BoxType :: AuxiliaryBox => {
4488
+ references. push ( TrackReferenceEntry :: Auxiliary ( read_tref_auxl ( & mut b) ?) ) ?
4489
+ }
4490
+ _ => skip_box_content ( & mut b) ?,
4491
+ } ;
4492
+ check_parser_state ! ( b. content) ;
4493
+ }
4494
+ Ok ( TrackReferenceBox { references } )
4495
+ }
4496
+
4497
+ fn read_tref_auxl < T : Read > ( f : & mut BMFFBox < T > ) -> Result < TrackReference > {
4498
+ let num_track_ids = ( f. bytes_left ( ) / std:: mem:: size_of :: < u32 > ( ) . to_u64 ( ) ) . try_into ( ) ?;
4499
+ let mut track_ids = TryVec :: with_capacity ( num_track_ids) ?;
4500
+ for _ in 0 ..num_track_ids {
4501
+ track_ids. push ( be_u32 ( f) ?) ?;
4502
+ }
4503
+
4504
+ Ok ( TrackReference { track_ids } )
4505
+ }
4506
+
4447
4507
fn read_minf < T : Read > ( f : & mut BMFFBox < T > , track : & mut Track ) -> Result < ( ) > {
4448
4508
let mut iter = f. box_iter ( ) ;
4449
4509
while let Some ( mut b) = iter. next_box ( ) ? {
@@ -5830,6 +5890,8 @@ fn read_stsd<T: Read>(src: &mut BMFFBox<T>, track: &mut Track) -> Result<SampleD
5830
5890
if let Some ( mut b) = iter. next_box ( ) ? {
5831
5891
let description = match track. track_type {
5832
5892
TrackType :: Video => read_video_sample_entry ( & mut b) ,
5893
+ TrackType :: Picture => read_video_sample_entry ( & mut b) ,
5894
+ TrackType :: AuxiliaryVideo => read_video_sample_entry ( & mut b) ,
5833
5895
TrackType :: Audio => read_audio_sample_entry ( & mut b) ,
5834
5896
TrackType :: Metadata => Err ( Error :: Unsupported ( "metadata track" ) ) ,
5835
5897
TrackType :: Unknown => Err ( Error :: Unsupported ( "unknown track type" ) ) ,
0 commit comments