From a6d4f12c33e2094b7cdffe34f679fcf5e21d0561 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Wed, 9 Nov 2022 14:10:03 -0500 Subject: [PATCH] Ilst: Add `AtomData::Bool` for flag atoms --- CHANGELOG.md | 1 + src/mp4/ilst/atom.rs | 7 ++++++- src/mp4/ilst/read.rs | 17 +++++++++++++++++ src/mp4/ilst/write.rs | 1 + 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b529cb093..30e2c574f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - **TagExt**: `TagExt::contains` +- **Ilst**: `AtomData::Bool` for the various flag atoms such as `cpil`, `pcst`, etc. ## [0.9.0] - 2022-10-30 diff --git a/src/mp4/ilst/atom.rs b/src/mp4/ilst/atom.rs index 3d3317c96..b96d8bf51 100644 --- a/src/mp4/ilst/atom.rs +++ b/src/mp4/ilst/atom.rs @@ -165,7 +165,6 @@ impl Debug for Atom { /// to the link above for codes. #[derive(Debug, PartialEq, Eq, Clone)] pub enum AtomData { - // TODO: Bool variant for the various flag atoms? /// A UTF-8 encoded string UTF8(String), /// A UTF-16 encoded string @@ -188,6 +187,12 @@ pub enum AtomData { /// /// NOTE: See [`AtomData::SignedInteger`] UnsignedInteger(u32), + /// A boolean value + /// + /// NOTE: This isn't an official data type, but multiple flag atoms exist, + /// so this makes them easier to represent. The *real* underlying type + /// is `SignedInteger`. + Bool(bool), /// Unknown data /// /// Due to the number of possible types, there are many diff --git a/src/mp4/ilst/read.rs b/src/mp4/ilst/read.rs index 765766b61..5cee2f062 100644 --- a/src/mp4/ilst/read.rs +++ b/src/mp4/ilst/read.rs @@ -86,6 +86,23 @@ where continue; }, + b"cpil" | b"hdvd" | b"pcst" | b"pgap" | b"shwm" => { + if let Some(atom_data) = parse_data_inner(&mut ilst_reader, &atom)? { + if let Some((_, content)) = atom_data.first() { + let data = match content[..] { + [0, ..] => AtomData::Bool(false), + _ => AtomData::Bool(true), + }; + + tag.atoms.push(Atom { + ident: AtomIdent::Fourcc(*fourcc), + data: AtomDataStorage::Single(data), + }) + } + } + + continue; + }, _ => {}, } } diff --git a/src/mp4/ilst/write.rs b/src/mp4/ilst/write.rs index fa2007689..e0bea6cc4 100644 --- a/src/mp4/ilst/write.rs +++ b/src/mp4/ilst/write.rs @@ -381,6 +381,7 @@ where AtomData::Picture(ref pic) => write_picture(pic, writer)?, AtomData::SignedInteger(int) => write_signed_int(*int, writer)?, AtomData::UnsignedInteger(uint) => write_unsigned_int(*uint, writer)?, + AtomData::Bool(b) => write_signed_int(i32::from(*b), writer)?, AtomData::Unknown { code, ref data } => write_data(*code, data, writer)?, }; }