MP4: Use all available free atoms

closes #346
This commit is contained in:
Serial 2024-04-26 08:49:10 -04:00 committed by Alex
parent 21e0e934ab
commit 79510821d6
2 changed files with 25 additions and 7 deletions

View file

@ -10,6 +10,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- **Truncate**: `impl<T: Truncate> Truncate for &mut T` ([PR](https://github.com/Serial-ATA/lofty-rs/pull/384))
- **Length**: `impl<T: Length> Truncate for &T` ([PR](https://github.com/Serial-ATA/lofty-rs/pull/384))
### Changed
- **MP4**: All surrounding `free` atoms will be used when writing `ilst` tags ([issue](https://github.com/Serial-ATA/lofty-rs/issues/346)) ([PR](https://github.com/Serial-ATA/lofty-rs/pull/386))
- Previously, only the `free` atoms immediately surrounding the `ilst` atom were used.
## [0.19.0] - 2024-04-21
### Added

View file

@ -256,21 +256,35 @@ fn save_to_existing(
// Check for one directly before the `ilst` atom
if ilst_idx > 0 {
let previous_atom = &tree[ilst_idx - 1];
let mut i = ilst_idx;
while i != 0 {
let atom = &tree[i - 1];
if atom.ident != AtomIdent::Fourcc(*b"free") {
break;
}
if previous_atom.ident == AtomIdent::Fourcc(*b"free") {
range_start = previous_atom.start;
available_space += previous_atom.len;
available_space += atom.len;
range_start = atom.start;
i -= 1;
}
log::trace!("Found {} preceding `free` atoms", ilst_idx - i)
}
// And after
if ilst_idx != tree.len() - 1 {
let next_atom = &tree[ilst_idx + 1];
let mut i = ilst_idx;
while i < tree.len() - 1 {
let atom = &tree[i + 1];
if atom.ident != AtomIdent::Fourcc(*b"free") {
break;
}
if next_atom.ident == AtomIdent::Fourcc(*b"free") {
available_space += next_atom.len;
available_space += atom.len;
i += 1;
}
log::trace!("Found {} succeeding `free` atoms", i - ilst_idx)
}
let ilst_len = ilst.len() as u64;