1mod cprt;
2mod kind;
3mod skip;
4
5pub use cprt::*;
6pub use kind::*;
7pub use skip::*;
8
9use crate::*;
10
11#[derive(Debug, Clone, PartialEq, Eq, Default)]
12#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
13pub struct Udta {
14 pub cprt: Option<Cprt>,
15 pub kind: Option<Kind>,
16 pub meta: Option<Meta>,
17}
18
19impl Atom for Udta {
20 const KIND: FourCC = FourCC::new(b"udta");
21
22 nested! {
23 required: [ ],
24 optional: [ Cprt, Meta, Kind],
25 multiple: [ ],
26 }
27}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32
33 #[test]
34 fn test_udta_empty() {
35 let expected = Udta {
36 cprt: None,
37 meta: None,
38 kind: None,
39 };
40
41 let mut buf = Vec::new();
42 expected.encode(&mut buf).unwrap();
43
44 let mut buf = buf.as_ref();
45 let output = Udta::decode(&mut buf).unwrap();
46 assert_eq!(output, expected);
47 }
48
49 #[test]
50 fn test_udta() {
51 let expected = Udta {
52 cprt: Some(Cprt {
53 language: "und".into(),
54 notice: "MIT or Apache".into(),
55 }),
56 meta: Some(Meta {
57 hdlr: Hdlr {
58 handler: FourCC::new(b"fake"),
59 name: "".into(),
60 },
61 items: vec![],
62 }),
63 kind: Some(Kind {
64 scheme_uri: "http://www.w3.org/TR/html5/".into(),
65 value: "".into(),
66 }),
67 };
68
69 let mut buf = Vec::new();
70 expected.encode(&mut buf).unwrap();
71
72 let mut buf = buf.as_ref();
73 let output = Udta::decode(&mut buf).unwrap();
74 assert_eq!(output, expected);
75 }
76
77 const ENCODED_UDTA_WITH_CPRT: &[u8] = &[
79 0x00, 0x00, 0x00, 0x70, 0x75, 0x64, 0x74, 0x61, 0x00, 0x00, 0x00, 0x68, 0x63, 0x70, 0x72,
80 0x74, 0x00, 0x00, 0x00, 0x00, 0x55, 0xc4, 0x45, 0x4e, 0x53, 0x54, 0x20, 0x49, 0x73, 0x6f,
81 0x4d, 0x65, 0x64, 0x69, 0x61, 0x20, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e,
82 0x63, 0x65, 0x20, 0x46, 0x69, 0x6c, 0x65, 0x73, 0x20, 0x2d, 0x20, 0x45, 0x4e, 0x53, 0x54,
83 0x20, 0x28, 0x63, 0x29, 0x20, 0x32, 0x30, 0x30, 0x36, 0x20, 0x2d, 0x20, 0x52, 0x69, 0x67,
84 0x68, 0x74, 0x73, 0x20, 0x72, 0x65, 0x6c, 0x65, 0x61, 0x73, 0x65, 0x64, 0x20, 0x66, 0x6f,
85 0x72, 0x20, 0x49, 0x53, 0x4f, 0x20, 0x43, 0x6f, 0x6e, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x6e,
86 0x63, 0x65, 0x20, 0x75, 0x73, 0x65, 0x00,
87 ];
88
89 #[test]
90 fn test_udta_cprt() {
91 let mut buf = std::io::Cursor::new(ENCODED_UDTA_WITH_CPRT);
92
93 let udta = Udta::decode(&mut buf).expect("failed to decode udta");
94
95 assert_eq!(
96 udta,
97 Udta {
98 cprt: Some(Cprt { language: "und".into(), notice: "ENST IsoMedia Conformance Files - ENST (c) 2006 - Rights released for ISO Conformance use".into() }),
99 meta: None,
100 kind: None,
101 }
102 );
103
104 let mut buf = Vec::new();
105 udta.encode(&mut buf).unwrap();
106
107 assert_eq!(buf, ENCODED_UDTA_WITH_CPRT);
108 }
109
110 const ENCODED_UDTA_WITH_KIND: &[u8] = &[
112 0x00, 0x00, 0x00, 0x31, 0x75, 0x64, 0x74, 0x61, 0x00, 0x00, 0x00, 0x29, 0x6b, 0x69, 0x6e,
113 0x64, 0x00, 0x00, 0x00, 0x00, 0x75, 0x72, 0x6e, 0x3a, 0x6d, 0x70, 0x65, 0x67, 0x3a, 0x64,
114 0x61, 0x73, 0x68, 0x3a, 0x72, 0x6f, 0x6c, 0x65, 0x3a, 0x32, 0x30, 0x31, 0x31, 0x00, 0x6d,
115 0x61, 0x69, 0x6e, 0x00,
116 ];
117
118 #[test]
119 fn test_udta_kind() {
120 let mut buf = std::io::Cursor::new(ENCODED_UDTA_WITH_KIND);
121
122 let udta = Udta::decode(&mut buf).expect("failed to decode udta");
123
124 assert_eq!(
125 udta,
126 Udta {
127 cprt: None,
128 meta: None,
129 kind: Some(Kind {
130 scheme_uri: "urn:mpeg:dash:role:2011".into(),
131 value: "main".into()
132 })
133 }
134 );
135
136 let mut buf = Vec::new();
137 udta.encode(&mut buf).unwrap();
138
139 assert_eq!(buf, ENCODED_UDTA_WITH_KIND);
140 }
141}