@@ -752,6 +752,19 @@ pub struct MetadataBox {
752
752
pub sort_album_artist : Option < TryString > ,
753
753
/// The name of the composer to sort by 'soco'
754
754
pub sort_composer : Option < TryString > ,
755
+ /// Metadata
756
+ #[ cfg( feature = "meta-xml" ) ]
757
+ pub xml : Option < XmlBox > ,
758
+ }
759
+
760
+ /// See ISOBMFF (ISO 14496-12:2015) § 8.11.2.1
761
+ #[ cfg( feature = "meta-xml" ) ]
762
+ #[ derive( Debug ) ]
763
+ pub enum XmlBox {
764
+ /// XML metadata
765
+ StringXmlBox ( TryString ) ,
766
+ /// Binary XML metadata
767
+ BinaryXmlBox ( TryVec < u8 > ) ,
755
768
}
756
769
757
770
/// Internal data structures.
@@ -763,6 +776,8 @@ pub struct MediaContext {
763
776
pub mvex : Option < MovieExtendsBox > ,
764
777
pub psshs : TryVec < ProtectionSystemSpecificHeaderBox > ,
765
778
pub userdata : Option < Result < UserdataBox > > ,
779
+ #[ cfg( feature = "meta-xml" ) ]
780
+ pub metadata : Option < Result < MetadataBox > > ,
766
781
}
767
782
768
783
/// An ISOBMFF item as described by an iloc box. For the sake of avoiding copies,
@@ -2307,6 +2322,12 @@ pub fn read_mp4<T: Read>(f: &mut T) -> Result<MediaContext> {
2307
2322
BoxType :: MovieBox => {
2308
2323
context = Some ( read_moov ( & mut b, context) ?) ;
2309
2324
}
2325
+ #[ cfg( feature = "meta-xml" ) ]
2326
+ BoxType :: MetadataBox => {
2327
+ if let Some ( ctx) = & mut context {
2328
+ ctx. metadata = Some ( read_meta ( & mut b) ) ;
2329
+ }
2330
+ }
2310
2331
_ => skip_box_content ( & mut b) ?,
2311
2332
} ;
2312
2333
check_parser_state ! ( b. content) ;
@@ -2352,6 +2373,8 @@ fn read_moov<T: Read>(f: &mut BMFFBox<T>, context: Option<MediaContext>) -> Resu
2352
2373
mut mvex,
2353
2374
mut psshs,
2354
2375
mut userdata,
2376
+ #[ cfg( feature = "meta-xml" ) ]
2377
+ metadata,
2355
2378
} = context. unwrap_or_default ( ) ;
2356
2379
2357
2380
let mut iter = f. box_iter ( ) ;
@@ -2394,6 +2417,8 @@ fn read_moov<T: Read>(f: &mut BMFFBox<T>, context: Option<MediaContext>) -> Resu
2394
2417
mvex,
2395
2418
psshs,
2396
2419
userdata,
2420
+ #[ cfg( feature = "meta-xml" ) ]
2421
+ metadata,
2397
2422
} )
2398
2423
}
2399
2424
@@ -4050,21 +4075,48 @@ fn read_udta<T: Read>(src: &mut BMFFBox<T>) -> Result<UserdataBox> {
4050
4075
Ok ( udta)
4051
4076
}
4052
4077
4053
- /// Parse a metadata box inside a udta box
4078
+ /// Parse the meta box
4079
+ /// See ISOBMFF (ISO 14496-12:2015) § 8.111.
4054
4080
fn read_meta < T : Read > ( src : & mut BMFFBox < T > ) -> Result < MetadataBox > {
4055
4081
let ( _, _) = read_fullbox_extra ( src) ?;
4056
4082
let mut iter = src. box_iter ( ) ;
4057
4083
let mut meta = MetadataBox :: default ( ) ;
4058
4084
while let Some ( mut b) = iter. next_box ( ) ? {
4059
4085
match b. head . name {
4060
4086
BoxType :: MetadataItemListEntry => read_ilst ( & mut b, & mut meta) ?,
4087
+ #[ cfg( feature = "meta-xml" ) ]
4088
+ BoxType :: MetadataXMLBox => read_xml_ ( & mut b, & mut meta) ?,
4089
+ #[ cfg( feature = "meta-xml" ) ]
4090
+ BoxType :: MetadataBXMLBox => read_bxml ( & mut b, & mut meta) ?,
4061
4091
_ => skip_box_content ( & mut b) ?,
4062
4092
} ;
4063
4093
check_parser_state ! ( b. content) ;
4064
4094
}
4065
4095
Ok ( meta)
4066
4096
}
4067
4097
4098
+ /// Parse a XML box inside a meta box
4099
+ /// See ISOBMFF (ISO 14496-12:2015) § 8.11.2
4100
+ #[ cfg( feature = "meta-xml" ) ]
4101
+ fn read_xml_ < T : Read > ( src : & mut BMFFBox < T > , meta : & mut MetadataBox ) -> Result < ( ) > {
4102
+ if read_fullbox_version_no_flags ( src) ? != 0 {
4103
+ return Err ( Error :: Unsupported ( "unsupported XmlBox version" ) ) ;
4104
+ }
4105
+ meta. xml = Some ( XmlBox :: StringXmlBox ( src. read_into_try_vec ( ) ?) ) ;
4106
+ Ok ( ( ) )
4107
+ }
4108
+
4109
+ /// Parse a Binary XML box inside a meta box
4110
+ /// See ISOBMFF (ISO 14496-12:2015) § 8.11.2
4111
+ #[ cfg( feature = "meta-xml" ) ]
4112
+ fn read_bxml < T : Read > ( src : & mut BMFFBox < T > , meta : & mut MetadataBox ) -> Result < ( ) > {
4113
+ if read_fullbox_version_no_flags ( src) ? != 0 {
4114
+ return Err ( Error :: Unsupported ( "unsupported XmlBox version" ) ) ;
4115
+ }
4116
+ meta. xml = Some ( XmlBox :: BinaryXmlBox ( src. read_into_try_vec ( ) ?) ) ;
4117
+ Ok ( ( ) )
4118
+ }
4119
+
4068
4120
/// Parse a metadata box inside a udta box
4069
4121
fn read_ilst < T : Read > ( src : & mut BMFFBox < T > , meta : & mut MetadataBox ) -> Result < ( ) > {
4070
4122
let mut iter = src. box_iter ( ) ;
0 commit comments