Skip to content

Commit 6b42422

Browse files
kornelskibaumanj
andcommitted
ipco reading improvements
Co-authored-by: baumanj <[email protected]>
1 parent 8713308 commit 6b42422

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

mp4parse/src/lib.rs

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,7 @@ fn read_iref<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<SingleItemTypeRefer
15481548

15491549
fn read_iprp<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<AssociatedProperty>> {
15501550
let mut iter = src.box_iter();
1551-
let mut properties = TryVec::new();
1551+
let mut properties = TryHashMap::with_capacity(1)?;
15521552
let mut associations = TryVec::new();
15531553

15541554
while let Some(mut b) = iter.next_box()? {
@@ -1565,19 +1565,21 @@ fn read_iprp<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<AssociatedProperty>
15651565

15661566
let mut associated = TryVec::new();
15671567
for a in associations {
1568-
let index = match a.property_index {
1569-
0 => continue,
1570-
x => x as usize - 1,
1571-
};
1572-
if let Some(prop) = properties.get(index) {
1573-
if *prop != ItemProperty::Unsupported {
1574-
associated.push(AssociatedProperty {
1575-
item_id: a.item_id,
1576-
property: prop.try_clone()?,
1577-
})?;
1568+
if a.property_index == 0 {
1569+
if a.essential {
1570+
return Err(Error::InvalidData("0 property index can't be essential"));
15781571
}
1572+
continue;
1573+
}
1574+
1575+
if let Some(prop) = properties.get(&a.property_index) {
1576+
associated.push(AssociatedProperty {
1577+
item_id: a.item_id,
1578+
property: prop.try_clone()?,
1579+
})?;
15791580
}
15801581
}
1582+
15811583
Ok(associated)
15821584
}
15831585

@@ -1638,21 +1640,28 @@ fn read_ipma<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<Association>> {
16381640
Ok(associations)
16391641
}
16401642

1641-
fn read_ipco<T: Read>(src: &mut BMFFBox<T>) -> Result<TryVec<ItemProperty>> {
1642-
let mut properties = TryVec::new();
1643+
fn read_ipco<T: Read>(src: &mut BMFFBox<T>) -> Result<TryHashMap<u16, ItemProperty>> {
1644+
let mut properties = TryHashMap::with_capacity(1)?;
16431645

1646+
let mut index = 1; // ipma uses 1-based indexing
16441647
let mut iter = src.box_iter();
16451648
while let Some(mut b) = iter.next_box()? {
1646-
// Must push for every property to have correct index for them
1647-
properties.push(match b.head.name {
1648-
BoxType::PixelInformationBox => ItemProperty::Channels(read_pixi(&mut b)?),
1649-
BoxType::AuxiliaryTypeProperty => ItemProperty::AuxiliaryType(read_auxc(&mut b)?),
1649+
if let Some(property) = match b.head.name {
1650+
BoxType::PixelInformationBox => Some(ItemProperty::Channels(read_pixi(&mut b)?)),
1651+
BoxType::AuxiliaryTypeProperty => Some(ItemProperty::AuxiliaryType(read_auxc(&mut b)?)),
16501652
_ => {
16511653
skip_box_remain(&mut b)?;
1652-
ItemProperty::Unsupported
1654+
None
16531655
}
1654-
})?;
1656+
} {
1657+
properties.insert(index, property)?;
1658+
}
1659+
1660+
index += 1; // must include ignored properties to have correct indexes
1661+
1662+
check_parser_state!(b.content);
16551663
}
1664+
16561665
Ok(properties)
16571666
}
16581667

0 commit comments

Comments
 (0)