Skip to content

Commit

Permalink
MP4: Use all available free atoms
Browse files Browse the repository at this point in the history
closes #346
  • Loading branch information
Serial-ATA committed Apr 26, 2024
1 parent 120b5f5 commit 36f57e7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 23 additions & 9 deletions lofty/src/mp4/ilst/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];

if previous_atom.ident == AtomIdent::Fourcc(*b"free") {
range_start = previous_atom.start;
available_space += previous_atom.len;
let mut i = ilst_idx;
while i != 0 {
i -= 1;
let atom = &tree[i];
if atom.ident != AtomIdent::Fourcc(*b"free") {
break;
}

available_space += atom.len;
range_start = atom.start;
}

log::trace!("Found {} preceding `free` atoms", ilst_idx - i)
}

// And after
if ilst_idx != tree.len() - 1 {
let next_atom = &tree[ilst_idx + 1];

if next_atom.ident == AtomIdent::Fourcc(*b"free") {
available_space += next_atom.len;
let mut i = ilst_idx + 1;
while i < tree.len() {
let atom = &tree[i];
if atom.ident != AtomIdent::Fourcc(*b"free") {
break;
}

available_space += atom.len;
i += 1;
}

log::trace!("Found {} succeeding `free` atoms", (i - 1) - ilst_idx)
}

let ilst_len = ilst.len() as u64;
Expand Down

0 comments on commit 36f57e7

Please sign in to comment.