1use crate::nal::sei::HeaderType;
2use crate::nal::sei::SeiMessage;
3
4#[derive(Debug)]
5pub enum ItuTT35Error {
6 NotEnoughData { expected: usize, actual: usize },
7}
8
9#[derive(Debug, PartialEq)]
10pub enum ItuTT35 {
11 Japan,
12 Albania,
13 Algeria,
14 AmericanSamoa,
15 GermanyFederalRepublicOf(u8),
16 Anguilla,
17 AntiguaandBarbuda,
18 Argentina,
19 AscensionseeSHelena,
20 Australia,
21 Austria,
22 Bahamas,
23 Bahrain,
24 Bangladesh,
25 Barbados,
26 Belgium,
27 Belize,
28 BeninRepublicOf,
29 Bermudas,
30 BhutanKingdomOf,
31 Bolivia,
32 Botswana,
33 Brazil,
34 BritishAntarcticTerritory,
35 BritishIndianOceanTerritory,
36 BritishVirginIslands,
37 BruneiDarussalam,
38 Bulgaria,
39 MyanmarUnionOf,
40 Burundi,
41 Byelorussia,
42 Cameroon,
43 Canada,
44 CapeVerde,
45 CaymanIslands,
46 CentralAfricanRepublic,
47 Chad,
48 Chile,
49 China,
50 Colombia,
51 Comoros,
52 Congo,
53 CookIslands,
54 CostaRica,
55 Cuba,
56 Cyprus,
57 CzechandSlovakFederalRepublic,
58 Cambodia,
59 DemocraticPeoplesRepublicOfKorea,
60 Denmark,
61 Djibouti,
62 DominicanRepublic,
63 Dominica,
64 Ecuador,
65 Egypt,
66 ElSalvador,
67 EquatorialGuinea,
68 Ethiopia,
69 FalklandIslands,
70 Fiji,
71 Finland,
72 France,
73 FrenchPolynesia,
74 FrenchSouthernAndAntarcticLands,
75 Gabon,
76 Gambia,
77 Angola,
78 Ghana,
79 Gibraltar,
80 Greece,
81 Grenada,
82 Guam,
83 Guatemala,
84 Guernsey,
85 Guinea,
86 GuineaBissau,
87 Guayana,
88 Haiti,
89 Honduras,
90 Hongkong,
91 HungaryRepublicOf,
92 Iceland,
93 India,
94 Indonesia,
95 IranIslamicRepublicOf,
96 Iraq,
97 Ireland,
98 Israel,
99 Italy,
100 CotedIvoire,
101 Jamaica,
102 Afghanistan,
103 Jersey,
104 Jordan,
105 Kenya,
106 Kiribati,
107 KoreaRepublicOf,
108 Kuwait,
109 LaoPeoplesDemocraticRepublic,
110 Lebanon,
111 Lesotho,
112 Liberia,
113 Libya,
114 Liechtenstein,
115 Luxembourg,
116 Macau,
117 Madagascar,
118 Malaysia,
119 Malawi,
120 Maldives,
121 Mali,
122 Malta,
123 Mauritania,
124 Mauritius,
125 Mexico,
126 Monaco,
127 Mongolia,
128 Montserrat,
129 Morocco,
130 Mozambique,
131 Nauru,
132 Nepal,
133 Netherlands,
134 NetherlandsAntilles,
135 NewCaledonia,
136 NewZealand,
137 Nicaragua,
138 Niger,
139 Nigeria,
140 Norway,
141 Oman,
142 Pakistan,
143 Panama,
144 PapuaNewGuinea,
145 Paraguay,
146 Peru,
147 Philippines,
148 PolandRepublicOf,
149 Portugal,
150 PuertoRico,
151 Qatar,
152 Romania,
153 Rwanda,
154 SaintKittsAndNevis,
155 SaintCroix,
156 SaintHelenaAndAscension,
157 SaintLucia,
158 SanMarino,
159 SaintThomas,
160 SaoTomeAndPrincipe,
161 SaintVincentAndTheGrenadines,
162 SaudiArabia,
163 Senegal,
164 Seychelles,
165 SierraLeone,
166 Singapore,
167 SolomonIslands,
168 Somalia,
169 SouthAfrica,
170 Spain,
171 SriLanka,
172 Sudan,
173 Suriname,
174 Swaziland,
175 Sweden,
176 Switzerland,
177 Syria,
178 Tanzania,
179 Thailand,
180 Togo,
181 Tonga,
182 TrinidadAndTobago,
183 Tunisia,
184 Turkey,
185 TurksAndCaicosIslands,
186 Tuvalu,
187 Uganda,
188 Ukraine,
189 UnitedArabEmirates,
190 UnitedKingdom,
191 UnitedStates,
192 BurkinaFaso,
193 Uruguay,
194 USSR,
195 Vanuatu,
196 VaticanCityState,
197 Venezuela,
198 VietNam,
199 WallisAndFutuna,
200 WesternSamoa,
201 YemenRepublicOf(u8),
202 Yugoslavia,
203 Zaire,
204 Zambia,
205 Zimbabwe,
206 Unknown(u8),
207 Extended(u8),
208}
209impl ItuTT35 {
210 pub fn read<'a>(msg: &SeiMessage<'a>) -> Result<(ItuTT35, &'a [u8]), ItuTT35Error> {
211 assert_eq!(msg.payload_type, HeaderType::UserDataRegisteredItuTT35);
212 if msg.payload.is_empty() {
213 return Err(ItuTT35Error::NotEnoughData {
214 expected: 1,
215 actual: 0,
216 });
217 }
218 let buf = msg.payload;
219 let itu_t_t35_country_code = buf[0];
220 Ok(match itu_t_t35_country_code {
221 0b0000_0000 => (ItuTT35::Japan, &buf[1..]),
222 0b0000_0001 => (ItuTT35::Albania, &buf[1..]),
223 0b0000_0010 => (ItuTT35::Algeria, &buf[1..]),
224 0b0000_0011 => (ItuTT35::AmericanSamoa, &buf[1..]),
225 0b0000_0100 => (
226 ItuTT35::GermanyFederalRepublicOf(itu_t_t35_country_code),
227 &buf[1..],
228 ),
229 0b0000_0101 => (ItuTT35::Anguilla, &buf[1..]),
230 0b0000_0110 => (ItuTT35::AntiguaandBarbuda, &buf[1..]),
231 0b0000_0111 => (ItuTT35::Argentina, &buf[1..]),
232 0b0000_1000 => (ItuTT35::AscensionseeSHelena, &buf[1..]),
233 0b0000_1001 => (ItuTT35::Australia, &buf[1..]),
234 0b0000_1010 => (ItuTT35::Austria, &buf[1..]),
235 0b0000_1011 => (ItuTT35::Bahamas, &buf[1..]),
236 0b0000_1100 => (ItuTT35::Bahrain, &buf[1..]),
237 0b0000_1101 => (ItuTT35::Bangladesh, &buf[1..]),
238 0b0000_1110 => (ItuTT35::Barbados, &buf[1..]),
239 0b0000_1111 => (ItuTT35::Belgium, &buf[1..]),
240 0b0001_0000 => (ItuTT35::Belize, &buf[1..]),
241 0b0001_0001 => (ItuTT35::BeninRepublicOf, &buf[1..]),
242 0b0001_0010 => (ItuTT35::Bermudas, &buf[1..]),
243 0b0001_0011 => (ItuTT35::BhutanKingdomOf, &buf[1..]),
244 0b0001_0100 => (ItuTT35::Bolivia, &buf[1..]),
245 0b0001_0101 => (ItuTT35::Botswana, &buf[1..]),
246 0b0001_0110 => (ItuTT35::Brazil, &buf[1..]),
247 0b0001_0111 => (ItuTT35::BritishAntarcticTerritory, &buf[1..]),
248 0b0001_1000 => (ItuTT35::BritishIndianOceanTerritory, &buf[1..]),
249 0b0001_1001 => (ItuTT35::BritishVirginIslands, &buf[1..]),
250 0b0001_1010 => (ItuTT35::BruneiDarussalam, &buf[1..]),
251 0b0001_1011 => (ItuTT35::Bulgaria, &buf[1..]),
252 0b0001_1100 => (ItuTT35::MyanmarUnionOf, &buf[1..]),
253 0b0001_1101 => (ItuTT35::Burundi, &buf[1..]),
254 0b0001_1110 => (ItuTT35::Byelorussia, &buf[1..]),
255 0b0001_1111 => (ItuTT35::Cameroon, &buf[1..]),
256 0b0010_0000 => (ItuTT35::Canada, &buf[1..]),
257 0b0010_0001 => (ItuTT35::CapeVerde, &buf[1..]),
258 0b0010_0010 => (ItuTT35::CaymanIslands, &buf[1..]),
259 0b0010_0011 => (ItuTT35::CentralAfricanRepublic, &buf[1..]),
260 0b0010_0100 => (ItuTT35::Chad, &buf[1..]),
261 0b0010_0101 => (ItuTT35::Chile, &buf[1..]),
262 0b0010_0110 => (ItuTT35::China, &buf[1..]),
263 0b0010_0111 => (ItuTT35::Colombia, &buf[1..]),
264 0b0010_1000 => (ItuTT35::Comoros, &buf[1..]),
265 0b0010_1001 => (ItuTT35::Congo, &buf[1..]),
266 0b0010_1010 => (ItuTT35::CookIslands, &buf[1..]),
267 0b0010_1011 => (ItuTT35::CostaRica, &buf[1..]),
268 0b0010_1100 => (ItuTT35::Cuba, &buf[1..]),
269 0b0010_1101 => (ItuTT35::Cyprus, &buf[1..]),
270 0b0010_1110 => (ItuTT35::CzechandSlovakFederalRepublic, &buf[1..]),
271 0b0010_1111 => (ItuTT35::Cambodia, &buf[1..]),
272 0b0011_0000 => (ItuTT35::DemocraticPeoplesRepublicOfKorea, &buf[1..]),
273 0b0011_0001 => (ItuTT35::Denmark, &buf[1..]),
274 0b0011_0010 => (ItuTT35::Djibouti, &buf[1..]),
275 0b0011_0011 => (ItuTT35::DominicanRepublic, &buf[1..]),
276 0b0011_0100 => (ItuTT35::Dominica, &buf[1..]),
277 0b0011_0101 => (ItuTT35::Ecuador, &buf[1..]),
278 0b0011_0110 => (ItuTT35::Egypt, &buf[1..]),
279 0b0011_0111 => (ItuTT35::ElSalvador, &buf[1..]),
280 0b0011_1000 => (ItuTT35::EquatorialGuinea, &buf[1..]),
281 0b0011_1001 => (ItuTT35::Ethiopia, &buf[1..]),
282 0b0011_1010 => (ItuTT35::FalklandIslands, &buf[1..]),
283 0b0011_1011 => (ItuTT35::Fiji, &buf[1..]),
284 0b0011_1100 => (ItuTT35::Finland, &buf[1..]),
285 0b0011_1101 => (ItuTT35::France, &buf[1..]),
286 0b0011_1110 => (ItuTT35::FrenchPolynesia, &buf[1..]),
287 0b0011_1111 => (ItuTT35::FrenchSouthernAndAntarcticLands, &buf[1..]),
288 0b0100_0000 => (ItuTT35::Gabon, &buf[1..]),
289 0b0100_0001 => (ItuTT35::Gambia, &buf[1..]),
290 0b0100_0010 => (
291 ItuTT35::GermanyFederalRepublicOf(itu_t_t35_country_code),
292 &buf[1..],
293 ),
294 0b0100_0011 => (ItuTT35::Angola, &buf[1..]),
295 0b0100_0100 => (ItuTT35::Ghana, &buf[1..]),
296 0b0100_0101 => (ItuTT35::Gibraltar, &buf[1..]),
297 0b0100_0110 => (ItuTT35::Greece, &buf[1..]),
298 0b0100_0111 => (ItuTT35::Grenada, &buf[1..]),
299 0b0100_1000 => (ItuTT35::Guam, &buf[1..]),
300 0b0100_1001 => (ItuTT35::Guatemala, &buf[1..]),
301 0b0100_1010 => (ItuTT35::Guernsey, &buf[1..]),
302 0b0100_1011 => (ItuTT35::Guinea, &buf[1..]),
303 0b0100_1100 => (ItuTT35::GuineaBissau, &buf[1..]),
304 0b0100_1101 => (ItuTT35::Guayana, &buf[1..]),
305 0b0100_1110 => (ItuTT35::Haiti, &buf[1..]),
306 0b0100_1111 => (ItuTT35::Honduras, &buf[1..]),
307 0b0101_0000 => (ItuTT35::Hongkong, &buf[1..]),
308 0b0101_0001 => (ItuTT35::HungaryRepublicOf, &buf[1..]),
309 0b0101_0010 => (ItuTT35::Iceland, &buf[1..]),
310 0b0101_0011 => (ItuTT35::India, &buf[1..]),
311 0b0101_0100 => (ItuTT35::Indonesia, &buf[1..]),
312 0b0101_0101 => (ItuTT35::IranIslamicRepublicOf, &buf[1..]),
313 0b0101_0110 => (ItuTT35::Iraq, &buf[1..]),
314 0b0101_0111 => (ItuTT35::Ireland, &buf[1..]),
315 0b0101_1000 => (ItuTT35::Israel, &buf[1..]),
316 0b0101_1001 => (ItuTT35::Italy, &buf[1..]),
317 0b0101_1010 => (ItuTT35::CotedIvoire, &buf[1..]),
318 0b0101_1011 => (ItuTT35::Jamaica, &buf[1..]),
319 0b0101_1100 => (ItuTT35::Afghanistan, &buf[1..]),
320 0b0101_1101 => (ItuTT35::Jersey, &buf[1..]),
321 0b0101_1110 => (ItuTT35::Jordan, &buf[1..]),
322 0b0101_1111 => (ItuTT35::Kenya, &buf[1..]),
323 0b0110_0000 => (ItuTT35::Kiribati, &buf[1..]),
324 0b0110_0001 => (ItuTT35::KoreaRepublicOf, &buf[1..]),
325 0b0110_0010 => (ItuTT35::Kuwait, &buf[1..]),
326 0b0110_0011 => (ItuTT35::LaoPeoplesDemocraticRepublic, &buf[1..]),
327 0b0110_0100 => (ItuTT35::Lebanon, &buf[1..]),
328 0b0110_0101 => (ItuTT35::Lesotho, &buf[1..]),
329 0b0110_0110 => (ItuTT35::Liberia, &buf[1..]),
330 0b0110_0111 => (ItuTT35::Libya, &buf[1..]),
331 0b0110_1000 => (ItuTT35::Liechtenstein, &buf[1..]),
332 0b0110_1001 => (ItuTT35::Luxembourg, &buf[1..]),
333 0b0110_1010 => (ItuTT35::Macau, &buf[1..]),
334 0b0110_1011 => (ItuTT35::Madagascar, &buf[1..]),
335 0b0110_1100 => (ItuTT35::Malaysia, &buf[1..]),
336 0b0110_1101 => (ItuTT35::Malawi, &buf[1..]),
337 0b0110_1110 => (ItuTT35::Maldives, &buf[1..]),
338 0b0110_1111 => (ItuTT35::Mali, &buf[1..]),
339 0b0111_0000 => (ItuTT35::Malta, &buf[1..]),
340 0b1111_0001 => (ItuTT35::Mauritania, &buf[1..]),
341 0b0111_0010 => (ItuTT35::Mauritius, &buf[1..]),
342 0b0111_0011 => (ItuTT35::Mexico, &buf[1..]),
343 0b0111_0100 => (ItuTT35::Monaco, &buf[1..]),
344 0b0111_0101 => (ItuTT35::Mongolia, &buf[1..]),
345 0b0111_0110 => (ItuTT35::Montserrat, &buf[1..]),
346 0b0111_0111 => (ItuTT35::Morocco, &buf[1..]),
347 0b0111_1000 => (ItuTT35::Mozambique, &buf[1..]),
348 0b0111_1001 => (ItuTT35::Nauru, &buf[1..]),
349 0b0111_1010 => (ItuTT35::Nepal, &buf[1..]),
350 0b0111_1011 => (ItuTT35::Netherlands, &buf[1..]),
351 0b0111_1100 => (ItuTT35::NetherlandsAntilles, &buf[1..]),
352 0b0111_1101 => (ItuTT35::NewCaledonia, &buf[1..]),
353 0b0111_1110 => (ItuTT35::NewZealand, &buf[1..]),
354 0b0111_1111 => (ItuTT35::Nicaragua, &buf[1..]),
355 0b1000_0000 => (ItuTT35::Niger, &buf[1..]),
356 0b1000_0001 => (ItuTT35::Nigeria, &buf[1..]),
357 0b1000_0010 => (ItuTT35::Norway, &buf[1..]),
358 0b1000_0011 => (ItuTT35::Oman, &buf[1..]),
359 0b1000_0100 => (ItuTT35::Pakistan, &buf[1..]),
360 0b1000_0101 => (ItuTT35::Panama, &buf[1..]),
361 0b1000_0110 => (ItuTT35::PapuaNewGuinea, &buf[1..]),
362 0b1000_0111 => (ItuTT35::Paraguay, &buf[1..]),
363 0b1000_1000 => (ItuTT35::Peru, &buf[1..]),
364 0b1000_1001 => (ItuTT35::Philippines, &buf[1..]),
365 0b1000_1010 => (ItuTT35::PolandRepublicOf, &buf[1..]),
366 0b1000_1011 => (ItuTT35::Portugal, &buf[1..]),
367 0b1000_1100 => (ItuTT35::PuertoRico, &buf[1..]),
368 0b1000_1101 => (ItuTT35::Qatar, &buf[1..]),
369 0b1000_1110 => (ItuTT35::Romania, &buf[1..]),
370 0b1000_1111 => (ItuTT35::Rwanda, &buf[1..]),
371 0b1001_0000 => (ItuTT35::SaintKittsAndNevis, &buf[1..]),
372 0b1001_0001 => (ItuTT35::SaintCroix, &buf[1..]),
373 0b1001_0010 => (ItuTT35::SaintHelenaAndAscension, &buf[1..]),
374 0b1001_0011 => (ItuTT35::SaintLucia, &buf[1..]),
375 0b1001_0100 => (ItuTT35::SanMarino, &buf[1..]),
376 0b1001_0101 => (ItuTT35::SaintThomas, &buf[1..]),
377 0b1001_0110 => (ItuTT35::SaoTomeAndPrincipe, &buf[1..]),
378 0b1001_0111 => (ItuTT35::SaintVincentAndTheGrenadines, &buf[1..]),
379 0b1001_1000 => (ItuTT35::SaudiArabia, &buf[1..]),
380 0b1001_1001 => (ItuTT35::Senegal, &buf[1..]),
381 0b1001_1010 => (ItuTT35::Seychelles, &buf[1..]),
382 0b1001_1011 => (ItuTT35::SierraLeone, &buf[1..]),
383 0b1001_1100 => (ItuTT35::Singapore, &buf[1..]),
384 0b1001_1101 => (ItuTT35::SolomonIslands, &buf[1..]),
385 0b1001_1110 => (ItuTT35::Somalia, &buf[1..]),
386 0b1001_1111 => (ItuTT35::SouthAfrica, &buf[1..]),
387 0b1010_0000 => (ItuTT35::Spain, &buf[1..]),
388 0b1010_0001 => (ItuTT35::SriLanka, &buf[1..]),
389 0b1010_0010 => (ItuTT35::Sudan, &buf[1..]),
390 0b1010_0011 => (ItuTT35::Suriname, &buf[1..]),
391 0b1010_0100 => (ItuTT35::Swaziland, &buf[1..]),
392 0b1010_0101 => (ItuTT35::Sweden, &buf[1..]),
393 0b1010_0110 => (ItuTT35::Switzerland, &buf[1..]),
394 0b1010_0111 => (ItuTT35::Syria, &buf[1..]),
395 0b1010_1000 => (ItuTT35::Tanzania, &buf[1..]),
396 0b1010_1001 => (ItuTT35::Thailand, &buf[1..]),
397 0b1010_1010 => (ItuTT35::Togo, &buf[1..]),
398 0b1010_1011 => (ItuTT35::Tonga, &buf[1..]),
399 0b1010_1100 => (ItuTT35::TrinidadAndTobago, &buf[1..]),
400 0b1010_1101 => (ItuTT35::Tunisia, &buf[1..]),
401 0b1010_1110 => (ItuTT35::Turkey, &buf[1..]),
402 0b1010_1111 => (ItuTT35::TurksAndCaicosIslands, &buf[1..]),
403 0b1011_0000 => (ItuTT35::Tuvalu, &buf[1..]),
404 0b1011_0001 => (ItuTT35::Uganda, &buf[1..]),
405 0b1011_0010 => (ItuTT35::Ukraine, &buf[1..]),
406 0b1011_0011 => (ItuTT35::UnitedArabEmirates, &buf[1..]),
407 0b1011_0100 => (ItuTT35::UnitedKingdom, &buf[1..]),
408 0b1011_0101 => (ItuTT35::UnitedStates, &buf[1..]),
409 0b1011_0110 => (ItuTT35::BurkinaFaso, &buf[1..]),
410 0b1011_0111 => (ItuTT35::Uruguay, &buf[1..]),
411 0b1011_1000 => (ItuTT35::USSR, &buf[1..]),
412 0b1011_1001 => (ItuTT35::Vanuatu, &buf[1..]),
413 0b1011_1010 => (ItuTT35::VaticanCityState, &buf[1..]),
414 0b1011_1011 => (ItuTT35::Venezuela, &buf[1..]),
415 0b1011_1100 => (ItuTT35::VietNam, &buf[1..]),
416 0b1011_1101 => (ItuTT35::WallisAndFutuna, &buf[1..]),
417 0b1011_1110 => (ItuTT35::WesternSamoa, &buf[1..]),
418 0b1011_1111 => (ItuTT35::YemenRepublicOf(itu_t_t35_country_code), &buf[1..]),
419 0b1100_0000 => (ItuTT35::YemenRepublicOf(itu_t_t35_country_code), &buf[1..]),
420 0b1100_0001 => (ItuTT35::Yugoslavia, &buf[1..]),
421 0b1100_0010 => (ItuTT35::Zaire, &buf[1..]),
422 0b1100_0011 => (ItuTT35::Zambia, &buf[1..]),
423 0b1100_0100 => (ItuTT35::Zimbabwe, &buf[1..]),
424 0b1111_1111 => {
425 if buf.len() < 2 {
426 return Err(ItuTT35Error::NotEnoughData {
427 expected: 2,
428 actual: buf.len(),
429 });
430 }
431 (ItuTT35::Extended(buf[1]), &buf[1..])
432 }
433 _ => (ItuTT35::Unknown(itu_t_t35_country_code), &buf[1..]),
434 })
435 }
436}
437
438#[cfg(test)]
439mod test {
440 use super::*;
441
442 #[test]
443 fn parse() {
444 let msg = SeiMessage {
445 payload_type: HeaderType::UserDataRegisteredItuTT35,
446 payload: &[0b1011_0100, 0x00],
447 };
448 assert_eq!(
449 ItuTT35::read(&msg).unwrap(),
450 (ItuTT35::UnitedKingdom, &[0x00][..])
451 );
452 }
453}