Skip to content

Commit

Permalink
mp4: Fix conversion of u16 track/disc numbers to BE bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
uklotzde committed Jan 13, 2024
1 parent ac20868 commit 5b3c26d
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/mp4/ilst/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -414,10 +414,10 @@ impl Accessor for Ilst {
}

fn set_track(&mut self, value: u32) {
let value = (value as u16).to_be_bytes();
let track_total = self.track_total().unwrap_or(0).to_be_bytes();
let track = (value as u16).to_be_bytes();
let track_total = (self.track_total().unwrap_or(0) as u16).to_be_bytes();

let data = vec![0, 0, value[0], value[1], track_total[0], track_total[1]];
let data = vec![0, 0, track[0], track[1], track_total[0], track_total[1]];
self.replace_atom(Atom::unknown_implicit(AtomIdent::Fourcc(*b"trkn"), data));
}

Expand All @@ -430,19 +430,19 @@ impl Accessor for Ilst {
}

fn set_track_total(&mut self, value: u32) {
let value = (value as u16).to_be_bytes();
let track = self.track().unwrap_or(1).to_be_bytes();
let track_total = (value as u16).to_be_bytes();
let track = (self.track().unwrap_or(0) as u16).to_be_bytes();

let data = vec![0, 0, track[0], track[1], value[0], value[1]];
let data = vec![0, 0, track[0], track[1], track_total[0], track_total[1]];
self.replace_atom(Atom::unknown_implicit(AtomIdent::Fourcc(*b"trkn"), data));
}

fn remove_track_total(&mut self) {
let track_num = self.track();
let track = self.track();
let _ = self.remove(&AtomIdent::Fourcc(*b"trkn"));

if let Some(track_num) = track_num {
let track_bytes = (track_num as u16).to_be_bytes();
if let Some(track) = track {
let track_bytes = (track as u16).to_be_bytes();
let data = vec![0, 0, track_bytes[0], track_bytes[1], 0, 0];

self.replace_atom(Atom::unknown_implicit(AtomIdent::Fourcc(*b"trkn"), data));
Expand All @@ -454,10 +454,10 @@ impl Accessor for Ilst {
}

fn set_disk(&mut self, value: u32) {
let value = (value as u16).to_be_bytes();
let disk_total = self.disk_total().unwrap_or(0).to_be_bytes();
let disk = (value as u16).to_be_bytes();
let disk_total = (self.disk_total().unwrap_or(0) as u16).to_be_bytes();

let data = vec![0, 0, value[0], value[1], disk_total[0], disk_total[1]];
let data = vec![0, 0, disk[0], disk[1], disk_total[0], disk_total[1]];
self.replace_atom(Atom::unknown_implicit(AtomIdent::Fourcc(*b"disk"), data));
}

Expand All @@ -470,19 +470,19 @@ impl Accessor for Ilst {
}

fn set_disk_total(&mut self, value: u32) {
let value = (value as u16).to_be_bytes();
let disk = self.disk().unwrap_or(1).to_be_bytes();
let disk_total = (value as u16).to_be_bytes();
let disk = (self.disk().unwrap_or(0) as u16).to_be_bytes();

let data = vec![0, 0, disk[0], disk[1], value[0], value[1]];
let data = vec![0, 0, disk[0], disk[1], disk_total[0], disk_total[1]];
self.replace_atom(Atom::unknown_implicit(AtomIdent::Fourcc(*b"disk"), data));
}

fn remove_disk_total(&mut self) {
let disk_num = self.disk();
let disk = self.disk();
let _ = self.remove(&AtomIdent::Fourcc(*b"disk"));

if let Some(disk_num) = disk_num {
let disk_bytes = (disk_num as u16).to_be_bytes();
if let Some(disk) = disk {
let disk_bytes = (disk as u16).to_be_bytes();
let data = vec![0, 0, disk_bytes[0], disk_bytes[1], 0, 0];

self.replace_atom(Atom::unknown_implicit(AtomIdent::Fourcc(*b"disk"), data));
Expand Down

0 comments on commit 5b3c26d

Please sign in to comment.