Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ any! {
Year,
Moov,
Mvhd,
Ainf,
Udta,
Cprt,
Kind,
Expand Down
88 changes: 88 additions & 0 deletions src/moov/ainf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
use crate::*;

ext! {
name: Ainf,
versions: [0],
flags: {
hidden = 0,
}
}

#[derive(Debug, Clone, PartialEq, Eq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ainf {
pub hidden: bool,
// TODO: this could be parsed further if DECE ever becomes important again
pub profile_version: u32,
pub apid: String,
}

impl AtomExt for Ainf {
const KIND_EXT: FourCC = FourCC::new(b"ainf");

type Ext = AinfExt;

fn decode_body_ext<B: Buf>(buf: &mut B, ext: AinfExt) -> Result<Self> {
let profile_version = u32::decode(buf)?;
let apid = String::decode(buf)?;
let remaining = buf.remaining();
if remaining != 0 {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#112 ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly, but I'm more interested in flagging this case because the spec says there can be nested boxes, rather than just padding.

Does make me think that up to 8 bytes would be a valid skip case for #112, while this is more "at least a Box" size.

tracing::warn!("Found additional data in ainf box, which could be additional private boxes, and that data is being ignored.");
buf.advance(remaining);
}
Ok(Ainf {
hidden: ext.hidden,
profile_version,
apid,
})
}

fn encode_body_ext<B: BufMut>(&self, buf: &mut B) -> Result<AinfExt> {
let ext = AinfExt {
hidden: self.hidden,
version: AinfVersion::V0,
};
self.profile_version.encode(buf)?;
self.apid.as_str().encode(buf)?;
Ok(ext)
}
}

#[cfg(test)]
mod tests {
use super::*;

const ENCODED_AINF: &[u8] = &[
0x00, 0x00, 0x00, 0x38, 0x61, 0x69, 0x6e, 0x66, 0x00, 0x00, 0x00, 0x00, 0x68, 0x31, 0x30,
0x37, 0x75, 0x72, 0x6e, 0x3a, 0x64, 0x65, 0x63, 0x65, 0x3a, 0x61, 0x70, 0x69, 0x64, 0x3a,
0x6f, 0x72, 0x67, 0x3a, 0x64, 0x65, 0x63, 0x65, 0x63, 0x76, 0x70, 0x3a, 0x64, 0x65, 0x76,
0x69, 0x63, 0x65, 0x30, 0x30, 0x32, 0x2d, 0x34, 0x76, 0x37, 0x00,
];

#[test]
fn test_ainf_decode() {
let buf: &mut std::io::Cursor<&&[u8]> = &mut std::io::Cursor::new(&ENCODED_AINF);
let ainf = Ainf::decode(buf).expect("failed to decode ainf");
assert_eq!(
ainf,
Ainf {
hidden: false,
profile_version: 1748054071,
apid: "urn:dece:apid:org:dececvp:device002-4v7".into(),
}
);
}

#[test]
fn test_ainf_encode() {
let ainf = Ainf {
hidden: false,
profile_version: 1748054071,
apid: "urn:dece:apid:org:dececvp:device002-4v7".into(),
};

let mut buf = Vec::new();
ainf.encode(&mut buf).unwrap();
assert_eq!(buf, ENCODED_AINF);
}
}
7 changes: 5 additions & 2 deletions src/moov/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
mod ainf;
mod mvex;
mod mvhd;
mod trak;
mod udta;

pub use ainf::*;
pub use mvex::*;
pub use mvhd::*;
pub use trak::*;
Expand All @@ -18,14 +20,15 @@ pub struct Moov {
pub mvex: Option<Mvex>,
pub trak: Vec<Trak>,
pub udta: Option<Udta>,
pub ainf: Option<Ainf>,
}

impl Atom for Moov {
const KIND: FourCC = FourCC::new(b"moov");

nested! {
required: [ Mvhd ],
optional: [ Meta, Mvex, Udta ],
optional: [ Ainf, Meta, Mvex, Udta ],
multiple: [ Trak ],
}
}
Expand Down Expand Up @@ -231,7 +234,7 @@ mod test {
senc: None,
udta: None
}],
udta: None,
..Default::default()
}
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/av1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ fn av1() {
},
next_track_id: 2
},
meta: None,
mvex: Some(Mvex {
mehd: None,
trex: vec![Trex {
Expand Down Expand Up @@ -189,7 +188,8 @@ fn av1() {
.into(),],
}),
..Default::default()
})
}),
..Default::default()
}
);

Expand Down
3 changes: 1 addition & 2 deletions src/test/flac.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ fn flac() {
},
next_track_id: 2
},
meta: None,
mvex: Some(Mvex {
mehd: None,
trex: vec![Trex {
Expand Down Expand Up @@ -157,7 +156,7 @@ fn flac() {
senc: None,
udta: None
}],
udta: None
..Default::default()
}
);

Expand Down
2 changes: 1 addition & 1 deletion src/test/h264.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ fn avcc_ext() {
},
next_track_id: 2,
},
meta: None,
mvex: Some(Mvex {
mehd: None,
trex: vec![
Expand Down Expand Up @@ -288,6 +287,7 @@ fn avcc_ext() {
},
],
udta: Some(Udta::default()),
..Default::default()
};

assert_eq!(moov, expected, "different decoded result");
Expand Down
4 changes: 2 additions & 2 deletions src/test/hevc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ fn hevc() {
},
next_track_id: 2
},
meta: None,
mvex: Some(Mvex {
mehd: None,
trex: vec![Trex {
Expand Down Expand Up @@ -406,7 +405,8 @@ fn hevc() {
.into(),],
}),
..Default::default()
})
}),
..Default::default()
}
);

Expand Down
5 changes: 2 additions & 3 deletions src/test/uncompressed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ fn uncompressed() {
},
next_track_id: 2
},
meta: None,
mvex: None,
trak: [Trak {
tkhd: Tkhd {
creation_time: 3827291266,
Expand Down Expand Up @@ -239,7 +237,8 @@ fn uncompressed() {
.into(),],
}),
..Default::default()
})
},),
..Default::default()
}
);

Expand Down
2 changes: 1 addition & 1 deletion src/test/vp9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ fn vp9() {
senc: None,
udta: None,
}],
udta: None
..Default::default()
}
);

Expand Down