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