@@ -15,6 +15,7 @@ use bitreader::{BitReader, ReadInto};
15
15
use byteorder:: { ReadBytesExt , WriteBytesExt } ;
16
16
use fallible_collections:: TryClone ;
17
17
use fallible_collections:: TryRead ;
18
+ use fallible_collections:: TryReserveError ;
18
19
use num_traits:: Num ;
19
20
use std:: convert:: { TryFrom , TryInto as _} ;
20
21
use std:: io:: Cursor ;
@@ -201,14 +202,14 @@ impl From<Error> for std::io::Error {
201
202
}
202
203
}
203
204
204
- impl From < fallible_collections :: TryReserveError > for Error {
205
- fn from ( _: fallible_collections :: TryReserveError ) -> Error {
205
+ impl From < TryReserveError > for Error {
206
+ fn from ( _: TryReserveError ) -> Error {
206
207
Error :: OutOfMemory
207
208
}
208
209
}
209
210
210
211
/// Result shorthand using our Error enum.
211
- pub type Result < T > = std:: result:: Result < T , Error > ;
212
+ pub type Result < T , E = Error > = std:: result:: Result < T , E > ;
212
213
213
214
/// Basic ISO box structure.
214
215
///
@@ -1281,7 +1282,7 @@ pub fn read_avif<T: Read>(f: &mut T, context: &mut AvifContext) -> Result<()> {
1281
1282
prop. item_id == item_id
1282
1283
&& match & prop. property {
1283
1284
ItemProperty :: AuxiliaryType ( urn) => {
1284
- urn. as_slice ( )
1285
+ urn. aux_type . as_slice ( )
1285
1286
== "urn:mpeg:mpegB:cicp:systems:auxiliary:alpha" . as_bytes ( )
1286
1287
}
1287
1288
_ => false ,
@@ -1572,7 +1573,7 @@ fn read_iprp<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<AssociatedProperty>
1572
1573
if * prop != ItemProperty :: Unsupported {
1573
1574
associated. push ( AssociatedProperty {
1574
1575
item_id : a. item_id ,
1575
- property : prop. clone ( ) ?,
1576
+ property : prop. try_clone ( ) ?,
1576
1577
} ) ?;
1577
1578
}
1578
1579
}
@@ -1583,12 +1584,12 @@ fn read_iprp<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<AssociatedProperty>
1583
1584
#[ derive( Debug , PartialEq ) ]
1584
1585
pub enum ItemProperty {
1585
1586
Channels ( TryVec < u8 > ) ,
1586
- AuxiliaryType ( TryString ) ,
1587
+ AuxiliaryType ( AuxiliaryTypeProperty ) ,
1587
1588
Unsupported ,
1588
1589
}
1589
1590
1590
- impl ItemProperty {
1591
- fn clone ( & self ) -> Result < Self > {
1591
+ impl TryClone for ItemProperty {
1592
+ fn try_clone ( & self ) -> Result < Self , TryReserveError > {
1592
1593
Ok ( match self {
1593
1594
Self :: Channels ( val) => Self :: Channels ( val. try_clone ( ) ?) ,
1594
1595
Self :: AuxiliaryType ( val) => Self :: AuxiliaryType ( val. try_clone ( ) ?) ,
@@ -1674,20 +1675,44 @@ fn read_pixi<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<u8>> {
1674
1675
Ok ( channels)
1675
1676
}
1676
1677
1677
- fn read_auxc < T : Read > ( src : & mut BMFFBox < T > ) -> Result < TryString > {
1678
+ #[ derive( Debug , PartialEq ) ]
1679
+ pub struct AuxiliaryTypeProperty {
1680
+ aux_type : TryString ,
1681
+ aux_subtype : TryString ,
1682
+ }
1683
+
1684
+ impl TryClone for AuxiliaryTypeProperty {
1685
+ fn try_clone ( & self ) -> Result < Self , TryReserveError > {
1686
+ Ok ( AuxiliaryTypeProperty {
1687
+ aux_type : self . aux_type . try_clone ( ) ?,
1688
+ aux_subtype : self . aux_subtype . try_clone ( ) ?,
1689
+ } )
1690
+ }
1691
+ }
1692
+
1693
+ fn read_auxc < T : Read > ( src : & mut BMFFBox < T > ) -> Result < AuxiliaryTypeProperty > {
1678
1694
let version = read_fullbox_version_no_flags ( src) ?;
1679
1695
if version != 0 {
1680
1696
return Err ( Error :: Unsupported ( "auxC version" ) ) ;
1681
1697
}
1682
1698
1683
1699
let mut aux = TryString :: new ( ) ;
1684
- loop {
1685
- match src. read_u8 ( ) ? {
1686
- 0 => break ,
1687
- c => aux. push ( c) ?,
1688
- }
1700
+ src. try_read_to_end ( & mut aux) ?;
1701
+
1702
+ let ( aux_type, aux_subtype) : ( TryString , TryVec < u8 > ) ;
1703
+ if let Some ( nul_byte_pos) = aux. iter ( ) . position ( |& b| b == b'\0' ) {
1704
+ let ( a, b) = aux. as_slice ( ) . split_at ( nul_byte_pos) ;
1705
+ aux_type = a. try_into ( ) ?;
1706
+ aux_subtype = ( & b[ 1 ..] ) . try_into ( ) ?;
1707
+ } else {
1708
+ aux_type = aux;
1709
+ aux_subtype = TryVec :: new ( ) ;
1689
1710
}
1690
- Ok ( aux)
1711
+
1712
+ Ok ( AuxiliaryTypeProperty {
1713
+ aux_type,
1714
+ aux_subtype,
1715
+ } )
1691
1716
}
1692
1717
1693
1718
/// Parse an item location box inside a meta box
0 commit comments